@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
|
@@ -8,6 +8,17 @@ import { createEtaStats, estimateEta } from "./eta.ts"
|
|
|
8
8
|
import type { EtaStats } from "./eta.ts"
|
|
9
9
|
import { formatAge, formatDuration, formatEta } from "./format.ts"
|
|
10
10
|
import { normalize, verbatimPrompt } from "./prompt-text.ts"
|
|
11
|
+
import {
|
|
12
|
+
appendSuspendInterval,
|
|
13
|
+
gateIntervals,
|
|
14
|
+
monotonicNow,
|
|
15
|
+
pauseIntervals,
|
|
16
|
+
readSuspendIntervals,
|
|
17
|
+
suspendFile,
|
|
18
|
+
SuspendTracker,
|
|
19
|
+
timeBuckets,
|
|
20
|
+
} from "./timing.ts"
|
|
21
|
+
import type { TimeBuckets } from "./timing.ts"
|
|
11
22
|
import type {
|
|
12
23
|
Metrics,
|
|
13
24
|
MetricEvent,
|
|
@@ -35,6 +46,9 @@ export type TaskWatcherOptions = {
|
|
|
35
46
|
type PromptEntry = { slug: string; texts: string[]; updatedAt: number }
|
|
36
47
|
|
|
37
48
|
const TEAM_REL = path.join(".ai.local", "team")
|
|
49
|
+
const SESSION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/
|
|
50
|
+
const LEASE_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
51
|
+
const LEASE_TTL_MS = 7 * 24 * 60 * 60 * 1000
|
|
38
52
|
const TICK_MS = 1000
|
|
39
53
|
const SYNC_MS = 5000
|
|
40
54
|
const INDEX_MS = 30000
|
|
@@ -94,6 +108,74 @@ const readJson = <T>(file: string): T | null => {
|
|
|
94
108
|
}
|
|
95
109
|
}
|
|
96
110
|
|
|
111
|
+
const sessionLeaseFile = (root: string, sessionID: string): string =>
|
|
112
|
+
path.join(root, ".session-leases", `${sessionID}.json`)
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The shell env the chain hook reads. Injected by `shell.env` for the tab
|
|
116
|
+
* that is about to run a command. An id the hook would reject is omitted.
|
|
117
|
+
*/
|
|
118
|
+
export const sessionShellEnv = (sessionID: string | undefined): Record<string, string> | null => {
|
|
119
|
+
if (!sessionID || !SESSION_ID_RE.test(sessionID)) return null
|
|
120
|
+
return { AI_RULES_SESSION_ID: sessionID, OPENCODE_SESSION_ID: sessionID }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const recordOf = (value: unknown): Record<string, unknown> =>
|
|
124
|
+
value !== null && typeof value === "object" ? (value as Record<string, unknown>) : {}
|
|
125
|
+
|
|
126
|
+
/** Fill a `shell.env` output. A prefix already on the command is left alone. */
|
|
127
|
+
export const bindShellEnv = async (input: unknown, output: unknown): Promise<void> => {
|
|
128
|
+
if (output === null || typeof output !== "object") return
|
|
129
|
+
const sessionID = recordOf(input).sessionID
|
|
130
|
+
const bound = sessionShellEnv(typeof sessionID === "string" ? sessionID : undefined)
|
|
131
|
+
if (!bound) return
|
|
132
|
+
const target = output as Record<string, unknown>
|
|
133
|
+
const env = recordOf(target.env)
|
|
134
|
+
for (const [key, value] of Object.entries(bound)) {
|
|
135
|
+
if (typeof env[key] !== "string" || env[key] === "") env[key] = value
|
|
136
|
+
}
|
|
137
|
+
target.env = env
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Persist the tab pin in the same shape the chain hook reads. A second write
|
|
142
|
+
* of the same slug keeps `firstSeenAt`. A different slug starts a new window.
|
|
143
|
+
* Returns false when the id or the slug is one the hook would ignore.
|
|
144
|
+
*/
|
|
145
|
+
export const writeSessionBinding = (root: string, sessionID: string, slug: string): boolean => {
|
|
146
|
+
if (!sessionShellEnv(sessionID)) return false
|
|
147
|
+
if (slug.length > 48 || !LEASE_SLUG_RE.test(slug)) return false
|
|
148
|
+
const file = sessionLeaseFile(root, sessionID)
|
|
149
|
+
const now = new Date().toISOString()
|
|
150
|
+
let firstSeenAt = now
|
|
151
|
+
try {
|
|
152
|
+
if (Date.now() - fs.statSync(file).mtimeMs <= LEASE_TTL_MS) {
|
|
153
|
+
const previous = JSON.parse(fs.readFileSync(file, "utf8")) as {
|
|
154
|
+
slug?: string
|
|
155
|
+
firstSeenAt?: string
|
|
156
|
+
updatedAt?: string
|
|
157
|
+
}
|
|
158
|
+
if (previous.slug === slug) firstSeenAt = previous.firstSeenAt ?? previous.updatedAt ?? now
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
/* a missing lease starts a window */
|
|
162
|
+
}
|
|
163
|
+
const body = `${JSON.stringify({ slug, sessionId: sessionID, firstSeenAt, updatedAt: now })}\n`
|
|
164
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
165
|
+
const temporary = `${file}.${process.pid}.tmp`
|
|
166
|
+
fs.writeFileSync(temporary, body)
|
|
167
|
+
fs.renameSync(temporary, file)
|
|
168
|
+
return true
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const sessionLeasePresent = (root: string, sessionID: string): boolean => {
|
|
172
|
+
try {
|
|
173
|
+
return fs.statSync(sessionLeaseFile(root, sessionID)).isFile()
|
|
174
|
+
} catch {
|
|
175
|
+
return false
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
97
179
|
const findTeamRoot = (start: string): string | null => {
|
|
98
180
|
let dir = path.resolve(start)
|
|
99
181
|
for (;;) {
|
|
@@ -149,6 +231,27 @@ export const pauseState = (root: string, slug?: string): PauseScope | null => {
|
|
|
149
231
|
const pausePayload = (scope: PauseScope) =>
|
|
150
232
|
JSON.stringify({ reason: "soft stop requested from the task sidebar", scope })
|
|
151
233
|
|
|
234
|
+
const fileMtime = (file: string): number | undefined => {
|
|
235
|
+
try {
|
|
236
|
+
return fs.statSync(file).mtimeMs
|
|
237
|
+
} catch {
|
|
238
|
+
return undefined
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* When the current pause started. The hook records `task_paused` on its next
|
|
244
|
+
* run; until then the sentinel mtime is the only honest clock.
|
|
245
|
+
*/
|
|
246
|
+
const pauseStartedAt = (root: string, slug: string | undefined, scope: PauseScope): number | undefined => {
|
|
247
|
+
if (scope === "task") return slug ? fileMtime(taskSentinel(root, slug)) : undefined
|
|
248
|
+
const overlay = overlayDir(root)
|
|
249
|
+
if (!overlay) return undefined
|
|
250
|
+
return [fileMtime(path.join(overlay, "STOP")), fileMtime(path.join(overlay, "ESTOP"))]
|
|
251
|
+
.filter((value): value is number => value !== undefined)
|
|
252
|
+
.sort((left, right) => left - right)[0]
|
|
253
|
+
}
|
|
254
|
+
|
|
152
255
|
/** The scope actually written, or `null` when no sentinel could be written. */
|
|
153
256
|
export const engagePause = (root: string, slug?: string): PauseScope | null => {
|
|
154
257
|
if (slug) {
|
|
@@ -229,6 +332,16 @@ const progressBar = (value: number, total: number, width = 8): string => {
|
|
|
229
332
|
return `${"█".repeat(filled)}${"░".repeat(width - filled)}`
|
|
230
333
|
}
|
|
231
334
|
|
|
335
|
+
/** Work first, then every non-work bucket that actually happened. */
|
|
336
|
+
const bucketText = (buckets: TimeBuckets): string => {
|
|
337
|
+
const parts = [`work ${formatDuration(buckets.workMs)}`]
|
|
338
|
+
if (buckets.gateMs > 0) parts.push(`gate ${formatDuration(buckets.gateMs)}`)
|
|
339
|
+
if (buckets.pausedMs > 0) parts.push(`paused ${formatDuration(buckets.pausedMs)}`)
|
|
340
|
+
if (buckets.suspendedMs > 0) parts.push(`sleep ${formatDuration(buckets.suspendedMs)}`)
|
|
341
|
+
if (buckets.idleMs > 0) parts.push(`idle ${formatDuration(buckets.idleMs)}`)
|
|
342
|
+
return parts.join(" · ")
|
|
343
|
+
}
|
|
344
|
+
|
|
232
345
|
const TASK_COMMAND = /^\s*\/(?:task|task-evil|task-continue|spec-start)\s+/i
|
|
233
346
|
|
|
234
347
|
const stripCommand = (text: string): string => text.replace(TASK_COMMAND, "").trim()
|
|
@@ -467,6 +580,18 @@ const buildTaskView = (
|
|
|
467
580
|
? Math.min(toMs(events.find((event) => event.type === "task_completed")?.at) ?? updatedAt, now)
|
|
468
581
|
: now
|
|
469
582
|
const elapsed = startedAt === undefined ? undefined : Math.max(0, finishedAt - startedAt)
|
|
583
|
+
const suspend = readSuspendIntervals(suspendFile(taskDir))
|
|
584
|
+
const gates = gateIntervals(events, now)
|
|
585
|
+
if (status.awaitingHumanGate && gateStart !== undefined) gates.push({ from: gateStart, to: now })
|
|
586
|
+
const pauses = pauseIntervals(events, now)
|
|
587
|
+
if (pauseScope) pauses.push({ from: pauseStartedAt(root, slug, pauseScope) ?? updatedAt, to: now })
|
|
588
|
+
const running = attempts
|
|
589
|
+
.map((attempt) => toMs(attempt.startedAt))
|
|
590
|
+
.filter((value): value is number => value !== undefined)
|
|
591
|
+
const buckets =
|
|
592
|
+
elapsed === undefined
|
|
593
|
+
? undefined
|
|
594
|
+
: timeBuckets({ wallMs: elapsed, events, running, gate: gates, pause: pauses, suspend, now })
|
|
470
595
|
|
|
471
596
|
const freshness = currentStart ?? gateStart ?? updatedAt
|
|
472
597
|
// A long real step must not be called stale: the agent's own p90 raises the floor.
|
|
@@ -502,7 +627,7 @@ const buildTaskView = (
|
|
|
502
627
|
|
|
503
628
|
const baseState =
|
|
504
629
|
state === "paused"
|
|
505
|
-
? `⏸ paused${
|
|
630
|
+
? `⏸ paused${buckets && buckets.pausedMs > 0 ? ` · ${formatDuration(buckets.pausedMs)}` : ""}`
|
|
506
631
|
: pauseScope !== null
|
|
507
632
|
? "⏸ stopping · in-flight attempt finishes"
|
|
508
633
|
: stale
|
|
@@ -531,10 +656,15 @@ const buildTaskView = (
|
|
|
531
656
|
const progress = stepNumber
|
|
532
657
|
? `${stepNumber}/${totalSteps ?? "?"} ${progressBar(stepNumber, totalSteps ?? 0)}`
|
|
533
658
|
: "?"
|
|
659
|
+
// A parallel wave runs one clock for every member: the oldest start wins.
|
|
660
|
+
const since =
|
|
661
|
+
attempts.length > 1
|
|
662
|
+
? Math.min(...attempts.map((attempt) => toMs(attempt.startedAt) ?? now))
|
|
663
|
+
: currentStart
|
|
534
664
|
stepLine = [
|
|
535
665
|
progress.trim(),
|
|
536
|
-
current.attempt ? `attempt ${current.attempt}` : null,
|
|
537
|
-
formatDuration(now -
|
|
666
|
+
attempts.length > 1 ? `${attempts.length} agents` : current.attempt ? `attempt ${current.attempt}` : null,
|
|
667
|
+
formatDuration(now - Math.min(since, now)),
|
|
538
668
|
]
|
|
539
669
|
.filter(Boolean)
|
|
540
670
|
.join(" · ")
|
|
@@ -550,7 +680,9 @@ const buildTaskView = (
|
|
|
550
680
|
const progressLabel = !done && totalSteps && stepNumber ? `${stepNumber}/${totalSteps}` : null
|
|
551
681
|
const summary =
|
|
552
682
|
state === "paused"
|
|
553
|
-
? ["paused",
|
|
683
|
+
? ["paused", buckets && buckets.pausedMs > 0 ? formatDuration(buckets.pausedMs) : null]
|
|
684
|
+
.filter(Boolean)
|
|
685
|
+
.join(" · ")
|
|
554
686
|
: pauseScope !== null
|
|
555
687
|
? "stopping"
|
|
556
688
|
: stale
|
|
@@ -563,6 +695,7 @@ const buildTaskView = (
|
|
|
563
695
|
fields: [
|
|
564
696
|
{ label: "task", value: truncate(slug, 34) },
|
|
565
697
|
{ label: "state", value: statusLine, tone: offline ? "muted" : tone },
|
|
698
|
+
...(buckets ? [{ label: "time", value: bucketText(buckets), tone: "muted" as const }] : []),
|
|
566
699
|
{ label: "role", value: actor.role ?? "—" },
|
|
567
700
|
{ label: "agent", value: agentText ?? "—" },
|
|
568
701
|
{ label: "step", value: stepLine },
|
|
@@ -788,6 +921,8 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
|
|
|
788
921
|
let etaAt = 0
|
|
789
922
|
const sessions = new Map<string, SessionState>()
|
|
790
923
|
const bindings = new Map<string, string>()
|
|
924
|
+
const lastSlug = new Map<string, string>()
|
|
925
|
+
const suspendTracker = new SuspendTracker()
|
|
791
926
|
|
|
792
927
|
const sessionState = (id: string): SessionState => {
|
|
793
928
|
const existing = sessions.get(id)
|
|
@@ -803,6 +938,7 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
|
|
|
803
938
|
if (oldest === undefined) break
|
|
804
939
|
sessions.delete(oldest)
|
|
805
940
|
bindings.delete(oldest)
|
|
941
|
+
lastSlug.delete(oldest)
|
|
806
942
|
}
|
|
807
943
|
return created
|
|
808
944
|
}
|
|
@@ -851,6 +987,9 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
|
|
|
851
987
|
const refreshView = () => {
|
|
852
988
|
const start = options.directory()
|
|
853
989
|
const now = Date.now()
|
|
990
|
+
// Read the monotonic clock before anything else: the gap is wall time the
|
|
991
|
+
// process did not run for, and it must not be charged to the agent.
|
|
992
|
+
const gap = suspendTracker.tick(now, monotonicNow())
|
|
854
993
|
const root = start ? cachedTeamRoot(start, now) : null
|
|
855
994
|
if (!root) {
|
|
856
995
|
logTaskDebug(`no team root from ${start ?? "unknown directory"}`)
|
|
@@ -881,6 +1020,13 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
|
|
|
881
1020
|
}
|
|
882
1021
|
const current = sessionState(sessionID)
|
|
883
1022
|
syncSession(sessionID)
|
|
1023
|
+
if (gap) {
|
|
1024
|
+
const slug = bindings.get(sessionID) ?? lastSlug.get(sessionID)
|
|
1025
|
+
const file = slug ? suspendFile(path.join(root, "tasks", slug)) : undefined
|
|
1026
|
+
if (file && appendSuspendInterval(file, gap)) {
|
|
1027
|
+
logTaskDebug(`session=${sessionID} suspend ${Math.round((gap.to - gap.from) / 1000)}s for ${slug}`)
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
884
1030
|
const offline = current.errorAt !== undefined && now - current.errorAt < OFFLINE_MS
|
|
885
1031
|
const pinned = bindings.get(sessionID)
|
|
886
1032
|
const view = buildSessionView(
|
|
@@ -898,7 +1044,16 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
|
|
|
898
1044
|
// Pin the first successful mapping so a later follow-up cannot flip the tab
|
|
899
1045
|
// to another task. An explicit `/task-continue` still re-binds.
|
|
900
1046
|
if (view.slug) {
|
|
901
|
-
|
|
1047
|
+
const changed = pinned !== view.slug
|
|
1048
|
+
if (changed) bindings.set(sessionID, view.slug)
|
|
1049
|
+
if (changed || !sessionLeasePresent(root, sessionID)) {
|
|
1050
|
+
try {
|
|
1051
|
+
writeSessionBinding(root, sessionID, view.slug)
|
|
1052
|
+
} catch (error) {
|
|
1053
|
+
logTaskDebug(`lease write failed for ${sessionID}: ${error instanceof Error ? error.message : String(error)}`)
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
lastSlug.set(sessionID, view.slug)
|
|
902
1057
|
} else if (pinned && !resolveSlug(root, pinned)) {
|
|
903
1058
|
bindings.delete(sessionID)
|
|
904
1059
|
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wall-clock buckets for a task run. Every value is derived from ledger events,
|
|
3
|
+
* never from a single subtraction: `wallMs` is the calendar span, the rest are
|
|
4
|
+
* intervals that the sidebar can show apart.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs"
|
|
8
|
+
import path from "node:path"
|
|
9
|
+
|
|
10
|
+
export type Interval = { from: number; to: number }
|
|
11
|
+
|
|
12
|
+
/** A killed producer or a suspended host must not count as work. */
|
|
13
|
+
export const MAX_ATTEMPT_MS = (() => {
|
|
14
|
+
const raw = process.env.AI_RULES_ATTEMPT_MAX_MS
|
|
15
|
+
const value = raw === undefined || raw.trim() === "" ? Number.NaN : Number(raw)
|
|
16
|
+
return Number.isFinite(value) && value >= 10 * 60 * 1000 ? value : 4 * 60 * 60 * 1000
|
|
17
|
+
})()
|
|
18
|
+
|
|
19
|
+
/** Longer than the one-second tick plus timer jitter, shorter than any real pause. */
|
|
20
|
+
export const SUSPEND_GAP_MS = 60 * 1000
|
|
21
|
+
|
|
22
|
+
export type TimingEvent = {
|
|
23
|
+
type?: string
|
|
24
|
+
at?: string
|
|
25
|
+
eventId?: string
|
|
26
|
+
gateStartedEventId?: string
|
|
27
|
+
durationMs?: number
|
|
28
|
+
activeMs?: number
|
|
29
|
+
outcome?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const toMs = (value?: string): number | undefined => {
|
|
33
|
+
if (!value) return undefined
|
|
34
|
+
const parsed = Date.parse(value)
|
|
35
|
+
return Number.isFinite(parsed) ? parsed : undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const mergeIntervals = (intervals: readonly Interval[]): Interval[] => {
|
|
39
|
+
const sorted = intervals
|
|
40
|
+
.filter((interval) => Number.isFinite(interval.from) && Number.isFinite(interval.to) && interval.to > interval.from)
|
|
41
|
+
.sort((left, right) => left.from - right.from)
|
|
42
|
+
const merged: Interval[] = []
|
|
43
|
+
for (const interval of sorted) {
|
|
44
|
+
const last = merged.at(-1)
|
|
45
|
+
if (!last || interval.from > last.to) {
|
|
46
|
+
merged.push({ ...interval })
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
last.to = Math.max(last.to, interval.to)
|
|
50
|
+
}
|
|
51
|
+
return merged
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const overlapMs = (intervals: readonly Interval[], from: number, to: number): number => {
|
|
55
|
+
if (to <= from) return 0
|
|
56
|
+
let total = 0
|
|
57
|
+
for (const interval of mergeIntervals(intervals)) {
|
|
58
|
+
const start = Math.max(from, interval.from)
|
|
59
|
+
const end = Math.min(to, interval.to)
|
|
60
|
+
if (end > start) total += end - start
|
|
61
|
+
}
|
|
62
|
+
return total
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Gate waits pair on `eventId`. An unclosed gate runs to `now`: a stuck gate is
|
|
67
|
+
* still waiting, not free time.
|
|
68
|
+
*/
|
|
69
|
+
export const gateIntervals = (events: readonly TimingEvent[], now: number): Interval[] => {
|
|
70
|
+
const opened = new Map<string, number>()
|
|
71
|
+
const closed = new Map<string, number>()
|
|
72
|
+
for (const event of events) {
|
|
73
|
+
if (event.type !== "human_gate_started" || !event.eventId) continue
|
|
74
|
+
const at = toMs(event.at)
|
|
75
|
+
if (at !== undefined) opened.set(event.eventId, at)
|
|
76
|
+
}
|
|
77
|
+
for (const event of events) {
|
|
78
|
+
if (event.type !== "human_gate_ended" || !event.gateStartedEventId) continue
|
|
79
|
+
const at = toMs(event.at)
|
|
80
|
+
if (at !== undefined) closed.set(event.gateStartedEventId, at)
|
|
81
|
+
}
|
|
82
|
+
return [...opened].map(([eventId, from]) => ({
|
|
83
|
+
from,
|
|
84
|
+
to: Math.max(from, closed.get(eventId) ?? now),
|
|
85
|
+
}))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Pauses pair as `task_paused` / `task_resumed`; the open one runs to `now`. */
|
|
89
|
+
export const pauseIntervals = (events: readonly TimingEvent[], now: number): Interval[] => {
|
|
90
|
+
const intervals: Interval[] = []
|
|
91
|
+
let open: number | undefined
|
|
92
|
+
for (const event of events) {
|
|
93
|
+
const at = toMs(event.at)
|
|
94
|
+
if (at === undefined) continue
|
|
95
|
+
if (event.type === "task_paused" && open === undefined) open = at
|
|
96
|
+
if (event.type === "task_resumed" && open !== undefined) {
|
|
97
|
+
intervals.push({ from: open, to: Math.max(open, at) })
|
|
98
|
+
open = undefined
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (open !== undefined) intervals.push({ from: open, to: Math.max(open, now) })
|
|
102
|
+
return intervals
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const suspendCache = new Map<string, { size: number; value: Interval[] }>()
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Intervals the host was suspended, appended by the sidebar's gap detector. The
|
|
109
|
+
* hook reads the same file when it closes an attempt.
|
|
110
|
+
*/
|
|
111
|
+
export const readSuspendIntervals = (file: string): Interval[] => {
|
|
112
|
+
let size: number
|
|
113
|
+
try {
|
|
114
|
+
size = fs.statSync(file).size
|
|
115
|
+
} catch {
|
|
116
|
+
suspendCache.delete(file)
|
|
117
|
+
return []
|
|
118
|
+
}
|
|
119
|
+
const hit = suspendCache.get(file)
|
|
120
|
+
if (hit && hit.size === size) return hit.value
|
|
121
|
+
const value: Interval[] = []
|
|
122
|
+
try {
|
|
123
|
+
for (const line of fs.readFileSync(file, "utf8").split("\n")) {
|
|
124
|
+
const trimmed = line.trim()
|
|
125
|
+
if (trimmed === "") continue
|
|
126
|
+
try {
|
|
127
|
+
const row = JSON.parse(trimmed) as { from?: string; to?: string }
|
|
128
|
+
const from = toMs(row.from)
|
|
129
|
+
const to = toMs(row.to)
|
|
130
|
+
if (from !== undefined && to !== undefined && to > from) value.push({ from, to })
|
|
131
|
+
} catch {
|
|
132
|
+
// A torn last line is read again when the file grows.
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
return hit?.value ?? []
|
|
137
|
+
}
|
|
138
|
+
suspendCache.set(file, { size, value })
|
|
139
|
+
return value
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const appendSuspendInterval = (file: string, interval: Interval): boolean => {
|
|
143
|
+
try {
|
|
144
|
+
fs.appendFileSync(
|
|
145
|
+
file,
|
|
146
|
+
`${JSON.stringify({ from: new Date(interval.from).toISOString(), to: new Date(interval.to).toISOString() })}\n`,
|
|
147
|
+
"utf8",
|
|
148
|
+
)
|
|
149
|
+
return true
|
|
150
|
+
} catch {
|
|
151
|
+
return false
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const suspendFile = (taskDir: string): string => path.join(taskDir, ".suspend.jsonl")
|
|
156
|
+
|
|
157
|
+
export type TimeBuckets = {
|
|
158
|
+
wallMs: number
|
|
159
|
+
workMs: number
|
|
160
|
+
gateMs: number
|
|
161
|
+
pausedMs: number
|
|
162
|
+
suspendedMs: number
|
|
163
|
+
idleMs: number
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export type BucketInput = {
|
|
167
|
+
wallMs: number
|
|
168
|
+
events: readonly TimingEvent[]
|
|
169
|
+
/** Started-at of every in-flight attempt. */
|
|
170
|
+
running: readonly number[]
|
|
171
|
+
gate: readonly Interval[]
|
|
172
|
+
pause: readonly Interval[]
|
|
173
|
+
suspend: readonly Interval[]
|
|
174
|
+
now: number
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The hook already removed pauses and suspends from `activeMs`; only cap. */
|
|
178
|
+
const attemptActive = (event: TimingEvent): number => {
|
|
179
|
+
const active = Number.isFinite(event.activeMs) ? event.activeMs : event.durationMs
|
|
180
|
+
if (!Number.isFinite(active) || !active || active <= 0) return 0
|
|
181
|
+
return Math.min(active, MAX_ATTEMPT_MS)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* `workMs` is attempt time with pauses, gates and suspends already removed;
|
|
186
|
+
* `idleMs` is what is left of the wall clock — parent latency, a hung attempt
|
|
187
|
+
* past the cap, and anything the ledger cannot attribute.
|
|
188
|
+
*/
|
|
189
|
+
export const timeBuckets = ({ wallMs, events, running, gate, pause, suspend, now }: BucketInput): TimeBuckets => {
|
|
190
|
+
const suspended = mergeIntervals(suspend)
|
|
191
|
+
const nonWork = mergeIntervals([...gate, ...pause, ...suspended])
|
|
192
|
+
let workMs = 0
|
|
193
|
+
for (const event of events) {
|
|
194
|
+
if (event.type === "attempt_finished") workMs += attemptActive(event)
|
|
195
|
+
}
|
|
196
|
+
for (const startedAt of running) {
|
|
197
|
+
const span = now - startedAt
|
|
198
|
+
if (span <= 0) continue
|
|
199
|
+
workMs += Math.min(Math.max(0, span - overlapMs(nonWork, startedAt, now)), MAX_ATTEMPT_MS)
|
|
200
|
+
}
|
|
201
|
+
const from = now - wallMs
|
|
202
|
+
const gateMs = overlapMs(gate, from, now)
|
|
203
|
+
const pausedMs = overlapMs(pause, from, now)
|
|
204
|
+
const suspendedMs = overlapMs(suspended, from, now)
|
|
205
|
+
// The union, not the sum: a pause during a suspend is one stretch of no work.
|
|
206
|
+
const idleMs = Math.max(0, wallMs - workMs - overlapMs(nonWork, from, now))
|
|
207
|
+
return {
|
|
208
|
+
wallMs: Math.max(0, wallMs),
|
|
209
|
+
workMs: Math.max(0, workMs),
|
|
210
|
+
gateMs,
|
|
211
|
+
pausedMs,
|
|
212
|
+
suspendedMs,
|
|
213
|
+
idleMs,
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Wall time minus monotonic time: 90 minutes of sleep shows as a ninety-minute
|
|
219
|
+
* gap that no timer fired during. The detector only reports; the caller persists.
|
|
220
|
+
*/
|
|
221
|
+
export class SuspendTracker {
|
|
222
|
+
private wallAt = 0
|
|
223
|
+
private monotonicAt = 0
|
|
224
|
+
private armed = false
|
|
225
|
+
|
|
226
|
+
tick(wall: number, monotonic: number): Interval | null {
|
|
227
|
+
if (!this.armed) {
|
|
228
|
+
this.armed = true
|
|
229
|
+
this.wallAt = wall
|
|
230
|
+
this.monotonicAt = monotonic
|
|
231
|
+
return null
|
|
232
|
+
}
|
|
233
|
+
const wallDelta = wall - this.wallAt
|
|
234
|
+
const monotonicDelta = monotonic - this.monotonicAt
|
|
235
|
+
this.wallAt = wall
|
|
236
|
+
this.monotonicAt = monotonic
|
|
237
|
+
const gap = wallDelta - monotonicDelta
|
|
238
|
+
if (gap < SUSPEND_GAP_MS) return null
|
|
239
|
+
return { from: wall - wallDelta, to: wall - wallDelta + gap }
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export const monotonicNow = (): number =>
|
|
244
|
+
typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now()
|
|
@@ -60,10 +60,16 @@ export type MetricEvent = {
|
|
|
60
60
|
type?: string
|
|
61
61
|
at?: string
|
|
62
62
|
eventId?: string
|
|
63
|
+
gateStartedEventId?: string
|
|
63
64
|
attemptId?: string
|
|
64
65
|
agent?: string
|
|
65
66
|
role?: string
|
|
66
67
|
durationMs?: number
|
|
68
|
+
wallMs?: number
|
|
69
|
+
activeMs?: number
|
|
70
|
+
idleMs?: number
|
|
71
|
+
outOfBandId?: string
|
|
72
|
+
outcome?: string
|
|
67
73
|
stepIndex?: number
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "opencode",
|
|
4
4
|
"stack": "svelte",
|
|
5
5
|
"semanticSource": "cursor/svelte",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "0ee4bc76f8ae9c99addaee8e5a1b99985d8965e58991c447caea624973d52bd7",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|
|
@@ -33,8 +33,9 @@ mass-kill, package-manager mismatch and a busy dev-server port.
|
|
|
33
33
|
- `run-hook.mjs` — not wired; no native hook schema, the chain hook stays a manual runner
|
|
34
34
|
- `hooks/examples/**` — hook plugin port is a follow-up
|
|
35
35
|
|
|
36
|
-
`guard-shell-command.mjs`
|
|
37
|
-
|
|
38
|
-
`
|
|
39
|
-
`tool.execute.
|
|
40
|
-
|
|
36
|
+
`guard-shell-command.mjs` is not a registered host command. Enforcement is
|
|
37
|
+
`.opencode/plugins/settings-guard/`: it calls this module's `evaluate` from
|
|
38
|
+
`ctx.permission.hook("evaluate")` (and, when that hook is absent, from
|
|
39
|
+
`ctx.tool.hook("execute.before")`). `opencode.json` `permission.bash` stays
|
|
40
|
+
the static floor. A configured `deny` (the `task-evil` agent) never reaches
|
|
41
|
+
the plugin. Do not describe the unregistered CLI file itself as enforcement.
|