@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,354 +0,0 @@
|
|
|
1
|
-
import crypto from 'node:crypto';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
mutateDelegationAdapterEvidence,
|
|
6
|
-
readRun
|
|
7
|
-
} from '../../../task/orchestration.ts';
|
|
8
|
-
import type { DelegationReceipt } from '../../../task/delegation-receipts.ts';
|
|
9
|
-
import { resolveTaskRef } from '../../../task/resolve-ref.ts';
|
|
10
|
-
import {
|
|
11
|
-
createCodexLifecycleState,
|
|
12
|
-
expireCodexLifecycleState,
|
|
13
|
-
reduceCodexLifecycleEvent
|
|
14
|
-
} from './evidence.ts';
|
|
15
|
-
import type { CodexLifecycleEvent, CodexLifecycleState } from './evidence.ts';
|
|
16
|
-
import type { CodexLifecycleTaskBinding } from './binding.ts';
|
|
17
|
-
|
|
18
|
-
type StoredCodexLifecycle = Readonly<{
|
|
19
|
-
schemaVersion: 2;
|
|
20
|
-
revision: number;
|
|
21
|
-
taskBinding: CodexLifecycleTaskBinding | null;
|
|
22
|
-
state: CodexLifecycleState;
|
|
23
|
-
consumer: string | null;
|
|
24
|
-
consumedAt: string | null;
|
|
25
|
-
spawnObservedAt: string | null;
|
|
26
|
-
updatedAt: string;
|
|
27
|
-
}>;
|
|
28
|
-
|
|
29
|
-
type CodexLifecycleActivationEvidence = Readonly<{
|
|
30
|
-
kind: 'codex-lifecycle-v2';
|
|
31
|
-
hookDefinitionHash: string;
|
|
32
|
-
startRevision: number;
|
|
33
|
-
protocolVersion?: number;
|
|
34
|
-
packageVersion?: string;
|
|
35
|
-
internalExecutableBuildHash?: string;
|
|
36
|
-
lifecycleContractHash?: string;
|
|
37
|
-
hookSource?: 'project' | 'managed';
|
|
38
|
-
hookSourcePathDigest?: string;
|
|
39
|
-
hookSourceHash?: string;
|
|
40
|
-
capabilitySessionId?: string;
|
|
41
|
-
capabilityTurnId?: string;
|
|
42
|
-
spawnToolUseId?: string;
|
|
43
|
-
spawnObservedAt?: string;
|
|
44
|
-
}>;
|
|
45
|
-
|
|
46
|
-
type CodexAdapterState = Readonly<{
|
|
47
|
-
records: Readonly<Record<string, StoredCodexLifecycle>>;
|
|
48
|
-
activationEvidence?: CodexLifecycleActivationEvidence;
|
|
49
|
-
}>;
|
|
50
|
-
|
|
51
|
-
type CodexLifecycleStoreOptions = Readonly<{
|
|
52
|
-
repoRoot?: string;
|
|
53
|
-
taskId: string;
|
|
54
|
-
cliVersion: string;
|
|
55
|
-
now?: () => string;
|
|
56
|
-
}>;
|
|
57
|
-
|
|
58
|
-
type CodexLifecycleStoreResult = Readonly<{
|
|
59
|
-
path: string;
|
|
60
|
-
revision: number;
|
|
61
|
-
state: CodexLifecycleState;
|
|
62
|
-
}>;
|
|
63
|
-
|
|
64
|
-
type ActiveCodexLifecycleEvidenceQuery = Readonly<{
|
|
65
|
-
hookDefinitionHash: string;
|
|
66
|
-
identity?: Readonly<{ sessionId: string; turnId: string; toolUseId: string }>;
|
|
67
|
-
}>;
|
|
68
|
-
|
|
69
|
-
function readCodexLifecycleActivationEvidence(receipt: DelegationReceipt): CodexLifecycleActivationEvidence | null {
|
|
70
|
-
const state = storedEvidence(receipt.adapterEvidence?.codex);
|
|
71
|
-
return state.activationEvidence && typeof state.activationEvidence === 'object'
|
|
72
|
-
? state.activationEvidence
|
|
73
|
-
: null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const NON_PERSISTENT_FAILURES = new Set([
|
|
77
|
-
'CODEX_EVIDENCE_IDENTITY_MISMATCH',
|
|
78
|
-
'CODEX_EVIDENCE_PARENT_MISMATCH',
|
|
79
|
-
'CODEX_EVIDENCE_REPLAY_CONFLICT'
|
|
80
|
-
]);
|
|
81
|
-
|
|
82
|
-
function recordKey(sessionId: string, turnId: string, toolUseId: string): string {
|
|
83
|
-
return crypto.createHash('sha256').update(`${sessionId}\0${turnId}\0${toolUseId}`).digest('hex');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
87
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function storedEvidence(value: unknown): CodexAdapterState {
|
|
91
|
-
if (!isRecord(value) || !isRecord(value.records)) return Object.freeze({ records: Object.freeze({}) });
|
|
92
|
-
return value as unknown as CodexAdapterState;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function receipts(taskDir: string): readonly DelegationReceipt[] {
|
|
96
|
-
const run = readRun(taskDir);
|
|
97
|
-
return run ? Object.freeze([...run.receipts, ...(run.pendingDelegation ? [run.pendingDelegation] : [])]) : [];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function allRecords(taskDir: string): readonly StoredCodexLifecycle[] {
|
|
101
|
-
return Object.freeze(receipts(taskDir).flatMap((receipt) => {
|
|
102
|
-
const state = storedEvidence(receipt.adapterEvidence?.codex);
|
|
103
|
-
return Object.values(state.records);
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function lifecyclePath(taskDir: string): string {
|
|
108
|
-
return path.join(taskDir, '.runtime', 'orchestration.json');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function assertCurrentCanApply(
|
|
112
|
-
current: StoredCodexLifecycle,
|
|
113
|
-
binding: CodexLifecycleTaskBinding | null
|
|
114
|
-
): void {
|
|
115
|
-
if (current.revision > 0 && binding && JSON.stringify(current.taskBinding) !== JSON.stringify(binding)) {
|
|
116
|
-
throw new Error('Codex lifecycle task binding does not match the stored spawn');
|
|
117
|
-
}
|
|
118
|
-
if (current.consumer) throw new Error(`Codex lifecycle evidence was already consumed by '${current.consumer}'`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function hasActiveCodexLifecycleEvidence(
|
|
122
|
-
taskDir: string,
|
|
123
|
-
query: ActiveCodexLifecycleEvidenceQuery
|
|
124
|
-
): boolean {
|
|
125
|
-
return allRecords(taskDir).some((record) => {
|
|
126
|
-
return record.consumer === null
|
|
127
|
-
&& !['invalid', 'expired'].includes(record.state.status)
|
|
128
|
-
&& record.state.spawn?.hookDefinitionHash === query.hookDefinitionHash
|
|
129
|
-
&& (!query.identity || record.state.spawn?.sessionId === query.identity.sessionId
|
|
130
|
-
&& record.state.spawn.turnId === query.identity.turnId
|
|
131
|
-
&& record.state.spawn.toolUseId === query.identity.toolUseId);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function createCodexLifecycleStore(options: CodexLifecycleStoreOptions) {
|
|
136
|
-
if (!/^TASK-[0-9]{8}-[0-9]{6}$/u.test(options.taskId)) {
|
|
137
|
-
throw new Error('Codex lifecycle store task id is invalid');
|
|
138
|
-
}
|
|
139
|
-
const repoRoot = options.repoRoot ?? process.cwd();
|
|
140
|
-
const resolved = resolveTaskRef(options.taskId, { repoRoot });
|
|
141
|
-
if (!resolved.ok) throw new Error(`${resolved.code}: ${resolved.message}`);
|
|
142
|
-
const taskDir = resolved.taskDir;
|
|
143
|
-
const now = options.now ?? (() => new Date().toISOString());
|
|
144
|
-
|
|
145
|
-
function currentBinding(): CodexLifecycleTaskBinding {
|
|
146
|
-
const run = readRun(taskDir);
|
|
147
|
-
const receipt = run?.pendingDelegation;
|
|
148
|
-
if (!run || !receipt || receipt.client !== 'codex') {
|
|
149
|
-
throw new Error('Codex lifecycle evidence has no current task delegation');
|
|
150
|
-
}
|
|
151
|
-
return Object.freeze({ taskId: receipt.taskId, runId: receipt.runId, receiptId: receipt.id });
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function findByChild(childThreadId: string): StoredCodexLifecycle[] {
|
|
155
|
-
return allRecords(taskDir).filter((record) => record.state.child?.childThreadId === childThreadId);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function locate(event: CodexLifecycleEvent): StoredCodexLifecycle {
|
|
159
|
-
if (event.type === 'hook-spawn') {
|
|
160
|
-
const key = recordKey(event.sessionId, event.turnId, event.toolUseId);
|
|
161
|
-
const existing = allRecords(taskDir).find((record) => record.spawnObservedAt && record.state.spawn
|
|
162
|
-
&& recordKey(record.state.spawn.sessionId, record.state.spawn.turnId, record.state.spawn.toolUseId) === key);
|
|
163
|
-
return existing ?? Object.freeze({
|
|
164
|
-
schemaVersion: 2,
|
|
165
|
-
revision: 0,
|
|
166
|
-
taskBinding: event.taskBinding ?? null,
|
|
167
|
-
state: createCodexLifecycleState(options.cliVersion),
|
|
168
|
-
consumer: null,
|
|
169
|
-
consumedAt: null,
|
|
170
|
-
spawnObservedAt: null,
|
|
171
|
-
updatedAt: now()
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
if (event.type === 'hook-child') {
|
|
175
|
-
const matches = allRecords(taskDir).filter((record) => record.state.spawn?.sessionId === event.parentThreadId
|
|
176
|
-
&& record.state.spawn.nativeAgent === event.nativeAgent
|
|
177
|
-
&& (!record.state.child || record.state.child.childThreadId === event.childThreadId));
|
|
178
|
-
if (matches.length !== 1) {
|
|
179
|
-
throw new Error(matches.length === 0
|
|
180
|
-
? 'Codex lifecycle parent session and agent correlation was not found'
|
|
181
|
-
: 'Codex lifecycle parent session and agent correlation is ambiguous');
|
|
182
|
-
}
|
|
183
|
-
return matches[0]!;
|
|
184
|
-
}
|
|
185
|
-
const matches = findByChild(event.childThreadId);
|
|
186
|
-
if (matches.length !== 1) {
|
|
187
|
-
throw new Error(matches.length === 0
|
|
188
|
-
? `Codex lifecycle child '${event.childThreadId}' was not found`
|
|
189
|
-
: `Codex lifecycle child '${event.childThreadId}' is ambiguous`);
|
|
190
|
-
}
|
|
191
|
-
return matches[0]!;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function update(
|
|
195
|
-
binding: CodexLifecycleTaskBinding,
|
|
196
|
-
key: string,
|
|
197
|
-
mutate: (current: StoredCodexLifecycle | null) => StoredCodexLifecycle
|
|
198
|
-
): StoredCodexLifecycle {
|
|
199
|
-
let result: StoredCodexLifecycle | null = null;
|
|
200
|
-
mutateDelegationAdapterEvidence(options.taskId, binding.receiptId, 'codex', (value) => {
|
|
201
|
-
const currentState = storedEvidence(value);
|
|
202
|
-
const current = currentState.records[key] ?? null;
|
|
203
|
-
result = mutate(current);
|
|
204
|
-
return Object.freeze({
|
|
205
|
-
...currentState,
|
|
206
|
-
records: Object.freeze({ ...currentState.records, [key]: result })
|
|
207
|
-
});
|
|
208
|
-
}, { repoRoot, now });
|
|
209
|
-
if (!result) throw new Error('Codex lifecycle record was not updated');
|
|
210
|
-
return result;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function apply(event: CodexLifecycleEvent): CodexLifecycleStoreResult {
|
|
214
|
-
const existing = event.type === 'hook-spawn' ? null : locate(event);
|
|
215
|
-
const binding = event.type === 'hook-spawn' ? event.taskBinding ?? currentBinding() : existing?.taskBinding;
|
|
216
|
-
if (!binding) throw new Error('Codex lifecycle event has no task receipt binding');
|
|
217
|
-
const key = event.type === 'hook-spawn'
|
|
218
|
-
? recordKey(event.sessionId, event.turnId, event.toolUseId)
|
|
219
|
-
: existing?.state.spawn
|
|
220
|
-
? recordKey(existing.state.spawn.sessionId, existing.state.spawn.turnId, existing.state.spawn.toolUseId)
|
|
221
|
-
: '';
|
|
222
|
-
const observedAt = now();
|
|
223
|
-
const next = update(binding, key, (current) => {
|
|
224
|
-
const base = current ?? Object.freeze({
|
|
225
|
-
schemaVersion: 2 as const,
|
|
226
|
-
revision: 0,
|
|
227
|
-
taskBinding: binding,
|
|
228
|
-
state: createCodexLifecycleState(options.cliVersion),
|
|
229
|
-
consumer: null,
|
|
230
|
-
consumedAt: null,
|
|
231
|
-
spawnObservedAt: null,
|
|
232
|
-
updatedAt: observedAt
|
|
233
|
-
});
|
|
234
|
-
assertCurrentCanApply(base, binding);
|
|
235
|
-
const state = reduceCodexLifecycleEvent(base.state, event);
|
|
236
|
-
if (state === base.state) return base;
|
|
237
|
-
if (state.status === 'invalid' && state.error && NON_PERSISTENT_FAILURES.has(state.error.code)) {
|
|
238
|
-
throw new Error(`${state.error.code}: ${state.error.message}`);
|
|
239
|
-
}
|
|
240
|
-
return Object.freeze({
|
|
241
|
-
...base,
|
|
242
|
-
revision: base.revision + 1,
|
|
243
|
-
state,
|
|
244
|
-
spawnObservedAt: event.type === 'hook-spawn' && base.revision === 0 ? observedAt : base.spawnObservedAt,
|
|
245
|
-
updatedAt: observedAt
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
return Object.freeze({ path: lifecyclePath(taskDir), revision: next.revision, state: next.state });
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function applyToSpawn(
|
|
252
|
-
identity: Readonly<{ sessionId: string; turnId: string; toolUseId: string; taskBinding: CodexLifecycleTaskBinding }>,
|
|
253
|
-
event: Extract<CodexLifecycleEvent, { type: 'hook-child' }>,
|
|
254
|
-
expectedRevision: number
|
|
255
|
-
): CodexLifecycleStoreResult {
|
|
256
|
-
const key = recordKey(identity.sessionId, identity.turnId, identity.toolUseId);
|
|
257
|
-
const current = allRecords(taskDir).find((record) => record.state.spawn
|
|
258
|
-
&& recordKey(record.state.spawn.sessionId, record.state.spawn.turnId, record.state.spawn.toolUseId) === key);
|
|
259
|
-
if (!current) throw new Error('Codex lifecycle spawn identity was not found');
|
|
260
|
-
const next = update(identity.taskBinding, key, (latest) => {
|
|
261
|
-
if (!latest || JSON.stringify(latest.taskBinding) !== JSON.stringify(identity.taskBinding)) {
|
|
262
|
-
throw new Error('Codex lifecycle task binding does not match the stored spawn');
|
|
263
|
-
}
|
|
264
|
-
if (latest.revision !== expectedRevision) {
|
|
265
|
-
throw new Error(`Codex lifecycle revision changed from ${expectedRevision} to ${latest.revision}`);
|
|
266
|
-
}
|
|
267
|
-
if (latest.consumer) throw new Error(`Codex lifecycle evidence was already consumed by '${latest.consumer}'`);
|
|
268
|
-
if (latest.state.spawn?.sessionId !== identity.sessionId
|
|
269
|
-
|| latest.state.spawn.turnId !== identity.turnId
|
|
270
|
-
|| latest.state.spawn.toolUseId !== identity.toolUseId
|
|
271
|
-
|| latest.state.spawn.nativeAgent !== event.nativeAgent
|
|
272
|
-
|| event.sessionId !== identity.sessionId
|
|
273
|
-
|| event.parentThreadId !== identity.sessionId) {
|
|
274
|
-
throw new Error('Codex lifecycle spawn identity does not match the stored event');
|
|
275
|
-
}
|
|
276
|
-
const state = reduceCodexLifecycleEvent(latest.state, event);
|
|
277
|
-
if (state.status === 'invalid' && state.error && NON_PERSISTENT_FAILURES.has(state.error.code)) {
|
|
278
|
-
throw new Error(`${state.error.code}: ${state.error.message}`);
|
|
279
|
-
}
|
|
280
|
-
return state === latest.state ? latest : Object.freeze({ ...latest, revision: latest.revision + 1, state, updatedAt: now() });
|
|
281
|
-
});
|
|
282
|
-
return Object.freeze({ path: lifecyclePath(taskDir), revision: next.revision, state: next.state });
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function findByParent(parentThreadId: string): readonly StoredCodexLifecycle[] {
|
|
286
|
-
const matches = allRecords(taskDir).filter((record) => record.state.startEvidence?.parentThreadId === parentThreadId
|
|
287
|
-
&& ['start-ready', 'observed-terminal', 'stop-ready'].includes(record.state.status));
|
|
288
|
-
const unconsumed = matches.filter((record) => !record.consumer);
|
|
289
|
-
if (unconsumed.length > 1) throw new Error(`Codex lifecycle parent '${parentThreadId}' has ambiguous active children`);
|
|
290
|
-
return Object.freeze(unconsumed.length === 1 ? unconsumed : matches.filter((record) => record.consumer));
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function findByTaskBinding(binding: CodexLifecycleTaskBinding): readonly StoredCodexLifecycle[] {
|
|
294
|
-
return Object.freeze(allRecords(taskDir).filter((record) => record.taskBinding?.runId === binding.runId
|
|
295
|
-
&& record.taskBinding.receiptId === binding.receiptId));
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function read(childThreadId: string): StoredCodexLifecycle {
|
|
299
|
-
const matches = findByChild(childThreadId);
|
|
300
|
-
if (matches.length !== 1) throw new Error(`Codex lifecycle child '${childThreadId}' was not found uniquely`);
|
|
301
|
-
return matches[0]!;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function consume(
|
|
305
|
-
childThreadId: string,
|
|
306
|
-
consumer: string,
|
|
307
|
-
expectedHookDefinitionHash?: string,
|
|
308
|
-
expectedTaskBinding?: CodexLifecycleTaskBinding
|
|
309
|
-
): StoredCodexLifecycle {
|
|
310
|
-
if (!consumer.trim()) throw new Error('Codex lifecycle consumer is required');
|
|
311
|
-
const current = read(childThreadId);
|
|
312
|
-
const binding = expectedTaskBinding ?? current.taskBinding;
|
|
313
|
-
if (!binding) throw new Error('Codex lifecycle task receipt binding is missing');
|
|
314
|
-
const spawn = current.state.spawn;
|
|
315
|
-
if (!spawn) throw new Error('Codex lifecycle spawn evidence is missing');
|
|
316
|
-
const key = recordKey(spawn.sessionId, spawn.turnId, spawn.toolUseId);
|
|
317
|
-
return update(binding, key, (latest) => {
|
|
318
|
-
if (!latest || expectedTaskBinding && JSON.stringify(latest.taskBinding) !== JSON.stringify(expectedTaskBinding)) {
|
|
319
|
-
throw new Error('Codex lifecycle task binding does not match the expected receipt');
|
|
320
|
-
}
|
|
321
|
-
if (latest.consumer && latest.consumer !== consumer) {
|
|
322
|
-
throw new Error(`Codex lifecycle evidence was already consumed by '${latest.consumer}'`);
|
|
323
|
-
}
|
|
324
|
-
if (latest.state.status !== 'stop-ready') throw new Error('Codex lifecycle evidence is not stop-ready');
|
|
325
|
-
if (expectedHookDefinitionHash && latest.state.startEvidence?.hookDefinitionHash !== expectedHookDefinitionHash) {
|
|
326
|
-
throw new Error('Codex lifecycle hook definition hash is stale');
|
|
327
|
-
}
|
|
328
|
-
if (latest.consumer) return latest;
|
|
329
|
-
return Object.freeze({ ...latest, revision: latest.revision + 1, consumer, consumedAt: now(), updatedAt: now() });
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function expireBefore(cutoff: string): number {
|
|
334
|
-
let changed = 0;
|
|
335
|
-
for (const record of allRecords(taskDir)) {
|
|
336
|
-
if (record.updatedAt >= cutoff || !record.taskBinding?.receiptId || !record.state.spawn) continue;
|
|
337
|
-
const key = recordKey(record.state.spawn.sessionId, record.state.spawn.turnId, record.state.spawn.toolUseId);
|
|
338
|
-
update(record.taskBinding, key, (latest) => {
|
|
339
|
-
if (!latest || latest.updatedAt >= cutoff || latest.consumer
|
|
340
|
-
|| ['invalid', 'expired', 'stop-ready'].includes(latest.state.status)) return latest ?? record;
|
|
341
|
-
const state = expireCodexLifecycleState(latest.state);
|
|
342
|
-
if (state === latest.state) return latest;
|
|
343
|
-
changed += 1;
|
|
344
|
-
return Object.freeze({ ...latest, revision: latest.revision + 1, state, updatedAt: now() });
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
return changed;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return Object.freeze({ taskId: options.taskId, root: path.join(taskDir, '.runtime'), apply, applyToSpawn, consume, expireBefore, findByParent, findByTaskBinding, read });
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export { createCodexLifecycleStore, hasActiveCodexLifecycleEvidence, readCodexLifecycleActivationEvidence };
|
|
354
|
-
export type { ActiveCodexLifecycleEvidenceQuery, CodexLifecycleActivationEvidence, CodexLifecycleStoreOptions, CodexLifecycleStoreResult, StoredCodexLifecycle };
|