@fitlab-ai/agent-infra 0.12.1 → 0.12.2
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 +0 -2
- package/README.zh-CN.md +0 -2
- package/dist/bin/internal-cli.js +2 -17
- package/dist/lib/agent-clients/adapter.js +0 -13
- package/dist/lib/agent-clients/adapters/antigravity-cli.js +0 -5
- package/dist/lib/agent-clients/adapters/claude-code-credentials.js +0 -17
- package/dist/lib/agent-clients/adapters/claude-code.js +0 -9
- package/dist/lib/agent-clients/adapters/codex.js +0 -52
- package/dist/lib/agent-clients/adapters/opencode.js +0 -5
- package/dist/lib/agent-clients/adapters/traecli.js +0 -5
- package/dist/lib/agent-clients/config.js +19 -54
- package/dist/lib/agent-clients/registry.js +1 -12
- package/dist/lib/agent-clients/schema.js +0 -18
- package/dist/lib/agent-clients/tokens.js +1 -2
- package/dist/lib/agent-clients/types.js +0 -1
- package/dist/lib/decide.js +2 -0
- package/dist/lib/git/worktree-identity.js +1 -9
- package/dist/lib/internal/agent-client.js +2 -62
- package/dist/lib/internal/cli-route-inventory.js +1 -5
- package/dist/lib/internal/manual-validation.js +18 -10
- package/dist/lib/internal/task-create.js +1 -1
- package/dist/lib/internal/task-event.js +1 -8
- package/dist/lib/internal/task-finalization.js +0 -1
- package/dist/lib/internal/task-lifecycle.js +2 -2
- package/dist/lib/internal/task-operation-registry.js +4 -20
- package/dist/lib/internal/task-review.js +4 -4
- package/dist/lib/platform/comment-safety.js +1 -7
- package/dist/lib/platform/in-label-sync.js +1 -14
- package/dist/lib/platform/issue-comments.js +1 -16
- package/dist/lib/platform/issues.js +1 -1
- package/dist/lib/platform/operation-coordinator.js +4 -2
- package/dist/lib/platform/pr-change-report.js +1 -4
- package/dist/lib/platform/pr-checks.js +2 -8
- package/dist/lib/platform/provider-validation.js +0 -20
- package/dist/lib/platform/pull-requests.js +73 -84
- package/dist/lib/platform/releases.js +1 -43
- package/dist/lib/platform/verification-required.js +0 -2
- package/dist/lib/platform/verification-sync.js +1 -79
- package/dist/lib/process-data/normalize.js +1 -185
- package/dist/lib/process-data/privacy.js +1 -16
- package/dist/lib/process-data/sources.js +2 -279
- package/dist/lib/render.js +0 -12
- package/dist/lib/run/index.js +15 -10
- package/dist/lib/run/skills.js +0 -3
- package/dist/lib/sandbox/commands/create.js +40 -53
- package/dist/lib/sandbox/commands/list-running.js +0 -18
- package/dist/lib/sandbox/commands/start.js +7 -8
- package/dist/lib/sandbox/constants.js +0 -6
- package/dist/lib/sandbox/control/client.js +0 -1
- package/dist/lib/sandbox/control/container-identity.js +1 -16
- package/dist/lib/sandbox/control/executor.js +0 -4
- package/dist/lib/sandbox/control/identity-sentinel.js +0 -7
- package/dist/lib/sandbox/control/lifecycle.js +21 -37
- package/dist/lib/sandbox/control/native-file-lock.js +0 -3
- package/dist/lib/sandbox/control/server.js +18 -38
- package/dist/lib/sandbox/control/state.js +1 -9
- package/dist/lib/sandbox/dockerfile.js +0 -6
- package/dist/lib/sandbox/engine.js +0 -14
- package/dist/lib/sandbox/engines/docker-exact-discovery.js +1 -4
- package/dist/lib/sandbox/engines/wsl2-paths.js +0 -3
- package/dist/lib/sandbox/recovery.js +24 -26
- package/dist/lib/sandbox/removal.js +11 -519
- package/dist/lib/sandbox/task-resolver.js +0 -41
- package/dist/lib/sandbox/tools.js +1 -4
- package/dist/lib/sandbox/workspace-view.js +1 -2
- package/dist/lib/server/display.js +0 -6
- package/dist/lib/task/activity-intent.js +45 -40
- package/dist/lib/task/activity-log.js +9 -16
- package/dist/lib/task/artifact-command.js +1 -1
- package/dist/lib/task/artifact-lifecycle.js +61 -63
- package/dist/lib/task/artifact-name.js +0 -6
- package/dist/lib/task/artifact-operations.js +3 -3
- package/dist/lib/task/capabilities.js +4 -5
- package/dist/lib/task/commands/log.js +0 -6
- package/dist/lib/task/commands/status.js +17 -60
- package/dist/lib/task/commit-operation.js +28 -39
- package/dist/lib/task/completion-facts.js +56 -43
- package/dist/lib/task/control-authority.js +23 -256
- package/dist/lib/task/control-recovery.js +3 -5
- package/dist/lib/task/create.js +2 -4
- package/dist/lib/task/decision-intents.js +8 -9
- package/dist/lib/task/delivery-target.js +1 -40
- package/dist/lib/task/events.js +84 -107
- package/dist/lib/task/finalization.js +44 -8
- package/dist/lib/task/ledger-intents.js +1 -1
- package/dist/lib/task/lifecycle-execution.js +38 -33
- package/dist/lib/task/lifecycle.js +49 -41
- package/dist/lib/task/local-artifact-finalization.js +1 -4
- package/dist/lib/task/manual-validation-evidence.js +1 -37
- package/dist/lib/task/platform-operation-recovery.js +67 -24
- package/dist/lib/task/pr-delivery-fact.js +2 -5
- package/dist/lib/task/qualification-confirmation.js +5 -7
- package/dist/lib/task/resolve-ref.js +1 -25
- package/dist/lib/task/review-command.js +2 -2
- package/dist/lib/task/review-finalization.js +1 -21
- package/dist/lib/task/review-fingerprint.js +0 -4
- package/dist/lib/task/secure-fs.js +0 -56
- package/dist/lib/task/short-id.js +1 -39
- package/dist/lib/task/skill-scope.js +0 -1
- package/dist/lib/task/verification-engine.js +58 -282
- package/dist/lib/task/verification.js +6 -3
- package/dist/lib/task/write.js +11 -1
- package/lib/agent-clients/adapter.ts +0 -76
- package/lib/agent-clients/adapters/antigravity-cli.ts +0 -5
- package/lib/agent-clients/adapters/claude-code-credentials.ts +0 -19
- package/lib/agent-clients/adapters/claude-code.ts +0 -9
- package/lib/agent-clients/adapters/codex.ts +0 -56
- package/lib/agent-clients/adapters/opencode.ts +0 -5
- package/lib/agent-clients/adapters/traecli.ts +0 -5
- package/lib/agent-clients/config.ts +20 -61
- package/lib/agent-clients/registry.ts +1 -34
- package/lib/agent-clients/schema.ts +0 -18
- package/lib/agent-clients/tokens.ts +1 -2
- package/lib/agent-clients/types.ts +0 -15
- package/lib/decide.ts +1 -0
- package/lib/git/worktree-identity.ts +0 -10
- package/lib/internal/agent-client.ts +2 -70
- package/lib/internal/cli-route-inventory.ts +1 -4
- package/lib/internal/manual-validation.ts +16 -9
- package/lib/internal/task-create.ts +0 -1
- package/lib/internal/task-event.ts +1 -5
- package/lib/internal/task-finalization.ts +0 -1
- package/lib/internal/task-lifecycle.ts +3 -5
- package/lib/internal/task-operation-registry.ts +3 -19
- package/lib/internal/task-review.ts +4 -4
- package/lib/platform/comment-safety.ts +0 -10
- package/lib/platform/github-provider.ts +0 -2
- package/lib/platform/in-label-sync.ts +0 -16
- package/lib/platform/issue-comments.ts +0 -21
- package/lib/platform/issues.ts +0 -2
- package/lib/platform/operation-coordinator.ts +4 -2
- package/lib/platform/pr-change-report.ts +0 -5
- package/lib/platform/pr-checks.ts +1 -10
- package/lib/platform/pr-review.ts +1 -1
- package/lib/platform/provider-bridge.ts +0 -1
- package/lib/platform/provider-loader.ts +1 -5
- package/lib/platform/provider-validation.ts +1 -49
- package/lib/platform/pull-requests.ts +64 -99
- package/lib/platform/releases.ts +1 -40
- package/lib/platform/verification-required.ts +0 -2
- package/lib/platform/verification-sync.ts +0 -94
- package/lib/process-data/normalize.ts +1 -186
- package/lib/process-data/privacy.ts +2 -19
- package/lib/process-data/sources.ts +3 -283
- package/lib/render.ts +0 -15
- package/lib/run/index.ts +13 -7
- package/lib/run/skills.ts +0 -4
- package/lib/sandbox/commands/create.ts +37 -74
- package/lib/sandbox/commands/list-running.ts +0 -19
- package/lib/sandbox/commands/start.ts +7 -10
- package/lib/sandbox/constants.ts +0 -8
- package/lib/sandbox/control/client.ts +0 -1
- package/lib/sandbox/control/container-identity.ts +1 -16
- package/lib/sandbox/control/executor.ts +1 -5
- package/lib/sandbox/control/identity-sentinel.ts +0 -8
- package/lib/sandbox/control/lifecycle.ts +18 -51
- package/lib/sandbox/control/native-file-lock.ts +0 -8
- package/lib/sandbox/control/protocol.ts +0 -2
- package/lib/sandbox/control/server.ts +13 -39
- package/lib/sandbox/control/state.ts +1 -10
- package/lib/sandbox/dockerfile.ts +0 -11
- package/lib/sandbox/engine.ts +0 -17
- package/lib/sandbox/engines/docker-exact-discovery.ts +1 -5
- package/lib/sandbox/engines/wsl2-paths.ts +0 -4
- package/lib/sandbox/recovery.ts +24 -26
- package/lib/sandbox/removal.ts +11 -696
- package/lib/sandbox/shell.ts +1 -1
- package/lib/sandbox/task-resolver.ts +0 -48
- package/lib/sandbox/tools.ts +1 -5
- package/lib/sandbox/workspace-view.ts +2 -4
- package/lib/server/display.ts +0 -14
- package/lib/server/process-control.ts +1 -1
- package/lib/task/activity-intent.ts +36 -44
- package/lib/task/activity-log.ts +9 -22
- package/lib/task/artifact-command.ts +1 -1
- package/lib/task/artifact-lifecycle.ts +58 -67
- package/lib/task/artifact-name.ts +0 -7
- package/lib/task/artifact-operations.ts +3 -3
- package/lib/task/capabilities.ts +5 -6
- package/lib/task/commands/log.ts +0 -7
- package/lib/task/commands/status.ts +14 -79
- package/lib/task/commit-operation.ts +29 -51
- package/lib/task/completion-facts.ts +45 -42
- package/lib/task/control-authority.ts +27 -317
- package/lib/task/control-recovery.ts +2 -5
- package/lib/task/create.ts +2 -5
- package/lib/task/decision-intents.ts +5 -5
- package/lib/task/delivery-target.ts +0 -40
- package/lib/task/events.ts +89 -123
- package/lib/task/finalization.ts +41 -9
- package/lib/task/ledger-intents.ts +1 -1
- package/lib/task/lifecycle-execution.ts +37 -89
- package/lib/task/lifecycle.ts +48 -44
- package/lib/task/local-artifact-finalization.ts +0 -7
- package/lib/task/manual-validation-evidence.ts +1 -47
- package/lib/task/platform-operation-recovery.ts +50 -26
- package/lib/task/pr-delivery-fact.ts +2 -11
- package/lib/task/qualification-confirmation.ts +6 -6
- package/lib/task/resolve-ref.ts +0 -23
- package/lib/task/review-command.ts +2 -2
- package/lib/task/review-finalization.ts +1 -27
- package/lib/task/review-fingerprint.ts +0 -8
- package/lib/task/secure-fs.ts +0 -42
- package/lib/task/short-id.ts +0 -43
- package/lib/task/skill-scope.ts +0 -1
- package/lib/task/verification-engine.ts +56 -287
- package/lib/task/verification.ts +5 -5
- package/lib/task/write.ts +12 -1
- package/package.json +2 -2
- package/templates/.agents/README.en.md +1 -3
- package/templates/.agents/README.zh-CN.md +0 -2
- package/templates/.agents/rules/README.en.md +0 -1
- package/templates/.agents/rules/README.zh-CN.md +0 -1
- package/templates/.agents/rules/commit-and-pr.en.md +1 -1
- package/templates/.agents/rules/commit-and-pr.zh-CN.md +1 -1
- package/templates/.agents/rules/no-mid-flow-questions.en.md +0 -10
- package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +0 -10
- package/templates/.agents/rules/pr-sync.en.md +1 -1
- package/templates/.agents/rules/pr-sync.zh-CN.md +1 -1
- package/templates/.agents/rules/task-management.en.md +3 -3
- package/templates/.agents/rules/task-management.zh-CN.md +3 -3
- package/templates/.agents/skills/analyze-task/SKILL.en.md +3 -3
- package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +3 -3
- 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/code-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/commit/SKILL.en.md +2 -2
- package/templates/.agents/skills/commit/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/commit/reference/commit-orchestration.en.md +6 -6
- package/templates/.agents/skills/commit/reference/commit-orchestration.zh-CN.md +6 -6
- package/templates/.agents/skills/plan-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/review-analysis/SKILL.en.md +3 -3
- package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +3 -3
- package/templates/.agents/skills/review-code/SKILL.en.md +5 -5
- package/templates/.agents/skills/review-code/SKILL.zh-CN.md +5 -5
- package/templates/.agents/skills/review-plan/SKILL.en.md +3 -3
- package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +3 -3
- package/templates/.agents/skills/review-pr/SKILL.en.md +4 -4
- package/templates/.agents/skills/review-pr/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/run-manual-validation/SKILL.en.md +1 -1
- package/templates/.agents/skills/run-manual-validation/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +3 -75
- package/templates/.agents/templates/task.en.md +1 -0
- package/templates/.agents/templates/task.zh-CN.md +1 -0
- package/templates/.claude/settings.json +0 -24
- package/templates/.codex/hooks.json +0 -50
- package/dist/lib/agent-clients/adapters/codex-lifecycle/app-server.js +0 -582
- package/dist/lib/agent-clients/adapters/codex-lifecycle/binding.js +0 -114
- package/dist/lib/agent-clients/adapters/codex-lifecycle/build-identity.js +0 -237
- package/dist/lib/agent-clients/adapters/codex-lifecycle/cli.js +0 -443
- package/dist/lib/agent-clients/adapters/codex-lifecycle/evidence.js +0 -236
- package/dist/lib/agent-clients/adapters/codex-lifecycle/recovery.js +0 -292
- package/dist/lib/agent-clients/adapters/codex-lifecycle/store.js +0 -267
- package/dist/lib/agent-clients/adapters/codex-orchestration.js +0 -466
- package/dist/lib/internal/task-orchestration.js +0 -71
- package/dist/lib/platform/verification.js +0 -6
- package/dist/lib/run/prompt.js +0 -2
- package/dist/lib/sandbox/engines/authority.js +0 -289
- package/dist/lib/task/delegation-receipts.js +0 -410
- package/dist/lib/task/orchestration.js +0 -1233
- package/dist/lib/task/verification-checks.js +0 -9
- package/dist/lib/task/workspace-snapshot.js +0 -121
- package/dist/lifecycle-build-manifest.json +0 -6
- package/lib/agent-clients/adapters/codex-lifecycle/app-server.ts +0 -688
- package/lib/agent-clients/adapters/codex-lifecycle/binding.ts +0 -147
- package/lib/agent-clients/adapters/codex-lifecycle/build-identity.ts +0 -349
- package/lib/agent-clients/adapters/codex-lifecycle/cli.ts +0 -506
- package/lib/agent-clients/adapters/codex-lifecycle/evidence.ts +0 -385
- package/lib/agent-clients/adapters/codex-lifecycle/manifest-files.json +0 -41
- package/lib/agent-clients/adapters/codex-lifecycle/recovery.ts +0 -418
- package/lib/agent-clients/adapters/codex-lifecycle/store.ts +0 -354
- package/lib/agent-clients/adapters/codex-orchestration.ts +0 -630
- package/lib/internal/task-orchestration.ts +0 -74
- package/lib/platform/verification.ts +0 -11
- package/lib/run/prompt.ts +0 -1
- package/lib/sandbox/engines/authority.ts +0 -365
- package/lib/task/delegation-receipts.ts +0 -547
- package/lib/task/orchestration.ts +0 -1651
- package/lib/task/verification-checks.ts +0 -10
- package/lib/task/workspace-snapshot.ts +0 -144
- package/templates/.agents/hooks/lifecycle-delegation.js +0 -140
- package/templates/.agents/rules/lifecycle-orchestration.en.md +0 -44
- package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +0 -44
- package/templates/.agents/skills/run-task/SKILL.en.md +0 -29
- package/templates/.agents/skills/run-task/SKILL.zh-CN.md +0 -29
- package/templates/.agents/skills/run-task/config/verify.en.json +0 -10
- package/templates/.agents/skills/run-task/config/verify.zh-CN.json +0 -10
- package/templates/.agents/skills/run-task/reference/host-validation.en.md +0 -24
- package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +0 -24
- package/templates/.claude/agents/agent-infra-lifecycle-executor.en.md +0 -6
- package/templates/.claude/agents/agent-infra-lifecycle-executor.zh-CN.md +0 -6
- package/templates/.claude/agents/agent-infra-lifecycle-reviewer.en.md +0 -6
- package/templates/.claude/agents/agent-infra-lifecycle-reviewer.zh-CN.md +0 -6
- package/templates/.claude/commands/run-task.en.md +0 -8
- package/templates/.claude/commands/run-task.zh-CN.md +0 -8
- package/templates/.codex/agents/agent-infra-lifecycle-executor.en.toml +0 -3
- package/templates/.codex/agents/agent-infra-lifecycle-executor.zh-CN.toml +0 -3
- package/templates/.codex/agents/agent-infra-lifecycle-reviewer.en.toml +0 -3
- package/templates/.codex/agents/agent-infra-lifecycle-reviewer.zh-CN.toml +0 -3
- package/templates/.opencode/commands/run-task.en.md +0 -11
- package/templates/.opencode/commands/run-task.zh-CN.md +0 -11
|
@@ -1,74 +0,0 @@
|
|
|
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';
|
|
4
|
-
import { ensureInternalHandlerRoute, internalHandlerRoute } from './cli-route-inventory.ts';
|
|
5
|
-
|
|
6
|
-
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';
|
|
7
|
-
|
|
8
|
-
function usageFailure(message: string): void {
|
|
9
|
-
process.stdout.write(`${JSON.stringify({
|
|
10
|
-
status: 'failed', changed: false,
|
|
11
|
-
error: { code: 'ORCHESTRATION_PAYLOAD_INVALID', message }
|
|
12
|
-
})}\n`);
|
|
13
|
-
process.stderr.write(USAGE);
|
|
14
|
-
process.exitCode = 2;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function parseFailure(error: unknown): string {
|
|
18
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
-
return message.replace(/^TASK_CONTROL_OPERATION_INVALID: /u, '');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function taskOrchestration(args: string[] = []): Promise<void> {
|
|
23
|
-
if (args[0] === '--help' || args[0] === '-h') {
|
|
24
|
-
process.stdout.write(USAGE);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (!ensureInternalHandlerRoute('task-orchestration', args)) return;
|
|
28
|
-
|
|
29
|
-
const route = internalHandlerRoute('task-orchestration', 'status', args[1] ?? '')
|
|
30
|
-
? 'status'
|
|
31
|
-
: internalHandlerRoute('task-orchestration', 'progress', args[1] ? 'progress' : '')
|
|
32
|
-
? 'progress'
|
|
33
|
-
: '';
|
|
34
|
-
if (!route) {
|
|
35
|
-
usageFailure('orchestration operation is required');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let operation;
|
|
40
|
-
try {
|
|
41
|
-
operation = parseTaskControlOperation('task-orchestration', args);
|
|
42
|
-
} catch (error) {
|
|
43
|
-
usageFailure(parseFailure(error));
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (operation.family !== 'task-orchestration') {
|
|
47
|
-
usageFailure('orchestration operation is invalid');
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let repoRoot = process.cwd();
|
|
52
|
-
try { repoRoot = detectRepoRoot(); } catch { /* domain resolution reports the repository error */ }
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const result = await dispatchTaskControlOperation(
|
|
56
|
-
createDirectHostExecutionContext({
|
|
57
|
-
repoRoot,
|
|
58
|
-
...(process.env.AGENT_INFRA_RUNTIME_DIR ? { runtimeDir: process.env.AGENT_INFRA_RUNTIME_DIR } : {})
|
|
59
|
-
}),
|
|
60
|
-
operation
|
|
61
|
-
);
|
|
62
|
-
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
63
|
-
if (result.status === 'failed') process.exitCode = 1;
|
|
64
|
-
} catch (error) {
|
|
65
|
-
if (!(error instanceof OrchestrationStateError)) throw error;
|
|
66
|
-
process.stdout.write(`${JSON.stringify({
|
|
67
|
-
status: 'failed', changed: false, taskId: error.taskId, run: null, next: null,
|
|
68
|
-
error: { code: error.code, message: error.message }
|
|
69
|
-
})}\n`);
|
|
70
|
-
process.exitCode = 1;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { taskOrchestration };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { inspectRequiredChecks } from './pr-checks.ts';
|
|
2
|
-
|
|
3
|
-
type VerificationStatus = 'pass' | 'fail' | 'blocked';
|
|
4
|
-
type VerificationCheck = { type: string; status: VerificationStatus; message: string; fail_type?: string };
|
|
5
|
-
|
|
6
|
-
function verificationCheck(type: string, status: VerificationStatus, message: string, failType?: string): VerificationCheck {
|
|
7
|
-
return { type, status, message, ...(failType ? { fail_type: failType } : {}) };
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { inspectRequiredChecks, verificationCheck };
|
|
11
|
-
export type { VerificationCheck, VerificationStatus };
|
package/lib/run/prompt.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { renderPrompt } from './tui.ts';
|
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import type { SpawnSyncReturns } from 'node:child_process';
|
|
3
|
-
import { runProbe } from '../shell.ts';
|
|
4
|
-
import { getAdapter } from './index.ts';
|
|
5
|
-
|
|
6
|
-
export type SandboxAuthorityEvidenceV1 = Readonly<{
|
|
7
|
-
version: 1;
|
|
8
|
-
provider: string;
|
|
9
|
-
lockDomain: string;
|
|
10
|
-
routeKind: 'default' | 'context' | 'endpoint' | 'wsl2';
|
|
11
|
-
routeSelector: Readonly<Record<string, string>>;
|
|
12
|
-
normalizedEndpoint: string;
|
|
13
|
-
endpointFingerprint: string;
|
|
14
|
-
daemonIdentity: Readonly<{
|
|
15
|
-
kind: 'docker-server-id';
|
|
16
|
-
fingerprint: string;
|
|
17
|
-
}>;
|
|
18
|
-
apiVersion: Readonly<{ major: number; minor: number }>;
|
|
19
|
-
authorityFingerprint: string;
|
|
20
|
-
}>;
|
|
21
|
-
|
|
22
|
-
export type AuthorityProbe = (cmd: string, args: string[], options?: { timeout?: number }) => SpawnSyncReturns<string | Buffer>;
|
|
23
|
-
|
|
24
|
-
export type AuthorityCaptureOptions = Readonly<{
|
|
25
|
-
probe?: AuthorityProbe;
|
|
26
|
-
timeoutMs?: number;
|
|
27
|
-
env?: NodeJS.ProcessEnv;
|
|
28
|
-
lockDomain?: string;
|
|
29
|
-
route?: SandboxAuthorityEvidenceV1;
|
|
30
|
-
}>;
|
|
31
|
-
|
|
32
|
-
export type AuthorityVerification = Readonly<{
|
|
33
|
-
state: 'verified' | 'unknown' | 'conflict';
|
|
34
|
-
reason?: string;
|
|
35
|
-
}>;
|
|
36
|
-
|
|
37
|
-
function digest(value: string): string {
|
|
38
|
-
return createHash('sha256').update(value).digest('hex');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function canonical(value: unknown): string {
|
|
42
|
-
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
|
|
43
|
-
if (!value || typeof value !== 'object') return JSON.stringify(value) ?? 'null';
|
|
44
|
-
return `{${Object.entries(value as Record<string, unknown>)
|
|
45
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
46
|
-
.map(([key, entry]) => `${JSON.stringify(key)}:${canonical(entry)}`)
|
|
47
|
-
.join(',')}}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function text(value: string | Buffer | null | undefined): string {
|
|
51
|
-
return typeof value === 'string' ? value : value?.toString('utf8') ?? '';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function safeEndpoint(value: string): string {
|
|
55
|
-
if (!value) return 'docker-default';
|
|
56
|
-
try {
|
|
57
|
-
const parsed = new URL(value);
|
|
58
|
-
const hasUnreplayableParts = Boolean(parsed.username || parsed.password || parsed.search || parsed.hash);
|
|
59
|
-
parsed.username = '';
|
|
60
|
-
parsed.password = '';
|
|
61
|
-
parsed.search = '';
|
|
62
|
-
parsed.hash = '';
|
|
63
|
-
const normalized = parsed.toString().replace(/\/$/u, '');
|
|
64
|
-
return hasUnreplayableParts
|
|
65
|
-
? `${normalized}#<redacted>`
|
|
66
|
-
: normalized;
|
|
67
|
-
} catch {
|
|
68
|
-
const normalized = value
|
|
69
|
-
.replace(/\/\/[^/@]+@/u, '//<redacted>@')
|
|
70
|
-
.replace(/[?&](?:token|password|secret|key)=[^&]*/giu, '');
|
|
71
|
-
return /[@?#]/u.test(value) ? `${normalized.replace(/[?#].*$/u, '')}#<redacted>` : normalized;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function lockDomainFor(engine: string, endpoint: string): string {
|
|
76
|
-
return digest(`${process.platform}\0${process.arch}\0${engine}\0${endpoint}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type SandboxAuthorityRoute = Readonly<{
|
|
80
|
-
kind: SandboxAuthorityEvidenceV1['routeKind'];
|
|
81
|
-
selector: Readonly<Record<string, string>>;
|
|
82
|
-
endpoint: string;
|
|
83
|
-
command: (args: string[]) => { cmd: string; args: string[] };
|
|
84
|
-
}>;
|
|
85
|
-
|
|
86
|
-
function contextRoute(context: string): SandboxAuthorityRoute {
|
|
87
|
-
return {
|
|
88
|
-
kind: 'context',
|
|
89
|
-
selector: { context },
|
|
90
|
-
endpoint: `docker-context://${context}`,
|
|
91
|
-
command: (args) => ({ cmd: 'docker', args: ['--context', context, ...args] })
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function endpointRoute(endpoint: string, rawEndpoint: string, unreplayable?: string): SandboxAuthorityRoute {
|
|
96
|
-
return {
|
|
97
|
-
kind: 'endpoint',
|
|
98
|
-
selector: {
|
|
99
|
-
source: 'DOCKER_HOST',
|
|
100
|
-
endpoint,
|
|
101
|
-
...(unreplayable ? { unreplayable } : {})
|
|
102
|
-
},
|
|
103
|
-
endpoint,
|
|
104
|
-
command: (args) => ({ cmd: 'docker', args: ['--host', rawEndpoint, ...args] })
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function tlsEnvironmentReason(env: NodeJS.ProcessEnv): string | undefined {
|
|
109
|
-
return env.DOCKER_TLS_VERIFY || env.DOCKER_CERT_PATH || env.DOCKER_TLS
|
|
110
|
-
? 'tls-environment'
|
|
111
|
-
: undefined;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function routeFor(engine: string, env: NodeJS.ProcessEnv): SandboxAuthorityRoute {
|
|
115
|
-
const context = getAdapter(engine).dockerContext;
|
|
116
|
-
if (context) {
|
|
117
|
-
return contextRoute(context);
|
|
118
|
-
}
|
|
119
|
-
if (env.DOCKER_CONTEXT) {
|
|
120
|
-
return contextRoute(env.DOCKER_CONTEXT);
|
|
121
|
-
}
|
|
122
|
-
if (env.DOCKER_HOST) {
|
|
123
|
-
return endpointRoute(safeEndpoint(env.DOCKER_HOST), env.DOCKER_HOST, tlsEnvironmentReason(env));
|
|
124
|
-
}
|
|
125
|
-
return contextRoute('default');
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function validRouteName(value: string): boolean {
|
|
129
|
-
return /^[A-Za-z0-9][A-Za-z0-9_.@/-]*$/u.test(value);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function resolveWslDistro(probe: AuthorityProbe, timeoutMs?: number, explicit?: string): string {
|
|
133
|
-
if (explicit) {
|
|
134
|
-
if (!validRouteName(explicit)) throw new Error('SANDBOX_AUTHORITY_ROUTE_CAPTURE_FAILED');
|
|
135
|
-
return explicit;
|
|
136
|
-
}
|
|
137
|
-
const result = probe(
|
|
138
|
-
'wsl.exe',
|
|
139
|
-
['--list', '--verbose'],
|
|
140
|
-
timeoutMs === undefined ? {} : { timeout: timeoutMs }
|
|
141
|
-
);
|
|
142
|
-
if (result.status !== 0) throw new Error('SANDBOX_AUTHORITY_ROUTE_CAPTURE_FAILED');
|
|
143
|
-
const output = text(result.stdout).replace(/\0/gu, '').replace(/\r/gu, '');
|
|
144
|
-
const defaultLine = output.split('\n').find((line) => /^\s*\*\s+/u.test(line));
|
|
145
|
-
const distro = defaultLine?.replace(/^\s*\*\s+/u, '').replace(/\s+(?:Running|Stopped)\s+\d+\s*$/iu, '').trim();
|
|
146
|
-
if (!distro || !validRouteName(distro)) throw new Error('SANDBOX_AUTHORITY_ROUTE_CAPTURE_FAILED');
|
|
147
|
-
return distro;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function wslRoute(
|
|
151
|
-
distro: string,
|
|
152
|
-
context: string | undefined,
|
|
153
|
-
env: NodeJS.ProcessEnv
|
|
154
|
-
): SandboxAuthorityRoute {
|
|
155
|
-
const endpoint = env.DOCKER_HOST
|
|
156
|
-
? safeEndpoint(env.DOCKER_HOST)
|
|
157
|
-
: `wsl://${distro}/${context ?? 'default'}`;
|
|
158
|
-
const unreplayable = tlsEnvironmentReason(env)
|
|
159
|
-
?? (endpoint.includes('<redacted>') ? 'ambient-endpoint-secret' : undefined);
|
|
160
|
-
return {
|
|
161
|
-
kind: 'wsl2',
|
|
162
|
-
selector: {
|
|
163
|
-
distro,
|
|
164
|
-
...(context ? { context } : {}),
|
|
165
|
-
...(unreplayable ? { unreplayable } : {}),
|
|
166
|
-
...(env.DOCKER_HOST ? { endpoint } : {})
|
|
167
|
-
},
|
|
168
|
-
endpoint,
|
|
169
|
-
command: (args) => ({
|
|
170
|
-
cmd: 'wsl.exe',
|
|
171
|
-
args: [
|
|
172
|
-
'--distribution', distro,
|
|
173
|
-
'--exec', 'docker',
|
|
174
|
-
...(context ? ['--context', context] : []),
|
|
175
|
-
...(env.DOCKER_HOST ? ['--host', env.DOCKER_HOST] : []),
|
|
176
|
-
...args
|
|
177
|
-
]
|
|
178
|
-
})
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function currentWslRoute(
|
|
183
|
-
env: NodeJS.ProcessEnv,
|
|
184
|
-
probe: AuthorityProbe,
|
|
185
|
-
timeoutMs?: number
|
|
186
|
-
): SandboxAuthorityRoute {
|
|
187
|
-
const distro = resolveWslDistro(probe, timeoutMs, env.WSL_DISTRO_NAME);
|
|
188
|
-
let context = env.DOCKER_CONTEXT;
|
|
189
|
-
if (!context && !env.DOCKER_HOST) {
|
|
190
|
-
const result = probe(
|
|
191
|
-
'wsl.exe',
|
|
192
|
-
['--distribution', distro, '--exec', 'docker', 'context', 'show'],
|
|
193
|
-
timeoutMs === undefined ? {} : { timeout: timeoutMs }
|
|
194
|
-
);
|
|
195
|
-
context = text(result.stdout).trim();
|
|
196
|
-
if (result.status !== 0 || !validRouteName(context)) {
|
|
197
|
-
throw new Error('SANDBOX_AUTHORITY_ROUTE_CAPTURE_FAILED');
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return wslRoute(distro, context, env);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function routeFromEvidence(evidence: SandboxAuthorityEvidenceV1): SandboxAuthorityRoute {
|
|
204
|
-
return {
|
|
205
|
-
kind: evidence.routeKind,
|
|
206
|
-
selector: evidence.routeSelector,
|
|
207
|
-
endpoint: evidence.normalizedEndpoint,
|
|
208
|
-
command: (args) => commandForSandboxAuthority(evidence, 'docker', args)
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function currentContextRoute(
|
|
213
|
-
engine: string,
|
|
214
|
-
env: NodeJS.ProcessEnv,
|
|
215
|
-
probe: AuthorityProbe,
|
|
216
|
-
timeoutMs?: number
|
|
217
|
-
): SandboxAuthorityRoute {
|
|
218
|
-
const configured = routeFor(engine, env);
|
|
219
|
-
if (configured.kind !== 'context' || configured.selector.context !== 'default') return configured;
|
|
220
|
-
if (env.DOCKER_CONTEXT || env.DOCKER_HOST || getAdapter(engine).dockerContext) return configured;
|
|
221
|
-
const result = probe('docker', ['context', 'show'], timeoutMs === undefined ? {} : { timeout: timeoutMs });
|
|
222
|
-
const context = text(result.stdout).trim();
|
|
223
|
-
if (result.status !== 0 || !/^[A-Za-z0-9][A-Za-z0-9_.@/-]*$/u.test(context)) {
|
|
224
|
-
throw new Error('SANDBOX_AUTHORITY_ROUTE_CAPTURE_FAILED');
|
|
225
|
-
}
|
|
226
|
-
return contextRoute(context);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** Build a command using only the route persisted with the sandbox authority. */
|
|
230
|
-
export function commandForSandboxAuthority(
|
|
231
|
-
evidence: SandboxAuthorityEvidenceV1,
|
|
232
|
-
cmd: string,
|
|
233
|
-
args: string[] = []
|
|
234
|
-
): { cmd: string; args: string[] } {
|
|
235
|
-
if (cmd !== 'docker') {
|
|
236
|
-
throw new Error('SANDBOX_AUTHORITY_ROUTE_UNSUPPORTED');
|
|
237
|
-
}
|
|
238
|
-
if (evidence.routeKind === 'context') {
|
|
239
|
-
const context = evidence.routeSelector.context;
|
|
240
|
-
if (!context) throw new Error('SANDBOX_AUTHORITY_ROUTE_INVALID');
|
|
241
|
-
return { cmd, args: ['--context', context, ...args] };
|
|
242
|
-
}
|
|
243
|
-
if (evidence.routeKind === 'endpoint') {
|
|
244
|
-
const endpoint = evidence.routeSelector.endpoint;
|
|
245
|
-
if (!endpoint || endpoint.includes('<redacted>') || evidence.routeSelector.unreplayable) {
|
|
246
|
-
throw new Error('SANDBOX_AUTHORITY_ROUTE_UNREPLAYABLE');
|
|
247
|
-
}
|
|
248
|
-
return { cmd, args: ['--host', endpoint, ...args] };
|
|
249
|
-
}
|
|
250
|
-
if (evidence.routeKind === 'wsl2') {
|
|
251
|
-
const distro = evidence.routeSelector.distro;
|
|
252
|
-
const context = evidence.routeSelector.context;
|
|
253
|
-
const endpoint = evidence.routeSelector.endpoint;
|
|
254
|
-
if (!distro || evidence.routeSelector.unreplayable || endpoint?.includes('<redacted>')) {
|
|
255
|
-
throw new Error('SANDBOX_AUTHORITY_ROUTE_UNREPLAYABLE');
|
|
256
|
-
}
|
|
257
|
-
return {
|
|
258
|
-
cmd: 'wsl.exe',
|
|
259
|
-
args: [
|
|
260
|
-
'--distribution', distro,
|
|
261
|
-
'--exec', cmd,
|
|
262
|
-
...(context ? ['--context', context] : []),
|
|
263
|
-
...(endpoint && !endpoint.startsWith('wsl://') ? ['--host', endpoint] : []),
|
|
264
|
-
...args
|
|
265
|
-
]
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
return { cmd, args: ['--context', 'default', ...args] };
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export function authorityVersionArgs(): string[] {
|
|
272
|
-
return ['version', '--format', '{{json .Server}}'];
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function captureSandboxAuthority(
|
|
276
|
-
engine: string,
|
|
277
|
-
options: AuthorityCaptureOptions = {}
|
|
278
|
-
): SandboxAuthorityEvidenceV1 {
|
|
279
|
-
const env = options.env ?? process.env;
|
|
280
|
-
const probe = options.probe ?? runProbe;
|
|
281
|
-
const route = options.route
|
|
282
|
-
? routeFromEvidence(options.route)
|
|
283
|
-
: engine === 'wsl2'
|
|
284
|
-
? currentWslRoute(env, probe, options.timeoutMs)
|
|
285
|
-
: currentContextRoute(engine, env, probe, options.timeoutMs);
|
|
286
|
-
function probeJson(args: string[]): unknown {
|
|
287
|
-
const command = options.route
|
|
288
|
-
? commandForSandboxAuthority(options.route, 'docker', args)
|
|
289
|
-
: route.command(args);
|
|
290
|
-
try {
|
|
291
|
-
const response = probe(
|
|
292
|
-
command.cmd,
|
|
293
|
-
command.args,
|
|
294
|
-
options.timeoutMs === undefined ? {} : { timeout: options.timeoutMs }
|
|
295
|
-
);
|
|
296
|
-
if (response.status !== 0) throw new Error('SANDBOX_AUTHORITY_CAPTURE_FAILED');
|
|
297
|
-
return JSON.parse(text(response.stdout).trim());
|
|
298
|
-
} catch {
|
|
299
|
-
throw new Error('SANDBOX_AUTHORITY_CAPTURE_FAILED');
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
const server = probeJson(authorityVersionArgs());
|
|
303
|
-
if (!server || typeof server !== 'object' || Array.isArray(server)) {
|
|
304
|
-
throw new Error('SANDBOX_AUTHORITY_CAPTURE_FAILED');
|
|
305
|
-
}
|
|
306
|
-
const record = server as Record<string, unknown>;
|
|
307
|
-
const api = typeof record.ApiVersion === 'string' ? /^(\d+)\.(\d+)$/u.exec(record.ApiVersion) : null;
|
|
308
|
-
if (!api) throw new Error('SANDBOX_AUTHORITY_CAPTURE_FAILED');
|
|
309
|
-
// Docker version exposes API metadata; the daemon ID belongs to Docker info.
|
|
310
|
-
const serverId = probeJson(['info', '--format', '{{json .ID}}']);
|
|
311
|
-
if (typeof serverId !== 'string' || !serverId.trim()) throw new Error('SANDBOX_AUTHORITY_CAPTURE_FAILED');
|
|
312
|
-
const normalizedEndpoint = route.endpoint;
|
|
313
|
-
const evidenceWithoutFingerprint = {
|
|
314
|
-
version: 1 as const,
|
|
315
|
-
provider: engine,
|
|
316
|
-
lockDomain: options.lockDomain ?? options.route?.lockDomain ?? lockDomainFor(engine, normalizedEndpoint),
|
|
317
|
-
routeKind: route.kind,
|
|
318
|
-
routeSelector: route.selector,
|
|
319
|
-
normalizedEndpoint,
|
|
320
|
-
endpointFingerprint: digest(normalizedEndpoint),
|
|
321
|
-
daemonIdentity: { kind: 'docker-server-id' as const, fingerprint: digest(serverId) },
|
|
322
|
-
apiVersion: { major: Number(api[1]), minor: Number(api[2]) }
|
|
323
|
-
};
|
|
324
|
-
return {
|
|
325
|
-
...evidenceWithoutFingerprint,
|
|
326
|
-
authorityFingerprint: digest(canonical(evidenceWithoutFingerprint))
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export function verifySandboxAuthority(
|
|
331
|
-
expected: SandboxAuthorityEvidenceV1 | null | undefined,
|
|
332
|
-
actual: SandboxAuthorityEvidenceV1 | null
|
|
333
|
-
): AuthorityVerification {
|
|
334
|
-
if (!expected) return { state: 'unknown', reason: 'SANDBOX_AUTHORITY_EVIDENCE_MISSING' };
|
|
335
|
-
if (!actual) return { state: 'unknown', reason: 'SANDBOX_AUTHORITY_UNAVAILABLE' };
|
|
336
|
-
if (expected.authorityFingerprint !== actual.authorityFingerprint
|
|
337
|
-
|| expected.lockDomain !== actual.lockDomain
|
|
338
|
-
|| expected.routeKind !== actual.routeKind
|
|
339
|
-
|| expected.endpointFingerprint !== actual.endpointFingerprint
|
|
340
|
-
|| expected.daemonIdentity.fingerprint !== actual.daemonIdentity.fingerprint) {
|
|
341
|
-
return { state: 'conflict', reason: 'SANDBOX_AUTHORITY_DRIFT' };
|
|
342
|
-
}
|
|
343
|
-
return { state: 'verified' };
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export function isSandboxAuthorityEvidence(value: unknown): value is SandboxAuthorityEvidenceV1 {
|
|
347
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
348
|
-
const evidence = value as Record<string, unknown>;
|
|
349
|
-
const selector = evidence.routeSelector as Record<string, unknown> | null;
|
|
350
|
-
const daemon = evidence.daemonIdentity as Record<string, unknown> | null;
|
|
351
|
-
const api = evidence.apiVersion as Record<string, unknown> | null;
|
|
352
|
-
return evidence.version === 1
|
|
353
|
-
&& typeof evidence.provider === 'string'
|
|
354
|
-
&& /^[a-f0-9]{64}$/u.test(evidence.lockDomain as string)
|
|
355
|
-
&& ['default', 'context', 'endpoint', 'wsl2'].includes(evidence.routeKind as string)
|
|
356
|
-
&& !!selector && typeof selector === 'object' && !Array.isArray(selector)
|
|
357
|
-
&& Object.values(selector).every((entry) => typeof entry === 'string')
|
|
358
|
-
&& typeof evidence.normalizedEndpoint === 'string'
|
|
359
|
-
&& /^[a-f0-9]{64}$/u.test(evidence.endpointFingerprint as string)
|
|
360
|
-
&& !!daemon && daemon.kind === 'docker-server-id'
|
|
361
|
-
&& /^[a-f0-9]{64}$/u.test(daemon.fingerprint as string)
|
|
362
|
-
&& !!api && Number.isSafeInteger(api.major) && (api.major as number) >= 0
|
|
363
|
-
&& Number.isSafeInteger(api.minor) && (api.minor as number) >= 0
|
|
364
|
-
&& /^[a-f0-9]{64}$/u.test(evidence.authorityFingerprint as string);
|
|
365
|
-
}
|