@fitlab-ai/agent-infra 0.8.5 → 0.9.1
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 +6 -1
- package/README.zh-CN.md +5 -1
- package/bin/cli.ts +2 -2
- package/dist/bin/cli.js +2 -2
- package/dist/bin/internal-cli.js +103 -0
- package/dist/lib/decide.js +81 -90
- package/dist/lib/defaults.json +1 -0
- package/dist/lib/git/review-snapshot.js +79 -0
- package/dist/lib/git/workflow.js +101 -0
- package/dist/lib/internal/git-workflow.js +42 -0
- package/dist/lib/internal/platform-checks.js +119 -0
- package/dist/lib/internal/platform-comment.js +129 -0
- package/dist/lib/internal/platform-context.js +46 -0
- package/dist/lib/internal/platform-issue.js +142 -0
- package/dist/lib/internal/platform-pr.js +146 -0
- package/dist/lib/internal/platform-release-notes.js +53 -0
- package/dist/lib/internal/release-workflow.js +320 -0
- package/dist/lib/internal/task-artifact.js +67 -0
- package/dist/lib/internal/task-context.js +43 -0
- package/dist/lib/internal/task-event.js +70 -0
- package/dist/lib/internal/task-ledger.js +114 -0
- package/dist/lib/internal/task-lifecycle.js +58 -0
- package/dist/lib/internal/task-short-id.js +83 -0
- package/dist/lib/internal/task-snapshot.js +47 -0
- package/dist/lib/internal/task-verify.js +50 -0
- package/dist/lib/internal/task-warning.js +74 -0
- package/dist/lib/platform/adapters.js +14 -0
- package/dist/lib/platform/context.js +146 -0
- package/dist/lib/platform/github-client.js +124 -0
- package/dist/lib/platform/github-release-notes.js +96 -0
- package/dist/lib/platform/issue-comments.js +409 -0
- package/dist/lib/platform/issue-metadata.js +183 -0
- package/dist/lib/platform/issues.js +619 -0
- package/dist/lib/platform/merged-pr-equivalence.js +54 -0
- package/dist/lib/platform/metadata-labels.js +28 -0
- package/dist/lib/platform/pr-checks.js +216 -0
- package/dist/lib/platform/pr-summary.js +88 -0
- package/dist/lib/platform/pull-request-metadata.js +38 -0
- package/dist/lib/platform/pull-requests.js +340 -0
- package/dist/lib/platform/release-notes.js +143 -0
- package/dist/lib/platform/releases.js +82 -0
- package/dist/lib/platform/types.js +22 -0
- package/dist/lib/platform/verification-required.js +102 -0
- package/dist/lib/platform/verification-sync.js +1014 -0
- package/dist/lib/platform/verification.js +6 -0
- package/dist/lib/release/channels.js +31 -0
- package/dist/lib/release/workflow.js +32 -0
- package/dist/lib/render.js +3 -2
- package/dist/lib/run/index.js +24 -7
- package/dist/lib/sandbox/build-proxy.js +63 -0
- package/dist/lib/sandbox/capture.js +25 -3
- package/dist/lib/sandbox/commands/create.js +93 -31
- package/dist/lib/sandbox/commands/enter.js +34 -11
- package/dist/lib/sandbox/commands/list-running.js +10 -8
- package/dist/lib/sandbox/commands/rebuild.js +24 -7
- package/dist/lib/sandbox/commands/show.js +2 -2
- package/dist/lib/sandbox/commands/start.js +53 -15
- package/dist/lib/sandbox/image-build.js +2 -1
- package/dist/lib/sandbox/index.js +6 -6
- package/dist/lib/sandbox/mounts.js +36 -0
- package/dist/lib/sandbox/recovery.js +562 -0
- package/dist/lib/sandbox/runtimes/ai-tools.dockerfile +24 -3
- package/dist/lib/sandbox/runtimes/base.dockerfile +8 -1
- package/dist/lib/sandbox/runtimes/java17.dockerfile +8 -1
- package/dist/lib/sandbox/runtimes/java21.dockerfile +8 -1
- package/dist/lib/sandbox/runtimes/node20.dockerfile +8 -1
- package/dist/lib/sandbox/runtimes/node22.dockerfile +8 -1
- package/dist/lib/sandbox/runtimes/python3.dockerfile +8 -1
- package/dist/lib/sandbox/shell.js +2 -1
- package/dist/lib/sandbox/task-resolver.js +5 -1
- package/dist/lib/sandbox/tools.js +19 -0
- package/dist/lib/server/protocol.js +5 -5
- package/dist/lib/task/activity-log.js +61 -0
- package/dist/lib/task/artifact-lifecycle.js +427 -0
- package/dist/lib/task/command-options.js +30 -0
- package/dist/lib/task/commands/cat.js +36 -6
- package/dist/lib/task/commands/decisions.js +80 -46
- package/dist/lib/task/commands/files.js +21 -7
- package/dist/lib/task/commands/grep.js +55 -7
- package/dist/lib/task/commands/issue-body.js +33 -19
- package/dist/lib/task/commands/log.js +27 -70
- package/dist/lib/task/commands/show.js +20 -7
- package/dist/lib/task/commands/status.js +18 -8
- package/dist/lib/task/decision-intents.js +154 -0
- package/dist/lib/task/decision-items.js +53 -0
- package/dist/lib/task/events.js +318 -0
- package/dist/lib/task/frontmatter.js +159 -1
- package/dist/lib/task/implementation-inputs.js +117 -0
- package/dist/lib/task/index.js +12 -9
- package/dist/lib/task/issue-form.js +21 -6
- package/dist/lib/task/ledger-intents.js +185 -0
- package/dist/lib/task/ledger.js +65 -35
- package/dist/lib/task/lifecycle.js +484 -0
- package/dist/lib/task/resolve-ref.js +152 -32
- package/dist/lib/task/review-artifacts.js +101 -0
- package/dist/lib/task/review-fingerprint.js +55 -0
- package/dist/lib/task/sections.js +358 -4
- package/dist/lib/task/short-id.js +292 -7
- package/dist/lib/task/snapshot.js +95 -0
- package/dist/lib/task/verification-checks.js +8 -0
- package/dist/lib/task/verification-config.js +14 -0
- package/dist/lib/task/verification-engine.js +923 -0
- package/dist/lib/task/verification-review.js +3 -0
- package/dist/lib/task/verification-types.js +2 -0
- package/dist/lib/task/verification.js +113 -0
- package/dist/lib/task/workflow-warning-intents.js +131 -0
- package/dist/lib/task/workflow-warnings.js +10 -78
- package/dist/lib/task/write.js +241 -0
- package/lib/decide.ts +57 -97
- package/lib/defaults.json +1 -0
- package/lib/git/review-snapshot.ts +73 -0
- package/lib/git/workflow.ts +101 -0
- package/lib/internal/git-workflow.ts +37 -0
- package/lib/internal/platform-checks.ts +101 -0
- package/lib/internal/platform-comment.ts +99 -0
- package/lib/internal/platform-context.ts +33 -0
- package/lib/internal/platform-issue.ts +116 -0
- package/lib/internal/platform-pr.ts +119 -0
- package/lib/internal/platform-release-notes.ts +55 -0
- package/lib/internal/release-workflow.ts +288 -0
- package/lib/internal/task-artifact.ts +47 -0
- package/lib/internal/task-context.ts +35 -0
- package/lib/internal/task-event.ts +51 -0
- package/lib/internal/task-ledger.ts +86 -0
- package/lib/internal/task-lifecycle.ts +41 -0
- package/lib/internal/task-short-id.ts +55 -0
- package/lib/internal/task-snapshot.ts +32 -0
- package/lib/internal/task-verify.ts +33 -0
- package/lib/internal/task-warning.ts +50 -0
- package/lib/platform/adapters.ts +30 -0
- package/lib/platform/context.ts +164 -0
- package/lib/platform/github-client.ts +146 -0
- package/lib/platform/github-release-notes.ts +132 -0
- package/lib/platform/issue-comments.ts +479 -0
- package/lib/platform/issue-metadata.ts +250 -0
- package/lib/platform/issues.ts +693 -0
- package/lib/platform/merged-pr-equivalence.ts +70 -0
- package/lib/platform/metadata-labels.ts +33 -0
- package/lib/platform/pr-checks.ts +247 -0
- package/lib/platform/pr-summary.ts +90 -0
- package/lib/platform/pull-request-metadata.ts +69 -0
- package/lib/platform/pull-requests.ts +386 -0
- package/lib/platform/release-notes.ts +167 -0
- package/lib/platform/releases.ts +71 -0
- package/lib/platform/types.ts +74 -0
- package/lib/platform/verification-required.ts +109 -0
- package/{runtime/platform-adapters/platform-sync.github.js → lib/platform/verification-sync.ts} +198 -367
- package/lib/platform/verification.ts +11 -0
- package/lib/release/channels.ts +30 -0
- package/lib/release/workflow.ts +31 -0
- package/lib/render.ts +3 -2
- package/lib/run/index.ts +25 -7
- package/lib/sandbox/build-proxy.ts +94 -0
- package/lib/sandbox/capture.ts +29 -3
- package/lib/sandbox/commands/create.ts +120 -36
- package/lib/sandbox/commands/enter.ts +38 -11
- package/lib/sandbox/commands/list-running.ts +10 -8
- package/lib/sandbox/commands/rebuild.ts +29 -7
- package/lib/sandbox/commands/show.ts +2 -2
- package/lib/sandbox/commands/start.ts +50 -16
- package/lib/sandbox/image-build.ts +4 -1
- package/lib/sandbox/index.ts +6 -6
- package/lib/sandbox/mounts.ts +55 -0
- package/lib/sandbox/recovery.ts +828 -0
- package/lib/sandbox/runtimes/ai-tools.dockerfile +24 -3
- package/lib/sandbox/runtimes/base.dockerfile +8 -1
- package/lib/sandbox/runtimes/java17.dockerfile +8 -1
- package/lib/sandbox/runtimes/java21.dockerfile +8 -1
- package/lib/sandbox/runtimes/node20.dockerfile +8 -1
- package/lib/sandbox/runtimes/node22.dockerfile +8 -1
- package/lib/sandbox/runtimes/python3.dockerfile +8 -1
- package/lib/sandbox/shell.ts +3 -1
- package/lib/sandbox/task-resolver.ts +5 -1
- package/lib/sandbox/tools.ts +31 -0
- package/lib/server/protocol.ts +5 -5
- package/lib/task/activity-log.ts +62 -0
- package/lib/task/artifact-lifecycle.ts +484 -0
- package/lib/task/command-options.ts +32 -0
- package/lib/task/commands/cat.ts +22 -9
- package/lib/task/commands/decisions.ts +49 -47
- package/lib/task/commands/files.ts +14 -6
- package/lib/task/commands/grep.ts +34 -7
- package/lib/task/commands/issue-body.ts +26 -21
- package/lib/task/commands/log.ts +17 -70
- package/lib/task/commands/show.ts +14 -6
- package/lib/task/commands/status.ts +17 -7
- package/lib/task/decision-intents.ts +163 -0
- package/lib/task/decision-items.ts +64 -0
- package/lib/task/events.ts +320 -0
- package/lib/task/frontmatter.ts +202 -2
- package/lib/task/implementation-inputs.ts +137 -0
- package/lib/task/index.ts +12 -9
- package/lib/task/issue-form.ts +24 -6
- package/lib/task/ledger-intents.ts +201 -0
- package/lib/task/ledger.ts +77 -31
- package/lib/task/lifecycle.ts +458 -0
- package/lib/task/resolve-ref.ts +197 -36
- package/{templates/.agents/scripts/lib/review-artifacts.js → lib/task/review-artifacts.ts} +11 -12
- package/{templates/.agents/scripts/lib/post-review-commit.js → lib/task/review-fingerprint.ts} +26 -12
- package/lib/task/sections.ts +486 -4
- package/lib/task/short-id.ts +403 -9
- package/lib/task/snapshot.ts +143 -0
- package/lib/task/verification-checks.ts +9 -0
- package/lib/task/verification-config.ts +20 -0
- package/{templates/.agents/scripts/validate-artifact.js → lib/task/verification-engine.ts} +230 -421
- package/lib/task/verification-review.ts +10 -0
- package/lib/task/verification-types.ts +29 -0
- package/lib/task/verification.ts +156 -0
- package/lib/task/workflow-warning-intents.ts +142 -0
- package/lib/task/workflow-warnings.ts +10 -78
- package/lib/task/write.ts +468 -0
- package/package.json +4 -2
- package/templates/.agents/README.en.md +4 -3
- package/templates/.agents/README.zh-CN.md +4 -3
- package/templates/.agents/rules/README.en.md +6 -5
- package/templates/.agents/rules/README.zh-CN.md +6 -5
- package/templates/.agents/rules/create-issue.en.md +1 -1
- package/templates/.agents/rules/create-issue.github.en.md +5 -184
- package/templates/.agents/rules/create-issue.github.zh-CN.md +12 -178
- package/templates/.agents/rules/create-issue.zh-CN.md +1 -1
- package/templates/.agents/rules/human-decision-context.en.md +36 -0
- package/templates/.agents/rules/human-decision-context.zh-CN.md +36 -0
- package/templates/.agents/rules/issue-fields.github.en.md +4 -148
- package/templates/.agents/rules/issue-fields.github.zh-CN.md +9 -144
- package/templates/.agents/rules/issue-pr-commands.en.md +43 -3
- package/templates/.agents/rules/issue-pr-commands.github.en.md +15 -220
- package/templates/.agents/rules/issue-pr-commands.github.zh-CN.md +23 -213
- package/templates/.agents/rules/issue-pr-commands.zh-CN.md +45 -3
- package/templates/.agents/rules/issue-sync.en.md +1 -1
- package/templates/.agents/rules/issue-sync.github.en.md +14 -301
- package/templates/.agents/rules/issue-sync.github.zh-CN.md +36 -287
- package/templates/.agents/rules/issue-sync.zh-CN.md +1 -1
- package/templates/.agents/rules/milestone-inference.en.md +1 -1
- package/templates/.agents/rules/milestone-inference.github.en.md +7 -119
- package/templates/.agents/rules/milestone-inference.github.zh-CN.md +8 -108
- package/templates/.agents/rules/milestone-inference.zh-CN.md +1 -1
- package/templates/.agents/rules/next-step-output.en.md +12 -11
- package/templates/.agents/rules/next-step-output.zh-CN.md +12 -11
- package/templates/.agents/rules/no-mid-flow-questions.en.md +3 -3
- package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +3 -3
- package/templates/.agents/rules/pr-checks-commands.en.md +16 -3
- package/templates/.agents/rules/pr-checks-commands.github.en.md +10 -54
- package/templates/.agents/rules/pr-checks-commands.github.zh-CN.md +19 -47
- package/templates/.agents/rules/pr-checks-commands.zh-CN.md +30 -3
- package/templates/.agents/rules/pr-sync.en.md +30 -3
- package/templates/.agents/rules/pr-sync.github.en.md +12 -115
- package/templates/.agents/rules/pr-sync.github.zh-CN.md +26 -104
- package/templates/.agents/rules/pr-sync.zh-CN.md +43 -3
- package/templates/.agents/rules/release-commands.en.md +2 -2
- package/templates/.agents/rules/release-commands.github.en.md +10 -40
- package/templates/.agents/rules/release-commands.github.zh-CN.md +9 -39
- package/templates/.agents/rules/release-commands.zh-CN.md +2 -2
- package/templates/.agents/rules/review-handshake.en.md +10 -6
- package/templates/.agents/rules/review-handshake.zh-CN.md +10 -6
- package/templates/.agents/rules/task-management.en.md +11 -2
- package/templates/.agents/rules/task-management.zh-CN.md +11 -3
- package/templates/.agents/rules/task-short-id.en.md +25 -29
- package/templates/.agents/rules/task-short-id.zh-CN.md +20 -23
- package/templates/.agents/rules/testing-discipline.en.md +20 -2
- package/templates/.agents/rules/testing-discipline.zh-CN.md +20 -2
- package/templates/.agents/scripts/lib/agent-infra-package.js +1 -9
- package/templates/.agents/scripts/task-short-id.js +71 -533
- package/templates/.agents/skills/analyze-task/SKILL.en.md +26 -56
- package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +30 -60
- package/templates/.agents/skills/analyze-task/config/verify.en.json +1 -3
- package/templates/.agents/skills/analyze-task/config/verify.zh-CN.json +1 -3
- package/templates/.agents/skills/block-task/SKILL.en.md +21 -47
- package/templates/.agents/skills/block-task/SKILL.zh-CN.md +23 -47
- package/templates/.agents/skills/block-task/config/verify.json +1 -2
- package/templates/.agents/skills/cancel-task/SKILL.en.md +16 -45
- package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +16 -45
- package/templates/.agents/skills/cancel-task/config/verify.json +1 -2
- package/templates/.agents/skills/check-task/SKILL.en.md +6 -3
- package/templates/.agents/skills/check-task/SKILL.zh-CN.md +6 -3
- package/templates/.agents/skills/close-codescan/SKILL.en.md +6 -24
- package/templates/.agents/skills/close-codescan/SKILL.zh-CN.md +6 -24
- package/templates/.agents/skills/close-dependabot/SKILL.en.md +6 -24
- package/templates/.agents/skills/close-dependabot/SKILL.zh-CN.md +6 -24
- package/templates/.agents/skills/code-task/SKILL.en.md +22 -35
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +28 -44
- package/templates/.agents/skills/code-task/config/verify.en.json +3 -3
- package/templates/.agents/skills/code-task/config/verify.zh-CN.json +3 -3
- package/templates/.agents/skills/code-task/reference/dual-mode.en.md +13 -9
- package/templates/.agents/skills/code-task/reference/dual-mode.zh-CN.md +13 -9
- package/templates/.agents/skills/code-task/reference/fix-mode.en.md +1 -1
- package/templates/.agents/skills/code-task/reference/fix-mode.zh-CN.md +1 -1
- package/templates/.agents/skills/code-task/reference/report-template.en.md +11 -1
- package/templates/.agents/skills/code-task/reference/report-template.zh-CN.md +11 -1
- package/templates/.agents/skills/commit/SKILL.en.md +13 -11
- package/templates/.agents/skills/commit/SKILL.zh-CN.md +13 -11
- package/templates/.agents/skills/commit/config/verify.json +1 -2
- package/templates/.agents/skills/commit/reference/commit-message.en.md +1 -11
- package/templates/.agents/skills/commit/reference/commit-message.zh-CN.md +1 -11
- package/templates/.agents/skills/commit/reference/issue-metadata-sync.en.md +4 -8
- package/templates/.agents/skills/commit/reference/issue-metadata-sync.zh-CN.md +4 -8
- package/templates/.agents/skills/commit/reference/pr-summary-sync.en.md +6 -18
- package/templates/.agents/skills/commit/reference/pr-summary-sync.zh-CN.md +5 -17
- package/templates/.agents/skills/commit/reference/task-status-update.en.md +13 -0
- package/templates/.agents/skills/commit/reference/task-status-update.zh-CN.md +13 -0
- package/templates/.agents/skills/complete-manual-validation/SKILL.en.md +13 -36
- package/templates/.agents/skills/complete-manual-validation/SKILL.zh-CN.md +13 -36
- package/templates/.agents/skills/complete-manual-validation/config/verify.en.json +1 -3
- package/templates/.agents/skills/complete-manual-validation/config/verify.zh-CN.json +1 -3
- package/templates/.agents/skills/complete-manual-validation/reference/summary-update.en.md +10 -54
- package/templates/.agents/skills/complete-manual-validation/reference/summary-update.zh-CN.md +10 -79
- package/templates/.agents/skills/complete-task/SKILL.en.md +59 -63
- package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +59 -63
- package/templates/.agents/skills/complete-task/config/verify.en.json +10 -7
- package/templates/.agents/skills/complete-task/config/verify.zh-CN.json +10 -7
- package/templates/.agents/skills/create-pr/SKILL.en.md +19 -44
- package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +19 -43
- package/templates/.agents/skills/create-pr/config/verify.json +1 -2
- package/templates/.agents/skills/create-pr/reference/comment-publish.en.md +8 -12
- package/templates/.agents/skills/create-pr/reference/comment-publish.zh-CN.md +7 -11
- package/templates/.agents/skills/create-release-note/SKILL.en.md +17 -38
- package/templates/.agents/skills/create-release-note/SKILL.zh-CN.md +16 -37
- package/templates/.agents/skills/create-task/SKILL.en.md +16 -13
- package/templates/.agents/skills/create-task/SKILL.zh-CN.md +16 -13
- package/templates/.agents/skills/create-task/config/verify.json +1 -2
- package/templates/.agents/skills/create-task/reference/context-capture.en.md +29 -0
- package/templates/.agents/skills/create-task/reference/context-capture.zh-CN.md +29 -0
- package/templates/.agents/skills/import-codescan/SKILL.en.md +2 -2
- package/templates/.agents/skills/import-codescan/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/import-codescan/config/verify.json +1 -2
- package/templates/.agents/skills/import-dependabot/SKILL.en.md +2 -2
- package/templates/.agents/skills/import-dependabot/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/import-dependabot/config/verify.json +1 -2
- package/templates/.agents/skills/import-issue/SKILL.en.md +9 -13
- package/templates/.agents/skills/import-issue/SKILL.zh-CN.md +10 -14
- package/templates/.agents/skills/import-issue/config/verify.json +1 -2
- package/templates/.agents/skills/plan-task/SKILL.en.md +17 -42
- package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +22 -49
- package/templates/.agents/skills/plan-task/config/verify.en.json +1 -3
- package/templates/.agents/skills/plan-task/config/verify.zh-CN.json +1 -3
- package/templates/.agents/skills/post-release/SKILL.en.md +11 -81
- package/templates/.agents/skills/post-release/SKILL.zh-CN.md +8 -78
- 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 -163
- package/templates/.agents/skills/release/SKILL.zh-CN.md +15 -162
- package/templates/.agents/skills/restore-task/SKILL.en.md +11 -29
- package/templates/.agents/skills/restore-task/SKILL.zh-CN.md +11 -29
- package/templates/.agents/skills/restore-task/config/verify.json +1 -2
- package/templates/.agents/skills/review-analysis/SKILL.en.md +13 -25
- package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +13 -33
- package/templates/.agents/skills/review-analysis/config/verify.en.json +3 -4
- package/templates/.agents/skills/review-analysis/config/verify.zh-CN.json +3 -4
- package/templates/.agents/skills/review-analysis/reference/output-templates.en.md +9 -12
- package/templates/.agents/skills/review-analysis/reference/output-templates.zh-CN.md +9 -12
- package/templates/.agents/skills/review-analysis/reference/report-template.en.md +9 -2
- package/templates/.agents/skills/review-analysis/reference/report-template.zh-CN.md +9 -2
- package/templates/.agents/skills/review-analysis/reference/review-criteria.en.md +7 -0
- package/templates/.agents/skills/review-analysis/reference/review-criteria.zh-CN.md +7 -0
- package/templates/.agents/skills/review-code/SKILL.en.md +22 -36
- package/templates/.agents/skills/review-code/SKILL.zh-CN.md +23 -41
- package/templates/.agents/skills/review-code/config/verify.en.json +3 -4
- package/templates/.agents/skills/review-code/config/verify.zh-CN.json +3 -4
- package/templates/.agents/skills/review-code/reference/output-templates.en.md +56 -18
- package/templates/.agents/skills/review-code/reference/output-templates.zh-CN.md +56 -18
- package/templates/.agents/skills/review-code/reference/report-template.en.md +11 -4
- package/templates/.agents/skills/review-code/reference/report-template.zh-CN.md +11 -4
- package/templates/.agents/skills/review-code/reference/review-criteria.en.md +7 -0
- package/templates/.agents/skills/review-code/reference/review-criteria.zh-CN.md +7 -0
- package/templates/.agents/skills/review-plan/SKILL.en.md +13 -25
- package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +13 -33
- package/templates/.agents/skills/review-plan/config/verify.en.json +3 -4
- package/templates/.agents/skills/review-plan/config/verify.zh-CN.json +3 -4
- package/templates/.agents/skills/review-plan/reference/output-templates.en.md +9 -12
- package/templates/.agents/skills/review-plan/reference/output-templates.zh-CN.md +9 -12
- package/templates/.agents/skills/review-plan/reference/report-template.en.md +9 -2
- package/templates/.agents/skills/review-plan/reference/report-template.zh-CN.md +9 -2
- package/templates/.agents/skills/review-plan/reference/review-criteria.en.md +7 -0
- package/templates/.agents/skills/review-plan/reference/review-criteria.zh-CN.md +7 -0
- package/templates/.agents/skills/update-agent-infra/SKILL.en.md +1 -2
- package/templates/.agents/skills/update-agent-infra/SKILL.zh-CN.md +1 -2
- package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +3 -15
- package/templates/.agents/skills/watch-pr/SKILL.en.md +24 -14
- package/templates/.agents/skills/watch-pr/SKILL.zh-CN.md +25 -15
- package/templates/.agents/skills/watch-pr/config/verify.json +1 -2
- package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.en.md +2 -2
- package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.zh-CN.md +2 -2
- package/templates/.agents/templates/task.en.md +24 -1
- package/templates/.agents/templates/task.zh-CN.md +24 -1
- package/templates/.claude/commands/analyze-task.en.md +1 -1
- package/templates/.claude/commands/analyze-task.zh-CN.md +1 -1
- package/templates/.claude/commands/block-task.en.md +1 -1
- package/templates/.claude/commands/block-task.zh-CN.md +1 -1
- package/templates/.claude/commands/cancel-task.en.md +1 -1
- package/templates/.claude/commands/cancel-task.zh-CN.md +1 -1
- package/templates/.claude/commands/check-task.en.md +1 -1
- package/templates/.claude/commands/check-task.zh-CN.md +1 -1
- package/templates/.claude/commands/code-task.en.md +1 -1
- package/templates/.claude/commands/code-task.zh-CN.md +1 -1
- package/templates/.claude/commands/commit.en.md +1 -0
- package/templates/.claude/commands/commit.zh-CN.md +1 -0
- package/templates/.claude/commands/complete-manual-validation.en.md +1 -1
- package/templates/.claude/commands/complete-manual-validation.zh-CN.md +1 -1
- package/templates/.claude/commands/complete-task.en.md +1 -1
- package/templates/.claude/commands/complete-task.zh-CN.md +1 -1
- package/templates/.claude/commands/create-pr.en.md +1 -1
- package/templates/.claude/commands/create-pr.zh-CN.md +1 -1
- package/templates/.claude/commands/plan-task.en.md +1 -1
- package/templates/.claude/commands/plan-task.zh-CN.md +1 -1
- package/templates/.claude/commands/review-analysis.en.md +1 -1
- package/templates/.claude/commands/review-analysis.zh-CN.md +1 -1
- package/templates/.claude/commands/review-code.en.md +1 -1
- package/templates/.claude/commands/review-code.zh-CN.md +1 -1
- package/templates/.claude/commands/review-plan.en.md +1 -1
- package/templates/.claude/commands/review-plan.zh-CN.md +1 -1
- package/templates/.claude/commands/watch-pr.en.md +1 -1
- package/templates/.claude/commands/watch-pr.zh-CN.md +1 -1
- package/templates/.gemini/commands/_project_/analyze-task.en.toml +2 -0
- package/templates/.gemini/commands/_project_/analyze-task.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/block-task.en.toml +2 -0
- package/templates/.gemini/commands/_project_/block-task.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/cancel-task.en.toml +2 -0
- package/templates/.gemini/commands/_project_/cancel-task.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/check-task.en.toml +2 -0
- package/templates/.gemini/commands/_project_/check-task.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/code-task.en.toml +2 -0
- package/templates/.gemini/commands/_project_/code-task.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/commit.en.toml +4 -0
- package/templates/.gemini/commands/_project_/commit.zh-CN.toml +4 -0
- package/templates/.gemini/commands/_project_/complete-manual-validation.en.toml +2 -0
- package/templates/.gemini/commands/_project_/complete-manual-validation.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/complete-task.en.toml +2 -0
- package/templates/.gemini/commands/_project_/complete-task.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/create-pr.en.toml +2 -0
- package/templates/.gemini/commands/_project_/create-pr.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/plan-task.en.toml +2 -0
- package/templates/.gemini/commands/_project_/plan-task.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/review-analysis.en.toml +2 -0
- package/templates/.gemini/commands/_project_/review-analysis.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/review-code.en.toml +2 -0
- package/templates/.gemini/commands/_project_/review-code.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/review-plan.en.toml +2 -0
- package/templates/.gemini/commands/_project_/review-plan.zh-CN.toml +2 -0
- package/templates/.gemini/commands/_project_/watch-pr.en.toml +2 -0
- package/templates/.gemini/commands/_project_/watch-pr.zh-CN.toml +2 -0
- package/templates/.git-hooks/check-large-files.cjs +92 -0
- package/templates/.git-hooks/check-version-format.sh +5 -1
- package/templates/.git-hooks/pre-commit +1 -0
- package/templates/.opencode/commands/analyze-task.en.md +1 -1
- package/templates/.opencode/commands/analyze-task.zh-CN.md +1 -1
- package/templates/.opencode/commands/check-task.en.md +1 -1
- package/templates/.opencode/commands/check-task.zh-CN.md +1 -1
- package/templates/.opencode/commands/code-task.en.md +1 -1
- package/templates/.opencode/commands/code-task.zh-CN.md +1 -1
- package/templates/.opencode/commands/commit.en.md +2 -0
- package/templates/.opencode/commands/commit.zh-CN.md +2 -0
- package/templates/.opencode/commands/complete-task.en.md +1 -1
- package/templates/.opencode/commands/complete-task.zh-CN.md +1 -1
- package/templates/.opencode/commands/plan-task.en.md +1 -1
- package/templates/.opencode/commands/plan-task.zh-CN.md +1 -1
- package/templates/.opencode/commands/review-analysis.en.md +1 -1
- package/templates/.opencode/commands/review-analysis.zh-CN.md +1 -1
- package/templates/.opencode/commands/review-code.en.md +1 -1
- package/templates/.opencode/commands/review-code.zh-CN.md +1 -1
- package/templates/.opencode/commands/review-plan.en.md +1 -1
- package/templates/.opencode/commands/review-plan.zh-CN.md +1 -1
- package/templates/.agents/scripts/platform-adapters/platform-sync.github.js +0 -40
- package/templates/.agents/scripts/platform-adapters/platform-sync.js +0 -13
- package/templates/.agents/scripts/review-diff-fingerprint.js +0 -170
- package/templates/.agents/scripts/workflow-warnings.js +0 -290
- package/templates/.agents/skills/code-task/scripts/detect-mode.js +0 -257
- package/templates/.agents/skills/release/scripts/manage-milestones.github.sh +0 -80
- package/templates/.agents/skills/release/scripts/manage-milestones.sh +0 -6
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { appendActivityEntry, locateActivityLog } from './activity-log.js';
|
|
5
|
+
import { artifactFamilyCatalog, inspectArtifactDirectory, parseArtifactName } from './artifact-lifecycle.js';
|
|
6
|
+
import { parseTypedTaskFrontmatter } from './frontmatter.js';
|
|
7
|
+
import { locateHotTaskDirs, resolveTaskRef, TASK_ID_RE } from './resolve-ref.js';
|
|
8
|
+
import { configuredShortIdLength, executeShortIdCommand, loadShortIdByTaskId, mutateShortIdRegistry } from './short-id.js';
|
|
9
|
+
import { captureTaskWriteMetadata, writeTask } from './write.js';
|
|
10
|
+
const lifecycleIntentCatalog = [
|
|
11
|
+
'block', 'activate', 'cancel', 'complete', 'close-codescan', 'close-dependabot', 'restore'
|
|
12
|
+
];
|
|
13
|
+
const STEPS = ['task-written', 'directory-moved', 'registry-committed'];
|
|
14
|
+
const DEFAULT_IO = {
|
|
15
|
+
renameSync: (source, target) => fs.renameSync(source, target),
|
|
16
|
+
readFileSync: (file) => fs.readFileSync(file, 'utf8'),
|
|
17
|
+
writeFileSync: (file, content, flag) => fs.writeFileSync(file, content, { encoding: 'utf8', flag: flag ?? 'w' }),
|
|
18
|
+
unlinkSync: (file) => fs.unlinkSync(file)
|
|
19
|
+
};
|
|
20
|
+
function failed(request, error, extra = {}) {
|
|
21
|
+
return {
|
|
22
|
+
status: 'failed', changed: false, requestRef: request.taskRef, taskId: null,
|
|
23
|
+
intent: request.intent, sourceState: null, targetState: null, sourcePath: null,
|
|
24
|
+
targetPath: null, task: { operations: [] }, directory: { effect: 'unchanged', changed: false },
|
|
25
|
+
shortId: { effect: 'unchanged', shortId: null, changed: false }, timestamp: null,
|
|
26
|
+
agentInfraVersion: null, journalPath: null, completedSteps: [], pendingSteps: STEPS,
|
|
27
|
+
error, ...extra
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function normalizedRequest(request) {
|
|
31
|
+
if (!request || typeof request !== 'object' || !lifecycleIntentCatalog.includes(request.intent)) {
|
|
32
|
+
return { code: 'LIFECYCLE_PAYLOAD_INVALID', message: 'intent is not in the lifecycle catalog' };
|
|
33
|
+
}
|
|
34
|
+
if (typeof request.taskRef !== 'string' || !request.taskRef || typeof request.agent !== 'string' || !request.agent.trim()) {
|
|
35
|
+
return { code: 'LIFECYCLE_PAYLOAD_INVALID', message: 'taskRef and agent are required' };
|
|
36
|
+
}
|
|
37
|
+
const singleLine = (name, value) => {
|
|
38
|
+
if (typeof value !== 'string' || !value.trim() || /[\r\n]/.test(value)) {
|
|
39
|
+
return { code: 'LIFECYCLE_PAYLOAD_INVALID', message: `${name} must be a non-empty single line` };
|
|
40
|
+
}
|
|
41
|
+
return value.trim();
|
|
42
|
+
};
|
|
43
|
+
const agent = singleLine('agent', request.agent);
|
|
44
|
+
if (typeof agent !== 'string')
|
|
45
|
+
return agent;
|
|
46
|
+
if (request.intent === 'block') {
|
|
47
|
+
const reason = singleLine('reason', request.reason);
|
|
48
|
+
const unblockCondition = singleLine('unblockCondition', request.unblockCondition);
|
|
49
|
+
if (typeof reason !== 'string')
|
|
50
|
+
return reason;
|
|
51
|
+
if (typeof unblockCondition !== 'string')
|
|
52
|
+
return unblockCondition;
|
|
53
|
+
return { ...request, agent, reason, unblockCondition };
|
|
54
|
+
}
|
|
55
|
+
if (request.intent === 'activate') {
|
|
56
|
+
const note = singleLine('note', request.note);
|
|
57
|
+
return typeof note === 'string' ? { ...request, agent, note } : note;
|
|
58
|
+
}
|
|
59
|
+
if (request.intent === 'cancel' || request.intent === 'close-codescan' || request.intent === 'close-dependabot') {
|
|
60
|
+
const reason = singleLine('reason', request.reason);
|
|
61
|
+
if (typeof reason !== 'string')
|
|
62
|
+
return reason;
|
|
63
|
+
if (request.intent !== 'cancel' && (!Number.isSafeInteger(request.alertNumber) || request.alertNumber < 1)) {
|
|
64
|
+
return { code: 'LIFECYCLE_PAYLOAD_INVALID', message: 'alertNumber must be a positive integer' };
|
|
65
|
+
}
|
|
66
|
+
return { ...request, agent, reason };
|
|
67
|
+
}
|
|
68
|
+
if (request.intent === 'restore') {
|
|
69
|
+
if (typeof request.stagingDir !== 'string' || !request.stagingDir || !Number.isSafeInteger(request.issueNumber) || request.issueNumber < 1) {
|
|
70
|
+
return { code: 'LIFECYCLE_PAYLOAD_INVALID', message: 'restore requires stagingDir and a positive issueNumber' };
|
|
71
|
+
}
|
|
72
|
+
return { ...request, agent };
|
|
73
|
+
}
|
|
74
|
+
return { ...request, agent };
|
|
75
|
+
}
|
|
76
|
+
function intentIdentity(request, taskId) {
|
|
77
|
+
const payload = { taskId, intent: request.intent, agent: request.agent };
|
|
78
|
+
if ('reason' in request)
|
|
79
|
+
payload.reason = request.reason;
|
|
80
|
+
if ('unblockCondition' in request)
|
|
81
|
+
payload.unblockCondition = request.unblockCondition;
|
|
82
|
+
if ('note' in request)
|
|
83
|
+
payload.note = request.note;
|
|
84
|
+
if ('alertNumber' in request)
|
|
85
|
+
payload.alertNumber = request.alertNumber;
|
|
86
|
+
if ('issueNumber' in request)
|
|
87
|
+
payload.issueNumber = request.issueNumber;
|
|
88
|
+
return createHash('sha256').update(JSON.stringify(payload)).digest('hex');
|
|
89
|
+
}
|
|
90
|
+
function transition(request) {
|
|
91
|
+
if (request.intent === 'block')
|
|
92
|
+
return { sources: ['active'], target: 'blocked', registry: 'release' };
|
|
93
|
+
if (request.intent === 'activate')
|
|
94
|
+
return { sources: ['blocked'], target: 'active', registry: 'alloc' };
|
|
95
|
+
if (request.intent === 'cancel')
|
|
96
|
+
return { sources: ['active', 'blocked'], target: 'completed', registry: 'release' };
|
|
97
|
+
if (request.intent === 'restore')
|
|
98
|
+
return { sources: ['staging'], target: 'active', registry: 'alloc' };
|
|
99
|
+
return { sources: ['active'], target: 'completed', registry: 'release' };
|
|
100
|
+
}
|
|
101
|
+
function actionAndNote(request, restoredFiles = 0) {
|
|
102
|
+
if (request.intent === 'block')
|
|
103
|
+
return { action: 'Block Task', note: request.reason };
|
|
104
|
+
if (request.intent === 'activate')
|
|
105
|
+
return { action: 'Activate Task', note: request.note };
|
|
106
|
+
if (request.intent === 'cancel')
|
|
107
|
+
return { action: 'Cancel Task', note: request.reason };
|
|
108
|
+
if (request.intent === 'complete')
|
|
109
|
+
return { action: 'Complete Task', note: 'Task moved to completed/' };
|
|
110
|
+
if (request.intent === 'close-codescan')
|
|
111
|
+
return { action: 'Close Codescan', note: `Code Scanning alert #${request.alertNumber} dismissed: ${request.reason}` };
|
|
112
|
+
if (request.intent === 'close-dependabot')
|
|
113
|
+
return { action: 'Close Dependabot', note: `Dependabot alert #${request.alertNumber} dismissed: ${request.reason}` };
|
|
114
|
+
return { action: 'Restore Task', note: `Restored ${restoredFiles} files from Issue #${request.issueNumber}` };
|
|
115
|
+
}
|
|
116
|
+
function matchingCompletion(content, request, restoredFiles = 0) {
|
|
117
|
+
const section = locateActivityLog(content);
|
|
118
|
+
if (!section)
|
|
119
|
+
return false;
|
|
120
|
+
const identity = actionAndNote(request, restoredFiles);
|
|
121
|
+
return section.entries.some((entry) => entry.step === identity.action && entry.agent === request.agent && entry.note === identity.note);
|
|
122
|
+
}
|
|
123
|
+
function validateRestoreStaging(request, repoRoot, taskId) {
|
|
124
|
+
const workspace = path.resolve(repoRoot, '.agents', 'workspace');
|
|
125
|
+
const stagingDir = path.resolve(request.stagingDir);
|
|
126
|
+
const relative = path.relative(workspace, stagingDir);
|
|
127
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative) || path.basename(stagingDir) === taskId) {
|
|
128
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: 'restore staging must be a non-final directory inside .agents/workspace' };
|
|
129
|
+
}
|
|
130
|
+
let entries;
|
|
131
|
+
try {
|
|
132
|
+
entries = fs.readdirSync(stagingDir, { withFileTypes: true });
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: String(error) };
|
|
136
|
+
}
|
|
137
|
+
for (const entry of entries) {
|
|
138
|
+
const stat = fs.lstatSync(path.join(stagingDir, entry.name));
|
|
139
|
+
if (stat.isSymbolicLink() || !stat.isFile() || (entry.name !== 'task.md' && entry.name !== '.task-lifecycle.json' && !parseArtifactName(entry.name))) {
|
|
140
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: `unsupported restore entry '${entry.name}'` };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
if (fs.statSync(workspace).dev !== fs.statSync(stagingDir).dev) {
|
|
145
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: 'restore staging and active workspace must share a filesystem' };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: String(error) };
|
|
150
|
+
}
|
|
151
|
+
const taskFile = path.join(stagingDir, 'task.md');
|
|
152
|
+
if (!fs.existsSync(taskFile))
|
|
153
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: 'restore staging has no task.md' };
|
|
154
|
+
try {
|
|
155
|
+
const frontmatter = parseTypedTaskFrontmatter(fs.readFileSync(taskFile, 'utf8'));
|
|
156
|
+
if (frontmatter.id !== taskId || Number(frontmatter.issue_number) !== request.issueNumber || frontmatter.current_step === 'completed') {
|
|
157
|
+
return { code: 'LIFECYCLE_STAGING_IDENTITY_INVALID', message: 'restore task identity, issue, or current_step is invalid' };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: error instanceof Error ? error.message : String(error) };
|
|
162
|
+
}
|
|
163
|
+
for (const family of artifactFamilyCatalog) {
|
|
164
|
+
const inventory = inspectArtifactDirectory(stagingDir, family.family);
|
|
165
|
+
if (inventory.diagnostics.some((item) => item.code !== 'BROKEN_REFERENCE')) {
|
|
166
|
+
return { code: 'LIFECYCLE_STAGING_INVALID', message: `restore artifact topology is invalid for ${family.family}` };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return { stagingDir, fileCount: entries.filter((entry) => !entry.name.startsWith('.')).length };
|
|
170
|
+
}
|
|
171
|
+
function mutationsFor(request, content, metadata, restoredFiles) {
|
|
172
|
+
const section = locateActivityLog(content);
|
|
173
|
+
if (!section)
|
|
174
|
+
return { code: 'LIFECYCLE_LOG_MISSING', message: 'task has no unique Activity Log section' };
|
|
175
|
+
const identity = actionAndNote(request, restoredFiles);
|
|
176
|
+
let body = appendActivityEntry(section, { time: metadata.timestamp, step: `${identity.action} [started]`, agent: request.agent, note: 'started' });
|
|
177
|
+
body = appendActivityEntry({ ...section, body }, { time: metadata.timestamp, step: identity.action, agent: request.agent, note: identity.note });
|
|
178
|
+
const set = {};
|
|
179
|
+
const remove = [];
|
|
180
|
+
if (request.intent === 'block') {
|
|
181
|
+
set.status = 'blocked';
|
|
182
|
+
set.blocked_at = metadata.timestamp;
|
|
183
|
+
remove.push('completed_at', 'cancelled_at', 'cancel_reason');
|
|
184
|
+
}
|
|
185
|
+
else if (request.intent === 'activate' || request.intent === 'restore') {
|
|
186
|
+
set.status = 'active';
|
|
187
|
+
set.assigned_to = request.agent;
|
|
188
|
+
remove.push('blocked_at', 'completed_at', 'cancelled_at', 'cancel_reason');
|
|
189
|
+
}
|
|
190
|
+
else if (request.intent === 'cancel') {
|
|
191
|
+
set.status = 'completed';
|
|
192
|
+
set.cancelled_at = metadata.timestamp;
|
|
193
|
+
set.cancel_reason = request.reason;
|
|
194
|
+
remove.push('blocked_at', 'completed_at');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
set.status = 'completed';
|
|
198
|
+
set.current_step = 'completed';
|
|
199
|
+
set.completed_at = metadata.timestamp;
|
|
200
|
+
remove.push('blocked_at', 'cancelled_at', 'cancel_reason');
|
|
201
|
+
const frontmatter = parseTypedTaskFrontmatter(content);
|
|
202
|
+
if (frontmatter.target_date === '')
|
|
203
|
+
set.target_date = metadata.timestamp.slice(0, 10);
|
|
204
|
+
}
|
|
205
|
+
const mutations = [
|
|
206
|
+
{ kind: 'frontmatter', set, remove: [...new Set(remove)] },
|
|
207
|
+
{ kind: 'section', aliases: ['活动日志', 'Activity Log'], heading: section.heading, body }
|
|
208
|
+
];
|
|
209
|
+
if (request.intent === 'block') {
|
|
210
|
+
mutations.splice(1, 0, {
|
|
211
|
+
kind: 'section', aliases: ['阻塞信息', 'Blocking Information'], heading: '阻塞信息',
|
|
212
|
+
body: `- **原因**:${request.reason}\n- **解除条件**:${request.unblockCondition}`
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return mutations;
|
|
216
|
+
}
|
|
217
|
+
function writeJournal(file, journal, io, create = false) {
|
|
218
|
+
const temporary = `${file}.tmp.${process.pid}.${Math.random().toString(36).slice(2)}`;
|
|
219
|
+
io.writeFileSync(temporary, `${JSON.stringify(journal, null, 2)}\n`, 'wx');
|
|
220
|
+
try {
|
|
221
|
+
if (create && fs.existsSync(file))
|
|
222
|
+
throw Object.assign(new Error('lifecycle journal already exists'), { code: 'LIFECYCLE_INTENT_CONFLICT' });
|
|
223
|
+
io.renameSync(temporary, file);
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
try {
|
|
227
|
+
io.unlinkSync(temporary);
|
|
228
|
+
}
|
|
229
|
+
catch { /* preserve primary error */ }
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function parseJournal(content) {
|
|
234
|
+
const value = JSON.parse(content);
|
|
235
|
+
if (value.version !== 1 || typeof value.taskId !== 'string' ||
|
|
236
|
+
!lifecycleIntentCatalog.includes(value.intent) ||
|
|
237
|
+
typeof value.intentDigest !== 'string' || !value.intentDigest ||
|
|
238
|
+
!['active', 'blocked', 'completed', 'staging'].includes(value.sourceState ?? '') ||
|
|
239
|
+
!['active', 'blocked', 'completed'].includes(value.targetState ?? '') ||
|
|
240
|
+
!value.metadata || typeof value.metadata.timestamp !== 'string' ||
|
|
241
|
+
typeof value.metadata.agentInfraVersion !== 'string' || !Array.isArray(value.completedSteps) ||
|
|
242
|
+
value.completedSteps.some((step) => !STEPS.includes(step)) ||
|
|
243
|
+
new Set(value.completedSteps).size !== value.completedSteps.length) {
|
|
244
|
+
throw new Error('lifecycle journal has invalid schema');
|
|
245
|
+
}
|
|
246
|
+
return value;
|
|
247
|
+
}
|
|
248
|
+
function applyTaskLifecycle(requestInput, options = {}) {
|
|
249
|
+
const normalized = normalizedRequest(requestInput);
|
|
250
|
+
if ('code' in normalized)
|
|
251
|
+
return failed(requestInput, normalized);
|
|
252
|
+
const request = normalized;
|
|
253
|
+
const repoRoot = path.resolve(options.repoRoot ?? process.cwd());
|
|
254
|
+
const io = { ...DEFAULT_IO, ...options.fileSystem };
|
|
255
|
+
let taskId;
|
|
256
|
+
if (request.intent === 'restore') {
|
|
257
|
+
if (!TASK_ID_RE.test(request.taskRef))
|
|
258
|
+
return failed(request, { code: 'LIFECYCLE_IDENTITY_INVALID', message: 'restore requires a full TASK-id' });
|
|
259
|
+
taskId = request.taskRef;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const resolved = resolveTaskRef(request.taskRef, { repoRoot });
|
|
263
|
+
if (!resolved.ok)
|
|
264
|
+
return failed(request, { code: resolved.code, message: resolved.message }, { taskId: resolved.taskId });
|
|
265
|
+
taskId = resolved.taskId;
|
|
266
|
+
}
|
|
267
|
+
const spec = transition(request);
|
|
268
|
+
const hot = locateHotTaskDirs(repoRoot, taskId);
|
|
269
|
+
if (hot.length > 1)
|
|
270
|
+
return failed(request, { code: 'LIFECYCLE_IDENTITY_CONFLICT', message: `task ${taskId} exists in multiple hot states` }, { taskId });
|
|
271
|
+
let sourceState;
|
|
272
|
+
let sourcePath;
|
|
273
|
+
let restoredFiles = 0;
|
|
274
|
+
if (request.intent === 'restore' && hot.length === 0) {
|
|
275
|
+
const validation = validateRestoreStaging(request, repoRoot, taskId);
|
|
276
|
+
if ('code' in validation)
|
|
277
|
+
return failed(request, validation, { taskId });
|
|
278
|
+
sourceState = 'staging';
|
|
279
|
+
sourcePath = validation.stagingDir;
|
|
280
|
+
restoredFiles = validation.fileCount;
|
|
281
|
+
}
|
|
282
|
+
else if (hot[0]) {
|
|
283
|
+
sourceState = hot[0].state;
|
|
284
|
+
sourcePath = hot[0].taskDir;
|
|
285
|
+
restoredFiles = fs.readdirSync(sourcePath).filter((name) => !name.startsWith('.')).length;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
return failed(request, { code: 'LIFECYCLE_TASK_NOT_FOUND', message: `task ${taskId} has no lifecycle source` }, { taskId });
|
|
289
|
+
}
|
|
290
|
+
const targetPath = path.join(repoRoot, '.agents', 'workspace', spec.target, taskId);
|
|
291
|
+
const currentTaskFile = path.join(sourcePath, 'task.md');
|
|
292
|
+
const existingJournal = fs.existsSync(path.join(sourcePath, '.task-lifecycle.json'));
|
|
293
|
+
if (sourceState === spec.target && !existingJournal) {
|
|
294
|
+
const content = io.readFileSync(currentTaskFile);
|
|
295
|
+
if (matchingCompletion(content, request, restoredFiles)) {
|
|
296
|
+
const frontmatter = parseTypedTaskFrontmatter(content);
|
|
297
|
+
return {
|
|
298
|
+
...failed(request, { code: '', message: '' }), status: 'no-op', error: null, taskId,
|
|
299
|
+
sourceState, targetState: spec.target, sourcePath, targetPath, pendingSteps: [],
|
|
300
|
+
completedSteps: STEPS, timestamp: typeof frontmatter.updated_at === 'string' ? frontmatter.updated_at : null,
|
|
301
|
+
agentInfraVersion: typeof frontmatter.agent_infra_version === 'string' ? frontmatter.agent_infra_version : null
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return failed(request, { code: 'LIFECYCLE_INTENT_CONFLICT', message: `task ${taskId} is already ${spec.target} with a different lifecycle intent` }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
305
|
+
}
|
|
306
|
+
if (!spec.sources.includes(sourceState) && !existingJournal) {
|
|
307
|
+
return failed(request, { code: 'LIFECYCLE_SOURCE_INVALID', message: `${request.intent} is not allowed from ${sourceState}` }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
308
|
+
}
|
|
309
|
+
if (sourcePath !== targetPath && fs.existsSync(targetPath)) {
|
|
310
|
+
return failed(request, { code: 'LIFECYCLE_TARGET_CONFLICT', message: `target directory already exists: ${targetPath}` }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
311
|
+
}
|
|
312
|
+
const content = io.readFileSync(currentTaskFile);
|
|
313
|
+
let frontmatter;
|
|
314
|
+
try {
|
|
315
|
+
frontmatter = parseTypedTaskFrontmatter(content);
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
return failed(request, { code: 'LIFECYCLE_DOCUMENT_INVALID', message: error instanceof Error ? error.message : String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
319
|
+
}
|
|
320
|
+
if (frontmatter.id !== taskId)
|
|
321
|
+
return failed(request, { code: 'LIFECYCLE_IDENTITY_INVALID', message: 'task.md id does not match its lifecycle task id' }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
322
|
+
if (!locateActivityLog(content))
|
|
323
|
+
return failed(request, { code: 'LIFECYCLE_LOG_MISSING', message: 'task has no unique Activity Log section' }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
324
|
+
const registryRequest = executeShortIdCommand({
|
|
325
|
+
operation: 'list', activeDir: path.join(repoRoot, '.agents', 'workspace', 'active'),
|
|
326
|
+
shortIdLength: configuredShortIdLength(repoRoot)
|
|
327
|
+
});
|
|
328
|
+
if (registryRequest.status === 'failed') {
|
|
329
|
+
return failed(request, registryRequest.error, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
330
|
+
}
|
|
331
|
+
const registry = JSON.parse(registryRequest.output || '{"version":1,"ids":{}}');
|
|
332
|
+
const registeredKey = Object.entries(registry.ids).find(([, candidate]) => candidate === taskId)?.[0];
|
|
333
|
+
if (spec.registry === 'release' && sourceState === 'active' && !registeredKey) {
|
|
334
|
+
return failed(request, { code: 'LIFECYCLE_SHORT_ID_PRECONDITION', message: 'active source has no short-id registry entry' }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
335
|
+
}
|
|
336
|
+
if (spec.registry === 'alloc' && !registeredKey && Object.keys(registry.ids).length >= 10 ** configuredShortIdLength(repoRoot) - 1) {
|
|
337
|
+
return failed(request, { code: 'SHORT_ID_CAPACITY_EXCEEDED', message: 'short-id registry has no free slot' }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
338
|
+
}
|
|
339
|
+
const digest = intentIdentity(request, taskId);
|
|
340
|
+
const initialJournalPath = path.join(sourcePath, '.task-lifecycle.json');
|
|
341
|
+
let journal;
|
|
342
|
+
let journalPath = initialJournalPath;
|
|
343
|
+
if (fs.existsSync(initialJournalPath)) {
|
|
344
|
+
try {
|
|
345
|
+
journal = parseJournal(io.readFileSync(initialJournalPath));
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
return failed(request, { code: 'LIFECYCLE_JOURNAL_INVALID', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath: initialJournalPath });
|
|
349
|
+
}
|
|
350
|
+
if (journal.intentDigest !== digest || journal.taskId !== taskId)
|
|
351
|
+
return failed(request, { code: 'LIFECYCLE_INTENT_CONFLICT', message: 'an in-progress lifecycle journal belongs to a different request' }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath: initialJournalPath });
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
let metadata;
|
|
355
|
+
try {
|
|
356
|
+
metadata = (options.metadataProvider ?? captureTaskWriteMetadata)();
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
return failed(request, { code: 'LIFECYCLE_METADATA_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
360
|
+
}
|
|
361
|
+
journal = { version: 1, taskId, intent: request.intent, intentDigest: digest, sourceState, targetState: spec.target, metadata, completedSteps: [] };
|
|
362
|
+
if (request.dryRun) {
|
|
363
|
+
const plannedMutations = mutationsFor(request, content, metadata, restoredFiles);
|
|
364
|
+
if ('code' in plannedMutations)
|
|
365
|
+
return failed(request, plannedMutations, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
366
|
+
const taskPlan = writeTask({ taskRef: taskId, expectedState: sourceState === 'blocked' ? 'blocked' : 'active', mutations: plannedMutations, dryRun: true }, {
|
|
367
|
+
repoRoot, metadataProvider: () => metadata,
|
|
368
|
+
taskLocation: sourceState === 'staging' ? { repoRoot, taskId, taskMdPath: path.join(sourcePath, 'task.md'), state: 'active' } : undefined
|
|
369
|
+
});
|
|
370
|
+
if (taskPlan.status === 'failed')
|
|
371
|
+
return failed(request, taskPlan.error, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, task: { operations: taskPlan.operations } });
|
|
372
|
+
return {
|
|
373
|
+
...failed(request, { code: '', message: '' }), status: 'planned', changed: true, error: null,
|
|
374
|
+
taskId, sourceState, targetState: spec.target, sourcePath, targetPath, task: { operations: taskPlan.operations },
|
|
375
|
+
directory: { effect: 'move', changed: true },
|
|
376
|
+
shortId: {
|
|
377
|
+
effect: spec.registry === 'alloc' ? (registeredKey ? 'unchanged' : 'allocated') : spec.registry === 'release' ? (registeredKey ? 'released' : 'unchanged') : 'unchanged',
|
|
378
|
+
shortId: registeredKey ?? null,
|
|
379
|
+
changed: spec.registry === 'alloc' ? !registeredKey : spec.registry === 'release' ? Boolean(registeredKey) : false
|
|
380
|
+
},
|
|
381
|
+
timestamp: metadata.timestamp, agentInfraVersion: metadata.agentInfraVersion,
|
|
382
|
+
journalPath: initialJournalPath
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
writeJournal(initialJournalPath, journal, io, true);
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
return failed(request, { code: 'LIFECYCLE_JOURNAL_WRITE_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath });
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const completed = new Set(journal.completedSteps);
|
|
393
|
+
if (sourceState === spec.target && journal.sourceState !== spec.target)
|
|
394
|
+
completed.add('directory-moved');
|
|
395
|
+
const currentMappings = loadShortIdByTaskId(repoRoot);
|
|
396
|
+
if ((spec.target === 'active' && currentMappings.has(taskId)) || (spec.target !== 'active' && !currentMappings.has(taskId))) {
|
|
397
|
+
if (completed.has('directory-moved'))
|
|
398
|
+
completed.add('registry-committed');
|
|
399
|
+
}
|
|
400
|
+
let taskOperations = [];
|
|
401
|
+
if (matchingCompletion(io.readFileSync(path.join(sourcePath, 'task.md')), request, restoredFiles))
|
|
402
|
+
completed.add('task-written');
|
|
403
|
+
if (!completed.has('task-written')) {
|
|
404
|
+
const current = io.readFileSync(path.join(sourcePath, 'task.md'));
|
|
405
|
+
const mutations = mutationsFor(request, current, journal.metadata, restoredFiles);
|
|
406
|
+
if ('code' in mutations)
|
|
407
|
+
return failed(request, mutations, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, completedSteps: [...completed], changed: completed.size > 0 });
|
|
408
|
+
const writeResult = writeTask({ taskRef: taskId, expectedState: sourceState === 'blocked' ? 'blocked' : 'active', mutations }, {
|
|
409
|
+
repoRoot, metadataProvider: () => journal.metadata,
|
|
410
|
+
fileSystem: options.taskFileSystem,
|
|
411
|
+
taskLocation: sourceState === 'staging' ? { repoRoot, taskId, taskMdPath: path.join(sourcePath, 'task.md'), state: 'active' } : undefined
|
|
412
|
+
});
|
|
413
|
+
taskOperations = writeResult.operations;
|
|
414
|
+
if (writeResult.status === 'failed')
|
|
415
|
+
return failed(request, writeResult.error, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, completedSteps: [...completed], changed: completed.size > 0, timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
416
|
+
completed.add('task-written');
|
|
417
|
+
journal.completedSteps = [...completed];
|
|
418
|
+
try {
|
|
419
|
+
writeJournal(journalPath, journal, io);
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
return failed(request, { code: 'LIFECYCLE_JOURNAL_WRITE_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, changed: true, completedSteps: [...completed], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (fs.existsSync(targetPath) && !fs.existsSync(sourcePath))
|
|
426
|
+
completed.add('directory-moved');
|
|
427
|
+
if (!completed.has('directory-moved')) {
|
|
428
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
429
|
+
if (fs.existsSync(targetPath))
|
|
430
|
+
return failed(request, { code: 'LIFECYCLE_TARGET_CONFLICT', message: `target directory already exists: ${targetPath}` }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, changed: true, completedSteps: [...completed], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
431
|
+
try {
|
|
432
|
+
(options.directoryRenameSync ?? io.renameSync)(sourcePath, targetPath);
|
|
433
|
+
}
|
|
434
|
+
catch (error) {
|
|
435
|
+
return failed(request, { code: 'LIFECYCLE_DIRECTORY_RENAME_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, changed: true, completedSteps: [...completed], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
436
|
+
}
|
|
437
|
+
completed.add('directory-moved');
|
|
438
|
+
journal.completedSteps = [...completed];
|
|
439
|
+
journalPath = path.join(targetPath, '.task-lifecycle.json');
|
|
440
|
+
try {
|
|
441
|
+
writeJournal(journalPath, journal, io);
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
return failed(request, { code: 'LIFECYCLE_JOURNAL_WRITE_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, directory: { effect: 'move', changed: true }, changed: true, completedSteps: [...completed], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
let shortId = { effect: 'unchanged', shortId: null, changed: false };
|
|
448
|
+
if (!completed.has('registry-committed')) {
|
|
449
|
+
try {
|
|
450
|
+
shortId = mutateShortIdRegistry(repoRoot, taskId, spec.registry);
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
return failed(request, { code: error.code ?? 'LIFECYCLE_SHORT_ID_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, directory: { effect: 'move', changed: true }, changed: true, completedSteps: [...completed], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
454
|
+
}
|
|
455
|
+
completed.add('registry-committed');
|
|
456
|
+
journal.completedSteps = [...completed];
|
|
457
|
+
try {
|
|
458
|
+
writeJournal(journalPath, journal, io);
|
|
459
|
+
}
|
|
460
|
+
catch (error) {
|
|
461
|
+
return failed(request, { code: 'LIFECYCLE_JOURNAL_WRITE_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, directory: { effect: 'move', changed: true }, shortId, changed: true, completedSteps: [...completed], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const mappings = loadShortIdByTaskId(repoRoot);
|
|
465
|
+
if (spec.target === 'active' && !mappings.has(taskId))
|
|
466
|
+
return failed(request, { code: 'LIFECYCLE_FINAL_STATE_INVALID', message: 'active lifecycle target has no short id' }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, changed: true, completedSteps: [...completed], pendingSteps: [], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
467
|
+
if (spec.target !== 'active' && mappings.has(taskId))
|
|
468
|
+
return failed(request, { code: 'LIFECYCLE_FINAL_STATE_INVALID', message: 'non-active lifecycle target retained a short id' }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, changed: true, completedSteps: [...completed], pendingSteps: [], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
469
|
+
try {
|
|
470
|
+
io.unlinkSync(journalPath);
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
return failed(request, { code: 'LIFECYCLE_JOURNAL_CLEANUP_FAILED', message: String(error) }, { taskId, sourceState, targetState: spec.target, sourcePath, targetPath, journalPath, task: { operations: taskOperations }, directory: { effect: 'move', changed: true }, shortId, changed: true, completedSteps: [...completed], pendingSteps: [], timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion });
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
...failed(request, { code: '', message: '' }), status: 'applied', changed: true, error: null,
|
|
477
|
+
taskId, sourceState, targetState: spec.target, sourcePath, targetPath,
|
|
478
|
+
task: { operations: taskOperations }, directory: { effect: 'move', changed: true }, shortId,
|
|
479
|
+
timestamp: journal.metadata.timestamp, agentInfraVersion: journal.metadata.agentInfraVersion,
|
|
480
|
+
journalPath, completedSteps: [...completed], pendingSteps: []
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
export { lifecycleIntentCatalog, applyTaskLifecycle };
|
|
484
|
+
//# sourceMappingURL=lifecycle.js.map
|