@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 maki maki
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# @cjhyy/code-shell-core
|
|
2
|
+
|
|
3
|
+
UI-agnostic agent orchestration framework. The headless core of [`code-shell`](https://github.com/cjhyy/codeshell): turn an LLM + a tool registry + a transcript into a multi-turn agent loop, with permissions, hooks, MCP support, and pluggable approval backends.
|
|
4
|
+
|
|
5
|
+
Compatible with Anthropic and OpenAI-protocol providers (Claude, DeepSeek, GPT, Gemini, Qwen, …). No terminal UI dependencies — embed it in a CLI, a web service, a Slack bot, a desktop app.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @cjhyy/code-shell-core
|
|
11
|
+
# or
|
|
12
|
+
bun add @cjhyy/code-shell-core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Node ≥ 20.10.
|
|
16
|
+
|
|
17
|
+
## Quickstart
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import {
|
|
21
|
+
Engine,
|
|
22
|
+
HeadlessApprovalBackend,
|
|
23
|
+
} from "@cjhyy/code-shell-core";
|
|
24
|
+
|
|
25
|
+
const engine = new Engine({
|
|
26
|
+
llm: {
|
|
27
|
+
provider: "anthropic",
|
|
28
|
+
model: "claude-sonnet-4-6",
|
|
29
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
30
|
+
},
|
|
31
|
+
cwd: process.cwd(),
|
|
32
|
+
// Headless approval — "approve-all" trusts the model fully; use
|
|
33
|
+
// "approve-read-only" or a custom ApprovalBackend in production.
|
|
34
|
+
approvalBackend: new HeadlessApprovalBackend("approve-all"),
|
|
35
|
+
headless: true,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const result = await engine.run(
|
|
39
|
+
"list files in this directory and summarise their purpose",
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
console.log(result.text);
|
|
43
|
+
console.log("turns:", result.turnCount, "reason:", result.reason);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Streaming events:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
await engine.run("...", {
|
|
50
|
+
onStream(event) {
|
|
51
|
+
if (event.type === "text_delta") process.stdout.write(event.text);
|
|
52
|
+
if (event.type === "tool_use_start") console.log("→", event.toolCall);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Restrict the tool set:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
new Engine({
|
|
61
|
+
llm: { /* … */ },
|
|
62
|
+
// Whitelist — only these built-in tools are registered.
|
|
63
|
+
enabledBuiltinTools: ["Read", "Glob", "Grep", "WebFetch"],
|
|
64
|
+
// Or blacklist — registers every built-in except these.
|
|
65
|
+
// disabledBuiltinTools: ["Bash", "Write", "Edit"],
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## What's included
|
|
70
|
+
|
|
71
|
+
- **Engine** — turn loop, transcript management, session persistence, resume.
|
|
72
|
+
- **Tool system** — registry, executor, permission classifier, schema validation. Built-in tools for filesystem, shell, web fetch, sub-agents, plan mode, tasks.
|
|
73
|
+
- **LLM clients** — Anthropic, OpenAI (and any OpenAI-protocol endpoint). Provider catalog covers DeepSeek, Qwen, OpenRouter, Gemini.
|
|
74
|
+
- **MCP** — connect to Model Context Protocol servers (stdio / SSE / streamable-http / in-process).
|
|
75
|
+
- **Hooks** — `pre_tool_use`, `post_tool_use`, `on_user_prompt_submit`, `on_session_start`, `on_session_end`, more.
|
|
76
|
+
- **Protocol** — `AgentServer` / `AgentClient` over JSON-RPC for running the engine out-of-process.
|
|
77
|
+
- **Run manager** — queue, schedule, and persist multi-engine workflows.
|
|
78
|
+
|
|
79
|
+
## Designing for production
|
|
80
|
+
|
|
81
|
+
- **Approval backend.** `HeadlessApprovalBackend("approve-all")` is fine for trusted prompts. For untrusted input, implement `ApprovalBackend` to gate destructive tools (Write/Edit/Bash) through your own auth.
|
|
82
|
+
- **Permission rules.** Pass `permissionRules` to the engine for fine-grained allow/deny per tool + args pattern. Bash commands additionally get a built-in safety classifier (dangerous commands like `rm -rf` always require explicit approval).
|
|
83
|
+
- **Hooks** are the right place for audit logging, prompt rewriting, and policy enforcement.
|
|
84
|
+
- **Memory.** The engine ships with an extract-memories + auto-dream pipeline that persists to `~/.code-shell/memory/`. Disable by passing a no-op `MemoryOrchestrator`, or scope to a project by setting `CODE_SHELL_HOME`.
|
|
85
|
+
|
|
86
|
+
## Recommended public API (B3 / standard §S7)
|
|
87
|
+
|
|
88
|
+
The stable, recommended construction path for embedders is the
|
|
89
|
+
`createServer` / `createClient` factory pair over a protocol transport.
|
|
90
|
+
Direct `new Engine(...)` still works for advanced cases — but the
|
|
91
|
+
protocol-mediated path is what we test, document, and avoid breaking.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import {
|
|
95
|
+
createServer,
|
|
96
|
+
createClient,
|
|
97
|
+
createInProcessTransport,
|
|
98
|
+
} from "@cjhyy/code-shell-core";
|
|
99
|
+
|
|
100
|
+
const [serverT, clientT] = createInProcessTransport();
|
|
101
|
+
const handle = createServer({
|
|
102
|
+
transport: serverT,
|
|
103
|
+
cwd: process.cwd(),
|
|
104
|
+
llm: { provider: "anthropic", model: "claude-sonnet-4-6", apiKey: KEY },
|
|
105
|
+
permissionMode: "default",
|
|
106
|
+
});
|
|
107
|
+
const client = createClient({ transport: clientT });
|
|
108
|
+
|
|
109
|
+
client.onStreamEvent(({ sessionId, event }) => {
|
|
110
|
+
if (event.type === "text_delta") process.stdout.write(event.text);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const result = await client.run({ sessionId: "main", task: "Summarize README.md" });
|
|
114
|
+
console.log(result.text);
|
|
115
|
+
|
|
116
|
+
handle.close();
|
|
117
|
+
client.close();
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For an out-of-process worker, swap `createInProcessTransport()` for a
|
|
121
|
+
`StdioTransport` pair. The factory accepts any `Transport`, so a future
|
|
122
|
+
`IpcAdapter` will compose without changing the call shape.
|
|
123
|
+
|
|
124
|
+
`StreamEvent` includes `background_agent_completed` (B2.2) so embedders
|
|
125
|
+
that don't poll `notificationQueue` still observe sub-agent finish/fail
|
|
126
|
+
results. `client.onBackgroundAgentCompleted((sessionId, event) => …)` is
|
|
127
|
+
the typed entry point; events also flow through the catch-all
|
|
128
|
+
`onStreamEvent`.
|
|
129
|
+
|
|
130
|
+
## Stable surface
|
|
131
|
+
|
|
132
|
+
These exports are covered by the stability promise:
|
|
133
|
+
|
|
134
|
+
| Area | Stable exports |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| Factories | `createServer`, `createClient`, `createInProcessTransport`, `StdioTransport` |
|
|
137
|
+
| Server/client | `AgentServer`, `AgentClient` (direct use is supported but `createServer/Client` preferred) |
|
|
138
|
+
| Engine | `Engine`, `EngineConfig`, `EngineRuntime`, `ChatSessionManager` |
|
|
139
|
+
| Protocol types | `Methods`, `ErrorCodes`, `RpcMessage`, `RunResult`, `StreamEvent`, `StreamCallback`, `BackgroundAgentCompletedEvent` |
|
|
140
|
+
| LLM | `LLMConfig`, `LLMResponse`, `ModelPool`, `createLLMClient`, `registerProvider` |
|
|
141
|
+
| Tool authoring | `ToolDefinition`, `ToolCall`, `ToolResult`, `RegisteredTool`, `BUILTIN_TOOLS`, `HookContext`, `HookResult` |
|
|
142
|
+
| Permissions | `PermissionClassifier`, `HeadlessApprovalBackend`, `AutoApprovalBackend`, `ApprovalBackend`, `PermissionMode`, `PermissionRule` |
|
|
143
|
+
| Errors | `FrameworkError` + subclasses (`LLMError`, `ToolError`, `PermissionDeniedError`, …) |
|
|
144
|
+
|
|
145
|
+
### Treat as internal
|
|
146
|
+
|
|
147
|
+
Anything not in the table above — including direct imports from
|
|
148
|
+
`./engine/...`, `./tool-system/...`, `./session/...`, `./hooks/...`
|
|
149
|
+
subpaths and APIs marked `@internal` in their docstrings — may change
|
|
150
|
+
between minor versions without notice. Plan to migrate via the protocol
|
|
151
|
+
surface instead of deep-importing.
|
|
152
|
+
|
|
153
|
+
## Stability
|
|
154
|
+
|
|
155
|
+
Pre-1.0 — APIs may change between minor versions. The "stable surface"
|
|
156
|
+
table above is the contract; everything else is mobile.
|
|
157
|
+
|
|
158
|
+
See [CHANGELOG.md](https://github.com/cjhyy/codeshell/blob/main/CHANGELOG.md) in the monorepo.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT © maki maki. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent coordinator — agent registry + message bus for multi-agent communication.
|
|
3
|
+
*/
|
|
4
|
+
/** A registered named agent. */
|
|
5
|
+
export interface AgentInfo {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
status: "running" | "completed" | "failed";
|
|
9
|
+
description: string;
|
|
10
|
+
startedAt: number;
|
|
11
|
+
completedAt?: number;
|
|
12
|
+
result?: string;
|
|
13
|
+
}
|
|
14
|
+
/** A message between agents. */
|
|
15
|
+
export interface AgentMessage {
|
|
16
|
+
from: string;
|
|
17
|
+
to: string;
|
|
18
|
+
content: string;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Singleton agent registry and message bus.
|
|
23
|
+
*/
|
|
24
|
+
declare class AgentCoordinator {
|
|
25
|
+
private agents;
|
|
26
|
+
private inbox;
|
|
27
|
+
/** Register a named agent. */
|
|
28
|
+
register(id: string, name: string, description: string): void;
|
|
29
|
+
/** Mark an agent as completed. */
|
|
30
|
+
complete(name: string, result?: string): void;
|
|
31
|
+
/** Mark an agent as failed. */
|
|
32
|
+
fail(name: string): void;
|
|
33
|
+
/** Get agent info by name. */
|
|
34
|
+
get(name: string): AgentInfo | undefined;
|
|
35
|
+
/** List all agents. */
|
|
36
|
+
list(): AgentInfo[];
|
|
37
|
+
/** List active (running) agents. */
|
|
38
|
+
listActive(): AgentInfo[];
|
|
39
|
+
/** Send a message to a named agent. */
|
|
40
|
+
send(from: string, to: string, content: string): boolean;
|
|
41
|
+
/** Read messages for a named agent (drains the inbox). */
|
|
42
|
+
receive(name: string): AgentMessage[];
|
|
43
|
+
/** Peek at messages without draining. */
|
|
44
|
+
peek(name: string): AgentMessage[];
|
|
45
|
+
/** Reset all state. */
|
|
46
|
+
reset(): void;
|
|
47
|
+
}
|
|
48
|
+
export declare const agentCoordinator: AgentCoordinator;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent coordinator — agent registry + message bus for multi-agent communication.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Singleton agent registry and message bus.
|
|
6
|
+
*/
|
|
7
|
+
class AgentCoordinator {
|
|
8
|
+
agents = new Map();
|
|
9
|
+
inbox = new Map();
|
|
10
|
+
/** Register a named agent. */
|
|
11
|
+
register(id, name, description) {
|
|
12
|
+
this.agents.set(name, {
|
|
13
|
+
id,
|
|
14
|
+
name,
|
|
15
|
+
status: "running",
|
|
16
|
+
description,
|
|
17
|
+
startedAt: Date.now(),
|
|
18
|
+
});
|
|
19
|
+
if (!this.inbox.has(name)) {
|
|
20
|
+
this.inbox.set(name, []);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Mark an agent as completed. */
|
|
24
|
+
complete(name, result) {
|
|
25
|
+
const agent = this.agents.get(name);
|
|
26
|
+
if (agent) {
|
|
27
|
+
agent.status = "completed";
|
|
28
|
+
agent.completedAt = Date.now();
|
|
29
|
+
agent.result = result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Mark an agent as failed. */
|
|
33
|
+
fail(name) {
|
|
34
|
+
const agent = this.agents.get(name);
|
|
35
|
+
if (agent) {
|
|
36
|
+
agent.status = "failed";
|
|
37
|
+
agent.completedAt = Date.now();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Get agent info by name. */
|
|
41
|
+
get(name) {
|
|
42
|
+
return this.agents.get(name);
|
|
43
|
+
}
|
|
44
|
+
/** List all agents. */
|
|
45
|
+
list() {
|
|
46
|
+
return [...this.agents.values()];
|
|
47
|
+
}
|
|
48
|
+
/** List active (running) agents. */
|
|
49
|
+
listActive() {
|
|
50
|
+
return [...this.agents.values()].filter((a) => a.status === "running");
|
|
51
|
+
}
|
|
52
|
+
/** Send a message to a named agent. */
|
|
53
|
+
send(from, to, content) {
|
|
54
|
+
if (!this.agents.has(to))
|
|
55
|
+
return false;
|
|
56
|
+
const messages = this.inbox.get(to) ?? [];
|
|
57
|
+
messages.push({ from, to, content, timestamp: Date.now() });
|
|
58
|
+
this.inbox.set(to, messages);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
/** Read messages for a named agent (drains the inbox). */
|
|
62
|
+
receive(name) {
|
|
63
|
+
const messages = this.inbox.get(name) ?? [];
|
|
64
|
+
this.inbox.set(name, []);
|
|
65
|
+
return messages;
|
|
66
|
+
}
|
|
67
|
+
/** Peek at messages without draining. */
|
|
68
|
+
peek(name) {
|
|
69
|
+
return this.inbox.get(name) ?? [];
|
|
70
|
+
}
|
|
71
|
+
/** Reset all state. */
|
|
72
|
+
reset() {
|
|
73
|
+
this.agents.clear();
|
|
74
|
+
this.inbox.clear();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export const agentCoordinator = new AgentCoordinator();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arena — multi-model collaborative analysis engine.
|
|
3
|
+
*
|
|
4
|
+
* Evidence-Driven Pipeline:
|
|
5
|
+
* 0. Planner → understand what the user wants (mode, lenses, sources)
|
|
6
|
+
* 1. EvidenceProviders → collect artifacts from selected sources
|
|
7
|
+
* 2. Strategy + Lens → compose prompts (mode flow + perspective)
|
|
8
|
+
* 3. ToolSelector → determine which tools participants can use
|
|
9
|
+
* 4. ParticipantResearch → each model investigates independently (parallel)
|
|
10
|
+
* 4b. ClaimRegistry → register findings as claims, populate ledger
|
|
11
|
+
* 5. VerificationReview → claim-aware cross-review with evidence digests
|
|
12
|
+
* 7. DebateRounds → contested claims enter structured debate
|
|
13
|
+
* 8. Adjudication → moderator rules on contested claims
|
|
14
|
+
* 6. ConsensusBuilder → claim-aware structured consensus
|
|
15
|
+
*/
|
|
16
|
+
import type { ArenaConfig, ArenaResultV2 } from "./types.js";
|
|
17
|
+
import type { PlannerFlags } from "./planner.js";
|
|
18
|
+
export declare class Arena {
|
|
19
|
+
private config;
|
|
20
|
+
private strategy;
|
|
21
|
+
private limits;
|
|
22
|
+
constructor(config: ArenaConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Run a full arena session.
|
|
25
|
+
*
|
|
26
|
+
* @param topic - User's topic/request (natural language)
|
|
27
|
+
* @param flags - Optional explicit overrides (mode, base, head)
|
|
28
|
+
*/
|
|
29
|
+
run(topic: string, flags?: PlannerFlags): Promise<ArenaResultV2>;
|
|
30
|
+
/**
|
|
31
|
+
* Planning path: merge-oriented review → roadmap consensus → detail expansion.
|
|
32
|
+
*
|
|
33
|
+
* Planning mode does NOT enter heavy debate/adjudication. Contested findings
|
|
34
|
+
* are converted to open questions or dependency risks in the roadmap.
|
|
35
|
+
*/
|
|
36
|
+
private runPlanningPath;
|
|
37
|
+
/**
|
|
38
|
+
* Review/Discussion path: verification review → debate → adjudication → consensus.
|
|
39
|
+
*
|
|
40
|
+
* This is the heavy trust loop for claim verification.
|
|
41
|
+
*/
|
|
42
|
+
private runReviewDiscussionPath;
|
|
43
|
+
}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arena — multi-model collaborative analysis engine.
|
|
3
|
+
*
|
|
4
|
+
* Evidence-Driven Pipeline:
|
|
5
|
+
* 0. Planner → understand what the user wants (mode, lenses, sources)
|
|
6
|
+
* 1. EvidenceProviders → collect artifacts from selected sources
|
|
7
|
+
* 2. Strategy + Lens → compose prompts (mode flow + perspective)
|
|
8
|
+
* 3. ToolSelector → determine which tools participants can use
|
|
9
|
+
* 4. ParticipantResearch → each model investigates independently (parallel)
|
|
10
|
+
* 4b. ClaimRegistry → register findings as claims, populate ledger
|
|
11
|
+
* 5. VerificationReview → claim-aware cross-review with evidence digests
|
|
12
|
+
* 7. DebateRounds → contested claims enter structured debate
|
|
13
|
+
* 8. Adjudication → moderator rules on contested claims
|
|
14
|
+
* 6. ConsensusBuilder → claim-aware structured consensus
|
|
15
|
+
*/
|
|
16
|
+
import { logger } from "../logging/logger.js";
|
|
17
|
+
import { ARENA_MODE_DEFAULTS, DEFAULT_EXECUTION_LIMITS, isStrategyPlanning } from "./types.js";
|
|
18
|
+
import { getStrategy, getStrategyForPlan } from "./strategies/index.js";
|
|
19
|
+
import { planArena } from "./planner.js";
|
|
20
|
+
import { collectEvidence } from "./providers/index.js";
|
|
21
|
+
import { selectTools } from "./tools/selector.js";
|
|
22
|
+
import { runParticipantResearchWithDossiers } from "./phases/participant-research.js";
|
|
23
|
+
import { runVerificationReview } from "./phases/cross-review.js";
|
|
24
|
+
import { runDebateRounds } from "./phases/debate-rounds.js";
|
|
25
|
+
import { runAdjudication } from "./phases/adjudication.js";
|
|
26
|
+
import { buildConsensus } from "./phases/build-consensus.js";
|
|
27
|
+
import { runDetailExpansion } from "./phases/planning-detail-expansion.js";
|
|
28
|
+
import { withLanguage } from "./strategies/language-wrapper.js";
|
|
29
|
+
import { ArenaLedger } from "./ledger.js";
|
|
30
|
+
import { registerClaims } from "./phases/claim-registry.js";
|
|
31
|
+
export class Arena {
|
|
32
|
+
config;
|
|
33
|
+
strategy;
|
|
34
|
+
limits;
|
|
35
|
+
constructor(config) {
|
|
36
|
+
if (config.participants.length < 2) {
|
|
37
|
+
throw new Error("Arena requires at least 2 participants");
|
|
38
|
+
}
|
|
39
|
+
const mode = config.mode ?? "review";
|
|
40
|
+
const defaults = ARENA_MODE_DEFAULTS[mode];
|
|
41
|
+
this.config = {
|
|
42
|
+
mode,
|
|
43
|
+
maxDiscussionRounds: config.maxDiscussionRounds ?? defaults.maxDiscussionRounds,
|
|
44
|
+
...config,
|
|
45
|
+
};
|
|
46
|
+
this.limits = config.executionLimits ?? DEFAULT_EXECUTION_LIMITS;
|
|
47
|
+
// Initial strategy — will be overridden in run() with lens + language wrappers
|
|
48
|
+
this.strategy = config.strategy ?? getStrategy(mode);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run a full arena session.
|
|
52
|
+
*
|
|
53
|
+
* @param topic - User's topic/request (natural language)
|
|
54
|
+
* @param flags - Optional explicit overrides (mode, base, head)
|
|
55
|
+
*/
|
|
56
|
+
async run(topic, flags) {
|
|
57
|
+
const participantNames = this.config.participants.map((p) => p.name);
|
|
58
|
+
const signal = this.config.signal;
|
|
59
|
+
logger.info("arena.start", { mode: this.config.mode, participants: participantNames });
|
|
60
|
+
signal?.throwIfAborted();
|
|
61
|
+
// ─── Phase 0: Plan ────────────────────────────────────────
|
|
62
|
+
const llmConfig = this.config.participants[0].llm;
|
|
63
|
+
const plan = await planArena(topic, llmConfig, flags, signal);
|
|
64
|
+
this.config.onProgress?.({ type: "plan_resolved", plan });
|
|
65
|
+
logger.info("arena.plan", {
|
|
66
|
+
mode: plan.mode,
|
|
67
|
+
lenses: plan.lenses.map((l) => l.name),
|
|
68
|
+
sources: plan.sources.map((s) => s.kind),
|
|
69
|
+
subject: plan.subject.label,
|
|
70
|
+
confidence: plan.confidence,
|
|
71
|
+
});
|
|
72
|
+
if (!flags?.mode && plan.mode !== this.config.mode) {
|
|
73
|
+
this.config.mode = plan.mode;
|
|
74
|
+
}
|
|
75
|
+
signal?.throwIfAborted();
|
|
76
|
+
// ─── Phase 1: Collect Evidence ────────────────────────────
|
|
77
|
+
// Bridge collectEvidence's lifecycle events to the public
|
|
78
|
+
// ArenaProgressEvent stream so the UI sees "collecting from
|
|
79
|
+
// repo..." instead of a silent pause.
|
|
80
|
+
const onProgress = this.config.onProgress;
|
|
81
|
+
const { artifacts, quickFacts } = await collectEvidence(plan, topic, {
|
|
82
|
+
signal,
|
|
83
|
+
onProgress: (e) => {
|
|
84
|
+
if (e.type === "evidence_started") {
|
|
85
|
+
onProgress?.({ type: "evidence_started", source: e.source });
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
onProgress?.({
|
|
89
|
+
type: "evidence_source_done",
|
|
90
|
+
source: e.source,
|
|
91
|
+
count: e.count ?? 0,
|
|
92
|
+
durationMs: e.durationMs ?? 0,
|
|
93
|
+
timedOut: e.timedOut ?? false,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
onProgress?.({ type: "evidence_collected", artifacts });
|
|
99
|
+
logger.info("arena.evidence", {
|
|
100
|
+
artifactCount: artifacts.length,
|
|
101
|
+
sources: plan.sources.map((s) => s.kind),
|
|
102
|
+
});
|
|
103
|
+
const baseContext = { plan, artifacts, quickFacts };
|
|
104
|
+
// ─── Phase 2: Compose Strategy ────────────────────────────
|
|
105
|
+
this.strategy = this.config.strategy ?? getStrategyForPlan(plan);
|
|
106
|
+
this.strategy = withLanguage(this.strategy, topic);
|
|
107
|
+
// ─── Phase 3: Select Tools ────────────────────────────────
|
|
108
|
+
const contextTools = this.config.enableContextTools !== false
|
|
109
|
+
? selectTools(plan)
|
|
110
|
+
: undefined;
|
|
111
|
+
signal?.throwIfAborted();
|
|
112
|
+
// ─── Phase 4: Participant Research (parallel) ─────────────
|
|
113
|
+
logger.info("arena.research_phase", { participants: participantNames });
|
|
114
|
+
const researchResults = await runParticipantResearchWithDossiers({
|
|
115
|
+
participants: this.config.participants,
|
|
116
|
+
strategy: this.strategy,
|
|
117
|
+
topic,
|
|
118
|
+
baseContext,
|
|
119
|
+
enableContextTools: this.config.enableContextTools ?? true,
|
|
120
|
+
contextTools,
|
|
121
|
+
signal,
|
|
122
|
+
onProgress: this.config.onProgress,
|
|
123
|
+
});
|
|
124
|
+
const reports = researchResults.map((r) => r.report);
|
|
125
|
+
const dossiers = researchResults.map((r) => r.dossier);
|
|
126
|
+
signal?.throwIfAborted();
|
|
127
|
+
// ─── Phase 4b: Claim Registry ─────────────────────────────
|
|
128
|
+
const ledger = new ArenaLedger();
|
|
129
|
+
// Populate ledger with dossiers
|
|
130
|
+
for (const dossier of dossiers) {
|
|
131
|
+
ledger.appendDossier(dossier);
|
|
132
|
+
}
|
|
133
|
+
// Register findings as claims
|
|
134
|
+
const claims = registerClaims({
|
|
135
|
+
dossiers,
|
|
136
|
+
ledger,
|
|
137
|
+
onProgress: this.config.onProgress,
|
|
138
|
+
});
|
|
139
|
+
logger.info("arena.claims_registered", {
|
|
140
|
+
claimCount: claims.length,
|
|
141
|
+
byOwner: Object.fromEntries(participantNames.map((name) => [
|
|
142
|
+
name,
|
|
143
|
+
claims.filter((c) => c.owner === name).length,
|
|
144
|
+
])),
|
|
145
|
+
});
|
|
146
|
+
signal?.throwIfAborted();
|
|
147
|
+
// ─── Phase 5: Mode Policy Router ─────────────────────────
|
|
148
|
+
//
|
|
149
|
+
// Planning mode: merge-oriented review → roadmap consensus → detail expansion
|
|
150
|
+
// Review/Discussion mode: verification review → debate → adjudication → consensus
|
|
151
|
+
const concluderName = this.config.concluder ?? participantNames[0];
|
|
152
|
+
const concluderMatch = this.config.participants.find((p) => p.name === concluderName);
|
|
153
|
+
if (!concluderMatch && this.config.concluder) {
|
|
154
|
+
logger.warn("arena.concluder_not_found", {
|
|
155
|
+
requested: this.config.concluder,
|
|
156
|
+
fallback: this.config.participants[0].name,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const concluder = concluderMatch ?? this.config.participants[0];
|
|
160
|
+
const enableTools = this.config.enableContextTools !== false;
|
|
161
|
+
if (this.config.mode === "planning") {
|
|
162
|
+
return this.runPlanningPath({
|
|
163
|
+
topic, participantNames, plan, baseContext, reports, dossiers, ledger,
|
|
164
|
+
concluder, contextTools, enableContextTools: enableTools, signal,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return this.runReviewDiscussionPath({
|
|
168
|
+
topic, participantNames, plan, baseContext, reports, dossiers, ledger, concluder, signal,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Planning path: merge-oriented review → roadmap consensus → detail expansion.
|
|
173
|
+
*
|
|
174
|
+
* Planning mode does NOT enter heavy debate/adjudication. Contested findings
|
|
175
|
+
* are converted to open questions or dependency risks in the roadmap.
|
|
176
|
+
*/
|
|
177
|
+
async runPlanningPath(ctx) {
|
|
178
|
+
const { topic, participantNames, plan, baseContext, reports, dossiers, ledger, concluder, contextTools, enableContextTools, signal, } = ctx;
|
|
179
|
+
// ─── Merge-Oriented Review ───────────────────────────────
|
|
180
|
+
logger.info("arena.planning_merge_review_phase");
|
|
181
|
+
const { reviews } = await runVerificationReview({
|
|
182
|
+
participants: this.config.participants,
|
|
183
|
+
strategy: this.strategy,
|
|
184
|
+
topic,
|
|
185
|
+
reports,
|
|
186
|
+
ledger,
|
|
187
|
+
limits: this.limits,
|
|
188
|
+
mode: "planning",
|
|
189
|
+
signal,
|
|
190
|
+
onProgress: this.config.onProgress,
|
|
191
|
+
});
|
|
192
|
+
signal?.throwIfAborted();
|
|
193
|
+
// ─── Roadmap Consensus ───────────────────────────────────
|
|
194
|
+
const allClaims = ledger.getAllClaims();
|
|
195
|
+
const claimSummary = {
|
|
196
|
+
verified: allClaims.filter((c) => c.status === "verified"),
|
|
197
|
+
contested: allClaims.filter((c) => c.status === "contested"),
|
|
198
|
+
unresolved: allClaims.filter((c) => c.status === "unresolved"),
|
|
199
|
+
rejected: allClaims.filter((c) => c.status === "rejected"),
|
|
200
|
+
};
|
|
201
|
+
logger.info("arena.planning_consensus_phase", { concluder: concluder.name });
|
|
202
|
+
const consensus = await buildConsensus({
|
|
203
|
+
concluder,
|
|
204
|
+
strategy: this.strategy,
|
|
205
|
+
topic,
|
|
206
|
+
reports,
|
|
207
|
+
reviews,
|
|
208
|
+
claimSummary,
|
|
209
|
+
signal,
|
|
210
|
+
onProgress: this.config.onProgress,
|
|
211
|
+
});
|
|
212
|
+
signal?.throwIfAborted();
|
|
213
|
+
// ─── Detail Expansion ────────────────────────────────────
|
|
214
|
+
if (consensus.roadmap.length > 0 && isStrategyPlanning(this.strategy)) {
|
|
215
|
+
logger.info("arena.detail_expansion_phase", { phaseCount: consensus.roadmap.length });
|
|
216
|
+
try {
|
|
217
|
+
const details = await runDetailExpansion({
|
|
218
|
+
concluder,
|
|
219
|
+
strategy: this.strategy,
|
|
220
|
+
topic,
|
|
221
|
+
phases: consensus.roadmap,
|
|
222
|
+
ledger,
|
|
223
|
+
limits: this.limits,
|
|
224
|
+
enableContextTools,
|
|
225
|
+
contextTools,
|
|
226
|
+
signal,
|
|
227
|
+
onProgress: this.config.onProgress,
|
|
228
|
+
});
|
|
229
|
+
consensus.roadmapDetails = details;
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
// Detail expansion is non-critical — degrade gracefully
|
|
233
|
+
logger.warn("arena.detail_expansion_failed", {
|
|
234
|
+
error: err.message,
|
|
235
|
+
phaseCount: consensus.roadmap.length,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
topic,
|
|
241
|
+
mode: this.config.mode,
|
|
242
|
+
participants: participantNames,
|
|
243
|
+
plan,
|
|
244
|
+
baseContext,
|
|
245
|
+
reports,
|
|
246
|
+
dossiers,
|
|
247
|
+
claims: allClaims,
|
|
248
|
+
reviews,
|
|
249
|
+
consensus,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Review/Discussion path: verification review → debate → adjudication → consensus.
|
|
254
|
+
*
|
|
255
|
+
* This is the heavy trust loop for claim verification.
|
|
256
|
+
*/
|
|
257
|
+
async runReviewDiscussionPath(ctx) {
|
|
258
|
+
const { topic, participantNames, plan, baseContext, reports, dossiers, ledger, concluder, signal } = ctx;
|
|
259
|
+
// ─── Verification Review (parallel) ──────────────────────
|
|
260
|
+
logger.info("arena.verification_review_phase");
|
|
261
|
+
const { reviews } = await runVerificationReview({
|
|
262
|
+
participants: this.config.participants,
|
|
263
|
+
strategy: this.strategy,
|
|
264
|
+
topic,
|
|
265
|
+
reports,
|
|
266
|
+
ledger,
|
|
267
|
+
limits: this.limits,
|
|
268
|
+
signal,
|
|
269
|
+
onProgress: this.config.onProgress,
|
|
270
|
+
});
|
|
271
|
+
signal?.throwIfAborted();
|
|
272
|
+
// ─── Debate Rounds ───────────────────────────────────────
|
|
273
|
+
logger.info("arena.debate_phase");
|
|
274
|
+
const debateRounds = await runDebateRounds({
|
|
275
|
+
participants: this.config.participants,
|
|
276
|
+
strategy: this.strategy,
|
|
277
|
+
topic,
|
|
278
|
+
ledger,
|
|
279
|
+
limits: this.limits,
|
|
280
|
+
maxRounds: this.config.maxDiscussionRounds,
|
|
281
|
+
signal,
|
|
282
|
+
onProgress: this.config.onProgress,
|
|
283
|
+
});
|
|
284
|
+
signal?.throwIfAborted();
|
|
285
|
+
// ─── Adjudication ────────────────────────────────────────
|
|
286
|
+
logger.info("arena.adjudication_phase", { concluder: concluder.name });
|
|
287
|
+
const adjudications = await runAdjudication({
|
|
288
|
+
concluder,
|
|
289
|
+
strategy: this.strategy,
|
|
290
|
+
topic,
|
|
291
|
+
ledger,
|
|
292
|
+
signal,
|
|
293
|
+
onProgress: this.config.onProgress,
|
|
294
|
+
});
|
|
295
|
+
signal?.throwIfAborted();
|
|
296
|
+
// ─── Consensus (claim-aware) ─────────────────────────────
|
|
297
|
+
const allClaims = ledger.getAllClaims();
|
|
298
|
+
const claimSummary = {
|
|
299
|
+
verified: allClaims.filter((c) => c.status === "verified"),
|
|
300
|
+
contested: allClaims.filter((c) => c.status === "contested"),
|
|
301
|
+
unresolved: allClaims.filter((c) => c.status === "unresolved"),
|
|
302
|
+
rejected: allClaims.filter((c) => c.status === "rejected"),
|
|
303
|
+
};
|
|
304
|
+
logger.info("arena.consensus_phase", {
|
|
305
|
+
concluder: concluder.name,
|
|
306
|
+
verified: claimSummary.verified.length,
|
|
307
|
+
unresolved: claimSummary.unresolved.length,
|
|
308
|
+
});
|
|
309
|
+
const consensus = await buildConsensus({
|
|
310
|
+
concluder,
|
|
311
|
+
strategy: this.strategy,
|
|
312
|
+
topic,
|
|
313
|
+
reports,
|
|
314
|
+
reviews,
|
|
315
|
+
claimSummary,
|
|
316
|
+
signal,
|
|
317
|
+
onProgress: this.config.onProgress,
|
|
318
|
+
});
|
|
319
|
+
return {
|
|
320
|
+
topic,
|
|
321
|
+
mode: this.config.mode,
|
|
322
|
+
participants: participantNames,
|
|
323
|
+
plan,
|
|
324
|
+
baseContext,
|
|
325
|
+
reports,
|
|
326
|
+
dossiers,
|
|
327
|
+
claims: allClaims,
|
|
328
|
+
reviews,
|
|
329
|
+
debateRounds,
|
|
330
|
+
adjudications,
|
|
331
|
+
consensus,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|