-
Notifications
You must be signed in to change notification settings - Fork 46
feat: add programmatic API for rulesync #854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add high-level functions (generate, importFrom, init, gitignore) that can be called directly from Node.js code. This enables programmatic usage of rulesync without going through the CLI. Changes: - Create src/core/ with core business logic extracted from CLI commands - Create src/index.ts as package entry point exporting functions and classes - Update CLI commands to be thin wrappers calling core functions - Add tsup.config.ts for dual ESM/CJS build with TypeScript declarations - Update package.json with exports field and separate CLI entry point - Update tests for new thin wrapper CLI implementation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a programmatic API to rulesync, enabling users to call functions like generate, importFrom, init, and gitignore directly from Node.js code. The implementation extracts core business logic from CLI commands into a new src/core/ directory, creates proper TypeScript declarations with dual ESM/CJS support, and updates the package structure for library consumption.
Changes:
- Created
src/core/directory with core functions extracted from CLI commands - Added
src/index.tsas the main package entry point exporting high-level functions, processors, and types - Refactored CLI commands to be thin wrappers calling core functions
- Configured dual ESM/CJS build with TypeScript declarations via tsup
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tsup.config.ts | Configures dual ESM/CJS build with separate CLI and library entry points |
| src/index.ts | Main package entry point exporting public API |
| src/core/init.ts | Core initialization logic extracted from CLI |
| src/core/import.ts | Core import functionality extracted from CLI |
| src/core/gitignore.ts | Core gitignore update logic extracted from CLI |
| src/core/generate.ts | Core file generation logic extracted from CLI |
| src/core/index.ts | Barrel export for core functions |
| src/cli/commands/init.ts | Refactored to call core init function |
| src/cli/commands/import.ts | Refactored to call core importFrom function |
| src/cli/commands/gitignore.ts | Refactored to call core gitignore function |
| src/cli/commands/generate.ts | Refactored to call core generate function |
| src/cli/commands/*.test.ts | Updated tests to mock core functions instead of implementation details |
| package.json | Updated with exports field, bin path, and build script |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/lib/import.ts
Outdated
| * import { importFrom } from "rulesync"; | ||
| * | ||
| * const totalImported = await importFrom({ | ||
| * target: "claudecode", |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation example shows target: "claudecode" but the actual parameter is targets (plural). The example should use targets: ["claudecode"] to match the actual API signature.
| * target: "claudecode", | |
| * targets: ["claudecode"], |
| } | ||
| }, | ||
| "main": "dist/index.js", | ||
| "module": "dist/index.mjs", |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module field points to dist/index.mjs, but tsup with format: ["esm", "cjs"] will generate dist/index.js for ESM (not .mjs). This field should be removed or changed to dist/index.js to match the actual build output and the exports field configuration.
| "module": "dist/index.mjs", | |
| "module": "dist/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d39884814
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/cli/commands/generate.ts
Outdated
| // Set logger verbosity based on config | ||
| logger.setVerbose(config.getVerbose()); | ||
|
|
||
| logger.setVerbose(options.verbose ?? false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honor config-file verbose for generate
The CLI now sets verbosity from options.verbose only, before any config is resolved. Because rulesync.jsonc supports a verbose flag and ConfigResolver merges it into the runtime config, running rulesync generate with "verbose": true in the config (but without --verbose) will no longer enable verbose logging. This is a behavioral regression from the previous CLI path where verbosity followed the resolved config, so debug output becomes unavailable unless the flag is passed explicitly.
Useful? React with 👍 / 👎.
src/cli/commands/import.ts
Outdated
| } | ||
|
|
||
| const global = config.getGlobal(); | ||
| logger.setVerbose(options.verbose ?? false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honor config-file verbose for import
The import CLI now sets verbosity solely from options.verbose and never updates it from the resolved config. Since the config file’s verbose setting is meant to control logging, rulesync import run without --verbose will ignore "verbose": true in rulesync.jsonc, unlike the previous behavior that respected the config. This silently disables verbose logging for users who rely on config defaults.
Useful? React with 👍 / 👎.
Resolve conflicts by keeping thin wrapper implementation for CLI commands while incorporating kiro subagents feature from main. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add a new Programmatic API section documenting how to use Rulesync programmatically in Node.js projects. This includes: - High-level functions: generate(), importFrom(), init(), gitignore() - Options table for generate() function - Low-level API usage with ConfigResolver and processors - Error handling examples Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add generate.test.ts with tests for rules, ignore, mcp, commands, subagents, and skills generation - Add import.test.ts with tests for importing from various AI tools - Add init.test.ts with tests for directory and file creation idempotency - Add gitignore.test.ts with tests for .gitignore management - Fix JSDoc typo in import.ts (target -> targets) These integration tests use process.chdir() as they test lib functions that use relative paths resolved by the filesystem. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove the unnecessary special case that converted process.cwd() to "." only in generateIgnore(), making it consistent with other generate functions that pass baseDir directly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
07551cb to
9ee579b
Compare
Update generate and import commands to use logger.configure() instead of the removed logger.setVerbose() method, integrating with the silent mode feature added in origin/main. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This change ensures that tool files (commands, subagents, rules, ignore) properly propagate their baseDir when converting to rulesync format. Changes: - Update toRulesyncCommand() in antigravity, codexcli, roo, claudecode commands - Update toRulesyncSubagent() in claudecode, copilot, kiro, opencode subagents - Update toRulesyncRule() in augmentcode-legacy-rule - Update toRulesyncIgnore() in tool-ignore and cursor-ignore - Fix related test expectations to match actual baseDir values - Add baseDir parameter to init() function for testability - Update import and generate lib functions to use baseDirs from config Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
generate,importFrom,init,gitignore) that can be called directly from Node.js codesrc/lib/directory with core business logic extracted from CLI commandssrc/index.tsas package entry point exporting functions, classes, and typestsup.config.tsfor dual ESM/CJS build with TypeScript declarationspackage.jsonwith exports field and separate CLI entry pointUsage Example
Test plan
pnpm cicheck:codepassespnpm cicheck:contentpassespnpm build🤖 Generated with Claude Code