@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,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Early Input Capture
|
|
3
|
+
*
|
|
4
|
+
* This module captures terminal input that is typed before the REPL is fully
|
|
5
|
+
* initialized. Users often type `claude` and immediately start typing their
|
|
6
|
+
* prompt, but those early keystrokes would otherwise be lost during startup.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* 1. Call startCapturingEarlyInput() as early as possible in cli.tsx
|
|
10
|
+
* 2. When REPL is ready, call consumeEarlyInput() to get any buffered text
|
|
11
|
+
* 3. stopCapturingEarlyInput() is called automatically when input is consumed
|
|
12
|
+
*/
|
|
13
|
+
import { lastGrapheme } from './intl.js';
|
|
14
|
+
// Buffer for early input characters
|
|
15
|
+
let earlyInputBuffer = '';
|
|
16
|
+
// Flag to track if we're currently capturing
|
|
17
|
+
let isCapturing = false;
|
|
18
|
+
// Reference to the readable handler so we can remove it later
|
|
19
|
+
let readableHandler = null;
|
|
20
|
+
/**
|
|
21
|
+
* Start capturing stdin data early, before the REPL is initialized.
|
|
22
|
+
* Should be called as early as possible in the startup sequence.
|
|
23
|
+
*
|
|
24
|
+
* Only captures if stdin is a TTY (interactive terminal).
|
|
25
|
+
*/
|
|
26
|
+
export function startCapturingEarlyInput() {
|
|
27
|
+
// Only capture in interactive mode: stdin must be a TTY, and we must not
|
|
28
|
+
// be in print mode. Raw mode disables ISIG (terminal Ctrl+C → SIGINT),
|
|
29
|
+
// which would make -p uninterruptible.
|
|
30
|
+
if (!process.stdin.isTTY ||
|
|
31
|
+
isCapturing ||
|
|
32
|
+
process.argv.includes('-p') ||
|
|
33
|
+
process.argv.includes('--print')) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
isCapturing = true;
|
|
37
|
+
earlyInputBuffer = '';
|
|
38
|
+
// Set stdin to raw mode and use 'readable' event like Ink does
|
|
39
|
+
// This ensures compatibility with how the REPL will handle stdin later
|
|
40
|
+
try {
|
|
41
|
+
process.stdin.setEncoding('utf8');
|
|
42
|
+
process.stdin.setRawMode(true);
|
|
43
|
+
process.stdin.ref();
|
|
44
|
+
readableHandler = () => {
|
|
45
|
+
let chunk = process.stdin.read();
|
|
46
|
+
while (chunk !== null) {
|
|
47
|
+
if (typeof chunk === 'string') {
|
|
48
|
+
processChunk(chunk);
|
|
49
|
+
}
|
|
50
|
+
chunk = process.stdin.read();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
process.stdin.on('readable', readableHandler);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// If we can't set raw mode, just silently continue without early capture
|
|
57
|
+
isCapturing = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Process a chunk of input data
|
|
62
|
+
*/
|
|
63
|
+
function processChunk(str) {
|
|
64
|
+
let i = 0;
|
|
65
|
+
while (i < str.length) {
|
|
66
|
+
const char = str[i];
|
|
67
|
+
const code = char.charCodeAt(0);
|
|
68
|
+
// Ctrl+C (code 3) - stop capturing and exit immediately.
|
|
69
|
+
// We use process.exit here instead of gracefulShutdown because at this
|
|
70
|
+
// early stage of startup, the shutdown machinery isn't initialized yet.
|
|
71
|
+
if (code === 3) {
|
|
72
|
+
stopCapturingEarlyInput();
|
|
73
|
+
// eslint-disable-next-line custom-rules/no-process-exit
|
|
74
|
+
process.exit(130); // Standard exit code for Ctrl+C
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Ctrl+D (code 4) - EOF, stop capturing
|
|
78
|
+
if (code === 4) {
|
|
79
|
+
stopCapturingEarlyInput();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Backspace (code 127 or 8) - remove last grapheme cluster
|
|
83
|
+
if (code === 127 || code === 8) {
|
|
84
|
+
if (earlyInputBuffer.length > 0) {
|
|
85
|
+
const last = lastGrapheme(earlyInputBuffer);
|
|
86
|
+
earlyInputBuffer = earlyInputBuffer.slice(0, -(last.length || 1));
|
|
87
|
+
}
|
|
88
|
+
i++;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// Skip escape sequences (arrow keys, function keys, focus events, etc.)
|
|
92
|
+
// All escape sequences start with ESC (0x1B) and end with a byte in 0x40-0x7E
|
|
93
|
+
if (code === 27) {
|
|
94
|
+
i++; // Skip the ESC character
|
|
95
|
+
// Skip until the terminating byte (@ to ~) or end of string
|
|
96
|
+
while (i < str.length &&
|
|
97
|
+
!(str.charCodeAt(i) >= 64 && str.charCodeAt(i) <= 126)) {
|
|
98
|
+
i++;
|
|
99
|
+
}
|
|
100
|
+
if (i < str.length)
|
|
101
|
+
i++; // Skip the terminating byte
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
// Skip other control characters (except tab and newline)
|
|
105
|
+
if (code < 32 && code !== 9 && code !== 10 && code !== 13) {
|
|
106
|
+
i++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
// Convert carriage return to newline
|
|
110
|
+
if (code === 13) {
|
|
111
|
+
earlyInputBuffer += '\n';
|
|
112
|
+
i++;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
// Add printable characters and allowed control chars to buffer
|
|
116
|
+
earlyInputBuffer += char;
|
|
117
|
+
i++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Stop capturing early input.
|
|
122
|
+
* Called automatically when input is consumed, or can be called manually.
|
|
123
|
+
*/
|
|
124
|
+
export function stopCapturingEarlyInput() {
|
|
125
|
+
if (!isCapturing) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
isCapturing = false;
|
|
129
|
+
if (readableHandler) {
|
|
130
|
+
process.stdin.removeListener('readable', readableHandler);
|
|
131
|
+
readableHandler = null;
|
|
132
|
+
}
|
|
133
|
+
// Don't reset stdin state - the REPL's Ink App will manage stdin state.
|
|
134
|
+
// If we call setRawMode(false) here, it can interfere with the REPL's
|
|
135
|
+
// own stdin setup which happens around the same time.
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Consume any early input that was captured.
|
|
139
|
+
* Returns the captured input and clears the buffer.
|
|
140
|
+
* Automatically stops capturing when called.
|
|
141
|
+
*/
|
|
142
|
+
export function consumeEarlyInput() {
|
|
143
|
+
stopCapturingEarlyInput();
|
|
144
|
+
const input = earlyInputBuffer.trim();
|
|
145
|
+
earlyInputBuffer = '';
|
|
146
|
+
return input;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Check if there is any early input available without consuming it.
|
|
150
|
+
*/
|
|
151
|
+
export function hasEarlyInput() {
|
|
152
|
+
return earlyInputBuffer.trim().length > 0;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Seed the early input buffer with text that will appear pre-filled
|
|
156
|
+
* in the prompt input when the REPL renders. Does not auto-submit.
|
|
157
|
+
*/
|
|
158
|
+
export function seedEarlyInput(text) {
|
|
159
|
+
earlyInputBuffer = text;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Check if early input capture is currently active.
|
|
163
|
+
*/
|
|
164
|
+
export function isCapturingEarlyInput() {
|
|
165
|
+
return isCapturing;
|
|
166
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment detection — platform, runtime, config paths, network.
|
|
3
|
+
*/
|
|
4
|
+
export declare const env: {
|
|
5
|
+
platform: "darwin" | "linux" | "win32";
|
|
6
|
+
terminal: string;
|
|
7
|
+
shell: string;
|
|
8
|
+
isCI: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function getHostPlatform(): "macos" | "linux" | "windows";
|
|
11
|
+
export declare function getHostPlatformForAnalytics(): string;
|
|
12
|
+
export declare function isWSL(): boolean;
|
|
13
|
+
/** ~/.claude/ directory (Claude Code compatible) */
|
|
14
|
+
export declare function getGlobalClaudeDir(): string;
|
|
15
|
+
/** ~/.code-shell/ directory */
|
|
16
|
+
export declare function getGlobalCodeShellDir(): string;
|
|
17
|
+
/** Resolve a file in ~/.claude/ or ~/.code-shell/ (claude takes precedence) */
|
|
18
|
+
export declare function getGlobalClaudeFile(filename: string): string | undefined;
|
|
19
|
+
export declare function getRuntime(): "bun" | "deno" | "node";
|
|
20
|
+
export declare function getPackageManager(cwd?: string): "bun" | "pnpm" | "yarn" | "npm";
|
|
21
|
+
export declare function hasInternetAccess(): Promise<boolean>;
|
|
22
|
+
export declare const JETBRAINS_IDES: readonly ["idea", "pycharm", "webstorm", "phpstorm", "rubymine", "clion", "goland", "rider", "datagrip", "fleet"];
|
|
23
|
+
export declare function isJetBrainsTerminal(): boolean;
|
|
24
|
+
export declare function isVSCodeTerminal(): boolean;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment detection — platform, runtime, config paths, network.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { execSync } from "node:child_process";
|
|
8
|
+
// ─── Platform / Terminal ────────────────────────────────────────────
|
|
9
|
+
export const env = {
|
|
10
|
+
platform: process.platform,
|
|
11
|
+
terminal: process.env.TERM_PROGRAM ?? process.env.TERM ?? "unknown",
|
|
12
|
+
shell: process.env.SHELL ?? (process.platform === "win32" ? "cmd.exe" : "/bin/sh"),
|
|
13
|
+
isCI: !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI),
|
|
14
|
+
};
|
|
15
|
+
export function getHostPlatform() {
|
|
16
|
+
if (process.platform === "darwin")
|
|
17
|
+
return "macos";
|
|
18
|
+
if (process.platform === "win32")
|
|
19
|
+
return "windows";
|
|
20
|
+
return "linux";
|
|
21
|
+
}
|
|
22
|
+
export function getHostPlatformForAnalytics() {
|
|
23
|
+
return getHostPlatform();
|
|
24
|
+
}
|
|
25
|
+
export function isWSL() {
|
|
26
|
+
if (process.platform !== "linux")
|
|
27
|
+
return false;
|
|
28
|
+
try {
|
|
29
|
+
const release = execSync("uname -r", { encoding: "utf-8", timeout: 2000 });
|
|
30
|
+
return /microsoft|wsl/i.test(release);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// ─── Config Paths ───────────────────────────────────────────────────
|
|
37
|
+
const HOME = homedir();
|
|
38
|
+
/** ~/.claude/ directory (Claude Code compatible) */
|
|
39
|
+
export function getGlobalClaudeDir() {
|
|
40
|
+
return join(HOME, ".claude");
|
|
41
|
+
}
|
|
42
|
+
/** ~/.code-shell/ directory */
|
|
43
|
+
export function getGlobalCodeShellDir() {
|
|
44
|
+
return join(HOME, ".code-shell");
|
|
45
|
+
}
|
|
46
|
+
/** Resolve a file in ~/.claude/ or ~/.code-shell/ (claude takes precedence) */
|
|
47
|
+
export function getGlobalClaudeFile(filename) {
|
|
48
|
+
const claudePath = join(getGlobalClaudeDir(), filename);
|
|
49
|
+
if (existsSync(claudePath))
|
|
50
|
+
return claudePath;
|
|
51
|
+
const csPath = join(getGlobalCodeShellDir(), filename);
|
|
52
|
+
if (existsSync(csPath))
|
|
53
|
+
return csPath;
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
// ─── Runtime / Package Manager ──────────────────────────────────────
|
|
57
|
+
export function getRuntime() {
|
|
58
|
+
if (typeof globalThis.Bun !== "undefined")
|
|
59
|
+
return "bun";
|
|
60
|
+
if (typeof globalThis.Deno !== "undefined")
|
|
61
|
+
return "deno";
|
|
62
|
+
return "node";
|
|
63
|
+
}
|
|
64
|
+
export function getPackageManager(cwd) {
|
|
65
|
+
const dir = cwd ?? process.cwd();
|
|
66
|
+
if (existsSync(join(dir, "bun.lock")) || existsSync(join(dir, "bun.lockb")))
|
|
67
|
+
return "bun";
|
|
68
|
+
if (existsSync(join(dir, "pnpm-lock.yaml")))
|
|
69
|
+
return "pnpm";
|
|
70
|
+
if (existsSync(join(dir, "yarn.lock")))
|
|
71
|
+
return "yarn";
|
|
72
|
+
return "npm";
|
|
73
|
+
}
|
|
74
|
+
// ─── Network ────────────────────────────────────────────────────────
|
|
75
|
+
let _hasInternet;
|
|
76
|
+
export async function hasInternetAccess() {
|
|
77
|
+
if (_hasInternet !== undefined)
|
|
78
|
+
return _hasInternet;
|
|
79
|
+
try {
|
|
80
|
+
const { connect } = await import("node:net");
|
|
81
|
+
return await new Promise((resolve) => {
|
|
82
|
+
const socket = connect({ host: "1.1.1.1", port: 443, timeout: 3000 });
|
|
83
|
+
socket.on("connect", () => { socket.destroy(); _hasInternet = true; resolve(true); });
|
|
84
|
+
socket.on("error", () => { _hasInternet = false; resolve(false); });
|
|
85
|
+
socket.on("timeout", () => { socket.destroy(); _hasInternet = false; resolve(false); });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
_hasInternet = false;
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// ─── IDE Detection ──────────────────────────────────────────────────
|
|
94
|
+
export const JETBRAINS_IDES = [
|
|
95
|
+
"idea", "pycharm", "webstorm", "phpstorm", "rubymine",
|
|
96
|
+
"clion", "goland", "rider", "datagrip", "fleet",
|
|
97
|
+
];
|
|
98
|
+
export function isJetBrainsTerminal() {
|
|
99
|
+
return !!(process.env.TERMINAL_EMULATOR?.includes("JetBrains") ||
|
|
100
|
+
process.env.JETBRAINS_IDE);
|
|
101
|
+
}
|
|
102
|
+
export function isVSCodeTerminal() {
|
|
103
|
+
return process.env.TERM_PROGRAM === "vscode";
|
|
104
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable helpers — ported from CC's utils/envUtils with full implementations.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Returns the Claude/Code Shell config home directory.
|
|
6
|
+
* Defaults to ~/.claude, overridable via CLAUDE_CONFIG_DIR env var.
|
|
7
|
+
* Memoized — keyed off CLAUDE_CONFIG_DIR so tests that change the env var get a fresh value.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getClaudeConfigHomeDir(): string;
|
|
10
|
+
export declare function getTeamsDir(): string;
|
|
11
|
+
export declare function isEnvTruthy(val: string | boolean | undefined): boolean;
|
|
12
|
+
export declare function isEnvDefinedFalsy(envVar: string | boolean | undefined): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if NODE_OPTIONS contains a specific flag.
|
|
15
|
+
*/
|
|
16
|
+
export declare function hasNodeOption(flag: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* --bare / CLAUDE_CODE_SIMPLE — skip hooks, LSP, plugin sync, skill dir-walk,
|
|
19
|
+
* attribution, background prefetches, and ALL keychain/credential reads.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isBareMode(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Parses an array of environment variable strings into a key-value object.
|
|
24
|
+
* @param rawEnvArgs Array of strings in KEY=VALUE format
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseEnvVars(rawEnvArgs: string[] | undefined): Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the AWS region with fallback to default.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getAWSRegion(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get the default Vertex AI region.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getDefaultVertexRegion(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Check if bash commands should maintain project working directory.
|
|
37
|
+
*/
|
|
38
|
+
export declare function shouldMaintainProjectWorkingDir(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Check if running on Homespace (ant-internal cloud environment).
|
|
41
|
+
*/
|
|
42
|
+
export declare function isRunningOnHomespace(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get the Vertex AI region for a specific model.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getVertexRegionForModel(model: string | undefined): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Stub: Check if running inside a protected namespace.
|
|
49
|
+
* Always returns false in Code Shell (Anthropic-internal feature).
|
|
50
|
+
*/
|
|
51
|
+
export declare function isInProtectedNamespace(): boolean;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable helpers — ported from CC's utils/envUtils with full implementations.
|
|
3
|
+
*/
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
// Memoize cache for getClaudeConfigHomeDir
|
|
7
|
+
let _configHomeDirCache = null;
|
|
8
|
+
let _configHomeDirCacheKey = undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the Claude/Code Shell config home directory.
|
|
11
|
+
* Defaults to ~/.claude, overridable via CLAUDE_CONFIG_DIR env var.
|
|
12
|
+
* Memoized — keyed off CLAUDE_CONFIG_DIR so tests that change the env var get a fresh value.
|
|
13
|
+
*/
|
|
14
|
+
export function getClaudeConfigHomeDir() {
|
|
15
|
+
const envKey = process.env.CLAUDE_CONFIG_DIR;
|
|
16
|
+
if (_configHomeDirCache !== null && _configHomeDirCacheKey === envKey) {
|
|
17
|
+
return _configHomeDirCache;
|
|
18
|
+
}
|
|
19
|
+
_configHomeDirCacheKey = envKey;
|
|
20
|
+
_configHomeDirCache = (envKey ?? join(homedir(), '.claude')).normalize('NFC');
|
|
21
|
+
return _configHomeDirCache;
|
|
22
|
+
}
|
|
23
|
+
export function getTeamsDir() {
|
|
24
|
+
return join(getClaudeConfigHomeDir(), 'teams');
|
|
25
|
+
}
|
|
26
|
+
export function isEnvTruthy(val) {
|
|
27
|
+
if (!val)
|
|
28
|
+
return false;
|
|
29
|
+
if (typeof val === 'boolean')
|
|
30
|
+
return val;
|
|
31
|
+
const normalizedValue = val.toLowerCase().trim();
|
|
32
|
+
return ['1', 'true', 'yes', 'on'].includes(normalizedValue);
|
|
33
|
+
}
|
|
34
|
+
export function isEnvDefinedFalsy(envVar) {
|
|
35
|
+
if (envVar === undefined)
|
|
36
|
+
return false;
|
|
37
|
+
if (typeof envVar === 'boolean')
|
|
38
|
+
return !envVar;
|
|
39
|
+
if (!envVar)
|
|
40
|
+
return false;
|
|
41
|
+
const normalizedValue = envVar.toLowerCase().trim();
|
|
42
|
+
return ['0', 'false', 'no', 'off'].includes(normalizedValue);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if NODE_OPTIONS contains a specific flag.
|
|
46
|
+
*/
|
|
47
|
+
export function hasNodeOption(flag) {
|
|
48
|
+
const nodeOptions = process.env.NODE_OPTIONS;
|
|
49
|
+
if (!nodeOptions)
|
|
50
|
+
return false;
|
|
51
|
+
return nodeOptions.split(/\s+/).includes(flag);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* --bare / CLAUDE_CODE_SIMPLE — skip hooks, LSP, plugin sync, skill dir-walk,
|
|
55
|
+
* attribution, background prefetches, and ALL keychain/credential reads.
|
|
56
|
+
*/
|
|
57
|
+
export function isBareMode() {
|
|
58
|
+
return (isEnvTruthy(process.env.CLAUDE_CODE_SIMPLE) ||
|
|
59
|
+
process.argv.includes('--bare'));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parses an array of environment variable strings into a key-value object.
|
|
63
|
+
* @param rawEnvArgs Array of strings in KEY=VALUE format
|
|
64
|
+
*/
|
|
65
|
+
export function parseEnvVars(rawEnvArgs) {
|
|
66
|
+
const parsedEnv = {};
|
|
67
|
+
if (rawEnvArgs) {
|
|
68
|
+
for (const envStr of rawEnvArgs) {
|
|
69
|
+
const [key, ...valueParts] = envStr.split('=');
|
|
70
|
+
if (!key || valueParts.length === 0) {
|
|
71
|
+
throw new Error(`Invalid environment variable format: ${envStr}, environment variables should be added as: -e KEY1=value1 -e KEY2=value2`);
|
|
72
|
+
}
|
|
73
|
+
parsedEnv[key] = valueParts.join('=');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return parsedEnv;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the AWS region with fallback to default.
|
|
80
|
+
*/
|
|
81
|
+
export function getAWSRegion() {
|
|
82
|
+
return process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the default Vertex AI region.
|
|
86
|
+
*/
|
|
87
|
+
export function getDefaultVertexRegion() {
|
|
88
|
+
return process.env.CLOUD_ML_REGION || 'us-east5';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check if bash commands should maintain project working directory.
|
|
92
|
+
*/
|
|
93
|
+
export function shouldMaintainProjectWorkingDir() {
|
|
94
|
+
return isEnvTruthy(process.env.CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if running on Homespace (ant-internal cloud environment).
|
|
98
|
+
*/
|
|
99
|
+
export function isRunningOnHomespace() {
|
|
100
|
+
return (process.env.USER_TYPE === 'ant' &&
|
|
101
|
+
isEnvTruthy(process.env.COO_RUNNING_ON_HOMESPACE));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Model prefix → env var for Vertex region overrides.
|
|
105
|
+
*/
|
|
106
|
+
const VERTEX_REGION_OVERRIDES = [
|
|
107
|
+
['claude-haiku-4-5', 'VERTEX_REGION_CLAUDE_HAIKU_4_5'],
|
|
108
|
+
['claude-3-5-haiku', 'VERTEX_REGION_CLAUDE_3_5_HAIKU'],
|
|
109
|
+
['claude-3-5-sonnet', 'VERTEX_REGION_CLAUDE_3_5_SONNET'],
|
|
110
|
+
['claude-3-7-sonnet', 'VERTEX_REGION_CLAUDE_3_7_SONNET'],
|
|
111
|
+
['claude-opus-4-1', 'VERTEX_REGION_CLAUDE_4_1_OPUS'],
|
|
112
|
+
['claude-opus-4', 'VERTEX_REGION_CLAUDE_4_0_OPUS'],
|
|
113
|
+
['claude-sonnet-4-6', 'VERTEX_REGION_CLAUDE_4_6_SONNET'],
|
|
114
|
+
['claude-sonnet-4-5', 'VERTEX_REGION_CLAUDE_4_5_SONNET'],
|
|
115
|
+
['claude-sonnet-4', 'VERTEX_REGION_CLAUDE_4_0_SONNET'],
|
|
116
|
+
];
|
|
117
|
+
/**
|
|
118
|
+
* Get the Vertex AI region for a specific model.
|
|
119
|
+
*/
|
|
120
|
+
export function getVertexRegionForModel(model) {
|
|
121
|
+
if (model) {
|
|
122
|
+
const match = VERTEX_REGION_OVERRIDES.find(([prefix]) => model.startsWith(prefix));
|
|
123
|
+
if (match) {
|
|
124
|
+
return process.env[match[1]] || getDefaultVertexRegion();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return getDefaultVertexRegion();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Stub: Check if running inside a protected namespace.
|
|
131
|
+
* Always returns false in Code Shell (Anthropic-internal feature).
|
|
132
|
+
*/
|
|
133
|
+
export function isInProtectedNamespace() {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a child process without throwing on non-zero exit.
|
|
3
|
+
*
|
|
4
|
+
* Distinguishes between:
|
|
5
|
+
* - Spawn failure (file not found, permission denied) → code = null
|
|
6
|
+
* - Non-zero exit (process ran but returned error) → code = exit code
|
|
7
|
+
* - Success → code = 0
|
|
8
|
+
*/
|
|
9
|
+
export interface ExecFileNoThrowResult {
|
|
10
|
+
/** Process exit code (0 = success, null = spawn failed). */
|
|
11
|
+
code: number | null;
|
|
12
|
+
stdout: string;
|
|
13
|
+
stderr: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ExecFileNoThrowOptions {
|
|
16
|
+
/** stdin input to pipe to the process. */
|
|
17
|
+
input?: string;
|
|
18
|
+
/** Working directory. */
|
|
19
|
+
cwd?: string;
|
|
20
|
+
/** Timeout in ms (default 10_000). */
|
|
21
|
+
timeout?: number;
|
|
22
|
+
/** Environment variables to merge. */
|
|
23
|
+
env?: Record<string, string | undefined>;
|
|
24
|
+
/** Shell to run in (if true, uses platform default). */
|
|
25
|
+
shell?: boolean | string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run a command and return exit code + stdout/stderr.
|
|
29
|
+
* Never throws — spawn failures return code=null.
|
|
30
|
+
*/
|
|
31
|
+
export declare function execFileNoThrow(file: string, args: string[], options?: ExecFileNoThrowOptions): Promise<ExecFileNoThrowResult>;
|
|
32
|
+
/**
|
|
33
|
+
* execFileNoThrow with explicit cwd (convenience wrapper).
|
|
34
|
+
*/
|
|
35
|
+
export declare function execFileNoThrowWithCwd(cwd: string, file: string, args: string[], options?: Omit<ExecFileNoThrowOptions, "cwd">): Promise<ExecFileNoThrowResult>;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use execFileNoThrow directly.
|
|
38
|
+
*/
|
|
39
|
+
export declare function execSyncWithDefaults_DEPRECATED(..._args: any[]): any;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a child process without throwing on non-zero exit.
|
|
3
|
+
*
|
|
4
|
+
* Distinguishes between:
|
|
5
|
+
* - Spawn failure (file not found, permission denied) → code = null
|
|
6
|
+
* - Non-zero exit (process ran but returned error) → code = exit code
|
|
7
|
+
* - Success → code = 0
|
|
8
|
+
*/
|
|
9
|
+
import { execFile } from "node:child_process";
|
|
10
|
+
/**
|
|
11
|
+
* Run a command and return exit code + stdout/stderr.
|
|
12
|
+
* Never throws — spawn failures return code=null.
|
|
13
|
+
*/
|
|
14
|
+
export function execFileNoThrow(file, args, options) {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
const execOpts = {
|
|
17
|
+
timeout: options?.timeout ?? 10_000,
|
|
18
|
+
maxBuffer: 10 * 1024 * 1024, // 10MB
|
|
19
|
+
encoding: "utf-8",
|
|
20
|
+
};
|
|
21
|
+
if (options?.cwd)
|
|
22
|
+
execOpts.cwd = options.cwd;
|
|
23
|
+
if (options?.env)
|
|
24
|
+
execOpts.env = { ...process.env, ...options.env };
|
|
25
|
+
if (options?.shell)
|
|
26
|
+
execOpts.shell = options.shell === true ? undefined : options.shell;
|
|
27
|
+
const child = execFile(file, args, execOpts, (error, stdout, stderr) => {
|
|
28
|
+
if (error) {
|
|
29
|
+
// Distinguish spawn failure vs non-zero exit
|
|
30
|
+
const errno = error;
|
|
31
|
+
if (errno.code === "ENOENT" || errno.code === "EACCES" || errno.code === "EPERM") {
|
|
32
|
+
// Spawn failure — file not found or permission denied
|
|
33
|
+
resolve({
|
|
34
|
+
code: null,
|
|
35
|
+
stdout: String(stdout ?? ""),
|
|
36
|
+
stderr: errno.message,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Non-zero exit or killed by signal
|
|
41
|
+
resolve({
|
|
42
|
+
code: error.code != null ? (typeof error.code === "number" ? error.code : 1) : 1,
|
|
43
|
+
stdout: String(stdout ?? ""),
|
|
44
|
+
stderr: String(stderr ?? ""),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
resolve({
|
|
50
|
+
code: 0,
|
|
51
|
+
stdout: String(stdout ?? ""),
|
|
52
|
+
stderr: String(stderr ?? ""),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
// Pipe stdin if provided
|
|
57
|
+
if (options?.input && child.stdin) {
|
|
58
|
+
child.stdin.write(options.input);
|
|
59
|
+
child.stdin.end();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* execFileNoThrow with explicit cwd (convenience wrapper).
|
|
65
|
+
*/
|
|
66
|
+
export function execFileNoThrowWithCwd(cwd, file, args, options) {
|
|
67
|
+
return execFileNoThrow(file, args, { ...options, cwd });
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use execFileNoThrow directly.
|
|
71
|
+
*/
|
|
72
|
+
export function execSyncWithDefaults_DEPRECATED(..._args) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a byte count to a human-readable string (KB, MB, GB).
|
|
3
|
+
* @example formatFileSize(1536) → "1.5KB"
|
|
4
|
+
*/
|
|
5
|
+
export declare function formatFileSize(sizeInBytes: number): string;
|
|
6
|
+
/**
|
|
7
|
+
* Formats milliseconds as seconds with 1 decimal place (e.g. `1234` → `"1.2s"`).
|
|
8
|
+
* Unlike formatDuration, always keeps the decimal — use for sub-minute timings
|
|
9
|
+
* where the fractional second is meaningful (TTFT, hook durations, etc.).
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatSecondsShort(ms: number): string;
|
|
12
|
+
export declare function formatDuration(ms: number, options?: {
|
|
13
|
+
hideTrailingZeros?: boolean;
|
|
14
|
+
mostSignificantOnly?: boolean;
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function formatNumber(number: number): string;
|
|
17
|
+
export declare function formatTokens(count: number): string;
|
|
18
|
+
type RelativeTimeStyle = 'long' | 'short' | 'narrow';
|
|
19
|
+
type RelativeTimeOptions = {
|
|
20
|
+
style?: RelativeTimeStyle;
|
|
21
|
+
numeric?: 'always' | 'auto';
|
|
22
|
+
};
|
|
23
|
+
export declare function formatRelativeTime(date: Date, options?: RelativeTimeOptions & {
|
|
24
|
+
now?: Date;
|
|
25
|
+
}): string;
|
|
26
|
+
export declare function formatRelativeTimeAgo(date: Date, options?: RelativeTimeOptions & {
|
|
27
|
+
now?: Date;
|
|
28
|
+
}): string;
|
|
29
|
+
/**
|
|
30
|
+
* Formats log metadata for display (time, size or message count, branch, tag, PR)
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatLogMetadata(log: {
|
|
33
|
+
modified: Date;
|
|
34
|
+
messageCount: number;
|
|
35
|
+
fileSize?: number;
|
|
36
|
+
gitBranch?: string;
|
|
37
|
+
tag?: string;
|
|
38
|
+
agentSetting?: string;
|
|
39
|
+
prNumber?: number;
|
|
40
|
+
prRepository?: string;
|
|
41
|
+
}): string;
|
|
42
|
+
export declare function formatResetTime(timestampInSeconds: number | undefined, showTimezone?: boolean, showTime?: boolean): string | undefined;
|
|
43
|
+
export declare function formatResetText(resetsAt: string, showTimezone?: boolean, showTime?: boolean): string;
|
|
44
|
+
export {};
|