@ai-devkit/agent-manager 0.43.0 → 0.44.1

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