@a5c-ai/agent-platform 5.0.1-staging.b436b3b3e611
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/README.md +53 -0
- package/dist/anycli/cache.d.ts +45 -0
- package/dist/anycli/cache.d.ts.map +1 -0
- package/dist/anycli/cache.js +118 -0
- package/dist/anycli/index.d.ts +10 -0
- package/dist/anycli/index.d.ts.map +1 -0
- package/dist/anycli/index.js +25 -0
- package/dist/anycli/types.d.ts +32 -0
- package/dist/anycli/types.d.ts.map +1 -0
- package/dist/anycli/types.js +9 -0
- package/dist/api/breakpoints.d.ts +93 -0
- package/dist/api/breakpoints.d.ts.map +1 -0
- package/dist/api/breakpoints.js +334 -0
- package/dist/api/effects.d.ts +14 -0
- package/dist/api/effects.d.ts.map +1 -0
- package/dist/api/effects.js +306 -0
- package/dist/api/effectsTypes.d.ts +79 -0
- package/dist/api/effectsTypes.d.ts.map +1 -0
- package/dist/api/effectsTypes.js +6 -0
- package/dist/api/eventStream.d.ts +34 -0
- package/dist/api/eventStream.d.ts.map +1 -0
- package/dist/api/eventStream.js +126 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +27 -0
- package/dist/api/runs.d.ts +85 -0
- package/dist/api/runs.d.ts.map +1 -0
- package/dist/api/runs.js +247 -0
- package/dist/api/utils.d.ts +28 -0
- package/dist/api/utils.d.ts.map +1 -0
- package/dist/api/utils.js +74 -0
- package/dist/breakpoints/approvalChains.d.ts +68 -0
- package/dist/breakpoints/approvalChains.d.ts.map +1 -0
- package/dist/breakpoints/approvalChains.js +111 -0
- package/dist/breakpoints/delegation.d.ts +42 -0
- package/dist/breakpoints/delegation.d.ts.map +1 -0
- package/dist/breakpoints/delegation.js +199 -0
- package/dist/breakpoints/delegationTypes.d.ts +46 -0
- package/dist/breakpoints/delegationTypes.d.ts.map +1 -0
- package/dist/breakpoints/delegationTypes.js +10 -0
- package/dist/breakpoints/postures.d.ts +28 -0
- package/dist/breakpoints/postures.d.ts.map +1 -0
- package/dist/breakpoints/postures.js +100 -0
- package/dist/cli/amuxEventsFormatter.d.ts +26 -0
- package/dist/cli/amuxEventsFormatter.d.ts.map +1 -0
- package/dist/cli/amuxEventsFormatter.js +86 -0
- package/dist/cli/args/argFlags.d.ts +6 -0
- package/dist/cli/args/argFlags.d.ts.map +1 -0
- package/dist/cli/args/argFlags.js +72 -0
- package/dist/cli/args/argPositionals.d.ts +3 -0
- package/dist/cli/args/argPositionals.d.ts.map +1 -0
- package/dist/cli/args/argPositionals.js +18 -0
- package/dist/cli/args/index.d.ts +4 -0
- package/dist/cli/args/index.d.ts.map +1 -0
- package/dist/cli/args/index.js +75 -0
- package/dist/cli/args/types.d.ts +13 -0
- package/dist/cli/args/types.d.ts.map +1 -0
- package/dist/cli/args/types.js +2 -0
- package/dist/cli/commands/daemon.d.ts +31 -0
- package/dist/cli/commands/daemon.d.ts.map +1 -0
- package/dist/cli/commands/daemon.js +156 -0
- package/dist/cli/commands/harness/createRun.d.ts +3 -0
- package/dist/cli/commands/harness/createRun.d.ts.map +1 -0
- package/dist/cli/commands/harness/createRun.js +8 -0
- package/dist/cli/commands/harness/resumeRun.d.ts +20 -0
- package/dist/cli/commands/harness/resumeRun.d.ts.map +1 -0
- package/dist/cli/commands/harness/resumeRun.js +341 -0
- package/dist/cli/commands/jsonlInteractive.d.ts +35 -0
- package/dist/cli/commands/jsonlInteractive.d.ts.map +1 -0
- package/dist/cli/commands/jsonlInteractive.js +302 -0
- package/dist/cli/commands/mcpServe.d.ts +18 -0
- package/dist/cli/commands/mcpServe.d.ts.map +1 -0
- package/dist/cli/commands/mcpServe.js +59 -0
- package/dist/cli/commands/session/history.d.ts +14 -0
- package/dist/cli/commands/session/history.d.ts.map +1 -0
- package/dist/cli/commands/session/history.js +100 -0
- package/dist/cli/commands/tui.d.ts +23 -0
- package/dist/cli/commands/tui.d.ts.map +1 -0
- package/dist/cli/commands/tui.js +183 -0
- package/dist/cli/dispatch.d.ts +4 -0
- package/dist/cli/dispatch.d.ts.map +1 -0
- package/dist/cli/dispatch.js +332 -0
- package/dist/cli/main.d.ts +7 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +41 -0
- package/dist/cli/program.d.ts +7 -0
- package/dist/cli/program.d.ts.map +1 -0
- package/dist/cli/program.js +8 -0
- package/dist/cli/ui.d.ts +9 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +125 -0
- package/dist/compression/compaction.d.ts +82 -0
- package/dist/compression/compaction.d.ts.map +1 -0
- package/dist/compression/compaction.js +310 -0
- package/dist/cost/claudeCodeParser.d.ts +81 -0
- package/dist/cost/claudeCodeParser.d.ts.map +1 -0
- package/dist/cost/claudeCodeParser.js +232 -0
- package/dist/cost/collector.d.ts +42 -0
- package/dist/cost/collector.d.ts.map +1 -0
- package/dist/cost/collector.js +105 -0
- package/dist/cost/effectCost.d.ts +23 -0
- package/dist/cost/effectCost.d.ts.map +1 -0
- package/dist/cost/effectCost.js +26 -0
- package/dist/cost/index.d.ts +7 -0
- package/dist/cost/index.d.ts.map +1 -0
- package/dist/cost/index.js +28 -0
- package/dist/cost/journal.d.ts +40 -0
- package/dist/cost/journal.d.ts.map +1 -0
- package/dist/cost/journal.js +137 -0
- package/dist/cost/types.d.ts +164 -0
- package/dist/cost/types.d.ts.map +1 -0
- package/dist/cost/types.js +228 -0
- package/dist/daemon/automationExecutor.d.ts +16 -0
- package/dist/daemon/automationExecutor.d.ts.map +1 -0
- package/dist/daemon/automationExecutor.js +222 -0
- package/dist/daemon/config.d.ts +8 -0
- package/dist/daemon/config.d.ts.map +1 -0
- package/dist/daemon/config.js +209 -0
- package/dist/daemon/daemonLog.d.ts +13 -0
- package/dist/daemon/daemonLog.d.ts.map +1 -0
- package/dist/daemon/daemonLog.js +64 -0
- package/dist/daemon/fileWatcher.d.ts +9 -0
- package/dist/daemon/fileWatcher.d.ts.map +1 -0
- package/dist/daemon/fileWatcher.js +141 -0
- package/dist/daemon/index.d.ts +7 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +21 -0
- package/dist/daemon/lifecycle.d.ts +12 -0
- package/dist/daemon/lifecycle.d.ts.map +1 -0
- package/dist/daemon/lifecycle.js +257 -0
- package/dist/daemon/loop.d.ts +21 -0
- package/dist/daemon/loop.d.ts.map +1 -0
- package/dist/daemon/loop.js +196 -0
- package/dist/daemon/timerScheduler.d.ts +13 -0
- package/dist/daemon/timerScheduler.d.ts.map +1 -0
- package/dist/daemon/timerScheduler.js +122 -0
- package/dist/daemon/types.d.ts +93 -0
- package/dist/daemon/types.d.ts.map +1 -0
- package/dist/daemon/types.js +25 -0
- package/dist/daemon/webhookListener.d.ts +6 -0
- package/dist/daemon/webhookListener.d.ts.map +1 -0
- package/dist/daemon/webhookListener.js +110 -0
- package/dist/governance/authority.d.ts +68 -0
- package/dist/governance/authority.d.ts.map +1 -0
- package/dist/governance/authority.js +136 -0
- package/dist/governance/bridge.d.ts +17 -0
- package/dist/governance/bridge.d.ts.map +1 -0
- package/dist/governance/bridge.js +46 -0
- package/dist/governance/builtins.d.ts +25 -0
- package/dist/governance/builtins.d.ts.map +1 -0
- package/dist/governance/builtins.js +67 -0
- package/dist/governance/categories.d.ts +58 -0
- package/dist/governance/categories.d.ts.map +1 -0
- package/dist/governance/categories.js +120 -0
- package/dist/governance/decisionTrail.d.ts +60 -0
- package/dist/governance/decisionTrail.d.ts.map +1 -0
- package/dist/governance/decisionTrail.js +68 -0
- package/dist/governance/engine.d.ts +20 -0
- package/dist/governance/engine.d.ts.map +1 -0
- package/dist/governance/engine.js +124 -0
- package/dist/governance/index.d.ts +20 -0
- package/dist/governance/index.d.ts.map +1 -0
- package/dist/governance/index.js +75 -0
- package/dist/governance/logging.d.ts +18 -0
- package/dist/governance/logging.d.ts.map +1 -0
- package/dist/governance/logging.js +83 -0
- package/dist/governance/mandate.d.ts +83 -0
- package/dist/governance/mandate.d.ts.map +1 -0
- package/dist/governance/mandate.js +180 -0
- package/dist/governance/permissionEvents.d.ts +51 -0
- package/dist/governance/permissionEvents.d.ts.map +1 -0
- package/dist/governance/permissionEvents.js +52 -0
- package/dist/governance/permissionPropagation.d.ts +18 -0
- package/dist/governance/permissionPropagation.d.ts.map +1 -0
- package/dist/governance/permissionPropagation.js +58 -0
- package/dist/governance/postureBridge.d.ts +17 -0
- package/dist/governance/postureBridge.d.ts.map +1 -0
- package/dist/governance/postureBridge.js +117 -0
- package/dist/governance/sandboxBridge.d.ts +49 -0
- package/dist/governance/sandboxBridge.d.ts.map +1 -0
- package/dist/governance/sandboxBridge.js +77 -0
- package/dist/governance/sandboxPolicy.d.ts +51 -0
- package/dist/governance/sandboxPolicy.d.ts.map +1 -0
- package/dist/governance/sandboxPolicy.js +177 -0
- package/dist/governance/types.d.ts +3 -0
- package/dist/governance/types.d.ts.map +1 -0
- package/dist/governance/types.js +5 -0
- package/dist/harness/amux/amuxBridge.d.ts +71 -0
- package/dist/harness/amux/amuxBridge.d.ts.map +1 -0
- package/dist/harness/amux/amuxBridge.js +117 -0
- package/dist/harness/amux/amuxClientFactory.d.ts +29 -0
- package/dist/harness/amux/amuxClientFactory.d.ts.map +1 -0
- package/dist/harness/amux/amuxClientFactory.js +90 -0
- package/dist/harness/amux/amuxEventEmitter.d.ts +51 -0
- package/dist/harness/amux/amuxEventEmitter.d.ts.map +1 -0
- package/dist/harness/amux/amuxEventEmitter.js +143 -0
- package/dist/harness/amux/amuxEventMapper.d.ts +58 -0
- package/dist/harness/amux/amuxEventMapper.d.ts.map +1 -0
- package/dist/harness/amux/amuxEventMapper.js +92 -0
- package/dist/harness/amux/amuxHarnessMap.d.ts +25 -0
- package/dist/harness/amux/amuxHarnessMap.d.ts.map +1 -0
- package/dist/harness/amux/amuxHarnessMap.js +55 -0
- package/dist/harness/amux/amuxStdinReader.d.ts +45 -0
- package/dist/harness/amux/amuxStdinReader.d.ts.map +1 -0
- package/dist/harness/amux/amuxStdinReader.js +106 -0
- package/dist/harness/amux/amuxTypes.d.ts +122 -0
- package/dist/harness/amux/amuxTypes.d.ts.map +1 -0
- package/dist/harness/amux/amuxTypes.js +11 -0
- package/dist/harness/amux/index.d.ts +17 -0
- package/dist/harness/amux/index.d.ts.map +1 -0
- package/dist/harness/amux/index.js +34 -0
- package/dist/harness/backgroundTracker.d.ts +64 -0
- package/dist/harness/backgroundTracker.d.ts.map +1 -0
- package/dist/harness/backgroundTracker.js +107 -0
- package/dist/harness/builtInHarness.d.ts +3 -0
- package/dist/harness/builtInHarness.d.ts.map +1 -0
- package/dist/harness/builtInHarness.js +18 -0
- package/dist/harness/capabilityRouter.d.ts +76 -0
- package/dist/harness/capabilityRouter.d.ts.map +1 -0
- package/dist/harness/capabilityRouter.js +176 -0
- package/dist/harness/fallbackChains.d.ts +42 -0
- package/dist/harness/fallbackChains.d.ts.map +1 -0
- package/dist/harness/fallbackChains.js +69 -0
- package/dist/harness/hostContract.d.ts +63 -0
- package/dist/harness/hostContract.d.ts.map +1 -0
- package/dist/harness/hostContract.js +136 -0
- package/dist/harness/index.d.ts +10 -0
- package/dist/harness/index.d.ts.map +1 -0
- package/dist/harness/index.js +66 -0
- package/dist/harness/internal/createRun/askUserQuestion.d.ts +11 -0
- package/dist/harness/internal/createRun/askUserQuestion.d.ts.map +1 -0
- package/dist/harness/internal/createRun/askUserQuestion.js +162 -0
- package/dist/harness/internal/createRun/index.d.ts +25 -0
- package/dist/harness/internal/createRun/index.d.ts.map +1 -0
- package/dist/harness/internal/createRun/index.js +137 -0
- package/dist/harness/internal/createRun/orchestration/constants.d.ts +7 -0
- package/dist/harness/internal/createRun/orchestration/constants.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/constants.js +13 -0
- package/dist/harness/internal/createRun/orchestration/effects.d.ts +43 -0
- package/dist/harness/internal/createRun/orchestration/effects.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/effects.js +490 -0
- package/dist/harness/internal/createRun/orchestration/effectsHelpers.d.ts +20 -0
- package/dist/harness/internal/createRun/orchestration/effectsHelpers.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/effectsHelpers.js +79 -0
- package/dist/harness/internal/createRun/orchestration/externalPhase.d.ts +3 -0
- package/dist/harness/internal/createRun/orchestration/externalPhase.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/externalPhase.js +319 -0
- package/dist/harness/internal/createRun/orchestration/externalPhaseHelpers.d.ts +16 -0
- package/dist/harness/internal/createRun/orchestration/externalPhaseHelpers.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/externalPhaseHelpers.js +104 -0
- package/dist/harness/internal/createRun/orchestration/index.d.ts +14 -0
- package/dist/harness/internal/createRun/orchestration/index.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/index.js +36 -0
- package/dist/harness/internal/createRun/orchestration/internalPhase.d.ts +3 -0
- package/dist/harness/internal/createRun/orchestration/internalPhase.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/internalPhase.js +464 -0
- package/dist/harness/internal/createRun/orchestration/internalTools.d.ts +26 -0
- package/dist/harness/internal/createRun/orchestration/internalTools.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/internalTools.js +262 -0
- package/dist/harness/internal/createRun/orchestration/internalToolsHelpers.d.ts +17 -0
- package/dist/harness/internal/createRun/orchestration/internalToolsHelpers.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/internalToolsHelpers.js +23 -0
- package/dist/harness/internal/createRun/orchestration/taskResult.d.ts +10 -0
- package/dist/harness/internal/createRun/orchestration/taskResult.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/taskResult.js +67 -0
- package/dist/harness/internal/createRun/orchestration/types.d.ts +46 -0
- package/dist/harness/internal/createRun/orchestration/types.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/types.js +2 -0
- package/dist/harness/internal/createRun/orchestration/verbose.d.ts +7 -0
- package/dist/harness/internal/createRun/orchestration/verbose.d.ts.map +1 -0
- package/dist/harness/internal/createRun/orchestration/verbose.js +240 -0
- package/dist/harness/internal/createRun/output.d.ts +38 -0
- package/dist/harness/internal/createRun/output.d.ts.map +1 -0
- package/dist/harness/internal/createRun/output.js +415 -0
- package/dist/harness/internal/createRun/pi.d.ts +34 -0
- package/dist/harness/internal/createRun/pi.d.ts.map +1 -0
- package/dist/harness/internal/createRun/pi.js +216 -0
- package/dist/harness/internal/createRun/planProcess/agentOutput.d.ts +5 -0
- package/dist/harness/internal/createRun/planProcess/agentOutput.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/agentOutput.js +113 -0
- package/dist/harness/internal/createRun/planProcess/delegation.d.ts +23 -0
- package/dist/harness/internal/createRun/planProcess/delegation.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/delegation.js +176 -0
- package/dist/harness/internal/createRun/planProcess/external.d.ts +14 -0
- package/dist/harness/internal/createRun/planProcess/external.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/external.js +139 -0
- package/dist/harness/internal/createRun/planProcess/index.d.ts +12 -0
- package/dist/harness/internal/createRun/planProcess/index.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/index.js +24 -0
- package/dist/harness/internal/createRun/planProcess/paths.d.ts +7 -0
- package/dist/harness/internal/createRun/planProcess/paths.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/paths.js +98 -0
- package/dist/harness/internal/createRun/planProcess/phase.d.ts +6 -0
- package/dist/harness/internal/createRun/planProcess/phase.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/phase.js +361 -0
- package/dist/harness/internal/createRun/planProcess/phaseHelpers.d.ts +37 -0
- package/dist/harness/internal/createRun/planProcess/phaseHelpers.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/phaseHelpers.js +159 -0
- package/dist/harness/internal/createRun/planProcess/phaseTypes.d.ts +25 -0
- package/dist/harness/internal/createRun/planProcess/phaseTypes.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/phaseTypes.js +6 -0
- package/dist/harness/internal/createRun/planProcess/prompts.d.ts +20 -0
- package/dist/harness/internal/createRun/planProcess/prompts.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/prompts.js +208 -0
- package/dist/harness/internal/createRun/planProcess/recovery.d.ts +18 -0
- package/dist/harness/internal/createRun/planProcess/recovery.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/recovery.js +188 -0
- package/dist/harness/internal/createRun/planProcess/recovery.test.d.ts +2 -0
- package/dist/harness/internal/createRun/planProcess/recovery.test.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/recovery.test.js +68 -0
- package/dist/harness/internal/createRun/planProcess/runState.d.ts +40 -0
- package/dist/harness/internal/createRun/planProcess/runState.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/runState.js +179 -0
- package/dist/harness/internal/createRun/planProcess/understandIntent.d.ts +22 -0
- package/dist/harness/internal/createRun/planProcess/understandIntent.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/understandIntent.js +65 -0
- package/dist/harness/internal/createRun/planProcess/validation.d.ts +2 -0
- package/dist/harness/internal/createRun/planProcess/validation.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/validation.js +212 -0
- package/dist/harness/internal/createRun/planProcess/validationSource.d.ts +11 -0
- package/dist/harness/internal/createRun/planProcess/validationSource.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/validationSource.js +328 -0
- package/dist/harness/internal/createRun/planProcess/validationText.d.ts +3 -0
- package/dist/harness/internal/createRun/planProcess/validationText.d.ts.map +1 -0
- package/dist/harness/internal/createRun/planProcess/validationText.js +145 -0
- package/dist/harness/internal/createRun/prompts.d.ts +49 -0
- package/dist/harness/internal/createRun/prompts.d.ts.map +1 -0
- package/dist/harness/internal/createRun/prompts.js +307 -0
- package/dist/harness/internal/createRun/resumeState.d.ts +28 -0
- package/dist/harness/internal/createRun/resumeState.d.ts.map +1 -0
- package/dist/harness/internal/createRun/resumeState.js +133 -0
- package/dist/harness/internal/createRun/utils.d.ts +182 -0
- package/dist/harness/internal/createRun/utils.d.ts.map +1 -0
- package/dist/harness/internal/createRun/utils.js +133 -0
- package/dist/harness/internal.d.ts +13 -0
- package/dist/harness/internal.d.ts.map +1 -0
- package/dist/harness/internal.js +149 -0
- package/dist/harness/invoker/launch.d.ts +20 -0
- package/dist/harness/invoker/launch.d.ts.map +1 -0
- package/dist/harness/invoker/launch.js +23 -0
- package/dist/harness/invoker/processControl.d.ts +11 -0
- package/dist/harness/invoker/processControl.d.ts.map +1 -0
- package/dist/harness/invoker/processControl.js +50 -0
- package/dist/harness/invoker.d.ts +43 -0
- package/dist/harness/invoker.d.ts.map +1 -0
- package/dist/harness/invoker.js +210 -0
- package/dist/harness/modeSelector.d.ts +50 -0
- package/dist/harness/modeSelector.d.ts.map +1 -0
- package/dist/harness/modeSelector.js +124 -0
- package/dist/harness/modelSelection.d.ts +37 -0
- package/dist/harness/modelSelection.d.ts.map +1 -0
- package/dist/harness/modelSelection.js +81 -0
- package/dist/harness/operatorCommands.d.ts +38 -0
- package/dist/harness/operatorCommands.d.ts.map +1 -0
- package/dist/harness/operatorCommands.js +118 -0
- package/dist/harness/piSecureSandbox.d.ts +8 -0
- package/dist/harness/piSecureSandbox.d.ts.map +1 -0
- package/dist/harness/piSecureSandbox.js +366 -0
- package/dist/harness/piSecureSandboxTypes.d.ts +51 -0
- package/dist/harness/piSecureSandboxTypes.d.ts.map +1 -0
- package/dist/harness/piSecureSandboxTypes.js +6 -0
- package/dist/harness/piWrapper/compaction.d.ts +13 -0
- package/dist/harness/piWrapper/compaction.d.ts.map +1 -0
- package/dist/harness/piWrapper/compaction.js +38 -0
- package/dist/harness/piWrapper/instructionPrompts.d.ts +2 -0
- package/dist/harness/piWrapper/instructionPrompts.d.ts.map +1 -0
- package/dist/harness/piWrapper/instructionPrompts.js +97 -0
- package/dist/harness/piWrapper/moduleSupport.d.ts +77 -0
- package/dist/harness/piWrapper/moduleSupport.d.ts.map +1 -0
- package/dist/harness/piWrapper/moduleSupport.js +204 -0
- package/dist/harness/piWrapper.d.ts +80 -0
- package/dist/harness/piWrapper.d.ts.map +1 -0
- package/dist/harness/piWrapper.js +389 -0
- package/dist/harness/piWrapper.test.d.ts +2 -0
- package/dist/harness/piWrapper.test.d.ts.map +1 -0
- package/dist/harness/piWrapper.test.js +193 -0
- package/dist/harness/planMode.d.ts +68 -0
- package/dist/harness/planMode.d.ts.map +1 -0
- package/dist/harness/planMode.js +145 -0
- package/dist/harness/selectionPolicies.d.ts +29 -0
- package/dist/harness/selectionPolicies.d.ts.map +1 -0
- package/dist/harness/selectionPolicies.js +165 -0
- package/dist/harness/types.d.ts +266 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +34 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/interaction/askUserQuestion/core.d.ts +8 -0
- package/dist/interaction/askUserQuestion/core.d.ts.map +1 -0
- package/dist/interaction/askUserQuestion/core.js +112 -0
- package/dist/interaction/askUserQuestion/terminal.d.ts +15 -0
- package/dist/interaction/askUserQuestion/terminal.d.ts.map +1 -0
- package/dist/interaction/askUserQuestion/terminal.js +128 -0
- package/dist/interaction/askUserQuestion.d.ts +10 -0
- package/dist/interaction/askUserQuestion.d.ts.map +1 -0
- package/dist/interaction/askUserQuestion.js +295 -0
- package/dist/interaction/askUserQuestionTypes.d.ts +31 -0
- package/dist/interaction/askUserQuestionTypes.d.ts.map +1 -0
- package/dist/interaction/askUserQuestionTypes.js +6 -0
- package/dist/interaction/index.d.ts +4 -0
- package/dist/interaction/index.d.ts.map +1 -0
- package/dist/interaction/index.js +20 -0
- package/dist/interaction/interactionRouter.d.ts +25 -0
- package/dist/interaction/interactionRouter.d.ts.map +1 -0
- package/dist/interaction/interactionRouter.js +55 -0
- package/dist/mcp/channels/allowlist.d.ts +19 -0
- package/dist/mcp/channels/allowlist.d.ts.map +1 -0
- package/dist/mcp/channels/allowlist.js +140 -0
- package/dist/mcp/channels/channelManager.d.ts +64 -0
- package/dist/mcp/channels/channelManager.d.ts.map +1 -0
- package/dist/mcp/channels/channelManager.js +137 -0
- package/dist/mcp/channels/inboundQueue.d.ts +47 -0
- package/dist/mcp/channels/inboundQueue.d.ts.map +1 -0
- package/dist/mcp/channels/inboundQueue.js +96 -0
- package/dist/mcp/channels/index.d.ts +17 -0
- package/dist/mcp/channels/index.d.ts.map +1 -0
- package/dist/mcp/channels/index.js +39 -0
- package/dist/mcp/channels/outbound.d.ts +33 -0
- package/dist/mcp/channels/outbound.d.ts.map +1 -0
- package/dist/mcp/channels/outbound.js +94 -0
- package/dist/mcp/channels/permissionRelay.d.ts +62 -0
- package/dist/mcp/channels/permissionRelay.d.ts.map +1 -0
- package/dist/mcp/channels/permissionRelay.js +159 -0
- package/dist/mcp/channels/types.d.ts +135 -0
- package/dist/mcp/channels/types.d.ts.map +1 -0
- package/dist/mcp/channels/types.js +16 -0
- package/dist/mcp/client/config.d.ts +28 -0
- package/dist/mcp/client/config.d.ts.map +1 -0
- package/dist/mcp/client/config.js +142 -0
- package/dist/mcp/client/executor.d.ts +30 -0
- package/dist/mcp/client/executor.d.ts.map +1 -0
- package/dist/mcp/client/executor.js +60 -0
- package/dist/mcp/client/index.d.ts +12 -0
- package/dist/mcp/client/index.d.ts.map +1 -0
- package/dist/mcp/client/index.js +27 -0
- package/dist/mcp/client/manager.d.ts +74 -0
- package/dist/mcp/client/manager.d.ts.map +1 -0
- package/dist/mcp/client/manager.js +214 -0
- package/dist/mcp/client/toolRegistry.d.ts +50 -0
- package/dist/mcp/client/toolRegistry.d.ts.map +1 -0
- package/dist/mcp/client/toolRegistry.js +118 -0
- package/dist/mcp/client/types.d.ts +96 -0
- package/dist/mcp/client/types.d.ts.map +1 -0
- package/dist/mcp/client/types.js +15 -0
- package/dist/mcp/transport/index.d.ts +9 -0
- package/dist/mcp/transport/index.d.ts.map +1 -0
- package/dist/mcp/transport/index.js +13 -0
- package/dist/mcp/transport/session.d.ts +18 -0
- package/dist/mcp/transport/session.d.ts.map +1 -0
- package/dist/mcp/transport/session.js +78 -0
- package/dist/mcp/transport/types.d.ts +19 -0
- package/dist/mcp/transport/types.d.ts.map +1 -0
- package/dist/mcp/transport/types.js +7 -0
- package/dist/mcp/transport/websocket.d.ts +41 -0
- package/dist/mcp/transport/websocket.d.ts.map +1 -0
- package/dist/mcp/transport/websocket.js +271 -0
- package/dist/observability/health.d.ts +19 -0
- package/dist/observability/health.d.ts.map +1 -0
- package/dist/observability/health.js +129 -0
- package/dist/observability/index.d.ts +7 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +22 -0
- package/dist/observability/runStatus.d.ts +44 -0
- package/dist/observability/runStatus.d.ts.map +1 -0
- package/dist/observability/runStatus.js +169 -0
- package/dist/observability/timeline.d.ts +11 -0
- package/dist/observability/timeline.d.ts.map +1 -0
- package/dist/observability/timeline.js +176 -0
- package/dist/observability/types.d.ts +62 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +8 -0
- package/dist/observability/webhooks.d.ts +68 -0
- package/dist/observability/webhooks.d.ts.map +1 -0
- package/dist/observability/webhooks.js +132 -0
- package/dist/prompts/commandTemplates.d.ts +3 -0
- package/dist/prompts/commandTemplates.d.ts.map +1 -0
- package/dist/prompts/commandTemplates.js +238 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +28 -0
- package/dist/seams/contract.d.ts +55 -0
- package/dist/seams/contract.d.ts.map +1 -0
- package/dist/seams/contract.js +120 -0
- package/dist/seams/contract.test.d.ts +2 -0
- package/dist/seams/contract.test.d.ts.map +1 -0
- package/dist/seams/contract.test.js +96 -0
- package/dist/seams/index.d.ts +3 -0
- package/dist/seams/index.d.ts.map +1 -0
- package/dist/seams/index.js +8 -0
- package/dist/session/context.d.ts +22 -0
- package/dist/session/context.d.ts.map +1 -0
- package/dist/session/context.js +113 -0
- package/dist/session/continuityState.d.ts +39 -0
- package/dist/session/continuityState.d.ts.map +1 -0
- package/dist/session/continuityState.js +164 -0
- package/dist/session/cost.d.ts +63 -0
- package/dist/session/cost.d.ts.map +1 -0
- package/dist/session/cost.js +194 -0
- package/dist/session/discovery.d.ts +22 -0
- package/dist/session/discovery.d.ts.map +1 -0
- package/dist/session/discovery.js +35 -0
- package/dist/session/history.d.ts +30 -0
- package/dist/session/history.d.ts.map +1 -0
- package/dist/session/history.js +143 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +70 -0
- package/dist/session/memoryExtraction.d.ts +65 -0
- package/dist/session/memoryExtraction.d.ts.map +1 -0
- package/dist/session/memoryExtraction.js +201 -0
- package/dist/session/parse.d.ts +45 -0
- package/dist/session/parse.d.ts.map +1 -0
- package/dist/session/parse.js +170 -0
- package/dist/session/persistence.d.ts +46 -0
- package/dist/session/persistence.d.ts.map +1 -0
- package/dist/session/persistence.js +180 -0
- package/dist/session/types.d.ts +267 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +45 -0
- package/dist/session/write.d.ts +61 -0
- package/dist/session/write.d.ts.map +1 -0
- package/dist/session/write.js +213 -0
- package/dist/storage/atomic.d.ts +2 -0
- package/dist/storage/atomic.d.ts.map +1 -0
- package/dist/storage/atomic.js +54 -0
- package/dist/storage/clock.d.ts +2 -0
- package/dist/storage/clock.d.ts.map +1 -0
- package/dist/storage/clock.js +6 -0
- package/dist/storage/index.d.ts +7 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +9 -0
- package/dist/storage/journalWatcher.d.ts +24 -0
- package/dist/storage/journalWatcher.d.ts.map +1 -0
- package/dist/storage/journalWatcher.js +172 -0
- package/dist/storage/paths.d.ts +5 -0
- package/dist/storage/paths.d.ts.map +1 -0
- package/dist/storage/paths.js +26 -0
- package/dist/storage/snapshotState.d.ts +10 -0
- package/dist/storage/snapshotState.d.ts.map +1 -0
- package/dist/storage/snapshotState.js +15 -0
- package/dist/storage/storeTaskArtifacts.d.ts +6 -0
- package/dist/storage/storeTaskArtifacts.d.ts.map +1 -0
- package/dist/storage/storeTaskArtifacts.js +55 -0
- package/dist/storage/types.d.ts +21 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/tasks/crud.d.ts +33 -0
- package/dist/tasks/crud.d.ts.map +1 -0
- package/dist/tasks/crud.js +150 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +9 -0
- package/package.json +141 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Status: NOT INTEGRATED YET
|
|
4
|
+
* Moved from @a5c-ai/babysitter-sdk.
|
|
5
|
+
* GAP-PERF-002: Session Compaction.
|
|
6
|
+
*
|
|
7
|
+
* Summarizes and condenses orchestration history to prevent context window
|
|
8
|
+
* overflow during long runs. Multiple strategies with auto-triggering
|
|
9
|
+
* based on token budget thresholds.
|
|
10
|
+
*
|
|
11
|
+
* Compacted data is stored as overlays — original journals and task artifacts
|
|
12
|
+
* are never modified.
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.DEFAULT_COMPACTION_CONFIG = void 0;
|
|
49
|
+
exports.getCompactionStatePath = getCompactionStatePath;
|
|
50
|
+
exports.getCompactionState = getCompactionState;
|
|
51
|
+
exports.shouldAutoCompact = shouldAutoCompact;
|
|
52
|
+
exports.buildIterationDigest = buildIterationDigest;
|
|
53
|
+
exports.compactSession = compactSession;
|
|
54
|
+
exports.renderCompactedHistory = renderCompactedHistory;
|
|
55
|
+
const node_fs_1 = require("node:fs");
|
|
56
|
+
const path = __importStar(require("node:path"));
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Defaults
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
exports.DEFAULT_COMPACTION_CONFIG = {
|
|
61
|
+
enabled: true,
|
|
62
|
+
autoCompactThreshold: 80_000,
|
|
63
|
+
strategies: ["tool-output-summarization", "iteration-digest"],
|
|
64
|
+
keepRecentIterations: 3,
|
|
65
|
+
toolOutputTargetReduction: 0.6,
|
|
66
|
+
};
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Internal helpers
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
function emptyCompactionState() {
|
|
71
|
+
return { operations: [], iterationDigests: [], toolOutputSummaries: [], totalTokensSaved: 0 };
|
|
72
|
+
}
|
|
73
|
+
async function readRaw(filePath) {
|
|
74
|
+
let raw;
|
|
75
|
+
try {
|
|
76
|
+
raw = await node_fs_1.promises.readFile(filePath, "utf8");
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
const err = error;
|
|
80
|
+
if (err.code === "ENOENT")
|
|
81
|
+
return emptyCompactionState();
|
|
82
|
+
return emptyCompactionState();
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const data = JSON.parse(raw);
|
|
86
|
+
return {
|
|
87
|
+
operations: Array.isArray(data.operations) ? data.operations : [],
|
|
88
|
+
iterationDigests: Array.isArray(data.iterationDigests) ? data.iterationDigests : [],
|
|
89
|
+
toolOutputSummaries: Array.isArray(data.toolOutputSummaries) ? data.toolOutputSummaries : [],
|
|
90
|
+
totalTokensSaved: typeof data.totalTokensSaved === "number" ? data.totalTokensSaved : 0,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return emptyCompactionState();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function writeRaw(filePath, data) {
|
|
98
|
+
const dir = path.dirname(filePath);
|
|
99
|
+
const tempPath = `${filePath}.tmp.${process.pid}`;
|
|
100
|
+
await node_fs_1.promises.mkdir(dir, { recursive: true });
|
|
101
|
+
await node_fs_1.promises.writeFile(tempPath, JSON.stringify(data, null, 2), "utf8");
|
|
102
|
+
await node_fs_1.promises.rename(tempPath, filePath);
|
|
103
|
+
}
|
|
104
|
+
/** Rough token estimate: ~4 chars per token. */
|
|
105
|
+
function estimateTokens(text) {
|
|
106
|
+
return Math.ceil(text.length / 4);
|
|
107
|
+
}
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// Public API
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
function getCompactionStatePath(stateDir, sessionId) {
|
|
112
|
+
return path.join(stateDir, `${sessionId}.compaction.json`);
|
|
113
|
+
}
|
|
114
|
+
async function getCompactionState(stateDir, sessionId) {
|
|
115
|
+
return readRaw(getCompactionStatePath(stateDir, sessionId));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check whether auto-compaction should trigger.
|
|
119
|
+
*/
|
|
120
|
+
function shouldAutoCompact(estimatedTokens, config) {
|
|
121
|
+
if (!config.enabled)
|
|
122
|
+
return false;
|
|
123
|
+
return estimatedTokens > config.autoCompactThreshold;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Build a digest from a set of journal events belonging to one iteration.
|
|
127
|
+
* Pure function.
|
|
128
|
+
*/
|
|
129
|
+
function buildIterationDigest(runId, iteration, events) {
|
|
130
|
+
const resolvedEffects = [];
|
|
131
|
+
let earliestAt = "";
|
|
132
|
+
let latestAt = "";
|
|
133
|
+
for (const ev of events) {
|
|
134
|
+
if (!earliestAt || ev.recordedAt < earliestAt)
|
|
135
|
+
earliestAt = ev.recordedAt;
|
|
136
|
+
if (!latestAt || ev.recordedAt > latestAt)
|
|
137
|
+
latestAt = ev.recordedAt;
|
|
138
|
+
if (ev.type === "EFFECT_RESOLVED" && ev.data) {
|
|
139
|
+
const effectId = ev.data.effectId;
|
|
140
|
+
if (effectId)
|
|
141
|
+
resolvedEffects.push(effectId);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const durationSeconds = earliestAt && latestAt
|
|
145
|
+
? (new Date(latestAt).getTime() - new Date(earliestAt).getTime()) / 1000
|
|
146
|
+
: 0;
|
|
147
|
+
const effectCount = resolvedEffects.length;
|
|
148
|
+
const eventTypes = [...new Set(events.map((e) => e.type))];
|
|
149
|
+
const summary = `Iteration ${iteration}: ${effectCount} effect(s) resolved, events: ${eventTypes.join(", ")}`;
|
|
150
|
+
return {
|
|
151
|
+
iteration,
|
|
152
|
+
runId,
|
|
153
|
+
summary,
|
|
154
|
+
resolvedEffects,
|
|
155
|
+
durationSeconds,
|
|
156
|
+
timestamp: latestAt || new Date().toISOString(),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Run compaction strategies on a session.
|
|
161
|
+
* Reads journal/tasks as needed but only writes to the overlay file — never
|
|
162
|
+
* modifies originals.
|
|
163
|
+
*/
|
|
164
|
+
async function compactSession(stateDir, sessionId, runsDir, config = exports.DEFAULT_COMPACTION_CONFIG) {
|
|
165
|
+
if (!config.enabled)
|
|
166
|
+
return [];
|
|
167
|
+
const overlayPath = getCompactionStatePath(stateDir, sessionId);
|
|
168
|
+
const state = await readRaw(overlayPath);
|
|
169
|
+
const results = [];
|
|
170
|
+
for (const strategy of config.strategies) {
|
|
171
|
+
const result = await applyStrategy(strategy, runsDir, config, state);
|
|
172
|
+
if (result) {
|
|
173
|
+
state.operations.push(result);
|
|
174
|
+
state.totalTokensSaved += result.tokensBefore - result.tokensAfter;
|
|
175
|
+
results.push(result);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
await writeRaw(overlayPath, state);
|
|
179
|
+
return results;
|
|
180
|
+
}
|
|
181
|
+
async function applyStrategy(strategy, runsDir, config, state) {
|
|
182
|
+
const now = new Date().toISOString();
|
|
183
|
+
if (strategy === "iteration-digest") {
|
|
184
|
+
// Scan run directories for journal files, build digests for old iterations
|
|
185
|
+
const existingDigestIterations = new Set(state.iterationDigests.map((d) => `${d.runId}:${d.iteration}`));
|
|
186
|
+
let itemsCompacted = 0;
|
|
187
|
+
let tokensBefore = 0;
|
|
188
|
+
let tokensAfter = 0;
|
|
189
|
+
let runDirs;
|
|
190
|
+
try {
|
|
191
|
+
const entries = await node_fs_1.promises.readdir(runsDir, { withFileTypes: true });
|
|
192
|
+
runDirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
for (const runDir of runDirs) {
|
|
198
|
+
const journalDir = path.join(runsDir, runDir, "journal");
|
|
199
|
+
let files;
|
|
200
|
+
try {
|
|
201
|
+
files = await node_fs_1.promises.readdir(journalDir);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
// Group events by iteration (heuristic: each EFFECT_REQUESTED starts new iteration group)
|
|
207
|
+
const events = [];
|
|
208
|
+
for (const file of files.sort()) {
|
|
209
|
+
if (!file.endsWith(".json"))
|
|
210
|
+
continue;
|
|
211
|
+
try {
|
|
212
|
+
const raw = await node_fs_1.promises.readFile(path.join(journalDir, file), "utf8");
|
|
213
|
+
events.push(JSON.parse(raw));
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (events.length === 0)
|
|
220
|
+
continue;
|
|
221
|
+
// Simple iteration grouping: split at RUN_CREATED or sequential grouping
|
|
222
|
+
const iterationSize = Math.max(1, Math.ceil(events.length / Math.max(1, config.keepRecentIterations + 1)));
|
|
223
|
+
const totalGroups = Math.ceil(events.length / iterationSize);
|
|
224
|
+
const compactableGroups = Math.max(0, totalGroups - config.keepRecentIterations);
|
|
225
|
+
for (let i = 0; i < compactableGroups; i++) {
|
|
226
|
+
const key = `${runDir}:${i + 1}`;
|
|
227
|
+
if (existingDigestIterations.has(key))
|
|
228
|
+
continue;
|
|
229
|
+
const groupEvents = events.slice(i * iterationSize, (i + 1) * iterationSize);
|
|
230
|
+
const beforeTokens = estimateTokens(JSON.stringify(groupEvents));
|
|
231
|
+
const digest = buildIterationDigest(runDir, i + 1, groupEvents);
|
|
232
|
+
const afterTokens = estimateTokens(JSON.stringify(digest));
|
|
233
|
+
state.iterationDigests.push(digest);
|
|
234
|
+
tokensBefore += beforeTokens;
|
|
235
|
+
tokensAfter += afterTokens;
|
|
236
|
+
itemsCompacted++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (itemsCompacted === 0)
|
|
240
|
+
return undefined;
|
|
241
|
+
return { strategy, tokensBefore, tokensAfter, itemsCompacted, compactedAt: now };
|
|
242
|
+
}
|
|
243
|
+
if (strategy === "tool-output-summarization") {
|
|
244
|
+
// Scan task directories for large stdout/stderr, create summarized overlays
|
|
245
|
+
let itemsCompacted = 0;
|
|
246
|
+
let tokensBefore = 0;
|
|
247
|
+
let tokensAfter = 0;
|
|
248
|
+
let runDirs;
|
|
249
|
+
try {
|
|
250
|
+
const entries = await node_fs_1.promises.readdir(runsDir, { withFileTypes: true });
|
|
251
|
+
runDirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
for (const runDir of runDirs) {
|
|
257
|
+
const tasksDir = path.join(runsDir, runDir, "tasks");
|
|
258
|
+
let taskDirs;
|
|
259
|
+
try {
|
|
260
|
+
const entries = await node_fs_1.promises.readdir(tasksDir, { withFileTypes: true });
|
|
261
|
+
taskDirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
for (const taskDir of taskDirs) {
|
|
267
|
+
for (const file of ["stdout.txt", "stderr.txt"]) {
|
|
268
|
+
const filePath = path.join(tasksDir, taskDir, file);
|
|
269
|
+
try {
|
|
270
|
+
const content = await node_fs_1.promises.readFile(filePath, "utf8");
|
|
271
|
+
const beforeTokens = estimateTokens(content);
|
|
272
|
+
if (beforeTokens < 200)
|
|
273
|
+
continue; // Skip small outputs
|
|
274
|
+
const relativePath = `${runDir}/tasks/${taskDir}/${file}`;
|
|
275
|
+
// Skip if already summarized
|
|
276
|
+
if (state.toolOutputSummaries.some((s) => s.relativePath === relativePath))
|
|
277
|
+
continue;
|
|
278
|
+
const targetLength = Math.ceil(content.length * (1 - config.toolOutputTargetReduction));
|
|
279
|
+
const truncated = content.slice(0, targetLength) + "\n... [compacted]";
|
|
280
|
+
const afterTokens = estimateTokens(truncated);
|
|
281
|
+
state.toolOutputSummaries.push({
|
|
282
|
+
relativePath,
|
|
283
|
+
summary: truncated,
|
|
284
|
+
originalTokens: beforeTokens,
|
|
285
|
+
});
|
|
286
|
+
tokensBefore += beforeTokens;
|
|
287
|
+
tokensAfter += afterTokens;
|
|
288
|
+
itemsCompacted++;
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (itemsCompacted === 0)
|
|
297
|
+
return undefined;
|
|
298
|
+
return { strategy, tokensBefore, tokensAfter, itemsCompacted, compactedAt: now };
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Render iteration digests as markdown for prompt injection.
|
|
304
|
+
*/
|
|
305
|
+
function renderCompactedHistory(state) {
|
|
306
|
+
if (state.iterationDigests.length === 0)
|
|
307
|
+
return "";
|
|
308
|
+
const lines = state.iterationDigests.map((d) => `- **Iter ${d.iteration}** (${d.runId}): ${d.summary} [${d.durationSeconds.toFixed(1)}s]`);
|
|
309
|
+
return `## Compacted History\n\n${lines.join("\n")}\n\n_${state.totalTokensSaved} tokens saved across ${state.operations.length} compaction(s)._`;
|
|
310
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code JSONL session file parser for cost data collection.
|
|
3
|
+
*
|
|
4
|
+
* Parses Claude Code session JSONL files (main session and subagent files)
|
|
5
|
+
* to extract token usage data and compute costs. Each assistant message with
|
|
6
|
+
* a `usage` block becomes a {@link CostEventData} entry.
|
|
7
|
+
*
|
|
8
|
+
* JSONL format (one JSON object per line):
|
|
9
|
+
* ```json
|
|
10
|
+
* {
|
|
11
|
+
* "type": "assistant",
|
|
12
|
+
* "message": {
|
|
13
|
+
* "model": "claude-opus-4-6",
|
|
14
|
+
* "usage": {
|
|
15
|
+
* "input_tokens": 3,
|
|
16
|
+
* "cache_creation_input_tokens": 26928,
|
|
17
|
+
* "cache_read_input_tokens": 0,
|
|
18
|
+
* "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 26928 },
|
|
19
|
+
* "output_tokens": 28,
|
|
20
|
+
* "service_tier": "standard"
|
|
21
|
+
* }
|
|
22
|
+
* },
|
|
23
|
+
* "timestamp": "2026-04-05T..."
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { CostEventData, ModelCostStats } from "./types";
|
|
28
|
+
/**
|
|
29
|
+
* Parse a single Claude Code session JSONL file into cost events.
|
|
30
|
+
*
|
|
31
|
+
* Reads the file, splits by newline, and for each line that represents an
|
|
32
|
+
* assistant message with usage data, extracts token counts and computes
|
|
33
|
+
* the USD cost using the extended pricing model.
|
|
34
|
+
*
|
|
35
|
+
* @param sessionJsonlPath - Absolute path to the `.jsonl` file.
|
|
36
|
+
* @returns Array of cost events extracted from assistant messages.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseClaudeCodeSession(sessionJsonlPath: string): Promise<CostEventData[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Parse a Claude Code session JSONL file and all associated subagent files.
|
|
41
|
+
*
|
|
42
|
+
* Subagent files live at `<sessionDir>/subagents/agent-*.jsonl` where
|
|
43
|
+
* `<sessionDir>` is derived by stripping the `.jsonl` extension from the
|
|
44
|
+
* main session file path.
|
|
45
|
+
*
|
|
46
|
+
* @param sessionJsonlPath - Absolute path to the main session `.jsonl` file.
|
|
47
|
+
* @returns Merged array of cost events from the main session and all subagents.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseClaudeCodeSessionWithSubagents(sessionJsonlPath: string): Promise<CostEventData[]>;
|
|
50
|
+
/** Aggregated usage summary returned by {@link aggregateUsageData}. */
|
|
51
|
+
export interface AggregatedUsage {
|
|
52
|
+
/** Total number of cost events. */
|
|
53
|
+
eventCount: number;
|
|
54
|
+
/** Total base input tokens across all events. */
|
|
55
|
+
totalInputTokens: number;
|
|
56
|
+
/** Total output tokens across all events. */
|
|
57
|
+
totalOutputTokens: number;
|
|
58
|
+
/** Total cache-creation tokens (top-level) across all events. */
|
|
59
|
+
totalCacheCreationTokens: number;
|
|
60
|
+
/** Total cache-read tokens across all events. */
|
|
61
|
+
totalCacheReadTokens: number;
|
|
62
|
+
/** Total 5-minute cache-creation tokens. */
|
|
63
|
+
totalCacheCreation5mTokens: number;
|
|
64
|
+
/** Total 1-hour cache-creation tokens. */
|
|
65
|
+
totalCacheCreation1hTokens: number;
|
|
66
|
+
/** Total computed cost in USD. */
|
|
67
|
+
totalCostUsd: number;
|
|
68
|
+
/** Per-model breakdown of usage statistics. */
|
|
69
|
+
byModel: Record<string, ModelCostStats>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Aggregate usage data across an array of cost events.
|
|
73
|
+
*
|
|
74
|
+
* Sums token counts and costs, producing both overall totals and a
|
|
75
|
+
* per-model breakdown.
|
|
76
|
+
*
|
|
77
|
+
* @param events - Array of cost events (e.g. from {@link parseClaudeCodeSessionWithSubagents}).
|
|
78
|
+
* @returns Aggregated usage summary with per-model breakdown.
|
|
79
|
+
*/
|
|
80
|
+
export declare function aggregateUsageData(events: CostEventData[]): AggregatedUsage;
|
|
81
|
+
//# sourceMappingURL=claudeCodeParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claudeCodeParser.d.ts","sourceRoot":"","sources":["../../src/cost/claudeCodeParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAqC7D;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CA+D1B;AAMD;;;;;;;;;GASG;AACH,wBAAsB,mCAAmC,CACvD,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CA+B1B;AAMD,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,gBAAgB,EAAE,MAAM,CAAC;IACzB,6CAA6C;IAC7C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,wBAAwB,EAAE,MAAM,CAAC;IACjC,iDAAiD;IACjD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,4CAA4C;IAC5C,0BAA0B,EAAE,MAAM,CAAC;IACnC,0CAA0C;IAC1C,0BAA0B,EAAE,MAAM,CAAC;IACnC,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe,CAqD3E"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Claude Code JSONL session file parser for cost data collection.
|
|
4
|
+
*
|
|
5
|
+
* Parses Claude Code session JSONL files (main session and subagent files)
|
|
6
|
+
* to extract token usage data and compute costs. Each assistant message with
|
|
7
|
+
* a `usage` block becomes a {@link CostEventData} entry.
|
|
8
|
+
*
|
|
9
|
+
* JSONL format (one JSON object per line):
|
|
10
|
+
* ```json
|
|
11
|
+
* {
|
|
12
|
+
* "type": "assistant",
|
|
13
|
+
* "message": {
|
|
14
|
+
* "model": "claude-opus-4-6",
|
|
15
|
+
* "usage": {
|
|
16
|
+
* "input_tokens": 3,
|
|
17
|
+
* "cache_creation_input_tokens": 26928,
|
|
18
|
+
* "cache_read_input_tokens": 0,
|
|
19
|
+
* "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 26928 },
|
|
20
|
+
* "output_tokens": 28,
|
|
21
|
+
* "service_tier": "standard"
|
|
22
|
+
* }
|
|
23
|
+
* },
|
|
24
|
+
* "timestamp": "2026-04-05T..."
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
45
|
+
var ownKeys = function(o) {
|
|
46
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
49
|
+
return ar;
|
|
50
|
+
};
|
|
51
|
+
return ownKeys(o);
|
|
52
|
+
};
|
|
53
|
+
return function (mod) {
|
|
54
|
+
if (mod && mod.__esModule) return mod;
|
|
55
|
+
var result = {};
|
|
56
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
57
|
+
__setModuleDefault(result, mod);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
})();
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.parseClaudeCodeSession = parseClaudeCodeSession;
|
|
63
|
+
exports.parseClaudeCodeSessionWithSubagents = parseClaudeCodeSessionWithSubagents;
|
|
64
|
+
exports.aggregateUsageData = aggregateUsageData;
|
|
65
|
+
const node_fs_1 = require("node:fs");
|
|
66
|
+
const path = __importStar(require("node:path"));
|
|
67
|
+
const types_1 = require("./types");
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// Single-file parser
|
|
70
|
+
// ============================================================================
|
|
71
|
+
/**
|
|
72
|
+
* Parse a single Claude Code session JSONL file into cost events.
|
|
73
|
+
*
|
|
74
|
+
* Reads the file, splits by newline, and for each line that represents an
|
|
75
|
+
* assistant message with usage data, extracts token counts and computes
|
|
76
|
+
* the USD cost using the extended pricing model.
|
|
77
|
+
*
|
|
78
|
+
* @param sessionJsonlPath - Absolute path to the `.jsonl` file.
|
|
79
|
+
* @returns Array of cost events extracted from assistant messages.
|
|
80
|
+
*/
|
|
81
|
+
async function parseClaudeCodeSession(sessionJsonlPath) {
|
|
82
|
+
let content;
|
|
83
|
+
try {
|
|
84
|
+
content = await node_fs_1.promises.readFile(sessionJsonlPath, "utf-8");
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const e = err;
|
|
88
|
+
if (e.code === "ENOENT")
|
|
89
|
+
return [];
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
const lines = content.split("\n");
|
|
93
|
+
const events = [];
|
|
94
|
+
for (const line of lines) {
|
|
95
|
+
const trimmed = line.trim();
|
|
96
|
+
if (!trimmed)
|
|
97
|
+
continue;
|
|
98
|
+
let entry;
|
|
99
|
+
try {
|
|
100
|
+
entry = JSON.parse(trimmed);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Malformed line — skip silently.
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (entry.type !== "assistant")
|
|
107
|
+
continue;
|
|
108
|
+
const usage = entry.message?.usage;
|
|
109
|
+
if (!usage)
|
|
110
|
+
continue;
|
|
111
|
+
const model = entry.message?.model ?? "unknown";
|
|
112
|
+
const inputTokens = usage.input_tokens ?? 0;
|
|
113
|
+
const outputTokens = usage.output_tokens ?? 0;
|
|
114
|
+
const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
|
|
115
|
+
const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
|
|
116
|
+
const cacheCreation5mTokens = usage.cache_creation?.ephemeral_5m_input_tokens ?? 0;
|
|
117
|
+
const cacheCreation1hTokens = usage.cache_creation?.ephemeral_1h_input_tokens ?? 0;
|
|
118
|
+
const costUsd = (0, types_1.calculateCostUsdExtended)(model, inputTokens, outputTokens, cacheCreation5mTokens, cacheCreation1hTokens, cacheReadTokens);
|
|
119
|
+
events.push({
|
|
120
|
+
model,
|
|
121
|
+
inputTokens,
|
|
122
|
+
outputTokens,
|
|
123
|
+
cacheCreationTokens,
|
|
124
|
+
cacheReadTokens,
|
|
125
|
+
cacheCreation5mTokens,
|
|
126
|
+
cacheCreation1hTokens,
|
|
127
|
+
serviceTier: usage.service_tier,
|
|
128
|
+
costUsd: costUsd ?? undefined,
|
|
129
|
+
timestamp: entry.timestamp,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return events;
|
|
133
|
+
}
|
|
134
|
+
// ============================================================================
|
|
135
|
+
// Session + subagent parser
|
|
136
|
+
// ============================================================================
|
|
137
|
+
/**
|
|
138
|
+
* Parse a Claude Code session JSONL file and all associated subagent files.
|
|
139
|
+
*
|
|
140
|
+
* Subagent files live at `<sessionDir>/subagents/agent-*.jsonl` where
|
|
141
|
+
* `<sessionDir>` is derived by stripping the `.jsonl` extension from the
|
|
142
|
+
* main session file path.
|
|
143
|
+
*
|
|
144
|
+
* @param sessionJsonlPath - Absolute path to the main session `.jsonl` file.
|
|
145
|
+
* @returns Merged array of cost events from the main session and all subagents.
|
|
146
|
+
*/
|
|
147
|
+
async function parseClaudeCodeSessionWithSubagents(sessionJsonlPath) {
|
|
148
|
+
// Parse main session file.
|
|
149
|
+
const mainEvents = await parseClaudeCodeSession(sessionJsonlPath);
|
|
150
|
+
// Derive the session directory (same name without .jsonl extension).
|
|
151
|
+
const sessionDir = sessionJsonlPath.replace(/\.jsonl$/, "");
|
|
152
|
+
const subagentsDir = path.join(sessionDir, "subagents");
|
|
153
|
+
let subagentFiles;
|
|
154
|
+
try {
|
|
155
|
+
const entries = await node_fs_1.promises.readdir(subagentsDir);
|
|
156
|
+
subagentFiles = entries
|
|
157
|
+
.filter((f) => f.startsWith("agent-") && f.endsWith(".jsonl"))
|
|
158
|
+
.map((f) => path.join(subagentsDir, f));
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
const e = err;
|
|
162
|
+
if (e.code === "ENOENT")
|
|
163
|
+
return mainEvents;
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
// Parse all subagent files and merge.
|
|
167
|
+
const subagentResults = await Promise.all(subagentFiles.map((f) => parseClaudeCodeSession(f)));
|
|
168
|
+
const allEvents = [...mainEvents];
|
|
169
|
+
for (const sub of subagentResults) {
|
|
170
|
+
allEvents.push(...sub);
|
|
171
|
+
}
|
|
172
|
+
return allEvents;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Aggregate usage data across an array of cost events.
|
|
176
|
+
*
|
|
177
|
+
* Sums token counts and costs, producing both overall totals and a
|
|
178
|
+
* per-model breakdown.
|
|
179
|
+
*
|
|
180
|
+
* @param events - Array of cost events (e.g. from {@link parseClaudeCodeSessionWithSubagents}).
|
|
181
|
+
* @returns Aggregated usage summary with per-model breakdown.
|
|
182
|
+
*/
|
|
183
|
+
function aggregateUsageData(events) {
|
|
184
|
+
const result = {
|
|
185
|
+
eventCount: 0,
|
|
186
|
+
totalInputTokens: 0,
|
|
187
|
+
totalOutputTokens: 0,
|
|
188
|
+
totalCacheCreationTokens: 0,
|
|
189
|
+
totalCacheReadTokens: 0,
|
|
190
|
+
totalCacheCreation5mTokens: 0,
|
|
191
|
+
totalCacheCreation1hTokens: 0,
|
|
192
|
+
totalCostUsd: 0,
|
|
193
|
+
byModel: {},
|
|
194
|
+
};
|
|
195
|
+
for (const event of events) {
|
|
196
|
+
result.eventCount += 1;
|
|
197
|
+
result.totalInputTokens += event.inputTokens;
|
|
198
|
+
result.totalOutputTokens += event.outputTokens;
|
|
199
|
+
result.totalCacheCreationTokens += event.cacheCreationTokens;
|
|
200
|
+
result.totalCacheReadTokens += event.cacheReadTokens;
|
|
201
|
+
result.totalCacheCreation5mTokens += event.cacheCreation5mTokens;
|
|
202
|
+
result.totalCacheCreation1hTokens += event.cacheCreation1hTokens;
|
|
203
|
+
result.totalCostUsd += event.costUsd ?? 0;
|
|
204
|
+
// Per-model breakdown.
|
|
205
|
+
const model = event.model ?? "unknown";
|
|
206
|
+
if (!result.byModel[model]) {
|
|
207
|
+
result.byModel[model] = {
|
|
208
|
+
model,
|
|
209
|
+
eventCount: 0,
|
|
210
|
+
inputTokens: 0,
|
|
211
|
+
outputTokens: 0,
|
|
212
|
+
cacheCreationTokens: 0,
|
|
213
|
+
cacheReadTokens: 0,
|
|
214
|
+
costUsd: 0,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const ms = result.byModel[model];
|
|
218
|
+
ms.eventCount += 1;
|
|
219
|
+
ms.inputTokens += event.inputTokens;
|
|
220
|
+
ms.outputTokens += event.outputTokens;
|
|
221
|
+
ms.cacheCreationTokens += event.cacheCreationTokens;
|
|
222
|
+
ms.cacheReadTokens += event.cacheReadTokens;
|
|
223
|
+
ms.costUsd += event.costUsd ?? 0;
|
|
224
|
+
}
|
|
225
|
+
// Round totals to 6 decimal places to avoid floating-point drift.
|
|
226
|
+
result.totalCostUsd =
|
|
227
|
+
Math.round(result.totalCostUsd * 1_000_000) / 1_000_000;
|
|
228
|
+
for (const ms of Object.values(result.byModel)) {
|
|
229
|
+
ms.costUsd = Math.round(ms.costUsd * 1_000_000) / 1_000_000;
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost data collector for Babysitter runs.
|
|
3
|
+
*
|
|
4
|
+
* Bridges the Claude Code JSONL parser with the run journal: parses a
|
|
5
|
+
* session file (including subagent files), then writes COST_TRACKED events
|
|
6
|
+
* to the run's journal for later aggregation and reporting.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Parse a Claude Code session (main + subagents) and write COST_TRACKED
|
|
10
|
+
* events into the run journal.
|
|
11
|
+
*
|
|
12
|
+
* Each assistant message with usage data becomes a separate journal event,
|
|
13
|
+
* preserving the full token breakdown for fine-grained cost analysis.
|
|
14
|
+
*
|
|
15
|
+
* @param runDir - Absolute path to the run directory (e.g. `.a5c/runs/<runId>`).
|
|
16
|
+
* @param sessionJsonlPath - Absolute path to the main session `.jsonl` file.
|
|
17
|
+
* @returns The number of COST_TRACKED events written to the journal.
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectCostDataForRun(runDir: string, sessionJsonlPath: string): Promise<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the Claude Code projects directory path for a given session ID.
|
|
22
|
+
*
|
|
23
|
+
* Claude Code stores session JSONL files at:
|
|
24
|
+
* ```
|
|
25
|
+
* ~/.claude/projects/<project-slug>/<sessionId>.jsonl
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Since we don't always know the project slug, this function returns the
|
|
29
|
+
* base Claude Code projects directory. The caller can then search for the
|
|
30
|
+
* session file within the project subdirectories.
|
|
31
|
+
*
|
|
32
|
+
* If a workspace path is provided, the project slug is derived using Claude
|
|
33
|
+
* Code's path-encoding convention (forward slashes and colons replaced with
|
|
34
|
+
* dashes, prefixed with the drive letter on Windows).
|
|
35
|
+
*
|
|
36
|
+
* @param sessionId - The Claude Code session UUID.
|
|
37
|
+
* @param workspacePath - Optional absolute workspace path to derive the project slug.
|
|
38
|
+
* @returns Absolute path to the session `.jsonl` file (when workspace is
|
|
39
|
+
* provided) or the Claude Code projects directory (when workspace is omitted).
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveClaudeCodeSessionDir(sessionId: string, workspacePath?: string): string;
|
|
42
|
+
//# sourceMappingURL=collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../src/cost/collector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,CAkBR"}
|