@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,236 @@
|
|
|
1
|
+
// Pure display formatters — leaf-safe (no Ink). Width-aware truncation lives in ./truncate.ts.
|
|
2
|
+
import { getRelativeTimeFormat, getTimeZone } from './intl.js';
|
|
3
|
+
/**
|
|
4
|
+
* Formats a byte count to a human-readable string (KB, MB, GB).
|
|
5
|
+
* @example formatFileSize(1536) → "1.5KB"
|
|
6
|
+
*/
|
|
7
|
+
export function formatFileSize(sizeInBytes) {
|
|
8
|
+
const kb = sizeInBytes / 1024;
|
|
9
|
+
if (kb < 1) {
|
|
10
|
+
return `${sizeInBytes} bytes`;
|
|
11
|
+
}
|
|
12
|
+
if (kb < 1024) {
|
|
13
|
+
return `${kb.toFixed(1).replace(/\.0$/, '')}KB`;
|
|
14
|
+
}
|
|
15
|
+
const mb = kb / 1024;
|
|
16
|
+
if (mb < 1024) {
|
|
17
|
+
return `${mb.toFixed(1).replace(/\.0$/, '')}MB`;
|
|
18
|
+
}
|
|
19
|
+
const gb = mb / 1024;
|
|
20
|
+
return `${gb.toFixed(1).replace(/\.0$/, '')}GB`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Formats milliseconds as seconds with 1 decimal place (e.g. `1234` → `"1.2s"`).
|
|
24
|
+
* Unlike formatDuration, always keeps the decimal — use for sub-minute timings
|
|
25
|
+
* where the fractional second is meaningful (TTFT, hook durations, etc.).
|
|
26
|
+
*/
|
|
27
|
+
export function formatSecondsShort(ms) {
|
|
28
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
29
|
+
}
|
|
30
|
+
export function formatDuration(ms, options) {
|
|
31
|
+
if (ms < 60000) {
|
|
32
|
+
// Special case for 0
|
|
33
|
+
if (ms === 0) {
|
|
34
|
+
return '0s';
|
|
35
|
+
}
|
|
36
|
+
// For durations < 1s, show 1 decimal place (e.g., 0.5s)
|
|
37
|
+
if (ms < 1) {
|
|
38
|
+
const s = (ms / 1000).toFixed(1);
|
|
39
|
+
return `${s}s`;
|
|
40
|
+
}
|
|
41
|
+
const s = Math.floor(ms / 1000).toString();
|
|
42
|
+
return `${s}s`;
|
|
43
|
+
}
|
|
44
|
+
let days = Math.floor(ms / 86400000);
|
|
45
|
+
let hours = Math.floor((ms % 86400000) / 3600000);
|
|
46
|
+
let minutes = Math.floor((ms % 3600000) / 60000);
|
|
47
|
+
let seconds = Math.round((ms % 60000) / 1000);
|
|
48
|
+
// Handle rounding carry-over (e.g., 59.5s rounds to 60s)
|
|
49
|
+
if (seconds === 60) {
|
|
50
|
+
seconds = 0;
|
|
51
|
+
minutes++;
|
|
52
|
+
}
|
|
53
|
+
if (minutes === 60) {
|
|
54
|
+
minutes = 0;
|
|
55
|
+
hours++;
|
|
56
|
+
}
|
|
57
|
+
if (hours === 24) {
|
|
58
|
+
hours = 0;
|
|
59
|
+
days++;
|
|
60
|
+
}
|
|
61
|
+
const hide = options?.hideTrailingZeros;
|
|
62
|
+
if (options?.mostSignificantOnly) {
|
|
63
|
+
if (days > 0)
|
|
64
|
+
return `${days}d`;
|
|
65
|
+
if (hours > 0)
|
|
66
|
+
return `${hours}h`;
|
|
67
|
+
if (minutes > 0)
|
|
68
|
+
return `${minutes}m`;
|
|
69
|
+
return `${seconds}s`;
|
|
70
|
+
}
|
|
71
|
+
if (days > 0) {
|
|
72
|
+
if (hide && hours === 0 && minutes === 0)
|
|
73
|
+
return `${days}d`;
|
|
74
|
+
if (hide && minutes === 0)
|
|
75
|
+
return `${days}d ${hours}h`;
|
|
76
|
+
return `${days}d ${hours}h ${minutes}m`;
|
|
77
|
+
}
|
|
78
|
+
if (hours > 0) {
|
|
79
|
+
if (hide && minutes === 0 && seconds === 0)
|
|
80
|
+
return `${hours}h`;
|
|
81
|
+
if (hide && seconds === 0)
|
|
82
|
+
return `${hours}h ${minutes}m`;
|
|
83
|
+
return `${hours}h ${minutes}m ${seconds}s`;
|
|
84
|
+
}
|
|
85
|
+
if (minutes > 0) {
|
|
86
|
+
if (hide && seconds === 0)
|
|
87
|
+
return `${minutes}m`;
|
|
88
|
+
return `${minutes}m ${seconds}s`;
|
|
89
|
+
}
|
|
90
|
+
return `${seconds}s`;
|
|
91
|
+
}
|
|
92
|
+
// `new Intl.NumberFormat` is expensive, so cache formatters for reuse
|
|
93
|
+
let numberFormatterForConsistentDecimals = null;
|
|
94
|
+
let numberFormatterForInconsistentDecimals = null;
|
|
95
|
+
const getNumberFormatter = (useConsistentDecimals) => {
|
|
96
|
+
if (useConsistentDecimals) {
|
|
97
|
+
if (!numberFormatterForConsistentDecimals) {
|
|
98
|
+
numberFormatterForConsistentDecimals = new Intl.NumberFormat('en-US', {
|
|
99
|
+
notation: 'compact',
|
|
100
|
+
maximumFractionDigits: 1,
|
|
101
|
+
minimumFractionDigits: 1,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return numberFormatterForConsistentDecimals;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
if (!numberFormatterForInconsistentDecimals) {
|
|
108
|
+
numberFormatterForInconsistentDecimals = new Intl.NumberFormat('en-US', {
|
|
109
|
+
notation: 'compact',
|
|
110
|
+
maximumFractionDigits: 1,
|
|
111
|
+
minimumFractionDigits: 0,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return numberFormatterForInconsistentDecimals;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
export function formatNumber(number) {
|
|
118
|
+
// Only use minimumFractionDigits for numbers that will be shown in compact notation
|
|
119
|
+
const shouldUseConsistentDecimals = number >= 1000;
|
|
120
|
+
return getNumberFormatter(shouldUseConsistentDecimals)
|
|
121
|
+
.format(number) // eg. "1321" => "1.3K", "900" => "900"
|
|
122
|
+
.toLowerCase(); // eg. "1.3K" => "1.3k", "1.0K" => "1.0k"
|
|
123
|
+
}
|
|
124
|
+
export function formatTokens(count) {
|
|
125
|
+
return formatNumber(count).replace('.0', '');
|
|
126
|
+
}
|
|
127
|
+
export function formatRelativeTime(date, options = {}) {
|
|
128
|
+
const { style = 'narrow', numeric = 'always', now = new Date() } = options;
|
|
129
|
+
const diffInMs = date.getTime() - now.getTime();
|
|
130
|
+
// Use Math.trunc to truncate towards zero for both positive and negative values
|
|
131
|
+
const diffInSeconds = Math.trunc(diffInMs / 1000);
|
|
132
|
+
// Define time intervals with custom short units
|
|
133
|
+
const intervals = [
|
|
134
|
+
{ unit: 'year', seconds: 31536000, shortUnit: 'y' },
|
|
135
|
+
{ unit: 'month', seconds: 2592000, shortUnit: 'mo' },
|
|
136
|
+
{ unit: 'week', seconds: 604800, shortUnit: 'w' },
|
|
137
|
+
{ unit: 'day', seconds: 86400, shortUnit: 'd' },
|
|
138
|
+
{ unit: 'hour', seconds: 3600, shortUnit: 'h' },
|
|
139
|
+
{ unit: 'minute', seconds: 60, shortUnit: 'm' },
|
|
140
|
+
{ unit: 'second', seconds: 1, shortUnit: 's' },
|
|
141
|
+
];
|
|
142
|
+
// Find the appropriate unit
|
|
143
|
+
for (const { unit, seconds: intervalSeconds, shortUnit } of intervals) {
|
|
144
|
+
if (Math.abs(diffInSeconds) >= intervalSeconds) {
|
|
145
|
+
const value = Math.trunc(diffInSeconds / intervalSeconds);
|
|
146
|
+
// For short style, use custom format
|
|
147
|
+
if (style === 'narrow') {
|
|
148
|
+
return diffInSeconds < 0
|
|
149
|
+
? `${Math.abs(value)}${shortUnit} ago`
|
|
150
|
+
: `in ${value}${shortUnit}`;
|
|
151
|
+
}
|
|
152
|
+
// For days and longer, use long style regardless of the style parameter
|
|
153
|
+
return getRelativeTimeFormat('long', numeric).format(value, unit);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// For values less than 1 second
|
|
157
|
+
if (style === 'narrow') {
|
|
158
|
+
return diffInSeconds <= 0 ? '0s ago' : 'in 0s';
|
|
159
|
+
}
|
|
160
|
+
return getRelativeTimeFormat(style, numeric).format(0, 'second');
|
|
161
|
+
}
|
|
162
|
+
export function formatRelativeTimeAgo(date, options = {}) {
|
|
163
|
+
const { now = new Date(), ...restOptions } = options;
|
|
164
|
+
if (date > now) {
|
|
165
|
+
// For future dates, just return the relative time without "ago"
|
|
166
|
+
return formatRelativeTime(date, { ...restOptions, now });
|
|
167
|
+
}
|
|
168
|
+
// For past dates, force numeric: 'always' to ensure we get "X units ago"
|
|
169
|
+
return formatRelativeTime(date, { ...restOptions, numeric: 'always', now });
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Formats log metadata for display (time, size or message count, branch, tag, PR)
|
|
173
|
+
*/
|
|
174
|
+
export function formatLogMetadata(log) {
|
|
175
|
+
const sizeOrCount = log.fileSize !== undefined
|
|
176
|
+
? formatFileSize(log.fileSize)
|
|
177
|
+
: `${log.messageCount} messages`;
|
|
178
|
+
const parts = [
|
|
179
|
+
formatRelativeTimeAgo(log.modified, { style: 'short' }),
|
|
180
|
+
...(log.gitBranch ? [log.gitBranch] : []),
|
|
181
|
+
sizeOrCount,
|
|
182
|
+
];
|
|
183
|
+
if (log.tag) {
|
|
184
|
+
parts.push(`#${log.tag}`);
|
|
185
|
+
}
|
|
186
|
+
if (log.agentSetting) {
|
|
187
|
+
parts.push(`@${log.agentSetting}`);
|
|
188
|
+
}
|
|
189
|
+
if (log.prNumber) {
|
|
190
|
+
parts.push(log.prRepository
|
|
191
|
+
? `${log.prRepository}#${log.prNumber}`
|
|
192
|
+
: `#${log.prNumber}`);
|
|
193
|
+
}
|
|
194
|
+
return parts.join(' · ');
|
|
195
|
+
}
|
|
196
|
+
export function formatResetTime(timestampInSeconds, showTimezone = false, showTime = true) {
|
|
197
|
+
if (!timestampInSeconds)
|
|
198
|
+
return undefined;
|
|
199
|
+
const date = new Date(timestampInSeconds * 1000);
|
|
200
|
+
const now = new Date();
|
|
201
|
+
const minutes = date.getMinutes();
|
|
202
|
+
// Calculate hours until reset
|
|
203
|
+
const hoursUntilReset = (date.getTime() - now.getTime()) / (1000 * 60 * 60);
|
|
204
|
+
// If reset is more than 24 hours away, show the date as well
|
|
205
|
+
if (hoursUntilReset > 24) {
|
|
206
|
+
// Show date and time for resets more than a day away
|
|
207
|
+
const dateOptions = {
|
|
208
|
+
month: 'short',
|
|
209
|
+
day: 'numeric',
|
|
210
|
+
hour: showTime ? 'numeric' : undefined,
|
|
211
|
+
minute: !showTime || minutes === 0 ? undefined : '2-digit',
|
|
212
|
+
hour12: showTime ? true : undefined,
|
|
213
|
+
};
|
|
214
|
+
// Add year if it's not the current year
|
|
215
|
+
if (date.getFullYear() !== now.getFullYear()) {
|
|
216
|
+
dateOptions.year = 'numeric';
|
|
217
|
+
}
|
|
218
|
+
const dateString = date.toLocaleString('en-US', dateOptions);
|
|
219
|
+
// Remove the space before AM/PM and make it lowercase
|
|
220
|
+
return (dateString.replace(/ ([AP]M)/i, (_match, ampm) => ampm.toLowerCase()) +
|
|
221
|
+
(showTimezone ? ` (${getTimeZone()})` : ''));
|
|
222
|
+
}
|
|
223
|
+
// For resets within 24 hours, show just the time (existing behavior)
|
|
224
|
+
const timeString = date.toLocaleTimeString('en-US', {
|
|
225
|
+
hour: 'numeric',
|
|
226
|
+
minute: minutes === 0 ? undefined : '2-digit',
|
|
227
|
+
hour12: true,
|
|
228
|
+
});
|
|
229
|
+
// Remove the space before AM/PM and make it lowercase, then add timezone
|
|
230
|
+
return (timeString.replace(/ ([AP]M)/i, (_match, ampm) => ampm.toLowerCase()) +
|
|
231
|
+
(showTimezone ? ` (${getTimeZone()})` : ''));
|
|
232
|
+
}
|
|
233
|
+
export function formatResetText(resetsAt, showTimezone = false, showTime = true) {
|
|
234
|
+
const dt = new Date(resetsAt);
|
|
235
|
+
return `${formatResetTime(Math.floor(dt.getTime() / 1000), showTimezone, showTime)}`;
|
|
236
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Intl object instances with lazy initialization.
|
|
3
|
+
*
|
|
4
|
+
* Intl constructors are expensive (~0.05-0.1ms each), so we cache instances
|
|
5
|
+
* for reuse across the codebase instead of creating new ones each time.
|
|
6
|
+
* Lazy initialization ensures we only pay the cost when actually needed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getGraphemeSegmenter(): Intl.Segmenter;
|
|
9
|
+
/**
|
|
10
|
+
* Extract the first grapheme cluster from a string.
|
|
11
|
+
* Returns '' for empty strings.
|
|
12
|
+
*/
|
|
13
|
+
export declare function firstGrapheme(text: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Extract the last grapheme cluster from a string.
|
|
16
|
+
* Returns '' for empty strings.
|
|
17
|
+
*/
|
|
18
|
+
export declare function lastGrapheme(text: string): string;
|
|
19
|
+
export declare function getWordSegmenter(): Intl.Segmenter;
|
|
20
|
+
export declare function getRelativeTimeFormat(style: 'long' | 'short' | 'narrow', numeric: 'always' | 'auto'): Intl.RelativeTimeFormat;
|
|
21
|
+
export declare function getTimeZone(): string;
|
|
22
|
+
export declare function getSystemLocaleLanguage(): string | undefined;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Intl object instances with lazy initialization.
|
|
3
|
+
*
|
|
4
|
+
* Intl constructors are expensive (~0.05-0.1ms each), so we cache instances
|
|
5
|
+
* for reuse across the codebase instead of creating new ones each time.
|
|
6
|
+
* Lazy initialization ensures we only pay the cost when actually needed.
|
|
7
|
+
*/
|
|
8
|
+
// Segmenters for Unicode text processing (lazily initialized)
|
|
9
|
+
let graphemeSegmenter = null;
|
|
10
|
+
let wordSegmenter = null;
|
|
11
|
+
export function getGraphemeSegmenter() {
|
|
12
|
+
if (!graphemeSegmenter) {
|
|
13
|
+
graphemeSegmenter = new Intl.Segmenter(undefined, {
|
|
14
|
+
granularity: 'grapheme',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return graphemeSegmenter;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extract the first grapheme cluster from a string.
|
|
21
|
+
* Returns '' for empty strings.
|
|
22
|
+
*/
|
|
23
|
+
export function firstGrapheme(text) {
|
|
24
|
+
if (!text)
|
|
25
|
+
return '';
|
|
26
|
+
const segments = getGraphemeSegmenter().segment(text);
|
|
27
|
+
const first = segments[Symbol.iterator]().next().value;
|
|
28
|
+
return first?.segment ?? '';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extract the last grapheme cluster from a string.
|
|
32
|
+
* Returns '' for empty strings.
|
|
33
|
+
*/
|
|
34
|
+
export function lastGrapheme(text) {
|
|
35
|
+
if (!text)
|
|
36
|
+
return '';
|
|
37
|
+
let last = '';
|
|
38
|
+
for (const { segment } of getGraphemeSegmenter().segment(text)) {
|
|
39
|
+
last = segment;
|
|
40
|
+
}
|
|
41
|
+
return last;
|
|
42
|
+
}
|
|
43
|
+
export function getWordSegmenter() {
|
|
44
|
+
if (!wordSegmenter) {
|
|
45
|
+
wordSegmenter = new Intl.Segmenter(undefined, { granularity: 'word' });
|
|
46
|
+
}
|
|
47
|
+
return wordSegmenter;
|
|
48
|
+
}
|
|
49
|
+
// RelativeTimeFormat cache (keyed by style:numeric)
|
|
50
|
+
const rtfCache = new Map();
|
|
51
|
+
export function getRelativeTimeFormat(style, numeric) {
|
|
52
|
+
const key = `${style}:${numeric}`;
|
|
53
|
+
let rtf = rtfCache.get(key);
|
|
54
|
+
if (!rtf) {
|
|
55
|
+
rtf = new Intl.RelativeTimeFormat('en', { style, numeric });
|
|
56
|
+
rtfCache.set(key, rtf);
|
|
57
|
+
}
|
|
58
|
+
return rtf;
|
|
59
|
+
}
|
|
60
|
+
// Timezone is constant for the process lifetime
|
|
61
|
+
let cachedTimeZone = null;
|
|
62
|
+
export function getTimeZone() {
|
|
63
|
+
if (!cachedTimeZone) {
|
|
64
|
+
cachedTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
65
|
+
}
|
|
66
|
+
return cachedTimeZone;
|
|
67
|
+
}
|
|
68
|
+
// System locale language subtag (e.g. 'en', 'ja') is constant for the process
|
|
69
|
+
// lifetime. null = not yet computed; undefined = computed but unavailable (so
|
|
70
|
+
// a stripped-ICU environment fails once instead of retrying on every call).
|
|
71
|
+
let cachedSystemLocaleLanguage = null;
|
|
72
|
+
export function getSystemLocaleLanguage() {
|
|
73
|
+
if (cachedSystemLocaleLanguage === null) {
|
|
74
|
+
try {
|
|
75
|
+
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
76
|
+
cachedSystemLocaleLanguage = new Intl.Locale(locale).language;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
cachedSystemLocaleLanguage = undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return cachedSystemLocaleLanguage;
|
|
83
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy accessor for proper-lockfile.
|
|
3
|
+
*
|
|
4
|
+
* proper-lockfile depends on graceful-fs, which monkey-patches every fs
|
|
5
|
+
* method on first require (~8ms). Static imports of proper-lockfile pull this
|
|
6
|
+
* cost into the startup path even when no locking happens (e.g. `--help`).
|
|
7
|
+
*
|
|
8
|
+
* Import this module instead of `proper-lockfile` directly. The underlying
|
|
9
|
+
* package is only loaded the first time a lock function is actually called.
|
|
10
|
+
*/
|
|
11
|
+
import type { CheckOptions, LockOptions, UnlockOptions } from 'proper-lockfile';
|
|
12
|
+
export declare function lock(file: string, options?: LockOptions): Promise<() => Promise<void>>;
|
|
13
|
+
export declare function lockSync(file: string, options?: LockOptions): () => void;
|
|
14
|
+
export declare function unlock(file: string, options?: UnlockOptions): Promise<void>;
|
|
15
|
+
export declare function check(file: string, options?: CheckOptions): Promise<boolean>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy accessor for proper-lockfile.
|
|
3
|
+
*
|
|
4
|
+
* proper-lockfile depends on graceful-fs, which monkey-patches every fs
|
|
5
|
+
* method on first require (~8ms). Static imports of proper-lockfile pull this
|
|
6
|
+
* cost into the startup path even when no locking happens (e.g. `--help`).
|
|
7
|
+
*
|
|
8
|
+
* Import this module instead of `proper-lockfile` directly. The underlying
|
|
9
|
+
* package is only loaded the first time a lock function is actually called.
|
|
10
|
+
*/
|
|
11
|
+
let _lockfile;
|
|
12
|
+
function getLockfile() {
|
|
13
|
+
if (!_lockfile) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
15
|
+
_lockfile = require('proper-lockfile');
|
|
16
|
+
}
|
|
17
|
+
return _lockfile;
|
|
18
|
+
}
|
|
19
|
+
export function lock(file, options) {
|
|
20
|
+
return getLockfile().lock(file, options);
|
|
21
|
+
}
|
|
22
|
+
export function lockSync(file, options) {
|
|
23
|
+
return getLockfile().lockSync(file, options);
|
|
24
|
+
}
|
|
25
|
+
export function unlock(file, options) {
|
|
26
|
+
return getLockfile().unlock(file, options);
|
|
27
|
+
}
|
|
28
|
+
export function check(file, options) {
|
|
29
|
+
return getLockfile().check(file, options);
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal memoize with a custom cache-key resolver — same shape as
|
|
3
|
+
* lodash's `memoize(fn, resolver)` for the call sites that need to
|
|
4
|
+
* derive the cache key from arguments + side-channel state (e.g.
|
|
5
|
+
* "user home + installed-plugins mtime"). Kept in-tree to drop the
|
|
6
|
+
* lodash-es dependency from the core package.
|
|
7
|
+
*
|
|
8
|
+
* The returned function exposes `.cache` matching the subset of
|
|
9
|
+
* lodash's MapCache API the existing call sites use (`.clear()`).
|
|
10
|
+
* Cache lives for the lifetime of the returned function. Not LRU —
|
|
11
|
+
* call sites cache scan results keyed by a string that changes when
|
|
12
|
+
* external state changes, so unbounded growth is bounded by the
|
|
13
|
+
* cardinality of that key.
|
|
14
|
+
*/
|
|
15
|
+
export interface MemoizedFn<Args extends readonly unknown[], R> {
|
|
16
|
+
(...args: Args): R;
|
|
17
|
+
cache: Map<string, R>;
|
|
18
|
+
}
|
|
19
|
+
export declare function memoize<Args extends readonly unknown[], R>(fn: (...args: Args) => R, resolver: (...args: Args) => string): MemoizedFn<Args, R>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function memoize(fn, resolver) {
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
const memoized = ((...args) => {
|
|
4
|
+
const key = resolver(...args);
|
|
5
|
+
const hit = cache.get(key);
|
|
6
|
+
if (hit !== undefined || cache.has(key))
|
|
7
|
+
return hit;
|
|
8
|
+
const result = fn(...args);
|
|
9
|
+
cache.set(key, result);
|
|
10
|
+
return result;
|
|
11
|
+
});
|
|
12
|
+
memoized.cache = cache;
|
|
13
|
+
return memoized;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shim for CC's utils/semver — re-exports semver comparison helpers.
|
|
3
|
+
*/
|
|
4
|
+
import { gte as semverGte, gt as semverGt, lt as semverLt } from 'semver';
|
|
5
|
+
export function gte(a, b) {
|
|
6
|
+
return semverGte(a, b);
|
|
7
|
+
}
|
|
8
|
+
export function gt(a, b) {
|
|
9
|
+
return semverGt(a, b);
|
|
10
|
+
}
|
|
11
|
+
export function lt(a, b) {
|
|
12
|
+
return semverLt(a, b);
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shim for CC's utils/sliceAnsi — slices an ANSI-styled string by display
|
|
3
|
+
* column position while preserving escape sequences.
|
|
4
|
+
*
|
|
5
|
+
* This is a lightweight implementation. For full fidelity with wide characters
|
|
6
|
+
* and complex ANSI sequences, consider installing `slice-ansi`.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Slice a string that may contain ANSI escape codes by *visible* character
|
|
10
|
+
* positions (start inclusive, end exclusive).
|
|
11
|
+
*/
|
|
12
|
+
export default function sliceAnsi(text: string, start: number, end?: number): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shim for CC's utils/sliceAnsi — slices an ANSI-styled string by display
|
|
3
|
+
* column position while preserving escape sequences.
|
|
4
|
+
*
|
|
5
|
+
* This is a lightweight implementation. For full fidelity with wide characters
|
|
6
|
+
* and complex ANSI sequences, consider installing `slice-ansi`.
|
|
7
|
+
*/
|
|
8
|
+
import stripAnsi from 'strip-ansi';
|
|
9
|
+
// Matches a single ANSI escape sequence
|
|
10
|
+
const ANSI_RE = /\x1b\[[0-9;]*m/g;
|
|
11
|
+
/**
|
|
12
|
+
* Slice a string that may contain ANSI escape codes by *visible* character
|
|
13
|
+
* positions (start inclusive, end exclusive).
|
|
14
|
+
*/
|
|
15
|
+
export default function sliceAnsi(text, start, end) {
|
|
16
|
+
// Fast path: no ANSI codes at all
|
|
17
|
+
if (!text.includes('\x1b')) {
|
|
18
|
+
return text.slice(start, end);
|
|
19
|
+
}
|
|
20
|
+
const chars = [];
|
|
21
|
+
let i = 0;
|
|
22
|
+
while (i < text.length) {
|
|
23
|
+
ANSI_RE.lastIndex = i;
|
|
24
|
+
const m = ANSI_RE.exec(text);
|
|
25
|
+
if (m && m.index === i) {
|
|
26
|
+
chars.push({ ch: m[0], visible: false });
|
|
27
|
+
i += m[0].length;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
chars.push({ ch: text[i], visible: true });
|
|
31
|
+
i++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const finalEnd = end ?? stripAnsi(text).length;
|
|
35
|
+
let visIdx = 0;
|
|
36
|
+
let result = '';
|
|
37
|
+
let activeStyles = '';
|
|
38
|
+
for (const { ch, visible } of chars) {
|
|
39
|
+
if (!visible) {
|
|
40
|
+
// Always accumulate style sequences that precede visible chars in range
|
|
41
|
+
if (visIdx >= start && visIdx < finalEnd) {
|
|
42
|
+
result += ch;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
activeStyles += ch;
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (visIdx >= start && visIdx < finalEnd) {
|
|
50
|
+
// First visible char in range: prepend any accumulated styles
|
|
51
|
+
if (activeStyles) {
|
|
52
|
+
result += activeStyles;
|
|
53
|
+
activeStyles = '';
|
|
54
|
+
}
|
|
55
|
+
result += ch;
|
|
56
|
+
}
|
|
57
|
+
visIdx++;
|
|
58
|
+
if (visIdx >= finalEnd)
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal dark/light mode detection for the 'auto' theme setting.
|
|
3
|
+
*
|
|
4
|
+
* Detection is based on the terminal's actual background color (queried via
|
|
5
|
+
* OSC 11 by systemThemeWatcher.ts) rather than the OS appearance setting —
|
|
6
|
+
* a dark terminal on a light-mode OS should still resolve to 'dark'.
|
|
7
|
+
*
|
|
8
|
+
* The detected theme is cached module-level so callers can resolve 'auto'
|
|
9
|
+
* without awaiting the async OSC round-trip. The cache is seeded from
|
|
10
|
+
* $COLORFGBG (synchronous, set by some terminals at launch) and then
|
|
11
|
+
* updated by the watcher once the OSC 11 response arrives.
|
|
12
|
+
*/
|
|
13
|
+
import type { ThemeName, ThemeSetting } from './theme.js';
|
|
14
|
+
export type SystemTheme = 'dark' | 'light';
|
|
15
|
+
/**
|
|
16
|
+
* Get the current terminal theme. Cached after first detection; the watcher
|
|
17
|
+
* updates the cache on live changes.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getSystemThemeName(): SystemTheme;
|
|
20
|
+
/**
|
|
21
|
+
* Update the cached terminal theme. Called by the watcher when the OSC 11
|
|
22
|
+
* query returns so non-React call sites stay in sync.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setCachedSystemTheme(theme: SystemTheme): void;
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a ThemeSetting (which may be 'auto') to a concrete ThemeName.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveThemeSetting(setting: ThemeSetting): ThemeName;
|
|
29
|
+
/**
|
|
30
|
+
* Parse an OSC color response data string into a theme.
|
|
31
|
+
*
|
|
32
|
+
* Accepts XParseColor formats returned by OSC 10/11 queries:
|
|
33
|
+
* - `rgb:R/G/B` where each component is 1–4 hex digits (each scaled to
|
|
34
|
+
* [0, 16^n - 1] for n digits). This is what xterm, iTerm2, Terminal.app,
|
|
35
|
+
* Ghostty, kitty, Alacritty, etc. return.
|
|
36
|
+
* - `#RRGGBB` / `#RRRRGGGGBBBB` (rare, but cheap to accept).
|
|
37
|
+
*
|
|
38
|
+
* Returns undefined for unrecognized formats so callers can fall back.
|
|
39
|
+
*/
|
|
40
|
+
export declare function themeFromOscColor(data: string): SystemTheme | undefined;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal dark/light mode detection for the 'auto' theme setting.
|
|
3
|
+
*
|
|
4
|
+
* Detection is based on the terminal's actual background color (queried via
|
|
5
|
+
* OSC 11 by systemThemeWatcher.ts) rather than the OS appearance setting —
|
|
6
|
+
* a dark terminal on a light-mode OS should still resolve to 'dark'.
|
|
7
|
+
*
|
|
8
|
+
* The detected theme is cached module-level so callers can resolve 'auto'
|
|
9
|
+
* without awaiting the async OSC round-trip. The cache is seeded from
|
|
10
|
+
* $COLORFGBG (synchronous, set by some terminals at launch) and then
|
|
11
|
+
* updated by the watcher once the OSC 11 response arrives.
|
|
12
|
+
*/
|
|
13
|
+
let cachedSystemTheme;
|
|
14
|
+
/**
|
|
15
|
+
* Get the current terminal theme. Cached after first detection; the watcher
|
|
16
|
+
* updates the cache on live changes.
|
|
17
|
+
*/
|
|
18
|
+
export function getSystemThemeName() {
|
|
19
|
+
if (cachedSystemTheme === undefined) {
|
|
20
|
+
cachedSystemTheme = detectFromColorFgBg() ?? 'dark';
|
|
21
|
+
}
|
|
22
|
+
return cachedSystemTheme;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Update the cached terminal theme. Called by the watcher when the OSC 11
|
|
26
|
+
* query returns so non-React call sites stay in sync.
|
|
27
|
+
*/
|
|
28
|
+
export function setCachedSystemTheme(theme) {
|
|
29
|
+
cachedSystemTheme = theme;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve a ThemeSetting (which may be 'auto') to a concrete ThemeName.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveThemeSetting(setting) {
|
|
35
|
+
if (setting === 'auto') {
|
|
36
|
+
return getSystemThemeName();
|
|
37
|
+
}
|
|
38
|
+
return setting;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse an OSC color response data string into a theme.
|
|
42
|
+
*
|
|
43
|
+
* Accepts XParseColor formats returned by OSC 10/11 queries:
|
|
44
|
+
* - `rgb:R/G/B` where each component is 1–4 hex digits (each scaled to
|
|
45
|
+
* [0, 16^n - 1] for n digits). This is what xterm, iTerm2, Terminal.app,
|
|
46
|
+
* Ghostty, kitty, Alacritty, etc. return.
|
|
47
|
+
* - `#RRGGBB` / `#RRRRGGGGBBBB` (rare, but cheap to accept).
|
|
48
|
+
*
|
|
49
|
+
* Returns undefined for unrecognized formats so callers can fall back.
|
|
50
|
+
*/
|
|
51
|
+
export function themeFromOscColor(data) {
|
|
52
|
+
const rgb = parseOscRgb(data);
|
|
53
|
+
if (!rgb)
|
|
54
|
+
return undefined;
|
|
55
|
+
// ITU-R BT.709 relative luminance. Midpoint split: > 0.5 is light.
|
|
56
|
+
const luminance = 0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b;
|
|
57
|
+
return luminance > 0.5 ? 'light' : 'dark';
|
|
58
|
+
}
|
|
59
|
+
function parseOscRgb(data) {
|
|
60
|
+
// rgb:RRRR/GGGG/BBBB — each component is 1–4 hex digits.
|
|
61
|
+
// Some terminals append an alpha component (rgba:…/…/…/…); ignore it.
|
|
62
|
+
const rgbMatch = /^rgba?:([0-9a-f]{1,4})\/([0-9a-f]{1,4})\/([0-9a-f]{1,4})/i.exec(data);
|
|
63
|
+
if (rgbMatch) {
|
|
64
|
+
return {
|
|
65
|
+
r: hexComponent(rgbMatch[1]),
|
|
66
|
+
g: hexComponent(rgbMatch[2]),
|
|
67
|
+
b: hexComponent(rgbMatch[3]),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// #RRGGBB or #RRRRGGGGBBBB — split into three equal hex runs.
|
|
71
|
+
const hashMatch = /^#([0-9a-f]+)$/i.exec(data);
|
|
72
|
+
if (hashMatch && hashMatch[1].length % 3 === 0) {
|
|
73
|
+
const hex = hashMatch[1];
|
|
74
|
+
const n = hex.length / 3;
|
|
75
|
+
return {
|
|
76
|
+
r: hexComponent(hex.slice(0, n)),
|
|
77
|
+
g: hexComponent(hex.slice(n, 2 * n)),
|
|
78
|
+
b: hexComponent(hex.slice(2 * n)),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
/** Normalize a 1–4 digit hex component to [0, 1]. */
|
|
84
|
+
function hexComponent(hex) {
|
|
85
|
+
const max = 16 ** hex.length - 1;
|
|
86
|
+
return parseInt(hex, 16) / max;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Read $COLORFGBG for a synchronous initial guess before the OSC 11
|
|
90
|
+
* round-trip completes. Format is `fg;bg` (or `fg;other;bg`) where values
|
|
91
|
+
* are ANSI color indices. rxvt convention: bg 0–6 or 8 are dark; bg 7
|
|
92
|
+
* and 9–15 are light. Only set by some terminals (rxvt-family, Konsole,
|
|
93
|
+
* iTerm2 with the option enabled), so this is a best-effort hint.
|
|
94
|
+
*/
|
|
95
|
+
function detectFromColorFgBg() {
|
|
96
|
+
const colorfgbg = process.env['COLORFGBG'];
|
|
97
|
+
if (!colorfgbg)
|
|
98
|
+
return undefined;
|
|
99
|
+
const parts = colorfgbg.split(';');
|
|
100
|
+
const bg = parts[parts.length - 1];
|
|
101
|
+
if (bg === undefined || bg === '')
|
|
102
|
+
return undefined;
|
|
103
|
+
const bgNum = Number(bg);
|
|
104
|
+
if (!Number.isInteger(bgNum) || bgNum < 0 || bgNum > 15)
|
|
105
|
+
return undefined;
|
|
106
|
+
// 0–6 and 8 are dark ANSI colors; 7 (white) and 9–15 (bright) are light.
|
|
107
|
+
return bgNum <= 6 || bgNum === 8 ? 'dark' : 'light';
|
|
108
|
+
}
|