@ai-devkit/agent-manager 0.43.0 → 0.44.0

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 (444) hide show
  1. package/package.json +8 -3
  2. package/.swcrc +0 -27
  3. package/dist/__tests__/AgentManager.test.js +0 -1727
  4. package/dist/__tests__/AgentManager.test.js.map +0 -1
  5. package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js +0 -486
  6. package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js.map +0 -1
  7. package/dist/__tests__/adapters/adapterProcessImports.test.js +0 -52
  8. package/dist/__tests__/adapters/adapterProcessImports.test.js.map +0 -1
  9. package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js +0 -247
  10. package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js.map +0 -1
  11. package/dist/__tests__/capacity/anthropic.test.js +0 -115
  12. package/dist/__tests__/capacity/anthropic.test.js.map +0 -1
  13. package/dist/__tests__/capacity/boundaries.test.js +0 -45
  14. package/dist/__tests__/capacity/boundaries.test.js.map +0 -1
  15. package/dist/__tests__/capacity/claude.test.js +0 -485
  16. package/dist/__tests__/capacity/claude.test.js.map +0 -1
  17. package/dist/__tests__/capacity/codex.test.js +0 -339
  18. package/dist/__tests__/capacity/codex.test.js.map +0 -1
  19. package/dist/__tests__/capacity/devin.test.js +0 -239
  20. package/dist/__tests__/capacity/devin.test.js.map +0 -1
  21. package/dist/__tests__/capacity/index.test.js +0 -53
  22. package/dist/__tests__/capacity/index.test.js.map +0 -1
  23. package/dist/__tests__/capacity/openai.test.js +0 -687
  24. package/dist/__tests__/capacity/openai.test.js.map +0 -1
  25. package/dist/__tests__/capacity/wham.test.js +0 -159
  26. package/dist/__tests__/capacity/wham.test.js.map +0 -1
  27. package/dist/__tests__/capacity/zai.test.js +0 -212
  28. package/dist/__tests__/capacity/zai.test.js.map +0 -1
  29. package/dist/__tests__/fixtures.test.js +0 -218
  30. package/dist/__tests__/fixtures.test.js.map +0 -1
  31. package/dist/__tests__/harnesses/BoundedSummarySkip.test.js +0 -568
  32. package/dist/__tests__/harnesses/BoundedSummarySkip.test.js.map +0 -1
  33. package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js +0 -1089
  34. package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js.map +0 -1
  35. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js +0 -143
  36. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js.map +0 -1
  37. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js +0 -462
  38. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js.map +0 -1
  39. package/dist/__tests__/harnesses/builtinAdapters.test.js +0 -33
  40. package/dist/__tests__/harnesses/builtinAdapters.test.js.map +0 -1
  41. package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js +0 -79
  42. package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js.map +0 -1
  43. package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js +0 -1881
  44. package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js.map +0 -1
  45. package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js +0 -425
  46. package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js.map +0 -1
  47. package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js +0 -314
  48. package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js.map +0 -1
  49. package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js +0 -49
  50. package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js.map +0 -1
  51. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js +0 -76
  52. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js.map +0 -1
  53. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js +0 -173
  54. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js.map +0 -1
  55. package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js +0 -181
  56. package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js.map +0 -1
  57. package/dist/__tests__/harnesses/codex/CodexAdapter.test.js +0 -685
  58. package/dist/__tests__/harnesses/codex/CodexAdapter.test.js.map +0 -1
  59. package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js +0 -463
  60. package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js.map +0 -1
  61. package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js +0 -86
  62. package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js.map +0 -1
  63. package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js +0 -254
  64. package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js.map +0 -1
  65. package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js +0 -121
  66. package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js.map +0 -1
  67. package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js +0 -84
  68. package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js.map +0 -1
  69. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js +0 -128
  70. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js.map +0 -1
  71. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js +0 -246
  72. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js.map +0 -1
  73. package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js +0 -384
  74. package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js.map +0 -1
  75. package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js +0 -659
  76. package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js.map +0 -1
  77. package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js +0 -290
  78. package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js.map +0 -1
  79. package/dist/__tests__/harnesses/devin/DevinAdapter.test.js +0 -597
  80. package/dist/__tests__/harnesses/devin/DevinAdapter.test.js.map +0 -1
  81. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +0 -99
  82. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +0 -1
  83. package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js +0 -192
  84. package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js.map +0 -1
  85. package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js +0 -407
  86. package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js.map +0 -1
  87. package/dist/__tests__/harnesses/devin/fixtures.js +0 -95
  88. package/dist/__tests__/harnesses/devin/fixtures.js.map +0 -1
  89. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js +0 -1454
  90. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js.map +0 -1
  91. package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js +0 -491
  92. package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js.map +0 -1
  93. package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js +0 -399
  94. package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js.map +0 -1
  95. package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js +0 -56
  96. package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js.map +0 -1
  97. package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js +0 -421
  98. package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js.map +0 -1
  99. package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js +0 -167
  100. package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js.map +0 -1
  101. package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js +0 -133
  102. package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js.map +0 -1
  103. package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js +0 -301
  104. package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js.map +0 -1
  105. package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js +0 -662
  106. package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js.map +0 -1
  107. package/dist/__tests__/harnesses/muse/MuseAdapter.test.js +0 -247
  108. package/dist/__tests__/harnesses/muse/MuseAdapter.test.js.map +0 -1
  109. package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js +0 -81
  110. package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js.map +0 -1
  111. package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js +0 -185
  112. package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js.map +0 -1
  113. package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js +0 -328
  114. package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js.map +0 -1
  115. package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js +0 -213
  116. package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js.map +0 -1
  117. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js +0 -108
  118. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js.map +0 -1
  119. package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js +0 -94
  120. package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js.map +0 -1
  121. package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js +0 -147
  122. package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js.map +0 -1
  123. package/dist/__tests__/harnesses/pi/PiAdapter.test.js +0 -367
  124. package/dist/__tests__/harnesses/pi/PiAdapter.test.js.map +0 -1
  125. package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js +0 -382
  126. package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js.map +0 -1
  127. package/dist/__tests__/harnesses/pi/PiSessionParser.test.js +0 -416
  128. package/dist/__tests__/harnesses/pi/PiSessionParser.test.js.map +0 -1
  129. package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js +0 -108
  130. package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js.map +0 -1
  131. package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js +0 -70
  132. package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js.map +0 -1
  133. package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js +0 -43
  134. package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js.map +0 -1
  135. package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js +0 -192
  136. package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js.map +0 -1
  137. package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js +0 -119
  138. package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js.map +0 -1
  139. package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js +0 -382
  140. package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js.map +0 -1
  141. package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js +0 -34
  142. package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js.map +0 -1
  143. package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js +0 -446
  144. package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js.map +0 -1
  145. package/dist/__tests__/harnesses/runtimeProfiles.test.js +0 -101
  146. package/dist/__tests__/harnesses/runtimeProfiles.test.js.map +0 -1
  147. package/dist/__tests__/print/DurableAgent.test.js +0 -15
  148. package/dist/__tests__/print/DurableAgent.test.js.map +0 -1
  149. package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js +0 -186
  150. package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js.map +0 -1
  151. package/dist/__tests__/print/DurableAgentRepository.test.js +0 -249
  152. package/dist/__tests__/print/DurableAgentRepository.test.js.map +0 -1
  153. package/dist/__tests__/readiness-fixtures.test.js +0 -54
  154. package/dist/__tests__/readiness-fixtures.test.js.map +0 -1
  155. package/dist/__tests__/runtime/AgentRuntime.test.js +0 -13
  156. package/dist/__tests__/runtime/AgentRuntime.test.js.map +0 -1
  157. package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js +0 -164
  158. package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js.map +0 -1
  159. package/dist/__tests__/runtime/HerdrAgentRuntime.test.js +0 -488
  160. package/dist/__tests__/runtime/HerdrAgentRuntime.test.js.map +0 -1
  161. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js +0 -637
  162. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js.map +0 -1
  163. package/dist/__tests__/terminal/GhosttyBackend.test.js +0 -334
  164. package/dist/__tests__/terminal/GhosttyBackend.test.js.map +0 -1
  165. package/dist/__tests__/terminal/TerminalFocusManager.test.js +0 -253
  166. package/dist/__tests__/terminal/TerminalFocusManager.test.js.map +0 -1
  167. package/dist/__tests__/terminal/TmuxManager.test.js +0 -168
  168. package/dist/__tests__/terminal/TmuxManager.test.js.map +0 -1
  169. package/dist/__tests__/terminal/TtyWriter.test.js +0 -386
  170. package/dist/__tests__/terminal/TtyWriter.test.js.map +0 -1
  171. package/dist/__tests__/utils/AgentRegistry.test.js +0 -636
  172. package/dist/__tests__/utils/AgentRegistry.test.js.map +0 -1
  173. package/dist/__tests__/utils/IncrementalJsonlSummary.test.js +0 -650
  174. package/dist/__tests__/utils/IncrementalJsonlSummary.test.js.map +0 -1
  175. package/dist/__tests__/utils/agent-requests.test.js +0 -90
  176. package/dist/__tests__/utils/agent-requests.test.js.map +0 -1
  177. package/dist/__tests__/utils/conversationTail.bench.test.js +0 -258
  178. package/dist/__tests__/utils/conversationTail.bench.test.js.map +0 -1
  179. package/dist/__tests__/utils/conversationTailParity.test.js +0 -588
  180. package/dist/__tests__/utils/conversationTailParity.test.js.map +0 -1
  181. package/dist/__tests__/utils/jsonlTail.test.js +0 -360
  182. package/dist/__tests__/utils/jsonlTail.test.js.map +0 -1
  183. package/dist/__tests__/utils/matching.test.js +0 -324
  184. package/dist/__tests__/utils/matching.test.js.map +0 -1
  185. package/dist/__tests__/utils/matchingConstants.test.js +0 -35
  186. package/dist/__tests__/utils/matchingConstants.test.js.map +0 -1
  187. package/dist/__tests__/utils/process.test.js +0 -818
  188. package/dist/__tests__/utils/process.test.js.map +0 -1
  189. package/dist/__tests__/utils/session.test.js +0 -175
  190. package/dist/__tests__/utils/session.test.js.map +0 -1
  191. package/project.json +0 -29
  192. package/scripts/benchmark-cold-start.mjs +0 -350
  193. package/src/AgentManager.ts +0 -559
  194. package/src/__tests__/AgentManager.test.ts +0 -1578
  195. package/src/__tests__/adapters/IncrementalSessionRefresh.test.ts +0 -437
  196. package/src/__tests__/adapters/adapterProcessImports.test.ts +0 -58
  197. package/src/__tests__/adapters/adapterSnapshotCandidates.test.ts +0 -243
  198. package/src/__tests__/capacity/anthropic.test.ts +0 -105
  199. package/src/__tests__/capacity/boundaries.test.ts +0 -36
  200. package/src/__tests__/capacity/claude.test.ts +0 -462
  201. package/src/__tests__/capacity/codex.test.ts +0 -311
  202. package/src/__tests__/capacity/devin.test.ts +0 -210
  203. package/src/__tests__/capacity/fixtures/claude-credentials.json +0 -7
  204. package/src/__tests__/capacity/fixtures/claude-usage-malformed.json +0 -1
  205. package/src/__tests__/capacity/fixtures/claude-usage-partial.json +0 -15
  206. package/src/__tests__/capacity/fixtures/claude-usage.json +0 -63
  207. package/src/__tests__/capacity/fixtures/devin-config.json +0 -6
  208. package/src/__tests__/capacity/fixtures/devin-credentials.toml +0 -4
  209. package/src/__tests__/capacity/fixtures/devin-quota-nonplan.json +0 -5
  210. package/src/__tests__/capacity/fixtures/devin-quota.json +0 -10
  211. package/src/__tests__/capacity/fixtures/openai-auth.json +0 -6
  212. package/src/__tests__/capacity/fixtures/openai-codex-auth.json +0 -9
  213. package/src/__tests__/capacity/fixtures/openai-usage-completions.json +0 -67
  214. package/src/__tests__/capacity/fixtures/openai-usage-responses.json +0 -20
  215. package/src/__tests__/capacity/fixtures/wham-usage.json +0 -45
  216. package/src/__tests__/capacity/fixtures/zai-auth.json +0 -6
  217. package/src/__tests__/capacity/fixtures/zai-quota-invalid.json +0 -7
  218. package/src/__tests__/capacity/fixtures/zai-quota.json +0 -38
  219. package/src/__tests__/capacity/index.test.ts +0 -54
  220. package/src/__tests__/capacity/openai.test.ts +0 -571
  221. package/src/__tests__/capacity/wham.test.ts +0 -122
  222. package/src/__tests__/capacity/zai.test.ts +0 -151
  223. package/src/__tests__/fixtures.test.ts +0 -245
  224. package/src/__tests__/harnesses/BoundedSummarySkip.test.ts +0 -496
  225. package/src/__tests__/harnesses/SessionSummaryEquivalence.test.ts +0 -726
  226. package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.ts +0 -133
  227. package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.ts +0 -396
  228. package/src/__tests__/harnesses/builtinAdapters.test.ts +0 -33
  229. package/src/__tests__/harnesses/claude/ClaudeAgentMapper.test.ts +0 -84
  230. package/src/__tests__/harnesses/claude/ClaudeCodeAdapter.test.ts +0 -1793
  231. package/src/__tests__/harnesses/claude/ClaudeSessionLocator.test.ts +0 -423
  232. package/src/__tests__/harnesses/claude/ClaudeSessionParser.test.ts +0 -300
  233. package/src/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.ts +0 -34
  234. package/src/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.ts +0 -61
  235. package/src/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.ts +0 -129
  236. package/src/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.ts +0 -152
  237. package/src/__tests__/harnesses/codex/CodexAdapter.test.ts +0 -652
  238. package/src/__tests__/harnesses/codex/CodexSessionLocator.test.ts +0 -419
  239. package/src/__tests__/harnesses/codex/CodexSessionMapping.test.ts +0 -63
  240. package/src/__tests__/harnesses/codex/CodexSessionParser.test.ts +0 -192
  241. package/src/__tests__/harnesses/codex/durable/CodexCliProbe.test.ts +0 -80
  242. package/src/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.ts +0 -65
  243. package/src/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.ts +0 -104
  244. package/src/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.ts +0 -201
  245. package/src/__tests__/harnesses/codex/durable/CodexPrintRunner.test.ts +0 -299
  246. package/src/__tests__/harnesses/copilot/CopilotAdapter.test.ts +0 -614
  247. package/src/__tests__/harnesses/copilot/CopilotRefreshIO.test.ts +0 -270
  248. package/src/__tests__/harnesses/devin/DevinAdapter.test.ts +0 -290
  249. package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +0 -101
  250. package/src/__tests__/harnesses/devin/DevinSessionLocator.test.ts +0 -139
  251. package/src/__tests__/harnesses/devin/DevinSessionParser.test.ts +0 -212
  252. package/src/__tests__/harnesses/devin/fixtures.ts +0 -144
  253. package/src/__tests__/harnesses/gemini/GeminiCliAdapter.test.ts +0 -1336
  254. package/src/__tests__/harnesses/gemini/GeminiSessionJsonl.test.ts +0 -402
  255. package/src/__tests__/harnesses/gemini/GeminiSessionLocator.test.ts +0 -396
  256. package/src/__tests__/harnesses/grok/GrokAgentMapper.test.ts +0 -57
  257. package/src/__tests__/harnesses/grok/GrokCliAdapter.test.ts +0 -376
  258. package/src/__tests__/harnesses/grok/GrokIncrementalRefresh.test.ts +0 -170
  259. package/src/__tests__/harnesses/grok/GrokSessionLocator.test.ts +0 -106
  260. package/src/__tests__/harnesses/grok/GrokSessionParser.test.ts +0 -230
  261. package/src/__tests__/harnesses/kiro/KiroAdapter.test.ts +0 -552
  262. package/src/__tests__/harnesses/muse/MuseAdapter.test.ts +0 -197
  263. package/src/__tests__/harnesses/muse/MuseAgentMapper.test.ts +0 -83
  264. package/src/__tests__/harnesses/muse/MuseSessionLocator.test.ts +0 -177
  265. package/src/__tests__/harnesses/muse/MuseSessionParser.test.ts +0 -279
  266. package/src/__tests__/harnesses/opencode/OpenCodeAdapter.test.ts +0 -215
  267. package/src/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.ts +0 -101
  268. package/src/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.ts +0 -84
  269. package/src/__tests__/harnesses/opencode/OpenCodeSessionParser.test.ts +0 -149
  270. package/src/__tests__/harnesses/pi/PiAdapter.test.ts +0 -325
  271. package/src/__tests__/harnesses/pi/PiDiscoveryIO.test.ts +0 -337
  272. package/src/__tests__/harnesses/pi/PiSessionParser.test.ts +0 -280
  273. package/src/__tests__/harnesses/pi/PiSessionTracker.test.ts +0 -79
  274. package/src/__tests__/harnesses/pi/durable/PiCliProbe.test.ts +0 -50
  275. package/src/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.ts +0 -33
  276. package/src/__tests__/harnesses/pi/durable/PiPrintAgentService.test.ts +0 -138
  277. package/src/__tests__/harnesses/pi/durable/PiPrintProtocol.test.ts +0 -71
  278. package/src/__tests__/harnesses/pi/durable/PiPrintRunner.test.ts +0 -252
  279. package/src/__tests__/harnesses/pi/durable/PiStreamParser.test.ts +0 -26
  280. package/src/__tests__/harnesses/readiness/AgentReadiness.test.ts +0 -362
  281. package/src/__tests__/harnesses/runtimeProfiles.test.ts +0 -123
  282. package/src/__tests__/print/DurableAgent.test.ts +0 -15
  283. package/src/__tests__/print/DurableAgentRepository.sqlite.test.ts +0 -128
  284. package/src/__tests__/print/DurableAgentRepository.test.ts +0 -184
  285. package/src/__tests__/readiness-fixtures.test.ts +0 -79
  286. package/src/__tests__/runtime/AgentRuntime.test.ts +0 -8
  287. package/src/__tests__/runtime/HerdrAgentDiscovery.test.ts +0 -131
  288. package/src/__tests__/runtime/HerdrAgentRuntime.test.ts +0 -377
  289. package/src/__tests__/runtime/ManagedAgentRuntime.test.ts +0 -590
  290. package/src/__tests__/terminal/GhosttyBackend.test.ts +0 -271
  291. package/src/__tests__/terminal/TerminalFocusManager.test.ts +0 -280
  292. package/src/__tests__/terminal/TmuxManager.test.ts +0 -185
  293. package/src/__tests__/terminal/TtyWriter.test.ts +0 -454
  294. package/src/__tests__/utils/AgentRegistry.test.ts +0 -532
  295. package/src/__tests__/utils/IncrementalJsonlSummary.test.ts +0 -414
  296. package/src/__tests__/utils/agent-requests.test.ts +0 -94
  297. package/src/__tests__/utils/conversationTail.bench.test.ts +0 -193
  298. package/src/__tests__/utils/conversationTailParity.test.ts +0 -365
  299. package/src/__tests__/utils/jsonlTail.test.ts +0 -317
  300. package/src/__tests__/utils/matching.test.ts +0 -234
  301. package/src/__tests__/utils/matchingConstants.test.ts +0 -40
  302. package/src/__tests__/utils/process.test.ts +0 -596
  303. package/src/__tests__/utils/session.test.ts +0 -158
  304. package/src/adapters/AgentAdapter.ts +0 -255
  305. package/src/capacity/index.ts +0 -127
  306. package/src/capacity/providers/anthropic.ts +0 -198
  307. package/src/capacity/providers/devin.ts +0 -121
  308. package/src/capacity/providers/openai-platform.ts +0 -150
  309. package/src/capacity/providers/openai-subscription.ts +0 -184
  310. package/src/capacity/providers/zai.ts +0 -155
  311. package/src/capacity/sources/claude.ts +0 -30
  312. package/src/capacity/sources/codex.ts +0 -251
  313. package/src/capacity/sources/devin.ts +0 -49
  314. package/src/capacity/sources/pi.ts +0 -131
  315. package/src/capacity/types.ts +0 -29
  316. package/src/database/connection.ts +0 -96
  317. package/src/database/index.ts +0 -7
  318. package/src/database/migrations/001_initial.sql +0 -12
  319. package/src/database/migrations/002_pins.sql +0 -1
  320. package/src/database/migrations/003_durable_agents.sql +0 -43
  321. package/src/database/migrations/004_codex_durable_sessions.sql +0 -1
  322. package/src/database/migrations/005_agent_runtime.sql +0 -2
  323. package/src/database/schema.ts +0 -64
  324. package/src/durable/DurableAgent.ts +0 -139
  325. package/src/durable/DurableAgentRepository.ts +0 -485
  326. package/src/durable/process.ts +0 -29
  327. package/src/durable/run.ts +0 -84
  328. package/src/durable/utils.ts +0 -66
  329. package/src/fixtures/bundle.ts +0 -130
  330. package/src/fixtures/capture.ts +0 -364
  331. package/src/harnesses/antigravity/AntigravityAgentMapper.ts +0 -34
  332. package/src/harnesses/antigravity/AntigravityCliAdapter.ts +0 -126
  333. package/src/harnesses/antigravity/AntigravitySessionLocator.ts +0 -75
  334. package/src/harnesses/antigravity/AntigravitySessionParser.ts +0 -252
  335. package/src/harnesses/claude/ClaudeAgentMapper.ts +0 -55
  336. package/src/harnesses/claude/ClaudeCodeAdapter.ts +0 -175
  337. package/src/harnesses/claude/ClaudeSessionLocator.ts +0 -358
  338. package/src/harnesses/claude/ClaudeSessionParser.ts +0 -524
  339. package/src/harnesses/claude/credentials.ts +0 -122
  340. package/src/harnesses/claude/durable/ClaudeCliProbe.ts +0 -57
  341. package/src/harnesses/claude/durable/ClaudePrintAgentService.ts +0 -79
  342. package/src/harnesses/claude/durable/ClaudePrintRunner.ts +0 -102
  343. package/src/harnesses/claude/durable/ClaudeStreamParser.ts +0 -108
  344. package/src/harnesses/claude/readiness.ts +0 -69
  345. package/src/harnesses/codex/CodexAdapter.ts +0 -337
  346. package/src/harnesses/codex/CodexAgentMapper.ts +0 -26
  347. package/src/harnesses/codex/CodexSessionLocator.ts +0 -509
  348. package/src/harnesses/codex/CodexSessionMapping.ts +0 -89
  349. package/src/harnesses/codex/CodexSessionParser.ts +0 -462
  350. package/src/harnesses/codex/credentials.ts +0 -81
  351. package/src/harnesses/codex/durable/CodexCliProbe.ts +0 -68
  352. package/src/harnesses/codex/durable/CodexPrintAgentService.ts +0 -79
  353. package/src/harnesses/codex/durable/CodexPrintRunner.ts +0 -104
  354. package/src/harnesses/codex/durable/CodexStreamParser.ts +0 -117
  355. package/src/harnesses/codex/readiness.ts +0 -72
  356. package/src/harnesses/copilot/CopilotAdapter.ts +0 -161
  357. package/src/harnesses/copilot/CopilotAgentMapper.ts +0 -27
  358. package/src/harnesses/copilot/CopilotSessionLocator.ts +0 -161
  359. package/src/harnesses/copilot/CopilotSessionParser.ts +0 -380
  360. package/src/harnesses/copilot/readiness.ts +0 -33
  361. package/src/harnesses/devin/DevinAdapter.ts +0 -212
  362. package/src/harnesses/devin/DevinAgentMapper.ts +0 -39
  363. package/src/harnesses/devin/DevinSessionLocator.ts +0 -230
  364. package/src/harnesses/devin/DevinSessionParser.ts +0 -227
  365. package/src/harnesses/devin/credentials.ts +0 -88
  366. package/src/harnesses/devin/readiness.ts +0 -36
  367. package/src/harnesses/gemini/GeminiAgentMapper.ts +0 -27
  368. package/src/harnesses/gemini/GeminiCliAdapter.ts +0 -272
  369. package/src/harnesses/gemini/GeminiSessionLocator.ts +0 -394
  370. package/src/harnesses/gemini/GeminiSessionParser.ts +0 -395
  371. package/src/harnesses/gemini/fileSignature.ts +0 -10
  372. package/src/harnesses/grok/GrokAgentMapper.ts +0 -32
  373. package/src/harnesses/grok/GrokCliAdapter.ts +0 -126
  374. package/src/harnesses/grok/GrokSessionLocator.ts +0 -179
  375. package/src/harnesses/grok/GrokSessionParser.ts +0 -251
  376. package/src/harnesses/index.ts +0 -32
  377. package/src/harnesses/kiro/KiroAdapter.ts +0 -143
  378. package/src/harnesses/kiro/KiroAgentMapper.ts +0 -34
  379. package/src/harnesses/kiro/KiroSessionLocator.ts +0 -143
  380. package/src/harnesses/kiro/KiroSessionParser.ts +0 -376
  381. package/src/harnesses/muse/MuseAdapter.ts +0 -157
  382. package/src/harnesses/muse/MuseAgentMapper.ts +0 -33
  383. package/src/harnesses/muse/MuseSessionLocator.ts +0 -286
  384. package/src/harnesses/muse/MuseSessionParser.ts +0 -435
  385. package/src/harnesses/muse/readiness.ts +0 -38
  386. package/src/harnesses/opencode/OpenCodeAdapter.ts +0 -110
  387. package/src/harnesses/opencode/OpenCodeAgentMapper.ts +0 -49
  388. package/src/harnesses/opencode/OpenCodeSessionLocator.ts +0 -151
  389. package/src/harnesses/opencode/OpenCodeSessionParser.ts +0 -146
  390. package/src/harnesses/opencode/readiness.ts +0 -48
  391. package/src/harnesses/pi/PiAdapter.ts +0 -197
  392. package/src/harnesses/pi/PiAgentMapper.ts +0 -27
  393. package/src/harnesses/pi/PiSessionLocator.ts +0 -288
  394. package/src/harnesses/pi/PiSessionParser.ts +0 -488
  395. package/src/harnesses/pi/PiSessionTracker.ts +0 -87
  396. package/src/harnesses/pi/credentials.ts +0 -129
  397. package/src/harnesses/pi/durable/PiCliProbe.ts +0 -56
  398. package/src/harnesses/pi/durable/PiPrintAgentService.ts +0 -77
  399. package/src/harnesses/pi/durable/PiPrintProtocol.ts +0 -41
  400. package/src/harnesses/pi/durable/PiPrintRunner.ts +0 -95
  401. package/src/harnesses/pi/durable/PiStreamParser.ts +0 -94
  402. package/src/harnesses/pi/readiness.ts +0 -104
  403. package/src/harnesses/readiness/AgentReadiness.ts +0 -91
  404. package/src/harnesses/readiness/checks.ts +0 -336
  405. package/src/harnesses/readiness/types.ts +0 -90
  406. package/src/harnesses/runtimeProfiles.ts +0 -105
  407. package/src/harnesses/shared.ts +0 -124
  408. package/src/index.ts +0 -71
  409. package/src/runtime/ManagedAgentRuntime.ts +0 -253
  410. package/src/runtime/RuntimeFactory.ts +0 -13
  411. package/src/runtime/errors.ts +0 -50
  412. package/src/runtime/herdr/HerdrAgentDiscovery.ts +0 -166
  413. package/src/runtime/herdr/HerdrAgentRuntime.ts +0 -216
  414. package/src/runtime/herdr/HerdrCliClient.ts +0 -78
  415. package/src/runtime/herdr/HerdrErrors.ts +0 -9
  416. package/src/runtime/herdr/HerdrResponseParsers.ts +0 -86
  417. package/src/runtime/herdr/HerdrRuntimeRef.ts +0 -41
  418. package/src/runtime/tmux/PidPolling.ts +0 -34
  419. package/src/runtime/tmux/TmuxAgentRuntime.ts +0 -113
  420. package/src/runtime/tmux/TmuxManager.ts +0 -102
  421. package/src/runtime/tmux/TmuxRuntimeRef.ts +0 -9
  422. package/src/runtime/types.ts +0 -56
  423. package/src/terminal/TerminalFocusManager.ts +0 -52
  424. package/src/terminal/TtyWriter.ts +0 -26
  425. package/src/terminal/backends/ghostty.ts +0 -180
  426. package/src/terminal/backends/index.ts +0 -23
  427. package/src/terminal/backends/iterm2.ts +0 -126
  428. package/src/terminal/backends/shared.ts +0 -47
  429. package/src/terminal/backends/terminal-app.ts +0 -122
  430. package/src/terminal/backends/tmux.ts +0 -62
  431. package/src/terminal/backends/wezterm.ts +0 -65
  432. package/src/terminal/types.ts +0 -23
  433. package/src/utils/AgentRegistry.ts +0 -351
  434. package/src/utils/IncrementalJsonlSummary.ts +0 -306
  435. package/src/utils/agent-requests.ts +0 -28
  436. package/src/utils/applescript.ts +0 -10
  437. package/src/utils/jsonlTail.ts +0 -349
  438. package/src/utils/matching.ts +0 -96
  439. package/src/utils/matchingConstants.ts +0 -15
  440. package/src/utils/process.ts +0 -604
  441. package/src/utils/session.ts +0 -144
  442. package/src/utils/sortAgents.ts +0 -54
  443. package/tsconfig.json +0 -11
  444. package/vitest.config.ts +0 -20
@@ -1,462 +0,0 @@
1
- import * as fs from "fs";
2
- import type {
3
- ConversationMessage,
4
- ConversationOptions,
5
- SessionSummary,
6
- } from "../../adapters/AgentAdapter.js";
7
- import { AgentStatus } from "../../adapters/AgentAdapter.js";
8
- import { JsonlTailReader, normalizeTail, type JsonlTailSource } from "../../utils/jsonlTail.js";
9
- import { safeReadFile, safeStat } from "../../utils/session.js";
10
- import {
11
- IncrementalJsonlSummary,
12
- reduceJsonlContent,
13
- type JsonlSummaryBounds,
14
- type JsonlSummaryReducer,
15
- } from "../../utils/IncrementalJsonlSummary.js";
16
- import { isIdle, parseTimestamp, SUMMARY_MAX_LENGTH, truncate } from "../shared.js";
17
-
18
- export interface CodexEventEntry {
19
- timestamp?: string;
20
- type?: string;
21
- payload?: {
22
- type?: string;
23
- message?: string;
24
- id?: string;
25
- cwd?: string;
26
- timestamp?: string;
27
- role?: string;
28
- content?: CodexContent[];
29
- item?: CodexItem;
30
- turn_id?: string;
31
- internal_chat_message_metadata_passthrough?: {
32
- turn_id?: string;
33
- };
34
- };
35
- }
36
-
37
- export interface CodexContent {
38
- type?: string;
39
- text?: string;
40
- }
41
-
42
- export interface CodexItem {
43
- type?: string;
44
- content?: string | CodexContent[];
45
- }
46
-
47
- export interface CodexSession {
48
- sessionId: string;
49
- projectPath: string;
50
- summary: string;
51
- sessionStart: Date;
52
- lastActive: Date;
53
- lastPayloadType?: string;
54
- }
55
-
56
- /** O(1) running summary folded from session entries; `toSession` builds a `CodexSession`. */
57
- interface CodexSummaryState {
58
- seenFirstLine: boolean;
59
- /** Set only when the first line is a valid `session_meta` entry. */
60
- meta?: { id: string; cwd?: string; timestamp?: string };
61
- lastEntryTimestamp?: string;
62
- lastPayloadType?: string;
63
- /** Truncated text of the last entry with displayable content. */
64
- summary?: string;
65
- }
66
-
67
- /** A candidate conversation message plus what is needed to de-duplicate mirrors. */
68
- interface CodexConversationItem {
69
- entryType?: string;
70
- mirrorKey: string | null;
71
- message: ConversationMessage;
72
- }
73
-
74
- const MIRROR_OVERSCAN = 8;
75
-
76
- export interface CodexSessionParserOptions {
77
- /** Cold-start scan bounds for `readSessionIncremental` (see IncrementalJsonlSummary). */
78
- summaryBounds?: JsonlSummaryBounds | false;
79
- }
80
-
81
- export class CodexSessionParser {
82
- /** Incremental reader backing `getConversation({ tail })`. */
83
- private readonly tailReader = new JsonlTailReader();
84
-
85
- private readonly sessionCache: IncrementalJsonlSummary<CodexSummaryState>;
86
-
87
- constructor(options: CodexSessionParserOptions = {}) {
88
- this.sessionCache = new IncrementalJsonlSummary(this.summaryReducer, {
89
- bounds: options.summaryBounds,
90
- });
91
- }
92
-
93
- readSession(filePath: string, cachedContent?: string): CodexSession | null {
94
- let content: string;
95
- if (cachedContent !== undefined) {
96
- content = cachedContent;
97
- } else {
98
- try {
99
- content = fs.readFileSync(filePath, "utf-8");
100
- } catch {
101
- return null;
102
- }
103
- }
104
-
105
- return this.toSession(
106
- reduceJsonlContent(this.summaryReducer, content),
107
- () => fs.statSync(filePath).mtime,
108
- );
109
- }
110
-
111
- /**
112
- * Same result as `readSession`, but backed by a per-instance incremental
113
- * cache so repeated refreshes only parse bytes appended since the last call.
114
- * Call `pruneSessionCache()` once per refresh to evict files no longer read.
115
- *
116
- * The first read of a large transcript is a bounded head + tail scan (see
117
- * `summaryReducer.skip`); fields whose entries lie only in the skipped
118
- * middle fall back to their defaults instead of forcing a full parse.
119
- */
120
- readSessionIncremental(filePath: string): CodexSession | null {
121
- const result = this.sessionCache.read(filePath);
122
- return result ? this.toSession(result.state, () => result.mtime) : null;
123
- }
124
-
125
- /** Evict cached summaries for files not read since the previous prune. */
126
- pruneSessionCache(): void {
127
- this.sessionCache.prune();
128
- }
129
-
130
- /**
131
- * Fold one JSONL entry into the O(1) session summary. The first line must
132
- * be a `session_meta` entry; the rest track the last typed entry and the
133
- * last entry with displayable text.
134
- *
135
- * `skip` (bounded cold start) keeps the head's `session_meta` and clears the
136
- * "latest" fields, so those come from the tail only. Without a typed tail
137
- * entry lastActive falls back to the meta timestamp, then the file mtime;
138
- * without tail text the summary is the "Codex session active" default. A
139
- * `session_meta` line longer than the head window yields no session (null).
140
- */
141
- private readonly summaryReducer: JsonlSummaryReducer<CodexSummaryState> = {
142
- initial: () => ({ seenFirstLine: false }),
143
- reduce: (state, value) => {
144
- const entry = value && typeof value === "object" ? (value as CodexEventEntry) : undefined;
145
- const next: CodexSummaryState = { ...state, seenFirstLine: true };
146
-
147
- if (!state.seenFirstLine) {
148
- if (entry?.type === "session_meta" && entry.payload?.id) {
149
- next.meta = {
150
- id: entry.payload.id,
151
- cwd: entry.payload.cwd,
152
- timestamp: entry.payload.timestamp,
153
- };
154
- }
155
- }
156
- // Without a leading session_meta the file is not a Codex session; skip the work
157
- if (!entry || !next.meta) return next;
158
-
159
- if (typeof entry.type === "string") {
160
- next.lastEntryTimestamp = entry.timestamp;
161
- next.lastPayloadType = this.normalizedPayloadType(entry);
162
- }
163
-
164
- const text = this.extractEntryText(entry);
165
- if (text) next.summary = truncate(text, SUMMARY_MAX_LENGTH);
166
-
167
- return next;
168
- },
169
- skip: (state) => ({ seenFirstLine: true, meta: state.meta }),
170
- };
171
-
172
- private toSession(state: CodexSummaryState, fileMtime: () => Date): CodexSession | null {
173
- const meta = state.meta;
174
- if (!meta) return null;
175
-
176
- const lastActive =
177
- parseTimestamp(state.lastEntryTimestamp) || parseTimestamp(meta.timestamp) || fileMtime();
178
- const sessionStart = parseTimestamp(meta.timestamp) || lastActive;
179
-
180
- return {
181
- sessionId: meta.id,
182
- projectPath: meta.cwd || "",
183
- summary: state.summary ?? "Codex session active",
184
- sessionStart,
185
- lastActive,
186
- lastPayloadType: state.lastPayloadType,
187
- };
188
- }
189
-
190
- determineStatus(session: CodexSession): AgentStatus {
191
- if (
192
- session.lastPayloadType === "agent_message" ||
193
- session.lastPayloadType === "task_complete" ||
194
- session.lastPayloadType === "turn_aborted"
195
- ) {
196
- return AgentStatus.WAITING;
197
- }
198
-
199
- if (isIdle(session.lastActive)) {
200
- return AgentStatus.IDLE;
201
- }
202
-
203
- return AgentStatus.RUNNING;
204
- }
205
-
206
- getConversation(sessionFilePath: string, options?: ConversationOptions): ConversationMessage[] {
207
- const verbose = options?.verbose ?? false;
208
- const source: JsonlTailSource<CodexConversationItem> = {
209
- parseLine: (line) => this.lineToConversationItem(line, verbose),
210
- finalize: (items) => this.dedupeMirroredMessages(items),
211
- };
212
-
213
- const tail = normalizeTail(options?.tail);
214
- if (tail !== undefined) {
215
- // Mirrored pairs sit next to each other, so a few extra messages of
216
- // look-behind keep de-duplication exact for the returned tail.
217
- return this.tailReader.read(sessionFilePath, tail, source, String(verbose), MIRROR_OVERSCAN);
218
- }
219
-
220
- const content = safeReadFile(sessionFilePath);
221
- if (content === undefined) return [];
222
-
223
- const items: CodexConversationItem[] = [];
224
- for (const line of content.trim().split("\n")) {
225
- const item = source.parseLine(line);
226
- if (item) items.push(item);
227
- }
228
-
229
- return this.dedupeMirroredMessages(items);
230
- }
231
-
232
- private lineToConversationItem(line: string, verbose: boolean): CodexConversationItem | null {
233
- let entry: CodexEventEntry;
234
- try {
235
- entry = JSON.parse(line);
236
- } catch {
237
- return null;
238
- }
239
-
240
- const message = this.toConversationMessage(entry, verbose);
241
- if (!message) return null;
242
-
243
- return { entryType: entry.type, mirrorKey: this.mirroredMessageKey(entry, message), message };
244
- }
245
-
246
- /** Drop event_msg messages mirrored by a response_item with the same turn/role/content. */
247
- private dedupeMirroredMessages(items: CodexConversationItem[]): ConversationMessage[] {
248
- const responseItemMirrorKeys = new Set<string>();
249
- for (const item of items) {
250
- if (item.entryType === "response_item" && item.mirrorKey) {
251
- responseItemMirrorKeys.add(item.mirrorKey);
252
- }
253
- }
254
-
255
- const messages: ConversationMessage[] = [];
256
- for (const item of items) {
257
- if (
258
- item.entryType === "event_msg" &&
259
- item.mirrorKey &&
260
- responseItemMirrorKeys.has(item.mirrorKey)
261
- ) {
262
- continue;
263
- }
264
- messages.push(item.message);
265
- }
266
- return messages;
267
- }
268
-
269
- fileToSessionSummary(filePath: string): SessionSummary | null {
270
- const content = safeReadFile(filePath);
271
- if (content === undefined) return null;
272
-
273
- const allLines = content.trim().split("\n");
274
- if (!allLines[0]) return null;
275
-
276
- let metaEntry: CodexEventEntry;
277
- try {
278
- metaEntry = JSON.parse(allLines[0]);
279
- } catch {
280
- return null;
281
- }
282
-
283
- if (metaEntry.type !== "session_meta" || !metaEntry.payload?.id) {
284
- return null;
285
- }
286
-
287
- let firstUserMessage = "";
288
- let lastTimestamp: Date | null = null;
289
-
290
- for (let i = 1; i < allLines.length; i++) {
291
- let entry: CodexEventEntry;
292
- try {
293
- entry = JSON.parse(allLines[i]);
294
- } catch {
295
- continue;
296
- }
297
-
298
- const ts = parseTimestamp(entry.timestamp);
299
- if (ts) lastTimestamp = ts;
300
-
301
- if (!firstUserMessage) {
302
- const message = this.toConversationMessage(entry, false);
303
- const content = message?.content.trim() ?? "";
304
- if (
305
- message?.role === "user" &&
306
- content.length > 0 &&
307
- !this.isSyntheticUserMessage(content)
308
- ) {
309
- firstUserMessage = content;
310
- }
311
- }
312
- }
313
-
314
- const stat = safeStat(filePath);
315
-
316
- const startedAt =
317
- parseTimestamp(metaEntry.payload.timestamp) ||
318
- lastTimestamp ||
319
- stat?.birthtime ||
320
- stat?.mtime ||
321
- new Date();
322
- const lastActive = lastTimestamp || startedAt;
323
-
324
- return {
325
- type: "codex",
326
- sessionId: metaEntry.payload.id,
327
- cwd: metaEntry.payload.cwd || "",
328
- firstUserMessage,
329
- lastActive,
330
- startedAt,
331
- sessionFilePath: filePath,
332
- };
333
- }
334
-
335
- parseMetaTimestampMs(value?: string): number | null {
336
- if (typeof value !== "string") return null;
337
-
338
- const timestamp = parseTimestamp(value);
339
- if (!timestamp) return null;
340
-
341
- const timestampMs = timestamp.getTime();
342
- return Number.isFinite(timestampMs) ? timestampMs : null;
343
- }
344
-
345
- private normalizedPayloadType(entry: CodexEventEntry): string | undefined {
346
- const payloadType = entry.payload?.type;
347
-
348
- if (entry.type === "response_item" && payloadType === "message") {
349
- if (entry.payload?.role === "assistant") return "agent_message";
350
- if (entry.payload?.role === "user") return "user_message";
351
- return payloadType;
352
- }
353
-
354
- if (entry.type === "event_msg" && payloadType === "item_completed") {
355
- const itemType = entry.payload?.item?.type;
356
- if (itemType === "AgentMessage") return "agent_message";
357
- if (itemType === "UserMessage") return "user_message";
358
- return itemType ?? payloadType;
359
- }
360
-
361
- return payloadType;
362
- }
363
-
364
- private extractEntryText(entry: CodexEventEntry | undefined): string {
365
- if (!entry) return "";
366
-
367
- const legacyMessage = entry.payload?.message;
368
- if (typeof legacyMessage === "string" && legacyMessage.trim().length > 0) {
369
- return legacyMessage.trim();
370
- }
371
-
372
- const conversationMessage = this.toConversationMessage(entry, false);
373
- return conversationMessage?.content.trim() ?? "";
374
- }
375
-
376
- private toConversationMessage(
377
- entry: CodexEventEntry,
378
- verbose: boolean,
379
- ): ConversationMessage | null {
380
- if (entry.type === "session_meta") return null;
381
-
382
- const payloadType = entry.payload?.type;
383
- if (entry.type === "response_item" && payloadType === "message") {
384
- const role = this.mapCodexRole(entry.payload?.role, verbose);
385
- const text = this.extractContentText(entry.payload?.content);
386
- if (!role || !text) return null;
387
-
388
- return { role, content: text, timestamp: entry.timestamp };
389
- }
390
-
391
- if (entry.type === "event_msg" && payloadType === "item_completed") {
392
- const item = entry.payload?.item;
393
- const role = this.mapCodexItemRole(item?.type, verbose);
394
- const text = this.extractContentText(item?.content);
395
- if (!role || !text) return null;
396
-
397
- return { role, content: text, timestamp: entry.timestamp };
398
- }
399
-
400
- if (!payloadType) return null;
401
-
402
- let role: ConversationMessage["role"];
403
- if (payloadType === "user_message") {
404
- role = "user";
405
- } else if (payloadType === "agent_message" || payloadType === "task_complete") {
406
- role = "assistant";
407
- } else if (verbose) {
408
- role = "system";
409
- } else {
410
- return null;
411
- }
412
-
413
- const text = entry.payload?.message?.trim();
414
- if (!text) return null;
415
-
416
- return { role, content: text, timestamp: entry.timestamp };
417
- }
418
-
419
- private mapCodexRole(
420
- role: string | undefined,
421
- verbose: boolean,
422
- ): ConversationMessage["role"] | null {
423
- if (role === "user") return "user";
424
- if (role === "assistant") return "assistant";
425
- return verbose ? "system" : null;
426
- }
427
-
428
- private mapCodexItemRole(
429
- itemType: string | undefined,
430
- verbose: boolean,
431
- ): ConversationMessage["role"] | null {
432
- if (itemType === "AgentMessage") return "assistant";
433
- if (itemType === "UserMessage") return "user";
434
- return verbose ? "system" : null;
435
- }
436
-
437
- private mirroredMessageKey(entry: CodexEventEntry, message: ConversationMessage): string | null {
438
- const turnId =
439
- entry.payload?.turn_id || entry.payload?.internal_chat_message_metadata_passthrough?.turn_id;
440
-
441
- if (!turnId) return null;
442
- return `${turnId}\0${message.role}\0${message.content}`;
443
- }
444
-
445
- private extractContentText(content: string | CodexContent[] | undefined): string {
446
- if (typeof content === "string") return content.trim();
447
- if (!Array.isArray(content)) return "";
448
-
449
- return content
450
- .map((part) => part.text)
451
- .filter((text): text is string => typeof text === "string" && text.trim().length > 0)
452
- .map((text) => text.trim())
453
- .join("\n")
454
- .trim();
455
- }
456
-
457
- private isSyntheticUserMessage(content: string): boolean {
458
- return (
459
- content.startsWith("<environment_context>") && content.includes("</environment_context>")
460
- );
461
- }
462
- }
@@ -1,81 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
-
4
- type UnknownRecord = Record<string, unknown>;
5
-
6
- export type CodexCredentialOptions = {
7
- env?: NodeJS.ProcessEnv;
8
- readFile?: (path: string, encoding: BufferEncoding) => Promise<string>;
9
- now?: () => Date;
10
- };
11
-
12
- export type CodexCredentials = {
13
- personalAccessToken: string | null;
14
- oauth: { access: string; accountId: string } | null;
15
- };
16
-
17
- function record(value: unknown): UnknownRecord | null {
18
- return value !== null && typeof value === "object" && !Array.isArray(value)
19
- ? (value as UnknownRecord)
20
- : null;
21
- }
22
-
23
- function finiteNumber(value: unknown): number | null {
24
- return typeof value === "number" && Number.isFinite(value) ? value : null;
25
- }
26
-
27
- function nonEmptyText(value: unknown): string | null {
28
- return typeof value === "string" && value.length > 0 ? value : null;
29
- }
30
-
31
- export function resolveCodexAuthPath(env: NodeJS.ProcessEnv = process.env): string {
32
- const root = env.CODEX_HOME || join(env.HOME || "", ".codex");
33
- return join(root, "auth.json");
34
- }
35
-
36
- function jwtExpiry(token: string): number | null {
37
- const part = token.split(".")[1];
38
- if (!part) return null;
39
- try {
40
- return finiteNumber(record(JSON.parse(Buffer.from(part, "base64url").toString("utf8")))?.exp);
41
- } catch {
42
- return null;
43
- }
44
- }
45
-
46
- function staleOAuth(tokens: UnknownRecord, token: string, now: Date): boolean {
47
- const metadata = tokens.expires_at ?? tokens.expiresAt ?? tokens.expiry;
48
- let expiry: number | null = finiteNumber(metadata);
49
- if (typeof metadata === "string") {
50
- const parsed = Date.parse(metadata);
51
- expiry = Number.isNaN(parsed) ? null : parsed / 1000;
52
- }
53
- expiry ??= jwtExpiry(token);
54
- return expiry !== null && expiry <= now.getTime() / 1000;
55
- }
56
-
57
- export async function resolveCodexCredentials(
58
- options: CodexCredentialOptions = {},
59
- ): Promise<CodexCredentials | null> {
60
- let auth: UnknownRecord;
61
- try {
62
- const contents = await (options.readFile ?? readFile)(
63
- resolveCodexAuthPath(options.env),
64
- "utf8",
65
- );
66
- auth = record(JSON.parse(contents)) ?? {};
67
- } catch {
68
- return null;
69
- }
70
-
71
- const personalAccessToken = nonEmptyText(auth.personal_access_token);
72
- const tokens = record(auth.tokens);
73
- const access = nonEmptyText(tokens?.access_token);
74
- const accountId = nonEmptyText(tokens?.account_id);
75
- const now = options.now?.() ?? new Date();
76
- const oauth =
77
- tokens && access && accountId && !staleOAuth(tokens, access, now)
78
- ? { access, accountId }
79
- : null;
80
- return { personalAccessToken, oauth };
81
- }
@@ -1,68 +0,0 @@
1
- import { execFile } from "child_process";
2
- import { promisify } from "util";
3
- import { CodexPrintError } from "../../../durable/DurableAgent.js";
4
- import { sanitizeText } from "../../../durable/utils.js";
5
-
6
- type ExecResult = { stdout: string; stderr: string };
7
- type Exec = (file: string, args: string[]) => Promise<ExecResult>;
8
-
9
- const execFileAsync = promisify(execFile);
10
-
11
- export interface CodexCliProbeOptions {
12
- executable?: string;
13
- exec?: Exec;
14
- }
15
-
16
- export class CodexCliProbe {
17
- private readonly executable: string;
18
- private readonly exec: Exec;
19
-
20
- constructor(options: CodexCliProbeOptions = {}) {
21
- this.executable = options.executable ?? "codex";
22
- this.exec =
23
- options.exec ??
24
- (async (file, args) => {
25
- const result = await execFileAsync(file, args, {
26
- encoding: "utf8",
27
- maxBuffer: 1024 * 1024,
28
- });
29
- return { stdout: result.stdout, stderr: result.stderr };
30
- });
31
- }
32
-
33
- async validate(): Promise<{ executable: string; version: string }> {
34
- try {
35
- const version = await this.exec(this.executable, ["--version"]);
36
- const execHelp = await this.exec(this.executable, ["exec", "--help"]);
37
- const resumeHelp = await this.exec(this.executable, ["exec", "resume", "--help"]);
38
- const missing = [
39
- !execHelp.stdout.includes("exec") && "exec",
40
- !execHelp.stdout.includes("--json") && "--json",
41
- !hasStdinDash(execHelp.stdout) && "stdin -",
42
- !resumeHelp.stdout.includes("resume") && "resume",
43
- !resumeHelp.stdout.includes("--json") && "resume --json",
44
- !hasStdinDash(resumeHelp.stdout) && "resume stdin -",
45
- ].filter((value): value is string => typeof value === "string");
46
- if (missing.length > 0) {
47
- throw new CodexPrintError(
48
- `Codex CLI does not support required print-mode capabilities: ${missing.join(", ")}.`,
49
- "CODEX_CLI_UNSUPPORTED",
50
- );
51
- }
52
- return {
53
- executable: this.executable,
54
- version: sanitizeText(version.stdout, 256) || "unknown",
55
- };
56
- } catch (error) {
57
- if (error instanceof CodexPrintError) throw error;
58
- throw new CodexPrintError(
59
- `Codex CLI validation failed: ${sanitizeText((error as Error).message, 512)}`,
60
- "CODEX_CLI_UNAVAILABLE",
61
- );
62
- }
63
- }
64
- }
65
-
66
- function hasStdinDash(help: string): boolean {
67
- return /(?:^|\s)-(?:\s|$)/m.test(help);
68
- }
@@ -1,79 +0,0 @@
1
- import type { DurableAgent, ProcessIdentity } from "../../../durable/DurableAgent.js";
2
- import { CodexPrintError } from "../../../durable/DurableAgent.js";
3
- import { CodexCliProbe } from "./CodexCliProbe.js";
4
- import { CodexPrintRunner, type CodexPrintRunResult } from "./CodexPrintRunner.js";
5
- import {
6
- DurableAgentRepository,
7
- type CreateDurableAgentInput,
8
- } from "../../../durable/DurableAgentRepository.js";
9
- import { runDurableAgent, type DurableRunRepository } from "../../../durable/run.js";
10
-
11
- interface RepositoryLike extends DurableRunRepository {
12
- create(input: CreateDurableAgentInput): Promise<DurableAgent>;
13
- list(): Promise<DurableAgent[]>;
14
- recordProviderProcess(id: string, token: string, identity: ProcessIdentity): Promise<void>;
15
- bindProviderSession(id: string, token: string, providerSessionId: string): Promise<DurableAgent>;
16
- }
17
-
18
- interface ProbeLike {
19
- validate(): Promise<{ executable: string; version: string }>;
20
- }
21
- interface RunnerLike {
22
- run(request: Parameters<CodexPrintRunner["run"]>[0]): Promise<CodexPrintRunResult>;
23
- }
24
-
25
- export interface CodexPrintAgentServiceOptions {
26
- repository?: RepositoryLike;
27
- probe?: ProbeLike;
28
- runner?: RunnerLike;
29
- executable?: string;
30
- }
31
-
32
- export interface CodexPrintSendResult extends CodexPrintRunResult {
33
- agentId: string;
34
- agentName: string;
35
- }
36
-
37
- export class CodexPrintAgentService {
38
- readonly repository: RepositoryLike;
39
- private readonly probe: ProbeLike;
40
- private readonly runner: RunnerLike;
41
- private readonly executable?: string;
42
-
43
- constructor(options: CodexPrintAgentServiceOptions = {}) {
44
- this.repository = options.repository ?? new DurableAgentRepository();
45
- this.probe = options.probe ?? new CodexCliProbe();
46
- this.runner = options.runner ?? new CodexPrintRunner();
47
- this.executable = options.executable;
48
- }
49
-
50
- async create(input: Omit<CreateDurableAgentInput, "provider">): Promise<DurableAgent> {
51
- await this.probe.validate();
52
- return this.repository.create({ ...input, provider: "codex" });
53
- }
54
-
55
- async send(reference: string, prompt: string): Promise<CodexPrintSendResult> {
56
- const completed = await runDurableAgent({
57
- reference,
58
- provider: "codex",
59
- repository: this.repository,
60
- ambiguousError: () =>
61
- new CodexPrintError("Multiple print agents match.", "CODEX_UNSUPPORTED"),
62
- providerError: () =>
63
- new CodexPrintError("Print agent provider is not Codex.", "CODEX_UNSUPPORTED"),
64
- execute: (agent, token) =>
65
- this.runner.run({
66
- agent,
67
- prompt,
68
- executable: this.executable,
69
- onSpawn: (identity) => this.repository.recordProviderProcess(agent.id, token, identity),
70
- onSession: async (sessionId) => {
71
- await this.repository.bindProviderSession(agent.id, token, sessionId);
72
- },
73
- }),
74
- isSessionMismatch: (error) =>
75
- error instanceof CodexPrintError && error.code === "CODEX_SESSION_MISMATCH",
76
- });
77
- return { ...completed.result, agentId: completed.agent.id, agentName: completed.agent.name };
78
- }
79
- }