@pennixrv/trellis 0.7.2-beta.3 → 0.7.2-beta.30
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/README.md +14 -0
- package/dist/cli/index.js +4 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/ablate.d.ts.map +1 -1
- package/dist/commands/ablate.js +13 -0
- package/dist/commands/ablate.js.map +1 -1
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +138 -120
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/teamwork/adapters/acp.d.ts.map +1 -1
- package/dist/commands/teamwork/adapters/acp.js +3 -0
- package/dist/commands/teamwork/adapters/acp.js.map +1 -1
- package/dist/commands/teamwork/adapters/index.d.ts +1 -1
- package/dist/commands/teamwork/adapters/index.d.ts.map +1 -1
- package/dist/commands/teamwork/artifact.d.ts +2 -0
- package/dist/commands/teamwork/artifact.d.ts.map +1 -1
- package/dist/commands/teamwork/artifact.js +4 -2
- package/dist/commands/teamwork/artifact.js.map +1 -1
- package/dist/commands/teamwork/batch-reservation.d.ts.map +1 -1
- package/dist/commands/teamwork/batch-reservation.js +16 -8
- package/dist/commands/teamwork/batch-reservation.js.map +1 -1
- package/dist/commands/teamwork/batch.d.ts +15 -1
- package/dist/commands/teamwork/batch.d.ts.map +1 -1
- package/dist/commands/teamwork/batch.js +279 -24
- package/dist/commands/teamwork/batch.js.map +1 -1
- package/dist/commands/teamwork/coordinator.d.ts +3 -0
- package/dist/commands/teamwork/coordinator.d.ts.map +1 -1
- package/dist/commands/teamwork/coordinator.js +22 -3
- package/dist/commands/teamwork/coordinator.js.map +1 -1
- package/dist/commands/teamwork/create.d.ts +1 -0
- package/dist/commands/teamwork/create.d.ts.map +1 -1
- package/dist/commands/teamwork/create.js +4 -0
- package/dist/commands/teamwork/create.js.map +1 -1
- package/dist/commands/teamwork/evidence-references.d.ts +19 -0
- package/dist/commands/teamwork/evidence-references.d.ts.map +1 -0
- package/dist/commands/teamwork/evidence-references.js +249 -0
- package/dist/commands/teamwork/evidence-references.js.map +1 -0
- package/dist/commands/teamwork/foreground-wait.d.ts +4 -1
- package/dist/commands/teamwork/foreground-wait.d.ts.map +1 -1
- package/dist/commands/teamwork/foreground-wait.js +15 -1
- package/dist/commands/teamwork/foreground-wait.js.map +1 -1
- package/dist/commands/teamwork/index.d.ts.map +1 -1
- package/dist/commands/teamwork/index.js +47 -5
- package/dist/commands/teamwork/index.js.map +1 -1
- package/dist/commands/teamwork/list.d.ts +1 -0
- package/dist/commands/teamwork/list.d.ts.map +1 -1
- package/dist/commands/teamwork/list.js +4 -1
- package/dist/commands/teamwork/list.js.map +1 -1
- package/dist/commands/teamwork/prompt.js +1 -1
- package/dist/commands/teamwork/prompt.js.map +1 -1
- package/dist/commands/teamwork/rm.d.ts +27 -4
- package/dist/commands/teamwork/rm.d.ts.map +1 -1
- package/dist/commands/teamwork/rm.js +155 -51
- package/dist/commands/teamwork/rm.js.map +1 -1
- package/dist/commands/teamwork/run.d.ts.map +1 -1
- package/dist/commands/teamwork/run.js +10 -1
- package/dist/commands/teamwork/run.js.map +1 -1
- package/dist/commands/teamwork/runtime.d.ts +1 -1
- package/dist/commands/teamwork/runtime.d.ts.map +1 -1
- package/dist/commands/teamwork/runtime.js +14 -4
- package/dist/commands/teamwork/runtime.js.map +1 -1
- package/dist/commands/teamwork/spawn.d.ts.map +1 -1
- package/dist/commands/teamwork/spawn.js +4 -1
- package/dist/commands/teamwork/spawn.js.map +1 -1
- package/dist/commands/teamwork/supervisor/stdout.d.ts.map +1 -1
- package/dist/commands/teamwork/supervisor/stdout.js +7 -0
- package/dist/commands/teamwork/supervisor/stdout.js.map +1 -1
- package/dist/commands/teamwork/supervisor.d.ts +1 -1
- package/dist/commands/teamwork/supervisor.d.ts.map +1 -1
- package/dist/commands/teamwork/teammate-adapters.d.ts +3 -0
- package/dist/commands/teamwork/teammate-adapters.d.ts.map +1 -1
- package/dist/commands/teamwork/teammate-adapters.js +14 -5
- package/dist/commands/teamwork/teammate-adapters.js.map +1 -1
- package/dist/commands/teamwork/teammate-launch.d.ts +3 -1
- package/dist/commands/teamwork/teammate-launch.d.ts.map +1 -1
- package/dist/commands/teamwork/teammate-launch.js +7 -5
- package/dist/commands/teamwork/teammate-launch.js.map +1 -1
- package/dist/commands/teamwork/workers.d.ts +8 -0
- package/dist/commands/teamwork/workers.d.ts.map +1 -0
- package/dist/commands/teamwork/workers.js +67 -0
- package/dist/commands/teamwork/workers.js.map +1 -0
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +188 -59
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +5 -7
- package/dist/commands/workflow.js.map +1 -1
- package/dist/configurators/codebuddy.d.ts +1 -8
- package/dist/configurators/codebuddy.d.ts.map +1 -1
- package/dist/configurators/codebuddy.js +2 -12
- package/dist/configurators/codebuddy.js.map +1 -1
- package/dist/configurators/codex.d.ts +0 -36
- package/dist/configurators/codex.d.ts.map +1 -1
- package/dist/configurators/codex.js +13 -106
- package/dist/configurators/codex.js.map +1 -1
- package/dist/configurators/copilot.d.ts +1 -12
- package/dist/configurators/copilot.d.ts.map +1 -1
- package/dist/configurators/copilot.js +2 -20
- package/dist/configurators/copilot.js.map +1 -1
- package/dist/configurators/cursor.d.ts +1 -8
- package/dist/configurators/cursor.d.ts.map +1 -1
- package/dist/configurators/cursor.js +2 -12
- package/dist/configurators/cursor.js.map +1 -1
- package/dist/configurators/droid.d.ts +1 -8
- package/dist/configurators/droid.d.ts.map +1 -1
- package/dist/configurators/droid.js +2 -12
- package/dist/configurators/droid.js.map +1 -1
- package/dist/configurators/dsh.d.ts +1 -21
- package/dist/configurators/dsh.d.ts.map +1 -1
- package/dist/configurators/dsh.js +4 -37
- package/dist/configurators/dsh.js.map +1 -1
- package/dist/configurators/gemini.d.ts +1 -16
- package/dist/configurators/gemini.d.ts.map +1 -1
- package/dist/configurators/gemini.js +3 -21
- package/dist/configurators/gemini.js.map +1 -1
- package/dist/configurators/grok.d.ts +1 -12
- package/dist/configurators/grok.d.ts.map +1 -1
- package/dist/configurators/grok.js +2 -18
- package/dist/configurators/grok.js.map +1 -1
- package/dist/configurators/kimi.d.ts +1 -21
- package/dist/configurators/kimi.d.ts.map +1 -1
- package/dist/configurators/kimi.js +2 -38
- package/dist/configurators/kimi.js.map +1 -1
- package/dist/configurators/kiro.d.ts +1 -9
- package/dist/configurators/kiro.d.ts.map +1 -1
- package/dist/configurators/kiro.js +1 -9
- package/dist/configurators/kiro.js.map +1 -1
- package/dist/configurators/omp.d.ts.map +1 -1
- package/dist/configurators/omp.js +1 -5
- package/dist/configurators/omp.js.map +1 -1
- package/dist/configurators/pi.d.ts.map +1 -1
- package/dist/configurators/pi.js +2 -5
- package/dist/configurators/pi.js.map +1 -1
- package/dist/configurators/qoder.d.ts +1 -10
- package/dist/configurators/qoder.d.ts.map +1 -1
- package/dist/configurators/qoder.js +3 -15
- package/dist/configurators/qoder.js.map +1 -1
- package/dist/configurators/reasonix.d.ts +1 -12
- package/dist/configurators/reasonix.d.ts.map +1 -1
- package/dist/configurators/reasonix.js +3 -22
- package/dist/configurators/reasonix.js.map +1 -1
- package/dist/configurators/shared.d.ts +1 -24
- package/dist/configurators/shared.d.ts.map +1 -1
- package/dist/configurators/shared.js +5 -184
- package/dist/configurators/shared.js.map +1 -1
- package/dist/configurators/snow.d.ts +1 -20
- package/dist/configurators/snow.d.ts.map +1 -1
- package/dist/configurators/snow.js +2 -25
- package/dist/configurators/snow.js.map +1 -1
- package/dist/configurators/trae.d.ts +1 -14
- package/dist/configurators/trae.d.ts.map +1 -1
- package/dist/configurators/trae.js +3 -19
- package/dist/configurators/trae.js.map +1 -1
- package/dist/configurators/workflow.d.ts +5 -0
- package/dist/configurators/workflow.d.ts.map +1 -1
- package/dist/configurators/workflow.js +85 -57
- package/dist/configurators/workflow.js.map +1 -1
- package/dist/configurators/zcode.d.ts +1 -13
- package/dist/configurators/zcode.d.ts.map +1 -1
- package/dist/configurators/zcode.js +2 -18
- package/dist/configurators/zcode.js.map +1 -1
- package/dist/migrations/manifests/0.5.0-beta.5.json +1 -212
- package/dist/migrations/manifests/0.7.2-beta.10.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.11.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.12.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.13.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.14.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.15.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.16.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.17.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.18.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.19.json +11 -0
- package/dist/migrations/manifests/0.7.2-beta.20.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.21.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.22.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.23.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.24.json +8 -0
- package/dist/migrations/manifests/0.7.2-beta.25.json +8 -0
- package/dist/migrations/manifests/0.7.2-beta.26.json +8 -0
- package/dist/migrations/manifests/0.7.2-beta.27.json +8 -0
- package/dist/migrations/manifests/0.7.2-beta.28.json +8 -0
- package/dist/migrations/manifests/0.7.2-beta.29.json +8 -0
- package/dist/migrations/manifests/0.7.2-beta.30.json +10 -0
- package/dist/migrations/manifests/0.7.2-beta.4.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.5.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.6.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.7.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.8.json +9 -0
- package/dist/migrations/manifests/0.7.2-beta.9.json +9 -0
- package/dist/migrations/retired-native-paths.d.ts +109 -0
- package/dist/migrations/retired-native-paths.d.ts.map +1 -0
- package/dist/migrations/retired-native-paths.js +263 -0
- package/dist/migrations/retired-native-paths.js.map +1 -0
- package/dist/templates/claude/index.d.ts +1 -16
- package/dist/templates/claude/index.d.ts.map +1 -1
- package/dist/templates/claude/index.js +5 -32
- package/dist/templates/claude/index.js.map +1 -1
- package/dist/templates/claude/settings.json +0 -22
- package/dist/templates/codebuddy/index.d.ts +2 -3
- package/dist/templates/codebuddy/index.d.ts.map +1 -1
- package/dist/templates/codebuddy/index.js +2 -3
- package/dist/templates/codebuddy/index.js.map +1 -1
- package/dist/templates/codebuddy/settings.json +0 -10
- package/dist/templates/codex/config.toml +4 -19
- package/dist/templates/codex/hooks/session-start.py +25 -30
- package/dist/templates/codex/hooks/turn-guard.py +67 -0
- package/dist/templates/codex/hooks.json +57 -6
- package/dist/templates/codex/index.d.ts +0 -5
- package/dist/templates/codex/index.d.ts.map +1 -1
- package/dist/templates/codex/index.js +0 -13
- package/dist/templates/codex/index.js.map +1 -1
- package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/SKILL.md +2 -0
- package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/workflow.md +13 -3
- package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/SKILL.md +2 -0
- package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/workflow.md +17 -9
- package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/SKILL.md +2 -0
- package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/workflow.md +7 -3
- package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +7 -7
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +9 -51
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-context-loading.md +3 -15
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +1 -2
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/bundled-skills.md +1 -1
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/context-injection.md +4 -9
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +2 -2
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/multi-agent-teamwork.md +6 -0
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +1 -1
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +10 -8
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +9 -79
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +2 -4
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +3 -6
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +24 -103
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +1 -1
- package/dist/templates/common/bundled-skills/trellis-session-insight/SKILL.md +1 -1
- package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/SKILL.md +2 -0
- package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/workflow.md +27 -6
- package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/SKILL.md +9 -7
- package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/mcp-setup.md +12 -84
- package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/repository-analysis.md +5 -25
- package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-task-planning.md +5 -9
- package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-writing.md +8 -0
- package/dist/templates/common/bundled-skills/trellis-task-implementation/SKILL.md +2 -0
- package/dist/templates/common/bundled-skills/trellis-task-implementation/workflow.md +5 -3
- package/dist/templates/common/bundled-skills/trellis-teamwork/SKILL.md +8 -1
- package/dist/templates/common/bundled-skills/trellis-teamwork/references/teammate-processes.md +21 -1
- package/dist/templates/common/bundled-skills/trellis-teamwork/references/teamwork-plan-construction.md +13 -2
- package/dist/templates/common/bundled-skills/trellis-worktree-delegation/SKILL.md +14 -0
- package/dist/templates/common/bundled-skills/trellis-worktree-delegation/workflow.md +82 -0
- package/dist/templates/common/commands/continue.md +16 -1
- package/dist/templates/common/commands/start.md +2 -0
- package/dist/templates/common/skills/before-dev.md +3 -1
- package/dist/templates/common/skills/check.md +3 -1
- package/dist/templates/common/skills/request-intake.md +14 -1
- package/dist/templates/copilot/hooks/session-start.py +11 -30
- package/dist/templates/cursor/hooks.json +0 -7
- package/dist/templates/cursor/index.d.ts +1 -11
- package/dist/templates/cursor/index.d.ts.map +1 -1
- package/dist/templates/cursor/index.js +2 -10
- package/dist/templates/cursor/index.js.map +1 -1
- package/dist/templates/droid/index.d.ts +2 -3
- package/dist/templates/droid/index.d.ts.map +1 -1
- package/dist/templates/droid/index.js +2 -3
- package/dist/templates/droid/index.js.map +1 -1
- package/dist/templates/droid/settings.json +0 -10
- package/dist/templates/dsh/DSH.md +2 -33
- package/dist/templates/dsh/index.d.ts +1 -19
- package/dist/templates/dsh/index.d.ts.map +1 -1
- package/dist/templates/dsh/index.js +2 -21
- package/dist/templates/dsh/index.js.map +1 -1
- package/dist/templates/gemini/index.d.ts +1 -11
- package/dist/templates/gemini/index.d.ts.map +1 -1
- package/dist/templates/gemini/index.js +2 -10
- package/dist/templates/gemini/index.js.map +1 -1
- package/dist/templates/kiro/index.d.ts +1 -13
- package/dist/templates/kiro/index.d.ts.map +1 -1
- package/dist/templates/kiro/index.js +1 -13
- package/dist/templates/kiro/index.js.map +1 -1
- package/dist/templates/markdown/agents.md +9 -14
- package/dist/templates/markdown/index.d.ts +1 -0
- package/dist/templates/markdown/index.d.ts.map +1 -1
- package/dist/templates/markdown/index.js +1 -0
- package/dist/templates/markdown/index.js.map +1 -1
- package/dist/templates/markdown/spec/index.md.txt +20 -0
- package/dist/templates/omp/extensions/trellis/index.ts.txt +27 -60
- package/dist/templates/omp/index.d.ts +0 -2
- package/dist/templates/omp/index.d.ts.map +1 -1
- package/dist/templates/omp/index.js +1 -4
- package/dist/templates/omp/index.js.map +1 -1
- package/dist/templates/opencode/lib/session-utils.js +17 -5
- package/dist/templates/opencode/lib/trellis-context.js +12 -321
- package/dist/templates/opencode/plugins/inject-shell-session-context.js +93 -0
- package/dist/templates/opencode/plugins/inject-workflow-state.js +19 -17
- package/dist/templates/opencode/plugins/session-start.js +2 -6
- package/dist/templates/pi/extensions/trellis/index.ts.txt +17 -1436
- package/dist/templates/pi/index.d.ts +1 -2
- package/dist/templates/pi/index.d.ts.map +1 -1
- package/dist/templates/pi/index.js +2 -5
- package/dist/templates/pi/index.js.map +1 -1
- package/dist/templates/qoder/index.d.ts +2 -3
- package/dist/templates/qoder/index.d.ts.map +1 -1
- package/dist/templates/qoder/index.js +2 -3
- package/dist/templates/qoder/index.js.map +1 -1
- package/dist/templates/shared-hooks/guard-teamwork-wait.py +118 -12
- package/dist/templates/shared-hooks/index.d.ts +2 -56
- package/dist/templates/shared-hooks/index.d.ts.map +1 -1
- package/dist/templates/shared-hooks/index.js +4 -70
- package/dist/templates/shared-hooks/index.js.map +1 -1
- package/dist/templates/shared-hooks/inject-shell-session-context.py +27 -1
- package/dist/templates/shared-hooks/inject-spec-context.py +6 -35
- package/dist/templates/shared-hooks/inject-workflow-state.py +62 -104
- package/dist/templates/shared-hooks/session-start.py +8 -6
- package/dist/templates/snow/SNOW.md +6 -18
- package/dist/templates/snow/hooks/write-trellis-context.py +51 -133
- package/dist/templates/snow/index.d.ts +2 -21
- package/dist/templates/snow/index.d.ts.map +1 -1
- package/dist/templates/snow/index.js +3 -24
- package/dist/templates/snow/index.js.map +1 -1
- package/dist/templates/template-utils.d.ts +1 -2
- package/dist/templates/template-utils.d.ts.map +1 -1
- package/dist/templates/template-utils.js +1 -11
- package/dist/templates/template-utils.js.map +1 -1
- package/dist/templates/trae/index.d.ts +2 -3
- package/dist/templates/trae/index.d.ts.map +1 -1
- package/dist/templates/trae/index.js +2 -3
- package/dist/templates/trae/index.js.map +1 -1
- package/dist/templates/trellis/agents/delegated-worktree-primary-agent.md +22 -22
- package/dist/templates/trellis/agents/teammate.md +6 -2
- package/dist/templates/trellis/agents/worktree-delegation-node.md +30 -0
- package/dist/templates/trellis/config.yaml +7 -36
- package/dist/templates/trellis/gitignore.txt +4 -0
- package/dist/templates/trellis/index.d.ts +1 -0
- package/dist/templates/trellis/index.d.ts.map +1 -1
- package/dist/templates/trellis/index.js +9 -0
- package/dist/templates/trellis/index.js.map +1 -1
- package/dist/templates/trellis/scripts/common/active_task.py +23 -31
- package/dist/templates/trellis/scripts/common/config.py +16 -36
- package/dist/templates/trellis/scripts/common/git_context.py +13 -4
- package/dist/templates/trellis/scripts/common/io.py +2 -2
- package/dist/templates/trellis/scripts/common/markdown_format.py +107 -0
- package/dist/templates/trellis/scripts/common/packages_context.py +29 -1
- package/dist/templates/trellis/scripts/common/session_context.py +25 -50
- package/dist/templates/trellis/scripts/common/task_context.py +5 -3
- package/dist/templates/trellis/scripts/common/task_continuity.py +66 -9
- package/dist/templates/trellis/scripts/common/task_move.py +11 -5
- package/dist/templates/trellis/scripts/common/task_runtime.py +211 -0
- package/dist/templates/trellis/scripts/common/task_store.py +8 -78
- package/dist/templates/trellis/scripts/common/task_turn.py +514 -0
- package/dist/templates/trellis/scripts/common/task_workflow.py +380 -395
- package/dist/templates/trellis/scripts/common/workflow_phase.py +3 -36
- package/dist/templates/trellis/scripts/common/workflow_selection.py +35 -40
- package/dist/templates/trellis/scripts/common/worktree_delegation.py +690 -0
- package/dist/templates/trellis/scripts/common/worktree_delegation_contract.py +446 -0
- package/dist/templates/trellis/scripts/common/worktree_delegation_messages.py +376 -0
- package/dist/templates/trellis/scripts/common/worktree_delegation_transport.py +57 -0
- package/dist/templates/trellis/scripts/markdown_format.py +40 -0
- package/dist/templates/trellis/scripts/task.py +73 -10
- package/dist/templates/trellis/workflow.md +48 -9
- package/dist/templates/zcode/config.json +0 -10
- package/dist/templates/zcode/index.d.ts +3 -22
- package/dist/templates/zcode/index.d.ts.map +1 -1
- package/dist/templates/zcode/index.js +3 -24
- package/dist/templates/zcode/index.js.map +1 -1
- package/dist/types/ai-tools.d.ts +0 -4
- package/dist/types/ai-tools.d.ts.map +1 -1
- package/dist/types/ai-tools.js +4 -109
- package/dist/types/ai-tools.js.map +1 -1
- package/dist/utils/ablation-store.d.ts.map +1 -1
- package/dist/utils/ablation-store.js +41 -1
- package/dist/utils/ablation-store.js.map +1 -1
- package/dist/utils/asset-backup.d.ts +1 -0
- package/dist/utils/asset-backup.d.ts.map +1 -1
- package/dist/utils/asset-backup.js +131 -31
- package/dist/utils/asset-backup.js.map +1 -1
- package/dist/utils/atomic-write.d.ts +1 -1
- package/dist/utils/atomic-write.d.ts.map +1 -1
- package/dist/utils/atomic-write.js +8 -2
- package/dist/utils/atomic-write.js.map +1 -1
- package/dist/utils/codex-config-ownership.d.ts +13 -0
- package/dist/utils/codex-config-ownership.d.ts.map +1 -0
- package/dist/utils/codex-config-ownership.js +64 -0
- package/dist/utils/codex-config-ownership.js.map +1 -0
- package/dist/utils/file-writer.d.ts +2 -0
- package/dist/utils/file-writer.d.ts.map +1 -1
- package/dist/utils/file-writer.js +1 -1
- package/dist/utils/file-writer.js.map +1 -1
- package/dist/utils/managed-markdown.d.ts +5 -0
- package/dist/utils/managed-markdown.d.ts.map +1 -0
- package/dist/utils/managed-markdown.js +64 -0
- package/dist/utils/managed-markdown.js.map +1 -0
- package/dist/utils/managed-removal.d.ts +2 -0
- package/dist/utils/managed-removal.d.ts.map +1 -1
- package/dist/utils/managed-removal.js +62 -8
- package/dist/utils/managed-removal.js.map +1 -1
- package/dist/utils/manifest-prune.d.ts.map +1 -1
- package/dist/utils/manifest-prune.js +5 -12
- package/dist/utils/manifest-prune.js.map +1 -1
- package/dist/utils/project-init.d.ts +26 -0
- package/dist/utils/project-init.d.ts.map +1 -0
- package/dist/utils/project-init.js +484 -0
- package/dist/utils/project-init.js.map +1 -0
- package/dist/utils/retired-native-assets.d.ts +17 -0
- package/dist/utils/retired-native-assets.d.ts.map +1 -0
- package/dist/utils/retired-native-assets.js +221 -0
- package/dist/utils/retired-native-assets.js.map +1 -0
- package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
- package/dist/utils/uninstall-scrubbers.js +6 -12
- package/dist/utils/uninstall-scrubbers.js.map +1 -1
- package/package.json +2 -2
- package/dist/templates/claude/agents/trellis-check.md +0 -115
- package/dist/templates/claude/agents/trellis-implement.md +0 -110
- package/dist/templates/claude/agents/trellis-research.md +0 -137
- package/dist/templates/codebuddy/agents/trellis-check.md +0 -115
- package/dist/templates/codebuddy/agents/trellis-implement.md +0 -110
- package/dist/templates/codebuddy/agents/trellis-research.md +0 -137
- package/dist/templates/codex/agents/trellis-check.toml +0 -56
- package/dist/templates/codex/agents/trellis-implement.toml +0 -37
- package/dist/templates/codex/agents/trellis-research.toml +0 -78
- package/dist/templates/cursor/agents/trellis-check.md +0 -114
- package/dist/templates/cursor/agents/trellis-implement.md +0 -109
- package/dist/templates/cursor/agents/trellis-research.md +0 -136
- package/dist/templates/droid/droids/trellis-check.md +0 -107
- package/dist/templates/droid/droids/trellis-implement.md +0 -102
- package/dist/templates/droid/droids/trellis-research.md +0 -137
- package/dist/templates/dsh/agents/trellis-check.md +0 -99
- package/dist/templates/dsh/agents/trellis-implement.md +0 -106
- package/dist/templates/dsh/agents/trellis-research.md +0 -134
- package/dist/templates/gemini/agents/trellis-check.md +0 -107
- package/dist/templates/gemini/agents/trellis-implement.md +0 -102
- package/dist/templates/gemini/agents/trellis-research.md +0 -136
- package/dist/templates/grok/agents/trellis-check.md +0 -105
- package/dist/templates/grok/agents/trellis-implement.md +0 -116
- package/dist/templates/grok/agents/trellis-research.md +0 -146
- package/dist/templates/grok/index.d.ts +0 -16
- package/dist/templates/grok/index.d.ts.map +0 -1
- package/dist/templates/grok/index.js +0 -19
- package/dist/templates/grok/index.js.map +0 -1
- package/dist/templates/kimi/agents/trellis-check.md +0 -103
- package/dist/templates/kimi/agents/trellis-implement.md +0 -115
- package/dist/templates/kimi/agents/trellis-research.md +0 -144
- package/dist/templates/kimi/index.d.ts +0 -20
- package/dist/templates/kimi/index.d.ts.map +0 -1
- package/dist/templates/kimi/index.js +0 -23
- package/dist/templates/kimi/index.js.map +0 -1
- package/dist/templates/kiro/agents/trellis-check.json +0 -26
- package/dist/templates/kiro/agents/trellis-implement.json +0 -26
- package/dist/templates/kiro/agents/trellis-research.json +0 -30
- package/dist/templates/omp/agents/trellis-check.md +0 -41
- package/dist/templates/omp/agents/trellis-implement.md +0 -45
- package/dist/templates/omp/agents/trellis-research.md +0 -30
- package/dist/templates/opencode/agents/trellis-check.md +0 -122
- package/dist/templates/opencode/agents/trellis-implement.md +0 -118
- package/dist/templates/opencode/agents/trellis-research.md +0 -145
- package/dist/templates/opencode/plugins/inject-subagent-context.js +0 -569
- package/dist/templates/pi/agents/trellis-check.md +0 -37
- package/dist/templates/pi/agents/trellis-implement.md +0 -42
- package/dist/templates/pi/agents/trellis-research.md +0 -25
- package/dist/templates/qoder/agents/trellis-check.md +0 -108
- package/dist/templates/qoder/agents/trellis-implement.md +0 -103
- package/dist/templates/qoder/agents/trellis-research.md +0 -137
- package/dist/templates/reasonix/agents/trellis-check.md +0 -36
- package/dist/templates/reasonix/agents/trellis-implement.md +0 -41
- package/dist/templates/reasonix/index.d.ts +0 -13
- package/dist/templates/reasonix/index.d.ts.map +0 -1
- package/dist/templates/reasonix/index.js +0 -16
- package/dist/templates/reasonix/index.js.map +0 -1
- package/dist/templates/shared-hooks/inject-subagent-context.py +0 -1217
- package/dist/templates/snow/agents/trellis-check.md +0 -135
- package/dist/templates/snow/agents/trellis-implement.md +0 -153
- package/dist/templates/snow/agents/trellis-research.md +0 -114
- package/dist/templates/snow/hooks/beforeSubAgentStart.json +0 -15
- package/dist/templates/trae/agents/trellis-check.md +0 -108
- package/dist/templates/trae/agents/trellis-implement.md +0 -103
- package/dist/templates/trae/agents/trellis-research.md +0 -137
- package/dist/templates/zcode/agents/trellis-check.md +0 -109
- package/dist/templates/zcode/agents/trellis-implement.md +0 -111
- package/dist/templates/zcode/agents/trellis-research.md +0 -133
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
"""Versioned controller-only worktree delegation; Paseo owns native resources."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import contextlib
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import uuid
|
|
11
|
+
|
|
12
|
+
from .paths import get_repo_root
|
|
13
|
+
|
|
14
|
+
from . import worktree_delegation_contract as contract
|
|
15
|
+
from .worktree_delegation_contract import (
|
|
16
|
+
assert_worktree as assert_worktree,
|
|
17
|
+
attach_package as attach_package,
|
|
18
|
+
checkout_claim as checkout_claim,
|
|
19
|
+
clean_result as clean_result,
|
|
20
|
+
current as current,
|
|
21
|
+
digest as digest,
|
|
22
|
+
fail as fail,
|
|
23
|
+
file_ref as file_ref,
|
|
24
|
+
freeze as freeze,
|
|
25
|
+
git as git,
|
|
26
|
+
git_paths as git_paths,
|
|
27
|
+
identity as identity,
|
|
28
|
+
package_admission as package_admission,
|
|
29
|
+
read as read,
|
|
30
|
+
resolve_record as resolve_record,
|
|
31
|
+
reuse_source as reuse_source,
|
|
32
|
+
runtime_path as runtime_path,
|
|
33
|
+
save as save,
|
|
34
|
+
source_clean as source_clean,
|
|
35
|
+
task_inputs as task_inputs,
|
|
36
|
+
MAX_BYTES as MAX_BYTES,
|
|
37
|
+
SAFE_ID as SAFE_ID,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
from .worktree_delegation_transport import adapter as adapter, inspection_pages as inspection_pages
|
|
42
|
+
from .worktree_delegation_messages import (
|
|
43
|
+
agent_payload as agent_payload,
|
|
44
|
+
candidate as candidate,
|
|
45
|
+
candidate_input as candidate_input,
|
|
46
|
+
close_native as close_native,
|
|
47
|
+
native_lifecycle as native_lifecycle,
|
|
48
|
+
owner_takeover as owner_takeover,
|
|
49
|
+
projection as projection,
|
|
50
|
+
refresh_delivery as refresh_delivery,
|
|
51
|
+
send_input as send_input,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@contextlib.contextmanager
|
|
56
|
+
def controller_transaction(root: Path):
|
|
57
|
+
"""Release only the layout lock around RPC; durable intents remain authoritative."""
|
|
58
|
+
from .task_move import layout_lock, require_settled_layout
|
|
59
|
+
lock = layout_lock(root)
|
|
60
|
+
lock.__enter__()
|
|
61
|
+
|
|
62
|
+
def rpc(record, operation, payload):
|
|
63
|
+
nonlocal lock
|
|
64
|
+
path = runtime_path(root, record["control_task_name"])
|
|
65
|
+
safety = operation in {"inspect", "observe", "interrupt", "queue", "withdraw", "timeline",
|
|
66
|
+
"background", "stop-background", "archive-agent", "close-agent", "wait"}
|
|
67
|
+
from .task_workflow import _task_dir
|
|
68
|
+
child_dir = _task_dir(record["control_task_name"])
|
|
69
|
+
latest, _ = current(root, child_dir, require_authorization=not safety)
|
|
70
|
+
identity_keys = ("binding", "attempt_id", "workspace_id", "agent_id", "worktree_path")
|
|
71
|
+
if any(latest.get(key) != record.get(key) for key in identity_keys):
|
|
72
|
+
fail("controller mapping changed before RPC; do not overwrite it")
|
|
73
|
+
if not safety and latest.get("status") == "retired":
|
|
74
|
+
fail("retired package cannot allocate resources or send inputs")
|
|
75
|
+
if latest.get("cancel_requested"):
|
|
76
|
+
record["cancel_requested"] = True
|
|
77
|
+
if not safety and record.get("cancel_requested"):
|
|
78
|
+
fail("cancellation is pending; no additional business inputs may be sent")
|
|
79
|
+
expected = {key: record.get(key) for key in identity_keys}
|
|
80
|
+
save(path, record)
|
|
81
|
+
lock.__exit__(None, None, None)
|
|
82
|
+
lock = None
|
|
83
|
+
try:
|
|
84
|
+
observed = adapter(record, operation, payload)
|
|
85
|
+
finally:
|
|
86
|
+
lock = layout_lock(root)
|
|
87
|
+
lock.__enter__()
|
|
88
|
+
require_settled_layout(root)
|
|
89
|
+
latest = read(path)
|
|
90
|
+
if (any(latest.get(key) != value for key, value in expected.items())
|
|
91
|
+
or latest.get("status") == "retired" and record.get("status") != "retired"):
|
|
92
|
+
latest.setdefault("late_receipts", []).append({"operation": operation, "observation": observed})
|
|
93
|
+
save(path, latest)
|
|
94
|
+
fail("resource mapping changed during RPC; late receipt preserved without granting writes")
|
|
95
|
+
for key, value in latest.items():
|
|
96
|
+
if record.get(key) != value:
|
|
97
|
+
record[key] = value
|
|
98
|
+
record["last_rpc_receipt"] = {"operation": operation, "observation": observed}
|
|
99
|
+
save(path, record)
|
|
100
|
+
return observed
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
require_settled_layout(root)
|
|
104
|
+
yield rpc
|
|
105
|
+
finally:
|
|
106
|
+
if lock is not None:
|
|
107
|
+
lock.__exit__(None, None, None)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def prepare_agent(root: Path, child_dir: Path, record: dict, path: Path, *, rpc=None):
|
|
111
|
+
rpc = rpc or adapter
|
|
112
|
+
modern = record["binding"].get("format_version") == 3
|
|
113
|
+
if modern and not record.get("agent_id"):
|
|
114
|
+
record["agent_id"] = str(uuid.uuid4())
|
|
115
|
+
context = projection(root, child_dir, record, path)
|
|
116
|
+
role = Path(read(path.with_name("context.json"))["role_ref"]).read_text(encoding="utf8")
|
|
117
|
+
if role.startswith("---\n"):
|
|
118
|
+
role = role.split("\n---\n", 1)[1].lstrip("\n")
|
|
119
|
+
codegraph = "codegraph" in record["requirements"].get("required_tools", [])
|
|
120
|
+
tool = shutil.which("codegraph") if codegraph else None
|
|
121
|
+
if codegraph and not tool:
|
|
122
|
+
fail("required CodeGraph executable is unavailable to the controller")
|
|
123
|
+
tool_payload = {"codegraph_command": str(Path(tool).resolve(strict=True))} if tool else {}
|
|
124
|
+
record["intent"] = "prepare-agent"
|
|
125
|
+
save(path, record)
|
|
126
|
+
creation = {"agent_id": record["agent_id"]} if modern else {"prompt": f"prepare:读取 {context},只准备并提交 ready.json;当前 agent_id 映射由主控落盘,身份不完整时只报告阻断。"}
|
|
127
|
+
agent = rpc(record, "prepare-agent", {"workspace_id": record["workspace_id"], "cwd": record["worktree_path"], "model": record["settings"]["model"], "effort": record["settings"]["effort"], "role": role, "context": str(context), **creation, "codegraph": codegraph, **tool_payload, "labels": {"trellis.control": record["control_project_id"], "trellis.child": record["binding"]["child_task_id"], "trellis.attempt": record["attempt_id"]}})["agent"]
|
|
128
|
+
if not agent or not agent.get("id") or agent.get("workspaceId") != record["workspace_id"]:
|
|
129
|
+
fail("agent creation outcome unknown; preserve intent")
|
|
130
|
+
if modern and agent["id"] != record["agent_id"]:
|
|
131
|
+
fail("created agent does not match its preallocated identity")
|
|
132
|
+
record.update({"agent_id": agent["id"], "status": "running", "intent": None})
|
|
133
|
+
save(path, record)
|
|
134
|
+
projection(root, child_dir, record, path)
|
|
135
|
+
if modern:
|
|
136
|
+
if record.get("cancel_requested"):
|
|
137
|
+
close_native(record, path, cancel=True, rpc=rpc)
|
|
138
|
+
else:
|
|
139
|
+
send_input(root, child_dir, record, path, "prepare", rpc=rpc)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def recover(root: Path, child_dir: Path, record: dict, path: Path, args, *, rpc=None):
|
|
143
|
+
rpc = rpc or adapter
|
|
144
|
+
modern = record["binding"].get("format_version") == 3
|
|
145
|
+
if not record.get("attempt_id") or (not record.get("intent") and not modern):
|
|
146
|
+
fail("recovery requires an unresolved attempt intent")
|
|
147
|
+
workspace_id = args.workspace_id or record.get("workspace_id")
|
|
148
|
+
if not workspace_id:
|
|
149
|
+
fail("explicit native workspace-id required; inspect native resources first")
|
|
150
|
+
agent_id = args.agent_id or record.get("agent_id")
|
|
151
|
+
payload = {"target": record["binding"]["target_locator"], "workspace_id": workspace_id}
|
|
152
|
+
if agent_id:
|
|
153
|
+
observed = rpc(record, "inspect", {**payload, "agent_id": agent_id})
|
|
154
|
+
else:
|
|
155
|
+
observed = None
|
|
156
|
+
found = []
|
|
157
|
+
for page in inspection_pages(record, payload, rpc=rpc):
|
|
158
|
+
if observed is None:
|
|
159
|
+
observed = {key: value for key, value in page.items() if key not in {"agents", "page_info"}}
|
|
160
|
+
found.extend(a for a in page["agents"] if a and a.get("labels", {}).get("trellis.attempt") == record["attempt_id"])
|
|
161
|
+
if observed is None:
|
|
162
|
+
fail("native inspection returned no complete page")
|
|
163
|
+
observed["agents"] = found
|
|
164
|
+
spaces = observed.get("workspaces", [])
|
|
165
|
+
if len(spaces) != 1 or spaces[0].get("id") != workspace_id or not spaces[0].get("workspaceDirectory"):
|
|
166
|
+
fail("native workspace identity is unverified")
|
|
167
|
+
adopted = {**record, "workspace_id": workspace_id, "worktree_path": str(Path(spaces[0]["workspaceDirectory"]).resolve())}
|
|
168
|
+
if not modern:
|
|
169
|
+
assert_worktree(adopted)
|
|
170
|
+
if record.get("workspace_id") and (record["workspace_id"] != workspace_id or record["worktree_path"] != adopted["worktree_path"]):
|
|
171
|
+
fail("recovery cannot switch existing workspace mappings")
|
|
172
|
+
if agent_id:
|
|
173
|
+
agents = [a for a in observed.get("agents", []) if a and a.get("id") == agent_id]
|
|
174
|
+
if len(agents) != 1:
|
|
175
|
+
fail("exact native agent-id not found; no fuzzy or prefix adoption")
|
|
176
|
+
agent = agents[0]
|
|
177
|
+
if agent.get("workspaceId") != workspace_id or Path(agent.get("cwd", "")).resolve() != Path(adopted["worktree_path"]) or agent.get("labels", {}).get("trellis.attempt") != record["attempt_id"] or agent.get("labels", {}).get("trellis.control") != record["control_project_id"]:
|
|
178
|
+
fail("native agent labels/workspace/cwd do not match the pending attempt")
|
|
179
|
+
if record.get("agent_id") and record["agent_id"] != agent_id:
|
|
180
|
+
fail("recovery cannot replace an existing agent")
|
|
181
|
+
adopted.update({"agent_id": agent_id, "status": "running"})
|
|
182
|
+
elif record["intent"] == "prepare-agent" and args.delivery_evidence_ref:
|
|
183
|
+
if any(a and a.get("labels", {}).get("trellis.attempt") == record["attempt_id"] for a in observed.get("agents", [])):
|
|
184
|
+
fail("native attempt agent exists; map its exact ID instead of asserting absence")
|
|
185
|
+
file_ref(child_dir, args.delivery_evidence_ref)
|
|
186
|
+
adopted["status"] = "workspace_created"
|
|
187
|
+
elif record["intent"] != "prepare-workspace":
|
|
188
|
+
fail("unknown agent creation must be mapped before any new agent is created")
|
|
189
|
+
else:
|
|
190
|
+
adopted["status"] = "workspace_created"
|
|
191
|
+
evidence = {"observation": observed, "intent": record.get("intent")}
|
|
192
|
+
if modern:
|
|
193
|
+
if record.get("status") == "retired":
|
|
194
|
+
adopted.update({"status": "retired", "execution_permission": "none"})
|
|
195
|
+
if not agent_id:
|
|
196
|
+
fail("modern recovery requires the exact preallocated native agent identity")
|
|
197
|
+
if not args.execute:
|
|
198
|
+
return {"status": "ready", "recovery": evidence, "adopted": adopted}
|
|
199
|
+
if not args.reason or not args.approval_ref:
|
|
200
|
+
fail("explicit recovery reason and existing approval reference required")
|
|
201
|
+
if record.get("daemon_identity") != observed.get("identity"):
|
|
202
|
+
adopted.setdefault("instance_history", []).append(record.get("daemon_identity"))
|
|
203
|
+
adopted["daemon_identity"] = observed["identity"]
|
|
204
|
+
adopted.setdefault("recovery_receipts", []).append({**evidence, "reason": args.reason,
|
|
205
|
+
"approval_ref": args.approval_ref})
|
|
206
|
+
save(path, adopted)
|
|
207
|
+
if record.get("intent") == "send_pending":
|
|
208
|
+
refresh_delivery(adopted, path, rpc=rpc)
|
|
209
|
+
message_id = record["send_pending"]["client_message_id"]
|
|
210
|
+
item = next(item for item in adopted.get("inputs", []) if item["id"] == message_id)
|
|
211
|
+
if item.get("delivery") not in {"queued", "consumed", "withdrawn"}:
|
|
212
|
+
fail("unknown send remains unproven; do not replay or erase the intent")
|
|
213
|
+
elif record.get("intent") not in {None, "prepare-agent", "prepare-workspace", "reuse-agent"}:
|
|
214
|
+
fail("native stopping intent requires queue/background closure, not delivery assertions")
|
|
215
|
+
adopted["intent"] = None
|
|
216
|
+
adopted.pop("send_pending", None)
|
|
217
|
+
save(path, adopted)
|
|
218
|
+
projection(root, child_dir, adopted, path)
|
|
219
|
+
return adopted
|
|
220
|
+
if record["intent"] in {"send_pending", "interrupt_pending", "prepare-agent"} and (not agent_id or record["intent"] != "prepare-agent"):
|
|
221
|
+
if not args.delivery_evidence_ref:
|
|
222
|
+
fail("controller-owned native delivery/interrupt evidence required; idle alone cannot resolve unknown delivery")
|
|
223
|
+
evidence["delivery_evidence"] = file_ref(child_dir, args.delivery_evidence_ref).read_text(encoding="utf8")
|
|
224
|
+
if not args.execute:
|
|
225
|
+
return {"status": "ready", "recovery": evidence, "adopted": adopted}
|
|
226
|
+
if not args.reason or not args.approval_ref:
|
|
227
|
+
fail("explicit recovery reason and existing approval reference required")
|
|
228
|
+
adopted.setdefault("recovery_receipts", []).append({**evidence, "reason": args.reason, "approval_ref": args.approval_ref})
|
|
229
|
+
adopted["intent"] = None
|
|
230
|
+
save(path, adopted)
|
|
231
|
+
projection(root, child_dir, adopted, path)
|
|
232
|
+
return adopted
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def wait_for_node(args):
|
|
236
|
+
from .task_workflow import _task_dir, _task_lock
|
|
237
|
+
from .task_move import layout_lock, require_settled_layout
|
|
238
|
+
root = get_repo_root().resolve()
|
|
239
|
+
with controller_transaction(root) as rpc:
|
|
240
|
+
child_dir = _task_dir(args.child_task)
|
|
241
|
+
record_path = runtime_path(root, child_dir.name)
|
|
242
|
+
if record_path.exists() and read(record_path)["binding"].get("format_version") == 3:
|
|
243
|
+
record, path = current(root, child_dir, require_authorization=False)
|
|
244
|
+
record["control_task_name"] = child_dir.name
|
|
245
|
+
if not record.get("agent_id") or record["status"] == "retired":
|
|
246
|
+
fail("wait requires a current mapped agent")
|
|
247
|
+
observed = rpc(record, "wait", {**agent_payload(record), "timeout_ms": args.timeout_ms})
|
|
248
|
+
refresh_delivery(record, path, rpc=rpc)
|
|
249
|
+
ready = candidate(record, "ready", current_head=False)
|
|
250
|
+
if (ready and ready.get("missing") == [] and not record.get("intent")
|
|
251
|
+
and not record.get("cancel_requested")
|
|
252
|
+
and not any(item["stage"] != "prepare" for item in record.get("inputs", []))):
|
|
253
|
+
send_input(root, child_dir, record, path, "execute", rpc=rpc)
|
|
254
|
+
reports = {kind: candidate(record, kind, current_head=False) for kind in ("ready", "result", "blocked")}
|
|
255
|
+
print(json.dumps({"record": record, "observations": observed, "candidates": reports}, ensure_ascii=False))
|
|
256
|
+
return 0
|
|
257
|
+
with layout_lock(root):
|
|
258
|
+
require_settled_layout(root)
|
|
259
|
+
child_dir = _task_dir(args.child_task)
|
|
260
|
+
with _task_lock(child_dir):
|
|
261
|
+
contract.task_inputs(child_dir)
|
|
262
|
+
record, _ = current(root, child_dir)
|
|
263
|
+
if not record.get("agent_id") or record["status"] == "retired":
|
|
264
|
+
fail("wait requires a current mapped agent")
|
|
265
|
+
# Long native waits must leave the controller free to inspect or interrupt.
|
|
266
|
+
observations = adapter(record, "wait", {"agent_id": record["agent_id"], "cwd": record["worktree_path"], "timeout_ms": args.timeout_ms})
|
|
267
|
+
with layout_lock(root):
|
|
268
|
+
require_settled_layout(root)
|
|
269
|
+
child_dir = _task_dir(args.child_task)
|
|
270
|
+
with _task_lock(child_dir):
|
|
271
|
+
contract.task_inputs(child_dir)
|
|
272
|
+
latest, _ = current(root, child_dir)
|
|
273
|
+
if any(latest.get(k) != record.get(k) for k in ["binding", "attempt_id", "agent_id", "workspace_id", "worktree_path"]) or latest["status"] == "retired":
|
|
274
|
+
fail("wait target changed; inspect current binding instead of using stale observations")
|
|
275
|
+
reports = {name: candidate(latest, name, current_head=False) for name in ["ready", "result", "blocked"]}
|
|
276
|
+
print(json.dumps({"record": latest, "observations": observations, "candidates": reports}, ensure_ascii=False))
|
|
277
|
+
return 0
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def run(args):
|
|
281
|
+
from .task_workflow import _task_dir
|
|
282
|
+
root = get_repo_root().resolve()
|
|
283
|
+
with controller_transaction(root) as rpc:
|
|
284
|
+
child_dir = _task_dir(args.child_task)
|
|
285
|
+
path = runtime_path(root, child_dir.name)
|
|
286
|
+
operation = args.command.removeprefix("delegate-")
|
|
287
|
+
if operation == "inspect":
|
|
288
|
+
from .task_workflow import _load
|
|
289
|
+
|
|
290
|
+
child, _ = _load(child_dir)
|
|
291
|
+
if child.get("status") in {"completed", "cancelled"} and not path.exists():
|
|
292
|
+
record = resolve_record(root, child_dir, child)
|
|
293
|
+
print(json.dumps({"record": record, "historical": True,
|
|
294
|
+
"observations": {}, "candidates": {}}, ensure_ascii=False))
|
|
295
|
+
return 0
|
|
296
|
+
if operation == "bind":
|
|
297
|
+
if getattr(args, "result_path", None):
|
|
298
|
+
fail("legacy --result-path cannot start protocol v1; reconcile old attempts first")
|
|
299
|
+
child, _, _, _ = contract.task_inputs(child_dir)
|
|
300
|
+
previous = resolve_record(root, child_dir, child)
|
|
301
|
+
if previous and previous.get("status") != "retired":
|
|
302
|
+
fail("an existing attempt is not retired; inspect/reconcile instead of rebinding")
|
|
303
|
+
if not args.target_repo or not args.integration_branch or not args.settings_ref or not args.requirements_ref:
|
|
304
|
+
fail("explicit --target-repo, --integration-branch, --settings-ref and --requirements-ref required")
|
|
305
|
+
record = freeze(root, child_dir, Path(args.target_repo).resolve(), child.get("branch"), args.integration_branch, args.settings_ref, args.requirements_ref,
|
|
306
|
+
target_mode=getattr(args, "target_mode", "worktree"))
|
|
307
|
+
attach_package(child_dir, record, args.package_ref, getattr(args, "package_id", None))
|
|
308
|
+
if getattr(args, "reuse_task", None):
|
|
309
|
+
source, source_path = reuse_source(root, args.reuse_task, record)
|
|
310
|
+
record["reuse_source"] = {"task": args.reuse_task, "record_ref": str(source_path),
|
|
311
|
+
"attempt_id": source["attempt_id"],
|
|
312
|
+
"binding_revision": source["binding"]["binding_revision"]}
|
|
313
|
+
record.update({"status": "bound", "control_project_id": digest(str(root).encode()), "execution_permission": "preparation"})
|
|
314
|
+
if previous:
|
|
315
|
+
previous_id = previous.get("attempt_id") or previous["binding"]["binding_revision"]
|
|
316
|
+
save(path.with_name(f"retired-{previous_id}.json"), previous)
|
|
317
|
+
record["control_task_name"] = child_dir.name
|
|
318
|
+
save(path, record)
|
|
319
|
+
else:
|
|
320
|
+
safety_control = operation in {"inspect", "observe", "interrupt"} or (operation == "reconcile" and (args.recover or args.disposition == "retained"))
|
|
321
|
+
_, _, state, _ = contract.task_inputs(child_dir, require_authorization=not safety_control)
|
|
322
|
+
if operation == "start":
|
|
323
|
+
admission = state.get("route_dependency_admission") or {}
|
|
324
|
+
if admission.get("admission_state") != "ready":
|
|
325
|
+
from .task_workflow import TaskWorkflowError
|
|
326
|
+
raise TaskWorkflowError("TASK_DELEGATE_ADMISSION_REQUIRED", "current route dependency admission is not ready")
|
|
327
|
+
record, path = current(root, child_dir, require_authorization=not safety_control)
|
|
328
|
+
record["control_task_name"] = child_dir.name
|
|
329
|
+
b = record["binding"]
|
|
330
|
+
if operation == "start":
|
|
331
|
+
if record.get("cancel_requested") or record.get("quarantined"):
|
|
332
|
+
fail("cancelled preparation cannot resume; close and retain its existing resources")
|
|
333
|
+
if b.get("format_version") != 3:
|
|
334
|
+
fail("legacy attempts support safe observation/closeout only; retire before a new approved binding")
|
|
335
|
+
if record["status"] == "running" and record.get("agent_id") and not record.get("intent"):
|
|
336
|
+
package_admission(root, child_dir, record, path)
|
|
337
|
+
if not record.get("inputs"):
|
|
338
|
+
send_input(root, child_dir, record, path, "prepare", rpc=rpc)
|
|
339
|
+
else:
|
|
340
|
+
refresh_delivery(record, path, rpc=rpc)
|
|
341
|
+
ready = candidate(record, "ready")
|
|
342
|
+
if ready and ready.get("missing") == [] and not any(item["stage"] != "prepare" for item in record["inputs"]):
|
|
343
|
+
send_input(root, child_dir, record, path, "execute", rpc=rpc)
|
|
344
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
345
|
+
return 0
|
|
346
|
+
if record["status"] == "workspace_created" and not record.get("intent"):
|
|
347
|
+
assert_worktree(record)
|
|
348
|
+
package_admission(root, child_dir, record, path)
|
|
349
|
+
prepare_agent(root, child_dir, record, path, rpc=rpc)
|
|
350
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
351
|
+
return 0
|
|
352
|
+
if record["status"] != "bound":
|
|
353
|
+
fail("attempt already exists; use inspect/observe/reconcile without creating another writer")
|
|
354
|
+
_, _, state, _ = contract.task_inputs(child_dir)
|
|
355
|
+
admission = state.get("route_dependency_admission") or {}
|
|
356
|
+
if admission.get("admission_state") != "ready" or admission.get("task_route_revision") != state["task_route_revision"] or not admission.get("evidence_refs") or not {"pennix-lifecycle", "paseo", "git"}.issubset(admission.get("dependencies", [])):
|
|
357
|
+
fail("current evidenced Lifecycle/Paseo/Git admission is required")
|
|
358
|
+
package_admission(root, child_dir, record, path, allocate=True)
|
|
359
|
+
observed = rpc(record, "capability", {"cwd": b["target_locator"]})
|
|
360
|
+
record["daemon_identity"] = observed["identity"]
|
|
361
|
+
if observed.get("features") != {"queue": True, "queue_management": True, "background_work": True, "runtime_close": True}:
|
|
362
|
+
fail("native queue, withdrawal, background-work and runtime-only close capabilities are required")
|
|
363
|
+
models = observed.get("models", [])
|
|
364
|
+
modes = observed.get("modes", [])
|
|
365
|
+
if isinstance(models, dict):
|
|
366
|
+
models = models.get("models", [])
|
|
367
|
+
if isinstance(modes, dict):
|
|
368
|
+
modes = modes.get("modes", [])
|
|
369
|
+
selected = next((m for m in models if m.get("id") == record["settings"]["model"]), None)
|
|
370
|
+
if not selected or not any(m.get("id") == "full-access" for m in modes):
|
|
371
|
+
fail("requested Codex model/full-access mode is not available")
|
|
372
|
+
options = selected.get("thinkingOptions", [])
|
|
373
|
+
if not any(o.get("id") == record["settings"]["effort"] for o in options):
|
|
374
|
+
fail("requested effort is not supported by the selected model")
|
|
375
|
+
for existing in inspection_pages(record, {"target": b["target_locator"]}, rpc=rpc):
|
|
376
|
+
if existing.get("lifecycle", {}).get("autoArchiveAfterMerge") is not False:
|
|
377
|
+
fail("native autoArchiveAfterMerge must be explicitly disabled before delegation; preserve worktrees until owner closeout")
|
|
378
|
+
for agent in existing["agents"]:
|
|
379
|
+
if agent and agent.get("status") != "closed" and agent.get("cwd") and Path(agent["cwd"]).exists() and identity(Path(agent["cwd"]))["common_dir"] == record["target_identity"]["common_dir"] and git(Path(agent["cwd"]), "branch", "--show-current") == b["execution_branch"]:
|
|
380
|
+
fail("another target writer is active; reconcile before starting")
|
|
381
|
+
if b.get("target_mode") != "directory" and not record.get("reuse_source") and subprocess.run(["git", "show-ref", "--verify", "--quiet", f"refs/heads/{b['execution_branch']}"], cwd=b["target_locator"]).returncode != 1:
|
|
382
|
+
fail("execution branch already exists; do not create or reset it")
|
|
383
|
+
for other in (root / ".trellis/.runtime/delegation").glob("*/record.json"):
|
|
384
|
+
if other != path:
|
|
385
|
+
item = read(other)
|
|
386
|
+
if item.get("target_identity") == record["target_identity"] and item.get("binding", {}).get("execution_branch") == b["execution_branch"] and item.get("status") not in {"bound", "retired"}:
|
|
387
|
+
fail("another controller record owns this target branch")
|
|
388
|
+
record.update({"attempt_id": uuid.uuid4().hex, "status": "starting", "intent": "prepare-workspace"})
|
|
389
|
+
if record.get("reuse_source"):
|
|
390
|
+
reference = record["reuse_source"]
|
|
391
|
+
source, source_path = reuse_source(root, reference["task"], record)
|
|
392
|
+
if (str(source_path) != reference["record_ref"] or source["attempt_id"] != reference["attempt_id"]
|
|
393
|
+
or source["binding"]["binding_revision"] != reference["binding_revision"]):
|
|
394
|
+
fail("previous accepted package changed after the explicit reuse binding")
|
|
395
|
+
record.update({"agent_id": source["agent_id"], "workspace_id": source["workspace_id"],
|
|
396
|
+
"worktree_path": source["worktree_path"], "intent": "reuse-agent"})
|
|
397
|
+
if git(Path(record["worktree_path"]), "rev-parse", "HEAD") != b["base_commit"]:
|
|
398
|
+
fail("reused checkout is not at the new approved starting HEAD")
|
|
399
|
+
source_clean(record, path)
|
|
400
|
+
checkout_claim(record, path)
|
|
401
|
+
save(path, record)
|
|
402
|
+
source["reused_by"] = {"record_ref": str(path), "attempt_id": record["attempt_id"],
|
|
403
|
+
"binding_revision": b["binding_revision"]}
|
|
404
|
+
save(source_path, source)
|
|
405
|
+
projection(root, child_dir, record, path)
|
|
406
|
+
agent = rpc(record, "reuse-agent", {**agent_payload(record), "workspace_id": record["workspace_id"],
|
|
407
|
+
"previous_attempt_id": reference["attempt_id"],
|
|
408
|
+
"model": record["settings"]["model"], "effort": record["settings"]["effort"],
|
|
409
|
+
"labels": {"trellis.control": record["control_project_id"], "trellis.child": b["child_task_id"],
|
|
410
|
+
"trellis.attempt": record["attempt_id"]}})["agent"]
|
|
411
|
+
if agent.get("id") != record["agent_id"] or agent.get("workspaceId") != record["workspace_id"]:
|
|
412
|
+
fail("native reuse outcome is unknown; preserve the new binding and intent")
|
|
413
|
+
record.update({"status": "running", "intent": None})
|
|
414
|
+
save(path, record)
|
|
415
|
+
send_input(root, child_dir, record, path, "prepare", rpc=rpc)
|
|
416
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
417
|
+
return 0
|
|
418
|
+
if b.get("target_mode") == "directory":
|
|
419
|
+
tree = Path(b["target_locator"])
|
|
420
|
+
if git(tree, "rev-parse", "HEAD") != b["base_commit"]:
|
|
421
|
+
fail("directory entry requires the exact approved HEAD")
|
|
422
|
+
source_clean(record, path)
|
|
423
|
+
checkout_claim(record, path)
|
|
424
|
+
save(path, record)
|
|
425
|
+
workspace = rpc(record, "prepare-workspace", {"target": b["target_locator"], "target_mode": b.get("target_mode", "worktree"), "branch": b["execution_branch"], "base_commit": b["base_commit"], "title": f"trellis-{record['attempt_id']}"})["workspace"]
|
|
426
|
+
if not isinstance(workspace, dict) or not workspace.get("id") or not workspace.get("workspaceDirectory"):
|
|
427
|
+
fail("workspace creation outcome unknown; preserve intent")
|
|
428
|
+
record.update({"workspace_id": workspace["id"], "worktree_path": str(Path(workspace["workspaceDirectory"]).resolve()),
|
|
429
|
+
"status": "workspace_created", "intent": None})
|
|
430
|
+
save(path, record)
|
|
431
|
+
assert_worktree(record)
|
|
432
|
+
if b.get("target_mode") != "directory":
|
|
433
|
+
checkout_claim(record, path)
|
|
434
|
+
save(path, record)
|
|
435
|
+
if record.get("cancel_requested"):
|
|
436
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
437
|
+
return 0
|
|
438
|
+
package_admission(root, child_dir, record, path)
|
|
439
|
+
prepare_agent(root, child_dir, record, path, rpc=rpc)
|
|
440
|
+
elif operation in {"inspect", "observe", "interrupt"}:
|
|
441
|
+
if b.get("format_version") == 3 and operation == "interrupt":
|
|
442
|
+
if not record.get("agent_id") or record.get("intent") in {"prepare-workspace", "prepare-agent"}:
|
|
443
|
+
if record.get("intent"):
|
|
444
|
+
record.update({"cancel_requested": True, "quarantined": True, "execution_permission": "none"})
|
|
445
|
+
save(path, record)
|
|
446
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
447
|
+
return 0
|
|
448
|
+
fail("no mapped agent to interrupt; retain an unstarted binding")
|
|
449
|
+
was_retired = record.get("status") == "retired"
|
|
450
|
+
if was_retired:
|
|
451
|
+
if record.get("reused_by"):
|
|
452
|
+
fail("native Agent was transferred to another approved package; use its current owner")
|
|
453
|
+
observed = rpc(record, "inspect", {"agent_id": record["agent_id"]})
|
|
454
|
+
matches = [agent for agent in observed.get("agents", []) if agent.get("id") == record["agent_id"]]
|
|
455
|
+
if (len(matches) != 1 or matches[0].get("labels", {}).get("trellis.attempt") != record["attempt_id"]
|
|
456
|
+
or matches[0].get("labels", {}).get("trellis.control") != record["control_project_id"]):
|
|
457
|
+
fail("historical resource is no longer owned by this attempt")
|
|
458
|
+
checkout_claim(record, path)
|
|
459
|
+
record["closure_recheck_pending"] = True
|
|
460
|
+
save(path, record)
|
|
461
|
+
close_native(record, path, cancel=True, rpc=rpc)
|
|
462
|
+
if was_retired:
|
|
463
|
+
checkout_claim(record, path, release=True)
|
|
464
|
+
record["closure_evidence"]["native_closure"] = record["native_closure"]
|
|
465
|
+
record.pop("closure_recheck_pending", None)
|
|
466
|
+
save(path, record)
|
|
467
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
468
|
+
return 0
|
|
469
|
+
if operation == "interrupt":
|
|
470
|
+
if not record.get("agent_id"):
|
|
471
|
+
fail("no mapped agent to interrupt; retain an unstarted binding without creating a cancel intent")
|
|
472
|
+
if record.get("intent"):
|
|
473
|
+
fail("resolve prior intent before interrupt; native emergency cancellation remains available")
|
|
474
|
+
record["intent"] = "interrupt_pending"
|
|
475
|
+
save(path, record)
|
|
476
|
+
observations = rpc(record, "interrupt" if operation == "interrupt" else "observe" if record.get("agent_id") else "inspect", {"agent_id": record["agent_id"], "cwd": record["worktree_path"]} if record.get("agent_id") else {"target": b["target_locator"], **({"workspace_id": record["workspace_id"]} if record.get("workspace_id") else {})})
|
|
477
|
+
if operation == "interrupt":
|
|
478
|
+
record.setdefault("interrupt_receipts", []).append(observations)
|
|
479
|
+
record["intent"] = None
|
|
480
|
+
save(path, record)
|
|
481
|
+
if b.get("format_version") == 3 and record.get("agent_id"):
|
|
482
|
+
refresh_delivery(record, path, rpc=rpc)
|
|
483
|
+
reports = {name: candidate(record, name, current_head=False) for name in ["ready", "result", "blocked"]} if record.get("worktree_path") else {}
|
|
484
|
+
print(json.dumps({"record": record, "observations": observations, "candidates": reports}, ensure_ascii=False))
|
|
485
|
+
return 0
|
|
486
|
+
elif operation in {"execute", "followup"}:
|
|
487
|
+
if record.get("status") != "running" or not record.get("agent_id") or not record.get("workspace_id"):
|
|
488
|
+
fail("execute/followup requires a current running attempt; retired attempts cannot send")
|
|
489
|
+
if record.get("intent"):
|
|
490
|
+
fail("prior creation/send outcome unresolved; inspect and reconcile first")
|
|
491
|
+
if b.get("format_version") == 3:
|
|
492
|
+
refresh_delivery(record, path, rpc=rpc)
|
|
493
|
+
if operation == "execute":
|
|
494
|
+
if any(item["stage"] != "prepare" for item in record.get("inputs", [])):
|
|
495
|
+
fail("initial execution input already exists; use a new authorized followup")
|
|
496
|
+
source_clean(record, path)
|
|
497
|
+
instructions = file_ref(child_dir, args.instructions_ref).read_text(encoding="utf8") if operation == "followup" else ""
|
|
498
|
+
send_input(root, child_dir, record, path, operation, instructions, rpc=rpc)
|
|
499
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
500
|
+
return 0
|
|
501
|
+
fail("legacy inputs have no message-scoped contract; retain before rebinding")
|
|
502
|
+
elif operation == "reconcile":
|
|
503
|
+
if args.recover:
|
|
504
|
+
print(json.dumps(recover(root, child_dir, record, path, args, rpc=rpc), ensure_ascii=False))
|
|
505
|
+
return 0
|
|
506
|
+
if record.get("status") == "retired":
|
|
507
|
+
if b.get("format_version") == 3 and getattr(args, "owner_result_ref", None):
|
|
508
|
+
print(json.dumps(owner_takeover(record, path, child_dir, args, rpc=rpc), ensure_ascii=False))
|
|
509
|
+
return 0
|
|
510
|
+
legacy_refresh = (b.get("format_version") == 2 and args.disposition == "retained"
|
|
511
|
+
and record.get("agent_id")
|
|
512
|
+
and record.get("closure_evidence", {}).get("observation", {}).get("agent", {}).get("status") != "closed")
|
|
513
|
+
if not legacy_refresh:
|
|
514
|
+
print(json.dumps(record, ensure_ascii=False)); return 0
|
|
515
|
+
if record.get("status") == "bound" and not any(record.get(key) for key in ["intent", "attempt_id", "workspace_id", "agent_id"]):
|
|
516
|
+
if args.disposition != "retained":
|
|
517
|
+
fail("unstarted binding can only be retained, not accepted as integrated")
|
|
518
|
+
evidence = {"disposition": "retained", "resource_absent": True}
|
|
519
|
+
if not args.execute:
|
|
520
|
+
print(json.dumps({"status": "ready", "evidence": evidence}, ensure_ascii=False)); return 0
|
|
521
|
+
if not args.reason or not args.approval_ref:
|
|
522
|
+
fail("explicit reason and existing approval reference required")
|
|
523
|
+
record.update({"status": "retired", "closure_evidence": {**evidence, "reason": args.reason, "approval_ref": args.approval_ref}})
|
|
524
|
+
save(path, record)
|
|
525
|
+
print(json.dumps(record, ensure_ascii=False)); return 0
|
|
526
|
+
if record.get("intent"):
|
|
527
|
+
fail("unresolved native intent requires explicit recovery before retirement")
|
|
528
|
+
if not record.get("agent_id"):
|
|
529
|
+
if b.get("format_version") == 3 and args.disposition == "retained" and record.get("workspace_id"):
|
|
530
|
+
pages = 0
|
|
531
|
+
observed_identity = None
|
|
532
|
+
for page in inspection_pages(record, {"target": b["target_locator"],
|
|
533
|
+
"workspace_id": record["workspace_id"]}, rpc=rpc):
|
|
534
|
+
pages += 1
|
|
535
|
+
observed_identity = page["identity"]
|
|
536
|
+
if any(agent.get("labels", {}).get("trellis.attempt") == record["attempt_id"]
|
|
537
|
+
and agent.get("labels", {}).get("trellis.control") == record["control_project_id"]
|
|
538
|
+
for agent in page["agents"]):
|
|
539
|
+
fail("an attempt Agent exists; map its exact identity before resource closure")
|
|
540
|
+
tree = Path(record["worktree_path"])
|
|
541
|
+
evidence = {"disposition": "retained", "native_agent_absent": True,
|
|
542
|
+
"agent_scan": {"complete": True, "pages": pages, "identity": observed_identity},
|
|
543
|
+
"preserved_worktree": str(tree), "source_state": "present" if tree.exists() else "missing",
|
|
544
|
+
"head_commit": git(tree, "rev-parse", "HEAD") if tree.exists() else None,
|
|
545
|
+
"git_status": git(tree, "status", "--porcelain", "--untracked-files=all") if tree.exists() else None}
|
|
546
|
+
if not args.execute:
|
|
547
|
+
print(json.dumps({"status": "ready", "evidence": evidence}, ensure_ascii=False))
|
|
548
|
+
return 0
|
|
549
|
+
if not args.reason or not args.approval_ref or not args.writer_evidence_ref:
|
|
550
|
+
fail("workspace-only retention requires explicit approval and external-writer evidence")
|
|
551
|
+
evidence["writer_evidence"] = file_ref(child_dir, args.writer_evidence_ref).read_text(encoding="utf8")
|
|
552
|
+
checkout_claim(record, path, release=True)
|
|
553
|
+
record.update({"status": "retired", "closure_evidence": {**evidence, "reason": args.reason,
|
|
554
|
+
"approval_ref": args.approval_ref}})
|
|
555
|
+
save(path, record)
|
|
556
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
557
|
+
return 0
|
|
558
|
+
fail("partial creation requires explicit native resource mapping before retirement; preserve intent")
|
|
559
|
+
observation = rpc(record, "observe", {"agent_id": record["agent_id"], "cwd": record["worktree_path"]})
|
|
560
|
+
agent = observation["agent"]
|
|
561
|
+
if not agent or agent.get("activeTurn") or agent.get("status") not in {"idle", "closed"}:
|
|
562
|
+
fail("native writer is active or unknown")
|
|
563
|
+
if record.get("status") == "retired" and agent.get("status") != "closed":
|
|
564
|
+
fail("historical Agent must be closed natively before refreshing its closure evidence")
|
|
565
|
+
if b.get("format_version") == 3:
|
|
566
|
+
refresh_delivery(record, path, rpc=rpc)
|
|
567
|
+
if record["queue_evidence"]["items"]:
|
|
568
|
+
fail("queued inputs remain; finish or explicitly interrupt them before reconciliation")
|
|
569
|
+
if args.disposition == "integrated":
|
|
570
|
+
native_lifecycle(record, rpc=rpc)
|
|
571
|
+
if record.get("quarantined") or not record.get("inputs"):
|
|
572
|
+
fail("quarantined or inputless attempt cannot be accepted as integrated")
|
|
573
|
+
for item in record["inputs"]:
|
|
574
|
+
report = candidate(record, "ready" if item["stage"] == "prepare" else "result",
|
|
575
|
+
current_head=False, input_id=item["id"])
|
|
576
|
+
if not report:
|
|
577
|
+
fail("every consumed input batch needs its own candidate before acceptance")
|
|
578
|
+
if item["stage"] != "prepare":
|
|
579
|
+
git(Path(record["worktree_path"]), "merge-base", "--is-ancestor",
|
|
580
|
+
report["head_commit"], "HEAD")
|
|
581
|
+
clean_result(record, report, path)
|
|
582
|
+
result = candidate(record, "result") if args.disposition == "integrated" else None
|
|
583
|
+
if not result and args.disposition != "retained":
|
|
584
|
+
fail("bounded result and preserved source evidence required before retirement")
|
|
585
|
+
if result:
|
|
586
|
+
clean_result(record, result, path)
|
|
587
|
+
if result.get("remaining"):
|
|
588
|
+
fail("unresolved result work remains; retain or request an authorized followup")
|
|
589
|
+
if args.disposition == "integrated":
|
|
590
|
+
if result is None:
|
|
591
|
+
fail("integrated closure requires a result")
|
|
592
|
+
git(Path(b["target_locator"]), "merge-base", "--is-ancestor", result["head_commit"], b["integration_branch"])
|
|
593
|
+
tree = assert_worktree(record) if args.disposition == "integrated" else Path(record["worktree_path"])
|
|
594
|
+
if args.disposition == "retained" and tree.exists() and identity(tree)["common_dir"] != record["target_identity"]["common_dir"]:
|
|
595
|
+
fail("retained checkout belongs to a different Git repository; preserve the native mapping")
|
|
596
|
+
evidence = {"result": result, "observation": observation, "disposition": args.disposition,
|
|
597
|
+
"preserved_worktree": str(tree), "source_state": "present" if tree.exists() else "missing",
|
|
598
|
+
"head_commit": git(tree, "rev-parse", "HEAD") if tree.exists() else None,
|
|
599
|
+
"git_status": git(tree, "status", "--porcelain", "--untracked-files=all") if tree.exists() else None}
|
|
600
|
+
if b.get("format_version") == 3 and result:
|
|
601
|
+
evidence["acceptance_candidate"] = {"version": 1, "attempt_id": record["attempt_id"],
|
|
602
|
+
"binding_revision": b["binding_revision"],
|
|
603
|
+
"head_commit": result["head_commit"], "result_revision": digest(result)}
|
|
604
|
+
if not args.execute:
|
|
605
|
+
print(json.dumps({"status": "ready", "evidence": evidence}, ensure_ascii=False)); return 0
|
|
606
|
+
if not args.reason or not args.approval_ref or not args.writer_evidence_ref:
|
|
607
|
+
fail("reason, approval-ref and controller-owned writer-evidence-ref required; idle/cancel alone do not prove background writers stopped")
|
|
608
|
+
evidence["writer_evidence"] = file_ref(child_dir, args.writer_evidence_ref).read_text(encoding="utf8")
|
|
609
|
+
if record.get("status") == "retired":
|
|
610
|
+
record["prior_closure_evidence"] = record.get("closure_evidence")
|
|
611
|
+
record["prior_result_evidence"] = record.get("result_evidence")
|
|
612
|
+
if b.get("format_version") == 3:
|
|
613
|
+
owner_acceptance = None
|
|
614
|
+
if result:
|
|
615
|
+
acceptance_ref = getattr(args, "acceptance_ref", None)
|
|
616
|
+
acceptance = read(file_ref(child_dir, acceptance_ref))
|
|
617
|
+
expected = evidence["acceptance_candidate"]
|
|
618
|
+
if acceptance != expected:
|
|
619
|
+
fail("owner acceptance must identify the exact current result candidate")
|
|
620
|
+
owner_acceptance = {**expected, "source_commits": result["source_commits"],
|
|
621
|
+
"acceptance_ref": acceptance_ref}
|
|
622
|
+
evidence["native_closure"] = close_native(record, path, cancel=False, rpc=rpc)
|
|
623
|
+
if result:
|
|
624
|
+
final_result = candidate(record, "result")
|
|
625
|
+
if final_result != result:
|
|
626
|
+
fail("source candidate changed during native closure; preserve its claim for owner review")
|
|
627
|
+
clean_result(record, result, path)
|
|
628
|
+
git(Path(b["target_locator"]), "merge-base", "--is-ancestor",
|
|
629
|
+
result["head_commit"], b["integration_branch"])
|
|
630
|
+
if owner_acceptance is not None:
|
|
631
|
+
record["owner_acceptance"] = owner_acceptance
|
|
632
|
+
checkout_claim(record, path, release=True)
|
|
633
|
+
evidence["result_revision"] = digest(result) if result else None
|
|
634
|
+
evidence.pop("result", None)
|
|
635
|
+
record.update({"status": "retired", "intent": None, "result_evidence": result, "closure_evidence": {**evidence, "reason": args.reason, "approval_ref": args.approval_ref}})
|
|
636
|
+
save(path, record)
|
|
637
|
+
else:
|
|
638
|
+
fail("unsupported delegation operation")
|
|
639
|
+
print(json.dumps(record, ensure_ascii=False))
|
|
640
|
+
return 0
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
def node_context() -> dict | None:
|
|
644
|
+
raw = os.environ.get("TRELLIS_DELEGATION_CONTEXT")
|
|
645
|
+
if not raw:
|
|
646
|
+
return None
|
|
647
|
+
context = read(Path(raw))
|
|
648
|
+
if context.get("kind") == "delegation_agent_locator":
|
|
649
|
+
if context.get("version") != 1 or context.get("agent_id") != os.environ.get("PASEO_AGENT_ID"):
|
|
650
|
+
fail("stable agent locator does not match the native agent")
|
|
651
|
+
context = read(Path(context["context_ref"]))
|
|
652
|
+
record = read(Path(context["record_ref"]))
|
|
653
|
+
if context.get("version") not in {1, 2} or record.get("status") == "retired" or record.get("cancel_requested") or record.get("quarantined") or context.get("attempt_id") != record.get("attempt_id") or context.get("binding_revision") != record.get("binding", {}).get("binding_revision") or context.get("agent_id") != os.environ.get("PASEO_AGENT_ID") or not context.get("agent_id") or git(Path.cwd(), "rev-parse", "--show-toplevel") != str(Path(context.get("target", "")).resolve()):
|
|
654
|
+
fail("delegated context/resource/cwd is missing, stale or mismatched; do not enter ordinary controller workflow")
|
|
655
|
+
assert_worktree(record)
|
|
656
|
+
if context.get("execution_permission") != record.get("execution_permission") or context.get("binding") != record.get("binding") or context.get("target") != record.get("worktree_path"):
|
|
657
|
+
fail("delegated execution projection is stale")
|
|
658
|
+
from .task_utils import resolve_task_dir
|
|
659
|
+
control = resolve_task_dir(Path(context["control_task"]).name, Path(context["control_root"]))
|
|
660
|
+
if control is None:
|
|
661
|
+
fail("current delegated task is missing")
|
|
662
|
+
child = read(control / "task.json")
|
|
663
|
+
parent_dir = resolve_task_dir(child["parent"], Path(context["control_root"]))
|
|
664
|
+
if parent_dir is None:
|
|
665
|
+
fail("current parent task is missing")
|
|
666
|
+
parent = read(parent_dir / "task.json")
|
|
667
|
+
state = parent.get("meta", {}).get("task_workflow", {})
|
|
668
|
+
b = record["binding"]
|
|
669
|
+
auth = state.get("implementation_authorization") or {}
|
|
670
|
+
if parent.get("status") != "in_progress" or state.get("current_phase_id") != "task_implementation" or state.get("task_route_revision") != b["parent_route_revision"] or auth.get("contract_revision") != b["parent_contract_revision"]:
|
|
671
|
+
fail("parent authorization changed; stop delegated implementation")
|
|
672
|
+
from .task_workflow import implementation_start_ready
|
|
673
|
+
if not implementation_start_ready(parent, parent_dir):
|
|
674
|
+
fail("parent implementation contract is no longer current")
|
|
675
|
+
if b.get("format_version") not in {2, 3}:
|
|
676
|
+
fail("incomplete legacy binding; stop and ask the controller to retain/rebind")
|
|
677
|
+
inputs = [(control, "prd.md", "contract"), (control, b["settings_ref"], "settings"), (control, b["requirements_ref"], "requirements"), (Path(context["control_root"]), ".trellis/agents/delegated-worktree-primary-agent.md", "role"), (Path(context["control_root"]), ".trellis/agents/worktree-delegation-node.md", "node_method")]
|
|
678
|
+
if record["requirements"].get("setup_ref"):
|
|
679
|
+
inputs.append((control, record["requirements"]["setup_ref"], "setup"))
|
|
680
|
+
for directory, ref, name in inputs:
|
|
681
|
+
key = f"{name}_sha256"
|
|
682
|
+
if digest(file_ref(directory, ref).read_bytes()) != b[key]:
|
|
683
|
+
fail("delegated input changed; wait for controller revalidation")
|
|
684
|
+
if name not in {"settings", "requirements"}:
|
|
685
|
+
expected = Path(context["record_ref"]).parent / "inputs" / record["attempt_id"] / f"{name}.md"
|
|
686
|
+
if context.get(f"{name}_ref") != str(expected) or digest(file_ref(expected.parent, expected.name).read_bytes()) != b[key]:
|
|
687
|
+
fail("delegated frozen snapshot is missing, redirected or stale")
|
|
688
|
+
if context.get("requirements") != record["requirements"] or context.get("settings") != record["settings"]:
|
|
689
|
+
fail("delegated inline inputs are stale")
|
|
690
|
+
return context
|