@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
package/src/utils/process.ts
DELETED
|
@@ -1,604 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Process Detection Utilities
|
|
3
|
-
*
|
|
4
|
-
* Shared shell command wrappers for detecting and inspecting running processes.
|
|
5
|
-
* Built-in refresh discovery uses captureProcessSnapshot(); synchronous helpers
|
|
6
|
-
* remain exported for compatibility with existing consumers.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import { execFile, execFileSync } from "child_process";
|
|
12
|
-
import type { ProcessInfo } from "../adapters/AgentAdapter.js";
|
|
13
|
-
|
|
14
|
-
const PROCESS_EXEC_MAX_BUFFER = 10 * 1024 * 1024;
|
|
15
|
-
const VALID_EXECUTABLE_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
16
|
-
const ABSOLUTE_PATH = /^(?:\/|[a-zA-Z]:[\\/])/;
|
|
17
|
-
const PATH_SEPARATOR = /[\\/]/;
|
|
18
|
-
|
|
19
|
-
function pathBasename(executable: string): string {
|
|
20
|
-
return path.basename(executable.replace(/\\/g, "/")).toLowerCase();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isFile(filePath: string): boolean {
|
|
24
|
-
try {
|
|
25
|
-
return fs.statSync(filePath, { throwIfNoEntry: false })?.isFile() ?? false;
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Resolve argv[0] from a `ps` command line.
|
|
33
|
-
*
|
|
34
|
-
* `ps` joins argv with spaces, so an executable installed under a directory
|
|
35
|
-
* containing spaces (`/Applications/Some App.app/Contents/Resources/codex`)
|
|
36
|
-
* spans several whitespace tokens. When the first token of an absolute path
|
|
37
|
-
* is not itself a file, longer space-joined prefixes ending in a token with a
|
|
38
|
-
* path separator are tried, and the first one that exists on disk wins.
|
|
39
|
-
* Otherwise the first token is returned, so arguments are never folded into
|
|
40
|
-
* the executable path unless that combined path really is a file.
|
|
41
|
-
*/
|
|
42
|
-
export function executablePath(command: string): string {
|
|
43
|
-
const parts = command.trim().split(/(\s+)/);
|
|
44
|
-
const first = parts[0] ?? "";
|
|
45
|
-
if (parts.length === 1 || !ABSOLUTE_PATH.test(first) || isFile(first)) return first;
|
|
46
|
-
|
|
47
|
-
let prefix = first;
|
|
48
|
-
for (let i = 2; i < parts.length; i += 2) {
|
|
49
|
-
prefix += parts[i - 1] + parts[i];
|
|
50
|
-
if (PATH_SEPARATOR.test(parts[i]) && isFile(prefix)) return prefix;
|
|
51
|
-
}
|
|
52
|
-
return first;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function executableBasename(command: string): string {
|
|
56
|
-
return pathBasename(executablePath(command));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function normalizeExecutableName(name: string): string {
|
|
60
|
-
const lower = name.toLowerCase();
|
|
61
|
-
return lower.endsWith(".exe") ? lower.slice(0, -4) : lower;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function normalizedProcessNames(namePatterns: readonly string[]): Set<string> {
|
|
65
|
-
return new Set(namePatterns.filter(Boolean).map(normalizeExecutableName));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Whether argv[0] of `command` is one of `names`.
|
|
70
|
-
*
|
|
71
|
-
* The first token is checked with string operations only, as before. The
|
|
72
|
-
* filesystem is consulted only for absolute commands where a later
|
|
73
|
-
* path-like token ends in one of the names, i.e. a possible executable under
|
|
74
|
-
* a directory containing spaces.
|
|
75
|
-
*/
|
|
76
|
-
function matchesExecutableName(command: string, names: ReadonlySet<string>): boolean {
|
|
77
|
-
const tokens = command.trim().split(/\s+/);
|
|
78
|
-
const first = tokens[0] ?? "";
|
|
79
|
-
if (names.has(normalizeExecutableName(pathBasename(first)))) return true;
|
|
80
|
-
if (!ABSOLUTE_PATH.test(first)) return false;
|
|
81
|
-
|
|
82
|
-
const mayContinuePath = tokens
|
|
83
|
-
.slice(1)
|
|
84
|
-
.some(
|
|
85
|
-
(token) =>
|
|
86
|
-
PATH_SEPARATOR.test(token) && names.has(normalizeExecutableName(pathBasename(token))),
|
|
87
|
-
);
|
|
88
|
-
return mayContinuePath && names.has(normalizeExecutableName(executableBasename(command)));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Whether argv[0]'s basename is exactly `prefix` or starts with `prefix-`.
|
|
93
|
-
*
|
|
94
|
-
* Covers versioned launchers such as `muse-bin-1.4.4-R5419.1` for prefix
|
|
95
|
-
* `muse`. This is a recall-oriented prefilter: adapters still apply
|
|
96
|
-
* `canHandle` for precise shaping, so a coincidental `prefix-*` binary
|
|
97
|
-
* cannot leak into another harness.
|
|
98
|
-
*/
|
|
99
|
-
export function matchesExecutablePrefix(command: string, prefixes: ReadonlySet<string>): boolean {
|
|
100
|
-
if (prefixes.size === 0) return false;
|
|
101
|
-
const base = normalizeExecutableName(pathBasename(command.trim().split(/\s+/)[0] ?? ""));
|
|
102
|
-
if (prefixes.has(base)) return true;
|
|
103
|
-
for (const prefix of prefixes) {
|
|
104
|
-
if (base.startsWith(`${prefix}-`)) return true;
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Whether argv[0] matches one of `names` exactly or one of `prefixes`. */
|
|
110
|
-
export function matchesProcessPatterns(
|
|
111
|
-
command: string,
|
|
112
|
-
names: ReadonlySet<string>,
|
|
113
|
-
prefixes: ReadonlySet<string> = new Set(),
|
|
114
|
-
): boolean {
|
|
115
|
-
return matchesExecutableName(command, names) || matchesExecutablePrefix(command, prefixes);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function filterByProcessNames(
|
|
119
|
-
processes: readonly ProcessInfo[],
|
|
120
|
-
namePatterns: readonly string[],
|
|
121
|
-
namePrefixes: readonly string[] = [],
|
|
122
|
-
): ProcessInfo[] {
|
|
123
|
-
const names = normalizedProcessNames(namePatterns);
|
|
124
|
-
const prefixes = normalizedProcessNames(namePrefixes);
|
|
125
|
-
if (names.size === 0 && prefixes.size === 0) return [];
|
|
126
|
-
return processes.filter((process) => matchesProcessPatterns(process.command, names, prefixes));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* List running processes matching an agent executable name.
|
|
131
|
-
*
|
|
132
|
-
* Uses `ps -axo` then filters in JS for exact executable basename match.
|
|
133
|
-
* This avoids shell pipelines and string interpolation.
|
|
134
|
-
*
|
|
135
|
-
* Returned ProcessInfo has pid, ppid, command, tty populated.
|
|
136
|
-
* cwd and startTime are NOT populated — call enrichProcesses() to fill them.
|
|
137
|
-
*/
|
|
138
|
-
export function listAgentProcesses(namePattern: string): ProcessInfo[] {
|
|
139
|
-
// Validate pattern contains only safe characters (alphanumeric, dash, underscore)
|
|
140
|
-
if (!namePattern || !VALID_EXECUTABLE_NAME.test(namePattern)) {
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const output = execFileSync("ps", ["-axo", "pid=,ppid=,tty=,command="], { encoding: "utf-8" });
|
|
146
|
-
|
|
147
|
-
const names = normalizedProcessNames([namePattern]);
|
|
148
|
-
const processes: ProcessInfo[] = [];
|
|
149
|
-
|
|
150
|
-
for (const line of output.trim().split("\n")) {
|
|
151
|
-
if (!line.trim()) continue;
|
|
152
|
-
|
|
153
|
-
const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.+)$/);
|
|
154
|
-
if (!match) continue;
|
|
155
|
-
|
|
156
|
-
const pid = parseInt(match[1], 10);
|
|
157
|
-
const ppid = parseInt(match[2], 10);
|
|
158
|
-
if (Number.isNaN(pid) || Number.isNaN(ppid)) continue;
|
|
159
|
-
|
|
160
|
-
const tty = match[3];
|
|
161
|
-
const command = match[4];
|
|
162
|
-
|
|
163
|
-
if (!matchesExecutableName(command, names)) continue;
|
|
164
|
-
|
|
165
|
-
const ttyShort = tty.startsWith("/dev/") ? tty.slice(5) : tty;
|
|
166
|
-
|
|
167
|
-
processes.push({
|
|
168
|
-
pid,
|
|
169
|
-
ppid,
|
|
170
|
-
command,
|
|
171
|
-
cwd: "",
|
|
172
|
-
tty: ttyShort,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return processes;
|
|
177
|
-
} catch {
|
|
178
|
-
return [];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** Runs an executable and resolves with its stdout. Injectable for tests. */
|
|
183
|
-
export type ProcessExec = (file: string, args: readonly string[]) => Promise<string>;
|
|
184
|
-
|
|
185
|
-
export interface ProcessSnapshotOptions {
|
|
186
|
-
/**
|
|
187
|
-
* Decides which name-matched processes are worth enriching with cwd and
|
|
188
|
-
* start time. Non-candidates are still returned (pid, ppid, tty, command
|
|
189
|
-
* only) so adapters can walk parent chains. Omitted = enrich everything.
|
|
190
|
-
*/
|
|
191
|
-
isCandidate?: (process: ProcessInfo) => boolean;
|
|
192
|
-
/**
|
|
193
|
-
* Basename prefixes matched like `processNamePrefixes`: exact or
|
|
194
|
-
* `<prefix>-*`. Same validation as namePatterns.
|
|
195
|
-
*/
|
|
196
|
-
namePrefixes?: readonly string[];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export type ProcessSnapshotCapture = (
|
|
200
|
-
namePatterns: readonly string[],
|
|
201
|
-
options?: ProcessSnapshotOptions,
|
|
202
|
-
) => Promise<ProcessInfo[]>;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* One construction site for snapshot options: `namePrefixes` is sent only
|
|
206
|
-
* when non-empty, so adapters without prefixes keep the exact legacy call
|
|
207
|
-
* shape that existing mock assertions pin.
|
|
208
|
-
*/
|
|
209
|
-
export function snapshotOptions(
|
|
210
|
-
namePrefixes: readonly string[],
|
|
211
|
-
isCandidate: (process: ProcessInfo) => boolean,
|
|
212
|
-
): ProcessSnapshotOptions {
|
|
213
|
-
return namePrefixes.length > 0
|
|
214
|
-
? { namePrefixes: [...namePrefixes], isCandidate }
|
|
215
|
-
: { isCandidate };
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const execFileText: ProcessExec = (file, args) =>
|
|
219
|
-
new Promise((resolve, reject) => {
|
|
220
|
-
execFile(
|
|
221
|
-
file,
|
|
222
|
-
args,
|
|
223
|
-
{ encoding: "utf-8", maxBuffer: PROCESS_EXEC_MAX_BUFFER },
|
|
224
|
-
(error, stdout) => {
|
|
225
|
-
if (error) {
|
|
226
|
-
reject(error);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
resolve(stdout);
|
|
230
|
-
},
|
|
231
|
-
);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
interface ParsedProcessList {
|
|
235
|
-
/** Every PID in the listing, used to evict cache entries for exited processes. */
|
|
236
|
-
allPids: Set<number>;
|
|
237
|
-
/** Processes whose executable matches one of the requested names. */
|
|
238
|
-
matched: ProcessInfo[];
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function parseProcessList(
|
|
242
|
-
output: string,
|
|
243
|
-
namePatterns: ReadonlySet<string>,
|
|
244
|
-
namePrefixes: ReadonlySet<string> = new Set(),
|
|
245
|
-
): ParsedProcessList {
|
|
246
|
-
const allPids = new Set<number>();
|
|
247
|
-
const matched: ProcessInfo[] = [];
|
|
248
|
-
|
|
249
|
-
for (const line of output.trim().split("\n")) {
|
|
250
|
-
if (!line.trim()) continue;
|
|
251
|
-
|
|
252
|
-
const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.+)$/);
|
|
253
|
-
if (!match) continue;
|
|
254
|
-
|
|
255
|
-
const pid = parseInt(match[1], 10);
|
|
256
|
-
const ppid = parseInt(match[2], 10);
|
|
257
|
-
if (Number.isNaN(pid) || Number.isNaN(ppid)) continue;
|
|
258
|
-
allPids.add(pid);
|
|
259
|
-
|
|
260
|
-
const tty = match[3];
|
|
261
|
-
const command = match[4];
|
|
262
|
-
if (!matchesProcessPatterns(command, namePatterns, namePrefixes)) continue;
|
|
263
|
-
|
|
264
|
-
matched.push({
|
|
265
|
-
pid,
|
|
266
|
-
ppid,
|
|
267
|
-
command,
|
|
268
|
-
cwd: "",
|
|
269
|
-
tty: tty.startsWith("/dev/") ? tty.slice(5) : tty,
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return { allPids, matched };
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/** Working directories of `pids` (async `lsof`); PIDs it cannot read are omitted. */
|
|
277
|
-
export function getProcessCwdsAsync(pids: number[]): Promise<Map<number, string>> {
|
|
278
|
-
return batchGetProcessCwdsAsync(execFileText, pids);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
async function batchGetProcessCwdsAsync(
|
|
282
|
-
exec: ProcessExec,
|
|
283
|
-
pids: number[],
|
|
284
|
-
): Promise<Map<number, string>> {
|
|
285
|
-
const result = new Map<number, string>();
|
|
286
|
-
if (pids.length === 0) return result;
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
const output = await exec("lsof", ["-a", "-d", "cwd", "-Fn", "-p", pids.join(",")]);
|
|
290
|
-
let currentPid: number | null = null;
|
|
291
|
-
for (const line of output.trim().split("\n")) {
|
|
292
|
-
if (line.startsWith("p")) {
|
|
293
|
-
currentPid = parseInt(line.slice(1), 10);
|
|
294
|
-
} else if (line.startsWith("n") && currentPid !== null) {
|
|
295
|
-
result.set(currentPid, line.slice(1));
|
|
296
|
-
currentPid = null;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return result;
|
|
300
|
-
} catch {
|
|
301
|
-
const entries = await Promise.all(
|
|
302
|
-
pids.map(async (pid) => {
|
|
303
|
-
try {
|
|
304
|
-
const output = await exec("pwdx", [String(pid)]);
|
|
305
|
-
const match = output.match(/^\d+:\s*(.+)$/);
|
|
306
|
-
return match ? ([pid, match[1].trim()] as const) : null;
|
|
307
|
-
} catch {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
}),
|
|
311
|
-
);
|
|
312
|
-
for (const entry of entries) {
|
|
313
|
-
if (entry) result.set(entry[0], entry[1]);
|
|
314
|
-
}
|
|
315
|
-
return result;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
async function batchGetProcessStartTimesAsync(
|
|
320
|
-
exec: ProcessExec,
|
|
321
|
-
pids: number[],
|
|
322
|
-
): Promise<Map<number, Date>> {
|
|
323
|
-
const result = new Map<number, Date>();
|
|
324
|
-
if (pids.length === 0) return result;
|
|
325
|
-
|
|
326
|
-
try {
|
|
327
|
-
const output = await exec("ps", ["-o", "pid=,lstart=", "-p", pids.join(",")]);
|
|
328
|
-
for (const rawLine of output.split("\n")) {
|
|
329
|
-
const match = rawLine.trim().match(/^(\d+)\s+(.+)$/);
|
|
330
|
-
if (!match) continue;
|
|
331
|
-
const pid = parseInt(match[1], 10);
|
|
332
|
-
const date = new Date(match[2].trim());
|
|
333
|
-
if (Number.isFinite(pid) && !Number.isNaN(date.getTime())) result.set(pid, date);
|
|
334
|
-
}
|
|
335
|
-
} catch {
|
|
336
|
-
// Return partial/empty data, matching the synchronous helper.
|
|
337
|
-
}
|
|
338
|
-
return result;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
interface CachedStartTime {
|
|
342
|
-
/** ppid + command seen when the start time was read; a mismatch means PID reuse. */
|
|
343
|
-
identity: string;
|
|
344
|
-
startTime: Date;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function processIdentity(process: ProcessInfo): string {
|
|
348
|
-
return `${process.ppid ?? ""}\0${process.command}`;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Create a snapshot capture function with its own start-time cache.
|
|
353
|
-
*
|
|
354
|
-
* Start times never change for a live process, so each PID is queried with
|
|
355
|
-
* `ps lstart` once and reused on later refreshes. A cache entry is dropped
|
|
356
|
-
* when its PID disappears from the base listing, and ignored when the PID's
|
|
357
|
-
* ppid/command no longer match (PID reuse). cwd is re-read every refresh
|
|
358
|
-
* because a process can change directory.
|
|
359
|
-
*/
|
|
360
|
-
export function createProcessSnapshotCapture(
|
|
361
|
-
deps: { exec?: ProcessExec } = {},
|
|
362
|
-
): ProcessSnapshotCapture {
|
|
363
|
-
const exec = deps.exec ?? execFileText;
|
|
364
|
-
const startTimeCache = new Map<number, CachedStartTime>();
|
|
365
|
-
|
|
366
|
-
const cachedStartTime = (process: ProcessInfo): Date | undefined => {
|
|
367
|
-
const cached = startTimeCache.get(process.pid);
|
|
368
|
-
return cached?.identity === processIdentity(process) ? cached.startTime : undefined;
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
return async (namePatterns, options = {}) => {
|
|
372
|
-
const valid = (name: string) => Boolean(name) && VALID_EXECUTABLE_NAME.test(name);
|
|
373
|
-
const names = normalizedProcessNames(namePatterns.filter(valid));
|
|
374
|
-
const prefixes = normalizedProcessNames((options.namePrefixes ?? []).filter(valid));
|
|
375
|
-
if (names.size === 0 && prefixes.size === 0) return [];
|
|
376
|
-
|
|
377
|
-
try {
|
|
378
|
-
const output = await exec("ps", ["-axo", "pid=,ppid=,tty=,command="]);
|
|
379
|
-
const { allPids, matched } = parseProcessList(output, names, prefixes);
|
|
380
|
-
|
|
381
|
-
for (const pid of startTimeCache.keys()) {
|
|
382
|
-
if (!allPids.has(pid)) startTimeCache.delete(pid);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const { isCandidate } = options;
|
|
386
|
-
const candidates = isCandidate ? matched.filter((process) => isCandidate(process)) : matched;
|
|
387
|
-
const candidatePids = candidates.map((process) => process.pid);
|
|
388
|
-
const uncachedPids = candidates
|
|
389
|
-
.filter((process) => cachedStartTime(process) === undefined)
|
|
390
|
-
.map((process) => process.pid);
|
|
391
|
-
|
|
392
|
-
const [cwdMap, startTimeMap] = await Promise.all([
|
|
393
|
-
batchGetProcessCwdsAsync(exec, candidatePids),
|
|
394
|
-
batchGetProcessStartTimesAsync(exec, uncachedPids),
|
|
395
|
-
]);
|
|
396
|
-
|
|
397
|
-
for (const process of candidates) {
|
|
398
|
-
const startTime = startTimeMap.get(process.pid);
|
|
399
|
-
if (startTime) {
|
|
400
|
-
startTimeCache.set(process.pid, { identity: processIdentity(process), startTime });
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
const candidateSet = new Set(candidatePids);
|
|
405
|
-
return matched.map((process) =>
|
|
406
|
-
candidateSet.has(process.pid)
|
|
407
|
-
? {
|
|
408
|
-
...process,
|
|
409
|
-
cwd: cwdMap.get(process.pid) || "",
|
|
410
|
-
startTime: cachedStartTime(process),
|
|
411
|
-
}
|
|
412
|
-
: process,
|
|
413
|
-
);
|
|
414
|
-
} catch {
|
|
415
|
-
return [];
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Capture and enrich relevant processes without blocking the event loop.
|
|
422
|
-
* One base process listing is shared by every requested executable name;
|
|
423
|
-
* only processes accepted by `options.isCandidate` are enriched.
|
|
424
|
-
*/
|
|
425
|
-
export const captureProcessSnapshot: ProcessSnapshotCapture = createProcessSnapshotCapture();
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Batch-get current working directories for multiple PIDs.
|
|
429
|
-
*
|
|
430
|
-
* Single `lsof -a -d cwd -Fn -p PID1,PID2,...` call.
|
|
431
|
-
* Returns partial results — if lsof fails for one PID, others still return.
|
|
432
|
-
*/
|
|
433
|
-
export function batchGetProcessCwds(pids: number[]): Map<number, string> {
|
|
434
|
-
const result = new Map<number, string>();
|
|
435
|
-
if (pids.length === 0) return result;
|
|
436
|
-
|
|
437
|
-
try {
|
|
438
|
-
const output = execFileSync("lsof", ["-a", "-d", "cwd", "-Fn", "-p", pids.join(",")], {
|
|
439
|
-
encoding: "utf-8",
|
|
440
|
-
stdio: ["pipe", "pipe", "ignore"],
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
// lsof output format: p{PID}\nn{path}\np{PID}\nn{path}...
|
|
444
|
-
let currentPid: number | null = null;
|
|
445
|
-
for (const line of output.trim().split("\n")) {
|
|
446
|
-
if (line.startsWith("p")) {
|
|
447
|
-
currentPid = parseInt(line.slice(1), 10);
|
|
448
|
-
} else if (line.startsWith("n") && currentPid !== null) {
|
|
449
|
-
result.set(currentPid, line.slice(1));
|
|
450
|
-
currentPid = null;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
} catch {
|
|
454
|
-
// Try per-PID fallback with pwdx (Linux)
|
|
455
|
-
for (const pid of pids) {
|
|
456
|
-
try {
|
|
457
|
-
const output = execFileSync("pwdx", [String(pid)], {
|
|
458
|
-
encoding: "utf-8",
|
|
459
|
-
stdio: ["pipe", "pipe", "ignore"],
|
|
460
|
-
});
|
|
461
|
-
const match = output.match(/^\d+:\s*(.+)$/);
|
|
462
|
-
if (match) {
|
|
463
|
-
result.set(pid, match[1].trim());
|
|
464
|
-
}
|
|
465
|
-
} catch {
|
|
466
|
-
// Skip this PID
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
return result;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Batch-get process start times for multiple PIDs.
|
|
476
|
-
*
|
|
477
|
-
* Single `ps -o pid=,lstart= -p PID1,PID2,...` call.
|
|
478
|
-
* Uses lstart format which gives full timestamp (e.g., "Thu Feb 5 16:00:57 2026").
|
|
479
|
-
* Returns partial results.
|
|
480
|
-
*/
|
|
481
|
-
export function batchGetProcessStartTimes(pids: number[]): Map<number, Date> {
|
|
482
|
-
const result = new Map<number, Date>();
|
|
483
|
-
if (pids.length === 0) return result;
|
|
484
|
-
|
|
485
|
-
try {
|
|
486
|
-
const output = execFileSync("ps", ["-o", "pid=,lstart=", "-p", pids.join(",")], {
|
|
487
|
-
encoding: "utf-8",
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
for (const rawLine of output.split("\n")) {
|
|
491
|
-
const line = rawLine.trim();
|
|
492
|
-
if (!line) continue;
|
|
493
|
-
|
|
494
|
-
// Format: " PID DAY MON DD HH:MM:SS YYYY"
|
|
495
|
-
// e.g., " 78070 Wed Mar 18 23:18:01 2026"
|
|
496
|
-
const match = line.match(/^\s*(\d+)\s+(.+)$/);
|
|
497
|
-
if (!match) continue;
|
|
498
|
-
|
|
499
|
-
const pid = parseInt(match[1], 10);
|
|
500
|
-
const dateStr = match[2].trim();
|
|
501
|
-
|
|
502
|
-
if (!Number.isFinite(pid)) continue;
|
|
503
|
-
|
|
504
|
-
const date = new Date(dateStr);
|
|
505
|
-
if (!Number.isNaN(date.getTime())) {
|
|
506
|
-
result.set(pid, date);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
} catch {
|
|
510
|
-
// Return whatever we have
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
return result;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* Enrich ProcessInfo array with cwd and startTime.
|
|
518
|
-
*
|
|
519
|
-
* Calls batchGetProcessCwds and batchGetProcessStartTimes in batched shell calls,
|
|
520
|
-
* then populates each ProcessInfo in-place. Returns partial results —
|
|
521
|
-
* if a PID fails, that process keeps empty cwd / undefined startTime.
|
|
522
|
-
*/
|
|
523
|
-
export function enrichProcesses(processes: ProcessInfo[]): ProcessInfo[] {
|
|
524
|
-
if (processes.length === 0) return processes;
|
|
525
|
-
|
|
526
|
-
const pids = processes.map((p) => p.pid);
|
|
527
|
-
const cwdMap = batchGetProcessCwds(pids);
|
|
528
|
-
const startTimeMap = batchGetProcessStartTimes(pids);
|
|
529
|
-
|
|
530
|
-
for (const proc of processes) {
|
|
531
|
-
proc.cwd = cwdMap.get(proc.pid) || "";
|
|
532
|
-
proc.startTime = startTimeMap.get(proc.pid);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return processes;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function isSameTerminalProcess(proc: ProcessInfo, matched: ProcessInfo): boolean {
|
|
539
|
-
const sameTty = proc.tty !== "" && proc.tty !== "?" && proc.tty === matched.tty;
|
|
540
|
-
const sameCwd = proc.cwd !== "" && proc.cwd === matched.cwd;
|
|
541
|
-
|
|
542
|
-
return sameTty && (sameCwd || proc.cwd === "" || matched.cwd === "");
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function matchesProcessIdentity(proc: ProcessInfo, matched: ProcessInfo): boolean {
|
|
546
|
-
return proc.pid === matched.pid || isSameTerminalProcess(proc, matched);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
export function findWrapperProcess(
|
|
550
|
-
processes: ProcessInfo[],
|
|
551
|
-
child: ProcessInfo,
|
|
552
|
-
): ProcessInfo | undefined {
|
|
553
|
-
return processes.find(
|
|
554
|
-
(proc) =>
|
|
555
|
-
proc.pid !== child.pid && child.ppid === proc.pid && matchesProcessIdentity(proc, child),
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Find parent wrapper processes that should not be reported as separate agents.
|
|
561
|
-
*
|
|
562
|
-
* A process is considered a wrapper when it is the parent of another candidate
|
|
563
|
-
* agent process in the same terminal/worktree, or when it points at the same
|
|
564
|
-
* terminal/worktree as an already session-matched process.
|
|
565
|
-
*/
|
|
566
|
-
export function findWrapperProcessPids(
|
|
567
|
-
processes: ProcessInfo[],
|
|
568
|
-
matchedProcesses: ProcessInfo[] = [],
|
|
569
|
-
): Set<number> {
|
|
570
|
-
const wrappers = new Set<number>();
|
|
571
|
-
|
|
572
|
-
for (const child of processes) {
|
|
573
|
-
const wrapper = findWrapperProcess(processes, child);
|
|
574
|
-
if (wrapper) {
|
|
575
|
-
wrappers.add(wrapper.pid);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
for (const proc of processes) {
|
|
580
|
-
if (
|
|
581
|
-
matchedProcesses.some(
|
|
582
|
-
(matched) => proc.pid !== matched.pid && isSameTerminalProcess(proc, matched),
|
|
583
|
-
)
|
|
584
|
-
) {
|
|
585
|
-
wrappers.add(proc.pid);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
return wrappers;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* Get the TTY device for a specific process
|
|
594
|
-
*/
|
|
595
|
-
export function getProcessTty(pid: number): string {
|
|
596
|
-
try {
|
|
597
|
-
const output = execFileSync("ps", ["-p", String(pid), "-o", "tty="], { encoding: "utf-8" });
|
|
598
|
-
|
|
599
|
-
const tty = output.trim();
|
|
600
|
-
return tty.startsWith("/dev/") ? tty.slice(5) : tty;
|
|
601
|
-
} catch {
|
|
602
|
-
return "?";
|
|
603
|
-
}
|
|
604
|
-
}
|