@bonesofspring/ai-rules 0.2.73 → 0.2.76
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 +88 -0
- package/README.md +2 -2
- package/bin/lib/engine-scripts.js +12 -0
- package/docs/TEAM-DB.md +96 -5
- package/docs/TOKEN-ECONOMY.md +18 -5
- package/docs/openapi/team-db.v1.json +1164 -224
- package/package.json +2 -2
- package/presets/_shared/ai-local/scripts/action-signals.mjs +225 -0
- package/presets/_shared/ai-local/scripts/actions-report.mjs +210 -0
- package/presets/_shared/ai-local/scripts/check-write-scope.mjs +56 -26
- package/presets/_shared/ai-local/scripts/lock.mjs +103 -30
- package/presets/_shared/ai-local/scripts/processes.mjs +5 -4
- package/presets/_shared/ai-local/scripts/rr-scheduler-start.mjs +161 -0
- package/presets/_shared/ai-local/scripts/rule-improver.mjs +4 -0
- package/presets/_shared/ai-local/scripts/run-compact.mjs +132 -0
- package/presets/_shared/ai-local/scripts/signals.mjs +3 -1
- package/presets/_shared/ai-local/scripts/team-db-api.mjs +354 -11
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +309 -4
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +515 -26
- package/presets/_shared/ai-local/scripts/team-db-scheduler.mjs +32 -2
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +185 -1
- package/presets/_shared/ai-local/scripts/team-db-task-runner.mjs +3 -1
- package/presets/_shared/core/agent-team/agent-task-metrics.md +29 -0
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +1 -1
- package/presets/_shared/core/meta/preset-pr-checklist.md +2 -2
- package/presets/_shared/core/quality/context-and-iteration.md +1 -1
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +18 -1
- package/presets/_shared/hooks/compact-shell-output.mjs +68 -0
- package/presets/claude/android-kotlin/commands/README.md +4 -0
- package/presets/claude/android-kotlin/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/android-kotlin/team/README.md +1 -1
- package/presets/claude/go/commands/README.md +4 -0
- package/presets/claude/go/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/go/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/go/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/go/team/README.md +1 -1
- package/presets/claude/ios-swift/commands/README.md +4 -0
- package/presets/claude/ios-swift/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/ios-swift/team/README.md +1 -1
- package/presets/claude/java/commands/README.md +4 -0
- package/presets/claude/java/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/java/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/java/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/java/team/README.md +1 -1
- package/presets/claude/mcp-ts/commands/README.md +4 -0
- package/presets/claude/mcp-ts/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/mcp-ts/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/mcp-ts/team/README.md +1 -1
- package/presets/claude/mol/commands/README.md +4 -0
- package/presets/claude/mol/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/mol/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/mol/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/mol/team/README.md +1 -1
- package/presets/claude/next/agents/build-verifier.md +1 -1
- package/presets/claude/next/agents/code-reviewer.md +2 -0
- package/presets/claude/next/commands/README.md +4 -0
- package/presets/claude/next/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/next/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/next/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/next/team/README.md +1 -1
- package/presets/claude/nuxt/commands/README.md +4 -0
- package/presets/claude/nuxt/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/nuxt/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/nuxt/team/README.md +1 -1
- package/presets/claude/php-hexagonal/commands/README.md +4 -0
- package/presets/claude/php-hexagonal/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/php-hexagonal/team/README.md +1 -1
- package/presets/claude/php-laravel/commands/README.md +4 -0
- package/presets/claude/php-laravel/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/php-laravel/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/php-laravel/team/README.md +1 -1
- package/presets/claude/svelte/commands/README.md +4 -0
- package/presets/claude/svelte/commands/rr-scheduler-start.md +32 -0
- package/presets/claude/svelte/hooks/chain-team-phases.sh +18 -1
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
- package/presets/claude/svelte/rules/tooling-and-review/preset-pr-checklist.md +2 -2
- package/presets/claude/svelte/team/README.md +1 -1
- package/presets/cursor/android-kotlin/commands/README.md +4 -0
- package/presets/cursor/android-kotlin/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/android-kotlin/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/android-kotlin/hooks.json +7 -0
- package/presets/cursor/android-kotlin/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/android-kotlin/team/README.md +1 -1
- package/presets/cursor/go/commands/README.md +4 -0
- package/presets/cursor/go/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/go/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/go/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/go/hooks.json +7 -0
- package/presets/cursor/go/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/go/team/README.md +1 -1
- package/presets/cursor/ios-swift/commands/README.md +4 -0
- package/presets/cursor/ios-swift/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/ios-swift/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/ios-swift/hooks.json +7 -0
- package/presets/cursor/ios-swift/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/ios-swift/team/README.md +1 -1
- package/presets/cursor/java/commands/README.md +4 -0
- package/presets/cursor/java/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/java/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/java/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/java/hooks.json +7 -0
- package/presets/cursor/java/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/java/team/README.md +1 -1
- package/presets/cursor/mcp-ts/commands/README.md +4 -0
- package/presets/cursor/mcp-ts/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/mcp-ts/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/mcp-ts/hooks.json +7 -0
- package/presets/cursor/mcp-ts/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/mcp-ts/team/README.md +1 -1
- package/presets/cursor/mol/commands/README.md +4 -0
- package/presets/cursor/mol/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/mol/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/mol/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/mol/hooks.json +7 -0
- package/presets/cursor/mol/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/mol/team/README.md +1 -1
- package/presets/cursor/next/agents/build-verifier.md +1 -1
- package/presets/cursor/next/agents/code-reviewer.md +2 -0
- package/presets/cursor/next/commands/README.md +4 -0
- package/presets/cursor/next/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/next/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/next/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/next/hooks.json +7 -0
- package/presets/cursor/next/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/next/team/README.md +1 -1
- package/presets/cursor/nuxt/commands/README.md +4 -0
- package/presets/cursor/nuxt/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/nuxt/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/nuxt/hooks.json +7 -0
- package/presets/cursor/nuxt/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/nuxt/team/README.md +1 -1
- package/presets/cursor/php-hexagonal/commands/README.md +4 -0
- package/presets/cursor/php-hexagonal/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/php-hexagonal/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/php-hexagonal/hooks.json +7 -0
- package/presets/cursor/php-hexagonal/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/php-hexagonal/team/README.md +1 -1
- package/presets/cursor/php-laravel/commands/README.md +4 -0
- package/presets/cursor/php-laravel/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/php-laravel/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/php-laravel/hooks.json +7 -0
- package/presets/cursor/php-laravel/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/php-laravel/team/README.md +1 -1
- package/presets/cursor/svelte/commands/README.md +4 -0
- package/presets/cursor/svelte/commands/rr-scheduler-start.md +32 -0
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +18 -1
- package/presets/cursor/svelte/hooks/compact-shell-output.mjs +68 -0
- package/presets/cursor/svelte/hooks.json +7 -0
- package/presets/cursor/svelte/rules/preset-pr-checklist.mdc +2 -2
- package/presets/cursor/svelte/team/README.md +1 -1
- package/presets/mavis/android-kotlin/adapter-map.json +17 -1
- package/presets/mavis/android-kotlin/commands/README.md +4 -0
- package/presets/mavis/android-kotlin/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/android-kotlin/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/android-kotlin/team/README.md +1 -1
- package/presets/mavis/go/adapter-map.json +17 -1
- package/presets/mavis/go/commands/README.md +4 -0
- package/presets/mavis/go/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/go/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/go/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/go/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/go/team/README.md +1 -1
- package/presets/mavis/ios-swift/adapter-map.json +17 -1
- package/presets/mavis/ios-swift/commands/README.md +4 -0
- package/presets/mavis/ios-swift/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/ios-swift/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/ios-swift/team/README.md +1 -1
- package/presets/mavis/java/adapter-map.json +17 -1
- package/presets/mavis/java/commands/README.md +4 -0
- package/presets/mavis/java/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/java/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/java/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/java/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/java/team/README.md +1 -1
- package/presets/mavis/mcp-ts/adapter-map.json +17 -1
- package/presets/mavis/mcp-ts/commands/README.md +4 -0
- package/presets/mavis/mcp-ts/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/mcp-ts/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/mcp-ts/team/README.md +1 -1
- package/presets/mavis/mol/adapter-map.json +17 -1
- package/presets/mavis/mol/commands/README.md +4 -0
- package/presets/mavis/mol/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/mol/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/mol/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/mol/team/README.md +1 -1
- package/presets/mavis/next/adapter-map.json +17 -1
- package/presets/mavis/next/agents/build-verifier.md +1 -1
- package/presets/mavis/next/agents/code-reviewer.md +2 -0
- package/presets/mavis/next/commands/README.md +4 -0
- package/presets/mavis/next/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/next/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/next/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/next/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/next/team/README.md +1 -1
- package/presets/mavis/nuxt/adapter-map.json +17 -1
- package/presets/mavis/nuxt/commands/README.md +4 -0
- package/presets/mavis/nuxt/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/nuxt/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/nuxt/team/README.md +1 -1
- package/presets/mavis/php-hexagonal/adapter-map.json +17 -1
- package/presets/mavis/php-hexagonal/commands/README.md +4 -0
- package/presets/mavis/php-hexagonal/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/php-hexagonal/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/php-hexagonal/team/README.md +1 -1
- package/presets/mavis/php-laravel/adapter-map.json +17 -1
- package/presets/mavis/php-laravel/commands/README.md +4 -0
- package/presets/mavis/php-laravel/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/php-laravel/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/php-laravel/team/README.md +1 -1
- package/presets/mavis/svelte/adapter-map.json +17 -1
- package/presets/mavis/svelte/commands/README.md +4 -0
- package/presets/mavis/svelte/commands/rr-scheduler-start.md +27 -0
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +18 -1
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +1 -1
- package/presets/mavis/svelte/rules/preset-pr-checklist.md +2 -2
- package/presets/mavis/svelte/team/README.md +1 -1
- package/presets/opencode/android-kotlin/adapter-map.json +17 -1
- package/presets/opencode/android-kotlin/commands/README.md +4 -0
- package/presets/opencode/android-kotlin/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/android-kotlin/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/android-kotlin/team/README.md +1 -1
- package/presets/opencode/go/adapter-map.json +17 -1
- package/presets/opencode/go/commands/README.md +4 -0
- package/presets/opencode/go/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/go/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/go/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/go/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/go/team/README.md +1 -1
- package/presets/opencode/ios-swift/adapter-map.json +17 -1
- package/presets/opencode/ios-swift/commands/README.md +4 -0
- package/presets/opencode/ios-swift/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/ios-swift/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/ios-swift/team/README.md +1 -1
- package/presets/opencode/java/adapter-map.json +17 -1
- package/presets/opencode/java/commands/README.md +4 -0
- package/presets/opencode/java/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/java/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/java/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/java/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/java/team/README.md +1 -1
- package/presets/opencode/mcp-ts/adapter-map.json +17 -1
- package/presets/opencode/mcp-ts/commands/README.md +4 -0
- package/presets/opencode/mcp-ts/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/mcp-ts/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/mcp-ts/team/README.md +1 -1
- package/presets/opencode/mol/adapter-map.json +17 -1
- package/presets/opencode/mol/commands/README.md +4 -0
- package/presets/opencode/mol/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/mol/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/mol/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/mol/team/README.md +1 -1
- package/presets/opencode/next/adapter-map.json +17 -1
- package/presets/opencode/next/agents/build-verifier.md +1 -1
- package/presets/opencode/next/agents/code-reviewer.md +2 -0
- package/presets/opencode/next/commands/README.md +4 -0
- package/presets/opencode/next/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/next/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/next/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/next/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/next/team/README.md +1 -1
- package/presets/opencode/nuxt/adapter-map.json +17 -1
- package/presets/opencode/nuxt/commands/README.md +4 -0
- package/presets/opencode/nuxt/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/nuxt/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/nuxt/team/README.md +1 -1
- package/presets/opencode/php-hexagonal/adapter-map.json +17 -1
- package/presets/opencode/php-hexagonal/commands/README.md +4 -0
- package/presets/opencode/php-hexagonal/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/php-hexagonal/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/php-hexagonal/team/README.md +1 -1
- package/presets/opencode/php-laravel/adapter-map.json +17 -1
- package/presets/opencode/php-laravel/commands/README.md +4 -0
- package/presets/opencode/php-laravel/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/php-laravel/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/php-laravel/team/README.md +1 -1
- package/presets/opencode/plugins/output-guard/README.md +45 -3
- package/presets/opencode/plugins/output-guard/actions.ts +201 -0
- package/presets/opencode/plugins/output-guard/index.ts +147 -6
- package/presets/opencode/plugins/output-guard/rewrite.ts +10 -1
- package/presets/opencode/svelte/adapter-map.json +17 -1
- package/presets/opencode/svelte/commands/README.md +4 -0
- package/presets/opencode/svelte/commands/rr-scheduler-start.md +35 -0
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +18 -1
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +1 -1
- package/presets/opencode/svelte/rules/preset-pr-checklist.md +2 -2
- package/presets/opencode/svelte/team/README.md +1 -1
- package/presets/zcode/android-kotlin/adapter-map.json +17 -1
- package/presets/zcode/android-kotlin/commands/README.md +4 -0
- package/presets/zcode/android-kotlin/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/android-kotlin/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/android-kotlin/team/README.md +1 -1
- package/presets/zcode/go/adapter-map.json +17 -1
- package/presets/zcode/go/commands/README.md +4 -0
- package/presets/zcode/go/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/go/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/go/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/go/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/go/team/README.md +1 -1
- package/presets/zcode/ios-swift/adapter-map.json +17 -1
- package/presets/zcode/ios-swift/commands/README.md +4 -0
- package/presets/zcode/ios-swift/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/ios-swift/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/ios-swift/team/README.md +1 -1
- package/presets/zcode/java/adapter-map.json +17 -1
- package/presets/zcode/java/commands/README.md +4 -0
- package/presets/zcode/java/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/java/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/java/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/java/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/java/team/README.md +1 -1
- package/presets/zcode/mcp-ts/adapter-map.json +17 -1
- package/presets/zcode/mcp-ts/commands/README.md +4 -0
- package/presets/zcode/mcp-ts/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/mcp-ts/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/mcp-ts/team/README.md +1 -1
- package/presets/zcode/mol/adapter-map.json +17 -1
- package/presets/zcode/mol/commands/README.md +4 -0
- package/presets/zcode/mol/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/mol/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/mol/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/mol/team/README.md +1 -1
- package/presets/zcode/next/adapter-map.json +17 -1
- package/presets/zcode/next/agents/build-verifier.md +1 -1
- package/presets/zcode/next/agents/code-reviewer.md +2 -0
- package/presets/zcode/next/commands/README.md +4 -0
- package/presets/zcode/next/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/next/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/next/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/next/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/next/team/README.md +1 -1
- package/presets/zcode/nuxt/adapter-map.json +17 -1
- package/presets/zcode/nuxt/commands/README.md +4 -0
- package/presets/zcode/nuxt/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/nuxt/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/nuxt/team/README.md +1 -1
- package/presets/zcode/php-hexagonal/adapter-map.json +17 -1
- package/presets/zcode/php-hexagonal/commands/README.md +4 -0
- package/presets/zcode/php-hexagonal/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/php-hexagonal/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/php-hexagonal/team/README.md +1 -1
- package/presets/zcode/php-laravel/adapter-map.json +17 -1
- package/presets/zcode/php-laravel/commands/README.md +4 -0
- package/presets/zcode/php-laravel/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/php-laravel/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/php-laravel/team/README.md +1 -1
- package/presets/zcode/svelte/adapter-map.json +17 -1
- package/presets/zcode/svelte/commands/README.md +4 -0
- package/presets/zcode/svelte/commands/rr-scheduler-start.md +35 -0
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +18 -1
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +1 -1
- package/presets/zcode/svelte/rules/preset-pr-checklist.md +2 -2
- package/presets/zcode/svelte/team/README.md +1 -1
- package/scripts/close-agent-task-human-gate.mjs +3 -3
- package/scripts/report-context-cost.mjs +10 -3
- package/scripts/aggregate-agent-task-metrics.mjs +0 -480
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
* inside an atomic `<lock>.d.reclaim` guard. The guard serialises the decision
|
|
11
11
|
* and the owner is re-read inside it, so a contender that judged the lock stale
|
|
12
12
|
* a moment earlier cannot delete the directory another process created since.
|
|
13
|
+
* The guard directory names its own owner. A contender removes a guard only
|
|
14
|
+
* when that pid is dead, or when the guard has no owner and has aged out; the
|
|
15
|
+
* removal renames that directory aside and deletes it only if the renamed
|
|
16
|
+
* inode and owner are the ones just evaluated. Age alone never drops a guard
|
|
17
|
+
* a live pid still holds.
|
|
13
18
|
*
|
|
14
19
|
* `releaseLock` only drops a lock this process acquired. A token from another
|
|
15
20
|
* process is ignored.
|
|
@@ -84,32 +89,86 @@ function removeOwnedDir(directory, token) {
|
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
|
|
92
|
+
/** dev/ino plus the owner record. `null` when the directory is already gone. */
|
|
93
|
+
function directoryIdentity(directory) {
|
|
94
|
+
let stat;
|
|
95
|
+
try {
|
|
96
|
+
stat = fs.statSync(directory, { bigint: true });
|
|
97
|
+
} catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
dev: stat.dev,
|
|
102
|
+
ino: stat.ino,
|
|
103
|
+
mtimeMs: Number(stat.mtimeMs),
|
|
104
|
+
owner: readOwner(directory),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
87
108
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
109
|
+
* The renamed directory is the one we evaluated. A path-only delete can move
|
|
110
|
+
* a guard another live reclaimer created after the age check.
|
|
90
111
|
*/
|
|
91
|
-
function
|
|
112
|
+
function sameInstance(observed, renamed) {
|
|
113
|
+
if (!observed || !renamed) return false;
|
|
114
|
+
if (observed.dev !== renamed.dev || observed.ino !== renamed.ino) return false;
|
|
115
|
+
const left = observed.owner;
|
|
116
|
+
const right = renamed.owner;
|
|
117
|
+
if (!left && !right) return true;
|
|
118
|
+
if (!left || !right) return false;
|
|
119
|
+
if (typeof left.token === 'string' || typeof right.token === 'string') {
|
|
120
|
+
return left.token === right.token;
|
|
121
|
+
}
|
|
122
|
+
return left.pid === right.pid;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function compareAndRemove(directory, observed) {
|
|
126
|
+
if (!observed) return false;
|
|
127
|
+
const trash = `${directory}.dead-${crypto.randomBytes(4).toString('hex')}`;
|
|
92
128
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
129
|
+
fs.renameSync(directory, trash);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return Boolean(error && error.code === 'ENOENT');
|
|
132
|
+
}
|
|
133
|
+
if (!sameInstance(observed, directoryIdentity(trash))) {
|
|
134
|
+
try { fs.renameSync(trash, directory); } catch { /* the path belongs to a successor */ }
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
fs.rmSync(trash, { recursive: true, force: true });
|
|
95
139
|
return true;
|
|
96
140
|
} catch {
|
|
97
141
|
return false;
|
|
98
142
|
}
|
|
99
143
|
}
|
|
100
144
|
|
|
101
|
-
|
|
102
|
-
|
|
145
|
+
/**
|
|
146
|
+
* A live owner pid holds the guard however old it is. A dead pid is abandoned
|
|
147
|
+
* immediately. An owner-less guard is the mkdir → owner.json window and is
|
|
148
|
+
* abandoned only after the stale window.
|
|
149
|
+
*/
|
|
150
|
+
function guardIsAbandoned(identity) {
|
|
151
|
+
if (!identity) return false;
|
|
152
|
+
const owner = identity.owner;
|
|
153
|
+
if (owner && Number.isInteger(owner.pid) && owner.pid > 0) {
|
|
154
|
+
return !isPidAlive(owner.pid);
|
|
155
|
+
}
|
|
156
|
+
return Date.now() - identity.mtimeMs > DEFAULT_STALE_MS;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function lockIdentityIsGone(identity) {
|
|
160
|
+
if (!identity) return false;
|
|
161
|
+
const owner = identity.owner;
|
|
103
162
|
if (owner) {
|
|
104
163
|
return Number.isInteger(owner.pid) && owner.pid > 0 && !isPidAlive(owner.pid);
|
|
105
164
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
165
|
+
return Date.now() - identity.mtimeMs > DEFAULT_STALE_MS;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function releaseOwnGuard(guard, token) {
|
|
169
|
+
const identity = directoryIdentity(guard);
|
|
170
|
+
if (!identity || !identity.owner || identity.owner.token !== token) return;
|
|
171
|
+
compareAndRemove(guard, identity);
|
|
113
172
|
}
|
|
114
173
|
|
|
115
174
|
/**
|
|
@@ -117,28 +176,42 @@ function ownerIsGone(directory) {
|
|
|
117
176
|
* serialisation point: only the winner judges and removes, and it re-reads the
|
|
118
177
|
* owner after taking the guard. A contender that decided "stale" before the
|
|
119
178
|
* winner re-created the directory therefore sees the new, live owner and backs
|
|
120
|
-
* off instead of deleting it.
|
|
179
|
+
* off instead of deleting it. An abandoned guard is removed and taken inside
|
|
180
|
+
* this call, so the decision and the delete stay on one guard instance.
|
|
121
181
|
*/
|
|
122
182
|
function reclaimStaleDir(directory) {
|
|
123
183
|
const guard = reclaimGuardDirectory(directory);
|
|
124
|
-
|
|
125
|
-
fs.mkdirSync(guard);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
if (error.code !== 'EEXIST') throw error;
|
|
128
|
-
removeStaleGuard(guard);
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
if (!ownerIsGone(directory)) return false;
|
|
184
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
133
185
|
try {
|
|
134
|
-
fs.
|
|
135
|
-
} catch {
|
|
136
|
-
|
|
186
|
+
fs.mkdirSync(guard);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error.code !== 'EEXIST') throw error;
|
|
189
|
+
const identity = directoryIdentity(guard);
|
|
190
|
+
if (!guardIsAbandoned(identity) || !compareAndRemove(guard, identity)) return false;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const token = newToken();
|
|
194
|
+
let wrote = false;
|
|
195
|
+
try {
|
|
196
|
+
fs.writeFileSync(
|
|
197
|
+
ownerFile(guard),
|
|
198
|
+
`${JSON.stringify({ pid: process.pid, token, at: new Date().toISOString() })}\n`,
|
|
199
|
+
{ encoding: 'utf8', mode: 0o600 },
|
|
200
|
+
);
|
|
201
|
+
wrote = true;
|
|
202
|
+
const identity = directoryIdentity(directory);
|
|
203
|
+
if (!lockIdentityIsGone(identity)) return false;
|
|
204
|
+
return compareAndRemove(directory, identity);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (!wrote) {
|
|
207
|
+
try { fs.rmSync(guard, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
208
|
+
}
|
|
209
|
+
throw error;
|
|
210
|
+
} finally {
|
|
211
|
+
if (wrote) releaseOwnGuard(guard, token);
|
|
137
212
|
}
|
|
138
|
-
return true;
|
|
139
|
-
} finally {
|
|
140
|
-
try { fs.rmSync(guard, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
141
213
|
}
|
|
214
|
+
return false;
|
|
142
215
|
}
|
|
143
216
|
|
|
144
217
|
function enterDirectoryLock(lockPath, deadline, busyWaitMs) {
|
|
@@ -1360,11 +1360,12 @@ const doctorVerb = (flags) => {
|
|
|
1360
1360
|
|
|
1361
1361
|
/**
|
|
1362
1362
|
* The command-line half of the ownership proof compares the recorded command to
|
|
1363
|
-
* the live one.
|
|
1364
|
-
*
|
|
1365
|
-
* The recorded command must still be a substantive
|
|
1363
|
+
* the live one. Quotes and a leading `exec` are shell syntax — `start --command
|
|
1364
|
+
* 'exec node script.js'` reaches the child as `node script.js` — so they are
|
|
1365
|
+
* dropped on both sides. The recorded command must still be a substantive
|
|
1366
|
+
* substring of the live one.
|
|
1366
1367
|
*/
|
|
1367
|
-
const commandForProof = (value) => normalize(value).replace(/["']/g, '');
|
|
1368
|
+
const commandForProof = (value) => normalize(value).replace(/["']/g, '').replace(/^(?:exec\s+)+/, '');
|
|
1368
1369
|
|
|
1369
1370
|
const proveOwnership = (record) => {
|
|
1370
1371
|
const owner = isRecord(record?.owner) ? record.owner : null;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start the team-db scheduler, or restart it when one already holds the lease.
|
|
3
|
+
*
|
|
4
|
+
* The manager lease (`processes.mjs`) and `scheduler.lock` are both honored:
|
|
5
|
+
* a recorded manager process is stopped through `processes.mjs stop`, and a
|
|
6
|
+
* scheduler started outside the manager is signalled only when its command
|
|
7
|
+
* line is still `team-db.mjs schedule`. A lock whose pid is already dead is
|
|
8
|
+
* removed so a crash does not block the next start for `LEASE_STALE_MS`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { spawnSync } from 'node:child_process';
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
|
|
16
|
+
import { readLease, schedulerPaths } from './team-db-scheduler.mjs';
|
|
17
|
+
|
|
18
|
+
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
19
|
+
const teamRoot = path.join(repoRoot, '.ai.local', 'team');
|
|
20
|
+
const processesBin = path.join(repoRoot, '.ai.local', 'scripts', 'processes.mjs');
|
|
21
|
+
const schedulerCommand = 'exec node .ai.local/scripts/team-db.mjs schedule';
|
|
22
|
+
const termWaitMs = 8000;
|
|
23
|
+
const killWaitMs = 3000;
|
|
24
|
+
const onlineWaitMs = 5000;
|
|
25
|
+
|
|
26
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
27
|
+
setTimeout(resolve, ms);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const pidAlive = (pid) => {
|
|
31
|
+
if (!Number.isInteger(pid) || pid <= 1) return false;
|
|
32
|
+
try {
|
|
33
|
+
process.kill(pid, 0);
|
|
34
|
+
return true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return error.code === 'EPERM';
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const commandOf = (pid) => {
|
|
41
|
+
const result = spawnSync('ps', ['-p', String(pid), '-o', 'command='], { encoding: 'utf8' });
|
|
42
|
+
if (result.error || result.status !== 0) return '';
|
|
43
|
+
return String(result.stdout ?? '').trim();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const isSchedulerProcess = (command) => /team-db\.mjs\s+schedule(?:\s|$)/.test(command);
|
|
47
|
+
|
|
48
|
+
const managedPid = () => {
|
|
49
|
+
try {
|
|
50
|
+
const record = JSON.parse(
|
|
51
|
+
fs.readFileSync(path.join(repoRoot, '.ai.local', '.processes', 'leases', 'scheduler.json'), 'utf8'),
|
|
52
|
+
);
|
|
53
|
+
const pid = Number(record?.owner?.pid);
|
|
54
|
+
return pidAlive(pid) ? pid : null;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const runProcesses = (args) => {
|
|
61
|
+
const result = spawnSync(process.execPath, [processesBin, ...args], {
|
|
62
|
+
cwd: repoRoot,
|
|
63
|
+
encoding: 'utf8',
|
|
64
|
+
});
|
|
65
|
+
if (result.stdout) process.stdout.write(result.stdout);
|
|
66
|
+
if (result.stderr) process.stderr.write(result.stderr);
|
|
67
|
+
return result.status ?? 1;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const waitUntil = async (predicate, timeoutMs) => {
|
|
71
|
+
const deadline = Date.now() + timeoutMs;
|
|
72
|
+
while (Date.now() < deadline) {
|
|
73
|
+
if (predicate()) return true;
|
|
74
|
+
await sleep(200);
|
|
75
|
+
}
|
|
76
|
+
return predicate();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const removeDeadLock = () => {
|
|
80
|
+
const current = readLease(teamRoot);
|
|
81
|
+
if (current.state === 'stopped') return;
|
|
82
|
+
const pid = Number(current.lease?.pid);
|
|
83
|
+
if (pidAlive(pid)) return;
|
|
84
|
+
fs.rmSync(schedulerPaths(teamRoot).lock, { force: true });
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const stopLockHolder = async () => {
|
|
88
|
+
const current = readLease(teamRoot);
|
|
89
|
+
if (current.state !== 'running') {
|
|
90
|
+
removeDeadLock();
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const pid = Number(current.lease?.pid);
|
|
94
|
+
const command = commandOf(pid);
|
|
95
|
+
if (!pidAlive(pid)) {
|
|
96
|
+
removeDeadLock();
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if (!isSchedulerProcess(command)) {
|
|
100
|
+
process.stderr.write(`error: scheduler.lock pid ${pid} is not team-db schedule\n`);
|
|
101
|
+
process.exit(4);
|
|
102
|
+
}
|
|
103
|
+
process.kill(pid, 'SIGTERM');
|
|
104
|
+
const exited = await waitUntil(() => !pidAlive(pid), termWaitMs);
|
|
105
|
+
if (!exited && pidAlive(pid)) {
|
|
106
|
+
process.kill(pid, 'SIGKILL');
|
|
107
|
+
await waitUntil(() => !pidAlive(pid), killWaitMs);
|
|
108
|
+
}
|
|
109
|
+
if (pidAlive(pid)) {
|
|
110
|
+
process.stderr.write(`error: scheduler pid ${pid} survived SIGKILL\n`);
|
|
111
|
+
process.exit(3);
|
|
112
|
+
}
|
|
113
|
+
removeDeadLock();
|
|
114
|
+
const after = readLease(teamRoot);
|
|
115
|
+
if (after.state === 'running' && pidAlive(Number(after.lease?.pid))) {
|
|
116
|
+
process.stderr.write('error: a scheduler still holds the lease\n');
|
|
117
|
+
process.exit(4);
|
|
118
|
+
}
|
|
119
|
+
return pid;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const tailLog = () => {
|
|
123
|
+
const file = path.join(repoRoot, '.ai.local', '.processes', 'logs', 'scheduler.log');
|
|
124
|
+
try {
|
|
125
|
+
return fs.readFileSync(file, 'utf8').split('\n').filter(Boolean).slice(-20).join('\n');
|
|
126
|
+
} catch {
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const main = async () => {
|
|
132
|
+
const recordedPid = managedPid();
|
|
133
|
+
const managed = runProcesses(['stop', '--name', 'scheduler']);
|
|
134
|
+
if (managed === 4) process.exit(4);
|
|
135
|
+
if (managed !== 0) process.exit(managed);
|
|
136
|
+
const stoppedPid = (await stopLockHolder()) ?? recordedPid;
|
|
137
|
+
const started = runProcesses([
|
|
138
|
+
'start',
|
|
139
|
+
'--name',
|
|
140
|
+
'scheduler',
|
|
141
|
+
'--command',
|
|
142
|
+
schedulerCommand,
|
|
143
|
+
]);
|
|
144
|
+
if (started !== 0) process.exit(started);
|
|
145
|
+
const online = await waitUntil(() => {
|
|
146
|
+
const lease = readLease(teamRoot);
|
|
147
|
+
return lease.state === 'running' && pidAlive(Number(lease.lease?.pid));
|
|
148
|
+
}, onlineWaitMs);
|
|
149
|
+
if (!online) {
|
|
150
|
+
const tail = tailLog();
|
|
151
|
+
process.stderr.write('error: scheduler did not take a fresh lease\n');
|
|
152
|
+
if (tail !== '') process.stderr.write(`${tail}\n`);
|
|
153
|
+
process.exit(3);
|
|
154
|
+
}
|
|
155
|
+
const pid = Number(readLease(teamRoot).lease?.pid);
|
|
156
|
+
const verb = stoppedPid === null ? 'started' : 'restarted';
|
|
157
|
+
const previous = stoppedPid === null ? '' : ` (stopped ${stoppedPid})`;
|
|
158
|
+
process.stdout.write(`scheduler: ${verb} pid ${pid}${previous}\n`);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
await main();
|
|
@@ -1887,6 +1887,10 @@ export function runImprover(options = {}) {
|
|
|
1887
1887
|
const visiblePending = [];
|
|
1888
1888
|
|
|
1889
1889
|
for (const group of enrichGroups(grouped.groups, signalsPath, canonical)) {
|
|
1890
|
+
if (typeof group.signature === 'string' && group.signature.startsWith('exemplar:')) {
|
|
1891
|
+
skipped.push({ signature: group.signature, reason: 'research exemplar' });
|
|
1892
|
+
continue;
|
|
1893
|
+
}
|
|
1890
1894
|
if (group.distinctSlugCount < 2) continue;
|
|
1891
1895
|
let decision;
|
|
1892
1896
|
try {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Run a command, store its combined output, and print a short view.
|
|
3
|
+
// Exit with the child status so a passing store cannot hide a failing test.
|
|
4
|
+
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { resolveTeamRoot } from './dump-output.mjs';
|
|
11
|
+
|
|
12
|
+
const PASS_THROUGH_BYTES = 4096;
|
|
13
|
+
const HEAD_LINES = 40;
|
|
14
|
+
const HEAD_BYTES = 8 * 1024;
|
|
15
|
+
const CAPTURE_BYTES = 2 * 1024 * 1024;
|
|
16
|
+
const FAIL_LINE = /\b(FAIL|ERROR|Error|AssertionError)\b|✗|×/u;
|
|
17
|
+
|
|
18
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const dumpScript = path.join(here, 'dump-output.mjs');
|
|
20
|
+
|
|
21
|
+
const usageFail = (message) => {
|
|
22
|
+
const error = new Error(message);
|
|
23
|
+
error.exitCode = 2;
|
|
24
|
+
throw error;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const parseArgs = (argv) => {
|
|
28
|
+
const split = argv.indexOf('--');
|
|
29
|
+
if (split === -1) usageFail('missing -- before the command');
|
|
30
|
+
const child = argv.slice(split + 1);
|
|
31
|
+
if (child.length === 0) usageFail('missing command after --');
|
|
32
|
+
let task = '';
|
|
33
|
+
let root = '';
|
|
34
|
+
for (let index = 0; index < split; index += 1) {
|
|
35
|
+
const token = argv[index];
|
|
36
|
+
if (token !== '--task' && token !== '--root') usageFail(`unknown flag ${token}`);
|
|
37
|
+
const value = argv[index + 1];
|
|
38
|
+
if (value === undefined || value.startsWith('--')) usageFail(`flag ${token} needs a value`);
|
|
39
|
+
if (token === '--task') task = value;
|
|
40
|
+
else root = value;
|
|
41
|
+
index += 1;
|
|
42
|
+
}
|
|
43
|
+
if (task === '') usageFail('missing --task');
|
|
44
|
+
return { task, root, child };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const footerOf = (dumpStdout) =>
|
|
48
|
+
dumpStdout
|
|
49
|
+
.split('\n')
|
|
50
|
+
.filter((line) => line.startsWith('bytes: ') || line.startsWith('path: ') || line.startsWith('grep -n '))
|
|
51
|
+
.join('\n');
|
|
52
|
+
|
|
53
|
+
const failureLines = (text) => {
|
|
54
|
+
const lines = text.split('\n');
|
|
55
|
+
if (lines.length > 0 && lines[lines.length - 1] === '') lines.pop();
|
|
56
|
+
const picked = [];
|
|
57
|
+
let used = 0;
|
|
58
|
+
for (let index = 0; index < lines.length && picked.length < HEAD_LINES; index += 1) {
|
|
59
|
+
if (!FAIL_LINE.test(lines[index])) continue;
|
|
60
|
+
const block = [lines[index]];
|
|
61
|
+
if (lines[index + 1]) block.push(lines[index + 1]);
|
|
62
|
+
for (const line of block) {
|
|
63
|
+
if (picked.length >= HEAD_LINES) break;
|
|
64
|
+
const size = Buffer.byteLength(line) + 1;
|
|
65
|
+
if (used + size > HEAD_BYTES) return picked;
|
|
66
|
+
picked.push(line);
|
|
67
|
+
used += size;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return picked;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const viewFor = ({ dumpStdout, storedText, storedBytes }) => {
|
|
74
|
+
if (storedBytes <= PASS_THROUGH_BYTES) return dumpStdout;
|
|
75
|
+
const picked = failureLines(storedText);
|
|
76
|
+
if (picked.length === 0) return dumpStdout;
|
|
77
|
+
const footer = footerOf(dumpStdout);
|
|
78
|
+
return `head:\n${picked.join('\n')}\n${footer}\n`;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const run = ({ task, root, child }) => {
|
|
82
|
+
const teamRoot = root ? path.resolve(root) : resolveTeamRoot(process.cwd());
|
|
83
|
+
if (!teamRoot) usageFail('no .ai.local/team found above the current directory; pass --root <team-dir>');
|
|
84
|
+
const captured = spawnSync(child[0], child.slice(1), {
|
|
85
|
+
cwd: process.cwd(),
|
|
86
|
+
maxBuffer: CAPTURE_BYTES,
|
|
87
|
+
});
|
|
88
|
+
const status = captured.status ?? 128;
|
|
89
|
+
const body = Buffer.concat([captured.stdout ?? Buffer.alloc(0), captured.stderr ?? Buffer.alloc(0)]);
|
|
90
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'run-compact-'));
|
|
91
|
+
const input = path.join(dir, 'output.bin');
|
|
92
|
+
try {
|
|
93
|
+
fs.writeFileSync(input, body);
|
|
94
|
+
const stored = spawnSync(
|
|
95
|
+
process.execPath,
|
|
96
|
+
[dumpScript, '--input', input, '--task', task, '--label', 'compact', '--root', teamRoot],
|
|
97
|
+
{ encoding: 'utf8' },
|
|
98
|
+
);
|
|
99
|
+
if (stored.status !== 0) {
|
|
100
|
+
process.stderr.write(stored.stderr || stored.stdout || '');
|
|
101
|
+
return status;
|
|
102
|
+
}
|
|
103
|
+
const storedBytesMatch = stored.stdout.match(/^bytes: (\d+)/m);
|
|
104
|
+
const storedBytes = storedBytesMatch ? Number(storedBytesMatch[1]) : body.length;
|
|
105
|
+
const storedText = body.subarray(0, CAPTURE_BYTES).toString('utf8');
|
|
106
|
+
const view = viewFor({ dumpStdout: stored.stdout, storedText, storedBytes });
|
|
107
|
+
const shownBytes = Buffer.byteLength(view);
|
|
108
|
+
process.stdout.write(view);
|
|
109
|
+
process.stdout.write(`stored_bytes: ${storedBytes} shown_bytes: ${shownBytes}\n`);
|
|
110
|
+
return status;
|
|
111
|
+
} finally {
|
|
112
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const invokedDirectly = (() => {
|
|
117
|
+
if (!process.argv[1]) return false;
|
|
118
|
+
try {
|
|
119
|
+
return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
120
|
+
} catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
})();
|
|
124
|
+
|
|
125
|
+
if (invokedDirectly) {
|
|
126
|
+
try {
|
|
127
|
+
process.exitCode = run(parseArgs(process.argv.slice(2)));
|
|
128
|
+
} catch (error) {
|
|
129
|
+
process.stderr.write(`run-compact: ${error.message}\n`);
|
|
130
|
+
process.exitCode = typeof error.exitCode === 'number' ? error.exitCode : 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -21,7 +21,9 @@ import { acquireLock, releaseLock } from './lock.mjs';
|
|
|
21
21
|
const SIGNALS_FILE = 'signals.jsonl';
|
|
22
22
|
export const DEFAULT_SIGNALS_PATH = path.join(process.cwd(), '.ai.local', SIGNALS_FILE);
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
// `exemplar` is a repeated clean path, not a wrong turn. The rule improver
|
|
25
|
+
// skips it; the efficacy oracle's wrong-turn list does not include it.
|
|
26
|
+
const KINDS = ['correction', 'retry', 'waste', 'reversal', 'dead-end', 'exemplar'];
|
|
25
27
|
const SEVERITIES = ['high', 'med', 'low'];
|
|
26
28
|
const SOURCES = ['self-review', 'gate', 'technical-retro', 'user'];
|
|
27
29
|
const STATUSES = ['proposed', 'staged', 'applied', 'rolled_back', 'rejected'];
|