@bonesofspring/ai-rules 0.2.84 → 0.2.87
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 +30 -0
- package/bin/lib/engine-scripts.js +4 -0
- package/bin/lib/seed-ai-local-team.js +39 -2
- package/bin/opencode-install.js +3 -2
- package/docs/OPENCODE-COMPATIBILITY.md +6 -4
- package/docs/OPENCODE.md +8 -5
- package/docs/PRESET-CONTRIBUTION.md +19 -10
- package/docs/TEAM-DB.md +76 -3
- package/docs/TOKEN-ECONOMY.md +20 -0
- package/docs/openapi/team-db.v1.json +7069 -5895
- package/package.json +5 -2
- package/presets/_shared/ai-local/scripts/report-step-cost.mjs +544 -0
- package/presets/_shared/ai-local/scripts/team-db-api.mjs +253 -15
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +310 -4
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +733 -8
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +44 -0
- package/presets/_shared/ai-local/scripts/team-db.mjs +43 -3
- package/presets/_shared/assets/model-tiers.json +6 -0
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +3 -3
- package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +125 -105
- package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/go/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/java/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/mol/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/next/agents/build-verifier.md +2 -1
- package/presets/claude/next/agents/feature-developer.md +1 -1
- package/presets/claude/next/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/nuxt/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/claude/svelte/hooks/guard-shell-command.mjs +125 -105
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
- package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/go/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/go/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/java/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/java/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/mol/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/next/agents/build-verifier.md +2 -1
- package/presets/cursor/next/agents/feature-developer.md +1 -1
- package/presets/cursor/next/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/cursor/svelte/hooks/guard-shell-command.mjs +125 -105
- package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +3 -3
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/agents/build-verifier.md +2 -1
- package/presets/mavis/next/agents/feature-developer.md +1 -1
- package/presets/mavis/next/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +3 -3
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +3 -3
- package/presets/opencode/android-kotlin/OPENCODE.md +5 -66
- package/presets/opencode/android-kotlin/adapter-map.json +42 -42
- package/presets/opencode/android-kotlin/agents/accessibility-reviewer.md +1 -1
- package/presets/opencode/android-kotlin/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/android-kotlin/agents/build-verifier.md +1 -1
- package/presets/opencode/android-kotlin/agents/ci-investigator.md +1 -1
- package/presets/opencode/android-kotlin/agents/code-reviewer.md +1 -1
- package/presets/opencode/android-kotlin/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/android-kotlin/agents/debugger.md +1 -1
- package/presets/opencode/android-kotlin/agents/feature-developer.md +1 -1
- package/presets/opencode/android-kotlin/agents/instrumentation-test-generator.md +1 -1
- package/presets/opencode/android-kotlin/agents/instrumentation-test-healer.md +1 -1
- package/presets/opencode/android-kotlin/agents/instrumentation-test-planner.md +1 -1
- package/presets/opencode/android-kotlin/agents/migration-specialist.md +1 -1
- package/presets/opencode/android-kotlin/agents/mockup-reviewer.md +1 -1
- package/presets/opencode/android-kotlin/agents/openspec-author.md +1 -1
- package/presets/opencode/android-kotlin/agents/performance-auditor.md +1 -1
- package/presets/opencode/android-kotlin/agents/qa-tester.md +1 -1
- package/presets/opencode/android-kotlin/agents/security-reviewer.md +1 -1
- package/presets/opencode/android-kotlin/agents/solution-architect.md +1 -1
- package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/opencode/android-kotlin/agents/task-router.md +1 -1
- package/presets/opencode/android-kotlin/agents/tech-writer.md +1 -1
- package/presets/opencode/android-kotlin/agents/unit-test-generator.md +1 -1
- package/presets/opencode/android-kotlin/agents/unit-test-healer.md +1 -1
- package/presets/opencode/android-kotlin/agents/unit-test-planner.md +1 -1
- package/presets/opencode/android-kotlin/commands/task-continue.md +1 -1
- package/presets/opencode/android-kotlin/hooks/README.md +11 -1
- package/presets/opencode/android-kotlin/hooks/guard-shell-command.mjs +155 -0
- package/presets/opencode/android-kotlin/plugins/rule-attach/globs.json +167 -0
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/go/OPENCODE.md +5 -51
- package/presets/opencode/go/adapter-map.json +45 -45
- package/presets/opencode/go/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/go/agents/build-verifier.md +1 -1
- package/presets/opencode/go/agents/ci-investigator.md +1 -1
- package/presets/opencode/go/agents/code-reviewer.md +1 -1
- package/presets/opencode/go/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/go/agents/debugger.md +1 -1
- package/presets/opencode/go/agents/feature-developer.md +1 -1
- package/presets/opencode/go/agents/integration-test-generator.md +1 -1
- package/presets/opencode/go/agents/integration-test-healer.md +1 -1
- package/presets/opencode/go/agents/integration-test-planner.md +1 -1
- package/presets/opencode/go/agents/migration-specialist.md +1 -1
- package/presets/opencode/go/agents/openspec-author.md +1 -1
- package/presets/opencode/go/agents/performance-auditor.md +1 -1
- package/presets/opencode/go/agents/qa-tester.md +1 -1
- package/presets/opencode/go/agents/security-reviewer.md +1 -1
- package/presets/opencode/go/agents/solution-architect.md +1 -1
- package/presets/opencode/go/agents/task-analyst.md +1 -1
- package/presets/opencode/go/agents/task-router.md +1 -1
- package/presets/opencode/go/agents/tech-writer.md +1 -1
- package/presets/opencode/go/agents/unit-test-generator.md +1 -1
- package/presets/opencode/go/agents/unit-test-healer.md +1 -1
- package/presets/opencode/go/agents/unit-test-planner.md +1 -1
- package/presets/opencode/go/commands/task-continue.md +1 -1
- package/presets/opencode/go/hooks/README.md +11 -1
- package/presets/opencode/go/hooks/guard-shell-command.mjs +154 -0
- package/presets/opencode/go/plugins/rule-attach/globs.json +198 -0
- package/presets/opencode/go/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/ios-swift/OPENCODE.md +5 -66
- package/presets/opencode/ios-swift/adapter-map.json +41 -41
- package/presets/opencode/ios-swift/agents/accessibility-reviewer.md +1 -1
- package/presets/opencode/ios-swift/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/ios-swift/agents/build-verifier.md +1 -1
- package/presets/opencode/ios-swift/agents/ci-investigator.md +1 -1
- package/presets/opencode/ios-swift/agents/code-reviewer.md +1 -1
- package/presets/opencode/ios-swift/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/ios-swift/agents/debugger.md +1 -1
- package/presets/opencode/ios-swift/agents/feature-developer.md +1 -1
- package/presets/opencode/ios-swift/agents/migration-specialist.md +1 -1
- package/presets/opencode/ios-swift/agents/mockup-reviewer.md +1 -1
- package/presets/opencode/ios-swift/agents/openspec-author.md +1 -1
- package/presets/opencode/ios-swift/agents/performance-auditor.md +1 -1
- package/presets/opencode/ios-swift/agents/qa-tester.md +1 -1
- package/presets/opencode/ios-swift/agents/security-reviewer.md +1 -1
- package/presets/opencode/ios-swift/agents/solution-architect.md +1 -1
- package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
- package/presets/opencode/ios-swift/agents/task-router.md +1 -1
- package/presets/opencode/ios-swift/agents/tech-writer.md +1 -1
- package/presets/opencode/ios-swift/agents/unit-test-generator.md +1 -1
- package/presets/opencode/ios-swift/agents/unit-test-healer.md +1 -1
- package/presets/opencode/ios-swift/agents/unit-test-planner.md +1 -1
- package/presets/opencode/ios-swift/agents/xcuitest-test-generator.md +1 -1
- package/presets/opencode/ios-swift/agents/xcuitest-test-healer.md +1 -1
- package/presets/opencode/ios-swift/agents/xcuitest-test-planner.md +1 -1
- package/presets/opencode/ios-swift/commands/task-continue.md +1 -1
- package/presets/opencode/ios-swift/hooks/README.md +11 -1
- package/presets/opencode/ios-swift/hooks/guard-shell-command.mjs +154 -0
- package/presets/opencode/ios-swift/plugins/rule-attach/globs.json +160 -0
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/java/OPENCODE.md +5 -58
- package/presets/opencode/java/adapter-map.json +45 -45
- package/presets/opencode/java/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/java/agents/build-verifier.md +1 -1
- package/presets/opencode/java/agents/ci-investigator.md +1 -1
- package/presets/opencode/java/agents/code-reviewer.md +1 -1
- package/presets/opencode/java/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/java/agents/debugger.md +1 -1
- package/presets/opencode/java/agents/feature-developer.md +1 -1
- package/presets/opencode/java/agents/integration-test-generator.md +1 -1
- package/presets/opencode/java/agents/integration-test-healer.md +1 -1
- package/presets/opencode/java/agents/integration-test-planner.md +1 -1
- package/presets/opencode/java/agents/migration-specialist.md +1 -1
- package/presets/opencode/java/agents/openspec-author.md +1 -1
- package/presets/opencode/java/agents/performance-auditor.md +1 -1
- package/presets/opencode/java/agents/qa-tester.md +1 -1
- package/presets/opencode/java/agents/security-reviewer.md +1 -1
- package/presets/opencode/java/agents/solution-architect.md +1 -1
- package/presets/opencode/java/agents/task-analyst.md +1 -1
- package/presets/opencode/java/agents/task-router.md +1 -1
- package/presets/opencode/java/agents/tech-writer.md +1 -1
- package/presets/opencode/java/agents/unit-test-generator.md +1 -1
- package/presets/opencode/java/agents/unit-test-healer.md +1 -1
- package/presets/opencode/java/agents/unit-test-planner.md +1 -1
- package/presets/opencode/java/commands/task-continue.md +1 -1
- package/presets/opencode/java/hooks/README.md +11 -1
- package/presets/opencode/java/hooks/guard-shell-command.mjs +155 -0
- package/presets/opencode/java/plugins/rule-attach/globs.json +230 -0
- package/presets/opencode/java/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/mcp-ts/OPENCODE.md +5 -48
- package/presets/opencode/mcp-ts/adapter-map.json +36 -36
- package/presets/opencode/mcp-ts/agents/build-verifier.md +1 -1
- package/presets/opencode/mcp-ts/agents/feature-developer.md +1 -1
- package/presets/opencode/mcp-ts/agents/security-reviewer.md +1 -1
- package/presets/opencode/mcp-ts/agents/solution-architect.md +1 -1
- package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/opencode/mcp-ts/agents/task-router.md +1 -1
- package/presets/opencode/mcp-ts/commands/task-continue.md +1 -1
- package/presets/opencode/mcp-ts/hooks/README.md +11 -1
- package/presets/opencode/mcp-ts/hooks/guard-shell-command.mjs +154 -0
- package/presets/opencode/mcp-ts/plugins/rule-attach/globs.json +151 -0
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/mol/OPENCODE.md +5 -56
- package/presets/opencode/mol/adapter-map.json +31 -31
- package/presets/opencode/mol/agents/accessibility-reviewer.md +1 -1
- package/presets/opencode/mol/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/mol/agents/build-verifier.md +1 -1
- package/presets/opencode/mol/agents/ci-investigator.md +1 -1
- package/presets/opencode/mol/agents/code-reviewer.md +1 -1
- package/presets/opencode/mol/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/mol/agents/debugger.md +1 -1
- package/presets/opencode/mol/agents/feature-developer.md +1 -1
- package/presets/opencode/mol/agents/migration-specialist.md +1 -1
- package/presets/opencode/mol/agents/mockup-reviewer.md +1 -1
- package/presets/opencode/mol/agents/openspec-author.md +1 -1
- package/presets/opencode/mol/agents/performance-auditor.md +1 -1
- package/presets/opencode/mol/agents/playwright-test-generator.md +1 -1
- package/presets/opencode/mol/agents/playwright-test-healer.md +1 -1
- package/presets/opencode/mol/agents/playwright-test-planner.md +1 -1
- package/presets/opencode/mol/agents/qa-tester.md +1 -1
- package/presets/opencode/mol/agents/security-reviewer.md +1 -1
- package/presets/opencode/mol/agents/solution-architect.md +1 -1
- package/presets/opencode/mol/agents/task-analyst.md +1 -1
- package/presets/opencode/mol/agents/task-router.md +1 -1
- package/presets/opencode/mol/agents/tech-writer.md +1 -1
- package/presets/opencode/mol/agents/unit-test-generator.md +1 -1
- package/presets/opencode/mol/agents/unit-test-healer.md +1 -1
- package/presets/opencode/mol/agents/unit-test-planner.md +1 -1
- package/presets/opencode/mol/commands/task-continue.md +1 -1
- package/presets/opencode/mol/hooks/README.md +11 -1
- package/presets/opencode/mol/hooks/guard-shell-command.mjs +153 -0
- package/presets/opencode/mol/plugins/rule-attach/globs.json +112 -0
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/next/OPENCODE.md +5 -55
- package/presets/opencode/next/adapter-map.json +56 -56
- package/presets/opencode/next/agents/accessibility-reviewer.md +1 -1
- package/presets/opencode/next/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/next/agents/build-verifier.md +3 -2
- package/presets/opencode/next/agents/ci-investigator.md +1 -1
- package/presets/opencode/next/agents/code-reviewer.md +1 -1
- package/presets/opencode/next/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/next/agents/debugger.md +1 -1
- package/presets/opencode/next/agents/feature-developer.md +2 -2
- package/presets/opencode/next/agents/migration-specialist.md +1 -1
- package/presets/opencode/next/agents/mockup-reviewer.md +1 -1
- package/presets/opencode/next/agents/openspec-author.md +1 -1
- package/presets/opencode/next/agents/performance-auditor.md +1 -1
- package/presets/opencode/next/agents/playwright-test-generator.md +1 -1
- package/presets/opencode/next/agents/playwright-test-healer.md +1 -1
- package/presets/opencode/next/agents/playwright-test-planner.md +1 -1
- package/presets/opencode/next/agents/qa-tester.md +1 -1
- package/presets/opencode/next/agents/security-reviewer.md +1 -1
- package/presets/opencode/next/agents/solution-architect.md +1 -1
- package/presets/opencode/next/agents/task-analyst.md +1 -1
- package/presets/opencode/next/agents/task-router.md +1 -1
- package/presets/opencode/next/agents/tech-writer.md +1 -1
- package/presets/opencode/next/agents/unit-test-generator.md +1 -1
- package/presets/opencode/next/agents/unit-test-healer.md +1 -1
- package/presets/opencode/next/agents/unit-test-planner.md +1 -1
- package/presets/opencode/next/commands/task-continue.md +1 -1
- package/presets/opencode/next/hooks/README.md +11 -1
- package/presets/opencode/next/hooks/guard-shell-command.mjs +153 -0
- package/presets/opencode/next/plugins/rule-attach/globs.json +276 -0
- package/presets/opencode/next/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/nuxt/OPENCODE.md +5 -54
- package/presets/opencode/nuxt/adapter-map.json +51 -51
- package/presets/opencode/nuxt/agents/accessibility-reviewer.md +1 -1
- package/presets/opencode/nuxt/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/nuxt/agents/build-verifier.md +1 -1
- package/presets/opencode/nuxt/agents/ci-investigator.md +1 -1
- package/presets/opencode/nuxt/agents/code-reviewer.md +1 -1
- package/presets/opencode/nuxt/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/nuxt/agents/debugger.md +1 -1
- package/presets/opencode/nuxt/agents/feature-developer.md +1 -1
- package/presets/opencode/nuxt/agents/migration-specialist.md +1 -1
- package/presets/opencode/nuxt/agents/mockup-reviewer.md +1 -1
- package/presets/opencode/nuxt/agents/openspec-author.md +1 -1
- package/presets/opencode/nuxt/agents/performance-auditor.md +1 -1
- package/presets/opencode/nuxt/agents/playwright-test-generator.md +1 -1
- package/presets/opencode/nuxt/agents/playwright-test-healer.md +1 -1
- package/presets/opencode/nuxt/agents/playwright-test-planner.md +1 -1
- package/presets/opencode/nuxt/agents/qa-tester.md +1 -1
- package/presets/opencode/nuxt/agents/security-reviewer.md +1 -1
- package/presets/opencode/nuxt/agents/solution-architect.md +1 -1
- package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
- package/presets/opencode/nuxt/agents/task-router.md +1 -1
- package/presets/opencode/nuxt/agents/tech-writer.md +1 -1
- package/presets/opencode/nuxt/agents/unit-test-generator.md +1 -1
- package/presets/opencode/nuxt/agents/unit-test-healer.md +1 -1
- package/presets/opencode/nuxt/agents/unit-test-planner.md +1 -1
- package/presets/opencode/nuxt/commands/task-continue.md +1 -1
- package/presets/opencode/nuxt/hooks/README.md +11 -1
- package/presets/opencode/nuxt/hooks/guard-shell-command.mjs +153 -0
- package/presets/opencode/nuxt/plugins/rule-attach/globs.json +266 -0
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/php-hexagonal/OPENCODE.md +5 -60
- package/presets/opencode/php-hexagonal/adapter-map.json +45 -45
- package/presets/opencode/php-hexagonal/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/build-verifier.md +1 -1
- package/presets/opencode/php-hexagonal/agents/ci-investigator.md +1 -1
- package/presets/opencode/php-hexagonal/agents/code-reviewer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/debugger.md +1 -1
- package/presets/opencode/php-hexagonal/agents/feature-developer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/integration-test-generator.md +1 -1
- package/presets/opencode/php-hexagonal/agents/integration-test-healer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/integration-test-planner.md +1 -1
- package/presets/opencode/php-hexagonal/agents/migration-specialist.md +1 -1
- package/presets/opencode/php-hexagonal/agents/openspec-author.md +1 -1
- package/presets/opencode/php-hexagonal/agents/performance-auditor.md +1 -1
- package/presets/opencode/php-hexagonal/agents/qa-tester.md +1 -1
- package/presets/opencode/php-hexagonal/agents/security-reviewer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/solution-architect.md +1 -1
- package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/opencode/php-hexagonal/agents/task-router.md +1 -1
- package/presets/opencode/php-hexagonal/agents/tech-writer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/unit-test-generator.md +1 -1
- package/presets/opencode/php-hexagonal/agents/unit-test-healer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/unit-test-planner.md +1 -1
- package/presets/opencode/php-hexagonal/commands/task-continue.md +1 -1
- package/presets/opencode/php-hexagonal/hooks/README.md +11 -1
- package/presets/opencode/php-hexagonal/hooks/guard-shell-command.mjs +155 -0
- package/presets/opencode/php-hexagonal/plugins/rule-attach/globs.json +242 -0
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/php-laravel/OPENCODE.md +5 -60
- package/presets/opencode/php-laravel/adapter-map.json +45 -45
- package/presets/opencode/php-laravel/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/php-laravel/agents/build-verifier.md +1 -1
- package/presets/opencode/php-laravel/agents/ci-investigator.md +1 -1
- package/presets/opencode/php-laravel/agents/code-reviewer.md +1 -1
- package/presets/opencode/php-laravel/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/php-laravel/agents/debugger.md +1 -1
- package/presets/opencode/php-laravel/agents/feature-developer.md +1 -1
- package/presets/opencode/php-laravel/agents/integration-test-generator.md +1 -1
- package/presets/opencode/php-laravel/agents/integration-test-healer.md +1 -1
- package/presets/opencode/php-laravel/agents/integration-test-planner.md +1 -1
- package/presets/opencode/php-laravel/agents/migration-specialist.md +1 -1
- package/presets/opencode/php-laravel/agents/openspec-author.md +1 -1
- package/presets/opencode/php-laravel/agents/performance-auditor.md +1 -1
- package/presets/opencode/php-laravel/agents/qa-tester.md +1 -1
- package/presets/opencode/php-laravel/agents/security-reviewer.md +1 -1
- package/presets/opencode/php-laravel/agents/solution-architect.md +1 -1
- package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
- package/presets/opencode/php-laravel/agents/task-router.md +1 -1
- package/presets/opencode/php-laravel/agents/tech-writer.md +1 -1
- package/presets/opencode/php-laravel/agents/unit-test-generator.md +1 -1
- package/presets/opencode/php-laravel/agents/unit-test-healer.md +1 -1
- package/presets/opencode/php-laravel/agents/unit-test-planner.md +1 -1
- package/presets/opencode/php-laravel/commands/task-continue.md +1 -1
- package/presets/opencode/php-laravel/hooks/README.md +11 -1
- package/presets/opencode/php-laravel/hooks/guard-shell-command.mjs +155 -0
- package/presets/opencode/php-laravel/plugins/rule-attach/globs.json +232 -0
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/platform-contract.json +4 -0
- package/presets/opencode/plugins/output-guard/README.md +1 -1
- package/presets/opencode/plugins/output-guard/index.ts +8 -2
- package/presets/opencode/plugins/output-guard/rewrite.ts +37 -0
- package/presets/opencode/plugins/rule-attach/README.md +34 -0
- package/presets/opencode/plugins/rule-attach/attach.ts +224 -0
- package/presets/opencode/plugins/rule-attach/index.ts +169 -0
- package/presets/opencode/plugins/rule-attach/package.json +9 -0
- package/presets/opencode/plugins/task-status/README.md +1 -1
- package/presets/opencode/plugins/task-status/deepseek.ts +13 -3
- package/presets/opencode/plugins/task-status/task-view.ts +4 -1
- package/presets/opencode/plugins/task-status/tui.tsx +4 -6
- package/presets/opencode/plugins/task-status/types.ts +5 -1
- package/presets/opencode/svelte/OPENCODE.md +5 -54
- package/presets/opencode/svelte/adapter-map.json +51 -51
- package/presets/opencode/svelte/agents/accessibility-reviewer.md +1 -1
- package/presets/opencode/svelte/agents/api-contract-reviewer.md +1 -1
- package/presets/opencode/svelte/agents/build-verifier.md +1 -1
- package/presets/opencode/svelte/agents/ci-investigator.md +1 -1
- package/presets/opencode/svelte/agents/code-reviewer.md +1 -1
- package/presets/opencode/svelte/agents/codebase-analyzer.md +1 -1
- package/presets/opencode/svelte/agents/debugger.md +1 -1
- package/presets/opencode/svelte/agents/feature-developer.md +1 -1
- package/presets/opencode/svelte/agents/migration-specialist.md +1 -1
- package/presets/opencode/svelte/agents/mockup-reviewer.md +1 -1
- package/presets/opencode/svelte/agents/openspec-author.md +1 -1
- package/presets/opencode/svelte/agents/performance-auditor.md +1 -1
- package/presets/opencode/svelte/agents/playwright-test-generator.md +1 -1
- package/presets/opencode/svelte/agents/playwright-test-healer.md +1 -1
- package/presets/opencode/svelte/agents/playwright-test-planner.md +1 -1
- package/presets/opencode/svelte/agents/qa-tester.md +1 -1
- package/presets/opencode/svelte/agents/security-reviewer.md +1 -1
- package/presets/opencode/svelte/agents/solution-architect.md +1 -1
- package/presets/opencode/svelte/agents/task-analyst.md +1 -1
- package/presets/opencode/svelte/agents/task-router.md +1 -1
- package/presets/opencode/svelte/agents/tech-writer.md +1 -1
- package/presets/opencode/svelte/agents/unit-test-generator.md +1 -1
- package/presets/opencode/svelte/agents/unit-test-healer.md +1 -1
- package/presets/opencode/svelte/agents/unit-test-planner.md +1 -1
- package/presets/opencode/svelte/commands/task-continue.md +1 -1
- package/presets/opencode/svelte/hooks/README.md +11 -1
- package/presets/opencode/svelte/hooks/guard-shell-command.mjs +153 -0
- package/presets/opencode/svelte/plugins/rule-attach/globs.json +245 -0
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/next/adapter-map.json +1 -1
- package/presets/zcode/next/agents/build-verifier.md +2 -1
- package/presets/zcode/next/agents/feature-developer.md +1 -1
- package/presets/zcode/next/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +3 -3
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +3 -3
- package/scripts/report-context-cost.mjs +1 -20
|
@@ -8,127 +8,147 @@ const SERVER_COMMAND = new RegExp("go\\s+run|air(\\s|$)");
|
|
|
8
8
|
const SERVER_PORTS = [8080];
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import net from 'node:net';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
11
13
|
|
|
12
|
-
const
|
|
14
|
+
const allowed = () => ({ permission: 'allow' });
|
|
13
15
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const ask = (userMessage, agentMessage) => ({
|
|
17
|
+
permission: 'ask',
|
|
18
|
+
user_message: userMessage,
|
|
19
|
+
agent_message: agentMessage || userMessage,
|
|
20
|
+
});
|
|
18
21
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const portIsOpen = (port) =>
|
|
23
|
+
new Promise((resolve) => {
|
|
24
|
+
const socket = net.createConnection({ host: '127.0.0.1', port });
|
|
25
|
+
const done = (open) => {
|
|
26
|
+
socket.destroy();
|
|
27
|
+
resolve(open);
|
|
28
|
+
};
|
|
29
|
+
socket.once('connect', () => done(true));
|
|
30
|
+
socket.once('error', () => done(false));
|
|
31
|
+
socket.setTimeout(400, () => done(false));
|
|
32
|
+
});
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The decision for one shell event: `{ permission, user_message, agent_message }`.
|
|
36
|
+
*
|
|
37
|
+
* Shared by the CLI below and any host that can import the rendered file, so
|
|
38
|
+
* the verdict cannot drift between them. Two effects are injected — a project
|
|
39
|
+
* file read and a TCP probe — because a plugin has no stdin to read and no
|
|
40
|
+
* guaranteed working directory. Never throws: an unreadable event is an allow,
|
|
41
|
+
* the same fail-open the hook always had.
|
|
42
|
+
*/
|
|
43
|
+
export const evaluate = async (event, options = {}) => {
|
|
44
|
+
const {
|
|
45
|
+
root = process.cwd(),
|
|
46
|
+
exists = (file) => fs.existsSync(file),
|
|
47
|
+
readText = (file) => fs.readFileSync(file, 'utf8'),
|
|
48
|
+
canConnect = portIsOpen,
|
|
49
|
+
} = options;
|
|
50
|
+
const at = (file) => path.join(root, file);
|
|
51
|
+
if (!event || typeof event !== 'object') return allowed();
|
|
52
|
+
|
|
53
|
+
const command = String(event.command || event.input?.command || event.tool_input?.command || '');
|
|
54
|
+
if (!command.trim()) return allowed();
|
|
55
|
+
|
|
56
|
+
const dangerousGit = /\bgit\s+(reset\s+--hard|clean\s+-[^\n]*f|push\s+--force|push\s+-f|checkout\s+--\s+)/;
|
|
57
|
+
if (dangerousGit.test(command)) {
|
|
58
|
+
return ask(
|
|
59
|
+
'This command looks destructive for git state. Review it before continuing.',
|
|
60
|
+
'A project hook flagged a destructive git command. Ask the user before running it.',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
32
63
|
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
if (/\b(?:pkill|killall)\b|\bxargs\s+kill\b/.test(command)) {
|
|
65
|
+
return ask(
|
|
66
|
+
'This command can stop processes the task does not own. Name the process you started, or use `node .ai.local/scripts/processes.mjs stop`.',
|
|
67
|
+
'Never mass-kill processes. Stop the recorded pid through processes.mjs; ask before pkill, killall, or xargs kill.',
|
|
68
|
+
);
|
|
69
|
+
}
|
|
35
70
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
71
|
+
const managerByFile = [
|
|
72
|
+
['yarn.lock', 'yarn'],
|
|
73
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
74
|
+
['package-lock.json', 'npm'],
|
|
75
|
+
].find(([file]) => exists(at(file)));
|
|
76
|
+
|
|
77
|
+
let expected = managerByFile?.[1];
|
|
78
|
+
if (!expected && exists(at('package.json'))) {
|
|
79
|
+
try {
|
|
80
|
+
const pkg = JSON.parse(readText(at('package.json')));
|
|
81
|
+
const pm = typeof pkg.packageManager === 'string' ? pkg.packageManager : '';
|
|
82
|
+
expected = pm.split('@')[0] || undefined;
|
|
83
|
+
} catch {
|
|
84
|
+
// Ignore invalid package.json in the hook; the agent can diagnose it later.
|
|
45
85
|
}
|
|
46
|
-
answer({ hookSpecificOutput });
|
|
47
86
|
}
|
|
48
|
-
answer({
|
|
49
|
-
permission,
|
|
50
|
-
user_message: userMessage,
|
|
51
|
-
agent_message: agentMessage || userMessage,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
87
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
88
|
+
const used = expected ? command.match(/(^|[;&|]\s*)(npm|yarn|pnpm)\s+/)?.[2] : undefined;
|
|
89
|
+
if (used && used !== expected) {
|
|
90
|
+
return ask(
|
|
91
|
+
`This repository appears to use ${expected}, but the command uses ${used}. Confirm before continuing.`,
|
|
92
|
+
`Use ${expected} for package scripts and installs unless the user explicitly approves ${used}.`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
58
95
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
96
|
+
// Only a server-start shaped command is worth probing: the hook must not slow
|
|
97
|
+
// down or interrogate every shell call.
|
|
98
|
+
const explicitPortMatch = command.match(/--port[=\s]+(\d{2,5})|\bPORT=(\d{2,5})/);
|
|
99
|
+
const explicitPort = Number(explicitPortMatch?.[1] || explicitPortMatch?.[2] || 0) || null;
|
|
100
|
+
const startsServer = SERVER_COMMAND ? SERVER_COMMAND.test(command) : false;
|
|
101
|
+
const portsToProbe = startsServer ? (explicitPort ? [explicitPort] : SERVER_PORTS) : [];
|
|
102
|
+
|
|
103
|
+
for (const port of portsToProbe) {
|
|
104
|
+
if (!(await canConnect(port))) continue;
|
|
105
|
+
return ask(
|
|
106
|
+
`Port ${port} is already listening. Reuse the running server, or stop the recorded process before starting another.`,
|
|
107
|
+
`A server may already serve port ${port}. Probe it first, reuse it, or stop it with \`node .ai.local/scripts/processes.mjs stop\`; never start a duplicate.`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
67
110
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'ask',
|
|
71
|
-
'This command can stop processes the task does not own. Name the process you started, or use `node .ai.local/scripts/processes.mjs stop`.',
|
|
72
|
-
'Never mass-kill processes. Stop the recorded pid through processes.mjs; ask before pkill, killall, or xargs kill.',
|
|
73
|
-
);
|
|
74
|
-
}
|
|
111
|
+
return allowed();
|
|
112
|
+
};
|
|
75
113
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
/** The host answers: Claude's `PreToolUse` envelope, or the neutral decision. */
|
|
115
|
+
const answer = (event, decision) => {
|
|
116
|
+
const claudePreTool = event !== null && event.hook_event_name === 'PreToolUse';
|
|
117
|
+
if (!claudePreTool) {
|
|
118
|
+
process.stdout.write(JSON.stringify(decision));
|
|
119
|
+
} else {
|
|
120
|
+
const verdict = decision.permission === 'ask' || decision.permission === 'deny' ? decision.permission : 'allow';
|
|
121
|
+
const hookSpecificOutput = { hookEventName: 'PreToolUse', permissionDecision: verdict };
|
|
122
|
+
if (decision.user_message && verdict !== 'allow') {
|
|
123
|
+
hookSpecificOutput.permissionDecisionReason = decision.user_message;
|
|
124
|
+
}
|
|
125
|
+
process.stdout.write(JSON.stringify({ hookSpecificOutput }));
|
|
126
|
+
}
|
|
127
|
+
process.exit(0);
|
|
128
|
+
};
|
|
81
129
|
|
|
82
|
-
|
|
83
|
-
|
|
130
|
+
const main = async () => {
|
|
131
|
+
let event = null;
|
|
84
132
|
try {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
expected = pm.split('@')[0] || undefined;
|
|
133
|
+
const parsed = JSON.parse(fs.readFileSync(0, 'utf8'));
|
|
134
|
+
event = parsed && typeof parsed === 'object' ? parsed : null;
|
|
88
135
|
} catch {
|
|
89
|
-
|
|
136
|
+
event = null;
|
|
90
137
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!expected) {
|
|
94
|
-
expected = undefined;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const used = expected ? command.match(/(^|[;&|]\s*)(npm|yarn|pnpm)\s+/)?.[2] : undefined;
|
|
98
|
-
if (used && used !== expected) {
|
|
99
|
-
out(
|
|
100
|
-
'ask',
|
|
101
|
-
`This repository appears to use ${expected}, but the command uses ${used}. Confirm before continuing.`,
|
|
102
|
-
`Use ${expected} for package scripts and installs unless the user explicitly approves ${used}.`,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
138
|
+
answer(event, await evaluate(event));
|
|
139
|
+
};
|
|
105
140
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
141
|
+
const invokedDirectly = (() => {
|
|
142
|
+
if (process.argv[1] === undefined) return false;
|
|
143
|
+
// Realpath on both sides: `os.tmpdir()` and `/tmp` are symlinks on macOS, so a
|
|
144
|
+
// plain resolve marks a script it cannot start.
|
|
145
|
+
try {
|
|
146
|
+
return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
147
|
+
} catch {
|
|
148
|
+
return path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
|
|
149
|
+
}
|
|
150
|
+
})();
|
|
117
151
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const explicitPortMatch = command.match(/--port[=\s]+(\d{2,5})|\bPORT=(\d{2,5})/);
|
|
121
|
-
const explicitPort = Number(explicitPortMatch?.[1] || explicitPortMatch?.[2] || 0) || null;
|
|
122
|
-
const startsServer = SERVER_COMMAND ? SERVER_COMMAND.test(command) : false;
|
|
123
|
-
const portsToProbe = startsServer ? (explicitPort ? [explicitPort] : SERVER_PORTS) : [];
|
|
124
|
-
|
|
125
|
-
for (const port of portsToProbe) {
|
|
126
|
-
if (!(await portIsOpen(port))) continue;
|
|
127
|
-
out(
|
|
128
|
-
'ask',
|
|
129
|
-
`Port ${port} is already listening. Reuse the running server, or stop the recorded process before starting another.`,
|
|
130
|
-
`A server may already serve port ${port}. Probe it first, reuse it, or stop it with \`node .ai.local/scripts/processes.mjs stop\`; never start a duplicate.`,
|
|
131
|
-
);
|
|
152
|
+
if (invokedDirectly) {
|
|
153
|
+
await main();
|
|
132
154
|
}
|
|
133
|
-
|
|
134
|
-
out('allow');
|
|
@@ -196,12 +196,12 @@ Use Task tool or `/agent-name`. Pass: slug, artifact paths, step `scope` if set.
|
|
|
196
196
|
### Model when invoking (Task)
|
|
197
197
|
|
|
198
198
|
1. Read `steps[i].model` if present; else use the agent’s frontmatter `model` (see `agents/README.md` matrix).
|
|
199
|
-
2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file
|
|
199
|
+
2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file is an approved map. An empty `tiers` object with an empty `approvedBy` is the unfilled template: omit the model and the session model applies. Once `approvedBy` is set or any tier value is set, the file is the map, so passing an explicit model is allowed. Pass the resolved `providerID/modelID` (or `providerID/modelID#variant`) to the Task/subagent tool.
|
|
200
200
|
- **`cheap`** → router, analyst, tech-writer, codebase-analyzer, and the review roles `code-reviewer`, `build-verifier`, `api-contract-reviewer`, `mockup-reviewer`. Resolve the provider through `.ai.local/team/model-tiers.json`. Do not write a provider id into the agent file. Pass the mapped id as written; do not append `#high`.
|
|
201
201
|
- **`standard`** → implementation and the other non-review specialists. `feature-developer` stays on this tier.
|
|
202
202
|
- **`strong`** → architecture, security, migration, performance. Never downgrade a `strong` step to the parent default, and do not put `mockup-reviewer` on `strong`.
|
|
203
|
-
- When `steps[i].model` is omitted and the agent file has no `model`, those four review roles stay `cheap` when
|
|
204
|
-
- If a tier is declared
|
|
203
|
+
- When `steps[i].model` is omitted and the agent file has no `model`, those four review roles stay `cheap` when the map has a `cheap` value. Without the file, or while the template is still empty, omit the model and the session model applies.
|
|
204
|
+
- If a tier is declared, the map is approved, and that tier has no mapping, **STOP** and report `model-tier-unmapped`; do not silently inherit the parent model.
|
|
205
205
|
3. If the tool does not accept a model (Cursor/Claude adapters), record the resolved tier in the handoff and let the platform pin apply.
|
|
206
206
|
4. Parallel steps: apply the step-level `model` to **each** agent in the array (or omit → each agent’s own frontmatter).
|
|
207
207
|
5. The tier never changes the step order, gates, receipts, or retry policy.
|
|
@@ -8,127 +8,147 @@ const SERVER_COMMAND = null;
|
|
|
8
8
|
const SERVER_PORTS = [];
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import net from 'node:net';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
11
13
|
|
|
12
|
-
const
|
|
14
|
+
const allowed = () => ({ permission: 'allow' });
|
|
13
15
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const ask = (userMessage, agentMessage) => ({
|
|
17
|
+
permission: 'ask',
|
|
18
|
+
user_message: userMessage,
|
|
19
|
+
agent_message: agentMessage || userMessage,
|
|
20
|
+
});
|
|
18
21
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const portIsOpen = (port) =>
|
|
23
|
+
new Promise((resolve) => {
|
|
24
|
+
const socket = net.createConnection({ host: '127.0.0.1', port });
|
|
25
|
+
const done = (open) => {
|
|
26
|
+
socket.destroy();
|
|
27
|
+
resolve(open);
|
|
28
|
+
};
|
|
29
|
+
socket.once('connect', () => done(true));
|
|
30
|
+
socket.once('error', () => done(false));
|
|
31
|
+
socket.setTimeout(400, () => done(false));
|
|
32
|
+
});
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The decision for one shell event: `{ permission, user_message, agent_message }`.
|
|
36
|
+
*
|
|
37
|
+
* Shared by the CLI below and any host that can import the rendered file, so
|
|
38
|
+
* the verdict cannot drift between them. Two effects are injected — a project
|
|
39
|
+
* file read and a TCP probe — because a plugin has no stdin to read and no
|
|
40
|
+
* guaranteed working directory. Never throws: an unreadable event is an allow,
|
|
41
|
+
* the same fail-open the hook always had.
|
|
42
|
+
*/
|
|
43
|
+
export const evaluate = async (event, options = {}) => {
|
|
44
|
+
const {
|
|
45
|
+
root = process.cwd(),
|
|
46
|
+
exists = (file) => fs.existsSync(file),
|
|
47
|
+
readText = (file) => fs.readFileSync(file, 'utf8'),
|
|
48
|
+
canConnect = portIsOpen,
|
|
49
|
+
} = options;
|
|
50
|
+
const at = (file) => path.join(root, file);
|
|
51
|
+
if (!event || typeof event !== 'object') return allowed();
|
|
52
|
+
|
|
53
|
+
const command = String(event.command || event.input?.command || event.tool_input?.command || '');
|
|
54
|
+
if (!command.trim()) return allowed();
|
|
55
|
+
|
|
56
|
+
const dangerousGit = /\bgit\s+(reset\s+--hard|clean\s+-[^\n]*f|push\s+--force|push\s+-f|checkout\s+--\s+)/;
|
|
57
|
+
if (dangerousGit.test(command)) {
|
|
58
|
+
return ask(
|
|
59
|
+
'This command looks destructive for git state. Review it before continuing.',
|
|
60
|
+
'A project hook flagged a destructive git command. Ask the user before running it.',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
32
63
|
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
if (/\b(?:pkill|killall)\b|\bxargs\s+kill\b/.test(command)) {
|
|
65
|
+
return ask(
|
|
66
|
+
'This command can stop processes the task does not own. Name the process you started, or use `node .ai.local/scripts/processes.mjs stop`.',
|
|
67
|
+
'Never mass-kill processes. Stop the recorded pid through processes.mjs; ask before pkill, killall, or xargs kill.',
|
|
68
|
+
);
|
|
69
|
+
}
|
|
35
70
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
71
|
+
const managerByFile = [
|
|
72
|
+
['yarn.lock', 'yarn'],
|
|
73
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
74
|
+
['package-lock.json', 'npm'],
|
|
75
|
+
].find(([file]) => exists(at(file)));
|
|
76
|
+
|
|
77
|
+
let expected = managerByFile?.[1];
|
|
78
|
+
if (!expected && exists(at('package.json'))) {
|
|
79
|
+
try {
|
|
80
|
+
const pkg = JSON.parse(readText(at('package.json')));
|
|
81
|
+
const pm = typeof pkg.packageManager === 'string' ? pkg.packageManager : '';
|
|
82
|
+
expected = pm.split('@')[0] || undefined;
|
|
83
|
+
} catch {
|
|
84
|
+
// Ignore invalid package.json in the hook; the agent can diagnose it later.
|
|
45
85
|
}
|
|
46
|
-
answer({ hookSpecificOutput });
|
|
47
86
|
}
|
|
48
|
-
answer({
|
|
49
|
-
permission,
|
|
50
|
-
user_message: userMessage,
|
|
51
|
-
agent_message: agentMessage || userMessage,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
87
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
88
|
+
const used = expected ? command.match(/(^|[;&|]\s*)(npm|yarn|pnpm)\s+/)?.[2] : undefined;
|
|
89
|
+
if (used && used !== expected) {
|
|
90
|
+
return ask(
|
|
91
|
+
`This repository appears to use ${expected}, but the command uses ${used}. Confirm before continuing.`,
|
|
92
|
+
`Use ${expected} for package scripts and installs unless the user explicitly approves ${used}.`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
58
95
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
96
|
+
// Only a server-start shaped command is worth probing: the hook must not slow
|
|
97
|
+
// down or interrogate every shell call.
|
|
98
|
+
const explicitPortMatch = command.match(/--port[=\s]+(\d{2,5})|\bPORT=(\d{2,5})/);
|
|
99
|
+
const explicitPort = Number(explicitPortMatch?.[1] || explicitPortMatch?.[2] || 0) || null;
|
|
100
|
+
const startsServer = SERVER_COMMAND ? SERVER_COMMAND.test(command) : false;
|
|
101
|
+
const portsToProbe = startsServer ? (explicitPort ? [explicitPort] : SERVER_PORTS) : [];
|
|
102
|
+
|
|
103
|
+
for (const port of portsToProbe) {
|
|
104
|
+
if (!(await canConnect(port))) continue;
|
|
105
|
+
return ask(
|
|
106
|
+
`Port ${port} is already listening. Reuse the running server, or stop the recorded process before starting another.`,
|
|
107
|
+
`A server may already serve port ${port}. Probe it first, reuse it, or stop it with \`node .ai.local/scripts/processes.mjs stop\`; never start a duplicate.`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
67
110
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'ask',
|
|
71
|
-
'This command can stop processes the task does not own. Name the process you started, or use `node .ai.local/scripts/processes.mjs stop`.',
|
|
72
|
-
'Never mass-kill processes. Stop the recorded pid through processes.mjs; ask before pkill, killall, or xargs kill.',
|
|
73
|
-
);
|
|
74
|
-
}
|
|
111
|
+
return allowed();
|
|
112
|
+
};
|
|
75
113
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
/** The host answers: Claude's `PreToolUse` envelope, or the neutral decision. */
|
|
115
|
+
const answer = (event, decision) => {
|
|
116
|
+
const claudePreTool = event !== null && event.hook_event_name === 'PreToolUse';
|
|
117
|
+
if (!claudePreTool) {
|
|
118
|
+
process.stdout.write(JSON.stringify(decision));
|
|
119
|
+
} else {
|
|
120
|
+
const verdict = decision.permission === 'ask' || decision.permission === 'deny' ? decision.permission : 'allow';
|
|
121
|
+
const hookSpecificOutput = { hookEventName: 'PreToolUse', permissionDecision: verdict };
|
|
122
|
+
if (decision.user_message && verdict !== 'allow') {
|
|
123
|
+
hookSpecificOutput.permissionDecisionReason = decision.user_message;
|
|
124
|
+
}
|
|
125
|
+
process.stdout.write(JSON.stringify({ hookSpecificOutput }));
|
|
126
|
+
}
|
|
127
|
+
process.exit(0);
|
|
128
|
+
};
|
|
81
129
|
|
|
82
|
-
|
|
83
|
-
|
|
130
|
+
const main = async () => {
|
|
131
|
+
let event = null;
|
|
84
132
|
try {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
expected = pm.split('@')[0] || undefined;
|
|
133
|
+
const parsed = JSON.parse(fs.readFileSync(0, 'utf8'));
|
|
134
|
+
event = parsed && typeof parsed === 'object' ? parsed : null;
|
|
88
135
|
} catch {
|
|
89
|
-
|
|
136
|
+
event = null;
|
|
90
137
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!expected) {
|
|
94
|
-
expected = undefined;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const used = expected ? command.match(/(^|[;&|]\s*)(npm|yarn|pnpm)\s+/)?.[2] : undefined;
|
|
98
|
-
if (used && used !== expected) {
|
|
99
|
-
out(
|
|
100
|
-
'ask',
|
|
101
|
-
`This repository appears to use ${expected}, but the command uses ${used}. Confirm before continuing.`,
|
|
102
|
-
`Use ${expected} for package scripts and installs unless the user explicitly approves ${used}.`,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
138
|
+
answer(event, await evaluate(event));
|
|
139
|
+
};
|
|
105
140
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
141
|
+
const invokedDirectly = (() => {
|
|
142
|
+
if (process.argv[1] === undefined) return false;
|
|
143
|
+
// Realpath on both sides: `os.tmpdir()` and `/tmp` are symlinks on macOS, so a
|
|
144
|
+
// plain resolve marks a script it cannot start.
|
|
145
|
+
try {
|
|
146
|
+
return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
147
|
+
} catch {
|
|
148
|
+
return path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
|
|
149
|
+
}
|
|
150
|
+
})();
|
|
117
151
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const explicitPortMatch = command.match(/--port[=\s]+(\d{2,5})|\bPORT=(\d{2,5})/);
|
|
121
|
-
const explicitPort = Number(explicitPortMatch?.[1] || explicitPortMatch?.[2] || 0) || null;
|
|
122
|
-
const startsServer = SERVER_COMMAND ? SERVER_COMMAND.test(command) : false;
|
|
123
|
-
const portsToProbe = startsServer ? (explicitPort ? [explicitPort] : SERVER_PORTS) : [];
|
|
124
|
-
|
|
125
|
-
for (const port of portsToProbe) {
|
|
126
|
-
if (!(await portIsOpen(port))) continue;
|
|
127
|
-
out(
|
|
128
|
-
'ask',
|
|
129
|
-
`Port ${port} is already listening. Reuse the running server, or stop the recorded process before starting another.`,
|
|
130
|
-
`A server may already serve port ${port}. Probe it first, reuse it, or stop it with \`node .ai.local/scripts/processes.mjs stop\`; never start a duplicate.`,
|
|
131
|
-
);
|
|
152
|
+
if (invokedDirectly) {
|
|
153
|
+
await main();
|
|
132
154
|
}
|
|
133
|
-
|
|
134
|
-
out('allow');
|
|
@@ -156,12 +156,12 @@ On each `subagentStop`, the hook reconciles `status.state` from the completing p
|
|
|
156
156
|
## Model when invoking (Task)
|
|
157
157
|
|
|
158
158
|
1. Read `steps[i].model` if present; else use the agent’s frontmatter `model` (see `agents/README.md` matrix).
|
|
159
|
-
2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file
|
|
159
|
+
2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file is an approved map. An empty `tiers` object with an empty `approvedBy` is the unfilled template: omit the model and the session model applies. Once `approvedBy` is set or any tier value is set, the file is the map, so passing an explicit model is allowed. Pass the resolved `providerID/modelID` (or `providerID/modelID#variant`) to the Task/subagent tool.
|
|
160
160
|
- **`cheap`** → router, analyst, tech-writer, codebase-analyzer, and the review roles `code-reviewer`, `build-verifier`, `api-contract-reviewer`, `mockup-reviewer`. Resolve the provider through `.ai.local/team/model-tiers.json`. Do not write a provider id into the agent file. Pass the mapped id as written; do not append `#high`.
|
|
161
161
|
- **`standard`** → implementation and the other non-review specialists. `feature-developer` stays on this tier.
|
|
162
162
|
- **`strong`** → architecture, security, migration, performance. Never downgrade a `strong` step to the parent default, and do not put `mockup-reviewer` on `strong`.
|
|
163
|
-
- When `steps[i].model` is omitted and the agent file has no `model`, those four review roles stay `cheap` when
|
|
164
|
-
- If a tier is declared
|
|
163
|
+
- When `steps[i].model` is omitted and the agent file has no `model`, those four review roles stay `cheap` when the map has a `cheap` value. Without the file, or while the template is still empty, omit the model and the session model applies.
|
|
164
|
+
- If a tier is declared, the map is approved, and that tier has no mapping, **STOP** and report `model-tier-unmapped`; do not silently inherit the parent model.
|
|
165
165
|
3. If the tool does not accept a model (Cursor/Claude adapters), record the resolved tier in the handoff and let the platform pin apply.
|
|
166
166
|
4. Parallel steps: apply the step-level `model` to **each** agent in the array (or omit → each agent’s own frontmatter).
|
|
167
167
|
5. The tier never changes the step order, gates, receipts, or retry policy.
|