@cjhyy/code-shell-core 0.5.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/agent/coordinator.d.ts +49 -0
- package/dist/agent/coordinator.js +77 -0
- package/dist/arena/arena.d.ts +43 -0
- package/dist/arena/arena.js +334 -0
- package/dist/arena/context/context-tools.d.ts +16 -0
- package/dist/arena/context/context-tools.js +231 -0
- package/dist/arena/detect-mode.d.ts +20 -0
- package/dist/arena/detect-mode.js +78 -0
- package/dist/arena/digest-builder.d.ts +25 -0
- package/dist/arena/digest-builder.js +120 -0
- package/dist/arena/index.d.ts +29 -0
- package/dist/arena/index.js +29 -0
- package/dist/arena/iterate/convergence.d.ts +25 -0
- package/dist/arena/iterate/convergence.js +103 -0
- package/dist/arena/iterate/formats/index.d.ts +22 -0
- package/dist/arena/iterate/formats/index.js +283 -0
- package/dist/arena/iterate/index.d.ts +11 -0
- package/dist/arena/iterate/index.js +9 -0
- package/dist/arena/iterate/iterative-arena.d.ts +23 -0
- package/dist/arena/iterate/iterative-arena.js +237 -0
- package/dist/arena/iterate/parse.d.ts +42 -0
- package/dist/arena/iterate/parse.js +123 -0
- package/dist/arena/iterate/phases/argue.d.ts +22 -0
- package/dist/arena/iterate/phases/argue.js +159 -0
- package/dist/arena/iterate/phases/revise.d.ts +16 -0
- package/dist/arena/iterate/phases/revise.js +62 -0
- package/dist/arena/iterate/phases/tournament.d.ts +34 -0
- package/dist/arena/iterate/phases/tournament.js +113 -0
- package/dist/arena/iterate/tools/web-tools.d.ts +13 -0
- package/dist/arena/iterate/tools/web-tools.js +54 -0
- package/dist/arena/iterate/types.d.ts +152 -0
- package/dist/arena/iterate/types.js +8 -0
- package/dist/arena/ledger.d.ts +47 -0
- package/dist/arena/ledger.js +151 -0
- package/dist/arena/lenses/architecture.d.ts +5 -0
- package/dist/arena/lenses/architecture.js +22 -0
- package/dist/arena/lenses/engineering.d.ts +5 -0
- package/dist/arena/lenses/engineering.js +22 -0
- package/dist/arena/lenses/general.d.ts +5 -0
- package/dist/arena/lenses/general.js +20 -0
- package/dist/arena/lenses/index.d.ts +16 -0
- package/dist/arena/lenses/index.js +47 -0
- package/dist/arena/lenses/product.d.ts +5 -0
- package/dist/arena/lenses/product.js +22 -0
- package/dist/arena/model-presets.d.ts +23 -0
- package/dist/arena/model-presets.js +44 -0
- package/dist/arena/phases/adjudication.d.ts +24 -0
- package/dist/arena/phases/adjudication.js +144 -0
- package/dist/arena/phases/build-consensus.d.ts +29 -0
- package/dist/arena/phases/build-consensus.js +86 -0
- package/dist/arena/phases/claim-registry.d.ts +26 -0
- package/dist/arena/phases/claim-registry.js +60 -0
- package/dist/arena/phases/cross-review.d.ts +45 -0
- package/dist/arena/phases/cross-review.js +224 -0
- package/dist/arena/phases/debate-rounds.d.ts +27 -0
- package/dist/arena/phases/debate-rounds.js +162 -0
- package/dist/arena/phases/participant-research.d.ts +38 -0
- package/dist/arena/phases/participant-research.js +317 -0
- package/dist/arena/phases/planning-detail-expansion.d.ts +38 -0
- package/dist/arena/phases/planning-detail-expansion.js +121 -0
- package/dist/arena/planner.d.ts +27 -0
- package/dist/arena/planner.js +312 -0
- package/dist/arena/providers/docs.d.ts +6 -0
- package/dist/arena/providers/docs.js +108 -0
- package/dist/arena/providers/git.d.ts +8 -0
- package/dist/arena/providers/git.js +174 -0
- package/dist/arena/providers/index.d.ts +32 -0
- package/dist/arena/providers/index.js +132 -0
- package/dist/arena/providers/none.d.ts +7 -0
- package/dist/arena/providers/none.js +11 -0
- package/dist/arena/providers/repo.d.ts +6 -0
- package/dist/arena/providers/repo.js +255 -0
- package/dist/arena/render/session.d.ts +17 -0
- package/dist/arena/render/session.js +190 -0
- package/dist/arena/render/terminal.d.ts +34 -0
- package/dist/arena/render/terminal.js +286 -0
- package/dist/arena/strategies/discussion.d.ts +25 -0
- package/dist/arena/strategies/discussion.js +143 -0
- package/dist/arena/strategies/index.d.ts +15 -0
- package/dist/arena/strategies/index.js +28 -0
- package/dist/arena/strategies/language-wrapper.d.ts +17 -0
- package/dist/arena/strategies/language-wrapper.js +102 -0
- package/dist/arena/strategies/lens-wrapper.d.ts +16 -0
- package/dist/arena/strategies/lens-wrapper.js +236 -0
- package/dist/arena/strategies/planning.d.ts +30 -0
- package/dist/arena/strategies/planning.js +225 -0
- package/dist/arena/strategies/review.d.ts +26 -0
- package/dist/arena/strategies/review.js +168 -0
- package/dist/arena/strategies/utils.d.ts +39 -0
- package/dist/arena/strategies/utils.js +647 -0
- package/dist/arena/tools/selector.d.ts +17 -0
- package/dist/arena/tools/selector.js +61 -0
- package/dist/arena/transitions.d.ts +48 -0
- package/dist/arena/transitions.js +92 -0
- package/dist/arena/types.d.ts +508 -0
- package/dist/arena/types.js +27 -0
- package/dist/cli/agent-server-stdio.d.ts +32 -0
- package/dist/cli/agent-server-stdio.js +116 -0
- package/dist/colorizer.d.ts +23 -0
- package/dist/colorizer.js +12 -0
- package/dist/context/compaction.d.ts +116 -0
- package/dist/context/compaction.js +534 -0
- package/dist/context/manager.d.ts +145 -0
- package/dist/context/manager.js +423 -0
- package/dist/context/token-counter.d.ts +27 -0
- package/dist/context/token-counter.js +91 -0
- package/dist/context/tool-result-storage.d.ts +96 -0
- package/dist/context/tool-result-storage.js +296 -0
- package/dist/cost-tracker.d.ts +64 -0
- package/dist/cost-tracker.js +314 -0
- package/dist/cron/scheduler.d.ts +34 -0
- package/dist/cron/scheduler.js +115 -0
- package/dist/data/deepseek-models.json +46 -0
- package/dist/data/gemini-models.json +67 -0
- package/dist/data/openai-models.json +175 -0
- package/dist/data/openrouter-models.d.ts +35 -0
- package/dist/data/openrouter-models.js +36 -0
- package/dist/data/openrouter-models.json +4626 -0
- package/dist/data/openrouter-sync.d.ts +16 -0
- package/dist/data/openrouter-sync.js +53 -0
- package/dist/data/static-catalogs.d.ts +25 -0
- package/dist/data/static-catalogs.js +26 -0
- package/dist/data/zai-models.json +56 -0
- package/dist/engine/cost-store.d.ts +22 -0
- package/dist/engine/cost-store.js +15 -0
- package/dist/engine/engine.d.ts +295 -0
- package/dist/engine/engine.js +1467 -0
- package/dist/engine/model-facade.d.ts +24 -0
- package/dist/engine/model-facade.js +194 -0
- package/dist/engine/parse-task.d.ts +59 -0
- package/dist/engine/parse-task.js +135 -0
- package/dist/engine/patch-orphaned-tools.d.ts +52 -0
- package/dist/engine/patch-orphaned-tools.js +95 -0
- package/dist/engine/query.d.ts +50 -0
- package/dist/engine/query.js +107 -0
- package/dist/engine/runtime.d.ts +50 -0
- package/dist/engine/runtime.js +59 -0
- package/dist/engine/streaming-tool-queue.d.ts +34 -0
- package/dist/engine/streaming-tool-queue.js +61 -0
- package/dist/engine/token-budget.d.ts +22 -0
- package/dist/engine/token-budget.js +40 -0
- package/dist/engine/tool-summary.d.ts +13 -0
- package/dist/engine/tool-summary.js +35 -0
- package/dist/engine/turn-loop.d.ts +122 -0
- package/dist/engine/turn-loop.js +602 -0
- package/dist/engine/turn-state.d.ts +20 -0
- package/dist/engine/turn-state.js +17 -0
- package/dist/exceptions.d.ts +61 -0
- package/dist/exceptions.js +116 -0
- package/dist/git/utils.d.ts +35 -0
- package/dist/git/utils.js +98 -0
- package/dist/git/worktree.d.ts +36 -0
- package/dist/git/worktree.js +139 -0
- package/dist/hooks/events.d.ts +114 -0
- package/dist/hooks/events.js +4 -0
- package/dist/hooks/inject.d.ts +19 -0
- package/dist/hooks/inject.js +29 -0
- package/dist/hooks/registry.d.ts +15 -0
- package/dist/hooks/registry.js +84 -0
- package/dist/hooks/shell-runner.d.ts +45 -0
- package/dist/hooks/shell-runner.js +173 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +145 -0
- package/dist/llm/api-key-sanitize.d.ts +22 -0
- package/dist/llm/api-key-sanitize.js +81 -0
- package/dist/llm/capabilities/index.d.ts +20 -0
- package/dist/llm/capabilities/index.js +39 -0
- package/dist/llm/capabilities/rules.d.ts +26 -0
- package/dist/llm/capabilities/rules.js +215 -0
- package/dist/llm/capabilities/types.d.ts +114 -0
- package/dist/llm/capabilities/types.js +24 -0
- package/dist/llm/client-base.d.ts +29 -0
- package/dist/llm/client-base.js +137 -0
- package/dist/llm/client-factory.d.ts +10 -0
- package/dist/llm/client-factory.js +29 -0
- package/dist/llm/model-cache.d.ts +21 -0
- package/dist/llm/model-cache.js +46 -0
- package/dist/llm/model-fetcher.d.ts +29 -0
- package/dist/llm/model-fetcher.js +282 -0
- package/dist/llm/model-pool.d.ts +95 -0
- package/dist/llm/model-pool.js +246 -0
- package/dist/llm/provider-catalog.d.ts +32 -0
- package/dist/llm/provider-catalog.js +50 -0
- package/dist/llm/provider-kinds.d.ts +21 -0
- package/dist/llm/provider-kinds.js +132 -0
- package/dist/llm/providers/anthropic.d.ts +19 -0
- package/dist/llm/providers/anthropic.js +267 -0
- package/dist/llm/providers/openai.d.ts +64 -0
- package/dist/llm/providers/openai.js +606 -0
- package/dist/llm/retry.d.ts +12 -0
- package/dist/llm/retry.js +17 -0
- package/dist/llm/stream-watchdog.d.ts +42 -0
- package/dist/llm/stream-watchdog.js +70 -0
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/llm/token-counter.js +36 -0
- package/dist/llm/types.d.ts +37 -0
- package/dist/llm/types.js +4 -0
- package/dist/logging/logger.d.ts +109 -0
- package/dist/logging/logger.js +390 -0
- package/dist/logging/sanitize-messages.d.ts +42 -0
- package/dist/logging/sanitize-messages.js +150 -0
- package/dist/logging/session-recorder.d.ts +90 -0
- package/dist/logging/session-recorder.js +304 -0
- package/dist/lsp/client.d.ts +41 -0
- package/dist/lsp/client.js +166 -0
- package/dist/lsp/manager.d.ts +40 -0
- package/dist/lsp/manager.js +124 -0
- package/dist/lsp/servers.d.ts +16 -0
- package/dist/lsp/servers.js +60 -0
- package/dist/migrate-models.d.ts +45 -0
- package/dist/migrate-models.js +179 -0
- package/dist/onboarding.d.ts +189 -0
- package/dist/onboarding.js +625 -0
- package/dist/plugins/gitOps.d.ts +32 -0
- package/dist/plugins/gitOps.js +62 -0
- package/dist/plugins/installedPlugins.d.ts +15 -0
- package/dist/plugins/installedPlugins.js +56 -0
- package/dist/plugins/knownMarketplaces.d.ts +10 -0
- package/dist/plugins/knownMarketplaces.js +46 -0
- package/dist/plugins/loadPluginHooks.d.ts +52 -0
- package/dist/plugins/loadPluginHooks.js +162 -0
- package/dist/plugins/marketplaceManager.d.ts +49 -0
- package/dist/plugins/marketplaceManager.js +142 -0
- package/dist/plugins/parseMarketplaceInput.d.ts +16 -0
- package/dist/plugins/parseMarketplaceInput.js +73 -0
- package/dist/plugins/pluginCommandHook.d.ts +54 -0
- package/dist/plugins/pluginCommandHook.js +180 -0
- package/dist/plugins/pluginCommandsLoader.d.ts +25 -0
- package/dist/plugins/pluginCommandsLoader.js +114 -0
- package/dist/plugins/pluginInstaller.d.ts +36 -0
- package/dist/plugins/pluginInstaller.js +228 -0
- package/dist/plugins/schemas.d.ts +9 -0
- package/dist/plugins/schemas.js +136 -0
- package/dist/plugins/types.d.ts +75 -0
- package/dist/plugins/types.js +7 -0
- package/dist/plugins/varRewrite.d.ts +42 -0
- package/dist/plugins/varRewrite.js +129 -0
- package/dist/preset/index.d.ts +60 -0
- package/dist/preset/index.js +159 -0
- package/dist/product/define.d.ts +60 -0
- package/dist/product/define.js +123 -0
- package/dist/product/index.d.ts +5 -0
- package/dist/product/index.js +4 -0
- package/dist/product/types.d.ts +111 -0
- package/dist/product/types.js +21 -0
- package/dist/prompt/composer.d.ts +49 -0
- package/dist/prompt/composer.js +168 -0
- package/dist/prompt/instruction-scanner.d.ts +54 -0
- package/dist/prompt/instruction-scanner.js +187 -0
- package/dist/prompt/section-cache.d.ts +15 -0
- package/dist/prompt/section-cache.js +31 -0
- package/dist/prompt/section-loader.d.ts +26 -0
- package/dist/prompt/section-loader.js +53 -0
- package/dist/prompt/sections/base.md +35 -0
- package/dist/prompt/sections/coding.md +31 -0
- package/dist/prompt/sections/orchestration.md +16 -0
- package/dist/prompt/sections/tone.md +9 -0
- package/dist/protocol/chat-session-manager.d.ts +33 -0
- package/dist/protocol/chat-session-manager.js +65 -0
- package/dist/protocol/chat-session.d.ts +49 -0
- package/dist/protocol/chat-session.js +86 -0
- package/dist/protocol/client.d.ts +104 -0
- package/dist/protocol/client.js +260 -0
- package/dist/protocol/factories.d.ts +93 -0
- package/dist/protocol/factories.js +64 -0
- package/dist/protocol/helpers.d.ts +42 -0
- package/dist/protocol/helpers.js +55 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +4 -0
- package/dist/protocol/server.d.ts +80 -0
- package/dist/protocol/server.js +855 -0
- package/dist/protocol/transport.d.ts +37 -0
- package/dist/protocol/transport.js +85 -0
- package/dist/protocol/types.d.ts +221 -0
- package/dist/protocol/types.js +61 -0
- package/dist/remote/bridge.d.ts +37 -0
- package/dist/remote/bridge.js +103 -0
- package/dist/run/ArtifactTracker.d.ts +38 -0
- package/dist/run/ArtifactTracker.js +132 -0
- package/dist/run/CheckpointWriter.d.ts +53 -0
- package/dist/run/CheckpointWriter.js +135 -0
- package/dist/run/EngineRunner.d.ts +72 -0
- package/dist/run/EngineRunner.js +119 -0
- package/dist/run/Evaluator.d.ts +56 -0
- package/dist/run/Evaluator.js +62 -0
- package/dist/run/FileRunStore.d.ts +39 -0
- package/dist/run/FileRunStore.js +176 -0
- package/dist/run/Heartbeat.d.ts +54 -0
- package/dist/run/Heartbeat.js +123 -0
- package/dist/run/RunApprovalBackend.d.ts +53 -0
- package/dist/run/RunApprovalBackend.js +85 -0
- package/dist/run/RunLock.d.ts +40 -0
- package/dist/run/RunLock.js +98 -0
- package/dist/run/RunManager.d.ts +82 -0
- package/dist/run/RunManager.js +587 -0
- package/dist/run/RunQueue.d.ts +27 -0
- package/dist/run/RunQueue.js +73 -0
- package/dist/run/RunStore.d.ts +25 -0
- package/dist/run/RunStore.js +9 -0
- package/dist/run/factory.d.ts +63 -0
- package/dist/run/factory.js +51 -0
- package/dist/run/index.d.ts +17 -0
- package/dist/run/index.js +23 -0
- package/dist/run/types.d.ts +136 -0
- package/dist/run/types.js +28 -0
- package/dist/runtime/safe-spawn.d.ts +118 -0
- package/dist/runtime/safe-spawn.js +268 -0
- package/dist/services/analytics.d.ts +29 -0
- package/dist/services/analytics.js +84 -0
- package/dist/services/auto-dream.d.ts +49 -0
- package/dist/services/auto-dream.js +124 -0
- package/dist/services/diagnostics.d.ts +41 -0
- package/dist/services/diagnostics.js +99 -0
- package/dist/services/extract-memories.d.ts +31 -0
- package/dist/services/extract-memories.js +71 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.js +17 -0
- package/dist/services/memory-orchestrator.d.ts +60 -0
- package/dist/services/memory-orchestrator.js +133 -0
- package/dist/services/notifier.d.ts +25 -0
- package/dist/services/notifier.js +69 -0
- package/dist/services/oauth.d.ts +27 -0
- package/dist/services/oauth.js +153 -0
- package/dist/services/session-memory.d.ts +37 -0
- package/dist/services/session-memory.js +81 -0
- package/dist/session/file-history.d.ts +41 -0
- package/dist/session/file-history.js +115 -0
- package/dist/session/memory.d.ts +104 -0
- package/dist/session/memory.js +310 -0
- package/dist/session/session-manager.d.ts +41 -0
- package/dist/session/session-manager.js +261 -0
- package/dist/session/transcript.d.ts +39 -0
- package/dist/session/transcript.js +186 -0
- package/dist/settings/manager.d.ts +36 -0
- package/dist/settings/manager.js +187 -0
- package/dist/settings/schema.d.ts +1219 -0
- package/dist/settings/schema.js +246 -0
- package/dist/skills/frontmatter.d.ts +13 -0
- package/dist/skills/frontmatter.js +70 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/scanner.d.ts +31 -0
- package/dist/skills/scanner.js +171 -0
- package/dist/state.d.ts +160 -0
- package/dist/state.js +267 -0
- package/dist/tool-system/builtin/agent-notifications.d.ts +84 -0
- package/dist/tool-system/builtin/agent-notifications.js +197 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +67 -0
- package/dist/tool-system/builtin/agent-registry.js +126 -0
- package/dist/tool-system/builtin/agent-transcript-translator.d.ts +22 -0
- package/dist/tool-system/builtin/agent-transcript-translator.js +160 -0
- package/dist/tool-system/builtin/agent.d.ts +16 -0
- package/dist/tool-system/builtin/agent.js +364 -0
- package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
- package/dist/tool-system/builtin/apply-patch/applier.js +250 -0
- package/dist/tool-system/builtin/apply-patch/index.d.ts +20 -0
- package/dist/tool-system/builtin/apply-patch/index.js +101 -0
- package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
- package/dist/tool-system/builtin/apply-patch/parser.js +212 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.js +123 -0
- package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
- package/dist/tool-system/builtin/apply-patch/types.js +13 -0
- package/dist/tool-system/builtin/arena.d.ts +31 -0
- package/dist/tool-system/builtin/arena.js +416 -0
- package/dist/tool-system/builtin/ask-user.d.ts +20 -0
- package/dist/tool-system/builtin/ask-user.js +99 -0
- package/dist/tool-system/builtin/bash.d.ts +21 -0
- package/dist/tool-system/builtin/bash.js +149 -0
- package/dist/tool-system/builtin/brief.d.ts +6 -0
- package/dist/tool-system/builtin/brief.js +41 -0
- package/dist/tool-system/builtin/config.d.ts +6 -0
- package/dist/tool-system/builtin/config.js +67 -0
- package/dist/tool-system/builtin/cron.d.ts +10 -0
- package/dist/tool-system/builtin/cron.js +61 -0
- package/dist/tool-system/builtin/edit.d.ts +6 -0
- package/dist/tool-system/builtin/edit.js +100 -0
- package/dist/tool-system/builtin/file-cache.d.ts +11 -0
- package/dist/tool-system/builtin/file-cache.js +39 -0
- package/dist/tool-system/builtin/glob.d.ts +7 -0
- package/dist/tool-system/builtin/glob.js +76 -0
- package/dist/tool-system/builtin/grep.d.ts +7 -0
- package/dist/tool-system/builtin/grep.js +150 -0
- package/dist/tool-system/builtin/index.d.ts +20 -0
- package/dist/tool-system/builtin/index.js +449 -0
- package/dist/tool-system/builtin/lsp.d.ts +6 -0
- package/dist/tool-system/builtin/lsp.js +141 -0
- package/dist/tool-system/builtin/mcp-tools.d.ts +10 -0
- package/dist/tool-system/builtin/mcp-tools.js +102 -0
- package/dist/tool-system/builtin/memory.d.ts +26 -0
- package/dist/tool-system/builtin/memory.js +226 -0
- package/dist/tool-system/builtin/notebook-edit.d.ts +6 -0
- package/dist/tool-system/builtin/notebook-edit.js +124 -0
- package/dist/tool-system/builtin/plan.d.ts +15 -0
- package/dist/tool-system/builtin/plan.js +55 -0
- package/dist/tool-system/builtin/powershell.d.ts +11 -0
- package/dist/tool-system/builtin/powershell.js +64 -0
- package/dist/tool-system/builtin/read.d.ts +6 -0
- package/dist/tool-system/builtin/read.js +70 -0
- package/dist/tool-system/builtin/remote-trigger.d.ts +6 -0
- package/dist/tool-system/builtin/remote-trigger.js +54 -0
- package/dist/tool-system/builtin/repl.d.ts +11 -0
- package/dist/tool-system/builtin/repl.js +82 -0
- package/dist/tool-system/builtin/send-message.d.ts +6 -0
- package/dist/tool-system/builtin/send-message.js +47 -0
- package/dist/tool-system/builtin/skill-prompt.d.ts +20 -0
- package/dist/tool-system/builtin/skill-prompt.js +52 -0
- package/dist/tool-system/builtin/skill.d.ts +9 -0
- package/dist/tool-system/builtin/skill.js +55 -0
- package/dist/tool-system/builtin/sleep.d.ts +6 -0
- package/dist/tool-system/builtin/sleep.js +33 -0
- package/dist/tool-system/builtin/task.d.ts +48 -0
- package/dist/tool-system/builtin/task.js +139 -0
- package/dist/tool-system/builtin/tool-search.d.ts +11 -0
- package/dist/tool-system/builtin/tool-search.js +90 -0
- package/dist/tool-system/builtin/web-fetch.d.ts +10 -0
- package/dist/tool-system/builtin/web-fetch.js +328 -0
- package/dist/tool-system/builtin/web-search.d.ts +25 -0
- package/dist/tool-system/builtin/web-search.js +174 -0
- package/dist/tool-system/builtin/worktree.d.ts +10 -0
- package/dist/tool-system/builtin/worktree.js +95 -0
- package/dist/tool-system/builtin/write.d.ts +6 -0
- package/dist/tool-system/builtin/write.js +36 -0
- package/dist/tool-system/context.d.ts +165 -0
- package/dist/tool-system/context.js +18 -0
- package/dist/tool-system/executor.d.ts +49 -0
- package/dist/tool-system/executor.js +495 -0
- package/dist/tool-system/investigation-guard.d.ts +46 -0
- package/dist/tool-system/investigation-guard.js +155 -0
- package/dist/tool-system/mcp-manager.d.ts +67 -0
- package/dist/tool-system/mcp-manager.js +249 -0
- package/dist/tool-system/permission.d.ts +111 -0
- package/dist/tool-system/permission.js +774 -0
- package/dist/tool-system/registry.d.ts +32 -0
- package/dist/tool-system/registry.js +131 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/bwrap.js +63 -0
- package/dist/tool-system/sandbox/index.d.ts +78 -0
- package/dist/tool-system/sandbox/index.js +222 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/off.js +8 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/tool-system/sandbox/seatbelt.js +109 -0
- package/dist/tool-system/task-guard.d.ts +29 -0
- package/dist/tool-system/task-guard.js +70 -0
- package/dist/tool-system/validation.d.ts +5 -0
- package/dist/tool-system/validation.js +39 -0
- package/dist/types.d.ts +376 -0
- package/dist/types.js +4 -0
- package/dist/updater.d.ts +65 -0
- package/dist/updater.js +405 -0
- package/dist/utils/debug.d.ts +41 -0
- package/dist/utils/debug.js +110 -0
- package/dist/utils/earlyInput.d.ts +43 -0
- package/dist/utils/earlyInput.js +166 -0
- package/dist/utils/env.d.ts +24 -0
- package/dist/utils/env.js +104 -0
- package/dist/utils/envUtils.d.ts +51 -0
- package/dist/utils/envUtils.js +135 -0
- package/dist/utils/execFileNoThrow.d.ts +39 -0
- package/dist/utils/execFileNoThrow.js +74 -0
- package/dist/utils/format.d.ts +44 -0
- package/dist/utils/format.js +236 -0
- package/dist/utils/intl.d.ts +22 -0
- package/dist/utils/intl.js +83 -0
- package/dist/utils/lockfile.d.ts +15 -0
- package/dist/utils/lockfile.js +30 -0
- package/dist/utils/memoize.d.ts +19 -0
- package/dist/utils/memoize.js +14 -0
- package/dist/utils/semver.d.ts +6 -0
- package/dist/utils/semver.js +13 -0
- package/dist/utils/sliceAnsi.d.ts +12 -0
- package/dist/utils/sliceAnsi.js +62 -0
- package/dist/utils/systemTheme.d.ts +40 -0
- package/dist/utils/systemTheme.js +108 -0
- package/dist/utils/task-sanitizer.d.ts +6 -0
- package/dist/utils/task-sanitizer.js +24 -0
- package/dist/utils/theme.d.ts +93 -0
- package/dist/utils/theme.js +544 -0
- package/dist/utils/toolDisplay.d.ts +31 -0
- package/dist/utils/toolDisplay.js +188 -0
- package/package.json +72 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip image base64 payloads out of messages before they reach any log or
|
|
3
|
+
* persisted record.
|
|
4
|
+
*
|
|
5
|
+
* Transcripts (`<storage>/sessions/<sid>/transcript.jsonl`) still hold the
|
|
6
|
+
* full base64 — replay needs the bytes intact. Logs (`~/.code-shell/logs/`
|
|
7
|
+
* and `<repo>/log/`) do not. A 10 MB base64 string showing up in a daily
|
|
8
|
+
* log file would (a) bloat disk usage by orders of magnitude, (b) make
|
|
9
|
+
* `tail`/`less` unusable, and (c) leak sensitive image content into a
|
|
10
|
+
* file the user does not expect to be a content store.
|
|
11
|
+
*
|
|
12
|
+
* The sanitizer replaces every `{type:"image", source:{...base64...}}`
|
|
13
|
+
* block with a metadata-only stub of the form
|
|
14
|
+
* `{type:"image", source:{type:"base64", media_type, bytes, omitted:true}}`
|
|
15
|
+
* — preserving enough structure that a developer reading the log can see
|
|
16
|
+
* "yes, an image was here, type X, N bytes" without seeing the bytes
|
|
17
|
+
* themselves. Same idea for the OpenAI-compat `image_url` shape some
|
|
18
|
+
* downstream serializers may produce.
|
|
19
|
+
*
|
|
20
|
+
* Pure / no I/O. Allocates only when an image block actually exists, so
|
|
21
|
+
* pure-text turns pay essentially nothing on the fast path.
|
|
22
|
+
*/
|
|
23
|
+
import type { Message } from "../types.js";
|
|
24
|
+
/**
|
|
25
|
+
* Walk a single message's content and replace image-payload blocks with
|
|
26
|
+
* metadata stubs. Returns a new value — the input is not mutated.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sanitizeContent(content: Message["content"]): Message["content"];
|
|
29
|
+
/**
|
|
30
|
+
* Walk a {@link Message}[] array and sanitize every entry's content.
|
|
31
|
+
* Returns the *same* array reference when no message held an image (fast
|
|
32
|
+
* path for the overwhelmingly common pure-text case).
|
|
33
|
+
*/
|
|
34
|
+
export declare function sanitizeMessages(messages: readonly Message[]): Message[];
|
|
35
|
+
/**
|
|
36
|
+
* Sanitize a free-form task string before logging.
|
|
37
|
+
*
|
|
38
|
+
* The desktop encoder embeds images as `<codeshell-image>` blocks holding
|
|
39
|
+
* `data:…;base64,<payload>` URLs. Strip those URLs but keep the wrapper
|
|
40
|
+
* so a reader can see "an image was attached here".
|
|
41
|
+
*/
|
|
42
|
+
export declare function sanitizeTaskString(task: string): string;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip image base64 payloads out of messages before they reach any log or
|
|
3
|
+
* persisted record.
|
|
4
|
+
*
|
|
5
|
+
* Transcripts (`<storage>/sessions/<sid>/transcript.jsonl`) still hold the
|
|
6
|
+
* full base64 — replay needs the bytes intact. Logs (`~/.code-shell/logs/`
|
|
7
|
+
* and `<repo>/log/`) do not. A 10 MB base64 string showing up in a daily
|
|
8
|
+
* log file would (a) bloat disk usage by orders of magnitude, (b) make
|
|
9
|
+
* `tail`/`less` unusable, and (c) leak sensitive image content into a
|
|
10
|
+
* file the user does not expect to be a content store.
|
|
11
|
+
*
|
|
12
|
+
* The sanitizer replaces every `{type:"image", source:{...base64...}}`
|
|
13
|
+
* block with a metadata-only stub of the form
|
|
14
|
+
* `{type:"image", source:{type:"base64", media_type, bytes, omitted:true}}`
|
|
15
|
+
* — preserving enough structure that a developer reading the log can see
|
|
16
|
+
* "yes, an image was here, type X, N bytes" without seeing the bytes
|
|
17
|
+
* themselves. Same idea for the OpenAI-compat `image_url` shape some
|
|
18
|
+
* downstream serializers may produce.
|
|
19
|
+
*
|
|
20
|
+
* Pure / no I/O. Allocates only when an image block actually exists, so
|
|
21
|
+
* pure-text turns pay essentially nothing on the fast path.
|
|
22
|
+
*/
|
|
23
|
+
/** Marker length below which we don't bother sanitizing — short URLs aren't base64. */
|
|
24
|
+
const BASE64_MIN_BYTES = 64;
|
|
25
|
+
/**
|
|
26
|
+
* Returns true iff this content block carries a real image payload that we
|
|
27
|
+
* should redact. Inline text/tool_use/tool_result blocks pass through.
|
|
28
|
+
*/
|
|
29
|
+
function isImageBlock(block) {
|
|
30
|
+
if (!block || typeof block !== "object")
|
|
31
|
+
return false;
|
|
32
|
+
const b = block;
|
|
33
|
+
if (b.type !== "image")
|
|
34
|
+
return false;
|
|
35
|
+
const src = b.source;
|
|
36
|
+
if (!src || src.type !== "base64")
|
|
37
|
+
return false;
|
|
38
|
+
return typeof src.data === "string" && src.data.length >= BASE64_MIN_BYTES;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns true if this is the OpenAI-compat `image_url` part with a data
|
|
42
|
+
* URL embedded inline.
|
|
43
|
+
*/
|
|
44
|
+
function isImageUrlPart(part) {
|
|
45
|
+
if (!part || typeof part !== "object")
|
|
46
|
+
return false;
|
|
47
|
+
const p = part;
|
|
48
|
+
if (p.type !== "image_url")
|
|
49
|
+
return false;
|
|
50
|
+
const iu = p.image_url;
|
|
51
|
+
if (!iu || typeof iu.url !== "string")
|
|
52
|
+
return false;
|
|
53
|
+
return iu.url.startsWith("data:") && iu.url.length >= BASE64_MIN_BYTES;
|
|
54
|
+
}
|
|
55
|
+
function sanitizeImageBlock(block) {
|
|
56
|
+
const src = block.source;
|
|
57
|
+
return {
|
|
58
|
+
type: "image",
|
|
59
|
+
source: {
|
|
60
|
+
type: "base64",
|
|
61
|
+
media_type: src.media_type,
|
|
62
|
+
bytes: src.data.length,
|
|
63
|
+
omitted: true,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function sanitizeImageUrlPart(part) {
|
|
68
|
+
// Best-effort byte count off the data URL. We don't decode — just report
|
|
69
|
+
// payload length so the reader knows the scale.
|
|
70
|
+
const url = part.image_url.url;
|
|
71
|
+
const comma = url.indexOf(",");
|
|
72
|
+
const payloadLen = comma === -1 ? 0 : url.length - comma - 1;
|
|
73
|
+
return {
|
|
74
|
+
type: "image_url",
|
|
75
|
+
image_url: {
|
|
76
|
+
// Keep the data-URL header so reviewers can see the MIME, but strip
|
|
77
|
+
// the payload. "data:image/png;base64,<omitted, 12345 bytes>"
|
|
78
|
+
url: comma === -1
|
|
79
|
+
? url
|
|
80
|
+
: `${url.slice(0, comma + 1)}<omitted, ${payloadLen} bytes>`,
|
|
81
|
+
omitted: true,
|
|
82
|
+
bytes: payloadLen,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Walk a single message's content and replace image-payload blocks with
|
|
88
|
+
* metadata stubs. Returns a new value — the input is not mutated.
|
|
89
|
+
*/
|
|
90
|
+
export function sanitizeContent(content) {
|
|
91
|
+
if (typeof content === "string")
|
|
92
|
+
return content;
|
|
93
|
+
if (!Array.isArray(content))
|
|
94
|
+
return content;
|
|
95
|
+
let touched = false;
|
|
96
|
+
const out = [];
|
|
97
|
+
for (const block of content) {
|
|
98
|
+
if (isImageBlock(block)) {
|
|
99
|
+
out.push(sanitizeImageBlock(block));
|
|
100
|
+
touched = true;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (isImageUrlPart(block)) {
|
|
104
|
+
out.push(sanitizeImageUrlPart(block));
|
|
105
|
+
touched = true;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
out.push(block);
|
|
109
|
+
}
|
|
110
|
+
return (touched ? out : content);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Walk a {@link Message}[] array and sanitize every entry's content.
|
|
114
|
+
* Returns the *same* array reference when no message held an image (fast
|
|
115
|
+
* path for the overwhelmingly common pure-text case).
|
|
116
|
+
*/
|
|
117
|
+
export function sanitizeMessages(messages) {
|
|
118
|
+
let touched = false;
|
|
119
|
+
const out = [];
|
|
120
|
+
for (const m of messages) {
|
|
121
|
+
const sanitized = sanitizeContent(m.content);
|
|
122
|
+
if (sanitized !== m.content) {
|
|
123
|
+
touched = true;
|
|
124
|
+
out.push({ ...m, content: sanitized });
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
out.push(m);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return touched ? out : messages;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Sanitize a free-form task string before logging.
|
|
134
|
+
*
|
|
135
|
+
* The desktop encoder embeds images as `<codeshell-image>` blocks holding
|
|
136
|
+
* `data:…;base64,<payload>` URLs. Strip those URLs but keep the wrapper
|
|
137
|
+
* so a reader can see "an image was attached here".
|
|
138
|
+
*/
|
|
139
|
+
export function sanitizeTaskString(task) {
|
|
140
|
+
if (typeof task !== "string" || task.indexOf("<codeshell-image") === -1) {
|
|
141
|
+
return task;
|
|
142
|
+
}
|
|
143
|
+
return task.replace(/(<codeshell-image\b[^>]*>)([\s\S]*?)(<\/codeshell-image>)/g, (_full, open, body, close) => {
|
|
144
|
+
const trimmed = body.trim();
|
|
145
|
+
const comma = trimmed.indexOf(",");
|
|
146
|
+
const bytes = comma === -1 ? trimmed.length : trimmed.length - comma - 1;
|
|
147
|
+
const header = comma === -1 ? "" : trimmed.slice(0, comma + 1);
|
|
148
|
+
return `${open}${header}<omitted, ${bytes} bytes>${close}`;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session verbose recorder for local-dev runs.
|
|
3
|
+
*
|
|
4
|
+
* Layout (per day, split by bucket):
|
|
5
|
+
* <repo>/log/<YYYY-MM-DD>/engine/session-<sid>.jsonl
|
|
6
|
+
* — unified timeline: LLM, tools, session events, AND UI events
|
|
7
|
+
* (UI events are dual-written so this file is the full story.)
|
|
8
|
+
* <repo>/log/<YYYY-MM-DD>/ui/session-<sid>.jsonl
|
|
9
|
+
* — UI-only events (stream events received, ctx renders, chatStore
|
|
10
|
+
* mutations). Open when chasing a display bug.
|
|
11
|
+
*
|
|
12
|
+
* Same sid → same filename in both folders. Diff/merge by sid to align
|
|
13
|
+
* "what the model said" with "what the UI did about it."
|
|
14
|
+
*
|
|
15
|
+
* Why a separate sink from logger.ts?
|
|
16
|
+
* - logger.ts is the terse process-wide log (~/.code-shell/logs/) and stays
|
|
17
|
+
* small for production observability.
|
|
18
|
+
* - This sink keeps full prompt/response bodies for post-mortem debugging
|
|
19
|
+
* and is gated to local-dev only (bun run dev / CODE_SHELL_DEV=1).
|
|
20
|
+
*
|
|
21
|
+
* Why JSONL not markdown?
|
|
22
|
+
* - `jq` can slice on any field in one command: tool histograms, slowest
|
|
23
|
+
* LLM calls, largest prompts, anything. Markdown would need ad-hoc parsing.
|
|
24
|
+
* - Field bodies are inlined; JSON.stringify handles arbitrarily long
|
|
25
|
+
* strings and jq streams, so no sidecar files are needed.
|
|
26
|
+
*
|
|
27
|
+
* Daily rotation: on first write each process, prune date folders older than
|
|
28
|
+
* RETENTION_DAYS.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isVerboseRecorderEnabled(): boolean;
|
|
31
|
+
export declare function getVerboseLogDir(): string;
|
|
32
|
+
export declare function recordSessionStart(sid: string, info: {
|
|
33
|
+
task?: string;
|
|
34
|
+
cwd?: string;
|
|
35
|
+
model?: string;
|
|
36
|
+
provider?: string;
|
|
37
|
+
permissionMode?: string;
|
|
38
|
+
resumed?: boolean;
|
|
39
|
+
}): void;
|
|
40
|
+
export type RecordLLMRequest = {
|
|
41
|
+
provider: string;
|
|
42
|
+
model: string;
|
|
43
|
+
stream: boolean;
|
|
44
|
+
temperature?: number;
|
|
45
|
+
maxTokens?: number;
|
|
46
|
+
messages: unknown;
|
|
47
|
+
tools?: unknown;
|
|
48
|
+
systemPrompt?: string;
|
|
49
|
+
};
|
|
50
|
+
export declare function recordLLMRequest(sid: string, req: RecordLLMRequest, reqId: string): void;
|
|
51
|
+
export type RecordLLMResponse = {
|
|
52
|
+
text?: string;
|
|
53
|
+
toolCalls?: Array<{
|
|
54
|
+
id: string;
|
|
55
|
+
toolName: string;
|
|
56
|
+
args: unknown;
|
|
57
|
+
}>;
|
|
58
|
+
stopReason?: string;
|
|
59
|
+
usage?: import("../types.js").TokenUsage;
|
|
60
|
+
durationMs?: number;
|
|
61
|
+
ttftMs?: number;
|
|
62
|
+
};
|
|
63
|
+
export declare function recordLLMResponse(sid: string, resp: RecordLLMResponse, reqId: string): void;
|
|
64
|
+
export declare function recordLLMError(sid: string, reqId: string, err: unknown, durationMs: number): void;
|
|
65
|
+
export declare function recordToolCall(sid: string, call: {
|
|
66
|
+
id: string;
|
|
67
|
+
toolName: string;
|
|
68
|
+
args: unknown;
|
|
69
|
+
}): void;
|
|
70
|
+
export declare function recordToolResult(sid: string, result: {
|
|
71
|
+
id: string;
|
|
72
|
+
toolName: string;
|
|
73
|
+
ok: boolean;
|
|
74
|
+
durationMs: number;
|
|
75
|
+
output?: string;
|
|
76
|
+
error?: string;
|
|
77
|
+
}): void;
|
|
78
|
+
export declare function recordEvent(sid: string, name: string, data?: Record<string, unknown>): void;
|
|
79
|
+
/**
|
|
80
|
+
* Record a UI-side event. Goes into both engine.jsonl (unified timeline) and
|
|
81
|
+
* ui.jsonl (focused view). Use from the UI when chasing display bugs — pass
|
|
82
|
+
* the current sessionId.
|
|
83
|
+
*/
|
|
84
|
+
export declare function recordUIEvent(sid: string | undefined, name: string, data?: Record<string, unknown>): void;
|
|
85
|
+
export declare function recordSessionEnd(sid: string, info: {
|
|
86
|
+
reason?: string;
|
|
87
|
+
turns?: number;
|
|
88
|
+
cost?: unknown;
|
|
89
|
+
durationMs?: number;
|
|
90
|
+
}): void;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session verbose recorder for local-dev runs.
|
|
3
|
+
*
|
|
4
|
+
* Layout (per day, split by bucket):
|
|
5
|
+
* <repo>/log/<YYYY-MM-DD>/engine/session-<sid>.jsonl
|
|
6
|
+
* — unified timeline: LLM, tools, session events, AND UI events
|
|
7
|
+
* (UI events are dual-written so this file is the full story.)
|
|
8
|
+
* <repo>/log/<YYYY-MM-DD>/ui/session-<sid>.jsonl
|
|
9
|
+
* — UI-only events (stream events received, ctx renders, chatStore
|
|
10
|
+
* mutations). Open when chasing a display bug.
|
|
11
|
+
*
|
|
12
|
+
* Same sid → same filename in both folders. Diff/merge by sid to align
|
|
13
|
+
* "what the model said" with "what the UI did about it."
|
|
14
|
+
*
|
|
15
|
+
* Why a separate sink from logger.ts?
|
|
16
|
+
* - logger.ts is the terse process-wide log (~/.code-shell/logs/) and stays
|
|
17
|
+
* small for production observability.
|
|
18
|
+
* - This sink keeps full prompt/response bodies for post-mortem debugging
|
|
19
|
+
* and is gated to local-dev only (bun run dev / CODE_SHELL_DEV=1).
|
|
20
|
+
*
|
|
21
|
+
* Why JSONL not markdown?
|
|
22
|
+
* - `jq` can slice on any field in one command: tool histograms, slowest
|
|
23
|
+
* LLM calls, largest prompts, anything. Markdown would need ad-hoc parsing.
|
|
24
|
+
* - Field bodies are inlined; JSON.stringify handles arbitrarily long
|
|
25
|
+
* strings and jq streams, so no sidecar files are needed.
|
|
26
|
+
*
|
|
27
|
+
* Daily rotation: on first write each process, prune date folders older than
|
|
28
|
+
* RETENTION_DAYS.
|
|
29
|
+
*/
|
|
30
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync, } from "node:fs";
|
|
31
|
+
import { join } from "node:path";
|
|
32
|
+
const RETENTION_DAYS = 7;
|
|
33
|
+
// Per-record cap on the inlined tool output/error blob. The recorder is dev
|
|
34
|
+
// only, but a stray CODE_SHELL_DEV=1 plus a Read of a large file would write
|
|
35
|
+
// the whole file body to disk every run; this caps it.
|
|
36
|
+
const MAX_RECORD_BYTES = 256 * 1024;
|
|
37
|
+
function clip(s) {
|
|
38
|
+
if (s === undefined)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (s.length <= MAX_RECORD_BYTES)
|
|
41
|
+
return s;
|
|
42
|
+
return s.slice(0, MAX_RECORD_BYTES) + `\n…(truncated, ${s.length - MAX_RECORD_BYTES} more bytes)`;
|
|
43
|
+
}
|
|
44
|
+
function isLocalDev() {
|
|
45
|
+
if (process.env.CODE_SHELL_VERBOSE_LOG === "0")
|
|
46
|
+
return false;
|
|
47
|
+
if (process.env.CODE_SHELL_DEV === "1")
|
|
48
|
+
return true;
|
|
49
|
+
if (process.argv.includes("--debug") || process.argv.includes("-d"))
|
|
50
|
+
return true;
|
|
51
|
+
if (process.argv.some((a) => a.startsWith("--debug=")))
|
|
52
|
+
return true;
|
|
53
|
+
if (process.env.NODE_ENV === "test" || process.env.BUN_TEST === "1")
|
|
54
|
+
return false;
|
|
55
|
+
const entry = process.argv[1] ?? "";
|
|
56
|
+
if (entry.includes(`${"/"}src${"/"}`))
|
|
57
|
+
return true;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const ENABLED = isLocalDev();
|
|
61
|
+
// Anchor the log dir at the repo root. We can't trust process.cwd() because
|
|
62
|
+
// the CLI may run from any subdirectory; instead walk up from this source
|
|
63
|
+
// file looking for package.json. In a published install this file is under
|
|
64
|
+
// dist/, which is fine — the recorder is only enabled in dev anyway.
|
|
65
|
+
function resolveLogDir() {
|
|
66
|
+
let dir = new URL(".", import.meta.url).pathname;
|
|
67
|
+
if (dir.endsWith("/"))
|
|
68
|
+
dir = dir.slice(0, -1);
|
|
69
|
+
for (let i = 0; i < 8; i++) {
|
|
70
|
+
if (existsSync(join(dir, "package.json")))
|
|
71
|
+
return join(dir, "log");
|
|
72
|
+
const parent = join(dir, "..");
|
|
73
|
+
if (parent === dir)
|
|
74
|
+
break;
|
|
75
|
+
dir = parent;
|
|
76
|
+
}
|
|
77
|
+
return join(process.cwd(), "log");
|
|
78
|
+
}
|
|
79
|
+
const LOG_ROOT = ENABLED ? resolveLogDir() : "";
|
|
80
|
+
// Strip secret-bearing flags before persisting argv. Covers both
|
|
81
|
+
// `--flag value` and `--flag=value` shapes; case-insensitive match on
|
|
82
|
+
// the flag name only (values are never inspected).
|
|
83
|
+
const SENSITIVE_FLAG_RE = /^--?(api[-_]?key|auth[-_]?token|token|password|secret|bearer)(=|$)/i;
|
|
84
|
+
function redactArgv(argv) {
|
|
85
|
+
const out = [];
|
|
86
|
+
for (let i = 0; i < argv.length; i++) {
|
|
87
|
+
const a = argv[i] ?? "";
|
|
88
|
+
const m = SENSITIVE_FLAG_RE.exec(a);
|
|
89
|
+
if (!m) {
|
|
90
|
+
out.push(a);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (m[2] === "=") {
|
|
94
|
+
out.push(`${a.slice(0, a.indexOf("=") + 1)}<redacted>`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
out.push(a);
|
|
98
|
+
if (i + 1 < argv.length) {
|
|
99
|
+
out.push("<redacted>");
|
|
100
|
+
i += 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
const states = new Map();
|
|
107
|
+
let rotated = false;
|
|
108
|
+
function todayStr() {
|
|
109
|
+
return new Date().toISOString().slice(0, 10);
|
|
110
|
+
}
|
|
111
|
+
function rotateOnce() {
|
|
112
|
+
if (rotated || !ENABLED)
|
|
113
|
+
return;
|
|
114
|
+
rotated = true;
|
|
115
|
+
try {
|
|
116
|
+
if (!existsSync(LOG_ROOT))
|
|
117
|
+
return;
|
|
118
|
+
const cutoff = Date.now() - RETENTION_DAYS * 24 * 60 * 60 * 1000;
|
|
119
|
+
for (const entry of readdirSync(LOG_ROOT)) {
|
|
120
|
+
const full = join(LOG_ROOT, entry);
|
|
121
|
+
try {
|
|
122
|
+
const st = statSync(full);
|
|
123
|
+
if (st.isDirectory() && st.mtimeMs < cutoff) {
|
|
124
|
+
rmSync(full, { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
/* ignore */
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
/* best-effort */
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function ensureState(sid) {
|
|
137
|
+
if (!ENABLED)
|
|
138
|
+
return null;
|
|
139
|
+
rotateOnce();
|
|
140
|
+
let st = states.get(sid);
|
|
141
|
+
if (st)
|
|
142
|
+
return st;
|
|
143
|
+
const dateStr = todayStr();
|
|
144
|
+
const dayDir = join(LOG_ROOT, dateStr);
|
|
145
|
+
const engineDir = join(dayDir, "engine");
|
|
146
|
+
const uiDir = join(dayDir, "ui");
|
|
147
|
+
const fileName = `session-${sid}.jsonl`;
|
|
148
|
+
try {
|
|
149
|
+
if (!existsSync(engineDir))
|
|
150
|
+
mkdirSync(engineDir, { recursive: true });
|
|
151
|
+
if (!existsSync(uiDir))
|
|
152
|
+
mkdirSync(uiDir, { recursive: true });
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
st = {
|
|
158
|
+
dir: dayDir,
|
|
159
|
+
engineFile: join(engineDir, fileName),
|
|
160
|
+
uiFile: join(uiDir, fileName),
|
|
161
|
+
startedAt: Date.now(),
|
|
162
|
+
};
|
|
163
|
+
states.set(sid, st);
|
|
164
|
+
return st;
|
|
165
|
+
}
|
|
166
|
+
function write(sid, bucket, event) {
|
|
167
|
+
const st = ensureState(sid);
|
|
168
|
+
if (!st)
|
|
169
|
+
return;
|
|
170
|
+
const record = { t: new Date().toISOString(), sid, ...event };
|
|
171
|
+
const line = JSON.stringify(record) + "\n";
|
|
172
|
+
try {
|
|
173
|
+
// Engine file is the unified timeline — every event lands here so a
|
|
174
|
+
// single `cat engine.jsonl` shows the complete story.
|
|
175
|
+
appendFileSync(st.engineFile, line, "utf-8");
|
|
176
|
+
// UI bucket also gets its own focused file for display-bug debugging
|
|
177
|
+
// without engine noise.
|
|
178
|
+
if (bucket === "ui") {
|
|
179
|
+
appendFileSync(st.uiFile, line, "utf-8");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
/* best-effort */
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// ─── Public API ────────────────────────────────────────────────────
|
|
187
|
+
export function isVerboseRecorderEnabled() {
|
|
188
|
+
return ENABLED;
|
|
189
|
+
}
|
|
190
|
+
export function getVerboseLogDir() {
|
|
191
|
+
return LOG_ROOT;
|
|
192
|
+
}
|
|
193
|
+
export function recordSessionStart(sid, info) {
|
|
194
|
+
if (!ENABLED)
|
|
195
|
+
return;
|
|
196
|
+
write(sid, "engine", {
|
|
197
|
+
type: "session_start",
|
|
198
|
+
pid: process.pid,
|
|
199
|
+
argv: redactArgv(process.argv.slice(1)),
|
|
200
|
+
cwd: info.cwd,
|
|
201
|
+
model: info.model,
|
|
202
|
+
provider: info.provider,
|
|
203
|
+
permissionMode: info.permissionMode,
|
|
204
|
+
resumed: info.resumed,
|
|
205
|
+
task: info.task,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
export function recordLLMRequest(sid, req, reqId) {
|
|
209
|
+
if (!ENABLED)
|
|
210
|
+
return;
|
|
211
|
+
write(sid, "engine", {
|
|
212
|
+
type: "llm.request",
|
|
213
|
+
reqId,
|
|
214
|
+
provider: req.provider,
|
|
215
|
+
model: req.model,
|
|
216
|
+
stream: req.stream,
|
|
217
|
+
temperature: req.temperature,
|
|
218
|
+
maxTokens: req.maxTokens,
|
|
219
|
+
toolCount: Array.isArray(req.tools) ? req.tools.length : 0,
|
|
220
|
+
messageCount: Array.isArray(req.messages) ? req.messages.length : undefined,
|
|
221
|
+
systemPrompt: req.systemPrompt,
|
|
222
|
+
tools: req.tools,
|
|
223
|
+
messages: req.messages,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
export function recordLLMResponse(sid, resp, reqId) {
|
|
227
|
+
if (!ENABLED)
|
|
228
|
+
return;
|
|
229
|
+
write(sid, "engine", {
|
|
230
|
+
type: "llm.response",
|
|
231
|
+
reqId,
|
|
232
|
+
stopReason: resp.stopReason,
|
|
233
|
+
durationMs: resp.durationMs,
|
|
234
|
+
ttftMs: resp.ttftMs,
|
|
235
|
+
usage: resp.usage,
|
|
236
|
+
toolCallCount: resp.toolCalls?.length ?? 0,
|
|
237
|
+
text: resp.text,
|
|
238
|
+
toolCalls: resp.toolCalls,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
export function recordLLMError(sid, reqId, err, durationMs) {
|
|
242
|
+
if (!ENABLED)
|
|
243
|
+
return;
|
|
244
|
+
write(sid, "engine", {
|
|
245
|
+
type: "llm.error",
|
|
246
|
+
reqId,
|
|
247
|
+
durationMs,
|
|
248
|
+
message: err instanceof Error ? err.message : String(err),
|
|
249
|
+
stack: err instanceof Error ? err.stack : undefined,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
export function recordToolCall(sid, call) {
|
|
253
|
+
if (!ENABLED)
|
|
254
|
+
return;
|
|
255
|
+
write(sid, "engine", {
|
|
256
|
+
type: "tool.call",
|
|
257
|
+
toolCallId: call.id,
|
|
258
|
+
toolName: call.toolName,
|
|
259
|
+
args: call.args,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
export function recordToolResult(sid, result) {
|
|
263
|
+
if (!ENABLED)
|
|
264
|
+
return;
|
|
265
|
+
write(sid, "engine", {
|
|
266
|
+
type: "tool.result",
|
|
267
|
+
toolCallId: result.id,
|
|
268
|
+
toolName: result.toolName,
|
|
269
|
+
ok: result.ok,
|
|
270
|
+
durationMs: result.durationMs,
|
|
271
|
+
chars: (result.output ?? result.error ?? "").length,
|
|
272
|
+
output: clip(result.output),
|
|
273
|
+
error: clip(result.error),
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
export function recordEvent(sid, name, data) {
|
|
277
|
+
if (!ENABLED)
|
|
278
|
+
return;
|
|
279
|
+
write(sid, "engine", { type: name, ...(data ?? {}) });
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Record a UI-side event. Goes into both engine.jsonl (unified timeline) and
|
|
283
|
+
* ui.jsonl (focused view). Use from the UI when chasing display bugs — pass
|
|
284
|
+
* the current sessionId.
|
|
285
|
+
*/
|
|
286
|
+
export function recordUIEvent(sid, name, data) {
|
|
287
|
+
if (!ENABLED)
|
|
288
|
+
return;
|
|
289
|
+
if (!sid)
|
|
290
|
+
return;
|
|
291
|
+
write(sid, "ui", { type: name, ...(data ?? {}) });
|
|
292
|
+
}
|
|
293
|
+
export function recordSessionEnd(sid, info) {
|
|
294
|
+
if (!ENABLED)
|
|
295
|
+
return;
|
|
296
|
+
write(sid, "engine", {
|
|
297
|
+
type: "session_end",
|
|
298
|
+
reason: info.reason,
|
|
299
|
+
turns: info.turns,
|
|
300
|
+
durationMs: info.durationMs,
|
|
301
|
+
cost: info.cost,
|
|
302
|
+
});
|
|
303
|
+
states.delete(sid);
|
|
304
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LSP client — JSON-RPC over stdio communication with language servers.
|
|
3
|
+
*/
|
|
4
|
+
import { EventEmitter } from "node:events";
|
|
5
|
+
export interface LSPRequest {
|
|
6
|
+
method: string;
|
|
7
|
+
params?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface LSPResponse {
|
|
10
|
+
id: number;
|
|
11
|
+
result?: unknown;
|
|
12
|
+
error?: {
|
|
13
|
+
code: number;
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface LSPNotification {
|
|
18
|
+
method: string;
|
|
19
|
+
params?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export declare class LSPClient extends EventEmitter {
|
|
22
|
+
private readonly command;
|
|
23
|
+
private readonly args;
|
|
24
|
+
private readonly cwd?;
|
|
25
|
+
private process;
|
|
26
|
+
private nextId;
|
|
27
|
+
private pending;
|
|
28
|
+
private buffer;
|
|
29
|
+
private contentLength;
|
|
30
|
+
private initialized;
|
|
31
|
+
constructor(command: string, args?: string[], cwd?: string | undefined);
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
initialize(rootUri: string): Promise<unknown>;
|
|
34
|
+
request(method: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
35
|
+
notify(method: string, params?: Record<string, unknown>): Promise<void>;
|
|
36
|
+
shutdown(): Promise<void>;
|
|
37
|
+
get isInitialized(): boolean;
|
|
38
|
+
get isAlive(): boolean;
|
|
39
|
+
private handleData;
|
|
40
|
+
private rejectAll;
|
|
41
|
+
}
|