@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,488 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import type {
4
- ConversationMessage,
5
- ConversationOptions,
6
- SessionSummary,
7
- } from "../../adapters/AgentAdapter.js";
8
- import { AgentStatus } from "../../adapters/AgentAdapter.js";
9
- import {
10
- IncrementalJsonlSummary,
11
- reduceJsonlContent,
12
- type JsonlSummaryBounds,
13
- type JsonlSummaryReducer,
14
- } from "../../utils/IncrementalJsonlSummary.js";
15
- import { JsonlTailReader, normalizeTail } from "../../utils/jsonlTail.js";
16
- import { safeReadFile, safeStat } from "../../utils/session.js";
17
- import { isIdle, parseTimestamp, SUMMARY_MAX_LENGTH, truncate } from "../shared.js";
18
-
19
- export interface PiSession {
20
- sessionId: string;
21
- projectPath: string;
22
- summary: string;
23
- sessionStart: Date;
24
- lastActive: Date;
25
- lastRole?: ConversationMessage["role"];
26
- }
27
-
28
- interface PiLine {
29
- timestamp?: string;
30
- role?: string;
31
- type?: string;
32
- content?: unknown;
33
- text?: unknown;
34
- message?: unknown;
35
- sessionId?: string;
36
- session_id?: string;
37
- id?: string;
38
- cwd?: string;
39
- projectPath?: string;
40
- project_path?: string;
41
- payload?: Record<string, unknown>;
42
- data?: Record<string, unknown>;
43
- [key: string]: unknown;
44
- }
45
-
46
- type PiRecord = Record<string, unknown>;
47
-
48
- /**
49
- * Session identity read from the start of a file, without parsing the rest.
50
- * Fields are undefined when not found in the head.
51
- */
52
- export interface PiSessionHead {
53
- sessionId?: string;
54
- projectPath?: string;
55
- /** Bytes read from the file. */
56
- bytesRead: number;
57
- /** True when the whole file fit in the head read. */
58
- complete: boolean;
59
- }
60
-
61
- /**
62
- * O(1) running summary folded from session entries; `toSession` turns it into
63
- * a `PiSession`. Timestamps are epoch ms so cached state stays immutable.
64
- */
65
- interface PiSummaryState {
66
- entryCount: number;
67
- /** A bounded cold start skipped the middle: later lines are not the session's first. */
68
- pastHead?: boolean;
69
- sessionId?: string;
70
- projectPath?: string;
71
- firstTimestampMs?: number;
72
- lastTimestampMs?: number;
73
- firstUserMessage?: string;
74
- lastUserMessage?: string;
75
- lastRole?: ConversationMessage["role"];
76
- }
77
-
78
- /** Upper bound for `readSessionHead`; Pi writes its session header as the first line. */
79
- export const PI_SESSION_HEAD_MAX_BYTES = 64 * 1024;
80
- const HEAD_CHUNK_BYTES = 4 * 1024;
81
-
82
- export interface PiSessionParserOptions {
83
- /** Cold-start scan bounds for `readSessionIncremental` (see IncrementalJsonlSummary). */
84
- summaryBounds?: JsonlSummaryBounds | false;
85
- }
86
-
87
- export class PiSessionParser {
88
- /** Incremental reader backing `getConversation({ tail })`. */
89
- private readonly tailReader = new JsonlTailReader();
90
-
91
- private readonly sessionCache: IncrementalJsonlSummary<PiSummaryState>;
92
-
93
- constructor(options: PiSessionParserOptions = {}) {
94
- this.sessionCache = new IncrementalJsonlSummary(this.summaryReducer, {
95
- bounds: options.summaryBounds,
96
- });
97
- }
98
-
99
- readSession(filePath: string, fallbackCwd = ""): PiSession | null {
100
- const content = safeReadFile(filePath);
101
- if (content === undefined) return null;
102
- return this.toSession(filePath, fallbackCwd, reduceJsonlContent(this.summaryReducer, content));
103
- }
104
-
105
- /**
106
- * Same result as `readSession`, but backed by a per-instance incremental
107
- * cache so repeated refreshes only parse bytes appended since the last call.
108
- * Call `pruneSessionCache()` once per refresh to evict files no longer read.
109
- *
110
- * The first read of a large transcript is a bounded head + tail scan (see
111
- * `summaryReducer.skip`); fields whose entries lie only in the skipped
112
- * middle fall back to their defaults instead of forcing a full parse.
113
- */
114
- readSessionIncremental(filePath: string, fallbackCwd = ""): PiSession | null {
115
- const result = this.sessionCache.read(filePath);
116
- return result ? this.toSession(filePath, fallbackCwd, result.state) : null;
117
- }
118
-
119
- /** Evict cached summaries for files not read since the previous prune. */
120
- pruneSessionCache(): void {
121
- this.sessionCache.prune();
122
- }
123
-
124
- /**
125
- * Read the session id and project path from the first complete lines of a
126
- * file, stopping once both are found or after `maxBytes`. Null if unreadable.
127
- */
128
- readSessionHead(filePath: string, maxBytes = PI_SESSION_HEAD_MAX_BYTES): PiSessionHead | null {
129
- let fd: number;
130
- try {
131
- fd = fs.openSync(filePath, "r");
132
- } catch {
133
- return null;
134
- }
135
-
136
- try {
137
- const head: PiSessionHead = { bytesRead: 0, complete: false };
138
- const buffer = Buffer.alloc(maxBytes);
139
- let lineStart = 0;
140
-
141
- while (head.bytesRead < maxBytes) {
142
- const bytesRead = fs.readSync(
143
- fd,
144
- buffer,
145
- head.bytesRead,
146
- Math.min(HEAD_CHUNK_BYTES, maxBytes - head.bytesRead),
147
- head.bytesRead,
148
- );
149
- if (bytesRead === 0) {
150
- head.complete = true;
151
- break;
152
- }
153
- head.bytesRead += bytesRead;
154
-
155
- let newline = buffer.indexOf(0x0a, lineStart);
156
- while (newline !== -1 && newline < head.bytesRead) {
157
- this.applyHeadLine(head, buffer.toString("utf8", lineStart, newline));
158
- lineStart = newline + 1;
159
- if (head.sessionId && head.projectPath) return head;
160
- newline = buffer.indexOf(0x0a, lineStart);
161
- }
162
- }
163
-
164
- // The unterminated last line is only trusted when it ends the file
165
- if (head.complete && lineStart < head.bytesRead) {
166
- this.applyHeadLine(head, buffer.toString("utf8", lineStart, head.bytesRead));
167
- }
168
- return head;
169
- } catch {
170
- return null;
171
- } finally {
172
- fs.closeSync(fd);
173
- }
174
- }
175
-
176
- determineStatus(session: PiSession): AgentStatus {
177
- if (session.lastRole === "assistant") return AgentStatus.WAITING;
178
- if (isIdle(session.lastActive)) return AgentStatus.IDLE;
179
- return AgentStatus.RUNNING;
180
- }
181
-
182
- getConversation(sessionFilePath: string, options?: ConversationOptions): ConversationMessage[] {
183
- const includeSystem = options?.verbose ?? false;
184
- const tail = normalizeTail(options?.tail);
185
- if (tail !== undefined) {
186
- return this.tailReader.read(
187
- sessionFilePath,
188
- tail,
189
- {
190
- parseLine: (line) => {
191
- const entry = this.parseJsonlLine(line);
192
- return entry ? this.entryToMessage(entry, includeSystem) : null;
193
- },
194
- },
195
- String(includeSystem),
196
- );
197
- }
198
- return this.entriesToMessages(this.readJsonl(sessionFilePath), includeSystem);
199
- }
200
-
201
- fileToSessionSummary(filePath: string): SessionSummary | null {
202
- const content = safeReadFile(filePath);
203
- if (content === undefined) return null;
204
-
205
- const state = reduceJsonlContent(this.summaryReducer, content);
206
- const session = this.toSession(filePath, "", state);
207
- if (!session) return null;
208
- return {
209
- type: "pi",
210
- sessionId: session.sessionId,
211
- cwd: session.projectPath,
212
- firstUserMessage: state.firstUserMessage ?? "",
213
- lastActive: session.lastActive,
214
- startedAt: session.sessionStart,
215
- sessionFilePath: filePath,
216
- };
217
- }
218
-
219
- sessionIdFromFile(filePath: string): string {
220
- const base = path.basename(filePath, ".jsonl");
221
- const underscore = base.lastIndexOf("_");
222
- return underscore >= 0 ? base.slice(underscore + 1) : base;
223
- }
224
-
225
- /**
226
- * Fold one JSONL entry into the O(1) session summary. Mirrors the previous
227
- * whole-file scan: id, cwd and start come from the first entry that has
228
- * them; last active, last user message and last role track the latest one.
229
- *
230
- * `skip` (bounded cold start) keeps the head's first-* fields (id, cwd,
231
- * start, first user message) and clears the latest ones, so those come from
232
- * the tail only. Tail entries never fill a first-* field: Pi message entries
233
- * carry their own `id`, which must not become the session id. A first-*
234
- * value beyond the head falls back like a missing one (filename id,
235
- * `fallbackCwd`, file birthtime, no first user message); a latest value
236
- * before the tail window stays unset (file mtime for last active).
237
- */
238
- private readonly summaryReducer: JsonlSummaryReducer<PiSummaryState> = {
239
- initial: () => ({ entryCount: 0 }),
240
- reduce: (state, value) => {
241
- const entry = this.asRecord(value) as PiLine | null;
242
- if (!entry) return state;
243
-
244
- const next: PiSummaryState = { ...state, entryCount: state.entryCount + 1 };
245
- const inHead = !state.pastHead;
246
- if (inHead) {
247
- next.sessionId ??= this.entrySessionId(entry);
248
- next.projectPath ??= this.entryCwd(entry);
249
- }
250
-
251
- const timestamp = parseTimestamp(this.entryTimestamp(entry));
252
- if (timestamp) {
253
- if (inHead) next.firstTimestampMs ??= timestamp.getTime();
254
- next.lastTimestampMs = timestamp.getTime();
255
- }
256
-
257
- const message = this.entryToMessage(entry, true);
258
- if (message) {
259
- next.lastRole = message.role;
260
- if (message.role === "user") {
261
- next.lastUserMessage = message.content;
262
- if (inHead) next.firstUserMessage ??= message.content;
263
- }
264
- }
265
- return next;
266
- },
267
- skip: (state) => ({
268
- entryCount: state.entryCount,
269
- pastHead: true,
270
- sessionId: state.sessionId,
271
- projectPath: state.projectPath,
272
- firstTimestampMs: state.firstTimestampMs,
273
- firstUserMessage: state.firstUserMessage,
274
- }),
275
- };
276
-
277
- private toSession(
278
- filePath: string,
279
- fallbackCwd: string,
280
- state: PiSummaryState,
281
- ): PiSession | null {
282
- if (state.entryCount === 0) return null;
283
-
284
- const needsStat = state.firstTimestampMs === undefined || state.lastTimestampMs === undefined;
285
- const stat = needsStat ? safeStat(filePath) : undefined;
286
- const sessionStart =
287
- state.firstTimestampMs !== undefined
288
- ? new Date(state.firstTimestampMs)
289
- : (stat?.birthtime ?? stat?.mtime ?? new Date());
290
- const lastActive =
291
- state.lastTimestampMs !== undefined
292
- ? new Date(state.lastTimestampMs)
293
- : (stat?.mtime ?? sessionStart);
294
-
295
- return {
296
- sessionId: state.sessionId || this.sessionIdFromFile(filePath),
297
- projectPath: state.projectPath || fallbackCwd,
298
- summary: state.lastUserMessage
299
- ? truncate(state.lastUserMessage, SUMMARY_MAX_LENGTH)
300
- : "Pi session active",
301
- sessionStart,
302
- lastActive,
303
- lastRole: state.lastRole,
304
- };
305
- }
306
-
307
- private applyHeadLine(head: PiSessionHead, line: string): void {
308
- const trimmed = line.trim();
309
- if (!trimmed) return;
310
- let entry: PiLine | null;
311
- try {
312
- entry = this.asRecord(JSON.parse(trimmed)) as PiLine | null;
313
- } catch {
314
- return;
315
- }
316
- if (!entry) return;
317
- head.sessionId ??= this.entrySessionId(entry);
318
- head.projectPath ??= this.entryCwd(entry);
319
- }
320
-
321
- private readJsonl(filePath: string): PiLine[] {
322
- const content = safeReadFile(filePath);
323
- if (content === undefined) return [];
324
-
325
- const entries: PiLine[] = [];
326
- for (const line of content.split(/\r?\n/)) {
327
- const entry = this.parseJsonlLine(line);
328
- if (entry) entries.push(entry);
329
- }
330
- return entries;
331
- }
332
-
333
- private parseJsonlLine(line: string): PiLine | null {
334
- const trimmed = line.trim();
335
- if (!trimmed) return null;
336
- try {
337
- const parsed = JSON.parse(trimmed);
338
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
339
- return parsed as PiLine;
340
- }
341
- } catch {
342
- return null;
343
- }
344
- return null;
345
- }
346
-
347
- private entriesToMessages(entries: PiLine[], includeSystem: boolean): ConversationMessage[] {
348
- return entries
349
- .map((entry) => this.entryToMessage(entry, includeSystem))
350
- .filter((msg): msg is ConversationMessage => msg !== null);
351
- }
352
-
353
- private entryToMessage(entry: PiLine, includeSystem: boolean): ConversationMessage | null {
354
- const role = this.entryRole(entry);
355
- if (!role) return null;
356
- if (role === "system" && !includeSystem) return null;
357
-
358
- const content = this.entryContent(entry).trim();
359
- if (!content) return null;
360
-
361
- return {
362
- role,
363
- content,
364
- timestamp: this.entryTimestamp(entry),
365
- };
366
- }
367
-
368
- private entryRole(entry: PiLine): ConversationMessage["role"] | null {
369
- const message = this.messageRecord(entry);
370
- const raw = this.firstString(
371
- entry.role,
372
- message?.role,
373
- this.roleLikeType(entry.type),
374
- entry.payload?.role,
375
- entry.payload?.type,
376
- entry.data?.role,
377
- entry.data?.type,
378
- );
379
- if (!raw) return null;
380
- const normalized = raw.toLowerCase();
381
- if (normalized === "user" || normalized === "human") return "user";
382
- if (normalized === "assistant" || normalized === "ai" || normalized === "pi")
383
- return "assistant";
384
- if (normalized === "system") return "system";
385
- return null;
386
- }
387
-
388
- private entryContent(entry: PiLine): string {
389
- const message = this.messageRecord(entry);
390
- const candidates = [
391
- entry.content,
392
- entry.text,
393
- message?.content,
394
- message?.text,
395
- message?.message,
396
- entry.message,
397
- entry.payload?.content,
398
- entry.payload?.text,
399
- entry.payload?.message,
400
- entry.data?.content,
401
- entry.data?.text,
402
- entry.data?.message,
403
- ];
404
-
405
- for (const candidate of candidates) {
406
- const text = this.contentToString(candidate);
407
- if (text) return text;
408
- }
409
- return "";
410
- }
411
-
412
- private contentToString(value: unknown): string {
413
- if (typeof value === "string") return value;
414
- if (Array.isArray(value)) {
415
- return value
416
- .map((item) => this.contentToString(item))
417
- .filter(Boolean)
418
- .join("");
419
- }
420
- if (!value || typeof value !== "object") return "";
421
-
422
- const record = value as Record<string, unknown>;
423
- return this.contentToString(record.content ?? record.text ?? record.value);
424
- }
425
-
426
- private messageRecord(entry: PiLine): PiRecord | null {
427
- return this.asRecord(entry.message);
428
- }
429
-
430
- private asRecord(value: unknown): PiRecord | null {
431
- if (!value || typeof value !== "object" || Array.isArray(value)) return null;
432
- return value as PiRecord;
433
- }
434
-
435
- private roleLikeType(value: unknown): string | undefined {
436
- if (typeof value !== "string") return undefined;
437
- const normalized = value.toLowerCase();
438
- if (["user", "human", "assistant", "ai", "pi", "system"].includes(normalized)) {
439
- return value;
440
- }
441
- return undefined;
442
- }
443
-
444
- private entryTimestamp(entry: PiLine): string | undefined {
445
- return this.firstString(
446
- entry.timestamp,
447
- entry.payload?.timestamp,
448
- entry.data?.timestamp,
449
- entry.createdAt,
450
- entry.created_at,
451
- );
452
- }
453
-
454
- private entrySessionId(entry: PiLine): string | undefined {
455
- return this.firstString(
456
- entry.sessionId,
457
- entry.session_id,
458
- entry.id,
459
- entry.payload?.sessionId,
460
- entry.payload?.session_id,
461
- entry.payload?.id,
462
- entry.data?.sessionId,
463
- entry.data?.session_id,
464
- entry.data?.id,
465
- );
466
- }
467
-
468
- private entryCwd(entry: PiLine): string | undefined {
469
- return this.firstString(
470
- entry.cwd,
471
- entry.projectPath,
472
- entry.project_path,
473
- entry.payload?.cwd,
474
- entry.payload?.projectPath,
475
- entry.payload?.project_path,
476
- entry.data?.cwd,
477
- entry.data?.projectPath,
478
- entry.data?.project_path,
479
- );
480
- }
481
-
482
- private firstString(...values: unknown[]): string | undefined {
483
- for (const value of values) {
484
- if (typeof value === "string" && value) return value;
485
- }
486
- return undefined;
487
- }
488
- }
@@ -1,87 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import type { ProcessInfo } from "../../adapters/AgentAdapter.js";
4
- import { safeReadFile } from "../../utils/session.js";
5
- import { homeDir } from "../shared.js";
6
-
7
- export interface PiTrackerMatch {
8
- process: ProcessInfo;
9
- filePath: string;
10
- }
11
-
12
- export interface PiTrackerMatchResult {
13
- matches: PiTrackerMatch[];
14
- fallback: ProcessInfo[];
15
- }
16
-
17
- export interface PiSessionTrackerOptions {
18
- sessionsDir?: string;
19
- trackerPath?: string;
20
- }
21
-
22
- export class PiSessionTracker {
23
- private readonly sessionsDir: string;
24
- private readonly trackerPath: string;
25
-
26
- constructor(options: PiSessionTrackerOptions = {}) {
27
- const agentDir = path.join(homeDir(), ".pi", "agent");
28
- this.sessionsDir = options.sessionsDir ?? path.join(agentDir, "sessions");
29
- this.trackerPath = options.trackerPath ?? path.join(agentDir, "sessions.json");
30
- }
31
-
32
- match(processes: ProcessInfo[]): PiTrackerMatchResult {
33
- const tracker = this.readTracker();
34
- if (tracker.size === 0) return { matches: [], fallback: processes };
35
-
36
- const matches: PiTrackerMatch[] = [];
37
- const fallback: ProcessInfo[] = [];
38
-
39
- for (const processInfo of processes) {
40
- const filePath = tracker.get(processInfo.pid);
41
- if (!filePath || !this.isTrustedSessionPath(filePath) || !fs.existsSync(filePath)) {
42
- fallback.push(processInfo);
43
- continue;
44
- }
45
-
46
- matches.push({ process: processInfo, filePath });
47
- }
48
-
49
- return { matches, fallback };
50
- }
51
-
52
- private readTracker(): Map<number, string> {
53
- const content = safeReadFile(this.trackerPath);
54
- if (content === undefined) return new Map();
55
-
56
- let parsed: unknown;
57
- try {
58
- parsed = JSON.parse(content);
59
- } catch {
60
- return new Map();
61
- }
62
-
63
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return new Map();
64
-
65
- const map = new Map<number, string>();
66
- for (const [key, value] of Object.entries(parsed)) {
67
- const keyPid = this.toPid(key);
68
- if (keyPid !== null && typeof value === "string" && value) {
69
- map.set(keyPid, value);
70
- }
71
- }
72
- return map;
73
- }
74
-
75
- private toPid(value: unknown): number | null {
76
- if (typeof value === "number" && Number.isInteger(value) && value > 0) return value;
77
- if (typeof value !== "string" || !/^\d+$/.test(value)) return null;
78
- const parsed = Number(value);
79
- return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
80
- }
81
-
82
- private isTrustedSessionPath(filePath: string): boolean {
83
- const resolvedRoot = path.resolve(this.sessionsDir);
84
- const resolvedPath = path.resolve(filePath);
85
- return resolvedPath === resolvedRoot || resolvedPath.startsWith(`${resolvedRoot}${path.sep}`);
86
- }
87
- }
@@ -1,129 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- type UnknownRecord = Record<string, unknown>;
6
-
7
- export type PiCredentialOptions = {
8
- env?: NodeJS.ProcessEnv;
9
- readFile?: (path: string, encoding: BufferEncoding) => Promise<string>;
10
- };
11
-
12
- export type PiAnthropicCredential = {
13
- kind: "oauth";
14
- access: string;
15
- expiresMs: number | null;
16
- };
17
-
18
- export type PiOpenAiCredential =
19
- | { kind: "platform"; key: string }
20
- | { kind: "oauth"; access: string; accountId: string; expiresMs: number | null };
21
-
22
- const OPENAI_CREDENTIALS_MISSING =
23
- "OpenAI credentials not found; set OPENAI_API_KEY, configure the Pi openai provider, or log in to OpenAI via Pi";
24
- const ZAI_CREDENTIAL_MISSING =
25
- "z.ai API key not found; set Z_AI_API_KEY or configure Pi provider zai";
26
-
27
- function record(value: unknown): UnknownRecord | null {
28
- return value !== null && typeof value === "object" && !Array.isArray(value)
29
- ? (value as UnknownRecord)
30
- : null;
31
- }
32
-
33
- function nonEmptyText(value: unknown): string | null {
34
- return typeof value === "string" && value.trim() ? value.trim() : null;
35
- }
36
-
37
- function epochMilliseconds(value: unknown): number | null {
38
- if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return null;
39
- return value > 1e12 ? value : value * 1000;
40
- }
41
-
42
- async function readPiAuthRoot(options: PiCredentialOptions): Promise<UnknownRecord> {
43
- const env = options.env ?? process.env;
44
- const authPath = join(env.HOME || homedir(), ".pi", "agent", "auth.json");
45
- const contents = await (options.readFile ?? readFile)(authPath, "utf8");
46
- const parsed = record(JSON.parse(contents));
47
- if (!parsed) throw new Error("Pi auth file is malformed");
48
- return parsed;
49
- }
50
-
51
- export async function resolvePiAnthropicCredential(
52
- options: PiCredentialOptions = {},
53
- ): Promise<PiAnthropicCredential> {
54
- let root: UnknownRecord;
55
- try {
56
- root = await readPiAuthRoot(options);
57
- } catch (error) {
58
- if (record(error)?.code === "ENOENT") {
59
- throw new Error("Pi Anthropic OAuth credentials not found");
60
- }
61
- throw new Error("Pi Anthropic auth file is malformed");
62
- }
63
-
64
- const credential = record(root.anthropic);
65
- if (!credential) throw new Error("Pi Anthropic OAuth credentials not found");
66
- const access = credential.type === "oauth" ? nonEmptyText(credential.access) : null;
67
- if (!access) throw new Error("Pi Anthropic OAuth credential is malformed");
68
- return {
69
- kind: "oauth",
70
- access,
71
- expiresMs: epochMilliseconds(credential.expires),
72
- };
73
- }
74
-
75
- export async function resolvePiOpenAiCredential(
76
- options: PiCredentialOptions = {},
77
- ): Promise<PiOpenAiCredential> {
78
- const env = options.env ?? process.env;
79
- const environmentKey = nonEmptyText(env.OPENAI_API_KEY);
80
- if (environmentKey) return { kind: "platform", key: environmentKey };
81
-
82
- let root: UnknownRecord;
83
- try {
84
- root = await readPiAuthRoot(options);
85
- } catch (error) {
86
- if (record(error)?.code === "ENOENT") throw new Error(OPENAI_CREDENTIALS_MISSING);
87
- throw new Error("OpenAI Pi auth file is malformed");
88
- }
89
-
90
- const platform = record(root.openai);
91
- if (platform) {
92
- const key = platform.type === "api_key" ? nonEmptyText(platform.key) : null;
93
- if (!key) throw new Error("OpenAI Pi auth file has a malformed openai credential");
94
- return { kind: "platform", key };
95
- }
96
-
97
- const oauth = record(root["openai-codex"]);
98
- const access = oauth?.type === "oauth" ? nonEmptyText(oauth.access) : null;
99
- const accountId = nonEmptyText(oauth?.accountId);
100
- if (oauth && access && accountId) {
101
- return {
102
- kind: "oauth",
103
- access,
104
- accountId,
105
- expiresMs: epochMilliseconds(oauth.expires),
106
- };
107
- }
108
- throw new Error(OPENAI_CREDENTIALS_MISSING);
109
- }
110
-
111
- export async function resolvePiZaiApiKey(options: PiCredentialOptions = {}): Promise<string> {
112
- const env = options.env ?? process.env;
113
- const environmentKey = nonEmptyText(env.Z_AI_API_KEY);
114
- if (environmentKey) return environmentKey;
115
-
116
- let root: UnknownRecord;
117
- try {
118
- root = await readPiAuthRoot(options);
119
- } catch (error) {
120
- if (record(error)?.code === "ENOENT") throw new Error(ZAI_CREDENTIAL_MISSING);
121
- throw new Error("z.ai Pi auth file is malformed");
122
- }
123
-
124
- const credential = record(root.zai);
125
- if (!credential) throw new Error(ZAI_CREDENTIAL_MISSING);
126
- const key = credential.type === "api_key" ? nonEmptyText(credential.key) : null;
127
- if (!key) throw new Error("z.ai Pi auth file has a malformed zai credential");
128
- return key;
129
- }