@fitlab-ai/agent-infra 0.9.13 → 0.9.15
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 +10 -0
- package/README.zh-CN.md +10 -0
- package/bin/cli.ts +26 -9
- package/bin/internal-cli.sh +45 -0
- package/dist/bin/cli.js +173 -157
- package/dist/bin/internal-cli.js +126 -42
- package/dist/lib/agent-client.js +5 -0
- package/dist/lib/agent-clients/adapters/codex-lifecycle/capability-store.js +165 -27
- package/dist/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.js +3 -2
- package/dist/lib/defaults.json +103 -103
- package/dist/lib/fs/durable-write.js +37 -0
- package/dist/lib/fs/file-lock.js +111 -0
- package/dist/lib/host-control/audit.js +19 -0
- package/dist/lib/host-control/client.js +142 -0
- package/dist/lib/host-control/command.js +49 -0
- package/dist/lib/host-control/path.js +160 -0
- package/dist/lib/host-control/secure-fs.js +140 -0
- package/dist/lib/host-control/server.js +159 -0
- package/dist/lib/host-control/service.js +112 -0
- package/dist/lib/init.js +11 -2
- package/dist/lib/internal/agent-client.js +5 -2
- package/dist/lib/internal/cli-route-inventory.js +154 -0
- package/dist/lib/internal/codex-lifecycle.js +15 -12
- package/dist/lib/internal/codex-sandbox-controller.js +8 -2
- package/dist/lib/internal/demo-promotion.js +322 -0
- package/dist/lib/internal/demo-transcript.js +454 -0
- package/dist/lib/internal/git-workflow.js +10 -6
- package/dist/lib/internal/host-control.js +28 -0
- package/dist/lib/internal/manual-validation.js +322 -0
- package/dist/lib/internal/platform-checks.js +16 -4
- package/dist/lib/internal/platform-comment.js +16 -4
- package/dist/lib/internal/platform-context.js +4 -1
- package/dist/lib/internal/platform-issue.js +12 -4
- package/dist/lib/internal/platform-metadata.js +88 -0
- package/dist/lib/internal/platform-pr-review.js +16 -3
- package/dist/lib/internal/platform-pr.js +42 -14
- package/dist/lib/internal/platform-release-notes.js +6 -3
- package/dist/lib/internal/platform-security.js +93 -0
- package/dist/lib/internal/pr-review-grade.js +14 -3
- package/dist/lib/internal/release-workflow.js +82 -89
- package/dist/lib/internal/sandbox-control.js +171 -7
- package/dist/lib/internal/task-activity.js +13 -4
- package/dist/lib/internal/task-artifact.js +19 -107
- package/dist/lib/internal/task-context.js +4 -1
- package/dist/lib/internal/task-create.js +48 -14
- package/dist/lib/internal/task-delivery.js +4 -1
- package/dist/lib/internal/task-event.js +38 -35
- package/dist/lib/internal/task-finalization.js +4 -1
- package/dist/lib/internal/task-invalidation.js +4 -1
- package/dist/lib/internal/task-ledger.js +12 -1
- package/dist/lib/internal/task-lifecycle.js +4 -1
- package/dist/lib/internal/task-operation-registry.js +519 -0
- package/dist/lib/internal/task-orchestration.js +12 -0
- package/dist/lib/internal/task-override.js +10 -3
- package/dist/lib/internal/task-qualification.js +90 -0
- package/dist/lib/internal/task-review.js +10 -52
- package/dist/lib/internal/task-short-id.js +11 -1
- package/dist/lib/internal/task-snapshot.js +4 -1
- package/dist/lib/internal/task-validate.js +37 -12
- package/dist/lib/internal/task-verify.js +5 -1
- package/dist/lib/internal/task-warning.js +8 -1
- package/dist/lib/owned-path.js +33 -0
- package/dist/lib/platform/check-status.js +11 -0
- package/dist/lib/platform/comment-safety.js +229 -0
- package/dist/lib/platform/completion-backfill.js +1 -1
- package/dist/lib/platform/github-data.js +241 -0
- package/dist/lib/platform/github-provider.js +248 -26
- package/dist/lib/platform/issue-comments.js +146 -34
- package/dist/lib/platform/issues.js +1 -179
- package/dist/lib/platform/pr-change-report.js +6 -12
- package/dist/lib/platform/pr-checks.js +12 -65
- package/dist/lib/platform/pr-summary.js +83 -10
- package/dist/lib/platform/provider-contract.d.ts +67 -1
- package/dist/lib/platform/provider-contract.js +6 -2
- package/dist/lib/platform/provider-validation.js +76 -3
- package/dist/lib/platform/pull-requests.js +117 -275
- package/dist/lib/platform/repository-metadata.js +377 -0
- package/dist/lib/platform/security-alerts.js +155 -0
- package/dist/lib/platform/snapshots.js +2 -0
- package/dist/lib/platform/verification-sync.js +154 -162
- package/dist/lib/process-data/index.js +7 -0
- package/dist/lib/release/workflow.js +1 -1
- package/dist/lib/run/index.js +5 -0
- package/dist/lib/sandbox/commands/control-status.js +22 -0
- package/dist/lib/sandbox/commands/create.js +39 -8
- package/dist/lib/sandbox/commands/ls.js +5 -0
- package/dist/lib/sandbox/commands/rm.js +3 -807
- package/dist/lib/sandbox/commands/show.js +16 -0
- package/dist/lib/sandbox/control/audit.js +203 -0
- package/dist/lib/sandbox/control/client.js +125 -12
- package/dist/lib/sandbox/control/completed-reentry.js +85 -0
- package/dist/lib/sandbox/control/container-identity.js +28 -31
- package/dist/lib/sandbox/control/executor.js +233 -34
- package/dist/lib/sandbox/control/finalization-response.js +27 -0
- package/dist/lib/sandbox/control/identity-sentinel.js +107 -0
- package/dist/lib/sandbox/control/lifecycle.js +656 -128
- package/dist/lib/sandbox/control/native-file-lock.js +85 -0
- package/dist/lib/sandbox/control/protocol.js +55 -4
- package/dist/lib/sandbox/control/server.js +720 -79
- package/dist/lib/sandbox/control/state.js +63 -3
- package/dist/lib/sandbox/control/task-view.js +183 -0
- package/dist/lib/sandbox/control/task-workflow.js +74 -0
- package/dist/lib/sandbox/control/workflow-executor.js +99 -0
- package/dist/lib/sandbox/engines/authority.js +289 -0
- package/dist/lib/sandbox/engines/docker-exact-discovery.js +97 -0
- package/dist/lib/sandbox/index.js +7 -2
- package/dist/lib/sandbox/recovery.js +49 -5
- package/dist/lib/sandbox/removal.js +1717 -0
- package/dist/lib/sandbox/task-cleanup.js +217 -0
- package/dist/lib/sandbox/workspace-view.js +15 -15
- package/dist/lib/sandbox/worktree-safety.js +4 -1
- package/dist/lib/server/index.js +8 -0
- package/dist/lib/task/activity-intent.js +2 -1
- package/dist/lib/task/activity-log.js +30 -24
- package/dist/lib/task/artifact-command.js +101 -0
- package/dist/lib/task/artifact-lifecycle.js +71 -40
- package/dist/lib/task/artifact-name.js +36 -0
- package/dist/lib/task/artifact-operations.js +474 -0
- package/dist/lib/task/artifact-receipts.js +3 -15
- package/dist/lib/task/artifact-repair-intent.js +130 -0
- package/dist/lib/task/artifact-schema.js +127 -0
- package/dist/lib/task/capabilities.js +83 -19
- package/dist/lib/task/codex-orchestration.js +71 -25
- package/dist/lib/task/commit-identity.js +28 -0
- package/dist/lib/task/commit-operation.js +2 -16
- package/dist/lib/task/control-authority.js +375 -5
- package/dist/lib/task/control-recovery.js +128 -0
- package/dist/lib/task/create-service.js +103 -4
- package/dist/lib/task/create.js +80 -2
- package/dist/lib/task/decision-details.js +2 -46
- package/dist/lib/task/events.js +306 -76
- package/dist/lib/task/finalization-state.js +9 -0
- package/dist/lib/task/human-override.js +3 -6
- package/dist/lib/task/implementation-inputs.js +3 -3
- package/dist/lib/task/index.js +11 -3
- package/dist/lib/task/intermediate-cleanup.js +383 -0
- package/dist/lib/task/invalidation.js +18 -65
- package/dist/lib/task/ledger-intents.js +7 -22
- package/dist/lib/task/ledger.js +1 -3
- package/dist/lib/task/lifecycle.js +19 -1
- package/dist/lib/task/local-artifact-finalization.js +190 -290
- package/dist/lib/task/manual-validation-completion.js +26 -0
- package/dist/lib/task/manual-validation-evidence.js +130 -0
- package/dist/lib/task/manual-validation-receipt.js +101 -0
- package/dist/lib/task/manual-validation-shared.js +40 -0
- package/dist/lib/task/manual-validation-transaction.js +243 -0
- package/dist/lib/task/markdown.js +47 -0
- package/dist/lib/task/orchestration.js +206 -69
- package/dist/lib/task/qualification-audit.js +476 -0
- package/dist/lib/task/qualification-confirmation.js +109 -0
- package/dist/lib/task/qualification-intents.js +148 -0
- package/dist/lib/task/review-artifacts.js +23 -40
- package/dist/lib/task/review-command.js +25 -0
- package/dist/lib/task/review-finalization.js +146 -97
- package/dist/lib/task/review-fingerprint.js +2 -2
- package/dist/lib/task/sections.js +34 -54
- package/dist/lib/task/verification-config.js +11 -0
- package/dist/lib/task/verification-engine.js +170 -327
- package/dist/lib/task/verification.js +1 -1
- package/dist/lib/task/workflow-command.js +17 -0
- package/dist/lib/task/workflow-warning-intents.js +0 -16
- package/dist/lib/task/workflow-warnings.js +28 -2
- package/dist/lib/update.js +2 -0
- package/dist/lifecycle-build-manifest.json +3 -3
- package/lib/agent-client.ts +9 -0
- package/lib/agent-clients/adapters/codex-lifecycle/capability-store.ts +223 -33
- package/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.ts +3 -2
- package/lib/fs/durable-write.ts +29 -0
- package/lib/fs/file-lock.ts +113 -0
- package/lib/host-control/audit.ts +22 -0
- package/lib/host-control/client.ts +172 -0
- package/lib/host-control/command.ts +60 -0
- package/lib/host-control/path.ts +167 -0
- package/lib/host-control/secure-fs.ts +135 -0
- package/lib/host-control/server.ts +180 -0
- package/lib/host-control/service.ts +133 -0
- package/lib/init.ts +15 -2
- package/lib/internal/agent-client.ts +4 -2
- package/lib/internal/cli-route-inventory.ts +142 -0
- package/lib/internal/codex-lifecycle.ts +14 -12
- package/lib/internal/codex-sandbox-controller.ts +7 -2
- package/lib/internal/demo-promotion.ts +354 -0
- package/lib/internal/demo-transcript.ts +419 -0
- package/lib/internal/git-workflow.ts +9 -6
- package/lib/internal/host-control.ts +28 -0
- package/lib/internal/manual-validation.ts +306 -0
- package/lib/internal/platform-checks.ts +12 -4
- package/lib/internal/platform-comment.ts +12 -4
- package/lib/internal/platform-context.ts +3 -1
- package/lib/internal/platform-issue.ts +11 -4
- package/lib/internal/platform-metadata.ts +70 -0
- package/lib/internal/platform-pr-review.ts +14 -3
- package/lib/internal/platform-pr.ts +38 -14
- package/lib/internal/platform-release-notes.ts +5 -3
- package/lib/internal/platform-security.ts +83 -0
- package/lib/internal/pr-review-grade.ts +10 -3
- package/lib/internal/release-workflow.ts +91 -87
- package/lib/internal/sandbox-control.ts +181 -6
- package/lib/internal/task-activity.ts +12 -4
- package/lib/internal/task-artifact.ts +15 -79
- package/lib/internal/task-context.ts +3 -1
- package/lib/internal/task-create.ts +76 -15
- package/lib/internal/task-delivery.ts +3 -1
- package/lib/internal/task-event.ts +21 -10
- package/lib/internal/task-finalization.ts +3 -1
- package/lib/internal/task-invalidation.ts +3 -1
- package/lib/internal/task-ledger.ts +11 -1
- package/lib/internal/task-lifecycle.ts +3 -1
- package/lib/internal/task-operation-registry.ts +590 -0
- package/lib/internal/task-orchestration.ts +12 -0
- package/lib/internal/task-override.ts +9 -3
- package/lib/internal/task-qualification.ts +61 -0
- package/lib/internal/task-review.ts +7 -50
- package/lib/internal/task-short-id.ts +10 -1
- package/lib/internal/task-snapshot.ts +3 -1
- package/lib/internal/task-validate.ts +32 -12
- package/lib/internal/task-verify.ts +4 -1
- package/lib/internal/task-warning.ts +7 -1
- package/lib/owned-path.ts +26 -0
- package/lib/platform/check-status.ts +9 -0
- package/lib/platform/comment-safety.ts +255 -0
- package/lib/platform/completion-backfill.ts +1 -1
- package/lib/platform/github-data.ts +322 -0
- package/lib/platform/github-provider.ts +244 -27
- package/lib/platform/issue-comments.ts +159 -35
- package/lib/platform/issues.ts +4 -245
- package/lib/platform/pr-change-report.ts +6 -12
- package/lib/platform/pr-checks.ts +13 -77
- package/lib/platform/pr-summary.ts +88 -11
- package/lib/platform/provider-contract.ts +78 -3
- package/lib/platform/provider-validation.ts +85 -3
- package/lib/platform/pull-requests.ts +129 -348
- package/lib/platform/repository-metadata.ts +453 -0
- package/lib/platform/security-alerts.ts +191 -0
- package/lib/platform/snapshots.ts +53 -0
- package/lib/platform/verification-sync.ts +171 -177
- package/lib/process-data/index.ts +7 -0
- package/lib/release/workflow.ts +3 -3
- package/lib/run/index.ts +5 -0
- package/lib/sandbox/commands/control-status.ts +26 -0
- package/lib/sandbox/commands/create.ts +53 -12
- package/lib/sandbox/commands/ls.ts +7 -0
- package/lib/sandbox/commands/rm.ts +3 -996
- package/lib/sandbox/commands/show.ts +16 -0
- package/lib/sandbox/control/audit.ts +253 -0
- package/lib/sandbox/control/client.ts +150 -13
- package/lib/sandbox/control/completed-reentry.ts +98 -0
- package/lib/sandbox/control/container-identity.ts +27 -43
- package/lib/sandbox/control/executor.ts +262 -37
- package/lib/sandbox/control/finalization-response.ts +29 -0
- package/lib/sandbox/control/identity-sentinel.ts +137 -0
- package/lib/sandbox/control/lifecycle.ts +672 -18
- package/lib/sandbox/control/native-file-lock.ts +108 -0
- package/lib/sandbox/control/protocol.ts +80 -8
- package/lib/sandbox/control/server.ts +779 -82
- package/lib/sandbox/control/state.ts +84 -3
- package/lib/sandbox/control/task-view.ts +240 -0
- package/lib/sandbox/control/task-workflow.ts +95 -0
- package/lib/sandbox/control/workflow-executor.ts +102 -0
- package/lib/sandbox/engines/authority.ts +365 -0
- package/lib/sandbox/engines/docker-exact-discovery.ts +132 -0
- package/lib/sandbox/index.ts +9 -2
- package/lib/sandbox/recovery.ts +49 -6
- package/lib/sandbox/removal.ts +2144 -0
- package/lib/sandbox/task-cleanup.ts +209 -0
- package/lib/sandbox/workspace-view.ts +26 -18
- package/lib/sandbox/worktree-safety.ts +4 -1
- package/lib/server/index.ts +10 -0
- package/lib/task/activity-intent.ts +2 -2
- package/lib/task/activity-log.ts +27 -19
- package/lib/task/artifact-command.ts +104 -0
- package/lib/task/artifact-lifecycle.ts +66 -39
- package/lib/task/artifact-name.ts +55 -0
- package/lib/task/artifact-operations.ts +580 -0
- package/lib/task/artifact-receipts.ts +3 -14
- package/lib/task/artifact-repair-intent.ts +152 -0
- package/lib/task/artifact-schema.ts +163 -0
- package/lib/task/capabilities.ts +82 -22
- package/lib/task/codex-orchestration.ts +85 -24
- package/lib/task/commit-identity.ts +31 -0
- package/lib/task/commit-operation.ts +2 -16
- package/lib/task/control-authority.ts +513 -6
- package/lib/task/control-recovery.ts +174 -0
- package/lib/task/create-service.ts +131 -6
- package/lib/task/create.ts +83 -1
- package/lib/task/decision-details.ts +3 -71
- package/lib/task/events.ts +292 -75
- package/lib/task/finalization-state.ts +11 -0
- package/lib/task/human-override.ts +3 -8
- package/lib/task/implementation-inputs.ts +3 -3
- package/lib/task/index.ts +16 -3
- package/lib/task/intermediate-cleanup.ts +455 -0
- package/lib/task/invalidation.ts +18 -62
- package/lib/task/ledger-intents.ts +7 -24
- package/lib/task/ledger.ts +1 -3
- package/lib/task/lifecycle.ts +17 -1
- package/lib/task/local-artifact-finalization.ts +223 -388
- package/lib/task/manual-validation-completion.ts +40 -0
- package/lib/task/manual-validation-evidence.ts +209 -0
- package/lib/task/manual-validation-receipt.ts +152 -0
- package/lib/task/manual-validation-shared.ts +50 -0
- package/lib/task/manual-validation-transaction.ts +304 -0
- package/lib/task/markdown.ts +70 -0
- package/lib/task/orchestration.ts +191 -68
- package/lib/task/qualification-audit.ts +588 -0
- package/lib/task/qualification-confirmation.ts +117 -0
- package/lib/task/qualification-intents.ts +150 -0
- package/lib/task/review-artifacts.ts +21 -41
- package/lib/task/review-command.ts +23 -0
- package/lib/task/review-finalization.ts +154 -153
- package/lib/task/review-fingerprint.ts +2 -2
- package/lib/task/sections.ts +33 -52
- package/lib/task/verification-config.ts +12 -0
- package/lib/task/verification-engine.ts +165 -370
- package/lib/task/verification-types.ts +17 -0
- package/lib/task/verification.ts +1 -1
- package/lib/task/workflow-command.ts +18 -0
- package/lib/task/workflow-warning-intents.ts +0 -13
- package/lib/task/workflow-warnings.ts +21 -2
- package/lib/update.ts +6 -0
- package/package.json +7 -2
- package/templates/.agents/hooks/lifecycle-delegation.js +6 -6
- package/templates/.agents/rules/README.en.md +2 -0
- package/templates/.agents/rules/README.zh-CN.md +2 -0
- package/templates/.agents/rules/decision-qualification.en.md +22 -0
- package/templates/.agents/rules/decision-qualification.zh-CN.md +22 -0
- package/templates/.agents/rules/evidence-reporting.en.md +28 -0
- package/templates/.agents/rules/evidence-reporting.zh-CN.md +28 -0
- package/templates/.agents/rules/label-milestone-setup.en.md +7 -7
- package/templates/.agents/rules/label-milestone-setup.zh-CN.md +7 -7
- package/templates/.agents/rules/local-artifact-repair.en.md +5 -1
- package/templates/.agents/rules/local-artifact-repair.zh-CN.md +5 -1
- package/templates/.agents/rules/security-alerts.en.md +8 -8
- package/templates/.agents/rules/security-alerts.zh-CN.md +8 -8
- package/templates/.agents/rules/testing-discipline.en.md +2 -0
- package/templates/.agents/rules/testing-discipline.zh-CN.md +2 -0
- package/templates/.agents/scripts/package.json +3 -0
- package/templates/.agents/skills/analyze-task/SKILL.en.md +15 -2
- package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +19 -2
- package/templates/.agents/skills/analyze-task/config/verify.en.json +1 -12
- package/templates/.agents/skills/analyze-task/config/verify.zh-CN.json +1 -12
- package/templates/.agents/skills/close-codescan/SKILL.en.md +2 -2
- package/templates/.agents/skills/close-codescan/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/close-dependabot/SKILL.en.md +2 -2
- package/templates/.agents/skills/close-dependabot/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/code-task/SKILL.en.md +14 -1
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +14 -1
- package/templates/.agents/skills/code-task/config/verify.en.json +5 -14
- package/templates/.agents/skills/code-task/config/verify.zh-CN.json +5 -14
- package/templates/.agents/skills/code-task/reference/code-rules.en.md +5 -4
- package/templates/.agents/skills/code-task/reference/code-rules.zh-CN.md +5 -4
- package/templates/.agents/skills/code-task/reference/dual-mode.en.md +1 -1
- package/templates/.agents/skills/code-task/reference/dual-mode.zh-CN.md +1 -1
- package/templates/.agents/skills/code-task/reference/fix-mode.en.md +3 -1
- package/templates/.agents/skills/code-task/reference/fix-mode.zh-CN.md +3 -1
- package/templates/.agents/skills/code-task/reference/report-template.en.md +42 -15
- package/templates/.agents/skills/code-task/reference/report-template.zh-CN.md +39 -12
- package/templates/.agents/skills/complete-manual-validation/SKILL.en.md +37 -21
- package/templates/.agents/skills/complete-manual-validation/SKILL.zh-CN.md +37 -21
- package/templates/.agents/skills/complete-manual-validation/config/verify.en.json +1 -1
- package/templates/.agents/skills/complete-manual-validation/config/verify.zh-CN.json +1 -1
- package/templates/.agents/skills/complete-manual-validation/reference/report-template.en.md +4 -0
- package/templates/.agents/skills/complete-manual-validation/reference/report-template.zh-CN.md +4 -0
- package/templates/.agents/skills/complete-manual-validation/reference/summary-update.en.md +16 -7
- package/templates/.agents/skills/complete-manual-validation/reference/summary-update.zh-CN.md +16 -7
- package/templates/.agents/skills/complete-task/SKILL.en.md +10 -23
- package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +10 -23
- package/templates/.agents/skills/create-task/SKILL.en.md +8 -0
- package/templates/.agents/skills/create-task/SKILL.zh-CN.md +7 -0
- package/templates/.agents/skills/import-codescan/SKILL.en.md +1 -1
- package/templates/.agents/skills/import-codescan/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/import-dependabot/SKILL.en.md +1 -1
- package/templates/.agents/skills/import-dependabot/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/init-labels/SKILL.en.md +8 -8
- package/templates/.agents/skills/init-labels/SKILL.zh-CN.md +8 -8
- package/templates/.agents/skills/init-milestones/SKILL.en.md +9 -11
- package/templates/.agents/skills/init-milestones/SKILL.zh-CN.md +9 -11
- package/templates/.agents/skills/plan-task/SKILL.en.md +14 -1
- package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +16 -1
- package/templates/.agents/skills/plan-task/config/verify.en.json +4 -14
- package/templates/.agents/skills/plan-task/config/verify.zh-CN.json +4 -14
- package/templates/.agents/skills/release/SKILL.en.md +7 -3
- package/templates/.agents/skills/release/SKILL.zh-CN.md +7 -3
- package/templates/.agents/skills/review-analysis/SKILL.en.md +14 -1
- package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +14 -1
- package/templates/.agents/skills/review-analysis/config/verify.en.json +1 -18
- package/templates/.agents/skills/review-analysis/config/verify.zh-CN.json +1 -18
- package/templates/.agents/skills/review-analysis/reference/report-template.en.md +50 -23
- package/templates/.agents/skills/review-analysis/reference/report-template.zh-CN.md +45 -18
- package/templates/.agents/skills/review-code/SKILL.en.md +14 -1
- package/templates/.agents/skills/review-code/SKILL.zh-CN.md +14 -1
- package/templates/.agents/skills/review-code/config/verify.en.json +1 -23
- package/templates/.agents/skills/review-code/config/verify.zh-CN.json +1 -23
- package/templates/.agents/skills/review-code/reference/report-template.en.md +49 -22
- package/templates/.agents/skills/review-code/reference/report-template.zh-CN.md +45 -18
- package/templates/.agents/skills/review-plan/SKILL.en.md +14 -1
- package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +14 -1
- package/templates/.agents/skills/review-plan/config/verify.en.json +1 -18
- package/templates/.agents/skills/review-plan/config/verify.zh-CN.json +1 -18
- package/templates/.agents/skills/review-plan/reference/report-template.en.md +49 -22
- package/templates/.agents/skills/review-plan/reference/report-template.zh-CN.md +45 -18
- package/templates/.agents/skills/review-pr/SKILL.en.md +5 -1
- package/templates/.agents/skills/review-pr/SKILL.zh-CN.md +5 -1
- package/templates/.agents/skills/review-pr/reference/report-template.en.md +4 -3
- package/templates/.agents/skills/review-pr/reference/report-template.zh-CN.md +4 -3
- package/templates/.agents/skills/run-manual-validation/SKILL.en.md +25 -4
- package/templates/.agents/skills/run-manual-validation/SKILL.zh-CN.md +25 -4
- package/templates/.agents/skills/run-manual-validation/reference/discovery-and-execution.en.md +4 -1
- package/templates/.agents/skills/run-manual-validation/reference/discovery-and-execution.zh-CN.md +4 -1
- package/templates/.agents/skills/run-manual-validation/reference/report-template.en.md +5 -1
- package/templates/.agents/skills/run-manual-validation/reference/report-template.zh-CN.md +5 -1
- package/templates/.agents/skills/run-task/SKILL.en.md +1 -1
- package/templates/.agents/skills/run-task/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/test/SKILL.en.md +29 -7
- package/templates/.agents/skills/test/SKILL.zh-CN.md +29 -7
- package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +14 -0
- package/templates/.agents/templates/task.en.md +6 -0
- package/templates/.agents/templates/task.zh-CN.md +6 -0
- package/templates/.claude/commands/run-manual-validation.en.md +1 -1
- package/templates/.claude/commands/run-manual-validation.zh-CN.md +1 -1
- package/dist/lib/platform/adapters.js +0 -56
- package/lib/platform/adapters.ts +0 -197
- package/templates/.agents/scripts/security-alerts.github.sh +0 -151
- package/templates/.agents/scripts/security-alerts.sh +0 -31
- package/templates/.agents/skills/init-labels/scripts/init-labels.github.sh +0 -146
- package/templates/.agents/skills/init-labels/scripts/init-labels.sh +0 -32
- package/templates/.agents/skills/init-milestones/scripts/init-milestones.github.sh +0 -294
- package/templates/.agents/skills/init-milestones/scripts/init-milestones.sh +0 -6
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { parseArtifactName } from './artifact-name.ts';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { readStableFileSync } from '../host-control/secure-fs.ts';
|
|
6
|
+
|
|
7
|
+
import { scanVisibleMarkdown, type VisibleMarkdown, type VisibleHeading } from './markdown.ts';
|
|
8
|
+
import { hasOpenArtifactRound } from './artifact-lifecycle.ts';
|
|
9
|
+
import { readArtifactRepairIntent } from './artifact-repair-intent.ts';
|
|
10
|
+
import { resolveTaskRef } from './resolve-ref.ts';
|
|
11
|
+
import {
|
|
12
|
+
getArtifactSchema,
|
|
13
|
+
renderArtifactSkeleton
|
|
14
|
+
} from './artifact-schema.ts';
|
|
15
|
+
import type {
|
|
16
|
+
ArtifactSchema,
|
|
17
|
+
ArtifactSchemaFamily,
|
|
18
|
+
ArtifactSection
|
|
19
|
+
} from './artifact-schema.ts';
|
|
20
|
+
import { withTaskExecutionLock } from './task-execution-lock.ts';
|
|
21
|
+
|
|
22
|
+
type ArtifactRepairOperation = Readonly<{
|
|
23
|
+
kind: 'replace-line' | 'insert-section';
|
|
24
|
+
sectionId: string;
|
|
25
|
+
line: number;
|
|
26
|
+
from: string;
|
|
27
|
+
to: string;
|
|
28
|
+
start: number;
|
|
29
|
+
end: number;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
type ArtifactStructuralDiagnosticCode =
|
|
33
|
+
| 'ARTIFACT_EMPTY'
|
|
34
|
+
| 'ARTIFACT_MISSING_SECTION'
|
|
35
|
+
| 'ARTIFACT_DUPLICATE_SECTION'
|
|
36
|
+
| 'ARTIFACT_UNCLOSED_FENCE'
|
|
37
|
+
| 'ARTIFACT_MARKER_MISSING'
|
|
38
|
+
| 'ARTIFACT_MARKER_DUPLICATE'
|
|
39
|
+
| 'ARTIFACT_MARKER_MISMATCH'
|
|
40
|
+
| 'ARTIFACT_EMPTY_SECTION'
|
|
41
|
+
| 'ARTIFACT_SECTION_ORDER_INVALID'
|
|
42
|
+
| 'ARTIFACT_HEADING_TRAILING_PUNCTUATION'
|
|
43
|
+
| 'ARTIFACT_REQUIRED_PATTERN_MISSING';
|
|
44
|
+
|
|
45
|
+
type ArtifactStructuralDiagnostic = Readonly<{
|
|
46
|
+
code: ArtifactStructuralDiagnosticCode;
|
|
47
|
+
message: string;
|
|
48
|
+
sectionId: string | null;
|
|
49
|
+
line: number | null;
|
|
50
|
+
repairable: boolean;
|
|
51
|
+
operation?: ArtifactRepairOperation;
|
|
52
|
+
}>;
|
|
53
|
+
|
|
54
|
+
type ArtifactStructureResult = Readonly<{
|
|
55
|
+
ok: boolean;
|
|
56
|
+
family: ArtifactSchemaFamily;
|
|
57
|
+
semanticDigest: string;
|
|
58
|
+
diagnostics: readonly ArtifactStructuralDiagnostic[];
|
|
59
|
+
repair: ArtifactRepairOperation | null;
|
|
60
|
+
}>;
|
|
61
|
+
|
|
62
|
+
type ArtifactFileResult = Readonly<{
|
|
63
|
+
status: 'applied' | 'no-op' | 'failed';
|
|
64
|
+
changed: boolean;
|
|
65
|
+
artifactSha256: string | null;
|
|
66
|
+
semanticDigest: string | null;
|
|
67
|
+
operation: ArtifactRepairOperation | null;
|
|
68
|
+
error: { code: string; message: string } | null;
|
|
69
|
+
}>;
|
|
70
|
+
|
|
71
|
+
type ArtifactRepairRequest = Readonly<{
|
|
72
|
+
repoRoot: string;
|
|
73
|
+
taskId: string;
|
|
74
|
+
taskDir: string;
|
|
75
|
+
family: ArtifactSchemaFamily;
|
|
76
|
+
artifact: string;
|
|
77
|
+
expectedSha256: string;
|
|
78
|
+
expectedSemanticDigest: string;
|
|
79
|
+
operation: ArtifactRepairOperation;
|
|
80
|
+
}>;
|
|
81
|
+
|
|
82
|
+
type ArtifactInitRequest = Readonly<{
|
|
83
|
+
repoRoot: string;
|
|
84
|
+
taskId: string;
|
|
85
|
+
taskDir: string;
|
|
86
|
+
family: ArtifactSchemaFamily;
|
|
87
|
+
artifact: string;
|
|
88
|
+
locale?: 'zh-CN' | 'en';
|
|
89
|
+
}>;
|
|
90
|
+
|
|
91
|
+
function sha256Content(content: string): string {
|
|
92
|
+
return createHash('sha256').update(content, 'utf8').digest('hex');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function lineNumber(content: string, offset: number): number {
|
|
96
|
+
return content.slice(0, offset).split('\n').length;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function markerPattern(marker: string): RegExp {
|
|
100
|
+
return new RegExp(`<!--\\s*${escapeRegExp(marker)}\\s*-->`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function escapeRegExp(value: string): string {
|
|
104
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function markerEntries(content: string, scanned: VisibleMarkdown): Array<{ marker: string; start: number; end: number; line: number; standalone: boolean }> {
|
|
108
|
+
const entries: Array<{ marker: string; start: number; end: number; line: number; standalone: boolean }> = [];
|
|
109
|
+
for (const line of scanned.lines) {
|
|
110
|
+
const match = line.text.match(/<!--\s*(artifact-section:[^\s>]+)\s*-->/g);
|
|
111
|
+
if (!match) continue;
|
|
112
|
+
for (const raw of match) {
|
|
113
|
+
const marker = raw.match(/artifact-section:[^\s>]+/)![0]!;
|
|
114
|
+
const offset = line.text.indexOf(raw);
|
|
115
|
+
entries.push({
|
|
116
|
+
marker,
|
|
117
|
+
start: line.start + offset,
|
|
118
|
+
end: line.start + offset + raw.length,
|
|
119
|
+
line: lineNumber(content, line.start),
|
|
120
|
+
standalone: line.text.trim() === raw
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return entries;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function sectionBodyBounds(content: string, heading: VisibleHeading, scanned: VisibleMarkdown): { start: number; end: number } {
|
|
128
|
+
const next = scanned.headings.find((candidate) => candidate.start > heading.start && candidate.level <= 2);
|
|
129
|
+
return { start: heading.end, end: next?.start ?? content.length };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function stripHtmlComments(content: string): string {
|
|
133
|
+
let result = '';
|
|
134
|
+
let cursor = 0;
|
|
135
|
+
while (cursor < content.length) {
|
|
136
|
+
const start = content.indexOf('<!--', cursor);
|
|
137
|
+
if (start < 0) return result + content.slice(cursor);
|
|
138
|
+
result += content.slice(cursor, start);
|
|
139
|
+
const end = content.indexOf('-->', start + 4);
|
|
140
|
+
if (end < 0) return result;
|
|
141
|
+
cursor = end + 3;
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function diagnostic(
|
|
147
|
+
code: ArtifactStructuralDiagnosticCode,
|
|
148
|
+
message: string,
|
|
149
|
+
sectionId: string | null,
|
|
150
|
+
line: number | null,
|
|
151
|
+
repairable = false,
|
|
152
|
+
operation?: ArtifactRepairOperation
|
|
153
|
+
): ArtifactStructuralDiagnostic {
|
|
154
|
+
return {
|
|
155
|
+
code, message, sectionId, line, repairable,
|
|
156
|
+
...(operation ? { operation } : {})
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function sectionHeadings(schema: ArtifactSchema, section: ArtifactSection): readonly string[] {
|
|
161
|
+
return [section.headings.zh, section.headings.en];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function createHeadingRepair(
|
|
165
|
+
content: string,
|
|
166
|
+
section: ArtifactSection,
|
|
167
|
+
heading: { start: number; end: number; text: string }
|
|
168
|
+
): ArtifactRepairOperation {
|
|
169
|
+
const to = heading.text.slice(0, -1);
|
|
170
|
+
return {
|
|
171
|
+
kind: 'replace-line',
|
|
172
|
+
sectionId: section.id,
|
|
173
|
+
line: lineNumber(content, heading.start),
|
|
174
|
+
from: heading.text,
|
|
175
|
+
to,
|
|
176
|
+
start: heading.start,
|
|
177
|
+
end: heading.end
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function createSectionInsertionRepair(
|
|
182
|
+
content: string,
|
|
183
|
+
section: ArtifactSection,
|
|
184
|
+
marker: { start: number; line: number },
|
|
185
|
+
locale: 'zh-CN' | 'en'
|
|
186
|
+
): ArtifactRepairOperation {
|
|
187
|
+
return {
|
|
188
|
+
kind: 'insert-section',
|
|
189
|
+
sectionId: section.id,
|
|
190
|
+
line: marker.line,
|
|
191
|
+
from: '',
|
|
192
|
+
to: `## ${section.headings[locale === 'en' ? 'en' : 'zh']}\n`,
|
|
193
|
+
start: marker.start,
|
|
194
|
+
end: marker.start
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function applyRepairOperation(content: string, operation: ArtifactRepairOperation): string | null {
|
|
199
|
+
if (operation.start < 0 || operation.end < operation.start || operation.end > content.length) return null;
|
|
200
|
+
if (operation.kind === 'insert-section') {
|
|
201
|
+
if (operation.from !== '' || operation.start !== operation.end || !operation.to) return null;
|
|
202
|
+
return `${content.slice(0, operation.start)}${operation.to}${content.slice(operation.end)}`;
|
|
203
|
+
}
|
|
204
|
+
const raw = content.slice(operation.start, operation.end);
|
|
205
|
+
const offset = raw.indexOf(operation.from);
|
|
206
|
+
if (!operation.from || offset < 0 || raw.indexOf(operation.from, offset + operation.from.length) >= 0) return null;
|
|
207
|
+
return `${content.slice(0, operation.start)}${raw.slice(0, offset)}${operation.to}${raw.slice(offset + operation.from.length)}${content.slice(operation.end)}`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function canonicalContent(content: string, operation: ArtifactRepairOperation | null = null): string {
|
|
211
|
+
let normalized = content;
|
|
212
|
+
if (operation) {
|
|
213
|
+
normalized = applyRepairOperation(normalized, operation) ?? normalized;
|
|
214
|
+
}
|
|
215
|
+
normalized = normalized.replace(/\r\n/g, '\n');
|
|
216
|
+
normalized = normalized.replace(/^<!--\s*artifact-context:[^\n]+-->\s*\n?/gm, '');
|
|
217
|
+
normalized = normalized.replace(/^\s*<!--\s*artifact-section:[^\n]+-->\s*\n?/gm, '');
|
|
218
|
+
normalized = normalized.replace(/^\s*<!--\s*artifact-slot:empty\s*-->\s*\n?/gm, '');
|
|
219
|
+
return normalized;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function canonicalSemanticDigest(content: string, operation: ArtifactRepairOperation | null = null): string {
|
|
223
|
+
return sha256Content(canonicalContent(content, operation));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function inspectArtifactStructure(
|
|
227
|
+
content: string,
|
|
228
|
+
schema: ArtifactSchema
|
|
229
|
+
): ArtifactStructureResult {
|
|
230
|
+
const diagnostics: ArtifactStructuralDiagnostic[] = [];
|
|
231
|
+
const scanned = scanVisibleMarkdown(content);
|
|
232
|
+
const repairCandidates: ArtifactRepairOperation[] = [];
|
|
233
|
+
if (!content.trim()) diagnostics.push(diagnostic('ARTIFACT_EMPTY', 'artifact is empty', null, null));
|
|
234
|
+
if (scanned.hasUnclosedFence) diagnostics.push(diagnostic('ARTIFACT_UNCLOSED_FENCE', 'artifact contains an unclosed Markdown fence', null, null));
|
|
235
|
+
|
|
236
|
+
const headingsBySection = new Map<string, typeof scanned.headings>();
|
|
237
|
+
for (const section of schema.sections) {
|
|
238
|
+
const aliases = sectionHeadings(schema, section);
|
|
239
|
+
const exact = scanned.headings.filter((heading) => heading.level === 2 && aliases.includes(heading.text));
|
|
240
|
+
const punctuated = scanned.headings.filter((heading) => heading.level === 2 && aliases.some((alias) => heading.text === `${alias}:` || heading.text === `${alias}:`));
|
|
241
|
+
headingsBySection.set(section.id, exact.length === 0 && punctuated.length === 1 ? punctuated : exact);
|
|
242
|
+
if (exact.length > 1 || punctuated.length > 0 && exact.length > 0 || punctuated.length > 1) {
|
|
243
|
+
const first = exact[1] ?? punctuated[0] ?? exact[0];
|
|
244
|
+
diagnostics.push(diagnostic(
|
|
245
|
+
'ARTIFACT_DUPLICATE_SECTION',
|
|
246
|
+
`required section '${aliases[0]}' is duplicated or has an ambiguous punctuation variant`,
|
|
247
|
+
section.id,
|
|
248
|
+
first ? lineNumber(content, first.start) : null
|
|
249
|
+
));
|
|
250
|
+
} else if (exact.length === 0 && punctuated.length === 1) {
|
|
251
|
+
repairCandidates.push(createHeadingRepair(content, section, punctuated[0]!));
|
|
252
|
+
} else if (exact.length === 0) {
|
|
253
|
+
diagnostics.push(diagnostic('ARTIFACT_MISSING_SECTION', `required section '${aliases[0]}' is missing`, section.id, null));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const markers = markerEntries(content, scanned);
|
|
258
|
+
const englishHeadings = scanned.headings.filter((heading) => heading.level === 2 && schema.sections.some((section) => section.headings.en === heading.text)).length;
|
|
259
|
+
const chineseHeadings = scanned.headings.filter((heading) => heading.level === 2 && schema.sections.some((section) => section.headings.zh === heading.text)).length;
|
|
260
|
+
const locale = englishHeadings > chineseHeadings ? 'en' : 'zh-CN';
|
|
261
|
+
for (const section of schema.sections) {
|
|
262
|
+
const matches = markers.filter((entry) => entry.marker === section.marker);
|
|
263
|
+
if (matches.length === 0) {
|
|
264
|
+
diagnostics.push(diagnostic('ARTIFACT_MARKER_MISSING', `section marker '${section.marker}' is missing`, section.id, null));
|
|
265
|
+
} else if (matches.length > 1) {
|
|
266
|
+
diagnostics.push(diagnostic('ARTIFACT_MARKER_DUPLICATE', `section marker '${section.marker}' is duplicated`, section.id, matches[1]!.line));
|
|
267
|
+
}
|
|
268
|
+
const marker = matches[0];
|
|
269
|
+
const heading = headingsBySection.get(section.id)?.[0];
|
|
270
|
+
if (marker && !marker.standalone) {
|
|
271
|
+
diagnostics.push(diagnostic('ARTIFACT_MARKER_MISMATCH', `section marker '${section.marker}' must occupy its own visible line`, section.id, marker.line));
|
|
272
|
+
}
|
|
273
|
+
if (marker && heading) {
|
|
274
|
+
const bounds = sectionBodyBounds(content, heading, scanned);
|
|
275
|
+
if (marker.start < bounds.start || marker.start >= bounds.end) {
|
|
276
|
+
diagnostics.push(diagnostic('ARTIFACT_MARKER_MISMATCH', `section marker '${section.marker}' is outside its section`, section.id, marker.line));
|
|
277
|
+
}
|
|
278
|
+
const body = stripHtmlComments(content.slice(bounds.start, bounds.end)).trim();
|
|
279
|
+
if (!body) diagnostics.push(diagnostic('ARTIFACT_EMPTY_SECTION', `section '${section.headings.zh}' has no semantic body`, section.id, lineNumber(content, heading.start)));
|
|
280
|
+
}
|
|
281
|
+
if (marker && !heading && marker.standalone) {
|
|
282
|
+
const nextHeading = scanned.headings.find((candidate) => candidate.start > marker.start && candidate.level <= 2);
|
|
283
|
+
const body = stripHtmlComments(content.slice(marker.end, nextHeading?.start ?? content.length)).trim();
|
|
284
|
+
if (body && repairCandidates.length === 0) {
|
|
285
|
+
repairCandidates.push(createSectionInsertionRepair(content, section, marker, locale));
|
|
286
|
+
} else if (!body) {
|
|
287
|
+
diagnostics.push(diagnostic('ARTIFACT_EMPTY_SECTION', `section '${section.headings.zh}' has no semantic body`, section.id, marker.line));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
for (const marker of markers) {
|
|
292
|
+
if (!schema.sections.some((section) => markerPattern(section.marker).test(`<!-- ${marker.marker} -->`))) {
|
|
293
|
+
diagnostics.push(diagnostic('ARTIFACT_MARKER_MISMATCH', `unknown section marker '${marker.marker}'`, null, marker.line));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
for (const candidate of repairCandidates) {
|
|
298
|
+
if (candidate.kind === 'replace-line') {
|
|
299
|
+
diagnostics.push(diagnostic(
|
|
300
|
+
'ARTIFACT_HEADING_TRAILING_PUNCTUATION',
|
|
301
|
+
`visible required H2 '${candidate.from}' may be normalized to '${candidate.to}'`,
|
|
302
|
+
candidate.sectionId,
|
|
303
|
+
candidate.line,
|
|
304
|
+
true,
|
|
305
|
+
candidate
|
|
306
|
+
));
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
const missing = diagnostics.findIndex((item) => item.code === 'ARTIFACT_MISSING_SECTION' && item.sectionId === candidate.sectionId);
|
|
310
|
+
if (missing >= 0) {
|
|
311
|
+
const section = schema.sections.find((item) => item.id === candidate.sectionId)!;
|
|
312
|
+
diagnostics.splice(missing, 1, diagnostic(
|
|
313
|
+
'ARTIFACT_MISSING_SECTION',
|
|
314
|
+
`required section '${section.headings.zh}' is missing and can be inserted at its unique marker`,
|
|
315
|
+
candidate.sectionId,
|
|
316
|
+
candidate.line,
|
|
317
|
+
true,
|
|
318
|
+
candidate
|
|
319
|
+
));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const orderedHeadings = schema.sections.flatMap((section) => {
|
|
324
|
+
const heading = headingsBySection.get(section.id)?.[0];
|
|
325
|
+
return heading ? [{ section, start: heading.start }] : [];
|
|
326
|
+
});
|
|
327
|
+
if (orderedHeadings.some((item, index) => index > 0 && item.start <= orderedHeadings[index - 1]!.start)) {
|
|
328
|
+
diagnostics.push(diagnostic('ARTIFACT_SECTION_ORDER_INVALID', 'required sections are not in schema order', null, null));
|
|
329
|
+
}
|
|
330
|
+
const orderedMarkers = schema.sections.flatMap((section) => {
|
|
331
|
+
const marker = markers.find((entry) => entry.marker === section.marker);
|
|
332
|
+
return marker ? [{ section, start: marker.start }] : [];
|
|
333
|
+
});
|
|
334
|
+
if (orderedMarkers.some((item, index) => index > 0 && item.start <= orderedMarkers[index - 1]!.start)) {
|
|
335
|
+
diagnostics.push(diagnostic('ARTIFACT_SECTION_ORDER_INVALID', 'section markers are not in schema order', null, null));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const repair = repairCandidates.length === 1 && (
|
|
339
|
+
diagnostics.length === 0 ||
|
|
340
|
+
(diagnostics.length === 1 && diagnostics[0]?.operation?.kind === repairCandidates[0]?.kind)
|
|
341
|
+
) ? repairCandidates[0]! : null;
|
|
342
|
+
return {
|
|
343
|
+
ok: diagnostics.length === 0,
|
|
344
|
+
family: schema.family,
|
|
345
|
+
semanticDigest: canonicalSemanticDigest(content, repair),
|
|
346
|
+
diagnostics,
|
|
347
|
+
repair
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function inspectArtifactPatterns(
|
|
352
|
+
content: string,
|
|
353
|
+
schema: ArtifactSchema
|
|
354
|
+
): ArtifactStructureResult {
|
|
355
|
+
const diagnostics = schema.requiredPatterns
|
|
356
|
+
.filter((pattern) => !new RegExp(pattern, 'm').test(content))
|
|
357
|
+
.map((pattern) => diagnostic(
|
|
358
|
+
'ARTIFACT_REQUIRED_PATTERN_MISSING',
|
|
359
|
+
`artifact is missing required pattern '${pattern}'`,
|
|
360
|
+
null,
|
|
361
|
+
null
|
|
362
|
+
));
|
|
363
|
+
return {
|
|
364
|
+
ok: diagnostics.length === 0,
|
|
365
|
+
family: schema.family,
|
|
366
|
+
semanticDigest: canonicalSemanticDigest(content),
|
|
367
|
+
diagnostics,
|
|
368
|
+
repair: null
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function inspectArtifactContract(
|
|
373
|
+
content: string,
|
|
374
|
+
schema: ArtifactSchema
|
|
375
|
+
): ArtifactStructureResult {
|
|
376
|
+
const structure = inspectArtifactStructure(content, schema);
|
|
377
|
+
const patterns = inspectArtifactPatterns(content, schema);
|
|
378
|
+
const diagnostics = [...structure.diagnostics, ...patterns.diagnostics];
|
|
379
|
+
const repair = patterns.diagnostics.length === 0 ? structure.repair : null;
|
|
380
|
+
return {
|
|
381
|
+
ok: diagnostics.length === 0,
|
|
382
|
+
family: schema.family,
|
|
383
|
+
semanticDigest: canonicalSemanticDigest(content, repair),
|
|
384
|
+
diagnostics,
|
|
385
|
+
repair
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function resultFailure(code: string, message: string): ArtifactFileResult {
|
|
390
|
+
return { status: 'failed', changed: false, artifactSha256: null, semanticDigest: null, operation: null, error: { code, message } };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function resultNoOp(content: string): ArtifactFileResult {
|
|
394
|
+
return {
|
|
395
|
+
status: 'no-op',
|
|
396
|
+
changed: false,
|
|
397
|
+
artifactSha256: sha256Content(content),
|
|
398
|
+
semanticDigest: canonicalSemanticDigest(content),
|
|
399
|
+
operation: null,
|
|
400
|
+
error: null
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function validateRepairContext(request: ArtifactRepairRequest, content: string): { ok: true } | { ok: false; code: string; message: string } {
|
|
405
|
+
const round = artifactRound(request.family, request.artifact);
|
|
406
|
+
if (round === null) return { ok: false, code: 'ARTIFACT_REPAIR_CONTEXT_INVALID', message: 'artifact round is not canonical' };
|
|
407
|
+
const contextPattern = /^<!--\s*artifact-context:([^:\s]+):([^:\s]+):(\d+)\s*-->\s*$/;
|
|
408
|
+
const contexts = scanVisibleMarkdown(content).lines
|
|
409
|
+
.map((line) => line.text.trim().match(contextPattern))
|
|
410
|
+
.filter((match): match is RegExpMatchArray => match !== null);
|
|
411
|
+
if (contexts.length !== 1
|
|
412
|
+
|| contexts[0]![1] !== request.taskId
|
|
413
|
+
|| contexts[0]![2] !== request.family
|
|
414
|
+
|| Number(contexts[0]![3]) !== round) {
|
|
415
|
+
return { ok: false, code: 'ARTIFACT_REPAIR_CONTEXT_INVALID', message: 'artifact context marker does not match the requested task, family, and round' };
|
|
416
|
+
}
|
|
417
|
+
let taskContent: string;
|
|
418
|
+
const resolved = resolveTaskRef(request.taskId, { repoRoot: request.repoRoot });
|
|
419
|
+
if (!resolved.ok) return { ok: false, code: 'ARTIFACT_REPAIR_CONTEXT_INVALID', message: resolved.message };
|
|
420
|
+
try { taskContent = fs.readFileSync(resolved.taskMdPath, 'utf8'); }
|
|
421
|
+
catch (error) { return { ok: false, code: 'ARTIFACT_REPAIR_CONTEXT_INVALID', message: `cannot read task lifecycle context: ${String(error)}` }; }
|
|
422
|
+
if (!hasOpenArtifactRound(taskContent, request.family, round)) {
|
|
423
|
+
return { ok: false, code: 'ARTIFACT_REPAIR_CONTEXT_INVALID', message: `artifact '${request.artifact}' does not have exactly one matching open started lifecycle event` };
|
|
424
|
+
}
|
|
425
|
+
let intent;
|
|
426
|
+
try { intent = readArtifactRepairIntent(request.repoRoot, request.taskId, request.family, request.artifact); }
|
|
427
|
+
catch (error) { return { ok: false, code: 'ARTIFACT_REPAIR_PROVENANCE_INVALID', message: String(error) }; }
|
|
428
|
+
if (!intent || intent.state !== 'awaiting-repair') {
|
|
429
|
+
return { ok: false, code: 'ARTIFACT_REPAIR_PROVENANCE_INVALID', message: 'artifact has no awaiting-repair finalization provenance' };
|
|
430
|
+
}
|
|
431
|
+
if (intent.artifactSha256 !== request.expectedSha256 || intent.semanticDigest !== request.expectedSemanticDigest) {
|
|
432
|
+
return { ok: false, code: 'ARTIFACT_REPAIR_PROVENANCE_INVALID', message: 'repair request does not match the current finalization provenance' };
|
|
433
|
+
}
|
|
434
|
+
return { ok: true };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function artifactRound(family: ArtifactSchemaFamily, artifact: string): number | null {
|
|
438
|
+
const identity = parseArtifactName(artifact);
|
|
439
|
+
return identity?.family === family ? identity.round : null;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function validateTarget(taskDir: string, family: ArtifactSchemaFamily, artifact: string): { path: string } | ArtifactFileResult {
|
|
443
|
+
if (path.basename(artifact) !== artifact || artifactRound(family, artifact) === null || !artifact.endsWith('.md')) return resultFailure('ARTIFACT_REPAIR_TARGET_INVALID', 'artifact must be a canonical top-level Markdown file');
|
|
444
|
+
if (!/^TASK-\d{8}-\d{6}$/.test(path.basename(path.resolve(taskDir)))) return resultFailure('ARTIFACT_REPAIR_TARGET_INVALID', 'target directory is not a task directory');
|
|
445
|
+
const target = path.join(taskDir, artifact);
|
|
446
|
+
if (path.dirname(path.resolve(target)) !== path.resolve(taskDir)) return resultFailure('ARTIFACT_REPAIR_TARGET_INVALID', 'artifact must be inside the current task directory');
|
|
447
|
+
let stat: fs.Stats;
|
|
448
|
+
try { stat = fs.lstatSync(target); }
|
|
449
|
+
catch (error) { return resultFailure('ARTIFACT_REPAIR_TARGET_INVALID', `artifact cannot be read: ${String(error)}`); }
|
|
450
|
+
if (stat.isSymbolicLink() || !stat.isFile()) return resultFailure('ARTIFACT_REPAIR_TARGET_INVALID', 'artifact is not a regular file');
|
|
451
|
+
try { fs.accessSync(target, fs.constants.R_OK | fs.constants.W_OK); }
|
|
452
|
+
catch (error) { return resultFailure('ARTIFACT_REPAIR_TARGET_INVALID', `artifact is not readable and writable: ${String(error)}`); }
|
|
453
|
+
return { path: target };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function applyRepairUnlocked(request: ArtifactRepairRequest): ArtifactFileResult {
|
|
457
|
+
const schema = getArtifactSchema(request.family);
|
|
458
|
+
if (!schema) return resultFailure('ARTIFACT_FAMILY_UNKNOWN', `unknown artifact family '${request.family}'`);
|
|
459
|
+
const target = validateTarget(request.taskDir, request.family, request.artifact);
|
|
460
|
+
if ('status' in target) return target;
|
|
461
|
+
let content: string;
|
|
462
|
+
try { content = readStableFileSync(target.path, { maxBytes: 1024 * 1024 }).bytes.toString('utf8'); }
|
|
463
|
+
catch (error) { return resultFailure('ARTIFACT_REPAIR_TARGET_INVALID', String(error)); }
|
|
464
|
+
const actualSha256 = sha256Content(content);
|
|
465
|
+
if (actualSha256 !== request.expectedSha256) return resultFailure('ARTIFACT_REPAIR_BASELINE_MISMATCH', 'artifact SHA-256 does not match the expected repair baseline');
|
|
466
|
+
const context = validateRepairContext(request, content);
|
|
467
|
+
if (!context.ok) return resultFailure(context.code, context.message);
|
|
468
|
+
const inspection = inspectArtifactStructure(content, schema);
|
|
469
|
+
if (!inspection.repair || inspection.diagnostics.length !== 1) {
|
|
470
|
+
return resultFailure('ARTIFACT_REPAIR_UNSAFE', inspection.diagnostics.map((item) => `${item.code}: ${item.message}`).join('; ') || 'no deterministic structural repair is available');
|
|
471
|
+
}
|
|
472
|
+
if (inspection.repair.kind !== request.operation.kind
|
|
473
|
+
|| inspection.repair.sectionId !== request.operation.sectionId
|
|
474
|
+
|| inspection.repair.from !== request.operation.from
|
|
475
|
+
|| inspection.repair.to !== request.operation.to
|
|
476
|
+
|| inspection.repair.start !== request.operation.start
|
|
477
|
+
|| inspection.repair.end !== request.operation.end) {
|
|
478
|
+
return resultFailure('ARTIFACT_REPAIR_OPERATION_MISMATCH', 'repair operation does not match the current artifact structure');
|
|
479
|
+
}
|
|
480
|
+
if (inspection.semanticDigest !== request.expectedSemanticDigest) return resultFailure('ARTIFACT_REPAIR_BASELINE_MISMATCH', 'artifact semantic digest does not match the expected repair baseline');
|
|
481
|
+
const transformed = applyRepairOperation(content, inspection.repair);
|
|
482
|
+
if (transformed === null) return resultFailure('ARTIFACT_REPAIR_OPERATION_MISMATCH', 'repair operation does not match the current artifact bytes');
|
|
483
|
+
if (transformed === content) return resultFailure('ARTIFACT_REPAIR_NO_PROGRESS', 'repair operation produced no byte change');
|
|
484
|
+
const tempPath = path.join(request.taskDir, `.${request.artifact}.repair-${process.pid}-${Date.now()}.tmp`);
|
|
485
|
+
let mode = 0o600;
|
|
486
|
+
try {
|
|
487
|
+
mode = fs.statSync(target.path).mode & 0o777;
|
|
488
|
+
fs.writeFileSync(tempPath, transformed, { encoding: 'utf8', mode, flag: 'wx' });
|
|
489
|
+
const currentStat = fs.lstatSync(target.path);
|
|
490
|
+
if (currentStat.isSymbolicLink() || !currentStat.isFile() || readStableFileSync(target.path, { maxBytes: 1024 * 1024 }).sha256 !== actualSha256) {
|
|
491
|
+
fs.unlinkSync(tempPath);
|
|
492
|
+
return resultFailure('ARTIFACT_REPAIR_CONFLICT', 'artifact changed or was replaced during repair');
|
|
493
|
+
}
|
|
494
|
+
fs.renameSync(tempPath, target.path);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
try { fs.unlinkSync(tempPath); } catch { /* preserve primary error */ }
|
|
497
|
+
return resultFailure('ARTIFACT_REPAIR_WRITE_FAILED', String(error));
|
|
498
|
+
}
|
|
499
|
+
return {
|
|
500
|
+
status: 'applied',
|
|
501
|
+
changed: true,
|
|
502
|
+
artifactSha256: sha256Content(transformed),
|
|
503
|
+
semanticDigest: canonicalSemanticDigest(transformed),
|
|
504
|
+
operation: inspection.repair,
|
|
505
|
+
error: null
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function applyArtifactRepair(request: ArtifactRepairRequest): ArtifactFileResult {
|
|
510
|
+
try {
|
|
511
|
+
return withTaskExecutionLock(request.repoRoot, request.taskId, 'task-artifact.repair', () => applyRepairUnlocked(request));
|
|
512
|
+
} catch (error) {
|
|
513
|
+
return resultFailure('ARTIFACT_REPAIR_LOCK_FAILED', String(error));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function initializeArtifactSkeleton(request: ArtifactInitRequest): ArtifactFileResult {
|
|
518
|
+
const schema = getArtifactSchema(request.family);
|
|
519
|
+
if (!schema) return resultFailure('ARTIFACT_FAMILY_UNKNOWN', `unknown artifact family '${request.family}'`);
|
|
520
|
+
if (artifactRound(request.family, request.artifact) === null) return resultFailure('ARTIFACT_INIT_TARGET_INVALID', 'artifact must be a canonical top-level Markdown file');
|
|
521
|
+
if (!/^TASK-\d{8}-\d{6}$/.test(path.basename(path.resolve(request.taskDir))) || path.basename(path.resolve(request.taskDir)) !== request.taskId) return resultFailure('ARTIFACT_INIT_TARGET_INVALID', 'target directory is not the requested task directory');
|
|
522
|
+
const target = path.join(request.taskDir, request.artifact);
|
|
523
|
+
if (path.dirname(path.resolve(target)) !== path.resolve(request.taskDir)) return resultFailure('ARTIFACT_INIT_TARGET_INVALID', 'artifact must be inside the current task directory');
|
|
524
|
+
try {
|
|
525
|
+
return withTaskExecutionLock(request.repoRoot, request.taskId, 'task-artifact.init', () => {
|
|
526
|
+
try {
|
|
527
|
+
const existing = fs.lstatSync(target);
|
|
528
|
+
if (existing.isSymbolicLink() || !existing.isFile()) return resultFailure('ARTIFACT_INIT_TARGET_INVALID', 'artifact target is not a regular file');
|
|
529
|
+
return resultNoOp(readStableFileSync(target, { maxBytes: 1024 * 1024 }).bytes.toString('utf8'));
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') return resultFailure('ARTIFACT_INIT_TARGET_INVALID', String(error));
|
|
532
|
+
}
|
|
533
|
+
const content = renderArtifactSkeleton({
|
|
534
|
+
taskId: request.taskId,
|
|
535
|
+
family: request.family,
|
|
536
|
+
artifact: request.artifact,
|
|
537
|
+
...(request.locale ? { locale: request.locale } : {})
|
|
538
|
+
});
|
|
539
|
+
const tempPath = path.join(request.taskDir, `.${request.artifact}.init-${process.pid}-${Date.now()}.tmp`);
|
|
540
|
+
try {
|
|
541
|
+
fs.writeFileSync(tempPath, content, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
542
|
+
try { fs.lstatSync(target); fs.unlinkSync(tempPath); return resultFailure('ARTIFACT_INIT_TARGET_EXISTS', 'artifact was created concurrently'); }
|
|
543
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; }
|
|
544
|
+
fs.renameSync(tempPath, target);
|
|
545
|
+
} catch (error) {
|
|
546
|
+
try { fs.unlinkSync(tempPath); } catch { /* preserve primary error */ }
|
|
547
|
+
return resultFailure('ARTIFACT_INIT_WRITE_FAILED', String(error));
|
|
548
|
+
}
|
|
549
|
+
return {
|
|
550
|
+
status: 'applied',
|
|
551
|
+
changed: true,
|
|
552
|
+
artifactSha256: sha256Content(content),
|
|
553
|
+
semanticDigest: canonicalSemanticDigest(content),
|
|
554
|
+
operation: null,
|
|
555
|
+
error: null
|
|
556
|
+
};
|
|
557
|
+
});
|
|
558
|
+
} catch (error) {
|
|
559
|
+
return resultFailure('ARTIFACT_INIT_LOCK_FAILED', String(error));
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export {
|
|
564
|
+
applyArtifactRepair,
|
|
565
|
+
canonicalSemanticDigest,
|
|
566
|
+
initializeArtifactSkeleton,
|
|
567
|
+
inspectArtifactContract,
|
|
568
|
+
inspectArtifactPatterns,
|
|
569
|
+
inspectArtifactStructure,
|
|
570
|
+
sha256Content
|
|
571
|
+
};
|
|
572
|
+
export type {
|
|
573
|
+
ArtifactFileResult,
|
|
574
|
+
ArtifactInitRequest,
|
|
575
|
+
ArtifactRepairOperation,
|
|
576
|
+
ArtifactRepairRequest,
|
|
577
|
+
ArtifactStructuralDiagnostic,
|
|
578
|
+
ArtifactStructuralDiagnosticCode,
|
|
579
|
+
ArtifactStructureResult
|
|
580
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
|
|
4
|
+
import { parseArtifactName } from './artifact-name.ts';
|
|
4
5
|
import { extractSection, findSectionHeading, parseTable } from './sections.ts';
|
|
5
6
|
|
|
6
7
|
const RECEIPT_SECTION_ALIASES = ['产物生命周期收据', 'Artifact Lifecycle Receipts'] as const;
|
|
@@ -12,7 +13,6 @@ const RECEIPT_EVENTS = new Set([
|
|
|
12
13
|
'code.completed'
|
|
13
14
|
]);
|
|
14
15
|
const SHA256_RE = /^[a-f0-9]{64}$/;
|
|
15
|
-
const ARTIFACT_NAME_RE = /^(analysis|review-analysis|plan|review-plan|code|review-code|manual-validation|validation-run|pr-review)(?:-r([2-9]|[1-9]\d+))?\.md$/;
|
|
16
16
|
const RECEIPT_SHAPES = {
|
|
17
17
|
'review-analysis.completed': { output: 'review-analysis', input: 'analysis' },
|
|
18
18
|
'review-plan.completed': { output: 'review-plan', input: 'plan' },
|
|
@@ -59,20 +59,9 @@ function sha256File(filePath: string): string {
|
|
|
59
59
|
return sha256Bytes(fs.readFileSync(filePath));
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function parseReceiptArtifactName(name: string): { family: string } | null {
|
|
63
|
-
const match = ARTIFACT_NAME_RE.exec(name);
|
|
64
|
-
if (!match) return null;
|
|
65
|
-
const roundText = match[2];
|
|
66
|
-
if (roundText !== undefined) {
|
|
67
|
-
const round = Number(roundText);
|
|
68
|
-
if (!Number.isSafeInteger(round) || String(round) !== roundText) return null;
|
|
69
|
-
}
|
|
70
|
-
return { family: match[1]! };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
62
|
function validateReceiptShape(event: ArtifactReceiptEvent, output: string, input: string): void {
|
|
74
|
-
const outputIdentity =
|
|
75
|
-
const inputIdentity =
|
|
63
|
+
const outputIdentity = parseArtifactName(output);
|
|
64
|
+
const inputIdentity = parseArtifactName(input);
|
|
76
65
|
if (!outputIdentity || !inputIdentity) throw new ArtifactReceiptError(`receipt artifact identity is invalid: ${output} -> ${input}`);
|
|
77
66
|
const shape = RECEIPT_SHAPES[event];
|
|
78
67
|
if (outputIdentity.family !== shape.output || inputIdentity.family !== shape.input) {
|