@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,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal `git` subprocess wrappers used by the plugin marketplace. Each
|
|
3
|
+
* function returns a discriminated union so callers can produce useful
|
|
4
|
+
* error messages without try/catching. Mirrors Claude Code's
|
|
5
|
+
* utils/plugins/marketplaceManager.ts:loadAndCacheMarketplace at the
|
|
6
|
+
* subset we need for the MVP.
|
|
7
|
+
*
|
|
8
|
+
* Subprocess lifecycle (spawn, timeout cascade, IO drain, byte cap) is
|
|
9
|
+
* centralized in {@link safeSpawn}; gitOps only owns the error-shape
|
|
10
|
+
* mapping into GitResult.
|
|
11
|
+
*
|
|
12
|
+
* Trust: gitOps is invoked from marketplace install/update actions that the
|
|
13
|
+
* user initiates by typing `/plugin install ...` (or the equivalent). It is
|
|
14
|
+
* NOT exposed to the LLM via tool calls, so it does not need permission
|
|
15
|
+
* classification. See docs/architecture/17 for the trust framing.
|
|
16
|
+
*/
|
|
17
|
+
import { safeSpawn } from "../runtime/safe-spawn.js";
|
|
18
|
+
async function runGit(args, cwd, timeoutMs = 60_000) {
|
|
19
|
+
const r = await safeSpawn("git", args, {
|
|
20
|
+
cwd: cwd ?? process.cwd(),
|
|
21
|
+
env: process.env,
|
|
22
|
+
timeoutMs,
|
|
23
|
+
});
|
|
24
|
+
if (r.spawnFailed) {
|
|
25
|
+
return { ok: false, error: `git ${args.join(" ")} failed: ${r.error ?? "spawn failed"}` };
|
|
26
|
+
}
|
|
27
|
+
if (r.timedOut) {
|
|
28
|
+
return { ok: false, error: `git ${args.join(" ")} timed out after ${timeoutMs}ms` };
|
|
29
|
+
}
|
|
30
|
+
if (r.exitCode === 0) {
|
|
31
|
+
return { ok: true, stdout: r.stdout.trim() };
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
ok: false,
|
|
35
|
+
error: `git ${args.join(" ")} exited ${r.exitCode}: ${r.stderr.trim() || "unknown error"}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export async function gitClone(url, destDir, options) {
|
|
39
|
+
const args = ["clone", "--depth", "1"];
|
|
40
|
+
if (options?.ref)
|
|
41
|
+
args.push("--branch", options.ref);
|
|
42
|
+
args.push("--", url, destDir);
|
|
43
|
+
return runGit(args);
|
|
44
|
+
}
|
|
45
|
+
export async function gitRevParseHead(repoDir) {
|
|
46
|
+
return runGit(["rev-parse", "HEAD"], repoDir);
|
|
47
|
+
}
|
|
48
|
+
export async function gitFetchAndReset(repoDir, ref) {
|
|
49
|
+
const fetchArgs = ["fetch", "--depth", "1", "origin"];
|
|
50
|
+
if (ref)
|
|
51
|
+
fetchArgs.push(ref);
|
|
52
|
+
const fetch = await runGit(fetchArgs, repoDir);
|
|
53
|
+
if (!fetch.ok)
|
|
54
|
+
return fetch;
|
|
55
|
+
return runGit(["reset", "--hard", ref ? `origin/${ref}` : "FETCH_HEAD"], repoDir);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Github source helper: convert "owner/repo" to an https clone URL.
|
|
59
|
+
*/
|
|
60
|
+
export function githubRepoToCloneUrl(repo) {
|
|
61
|
+
return `https://github.com/${repo}.git`;
|
|
62
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read/write ~/.code-shell/plugins/installed_plugins.json (V2 format).
|
|
3
|
+
* Byte-compatible with Claude Code's analogous file.
|
|
4
|
+
*/
|
|
5
|
+
import type { InstalledPluginsV2, PluginInstallEntry } from "./types.js";
|
|
6
|
+
export declare function installedPluginsPath(): string;
|
|
7
|
+
export declare function readInstalledPlugins(): InstalledPluginsV2;
|
|
8
|
+
export declare function writeInstalledPlugins(data: InstalledPluginsV2): void;
|
|
9
|
+
/**
|
|
10
|
+
* Append an install entry for `<plugin>@<marketplace>`. Multiple entries
|
|
11
|
+
* for the same key are allowed (different scopes); MVP only writes scope:"user".
|
|
12
|
+
*/
|
|
13
|
+
export declare function appendInstallEntry(key: string, entry: PluginInstallEntry): void;
|
|
14
|
+
export declare function removeInstallEntries(key: string): boolean;
|
|
15
|
+
export declare function pluginInstallKey(plugin: string, marketplace: string): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read/write ~/.code-shell/plugins/installed_plugins.json (V2 format).
|
|
3
|
+
* Byte-compatible with Claude Code's analogous file.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
function userHome() {
|
|
9
|
+
return process.env.HOME ?? homedir();
|
|
10
|
+
}
|
|
11
|
+
export function installedPluginsPath() {
|
|
12
|
+
return join(userHome(), ".code-shell", "plugins", "installed_plugins.json");
|
|
13
|
+
}
|
|
14
|
+
const EMPTY = { version: 2, plugins: {} };
|
|
15
|
+
export function readInstalledPlugins() {
|
|
16
|
+
const path = installedPluginsPath();
|
|
17
|
+
if (!existsSync(path))
|
|
18
|
+
return { version: 2, plugins: {} };
|
|
19
|
+
try {
|
|
20
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
21
|
+
if (raw && typeof raw === "object" && raw.version === 2 && raw.plugins && typeof raw.plugins === "object") {
|
|
22
|
+
return raw;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Corrupt — treat as empty so the user can re-install.
|
|
27
|
+
}
|
|
28
|
+
return { version: 2, plugins: {} };
|
|
29
|
+
}
|
|
30
|
+
export function writeInstalledPlugins(data) {
|
|
31
|
+
const path = installedPluginsPath();
|
|
32
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
33
|
+
writeFileSync(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Append an install entry for `<plugin>@<marketplace>`. Multiple entries
|
|
37
|
+
* for the same key are allowed (different scopes); MVP only writes scope:"user".
|
|
38
|
+
*/
|
|
39
|
+
export function appendInstallEntry(key, entry) {
|
|
40
|
+
const data = readInstalledPlugins();
|
|
41
|
+
const list = data.plugins[key] ?? [];
|
|
42
|
+
list.push(entry);
|
|
43
|
+
data.plugins[key] = list;
|
|
44
|
+
writeInstalledPlugins(data);
|
|
45
|
+
}
|
|
46
|
+
export function removeInstallEntries(key) {
|
|
47
|
+
const data = readInstalledPlugins();
|
|
48
|
+
if (!(key in data.plugins))
|
|
49
|
+
return false;
|
|
50
|
+
delete data.plugins[key];
|
|
51
|
+
writeInstalledPlugins(data);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
export function pluginInstallKey(plugin, marketplace) {
|
|
55
|
+
return `${plugin}@${marketplace}`;
|
|
56
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read/write ~/.code-shell/plugins/known_marketplaces.json.
|
|
3
|
+
* File format is byte-compatible with Claude Code's analogous file.
|
|
4
|
+
*/
|
|
5
|
+
import type { KnownMarketplaces, KnownMarketplace } from "./types.js";
|
|
6
|
+
export declare function knownMarketplacesPath(): string;
|
|
7
|
+
export declare function readKnownMarketplaces(): KnownMarketplaces;
|
|
8
|
+
export declare function writeKnownMarketplaces(data: KnownMarketplaces): void;
|
|
9
|
+
export declare function upsertKnownMarketplace(name: string, entry: KnownMarketplace): void;
|
|
10
|
+
export declare function removeKnownMarketplace(name: string): boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read/write ~/.code-shell/plugins/known_marketplaces.json.
|
|
3
|
+
* File format is byte-compatible with Claude Code's analogous file.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
function userHome() {
|
|
9
|
+
return process.env.HOME ?? homedir();
|
|
10
|
+
}
|
|
11
|
+
export function knownMarketplacesPath() {
|
|
12
|
+
return join(userHome(), ".code-shell", "plugins", "known_marketplaces.json");
|
|
13
|
+
}
|
|
14
|
+
export function readKnownMarketplaces() {
|
|
15
|
+
const path = knownMarketplacesPath();
|
|
16
|
+
if (!existsSync(path))
|
|
17
|
+
return {};
|
|
18
|
+
try {
|
|
19
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
20
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
21
|
+
return raw;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Corrupted file: treat as empty so the caller can recover by re-adding.
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
export function writeKnownMarketplaces(data) {
|
|
30
|
+
const path = knownMarketplacesPath();
|
|
31
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
32
|
+
writeFileSync(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
33
|
+
}
|
|
34
|
+
export function upsertKnownMarketplace(name, entry) {
|
|
35
|
+
const data = readKnownMarketplaces();
|
|
36
|
+
data[name] = entry;
|
|
37
|
+
writeKnownMarketplaces(data);
|
|
38
|
+
}
|
|
39
|
+
export function removeKnownMarketplace(name) {
|
|
40
|
+
const data = readKnownMarketplaces();
|
|
41
|
+
if (!(name in data))
|
|
42
|
+
return false;
|
|
43
|
+
delete data[name];
|
|
44
|
+
writeKnownMarketplaces(data);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loadPluginHooks — scan every installed plugin's hooks/hooks.json and
|
|
3
|
+
* register the command-type hooks with the engine's HookRegistry.
|
|
4
|
+
*
|
|
5
|
+
* Plugin hooks.json schema (Claude Code-compatible):
|
|
6
|
+
*
|
|
7
|
+
* {
|
|
8
|
+
* "hooks": {
|
|
9
|
+
* "<EventName>": [
|
|
10
|
+
* {
|
|
11
|
+
* "matcher": "<regex>", // optional; semantics depend on event
|
|
12
|
+
* "hooks": [
|
|
13
|
+
* {
|
|
14
|
+
* "type": "command",
|
|
15
|
+
* "command": "...", // ${CODESHELL_PLUGIN_ROOT} placeholder
|
|
16
|
+
* "async": false, // currently ignored (always sync await)
|
|
17
|
+
* "timeout_ms": 60000 // optional override
|
|
18
|
+
* }
|
|
19
|
+
* ]
|
|
20
|
+
* }
|
|
21
|
+
* ]
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* Event-name mapping (CC PascalCase → codeshell snake_case):
|
|
26
|
+
* SessionStart → on_session_start
|
|
27
|
+
* UserPromptSubmit → user_prompt_submit
|
|
28
|
+
* PreToolUse → pre_tool_use
|
|
29
|
+
* PostToolUse → post_tool_use
|
|
30
|
+
* PreCompact → pre_compact
|
|
31
|
+
* Notification → notification
|
|
32
|
+
* Stop → on_session_end
|
|
33
|
+
* SubagentStop → (skipped — codeshell sub-agents don't surface this event)
|
|
34
|
+
*
|
|
35
|
+
* matcher semantics:
|
|
36
|
+
* SessionStart — matches against ctx.data.source ("startup"|"resume"|"clear"|"compact")
|
|
37
|
+
* PreToolUse /
|
|
38
|
+
* PostToolUse — matches against ctx.data.toolName
|
|
39
|
+
* other events — matcher is currently ignored (the CC spec doesn't
|
|
40
|
+
* define matcher semantics for them either)
|
|
41
|
+
*
|
|
42
|
+
* Errors are swallowed per-plugin: a malformed hooks.json from one plugin
|
|
43
|
+
* must not block other plugins from loading.
|
|
44
|
+
*/
|
|
45
|
+
import type { HookRegistry } from "../hooks/registry.js";
|
|
46
|
+
/**
|
|
47
|
+
* Walk installed plugins and register their command hooks. Safe to call
|
|
48
|
+
* multiple times — the caller is responsible for not double-registering
|
|
49
|
+
* (HookRegistry has no de-dup; the engine constructor calls this exactly
|
|
50
|
+
* once after creating the registry).
|
|
51
|
+
*/
|
|
52
|
+
export declare function loadPluginHooks(registry: HookRegistry): void;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loadPluginHooks — scan every installed plugin's hooks/hooks.json and
|
|
3
|
+
* register the command-type hooks with the engine's HookRegistry.
|
|
4
|
+
*
|
|
5
|
+
* Plugin hooks.json schema (Claude Code-compatible):
|
|
6
|
+
*
|
|
7
|
+
* {
|
|
8
|
+
* "hooks": {
|
|
9
|
+
* "<EventName>": [
|
|
10
|
+
* {
|
|
11
|
+
* "matcher": "<regex>", // optional; semantics depend on event
|
|
12
|
+
* "hooks": [
|
|
13
|
+
* {
|
|
14
|
+
* "type": "command",
|
|
15
|
+
* "command": "...", // ${CODESHELL_PLUGIN_ROOT} placeholder
|
|
16
|
+
* "async": false, // currently ignored (always sync await)
|
|
17
|
+
* "timeout_ms": 60000 // optional override
|
|
18
|
+
* }
|
|
19
|
+
* ]
|
|
20
|
+
* }
|
|
21
|
+
* ]
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* Event-name mapping (CC PascalCase → codeshell snake_case):
|
|
26
|
+
* SessionStart → on_session_start
|
|
27
|
+
* UserPromptSubmit → user_prompt_submit
|
|
28
|
+
* PreToolUse → pre_tool_use
|
|
29
|
+
* PostToolUse → post_tool_use
|
|
30
|
+
* PreCompact → pre_compact
|
|
31
|
+
* Notification → notification
|
|
32
|
+
* Stop → on_session_end
|
|
33
|
+
* SubagentStop → (skipped — codeshell sub-agents don't surface this event)
|
|
34
|
+
*
|
|
35
|
+
* matcher semantics:
|
|
36
|
+
* SessionStart — matches against ctx.data.source ("startup"|"resume"|"clear"|"compact")
|
|
37
|
+
* PreToolUse /
|
|
38
|
+
* PostToolUse — matches against ctx.data.toolName
|
|
39
|
+
* other events — matcher is currently ignored (the CC spec doesn't
|
|
40
|
+
* define matcher semantics for them either)
|
|
41
|
+
*
|
|
42
|
+
* Errors are swallowed per-plugin: a malformed hooks.json from one plugin
|
|
43
|
+
* must not block other plugins from loading.
|
|
44
|
+
*/
|
|
45
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
46
|
+
import { join } from "node:path";
|
|
47
|
+
import { readInstalledPlugins } from "./installedPlugins.js";
|
|
48
|
+
import { runPluginCommandHook } from "./pluginCommandHook.js";
|
|
49
|
+
/** Priority for plugin hooks — between built-in (100) and settings (50). */
|
|
50
|
+
const PLUGIN_HOOK_PRIORITY = 80;
|
|
51
|
+
const EVENT_NAME_MAP = {
|
|
52
|
+
SessionStart: "on_session_start",
|
|
53
|
+
UserPromptSubmit: "user_prompt_submit",
|
|
54
|
+
PreToolUse: "pre_tool_use",
|
|
55
|
+
PostToolUse: "post_tool_use",
|
|
56
|
+
PreCompact: "pre_compact",
|
|
57
|
+
Notification: "notification",
|
|
58
|
+
Stop: "on_session_end",
|
|
59
|
+
SubagentStop: null,
|
|
60
|
+
};
|
|
61
|
+
function readHooksJson(installPath) {
|
|
62
|
+
const path = join(installPath, "hooks", "hooks.json");
|
|
63
|
+
if (!existsSync(path))
|
|
64
|
+
return null;
|
|
65
|
+
try {
|
|
66
|
+
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
67
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
68
|
+
return raw;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
// eslint-disable-next-line no-console
|
|
73
|
+
console.warn(`[plugin-hooks] failed to parse ${path}:`, err.message);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Per-event matcher logic. Returns true when the hook should fire.
|
|
79
|
+
*
|
|
80
|
+
* We only consult the matcher for events where CC defines its semantics;
|
|
81
|
+
* for others we always fire (matcher is treated as advisory metadata only).
|
|
82
|
+
*/
|
|
83
|
+
function matcherAccepts(event, matcher, ctx) {
|
|
84
|
+
if (!matcher)
|
|
85
|
+
return true;
|
|
86
|
+
let re;
|
|
87
|
+
try {
|
|
88
|
+
re = new RegExp(matcher);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Bad regex — be permissive (matches CC's "log + drop" behavior).
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
if (event === "on_session_start") {
|
|
95
|
+
const source = ctx.data.source;
|
|
96
|
+
if (typeof source !== "string")
|
|
97
|
+
return true;
|
|
98
|
+
return re.test(source);
|
|
99
|
+
}
|
|
100
|
+
if (event === "pre_tool_use" || event === "post_tool_use") {
|
|
101
|
+
const toolName = ctx.data.toolName;
|
|
102
|
+
if (typeof toolName !== "string")
|
|
103
|
+
return false;
|
|
104
|
+
return re.test(toolName);
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
function pluginNameFromKey(key) {
|
|
109
|
+
const at = key.lastIndexOf("@");
|
|
110
|
+
return at > 0 ? key.slice(0, at) : key;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Walk installed plugins and register their command hooks. Safe to call
|
|
114
|
+
* multiple times — the caller is responsible for not double-registering
|
|
115
|
+
* (HookRegistry has no de-dup; the engine constructor calls this exactly
|
|
116
|
+
* once after creating the registry).
|
|
117
|
+
*/
|
|
118
|
+
export function loadPluginHooks(registry) {
|
|
119
|
+
const data = readInstalledPlugins();
|
|
120
|
+
for (const [key, entries] of Object.entries(data.plugins)) {
|
|
121
|
+
for (const entry of entries) {
|
|
122
|
+
const installPath = entry.installPath;
|
|
123
|
+
if (!installPath || !existsSync(installPath))
|
|
124
|
+
continue;
|
|
125
|
+
const raw = readHooksJson(installPath);
|
|
126
|
+
if (!raw?.hooks)
|
|
127
|
+
continue;
|
|
128
|
+
for (const [eventNameRaw, groups] of Object.entries(raw.hooks)) {
|
|
129
|
+
const mapped = EVENT_NAME_MAP[eventNameRaw];
|
|
130
|
+
if (mapped === null || mapped === undefined) {
|
|
131
|
+
// Unmapped event name (e.g. SubagentStop) — silently skip; logging
|
|
132
|
+
// every unknown event for every plugin would be noisy.
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!Array.isArray(groups))
|
|
136
|
+
continue;
|
|
137
|
+
for (const group of groups) {
|
|
138
|
+
const commands = group.hooks ?? [];
|
|
139
|
+
for (const cmd of commands) {
|
|
140
|
+
if (cmd.type !== "command" || typeof cmd.command !== "string") {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const commandLine = cmd.command;
|
|
144
|
+
const timeoutMs = cmd.timeout_ms;
|
|
145
|
+
const matcher = group.matcher;
|
|
146
|
+
const handler = async (ctx) => {
|
|
147
|
+
if (!matcherAccepts(mapped, matcher, ctx))
|
|
148
|
+
return {};
|
|
149
|
+
return runPluginCommandHook({
|
|
150
|
+
command: commandLine,
|
|
151
|
+
installPath,
|
|
152
|
+
pluginKey: key,
|
|
153
|
+
timeoutMs,
|
|
154
|
+
}, ctx);
|
|
155
|
+
};
|
|
156
|
+
registry.register(mapped, handler, PLUGIN_HOOK_PRIORITY, `plugin:${pluginNameFromKey(key)}:${eventNameRaw}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marketplace lifecycle: add (clone + validate + persist), remove
|
|
3
|
+
* (delete from disk + manifest), list, load (read marketplace.json on
|
|
4
|
+
* demand). Mirrors Claude Code's utils/plugins/marketplaceManager.ts
|
|
5
|
+
* at the MVP subset (github + git sources only, no auto-update,
|
|
6
|
+
* no policy blocking, no GCS mirror).
|
|
7
|
+
*/
|
|
8
|
+
import type { MarketplaceSource, PluginMarketplace } from "./types.js";
|
|
9
|
+
export declare function marketplacesRoot(): string;
|
|
10
|
+
export declare function marketplaceDir(name: string): string;
|
|
11
|
+
export type AddMarketplaceResult = {
|
|
12
|
+
ok: true;
|
|
13
|
+
name: string;
|
|
14
|
+
marketplace: PluginMarketplace;
|
|
15
|
+
replaced: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
error: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Adds a marketplace by cloning it (or refreshing if already present
|
|
22
|
+
* with the same source), validating its marketplace.json, and writing
|
|
23
|
+
* an entry into known_marketplaces.json.
|
|
24
|
+
*/
|
|
25
|
+
export declare function addMarketplace(name: string, source: MarketplaceSource): Promise<AddMarketplaceResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Removes a marketplace: deletes the cached clone and the manifest entry.
|
|
28
|
+
* Returns whether anything was actually removed.
|
|
29
|
+
*/
|
|
30
|
+
export declare function removeMarketplace(name: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Loads a previously-added marketplace's manifest from disk. Returns null
|
|
33
|
+
* if the marketplace is unknown or the manifest is gone (caller can
|
|
34
|
+
* report to user).
|
|
35
|
+
*/
|
|
36
|
+
export declare function loadMarketplace(name: string): PluginMarketplace | null;
|
|
37
|
+
export interface ListedMarketplace {
|
|
38
|
+
name: string;
|
|
39
|
+
source: MarketplaceSource;
|
|
40
|
+
installLocation: string;
|
|
41
|
+
lastUpdated: string;
|
|
42
|
+
pluginCount: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Lists all known marketplaces with a quick plugin count read from each
|
|
46
|
+
* cached manifest. Marketplaces whose manifest is missing or invalid
|
|
47
|
+
* show pluginCount: -1 so the caller can flag them.
|
|
48
|
+
*/
|
|
49
|
+
export declare function listMarketplaces(): ListedMarketplace[];
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marketplace lifecycle: add (clone + validate + persist), remove
|
|
3
|
+
* (delete from disk + manifest), list, load (read marketplace.json on
|
|
4
|
+
* demand). Mirrors Claude Code's utils/plugins/marketplaceManager.ts
|
|
5
|
+
* at the MVP subset (github + git sources only, no auto-update,
|
|
6
|
+
* no policy blocking, no GCS mirror).
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync, rmSync, mkdirSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { gitClone, gitFetchAndReset, githubRepoToCloneUrl } from "./gitOps.js";
|
|
12
|
+
import { readKnownMarketplaces, upsertKnownMarketplace, removeKnownMarketplace, } from "./knownMarketplaces.js";
|
|
13
|
+
import { validateMarketplace } from "./schemas.js";
|
|
14
|
+
function userHome() {
|
|
15
|
+
return process.env.HOME ?? homedir();
|
|
16
|
+
}
|
|
17
|
+
export function marketplacesRoot() {
|
|
18
|
+
return join(userHome(), ".code-shell", "plugins", "marketplaces");
|
|
19
|
+
}
|
|
20
|
+
export function marketplaceDir(name) {
|
|
21
|
+
return join(marketplacesRoot(), name);
|
|
22
|
+
}
|
|
23
|
+
function marketplaceJsonPath(name) {
|
|
24
|
+
return join(marketplaceDir(name), ".claude-plugin", "marketplace.json");
|
|
25
|
+
}
|
|
26
|
+
function sourceToCloneUrl(source) {
|
|
27
|
+
return source.source === "github" ? githubRepoToCloneUrl(source.repo) : source.url;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Adds a marketplace by cloning it (or refreshing if already present
|
|
31
|
+
* with the same source), validating its marketplace.json, and writing
|
|
32
|
+
* an entry into known_marketplaces.json.
|
|
33
|
+
*/
|
|
34
|
+
export async function addMarketplace(name, source) {
|
|
35
|
+
const dir = marketplaceDir(name);
|
|
36
|
+
const known = readKnownMarketplaces();
|
|
37
|
+
const existing = known[name];
|
|
38
|
+
const sameSource = existing &&
|
|
39
|
+
JSON.stringify(existing.source) === JSON.stringify(source) &&
|
|
40
|
+
existsSync(dir);
|
|
41
|
+
if (sameSource) {
|
|
42
|
+
// Refresh: pull latest. Best-effort; if fetch fails we still try to
|
|
43
|
+
// validate the existing checkout.
|
|
44
|
+
const ref = source.source === "git" ? undefined : undefined; // MVP: default branch
|
|
45
|
+
await gitFetchAndReset(dir, ref);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Fresh clone (delete first if a stale directory exists).
|
|
49
|
+
if (existsSync(dir))
|
|
50
|
+
rmSync(dir, { recursive: true, force: true });
|
|
51
|
+
mkdirSync(marketplacesRoot(), { recursive: true });
|
|
52
|
+
const clone = await gitClone(sourceToCloneUrl(source), dir);
|
|
53
|
+
if (!clone.ok) {
|
|
54
|
+
return { ok: false, error: clone.error };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const manifestPath = marketplaceJsonPath(name);
|
|
58
|
+
if (!existsSync(manifestPath)) {
|
|
59
|
+
rmSync(dir, { recursive: true, force: true });
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
error: `Marketplace ${name}: .claude-plugin/marketplace.json not found in the cloned repository.`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
let raw;
|
|
66
|
+
try {
|
|
67
|
+
raw = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
rmSync(dir, { recursive: true, force: true });
|
|
71
|
+
return {
|
|
72
|
+
ok: false,
|
|
73
|
+
error: `Marketplace ${name}: failed to parse marketplace.json: ${e.message}`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const v = validateMarketplace(raw);
|
|
77
|
+
if (!v.ok) {
|
|
78
|
+
rmSync(dir, { recursive: true, force: true });
|
|
79
|
+
return { ok: false, error: `Marketplace ${name}: ${v.error}` };
|
|
80
|
+
}
|
|
81
|
+
const entry = {
|
|
82
|
+
source,
|
|
83
|
+
installLocation: dir,
|
|
84
|
+
lastUpdated: new Date().toISOString(),
|
|
85
|
+
};
|
|
86
|
+
upsertKnownMarketplace(name, entry);
|
|
87
|
+
return { ok: true, name, marketplace: v.value, replaced: Boolean(existing) };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Removes a marketplace: deletes the cached clone and the manifest entry.
|
|
91
|
+
* Returns whether anything was actually removed.
|
|
92
|
+
*/
|
|
93
|
+
export function removeMarketplace(name) {
|
|
94
|
+
const removed = removeKnownMarketplace(name);
|
|
95
|
+
const dir = marketplaceDir(name);
|
|
96
|
+
if (existsSync(dir)) {
|
|
97
|
+
rmSync(dir, { recursive: true, force: true });
|
|
98
|
+
}
|
|
99
|
+
return removed;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Loads a previously-added marketplace's manifest from disk. Returns null
|
|
103
|
+
* if the marketplace is unknown or the manifest is gone (caller can
|
|
104
|
+
* report to user).
|
|
105
|
+
*/
|
|
106
|
+
export function loadMarketplace(name) {
|
|
107
|
+
const known = readKnownMarketplaces();
|
|
108
|
+
if (!known[name])
|
|
109
|
+
return null;
|
|
110
|
+
const manifestPath = marketplaceJsonPath(name);
|
|
111
|
+
if (!existsSync(manifestPath))
|
|
112
|
+
return null;
|
|
113
|
+
let raw;
|
|
114
|
+
try {
|
|
115
|
+
raw = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const v = validateMarketplace(raw);
|
|
121
|
+
return v.ok ? v.value : null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Lists all known marketplaces with a quick plugin count read from each
|
|
125
|
+
* cached manifest. Marketplaces whose manifest is missing or invalid
|
|
126
|
+
* show pluginCount: -1 so the caller can flag them.
|
|
127
|
+
*/
|
|
128
|
+
export function listMarketplaces() {
|
|
129
|
+
const known = readKnownMarketplaces();
|
|
130
|
+
const out = [];
|
|
131
|
+
for (const [name, entry] of Object.entries(known)) {
|
|
132
|
+
const mp = loadMarketplace(name);
|
|
133
|
+
out.push({
|
|
134
|
+
name,
|
|
135
|
+
source: entry.source,
|
|
136
|
+
installLocation: entry.installLocation,
|
|
137
|
+
lastUpdated: entry.lastUpdated,
|
|
138
|
+
pluginCount: mp ? mp.plugins.length : -1,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
142
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import type { MarketplaceSource } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Returns the parsed source, or null when the input does not match any
|
|
9
|
+
* supported pattern. Callers should show a usage hint on null.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseMarketplaceInput(input: string): MarketplaceSource | null;
|
|
12
|
+
/**
|
|
13
|
+
* Derive a stable marketplace name from a source. Used as the filesystem
|
|
14
|
+
* directory and the key in known_marketplaces.json.
|
|
15
|
+
*/
|
|
16
|
+
export declare function deriveMarketplaceName(source: MarketplaceSource): string;
|