@bonesofspring/ai-rules 0.2.57 → 0.2.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +41 -3
- package/bin/cli.js +399 -27
- package/bin/lib/engine-scripts.js +3 -0
- package/bin/lib/mcp/catalog.js +97 -0
- package/bin/lib/mcp/clients.js +35 -2
- package/bin/lib/mcp/credentials.js +85 -1
- package/bin/lib/mcp/doctor.js +93 -17
- package/bin/lib/mcp/registry.js +10 -4
- package/bin/lib/seed-ai-local-team.js +8 -5
- package/docs/MCP-CATALOG.md +56 -0
- package/docs/MCP-SETUP.md +38 -6
- package/docs/PRESET-CONTRIBUTION.md +1 -0
- package/mcp/github-proxy.mjs +133 -0
- package/mcp/lib/github.mjs +187 -0
- package/mcp/lib/streamable-http.mjs +185 -0
- package/mcp/lib/yandex.mjs +16 -137
- package/package.json +3 -1
- package/presets/_shared/ai-local/scripts/check-write-scope.mjs +212 -0
- package/presets/_shared/ai-local/scripts/rule-improver.mjs +343 -50
- package/presets/_shared/ai-local/scripts/run.mjs +122 -3
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +12 -0
- package/presets/_shared/core/review/code-review-mr.md +10 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +143 -1
- package/presets/claude/android-kotlin/commands/update.md +1 -0
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/android-kotlin/rules/tooling-and-review/code-review.md +10 -0
- package/presets/claude/go/commands/update.md +1 -0
- package/presets/claude/go/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/go/rules/tooling-and-review/code-review.md +10 -0
- package/presets/claude/ios-swift/commands/update.md +1 -0
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/ios-swift/rules/tooling-and-review/code-review.md +10 -0
- package/presets/claude/java/commands/update.md +1 -0
- package/presets/claude/java/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/java/rules/tooling-and-review/code-review.md +10 -0
- package/presets/claude/mcp-ts/commands/update.md +1 -0
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/mcp-ts/rules/tooling-and-review/code-review.md +10 -0
- package/presets/claude/mol/commands/update.md +1 -0
- package/presets/claude/mol/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/mol/rules/tooling-and-review/code-review-mr.md +10 -0
- package/presets/claude/next/agents/build-verifier.md +2 -0
- package/presets/claude/next/agents/code-reviewer.md +8 -0
- package/presets/claude/next/commands/task-continue.md +3 -1
- package/presets/claude/next/commands/update.md +1 -0
- package/presets/claude/next/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/next/rules/tooling-and-review/code-review-mr.md +10 -0
- package/presets/claude/nuxt/commands/update.md +1 -0
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/nuxt/rules/tooling-and-review/code-review-mr.md +10 -0
- package/presets/claude/php-hexagonal/commands/update.md +1 -0
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/php-hexagonal/rules/tooling-and-review/code-review.md +10 -0
- package/presets/claude/php-laravel/commands/update.md +1 -0
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/php-laravel/rules/tooling-and-review/code-review.md +10 -0
- package/presets/claude/svelte/commands/update.md +1 -0
- package/presets/claude/svelte/hooks/chain-team-phases.sh +143 -1
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
- package/presets/claude/svelte/rules/tooling-and-review/code-review-mr.md +10 -0
- package/presets/cursor/android-kotlin/commands/update.md +1 -0
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/android-kotlin/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/go/commands/update.md +1 -0
- package/presets/cursor/go/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/go/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/ios-swift/commands/update.md +1 -0
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/ios-swift/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/java/commands/update.md +1 -0
- package/presets/cursor/java/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/java/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/mcp-ts/commands/update.md +1 -0
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/mcp-ts/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/mol/MCP.md +4 -3
- package/presets/cursor/mol/commands/update.md +1 -0
- package/presets/cursor/mol/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/mol/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/next/MCP.md +4 -3
- package/presets/cursor/next/agents/build-verifier.md +2 -0
- package/presets/cursor/next/agents/code-reviewer.md +8 -0
- package/presets/cursor/next/commands/task-continue.md +3 -1
- package/presets/cursor/next/commands/update.md +1 -0
- package/presets/cursor/next/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/next/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/nuxt/commands/update.md +1 -0
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/nuxt/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/php-hexagonal/commands/update.md +1 -0
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/php-hexagonal/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/php-laravel/commands/update.md +1 -0
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/php-laravel/rules/code-review-mr.mdc +10 -0
- package/presets/cursor/svelte/commands/update.md +1 -0
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +143 -1
- package/presets/cursor/svelte/rules/code-review-mr.mdc +10 -0
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/commands/update.md +1 -0
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/android-kotlin/rules/code-review-mr.md +10 -0
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/commands/update.md +1 -0
- package/presets/mavis/go/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/go/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/go/rules/code-review-mr.md +10 -0
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/commands/update.md +1 -0
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/ios-swift/rules/code-review-mr.md +10 -0
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/commands/update.md +1 -0
- package/presets/mavis/java/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/java/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/java/rules/code-review-mr.md +10 -0
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/commands/update.md +1 -0
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/mcp-ts/rules/code-review-mr.md +10 -0
- package/presets/mavis/mol/MCP.md +4 -3
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/commands/update.md +1 -0
- package/presets/mavis/mol/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/mol/rules/code-review-mr.md +10 -0
- package/presets/mavis/next/MCP.md +4 -3
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/agents/build-verifier.md +2 -0
- package/presets/mavis/next/agents/code-reviewer.md +8 -0
- package/presets/mavis/next/commands/task-continue.md +3 -1
- package/presets/mavis/next/commands/update.md +1 -0
- package/presets/mavis/next/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/next/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/next/rules/code-review-mr.md +10 -0
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/commands/update.md +1 -0
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/nuxt/rules/code-review-mr.md +10 -0
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/commands/update.md +1 -0
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/php-hexagonal/rules/code-review-mr.md +10 -0
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/commands/update.md +1 -0
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/php-laravel/rules/code-review-mr.md +10 -0
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/commands/update.md +1 -0
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +143 -1
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +12 -0
- package/presets/mavis/svelte/rules/code-review-mr.md +10 -0
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/commands/update.md +1 -0
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/android-kotlin/rules/code-review-mr.md +10 -0
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/commands/update.md +1 -0
- package/presets/opencode/go/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/go/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/go/rules/code-review-mr.md +10 -0
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/commands/update.md +1 -0
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/ios-swift/rules/code-review-mr.md +10 -0
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/commands/update.md +1 -0
- package/presets/opencode/java/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/java/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/java/rules/code-review-mr.md +10 -0
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/commands/update.md +1 -0
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/mcp-ts/rules/code-review-mr.md +10 -0
- package/presets/opencode/mol/MCP.md +4 -3
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/commands/update.md +1 -0
- package/presets/opencode/mol/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/mol/rules/code-review-mr.md +10 -0
- package/presets/opencode/next/MCP.md +4 -3
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/agents/build-verifier.md +2 -0
- package/presets/opencode/next/agents/code-reviewer.md +8 -0
- package/presets/opencode/next/commands/task-continue.md +3 -1
- package/presets/opencode/next/commands/update.md +1 -0
- package/presets/opencode/next/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/next/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/next/rules/code-review-mr.md +10 -0
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/commands/update.md +1 -0
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/nuxt/rules/code-review-mr.md +10 -0
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/commands/update.md +1 -0
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/php-hexagonal/rules/code-review-mr.md +10 -0
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/commands/update.md +1 -0
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/php-laravel/rules/code-review-mr.md +10 -0
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/commands/update.md +1 -0
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +143 -1
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +12 -0
- package/presets/opencode/svelte/rules/code-review-mr.md +10 -0
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/commands/update.md +1 -0
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/android-kotlin/rules/code-review-mr.md +10 -0
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/commands/update.md +1 -0
- package/presets/zcode/go/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/go/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/go/rules/code-review-mr.md +10 -0
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/commands/update.md +1 -0
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/ios-swift/rules/code-review-mr.md +10 -0
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/commands/update.md +1 -0
- package/presets/zcode/java/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/java/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/java/rules/code-review-mr.md +10 -0
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/commands/update.md +1 -0
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/mcp-ts/rules/code-review-mr.md +10 -0
- package/presets/zcode/mol/MCP.md +4 -3
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/commands/update.md +1 -0
- package/presets/zcode/mol/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/mol/rules/code-review-mr.md +10 -0
- package/presets/zcode/next/MCP.md +4 -3
- package/presets/zcode/next/adapter-map.json +1 -1
- package/presets/zcode/next/agents/build-verifier.md +2 -0
- package/presets/zcode/next/agents/code-reviewer.md +8 -0
- package/presets/zcode/next/commands/task-continue.md +3 -1
- package/presets/zcode/next/commands/update.md +1 -0
- package/presets/zcode/next/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/next/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/next/rules/code-review-mr.md +10 -0
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/commands/update.md +1 -0
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/nuxt/rules/code-review-mr.md +10 -0
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/commands/update.md +1 -0
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/php-hexagonal/rules/code-review-mr.md +10 -0
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/commands/update.md +1 -0
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/php-laravel/rules/code-review-mr.md +10 -0
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/commands/update.md +1 -0
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +143 -1
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +12 -0
- package/presets/zcode/svelte/rules/code-review-mr.md +10 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Post-step write-scope reconciliation (read-only).
|
|
4
|
+
*
|
|
5
|
+
* Compares the paths a step actually changed with that step's declared
|
|
6
|
+
* `pipeline.json` `writeScopes`, and labels every path `declared`, `derived`
|
|
7
|
+
* (a generated mirror, the task folder, or another declared derived output), or
|
|
8
|
+
* `out-of-scope`. This is the missing audit between the plan (`check-parallel-plan.sh`)
|
|
9
|
+
* and the diff; it never writes and never gates a hook.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* node .ai.local/scripts/check-write-scope.mjs --slug <slug> [--step <id>] [--base <ref>] [--json]
|
|
13
|
+
* node .ai.local/scripts/check-write-scope.mjs --slug <slug> --paths a,b [--step <id>] [--json]
|
|
14
|
+
* node .ai.local/scripts/check-write-scope.mjs --slug <slug> --root <project> ...
|
|
15
|
+
*
|
|
16
|
+
* `--root` is the project root (the directory holding `.ai.local/`), not
|
|
17
|
+
* necessarily the git top level; a nested project works because the git
|
|
18
|
+
* baseline is emitted relative to that root.
|
|
19
|
+
*
|
|
20
|
+
* Baseline: `--base` defaults to `HEAD`, so the default audit covers the
|
|
21
|
+
* uncommitted change-set (tracked diff + untracked files). Pass a ref for a
|
|
22
|
+
* committed change-set: `--base origin/main`.
|
|
23
|
+
*
|
|
24
|
+
* Exit codes:
|
|
25
|
+
* 0 PASS, no changed paths, or an advisory (reviewer/verifier) step
|
|
26
|
+
* 1 FAIL — an implementation step changed an out-of-scope path
|
|
27
|
+
* 2 usage/config error (missing pipeline, unknown step, bad git ref)
|
|
28
|
+
*
|
|
29
|
+
* `--json` prints one object; the human report prints one labelled line per path.
|
|
30
|
+
*/
|
|
31
|
+
import { spawnSync } from 'node:child_process';
|
|
32
|
+
import fs from 'node:fs';
|
|
33
|
+
import path from 'node:path';
|
|
34
|
+
|
|
35
|
+
const USAGE = `Usage: node .ai.local/scripts/check-write-scope.mjs --slug <slug> [--step <id>] [--base <ref>] [--root <project>] [--paths a,b] [--json]`;
|
|
36
|
+
|
|
37
|
+
const REVIEW_AGENT_RE = /reviewer|auditor|verifier/i;
|
|
38
|
+
const DERIVED_RULES = [
|
|
39
|
+
{ name: 'task-folder', test: (file, slug) => file.startsWith(`.ai.local/team/tasks/${slug}/`) },
|
|
40
|
+
{ name: 'team-state', test: (file) => file.startsWith('.ai.local/team/') },
|
|
41
|
+
{ name: 'engine-mirror', test: (file) => file.startsWith('.ai.local/scripts/') },
|
|
42
|
+
{ name: 'generated-platform', test: (file) => /^packages\/ai-rules\/presets\/(?:claude|mavis|opencode|zcode)\//.test(file) },
|
|
43
|
+
{ name: 'generated-hook', test: (file) => /^packages\/ai-rules\/presets\/cursor\/[^/]+\/hooks\/chain-team-phases\.sh$/.test(file) },
|
|
44
|
+
{ name: 'generated-golden', test: (file) => file.startsWith('packages/ai-rules/scripts/fixtures/cli-golden/') },
|
|
45
|
+
{ name: 'dogfood-tree', test: (file) => /^\.(?:cursor|claude|mavis|opencode|zcode)\//.test(file) },
|
|
46
|
+
{ name: 'generated-root-agents', test: (file) => file === 'AGENTS.md' },
|
|
47
|
+
{ name: 'generated-adapter-map', test: (file) => /adapter-map\.json$/.test(file) },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
function fail(message) {
|
|
51
|
+
console.error(`check-write-scope: ${message}`);
|
|
52
|
+
process.exit(2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parseArgs(argv) {
|
|
56
|
+
const args = { _: [] };
|
|
57
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
58
|
+
const token = argv[index];
|
|
59
|
+
const readValue = () => {
|
|
60
|
+
const value = argv[index + 1];
|
|
61
|
+
if (value === undefined || value.startsWith('-')) fail(`${token} needs a value`);
|
|
62
|
+
index += 1;
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
if (token === '--slug') args.slug = readValue();
|
|
66
|
+
else if (token === '--step') args.step = readValue();
|
|
67
|
+
else if (token === '--base') args.base = readValue();
|
|
68
|
+
else if (token === '--root') args.root = readValue();
|
|
69
|
+
else if (token === '--paths') args.paths = readValue();
|
|
70
|
+
else if (token === '--json') args.json = true;
|
|
71
|
+
else if (token === '--help' || token === '-h') {
|
|
72
|
+
console.log(USAGE);
|
|
73
|
+
process.exit(0);
|
|
74
|
+
} else if (token.startsWith('-')) fail(`unknown option ${token}`);
|
|
75
|
+
else args._.push(token);
|
|
76
|
+
}
|
|
77
|
+
return args;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function normalizePath(value) {
|
|
81
|
+
let text = String(value ?? '').trim().replace(/\\/g, '/');
|
|
82
|
+
while (text.startsWith('./')) text = text.slice(2);
|
|
83
|
+
return text;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function inScope(file, scope) {
|
|
87
|
+
const target = normalizePath(file);
|
|
88
|
+
const normalized = normalizePath(scope);
|
|
89
|
+
if (!target || !normalized) return false;
|
|
90
|
+
if (normalized === target) return true;
|
|
91
|
+
if (normalized.endsWith('/**')) {
|
|
92
|
+
const prefix = normalized.slice(0, -3);
|
|
93
|
+
return target === prefix || target.startsWith(`${prefix}/`);
|
|
94
|
+
}
|
|
95
|
+
if (normalized.endsWith('/*')) {
|
|
96
|
+
const prefix = normalized.slice(0, -2);
|
|
97
|
+
const rest = target.startsWith(`${prefix}/`) ? target.slice(prefix.length + 1) : '';
|
|
98
|
+
return Boolean(rest) && !rest.includes('/');
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function agentsOf(step) {
|
|
104
|
+
if (!step) return [];
|
|
105
|
+
return Array.isArray(step.agent) ? step.agent.filter((agent) => typeof agent === 'string') : [step.agent];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function chooseStep(pipeline, requested) {
|
|
109
|
+
const steps = Array.isArray(pipeline.steps) ? pipeline.steps : [];
|
|
110
|
+
if (requested) {
|
|
111
|
+
const step = steps.find((item) => item && item.id === requested);
|
|
112
|
+
if (!step) fail(`unknown step "${requested}" (available: ${steps.map((item) => item?.id ?? '(no id)').join(', ') || 'none'})`);
|
|
113
|
+
return step;
|
|
114
|
+
}
|
|
115
|
+
const implementation = steps.find((item) => Array.isArray(item?.writeScopes)
|
|
116
|
+
&& item.writeScopes.length > 0
|
|
117
|
+
&& agentsOf(item).some((agent) => /feature-developer|debugger|ci-investigator/i.test(agent)));
|
|
118
|
+
if (implementation) return implementation;
|
|
119
|
+
const scoped = steps.filter((item) => Array.isArray(item?.writeScopes) && item.writeScopes.length > 0);
|
|
120
|
+
if (scoped.length === 1) return scoped[0];
|
|
121
|
+
fail('cannot choose a step; pass --step <id>');
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function gitChangedPaths(root, base) {
|
|
126
|
+
// `--relative` emits the diff against `root` (the project root), matching the
|
|
127
|
+
// cwd-relative `ls-files` output below even when `root` is not the git root.
|
|
128
|
+
const diff = spawnSync('git', ['-C', root, 'diff', '--relative', '--name-only', base, '--', '.'], { encoding: 'utf8' });
|
|
129
|
+
if (diff.status !== 0) {
|
|
130
|
+
fail(`git diff ${base} failed: ${(diff.stderr || '').trim() || `exit ${diff.status}`}`);
|
|
131
|
+
}
|
|
132
|
+
const untracked = spawnSync('git', ['-C', root, 'ls-files', '--others', '--exclude-standard'], { encoding: 'utf8' });
|
|
133
|
+
if (untracked.status !== 0) {
|
|
134
|
+
fail(`git ls-files failed: ${(untracked.stderr || '').trim() || `exit ${untracked.status}`}`);
|
|
135
|
+
}
|
|
136
|
+
return [...String(diff.stdout || '').split('\n'), ...String(untracked.stdout || '').split('\n')]
|
|
137
|
+
.map(normalizePath)
|
|
138
|
+
.filter(Boolean);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function classify(changed, writeScopes, slug) {
|
|
142
|
+
return changed.map((file) => {
|
|
143
|
+
const derived = DERIVED_RULES.find((rule) => rule.test(file, slug));
|
|
144
|
+
if (derived) return { path: file, classification: 'derived', source: `derived: ${derived.name}` };
|
|
145
|
+
const scope = writeScopes.find((candidate) => inScope(file, candidate));
|
|
146
|
+
if (scope) return { path: file, classification: 'declared', source: `writeScopes: ${scope}` };
|
|
147
|
+
return { path: file, classification: 'out-of-scope', source: 'not in step writeScopes' };
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function renderReport({ slug, step, base, verdict, rows }) {
|
|
152
|
+
const counts = {
|
|
153
|
+
declared: rows.filter((row) => row.classification === 'declared').length,
|
|
154
|
+
derived: rows.filter((row) => row.classification === 'derived').length,
|
|
155
|
+
outOfScope: rows.filter((row) => row.classification === 'out-of-scope').length,
|
|
156
|
+
};
|
|
157
|
+
const lines = [
|
|
158
|
+
`Write-scope reconciliation — slug ${slug}, step ${step.id ?? '(no id)'} (${agentsOf(step).join(', ')})`,
|
|
159
|
+
`base: ${base}${base === 'HEAD' ? ' (uncommitted change-set)' : ''}`,
|
|
160
|
+
`paths: ${rows.length} — declared ${counts.declared}, derived ${counts.derived}, out-of-scope ${counts.outOfScope}`,
|
|
161
|
+
];
|
|
162
|
+
for (const row of rows) {
|
|
163
|
+
lines.push(` ${row.classification.padEnd(12)} ${row.path} — ${row.source}`);
|
|
164
|
+
}
|
|
165
|
+
lines.push(`verdict: ${verdict.toUpperCase()}`);
|
|
166
|
+
return { counts, text: `${lines.join('\n')}\n` };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function main() {
|
|
170
|
+
const args = parseArgs(process.argv.slice(2));
|
|
171
|
+
if (!args.slug) fail('--slug <slug> is required');
|
|
172
|
+
if (args._.length > 0) fail(`unexpected positional argument "${args._[0]}"`);
|
|
173
|
+
const root = path.resolve(args.root ?? process.cwd());
|
|
174
|
+
const pipelinePath = path.join(root, '.ai.local', 'team', 'tasks', args.slug, 'pipeline.json');
|
|
175
|
+
if (!fs.existsSync(pipelinePath)) fail(`no pipeline.json at ${path.relative(root, pipelinePath)}`);
|
|
176
|
+
let pipeline;
|
|
177
|
+
try {
|
|
178
|
+
pipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
|
|
179
|
+
} catch (error) {
|
|
180
|
+
fail(`pipeline.json is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
181
|
+
}
|
|
182
|
+
const step = chooseStep(pipeline, args.step);
|
|
183
|
+
const writeScopes = Array.isArray(step.writeScopes) ? step.writeScopes.filter((scope) => typeof scope === 'string' && scope) : [];
|
|
184
|
+
if (writeScopes.length === 0) fail(`step ${step.id ?? '(no id)'} declares no writeScopes`);
|
|
185
|
+
|
|
186
|
+
const base = args.base ?? 'HEAD';
|
|
187
|
+
const changed = args.paths !== undefined
|
|
188
|
+
? String(args.paths).split(',').map(normalizePath).filter(Boolean)
|
|
189
|
+
: gitChangedPaths(root, base);
|
|
190
|
+
const rows = classify(changed, writeScopes, args.slug);
|
|
191
|
+
const outOfScope = rows.filter((row) => row.classification === 'out-of-scope');
|
|
192
|
+
const advisory = agentsOf(step).some((agent) => REVIEW_AGENT_RE.test(agent));
|
|
193
|
+
const verdict = outOfScope.length === 0 ? 'pass' : advisory ? 'advisory' : 'fail';
|
|
194
|
+
const { counts, text } = renderReport({ slug: args.slug, step, base, verdict, rows });
|
|
195
|
+
|
|
196
|
+
if (args.json) {
|
|
197
|
+
console.log(JSON.stringify({
|
|
198
|
+
schemaVersion: 1,
|
|
199
|
+
slug: args.slug,
|
|
200
|
+
step: { id: step.id ?? null, agent: step.agent ?? null, writeScopes },
|
|
201
|
+
base,
|
|
202
|
+
verdict,
|
|
203
|
+
counts,
|
|
204
|
+
paths: rows,
|
|
205
|
+
}, null, 2));
|
|
206
|
+
} else {
|
|
207
|
+
process.stdout.write(text);
|
|
208
|
+
}
|
|
209
|
+
process.exit(verdict === 'fail' ? 1 : 0);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
main();
|