@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonesofspring/ai-rules",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.87",
|
|
4
4
|
"description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Revy Ross",
|
|
@@ -40,10 +40,12 @@
|
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
42
|
"check:fast": "bash scripts/check-preset-fast.sh",
|
|
43
|
+
"check:classified": "node scripts/run-classified-gates.mjs",
|
|
43
44
|
"check:changed": "node scripts/check-preset-delta.mjs --base HEAD",
|
|
44
45
|
"check:task": "node scripts/check-preset-delta.mjs --since-task",
|
|
45
46
|
"test:hooks": "node scripts/test-chain-team-phases-coverage.mjs && node scripts/test-chain-team-phases-resume-blocked.mjs && node scripts/test-agent-task-metrics-hooks.mjs && node scripts/test-chain-team-phases-dev-cleanup.mjs",
|
|
46
47
|
"check:preset-structure": "bash scripts/check-preset-structure.sh",
|
|
48
|
+
"test:tooling": "node scripts/run-locked.mjs --label test:tooling -- bash scripts/run-tooling-tests.sh",
|
|
47
49
|
"release:gate": "bash scripts/release-gate.sh",
|
|
48
50
|
"check:platform-scripts": "node scripts/check-platform-scripts.mjs",
|
|
49
51
|
"test:platform": "node scripts/run-platform-tests.mjs",
|
|
@@ -149,7 +151,8 @@
|
|
|
149
151
|
"check:zcode-local-overlay": "node scripts/check-zcode-local-overlay.mjs",
|
|
150
152
|
"test:opencode-context-budget": "node scripts/test-opencode-context-budget.mjs",
|
|
151
153
|
"test:probe-mavis-capabilities": "node scripts/test-probe-mavis-capabilities.mjs",
|
|
152
|
-
"
|
|
154
|
+
"check:task-receipt": "node scripts/check-task-receipt.mjs",
|
|
155
|
+
"preset:loop": "yarn fix:generated && yarn check:classified",
|
|
153
156
|
"fix:generated": "node scripts/fix-generated.mjs",
|
|
154
157
|
"generate:claude": "node scripts/generate-claude.mjs",
|
|
155
158
|
"generate:mavis": "node scripts/generate-mavis.mjs",
|
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Per-phase step cost for one task, read from the ledgers the OpenCode output
|
|
4
|
+
* guard already writes.
|
|
5
|
+
*
|
|
6
|
+
* Phases are the task's own attempts: `metrics.json` `attempt_started` /
|
|
7
|
+
* `attempt_finished` events give each step's agent and window, so a phase needs
|
|
8
|
+
* no guessing about which session belonged to which step. Every window is
|
|
9
|
+
* half-open `[start, end)`; an attempt with no `attempt_finished` (a step still
|
|
10
|
+
* running, or a manual host that never wrote the pair) ends at the next start,
|
|
11
|
+
* or at `now` for the last one.
|
|
12
|
+
*
|
|
13
|
+
* Three figures per phase, each a direct count over a deduped row set:
|
|
14
|
+
* `turns` is one `usage.jsonl` row per `(sessionID, messageID)`, `callsByName`
|
|
15
|
+
* is one `results.jsonl` row per `(sessionID, callID)` grouped by tool, and
|
|
16
|
+
* `chainInvocations` is a `bash` / `shell` / `sh` command that runs
|
|
17
|
+
* `chain-team-phases.sh` through an interpreter — the manual step this task
|
|
18
|
+
* removes. A mention inside `echo` does not count.
|
|
19
|
+
*
|
|
20
|
+
* Windows do not overlap: a finished attempt is clipped at the next attempt's
|
|
21
|
+
* start. A row missing the id used for dedupe stays in `unattributed`.
|
|
22
|
+
* When `.ai.local/team/.session-leases/` names this task, only that session
|
|
23
|
+
* and its child sessions are counted. With no lease the report says the
|
|
24
|
+
* window is the whole host ledger.
|
|
25
|
+
*
|
|
26
|
+
* Usage (any cwd):
|
|
27
|
+
* node .ai.local/scripts/report-step-cost.mjs --task <slug> [--json]
|
|
28
|
+
* [--root <team-dir>] [--dir <output-guard-dir>]
|
|
29
|
+
*
|
|
30
|
+
* Read-only: prints to stdout, writes nothing. Exit 0 whenever a report is
|
|
31
|
+
* produced — a task with no ledger rows is a report of zeros, not an error.
|
|
32
|
+
* Exit 2 on a usage error or a `metrics.json` that cannot be parsed.
|
|
33
|
+
*/
|
|
34
|
+
import fs from 'node:fs'
|
|
35
|
+
import path from 'node:path'
|
|
36
|
+
import { fileURLToPath } from 'node:url'
|
|
37
|
+
|
|
38
|
+
const USAGE = `usage: report-step-cost.mjs --task <slug> [--json] [--root <team-dir>] [--dir <output-guard-dir>]`
|
|
39
|
+
|
|
40
|
+
const SCHEMA_VERSION = 1
|
|
41
|
+
const LEDGER_ARCHIVES = 3
|
|
42
|
+
|
|
43
|
+
const formatInt = (value) => value.toLocaleString('en-US')
|
|
44
|
+
const padEnd = (value, width) => String(value).padEnd(width)
|
|
45
|
+
const padStart = (value, width) => String(value).padStart(width)
|
|
46
|
+
|
|
47
|
+
/** Nearest `.ai.local/team` above `start`; `null` when the walk reaches the root. */
|
|
48
|
+
export function findTeamRoot(start) {
|
|
49
|
+
let dir = path.resolve(start)
|
|
50
|
+
for (;;) {
|
|
51
|
+
const candidate = path.join(dir, '.ai.local', 'team')
|
|
52
|
+
try {
|
|
53
|
+
if (fs.statSync(candidate).isDirectory()) return candidate
|
|
54
|
+
} catch {
|
|
55
|
+
/* keep walking up */
|
|
56
|
+
}
|
|
57
|
+
const parent = path.dirname(dir)
|
|
58
|
+
if (parent === dir) return null
|
|
59
|
+
dir = parent
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const parseArgs = (argv) => {
|
|
64
|
+
const options = { task: null, json: false, root: null, dir: null }
|
|
65
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
66
|
+
const arg = argv[index]
|
|
67
|
+
if (arg === '--json') options.json = true
|
|
68
|
+
else if (arg === '--task') options.task = argv[++index] ?? null
|
|
69
|
+
else if (arg === '--root') options.root = argv[++index] ?? null
|
|
70
|
+
else if (arg === '--dir') options.dir = argv[++index] ?? null
|
|
71
|
+
else if (arg === '--help' || arg === '-h') {
|
|
72
|
+
process.stdout.write(`${USAGE}\n`)
|
|
73
|
+
process.exit(0)
|
|
74
|
+
} else {
|
|
75
|
+
process.stderr.write(`report-step-cost: unknown argument ${arg}\n${USAGE}\n`)
|
|
76
|
+
process.exit(2)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return options
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** JSONL rows; unparsable lines are counted and skipped, an absent file is empty. */
|
|
83
|
+
function readJsonl(file) {
|
|
84
|
+
let text
|
|
85
|
+
try {
|
|
86
|
+
text = fs.readFileSync(file, 'utf8')
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error.code === 'ENOENT') return { rows: [], invalid: 0, files: 0 }
|
|
89
|
+
throw error
|
|
90
|
+
}
|
|
91
|
+
const rows = []
|
|
92
|
+
let invalid = 0
|
|
93
|
+
for (const line of text.split('\n')) {
|
|
94
|
+
if (line.trim() === '') continue
|
|
95
|
+
try {
|
|
96
|
+
rows.push(JSON.parse(line))
|
|
97
|
+
} catch {
|
|
98
|
+
invalid += 1
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { rows, invalid, files: 1 }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** `results.jsonl` plus its rotation archives. The live file is first, so a re-record keeps the newest row. */
|
|
105
|
+
export function readLedger(directory, stem) {
|
|
106
|
+
const rows = []
|
|
107
|
+
let invalid = 0
|
|
108
|
+
let files = 0
|
|
109
|
+
for (let index = 0; index < LEDGER_ARCHIVES; index += 1) {
|
|
110
|
+
const name = index === 0 ? `${stem}.jsonl` : `${stem}.${index}.jsonl`
|
|
111
|
+
const part = readJsonl(path.join(directory, name))
|
|
112
|
+
rows.push(...part.rows)
|
|
113
|
+
invalid += part.invalid
|
|
114
|
+
files += part.files
|
|
115
|
+
}
|
|
116
|
+
return { rows, invalid, files }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const numericTime = (value) => {
|
|
120
|
+
const at = Date.parse(value)
|
|
121
|
+
return Number.isFinite(at) ? at : null
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const stepLabel = (stepIndex) => (stepIndex === null ? 'step?' : `step${stepIndex}`)
|
|
125
|
+
|
|
126
|
+
const phaseLabel = (members) => {
|
|
127
|
+
if (members.length === 1) return `${stepLabel(members[0].stepIndex)}:${members[0].agent}`
|
|
128
|
+
const steps = new Set(members.map((member) => member.stepIndex))
|
|
129
|
+
if (steps.size === 1) return `${stepLabel(members[0].stepIndex)}:${members.map((member) => member.agent).join('+')}`
|
|
130
|
+
return members.map((member) => `${stepLabel(member.stepIndex)}:${member.agent}`).join('+')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** One id for a shared phase: the parallel group, else the wave, else the first attempt. */
|
|
134
|
+
const sharedAttemptId = (members) => {
|
|
135
|
+
if (members.length === 1) return members[0].attemptId
|
|
136
|
+
const groups = new Set(members.map((member) => member.parallelGroupId).filter((id) => id !== ''))
|
|
137
|
+
if (groups.size === 1) return [...groups][0]
|
|
138
|
+
const waves = new Set(members.map((member) => member.waveId).filter((id) => id !== ''))
|
|
139
|
+
if (waves.size === 1) return [...waves][0]
|
|
140
|
+
return members[0].attemptId
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* One phase per attempt, ordered by start. Attempts that share a start are one
|
|
145
|
+
* phase: a parallel step and a ready wave record every agent at the same
|
|
146
|
+
* timestamp, and time cannot split their rows. A finished phase closes at its
|
|
147
|
+
* latest finish, clipped at the next later start. An open phase closes at that
|
|
148
|
+
* next start, and the last open phase closes at `now`.
|
|
149
|
+
*/
|
|
150
|
+
export function buildPhases(events, now) {
|
|
151
|
+
const started = (Array.isArray(events) ? events : [])
|
|
152
|
+
.filter((event) => event && event.type === 'attempt_started')
|
|
153
|
+
.map((event, index) => ({
|
|
154
|
+
attemptId: typeof event.attemptId === 'string' ? event.attemptId : '',
|
|
155
|
+
stepIndex: Number.isInteger(event.stepIndex) ? event.stepIndex : null,
|
|
156
|
+
agent: typeof event.agent === 'string' ? event.agent : 'unknown',
|
|
157
|
+
parallelGroupId: typeof event.parallelGroupId === 'string' ? event.parallelGroupId : '',
|
|
158
|
+
waveId: typeof event.waveId === 'string' ? event.waveId : '',
|
|
159
|
+
start: numericTime(event.at),
|
|
160
|
+
order: index,
|
|
161
|
+
}))
|
|
162
|
+
.filter((entry) => entry.start !== null)
|
|
163
|
+
.sort((a, b) => a.start - b.start || a.order - b.order)
|
|
164
|
+
const finished = new Map()
|
|
165
|
+
for (const event of Array.isArray(events) ? events : []) {
|
|
166
|
+
if (!event || event.type !== 'attempt_finished') continue
|
|
167
|
+
const at = numericTime(event.at)
|
|
168
|
+
if (at === null || typeof event.attemptId !== 'string') continue
|
|
169
|
+
finished.set(event.attemptId, at)
|
|
170
|
+
}
|
|
171
|
+
const clusters = []
|
|
172
|
+
for (const entry of started) {
|
|
173
|
+
const current = clusters[clusters.length - 1]
|
|
174
|
+
if (current && current[0].start === entry.start) current.push(entry)
|
|
175
|
+
else clusters.push([entry])
|
|
176
|
+
}
|
|
177
|
+
return clusters.map((members, index) => {
|
|
178
|
+
const nextStart = index + 1 < clusters.length ? clusters[index + 1][0].start : now
|
|
179
|
+
const finishes = members
|
|
180
|
+
.map((member) => finished.get(member.attemptId))
|
|
181
|
+
.filter((at) => at !== undefined)
|
|
182
|
+
const allFinished = finishes.length === members.length
|
|
183
|
+
const finishedAt = allFinished ? Math.max(...finishes) : undefined
|
|
184
|
+
const to = Math.min(finishedAt ?? nextStart, nextStart)
|
|
185
|
+
return {
|
|
186
|
+
phase: phaseLabel(members),
|
|
187
|
+
attemptId: sharedAttemptId(members),
|
|
188
|
+
stepIndex: members[0].stepIndex,
|
|
189
|
+
agent: members.length === 1 ? members[0].agent : members.map((member) => member.agent).join('+'),
|
|
190
|
+
startedAt: new Date(members[0].start).toISOString(),
|
|
191
|
+
endedAt: new Date(to).toISOString(),
|
|
192
|
+
open: !allFinished,
|
|
193
|
+
from: members[0].start,
|
|
194
|
+
to,
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Count the deduped rows that fall inside `[from, to)`. */
|
|
200
|
+
function countWindow(usageRows, resultRows, from, to) {
|
|
201
|
+
const turns = []
|
|
202
|
+
for (const row of usageRows) {
|
|
203
|
+
const at = numericTime(row?.at)
|
|
204
|
+
if (at === null || at < from || at >= to) continue
|
|
205
|
+
turns.push(row)
|
|
206
|
+
}
|
|
207
|
+
const calls = resultRows.filter((row) => {
|
|
208
|
+
const at = numericTime(row?.at)
|
|
209
|
+
return at !== null && at >= from && at < to
|
|
210
|
+
})
|
|
211
|
+
return { turns, calls }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const SHELL_TOOLS = new Set(['bash', 'shell', 'sh'])
|
|
215
|
+
const CHAIN_PATH = /(?:^|\/)chain-team-phases\.sh$/
|
|
216
|
+
|
|
217
|
+
/** Quoted or bare tokens. A quoted sentence stays one token. */
|
|
218
|
+
export function shellTokens(command) {
|
|
219
|
+
const tokens = []
|
|
220
|
+
const pattern = /"([^"]*)"|'([^']*)'|`([^`]*)`|(\S+)/g
|
|
221
|
+
for (let match = pattern.exec(command); match !== null; match = pattern.exec(command)) {
|
|
222
|
+
const token = match[1] ?? match[2] ?? match[3] ?? match[4] ?? ''
|
|
223
|
+
if (token !== '') tokens.push(token)
|
|
224
|
+
}
|
|
225
|
+
return tokens
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** A shell command that executes the chain script, not one that only mentions it. */
|
|
229
|
+
export function isChainInvocation(tool, command) {
|
|
230
|
+
if (typeof tool !== 'string' || !SHELL_TOOLS.has(tool)) return false
|
|
231
|
+
if (typeof command !== 'string' || command === '') return false
|
|
232
|
+
const tokens = shellTokens(command)
|
|
233
|
+
return tokens.some((token, index) => {
|
|
234
|
+
if (!CHAIN_PATH.test(token)) return false
|
|
235
|
+
for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
|
|
236
|
+
const previous = tokens[cursor]
|
|
237
|
+
if (previous === '|' || previous === '||' || previous === '&&' || previous === ';' || previous === '&') {
|
|
238
|
+
return false
|
|
239
|
+
}
|
|
240
|
+
if (previous.startsWith('-') || /^[A-Za-z_][A-Za-z0-9_]*=/.test(previous)) continue
|
|
241
|
+
return previous === 'bash' || previous === 'sh' || previous === 'zsh' || previous === 'source' || previous === '.'
|
|
242
|
+
}
|
|
243
|
+
return false
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** `{calls, callsByName, chainInvocations}` for one deduped call set. */
|
|
248
|
+
export function summarizeCalls(rows) {
|
|
249
|
+
const counts = new Map()
|
|
250
|
+
let chainInvocations = 0
|
|
251
|
+
for (const row of rows) {
|
|
252
|
+
const tool = typeof row?.tool === 'string' && row.tool !== '' ? row.tool : 'unknown'
|
|
253
|
+
counts.set(tool, (counts.get(tool) ?? 0) + 1)
|
|
254
|
+
if (isChainInvocation(tool, row?.command)) chainInvocations += 1
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
calls: rows.length,
|
|
258
|
+
callsByName: Object.fromEntries([...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))),
|
|
259
|
+
chainInvocations,
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const usageKey = (row) => {
|
|
264
|
+
const sessionID = typeof row?.sessionID === 'string' ? row.sessionID : ''
|
|
265
|
+
const messageID = typeof row?.messageID === 'string' ? row.messageID : ''
|
|
266
|
+
return sessionID === '' || messageID === '' ? null : `${sessionID}|${messageID}`
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const callKey = (row) => {
|
|
270
|
+
const sessionID = typeof row?.sessionID === 'string' ? row.sessionID : ''
|
|
271
|
+
const callID = typeof row?.callID === 'string' ? row.callID : ''
|
|
272
|
+
return sessionID === '' || callID === '' ? null : `${sessionID}|${callID}`
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const splitRows = (rows, keyOf) => {
|
|
276
|
+
const keyed = []
|
|
277
|
+
const anonymous = []
|
|
278
|
+
const seen = new Set()
|
|
279
|
+
for (const row of rows) {
|
|
280
|
+
const key = keyOf(row)
|
|
281
|
+
if (key === null) {
|
|
282
|
+
anonymous.push(row)
|
|
283
|
+
continue
|
|
284
|
+
}
|
|
285
|
+
if (seen.has(key)) continue
|
|
286
|
+
seen.add(key)
|
|
287
|
+
keyed.push(row)
|
|
288
|
+
}
|
|
289
|
+
return { keyed, anonymous }
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const LEASE_TTL_MS = 7 * 24 * 60 * 60 * 1000
|
|
293
|
+
|
|
294
|
+
/** Unexpired `.session-leases/*.json` rows. A bad file is skipped. */
|
|
295
|
+
export function readSessionLeases(teamRoot, now = Date.now()) {
|
|
296
|
+
const dir = path.join(teamRoot, '.session-leases')
|
|
297
|
+
let names
|
|
298
|
+
try {
|
|
299
|
+
names = fs.readdirSync(dir)
|
|
300
|
+
} catch {
|
|
301
|
+
return []
|
|
302
|
+
}
|
|
303
|
+
const leases = []
|
|
304
|
+
for (const name of names) {
|
|
305
|
+
if (!name.endsWith('.json')) continue
|
|
306
|
+
const file = path.join(dir, name)
|
|
307
|
+
try {
|
|
308
|
+
if (now - fs.statSync(file).mtimeMs > LEASE_TTL_MS) continue
|
|
309
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
310
|
+
if (!parsed || typeof parsed.slug !== 'string' || typeof parsed.sessionId !== 'string') continue
|
|
311
|
+
leases.push({ slug: parsed.slug, sessionId: parsed.sessionId })
|
|
312
|
+
} catch {
|
|
313
|
+
/* one bad lease does not hide the others */
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return leases
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* `null` when no lease names `task` (the caller keeps the host window).
|
|
321
|
+
* Otherwise a predicate for that session and usage children whose
|
|
322
|
+
* `parentSessionID` chain reaches it.
|
|
323
|
+
*/
|
|
324
|
+
export function sessionsForSlug(leases, usageRows, task) {
|
|
325
|
+
const owned = new Set()
|
|
326
|
+
for (const lease of leases) {
|
|
327
|
+
if (lease && lease.slug === task && typeof lease.sessionId === 'string' && lease.sessionId !== '') {
|
|
328
|
+
owned.add(lease.sessionId)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (owned.size === 0) return null
|
|
332
|
+
const parentOf = new Map()
|
|
333
|
+
for (const row of usageRows) {
|
|
334
|
+
const sessionID = typeof row?.sessionID === 'string' ? row.sessionID : ''
|
|
335
|
+
const parent = typeof row?.parentSessionID === 'string' ? row.parentSessionID : ''
|
|
336
|
+
if (sessionID !== '' && parent !== '') parentOf.set(sessionID, parent)
|
|
337
|
+
}
|
|
338
|
+
const memo = new Map()
|
|
339
|
+
return (sessionID) => {
|
|
340
|
+
if (memo.has(sessionID)) return memo.get(sessionID)
|
|
341
|
+
const seen = new Set()
|
|
342
|
+
let current = sessionID
|
|
343
|
+
let ok = false
|
|
344
|
+
while (typeof current === 'string' && current !== '' && !seen.has(current)) {
|
|
345
|
+
if (owned.has(current)) {
|
|
346
|
+
ok = true
|
|
347
|
+
break
|
|
348
|
+
}
|
|
349
|
+
seen.add(current)
|
|
350
|
+
current = parentOf.get(current)
|
|
351
|
+
}
|
|
352
|
+
for (const id of seen) memo.set(id, ok)
|
|
353
|
+
memo.set(sessionID, ok)
|
|
354
|
+
return ok
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const partitionSessions = (rows, includeSession) => {
|
|
359
|
+
if (typeof includeSession !== 'function') return { included: rows, excluded: [] }
|
|
360
|
+
const included = []
|
|
361
|
+
const excluded = []
|
|
362
|
+
for (const row of rows) {
|
|
363
|
+
const sessionID = typeof row?.sessionID === 'string' ? row.sessionID : ''
|
|
364
|
+
if (sessionID !== '' && includeSession(sessionID)) included.push(row)
|
|
365
|
+
else excluded.push(row)
|
|
366
|
+
}
|
|
367
|
+
return { included, excluded }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* The whole report: phases from `metrics.json`, rows from the ledger, and one
|
|
372
|
+
* `unattributed` bucket for in-scope rows no attempt window covers. Rows with
|
|
373
|
+
* no dedupe id stay in that bucket and in the totals when the report is the
|
|
374
|
+
* host window. A session lease moves those rows to `excluded` with the other
|
|
375
|
+
* sessions, because they cannot be tied to the lease.
|
|
376
|
+
*/
|
|
377
|
+
export function buildReport({
|
|
378
|
+
task,
|
|
379
|
+
events,
|
|
380
|
+
ledgerDirectory,
|
|
381
|
+
usage,
|
|
382
|
+
results,
|
|
383
|
+
now = Date.now(),
|
|
384
|
+
includeSession = null,
|
|
385
|
+
}) {
|
|
386
|
+
const phases = buildPhases(events, now)
|
|
387
|
+
const usageSplit = splitRows(usage, usageKey)
|
|
388
|
+
const resultSplit = splitRows(results, callKey)
|
|
389
|
+
const usageSessions = partitionSessions(usageSplit.keyed, includeSession)
|
|
390
|
+
const resultSessions = partitionSessions(resultSplit.keyed, includeSession)
|
|
391
|
+
const usageRows = usageSessions.included
|
|
392
|
+
const resultRows = resultSessions.included
|
|
393
|
+
const covered = { usage: new Set(), results: new Set() }
|
|
394
|
+
|
|
395
|
+
const rows = phases.map((phase) => {
|
|
396
|
+
const window = countWindow(usageRows, resultRows, phase.from, phase.to)
|
|
397
|
+
for (const row of window.turns) covered.usage.add(row)
|
|
398
|
+
for (const row of window.calls) covered.results.add(row)
|
|
399
|
+
return {
|
|
400
|
+
phase: phase.phase,
|
|
401
|
+
stepIndex: phase.stepIndex,
|
|
402
|
+
agent: phase.agent,
|
|
403
|
+
attemptId: phase.attemptId,
|
|
404
|
+
startedAt: phase.startedAt,
|
|
405
|
+
endedAt: phase.endedAt,
|
|
406
|
+
open: phase.open,
|
|
407
|
+
turns: window.turns.length,
|
|
408
|
+
...summarizeCalls(window.calls),
|
|
409
|
+
}
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
const lease = typeof includeSession === 'function'
|
|
413
|
+
const usageAnonymous = lease ? [] : usageSplit.anonymous
|
|
414
|
+
const resultAnonymous = lease ? [] : resultSplit.anonymous
|
|
415
|
+
const leftoversUsage = usageRows.filter((row) => !covered.usage.has(row))
|
|
416
|
+
const leftoversResults = resultRows.filter((row) => !covered.results.has(row))
|
|
417
|
+
const unattributed = {
|
|
418
|
+
phase: 'unattributed',
|
|
419
|
+
turns: leftoversUsage.length + usageAnonymous.length,
|
|
420
|
+
...summarizeCalls([...leftoversResults, ...resultAnonymous]),
|
|
421
|
+
}
|
|
422
|
+
const total = summarizeCalls([...resultRows, ...resultAnonymous])
|
|
423
|
+
const excluded = summarizeCalls([
|
|
424
|
+
...resultSessions.excluded,
|
|
425
|
+
...(lease ? resultSplit.anonymous : []),
|
|
426
|
+
])
|
|
427
|
+
return {
|
|
428
|
+
schemaVersion: SCHEMA_VERSION,
|
|
429
|
+
task,
|
|
430
|
+
generatedAt: new Date(now).toISOString(),
|
|
431
|
+
ledgerDirectory,
|
|
432
|
+
attribution: lease ? 'session-lease' : 'host-window',
|
|
433
|
+
totals: {
|
|
434
|
+
phases: rows.length,
|
|
435
|
+
turns: usageRows.length + usageAnonymous.length,
|
|
436
|
+
...total,
|
|
437
|
+
},
|
|
438
|
+
phases: rows,
|
|
439
|
+
unattributed,
|
|
440
|
+
excluded: {
|
|
441
|
+
turns: usageSessions.excluded.length + (lease ? usageSplit.anonymous.length : 0),
|
|
442
|
+
calls: excluded.calls,
|
|
443
|
+
},
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const renderPhase = (row, { tools = true } = {}) => {
|
|
448
|
+
const calls = Object.entries(row.callsByName)
|
|
449
|
+
.map(([tool, count]) => `${tool} ${count}`)
|
|
450
|
+
.join(', ')
|
|
451
|
+
const detail = tools ? ` ${calls}` : ' (outside every phase window; per-tool split in --json)'
|
|
452
|
+
return [
|
|
453
|
+
padEnd(row.phase, 34),
|
|
454
|
+
padEnd(row.attemptId ?? '', 46),
|
|
455
|
+
padStart(formatInt(row.turns), 6),
|
|
456
|
+
padStart(formatInt(row.calls), 6),
|
|
457
|
+
padStart(formatInt(row.chainInvocations), 6),
|
|
458
|
+
detail,
|
|
459
|
+
].join('')
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function renderText(report) {
|
|
463
|
+
const attribution = report.attribution === 'session-lease'
|
|
464
|
+
? 'attribution: session lease'
|
|
465
|
+
: 'attribution: host window (no session lease for this task)'
|
|
466
|
+
const lines = [
|
|
467
|
+
`step cost — ${report.task}`,
|
|
468
|
+
`ledger: ${report.ledgerDirectory}`,
|
|
469
|
+
attribution,
|
|
470
|
+
'',
|
|
471
|
+
`${padEnd('phase', 34)}${padEnd('attempt', 46)}${padStart('turns', 6)}${padStart('calls', 6)}${padStart('chain', 6)} calls by tool`,
|
|
472
|
+
]
|
|
473
|
+
for (const row of report.phases) lines.push(renderPhase(row))
|
|
474
|
+
lines.push(renderPhase(report.unattributed, { tools: false }))
|
|
475
|
+
lines.push(
|
|
476
|
+
'',
|
|
477
|
+
`totals: ${formatInt(report.totals.turns)} turns, ${formatInt(report.totals.calls)} calls, `
|
|
478
|
+
+ `${formatInt(report.totals.chainInvocations)} chain invocation(s) across ${formatInt(report.totals.phases)} phase(s)`,
|
|
479
|
+
)
|
|
480
|
+
if (report.excluded && (report.excluded.turns > 0 || report.excluded.calls > 0)) {
|
|
481
|
+
lines.push(
|
|
482
|
+
`excluded other sessions: ${formatInt(report.excluded.turns)} turns, ${formatInt(report.excluded.calls)} calls`,
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
return `${lines.join('\n')}\n`
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const readMetrics = (file) => {
|
|
489
|
+
let text
|
|
490
|
+
try {
|
|
491
|
+
text = fs.readFileSync(file, 'utf8')
|
|
492
|
+
} catch (error) {
|
|
493
|
+
if (error.code === 'ENOENT') return { events: [], present: false }
|
|
494
|
+
throw error
|
|
495
|
+
}
|
|
496
|
+
return { events: JSON.parse(text)?.events ?? [], present: true }
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const main = () => {
|
|
500
|
+
const options = parseArgs(process.argv.slice(2))
|
|
501
|
+
if (!options.task) {
|
|
502
|
+
process.stderr.write(`report-step-cost: --task is required\n${USAGE}\n`)
|
|
503
|
+
process.exit(2)
|
|
504
|
+
}
|
|
505
|
+
const teamRoot = options.root ? path.resolve(options.root) : findTeamRoot(process.cwd())
|
|
506
|
+
if (teamRoot === null) {
|
|
507
|
+
process.stderr.write('report-step-cost: no .ai.local/team above the working directory; pass --root\n')
|
|
508
|
+
process.exit(2)
|
|
509
|
+
}
|
|
510
|
+
const ledgerDirectory = options.dir
|
|
511
|
+
? path.resolve(options.dir)
|
|
512
|
+
: path.join(teamRoot, 'output-guard')
|
|
513
|
+
const metricsFile = path.join(teamRoot, 'tasks', options.task, 'metrics.json')
|
|
514
|
+
let metrics
|
|
515
|
+
try {
|
|
516
|
+
metrics = readMetrics(metricsFile)
|
|
517
|
+
} catch (error) {
|
|
518
|
+
process.stderr.write(`report-step-cost: cannot parse ${metricsFile}: ${error.message}\n`)
|
|
519
|
+
process.exit(2)
|
|
520
|
+
}
|
|
521
|
+
const usage = readLedger(ledgerDirectory, 'usage')
|
|
522
|
+
const results = readLedger(ledgerDirectory, 'results')
|
|
523
|
+
const includeSession = sessionsForSlug(readSessionLeases(teamRoot), usage.rows, options.task)
|
|
524
|
+
const report = buildReport({
|
|
525
|
+
task: options.task,
|
|
526
|
+
events: metrics.events,
|
|
527
|
+
ledgerDirectory,
|
|
528
|
+
usage: usage.rows,
|
|
529
|
+
results: results.rows,
|
|
530
|
+
includeSession,
|
|
531
|
+
})
|
|
532
|
+
report.ledger = {
|
|
533
|
+
usageFiles: usage.files,
|
|
534
|
+
resultFiles: results.files,
|
|
535
|
+
invalidUsageRows: usage.invalid,
|
|
536
|
+
invalidResultRows: results.invalid,
|
|
537
|
+
metricsPresent: metrics.present,
|
|
538
|
+
}
|
|
539
|
+
process.stdout.write(options.json ? `${JSON.stringify(report, null, 2)}\n` : renderText(report))
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const invokedDirectly =
|
|
543
|
+
process.argv[1] !== undefined && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))
|
|
544
|
+
if (invokedDirectly) main()
|