@jingyi0605/codingns4dsh 0.2.0-rc.2 → 0.2.0-rc.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/README.en.md +4 -4
- package/README.md +15 -6
- package/assets/provider-icons/antigravity.svg +39 -0
- package/assets/provider-icons/codebuddy.svg +37 -0
- package/assets/provider-icons/cursor-cli.svg +1 -0
- package/assets/provider-icons/kiro-cli.svg +11 -0
- package/assets/provider-icons/qoder-cn.svg +5 -0
- package/assets/provider-icons/qoder.svg +5 -0
- package/assets/provider-icons/workbuddy.svg +29 -0
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.d.ts.map +1 -1
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.js +78 -1
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.js.map +1 -1
- package/data/build/dist/client/bundle.js +3864 -507
- package/data/build/dist/client/bundle.js.map +1 -1
- package/data/build/dist/client/cli-catalog.d.ts +1 -1
- package/data/build/dist/client/cli-catalog.d.ts.map +1 -1
- package/data/build/dist/client/cli-catalog.js +11 -5
- package/data/build/dist/client/cli-catalog.js.map +1 -1
- package/data/build/dist/client/cli-slots.d.ts.map +1 -1
- package/data/build/dist/client/cli-slots.js +111 -13
- package/data/build/dist/client/cli-slots.js.map +1 -1
- package/data/build/dist/client/debug/ui.d.ts.map +1 -1
- package/data/build/dist/client/debug/ui.js +2 -1
- package/data/build/dist/client/debug/ui.js.map +1 -1
- package/data/build/dist/client/delegate-command.d.ts +1 -0
- package/data/build/dist/client/delegate-command.d.ts.map +1 -1
- package/data/build/dist/client/delegate-command.js +486 -27
- package/data/build/dist/client/delegate-command.js.map +1 -1
- package/data/build/dist/client/delegate-plan.d.ts +13 -4
- package/data/build/dist/client/delegate-plan.d.ts.map +1 -1
- package/data/build/dist/client/delegate-plan.js +10 -6
- package/data/build/dist/client/delegate-plan.js.map +1 -1
- package/data/build/dist/client/delegate-ui-dom.d.ts +46 -0
- package/data/build/dist/client/delegate-ui-dom.d.ts.map +1 -1
- package/data/build/dist/client/delegate-ui-dom.js +291 -7
- package/data/build/dist/client/delegate-ui-dom.js.map +1 -1
- package/data/build/dist/client/features/cli-adapters.d.ts.map +1 -1
- package/data/build/dist/client/features/cli-adapters.js +117 -8
- package/data/build/dist/client/features/cli-adapters.js.map +1 -1
- package/data/build/dist/client/features/mobile-access-panel.d.ts.map +1 -1
- package/data/build/dist/client/features/mobile-access-panel.js +8 -7
- package/data/build/dist/client/features/mobile-access-panel.js.map +1 -1
- package/data/build/dist/client/features/peer-host.d.ts +6 -4
- package/data/build/dist/client/features/peer-host.d.ts.map +1 -1
- package/data/build/dist/client/features/peer-host.js +346 -18
- package/data/build/dist/client/features/peer-host.js.map +1 -1
- package/data/build/dist/client/git-history-graph.d.ts +2 -2
- package/data/build/dist/client/git-history-graph.d.ts.map +1 -1
- package/data/build/dist/client/git-history-graph.js +2 -2
- package/data/build/dist/client/git-history-graph.js.map +1 -1
- package/data/build/dist/client/git-management.d.ts.map +1 -1
- package/data/build/dist/client/git-management.js +21 -1
- package/data/build/dist/client/git-management.js.map +1 -1
- package/data/build/dist/client/locale.d.ts.map +1 -1
- package/data/build/dist/client/locale.js +60 -6
- package/data/build/dist/client/locale.js.map +1 -1
- package/data/build/dist/client/locales/terminalAuth.d.ts.map +1 -1
- package/data/build/dist/client/locales/terminalAuth.js +4 -0
- package/data/build/dist/client/locales/terminalAuth.js.map +1 -1
- package/data/build/dist/client/locales/usage.d.ts.map +1 -1
- package/data/build/dist/client/locales/usage.js +20 -0
- package/data/build/dist/client/locales/usage.js.map +1 -1
- package/data/build/dist/client/mobile-session-interaction.d.ts.map +1 -1
- package/data/build/dist/client/mobile-session-interaction.js +24 -7
- package/data/build/dist/client/mobile-session-interaction.js.map +1 -1
- package/data/build/dist/client/mobile-sidebar-gestures.d.ts +55 -7
- package/data/build/dist/client/mobile-sidebar-gestures.d.ts.map +1 -1
- package/data/build/dist/client/mobile-sidebar-gestures.js +339 -40
- package/data/build/dist/client/mobile-sidebar-gestures.js.map +1 -1
- package/data/build/dist/client/model-catalog-cache.d.ts +5 -0
- package/data/build/dist/client/model-catalog-cache.d.ts.map +1 -0
- package/data/build/dist/client/model-catalog-cache.js +58 -0
- package/data/build/dist/client/model-catalog-cache.js.map +1 -0
- package/data/build/dist/client/peer-host-aggregate-refresh.d.ts +7 -0
- package/data/build/dist/client/peer-host-aggregate-refresh.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-aggregate-refresh.js +13 -1
- package/data/build/dist/client/peer-host-aggregate-refresh.js.map +1 -1
- package/data/build/dist/client/peer-host-native-projection.d.ts +16 -1
- package/data/build/dist/client/peer-host-native-projection.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-native-projection.js +49 -8
- package/data/build/dist/client/peer-host-native-projection.js.map +1 -1
- package/data/build/dist/client/peer-host-native-store-projection.d.ts +6 -2
- package/data/build/dist/client/peer-host-native-store-projection.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-native-store-projection.js +308 -10
- package/data/build/dist/client/peer-host-native-store-projection.js.map +1 -1
- package/data/build/dist/client/provider-icon-assets.js +14 -0
- package/data/build/dist/client/provider-icon-assets.js.map +1 -1
- package/data/build/dist/client/provider-icons.d.ts.map +1 -1
- package/data/build/dist/client/provider-icons.js +15 -3
- package/data/build/dist/client/provider-icons.js.map +1 -1
- package/data/build/dist/client/remote-web-context.js +10 -6
- package/data/build/dist/client/remote-web-context.js.map +1 -1
- package/data/build/dist/client/service-tier.d.ts +54 -0
- package/data/build/dist/client/service-tier.d.ts.map +1 -0
- package/data/build/dist/client/service-tier.js +78 -0
- package/data/build/dist/client/service-tier.js.map +1 -0
- package/data/build/dist/client/settings-promo-styles.d.ts +28 -0
- package/data/build/dist/client/settings-promo-styles.d.ts.map +1 -0
- package/data/build/dist/client/settings-promo-styles.js +58 -0
- package/data/build/dist/client/settings-promo-styles.js.map +1 -0
- package/data/build/dist/client/settings-promo.d.ts +14 -0
- package/data/build/dist/client/settings-promo.d.ts.map +1 -0
- package/data/build/dist/client/settings-promo.js +68 -0
- package/data/build/dist/client/settings-promo.js.map +1 -0
- package/data/build/dist/client/settings-section.d.ts +2 -1
- package/data/build/dist/client/settings-section.d.ts.map +1 -1
- package/data/build/dist/client/settings-section.js +7 -4
- package/data/build/dist/client/settings-section.js.map +1 -1
- package/data/build/dist/client/subscription-slot.d.ts.map +1 -1
- package/data/build/dist/client/subscription-slot.js +181 -16
- package/data/build/dist/client/subscription-slot.js.map +1 -1
- package/data/build/dist/client/terminal/model.d.ts +82 -3
- package/data/build/dist/client/terminal/model.d.ts.map +1 -1
- package/data/build/dist/client/terminal/model.js +368 -29
- package/data/build/dist/client/terminal/model.js.map +1 -1
- package/data/build/dist/client/terminal/recovery.d.ts +16 -1
- package/data/build/dist/client/terminal/recovery.d.ts.map +1 -1
- package/data/build/dist/client/terminal/recovery.js +101 -39
- package/data/build/dist/client/terminal/recovery.js.map +1 -1
- package/data/build/dist/client/terminal/styles.d.ts +10 -0
- package/data/build/dist/client/terminal/styles.d.ts.map +1 -1
- package/data/build/dist/client/terminal/styles.js +27 -3
- package/data/build/dist/client/terminal/styles.js.map +1 -1
- package/data/build/dist/client/terminal/ui.d.ts +3 -2
- package/data/build/dist/client/terminal/ui.d.ts.map +1 -1
- package/data/build/dist/client/terminal/ui.js +215 -104
- package/data/build/dist/client/terminal/ui.js.map +1 -1
- package/data/build/dist/client/terminal/xterm-view.d.ts +5 -1
- package/data/build/dist/client/terminal/xterm-view.d.ts.map +1 -1
- package/data/build/dist/client/terminal/xterm-view.js +378 -20
- package/data/build/dist/client/terminal/xterm-view.js.map +1 -1
- package/data/build/dist/host/cli-adapters/acp-cli-driver.d.ts +58 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.js +271 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.d.ts +30 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.js +210 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/claude-driver.js +1 -1
- package/data/build/dist/host/cli-adapters/claude-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/codebuddy-driver.d.ts +139 -0
- package/data/build/dist/host/cli-adapters/codebuddy-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/codebuddy-driver.js +1721 -0
- package/data/build/dist/host/cli-adapters/codebuddy-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.d.ts +53 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.js +778 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.js.map +1 -0
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts +12 -0
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/codex-driver.js +153 -6
- package/data/build/dist/host/cli-adapters/codex-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +43 -3
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-driver.js +637 -72
- package/data/build/dist/host/cli-adapters/command-code-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-history.d.ts +147 -0
- package/data/build/dist/host/cli-adapters/command-code-history.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/command-code-history.js +659 -0
- package/data/build/dist/host/cli-adapters/command-code-history.js.map +1 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.d.ts +12 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.js +20 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.d.ts +67 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.js +169 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.js.map +1 -0
- package/data/build/dist/host/cli-adapters/delegate-dispatch.d.ts +2 -1
- package/data/build/dist/host/cli-adapters/delegate-dispatch.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/delegate-dispatch.js +14 -61
- package/data/build/dist/host/cli-adapters/delegate-dispatch.js.map +1 -1
- package/data/build/dist/host/cli-adapters/delegation-authorization.d.ts +19 -0
- package/data/build/dist/host/cli-adapters/delegation-authorization.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/delegation-authorization.js +49 -0
- package/data/build/dist/host/cli-adapters/delegation-authorization.js.map +1 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.d.ts +34 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.js +121 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.js.map +1 -0
- package/data/build/dist/host/cli-adapters/driver.d.ts +6 -0
- package/data/build/dist/host/cli-adapters/driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/feature.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/feature.js +269 -18
- package/data/build/dist/host/cli-adapters/feature.js.map +1 -1
- package/data/build/dist/host/cli-adapters/kiro-driver.d.ts +12 -0
- package/data/build/dist/host/cli-adapters/kiro-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/kiro-driver.js +18 -0
- package/data/build/dist/host/cli-adapters/kiro-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/legacy-session-adapter.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/legacy-session-adapter.js +11 -0
- package/data/build/dist/host/cli-adapters/legacy-session-adapter.js.map +1 -1
- package/data/build/dist/host/cli-adapters/model-catalog.d.ts +5 -0
- package/data/build/dist/host/cli-adapters/model-catalog.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/model-catalog.js +130 -0
- package/data/build/dist/host/cli-adapters/model-catalog.js.map +1 -1
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.d.ts +33 -3
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.js +115 -9
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.js.map +1 -1
- package/data/build/dist/host/cli-adapters/native-team-subagent.d.ts +14 -2
- package/data/build/dist/host/cli-adapters/native-team-subagent.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/native-team-subagent.js +23 -4
- package/data/build/dist/host/cli-adapters/native-team-subagent.js.map +1 -1
- package/data/build/dist/host/cli-adapters/new-api-subscription.d.ts +75 -0
- package/data/build/dist/host/cli-adapters/new-api-subscription.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/new-api-subscription.js +959 -0
- package/data/build/dist/host/cli-adapters/new-api-subscription.js.map +1 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/opencode-driver.js +9 -7
- package/data/build/dist/host/cli-adapters/opencode-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +33 -3
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/provider-subscription.js +158 -40
- package/data/build/dist/host/cli-adapters/provider-subscription.js.map +1 -1
- package/data/build/dist/host/cli-adapters/qoder-driver.d.ts +71 -0
- package/data/build/dist/host/cli-adapters/qoder-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/qoder-driver.js +553 -0
- package/data/build/dist/host/cli-adapters/qoder-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.d.ts +31 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.js +178 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.js.map +1 -0
- package/data/build/dist/host/cli-adapters/registry.d.ts +41 -2
- package/data/build/dist/host/cli-adapters/registry.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/registry.js +187 -18
- package/data/build/dist/host/cli-adapters/registry.js.map +1 -1
- package/data/build/dist/host/cli-adapters/session-store.d.ts +4 -0
- package/data/build/dist/host/cli-adapters/session-store.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/session-store.js +18 -2
- package/data/build/dist/host/cli-adapters/session-store.js.map +1 -1
- package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts +14 -1
- package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/standard-stream-driver.js +121 -23
- package/data/build/dist/host/cli-adapters/standard-stream-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +10 -1
- package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/stream-normalizer.js +23 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.js.map +1 -1
- package/data/build/dist/host/cli-adapters/subagent-tool.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/subagent-tool.js +53 -7
- package/data/build/dist/host/cli-adapters/subagent-tool.js.map +1 -1
- package/data/build/dist/host/cli-bridge/bridge-server.d.ts +5 -0
- package/data/build/dist/host/cli-bridge/bridge-server.d.ts.map +1 -1
- package/data/build/dist/host/cli-bridge/bridge-server.js +7 -2
- package/data/build/dist/host/cli-bridge/bridge-server.js.map +1 -1
- package/data/build/dist/host/cli-bridge/command-code-mod.d.ts +5 -1
- package/data/build/dist/host/cli-bridge/command-code-mod.d.ts.map +1 -1
- package/data/build/dist/host/cli-bridge/command-code-mod.js +43 -12
- package/data/build/dist/host/cli-bridge/command-code-mod.js.map +1 -1
- package/data/build/dist/host/cli-bridge/dispatch.d.ts.map +1 -1
- package/data/build/dist/host/cli-bridge/dispatch.js +43 -5
- package/data/build/dist/host/cli-bridge/dispatch.js.map +1 -1
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.js +24 -5
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.js.map +1 -1
- package/data/build/dist/host/features/peer-host.d.ts +21 -1
- package/data/build/dist/host/features/peer-host.d.ts.map +1 -1
- package/data/build/dist/host/features/peer-host.js +174 -30
- package/data/build/dist/host/features/peer-host.js.map +1 -1
- package/data/build/dist/host/features/types.d.ts +2 -0
- package/data/build/dist/host/features/types.d.ts.map +1 -1
- package/data/build/dist/host/index.d.ts +11 -1
- package/data/build/dist/host/index.d.ts.map +1 -1
- package/data/build/dist/host/index.js +12 -2
- package/data/build/dist/host/index.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.js +6 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.d.ts +2 -0
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.js +26 -7
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.js.map +1 -1
- package/data/build/dist/host/native-session-bridge.d.ts.map +1 -1
- package/data/build/dist/host/native-session-bridge.js +36 -7
- package/data/build/dist/host/native-session-bridge.js.map +1 -1
- package/data/build/dist/host/rpc.js +5 -2
- package/data/build/dist/host/rpc.js.map +1 -1
- package/data/build/dist/host/settings.d.ts.map +1 -1
- package/data/build/dist/host/settings.js +12 -5
- package/data/build/dist/host/settings.js.map +1 -1
- package/data/build/dist/host/terminal/backends/local-pty-backend.d.ts.map +1 -1
- package/data/build/dist/host/terminal/backends/local-pty-backend.js +14 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.js.map +1 -1
- package/data/build/dist/host/terminal/backends/tmux-backend.d.ts +40 -1
- package/data/build/dist/host/terminal/backends/tmux-backend.d.ts.map +1 -1
- package/data/build/dist/host/terminal/backends/tmux-backend.js +291 -18
- package/data/build/dist/host/terminal/backends/tmux-backend.js.map +1 -1
- package/data/build/dist/host/terminal/runtime-adapter.d.ts +32 -0
- package/data/build/dist/host/terminal/runtime-adapter.d.ts.map +1 -1
- package/data/build/dist/host/terminal/runtime-adapter.js +8 -0
- package/data/build/dist/host/terminal/runtime-adapter.js.map +1 -1
- package/data/build/dist/host/terminal/runtime-manager.d.ts +3 -0
- package/data/build/dist/host/terminal/runtime-manager.d.ts.map +1 -1
- package/data/build/dist/host/terminal/runtime-manager.js +92 -4
- package/data/build/dist/host/terminal/runtime-manager.js.map +1 -1
- package/data/build/dist/host/terminal/terminal-controller.d.ts.map +1 -1
- package/data/build/dist/host/terminal/terminal-controller.js +58 -6
- package/data/build/dist/host/terminal/terminal-controller.js.map +1 -1
- package/data/build/dist/host/terminal/terminal-process-service.d.ts.map +1 -1
- package/data/build/dist/host/terminal/terminal-process-service.js +12 -2
- package/data/build/dist/host/terminal/terminal-process-service.js.map +1 -1
- package/data/build/dist/host/terminal/terminal-service.d.ts +41 -4
- package/data/build/dist/host/terminal/terminal-service.d.ts.map +1 -1
- package/data/build/dist/host/terminal/terminal-service.js +551 -61
- package/data/build/dist/host/terminal/terminal-service.js.map +1 -1
- package/data/build/dist/index.d.ts +2 -2
- package/data/build/dist/index.d.ts.map +1 -1
- package/data/build/dist/index.js +2 -2
- package/data/build/dist/index.js.map +1 -1
- package/data/build/dist/shared/contracts/cli-adapter.d.ts +64 -2
- package/data/build/dist/shared/contracts/cli-adapter.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/config.d.ts +54 -11
- package/data/build/dist/shared/contracts/config.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/config.js +52 -8
- package/data/build/dist/shared/contracts/config.js.map +1 -1
- package/data/build/dist/shared/contracts/subscription.d.ts +5 -1
- package/data/build/dist/shared/contracts/subscription.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/subscription.js.map +1 -1
- package/data/build/dist/shared/contracts/terminal.d.ts +8 -1
- package/data/build/dist/shared/contracts/terminal.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/version.d.ts +1 -1
- package/data/build/dist/shared/contracts/version.js +1 -1
- package/data/build/dist/shared/debug.d.ts +8 -0
- package/data/build/dist/shared/debug.d.ts.map +1 -1
- package/data/build/dist/shared/debug.js +43 -7
- package/data/build/dist/shared/debug.js.map +1 -1
- package/data/build/dist/shared/delegation-carrier.d.ts +24 -0
- package/data/build/dist/shared/delegation-carrier.d.ts.map +1 -0
- package/data/build/dist/shared/delegation-carrier.js +111 -0
- package/data/build/dist/shared/delegation-carrier.js.map +1 -0
- package/data/build/dist/shared/index.d.ts +2 -2
- package/data/build/dist/shared/index.d.ts.map +1 -1
- package/data/build/dist/shared/index.js +2 -2
- package/data/build/dist/shared/index.js.map +1 -1
- package/data/build/dist/shared/terminal-input.d.ts +8 -0
- package/data/build/dist/shared/terminal-input.d.ts.map +1 -0
- package/data/build/dist/shared/terminal-input.js +10 -0
- package/data/build/dist/shared/terminal-input.js.map +1 -0
- package/data/build/dist/transport/debug.d.ts +7 -0
- package/data/build/dist/transport/debug.d.ts.map +1 -1
- package/data/build/dist/transport/debug.js +33 -5
- package/data/build/dist/transport/debug.js.map +1 -1
- package/data/build/dist/transport/index.d.ts +1 -1
- package/data/build/dist/transport/index.d.ts.map +1 -1
- package/data/build/dist/transport/index.js +1 -1
- package/data/build/dist/transport/index.js.map +1 -1
- package/data/build/dist/typert.host.js +1 -1
- package/data/build/dist/typert.host.js.map +1 -1
- package/package.json +1 -1
- package/profile/README.md +2 -2
- package/profile/package.json +2 -2
- package/profile/version.json +1 -1
- package/version.json +1 -1
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from 'node:fs';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
5
|
+
import { knownCommandCodeContextWindow } from './model-catalog.js';
|
|
6
|
+
const COMMAND_CODE_MAX_TITLE_LENGTH = 48;
|
|
7
|
+
const COMMAND_CODE_HISTORY_CACHE_MAX_ENTRIES = 64;
|
|
8
|
+
const COMMAND_CODE_HISTORY_CACHE_MAX_BYTES = 32 * 1024 * 1024;
|
|
9
|
+
const COMMAND_CODE_HISTORY_FALLBACK_INTERVAL_MS = 5_000;
|
|
10
|
+
/**
|
|
11
|
+
* Command Code 原生 JSONL 的只读历史层。
|
|
12
|
+
*
|
|
13
|
+
* 运行层负责启动 CLI;本类只操作 Provider canonical transcript,避免把 DSH
|
|
14
|
+
* 会话索引误当成 Provider 历史。方法名与父仓库 Provider Adapter 保持一致,
|
|
15
|
+
* 供 Host RPC 或后续原生历史投影按需接入。
|
|
16
|
+
*/
|
|
17
|
+
export class CommandCodeHistory {
|
|
18
|
+
homeDirectory;
|
|
19
|
+
readStatus;
|
|
20
|
+
cache = new Map();
|
|
21
|
+
cacheBytes = 0;
|
|
22
|
+
constructor(homeDirectory = join(homedir(), '.commandcode'), options = {}) {
|
|
23
|
+
this.homeDirectory = homeDirectory;
|
|
24
|
+
this.readStatus = options.readStatus;
|
|
25
|
+
}
|
|
26
|
+
async detectSessions(workspacePath) {
|
|
27
|
+
return (await this.detectSessionsDetailed(workspacePath)).sessions;
|
|
28
|
+
}
|
|
29
|
+
async detectSessionsDetailed(workspacePath) {
|
|
30
|
+
const target = normalizeWorkspace(workspacePath);
|
|
31
|
+
const projectsRoot = join(this.homeDirectory, 'projects');
|
|
32
|
+
const sessions = [];
|
|
33
|
+
let invalidLineCount = 0;
|
|
34
|
+
let incompleteTailCount = 0;
|
|
35
|
+
for (const path of walkJsonlFiles(projectsRoot)) {
|
|
36
|
+
const parsed = readTranscript(path);
|
|
37
|
+
invalidLineCount += parsed.invalidLineCount;
|
|
38
|
+
incompleteTailCount += parsed.incompleteTailCount;
|
|
39
|
+
const session = parsed.records.find((record) => record.type === 'session') ?? parsed.records[0];
|
|
40
|
+
const cwd = text(session?.cwd);
|
|
41
|
+
if (cwd === '' || normalizeWorkspace(cwd) !== target)
|
|
42
|
+
continue;
|
|
43
|
+
const providerSessionId = text(session?.id ?? session?.sessionId) || basename(path, '.jsonl');
|
|
44
|
+
const messages = this.parseMessages(path, providerSessionId, parsed.records, parsed.lineNumbers);
|
|
45
|
+
const stats = statSafe(path);
|
|
46
|
+
if (stats === null)
|
|
47
|
+
continue;
|
|
48
|
+
sessions.push({
|
|
49
|
+
provider: 'command-code',
|
|
50
|
+
providerSessionId,
|
|
51
|
+
title: transcriptTitle(parsed.records, messages, path),
|
|
52
|
+
workspacePath,
|
|
53
|
+
rawStoreRef: path,
|
|
54
|
+
isArchived: readArchived(path),
|
|
55
|
+
lastMessageAt: messages.at(-1)?.timestamp ?? (text(parsed.records.at(-1)?.timestamp) || null),
|
|
56
|
+
messageCount: messages.length,
|
|
57
|
+
sourceMtimeMs: stats.mtimeMs,
|
|
58
|
+
sourceSizeBytes: stats.size,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
sessions.sort((left, right) => (right.lastMessageAt ?? '').localeCompare(left.lastMessageAt ?? ''));
|
|
62
|
+
return { sessions, isComplete: invalidLineCount === 0 && incompleteTailCount === 0, invalidLineCount, incompleteTailCount };
|
|
63
|
+
}
|
|
64
|
+
async startSession(workspacePath, options = {}) {
|
|
65
|
+
const providerSessionId = randomUUID();
|
|
66
|
+
const directory = join(this.homeDirectory, 'projects', workspaceSlug(workspacePath));
|
|
67
|
+
const filePath = join(directory, `${providerSessionId}.jsonl`);
|
|
68
|
+
mkdirSync(directory, { recursive: true });
|
|
69
|
+
const timestamp = new Date().toISOString();
|
|
70
|
+
const initialPrompt = options.initialPrompt?.trim() ?? '';
|
|
71
|
+
const lines = [{ type: 'session', version: 3, id: providerSessionId, timestamp, cwd: workspacePath }];
|
|
72
|
+
if (initialPrompt !== '')
|
|
73
|
+
lines.push({ type: 'message', id: randomUUID(), parentId: null, timestamp, sessionId: providerSessionId, message: { role: 'user', content: [{ type: 'text', text: initialPrompt }], meta: { source: 'user', createdAt: Date.parse(timestamp) } } });
|
|
74
|
+
writeFileSync(filePath, `${lines.map((line) => JSON.stringify(line)).join('\n')}\n`, 'utf8');
|
|
75
|
+
const stats = statSafe(filePath);
|
|
76
|
+
const messages = this.getMessages(filePath, providerSessionId);
|
|
77
|
+
return { session: { provider: 'command-code', providerSessionId, title: normalizeTitle(initialPrompt) || 'New Command Code session', workspacePath, rawStoreRef: filePath, isArchived: false, lastMessageAt: timestamp, messageCount: messages.length, sourceMtimeMs: stats.mtimeMs, sourceSizeBytes: stats.size }, initialCursor: encodeCursor(messages.length) };
|
|
78
|
+
}
|
|
79
|
+
async resumeSession(providerSessionId, rawStoreRef) {
|
|
80
|
+
const filePath = this.requireSessionFilePath(providerSessionId, rawStoreRef);
|
|
81
|
+
return { provider: 'command-code', providerSessionId, resumedAt: new Date().toISOString(), rawStoreRef: filePath };
|
|
82
|
+
}
|
|
83
|
+
async sendMessage(providerSessionId, rawStoreRef, content) {
|
|
84
|
+
const filePath = this.requireSessionFilePath(providerSessionId, rawStoreRef);
|
|
85
|
+
const acceptedAt = new Date().toISOString();
|
|
86
|
+
const textContent = content;
|
|
87
|
+
if (textContent.trim() === '')
|
|
88
|
+
throw new Error('content 不能为空');
|
|
89
|
+
const recordId = randomUUID();
|
|
90
|
+
appendFileSync(filePath, `${JSON.stringify({ type: 'message', id: recordId, parentId: null, timestamp: acceptedAt, sessionId: providerSessionId, message: { role: 'user', content: [{ type: 'text', text: textContent }], meta: { source: 'user', createdAt: Date.parse(acceptedAt) } } })}\n`, 'utf8');
|
|
91
|
+
this.deleteCached(filePath);
|
|
92
|
+
const message = this.getMessages(filePath, providerSessionId).at(-1);
|
|
93
|
+
if (message === undefined)
|
|
94
|
+
throw new Error('PROVIDER_HISTORY_WRITE_FAILED');
|
|
95
|
+
return { acceptedAt, message };
|
|
96
|
+
}
|
|
97
|
+
async readSessionHistory(providerSessionId, rawStoreRef, cursor, limit, direction = 'forward') {
|
|
98
|
+
const filePath = this.resolveSessionFilePath(providerSessionId, rawStoreRef);
|
|
99
|
+
if (filePath === null)
|
|
100
|
+
return { messages: [], cursor, nextCursor: null, total: 0 };
|
|
101
|
+
const messages = this.getMessages(filePath, providerSessionId);
|
|
102
|
+
return sliceHistory(messages, cursor, limit, direction);
|
|
103
|
+
}
|
|
104
|
+
async readSessionHistoryDelta(providerSessionId, rawStoreRef, cursor, limit, direction = 'forward') {
|
|
105
|
+
const filePath = this.resolveSessionFilePath(providerSessionId, rawStoreRef);
|
|
106
|
+
if (filePath === null)
|
|
107
|
+
return { messages: [], cursor, nextCursor: null, total: 0, mode: 'reset_required', bytesRead: 0, recordsParsed: 0 };
|
|
108
|
+
const previous = this.cache.get(filePath);
|
|
109
|
+
const stats = statSafe(filePath);
|
|
110
|
+
if (stats === null)
|
|
111
|
+
return { messages: [], cursor, nextCursor: null, total: 0, mode: 'reset_required', bytesRead: 0, recordsParsed: 0 };
|
|
112
|
+
const messages = this.getMessages(filePath, providerSessionId);
|
|
113
|
+
const current = this.cache.get(filePath);
|
|
114
|
+
const mode = previous === undefined
|
|
115
|
+
? 'seed'
|
|
116
|
+
: previous.identity !== current.identity || stats.size < previous.size
|
|
117
|
+
? 'reset_required'
|
|
118
|
+
: stats.size === previous.size ? 'unchanged' : 'append';
|
|
119
|
+
const page = sliceHistory(messages, cursor, limit, direction);
|
|
120
|
+
return { ...page, mode, bytesRead: mode === 'unchanged' ? 0 : Math.max(0, stats.size - (previous?.size ?? 0)), recordsParsed: mode === 'unchanged' ? 0 : Math.max(0, current.recordCount - (previous?.recordCount ?? 0)) };
|
|
121
|
+
}
|
|
122
|
+
subscribeSession(providerSessionId, rawStoreRef, cursor, limit, onEvent) {
|
|
123
|
+
const filePath = this.resolveSessionFilePath(providerSessionId, rawStoreRef);
|
|
124
|
+
if (filePath === null)
|
|
125
|
+
return { close() { } };
|
|
126
|
+
let closed = false;
|
|
127
|
+
let currentCursor = cursor;
|
|
128
|
+
let watcher;
|
|
129
|
+
const fallbackTimer = setInterval(() => { ensureWatcher(); void refresh(); }, COMMAND_CODE_HISTORY_FALLBACK_INTERVAL_MS);
|
|
130
|
+
fallbackTimer.unref?.();
|
|
131
|
+
let running = false;
|
|
132
|
+
const refresh = async () => {
|
|
133
|
+
if (closed || running)
|
|
134
|
+
return;
|
|
135
|
+
running = true;
|
|
136
|
+
try {
|
|
137
|
+
const delta = await this.readSessionHistoryDelta(providerSessionId, filePath, currentCursor, limit);
|
|
138
|
+
if (!closed && delta.mode !== 'unchanged' && delta.messages.length > 0) {
|
|
139
|
+
currentCursor = delta.cursor;
|
|
140
|
+
await onEvent({ messages: delta.messages, cursor: delta.cursor });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
running = false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const ensureWatcher = () => {
|
|
148
|
+
if (closed || watcher !== undefined || !existsSync(filePath))
|
|
149
|
+
return;
|
|
150
|
+
try {
|
|
151
|
+
watcher = watch(filePath, (eventType) => {
|
|
152
|
+
if (eventType === 'rename') {
|
|
153
|
+
watcher?.close();
|
|
154
|
+
watcher = undefined;
|
|
155
|
+
}
|
|
156
|
+
void refresh();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
watcher = undefined;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
ensureWatcher();
|
|
164
|
+
return {
|
|
165
|
+
close: () => {
|
|
166
|
+
if (closed)
|
|
167
|
+
return;
|
|
168
|
+
closed = true;
|
|
169
|
+
watcher?.close();
|
|
170
|
+
watcher = undefined;
|
|
171
|
+
clearInterval(fallbackTimer);
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async readSessionTitle(providerSessionId, rawStoreRef) {
|
|
176
|
+
const filePath = this.resolveSessionFilePath(providerSessionId, rawStoreRef);
|
|
177
|
+
if (filePath === null)
|
|
178
|
+
return '';
|
|
179
|
+
const parsed = readTranscript(filePath);
|
|
180
|
+
return transcriptTitle(parsed.records, this.getMessages(filePath, providerSessionId), filePath);
|
|
181
|
+
}
|
|
182
|
+
async renameSessionTitle(providerSessionId, rawStoreRef, title) {
|
|
183
|
+
const filePath = this.requireSessionFilePath(providerSessionId, rawStoreRef);
|
|
184
|
+
const normalized = title.trim().replace(/[\r\n]+/gu, ' ').replace(/\s+/gu, ' ').slice(0, COMMAND_CODE_MAX_TITLE_LENGTH);
|
|
185
|
+
appendFileSync(filePath, `${JSON.stringify({ type: 'title', sessionId: providerSessionId, title: normalized })}\n`, 'utf8');
|
|
186
|
+
this.deleteCached(filePath);
|
|
187
|
+
return normalized;
|
|
188
|
+
}
|
|
189
|
+
async updateSessionArchiveState(providerSessionId, rawStoreRef, isArchived) {
|
|
190
|
+
const filePath = this.requireSessionFilePath(providerSessionId, rawStoreRef);
|
|
191
|
+
const metadataPath = join(dirname(filePath), '.meta.json');
|
|
192
|
+
let metadata = {};
|
|
193
|
+
try {
|
|
194
|
+
metadata = JSON.parse(readFileSync(metadataPath, 'utf8'));
|
|
195
|
+
}
|
|
196
|
+
catch { /* 缺少或损坏的 meta 视为默认空对象 */ }
|
|
197
|
+
metadata.archived = isArchived;
|
|
198
|
+
mkdirSync(dirname(metadataPath), { recursive: true });
|
|
199
|
+
writeFileSync(metadataPath, `${JSON.stringify(metadata)}\n`, 'utf8');
|
|
200
|
+
return { rawStoreRef: filePath, isArchived };
|
|
201
|
+
}
|
|
202
|
+
async deleteSession(providerSessionId, rawStoreRef) {
|
|
203
|
+
const filePath = this.requireSessionFilePath(providerSessionId, rawStoreRef);
|
|
204
|
+
rmSync(filePath, { force: true });
|
|
205
|
+
this.deleteCached(filePath);
|
|
206
|
+
}
|
|
207
|
+
async readContextUsage(providerSessionId, rawStoreRef) {
|
|
208
|
+
const filePath = this.resolveSessionFilePath(providerSessionId, rawStoreRef);
|
|
209
|
+
if (filePath === null)
|
|
210
|
+
return null;
|
|
211
|
+
const parsed = readTranscript(filePath);
|
|
212
|
+
const usage = parsed.records.map((record, index) => readUsage(record, index)).filter((value) => value !== null).at(-1);
|
|
213
|
+
if (usage === undefined)
|
|
214
|
+
return null;
|
|
215
|
+
const session = parsed.records.find((record) => record.type === 'session');
|
|
216
|
+
const modelId = usage.model || text(session?.model) || null;
|
|
217
|
+
const status = this.readStatus === undefined
|
|
218
|
+
? null
|
|
219
|
+
: await this.readStatus(text(session?.cwd) || dirname(filePath)).catch(() => null);
|
|
220
|
+
const statusModel = text(status?.model).trim().toLowerCase();
|
|
221
|
+
const statusWindow = readNumber(status?.contextWindow ?? status?.context_window);
|
|
222
|
+
const runtimeWindow = statusWindow > 0 && modelId !== null && statusModel === modelId.trim().toLowerCase()
|
|
223
|
+
? statusWindow
|
|
224
|
+
: null;
|
|
225
|
+
const contextWindow = usage.contextWindow ?? runtimeWindow ?? knownCommandCodeContextWindow(modelId === null ? undefined : modelId) ?? null;
|
|
226
|
+
return {
|
|
227
|
+
provider: 'command-code',
|
|
228
|
+
promptTokens: usage.inputTokens,
|
|
229
|
+
outputTokens: usage.outputTokens,
|
|
230
|
+
cacheReadTokens: usage.cacheReadTokens,
|
|
231
|
+
cacheWriteTokens: usage.cacheWriteTokens,
|
|
232
|
+
contextWindow,
|
|
233
|
+
usageRatio: contextWindow === null || contextWindow <= 0 ? null : Math.min(1, Math.max(0, usage.inputTokens / contextWindow)),
|
|
234
|
+
modelId,
|
|
235
|
+
capturedAt: usage.timestamp || null,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
async readSessionStats(providerSessionId, rawStoreRef) {
|
|
239
|
+
const filePath = this.resolveSessionFilePath(providerSessionId, rawStoreRef);
|
|
240
|
+
if (filePath === null)
|
|
241
|
+
return null;
|
|
242
|
+
const records = readTranscript(filePath).records;
|
|
243
|
+
const byMessageId = new Map();
|
|
244
|
+
for (const usage of records.map((record, index) => readUsage(record, index)).filter((value) => value !== null)) {
|
|
245
|
+
byMessageId.set(usage.messageId, usage);
|
|
246
|
+
}
|
|
247
|
+
const usages = [...byMessageId.values()];
|
|
248
|
+
if (usages.length === 0)
|
|
249
|
+
return null;
|
|
250
|
+
const inputTokens = usages.reduce((sum, value) => sum + value.inputTokens, 0);
|
|
251
|
+
const outputTokens = usages.reduce((sum, value) => sum + value.outputTokens, 0);
|
|
252
|
+
return {
|
|
253
|
+
provider: 'command-code',
|
|
254
|
+
inputTokens,
|
|
255
|
+
outputTokens,
|
|
256
|
+
cacheReadTokens: usages.reduce((sum, value) => sum + value.cacheReadTokens, 0),
|
|
257
|
+
cacheWriteTokens: usages.reduce((sum, value) => sum + value.cacheWriteTokens, 0),
|
|
258
|
+
totalTokens: inputTokens + outputTokens,
|
|
259
|
+
turns: countTurns(records),
|
|
260
|
+
steps: usages.length,
|
|
261
|
+
capturedAt: usages.at(-1)?.timestamp || null,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async forkSession(providerSessionId, workspacePath, options) {
|
|
265
|
+
const sourcePath = this.requireSessionFilePath(providerSessionId, options.rawStoreRef);
|
|
266
|
+
const sourceMessages = this.getMessages(sourcePath, providerSessionId).filter((message) => (message.role === 'user' || message.role === 'assistant') && message.kind === 'text' && message.content.trim() !== '');
|
|
267
|
+
const sourceIndex = options.sourceType === 'message' && options.sourceMessageId
|
|
268
|
+
? sourceMessages.findIndex((message) => message.messageId === options.sourceMessageId)
|
|
269
|
+
: -1;
|
|
270
|
+
const inherited = sourceIndex >= 0 ? sourceMessages.slice(0, sourceIndex + 1) : sourceMessages;
|
|
271
|
+
const forkedId = randomUUID();
|
|
272
|
+
const directory = join(this.homeDirectory, 'projects', workspaceSlug(workspacePath));
|
|
273
|
+
const targetPath = join(directory, `${forkedId}.jsonl`);
|
|
274
|
+
mkdirSync(directory, { recursive: true });
|
|
275
|
+
const timestamp = new Date().toISOString();
|
|
276
|
+
const lines = [{ type: 'session', version: 3, id: forkedId, timestamp, cwd: workspacePath }, ...inherited.map((message) => ({ type: 'message', id: randomUUID(), parentId: null, timestamp: message.timestamp, message: { role: message.role, content: [{ type: 'text', text: message.content }] } }))];
|
|
277
|
+
writeFileSync(targetPath, `${lines.map((line) => JSON.stringify(line)).join('\n')}\n`, 'utf8');
|
|
278
|
+
const stats = statSafe(targetPath);
|
|
279
|
+
const session = {
|
|
280
|
+
provider: 'command-code', providerSessionId: forkedId, title: transcriptTitle([], inherited, targetPath), workspacePath,
|
|
281
|
+
rawStoreRef: targetPath, isArchived: false, lastMessageAt: inherited.at(-1)?.timestamp ?? timestamp,
|
|
282
|
+
messageCount: inherited.length, sourceMtimeMs: stats.mtimeMs, sourceSizeBytes: stats.size,
|
|
283
|
+
};
|
|
284
|
+
return { session, inheritedPrefixMessageCount: inherited.length, forkSourceType: options.sourceType, providerSourceMessageId: options.sourceMessageId ?? null };
|
|
285
|
+
}
|
|
286
|
+
getMessages(filePath, providerSessionId) {
|
|
287
|
+
const stats = statSafe(filePath);
|
|
288
|
+
if (stats === null)
|
|
289
|
+
return [];
|
|
290
|
+
const identity = `${stats.dev}:${stats.ino}`;
|
|
291
|
+
const cached = this.cache.get(filePath);
|
|
292
|
+
if (cached?.identity === identity && cached.providerSessionId === providerSessionId && cached.size === stats.size)
|
|
293
|
+
return cached.messages;
|
|
294
|
+
const parsed = readTranscript(filePath);
|
|
295
|
+
const messages = this.parseMessages(filePath, providerSessionId, parsed.records, parsed.lineNumbers);
|
|
296
|
+
this.setCached(filePath, { filePath, providerSessionId, identity, size: stats.size, mtimeMs: stats.mtimeMs, messages, recordCount: parsed.records.length });
|
|
297
|
+
return messages;
|
|
298
|
+
}
|
|
299
|
+
setCached(filePath, value) {
|
|
300
|
+
const previous = this.cache.get(filePath);
|
|
301
|
+
if (previous !== undefined)
|
|
302
|
+
this.cacheBytes -= previous.size;
|
|
303
|
+
this.cache.set(filePath, value);
|
|
304
|
+
this.cacheBytes += value.size;
|
|
305
|
+
while (this.cache.size > COMMAND_CODE_HISTORY_CACHE_MAX_ENTRIES || this.cacheBytes > COMMAND_CODE_HISTORY_CACHE_MAX_BYTES) {
|
|
306
|
+
const oldest = this.cache.keys().next().value;
|
|
307
|
+
if (oldest === undefined)
|
|
308
|
+
break;
|
|
309
|
+
this.deleteCached(oldest);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
deleteCached(filePath) {
|
|
313
|
+
const cached = this.cache.get(filePath);
|
|
314
|
+
if (cached === undefined)
|
|
315
|
+
return;
|
|
316
|
+
this.cache.delete(filePath);
|
|
317
|
+
this.cacheBytes = Math.max(0, this.cacheBytes - cached.size);
|
|
318
|
+
}
|
|
319
|
+
parseMessages(filePath, providerSessionId, records, lineNumbers) {
|
|
320
|
+
const result = [];
|
|
321
|
+
const positions = new Map();
|
|
322
|
+
records.forEach((record, recordIndex) => {
|
|
323
|
+
if (record.type !== 'message')
|
|
324
|
+
return;
|
|
325
|
+
const message = asRecord(record.message);
|
|
326
|
+
const role = normalizeRole(message?.role);
|
|
327
|
+
const content = Array.isArray(message?.content) ? message.content : [message?.content];
|
|
328
|
+
content.forEach((part, partIndex) => {
|
|
329
|
+
const block = asRecord(part);
|
|
330
|
+
if (block === null)
|
|
331
|
+
return;
|
|
332
|
+
const type = text(block.type).toLowerCase();
|
|
333
|
+
const callId = text(block.id ?? block.tool_use_id ?? block.toolCallId ?? block.callId);
|
|
334
|
+
const messageId = `${text(record.id) || text(message?.id) || recordIndex}:${partIndex}:${type}:${callId}`;
|
|
335
|
+
const rawRef = `${filePath}#${lineNumbers?.get(record) ?? recordIndex + 1}:${partIndex}`;
|
|
336
|
+
const timestamp = text(record.timestamp) || new Date().toISOString();
|
|
337
|
+
const push = (entry) => {
|
|
338
|
+
const normalized = { ...entry, messageId, providerSessionId, timestamp, sequence: 0, rawRef };
|
|
339
|
+
const existing = positions.get(messageId);
|
|
340
|
+
if (existing === undefined) {
|
|
341
|
+
positions.set(messageId, result.length);
|
|
342
|
+
result.push(normalized);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
result[existing] = normalized;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
if (type === 'thinking' || type === 'reasoning') {
|
|
349
|
+
push({ role: 'assistant', kind: 'thinking', content: text(block.thinking ?? block.text ?? block.content), toolCall: null });
|
|
350
|
+
}
|
|
351
|
+
else if (type === 'text' || type === 'output_text' || type === 'markdown') {
|
|
352
|
+
push({ role, kind: 'text', content: text(block.text ?? block.content), toolCall: null });
|
|
353
|
+
}
|
|
354
|
+
else if (type === 'tool_use' || type === 'tool_call' || type === 'function_call') {
|
|
355
|
+
const fn = asRecord(block.function);
|
|
356
|
+
const name = text(block.name ?? block.tool ?? fn?.name) || 'tool';
|
|
357
|
+
push({ role: 'assistant', kind: 'tool_call', content: '', toolCall: { callId: callId || messageId, name, input: stringify(block.input ?? fn?.arguments ?? {}), output: null, error: null, status: 'running' } });
|
|
358
|
+
}
|
|
359
|
+
else if (type === 'tool_result' || type === 'tool_return' || type === 'function_result') {
|
|
360
|
+
const error = block.error !== undefined || block.is_error === true;
|
|
361
|
+
const output = extractTextBlocks(block.content ?? block.output ?? block.result);
|
|
362
|
+
push({ role: 'tool', kind: 'tool_result', content: output, toolCall: { callId: callId || messageId, name: text(block.name) || 'tool', input: '', output: error ? null : output, error: error ? output : null, status: error ? 'failed' : 'completed' } });
|
|
363
|
+
}
|
|
364
|
+
else if (role === 'user' || role === 'assistant' || role === 'system') {
|
|
365
|
+
const value = extractTextBlocks(part);
|
|
366
|
+
if (value.trim() !== '')
|
|
367
|
+
push({ role, kind: 'text', content: value, toolCall: null });
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
return result.map((message, index) => ({ ...message, sequence: index + 1 }));
|
|
372
|
+
}
|
|
373
|
+
resolveSessionFilePath(providerSessionId, rawStoreRef) {
|
|
374
|
+
const candidate = rawStoreRef.trim();
|
|
375
|
+
if (isSafeTranscriptPath(candidate, this.homeDirectory) && existsSync(candidate)) {
|
|
376
|
+
const filenameId = basename(candidate, '.jsonl');
|
|
377
|
+
const first = readTranscript(candidate).records.find((record) => record.type === 'session');
|
|
378
|
+
const recordedId = text(first?.id ?? first?.sessionId).trim();
|
|
379
|
+
if (filenameId === providerSessionId || recordedId === providerSessionId)
|
|
380
|
+
return candidate;
|
|
381
|
+
}
|
|
382
|
+
return this.findSessionFile(providerSessionId);
|
|
383
|
+
}
|
|
384
|
+
requireSessionFilePath(providerSessionId, rawStoreRef) {
|
|
385
|
+
const path = this.resolveSessionFilePath(providerSessionId, rawStoreRef);
|
|
386
|
+
if (path === null)
|
|
387
|
+
throw new Error('PROVIDER_SESSION_NOT_FOUND');
|
|
388
|
+
return path;
|
|
389
|
+
}
|
|
390
|
+
findSessionFile(providerSessionId) {
|
|
391
|
+
const root = resolve(join(this.homeDirectory, 'projects'));
|
|
392
|
+
for (const filePath of walkJsonlFiles(root)) {
|
|
393
|
+
if (basename(filePath, '.jsonl') === providerSessionId)
|
|
394
|
+
return filePath;
|
|
395
|
+
const first = readTranscript(filePath).records.find((record) => record.type === 'session');
|
|
396
|
+
if (text(first?.id ?? first?.sessionId).trim() === providerSessionId)
|
|
397
|
+
return filePath;
|
|
398
|
+
}
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function readUsage(record, recordIndex = 0) {
|
|
403
|
+
const usage = asRecord(record.usage) ?? asRecord(asRecord(record.event)?.usage) ?? asRecord(asRecord(record.result)?.usage);
|
|
404
|
+
if (usage === null)
|
|
405
|
+
return null;
|
|
406
|
+
const number = (...keys) => {
|
|
407
|
+
for (const key of keys) {
|
|
408
|
+
const value = usage[key];
|
|
409
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
410
|
+
return Math.max(0, value);
|
|
411
|
+
}
|
|
412
|
+
return 0;
|
|
413
|
+
};
|
|
414
|
+
const inputTokens = number('inputTokens', 'input_tokens', 'promptTokens', 'prompt_tokens');
|
|
415
|
+
const outputTokens = number('outputTokens', 'output_tokens', 'completionTokens', 'completion_tokens');
|
|
416
|
+
if (inputTokens === 0 && outputTokens === 0 && number('totalTokens', 'total_tokens') === 0)
|
|
417
|
+
return null;
|
|
418
|
+
const contextWindow = number('contextWindow', 'context_window') || readNumber(record.contextWindow ?? record.context_window);
|
|
419
|
+
return {
|
|
420
|
+
messageId: text(record.id ?? asRecord(record.message)?.id ?? asRecord(record.meta)?.messageId) || `record:${recordIndex}`,
|
|
421
|
+
inputTokens,
|
|
422
|
+
outputTokens,
|
|
423
|
+
cacheReadTokens: number('cacheReadTokens', 'cache_read_tokens', 'cachedInputTokens'),
|
|
424
|
+
cacheWriteTokens: number('cacheWriteTokens', 'cache_write_tokens'),
|
|
425
|
+
...(contextWindow > 0 ? { contextWindow } : {}),
|
|
426
|
+
model: text(usage.model ?? record.model),
|
|
427
|
+
timestamp: text(record.timestamp ?? asRecord(record.event)?.timestamp),
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function readNumber(value) {
|
|
431
|
+
const parsed = typeof value === 'number' ? value : Number(value);
|
|
432
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : 0;
|
|
433
|
+
}
|
|
434
|
+
/** 工具结果也会以 user 角色写回,但它不代表新的真实用户轮次。 */
|
|
435
|
+
function countTurns(records) {
|
|
436
|
+
return records.reduce((count, record) => {
|
|
437
|
+
if (record.type !== 'message')
|
|
438
|
+
return count;
|
|
439
|
+
const message = asRecord(record.message);
|
|
440
|
+
if (text(message?.role).trim().toLowerCase() !== 'user')
|
|
441
|
+
return count;
|
|
442
|
+
const parts = Array.isArray(message?.content) ? message.content : [];
|
|
443
|
+
if (parts.length === 0)
|
|
444
|
+
return count;
|
|
445
|
+
const isToolResult = parts.some((part) => {
|
|
446
|
+
const type = text(asRecord(part)?.type).trim().toLowerCase();
|
|
447
|
+
return type === 'tool_result' || type === 'tool_return' || type === 'function_result';
|
|
448
|
+
});
|
|
449
|
+
return isToolResult ? count : count + 1;
|
|
450
|
+
}, 0);
|
|
451
|
+
}
|
|
452
|
+
function sliceHistory(messages, cursor, limit, direction) {
|
|
453
|
+
const size = Math.max(1, Math.min(100, Math.floor(limit) || 50));
|
|
454
|
+
const offset = cursor === null
|
|
455
|
+
? (direction === 'backward' ? messages.length : 0)
|
|
456
|
+
: decodeCursor(cursor);
|
|
457
|
+
if (direction === 'backward') {
|
|
458
|
+
const start = Math.max(0, offset - size);
|
|
459
|
+
return { messages: messages.slice(start, offset), cursor: encodeCursor(offset), nextCursor: start > 0 ? encodeCursor(start) : null, total: messages.length };
|
|
460
|
+
}
|
|
461
|
+
const end = Math.min(messages.length, offset + size);
|
|
462
|
+
return { messages: messages.slice(offset, end), cursor: encodeCursor(end), nextCursor: end < messages.length ? encodeCursor(end) : null, total: messages.length };
|
|
463
|
+
}
|
|
464
|
+
function encodeCursor(index) {
|
|
465
|
+
return Buffer.from(JSON.stringify({ index: Math.max(0, Math.trunc(index)) }), 'utf8').toString('base64url');
|
|
466
|
+
}
|
|
467
|
+
function decodeCursor(cursor) {
|
|
468
|
+
try {
|
|
469
|
+
const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
|
|
470
|
+
const index = Number(value.index);
|
|
471
|
+
if (!Number.isFinite(index) || index < 0)
|
|
472
|
+
throw new Error('CURSOR_INVALID');
|
|
473
|
+
return Math.trunc(index);
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
// 兼容旧版本曾经暴露的十进制游标,已存在的分页链接不应突然失效。
|
|
477
|
+
const legacy = Number.parseInt(cursor, 10);
|
|
478
|
+
if (Number.isFinite(legacy) && legacy >= 0)
|
|
479
|
+
return legacy;
|
|
480
|
+
throw new Error('CURSOR_INVALID');
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function readTranscript(path) {
|
|
484
|
+
let content = '';
|
|
485
|
+
try {
|
|
486
|
+
content = readFileSync(path, 'utf8');
|
|
487
|
+
}
|
|
488
|
+
catch {
|
|
489
|
+
return { records: [], invalidLineCount: 1, incompleteTailCount: 0, lineNumbers: new Map() };
|
|
490
|
+
}
|
|
491
|
+
const lines = content.split(/\r?\n/u);
|
|
492
|
+
const completeFinalLine = /\r?\n$/u.test(content);
|
|
493
|
+
const records = [];
|
|
494
|
+
const lineNumbers = new Map();
|
|
495
|
+
let invalidLineCount = 0;
|
|
496
|
+
let incompleteTailCount = 0;
|
|
497
|
+
lines.forEach((line, index) => {
|
|
498
|
+
if (line.trim() === '')
|
|
499
|
+
return;
|
|
500
|
+
try {
|
|
501
|
+
const value = JSON.parse(line);
|
|
502
|
+
if (asRecord(value) === null)
|
|
503
|
+
invalidLineCount += 1;
|
|
504
|
+
else {
|
|
505
|
+
const record = value;
|
|
506
|
+
records.push(record);
|
|
507
|
+
lineNumbers.set(record, index + 1);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
catch {
|
|
511
|
+
// 末尾半行是 CLI 正在写入的正常瞬态;中间损坏行仍计入诊断。
|
|
512
|
+
if (index !== lines.length - 1 || completeFinalLine)
|
|
513
|
+
invalidLineCount += 1;
|
|
514
|
+
else if (looksLikeIncompleteJson(line))
|
|
515
|
+
incompleteTailCount += 1;
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
return { records, invalidLineCount, incompleteTailCount, lineNumbers };
|
|
519
|
+
}
|
|
520
|
+
function looksLikeIncompleteJson(value) {
|
|
521
|
+
const trimmed = value.trim();
|
|
522
|
+
if (!trimmed.startsWith('{') && !trimmed.startsWith('['))
|
|
523
|
+
return false;
|
|
524
|
+
let depth = 0;
|
|
525
|
+
let inString = false;
|
|
526
|
+
let escaping = false;
|
|
527
|
+
for (const char of trimmed) {
|
|
528
|
+
if (inString) {
|
|
529
|
+
if (escaping)
|
|
530
|
+
escaping = false;
|
|
531
|
+
else if (char === '\\')
|
|
532
|
+
escaping = true;
|
|
533
|
+
else if (char === '"')
|
|
534
|
+
inString = false;
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
if (char === '"')
|
|
538
|
+
inString = true;
|
|
539
|
+
else if (char === '{' || char === '[')
|
|
540
|
+
depth += 1;
|
|
541
|
+
else if (char === '}' || char === ']')
|
|
542
|
+
depth -= 1;
|
|
543
|
+
}
|
|
544
|
+
return depth > 0 || inString || escaping;
|
|
545
|
+
}
|
|
546
|
+
function extractTextBlocks(value) {
|
|
547
|
+
if (typeof value === 'string')
|
|
548
|
+
return value;
|
|
549
|
+
if (value === undefined || value === null)
|
|
550
|
+
return '';
|
|
551
|
+
if (Array.isArray(value)) {
|
|
552
|
+
const combined = value.map((item) => extractTextBlocks(item).trim()).filter(Boolean).join('\n');
|
|
553
|
+
return combined || stringify(value);
|
|
554
|
+
}
|
|
555
|
+
if (typeof value === 'object') {
|
|
556
|
+
const record = value;
|
|
557
|
+
for (const key of ['text', 'thinking', 'output', 'content', 'message']) {
|
|
558
|
+
const nested = extractTextBlocks(record[key]).trim();
|
|
559
|
+
if (nested)
|
|
560
|
+
return nested;
|
|
561
|
+
}
|
|
562
|
+
return stringify(value);
|
|
563
|
+
}
|
|
564
|
+
return text(value);
|
|
565
|
+
}
|
|
566
|
+
function transcriptTitle(records, messages, path) {
|
|
567
|
+
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
568
|
+
const record = records[index];
|
|
569
|
+
const metadata = asRecord(record?.meta);
|
|
570
|
+
const title = text(record?.title ?? record?.aiTitle ?? metadata?.title).trim();
|
|
571
|
+
if (title !== '')
|
|
572
|
+
return normalizeTitle(title);
|
|
573
|
+
}
|
|
574
|
+
return normalizeTitle(messages.find((message) => message.role === 'user' && message.kind === 'text' && message.content.trim() !== '')?.content ?? '')
|
|
575
|
+
|| basename(path, '.jsonl');
|
|
576
|
+
}
|
|
577
|
+
function normalizeTitle(value) {
|
|
578
|
+
return value.trim().replace(/[\r\n]+/gu, ' ').replace(/\s+/gu, ' ').slice(0, COMMAND_CODE_MAX_TITLE_LENGTH);
|
|
579
|
+
}
|
|
580
|
+
function readArchived(path) {
|
|
581
|
+
try {
|
|
582
|
+
const value = JSON.parse(readFileSync(join(dirname(path), '.meta.json'), 'utf8'));
|
|
583
|
+
return value.archived === true || value.isArchived === true;
|
|
584
|
+
}
|
|
585
|
+
catch {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function isSafeTranscriptPath(candidate, homeDirectory) {
|
|
590
|
+
const rootPath = resolve(join(homeDirectory, 'projects'));
|
|
591
|
+
let root = rootPath;
|
|
592
|
+
try {
|
|
593
|
+
if (existsSync(rootPath))
|
|
594
|
+
root = realpathSync(rootPath);
|
|
595
|
+
}
|
|
596
|
+
catch {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
const value = resolve(candidate);
|
|
600
|
+
let actualValue = value;
|
|
601
|
+
try {
|
|
602
|
+
if (existsSync(value))
|
|
603
|
+
actualValue = realpathSync(value);
|
|
604
|
+
}
|
|
605
|
+
catch {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
const relativePath = relative(root, actualValue);
|
|
609
|
+
return relativePath !== '' && !relativePath.startsWith('..') && actualValue.endsWith('.jsonl');
|
|
610
|
+
}
|
|
611
|
+
function walkJsonlFiles(root) {
|
|
612
|
+
const files = [];
|
|
613
|
+
const visit = (directory) => {
|
|
614
|
+
let entries;
|
|
615
|
+
try {
|
|
616
|
+
entries = readdirSync(directory);
|
|
617
|
+
}
|
|
618
|
+
catch {
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
for (const entry of entries) {
|
|
622
|
+
const path = join(directory, entry);
|
|
623
|
+
try {
|
|
624
|
+
const stats = statSync(path);
|
|
625
|
+
if (stats.isDirectory())
|
|
626
|
+
visit(path);
|
|
627
|
+
else if (stats.isFile() && entry.endsWith('.jsonl') && !entry.endsWith('.checkpoints.jsonl'))
|
|
628
|
+
files.push(path);
|
|
629
|
+
}
|
|
630
|
+
catch { /* 文件在扫描期间消失,跳过即可 */ }
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
visit(root);
|
|
634
|
+
return files;
|
|
635
|
+
}
|
|
636
|
+
function normalizeWorkspace(value) { return resolve(value).replace(/[\\/]+$/u, '').toLowerCase(); }
|
|
637
|
+
function workspaceSlug(value) {
|
|
638
|
+
return value.replace(/[\\/]+$/u, '').replace(/([a-z0-9])([A-Z])/g, '$1-$2').replaceAll(':', '-').replaceAll('\\', '-').replaceAll('/', '-').replace(/[^a-zA-Z0-9_-]+/gu, '-').replace(/-+/g, '-').replace(/^-+|-+$/g, '').toLowerCase();
|
|
639
|
+
}
|
|
640
|
+
function statSafe(path) {
|
|
641
|
+
try {
|
|
642
|
+
const stats = statSync(path);
|
|
643
|
+
return { size: stats.size, mtimeMs: stats.mtimeMs, dev: stats.dev, ino: stats.ino };
|
|
644
|
+
}
|
|
645
|
+
catch {
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function asRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : null; }
|
|
650
|
+
function text(value) { return typeof value === 'string' ? value : value === undefined || value === null ? '' : stringify(value); }
|
|
651
|
+
function stringify(value) { if (typeof value === 'string')
|
|
652
|
+
return value; try {
|
|
653
|
+
return JSON.stringify(value) ?? '';
|
|
654
|
+
}
|
|
655
|
+
catch {
|
|
656
|
+
return String(value);
|
|
657
|
+
} }
|
|
658
|
+
function normalizeRole(value) { return value === 'assistant' || value === 'tool' || value === 'system' ? value : 'user'; }
|
|
659
|
+
//# sourceMappingURL=command-code-history.js.map
|