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