@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,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a user-typed marketplace identifier into a MarketplaceSource.
|
|
3
|
+
* MVP subset of Claude Code's utils/plugins/parseMarketplaceInput.ts —
|
|
4
|
+
* local absolute paths, github shorthand, https git URLs, and ssh git URLs.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Returns the parsed source, or null when the input does not match any
|
|
8
|
+
* supported pattern. Callers should show a usage hint on null.
|
|
9
|
+
*/
|
|
10
|
+
export function parseMarketplaceInput(input) {
|
|
11
|
+
const trimmed = input.trim();
|
|
12
|
+
if (trimmed === "")
|
|
13
|
+
return null;
|
|
14
|
+
// Absolute local path to a git repository (bare or with .git suffix).
|
|
15
|
+
// Useful for dev workflows where the marketplace lives on disk rather
|
|
16
|
+
// than at a remote URL. git clone itself accepts the same form.
|
|
17
|
+
if ((trimmed.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(trimmed)) &&
|
|
18
|
+
trimmed.endsWith(".git")) {
|
|
19
|
+
return { source: "git", url: trimmed };
|
|
20
|
+
}
|
|
21
|
+
// SSH: user@host:path[.git]
|
|
22
|
+
// Username can contain alphanumeric, dots, underscores, hyphens.
|
|
23
|
+
const sshMatch = trimmed.match(/^[a-zA-Z0-9._-]+@[^:\s]+:[^\s]+$/);
|
|
24
|
+
if (sshMatch) {
|
|
25
|
+
return { source: "git", url: trimmed };
|
|
26
|
+
}
|
|
27
|
+
// HTTPS
|
|
28
|
+
if (trimmed.startsWith("https://") || trimmed.startsWith("http://")) {
|
|
29
|
+
let parsed;
|
|
30
|
+
try {
|
|
31
|
+
parsed = new URL(trimmed);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (parsed.hostname === "github.com" || parsed.hostname === "www.github.com") {
|
|
37
|
+
const m = parsed.pathname.match(/^\/([^/]+\/[^/]+?)(\/|\.git|$)/);
|
|
38
|
+
if (!m)
|
|
39
|
+
return null;
|
|
40
|
+
const url = trimmed.endsWith(".git") ? trimmed : `${trimmed}.git`;
|
|
41
|
+
return { source: "git", url };
|
|
42
|
+
}
|
|
43
|
+
if (trimmed.endsWith(".git")) {
|
|
44
|
+
return { source: "git", url: trimmed };
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
// GitHub shorthand: owner/repo (single slash, no protocol, no spaces)
|
|
49
|
+
const shorthandMatch = trimmed.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\/([A-Za-z0-9._-]+?)(\.git)?$/);
|
|
50
|
+
if (shorthandMatch) {
|
|
51
|
+
const owner = shorthandMatch[1];
|
|
52
|
+
const repo = shorthandMatch[2];
|
|
53
|
+
return { source: "github", repo: `${owner}/${repo}` };
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Derive a stable marketplace name from a source. Used as the filesystem
|
|
59
|
+
* directory and the key in known_marketplaces.json.
|
|
60
|
+
*/
|
|
61
|
+
export function deriveMarketplaceName(source) {
|
|
62
|
+
if (source.source === "github") {
|
|
63
|
+
const parts = source.repo.split("/");
|
|
64
|
+
return parts[parts.length - 1].toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
// git: strip protocol, strip trailing .git, take last segment.
|
|
67
|
+
// Local path /tmp/foo/skills.git → name "skills"
|
|
68
|
+
// Local path /tmp/skills.git → name "skills"
|
|
69
|
+
const stripped = source.url.replace(/\.git$/, "");
|
|
70
|
+
const segments = stripped.split(/[/:]/).filter(Boolean);
|
|
71
|
+
const tail = segments[segments.length - 1] ?? "marketplace";
|
|
72
|
+
return tail.toLowerCase();
|
|
73
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pluginCommandHook — execute a plugin's command-type hook as a child
|
|
3
|
+
* process and translate its stdout into a HookResult.
|
|
4
|
+
*
|
|
5
|
+
* This is the plugin-side analogue of `src/hooks/shell-runner.ts`. The two
|
|
6
|
+
* runners are intentionally separate because they speak different protocols:
|
|
7
|
+
*
|
|
8
|
+
* src/hooks/shell-runner.ts codeshell-native: stdout is a HookResult
|
|
9
|
+
* JSON envelope ({ messages, decision, ... }).
|
|
10
|
+
* Used by user-authored settings.hooks.
|
|
11
|
+
*
|
|
12
|
+
* this file CC plugin protocol: stdout is one of
|
|
13
|
+
* - { hookSpecificOutput: { hookEventName, additionalContext } }
|
|
14
|
+
* - { additional_context: "..." } (Cursor)
|
|
15
|
+
* - { additionalContext: "..." } (SDK)
|
|
16
|
+
* We normalize all three into HookResult.messages
|
|
17
|
+
* so downstream hook plumbing (inject.ts) is
|
|
18
|
+
* untouched.
|
|
19
|
+
*
|
|
20
|
+
* env contract:
|
|
21
|
+
* CODESHELL_PLUGIN_ROOT — set to installPath. Plugin command strings
|
|
22
|
+
* reference this via ${CODESHELL_PLUGIN_ROOT}
|
|
23
|
+
* (varRewrite.ts rewrites CC's CLAUDE_PLUGIN_ROOT
|
|
24
|
+
* to this name at install time).
|
|
25
|
+
* CODESHELL_HOOK_EVENT — the codeshell-side event name (snake_case)
|
|
26
|
+
*
|
|
27
|
+
* We deliberately do NOT set CLAUDE_PLUGIN_ROOT here. Plugin scripts that
|
|
28
|
+
* branch on which host they detect (e.g. superpowers' session-start checks
|
|
29
|
+
* `[ -n "${CLAUDE_PLUGIN_ROOT:-}" ]`) get rewritten by varRewrite.ts at
|
|
30
|
+
* install time, so the branch they take after rewrite is the codeshell
|
|
31
|
+
* branch — not the CC one.
|
|
32
|
+
*/
|
|
33
|
+
import type { HookContext, HookResult } from "../hooks/events.js";
|
|
34
|
+
export interface PluginCommandHookSpec {
|
|
35
|
+
/** Shell command line, with ${CODESHELL_PLUGIN_ROOT} placeholder allowed. */
|
|
36
|
+
command: string;
|
|
37
|
+
/** Plugin install path; exported as CODESHELL_PLUGIN_ROOT for the child. */
|
|
38
|
+
installPath: string;
|
|
39
|
+
/** Plugin install key (`name@marketplace`), used for log lines. */
|
|
40
|
+
pluginKey: string;
|
|
41
|
+
/** Per-hook override; falls back to DEFAULT_TIMEOUT_MS. */
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Run one plugin hook command. Returns an empty HookResult on any failure
|
|
46
|
+
* (spawn error, timeout, non-zero exit, unparseable stdout) so the hook
|
|
47
|
+
* chain keeps moving — a misbehaving plugin must not wedge the engine.
|
|
48
|
+
*
|
|
49
|
+
* Stdin carries the same envelope shape the codeshell-native shell-runner
|
|
50
|
+
* uses (eventName + data) so plugin authors who want richer context can
|
|
51
|
+
* read it; CC plugins typically ignore stdin and emit context derived from
|
|
52
|
+
* their own state (e.g. reading a SKILL.md off disk via PLUGIN_ROOT).
|
|
53
|
+
*/
|
|
54
|
+
export declare function runPluginCommandHook(spec: PluginCommandHookSpec, ctx: HookContext): Promise<HookResult>;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pluginCommandHook — execute a plugin's command-type hook as a child
|
|
3
|
+
* process and translate its stdout into a HookResult.
|
|
4
|
+
*
|
|
5
|
+
* This is the plugin-side analogue of `src/hooks/shell-runner.ts`. The two
|
|
6
|
+
* runners are intentionally separate because they speak different protocols:
|
|
7
|
+
*
|
|
8
|
+
* src/hooks/shell-runner.ts codeshell-native: stdout is a HookResult
|
|
9
|
+
* JSON envelope ({ messages, decision, ... }).
|
|
10
|
+
* Used by user-authored settings.hooks.
|
|
11
|
+
*
|
|
12
|
+
* this file CC plugin protocol: stdout is one of
|
|
13
|
+
* - { hookSpecificOutput: { hookEventName, additionalContext } }
|
|
14
|
+
* - { additional_context: "..." } (Cursor)
|
|
15
|
+
* - { additionalContext: "..." } (SDK)
|
|
16
|
+
* We normalize all three into HookResult.messages
|
|
17
|
+
* so downstream hook plumbing (inject.ts) is
|
|
18
|
+
* untouched.
|
|
19
|
+
*
|
|
20
|
+
* env contract:
|
|
21
|
+
* CODESHELL_PLUGIN_ROOT — set to installPath. Plugin command strings
|
|
22
|
+
* reference this via ${CODESHELL_PLUGIN_ROOT}
|
|
23
|
+
* (varRewrite.ts rewrites CC's CLAUDE_PLUGIN_ROOT
|
|
24
|
+
* to this name at install time).
|
|
25
|
+
* CODESHELL_HOOK_EVENT — the codeshell-side event name (snake_case)
|
|
26
|
+
*
|
|
27
|
+
* We deliberately do NOT set CLAUDE_PLUGIN_ROOT here. Plugin scripts that
|
|
28
|
+
* branch on which host they detect (e.g. superpowers' session-start checks
|
|
29
|
+
* `[ -n "${CLAUDE_PLUGIN_ROOT:-}" ]`) get rewritten by varRewrite.ts at
|
|
30
|
+
* install time, so the branch they take after rewrite is the codeshell
|
|
31
|
+
* branch — not the CC one.
|
|
32
|
+
*/
|
|
33
|
+
import { spawn } from "node:child_process";
|
|
34
|
+
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
35
|
+
/**
|
|
36
|
+
* Extract the user-facing context string from a CC plugin's stdout JSON.
|
|
37
|
+
* Returns null if the payload doesn't carry context (which is valid — the
|
|
38
|
+
* hook may be doing side effects only).
|
|
39
|
+
*/
|
|
40
|
+
function extractAdditionalContext(parsed) {
|
|
41
|
+
if (!parsed || typeof parsed !== "object")
|
|
42
|
+
return null;
|
|
43
|
+
const obj = parsed;
|
|
44
|
+
// Claude Code nested shape: { hookSpecificOutput: { additionalContext } }
|
|
45
|
+
const hso = obj.hookSpecificOutput;
|
|
46
|
+
if (hso && typeof hso === "object") {
|
|
47
|
+
const ctx = hso.additionalContext;
|
|
48
|
+
if (typeof ctx === "string" && ctx.length > 0)
|
|
49
|
+
return ctx;
|
|
50
|
+
}
|
|
51
|
+
// Cursor snake_case (top-level)
|
|
52
|
+
if (typeof obj.additional_context === "string" && obj.additional_context.length > 0) {
|
|
53
|
+
return obj.additional_context;
|
|
54
|
+
}
|
|
55
|
+
// SDK standard (top-level)
|
|
56
|
+
if (typeof obj.additionalContext === "string" && obj.additionalContext.length > 0) {
|
|
57
|
+
return obj.additionalContext;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Run one plugin hook command. Returns an empty HookResult on any failure
|
|
63
|
+
* (spawn error, timeout, non-zero exit, unparseable stdout) so the hook
|
|
64
|
+
* chain keeps moving — a misbehaving plugin must not wedge the engine.
|
|
65
|
+
*
|
|
66
|
+
* Stdin carries the same envelope shape the codeshell-native shell-runner
|
|
67
|
+
* uses (eventName + data) so plugin authors who want richer context can
|
|
68
|
+
* read it; CC plugins typically ignore stdin and emit context derived from
|
|
69
|
+
* their own state (e.g. reading a SKILL.md off disk via PLUGIN_ROOT).
|
|
70
|
+
*/
|
|
71
|
+
export async function runPluginCommandHook(spec, ctx) {
|
|
72
|
+
const timeoutMs = spec.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
let child;
|
|
75
|
+
try {
|
|
76
|
+
// Strip CLAUDE_PLUGIN_ROOT from the inherited env: a plugin script
|
|
77
|
+
// that branches on `[ -n "$CLAUDE_PLUGIN_ROOT" ]` must conclude
|
|
78
|
+
// "not Claude Code" and pick the codeshell branch. varRewrite.ts
|
|
79
|
+
// converted the literal `${CLAUDE_PLUGIN_ROOT}` references to the
|
|
80
|
+
// codeshell name; this drop closes the runtime side of the same
|
|
81
|
+
// story.
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
+
const { CLAUDE_PLUGIN_ROOT: _stripped, ...parentEnv } = process.env;
|
|
84
|
+
child = spawn(spec.command, [], {
|
|
85
|
+
shell: true,
|
|
86
|
+
env: {
|
|
87
|
+
...parentEnv,
|
|
88
|
+
CODESHELL_PLUGIN_ROOT: spec.installPath,
|
|
89
|
+
CODESHELL_HOOK_EVENT: ctx.eventName,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.error(`[plugin-hook] spawn failed for ${spec.pluginKey} command "${spec.command}":`, err.message);
|
|
96
|
+
resolve({});
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
let stdout = "";
|
|
100
|
+
let stderr = "";
|
|
101
|
+
let settled = false;
|
|
102
|
+
const settle = (value) => {
|
|
103
|
+
if (settled)
|
|
104
|
+
return;
|
|
105
|
+
settled = true;
|
|
106
|
+
resolve(value);
|
|
107
|
+
};
|
|
108
|
+
const timer = setTimeout(() => {
|
|
109
|
+
// eslint-disable-next-line no-console
|
|
110
|
+
console.warn(`[plugin-hook] ${spec.pluginKey} ${ctx.eventName} timed out after ${timeoutMs}ms`);
|
|
111
|
+
try {
|
|
112
|
+
child.kill("SIGTERM");
|
|
113
|
+
setTimeout(() => {
|
|
114
|
+
try {
|
|
115
|
+
child.kill("SIGKILL");
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
/* already exited */
|
|
119
|
+
}
|
|
120
|
+
}, 1000);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
/* already exited */
|
|
124
|
+
}
|
|
125
|
+
settle({});
|
|
126
|
+
}, timeoutMs);
|
|
127
|
+
child.stdout?.on("data", (chunk) => {
|
|
128
|
+
stdout += chunk.toString("utf8");
|
|
129
|
+
});
|
|
130
|
+
child.stderr?.on("data", (chunk) => {
|
|
131
|
+
stderr += chunk.toString("utf8");
|
|
132
|
+
});
|
|
133
|
+
child.on("error", (err) => {
|
|
134
|
+
clearTimeout(timer);
|
|
135
|
+
// eslint-disable-next-line no-console
|
|
136
|
+
console.error(`[plugin-hook] ${spec.pluginKey} ${ctx.eventName} spawn error:`, err.message);
|
|
137
|
+
settle({});
|
|
138
|
+
});
|
|
139
|
+
child.on("close", (code) => {
|
|
140
|
+
clearTimeout(timer);
|
|
141
|
+
if (code !== 0) {
|
|
142
|
+
// eslint-disable-next-line no-console
|
|
143
|
+
console.warn(`[plugin-hook] ${spec.pluginKey} ${ctx.eventName} exited ${code}; stderr:`, stderr.slice(0, 500));
|
|
144
|
+
settle({});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const trimmed = stdout.trim();
|
|
148
|
+
if (trimmed.length === 0) {
|
|
149
|
+
settle({});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
let parsed;
|
|
153
|
+
try {
|
|
154
|
+
parsed = JSON.parse(trimmed);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
// eslint-disable-next-line no-console
|
|
158
|
+
console.warn(`[plugin-hook] ${spec.pluginKey} ${ctx.eventName} returned non-JSON stdout, ignoring:`, err.message, "\nfirst 200 chars:", trimmed.slice(0, 200));
|
|
159
|
+
settle({});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const additional = extractAdditionalContext(parsed);
|
|
163
|
+
if (additional === null) {
|
|
164
|
+
settle({});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
settle({ messages: [additional] });
|
|
168
|
+
});
|
|
169
|
+
// Stdin envelope: matches the shape codeshell-native shell hooks use.
|
|
170
|
+
// CC plugins generally don't read stdin, but writing it is cheap and
|
|
171
|
+
// keeps the protocol open for plugin authors who want it.
|
|
172
|
+
try {
|
|
173
|
+
child.stdin?.write(JSON.stringify({ eventName: ctx.eventName, data: ctx.data }));
|
|
174
|
+
child.stdin?.end();
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
// Child may have closed stdin already; not fatal.
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover plugin-provided slash commands. For each installed plugin,
|
|
3
|
+
* walks <installPath>/commands/*.md and returns one PluginCommand per
|
|
4
|
+
* markdown file. Mirrors Claude Code's loadPluginCommands.ts at the
|
|
5
|
+
* MVP subset (single-level commands directory, no nested subcommands,
|
|
6
|
+
* no inline-via-plugin.json commands).
|
|
7
|
+
*/
|
|
8
|
+
export interface PluginCommand {
|
|
9
|
+
/** Namespaced name, e.g. "superpowers:brainstorming" */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Plain command (without plugin prefix), e.g. "brainstorming" */
|
|
12
|
+
commandName: string;
|
|
13
|
+
/** Plugin id (without @marketplace), e.g. "superpowers" */
|
|
14
|
+
pluginName: string;
|
|
15
|
+
/** Frontmatter description, coerced. May be empty. */
|
|
16
|
+
description: string;
|
|
17
|
+
/** Frontmatter "argument-hint" if present. */
|
|
18
|
+
argumentHint?: string;
|
|
19
|
+
/** Body of the .md (frontmatter stripped). */
|
|
20
|
+
body: string;
|
|
21
|
+
/** Absolute path to the .md file. */
|
|
22
|
+
filePath: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function scanPluginCommands(): PluginCommand[];
|
|
25
|
+
export declare function invalidatePluginCommandsCache(): void;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover plugin-provided slash commands. For each installed plugin,
|
|
3
|
+
* walks <installPath>/commands/*.md and returns one PluginCommand per
|
|
4
|
+
* markdown file. Mirrors Claude Code's loadPluginCommands.ts at the
|
|
5
|
+
* MVP subset (single-level commands directory, no nested subcommands,
|
|
6
|
+
* no inline-via-plugin.json commands).
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { memoize } from "../utils/memoize.js";
|
|
12
|
+
import { parseFrontmatter, coerceDescription } from "../skills/frontmatter.js";
|
|
13
|
+
import { installedPluginsPath, readInstalledPlugins } from "./installedPlugins.js";
|
|
14
|
+
function isENOENT(e) {
|
|
15
|
+
return (typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT");
|
|
16
|
+
}
|
|
17
|
+
function isInaccessible(e) {
|
|
18
|
+
if (typeof e !== "object" || e === null || !("code" in e))
|
|
19
|
+
return false;
|
|
20
|
+
const code = e.code;
|
|
21
|
+
return code === "EACCES" || code === "EPERM" || code === "EIO";
|
|
22
|
+
}
|
|
23
|
+
function userHome() {
|
|
24
|
+
return process.env.HOME ?? homedir();
|
|
25
|
+
}
|
|
26
|
+
function readCommandFile(filePath) {
|
|
27
|
+
try {
|
|
28
|
+
return readFileSync(filePath, "utf-8");
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (isENOENT(e))
|
|
32
|
+
return null;
|
|
33
|
+
if (isInaccessible(e)) {
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
console.warn(`[plugin-commands] cannot read ${filePath}: ${e.message}`);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function scanOnce() {
|
|
42
|
+
const data = readInstalledPlugins();
|
|
43
|
+
const out = [];
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
const keys = Object.keys(data.plugins).sort();
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
const entries = data.plugins[key] ?? [];
|
|
48
|
+
const atIdx = key.lastIndexOf("@");
|
|
49
|
+
const pluginName = atIdx > 0 ? key.slice(0, atIdx) : key;
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
const commandsDir = join(entry.installPath, "commands");
|
|
52
|
+
if (!existsSync(commandsDir))
|
|
53
|
+
continue;
|
|
54
|
+
let dirEntries;
|
|
55
|
+
try {
|
|
56
|
+
dirEntries = readdirSync(commandsDir, { withFileTypes: true });
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (isInaccessible(e)) {
|
|
60
|
+
// eslint-disable-next-line no-console
|
|
61
|
+
console.warn(`[plugin-commands] cannot read ${commandsDir}: ${e.message}`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
for (const dirent of dirEntries) {
|
|
67
|
+
if (!dirent.isFile() && !dirent.isSymbolicLink())
|
|
68
|
+
continue;
|
|
69
|
+
if (!dirent.name.endsWith(".md"))
|
|
70
|
+
continue;
|
|
71
|
+
const filePath = join(commandsDir, dirent.name);
|
|
72
|
+
const raw = readCommandFile(filePath);
|
|
73
|
+
if (raw === null)
|
|
74
|
+
continue;
|
|
75
|
+
const baseName = dirent.name.slice(0, -3); // drop .md
|
|
76
|
+
const namespaced = `${pluginName}:${baseName}`;
|
|
77
|
+
if (seen.has(namespaced))
|
|
78
|
+
continue;
|
|
79
|
+
const { frontmatter, body } = parseFrontmatter(raw);
|
|
80
|
+
const description = coerceDescription(frontmatter.description);
|
|
81
|
+
const argumentHint = typeof frontmatter["argument-hint"] === "string"
|
|
82
|
+
? frontmatter["argument-hint"]
|
|
83
|
+
: undefined;
|
|
84
|
+
out.push({
|
|
85
|
+
name: namespaced,
|
|
86
|
+
commandName: baseName,
|
|
87
|
+
pluginName,
|
|
88
|
+
description,
|
|
89
|
+
argumentHint,
|
|
90
|
+
body,
|
|
91
|
+
filePath,
|
|
92
|
+
});
|
|
93
|
+
seen.add(namespaced);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
function installedPluginsMtime() {
|
|
100
|
+
const p = installedPluginsPath();
|
|
101
|
+
try {
|
|
102
|
+
return statSync(p).mtimeMs.toString();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return "0";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const memoized = memoize(scanOnce, () => `${userHome()}\0${installedPluginsMtime()}`);
|
|
109
|
+
export function scanPluginCommands() {
|
|
110
|
+
return memoized();
|
|
111
|
+
}
|
|
112
|
+
export function invalidatePluginCommandsCache() {
|
|
113
|
+
memoized.cache.clear?.();
|
|
114
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install / uninstall plugins from a known marketplace. Mirrors Claude
|
|
3
|
+
* Code's installResolvedPlugin pattern at the MVP subset: four entry
|
|
4
|
+
* source types (path / git / github / git-subdir), no dependencies, no
|
|
5
|
+
* sparse-checkout, no npm/pip.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginInstallEntry } from "./types.js";
|
|
8
|
+
export interface VarRewriteReport {
|
|
9
|
+
filesScanned: number;
|
|
10
|
+
filesRewritten: number;
|
|
11
|
+
}
|
|
12
|
+
export type InstallResult = {
|
|
13
|
+
ok: true;
|
|
14
|
+
entry: PluginInstallEntry;
|
|
15
|
+
freshlyCloned: boolean;
|
|
16
|
+
varRewrite: VarRewriteReport;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Install a plugin from a previously-added marketplace into the user
|
|
23
|
+
* cache. Idempotent within a process: re-installing replaces the
|
|
24
|
+
* cached files and updates the manifest entry.
|
|
25
|
+
*/
|
|
26
|
+
export declare function installPlugin(pluginName: string, marketplaceName: string): Promise<InstallResult>;
|
|
27
|
+
export interface UninstallResult {
|
|
28
|
+
ok: boolean;
|
|
29
|
+
removedFromManifest: boolean;
|
|
30
|
+
removedFromDisk: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function uninstallPlugin(pluginName: string, marketplaceName: string): UninstallResult;
|
|
33
|
+
export declare function listInstalled(): {
|
|
34
|
+
key: string;
|
|
35
|
+
entry: PluginInstallEntry;
|
|
36
|
+
}[];
|