@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
|
@@ -1,815 +1,12 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
1
|
import { parseArgs } from 'node:util';
|
|
4
|
-
import * as p from '@clack/prompts';
|
|
5
|
-
import pc from 'picocolors';
|
|
6
2
|
import { loadConfig } from '../config.js';
|
|
7
|
-
import { assertValidBranchName, containerNameCandidates, sandboxBranchLabel, sandboxLabel, sandboxTaskIdLabel, sandboxWorkspaceModeLabel, shareBranchDir, shellConfigDirCandidates, worktreeDirCandidates } from '../constants.js';
|
|
8
|
-
import { ENGINES, detectEngine, engineDisplayName, isManagedEngine, stopManagedVm } from '../engine.js';
|
|
9
|
-
import { pruneSandboxDanglingImages } from '../image-prune.js';
|
|
10
|
-
import { assertManagedPath, removeManagedDir, removeWorktreeDir } from '../managed-fs.js';
|
|
11
|
-
import { runEngine, runOk, runOkEngine, runSafe, runSafeEngine } from '../shell.js';
|
|
12
|
-
import { parseSandboxWorkspaceIdentity, resolveSandboxCleanupTarget, sameSandboxWorkspaceIdentity } from '../workspace-identity.js';
|
|
13
|
-
import { sandboxControlPaths, sandboxWorkspaceViewPaths } from '../workspace-view.js';
|
|
14
|
-
import { removeSandboxControlRoot, readSandboxControlManifest } from '../control/lifecycle.js';
|
|
15
|
-
import { inspectSandboxControlContainer } from '../control/container-identity.js';
|
|
16
|
-
import { toolConfigDirCandidates, toolProjectDirCandidates } from '../tools.js';
|
|
17
3
|
import { createSandboxCapabilityPlan } from '../agent-client-reconciler.js';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
4
|
+
import { resolveSandboxCleanupTarget } from '../workspace-identity.js';
|
|
5
|
+
import { rmOne, rmPurge, rmUnbound } from '../removal.js';
|
|
20
6
|
const USAGE = `Usage:
|
|
21
7
|
ai sandbox rm <branch | TASK-id | short id> Remove one sandbox; use a full TASK-id for a task-bound sandbox and a branch for branch-only sandboxes
|
|
22
|
-
ai sandbox rm --unbound [--dry-run] [--yes] Remove completed task-bound and branch-only sandboxes; active, blocked, and archive tasks are protected
|
|
8
|
+
ai sandbox rm --unbound [--dry-run] [--yes] Remove completed task-bound and branch-only sandboxes and verified auxiliary state; active, blocked, and archive tasks are protected
|
|
23
9
|
ai sandbox rm --purge Tear down ALL sandboxes for the project (containers, worktrees, image, VM)`;
|
|
24
|
-
export { assertManagedPath } from '../managed-fs.js';
|
|
25
|
-
function projectToolDirs(config, tools) {
|
|
26
|
-
return tools.flatMap((tool) => toolProjectDirCandidates(tool, config.project));
|
|
27
|
-
}
|
|
28
|
-
function isMissingPathError(error) {
|
|
29
|
-
return Boolean(error && typeof error === 'object' && 'code' in error
|
|
30
|
-
&& error.code === 'ENOENT');
|
|
31
|
-
}
|
|
32
|
-
export function sandboxManagedPathKey(candidate, platform = process.platform, resolveExistingPath = (resolved) => fs.realpathSync.native(resolved)) {
|
|
33
|
-
const resolved = path.resolve(candidate);
|
|
34
|
-
let identity = resolved;
|
|
35
|
-
try {
|
|
36
|
-
identity = resolveExistingPath(resolved);
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
if (!isMissingPathError(error)) {
|
|
40
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: unable to determine managed path identity for '${resolved}'`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return platform === 'win32' ? identity.toLowerCase() : identity;
|
|
44
|
-
}
|
|
45
|
-
function recoveryContexts(config, target, worktrees) {
|
|
46
|
-
const candidates = worktreeDirCandidates(config, target.effectiveBranch).map((candidate) => path.resolve(candidate));
|
|
47
|
-
const existingCandidates = candidates.filter((candidate) => fs.existsSync(candidate));
|
|
48
|
-
if (existingCandidates.length !== 1)
|
|
49
|
-
return new Map();
|
|
50
|
-
const contexts = new Map();
|
|
51
|
-
for (const worktree of worktrees) {
|
|
52
|
-
const resolvedWorktree = path.resolve(worktree);
|
|
53
|
-
if (resolvedWorktree !== existingCandidates[0])
|
|
54
|
-
continue;
|
|
55
|
-
for (const root of target.controlRoots.filter((candidate) => fs.existsSync(candidate))) {
|
|
56
|
-
assertLegacyCandidateEvidence(root, config.controlBase, config, target.effectiveBranch, target.matchedContainers);
|
|
57
|
-
assertControlRootMatchesTarget(root, target.effectiveBranch, target.workspace);
|
|
58
|
-
}
|
|
59
|
-
contexts.set(resolvedWorktree, {
|
|
60
|
-
repoRoot: config.repoRoot,
|
|
61
|
-
worktreeBase: config.worktreeBase,
|
|
62
|
-
branch: target.effectiveBranch,
|
|
63
|
-
identitySource: target.workspace.mode,
|
|
64
|
-
taskId: target.workspace.mode === 'task-bound' ? target.workspace.taskId : null
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return contexts;
|
|
68
|
-
}
|
|
69
|
-
function resolveRmTarget(config, tools, cleanupTarget, options = {}) {
|
|
70
|
-
assertValidBranchName(cleanupTarget.branch);
|
|
71
|
-
const engine = detectEngine(config);
|
|
72
|
-
const branch = cleanupTarget.branch;
|
|
73
|
-
const effectiveBranch = branch;
|
|
74
|
-
const worktreeCandidates = worktreeDirCandidates(config, branch);
|
|
75
|
-
const toolCandidates = tools.map((tool) => ({
|
|
76
|
-
tool,
|
|
77
|
-
candidates: toolConfigDirCandidates(tool, config.project, branch)
|
|
78
|
-
}));
|
|
79
|
-
const shellCandidates = shellConfigDirCandidates(config, branch);
|
|
80
|
-
const existing = runEngine(engine, 'docker', ['ps', '-a', '--format', '{{.Names}}']).split('\n').filter(Boolean);
|
|
81
|
-
const matchedContainers = options.discoveredContainers
|
|
82
|
-
? options.discoveredContainers.map((container) => {
|
|
83
|
-
if (!existing.includes(container)) {
|
|
84
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: discovered container '${container}' is no longer present`);
|
|
85
|
-
}
|
|
86
|
-
return container;
|
|
87
|
-
})
|
|
88
|
-
: containerNameCandidates(config, branch).filter((name) => existing.includes(name));
|
|
89
|
-
const workspace = cleanupTarget.workspace;
|
|
90
|
-
const identities = [workspace];
|
|
91
|
-
const containers = options.discoveredContainers
|
|
92
|
-
? matchedContainers
|
|
93
|
-
: [...new Set([...containerNameCandidates(config, effectiveBranch), ...matchedContainers])];
|
|
94
|
-
const controlRoots = containers.flatMap((container) => identities.map((identity) => sandboxControlPaths({
|
|
95
|
-
base: config.controlBase, project: config.project, container, identity
|
|
96
|
-
}).root));
|
|
97
|
-
const workspaceViewRoots = containers.flatMap((container) => identities.map((identity) => sandboxWorkspaceViewPaths({
|
|
98
|
-
base: config.workspaceViewBase, project: config.project, container, identity
|
|
99
|
-
}).root));
|
|
100
|
-
const managedPathCandidates = [...new Set([
|
|
101
|
-
...worktreeCandidates,
|
|
102
|
-
...toolCandidates.flatMap(({ candidates }) => candidates),
|
|
103
|
-
...shellCandidates,
|
|
104
|
-
shareBranchDir(config, branch),
|
|
105
|
-
...controlRoots,
|
|
106
|
-
...workspaceViewRoots
|
|
107
|
-
].map((candidate) => path.resolve(candidate)))];
|
|
108
|
-
return {
|
|
109
|
-
branch,
|
|
110
|
-
effectiveBranch,
|
|
111
|
-
engine,
|
|
112
|
-
matchedContainers,
|
|
113
|
-
existingWorktrees: worktreeCandidates.filter((candidate) => fs.existsSync(candidate)),
|
|
114
|
-
toolCandidates,
|
|
115
|
-
managedPathCandidates,
|
|
116
|
-
workspace,
|
|
117
|
-
controlRoots: [...new Set(controlRoots)],
|
|
118
|
-
workspaceViewRoots: [...new Set(workspaceViewRoots)]
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function inspectNamedContainerIdentity(target, container) {
|
|
122
|
-
const raw = runSafeEngine(target.engine, 'docker', [
|
|
123
|
-
'inspect', '--format', '{{json .}}', container
|
|
124
|
-
]).trim();
|
|
125
|
-
let parsed;
|
|
126
|
-
try {
|
|
127
|
-
parsed = JSON.parse(raw);
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
throw new Error(`SANDBOX_WORKSPACE_IDENTITY_UNKNOWN: container '${container}' inspection is invalid`);
|
|
131
|
-
}
|
|
132
|
-
const value = Array.isArray(parsed) && parsed.length === 1 ? parsed[0] : parsed;
|
|
133
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
134
|
-
throw new Error(`SANDBOX_WORKSPACE_IDENTITY_UNKNOWN: container '${container}' inspection is incomplete`);
|
|
135
|
-
}
|
|
136
|
-
const candidate = value;
|
|
137
|
-
if (typeof candidate.Id !== 'string' || !candidate.Id
|
|
138
|
-
|| !candidate.Config?.Labels || typeof candidate.Config.Labels !== 'object'
|
|
139
|
-
|| Array.isArray(candidate.Config.Labels)
|
|
140
|
-
|| Object.values(candidate.Config.Labels).some((value) => typeof value !== 'string')) {
|
|
141
|
-
throw new Error(`SANDBOX_WORKSPACE_IDENTITY_UNKNOWN: container '${container}' inspection is incomplete`);
|
|
142
|
-
}
|
|
143
|
-
return { id: candidate.Id, labels: candidate.Config.Labels };
|
|
144
|
-
}
|
|
145
|
-
function assertMatchedContainerIdentities(config, target) {
|
|
146
|
-
const current = new Map();
|
|
147
|
-
for (const container of target.matchedContainers) {
|
|
148
|
-
const observation = inspectNamedContainerIdentity(target, container);
|
|
149
|
-
const stringLabels = observation.labels;
|
|
150
|
-
const branch = stringLabels[sandboxBranchLabel(config)];
|
|
151
|
-
if (branch !== target.branch) {
|
|
152
|
-
throw new Error(`SANDBOX_WORKSPACE_IDENTITY_CONFLICT: container '${container}' branch is ${JSON.stringify(branch ?? null)}, `
|
|
153
|
-
+ `but this request is ${JSON.stringify(target.branch)}`);
|
|
154
|
-
}
|
|
155
|
-
const identity = parseSandboxWorkspaceIdentity(stringLabels, {
|
|
156
|
-
mode: sandboxWorkspaceModeLabel(config),
|
|
157
|
-
taskId: sandboxTaskIdLabel(config)
|
|
158
|
-
});
|
|
159
|
-
if (identity.mode === 'legacy-invalid' || !sameSandboxWorkspaceIdentity(identity, target.workspace)) {
|
|
160
|
-
const existingDescription = identity.mode === 'task-bound'
|
|
161
|
-
? `task-bound:${identity.taskId}`
|
|
162
|
-
: identity.mode;
|
|
163
|
-
const requestedDescription = target.workspace.mode === 'task-bound'
|
|
164
|
-
? `task-bound:${target.workspace.taskId}`
|
|
165
|
-
: target.workspace.mode;
|
|
166
|
-
throw new Error(`SANDBOX_WORKSPACE_IDENTITY_CONFLICT: container '${container}' is ${existingDescription}, `
|
|
167
|
-
+ `but this request is ${requestedDescription}`);
|
|
168
|
-
}
|
|
169
|
-
current.set(container, observation);
|
|
170
|
-
}
|
|
171
|
-
return current;
|
|
172
|
-
}
|
|
173
|
-
function controlRootContainer(config, root) {
|
|
174
|
-
const relative = path.relative(path.join(config.controlBase, config.project), root);
|
|
175
|
-
const [container, identity, ...extra] = relative.split(path.sep);
|
|
176
|
-
if (!container || !identity || extra.length > 0) {
|
|
177
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_EVIDENCE_INVALID: ${root}`);
|
|
178
|
-
}
|
|
179
|
-
return container;
|
|
180
|
-
}
|
|
181
|
-
function assertControlRootMatchesTarget(root, effectiveBranch, workspace) {
|
|
182
|
-
const manifestPath = path.join(root, 'manifest.json');
|
|
183
|
-
if (!fs.existsSync(manifestPath)) {
|
|
184
|
-
if (workspace.mode === 'task-bound') {
|
|
185
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_EVIDENCE_MISSING: ${root}`);
|
|
186
|
-
}
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const manifest = readSandboxControlManifest(manifestPath);
|
|
190
|
-
const identityMatches = workspace.mode === 'task-bound'
|
|
191
|
-
? manifest.mode === 'task-bound' && manifest.taskId === workspace.taskId
|
|
192
|
-
: manifest.mode === 'branch-only';
|
|
193
|
-
if (manifest.branch !== effectiveBranch || !identityMatches) {
|
|
194
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_MISMATCH: ${root}`);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function preflightRmTarget(config, target) {
|
|
198
|
-
const current = assertMatchedContainerIdentities(config, target);
|
|
199
|
-
const manifests = [];
|
|
200
|
-
for (const root of target.controlRoots.filter((candidate) => fs.existsSync(candidate))) {
|
|
201
|
-
assertLegacyCandidateEvidence(root, config.controlBase, config, target.effectiveBranch, target.matchedContainers);
|
|
202
|
-
assertControlRootMatchesTarget(root, target.effectiveBranch, target.workspace);
|
|
203
|
-
const manifestPath = path.join(root, 'manifest.json');
|
|
204
|
-
if (!fs.existsSync(manifestPath))
|
|
205
|
-
continue;
|
|
206
|
-
const manifest = readSandboxControlManifest(manifestPath);
|
|
207
|
-
const rootContainer = controlRootContainer(config, root);
|
|
208
|
-
if (manifest.container !== rootContainer) {
|
|
209
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_MISMATCH: ${root}`);
|
|
210
|
-
}
|
|
211
|
-
const observed = current.get(manifest.container);
|
|
212
|
-
if (observed && (observed.id !== manifest.containerIdentity.id
|
|
213
|
-
|| Object.entries(manifest.containerIdentity.labels).some(([key, value]) => observed.labels[key] !== value))) {
|
|
214
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_MISMATCH: ${root}`);
|
|
215
|
-
}
|
|
216
|
-
manifests.push(manifest);
|
|
217
|
-
}
|
|
218
|
-
if (target.workspace.mode !== 'task-bound')
|
|
219
|
-
return;
|
|
220
|
-
const matched = new Set(target.matchedContainers);
|
|
221
|
-
const manifestContainers = manifests.map((manifest) => manifest.container);
|
|
222
|
-
if (matched.size > 0 && manifestContainers.some((container) => !matched.has(container))) {
|
|
223
|
-
throw new Error('SANDBOX_CONTROL_TARGET_MISMATCH: manifest container is outside the cleanup target');
|
|
224
|
-
}
|
|
225
|
-
for (const container of matched) {
|
|
226
|
-
const matches = manifests.filter((manifest) => manifest.container === container);
|
|
227
|
-
if (matches.length !== 1) {
|
|
228
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_EVIDENCE_MISSING: container '${container}'`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (matched.size === 0 && manifests.length > 0) {
|
|
232
|
-
const supported = new Set(containerNameCandidates(config, target.effectiveBranch));
|
|
233
|
-
if (manifests.some((manifest) => !supported.has(manifest.container))) {
|
|
234
|
-
throw new Error('SANDBOX_CONTROL_TARGET_MISMATCH: manifest container is outside the cleanup target');
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function assertCleanupGroupPathsDoNotOverlap(groups) {
|
|
239
|
-
const owners = new Map();
|
|
240
|
-
for (const group of groups) {
|
|
241
|
-
for (const candidate of group.target.managedPathCandidates ?? []) {
|
|
242
|
-
const key = sandboxManagedPathKey(candidate);
|
|
243
|
-
const existingBranch = owners.get(key);
|
|
244
|
-
if (existingBranch && existingBranch !== group.cleanupTarget.branch) {
|
|
245
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: managed path '${candidate}' is shared by branches `
|
|
246
|
-
+ `${JSON.stringify(existingBranch)} and ${JSON.stringify(group.cleanupTarget.branch)}`);
|
|
247
|
-
}
|
|
248
|
-
owners.set(key, group.cleanupTarget.branch);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function assertWorktreeBranchesMatchGroups(groups, inspections) {
|
|
253
|
-
const byPath = new Map(inspections.flatMap((inspection) => inspection.status === 'failed'
|
|
254
|
-
? []
|
|
255
|
-
: [[sandboxManagedPathKey(inspection.snapshot.worktree), inspection.snapshot.branch]]));
|
|
256
|
-
for (const group of groups) {
|
|
257
|
-
for (const worktree of group.target.existingWorktrees) {
|
|
258
|
-
const registeredBranch = byPath.get(sandboxManagedPathKey(worktree));
|
|
259
|
-
if (registeredBranch && registeredBranch !== group.cleanupTarget.branch) {
|
|
260
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: worktree '${worktree}' is registered to branch `
|
|
261
|
-
+ `${JSON.stringify(registeredBranch)}, but cleanup targets ${JSON.stringify(group.cleanupTarget.branch)}`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function assertLegacyCandidateEvidence(candidate, base, config, effectiveBranch, matchedContainers) {
|
|
267
|
-
const relative = path.relative(path.join(base, config.project), candidate);
|
|
268
|
-
const [container, identity] = relative.split(path.sep);
|
|
269
|
-
const [canonical, legacy] = containerNameCandidates(config, effectiveBranch);
|
|
270
|
-
if (!container || !identity || legacy === canonical || container !== legacy || matchedContainers.includes(container))
|
|
271
|
-
return;
|
|
272
|
-
const manifestPath = path.join(config.controlBase, config.project, container, identity, 'manifest.json');
|
|
273
|
-
if (!fs.existsSync(manifestPath)) {
|
|
274
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_EVIDENCE_MISSING: ${candidate}`);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function assertRemoved(target, label) {
|
|
278
|
-
if (fs.existsSync(target))
|
|
279
|
-
throw new Error(`${label} still exists after removal: ${target}`);
|
|
280
|
-
}
|
|
281
|
-
function removeEmptyManagedParent(base, directory) {
|
|
282
|
-
const parent = path.dirname(directory);
|
|
283
|
-
if (path.resolve(parent) === path.resolve(base))
|
|
284
|
-
return;
|
|
285
|
-
assertManagedPath(base, parent);
|
|
286
|
-
try {
|
|
287
|
-
fs.rmdirSync(parent);
|
|
288
|
-
}
|
|
289
|
-
catch (error) {
|
|
290
|
-
if (['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error.code ?? ''))
|
|
291
|
-
return;
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
assertRemoved(parent, 'Empty sandbox container directory');
|
|
295
|
-
}
|
|
296
|
-
async function removeExactSandboxContainer(engine, manifest, timeoutMs) {
|
|
297
|
-
const deadlineAt = Date.now() + timeoutMs;
|
|
298
|
-
const remaining = () => Math.max(1, deadlineAt - Date.now());
|
|
299
|
-
const inspect = () => inspectSandboxControlContainer(manifest, { timeoutMs: remaining() });
|
|
300
|
-
const before = await inspect();
|
|
301
|
-
if (before.state === 'unknown')
|
|
302
|
-
throw new Error(`SANDBOX_CONTROL_CONTAINER_UNKNOWN: ${before.reason}`);
|
|
303
|
-
if (before.state === 'absent')
|
|
304
|
-
return;
|
|
305
|
-
if (before.running && !runOkEngine(engine, 'docker', ['stop', '--timeout', '1', manifest.containerIdentity.id], { timeout: remaining() })) {
|
|
306
|
-
const afterStop = await inspect();
|
|
307
|
-
if (afterStop.state !== 'absent' && afterStop.state !== 'found') {
|
|
308
|
-
throw new Error(`SANDBOX_CONTROL_CONTAINER_UNKNOWN: ${afterStop.reason}`);
|
|
309
|
-
}
|
|
310
|
-
if (afterStop.state === 'found' && afterStop.running) {
|
|
311
|
-
throw new Error(`Failed to stop sandbox container: ${manifest.containerIdentity.id}`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
const afterStop = await inspect();
|
|
315
|
-
if (afterStop.state === 'unknown')
|
|
316
|
-
throw new Error(`SANDBOX_CONTROL_CONTAINER_UNKNOWN: ${afterStop.reason}`);
|
|
317
|
-
if (afterStop.state === 'found' && !runOkEngine(engine, 'docker', ['rm', manifest.containerIdentity.id], { timeout: remaining() })) {
|
|
318
|
-
const afterRemove = await inspect();
|
|
319
|
-
if (afterRemove.state !== 'absent') {
|
|
320
|
-
throw new Error(`Failed to remove sandbox container: ${manifest.containerIdentity.id}`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
async function removeProjectControlRoots(config, engine) {
|
|
325
|
-
const containers = new Set();
|
|
326
|
-
const projectRoot = path.join(config.controlBase, config.project);
|
|
327
|
-
if (!fs.existsSync(projectRoot))
|
|
328
|
-
return containers;
|
|
329
|
-
assertManagedPath(config.controlBase, projectRoot);
|
|
330
|
-
const projectStat = fs.lstatSync(projectRoot);
|
|
331
|
-
if (!projectStat.isDirectory() || projectStat.isSymbolicLink())
|
|
332
|
-
throw new Error('SANDBOX_CONTROL_CHANNEL_INVALID');
|
|
333
|
-
for (const container of fs.readdirSync(projectRoot, { withFileTypes: true })) {
|
|
334
|
-
if (!container.isDirectory() || container.isSymbolicLink())
|
|
335
|
-
continue;
|
|
336
|
-
const containerRoot = path.join(projectRoot, container.name);
|
|
337
|
-
for (const identity of fs.readdirSync(containerRoot, { withFileTypes: true })) {
|
|
338
|
-
if (!identity.isDirectory() || identity.isSymbolicLink())
|
|
339
|
-
continue;
|
|
340
|
-
const root = path.join(containerRoot, identity.name);
|
|
341
|
-
const manifestPath = path.join(root, 'manifest.json');
|
|
342
|
-
if (!fs.existsSync(manifestPath))
|
|
343
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_EVIDENCE_MISSING: ${root}`);
|
|
344
|
-
const manifest = readSandboxControlManifest(manifestPath);
|
|
345
|
-
containers.add(manifest.container);
|
|
346
|
-
await removeSandboxControlRoot(root, {
|
|
347
|
-
inspectContainer: (timeoutMs) => inspectSandboxControlContainer(manifest, { timeoutMs }),
|
|
348
|
-
removeContainer: (timeoutMs) => removeExactSandboxContainer(engine, manifest, timeoutMs)
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return containers;
|
|
353
|
-
}
|
|
354
|
-
function inspectionBlockers(inspections) {
|
|
355
|
-
return inspections.filter((inspection) => inspection.status !== 'clean');
|
|
356
|
-
}
|
|
357
|
-
function blockerMessage(blockers) {
|
|
358
|
-
return blockers.map((blocker) => {
|
|
359
|
-
if (blocker.status === 'failed')
|
|
360
|
-
return `${JSON.stringify(blocker.worktree)}: ${blocker.message}`;
|
|
361
|
-
return `${formatWorktreeSnapshot(blocker.snapshot)}\n Action: commit, stash, clean, or remove this sandbox interactively.`;
|
|
362
|
-
}).join('\n');
|
|
363
|
-
}
|
|
364
|
-
function cleanPermits(inspections) {
|
|
365
|
-
const permits = new Map();
|
|
366
|
-
for (const inspection of inspections) {
|
|
367
|
-
if (inspection.status === 'clean')
|
|
368
|
-
permits.set(inspection.snapshot.worktree, createCleanPermit(inspection.snapshot));
|
|
369
|
-
}
|
|
370
|
-
return permits;
|
|
371
|
-
}
|
|
372
|
-
async function authorizeWorktrees(worktrees, { allowDirtyDiscard, assumeYes }, { interactive = Boolean(process.stdin.isTTY), confirm = p.confirm, isCancel = p.isCancel, recovery = new Map() } = {}) {
|
|
373
|
-
const inspections = worktrees.map((worktree) => {
|
|
374
|
-
const inspection = inspectWorktrees([worktree])[0];
|
|
375
|
-
const context = recovery.get(path.resolve(worktree));
|
|
376
|
-
return inspection.status === 'failed' && context
|
|
377
|
-
? inspectRecoveredWorktree(worktree, context)
|
|
378
|
-
: inspection;
|
|
379
|
-
});
|
|
380
|
-
const failures = inspections.filter((inspection) => inspection.status === 'failed');
|
|
381
|
-
if (failures.length > 0)
|
|
382
|
-
throw new Error(`Unable to inspect worktree(s):\n${blockerMessage(failures)}`);
|
|
383
|
-
const permits = cleanPermits(inspections);
|
|
384
|
-
for (const inspection of inspections) {
|
|
385
|
-
if (inspection.status !== 'dirty')
|
|
386
|
-
continue;
|
|
387
|
-
if (!allowDirtyDiscard || assumeYes || !interactive) {
|
|
388
|
-
throw new Error(`Refusing to remove dirty worktree(s):\n${blockerMessage([inspection])}`);
|
|
389
|
-
}
|
|
390
|
-
p.log.warn(formatWorktreeSnapshot(inspection.snapshot));
|
|
391
|
-
const confirmed = await confirm({
|
|
392
|
-
message: 'Discard these exact uncommitted changes?',
|
|
393
|
-
initialValue: false
|
|
394
|
-
});
|
|
395
|
-
if (isCancel(confirmed) || !confirmed)
|
|
396
|
-
throw new Error('Dirty worktree removal cancelled; nothing was deleted');
|
|
397
|
-
permits.set(inspection.snapshot.worktree, createDiscardPermit(inspection.snapshot));
|
|
398
|
-
}
|
|
399
|
-
return permits;
|
|
400
|
-
}
|
|
401
|
-
async function rmOne(config, tools, branch, options = {}) {
|
|
402
|
-
const target = options.target ?? resolveRmTarget(config, tools, options.cleanupTarget ?? resolveSandboxCleanupTarget(branch, config.repoRoot));
|
|
403
|
-
const { effectiveBranch, engine, matchedContainers, existingWorktrees, toolCandidates } = target;
|
|
404
|
-
const { workspace, controlRoots, workspaceViewRoots } = target;
|
|
405
|
-
preflightRmTarget(config, target);
|
|
406
|
-
const confirm = options.prompt?.confirm ?? p.confirm;
|
|
407
|
-
const isCancel = options.prompt?.isCancel ?? p.isCancel;
|
|
408
|
-
if (!options.quiet) {
|
|
409
|
-
p.intro(pc.cyan(`Removing sandbox for ${branch}`));
|
|
410
|
-
}
|
|
411
|
-
const recovery = options.permits
|
|
412
|
-
? new Map()
|
|
413
|
-
: recoveryContexts(config, target, existingWorktrees);
|
|
414
|
-
const permits = options.permits
|
|
415
|
-
? new Map(options.permits)
|
|
416
|
-
: await authorizeWorktrees(existingWorktrees, {
|
|
417
|
-
allowDirtyDiscard: options.allowDirtyDiscard ?? true,
|
|
418
|
-
assumeYes: Boolean(options.assumeYes)
|
|
419
|
-
}, {
|
|
420
|
-
...options.prompt,
|
|
421
|
-
interactive: options.interactive ?? Boolean(process.stdin.isTTY),
|
|
422
|
-
recovery
|
|
423
|
-
});
|
|
424
|
-
for (const worktree of existingWorktrees) {
|
|
425
|
-
const permit = permits.get(path.resolve(worktree));
|
|
426
|
-
if (!permit)
|
|
427
|
-
throw new Error(`Missing worktree removal permit: ${worktree}`);
|
|
428
|
-
verifyWorktreePermit(permit);
|
|
429
|
-
}
|
|
430
|
-
const shouldRemoveWorktree = existingWorktrees.length === 0
|
|
431
|
-
? false
|
|
432
|
-
: options.assumeYes
|
|
433
|
-
? true
|
|
434
|
-
: await confirm({
|
|
435
|
-
message: `Remove worktree(s): ${existingWorktrees.join(', ')}?`,
|
|
436
|
-
initialValue: true
|
|
437
|
-
});
|
|
438
|
-
if (isCancel(shouldRemoveWorktree)) {
|
|
439
|
-
p.outro('Cancelled');
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
preflightRmTarget(config, target);
|
|
443
|
-
const coordinatedContainers = new Set();
|
|
444
|
-
for (const root of controlRoots.filter((candidate) => fs.existsSync(candidate))) {
|
|
445
|
-
assertLegacyCandidateEvidence(root, config.controlBase, config, effectiveBranch, matchedContainers);
|
|
446
|
-
assertControlRootMatchesTarget(root, effectiveBranch, workspace);
|
|
447
|
-
const manifestPath = path.join(root, 'manifest.json');
|
|
448
|
-
if (!fs.existsSync(manifestPath))
|
|
449
|
-
continue;
|
|
450
|
-
const manifest = readSandboxControlManifest(manifestPath);
|
|
451
|
-
coordinatedContainers.add(manifest.container);
|
|
452
|
-
await removeSandboxControlRoot(root, {
|
|
453
|
-
inspectContainer: (timeoutMs) => inspectSandboxControlContainer(manifest, { timeoutMs }),
|
|
454
|
-
removeContainer: (timeoutMs) => removeExactSandboxContainer(engine, manifest, timeoutMs)
|
|
455
|
-
});
|
|
456
|
-
removeEmptyManagedParent(path.join(config.controlBase, config.project), root);
|
|
457
|
-
}
|
|
458
|
-
const uncoordinatedContainers = matchedContainers.filter((name) => !coordinatedContainers.has(name));
|
|
459
|
-
if (uncoordinatedContainers.length > 0) {
|
|
460
|
-
if (workspace.mode === 'task-bound') {
|
|
461
|
-
throw new Error(`SANDBOX_CONTROL_TARGET_EVIDENCE_MISSING: container '${uncoordinatedContainers[0]}'`);
|
|
462
|
-
}
|
|
463
|
-
const spinner = p.spinner();
|
|
464
|
-
spinner.start(`Stopping container(s): ${uncoordinatedContainers.join(', ')}`);
|
|
465
|
-
for (const name of uncoordinatedContainers) {
|
|
466
|
-
if (!runOkEngine(engine, 'docker', ['stop', name]))
|
|
467
|
-
throw new Error(`Failed to stop sandbox container: ${name}`);
|
|
468
|
-
if (!runOkEngine(engine, 'docker', ['rm', name]))
|
|
469
|
-
throw new Error(`Failed to remove sandbox container: ${name}`);
|
|
470
|
-
}
|
|
471
|
-
const remaining = runEngine(engine, 'docker', ['ps', '-a', '--format', '{{.Names}}']).split('\n').filter(Boolean);
|
|
472
|
-
const leftovers = uncoordinatedContainers.filter((name) => remaining.includes(name));
|
|
473
|
-
if (leftovers.length > 0)
|
|
474
|
-
throw new Error(`Sandbox container(s) still exist after removal: ${leftovers.join(', ')}`);
|
|
475
|
-
spinner.stop(pc.green(`Removed container(s): ${uncoordinatedContainers.join(', ')}`));
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
p.log.warn(`No sandbox container found for '${branch}'`);
|
|
479
|
-
}
|
|
480
|
-
for (const [roots, base, label] of [
|
|
481
|
-
[workspaceViewRoots, path.join(config.workspaceViewBase, config.project), 'Workspace view'],
|
|
482
|
-
[controlRoots, path.join(config.controlBase, config.project), 'Control channel']
|
|
483
|
-
]) {
|
|
484
|
-
for (const directory of roots.filter((candidate) => fs.existsSync(candidate))) {
|
|
485
|
-
assertLegacyCandidateEvidence(directory, base === path.join(config.controlBase, config.project)
|
|
486
|
-
? config.controlBase : config.workspaceViewBase, config, effectiveBranch, matchedContainers);
|
|
487
|
-
removeManagedDir(base, directory);
|
|
488
|
-
assertRemoved(directory, label);
|
|
489
|
-
removeEmptyManagedParent(base, directory);
|
|
490
|
-
if (!options.quiet)
|
|
491
|
-
p.log.success(`${label} removed: ${directory}`);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
if (shouldRemoveWorktree) {
|
|
495
|
-
for (const worktree of existingWorktrees) {
|
|
496
|
-
const permit = permits.get(path.resolve(worktree));
|
|
497
|
-
if (!permit)
|
|
498
|
-
throw new Error(`Missing worktree removal permit: ${worktree}`);
|
|
499
|
-
removeWorktreeDir(config.repoRoot, config.worktreeBase, worktree, permit, {
|
|
500
|
-
allowRegisteredPathFallback: engine === ENGINES.WSL2
|
|
501
|
-
});
|
|
502
|
-
assertRemoved(worktree, 'Worktree');
|
|
503
|
-
const registered = runSafe('git', ['-C', config.repoRoot, 'worktree', 'list', '--porcelain'])
|
|
504
|
-
.split('\n').filter((line) => line.startsWith('worktree ')).map((line) => path.resolve(line.slice(9)));
|
|
505
|
-
if (registered.includes(path.resolve(worktree)))
|
|
506
|
-
throw new Error(`Worktree is still registered after removal: ${worktree}`);
|
|
507
|
-
}
|
|
508
|
-
const shouldDeleteBranch = options.assumeYes
|
|
509
|
-
? true
|
|
510
|
-
: await confirm({
|
|
511
|
-
message: `Also delete local branch '${effectiveBranch}'?`,
|
|
512
|
-
initialValue: true
|
|
513
|
-
});
|
|
514
|
-
if (!isCancel(shouldDeleteBranch) && shouldDeleteBranch) {
|
|
515
|
-
if (!runOk('git', ['-C', config.repoRoot, 'branch', '-D', effectiveBranch])) {
|
|
516
|
-
throw new Error(`Local branch '${effectiveBranch}' was not deleted`);
|
|
517
|
-
}
|
|
518
|
-
if (runOk('git', ['-C', config.repoRoot, 'show-ref', '--verify', `refs/heads/${effectiveBranch}`])) {
|
|
519
|
-
throw new Error(`Local branch '${effectiveBranch}' still exists after removal`);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
for (const { tool, candidates } of toolCandidates) {
|
|
524
|
-
for (const dir of candidates.filter((candidate) => fs.existsSync(candidate))) {
|
|
525
|
-
removeManagedDir(tool.sandboxBase, dir);
|
|
526
|
-
assertRemoved(dir, `${tool.name} state`);
|
|
527
|
-
p.log.success(`${tool.name} state removed: ${dir}`);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
for (const dir of shellConfigDirCandidates(config, effectiveBranch).filter((candidate) => fs.existsSync(candidate))) {
|
|
531
|
-
removeManagedDir(config.shellConfigBase, dir);
|
|
532
|
-
assertRemoved(dir, 'Shell config');
|
|
533
|
-
p.log.success(`Shell config removed: ${dir}`);
|
|
534
|
-
}
|
|
535
|
-
const shareBranch = shareBranchDir(config, effectiveBranch);
|
|
536
|
-
if (fs.existsSync(shareBranch)) {
|
|
537
|
-
const shouldRemoveShare = options.assumeYes
|
|
538
|
-
? true
|
|
539
|
-
: await confirm({
|
|
540
|
-
message: `Remove share dir for branch '${effectiveBranch}' (${shareBranch})?`,
|
|
541
|
-
initialValue: true
|
|
542
|
-
});
|
|
543
|
-
if (!isCancel(shouldRemoveShare) && shouldRemoveShare) {
|
|
544
|
-
removeManagedDir(config.shareBase, shareBranch);
|
|
545
|
-
assertRemoved(shareBranch, 'Share dir');
|
|
546
|
-
p.log.success(`Share dir removed: ${shareBranch}`);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
if (!options.quiet) {
|
|
550
|
-
p.outro(pc.green('Sandbox removed'));
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
async function rmPurge(config, tools, prompt = {}) {
|
|
554
|
-
const engine = detectEngine(config);
|
|
555
|
-
const confirm = prompt.confirm ?? p.confirm;
|
|
556
|
-
const isCancel = prompt.isCancel ?? p.isCancel;
|
|
557
|
-
p.intro(pc.cyan(`Removing all sandboxes for ${config.project}`));
|
|
558
|
-
const worktrees = fs.existsSync(config.worktreeBase)
|
|
559
|
-
? fs.readdirSync(config.worktreeBase)
|
|
560
|
-
.map((entry) => path.join(config.worktreeBase, entry))
|
|
561
|
-
.filter((entry) => {
|
|
562
|
-
try {
|
|
563
|
-
return fs.statSync(entry).isDirectory();
|
|
564
|
-
}
|
|
565
|
-
catch {
|
|
566
|
-
return false;
|
|
567
|
-
}
|
|
568
|
-
})
|
|
569
|
-
: [];
|
|
570
|
-
const inspections = inspectWorktrees(worktrees);
|
|
571
|
-
const blockers = inspectionBlockers(inspections);
|
|
572
|
-
if (blockers.length > 0) {
|
|
573
|
-
throw new Error(`Refusing to purge because worktree preflight found blocker(s):\n${blockerMessage(blockers)}`);
|
|
574
|
-
}
|
|
575
|
-
const permits = cleanPermits(inspections);
|
|
576
|
-
const coordinatedContainers = await removeProjectControlRoots(config, engine);
|
|
577
|
-
const containers = runEngine(engine, 'docker', [
|
|
578
|
-
'ps',
|
|
579
|
-
'-a',
|
|
580
|
-
'--filter',
|
|
581
|
-
`label=${sandboxLabel(config)}`,
|
|
582
|
-
'--format',
|
|
583
|
-
'{{.Names}}'
|
|
584
|
-
]);
|
|
585
|
-
const uncoordinatedContainers = containers.split('\n').filter((name) => name && !coordinatedContainers.has(name));
|
|
586
|
-
if (uncoordinatedContainers.length > 0) {
|
|
587
|
-
const spinner = p.spinner();
|
|
588
|
-
spinner.start('Stopping project sandbox containers...');
|
|
589
|
-
for (const name of uncoordinatedContainers) {
|
|
590
|
-
if (!runOkEngine(engine, 'docker', ['stop', name]))
|
|
591
|
-
throw new Error(`Failed to stop sandbox container: ${name}`);
|
|
592
|
-
if (!runOkEngine(engine, 'docker', ['rm', name]))
|
|
593
|
-
throw new Error(`Failed to remove sandbox container: ${name}`);
|
|
594
|
-
}
|
|
595
|
-
const remaining = runEngine(engine, 'docker', [
|
|
596
|
-
'ps', '-a', '--filter', `label=${sandboxLabel(config)}`, '--format', '{{.Names}}'
|
|
597
|
-
]);
|
|
598
|
-
const leftovers = remaining.split('\n').filter((name) => name && !coordinatedContainers.has(name));
|
|
599
|
-
if (leftovers.length > 0)
|
|
600
|
-
throw new Error(`Project sandbox container(s) still exist after removal: ${leftovers.join(', ')}`);
|
|
601
|
-
spinner.stop(pc.green('Project sandbox containers removed'));
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
p.log.warn('No project sandbox containers found');
|
|
605
|
-
}
|
|
606
|
-
if (worktrees.length > 0) {
|
|
607
|
-
const shouldRemoveWorktrees = await confirm({
|
|
608
|
-
message: `Remove all worktrees in ${config.worktreeBase}?`,
|
|
609
|
-
initialValue: true
|
|
610
|
-
});
|
|
611
|
-
if (!isCancel(shouldRemoveWorktrees) && shouldRemoveWorktrees) {
|
|
612
|
-
for (const dir of worktrees) {
|
|
613
|
-
const permit = permits.get(path.resolve(dir));
|
|
614
|
-
if (!permit)
|
|
615
|
-
throw new Error(`Missing worktree removal permit: ${dir}`);
|
|
616
|
-
removeWorktreeDir(config.repoRoot, config.worktreeBase, dir, permit, {
|
|
617
|
-
allowRegisteredPathFallback: engine === ENGINES.WSL2
|
|
618
|
-
});
|
|
619
|
-
assertRemoved(dir, 'Worktree');
|
|
620
|
-
}
|
|
621
|
-
runSafe('git', ['-C', config.repoRoot, 'worktree', 'prune']);
|
|
622
|
-
const registered = new Set(runSafe('git', ['-C', config.repoRoot, 'worktree', 'list', '--porcelain'])
|
|
623
|
-
.split('\n').filter((line) => line.startsWith('worktree ')).map((line) => path.resolve(line.slice(9))));
|
|
624
|
-
const leftovers = worktrees.filter((dir) => registered.has(path.resolve(dir)));
|
|
625
|
-
if (leftovers.length > 0)
|
|
626
|
-
throw new Error(`Worktree(s) still registered after removal: ${leftovers.join(', ')}`);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
for (const dir of projectToolDirs(config, tools)) {
|
|
630
|
-
if (fs.existsSync(dir)) {
|
|
631
|
-
removeManagedDir(path.dirname(dir), dir);
|
|
632
|
-
assertRemoved(dir, 'Tool state');
|
|
633
|
-
p.log.success(`Removed tool state: ${dir}`);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
if (fs.existsSync(config.shellConfigBase) && fs.readdirSync(config.shellConfigBase).length > 0) {
|
|
637
|
-
const shouldRemoveShellConfigs = await confirm({
|
|
638
|
-
message: `Remove all shell config dirs in ${config.shellConfigBase}?`,
|
|
639
|
-
initialValue: true
|
|
640
|
-
});
|
|
641
|
-
if (!isCancel(shouldRemoveShellConfigs) && shouldRemoveShellConfigs) {
|
|
642
|
-
for (const entry of fs.readdirSync(config.shellConfigBase)) {
|
|
643
|
-
const dir = path.join(config.shellConfigBase, entry);
|
|
644
|
-
removeManagedDir(config.shellConfigBase, dir);
|
|
645
|
-
assertRemoved(dir, 'Shell config');
|
|
646
|
-
}
|
|
647
|
-
p.log.success(`Project shell config dirs removed: ${config.shellConfigBase}`);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
if (fs.existsSync(config.shareBase) && fs.readdirSync(config.shareBase).length > 0) {
|
|
651
|
-
const shouldRemoveAllShares = await confirm({
|
|
652
|
-
message: `Remove all share dirs for project (${config.shareBase})?`,
|
|
653
|
-
initialValue: true
|
|
654
|
-
});
|
|
655
|
-
if (!isCancel(shouldRemoveAllShares) && shouldRemoveAllShares) {
|
|
656
|
-
removeManagedDir(path.dirname(config.shareBase), config.shareBase);
|
|
657
|
-
assertRemoved(config.shareBase, 'Project share dir');
|
|
658
|
-
p.log.success(`Project share dirs removed: ${config.shareBase}`);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
for (const [base, label] of [
|
|
662
|
-
[config.workspaceViewBase, 'workspace views'],
|
|
663
|
-
[config.controlBase, 'control channels']
|
|
664
|
-
]) {
|
|
665
|
-
const projectDir = path.join(base, config.project);
|
|
666
|
-
if (fs.existsSync(projectDir)) {
|
|
667
|
-
removeManagedDir(base, projectDir);
|
|
668
|
-
assertRemoved(projectDir, `Project ${label}`);
|
|
669
|
-
p.log.success(`Removed project ${label}: ${projectDir}`);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
const shouldRemoveImage = await confirm({
|
|
673
|
-
message: `Remove image ${config.imageName}?`,
|
|
674
|
-
initialValue: false
|
|
675
|
-
});
|
|
676
|
-
if (!isCancel(shouldRemoveImage) && shouldRemoveImage) {
|
|
677
|
-
runSafeEngine(engine, 'docker', ['rmi', config.imageName]);
|
|
678
|
-
}
|
|
679
|
-
pruneSandboxDanglingImages(config, engine);
|
|
680
|
-
if (isManagedEngine(engine)) {
|
|
681
|
-
if (engine === ENGINES.WSL2) {
|
|
682
|
-
p.log.warn('Windows uses Docker Desktop with WSL2. Stop it from Docker Desktop or run "wsl --shutdown" manually.');
|
|
683
|
-
p.outro(pc.green('All project sandboxes removed'));
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
const name = engineDisplayName(engine);
|
|
687
|
-
const shouldStopVm = await confirm({
|
|
688
|
-
message: `Stop ${name} VM?`,
|
|
689
|
-
initialValue: false
|
|
690
|
-
});
|
|
691
|
-
if (!isCancel(shouldStopVm) && shouldStopVm) {
|
|
692
|
-
stopManagedVm(config);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
p.outro(pc.green('All project sandboxes removed'));
|
|
696
|
-
}
|
|
697
|
-
async function rmUnbound(config, tools, options) {
|
|
698
|
-
const engine = detectEngine(config);
|
|
699
|
-
const { running, nonRunning } = fetchSandboxRows(engine, sandboxLabel(config), sandboxBranchLabel(config), { mode: sandboxWorkspaceModeLabel(config), taskId: sandboxTaskIdLabel(config) });
|
|
700
|
-
const rows = [...running, ...nonRunning];
|
|
701
|
-
p.intro(pc.cyan(`Removing sandboxes not bound to an active task for ${config.project}`));
|
|
702
|
-
if (rows.length === 0) {
|
|
703
|
-
p.outro('No removable sandboxes: every container is bound to an active task (or none exist)');
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
const candidates = rows.map((row) => {
|
|
707
|
-
if (!row.branch || !row.workspaceMode || row.workspaceMode === 'legacy-invalid') {
|
|
708
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: container '${row.name}' has incomplete workspace identity`);
|
|
709
|
-
}
|
|
710
|
-
if (row.workspaceMode === 'task-bound') {
|
|
711
|
-
if (!row.taskId) {
|
|
712
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: container '${row.name}' has no task id`);
|
|
713
|
-
}
|
|
714
|
-
const cleanupTarget = resolveSandboxCleanupTarget(row.taskId, config.repoRoot, { allowProtected: true });
|
|
715
|
-
if (cleanupTarget.branch !== row.branch
|
|
716
|
-
|| cleanupTarget.workspace.mode !== 'task-bound'
|
|
717
|
-
|| cleanupTarget.workspace.taskId !== row.taskId) {
|
|
718
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: container '${row.name}' task identity conflicts with task.md`);
|
|
719
|
-
}
|
|
720
|
-
return { row, cleanupTarget };
|
|
721
|
-
}
|
|
722
|
-
return {
|
|
723
|
-
row,
|
|
724
|
-
cleanupTarget: {
|
|
725
|
-
requestedRef: row.branch,
|
|
726
|
-
branch: row.branch,
|
|
727
|
-
workspace: { mode: 'branch-only' },
|
|
728
|
-
taskState: 'branch-only'
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
});
|
|
732
|
-
const branchIdentities = new Map();
|
|
733
|
-
const groupedCandidates = new Map();
|
|
734
|
-
for (const candidate of candidates) {
|
|
735
|
-
const identity = candidate.cleanupTarget.workspace.mode === 'task-bound'
|
|
736
|
-
? `task-bound:${candidate.cleanupTarget.workspace.taskId}`
|
|
737
|
-
: 'branch-only';
|
|
738
|
-
const existingIdentity = branchIdentities.get(candidate.cleanupTarget.branch);
|
|
739
|
-
if (existingIdentity && existingIdentity !== identity) {
|
|
740
|
-
throw new Error(`SANDBOX_CLEANUP_BATCH_PREFLIGHT_FAILED: branch '${candidate.cleanupTarget.branch}' has conflicting workspace identities`);
|
|
741
|
-
}
|
|
742
|
-
branchIdentities.set(candidate.cleanupTarget.branch, identity);
|
|
743
|
-
const groupKey = `${candidate.cleanupTarget.branch}\0${identity}`;
|
|
744
|
-
const group = groupedCandidates.get(groupKey) ?? [];
|
|
745
|
-
group.push(candidate);
|
|
746
|
-
groupedCandidates.set(groupKey, group);
|
|
747
|
-
}
|
|
748
|
-
const groups = [...groupedCandidates.values()].map((groupCandidates) => {
|
|
749
|
-
const cleanupTarget = groupCandidates[0].cleanupTarget;
|
|
750
|
-
const target = resolveRmTarget(config, tools, cleanupTarget, {
|
|
751
|
-
discoveredContainers: groupCandidates.map(({ row }) => row.name)
|
|
752
|
-
});
|
|
753
|
-
preflightRmTarget(config, target);
|
|
754
|
-
return { candidates: groupCandidates, cleanupTarget, target };
|
|
755
|
-
});
|
|
756
|
-
assertCleanupGroupPathsDoNotOverlap(groups);
|
|
757
|
-
const removableGroups = groups.filter(({ cleanupTarget }) => cleanupTarget.taskState === 'completed' || cleanupTarget.taskState === 'branch-only');
|
|
758
|
-
const removable = removableGroups.flatMap(({ candidates: groupCandidates }) => groupCandidates);
|
|
759
|
-
for (const { candidates: groupCandidates, cleanupTarget } of groups.filter(({ cleanupTarget }) => cleanupTarget.taskState !== 'completed' && cleanupTarget.taskState !== 'branch-only')) {
|
|
760
|
-
for (const { row } of groupCandidates) {
|
|
761
|
-
p.log.message(`Skipped protected sandbox ${row.name} (${cleanupTarget.taskState})`);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
if (removableGroups.length === 0) {
|
|
765
|
-
p.outro('No removable sandboxes: every container is bound to a protected task (or none exist)');
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
const inspections = inspectWorktrees(removableGroups.flatMap(({ target }) => target.existingWorktrees));
|
|
769
|
-
assertWorktreeBranchesMatchGroups(removableGroups, inspections);
|
|
770
|
-
const blockers = inspectionBlockers(inspections);
|
|
771
|
-
const permits = cleanPermits(inspections);
|
|
772
|
-
for (const { row } of removable) {
|
|
773
|
-
p.log.message(`${row.name} ${row.branch}`);
|
|
774
|
-
}
|
|
775
|
-
if (blockers.length > 0)
|
|
776
|
-
p.log.error(blockerMessage(blockers));
|
|
777
|
-
if (options.dryRun) {
|
|
778
|
-
p.outro(`Dry run: ${removable.length} sandbox(es) inspected, nothing deleted`);
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
if (blockers.length > 0) {
|
|
782
|
-
throw new Error(`Refusing batch removal because worktree preflight found blocker(s):\n${blockerMessage(blockers)}`);
|
|
783
|
-
}
|
|
784
|
-
if (!options.assumeYes && !process.stdin.isTTY) {
|
|
785
|
-
throw new Error('Refusing to remove sandboxes without confirmation in a non-interactive shell; pass --yes to proceed.');
|
|
786
|
-
}
|
|
787
|
-
const failures = [];
|
|
788
|
-
let failedRows = 0;
|
|
789
|
-
for (const group of removableGroups) {
|
|
790
|
-
try {
|
|
791
|
-
await rmOne(config, tools, group.cleanupTarget.branch, {
|
|
792
|
-
assumeYes: options.assumeYes,
|
|
793
|
-
quiet: true,
|
|
794
|
-
target: group.target,
|
|
795
|
-
cleanupTarget: group.cleanupTarget,
|
|
796
|
-
permits,
|
|
797
|
-
allowDirtyDiscard: false
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
catch (error) {
|
|
801
|
-
failedRows += group.candidates.length;
|
|
802
|
-
failures.push({ branch: group.cleanupTarget.branch, message: error instanceof Error ? error.message : String(error) });
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
if (failures.length > 0) {
|
|
806
|
-
for (const failure of failures) {
|
|
807
|
-
p.log.error(`Failed to remove '${failure.branch}': ${failure.message}`);
|
|
808
|
-
}
|
|
809
|
-
throw new Error(`Removed ${removable.length - failedRows}/${removable.length} sandbox(es); ${failures.length} failed`);
|
|
810
|
-
}
|
|
811
|
-
p.outro(pc.green(`Removed ${removable.length} sandbox(es)`));
|
|
812
|
-
}
|
|
813
10
|
export async function rm(args) {
|
|
814
11
|
const { values, positionals } = parseArgs({
|
|
815
12
|
args,
|
|
@@ -859,5 +56,4 @@ export async function rm(args) {
|
|
|
859
56
|
const cleanupTarget = resolveSandboxCleanupTarget(positionals[0] ?? '', config.repoRoot);
|
|
860
57
|
await rmOne(config, tools, cleanupTarget.branch, { cleanupTarget });
|
|
861
58
|
}
|
|
862
|
-
export { authorizeWorktrees, rmOne, rmPurge };
|
|
863
59
|
//# sourceMappingURL=rm.js.map
|