@fitlab-ai/agent-infra 0.12.0 → 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.
Files changed (331) hide show
  1. package/README.md +0 -2
  2. package/README.zh-CN.md +0 -2
  3. package/dist/bin/internal-cli.js +2 -17
  4. package/dist/lib/agent-clients/adapter.js +0 -13
  5. package/dist/lib/agent-clients/adapters/antigravity-cli.js +0 -5
  6. package/dist/lib/agent-clients/adapters/claude-code-credentials.js +0 -17
  7. package/dist/lib/agent-clients/adapters/claude-code.js +0 -9
  8. package/dist/lib/agent-clients/adapters/codex.js +0 -52
  9. package/dist/lib/agent-clients/adapters/opencode.js +0 -5
  10. package/dist/lib/agent-clients/adapters/traecli.js +0 -5
  11. package/dist/lib/agent-clients/config.js +19 -54
  12. package/dist/lib/agent-clients/registry.js +1 -12
  13. package/dist/lib/agent-clients/schema.js +0 -18
  14. package/dist/lib/agent-clients/tokens.js +1 -2
  15. package/dist/lib/agent-clients/types.js +0 -1
  16. package/dist/lib/decide.js +2 -0
  17. package/dist/lib/git/worktree-identity.js +1 -9
  18. package/dist/lib/internal/agent-client.js +2 -62
  19. package/dist/lib/internal/cli-route-inventory.js +1 -5
  20. package/dist/lib/internal/manual-validation.js +29 -27
  21. package/dist/lib/internal/platform-comment.js +56 -7
  22. package/dist/lib/internal/task-create.js +1 -1
  23. package/dist/lib/internal/task-event.js +1 -8
  24. package/dist/lib/internal/task-finalization.js +0 -1
  25. package/dist/lib/internal/task-lifecycle.js +2 -2
  26. package/dist/lib/internal/task-operation-registry.js +4 -20
  27. package/dist/lib/internal/task-review.js +4 -4
  28. package/dist/lib/platform/comment-safety.js +1 -7
  29. package/dist/lib/platform/in-label-sync.js +1 -14
  30. package/dist/lib/platform/issue-comments.js +373 -282
  31. package/dist/lib/platform/issue-summary-content.js +112 -0
  32. package/dist/lib/platform/issues.js +1 -1
  33. package/dist/lib/platform/operation-coordinator.js +4 -2
  34. package/dist/lib/platform/pr-change-report.js +176 -30
  35. package/dist/lib/platform/pr-checks.js +2 -8
  36. package/dist/lib/platform/pr-summary-content.js +54 -0
  37. package/dist/lib/platform/pr-summary.js +318 -284
  38. package/dist/lib/platform/provider-validation.js +0 -20
  39. package/dist/lib/platform/pull-requests.js +73 -84
  40. package/dist/lib/platform/releases.js +1 -43
  41. package/dist/lib/platform/summary-content-pipeline.js +18 -0
  42. package/dist/lib/platform/verification-required.js +0 -2
  43. package/dist/lib/platform/verification-sync.js +1 -79
  44. package/dist/lib/process-data/normalize.js +1 -185
  45. package/dist/lib/process-data/privacy.js +1 -16
  46. package/dist/lib/process-data/sources.js +2 -279
  47. package/dist/lib/render.js +0 -12
  48. package/dist/lib/run/index.js +15 -10
  49. package/dist/lib/run/skills.js +0 -3
  50. package/dist/lib/sandbox/commands/create.js +40 -53
  51. package/dist/lib/sandbox/commands/list-running.js +0 -18
  52. package/dist/lib/sandbox/commands/start.js +7 -8
  53. package/dist/lib/sandbox/constants.js +0 -6
  54. package/dist/lib/sandbox/control/client.js +0 -1
  55. package/dist/lib/sandbox/control/container-identity.js +1 -16
  56. package/dist/lib/sandbox/control/executor.js +0 -4
  57. package/dist/lib/sandbox/control/identity-sentinel.js +0 -7
  58. package/dist/lib/sandbox/control/lifecycle.js +21 -37
  59. package/dist/lib/sandbox/control/native-file-lock.js +0 -3
  60. package/dist/lib/sandbox/control/server.js +18 -38
  61. package/dist/lib/sandbox/control/state.js +1 -9
  62. package/dist/lib/sandbox/dockerfile.js +0 -6
  63. package/dist/lib/sandbox/engine.js +0 -14
  64. package/dist/lib/sandbox/engines/docker-exact-discovery.js +1 -4
  65. package/dist/lib/sandbox/engines/wsl2-paths.js +0 -3
  66. package/dist/lib/sandbox/recovery.js +24 -26
  67. package/dist/lib/sandbox/removal.js +67 -518
  68. package/dist/lib/sandbox/task-resolver.js +0 -41
  69. package/dist/lib/sandbox/tools.js +1 -4
  70. package/dist/lib/sandbox/workspace-view.js +1 -2
  71. package/dist/lib/server/display.js +0 -6
  72. package/dist/lib/task/activity-intent.js +45 -40
  73. package/dist/lib/task/activity-log.js +9 -16
  74. package/dist/lib/task/artifact-command.js +1 -1
  75. package/dist/lib/task/artifact-lifecycle.js +61 -63
  76. package/dist/lib/task/artifact-name.js +0 -6
  77. package/dist/lib/task/artifact-operations.js +3 -3
  78. package/dist/lib/task/capabilities.js +4 -5
  79. package/dist/lib/task/commands/log.js +0 -6
  80. package/dist/lib/task/commands/status.js +17 -60
  81. package/dist/lib/task/commit-operation.js +28 -39
  82. package/dist/lib/task/completion-facts.js +56 -43
  83. package/dist/lib/task/control-authority.js +23 -256
  84. package/dist/lib/task/control-recovery.js +3 -5
  85. package/dist/lib/task/create.js +2 -4
  86. package/dist/lib/task/decision-intents.js +8 -9
  87. package/dist/lib/task/delivery-target.js +1 -40
  88. package/dist/lib/task/events.js +84 -107
  89. package/dist/lib/task/finalization.js +60 -15
  90. package/dist/lib/task/ledger-intents.js +1 -1
  91. package/dist/lib/task/lifecycle-execution.js +38 -33
  92. package/dist/lib/task/lifecycle.js +49 -41
  93. package/dist/lib/task/local-artifact-finalization.js +1 -4
  94. package/dist/lib/task/manual-validation-evidence.js +1 -37
  95. package/dist/lib/task/platform-operation-recovery.js +151 -108
  96. package/dist/lib/task/pr-delivery-fact.js +2 -5
  97. package/dist/lib/task/qualification-confirmation.js +5 -7
  98. package/dist/lib/task/resolve-ref.js +1 -25
  99. package/dist/lib/task/review-command.js +2 -2
  100. package/dist/lib/task/review-finalization.js +1 -21
  101. package/dist/lib/task/review-fingerprint.js +0 -4
  102. package/dist/lib/task/secure-fs.js +0 -56
  103. package/dist/lib/task/short-id.js +1 -39
  104. package/dist/lib/task/skill-scope.js +0 -1
  105. package/dist/lib/task/verification-engine.js +58 -282
  106. package/dist/lib/task/verification.js +6 -3
  107. package/dist/lib/task/write.js +11 -1
  108. package/lib/agent-clients/adapter.ts +0 -76
  109. package/lib/agent-clients/adapters/antigravity-cli.ts +0 -5
  110. package/lib/agent-clients/adapters/claude-code-credentials.ts +0 -19
  111. package/lib/agent-clients/adapters/claude-code.ts +0 -9
  112. package/lib/agent-clients/adapters/codex.ts +0 -56
  113. package/lib/agent-clients/adapters/opencode.ts +0 -5
  114. package/lib/agent-clients/adapters/traecli.ts +0 -5
  115. package/lib/agent-clients/config.ts +20 -61
  116. package/lib/agent-clients/registry.ts +1 -34
  117. package/lib/agent-clients/schema.ts +0 -18
  118. package/lib/agent-clients/tokens.ts +1 -2
  119. package/lib/agent-clients/types.ts +0 -15
  120. package/lib/decide.ts +1 -0
  121. package/lib/git/worktree-identity.ts +0 -10
  122. package/lib/internal/agent-client.ts +2 -70
  123. package/lib/internal/cli-route-inventory.ts +1 -4
  124. package/lib/internal/manual-validation.ts +28 -27
  125. package/lib/internal/platform-comment.ts +46 -4
  126. package/lib/internal/task-create.ts +0 -1
  127. package/lib/internal/task-event.ts +1 -5
  128. package/lib/internal/task-finalization.ts +0 -1
  129. package/lib/internal/task-lifecycle.ts +3 -5
  130. package/lib/internal/task-operation-registry.ts +3 -19
  131. package/lib/internal/task-review.ts +4 -4
  132. package/lib/platform/comment-safety.ts +0 -10
  133. package/lib/platform/github-provider.ts +0 -2
  134. package/lib/platform/in-label-sync.ts +0 -16
  135. package/lib/platform/issue-comments.ts +478 -301
  136. package/lib/platform/issue-summary-content.ts +132 -0
  137. package/lib/platform/issues.ts +0 -2
  138. package/lib/platform/operation-coordinator.ts +4 -2
  139. package/lib/platform/pr-change-report.ts +165 -25
  140. package/lib/platform/pr-checks.ts +1 -10
  141. package/lib/platform/pr-review.ts +1 -1
  142. package/lib/platform/pr-summary-content.ts +60 -0
  143. package/lib/platform/pr-summary.ts +364 -257
  144. package/lib/platform/provider-bridge.ts +0 -1
  145. package/lib/platform/provider-loader.ts +1 -5
  146. package/lib/platform/provider-validation.ts +1 -49
  147. package/lib/platform/pull-requests.ts +64 -99
  148. package/lib/platform/releases.ts +1 -40
  149. package/lib/platform/summary-content-pipeline.ts +23 -0
  150. package/lib/platform/verification-required.ts +0 -2
  151. package/lib/platform/verification-sync.ts +0 -94
  152. package/lib/process-data/normalize.ts +1 -186
  153. package/lib/process-data/privacy.ts +2 -19
  154. package/lib/process-data/sources.ts +3 -283
  155. package/lib/render.ts +0 -15
  156. package/lib/run/index.ts +13 -7
  157. package/lib/run/skills.ts +0 -4
  158. package/lib/sandbox/commands/create.ts +37 -74
  159. package/lib/sandbox/commands/list-running.ts +0 -19
  160. package/lib/sandbox/commands/start.ts +7 -10
  161. package/lib/sandbox/constants.ts +0 -8
  162. package/lib/sandbox/control/client.ts +0 -1
  163. package/lib/sandbox/control/container-identity.ts +1 -16
  164. package/lib/sandbox/control/executor.ts +1 -5
  165. package/lib/sandbox/control/identity-sentinel.ts +0 -8
  166. package/lib/sandbox/control/lifecycle.ts +18 -51
  167. package/lib/sandbox/control/native-file-lock.ts +0 -8
  168. package/lib/sandbox/control/protocol.ts +0 -2
  169. package/lib/sandbox/control/server.ts +13 -39
  170. package/lib/sandbox/control/state.ts +1 -10
  171. package/lib/sandbox/dockerfile.ts +0 -11
  172. package/lib/sandbox/engine.ts +0 -17
  173. package/lib/sandbox/engines/docker-exact-discovery.ts +1 -5
  174. package/lib/sandbox/engines/wsl2-paths.ts +0 -4
  175. package/lib/sandbox/recovery.ts +24 -26
  176. package/lib/sandbox/removal.ts +58 -687
  177. package/lib/sandbox/shell.ts +1 -1
  178. package/lib/sandbox/task-resolver.ts +0 -48
  179. package/lib/sandbox/tools.ts +1 -5
  180. package/lib/sandbox/workspace-view.ts +2 -4
  181. package/lib/server/display.ts +0 -14
  182. package/lib/server/process-control.ts +1 -1
  183. package/lib/task/activity-intent.ts +36 -44
  184. package/lib/task/activity-log.ts +9 -22
  185. package/lib/task/artifact-command.ts +1 -1
  186. package/lib/task/artifact-lifecycle.ts +58 -67
  187. package/lib/task/artifact-name.ts +0 -7
  188. package/lib/task/artifact-operations.ts +3 -3
  189. package/lib/task/capabilities.ts +5 -6
  190. package/lib/task/commands/log.ts +0 -7
  191. package/lib/task/commands/status.ts +14 -79
  192. package/lib/task/commit-operation.ts +29 -51
  193. package/lib/task/completion-facts.ts +45 -42
  194. package/lib/task/control-authority.ts +27 -317
  195. package/lib/task/control-recovery.ts +2 -5
  196. package/lib/task/create.ts +2 -5
  197. package/lib/task/decision-intents.ts +5 -5
  198. package/lib/task/delivery-target.ts +0 -40
  199. package/lib/task/events.ts +89 -123
  200. package/lib/task/finalization.ts +52 -15
  201. package/lib/task/ledger-intents.ts +1 -1
  202. package/lib/task/lifecycle-execution.ts +37 -89
  203. package/lib/task/lifecycle.ts +48 -44
  204. package/lib/task/local-artifact-finalization.ts +0 -7
  205. package/lib/task/manual-validation-evidence.ts +1 -47
  206. package/lib/task/platform-operation-recovery.ts +117 -104
  207. package/lib/task/pr-delivery-fact.ts +2 -11
  208. package/lib/task/qualification-confirmation.ts +6 -6
  209. package/lib/task/resolve-ref.ts +0 -23
  210. package/lib/task/review-command.ts +2 -2
  211. package/lib/task/review-finalization.ts +1 -27
  212. package/lib/task/review-fingerprint.ts +0 -8
  213. package/lib/task/secure-fs.ts +0 -42
  214. package/lib/task/short-id.ts +0 -43
  215. package/lib/task/skill-scope.ts +0 -1
  216. package/lib/task/verification-engine.ts +56 -287
  217. package/lib/task/verification.ts +5 -5
  218. package/lib/task/write.ts +12 -1
  219. package/package.json +2 -2
  220. package/templates/.agents/README.en.md +1 -3
  221. package/templates/.agents/README.zh-CN.md +0 -2
  222. package/templates/.agents/rules/README.en.md +0 -1
  223. package/templates/.agents/rules/README.zh-CN.md +0 -1
  224. package/templates/.agents/rules/commit-and-pr.en.md +1 -1
  225. package/templates/.agents/rules/commit-and-pr.zh-CN.md +1 -1
  226. package/templates/.agents/rules/no-mid-flow-questions.en.md +0 -10
  227. package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +0 -10
  228. package/templates/.agents/rules/pr-sync.en.md +4 -2
  229. package/templates/.agents/rules/pr-sync.zh-CN.md +6 -9
  230. package/templates/.agents/rules/task-management.en.md +3 -3
  231. package/templates/.agents/rules/task-management.zh-CN.md +3 -3
  232. package/templates/.agents/skills/analyze-task/SKILL.en.md +3 -3
  233. package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +3 -3
  234. package/templates/.agents/skills/cancel-task/SKILL.en.md +2 -2
  235. package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +2 -2
  236. package/templates/.agents/skills/code-task/SKILL.en.md +2 -2
  237. package/templates/.agents/skills/code-task/SKILL.zh-CN.md +4 -4
  238. package/templates/.agents/skills/commit/SKILL.en.md +2 -2
  239. package/templates/.agents/skills/commit/SKILL.zh-CN.md +2 -2
  240. package/templates/.agents/skills/commit/reference/commit-orchestration.en.md +6 -6
  241. package/templates/.agents/skills/commit/reference/commit-orchestration.zh-CN.md +6 -6
  242. package/templates/.agents/skills/commit/reference/pr-summary-sync.en.md +1 -1
  243. package/templates/.agents/skills/commit/reference/pr-summary-sync.zh-CN.md +1 -1
  244. package/templates/.agents/skills/complete-manual-validation/reference/summary-update.en.md +2 -2
  245. package/templates/.agents/skills/complete-manual-validation/reference/summary-update.zh-CN.md +2 -2
  246. package/templates/.agents/skills/complete-task/SKILL.en.md +10 -25
  247. package/templates/.agents/skills/complete-task/SKILL.zh-CN.md +11 -26
  248. package/templates/.agents/skills/create-pr/SKILL.en.md +1 -1
  249. package/templates/.agents/skills/create-pr/SKILL.zh-CN.md +1 -1
  250. package/templates/.agents/skills/create-pr/reference/change-report.en.md +9 -2
  251. package/templates/.agents/skills/create-pr/reference/change-report.zh-CN.md +9 -2
  252. package/templates/.agents/skills/create-pr/reference/comment-publish.en.md +2 -2
  253. package/templates/.agents/skills/create-pr/reference/comment-publish.zh-CN.md +2 -2
  254. package/templates/.agents/skills/create-task/SKILL.en.md +0 -18
  255. package/templates/.agents/skills/create-task/SKILL.zh-CN.md +0 -18
  256. package/templates/.agents/skills/plan-task/SKILL.en.md +2 -2
  257. package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +2 -2
  258. package/templates/.agents/skills/review-analysis/SKILL.en.md +3 -3
  259. package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +3 -3
  260. package/templates/.agents/skills/review-code/SKILL.en.md +5 -5
  261. package/templates/.agents/skills/review-code/SKILL.zh-CN.md +5 -5
  262. package/templates/.agents/skills/review-plan/SKILL.en.md +3 -3
  263. package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +3 -3
  264. package/templates/.agents/skills/review-pr/SKILL.en.md +4 -4
  265. package/templates/.agents/skills/review-pr/SKILL.zh-CN.md +4 -4
  266. package/templates/.agents/skills/run-manual-validation/SKILL.en.md +1 -1
  267. package/templates/.agents/skills/run-manual-validation/SKILL.zh-CN.md +1 -1
  268. package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +3 -75
  269. package/templates/.agents/skills/watch-pr/SKILL.en.md +1 -1
  270. package/templates/.agents/skills/watch-pr/SKILL.zh-CN.md +1 -1
  271. package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.en.md +3 -3
  272. package/templates/.agents/skills/watch-pr/reference/monitor-and-heal.zh-CN.md +3 -3
  273. package/templates/.agents/templates/task.en.md +1 -0
  274. package/templates/.agents/templates/task.zh-CN.md +1 -0
  275. package/templates/.claude/settings.json +0 -24
  276. package/templates/.codex/hooks.json +0 -50
  277. package/dist/lib/agent-clients/adapters/codex-lifecycle/app-server.js +0 -582
  278. package/dist/lib/agent-clients/adapters/codex-lifecycle/binding.js +0 -114
  279. package/dist/lib/agent-clients/adapters/codex-lifecycle/build-identity.js +0 -237
  280. package/dist/lib/agent-clients/adapters/codex-lifecycle/cli.js +0 -443
  281. package/dist/lib/agent-clients/adapters/codex-lifecycle/evidence.js +0 -236
  282. package/dist/lib/agent-clients/adapters/codex-lifecycle/recovery.js +0 -292
  283. package/dist/lib/agent-clients/adapters/codex-lifecycle/store.js +0 -267
  284. package/dist/lib/agent-clients/adapters/codex-orchestration.js +0 -466
  285. package/dist/lib/internal/task-orchestration.js +0 -71
  286. package/dist/lib/platform/verification.js +0 -6
  287. package/dist/lib/run/prompt.js +0 -2
  288. package/dist/lib/sandbox/engines/authority.js +0 -289
  289. package/dist/lib/task/delegation-receipts.js +0 -410
  290. package/dist/lib/task/orchestration.js +0 -1233
  291. package/dist/lib/task/verification-checks.js +0 -9
  292. package/dist/lib/task/workspace-snapshot.js +0 -121
  293. package/dist/lifecycle-build-manifest.json +0 -6
  294. package/lib/agent-clients/adapters/codex-lifecycle/app-server.ts +0 -688
  295. package/lib/agent-clients/adapters/codex-lifecycle/binding.ts +0 -147
  296. package/lib/agent-clients/adapters/codex-lifecycle/build-identity.ts +0 -349
  297. package/lib/agent-clients/adapters/codex-lifecycle/cli.ts +0 -506
  298. package/lib/agent-clients/adapters/codex-lifecycle/evidence.ts +0 -385
  299. package/lib/agent-clients/adapters/codex-lifecycle/manifest-files.json +0 -41
  300. package/lib/agent-clients/adapters/codex-lifecycle/recovery.ts +0 -418
  301. package/lib/agent-clients/adapters/codex-lifecycle/store.ts +0 -354
  302. package/lib/agent-clients/adapters/codex-orchestration.ts +0 -630
  303. package/lib/internal/task-orchestration.ts +0 -74
  304. package/lib/platform/verification.ts +0 -11
  305. package/lib/run/prompt.ts +0 -1
  306. package/lib/sandbox/engines/authority.ts +0 -365
  307. package/lib/task/delegation-receipts.ts +0 -547
  308. package/lib/task/orchestration.ts +0 -1651
  309. package/lib/task/verification-checks.ts +0 -10
  310. package/lib/task/workspace-snapshot.ts +0 -144
  311. package/templates/.agents/hooks/lifecycle-delegation.js +0 -140
  312. package/templates/.agents/rules/lifecycle-orchestration.en.md +0 -44
  313. package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +0 -44
  314. package/templates/.agents/skills/run-task/SKILL.en.md +0 -29
  315. package/templates/.agents/skills/run-task/SKILL.zh-CN.md +0 -29
  316. package/templates/.agents/skills/run-task/config/verify.en.json +0 -10
  317. package/templates/.agents/skills/run-task/config/verify.zh-CN.json +0 -10
  318. package/templates/.agents/skills/run-task/reference/host-validation.en.md +0 -24
  319. package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +0 -24
  320. package/templates/.claude/agents/agent-infra-lifecycle-executor.en.md +0 -6
  321. package/templates/.claude/agents/agent-infra-lifecycle-executor.zh-CN.md +0 -6
  322. package/templates/.claude/agents/agent-infra-lifecycle-reviewer.en.md +0 -6
  323. package/templates/.claude/agents/agent-infra-lifecycle-reviewer.zh-CN.md +0 -6
  324. package/templates/.claude/commands/run-task.en.md +0 -8
  325. package/templates/.claude/commands/run-task.zh-CN.md +0 -8
  326. package/templates/.codex/agents/agent-infra-lifecycle-executor.en.toml +0 -3
  327. package/templates/.codex/agents/agent-infra-lifecycle-executor.zh-CN.toml +0 -3
  328. package/templates/.codex/agents/agent-infra-lifecycle-reviewer.en.toml +0 -3
  329. package/templates/.codex/agents/agent-infra-lifecycle-reviewer.zh-CN.toml +0 -3
  330. package/templates/.opencode/commands/run-task.en.md +0 -11
  331. package/templates/.opencode/commands/run-task.zh-CN.md +0 -11
@@ -1,418 +0,0 @@
1
- import fs from 'node:fs';
2
-
3
- import { createCodexLifecycleStore, readCodexLifecycleActivationEvidence } from './store.ts';
4
- import type { CodexLifecycleActivationEvidence, StoredCodexLifecycle } from './store.ts';
5
- import { managedDelegationRole } from '../../../task/delegation-receipts.ts';
6
- import type { DelegationReceipt } from '../../../task/delegation-receipts.ts';
7
- import { normalizeAgentToken } from '../../tokens.ts';
8
- import { locateActivityLog, pairEntries, appendActivityEntry } from '../../../task/activity-log.ts';
9
- import type { ActivityLogSection, StepRow } from '../../../task/activity-log.ts';
10
- import { captureTaskWriteMetadata, writeTask } from '../../../task/write.ts';
11
- import { parseTypedTaskFrontmatter } from '../../../task/frontmatter.ts';
12
- import { resolveTaskRef } from '../../../task/resolve-ref.ts';
13
- import {
14
- recoverActivatedOrchestrationDelegation,
15
- readRun
16
- } from '../../../task/orchestration.ts';
17
- import type { OrchestrationOptions, OrchestrationRun } from '../../../task/orchestration.ts';
18
- import type {
19
- AgentClientLifecycleRecoveryRequest,
20
- AgentClientLifecycleRecoveryResult
21
- } from '../../adapter.ts';
22
-
23
- const ACTIONS = {
24
- analysis: 'Analyze Task',
25
- 'review-analysis': 'Review Analysis',
26
- plan: 'Plan Task',
27
- 'review-plan': 'Review Plan',
28
- code: 'Code Task',
29
- 'review-code': 'Review Code'
30
- } as const;
31
-
32
- type RecoveryStage = keyof typeof ACTIONS;
33
- type LifecycleRecoveryRequest = AgentClientLifecycleRecoveryRequest;
34
- type LifecycleRecoveryResult = AgentClientLifecycleRecoveryResult;
35
- type LifecycleRecoveryOptions = Readonly<{
36
- repoRoot?: string;
37
- now?: () => string;
38
- orchestration?: Pick<OrchestrationOptions, 'diagnosticLog' | 'now'>;
39
- lifecycleStore?: ReturnType<typeof createCodexLifecycleStore>;
40
- writeTask?: typeof writeTask;
41
- }>;
42
-
43
- type RecoveryCandidate = Readonly<{
44
- receipt: DelegationReceipt;
45
- row: StepRow;
46
- }>;
47
-
48
- function result(
49
- request: LifecycleRecoveryRequest,
50
- status: LifecycleRecoveryResult['status'],
51
- extra: Partial<LifecycleRecoveryResult> = {}
52
- ): LifecycleRecoveryResult {
53
- return {
54
- status,
55
- changed: status === 'applied',
56
- targetState: 'active',
57
- requestRef: request.taskRef,
58
- intent: 'recover-started',
59
- taskId: null,
60
- receiptId: null,
61
- childId: null,
62
- error: null,
63
- ...extra
64
- };
65
- }
66
-
67
- function failure(
68
- request: LifecycleRecoveryRequest,
69
- status: 'owner-unknown' | 'conflict',
70
- code: string,
71
- message: string,
72
- extra: Partial<LifecycleRecoveryResult> = {}
73
- ): LifecycleRecoveryResult {
74
- return result(request, status, { error: { code, message }, ...extra });
75
- }
76
-
77
- function actionPattern(receipt: Pick<DelegationReceipt, 'stage' | 'round'>): RegExp | null {
78
- const action = ACTIONS[receipt.stage as RecoveryStage];
79
- if (!action) return null;
80
- const escaped = action.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
81
- return new RegExp(`^${escaped} \\(Round ${receipt.round}(?:, (?:fix for review-code(?:-r[2-9]|-r[1-9]\\d+)?.md|decision II-[1-9]\\d*))?\\)$`, 'u');
82
- }
83
-
84
- function openRows(section: ActivityLogSection): StepRow[] {
85
- return pairEntries([...section.entries]).filter((row) => row.started !== '' && row.done === '');
86
- }
87
-
88
- function rowForReceipt(rows: readonly StepRow[], receipt: DelegationReceipt): StepRow[] {
89
- const pattern = actionPattern(receipt);
90
- return pattern ? rows.filter((row) => pattern.test(row.step)) : [];
91
- }
92
-
93
- function readLifecycleStore(
94
- options: LifecycleRecoveryOptions,
95
- repoRoot: string,
96
- taskId: string
97
- ): ReturnType<typeof createCodexLifecycleStore> {
98
- return options.lifecycleStore ?? createCodexLifecycleStore({
99
- repoRoot,
100
- taskId,
101
- cliVersion: 'recovery',
102
- now: options.now
103
- });
104
- }
105
-
106
- function readStoredEvidence(
107
- store: ReturnType<typeof createCodexLifecycleStore>,
108
- childId: string
109
- ): StoredCodexLifecycle | { missing: true } | { error: Error } {
110
- try {
111
- return store.read(childId);
112
- } catch (error) {
113
- const message = error instanceof Error ? error.message : String(error);
114
- if (message.includes('was not found uniquely')) return { missing: true };
115
- return { error: error instanceof Error ? error : new Error(message) };
116
- }
117
- }
118
-
119
- function validateStopRecord(
120
- record: StoredCodexLifecycle,
121
- receipt: DelegationReceipt
122
- ): { ok: true } | { ok: false; code: string; message: string } {
123
- if (!stopRecordMatchesReceipt(record, receipt)) {
124
- return { ok: false, code: 'RECOVERY_TASK_BINDING_MISMATCH', message: 'lifecycle evidence belongs to a different task receipt' };
125
- }
126
- if (!stopEvidenceMatchesReceipt(record, receipt)) {
127
- return { ok: false, code: 'RECOVERY_STOP_EVIDENCE_INVALID', message: 'Codex stop evidence does not match the activated receipt' };
128
- }
129
- if (record.consumer !== null && record.consumer !== receipt.id) {
130
- return { ok: false, code: 'RECOVERY_CONSUMER_CONFLICT', message: `Codex lifecycle evidence was consumed by '${record.consumer}'` };
131
- }
132
- return { ok: true };
133
- }
134
-
135
- function stopRecordMatchesReceipt(record: StoredCodexLifecycle, receipt: DelegationReceipt): boolean {
136
- return record.taskBinding?.runId === receipt.runId
137
- && record.taskBinding.receiptId === receipt.id;
138
- }
139
-
140
- function stopEvidenceMatchesReceipt(record: StoredCodexLifecycle, receipt: DelegationReceipt): boolean {
141
- const start = record.state.startEvidence;
142
- const stop = record.state.stopEvidence;
143
- const host = readCodexLifecycleActivationEvidence(receipt);
144
- if (!stopRecordHasRequiredEvidence(record, receipt, start, stop, host)) return false;
145
- return spawnMatchesReceipt(record, receipt, host!, start!)
146
- && childMatchesReceipt(record, receipt, start!, stop!)
147
- && hostEvidenceMatches(record, receipt, host!, start!);
148
- }
149
-
150
- function stopRecordHasRequiredEvidence(
151
- record: StoredCodexLifecycle,
152
- receipt: DelegationReceipt,
153
- start: StoredCodexLifecycle['state']['startEvidence'],
154
- stop: StoredCodexLifecycle['state']['stopEvidence'],
155
- host: CodexLifecycleActivationEvidence | null
156
- ): boolean {
157
- return receipt.client === 'codex'
158
- && host?.kind === 'codex-lifecycle-v2'
159
- && Boolean(start && stop && record.state.spawn && record.state.child && record.state.stop)
160
- && record.state.status === 'stop-ready'
161
- && stop?.terminalStatus === 'completed'
162
- && stop.hookStopObserved === true;
163
- }
164
-
165
- function spawnMatchesReceipt(
166
- record: StoredCodexLifecycle,
167
- receipt: DelegationReceipt,
168
- host: CodexLifecycleActivationEvidence,
169
- start: NonNullable<StoredCodexLifecycle['state']['startEvidence']>
170
- ): boolean {
171
- const spawn = record.state.spawn;
172
- return Boolean(spawn)
173
- && spawn!.sessionId === start.parentThreadId
174
- && spawn!.turnId === host.capabilityTurnId
175
- && spawn!.toolUseId === host.spawnToolUseId
176
- && spawn!.nativeAgent === start.nativeAgent
177
- && spawn!.hookDefinitionHash === host.hookDefinitionHash
178
- && spawn!.requestedModel === receipt.requestedModel
179
- && spawn!.requestedReasoningEffort === receipt.requestedReasoningEffort
180
- && spawn!.taskBinding?.runId === receipt.runId
181
- && spawn!.taskBinding.receiptId === receipt.id;
182
- }
183
-
184
- function childMatchesReceipt(
185
- record: StoredCodexLifecycle,
186
- receipt: DelegationReceipt,
187
- start: NonNullable<StoredCodexLifecycle['state']['startEvidence']>,
188
- stop: NonNullable<StoredCodexLifecycle['state']['stopEvidence']>
189
- ): boolean {
190
- const child = record.state.child;
191
- const stopState = record.state.stop;
192
- return Boolean(child && stopState)
193
- && child!.sessionId === start.parentThreadId
194
- && stopState!.turnId === child!.turnId
195
- && (stopState!.source === 'parent-rollout'
196
- ? stop.turnId === record.state.terminal?.turnId
197
- : child!.turnId === stop.turnId)
198
- && child!.childThreadId === receipt.childId
199
- && child!.nativeAgent === start.nativeAgent
200
- && stopState!.childThreadId === receipt.childId
201
- && stopState!.nativeAgent === start.nativeAgent
202
- && start.childThreadId === receipt.childId
203
- && start.parentThreadId === receipt.parentId
204
- && managedDelegationRole(start.nativeAgent) === receipt.role;
205
- }
206
-
207
- function hostEvidenceMatches(
208
- record: StoredCodexLifecycle,
209
- receipt: DelegationReceipt,
210
- host: CodexLifecycleActivationEvidence,
211
- start: NonNullable<StoredCodexLifecycle['state']['startEvidence']>
212
- ): boolean {
213
- return start.hookDefinitionHash === host.hookDefinitionHash
214
- && host.capabilitySessionId === start.parentThreadId
215
- && host.capabilityTurnId === record.state.spawn?.turnId
216
- && host.spawnToolUseId === start.spawnToolUseId
217
- && Boolean(host.spawnObservedAt)
218
- && host.spawnObservedAt === record.spawnObservedAt
219
- && hostRevisionMatches(record, receipt, host);
220
- }
221
-
222
- function hostRevisionMatches(record: StoredCodexLifecycle, receipt: DelegationReceipt, host: CodexLifecycleActivationEvidence): boolean {
223
- return host.startRevision >= 1
224
- && record.revision > host.startRevision
225
- && record.state.child?.childThreadId === receipt.childId
226
- && record.state.stop?.childThreadId === receipt.childId;
227
- }
228
-
229
- function abortedCandidates(run: OrchestrationRun, rows: readonly StepRow[]): RecoveryCandidate[] {
230
- const candidates = run.receipts.flatMap((receipt) => {
231
- if (receipt.status !== 'aborted' || receipt.activatedAt === null || receipt.client !== 'codex') return [];
232
- const matches = rowForReceipt(rows, receipt);
233
- return matches.length === 1 ? [{ receipt, row: matches[0]! }] : [];
234
- });
235
- return candidates;
236
- }
237
-
238
- function appendRecoveryLog(
239
- request: LifecycleRecoveryRequest,
240
- taskId: string,
241
- section: ActivityLogSection,
242
- candidate: RecoveryCandidate,
243
- repoRoot: string,
244
- writer: typeof writeTask
245
- ): LifecycleRecoveryResult {
246
- const metadata = captureTaskWriteMetadata();
247
- const body = appendActivityEntry(section, {
248
- time: metadata.timestamp,
249
- step: `${candidate.row.step} [aborted]`,
250
- agent: request.agent,
251
- note: `terminated Codex delegation; receipt=${candidate.receipt.id}; child=${candidate.receipt.childId}`
252
- });
253
- const written = writer({
254
- taskRef: taskId,
255
- expectedState: 'active',
256
- mutations: [{ kind: 'section', aliases: ['活动日志', 'Activity Log'], heading: section.heading, body }]
257
- }, { repoRoot, metadataProvider: () => metadata });
258
- if (written.status === 'failed') {
259
- return failure(request, 'owner-unknown', 'RECOVERY_LOG_WRITE_FAILED', written.error.message, {
260
- taskId, receiptId: candidate.receipt.id, childId: candidate.receipt.childId
261
- });
262
- }
263
- return result(request, 'applied', {
264
- taskId, receiptId: candidate.receipt.id, childId: candidate.receipt.childId
265
- });
266
- }
267
-
268
- function recoverStartedLifecycle(
269
- request: LifecycleRecoveryRequest,
270
- options: LifecycleRecoveryOptions = {}
271
- ): LifecycleRecoveryResult {
272
- if (!request || request.intent !== 'recover-started' || request.auto !== true || normalizeAgentToken(request.agent) !== 'codex') {
273
- return failure(request, 'conflict', 'RECOVERY_PAYLOAD_INVALID', 'automatic recovery requires a task and the Codex agent');
274
- }
275
- const resolved = resolveTaskRef(request.taskRef, { repoRoot: options.repoRoot });
276
- if (!resolved.ok) return failure(request, 'conflict', resolved.code, resolved.message);
277
- const taskId = resolved.taskId;
278
- let content: string;
279
- try {
280
- content = fs.readFileSync(resolved.taskMdPath, 'utf8');
281
- parseTypedTaskFrontmatter(content);
282
- } catch (error) {
283
- return failure(request, 'conflict', 'RECOVERY_TASK_INVALID', error instanceof Error ? error.message : String(error), { taskId });
284
- }
285
- const section = locateActivityLog(content);
286
- if (!section) return failure(request, 'conflict', 'RECOVERY_LOG_INVALID', 'task has no unique Activity Log section', { taskId });
287
- let run: OrchestrationRun | null;
288
- try {
289
- run = readRun(resolved.taskDir, options.orchestration);
290
- } catch (error) {
291
- return failure(request, 'owner-unknown', 'RECOVERY_ORCHESTRATION_UNKNOWN', error instanceof Error ? error.message : String(error), { taskId });
292
- }
293
- if (!run) return result(request, 'no-op', { taskId });
294
-
295
- const rows = openRows(section);
296
- const pending = run.pendingDelegation;
297
- if (!pending) return recoverAbortedLifecycle(request, taskId, section, resolved.repoRoot, run, rows, options);
298
- return recoverActiveLifecycle(request, taskId, section, resolved.repoRoot, run, rows, pending, options);
299
- }
300
-
301
- function recoverAbortedLifecycle(
302
- request: LifecycleRecoveryRequest,
303
- taskId: string,
304
- section: ActivityLogSection,
305
- repoRoot: string,
306
- run: OrchestrationRun,
307
- rows: readonly StepRow[],
308
- options: LifecycleRecoveryOptions
309
- ): LifecycleRecoveryResult {
310
- const candidates = abortedCandidates(run, rows);
311
- if (candidates.length === 0) return result(request, 'no-op', { taskId });
312
- if (candidates.length > 1) {
313
- return failure(request, 'conflict', 'RECOVERY_CANDIDATE_AMBIGUOUS', 'more than one aborted delegation has an open lifecycle row', { taskId });
314
- }
315
- return appendRecoveryLog(request, taskId, section, candidates[0]!, repoRoot, options.writeTask ?? writeTask);
316
- }
317
-
318
- function recoverActiveLifecycle(
319
- request: LifecycleRecoveryRequest,
320
- taskId: string,
321
- section: ActivityLogSection,
322
- repoRoot: string,
323
- run: OrchestrationRun,
324
- rows: readonly StepRow[],
325
- pending: DelegationReceipt,
326
- options: LifecycleRecoveryOptions
327
- ): LifecycleRecoveryResult {
328
- if (pending.status !== 'activated') return result(request, 'no-op', { taskId });
329
- if (pending.client !== 'codex' || run.status !== 'running' || run.pause !== null) {
330
- return failure(request, 'conflict', 'RECOVERY_ORCHESTRATION_INVALID', 'activated recovery requires one running Codex delegation', {
331
- taskId, receiptId: pending.id, childId: pending.childId
332
- });
333
- }
334
- const rowResult = matchingActiveRecoveryRow(request, taskId, rows, pending);
335
- if ('result' in rowResult) return rowResult.result;
336
- const evidenceResult = consumeRecoveryEvidence(request, taskId, repoRoot, pending, options);
337
- if ('result' in evidenceResult) return evidenceResult.result;
338
- return finishActiveRecovery(request, taskId, section, repoRoot, pending, rowResult.row, options);
339
- }
340
-
341
- function matchingActiveRecoveryRow(
342
- request: LifecycleRecoveryRequest,
343
- taskId: string,
344
- rows: readonly StepRow[],
345
- pending: DelegationReceipt
346
- ): { row: StepRow } | { result: LifecycleRecoveryResult } {
347
- const matchingRows = rowForReceipt(rows, pending);
348
- if (matchingRows.length !== 1 || normalizeAgentToken(matchingRows[0]!.agent) !== 'codex' || matchingRows[0]!.note !== 'started') {
349
- return { result: failure(request, 'conflict', 'RECOVERY_LOG_CONFLICT', 'activated delegation does not have one matching open lifecycle row', {
350
- taskId, receiptId: pending.id, childId: pending.childId
351
- }) };
352
- }
353
- if (!pending.childId) {
354
- return { result: failure(request, 'conflict', 'RECOVERY_DELEGATION_INVALID', 'activated delegation has no child identity', { taskId, receiptId: pending.id }) };
355
- }
356
- return { row: matchingRows[0]! };
357
- }
358
-
359
- function consumeRecoveryEvidence(
360
- request: LifecycleRecoveryRequest,
361
- taskId: string,
362
- repoRoot: string,
363
- pending: DelegationReceipt,
364
- options: LifecycleRecoveryOptions
365
- ): { consumed: StoredCodexLifecycle } | { result: LifecycleRecoveryResult } {
366
- const store = readLifecycleStore(options, repoRoot, taskId);
367
- const stored = readStoredEvidence(store, pending.childId!);
368
- if ('error' in stored) return { result: failure(request, 'owner-unknown', 'RECOVERY_STORE_UNKNOWN', stored.error.message, { taskId, receiptId: pending.id, childId: pending.childId }) };
369
- if ('missing' in stored) return { result: failure(request, 'owner-unknown', 'RECOVERY_STOP_EVIDENCE_MISSING', 'matching Codex lifecycle stop evidence is missing', { taskId, receiptId: pending.id, childId: pending.childId }) };
370
- const evidence = validateStopRecord(stored, pending);
371
- if (!evidence.ok) return { result: failure(request, evidence.code === 'RECOVERY_CONSUMER_CONFLICT' ? 'conflict' : 'owner-unknown', evidence.code, evidence.message, { taskId, receiptId: pending.id, childId: pending.childId }) };
372
- let consumed = stored;
373
- if (stored.consumer === null) {
374
- try {
375
- consumed = store.consume(pending.childId!, pending.id, stored.state.startEvidence?.hookDefinitionHash, {
376
- taskId: pending.taskId, runId: pending.runId, receiptId: pending.id
377
- });
378
- } catch (error) {
379
- return { result: failure(request, 'owner-unknown', 'RECOVERY_EVIDENCE_CONSUME_FAILED', error instanceof Error ? error.message : String(error), { taskId, receiptId: pending.id, childId: pending.childId }) };
380
- }
381
- }
382
- return consumed.consumedAt
383
- ? { consumed }
384
- : { result: failure(request, 'owner-unknown', 'RECOVERY_EVIDENCE_INVALID', 'consumed stop evidence has no timestamp', { taskId, receiptId: pending.id, childId: pending.childId }) };
385
- }
386
-
387
- function finishActiveRecovery(
388
- request: LifecycleRecoveryRequest,
389
- taskId: string,
390
- section: ActivityLogSection,
391
- repoRoot: string,
392
- pending: DelegationReceipt,
393
- row: StepRow,
394
- options: LifecycleRecoveryOptions
395
- ): LifecycleRecoveryResult {
396
- const recovered = recoverActivatedOrchestrationDelegation(taskId, {
397
- receiptId: pending.id,
398
- stage: pending.stage,
399
- round: pending.round,
400
- artifact: pending.artifact,
401
- startedAgent: request.agent,
402
- childId: pending.childId!
403
- }, { ...options.orchestration, repoRoot, now: options.now });
404
- if (recovered.status === 'failed' || !recovered.run) {
405
- return failure(request, 'owner-unknown', recovered.error?.code ?? 'RECOVERY_ORCHESTRATION_FAILED', recovered.error?.message ?? 'orchestration recovery failed', { taskId, receiptId: pending.id, childId: pending.childId });
406
- }
407
- return appendRecoveryLog(request, taskId, section, { receipt: recovered.run.receipts.at(-1)!, row }, repoRoot, options.writeTask ?? writeTask);
408
- }
409
-
410
- function recoverStartedLifecycleFromAdapter(
411
- request: LifecycleRecoveryRequest,
412
- options: LifecycleRecoveryOptions = {}
413
- ): LifecycleRecoveryResult {
414
- return recoverStartedLifecycle(request, options);
415
- }
416
-
417
- export { recoverStartedLifecycle, recoverStartedLifecycleFromAdapter };
418
- export type { LifecycleRecoveryOptions, LifecycleRecoveryRequest, LifecycleRecoveryResult };