@ai-devkit/agent-manager 0.42.3 → 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 (451) hide show
  1. package/dist/AgentManager.d.ts +14 -5
  2. package/dist/AgentManager.d.ts.map +1 -1
  3. package/dist/AgentManager.js +32 -13
  4. package/dist/AgentManager.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/package.json +9 -4
  9. package/.swcrc +0 -27
  10. package/dist/__tests__/AgentManager.test.js +0 -1596
  11. package/dist/__tests__/AgentManager.test.js.map +0 -1
  12. package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js +0 -486
  13. package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js.map +0 -1
  14. package/dist/__tests__/adapters/adapterProcessImports.test.js +0 -52
  15. package/dist/__tests__/adapters/adapterProcessImports.test.js.map +0 -1
  16. package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js +0 -247
  17. package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js.map +0 -1
  18. package/dist/__tests__/capacity/anthropic.test.js +0 -115
  19. package/dist/__tests__/capacity/anthropic.test.js.map +0 -1
  20. package/dist/__tests__/capacity/boundaries.test.js +0 -45
  21. package/dist/__tests__/capacity/boundaries.test.js.map +0 -1
  22. package/dist/__tests__/capacity/claude.test.js +0 -485
  23. package/dist/__tests__/capacity/claude.test.js.map +0 -1
  24. package/dist/__tests__/capacity/codex.test.js +0 -339
  25. package/dist/__tests__/capacity/codex.test.js.map +0 -1
  26. package/dist/__tests__/capacity/devin.test.js +0 -239
  27. package/dist/__tests__/capacity/devin.test.js.map +0 -1
  28. package/dist/__tests__/capacity/index.test.js +0 -53
  29. package/dist/__tests__/capacity/index.test.js.map +0 -1
  30. package/dist/__tests__/capacity/openai.test.js +0 -687
  31. package/dist/__tests__/capacity/openai.test.js.map +0 -1
  32. package/dist/__tests__/capacity/wham.test.js +0 -159
  33. package/dist/__tests__/capacity/wham.test.js.map +0 -1
  34. package/dist/__tests__/capacity/zai.test.js +0 -212
  35. package/dist/__tests__/capacity/zai.test.js.map +0 -1
  36. package/dist/__tests__/fixtures.test.js +0 -218
  37. package/dist/__tests__/fixtures.test.js.map +0 -1
  38. package/dist/__tests__/harnesses/BoundedSummarySkip.test.js +0 -568
  39. package/dist/__tests__/harnesses/BoundedSummarySkip.test.js.map +0 -1
  40. package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js +0 -1089
  41. package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js.map +0 -1
  42. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js +0 -143
  43. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js.map +0 -1
  44. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js +0 -462
  45. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js.map +0 -1
  46. package/dist/__tests__/harnesses/builtinAdapters.test.js +0 -33
  47. package/dist/__tests__/harnesses/builtinAdapters.test.js.map +0 -1
  48. package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js +0 -79
  49. package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js.map +0 -1
  50. package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js +0 -1881
  51. package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js.map +0 -1
  52. package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js +0 -425
  53. package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js.map +0 -1
  54. package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js +0 -314
  55. package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js.map +0 -1
  56. package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js +0 -49
  57. package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js.map +0 -1
  58. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js +0 -76
  59. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js.map +0 -1
  60. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js +0 -173
  61. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js.map +0 -1
  62. package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js +0 -181
  63. package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js.map +0 -1
  64. package/dist/__tests__/harnesses/codex/CodexAdapter.test.js +0 -685
  65. package/dist/__tests__/harnesses/codex/CodexAdapter.test.js.map +0 -1
  66. package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js +0 -463
  67. package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js.map +0 -1
  68. package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js +0 -86
  69. package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js.map +0 -1
  70. package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js +0 -254
  71. package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js.map +0 -1
  72. package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js +0 -121
  73. package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js.map +0 -1
  74. package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js +0 -84
  75. package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js.map +0 -1
  76. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js +0 -128
  77. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js.map +0 -1
  78. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js +0 -246
  79. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js.map +0 -1
  80. package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js +0 -384
  81. package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js.map +0 -1
  82. package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js +0 -659
  83. package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js.map +0 -1
  84. package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js +0 -290
  85. package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js.map +0 -1
  86. package/dist/__tests__/harnesses/devin/DevinAdapter.test.js +0 -597
  87. package/dist/__tests__/harnesses/devin/DevinAdapter.test.js.map +0 -1
  88. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +0 -99
  89. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +0 -1
  90. package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js +0 -192
  91. package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js.map +0 -1
  92. package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js +0 -407
  93. package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js.map +0 -1
  94. package/dist/__tests__/harnesses/devin/fixtures.js +0 -95
  95. package/dist/__tests__/harnesses/devin/fixtures.js.map +0 -1
  96. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js +0 -1454
  97. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js.map +0 -1
  98. package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js +0 -491
  99. package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js.map +0 -1
  100. package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js +0 -399
  101. package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js.map +0 -1
  102. package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js +0 -56
  103. package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js.map +0 -1
  104. package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js +0 -421
  105. package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js.map +0 -1
  106. package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js +0 -167
  107. package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js.map +0 -1
  108. package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js +0 -133
  109. package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js.map +0 -1
  110. package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js +0 -301
  111. package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js.map +0 -1
  112. package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js +0 -662
  113. package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js.map +0 -1
  114. package/dist/__tests__/harnesses/muse/MuseAdapter.test.js +0 -247
  115. package/dist/__tests__/harnesses/muse/MuseAdapter.test.js.map +0 -1
  116. package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js +0 -81
  117. package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js.map +0 -1
  118. package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js +0 -185
  119. package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js.map +0 -1
  120. package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js +0 -328
  121. package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js.map +0 -1
  122. package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js +0 -213
  123. package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js.map +0 -1
  124. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js +0 -108
  125. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js.map +0 -1
  126. package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js +0 -94
  127. package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js.map +0 -1
  128. package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js +0 -147
  129. package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js.map +0 -1
  130. package/dist/__tests__/harnesses/pi/PiAdapter.test.js +0 -367
  131. package/dist/__tests__/harnesses/pi/PiAdapter.test.js.map +0 -1
  132. package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js +0 -382
  133. package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js.map +0 -1
  134. package/dist/__tests__/harnesses/pi/PiSessionParser.test.js +0 -416
  135. package/dist/__tests__/harnesses/pi/PiSessionParser.test.js.map +0 -1
  136. package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js +0 -108
  137. package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js.map +0 -1
  138. package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js +0 -70
  139. package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js.map +0 -1
  140. package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js +0 -43
  141. package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js.map +0 -1
  142. package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js +0 -192
  143. package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js.map +0 -1
  144. package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js +0 -119
  145. package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js.map +0 -1
  146. package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js +0 -382
  147. package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js.map +0 -1
  148. package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js +0 -34
  149. package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js.map +0 -1
  150. package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js +0 -446
  151. package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js.map +0 -1
  152. package/dist/__tests__/harnesses/runtimeProfiles.test.js +0 -101
  153. package/dist/__tests__/harnesses/runtimeProfiles.test.js.map +0 -1
  154. package/dist/__tests__/print/DurableAgent.test.js +0 -15
  155. package/dist/__tests__/print/DurableAgent.test.js.map +0 -1
  156. package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js +0 -186
  157. package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js.map +0 -1
  158. package/dist/__tests__/print/DurableAgentRepository.test.js +0 -249
  159. package/dist/__tests__/print/DurableAgentRepository.test.js.map +0 -1
  160. package/dist/__tests__/readiness-fixtures.test.js +0 -54
  161. package/dist/__tests__/readiness-fixtures.test.js.map +0 -1
  162. package/dist/__tests__/runtime/AgentRuntime.test.js +0 -13
  163. package/dist/__tests__/runtime/AgentRuntime.test.js.map +0 -1
  164. package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js +0 -164
  165. package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js.map +0 -1
  166. package/dist/__tests__/runtime/HerdrAgentRuntime.test.js +0 -488
  167. package/dist/__tests__/runtime/HerdrAgentRuntime.test.js.map +0 -1
  168. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js +0 -637
  169. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js.map +0 -1
  170. package/dist/__tests__/terminal/GhosttyBackend.test.js +0 -334
  171. package/dist/__tests__/terminal/GhosttyBackend.test.js.map +0 -1
  172. package/dist/__tests__/terminal/TerminalFocusManager.test.js +0 -253
  173. package/dist/__tests__/terminal/TerminalFocusManager.test.js.map +0 -1
  174. package/dist/__tests__/terminal/TmuxManager.test.js +0 -168
  175. package/dist/__tests__/terminal/TmuxManager.test.js.map +0 -1
  176. package/dist/__tests__/terminal/TtyWriter.test.js +0 -386
  177. package/dist/__tests__/terminal/TtyWriter.test.js.map +0 -1
  178. package/dist/__tests__/utils/AgentRegistry.test.js +0 -636
  179. package/dist/__tests__/utils/AgentRegistry.test.js.map +0 -1
  180. package/dist/__tests__/utils/IncrementalJsonlSummary.test.js +0 -650
  181. package/dist/__tests__/utils/IncrementalJsonlSummary.test.js.map +0 -1
  182. package/dist/__tests__/utils/agent-requests.test.js +0 -90
  183. package/dist/__tests__/utils/agent-requests.test.js.map +0 -1
  184. package/dist/__tests__/utils/conversationTail.bench.test.js +0 -258
  185. package/dist/__tests__/utils/conversationTail.bench.test.js.map +0 -1
  186. package/dist/__tests__/utils/conversationTailParity.test.js +0 -588
  187. package/dist/__tests__/utils/conversationTailParity.test.js.map +0 -1
  188. package/dist/__tests__/utils/jsonlTail.test.js +0 -360
  189. package/dist/__tests__/utils/jsonlTail.test.js.map +0 -1
  190. package/dist/__tests__/utils/matching.test.js +0 -324
  191. package/dist/__tests__/utils/matching.test.js.map +0 -1
  192. package/dist/__tests__/utils/matchingConstants.test.js +0 -35
  193. package/dist/__tests__/utils/matchingConstants.test.js.map +0 -1
  194. package/dist/__tests__/utils/process.test.js +0 -818
  195. package/dist/__tests__/utils/process.test.js.map +0 -1
  196. package/dist/__tests__/utils/session.test.js +0 -175
  197. package/dist/__tests__/utils/session.test.js.map +0 -1
  198. package/project.json +0 -29
  199. package/scripts/benchmark-cold-start.mjs +0 -350
  200. package/src/AgentManager.ts +0 -530
  201. package/src/__tests__/AgentManager.test.ts +0 -1483
  202. package/src/__tests__/adapters/IncrementalSessionRefresh.test.ts +0 -437
  203. package/src/__tests__/adapters/adapterProcessImports.test.ts +0 -58
  204. package/src/__tests__/adapters/adapterSnapshotCandidates.test.ts +0 -243
  205. package/src/__tests__/capacity/anthropic.test.ts +0 -105
  206. package/src/__tests__/capacity/boundaries.test.ts +0 -36
  207. package/src/__tests__/capacity/claude.test.ts +0 -462
  208. package/src/__tests__/capacity/codex.test.ts +0 -311
  209. package/src/__tests__/capacity/devin.test.ts +0 -210
  210. package/src/__tests__/capacity/fixtures/claude-credentials.json +0 -7
  211. package/src/__tests__/capacity/fixtures/claude-usage-malformed.json +0 -1
  212. package/src/__tests__/capacity/fixtures/claude-usage-partial.json +0 -15
  213. package/src/__tests__/capacity/fixtures/claude-usage.json +0 -63
  214. package/src/__tests__/capacity/fixtures/devin-config.json +0 -6
  215. package/src/__tests__/capacity/fixtures/devin-credentials.toml +0 -4
  216. package/src/__tests__/capacity/fixtures/devin-quota-nonplan.json +0 -5
  217. package/src/__tests__/capacity/fixtures/devin-quota.json +0 -10
  218. package/src/__tests__/capacity/fixtures/openai-auth.json +0 -6
  219. package/src/__tests__/capacity/fixtures/openai-codex-auth.json +0 -9
  220. package/src/__tests__/capacity/fixtures/openai-usage-completions.json +0 -67
  221. package/src/__tests__/capacity/fixtures/openai-usage-responses.json +0 -20
  222. package/src/__tests__/capacity/fixtures/wham-usage.json +0 -45
  223. package/src/__tests__/capacity/fixtures/zai-auth.json +0 -6
  224. package/src/__tests__/capacity/fixtures/zai-quota-invalid.json +0 -7
  225. package/src/__tests__/capacity/fixtures/zai-quota.json +0 -38
  226. package/src/__tests__/capacity/index.test.ts +0 -54
  227. package/src/__tests__/capacity/openai.test.ts +0 -571
  228. package/src/__tests__/capacity/wham.test.ts +0 -122
  229. package/src/__tests__/capacity/zai.test.ts +0 -151
  230. package/src/__tests__/fixtures.test.ts +0 -245
  231. package/src/__tests__/harnesses/BoundedSummarySkip.test.ts +0 -496
  232. package/src/__tests__/harnesses/SessionSummaryEquivalence.test.ts +0 -726
  233. package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.ts +0 -133
  234. package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.ts +0 -396
  235. package/src/__tests__/harnesses/builtinAdapters.test.ts +0 -33
  236. package/src/__tests__/harnesses/claude/ClaudeAgentMapper.test.ts +0 -84
  237. package/src/__tests__/harnesses/claude/ClaudeCodeAdapter.test.ts +0 -1793
  238. package/src/__tests__/harnesses/claude/ClaudeSessionLocator.test.ts +0 -423
  239. package/src/__tests__/harnesses/claude/ClaudeSessionParser.test.ts +0 -300
  240. package/src/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.ts +0 -34
  241. package/src/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.ts +0 -61
  242. package/src/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.ts +0 -129
  243. package/src/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.ts +0 -152
  244. package/src/__tests__/harnesses/codex/CodexAdapter.test.ts +0 -652
  245. package/src/__tests__/harnesses/codex/CodexSessionLocator.test.ts +0 -419
  246. package/src/__tests__/harnesses/codex/CodexSessionMapping.test.ts +0 -63
  247. package/src/__tests__/harnesses/codex/CodexSessionParser.test.ts +0 -192
  248. package/src/__tests__/harnesses/codex/durable/CodexCliProbe.test.ts +0 -80
  249. package/src/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.ts +0 -65
  250. package/src/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.ts +0 -104
  251. package/src/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.ts +0 -201
  252. package/src/__tests__/harnesses/codex/durable/CodexPrintRunner.test.ts +0 -299
  253. package/src/__tests__/harnesses/copilot/CopilotAdapter.test.ts +0 -614
  254. package/src/__tests__/harnesses/copilot/CopilotRefreshIO.test.ts +0 -270
  255. package/src/__tests__/harnesses/devin/DevinAdapter.test.ts +0 -290
  256. package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +0 -101
  257. package/src/__tests__/harnesses/devin/DevinSessionLocator.test.ts +0 -139
  258. package/src/__tests__/harnesses/devin/DevinSessionParser.test.ts +0 -212
  259. package/src/__tests__/harnesses/devin/fixtures.ts +0 -144
  260. package/src/__tests__/harnesses/gemini/GeminiCliAdapter.test.ts +0 -1336
  261. package/src/__tests__/harnesses/gemini/GeminiSessionJsonl.test.ts +0 -402
  262. package/src/__tests__/harnesses/gemini/GeminiSessionLocator.test.ts +0 -396
  263. package/src/__tests__/harnesses/grok/GrokAgentMapper.test.ts +0 -57
  264. package/src/__tests__/harnesses/grok/GrokCliAdapter.test.ts +0 -376
  265. package/src/__tests__/harnesses/grok/GrokIncrementalRefresh.test.ts +0 -170
  266. package/src/__tests__/harnesses/grok/GrokSessionLocator.test.ts +0 -106
  267. package/src/__tests__/harnesses/grok/GrokSessionParser.test.ts +0 -230
  268. package/src/__tests__/harnesses/kiro/KiroAdapter.test.ts +0 -552
  269. package/src/__tests__/harnesses/muse/MuseAdapter.test.ts +0 -197
  270. package/src/__tests__/harnesses/muse/MuseAgentMapper.test.ts +0 -83
  271. package/src/__tests__/harnesses/muse/MuseSessionLocator.test.ts +0 -177
  272. package/src/__tests__/harnesses/muse/MuseSessionParser.test.ts +0 -279
  273. package/src/__tests__/harnesses/opencode/OpenCodeAdapter.test.ts +0 -215
  274. package/src/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.ts +0 -101
  275. package/src/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.ts +0 -84
  276. package/src/__tests__/harnesses/opencode/OpenCodeSessionParser.test.ts +0 -149
  277. package/src/__tests__/harnesses/pi/PiAdapter.test.ts +0 -325
  278. package/src/__tests__/harnesses/pi/PiDiscoveryIO.test.ts +0 -337
  279. package/src/__tests__/harnesses/pi/PiSessionParser.test.ts +0 -280
  280. package/src/__tests__/harnesses/pi/PiSessionTracker.test.ts +0 -79
  281. package/src/__tests__/harnesses/pi/durable/PiCliProbe.test.ts +0 -50
  282. package/src/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.ts +0 -33
  283. package/src/__tests__/harnesses/pi/durable/PiPrintAgentService.test.ts +0 -138
  284. package/src/__tests__/harnesses/pi/durable/PiPrintProtocol.test.ts +0 -71
  285. package/src/__tests__/harnesses/pi/durable/PiPrintRunner.test.ts +0 -252
  286. package/src/__tests__/harnesses/pi/durable/PiStreamParser.test.ts +0 -26
  287. package/src/__tests__/harnesses/readiness/AgentReadiness.test.ts +0 -362
  288. package/src/__tests__/harnesses/runtimeProfiles.test.ts +0 -123
  289. package/src/__tests__/print/DurableAgent.test.ts +0 -15
  290. package/src/__tests__/print/DurableAgentRepository.sqlite.test.ts +0 -128
  291. package/src/__tests__/print/DurableAgentRepository.test.ts +0 -184
  292. package/src/__tests__/readiness-fixtures.test.ts +0 -79
  293. package/src/__tests__/runtime/AgentRuntime.test.ts +0 -8
  294. package/src/__tests__/runtime/HerdrAgentDiscovery.test.ts +0 -131
  295. package/src/__tests__/runtime/HerdrAgentRuntime.test.ts +0 -377
  296. package/src/__tests__/runtime/ManagedAgentRuntime.test.ts +0 -590
  297. package/src/__tests__/terminal/GhosttyBackend.test.ts +0 -271
  298. package/src/__tests__/terminal/TerminalFocusManager.test.ts +0 -280
  299. package/src/__tests__/terminal/TmuxManager.test.ts +0 -185
  300. package/src/__tests__/terminal/TtyWriter.test.ts +0 -454
  301. package/src/__tests__/utils/AgentRegistry.test.ts +0 -532
  302. package/src/__tests__/utils/IncrementalJsonlSummary.test.ts +0 -414
  303. package/src/__tests__/utils/agent-requests.test.ts +0 -94
  304. package/src/__tests__/utils/conversationTail.bench.test.ts +0 -193
  305. package/src/__tests__/utils/conversationTailParity.test.ts +0 -365
  306. package/src/__tests__/utils/jsonlTail.test.ts +0 -317
  307. package/src/__tests__/utils/matching.test.ts +0 -234
  308. package/src/__tests__/utils/matchingConstants.test.ts +0 -40
  309. package/src/__tests__/utils/process.test.ts +0 -596
  310. package/src/__tests__/utils/session.test.ts +0 -158
  311. package/src/adapters/AgentAdapter.ts +0 -255
  312. package/src/capacity/index.ts +0 -127
  313. package/src/capacity/providers/anthropic.ts +0 -198
  314. package/src/capacity/providers/devin.ts +0 -121
  315. package/src/capacity/providers/openai-platform.ts +0 -150
  316. package/src/capacity/providers/openai-subscription.ts +0 -184
  317. package/src/capacity/providers/zai.ts +0 -155
  318. package/src/capacity/sources/claude.ts +0 -30
  319. package/src/capacity/sources/codex.ts +0 -251
  320. package/src/capacity/sources/devin.ts +0 -49
  321. package/src/capacity/sources/pi.ts +0 -131
  322. package/src/capacity/types.ts +0 -29
  323. package/src/database/connection.ts +0 -96
  324. package/src/database/index.ts +0 -7
  325. package/src/database/migrations/001_initial.sql +0 -12
  326. package/src/database/migrations/002_pins.sql +0 -1
  327. package/src/database/migrations/003_durable_agents.sql +0 -43
  328. package/src/database/migrations/004_codex_durable_sessions.sql +0 -1
  329. package/src/database/migrations/005_agent_runtime.sql +0 -2
  330. package/src/database/schema.ts +0 -64
  331. package/src/durable/DurableAgent.ts +0 -139
  332. package/src/durable/DurableAgentRepository.ts +0 -485
  333. package/src/durable/process.ts +0 -29
  334. package/src/durable/run.ts +0 -84
  335. package/src/durable/utils.ts +0 -66
  336. package/src/fixtures/bundle.ts +0 -130
  337. package/src/fixtures/capture.ts +0 -364
  338. package/src/harnesses/antigravity/AntigravityAgentMapper.ts +0 -34
  339. package/src/harnesses/antigravity/AntigravityCliAdapter.ts +0 -126
  340. package/src/harnesses/antigravity/AntigravitySessionLocator.ts +0 -75
  341. package/src/harnesses/antigravity/AntigravitySessionParser.ts +0 -252
  342. package/src/harnesses/claude/ClaudeAgentMapper.ts +0 -55
  343. package/src/harnesses/claude/ClaudeCodeAdapter.ts +0 -175
  344. package/src/harnesses/claude/ClaudeSessionLocator.ts +0 -358
  345. package/src/harnesses/claude/ClaudeSessionParser.ts +0 -524
  346. package/src/harnesses/claude/credentials.ts +0 -122
  347. package/src/harnesses/claude/durable/ClaudeCliProbe.ts +0 -57
  348. package/src/harnesses/claude/durable/ClaudePrintAgentService.ts +0 -79
  349. package/src/harnesses/claude/durable/ClaudePrintRunner.ts +0 -102
  350. package/src/harnesses/claude/durable/ClaudeStreamParser.ts +0 -108
  351. package/src/harnesses/claude/readiness.ts +0 -69
  352. package/src/harnesses/codex/CodexAdapter.ts +0 -337
  353. package/src/harnesses/codex/CodexAgentMapper.ts +0 -26
  354. package/src/harnesses/codex/CodexSessionLocator.ts +0 -509
  355. package/src/harnesses/codex/CodexSessionMapping.ts +0 -89
  356. package/src/harnesses/codex/CodexSessionParser.ts +0 -462
  357. package/src/harnesses/codex/credentials.ts +0 -81
  358. package/src/harnesses/codex/durable/CodexCliProbe.ts +0 -68
  359. package/src/harnesses/codex/durable/CodexPrintAgentService.ts +0 -79
  360. package/src/harnesses/codex/durable/CodexPrintRunner.ts +0 -104
  361. package/src/harnesses/codex/durable/CodexStreamParser.ts +0 -117
  362. package/src/harnesses/codex/readiness.ts +0 -72
  363. package/src/harnesses/copilot/CopilotAdapter.ts +0 -161
  364. package/src/harnesses/copilot/CopilotAgentMapper.ts +0 -27
  365. package/src/harnesses/copilot/CopilotSessionLocator.ts +0 -161
  366. package/src/harnesses/copilot/CopilotSessionParser.ts +0 -380
  367. package/src/harnesses/copilot/readiness.ts +0 -33
  368. package/src/harnesses/devin/DevinAdapter.ts +0 -212
  369. package/src/harnesses/devin/DevinAgentMapper.ts +0 -39
  370. package/src/harnesses/devin/DevinSessionLocator.ts +0 -230
  371. package/src/harnesses/devin/DevinSessionParser.ts +0 -227
  372. package/src/harnesses/devin/credentials.ts +0 -88
  373. package/src/harnesses/devin/readiness.ts +0 -36
  374. package/src/harnesses/gemini/GeminiAgentMapper.ts +0 -27
  375. package/src/harnesses/gemini/GeminiCliAdapter.ts +0 -272
  376. package/src/harnesses/gemini/GeminiSessionLocator.ts +0 -394
  377. package/src/harnesses/gemini/GeminiSessionParser.ts +0 -395
  378. package/src/harnesses/gemini/fileSignature.ts +0 -10
  379. package/src/harnesses/grok/GrokAgentMapper.ts +0 -32
  380. package/src/harnesses/grok/GrokCliAdapter.ts +0 -126
  381. package/src/harnesses/grok/GrokSessionLocator.ts +0 -179
  382. package/src/harnesses/grok/GrokSessionParser.ts +0 -251
  383. package/src/harnesses/index.ts +0 -32
  384. package/src/harnesses/kiro/KiroAdapter.ts +0 -143
  385. package/src/harnesses/kiro/KiroAgentMapper.ts +0 -34
  386. package/src/harnesses/kiro/KiroSessionLocator.ts +0 -143
  387. package/src/harnesses/kiro/KiroSessionParser.ts +0 -376
  388. package/src/harnesses/muse/MuseAdapter.ts +0 -157
  389. package/src/harnesses/muse/MuseAgentMapper.ts +0 -33
  390. package/src/harnesses/muse/MuseSessionLocator.ts +0 -286
  391. package/src/harnesses/muse/MuseSessionParser.ts +0 -435
  392. package/src/harnesses/muse/readiness.ts +0 -38
  393. package/src/harnesses/opencode/OpenCodeAdapter.ts +0 -110
  394. package/src/harnesses/opencode/OpenCodeAgentMapper.ts +0 -49
  395. package/src/harnesses/opencode/OpenCodeSessionLocator.ts +0 -151
  396. package/src/harnesses/opencode/OpenCodeSessionParser.ts +0 -146
  397. package/src/harnesses/opencode/readiness.ts +0 -48
  398. package/src/harnesses/pi/PiAdapter.ts +0 -197
  399. package/src/harnesses/pi/PiAgentMapper.ts +0 -27
  400. package/src/harnesses/pi/PiSessionLocator.ts +0 -288
  401. package/src/harnesses/pi/PiSessionParser.ts +0 -488
  402. package/src/harnesses/pi/PiSessionTracker.ts +0 -87
  403. package/src/harnesses/pi/credentials.ts +0 -129
  404. package/src/harnesses/pi/durable/PiCliProbe.ts +0 -56
  405. package/src/harnesses/pi/durable/PiPrintAgentService.ts +0 -77
  406. package/src/harnesses/pi/durable/PiPrintProtocol.ts +0 -41
  407. package/src/harnesses/pi/durable/PiPrintRunner.ts +0 -95
  408. package/src/harnesses/pi/durable/PiStreamParser.ts +0 -94
  409. package/src/harnesses/pi/readiness.ts +0 -104
  410. package/src/harnesses/readiness/AgentReadiness.ts +0 -91
  411. package/src/harnesses/readiness/checks.ts +0 -336
  412. package/src/harnesses/readiness/types.ts +0 -90
  413. package/src/harnesses/runtimeProfiles.ts +0 -105
  414. package/src/harnesses/shared.ts +0 -124
  415. package/src/index.ts +0 -70
  416. package/src/runtime/ManagedAgentRuntime.ts +0 -253
  417. package/src/runtime/RuntimeFactory.ts +0 -13
  418. package/src/runtime/errors.ts +0 -50
  419. package/src/runtime/herdr/HerdrAgentDiscovery.ts +0 -166
  420. package/src/runtime/herdr/HerdrAgentRuntime.ts +0 -216
  421. package/src/runtime/herdr/HerdrCliClient.ts +0 -78
  422. package/src/runtime/herdr/HerdrErrors.ts +0 -9
  423. package/src/runtime/herdr/HerdrResponseParsers.ts +0 -86
  424. package/src/runtime/herdr/HerdrRuntimeRef.ts +0 -41
  425. package/src/runtime/tmux/PidPolling.ts +0 -34
  426. package/src/runtime/tmux/TmuxAgentRuntime.ts +0 -113
  427. package/src/runtime/tmux/TmuxManager.ts +0 -102
  428. package/src/runtime/tmux/TmuxRuntimeRef.ts +0 -9
  429. package/src/runtime/types.ts +0 -56
  430. package/src/terminal/TerminalFocusManager.ts +0 -52
  431. package/src/terminal/TtyWriter.ts +0 -26
  432. package/src/terminal/backends/ghostty.ts +0 -180
  433. package/src/terminal/backends/index.ts +0 -23
  434. package/src/terminal/backends/iterm2.ts +0 -126
  435. package/src/terminal/backends/shared.ts +0 -47
  436. package/src/terminal/backends/terminal-app.ts +0 -122
  437. package/src/terminal/backends/tmux.ts +0 -62
  438. package/src/terminal/backends/wezterm.ts +0 -65
  439. package/src/terminal/types.ts +0 -23
  440. package/src/utils/AgentRegistry.ts +0 -351
  441. package/src/utils/IncrementalJsonlSummary.ts +0 -306
  442. package/src/utils/agent-requests.ts +0 -28
  443. package/src/utils/applescript.ts +0 -10
  444. package/src/utils/jsonlTail.ts +0 -349
  445. package/src/utils/matching.ts +0 -96
  446. package/src/utils/matchingConstants.ts +0 -15
  447. package/src/utils/process.ts +0 -604
  448. package/src/utils/session.ts +0 -144
  449. package/src/utils/sortAgents.ts +0 -54
  450. package/tsconfig.json +0 -11
  451. package/vitest.config.ts +0 -20
@@ -1,306 +0,0 @@
1
- /**
2
- * Incremental JSONL Summary
3
- *
4
- * Keeps a small per-file summary of append-only JSONL transcripts so repeated
5
- * refreshes only parse bytes that were appended since the previous read.
6
- *
7
- * Usage:
8
- * ```ts
9
- * const summaries = new IncrementalJsonlSummary<MyState>({
10
- * initial: () => ({ lastType: undefined }),
11
- * reduce: (state, entry) => ({ ...state, lastType: (entry as any)?.type }),
12
- * });
13
- *
14
- * const result = summaries.read(filePath); // { state, size, mtime, skippedBytes } | null
15
- * summaries.prune(); // once per refresh: evict paths not read since the last prune
16
- * ```
17
- *
18
- * Read rules, keyed by file path:
19
- * - dev, ino, size and mtimeMs unchanged → cached state, 0 bytes read.
20
- * - same dev/ino and size grew → read only the bytes after the last complete line.
21
- * - anything else (first read, shrink, rotation, in-place rewrite) → rebuild.
22
- *
23
- * A rebuild of a file larger than `headBytes + tailBytes` (default 1 MiB +
24
- * 4 MiB) is a bounded cold start rather than a full parse: it folds the
25
- * complete lines in `[0, headBytes)`, calls `reducer.skip(state)`, then folds
26
- * the lines that start inside `[size - tailBytes, size)`, including a line
27
- * that starts exactly at `size - tailBytes` (one extra byte before the window
28
- * is read to tell). Lines straddling a window edge are dropped. A field whose
29
- * entries all sit in the skipped middle keeps whatever `skip` leaves; there is
30
- * never a hidden full scan. The result's `skippedBytes` reports the unread
31
- * middle, and the cache is seeded at end of file so later appends stay
32
- * incremental.
33
- *
34
- * An unterminated last line is never folded into the committed state. If it
35
- * already parses as JSON it is applied to the returned state only, and it is
36
- * re-read (from its start offset) once more bytes arrive.
37
- */
38
-
39
- import * as fs from "fs";
40
-
41
- /**
42
- * Pure fold over the entries of a JSONL file.
43
- *
44
- * `reduce` receives each non-blank line in file order: the parsed JSON value,
45
- * or `undefined` when the line is not valid JSON. It must return a new state
46
- * rather than mutate `state`, and the state should stay O(1) in file size
47
- * (no entry arrays or raw file contents).
48
- *
49
- * `skip` is called once when a bounded cold start skips the middle of a file,
50
- * between the head lines and the tail lines. It returns the state the tail
51
- * lines fold onto: keep what the head established (e.g. the first entry) and
52
- * reset fields that track the latest entry, so those come only from lines
53
- * actually read. Without `skip`, tail lines fold straight onto the head state.
54
- */
55
- export interface JsonlSummaryReducer<S> {
56
- initial(): S;
57
- reduce(state: S, entry: unknown): S;
58
- skip?(state: S): S;
59
- }
60
-
61
- export interface JsonlSummaryResult<S> {
62
- state: S;
63
- /** File size in bytes when the state was computed. */
64
- size: number;
65
- /** File mtime (`fs.Stats.mtime`) when the state was computed. */
66
- mtime: Date;
67
- /** Bytes the bounded cold start did not read; 0 when the whole file was parsed. */
68
- skippedBytes: number;
69
- }
70
-
71
- export interface JsonlSummaryBounds {
72
- /** Bytes scanned from the start of the file on a cold start. */
73
- headBytes: number;
74
- /** Bytes scanned at the end of the file on a cold start. */
75
- tailBytes: number;
76
- }
77
-
78
- export interface IncrementalJsonlSummaryOptions {
79
- /** Bytes read per `fs.readSync` call. */
80
- chunkSize?: number;
81
- /** Cold-start scan bounds; `false` parses rebuilt files from byte 0. */
82
- bounds?: JsonlSummaryBounds | false;
83
- }
84
-
85
- interface CacheEntry<S> {
86
- dev: number;
87
- ino: number;
88
- size: number;
89
- mtimeMs: number;
90
- mtime: Date;
91
- /** Byte offset just past the last newline folded into `committed`. */
92
- offset: number;
93
- /** `offset` is mid-line: drop bytes up to and including the next newline. */
94
- discarding: boolean;
95
- /** State after every newline-terminated line. */
96
- committed: S;
97
- /** `committed` plus the unterminated last line, when it parses as JSON. */
98
- state: S;
99
- /** Bytes the cold start did not read. */
100
- skippedBytes: number;
101
- /** Prune generation in which this entry was last read. */
102
- seen: number;
103
- }
104
-
105
- export const DEFAULT_HEAD_BYTES = 1024 * 1024;
106
- export const DEFAULT_TAIL_BYTES = 4 * 1024 * 1024;
107
- const DEFAULT_CHUNK_SIZE = 1024 * 1024;
108
- const NEWLINE = 0x0a;
109
-
110
- /** Fold a whole JSONL string with a reducer (one-shot, uncached). */
111
- export function reduceJsonlContent<S>(reducer: JsonlSummaryReducer<S>, content: string): S {
112
- let state = reducer.initial();
113
- for (const line of content.split("\n")) {
114
- state = reduceLine(reducer, state, line);
115
- }
116
- return state;
117
- }
118
-
119
- export class IncrementalJsonlSummary<S> {
120
- private readonly entries = new Map<string, CacheEntry<S>>();
121
- private readonly chunkSize: number;
122
- private readonly bounds: JsonlSummaryBounds | false;
123
- private generation = 0;
124
-
125
- constructor(
126
- private readonly reducer: JsonlSummaryReducer<S>,
127
- options: IncrementalJsonlSummaryOptions = {},
128
- ) {
129
- this.chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
130
- this.bounds = options.bounds ?? {
131
- headBytes: DEFAULT_HEAD_BYTES,
132
- tailBytes: DEFAULT_TAIL_BYTES,
133
- };
134
- }
135
-
136
- /** Number of cached files. */
137
- get size(): number {
138
- return this.entries.size;
139
- }
140
-
141
- /** Return the summary of `filePath`, reading only what changed. Null if unreadable. */
142
- read(filePath: string): JsonlSummaryResult<S> | null {
143
- let stat: fs.Stats;
144
- try {
145
- stat = fs.statSync(filePath);
146
- } catch {
147
- this.entries.delete(filePath);
148
- return null;
149
- }
150
-
151
- const cached = this.entries.get(filePath);
152
- const sameFile = cached !== undefined && cached.dev === stat.dev && cached.ino === stat.ino;
153
-
154
- if (sameFile && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) {
155
- cached.seen = this.generation;
156
- return toResult(cached);
157
- }
158
-
159
- const appended = sameFile && stat.size > cached.size;
160
- const entry: CacheEntry<S> = appended
161
- ? { ...cached }
162
- : {
163
- dev: stat.dev,
164
- ino: stat.ino,
165
- size: 0,
166
- mtimeMs: 0,
167
- mtime: stat.mtime,
168
- offset: 0,
169
- discarding: false,
170
- committed: this.reducer.initial(),
171
- state: this.reducer.initial(),
172
- skippedBytes: 0,
173
- seen: this.generation,
174
- };
175
-
176
- try {
177
- const fd = fs.openSync(filePath, "r");
178
- try {
179
- const bounds = this.bounds;
180
- if (!appended && bounds && stat.size > bounds.headBytes + bounds.tailBytes) {
181
- this.readBounded(fd, entry, stat.size, bounds);
182
- } else {
183
- this.readRange(fd, entry, stat.size);
184
- }
185
- } finally {
186
- fs.closeSync(fd);
187
- }
188
- } catch {
189
- this.entries.delete(filePath);
190
- return null;
191
- }
192
-
193
- entry.mtimeMs = stat.mtimeMs;
194
- entry.mtime = stat.mtime;
195
- entry.seen = this.generation;
196
- this.entries.set(filePath, entry);
197
- return toResult(entry);
198
- }
199
-
200
- /** Evict entries not read since the previous `prune()` call. Call once per refresh. */
201
- prune(): void {
202
- for (const [filePath, entry] of this.entries) {
203
- if (entry.seen !== this.generation) {
204
- this.entries.delete(filePath);
205
- }
206
- }
207
- this.generation++;
208
- }
209
-
210
- /** Cold start: fold the head lines, `skip`, then the lines starting in the tail window. */
211
- private readBounded(
212
- fd: number,
213
- entry: CacheEntry<S>,
214
- size: number,
215
- { headBytes, tailBytes }: JsonlSummaryBounds,
216
- ): void {
217
- this.readRange(fd, entry, headBytes);
218
-
219
- const tailStart = size - tailBytes;
220
- const head = entry.committed;
221
- entry.committed = this.reducer.skip ? this.reducer.skip(head) : head;
222
- // Lines are only folded from their first byte, and tailStart may fall
223
- // mid-line. Discard from one byte earlier (tailStart > headBytes >= 0): if
224
- // that byte is the newline ending the previous line, discarding stops there
225
- // and the line starting at tailStart is folded; otherwise the partial line
226
- // is dropped up to its newline.
227
- entry.offset = tailStart - 1;
228
- entry.discarding = true;
229
- entry.skippedBytes = tailStart - headBytes;
230
- this.readRange(fd, entry, size);
231
- }
232
-
233
- /** Fold complete lines in `[entry.offset, end)` into `entry`. */
234
- private readRange(fd: number, entry: CacheEntry<S>, end: number): void {
235
- const chunk = Buffer.allocUnsafe(Math.min(this.chunkSize, Math.max(end - entry.offset, 1)));
236
- let position = entry.offset;
237
- let carry: Buffer | undefined;
238
- let committed = entry.committed;
239
- let discarding = entry.discarding;
240
-
241
- while (position < end) {
242
- const bytesRead = fs.readSync(fd, chunk, 0, Math.min(chunk.length, end - position), position);
243
- if (bytesRead === 0) break;
244
- position += bytesRead;
245
-
246
- let lineStart = 0;
247
- let newline = chunk.indexOf(NEWLINE, 0);
248
- while (newline !== -1 && newline < bytesRead) {
249
- if (discarding) {
250
- discarding = false;
251
- } else {
252
- const lineBytes = carry
253
- ? Buffer.concat([carry, chunk.subarray(lineStart, newline)])
254
- : chunk.subarray(lineStart, newline);
255
- committed = reduceLine(this.reducer, committed, lineBytes.toString("utf8"));
256
- }
257
- carry = undefined;
258
- lineStart = newline + 1;
259
- newline = chunk.indexOf(NEWLINE, lineStart);
260
- }
261
-
262
- if (lineStart < bytesRead && !discarding) {
263
- const rest = Buffer.from(chunk.subarray(lineStart, bytesRead));
264
- carry = carry ? Buffer.concat([carry, rest]) : rest;
265
- }
266
- }
267
-
268
- entry.committed = committed;
269
- entry.discarding = discarding;
270
- entry.offset = position - (carry?.length ?? 0);
271
- entry.size = position;
272
- entry.state = carry
273
- ? reduceTentative(this.reducer, committed, carry.toString("utf8"))
274
- : committed;
275
- }
276
- }
277
-
278
- function toResult<S>(entry: CacheEntry<S>): JsonlSummaryResult<S> {
279
- return {
280
- state: entry.state,
281
- size: entry.size,
282
- mtime: entry.mtime,
283
- skippedBytes: entry.skippedBytes,
284
- };
285
- }
286
-
287
- function reduceLine<S>(reducer: JsonlSummaryReducer<S>, state: S, line: string): S {
288
- if (!/\S/.test(line)) return state;
289
- let entry: unknown;
290
- try {
291
- entry = JSON.parse(line);
292
- } catch {
293
- entry = undefined;
294
- }
295
- return reducer.reduce(state, entry);
296
- }
297
-
298
- /** Apply an unterminated line only if it is already valid JSON (i.e. fully written). */
299
- function reduceTentative<S>(reducer: JsonlSummaryReducer<S>, state: S, line: string): S {
300
- if (!/\S/.test(line)) return state;
301
- try {
302
- return reducer.reduce(state, JSON.parse(line));
303
- } catch {
304
- return state;
305
- }
306
- }
@@ -1,28 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
-
4
- export interface AgentRequest {
5
- sessionId: string;
6
- toolName: string;
7
- toolInput: Record<string, unknown>;
8
- timestamp: string;
9
- }
10
-
11
- export function getAgentRequestPath(homeDir: string, sessionId: string): string {
12
- return path.join(homeDir, ".ai-devkit", "agent-requests", `${sessionId}.json`);
13
- }
14
-
15
- export function readLatestAgentRequest(homeDir: string, sessionId: string): AgentRequest | null {
16
- try {
17
- const raw = fs.readFileSync(getAgentRequestPath(homeDir, sessionId), "utf-8");
18
- return JSON.parse(raw) as AgentRequest;
19
- } catch {
20
- return null;
21
- }
22
- }
23
-
24
- export function writeAgentRequest(homeDir: string, entry: AgentRequest): void {
25
- const filePath = getAgentRequestPath(homeDir, entry.sessionId);
26
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
27
- fs.writeFileSync(filePath, JSON.stringify(entry, null, 2), "utf-8");
28
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Escape a string for safe use inside an AppleScript double-quoted string.
3
- * Backslashes, double quotes, and newlines must be escaped.
4
- */
5
- export function escapeAppleScript(text: string): string {
6
- return text
7
- .replace(/\\/g, "\\\\")
8
- .replace(/"/g, '\\"')
9
- .replace(/\r\n|\r|\n/g, "\\n");
10
- }
@@ -1,349 +0,0 @@
1
- /**
2
- * Tail reader for append-only JSONL transcripts.
3
- *
4
- * Reading the last N conversation messages from a large transcript should not
5
- * require reading (and JSON-parsing) the whole file. This reader:
6
- *
7
- * 1. On the first call for a file, reads backward from the end in fixed-size
8
- * chunks until enough messages are collected (or the start is reached).
9
- * 2. Remembers `{dev, ino, offset}` plus a small window of parsed items, and
10
- * on later calls parses only bytes appended since `offset`.
11
- * 3. Resets (re-reads from the end) when the file is truncated or replaced by
12
- * a different inode.
13
- *
14
- * Each adapter supplies a {@link JsonlTailSource}: `parseLine` maps one raw
15
- * line to a candidate item (or null) and the optional `finalize` turns a
16
- * contiguous window of items into messages. `finalize` exists for formats
17
- * where one line's visibility depends on other lines (e.g. Codex drops an
18
- * `event_msg` mirrored by a `response_item`); line-independent formats can
19
- * omit it and return a {@link ConversationMessage} directly from `parseLine`.
20
- */
21
-
22
- import * as fs from "fs";
23
- import type { ConversationMessage } from "../adapters/AgentAdapter.js";
24
-
25
- /**
26
- * Normalize a `tail` option: a positive integer, or undefined for "full
27
- * conversation" (the pre-existing behaviour).
28
- */
29
- export function normalizeTail(tail: number | undefined): number | undefined {
30
- if (tail === undefined || !Number.isFinite(tail)) return undefined;
31
- const n = Math.floor(tail);
32
- return n > 0 ? n : undefined;
33
- }
34
-
35
- /** Keep the last `tail` messages of an already fully-parsed conversation. */
36
- export function sliceTail<T>(messages: T[], tail: number | undefined): T[] {
37
- const n = normalizeTail(tail);
38
- return n !== undefined && messages.length > n ? messages.slice(-n) : messages;
39
- }
40
-
41
- export const DEFAULT_TAIL_CHUNK_SIZE = 64 * 1024;
42
- const DEFAULT_MAX_FILES = 16;
43
- const NEWLINE = 0x0a;
44
- const ANCHOR_BYTES = 32;
45
-
46
- export interface JsonlTailSource<Item> {
47
- /** Map one raw JSONL line (no trailing newline) to an item, or null to skip it. */
48
- parseLine(line: string): Item | null;
49
- /**
50
- * Convert a contiguous window of items (oldest first) into messages. Must
51
- * behave like the adapter's full parse restricted to that window. Defaults
52
- * to treating every item as a {@link ConversationMessage}.
53
- */
54
- finalize?(items: Item[]): ConversationMessage[];
55
- }
56
-
57
- export interface JsonlTailReaderOptions {
58
- /** Bytes read per backward step. Defaults to 64 KiB. */
59
- chunkSize?: number;
60
- /** Number of (file, variant, tail) windows kept in the LRU cache. */
61
- maxFiles?: number;
62
- }
63
-
64
- interface TailState {
65
- dev: number;
66
- ino: number;
67
- size: number;
68
- mtimeMs: number;
69
- /** Byte offset just past the last newline consumed; appends are read from here. */
70
- offset: number;
71
- /**
72
- * Up to {@link ANCHOR_BYTES} bytes ending at `offset`. Re-checked before an
73
- * incremental read so a same-inode truncate-and-regrow is detected.
74
- */
75
- anchor: Buffer;
76
- /** Parsed items from complete (newline-terminated) lines, oldest first. */
77
- items: unknown[];
78
- /** Last computed result, returned as-is while the file is unchanged. */
79
- result: ConversationMessage[];
80
- }
81
-
82
- export class JsonlTailReader {
83
- private readonly chunkSize: number;
84
- private readonly maxFiles: number;
85
- private readonly cache = new Map<string, TailState>();
86
-
87
- constructor(options: JsonlTailReaderOptions = {}) {
88
- this.chunkSize = Math.max(1, options.chunkSize ?? DEFAULT_TAIL_CHUNK_SIZE);
89
- this.maxFiles = Math.max(1, options.maxFiles ?? DEFAULT_MAX_FILES);
90
- }
91
-
92
- /**
93
- * Return the last `tail` messages of `filePath`.
94
- *
95
- * @param variant Cache discriminator for sources whose output differs by
96
- * option (e.g. verbose vs. non-verbose).
97
- * @param overscan Extra messages collected beyond `tail` before trimming,
98
- * for sources whose `finalize` looks at neighbouring lines.
99
- */
100
- read<Item>(
101
- filePath: string,
102
- tail: number,
103
- source: JsonlTailSource<Item>,
104
- variant = "",
105
- overscan = 0,
106
- ): ConversationMessage[] {
107
- const key = `${variant}\0${tail}\0${filePath}`;
108
- const threshold = tail + Math.max(0, overscan);
109
-
110
- let stat: fs.Stats;
111
- try {
112
- stat = fs.statSync(filePath);
113
- } catch {
114
- this.cache.delete(key);
115
- return [];
116
- }
117
-
118
- const cached = this.cache.get(key);
119
- if (
120
- cached &&
121
- cached.dev === stat.dev &&
122
- cached.ino === stat.ino &&
123
- cached.size === stat.size &&
124
- cached.mtimeMs === stat.mtimeMs
125
- ) {
126
- this.touch(key, cached);
127
- return cached.result.slice();
128
- }
129
-
130
- let fd: number;
131
- try {
132
- fd = fs.openSync(filePath, "r");
133
- } catch {
134
- this.cache.delete(key);
135
- return [];
136
- }
137
-
138
- try {
139
- const current = fs.fstatSync(fd);
140
- const canAppend =
141
- cached !== undefined &&
142
- cached.dev === current.dev &&
143
- cached.ino === current.ino &&
144
- current.size >= cached.offset &&
145
- // A very large append is cheaper to re-read from the end.
146
- current.size - cached.offset <= Math.max(this.chunkSize * 16, 1024 * 1024);
147
-
148
- const state =
149
- (canAppend && this.readAppended(fd, current, cached, tail, threshold, source)) ||
150
- this.readBackward(fd, current, tail, threshold, source);
151
- this.touch(key, state);
152
- return state.result.slice();
153
- } catch {
154
- this.cache.delete(key);
155
- return [];
156
- } finally {
157
- fs.closeSync(fd);
158
- }
159
- }
160
-
161
- /** Forget all cached windows. */
162
- clear(): void {
163
- this.cache.clear();
164
- }
165
-
166
- private readBackward<Item>(
167
- fd: number,
168
- stat: fs.Stats,
169
- tail: number,
170
- threshold: number,
171
- source: JsonlTailSource<Item>,
172
- ): TailState {
173
- const reversed: Item[] = [];
174
- let partial: Item | null = null;
175
- let offset = 0;
176
- let sawNewline = false;
177
- // Pieces of the line currently being assembled, in file order.
178
- let pending: Buffer[] = [];
179
- let pos = stat.size;
180
-
181
- const takeLine = (piece: Buffer): void => {
182
- const lineBuf = pending.length === 0 ? piece : Buffer.concat([piece, ...pending]);
183
- pending = [];
184
- if (!sawNewline) {
185
- // Bytes after the file's last newline: an unterminated (possibly
186
- // still being written) line. Parsed tentatively, never cached.
187
- sawNewline = true;
188
- partial = this.parse(lineBuf, source);
189
- return;
190
- }
191
- const item = this.parse(lineBuf, source);
192
- if (item !== null) reversed.push(item);
193
- };
194
-
195
- while (pos > 0) {
196
- const len = Math.min(this.chunkSize, pos);
197
- pos -= len;
198
- const buf = readExactly(fd, pos, len);
199
-
200
- let end = len;
201
- let nl = end > 0 ? buf.lastIndexOf(NEWLINE, end - 1) : -1;
202
- while (nl !== -1) {
203
- if (!sawNewline) offset = pos + nl + 1;
204
- takeLine(buf.subarray(nl + 1, end));
205
- end = nl;
206
- nl = end > 0 ? buf.lastIndexOf(NEWLINE, end - 1) : -1;
207
- }
208
- if (end > 0) pending.unshift(buf.subarray(0, end));
209
-
210
- if (this.countMessages(reversed, partial, source, threshold) >= threshold) break;
211
- }
212
-
213
- if (pos === 0 && pending.length > 0) {
214
- // The first line of the file (no newline before it).
215
- const first = pending.shift()!;
216
- takeLine(first);
217
- }
218
-
219
- const items = reversed.reverse();
220
- return {
221
- dev: stat.dev,
222
- ino: stat.ino,
223
- size: stat.size,
224
- mtimeMs: stat.mtimeMs,
225
- offset,
226
- anchor: readAnchor(fd, offset),
227
- items,
228
- result: this.finish(items, partial, source, tail),
229
- };
230
- }
231
-
232
- /**
233
- * Parse bytes appended since the cached offset. Returns null when the
234
- * bytes before the offset no longer match (file rewritten in place).
235
- */
236
- private readAppended<Item>(
237
- fd: number,
238
- stat: fs.Stats,
239
- cached: TailState,
240
- tail: number,
241
- threshold: number,
242
- source: JsonlTailSource<Item>,
243
- ): TailState | null {
244
- let items = cached.items as Item[];
245
- let offset = cached.offset;
246
- let partial: Item | null = null;
247
-
248
- const anchorLength = cached.anchor.length;
249
- const raw = readExactly(fd, cached.offset - anchorLength, stat.size - offset + anchorLength);
250
- if (!raw.subarray(0, anchorLength).equals(cached.anchor)) return null;
251
- const buf = raw.subarray(anchorLength);
252
- let anchor = cached.anchor;
253
-
254
- if (buf.length > 0) {
255
- const added: Item[] = [];
256
- let start = 0;
257
- let nl = buf.indexOf(NEWLINE, start);
258
- while (nl !== -1) {
259
- const item = this.parse(buf.subarray(start, nl), source);
260
- if (item !== null) added.push(item);
261
- start = nl + 1;
262
- nl = buf.indexOf(NEWLINE, start);
263
- }
264
- offset = cached.offset + start;
265
- if (start > 0) anchor = tailBytes(raw.subarray(0, anchorLength + start));
266
- if (start < buf.length) partial = this.parse(buf.subarray(start), source);
267
-
268
- if (added.length > 0) {
269
- items = items.concat(added);
270
- // Bound the retained window; keep a generous margin so sources whose
271
- // finalize() drops items (e.g. de-duplication) still cover `tail`.
272
- if (items.length > threshold * 4) items = items.slice(-threshold * 2);
273
- }
274
- }
275
-
276
- return {
277
- dev: stat.dev,
278
- ino: stat.ino,
279
- size: stat.size,
280
- mtimeMs: stat.mtimeMs,
281
- offset,
282
- anchor,
283
- items,
284
- result: this.finish(items, partial, source, tail),
285
- };
286
- }
287
-
288
- private parse<Item>(lineBuf: Buffer, source: JsonlTailSource<Item>): Item | null {
289
- const line = lineBuf.toString("utf-8");
290
- if (line.trim().length === 0) return null;
291
- return source.parseLine(line);
292
- }
293
-
294
- private countMessages<Item>(
295
- reversed: Item[],
296
- partial: Item | null,
297
- source: JsonlTailSource<Item>,
298
- threshold: number,
299
- ): number {
300
- const available = reversed.length + (partial === null ? 0 : 1);
301
- if (!source.finalize || available < threshold) return available;
302
- const window = reversed.slice().reverse();
303
- if (partial !== null) window.push(partial);
304
- return source.finalize(window).length;
305
- }
306
-
307
- private finish<Item>(
308
- items: Item[],
309
- partial: Item | null,
310
- source: JsonlTailSource<Item>,
311
- tail: number,
312
- ): ConversationMessage[] {
313
- const window = partial === null ? items : [...items, partial];
314
- const messages = source.finalize
315
- ? source.finalize(window)
316
- : (window as unknown as ConversationMessage[]).slice();
317
- return messages.length > tail ? messages.slice(-tail) : messages;
318
- }
319
-
320
- private touch(key: string, state: TailState): void {
321
- this.cache.delete(key);
322
- this.cache.set(key, state);
323
- while (this.cache.size > this.maxFiles) {
324
- const oldest = this.cache.keys().next().value;
325
- if (oldest === undefined) break;
326
- this.cache.delete(oldest);
327
- }
328
- }
329
- }
330
-
331
- function readExactly(fd: number, position: number, length: number): Buffer {
332
- const buf = Buffer.allocUnsafe(length);
333
- let filled = 0;
334
- while (filled < length) {
335
- const n = fs.readSync(fd, buf, filled, length - filled, position + filled);
336
- if (n === 0) break;
337
- filled += n;
338
- }
339
- return filled === length ? buf : buf.subarray(0, filled);
340
- }
341
-
342
- function readAnchor(fd: number, offset: number): Buffer {
343
- const start = Math.max(0, offset - ANCHOR_BYTES);
344
- return Buffer.from(readExactly(fd, start, offset - start));
345
- }
346
-
347
- function tailBytes(buf: Buffer): Buffer {
348
- return Buffer.from(buf.subarray(Math.max(0, buf.length - ANCHOR_BYTES)));
349
- }