@bonesofspring/ai-rules 0.2.67 → 0.2.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +4 -4
- package/bin/lib/engine-scripts.js +3 -6
- package/bin/lib/seed-ai-local-team.js +1 -1
- package/docs/PRESET-CONTRIBUTION.md +15 -8
- package/docs/TEAM-DB.md +105 -105
- package/docs/TOKEN-ECONOMY.md +4 -2
- package/docs/openapi/team-db.v1.json +3905 -1466
- package/package.json +4 -4
- package/presets/_shared/ai-local/scripts/processes.mjs +467 -55
- package/presets/_shared/ai-local/scripts/team-db-api.mjs +564 -10
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +816 -47
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +659 -5
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +135 -0
- package/presets/_shared/ai-local/scripts/team-db-task-runner.mjs +11 -6
- package/presets/_shared/ai-local/scripts/team-db.mjs +16 -54
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +5 -5
- package/presets/_shared/core/architecture/feature-delivery-workflow.md +3 -7
- package/presets/_shared/core/meta/preset-pr-checklist.md +2 -2
- package/presets/_shared/core/quality/code-quality-and-refactoring.md +2 -6
- package/presets/_shared/core/quality/verification-before-completion.md +20 -3
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +12 -3
- package/presets/claude/android-kotlin/REPO_AGENTS.md +7 -47
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/android-kotlin/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/android-kotlin/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/go/REPO_AGENTS.md +7 -47
- package/presets/claude/go/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/go/rules/architecture/feature-delivery.md +3 -7
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/go/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/go/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/ios-swift/REPO_AGENTS.md +7 -47
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/ios-swift/rules/architecture/feature-delivery.md +3 -7
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/ios-swift/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/ios-swift/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/java/REPO_AGENTS.md +7 -47
- package/presets/claude/java/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/java/rules/architecture/feature-delivery.md +3 -7
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/java/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/java/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/mcp-ts/REPO_AGENTS.md +7 -47
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/mcp-ts/rules/architecture/feature-delivery.md +3 -7
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/mcp-ts/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/mcp-ts/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/mol/REPO_AGENTS.md +9 -49
- package/presets/claude/mol/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/mol/rules/architecture/feature-delivery-workflow.md +3 -7
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/mol/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/mol/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/next/REPO_AGENTS.md +10 -50
- package/presets/claude/next/agents/accessibility-reviewer.md +0 -1
- package/presets/claude/next/agents/api-contract-reviewer.md +0 -1
- package/presets/claude/next/agents/build-verifier.md +12 -8
- package/presets/claude/next/agents/code-reviewer.md +1 -1
- package/presets/claude/next/agents/codebase-analyzer.md +0 -1
- package/presets/claude/next/agents/feature-developer.md +6 -6
- package/presets/claude/next/agents/migration-specialist.md +0 -1
- package/presets/claude/next/agents/mockup-reviewer.md +0 -1
- package/presets/claude/next/agents/openspec-author.md +0 -1
- package/presets/claude/next/agents/performance-auditor.md +0 -1
- package/presets/claude/next/agents/playwright-test-generator.md +0 -1
- package/presets/claude/next/agents/playwright-test-healer.md +0 -1
- package/presets/claude/next/agents/playwright-test-planner.md +0 -1
- package/presets/claude/next/agents/qa-tester.md +3 -3
- package/presets/claude/next/agents/security-reviewer.md +0 -1
- package/presets/claude/next/agents/solution-architect.md +0 -1
- package/presets/claude/next/agents/task-analyst.md +0 -1
- package/presets/claude/next/agents/task-router.md +8 -7
- package/presets/claude/next/agents/tech-writer.md +0 -1
- package/presets/claude/next/agents/unit-test-generator.md +0 -1
- package/presets/claude/next/agents/unit-test-healer.md +0 -1
- package/presets/claude/next/agents/unit-test-planner.md +0 -1
- package/presets/claude/next/commands/README.md +0 -6
- package/presets/claude/next/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/next/rules/architecture/feature-delivery-workflow.md +5 -9
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/next/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/next/rules/tooling-and-review/post-change-lint.md +12 -16
- package/presets/claude/next/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/next/skills/feature-delivery/SKILL.md +1 -1
- package/presets/claude/next/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/claude/next/skills/unit-testing/SKILL.md +1 -1
- package/presets/claude/nuxt/REPO_AGENTS.md +8 -48
- package/presets/claude/nuxt/agents/accessibility-reviewer.md +0 -1
- package/presets/claude/nuxt/agents/api-contract-reviewer.md +0 -1
- package/presets/claude/nuxt/agents/build-verifier.md +5 -3
- package/presets/claude/nuxt/agents/ci-investigator.md +1 -1
- package/presets/claude/nuxt/agents/code-reviewer.md +0 -1
- package/presets/claude/nuxt/agents/codebase-analyzer.md +0 -1
- package/presets/claude/nuxt/agents/debugger.md +1 -1
- package/presets/claude/nuxt/agents/feature-developer.md +6 -6
- package/presets/claude/nuxt/agents/migration-specialist.md +0 -1
- package/presets/claude/nuxt/agents/mockup-reviewer.md +0 -1
- package/presets/claude/nuxt/agents/openspec-author.md +0 -1
- package/presets/claude/nuxt/agents/performance-auditor.md +0 -1
- package/presets/claude/nuxt/agents/playwright-test-generator.md +0 -1
- package/presets/claude/nuxt/agents/playwright-test-healer.md +0 -1
- package/presets/claude/nuxt/agents/playwright-test-planner.md +0 -1
- package/presets/claude/nuxt/agents/qa-tester.md +3 -3
- package/presets/claude/nuxt/agents/security-reviewer.md +0 -1
- package/presets/claude/nuxt/agents/solution-architect.md +0 -1
- package/presets/claude/nuxt/agents/task-analyst.md +0 -1
- package/presets/claude/nuxt/agents/task-router.md +8 -7
- package/presets/claude/nuxt/agents/tech-writer.md +0 -1
- package/presets/claude/nuxt/agents/unit-test-generator.md +0 -1
- package/presets/claude/nuxt/agents/unit-test-healer.md +0 -1
- package/presets/claude/nuxt/agents/unit-test-planner.md +0 -1
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/nuxt/rules/architecture/feature-delivery-workflow.md +3 -7
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/nuxt/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/nuxt/rules/tooling-and-review/post-change-lint.md +14 -14
- package/presets/claude/nuxt/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/nuxt/skills/feature-delivery/SKILL.md +1 -1
- package/presets/claude/nuxt/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/claude/nuxt/skills/unit-testing/SKILL.md +1 -1
- package/presets/claude/php-hexagonal/REPO_AGENTS.md +7 -47
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/php-hexagonal/rules/architecture/feature-delivery.md +3 -7
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/php-hexagonal/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/php-laravel/REPO_AGENTS.md +7 -47
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/php-laravel/rules/architecture/feature-delivery.md +3 -7
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/php-laravel/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/php-laravel/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/svelte/REPO_AGENTS.md +8 -48
- package/presets/claude/svelte/agents/accessibility-reviewer.md +0 -1
- package/presets/claude/svelte/agents/api-contract-reviewer.md +0 -1
- package/presets/claude/svelte/agents/build-verifier.md +5 -3
- package/presets/claude/svelte/agents/ci-investigator.md +1 -1
- package/presets/claude/svelte/agents/code-reviewer.md +0 -1
- package/presets/claude/svelte/agents/codebase-analyzer.md +0 -1
- package/presets/claude/svelte/agents/debugger.md +1 -1
- package/presets/claude/svelte/agents/feature-developer.md +6 -6
- package/presets/claude/svelte/agents/migration-specialist.md +0 -1
- package/presets/claude/svelte/agents/mockup-reviewer.md +0 -1
- package/presets/claude/svelte/agents/openspec-author.md +0 -1
- package/presets/claude/svelte/agents/performance-auditor.md +0 -1
- package/presets/claude/svelte/agents/playwright-test-generator.md +0 -1
- package/presets/claude/svelte/agents/playwright-test-healer.md +0 -1
- package/presets/claude/svelte/agents/playwright-test-planner.md +0 -1
- package/presets/claude/svelte/agents/qa-tester.md +3 -3
- package/presets/claude/svelte/agents/security-reviewer.md +0 -1
- package/presets/claude/svelte/agents/solution-architect.md +0 -1
- package/presets/claude/svelte/agents/task-analyst.md +0 -1
- package/presets/claude/svelte/agents/task-router.md +8 -7
- package/presets/claude/svelte/agents/tech-writer.md +0 -1
- package/presets/claude/svelte/agents/unit-test-generator.md +0 -1
- package/presets/claude/svelte/agents/unit-test-healer.md +0 -1
- package/presets/claude/svelte/agents/unit-test-planner.md +0 -1
- package/presets/claude/svelte/hooks/chain-team-phases.sh +12 -3
- package/presets/claude/svelte/rules/architecture/feature-delivery-workflow.md +3 -7
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +5 -5
- package/presets/claude/svelte/rules/tooling-and-review/code-quality.md +2 -6
- package/presets/claude/svelte/rules/tooling-and-review/post-change-lint.md +14 -14
- package/presets/claude/svelte/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/svelte/skills/feature-delivery/SKILL.md +1 -1
- package/presets/claude/svelte/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/claude/svelte/skills/unit-testing/SKILL.md +1 -1
- package/presets/cursor/android-kotlin/AGENTS.md +0 -10
- package/presets/cursor/android-kotlin/REPO_AGENTS.md +7 -47
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/android-kotlin/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/android-kotlin/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/go/AGENTS.md +0 -8
- package/presets/cursor/go/REPO_AGENTS.md +7 -47
- package/presets/cursor/go/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/go/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/go/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/ios-swift/AGENTS.md +0 -10
- package/presets/cursor/ios-swift/REPO_AGENTS.md +7 -47
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/ios-swift/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/ios-swift/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/java/AGENTS.md +0 -8
- package/presets/cursor/java/REPO_AGENTS.md +7 -47
- package/presets/cursor/java/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/java/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/java/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/mcp-ts/AGENTS.md +0 -6
- package/presets/cursor/mcp-ts/REPO_AGENTS.md +7 -47
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/mcp-ts/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/mcp-ts/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/mol/AGENTS.md +0 -11
- package/presets/cursor/mol/REPO_AGENTS.md +9 -49
- package/presets/cursor/mol/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/mol/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/mol/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/next/AGENTS.md +1 -12
- package/presets/cursor/next/REPO_AGENTS.md +10 -50
- package/presets/cursor/next/agents/build-verifier.md +11 -7
- package/presets/cursor/next/agents/code-reviewer.md +1 -0
- package/presets/cursor/next/agents/feature-developer.md +6 -6
- package/presets/cursor/next/agents/qa-tester.md +3 -2
- package/presets/cursor/next/agents/task-router.md +8 -6
- package/presets/cursor/next/commands/README.md +0 -6
- package/presets/cursor/next/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +4 -4
- package/presets/cursor/next/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/next/rules/feature-delivery-workflow.mdc +2 -2
- package/presets/cursor/next/rules/post-change-lint.mdc +12 -16
- package/presets/cursor/next/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/next/skills/feature-delivery/SKILL.md +1 -1
- package/presets/cursor/next/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/cursor/next/skills/unit-testing/SKILL.md +1 -1
- package/presets/cursor/nuxt/AGENTS.md +1 -12
- package/presets/cursor/nuxt/REPO_AGENTS.md +8 -48
- package/presets/cursor/nuxt/agents/build-verifier.md +1 -1
- package/presets/cursor/nuxt/agents/feature-developer.md +2 -2
- package/presets/cursor/nuxt/agents/qa-tester.md +3 -2
- package/presets/cursor/nuxt/agents/task-router.md +8 -6
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/nuxt/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/nuxt/rules/post-change-lint.mdc +14 -14
- package/presets/cursor/nuxt/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/nuxt/skills/feature-delivery/SKILL.md +1 -1
- package/presets/cursor/nuxt/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/cursor/nuxt/skills/unit-testing/SKILL.md +1 -1
- package/presets/cursor/php-hexagonal/AGENTS.md +0 -8
- package/presets/cursor/php-hexagonal/REPO_AGENTS.md +7 -47
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/php-hexagonal/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/php-hexagonal/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/php-laravel/AGENTS.md +0 -8
- package/presets/cursor/php-laravel/REPO_AGENTS.md +7 -47
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/php-laravel/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/php-laravel/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/svelte/AGENTS.md +1 -12
- package/presets/cursor/svelte/REPO_AGENTS.md +8 -48
- package/presets/cursor/svelte/agents/build-verifier.md +1 -1
- package/presets/cursor/svelte/agents/feature-developer.md +2 -2
- package/presets/cursor/svelte/agents/qa-tester.md +3 -2
- package/presets/cursor/svelte/agents/task-router.md +8 -6
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +12 -3
- package/presets/cursor/svelte/rules/code-quality-and-refactoring.mdc +2 -6
- package/presets/cursor/svelte/rules/post-change-lint.mdc +14 -14
- package/presets/cursor/svelte/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/svelte/skills/feature-delivery/SKILL.md +1 -1
- package/presets/cursor/svelte/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/cursor/svelte/skills/unit-testing/SKILL.md +1 -1
- package/presets/mavis/android-kotlin/MAVIS.md +0 -2
- package/presets/mavis/android-kotlin/REPO_AGENTS.md +7 -47
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/android-kotlin/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/android-kotlin/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/go/MAVIS.md +8 -0
- package/presets/mavis/go/REPO_AGENTS.md +7 -47
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/go/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/go/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/go/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/go/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/ios-swift/MAVIS.md +0 -2
- package/presets/mavis/ios-swift/REPO_AGENTS.md +7 -47
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/ios-swift/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/ios-swift/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/ios-swift/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/java/MAVIS.md +14 -0
- package/presets/mavis/java/REPO_AGENTS.md +7 -47
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/java/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/java/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/java/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/java/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/mcp-ts/MAVIS.md +6 -0
- package/presets/mavis/mcp-ts/REPO_AGENTS.md +7 -47
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/mcp-ts/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/mcp-ts/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/mcp-ts/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/mol/MAVIS.md +1 -5
- package/presets/mavis/mol/REPO_AGENTS.md +9 -49
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/mol/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/mol/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/mol/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/next/MAVIS.md +2 -6
- package/presets/mavis/next/REPO_AGENTS.md +10 -50
- package/presets/mavis/next/adapter-map.json +1 -17
- package/presets/mavis/next/agents/accessibility-reviewer.md +0 -1
- package/presets/mavis/next/agents/api-contract-reviewer.md +0 -1
- package/presets/mavis/next/agents/build-verifier.md +12 -8
- package/presets/mavis/next/agents/code-reviewer.md +1 -1
- package/presets/mavis/next/agents/codebase-analyzer.md +0 -1
- package/presets/mavis/next/agents/feature-developer.md +6 -6
- package/presets/mavis/next/agents/migration-specialist.md +0 -1
- package/presets/mavis/next/agents/mockup-reviewer.md +0 -1
- package/presets/mavis/next/agents/openspec-author.md +0 -1
- package/presets/mavis/next/agents/performance-auditor.md +0 -1
- package/presets/mavis/next/agents/playwright-test-generator.md +0 -1
- package/presets/mavis/next/agents/playwright-test-healer.md +0 -1
- package/presets/mavis/next/agents/playwright-test-planner.md +0 -1
- package/presets/mavis/next/agents/qa-tester.md +3 -3
- package/presets/mavis/next/agents/security-reviewer.md +0 -1
- package/presets/mavis/next/agents/solution-architect.md +0 -1
- package/presets/mavis/next/agents/task-analyst.md +0 -1
- package/presets/mavis/next/agents/task-router.md +8 -7
- package/presets/mavis/next/agents/tech-writer.md +0 -1
- package/presets/mavis/next/agents/unit-test-generator.md +0 -1
- package/presets/mavis/next/agents/unit-test-healer.md +0 -1
- package/presets/mavis/next/agents/unit-test-planner.md +0 -1
- package/presets/mavis/next/commands/README.md +0 -6
- package/presets/mavis/next/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/next/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/next/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/next/rules/feature-delivery-workflow.md +5 -9
- package/presets/mavis/next/rules/post-change-lint.md +11 -15
- package/presets/mavis/next/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/next/skills/feature-delivery/SKILL.md +1 -1
- package/presets/mavis/next/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/mavis/next/skills/unit-testing/SKILL.md +1 -1
- package/presets/mavis/nuxt/MAVIS.md +2 -6
- package/presets/mavis/nuxt/REPO_AGENTS.md +8 -48
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/agents/accessibility-reviewer.md +0 -1
- package/presets/mavis/nuxt/agents/api-contract-reviewer.md +0 -1
- package/presets/mavis/nuxt/agents/build-verifier.md +2 -2
- package/presets/mavis/nuxt/agents/ci-investigator.md +1 -1
- package/presets/mavis/nuxt/agents/code-reviewer.md +0 -1
- package/presets/mavis/nuxt/agents/codebase-analyzer.md +0 -1
- package/presets/mavis/nuxt/agents/debugger.md +1 -1
- package/presets/mavis/nuxt/agents/feature-developer.md +3 -3
- package/presets/mavis/nuxt/agents/migration-specialist.md +0 -1
- package/presets/mavis/nuxt/agents/mockup-reviewer.md +0 -1
- package/presets/mavis/nuxt/agents/openspec-author.md +0 -1
- package/presets/mavis/nuxt/agents/performance-auditor.md +0 -1
- package/presets/mavis/nuxt/agents/playwright-test-generator.md +0 -1
- package/presets/mavis/nuxt/agents/playwright-test-healer.md +0 -1
- package/presets/mavis/nuxt/agents/playwright-test-planner.md +0 -1
- package/presets/mavis/nuxt/agents/qa-tester.md +3 -3
- package/presets/mavis/nuxt/agents/security-reviewer.md +0 -1
- package/presets/mavis/nuxt/agents/solution-architect.md +0 -1
- package/presets/mavis/nuxt/agents/task-analyst.md +0 -1
- package/presets/mavis/nuxt/agents/task-router.md +8 -7
- package/presets/mavis/nuxt/agents/tech-writer.md +0 -1
- package/presets/mavis/nuxt/agents/unit-test-generator.md +0 -1
- package/presets/mavis/nuxt/agents/unit-test-healer.md +0 -1
- package/presets/mavis/nuxt/agents/unit-test-planner.md +0 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/nuxt/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/nuxt/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/nuxt/rules/post-change-lint.md +13 -13
- package/presets/mavis/nuxt/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/nuxt/skills/feature-delivery/SKILL.md +1 -1
- package/presets/mavis/nuxt/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/mavis/nuxt/skills/unit-testing/SKILL.md +1 -1
- package/presets/mavis/php-hexagonal/MAVIS.md +16 -0
- package/presets/mavis/php-hexagonal/REPO_AGENTS.md +7 -47
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/php-hexagonal/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/php-hexagonal/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/php-hexagonal/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/php-laravel/MAVIS.md +16 -0
- package/presets/mavis/php-laravel/REPO_AGENTS.md +7 -47
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/php-laravel/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/php-laravel/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/php-laravel/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/svelte/MAVIS.md +2 -6
- package/presets/mavis/svelte/REPO_AGENTS.md +8 -48
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/agents/accessibility-reviewer.md +0 -1
- package/presets/mavis/svelte/agents/api-contract-reviewer.md +0 -1
- package/presets/mavis/svelte/agents/build-verifier.md +2 -2
- package/presets/mavis/svelte/agents/ci-investigator.md +1 -1
- package/presets/mavis/svelte/agents/code-reviewer.md +0 -1
- package/presets/mavis/svelte/agents/codebase-analyzer.md +0 -1
- package/presets/mavis/svelte/agents/debugger.md +1 -1
- package/presets/mavis/svelte/agents/feature-developer.md +3 -3
- package/presets/mavis/svelte/agents/migration-specialist.md +0 -1
- package/presets/mavis/svelte/agents/mockup-reviewer.md +0 -1
- package/presets/mavis/svelte/agents/openspec-author.md +0 -1
- package/presets/mavis/svelte/agents/performance-auditor.md +0 -1
- package/presets/mavis/svelte/agents/playwright-test-generator.md +0 -1
- package/presets/mavis/svelte/agents/playwright-test-healer.md +0 -1
- package/presets/mavis/svelte/agents/playwright-test-planner.md +0 -1
- package/presets/mavis/svelte/agents/qa-tester.md +3 -3
- package/presets/mavis/svelte/agents/security-reviewer.md +0 -1
- package/presets/mavis/svelte/agents/solution-architect.md +0 -1
- package/presets/mavis/svelte/agents/task-analyst.md +0 -1
- package/presets/mavis/svelte/agents/task-router.md +8 -7
- package/presets/mavis/svelte/agents/tech-writer.md +0 -1
- package/presets/mavis/svelte/agents/unit-test-generator.md +0 -1
- package/presets/mavis/svelte/agents/unit-test-healer.md +0 -1
- package/presets/mavis/svelte/agents/unit-test-planner.md +0 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +12 -3
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +5 -5
- package/presets/mavis/svelte/rules/code-quality-and-refactoring.md +2 -6
- package/presets/mavis/svelte/rules/feature-delivery-workflow.md +3 -7
- package/presets/mavis/svelte/rules/post-change-lint.md +13 -13
- package/presets/mavis/svelte/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/svelte/skills/feature-delivery/SKILL.md +1 -1
- package/presets/mavis/svelte/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/mavis/svelte/skills/unit-testing/SKILL.md +1 -1
- package/presets/opencode/android-kotlin/OPENCODE.md +1 -43
- package/presets/opencode/android-kotlin/REPO_AGENTS.md +7 -47
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/android-kotlin/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/android-kotlin/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/go/OPENCODE.md +7 -39
- package/presets/opencode/go/REPO_AGENTS.md +7 -47
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/go/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/go/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/go/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/go/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/ios-swift/OPENCODE.md +1 -43
- package/presets/opencode/ios-swift/REPO_AGENTS.md +7 -47
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/ios-swift/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/ios-swift/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/ios-swift/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/java/OPENCODE.md +12 -38
- package/presets/opencode/java/REPO_AGENTS.md +7 -47
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/java/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/java/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/java/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/java/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/mcp-ts/OPENCODE.md +5 -39
- package/presets/opencode/mcp-ts/REPO_AGENTS.md +7 -47
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/mcp-ts/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/mcp-ts/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/mcp-ts/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/mol/OPENCODE.md +1 -44
- package/presets/opencode/mol/REPO_AGENTS.md +9 -49
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/mol/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/mol/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/mol/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/next/OPENCODE.md +2 -45
- package/presets/opencode/next/REPO_AGENTS.md +10 -50
- package/presets/opencode/next/adapter-map.json +1 -17
- package/presets/opencode/next/agents/accessibility-reviewer.md +0 -1
- package/presets/opencode/next/agents/api-contract-reviewer.md +0 -1
- package/presets/opencode/next/agents/build-verifier.md +12 -8
- package/presets/opencode/next/agents/code-reviewer.md +1 -1
- package/presets/opencode/next/agents/codebase-analyzer.md +0 -1
- package/presets/opencode/next/agents/feature-developer.md +6 -6
- package/presets/opencode/next/agents/migration-specialist.md +0 -1
- package/presets/opencode/next/agents/mockup-reviewer.md +0 -1
- package/presets/opencode/next/agents/openspec-author.md +0 -1
- package/presets/opencode/next/agents/performance-auditor.md +0 -1
- package/presets/opencode/next/agents/playwright-test-generator.md +0 -1
- package/presets/opencode/next/agents/playwright-test-healer.md +0 -1
- package/presets/opencode/next/agents/playwright-test-planner.md +0 -1
- package/presets/opencode/next/agents/qa-tester.md +3 -3
- package/presets/opencode/next/agents/security-reviewer.md +0 -1
- package/presets/opencode/next/agents/solution-architect.md +0 -1
- package/presets/opencode/next/agents/task-analyst.md +0 -1
- package/presets/opencode/next/agents/task-router.md +8 -7
- package/presets/opencode/next/agents/tech-writer.md +0 -1
- package/presets/opencode/next/agents/unit-test-generator.md +0 -1
- package/presets/opencode/next/agents/unit-test-healer.md +0 -1
- package/presets/opencode/next/agents/unit-test-planner.md +0 -1
- package/presets/opencode/next/commands/README.md +0 -6
- package/presets/opencode/next/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/next/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/next/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/next/rules/feature-delivery-workflow.md +5 -9
- package/presets/opencode/next/rules/post-change-lint.md +11 -15
- package/presets/opencode/next/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/next/skills/feature-delivery/SKILL.md +1 -1
- package/presets/opencode/next/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/opencode/next/skills/unit-testing/SKILL.md +1 -1
- package/presets/opencode/nuxt/OPENCODE.md +2 -45
- package/presets/opencode/nuxt/REPO_AGENTS.md +8 -48
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/agents/accessibility-reviewer.md +0 -1
- package/presets/opencode/nuxt/agents/api-contract-reviewer.md +0 -1
- package/presets/opencode/nuxt/agents/build-verifier.md +2 -2
- package/presets/opencode/nuxt/agents/ci-investigator.md +1 -1
- package/presets/opencode/nuxt/agents/code-reviewer.md +0 -1
- package/presets/opencode/nuxt/agents/codebase-analyzer.md +0 -1
- package/presets/opencode/nuxt/agents/debugger.md +1 -1
- package/presets/opencode/nuxt/agents/feature-developer.md +3 -3
- package/presets/opencode/nuxt/agents/migration-specialist.md +0 -1
- package/presets/opencode/nuxt/agents/mockup-reviewer.md +0 -1
- package/presets/opencode/nuxt/agents/openspec-author.md +0 -1
- package/presets/opencode/nuxt/agents/performance-auditor.md +0 -1
- package/presets/opencode/nuxt/agents/playwright-test-generator.md +0 -1
- package/presets/opencode/nuxt/agents/playwright-test-healer.md +0 -1
- package/presets/opencode/nuxt/agents/playwright-test-planner.md +0 -1
- package/presets/opencode/nuxt/agents/qa-tester.md +3 -3
- package/presets/opencode/nuxt/agents/security-reviewer.md +0 -1
- package/presets/opencode/nuxt/agents/solution-architect.md +0 -1
- package/presets/opencode/nuxt/agents/task-analyst.md +0 -1
- package/presets/opencode/nuxt/agents/task-router.md +8 -7
- package/presets/opencode/nuxt/agents/tech-writer.md +0 -1
- package/presets/opencode/nuxt/agents/unit-test-generator.md +0 -1
- package/presets/opencode/nuxt/agents/unit-test-healer.md +0 -1
- package/presets/opencode/nuxt/agents/unit-test-planner.md +0 -1
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/nuxt/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/nuxt/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/nuxt/rules/post-change-lint.md +13 -13
- package/presets/opencode/nuxt/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/nuxt/skills/feature-delivery/SKILL.md +1 -1
- package/presets/opencode/nuxt/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/opencode/nuxt/skills/unit-testing/SKILL.md +1 -1
- package/presets/opencode/php-hexagonal/OPENCODE.md +14 -38
- package/presets/opencode/php-hexagonal/REPO_AGENTS.md +7 -47
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/php-hexagonal/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/php-hexagonal/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/php-hexagonal/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/php-laravel/OPENCODE.md +14 -38
- package/presets/opencode/php-laravel/REPO_AGENTS.md +7 -47
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/php-laravel/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/php-laravel/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/php-laravel/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/plugins/output-guard/index.ts +7 -1
- package/presets/opencode/plugins/output-guard/ledger.ts +43 -0
- package/presets/opencode/plugins/task-status/economy.ts +112 -0
- package/presets/opencode/plugins/task-status/task-view.ts +28 -0
- package/presets/opencode/plugins/task-status/tui.tsx +14 -2
- package/presets/opencode/plugins/task-status/types.ts +3 -1
- package/presets/opencode/svelte/OPENCODE.md +2 -45
- package/presets/opencode/svelte/REPO_AGENTS.md +8 -48
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/agents/accessibility-reviewer.md +0 -1
- package/presets/opencode/svelte/agents/api-contract-reviewer.md +0 -1
- package/presets/opencode/svelte/agents/build-verifier.md +2 -2
- package/presets/opencode/svelte/agents/ci-investigator.md +1 -1
- package/presets/opencode/svelte/agents/code-reviewer.md +0 -1
- package/presets/opencode/svelte/agents/codebase-analyzer.md +0 -1
- package/presets/opencode/svelte/agents/debugger.md +1 -1
- package/presets/opencode/svelte/agents/feature-developer.md +3 -3
- package/presets/opencode/svelte/agents/migration-specialist.md +0 -1
- package/presets/opencode/svelte/agents/mockup-reviewer.md +0 -1
- package/presets/opencode/svelte/agents/openspec-author.md +0 -1
- package/presets/opencode/svelte/agents/performance-auditor.md +0 -1
- package/presets/opencode/svelte/agents/playwright-test-generator.md +0 -1
- package/presets/opencode/svelte/agents/playwright-test-healer.md +0 -1
- package/presets/opencode/svelte/agents/playwright-test-planner.md +0 -1
- package/presets/opencode/svelte/agents/qa-tester.md +3 -3
- package/presets/opencode/svelte/agents/security-reviewer.md +0 -1
- package/presets/opencode/svelte/agents/solution-architect.md +0 -1
- package/presets/opencode/svelte/agents/task-analyst.md +0 -1
- package/presets/opencode/svelte/agents/task-router.md +8 -7
- package/presets/opencode/svelte/agents/tech-writer.md +0 -1
- package/presets/opencode/svelte/agents/unit-test-generator.md +0 -1
- package/presets/opencode/svelte/agents/unit-test-healer.md +0 -1
- package/presets/opencode/svelte/agents/unit-test-planner.md +0 -1
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +12 -3
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +5 -5
- package/presets/opencode/svelte/rules/code-quality-and-refactoring.md +2 -6
- package/presets/opencode/svelte/rules/feature-delivery-workflow.md +3 -7
- package/presets/opencode/svelte/rules/post-change-lint.md +13 -13
- package/presets/opencode/svelte/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/svelte/skills/feature-delivery/SKILL.md +1 -1
- package/presets/opencode/svelte/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/opencode/svelte/skills/unit-testing/SKILL.md +1 -1
- package/presets/zcode/android-kotlin/REPO_AGENTS.md +7 -47
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/android-kotlin/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/android-kotlin/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/go/REPO_AGENTS.md +7 -47
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/go/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/go/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/go/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/go/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/ios-swift/REPO_AGENTS.md +7 -47
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/ios-swift/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/ios-swift/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/ios-swift/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/java/REPO_AGENTS.md +7 -47
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/java/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/java/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/java/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/java/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/mcp-ts/REPO_AGENTS.md +7 -47
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/mcp-ts/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/mcp-ts/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/mcp-ts/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/mol/REPO_AGENTS.md +9 -49
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/mol/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/mol/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/mol/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/next/REPO_AGENTS.md +10 -50
- package/presets/zcode/next/adapter-map.json +1 -17
- package/presets/zcode/next/agents/accessibility-reviewer.md +0 -1
- package/presets/zcode/next/agents/api-contract-reviewer.md +0 -1
- package/presets/zcode/next/agents/build-verifier.md +12 -8
- package/presets/zcode/next/agents/code-reviewer.md +1 -1
- package/presets/zcode/next/agents/codebase-analyzer.md +0 -1
- package/presets/zcode/next/agents/feature-developer.md +6 -6
- package/presets/zcode/next/agents/migration-specialist.md +0 -1
- package/presets/zcode/next/agents/mockup-reviewer.md +0 -1
- package/presets/zcode/next/agents/openspec-author.md +0 -1
- package/presets/zcode/next/agents/performance-auditor.md +0 -1
- package/presets/zcode/next/agents/playwright-test-generator.md +0 -1
- package/presets/zcode/next/agents/playwright-test-healer.md +0 -1
- package/presets/zcode/next/agents/playwright-test-planner.md +0 -1
- package/presets/zcode/next/agents/qa-tester.md +3 -3
- package/presets/zcode/next/agents/security-reviewer.md +0 -1
- package/presets/zcode/next/agents/solution-architect.md +0 -1
- package/presets/zcode/next/agents/task-analyst.md +0 -1
- package/presets/zcode/next/agents/task-router.md +8 -7
- package/presets/zcode/next/agents/tech-writer.md +0 -1
- package/presets/zcode/next/agents/unit-test-generator.md +0 -1
- package/presets/zcode/next/agents/unit-test-healer.md +0 -1
- package/presets/zcode/next/agents/unit-test-planner.md +0 -1
- package/presets/zcode/next/commands/README.md +0 -6
- package/presets/zcode/next/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/next/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/next/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/next/rules/feature-delivery-workflow.md +5 -9
- package/presets/zcode/next/rules/post-change-lint.md +11 -15
- package/presets/zcode/next/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/next/skills/feature-delivery/SKILL.md +1 -1
- package/presets/zcode/next/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/zcode/next/skills/unit-testing/SKILL.md +1 -1
- package/presets/zcode/nuxt/REPO_AGENTS.md +8 -48
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/agents/accessibility-reviewer.md +0 -1
- package/presets/zcode/nuxt/agents/api-contract-reviewer.md +0 -1
- package/presets/zcode/nuxt/agents/build-verifier.md +2 -2
- package/presets/zcode/nuxt/agents/ci-investigator.md +1 -1
- package/presets/zcode/nuxt/agents/code-reviewer.md +0 -1
- package/presets/zcode/nuxt/agents/codebase-analyzer.md +0 -1
- package/presets/zcode/nuxt/agents/debugger.md +1 -1
- package/presets/zcode/nuxt/agents/feature-developer.md +3 -3
- package/presets/zcode/nuxt/agents/migration-specialist.md +0 -1
- package/presets/zcode/nuxt/agents/mockup-reviewer.md +0 -1
- package/presets/zcode/nuxt/agents/openspec-author.md +0 -1
- package/presets/zcode/nuxt/agents/performance-auditor.md +0 -1
- package/presets/zcode/nuxt/agents/playwright-test-generator.md +0 -1
- package/presets/zcode/nuxt/agents/playwright-test-healer.md +0 -1
- package/presets/zcode/nuxt/agents/playwright-test-planner.md +0 -1
- package/presets/zcode/nuxt/agents/qa-tester.md +3 -3
- package/presets/zcode/nuxt/agents/security-reviewer.md +0 -1
- package/presets/zcode/nuxt/agents/solution-architect.md +0 -1
- package/presets/zcode/nuxt/agents/task-analyst.md +0 -1
- package/presets/zcode/nuxt/agents/task-router.md +8 -7
- package/presets/zcode/nuxt/agents/tech-writer.md +0 -1
- package/presets/zcode/nuxt/agents/unit-test-generator.md +0 -1
- package/presets/zcode/nuxt/agents/unit-test-healer.md +0 -1
- package/presets/zcode/nuxt/agents/unit-test-planner.md +0 -1
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/nuxt/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/nuxt/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/nuxt/rules/post-change-lint.md +13 -13
- package/presets/zcode/nuxt/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/nuxt/skills/feature-delivery/SKILL.md +1 -1
- package/presets/zcode/nuxt/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/zcode/nuxt/skills/unit-testing/SKILL.md +1 -1
- package/presets/zcode/php-hexagonal/REPO_AGENTS.md +7 -47
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/php-hexagonal/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/php-hexagonal/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/php-hexagonal/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/php-laravel/REPO_AGENTS.md +7 -47
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/php-laravel/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/php-laravel/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/php-laravel/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/svelte/REPO_AGENTS.md +8 -48
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/agents/accessibility-reviewer.md +0 -1
- package/presets/zcode/svelte/agents/api-contract-reviewer.md +0 -1
- package/presets/zcode/svelte/agents/build-verifier.md +2 -2
- package/presets/zcode/svelte/agents/ci-investigator.md +1 -1
- package/presets/zcode/svelte/agents/code-reviewer.md +0 -1
- package/presets/zcode/svelte/agents/codebase-analyzer.md +0 -1
- package/presets/zcode/svelte/agents/debugger.md +1 -1
- package/presets/zcode/svelte/agents/feature-developer.md +3 -3
- package/presets/zcode/svelte/agents/migration-specialist.md +0 -1
- package/presets/zcode/svelte/agents/mockup-reviewer.md +0 -1
- package/presets/zcode/svelte/agents/openspec-author.md +0 -1
- package/presets/zcode/svelte/agents/performance-auditor.md +0 -1
- package/presets/zcode/svelte/agents/playwright-test-generator.md +0 -1
- package/presets/zcode/svelte/agents/playwright-test-healer.md +0 -1
- package/presets/zcode/svelte/agents/playwright-test-planner.md +0 -1
- package/presets/zcode/svelte/agents/qa-tester.md +3 -3
- package/presets/zcode/svelte/agents/security-reviewer.md +0 -1
- package/presets/zcode/svelte/agents/solution-architect.md +0 -1
- package/presets/zcode/svelte/agents/task-analyst.md +0 -1
- package/presets/zcode/svelte/agents/task-router.md +8 -7
- package/presets/zcode/svelte/agents/tech-writer.md +0 -1
- package/presets/zcode/svelte/agents/unit-test-generator.md +0 -1
- package/presets/zcode/svelte/agents/unit-test-healer.md +0 -1
- package/presets/zcode/svelte/agents/unit-test-planner.md +0 -1
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +12 -3
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +5 -5
- package/presets/zcode/svelte/rules/code-quality-and-refactoring.md +2 -6
- package/presets/zcode/svelte/rules/feature-delivery-workflow.md +3 -7
- package/presets/zcode/svelte/rules/post-change-lint.md +13 -13
- package/presets/zcode/svelte/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/svelte/skills/feature-delivery/SKILL.md +1 -1
- package/presets/zcode/svelte/skills/playwright-e2e/SKILL.md +1 -1
- package/presets/zcode/svelte/skills/unit-testing/SKILL.md +1 -1
- package/presets/_shared/ai-local/scripts/team-db-dashboard.mjs +0 -2103
- package/presets/_shared/ai-local/scripts/team-db-ui.mjs +0 -750
- package/presets/claude/next/commands/ui-start.md +0 -78
- package/presets/claude/next/commands/ui-stop.md +0 -71
- package/presets/cursor/next/commands/ui-start.md +0 -78
- package/presets/cursor/next/commands/ui-stop.md +0 -71
- package/presets/mavis/next/commands/ui-start.md +0 -73
- package/presets/mavis/next/commands/ui-stop.md +0 -66
- package/presets/opencode/next/commands/ui-start.md +0 -81
- package/presets/opencode/next/commands/ui-stop.md +0 -74
- package/presets/zcode/next/commands/ui-start.md +0 -81
- package/presets/zcode/next/commands/ui-stop.md +0 -74
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import crypto from 'node:crypto';
|
|
18
18
|
import fs from 'node:fs';
|
|
19
19
|
import path from 'node:path';
|
|
20
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
20
21
|
|
|
21
22
|
import {
|
|
22
23
|
DEFAULT_TEAM_ROOT,
|
|
@@ -73,6 +74,7 @@ export const EVENT_TYPES = new Set([
|
|
|
73
74
|
'step_joined',
|
|
74
75
|
'parallel_attribution_repair',
|
|
75
76
|
'parallel_conflict_deferred',
|
|
77
|
+
'usage_recorded',
|
|
76
78
|
]);
|
|
77
79
|
|
|
78
80
|
const TEXT_EXTENSIONS = new Set([
|
|
@@ -695,6 +697,20 @@ const normalizeEvent = (event, index, slug) => {
|
|
|
695
697
|
source: typeof event.source === 'string' ? event.source : null,
|
|
696
698
|
attributionConfidence:
|
|
697
699
|
typeof event.attributionConfidence === 'string' ? event.attributionConfidence : null,
|
|
700
|
+
usage: isRecord(event.usage) ? event.usage : null,
|
|
701
|
+
usageEvent:
|
|
702
|
+
type === 'usage_recorded'
|
|
703
|
+
? {
|
|
704
|
+
at: isoTimestamp(event.at),
|
|
705
|
+
turn: typeof event.turn === 'string' && event.turn !== '' ? event.turn : null,
|
|
706
|
+
model: typeof event.model === 'string' && event.model !== '' ? event.model : null,
|
|
707
|
+
input: integerOrNull(event.input),
|
|
708
|
+
output: integerOrNull(event.output),
|
|
709
|
+
cached: integerOrNull(event.cached),
|
|
710
|
+
cacheWrite: integerOrNull(event.cacheWrite),
|
|
711
|
+
reasoning: integerOrNull(event.reasoning),
|
|
712
|
+
}
|
|
713
|
+
: null,
|
|
698
714
|
payloadJson: canonicalJson(event),
|
|
699
715
|
known: EVENT_TYPES.has(type),
|
|
700
716
|
malformed: null,
|
|
@@ -706,8 +722,134 @@ const attemptSuffix = (attemptId) => {
|
|
|
706
722
|
return match ? Number(match[1]) : null;
|
|
707
723
|
};
|
|
708
724
|
|
|
725
|
+
const EMPTY_USAGE = {
|
|
726
|
+
inputTokens: null,
|
|
727
|
+
outputTokens: null,
|
|
728
|
+
reasoningTokens: null,
|
|
729
|
+
cacheReadTokens: null,
|
|
730
|
+
cacheWriteTokens: null,
|
|
731
|
+
costUsd: null,
|
|
732
|
+
usageOrigin: null,
|
|
733
|
+
usageSource: null,
|
|
734
|
+
usageTurnCount: null,
|
|
735
|
+
modelProvider: null,
|
|
736
|
+
modelId: null,
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
const numberOrNull = (value) =>
|
|
740
|
+
typeof value === 'number' && Number.isFinite(value) ? Math.trunc(value) : null;
|
|
741
|
+
|
|
742
|
+
const realOrNull = (value) => (typeof value === 'number' && Number.isFinite(value) ? value : null);
|
|
743
|
+
|
|
744
|
+
const usageModel = (value) => {
|
|
745
|
+
if (typeof value === 'string' && value !== '') {
|
|
746
|
+
const separator = value.indexOf('/');
|
|
747
|
+
return separator > 0
|
|
748
|
+
? { modelProvider: value.slice(0, separator), modelId: value.slice(separator + 1) }
|
|
749
|
+
: { modelProvider: null, modelId: value };
|
|
750
|
+
}
|
|
751
|
+
if (isRecord(value)) {
|
|
752
|
+
const provider = typeof value.providerID === 'string' ? value.providerID : value.provider;
|
|
753
|
+
return {
|
|
754
|
+
modelProvider: typeof provider === 'string' && provider !== '' ? provider : null,
|
|
755
|
+
modelId: typeof value.id === 'string' && value.id !== '' ? value.id : null,
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
return { modelProvider: null, modelId: null };
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
const usageEventAt = (event) => {
|
|
762
|
+
const at = isoTimestamp(event.at);
|
|
763
|
+
return at === null ? null : Date.parse(at);
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* A re-run for one turn replaces the earlier write (AD-3): keep the latest `at`
|
|
768
|
+
* per turn, falling back to input order when either side has no timestamp (the
|
|
769
|
+
* later array element wins). A row without a turn is a legacy row and stays
|
|
770
|
+
* distinct.
|
|
771
|
+
*/
|
|
772
|
+
const collapseUsageTurns = (events) => {
|
|
773
|
+
const winners = new Map();
|
|
774
|
+
events.forEach((event, index) => {
|
|
775
|
+
if (typeof event.turn !== 'string' || event.turn === '') return;
|
|
776
|
+
const currentIndex = winners.get(event.turn);
|
|
777
|
+
if (currentIndex === undefined) {
|
|
778
|
+
winners.set(event.turn, index);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
const at = usageEventAt(event);
|
|
782
|
+
const currentAt = usageEventAt(events[currentIndex]);
|
|
783
|
+
const later = at === null || currentAt === null || at === currentAt ? index > currentIndex : at > currentAt;
|
|
784
|
+
if (later) winners.set(event.turn, index);
|
|
785
|
+
});
|
|
786
|
+
if (winners.size === 0) return events;
|
|
787
|
+
const kept = new Set(winners.values());
|
|
788
|
+
return events.filter(
|
|
789
|
+
(event, index) => kept.has(index) || typeof event.turn !== 'string' || event.turn === '',
|
|
790
|
+
);
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* One attempt has exactly one usage rollup (AD-3): a host `usage` object on
|
|
795
|
+
* `attempt_finished` wins; `usage_recorded` rows are collapsed per turn, then
|
|
796
|
+
* summed, only when no such object exists. A token kind nobody reported stays
|
|
797
|
+
* `null`, never `0`.
|
|
798
|
+
*/
|
|
799
|
+
export function normalizeAttemptUsage(hostUsage, usageEvents = []) {
|
|
800
|
+
if (isRecord(hostUsage)) {
|
|
801
|
+
const tokens = {
|
|
802
|
+
inputTokens: numberOrNull(hostUsage.input),
|
|
803
|
+
outputTokens: numberOrNull(hostUsage.output),
|
|
804
|
+
reasoningTokens: numberOrNull(hostUsage.reasoning),
|
|
805
|
+
cacheReadTokens: numberOrNull(hostUsage.cacheRead),
|
|
806
|
+
cacheWriteTokens: numberOrNull(hostUsage.cacheWrite),
|
|
807
|
+
};
|
|
808
|
+
const costUsd = realOrNull(hostUsage.costUsd);
|
|
809
|
+
const reported = Object.values(tokens).some((value) => value !== null) || costUsd !== null;
|
|
810
|
+
return {
|
|
811
|
+
...EMPTY_USAGE,
|
|
812
|
+
...tokens,
|
|
813
|
+
costUsd,
|
|
814
|
+
usageOrigin: reported
|
|
815
|
+
? hostUsage.origin === 'estimated'
|
|
816
|
+
? 'estimated'
|
|
817
|
+
: 'measured'
|
|
818
|
+
: null,
|
|
819
|
+
usageSource: 'host',
|
|
820
|
+
...usageModel(hostUsage.model),
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
const all = (Array.isArray(usageEvents) ? usageEvents : []).filter(isRecord);
|
|
824
|
+
if (all.length === 0) return { ...EMPTY_USAGE };
|
|
825
|
+
const events = collapseUsageTurns(all);
|
|
826
|
+
const sum = (key) => {
|
|
827
|
+
let total = null;
|
|
828
|
+
for (const event of events) {
|
|
829
|
+
const value = numberOrNull(event[key]);
|
|
830
|
+
if (value !== null) total = (total ?? 0) + value;
|
|
831
|
+
}
|
|
832
|
+
return total;
|
|
833
|
+
};
|
|
834
|
+
const model = events.find((event) => typeof event.model === 'string' && event.model !== '')?.model ?? null;
|
|
835
|
+
return {
|
|
836
|
+
...EMPTY_USAGE,
|
|
837
|
+
inputTokens: sum('input'),
|
|
838
|
+
outputTokens: sum('output'),
|
|
839
|
+
reasoningTokens: sum('reasoning'),
|
|
840
|
+
cacheReadTokens: sum('cached'),
|
|
841
|
+
cacheWriteTokens: sum('cacheWrite'),
|
|
842
|
+
usageOrigin: 'measured',
|
|
843
|
+
usageSource: 'cli',
|
|
844
|
+
usageTurnCount: events.length,
|
|
845
|
+
...usageModel(model),
|
|
846
|
+
};
|
|
847
|
+
};
|
|
848
|
+
|
|
709
849
|
export function deriveAttempts(events, status) {
|
|
710
850
|
const attempts = new Map();
|
|
851
|
+
const hostUsage = new Map();
|
|
852
|
+
const usageEvents = new Map();
|
|
711
853
|
const ensure = (attemptId) => {
|
|
712
854
|
if (!attempts.has(attemptId)) {
|
|
713
855
|
attempts.set(attemptId, {
|
|
@@ -748,8 +890,13 @@ export function deriveAttempts(events, status) {
|
|
|
748
890
|
row.finishedAt = event.at ?? row.finishedAt;
|
|
749
891
|
row.durationMs = event.durationMs ?? row.durationMs;
|
|
750
892
|
row.outcome = event.outcome ?? row.outcome;
|
|
893
|
+
if (isRecord(event.usage)) hostUsage.set(event.attemptId, event.usage);
|
|
751
894
|
} else if (event.type === 'attempt_skipped') {
|
|
752
895
|
row.outcome = 'skipped';
|
|
896
|
+
} else if (event.type === 'usage_recorded' && event.usageEvent) {
|
|
897
|
+
const list = usageEvents.get(event.attemptId) ?? [];
|
|
898
|
+
list.push(event.usageEvent);
|
|
899
|
+
usageEvents.set(event.attemptId, list);
|
|
753
900
|
}
|
|
754
901
|
}
|
|
755
902
|
const active = isRecord(status?.activeAttempts) ? status.activeAttempts : {};
|
|
@@ -765,11 +912,32 @@ export function deriveAttempts(events, status) {
|
|
|
765
912
|
row.startedAt = isoTimestamp(value.startedAt) ?? row.startedAt;
|
|
766
913
|
row.source = row.startedAt && !row.finishedAt ? 'status' : row.source;
|
|
767
914
|
}
|
|
915
|
+
for (const row of attempts.values()) {
|
|
916
|
+
Object.assign(
|
|
917
|
+
row,
|
|
918
|
+
normalizeAttemptUsage(hostUsage.get(row.attemptId) ?? null, usageEvents.get(row.attemptId) ?? []),
|
|
919
|
+
);
|
|
920
|
+
}
|
|
768
921
|
return [...attempts.values()];
|
|
769
922
|
}
|
|
770
923
|
|
|
924
|
+
const GATE_REWORK_EVENTS = new Set(['attempt_started', 'retry_scheduled']);
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* The next event after `human_gate_ended`. The metrics stream records no
|
|
928
|
+
* verdict, so the derivation names the immediate next step only.
|
|
929
|
+
*/
|
|
930
|
+
const gateOutcomeFrom = (event) => {
|
|
931
|
+
if (!event) return 'open';
|
|
932
|
+
if (event.type === 'task_completed') return 'advanced_to_done';
|
|
933
|
+
if (GATE_REWORK_EVENTS.has(event.type)) return 'rework';
|
|
934
|
+
if (event.type === 'human_gate_started') return 're_gated';
|
|
935
|
+
return 'unknown';
|
|
936
|
+
};
|
|
937
|
+
|
|
771
938
|
export function deriveGates(events) {
|
|
772
939
|
const gates = new Map();
|
|
940
|
+
const endIndex = new Map();
|
|
773
941
|
for (const event of events) {
|
|
774
942
|
if (event.type === 'human_gate_started') {
|
|
775
943
|
gates.set(event.eventId, {
|
|
@@ -778,10 +946,11 @@ export function deriveGates(events) {
|
|
|
778
946
|
endEventId: null,
|
|
779
947
|
endedAt: null,
|
|
780
948
|
durationMs: null,
|
|
949
|
+
outcome: 'open',
|
|
781
950
|
});
|
|
782
951
|
}
|
|
783
952
|
}
|
|
784
|
-
for (const event of events) {
|
|
953
|
+
for (const [index, event] of events.entries()) {
|
|
785
954
|
if (event.type !== 'human_gate_ended') continue;
|
|
786
955
|
const gate = event.gateStartedEventId ? gates.get(event.gateStartedEventId) : null;
|
|
787
956
|
if (!gate) continue;
|
|
@@ -791,6 +960,12 @@ export function deriveGates(events) {
|
|
|
791
960
|
const duration = Date.parse(gate.endedAt) - Date.parse(gate.startedAt);
|
|
792
961
|
gate.durationMs = Number.isFinite(duration) && duration >= 0 ? duration : null;
|
|
793
962
|
}
|
|
963
|
+
endIndex.set(gate.startEventId, index);
|
|
964
|
+
}
|
|
965
|
+
for (const gate of gates.values()) {
|
|
966
|
+
// A gate without an end, or whose end is the last event, has no next step.
|
|
967
|
+
const index = endIndex.get(gate.startEventId);
|
|
968
|
+
gate.outcome = index === undefined ? 'open' : gateOutcomeFrom(events[index + 1]);
|
|
794
969
|
}
|
|
795
970
|
return [...gates.values()];
|
|
796
971
|
}
|
|
@@ -1036,8 +1211,10 @@ const replaceAttempts = (db, slug, attempts) => {
|
|
|
1036
1211
|
`INSERT OR IGNORE INTO attempts(
|
|
1037
1212
|
attempt_id, task_slug, step_index, step_label, agent, role, attempt_no, wave_id,
|
|
1038
1213
|
parallel_group_id, started_at, finished_at, duration_ms, outcome, source,
|
|
1039
|
-
attribution_confidence, is_current
|
|
1040
|
-
|
|
1214
|
+
attribution_confidence, is_current, input_tokens, output_tokens, reasoning_tokens,
|
|
1215
|
+
cache_read_tokens, cache_write_tokens, cost_usd, usage_origin, usage_source,
|
|
1216
|
+
usage_turn_count, model_provider, model_id
|
|
1217
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
1041
1218
|
);
|
|
1042
1219
|
for (const attempt of attempts) {
|
|
1043
1220
|
statement.run(
|
|
@@ -1057,6 +1234,17 @@ const replaceAttempts = (db, slug, attempts) => {
|
|
|
1057
1234
|
attempt.source,
|
|
1058
1235
|
attempt.attributionConfidence,
|
|
1059
1236
|
attempt.isCurrent,
|
|
1237
|
+
attempt.inputTokens,
|
|
1238
|
+
attempt.outputTokens,
|
|
1239
|
+
attempt.reasoningTokens,
|
|
1240
|
+
attempt.cacheReadTokens,
|
|
1241
|
+
attempt.cacheWriteTokens,
|
|
1242
|
+
attempt.costUsd,
|
|
1243
|
+
attempt.usageOrigin,
|
|
1244
|
+
attempt.usageSource,
|
|
1245
|
+
attempt.usageTurnCount,
|
|
1246
|
+
attempt.modelProvider,
|
|
1247
|
+
attempt.modelId,
|
|
1060
1248
|
);
|
|
1061
1249
|
}
|
|
1062
1250
|
};
|
|
@@ -1064,10 +1252,10 @@ const replaceAttempts = (db, slug, attempts) => {
|
|
|
1064
1252
|
const replaceGates = (db, slug, gates) => {
|
|
1065
1253
|
db.prepare('DELETE FROM gates WHERE task_slug = ?').run(slug);
|
|
1066
1254
|
const statement = db.prepare(
|
|
1067
|
-
'INSERT OR IGNORE INTO gates(start_event_id, task_slug, started_at, end_event_id, ended_at, duration_ms) VALUES (?, ?, ?, ?, ?,
|
|
1255
|
+
'INSERT OR IGNORE INTO gates(start_event_id, task_slug, started_at, end_event_id, ended_at, duration_ms, outcome, outcome_derived) VALUES (?, ?, ?, ?, ?, ?, ?, 1)',
|
|
1068
1256
|
);
|
|
1069
1257
|
for (const gate of gates) {
|
|
1070
|
-
statement.run(gate.startEventId, slug, gate.startedAt, gate.endEventId, gate.endedAt, gate.durationMs);
|
|
1258
|
+
statement.run(gate.startEventId, slug, gate.startedAt, gate.endEventId, gate.endedAt, gate.durationMs, gate.outcome);
|
|
1071
1259
|
}
|
|
1072
1260
|
};
|
|
1073
1261
|
|
|
@@ -1756,6 +1944,445 @@ const hasSearchTable = (db) =>
|
|
|
1756
1944
|
const markAbsent = (db, slug, at) =>
|
|
1757
1945
|
db.prepare('UPDATE tasks SET absent_at = ? WHERE slug = ? AND absent_at IS NULL').run(at, slug).changes;
|
|
1758
1946
|
|
|
1947
|
+
/* ------------------------------- telemetry -------------------------------- */
|
|
1948
|
+
|
|
1949
|
+
const TELEMETRY_DIR_ENV = 'AI_RULES_TEAM_DB_TELEMETRY_DIR';
|
|
1950
|
+
const telemetryDirectory = (teamRoot, env) => {
|
|
1951
|
+
const override = env && typeof env[TELEMETRY_DIR_ENV] === 'string' ? env[TELEMETRY_DIR_ENV].trim() : '';
|
|
1952
|
+
return override ? path.resolve(override) : path.join(teamRoot, 'output-guard');
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
const deadlineReached = (deadlineAt) => Number.isFinite(deadlineAt) && Date.now() > deadlineAt;
|
|
1956
|
+
|
|
1957
|
+
function* iterateLines(file) {
|
|
1958
|
+
const decoder = new StringDecoder('utf8');
|
|
1959
|
+
const descriptor = fs.openSync(file, 'r');
|
|
1960
|
+
try {
|
|
1961
|
+
const buffer = Buffer.allocUnsafe(64 * 1024);
|
|
1962
|
+
let leftover = '';
|
|
1963
|
+
for (;;) {
|
|
1964
|
+
const read = fs.readSync(descriptor, buffer, 0, buffer.length, null);
|
|
1965
|
+
if (read === 0) break;
|
|
1966
|
+
const text = leftover + decoder.write(buffer.subarray(0, read));
|
|
1967
|
+
const lines = text.split('\n');
|
|
1968
|
+
leftover = lines.pop() ?? '';
|
|
1969
|
+
for (const line of lines) yield line;
|
|
1970
|
+
}
|
|
1971
|
+
const tail = leftover + decoder.end();
|
|
1972
|
+
if (tail !== '') yield tail;
|
|
1973
|
+
} finally {
|
|
1974
|
+
fs.closeSync(descriptor);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
const keyOfLine = (line, keyOf) => {
|
|
1979
|
+
if (line.trim() === '') return '';
|
|
1980
|
+
try {
|
|
1981
|
+
return keyOf(JSON.parse(line)) ?? '';
|
|
1982
|
+
} catch {
|
|
1983
|
+
return '';
|
|
1984
|
+
}
|
|
1985
|
+
};
|
|
1986
|
+
|
|
1987
|
+
/**
|
|
1988
|
+
* Read a ledger once. With `skipLines`, the line at that boundary must carry
|
|
1989
|
+
* `expectedKey`; anything else means the file was rewritten and the caller
|
|
1990
|
+
* re-reads it whole.
|
|
1991
|
+
*/
|
|
1992
|
+
const readLedgerLines = (file, keyOf, { skipLines = 0, expectedKey = null } = {}) => {
|
|
1993
|
+
const rows = [];
|
|
1994
|
+
let total = 0;
|
|
1995
|
+
let boundary = null;
|
|
1996
|
+
for (const line of iterateLines(file)) {
|
|
1997
|
+
total += 1;
|
|
1998
|
+
if (total < skipLines) continue;
|
|
1999
|
+
if (total === skipLines) {
|
|
2000
|
+
boundary = keyOfLine(line, keyOf);
|
|
2001
|
+
continue;
|
|
2002
|
+
}
|
|
2003
|
+
rows.push(line);
|
|
2004
|
+
}
|
|
2005
|
+
if (skipLines > 0 && boundary !== expectedKey) return null;
|
|
2006
|
+
return { rows, total };
|
|
2007
|
+
};
|
|
2008
|
+
|
|
2009
|
+
const toolCallKey = (row) =>
|
|
2010
|
+
isRecord(row) && typeof row.sessionID === 'string' && typeof row.callID === 'string'
|
|
2011
|
+
? `${row.sessionID}|${row.callID}`
|
|
2012
|
+
: '';
|
|
2013
|
+
|
|
2014
|
+
const usageTurnKey = (row) =>
|
|
2015
|
+
isRecord(row) && typeof row.sessionID === 'string' && typeof row.messageID === 'string'
|
|
2016
|
+
? `${row.sessionID}|${row.messageID}`
|
|
2017
|
+
: '';
|
|
2018
|
+
|
|
2019
|
+
/** Same classifier as `report-efficiency.mjs`; the drift test pins the pair. */
|
|
2020
|
+
const classifyToolCall = (row) => {
|
|
2021
|
+
const tool = String(row?.tool ?? '').toLowerCase();
|
|
2022
|
+
const command = String(row?.command ?? '');
|
|
2023
|
+
if (tool === 'read') return 'read';
|
|
2024
|
+
if (tool === 'webfetch') return 'web';
|
|
2025
|
+
if (/\bgit\b/i.test(command)) return 'git';
|
|
2026
|
+
if (/\b(test|lint|type-check|tsc|vitest|jest|playwright|eslint)\b/i.test(command)) return 'test';
|
|
2027
|
+
if (/\b(build|compile|bundle)\b/i.test(command)) return 'build';
|
|
2028
|
+
if (/\b(grep|rg|find|search)\b/i.test(command)) return 'search';
|
|
2029
|
+
if (/\b(cat|sed|head|tail)\b/i.test(command)) return 'read';
|
|
2030
|
+
if (/\b(curl|wget|http)\b/i.test(command)) return 'web';
|
|
2031
|
+
return 'other';
|
|
2032
|
+
};
|
|
2033
|
+
|
|
2034
|
+
const normalizeToolCall = (row) => {
|
|
2035
|
+
if (!isRecord(row)) return null;
|
|
2036
|
+
const sessionID = typeof row.sessionID === 'string' ? row.sessionID : '';
|
|
2037
|
+
const callID = typeof row.callID === 'string' ? row.callID : '';
|
|
2038
|
+
const rawBytes = numberOrNull(row.rawBytes);
|
|
2039
|
+
const returnedBytes = numberOrNull(row.returnedBytes);
|
|
2040
|
+
const observedAt = isoTimestamp(row.at);
|
|
2041
|
+
if (sessionID === '' || callID === '' || rawBytes === null || returnedBytes === null || observedAt === null) {
|
|
2042
|
+
return null;
|
|
2043
|
+
}
|
|
2044
|
+
if (rawBytes < 0 || returnedBytes < 0) return null;
|
|
2045
|
+
const tool = typeof row.tool === 'string' && row.tool !== '' ? row.tool.toLowerCase() : 'unknown';
|
|
2046
|
+
return {
|
|
2047
|
+
key: `${sessionID}|${callID}`,
|
|
2048
|
+
sessionID,
|
|
2049
|
+
callID,
|
|
2050
|
+
tool,
|
|
2051
|
+
category: classifyToolCall({ tool, command: row.command }),
|
|
2052
|
+
rawBytes,
|
|
2053
|
+
returnedBytes,
|
|
2054
|
+
keptOutBytes: Math.max(0, rawBytes - returnedBytes),
|
|
2055
|
+
replaced: booleanFlag(row.replaced),
|
|
2056
|
+
observedAt,
|
|
2057
|
+
day: observedAt.slice(0, 10),
|
|
2058
|
+
};
|
|
2059
|
+
};
|
|
2060
|
+
|
|
2061
|
+
const normalizeUsageTurn = (row) => {
|
|
2062
|
+
if (!isRecord(row)) return null;
|
|
2063
|
+
const sessionID = typeof row.sessionID === 'string' ? row.sessionID : '';
|
|
2064
|
+
const messageID = typeof row.messageID === 'string' ? row.messageID : '';
|
|
2065
|
+
const inputTokens = numberOrNull(row.input);
|
|
2066
|
+
const observedAt = isoTimestamp(row.at);
|
|
2067
|
+
if (sessionID === '' || messageID === '' || inputTokens === null || observedAt === null) return null;
|
|
2068
|
+
const model = isRecord(row.model) ? row.model : null;
|
|
2069
|
+
return {
|
|
2070
|
+
key: `${sessionID}|${messageID}`,
|
|
2071
|
+
sessionID,
|
|
2072
|
+
messageID,
|
|
2073
|
+
agent: typeof row.agent === 'string' && row.agent !== '' ? row.agent : null,
|
|
2074
|
+
providerId: model && typeof model.providerID === 'string' ? model.providerID : null,
|
|
2075
|
+
modelId: model && typeof model.id === 'string' ? model.id : null,
|
|
2076
|
+
modelVariant: model && typeof model.variant === 'string' ? model.variant : null,
|
|
2077
|
+
inputTokens,
|
|
2078
|
+
outputTokens: numberOrNull(row.output) ?? 0,
|
|
2079
|
+
reasoningTokens: numberOrNull(row.reasoning) ?? 0,
|
|
2080
|
+
cacheReadTokens: numberOrNull(row.cacheRead) ?? 0,
|
|
2081
|
+
cacheWriteTokens: numberOrNull(row.cacheWrite) ?? 0,
|
|
2082
|
+
costUsd: realOrNull(row.cost) ?? 0,
|
|
2083
|
+
finish: typeof row.finish === 'string' && row.finish !== '' ? row.finish : null,
|
|
2084
|
+
observedAt,
|
|
2085
|
+
eventAt: null,
|
|
2086
|
+
day: observedAt.slice(0, 10),
|
|
2087
|
+
};
|
|
2088
|
+
};
|
|
2089
|
+
|
|
2090
|
+
const UPSERT_TOOL_CALL_SQL = `
|
|
2091
|
+
INSERT INTO tool_calls (
|
|
2092
|
+
call_key, session_id, call_id, tool, category, raw_bytes, returned_bytes, kept_out_bytes,
|
|
2093
|
+
replaced, origin, observed_at, day, task_slug, attribution
|
|
2094
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'measured', ?, ?, ?, ?)
|
|
2095
|
+
ON CONFLICT(call_key) DO UPDATE SET
|
|
2096
|
+
session_id = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.session_id ELSE tool_calls.session_id END,
|
|
2097
|
+
call_id = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.call_id ELSE tool_calls.call_id END,
|
|
2098
|
+
tool = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.tool ELSE tool_calls.tool END,
|
|
2099
|
+
category = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.category ELSE tool_calls.category END,
|
|
2100
|
+
raw_bytes = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.raw_bytes ELSE tool_calls.raw_bytes END,
|
|
2101
|
+
returned_bytes = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.returned_bytes ELSE tool_calls.returned_bytes END,
|
|
2102
|
+
kept_out_bytes = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.kept_out_bytes ELSE tool_calls.kept_out_bytes END,
|
|
2103
|
+
replaced = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.replaced ELSE tool_calls.replaced END,
|
|
2104
|
+
observed_at = MIN(tool_calls.observed_at, excluded.observed_at),
|
|
2105
|
+
day = MIN(tool_calls.day, excluded.day),
|
|
2106
|
+
task_slug = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.task_slug ELSE tool_calls.task_slug END,
|
|
2107
|
+
attribution = CASE WHEN excluded.observed_at < tool_calls.observed_at THEN excluded.attribution ELSE tool_calls.attribution END
|
|
2108
|
+
`;
|
|
2109
|
+
|
|
2110
|
+
const UPSERT_USAGE_TURN_SQL = `
|
|
2111
|
+
INSERT INTO usage_turns (
|
|
2112
|
+
turn_key, session_id, message_id, agent, provider_id, model_id, model_variant,
|
|
2113
|
+
input_tokens, output_tokens, reasoning_tokens, cache_read_tokens, cache_write_tokens,
|
|
2114
|
+
cost_usd, finish, origin, observed_at, event_at, day, task_slug, attribution
|
|
2115
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'measured', ?, ?, ?, ?, ?)
|
|
2116
|
+
ON CONFLICT(turn_key) DO UPDATE SET
|
|
2117
|
+
session_id = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.session_id ELSE usage_turns.session_id END,
|
|
2118
|
+
message_id = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.message_id ELSE usage_turns.message_id END,
|
|
2119
|
+
agent = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.agent ELSE usage_turns.agent END,
|
|
2120
|
+
provider_id = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.provider_id ELSE usage_turns.provider_id END,
|
|
2121
|
+
model_id = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.model_id ELSE usage_turns.model_id END,
|
|
2122
|
+
model_variant = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.model_variant ELSE usage_turns.model_variant END,
|
|
2123
|
+
input_tokens = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.input_tokens ELSE usage_turns.input_tokens END,
|
|
2124
|
+
output_tokens = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.output_tokens ELSE usage_turns.output_tokens END,
|
|
2125
|
+
reasoning_tokens = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.reasoning_tokens ELSE usage_turns.reasoning_tokens END,
|
|
2126
|
+
cache_read_tokens = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.cache_read_tokens ELSE usage_turns.cache_read_tokens END,
|
|
2127
|
+
cache_write_tokens = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.cache_write_tokens ELSE usage_turns.cache_write_tokens END,
|
|
2128
|
+
cost_usd = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.cost_usd ELSE usage_turns.cost_usd END,
|
|
2129
|
+
finish = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.finish ELSE usage_turns.finish END,
|
|
2130
|
+
observed_at = MIN(usage_turns.observed_at, excluded.observed_at),
|
|
2131
|
+
day = MIN(usage_turns.day, excluded.day),
|
|
2132
|
+
task_slug = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.task_slug ELSE usage_turns.task_slug END,
|
|
2133
|
+
attribution = CASE WHEN excluded.observed_at < usage_turns.observed_at THEN excluded.attribution ELSE usage_turns.attribution END
|
|
2134
|
+
`;
|
|
2135
|
+
|
|
2136
|
+
const UPSERT_SOURCE_SQL = `
|
|
2137
|
+
INSERT INTO telemetry_sources (source_path, kind, size_bytes, mtime_ms, last_key, rows, ingested_at)
|
|
2138
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
2139
|
+
ON CONFLICT(source_path) DO UPDATE SET
|
|
2140
|
+
kind = excluded.kind,
|
|
2141
|
+
size_bytes = excluded.size_bytes,
|
|
2142
|
+
mtime_ms = excluded.mtime_ms,
|
|
2143
|
+
last_key = excluded.last_key,
|
|
2144
|
+
rows = excluded.rows,
|
|
2145
|
+
ingested_at = excluded.ingested_at
|
|
2146
|
+
`;
|
|
2147
|
+
|
|
2148
|
+
const UPSERT_LEASE_SQL = `
|
|
2149
|
+
INSERT INTO session_tasks (session_id, task_slug, first_seen_at, last_seen_at)
|
|
2150
|
+
VALUES (?, ?, ?, ?)
|
|
2151
|
+
ON CONFLICT(session_id, task_slug) DO UPDATE SET
|
|
2152
|
+
first_seen_at = MIN(session_tasks.first_seen_at, excluded.first_seen_at),
|
|
2153
|
+
last_seen_at = MAX(session_tasks.last_seen_at, excluded.last_seen_at)
|
|
2154
|
+
`;
|
|
2155
|
+
|
|
2156
|
+
const projectSessionLeases = (db, teamRoot) => {
|
|
2157
|
+
const directory = path.join(teamRoot, '.session-leases');
|
|
2158
|
+
if (!fs.existsSync(directory)) return 0;
|
|
2159
|
+
const statement = db.prepare(UPSERT_LEASE_SQL);
|
|
2160
|
+
let projected = 0;
|
|
2161
|
+
for (const name of fs.readdirSync(directory).sort()) {
|
|
2162
|
+
if (!name.endsWith('.json')) continue;
|
|
2163
|
+
let value;
|
|
2164
|
+
try {
|
|
2165
|
+
value = JSON.parse(fs.readFileSync(path.join(directory, name), 'utf8'));
|
|
2166
|
+
} catch {
|
|
2167
|
+
continue;
|
|
2168
|
+
}
|
|
2169
|
+
if (!isRecord(value)) continue;
|
|
2170
|
+
const sessionID = typeof value.sessionId === 'string' ? value.sessionId : '';
|
|
2171
|
+
const slug = typeof value.slug === 'string' ? value.slug : '';
|
|
2172
|
+
const at = isoTimestamp(value.updatedAt);
|
|
2173
|
+
if (sessionID === '' || slug === '' || at === null) continue;
|
|
2174
|
+
statement.run(sessionID, slug, at, at);
|
|
2175
|
+
projected += 1;
|
|
2176
|
+
}
|
|
2177
|
+
return projected;
|
|
2178
|
+
};
|
|
2179
|
+
|
|
2180
|
+
const leaseWindows = (db) => {
|
|
2181
|
+
const map = new Map();
|
|
2182
|
+
for (const row of db.prepare('SELECT session_id, task_slug, first_seen_at, last_seen_at FROM session_tasks').all()) {
|
|
2183
|
+
const first = Date.parse(row.first_seen_at);
|
|
2184
|
+
const last = Date.parse(row.last_seen_at);
|
|
2185
|
+
if (!Number.isFinite(first) || !Number.isFinite(last)) continue;
|
|
2186
|
+
const list = map.get(row.session_id) ?? [];
|
|
2187
|
+
list.push({ slug: row.task_slug, first, last });
|
|
2188
|
+
map.set(row.session_id, list);
|
|
2189
|
+
}
|
|
2190
|
+
return map;
|
|
2191
|
+
};
|
|
2192
|
+
|
|
2193
|
+
const resolveAttribution = (windows, sessionID, observedAt) => {
|
|
2194
|
+
const list = windows.get(sessionID);
|
|
2195
|
+
const at = Date.parse(observedAt);
|
|
2196
|
+
if (!list || !Number.isFinite(at)) return { taskSlug: null, attribution: 'unmapped' };
|
|
2197
|
+
let best = null;
|
|
2198
|
+
for (const window of list) {
|
|
2199
|
+
if (window.first <= at && at <= window.last && (!best || window.first >= best.first)) best = window;
|
|
2200
|
+
}
|
|
2201
|
+
return best ? { taskSlug: best.slug, attribution: 'lease' } : { taskSlug: null, attribution: 'unmapped' };
|
|
2202
|
+
};
|
|
2203
|
+
|
|
2204
|
+
const sourcePathFor = (teamRoot, file) => {
|
|
2205
|
+
const relative = path.relative(teamRoot, file).split(path.sep).join('/');
|
|
2206
|
+
return relative.startsWith('..') || path.isAbsolute(relative) ? file.split(path.sep).join('/') : relative;
|
|
2207
|
+
};
|
|
2208
|
+
|
|
2209
|
+
const listLedgerFiles = (directory, stem) => {
|
|
2210
|
+
if (!fs.existsSync(directory)) return [];
|
|
2211
|
+
return fs
|
|
2212
|
+
.readdirSync(directory)
|
|
2213
|
+
.sort()
|
|
2214
|
+
.filter((name) => name.startsWith(stem) && name.endsWith('.jsonl'))
|
|
2215
|
+
.map((name) => path.join(directory, name))
|
|
2216
|
+
.filter((file) => {
|
|
2217
|
+
try {
|
|
2218
|
+
return fs.statSync(file).isFile();
|
|
2219
|
+
} catch {
|
|
2220
|
+
return false;
|
|
2221
|
+
}
|
|
2222
|
+
});
|
|
2223
|
+
};
|
|
2224
|
+
|
|
2225
|
+
const ingestLedgerFile = ({ db, file, kind, keyOf, ingestedAt, deadlineAt, windows, teamRoot }) => {
|
|
2226
|
+
let stats;
|
|
2227
|
+
try {
|
|
2228
|
+
stats = fs.statSync(file);
|
|
2229
|
+
} catch {
|
|
2230
|
+
return { rows: 0, invalid: 0, ingested: false };
|
|
2231
|
+
}
|
|
2232
|
+
const sizeBytes = stats.size;
|
|
2233
|
+
const mtimeMs = Math.floor(stats.mtimeMs);
|
|
2234
|
+
const sourcePath = sourcePathFor(teamRoot, file);
|
|
2235
|
+
const previous = db
|
|
2236
|
+
.prepare('SELECT size_bytes, mtime_ms, last_key, rows FROM telemetry_sources WHERE source_path = ?')
|
|
2237
|
+
.get(sourcePath);
|
|
2238
|
+
if (
|
|
2239
|
+
previous &&
|
|
2240
|
+
Number(previous.size_bytes) === sizeBytes &&
|
|
2241
|
+
Number(previous.mtime_ms) === mtimeMs
|
|
2242
|
+
) {
|
|
2243
|
+
return { rows: 0, invalid: 0, ingested: false };
|
|
2244
|
+
}
|
|
2245
|
+
const resumable = Boolean(previous) && sizeBytes >= Number(previous.size_bytes) && Number(previous.rows) > 0;
|
|
2246
|
+
let pass = resumable
|
|
2247
|
+
? readLedgerLines(file, keyOf, { skipLines: Number(previous.rows), expectedKey: previous.last_key ?? '' })
|
|
2248
|
+
: null;
|
|
2249
|
+
if (pass === null) pass = readLedgerLines(file, keyOf);
|
|
2250
|
+
|
|
2251
|
+
const statement = db.prepare(kind === 'results' ? UPSERT_TOOL_CALL_SQL : UPSERT_USAGE_TURN_SQL);
|
|
2252
|
+
let invalid = 0;
|
|
2253
|
+
let rows = 0;
|
|
2254
|
+
let lastKey = previous?.last_key ?? '';
|
|
2255
|
+
db.exec('BEGIN IMMEDIATE');
|
|
2256
|
+
try {
|
|
2257
|
+
for (const line of pass.rows) {
|
|
2258
|
+
if (deadlineReached(deadlineAt)) {
|
|
2259
|
+
db.exec('ROLLBACK');
|
|
2260
|
+
return { rows: 0, invalid, ingested: false };
|
|
2261
|
+
}
|
|
2262
|
+
if (line.trim() === '') {
|
|
2263
|
+
lastKey = '';
|
|
2264
|
+
continue;
|
|
2265
|
+
}
|
|
2266
|
+
let raw;
|
|
2267
|
+
try {
|
|
2268
|
+
raw = JSON.parse(line);
|
|
2269
|
+
} catch {
|
|
2270
|
+
invalid += 1;
|
|
2271
|
+
lastKey = '';
|
|
2272
|
+
continue;
|
|
2273
|
+
}
|
|
2274
|
+
const row = kind === 'results' ? normalizeToolCall(raw) : normalizeUsageTurn(raw);
|
|
2275
|
+
if (row === null) {
|
|
2276
|
+
invalid += 1;
|
|
2277
|
+
lastKey = '';
|
|
2278
|
+
continue;
|
|
2279
|
+
}
|
|
2280
|
+
const { taskSlug, attribution } = resolveAttribution(windows, row.sessionID, row.observedAt);
|
|
2281
|
+
if (kind === 'results') {
|
|
2282
|
+
statement.run(
|
|
2283
|
+
row.key,
|
|
2284
|
+
row.sessionID,
|
|
2285
|
+
row.callID,
|
|
2286
|
+
row.tool,
|
|
2287
|
+
row.category,
|
|
2288
|
+
row.rawBytes,
|
|
2289
|
+
row.returnedBytes,
|
|
2290
|
+
row.keptOutBytes,
|
|
2291
|
+
row.replaced,
|
|
2292
|
+
row.observedAt,
|
|
2293
|
+
row.day,
|
|
2294
|
+
taskSlug,
|
|
2295
|
+
attribution,
|
|
2296
|
+
);
|
|
2297
|
+
} else {
|
|
2298
|
+
statement.run(
|
|
2299
|
+
row.key,
|
|
2300
|
+
row.sessionID,
|
|
2301
|
+
row.messageID,
|
|
2302
|
+
row.agent,
|
|
2303
|
+
row.providerId,
|
|
2304
|
+
row.modelId,
|
|
2305
|
+
row.modelVariant,
|
|
2306
|
+
row.inputTokens,
|
|
2307
|
+
row.outputTokens,
|
|
2308
|
+
row.reasoningTokens,
|
|
2309
|
+
row.cacheReadTokens,
|
|
2310
|
+
row.cacheWriteTokens,
|
|
2311
|
+
row.costUsd,
|
|
2312
|
+
row.finish,
|
|
2313
|
+
row.observedAt,
|
|
2314
|
+
row.eventAt,
|
|
2315
|
+
row.day,
|
|
2316
|
+
taskSlug,
|
|
2317
|
+
attribution,
|
|
2318
|
+
);
|
|
2319
|
+
}
|
|
2320
|
+
rows += 1;
|
|
2321
|
+
lastKey = row.key;
|
|
2322
|
+
}
|
|
2323
|
+
db.prepare(UPSERT_SOURCE_SQL).run(sourcePath, kind, sizeBytes, mtimeMs, lastKey, pass.total, ingestedAt);
|
|
2324
|
+
db.exec('COMMIT');
|
|
2325
|
+
} catch (error) {
|
|
2326
|
+
try {
|
|
2327
|
+
db.exec('ROLLBACK');
|
|
2328
|
+
} catch {
|
|
2329
|
+
/* the original error is the finding */
|
|
2330
|
+
}
|
|
2331
|
+
throw error;
|
|
2332
|
+
}
|
|
2333
|
+
return { rows, invalid, ingested: true };
|
|
2334
|
+
};
|
|
2335
|
+
|
|
2336
|
+
/**
|
|
2337
|
+
* Ingest the OpenCode ledgers into `tool_calls` / `usage_turns` and the
|
|
2338
|
+
* session leases into `session_tasks`. Full sync only; a per-file watermark
|
|
2339
|
+
* makes a second run over an unchanged tree a no-op.
|
|
2340
|
+
*/
|
|
2341
|
+
export function projectTelemetry({ db, teamRoot, now, deadlineAt = Number.POSITIVE_INFINITY, env = process.env }) {
|
|
2342
|
+
const ingestedAt = isoTimestamp(now) ?? new Date().toISOString();
|
|
2343
|
+
projectSessionLeases(db, teamRoot);
|
|
2344
|
+
const windows = leaseWindows(db);
|
|
2345
|
+
const directory = telemetryDirectory(teamRoot, env);
|
|
2346
|
+
let rows = 0;
|
|
2347
|
+
let invalid = 0;
|
|
2348
|
+
let sources = 0;
|
|
2349
|
+
let expired = false;
|
|
2350
|
+
for (const [stem, kind, keyOf] of [
|
|
2351
|
+
['results', 'results', toolCallKey],
|
|
2352
|
+
['usage', 'usage', usageTurnKey],
|
|
2353
|
+
]) {
|
|
2354
|
+
for (const file of listLedgerFiles(directory, stem)) {
|
|
2355
|
+
if (deadlineReached(deadlineAt)) {
|
|
2356
|
+
expired = true;
|
|
2357
|
+
break;
|
|
2358
|
+
}
|
|
2359
|
+
const outcome = ingestLedgerFile({ db, file, kind, keyOf, ingestedAt, deadlineAt, windows, teamRoot });
|
|
2360
|
+
rows += outcome.rows;
|
|
2361
|
+
invalid += outcome.invalid;
|
|
2362
|
+
if (outcome.ingested) sources += 1;
|
|
2363
|
+
}
|
|
2364
|
+
if (expired) break;
|
|
2365
|
+
}
|
|
2366
|
+
return { rows, invalid, sources, expired };
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
const logProjectionFailure = (code, message, env = process.env) => {
|
|
2370
|
+
try {
|
|
2371
|
+
const override = env && typeof env.AI_RULES_TEAM_DB_LOG === 'string' ? env.AI_RULES_TEAM_DB_LOG.trim() : '';
|
|
2372
|
+
const target = override
|
|
2373
|
+
? path.resolve(override)
|
|
2374
|
+
: path.join(process.cwd(), '.ai.local', 'team', 'team-db-errors.log');
|
|
2375
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2376
|
+
fs.appendFileSync(target, `${new Date().toISOString()} ${code} cli ${message}\n`);
|
|
2377
|
+
let lines = fs.readFileSync(target, 'utf8').split('\n').filter((entry) => entry.length > 0);
|
|
2378
|
+
if (lines.length > 200) lines = lines.slice(lines.length - 200);
|
|
2379
|
+
while (Buffer.byteLength(`${lines.join('\n')}\n`, 'utf8') > 65536 && lines.length > 1) lines.shift();
|
|
2380
|
+
fs.writeFileSync(target, lines.length > 0 ? `${lines.join('\n')}\n` : '');
|
|
2381
|
+
} catch {
|
|
2382
|
+
/* a log failure is not a projection failure */
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
|
|
1759
2386
|
const maintainDatabase = (db, now) => {
|
|
1760
2387
|
const retentionCutoff = new Date(Date.now() - RETENTION_DAYS * 24 * 60 * 60 * 1000).toISOString();
|
|
1761
2388
|
const staleCutoff = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
|
|
@@ -1772,6 +2399,15 @@ const maintainDatabase = (db, now) => {
|
|
|
1772
2399
|
if (hasSearchTable(db)) db.prepare('DELETE FROM search_fts WHERE task_slug = ?').run(row.slug);
|
|
1773
2400
|
if (changed > 0) retained += 1;
|
|
1774
2401
|
}
|
|
2402
|
+
// The telemetry plane keeps the same cutoff as document retention (§3.2).
|
|
2403
|
+
const retentionDay = retentionCutoff.slice(0, 10);
|
|
2404
|
+
db.prepare('DELETE FROM tool_calls WHERE day < ?').run(retentionDay);
|
|
2405
|
+
db.prepare('DELETE FROM usage_turns WHERE day < ?').run(retentionDay);
|
|
2406
|
+
db.prepare(
|
|
2407
|
+
`DELETE FROM efficiency_runs WHERE run_key NOT IN (
|
|
2408
|
+
SELECT run_key FROM efficiency_runs ORDER BY generated_at DESC LIMIT 50
|
|
2409
|
+
)`,
|
|
2410
|
+
).run();
|
|
1775
2411
|
db.prepare(
|
|
1776
2412
|
`DELETE FROM sync_runs WHERE run_id NOT IN (
|
|
1777
2413
|
SELECT run_id FROM sync_runs ORDER BY run_id DESC LIMIT ?
|
|
@@ -1845,6 +2481,10 @@ export function syncProjection(options = {}) {
|
|
|
1845
2481
|
if (slug && (prune || vacuum || options.maintain)) {
|
|
1846
2482
|
teamDbFail('E_USAGE', '--maintain, --prune and --vacuum cannot be combined with --slug', 3);
|
|
1847
2483
|
}
|
|
2484
|
+
if (slug && options.telemetry === true) {
|
|
2485
|
+
teamDbFail('E_USAGE', '--telemetry cannot be combined with --slug', 3);
|
|
2486
|
+
}
|
|
2487
|
+
const telemetry = !slug && options.telemetry !== false;
|
|
1848
2488
|
const deadlineAt = resolveDeadline(options.deadlineMs, slug);
|
|
1849
2489
|
const startedAt = new Date().toISOString();
|
|
1850
2490
|
const handle = openTeamDb({
|
|
@@ -1952,6 +2592,20 @@ export function syncProjection(options = {}) {
|
|
|
1952
2592
|
result.failed += schedulerProjection.failed;
|
|
1953
2593
|
for (const error of schedulerProjection.errors) result.errors.push(error);
|
|
1954
2594
|
}
|
|
2595
|
+
if (telemetry) {
|
|
2596
|
+
try {
|
|
2597
|
+
projectTelemetry({
|
|
2598
|
+
db,
|
|
2599
|
+
teamRoot: handle.teamRoot,
|
|
2600
|
+
now: new Date().toISOString(),
|
|
2601
|
+
deadlineAt,
|
|
2602
|
+
env: options.env,
|
|
2603
|
+
});
|
|
2604
|
+
} catch (error) {
|
|
2605
|
+
// A telemetry projection failure is recorded, never a failed sync.
|
|
2606
|
+
logProjectionFailure('E_TELEMETRY_FAILED', error.message, options.env);
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
1955
2609
|
if (maintain) {
|
|
1956
2610
|
result.retained += maintainDatabase(db, startedAt).retained;
|
|
1957
2611
|
retainRuns(db);
|