@fitlab-ai/agent-infra 0.9.8 → 0.9.10

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.
Files changed (182) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/bin/internal-cli.js +11 -1
  4. package/dist/lib/agent-clients/adapters/codex-lifecycle/app-server.js +58 -21
  5. package/dist/lib/agent-clients/adapters/codex-lifecycle/build-identity.js +25 -11
  6. package/dist/lib/agent-clients/adapters/codex-lifecycle/capability-store.js +173 -10
  7. package/dist/lib/agent-clients/adapters/codex-lifecycle/controller-context.js +127 -0
  8. package/dist/lib/agent-clients/adapters/codex-lifecycle/evidence.js +14 -0
  9. package/dist/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.js +63 -92
  10. package/dist/lib/agent-clients/adapters/codex-sandbox.js +72 -11
  11. package/dist/lib/agent-clients/adapters/index.js +3 -1
  12. package/dist/lib/agent-clients/adapters/traecli.js +66 -0
  13. package/dist/lib/agent-clients/tokens.js +2 -2
  14. package/dist/lib/agent-clients/types.js +2 -1
  15. package/dist/lib/defaults.json +5 -0
  16. package/dist/lib/git/workflow.js +10 -1
  17. package/dist/lib/internal/codex-lifecycle.js +20 -6
  18. package/dist/lib/internal/codex-sandbox-controller.js +9 -15
  19. package/dist/lib/internal/git-workflow.js +5 -7
  20. package/dist/lib/internal/platform-pr.js +20 -7
  21. package/dist/lib/internal/release-workflow.js +2 -1
  22. package/dist/lib/internal/sandbox-control.js +79 -2
  23. package/dist/lib/internal/task-finalization.js +54 -0
  24. package/dist/lib/internal/task-orchestration.js +156 -291
  25. package/dist/lib/{task/commands/validate.js → internal/task-validate.js} +75 -42
  26. package/dist/lib/platform/pr-summary.js +48 -10
  27. package/dist/lib/platform/pull-requests.js +205 -41
  28. package/dist/lib/run/tui.js +5 -2
  29. package/dist/lib/sandbox/commands/rm.js +316 -55
  30. package/dist/lib/sandbox/control/client.js +190 -6
  31. package/dist/lib/sandbox/control/controller-registration.js +275 -0
  32. package/dist/lib/sandbox/control/executor.js +140 -5
  33. package/dist/lib/sandbox/control/lifecycle.js +3 -1
  34. package/dist/lib/sandbox/control/protocol.js +67 -6
  35. package/dist/lib/sandbox/index.js +5 -3
  36. package/dist/lib/sandbox/managed-fs.js +5 -0
  37. package/dist/lib/sandbox/task-resolver.js +50 -6
  38. package/dist/lib/sandbox/workspace-identity.js +27 -0
  39. package/dist/lib/sandbox/worktree-safety.js +215 -2
  40. package/dist/lib/task/codex-orchestration.js +161 -39
  41. package/dist/lib/task/commands/status.js +59 -1
  42. package/dist/lib/task/commit-operation.js +335 -0
  43. package/dist/lib/task/commit-policy.js +18 -0
  44. package/dist/lib/task/delegation-receipts.js +248 -6
  45. package/dist/lib/task/finalization.js +593 -0
  46. package/dist/lib/task/index.js +0 -9
  47. package/dist/lib/task/operation-outcome.js +33 -0
  48. package/dist/lib/task/orchestration.js +187 -761
  49. package/dist/lib/task/short-id.js +59 -1
  50. package/dist/lib/task/task-execution-lock.js +6 -1
  51. package/dist/lib/task/verification-engine.js +110 -60
  52. package/dist/lib/task/verification.js +2 -1
  53. package/dist/lib/task/workflow-warning-intents.js +50 -1
  54. package/dist/lifecycle-build-manifest.json +3 -3
  55. package/lib/agent-clients/adapters/codex-lifecycle/app-server.ts +61 -19
  56. package/lib/agent-clients/adapters/codex-lifecycle/build-identity.ts +37 -10
  57. package/lib/agent-clients/adapters/codex-lifecycle/capability-store.ts +276 -12
  58. package/lib/agent-clients/adapters/codex-lifecycle/controller-context.ts +163 -0
  59. package/lib/agent-clients/adapters/codex-lifecycle/evidence.ts +19 -0
  60. package/lib/agent-clients/adapters/codex-lifecycle/manifest-files.json +9 -1
  61. package/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.ts +91 -118
  62. package/lib/agent-clients/adapters/codex-sandbox.ts +89 -14
  63. package/lib/agent-clients/adapters/index.ts +3 -1
  64. package/lib/agent-clients/adapters/traecli.ts +67 -0
  65. package/lib/agent-clients/tokens.ts +2 -2
  66. package/lib/agent-clients/types.ts +2 -1
  67. package/lib/defaults.json +5 -0
  68. package/lib/git/workflow.ts +11 -2
  69. package/lib/internal/codex-lifecycle.ts +19 -6
  70. package/lib/internal/codex-sandbox-controller.ts +9 -14
  71. package/lib/internal/git-workflow.ts +5 -6
  72. package/lib/internal/platform-pr.ts +14 -7
  73. package/lib/internal/release-workflow.ts +2 -1
  74. package/lib/internal/sandbox-control.ts +92 -2
  75. package/lib/internal/task-finalization.ts +68 -0
  76. package/lib/internal/task-orchestration.ts +20 -103
  77. package/lib/{task/commands/validate.ts → internal/task-validate.ts} +75 -40
  78. package/lib/platform/pr-summary.ts +55 -11
  79. package/lib/platform/pull-requests.ts +211 -41
  80. package/lib/run/tui.ts +5 -3
  81. package/lib/sandbox/commands/rm.ts +413 -61
  82. package/lib/sandbox/control/client.ts +255 -6
  83. package/lib/sandbox/control/controller-registration.ts +352 -0
  84. package/lib/sandbox/control/executor.ts +169 -5
  85. package/lib/sandbox/control/lifecycle.ts +2 -1
  86. package/lib/sandbox/control/protocol.ts +80 -7
  87. package/lib/sandbox/index.ts +5 -3
  88. package/lib/sandbox/managed-fs.ts +5 -0
  89. package/lib/sandbox/task-resolver.ts +58 -7
  90. package/lib/sandbox/workspace-identity.ts +50 -2
  91. package/lib/sandbox/workspace-view.ts +3 -3
  92. package/lib/sandbox/worktree-safety.ts +236 -2
  93. package/lib/task/codex-orchestration.ts +168 -40
  94. package/lib/task/commands/status.ts +78 -1
  95. package/lib/task/commit-operation.ts +430 -0
  96. package/lib/task/commit-policy.ts +30 -0
  97. package/lib/task/delegation-receipts.ts +263 -4
  98. package/lib/task/finalization.ts +761 -0
  99. package/lib/task/index.ts +0 -8
  100. package/lib/task/operation-outcome.ts +48 -0
  101. package/lib/task/orchestration.ts +218 -982
  102. package/lib/task/short-id.ts +65 -1
  103. package/lib/task/task-execution-lock.ts +10 -1
  104. package/lib/task/verification-engine.ts +115 -63
  105. package/lib/task/verification.ts +3 -2
  106. package/lib/task/workflow-warning-intents.ts +57 -2
  107. package/package.json +2 -2
  108. package/templates/.agents/QUICKSTART.en.md +3 -4
  109. package/templates/.agents/QUICKSTART.zh-CN.md +3 -4
  110. package/templates/.agents/hooks/lifecycle-delegation.js +1 -21
  111. package/templates/.agents/rules/README.en.md +1 -0
  112. package/templates/.agents/rules/README.zh-CN.md +1 -0
  113. package/templates/.agents/rules/compatibility-policy.en.md +39 -0
  114. package/templates/.agents/rules/compatibility-policy.zh-CN.md +39 -0
  115. package/templates/.agents/rules/lifecycle-orchestration.en.md +4 -4
  116. package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +4 -4
  117. package/templates/.agents/rules/pr-sync.en.md +1 -1
  118. package/templates/.agents/rules/pr-sync.github.en.md +2 -1
  119. package/templates/.agents/rules/pr-sync.github.zh-CN.md +2 -0
  120. package/templates/.agents/rules/pr-sync.zh-CN.md +1 -0
  121. package/templates/.agents/rules/review-method.en.md +1 -0
  122. package/templates/.agents/rules/review-method.zh-CN.md +1 -0
  123. package/templates/.agents/rules/task-management.en.md +2 -2
  124. package/templates/.agents/rules/task-management.zh-CN.md +2 -2
  125. package/templates/.agents/skills/analyze-task/SKILL.en.md +1 -0
  126. package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +1 -0
  127. package/templates/.agents/skills/block-task/SKILL.en.md +2 -4
  128. package/templates/.agents/skills/block-task/SKILL.zh-CN.md +2 -4
  129. package/templates/.agents/skills/cancel-task/SKILL.en.md +3 -3
  130. package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +3 -3
  131. package/templates/.agents/skills/close-codescan/SKILL.en.md +6 -2
  132. package/templates/.agents/skills/close-codescan/SKILL.zh-CN.md +6 -2
  133. package/templates/.agents/skills/close-dependabot/SKILL.en.md +6 -2
  134. package/templates/.agents/skills/close-dependabot/SKILL.zh-CN.md +6 -2
  135. package/templates/.agents/skills/code-task/SKILL.en.md +1 -0
  136. package/templates/.agents/skills/code-task/SKILL.zh-CN.md +2 -0
  137. package/templates/.agents/skills/commit/SKILL.en.md +41 -125
  138. package/templates/.agents/skills/commit/SKILL.zh-CN.md +52 -123
  139. package/templates/.agents/skills/commit/reference/commit-message.en.md +1 -1
  140. package/templates/.agents/skills/commit/reference/commit-message.zh-CN.md +1 -1
  141. package/templates/.agents/skills/commit/reference/commit-orchestration.en.md +14 -43
  142. package/templates/.agents/skills/commit/reference/commit-orchestration.zh-CN.md +14 -49
  143. package/templates/.agents/skills/commit/reference/pr-summary-sync.en.md +1 -1
  144. package/templates/.agents/skills/commit/reference/pr-summary-sync.zh-CN.md +1 -1
  145. package/templates/.agents/skills/commit/reference/task-status-update.en.md +2 -35
  146. package/templates/.agents/skills/commit/reference/task-status-update.zh-CN.md +2 -35
  147. package/templates/.agents/skills/complete-task/SKILL.en.md +31 -38
  148. package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +31 -38
  149. package/templates/.agents/skills/complete-task/config/verify.en.json +1 -0
  150. package/templates/.agents/skills/complete-task/config/verify.zh-CN.json +1 -0
  151. package/templates/.agents/skills/complete-task/reference/external-delivery.en.md +1 -1
  152. package/templates/.agents/skills/complete-task/reference/external-delivery.zh-CN.md +1 -1
  153. package/templates/.agents/skills/create-pr/SKILL.en.md +17 -9
  154. package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +17 -9
  155. package/templates/.agents/skills/create-pr/reference/change-report.en.md +41 -0
  156. package/templates/.agents/skills/create-pr/reference/change-report.zh-CN.md +41 -0
  157. package/templates/.agents/skills/create-pr/reference/comment-publish.en.md +2 -2
  158. package/templates/.agents/skills/create-pr/reference/comment-publish.zh-CN.md +2 -2
  159. package/templates/.agents/skills/plan-task/SKILL.en.md +2 -1
  160. package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +2 -1
  161. package/templates/.agents/skills/review-code/reference/migration-risks.en.md +8 -6
  162. package/templates/.agents/skills/review-code/reference/migration-risks.zh-CN.md +8 -6
  163. package/templates/.agents/skills/run-manual-validation/SKILL.en.md +3 -3
  164. package/templates/.agents/skills/run-manual-validation/SKILL.zh-CN.md +3 -3
  165. package/templates/.agents/skills/run-manual-validation/reference/discovery-and-execution.en.md +1 -1
  166. package/templates/.agents/skills/run-manual-validation/reference/discovery-and-execution.zh-CN.md +1 -1
  167. package/templates/.agents/skills/run-manual-validation/reference/report-template.en.md +2 -2
  168. package/templates/.agents/skills/run-manual-validation/reference/report-template.zh-CN.md +2 -2
  169. package/templates/.agents/skills/run-task/SKILL.en.md +6 -6
  170. package/templates/.agents/skills/run-task/SKILL.zh-CN.md +6 -6
  171. package/templates/.agents/skills/run-task/reference/host-validation.en.md +2 -2
  172. package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +2 -2
  173. package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +24 -0
  174. package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.en.md +1 -1
  175. package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.zh-CN.md +1 -1
  176. package/templates/.codex/hooks.json +4 -4
  177. package/templates/.trae/skills/update-agent-infra.en.md +8 -0
  178. package/templates/.trae/skills/update-agent-infra.zh-CN.md +8 -0
  179. package/dist/lib/task/commit-finalization.js +0 -305
  180. package/dist/lib/task/commit-intent.js +0 -165
  181. package/lib/task/commit-finalization.ts +0 -419
  182. package/lib/task/commit-intent.ts +0 -230
@@ -1,18 +1,34 @@
1
- import fs from 'node:fs';
2
1
  import { preflightCodexLifecycleEvidence, resolveCodexSpawnedChild, resolveCodexTerminal, resolveCodexThread } from '../agent-clients/adapters/codex-lifecycle/app-server.js';
3
2
  import { createCodexLifecycleStore } from '../agent-clients/adapters/codex-lifecycle/store.js';
4
- import { createCodexCapabilityStore } from '../agent-clients/adapters/codex-lifecycle/capability-store.js';
5
- import { computeLifecycleBuildIdentity } from '../agent-clients/adapters/codex-lifecycle/build-identity.js';
6
- import { verifyCodexSandboxControllerContext } from '../agent-clients/adapters/codex-lifecycle/sandbox-controller.js';
3
+ import { createCodexCapabilityStore, isCodexCapabilityProvenanceDetail } from '../agent-clients/adapters/codex-lifecycle/capability-store.js';
4
+ import { computeLifecycleBuildIdentity, verifyLifecycleBuildIdentity } from '../agent-clients/adapters/codex-lifecycle/build-identity.js';
5
+ import { verifyCodexSandboxControllerContextWithWarnings as verifySandboxControllerWithWarnings } from '../agent-clients/adapters/codex-lifecycle/sandbox-controller.js';
6
+ import { verifyCodexSandboxControllerContextWithWarnings as verifyControllerContextFileWithWarnings } from '../agent-clients/adapters/codex-lifecycle/controller-context.js';
7
7
  import { resolveTaskRef } from './resolve-ref.js';
8
- import { activateMatchingOrchestrationDelegation, hasActivatableOrchestrationDelegation, hasSealableOrchestrationDelegation, pauseMatchingOrchestrationDelegation, prepareOrchestrationDelegation, reconcileMatchingOrchestrationDelegation, sealMatchingOrchestrationDelegationWithHostEvidence } from './orchestration.js';
8
+ import { activateMatchingOrchestrationDelegation, hasActivatableOrchestrationDelegation, hasSealableOrchestrationDelegation, OrchestrationStateError, pauseMatchingOrchestrationDelegation, prepareOrchestrationDelegation, reconcileMatchingOrchestrationDelegation, sealMatchingOrchestrationDelegationWithHostEvidence } from './orchestration.js';
9
9
  function coreOptions(options) {
10
10
  return { ...options.orchestrationOptions, repoRoot: options.repoRoot ?? options.orchestrationOptions?.repoRoot };
11
11
  }
12
- function bridgeFailure(code, message) {
12
+ function bridgeFailure(code, message, detail) {
13
13
  return {
14
14
  status: 'failed', changed: false, taskId: null, run: null, next: null,
15
- error: { code, message }
15
+ error: { code, message, ...(detail ? { detail } : {}) }
16
+ };
17
+ }
18
+ function capabilityFailure(error) {
19
+ const detailValue = error instanceof Error
20
+ ? error.detail
21
+ : undefined;
22
+ return {
23
+ code: error instanceof Error && error.name.startsWith('CODEX_CAPABILITY_')
24
+ ? error.name
25
+ : 'ORCHESTRATION_CLIENT_PREFLIGHT_FAILED',
26
+ message: error instanceof Error ? error.message : String(error),
27
+ ...(error instanceof Error
28
+ && error.name === 'CODEX_CAPABILITY_PROVENANCE_MISMATCH'
29
+ && isCodexCapabilityProvenanceDetail(detailValue)
30
+ ? { detail: detailValue }
31
+ : {})
16
32
  };
17
33
  }
18
34
  function pauseBridge(code, message, options) {
@@ -26,11 +42,27 @@ function requiredStore(options) {
26
42
  throw new Error('Codex lifecycle store is required for orchestration bridge events');
27
43
  return options.store;
28
44
  }
29
- function controllerContext(taskId, repoRoot) {
30
- const contextPath = process.env.AGENT_INFRA_CODEX_CONTROLLER_CONTEXT;
31
- return contextPath
32
- ? verifyCodexSandboxControllerContext(contextPath, taskId, { repoRoot })
33
- : null;
45
+ function brokerControllerBinding() {
46
+ const raw = process.env.AGENT_INFRA_CONTROL_CONTROLLER_BINDING;
47
+ if (!raw)
48
+ return null;
49
+ let value;
50
+ try {
51
+ value = JSON.parse(raw);
52
+ }
53
+ catch {
54
+ throw new Error('CODEX_SANDBOX_CONTROLLER_BINDING_INVALID');
55
+ }
56
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
57
+ throw new Error('CODEX_SANDBOX_CONTROLLER_BINDING_INVALID');
58
+ }
59
+ const binding = value;
60
+ if (Object.keys(binding).sort().join(',') !== 'controlGeneration,instanceDigest'
61
+ || typeof binding.instanceDigest !== 'string' || !/^[a-f0-9]{64}$/u.test(binding.instanceDigest)
62
+ || typeof binding.controlGeneration !== 'string' || binding.controlGeneration.length === 0) {
63
+ throw new Error('CODEX_SANDBOX_CONTROLLER_BINDING_INVALID');
64
+ }
65
+ return binding;
34
66
  }
35
67
  async function prepareCodexOrchestrationDelegation(taskRef, input, options = {}) {
36
68
  if (input.client !== 'codex')
@@ -45,35 +77,111 @@ async function prepareCodexOrchestrationDelegation(taskRef, input, options = {})
45
77
  return bridgeFailure('ORCHESTRATION_CODEX_CAPABILITY_REQUIRED', 'Codex prepare requires a current-session capability token');
46
78
  }
47
79
  const buildIdentity = options.buildIdentity ?? computeLifecycleBuildIdentity(repoRoot);
48
- const controller = controllerContext(resolved.taskId, repoRoot);
80
+ const brokerController = brokerControllerBinding();
81
+ const contextPath = process.env.AGENT_INFRA_CODEX_CONTROLLER_CONTEXT;
82
+ const contextVerification = contextPath
83
+ ? (brokerController
84
+ ? verifyControllerContextFileWithWarnings(contextPath, {
85
+ repoRoot,
86
+ generation: process.env.AGENT_INFRA_CONTROL_GENERATION ?? brokerController.controlGeneration
87
+ })
88
+ : verifySandboxControllerWithWarnings(contextPath, { repoRoot }))
89
+ : null;
90
+ const identityWarnings = [...(contextVerification?.warnings ?? [])];
91
+ const localController = contextVerification?.context ?? null;
92
+ if (localController && brokerController
93
+ && (localController.controllerInstanceDigest !== brokerController.instanceDigest
94
+ || localController.controlGeneration !== brokerController.controlGeneration)) {
95
+ return bridgeFailure('CODEX_SANDBOX_CONTROLLER_BINDING_MISMATCH', 'broker and local controller bindings do not match');
96
+ }
97
+ const controller = brokerController ?? (localController ? {
98
+ instanceDigest: localController.controllerInstanceDigest,
99
+ controlGeneration: localController.controlGeneration
100
+ } : null);
49
101
  const capabilityStore = options.capabilityStore ?? createCodexCapabilityStore();
50
- const consumed = capabilityStore.consume(input.capabilityToken, {
102
+ const attested = capabilityStore.inspect(input.capabilityToken);
103
+ const capabilityIdentity = verifyLifecycleBuildIdentity(attested.buildIdentity, buildIdentity);
104
+ if (!capabilityIdentity.ok) {
105
+ return bridgeFailure(capabilityIdentity.code, capabilityIdentity.message);
106
+ }
107
+ identityWarnings.push(...capabilityIdentity.warnings);
108
+ const lifecycleProvenance = {
109
+ ...attested.buildIdentity,
110
+ hookDefinitionHash: preflight.hookDefinitionHash,
111
+ ...preflight.hookProvenance,
112
+ capabilitySessionId: attested.sessionId,
113
+ capabilityTurnId: attested.turnId,
114
+ capabilityToolUseId: attested.toolUseId,
115
+ controllerInstanceDigest: controller?.instanceDigest ?? null,
116
+ controlGeneration: controller?.controlGeneration ?? null
117
+ };
118
+ const capabilityExpected = {
51
119
  taskId: resolved.taskId,
52
120
  hookDefinitionHash: preflight.hookDefinitionHash,
53
121
  buildIdentity,
54
122
  ...(controller ? { controller: {
55
- instanceDigest: controller.controllerInstanceDigest,
123
+ instanceDigest: controller.instanceDigest,
56
124
  controlGeneration: controller.controlGeneration
57
125
  } } : {})
58
- });
59
- return prepareOrchestrationDelegation(taskRef, {
126
+ };
127
+ const prepared = prepareOrchestrationDelegation(taskRef, {
60
128
  ...input,
61
- lifecycleProvenance: {
62
- ...consumed.buildIdentity,
63
- hookDefinitionHash: preflight.hookDefinitionHash,
64
- ...preflight.hookProvenance,
65
- capabilitySessionId: consumed.sessionId,
66
- capabilityTurnId: consumed.turnId,
67
- capabilityToolUseId: consumed.toolUseId,
68
- controllerInstanceDigest: controller?.controllerInstanceDigest ?? null,
69
- controlGeneration: controller?.controlGeneration ?? null
129
+ lifecycleProvenance
130
+ }, {
131
+ ...coreOptions(options),
132
+ validateLifecycleCapability: () => {
133
+ try {
134
+ const validated = capabilityStore.validate(input.capabilityToken, capabilityExpected);
135
+ if (validated.sessionId !== attested.sessionId
136
+ || validated.turnId !== attested.turnId
137
+ || validated.toolUseId !== attested.toolUseId) {
138
+ return {
139
+ code: 'CODEX_CAPABILITY_IDENTITY_CHANGED',
140
+ message: 'capability identity changed during validation'
141
+ };
142
+ }
143
+ return null;
144
+ }
145
+ catch (error) {
146
+ return capabilityFailure(error);
147
+ }
148
+ },
149
+ consumeLifecycleCapability: () => {
150
+ try {
151
+ const consumed = capabilityStore.consume(input.capabilityToken, capabilityExpected);
152
+ if (consumed.sessionId !== attested.sessionId
153
+ || consumed.turnId !== attested.turnId
154
+ || consumed.toolUseId !== attested.toolUseId) {
155
+ return {
156
+ code: 'CODEX_CAPABILITY_IDENTITY_CHANGED',
157
+ message: 'capability identity changed during consumption'
158
+ };
159
+ }
160
+ return null;
161
+ }
162
+ catch (error) {
163
+ return capabilityFailure(error);
164
+ }
70
165
  }
71
- }, coreOptions(options));
166
+ });
167
+ return identityWarnings.length > 0 && prepared.status !== 'failed'
168
+ ? { ...prepared, warnings: Object.freeze(identityWarnings) }
169
+ : prepared;
72
170
  }
73
171
  catch (error) {
172
+ if (error instanceof OrchestrationStateError)
173
+ return bridgeFailure(error.code, error.message);
174
+ const detailValue = error instanceof Error
175
+ ? error.detail
176
+ : undefined;
177
+ const detail = error instanceof Error
178
+ && error.name === 'CODEX_CAPABILITY_PROVENANCE_MISMATCH'
179
+ && isCodexCapabilityProvenanceDetail(detailValue)
180
+ ? detailValue
181
+ : undefined;
74
182
  return bridgeFailure(error instanceof Error && error.name.startsWith('CODEX_CAPABILITY_')
75
183
  ? error.name
76
- : 'ORCHESTRATION_CLIENT_PREFLIGHT_FAILED', error instanceof Error ? error.message : String(error));
184
+ : 'ORCHESTRATION_CLIENT_PREFLIGHT_FAILED', error instanceof Error ? error.message : String(error), detail);
77
185
  }
78
186
  }
79
187
  async function activateCodexOrchestrationDelegation(childThreadId, options = {}) {
@@ -100,16 +208,11 @@ async function activateCodexOrchestrationDelegation(childThreadId, options = {})
100
208
  });
101
209
  const buildIdentity = options.buildIdentity ?? computeLifecycleBuildIdentity(repoRoot);
102
210
  const contextPath = process.env.AGENT_INFRA_CODEX_CONTROLLER_CONTEXT;
103
- const contextTaskId = contextPath
104
- ? JSON.parse(fs.readFileSync(contextPath, 'utf8')).taskId
211
+ const contextVerification = contextPath
212
+ ? verifySandboxControllerWithWarnings(contextPath, { repoRoot })
105
213
  : null;
106
- if (contextPath && typeof contextTaskId !== 'string') {
107
- throw new Error('CODEX_SANDBOX_CONTROLLER_CONTEXT_INVALID');
108
- }
109
- const controller = contextPath
110
- ? verifyCodexSandboxControllerContext(contextPath, contextTaskId, { repoRoot })
111
- : null;
112
- return activateMatchingOrchestrationDelegation('codex', {
214
+ const controller = contextVerification?.context ?? null;
215
+ const activated = activateMatchingOrchestrationDelegation('codex', {
113
216
  nativeAgent: evidence.nativeAgent,
114
217
  childId: evidence.childThreadId,
115
218
  parentId: evidence.parentThreadId,
@@ -134,8 +237,14 @@ async function activateCodexOrchestrationDelegation(childThreadId, options = {})
134
237
  controlGeneration: controller?.controlGeneration ?? null
135
238
  }
136
239
  }, coreOptions(options));
240
+ const warnings = contextVerification?.warnings ?? [];
241
+ return warnings.length > 0 && activated.status !== 'failed'
242
+ ? { ...activated, warnings: Object.freeze(warnings) }
243
+ : activated;
137
244
  }
138
245
  catch (error) {
246
+ if (error instanceof OrchestrationStateError)
247
+ return bridgeFailure(error.code, error.message);
139
248
  return pauseBridge('ORCHESTRATION_CODEX_START_FAILED', error instanceof Error ? error.message : String(error), options);
140
249
  }
141
250
  }
@@ -160,6 +269,8 @@ async function activateCodexSpawnDelegation(spawn, options = {}) {
160
269
  });
161
270
  }
162
271
  catch (error) {
272
+ if (error instanceof OrchestrationStateError)
273
+ return bridgeFailure(error.code, error.message);
163
274
  return pauseBridge('ORCHESTRATION_CODEX_START_FAILED', error instanceof Error ? error.message : String(error), options);
164
275
  }
165
276
  }
@@ -171,7 +282,11 @@ async function sealCodexOrchestrationDelegation(childThreadId, options = {}) {
171
282
  const store = requiredStore(options);
172
283
  const existing = store.read(childThreadId);
173
284
  if (!existing.consumer) {
174
- store.apply(await (options.resolveTerminal ?? resolveCodexTerminal)(childThreadId));
285
+ const stopTurnId = existing.state.stop?.turnId;
286
+ if (!stopTurnId) {
287
+ return pauseBridge('ORCHESTRATION_CODEX_STOP_EVIDENCE_INVALID', 'Codex lifecycle stop hook is not available', options);
288
+ }
289
+ store.apply(await (options.resolveTerminal ?? resolveCodexTerminal)(childThreadId, stopTurnId));
175
290
  }
176
291
  const record = store.read(childThreadId);
177
292
  const evidence = record.state.stopEvidence;
@@ -188,6 +303,8 @@ async function sealCodexOrchestrationDelegation(childThreadId, options = {}) {
188
303
  }, coreOptions(options));
189
304
  }
190
305
  catch (error) {
306
+ if (error instanceof OrchestrationStateError)
307
+ return bridgeFailure(error.code, error.message);
191
308
  return pauseBridge('ORCHESTRATION_CODEX_STOP_FAILED', error instanceof Error ? error.message : String(error), options);
192
309
  }
193
310
  }
@@ -208,7 +325,10 @@ async function sealCodexParentDelegation(parentThreadId, options = {}) {
208
325
  const start = active.state.startEvidence;
209
326
  const child = active.state.child;
210
327
  if (!active.state.terminal) {
211
- store.apply(await (options.resolveTerminal ?? resolveCodexTerminal)(start.childThreadId));
328
+ const resolveTerminal = options.resolveTerminal ?? resolveCodexTerminal;
329
+ store.apply(active.state.stop
330
+ ? await resolveTerminal(start.childThreadId, active.state.stop.turnId)
331
+ : await resolveTerminal(start.childThreadId));
212
332
  }
213
333
  if (!store.read(start.childThreadId).state.stop) {
214
334
  store.apply({
@@ -223,6 +343,8 @@ async function sealCodexParentDelegation(parentThreadId, options = {}) {
223
343
  return sealCodexOrchestrationDelegation(start.childThreadId, options);
224
344
  }
225
345
  catch (error) {
346
+ if (error instanceof OrchestrationStateError)
347
+ return bridgeFailure(error.code, error.message);
226
348
  if (error instanceof Error && error.message === 'CODEX_TURN_NOT_TERMINAL') {
227
349
  return bridgeFailure('ORCHESTRATION_DELEGATION_MISSING', 'The matching Codex child has not completed');
228
350
  }
@@ -9,6 +9,7 @@ import { parseTaskFrontmatter, extractTitle } from '../frontmatter.js';
9
9
  import { loadShortIdByTaskId } from '../short-id.js';
10
10
  import { getOpenWorkflowWarnings, formatWorkflowWarningSummary } from '../workflow-warnings.js';
11
11
  import { parseActivityLog, pairEntries } from '../activity-log.js';
12
+ import { readRun } from '../orchestration.js';
12
13
  import { statusCard } from '../../server/display.js';
13
14
  const USAGE = `Usage: ai task status [<N | TASK-id> | --task <ref> | -t <ref>]
14
15
 
@@ -262,6 +263,38 @@ function collectRuntime(taskDir, workflow, run) {
262
263
  log: record.log_file
263
264
  };
264
265
  }
266
+ function pendingDelegationInfo(receipt) {
267
+ if (!receipt)
268
+ return null;
269
+ return {
270
+ id: receipt.id,
271
+ role: receipt.role,
272
+ stage: receipt.stage,
273
+ round: receipt.round,
274
+ artifact: receipt.artifact,
275
+ client: receipt.client,
276
+ status: receipt.status
277
+ };
278
+ }
279
+ function collectOrchestration(taskDir) {
280
+ const run = readRun(taskDir);
281
+ if (!run) {
282
+ return {
283
+ status: 'absent',
284
+ runId: DASH,
285
+ nextStage: DASH,
286
+ pause: null,
287
+ pendingDelegation: null
288
+ };
289
+ }
290
+ return {
291
+ status: run.status,
292
+ runId: run.runId,
293
+ nextStage: run.nextStage ?? DASH,
294
+ pause: run.pause,
295
+ pendingDelegation: pendingDelegationInfo(run.pendingDelegation)
296
+ };
297
+ }
265
298
  // Indent each label/value pair by two spaces and pad labels to a common width so
266
299
  // every section reads as an aligned "key value" block.
267
300
  function renderPairs(rows) {
@@ -284,6 +317,21 @@ function renderStatus(model) {
284
317
  else {
285
318
  lines.push(...renderPairs(model.artifacts.groups.map((group) => [group.stage, group.files.join(', ')])));
286
319
  }
320
+ lines.push('', 'Orchestration', ...renderPairs([
321
+ ['status', model.orchestration.status],
322
+ ['run_id', model.orchestration.runId],
323
+ ['next_stage', model.orchestration.nextStage],
324
+ ['pause_code', model.orchestration.pause?.code ?? DASH],
325
+ ['pause_message', model.orchestration.pause?.message ?? DASH],
326
+ ['recoverable', model.orchestration.pause ? String(model.orchestration.pause.recoverable) : DASH],
327
+ ['pending_id', model.orchestration.pendingDelegation?.id ?? DASH],
328
+ ['pending_role', model.orchestration.pendingDelegation?.role ?? DASH],
329
+ ['pending_stage', model.orchestration.pendingDelegation?.stage ?? DASH],
330
+ ['pending_round', model.orchestration.pendingDelegation ? String(model.orchestration.pendingDelegation.round) : DASH],
331
+ ['pending_artifact', model.orchestration.pendingDelegation?.artifact ?? DASH],
332
+ ['pending_client', model.orchestration.pendingDelegation?.client ?? DASH],
333
+ ['pending_status', model.orchestration.pendingDelegation?.status ?? DASH]
334
+ ]));
287
335
  lines.push('', 'Workflow', ...renderPairs([
288
336
  ['state', model.workflow.state],
289
337
  ['step', model.workflow.step],
@@ -313,6 +361,12 @@ function renderStatus(model) {
313
361
  return lines;
314
362
  }
315
363
  function modelTone(model) {
364
+ if (model.orchestration.status === 'paused')
365
+ return 'warning';
366
+ if (model.orchestration.status === 'running')
367
+ return 'running';
368
+ if (model.orchestration.status === 'completed')
369
+ return 'success';
316
370
  if (model.workflow.state === 'in-progress')
317
371
  return model.workflow.stale === 'yes' ? 'warning' : 'running';
318
372
  if (model.metadata.some(([key, value]) => key === 'status' && value === 'completed'))
@@ -337,6 +391,7 @@ function buildFromResolved(input) {
337
391
  artifacts: { count: artifacts.length, groups: groupArtifacts(artifacts) },
338
392
  workflow,
339
393
  runtime: collectRuntime(input.taskDir, workflow, run),
394
+ orchestration: collectOrchestration(input.taskDir),
340
395
  git: collectGit(fm.branch ?? '', run)
341
396
  };
342
397
  }
@@ -359,6 +414,9 @@ function buildStatusModel(refOrInput, options = {}) {
359
414
  }
360
415
  function statusModelToDisplay(model) {
361
416
  return statusCard(`Task ${model.taskId} (${model.shortId})`, modelTone(model), [
417
+ ['orchestration', model.orchestration.status],
418
+ ['run', model.orchestration.runId],
419
+ ['next', model.orchestration.nextStage],
362
420
  ['workflow', model.workflow.state],
363
421
  ['step', model.workflow.step],
364
422
  ['runtime', model.runtime.status],
@@ -393,5 +451,5 @@ function status(args = []) {
393
451
  process.stdout.write(`${line}\n`);
394
452
  }
395
453
  }
396
- export { status, makeRunner, buildStatusModel, collectMetadata, groupArtifacts, collectGit, collectWorkflow, collectRuntime, renderStatus, statusModelToDisplay, METADATA_KEYS };
454
+ export { status, makeRunner, buildStatusModel, collectMetadata, groupArtifacts, collectGit, collectWorkflow, collectRuntime, collectOrchestration, renderStatus, statusModelToDisplay, METADATA_KEYS };
397
455
  //# sourceMappingURL=status.js.map