@greppleai/grip 0.0.0-stage → 0.1.3
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/CHANGELOG.md +115 -0
- package/README.md +731 -2
- package/dist/bun/cli.d.ts +3 -0
- package/dist/bun/cli.d.ts.map +1 -0
- package/dist/bun/cli.js +13 -0
- package/dist/bun/cli.js.map +1 -0
- package/dist/bun/embedded-assets.d.ts +3 -0
- package/dist/bun/embedded-assets.d.ts.map +1 -0
- package/dist/bun/embedded-assets.js +52 -0
- package/dist/bun/embedded-assets.js.map +1 -0
- package/dist/bun/register-bedrock.d.ts +2 -0
- package/dist/bun/register-bedrock.d.ts.map +1 -0
- package/dist/bun/register-bedrock.js +4 -0
- package/dist/bun/register-bedrock.js.map +1 -0
- package/dist/bun/restore-sandbox-env.d.ts +13 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +32 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/cli/args.d.ts +70 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +442 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config-selector.d.ts +14 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +31 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +60 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/initial-message.d.ts +18 -0
- package/dist/cli/initial-message.d.ts.map +1 -0
- package/dist/cli/initial-message.js +22 -0
- package/dist/cli/initial-message.js.map +1 -0
- package/dist/cli/list-models.d.ts +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +98 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/session-picker.d.ts +9 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +35 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +14 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +82 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +406 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session.d.ts +970 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +5191 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +150 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +557 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +26 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +99 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +83 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +220 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +65 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +550 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/compression-detection-ledger.d.ts +34 -0
- package/dist/core/compaction/compression-detection-ledger.d.ts.map +1 -0
- package/dist/core/compaction/compression-detection-ledger.js +52 -0
- package/dist/core/compaction/compression-detection-ledger.js.map +1 -0
- package/dist/core/compaction/compression-detector.d.ts +71 -0
- package/dist/core/compaction/compression-detector.d.ts.map +1 -0
- package/dist/core/compaction/compression-detector.js +407 -0
- package/dist/core/compaction/compression-detector.js.map +1 -0
- package/dist/core/compaction/compression-economics.d.ts +55 -0
- package/dist/core/compaction/compression-economics.d.ts.map +1 -0
- package/dist/core/compaction/compression-economics.js +151 -0
- package/dist/core/compaction/compression-economics.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +28 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +165 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/defaults.d.ts +3 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +18 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +75 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +245 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +21 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +230 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +1066 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1864 -0
- package/dist/core/export-html/tool-renderer.d.ts +32 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +108 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +78 -0
- package/dist/core/extensions/loader.d.ts +24 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +613 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +160 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +962 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1311 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +51 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +20 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +22 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +52 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +318 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/grip-agent.d.ts +240 -0
- package/dist/core/grip-agent.d.ts.map +1 -0
- package/dist/core/grip-agent.js +1243 -0
- package/dist/core/grip-agent.js.map +1 -0
- package/dist/core/grip-manifest.d.ts +9 -0
- package/dist/core/grip-manifest.d.ts.map +1 -0
- package/dist/core/grip-manifest.js +25 -0
- package/dist/core/grip-manifest.js.map +1 -0
- package/dist/core/hooks/aggregate.d.ts +5 -0
- package/dist/core/hooks/aggregate.d.ts.map +1 -0
- package/dist/core/hooks/aggregate.js +226 -0
- package/dist/core/hooks/aggregate.js.map +1 -0
- package/dist/core/hooks/config.d.ts +14 -0
- package/dist/core/hooks/config.d.ts.map +1 -0
- package/dist/core/hooks/config.js +372 -0
- package/dist/core/hooks/config.js.map +1 -0
- package/dist/core/hooks/executor.d.ts +12 -0
- package/dist/core/hooks/executor.d.ts.map +1 -0
- package/dist/core/hooks/executor.js +708 -0
- package/dist/core/hooks/executor.js.map +1 -0
- package/dist/core/hooks/index.d.ts +9 -0
- package/dist/core/hooks/index.d.ts.map +1 -0
- package/dist/core/hooks/index.js +14 -0
- package/dist/core/hooks/index.js.map +1 -0
- package/dist/core/hooks/matcher.d.ts +10 -0
- package/dist/core/hooks/matcher.d.ts.map +1 -0
- package/dist/core/hooks/matcher.js +70 -0
- package/dist/core/hooks/matcher.js.map +1 -0
- package/dist/core/hooks/trust-store.d.ts +38 -0
- package/dist/core/hooks/trust-store.d.ts.map +1 -0
- package/dist/core/hooks/trust-store.js +167 -0
- package/dist/core/hooks/trust-store.js.map +1 -0
- package/dist/core/hooks/types.d.ts +234 -0
- package/dist/core/hooks/types.d.ts.map +1 -0
- package/dist/core/hooks/types.js +52 -0
- package/dist/core/hooks/types.js.map +1 -0
- package/dist/core/http-dispatcher.d.ts +21 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -0
- package/dist/core/http-dispatcher.js +82 -0
- package/dist/core/http-dispatcher.js.map +1 -0
- package/dist/core/instruction-resource-loader.d.ts +81 -0
- package/dist/core/instruction-resource-loader.d.ts.map +1 -0
- package/dist/core/instruction-resource-loader.js +574 -0
- package/dist/core/instruction-resource-loader.js.map +1 -0
- package/dist/core/keybindings.d.ts +399 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +299 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/lsp/abort.d.ts +3 -0
- package/dist/core/lsp/abort.d.ts.map +1 -0
- package/dist/core/lsp/abort.js +28 -0
- package/dist/core/lsp/abort.js.map +1 -0
- package/dist/core/lsp/client.d.ts +108 -0
- package/dist/core/lsp/client.d.ts.map +1 -0
- package/dist/core/lsp/client.js +586 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/config-loader.d.ts +44 -0
- package/dist/core/lsp/config-loader.d.ts.map +1 -0
- package/dist/core/lsp/config-loader.js +223 -0
- package/dist/core/lsp/config-loader.js.map +1 -0
- package/dist/core/lsp/config.d.ts +134 -0
- package/dist/core/lsp/config.d.ts.map +1 -0
- package/dist/core/lsp/config.js +682 -0
- package/dist/core/lsp/config.js.map +1 -0
- package/dist/core/lsp/diagnostics.d.ts +18 -0
- package/dist/core/lsp/diagnostics.d.ts.map +1 -0
- package/dist/core/lsp/diagnostics.js +311 -0
- package/dist/core/lsp/diagnostics.js.map +1 -0
- package/dist/core/lsp/file-sync.d.ts +58 -0
- package/dist/core/lsp/file-sync.d.ts.map +1 -0
- package/dist/core/lsp/file-sync.js +432 -0
- package/dist/core/lsp/file-sync.js.map +1 -0
- package/dist/core/lsp/integration.d.ts +62 -0
- package/dist/core/lsp/integration.d.ts.map +1 -0
- package/dist/core/lsp/integration.js +145 -0
- package/dist/core/lsp/integration.js.map +1 -0
- package/dist/core/lsp/language-map.d.ts +54 -0
- package/dist/core/lsp/language-map.d.ts.map +1 -0
- package/dist/core/lsp/language-map.js +300 -0
- package/dist/core/lsp/language-map.js.map +1 -0
- package/dist/core/lsp/manager.d.ts +120 -0
- package/dist/core/lsp/manager.d.ts.map +1 -0
- package/dist/core/lsp/manager.js +636 -0
- package/dist/core/lsp/manager.js.map +1 -0
- package/dist/core/lsp/navigation.d.ts +32 -0
- package/dist/core/lsp/navigation.d.ts.map +1 -0
- package/dist/core/lsp/navigation.js +327 -0
- package/dist/core/lsp/navigation.js.map +1 -0
- package/dist/core/lsp/portable-path.d.ts +18 -0
- package/dist/core/lsp/portable-path.d.ts.map +1 -0
- package/dist/core/lsp/portable-path.js +83 -0
- package/dist/core/lsp/portable-path.js.map +1 -0
- package/dist/core/lsp/refactor.d.ts +32 -0
- package/dist/core/lsp/refactor.d.ts.map +1 -0
- package/dist/core/lsp/refactor.js +519 -0
- package/dist/core/lsp/refactor.js.map +1 -0
- package/dist/core/lsp/transport.d.ts +39 -0
- package/dist/core/lsp/transport.d.ts.map +1 -0
- package/dist/core/lsp/transport.js +261 -0
- package/dist/core/lsp/transport.js.map +1 -0
- package/dist/core/messages.d.ts +34 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +140 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-registry.d.ts +148 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +812 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +115 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +498 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/output-guard.d.ts +7 -0
- package/dist/core/output-guard.d.ts.map +1 -0
- package/dist/core/output-guard.js +89 -0
- package/dist/core/output-guard.js.map +1 -0
- package/dist/core/package-manager.d.ts +209 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +2341 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +57 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +353 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/provider-display-names.d.ts +2 -0
- package/dist/core/provider-display-names.d.ts.map +1 -0
- package/dist/core/provider-display-names.js +33 -0
- package/dist/core/provider-display-names.js.map +1 -0
- package/dist/core/remote-workspace-protocol/contract.d.ts +465 -0
- package/dist/core/remote-workspace-protocol/contract.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/contract.js +825 -0
- package/dist/core/remote-workspace-protocol/contract.js.map +1 -0
- package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts +16 -0
- package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/guest-shared-client.js +54 -0
- package/dist/core/remote-workspace-protocol/guest-shared-client.js.map +1 -0
- package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts +23 -0
- package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js +112 -0
- package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js.map +1 -0
- package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts +30 -0
- package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/guest-shared-uplink.js +243 -0
- package/dist/core/remote-workspace-protocol/guest-shared-uplink.js.map +1 -0
- package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts +3 -0
- package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/lima-owner-directory.js +31 -0
- package/dist/core/remote-workspace-protocol/lima-owner-directory.js.map +1 -0
- package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts +9 -0
- package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/lima-owner-lock.js +89 -0
- package/dist/core/remote-workspace-protocol/lima-owner-lock.js.map +1 -0
- package/dist/core/remote-workspace-protocol/session.d.ts +249 -0
- package/dist/core/remote-workspace-protocol/session.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/session.js +1842 -0
- package/dist/core/remote-workspace-protocol/session.js.map +1 -0
- package/dist/core/remote-workspace-protocol/shared-transport.d.ts +71 -0
- package/dist/core/remote-workspace-protocol/shared-transport.d.ts.map +1 -0
- package/dist/core/remote-workspace-protocol/shared-transport.js +68 -0
- package/dist/core/remote-workspace-protocol/shared-transport.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +32 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +257 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +200 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +1209 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/rules.d.ts +40 -0
- package/dist/core/rules.d.ts.map +1 -0
- package/dist/core/rules.js +57 -0
- package/dist/core/rules.js.map +1 -0
- package/dist/core/sandbox/command.d.ts +25 -0
- package/dist/core/sandbox/command.d.ts.map +1 -0
- package/dist/core/sandbox/command.js +102 -0
- package/dist/core/sandbox/command.js.map +1 -0
- package/dist/core/sandbox/config.d.ts +91 -0
- package/dist/core/sandbox/config.d.ts.map +1 -0
- package/dist/core/sandbox/config.js +88 -0
- package/dist/core/sandbox/config.js.map +1 -0
- package/dist/core/sandbox/lima-guest-binary.d.ts +11 -0
- package/dist/core/sandbox/lima-guest-binary.d.ts.map +1 -0
- package/dist/core/sandbox/lima-guest-binary.js +140 -0
- package/dist/core/sandbox/lima-guest-binary.js.map +1 -0
- package/dist/core/sandbox/lima.d.ts +57 -0
- package/dist/core/sandbox/lima.d.ts.map +1 -0
- package/dist/core/sandbox/lima.js +716 -0
- package/dist/core/sandbox/lima.js.map +1 -0
- package/dist/core/sandbox/shared-lima-roots.d.ts +11 -0
- package/dist/core/sandbox/shared-lima-roots.d.ts.map +1 -0
- package/dist/core/sandbox/shared-lima-roots.js +25 -0
- package/dist/core/sandbox/shared-lima-roots.js.map +1 -0
- package/dist/core/sandbox/update-shared-guest-binary.d.ts +8 -0
- package/dist/core/sandbox/update-shared-guest-binary.d.ts.map +1 -0
- package/dist/core/sandbox/update-shared-guest-binary.js +100 -0
- package/dist/core/sandbox/update-shared-guest-binary.js.map +1 -0
- package/dist/core/session/constants.d.ts +2 -0
- package/dist/core/session/constants.d.ts.map +1 -0
- package/dist/core/session/constants.js +2 -0
- package/dist/core/session/constants.js.map +1 -0
- package/dist/core/session/context-metadata.d.ts +5 -0
- package/dist/core/session/context-metadata.d.ts.map +1 -0
- package/dist/core/session/context-metadata.js +55 -0
- package/dist/core/session/context-metadata.js.map +1 -0
- package/dist/core/session/context.d.ts +14 -0
- package/dist/core/session/context.d.ts.map +1 -0
- package/dist/core/session/context.js +117 -0
- package/dist/core/session/context.js.map +1 -0
- package/dist/core/session/ids.d.ts +9 -0
- package/dist/core/session/ids.d.ts.map +1 -0
- package/dist/core/session/ids.js +21 -0
- package/dist/core/session/ids.js.map +1 -0
- package/dist/core/session/in-memory-session-manager.d.ts +17 -0
- package/dist/core/session/in-memory-session-manager.d.ts.map +1 -0
- package/dist/core/session/in-memory-session-manager.js +40 -0
- package/dist/core/session/in-memory-session-manager.js.map +1 -0
- package/dist/core/session/in-memory-session.d.ts +7 -0
- package/dist/core/session/in-memory-session.d.ts.map +1 -0
- package/dist/core/session/in-memory-session.js +11 -0
- package/dist/core/session/in-memory-session.js.map +1 -0
- package/dist/core/session/jsonl-errors.d.ts +36 -0
- package/dist/core/session/jsonl-errors.d.ts.map +1 -0
- package/dist/core/session/jsonl-errors.js +49 -0
- package/dist/core/session/jsonl-errors.js.map +1 -0
- package/dist/core/session/jsonl-helpers.d.ts +20 -0
- package/dist/core/session/jsonl-helpers.d.ts.map +1 -0
- package/dist/core/session/jsonl-helpers.js +21 -0
- package/dist/core/session/jsonl-helpers.js.map +1 -0
- package/dist/core/session/local-session-manager.d.ts +30 -0
- package/dist/core/session/local-session-manager.d.ts.map +1 -0
- package/dist/core/session/local-session-manager.js +205 -0
- package/dist/core/session/local-session-manager.js.map +1 -0
- package/dist/core/session/local-session.d.ts +9 -0
- package/dist/core/session/local-session.d.ts.map +1 -0
- package/dist/core/session/local-session.js +15 -0
- package/dist/core/session/local-session.js.map +1 -0
- package/dist/core/session/migrations.d.ts +11 -0
- package/dist/core/session/migrations.d.ts.map +1 -0
- package/dist/core/session/migrations.js +78 -0
- package/dist/core/session/migrations.js.map +1 -0
- package/dist/core/session/remote-session-client.d.ts +83 -0
- package/dist/core/session/remote-session-client.d.ts.map +1 -0
- package/dist/core/session/remote-session-client.js +224 -0
- package/dist/core/session/remote-session-client.js.map +1 -0
- package/dist/core/session/remote-session-manager.d.ts +32 -0
- package/dist/core/session/remote-session-manager.d.ts.map +1 -0
- package/dist/core/session/remote-session-manager.js +124 -0
- package/dist/core/session/remote-session-manager.js.map +1 -0
- package/dist/core/session/remote-session.d.ts +20 -0
- package/dist/core/session/remote-session.d.ts.map +1 -0
- package/dist/core/session/remote-session.js +33 -0
- package/dist/core/session/remote-session.js.map +1 -0
- package/dist/core/session/session-manager.d.ts +18 -0
- package/dist/core/session/session-manager.d.ts.map +1 -0
- package/dist/core/session/session-manager.js +2 -0
- package/dist/core/session/session-manager.js.map +1 -0
- package/dist/core/session/session.d.ts +140 -0
- package/dist/core/session/session.d.ts.map +1 -0
- package/dist/core/session/session.js +461 -0
- package/dist/core/session/session.js.map +1 -0
- package/dist/core/session/stores/in-memory-session-store.d.ts +39 -0
- package/dist/core/session/stores/in-memory-session-store.d.ts.map +1 -0
- package/dist/core/session/stores/in-memory-session-store.js +168 -0
- package/dist/core/session/stores/in-memory-session-store.js.map +1 -0
- package/dist/core/session/stores/jsonl-session-store.d.ts +97 -0
- package/dist/core/session/stores/jsonl-session-store.d.ts.map +1 -0
- package/dist/core/session/stores/jsonl-session-store.js +1140 -0
- package/dist/core/session/stores/jsonl-session-store.js.map +1 -0
- package/dist/core/session/stores/remote-session-store.d.ts +44 -0
- package/dist/core/session/stores/remote-session-store.d.ts.map +1 -0
- package/dist/core/session/stores/remote-session-store.js +159 -0
- package/dist/core/session/stores/remote-session-store.js.map +1 -0
- package/dist/core/session/stores/session-store.d.ts +42 -0
- package/dist/core/session/stores/session-store.d.ts.map +1 -0
- package/dist/core/session/stores/session-store.js +2 -0
- package/dist/core/session/stores/session-store.js.map +1 -0
- package/dist/core/session/types.d.ts +141 -0
- package/dist/core/session/types.d.ts.map +1 -0
- package/dist/core/session/types.js +2 -0
- package/dist/core/session/types.js.map +1 -0
- package/dist/core/session/usage-ledger.d.ts +18 -0
- package/dist/core/session/usage-ledger.d.ts.map +1 -0
- package/dist/core/session/usage-ledger.js +68 -0
- package/dist/core/session/usage-ledger.js.map +1 -0
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +38 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/settings-manager.d.ts +314 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +991 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +40 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +57 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +15 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +36 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/source-info.d.ts +26 -0
- package/dist/core/source-info.d.ts.map +1 -0
- package/dist/core/source-info.js +27 -0
- package/dist/core/source-info.js.map +1 -0
- package/dist/core/system-prompt.d.ts +32 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +131 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/telemetry.d.ts +3 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +9 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/core/timings.d.ts +10 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +41 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +51 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +321 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/compress-context.d.ts +27 -0
- package/dist/core/tools/compress-context.d.ts.map +1 -0
- package/dist/core/tools/compress-context.js +142 -0
- package/dist/core/tools/compress-context.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +82 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +327 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +50 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +324 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +8 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-queue.js +69 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/core/tools/find.d.ts +22 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +268 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +27 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +332 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/hash-store.d.ts +12 -0
- package/dist/core/tools/hash-store.d.ts.map +1 -0
- package/dist/core/tools/hash-store.js +48 -0
- package/dist/core/tools/hash-store.js.map +1 -0
- package/dist/core/tools/hashline/apply.d.ts +40 -0
- package/dist/core/tools/hashline/apply.d.ts.map +1 -0
- package/dist/core/tools/hashline/apply.js +261 -0
- package/dist/core/tools/hashline/apply.js.map +1 -0
- package/dist/core/tools/hashline/hash.d.ts +56 -0
- package/dist/core/tools/hashline/hash.d.ts.map +1 -0
- package/dist/core/tools/hashline/hash.js +196 -0
- package/dist/core/tools/hashline/hash.js.map +1 -0
- package/dist/core/tools/hashline/parse.d.ts +8 -0
- package/dist/core/tools/hashline/parse.d.ts.map +1 -0
- package/dist/core/tools/hashline/parse.js +41 -0
- package/dist/core/tools/hashline/parse.js.map +1 -0
- package/dist/core/tools/hashline/resolve.d.ts +51 -0
- package/dist/core/tools/hashline/resolve.d.ts.map +1 -0
- package/dist/core/tools/hashline/resolve.js +187 -0
- package/dist/core/tools/hashline/resolve.js.map +1 -0
- package/dist/core/tools/hashline-utils.d.ts +6 -0
- package/dist/core/tools/hashline-utils.d.ts.map +1 -0
- package/dist/core/tools/hashline-utils.js +23 -0
- package/dist/core/tools/hashline-utils.js.map +1 -0
- package/dist/core/tools/index.d.ts +36 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +141 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +21 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +156 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/operations.d.ts +212 -0
- package/dist/core/tools/operations.d.ts.map +1 -0
- package/dist/core/tools/operations.js +793 -0
- package/dist/core/tools/operations.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +54 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +184 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +9 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +99 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +32 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +318 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/render-utils.d.ts +33 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -0
- package/dist/core/tools/render-utils.js +61 -0
- package/dist/core/tools/render-utils.js.map +1 -0
- package/dist/core/tools/replace-diff.d.ts +16 -0
- package/dist/core/tools/replace-diff.d.ts.map +1 -0
- package/dist/core/tools/replace-diff.js +117 -0
- package/dist/core/tools/replace-diff.js.map +1 -0
- package/dist/core/tools/replace-normalize.d.ts +2 -0
- package/dist/core/tools/replace-normalize.d.ts.map +1 -0
- package/dist/core/tools/replace-normalize.js +73 -0
- package/dist/core/tools/replace-normalize.js.map +1 -0
- package/dist/core/tools/replace-render.d.ts +51 -0
- package/dist/core/tools/replace-render.d.ts.map +1 -0
- package/dist/core/tools/replace-render.js +162 -0
- package/dist/core/tools/replace-render.js.map +1 -0
- package/dist/core/tools/runtime.d.ts +2 -0
- package/dist/core/tools/runtime.d.ts.map +1 -0
- package/dist/core/tools/runtime.js +6 -0
- package/dist/core/tools/runtime.js.map +1 -0
- package/dist/core/tools/session-history.d.ts +55 -0
- package/dist/core/tools/session-history.d.ts.map +1 -0
- package/dist/core/tools/session-history.js +649 -0
- package/dist/core/tools/session-history.js.map +1 -0
- package/dist/core/tools/subagent-agents.d.ts +29 -0
- package/dist/core/tools/subagent-agents.d.ts.map +1 -0
- package/dist/core/tools/subagent-agents.js +223 -0
- package/dist/core/tools/subagent-agents.js.map +1 -0
- package/dist/core/tools/subagent.d.ts +185 -0
- package/dist/core/tools/subagent.d.ts.map +1 -0
- package/dist/core/tools/subagent.js +1309 -0
- package/dist/core/tools/subagent.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.js +34 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +39 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +215 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/websearch.d.ts +33 -0
- package/dist/core/tools/websearch.d.ts.map +1 -0
- package/dist/core/tools/websearch.js +341 -0
- package/dist/core/tools/websearch.js.map +1 -0
- package/dist/core/tools/workspace-tool-host.d.ts +102 -0
- package/dist/core/tools/workspace-tool-host.d.ts.map +1 -0
- package/dist/core/tools/workspace-tool-host.js +348 -0
- package/dist/core/tools/workspace-tool-host.js.map +1 -0
- package/dist/core/tools/write.d.ts +16 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +204 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/core/workspace-identity.d.ts +7 -0
- package/dist/core/workspace-identity.d.ts.map +1 -0
- package/dist/core/workspace-identity.js +2 -0
- package/dist/core/workspace-identity.js.map +1 -0
- package/dist/daemon/activity-budget.d.ts +10 -0
- package/dist/daemon/activity-budget.d.ts.map +1 -0
- package/dist/daemon/activity-budget.js +34 -0
- package/dist/daemon/activity-budget.js.map +1 -0
- package/dist/daemon/command.d.ts +6 -0
- package/dist/daemon/command.d.ts.map +1 -0
- package/dist/daemon/command.js +58 -0
- package/dist/daemon/command.js.map +1 -0
- package/dist/daemon/config.d.ts +45 -0
- package/dist/daemon/config.d.ts.map +1 -0
- package/dist/daemon/config.js +319 -0
- package/dist/daemon/config.js.map +1 -0
- package/dist/daemon/help.d.ts +2 -0
- package/dist/daemon/help.d.ts.map +1 -0
- package/dist/daemon/help.js +42 -0
- package/dist/daemon/help.js.map +1 -0
- package/dist/daemon/lsp-config.d.ts +4 -0
- package/dist/daemon/lsp-config.d.ts.map +1 -0
- package/dist/daemon/lsp-config.js +155 -0
- package/dist/daemon/lsp-config.js.map +1 -0
- package/dist/daemon/outbound-budget.d.ts +10 -0
- package/dist/daemon/outbound-budget.d.ts.map +1 -0
- package/dist/daemon/outbound-budget.js +30 -0
- package/dist/daemon/outbound-budget.js.map +1 -0
- package/dist/daemon/security.d.ts +19 -0
- package/dist/daemon/security.d.ts.map +1 -0
- package/dist/daemon/security.js +177 -0
- package/dist/daemon/security.js.map +1 -0
- package/dist/daemon/server.d.ts +20 -0
- package/dist/daemon/server.d.ts.map +1 -0
- package/dist/daemon/server.js +480 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/daemon/shared-connection.d.ts +33 -0
- package/dist/daemon/shared-connection.d.ts.map +1 -0
- package/dist/daemon/shared-connection.js +271 -0
- package/dist/daemon/shared-connection.js.map +1 -0
- package/dist/daemon/shared-revision.d.ts +5 -0
- package/dist/daemon/shared-revision.d.ts.map +1 -0
- package/dist/daemon/shared-revision.js +61 -0
- package/dist/daemon/shared-revision.js.map +1 -0
- package/dist/daemon/shared-roots.d.ts +9 -0
- package/dist/daemon/shared-roots.d.ts.map +1 -0
- package/dist/daemon/shared-roots.js +33 -0
- package/dist/daemon/shared-roots.js.map +1 -0
- package/dist/daemon/workspace-runtime.d.ts +46 -0
- package/dist/daemon/workspace-runtime.d.ts.map +1 -0
- package/dist/daemon/workspace-runtime.js +705 -0
- package/dist/daemon/workspace-runtime.js.map +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +39 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +765 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +35 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +412 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +30 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +159 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +36 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +173 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +18 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +54 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +17 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +45 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +17 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +46 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +74 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +514 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +25 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +85 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +20 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +81 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +118 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +22 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +128 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +61 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +26 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +83 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +36 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +227 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/hook-execution.d.ts +19 -0
- package/dist/modes/interactive/components/hook-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/hook-execution.js +185 -0
- package/dist/modes/interactive/components/hook-execution.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +36 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +55 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +176 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts +4 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/mermaid.d.ts +14 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +228 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/message-card.d.ts +9 -0
- package/dist/modes/interactive/components/message-card.d.ts.map +1 -0
- package/dist/modes/interactive/components/message-card.js +24 -0
- package/dist/modes/interactive/components/message-card.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +52 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +296 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +33 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +165 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +50 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +300 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +144 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +108 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +835 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +81 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +455 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +39 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +18 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +48 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +50 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +51 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +67 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +312 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +127 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +1098 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +114 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +16 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +50 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +554 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +5870 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -0
- package/dist/modes/interactive/theme/dark.json +86 -0
- package/dist/modes/interactive/theme/light.json +85 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +109 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +1040 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/json-event.d.ts +28 -0
- package/dist/modes/json-event.d.ts.map +1 -0
- package/dist/modes/json-event.js +12 -0
- package/dist/modes/json-event.js.map +1 -0
- package/dist/modes/print-mode.d.ts +29 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +142 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/jsonl.d.ts +17 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +49 -0
- package/dist/modes/rpc/jsonl.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +321 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +755 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +963 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +652 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/package-manager-cli.d.ts +4 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +488 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/utils/ansi.d.ts +2 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +25 -0
- package/dist/utils/ansi.js.map +1 -0
- package/dist/utils/changelog.d.ts +23 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +74 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/child-process.d.ts +15 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +88 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +13 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +248 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +11 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -0
- package/dist/utils/clipboard-native.js +20 -0
- package/dist/utils/clipboard-native.js.map +1 -0
- package/dist/utils/clipboard.d.ts +4 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +171 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/deprecation.d.ts +4 -0
- package/dist/utils/deprecation.d.ts.map +1 -0
- package/dist/utils/deprecation.js +13 -0
- package/dist/utils/deprecation.js.map +1 -0
- package/dist/utils/directory-completions.d.ts +5 -0
- package/dist/utils/directory-completions.d.ts.map +1 -0
- package/dist/utils/directory-completions.js +64 -0
- package/dist/utils/directory-completions.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts +6 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -0
- package/dist/utils/exif-orientation.js +166 -0
- package/dist/utils/exif-orientation.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +26 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/fs-watch.d.ts +5 -0
- package/dist/utils/fs-watch.d.ts.map +1 -0
- package/dist/utils/fs-watch.js +25 -0
- package/dist/utils/fs-watch.js.map +1 -0
- package/dist/utils/git.d.ts +27 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +237 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/grip-user-agent.d.ts +2 -0
- package/dist/utils/grip-user-agent.d.ts.map +1 -0
- package/dist/utils/grip-user-agent.js +5 -0
- package/dist/utils/grip-user-agent.js.map +1 -0
- package/dist/utils/html.d.ts +7 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +40 -0
- package/dist/utils/html.js.map +1 -0
- package/dist/utils/image-convert.d.ts +12 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +43 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-process.d.ts +18 -0
- package/dist/utils/image-process.d.ts.map +1 -0
- package/dist/utils/image-process.js +83 -0
- package/dist/utils/image-process.js.map +1 -0
- package/dist/utils/image-resize-core.d.ts +30 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -0
- package/dist/utils/image-resize-core.js +133 -0
- package/dist/utils/image-resize-core.js.map +1 -0
- package/dist/utils/image-resize-worker.d.ts +2 -0
- package/dist/utils/image-resize-worker.d.ts.map +1 -0
- package/dist/utils/image-resize-worker.js +31 -0
- package/dist/utils/image-resize-worker.js.map +1 -0
- package/dist/utils/image-resize.d.ts +19 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +86 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/json.d.ts +3 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +7 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/mime.d.ts +3 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +110 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/open-browser.d.ts +9 -0
- package/dist/utils/open-browser.d.ts.map +1 -0
- package/dist/utils/open-browser.js +22 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/paths.d.ts +31 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +87 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/photon.d.ts +22 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +126 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/shell.d.ts +28 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +188 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/syntax-highlight.d.ts +12 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +125 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +5 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +329 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/dist/utils/version-check.d.ts +14 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +91 -0
- package/dist/utils/version-check.js.map +1 -0
- package/dist/utils/windows-self-update.d.ts +3 -0
- package/dist/utils/windows-self-update.d.ts.map +1 -0
- package/dist/utils/windows-self-update.js +77 -0
- package/dist/utils/windows-self-update.js.map +1 -0
- package/docs/compaction.md +408 -0
- package/docs/custom-provider.md +714 -0
- package/docs/daemon-architecture.md +399 -0
- package/docs/daemon.md +112 -0
- package/docs/development.md +72 -0
- package/docs/docs.json +164 -0
- package/docs/extensions.md +2745 -0
- package/docs/hooks.md +85 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +77 -0
- package/docs/json.md +89 -0
- package/docs/keybindings.md +230 -0
- package/docs/lsp.md +499 -0
- package/docs/migrating-to-grip.md +18 -0
- package/docs/models.md +496 -0
- package/docs/packages.md +228 -0
- package/docs/prompt-templates.md +88 -0
- package/docs/providers.md +251 -0
- package/docs/quickstart.md +159 -0
- package/docs/rpc.md +1492 -0
- package/docs/rules.md +117 -0
- package/docs/sandbox.md +104 -0
- package/docs/sdk.md +360 -0
- package/docs/session-format.md +414 -0
- package/docs/sessions.md +137 -0
- package/docs/settings.md +372 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +246 -0
- package/docs/terminal-setup.md +112 -0
- package/docs/termux.md +112 -0
- package/docs/themes.md +295 -0
- package/docs/tmux.md +61 -0
- package/docs/tui.md +918 -0
- package/docs/usage.md +304 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +29 -0
- package/examples/daemon-docker/Dockerfile +43 -0
- package/examples/daemon-docker/README.md +45 -0
- package/examples/extensions/README.md +208 -0
- package/examples/extensions/auto-commit-on-exit.ts +46 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +145 -0
- package/examples/extensions/built-in-tool-renderer.ts +259 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +82 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +131 -0
- package/examples/extensions/custom-footer.ts +79 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +707 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +402 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +104 -0
- package/examples/extensions/dirty-repo-guard.ts +59 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +133 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/dynamic-resources/RULES.md +8 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +79 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +16 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/git-merge-and-resolve.ts +125 -0
- package/examples/extensions/github-issue-autocomplete.ts +191 -0
- package/examples/extensions/handoff.ts +191 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +104 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +194 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +428 -0
- package/examples/extensions/modal-editor.ts +86 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +55 -0
- package/examples/extensions/overlay-qa-tests.ts +1374 -0
- package/examples/extensions/overlay-test.ts +171 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +346 -0
- package/examples/extensions/plan-mode/utils.ts +172 -0
- package/examples/extensions/preset.ts +426 -0
- package/examples/extensions/prompt-customizer.ts +97 -0
- package/examples/extensions/protected-paths.ts +29 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +125 -0
- package/examples/extensions/question.ts +294 -0
- package/examples/extensions/questionnaire.ts +459 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +320 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +381 -0
- package/examples/extensions/space-invaders.ts +597 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +175 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +126 -0
- package/examples/extensions/subagent/index.ts +1083 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +186 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1091 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +306 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +141 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +200 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/remote-session-server/README.md +71 -0
- package/examples/remote-session-server/server.ts +353 -0
- package/examples/rpc-extension-ui.ts +642 -0
- package/examples/sdk/01-minimal.ts +27 -0
- package/examples/sdk/02-custom-model.ts +54 -0
- package/examples/sdk/03-custom-prompt.ts +76 -0
- package/examples/sdk/04-skills.ts +60 -0
- package/examples/sdk/05-tools.ts +55 -0
- package/examples/sdk/06-extensions.ts +94 -0
- package/examples/sdk/07-context-files.ts +47 -0
- package/examples/sdk/08-prompt-templates.ts +56 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +50 -0
- package/examples/sdk/10-settings.ts +58 -0
- package/examples/sdk/11-sessions.ts +54 -0
- package/examples/sdk/12-full-control.ts +79 -0
- package/examples/sdk/13-session-runtime.ts +49 -0
- package/examples/sdk/README.md +94 -0
- package/npm-shrinkwrap.json +1878 -0
- package/package.json +101 -5
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { sessionEntryToContextMessages } from "../session/context.js";
|
|
2
|
+
import { estimateTokens } from "./compaction.js";
|
|
3
|
+
export const COMPRESSION_ECONOMICS_ENTRY_TYPE = "compression_economics";
|
|
4
|
+
export const COMPRESSION_SAVINGS_SNAPSHOT_TYPE = "compression_savings_snapshot";
|
|
5
|
+
function estimateRangeTokenCounts(entries, start, end) {
|
|
6
|
+
let source = 0;
|
|
7
|
+
let suffix = 0;
|
|
8
|
+
for (const [index, entry] of entries.entries()) {
|
|
9
|
+
for (const message of sessionEntryToContextMessages(entry)) {
|
|
10
|
+
const tokens = estimateTokens(message);
|
|
11
|
+
if (index >= start && index <= end)
|
|
12
|
+
source += tokens;
|
|
13
|
+
else if (index > end)
|
|
14
|
+
suffix += tokens;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return { source, suffix };
|
|
18
|
+
}
|
|
19
|
+
export function estimateCompressionEconomics(entries, startEntryId, endEntryId, model, summary, usingSubscription = false) {
|
|
20
|
+
const start = entries.findIndex((entry) => entry.id === startEntryId);
|
|
21
|
+
const end = entries.findIndex((entry) => entry.id === endEntryId);
|
|
22
|
+
if (start < 0 || end < start)
|
|
23
|
+
return undefined;
|
|
24
|
+
const { source: sourceTokens, suffix: suffixTokens } = estimateRangeTokenCounts(entries, start, end);
|
|
25
|
+
const summaryTokens = summary === undefined ? Math.ceil(sourceTokens / 4) : Math.ceil(summary.length / 4);
|
|
26
|
+
const removedTokens = Math.max(0, sourceTokens - summaryTokens);
|
|
27
|
+
const readRate = usingSubscription ? 0 : model.cost.cacheRead > 0 ? model.cost.cacheRead : model.cost.input;
|
|
28
|
+
// For automatic caching, a miss is ordinary input, not a separately reported cache write.
|
|
29
|
+
// Only the suffix after the changed range may lose its cached prefix; the earlier prefix is unchanged.
|
|
30
|
+
const oneTimeCost = !usingSubscription && model.cost.input > 0 && model.cost.output > 0
|
|
31
|
+
? (summaryTokens * (model.cost.input + model.cost.output) +
|
|
32
|
+
suffixTokens * Math.max(0, model.cost.input - readRate)) /
|
|
33
|
+
1_000_000
|
|
34
|
+
: null;
|
|
35
|
+
const savingPerRequest = (removedTokens * readRate) / 1_000_000;
|
|
36
|
+
return {
|
|
37
|
+
provider: model.provider,
|
|
38
|
+
modelId: model.id,
|
|
39
|
+
sourceTokens,
|
|
40
|
+
summaryTokens,
|
|
41
|
+
removedTokens,
|
|
42
|
+
readRate,
|
|
43
|
+
oneTimeCost,
|
|
44
|
+
breakEvenRequests: oneTimeCost != null && savingPerRequest > 0 ? Math.ceil(oneTimeCost / savingPerRequest) : null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function isEconomicsRecord(data) {
|
|
48
|
+
if (!data || typeof data !== "object")
|
|
49
|
+
return false;
|
|
50
|
+
const record = data;
|
|
51
|
+
return (record.version === 1 &&
|
|
52
|
+
typeof record.summaryEntryId === "string" &&
|
|
53
|
+
typeof record.provider === "string" &&
|
|
54
|
+
typeof record.modelId === "string" &&
|
|
55
|
+
typeof record.removedTokens === "number" &&
|
|
56
|
+
Number.isFinite(record.removedTokens) &&
|
|
57
|
+
record.removedTokens >= 0 &&
|
|
58
|
+
typeof record.readRate === "number" &&
|
|
59
|
+
Number.isFinite(record.readRate) &&
|
|
60
|
+
record.readRate >= 0 &&
|
|
61
|
+
(record.oneTimeCost === null || (typeof record.oneTimeCost === "number" && Number.isFinite(record.oneTimeCost))));
|
|
62
|
+
}
|
|
63
|
+
function isSavingsSnapshot(data) {
|
|
64
|
+
if (!data || typeof data !== "object")
|
|
65
|
+
return false;
|
|
66
|
+
const snapshot = data;
|
|
67
|
+
return (snapshot.version === 1 &&
|
|
68
|
+
Number.isFinite(snapshot.totalRemovedTokens) &&
|
|
69
|
+
Number.isFinite(snapshot.liveRemovedTokens) &&
|
|
70
|
+
Number.isFinite(snapshot.avoidedCost) &&
|
|
71
|
+
Number.isFinite(snapshot.oneTimeCost) &&
|
|
72
|
+
Number.isFinite(snapshot.pricedRequests) &&
|
|
73
|
+
Array.isArray(snapshot.activeSavings) &&
|
|
74
|
+
snapshot.activeSavings.every((saving) => !!saving &&
|
|
75
|
+
typeof saving === "object" &&
|
|
76
|
+
typeof saving.summaryEntryId === "string" &&
|
|
77
|
+
typeof saving.provider === "string" &&
|
|
78
|
+
typeof saving.modelId === "string" &&
|
|
79
|
+
Number.isFinite(saving.removedTokens) &&
|
|
80
|
+
Number.isFinite(saving.readRate)));
|
|
81
|
+
}
|
|
82
|
+
/** Approximate future requests to recover outstanding compression cost at two input-price scenarios. */
|
|
83
|
+
export function estimateCompressionCatchUp(branch, model, usingSubscription) {
|
|
84
|
+
const state = createCompressionSavingsSnapshot(branch);
|
|
85
|
+
const remaining = Math.max(0, state.oneTimeCost - state.avoidedCost);
|
|
86
|
+
const tokens = state.activeSavings.reduce((total, saving) => total + (saving.provider === model.provider && saving.modelId === model.id ? saving.removedTokens : 0), 0);
|
|
87
|
+
if (usingSubscription || !remaining || !tokens)
|
|
88
|
+
return { cachedTurns: null, newInputTurns: null };
|
|
89
|
+
return {
|
|
90
|
+
cachedTurns: model.cost.cacheRead > 0 ? Math.ceil((remaining * 1_000_000) / (tokens * model.cost.cacheRead)) : null,
|
|
91
|
+
newInputTurns: model.cost.input > 0 ? Math.ceil((remaining * 1_000_000) / (tokens * model.cost.input)) : null,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Replay persisted estimates in branch order, without counting archived or replayed provider calls twice. */
|
|
95
|
+
export function estimateCompressionSavings(branch) {
|
|
96
|
+
const { activeSavings: _activeSavings, version: _version, ...totals } = createCompressionSavingsSnapshot(branch);
|
|
97
|
+
return {
|
|
98
|
+
...totals,
|
|
99
|
+
netAvoidedCost: Math.max(0, totals.avoidedCost - totals.oneTimeCost),
|
|
100
|
+
remainingToBreakEven: Math.max(0, totals.oneTimeCost - totals.avoidedCost),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function creditAssistantRequest(state, provider, modelId) {
|
|
104
|
+
let saved = 0;
|
|
105
|
+
for (const saving of state.activeSavings) {
|
|
106
|
+
if (provider === saving.provider && modelId === saving.modelId)
|
|
107
|
+
saved += (saving.removedTokens * saving.readRate) / 1_000_000;
|
|
108
|
+
}
|
|
109
|
+
if (saved > 0) {
|
|
110
|
+
state.pricedRequests++;
|
|
111
|
+
state.avoidedCost += saved;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function applyEconomicsRecord(state, data) {
|
|
115
|
+
if (!isEconomicsRecord(data))
|
|
116
|
+
return;
|
|
117
|
+
const { summaryEntryId, provider, modelId, removedTokens, readRate, oneTimeCost } = data;
|
|
118
|
+
state.totalRemovedTokens += removedTokens;
|
|
119
|
+
state.liveRemovedTokens += removedTokens;
|
|
120
|
+
state.oneTimeCost += oneTimeCost ?? 0;
|
|
121
|
+
state.activeSavings.push({ summaryEntryId, provider, modelId, removedTokens, readRate });
|
|
122
|
+
}
|
|
123
|
+
export function createCompressionSavingsSnapshot(branch) {
|
|
124
|
+
let state = {
|
|
125
|
+
version: 1,
|
|
126
|
+
totalRemovedTokens: 0,
|
|
127
|
+
liveRemovedTokens: 0,
|
|
128
|
+
avoidedCost: 0,
|
|
129
|
+
oneTimeCost: 0,
|
|
130
|
+
pricedRequests: 0,
|
|
131
|
+
activeSavings: [],
|
|
132
|
+
};
|
|
133
|
+
for (const entry of branch) {
|
|
134
|
+
if (entry.type === "compaction") {
|
|
135
|
+
state.liveRemovedTokens = 0;
|
|
136
|
+
state.activeSavings = [];
|
|
137
|
+
}
|
|
138
|
+
else if (entry.type === "custom" && entry.customType === COMPRESSION_SAVINGS_SNAPSHOT_TYPE) {
|
|
139
|
+
if (isSavingsSnapshot(entry.data))
|
|
140
|
+
state = { ...entry.data, activeSavings: [...entry.data.activeSavings] };
|
|
141
|
+
}
|
|
142
|
+
else if (entry.type === "custom" && entry.customType === COMPRESSION_ECONOMICS_ENTRY_TYPE) {
|
|
143
|
+
applyEconomicsRecord(state, entry.data);
|
|
144
|
+
}
|
|
145
|
+
else if (entry.type === "message" && entry.message.role === "assistant" && !entry.replayedFromId) {
|
|
146
|
+
creditAssistantRequest(state, entry.message.provider, entry.message.model);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return state;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=compression-economics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compression-economics.js","sourceRoot":"","sources":["../../../src/core/compaction/compression-economics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,CAAC,MAAM,gCAAgC,GAAG,uBAAuB,CAAC;AACxE,MAAM,CAAC,MAAM,iCAAiC,GAAG,8BAA8B,CAAC;AAqBhF,SAAS,wBAAwB,CAAC,OAAuB,EAAE,KAAa,EAAE,GAAW,EAA+B;IACnH,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAChD,KAAK,MAAM,OAAO,IAAI,6BAA6B,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5D,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;YACvC,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG;gBAAE,MAAM,IAAI,MAAM,CAAC;iBAChD,IAAI,KAAK,GAAG,GAAG;gBAAE,MAAM,IAAI,MAAM,CAAC;QACxC,CAAC;IACF,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAAA,CA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AO,CAAC,KAAK,CAAC,CAAC;QAC5E,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import type { Api, Model } from \"@greppleai/grip-ai\";\nimport { sessionEntryToContextMessages } from \"../session/context.ts\";\nimport type { SessionEntry } from \"../session/types.ts\";\nimport { estimateTokens } from \"./compaction.ts\";\n\nexport const COMPRESSION_ECONOMICS_ENTRY_TYPE = \"compression_economics\";\nexport const COMPRESSION_SAVINGS_SNAPSHOT_TYPE = \"compression_savings_snapshot\";\n\n/** Approximate context and catalog-price assumptions, not provider-reported savings. */\nexport interface CompressionEconomicsRecord {\n\tversion: 1;\n\tsummaryEntryId: string;\n\tprovider: string;\n\tmodelId: string;\n\tsourceTokens: number;\n\tsummaryTokens: number;\n\tremovedTokens: number;\n\treadRate: number;\n\toneTimeCost: number | null;\n\tbreakEvenRequests: number | null;\n}\n\ninterface CompressionRangeTokenCounts {\n\tsource: number;\n\tsuffix: number;\n}\n\nfunction estimateRangeTokenCounts(entries: SessionEntry[], start: number, end: number): CompressionRangeTokenCounts {\n\tlet source = 0;\n\tlet suffix = 0;\n\tfor (const [index, entry] of entries.entries()) {\n\t\tfor (const message of sessionEntryToContextMessages(entry)) {\n\t\t\tconst tokens = estimateTokens(message);\n\t\t\tif (index >= start && index <= end) source += tokens;\n\t\t\telse if (index > end) suffix += tokens;\n\t\t}\n\t}\n\treturn { source, suffix };\n}\n\nexport function estimateCompressionEconomics(\n\tentries: SessionEntry[],\n\tstartEntryId: string,\n\tendEntryId: string,\n\tmodel: Model<Api>,\n\tsummary?: string,\n\tusingSubscription = false,\n): Omit<CompressionEconomicsRecord, \"version\" | \"summaryEntryId\"> | undefined {\n\tconst start = entries.findIndex((entry) => entry.id === startEntryId);\n\tconst end = entries.findIndex((entry) => entry.id === endEntryId);\n\tif (start < 0 || end < start) return undefined;\n\tconst { source: sourceTokens, suffix: suffixTokens } = estimateRangeTokenCounts(entries, start, end);\n\tconst summaryTokens = summary === undefined ? Math.ceil(sourceTokens / 4) : Math.ceil(summary.length / 4);\n\tconst removedTokens = Math.max(0, sourceTokens - summaryTokens);\n\tconst readRate = usingSubscription ? 0 : model.cost.cacheRead > 0 ? model.cost.cacheRead : model.cost.input;\n\t// For automatic caching, a miss is ordinary input, not a separately reported cache write.\n\t// Only the suffix after the changed range may lose its cached prefix; the earlier prefix is unchanged.\n\tconst oneTimeCost =\n\t\t!usingSubscription && model.cost.input > 0 && model.cost.output > 0\n\t\t\t? (summaryTokens * (model.cost.input + model.cost.output) +\n\t\t\t\t\tsuffixTokens * Math.max(0, model.cost.input - readRate)) /\n\t\t\t\t1_000_000\n\t\t\t: null;\n\tconst savingPerRequest = (removedTokens * readRate) / 1_000_000;\n\treturn {\n\t\tprovider: model.provider,\n\t\tmodelId: model.id,\n\t\tsourceTokens,\n\t\tsummaryTokens,\n\t\tremovedTokens,\n\t\treadRate,\n\t\toneTimeCost,\n\t\tbreakEvenRequests: oneTimeCost != null && savingPerRequest > 0 ? Math.ceil(oneTimeCost / savingPerRequest) : null,\n\t};\n}\n\nfunction isEconomicsRecord(data: unknown): data is CompressionEconomicsRecord {\n\tif (!data || typeof data !== \"object\") return false;\n\tconst record = data as Partial<CompressionEconomicsRecord>;\n\treturn (\n\t\trecord.version === 1 &&\n\t\ttypeof record.summaryEntryId === \"string\" &&\n\t\ttypeof record.provider === \"string\" &&\n\t\ttypeof record.modelId === \"string\" &&\n\t\ttypeof record.removedTokens === \"number\" &&\n\t\tNumber.isFinite(record.removedTokens) &&\n\t\trecord.removedTokens >= 0 &&\n\t\ttypeof record.readRate === \"number\" &&\n\t\tNumber.isFinite(record.readRate) &&\n\t\trecord.readRate >= 0 &&\n\t\t(record.oneTimeCost === null || (typeof record.oneTimeCost === \"number\" && Number.isFinite(record.oneTimeCost)))\n\t);\n}\n\ninterface ActiveSaving {\n\tsummaryEntryId: string;\n\tprovider: string;\n\tmodelId: string;\n\tremovedTokens: number;\n\treadRate: number;\n}\n\n/** Captures accrued estimates before replacing their ledger entries on an archived branch. */\nexport interface CompressionSavingsSnapshot {\n\tversion: 1;\n\ttotalRemovedTokens: number;\n\tliveRemovedTokens: number;\n\tavoidedCost: number;\n\toneTimeCost: number;\n\tpricedRequests: number;\n\tactiveSavings: ActiveSaving[];\n}\n\nfunction isSavingsSnapshot(data: unknown): data is CompressionSavingsSnapshot {\n\tif (!data || typeof data !== \"object\") return false;\n\tconst snapshot = data as Partial<CompressionSavingsSnapshot>;\n\treturn (\n\t\tsnapshot.version === 1 &&\n\t\tNumber.isFinite(snapshot.totalRemovedTokens) &&\n\t\tNumber.isFinite(snapshot.liveRemovedTokens) &&\n\t\tNumber.isFinite(snapshot.avoidedCost) &&\n\t\tNumber.isFinite(snapshot.oneTimeCost) &&\n\t\tNumber.isFinite(snapshot.pricedRequests) &&\n\t\tArray.isArray(snapshot.activeSavings) &&\n\t\tsnapshot.activeSavings.every(\n\t\t\t(saving: unknown) =>\n\t\t\t\t!!saving &&\n\t\t\t\ttypeof saving === \"object\" &&\n\t\t\t\ttypeof (saving as ActiveSaving).summaryEntryId === \"string\" &&\n\t\t\t\ttypeof (saving as ActiveSaving).provider === \"string\" &&\n\t\t\t\ttypeof (saving as ActiveSaving).modelId === \"string\" &&\n\t\t\t\tNumber.isFinite((saving as ActiveSaving).removedTokens) &&\n\t\t\t\tNumber.isFinite((saving as ActiveSaving).readRate),\n\t\t)\n\t);\n}\n\nexport interface CompressionSavingsEstimate {\n\ttotalRemovedTokens: number;\n\tliveRemovedTokens: number;\n\tavoidedCost: number;\n\toneTimeCost: number;\n\tnetAvoidedCost: number;\n\tremainingToBreakEven: number;\n\tpricedRequests: number;\n}\nexport interface CompressionCatchUpEstimate {\n\tcachedTurns: number | null;\n\tnewInputTurns: number | null;\n}\n\n/** Approximate future requests to recover outstanding compression cost at two input-price scenarios. */\nexport function estimateCompressionCatchUp(\n\tbranch: SessionEntry[],\n\tmodel: Model<Api>,\n\tusingSubscription: boolean,\n): CompressionCatchUpEstimate {\n\tconst state = createCompressionSavingsSnapshot(branch);\n\tconst remaining = Math.max(0, state.oneTimeCost - state.avoidedCost);\n\tconst tokens = state.activeSavings.reduce(\n\t\t(total, saving) =>\n\t\t\ttotal + (saving.provider === model.provider && saving.modelId === model.id ? saving.removedTokens : 0),\n\t\t0,\n\t);\n\tif (usingSubscription || !remaining || !tokens) return { cachedTurns: null, newInputTurns: null };\n\treturn {\n\t\tcachedTurns:\n\t\t\tmodel.cost.cacheRead > 0 ? Math.ceil((remaining * 1_000_000) / (tokens * model.cost.cacheRead)) : null,\n\t\tnewInputTurns: model.cost.input > 0 ? Math.ceil((remaining * 1_000_000) / (tokens * model.cost.input)) : null,\n\t};\n}\n\n/** Replay persisted estimates in branch order, without counting archived or replayed provider calls twice. */\nexport function estimateCompressionSavings(branch: SessionEntry[]): CompressionSavingsEstimate {\n\tconst { activeSavings: _activeSavings, version: _version, ...totals } = createCompressionSavingsSnapshot(branch);\n\treturn {\n\t\t...totals,\n\t\tnetAvoidedCost: Math.max(0, totals.avoidedCost - totals.oneTimeCost),\n\t\tremainingToBreakEven: Math.max(0, totals.oneTimeCost - totals.avoidedCost),\n\t};\n}\n\nfunction creditAssistantRequest(state: CompressionSavingsSnapshot, provider: string, modelId: string): void {\n\tlet saved = 0;\n\tfor (const saving of state.activeSavings) {\n\t\tif (provider === saving.provider && modelId === saving.modelId)\n\t\t\tsaved += (saving.removedTokens * saving.readRate) / 1_000_000;\n\t}\n\tif (saved > 0) {\n\t\tstate.pricedRequests++;\n\t\tstate.avoidedCost += saved;\n\t}\n}\n\nfunction applyEconomicsRecord(state: CompressionSavingsSnapshot, data: unknown): void {\n\tif (!isEconomicsRecord(data)) return;\n\tconst { summaryEntryId, provider, modelId, removedTokens, readRate, oneTimeCost } = data;\n\tstate.totalRemovedTokens += removedTokens;\n\tstate.liveRemovedTokens += removedTokens;\n\tstate.oneTimeCost += oneTimeCost ?? 0;\n\tstate.activeSavings.push({ summaryEntryId, provider, modelId, removedTokens, readRate });\n}\n\nexport function createCompressionSavingsSnapshot(branch: SessionEntry[]): CompressionSavingsSnapshot {\n\tlet state: CompressionSavingsSnapshot = {\n\t\tversion: 1,\n\t\ttotalRemovedTokens: 0,\n\t\tliveRemovedTokens: 0,\n\t\tavoidedCost: 0,\n\t\toneTimeCost: 0,\n\t\tpricedRequests: 0,\n\t\tactiveSavings: [],\n\t};\n\tfor (const entry of branch) {\n\t\tif (entry.type === \"compaction\") {\n\t\t\tstate.liveRemovedTokens = 0;\n\t\t\tstate.activeSavings = [];\n\t\t} else if (entry.type === \"custom\" && entry.customType === COMPRESSION_SAVINGS_SNAPSHOT_TYPE) {\n\t\t\tif (isSavingsSnapshot(entry.data)) state = { ...entry.data, activeSavings: [...entry.data.activeSavings] };\n\t\t} else if (entry.type === \"custom\" && entry.customType === COMPRESSION_ECONOMICS_ENTRY_TYPE) {\n\t\t\tapplyEconomicsRecord(state, entry.data);\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\" && !entry.replayedFromId) {\n\t\t\tcreditAssistantRequest(state, entry.message.provider, entry.message.model);\n\t\t}\n\t}\n\treturn state;\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for compaction and branch summarization.
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentMessage, FileOperationLists, FileOperations } from "@greppleai/grip-agent-core";
|
|
5
|
+
export type { FileOperations } from "@greppleai/grip-agent-core";
|
|
6
|
+
import type { Message } from "@greppleai/grip-ai";
|
|
7
|
+
export declare function createFileOps(): FileOperations;
|
|
8
|
+
export declare function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void;
|
|
9
|
+
/**
|
|
10
|
+
* Compute final file lists from file operations.
|
|
11
|
+
* Returns readFiles (files only read, not modified) and modifiedFiles.
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeFileLists(fileOps: FileOperations): FileOperationLists;
|
|
14
|
+
/**
|
|
15
|
+
* Format file operations as XML tags for summary.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Serialize LLM messages to text for summarization.
|
|
20
|
+
* This prevents the model from treating it as a conversation to continue.
|
|
21
|
+
* Call convertToLlm() first to handle custom message types.
|
|
22
|
+
*
|
|
23
|
+
* Tool results are truncated to keep the summarization request within
|
|
24
|
+
* reasonable token budgets. Full content is not needed for summarization.
|
|
25
|
+
*/
|
|
26
|
+
export declare function serializeConversation(messages: Message[]): string;
|
|
27
|
+
export declare const SUMMARIZATION_SYSTEM_PROMPT = "You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.\n\nDo NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.";
|
|
28
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/core/compaction/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEnG,YAAY,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,KAAK,EAGX,OAAO,EAIP,MAAM,oBAAoB,CAAC;AAM5B,wBAAgB,aAAa,IAAI,cAAc,CAM9C;AA0BD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAI9F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,kBAAkB,CAK5E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,CAUzF;AA8DD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,CAgBjE;AAMD,eAAO,MAAM,2BAA2B,oUAEmF,CAAC","sourcesContent":["/**\n * Shared utilities for compaction and branch summarization.\n */\n\nimport type { AgentMessage, FileOperationLists, FileOperations } from \"@greppleai/grip-agent-core\";\n\nexport type { FileOperations } from \"@greppleai/grip-agent-core\";\n\nimport type {\n\tAssistantMessage,\n\tImageContent,\n\tMessage,\n\tTextContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"@greppleai/grip-ai\";\n\n// ============================================================================\n// File Operation Tracking\n// ============================================================================\n\nexport function createFileOps(): FileOperations {\n\treturn {\n\t\tread: new Set(),\n\t\twritten: new Set(),\n\t\tedited: new Set(),\n\t};\n}\n\n/**\n * Extract file operations from tool calls in an assistant message.\n */\nfunction recordToolCallFileOperation(block: unknown, fileOps: FileOperations): void {\n\tif (typeof block !== \"object\" || block === null) return;\n\tif (!(\"type\" in block) || block.type !== \"toolCall\") return;\n\tif (!(\"arguments\" in block) || !(\"name\" in block)) return;\n\tconst args = block.arguments as Record<string, unknown> | undefined;\n\tif (!args) return;\n\tconst path = typeof args.path === \"string\" ? args.path : undefined;\n\tif (!path) return;\n\tswitch (block.name) {\n\t\tcase \"read\":\n\t\t\tfileOps.read.add(path);\n\t\t\tbreak;\n\t\tcase \"write\":\n\t\t\tfileOps.written.add(path);\n\t\t\tbreak;\n\t\tcase \"edit\":\n\t\t\tfileOps.edited.add(path);\n\t\t\tbreak;\n\t}\n}\n\nexport function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void {\n\tif (message.role !== \"assistant\") return;\n\tif (!(\"content\" in message) || !Array.isArray(message.content)) return;\n\tfor (const block of message.content) recordToolCallFileOperation(block, fileOps);\n}\n\n/**\n * Compute final file lists from file operations.\n * Returns readFiles (files only read, not modified) and modifiedFiles.\n */\nexport function computeFileLists(fileOps: FileOperations): FileOperationLists {\n\tconst modified = new Set([...fileOps.edited, ...fileOps.written]);\n\tconst readOnly = [...fileOps.read].filter((f) => !modified.has(f)).sort();\n\tconst modifiedFiles = [...modified].sort();\n\treturn { readFiles: readOnly, modifiedFiles };\n}\n\n/**\n * Format file operations as XML tags for summary.\n */\nexport function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string {\n\tconst sections: string[] = [];\n\tif (readFiles.length > 0) {\n\t\tsections.push(`<read-files>\\n${readFiles.join(\"\\n\")}\\n</read-files>`);\n\t}\n\tif (modifiedFiles.length > 0) {\n\t\tsections.push(`<modified-files>\\n${modifiedFiles.join(\"\\n\")}\\n</modified-files>`);\n\t}\n\tif (sections.length === 0) return \"\";\n\treturn `\\n\\n${sections.join(\"\\n\\n\")}`;\n}\n\n// ============================================================================\n// Message Serialization\n// ============================================================================\n\n/** Maximum characters for a tool result in serialized summaries. */\nconst TOOL_RESULT_MAX_CHARS = 2000;\n\n/**\n * Truncate text to a maximum character length for summarization.\n * Keeps the beginning and appends a truncation marker.\n */\nfunction truncateForSummary(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\tconst truncatedChars = text.length - maxChars;\n\treturn `${text.slice(0, maxChars)}\\n\\n[... ${truncatedChars} more characters truncated]`;\n}\n\nfunction joinTextBlocks(content: readonly (TextContent | ImageContent)[]): string {\n\tlet text = \"\";\n\tfor (const block of content) {\n\t\tif (block.type === \"text\") text += block.text;\n\t}\n\treturn text;\n}\n\nfunction serializeUserMessage(message: UserMessage): string[] {\n\tconst content = typeof message.content === \"string\" ? message.content : joinTextBlocks(message.content);\n\treturn content ? [`[User]: ${content}`] : [];\n}\n\nfunction serializeAssistantMessage(message: AssistantMessage): string[] {\n\tconst textParts: string[] = [];\n\tconst thinkingParts: string[] = [];\n\tconst toolCalls: string[] = [];\n\tfor (const block of message.content) {\n\t\tif (block.type === \"text\") {\n\t\t\ttextParts.push(block.text);\n\t\t} else if (block.type === \"thinking\") {\n\t\t\tthinkingParts.push(block.thinking);\n\t\t} else if (block.type === \"toolCall\") {\n\t\t\tconst args = block.arguments as Record<string, unknown>;\n\t\t\tconst argsText = Object.entries(args)\n\t\t\t\t.map(([key, value]) => `${key}=${JSON.stringify(value)}`)\n\t\t\t\t.join(\", \");\n\t\t\ttoolCalls.push(`${block.name}(${argsText})`);\n\t\t}\n\t}\n\n\tconst parts: string[] = [];\n\tif (thinkingParts.length > 0) parts.push(`[Assistant thinking]: ${thinkingParts.join(\"\\n\")}`);\n\tif (textParts.length > 0) parts.push(`[Assistant]: ${textParts.join(\"\\n\")}`);\n\tif (toolCalls.length > 0) parts.push(`[Assistant tool calls]: ${toolCalls.join(\"; \")}`);\n\treturn parts;\n}\n\nfunction serializeToolResultMessage(message: ToolResultMessage): string[] {\n\tconst content = joinTextBlocks(message.content);\n\treturn content ? [`[Tool result]: ${truncateForSummary(content, TOOL_RESULT_MAX_CHARS)}`] : [];\n}\n\n/**\n * Serialize LLM messages to text for summarization.\n * This prevents the model from treating it as a conversation to continue.\n * Call convertToLlm() first to handle custom message types.\n *\n * Tool results are truncated to keep the summarization request within\n * reasonable token budgets. Full content is not needed for summarization.\n */\nexport function serializeConversation(messages: Message[]): string {\n\tconst parts: string[] = [];\n\tfor (const message of messages) {\n\t\tswitch (message.role) {\n\t\t\tcase \"user\":\n\t\t\t\tparts.push(...serializeUserMessage(message));\n\t\t\t\tbreak;\n\t\t\tcase \"assistant\":\n\t\t\t\tparts.push(...serializeAssistantMessage(message));\n\t\t\t\tbreak;\n\t\t\tcase \"toolResult\":\n\t\t\t\tparts.push(...serializeToolResultMessage(message));\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn parts.join(\"\\n\\n\");\n}\n\n// ============================================================================\n// Summarization System Prompt\n// ============================================================================\n\nexport const SUMMARIZATION_SYSTEM_PROMPT = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.\n\nDo NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;\n"]}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for compaction and branch summarization.
|
|
3
|
+
*/
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// File Operation Tracking
|
|
6
|
+
// ============================================================================
|
|
7
|
+
export function createFileOps() {
|
|
8
|
+
return {
|
|
9
|
+
read: new Set(),
|
|
10
|
+
written: new Set(),
|
|
11
|
+
edited: new Set(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extract file operations from tool calls in an assistant message.
|
|
16
|
+
*/
|
|
17
|
+
function recordToolCallFileOperation(block, fileOps) {
|
|
18
|
+
if (typeof block !== "object" || block === null)
|
|
19
|
+
return;
|
|
20
|
+
if (!("type" in block) || block.type !== "toolCall")
|
|
21
|
+
return;
|
|
22
|
+
if (!("arguments" in block) || !("name" in block))
|
|
23
|
+
return;
|
|
24
|
+
const args = block.arguments;
|
|
25
|
+
if (!args)
|
|
26
|
+
return;
|
|
27
|
+
const path = typeof args.path === "string" ? args.path : undefined;
|
|
28
|
+
if (!path)
|
|
29
|
+
return;
|
|
30
|
+
switch (block.name) {
|
|
31
|
+
case "read":
|
|
32
|
+
fileOps.read.add(path);
|
|
33
|
+
break;
|
|
34
|
+
case "write":
|
|
35
|
+
fileOps.written.add(path);
|
|
36
|
+
break;
|
|
37
|
+
case "edit":
|
|
38
|
+
fileOps.edited.add(path);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function extractFileOpsFromMessage(message, fileOps) {
|
|
43
|
+
if (message.role !== "assistant")
|
|
44
|
+
return;
|
|
45
|
+
if (!("content" in message) || !Array.isArray(message.content))
|
|
46
|
+
return;
|
|
47
|
+
for (const block of message.content)
|
|
48
|
+
recordToolCallFileOperation(block, fileOps);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compute final file lists from file operations.
|
|
52
|
+
* Returns readFiles (files only read, not modified) and modifiedFiles.
|
|
53
|
+
*/
|
|
54
|
+
export function computeFileLists(fileOps) {
|
|
55
|
+
const modified = new Set([...fileOps.edited, ...fileOps.written]);
|
|
56
|
+
const readOnly = [...fileOps.read].filter((f) => !modified.has(f)).sort();
|
|
57
|
+
const modifiedFiles = [...modified].sort();
|
|
58
|
+
return { readFiles: readOnly, modifiedFiles };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format file operations as XML tags for summary.
|
|
62
|
+
*/
|
|
63
|
+
export function formatFileOperations(readFiles, modifiedFiles) {
|
|
64
|
+
const sections = [];
|
|
65
|
+
if (readFiles.length > 0) {
|
|
66
|
+
sections.push(`<read-files>\n${readFiles.join("\n")}\n</read-files>`);
|
|
67
|
+
}
|
|
68
|
+
if (modifiedFiles.length > 0) {
|
|
69
|
+
sections.push(`<modified-files>\n${modifiedFiles.join("\n")}\n</modified-files>`);
|
|
70
|
+
}
|
|
71
|
+
if (sections.length === 0)
|
|
72
|
+
return "";
|
|
73
|
+
return `\n\n${sections.join("\n\n")}`;
|
|
74
|
+
}
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Message Serialization
|
|
77
|
+
// ============================================================================
|
|
78
|
+
/** Maximum characters for a tool result in serialized summaries. */
|
|
79
|
+
const TOOL_RESULT_MAX_CHARS = 2000;
|
|
80
|
+
/**
|
|
81
|
+
* Truncate text to a maximum character length for summarization.
|
|
82
|
+
* Keeps the beginning and appends a truncation marker.
|
|
83
|
+
*/
|
|
84
|
+
function truncateForSummary(text, maxChars) {
|
|
85
|
+
if (text.length <= maxChars)
|
|
86
|
+
return text;
|
|
87
|
+
const truncatedChars = text.length - maxChars;
|
|
88
|
+
return `${text.slice(0, maxChars)}\n\n[... ${truncatedChars} more characters truncated]`;
|
|
89
|
+
}
|
|
90
|
+
function joinTextBlocks(content) {
|
|
91
|
+
let text = "";
|
|
92
|
+
for (const block of content) {
|
|
93
|
+
if (block.type === "text")
|
|
94
|
+
text += block.text;
|
|
95
|
+
}
|
|
96
|
+
return text;
|
|
97
|
+
}
|
|
98
|
+
function serializeUserMessage(message) {
|
|
99
|
+
const content = typeof message.content === "string" ? message.content : joinTextBlocks(message.content);
|
|
100
|
+
return content ? [`[User]: ${content}`] : [];
|
|
101
|
+
}
|
|
102
|
+
function serializeAssistantMessage(message) {
|
|
103
|
+
const textParts = [];
|
|
104
|
+
const thinkingParts = [];
|
|
105
|
+
const toolCalls = [];
|
|
106
|
+
for (const block of message.content) {
|
|
107
|
+
if (block.type === "text") {
|
|
108
|
+
textParts.push(block.text);
|
|
109
|
+
}
|
|
110
|
+
else if (block.type === "thinking") {
|
|
111
|
+
thinkingParts.push(block.thinking);
|
|
112
|
+
}
|
|
113
|
+
else if (block.type === "toolCall") {
|
|
114
|
+
const args = block.arguments;
|
|
115
|
+
const argsText = Object.entries(args)
|
|
116
|
+
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
|
|
117
|
+
.join(", ");
|
|
118
|
+
toolCalls.push(`${block.name}(${argsText})`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const parts = [];
|
|
122
|
+
if (thinkingParts.length > 0)
|
|
123
|
+
parts.push(`[Assistant thinking]: ${thinkingParts.join("\n")}`);
|
|
124
|
+
if (textParts.length > 0)
|
|
125
|
+
parts.push(`[Assistant]: ${textParts.join("\n")}`);
|
|
126
|
+
if (toolCalls.length > 0)
|
|
127
|
+
parts.push(`[Assistant tool calls]: ${toolCalls.join("; ")}`);
|
|
128
|
+
return parts;
|
|
129
|
+
}
|
|
130
|
+
function serializeToolResultMessage(message) {
|
|
131
|
+
const content = joinTextBlocks(message.content);
|
|
132
|
+
return content ? [`[Tool result]: ${truncateForSummary(content, TOOL_RESULT_MAX_CHARS)}`] : [];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Serialize LLM messages to text for summarization.
|
|
136
|
+
* This prevents the model from treating it as a conversation to continue.
|
|
137
|
+
* Call convertToLlm() first to handle custom message types.
|
|
138
|
+
*
|
|
139
|
+
* Tool results are truncated to keep the summarization request within
|
|
140
|
+
* reasonable token budgets. Full content is not needed for summarization.
|
|
141
|
+
*/
|
|
142
|
+
export function serializeConversation(messages) {
|
|
143
|
+
const parts = [];
|
|
144
|
+
for (const message of messages) {
|
|
145
|
+
switch (message.role) {
|
|
146
|
+
case "user":
|
|
147
|
+
parts.push(...serializeUserMessage(message));
|
|
148
|
+
break;
|
|
149
|
+
case "assistant":
|
|
150
|
+
parts.push(...serializeAssistantMessage(message));
|
|
151
|
+
break;
|
|
152
|
+
case "toolResult":
|
|
153
|
+
parts.push(...serializeToolResultMessage(message));
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return parts.join("\n\n");
|
|
158
|
+
}
|
|
159
|
+
// ============================================================================
|
|
160
|
+
// Summarization System Prompt
|
|
161
|
+
// ============================================================================
|
|
162
|
+
export const SUMMARIZATION_SYSTEM_PROMPT = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.
|
|
163
|
+
|
|
164
|
+
Do NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;
|
|
165
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/compaction/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E,MAAM,UAAU,aAAa,GAAmB;IAC/C,OAAO;QACN,IAAI,EAAE,IAAI,GAAG,EAAE;QACf,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,MAAM,EAAE,IAAI,GAAG,EAAE;KACjB,CAAC;AAAA,CACF;AAED;;GAEG;AACH,SAAS,2BAA2B,CAAC,KAAc,EAAE,OAAuB,EAAQ;IACnF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO;IACxD,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAA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B,KAAK,MAAM;gBACV,KAAK,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC7C,MAAM;YACP,KAAK,WAAW;gBACf,KAAK,CAAC,IAAI,CAAC,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC;gBAClD,MAAM;YACP,KAAK,YAAY;gBAChB,KAAK,CAAC,IAAI,CAAC,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;gBACnD,MAAM;QACR,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAAA,CAC1B;AAED,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,MAAM,CAAC,MAAM,2BAA2B,GAAG;;2HAEgF,CAAC","sourcesContent":["/**\n * Shared utilities for compaction and branch summarization.\n */\n\nimport type { AgentMessage, FileOperationLists, FileOperations } from \"@greppleai/grip-agent-core\";\n\nexport type { FileOperations } from \"@greppleai/grip-agent-core\";\n\nimport type {\n\tAssistantMessage,\n\tImageContent,\n\tMessage,\n\tTextContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"@greppleai/grip-ai\";\n\n// ============================================================================\n// File Operation Tracking\n// ============================================================================\n\nexport function createFileOps(): FileOperations {\n\treturn {\n\t\tread: new Set(),\n\t\twritten: new Set(),\n\t\tedited: new Set(),\n\t};\n}\n\n/**\n * Extract file operations from tool calls in an assistant message.\n */\nfunction recordToolCallFileOperation(block: unknown, fileOps: FileOperations): void {\n\tif (typeof block !== \"object\" || block === null) return;\n\tif (!(\"type\" in block) || block.type !== \"toolCall\") return;\n\tif (!(\"arguments\" in block) || !(\"name\" in block)) return;\n\tconst args = block.arguments as Record<string, unknown> | undefined;\n\tif (!args) return;\n\tconst path = typeof args.path === \"string\" ? args.path : undefined;\n\tif (!path) return;\n\tswitch (block.name) {\n\t\tcase \"read\":\n\t\t\tfileOps.read.add(path);\n\t\t\tbreak;\n\t\tcase \"write\":\n\t\t\tfileOps.written.add(path);\n\t\t\tbreak;\n\t\tcase \"edit\":\n\t\t\tfileOps.edited.add(path);\n\t\t\tbreak;\n\t}\n}\n\nexport function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void {\n\tif (message.role !== \"assistant\") return;\n\tif (!(\"content\" in message) || !Array.isArray(message.content)) return;\n\tfor (const block of message.content) recordToolCallFileOperation(block, fileOps);\n}\n\n/**\n * Compute final file lists from file operations.\n * Returns readFiles (files only read, not modified) and modifiedFiles.\n */\nexport function computeFileLists(fileOps: FileOperations): FileOperationLists {\n\tconst modified = new Set([...fileOps.edited, ...fileOps.written]);\n\tconst readOnly = [...fileOps.read].filter((f) => !modified.has(f)).sort();\n\tconst modifiedFiles = [...modified].sort();\n\treturn { readFiles: readOnly, modifiedFiles };\n}\n\n/**\n * Format file operations as XML tags for summary.\n */\nexport function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string {\n\tconst sections: string[] = [];\n\tif (readFiles.length > 0) {\n\t\tsections.push(`<read-files>\\n${readFiles.join(\"\\n\")}\\n</read-files>`);\n\t}\n\tif (modifiedFiles.length > 0) {\n\t\tsections.push(`<modified-files>\\n${modifiedFiles.join(\"\\n\")}\\n</modified-files>`);\n\t}\n\tif (sections.length === 0) return \"\";\n\treturn `\\n\\n${sections.join(\"\\n\\n\")}`;\n}\n\n// ============================================================================\n// Message Serialization\n// ============================================================================\n\n/** Maximum characters for a tool result in serialized summaries. */\nconst TOOL_RESULT_MAX_CHARS = 2000;\n\n/**\n * Truncate text to a maximum character length for summarization.\n * Keeps the beginning and appends a truncation marker.\n */\nfunction truncateForSummary(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\tconst truncatedChars = text.length - maxChars;\n\treturn `${text.slice(0, maxChars)}\\n\\n[... ${truncatedChars} more characters truncated]`;\n}\n\nfunction joinTextBlocks(content: readonly (TextContent | ImageContent)[]): string {\n\tlet text = \"\";\n\tfor (const block of content) {\n\t\tif (block.type === \"text\") text += block.text;\n\t}\n\treturn text;\n}\n\nfunction serializeUserMessage(message: UserMessage): string[] {\n\tconst content = typeof message.content === \"string\" ? message.content : joinTextBlocks(message.content);\n\treturn content ? [`[User]: ${content}`] : [];\n}\n\nfunction serializeAssistantMessage(message: AssistantMessage): string[] {\n\tconst textParts: string[] = [];\n\tconst thinkingParts: string[] = [];\n\tconst toolCalls: string[] = [];\n\tfor (const block of message.content) {\n\t\tif (block.type === \"text\") {\n\t\t\ttextParts.push(block.text);\n\t\t} else if (block.type === \"thinking\") {\n\t\t\tthinkingParts.push(block.thinking);\n\t\t} else if (block.type === \"toolCall\") {\n\t\t\tconst args = block.arguments as Record<string, unknown>;\n\t\t\tconst argsText = Object.entries(args)\n\t\t\t\t.map(([key, value]) => `${key}=${JSON.stringify(value)}`)\n\t\t\t\t.join(\", \");\n\t\t\ttoolCalls.push(`${block.name}(${argsText})`);\n\t\t}\n\t}\n\n\tconst parts: string[] = [];\n\tif (thinkingParts.length > 0) parts.push(`[Assistant thinking]: ${thinkingParts.join(\"\\n\")}`);\n\tif (textParts.length > 0) parts.push(`[Assistant]: ${textParts.join(\"\\n\")}`);\n\tif (toolCalls.length > 0) parts.push(`[Assistant tool calls]: ${toolCalls.join(\"; \")}`);\n\treturn parts;\n}\n\nfunction serializeToolResultMessage(message: ToolResultMessage): string[] {\n\tconst content = joinTextBlocks(message.content);\n\treturn content ? [`[Tool result]: ${truncateForSummary(content, TOOL_RESULT_MAX_CHARS)}`] : [];\n}\n\n/**\n * Serialize LLM messages to text for summarization.\n * This prevents the model from treating it as a conversation to continue.\n * Call convertToLlm() first to handle custom message types.\n *\n * Tool results are truncated to keep the summarization request within\n * reasonable token budgets. Full content is not needed for summarization.\n */\nexport function serializeConversation(messages: Message[]): string {\n\tconst parts: string[] = [];\n\tfor (const message of messages) {\n\t\tswitch (message.role) {\n\t\t\tcase \"user\":\n\t\t\t\tparts.push(...serializeUserMessage(message));\n\t\t\t\tbreak;\n\t\t\tcase \"assistant\":\n\t\t\t\tparts.push(...serializeAssistantMessage(message));\n\t\t\t\tbreak;\n\t\t\tcase \"toolResult\":\n\t\t\t\tparts.push(...serializeToolResultMessage(message));\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn parts.join(\"\\n\\n\");\n}\n\n// ============================================================================\n// Summarization System Prompt\n// ============================================================================\n\nexport const SUMMARIZATION_SYSTEM_PROMPT = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.\n\nDo NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/core/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,eAAO,MAAM,sBAAsB,EAAE,aAAwB,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@greppleai/grip-agent-core\";\n\nexport const DEFAULT_THINKING_LEVEL: ThinkingLevel = \"medium\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/core/defaults.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAkB,QAAQ,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@greppleai/grip-agent-core\";\n\nexport const DEFAULT_THINKING_LEVEL: ThinkingLevel = \"medium\";\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type ResourceCollisionCategory = "extension" | "skill" | "rule" | "prompt" | "theme";
|
|
2
|
+
type ResourceDiagnosticCategory = "warning" | "error" | "collision";
|
|
3
|
+
export interface ResourceCollision {
|
|
4
|
+
resourceType: ResourceCollisionCategory;
|
|
5
|
+
name: string;
|
|
6
|
+
winnerPath: string;
|
|
7
|
+
loserPath: string;
|
|
8
|
+
winnerSource?: string;
|
|
9
|
+
loserSource?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ResourceDiagnostic {
|
|
12
|
+
type: ResourceDiagnosticCategory;
|
|
13
|
+
message: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
collision?: ResourceCollision;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/core/diagnostics.ts"],"names":[],"mappings":"AAAA,KAAK,yBAAyB,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AACrF,KAAK,0BAA0B,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IACjC,YAAY,EAAE,yBAAyB,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC9B","sourcesContent":["type ResourceCollisionCategory = \"extension\" | \"skill\" | \"rule\" | \"prompt\" | \"theme\";\ntype ResourceDiagnosticCategory = \"warning\" | \"error\" | \"collision\";\n\nexport interface ResourceCollision {\n\tresourceType: ResourceCollisionCategory;\n\tname: string; // skill/rule name, command/tool/flag name, prompt name, theme name\n\twinnerPath: string;\n\tloserPath: string;\n\twinnerSource?: string; // e.g., \"npm:foo\", \"git:...\", \"local\"\n\tloserSource?: string;\n}\n\nexport interface ResourceDiagnostic {\n\ttype: ResourceDiagnosticCategory;\n\tmessage: string;\n\tpath?: string;\n\tcollision?: ResourceCollision;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/core/diagnostics.ts"],"names":[],"mappings":"","sourcesContent":["type ResourceCollisionCategory = \"extension\" | \"skill\" | \"rule\" | \"prompt\" | \"theme\";\ntype ResourceDiagnosticCategory = \"warning\" | \"error\" | \"collision\";\n\nexport interface ResourceCollision {\n\tresourceType: ResourceCollisionCategory;\n\tname: string; // skill/rule name, command/tool/flag name, prompt name, theme name\n\twinnerPath: string;\n\tloserPath: string;\n\twinnerSource?: string; // e.g., \"npm:foo\", \"git:...\", \"local\"\n\tloserSource?: string;\n}\n\nexport interface ResourceDiagnostic {\n\ttype: ResourceDiagnosticCategory;\n\tmessage: string;\n\tpath?: string;\n\tcollision?: ResourceCollision;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface EventBus {
|
|
2
|
+
emit(channel: string, data: unknown): void;
|
|
3
|
+
on(channel: string, handler: (data: unknown) => void): () => void;
|
|
4
|
+
}
|
|
5
|
+
export interface EventBusController extends EventBus {
|
|
6
|
+
clear(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createEventBus(): EventBusController;
|
|
9
|
+
//# sourceMappingURL=event-bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/core/event-bus.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACxB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3C,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAClE;AAED,MAAM,WAAW,kBAAmB,SAAQ,QAAQ;IACnD,KAAK,IAAI,IAAI,CAAC;CACd;AAED,wBAAgB,cAAc,IAAI,kBAAkB,CAqBnD","sourcesContent":["import { EventEmitter } from \"node:events\";\n\nexport interface EventBus {\n\temit(channel: string, data: unknown): void;\n\ton(channel: string, handler: (data: unknown) => void): () => void;\n}\n\nexport interface EventBusController extends EventBus {\n\tclear(): void;\n}\n\nexport function createEventBus(): EventBusController {\n\tconst emitter = new EventEmitter();\n\treturn {\n\t\temit: (channel, data) => {\n\t\t\temitter.emit(channel, data);\n\t\t},\n\t\ton: (channel, handler) => {\n\t\t\tconst safeHandler = async (data: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait handler(data);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconsole.error(`Event handler error (${channel}):`, err);\n\t\t\t\t}\n\t\t\t};\n\t\t\temitter.on(channel, safeHandler);\n\t\t\treturn () => emitter.off(channel, safeHandler);\n\t\t},\n\t\tclear: () => {\n\t\t\temitter.removeAllListeners();\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
export function createEventBus() {
|
|
3
|
+
const emitter = new EventEmitter();
|
|
4
|
+
return {
|
|
5
|
+
emit: (channel, data) => {
|
|
6
|
+
emitter.emit(channel, data);
|
|
7
|
+
},
|
|
8
|
+
on: (channel, handler) => {
|
|
9
|
+
const safeHandler = async (data) => {
|
|
10
|
+
try {
|
|
11
|
+
await handler(data);
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
console.error(`Event handler error (${channel}):`, err);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
emitter.on(channel, safeHandler);
|
|
18
|
+
return () => emitter.off(channel, safeHandler);
|
|
19
|
+
},
|
|
20
|
+
clear: () => {
|
|
21
|
+
emitter.removeAllListeners();
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=event-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../src/core/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAW3C,MAAM,UAAU,cAAc,GAAuB;IACpD,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;IACnC,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAAA,CAC5B;QACD,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC;YACzB,MAAM,WAAW,GAAG,KAAK,EAAE,IAAa,EAAE,EAAE,CAAC;gBAC5C,IAAI,CAAC;oBACJ,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;gBACrB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACd,OAAO,CAAC,KAAK,CAAC,wBAAwB,OAAO,IAAI,EAAE,GAAG,CAAC,CAAC;gBACzD,CAAC;YAAA,CACD,CAAC;YACF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YACjC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAAA,CAC/C;QACD,KAAK,EAAE,GAAG,EAAE,CAAC;YACZ,OAAO,CAAC,kBAAkB,EAAE,CAAC;QAAA,CAC7B;KACD,CAAC;AAAA,CACF","sourcesContent":["import { EventEmitter } from \"node:events\";\n\nexport interface EventBus {\n\temit(channel: string, data: unknown): void;\n\ton(channel: string, handler: (data: unknown) => void): () => void;\n}\n\nexport interface EventBusController extends EventBus {\n\tclear(): void;\n}\n\nexport function createEventBus(): EventBusController {\n\tconst emitter = new EventEmitter();\n\treturn {\n\t\temit: (channel, data) => {\n\t\t\temitter.emit(channel, data);\n\t\t},\n\t\ton: (channel, handler) => {\n\t\t\tconst safeHandler = async (data: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait handler(data);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconsole.error(`Event handler error (${channel}):`, err);\n\t\t\t\t}\n\t\t\t};\n\t\t\temitter.on(channel, safeHandler);\n\t\t\treturn () => emitter.off(channel, safeHandler);\n\t\t},\n\t\tclear: () => {\n\t\t\temitter.removeAllListeners();\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared command execution utilities for extensions and custom tools.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Options for executing shell commands.
|
|
6
|
+
*/
|
|
7
|
+
export interface ExecOptions {
|
|
8
|
+
/** AbortSignal to cancel the command */
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
/** Timeout in milliseconds */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Working directory */
|
|
13
|
+
cwd?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Result of executing a shell command.
|
|
17
|
+
*/
|
|
18
|
+
export interface ExecResult {
|
|
19
|
+
stdout: string;
|
|
20
|
+
stderr: string;
|
|
21
|
+
code: number;
|
|
22
|
+
killed: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Execute a shell command and return stdout/stderr/code.
|
|
26
|
+
* Supports timeout and abort signal.
|
|
27
|
+
*/
|
|
28
|
+
export declare function execCommand(command: string, args: string[], cwd: string, options?: ExecOptions): Promise<ExecResult>;
|
|
29
|
+
//# sourceMappingURL=exec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/core/exec.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,wCAAwC;IACxC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAChC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAoErB","sourcesContent":["/**\n * Shared command execution utilities for extensions and custom tools.\n */\n\nimport { spawn } from \"node:child_process\";\nimport { waitForChildProcess } from \"../utils/child-process.ts\";\n\n/**\n * Options for executing shell commands.\n */\nexport interface ExecOptions {\n\t/** AbortSignal to cancel the command */\n\tsignal?: AbortSignal;\n\t/** Timeout in milliseconds */\n\ttimeout?: number;\n\t/** Working directory */\n\tcwd?: string;\n}\n\n/**\n * Result of executing a shell command.\n */\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n\tkilled: boolean;\n}\n\n/**\n * Execute a shell command and return stdout/stderr/code.\n * Supports timeout and abort signal.\n */\nexport async function execCommand(\n\tcommand: string,\n\targs: string[],\n\tcwd: string,\n\toptions?: ExecOptions,\n): Promise<ExecResult> {\n\treturn new Promise((resolve) => {\n\t\tconst proc = spawn(command, args, {\n\t\t\tcwd,\n\t\t\tshell: false,\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\n\t\tlet stdout = \"\";\n\t\tlet stderr = \"\";\n\t\tlet killed = false;\n\t\tlet timeoutId: NodeJS.Timeout | undefined;\n\n\t\tconst killProcess = () => {\n\t\t\tif (!killed) {\n\t\t\t\tkilled = true;\n\t\t\t\tproc.kill(\"SIGTERM\");\n\t\t\t\t// Force kill after 5 seconds if SIGTERM doesn't work\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tif (!proc.killed) {\n\t\t\t\t\t\tproc.kill(\"SIGKILL\");\n\t\t\t\t\t}\n\t\t\t\t}, 5000);\n\t\t\t}\n\t\t};\n\n\t\t// Handle abort signal\n\t\tif (options?.signal) {\n\t\t\tif (options.signal.aborted) {\n\t\t\t\tkillProcess();\n\t\t\t} else {\n\t\t\t\toptions.signal.addEventListener(\"abort\", killProcess, { once: true });\n\t\t\t}\n\t\t}\n\n\t\t// Handle timeout\n\t\tif (options?.timeout && options.timeout > 0) {\n\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\tkillProcess();\n\t\t\t}, options.timeout);\n\t\t}\n\n\t\tproc.stdout?.on(\"data\", (data) => {\n\t\t\tstdout += data.toString();\n\t\t});\n\n\t\tproc.stderr?.on(\"data\", (data) => {\n\t\t\tstderr += data.toString();\n\t\t});\n\n\t\t// Wait for process termination without hanging on inherited stdio handles\n\t\t// held open by detached descendants.\n\t\twaitForChildProcess(proc)\n\t\t\t.then((code) => {\n\t\t\t\tif (timeoutId) clearTimeout(timeoutId);\n\t\t\t\tif (options?.signal) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", killProcess);\n\t\t\t\t}\n\t\t\t\tresolve({ stdout, stderr, code: code ?? 0, killed });\n\t\t\t})\n\t\t\t.catch((_err) => {\n\t\t\t\tif (timeoutId) clearTimeout(timeoutId);\n\t\t\t\tif (options?.signal) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", killProcess);\n\t\t\t\t}\n\t\t\t\tresolve({ stdout, stderr, code: 1, killed });\n\t\t\t});\n\t});\n}\n"]}
|