Skip to content

Conversation

@dyoshikawa
Copy link
Owner

@dyoshikawa dyoshikawa commented Jan 20, 2026

Summary

  • Add high-level functions (generate, importFrom, init, gitignore) that can be called directly from Node.js code
  • Create src/lib/ directory with core business logic extracted from CLI commands
  • Create src/index.ts as package entry point exporting functions, classes, and types
  • 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
  • Add comprehensive Programmatic API documentation to README
  • Add comprehensive test coverage for lib functions (generate, importFrom, init, gitignore)
  • Fix JSDoc typo in import.ts (target -> targets)

Usage Example

import { generate, importFrom, init, gitignore } from "rulesync";

// High-level API
const totalGenerated = await generate({
  targets: ["claudecode", "cursor"],
  features: ["rules", "mcp"],
});
console.log(`Generated ${totalGenerated} files`);

// Import from existing tool
const totalImported = await importFrom({
  targets: ["claudecode"],
  features: ["rules", "commands"],
});

Test plan

  • All existing tests pass (3192 tests)
  • pnpm cicheck:code passes
  • pnpm cicheck:content passes
  • Build succeeds with pnpm build
  • New lib function tests added (69 tests)
  • Manual testing of programmatic API usage

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings January 20, 2026 14:14
Copy link
Contributor

Copilot AI left a 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.ts as 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.

* import { importFrom } from "rulesync";
*
* const totalImported = await importFrom({
* target: "claudecode",
Copy link

Copilot AI Jan 20, 2026

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.

Suggested change
* target: "claudecode",
* targets: ["claudecode"],

Copilot uses AI. Check for mistakes.
}
},
"main": "dist/index.js",
"module": "dist/index.mjs",
Copy link

Copilot AI Jan 20, 2026

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.

Suggested change
"module": "dist/index.mjs",
"module": "dist/index.js",

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

// Set logger verbosity based on config
logger.setVerbose(config.getVerbose());

logger.setVerbose(options.verbose ?? false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

}

const global = config.getGlobal();
logger.setVerbose(options.verbose ?? false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

cm-dyoshikawa and others added 5 commits January 20, 2026 06:21
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>
@cm-dyoshikawa
Copy link
Collaborator

#377

cm-dyoshikawa and others added 3 commits January 20, 2026 19:52
- 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>
@dyoshikawa dyoshikawa force-pushed the feat/programmatic-api branch from 07551cb to 9ee579b Compare January 21, 2026 03:52
cm-dyoshikawa and others added 2 commits January 20, 2026 20:01
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants