Skip to content

fix(import): write sources to ./.rulesync for every --output-root import - #3997

Merged
dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3773-import-output-root
Nov 26, 2026
Merged

dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3773-import-output-root

Conversation

@dyoshikawa

Copy link
Copy Markdown
Owner

Summary

Resolves the remaining items of #3773: where import --output-root <dir> writes rulesync sources, plus the two low notes collected in the issue (canonical-looking unknown hook keys, silent drops of reserved permission names).

Changes

1. import -o <dir> always writes sources to ./.rulesync/ (project mode)

Probing main showed the inconsistency is wider than the issue listed. With -o sub:

Writes to sub/.rulesync/ Writes to ./.rulesync/
MCP, hooks, permissions and skills for every target; Claude Code rules and ignore; Copilot commands other rules, other ignore adapters, commands, subagents; packaging targets (already rebased)

Instead of patching ~20 adapters one by one, src/lib/import.ts now rebases every converted rulesync file and directory to process.cwd() before it is written (and before the MCP / hooks / permissions source-path resolution and the permissions merge, which read the existing file there). This replaces the packaging-only rebasing (getPackagingImportOutputRoot and the RulesyncSkill rebuild in importSkillsCore).

  • AiFile.withOutputRoot() / AiDir.withOutputRoot(): a copy of the file/directory written under another output root, every other field unchanged.
  • docs/reference/cli-commands.md: new short "Import Command" section stating the rule.
  • Tests: src/lib/import.test.ts (project mode rebases, global mode keeps), AiFile/AiDir unit tests, and a new E2E spec src/e2e/e2e-import-output-root.spec.ts covering all eight Claude Code features plus Copilot commands and Codex CLI rules with --output-root sub.

Behavior change: users who ran import -o <dir> and relied on MCP/hooks/permissions/skills (or Claude Code rules/ignore, Copilot commands) landing in <dir>/.rulesync/ now get them in ./.rulesync/, where generate actually reads them.

2. Hooks: canonical-looking unknown native keys

toolHooksToCanonical used to pass an unmapped key through unchanged, so camelCase preToolUse in a Goose file (inert in Goose) landed in the canonical block and became active after generate, even merging into the real mapped PreToolUse hooks. Now such a key is skipped with a warning when it is a canonical event name the tool does not read verbatim (not supported, or supported under a different native name). Non-canonical unknown keys (e.g. PostFileSave, PreToolUseResult) still go to the <tool>.hooks override block as before.

3. Permissions: warn on dropped reserved names

New helper skipsReservedPermissionName (src/features/permissions/reserved-permission-name.ts) replaces the silent isPrototypePollutionKey skips in the import paths of amp, antigravity (cli/ide), claudecode, codebuddy, continue, crush, cursor, devin, goose, lettacode, pool, qoder, qwencode, reasonix and trae. Wording follows buildImportedHooksConfig: Skipping imported <Tool> permission rule for "<category>" pattern "<pattern>": reserved key names cannot be used as permission categories or patterns.

Design decisions

  • ./.rulesync/ in cwd, not <dir>/.rulesync/. Already documented (docs/guide/declarative-sources.md, docs/guide/plugin-packaging.md), and generate reads sources from its input roots (default ./.rulesync), never from the output root, so <dir>/.rulesync/ was never read back.
  • Central rebase instead of per-adapter edits. One place covers every current and future adapter, and it matches how packaging targets were already handled. The adapter-level output roots (e.g. ClaudecodeIgnore, CopilotCommand.getRulesyncOutputRoot) are left as they are because they now only matter in global mode (see below).
  • Global mode unchanged. In global mode the sources also end up split today (e.g. Claude Code rules/MCP/skills go to ~/.rulesync/, Codex CLI rules and commands to ./.rulesync/), and the tool-home helpers (getToolRulesyncOutputRoot) deliberately send global sources to the home directory. Changing that is a separate decision, outside "import -o" (global mode ignores outputRoots).
  • Hooks: skip rather than move to the override block. I first moved such keys into <tool>.hooks, but generate reads canonical names in an override block as overrides of the canonical event, so the inert preToolUse then replaced Goose's real PreToolUse hooks. Since the tool ignores the key anyway, dropping it with a warning loses nothing that runs. I checked every converter config used by toolHooksToCanonical: each supported event already has an explicit native-name mapping, so no real native event is affected; the "supported and written verbatim" check is a safety net.
  • Permission warnings go through warnWithFallback. Most of these converters have no logger in scope; the fallback logger honors silent, like the existing Command Code import warnings.

Skipped items

  • Global-mode destination of imported sources: deliberately out of scope (see above); worth a separate issue if the maintainer wants one rule there too.
  • Hooks adapters that do not use toolHooksToCanonical (e.g. Cursor, Kiro, Copilot) were not changed; the note in the issue concerned the shared converter.

Closes #3773

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

`import --output-root <dir>` reads the tool files from <dir>, but the
features disagreed on where the converted sources went: MCP, hooks,
permissions, skills and the Claude Code / Copilot adapters wrote to
<dir>/.rulesync/, the rest to ./.rulesync/. Rebase every converted file
and directory to the current working directory in project mode, as the
docs already state, where `generate` reads them. Global mode keeps the
root each adapter chose.

Also, from the same follow-up issue:
- hooks import skips an unmapped native key spelled like a canonical
  event the tool does not read (e.g. camelCase `preToolUse` in a Goose
  file) with a warning, instead of activating it on the next generate
- permissions importers warn when they drop a rule whose category or
  pattern is `__proto__` / `constructor` / `prototype`

Closes #3773

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
@github-actions

Copy link
Copy Markdown
Contributor

@dyoshikawa The CI checks on this pull request are currently failing.

Please review the failing checks and push a fix. If you need help, leave a comment and a maintainer will follow up.

dyoshikawa and others added 3 commits November 26, 2026 18:57
…port-output-root

# Conflicts:
#	src/generated/docs-content.ts
…ort fixtures

The codexcli and factorydroid hooks-import E2E fixtures spelled the event
as camelCase `sessionStart`, which neither tool reads (both use
`SessionStart`). The import now skips such inert canonical-looking keys,
so the fixtures use the native spelling, and a unit test pins that the
real converter configs keep `SessionStart` and skip `sessionStart`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…port-output-root

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit 33fe073 into main Nov 26, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3773-import-output-root branch November 26, 2026 10:28
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.

Consistency follow-ups from the #3765 refactor: import -o destination, cwd overrides, Reasonix root guard, convert check

1 participant