@fitlab-ai/agent-infra 0.9.7 → 0.9.9

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 (195) 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/claude-code.js +3 -3
  5. package/dist/lib/agent-clients/adapters/codex-lifecycle/app-server.js +60 -22
  6. package/dist/lib/agent-clients/adapters/codex-lifecycle/build-identity.js +8 -1
  7. package/dist/lib/agent-clients/adapters/codex-lifecycle/capability-store.js +175 -11
  8. package/dist/lib/agent-clients/adapters/codex-lifecycle/controller-context.js +147 -0
  9. package/dist/lib/agent-clients/adapters/codex-lifecycle/evidence.js +14 -0
  10. package/dist/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.js +86 -69
  11. package/dist/lib/agent-clients/adapters/codex-lifecycle/store.js +2 -1
  12. package/dist/lib/decide.js +68 -14
  13. package/dist/lib/git/workflow.js +10 -1
  14. package/dist/lib/init.js +1 -1
  15. package/dist/lib/internal/codex-lifecycle.js +19 -5
  16. package/dist/lib/internal/codex-sandbox-controller.js +6 -13
  17. package/dist/lib/internal/git-workflow.js +5 -7
  18. package/dist/lib/internal/platform-pr.js +20 -7
  19. package/dist/lib/internal/release-workflow.js +3 -4
  20. package/dist/lib/internal/sandbox-control.js +79 -2
  21. package/dist/lib/internal/task-activity.js +57 -7
  22. package/dist/lib/internal/task-event.js +57 -4
  23. package/dist/lib/internal/task-finalization.js +54 -0
  24. package/dist/lib/internal/task-ledger.js +59 -5
  25. package/dist/lib/internal/task-lifecycle.js +59 -8
  26. package/dist/lib/internal/task-orchestration.js +161 -288
  27. package/dist/lib/internal/task-override.js +131 -0
  28. package/dist/lib/internal/task-review.js +64 -6
  29. package/dist/lib/internal/task-verify.js +65 -3
  30. package/dist/lib/internal/task-warning.js +57 -4
  31. package/dist/lib/platform/pr-summary.js +53 -13
  32. package/dist/lib/platform/pull-requests.js +205 -41
  33. package/dist/lib/runtime/agent-runtime.js +56 -0
  34. package/dist/lib/sandbox/commands/create.js +389 -311
  35. package/dist/lib/sandbox/commands/rm.js +316 -55
  36. package/dist/lib/sandbox/control/client.js +190 -6
  37. package/dist/lib/sandbox/control/container-identity.js +1 -1
  38. package/dist/lib/sandbox/control/controller-registration.js +273 -0
  39. package/dist/lib/sandbox/control/executor.js +145 -5
  40. package/dist/lib/sandbox/control/lifecycle.js +395 -73
  41. package/dist/lib/sandbox/control/protocol.js +67 -6
  42. package/dist/lib/sandbox/control/state.js +27 -11
  43. package/dist/lib/sandbox/engine.js +14 -7
  44. package/dist/lib/sandbox/index.js +5 -3
  45. package/dist/lib/sandbox/managed-fs.js +5 -0
  46. package/dist/lib/sandbox/mounts.js +20 -5
  47. package/dist/lib/sandbox/recovery.js +78 -10
  48. package/dist/lib/sandbox/task-resolver.js +50 -6
  49. package/dist/lib/sandbox/workspace-identity.js +27 -0
  50. package/dist/lib/sandbox/workspace-view.js +62 -40
  51. package/dist/lib/sandbox/worktree-safety.js +215 -2
  52. package/dist/lib/server/process-state.js +51 -1
  53. package/dist/lib/task/activity-intent.js +4 -1
  54. package/dist/lib/task/codex-orchestration.js +158 -33
  55. package/dist/lib/task/commands/status.js +59 -1
  56. package/dist/lib/task/commit-operation.js +335 -0
  57. package/dist/lib/task/commit-policy.js +18 -0
  58. package/dist/lib/task/decision-intents.js +4 -2
  59. package/dist/lib/task/delegation-receipts.js +279 -17
  60. package/dist/lib/task/events.js +9 -5
  61. package/dist/lib/task/finalization.js +567 -0
  62. package/dist/lib/task/guard-override.js +31 -0
  63. package/dist/lib/task/human-override.js +1240 -0
  64. package/dist/lib/task/ledger-intents.js +6 -3
  65. package/dist/lib/task/lifecycle.js +69 -14
  66. package/dist/lib/task/operation-outcome.js +33 -0
  67. package/dist/lib/task/orchestration.js +199 -719
  68. package/dist/lib/task/review-finalization.js +3 -2
  69. package/dist/lib/task/short-id.js +59 -1
  70. package/dist/lib/task/task-execution-lock.js +6 -1
  71. package/dist/lib/task/verification-engine.js +138 -59
  72. package/dist/lib/task/verification.js +15 -2
  73. package/dist/lib/task/workflow-warning-intents.js +54 -3
  74. package/dist/lib/task/write.js +2 -1
  75. package/dist/lifecycle-build-manifest.json +3 -3
  76. package/lib/agent-clients/adapters/claude-code.ts +3 -3
  77. package/lib/agent-clients/adapters/codex-lifecycle/app-server.ts +63 -20
  78. package/lib/agent-clients/adapters/codex-lifecycle/build-identity.ts +12 -0
  79. package/lib/agent-clients/adapters/codex-lifecycle/capability-store.ts +278 -13
  80. package/lib/agent-clients/adapters/codex-lifecycle/controller-context.ts +180 -0
  81. package/lib/agent-clients/adapters/codex-lifecycle/evidence.ts +19 -0
  82. package/lib/agent-clients/adapters/codex-lifecycle/manifest-files.json +9 -1
  83. package/lib/agent-clients/adapters/codex-lifecycle/sandbox-controller.ts +112 -93
  84. package/lib/agent-clients/adapters/codex-lifecycle/store.ts +2 -1
  85. package/lib/decide.ts +59 -14
  86. package/lib/git/workflow.ts +11 -2
  87. package/lib/init.ts +1 -1
  88. package/lib/internal/codex-lifecycle.ts +18 -5
  89. package/lib/internal/codex-sandbox-controller.ts +6 -12
  90. package/lib/internal/git-workflow.ts +5 -6
  91. package/lib/internal/platform-pr.ts +14 -7
  92. package/lib/internal/release-workflow.ts +3 -4
  93. package/lib/internal/sandbox-control.ts +92 -2
  94. package/lib/internal/task-activity.ts +46 -6
  95. package/lib/internal/task-event.ts +53 -4
  96. package/lib/internal/task-finalization.ts +68 -0
  97. package/lib/internal/task-ledger.ts +48 -4
  98. package/lib/internal/task-lifecycle.ts +56 -12
  99. package/lib/internal/task-orchestration.ts +32 -107
  100. package/lib/internal/task-override.ts +138 -0
  101. package/lib/internal/task-review.ts +51 -6
  102. package/lib/internal/task-verify.ts +52 -3
  103. package/lib/internal/task-warning.ts +44 -3
  104. package/lib/platform/pr-summary.ts +65 -14
  105. package/lib/platform/pull-requests.ts +211 -41
  106. package/lib/runtime/agent-runtime.ts +76 -0
  107. package/lib/sandbox/commands/create.ts +88 -4
  108. package/lib/sandbox/commands/rm.ts +413 -61
  109. package/lib/sandbox/config.ts +2 -1
  110. package/lib/sandbox/control/client.ts +255 -6
  111. package/lib/sandbox/control/container-identity.ts +3 -3
  112. package/lib/sandbox/control/controller-registration.ts +347 -0
  113. package/lib/sandbox/control/executor.ts +172 -6
  114. package/lib/sandbox/control/lifecycle.ts +465 -77
  115. package/lib/sandbox/control/protocol.ts +85 -9
  116. package/lib/sandbox/control/state.ts +35 -18
  117. package/lib/sandbox/engine.ts +20 -9
  118. package/lib/sandbox/index.ts +5 -3
  119. package/lib/sandbox/managed-fs.ts +5 -0
  120. package/lib/sandbox/mounts.ts +23 -5
  121. package/lib/sandbox/recovery.ts +90 -9
  122. package/lib/sandbox/task-resolver.ts +58 -7
  123. package/lib/sandbox/workspace-identity.ts +50 -2
  124. package/lib/sandbox/workspace-view.ts +73 -43
  125. package/lib/sandbox/worktree-safety.ts +236 -2
  126. package/lib/server/process-state.ts +48 -1
  127. package/lib/task/activity-intent.ts +4 -2
  128. package/lib/task/codex-orchestration.ts +167 -33
  129. package/lib/task/commands/status.ts +78 -1
  130. package/lib/task/commit-operation.ts +430 -0
  131. package/lib/task/commit-policy.ts +30 -0
  132. package/lib/task/decision-intents.ts +4 -2
  133. package/lib/task/delegation-receipts.ts +304 -19
  134. package/lib/task/events.ts +10 -5
  135. package/lib/task/finalization.ts +719 -0
  136. package/lib/task/guard-override.ts +50 -0
  137. package/lib/task/human-override.ts +1503 -0
  138. package/lib/task/ledger-intents.ts +6 -3
  139. package/lib/task/lifecycle.ts +71 -14
  140. package/lib/task/operation-outcome.ts +48 -0
  141. package/lib/task/orchestration.ts +239 -922
  142. package/lib/task/review-finalization.ts +6 -2
  143. package/lib/task/short-id.ts +65 -1
  144. package/lib/task/task-execution-lock.ts +10 -1
  145. package/lib/task/verification-engine.ts +145 -64
  146. package/lib/task/verification.ts +18 -3
  147. package/lib/task/workflow-warning-intents.ts +61 -4
  148. package/lib/task/write.ts +4 -1
  149. package/package.json +2 -2
  150. package/templates/.agents/QUICKSTART.en.md +2 -2
  151. package/templates/.agents/QUICKSTART.zh-CN.md +2 -2
  152. package/templates/.agents/hooks/lifecycle-delegation.js +9 -24
  153. package/templates/.agents/rules/lifecycle-orchestration.en.md +4 -3
  154. package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +4 -3
  155. package/templates/.agents/rules/task-management.en.md +2 -2
  156. package/templates/.agents/rules/task-management.zh-CN.md +2 -2
  157. package/templates/.agents/skills/block-task/SKILL.en.md +2 -4
  158. package/templates/.agents/skills/block-task/SKILL.zh-CN.md +2 -4
  159. package/templates/.agents/skills/cancel-task/SKILL.en.md +3 -3
  160. package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +3 -3
  161. package/templates/.agents/skills/close-codescan/SKILL.en.md +6 -2
  162. package/templates/.agents/skills/close-codescan/SKILL.zh-CN.md +6 -2
  163. package/templates/.agents/skills/close-dependabot/SKILL.en.md +6 -2
  164. package/templates/.agents/skills/close-dependabot/SKILL.zh-CN.md +6 -2
  165. package/templates/.agents/skills/commit/SKILL.en.md +41 -125
  166. package/templates/.agents/skills/commit/SKILL.zh-CN.md +52 -123
  167. package/templates/.agents/skills/commit/reference/commit-message.en.md +1 -1
  168. package/templates/.agents/skills/commit/reference/commit-message.zh-CN.md +1 -1
  169. package/templates/.agents/skills/commit/reference/commit-orchestration.en.md +14 -43
  170. package/templates/.agents/skills/commit/reference/commit-orchestration.zh-CN.md +14 -49
  171. package/templates/.agents/skills/commit/reference/pr-summary-sync.en.md +1 -1
  172. package/templates/.agents/skills/commit/reference/pr-summary-sync.zh-CN.md +1 -1
  173. package/templates/.agents/skills/commit/reference/task-status-update.en.md +2 -35
  174. package/templates/.agents/skills/commit/reference/task-status-update.zh-CN.md +2 -35
  175. package/templates/.agents/skills/complete-task/SKILL.en.md +31 -38
  176. package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +31 -38
  177. package/templates/.agents/skills/complete-task/config/verify.en.json +1 -0
  178. package/templates/.agents/skills/complete-task/config/verify.zh-CN.json +1 -0
  179. package/templates/.agents/skills/complete-task/reference/external-delivery.en.md +1 -1
  180. package/templates/.agents/skills/complete-task/reference/external-delivery.zh-CN.md +1 -1
  181. package/templates/.agents/skills/create-pr/SKILL.en.md +6 -4
  182. package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +6 -4
  183. package/templates/.agents/skills/create-pr/reference/comment-publish.en.md +2 -2
  184. package/templates/.agents/skills/create-pr/reference/comment-publish.zh-CN.md +2 -2
  185. package/templates/.agents/skills/run-task/SKILL.en.md +5 -5
  186. package/templates/.agents/skills/run-task/SKILL.zh-CN.md +5 -5
  187. package/templates/.agents/skills/run-task/reference/host-validation.en.md +3 -1
  188. package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +3 -1
  189. package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.en.md +1 -1
  190. package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.zh-CN.md +1 -1
  191. package/templates/.codex/hooks.json +4 -4
  192. package/dist/lib/task/commit-finalization.js +0 -305
  193. package/dist/lib/task/commit-intent.js +0 -165
  194. package/lib/task/commit-finalization.ts +0 -419
  195. package/lib/task/commit-intent.ts +0 -230
@@ -1,8 +1,7 @@
1
- import { normalizeAgentToken, AGENT_USAGE_HINT } from '../agent-clients/tokens.js';
2
- import { abortCommitIntent, activateMatchingOrchestrationDelegation, activateOrchestrationDelegation, advanceOrchestration, awaitOrchestrationDelegationActivation, beginCommitIntent, beginOrResumeOrchestration, checkpointCommitIntent, completeCommitIntent, dispatchOrchestrationDelegation, pauseOrchestration, recoverCommitIntent, recoverPreparedOrchestrationDelegation, routeOrchestration, sealMatchingOrchestrationDelegation, sealOrchestrationDelegation, startCommitAttempt, statusCommitIntent, statusOrchestration, terminateCommitAttempt } from '../task/orchestration.js';
1
+ import { activateMatchingOrchestrationDelegation, activateOrchestrationDelegation, advanceOrchestration, awaitOrchestrationDelegationActivation, beginOrResumeOrchestration, dispatchOrchestrationDelegation, OrchestrationStateError, pauseOrchestration, recoverPreparedOrchestrationDelegation, routeOrchestration, sealMatchingOrchestrationDelegation, sealOrchestrationDelegation, statusOrchestration } from '../task/orchestration.js';
3
2
  import { prepareCodexOrchestrationDelegation } from '../task/codex-orchestration.js';
4
3
  import { isAgentClientId } from '../agent-clients/types.js';
5
- const USAGE = 'Usage: agent-infra-internal task-orchestration <task-ref|auto> <begin-or-resume|route|prepare|dispatch|await-activation|recover-prepared|hook-start|hook-stop|advance|pause|status|commit-start|commit-begin|commit-checkpoint|commit-complete|commit-recover|commit-abort|commit-terminate|commit-status> [options]\n';
4
+ const USAGE = 'Usage: agent-infra-internal task-orchestration <task-ref|auto> <begin-or-resume|route|prepare|dispatch|await-activation|recover-prepared|hook-start|hook-stop|advance|pause|status> [options]\n';
6
5
  function usageFailure(message) {
7
6
  process.stdout.write(`${JSON.stringify({
8
7
  status: 'failed', changed: false,
@@ -23,26 +22,15 @@ async function taskOrchestration(args = []) {
23
22
  const [taskRef, intent] = args;
24
23
  if (![
25
24
  'begin-or-resume', 'route', 'prepare', 'dispatch', 'await-activation', 'recover-prepared',
26
- 'hook-start', 'hook-stop', 'advance', 'pause', 'status',
27
- 'commit-start', 'commit-begin', 'commit-checkpoint', 'commit-complete', 'commit-recover', 'commit-abort', 'commit-terminate', 'commit-status'
25
+ 'hook-start', 'hook-stop', 'advance', 'pause', 'status'
28
26
  ].includes(intent)) {
29
27
  usageFailure(`unknown intent '${intent}'`);
30
28
  return;
31
29
  }
32
30
  const values = {};
33
31
  const seen = new Set();
34
- let orchestrated = false;
35
32
  for (let index = 2; index < args.length; index += 1) {
36
33
  const flag = args[index];
37
- if (flag === '--orchestrated') {
38
- if (seen.has(flag)) {
39
- usageFailure(`duplicate option '${flag}'`);
40
- return;
41
- }
42
- seen.add(flag);
43
- orchestrated = true;
44
- continue;
45
- }
46
34
  if (![
47
35
  '--max-steps', '--executor-model', '--executor-reasoning-effort',
48
36
  '--reviewer-model', '--reviewer-reasoning-effort',
@@ -52,8 +40,7 @@ async function taskOrchestration(args = []) {
52
40
  '--native-agent', '--child-id', '--spawn-mode', '--actual-model', '--actual-reasoning-effort',
53
41
  '--model-fallback-reason', '--reasoning-effort-fallback-reason',
54
42
  '--exit-code', '--after-fingerprint', '--changed-paths', '--code', '--message', '--recoverable', '--agent',
55
- '--baseline-head', '--token', '--kind', '--head', '--remote', '--ref', '--expected-head',
56
- '--attempt', '--git-worktree-root'
43
+ '--git-worktree-root'
57
44
  ].includes(flag)) {
58
45
  usageFailure(`unknown option '${flag}'`);
59
46
  return;
@@ -70,33 +57,6 @@ async function taskOrchestration(args = []) {
70
57
  }
71
58
  values[flag] = value;
72
59
  }
73
- const commitIntentFlags = {
74
- 'commit-start': ['--agent', '--git-worktree-root'],
75
- 'commit-begin': ['--agent', '--baseline-head', '--attempt', '--orchestrated', '--git-worktree-root'],
76
- 'commit-checkpoint': ['--token', '--kind', '--head', '--remote', '--ref', '--git-worktree-root'],
77
- 'commit-complete': ['--token', '--agent', '--git-worktree-root'],
78
- 'commit-recover': ['--agent', '--git-worktree-root'],
79
- 'commit-abort': ['--token', '--expected-head', '--git-worktree-root'],
80
- 'commit-terminate': ['--attempt', '--agent', '--code', '--git-worktree-root'],
81
- 'commit-status': ['--git-worktree-root']
82
- };
83
- if (intent in commitIntentFlags) {
84
- const allowed = commitIntentFlags[intent];
85
- const invalid = [...seen].find((flag) => !allowed.includes(flag));
86
- if (invalid) {
87
- usageFailure(`intent '${intent}' does not accept '${invalid}'`);
88
- return;
89
- }
90
- }
91
- else {
92
- const commitOnly = [...seen].find((flag) => [
93
- '--orchestrated', '--baseline-head', '--attempt', '--token', '--kind', '--head', '--remote', '--ref', '--expected-head'
94
- ].includes(flag));
95
- if (commitOnly) {
96
- usageFailure(`intent '${intent}' does not accept '${commitOnly}'`);
97
- return;
98
- }
99
- }
100
60
  const requireValues = (flags) => flags.find((flag) => values[flag] === undefined);
101
61
  const coreOptions = values['--git-worktree-root'] === undefined
102
62
  ? {}
@@ -106,265 +66,178 @@ async function taskOrchestration(args = []) {
106
66
  return;
107
67
  }
108
68
  let result;
109
- if (intent === 'commit-start') {
110
- const missing = requireValues(['--agent']);
111
- if (missing) {
112
- usageFailure(`intent 'commit-start' requires '${missing}'`);
113
- return;
114
- }
115
- const agent = normalizeAgentToken(values['--agent']);
116
- if (!agent) {
117
- usageFailure(`invalid --agent '${values['--agent']}': ${AGENT_USAGE_HINT}`);
118
- return;
119
- }
120
- result = startCommitAttempt(taskRef, { agent }, coreOptions);
121
- }
122
- else if (intent === 'commit-begin') {
123
- const missing = requireValues(['--agent', '--baseline-head', '--attempt']);
124
- if (missing) {
125
- usageFailure(`intent 'commit-begin' requires '${missing}'`);
126
- return;
127
- }
128
- const agent = normalizeAgentToken(values['--agent']);
129
- if (!agent) {
130
- usageFailure(`invalid --agent '${values['--agent']}': ${AGENT_USAGE_HINT}`);
131
- return;
132
- }
133
- result = beginCommitIntent(taskRef, {
134
- agent, orchestrated, baselineHead: values['--baseline-head'], attempt: values['--attempt']
135
- }, coreOptions);
136
- }
137
- else if (intent === 'commit-checkpoint') {
138
- const missing = requireValues(['--token', '--kind', '--head']);
139
- if (missing) {
140
- usageFailure(`intent 'commit-checkpoint' requires '${missing}'`);
141
- return;
142
- }
143
- if (!['committed', 'pushed'].includes(values['--kind'])) {
144
- usageFailure('--kind must be committed or pushed');
145
- return;
146
- }
147
- if (values['--kind'] === 'pushed') {
148
- const pushedMissing = requireValues(['--remote', '--ref']);
149
- if (pushedMissing) {
150
- usageFailure(`pushed checkpoint requires '${pushedMissing}'`);
69
+ try {
70
+ if (intent === 'begin-or-resume') {
71
+ const missing = requireValues(['--client']);
72
+ if (missing) {
73
+ usageFailure(`intent 'begin-or-resume' requires '${missing}'`);
151
74
  return;
152
75
  }
153
- }
154
- else if (values['--remote'] !== undefined || values['--ref'] !== undefined) {
155
- usageFailure('committed checkpoint does not accept --remote or --ref');
156
- return;
157
- }
158
- result = checkpointCommitIntent(taskRef, {
159
- token: values['--token'], kind: values['--kind'],
160
- head: values['--head'], remote: values['--remote'], ref: values['--ref']
161
- }, coreOptions);
162
- }
163
- else if (intent === 'commit-complete') {
164
- const missing = requireValues(['--token', '--agent']);
165
- if (missing) {
166
- usageFailure(`intent 'commit-complete' requires '${missing}'`);
167
- return;
168
- }
169
- const agent = normalizeAgentToken(values['--agent']);
170
- if (!agent) {
171
- usageFailure(`invalid --agent '${values['--agent']}': ${AGENT_USAGE_HINT}`);
172
- return;
173
- }
174
- result = completeCommitIntent(taskRef, { token: values['--token'], agent }, coreOptions);
175
- }
176
- else if (intent === 'commit-recover') {
177
- const missing = requireValues(['--agent']);
178
- if (missing) {
179
- usageFailure(`intent 'commit-recover' requires '${missing}'`);
180
- return;
181
- }
182
- const agent = normalizeAgentToken(values['--agent']);
183
- if (!agent) {
184
- usageFailure(`invalid --agent '${values['--agent']}': ${AGENT_USAGE_HINT}`);
185
- return;
186
- }
187
- result = recoverCommitIntent(taskRef, { agent }, coreOptions);
188
- }
189
- else if (intent === 'commit-abort') {
190
- const missing = requireValues(['--token', '--expected-head']);
191
- if (missing) {
192
- usageFailure(`intent 'commit-abort' requires '${missing}'`);
193
- return;
194
- }
195
- result = abortCommitIntent(taskRef, { token: values['--token'], expectedHead: values['--expected-head'] }, coreOptions);
196
- }
197
- else if (intent === 'commit-terminate') {
198
- const missing = requireValues(['--attempt', '--agent', '--code']);
199
- if (missing) {
200
- usageFailure(`intent 'commit-terminate' requires '${missing}'`);
201
- return;
202
- }
203
- const agent = normalizeAgentToken(values['--agent']);
204
- if (!agent) {
205
- usageFailure(`invalid --agent '${values['--agent']}': ${AGENT_USAGE_HINT}`);
206
- return;
207
- }
208
- if (!/^[A-Z][A-Z0-9_]{2,63}$/.test(values['--code'])) {
209
- usageFailure('--code must be a stable uppercase identifier');
210
- return;
211
- }
212
- result = terminateCommitAttempt(taskRef, {
213
- attempt: values['--attempt'], agent, code: values['--code']
214
- }, coreOptions);
215
- }
216
- else if (intent === 'commit-status') {
217
- result = statusCommitIntent(taskRef, coreOptions);
218
- }
219
- else if (intent === 'begin-or-resume') {
220
- const missing = requireValues(['--client']);
221
- if (missing) {
222
- usageFailure(`intent 'begin-or-resume' requires '${missing}'`);
223
- return;
224
- }
225
- const maxSteps = values['--max-steps'] === undefined ? undefined : Number(values['--max-steps']);
226
- if (maxSteps !== undefined && (!Number.isInteger(maxSteps) || maxSteps < 1)) {
227
- usageFailure('--max-steps must be a positive integer');
228
- return;
229
- }
230
- const policyFlags = [
231
- '--executor-model', '--executor-reasoning-effort',
232
- '--reviewer-model', '--reviewer-reasoning-effort'
233
- ];
234
- const hasAnyPolicy = policyFlags.some((flag) => values[flag] !== undefined);
235
- if (hasAnyPolicy && policyFlags.some((flag) => values[flag] === undefined)) {
236
- usageFailure('explicit model policy requires executor/reviewer model and reasoning effort');
237
- return;
238
- }
239
- result = beginOrResumeOrchestration(taskRef, {
240
- ...coreOptions,
241
- maxSteps,
242
- client: values['--client'],
243
- modelPolicy: hasAnyPolicy ? {
244
- executor: {
245
- model: values['--executor-model'],
246
- reasoningEffort: values['--executor-reasoning-effort']
247
- },
248
- reviewer: {
249
- model: values['--reviewer-model'],
250
- reasoningEffort: values['--reviewer-reasoning-effort']
251
- }
252
- } : undefined
253
- });
254
- }
255
- else if (intent === 'route') {
256
- result = routeOrchestration(taskRef, coreOptions);
257
- }
258
- else if (intent === 'status') {
259
- result = statusOrchestration(taskRef, coreOptions);
260
- }
261
- else if (intent === 'prepare') {
262
- const missing = requireValues(['--client']);
263
- if (missing) {
264
- usageFailure(`intent 'prepare' requires '${missing}'`);
265
- return;
266
- }
267
- result = await prepareCodexOrchestrationDelegation(taskRef, {
268
- client: values['--client'],
269
- requestedModel: values['--requested-model'],
270
- requestedReasoningEffort: values['--requested-reasoning-effort'],
271
- capabilityToken: values['--capability-token']
272
- }, { orchestrationOptions: coreOptions });
273
- }
274
- else if (intent === 'dispatch') {
275
- result = dispatchOrchestrationDelegation(taskRef, coreOptions);
276
- }
277
- else if (intent === 'await-activation') {
278
- const missing = requireValues(['--stage', '--round', '--artifact', '--role']);
279
- if (missing) {
280
- usageFailure(`intent 'await-activation' requires '${missing}'`);
281
- return;
282
- }
283
- const round = Number(values['--round']);
284
- if (!Number.isSafeInteger(round) || round < 1) {
285
- usageFailure('--round must be a positive integer');
286
- return;
287
- }
288
- if (!['executor', 'reviewer'].includes(values['--role'])) {
289
- usageFailure('--role must be executor or reviewer');
290
- return;
291
- }
292
- result = await awaitOrchestrationDelegationActivation(taskRef, {
293
- stage: values['--stage'],
294
- round,
295
- artifact: values['--artifact'],
296
- role: values['--role']
297
- }, coreOptions);
298
- }
299
- else if (intent === 'recover-prepared') {
300
- result = recoverPreparedOrchestrationDelegation(taskRef, coreOptions);
301
- }
302
- else if (intent === 'hook-start') {
303
- const missing = requireValues([
304
- ...(taskRef === 'auto' ? ['--client'] : []),
305
- '--native-agent', '--child-id', '--parent-id', '--spawn-mode'
306
- ]);
307
- if (missing) {
308
- usageFailure(`intent 'hook-start' requires '${missing}'`);
309
- return;
310
- }
311
- const event = {
312
- nativeAgent: values['--native-agent'], childId: values['--child-id'],
313
- parentId: values['--parent-id'], spawnMode: values['--spawn-mode'],
314
- actualModel: values['--actual-model'],
315
- actualReasoningEffort: values['--actual-reasoning-effort'],
316
- modelFallbackReason: values['--model-fallback-reason'],
317
- reasoningEffortFallbackReason: values['--reasoning-effort-fallback-reason']
318
- };
319
- result = taskRef === 'auto'
320
- ? activateMatchingOrchestrationDelegation(values['--client'], event, coreOptions)
321
- : activateOrchestrationDelegation(taskRef, event, coreOptions);
322
- }
323
- else if (intent === 'hook-stop') {
324
- if (taskRef === 'auto') {
325
- const missing = requireValues(['--client', '--native-agent', '--child-id']);
76
+ const maxSteps = values['--max-steps'] === undefined ? undefined : Number(values['--max-steps']);
77
+ if (maxSteps !== undefined && (!Number.isInteger(maxSteps) || maxSteps < 1)) {
78
+ usageFailure('--max-steps must be a positive integer');
79
+ return;
80
+ }
81
+ const policyFlags = [
82
+ '--executor-model', '--executor-reasoning-effort',
83
+ '--reviewer-model', '--reviewer-reasoning-effort'
84
+ ];
85
+ const hasAnyPolicy = policyFlags.some((flag) => values[flag] !== undefined);
86
+ if (hasAnyPolicy && policyFlags.some((flag) => values[flag] === undefined)) {
87
+ usageFailure('explicit model policy requires executor/reviewer model and reasoning effort');
88
+ return;
89
+ }
90
+ result = beginOrResumeOrchestration(taskRef, {
91
+ ...coreOptions,
92
+ maxSteps,
93
+ client: values['--client'],
94
+ modelPolicy: hasAnyPolicy ? {
95
+ executor: {
96
+ model: values['--executor-model'],
97
+ reasoningEffort: values['--executor-reasoning-effort']
98
+ },
99
+ reviewer: {
100
+ model: values['--reviewer-model'],
101
+ reasoningEffort: values['--reviewer-reasoning-effort']
102
+ }
103
+ } : undefined
104
+ });
105
+ }
106
+ else if (intent === 'route') {
107
+ result = routeOrchestration(taskRef, coreOptions);
108
+ }
109
+ else if (intent === 'status') {
110
+ result = statusOrchestration(taskRef, coreOptions);
111
+ }
112
+ else if (intent === 'prepare') {
113
+ const missing = requireValues(['--client']);
326
114
  if (missing) {
327
- usageFailure(`intent 'hook-stop' requires '${missing}'`);
115
+ usageFailure(`intent 'prepare' requires '${missing}'`);
328
116
  return;
329
117
  }
330
- result = sealMatchingOrchestrationDelegation(values['--client'], {
331
- nativeAgent: values['--native-agent'], childId: values['--child-id']
332
- }, coreOptions);
333
- }
334
- else {
335
- const missing = requireValues(['--child-id', '--exit-code', '--after-fingerprint']);
118
+ result = await prepareCodexOrchestrationDelegation(taskRef, {
119
+ client: values['--client'],
120
+ requestedModel: values['--requested-model'],
121
+ requestedReasoningEffort: values['--requested-reasoning-effort'],
122
+ capabilityToken: values['--capability-token']
123
+ }, { orchestrationOptions: coreOptions });
124
+ }
125
+ else if (intent === 'dispatch') {
126
+ result = dispatchOrchestrationDelegation(taskRef, coreOptions);
127
+ }
128
+ else if (intent === 'await-activation') {
129
+ const missing = requireValues(['--stage', '--round', '--artifact', '--role']);
336
130
  if (missing) {
337
- usageFailure(`intent 'hook-stop' requires '${missing}'`);
131
+ usageFailure(`intent 'await-activation' requires '${missing}'`);
338
132
  return;
339
133
  }
340
- const exitCode = Number(values['--exit-code']);
341
- if (!Number.isInteger(exitCode)) {
342
- usageFailure('--exit-code must be an integer');
134
+ const round = Number(values['--round']);
135
+ if (!Number.isSafeInteger(round) || round < 1) {
136
+ usageFailure('--round must be a positive integer');
343
137
  return;
344
138
  }
345
- result = sealOrchestrationDelegation(taskRef, {
346
- childId: values['--child-id'], exitCode,
347
- afterFingerprint: values['--after-fingerprint'],
348
- changedPaths: values['--changed-paths'] ? values['--changed-paths'].split(',').filter(Boolean) : []
139
+ if (!['executor', 'reviewer'].includes(values['--role'])) {
140
+ usageFailure('--role must be executor or reviewer');
141
+ return;
142
+ }
143
+ result = await awaitOrchestrationDelegationActivation(taskRef, {
144
+ stage: values['--stage'],
145
+ round,
146
+ artifact: values['--artifact'],
147
+ role: values['--role']
349
148
  }, coreOptions);
350
149
  }
351
- }
352
- else if (intent === 'advance') {
353
- result = advanceOrchestration(taskRef, coreOptions);
354
- }
355
- else {
356
- const missing = requireValues(['--code', '--message', '--recoverable']);
357
- if (missing) {
358
- usageFailure(`intent 'pause' requires '${missing}'`);
359
- return;
150
+ else if (intent === 'recover-prepared') {
151
+ result = recoverPreparedOrchestrationDelegation(taskRef, coreOptions);
360
152
  }
361
- if (!['true', 'false'].includes(values['--recoverable'])) {
362
- usageFailure('--recoverable must be true or false');
363
- return;
153
+ else if (intent === 'hook-start') {
154
+ const missing = requireValues([
155
+ ...(taskRef === 'auto' ? ['--client'] : []),
156
+ '--native-agent', '--child-id', '--parent-id'
157
+ ]);
158
+ if (missing) {
159
+ usageFailure(`intent 'hook-start' requires '${missing}'`);
160
+ return;
161
+ }
162
+ const event = {
163
+ nativeAgent: values['--native-agent'], childId: values['--child-id'],
164
+ parentId: values['--parent-id'], spawnMode: values['--spawn-mode'],
165
+ actualModel: values['--actual-model'],
166
+ actualReasoningEffort: values['--actual-reasoning-effort'],
167
+ modelFallbackReason: values['--model-fallback-reason'],
168
+ reasoningEffortFallbackReason: values['--reasoning-effort-fallback-reason']
169
+ };
170
+ result = taskRef === 'auto'
171
+ ? activateMatchingOrchestrationDelegation(values['--client'], event, coreOptions)
172
+ : activateOrchestrationDelegation(taskRef, event, coreOptions);
173
+ }
174
+ else if (intent === 'hook-stop') {
175
+ if (taskRef === 'auto') {
176
+ const missing = requireValues(['--client', '--native-agent', '--child-id']);
177
+ if (missing) {
178
+ usageFailure(`intent 'hook-stop' requires '${missing}'`);
179
+ return;
180
+ }
181
+ result = sealMatchingOrchestrationDelegation(values['--client'], {
182
+ nativeAgent: values['--native-agent'], childId: values['--child-id'],
183
+ actualModel: values['--actual-model'],
184
+ actualReasoningEffort: values['--actual-reasoning-effort'],
185
+ modelFallbackReason: values['--model-fallback-reason'],
186
+ reasoningEffortFallbackReason: values['--reasoning-effort-fallback-reason']
187
+ }, coreOptions);
188
+ }
189
+ else {
190
+ const missing = requireValues(['--child-id', '--exit-code', '--after-fingerprint']);
191
+ if (missing) {
192
+ usageFailure(`intent 'hook-stop' requires '${missing}'`);
193
+ return;
194
+ }
195
+ const exitCode = Number(values['--exit-code']);
196
+ if (!Number.isInteger(exitCode)) {
197
+ usageFailure('--exit-code must be an integer');
198
+ return;
199
+ }
200
+ result = sealOrchestrationDelegation(taskRef, {
201
+ childId: values['--child-id'], exitCode,
202
+ afterFingerprint: values['--after-fingerprint'],
203
+ changedPaths: values['--changed-paths'] ? values['--changed-paths'].split(',').filter(Boolean) : [],
204
+ actualModel: values['--actual-model'],
205
+ actualReasoningEffort: values['--actual-reasoning-effort'],
206
+ modelFallbackReason: values['--model-fallback-reason'],
207
+ reasoningEffortFallbackReason: values['--reasoning-effort-fallback-reason']
208
+ }, coreOptions);
209
+ }
210
+ }
211
+ else if (intent === 'advance') {
212
+ result = advanceOrchestration(taskRef, coreOptions);
364
213
  }
365
- result = pauseOrchestration(taskRef, values['--code'], values['--message'], values['--recoverable'] === 'true', coreOptions);
214
+ else {
215
+ const missing = requireValues(['--code', '--message', '--recoverable']);
216
+ if (missing) {
217
+ usageFailure(`intent 'pause' requires '${missing}'`);
218
+ return;
219
+ }
220
+ if (!['true', 'false'].includes(values['--recoverable'])) {
221
+ usageFailure('--recoverable must be true or false');
222
+ return;
223
+ }
224
+ result = pauseOrchestration(taskRef, values['--code'], values['--message'], values['--recoverable'] === 'true', coreOptions);
225
+ }
226
+ }
227
+ catch (error) {
228
+ if (!(error instanceof OrchestrationStateError))
229
+ throw error;
230
+ result = {
231
+ status: 'failed',
232
+ changed: false,
233
+ taskId: error.taskId,
234
+ run: null,
235
+ next: null,
236
+ error: { code: error.code, message: error.message }
237
+ };
366
238
  }
367
- process.stdout.write(`${JSON.stringify(result)}\n`);
239
+ const output = result;
240
+ process.stdout.write(`${JSON.stringify(output)}\n`);
368
241
  if (result.status === 'failed')
369
242
  process.exitCode = 1;
370
243
  }
@@ -0,0 +1,131 @@
1
+ import { consumeHumanOverride, diagnoseHumanOverrideForTask, issueHumanOverride } from '../task/human-override.js';
2
+ import { resolveTaskRef } from '../task/resolve-ref.js';
3
+ import { TaskExecutionLockError, withTaskExecutionLock } from '../task/task-execution-lock.js';
4
+ const USAGE = `Usage: agent-infra-internal task-override <task-ref> <diagnose|issue|consume> [options]
5
+
6
+ Options: --failure-id <id> --target <target> --operator <operator> --reason <reason> --scope <scope>
7
+ --intent <lifecycle-intent> --alert-number <N> --issue-number <N> --staging-dir <path>
8
+ --expires-at <timestamp> --ticket <ticket-id> --pr-number <N>
9
+ `;
10
+ const FLAGS = {
11
+ '--failure-id': 'failureId',
12
+ '--target': 'target',
13
+ '--operator': 'operator',
14
+ '--reason': 'reason',
15
+ '--scope': 'scope',
16
+ '--intent': 'intent',
17
+ '--failure-digest': 'failureDigest',
18
+ '--expires-at': 'expiresAt',
19
+ '--ticket': 'ticketId',
20
+ '--facts': 'observedFacts',
21
+ '--alert-number': 'alertNumber',
22
+ '--issue-number': 'issueNumber',
23
+ '--pr-number': 'pullRequestNumber',
24
+ '--staging-dir': 'stagingDir'
25
+ };
26
+ function usageFailure(message) {
27
+ process.stdout.write(`${JSON.stringify({ status: 'failed', changed: false, error: { code: 'OVERRIDE_PAYLOAD_INVALID', message } })}\n`);
28
+ process.stderr.write(USAGE);
29
+ process.exitCode = 1;
30
+ }
31
+ function taskOverride(args = []) {
32
+ if (args[0] === '--help' || args[0] === '-h') {
33
+ process.stdout.write(USAGE);
34
+ return;
35
+ }
36
+ const [taskRef, operation] = args;
37
+ if (!taskRef || !operation || !['diagnose', 'issue', 'consume'].includes(operation)) {
38
+ usageFailure('task ref and a valid operation are required');
39
+ return;
40
+ }
41
+ const values = { taskRef };
42
+ const seen = new Set();
43
+ for (let index = 2; index < args.length; index += 1) {
44
+ const flag = args[index];
45
+ const key = FLAGS[flag];
46
+ if (!key) {
47
+ usageFailure(`unknown option '${flag}'`);
48
+ return;
49
+ }
50
+ if (seen.has(flag)) {
51
+ usageFailure(`duplicate option '${flag}'`);
52
+ return;
53
+ }
54
+ const value = args[++index];
55
+ if (value === undefined || value.startsWith('--')) {
56
+ usageFailure(`option '${flag}' requires a value`);
57
+ return;
58
+ }
59
+ seen.add(flag);
60
+ values[key] = key === 'observedFacts' ? value.split(',').map((fact) => fact.trim()).filter(Boolean)
61
+ : key === 'alertNumber' || key === 'issueNumber' || key === 'pullRequestNumber' ? Number(value) : value;
62
+ }
63
+ const required = {
64
+ diagnose: [],
65
+ issue: ['failureId', 'target', 'operator', 'reason', 'scope', 'expiresAt'],
66
+ consume: ['failureId', 'target', 'scope', 'ticketId']
67
+ };
68
+ const missing = required[operation].find((key) => values[key] === undefined);
69
+ if (missing) {
70
+ usageFailure(`${operation} requires '--${missing.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}'`);
71
+ return;
72
+ }
73
+ const resolved = resolveTaskRef(taskRef);
74
+ if (!resolved.ok) {
75
+ process.stdout.write(`${JSON.stringify({ status: 'failed', changed: false, error: { code: resolved.code, message: resolved.message } })}\n`);
76
+ process.exitCode = 1;
77
+ return;
78
+ }
79
+ let result;
80
+ try {
81
+ if (operation === 'diagnose') {
82
+ result = diagnoseHumanOverrideForTask(taskRef, values.failureId ? String(values.failureId) : undefined, values.target ? String(values.target) : undefined);
83
+ }
84
+ else if (operation === 'issue') {
85
+ result = withTaskExecutionLock(resolved.repoRoot, resolved.taskId, 'task-override.issue', () => issueHumanOverride({
86
+ taskRef,
87
+ failureId: String(values.failureId),
88
+ target: String(values.target),
89
+ operator: String(values.operator),
90
+ reason: String(values.reason),
91
+ scope: String(values.scope),
92
+ expiresAt: String(values.expiresAt),
93
+ ...(values.intent ? { intent: String(values.intent) } : {}),
94
+ ...(values.alertNumber !== undefined ? { alertNumber: Number(values.alertNumber) } : {}),
95
+ ...(values.issueNumber !== undefined ? { issueNumber: Number(values.issueNumber) } : {}),
96
+ ...(values.pullRequestNumber !== undefined ? { pullRequestNumber: Number(values.pullRequestNumber) } : {}),
97
+ ...(values.stagingDir ? { stagingDir: String(values.stagingDir) } : {}),
98
+ ...(values.failureDigest ? { failureDigest: String(values.failureDigest) } : {})
99
+ }));
100
+ }
101
+ else {
102
+ result = withTaskExecutionLock(resolved.repoRoot, resolved.taskId, 'task-override.consume', () => consumeHumanOverride({
103
+ taskRef,
104
+ ticketId: String(values.ticketId),
105
+ failureId: String(values.failureId),
106
+ target: String(values.target),
107
+ scope: String(values.scope),
108
+ ...(values.intent ? { intent: String(values.intent) } : {}),
109
+ ...(values.alertNumber !== undefined ? { alertNumber: Number(values.alertNumber) } : {}),
110
+ ...(values.issueNumber !== undefined ? { issueNumber: Number(values.issueNumber) } : {}),
111
+ ...(values.pullRequestNumber !== undefined ? { pullRequestNumber: Number(values.pullRequestNumber) } : {}),
112
+ ...(values.stagingDir ? { stagingDir: String(values.stagingDir) } : {}),
113
+ ...(values.failureDigest ? { failureDigest: String(values.failureDigest) } : {}),
114
+ ...(values.observedFacts ? { observedFacts: values.observedFacts } : {})
115
+ }));
116
+ }
117
+ }
118
+ catch (cause) {
119
+ if (cause instanceof TaskExecutionLockError) {
120
+ process.stdout.write(`${JSON.stringify({ status: 'failed', changed: false, error: { code: cause.code, message: cause.message } })}\n`);
121
+ process.exitCode = 1;
122
+ return;
123
+ }
124
+ throw cause;
125
+ }
126
+ process.stdout.write(`${JSON.stringify(result)}\n`);
127
+ if (result.status === 'failed')
128
+ process.exitCode = 1;
129
+ }
130
+ export { taskOverride };
131
+ //# sourceMappingURL=task-override.js.map