@fitlab-ai/agent-infra 0.9.9 → 0.9.11
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 +13 -3
- package/README.zh-CN.md +13 -3
- package/bin/cli.ts +17 -4
- package/dist/bin/cli.js +19 -4
- package/dist/bin/internal-cli.js +55 -4
- package/dist/lib/agent-client.js +0 -1
- package/dist/lib/agent-clients/adapters/codex-lifecycle/build-identity.js +17 -10
- package/dist/lib/agent-clients/adapters/codex-lifecycle/controller-context.js +11 -31
- package/dist/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.js +15 -33
- package/dist/lib/agent-clients/adapters/codex-sandbox.js +72 -11
- package/dist/lib/agent-clients/adapters/index.js +3 -1
- package/dist/lib/agent-clients/adapters/opencode-sandbox.js +0 -4
- package/dist/lib/agent-clients/adapters/traecli.js +65 -0
- package/dist/lib/agent-clients/config.js +14 -99
- package/dist/lib/agent-clients/reconcile.js +1 -11
- package/dist/lib/agent-clients/schema.js +5 -4
- package/dist/lib/agent-clients/tokens.js +7 -17
- package/dist/lib/agent-clients/types.js +2 -1
- package/dist/lib/decide.js +14 -30
- package/dist/lib/defaults.json +9 -0
- package/dist/lib/init.js +2 -2
- package/dist/lib/internal/codex-lifecycle.js +2 -2
- package/dist/lib/internal/codex-sandbox-controller.js +4 -3
- package/dist/lib/internal/release-workflow.js +0 -1
- package/dist/lib/internal/sandbox-control.js +2 -2
- package/dist/lib/internal/task-finalization.js +19 -9
- package/dist/lib/internal/task-ledger.js +8 -2
- package/dist/lib/internal/task-lifecycle.js +17 -93
- package/dist/lib/internal/task-orchestration.js +30 -216
- package/dist/lib/{task/commands/validate.js → internal/task-validate.js} +77 -43
- package/dist/lib/merge.js +205 -103
- package/dist/lib/process-data/normalize.js +2 -9
- package/dist/lib/run/host.js +46 -16
- package/dist/lib/run/tui.js +5 -2
- package/dist/lib/sandbox/agent-client-reconciler.js +4 -12
- package/dist/lib/sandbox/commands/create.js +3 -3
- package/dist/lib/sandbox/commands/enter.js +18 -4
- package/dist/lib/sandbox/config.js +3 -12
- package/dist/lib/sandbox/control/controller-registration.js +4 -2
- package/dist/lib/sandbox/control/executor.js +135 -40
- package/dist/lib/sandbox/control/lifecycle.js +29 -20
- package/dist/lib/sandbox/control/server.js +18 -16
- package/dist/lib/sandbox/mounts.js +3 -2
- package/dist/lib/sandbox/recovery.js +123 -22
- package/dist/lib/sandbox/workspace-identity.js +14 -0
- package/dist/lib/sandbox/workspace-view.js +8 -9
- package/dist/lib/self-update.js +278 -0
- package/dist/lib/server/protocol.js +5 -5
- package/dist/lib/task/activity-log.js +4 -1
- package/dist/lib/task/artifact-lifecycle.js +4 -2
- package/dist/lib/task/codex-orchestration.js +32 -35
- package/dist/lib/task/command-options.js +1 -3
- package/dist/lib/task/commands/cat.js +0 -5
- package/dist/lib/task/commands/decisions.js +76 -92
- package/dist/lib/task/commands/files.js +6 -6
- package/dist/lib/task/commands/grep.js +25 -61
- package/dist/lib/task/commands/issue-body.js +6 -6
- package/dist/lib/task/commands/log.js +25 -10
- package/dist/lib/task/commands/show.js +5 -6
- package/dist/lib/task/commands/status.js +8 -8
- package/dist/lib/task/commit-operation.js +21 -25
- package/dist/lib/task/commit-policy.js +1 -1
- package/dist/lib/task/control-authority.js +431 -0
- package/dist/lib/task/create.js +6 -1
- package/dist/lib/task/current-contract.js +35 -0
- package/dist/lib/task/decision-details.js +263 -0
- package/dist/lib/task/decision-intents.js +5 -2
- package/dist/lib/task/delegation-receipts.js +8 -7
- package/dist/lib/task/events.js +11 -5
- package/dist/lib/task/finalization.js +72 -46
- package/dist/lib/task/index.js +19 -29
- package/dist/lib/task/ledger-intents.js +8 -9
- package/dist/lib/task/ledger.js +13 -6
- package/dist/lib/task/lifecycle.js +16 -0
- package/dist/lib/task/orchestration.js +51 -14
- package/dist/lib/task/review-artifacts.js +31 -12
- package/dist/lib/task/review-finalization.js +19 -6
- package/dist/lib/task/verification-engine.js +38 -18
- package/dist/lib/task/verification-review.js +1 -1
- package/dist/lib/task/workspace-snapshot.js +5 -11
- package/dist/lib/task/write.js +11 -1
- package/dist/lib/update.js +6 -37
- package/dist/lib/version.js +5 -1
- package/dist/lifecycle-build-manifest.json +3 -3
- package/lib/agent-client.ts +0 -1
- package/lib/agent-clients/adapters/codex-lifecycle/build-identity.ts +25 -10
- package/lib/agent-clients/adapters/codex-lifecycle/controller-context.ts +16 -33
- package/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.ts +16 -35
- package/lib/agent-clients/adapters/codex-sandbox.ts +89 -14
- package/lib/agent-clients/adapters/index.ts +3 -1
- package/lib/agent-clients/adapters/opencode-sandbox.ts +0 -5
- package/lib/agent-clients/adapters/traecli.ts +66 -0
- package/lib/agent-clients/config.ts +14 -144
- package/lib/agent-clients/reconcile.ts +1 -12
- package/lib/agent-clients/schema.ts +5 -4
- package/lib/agent-clients/tokens.ts +7 -20
- package/lib/agent-clients/types.ts +2 -1
- package/lib/decide.ts +12 -22
- package/lib/defaults.json +9 -0
- package/lib/init.ts +2 -2
- package/lib/internal/codex-lifecycle.ts +2 -2
- package/lib/internal/codex-sandbox-controller.ts +4 -3
- package/lib/internal/release-workflow.ts +0 -1
- package/lib/internal/sandbox-control.ts +2 -2
- package/lib/internal/task-finalization.ts +27 -13
- package/lib/internal/task-ledger.ts +8 -2
- package/lib/internal/task-lifecycle.ts +33 -76
- package/lib/internal/task-orchestration.ts +33 -190
- package/lib/{task/commands/validate.ts → internal/task-validate.ts} +77 -41
- package/lib/merge.ts +236 -120
- package/lib/process-data/normalize.ts +2 -8
- package/lib/run/host.ts +63 -14
- package/lib/run/tui.ts +5 -3
- package/lib/sandbox/agent-client-reconciler.ts +5 -15
- package/lib/sandbox/commands/create.ts +4 -4
- package/lib/sandbox/commands/enter.ts +24 -4
- package/lib/sandbox/config.ts +2 -14
- package/lib/sandbox/control/container-identity.ts +2 -2
- package/lib/sandbox/control/controller-registration.ts +8 -3
- package/lib/sandbox/control/executor.ts +156 -53
- package/lib/sandbox/control/lifecycle.ts +34 -28
- package/lib/sandbox/control/protocol.ts +1 -3
- package/lib/sandbox/control/server.ts +15 -12
- package/lib/sandbox/control/state.ts +7 -7
- package/lib/sandbox/mounts.ts +4 -3
- package/lib/sandbox/recovery.ts +162 -34
- package/lib/sandbox/tools.ts +1 -1
- package/lib/sandbox/workspace-identity.ts +28 -0
- package/lib/sandbox/workspace-view.ts +14 -10
- package/lib/self-update.ts +341 -0
- package/lib/server/protocol.ts +5 -5
- package/lib/task/activity-log.ts +6 -1
- package/lib/task/artifact-lifecycle.ts +5 -3
- package/lib/task/codex-orchestration.ts +40 -45
- package/lib/task/command-options.ts +1 -2
- package/lib/task/commands/cat.ts +0 -4
- package/lib/task/commands/decisions.ts +80 -75
- package/lib/task/commands/files.ts +6 -6
- package/lib/task/commands/grep.ts +23 -51
- package/lib/task/commands/issue-body.ts +6 -6
- package/lib/task/commands/log.ts +22 -10
- package/lib/task/commands/show.ts +5 -6
- package/lib/task/commands/status.ts +8 -8
- package/lib/task/commit-operation.ts +25 -30
- package/lib/task/commit-policy.ts +1 -2
- package/lib/task/control-authority.ts +563 -0
- package/lib/task/create.ts +6 -1
- package/lib/task/current-contract.ts +49 -0
- package/lib/task/decision-details.ts +340 -0
- package/lib/task/decision-intents.ts +7 -2
- package/lib/task/delegation-receipts.ts +8 -6
- package/lib/task/events.ts +10 -5
- package/lib/task/finalization.ts +84 -42
- package/lib/task/index.ts +19 -28
- package/lib/task/ledger-intents.ts +6 -8
- package/lib/task/ledger.ts +17 -7
- package/lib/task/lifecycle.ts +20 -0
- package/lib/task/orchestration.ts +42 -16
- package/lib/task/review-artifacts.ts +53 -15
- package/lib/task/review-finalization.ts +33 -7
- package/lib/task/verification-engine.ts +33 -21
- package/lib/task/verification-review.ts +1 -1
- package/lib/task/workspace-snapshot.ts +4 -13
- package/lib/task/write.ts +20 -1
- package/lib/update.ts +6 -40
- package/lib/version.ts +6 -1
- package/package.json +1 -1
- package/templates/.agents/QUICKSTART.en.md +2 -3
- package/templates/.agents/QUICKSTART.zh-CN.md +2 -3
- package/templates/.agents/README.en.md +5 -3
- package/templates/.agents/README.zh-CN.md +5 -3
- package/templates/.agents/rules/README.en.md +1 -0
- package/templates/.agents/rules/README.zh-CN.md +1 -0
- package/templates/.agents/rules/compatibility-policy.en.md +40 -0
- package/templates/.agents/rules/compatibility-policy.zh-CN.md +40 -0
- package/templates/.agents/rules/create-issue.github.en.md +1 -1
- package/templates/.agents/rules/create-issue.github.zh-CN.md +1 -1
- package/templates/.agents/rules/human-decision-context.en.md +9 -7
- package/templates/.agents/rules/human-decision-context.zh-CN.md +9 -7
- package/templates/.agents/rules/issue-fields.github.en.md +1 -1
- package/templates/.agents/rules/issue-fields.github.zh-CN.md +1 -1
- package/templates/.agents/rules/issue-pr-commands.en.md +1 -1
- package/templates/.agents/rules/issue-pr-commands.github.en.md +1 -1
- package/templates/.agents/rules/issue-pr-commands.github.zh-CN.md +1 -1
- package/templates/.agents/rules/issue-pr-commands.zh-CN.md +1 -1
- package/templates/.agents/rules/issue-sync.github.en.md +1 -1
- package/templates/.agents/rules/issue-sync.github.zh-CN.md +2 -2
- package/templates/.agents/rules/lifecycle-orchestration.en.md +4 -4
- package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +4 -4
- package/templates/.agents/rules/milestone-inference.github.en.md +1 -1
- package/templates/.agents/rules/milestone-inference.github.zh-CN.md +1 -1
- package/templates/.agents/rules/next-step-output.en.md +3 -3
- package/templates/.agents/rules/next-step-output.zh-CN.md +3 -3
- package/templates/.agents/rules/no-mid-flow-questions.en.md +1 -1
- package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +1 -1
- package/templates/.agents/rules/pr-sync.en.md +2 -2
- package/templates/.agents/rules/pr-sync.github.en.md +3 -2
- package/templates/.agents/rules/pr-sync.github.zh-CN.md +3 -1
- package/templates/.agents/rules/pr-sync.zh-CN.md +2 -1
- package/templates/.agents/rules/release-commands.github.en.md +6 -0
- package/templates/.agents/rules/release-commands.github.zh-CN.md +6 -0
- package/templates/.agents/rules/review-handshake.en.md +1 -1
- package/templates/.agents/rules/review-handshake.zh-CN.md +1 -1
- package/templates/.agents/rules/review-method.en.md +1 -0
- package/templates/.agents/rules/review-method.zh-CN.md +1 -0
- package/templates/.agents/rules/task-management.en.md +1 -2
- package/templates/.agents/rules/task-management.zh-CN.md +1 -2
- package/templates/.agents/skills/analyze-task/SKILL.en.md +4 -3
- package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +4 -3
- package/templates/.agents/skills/block-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/block-task/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/cancel-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/check-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/check-task/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/close-codescan/SKILL.en.md +1 -1
- package/templates/.agents/skills/close-codescan/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/close-dependabot/SKILL.en.md +1 -1
- package/templates/.agents/skills/close-dependabot/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/code-task/SKILL.en.md +4 -3
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +5 -3
- package/templates/.agents/skills/commit/SKILL.en.md +27 -7
- package/templates/.agents/skills/commit/SKILL.zh-CN.md +3 -4
- package/templates/.agents/skills/complete-manual-validation/SKILL.en.md +5 -5
- package/templates/.agents/skills/complete-manual-validation/SKILL.zh-CN.md +5 -5
- package/templates/.agents/skills/complete-task/SKILL.en.md +3 -3
- package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +3 -3
- package/templates/.agents/skills/create-pr/SKILL.en.md +15 -11
- package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +15 -11
- package/templates/.agents/skills/create-pr/reference/change-report.en.md +46 -0
- package/templates/.agents/skills/create-pr/reference/change-report.zh-CN.md +46 -0
- package/templates/.agents/skills/create-pr/scripts/change-report.mjs +203 -0
- package/templates/.agents/skills/create-release-note/SKILL.en.md +5 -6
- package/templates/.agents/skills/create-release-note/SKILL.zh-CN.md +5 -6
- package/templates/.agents/skills/create-task/SKILL.en.md +1 -1
- package/templates/.agents/skills/create-task/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/import-issue/SKILL.en.md +1 -1
- package/templates/.agents/skills/import-issue/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/plan-task/SKILL.en.md +5 -4
- package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +5 -4
- package/templates/.agents/skills/restore-task/SKILL.en.md +1 -1
- package/templates/.agents/skills/restore-task/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/review-analysis/SKILL.en.md +5 -3
- package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +5 -3
- package/templates/.agents/skills/review-analysis/config/verify.en.json +1 -0
- package/templates/.agents/skills/review-analysis/config/verify.zh-CN.json +1 -0
- package/templates/.agents/skills/review-code/SKILL.en.md +5 -3
- package/templates/.agents/skills/review-code/SKILL.zh-CN.md +5 -3
- package/templates/.agents/skills/review-code/config/verify.en.json +1 -0
- package/templates/.agents/skills/review-code/config/verify.zh-CN.json +1 -0
- package/templates/.agents/skills/review-code/reference/migration-risks.en.md +9 -6
- package/templates/.agents/skills/review-code/reference/migration-risks.zh-CN.md +9 -6
- package/templates/.agents/skills/review-plan/SKILL.en.md +5 -3
- package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +5 -3
- package/templates/.agents/skills/review-plan/config/verify.en.json +1 -0
- package/templates/.agents/skills/review-plan/config/verify.zh-CN.json +1 -0
- package/templates/.agents/skills/run-manual-validation/SKILL.en.md +7 -3
- package/templates/.agents/skills/run-manual-validation/SKILL.zh-CN.md +7 -3
- package/templates/.agents/skills/run-manual-validation/reference/discovery-and-execution.en.md +1 -1
- package/templates/.agents/skills/run-manual-validation/reference/discovery-and-execution.zh-CN.md +1 -1
- package/templates/.agents/skills/run-manual-validation/reference/report-template.en.md +2 -2
- package/templates/.agents/skills/run-manual-validation/reference/report-template.zh-CN.md +2 -2
- package/templates/.agents/skills/run-task/SKILL.en.md +6 -2
- package/templates/.agents/skills/run-task/SKILL.zh-CN.md +6 -2
- package/templates/.agents/skills/run-task/reference/host-validation.en.md +2 -2
- package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +2 -2
- package/templates/.agents/skills/update-agent-infra/SKILL.en.md +2 -2
- package/templates/.agents/skills/update-agent-infra/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +159 -104
- package/templates/.agents/skills/watch-pr/SKILL.en.md +2 -2
- package/templates/.agents/skills/watch-pr/SKILL.zh-CN.md +2 -2
- package/templates/.agents/templates/task.en.md +1 -1
- package/templates/.agents/templates/task.zh-CN.md +1 -1
- package/templates/.claude/commands/analyze-task.en.md +1 -1
- package/templates/.claude/commands/analyze-task.zh-CN.md +1 -1
- package/templates/.claude/commands/block-task.en.md +1 -1
- package/templates/.claude/commands/block-task.zh-CN.md +1 -1
- package/templates/.claude/commands/cancel-task.en.md +1 -1
- package/templates/.claude/commands/cancel-task.zh-CN.md +1 -1
- package/templates/.claude/commands/check-task.en.md +1 -1
- package/templates/.claude/commands/check-task.zh-CN.md +1 -1
- package/templates/.claude/commands/code-task.en.md +1 -1
- package/templates/.claude/commands/code-task.zh-CN.md +1 -1
- package/templates/.claude/commands/commit.en.md +1 -1
- package/templates/.claude/commands/commit.zh-CN.md +1 -1
- package/templates/.claude/commands/complete-manual-validation.en.md +1 -1
- package/templates/.claude/commands/complete-manual-validation.zh-CN.md +1 -1
- package/templates/.claude/commands/complete-task.en.md +1 -1
- package/templates/.claude/commands/complete-task.zh-CN.md +1 -1
- package/templates/.claude/commands/create-pr.en.md +1 -1
- package/templates/.claude/commands/create-pr.zh-CN.md +1 -1
- package/templates/.claude/commands/plan-task.en.md +1 -1
- package/templates/.claude/commands/plan-task.zh-CN.md +1 -1
- package/templates/.claude/commands/review-analysis.en.md +1 -1
- package/templates/.claude/commands/review-analysis.zh-CN.md +1 -1
- package/templates/.claude/commands/review-code.en.md +1 -1
- package/templates/.claude/commands/review-code.zh-CN.md +1 -1
- package/templates/.claude/commands/review-plan.en.md +1 -1
- package/templates/.claude/commands/review-plan.zh-CN.md +1 -1
- package/templates/.claude/commands/run-manual-validation.en.md +1 -1
- package/templates/.claude/commands/run-manual-validation.zh-CN.md +1 -1
- package/templates/.claude/commands/run-task.en.md +1 -1
- package/templates/.claude/commands/run-task.zh-CN.md +1 -1
- package/templates/.claude/commands/watch-pr.en.md +1 -1
- package/templates/.claude/commands/watch-pr.zh-CN.md +1 -1
- package/templates/.traecli/commands/update-agent-infra.en.md +7 -0
- package/templates/.traecli/commands/update-agent-infra.zh-CN.md +7 -0
- package/dist/lib/builtin-tuis.js +0 -40
- package/lib/builtin-tuis.ts +0 -56
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
createDirectHostExecutionContext,
|
|
3
|
+
dispatchTaskControlOperation,
|
|
4
|
+
parseTaskControlOperation,
|
|
5
|
+
type TaskLifecycleControlRequest
|
|
6
|
+
} from '../task/control-authority.ts';
|
|
7
|
+
import { lifecycleIntentCatalog } from '../task/lifecycle.ts';
|
|
5
8
|
import { detectRepoRoot, resolveTaskRef } from '../task/resolve-ref.ts';
|
|
6
|
-
import {
|
|
9
|
+
import type { TaskLifecycleResult } from '../task/lifecycle.ts';
|
|
7
10
|
|
|
8
11
|
const USAGE = `Usage: agent-infra-internal task-lifecycle <N | TASK-id> <intent> --agent <agent> [intent flags] [--dry-run]\n\nIntents: ${lifecycleIntentCatalog.join(', ')}\nOverride: --override-ticket <ticket> --override-target <target> --override-scope <scope>\n`;
|
|
9
|
-
const FLAGS: Record<string, string> = {
|
|
10
|
-
'--agent': 'agent', '--reason': 'reason', '--unblock-condition': 'unblockCondition',
|
|
11
|
-
'--note': 'note', '--alert-number': 'alertNumber', '--staging-dir': 'stagingDir',
|
|
12
|
-
'--issue-number': 'issueNumber', '--override-ticket': 'overrideTicket',
|
|
13
|
-
'--override-target': 'overrideTarget', '--override-scope': 'overrideScope'
|
|
14
|
-
};
|
|
15
12
|
|
|
16
13
|
function usageFailure(message: string): void {
|
|
17
14
|
process.stdout.write(`${JSON.stringify({ status: 'failed', changed: false, error: { code: 'LIFECYCLE_PAYLOAD_INVALID', message } })}\n`);
|
|
@@ -19,36 +16,29 @@ function usageFailure(message: string): void {
|
|
|
19
16
|
process.exitCode = 1;
|
|
20
17
|
}
|
|
21
18
|
|
|
19
|
+
function parseFailure(error: unknown): string {
|
|
20
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
21
|
+
return message.replace(/^TASK_CONTROL_OPERATION_INVALID: /u, '');
|
|
22
|
+
}
|
|
23
|
+
|
|
22
24
|
function taskLifecycle(args: string[] = []): void {
|
|
23
25
|
if (args[0] === '--help' || args[0] === '-h') { process.stdout.write(USAGE); return; }
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
seen.add(flag); values.dryRun = true; continue;
|
|
32
|
-
}
|
|
33
|
-
const key = FLAGS[flag];
|
|
34
|
-
if (!key) { usageFailure(`unknown option '${flag}'`); return; }
|
|
35
|
-
if (seen.has(flag)) { usageFailure(`duplicate option '${flag}'`); return; }
|
|
36
|
-
const value = args[++index];
|
|
37
|
-
if (value === undefined || value.startsWith('--')) { usageFailure(`option '${flag}' requires a value`); return; }
|
|
38
|
-
seen.add(flag);
|
|
39
|
-
values[key] = key === 'alertNumber' || key === 'issueNumber' ? Number(value) : value;
|
|
26
|
+
|
|
27
|
+
let operation;
|
|
28
|
+
try {
|
|
29
|
+
operation = parseTaskControlOperation('task-lifecycle', args);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
usageFailure(parseFailure(error));
|
|
32
|
+
return;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
if (operation.family !== 'task-lifecycle') {
|
|
35
|
+
usageFailure('lifecycle operation is invalid');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const request = operation.request as TaskLifecycleControlRequest;
|
|
46
40
|
let repoRoot: string;
|
|
47
|
-
|
|
48
|
-
if (values.intent === 'restore') {
|
|
49
|
-
// restore's precondition is that the task does NOT exist locally yet (it only lives
|
|
50
|
-
// in a staging dir), so resolveTaskRef's existence check is inapplicable here; identity
|
|
51
|
-
// is guaranteed by applyTaskLifecycle's own full-TASK-id check plus staging validation.
|
|
41
|
+
if (request.intent === 'restore') {
|
|
52
42
|
try {
|
|
53
43
|
repoRoot = detectRepoRoot();
|
|
54
44
|
} catch (error) {
|
|
@@ -56,53 +46,20 @@ function taskLifecycle(args: string[] = []): void {
|
|
|
56
46
|
process.exitCode = 1;
|
|
57
47
|
return;
|
|
58
48
|
}
|
|
59
|
-
taskId = String(values.taskRef);
|
|
60
49
|
} else {
|
|
61
|
-
const resolved = resolveTaskRef(
|
|
50
|
+
const resolved = resolveTaskRef(request.taskRef);
|
|
62
51
|
if (!resolved.ok) {
|
|
63
52
|
process.stdout.write(`${JSON.stringify({ status: 'failed', changed: false, error: { code: resolved.code, message: resolved.message } })}\n`);
|
|
64
53
|
process.exitCode = 1;
|
|
65
54
|
return;
|
|
66
55
|
}
|
|
67
56
|
repoRoot = resolved.repoRoot;
|
|
68
|
-
taskId = resolved.taskId;
|
|
69
|
-
}
|
|
70
|
-
let result: ReturnType<typeof applyTaskLifecycle> & { humanOverride?: unknown };
|
|
71
|
-
try {
|
|
72
|
-
result = withTaskExecutionLock(
|
|
73
|
-
repoRoot,
|
|
74
|
-
taskId,
|
|
75
|
-
`task-lifecycle.${String(values.intent)}`,
|
|
76
|
-
() => {
|
|
77
|
-
const lifecycleResult = applyTaskLifecycle(values as TaskLifecycleRequest);
|
|
78
|
-
if (lifecycleResult.status !== 'failed' || !values.overrideTicket) return lifecycleResult;
|
|
79
|
-
if (!values.overrideTarget || !values.overrideScope) {
|
|
80
|
-
return {
|
|
81
|
-
...lifecycleResult,
|
|
82
|
-
error: { code: 'OVERRIDE_PAYLOAD_INVALID', message: 'override ticket requires --override-target and --override-scope' }
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const override = consumeHumanOverride({
|
|
86
|
-
taskRef: String(values.taskRef),
|
|
87
|
-
ticketId: String(values.overrideTicket),
|
|
88
|
-
failureId: failureId('lifecycle.apply', lifecycleResult.error?.code ?? 'LIFECYCLE_FAILED'),
|
|
89
|
-
target: String(values.overrideTarget),
|
|
90
|
-
scope: String(values.overrideScope),
|
|
91
|
-
intent: String(values.intent) as TaskLifecycleRequest['intent'],
|
|
92
|
-
...(values.alertNumber ? { alertNumber: Number(values.alertNumber) } : {}),
|
|
93
|
-
...(values.issueNumber ? { issueNumber: Number(values.issueNumber) } : {}),
|
|
94
|
-
...(values.stagingDir ? { stagingDir: String(values.stagingDir) } : {})
|
|
95
|
-
});
|
|
96
|
-
if (override.status === 'failed') return { ...lifecycleResult, humanOverride: override };
|
|
97
|
-
return { ...lifecycleResult, ...override, humanOverride: override, error: null };
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
if (!(error instanceof TaskExecutionLockError)) throw error;
|
|
102
|
-
process.stdout.write(`${JSON.stringify({ status: 'failed', changed: false, error: { code: error.code, message: error.message } })}\n`);
|
|
103
|
-
process.exitCode = 1;
|
|
104
|
-
return;
|
|
105
57
|
}
|
|
58
|
+
|
|
59
|
+
const result = dispatchTaskControlOperation(
|
|
60
|
+
createDirectHostExecutionContext({ repoRoot }),
|
|
61
|
+
operation
|
|
62
|
+
) as TaskLifecycleResult & { humanOverride?: unknown };
|
|
106
63
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
107
64
|
if (result.status === 'failed') process.exitCode = 1;
|
|
108
65
|
}
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
advanceOrchestration,
|
|
5
|
-
awaitOrchestrationDelegationActivation,
|
|
6
|
-
beginOrResumeOrchestration,
|
|
7
|
-
dispatchOrchestrationDelegation,
|
|
8
|
-
OrchestrationStateError,
|
|
9
|
-
pauseOrchestration,
|
|
10
|
-
recoverPreparedOrchestrationDelegation,
|
|
11
|
-
routeOrchestration,
|
|
12
|
-
sealMatchingOrchestrationDelegation,
|
|
13
|
-
sealOrchestrationDelegation,
|
|
14
|
-
statusOrchestration
|
|
15
|
-
} from '../task/orchestration.ts';
|
|
16
|
-
import { prepareCodexOrchestrationDelegation } from '../task/codex-orchestration.ts';
|
|
17
|
-
import { isAgentClientId } from '../agent-clients/types.ts';
|
|
18
|
-
import type { AgentClientId } from '../agent-clients/types.ts';
|
|
1
|
+
import { createDirectHostExecutionContext, dispatchTaskControlOperation, parseTaskControlOperation } from '../task/control-authority.ts';
|
|
2
|
+
import { OrchestrationStateError } from '../task/orchestration.ts';
|
|
3
|
+
import { detectRepoRoot } from '../task/resolve-ref.ts';
|
|
19
4
|
|
|
20
5
|
const USAGE = 'Usage: agent-infra-internal task-orchestration <task-ref|auto> <begin-or-resume|route|prepare|dispatch|await-activation|recover-prepared|hook-start|hook-stop|advance|pause|status> [options]\n';
|
|
21
6
|
|
|
@@ -28,192 +13,50 @@ function usageFailure(message: string): void {
|
|
|
28
13
|
process.exitCode = 2;
|
|
29
14
|
}
|
|
30
15
|
|
|
16
|
+
function parseFailure(error: unknown): string {
|
|
17
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
18
|
+
return message.replace(/^TASK_CONTROL_OPERATION_INVALID: /u, '');
|
|
19
|
+
}
|
|
20
|
+
|
|
31
21
|
async function taskOrchestration(args: string[] = []): Promise<void> {
|
|
32
22
|
if (args[0] === '--help' || args[0] === '-h') {
|
|
33
23
|
process.stdout.write(USAGE);
|
|
34
24
|
return;
|
|
35
25
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
'begin-or-resume', 'route', 'prepare', 'dispatch', 'await-activation', 'recover-prepared',
|
|
43
|
-
'hook-start', 'hook-stop', 'advance', 'pause', 'status'
|
|
44
|
-
].includes(intent!)) {
|
|
45
|
-
usageFailure(`unknown intent '${intent}'`);
|
|
26
|
+
|
|
27
|
+
let operation;
|
|
28
|
+
try {
|
|
29
|
+
operation = parseTaskControlOperation('task-orchestration', args);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
usageFailure(parseFailure(error));
|
|
46
32
|
return;
|
|
47
33
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (let index = 2; index < args.length; index += 1) {
|
|
51
|
-
const flag = args[index]!;
|
|
52
|
-
if (![
|
|
53
|
-
'--max-steps', '--executor-model', '--executor-reasoning-effort',
|
|
54
|
-
'--reviewer-model', '--reviewer-reasoning-effort',
|
|
55
|
-
'--client', '--requested-model', '--requested-reasoning-effort', '--capability-token',
|
|
56
|
-
'--parent-id', '--before-fingerprint',
|
|
57
|
-
'--stage', '--round', '--artifact', '--role',
|
|
58
|
-
'--native-agent', '--child-id', '--spawn-mode', '--actual-model', '--actual-reasoning-effort',
|
|
59
|
-
'--model-fallback-reason', '--reasoning-effort-fallback-reason',
|
|
60
|
-
'--exit-code', '--after-fingerprint', '--changed-paths', '--code', '--message', '--recoverable', '--agent',
|
|
61
|
-
'--git-worktree-root'
|
|
62
|
-
].includes(flag)) {
|
|
63
|
-
usageFailure(`unknown option '${flag}'`);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (seen.has(flag)) {
|
|
67
|
-
usageFailure(`duplicate option '${flag}'`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
seen.add(flag);
|
|
71
|
-
const value = args[++index];
|
|
72
|
-
if (!value || value.startsWith('--')) {
|
|
73
|
-
usageFailure(`option '${flag}' requires a value`);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
values[flag] = value;
|
|
77
|
-
}
|
|
78
|
-
const requireValues = (flags: string[]) => flags.find((flag) => values[flag] === undefined);
|
|
79
|
-
const coreOptions = values['--git-worktree-root'] === undefined
|
|
80
|
-
? {}
|
|
81
|
-
: { gitWorktreeRoot: values['--git-worktree-root'] };
|
|
82
|
-
if (values['--client'] !== undefined && !isAgentClientId(values['--client'])) {
|
|
83
|
-
usageFailure(`unknown client '${values['--client']}'`);
|
|
34
|
+
if (operation.family !== 'task-orchestration') {
|
|
35
|
+
usageFailure('orchestration operation is invalid');
|
|
84
36
|
return;
|
|
85
37
|
}
|
|
86
|
-
|
|
38
|
+
|
|
39
|
+
let repoRoot = process.cwd();
|
|
40
|
+
try { repoRoot = detectRepoRoot(); } catch { /* domain resolution reports the repository error */ }
|
|
41
|
+
|
|
87
42
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
'--reviewer-model', '--reviewer-reasoning-effort'
|
|
98
|
-
];
|
|
99
|
-
const hasAnyPolicy = policyFlags.some((flag) => values[flag] !== undefined);
|
|
100
|
-
if (hasAnyPolicy && policyFlags.some((flag) => values[flag] === undefined)) {
|
|
101
|
-
usageFailure('explicit model policy requires executor/reviewer model and reasoning effort');
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
result = beginOrResumeOrchestration(taskRef!, {
|
|
105
|
-
...coreOptions,
|
|
106
|
-
maxSteps,
|
|
107
|
-
client: values['--client'] as AgentClientId,
|
|
108
|
-
modelPolicy: hasAnyPolicy ? {
|
|
109
|
-
executor: {
|
|
110
|
-
model: values['--executor-model']!,
|
|
111
|
-
reasoningEffort: values['--executor-reasoning-effort']!
|
|
112
|
-
},
|
|
113
|
-
reviewer: {
|
|
114
|
-
model: values['--reviewer-model']!,
|
|
115
|
-
reasoningEffort: values['--reviewer-reasoning-effort']!
|
|
116
|
-
}
|
|
117
|
-
} : undefined
|
|
118
|
-
});
|
|
119
|
-
} else if (intent === 'route') {
|
|
120
|
-
result = routeOrchestration(taskRef!, coreOptions);
|
|
121
|
-
} else if (intent === 'status') {
|
|
122
|
-
result = statusOrchestration(taskRef!, coreOptions);
|
|
123
|
-
} else if (intent === 'prepare') {
|
|
124
|
-
const missing = requireValues(['--client']);
|
|
125
|
-
if (missing) { usageFailure(`intent 'prepare' requires '${missing}'`); return; }
|
|
126
|
-
result = await prepareCodexOrchestrationDelegation(taskRef!, {
|
|
127
|
-
client: values['--client'] as AgentClientId,
|
|
128
|
-
requestedModel: values['--requested-model'],
|
|
129
|
-
requestedReasoningEffort: values['--requested-reasoning-effort'],
|
|
130
|
-
capabilityToken: values['--capability-token']
|
|
131
|
-
}, { orchestrationOptions: coreOptions });
|
|
132
|
-
} else if (intent === 'dispatch') {
|
|
133
|
-
result = dispatchOrchestrationDelegation(taskRef!, coreOptions);
|
|
134
|
-
} else if (intent === 'await-activation') {
|
|
135
|
-
const missing = requireValues(['--stage', '--round', '--artifact', '--role']);
|
|
136
|
-
if (missing) { usageFailure(`intent 'await-activation' requires '${missing}'`); return; }
|
|
137
|
-
const round = Number(values['--round']);
|
|
138
|
-
if (!Number.isSafeInteger(round) || round < 1) {
|
|
139
|
-
usageFailure('--round must be a positive integer'); return;
|
|
140
|
-
}
|
|
141
|
-
if (!['executor', 'reviewer'].includes(values['--role']!)) {
|
|
142
|
-
usageFailure('--role must be executor or reviewer'); return;
|
|
143
|
-
}
|
|
144
|
-
result = await awaitOrchestrationDelegationActivation(taskRef!, {
|
|
145
|
-
stage: values['--stage'] as Parameters<typeof awaitOrchestrationDelegationActivation>[1]['stage'],
|
|
146
|
-
round,
|
|
147
|
-
artifact: values['--artifact']!,
|
|
148
|
-
role: values['--role'] as 'executor' | 'reviewer'
|
|
149
|
-
}, coreOptions);
|
|
150
|
-
} else if (intent === 'recover-prepared') {
|
|
151
|
-
result = recoverPreparedOrchestrationDelegation(taskRef!, coreOptions);
|
|
152
|
-
} else if (intent === 'hook-start') {
|
|
153
|
-
const missing = requireValues([
|
|
154
|
-
...(taskRef === 'auto' ? ['--client'] : []),
|
|
155
|
-
'--native-agent', '--child-id', '--parent-id'
|
|
156
|
-
]);
|
|
157
|
-
if (missing) { usageFailure(`intent 'hook-start' requires '${missing}'`); return; }
|
|
158
|
-
const event = {
|
|
159
|
-
nativeAgent: values['--native-agent']!, childId: values['--child-id']!,
|
|
160
|
-
parentId: values['--parent-id']!, spawnMode: values['--spawn-mode'],
|
|
161
|
-
actualModel: values['--actual-model'],
|
|
162
|
-
actualReasoningEffort: values['--actual-reasoning-effort'],
|
|
163
|
-
modelFallbackReason: values['--model-fallback-reason'],
|
|
164
|
-
reasoningEffortFallbackReason: values['--reasoning-effort-fallback-reason']
|
|
165
|
-
};
|
|
166
|
-
result = taskRef === 'auto'
|
|
167
|
-
? activateMatchingOrchestrationDelegation(values['--client'] as AgentClientId, event, coreOptions)
|
|
168
|
-
: activateOrchestrationDelegation(taskRef!, event, coreOptions);
|
|
169
|
-
} else if (intent === 'hook-stop') {
|
|
170
|
-
if (taskRef === 'auto') {
|
|
171
|
-
const missing = requireValues(['--client', '--native-agent', '--child-id']);
|
|
172
|
-
if (missing) { usageFailure(`intent 'hook-stop' requires '${missing}'`); return; }
|
|
173
|
-
result = sealMatchingOrchestrationDelegation(values['--client'] as AgentClientId, {
|
|
174
|
-
nativeAgent: values['--native-agent']!, childId: values['--child-id']!,
|
|
175
|
-
actualModel: values['--actual-model'],
|
|
176
|
-
actualReasoningEffort: values['--actual-reasoning-effort'],
|
|
177
|
-
modelFallbackReason: values['--model-fallback-reason'],
|
|
178
|
-
reasoningEffortFallbackReason: values['--reasoning-effort-fallback-reason']
|
|
179
|
-
}, coreOptions);
|
|
180
|
-
} else {
|
|
181
|
-
const missing = requireValues(['--child-id', '--exit-code', '--after-fingerprint']);
|
|
182
|
-
if (missing) { usageFailure(`intent 'hook-stop' requires '${missing}'`); return; }
|
|
183
|
-
const exitCode = Number(values['--exit-code']);
|
|
184
|
-
if (!Number.isInteger(exitCode)) { usageFailure('--exit-code must be an integer'); return; }
|
|
185
|
-
result = sealOrchestrationDelegation(taskRef!, {
|
|
186
|
-
childId: values['--child-id']!, exitCode,
|
|
187
|
-
afterFingerprint: values['--after-fingerprint']!,
|
|
188
|
-
changedPaths: values['--changed-paths'] ? values['--changed-paths']!.split(',').filter(Boolean) : [],
|
|
189
|
-
actualModel: values['--actual-model'],
|
|
190
|
-
actualReasoningEffort: values['--actual-reasoning-effort'],
|
|
191
|
-
modelFallbackReason: values['--model-fallback-reason'],
|
|
192
|
-
reasoningEffortFallbackReason: values['--reasoning-effort-fallback-reason']
|
|
193
|
-
}, coreOptions);
|
|
194
|
-
}
|
|
195
|
-
} else if (intent === 'advance') {
|
|
196
|
-
result = advanceOrchestration(taskRef!, coreOptions);
|
|
197
|
-
} else {
|
|
198
|
-
const missing = requireValues(['--code', '--message', '--recoverable']);
|
|
199
|
-
if (missing) { usageFailure(`intent 'pause' requires '${missing}'`); return; }
|
|
200
|
-
if (!['true', 'false'].includes(values['--recoverable']!)) { usageFailure('--recoverable must be true or false'); return; }
|
|
201
|
-
result = pauseOrchestration(taskRef!, values['--code']!, values['--message']!, values['--recoverable'] === 'true', coreOptions);
|
|
202
|
-
}
|
|
43
|
+
const result = await dispatchTaskControlOperation(
|
|
44
|
+
createDirectHostExecutionContext({
|
|
45
|
+
repoRoot,
|
|
46
|
+
...(process.env.AGENT_INFRA_RUNTIME_DIR ? { runtimeDir: process.env.AGENT_INFRA_RUNTIME_DIR } : {})
|
|
47
|
+
}),
|
|
48
|
+
operation
|
|
49
|
+
);
|
|
50
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
51
|
+
if (result.status === 'failed') process.exitCode = 1;
|
|
203
52
|
} catch (error) {
|
|
204
53
|
if (!(error instanceof OrchestrationStateError)) throw error;
|
|
205
|
-
|
|
206
|
-
status: 'failed'
|
|
207
|
-
changed: false,
|
|
208
|
-
taskId: error.taskId,
|
|
209
|
-
run: null,
|
|
210
|
-
next: null,
|
|
54
|
+
process.stdout.write(`${JSON.stringify({
|
|
55
|
+
status: 'failed', changed: false, taskId: error.taskId, run: null, next: null,
|
|
211
56
|
error: { code: error.code, message: error.message }
|
|
212
|
-
};
|
|
57
|
+
})}\n`);
|
|
58
|
+
process.exitCode = 1;
|
|
213
59
|
}
|
|
214
|
-
const output = result;
|
|
215
|
-
process.stdout.write(`${JSON.stringify(output)}\n`);
|
|
216
|
-
if (result.status === 'failed') process.exitCode = 1;
|
|
217
60
|
}
|
|
218
61
|
|
|
219
62
|
export { taskOrchestration };
|
|
@@ -3,28 +3,29 @@ import fs from 'node:fs';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { randomUUID } from 'node:crypto';
|
|
6
|
-
import { loadConfig } from '
|
|
7
|
-
import { detectEngine } from '
|
|
8
|
-
import { runEngine } from '
|
|
9
|
-
import { sandboxBranchLabel, sandboxLabel } from '
|
|
10
|
-
import { fetchSandboxRows, selectSandboxContainer } from '
|
|
11
|
-
import { containerNameCandidates } from '
|
|
12
|
-
import { resolveSandboxTarget } from '
|
|
13
|
-
import { sandboxControlPaths } from '
|
|
6
|
+
import { loadConfig } from '../sandbox/config.ts';
|
|
7
|
+
import { detectEngine } from '../sandbox/engine.ts';
|
|
8
|
+
import { runEngine } from '../sandbox/shell.ts';
|
|
9
|
+
import { sandboxBranchLabel, sandboxLabel } from '../sandbox/constants.ts';
|
|
10
|
+
import { fetchSandboxRows, selectSandboxContainer } from '../sandbox/commands/list-running.ts';
|
|
11
|
+
import { containerNameCandidates } from '../sandbox/constants.ts';
|
|
12
|
+
import { resolveSandboxTarget } from '../sandbox/workspace-identity.ts';
|
|
13
|
+
import { sandboxControlPaths } from '../sandbox/workspace-view.ts';
|
|
14
14
|
import {
|
|
15
15
|
appendSandboxControlAudit,
|
|
16
16
|
readActiveLease,
|
|
17
17
|
readSandboxControlStatus
|
|
18
|
-
} from '
|
|
19
|
-
import type { SandboxControlLease
|
|
18
|
+
} from '../sandbox/control/state.ts';
|
|
19
|
+
import type { SandboxControlLease } from '../sandbox/control/protocol.ts';
|
|
20
|
+
import { readSandboxControlManifest } from '../sandbox/control/lifecycle.ts';
|
|
20
21
|
import {
|
|
21
22
|
SANDBOX_CONTROL_FUTURE_SKEW_MS,
|
|
22
23
|
SANDBOX_CONTROL_STATUS_STALE_MS
|
|
23
|
-
} from '
|
|
24
|
-
import { getProcessStartTime } from '
|
|
25
|
-
import { assertGitWorktreeBinding } from '
|
|
24
|
+
} from '../sandbox/control/protocol.ts';
|
|
25
|
+
import { getProcessStartTime } from '../server/process-state.ts';
|
|
26
|
+
import { assertGitWorktreeBinding } from '../git/worktree-identity.ts';
|
|
26
27
|
|
|
27
|
-
const USAGE = `Usage:
|
|
28
|
+
const USAGE = `Usage: agent-infra-internal task-validate <branch | TASK-id | N> [--scope snapshot|inplace] [--timeout <ms>] [--format text|json] -- <command> [args...]`;
|
|
28
29
|
const MAX_TIMEOUT_MS = 60 * 60 * 1000;
|
|
29
30
|
const RECOVERY_GRACE_MS = 30_000;
|
|
30
31
|
|
|
@@ -152,7 +153,7 @@ function inplaceValidation(config: ReturnType<typeof loadConfig>, target: Return
|
|
|
152
153
|
base: config.controlBase, project: config.project,
|
|
153
154
|
container: row.name, identity: target.workspace
|
|
154
155
|
});
|
|
155
|
-
const manifest =
|
|
156
|
+
const manifest = readSandboxControlManifest(control.manifestPath);
|
|
156
157
|
const initial = readSandboxControlStatus(control.statusDir);
|
|
157
158
|
const now = Date.now();
|
|
158
159
|
if (initial.generation !== manifest.generation
|
|
@@ -250,33 +251,68 @@ function inplaceValidation(config: ReturnType<typeof loadConfig>, target: Return
|
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
|
|
253
|
-
|
|
254
|
-
const
|
|
254
|
+
function errorCode(message: string): string {
|
|
255
|
+
const match = message.match(/^([A-Z][A-Z0-9_]*)/);
|
|
256
|
+
return match && match[1]!.length >= 3 ? match[1]! : 'TASK_VALIDATE_FAILED';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function fail(format: 'text' | 'json', code: string, message: string): void {
|
|
260
|
+
if (format === 'json') {
|
|
261
|
+
process.stdout.write(`${JSON.stringify({ status: 'failed', changed: false, error: { code, message } })}\n`);
|
|
262
|
+
} else {
|
|
263
|
+
process.stderr.write(`${message}\n`);
|
|
264
|
+
}
|
|
265
|
+
process.exitCode = 1;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function sniffFormat(args: string[]): 'text' | 'json' {
|
|
269
|
+
const index = args.indexOf('--format');
|
|
270
|
+
return index >= 0 && args[index + 1] === 'json' ? 'json' : 'text';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function taskValidate(args: string[]): void {
|
|
274
|
+
let options: ValidateOptions;
|
|
275
|
+
try {
|
|
276
|
+
options = parseValidateArgs(args);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
fail(sniffFormat(args), 'TASK_VALIDATE_ARGS_INVALID', error instanceof Error ? error.message : String(error));
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
255
281
|
if (options.help) {
|
|
256
282
|
process.stdout.write(`${USAGE}\n`);
|
|
257
|
-
return
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
const config = loadConfig();
|
|
287
|
+
const target = resolveSandboxTarget(options.target, config.repoRoot);
|
|
288
|
+
const commit = git(config.repoRoot, ['rev-parse', target.branch]);
|
|
289
|
+
const startedAt = new Date().toISOString();
|
|
290
|
+
const result = options.scope === 'snapshot'
|
|
291
|
+
? snapshotValidation(config.repoRoot, commit, options)
|
|
292
|
+
: inplaceValidation(config, target, options);
|
|
293
|
+
const evidence = {
|
|
294
|
+
version: 1,
|
|
295
|
+
taskId: target.workspace.mode === 'task-bound' ? target.workspace.taskId : null,
|
|
296
|
+
branch: target.branch,
|
|
297
|
+
scope: options.scope,
|
|
298
|
+
commit,
|
|
299
|
+
command: path.basename(options.command[0]!),
|
|
300
|
+
startedAt,
|
|
301
|
+
completedAt: new Date().toISOString(),
|
|
302
|
+
exitCode: result.exitCode,
|
|
303
|
+
signal: result.signal,
|
|
304
|
+
cleanup: result.cleanup()
|
|
305
|
+
};
|
|
306
|
+
if (options.format === 'json') {
|
|
307
|
+
process.stdout.write(`${JSON.stringify({ status: 'applied', changed: false, evidence, error: null })}\n`);
|
|
308
|
+
} else {
|
|
309
|
+
process.stdout.write(`Validation ${result.exitCode === 0 ? 'passed' : 'failed'} (${options.scope}, ${evidence.command}, cleanup=${evidence.cleanup}).\n`);
|
|
310
|
+
}
|
|
311
|
+
process.exitCode = result.exitCode;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
314
|
+
fail(options.format, errorCode(message), message);
|
|
258
315
|
}
|
|
259
|
-
const config = loadConfig();
|
|
260
|
-
const target = resolveSandboxTarget(options.target, config.repoRoot);
|
|
261
|
-
const commit = git(config.repoRoot, ['rev-parse', target.branch]);
|
|
262
|
-
const startedAt = new Date().toISOString();
|
|
263
|
-
const result = options.scope === 'snapshot'
|
|
264
|
-
? snapshotValidation(config.repoRoot, commit, options)
|
|
265
|
-
: inplaceValidation(config, target, options);
|
|
266
|
-
const evidence = {
|
|
267
|
-
version: 1,
|
|
268
|
-
taskId: target.workspace.mode === 'task-bound' ? target.workspace.taskId : null,
|
|
269
|
-
branch: target.branch,
|
|
270
|
-
scope: options.scope,
|
|
271
|
-
commit,
|
|
272
|
-
command: path.basename(options.command[0]!),
|
|
273
|
-
startedAt,
|
|
274
|
-
completedAt: new Date().toISOString(),
|
|
275
|
-
exitCode: result.exitCode,
|
|
276
|
-
signal: result.signal,
|
|
277
|
-
cleanup: result.cleanup()
|
|
278
|
-
};
|
|
279
|
-
if (options.format === 'json') process.stdout.write(`${JSON.stringify(evidence)}\n`);
|
|
280
|
-
else process.stdout.write(`Validation ${result.exitCode === 0 ? 'passed' : 'failed'} (${options.scope}, ${evidence.command}, cleanup=${evidence.cleanup}).\n`);
|
|
281
|
-
return result.exitCode;
|
|
282
316
|
}
|
|
317
|
+
|
|
318
|
+
export { taskValidate };
|