@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,1336 +0,0 @@
1
- /**
2
- * Tests for GeminiCliAdapter
3
- */
4
-
5
- import type { MockedFunction } from "vitest";
6
- import * as fs from "fs";
7
- import * as os from "os";
8
- import * as path from "path";
9
-
10
- import { GeminiCliAdapter } from "../../../harnesses/gemini/GeminiCliAdapter.js";
11
- import { GeminiSessionLocator } from "../../../harnesses/gemini/GeminiSessionLocator.js";
12
- import { GeminiSessionParser } from "../../../harnesses/gemini/GeminiSessionParser.js";
13
- import type { ProcessInfo } from "../../../adapters/AgentAdapter.js";
14
- import { AgentStatus } from "../../../adapters/AgentAdapter.js";
15
- import { AgentRegistry, type RegistryEntry } from "../../../utils/AgentRegistry.js";
16
- import {
17
- listAgentProcesses,
18
- enrichProcesses,
19
- captureProcessSnapshot,
20
- } from "../../../utils/process.js";
21
- import { matchProcessesToSessions, generateAgentName } from "../../../utils/matching.js";
22
- import * as crypto from "crypto";
23
-
24
- vi.mock("../../../utils/process.js", async (importOriginal) => {
25
- const actual = (await importOriginal()) as typeof import("../../../utils/process.js");
26
- return {
27
- ...actual,
28
- listAgentProcesses: vi.fn(),
29
- enrichProcesses: vi.fn(),
30
- captureProcessSnapshot: vi.fn(),
31
- };
32
- });
33
-
34
- vi.mock("../../../utils/matching.js", () => ({
35
- matchProcessesToSessions: vi.fn(),
36
- generateAgentName: vi.fn(),
37
- }));
38
-
39
- const mockedListAgentProcesses = listAgentProcesses as MockedFunction<typeof listAgentProcesses>;
40
- const mockedEnrichProcesses = enrichProcesses as MockedFunction<typeof enrichProcesses>;
41
- const mockedCaptureProcessSnapshot = captureProcessSnapshot as MockedFunction<
42
- typeof captureProcessSnapshot
43
- >;
44
- const mockedMatchProcessesToSessions = matchProcessesToSessions as MockedFunction<
45
- typeof matchProcessesToSessions
46
- >;
47
- const mockedGenerateAgentName = generateAgentName as MockedFunction<typeof generateAgentName>;
48
-
49
- describe("GeminiCliAdapter", () => {
50
- let adapter: GeminiCliAdapter;
51
- let tmpHome: string;
52
- let parser: GeminiSessionParser;
53
- let locator: GeminiSessionLocator;
54
-
55
- beforeEach(() => {
56
- tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "gemini-adapter-test-"));
57
- process.env.HOME = tmpHome;
58
-
59
- adapter = new GeminiCliAdapter(new AgentRegistry(path.join(tmpHome, "agents.json")));
60
- parser = new GeminiSessionParser();
61
- locator = new GeminiSessionLocator({
62
- geminiTmpDir: path.join(tmpHome, ".gemini", "tmp"),
63
- });
64
- mockedListAgentProcesses.mockReset();
65
- mockedEnrichProcesses.mockReset();
66
- mockedCaptureProcessSnapshot.mockReset();
67
- mockedMatchProcessesToSessions.mockReset();
68
- mockedGenerateAgentName.mockReset();
69
-
70
- mockedEnrichProcesses.mockImplementation((procs) => procs);
71
- // Compatibility shim for standalone adapter discovery; the manager captures once and slices by name.
72
- mockedCaptureProcessSnapshot.mockImplementation(async (names) =>
73
- enrichProcesses(names.flatMap((name) => listAgentProcesses(name))),
74
- );
75
- mockedMatchProcessesToSessions.mockReturnValue([]);
76
- mockedGenerateAgentName.mockImplementation((cwd: string, pid: number) => {
77
- const folder = path.basename(cwd) || "unknown";
78
- return `${folder} (${pid})`;
79
- });
80
- });
81
-
82
- afterEach(() => {
83
- fs.rmSync(tmpHome, { recursive: true, force: true });
84
- });
85
-
86
- describe("initialization", () => {
87
- it("should expose gemini_cli type", () => {
88
- expect(adapter.type).toBe("gemini_cli");
89
- });
90
- });
91
-
92
- describe("canHandle", () => {
93
- it("should return true for plain gemini command", () => {
94
- expect(adapter.canHandle({ pid: 1, command: "gemini", cwd: "/repo", tty: "ttys001" })).toBe(
95
- true,
96
- );
97
- });
98
-
99
- it("should return true for gemini with full path (case-insensitive)", () => {
100
- expect(
101
- adapter.canHandle({
102
- pid: 2,
103
- command: "/usr/local/bin/GEMINI --yolo",
104
- cwd: "/repo",
105
- tty: "ttys002",
106
- }),
107
- ).toBe(true);
108
- });
109
-
110
- it("should return false for non-gemini processes", () => {
111
- expect(
112
- adapter.canHandle({ pid: 3, command: "node app.js", cwd: "/repo", tty: "ttys003" }),
113
- ).toBe(false);
114
- });
115
-
116
- it('should return false when "gemini" appears only in path arguments', () => {
117
- expect(
118
- adapter.canHandle({
119
- pid: 4,
120
- command: "node /path/to/gemini-runner.js",
121
- cwd: "/repo",
122
- tty: "ttys004",
123
- }),
124
- ).toBe(false);
125
- });
126
-
127
- it("should return true for Node-invoked gemini script (real install layout)", () => {
128
- expect(
129
- adapter.canHandle({
130
- pid: 5,
131
- command: "node /Users/foo/.volta/tools/image/node/24.14.0/bin/gemini --help",
132
- cwd: "/repo",
133
- tty: "ttys005",
134
- }),
135
- ).toBe(true);
136
- });
137
-
138
- it("should return true for Node-invoked gemini.js bundle entrypoint", () => {
139
- expect(
140
- adapter.canHandle({
141
- pid: 6,
142
- command: "node /opt/homebrew/lib/node_modules/@google/gemini-cli/bundle/gemini.js",
143
- cwd: "/repo",
144
- tty: "ttys006",
145
- }),
146
- ).toBe(true);
147
- });
148
-
149
- it("should recognize Windows executable and entrypoint paths", () => {
150
- expect(
151
- adapter.canHandle({
152
- pid: 7,
153
- command: "C:\\tools\\node.exe C:\\lib\\gemini.js",
154
- cwd: "C:\\repo",
155
- tty: "",
156
- }),
157
- ).toBe(true);
158
- });
159
- });
160
-
161
- describe("detectAgents", () => {
162
- it("should return empty array when no gemini processes are running", async () => {
163
- mockedListAgentProcesses.mockReturnValue([]);
164
- const agents = await adapter.detectAgents();
165
- expect(agents).toEqual([]);
166
- });
167
-
168
- it("should filter non-gemini Node processes out of the node process pool", async () => {
169
- const geminiProc: ProcessInfo = {
170
- pid: 100,
171
- command: "node /Users/foo/.volta/tools/image/node/24.14.0/bin/gemini --help",
172
- cwd: "/repo",
173
- tty: "ttys001",
174
- startTime: new Date("2026-04-18T00:00:00Z"),
175
- };
176
- const unrelatedNodeProc: ProcessInfo = {
177
- pid: 200,
178
- command: "node /usr/local/bin/eslint src/",
179
- cwd: "/other-repo",
180
- tty: "ttys002",
181
- startTime: new Date("2026-04-18T00:00:00Z"),
182
- };
183
- mockedListAgentProcesses.mockReturnValue([geminiProc, unrelatedNodeProc]);
184
-
185
- const agents = await adapter.detectAgents();
186
- expect(agents).toHaveLength(1);
187
- expect(agents[0].pid).toBe(100);
188
- });
189
-
190
- it("should detect gemini run by a node binary installed under a path containing spaces", async () => {
191
- const nodePath = path.join(tmpHome, "Applications", "Dev Tools", "node", "bin", "node");
192
- fs.mkdirSync(path.dirname(nodePath), { recursive: true });
193
- fs.writeFileSync(nodePath, "");
194
- const geminiProc: ProcessInfo = {
195
- pid: 100,
196
- command: `${nodePath} ${tmpHome}/My Tools/lib/node_modules/.bin/gemini --prompt fix the bug`,
197
- cwd: "/repo",
198
- tty: "ttys001",
199
- startTime: new Date("2026-04-18T00:00:00Z"),
200
- };
201
- const unrelatedNodeProc: ProcessInfo = {
202
- pid: 200,
203
- command: `${nodePath} /usr/local/bin/eslint src/`,
204
- cwd: "/other-repo",
205
- tty: "ttys002",
206
- startTime: new Date("2026-04-18T00:00:00Z"),
207
- };
208
-
209
- const agents = await adapter.detectAgents({ processes: [geminiProc, unrelatedNodeProc] });
210
- expect(agents.map((agent) => agent.pid)).toEqual([100]);
211
- });
212
-
213
- it("should return process-only agents when no session files exist for the process", async () => {
214
- const proc: ProcessInfo = {
215
- pid: 1234,
216
- command: "node /usr/local/bin/gemini",
217
- cwd: "/repo",
218
- tty: "ttys001",
219
- startTime: new Date("2026-04-18T00:00:00Z"),
220
- };
221
- mockedListAgentProcesses.mockReturnValue([proc]);
222
-
223
- const agents = await adapter.detectAgents();
224
- expect(agents).toHaveLength(1);
225
- expect(agents[0]).toMatchObject({
226
- type: "gemini_cli",
227
- pid: 1234,
228
- projectPath: "/repo",
229
- status: AgentStatus.RUNNING,
230
- sessionId: "pid-1234",
231
- });
232
- });
233
-
234
- it("should suppress Gemini wrapper process-only agents before a session file exists", async () => {
235
- const wrapperProc: ProcessInfo = {
236
- pid: 20452,
237
- ppid: 17530,
238
- command: "/opt/homebrew/opt/node/bin/node /opt/homebrew/bin/gemini",
239
- cwd: "/repo",
240
- tty: "ttys007",
241
- startTime: new Date("2026-06-13T08:25:21Z"),
242
- };
243
- const childProc: ProcessInfo = {
244
- pid: 21373,
245
- ppid: 20452,
246
- command:
247
- "/opt/homebrew/Cellar/node/26.0.0/bin/node --max-old-space-size=8192 /opt/homebrew/bin/gemini",
248
- cwd: "/repo",
249
- tty: "ttys007",
250
- startTime: new Date("2026-06-13T08:25:26Z"),
251
- };
252
- mockedListAgentProcesses.mockReturnValue([wrapperProc, childProc]);
253
-
254
- const agents = await adapter.detectAgents();
255
-
256
- expect(agents).toHaveLength(1);
257
- expect(agents[0]).toMatchObject({
258
- pid: 21373,
259
- sessionId: "pid-21373",
260
- summary: "Gemini CLI process running",
261
- });
262
- });
263
-
264
- it("should carry the managed wrapper name to a process-only child before a session file exists", async () => {
265
- const regPath = path.join(tmpHome, "agents.json");
266
- const registry = new AgentRegistry(regPath);
267
- const namedAdapter = new GeminiCliAdapter(registry);
268
- const wrapperProc: ProcessInfo = {
269
- pid: 35792,
270
- ppid: 33068,
271
- command: "/opt/homebrew/opt/node/bin/node /opt/homebrew/bin/gemini",
272
- cwd: "/repo",
273
- tty: "ttys002",
274
- startTime: new Date("2026-06-13T19:15:16Z"),
275
- };
276
- const childProc: ProcessInfo = {
277
- pid: 36514,
278
- ppid: 35792,
279
- command:
280
- "/opt/homebrew/Cellar/node/26.0.0/bin/node --max-old-space-size=8192 /opt/homebrew/bin/gemini",
281
- cwd: "/repo",
282
- tty: "ttys002",
283
- startTime: new Date("2026-06-13T19:15:18Z"),
284
- };
285
- registry.register({
286
- name: "cli-mqcqj469",
287
- type: "gemini_cli",
288
- pid: wrapperProc.pid,
289
- runtime: "tmux",
290
- runtimeRef: { session: "cli-mqcqj469" },
291
- cwd: wrapperProc.cwd,
292
- startedAt: "2026-06-13T19:15:16.211Z",
293
- sessionId: `pid-${wrapperProc.pid}`,
294
- sessionFilePath: "",
295
- });
296
- mockedListAgentProcesses.mockReturnValue([wrapperProc, childProc]);
297
-
298
- const agents = await namedAdapter.detectAgents();
299
-
300
- expect(agents).toHaveLength(1);
301
- expect(agents[0]).toMatchObject({
302
- name: "cli-mqcqj469",
303
- pid: childProc.pid,
304
- sessionId: `pid-${childProc.pid}`,
305
- });
306
- });
307
-
308
- it("should map a process to its matching session file via projectHash", async () => {
309
- const cwd = "/repo/project-a";
310
- const projectHash = hashProjectRoot(cwd);
311
- const shortId = "abc123";
312
- const chatsDir = path.join(tmpHome, ".gemini", "tmp", shortId, "chats");
313
- fs.mkdirSync(chatsDir, { recursive: true });
314
- const sessionPath = path.join(chatsDir, "session-2026-04-18T00-00-session1.json");
315
- const sessionStart = new Date("2026-04-18T00:00:00Z").toISOString();
316
- fs.writeFileSync(
317
- sessionPath,
318
- JSON.stringify({
319
- sessionId: "session1",
320
- projectHash,
321
- startTime: sessionStart,
322
- lastUpdated: sessionStart,
323
- kind: "main",
324
- messages: [{ id: "m1", timestamp: sessionStart, type: "user", content: "hello gemini" }],
325
- }),
326
- );
327
-
328
- const proc: ProcessInfo = {
329
- pid: 42,
330
- command: "node /usr/local/bin/gemini",
331
- cwd,
332
- tty: "ttys001",
333
- startTime: new Date("2026-04-18T00:00:00Z"),
334
- };
335
- mockedListAgentProcesses.mockReturnValue([proc]);
336
- mockedMatchProcessesToSessions.mockReturnValue([
337
- {
338
- process: proc,
339
- session: {
340
- sessionId: "session1",
341
- filePath: sessionPath,
342
- projectDir: chatsDir,
343
- birthtimeMs: Date.now(),
344
- resolvedCwd: cwd,
345
- },
346
- deltaMs: 0,
347
- },
348
- ]);
349
-
350
- const agents = await adapter.detectAgents();
351
- expect(agents).toHaveLength(1);
352
- expect(agents[0]).toMatchObject({
353
- type: "gemini_cli",
354
- pid: 42,
355
- projectPath: cwd,
356
- sessionId: "session1",
357
- sessionFilePath: sessionPath,
358
- });
359
- expect(agents[0].summary).toContain("hello gemini");
360
- });
361
-
362
- it("should collapse Gemini wrapper and child processes matched to the same session", async () => {
363
- const cwd = "/repo/project-a";
364
- const projectHash = hashProjectRoot(cwd);
365
- const shortId = "abc123";
366
- const chatsDir = path.join(tmpHome, ".gemini", "tmp", shortId, "chats");
367
- fs.mkdirSync(chatsDir, { recursive: true });
368
- const sessionPath = path.join(chatsDir, "session-2026-04-18T00-00-session1.json");
369
- const sessionStart = new Date("2026-04-18T00:00:00Z").toISOString();
370
- fs.writeFileSync(
371
- sessionPath,
372
- JSON.stringify({
373
- sessionId: "session1",
374
- projectHash,
375
- startTime: sessionStart,
376
- lastUpdated: sessionStart,
377
- kind: "main",
378
- directories: [cwd],
379
- messages: [{ id: "m1", timestamp: sessionStart, type: "user", content: "hello gemini" }],
380
- }),
381
- );
382
-
383
- const wrapperProc: ProcessInfo = {
384
- pid: 88394,
385
- command: "node /Users/foo/.nvm/versions/node/v23.9.0/bin/gemini",
386
- cwd,
387
- tty: "ttys015",
388
- startTime: new Date("2026-04-18T00:00:00Z"),
389
- };
390
- const childProc: ProcessInfo = {
391
- pid: 88460,
392
- command:
393
- "/Users/foo/.nvm/versions/node/v24.13.1/bin/node /Users/foo/.nvm/versions/node/v23.9.0/bin/gemini",
394
- cwd,
395
- tty: "ttys015",
396
- startTime: new Date("2026-04-18T00:00:01Z"),
397
- };
398
- mockedListAgentProcesses.mockReturnValue([wrapperProc, childProc]);
399
- mockedMatchProcessesToSessions.mockReturnValue([
400
- {
401
- process: wrapperProc,
402
- session: {
403
- sessionId: "session1",
404
- filePath: sessionPath,
405
- projectDir: chatsDir,
406
- birthtimeMs: Date.now(),
407
- resolvedCwd: cwd,
408
- },
409
- deltaMs: 0,
410
- },
411
- {
412
- process: childProc,
413
- session: {
414
- sessionId: "session1",
415
- filePath: sessionPath,
416
- projectDir: chatsDir,
417
- birthtimeMs: Date.now(),
418
- resolvedCwd: cwd,
419
- },
420
- deltaMs: 0,
421
- },
422
- ]);
423
-
424
- const agents = await adapter.detectAgents();
425
-
426
- expect(agents).toHaveLength(1);
427
- expect(agents[0]).toMatchObject({
428
- pid: 88460,
429
- sessionId: "session1",
430
- sessionFilePath: sessionPath,
431
- });
432
- });
433
-
434
- it("should not match sessions from other projects", async () => {
435
- const procCwd = "/repo/project-a";
436
- const otherCwd = "/repo/project-b";
437
- const otherHash = hashProjectRoot(otherCwd);
438
- const chatsDir = path.join(tmpHome, ".gemini", "tmp", "other", "chats");
439
- fs.mkdirSync(chatsDir, { recursive: true });
440
- const sessionPath = path.join(chatsDir, "session-2026-04-18T00-00-other.json");
441
- fs.writeFileSync(
442
- sessionPath,
443
- JSON.stringify({
444
- sessionId: "other-session",
445
- projectHash: otherHash,
446
- startTime: new Date().toISOString(),
447
- lastUpdated: new Date().toISOString(),
448
- kind: "main",
449
- messages: [],
450
- }),
451
- );
452
-
453
- const proc: ProcessInfo = {
454
- pid: 7,
455
- command: "node /usr/local/bin/gemini",
456
- cwd: procCwd,
457
- tty: "ttys001",
458
- startTime: new Date(),
459
- };
460
- mockedListAgentProcesses.mockReturnValue([proc]);
461
-
462
- const agents = await adapter.detectAgents();
463
-
464
- const candidateSessions = mockedMatchProcessesToSessions.mock.calls[0]?.[1] ?? [];
465
- expect(candidateSessions).toHaveLength(0);
466
-
467
- expect(agents).toHaveLength(1);
468
- expect(agents[0].sessionId).toBe(`pid-${proc.pid}`);
469
- });
470
- });
471
-
472
- describe("detectAgents — registry cache short-circuit", () => {
473
- let regPath: string;
474
- let registry: AgentRegistry;
475
- let cachedAdapter: GeminiCliAdapter;
476
- let sessionFilePath: string;
477
-
478
- function registerEntry(over: Partial<RegistryEntry> = {}): void {
479
- registry.register({
480
- name: "gemini-100",
481
- type: "gemini_cli",
482
- pid: 100,
483
- runtime: "tmux",
484
- runtimeRef: null,
485
- cwd: "/repo-a",
486
- startedAt: "2026-05-30T00:00:00.000Z",
487
- sessionId: "s-cached",
488
- sessionFilePath,
489
- ...over,
490
- });
491
- }
492
-
493
- beforeEach(() => {
494
- regPath = path.join(tmpHome, "agents.json");
495
- registry = new AgentRegistry(regPath);
496
- cachedAdapter = new GeminiCliAdapter(registry);
497
-
498
- const now = new Date().toISOString();
499
- sessionFilePath = path.join(tmpHome, "gemini-session.json");
500
- fs.writeFileSync(
501
- sessionFilePath,
502
- JSON.stringify({
503
- sessionId: "s-cached",
504
- projectHash: "h",
505
- startTime: now,
506
- lastUpdated: now,
507
- directories: ["/repo-a"],
508
- messages: [
509
- { id: "m1", timestamp: now, type: "user", content: "Hello from gemini cache" },
510
- ],
511
- }),
512
- );
513
- });
514
-
515
- it("short-circuits matching when registry has a valid entry", async () => {
516
- registerEntry();
517
- const proc: ProcessInfo = {
518
- pid: 100,
519
- command: "node /path/to/gemini --help",
520
- cwd: "/repo-a",
521
- tty: "ttys001",
522
- startTime: new Date(),
523
- };
524
- mockedListAgentProcesses.mockReturnValue([proc]);
525
-
526
- const agents = await cachedAdapter.detectAgents();
527
-
528
- expect(agents).toHaveLength(1);
529
- expect(agents[0]).toMatchObject({
530
- type: "gemini_cli",
531
- pid: 100,
532
- sessionId: "s-cached",
533
- summary: "Hello from gemini cache",
534
- });
535
- expect(mockedMatchProcessesToSessions).not.toHaveBeenCalled();
536
- });
537
-
538
- it("falls through when no registry entry exists for the pid", async () => {
539
- const proc: ProcessInfo = {
540
- pid: 100,
541
- command: "node /path/to/gemini --help",
542
- cwd: "/repo-a",
543
- tty: "ttys001",
544
- startTime: new Date(),
545
- };
546
- mockedListAgentProcesses.mockReturnValue([proc]);
547
-
548
- const agents = await cachedAdapter.detectAgents();
549
-
550
- expect(agents[0].sessionId).toBe("pid-100");
551
- });
552
-
553
- it("falls through when registry entry type does not match", async () => {
554
- registerEntry({ type: "claude" });
555
- const proc: ProcessInfo = {
556
- pid: 100,
557
- command: "node /path/to/gemini --help",
558
- cwd: "/repo-a",
559
- tty: "ttys001",
560
- startTime: new Date(),
561
- };
562
- mockedListAgentProcesses.mockReturnValue([proc]);
563
-
564
- const agents = await cachedAdapter.detectAgents();
565
-
566
- expect(agents[0].sessionId).toBe("pid-100");
567
- });
568
-
569
- it("falls through when the cached session file no longer exists", async () => {
570
- registerEntry({ sessionFilePath: path.join(tmpHome, "deleted.json") });
571
- const proc: ProcessInfo = {
572
- pid: 100,
573
- command: "node /path/to/gemini --help",
574
- cwd: "/repo-a",
575
- tty: "ttys001",
576
- startTime: new Date(),
577
- };
578
- mockedListAgentProcesses.mockReturnValue([proc]);
579
-
580
- const agents = await cachedAdapter.detectAgents();
581
-
582
- expect(agents[0].sessionId).toBe("pid-100");
583
- });
584
-
585
- it("carries the managed wrapper name to the detected child process", async () => {
586
- const wrapperProc: ProcessInfo = {
587
- pid: 20339,
588
- ppid: 17570,
589
- command: "/opt/homebrew/opt/node/bin/node /opt/homebrew/bin/gemini",
590
- cwd: "/repo-a",
591
- tty: "ttys002",
592
- startTime: new Date("2026-06-13T19:00:53Z"),
593
- };
594
- const childProc: ProcessInfo = {
595
- pid: 21038,
596
- ppid: 20339,
597
- command:
598
- "/opt/homebrew/Cellar/node/26.0.0/bin/node --max-old-space-size=8192 /opt/homebrew/bin/gemini",
599
- cwd: "/repo-a",
600
- tty: "ttys002",
601
- startTime: new Date("2026-06-13T19:00:57Z"),
602
- };
603
- const now = new Date().toISOString();
604
- sessionFilePath = writeSession(tmpHome, "cli-2", "session-2026-06-13T19-00-s-cached", {
605
- sessionId: "s-cached",
606
- projectHash: hashProjectRoot("/repo-a"),
607
- startTime: now,
608
- lastUpdated: now,
609
- directories: ["/repo-a"],
610
- messages: [{ id: "m1", timestamp: now, type: "user", content: "Hello from child process" }],
611
- });
612
- registerEntry({
613
- name: "cli-mqcq0mg5",
614
- pid: wrapperProc.pid,
615
- runtimeRef: { session: "cli-mqcq0mg5" },
616
- sessionId: "s-cached",
617
- sessionFilePath,
618
- });
619
- mockedListAgentProcesses.mockReturnValue([wrapperProc, childProc]);
620
- mockedMatchProcessesToSessions.mockReturnValue([
621
- {
622
- process: childProc,
623
- session: {
624
- sessionId: "s-cached",
625
- filePath: sessionFilePath,
626
- projectDir: path.dirname(sessionFilePath),
627
- birthtimeMs: Date.now(),
628
- resolvedCwd: "/repo-a",
629
- },
630
- deltaMs: 0,
631
- },
632
- ]);
633
-
634
- const agents = await cachedAdapter.detectAgents();
635
-
636
- expect(agents).toHaveLength(1);
637
- expect(agents[0]).toMatchObject({
638
- name: "cli-mqcq0mg5",
639
- pid: childProc.pid,
640
- sessionId: "s-cached",
641
- });
642
- });
643
- });
644
-
645
- describe("discoverSessions", () => {
646
- it("should return empty when ~/.gemini/tmp does not exist", () => {
647
- const proc: ProcessInfo = {
648
- pid: 1,
649
- command: "gemini",
650
- cwd: "/repo",
651
- tty: "ttys001",
652
- startTime: new Date(),
653
- };
654
- // tmp dir absent by default
655
- const result = locator.discoverSessions([proc]);
656
- expect(result.sessions).toEqual([]);
657
- expect(result).not.toHaveProperty("contentCache");
658
- });
659
-
660
- it("should skip processes with empty cwd when building the hash map", () => {
661
- const proc: ProcessInfo = {
662
- pid: 1,
663
- command: "gemini",
664
- cwd: "",
665
- tty: "ttys001",
666
- startTime: new Date(),
667
- };
668
- writeSession(tmpHome, "abc", "session-x", {
669
- sessionId: "s1",
670
- projectHash: hashProjectRoot("/some/where"),
671
- startTime: new Date().toISOString(),
672
- lastUpdated: new Date().toISOString(),
673
- kind: "main",
674
- messages: [],
675
- });
676
-
677
- const result = locator.discoverSessions([proc]);
678
- expect(result.sessions).toEqual([]);
679
- });
680
-
681
- it("should ignore sessions whose projectHash does not match any process cwd", () => {
682
- const proc: ProcessInfo = {
683
- pid: 1,
684
- command: "gemini",
685
- cwd: "/repo/a",
686
- tty: "ttys001",
687
- startTime: new Date(),
688
- };
689
- writeSession(tmpHome, "other", "session-other", {
690
- sessionId: "s-other",
691
- projectHash: hashProjectRoot("/repo/different"),
692
- startTime: new Date().toISOString(),
693
- lastUpdated: new Date().toISOString(),
694
- kind: "main",
695
- messages: [],
696
- });
697
-
698
- const result = locator.discoverSessions([proc]);
699
- expect(result.sessions).toEqual([]);
700
- });
701
-
702
- it("should skip malformed JSON files and still return valid ones", () => {
703
- const cwd = "/repo/valid";
704
- const proc: ProcessInfo = {
705
- pid: 1,
706
- command: "gemini",
707
- cwd,
708
- tty: "ttys001",
709
- startTime: new Date(),
710
- };
711
-
712
- const chatsDir = path.join(tmpHome, ".gemini", "tmp", "abc", "chats");
713
- fs.mkdirSync(chatsDir, { recursive: true });
714
- fs.writeFileSync(path.join(chatsDir, "session-bad.json"), "{ not valid");
715
- writeSession(tmpHome, "abc", "session-good", {
716
- sessionId: "s-good",
717
- projectHash: hashProjectRoot(cwd),
718
- startTime: new Date().toISOString(),
719
- lastUpdated: new Date().toISOString(),
720
- kind: "main",
721
- messages: [],
722
- });
723
-
724
- const result = locator.discoverSessions([proc]);
725
- expect(result.sessions).toHaveLength(1);
726
- expect(result.sessions[0].sessionId).toBe("s-good");
727
- });
728
-
729
- it("should match sessions whose projectHash is a parent of the process cwd (git root case)", () => {
730
- const gitRoot = "/repo/monorepo";
731
- const procCwd = "/repo/monorepo/packages/inner";
732
- const proc: ProcessInfo = {
733
- pid: 1,
734
- command: "gemini",
735
- cwd: procCwd,
736
- tty: "ttys001",
737
- startTime: new Date(),
738
- };
739
- writeSession(tmpHome, "abc", "session-rootmatch", {
740
- sessionId: "s-root",
741
- // Gemini CLI stores the hash of the walked-up project root,
742
- // not the process CWD.
743
- projectHash: hashProjectRoot(gitRoot),
744
- startTime: new Date().toISOString(),
745
- lastUpdated: new Date().toISOString(),
746
- kind: "main",
747
- messages: [],
748
- });
749
-
750
- const result = locator.discoverSessions([proc]);
751
- expect(result.sessions).toHaveLength(1);
752
- expect(result.sessions[0].resolvedCwd).toBe(procCwd);
753
- });
754
-
755
- it('should skip files that do not start with "session-"', () => {
756
- const cwd = "/repo/keep";
757
- const proc: ProcessInfo = {
758
- pid: 1,
759
- command: "gemini",
760
- cwd,
761
- tty: "ttys001",
762
- startTime: new Date(),
763
- };
764
-
765
- const chatsDir = path.join(tmpHome, ".gemini", "tmp", "abc", "chats");
766
- fs.mkdirSync(chatsDir, { recursive: true });
767
- fs.writeFileSync(
768
- path.join(chatsDir, "notsession.json"),
769
- JSON.stringify({
770
- sessionId: "skip",
771
- projectHash: hashProjectRoot(cwd),
772
- messages: [],
773
- }),
774
- );
775
-
776
- const result = locator.discoverSessions([proc]);
777
- expect(result.sessions).toEqual([]);
778
- });
779
- });
780
-
781
- describe("GeminiSessionParser", () => {
782
- describe("determineStatus", () => {
783
- it('should return "waiting" when the last message is from gemini', () => {
784
- const session = {
785
- sessionId: "s",
786
- projectPath: "",
787
- summary: "",
788
- sessionStart: new Date(),
789
- lastActive: new Date(),
790
- lastMessageType: "gemini",
791
- };
792
- expect(parser.determineStatus(session)).toBe(AgentStatus.WAITING);
793
- });
794
-
795
- it('should return "waiting" when the last message is from assistant', () => {
796
- const session = {
797
- sessionId: "s",
798
- projectPath: "",
799
- summary: "",
800
- sessionStart: new Date(),
801
- lastActive: new Date(),
802
- lastMessageType: "assistant",
803
- };
804
- expect(parser.determineStatus(session)).toBe(AgentStatus.WAITING);
805
- });
806
-
807
- it('should return "running" when the last message is from the user', () => {
808
- const session = {
809
- sessionId: "s",
810
- projectPath: "",
811
- summary: "",
812
- sessionStart: new Date(),
813
- lastActive: new Date(),
814
- lastMessageType: "user",
815
- };
816
- expect(parser.determineStatus(session)).toBe(AgentStatus.RUNNING);
817
- });
818
-
819
- it('should return "idle" when last activity is older than the threshold', () => {
820
- const session = {
821
- sessionId: "s",
822
- projectPath: "",
823
- summary: "",
824
- sessionStart: new Date(),
825
- lastActive: new Date(Date.now() - 10 * 60 * 1000),
826
- lastMessageType: "user",
827
- };
828
- expect(parser.determineStatus(session)).toBe(AgentStatus.IDLE);
829
- });
830
-
831
- it('should stay "waiting" past the idle threshold when awaiting input', () => {
832
- const session = {
833
- sessionId: "s",
834
- projectPath: "",
835
- summary: "",
836
- sessionStart: new Date(),
837
- lastActive: new Date(Date.now() - 10 * 60 * 1000),
838
- lastMessageType: "gemini",
839
- };
840
- expect(parser.determineStatus(session)).toBe(AgentStatus.WAITING);
841
- });
842
- });
843
-
844
- describe("parseSession", () => {
845
- it("should parse a valid session file", () => {
846
- const filePath = writeSession(tmpHome, "p", "session-a", {
847
- sessionId: "s1",
848
- projectHash: "h",
849
- startTime: "2026-04-18T00:00:00Z",
850
- lastUpdated: "2026-04-18T00:05:00Z",
851
- kind: "main",
852
- directories: ["/repo"],
853
- messages: [
854
- { id: "m1", timestamp: "2026-04-18T00:00:01Z", type: "user", content: "hello" },
855
- ],
856
- });
857
-
858
- const result = parser.parseSession(undefined, filePath);
859
- expect(result).toMatchObject({
860
- sessionId: "s1",
861
- projectPath: "/repo",
862
- summary: "hello",
863
- });
864
- });
865
-
866
- it("should parse from cached content without reading disk", () => {
867
- const content = JSON.stringify({
868
- sessionId: "s2",
869
- projectHash: "h",
870
- startTime: "2026-04-18T00:00:00Z",
871
- lastUpdated: "2026-04-18T00:00:00Z",
872
- messages: [],
873
- });
874
-
875
- const result = parser.parseSession(content, "/does/not/exist.json");
876
- expect(result?.sessionId).toBe("s2");
877
- });
878
-
879
- it("should return null for a missing file with no cached content", () => {
880
- expect(parser.parseSession(undefined, "/missing.json")).toBeNull();
881
- });
882
-
883
- it("should return null when the file is not valid JSON", () => {
884
- const filePath = path.join(tmpHome, "broken.json");
885
- fs.writeFileSync(filePath, "not json");
886
- expect(parser.parseSession(undefined, filePath)).toBeNull();
887
- });
888
-
889
- it("should return null when sessionId is missing", () => {
890
- const filePath = path.join(tmpHome, "no-id.json");
891
- fs.writeFileSync(filePath, JSON.stringify({ messages: [] }));
892
- expect(parser.parseSession(undefined, filePath)).toBeNull();
893
- });
894
-
895
- it("should default the summary when no user message has content", () => {
896
- const filePath = writeSession(tmpHome, "p", "session-empty", {
897
- sessionId: "s3",
898
- projectHash: "h",
899
- startTime: "2026-04-18T00:00:00Z",
900
- lastUpdated: "2026-04-18T00:00:00Z",
901
- messages: [
902
- {
903
- id: "m1",
904
- timestamp: "2026-04-18T00:00:01Z",
905
- type: "gemini",
906
- content: "only assistant",
907
- },
908
- ],
909
- });
910
-
911
- const result = parser.parseSession(undefined, filePath);
912
- expect(result?.summary).toBe("Gemini CLI session active");
913
- });
914
-
915
- it("should truncate long summaries to 120 characters", () => {
916
- const longContent = "x".repeat(200);
917
- const filePath = writeSession(tmpHome, "p", "session-long", {
918
- sessionId: "s4",
919
- projectHash: "h",
920
- startTime: "2026-04-18T00:00:00Z",
921
- lastUpdated: "2026-04-18T00:00:00Z",
922
- messages: [
923
- { id: "m1", timestamp: "2026-04-18T00:00:01Z", type: "user", content: longContent },
924
- ],
925
- });
926
-
927
- const result = parser.parseSession(undefined, filePath);
928
- expect(result?.summary.length).toBe(120);
929
- expect(result?.summary.endsWith("...")).toBe(true);
930
- });
931
-
932
- it("should extract summary when user content is an array of parts (real Gemini shape)", () => {
933
- const filePath = writeSession(tmpHome, "p", "session-parts", {
934
- sessionId: "s-parts",
935
- projectHash: "h",
936
- startTime: "2026-04-18T00:00:00Z",
937
- lastUpdated: "2026-04-18T00:00:00Z",
938
- messages: [
939
- {
940
- id: "m1",
941
- timestamp: "2026-04-18T00:00:01Z",
942
- type: "user",
943
- content: [{ text: "hello from part" }, { text: " continued" }],
944
- },
945
- ],
946
- });
947
-
948
- const result = parser.parseSession(undefined, filePath);
949
- expect(result?.summary).toBe("hello from part continued");
950
- });
951
-
952
- it("should drop non-text parts (data/file) when resolving user content", () => {
953
- const filePath = writeSession(tmpHome, "p", "session-mixed-parts", {
954
- sessionId: "s-mixed",
955
- projectHash: "h",
956
- startTime: "2026-04-18T00:00:00Z",
957
- lastUpdated: "2026-04-18T00:00:00Z",
958
- messages: [
959
- {
960
- id: "m1",
961
- timestamp: "2026-04-18T00:00:01Z",
962
- type: "user",
963
- content: [
964
- { text: "readable text" },
965
- { inlineData: { mimeType: "image/png", data: "base64..." } },
966
- { text: " + more" },
967
- ],
968
- },
969
- ],
970
- });
971
-
972
- const result = parser.parseSession(undefined, filePath);
973
- expect(result?.summary).toBe("readable text + more");
974
- });
975
-
976
- it("should prefer lastUpdated over entry timestamp for lastActive", () => {
977
- const filePath = writeSession(tmpHome, "p", "session-last", {
978
- sessionId: "s5",
979
- projectHash: "h",
980
- startTime: "2026-04-18T00:00:00Z",
981
- lastUpdated: "2026-04-18T00:10:00Z",
982
- messages: [{ id: "m1", timestamp: "2026-04-18T00:00:01Z", type: "user", content: "hi" }],
983
- });
984
-
985
- const result = parser.parseSession(undefined, filePath);
986
- expect(result?.lastActive.toISOString()).toBe("2026-04-18T00:10:00.000Z");
987
- });
988
- });
989
- });
990
-
991
- describe("getConversation", () => {
992
- it("should return messages from a valid Gemini session file", () => {
993
- const sessionPath = path.join(tmpHome, "session-2026-04-18T00-00-id.json");
994
- fs.writeFileSync(
995
- sessionPath,
996
- JSON.stringify({
997
- sessionId: "abc",
998
- projectHash: "hash",
999
- startTime: "2026-04-18T00:00:00Z",
1000
- lastUpdated: "2026-04-18T00:00:00Z",
1001
- kind: "main",
1002
- messages: [
1003
- { id: "m1", timestamp: "2026-04-18T00:00:01Z", type: "user", content: "hi" },
1004
- { id: "m2", timestamp: "2026-04-18T00:00:02Z", type: "gemini", content: "hello" },
1005
- { id: "m3", timestamp: "2026-04-18T00:00:03Z", type: "tool", content: "unused" },
1006
- ],
1007
- }),
1008
- );
1009
-
1010
- const messages = adapter.getConversation(sessionPath);
1011
- expect(messages).toEqual([
1012
- { role: "user", content: "hi", timestamp: "2026-04-18T00:00:01Z" },
1013
- { role: "assistant", content: "hello", timestamp: "2026-04-18T00:00:02Z" },
1014
- ]);
1015
- });
1016
-
1017
- it("should include tool entries when verbose is true", () => {
1018
- const sessionPath = path.join(tmpHome, "session-verbose.json");
1019
- fs.writeFileSync(
1020
- sessionPath,
1021
- JSON.stringify({
1022
- sessionId: "abc",
1023
- projectHash: "hash",
1024
- startTime: "2026-04-18T00:00:00Z",
1025
- lastUpdated: "2026-04-18T00:00:00Z",
1026
- kind: "main",
1027
- messages: [
1028
- { id: "m1", timestamp: "2026-04-18T00:00:01Z", type: "tool", content: "tool call" },
1029
- ],
1030
- }),
1031
- );
1032
-
1033
- const messages = adapter.getConversation(sessionPath, { verbose: true });
1034
- expect(messages).toEqual([
1035
- { role: "system", content: "tool call", timestamp: "2026-04-18T00:00:01Z" },
1036
- ]);
1037
- });
1038
-
1039
- it("should return empty array for missing or malformed files", () => {
1040
- expect(adapter.getConversation("/nonexistent/file.json")).toEqual([]);
1041
-
1042
- const brokenPath = path.join(tmpHome, "broken.json");
1043
- fs.writeFileSync(brokenPath, "{ not valid json");
1044
- expect(adapter.getConversation(brokenPath)).toEqual([]);
1045
- });
1046
-
1047
- it("should prefer displayContent over content when both are present", () => {
1048
- const sessionPath = path.join(tmpHome, "session-display.json");
1049
- fs.writeFileSync(
1050
- sessionPath,
1051
- JSON.stringify({
1052
- sessionId: "abc",
1053
- messages: [
1054
- {
1055
- id: "m1",
1056
- timestamp: "2026-04-18T00:00:01Z",
1057
- type: "user",
1058
- content: "raw",
1059
- displayContent: "rendered",
1060
- },
1061
- ],
1062
- }),
1063
- );
1064
-
1065
- const messages = adapter.getConversation(sessionPath);
1066
- expect(messages[0].content).toBe("rendered");
1067
- });
1068
-
1069
- it("should skip entries with empty content", () => {
1070
- const sessionPath = path.join(tmpHome, "session-empty.json");
1071
- fs.writeFileSync(
1072
- sessionPath,
1073
- JSON.stringify({
1074
- sessionId: "abc",
1075
- messages: [
1076
- { id: "m1", timestamp: "2026-04-18T00:00:01Z", type: "user", content: "" },
1077
- { id: "m2", timestamp: "2026-04-18T00:00:02Z", type: "user", content: "real" },
1078
- ],
1079
- }),
1080
- );
1081
-
1082
- const messages = adapter.getConversation(sessionPath);
1083
- expect(messages).toHaveLength(1);
1084
- expect(messages[0].content).toBe("real");
1085
- });
1086
-
1087
- it("should skip entries without a type", () => {
1088
- const sessionPath = path.join(tmpHome, "session-no-type.json");
1089
- fs.writeFileSync(
1090
- sessionPath,
1091
- JSON.stringify({
1092
- sessionId: "abc",
1093
- messages: [{ id: "m1", timestamp: "2026-04-18T00:00:01Z", content: "typeless" }],
1094
- }),
1095
- );
1096
-
1097
- expect(adapter.getConversation(sessionPath)).toEqual([]);
1098
- });
1099
-
1100
- it("should resolve user messages whose content is an array of text parts", () => {
1101
- const sessionPath = path.join(tmpHome, "session-user-parts.json");
1102
- fs.writeFileSync(
1103
- sessionPath,
1104
- JSON.stringify({
1105
- sessionId: "abc",
1106
- messages: [
1107
- {
1108
- id: "m1",
1109
- timestamp: "2026-04-18T00:00:01Z",
1110
- type: "user",
1111
- content: [{ text: "hello" }, { text: " world" }],
1112
- },
1113
- {
1114
- id: "m2",
1115
- timestamp: "2026-04-18T00:00:02Z",
1116
- type: "gemini",
1117
- content: "hi there",
1118
- },
1119
- ],
1120
- }),
1121
- );
1122
-
1123
- const messages = adapter.getConversation(sessionPath);
1124
- expect(messages).toEqual([
1125
- { role: "user", content: "hello world", timestamp: "2026-04-18T00:00:01Z" },
1126
- { role: "assistant", content: "hi there", timestamp: "2026-04-18T00:00:02Z" },
1127
- ]);
1128
- });
1129
-
1130
- it("should not throw when content is an array but no part carries text", () => {
1131
- const sessionPath = path.join(tmpHome, "session-no-text-parts.json");
1132
- fs.writeFileSync(
1133
- sessionPath,
1134
- JSON.stringify({
1135
- sessionId: "abc",
1136
- messages: [
1137
- {
1138
- id: "m1",
1139
- timestamp: "2026-04-18T00:00:01Z",
1140
- type: "user",
1141
- content: [{ inlineData: { mimeType: "image/png" } }],
1142
- },
1143
- ],
1144
- }),
1145
- );
1146
-
1147
- expect(() => adapter.getConversation(sessionPath)).not.toThrow();
1148
- expect(adapter.getConversation(sessionPath)).toEqual([]);
1149
- });
1150
-
1151
- it("should return empty array when messages is not an array", () => {
1152
- const sessionPath = path.join(tmpHome, "session-bad-messages.json");
1153
- fs.writeFileSync(sessionPath, JSON.stringify({ sessionId: "abc", messages: "not-an-array" }));
1154
-
1155
- expect(adapter.getConversation(sessionPath)).toEqual([]);
1156
- });
1157
- });
1158
-
1159
- describe("listSessions", () => {
1160
- it("returns empty when ~/.gemini/tmp does not exist", async () => {
1161
- // tmpHome has no .gemini dir by default
1162
- const result = await adapter.listSessions();
1163
- expect(result).toEqual([]);
1164
- });
1165
-
1166
- it("walks every shortId/chats dir and returns sessions", async () => {
1167
- writeSession(tmpHome, "aaa", "session-1", {
1168
- sessionId: "s-1",
1169
- projectHash: hashProjectRoot("/repo-a"),
1170
- startTime: "2025-01-01T00:00:00Z",
1171
- lastUpdated: "2025-01-01T00:01:00Z",
1172
- directories: ["/repo-a"],
1173
- messages: [
1174
- { type: "user", timestamp: "2025-01-01T00:00:00Z", content: [{ text: "hello a" }] },
1175
- ],
1176
- });
1177
- writeSession(tmpHome, "bbb", "session-2", {
1178
- sessionId: "s-2",
1179
- projectHash: hashProjectRoot("/repo-b"),
1180
- startTime: "2025-01-02T00:00:00Z",
1181
- lastUpdated: "2025-01-02T00:01:00Z",
1182
- directories: ["/repo-b"],
1183
- messages: [
1184
- { type: "user", timestamp: "2025-01-02T00:00:00Z", content: [{ text: "hello b" }] },
1185
- ],
1186
- });
1187
-
1188
- const result = await adapter.listSessions();
1189
-
1190
- expect(result).toHaveLength(2);
1191
- const byId = Object.fromEntries(result.map((r) => [r.sessionId, r]));
1192
- expect(byId["s-1"]).toMatchObject({
1193
- type: "gemini_cli",
1194
- cwd: "/repo-a",
1195
- firstUserMessage: "hello a",
1196
- });
1197
- expect(byId["s-2"]).toMatchObject({
1198
- type: "gemini_cli",
1199
- cwd: "/repo-b",
1200
- firstUserMessage: "hello b",
1201
- });
1202
- });
1203
-
1204
- it("finds an exact session ID from Gemini metadata", async () => {
1205
- const wantedPath = writeSession(tmpHome, "aaa", "session-one", {
1206
- sessionId: "wanted",
1207
- projectHash: hashProjectRoot("/repo"),
1208
- startTime: "2025-01-01T00:00:00Z",
1209
- directories: ["/repo"],
1210
- messages: [{ type: "user", content: "wanted prompt" }],
1211
- });
1212
- writeSession(tmpHome, "bbb", "session-two", {
1213
- sessionId: "other",
1214
- projectHash: hashProjectRoot("/other"),
1215
- startTime: "2025-01-01T00:00:00Z",
1216
- directories: ["/other"],
1217
- messages: [{ type: "user", content: "other prompt" }],
1218
- });
1219
-
1220
- await expect(adapter.findSessionsById("wanted")).resolves.toEqual([
1221
- expect.objectContaining({ sessionId: "wanted", sessionFilePath: wantedPath }),
1222
- ]);
1223
- });
1224
-
1225
- it("applies strict-equality cwd filter against directories[0]", async () => {
1226
- writeSession(tmpHome, "aaa", "session-keep", {
1227
- sessionId: "keep",
1228
- projectHash: hashProjectRoot("/repo"),
1229
- startTime: "2025-01-01T00:00:00Z",
1230
- directories: ["/repo"],
1231
- messages: [{ type: "user", timestamp: "2025-01-01T00:00:00Z", content: "yes" }],
1232
- });
1233
- writeSession(tmpHome, "bbb", "session-drop", {
1234
- sessionId: "drop",
1235
- projectHash: hashProjectRoot("/other"),
1236
- startTime: "2025-01-01T00:00:00Z",
1237
- directories: ["/other"],
1238
- messages: [{ type: "user", timestamp: "2025-01-01T00:00:00Z", content: "no" }],
1239
- });
1240
-
1241
- const result = await adapter.listSessions({ cwd: "/repo" });
1242
-
1243
- expect(result).toHaveLength(1);
1244
- expect(result[0].sessionId).toBe("keep");
1245
- });
1246
-
1247
- it("skips malformed JSON files", async () => {
1248
- const chatsDir = path.join(tmpHome, ".gemini", "tmp", "aaa", "chats");
1249
- fs.mkdirSync(chatsDir, { recursive: true });
1250
- fs.writeFileSync(path.join(chatsDir, "session-bad.json"), "{ not json");
1251
- writeSession(tmpHome, "aaa", "session-good", {
1252
- sessionId: "good",
1253
- projectHash: hashProjectRoot("/repo"),
1254
- startTime: "2025-01-01T00:00:00Z",
1255
- directories: ["/repo"],
1256
- messages: [{ type: "user", timestamp: "2025-01-01T00:00:00Z", content: "ok" }],
1257
- });
1258
-
1259
- const result = await adapter.listSessions();
1260
- expect(result).toHaveLength(1);
1261
- expect(result[0].sessionId).toBe("good");
1262
- });
1263
-
1264
- it("skips files missing sessionId", async () => {
1265
- writeSession(tmpHome, "aaa", "session-no-id", {
1266
- projectHash: hashProjectRoot("/repo"),
1267
- startTime: "2025-01-01T00:00:00Z",
1268
- directories: ["/repo"],
1269
- messages: [],
1270
- });
1271
-
1272
- const result = await adapter.listSessions();
1273
- expect(result).toEqual([]);
1274
- });
1275
-
1276
- it("captures the first user-typed message as firstUserMessage", async () => {
1277
- writeSession(tmpHome, "aaa", "session-x", {
1278
- sessionId: "s",
1279
- projectHash: hashProjectRoot("/repo"),
1280
- startTime: "2025-01-01T00:00:00Z",
1281
- directories: ["/repo"],
1282
- messages: [
1283
- { type: "gemini", timestamp: "2025-01-01T00:00:00Z", content: "preamble" },
1284
- { type: "user", timestamp: "2025-01-01T00:00:01Z", content: [{ text: "first user" }] },
1285
- { type: "user", timestamp: "2025-01-01T00:00:02Z", content: "second user" },
1286
- ],
1287
- });
1288
-
1289
- const result = await adapter.listSessions({ cwd: "/repo" });
1290
-
1291
- expect(result).toHaveLength(1);
1292
- expect(result[0].firstUserMessage).toBe("first user");
1293
- });
1294
-
1295
- it("returns empty firstUserMessage when no user message exists", async () => {
1296
- writeSession(tmpHome, "aaa", "session-x", {
1297
- sessionId: "s",
1298
- projectHash: hashProjectRoot("/repo"),
1299
- startTime: "2025-01-01T00:00:00Z",
1300
- directories: ["/repo"],
1301
- messages: [{ type: "gemini", timestamp: "2025-01-01T00:00:00Z", content: "agent only" }],
1302
- });
1303
-
1304
- const result = await adapter.listSessions({ cwd: "/repo" });
1305
-
1306
- expect(result).toHaveLength(1);
1307
- expect(result[0].firstUserMessage).toBe("");
1308
- });
1309
- });
1310
- });
1311
-
1312
- /**
1313
- * Write a Gemini session JSON to the temporary home under the expected
1314
- * ~/.gemini/tmp/<shortId>/chats/<fileName>.json layout. Returns the full path.
1315
- */
1316
- function writeSession(
1317
- home: string,
1318
- shortId: string,
1319
- fileName: string,
1320
- body: Record<string, unknown>,
1321
- ): string {
1322
- const chatsDir = path.join(home, ".gemini", "tmp", shortId, "chats");
1323
- fs.mkdirSync(chatsDir, { recursive: true });
1324
- const filePath = path.join(chatsDir, `${fileName}.json`);
1325
- fs.writeFileSync(filePath, JSON.stringify(body));
1326
- return filePath;
1327
- }
1328
-
1329
- /**
1330
- * Mirror the projectHash algo used by Gemini CLI:
1331
- * sha256(projectRoot) as hex.
1332
- */
1333
- function hashProjectRoot(projectRoot: string): string {
1334
- // eslint-disable-next-line @typescript-eslint/no-require-imports
1335
- return crypto.createHash("sha256").update(projectRoot).digest("hex");
1336
- }