@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.
- package/dist/harnesses/pi/PiAdapter.d.ts.map +1 -1
- package/dist/harnesses/pi/PiAdapter.js +9 -4
- package/dist/harnesses/pi/PiAdapter.js.map +1 -1
- package/package.json +8 -3
- package/.swcrc +0 -27
- package/dist/__tests__/AgentManager.test.js +0 -1727
- package/dist/__tests__/AgentManager.test.js.map +0 -1
- package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js +0 -486
- package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js.map +0 -1
- package/dist/__tests__/adapters/adapterProcessImports.test.js +0 -52
- package/dist/__tests__/adapters/adapterProcessImports.test.js.map +0 -1
- package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js +0 -247
- package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js.map +0 -1
- package/dist/__tests__/capacity/anthropic.test.js +0 -115
- package/dist/__tests__/capacity/anthropic.test.js.map +0 -1
- package/dist/__tests__/capacity/boundaries.test.js +0 -45
- package/dist/__tests__/capacity/boundaries.test.js.map +0 -1
- package/dist/__tests__/capacity/claude.test.js +0 -485
- package/dist/__tests__/capacity/claude.test.js.map +0 -1
- package/dist/__tests__/capacity/codex.test.js +0 -339
- package/dist/__tests__/capacity/codex.test.js.map +0 -1
- package/dist/__tests__/capacity/devin.test.js +0 -239
- package/dist/__tests__/capacity/devin.test.js.map +0 -1
- package/dist/__tests__/capacity/index.test.js +0 -53
- package/dist/__tests__/capacity/index.test.js.map +0 -1
- package/dist/__tests__/capacity/openai.test.js +0 -687
- package/dist/__tests__/capacity/openai.test.js.map +0 -1
- package/dist/__tests__/capacity/wham.test.js +0 -159
- package/dist/__tests__/capacity/wham.test.js.map +0 -1
- package/dist/__tests__/capacity/zai.test.js +0 -212
- package/dist/__tests__/capacity/zai.test.js.map +0 -1
- package/dist/__tests__/fixtures.test.js +0 -218
- package/dist/__tests__/fixtures.test.js.map +0 -1
- package/dist/__tests__/harnesses/BoundedSummarySkip.test.js +0 -568
- package/dist/__tests__/harnesses/BoundedSummarySkip.test.js.map +0 -1
- package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js +0 -1089
- package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js.map +0 -1
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js +0 -143
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js.map +0 -1
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js +0 -462
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/builtinAdapters.test.js +0 -33
- package/dist/__tests__/harnesses/builtinAdapters.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js +0 -79
- package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js +0 -1881
- package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js +0 -425
- package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js +0 -314
- package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js +0 -49
- package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js +0 -76
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js +0 -173
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js +0 -181
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexAdapter.test.js +0 -685
- package/dist/__tests__/harnesses/codex/CodexAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js +0 -463
- package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js +0 -86
- package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js +0 -254
- package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js +0 -121
- package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js +0 -84
- package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js +0 -128
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js +0 -246
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js +0 -384
- package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js.map +0 -1
- package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js +0 -659
- package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js +0 -290
- package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinAdapter.test.js +0 -597
- package/dist/__tests__/harnesses/devin/DevinAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +0 -99
- package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js +0 -192
- package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js +0 -407
- package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/fixtures.js +0 -95
- package/dist/__tests__/harnesses/devin/fixtures.js.map +0 -1
- package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js +0 -1454
- package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js +0 -491
- package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js.map +0 -1
- package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js +0 -399
- package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js +0 -56
- package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js +0 -421
- package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js +0 -167
- package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js +0 -133
- package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js +0 -301
- package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js +0 -662
- package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseAdapter.test.js +0 -247
- package/dist/__tests__/harnesses/muse/MuseAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js +0 -81
- package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js +0 -185
- package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js +0 -328
- package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js +0 -213
- package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js +0 -108
- package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js +0 -94
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js +0 -147
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiAdapter.test.js +0 -367
- package/dist/__tests__/harnesses/pi/PiAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js +0 -382
- package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiSessionParser.test.js +0 -416
- package/dist/__tests__/harnesses/pi/PiSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js +0 -108
- package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js +0 -70
- package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js +0 -43
- package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js +0 -192
- package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js +0 -119
- package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js +0 -382
- package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js +0 -34
- package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js +0 -446
- package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js.map +0 -1
- package/dist/__tests__/harnesses/runtimeProfiles.test.js +0 -101
- package/dist/__tests__/harnesses/runtimeProfiles.test.js.map +0 -1
- package/dist/__tests__/print/DurableAgent.test.js +0 -15
- package/dist/__tests__/print/DurableAgent.test.js.map +0 -1
- package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js +0 -186
- package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js.map +0 -1
- package/dist/__tests__/print/DurableAgentRepository.test.js +0 -249
- package/dist/__tests__/print/DurableAgentRepository.test.js.map +0 -1
- package/dist/__tests__/readiness-fixtures.test.js +0 -54
- package/dist/__tests__/readiness-fixtures.test.js.map +0 -1
- package/dist/__tests__/runtime/AgentRuntime.test.js +0 -13
- package/dist/__tests__/runtime/AgentRuntime.test.js.map +0 -1
- package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js +0 -164
- package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js.map +0 -1
- package/dist/__tests__/runtime/HerdrAgentRuntime.test.js +0 -488
- package/dist/__tests__/runtime/HerdrAgentRuntime.test.js.map +0 -1
- package/dist/__tests__/runtime/ManagedAgentRuntime.test.js +0 -637
- package/dist/__tests__/runtime/ManagedAgentRuntime.test.js.map +0 -1
- package/dist/__tests__/terminal/GhosttyBackend.test.js +0 -334
- package/dist/__tests__/terminal/GhosttyBackend.test.js.map +0 -1
- package/dist/__tests__/terminal/TerminalFocusManager.test.js +0 -253
- package/dist/__tests__/terminal/TerminalFocusManager.test.js.map +0 -1
- package/dist/__tests__/terminal/TmuxManager.test.js +0 -168
- package/dist/__tests__/terminal/TmuxManager.test.js.map +0 -1
- package/dist/__tests__/terminal/TtyWriter.test.js +0 -386
- package/dist/__tests__/terminal/TtyWriter.test.js.map +0 -1
- package/dist/__tests__/utils/AgentRegistry.test.js +0 -636
- package/dist/__tests__/utils/AgentRegistry.test.js.map +0 -1
- package/dist/__tests__/utils/IncrementalJsonlSummary.test.js +0 -650
- package/dist/__tests__/utils/IncrementalJsonlSummary.test.js.map +0 -1
- package/dist/__tests__/utils/agent-requests.test.js +0 -90
- package/dist/__tests__/utils/agent-requests.test.js.map +0 -1
- package/dist/__tests__/utils/conversationTail.bench.test.js +0 -258
- package/dist/__tests__/utils/conversationTail.bench.test.js.map +0 -1
- package/dist/__tests__/utils/conversationTailParity.test.js +0 -588
- package/dist/__tests__/utils/conversationTailParity.test.js.map +0 -1
- package/dist/__tests__/utils/jsonlTail.test.js +0 -360
- package/dist/__tests__/utils/jsonlTail.test.js.map +0 -1
- package/dist/__tests__/utils/matching.test.js +0 -324
- package/dist/__tests__/utils/matching.test.js.map +0 -1
- package/dist/__tests__/utils/matchingConstants.test.js +0 -35
- package/dist/__tests__/utils/matchingConstants.test.js.map +0 -1
- package/dist/__tests__/utils/process.test.js +0 -818
- package/dist/__tests__/utils/process.test.js.map +0 -1
- package/dist/__tests__/utils/session.test.js +0 -175
- package/dist/__tests__/utils/session.test.js.map +0 -1
- package/project.json +0 -29
- package/scripts/benchmark-cold-start.mjs +0 -350
- package/src/AgentManager.ts +0 -559
- package/src/__tests__/AgentManager.test.ts +0 -1578
- package/src/__tests__/adapters/IncrementalSessionRefresh.test.ts +0 -437
- package/src/__tests__/adapters/adapterProcessImports.test.ts +0 -58
- package/src/__tests__/adapters/adapterSnapshotCandidates.test.ts +0 -243
- package/src/__tests__/capacity/anthropic.test.ts +0 -105
- package/src/__tests__/capacity/boundaries.test.ts +0 -36
- package/src/__tests__/capacity/claude.test.ts +0 -462
- package/src/__tests__/capacity/codex.test.ts +0 -311
- package/src/__tests__/capacity/devin.test.ts +0 -210
- package/src/__tests__/capacity/fixtures/claude-credentials.json +0 -7
- package/src/__tests__/capacity/fixtures/claude-usage-malformed.json +0 -1
- package/src/__tests__/capacity/fixtures/claude-usage-partial.json +0 -15
- package/src/__tests__/capacity/fixtures/claude-usage.json +0 -63
- package/src/__tests__/capacity/fixtures/devin-config.json +0 -6
- package/src/__tests__/capacity/fixtures/devin-credentials.toml +0 -4
- package/src/__tests__/capacity/fixtures/devin-quota-nonplan.json +0 -5
- package/src/__tests__/capacity/fixtures/devin-quota.json +0 -10
- package/src/__tests__/capacity/fixtures/openai-auth.json +0 -6
- package/src/__tests__/capacity/fixtures/openai-codex-auth.json +0 -9
- package/src/__tests__/capacity/fixtures/openai-usage-completions.json +0 -67
- package/src/__tests__/capacity/fixtures/openai-usage-responses.json +0 -20
- package/src/__tests__/capacity/fixtures/wham-usage.json +0 -45
- package/src/__tests__/capacity/fixtures/zai-auth.json +0 -6
- package/src/__tests__/capacity/fixtures/zai-quota-invalid.json +0 -7
- package/src/__tests__/capacity/fixtures/zai-quota.json +0 -38
- package/src/__tests__/capacity/index.test.ts +0 -54
- package/src/__tests__/capacity/openai.test.ts +0 -571
- package/src/__tests__/capacity/wham.test.ts +0 -122
- package/src/__tests__/capacity/zai.test.ts +0 -151
- package/src/__tests__/fixtures.test.ts +0 -245
- package/src/__tests__/harnesses/BoundedSummarySkip.test.ts +0 -496
- package/src/__tests__/harnesses/SessionSummaryEquivalence.test.ts +0 -726
- package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.ts +0 -133
- package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.ts +0 -396
- package/src/__tests__/harnesses/builtinAdapters.test.ts +0 -33
- package/src/__tests__/harnesses/claude/ClaudeAgentMapper.test.ts +0 -84
- package/src/__tests__/harnesses/claude/ClaudeCodeAdapter.test.ts +0 -1793
- package/src/__tests__/harnesses/claude/ClaudeSessionLocator.test.ts +0 -423
- package/src/__tests__/harnesses/claude/ClaudeSessionParser.test.ts +0 -300
- package/src/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.ts +0 -34
- package/src/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.ts +0 -61
- package/src/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.ts +0 -129
- package/src/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.ts +0 -152
- package/src/__tests__/harnesses/codex/CodexAdapter.test.ts +0 -652
- package/src/__tests__/harnesses/codex/CodexSessionLocator.test.ts +0 -419
- package/src/__tests__/harnesses/codex/CodexSessionMapping.test.ts +0 -63
- package/src/__tests__/harnesses/codex/CodexSessionParser.test.ts +0 -192
- package/src/__tests__/harnesses/codex/durable/CodexCliProbe.test.ts +0 -80
- package/src/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.ts +0 -65
- package/src/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.ts +0 -104
- package/src/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.ts +0 -201
- package/src/__tests__/harnesses/codex/durable/CodexPrintRunner.test.ts +0 -299
- package/src/__tests__/harnesses/copilot/CopilotAdapter.test.ts +0 -614
- package/src/__tests__/harnesses/copilot/CopilotRefreshIO.test.ts +0 -270
- package/src/__tests__/harnesses/devin/DevinAdapter.test.ts +0 -290
- package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +0 -101
- package/src/__tests__/harnesses/devin/DevinSessionLocator.test.ts +0 -139
- package/src/__tests__/harnesses/devin/DevinSessionParser.test.ts +0 -212
- package/src/__tests__/harnesses/devin/fixtures.ts +0 -144
- package/src/__tests__/harnesses/gemini/GeminiCliAdapter.test.ts +0 -1336
- package/src/__tests__/harnesses/gemini/GeminiSessionJsonl.test.ts +0 -402
- package/src/__tests__/harnesses/gemini/GeminiSessionLocator.test.ts +0 -396
- package/src/__tests__/harnesses/grok/GrokAgentMapper.test.ts +0 -57
- package/src/__tests__/harnesses/grok/GrokCliAdapter.test.ts +0 -376
- package/src/__tests__/harnesses/grok/GrokIncrementalRefresh.test.ts +0 -170
- package/src/__tests__/harnesses/grok/GrokSessionLocator.test.ts +0 -106
- package/src/__tests__/harnesses/grok/GrokSessionParser.test.ts +0 -230
- package/src/__tests__/harnesses/kiro/KiroAdapter.test.ts +0 -552
- package/src/__tests__/harnesses/muse/MuseAdapter.test.ts +0 -197
- package/src/__tests__/harnesses/muse/MuseAgentMapper.test.ts +0 -83
- package/src/__tests__/harnesses/muse/MuseSessionLocator.test.ts +0 -177
- package/src/__tests__/harnesses/muse/MuseSessionParser.test.ts +0 -279
- package/src/__tests__/harnesses/opencode/OpenCodeAdapter.test.ts +0 -215
- package/src/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.ts +0 -101
- package/src/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.ts +0 -84
- package/src/__tests__/harnesses/opencode/OpenCodeSessionParser.test.ts +0 -149
- package/src/__tests__/harnesses/pi/PiAdapter.test.ts +0 -325
- package/src/__tests__/harnesses/pi/PiDiscoveryIO.test.ts +0 -337
- package/src/__tests__/harnesses/pi/PiSessionParser.test.ts +0 -280
- package/src/__tests__/harnesses/pi/PiSessionTracker.test.ts +0 -79
- package/src/__tests__/harnesses/pi/durable/PiCliProbe.test.ts +0 -50
- package/src/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.ts +0 -33
- package/src/__tests__/harnesses/pi/durable/PiPrintAgentService.test.ts +0 -138
- package/src/__tests__/harnesses/pi/durable/PiPrintProtocol.test.ts +0 -71
- package/src/__tests__/harnesses/pi/durable/PiPrintRunner.test.ts +0 -252
- package/src/__tests__/harnesses/pi/durable/PiStreamParser.test.ts +0 -26
- package/src/__tests__/harnesses/readiness/AgentReadiness.test.ts +0 -362
- package/src/__tests__/harnesses/runtimeProfiles.test.ts +0 -123
- package/src/__tests__/print/DurableAgent.test.ts +0 -15
- package/src/__tests__/print/DurableAgentRepository.sqlite.test.ts +0 -128
- package/src/__tests__/print/DurableAgentRepository.test.ts +0 -184
- package/src/__tests__/readiness-fixtures.test.ts +0 -79
- package/src/__tests__/runtime/AgentRuntime.test.ts +0 -8
- package/src/__tests__/runtime/HerdrAgentDiscovery.test.ts +0 -131
- package/src/__tests__/runtime/HerdrAgentRuntime.test.ts +0 -377
- package/src/__tests__/runtime/ManagedAgentRuntime.test.ts +0 -590
- package/src/__tests__/terminal/GhosttyBackend.test.ts +0 -271
- package/src/__tests__/terminal/TerminalFocusManager.test.ts +0 -280
- package/src/__tests__/terminal/TmuxManager.test.ts +0 -185
- package/src/__tests__/terminal/TtyWriter.test.ts +0 -454
- package/src/__tests__/utils/AgentRegistry.test.ts +0 -532
- package/src/__tests__/utils/IncrementalJsonlSummary.test.ts +0 -414
- package/src/__tests__/utils/agent-requests.test.ts +0 -94
- package/src/__tests__/utils/conversationTail.bench.test.ts +0 -193
- package/src/__tests__/utils/conversationTailParity.test.ts +0 -365
- package/src/__tests__/utils/jsonlTail.test.ts +0 -317
- package/src/__tests__/utils/matching.test.ts +0 -234
- package/src/__tests__/utils/matchingConstants.test.ts +0 -40
- package/src/__tests__/utils/process.test.ts +0 -596
- package/src/__tests__/utils/session.test.ts +0 -158
- package/src/adapters/AgentAdapter.ts +0 -255
- package/src/capacity/index.ts +0 -127
- package/src/capacity/providers/anthropic.ts +0 -198
- package/src/capacity/providers/devin.ts +0 -121
- package/src/capacity/providers/openai-platform.ts +0 -150
- package/src/capacity/providers/openai-subscription.ts +0 -184
- package/src/capacity/providers/zai.ts +0 -155
- package/src/capacity/sources/claude.ts +0 -30
- package/src/capacity/sources/codex.ts +0 -251
- package/src/capacity/sources/devin.ts +0 -49
- package/src/capacity/sources/pi.ts +0 -131
- package/src/capacity/types.ts +0 -29
- package/src/database/connection.ts +0 -96
- package/src/database/index.ts +0 -7
- package/src/database/migrations/001_initial.sql +0 -12
- package/src/database/migrations/002_pins.sql +0 -1
- package/src/database/migrations/003_durable_agents.sql +0 -43
- package/src/database/migrations/004_codex_durable_sessions.sql +0 -1
- package/src/database/migrations/005_agent_runtime.sql +0 -2
- package/src/database/schema.ts +0 -64
- package/src/durable/DurableAgent.ts +0 -139
- package/src/durable/DurableAgentRepository.ts +0 -485
- package/src/durable/process.ts +0 -29
- package/src/durable/run.ts +0 -84
- package/src/durable/utils.ts +0 -66
- package/src/fixtures/bundle.ts +0 -130
- package/src/fixtures/capture.ts +0 -364
- package/src/harnesses/antigravity/AntigravityAgentMapper.ts +0 -34
- package/src/harnesses/antigravity/AntigravityCliAdapter.ts +0 -126
- package/src/harnesses/antigravity/AntigravitySessionLocator.ts +0 -75
- package/src/harnesses/antigravity/AntigravitySessionParser.ts +0 -252
- package/src/harnesses/claude/ClaudeAgentMapper.ts +0 -55
- package/src/harnesses/claude/ClaudeCodeAdapter.ts +0 -175
- package/src/harnesses/claude/ClaudeSessionLocator.ts +0 -358
- package/src/harnesses/claude/ClaudeSessionParser.ts +0 -524
- package/src/harnesses/claude/credentials.ts +0 -122
- package/src/harnesses/claude/durable/ClaudeCliProbe.ts +0 -57
- package/src/harnesses/claude/durable/ClaudePrintAgentService.ts +0 -79
- package/src/harnesses/claude/durable/ClaudePrintRunner.ts +0 -102
- package/src/harnesses/claude/durable/ClaudeStreamParser.ts +0 -108
- package/src/harnesses/claude/readiness.ts +0 -69
- package/src/harnesses/codex/CodexAdapter.ts +0 -337
- package/src/harnesses/codex/CodexAgentMapper.ts +0 -26
- package/src/harnesses/codex/CodexSessionLocator.ts +0 -509
- package/src/harnesses/codex/CodexSessionMapping.ts +0 -89
- package/src/harnesses/codex/CodexSessionParser.ts +0 -462
- package/src/harnesses/codex/credentials.ts +0 -81
- package/src/harnesses/codex/durable/CodexCliProbe.ts +0 -68
- package/src/harnesses/codex/durable/CodexPrintAgentService.ts +0 -79
- package/src/harnesses/codex/durable/CodexPrintRunner.ts +0 -104
- package/src/harnesses/codex/durable/CodexStreamParser.ts +0 -117
- package/src/harnesses/codex/readiness.ts +0 -72
- package/src/harnesses/copilot/CopilotAdapter.ts +0 -161
- package/src/harnesses/copilot/CopilotAgentMapper.ts +0 -27
- package/src/harnesses/copilot/CopilotSessionLocator.ts +0 -161
- package/src/harnesses/copilot/CopilotSessionParser.ts +0 -380
- package/src/harnesses/copilot/readiness.ts +0 -33
- package/src/harnesses/devin/DevinAdapter.ts +0 -212
- package/src/harnesses/devin/DevinAgentMapper.ts +0 -39
- package/src/harnesses/devin/DevinSessionLocator.ts +0 -230
- package/src/harnesses/devin/DevinSessionParser.ts +0 -227
- package/src/harnesses/devin/credentials.ts +0 -88
- package/src/harnesses/devin/readiness.ts +0 -36
- package/src/harnesses/gemini/GeminiAgentMapper.ts +0 -27
- package/src/harnesses/gemini/GeminiCliAdapter.ts +0 -272
- package/src/harnesses/gemini/GeminiSessionLocator.ts +0 -394
- package/src/harnesses/gemini/GeminiSessionParser.ts +0 -395
- package/src/harnesses/gemini/fileSignature.ts +0 -10
- package/src/harnesses/grok/GrokAgentMapper.ts +0 -32
- package/src/harnesses/grok/GrokCliAdapter.ts +0 -126
- package/src/harnesses/grok/GrokSessionLocator.ts +0 -179
- package/src/harnesses/grok/GrokSessionParser.ts +0 -251
- package/src/harnesses/index.ts +0 -32
- package/src/harnesses/kiro/KiroAdapter.ts +0 -143
- package/src/harnesses/kiro/KiroAgentMapper.ts +0 -34
- package/src/harnesses/kiro/KiroSessionLocator.ts +0 -143
- package/src/harnesses/kiro/KiroSessionParser.ts +0 -376
- package/src/harnesses/muse/MuseAdapter.ts +0 -157
- package/src/harnesses/muse/MuseAgentMapper.ts +0 -33
- package/src/harnesses/muse/MuseSessionLocator.ts +0 -286
- package/src/harnesses/muse/MuseSessionParser.ts +0 -435
- package/src/harnesses/muse/readiness.ts +0 -38
- package/src/harnesses/opencode/OpenCodeAdapter.ts +0 -110
- package/src/harnesses/opencode/OpenCodeAgentMapper.ts +0 -49
- package/src/harnesses/opencode/OpenCodeSessionLocator.ts +0 -151
- package/src/harnesses/opencode/OpenCodeSessionParser.ts +0 -146
- package/src/harnesses/opencode/readiness.ts +0 -48
- package/src/harnesses/pi/PiAdapter.ts +0 -197
- package/src/harnesses/pi/PiAgentMapper.ts +0 -27
- package/src/harnesses/pi/PiSessionLocator.ts +0 -288
- package/src/harnesses/pi/PiSessionParser.ts +0 -488
- package/src/harnesses/pi/PiSessionTracker.ts +0 -87
- package/src/harnesses/pi/credentials.ts +0 -129
- package/src/harnesses/pi/durable/PiCliProbe.ts +0 -56
- package/src/harnesses/pi/durable/PiPrintAgentService.ts +0 -77
- package/src/harnesses/pi/durable/PiPrintProtocol.ts +0 -41
- package/src/harnesses/pi/durable/PiPrintRunner.ts +0 -95
- package/src/harnesses/pi/durable/PiStreamParser.ts +0 -94
- package/src/harnesses/pi/readiness.ts +0 -104
- package/src/harnesses/readiness/AgentReadiness.ts +0 -91
- package/src/harnesses/readiness/checks.ts +0 -336
- package/src/harnesses/readiness/types.ts +0 -90
- package/src/harnesses/runtimeProfiles.ts +0 -105
- package/src/harnesses/shared.ts +0 -124
- package/src/index.ts +0 -71
- package/src/runtime/ManagedAgentRuntime.ts +0 -253
- package/src/runtime/RuntimeFactory.ts +0 -13
- package/src/runtime/errors.ts +0 -50
- package/src/runtime/herdr/HerdrAgentDiscovery.ts +0 -166
- package/src/runtime/herdr/HerdrAgentRuntime.ts +0 -216
- package/src/runtime/herdr/HerdrCliClient.ts +0 -78
- package/src/runtime/herdr/HerdrErrors.ts +0 -9
- package/src/runtime/herdr/HerdrResponseParsers.ts +0 -86
- package/src/runtime/herdr/HerdrRuntimeRef.ts +0 -41
- package/src/runtime/tmux/PidPolling.ts +0 -34
- package/src/runtime/tmux/TmuxAgentRuntime.ts +0 -113
- package/src/runtime/tmux/TmuxManager.ts +0 -102
- package/src/runtime/tmux/TmuxRuntimeRef.ts +0 -9
- package/src/runtime/types.ts +0 -56
- package/src/terminal/TerminalFocusManager.ts +0 -52
- package/src/terminal/TtyWriter.ts +0 -26
- package/src/terminal/backends/ghostty.ts +0 -180
- package/src/terminal/backends/index.ts +0 -23
- package/src/terminal/backends/iterm2.ts +0 -126
- package/src/terminal/backends/shared.ts +0 -47
- package/src/terminal/backends/terminal-app.ts +0 -122
- package/src/terminal/backends/tmux.ts +0 -62
- package/src/terminal/backends/wezterm.ts +0 -65
- package/src/terminal/types.ts +0 -23
- package/src/utils/AgentRegistry.ts +0 -351
- package/src/utils/IncrementalJsonlSummary.ts +0 -306
- package/src/utils/agent-requests.ts +0 -28
- package/src/utils/applescript.ts +0 -10
- package/src/utils/jsonlTail.ts +0 -349
- package/src/utils/matching.ts +0 -96
- package/src/utils/matchingConstants.ts +0 -15
- package/src/utils/process.ts +0 -604
- package/src/utils/session.ts +0 -144
- package/src/utils/sortAgents.ts +0 -54
- package/tsconfig.json +0 -11
- 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
|
-
}
|
package/src/capacity/types.ts
DELETED
|
@@ -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">;
|