@fitlab-ai/agent-infra 0.9.1 → 0.9.3
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 +24 -11
- package/README.zh-CN.md +24 -11
- package/bin/cli.ts +12 -0
- package/dist/bin/cli.js +14 -0
- package/dist/bin/internal-cli.js +30 -0
- package/dist/lib/agent-client.js +163 -0
- package/dist/lib/agent-clients/adapter.js +337 -0
- package/dist/lib/agent-clients/adapters/antigravity-cli.js +64 -0
- package/dist/lib/agent-clients/adapters/claude-code.js +71 -0
- package/dist/lib/agent-clients/adapters/codex-sandbox.js +210 -0
- package/dist/lib/agent-clients/adapters/codex.js +63 -0
- package/dist/lib/agent-clients/adapters/index.js +20 -0
- package/dist/lib/agent-clients/adapters/opencode.js +73 -0
- package/dist/lib/agent-clients/config.js +215 -0
- package/dist/lib/agent-clients/custom-tuis.js +99 -0
- package/dist/lib/agent-clients/invocation.js +9 -0
- package/dist/lib/agent-clients/next-steps.js +47 -0
- package/dist/lib/agent-clients/project-assets.js +45 -0
- package/dist/lib/agent-clients/reconcile.js +236 -0
- package/dist/lib/agent-clients/registry.js +78 -0
- package/dist/lib/agent-clients/schema.js +75 -0
- package/dist/lib/agent-clients/tokens.js +49 -0
- package/dist/lib/agent-clients/types.js +29 -0
- package/dist/lib/builtin-tuis.js +9 -14
- package/dist/lib/defaults.json +85 -73
- package/dist/lib/git/review-snapshot.js +25 -10
- package/dist/lib/git/reviewed-commit-equivalence.js +110 -0
- package/dist/lib/git/workflow.js +54 -1
- package/dist/lib/init.js +47 -91
- package/dist/lib/internal/agent-client.js +174 -0
- package/dist/lib/internal/git-workflow.js +7 -2
- package/dist/lib/internal/platform-checks.js +3 -3
- package/dist/lib/internal/platform-comment.js +29 -2
- package/dist/lib/internal/platform-issue.js +7 -0
- package/dist/lib/internal/platform-pr-review.js +132 -0
- package/dist/lib/internal/platform-pr.js +20 -2
- package/dist/lib/internal/platform-release-notes.js +52 -16
- package/dist/lib/internal/pr-review-grade.js +140 -0
- package/dist/lib/internal/release-workflow.js +82 -20
- package/dist/lib/internal/task-activity.js +73 -0
- package/dist/lib/internal/task-event.js +17 -1
- package/dist/lib/internal/task-lifecycle.js +7 -0
- package/dist/lib/internal/task-orchestration.js +196 -0
- package/dist/lib/internal/task-review.js +70 -0
- package/dist/lib/merge.js +2 -1
- package/dist/lib/platform/adapters.js +45 -1
- package/dist/lib/platform/change-request-git-evidence.js +113 -0
- package/dist/lib/platform/completion-backfill.js +122 -0
- package/dist/lib/platform/issue-comments.js +3 -2
- package/dist/lib/platform/merged-pr-equivalence.js +156 -16
- package/dist/lib/platform/pr-checks.js +101 -50
- package/dist/lib/platform/pr-review.js +166 -0
- package/dist/lib/platform/pull-requests.js +432 -7
- package/dist/lib/platform/release-notes.js +85 -3
- package/dist/lib/platform/releases.js +1 -1
- package/dist/lib/platform/verification-required.js +8 -10
- package/dist/lib/pr-review/evidence-grading.js +229 -0
- package/dist/lib/prompt.js +15 -3
- package/dist/lib/release/channels.js +4 -1
- package/dist/lib/release/workflow.js +4 -2
- package/dist/lib/remove-dir.js +25 -0
- package/dist/lib/run/tui.js +11 -7
- package/dist/lib/sandbox/agent-client-reconciler.js +234 -0
- package/dist/lib/sandbox/clipboard/linux.js +2 -1
- package/dist/lib/sandbox/commands/create.js +76 -200
- package/dist/lib/sandbox/commands/enter.js +17 -1
- package/dist/lib/sandbox/commands/prune.js +2 -2
- package/dist/lib/sandbox/commands/rm.js +3 -2
- package/dist/lib/sandbox/commands/show.js +1 -1
- package/dist/lib/sandbox/config.js +21 -4
- package/dist/lib/sandbox/constants.js +3 -0
- package/dist/lib/sandbox/dockerfile.js +2 -1
- package/dist/lib/sandbox/managed-fs.js +10 -5
- package/dist/lib/sandbox/recovery.js +52 -36
- package/dist/lib/sandbox/shell.js +1 -1
- package/dist/lib/sandbox/tool-types.js +8 -0
- package/dist/lib/sandbox/tools.js +2 -126
- package/dist/lib/task/activity-intent.js +101 -0
- package/dist/lib/task/artifact-lifecycle.js +3 -50
- package/dist/lib/task/commands/decisions.js +50 -20
- package/dist/lib/task/commands/log.js +15 -14
- package/dist/lib/task/delegation-receipts.js +128 -0
- package/dist/lib/task/events.js +146 -8
- package/dist/lib/task/finalization-artifacts.js +35 -0
- package/dist/lib/task/lifecycle-execution.js +46 -0
- package/dist/lib/task/orchestration.js +784 -0
- package/dist/lib/task/review-artifacts.js +143 -59
- package/dist/lib/task/review-finalization.js +186 -0
- package/dist/lib/task/review-fingerprint.js +4 -0
- package/dist/lib/task/task-execution-lock.js +231 -0
- package/dist/lib/task/verification-checks.js +2 -1
- package/dist/lib/task/verification-engine.js +372 -28
- package/dist/lib/task/verification-review.js +1 -1
- package/dist/lib/task/verification.js +5 -2
- package/dist/lib/task/workspace-snapshot.js +46 -0
- package/dist/lib/update.js +42 -161
- package/lib/agent-client.ts +214 -0
- package/lib/agent-clients/adapter.ts +534 -0
- package/lib/agent-clients/adapters/antigravity-cli.ts +65 -0
- package/lib/agent-clients/adapters/claude-code.ts +79 -0
- package/lib/agent-clients/adapters/codex-sandbox.ts +245 -0
- package/lib/agent-clients/adapters/codex.ts +67 -0
- package/lib/agent-clients/adapters/index.ts +27 -0
- package/lib/agent-clients/adapters/opencode.ts +75 -0
- package/lib/agent-clients/config.ts +323 -0
- package/lib/agent-clients/custom-tuis.ts +149 -0
- package/lib/agent-clients/invocation.ts +19 -0
- package/lib/agent-clients/next-steps.ts +85 -0
- package/lib/agent-clients/project-assets.ts +96 -0
- package/lib/agent-clients/reconcile.ts +325 -0
- package/lib/agent-clients/registry.ts +154 -0
- package/lib/agent-clients/schema.ts +80 -0
- package/lib/agent-clients/tokens.ts +53 -0
- package/lib/agent-clients/types.ts +92 -0
- package/lib/benchmark/schemas/v1.0.0/case-manifest.schema.json +120 -0
- package/lib/benchmark/schemas/v1.0.0/common.schema.json +109 -0
- package/lib/benchmark/schemas/v1.0.0/grader-result.schema.json +160 -0
- package/lib/benchmark/schemas/v1.0.0/run-manifest.schema.json +122 -0
- package/lib/benchmark/schemas/v1.0.0/subject.schema.json +227 -0
- package/lib/builtin-tuis.ts +16 -15
- package/lib/defaults.json +24 -12
- package/lib/git/review-snapshot.ts +39 -9
- package/lib/git/reviewed-commit-equivalence.ts +135 -0
- package/lib/git/workflow.ts +66 -2
- package/lib/init.ts +53 -121
- package/lib/internal/agent-client.ts +186 -0
- package/lib/internal/git-workflow.ts +6 -2
- package/lib/internal/platform-checks.ts +4 -4
- package/lib/internal/platform-comment.ts +17 -2
- package/lib/internal/platform-issue.ts +4 -0
- package/lib/internal/platform-pr-review.ts +104 -0
- package/lib/internal/platform-pr.ts +14 -1
- package/lib/internal/platform-release-notes.ts +59 -16
- package/lib/internal/pr-review-grade.ts +130 -0
- package/lib/internal/release-workflow.ts +79 -20
- package/lib/internal/task-activity.ts +55 -0
- package/lib/internal/task-event.ts +9 -1
- package/lib/internal/task-lifecycle.ts +4 -0
- package/lib/internal/task-orchestration.ts +171 -0
- package/lib/internal/task-review.ts +70 -0
- package/lib/merge.ts +2 -1
- package/lib/platform/adapters.ts +169 -3
- package/lib/platform/change-request-git-evidence.ts +159 -0
- package/lib/platform/completion-backfill.ts +134 -0
- package/lib/platform/issue-comments.ts +3 -2
- package/lib/platform/merged-pr-equivalence.ts +178 -19
- package/lib/platform/pr-checks.ts +121 -66
- package/lib/platform/pr-review.ts +201 -0
- package/lib/platform/pull-requests.ts +529 -27
- package/lib/platform/release-notes.ts +100 -4
- package/lib/platform/releases.ts +1 -1
- package/lib/platform/verification-required.ts +12 -10
- package/lib/pr-review/evidence-grading.ts +318 -0
- package/lib/prompt.ts +16 -3
- package/lib/release/channels.ts +4 -1
- package/lib/release/workflow.ts +4 -3
- package/lib/remove-dir.ts +28 -0
- package/lib/run/tui.ts +12 -5
- package/lib/sandbox/agent-client-reconciler.ts +378 -0
- package/lib/sandbox/clipboard/linux.ts +2 -1
- package/lib/sandbox/commands/create.ts +111 -212
- package/lib/sandbox/commands/enter.ts +23 -1
- package/lib/sandbox/commands/prune.ts +2 -2
- package/lib/sandbox/commands/rm.ts +3 -2
- package/lib/sandbox/commands/show.ts +1 -1
- package/lib/sandbox/config.ts +31 -4
- package/lib/sandbox/constants.ts +6 -0
- package/lib/sandbox/dockerfile.ts +2 -1
- package/lib/sandbox/managed-fs.ts +18 -5
- package/lib/sandbox/recovery.ts +98 -67
- package/lib/sandbox/shell.ts +1 -1
- package/lib/sandbox/tool-types.ts +143 -0
- package/lib/sandbox/tools.ts +5 -157
- package/lib/server/server.schema.json +2 -2
- package/lib/task/activity-intent.ts +128 -0
- package/lib/task/artifact-lifecycle.ts +3 -39
- package/lib/task/commands/decisions.ts +53 -20
- package/lib/task/commands/log.ts +15 -14
- package/lib/task/delegation-receipts.ts +199 -0
- package/lib/task/events.ts +164 -11
- package/lib/task/finalization-artifacts.ts +58 -0
- package/lib/task/lifecycle-execution.ts +106 -0
- package/lib/task/orchestration.ts +1022 -0
- package/lib/task/review-artifacts.ts +201 -69
- package/lib/task/review-finalization.ts +306 -0
- package/lib/task/review-fingerprint.ts +5 -0
- package/lib/task/task-execution-lock.ts +296 -0
- package/lib/task/verification-checks.ts +2 -1
- package/lib/task/verification-engine.ts +424 -28
- package/lib/task/verification-review.ts +1 -0
- package/lib/task/verification.ts +8 -3
- package/lib/task/workspace-snapshot.ts +57 -0
- package/lib/update.ts +48 -184
- package/package.json +4 -4
- package/templates/.agents/QUICKSTART.en.md +25 -8
- package/templates/.agents/QUICKSTART.zh-CN.md +25 -8
- package/templates/.agents/README.en.md +29 -25
- package/templates/.agents/README.zh-CN.md +29 -25
- package/templates/.agents/hooks/lifecycle-delegation.js +75 -0
- package/templates/.agents/rules/README.en.md +2 -0
- package/templates/.agents/rules/README.zh-CN.md +2 -0
- package/templates/.agents/rules/commit-and-pr.en.md +1 -0
- package/templates/.agents/rules/commit-and-pr.zh-CN.md +1 -0
- package/templates/.agents/rules/create-issue.github.en.md +4 -2
- package/templates/.agents/rules/create-issue.github.zh-CN.md +4 -2
- package/templates/.agents/rules/human-decision-context.en.md +14 -12
- package/templates/.agents/rules/human-decision-context.zh-CN.md +14 -12
- package/templates/.agents/rules/issue-fields.github.en.md +3 -1
- package/templates/.agents/rules/issue-fields.github.zh-CN.md +3 -1
- package/templates/.agents/rules/issue-pr-commands.en.md +5 -3
- package/templates/.agents/rules/issue-pr-commands.github.en.md +5 -3
- package/templates/.agents/rules/issue-pr-commands.github.zh-CN.md +5 -3
- package/templates/.agents/rules/issue-pr-commands.zh-CN.md +5 -3
- package/templates/.agents/rules/issue-sync.github.en.md +7 -3
- package/templates/.agents/rules/issue-sync.github.zh-CN.md +8 -4
- package/templates/.agents/rules/lifecycle-orchestration.en.md +24 -0
- package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +24 -0
- package/templates/.agents/rules/milestone-inference.github.en.md +4 -2
- package/templates/.agents/rules/milestone-inference.github.zh-CN.md +4 -2
- package/templates/.agents/rules/next-step-output.en.md +18 -0
- package/templates/.agents/rules/next-step-output.zh-CN.md +18 -0
- package/templates/.agents/rules/no-mid-flow-questions.en.md +19 -0
- package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +19 -0
- package/templates/.agents/rules/pr-checks-commands.en.md +3 -3
- package/templates/.agents/rules/pr-checks-commands.github.en.md +2 -2
- package/templates/.agents/rules/pr-checks-commands.github.zh-CN.md +2 -2
- package/templates/.agents/rules/pr-checks-commands.zh-CN.md +3 -3
- package/templates/.agents/rules/pr-sync.en.md +3 -1
- package/templates/.agents/rules/pr-sync.github.en.md +11 -1
- package/templates/.agents/rules/pr-sync.github.zh-CN.md +11 -1
- package/templates/.agents/rules/pr-sync.zh-CN.md +3 -1
- package/templates/.agents/rules/release-commands.en.md +1 -1
- package/templates/.agents/rules/release-commands.github.en.md +21 -5
- package/templates/.agents/rules/release-commands.github.zh-CN.md +21 -5
- package/templates/.agents/rules/release-commands.zh-CN.md +1 -1
- package/templates/.agents/rules/review-handshake.en.md +4 -4
- package/templates/.agents/rules/review-handshake.zh-CN.md +4 -4
- package/templates/.agents/rules/review-method.en.md +113 -0
- package/templates/.agents/rules/review-method.zh-CN.md +98 -0
- package/templates/.agents/rules/task-management.en.md +11 -0
- package/templates/.agents/rules/task-management.zh-CN.md +11 -0
- package/templates/.agents/skills/analyze-task/SKILL.en.md +15 -12
- package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +15 -12
- package/templates/.agents/skills/block-task/SKILL.en.md +11 -9
- package/templates/.agents/skills/block-task/SKILL.zh-CN.md +11 -9
- package/templates/.agents/skills/cancel-task/SKILL.en.md +10 -8
- package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +11 -9
- package/templates/.agents/skills/check-task/SKILL.en.md +16 -16
- package/templates/.agents/skills/check-task/SKILL.zh-CN.md +16 -16
- package/templates/.agents/skills/close-codescan/SKILL.en.md +7 -5
- package/templates/.agents/skills/close-codescan/SKILL.zh-CN.md +7 -5
- package/templates/.agents/skills/close-dependabot/SKILL.en.md +7 -5
- package/templates/.agents/skills/close-dependabot/SKILL.zh-CN.md +7 -5
- package/templates/.agents/skills/code-task/SKILL.en.md +10 -7
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +13 -10
- package/templates/.agents/skills/code-task/reference/fix-mode.en.md +14 -16
- package/templates/.agents/skills/code-task/reference/fix-mode.zh-CN.md +14 -16
- package/templates/.agents/skills/code-task/reference/output-template.en.md +3 -3
- package/templates/.agents/skills/code-task/reference/output-template.zh-CN.md +3 -3
- package/templates/.agents/skills/commit/SKILL.en.md +13 -1
- package/templates/.agents/skills/commit/SKILL.zh-CN.md +13 -1
- package/templates/.agents/skills/commit/reference/commit-message.en.md +1 -1
- package/templates/.agents/skills/commit/reference/commit-message.zh-CN.md +1 -1
- package/templates/.agents/skills/commit/reference/issue-metadata-sync.en.md +1 -1
- package/templates/.agents/skills/commit/reference/issue-metadata-sync.zh-CN.md +1 -1
- package/templates/.agents/skills/commit/reference/pr-summary-sync.en.md +1 -1
- package/templates/.agents/skills/commit/reference/pr-summary-sync.zh-CN.md +1 -1
- package/templates/.agents/skills/commit/reference/task-status-update.en.md +24 -28
- package/templates/.agents/skills/commit/reference/task-status-update.zh-CN.md +24 -28
- package/templates/.agents/skills/complete-manual-validation/SKILL.en.md +6 -4
- package/templates/.agents/skills/complete-manual-validation/SKILL.zh-CN.md +6 -4
- package/templates/.agents/skills/complete-manual-validation/reference/summary-update.en.md +1 -1
- package/templates/.agents/skills/complete-manual-validation/reference/summary-update.zh-CN.md +1 -1
- package/templates/.agents/skills/complete-task/SKILL.en.md +23 -8
- package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +23 -8
- package/templates/.agents/skills/complete-task/config/verify.en.json +1 -0
- package/templates/.agents/skills/complete-task/config/verify.zh-CN.json +1 -0
- package/templates/.agents/skills/complete-task/reference/external-delivery.en.md +17 -0
- package/templates/.agents/skills/complete-task/reference/external-delivery.zh-CN.md +17 -0
- package/templates/.agents/skills/create-pr/SKILL.en.md +13 -11
- package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +13 -11
- package/templates/.agents/skills/create-pr/reference/comment-publish.en.md +1 -1
- package/templates/.agents/skills/create-pr/reference/comment-publish.zh-CN.md +1 -1
- package/templates/.agents/skills/create-pr/reference/pr-body-template.en.md +3 -3
- package/templates/.agents/skills/create-pr/reference/pr-body-template.zh-CN.md +3 -3
- package/templates/.agents/skills/create-release-note/SKILL.en.md +17 -16
- package/templates/.agents/skills/create-release-note/SKILL.zh-CN.md +17 -16
- package/templates/.agents/skills/create-task/SKILL.en.md +16 -14
- package/templates/.agents/skills/create-task/SKILL.zh-CN.md +16 -14
- package/templates/.agents/skills/import-codescan/SKILL.en.md +5 -5
- package/templates/.agents/skills/import-codescan/SKILL.zh-CN.md +5 -5
- package/templates/.agents/skills/import-dependabot/SKILL.en.md +5 -5
- package/templates/.agents/skills/import-dependabot/SKILL.zh-CN.md +5 -5
- package/templates/.agents/skills/import-issue/SKILL.en.md +10 -8
- package/templates/.agents/skills/import-issue/SKILL.zh-CN.md +10 -8
- package/templates/.agents/skills/init-labels/SKILL.en.md +4 -4
- package/templates/.agents/skills/init-labels/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/init-milestones/SKILL.en.md +4 -4
- package/templates/.agents/skills/init-milestones/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/plan-task/SKILL.en.md +13 -10
- package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +13 -10
- package/templates/.agents/skills/post-release/SKILL.en.md +2 -0
- package/templates/.agents/skills/post-release/SKILL.zh-CN.md +2 -0
- package/templates/.agents/skills/refine-title/SKILL.en.md +1 -1
- package/templates/.agents/skills/refine-title/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/release/SKILL.en.md +16 -10
- package/templates/.agents/skills/release/SKILL.zh-CN.md +16 -10
- package/templates/.agents/skills/restore-task/SKILL.en.md +4 -1
- package/templates/.agents/skills/restore-task/SKILL.zh-CN.md +4 -1
- package/templates/.agents/skills/review-analysis/SKILL.en.md +18 -4
- package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +19 -5
- package/templates/.agents/skills/review-analysis/config/verify.en.json +6 -0
- package/templates/.agents/skills/review-analysis/config/verify.zh-CN.json +6 -0
- package/templates/.agents/skills/review-analysis/reference/output-templates.en.md +13 -15
- package/templates/.agents/skills/review-analysis/reference/output-templates.zh-CN.md +13 -15
- package/templates/.agents/skills/review-analysis/reference/report-template.en.md +51 -5
- package/templates/.agents/skills/review-analysis/reference/report-template.zh-CN.md +52 -6
- package/templates/.agents/skills/review-analysis/reference/review-criteria.en.md +25 -22
- package/templates/.agents/skills/review-analysis/reference/review-criteria.zh-CN.md +25 -22
- package/templates/.agents/skills/review-code/SKILL.en.md +35 -12
- package/templates/.agents/skills/review-code/SKILL.zh-CN.md +35 -12
- package/templates/.agents/skills/review-code/config/verify.en.json +7 -0
- package/templates/.agents/skills/review-code/config/verify.zh-CN.json +7 -0
- package/templates/.agents/skills/review-code/reference/concurrency-risks.en.md +25 -0
- package/templates/.agents/skills/review-code/reference/concurrency-risks.zh-CN.md +25 -0
- package/templates/.agents/skills/review-code/reference/cross-platform-risks.en.md +27 -0
- package/templates/.agents/skills/review-code/reference/cross-platform-risks.zh-CN.md +27 -0
- package/templates/.agents/skills/review-code/reference/documentation-antipatterns.en.md +13 -0
- package/templates/.agents/skills/review-code/reference/documentation-antipatterns.zh-CN.md +13 -0
- package/templates/.agents/skills/review-code/reference/migration-risks.en.md +25 -0
- package/templates/.agents/skills/review-code/reference/migration-risks.zh-CN.md +25 -0
- package/templates/.agents/skills/review-code/reference/output-templates.en.md +22 -24
- package/templates/.agents/skills/review-code/reference/output-templates.zh-CN.md +22 -24
- package/templates/.agents/skills/review-code/reference/report-template.en.md +54 -7
- package/templates/.agents/skills/review-code/reference/report-template.zh-CN.md +54 -7
- package/templates/.agents/skills/review-code/reference/review-criteria.en.md +29 -24
- package/templates/.agents/skills/review-code/reference/review-criteria.zh-CN.md +29 -24
- package/templates/.agents/skills/review-code/reference/security-risks.en.md +25 -0
- package/templates/.agents/skills/review-code/reference/security-risks.zh-CN.md +25 -0
- package/templates/.agents/skills/review-plan/SKILL.en.md +18 -4
- package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +19 -5
- package/templates/.agents/skills/review-plan/config/verify.en.json +6 -0
- package/templates/.agents/skills/review-plan/config/verify.zh-CN.json +6 -0
- package/templates/.agents/skills/review-plan/reference/output-templates.en.md +13 -15
- package/templates/.agents/skills/review-plan/reference/output-templates.zh-CN.md +13 -15
- package/templates/.agents/skills/review-plan/reference/report-template.en.md +61 -5
- package/templates/.agents/skills/review-plan/reference/report-template.zh-CN.md +61 -5
- package/templates/.agents/skills/review-plan/reference/review-criteria.en.md +21 -24
- package/templates/.agents/skills/review-plan/reference/review-criteria.zh-CN.md +21 -24
- package/templates/.agents/skills/review-pr/SKILL.en.md +158 -0
- package/templates/.agents/skills/review-pr/SKILL.zh-CN.md +158 -0
- package/templates/.agents/skills/review-pr/config/verify.en.json +37 -0
- package/templates/.agents/skills/review-pr/config/verify.zh-CN.json +37 -0
- package/templates/.agents/skills/review-pr/reference/evidence-grading.en.md +65 -0
- package/templates/.agents/skills/review-pr/reference/evidence-grading.zh-CN.md +65 -0
- package/templates/.agents/skills/review-pr/reference/output-guidance.en.md +18 -0
- package/templates/.agents/skills/review-pr/reference/output-guidance.zh-CN.md +18 -0
- package/templates/.agents/skills/review-pr/reference/report-template.en.md +85 -0
- package/templates/.agents/skills/review-pr/reference/report-template.zh-CN.md +85 -0
- package/templates/.agents/skills/run-task/SKILL.en.md +22 -0
- package/templates/.agents/skills/run-task/SKILL.zh-CN.md +22 -0
- package/templates/.agents/skills/run-task/config/verify.en.json +10 -0
- package/templates/.agents/skills/run-task/config/verify.zh-CN.json +10 -0
- package/templates/.agents/skills/run-task/reference/host-validation.en.md +20 -0
- package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +20 -0
- package/templates/.agents/skills/test/SKILL.en.md +4 -4
- package/templates/.agents/skills/test/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/test-integration/SKILL.en.md +4 -4
- package/templates/.agents/skills/test-integration/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/update-agent-infra/SKILL.en.md +5 -5
- package/templates/.agents/skills/update-agent-infra/SKILL.zh-CN.md +5 -5
- package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +664 -246
- package/templates/.agents/skills/upgrade-dependency/SKILL.en.md +4 -4
- package/templates/.agents/skills/upgrade-dependency/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/watch-pr/SKILL.en.md +21 -21
- package/templates/.agents/skills/watch-pr/SKILL.zh-CN.md +21 -21
- package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.en.md +27 -6
- package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.zh-CN.md +26 -5
- package/templates/.agents/templates/task.en.md +1 -1
- package/templates/.agents/templates/task.zh-CN.md +1 -1
- package/templates/.agents/workflows/bug-fix.en.yaml +3 -3
- package/templates/.agents/workflows/bug-fix.zh-CN.yaml +3 -3
- package/templates/.agents/workflows/code-review.en.yaml +1 -1
- package/templates/.agents/workflows/code-review.zh-CN.yaml +1 -1
- package/templates/.agents/workflows/feature-development.en.yaml +4 -4
- package/templates/.agents/workflows/feature-development.zh-CN.yaml +4 -4
- package/templates/.agents/workflows/refactoring.en.yaml +3 -3
- package/templates/.agents/workflows/refactoring.zh-CN.yaml +3 -3
- package/templates/.claude/agents/agent-infra-lifecycle-executor.en.md +6 -0
- package/templates/.claude/agents/agent-infra-lifecycle-executor.zh-CN.md +6 -0
- package/templates/.claude/agents/agent-infra-lifecycle-reviewer.en.md +6 -0
- package/templates/.claude/agents/agent-infra-lifecycle-reviewer.zh-CN.md +6 -0
- package/templates/.claude/commands/post-release.en.md +1 -0
- package/templates/.claude/commands/post-release.zh-CN.md +1 -0
- package/templates/.claude/commands/review-pr.en.md +8 -0
- package/templates/.claude/commands/review-pr.zh-CN.md +8 -0
- package/templates/.claude/commands/run-task.en.md +8 -0
- package/templates/.claude/commands/run-task.zh-CN.md +8 -0
- package/templates/.claude/settings.json +24 -0
- package/templates/.codex/agents/agent-infra-lifecycle-executor.en.toml +3 -0
- package/templates/.codex/agents/agent-infra-lifecycle-executor.zh-CN.toml +3 -0
- package/templates/.codex/agents/agent-infra-lifecycle-reviewer.en.toml +3 -0
- package/templates/.codex/agents/agent-infra-lifecycle-reviewer.zh-CN.toml +3 -0
- package/templates/.gemini/commands/_project_/review-pr.en.toml +10 -0
- package/templates/.gemini/commands/_project_/review-pr.zh-CN.toml +10 -0
- package/templates/.opencode/commands/post-release.en.md +2 -0
- package/templates/.opencode/commands/post-release.zh-CN.md +2 -0
- package/templates/.opencode/commands/review-pr.en.md +11 -0
- package/templates/.opencode/commands/review-pr.zh-CN.md +11 -0
- package/templates/.opencode/commands/run-task.en.md +11 -0
- package/templates/.opencode/commands/run-task.zh-CN.md +11 -0
- package/templates/.gemini/commands/_project_/analyze-task.en.toml +0 -10
- package/templates/.gemini/commands/_project_/analyze-task.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/archive-tasks.en.toml +0 -10
- package/templates/.gemini/commands/_project_/archive-tasks.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/block-task.en.toml +0 -10
- package/templates/.gemini/commands/_project_/block-task.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/cancel-task.en.toml +0 -10
- package/templates/.gemini/commands/_project_/cancel-task.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/check-task.en.toml +0 -10
- package/templates/.gemini/commands/_project_/check-task.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/close-codescan.en.toml +0 -8
- package/templates/.gemini/commands/_project_/close-codescan.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/close-dependabot.en.toml +0 -8
- package/templates/.gemini/commands/_project_/close-dependabot.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/code-task.en.toml +0 -10
- package/templates/.gemini/commands/_project_/code-task.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/commit.en.toml +0 -10
- package/templates/.gemini/commands/_project_/commit.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/complete-manual-validation.en.toml +0 -10
- package/templates/.gemini/commands/_project_/complete-manual-validation.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/complete-task.en.toml +0 -10
- package/templates/.gemini/commands/_project_/complete-task.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/create-pr.en.toml +0 -10
- package/templates/.gemini/commands/_project_/create-pr.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/create-release-note.en.toml +0 -8
- package/templates/.gemini/commands/_project_/create-release-note.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/create-task.en.toml +0 -8
- package/templates/.gemini/commands/_project_/create-task.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/import-codescan.en.toml +0 -8
- package/templates/.gemini/commands/_project_/import-codescan.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/import-dependabot.en.toml +0 -8
- package/templates/.gemini/commands/_project_/import-dependabot.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/import-issue.en.toml +0 -8
- package/templates/.gemini/commands/_project_/import-issue.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/init-labels.en.toml +0 -8
- package/templates/.gemini/commands/_project_/init-labels.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/init-milestones.en.toml +0 -10
- package/templates/.gemini/commands/_project_/init-milestones.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/plan-task.en.toml +0 -10
- package/templates/.gemini/commands/_project_/plan-task.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/post-release.en.toml +0 -6
- package/templates/.gemini/commands/_project_/post-release.zh-CN.toml +0 -6
- package/templates/.gemini/commands/_project_/refine-title.en.toml +0 -8
- package/templates/.gemini/commands/_project_/refine-title.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/release.en.toml +0 -8
- package/templates/.gemini/commands/_project_/release.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/restore-task.en.toml +0 -8
- package/templates/.gemini/commands/_project_/restore-task.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/review-analysis.en.toml +0 -10
- package/templates/.gemini/commands/_project_/review-analysis.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/review-code.en.toml +0 -10
- package/templates/.gemini/commands/_project_/review-code.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/review-plan.en.toml +0 -10
- package/templates/.gemini/commands/_project_/review-plan.zh-CN.toml +0 -10
- package/templates/.gemini/commands/_project_/test-integration.en.toml +0 -6
- package/templates/.gemini/commands/_project_/test-integration.zh-CN.toml +0 -6
- package/templates/.gemini/commands/_project_/test.en.toml +0 -6
- package/templates/.gemini/commands/_project_/test.zh-CN.toml +0 -6
- package/templates/.gemini/commands/_project_/update-agent-infra.en.toml +0 -6
- package/templates/.gemini/commands/_project_/update-agent-infra.zh-CN.toml +0 -6
- package/templates/.gemini/commands/_project_/upgrade-dependency.en.toml +0 -8
- package/templates/.gemini/commands/_project_/upgrade-dependency.zh-CN.toml +0 -8
- package/templates/.gemini/commands/_project_/watch-pr.en.toml +0 -10
- package/templates/.gemini/commands/_project_/watch-pr.zh-CN.toml +0 -10
- package/templates/.gemini/settings.json +0 -3
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { parseTypedTaskFrontmatter } from './frontmatter.js';
|
|
5
|
+
import { parseReviewSummary } from './review-artifacts.js';
|
|
6
|
+
import { inspectArtifactDirectory } from './artifact-lifecycle.js';
|
|
7
|
+
import { parseLedger, summarizeLedgerStage, validateLedgerRows } from './ledger.js';
|
|
8
|
+
import { resolveTaskRef } from './resolve-ref.js';
|
|
9
|
+
import { activateDelegation, completeDelegationStage, consumeDelegation, managedDelegationRole, prepareDelegation, sealDelegation } from './delegation-receipts.js';
|
|
10
|
+
import { normalizeAgentClients } from '../agent-clients/config.js';
|
|
11
|
+
import { inspectPlatformPullRequest } from '../platform/pull-requests.js';
|
|
12
|
+
import { getAgentClientCapability, getAgentClientDelegationEvidence, getAgentClientModelSelection } from '../agent-clients/registry.js';
|
|
13
|
+
import { isAgentClientId } from '../agent-clients/types.js';
|
|
14
|
+
import { captureRepositorySnapshot, captureWorkspaceSnapshot, diffWorkspaceSnapshots } from './workspace-snapshot.js';
|
|
15
|
+
import { TaskExecutionLockError, withTaskExecutionLock } from './task-execution-lock.js';
|
|
16
|
+
function supportsLifecycleDelegation(client) {
|
|
17
|
+
return getAgentClientCapability(client, 'subagents').level !== 'unsupported'
|
|
18
|
+
&& getAgentClientCapability(client, 'orchestration').level !== 'unsupported'
|
|
19
|
+
&& getAgentClientDelegationEvidence(client).actualModel !== 'unavailable'
|
|
20
|
+
&& getAgentClientDelegationEvidence(client).actualReasoningEffort !== 'unavailable';
|
|
21
|
+
}
|
|
22
|
+
function orchestrationPath(taskDir) {
|
|
23
|
+
return path.join(taskDir, 'orchestration.json');
|
|
24
|
+
}
|
|
25
|
+
function readRun(taskDir) {
|
|
26
|
+
const file = orchestrationPath(taskDir);
|
|
27
|
+
if (!fs.existsSync(file))
|
|
28
|
+
return null;
|
|
29
|
+
const run = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
30
|
+
if (run.schemaVersion !== 2 || !isV2Policy(run.modelPolicy))
|
|
31
|
+
return run;
|
|
32
|
+
return {
|
|
33
|
+
...run,
|
|
34
|
+
modelPolicy: {
|
|
35
|
+
executor: {
|
|
36
|
+
model: run.modelPolicy.executor.model,
|
|
37
|
+
reasoningEffort: run.modelPolicy.executor.reasoningEffort
|
|
38
|
+
},
|
|
39
|
+
reviewer: {
|
|
40
|
+
model: run.modelPolicy.reviewer.model,
|
|
41
|
+
reasoningEffort: run.modelPolicy.reviewer.reasoningEffort
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function atomicWrite(file, value) {
|
|
47
|
+
const temp = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
48
|
+
fs.writeFileSync(temp, `${JSON.stringify(value, null, 2)}\n`, { encoding: 'utf8', flag: 'wx' });
|
|
49
|
+
fs.renameSync(temp, file);
|
|
50
|
+
}
|
|
51
|
+
function saveRun(taskDir, run) {
|
|
52
|
+
atomicWrite(orchestrationPath(taskDir), run);
|
|
53
|
+
}
|
|
54
|
+
function withUpdatedRun(run, updates) {
|
|
55
|
+
return Object.freeze({ ...run, ...updates, updatedAt: new Date().toISOString() });
|
|
56
|
+
}
|
|
57
|
+
function failed(code, message, taskId = null, details = {}) {
|
|
58
|
+
return { status: 'failed', changed: false, taskId, run: null, next: null, error: { code, message, ...details } };
|
|
59
|
+
}
|
|
60
|
+
function validModel(value) {
|
|
61
|
+
return typeof value === 'string' && value.length > 0 && value.trim() === value;
|
|
62
|
+
}
|
|
63
|
+
function validateModelPolicy(policy) {
|
|
64
|
+
if (!policy
|
|
65
|
+
|| !validModel(policy.executor?.model)
|
|
66
|
+
|| !validModel(policy.executor?.reasoningEffort)
|
|
67
|
+
|| !validModel(policy.reviewer?.model)
|
|
68
|
+
|| !validModel(policy.reviewer?.reasoningEffort)) {
|
|
69
|
+
return { code: 'ORCHESTRATION_MODEL_POLICY_REQUIRED', message: 'executor and reviewer model and reasoning effort are required' };
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function sameModelPolicy(left, right) {
|
|
74
|
+
return left.executor.model === right.executor.model
|
|
75
|
+
&& left.executor.reasoningEffort === right.executor.reasoningEffort
|
|
76
|
+
&& left.reviewer.model === right.reviewer.model
|
|
77
|
+
&& left.reviewer.reasoningEffort === right.reviewer.reasoningEffort;
|
|
78
|
+
}
|
|
79
|
+
function isV2Policy(policy) {
|
|
80
|
+
return typeof policy?.executor === 'object' && typeof policy?.reviewer === 'object';
|
|
81
|
+
}
|
|
82
|
+
function rolePolicy(run, role) {
|
|
83
|
+
return isV2Policy(run.modelPolicy) ? run.modelPolicy[role] : null;
|
|
84
|
+
}
|
|
85
|
+
function resolveProjectPolicy(repoRoot, client) {
|
|
86
|
+
const configPath = path.join(repoRoot, '.agents', '.airc.json');
|
|
87
|
+
if (!fs.existsSync(configPath))
|
|
88
|
+
return undefined;
|
|
89
|
+
const raw = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
90
|
+
return normalizeAgentClients(raw).state[client].orchestration;
|
|
91
|
+
}
|
|
92
|
+
function beginOrResumeOrchestration(taskRef, options = {}) {
|
|
93
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
94
|
+
if (!resolved.ok)
|
|
95
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
96
|
+
if (!isAgentClientId(options.client)) {
|
|
97
|
+
return failed('ORCHESTRATION_PAYLOAD_INVALID', 'begin-or-resume requires a known client', resolved.taskId);
|
|
98
|
+
}
|
|
99
|
+
let existing;
|
|
100
|
+
try {
|
|
101
|
+
existing = readRun(resolved.taskDir);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return failed('ORCHESTRATION_STATE_INVALID', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
105
|
+
}
|
|
106
|
+
if (existing) {
|
|
107
|
+
if (![1, 2].includes(existing.schemaVersion)
|
|
108
|
+
|| !Array.isArray(existing.receipts)
|
|
109
|
+
|| !Object.prototype.hasOwnProperty.call(existing, 'pendingDelegation')) {
|
|
110
|
+
return failed('ORCHESTRATION_STATE_INVALID', 'orchestration state has an invalid schema', resolved.taskId);
|
|
111
|
+
}
|
|
112
|
+
if (existing.status === 'completed' && existing.schemaVersion === 1) {
|
|
113
|
+
return { status: 'completed', changed: false, taskId: resolved.taskId, run: existing, next: null, error: null };
|
|
114
|
+
}
|
|
115
|
+
if (existing.schemaVersion === 2) {
|
|
116
|
+
const policyError = validateModelPolicy(isV2Policy(existing.modelPolicy) ? existing.modelPolicy : undefined);
|
|
117
|
+
if (policyError
|
|
118
|
+
|| !existing.modelPolicySource
|
|
119
|
+
|| !isAgentClientId(existing.modelPolicySource.client)
|
|
120
|
+
|| !Array.isArray(existing.recoveryHistory)) {
|
|
121
|
+
return failed('ORCHESTRATION_STATE_INVALID', 'schemaVersion 2 orchestration state is incomplete', resolved.taskId);
|
|
122
|
+
}
|
|
123
|
+
if (existing.status === 'completed') {
|
|
124
|
+
return { status: 'completed', changed: false, taskId: resolved.taskId, run: existing, next: null, error: null };
|
|
125
|
+
}
|
|
126
|
+
if (existing.modelPolicySource.client !== options.client) {
|
|
127
|
+
return failed('ORCHESTRATION_CLIENT_MISMATCH', 'provided client does not match the persisted run policy source', resolved.taskId);
|
|
128
|
+
}
|
|
129
|
+
if (options.modelPolicy) {
|
|
130
|
+
const suppliedError = validateModelPolicy(options.modelPolicy);
|
|
131
|
+
if (suppliedError)
|
|
132
|
+
return failed(suppliedError.code, suppliedError.message, resolved.taskId);
|
|
133
|
+
if (!sameModelPolicy(existing.modelPolicy, options.modelPolicy)) {
|
|
134
|
+
return failed('ORCHESTRATION_MODEL_POLICY_MISMATCH', 'provided model policy does not match the persisted run policy', resolved.taskId);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (existing.status === 'paused' && existing.pause?.recoverable && existing.pendingDelegation === null) {
|
|
138
|
+
const resumed = withUpdatedRun(existing, { status: 'running', pause: null });
|
|
139
|
+
saveRun(resolved.taskDir, resumed);
|
|
140
|
+
return { status: 'running', changed: true, taskId: resolved.taskId, run: resumed, next: null, error: null };
|
|
141
|
+
}
|
|
142
|
+
return { status: existing.status, changed: false, taskId: resolved.taskId, run: existing, next: null, error: null };
|
|
143
|
+
}
|
|
144
|
+
let policy = options.modelPolicy;
|
|
145
|
+
let sourceKind = 'explicit';
|
|
146
|
+
if (!policy) {
|
|
147
|
+
try {
|
|
148
|
+
policy = resolveProjectPolicy(resolved.repoRoot, options.client);
|
|
149
|
+
sourceKind = 'project-config';
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
return failed('ORCHESTRATION_CONFIG_INVALID', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const policyError = validateModelPolicy(policy);
|
|
156
|
+
if (policyError) {
|
|
157
|
+
return failed(policyError.code, policyError.message, resolved.taskId, {
|
|
158
|
+
client: options.client,
|
|
159
|
+
missingFields: ['executor.model', 'executor.reasoningEffort', 'reviewer.model', 'reviewer.reasoningEffort'],
|
|
160
|
+
modelSelectionContext: getAgentClientModelSelection(options.client)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (existing.pendingDelegation !== null) {
|
|
164
|
+
const alreadyPaused = existing.status === 'paused' && existing.pause?.code === 'ORCHESTRATION_DELEGATION_BUSY';
|
|
165
|
+
if (alreadyPaused)
|
|
166
|
+
return { status: 'paused', changed: false, taskId: resolved.taskId, run: existing, next: null, error: null };
|
|
167
|
+
const paused = withUpdatedRun(existing, {
|
|
168
|
+
status: 'paused',
|
|
169
|
+
pause: { code: 'ORCHESTRATION_DELEGATION_BUSY', message: 'legacy run has a pending delegation', recoverable: false }
|
|
170
|
+
});
|
|
171
|
+
saveRun(resolved.taskDir, paused);
|
|
172
|
+
return { status: 'paused', changed: true, taskId: resolved.taskId, run: paused, next: null, error: null };
|
|
173
|
+
}
|
|
174
|
+
if (existing.receipts.length > 0) {
|
|
175
|
+
const alreadyPaused = existing.status === 'paused' && existing.pause?.code === 'ORCHESTRATION_HISTORICAL_EFFORT_UNVERIFIED';
|
|
176
|
+
if (alreadyPaused)
|
|
177
|
+
return { status: 'paused', changed: false, taskId: resolved.taskId, run: existing, next: null, error: null };
|
|
178
|
+
const paused = withUpdatedRun(existing, {
|
|
179
|
+
status: 'paused',
|
|
180
|
+
pause: {
|
|
181
|
+
code: 'ORCHESTRATION_HISTORICAL_EFFORT_UNVERIFIED',
|
|
182
|
+
message: 'legacy receipts do not contain actual reasoning-effort evidence',
|
|
183
|
+
recoverable: false
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
saveRun(resolved.taskDir, paused);
|
|
187
|
+
return { status: 'paused', changed: true, taskId: resolved.taskId, run: paused, next: null, error: null };
|
|
188
|
+
}
|
|
189
|
+
if (existing.modelPolicy
|
|
190
|
+
&& typeof existing.modelPolicy.executor === 'string'
|
|
191
|
+
&& (existing.modelPolicy.executor !== policy.executor.model
|
|
192
|
+
|| existing.modelPolicy.reviewer !== policy.reviewer.model)) {
|
|
193
|
+
return failed('ORCHESTRATION_MODEL_POLICY_MISMATCH', 'provided model policy does not match the persisted run policy', resolved.taskId);
|
|
194
|
+
}
|
|
195
|
+
const now = (options.now ?? (() => new Date().toISOString()))();
|
|
196
|
+
const source = { kind: sourceKind, client: options.client, resolvedAt: now };
|
|
197
|
+
const clearsModelPause = existing.pause?.code === 'ORCHESTRATION_MODEL_EVIDENCE_MISSING';
|
|
198
|
+
const resultingStatus = clearsModelPause ? 'running' : existing.status;
|
|
199
|
+
const recovery = {
|
|
200
|
+
code: 'MODEL_POLICY_SUPPLEMENTED',
|
|
201
|
+
recoveredAt: now,
|
|
202
|
+
previousSchemaVersion: 1,
|
|
203
|
+
previousStatus: existing.status,
|
|
204
|
+
previousPause: existing.pause,
|
|
205
|
+
policySource: source,
|
|
206
|
+
receiptCount: 0,
|
|
207
|
+
pendingDelegation: false,
|
|
208
|
+
resultingStatus
|
|
209
|
+
};
|
|
210
|
+
const recovered = Object.freeze({
|
|
211
|
+
...existing,
|
|
212
|
+
schemaVersion: 2,
|
|
213
|
+
status: resultingStatus,
|
|
214
|
+
modelPolicy: policy,
|
|
215
|
+
modelPolicySource: source,
|
|
216
|
+
recoveryHistory: Object.freeze([recovery]),
|
|
217
|
+
pause: clearsModelPause ? null : existing.pause,
|
|
218
|
+
updatedAt: now
|
|
219
|
+
});
|
|
220
|
+
saveRun(resolved.taskDir, recovered);
|
|
221
|
+
return { status: resultingStatus, changed: true, taskId: resolved.taskId, run: recovered, next: null, error: null };
|
|
222
|
+
}
|
|
223
|
+
let policy = options.modelPolicy;
|
|
224
|
+
let sourceKind = 'explicit';
|
|
225
|
+
if (!policy) {
|
|
226
|
+
try {
|
|
227
|
+
policy = resolveProjectPolicy(resolved.repoRoot, options.client);
|
|
228
|
+
sourceKind = 'project-config';
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
return failed('ORCHESTRATION_CONFIG_INVALID', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const policyError = validateModelPolicy(policy);
|
|
235
|
+
if (policyError)
|
|
236
|
+
return failed(policyError.code, policyError.message, resolved.taskId, {
|
|
237
|
+
client: options.client,
|
|
238
|
+
missingFields: ['executor.model', 'executor.reasoningEffort', 'reviewer.model', 'reviewer.reasoningEffort'],
|
|
239
|
+
modelSelectionContext: getAgentClientModelSelection(options.client)
|
|
240
|
+
});
|
|
241
|
+
const now = (options.now ?? (() => new Date().toISOString()))();
|
|
242
|
+
const source = { kind: sourceKind, client: options.client, resolvedAt: now };
|
|
243
|
+
const run = {
|
|
244
|
+
schemaVersion: 2,
|
|
245
|
+
taskId: resolved.taskId,
|
|
246
|
+
runId: (options.id ?? randomUUID)(),
|
|
247
|
+
status: 'running',
|
|
248
|
+
nextStage: null,
|
|
249
|
+
stepCount: 0,
|
|
250
|
+
maxSteps: options.maxSteps ?? 24,
|
|
251
|
+
modelPolicy: policy,
|
|
252
|
+
modelPolicySource: source,
|
|
253
|
+
recoveryHistory: [],
|
|
254
|
+
baseline: '',
|
|
255
|
+
pendingDelegation: null,
|
|
256
|
+
receipts: [],
|
|
257
|
+
pause: null,
|
|
258
|
+
commitAuthorization: { issuedAt: null, consumedAt: null },
|
|
259
|
+
completionEvidence: null,
|
|
260
|
+
createdAt: now,
|
|
261
|
+
updatedAt: now
|
|
262
|
+
};
|
|
263
|
+
atomicWrite(orchestrationPath(resolved.taskDir), run);
|
|
264
|
+
return { status: 'running', changed: true, taskId: resolved.taskId, run, next: null, error: null };
|
|
265
|
+
}
|
|
266
|
+
function highestRound(taskDir, family) {
|
|
267
|
+
const pattern = new RegExp(`^${family}(?:-r(\\d+))?\\.md$`);
|
|
268
|
+
return fs.readdirSync(taskDir).reduce((max, name) => {
|
|
269
|
+
const match = pattern.exec(name);
|
|
270
|
+
return match ? Math.max(max, match[1] ? Number(match[1]) : 1) : max;
|
|
271
|
+
}, 0);
|
|
272
|
+
}
|
|
273
|
+
function artifactName(family, round) {
|
|
274
|
+
return round === 1 ? `${family}.md` : `${family}-r${round}.md`;
|
|
275
|
+
}
|
|
276
|
+
function hasReviewAfterArtifact(taskDir, family, reviewFamily) {
|
|
277
|
+
const artifact = inspectArtifactDirectory(taskDir, family);
|
|
278
|
+
const review = inspectArtifactDirectory(taskDir, reviewFamily);
|
|
279
|
+
return artifact.status === 'ready'
|
|
280
|
+
&& review.status === 'ready'
|
|
281
|
+
&& artifact.latest !== null
|
|
282
|
+
&& review.reviewedInput?.name === artifact.latest.name;
|
|
283
|
+
}
|
|
284
|
+
function latestReviewApproved(taskDir, family) {
|
|
285
|
+
const round = highestRound(taskDir, family);
|
|
286
|
+
if (round === 0)
|
|
287
|
+
return false;
|
|
288
|
+
const parsed = parseReviewSummary(fs.readFileSync(path.join(taskDir, artifactName(family, round)), 'utf8'));
|
|
289
|
+
return parsed.ok && parsed.summary.verdict === 'Approved' && parsed.summary.counts !== null;
|
|
290
|
+
}
|
|
291
|
+
function routeFromFacts(taskDir) {
|
|
292
|
+
const analysisRound = highestRound(taskDir, 'analysis');
|
|
293
|
+
const analysisReviewRound = highestRound(taskDir, 'review-analysis');
|
|
294
|
+
const planRound = highestRound(taskDir, 'plan');
|
|
295
|
+
const planReviewRound = highestRound(taskDir, 'review-plan');
|
|
296
|
+
const codeRound = highestRound(taskDir, 'code');
|
|
297
|
+
const codeReviewRound = highestRound(taskDir, 'review-code');
|
|
298
|
+
if (analysisRound === 0) {
|
|
299
|
+
const round = analysisRound + 1;
|
|
300
|
+
return { action: 'analyze-task', role: 'executor', stage: 'analysis', round, artifact: artifactName('analysis', round) };
|
|
301
|
+
}
|
|
302
|
+
if (!hasReviewAfterArtifact(taskDir, 'analysis', 'review-analysis')) {
|
|
303
|
+
const round = analysisReviewRound + 1;
|
|
304
|
+
return { action: 'review-analysis', role: 'reviewer', stage: 'review-analysis', round, artifact: artifactName('review-analysis', round) };
|
|
305
|
+
}
|
|
306
|
+
if (!latestReviewApproved(taskDir, 'review-analysis')) {
|
|
307
|
+
const round = analysisRound + 1;
|
|
308
|
+
return { action: 'analyze-task', role: 'executor', stage: 'analysis', round, artifact: artifactName('analysis', round) };
|
|
309
|
+
}
|
|
310
|
+
if (planRound === 0) {
|
|
311
|
+
const round = planRound + 1;
|
|
312
|
+
return { action: 'plan-task', role: 'executor', stage: 'plan', round, artifact: artifactName('plan', round) };
|
|
313
|
+
}
|
|
314
|
+
if (!hasReviewAfterArtifact(taskDir, 'plan', 'review-plan')) {
|
|
315
|
+
const round = planReviewRound + 1;
|
|
316
|
+
return { action: 'review-plan', role: 'reviewer', stage: 'review-plan', round, artifact: artifactName('review-plan', round) };
|
|
317
|
+
}
|
|
318
|
+
if (!latestReviewApproved(taskDir, 'review-plan')) {
|
|
319
|
+
const round = planRound + 1;
|
|
320
|
+
return { action: 'plan-task', role: 'executor', stage: 'plan', round, artifact: artifactName('plan', round) };
|
|
321
|
+
}
|
|
322
|
+
if (codeRound === 0) {
|
|
323
|
+
const round = codeRound + 1;
|
|
324
|
+
return { action: 'code-task', role: 'executor', stage: 'code', round, artifact: artifactName('code', round) };
|
|
325
|
+
}
|
|
326
|
+
if (!hasReviewAfterArtifact(taskDir, 'code', 'review-code')) {
|
|
327
|
+
const round = codeReviewRound + 1;
|
|
328
|
+
return { action: 'review-code', role: 'reviewer', stage: 'review-code', round, artifact: artifactName('review-code', round) };
|
|
329
|
+
}
|
|
330
|
+
if (!latestReviewApproved(taskDir, 'review-code')) {
|
|
331
|
+
const round = codeRound + 1;
|
|
332
|
+
return { action: 'code-task', role: 'executor', stage: 'code', round, artifact: artifactName('code', round) };
|
|
333
|
+
}
|
|
334
|
+
return { action: 'commit', role: 'executor', stage: 'commit', round: 1, artifact: 'commit' };
|
|
335
|
+
}
|
|
336
|
+
function routeOrchestration(taskRef, options = {}) {
|
|
337
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
338
|
+
if (!resolved.ok)
|
|
339
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
340
|
+
let content;
|
|
341
|
+
try {
|
|
342
|
+
content = fs.readFileSync(resolved.taskMdPath, 'utf8');
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
return failed('ORCHESTRATION_TASK_READ_FAILED', String(error), resolved.taskId);
|
|
346
|
+
}
|
|
347
|
+
let metadata;
|
|
348
|
+
try {
|
|
349
|
+
metadata = parseTypedTaskFrontmatter(content);
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
return failed('ORCHESTRATION_TASK_INVALID', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
353
|
+
}
|
|
354
|
+
const routed = routeFromFacts(resolved.taskDir);
|
|
355
|
+
if (!routed)
|
|
356
|
+
return failed('ORCHESTRATION_ROUTE_UNKNOWN', 'cannot determine a unique lifecycle action', resolved.taskId);
|
|
357
|
+
const run = readRun(resolved.taskDir);
|
|
358
|
+
const policy = run ? rolePolicy(run, routed.role) : null;
|
|
359
|
+
const next = {
|
|
360
|
+
...routed,
|
|
361
|
+
requestedModel: policy?.model ?? null,
|
|
362
|
+
requestedReasoningEffort: policy?.reasoningEffort ?? null
|
|
363
|
+
};
|
|
364
|
+
if (next.stage === 'commit') {
|
|
365
|
+
const reviewRound = highestRound(resolved.taskDir, 'review-code');
|
|
366
|
+
const review = parseReviewSummary(fs.readFileSync(path.join(resolved.taskDir, artifactName('review-code', reviewRound)), 'utf8'));
|
|
367
|
+
if (!review.ok || review.summary.manualValidation === null) {
|
|
368
|
+
return failed('ORCHESTRATION_REVIEW_INVALID', 'latest code review has no numeric manual-validation count', resolved.taskId);
|
|
369
|
+
}
|
|
370
|
+
const rows = parseLedger(content);
|
|
371
|
+
const ledgerError = validateLedgerRows(rows);
|
|
372
|
+
if (ledgerError)
|
|
373
|
+
return failed('ORCHESTRATION_LEDGER_INVALID', ledgerError.message, resolved.taskId);
|
|
374
|
+
if (!summarizeLedgerStage(rows, 'code').canAdvance) {
|
|
375
|
+
return failed('ORCHESTRATION_LEDGER_BLOCKED', 'code review ledger has unresolved findings or human decisions', resolved.taskId);
|
|
376
|
+
}
|
|
377
|
+
if (run?.status === 'completed') {
|
|
378
|
+
return { status: 'completed', changed: false, taskId: resolved.taskId, run, next: null, error: null };
|
|
379
|
+
}
|
|
380
|
+
let config;
|
|
381
|
+
try {
|
|
382
|
+
config = JSON.parse(fs.readFileSync(path.join(resolved.repoRoot, '.agents', '.airc.json'), 'utf8'));
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
return failed('ORCHESTRATION_CONFIG_INVALID', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
386
|
+
}
|
|
387
|
+
if (!config || typeof config !== 'object' || Array.isArray(config)) {
|
|
388
|
+
return failed('ORCHESTRATION_CONFIG_INVALID', 'project configuration must be an object', resolved.taskId);
|
|
389
|
+
}
|
|
390
|
+
const projectConfig = config;
|
|
391
|
+
if (!Object.hasOwn(projectConfig, 'prFlow') || projectConfig.prFlow === 'disabled') {
|
|
392
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run, next, error: null };
|
|
393
|
+
}
|
|
394
|
+
if (projectConfig.prFlow !== 'required') {
|
|
395
|
+
return failed('ORCHESTRATION_CONFIG_INVALID', "project configuration 'prFlow' must be 'required' or 'disabled'", resolved.taskId);
|
|
396
|
+
}
|
|
397
|
+
const prNumber = Number(metadata.pr_number);
|
|
398
|
+
if (!Number.isInteger(prNumber) || prNumber <= 0) {
|
|
399
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run, next, error: null };
|
|
400
|
+
}
|
|
401
|
+
if (!run) {
|
|
402
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run, next, error: null };
|
|
403
|
+
}
|
|
404
|
+
if (run.status !== 'running' || run.pendingDelegation !== null) {
|
|
405
|
+
return failed('ORCHESTRATION_RUN_NOT_RUNNING', 'clean completion requires an idle running orchestration', resolved.taskId);
|
|
406
|
+
}
|
|
407
|
+
const capture = options.captureRepository ?? captureRepositorySnapshot;
|
|
408
|
+
let before;
|
|
409
|
+
try {
|
|
410
|
+
before = capture(resolved.repoRoot);
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
return failed('ORCHESTRATION_SNAPSHOT_FAILED', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
414
|
+
}
|
|
415
|
+
if (before.headTree !== before.worktreeTree) {
|
|
416
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run, next, error: null };
|
|
417
|
+
}
|
|
418
|
+
const lastReviewedCommit = String(metadata.last_reviewed_commit ?? '');
|
|
419
|
+
if (before.head !== lastReviewedCommit) {
|
|
420
|
+
return failed('ORCHESTRATION_REVIEWED_HEAD_MISMATCH', 'local HEAD does not match last_reviewed_commit', resolved.taskId);
|
|
421
|
+
}
|
|
422
|
+
const inspect = options.inspectPullRequest ?? inspectPlatformPullRequest;
|
|
423
|
+
let inspection;
|
|
424
|
+
try {
|
|
425
|
+
inspection = inspect(resolved.taskId, { cwd: resolved.repoRoot });
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
return failed('ORCHESTRATION_PR_INSPECTION_FAILED', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
429
|
+
}
|
|
430
|
+
if (inspection.status === 'blocked') {
|
|
431
|
+
return failed('ORCHESTRATION_PR_INSPECTION_BLOCKED', inspection.error?.message ?? 'pull request inspection is blocked', resolved.taskId);
|
|
432
|
+
}
|
|
433
|
+
if (inspection.status === 'failed') {
|
|
434
|
+
return failed('ORCHESTRATION_PR_INSPECTION_FAILED', inspection.error?.message ?? 'pull request inspection failed', resolved.taskId);
|
|
435
|
+
}
|
|
436
|
+
const inspectedPrNumber = inspection.task?.prNumber ?? inspection.prNumber;
|
|
437
|
+
const prHead = inspection.pullRequest?.head?.sha;
|
|
438
|
+
if (typeof prHead !== 'string') {
|
|
439
|
+
return failed('ORCHESTRATION_PR_INSPECTION_INVALID', 'pull request inspection returned incomplete identity evidence', resolved.taskId);
|
|
440
|
+
}
|
|
441
|
+
if (inspectedPrNumber !== prNumber || prHead !== before.head) {
|
|
442
|
+
return failed('ORCHESTRATION_PR_HEAD_MISMATCH', 'pull request identity does not match the reviewed local HEAD', resolved.taskId);
|
|
443
|
+
}
|
|
444
|
+
let after;
|
|
445
|
+
try {
|
|
446
|
+
after = capture(resolved.repoRoot);
|
|
447
|
+
}
|
|
448
|
+
catch (error) {
|
|
449
|
+
return failed('ORCHESTRATION_SNAPSHOT_FAILED', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
450
|
+
}
|
|
451
|
+
if (after.headTree !== after.worktreeTree) {
|
|
452
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run, next, error: null };
|
|
453
|
+
}
|
|
454
|
+
if (after.head !== before.head || after.headTree !== before.headTree) {
|
|
455
|
+
return failed('ORCHESTRATION_REPOSITORY_CHANGED', 'repository changed while clean completion evidence was collected', resolved.taskId);
|
|
456
|
+
}
|
|
457
|
+
const observedAt = (options.now ?? (() => new Date().toISOString()))();
|
|
458
|
+
const completionEvidence = {
|
|
459
|
+
kind: 'reviewed-head-clean',
|
|
460
|
+
observedAt,
|
|
461
|
+
head: after.head,
|
|
462
|
+
headTree: after.headTree,
|
|
463
|
+
worktreeTree: after.worktreeTree,
|
|
464
|
+
lastReviewedCommit,
|
|
465
|
+
prNumber,
|
|
466
|
+
prHead
|
|
467
|
+
};
|
|
468
|
+
const completed = withUpdatedRun(run, {
|
|
469
|
+
status: 'completed',
|
|
470
|
+
nextStage: null,
|
|
471
|
+
pause: null,
|
|
472
|
+
completionEvidence
|
|
473
|
+
});
|
|
474
|
+
saveRun(resolved.taskDir, completed);
|
|
475
|
+
return { status: 'completed', changed: true, taskId: resolved.taskId, run: completed, next: null, error: null };
|
|
476
|
+
}
|
|
477
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run, next, error: null };
|
|
478
|
+
}
|
|
479
|
+
function statusOrchestration(taskRef, options = {}) {
|
|
480
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
481
|
+
if (!resolved.ok)
|
|
482
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
483
|
+
const run = readRun(resolved.taskDir);
|
|
484
|
+
if (!run)
|
|
485
|
+
return failed('ORCHESTRATION_RUN_MISSING', 'no orchestration run exists', resolved.taskId);
|
|
486
|
+
return { status: run.status, changed: false, taskId: resolved.taskId, run, next: null, error: null };
|
|
487
|
+
}
|
|
488
|
+
function prepareOrchestrationDelegationUnlocked(taskRef, input, options = {}) {
|
|
489
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
490
|
+
if (!resolved.ok)
|
|
491
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
492
|
+
if (!(options.supportsLifecycleDelegation ?? supportsLifecycleDelegation)(input.client)) {
|
|
493
|
+
return failed('ORCHESTRATION_CLIENT_UNSUPPORTED', `client '${input.client}' does not support lifecycle orchestration`, resolved.taskId);
|
|
494
|
+
}
|
|
495
|
+
const run = readRun(resolved.taskDir);
|
|
496
|
+
if (!run || run.status !== 'running')
|
|
497
|
+
return failed('ORCHESTRATION_RUN_NOT_RUNNING', 'a running orchestration is required', resolved.taskId);
|
|
498
|
+
if (!isV2Policy(run.modelPolicy))
|
|
499
|
+
return failed('ORCHESTRATION_MODEL_EVIDENCE_MISSING', 'running orchestration has no persisted model policy', resolved.taskId);
|
|
500
|
+
if (run.pendingDelegation)
|
|
501
|
+
return failed('ORCHESTRATION_DELEGATION_BUSY', 'the run already has a pending delegation', resolved.taskId);
|
|
502
|
+
const repositoryPending = ['claude-code', 'codex']
|
|
503
|
+
.flatMap((client) => matchingDelegations(client, () => true, options));
|
|
504
|
+
if (repositoryPending.length > 0) {
|
|
505
|
+
return failed('ORCHESTRATION_DELEGATION_BUSY', 'the repository already has a pending lifecycle delegation', resolved.taskId);
|
|
506
|
+
}
|
|
507
|
+
if (run.stepCount >= run.maxSteps)
|
|
508
|
+
return pauseOrchestration(taskRef, 'ORCHESTRATION_MAX_STEPS', 'maximum orchestration steps reached', true, options);
|
|
509
|
+
const routed = routeOrchestration(taskRef, options);
|
|
510
|
+
if (!routed.next)
|
|
511
|
+
return routed;
|
|
512
|
+
const next = routed.next;
|
|
513
|
+
if (!validModel(input.requestedModel)) {
|
|
514
|
+
return failed('ORCHESTRATION_REQUESTED_MODEL_REQUIRED', 'prepare requires the exact requested model identity', resolved.taskId);
|
|
515
|
+
}
|
|
516
|
+
if (!validModel(input.requestedReasoningEffort)) {
|
|
517
|
+
return failed('ORCHESTRATION_REQUESTED_REASONING_EFFORT_REQUIRED', 'prepare requires the exact requested reasoning effort', resolved.taskId);
|
|
518
|
+
}
|
|
519
|
+
const expectedPolicy = run.modelPolicy[next.role];
|
|
520
|
+
if (input.requestedModel !== expectedPolicy.model) {
|
|
521
|
+
return failed('ORCHESTRATION_REQUESTED_MODEL_MISMATCH', `requested model does not match the persisted ${next.role} model`, resolved.taskId);
|
|
522
|
+
}
|
|
523
|
+
if (input.requestedReasoningEffort !== expectedPolicy.reasoningEffort) {
|
|
524
|
+
return failed('ORCHESTRATION_REQUESTED_REASONING_EFFORT_MISMATCH', `requested reasoning effort does not match the persisted ${next.role} policy`, resolved.taskId);
|
|
525
|
+
}
|
|
526
|
+
let beforeFingerprint;
|
|
527
|
+
try {
|
|
528
|
+
beforeFingerprint = (options.captureWorkspace ?? captureWorkspaceSnapshot)(resolved.repoRoot, resolved.taskId);
|
|
529
|
+
}
|
|
530
|
+
catch (error) {
|
|
531
|
+
return failed('ORCHESTRATION_SNAPSHOT_FAILED', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
532
|
+
}
|
|
533
|
+
const receipt = prepareDelegation({
|
|
534
|
+
taskId: resolved.taskId,
|
|
535
|
+
runId: run.runId,
|
|
536
|
+
role: next.role,
|
|
537
|
+
stage: next.stage,
|
|
538
|
+
round: next.round,
|
|
539
|
+
artifact: next.artifact,
|
|
540
|
+
client: input.client,
|
|
541
|
+
requestedModel: input.requestedModel,
|
|
542
|
+
requestedReasoningEffort: input.requestedReasoningEffort,
|
|
543
|
+
workspaceSnapshotScope: 'task',
|
|
544
|
+
beforeFingerprint
|
|
545
|
+
}, { id: options.id, now: options.now });
|
|
546
|
+
const updated = withUpdatedRun(run, {
|
|
547
|
+
nextStage: next.stage,
|
|
548
|
+
pendingDelegation: receipt,
|
|
549
|
+
commitAuthorization: next.stage === 'commit' && run.commitAuthorization.issuedAt === null
|
|
550
|
+
? { issuedAt: (options.now ?? (() => new Date().toISOString()))(), consumedAt: null }
|
|
551
|
+
: run.commitAuthorization
|
|
552
|
+
});
|
|
553
|
+
saveRun(resolved.taskDir, updated);
|
|
554
|
+
return { status: 'running', changed: true, taskId: resolved.taskId, run: updated, next, error: null };
|
|
555
|
+
}
|
|
556
|
+
function prepareOrchestrationDelegation(taskRef, input, options = {}) {
|
|
557
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
558
|
+
if (!resolved.ok)
|
|
559
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
560
|
+
try {
|
|
561
|
+
return withTaskExecutionLock(resolved.repoRoot, resolved.taskId, 'task-orchestration.prepare', () => prepareOrchestrationDelegationUnlocked(taskRef, input, options));
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
if (error instanceof TaskExecutionLockError)
|
|
565
|
+
return failed(error.code, error.message, resolved.taskId);
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function matchingDelegations(client, predicate, options) {
|
|
570
|
+
const repoRoot = options.repoRoot ?? process.cwd();
|
|
571
|
+
const activeRoot = path.join(repoRoot, '.agents', 'workspace', 'active');
|
|
572
|
+
if (!fs.existsSync(activeRoot))
|
|
573
|
+
return [];
|
|
574
|
+
return fs.readdirSync(activeRoot, { withFileTypes: true })
|
|
575
|
+
.filter((entry) => entry.isDirectory())
|
|
576
|
+
.flatMap((entry) => {
|
|
577
|
+
const run = readRun(path.join(activeRoot, entry.name));
|
|
578
|
+
if (!run?.pendingDelegation)
|
|
579
|
+
return [];
|
|
580
|
+
const receipt = run.pendingDelegation;
|
|
581
|
+
return receipt.client === client && predicate(receipt)
|
|
582
|
+
? [{ taskId: entry.name, run }]
|
|
583
|
+
: [];
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function uniqueMatchingDelegation(client, predicate, options) {
|
|
587
|
+
const matches = matchingDelegations(client, predicate, options);
|
|
588
|
+
if (matches.length === 0)
|
|
589
|
+
return failed('ORCHESTRATION_DELEGATION_MISSING', 'no matching lifecycle delegation exists');
|
|
590
|
+
if (matches.length > 1)
|
|
591
|
+
return failed('ORCHESTRATION_DELEGATION_AMBIGUOUS', 'multiple lifecycle delegations match the native hook event');
|
|
592
|
+
return matches[0];
|
|
593
|
+
}
|
|
594
|
+
function activateMatchingOrchestrationDelegation(client, event, options = {}) {
|
|
595
|
+
const role = managedDelegationRole(event.nativeAgent);
|
|
596
|
+
if (!role)
|
|
597
|
+
return failed('DELEGATION_IGNORED', `subagent '${event.nativeAgent}' is not lifecycle-managed`);
|
|
598
|
+
const matched = uniqueMatchingDelegation(client, (receipt) => receipt.status === 'prepared', options);
|
|
599
|
+
if ('status' in matched)
|
|
600
|
+
return matched;
|
|
601
|
+
if (matched.run.receipts.some((receipt) => receipt.childId === event.childId)) {
|
|
602
|
+
return pauseOrchestration(matched.taskId, 'DELEGATION_IDENTITY_REUSED', 'native child identity was already used by this run', true, options);
|
|
603
|
+
}
|
|
604
|
+
return activateOrchestrationDelegation(matched.taskId, event, options);
|
|
605
|
+
}
|
|
606
|
+
function sealMatchingOrchestrationDelegation(client, event, options = {}) {
|
|
607
|
+
const role = managedDelegationRole(event.nativeAgent);
|
|
608
|
+
if (!role)
|
|
609
|
+
return failed('DELEGATION_IGNORED', `subagent '${event.nativeAgent}' is not lifecycle-managed`);
|
|
610
|
+
const matched = uniqueMatchingDelegation(client, (receipt) => receipt.status !== 'prepared', options);
|
|
611
|
+
if ('status' in matched)
|
|
612
|
+
return matched;
|
|
613
|
+
const receipt = matched.run.pendingDelegation;
|
|
614
|
+
if (receipt.role !== role) {
|
|
615
|
+
return pauseOrchestration(matched.taskId, 'DELEGATION_ROLE_MISMATCH', `managed role ${role} does not match ${receipt.role}`, true, options);
|
|
616
|
+
}
|
|
617
|
+
const repoRoot = options.repoRoot ?? process.cwd();
|
|
618
|
+
try {
|
|
619
|
+
const snapshotTaskId = receipt.workspaceSnapshotScope === 'task' ? receipt.taskId : null;
|
|
620
|
+
const afterFingerprint = (options.captureWorkspace ?? captureWorkspaceSnapshot)(repoRoot, snapshotTaskId);
|
|
621
|
+
const changedPaths = (options.diffWorkspace ?? diffWorkspaceSnapshots)(repoRoot, receipt.beforeFingerprint, afterFingerprint);
|
|
622
|
+
return sealOrchestrationDelegation(matched.taskId, {
|
|
623
|
+
childId: event.childId,
|
|
624
|
+
exitCode: 0,
|
|
625
|
+
afterFingerprint,
|
|
626
|
+
changedPaths
|
|
627
|
+
}, options);
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
return pauseOrchestration(matched.taskId, 'ORCHESTRATION_SNAPSHOT_FAILED', error instanceof Error ? error.message : String(error), true, options);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function activateOrchestrationDelegation(taskRef, event, options = {}) {
|
|
634
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
635
|
+
if (!resolved.ok)
|
|
636
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
637
|
+
const run = readRun(resolved.taskDir);
|
|
638
|
+
if (!run?.pendingDelegation)
|
|
639
|
+
return failed('ORCHESTRATION_DELEGATION_MISSING', 'no pending delegation exists', resolved.taskId);
|
|
640
|
+
const result = activateDelegation(run.pendingDelegation, event, { now: options.now });
|
|
641
|
+
if (!result.ok) {
|
|
642
|
+
if (result.code === 'DELEGATION_IGNORED')
|
|
643
|
+
return { status: run.status, changed: false, taskId: resolved.taskId, run, next: null, error: null };
|
|
644
|
+
return pauseOrchestration(taskRef, result.code, result.message, true, options);
|
|
645
|
+
}
|
|
646
|
+
const updated = withUpdatedRun(run, { pendingDelegation: result.receipt });
|
|
647
|
+
saveRun(resolved.taskDir, updated);
|
|
648
|
+
return { status: 'running', changed: true, taskId: resolved.taskId, run: updated, next: null, error: null };
|
|
649
|
+
}
|
|
650
|
+
function completeOrchestrationStage(taskRef, event, options = {}) {
|
|
651
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
652
|
+
if (!resolved.ok)
|
|
653
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
654
|
+
const run = readRun(resolved.taskDir);
|
|
655
|
+
if (!run)
|
|
656
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run: null, next: null, error: null };
|
|
657
|
+
if (!run.pendingDelegation)
|
|
658
|
+
return failed('ORCHESTRATION_DELEGATION_MISSING', 'active run has no pending delegation', resolved.taskId);
|
|
659
|
+
const result = completeDelegationStage(run.pendingDelegation, event);
|
|
660
|
+
if (!result.ok)
|
|
661
|
+
return pauseOrchestration(taskRef, result.code, result.message, true, options);
|
|
662
|
+
const updated = withUpdatedRun(run, { pendingDelegation: result.receipt });
|
|
663
|
+
saveRun(resolved.taskDir, updated);
|
|
664
|
+
return { status: 'running', changed: true, taskId: resolved.taskId, run: updated, next: null, error: null };
|
|
665
|
+
}
|
|
666
|
+
function inspectOrchestrationStage(taskRef, event, options = {}) {
|
|
667
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
668
|
+
if (!resolved.ok)
|
|
669
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
670
|
+
let run;
|
|
671
|
+
try {
|
|
672
|
+
run = readRun(resolved.taskDir);
|
|
673
|
+
}
|
|
674
|
+
catch (error) {
|
|
675
|
+
return failed('ORCHESTRATION_STATE_INVALID', error instanceof Error ? error.message : String(error), resolved.taskId);
|
|
676
|
+
}
|
|
677
|
+
if (!run)
|
|
678
|
+
return failed('ORCHESTRATION_RUN_MISSING', 'no orchestration run exists', resolved.taskId);
|
|
679
|
+
const receipt = run.pendingDelegation;
|
|
680
|
+
if (!receipt
|
|
681
|
+
|| receipt.status !== 'activated'
|
|
682
|
+
|| receipt.stage !== event.stage
|
|
683
|
+
|| receipt.round !== event.round
|
|
684
|
+
|| receipt.artifact !== event.artifact
|
|
685
|
+
|| receipt.role !== event.role) {
|
|
686
|
+
return failed('ORCHESTRATION_PROVENANCE_MISMATCH', 'active run does not have one matching activated delegation', resolved.taskId);
|
|
687
|
+
}
|
|
688
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run, next: null, error: null };
|
|
689
|
+
}
|
|
690
|
+
function planOrchestrationStageCompletion(taskRef, event, options = {}) {
|
|
691
|
+
const inspected = inspectOrchestrationStage(taskRef, event, options);
|
|
692
|
+
if (inspected.status === 'failed' || !inspected.run?.pendingDelegation) {
|
|
693
|
+
return { result: inspected, plan: null };
|
|
694
|
+
}
|
|
695
|
+
const receipt = inspected.run.pendingDelegation;
|
|
696
|
+
const completed = completeDelegationStage(receipt, event);
|
|
697
|
+
if (!completed.ok) {
|
|
698
|
+
return { result: failed(completed.code, completed.message, inspected.taskId), plan: null };
|
|
699
|
+
}
|
|
700
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
701
|
+
if (!resolved.ok)
|
|
702
|
+
return { result: failed(resolved.code, resolved.message, resolved.taskId), plan: null };
|
|
703
|
+
const updatedRun = withUpdatedRun(inspected.run, { pendingDelegation: completed.receipt });
|
|
704
|
+
return {
|
|
705
|
+
result: { status: 'running', changed: true, taskId: resolved.taskId, run: updatedRun, next: null, error: null },
|
|
706
|
+
plan: {
|
|
707
|
+
taskId: resolved.taskId,
|
|
708
|
+
taskDir: resolved.taskDir,
|
|
709
|
+
updatedRun
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
function commitOrchestrationStageCompletion(plan) {
|
|
714
|
+
saveRun(plan.taskDir, plan.updatedRun);
|
|
715
|
+
}
|
|
716
|
+
function completeCommitOrchestrationStage(taskRef, agent, options = {}) {
|
|
717
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
718
|
+
if (!resolved.ok)
|
|
719
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
720
|
+
const run = readRun(resolved.taskDir);
|
|
721
|
+
if (!run)
|
|
722
|
+
return { status: 'running', changed: false, taskId: resolved.taskId, run: null, next: null, error: null };
|
|
723
|
+
const receipt = run.pendingDelegation;
|
|
724
|
+
if (!receipt || receipt.stage !== 'commit') {
|
|
725
|
+
return failed('ORCHESTRATION_DELEGATION_MISSING', 'active run has no pending commit delegation', resolved.taskId);
|
|
726
|
+
}
|
|
727
|
+
return completeOrchestrationStage(taskRef, {
|
|
728
|
+
stage: receipt.stage,
|
|
729
|
+
round: receipt.round,
|
|
730
|
+
artifact: receipt.artifact,
|
|
731
|
+
agent
|
|
732
|
+
}, options);
|
|
733
|
+
}
|
|
734
|
+
function sealOrchestrationDelegation(taskRef, event, options = {}) {
|
|
735
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
736
|
+
if (!resolved.ok)
|
|
737
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
738
|
+
const run = readRun(resolved.taskDir);
|
|
739
|
+
if (!run?.pendingDelegation)
|
|
740
|
+
return failed('ORCHESTRATION_DELEGATION_MISSING', 'no pending delegation exists', resolved.taskId);
|
|
741
|
+
const result = sealDelegation(run.pendingDelegation, event, { now: options.now });
|
|
742
|
+
if (!result.ok)
|
|
743
|
+
return pauseOrchestration(taskRef, result.code, result.message, true, options);
|
|
744
|
+
const updated = withUpdatedRun(run, { pendingDelegation: result.receipt });
|
|
745
|
+
saveRun(resolved.taskDir, updated);
|
|
746
|
+
return { status: 'running', changed: true, taskId: resolved.taskId, run: updated, next: null, error: null };
|
|
747
|
+
}
|
|
748
|
+
function advanceOrchestration(taskRef, options = {}) {
|
|
749
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
750
|
+
if (!resolved.ok)
|
|
751
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
752
|
+
const run = readRun(resolved.taskDir);
|
|
753
|
+
if (!run?.pendingDelegation)
|
|
754
|
+
return failed('ORCHESTRATION_DELEGATION_MISSING', 'no pending delegation exists', resolved.taskId);
|
|
755
|
+
const result = consumeDelegation(run.pendingDelegation, { now: options.now });
|
|
756
|
+
if (!result.ok)
|
|
757
|
+
return pauseOrchestration(taskRef, result.code, result.message, true, options);
|
|
758
|
+
const completed = result.receipt.stage === 'commit';
|
|
759
|
+
const updated = withUpdatedRun(run, {
|
|
760
|
+
status: completed ? 'completed' : 'running',
|
|
761
|
+
nextStage: null,
|
|
762
|
+
stepCount: run.stepCount + 1,
|
|
763
|
+
pendingDelegation: null,
|
|
764
|
+
receipts: Object.freeze([...run.receipts, result.receipt]),
|
|
765
|
+
commitAuthorization: completed
|
|
766
|
+
? { ...run.commitAuthorization, consumedAt: (options.now ?? (() => new Date().toISOString()))() }
|
|
767
|
+
: run.commitAuthorization
|
|
768
|
+
});
|
|
769
|
+
saveRun(resolved.taskDir, updated);
|
|
770
|
+
return { status: updated.status, changed: true, taskId: resolved.taskId, run: updated, next: null, error: null };
|
|
771
|
+
}
|
|
772
|
+
function pauseOrchestration(taskRef, code, message, recoverable, options = {}) {
|
|
773
|
+
const resolved = resolveTaskRef(taskRef, { repoRoot: options.repoRoot });
|
|
774
|
+
if (!resolved.ok)
|
|
775
|
+
return failed(resolved.code, resolved.message, resolved.taskId);
|
|
776
|
+
const run = readRun(resolved.taskDir);
|
|
777
|
+
if (!run)
|
|
778
|
+
return failed('ORCHESTRATION_RUN_MISSING', 'no orchestration run exists', resolved.taskId);
|
|
779
|
+
const updated = withUpdatedRun(run, { status: 'paused', pause: { code, message, recoverable } });
|
|
780
|
+
saveRun(resolved.taskDir, updated);
|
|
781
|
+
return { status: 'paused', changed: true, taskId: resolved.taskId, run: updated, next: null, error: null };
|
|
782
|
+
}
|
|
783
|
+
export { activateMatchingOrchestrationDelegation, activateOrchestrationDelegation, advanceOrchestration, beginOrResumeOrchestration, commitOrchestrationStageCompletion, completeCommitOrchestrationStage, completeOrchestrationStage, inspectOrchestrationStage, orchestrationPath, pauseOrchestration, planOrchestrationStageCompletion, prepareOrchestrationDelegation, readRun, routeOrchestration, sealMatchingOrchestrationDelegation, sealOrchestrationDelegation, statusOrchestration };
|
|
784
|
+
//# sourceMappingURL=orchestration.js.map
|