@bonesofspring/ai-rules 0.2.87 → 0.2.90
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 +9 -1
- package/bin/lib/engine-scripts.js +7 -0
- package/bin/lib/seed-ai-local-team.js +40 -0
- package/bin/opencode-install.js +11 -10
- package/docs/OPENCODE.md +8 -4
- package/docs/openapi/team-db.v1.json +2 -2
- package/package.json +1 -1
- package/presets/_shared/ai-local/env.example +54 -0
- package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +34 -5
- package/presets/_shared/ai-local/scripts/check-task-repositories.mjs +25 -22
- package/presets/_shared/ai-local/scripts/process-lease.mjs +3 -2
- package/presets/_shared/ai-local/scripts/processes.mjs +52 -20
- package/presets/_shared/ai-local/scripts/run.mjs +38 -6
- package/presets/_shared/ai-local/scripts/settings.mjs +246 -0
- package/presets/_shared/ai-local/scripts/task-worktree.mjs +364 -0
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +2 -2
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +87 -14
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +102 -12
- package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +35 -0
- package/presets/_shared/ai-local/scripts/tracker-planned-drain.mjs +10 -1
- package/presets/_shared/ai-local/scripts/verification.mjs +106 -11
- package/presets/_shared/core/agent-team/agent-task-metrics.md +10 -2
- package/presets/_shared/core/agent-team/agent-team-intake.md +2 -0
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +2 -2
- package/presets/_shared/core/meta/preset-writing-style.md +8 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +541 -61
- package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +733 -9
- package/presets/_shared/hooks/prompt-autoroute.mjs.tmpl +153 -0
- package/presets/claude/android-kotlin/CLAUDE.md +2 -4
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/android-kotlin/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/android-kotlin/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/android-kotlin/settings.json +15 -5
- package/presets/claude/go/CLAUDE.md +2 -4
- package/presets/claude/go/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/go/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/go/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/go/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/go/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/go/settings.json +15 -5
- package/presets/claude/ios-swift/CLAUDE.md +2 -4
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/ios-swift/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/ios-swift/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/ios-swift/settings.json +15 -5
- package/presets/claude/java/CLAUDE.md +2 -4
- package/presets/claude/java/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/java/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/java/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/java/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/java/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/java/settings.json +15 -5
- package/presets/claude/mcp-ts/CLAUDE.md +2 -4
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/mcp-ts/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/mcp-ts/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/mcp-ts/settings.json +15 -5
- package/presets/claude/mol/CLAUDE.md +2 -4
- package/presets/claude/mol/agents/feature-developer.md +1 -1
- package/presets/claude/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/claude/mol/commands/task-evil.md +8 -0
- package/presets/claude/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/mol/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/mol/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/mol/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/mol/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/mol/settings.json +15 -4
- package/presets/claude/next/CLAUDE.md +2 -4
- package/presets/claude/next/REPO_AGENTS.md +2 -0
- package/presets/claude/next/agents/feature-developer.md +1 -1
- package/presets/claude/next/agents/task-analyst.md +1 -7
- package/presets/claude/next/agents/task-router.md +1 -1
- package/presets/claude/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/claude/next/commands/spec-start.md +3 -4
- package/presets/claude/next/commands/task-continue.md +9 -8
- package/presets/claude/next/commands/task-evil.md +8 -0
- package/presets/claude/next/commands/task.md +1 -1
- package/presets/claude/next/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/next/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/next/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/next/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/next/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/next/settings.json +15 -4
- package/presets/claude/next/team/README.md +1 -1
- package/presets/claude/nuxt/CLAUDE.md +2 -4
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/nuxt/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/nuxt/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/nuxt/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/nuxt/settings.json +15 -4
- package/presets/claude/php-hexagonal/CLAUDE.md +2 -4
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/php-hexagonal/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/php-hexagonal/settings.json +15 -5
- package/presets/claude/php-laravel/CLAUDE.md +2 -4
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/php-laravel/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/php-laravel/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/php-laravel/settings.json +15 -5
- package/presets/claude/svelte/CLAUDE.md +2 -4
- package/presets/claude/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/svelte/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/svelte/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/svelte/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/svelte/settings.json +15 -4
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/android-kotlin/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/android-kotlin/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/go/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/go/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/go/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/go/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/ios-swift/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/ios-swift/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/java/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/java/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/java/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/java/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/mcp-ts/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mcp-ts/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/mol/agents/feature-developer.md +1 -1
- package/presets/cursor/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/cursor/mol/commands/task-evil.md +8 -0
- package/presets/cursor/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/mol/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/mol/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mol/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/next/REPO_AGENTS.md +2 -0
- package/presets/cursor/next/agents/feature-developer.md +1 -1
- package/presets/cursor/next/agents/task-analyst.md +1 -7
- package/presets/cursor/next/agents/task-router.md +1 -1
- package/presets/cursor/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/cursor/next/commands/spec-start.md +3 -4
- package/presets/cursor/next/commands/task-continue.md +9 -8
- package/presets/cursor/next/commands/task-evil.md +8 -0
- package/presets/cursor/next/commands/task.md +1 -1
- package/presets/cursor/next/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/next/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/next/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +2 -2
- package/presets/cursor/next/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/next/team/README.md +1 -1
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/nuxt/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/nuxt/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/php-hexagonal/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-hexagonal/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/php-laravel/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-laravel/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/svelte/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/svelte/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/svelte/rules/preset-writing-style.mdc +8 -0
- package/presets/mavis/android-kotlin/MAVIS.md +1 -1
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/android-kotlin/rules/agent-team-intake.md +2 -0
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/android-kotlin/rules/preset-writing-style.md +8 -0
- package/presets/mavis/go/MAVIS.md +1 -1
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/go/rules/agent-team-intake.md +2 -0
- package/presets/mavis/go/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/go/rules/preset-writing-style.md +8 -0
- package/presets/mavis/ios-swift/MAVIS.md +1 -1
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/ios-swift/rules/agent-team-intake.md +2 -0
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/ios-swift/rules/preset-writing-style.md +8 -0
- package/presets/mavis/java/MAVIS.md +1 -1
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/java/rules/agent-team-intake.md +2 -0
- package/presets/mavis/java/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/java/rules/preset-writing-style.md +8 -0
- package/presets/mavis/mcp-ts/MAVIS.md +1 -1
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/mcp-ts/rules/agent-team-intake.md +2 -0
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/mcp-ts/rules/preset-writing-style.md +8 -0
- package/presets/mavis/mol/MAVIS.md +1 -1
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/agents/feature-developer.md +1 -1
- package/presets/mavis/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/mavis/mol/commands/task-evil.md +8 -0
- package/presets/mavis/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/mol/native-skills/task-evil/SKILL.md +8 -0
- package/presets/mavis/mol/rules/agent-team-intake.md +2 -0
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/mol/rules/preset-writing-style.md +8 -0
- package/presets/mavis/next/MAVIS.md +1 -1
- package/presets/mavis/next/REPO_AGENTS.md +2 -0
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/agents/feature-developer.md +1 -1
- package/presets/mavis/next/agents/task-analyst.md +1 -7
- package/presets/mavis/next/agents/task-router.md +1 -1
- package/presets/mavis/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/mavis/next/commands/spec-start.md +3 -4
- package/presets/mavis/next/commands/task-continue.md +9 -8
- package/presets/mavis/next/commands/task-evil.md +8 -0
- package/presets/mavis/next/commands/task.md +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/next/native-skills/spec-start/SKILL.md +3 -4
- package/presets/mavis/next/native-skills/task/SKILL.md +1 -1
- package/presets/mavis/next/native-skills/task-continue/SKILL.md +9 -8
- package/presets/mavis/next/native-skills/task-evil/SKILL.md +8 -0
- package/presets/mavis/next/rules/agent-team-intake.md +2 -0
- package/presets/mavis/next/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/next/rules/preset-writing-style.md +8 -0
- package/presets/mavis/next/team/README.md +1 -1
- package/presets/mavis/nuxt/MAVIS.md +1 -1
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/nuxt/rules/agent-team-intake.md +2 -0
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/nuxt/rules/preset-writing-style.md +8 -0
- package/presets/mavis/php-hexagonal/MAVIS.md +1 -1
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/php-hexagonal/rules/agent-team-intake.md +2 -0
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/php-hexagonal/rules/preset-writing-style.md +8 -0
- package/presets/mavis/php-laravel/MAVIS.md +1 -1
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/php-laravel/rules/agent-team-intake.md +2 -0
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/php-laravel/rules/preset-writing-style.md +8 -0
- package/presets/mavis/svelte/MAVIS.md +1 -1
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/svelte/rules/agent-team-intake.md +2 -0
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/svelte/rules/preset-writing-style.md +8 -0
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/README.md +6 -5
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/android-kotlin/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/android-kotlin/opencode.json +4 -4
- package/presets/opencode/android-kotlin/rules/agent-team-intake.md +2 -0
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/android-kotlin/rules/preset-writing-style.md +8 -0
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/README.md +6 -5
- package/presets/opencode/go/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/go/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/go/opencode.json +4 -4
- package/presets/opencode/go/rules/agent-team-intake.md +2 -0
- package/presets/opencode/go/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/go/rules/preset-writing-style.md +8 -0
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/README.md +6 -5
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/ios-swift/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/ios-swift/opencode.json +4 -4
- package/presets/opencode/ios-swift/rules/agent-team-intake.md +2 -0
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/ios-swift/rules/preset-writing-style.md +8 -0
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/README.md +6 -5
- package/presets/opencode/java/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/java/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/java/opencode.json +4 -4
- package/presets/opencode/java/rules/agent-team-intake.md +2 -0
- package/presets/opencode/java/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/java/rules/preset-writing-style.md +8 -0
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/README.md +6 -5
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/mcp-ts/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/mcp-ts/opencode.json +4 -4
- package/presets/opencode/mcp-ts/rules/agent-team-intake.md +2 -0
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/mcp-ts/rules/preset-writing-style.md +8 -0
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/agents/feature-developer.md +1 -1
- package/presets/opencode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/opencode/mol/commands/task-evil.md +8 -0
- package/presets/opencode/mol/hooks/README.md +6 -5
- package/presets/opencode/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/mol/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/mol/opencode.json +4 -4
- package/presets/opencode/mol/rules/agent-team-intake.md +2 -0
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/mol/rules/preset-writing-style.md +8 -0
- package/presets/opencode/next/REPO_AGENTS.md +2 -0
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/agents/feature-developer.md +1 -1
- package/presets/opencode/next/agents/task-analyst.md +1 -7
- package/presets/opencode/next/agents/task-router.md +1 -1
- package/presets/opencode/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/opencode/next/commands/spec-start.md +3 -4
- package/presets/opencode/next/commands/task-continue.md +9 -8
- package/presets/opencode/next/commands/task-evil.md +8 -0
- package/presets/opencode/next/commands/task.md +1 -1
- package/presets/opencode/next/hooks/README.md +6 -5
- package/presets/opencode/next/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/next/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/next/opencode.json +4 -4
- package/presets/opencode/next/rules/agent-team-intake.md +2 -0
- package/presets/opencode/next/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/next/rules/preset-writing-style.md +8 -0
- package/presets/opencode/next/team/README.md +1 -1
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/hooks/README.md +6 -5
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/nuxt/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/nuxt/opencode.json +4 -4
- package/presets/opencode/nuxt/rules/agent-team-intake.md +2 -0
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/nuxt/rules/preset-writing-style.md +8 -0
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/README.md +6 -5
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/php-hexagonal/opencode.json +4 -4
- package/presets/opencode/php-hexagonal/rules/agent-team-intake.md +2 -0
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/php-hexagonal/rules/preset-writing-style.md +8 -0
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/README.md +6 -5
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/php-laravel/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/php-laravel/opencode.json +4 -4
- package/presets/opencode/php-laravel/rules/agent-team-intake.md +2 -0
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/php-laravel/rules/preset-writing-style.md +8 -0
- package/presets/opencode/plugins/settings-guard/README.md +25 -0
- package/presets/opencode/plugins/settings-guard/index.ts +114 -0
- package/presets/opencode/plugins/settings-guard/package.json +9 -0
- package/presets/opencode/plugins/settings-guard/policy.mjs +85 -0
- package/presets/opencode/plugins/settings-guard/prompt-face.mjs +153 -0
- package/presets/opencode/plugins/task-status/README.md +9 -4
- package/presets/opencode/plugins/task-status/eta.ts +20 -7
- package/presets/opencode/plugins/task-status/index.ts +14 -1
- package/presets/opencode/plugins/task-status/task-view.ts +160 -5
- package/presets/opencode/plugins/task-status/timing.ts +244 -0
- package/presets/opencode/plugins/task-status/types.ts +6 -0
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/hooks/README.md +6 -5
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/svelte/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/svelte/opencode.json +4 -4
- package/presets/opencode/svelte/rules/agent-team-intake.md +2 -0
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/svelte/rules/preset-writing-style.md +8 -0
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/android-kotlin/rules/agent-team-intake.md +2 -0
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/android-kotlin/rules/preset-writing-style.md +8 -0
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/go/rules/agent-team-intake.md +2 -0
- package/presets/zcode/go/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/go/rules/preset-writing-style.md +8 -0
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/ios-swift/rules/agent-team-intake.md +2 -0
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/ios-swift/rules/preset-writing-style.md +8 -0
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/java/rules/agent-team-intake.md +2 -0
- package/presets/zcode/java/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/java/rules/preset-writing-style.md +8 -0
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/mcp-ts/rules/agent-team-intake.md +2 -0
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/mcp-ts/rules/preset-writing-style.md +8 -0
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/agents/feature-developer.md +1 -1
- package/presets/zcode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/zcode/mol/commands/task-evil.md +8 -0
- package/presets/zcode/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/mol/rules/agent-team-intake.md +2 -0
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/mol/rules/preset-writing-style.md +8 -0
- package/presets/zcode/next/REPO_AGENTS.md +2 -0
- package/presets/zcode/next/adapter-map.json +1 -1
- package/presets/zcode/next/agents/feature-developer.md +1 -1
- package/presets/zcode/next/agents/task-analyst.md +1 -7
- package/presets/zcode/next/agents/task-router.md +1 -1
- package/presets/zcode/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/zcode/next/commands/spec-start.md +3 -4
- package/presets/zcode/next/commands/task-continue.md +9 -8
- package/presets/zcode/next/commands/task-evil.md +8 -0
- package/presets/zcode/next/commands/task.md +1 -1
- package/presets/zcode/next/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/next/rules/agent-team-intake.md +2 -0
- package/presets/zcode/next/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/next/rules/preset-writing-style.md +8 -0
- package/presets/zcode/next/team/README.md +1 -1
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/nuxt/rules/agent-team-intake.md +2 -0
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/nuxt/rules/preset-writing-style.md +8 -0
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/php-hexagonal/rules/agent-team-intake.md +2 -0
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/php-hexagonal/rules/preset-writing-style.md +8 -0
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/php-laravel/rules/agent-team-intake.md +2 -0
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/php-laravel/rules/preset-writing-style.md +8 -0
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/svelte/rules/agent-team-intake.md +2 -0
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/svelte/rules/preset-writing-style.md +8 -0
|
@@ -12,7 +12,10 @@ const fs = require('fs');
|
|
|
12
12
|
const path = require('path');
|
|
13
13
|
const crypto = require('crypto');
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// Worktree hooks set AI_RULES_TEAM_ROOT so cwd does not open a second store.
|
|
16
|
+
const TEAM_ROOT = process.env.AI_RULES_TEAM_ROOT
|
|
17
|
+
? path.resolve(process.env.AI_RULES_TEAM_ROOT)
|
|
18
|
+
: path.join(process.cwd(), '.ai.local', 'team');
|
|
16
19
|
|
|
17
20
|
const inputRaw = process.env.INPUT || '';
|
|
18
21
|
let hookInput;
|
|
@@ -35,11 +38,15 @@ if (hookInput.status !== 'completed') {
|
|
|
35
38
|
// Slug resolution, strongest first:
|
|
36
39
|
// 1. TEAM_TASK_SLUG — the orchestrator's explicit binding for this call.
|
|
37
40
|
// 2. the per-session lease `.ai.local/team/.session-leases/<session>.json`,
|
|
38
|
-
// written by an earlier call that carried (1)
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
41
|
+
// written by an earlier call that carried (1), or by the OpenCode
|
|
42
|
+
// task-status plugin when it pinned this tab.
|
|
43
|
+
// 3. active-task.json — a UI projection of the live slugs (rebuilt by
|
|
44
|
+
// `team-db sync`), read only as a fallback for older hosts; when more
|
|
45
|
+
// than one slug is live the resolution is ambiguous and refused below.
|
|
46
|
+
// Only (1) writes the lease from this hook. The OpenCode task-status plugin
|
|
47
|
+
// writes the same file when it pins a tab, and `shell.env` injects the session
|
|
48
|
+
// id so this lookup sees that pin. A pointer fallback never writes a lease:
|
|
49
|
+
// that would let one session inherit another's task.
|
|
43
50
|
const SESSION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
44
51
|
const LEASE_ROOT = path.join(TEAM_ROOT, '.session-leases');
|
|
45
52
|
const LEASE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -103,21 +110,24 @@ if (!slug && sessionId) {
|
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
112
|
if (!slug) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (!fs.existsSync(activePath)) {
|
|
109
|
-
process.stdout.write('{}');
|
|
110
|
-
process.exit(0);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let active;
|
|
113
|
+
let active = null;
|
|
114
114
|
try {
|
|
115
|
-
active = JSON.parse(fs.readFileSync(
|
|
115
|
+
active = JSON.parse(fs.readFileSync(path.join(TEAM_ROOT, 'active-task.json'), 'utf8'));
|
|
116
116
|
} catch {
|
|
117
|
+
active = null;
|
|
118
|
+
}
|
|
119
|
+
// Back-compat reader: the projection shape `{"slugs": [...]}` (rebuilt by
|
|
120
|
+
// `team-db sync`) and the legacy single-slot `{"slug"}` shape are accepted
|
|
121
|
+
// forever. An empty or unreadable projection is identical to a missing
|
|
122
|
+
// file: a `{}` no-op.
|
|
123
|
+
const pointerSlugs = active && Array.isArray(active.slugs)
|
|
124
|
+
? active.slugs
|
|
125
|
+
: (active && typeof active.slug === 'string' && active.slug ? [active.slug] : []);
|
|
126
|
+
if (pointerSlugs.length === 0) {
|
|
117
127
|
process.stdout.write('{}');
|
|
118
128
|
process.exit(0);
|
|
119
129
|
}
|
|
120
|
-
slug =
|
|
130
|
+
slug = pointerSlugs[0];
|
|
121
131
|
slugSource = 'active-task.json';
|
|
122
132
|
}
|
|
123
133
|
// Reject non-kebab / traversal slugs: the runtime writes status.json and
|
|
@@ -127,6 +137,44 @@ if (typeof slug !== 'string' || slug.length > 48 || !SLUG_RE.test(slug)) {
|
|
|
127
137
|
process.stdout.write('{}');
|
|
128
138
|
process.exit(0);
|
|
129
139
|
}
|
|
140
|
+
// Canonical live-slug scan over the task store, never the pointer: a slug is
|
|
141
|
+
// live when `tasks/<name>/status.json` parses and its state is not terminal.
|
|
142
|
+
const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
143
|
+
function liveSlugs() {
|
|
144
|
+
const tasksDir = path.join(TEAM_ROOT, 'tasks');
|
|
145
|
+
let entries;
|
|
146
|
+
try {
|
|
147
|
+
entries = fs.readdirSync(tasksDir, { withFileTypes: true });
|
|
148
|
+
} catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
const live = [];
|
|
152
|
+
for (const entry of entries) {
|
|
153
|
+
if (!entry.isDirectory()) continue;
|
|
154
|
+
try {
|
|
155
|
+
const status = JSON.parse(fs.readFileSync(path.join(tasksDir, entry.name, 'status.json'), 'utf8'));
|
|
156
|
+
if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) live.push(entry.name);
|
|
157
|
+
} catch {}
|
|
158
|
+
}
|
|
159
|
+
return live.sort();
|
|
160
|
+
}
|
|
161
|
+
// Level-3 (pointer) resolution guard: when the slug came from
|
|
162
|
+
// active-task.json and any other live slug exists, the pointer cannot say
|
|
163
|
+
// which task this call belongs to. Refuse loudly — `ok:false` with exit 0,
|
|
164
|
+
// the hook's refusal convention (a non-zero exit would be read as a blocking
|
|
165
|
+
// platform error by Stop-class hook consumers) — so the caller re-runs with
|
|
166
|
+
// `TEAM_TASK_SLUG=<slug>` instead of silently acting on the wrong task.
|
|
167
|
+
// Exactly one live slug keeps today's warning-only behaviour, so older hosts
|
|
168
|
+
// keep working until they pass the env.
|
|
169
|
+
if (slugSource === 'active-task.json') {
|
|
170
|
+
const live = liveSlugs();
|
|
171
|
+
if (live.some((name) => name !== slug)) {
|
|
172
|
+
const shown = live.slice(0, 5).join(', ');
|
|
173
|
+
process.stderr.write(`ERROR: ${slug}: active-task.json is ambiguous — ${live.length} live slugs (${shown}${live.length > 5 ? ', max 5 shown' : ''}); pass TEAM_TASK_SLUG=<slug> on every hook call.\n`);
|
|
174
|
+
process.stdout.write(JSON.stringify({ ok: false, reason: 'active-task-pointer-ambiguous', slug, liveSlugs: live }));
|
|
175
|
+
process.exit(0);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
130
178
|
if (slugSource !== 'TEAM_TASK_SLUG') {
|
|
131
179
|
process.stderr.write(`WARNING: ${slug}: chain hook resolved the slug from ${slugSource}; pass TEAM_TASK_SLUG=<slug> on every hook call so parallel sessions cannot no-op each other.\n`);
|
|
132
180
|
}
|
|
@@ -315,6 +363,86 @@ function attemptStaleMs() {
|
|
|
315
363
|
const value = Number(raw);
|
|
316
364
|
return Number.isFinite(value) && value >= MIN_ATTEMPT_STALE_MS ? value : DEFAULT_ATTEMPT_STALE_MS;
|
|
317
365
|
}
|
|
366
|
+
// Work a single attempt may claim. Wall time beyond it is suspension, a hang, or
|
|
367
|
+
// a stop that arrived days after the agent died, and it is recorded as idle.
|
|
368
|
+
const DEFAULT_ATTEMPT_MAX_MS = 4 * 60 * 60 * 1000;
|
|
369
|
+
const MIN_ATTEMPT_MAX_MS = 10 * 60 * 1000;
|
|
370
|
+
function attemptMaxMs() {
|
|
371
|
+
const raw = process.env.AI_RULES_ATTEMPT_MAX_MS;
|
|
372
|
+
if (typeof raw !== 'string' || raw.trim() === '') return DEFAULT_ATTEMPT_MAX_MS;
|
|
373
|
+
const value = Number(raw);
|
|
374
|
+
return Number.isFinite(value) && value >= MIN_ATTEMPT_MAX_MS ? value : DEFAULT_ATTEMPT_MAX_MS;
|
|
375
|
+
}
|
|
376
|
+
// Intervals appended by the sidebar's suspend detector: the host did not run, so
|
|
377
|
+
// the attempt did not work. Written as JSONL, one { from, to } per line.
|
|
378
|
+
function readSuspendIntervals() {
|
|
379
|
+
const file = path.join(taskDir, '.suspend.jsonl');
|
|
380
|
+
let raw;
|
|
381
|
+
try { raw = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
382
|
+
const intervals = [];
|
|
383
|
+
for (const line of raw.split('\n')) {
|
|
384
|
+
const trimmed = line.trim();
|
|
385
|
+
if (trimmed === '') continue;
|
|
386
|
+
try {
|
|
387
|
+
const row = JSON.parse(trimmed);
|
|
388
|
+
const from = Date.parse(row && row.from);
|
|
389
|
+
const to = Date.parse(row && row.to);
|
|
390
|
+
if (Number.isFinite(from) && Number.isFinite(to) && to > from) intervals.push([from, to]);
|
|
391
|
+
} catch { /* a torn last line is re-read when the file grows */ }
|
|
392
|
+
}
|
|
393
|
+
return intervals;
|
|
394
|
+
}
|
|
395
|
+
function unionOverlapMs(intervals, from, to) {
|
|
396
|
+
if (!Number.isFinite(from) || !Number.isFinite(to) || to <= from) return 0;
|
|
397
|
+
const sorted = intervals
|
|
398
|
+
.filter((pair) => Array.isArray(pair) && Number.isFinite(pair[0]) && Number.isFinite(pair[1]) && pair[1] > pair[0])
|
|
399
|
+
.sort((left, right) => left[0] - right[0]);
|
|
400
|
+
let total = 0;
|
|
401
|
+
let cursor = from;
|
|
402
|
+
for (const [start, end] of sorted) {
|
|
403
|
+
const overlapStart = Math.max(start, from, cursor);
|
|
404
|
+
const overlapEnd = Math.min(end, to);
|
|
405
|
+
if (overlapEnd <= overlapStart) continue;
|
|
406
|
+
total += overlapEnd - overlapStart;
|
|
407
|
+
cursor = overlapEnd;
|
|
408
|
+
}
|
|
409
|
+
return total;
|
|
410
|
+
}
|
|
411
|
+
// Everything the ledger can prove was not work: a gate, an operator pause, a
|
|
412
|
+
// host suspension. Attempt wall time minus this is the attempt's active time.
|
|
413
|
+
function attemptIdleMs(startedAtMs, endedAtMs, events) {
|
|
414
|
+
const intervals = readSuspendIntervals();
|
|
415
|
+
// The sentinel is the control plane: it is engaged before `task_paused` is
|
|
416
|
+
// written, so a stop that notices it must still charge the wait as idle.
|
|
417
|
+
const livePause = readPauseSentinel();
|
|
418
|
+
if (livePause.engaged && livePause.at) {
|
|
419
|
+
intervals.push([Date.parse(livePause.at), endedAtMs]);
|
|
420
|
+
}
|
|
421
|
+
const gates = new Map();
|
|
422
|
+
for (const event of events) {
|
|
423
|
+
if (event && event.type === 'human_gate_started' && event.eventId) gates.set(event.eventId, Date.parse(event.at));
|
|
424
|
+
}
|
|
425
|
+
for (const event of events) {
|
|
426
|
+
if (!event) continue;
|
|
427
|
+
if (event.type === 'human_gate_ended' && event.gateStartedEventId) {
|
|
428
|
+
const start = gates.get(event.gateStartedEventId);
|
|
429
|
+
const end = Date.parse(event.at);
|
|
430
|
+
if (Number.isFinite(start) && Number.isFinite(end)) intervals.push([start, end]);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
let openPause = null;
|
|
434
|
+
for (const event of events) {
|
|
435
|
+
if (!event) continue;
|
|
436
|
+
if (event.type === 'task_paused') openPause = Date.parse(event.at);
|
|
437
|
+
if (event.type === 'task_resumed' && openPause !== null) {
|
|
438
|
+
const end = Date.parse(event.at);
|
|
439
|
+
if (Number.isFinite(end) && end > openPause) intervals.push([openPause, end]);
|
|
440
|
+
openPause = null;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (openPause !== null && Number.isFinite(openPause)) intervals.push([openPause, endedAtMs]);
|
|
444
|
+
return unionOverlapMs(intervals, startedAtMs, endedAtMs);
|
|
445
|
+
}
|
|
318
446
|
function hasTerminalReceipt(attemptId, entry) {
|
|
319
447
|
const manifestPath = path.join(taskDir, 'artifact-manifest.json');
|
|
320
448
|
if (!fs.existsSync(manifestPath)) return false;
|
|
@@ -372,6 +500,9 @@ function reclaimStaleAttempts(scope) {
|
|
|
372
500
|
role: roleFor(entry.agent),
|
|
373
501
|
outcome: 'stale',
|
|
374
502
|
durationMs: ageMs,
|
|
503
|
+
wallMs: ageMs,
|
|
504
|
+
activeMs: Math.min(ageMs, attemptMaxMs()),
|
|
505
|
+
idleMs: Math.max(0, ageMs - Math.min(ageMs, attemptMaxMs())),
|
|
375
506
|
retryAfterFix: status.retryAfterFix || null,
|
|
376
507
|
source: 'hook',
|
|
377
508
|
attributionConfidence: 'high',
|
|
@@ -1220,7 +1351,33 @@ function sanitizeUsage(value) {
|
|
|
1220
1351
|
/**
|
|
1221
1352
|
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1222
1353
|
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1354
|
+
*
|
|
1355
|
+
* Task scoping: with the slug's write-scope step baselines
|
|
1356
|
+
* (`.write-scope/<slug>/*.json`) the evidence hash covers the union of the
|
|
1357
|
+
* baselines' recorded paths only, so another live slug's uncommitted work
|
|
1358
|
+
* cannot stale this task's evidence. Known limit: a file created after baseline
|
|
1359
|
+
* activation outside the claimed path set is invisible to `scopeHash`; the
|
|
1360
|
+
* write-scope audit and `check:task` still attribute such files at gate time
|
|
1361
|
+
* (content-hash delta). The scoped hash is a change detector, not an
|
|
1362
|
+
* attribution tool. `environmentHash` (renamed from `worktreeHash`) keeps the
|
|
1363
|
+
* whole-tree capture as diagnostics only.
|
|
1223
1364
|
*/
|
|
1365
|
+
function writeScopeBaselinePaths(dir) {
|
|
1366
|
+
let entries;
|
|
1367
|
+
try { entries = fs.readdirSync(dir); } catch { return null; }
|
|
1368
|
+
const paths = new Set();
|
|
1369
|
+
for (const entry of entries) {
|
|
1370
|
+
if (!entry.endsWith('.json')) continue;
|
|
1371
|
+
let parsed = null;
|
|
1372
|
+
try { parsed = JSON.parse(fs.readFileSync(path.join(dir, entry), 'utf8')); } catch { parsed = null; }
|
|
1373
|
+
const record = parsed && typeof parsed === 'object' && parsed.paths && typeof parsed.paths === 'object' && !Array.isArray(parsed.paths) ? parsed.paths : null;
|
|
1374
|
+
if (!record) continue;
|
|
1375
|
+
for (const key of Object.keys(record)) {
|
|
1376
|
+
if (typeof key === 'string' && key !== '') paths.add(key.split(path.sep).join('/'));
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
return paths.size > 0 ? [...paths].sort() : null;
|
|
1380
|
+
}
|
|
1224
1381
|
function gitSnapshot() {
|
|
1225
1382
|
const { spawnSync } = require('child_process');
|
|
1226
1383
|
const git = (args) => {
|
|
@@ -1234,11 +1391,30 @@ function gitSnapshot() {
|
|
|
1234
1391
|
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1235
1392
|
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1236
1393
|
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1394
|
+
const baselinePaths = typeof slug === 'string' && slug !== '' && SLUG_RE.test(slug)
|
|
1395
|
+
? writeScopeBaselinePaths(path.join(TEAM_ROOT, '.write-scope', slug))
|
|
1396
|
+
: null;
|
|
1397
|
+
const liveCount = liveSlugs().length;
|
|
1398
|
+
let scopeBasis = 'none';
|
|
1399
|
+
let scopeHash = null;
|
|
1400
|
+
if (baselinePaths !== null) {
|
|
1401
|
+
scopeBasis = 'write-scope';
|
|
1402
|
+
const spec = ['--', ...baselinePaths];
|
|
1403
|
+
const scopedStatus = git(['status', '--porcelain=v1', ...spec]) || '';
|
|
1404
|
+
const scopedDiff = git(['diff', '--binary', 'HEAD', ...spec]) || '';
|
|
1405
|
+
const scopedUntracked = git(['ls-files', '--others', '--exclude-standard', ...spec]) || '';
|
|
1406
|
+
scopeHash = crypto.createHash('sha256').update(`${scopedStatus}\u0000${scopedDiff}\u0000${scopedUntracked}`).digest('hex');
|
|
1407
|
+
} else if (liveCount <= 1) {
|
|
1408
|
+
scopeBasis = 'whole-tree';
|
|
1409
|
+
}
|
|
1237
1410
|
return {
|
|
1238
1411
|
head: head.trim(),
|
|
1239
1412
|
branch: branch === null ? null : branch.trim(),
|
|
1240
1413
|
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1241
|
-
|
|
1414
|
+
environmentHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1415
|
+
scopeBasis,
|
|
1416
|
+
scopePaths: baselinePaths === null ? 0 : baselinePaths.length,
|
|
1417
|
+
scopeHash,
|
|
1242
1418
|
capturedAt: now,
|
|
1243
1419
|
};
|
|
1244
1420
|
}
|
|
@@ -1327,7 +1503,7 @@ function ensureVerificationSnapshot(dir, agent) {
|
|
|
1327
1503
|
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1328
1504
|
fs.renameSync(temporary, file);
|
|
1329
1505
|
});
|
|
1330
|
-
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head,
|
|
1506
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, environmentHash: snapshot.environmentHash, source: 'hook', attributionConfidence: 'high' });
|
|
1331
1507
|
}
|
|
1332
1508
|
|
|
1333
1509
|
function verificationFreshness(dir) {
|
|
@@ -1342,15 +1518,34 @@ function verificationFreshness(dir) {
|
|
|
1342
1518
|
// Judge the report the gate judges: its `tree:` header, not the wider worktree
|
|
1343
1519
|
// hash. A later edit inside the same report generation moved the hash while the
|
|
1344
1520
|
// gate still accepted the report, so the same fresh evidence warned twice.
|
|
1521
|
+
// The head comparison stays global (HEAD is shared across live slugs); the
|
|
1522
|
+
// dirty/hash dimension binds to the task's `scopeHash` when the evidence was
|
|
1523
|
+
// captured on a `write-scope` basis — the header's dirty count is a whole-tree
|
|
1524
|
+
// number and is not comparable to a scoped one, so the scoped hash is the
|
|
1525
|
+
// binding check for that basis, and a scope that can no longer be recomputed
|
|
1526
|
+
// reports `scope-unbound` (loud not-fresh, never a false fresh). Legacy
|
|
1527
|
+
// snapshots (no `scopeBasis`) and `whole-tree` snapshots keep today's
|
|
1528
|
+
// whole-tree comparison, reading the renamed field as
|
|
1529
|
+
// `environmentHash ?? worktreeHash`.
|
|
1345
1530
|
const found = evidenceReportText(dir);
|
|
1346
1531
|
const header = found === null ? null : found.text.match(REPORT_TREE_RE);
|
|
1347
1532
|
const reasons = [];
|
|
1348
1533
|
if (header) {
|
|
1349
1534
|
if (!current.head.startsWith(header[1])) reasons.push('head-changed');
|
|
1350
|
-
if (Number(header[2]) !== current.dirtyFiles) reasons.push('worktree-changed');
|
|
1351
1535
|
} else {
|
|
1352
1536
|
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1353
|
-
|
|
1537
|
+
}
|
|
1538
|
+
const basis = typeof snapshot.scopeBasis === 'string' ? snapshot.scopeBasis : 'legacy';
|
|
1539
|
+
if (basis === 'write-scope') {
|
|
1540
|
+
if (current.scopeBasis !== 'write-scope') reasons.push('scope-unbound');
|
|
1541
|
+
else if (current.scopeHash !== snapshot.scopeHash) reasons.push('worktree-changed');
|
|
1542
|
+
} else if (basis === 'none') {
|
|
1543
|
+
reasons.push('scope-unbound');
|
|
1544
|
+
} else if (header) {
|
|
1545
|
+
if (Number(header[2]) !== current.dirtyFiles) reasons.push('worktree-changed');
|
|
1546
|
+
} else {
|
|
1547
|
+
const recorded = typeof snapshot.environmentHash === 'string' ? snapshot.environmentHash : snapshot.worktreeHash;
|
|
1548
|
+
if (current.environmentHash !== recorded) reasons.push('worktree-changed');
|
|
1354
1549
|
}
|
|
1355
1550
|
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1356
1551
|
}
|
|
@@ -1369,10 +1564,32 @@ function noteVerificationFreshness(dir, agent) {
|
|
|
1369
1564
|
|
|
1370
1565
|
function finishActiveAttempt(forced) {
|
|
1371
1566
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
1372
|
-
const
|
|
1567
|
+
const startedAtMs = Date.parse(resolved.entry.startedAt);
|
|
1568
|
+
const endedAtMs = Date.parse(now);
|
|
1569
|
+
const wallMs = Number.isFinite(startedAtMs) && Number.isFinite(endedAtMs) ? Math.max(0, endedAtMs - startedAtMs) : null;
|
|
1570
|
+
// Suspension, a gate or an operator pause inside the attempt is not work.
|
|
1571
|
+
const nonWorkMs = wallMs === null ? null : attemptIdleMs(startedAtMs, endedAtMs, readMetricsEvents());
|
|
1572
|
+
// `idleMs` is the remainder, not only the proven intervals: wall = active + idle.
|
|
1573
|
+
const activeMs = wallMs === null ? null : Math.min(Math.max(0, wallMs - nonWorkMs), attemptMaxMs());
|
|
1574
|
+
const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
|
|
1373
1575
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
1374
1576
|
const usage = sanitizeUsage(hookInput.usage);
|
|
1375
|
-
appendMetric({
|
|
1577
|
+
appendMetric({
|
|
1578
|
+
type: 'attempt_finished',
|
|
1579
|
+
at: now,
|
|
1580
|
+
attemptId: resolved.attemptId,
|
|
1581
|
+
stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
|
|
1582
|
+
agent: resolved.entry.agent || null,
|
|
1583
|
+
outcome,
|
|
1584
|
+
durationMs: wallMs,
|
|
1585
|
+
wallMs,
|
|
1586
|
+
activeMs,
|
|
1587
|
+
idleMs,
|
|
1588
|
+
retryAfterFix: status.retryAfterFix || null,
|
|
1589
|
+
source: resolved.source || 'hook',
|
|
1590
|
+
attributionConfidence: resolved.confidence,
|
|
1591
|
+
...(usage ? { usage } : {}),
|
|
1592
|
+
});
|
|
1376
1593
|
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
1377
1594
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
1378
1595
|
}
|
|
@@ -1449,10 +1666,38 @@ function completePipeline(statusPatch) {
|
|
|
1449
1666
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|
|
1450
1667
|
process.exit(0);
|
|
1451
1668
|
}
|
|
1452
|
-
function beginHumanGate() {
|
|
1669
|
+
function beginHumanGate() {
|
|
1670
|
+
// A second stop for the same gate must not open a parallel one: the wait
|
|
1671
|
+
// would be counted twice and the pairing lost.
|
|
1672
|
+
if (status.activeHumanGateEventId && status.awaitingHumanGate) return;
|
|
1673
|
+
const eventId = `${status.metricsRunId || slug}:gate:${Date.now()}`;
|
|
1674
|
+
appendMetric({
|
|
1675
|
+
eventId,
|
|
1676
|
+
type: 'human_gate_started',
|
|
1677
|
+
at: now,
|
|
1678
|
+
stepIndex: typeof status.pipelineIndex === 'number' ? status.pipelineIndex : null,
|
|
1679
|
+
agent: status.currentAgent || null,
|
|
1680
|
+
source: 'hook',
|
|
1681
|
+
attributionConfidence: 'high',
|
|
1682
|
+
});
|
|
1683
|
+
status.activeHumanGateEventId = eventId;
|
|
1684
|
+
}
|
|
1453
1685
|
function endHumanGateIfResumed() {
|
|
1454
1686
|
if (!status.activeHumanGateEventId || status.awaitingHumanGate || status.state === 'awaiting_approval') return;
|
|
1455
|
-
|
|
1687
|
+
const events = readMetricsEvents();
|
|
1688
|
+
const started = events.find((event) => event && event.type === 'human_gate_started' && event.eventId === status.activeHumanGateEventId);
|
|
1689
|
+
const startedAt = started ? Date.parse(started.at) : NaN;
|
|
1690
|
+
// The gate ends when work resumed, not when a later stop noticed it.
|
|
1691
|
+
const resumed = Number.isFinite(startedAt)
|
|
1692
|
+
? events.find((event) => event && event.type === 'attempt_started' && Date.parse(event.at) > startedAt)
|
|
1693
|
+
: null;
|
|
1694
|
+
appendMetric({
|
|
1695
|
+
type: 'human_gate_ended',
|
|
1696
|
+
at: resumed ? resumed.at : now,
|
|
1697
|
+
gateStartedEventId: status.activeHumanGateEventId,
|
|
1698
|
+
source: 'hook',
|
|
1699
|
+
attributionConfidence: 'high',
|
|
1700
|
+
});
|
|
1456
1701
|
delete status.activeHumanGateEventId;
|
|
1457
1702
|
}
|
|
1458
1703
|
function completeTaskMetrics() {
|
|
@@ -1817,21 +2062,22 @@ function writeStatus(next) {
|
|
|
1817
2062
|
// attempt is finished before this check runs. An empty or unreadable file still
|
|
1818
2063
|
// counts as engaged (fail safe).
|
|
1819
2064
|
const PAUSE_SENTINELS = [
|
|
1820
|
-
path.join(process.cwd(), '.ai.local', 'STOP'),
|
|
1821
|
-
path.join(process.cwd(), '.ai.local', 'ESTOP'),
|
|
2065
|
+
{ file: path.join(process.cwd(), '.ai.local', 'STOP'), scope: 'repo' },
|
|
2066
|
+
{ file: path.join(process.cwd(), '.ai.local', 'ESTOP'), scope: 'repo-emergency' },
|
|
1822
2067
|
];
|
|
1823
2068
|
function readPauseSentinel() {
|
|
1824
2069
|
const sentinels = [...PAUSE_SENTINELS];
|
|
1825
2070
|
if (typeof slug === 'string' && slug !== '') {
|
|
1826
|
-
sentinels.push(path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug, 'STOP'));
|
|
2071
|
+
sentinels.push({ file: path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug, 'STOP'), scope: 'task' });
|
|
1827
2072
|
}
|
|
1828
|
-
for (const
|
|
2073
|
+
for (const sentinel of sentinels) {
|
|
2074
|
+
const file = sentinel.file;
|
|
1829
2075
|
let stat = null;
|
|
1830
2076
|
try { stat = fs.statSync(file); } catch (error) {
|
|
1831
2077
|
if (error && error.code === 'ENOENT') continue;
|
|
1832
2078
|
// A permission or I/O error is not proof of absence: fail safe and say so.
|
|
1833
2079
|
process.stderr.write(`WARNING: ${slug}: cannot stat pause sentinel ${path.relative(process.cwd(), file).split(path.sep).join('/')} (${error && error.message ? error.message : String(error)}); treating it as engaged.\n`);
|
|
1834
|
-
return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), reason: 'sentinel stat failed' };
|
|
2080
|
+
return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), scope: sentinel.scope, at: null, reason: 'sentinel stat failed' };
|
|
1835
2081
|
}
|
|
1836
2082
|
if (!stat || !stat.isFile()) continue;
|
|
1837
2083
|
let reason = '';
|
|
@@ -1849,19 +2095,52 @@ function readPauseSentinel() {
|
|
|
1849
2095
|
return {
|
|
1850
2096
|
engaged: true,
|
|
1851
2097
|
file: path.relative(process.cwd(), file).split(path.sep).join('/'),
|
|
2098
|
+
scope: sentinel.scope,
|
|
2099
|
+
// The pause started when the sentinel was written, not when a hook noticed it.
|
|
2100
|
+
at: new Date(stat.mtimeMs).toISOString(),
|
|
1852
2101
|
reason: reason.replace(/\s+/g, ' ').slice(0, 160),
|
|
1853
2102
|
};
|
|
1854
2103
|
}
|
|
1855
|
-
return { engaged: false, file: null, reason: '' };
|
|
2104
|
+
return { engaged: false, file: null, scope: null, at: null, reason: '' };
|
|
1856
2105
|
}
|
|
1857
2106
|
function pausedNotice(pause) {
|
|
1858
2107
|
const where = pause && pause.file ? pause.file : '.ai.local/STOP';
|
|
1859
2108
|
const because = pause && pause.reason ? ` (${pause.reason})` : '';
|
|
1860
2109
|
return `[chain-team-phases] ${slug}: paused — operator sentinel ${where} is engaged${because}. No step advanced and no handoff was emitted. Remove the sentinel and run /task-continue ${slug}.`;
|
|
1861
2110
|
}
|
|
2111
|
+
// A pause is a duration in the ledger, not only a file. One `task_paused` per
|
|
2112
|
+
// engagement and one `task_resumed` when the sentinel is gone.
|
|
2113
|
+
function recordPauseEngaged(pause) {
|
|
2114
|
+
if (openPauseIndex(readMetricsEvents()) !== -1) return;
|
|
2115
|
+
appendMetric({
|
|
2116
|
+
type: 'task_paused',
|
|
2117
|
+
at: pause.at || now,
|
|
2118
|
+
scope: pause.scope || 'repo',
|
|
2119
|
+
file: pause.file || null,
|
|
2120
|
+
reason: pause.reason || null,
|
|
2121
|
+
source: 'hook',
|
|
2122
|
+
attributionConfidence: 'high',
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
function recordPauseResumed() {
|
|
2126
|
+
const events = readMetricsEvents();
|
|
2127
|
+
const index = openPauseIndex(events);
|
|
2128
|
+
if (index === -1) return;
|
|
2129
|
+
appendMetric({
|
|
2130
|
+
type: 'task_resumed',
|
|
2131
|
+
at: now,
|
|
2132
|
+
pausedSince: events[index].at || null,
|
|
2133
|
+
source: 'hook',
|
|
2134
|
+
attributionConfidence: 'high',
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
1862
2137
|
function pauseBlocksAdvance() {
|
|
1863
2138
|
const pause = readPauseSentinel();
|
|
1864
|
-
if (!pause.engaged)
|
|
2139
|
+
if (!pause.engaged) {
|
|
2140
|
+
recordPauseResumed();
|
|
2141
|
+
return null;
|
|
2142
|
+
}
|
|
2143
|
+
recordPauseEngaged(pause);
|
|
1865
2144
|
writeStatus({ state: 'paused', phase: 'paused' });
|
|
1866
2145
|
out(pausedNotice(pause));
|
|
1867
2146
|
return pause;
|
|
@@ -2296,6 +2575,96 @@ function countDebugImplementationRetries() {
|
|
|
2296
2575
|
return 0;
|
|
2297
2576
|
}
|
|
2298
2577
|
}
|
|
2578
|
+
function replanDecisionCount() {
|
|
2579
|
+
try {
|
|
2580
|
+
const text = fs.readFileSync(path.join(taskDir, '.memlog.md'), 'utf8');
|
|
2581
|
+
const matches = text.match(/replan rev\s+\d+\s*(?:→|->)\s*\d+/g);
|
|
2582
|
+
return matches ? matches.length : 0;
|
|
2583
|
+
} catch {
|
|
2584
|
+
return 0;
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
function changesRequestedCount(agent) {
|
|
2588
|
+
if (typeof agent !== 'string' || agent === '') return 0;
|
|
2589
|
+
try {
|
|
2590
|
+
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
2591
|
+
const events = Array.isArray(metrics.events) ? metrics.events : [];
|
|
2592
|
+
const needle = `:${agent}:`;
|
|
2593
|
+
return events.filter((event) => event && event.type === 'attempt_finished' && event.outcome === 'changes_requested' && typeof event.attemptId === 'string' && event.attemptId.includes(needle)).length;
|
|
2594
|
+
} catch {
|
|
2595
|
+
return 0;
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
function holdDesignEscalation(agent, mode, reviewerStepIndex) {
|
|
2599
|
+
if (changesRequestedCount(agent) < 2) return false;
|
|
2600
|
+
beginHumanGate();
|
|
2601
|
+
writeStatus({
|
|
2602
|
+
awaitingHumanGate: true,
|
|
2603
|
+
state: 'awaiting_approval',
|
|
2604
|
+
currentAgent: agent,
|
|
2605
|
+
phase: 'human_gate',
|
|
2606
|
+
designEscalation: {
|
|
2607
|
+
agent,
|
|
2608
|
+
mode,
|
|
2609
|
+
reviewerStepIndex: Number.isInteger(reviewerStepIndex) ? reviewerStepIndex : null,
|
|
2610
|
+
priorReplanCount: replanDecisionCount(),
|
|
2611
|
+
},
|
|
2612
|
+
parallelCompleted: [],
|
|
2613
|
+
parallelOutcomes: {},
|
|
2614
|
+
waveSteps: [],
|
|
2615
|
+
waveId: null,
|
|
2616
|
+
retryAfterFix: null,
|
|
2617
|
+
retryAfterFixStepIndex: null,
|
|
2618
|
+
});
|
|
2619
|
+
out(`${agent} requested changes for slug "${slug}" a second time in this task. Append a \`.memlog.md\` line \`decision: replan rev N → N+1\` that changes the model, then resume via /task-continue. The next attempt is not dispatched until that line exists.`);
|
|
2620
|
+
process.exit(0);
|
|
2621
|
+
}
|
|
2622
|
+
function resumeDesignEscalation(escalation, resumeSteps) {
|
|
2623
|
+
steps = resumeSteps;
|
|
2624
|
+
const reviewer = escalation.agent;
|
|
2625
|
+
const reviewerStepIndex = Number.isInteger(escalation.reviewerStepIndex)
|
|
2626
|
+
? escalation.reviewerStepIndex
|
|
2627
|
+
: (typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0);
|
|
2628
|
+
status.pipelineIndex = reviewerStepIndex;
|
|
2629
|
+
delete status.designEscalation;
|
|
2630
|
+
if (escalation.mode === 'graph') {
|
|
2631
|
+
const producerIndex = resolveProducerStepIndex('feature-developer', reviewerStepIndex);
|
|
2632
|
+
if (producerIndex < 0) {
|
|
2633
|
+
out(`${reviewer} requested changes for slug "${slug}" but no graph ancestor authors fixes. Read the review artifact. Resume only via /task-continue.`);
|
|
2634
|
+
process.exit(0);
|
|
2635
|
+
}
|
|
2636
|
+
appendMetric({ type: 'retry_scheduled', at: now, attemptId: status.lastCompletedAttempt?.attemptId || null, nextAgent: 'feature-developer', retryAfterFix: reviewer, source: 'hook', attributionConfidence: 'high' });
|
|
2637
|
+
invalidateFrom(producerIndex, reviewerStepIndex);
|
|
2638
|
+
writeStatus({ state: 'in_progress', phase: 'executing', awaitingHumanGate: false, waveSteps: [], waveId: null, retryAfterFix: null, retryAfterFixStepIndex: null, parallelCompleted: [], parallelOutcomes: {} });
|
|
2639
|
+
if (!dispatchReadyWave(`Design escalation for ${reviewer} accepted; re-dispatching unsatisfied steps.`)) out(noProgressNotice());
|
|
2640
|
+
process.exit(0);
|
|
2641
|
+
}
|
|
2642
|
+
let verifierStepIndex = -1;
|
|
2643
|
+
for (let index = reviewerStepIndex - 1; index >= 0; index -= 1) {
|
|
2644
|
+
if (getStepAgents(steps[index]).includes('build-verifier')) {
|
|
2645
|
+
verifierStepIndex = index;
|
|
2646
|
+
break;
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
const retryGate = verifierStepIndex >= 0 ? 'build-verifier' : reviewer;
|
|
2650
|
+
const retryAfterFixStepIndex = verifierStepIndex >= 0 ? verifierStepIndex : reviewerStepIndex;
|
|
2651
|
+
const developerIndex = scheduleRetry('feature-developer', reviewer, status.lastCompletedAttempt);
|
|
2652
|
+
if (developerIndex < 0) {
|
|
2653
|
+
out(`${reviewer} requested changes for slug "${slug}" but this pipeline has no feature-developer step. Read the review artifact. Resume only via /task-continue.`);
|
|
2654
|
+
process.exit(0);
|
|
2655
|
+
}
|
|
2656
|
+
writeStatus({
|
|
2657
|
+
pipelineIndex: developerIndex,
|
|
2658
|
+
currentAgent: 'feature-developer',
|
|
2659
|
+
state: 'in_progress',
|
|
2660
|
+
phase: 'executing',
|
|
2661
|
+
awaitingHumanGate: false,
|
|
2662
|
+
retryAfterFix: retryGate,
|
|
2663
|
+
retryAfterFixStepIndex,
|
|
2664
|
+
});
|
|
2665
|
+
out(handoffForAgent('feature-developer', steps[developerIndex]?.scope, steps[developerIndex]) + ` After fixes, re-run ${retryGate}.`);
|
|
2666
|
+
process.exit(0);
|
|
2667
|
+
}
|
|
2299
2668
|
function featureDeveloperAlreadyStarted() {
|
|
2300
2669
|
try {
|
|
2301
2670
|
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
@@ -2728,6 +3097,19 @@ if (hookInput.action === 'bootstrap') {
|
|
|
2728
3097
|
function readMetricsLedger() {
|
|
2729
3098
|
try { return JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch { return null; }
|
|
2730
3099
|
}
|
|
3100
|
+
function readMetricsEvents() {
|
|
3101
|
+
const ledger = readMetricsLedger();
|
|
3102
|
+
return ledger && Array.isArray(ledger.events) ? ledger.events : [];
|
|
3103
|
+
}
|
|
3104
|
+
/** Index of the `task_paused` that no `task_resumed` closed, or -1. */
|
|
3105
|
+
function openPauseIndex(events) {
|
|
3106
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
3107
|
+
const type = events[index] && events[index].type;
|
|
3108
|
+
if (type === 'task_resumed') return -1;
|
|
3109
|
+
if (type === 'task_paused') return index;
|
|
3110
|
+
}
|
|
3111
|
+
return -1;
|
|
3112
|
+
}
|
|
2731
3113
|
|
|
2732
3114
|
if (hookInput.action === 'out_of_band_start') {
|
|
2733
3115
|
if (pauseBlocksAdvance()) process.exit(0);
|
|
@@ -2794,6 +3176,11 @@ if (hookInput.action === 'out_of_band_end') {
|
|
|
2794
3176
|
|
|
2795
3177
|
if (hookInput.action === 'end_human_gate') {
|
|
2796
3178
|
if (pauseBlocksAdvance()) process.exit(0);
|
|
3179
|
+
const designEscalation = status.designEscalation && typeof status.designEscalation === 'object' ? status.designEscalation : null;
|
|
3180
|
+
if (designEscalation && replanDecisionCount() <= (Number(designEscalation.priorReplanCount) || 0)) {
|
|
3181
|
+
out(`Design escalation for slug "${slug}" is still open. Append a \`.memlog.md\` line \`decision: replan rev N → N+1\` that changes the model, then resume via /task-continue.`);
|
|
3182
|
+
process.exit(0);
|
|
3183
|
+
}
|
|
2797
3184
|
// Only advance when a gate was actually open. A duplicate or retried
|
|
2798
3185
|
// end_human_gate must be a no-op, not a silent pipeline skip.
|
|
2799
3186
|
const gateWasOpen = Boolean(status.activeHumanGateEventId) || status.awaitingHumanGate === true;
|
|
@@ -2825,6 +3212,12 @@ if (hookInput.action === 'end_human_gate') {
|
|
|
2825
3212
|
});
|
|
2826
3213
|
delete status.activeHumanGateEventId;
|
|
2827
3214
|
}
|
|
3215
|
+
if (designEscalation && hookInput.activateNext && fs.existsSync(pipelinePath)) {
|
|
3216
|
+
let designPipeline = null;
|
|
3217
|
+
try { designPipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8')); } catch {}
|
|
3218
|
+
const designSteps = designPipeline && Array.isArray(designPipeline.steps) ? designPipeline.steps : [];
|
|
3219
|
+
resumeDesignEscalation(designEscalation, designSteps);
|
|
3220
|
+
}
|
|
2828
3221
|
if (gateWasOpen && hookInput.activateNext && fs.existsSync(pipelinePath)) {
|
|
2829
3222
|
let resumePipeline = null;
|
|
2830
3223
|
try { resumePipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8')); } catch {}
|
|
@@ -2964,10 +3357,12 @@ if (status.state === 'awaiting_artifact_receipt') {
|
|
|
2964
3357
|
const pause = readPauseSentinel();
|
|
2965
3358
|
if (pause.engaged) {
|
|
2966
3359
|
if (artifactStallMessage) process.stderr.write(artifactStallMessage + '\n');
|
|
3360
|
+
recordPauseEngaged(pause);
|
|
2967
3361
|
writeStatus({ state: 'paused', phase: 'paused' });
|
|
2968
3362
|
out(pausedNotice(pause));
|
|
2969
3363
|
process.exit(0);
|
|
2970
3364
|
}
|
|
3365
|
+
recordPauseResumed();
|
|
2971
3366
|
writeStatus({});
|
|
2972
3367
|
emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
|
|
2973
3368
|
process.exit(0);
|
|
@@ -3191,6 +3586,7 @@ if (waveIndexes) {
|
|
|
3191
3586
|
out(`${retryReviewer} requested changes for slug "${slug}" but no graph ancestor authors fixes. Read the review artifact. Resume only via /task-continue.`);
|
|
3192
3587
|
process.exit(0);
|
|
3193
3588
|
}
|
|
3589
|
+
holdDesignEscalation(retryReviewer, 'graph', reviewerStepIndex);
|
|
3194
3590
|
const graphPredecessor = outcomes[retryReviewer]
|
|
3195
3591
|
? { attemptId: outcomes[retryReviewer].attemptId, confidence: outcomes[retryReviewer].confidence }
|
|
3196
3592
|
: finishedAttempt;
|
|
@@ -3203,6 +3599,7 @@ if (waveIndexes) {
|
|
|
3203
3599
|
if (!dispatchReadyWave(`Step ${reviewerStepIndex} (${retryReviewer}) requested changes; re-dispatching unsatisfied steps.`)) out(noProgressNotice());
|
|
3204
3600
|
process.exit(0);
|
|
3205
3601
|
}
|
|
3602
|
+
holdDesignEscalation(retryReviewer, 'linear', idx);
|
|
3206
3603
|
const retryAfterFixStepIndex = idx;
|
|
3207
3604
|
const predecessor = outcomes[retryReviewer]
|
|
3208
3605
|
? {
|
|
@@ -3302,6 +3699,7 @@ if (status.state === 'changes_requested') {
|
|
|
3302
3699
|
process.exit(0);
|
|
3303
3700
|
}
|
|
3304
3701
|
const reviewerStepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
|
|
3702
|
+
holdDesignEscalation(reviewer, 'linear', reviewerStepIndex);
|
|
3305
3703
|
let verifierStepIndex = -1;
|
|
3306
3704
|
for (let index = reviewerStepIndex - 1; index >= 0; index -= 1) {
|
|
3307
3705
|
if (getStepAgents(steps[index]).includes('build-verifier')) {
|
|
@@ -3435,26 +3833,21 @@ const fs = require('fs');
|
|
|
3435
3833
|
const path = require('path');
|
|
3436
3834
|
const { spawnSync } = require('child_process');
|
|
3437
3835
|
|
|
3836
|
+
// Slug binding for the seams below is inside the projection markers. The
|
|
3837
|
+
// dualwrite harness executes that region alone, so the resolver has to live
|
|
3838
|
+
// there or a fresh store is never created.
|
|
3839
|
+
|
|
3438
3840
|
// Dev-server cleanup: terminal task state only. `processes.mjs` proves
|
|
3439
3841
|
// ownership from `.ai.local/.processes/leases/<name>.json` before any signal,
|
|
3440
3842
|
// so a foreign process is never touched. A refusal or timeout is a warning,
|
|
3441
|
-
// never a hook failure.
|
|
3843
|
+
// never a hook failure. The slug is the env binding only — no pointer
|
|
3844
|
+
// fallback: cleanup matters only on terminal state, and the main hook always
|
|
3845
|
+
// knows the slug it resolved.
|
|
3442
3846
|
function stopOwnedDevServers() {
|
|
3443
3847
|
const processes = path.join(process.cwd(), '.ai.local', 'scripts', 'processes.mjs');
|
|
3444
3848
|
if (!fs.existsSync(processes)) return;
|
|
3445
|
-
const
|
|
3446
|
-
|
|
3447
|
-
if (!slug) {
|
|
3448
|
-
try {
|
|
3449
|
-
const active = JSON.parse(
|
|
3450
|
-
fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'),
|
|
3451
|
-
);
|
|
3452
|
-
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
3453
|
-
} catch {
|
|
3454
|
-
return;
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3457
|
-
if (slug.length === 0 || slug.length > 48 || !SLUG_RE.test(slug)) return;
|
|
3849
|
+
const slug = typeof process.env.TEAM_TASK_SLUG === 'string' ? process.env.TEAM_TASK_SLUG : '';
|
|
3850
|
+
if (slug.length === 0 || slug.length > 48 || !POSTFLIGHT_SLUG_RE.test(slug)) return;
|
|
3458
3851
|
let state = '';
|
|
3459
3852
|
try {
|
|
3460
3853
|
const status = JSON.parse(
|
|
@@ -3682,6 +4075,95 @@ if (!input || input.status !== 'completed') {
|
|
|
3682
4075
|
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
3683
4076
|
// all 40 rendered bodies and needs no per-stack fragment.
|
|
3684
4077
|
// <<<team-db-projection>>>
|
|
4078
|
+
// Postflight slug binding, shared by the seams below: the env slug first,
|
|
4079
|
+
// then the per-session lease (the same file the main hook and the OpenCode
|
|
4080
|
+
// task-status plugin write), and the active-task.json projection only as a
|
|
4081
|
+
// last resort. Containment comes from validating every derivation point with
|
|
4082
|
+
// the slug grammar (the same pattern as the hook's SLUG_RE), so `tasks/<slug>`
|
|
4083
|
+
// cannot escape the tree on any postflight path. This region is extracted and
|
|
4084
|
+
// executed alone by the dualwrite harness, so the resolver stays inside the
|
|
4085
|
+
// markers.
|
|
4086
|
+
const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
4087
|
+
const POSTFLIGHT_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4088
|
+
function postflightLiveSlugs() {
|
|
4089
|
+
const tasksDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks');
|
|
4090
|
+
let entries;
|
|
4091
|
+
try {
|
|
4092
|
+
entries = fs.readdirSync(tasksDir, { withFileTypes: true });
|
|
4093
|
+
} catch (error) {
|
|
4094
|
+
return [];
|
|
4095
|
+
}
|
|
4096
|
+
const live = [];
|
|
4097
|
+
for (const entry of entries) {
|
|
4098
|
+
if (!entry.isDirectory()) continue;
|
|
4099
|
+
try {
|
|
4100
|
+
const status = JSON.parse(fs.readFileSync(path.join(tasksDir, entry.name, 'status.json'), 'utf8'));
|
|
4101
|
+
if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) live.push(entry.name);
|
|
4102
|
+
} catch (error) {
|
|
4103
|
+
/* an unreadable status is not a live slug */
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
return live.sort();
|
|
4107
|
+
}
|
|
4108
|
+
function postflightPointerSlug() {
|
|
4109
|
+
// Last-resort read of the UI projection; both the projection shape
|
|
4110
|
+
// `{"slugs": [...]}` and the legacy single-slot `{"slug"}` are accepted
|
|
4111
|
+
// forever. A multi-slug projection resolves to its first entry; the
|
|
4112
|
+
// live-scan guard in postflightResolveSlug decides whether that
|
|
4113
|
+
// resolution is safe to act on.
|
|
4114
|
+
try {
|
|
4115
|
+
const active = JSON.parse(
|
|
4116
|
+
fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'),
|
|
4117
|
+
);
|
|
4118
|
+
const slugs = Array.isArray(active.slugs)
|
|
4119
|
+
? active.slugs
|
|
4120
|
+
: (typeof active.slug === 'string' && active.slug ? [active.slug] : []);
|
|
4121
|
+
const candidate = typeof slugs[0] === 'string' ? slugs[0] : '';
|
|
4122
|
+
if (candidate.length > 48 || !POSTFLIGHT_SLUG_RE.test(candidate)) return '';
|
|
4123
|
+
return candidate;
|
|
4124
|
+
} catch (error) {
|
|
4125
|
+
return '';
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
function postflightSessionId() {
|
|
4129
|
+
const raw = process.env.OPENCODE_SESSION_ID || process.env.AI_RULES_SESSION_ID || '';
|
|
4130
|
+
return /^[A-Za-z0-9_-]{1,128}$/.test(raw) ? raw : '';
|
|
4131
|
+
}
|
|
4132
|
+
function postflightLeaseSlug() {
|
|
4133
|
+
// Same file and TTL as the main hook. A pointer fallback must not win while
|
|
4134
|
+
// this session already has a pin.
|
|
4135
|
+
const id = postflightSessionId();
|
|
4136
|
+
if (!id) return '';
|
|
4137
|
+
try {
|
|
4138
|
+
const file = path.join(process.cwd(), '.ai.local', 'team', '.session-leases', `${id}.json`);
|
|
4139
|
+
if (Date.now() - fs.statSync(file).mtimeMs > 7 * 24 * 60 * 60 * 1000) return '';
|
|
4140
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
4141
|
+
const slug = parsed && typeof parsed.slug === 'string' ? parsed.slug : '';
|
|
4142
|
+
if (slug.length > 48 || !POSTFLIGHT_SLUG_RE.test(slug)) return '';
|
|
4143
|
+
return slug;
|
|
4144
|
+
} catch (error) {
|
|
4145
|
+
return '';
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
function postflightResolveSlug() {
|
|
4149
|
+
// An env slug present but invalid is a stop, not a fallback: the projection
|
|
4150
|
+
// must never route around a bad explicit binding.
|
|
4151
|
+
const envSlug = typeof process.env.TEAM_TASK_SLUG === 'string' ? process.env.TEAM_TASK_SLUG : '';
|
|
4152
|
+
if (envSlug !== '') {
|
|
4153
|
+
if (envSlug.length <= 48 && POSTFLIGHT_SLUG_RE.test(envSlug)) return { slug: envSlug };
|
|
4154
|
+
return { slug: '' };
|
|
4155
|
+
}
|
|
4156
|
+
const leaseSlug = postflightLeaseSlug();
|
|
4157
|
+
if (leaseSlug) return { slug: leaseSlug };
|
|
4158
|
+
const pointerSlug = postflightPointerSlug();
|
|
4159
|
+
if (!pointerSlug) return { slug: '' };
|
|
4160
|
+
const live = postflightLiveSlugs();
|
|
4161
|
+
for (let index = 0; index < live.length; index += 1) {
|
|
4162
|
+
if (live[index] !== pointerSlug) return { slug: '', pointerLiveSlugs: live.length };
|
|
4163
|
+
}
|
|
4164
|
+
return { slug: pointerSlug };
|
|
4165
|
+
}
|
|
4166
|
+
|
|
3685
4167
|
function teamDbTruthy(value) {
|
|
3686
4168
|
if (typeof value !== 'string') return false;
|
|
3687
4169
|
const normalized = value.trim().toLowerCase();
|
|
@@ -3738,17 +4220,17 @@ function teamDbProject() {
|
|
|
3738
4220
|
try {
|
|
3739
4221
|
const env = process.env;
|
|
3740
4222
|
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
} catch (error) {
|
|
4223
|
+
const resolved = postflightResolveSlug();
|
|
4224
|
+
if (resolved.pointerLiveSlugs) {
|
|
4225
|
+
// A pointer-resolved projection under other live slugs cannot say
|
|
4226
|
+
// which task this stop belongs to. Skipping is safe: the projection
|
|
4227
|
+
// converges on the next `team-db sync`, and the files stay
|
|
4228
|
+
// authoritative.
|
|
4229
|
+
process.stderr.write(`WARNING: pointer-resolved projection skipped; ${resolved.pointerLiveSlugs} live slugs\n`);
|
|
3749
4230
|
return;
|
|
3750
4231
|
}
|
|
3751
|
-
|
|
4232
|
+
const slug = resolved.slug;
|
|
4233
|
+
if (!slug) return;
|
|
3752
4234
|
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
3753
4235
|
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
3754
4236
|
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
@@ -3894,13 +4376,11 @@ teamDbTrackerDrain();
|
|
|
3894
4376
|
let pipeline = null;
|
|
3895
4377
|
try {
|
|
3896
4378
|
const teamRoot = path.join(process.cwd(), '.ai.local', 'team');
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
//
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
const POSTFLIGHT_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3903
|
-
if (pipelineSlug.length <= 48 && POSTFLIGHT_SLUG_RE.test(pipelineSlug)) {
|
|
4379
|
+
// Same binding as the seams above: env slug first, projection last resort.
|
|
4380
|
+
// A pointer resolution refused by the live-scan guard is a silent policy
|
|
4381
|
+
// skip here — the ratchet is already silent-by-design for light/spike.
|
|
4382
|
+
const pipelineSlug = postflightResolveSlug().slug;
|
|
4383
|
+
if (pipelineSlug) {
|
|
3904
4384
|
pipeline = JSON.parse(fs.readFileSync(path.join(teamRoot, 'tasks', pipelineSlug, 'pipeline.json'), 'utf8'));
|
|
3905
4385
|
}
|
|
3906
4386
|
} catch {
|