@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
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"permission": {
|
|
11
11
|
"bash": {
|
|
12
12
|
"*": "allow",
|
|
13
|
-
"git commit": "
|
|
14
|
-
"git commit *": "
|
|
15
|
-
"git push": "
|
|
16
|
-
"git push *": "
|
|
13
|
+
"git commit": "ask",
|
|
14
|
+
"git commit *": "ask",
|
|
15
|
+
"git push": "ask",
|
|
16
|
+
"git push *": "ask",
|
|
17
17
|
"pkill *": "ask",
|
|
18
18
|
"killall *": "ask",
|
|
19
19
|
"xargs kill*": "ask",
|
|
@@ -12,6 +12,8 @@ When the user message looks like a **work request** (implement, add, fix, refact
|
|
|
12
12
|
6. **Reuse the dialogue language already resolved on this turn** (always-on `ai-local-overlay` / **language-policy**). A question and a message without a slash command still resolve before you speak. When this request writes `prompt.md`, persist that tag once in the header (`language: <BCP-47>`) + a `.memlog.md` `event:` line. Development, reasoning, and artifacts stay English. The setting wins over a mid-task prompt switch (surface it once, never ask). See **language-policy**.
|
|
13
13
|
7. **Project the intake write.** After `prompt.md` is written for an inline (non-`/task`) work request, run `node .ai.local/scripts/team-db.mjs sync --slug <slug> --deadline-ms 4500` once, so the new task row and its prompt reach the database. A projection failure is reported to the user, never blocks the request; the next full sync remains the convergence path. Do not run a full sync from intake.
|
|
14
14
|
|
|
15
|
+
On Cursor, Mavis, OpenCode and ZCode — the hosts without a verified prompt hook — run a request that is not already `/task` or `/task-continue` as `/task` when `node .ai.local/scripts/settings.mjs get AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS` prints `true` and the live-slug count (every `.ai.local/team/tasks/*/status.json` whose `state` is not one of `completed`, `blocked`, `changes_requested`, `validation_failed`) is below the `node .ai.local/scripts/settings.mjs get AI_RULES_MAX_PARALLEL_TASKS` cap (`4` by default; `0` = unlimited). A prompt that names an existing slug or is a resume intent (`continue` / `resume` / `продолжай` family, `.ai.local/rules/task-resume.md`) routes to `/task-continue <slug>` regardless of the cap. <!-- i18n-keep: E4 -->
|
|
16
|
+
|
|
15
17
|
Exceptions: user explicitly says “no pipeline”, “just do it”, or continues an active slug.
|
|
16
18
|
|
|
17
19
|
## Stack notes
|
|
@@ -243,7 +243,7 @@ No `subagentStop` event exists on this host: after each producer receipt the age
|
|
|
243
243
|
3. One role per Task call — **except** parallel steps: multiple Task calls in one message.
|
|
244
244
|
4. **Never** skip `humanGates` without `/task-continue` or explicit user approval.
|
|
245
245
|
5. Persist handoffs to disk (`brief.md`, `decomposition.md`, `debug-report.md`, `validation-report.md`, `architecture.md`, `migration-plan.md`, `ci-report.md`, `a11y-review.md`, `perf-report.md`, `security-review.md`, `api-contract-review.md`, `unit-test-plan.md`, `documentation.md`, `review.md`, `mockup-review.md`, `ux-design.md`) and update the producer-owned terminal receipt in `artifact-manifest.json`.
|
|
246
|
-
6. On `changes_requested` from reviewers: hook sets `retryAfterFix` → developer → `build-verifier` (delta) → same reviewer when the fix touches code/tests; a docs/artifacts-only fix returns to the same reviewer without a code gate. Exception: embedded `mockup-reviewer` FAIL (`changes_requested` while the completed/current agent is `mockup-reviewer`) → `awaiting_approval` / `/task-continue` only — do **not** `retryAfterFix` to developer. A `mockup-reviewer` verdict `mockup-change-requested` (a defect whose fix belongs in the design source, not the implementation) routes the same way — `awaiting_approval`, no developer retry.
|
|
246
|
+
6. On `changes_requested` from reviewers: the first time that agent returns it, the hook sets `retryAfterFix` → developer → `build-verifier` (delta) → same reviewer when the fix touches code/tests; a docs/artifacts-only fix returns to the same reviewer without a code gate. The second `changes_requested` from the same agent is a human gate (`awaitingHumanGate`, `designEscalation`): do not dispatch the developer. Append `decision: replan rev N → N+1` to `.memlog.md` (the decision changes the model), then `/task-continue`, which the hook accepts only when that line is new. Exception: embedded `mockup-reviewer` FAIL (`changes_requested` while the completed/current agent is `mockup-reviewer`) → `awaiting_approval` / `/task-continue` only — do **not** `retryAfterFix` to developer. A `mockup-reviewer` verdict `mockup-change-requested` (a defect whose fix belongs in the design source, not the implementation) routes the same way — `awaiting_approval`, no developer retry.
|
|
247
247
|
7. On `validation_failed` from `build-verifier`: hook sets `retryAfterFix: build-verifier` → developer → build-verifier (delta).
|
|
248
248
|
8. When all steps complete, suggest `/technical-retro <slug>`.
|
|
249
249
|
9. If `autoChain: false` in pipeline, do not rely on hook — manual step only.
|
|
@@ -287,7 +287,7 @@ node .ai.local/scripts/record-usage.mjs --task <slug> --attempt <attemptId> --in
|
|
|
287
287
|
|
|
288
288
|
The chain hook also forwards a `usage` object from its input into the `attempt_finished` event. Never estimate or invent token counts; a missing usage record stays missing.
|
|
289
289
|
|
|
290
|
-
After each agent completes, verify its terminal manifest receipt, then let the orchestration runtime/hook reconcile `status.json` (`completed`, a blocking outcome, or `awaiting_approval`) from that receipt.
|
|
290
|
+
After each agent completes, verify its terminal manifest receipt, then let the orchestration runtime/hook reconcile `status.json` (`completed`, a blocking outcome, or `awaiting_approval`) from that receipt. **MUST: pass `TEAM_TASK_SLUG=<slug>` on every hook call** — `TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh` (or the host's hook path). With more than one live slug, an omitted env is a hook refusal (`active-task-pointer-ambiguous`, `ok:false`), never a silent reroute: re-run with the env set. The OpenCode task-status plugin pins each tab in `.ai.local/team/.session-leases/<session>.json` and injects `AI_RULES_SESSION_ID` on `shell.env`, so a later hook call in that tab resolves through the lease when `TEAM_TASK_SLUG` is omitted. `active-task.json` is the live-slug list, not a tab binding. Do not ask the agent to mutate shared lifecycle fields, and do not invoke the next specialist until the hook has written the handoff / updated `status.json`.
|
|
291
291
|
|
|
292
292
|
## Legacy mode
|
|
293
293
|
|
|
@@ -25,6 +25,14 @@ Write for two readers at once: an **agent** loading one file out of context, and
|
|
|
25
25
|
- No scenario storytelling, rhetorical questions, or meta-narration ("this section explains…").
|
|
26
26
|
- No duplicated rule text across stems — link instead.
|
|
27
27
|
|
|
28
|
+
## Shell guards
|
|
29
|
+
|
|
30
|
+
A write or execute guard allowlists the benign shapes and answers `ask` on anything it cannot classify. `allow` on an unknown shape is a defect.
|
|
31
|
+
|
|
32
|
+
- Name the bypass class — abbreviations, aliases, quoting, shell wrappers, config-injection options (`-c`, `--exec`, `--receive-pack`), value-consumption mismatch — not a list of spellings.
|
|
33
|
+
- Probe each shape with the flag on, the flag off, a sentinel, and an unreadable config. Quote the tool output. A green gate set is not that evidence.
|
|
34
|
+
- Compare every probed shape with the previous answer. A shape that asked before and allows now is a blocker.
|
|
35
|
+
|
|
28
36
|
## Size
|
|
29
37
|
|
|
30
38
|
- Shortest form that still changes behavior: if a bullet fits as a clause, make it a clause.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Settings guard (OpenCode plugin)
|
|
2
|
+
|
|
3
|
+
Applies `.ai.local/.env` on OpenCode. The static `permission.bash` rows stay the floor. A configured `deny`, including the `task-evil` agent, is final and this plugin never sees it.
|
|
4
|
+
|
|
5
|
+
## Git writes — `AI_RULES_ALLOW_GIT_WRITES`
|
|
6
|
+
|
|
7
|
+
The plugin imports `evaluate` from `.opencode/hooks/guard-shell-command.mjs`.
|
|
8
|
+
|
|
9
|
+
| Guard verdict | Permission hook | Tool hook, only when the permission hook is absent |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `allow` on a plain `git commit` / `git push` | effect `allow` (the static ask is lifted) | no throw; the static ask remains |
|
|
12
|
+
| `ask` | effect `ask`, with the guard's message | throw, so the command does not run |
|
|
13
|
+
| `allow` on anything else | unchanged | unchanged |
|
|
14
|
+
|
|
15
|
+
`false`, a missing file, and a broken file stay `ask`. `true` allows only a plain commit or push. Destructive, alias, and indirect shapes stay `ask`.
|
|
16
|
+
|
|
17
|
+
## Autoroute — `AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS`
|
|
18
|
+
|
|
19
|
+
The `prompt` session hook appends the same directive as Claude's `UserPromptSubmit` when the flag is `true` and the live-slug count is below `AI_RULES_MAX_PARALLEL_TASKS`. `false` appends nothing. A host that does not dispatch `prompt` leaves the entry-prose check in place.
|
|
20
|
+
|
|
21
|
+
## Files
|
|
22
|
+
|
|
23
|
+
- `index.ts` — host adapter.
|
|
24
|
+
- `policy.mjs` — pure command and prompt shaping. No host import.
|
|
25
|
+
- `prompt-face.mjs` — the shared autoroute evaluator. `generate-opencode` rewrites it from the template.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode settings guard.
|
|
3
|
+
*
|
|
4
|
+
* Reads `.ai.local/.env` through the shared shell guard and the prompt face.
|
|
5
|
+
* `ctx.permission.hook("evaluate")` maps the guard's `allow` / `ask` onto the
|
|
6
|
+
* permission effect, so a plain commit or push is allowed only when the git-write
|
|
7
|
+
* flag is on. A configured `deny` never reaches this hook. When the permission
|
|
8
|
+
* hook is missing, `ctx.tool.hook("execute.before")` throws on `ask`, which
|
|
9
|
+
* stops the command. The `prompt` session hook appends the autoroute directive
|
|
10
|
+
* when that flag is on and the live-slug cap allows it.
|
|
11
|
+
*
|
|
12
|
+
* A host without these hooks no-ops. The static `permission.bash` rows stay the floor.
|
|
13
|
+
*/
|
|
14
|
+
import path from "node:path"
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
16
|
+
import { Plugin } from "@opencode/plugin"
|
|
17
|
+
import {
|
|
18
|
+
appendPromptContext,
|
|
19
|
+
commandFromPermission,
|
|
20
|
+
commandFromTool,
|
|
21
|
+
promptText,
|
|
22
|
+
shouldApply,
|
|
23
|
+
} from "./policy.mjs"
|
|
24
|
+
|
|
25
|
+
type GuardDecision = { permission: string; user_message?: string; agent_message?: string }
|
|
26
|
+
type Evaluate = (event: unknown, options: { root: string }) => Promise<GuardDecision | null>
|
|
27
|
+
|
|
28
|
+
const recordOf = (value: unknown): Record<string, unknown> =>
|
|
29
|
+
value !== null && typeof value === "object" ? (value as Record<string, unknown>) : {}
|
|
30
|
+
|
|
31
|
+
const importEvaluate = async (file: string): Promise<Evaluate | null> => {
|
|
32
|
+
try {
|
|
33
|
+
const loaded = (await import(pathToFileURL(file).href)) as { evaluate?: Evaluate }
|
|
34
|
+
return typeof loaded.evaluate === "function" ? loaded.evaluate : null
|
|
35
|
+
} catch {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default Plugin.define({
|
|
41
|
+
id: "ai-rules.settings-guard",
|
|
42
|
+
async setup(ctx) {
|
|
43
|
+
try {
|
|
44
|
+
const projectRoot = path.resolve(ctx.location.directory)
|
|
45
|
+
const guard = await importEvaluate(
|
|
46
|
+
path.join(projectRoot, ".opencode", "hooks", "guard-shell-command.mjs"),
|
|
47
|
+
)
|
|
48
|
+
const promptFace = await importEvaluate(path.join(path.dirname(fileURLToPath(import.meta.url)), "prompt-face.mjs"))
|
|
49
|
+
|
|
50
|
+
const shellDecision = async (command: string): Promise<GuardDecision | null> => {
|
|
51
|
+
if (guard === null) return null
|
|
52
|
+
try {
|
|
53
|
+
const decision = await guard({ command }, { root: projectRoot })
|
|
54
|
+
return decision && typeof decision.permission === "string" ? decision : null
|
|
55
|
+
} catch {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let permissionBound = false
|
|
61
|
+
const permission = recordOf(ctx.permission)
|
|
62
|
+
if (typeof permission.hook === "function" && guard !== null) {
|
|
63
|
+
try {
|
|
64
|
+
await permission.hook("evaluate", async (event: unknown) => {
|
|
65
|
+
const command = commandFromPermission(event)
|
|
66
|
+
if (command === null) return
|
|
67
|
+
const decision = await shellDecision(command)
|
|
68
|
+
if (decision === null || !shouldApply(command, decision.permission)) return
|
|
69
|
+
const record = recordOf(event)
|
|
70
|
+
record.effect = decision.permission
|
|
71
|
+
if (decision.permission === "ask") {
|
|
72
|
+
const message = decision.user_message || decision.agent_message
|
|
73
|
+
if (message) record.message = message
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
permissionBound = true
|
|
77
|
+
} catch {
|
|
78
|
+
permissionBound = false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const tool = recordOf(ctx.tool)
|
|
83
|
+
if (!permissionBound && typeof tool.hook === "function" && guard !== null) {
|
|
84
|
+
try {
|
|
85
|
+
await tool.hook("execute.before", async (event: unknown, output: unknown) => {
|
|
86
|
+
const command = commandFromTool(event, output)
|
|
87
|
+
if (command === null) return
|
|
88
|
+
const decision = await shellDecision(command)
|
|
89
|
+
if (decision === null || decision.permission !== "ask" || !shouldApply(command, "ask")) return
|
|
90
|
+
throw new Error(decision.user_message || decision.agent_message || "blocked by the shell guard")
|
|
91
|
+
})
|
|
92
|
+
} catch {
|
|
93
|
+
/* a host that rejects the hook name keeps the static permission floor */
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const session = recordOf(ctx.session)
|
|
98
|
+
if (typeof session.hook === "function" && promptFace !== null) {
|
|
99
|
+
try {
|
|
100
|
+
await session.hook("prompt", async (event: unknown) => {
|
|
101
|
+
const envelope = await promptFace({ prompt: promptText(event) }, { root: projectRoot })
|
|
102
|
+
const output = recordOf(recordOf(envelope).hookSpecificOutput)
|
|
103
|
+
const text = typeof output.additionalContext === "string" ? output.additionalContext : ""
|
|
104
|
+
if (text !== "") appendPromptContext(event, text)
|
|
105
|
+
})
|
|
106
|
+
} catch {
|
|
107
|
+
/* autoroute stays off when the prompt hook is rejected */
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch {
|
|
111
|
+
/* the static permission rows remain the floor */
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure decisions for the OpenCode settings guard. No host import.
|
|
3
|
+
*
|
|
4
|
+
* `ask` from the shell guard always applies. `allow` applies only to a git
|
|
5
|
+
* commit or push the guard already classified as plain, so a user's other
|
|
6
|
+
* ask rules are left alone.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const SHELL_TOOLS = new Set(['bash', 'shell', 'sh']);
|
|
10
|
+
|
|
11
|
+
const recordOf = (value) =>
|
|
12
|
+
value !== null && typeof value === 'object' ? value : {};
|
|
13
|
+
|
|
14
|
+
export const shouldApply = (command, permission) => {
|
|
15
|
+
if (permission === 'ask') return true;
|
|
16
|
+
if (permission !== 'allow') return false;
|
|
17
|
+
return /\bgit\b/.test(command) && /\b(?:commit|push)\b/.test(command);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const firstText = (values) => {
|
|
21
|
+
if (!Array.isArray(values)) return null;
|
|
22
|
+
const found = values.find((item) => typeof item === 'string' && item.trim() !== '');
|
|
23
|
+
return typeof found === 'string' ? found : null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** The shell command on a permission-evaluate event, or null when it is not a shell check. */
|
|
27
|
+
export const commandFromPermission = (event) => {
|
|
28
|
+
const record = recordOf(event);
|
|
29
|
+
const action = typeof record.action === 'string' ? record.action : '';
|
|
30
|
+
if (action !== '' && action !== 'shell' && action !== 'bash') return null;
|
|
31
|
+
const fromResources = firstText(record.resources);
|
|
32
|
+
if (fromResources !== null) return fromResources;
|
|
33
|
+
const metadata = recordOf(record.metadata);
|
|
34
|
+
if (typeof metadata.command === 'string' && metadata.command.trim() !== '') return metadata.command;
|
|
35
|
+
const input = recordOf(record.input);
|
|
36
|
+
if (typeof input.command === 'string' && input.command.trim() !== '') return input.command;
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The shell command on a tool-execute event. `output` is the v1 second argument
|
|
42
|
+
* (`{ args: { command } }`); v2 carries the command on `event.input.command`.
|
|
43
|
+
*/
|
|
44
|
+
export const commandFromTool = (event, output) => {
|
|
45
|
+
const record = recordOf(event);
|
|
46
|
+
const tool = typeof record.tool === 'string' ? record.tool : '';
|
|
47
|
+
if (!SHELL_TOOLS.has(tool)) return null;
|
|
48
|
+
const input = recordOf(record.input);
|
|
49
|
+
if (typeof input.command === 'string') return input.command;
|
|
50
|
+
const args = recordOf(recordOf(output).args);
|
|
51
|
+
if (typeof args.command === 'string') return args.command;
|
|
52
|
+
const nested = recordOf(recordOf(record.output).args);
|
|
53
|
+
if (typeof nested.command === 'string') return nested.command;
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** The user prompt text, from `prompt` or from text parts. */
|
|
58
|
+
export const promptText = (event) => {
|
|
59
|
+
const record = recordOf(event);
|
|
60
|
+
if (typeof record.prompt === 'string') return record.prompt;
|
|
61
|
+
if (!Array.isArray(record.parts)) return '';
|
|
62
|
+
return record.parts
|
|
63
|
+
.map((part) => (typeof recordOf(part).text === 'string' ? recordOf(part).text : ''))
|
|
64
|
+
.filter((text) => text !== '')
|
|
65
|
+
.join('\n');
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Append the autoroute directive. A `parts` array gains a text part; a string
|
|
70
|
+
* `prompt` is extended. Any other shape is left untouched.
|
|
71
|
+
*
|
|
72
|
+
* @returns {boolean} whether the event was changed
|
|
73
|
+
*/
|
|
74
|
+
export const appendPromptContext = (event, text) => {
|
|
75
|
+
const record = recordOf(event);
|
|
76
|
+
if (Array.isArray(record.parts)) {
|
|
77
|
+
record.parts.push({ type: 'text', text });
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (typeof record.prompt === 'string') {
|
|
81
|
+
record.prompt = record.prompt.trim() === '' ? text : `${record.prompt}\n\n${text}`;
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Claude `UserPromptSubmit` autoroute prompt face.
|
|
3
|
+
// Rendered from `presets/_shared/hooks/prompt-autoroute.mjs.tmpl`; edit the
|
|
4
|
+
// template, never a rendered copy.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const SETTING_KEY = 'AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS';
|
|
10
|
+
const CAP_KEY = 'AI_RULES_MAX_PARALLEL_TASKS';
|
|
11
|
+
const DEFAULT_MAX_PARALLEL_TASKS = 4;
|
|
12
|
+
const MARKER = '[ai-rules:autoroute]';
|
|
13
|
+
// The chain hook's own terminal `status.json` states (`TERMINAL_RECEIPT_OUTCOMES`
|
|
14
|
+
// and the `terminal` set in `chain-team-phases.sh.tmpl`). A slug in one of these
|
|
15
|
+
// states is closed and must not suppress the wrap; every other state is live.
|
|
16
|
+
const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
17
|
+
const TASK_COMMAND = /^\/(?:task|task-continue)(?:\s|$)/;
|
|
18
|
+
const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
19
|
+
|
|
20
|
+
const directive = () =>
|
|
21
|
+
`${MARKER} This request arrived outside the task chain. Run the current request as /task before answering.`;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Default settings resolver: the same dynamic import of the seeded parser the
|
|
25
|
+
* shell guard uses. A missing or unimportable module yields `null`, so the hook
|
|
26
|
+
* stays inert instead of carrying a copy of the parser. The resolver returns
|
|
27
|
+
* the raw `{value, source}` setting so the boolean switch keeps its `=== true`
|
|
28
|
+
* coercion here while the numeric cap reads the value as-is (an old parser
|
|
29
|
+
* without the cap key yields the unknown-key `false`, and the cap stays at the
|
|
30
|
+
* default).
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<((key: string) => { value: boolean | number, source: string }) | null>} `get(key)`, or `null`
|
|
33
|
+
*/
|
|
34
|
+
const importSettings = async ({ root, exists, readText }) => {
|
|
35
|
+
const file = path.join(root, '.ai.local', 'scripts', 'settings.mjs');
|
|
36
|
+
if (!exists(file)) return null;
|
|
37
|
+
try {
|
|
38
|
+
const module = await import(pathToFileURL(file).href);
|
|
39
|
+
if (typeof module.readSetting !== 'function') return null;
|
|
40
|
+
return (key) => module.readSetting(key, { root, exists, readText });
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Every live slug — the canonical scan over the task store (`tasks/*`), never
|
|
48
|
+
* the `active-task.json` pointer. A slug is live when `tasks/<name>/status.json`
|
|
49
|
+
* parses to a non-terminal `state`; a missing tasks directory, a non-slug name,
|
|
50
|
+
* or an unreadable status is not a live task.
|
|
51
|
+
*
|
|
52
|
+
* @returns {string[]} sorted live slugs
|
|
53
|
+
*/
|
|
54
|
+
const liveSlugs = ({ root, exists, readText, readDirNames }) => {
|
|
55
|
+
const tasksDir = path.join(root, '.ai.local', 'team', 'tasks');
|
|
56
|
+
let names;
|
|
57
|
+
try {
|
|
58
|
+
names = readDirNames(tasksDir);
|
|
59
|
+
} catch {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const live = [];
|
|
63
|
+
for (const name of names) {
|
|
64
|
+
if (!SLUG_RE.test(name)) continue;
|
|
65
|
+
const statusFile = path.join(tasksDir, name, 'status.json');
|
|
66
|
+
if (!exists(statusFile)) continue;
|
|
67
|
+
try {
|
|
68
|
+
const status = JSON.parse(readText(statusFile));
|
|
69
|
+
const state = status && typeof status.state === 'string' ? status.state : null;
|
|
70
|
+
if (state !== null && !TERMINAL_STATES.has(state)) live.push(name);
|
|
71
|
+
} catch {
|
|
72
|
+
/* an unreadable status is not a live slug */
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return live.sort();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The Claude envelope for one prompt event, or `null` when the hook stays
|
|
80
|
+
* silent. Never throws: every failure resolves to silence.
|
|
81
|
+
*
|
|
82
|
+
* @param {unknown} event
|
|
83
|
+
* @param {{ root?: string, exists?: (file: string) => boolean, readText?: (file: string) => string, settings?: Function }} [options]
|
|
84
|
+
* @returns {Promise<{ hookSpecificOutput: { hookEventName: string, additionalContext: string } } | null>}
|
|
85
|
+
*/
|
|
86
|
+
export const evaluate = async (event, options = {}) => {
|
|
87
|
+
const {
|
|
88
|
+
root = process.cwd(),
|
|
89
|
+
exists = (file) => fs.existsSync(file),
|
|
90
|
+
readText = (file) => fs.readFileSync(file, 'utf8'),
|
|
91
|
+
readDirNames = (dir) =>
|
|
92
|
+
fs
|
|
93
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
94
|
+
.filter((entry) => entry.isDirectory())
|
|
95
|
+
.map((entry) => entry.name),
|
|
96
|
+
settings = importSettings,
|
|
97
|
+
} = options;
|
|
98
|
+
if (!event || typeof event !== 'object') return null;
|
|
99
|
+
const prompt = typeof event.prompt === 'string' ? event.prompt : '';
|
|
100
|
+
if (TASK_COMMAND.test(prompt.trimStart())) return null;
|
|
101
|
+
|
|
102
|
+
let enabled = false;
|
|
103
|
+
let cap = DEFAULT_MAX_PARALLEL_TASKS;
|
|
104
|
+
try {
|
|
105
|
+
const getSetting = await settings({ root, exists, readText });
|
|
106
|
+
if (typeof getSetting === 'function') {
|
|
107
|
+
const setting = getSetting(SETTING_KEY);
|
|
108
|
+
enabled = Boolean(setting) && setting.value === true;
|
|
109
|
+
const capSetting = getSetting(CAP_KEY);
|
|
110
|
+
if (Boolean(capSetting) && Number.isFinite(capSetting.value)) cap = capSetting.value;
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
enabled = false;
|
|
114
|
+
}
|
|
115
|
+
if (!enabled) return null;
|
|
116
|
+
// Wrap while the live-slug count is below the cap; an explicit `0` cap is
|
|
117
|
+
// unlimited — only a configured bound suppresses the wrap.
|
|
118
|
+
if (cap !== 0 && liveSlugs({ root, exists, readText, readDirNames }).length >= cap) return null;
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
hookSpecificOutput: {
|
|
122
|
+
hookEventName: 'UserPromptSubmit',
|
|
123
|
+
additionalContext: directive(),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const main = async () => {
|
|
129
|
+
let envelope = null;
|
|
130
|
+
try {
|
|
131
|
+
const parsed = JSON.parse(fs.readFileSync(0, 'utf8'));
|
|
132
|
+
envelope = await evaluate(parsed && typeof parsed === 'object' ? parsed : null, {
|
|
133
|
+
root: typeof parsed?.cwd === 'string' && parsed.cwd ? parsed.cwd : process.cwd(),
|
|
134
|
+
});
|
|
135
|
+
} catch {
|
|
136
|
+
envelope = null;
|
|
137
|
+
}
|
|
138
|
+
if (envelope) process.stdout.write(JSON.stringify(envelope));
|
|
139
|
+
process.exit(0);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const invokedDirectly = (() => {
|
|
143
|
+
if (process.argv[1] === undefined) return false;
|
|
144
|
+
try {
|
|
145
|
+
return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
146
|
+
} catch {
|
|
147
|
+
return path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
|
|
148
|
+
}
|
|
149
|
+
})();
|
|
150
|
+
|
|
151
|
+
if (invokedDirectly) {
|
|
152
|
+
await main();
|
|
153
|
+
}
|
|
@@ -8,7 +8,8 @@ Modelled on the built-in MCP sidebar plugin (`packages/tui/src/feature-plugins/s
|
|
|
8
8
|
|
|
9
9
|
- header `▼ Task` toggles on click; collapsed it reads `▶ Task (running · 3/7 · 16h 05m)`
|
|
10
10
|
- each row is a flex row of a bold label and a value; the state value is colored by tone (success, warning, error, muted)
|
|
11
|
-
- the
|
|
11
|
+
- the `time` row splits the wall clock: `work 1h 25m · gate 1h 00m · paused 30m · sleep 20m · idle 4m`. `work` is `attempt_finished.activeMs` (older ledgers fall back to `durationMs`, capped at 4h), `gate`/`paused`/`sleep` are interval sums, `idle` is what is left — parent latency, a hung attempt past the cap, anything the ledger cannot attribute. A zero bucket is hidden; `paused` takes the sentinel mtime until the hook writes `task_paused`
|
|
12
|
+
- the step row carries a progress bar, e.g. `3/7 ███░░░░░ · attempt 1 · 3h 35m`; a parallel wave reads `3/7 ███░░░░░ · 3 agents · 42m` and clocks from the oldest start; a `status.json` written before any attempt reads `3/7 · no attempt started` instead of hiding the plan
|
|
12
13
|
- the `eta` row reads `~52m · p90 3h 32m`: estimated time to finish the remaining plan steps. It hides while the run waits on a human gate, is paused, blocked, waiting for a receipt, or is done. A stale run keeps it — the estimate is historical, not live — and with fewer than 3 ledgers the row reads `—` instead of disappearing
|
|
13
14
|
- clicking any row opens a details dialog with 3-cell side padding: `goal.md`, pipeline steps with the current one marked, artifacts from `artifact-manifest.json`, the last manifest entries, the prompt, the last update age and the ETA with its ledger count. The body scrolls with ↑/↓, PgUp/PgDn, Home/End or the mouse wheel; `esc` closes it.
|
|
14
15
|
- a live task shows `■ stop` in the header; click → confirm → writes the task-scoped `.ai.local/team/tasks/<slug>/STOP` (the repo-wide `.ai.local/STOP` only when the task directory is gone). The in-flight attempt finishes, no next step starts. A task with a stop sentinel shows `▶ resume` instead: confirm clears it. Saying `/task-continue <slug>` (or `продолжай` / `continue`) in a matched session is the keyboard path. <!-- i18n-keep: E4 -->
|
|
@@ -26,7 +27,8 @@ Reads the nearest `.ai.local/team/` above the session directory, and the provide
|
|
|
26
27
|
- `tasks/<slug>/prompt-log.md` — the follow-up log, shown in the details dialog only
|
|
27
28
|
- `tasks/<slug>/status.json` — state, attempts, gate, timestamps
|
|
28
29
|
- `tasks/<slug>/pipeline.json` — step count and the agent for each remaining step
|
|
29
|
-
- `tasks/<slug>/metrics.json` — task start, role per attempt, attempt durations
|
|
30
|
+
- `tasks/<slug>/metrics.json` — task start, role per attempt, attempt durations; `attempt_finished` carries `agent`, `stepIndex`, `wallMs`, `activeMs`, `idleMs` (and `pausedMs`/`suspendedMs` are folded into `idleMs`), plus `human_gate_started`/`task_paused`/`task_resumed` for the buckets
|
|
31
|
+
- `tasks/<slug>/.suspend.jsonl` — host-suspension intervals appended by the sidebar (`wall clock − monotonic clock` gap > 60s); the chain hook subtracts the same file when it closes an attempt
|
|
30
32
|
- `tasks/<slug>/artifact-manifest.json` — producer receipts that feed the details dialog
|
|
31
33
|
- every `tasks/*/metrics.json` — historical attempt durations that feed the ETA medians
|
|
32
34
|
- `output-guard/results*.jsonl` — tool-byte totals for the economy block, read incrementally
|
|
@@ -35,7 +37,7 @@ Reads the nearest `.ai.local/team/` above the session directory, and the provide
|
|
|
35
37
|
|
|
36
38
|
`eta.ts` estimates the remaining agent work, not wall-clock time:
|
|
37
39
|
|
|
38
|
-
- per-agent median attempt duration and a per-step retry factor (attempts ÷ distinct steps, capped at 1.5) come from every `metrics.json` under the team root; the index is rebuilt with the prompt index, every 30s, through the same mtime cache
|
|
40
|
+
- per-agent median attempt duration and a per-step retry factor (attempts ÷ distinct steps, capped at 1.5) come from every `metrics.json` under the team root; the index is rebuilt with the prompt index, every 30s, through the same mtime cache. Samples use `activeMs` when present (older ledgers: `durationMs` capped at 4h) and skip `stale`/`unknown` closes
|
|
39
41
|
- remaining plan steps are summed, then scaled by 0.65: adding right-skewed per-step medians overestimates the median of the total
|
|
40
42
|
- a running step subtracts what it already spent (finished attempts plus the current attempt's elapsed), floored at 15% of its estimate
|
|
41
43
|
- `p90` is `max(4 × p50, 1.5 × √Σ p90²)` — the quadrature keeps the range from growing linearly with the step count
|
|
@@ -56,6 +58,7 @@ The sidebar renders the session the host passes into the `sidebar.content` slot
|
|
|
56
58
|
- tiers: an exact prompt match wins; otherwise a substring match of at least 40 characters over the remaining messages. A confirmation word is ignored at every tier
|
|
57
59
|
- a `/task-continue <slug>` message maps the tab directly to that slug, case-insensitively; an unknown slug falls back to the prompt match instead of hiding the task
|
|
58
60
|
- the first successful mapping is pinned for the session, so a new message cannot flip the tab; an explicit `/task-continue <other-slug>` re-binds it
|
|
61
|
+
- the pin is written to `.ai.local/team/.session-leases/<sessionID>.json` (the same file the chain hook reads). The server plugin sets `AI_RULES_SESSION_ID` and `OPENCODE_SESSION_ID` on `shell.env` for that tab, so a later hook call still selects this task when `TEAM_TASK_SLUG` is omitted. `active-task.json` stays the list of live slugs and is not a tab binding
|
|
59
62
|
- the match is memoized per prompt-index generation and a fingerprint of every message, so the one-second tick does not re-scan every prompt
|
|
60
63
|
- a `/task ...` prefix on the prompt is stripped on both sides, so a `prompt.md` written with or without the command matches
|
|
61
64
|
- a subagent session maps through `data.session.root(sessionID)`, so its sidebar shows the parent task
|
|
@@ -108,6 +111,8 @@ The sidebar is session-scoped and follows `session.sidebar.toggle` (`ctrl+x b`).
|
|
|
108
111
|
- The resume intent clears a task-scoped sentinel only for the session's pinned task; a repository-wide `.ai.local/STOP` is lifted only by an explicit `/task-continue <slug>`, never by a text match in an unrelated session. <!-- i18n-keep: E4 -->
|
|
109
112
|
- Mapping relies on prompt text: a task without `prompt.md` cannot be matched, so its tab falls back to the prompt view. A session whose first message is not the prompt (for example a resumed tab opened with a bare `продолжай`) needs `/task-continue <slug>`. <!-- i18n-keep: E4 -->
|
|
110
113
|
- With a remote server, messages come from the server but the prompt files are read from the client filesystem; a failed message fetch keeps the last view and marks it `offline` for a minute.
|
|
111
|
-
- `status.json` timestamps
|
|
114
|
+
- `status.json` and `metrics.json` timestamps drive every bucket; a gap that no event covers lands in `idle`, which is why a long wall clock on a paused run is explained instead of hidden. A suspension is only observable while the TUI process is alive to compare clocks, so a suspend while OpenCode is closed stays inside `idle`.
|
|
115
|
+
- The suspension detector only sees gaps above 60s; shorter timer stalls stay in `work`. An attempt is capped at 4h of work (`AI_RULES_ATTEMPT_MAX_MS` moves the cap for both the hook and the sidebar).
|
|
116
|
+
- A pause interval starts at the sentinel mtime, so the tail of an in-flight attempt — the work it does between the click and its own stop — is charged to `paused`, not to `work`. This is the same choice the UI makes while `stop` is engaged, so the two layers never disagree.
|
|
112
117
|
- A timestamp later than the host clock is ignored; a future `task_started` in agent-written metrics would otherwise freeze the elapsed value at `0s`.
|
|
113
118
|
- The ETA has no per-repository model: the medians are shared by every task under the team root, so a run that differs in size from the history is only as good as the step composition and the profile. It also needs finished attempts — a first run in a fresh repository shows no estimate.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs"
|
|
2
2
|
import path from "node:path"
|
|
3
|
+
import { MAX_ATTEMPT_MS } from "./timing.ts"
|
|
3
4
|
|
|
4
5
|
export type EtaStat = {
|
|
5
6
|
medianMs: number
|
|
@@ -33,10 +34,18 @@ type MetricEvent = {
|
|
|
33
34
|
type?: string
|
|
34
35
|
attemptId?: string
|
|
35
36
|
durationMs?: number
|
|
37
|
+
activeMs?: number
|
|
38
|
+
outcome?: string
|
|
36
39
|
agent?: string
|
|
37
40
|
stepIndex?: number
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
const attemptMs = (event: MetricEvent): number | undefined => {
|
|
44
|
+
const value = Number.isFinite(event.activeMs) ? event.activeMs : event.durationMs
|
|
45
|
+
if (!Number.isFinite(value) || !value || value <= 0) return undefined
|
|
46
|
+
return Math.min(value, MAX_ATTEMPT_MS)
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
type Reader = <T>(file: string) => T | null
|
|
41
50
|
|
|
42
51
|
const MIN_SAMPLE = 3
|
|
@@ -112,14 +121,18 @@ export const createEtaStats = (root: string, readJson: Reader): EtaStats => {
|
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
for (const event of events) {
|
|
115
|
-
if (event.type !== "attempt_finished"
|
|
124
|
+
if (event.type !== "attempt_finished") continue
|
|
125
|
+
// A reclaimed or unattributed close is not a work sample.
|
|
126
|
+
if (event.outcome === "stale" || event.outcome === "unknown") continue
|
|
127
|
+
const sample = attemptMs(event)
|
|
128
|
+
if (sample === undefined) continue
|
|
116
129
|
const parsed = parseAttempt(event.attemptId)
|
|
117
|
-
const ref = (event.attemptId
|
|
130
|
+
const ref = (event.attemptId ? started.get(event.attemptId) : undefined) ?? parsed
|
|
118
131
|
const agent = ref.agent ?? event.agent ?? "unknown"
|
|
119
132
|
const step = ref.step ?? parsed.step
|
|
120
133
|
if (!durations.has(agent)) durations.set(agent, [])
|
|
121
|
-
durations.get(agent)!.push(
|
|
122
|
-
all.push(
|
|
134
|
+
durations.get(agent)!.push(sample)
|
|
135
|
+
all.push(sample)
|
|
123
136
|
if (!stepKeys.has(agent)) stepKeys.set(agent, new Set())
|
|
124
137
|
stepKeys.get(agent)!.add(`${entry.name}:${step ?? event.attemptId}`)
|
|
125
138
|
}
|
|
@@ -165,15 +178,15 @@ const stepSpent = (
|
|
|
165
178
|
const agents = new Set(running.map((attempt) => attempt.agent).filter(Boolean))
|
|
166
179
|
let spent = 0
|
|
167
180
|
for (const event of events) {
|
|
168
|
-
if (event.type !== "attempt_finished"
|
|
181
|
+
if (event.type !== "attempt_finished") continue
|
|
169
182
|
const parsed = parseAttempt(event.attemptId)
|
|
170
183
|
if (parsed.step !== step) continue
|
|
171
184
|
if (agents.size > 0 && parsed.agent && !agents.has(parsed.agent)) continue
|
|
172
|
-
spent += event
|
|
185
|
+
spent += attemptMs(event) ?? 0
|
|
173
186
|
}
|
|
174
187
|
for (const attempt of running) {
|
|
175
188
|
if (attempt.startedAt === undefined) continue
|
|
176
|
-
spent += Math.max(0, now - attempt.startedAt)
|
|
189
|
+
spent += Math.min(Math.max(0, now - attempt.startedAt), MAX_ATTEMPT_MS)
|
|
177
190
|
}
|
|
178
191
|
return spent
|
|
179
192
|
}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { Plugin } from "@opencode/plugin"
|
|
2
|
+
import { bindShellEnv } from "./task-view.ts"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Put this tab's session id on the shell the chain hook is about to run.
|
|
6
|
+
* The command prefix `TEAM_TASK_SLUG=` still wins over the inherited env.
|
|
7
|
+
*/
|
|
2
8
|
|
|
3
9
|
export default Plugin.define({
|
|
4
10
|
id: "ai-rules.task-status",
|
|
5
|
-
setup() {
|
|
11
|
+
async setup(ctx) {
|
|
12
|
+
try {
|
|
13
|
+
if (typeof ctx.session?.hook !== "function") return
|
|
14
|
+
await ctx.session.hook("shell.env", bindShellEnv)
|
|
15
|
+
} catch {
|
|
16
|
+
/* a host that rejects the name keeps the on-disk pin */
|
|
17
|
+
}
|
|
18
|
+
},
|
|
6
19
|
})
|