Skip to content

feat(sources): install commands and subagents from declarative sources - #4005

Merged
dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3423-sources-commands-subagents
Nov 26, 2026
Merged

dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3423-sources-commands-subagents

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Declarative sources can now install commands and subagents, in addition to skills and rules. This follows the rules precedent (#2349): one optional selection field and one optional path field per feature, the same lock shape, and the same curated-directory model.

{
  "sources": [
    {
      "source": "acme/ai-assets",
      "commands": ["review", "release"],
      "commandsPath": "exports/commands", // default: "commands"
      "subagents": ["*"],                 // subagentsPath default: "subagents"
    },
  ],
}

Changes

  • Config: commands / commandsPath and subagents / subagentsPath on source entries. The path fields reuse the rulesPath validation (relative, no .., no control characters). A source that declares only commands and/or subagents takes no skills, as for rules.
  • Fetching: the rule-only helpers (replaceCuratedRules, canReuseLockedRules, selectDeclaredRules, fetchRulesViaGithub / fetchRulesViaGit, npm fetchNpmRules, the GitHub prefetch claims, frozen coverage, stale-entry cleanup, lock key migration) are generalized to a per-file feature (rules | commands | subagents), so all three share one code path over the GitHub, git and npm transports. Rules behave exactly as before (same messages, same lock shape).
  • One SHA per source: every feature of a source reuses the ref resolved by the first one, and re-fetches at it on --update (generalizing the existing skills+rules rule).
  • Lock: optional commands / commandSelection / commandsPath / resolvedCommandNames and the subagent counterparts on both rulesync.lock and rulesync-npm.lock.json entries. LOCKFILE_VERSION stays 1; old lockfiles parse unchanged. Lock keys of a repository declared several times are qualified by commandsPath / subagentsPath as well as rulesPath.
  • Generate: the commands and subagents processors read commands/.curated/ and subagents/.curated/; a local file of the same name wins (case-only collisions warn, via a shared filterCuratedShadowedByLocal helper).
  • CLI / MCP: rulesync add --commands --subagents --commands-path --subagents-path, the MCP add tool schema, install/add summaries and --json counts (commandsFetched, subagentsFetched). --mode gh rejects the new fields like it rejects rules.
  • gitignore: .rulesync/commands/.curated/ and .rulesync/subagents/.curated/.
  • Docs: declarative sources guide, CLI reference, MCP reference, configuration example; src/generated/docs-content.ts regenerated.

Safety: fetched content stays inside .rulesync/

  • Remote names containing /, \, .., hidden/control characters, or __proto__-like names are skipped with a warning (same gate as rules), and every write goes through checkPathTraversal against the feature's curated directory.
  • install / add refuse to run when any curated directory (now including the commands and subagents ones) resolves outside the project root, is not a directory, or contains a symlink.
  • New hardening (applies to rules too): names read from the lockfile, which can be hand-edited, are checked to resolve inside the curated directory before they are read for rollback, removed, or restored; such a name never counts as installed, so the source is fetched again.
  • Path fields reject .., absolute paths and control characters at config parse time.
  • Fetched commands and subagents keep only canonical frontmatter (review rounds 1-2). When generate reads a file from commands/.curated/ or subagents/.curated/, it keeps only targets and description (plus name for a subagent; the schemas have no canonical model) and drops every other key, including every tool section, with one warning per file listing what was dropped and pointing to a local copy for tool-specific settings. An allowlist replaces the round-1 denylist because tool sections are copied into generated files and each tool has its own privileged settings (Claude Code permissionMode/hooks/mcpServers/allowed-tools, Kiro toolsSettings/includeMcpJson, Codex notify/sandbox_*/model_providers, OpenCode permission/tools, ...). This runs at generate time, so lock integrity still covers the fetched bytes.

Design decisions

  1. Commands and subagents only, one feature at a time (as in feat: support rules in declarative sources #2349), rather than the generic per-feature lock schema suggested in the issue thread: that would change the lock format for every feature.
  2. No lockfileVersion bump: only additive optional fields, so existing lockfiles and older readers keep working.
  3. Flat layout: only direct .md children of commandsPath / subagentsPath are installed, matching rules. Nested commands are not fetched.
  4. Local precedence: a local .rulesync/commands/<name>.md / .rulesync/subagents/<name>.md makes the remote one skipped at install time and shadowed at generate time, like skills and rules.
  5. Curated files keep their curated directory as the rulesync file's directory (they are loaded with relativeDirPath .rulesync/commands/.curated), which keeps the loader simple; tool outputs depend only on the file name.
  6. No per-source opt-in for tool-specific frontmatter: a per-source flag would require tracking which source each curated file came from at generate time. The documented escape hatch is copying the file into the local tree, where it gets reviewed.
  7. Skills are not filtered: skills from sources already existed before this PR, and they can ship scripts the agent runs, so a frontmatter filter would not close that path and would break existing allowed-tools usage. The docs say to review skill sources as code.
  8. Additive API: ResolveAndFetchSourcesOptions / Result gain command/subagent counterparts of the rule options; getInstalledSourceRuleNames became getInstalledSourceFileNames({ feature }).

Skipped items and why

  • MCP servers, hooks and permissions are intentionally not installable from sources. MCP servers and hooks run commands on each developer's machine, and permissions widen what agents may do without asking; pulling them from a remote source on install is a safety risk that needs its own opt-in design. The docs point to a reviewed, pinned checkout in inputRoots for those. The issue stays open for them, hence Refs.
  • A generic features lock schema (issue comment): not chosen, see decision 1.

Verification

  • New tests: GitHub install of commands + subagents at one SHA with lock fields, lock reuse without refetch, local precedence, traversal-named remote files, hand-edited traversal names in the lock (not read/removed/restored), git transport, npm transport, --frozen coverage, removing a feature clears its curated files and lock fields, empty-list message; lock round-trip without version bump and key qualifiers; config validation; gh-mode rejection; curated loading in both processors.
  • Manual: a local file:// git source with commands/ and subagents/ → install writes the curated files and lock, generate emits .claude/commands/* and .claude/agents/planner.md with the local command winning, install --frozen reports up to date.
  • pnpm cicheck (full) passed locally on the first commit (625 test files, 17540 tests, content checks clean). The review-round commits were checked with targeted suites (src/lib, commands, subagents, config, utils: 3797 tests), fmt, oxlint, typecheck and cicheck:content.

Refs #3423

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

dyoshikawa and others added 4 commits November 26, 2026 18:29
Declarative sources could only install skills and rules. Add `commands` /
`commandsPath` and `subagents` / `subagentsPath` to source entries,
following the rules precedent (#2349): direct `.md` files of the path are
fetched into `.rulesync/commands/.curated/` and
`.rulesync/subagents/.curated/` over every transport (GitHub, git, npm),
locked with optional fields in `rulesync.lock` / `rulesync-npm.lock.json`
(no lockfile version bump), covered by `--frozen`, `rulesync add` flags,
the MCP add tool and gitignore, and read by `generate` with local files
taking precedence.

The rule-only helpers are generalized to a per-file feature so rules,
commands and subagents share one code path. Locked names are checked to
stay inside the curated directory before anything is read, removed or
restored under them.

MCP servers, hooks and permissions stay out of sources: installing them
from a remote source would run commands or widen permissions.

Refs #3423

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

A command or subagent installed from a declared source could carry tool
section keys such as `permissionMode: bypassPermissions`, `hooks`,
`mcpServers` or `allowed-tools`, which the tool adapters copy verbatim
into the generated file, so a source could still widen permissions or
run commands. When `generate` reads a file from `commands/.curated/` or
`subagents/.curated/`, drop those keys at the root and in every tool
section and warn with what was dropped. Narrowing keys (`tools`,
`disallowedTools`) are kept. A local copy of the file keeps them.

Also mention `.curated/` in the simulated command and subagent
instructions, list the new curated directories in the global mode guide,
remove the now-unused `shouldSkipRule` / `getLockedRuleNames`, and share
`mapFileFeatures` instead of duplicating it.

Refs #3423

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

The denylist of privileged keys could not keep up with every tool's
settings: Kiro `toolsSettings` / `includeMcpJson`, Codex `notify` and
`model_providers`, OpenCode `tools` and others still reached the
generated files. Switch to an allowlist: a file read from
`commands/.curated/` or `subagents/.curated/` keeps only `targets` and
`description` (plus `name` for a subagent) and drops every tool section,
with one warning per file naming what was dropped and pointing to a local
copy for tool-specific settings.

Refs #3423

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…urces-commands-subagents

# Conflicts:
#	src/generated/docs-content.ts
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.

1 participant