@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,114 +0,0 @@
|
|
|
1
|
-
import { managedDelegationRole } from '../../../task/delegation-receipts.js';
|
|
2
|
-
const MARKER_PREFIX = '__agent_infra_binding_';
|
|
3
|
-
const BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
|
|
4
|
-
const TASK_ID_PATTERN = /^TASK-[0-9]{8}-[0-9]{6}$/u;
|
|
5
|
-
const SAFE_LABEL_PATTERN = /^[a-z0-9_]{1,80}$/u;
|
|
6
|
-
const SAFE_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/u;
|
|
7
|
-
function assertSafeTaskName(taskName) {
|
|
8
|
-
if (Buffer.byteLength(taskName, 'utf8') > 255 || !/^[a-z0-9_]+$/u.test(taskName)) {
|
|
9
|
-
throw new Error('Codex task_name must use lowercase letters, digits, and underscores within 255 bytes');
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function encodeTaskNamePayload(value) {
|
|
13
|
-
let buffer = 0;
|
|
14
|
-
let bits = 0;
|
|
15
|
-
let encoded = '';
|
|
16
|
-
for (const byte of Buffer.from(value, 'utf8')) {
|
|
17
|
-
buffer = (buffer << 8) | byte;
|
|
18
|
-
bits += 8;
|
|
19
|
-
while (bits >= 5) {
|
|
20
|
-
encoded += BASE32_ALPHABET[(buffer >>> (bits - 5)) & 31];
|
|
21
|
-
bits -= 5;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (bits)
|
|
25
|
-
encoded += BASE32_ALPHABET[(buffer << (5 - bits)) & 31];
|
|
26
|
-
return encoded;
|
|
27
|
-
}
|
|
28
|
-
function decodeTaskNamePayload(encoded) {
|
|
29
|
-
let buffer = 0;
|
|
30
|
-
let bits = 0;
|
|
31
|
-
const bytes = [];
|
|
32
|
-
for (const character of encoded) {
|
|
33
|
-
const value = BASE32_ALPHABET.indexOf(character);
|
|
34
|
-
if (value < 0)
|
|
35
|
-
return null;
|
|
36
|
-
buffer = (buffer << 5) | value;
|
|
37
|
-
bits += 5;
|
|
38
|
-
if (bits >= 8) {
|
|
39
|
-
bytes.push((buffer >>> (bits - 8)) & 255);
|
|
40
|
-
bits -= 8;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (bits && (buffer & ((1 << bits) - 1)) !== 0)
|
|
44
|
-
return null;
|
|
45
|
-
const decoded = Buffer.from(bytes).toString('utf8');
|
|
46
|
-
return encodeTaskNamePayload(decoded) === encoded ? decoded : null;
|
|
47
|
-
}
|
|
48
|
-
function encodeCodexLifecycleBinding(binding) {
|
|
49
|
-
if (!TASK_ID_PATTERN.test(binding.taskId)
|
|
50
|
-
|| !SAFE_ID_PATTERN.test(binding.runId)
|
|
51
|
-
|| !SAFE_ID_PATTERN.test(binding.receiptId)) {
|
|
52
|
-
throw new Error('Codex lifecycle task binding is invalid');
|
|
53
|
-
}
|
|
54
|
-
return `${MARKER_PREFIX}${encodeTaskNamePayload(JSON.stringify(binding))}`;
|
|
55
|
-
}
|
|
56
|
-
function appendCodexLifecycleBinding(label, binding) {
|
|
57
|
-
if (!SAFE_LABEL_PATTERN.test(label))
|
|
58
|
-
throw new Error('Codex task_name label is invalid');
|
|
59
|
-
const taskName = `${label}${encodeCodexLifecycleBinding(binding)}`;
|
|
60
|
-
assertSafeTaskName(taskName);
|
|
61
|
-
return taskName;
|
|
62
|
-
}
|
|
63
|
-
function parseCodexLifecycleBinding(taskName) {
|
|
64
|
-
assertSafeTaskName(taskName);
|
|
65
|
-
const markerIndex = taskName.lastIndexOf(MARKER_PREFIX);
|
|
66
|
-
if (markerIndex < 1)
|
|
67
|
-
return null;
|
|
68
|
-
const label = taskName.slice(0, markerIndex);
|
|
69
|
-
const encoded = taskName.slice(markerIndex + MARKER_PREFIX.length);
|
|
70
|
-
if (!SAFE_LABEL_PATTERN.test(label) || !/^[a-z2-7]+$/u.test(encoded))
|
|
71
|
-
return null;
|
|
72
|
-
try {
|
|
73
|
-
const decoded = decodeTaskNamePayload(encoded);
|
|
74
|
-
if (!decoded)
|
|
75
|
-
return null;
|
|
76
|
-
const value = JSON.parse(decoded);
|
|
77
|
-
if (Object.keys(value).sort().join(',') !== 'receiptId,runId,taskId'
|
|
78
|
-
|| typeof value.taskId !== 'string' || !TASK_ID_PATTERN.test(value.taskId)
|
|
79
|
-
|| typeof value.runId !== 'string' || !SAFE_ID_PATTERN.test(value.runId)
|
|
80
|
-
|| typeof value.receiptId !== 'string' || !SAFE_ID_PATTERN.test(value.receiptId))
|
|
81
|
-
return null;
|
|
82
|
-
return Object.freeze({
|
|
83
|
-
taskName,
|
|
84
|
-
label,
|
|
85
|
-
binding: Object.freeze({ taskId: value.taskId, runId: value.runId, receiptId: value.receiptId })
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function verifyCodexLifecycleTaskBinding(binding, run, nativeAgent, expected = {}) {
|
|
93
|
-
if (!codexReceiptMatchesBinding(binding, run, nativeAgent, expected)) {
|
|
94
|
-
throw new Error('Codex lifecycle task binding does not match the current pending receipt');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function codexReceiptMatchesBinding(binding, run, nativeAgent, expected) {
|
|
98
|
-
const receipt = run.pendingDelegation;
|
|
99
|
-
return Boolean(receipt)
|
|
100
|
-
&& run.status === 'running'
|
|
101
|
-
&& run.runId === binding.runId
|
|
102
|
-
&& receipt.runId === binding.runId
|
|
103
|
-
&& receipt.id === binding.receiptId
|
|
104
|
-
&& receipt.client === 'codex'
|
|
105
|
-
&& receipt.status === 'prepared'
|
|
106
|
-
&& managedDelegationRole(nativeAgent) === receipt.role
|
|
107
|
-
&& requestedBindingMatches(receipt, expected);
|
|
108
|
-
}
|
|
109
|
-
function requestedBindingMatches(receipt, expected) {
|
|
110
|
-
return (!expected.requestedModel || receipt.requestedModel === expected.requestedModel)
|
|
111
|
-
&& (!expected.requestedReasoningEffort || receipt.requestedReasoningEffort === expected.requestedReasoningEffort);
|
|
112
|
-
}
|
|
113
|
-
export { appendCodexLifecycleBinding, encodeCodexLifecycleBinding, parseCodexLifecycleBinding, verifyCodexLifecycleTaskBinding };
|
|
114
|
-
//# sourceMappingURL=binding.js.map
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import crypto from 'node:crypto';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import semver from 'semver';
|
|
6
|
-
const LIFECYCLE_PROTOCOL_VERSION = 3;
|
|
7
|
-
function exactText(value) {
|
|
8
|
-
return typeof value === 'string' && value.trim() === value && value.length > 0;
|
|
9
|
-
}
|
|
10
|
-
function isCanonicalLifecyclePackageVersion(value) {
|
|
11
|
-
return typeof value === 'string' && semver.valid(value) === value;
|
|
12
|
-
}
|
|
13
|
-
function isLifecycleProtocolVersion(value) {
|
|
14
|
-
return value === LIFECYCLE_PROTOCOL_VERSION;
|
|
15
|
-
}
|
|
16
|
-
function normalizeRelativePath(value) {
|
|
17
|
-
return value.replaceAll('\\', '/');
|
|
18
|
-
}
|
|
19
|
-
function isSafeLifecyclePath(value) {
|
|
20
|
-
return exactText(value)
|
|
21
|
-
&& value === normalizeRelativePath(value)
|
|
22
|
-
&& !path.isAbsolute(value)
|
|
23
|
-
&& !/^[A-Za-z]:[\\/]/u.test(value)
|
|
24
|
-
&& !value.split('/').includes('..');
|
|
25
|
-
}
|
|
26
|
-
function isLifecycleLauncherLine(value) {
|
|
27
|
-
return typeof value === 'string'
|
|
28
|
-
&& value.length > 1
|
|
29
|
-
&& value.slice(0, -1).trim() === value.slice(0, -1)
|
|
30
|
-
&& value.startsWith('#!')
|
|
31
|
-
&& value.endsWith('\n')
|
|
32
|
-
&& value.indexOf('\n') === value.length - 1
|
|
33
|
-
&& !value.includes('\r');
|
|
34
|
-
}
|
|
35
|
-
function readLifecycleLauncherShebang(value, executableFiles) {
|
|
36
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
37
|
-
throw new Error('Lifecycle manifest launcher shebang policy is invalid');
|
|
38
|
-
}
|
|
39
|
-
const policy = value;
|
|
40
|
-
if (!isSafeLifecyclePath(policy.sourceFile)
|
|
41
|
-
|| !isSafeLifecyclePath(policy.compiledFile)
|
|
42
|
-
|| !isLifecycleLauncherLine(policy.canonicalLine)
|
|
43
|
-
|| !Array.isArray(policy.acceptedLines)
|
|
44
|
-
|| !policy.acceptedLines.every(isLifecycleLauncherLine)
|
|
45
|
-
|| new Set(policy.acceptedLines).size !== policy.acceptedLines.length
|
|
46
|
-
|| !policy.acceptedLines.includes(policy.canonicalLine)
|
|
47
|
-
|| !executableFiles.includes(policy.sourceFile)
|
|
48
|
-
|| policy.compiledFile !== normalizeRelativePath(path.join('dist', policy.sourceFile.endsWith('.ts')
|
|
49
|
-
? policy.sourceFile.replace(/\.ts$/u, '.js')
|
|
50
|
-
: policy.sourceFile))) {
|
|
51
|
-
throw new Error('Lifecycle manifest launcher shebang policy is invalid');
|
|
52
|
-
}
|
|
53
|
-
return Object.freeze({
|
|
54
|
-
sourceFile: policy.sourceFile,
|
|
55
|
-
compiledFile: policy.compiledFile,
|
|
56
|
-
canonicalLine: policy.canonicalLine,
|
|
57
|
-
acceptedLines: Object.freeze([...policy.acceptedLines])
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function readLifecycleManifestFiles(packageRoot) {
|
|
61
|
-
const file = path.join(packageRoot, 'lib', 'agent-clients', 'adapters', 'codex-lifecycle', 'manifest-files.json');
|
|
62
|
-
const value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
63
|
-
if (!Array.isArray(value.executableFiles)
|
|
64
|
-
|| !Array.isArray(value.contractFiles)
|
|
65
|
-
|| !value.executableFiles.every(isSafeLifecyclePath)
|
|
66
|
-
|| !value.contractFiles.every(isSafeLifecyclePath)
|
|
67
|
-
|| new Set(value.executableFiles).size !== value.executableFiles.length
|
|
68
|
-
|| new Set(value.contractFiles).size !== value.contractFiles.length) {
|
|
69
|
-
throw new Error('Lifecycle manifest file list is invalid');
|
|
70
|
-
}
|
|
71
|
-
const executableFiles = Object.freeze([...value.executableFiles]);
|
|
72
|
-
return Object.freeze({
|
|
73
|
-
executableFiles,
|
|
74
|
-
contractFiles: Object.freeze([...value.contractFiles]),
|
|
75
|
-
launcherShebang: readLifecycleLauncherShebang(value.launcherShebang, executableFiles)
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function executablePackageRoot() {
|
|
79
|
-
let current = path.dirname(fileURLToPath(import.meta.url));
|
|
80
|
-
while (true) {
|
|
81
|
-
const candidate = path.join(current, 'package.json');
|
|
82
|
-
if (fs.existsSync(candidate)) {
|
|
83
|
-
const value = JSON.parse(fs.readFileSync(candidate, 'utf8'));
|
|
84
|
-
if (value.name === '@fitlab-ai/agent-infra')
|
|
85
|
-
return current;
|
|
86
|
-
}
|
|
87
|
-
const parent = path.dirname(current);
|
|
88
|
-
if (parent === current)
|
|
89
|
-
throw new Error('Lifecycle executable package root is unavailable');
|
|
90
|
-
current = parent;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function normalizeLifecycleLauncherBytes(relative, content, policy) {
|
|
94
|
-
const normalized = normalizeRelativePath(relative);
|
|
95
|
-
if (normalized !== policy.sourceFile && normalized !== policy.compiledFile)
|
|
96
|
-
return content;
|
|
97
|
-
const lineEnd = content.indexOf(0x0a);
|
|
98
|
-
if (lineEnd < 0)
|
|
99
|
-
return content;
|
|
100
|
-
const firstLine = content.subarray(0, lineEnd + 1);
|
|
101
|
-
if (!policy.acceptedLines.some((line) => Buffer.from(line).equals(firstLine)))
|
|
102
|
-
return content;
|
|
103
|
-
return Buffer.concat([
|
|
104
|
-
Buffer.from(policy.canonicalLine),
|
|
105
|
-
content.subarray(lineEnd + 1)
|
|
106
|
-
]);
|
|
107
|
-
}
|
|
108
|
-
function hashFiles(root, files, launcherShebang) {
|
|
109
|
-
const hash = crypto.createHash('sha256');
|
|
110
|
-
for (const relative of [...new Set(files.map(normalizeRelativePath))].sort()) {
|
|
111
|
-
if (path.isAbsolute(relative) || relative.split(/[\\/]/u).includes('..')) {
|
|
112
|
-
throw new Error(`Lifecycle manifest path '${relative}' is unsafe`);
|
|
113
|
-
}
|
|
114
|
-
const file = path.join(root, relative);
|
|
115
|
-
const stat = fs.lstatSync(file);
|
|
116
|
-
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
117
|
-
throw new Error(`Lifecycle manifest entry '${relative}' must be a regular file`);
|
|
118
|
-
}
|
|
119
|
-
hash.update(relative);
|
|
120
|
-
hash.update('\0');
|
|
121
|
-
const content = fs.readFileSync(file);
|
|
122
|
-
hash.update(launcherShebang
|
|
123
|
-
? normalizeLifecycleLauncherBytes(relative, content, launcherShebang)
|
|
124
|
-
: content);
|
|
125
|
-
hash.update('\0');
|
|
126
|
-
}
|
|
127
|
-
return hash.digest('hex');
|
|
128
|
-
}
|
|
129
|
-
function resolveLifecycleExecutableFiles(root, entries) {
|
|
130
|
-
const pending = [...entries];
|
|
131
|
-
const resolved = new Set();
|
|
132
|
-
while (pending.length > 0) {
|
|
133
|
-
const relative = normalizeRelativePath(pending.pop());
|
|
134
|
-
if (resolved.has(relative))
|
|
135
|
-
continue;
|
|
136
|
-
resolved.add(relative);
|
|
137
|
-
if (!/\.[cm]?[jt]s$/u.test(relative))
|
|
138
|
-
continue;
|
|
139
|
-
const file = path.join(root, relative);
|
|
140
|
-
const source = fs.readFileSync(file, 'utf8');
|
|
141
|
-
const imports = source.matchAll(/(?:\bfrom\s*|\bimport\s*(?:\(\s*)?)["'](\.[^"']+)["']/gu);
|
|
142
|
-
for (const match of imports) {
|
|
143
|
-
const requested = match[1];
|
|
144
|
-
const base = path.resolve(path.dirname(file), requested);
|
|
145
|
-
const candidates = [
|
|
146
|
-
base,
|
|
147
|
-
`${base}.ts`, `${base}.js`,
|
|
148
|
-
path.join(base, 'index.ts'), path.join(base, 'index.js')
|
|
149
|
-
];
|
|
150
|
-
const dependency = candidates.find((candidate) => fs.existsSync(candidate) && fs.lstatSync(candidate).isFile());
|
|
151
|
-
if (!dependency)
|
|
152
|
-
throw new Error(`Lifecycle executable dependency '${requested}' from '${relative}' is unavailable`);
|
|
153
|
-
const dependencyRelative = path.relative(root, dependency);
|
|
154
|
-
if (dependencyRelative.startsWith('..') || path.isAbsolute(dependencyRelative)) {
|
|
155
|
-
throw new Error(`Lifecycle executable dependency '${requested}' escapes the package root`);
|
|
156
|
-
}
|
|
157
|
-
pending.push(normalizeRelativePath(dependencyRelative));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return [...resolved].sort();
|
|
161
|
-
}
|
|
162
|
-
function computeLifecycleBuildIdentity(repoRoot, options = {}) {
|
|
163
|
-
const packageRoot = executablePackageRoot();
|
|
164
|
-
const executableRoot = options.executableFiles ? repoRoot : packageRoot;
|
|
165
|
-
const defaults = readLifecycleManifestFiles(packageRoot);
|
|
166
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(executableRoot, 'package.json'), 'utf8'));
|
|
167
|
-
if (!exactText(packageJson.version))
|
|
168
|
-
throw new Error('Lifecycle package version is invalid');
|
|
169
|
-
let internalExecutableBuildHash;
|
|
170
|
-
if (options.executableFiles) {
|
|
171
|
-
internalExecutableBuildHash = hashFiles(repoRoot, options.executableFiles, defaults.launcherShebang);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
const manifestFile = path.join(executableRoot, 'dist', 'lifecycle-build-manifest.json');
|
|
175
|
-
if (fs.existsSync(manifestFile)) {
|
|
176
|
-
const manifest = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
|
|
177
|
-
if (manifest.protocolVersion !== LIFECYCLE_PROTOCOL_VERSION
|
|
178
|
-
|| manifest.packageVersion !== packageJson.version
|
|
179
|
-
|| !exactText(manifest.sourceInputHash)
|
|
180
|
-
|| !exactText(manifest.internalExecutableBuildHash)) {
|
|
181
|
-
throw new Error('Lifecycle executable build manifest is stale or invalid');
|
|
182
|
-
}
|
|
183
|
-
if (fileURLToPath(import.meta.url).split(path.sep).includes('dist')) {
|
|
184
|
-
const compiledFiles = defaults.executableFiles.map((file) => file.endsWith('.ts') ? path.join('dist', file.replace(/\.ts$/u, '.js')) : file);
|
|
185
|
-
if (hashFiles(executableRoot, resolveLifecycleExecutableFiles(executableRoot, compiledFiles), defaults.launcherShebang) !== manifest.internalExecutableBuildHash) {
|
|
186
|
-
throw new Error('Lifecycle compiled executable build does not match its manifest');
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else if (hashFiles(executableRoot, resolveLifecycleExecutableFiles(executableRoot, defaults.executableFiles), defaults.launcherShebang) !== manifest.sourceInputHash) {
|
|
190
|
-
throw new Error('Lifecycle executable build manifest is stale or invalid');
|
|
191
|
-
}
|
|
192
|
-
internalExecutableBuildHash = manifest.internalExecutableBuildHash;
|
|
193
|
-
}
|
|
194
|
-
else
|
|
195
|
-
internalExecutableBuildHash = hashFiles(executableRoot, resolveLifecycleExecutableFiles(executableRoot, defaults.executableFiles), defaults.launcherShebang);
|
|
196
|
-
}
|
|
197
|
-
return Object.freeze({
|
|
198
|
-
protocolVersion: LIFECYCLE_PROTOCOL_VERSION,
|
|
199
|
-
packageVersion: packageJson.version,
|
|
200
|
-
internalExecutableBuildHash,
|
|
201
|
-
lifecycleContractHash: hashFiles(repoRoot, options.contractFiles ?? defaults.contractFiles)
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
function verifyLifecycleBuildIdentity(expected, actual) {
|
|
205
|
-
if (actual.protocolVersion !== expected.protocolVersion) {
|
|
206
|
-
return {
|
|
207
|
-
ok: false,
|
|
208
|
-
code: 'CODEX_LIFECYCLE_PROTOCOL_MISMATCH',
|
|
209
|
-
message: 'Codex lifecycle protocol version does not match',
|
|
210
|
-
warnings: []
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
const warnings = [];
|
|
214
|
-
if (actual.packageVersion !== expected.packageVersion
|
|
215
|
-
|| actual.internalExecutableBuildHash !== expected.internalExecutableBuildHash) {
|
|
216
|
-
warnings.push({
|
|
217
|
-
code: 'CODEX_LIFECYCLE_BUILD_MISMATCH',
|
|
218
|
-
message: 'Codex lifecycle executable build identity differs; rebuild the sandbox if the runtime is stale',
|
|
219
|
-
action: 'rebuild-sandbox'
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
if (actual.lifecycleContractHash !== expected.lifecycleContractHash) {
|
|
223
|
-
warnings.push({
|
|
224
|
-
code: 'CODEX_LIFECYCLE_CONTRACT_MISMATCH',
|
|
225
|
-
message: 'Codex lifecycle contract identity differs; rebuild the sandbox if the runtime is stale',
|
|
226
|
-
action: 'rebuild-sandbox'
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
return {
|
|
230
|
-
ok: true,
|
|
231
|
-
code: null,
|
|
232
|
-
message: null,
|
|
233
|
-
warnings: Object.freeze(warnings)
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
export { LIFECYCLE_PROTOCOL_VERSION, computeLifecycleBuildIdentity, isCanonicalLifecyclePackageVersion, isLifecycleProtocolVersion, readLifecycleManifestFiles, resolveLifecycleExecutableFiles, verifyLifecycleBuildIdentity };
|
|
237
|
-
//# sourceMappingURL=build-identity.js.map
|