hyacinth-ai 0.9.6
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 +205 -0
- package/commands.json +25 -0
- package/dist/agents/builtins.d.ts +8 -0
- package/dist/agents/builtins.js +50 -0
- package/dist/agents/config-loader.d.ts +15 -0
- package/dist/agents/config-loader.js +75 -0
- package/dist/agents/delegate-tool.d.ts +109 -0
- package/dist/agents/delegate-tool.js +407 -0
- package/dist/agents/index.d.ts +5 -0
- package/dist/agents/index.js +5 -0
- package/dist/agents/registry.d.ts +2 -0
- package/dist/agents/registry.js +2 -0
- package/dist/bypass/agents/companion/index.d.ts +57 -0
- package/dist/bypass/agents/companion/index.js +487 -0
- package/dist/bypass/agents/orchestrator/index.d.ts +17 -0
- package/dist/bypass/agents/orchestrator/index.js +414 -0
- package/dist/bypass/agents/orchestrator.d.ts +16 -0
- package/dist/bypass/agents/orchestrator.js +377 -0
- package/dist/bypass/agents/world-engine/agent.d.ts +41 -0
- package/dist/bypass/agents/world-engine/agent.js +385 -0
- package/dist/bypass/agents/world-engine/index.d.ts +52 -0
- package/dist/bypass/agents/world-engine/index.js +198 -0
- package/dist/bypass/agents/world-engine/sim.d.ts +14 -0
- package/dist/bypass/agents/world-engine/sim.js +120 -0
- package/dist/bypass/agents/world-engine/store.d.ts +110 -0
- package/dist/bypass/agents/world-engine/store.js +519 -0
- package/dist/bypass/agents/world-engine/ticker.d.ts +37 -0
- package/dist/bypass/agents/world-engine/ticker.js +214 -0
- package/dist/bypass/agents/world-engine/tools.d.ts +6 -0
- package/dist/bypass/agents/world-engine/tools.js +380 -0
- package/dist/bypass/agents/world-engine/types.d.ts +202 -0
- package/dist/bypass/agents/world-engine/types.js +56 -0
- package/dist/bypass/agents/world-engine.d.ts +20 -0
- package/dist/bypass/agents/world-engine.js +63 -0
- package/dist/bypass/base.d.ts +48 -0
- package/dist/bypass/base.js +126 -0
- package/dist/bypass/index.d.ts +5 -0
- package/dist/bypass/index.js +6 -0
- package/dist/bypass/manager.d.ts +41 -0
- package/dist/bypass/manager.js +179 -0
- package/dist/bypass/types.d.ts +63 -0
- package/dist/bypass/types.js +14 -0
- package/dist/channels/auto-detect.d.ts +25 -0
- package/dist/channels/auto-detect.js +77 -0
- package/dist/channels/builtin/http-webhook.d.ts +25 -0
- package/dist/channels/builtin/http-webhook.js +287 -0
- package/dist/channels/builtin/tui-channel.d.ts +33 -0
- package/dist/channels/builtin/tui-channel.js +61 -0
- package/dist/channels/builtin/tui-ws-session.d.ts +16 -0
- package/dist/channels/builtin/tui-ws-session.js +90 -0
- package/dist/channels/builtin/webui-output-handler.d.ts +30 -0
- package/dist/channels/builtin/webui-output-handler.js +93 -0
- package/dist/channels/index.d.ts +5 -0
- package/dist/channels/index.js +3 -0
- package/dist/channels/interface.d.ts +148 -0
- package/dist/channels/interface.js +15 -0
- package/dist/channels/manager.d.ts +43 -0
- package/dist/channels/manager.js +156 -0
- package/dist/channels/message-queue.d.ts +36 -0
- package/dist/channels/message-queue.js +91 -0
- package/dist/channels/plugins/clawbot/clawbot-auth.d.ts +50 -0
- package/dist/channels/plugins/clawbot/clawbot-auth.js +235 -0
- package/dist/channels/plugins/clawbot/clawbot-channel.d.ts +76 -0
- package/dist/channels/plugins/clawbot/clawbot-channel.js +566 -0
- package/dist/channels/plugins/clawbot/clawbot-client.d.ts +180 -0
- package/dist/channels/plugins/clawbot/clawbot-client.js +312 -0
- package/dist/channels/plugins/clawbot/clawbot-config.d.ts +30 -0
- package/dist/channels/plugins/clawbot/clawbot-config.js +28 -0
- package/dist/channels/plugins/clawbot/clawbot-message-queue.d.ts +27 -0
- package/dist/channels/plugins/clawbot/clawbot-message-queue.js +114 -0
- package/dist/channels/plugins/clawbot/clawbot-session.d.ts +10 -0
- package/dist/channels/plugins/clawbot/clawbot-session.js +26 -0
- package/dist/channels/plugins/clawbot/index.d.ts +17 -0
- package/dist/channels/plugins/clawbot/index.js +58 -0
- package/dist/channels/plugins/feishu/feishu-channel.d.ts +57 -0
- package/dist/channels/plugins/feishu/feishu-channel.js +602 -0
- package/dist/channels/plugins/feishu/feishu-client.d.ts +23 -0
- package/dist/channels/plugins/feishu/feishu-client.js +86 -0
- package/dist/channels/plugins/feishu/feishu-config.d.ts +53 -0
- package/dist/channels/plugins/feishu/feishu-config.js +35 -0
- package/dist/channels/plugins/feishu/feishu-event.d.ts +102 -0
- package/dist/channels/plugins/feishu/feishu-event.js +257 -0
- package/dist/channels/plugins/feishu/feishu-log-suppressor.d.ts +7 -0
- package/dist/channels/plugins/feishu/feishu-log-suppressor.js +34 -0
- package/dist/channels/plugins/feishu/feishu-message-queue.d.ts +27 -0
- package/dist/channels/plugins/feishu/feishu-message-queue.js +112 -0
- package/dist/channels/plugins/feishu/feishu-send.d.ts +44 -0
- package/dist/channels/plugins/feishu/feishu-send.js +232 -0
- package/dist/channels/plugins/feishu/feishu-session.d.ts +44 -0
- package/dist/channels/plugins/feishu/feishu-session.js +84 -0
- package/dist/channels/plugins/feishu/feishu-streaming.d.ts +49 -0
- package/dist/channels/plugins/feishu/feishu-streaming.js +185 -0
- package/dist/channels/plugins/feishu/feishu-transport.d.ts +29 -0
- package/dist/channels/plugins/feishu/feishu-transport.js +99 -0
- package/dist/channels/plugins/feishu/index.d.ts +22 -0
- package/dist/channels/plugins/feishu/index.js +68 -0
- package/dist/cli/doctor.d.ts +20 -0
- package/dist/cli/doctor.js +317 -0
- package/dist/context/cache-strategy.d.ts +76 -0
- package/dist/context/cache-strategy.js +123 -0
- package/dist/context/composer.d.ts +77 -0
- package/dist/context/composer.js +318 -0
- package/dist/context/compressor.d.ts +218 -0
- package/dist/context/compressor.js +909 -0
- package/dist/context/index.d.ts +14 -0
- package/dist/context/index.js +8 -0
- package/dist/context/interface.d.ts +33 -0
- package/dist/context/interface.js +2 -0
- package/dist/context/manifest-defaults.d.ts +51 -0
- package/dist/context/manifest-defaults.js +133 -0
- package/dist/context/manifest-loader.d.ts +16 -0
- package/dist/context/manifest-loader.js +103 -0
- package/dist/context/manifest-types.d.ts +26 -0
- package/dist/context/manifest-types.js +2 -0
- package/dist/context/precision/analyzer.d.ts +31 -0
- package/dist/context/precision/analyzer.js +131 -0
- package/dist/context/precision/companion.d.ts +27 -0
- package/dist/context/precision/companion.js +144 -0
- package/dist/context/precision/default.d.ts +14 -0
- package/dist/context/precision/default.js +17 -0
- package/dist/context/precision/index.d.ts +9 -0
- package/dist/context/precision/index.js +7 -0
- package/dist/context/precision/keyword-pool.d.ts +27 -0
- package/dist/context/precision/keyword-pool.js +66 -0
- package/dist/context/precision/strategy.d.ts +18 -0
- package/dist/context/precision/strategy.js +51 -0
- package/dist/context/precision/summary-store.d.ts +18 -0
- package/dist/context/precision/summary-store.js +67 -0
- package/dist/context/precision/types.d.ts +23 -0
- package/dist/context/precision/types.js +2 -0
- package/dist/context/profiles.d.ts +45 -0
- package/dist/context/profiles.js +92 -0
- package/dist/context/prompt-builder.d.ts +76 -0
- package/dist/context/prompt-builder.js +133 -0
- package/dist/context/retriever.d.ts +44 -0
- package/dist/context/retriever.js +203 -0
- package/dist/context/router.d.ts +122 -0
- package/dist/context/router.js +291 -0
- package/dist/context/section-resolver.d.ts +38 -0
- package/dist/context/section-resolver.js +398 -0
- package/dist/context/tokenizer.d.ts +23 -0
- package/dist/context/tokenizer.js +78 -0
- package/dist/dependency/analyzer.d.ts +33 -0
- package/dist/dependency/analyzer.js +242 -0
- package/dist/dependency/data-flow-tracker.d.ts +12 -0
- package/dist/dependency/data-flow-tracker.js +97 -0
- package/dist/dependency/function-parser.d.ts +34 -0
- package/dist/dependency/function-parser.js +295 -0
- package/dist/dependency/index.d.ts +14 -0
- package/dist/dependency/index.js +20 -0
- package/dist/dependency/parser.d.ts +10 -0
- package/dist/dependency/parser.js +93 -0
- package/dist/dependency/types.d.ts +57 -0
- package/dist/dependency/types.js +2 -0
- package/dist/env/env-collector.d.ts +45 -0
- package/dist/env/env-collector.js +221 -0
- package/dist/env/index.d.ts +3 -0
- package/dist/env/index.js +2 -0
- package/dist/event-store.d.ts +27 -0
- package/dist/event-store.js +71 -0
- package/dist/evolution/git-manager.d.ts +46 -0
- package/dist/evolution/git-manager.js +276 -0
- package/dist/evolution/index.d.ts +3 -0
- package/dist/evolution/index.js +2 -0
- package/dist/flow/bootstrap-flow.d.ts +19 -0
- package/dist/flow/bootstrap-flow.js +72 -0
- package/dist/flow/flow-registry.d.ts +12 -0
- package/dist/flow/flow-registry.js +74 -0
- package/dist/flow/flow-tools.d.ts +8 -0
- package/dist/flow/flow-tools.js +106 -0
- package/dist/flow/index.d.ts +6 -0
- package/dist/flow/index.js +8 -0
- package/dist/flow/todo-flow.d.ts +25 -0
- package/dist/flow/todo-flow.js +107 -0
- package/dist/flow/types.d.ts +78 -0
- package/dist/flow/types.js +12 -0
- package/dist/flows/bootstrap.d.ts +18 -0
- package/dist/flows/bootstrap.js +119 -0
- package/dist/flows/index.d.ts +6 -0
- package/dist/flows/index.js +11 -0
- package/dist/flows/todo.d.ts +26 -0
- package/dist/flows/todo.js +174 -0
- package/dist/flows/tools.d.ts +8 -0
- package/dist/flows/tools.js +119 -0
- package/dist/flows/types.d.ts +27 -0
- package/dist/flows/types.js +10 -0
- package/dist/gateway/cli.d.ts +5 -0
- package/dist/gateway/cli.js +1027 -0
- package/dist/gateway/factory.d.ts +80 -0
- package/dist/gateway/factory.js +832 -0
- package/dist/gateway/guardian.d.ts +8 -0
- package/dist/gateway/guardian.js +30 -0
- package/dist/gateway/index.d.ts +3 -0
- package/dist/gateway/index.js +3 -0
- package/dist/gateway/server.d.ts +17 -0
- package/dist/gateway/server.js +96 -0
- package/dist/gateway/tui.d.ts +16 -0
- package/dist/gateway/tui.js +3273 -0
- package/dist/hot-reload/agent-watcher.d.ts +24 -0
- package/dist/hot-reload/agent-watcher.js +175 -0
- package/dist/hot-reload/bundle-watcher.d.ts +12 -0
- package/dist/hot-reload/bundle-watcher.js +35 -0
- package/dist/hot-reload/channel-watcher.d.ts +19 -0
- package/dist/hot-reload/channel-watcher.js +54 -0
- package/dist/hot-reload/command-watcher.d.ts +14 -0
- package/dist/hot-reload/command-watcher.js +54 -0
- package/dist/hot-reload/config-watcher.d.ts +20 -0
- package/dist/hot-reload/config-watcher.js +58 -0
- package/dist/hot-reload/index.d.ts +12 -0
- package/dist/hot-reload/index.js +12 -0
- package/dist/hot-reload/manager.d.ts +58 -0
- package/dist/hot-reload/manager.js +243 -0
- package/dist/hot-reload/manifest-watcher.d.ts +9 -0
- package/dist/hot-reload/manifest-watcher.js +42 -0
- package/dist/hot-reload/mcp-watcher.d.ts +18 -0
- package/dist/hot-reload/mcp-watcher.js +64 -0
- package/dist/hot-reload/model-catalog-watcher.d.ts +18 -0
- package/dist/hot-reload/model-catalog-watcher.js +62 -0
- package/dist/hot-reload/plugin-watcher.d.ts +20 -0
- package/dist/hot-reload/plugin-watcher.js +56 -0
- package/dist/hot-reload/prompt-watcher.d.ts +6 -0
- package/dist/hot-reload/prompt-watcher.js +38 -0
- package/dist/hot-reload/provider-watcher.d.ts +16 -0
- package/dist/hot-reload/provider-watcher.js +45 -0
- package/dist/hot-reload/skill-watcher.d.ts +19 -0
- package/dist/hot-reload/skill-watcher.js +82 -0
- package/dist/hot-reload/tool-watcher.d.ts +16 -0
- package/dist/hot-reload/tool-watcher.js +168 -0
- package/dist/hot-reload/workflow-watcher.d.ts +19 -0
- package/dist/hot-reload/workflow-watcher.js +84 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/knowledge/fts5-retriever.d.ts +30 -0
- package/dist/knowledge/fts5-retriever.js +223 -0
- package/dist/knowledge/index.d.ts +11 -0
- package/dist/knowledge/index.js +14 -0
- package/dist/knowledge/indexer.d.ts +41 -0
- package/dist/knowledge/indexer.js +186 -0
- package/dist/knowledge/query-preprocessor.d.ts +13 -0
- package/dist/knowledge/query-preprocessor.js +63 -0
- package/dist/knowledge/retriever.d.ts +45 -0
- package/dist/knowledge/retriever.js +9 -0
- package/dist/knowledge/store.d.ts +27 -0
- package/dist/knowledge/store.js +61 -0
- package/dist/knowledge/structured-store.d.ts +78 -0
- package/dist/knowledge/structured-store.js +280 -0
- package/dist/knowledge/structured-tools.d.ts +12 -0
- package/dist/knowledge/structured-tools.js +151 -0
- package/dist/knowledge/tools.d.ts +20 -0
- package/dist/knowledge/tools.js +238 -0
- package/dist/knowledge/watcher.d.ts +28 -0
- package/dist/knowledge/watcher.js +113 -0
- package/dist/lifecycle/index.d.ts +12 -0
- package/dist/lifecycle/index.js +14 -0
- package/dist/lifecycle/interface.d.ts +94 -0
- package/dist/lifecycle/interface.js +2 -0
- package/dist/lifecycle/local-model.d.ts +62 -0
- package/dist/lifecycle/local-model.js +331 -0
- package/dist/lifecycle/manager.d.ts +70 -0
- package/dist/lifecycle/manager.js +374 -0
- package/dist/lifecycle/supervisor.d.ts +89 -0
- package/dist/lifecycle/supervisor.js +277 -0
- package/dist/lifecycle-integration-test.d.ts +2 -0
- package/dist/lifecycle-integration-test.js +72 -0
- package/dist/local-model/download-manager.d.ts +59 -0
- package/dist/local-model/download-manager.js +517 -0
- package/dist/local-model/index.d.ts +109 -0
- package/dist/local-model/index.js +233 -0
- package/dist/local-model/llamacpp-provider.d.ts +95 -0
- package/dist/local-model/llamacpp-provider.js +379 -0
- package/dist/local-model/model-bridge.d.ts +48 -0
- package/dist/local-model/model-bridge.js +256 -0
- package/dist/local-model/model-registry.d.ts +47 -0
- package/dist/local-model/model-registry.js +188 -0
- package/dist/local-model/types.d.ts +49 -0
- package/dist/local-model/types.js +2 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/logger.d.ts +56 -0
- package/dist/logging/logger.js +94 -0
- package/dist/machine/flows/bootstrap.d.ts +18 -0
- package/dist/machine/flows/bootstrap.js +119 -0
- package/dist/machine/flows/index.d.ts +6 -0
- package/dist/machine/flows/index.js +11 -0
- package/dist/machine/flows/spec.d.ts +17 -0
- package/dist/machine/flows/spec.js +176 -0
- package/dist/machine/flows/todo.d.ts +26 -0
- package/dist/machine/flows/todo.js +175 -0
- package/dist/machine/flows/tools.d.ts +8 -0
- package/dist/machine/flows/tools.js +119 -0
- package/dist/machine/flows/types.d.ts +33 -0
- package/dist/machine/flows/types.js +10 -0
- package/dist/machine/index.d.ts +8 -0
- package/dist/machine/index.js +9 -0
- package/dist/machine/registry.d.ts +34 -0
- package/dist/machine/registry.js +98 -0
- package/dist/machine/runner.d.ts +41 -0
- package/dist/machine/runner.js +177 -0
- package/dist/machine/types.d.ts +121 -0
- package/dist/machine/types.js +9 -0
- package/dist/mcp/bridge.d.ts +33 -0
- package/dist/mcp/bridge.js +99 -0
- package/dist/mcp/client.d.ts +37 -0
- package/dist/mcp/client.js +161 -0
- package/dist/mcp/config.d.ts +15 -0
- package/dist/mcp/config.js +85 -0
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.js +7 -0
- package/dist/mcp/install-manager.d.ts +31 -0
- package/dist/mcp/install-manager.js +158 -0
- package/dist/mcp/lifecycle.d.ts +41 -0
- package/dist/mcp/lifecycle.js +175 -0
- package/dist/mcp/process-transport.d.ts +21 -0
- package/dist/mcp/process-transport.js +59 -0
- package/dist/mcp/side-effect.d.ts +5 -0
- package/dist/mcp/side-effect.js +21 -0
- package/dist/mcp/system.d.ts +95 -0
- package/dist/mcp/system.js +279 -0
- package/dist/memory/companion-session.d.ts +22 -0
- package/dist/memory/companion-session.js +77 -0
- package/dist/memory/compression-boundary.d.ts +20 -0
- package/dist/memory/compression-boundary.js +40 -0
- package/dist/memory/conversation.d.ts +34 -0
- package/dist/memory/conversation.js +107 -0
- package/dist/memory/events.d.ts +42 -0
- package/dist/memory/events.js +56 -0
- package/dist/memory/index.d.ts +7 -0
- package/dist/memory/index.js +6 -0
- package/dist/memory/memory-store.d.ts +11 -0
- package/dist/memory/memory-store.js +51 -0
- package/dist/memory/session-allowlist.d.ts +11 -0
- package/dist/memory/session-allowlist.js +50 -0
- package/dist/memory/session.d.ts +48 -0
- package/dist/memory/session.js +275 -0
- package/dist/memory/stats.d.ts +23 -0
- package/dist/memory/stats.js +59 -0
- package/dist/memory/summary.d.ts +7 -0
- package/dist/memory/summary.js +23 -0
- package/dist/multimodal/index.d.ts +66 -0
- package/dist/multimodal/index.js +210 -0
- package/dist/orchestrator/index.d.ts +5 -0
- package/dist/orchestrator/index.js +4 -0
- package/dist/orchestrator/loop.d.ts +331 -0
- package/dist/orchestrator/loop.js +2443 -0
- package/dist/orchestrator/plan-store.d.ts +81 -0
- package/dist/orchestrator/plan-store.js +167 -0
- package/dist/orchestrator/planner.d.ts +20 -0
- package/dist/orchestrator/planner.js +34 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.js +2 -0
- package/dist/parser/router.d.ts +30 -0
- package/dist/parser/router.js +61 -0
- package/dist/plugins/api.d.ts +39 -0
- package/dist/plugins/api.js +85 -0
- package/dist/plugins/define.d.ts +27 -0
- package/dist/plugins/define.js +32 -0
- package/dist/plugins/index.d.ts +9 -0
- package/dist/plugins/index.js +5 -0
- package/dist/plugins/loader.d.ts +39 -0
- package/dist/plugins/loader.js +128 -0
- package/dist/plugins/manager.d.ts +61 -0
- package/dist/plugins/manager.js +257 -0
- package/dist/plugins/types.d.ts +82 -0
- package/dist/plugins/types.js +2 -0
- package/dist/prompts/agents/code-reviewer.md +16 -0
- package/dist/prompts/agents/security-auditor.md +17 -0
- package/dist/prompts/agents/test-writer.md +15 -0
- package/dist/prompts/attention/attention.md +12 -0
- package/dist/prompts/environment/environment.md +18 -0
- package/dist/prompts/environment/feishu.md +107 -0
- package/dist/prompts/flows/bootstrap-confirm.md +14 -0
- package/dist/prompts/flows/bootstrap-identity.md +11 -0
- package/dist/prompts/flows/bootstrap-soul.md +19 -0
- package/dist/prompts/flows/bootstrap-user.md +11 -0
- package/dist/prompts/flows/spec-checklist.md +27 -0
- package/dist/prompts/flows/spec-define.md +64 -0
- package/dist/prompts/flows/spec-executing-checklist.md +15 -0
- package/dist/prompts/flows/spec-executing-tasks.md +15 -0
- package/dist/prompts/flows/spec-spec.md +51 -0
- package/dist/prompts/flows/spec-tasks.md +32 -0
- package/dist/prompts/flows/todo-execution.md +7 -0
- package/dist/prompts/flows/todo-planning.md +18 -0
- package/dist/prompts/framework/architecture.md +131 -0
- package/dist/prompts/identity/identity.md +2 -0
- package/dist/prompts/loader.d.ts +24 -0
- package/dist/prompts/loader.js +102 -0
- package/dist/prompts/loader.ts +119 -0
- package/dist/prompts/orchestration/summary.md +14 -0
- package/dist/prompts/persona/BOOTSTRAP.md +5 -0
- package/dist/prompts/persona/IDENTITY.md +16 -0
- package/dist/prompts/persona/PartnerMemory.md +5 -0
- package/dist/prompts/persona/PartnerSoul.md +7 -0
- package/dist/prompts/persona/SOUL.md +30 -0
- package/dist/prompts/persona/USER.md +16 -0
- package/dist/prompts/precise/analyze.md +23 -0
- package/dist/prompts/precise/persona.md +18 -0
- package/dist/prompts/safety/coding-standards.md +5 -0
- package/dist/prompts/safety/safety.md +4 -0
- package/dist/prompts/skills/code-review.md +4 -0
- package/dist/prompts/skills/debug.md +7 -0
- package/dist/prompts/skills/framework-reference.md +131 -0
- package/dist/prompts/skills/refactor.md +6 -0
- package/dist/prompts/summary.md +22 -0
- package/dist/prompts/tools/framework-capabilities.md +241 -0
- package/dist/prompts/tools/tool-rules.md +15 -0
- package/dist/provider/anthropic.d.ts +62 -0
- package/dist/provider/anthropic.js +361 -0
- package/dist/provider/catalog.d.ts +58 -0
- package/dist/provider/catalog.js +97 -0
- package/dist/provider/compatible.d.ts +89 -0
- package/dist/provider/compatible.js +328 -0
- package/dist/provider/config.d.ts +23 -0
- package/dist/provider/config.js +158 -0
- package/dist/provider/deepseek.d.ts +25 -0
- package/dist/provider/deepseek.js +37 -0
- package/dist/provider/fallback.d.ts +51 -0
- package/dist/provider/fallback.js +113 -0
- package/dist/provider/gemini.d.ts +27 -0
- package/dist/provider/gemini.js +170 -0
- package/dist/provider/index.d.ts +36 -0
- package/dist/provider/index.js +42 -0
- package/dist/provider/interface.d.ts +62 -0
- package/dist/provider/interface.js +2 -0
- package/dist/provider/local-config.d.ts +37 -0
- package/dist/provider/local-config.js +146 -0
- package/dist/provider/local.d.ts +45 -0
- package/dist/provider/local.js +248 -0
- package/dist/provider/manager.d.ts +67 -0
- package/dist/provider/manager.js +355 -0
- package/dist/provider/mimo.d.ts +19 -0
- package/dist/provider/mimo.js +30 -0
- package/dist/provider/minimax.d.ts +22 -0
- package/dist/provider/minimax.js +33 -0
- package/dist/provider/model-catalog-loader.d.ts +42 -0
- package/dist/provider/model-catalog-loader.js +89 -0
- package/dist/provider/model-channel-registry.d.ts +130 -0
- package/dist/provider/model-channel-registry.js +488 -0
- package/dist/provider/model-router.d.ts +60 -0
- package/dist/provider/model-router.js +87 -0
- package/dist/provider/openai.d.ts +54 -0
- package/dist/provider/openai.js +274 -0
- package/dist/provider/qwen.d.ts +19 -0
- package/dist/provider/qwen.js +30 -0
- package/dist/provider/resilient.d.ts +46 -0
- package/dist/provider/resilient.js +181 -0
- package/dist/provider/retry.d.ts +16 -0
- package/dist/provider/retry.js +78 -0
- package/dist/provider/router.d.ts +68 -0
- package/dist/provider/router.js +145 -0
- package/dist/provider/tool-args-recovery.d.ts +36 -0
- package/dist/provider/tool-args-recovery.js +91 -0
- package/dist/provider/user-id.d.ts +13 -0
- package/dist/provider/user-id.js +53 -0
- package/dist/provider/zhipu.d.ts +19 -0
- package/dist/provider/zhipu.js +32 -0
- package/dist/registry/agent.registry.d.ts +57 -0
- package/dist/registry/agent.registry.js +224 -0
- package/dist/registry/base.d.ts +54 -0
- package/dist/registry/base.js +99 -0
- package/dist/registry/channel.registry.d.ts +53 -0
- package/dist/registry/channel.registry.js +87 -0
- package/dist/registry/index.d.ts +9 -0
- package/dist/registry/index.js +10 -0
- package/dist/registry/mcp.registry.d.ts +2 -0
- package/dist/registry/mcp.registry.js +2 -0
- package/dist/registry/plugin.registry.d.ts +33 -0
- package/dist/registry/plugin.registry.js +66 -0
- package/dist/registry/provider.registry.d.ts +51 -0
- package/dist/registry/provider.registry.js +104 -0
- package/dist/registry/skill.registry.d.ts +33 -0
- package/dist/registry/skill.registry.js +95 -0
- package/dist/registry/tool.registry.d.ts +68 -0
- package/dist/registry/tool.registry.js +185 -0
- package/dist/repair/loop-guard.d.ts +98 -0
- package/dist/repair/loop-guard.js +217 -0
- package/dist/repair/scavenge.d.ts +19 -0
- package/dist/repair/scavenge.js +81 -0
- package/dist/repair/storm.d.ts +7 -0
- package/dist/repair/storm.js +7 -0
- package/dist/rollback/index.d.ts +5 -0
- package/dist/rollback/index.js +4 -0
- package/dist/rollback/rollback-tool.d.ts +13 -0
- package/dist/rollback/rollback-tool.js +167 -0
- package/dist/rollback/turn-recorder.d.ts +37 -0
- package/dist/rollback/turn-recorder.js +183 -0
- package/dist/rollback/turn-store.d.ts +29 -0
- package/dist/rollback/turn-store.js +114 -0
- package/dist/rollback/types.d.ts +51 -0
- package/dist/rollback/types.js +9 -0
- package/dist/runtime/config-center.d.ts +92 -0
- package/dist/runtime/config-center.js +467 -0
- package/dist/runtime/config-schema.d.ts +201 -0
- package/dist/runtime/config-schema.js +2 -0
- package/dist/runtime/defaults.d.ts +3 -0
- package/dist/runtime/defaults.js +146 -0
- package/dist/schedule/cron.d.ts +24 -0
- package/dist/schedule/cron.js +145 -0
- package/dist/schedule/index.d.ts +6 -0
- package/dist/schedule/index.js +4 -0
- package/dist/schedule/persistence.d.ts +33 -0
- package/dist/schedule/persistence.js +106 -0
- package/dist/schedule/scheduler.d.ts +85 -0
- package/dist/schedule/scheduler.js +630 -0
- package/dist/schedule/types.d.ts +185 -0
- package/dist/schedule/types.js +2 -0
- package/dist/setup/config.d.ts +189 -0
- package/dist/setup/config.js +253 -0
- package/dist/setup/index.d.ts +3 -0
- package/dist/setup/index.js +3 -0
- package/dist/setup/model-defaults.d.ts +13 -0
- package/dist/setup/model-defaults.js +87 -0
- package/dist/setup/persona-bootstrap.d.ts +42 -0
- package/dist/setup/persona-bootstrap.js +379 -0
- package/dist/setup/wizard.d.ts +32 -0
- package/dist/setup/wizard.js +384 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +4 -0
- package/dist/skills/loader.d.ts +12 -0
- package/dist/skills/loader.js +83 -0
- package/dist/skills/registry.d.ts +2 -0
- package/dist/skills/registry.js +2 -0
- package/dist/skills/skill-tool.d.ts +20 -0
- package/dist/skills/skill-tool.js +49 -0
- package/dist/tools/archive.d.ts +17 -0
- package/dist/tools/archive.js +131 -0
- package/dist/tools/ask-user.d.ts +9 -0
- package/dist/tools/ask-user.js +62 -0
- package/dist/tools/background-registry.d.ts +45 -0
- package/dist/tools/background-registry.js +164 -0
- package/dist/tools/bash.d.ts +56 -0
- package/dist/tools/bash.js +391 -0
- package/dist/tools/bundle-registry.d.ts +42 -0
- package/dist/tools/bundle-registry.js +239 -0
- package/dist/tools/bundle-tools.d.ts +11 -0
- package/dist/tools/bundle-tools.js +168 -0
- package/dist/tools/channel-info.d.ts +5 -0
- package/dist/tools/channel-info.js +38 -0
- package/dist/tools/compression.d.ts +7 -0
- package/dist/tools/compression.js +21 -0
- package/dist/tools/config.d.ts +23 -0
- package/dist/tools/config.js +255 -0
- package/dist/tools/db-query.d.ts +12 -0
- package/dist/tools/db-query.js +107 -0
- package/dist/tools/diagnostics.d.ts +30 -0
- package/dist/tools/diagnostics.js +111 -0
- package/dist/tools/diff-channel.d.ts +9 -0
- package/dist/tools/diff-channel.js +17 -0
- package/dist/tools/diff-files.d.ts +17 -0
- package/dist/tools/diff-files.js +88 -0
- package/dist/tools/disk-usage.d.ts +34 -0
- package/dist/tools/disk-usage.js +258 -0
- package/dist/tools/edit.d.ts +30 -0
- package/dist/tools/edit.js +235 -0
- package/dist/tools/executor.d.ts +32 -0
- package/dist/tools/executor.js +66 -0
- package/dist/tools/file-tracker.d.ts +20 -0
- package/dist/tools/file-tracker.js +44 -0
- package/dist/tools/filtered-registry.d.ts +29 -0
- package/dist/tools/filtered-registry.js +50 -0
- package/dist/tools/flow.d.ts +10 -0
- package/dist/tools/flow.js +180 -0
- package/dist/tools/git-tool.d.ts +24 -0
- package/dist/tools/git-tool.js +113 -0
- package/dist/tools/glob.d.ts +29 -0
- package/dist/tools/glob.js +152 -0
- package/dist/tools/grep.d.ts +14 -0
- package/dist/tools/grep.js +325 -0
- package/dist/tools/http-request.d.ts +14 -0
- package/dist/tools/http-request.js +126 -0
- package/dist/tools/index.d.ts +43 -0
- package/dist/tools/index.js +76 -0
- package/dist/tools/injection-filter.d.ts +6 -0
- package/dist/tools/injection-filter.js +71 -0
- package/dist/tools/insert.d.ts +13 -0
- package/dist/tools/insert.js +61 -0
- package/dist/tools/interface.d.ts +30 -0
- package/dist/tools/interface.js +2 -0
- package/dist/tools/json-edit.d.ts +15 -0
- package/dist/tools/json-edit.js +122 -0
- package/dist/tools/multi-edit.d.ts +9 -0
- package/dist/tools/multi-edit.js +146 -0
- package/dist/tools/path-sandbox.d.ts +14 -0
- package/dist/tools/path-sandbox.js +60 -0
- package/dist/tools/process-tools.d.ts +15 -0
- package/dist/tools/process-tools.js +95 -0
- package/dist/tools/python-bridge/bridge.d.ts +24 -0
- package/dist/tools/python-bridge/bridge.js +39 -0
- package/dist/tools/python-bridge/executor.d.ts +6 -0
- package/dist/tools/python-bridge/executor.js +69 -0
- package/dist/tools/python-bridge/index.d.ts +5 -0
- package/dist/tools/python-bridge/index.js +4 -0
- package/dist/tools/python-bridge/parser.d.ts +21 -0
- package/dist/tools/python-bridge/parser.js +258 -0
- package/dist/tools/read.d.ts +16 -0
- package/dist/tools/read.js +276 -0
- package/dist/tools/registry.d.ts +2 -0
- package/dist/tools/registry.js +2 -0
- package/dist/tools/restart.d.ts +10 -0
- package/dist/tools/restart.js +46 -0
- package/dist/tools/result-buffer.d.ts +66 -0
- package/dist/tools/result-buffer.js +146 -0
- package/dist/tools/runtime-control.d.ts +163 -0
- package/dist/tools/runtime-control.js +1780 -0
- package/dist/tools/symbol-references.d.ts +5 -0
- package/dist/tools/symbol-references.js +331 -0
- package/dist/tools/system-info.d.ts +3 -0
- package/dist/tools/system-info.js +55 -0
- package/dist/tools/write.d.ts +18 -0
- package/dist/tools/write.js +118 -0
- package/dist/tools/xref/index.d.ts +25 -0
- package/dist/tools/xref/index.js +25 -0
- package/dist/tools/xref/manager.d.ts +85 -0
- package/dist/tools/xref/manager.js +948 -0
- package/dist/tools/xref/parser.d.ts +34 -0
- package/dist/tools/xref/parser.js +64 -0
- package/dist/tools/xref/regex-parser.d.ts +26 -0
- package/dist/tools/xref/regex-parser.js +446 -0
- package/dist/tools/xref/schema.d.ts +104 -0
- package/dist/tools/xref/schema.js +68 -0
- package/dist/tools/xref/ts-parser.d.ts +20 -0
- package/dist/tools/xref/ts-parser.js +403 -0
- package/dist/tools/xref/xref-build.d.ts +20 -0
- package/dist/tools/xref/xref-build.js +128 -0
- package/dist/tools/xref/xref-graph.d.ts +24 -0
- package/dist/tools/xref/xref-graph.js +88 -0
- package/dist/tools/xref/xref-query.d.ts +30 -0
- package/dist/tools/xref/xref-query.js +123 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.js +2 -0
- package/dist/ui/assistant-message.d.ts +7 -0
- package/dist/ui/assistant-message.js +18 -0
- package/dist/ui/chat-log.d.ts +52 -0
- package/dist/ui/chat-log.js +246 -0
- package/dist/ui/command-registry.d.ts +73 -0
- package/dist/ui/command-registry.js +838 -0
- package/dist/ui/diff-component.d.ts +14 -0
- package/dist/ui/diff-component.js +42 -0
- package/dist/ui/hyperlink-markdown.d.ts +10 -0
- package/dist/ui/hyperlink-markdown.js +21 -0
- package/dist/ui/markdown-message.d.ts +10 -0
- package/dist/ui/markdown-message.js +16 -0
- package/dist/ui/osc8-hyperlinks.d.ts +4 -0
- package/dist/ui/osc8-hyperlinks.js +142 -0
- package/dist/ui/pi-tui-editor.d.ts +35 -0
- package/dist/ui/pi-tui-editor.js +79 -0
- package/dist/ui/slash-commands.d.ts +16 -0
- package/dist/ui/slash-commands.js +29 -0
- package/dist/ui/slash-panel.d.ts +54 -0
- package/dist/ui/slash-panel.js +199 -0
- package/dist/ui/theme.d.ts +120 -0
- package/dist/ui/theme.js +154 -0
- package/dist/ui/tool-display.d.ts +13 -0
- package/dist/ui/tool-display.js +85 -0
- package/dist/ui/tool-execution.d.ts +22 -0
- package/dist/ui/tool-execution.js +87 -0
- package/dist/ui/tui-formatters.d.ts +2 -0
- package/dist/ui/tui-formatters.js +145 -0
- package/dist/ui/user-message.d.ts +5 -0
- package/dist/ui/user-message.js +11 -0
- package/dist/update/check.d.ts +8 -0
- package/dist/update/check.js +28 -0
- package/dist/update/config.d.ts +6 -0
- package/dist/update/config.js +18 -0
- package/dist/update/download.d.ts +3 -0
- package/dist/update/download.js +27 -0
- package/dist/update/index.d.ts +6 -0
- package/dist/update/index.js +5 -0
- package/dist/update/install.d.ts +3 -0
- package/dist/update/install.js +33 -0
- package/dist/update/types.d.ts +16 -0
- package/dist/update/types.js +2 -0
- package/dist/utils/diff.d.ts +9 -0
- package/dist/utils/diff.js +45 -0
- package/dist/utils/misc.d.ts +12 -0
- package/dist/utils/misc.js +34 -0
- package/dist/world-engine/agent.d.ts +41 -0
- package/dist/world-engine/agent.js +385 -0
- package/dist/world-engine/index.d.ts +45 -0
- package/dist/world-engine/index.js +160 -0
- package/dist/world-engine/sim.d.ts +14 -0
- package/dist/world-engine/sim.js +120 -0
- package/dist/world-engine/store.d.ts +110 -0
- package/dist/world-engine/store.js +519 -0
- package/dist/world-engine/ticker.d.ts +37 -0
- package/dist/world-engine/ticker.js +214 -0
- package/dist/world-engine/tools.d.ts +6 -0
- package/dist/world-engine/tools.js +380 -0
- package/dist/world-engine/types.d.ts +202 -0
- package/dist/world-engine/types.js +56 -0
- package/docs/api.md +180 -0
- package/docs/architecture.md +206 -0
- package/docs/diagnostics/2026-06-08-config-prompt-guidance.md +67 -0
- package/docs/superpowers/plans/2026-06-08-global-bootstrap-mode.md +89 -0
- package/docs/superpowers/specs/2026-06-08-global-bootstrap-mode-design.md +174 -0
- package/docs/user-guide.md +226 -0
- package/package.json +63 -0
- package/plugins/example-greeter/index.js +55 -0
- package/plugins/example-greeter/plugin.json +8 -0
- package/pnpm-workspace.yaml +5 -0
- package/provider_arch.md +179 -0
- package/start-webui.sh +27 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/webui-channel-design.md +789 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { TokenCounter, } from './tokenizer.js';
|
|
2
|
+
import { SystemPromptBuilder, } from './prompt-builder.js';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { getManifestLoader } from '../hot-reload/manifest-watcher.js';
|
|
5
|
+
import { NORMAL_PROFILE, getActiveRouter } from './profiles.js';
|
|
6
|
+
import { resolveSection } from './section-resolver.js';
|
|
7
|
+
import { getCacheStrategy } from './cache-strategy.js';
|
|
8
|
+
function formatTimestamp(date = new Date()) {
|
|
9
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
10
|
+
const y = date.getFullYear();
|
|
11
|
+
const m = pad(date.getMonth() + 1);
|
|
12
|
+
const d = pad(date.getDate());
|
|
13
|
+
const h = pad(date.getHours());
|
|
14
|
+
const min = pad(date.getMinutes());
|
|
15
|
+
return `${y}-${m}-${d} ${h}:${min}`;
|
|
16
|
+
}
|
|
17
|
+
/** 判断是否应跳过该历史消息 */
|
|
18
|
+
function shouldSkipHistoryMessage(msg) {
|
|
19
|
+
if (msg.role === 'system')
|
|
20
|
+
return true;
|
|
21
|
+
const blocks = Array.isArray(msg.content) ? msg.content : [msg.content];
|
|
22
|
+
if (blocks.every(b => b.type === 'thinking'))
|
|
23
|
+
return true;
|
|
24
|
+
// 跳过纯系统注入文本
|
|
25
|
+
if (blocks.every(b => b.type === 'text')) {
|
|
26
|
+
const text = blocks.map(b => b.text).join('\n');
|
|
27
|
+
if (text.startsWith('[Scheduled Task]') || text.startsWith('[System]'))
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
export class LayeredContextComposer {
|
|
33
|
+
promptBuilder;
|
|
34
|
+
tokenCounter;
|
|
35
|
+
sources = new Map();
|
|
36
|
+
/** 当前激活的条件(如 precise_mode)— 由策略设置 */
|
|
37
|
+
activeConditions = new Set();
|
|
38
|
+
persistentSections = [];
|
|
39
|
+
cwd;
|
|
40
|
+
constructor(maxContextTokens = 200000) {
|
|
41
|
+
this.promptBuilder = new SystemPromptBuilder();
|
|
42
|
+
this.tokenCounter = new TokenCounter();
|
|
43
|
+
this.cwd = process.cwd();
|
|
44
|
+
}
|
|
45
|
+
registerSource(source) {
|
|
46
|
+
this.sources.set(source.name, source);
|
|
47
|
+
}
|
|
48
|
+
unregisterSource(name) {
|
|
49
|
+
this.sources.delete(name);
|
|
50
|
+
}
|
|
51
|
+
getSource(name) {
|
|
52
|
+
return this.sources.get(name);
|
|
53
|
+
}
|
|
54
|
+
registerPromptSection(section) {
|
|
55
|
+
this.persistentSections.push(section);
|
|
56
|
+
}
|
|
57
|
+
clearPersistentSections() {
|
|
58
|
+
this.persistentSections = [];
|
|
59
|
+
}
|
|
60
|
+
async compose(options) {
|
|
61
|
+
this.cwd = options.cwd ?? process.cwd();
|
|
62
|
+
if (this.isLayeredOptions(options)) {
|
|
63
|
+
this.promptBuilder = new SystemPromptBuilder();
|
|
64
|
+
for (const section of this.persistentSections) {
|
|
65
|
+
this.promptBuilder.registerSection(section);
|
|
66
|
+
}
|
|
67
|
+
return this.composeCore(options);
|
|
68
|
+
}
|
|
69
|
+
const composeOpts = options;
|
|
70
|
+
this.promptBuilder = new SystemPromptBuilder();
|
|
71
|
+
for (const section of this.persistentSections) {
|
|
72
|
+
this.promptBuilder.registerSection(section);
|
|
73
|
+
}
|
|
74
|
+
this.promptBuilder.registerSection({
|
|
75
|
+
name: 'legacy_system_prompt',
|
|
76
|
+
priority: 0,
|
|
77
|
+
content: composeOpts.systemPrompt,
|
|
78
|
+
});
|
|
79
|
+
const layeredOptions = this.toLayeredOptions(composeOpts);
|
|
80
|
+
const result = await this.composeCore(layeredOptions);
|
|
81
|
+
return result.messages;
|
|
82
|
+
}
|
|
83
|
+
async composeLegacy(options) {
|
|
84
|
+
return this.compose(options);
|
|
85
|
+
}
|
|
86
|
+
buildResolverContext(options) {
|
|
87
|
+
return {
|
|
88
|
+
cwd: options.cwd,
|
|
89
|
+
tools: options.tools,
|
|
90
|
+
userInput: options.userInput,
|
|
91
|
+
timestamp: options.timestamp || formatTimestamp(),
|
|
92
|
+
historySummary: options.historySummary,
|
|
93
|
+
currentPlan: options.currentPlan,
|
|
94
|
+
impactInfo: options.impactInfo,
|
|
95
|
+
history: options.history,
|
|
96
|
+
fullHistory: options.fullHistory,
|
|
97
|
+
zone3Hashes: options.zone3Hashes,
|
|
98
|
+
maxContextTokens: options.maxContextTokens,
|
|
99
|
+
sources: this.sources,
|
|
100
|
+
selectedSkills: options.selectedSkills,
|
|
101
|
+
selectedAgents: options.selectedAgents,
|
|
102
|
+
gitManager: options.gitManager,
|
|
103
|
+
tokenCounter: this.tokenCounter,
|
|
104
|
+
activeConditions: this.activeConditions,
|
|
105
|
+
profile: options.profile ?? NORMAL_PROFILE,
|
|
106
|
+
router: getActiveRouter(),
|
|
107
|
+
bypassInjections: options.bypassInjections,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async composeCore(options) {
|
|
111
|
+
const manifestLoader = getManifestLoader(this.cwd);
|
|
112
|
+
const enabledZones = manifestLoader.getEnabledZones();
|
|
113
|
+
const allMessages = [];
|
|
114
|
+
const breakdown = {};
|
|
115
|
+
// 记录每个 Zone 的消息数,供缓存策略计算断点位置
|
|
116
|
+
const zoneMsgCounts = [];
|
|
117
|
+
const ctx = this.buildResolverContext(options);
|
|
118
|
+
for (const [zoneKey] of enabledZones) {
|
|
119
|
+
const result = await this.assembleZone(zoneKey, options, ctx);
|
|
120
|
+
allMessages.push(...result.messages);
|
|
121
|
+
breakdown[zoneKey] = result.tokens;
|
|
122
|
+
zoneMsgCounts.push({ key: zoneKey, msgCount: result.messages.length });
|
|
123
|
+
if (zoneKey === 'zone3') {
|
|
124
|
+
options.zone3Hashes = this.computeHashes(result.messages);
|
|
125
|
+
ctx.zone3Hashes = options.zone3Hashes;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// ── 缓存策略:根据 ProviderType 在 Zone 边界打 cache_control 断点 ──
|
|
129
|
+
if (options.providerType) {
|
|
130
|
+
const strategy = getCacheStrategy(options.providerType);
|
|
131
|
+
// 先清除旧标记(防止历史消息中残留其他 Provider 的 cache_control)
|
|
132
|
+
this.clearMarkers(allMessages);
|
|
133
|
+
if (strategy.shouldApplyMarkers()) {
|
|
134
|
+
const markers = strategy.computeMarkers({ zones: zoneMsgCounts });
|
|
135
|
+
this.applyMarkers(allMessages, markers);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const totalTokens = Object.values(breakdown).reduce((sum, t) => sum + t, 0);
|
|
139
|
+
const zoneBreakdown = { ...breakdown, total: totalTokens };
|
|
140
|
+
this.clearPromptBuilder();
|
|
141
|
+
return { messages: allMessages, zoneBreakdown };
|
|
142
|
+
}
|
|
143
|
+
async assembleZone(zoneKey, options, ctx) {
|
|
144
|
+
const manifestLoader = getManifestLoader(this.cwd);
|
|
145
|
+
const zone = manifestLoader.getZone(zoneKey);
|
|
146
|
+
if (!zone || !zone.enabled) {
|
|
147
|
+
return { messages: [], tokens: 0 };
|
|
148
|
+
}
|
|
149
|
+
const zoneRole = zone.role ?? 'user';
|
|
150
|
+
if (zoneRole === 'system') {
|
|
151
|
+
const sections = manifestLoader.getSections(zoneKey);
|
|
152
|
+
for (const sec of sections) {
|
|
153
|
+
if (this.promptBuilder.getSection(sec.name))
|
|
154
|
+
continue;
|
|
155
|
+
// conditional section 也需要解析——由 resolveConditional 根据 activeConditions 决定是否注入
|
|
156
|
+
if (sec.type === 'conditional') {
|
|
157
|
+
const content = await resolveSection(sec, ctx);
|
|
158
|
+
if (content) {
|
|
159
|
+
this.promptBuilder.registerSection({
|
|
160
|
+
name: sec.name,
|
|
161
|
+
priority: sec.priority,
|
|
162
|
+
content,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const content = await resolveSection(sec, ctx);
|
|
168
|
+
if (content) {
|
|
169
|
+
this.promptBuilder.registerSection({
|
|
170
|
+
name: sec.name,
|
|
171
|
+
priority: sec.priority,
|
|
172
|
+
content,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const systemPrompt = await this.promptBuilder.build();
|
|
177
|
+
if (!systemPrompt.trim()) {
|
|
178
|
+
return { messages: [], tokens: 0 };
|
|
179
|
+
}
|
|
180
|
+
const systemMessage = {
|
|
181
|
+
role: 'system',
|
|
182
|
+
content: { type: 'text', text: systemPrompt },
|
|
183
|
+
};
|
|
184
|
+
const tokens = this.tokenCounter.countMessageTokens(systemMessage);
|
|
185
|
+
return { messages: [systemMessage], tokens };
|
|
186
|
+
}
|
|
187
|
+
const sections = manifestLoader.getSections(zoneKey);
|
|
188
|
+
const messages = [];
|
|
189
|
+
const textParts = [];
|
|
190
|
+
const systemParts = [];
|
|
191
|
+
const flushTextParts = () => {
|
|
192
|
+
if (textParts.length > 0) {
|
|
193
|
+
messages.push({ role: zoneRole, content: { type: 'text', text: textParts.join('\n\n') } });
|
|
194
|
+
textParts.length = 0;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const flushSystemParts = () => {
|
|
198
|
+
if (systemParts.length > 0) {
|
|
199
|
+
messages.push({ role: 'system', content: { type: 'text', text: systemParts.join('\n\n') } });
|
|
200
|
+
systemParts.length = 0;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
for (const sec of sections) {
|
|
204
|
+
// runtime:history — 保持消息独立性(保留 role),跳过系统注入和 thinking
|
|
205
|
+
if (sec.source === 'runtime:history' && options.history && options.history.length > 0) {
|
|
206
|
+
flushSystemParts();
|
|
207
|
+
flushTextParts();
|
|
208
|
+
for (const msg of options.history) {
|
|
209
|
+
if (shouldSkipHistoryMessage(msg))
|
|
210
|
+
continue;
|
|
211
|
+
messages.push(msg);
|
|
212
|
+
}
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const content = await resolveSection(sec, ctx);
|
|
216
|
+
if (!content)
|
|
217
|
+
continue;
|
|
218
|
+
// Router 可按"本轮该 section 的实际来源"覆写 role(如陪伴模式世界旁白 → assistant 内心独白)
|
|
219
|
+
// 旁路Agent 注入也可指定 role
|
|
220
|
+
const bypassRole = ctx.bypassInjections?.find(ij => ij.section === sec.name)?.role;
|
|
221
|
+
const roleOverride = bypassRole ?? ctx.router.roleForSection?.(sec.name);
|
|
222
|
+
const sectionRole = (roleOverride ?? sec.role ?? zoneRole);
|
|
223
|
+
const zr = zoneRole; // widen to avoid TS narrowing
|
|
224
|
+
if (sectionRole === 'system' && zr !== 'system') {
|
|
225
|
+
// 系统消息独立累积,合并成一条 system message
|
|
226
|
+
flushTextParts();
|
|
227
|
+
systemParts.push(content);
|
|
228
|
+
}
|
|
229
|
+
else if (sectionRole !== zr) {
|
|
230
|
+
flushSystemParts();
|
|
231
|
+
flushTextParts();
|
|
232
|
+
messages.push({ role: sectionRole, content: { type: 'text', text: content } });
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
flushSystemParts();
|
|
236
|
+
textParts.push(content);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
flushSystemParts();
|
|
240
|
+
flushTextParts();
|
|
241
|
+
if (messages.length === 0) {
|
|
242
|
+
return { messages: [], tokens: 0 };
|
|
243
|
+
}
|
|
244
|
+
const tokens = this.tokenCounter.countMessagesTokens(messages);
|
|
245
|
+
return { messages, tokens };
|
|
246
|
+
}
|
|
247
|
+
// --- Helpers ---
|
|
248
|
+
clearPromptBuilder() {
|
|
249
|
+
const sections = this.promptBuilder.getAllSections();
|
|
250
|
+
for (const section of sections) {
|
|
251
|
+
this.promptBuilder.unregisterSection(section.name);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
isLayeredOptions(options) {
|
|
255
|
+
return 'sessionDir' in options;
|
|
256
|
+
}
|
|
257
|
+
computeHashes(messages) {
|
|
258
|
+
const hashes = new Set();
|
|
259
|
+
for (const msg of messages) {
|
|
260
|
+
const contentStr = JSON.stringify(msg.content);
|
|
261
|
+
hashes.add(createHash('md5').update(contentStr).digest('hex'));
|
|
262
|
+
}
|
|
263
|
+
return hashes;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 按策略计算出的断点位置,在消息的 TextContent 上打 cache_control 标记。
|
|
267
|
+
*
|
|
268
|
+
* 仅标记系统角色 (system/user) 的消息,跳过 assistant 角色。
|
|
269
|
+
* `cache_control` 放在消息的最后一个 TextContent block 上。
|
|
270
|
+
*/
|
|
271
|
+
/**
|
|
272
|
+
* 清除所有消息上的 cache_control 标记。
|
|
273
|
+
*
|
|
274
|
+
* 历史消息中可能残留之前 Anthropic session 的 cache_control,
|
|
275
|
+
* 当切换到 DeepSeek/OpenAI 等 auto-prefix Provider 时,必须清除。
|
|
276
|
+
*/
|
|
277
|
+
clearMarkers(messages) {
|
|
278
|
+
for (const msg of messages) {
|
|
279
|
+
if (msg.role === 'assistant')
|
|
280
|
+
continue;
|
|
281
|
+
const blocks = Array.isArray(msg.content) ? msg.content : [msg.content];
|
|
282
|
+
for (const block of blocks) {
|
|
283
|
+
if ('cache_control' in block) {
|
|
284
|
+
delete block.cache_control;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
applyMarkers(messages, markers) {
|
|
290
|
+
for (const marker of markers) {
|
|
291
|
+
const msg = messages[marker.index];
|
|
292
|
+
if (!msg || msg.role === 'assistant')
|
|
293
|
+
continue;
|
|
294
|
+
const blocks = Array.isArray(msg.content) ? msg.content : [msg.content];
|
|
295
|
+
// 从后往前找最后一个 TextContent block
|
|
296
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
297
|
+
if (blocks[i].type === 'text' || blocks[i].type === 'image') {
|
|
298
|
+
blocks[i].cache_control = {
|
|
299
|
+
type: 'ephemeral',
|
|
300
|
+
};
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
toLayeredOptions(options) {
|
|
307
|
+
return {
|
|
308
|
+
sessionDir: process.cwd(),
|
|
309
|
+
maxContextTokens: options.maxContextTokens,
|
|
310
|
+
cwd: process.cwd(),
|
|
311
|
+
timestamp: formatTimestamp(),
|
|
312
|
+
tools: options.tools,
|
|
313
|
+
history: options.history,
|
|
314
|
+
userInput: options.userInput,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=composer.js.map
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 差分压缩引擎 — Agent 框架的上下文压缩模块
|
|
3
|
+
*
|
|
4
|
+
* Phase 1: ToolOutputTrimmer — 无 LLM 调用的轻量压缩(规则裁剪)
|
|
5
|
+
* Phase 2: StructuredSummarizer — 首次结构化摘要(LLM 调用)
|
|
6
|
+
* Phase 3: StructuredSummarizer — 增量摘要更新(LLM 调用)
|
|
7
|
+
* Phase 4: 保护区规则裁剪 — 最终兜底(无 LLM 调用)
|
|
8
|
+
*
|
|
9
|
+
* 多轮迭代压缩:每轮按 token 比例动态分层,LLM 压缩最旧部分,
|
|
10
|
+
* 检查收敛后决定是否继续下一轮,最多 3 轮。
|
|
11
|
+
*/
|
|
12
|
+
import type { Message } from '../types.js';
|
|
13
|
+
import type { ModelRouter } from '../provider/model-router.js';
|
|
14
|
+
import type { GitManager } from '../evolution/git-manager.js';
|
|
15
|
+
/**
|
|
16
|
+
* Phase 1 压缩器 — 无需 LLM 调用,纯规则驱动的工具输出裁剪。
|
|
17
|
+
*/
|
|
18
|
+
export declare class ToolOutputTrimmer {
|
|
19
|
+
/** 最近 N 条消息中的工具结果保持原样 */
|
|
20
|
+
private trimWindow;
|
|
21
|
+
constructor(trimWindow?: number);
|
|
22
|
+
/**
|
|
23
|
+
* 裁剪旧工具结果:不在最近 N 条消息中的 ToolResultContent 替换为一行摘要。
|
|
24
|
+
*/
|
|
25
|
+
trimToolResults(messages: Message[]): Message[];
|
|
26
|
+
/**
|
|
27
|
+
* 去重连续的相同工具结果(MD5 匹配),仅保留最新,旧结果替换为引用。
|
|
28
|
+
*/
|
|
29
|
+
deduplicateToolResults(messages: Message[]): Message[];
|
|
30
|
+
/**
|
|
31
|
+
* 截断过大的 tool_call JSON:当 input 序列化后超过 maxJsonLength 时,
|
|
32
|
+
* 生成智能摘要(提取关键参数)而非一刀切截断字符串。
|
|
33
|
+
*/
|
|
34
|
+
truncateLargeToolCalls(messages: Message[], maxJsonLength?: number): Message[];
|
|
35
|
+
private static getCacheDir;
|
|
36
|
+
/** 将工具结果内容保存到缓存,返回引用 ID */
|
|
37
|
+
private saveToCache;
|
|
38
|
+
/** 为 ToolResultContent 生成一行摘要并缓存原始内容 */
|
|
39
|
+
private summarizeToolResult;
|
|
40
|
+
/** 根据工具结果内容推断工具名并生成摘要 + 缓存 */
|
|
41
|
+
private generateSummary;
|
|
42
|
+
/** 为大型 ToolUse input 生成智能摘要,提取关键参数。
|
|
43
|
+
*
|
|
44
|
+
* Write 工具特殊处理:提取函数/类签名、import、行数
|
|
45
|
+
* Edit 工具特殊处理:提取 old/new_string 首尾行、行数变化
|
|
46
|
+
* 其他工具:提取关键参数名
|
|
47
|
+
*/
|
|
48
|
+
private summarizeToolInput;
|
|
49
|
+
/** Write 工具:提取函数/类签名、import、行数 */
|
|
50
|
+
private summarizeWriteInput;
|
|
51
|
+
/** Edit 工具:提取 old/new_string 首尾行、行数变化 */
|
|
52
|
+
private summarizeEditInput;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 12 字段结构化摘要模板 — 用于 Phase 2/3 的 LLM 摘要生成。
|
|
56
|
+
*/
|
|
57
|
+
export declare const STRUCTURED_SUMMARY_TEMPLATE: string;
|
|
58
|
+
/**
|
|
59
|
+
* Phase 2-3 压缩器 — 使用 LLM 生成结构化摘要。
|
|
60
|
+
*/
|
|
61
|
+
export declare class StructuredSummarizer {
|
|
62
|
+
private modelRouter;
|
|
63
|
+
private compressDepth;
|
|
64
|
+
constructor(modelRouter: ModelRouter, options?: {
|
|
65
|
+
compressDepth?: number;
|
|
66
|
+
});
|
|
67
|
+
/** 运行时更新压缩深度 */
|
|
68
|
+
setCompressDepth(depth: number): void;
|
|
69
|
+
/** 根据 compressDepth 生成压缩策略提示词 */
|
|
70
|
+
private getDepthInstruction;
|
|
71
|
+
/**
|
|
72
|
+
* 生成结构化摘要。
|
|
73
|
+
*
|
|
74
|
+
* - 无 existingSummary → Phase 2(首次摘要),使用完整模板
|
|
75
|
+
* - 有 existingSummary → Phase 3(增量更新),基于前次摘要增量更新
|
|
76
|
+
*
|
|
77
|
+
* @param messages - 待压缩的历史消息
|
|
78
|
+
* @param existingSummary - 已有的摘要(增量压缩时传入)
|
|
79
|
+
* @param recentContext - 近期对话(不压缩,仅供 LLM 判断相关性,优先保留相关信息)
|
|
80
|
+
*/
|
|
81
|
+
summarize(messages: Message[], existingSummary?: string, recentContext?: Message[]): Promise<string>;
|
|
82
|
+
/** 将消息序列化为可读文本 */
|
|
83
|
+
private serializeMessages;
|
|
84
|
+
}
|
|
85
|
+
/** 压缩结果 */
|
|
86
|
+
export interface CompressionResult {
|
|
87
|
+
messages: Message[];
|
|
88
|
+
summary?: string;
|
|
89
|
+
phasesUsed: number[];
|
|
90
|
+
/** 本轮压缩覆盖的原始消息数量(输入消息数 - 返回消息数) */
|
|
91
|
+
compressedCount?: number;
|
|
92
|
+
}
|
|
93
|
+
/** 压缩统计 */
|
|
94
|
+
export interface CompressionStats {
|
|
95
|
+
totalTokens: number;
|
|
96
|
+
maxTokens: number;
|
|
97
|
+
usageRatio: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 压缩编排器 — 协调所有压缩阶段。
|
|
101
|
+
*/
|
|
102
|
+
export declare class CompressorOrchestrator {
|
|
103
|
+
#private;
|
|
104
|
+
private tokenizer;
|
|
105
|
+
private summarizer;
|
|
106
|
+
private maxContextTokens;
|
|
107
|
+
/** ToolOutputTrimmer 的窗口大小(规则裁剪时最近 N 条不处理) */
|
|
108
|
+
private trimWindow;
|
|
109
|
+
private safetyThreshold;
|
|
110
|
+
private targetRatio;
|
|
111
|
+
private compressThreshold;
|
|
112
|
+
/** 最大迭代轮数 */
|
|
113
|
+
private maxRounds;
|
|
114
|
+
/** 压缩激进程度 0.0~1.0 */
|
|
115
|
+
private compressDepth;
|
|
116
|
+
/** 当前压缩摘要内容 */
|
|
117
|
+
private _currentSummary;
|
|
118
|
+
constructor(tokenizer: {
|
|
119
|
+
countMessagesTokens(messages: Message[]): number;
|
|
120
|
+
}, summarizer: StructuredSummarizer, maxContextTokens: number, options?: {
|
|
121
|
+
trimWindow?: number;
|
|
122
|
+
safetyThreshold?: number;
|
|
123
|
+
targetRatio?: number;
|
|
124
|
+
compressThreshold?: number;
|
|
125
|
+
maxRounds?: number;
|
|
126
|
+
compressDepth?: number;
|
|
127
|
+
});
|
|
128
|
+
/**
|
|
129
|
+
* 执行多轮迭代压缩。
|
|
130
|
+
*
|
|
131
|
+
* 每轮按 token 比例动态分层,LLM 压缩最旧部分(Layer 3),
|
|
132
|
+
* 规则裁剪中间部分(Layer 2,仅第 1 轮),保留最新部分(Layer 1)。
|
|
133
|
+
* 每轮后检查是否收敛,未收敛则缩小保护区继续下一轮,最多 maxRounds 轮。
|
|
134
|
+
*
|
|
135
|
+
* @param protectLast - 保护最后 N 条消息不被压缩(用于 Zone 5 live tail),默认 0
|
|
136
|
+
* @param historyBudget - 压缩预算基准(token 数)。调用方应传入 maxContextTokens
|
|
137
|
+
* 或计算后的 history 可用空间。未传入时回退到 maxContextTokens。
|
|
138
|
+
*/
|
|
139
|
+
compress(messages: Message[], currentSummary: string | undefined, protectLast: number | undefined, historyBudget: number, options?: {
|
|
140
|
+
/** Git 管理器(热文件检测用) */
|
|
141
|
+
gitManager?: GitManager;
|
|
142
|
+
}): Promise<CompressionResult>;
|
|
143
|
+
/** 检查消息是否超过压缩阈值的最大上下文 token */
|
|
144
|
+
needsCompression(messages: Message[]): boolean;
|
|
145
|
+
/** 获取压缩统计信息 */
|
|
146
|
+
getCompressionStats(messages: Message[]): CompressionStats;
|
|
147
|
+
/**
|
|
148
|
+
* Update the compression threshold at runtime.
|
|
149
|
+
* This allows config changes to take effect without reconstruction.
|
|
150
|
+
*/
|
|
151
|
+
setCompressThreshold(threshold: number): void;
|
|
152
|
+
/**
|
|
153
|
+
* Update the compression depth at runtime.
|
|
154
|
+
* Delegates to StructuredSummarizer for prompt modulation.
|
|
155
|
+
*/
|
|
156
|
+
setCompressDepth(depth: number): void;
|
|
157
|
+
/**
|
|
158
|
+
* Get current compressDepth.
|
|
159
|
+
*/
|
|
160
|
+
getCompressDepth(): number;
|
|
161
|
+
/** 获取当前压缩摘要 */
|
|
162
|
+
get currentSummary(): string | undefined;
|
|
163
|
+
/** 获取当前使用比例 */
|
|
164
|
+
private getUsageRatio;
|
|
165
|
+
/**
|
|
166
|
+
* 按 token 比例动态分层:从消息末尾向前累加 token 数,切分为三层。
|
|
167
|
+
*
|
|
168
|
+
* @param ratios - 分层比例 { layer1: 最新保留比例, layer2: 中间规则层比例, layer3: 最旧 LLM 层比例 }
|
|
169
|
+
* 三者之和应为 1.0。layer2 为 0 表示跳过规则裁剪层。
|
|
170
|
+
* @returns { layer3, layer2, layer1 } 从最旧到最新排列
|
|
171
|
+
*/
|
|
172
|
+
private splitByTokenRatio;
|
|
173
|
+
/**
|
|
174
|
+
* 确保消息数组中不存在连续的 user 角色消息。
|
|
175
|
+
*
|
|
176
|
+
* 策略:如果连续两条 user 消息中,后一条含 tool_result,
|
|
177
|
+
* 则将后一条的 tool_result 合并到前一条 user 消息中(保持与 assistant(tool_calls) 的配对),
|
|
178
|
+
* 否则插入空 assistant 消息分隔。
|
|
179
|
+
*/
|
|
180
|
+
private ensureNoConsecutiveUserMessages;
|
|
181
|
+
/**
|
|
182
|
+
* 修复分层后 tool 消息的配对完整性。
|
|
183
|
+
* 如果 assistant 消息含 tool_use 被分到 layer3(将被摘要替代),
|
|
184
|
+
* 而对应的 tool_result 消息被分到 layer2/layer1,则会产生孤立 tool_result,
|
|
185
|
+
* 导致 API 报错 "Messages with role 'tool' must be a response to a preceding message with 'tool_calls'"。
|
|
186
|
+
*
|
|
187
|
+
* 修复策略:将孤立的 tool_result 消息降级为普通 user 文本消息,
|
|
188
|
+
* 保留其内容但移除 tool_result 结构。
|
|
189
|
+
*/
|
|
190
|
+
private fixOrphanedToolResults;
|
|
191
|
+
/**
|
|
192
|
+
* 全局 tool_result 完整性校验:确保最终输出中所有 tool_result
|
|
193
|
+
* 都有对应的 tool_use(assistant 消息中的 tool_calls)。
|
|
194
|
+
*
|
|
195
|
+
* 压缩后可能出现以下孤立场景:
|
|
196
|
+
* - layer3 整体被 LLM 摘要替代后,layer2/layer1 中残留的 tool_result
|
|
197
|
+
* 其对应的 tool_use 已随 layer3 一起消失
|
|
198
|
+
* - ensureNoConsecutiveUserMessages 插入空 assistant 后,
|
|
199
|
+
* tool_result 与 tool_use 之间可能被隔开
|
|
200
|
+
* - 多轮压缩迭代中,早期修复可能引入新的孤立
|
|
201
|
+
*
|
|
202
|
+
* 修复策略:将孤立 tool_result 降级为普通 user 文本消息
|
|
203
|
+
*/
|
|
204
|
+
private fixGlobalOrphanedToolResults;
|
|
205
|
+
/**
|
|
206
|
+
* 全局 tool_calls 完整性校验:确保每个 assistant 消息中的 tool_call
|
|
207
|
+
* 都有对应的 tool_result 消息紧跟其后。
|
|
208
|
+
*
|
|
209
|
+
* 压缩后可能出现的孤立场景:
|
|
210
|
+
* - assistant(tool_calls) 消息保留,但对应的 user(tool_result) 被压缩删掉
|
|
211
|
+
* - ensureNoConsecutiveUserMessages 合并消息时,tool_result 被移到其他位置
|
|
212
|
+
*
|
|
213
|
+
* 修复策略:从 assistant 消息中移除没有配对 tool_result 的 tool_calls。
|
|
214
|
+
* 如果移除后 assistant 消息只剩 tool_calls(无文本),则整体转为文本消息。
|
|
215
|
+
*/
|
|
216
|
+
private fixGlobalOrphanedToolCalls;
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=compressor.d.ts.map
|