@ai-devkit/agent-manager 0.42.3 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (451) hide show
  1. package/dist/AgentManager.d.ts +14 -5
  2. package/dist/AgentManager.d.ts.map +1 -1
  3. package/dist/AgentManager.js +32 -13
  4. package/dist/AgentManager.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/package.json +9 -4
  9. package/.swcrc +0 -27
  10. package/dist/__tests__/AgentManager.test.js +0 -1596
  11. package/dist/__tests__/AgentManager.test.js.map +0 -1
  12. package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js +0 -486
  13. package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js.map +0 -1
  14. package/dist/__tests__/adapters/adapterProcessImports.test.js +0 -52
  15. package/dist/__tests__/adapters/adapterProcessImports.test.js.map +0 -1
  16. package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js +0 -247
  17. package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js.map +0 -1
  18. package/dist/__tests__/capacity/anthropic.test.js +0 -115
  19. package/dist/__tests__/capacity/anthropic.test.js.map +0 -1
  20. package/dist/__tests__/capacity/boundaries.test.js +0 -45
  21. package/dist/__tests__/capacity/boundaries.test.js.map +0 -1
  22. package/dist/__tests__/capacity/claude.test.js +0 -485
  23. package/dist/__tests__/capacity/claude.test.js.map +0 -1
  24. package/dist/__tests__/capacity/codex.test.js +0 -339
  25. package/dist/__tests__/capacity/codex.test.js.map +0 -1
  26. package/dist/__tests__/capacity/devin.test.js +0 -239
  27. package/dist/__tests__/capacity/devin.test.js.map +0 -1
  28. package/dist/__tests__/capacity/index.test.js +0 -53
  29. package/dist/__tests__/capacity/index.test.js.map +0 -1
  30. package/dist/__tests__/capacity/openai.test.js +0 -687
  31. package/dist/__tests__/capacity/openai.test.js.map +0 -1
  32. package/dist/__tests__/capacity/wham.test.js +0 -159
  33. package/dist/__tests__/capacity/wham.test.js.map +0 -1
  34. package/dist/__tests__/capacity/zai.test.js +0 -212
  35. package/dist/__tests__/capacity/zai.test.js.map +0 -1
  36. package/dist/__tests__/fixtures.test.js +0 -218
  37. package/dist/__tests__/fixtures.test.js.map +0 -1
  38. package/dist/__tests__/harnesses/BoundedSummarySkip.test.js +0 -568
  39. package/dist/__tests__/harnesses/BoundedSummarySkip.test.js.map +0 -1
  40. package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js +0 -1089
  41. package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js.map +0 -1
  42. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js +0 -143
  43. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js.map +0 -1
  44. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js +0 -462
  45. package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js.map +0 -1
  46. package/dist/__tests__/harnesses/builtinAdapters.test.js +0 -33
  47. package/dist/__tests__/harnesses/builtinAdapters.test.js.map +0 -1
  48. package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js +0 -79
  49. package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js.map +0 -1
  50. package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js +0 -1881
  51. package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js.map +0 -1
  52. package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js +0 -425
  53. package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js.map +0 -1
  54. package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js +0 -314
  55. package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js.map +0 -1
  56. package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js +0 -49
  57. package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js.map +0 -1
  58. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js +0 -76
  59. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js.map +0 -1
  60. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js +0 -173
  61. package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js.map +0 -1
  62. package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js +0 -181
  63. package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js.map +0 -1
  64. package/dist/__tests__/harnesses/codex/CodexAdapter.test.js +0 -685
  65. package/dist/__tests__/harnesses/codex/CodexAdapter.test.js.map +0 -1
  66. package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js +0 -463
  67. package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js.map +0 -1
  68. package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js +0 -86
  69. package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js.map +0 -1
  70. package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js +0 -254
  71. package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js.map +0 -1
  72. package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js +0 -121
  73. package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js.map +0 -1
  74. package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js +0 -84
  75. package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js.map +0 -1
  76. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js +0 -128
  77. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js.map +0 -1
  78. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js +0 -246
  79. package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js.map +0 -1
  80. package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js +0 -384
  81. package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js.map +0 -1
  82. package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js +0 -659
  83. package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js.map +0 -1
  84. package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js +0 -290
  85. package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js.map +0 -1
  86. package/dist/__tests__/harnesses/devin/DevinAdapter.test.js +0 -597
  87. package/dist/__tests__/harnesses/devin/DevinAdapter.test.js.map +0 -1
  88. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +0 -99
  89. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +0 -1
  90. package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js +0 -192
  91. package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js.map +0 -1
  92. package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js +0 -407
  93. package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js.map +0 -1
  94. package/dist/__tests__/harnesses/devin/fixtures.js +0 -95
  95. package/dist/__tests__/harnesses/devin/fixtures.js.map +0 -1
  96. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js +0 -1454
  97. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js.map +0 -1
  98. package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js +0 -491
  99. package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js.map +0 -1
  100. package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js +0 -399
  101. package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js.map +0 -1
  102. package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js +0 -56
  103. package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js.map +0 -1
  104. package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js +0 -421
  105. package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js.map +0 -1
  106. package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js +0 -167
  107. package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js.map +0 -1
  108. package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js +0 -133
  109. package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js.map +0 -1
  110. package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js +0 -301
  111. package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js.map +0 -1
  112. package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js +0 -662
  113. package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js.map +0 -1
  114. package/dist/__tests__/harnesses/muse/MuseAdapter.test.js +0 -247
  115. package/dist/__tests__/harnesses/muse/MuseAdapter.test.js.map +0 -1
  116. package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js +0 -81
  117. package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js.map +0 -1
  118. package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js +0 -185
  119. package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js.map +0 -1
  120. package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js +0 -328
  121. package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js.map +0 -1
  122. package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js +0 -213
  123. package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js.map +0 -1
  124. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js +0 -108
  125. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js.map +0 -1
  126. package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js +0 -94
  127. package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js.map +0 -1
  128. package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js +0 -147
  129. package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js.map +0 -1
  130. package/dist/__tests__/harnesses/pi/PiAdapter.test.js +0 -367
  131. package/dist/__tests__/harnesses/pi/PiAdapter.test.js.map +0 -1
  132. package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js +0 -382
  133. package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js.map +0 -1
  134. package/dist/__tests__/harnesses/pi/PiSessionParser.test.js +0 -416
  135. package/dist/__tests__/harnesses/pi/PiSessionParser.test.js.map +0 -1
  136. package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js +0 -108
  137. package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js.map +0 -1
  138. package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js +0 -70
  139. package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js.map +0 -1
  140. package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js +0 -43
  141. package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js.map +0 -1
  142. package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js +0 -192
  143. package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js.map +0 -1
  144. package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js +0 -119
  145. package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js.map +0 -1
  146. package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js +0 -382
  147. package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js.map +0 -1
  148. package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js +0 -34
  149. package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js.map +0 -1
  150. package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js +0 -446
  151. package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js.map +0 -1
  152. package/dist/__tests__/harnesses/runtimeProfiles.test.js +0 -101
  153. package/dist/__tests__/harnesses/runtimeProfiles.test.js.map +0 -1
  154. package/dist/__tests__/print/DurableAgent.test.js +0 -15
  155. package/dist/__tests__/print/DurableAgent.test.js.map +0 -1
  156. package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js +0 -186
  157. package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js.map +0 -1
  158. package/dist/__tests__/print/DurableAgentRepository.test.js +0 -249
  159. package/dist/__tests__/print/DurableAgentRepository.test.js.map +0 -1
  160. package/dist/__tests__/readiness-fixtures.test.js +0 -54
  161. package/dist/__tests__/readiness-fixtures.test.js.map +0 -1
  162. package/dist/__tests__/runtime/AgentRuntime.test.js +0 -13
  163. package/dist/__tests__/runtime/AgentRuntime.test.js.map +0 -1
  164. package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js +0 -164
  165. package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js.map +0 -1
  166. package/dist/__tests__/runtime/HerdrAgentRuntime.test.js +0 -488
  167. package/dist/__tests__/runtime/HerdrAgentRuntime.test.js.map +0 -1
  168. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js +0 -637
  169. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js.map +0 -1
  170. package/dist/__tests__/terminal/GhosttyBackend.test.js +0 -334
  171. package/dist/__tests__/terminal/GhosttyBackend.test.js.map +0 -1
  172. package/dist/__tests__/terminal/TerminalFocusManager.test.js +0 -253
  173. package/dist/__tests__/terminal/TerminalFocusManager.test.js.map +0 -1
  174. package/dist/__tests__/terminal/TmuxManager.test.js +0 -168
  175. package/dist/__tests__/terminal/TmuxManager.test.js.map +0 -1
  176. package/dist/__tests__/terminal/TtyWriter.test.js +0 -386
  177. package/dist/__tests__/terminal/TtyWriter.test.js.map +0 -1
  178. package/dist/__tests__/utils/AgentRegistry.test.js +0 -636
  179. package/dist/__tests__/utils/AgentRegistry.test.js.map +0 -1
  180. package/dist/__tests__/utils/IncrementalJsonlSummary.test.js +0 -650
  181. package/dist/__tests__/utils/IncrementalJsonlSummary.test.js.map +0 -1
  182. package/dist/__tests__/utils/agent-requests.test.js +0 -90
  183. package/dist/__tests__/utils/agent-requests.test.js.map +0 -1
  184. package/dist/__tests__/utils/conversationTail.bench.test.js +0 -258
  185. package/dist/__tests__/utils/conversationTail.bench.test.js.map +0 -1
  186. package/dist/__tests__/utils/conversationTailParity.test.js +0 -588
  187. package/dist/__tests__/utils/conversationTailParity.test.js.map +0 -1
  188. package/dist/__tests__/utils/jsonlTail.test.js +0 -360
  189. package/dist/__tests__/utils/jsonlTail.test.js.map +0 -1
  190. package/dist/__tests__/utils/matching.test.js +0 -324
  191. package/dist/__tests__/utils/matching.test.js.map +0 -1
  192. package/dist/__tests__/utils/matchingConstants.test.js +0 -35
  193. package/dist/__tests__/utils/matchingConstants.test.js.map +0 -1
  194. package/dist/__tests__/utils/process.test.js +0 -818
  195. package/dist/__tests__/utils/process.test.js.map +0 -1
  196. package/dist/__tests__/utils/session.test.js +0 -175
  197. package/dist/__tests__/utils/session.test.js.map +0 -1
  198. package/project.json +0 -29
  199. package/scripts/benchmark-cold-start.mjs +0 -350
  200. package/src/AgentManager.ts +0 -530
  201. package/src/__tests__/AgentManager.test.ts +0 -1483
  202. package/src/__tests__/adapters/IncrementalSessionRefresh.test.ts +0 -437
  203. package/src/__tests__/adapters/adapterProcessImports.test.ts +0 -58
  204. package/src/__tests__/adapters/adapterSnapshotCandidates.test.ts +0 -243
  205. package/src/__tests__/capacity/anthropic.test.ts +0 -105
  206. package/src/__tests__/capacity/boundaries.test.ts +0 -36
  207. package/src/__tests__/capacity/claude.test.ts +0 -462
  208. package/src/__tests__/capacity/codex.test.ts +0 -311
  209. package/src/__tests__/capacity/devin.test.ts +0 -210
  210. package/src/__tests__/capacity/fixtures/claude-credentials.json +0 -7
  211. package/src/__tests__/capacity/fixtures/claude-usage-malformed.json +0 -1
  212. package/src/__tests__/capacity/fixtures/claude-usage-partial.json +0 -15
  213. package/src/__tests__/capacity/fixtures/claude-usage.json +0 -63
  214. package/src/__tests__/capacity/fixtures/devin-config.json +0 -6
  215. package/src/__tests__/capacity/fixtures/devin-credentials.toml +0 -4
  216. package/src/__tests__/capacity/fixtures/devin-quota-nonplan.json +0 -5
  217. package/src/__tests__/capacity/fixtures/devin-quota.json +0 -10
  218. package/src/__tests__/capacity/fixtures/openai-auth.json +0 -6
  219. package/src/__tests__/capacity/fixtures/openai-codex-auth.json +0 -9
  220. package/src/__tests__/capacity/fixtures/openai-usage-completions.json +0 -67
  221. package/src/__tests__/capacity/fixtures/openai-usage-responses.json +0 -20
  222. package/src/__tests__/capacity/fixtures/wham-usage.json +0 -45
  223. package/src/__tests__/capacity/fixtures/zai-auth.json +0 -6
  224. package/src/__tests__/capacity/fixtures/zai-quota-invalid.json +0 -7
  225. package/src/__tests__/capacity/fixtures/zai-quota.json +0 -38
  226. package/src/__tests__/capacity/index.test.ts +0 -54
  227. package/src/__tests__/capacity/openai.test.ts +0 -571
  228. package/src/__tests__/capacity/wham.test.ts +0 -122
  229. package/src/__tests__/capacity/zai.test.ts +0 -151
  230. package/src/__tests__/fixtures.test.ts +0 -245
  231. package/src/__tests__/harnesses/BoundedSummarySkip.test.ts +0 -496
  232. package/src/__tests__/harnesses/SessionSummaryEquivalence.test.ts +0 -726
  233. package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.ts +0 -133
  234. package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.ts +0 -396
  235. package/src/__tests__/harnesses/builtinAdapters.test.ts +0 -33
  236. package/src/__tests__/harnesses/claude/ClaudeAgentMapper.test.ts +0 -84
  237. package/src/__tests__/harnesses/claude/ClaudeCodeAdapter.test.ts +0 -1793
  238. package/src/__tests__/harnesses/claude/ClaudeSessionLocator.test.ts +0 -423
  239. package/src/__tests__/harnesses/claude/ClaudeSessionParser.test.ts +0 -300
  240. package/src/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.ts +0 -34
  241. package/src/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.ts +0 -61
  242. package/src/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.ts +0 -129
  243. package/src/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.ts +0 -152
  244. package/src/__tests__/harnesses/codex/CodexAdapter.test.ts +0 -652
  245. package/src/__tests__/harnesses/codex/CodexSessionLocator.test.ts +0 -419
  246. package/src/__tests__/harnesses/codex/CodexSessionMapping.test.ts +0 -63
  247. package/src/__tests__/harnesses/codex/CodexSessionParser.test.ts +0 -192
  248. package/src/__tests__/harnesses/codex/durable/CodexCliProbe.test.ts +0 -80
  249. package/src/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.ts +0 -65
  250. package/src/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.ts +0 -104
  251. package/src/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.ts +0 -201
  252. package/src/__tests__/harnesses/codex/durable/CodexPrintRunner.test.ts +0 -299
  253. package/src/__tests__/harnesses/copilot/CopilotAdapter.test.ts +0 -614
  254. package/src/__tests__/harnesses/copilot/CopilotRefreshIO.test.ts +0 -270
  255. package/src/__tests__/harnesses/devin/DevinAdapter.test.ts +0 -290
  256. package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +0 -101
  257. package/src/__tests__/harnesses/devin/DevinSessionLocator.test.ts +0 -139
  258. package/src/__tests__/harnesses/devin/DevinSessionParser.test.ts +0 -212
  259. package/src/__tests__/harnesses/devin/fixtures.ts +0 -144
  260. package/src/__tests__/harnesses/gemini/GeminiCliAdapter.test.ts +0 -1336
  261. package/src/__tests__/harnesses/gemini/GeminiSessionJsonl.test.ts +0 -402
  262. package/src/__tests__/harnesses/gemini/GeminiSessionLocator.test.ts +0 -396
  263. package/src/__tests__/harnesses/grok/GrokAgentMapper.test.ts +0 -57
  264. package/src/__tests__/harnesses/grok/GrokCliAdapter.test.ts +0 -376
  265. package/src/__tests__/harnesses/grok/GrokIncrementalRefresh.test.ts +0 -170
  266. package/src/__tests__/harnesses/grok/GrokSessionLocator.test.ts +0 -106
  267. package/src/__tests__/harnesses/grok/GrokSessionParser.test.ts +0 -230
  268. package/src/__tests__/harnesses/kiro/KiroAdapter.test.ts +0 -552
  269. package/src/__tests__/harnesses/muse/MuseAdapter.test.ts +0 -197
  270. package/src/__tests__/harnesses/muse/MuseAgentMapper.test.ts +0 -83
  271. package/src/__tests__/harnesses/muse/MuseSessionLocator.test.ts +0 -177
  272. package/src/__tests__/harnesses/muse/MuseSessionParser.test.ts +0 -279
  273. package/src/__tests__/harnesses/opencode/OpenCodeAdapter.test.ts +0 -215
  274. package/src/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.ts +0 -101
  275. package/src/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.ts +0 -84
  276. package/src/__tests__/harnesses/opencode/OpenCodeSessionParser.test.ts +0 -149
  277. package/src/__tests__/harnesses/pi/PiAdapter.test.ts +0 -325
  278. package/src/__tests__/harnesses/pi/PiDiscoveryIO.test.ts +0 -337
  279. package/src/__tests__/harnesses/pi/PiSessionParser.test.ts +0 -280
  280. package/src/__tests__/harnesses/pi/PiSessionTracker.test.ts +0 -79
  281. package/src/__tests__/harnesses/pi/durable/PiCliProbe.test.ts +0 -50
  282. package/src/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.ts +0 -33
  283. package/src/__tests__/harnesses/pi/durable/PiPrintAgentService.test.ts +0 -138
  284. package/src/__tests__/harnesses/pi/durable/PiPrintProtocol.test.ts +0 -71
  285. package/src/__tests__/harnesses/pi/durable/PiPrintRunner.test.ts +0 -252
  286. package/src/__tests__/harnesses/pi/durable/PiStreamParser.test.ts +0 -26
  287. package/src/__tests__/harnesses/readiness/AgentReadiness.test.ts +0 -362
  288. package/src/__tests__/harnesses/runtimeProfiles.test.ts +0 -123
  289. package/src/__tests__/print/DurableAgent.test.ts +0 -15
  290. package/src/__tests__/print/DurableAgentRepository.sqlite.test.ts +0 -128
  291. package/src/__tests__/print/DurableAgentRepository.test.ts +0 -184
  292. package/src/__tests__/readiness-fixtures.test.ts +0 -79
  293. package/src/__tests__/runtime/AgentRuntime.test.ts +0 -8
  294. package/src/__tests__/runtime/HerdrAgentDiscovery.test.ts +0 -131
  295. package/src/__tests__/runtime/HerdrAgentRuntime.test.ts +0 -377
  296. package/src/__tests__/runtime/ManagedAgentRuntime.test.ts +0 -590
  297. package/src/__tests__/terminal/GhosttyBackend.test.ts +0 -271
  298. package/src/__tests__/terminal/TerminalFocusManager.test.ts +0 -280
  299. package/src/__tests__/terminal/TmuxManager.test.ts +0 -185
  300. package/src/__tests__/terminal/TtyWriter.test.ts +0 -454
  301. package/src/__tests__/utils/AgentRegistry.test.ts +0 -532
  302. package/src/__tests__/utils/IncrementalJsonlSummary.test.ts +0 -414
  303. package/src/__tests__/utils/agent-requests.test.ts +0 -94
  304. package/src/__tests__/utils/conversationTail.bench.test.ts +0 -193
  305. package/src/__tests__/utils/conversationTailParity.test.ts +0 -365
  306. package/src/__tests__/utils/jsonlTail.test.ts +0 -317
  307. package/src/__tests__/utils/matching.test.ts +0 -234
  308. package/src/__tests__/utils/matchingConstants.test.ts +0 -40
  309. package/src/__tests__/utils/process.test.ts +0 -596
  310. package/src/__tests__/utils/session.test.ts +0 -158
  311. package/src/adapters/AgentAdapter.ts +0 -255
  312. package/src/capacity/index.ts +0 -127
  313. package/src/capacity/providers/anthropic.ts +0 -198
  314. package/src/capacity/providers/devin.ts +0 -121
  315. package/src/capacity/providers/openai-platform.ts +0 -150
  316. package/src/capacity/providers/openai-subscription.ts +0 -184
  317. package/src/capacity/providers/zai.ts +0 -155
  318. package/src/capacity/sources/claude.ts +0 -30
  319. package/src/capacity/sources/codex.ts +0 -251
  320. package/src/capacity/sources/devin.ts +0 -49
  321. package/src/capacity/sources/pi.ts +0 -131
  322. package/src/capacity/types.ts +0 -29
  323. package/src/database/connection.ts +0 -96
  324. package/src/database/index.ts +0 -7
  325. package/src/database/migrations/001_initial.sql +0 -12
  326. package/src/database/migrations/002_pins.sql +0 -1
  327. package/src/database/migrations/003_durable_agents.sql +0 -43
  328. package/src/database/migrations/004_codex_durable_sessions.sql +0 -1
  329. package/src/database/migrations/005_agent_runtime.sql +0 -2
  330. package/src/database/schema.ts +0 -64
  331. package/src/durable/DurableAgent.ts +0 -139
  332. package/src/durable/DurableAgentRepository.ts +0 -485
  333. package/src/durable/process.ts +0 -29
  334. package/src/durable/run.ts +0 -84
  335. package/src/durable/utils.ts +0 -66
  336. package/src/fixtures/bundle.ts +0 -130
  337. package/src/fixtures/capture.ts +0 -364
  338. package/src/harnesses/antigravity/AntigravityAgentMapper.ts +0 -34
  339. package/src/harnesses/antigravity/AntigravityCliAdapter.ts +0 -126
  340. package/src/harnesses/antigravity/AntigravitySessionLocator.ts +0 -75
  341. package/src/harnesses/antigravity/AntigravitySessionParser.ts +0 -252
  342. package/src/harnesses/claude/ClaudeAgentMapper.ts +0 -55
  343. package/src/harnesses/claude/ClaudeCodeAdapter.ts +0 -175
  344. package/src/harnesses/claude/ClaudeSessionLocator.ts +0 -358
  345. package/src/harnesses/claude/ClaudeSessionParser.ts +0 -524
  346. package/src/harnesses/claude/credentials.ts +0 -122
  347. package/src/harnesses/claude/durable/ClaudeCliProbe.ts +0 -57
  348. package/src/harnesses/claude/durable/ClaudePrintAgentService.ts +0 -79
  349. package/src/harnesses/claude/durable/ClaudePrintRunner.ts +0 -102
  350. package/src/harnesses/claude/durable/ClaudeStreamParser.ts +0 -108
  351. package/src/harnesses/claude/readiness.ts +0 -69
  352. package/src/harnesses/codex/CodexAdapter.ts +0 -337
  353. package/src/harnesses/codex/CodexAgentMapper.ts +0 -26
  354. package/src/harnesses/codex/CodexSessionLocator.ts +0 -509
  355. package/src/harnesses/codex/CodexSessionMapping.ts +0 -89
  356. package/src/harnesses/codex/CodexSessionParser.ts +0 -462
  357. package/src/harnesses/codex/credentials.ts +0 -81
  358. package/src/harnesses/codex/durable/CodexCliProbe.ts +0 -68
  359. package/src/harnesses/codex/durable/CodexPrintAgentService.ts +0 -79
  360. package/src/harnesses/codex/durable/CodexPrintRunner.ts +0 -104
  361. package/src/harnesses/codex/durable/CodexStreamParser.ts +0 -117
  362. package/src/harnesses/codex/readiness.ts +0 -72
  363. package/src/harnesses/copilot/CopilotAdapter.ts +0 -161
  364. package/src/harnesses/copilot/CopilotAgentMapper.ts +0 -27
  365. package/src/harnesses/copilot/CopilotSessionLocator.ts +0 -161
  366. package/src/harnesses/copilot/CopilotSessionParser.ts +0 -380
  367. package/src/harnesses/copilot/readiness.ts +0 -33
  368. package/src/harnesses/devin/DevinAdapter.ts +0 -212
  369. package/src/harnesses/devin/DevinAgentMapper.ts +0 -39
  370. package/src/harnesses/devin/DevinSessionLocator.ts +0 -230
  371. package/src/harnesses/devin/DevinSessionParser.ts +0 -227
  372. package/src/harnesses/devin/credentials.ts +0 -88
  373. package/src/harnesses/devin/readiness.ts +0 -36
  374. package/src/harnesses/gemini/GeminiAgentMapper.ts +0 -27
  375. package/src/harnesses/gemini/GeminiCliAdapter.ts +0 -272
  376. package/src/harnesses/gemini/GeminiSessionLocator.ts +0 -394
  377. package/src/harnesses/gemini/GeminiSessionParser.ts +0 -395
  378. package/src/harnesses/gemini/fileSignature.ts +0 -10
  379. package/src/harnesses/grok/GrokAgentMapper.ts +0 -32
  380. package/src/harnesses/grok/GrokCliAdapter.ts +0 -126
  381. package/src/harnesses/grok/GrokSessionLocator.ts +0 -179
  382. package/src/harnesses/grok/GrokSessionParser.ts +0 -251
  383. package/src/harnesses/index.ts +0 -32
  384. package/src/harnesses/kiro/KiroAdapter.ts +0 -143
  385. package/src/harnesses/kiro/KiroAgentMapper.ts +0 -34
  386. package/src/harnesses/kiro/KiroSessionLocator.ts +0 -143
  387. package/src/harnesses/kiro/KiroSessionParser.ts +0 -376
  388. package/src/harnesses/muse/MuseAdapter.ts +0 -157
  389. package/src/harnesses/muse/MuseAgentMapper.ts +0 -33
  390. package/src/harnesses/muse/MuseSessionLocator.ts +0 -286
  391. package/src/harnesses/muse/MuseSessionParser.ts +0 -435
  392. package/src/harnesses/muse/readiness.ts +0 -38
  393. package/src/harnesses/opencode/OpenCodeAdapter.ts +0 -110
  394. package/src/harnesses/opencode/OpenCodeAgentMapper.ts +0 -49
  395. package/src/harnesses/opencode/OpenCodeSessionLocator.ts +0 -151
  396. package/src/harnesses/opencode/OpenCodeSessionParser.ts +0 -146
  397. package/src/harnesses/opencode/readiness.ts +0 -48
  398. package/src/harnesses/pi/PiAdapter.ts +0 -197
  399. package/src/harnesses/pi/PiAgentMapper.ts +0 -27
  400. package/src/harnesses/pi/PiSessionLocator.ts +0 -288
  401. package/src/harnesses/pi/PiSessionParser.ts +0 -488
  402. package/src/harnesses/pi/PiSessionTracker.ts +0 -87
  403. package/src/harnesses/pi/credentials.ts +0 -129
  404. package/src/harnesses/pi/durable/PiCliProbe.ts +0 -56
  405. package/src/harnesses/pi/durable/PiPrintAgentService.ts +0 -77
  406. package/src/harnesses/pi/durable/PiPrintProtocol.ts +0 -41
  407. package/src/harnesses/pi/durable/PiPrintRunner.ts +0 -95
  408. package/src/harnesses/pi/durable/PiStreamParser.ts +0 -94
  409. package/src/harnesses/pi/readiness.ts +0 -104
  410. package/src/harnesses/readiness/AgentReadiness.ts +0 -91
  411. package/src/harnesses/readiness/checks.ts +0 -336
  412. package/src/harnesses/readiness/types.ts +0 -90
  413. package/src/harnesses/runtimeProfiles.ts +0 -105
  414. package/src/harnesses/shared.ts +0 -124
  415. package/src/index.ts +0 -70
  416. package/src/runtime/ManagedAgentRuntime.ts +0 -253
  417. package/src/runtime/RuntimeFactory.ts +0 -13
  418. package/src/runtime/errors.ts +0 -50
  419. package/src/runtime/herdr/HerdrAgentDiscovery.ts +0 -166
  420. package/src/runtime/herdr/HerdrAgentRuntime.ts +0 -216
  421. package/src/runtime/herdr/HerdrCliClient.ts +0 -78
  422. package/src/runtime/herdr/HerdrErrors.ts +0 -9
  423. package/src/runtime/herdr/HerdrResponseParsers.ts +0 -86
  424. package/src/runtime/herdr/HerdrRuntimeRef.ts +0 -41
  425. package/src/runtime/tmux/PidPolling.ts +0 -34
  426. package/src/runtime/tmux/TmuxAgentRuntime.ts +0 -113
  427. package/src/runtime/tmux/TmuxManager.ts +0 -102
  428. package/src/runtime/tmux/TmuxRuntimeRef.ts +0 -9
  429. package/src/runtime/types.ts +0 -56
  430. package/src/terminal/TerminalFocusManager.ts +0 -52
  431. package/src/terminal/TtyWriter.ts +0 -26
  432. package/src/terminal/backends/ghostty.ts +0 -180
  433. package/src/terminal/backends/index.ts +0 -23
  434. package/src/terminal/backends/iterm2.ts +0 -126
  435. package/src/terminal/backends/shared.ts +0 -47
  436. package/src/terminal/backends/terminal-app.ts +0 -122
  437. package/src/terminal/backends/tmux.ts +0 -62
  438. package/src/terminal/backends/wezterm.ts +0 -65
  439. package/src/terminal/types.ts +0 -23
  440. package/src/utils/AgentRegistry.ts +0 -351
  441. package/src/utils/IncrementalJsonlSummary.ts +0 -306
  442. package/src/utils/agent-requests.ts +0 -28
  443. package/src/utils/applescript.ts +0 -10
  444. package/src/utils/jsonlTail.ts +0 -349
  445. package/src/utils/matching.ts +0 -96
  446. package/src/utils/matchingConstants.ts +0 -15
  447. package/src/utils/process.ts +0 -604
  448. package/src/utils/session.ts +0 -144
  449. package/src/utils/sortAgents.ts +0 -54
  450. package/tsconfig.json +0 -11
  451. package/vitest.config.ts +0 -20
@@ -1,155 +0,0 @@
1
- import type {
2
- Availability,
3
- CapacityLimitType,
4
- CapacityWindow,
5
- ProviderCapacitySnapshot,
6
- } from "../types.js";
7
-
8
- const ZAI_QUOTA_URL = "https://api.z.ai/api/monitor/usage/quota/limit";
9
- const LIMIT_METADATA = {
10
- TOKENS_LIMIT: { id: "tokens", label: "Tokens" },
11
- CREDIT_LIMIT: { id: "credit", label: "Credit" },
12
- TIME_LIMIT: { id: "time", label: "Time" },
13
- } as const satisfies Record<CapacityLimitType, { id: string; label: string }>;
14
- const UNIT_METADATA = new Map<number, { minutes: number; label: string }>([
15
- [1, { minutes: 24 * 60, label: "day" }],
16
- [3, { minutes: 60, label: "hour" }],
17
- [5, { minutes: 1, label: "minute" }],
18
- [6, { minutes: 7 * 24 * 60, label: "week" }],
19
- ]);
20
- type UnknownRecord = Record<string, unknown>;
21
-
22
- export type ZaiRequestOptions = {
23
- fetch?: typeof globalThis.fetch;
24
- timeoutMs?: number;
25
- };
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 optionalNumber(value: unknown, field: string): number | null {
34
- if (value === undefined || value === null) return null;
35
- if (typeof value !== "number" || !Number.isFinite(value)) {
36
- throw new Error(`Invalid z.ai quota ${field}`);
37
- }
38
- return value;
39
- }
40
-
41
- function integer(value: unknown): number | null {
42
- return typeof value === "number" && Number.isInteger(value) ? value : null;
43
- }
44
-
45
- function isCapacityLimitType(value: string): value is CapacityLimitType {
46
- return Object.hasOwn(LIMIT_METADATA, value);
47
- }
48
-
49
- function durationMinutes(unit: number, count: number, type: CapacityLimitType): number | null {
50
- if (type === "TIME_LIMIT" && unit === 5 && count === 1) return 30 * 24 * 60;
51
- const metadata = UNIT_METADATA.get(unit);
52
- return metadata === undefined || count <= 0 ? null : metadata.minutes * count;
53
- }
54
-
55
- function windowLabel(type: CapacityLimitType, unit: number, count: number): string {
56
- if (type === "TIME_LIMIT" && unit === 5 && count === 1) return "MCP · monthly";
57
- const kind = LIMIT_METADATA[type].label;
58
- const unitLabel = UNIT_METADATA.get(unit)?.label;
59
- if (!unitLabel) return kind;
60
- return `${kind} · ${count} ${unitLabel}${count === 1 ? "" : "s"}`;
61
- }
62
-
63
- function resetTime(value: unknown): string | null {
64
- const milliseconds = optionalNumber(value, "limit nextResetTime");
65
- if (milliseconds === null) return null;
66
- const date = new Date(milliseconds);
67
- if (Number.isNaN(date.getTime())) throw new Error("Invalid z.ai quota limit nextResetTime");
68
- return date.toISOString();
69
- }
70
-
71
- function availability(windows: CapacityWindow[]): Availability {
72
- if (windows.length === 0) return "unknown";
73
- return windows.some((window) => window.usedPercent !== null && window.usedPercent < 100)
74
- ? "yes"
75
- : "no";
76
- }
77
-
78
- function parseLimit(value: unknown, index: number): CapacityWindow | null {
79
- const limit = record(value);
80
- if (!limit) throw new Error("Invalid z.ai quota limit entry");
81
- const unit = integer(limit.unit);
82
- const count = integer(limit.number);
83
- if (typeof limit.type !== "string" || unit === null || count === null) {
84
- throw new Error("Invalid z.ai quota limit entry");
85
- }
86
- const serverPercent = optionalNumber(limit.percentage, "limit percentage");
87
- if (serverPercent === null) throw new Error("Invalid z.ai quota limit percentage");
88
- if (!isCapacityLimitType(limit.type)) return null;
89
-
90
- const total = optionalNumber(limit.usage, "limit usage");
91
- const current = optionalNumber(limit.currentValue, "limit currentValue");
92
- const remaining = optionalNumber(limit.remaining, "limit remaining");
93
- let consumed = total !== null && remaining !== null ? total - remaining : null;
94
- if (current !== null) consumed = Math.max(consumed ?? current, current);
95
- let usedPercent = serverPercent;
96
- if (total !== null && total > 0 && consumed !== null) {
97
- usedPercent = (consumed / total) * 100;
98
- }
99
- const metadata = LIMIT_METADATA[limit.type];
100
- return {
101
- id: `zai:${metadata.id}:${index + 1}`,
102
- label: windowLabel(limit.type, unit, count),
103
- limitType: limit.type,
104
- durationMinutes: durationMinutes(unit, count, limit.type),
105
- usedPercent: Math.max(0, Math.min(100, usedPercent)),
106
- resetsAt: resetTime(limit.nextResetTime),
107
- total,
108
- current,
109
- remaining,
110
- };
111
- }
112
-
113
- export function parseZaiCapacity(raw: unknown): ProviderCapacitySnapshot {
114
- const root = record(raw);
115
- const data = record(root?.data);
116
- if (root?.success !== true || root.code !== 200 || !data || !Array.isArray(data.limits)) {
117
- throw new Error("Invalid z.ai quota response");
118
- }
119
- const windows = data.limits
120
- .map(parseLimit)
121
- .filter((window): window is CapacityWindow => window !== null);
122
- return {
123
- authenticated: true,
124
- available: availability(windows),
125
- windows,
126
- creditsRemaining: null,
127
- };
128
- }
129
-
130
- export async function fetchZaiCapacity(
131
- key: string,
132
- options: ZaiRequestOptions = {},
133
- ): Promise<ProviderCapacitySnapshot> {
134
- let response: Response;
135
- try {
136
- response = await (options.fetch ?? globalThis.fetch)(ZAI_QUOTA_URL, {
137
- method: "GET",
138
- headers: { Authorization: `Bearer ${key}` },
139
- signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
140
- });
141
- } catch {
142
- throw new Error("z.ai quota request failed");
143
- }
144
- if (response.status !== 200) {
145
- throw new Error(`z.ai quota request failed: HTTP ${response.status}`);
146
- }
147
- try {
148
- return parseZaiCapacity(await response.json());
149
- } catch (error) {
150
- if (error instanceof SyntaxError) {
151
- throw new Error("z.ai quota response is not valid JSON");
152
- }
153
- throw error;
154
- }
155
- }
@@ -1,30 +0,0 @@
1
- import {
2
- fetchAnthropicCapacity,
3
- type AnthropicCapacityRequestOptions,
4
- } from "../providers/anthropic.js";
5
- import type { CapacityReport, ProviderCapacitySnapshot } from "../types.js";
6
- import {
7
- resolveClaudeAnthropicToken,
8
- type ClaudeCredentialOptions,
9
- } from "../../harnesses/claude/credentials.js";
10
-
11
- export type ClaudeCapacityOptions = ClaudeCredentialOptions & AnthropicCapacityRequestOptions;
12
-
13
- export type ClaudeProbeOptions = ClaudeCapacityOptions & {
14
- checkedAt: string;
15
- };
16
-
17
- function claudeReport(snapshot: ProviderCapacitySnapshot, checkedAt: string): CapacityReport {
18
- return {
19
- harness: "claude",
20
- provider: "anthropic",
21
- generatedAt: checkedAt,
22
- ...snapshot,
23
- };
24
- }
25
-
26
- export async function probeClaudeCapacity(options: ClaudeProbeOptions): Promise<CapacityReport> {
27
- const token = await resolveClaudeAnthropicToken(options);
28
- const snapshot = await fetchAnthropicCapacity(token, options);
29
- return claudeReport(snapshot, options.checkedAt);
30
- }
@@ -1,251 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import {
3
- fetchOpenAiPatAccountId,
4
- fetchOpenAiSubscriptionCapacity,
5
- resetTime,
6
- safeIdentifier,
7
- } from "../providers/openai-subscription.js";
8
- import type { CapacityReport, CapacityWindow } from "../types.js";
9
- import {
10
- resolveCodexCredentials,
11
- type CodexCredentialOptions,
12
- } from "../../harnesses/codex/credentials.js";
13
-
14
- type UsageSnapshot = {
15
- windows: CapacityWindow[];
16
- creditsRemaining: number | null;
17
- available: CapacityReport["available"] | null;
18
- };
19
-
20
- type UnknownRecord = Record<string, unknown>;
21
- type RpcMessage = { id?: number; method: string; params?: UnknownRecord };
22
- type CliResponses = { rateLimits: unknown; account: unknown };
23
- type CodexRpc = (messages: RpcMessage[]) => Promise<CliResponses>;
24
-
25
- export type CodexProbeOptions = CodexCredentialOptions & {
26
- installed: boolean;
27
- checkedAt: string;
28
- fetch?: typeof globalThis.fetch;
29
- rpc?: CodexRpc;
30
- timeoutMs?: number;
31
- };
32
-
33
- export const CODEX_APP_SERVER_ARGS = ["-s", "read-only", "-a", "untrusted", "app-server"] as const;
34
-
35
- function record(value: unknown): UnknownRecord | null {
36
- return value !== null && typeof value === "object" && !Array.isArray(value)
37
- ? (value as UnknownRecord)
38
- : null;
39
- }
40
-
41
- function finiteNumber(value: unknown): number | null {
42
- return typeof value === "number" && Number.isFinite(value) ? value : null;
43
- }
44
-
45
- function nonEmptyText(value: unknown): string | null {
46
- return typeof value === "string" && value.length > 0 ? value : null;
47
- }
48
-
49
- function cliWindow(value: unknown, id: string, label: string): CapacityWindow | null {
50
- const input = record(value);
51
- if (!input) return null;
52
- return {
53
- id,
54
- label,
55
- durationMinutes: finiteNumber(input.windowDurationMins),
56
- usedPercent: finiteNumber(input.usedPercent),
57
- resetsAt: resetTime(input.resetsAt),
58
- };
59
- }
60
-
61
- function cliSnapshotWindows(value: unknown, fallbackId: string): CapacityWindow[] {
62
- const snapshot = record(value);
63
- if (!snapshot) return [];
64
- const scope = safeIdentifier(snapshot.limitId) ?? safeIdentifier(fallbackId) ?? "codex";
65
- return [
66
- cliWindow(snapshot.primary, `${scope}:primary`, `${scope} primary`),
67
- cliWindow(snapshot.secondary, `${scope}:secondary`, `${scope} secondary`),
68
- ].filter((item): item is CapacityWindow => item !== null);
69
- }
70
-
71
- function parseCliUsage(raw: unknown): UsageSnapshot {
72
- const response = record(raw) ?? {};
73
- const primary = record(response.rateLimits);
74
- const windows = primary ? cliSnapshotWindows(primary, "codex") : [];
75
- const buckets = record(response.rateLimitsByLimitId);
76
- if (buckets) {
77
- for (const [id, snapshot] of Object.entries(buckets)) {
78
- windows.push(...cliSnapshotWindows(snapshot, id));
79
- }
80
- }
81
- const unique = [...new Map(windows.map((window) => [window.id, window])).values()];
82
- return { windows: unique, creditsRemaining: null, available: null };
83
- }
84
-
85
- function capacityFromSnapshot(
86
- snapshot: UsageSnapshot,
87
- options: CodexProbeOptions,
88
- raw?: unknown,
89
- ): CapacityReport {
90
- const hasUsage = snapshot.windows.some((window) => window.usedPercent !== null);
91
- const rateLimits = record(record(raw)?.rateLimits);
92
- const reached = nonEmptyText(rateLimits?.rateLimitReachedType);
93
- const resetCredits =
94
- record(record(raw)?.rateLimitResetCredits) ?? record(record(raw)?.usageLimitResetCredits);
95
- let available = snapshot.available;
96
- if (reached) available = "no";
97
- else if (available === null) available = hasUsage ? "yes" : "unknown";
98
- return {
99
- harness: "codex",
100
- provider: "openai",
101
- generatedAt: options.checkedAt,
102
- authenticated: true,
103
- available,
104
- windows: snapshot.windows,
105
- creditsRemaining: snapshot.creditsRemaining ?? finiteNumber(resetCredits?.availableCount),
106
- };
107
- }
108
-
109
- function appServerRpc(messages: RpcMessage[], timeoutMs = 5000): Promise<CliResponses> {
110
- return new Promise((resolve, reject) => {
111
- const child = spawn("codex", CODEX_APP_SERVER_ARGS, { stdio: ["pipe", "pipe", "ignore"] });
112
- const results: Partial<CliResponses> = {};
113
- let buffer = "";
114
- let settled = false;
115
- const finish = (error?: Error) => {
116
- if (settled) return;
117
- settled = true;
118
- clearTimeout(timer);
119
- child.kill();
120
- if (error) reject(error);
121
- else resolve(results as CliResponses);
122
- };
123
- const timer = setTimeout(() => finish(new Error("codex probe timed out")), timeoutMs);
124
- child.once("error", () => finish(new Error("codex app-server unavailable")));
125
- child.once("exit", () => {
126
- if (!settled) finish(new Error("codex app-server exited"));
127
- });
128
- child.stdout.setEncoding("utf8");
129
- child.stdout.on("data", (chunk: string) => {
130
- buffer += chunk;
131
- for (;;) {
132
- const newline = buffer.indexOf("\n");
133
- if (newline < 0) break;
134
- const line = buffer.slice(0, newline).trim();
135
- buffer = buffer.slice(newline + 1);
136
- if (!line) continue;
137
- let message: UnknownRecord;
138
- try {
139
- message = JSON.parse(line) as UnknownRecord;
140
- } catch {
141
- continue;
142
- }
143
- if (message.id === 1) {
144
- for (const request of messages.slice(1))
145
- child.stdin.write(`${JSON.stringify(request)}\n`);
146
- } else if (message.id === 2) {
147
- if (message.error) finish(new Error("codex rate-limit method failed"));
148
- else results.rateLimits = message.result;
149
- } else if (message.id === 3) {
150
- if (message.error) finish(new Error("codex account method failed"));
151
- else results.account = message.result;
152
- }
153
- if ("rateLimits" in results && "account" in results) finish();
154
- }
155
- });
156
- child.stdin.write(`${JSON.stringify(messages[0])}\n`);
157
- });
158
- }
159
-
160
- export function codexUnavailableReport(checkedAt: string): CapacityReport {
161
- return {
162
- harness: "codex",
163
- provider: "openai",
164
- generatedAt: checkedAt,
165
- authenticated: null,
166
- available: "unknown",
167
- windows: [],
168
- creditsRemaining: null,
169
- };
170
- }
171
-
172
- async function cliFallback(options: CodexProbeOptions): Promise<CapacityReport> {
173
- if (!options.installed) return codexUnavailableReport(options.checkedAt);
174
- const messages: RpcMessage[] = [
175
- {
176
- id: 1,
177
- method: "initialize",
178
- params: {
179
- clientInfo: { name: "ai-devkit", title: null, version: "1" },
180
- capabilities: null,
181
- },
182
- },
183
- { method: "initialized" },
184
- { id: 2, method: "account/rateLimits/read" },
185
- { id: 3, method: "account/read" },
186
- ];
187
- try {
188
- const rpc = options.rpc ?? ((requests) => appServerRpc(requests, options.timeoutMs));
189
- const response = await rpc(messages);
190
- const result = capacityFromSnapshot(
191
- parseCliUsage(response.rateLimits),
192
- options,
193
- response.rateLimits,
194
- );
195
- const accountEnvelope = record(response.account);
196
- if (
197
- accountEnvelope &&
198
- Object.hasOwn(accountEnvelope, "account") &&
199
- !record(accountEnvelope.account)
200
- ) {
201
- result.authenticated = false;
202
- result.available = "unknown";
203
- }
204
- return result;
205
- } catch {
206
- return codexUnavailableReport(options.checkedAt);
207
- }
208
- }
209
-
210
- async function subscriptionSnapshot(
211
- access: string,
212
- accountId: string,
213
- options: CodexProbeOptions,
214
- ): Promise<UsageSnapshot> {
215
- const snapshot = await fetchOpenAiSubscriptionCapacity({ access, accountId }, options);
216
- if (snapshot.authenticated === false) throw new Error("unauthorized");
217
- return snapshot;
218
- }
219
-
220
- export async function probeCodexCapacity(options: CodexProbeOptions): Promise<CapacityReport> {
221
- const credentials = await resolveCodexCredentials(options);
222
- if (!credentials) return cliFallback(options);
223
-
224
- if (credentials.personalAccessToken) {
225
- try {
226
- const accountId = await fetchOpenAiPatAccountId(credentials.personalAccessToken, options);
227
- const snapshot = await subscriptionSnapshot(
228
- credentials.personalAccessToken,
229
- accountId,
230
- options,
231
- );
232
- return capacityFromSnapshot(snapshot, options);
233
- } catch {
234
- // Continue to a separately available OAuth credential before using the CLI.
235
- }
236
- }
237
-
238
- if (credentials.oauth) {
239
- try {
240
- const snapshot = await subscriptionSnapshot(
241
- credentials.oauth.access,
242
- credentials.oauth.accountId,
243
- options,
244
- );
245
- return capacityFromSnapshot(snapshot, options);
246
- } catch {
247
- return cliFallback(options);
248
- }
249
- }
250
- return cliFallback(options);
251
- }
@@ -1,49 +0,0 @@
1
- import { DevinHttpError, fetchDevinCapacity } from "../providers/devin.js";
2
- import type { CapacityReport } from "../types.js";
3
- import {
4
- resolveDevinCredential,
5
- type DevinCredentialOptions,
6
- } from "../../harnesses/devin/credentials.js";
7
-
8
- export type DevinCapacityOptions = DevinCredentialOptions & {
9
- now?: () => Date;
10
- fetch?: typeof globalThis.fetch;
11
- timeoutMs?: number;
12
- };
13
-
14
- export type DevinProbeOptions = DevinCapacityOptions & {
15
- checkedAt: string;
16
- };
17
-
18
- function devinReport(
19
- snapshot: Omit<CapacityReport, "harness" | "provider" | "generatedAt">,
20
- checkedAt: string,
21
- ): CapacityReport {
22
- return {
23
- harness: "devin",
24
- provider: "devin",
25
- generatedAt: checkedAt,
26
- ...snapshot,
27
- };
28
- }
29
-
30
- export async function probeDevinCapacity(options: DevinProbeOptions): Promise<CapacityReport> {
31
- const credential = await resolveDevinCredential(options);
32
- try {
33
- const snapshot = await fetchDevinCapacity(credential, options);
34
- return devinReport(snapshot, options.checkedAt);
35
- } catch (error) {
36
- if (error instanceof DevinHttpError && (error.status === 401 || error.status === 403)) {
37
- return devinReport(
38
- {
39
- authenticated: false,
40
- available: "unknown",
41
- windows: [],
42
- creditsRemaining: null,
43
- },
44
- options.checkedAt,
45
- );
46
- }
47
- throw error;
48
- }
49
- }
@@ -1,131 +0,0 @@
1
- import { fetchAnthropicCapacity } from "../providers/anthropic.js";
2
- import { fetchOpenAiPlatformCapacity } from "../providers/openai-platform.js";
3
- import { fetchOpenAiSubscriptionCapacity } from "../providers/openai-subscription.js";
4
- import { fetchZaiCapacity } from "../providers/zai.js";
5
- import type { CapacityReport, ProviderCapacitySnapshot } from "../types.js";
6
- import {
7
- resolvePiAnthropicCredential,
8
- resolvePiOpenAiCredential,
9
- resolvePiZaiApiKey,
10
- type PiCredentialOptions,
11
- type PiOpenAiCredential,
12
- } from "../../harnesses/pi/credentials.js";
13
-
14
- export type PiAnthropicCapacityOptions = PiCredentialOptions & {
15
- now?: () => Date;
16
- fetch?: typeof globalThis.fetch;
17
- timeoutMs?: number;
18
- };
19
-
20
- export type PiAnthropicProbeOptions = PiAnthropicCapacityOptions & {
21
- checkedAt: string;
22
- };
23
-
24
- export type PiOpenAiCapacityOptions = PiCredentialOptions & {
25
- now?: () => Date;
26
- fetch?: typeof globalThis.fetch;
27
- timeoutMs?: number;
28
- };
29
-
30
- export type PiOpenAiProbeOptions = PiOpenAiCapacityOptions & {
31
- checkedAt: string;
32
- };
33
-
34
- export type PiZaiCapacityOptions = PiCredentialOptions & {
35
- now?: () => Date;
36
- fetch?: typeof globalThis.fetch;
37
- timeoutMs?: number;
38
- };
39
-
40
- export type PiZaiProbeOptions = PiZaiCapacityOptions & {
41
- checkedAt: string;
42
- };
43
-
44
- export async function probePiAnthropicCapacity(
45
- options: PiAnthropicProbeOptions,
46
- ): Promise<CapacityReport> {
47
- const credential = await resolvePiAnthropicCredential(options);
48
- const now = options.now?.() ?? new Date();
49
- if (credential.expiresMs !== null && credential.expiresMs <= now.getTime()) {
50
- return {
51
- harness: "pi",
52
- provider: "anthropic",
53
- generatedAt: options.checkedAt,
54
- authenticated: true,
55
- available: "unknown",
56
- windows: [],
57
- creditsRemaining: null,
58
- };
59
- }
60
- const snapshot = await fetchAnthropicCapacity(credential.access, options);
61
- return {
62
- harness: "pi",
63
- provider: "anthropic",
64
- generatedAt: options.checkedAt,
65
- ...snapshot,
66
- };
67
- }
68
-
69
- function piOpenAiReport(snapshot: ProviderCapacitySnapshot, checkedAt: string): CapacityReport {
70
- return {
71
- harness: "pi",
72
- provider: "openai",
73
- generatedAt: checkedAt,
74
- ...snapshot,
75
- };
76
- }
77
-
78
- function jwtExpiryMs(token: string): number | null {
79
- const part = token.split(".")[1];
80
- if (!part) return null;
81
- try {
82
- const payload = JSON.parse(Buffer.from(part, "base64url").toString("utf8")) as unknown;
83
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) return null;
84
- const exp = (payload as Record<string, unknown>).exp;
85
- return typeof exp === "number" && Number.isFinite(exp) ? exp * 1000 : null;
86
- } catch {
87
- return null;
88
- }
89
- }
90
-
91
- function oauthExpired(
92
- credential: Extract<PiOpenAiCredential, { kind: "oauth" }>,
93
- nowMs: number,
94
- ): boolean {
95
- const expiryMs = credential.expiresMs ?? jwtExpiryMs(credential.access);
96
- return expiryMs !== null && expiryMs <= nowMs;
97
- }
98
-
99
- export async function probeOpenAiCapacity(options: PiOpenAiProbeOptions): Promise<CapacityReport> {
100
- const credential = await resolvePiOpenAiCredential(options);
101
- if (credential.kind === "platform") {
102
- const snapshot = await fetchOpenAiPlatformCapacity(credential.key, options);
103
- return piOpenAiReport(snapshot, options.checkedAt);
104
- }
105
-
106
- const nowMs = Date.parse(options.checkedAt);
107
- if (Number.isNaN(nowMs) || oauthExpired(credential, nowMs)) {
108
- return piOpenAiReport(
109
- {
110
- authenticated: true,
111
- available: "unknown",
112
- windows: [],
113
- creditsRemaining: null,
114
- },
115
- options.checkedAt,
116
- );
117
- }
118
- const snapshot = await fetchOpenAiSubscriptionCapacity(credential, options);
119
- return piOpenAiReport(snapshot, options.checkedAt);
120
- }
121
-
122
- export async function probeZaiCapacity(options: PiZaiProbeOptions): Promise<CapacityReport> {
123
- const key = await resolvePiZaiApiKey(options);
124
- const snapshot = await fetchZaiCapacity(key, options);
125
- return {
126
- harness: "pi",
127
- provider: "zai",
128
- generatedAt: options.checkedAt,
129
- ...snapshot,
130
- };
131
- }
@@ -1,29 +0,0 @@
1
- export type Availability = "yes" | "no" | "unknown";
2
- export type CapacityLimitType = "TOKENS_LIMIT" | "CREDIT_LIMIT" | "TIME_LIMIT";
3
-
4
- export interface CapacityWindow {
5
- id: string;
6
- label: string;
7
- durationMinutes: number | null;
8
- usedPercent: number | null;
9
- resetsAt: string | null;
10
- limitType?: CapacityLimitType;
11
- total?: number | null;
12
- current?: number | null;
13
- remaining?: number | null;
14
- }
15
-
16
- export interface CapacityReport {
17
- /** Harness whose quota pool is measured, e.g. "pi" or "codex". */
18
- harness: string;
19
- /** Model provider backing the harness, e.g. "zai" or "openai". */
20
- provider: string;
21
- generatedAt: string;
22
- authenticated: boolean | null;
23
- available: Availability;
24
- windows: CapacityWindow[];
25
- creditsRemaining: number | null;
26
- }
27
-
28
- /** Provider quota data before a harness/source identity is attached. */
29
- export type ProviderCapacitySnapshot = Omit<CapacityReport, "harness" | "provider" | "generatedAt">;