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,519 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// world-engine / store — WorldStore
|
|
3
|
+
// ============================================================
|
|
4
|
+
//
|
|
5
|
+
// world.json 的读写层。纯数据,零 LLM,可独立测试。
|
|
6
|
+
//
|
|
7
|
+
// 并发模型:读并发、写串行。
|
|
8
|
+
// - 读(readEnvironment / getWorld)直接返回内存快照,永不阻塞。
|
|
9
|
+
// - 写(所有 mutate 方法)先改内存,再进队列顺序持久化。
|
|
10
|
+
// - 持久化用"写临时文件 + rename",保证磁盘上永远是完整文件。
|
|
11
|
+
//
|
|
12
|
+
// 目录布局(v0.9.6+:以角色名组织,一个角色一个世界):
|
|
13
|
+
// .agent/companion/<name>/world.json 世界状态
|
|
14
|
+
// .agent/companion/<name>/saves/*.json 存档快照
|
|
15
|
+
// ============================================================
|
|
16
|
+
import * as fs from 'fs/promises';
|
|
17
|
+
import * as path from 'path';
|
|
18
|
+
import * as os from 'os';
|
|
19
|
+
import { createEmptyWorld } from './types.js';
|
|
20
|
+
import { initSim } from './sim.js';
|
|
21
|
+
/** 最近事件保留条数(防 world.json 无限膨胀) */
|
|
22
|
+
const MAX_EVENTS = 30;
|
|
23
|
+
/** readEnvironment 返回的最近事件条数 */
|
|
24
|
+
const ENV_EVENT_LIMIT = 5;
|
|
25
|
+
/** 清掉某地点里与某物品相关的布局边(作为主体或参照物) */
|
|
26
|
+
function clearLayoutFor(loc, object) {
|
|
27
|
+
if (!loc.layout)
|
|
28
|
+
return;
|
|
29
|
+
loc.layout = loc.layout.filter(p => p.object !== object && p.anchor !== object);
|
|
30
|
+
}
|
|
31
|
+
export class WorldStore {
|
|
32
|
+
worldsDir;
|
|
33
|
+
characterName;
|
|
34
|
+
/** 内存中的当前世界快照(读的唯一来源) */
|
|
35
|
+
world = null;
|
|
36
|
+
/** 写队列:保证持久化顺序执行 */
|
|
37
|
+
writeQueue = Promise.resolve();
|
|
38
|
+
/**
|
|
39
|
+
* @param characterName 陪伴角色名(如"柔柔")——一个角色 = 一个世界。
|
|
40
|
+
* world.json 落在 ~/.agent/companion/<name>/world.json
|
|
41
|
+
*/
|
|
42
|
+
constructor(characterName) {
|
|
43
|
+
if (!characterName || characterName === 'default') {
|
|
44
|
+
throw new Error(`WorldStore: 拒绝保留名 "${characterName}",请使用正确的角色名`);
|
|
45
|
+
}
|
|
46
|
+
this.worldsDir = path.join(os.homedir(), '.agent', 'companion');
|
|
47
|
+
this.characterName = characterName;
|
|
48
|
+
}
|
|
49
|
+
// ── 路径(一个角色 = 一个世界,角色名即 worldId)──────
|
|
50
|
+
worldDir(id) {
|
|
51
|
+
return path.join(this.worldsDir, id);
|
|
52
|
+
}
|
|
53
|
+
worldFilePath(id) {
|
|
54
|
+
return path.join(this.worldDir(id), 'world.json');
|
|
55
|
+
}
|
|
56
|
+
// ── 加载 / 引导 ──────────────────────────────────────────
|
|
57
|
+
/**
|
|
58
|
+
* 加载活动世界到内存。若不存在则创建一个空世界并设为活动。
|
|
59
|
+
* @returns 当前内存中的世界
|
|
60
|
+
*/
|
|
61
|
+
/** @returns true 表示本次是新建的空世界(供调用方决定是否注入预设) */
|
|
62
|
+
async loadOrCreate(defaultName, now) {
|
|
63
|
+
const loaded = await this.readWorldFile(this.characterName);
|
|
64
|
+
if (loaded) {
|
|
65
|
+
// 修复旧数据:meta.id 可能与角色目录名不一致(如旧 bug 导致 id="default")
|
|
66
|
+
if (loaded.meta.id !== this.characterName) {
|
|
67
|
+
loaded.meta.id = this.characterName;
|
|
68
|
+
}
|
|
69
|
+
this.world = loaded;
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
this.world = createEmptyWorld(this.characterName, defaultName, now);
|
|
73
|
+
await fs.mkdir(this.worldDir(this.characterName), { recursive: true });
|
|
74
|
+
await this.persist();
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
async readWorldFile(id) {
|
|
78
|
+
try {
|
|
79
|
+
const raw = await fs.readFile(this.worldFilePath(id), 'utf-8');
|
|
80
|
+
const w = JSON.parse(raw);
|
|
81
|
+
if (!Array.isArray(w.relationships))
|
|
82
|
+
w.relationships = []; // 兼容旧文件
|
|
83
|
+
if (!w.simObjects || typeof w.simObjects !== 'object')
|
|
84
|
+
w.simObjects = {};
|
|
85
|
+
if (!w.customKinds || typeof w.customKinds !== 'object')
|
|
86
|
+
w.customKinds = {};
|
|
87
|
+
// 双地点迁移:旧文件只有 location(用户/场景),陪伴角色默认与其同地
|
|
88
|
+
if (typeof w.state.companionLocation !== 'string')
|
|
89
|
+
w.state.companionLocation = w.state.location ?? '';
|
|
90
|
+
// 身份补充迁移:旧文件无 characters overlay
|
|
91
|
+
if (!w.state.characters || typeof w.state.characters !== 'object')
|
|
92
|
+
w.state.characters = {};
|
|
93
|
+
return w;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** 列出所有世界 id */
|
|
100
|
+
async listWorlds() {
|
|
101
|
+
try {
|
|
102
|
+
const entries = await fs.readdir(this.worldsDir, { withFileTypes: true });
|
|
103
|
+
return entries.filter(e => e.isDirectory()).map(e => e.name);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// ── 读(并发安全,返回内存快照) ─────────────────────────
|
|
110
|
+
getWorld() {
|
|
111
|
+
return this.world;
|
|
112
|
+
}
|
|
113
|
+
/** 场景地点 = 陪伴角色所在地(narrate 服务于她);未设则回落用户地点 */
|
|
114
|
+
sceneLocation(w) {
|
|
115
|
+
return w.state.companionLocation || w.state.location;
|
|
116
|
+
}
|
|
117
|
+
/** 世界是否已"长出"可注入的内容(有场景地点且该地点存在) */
|
|
118
|
+
hasContent() {
|
|
119
|
+
const w = this.world;
|
|
120
|
+
if (!w)
|
|
121
|
+
return false;
|
|
122
|
+
const scene = this.sceneLocation(w);
|
|
123
|
+
return !!(scene && w.locations[scene]);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 组装当前地点的环境快照。
|
|
127
|
+
* 临近可见地点只带一层摘要(desc),绝不展开其 visible——防无限递归。
|
|
128
|
+
* @param mainCharacters 始终视为"在场"的角色名(主角/陪伴),用于筛选相关社会关系。
|
|
129
|
+
*/
|
|
130
|
+
readEnvironment(mainCharacters = []) {
|
|
131
|
+
const w = this.world;
|
|
132
|
+
if (!w)
|
|
133
|
+
return null;
|
|
134
|
+
const scene = this.sceneLocation(w); // 陪伴角色所在地
|
|
135
|
+
if (!scene)
|
|
136
|
+
return null;
|
|
137
|
+
const loc = w.locations[scene];
|
|
138
|
+
if (!loc)
|
|
139
|
+
return null;
|
|
140
|
+
// depth-1:仅取邻近可见地点的 desc 摘要,不再读它们的 visible
|
|
141
|
+
const visible = loc.visible
|
|
142
|
+
.filter(id => w.locations[id])
|
|
143
|
+
.map(id => ({ id, desc: w.locations[id].desc }));
|
|
144
|
+
const npcsHere = this.npcsAt(scene);
|
|
145
|
+
// 场景内角色 = 主角/陪伴(始终在场)+ 当前地点的 NPC
|
|
146
|
+
const inScene = new Set([...mainCharacters, ...npcsHere.map(n => n.id)]);
|
|
147
|
+
// 只取"双方都在当前场景"的关系——这才是当前地点的社交圈,也避免关系网变大后的性能开销
|
|
148
|
+
const relationships = w.relationships.filter(r => inScene.has(r.from) && inScene.has(r.to));
|
|
149
|
+
// 在场角色的身份补充(种族/别名/留痕),供旁白按规范名叠加渲染
|
|
150
|
+
const characters = {};
|
|
151
|
+
for (const name of inScene) {
|
|
152
|
+
if (w.state.characters[name])
|
|
153
|
+
characters[name] = w.state.characters[name];
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
location: scene,
|
|
157
|
+
userLocation: w.state.location,
|
|
158
|
+
userPresent: w.state.location === scene,
|
|
159
|
+
desc: loc.desc,
|
|
160
|
+
owner: loc.owner,
|
|
161
|
+
objects: loc.objects,
|
|
162
|
+
layout: loc.layout ?? [],
|
|
163
|
+
sceneOverrides: w.state.sceneOverrides,
|
|
164
|
+
ambient: w.ambient,
|
|
165
|
+
visible,
|
|
166
|
+
npcs: npcsHere,
|
|
167
|
+
relationships,
|
|
168
|
+
characters,
|
|
169
|
+
simObjects: Object.values(w.simObjects).filter(s => s.location === scene),
|
|
170
|
+
recentEvents: w.state.recentEvents.slice(-ENV_EVENT_LIMIT),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 当前在某地点的 NPC,带主标识 id。
|
|
175
|
+
* 【未来·用户↔NPC 交互】曾有"pin 优先于日常 location"的逻辑(剧情把 NPC 钉在某地),
|
|
176
|
+
* 因触发者已移除而清理;将来重做 NPC 交互时可在此恢复 pin 优先判断。
|
|
177
|
+
*/
|
|
178
|
+
npcsAt(locationId) {
|
|
179
|
+
const w = this.world;
|
|
180
|
+
if (!w)
|
|
181
|
+
return [];
|
|
182
|
+
return Object.entries(w.npcs)
|
|
183
|
+
.filter(([, npc]) => npc.location === locationId)
|
|
184
|
+
.map(([id, npc]) => ({ id, ...npc }));
|
|
185
|
+
}
|
|
186
|
+
// ── 写(先改内存,再串行持久化) ─────────────────────────
|
|
187
|
+
/** WorldTicker:更新环境 */
|
|
188
|
+
setAmbient(patch) {
|
|
189
|
+
return this.mutate(w => {
|
|
190
|
+
w.ambient = { ...w.ambient, ...patch };
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/** WorldTicker:放置 NPC 到某地点(跳过被 pin 的调用方自行判断) */
|
|
194
|
+
placeNpc(npcId, location) {
|
|
195
|
+
return this.mutate(w => {
|
|
196
|
+
const npc = w.npcs[npcId];
|
|
197
|
+
if (npc)
|
|
198
|
+
npc.location = location;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/** WorldAgent:创建/更新地点(对话中"长出来") */
|
|
202
|
+
upsertLocation(id, patch) {
|
|
203
|
+
return this.mutate(w => {
|
|
204
|
+
const prev = w.locations[id] ?? { desc: '', objects: [], visible: [], connects: [] };
|
|
205
|
+
w.locations[id] = {
|
|
206
|
+
desc: patch.desc ?? prev.desc,
|
|
207
|
+
objects: patch.objects ?? prev.objects,
|
|
208
|
+
visible: patch.visible ?? prev.visible,
|
|
209
|
+
connects: patch.connects ?? prev.connects,
|
|
210
|
+
owner: patch.owner ?? prev.owner,
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/** WorldAgent:创建 NPC,或后续丰富其信息(世界从对话中逐渐长细节) */
|
|
215
|
+
upsertNpc(id, patch) {
|
|
216
|
+
return this.mutate(w => {
|
|
217
|
+
const prev = w.npcs[id];
|
|
218
|
+
if (!prev) {
|
|
219
|
+
w.npcs[id] = {
|
|
220
|
+
desc: patch.desc ?? '',
|
|
221
|
+
aliases: patch.aliases ?? [],
|
|
222
|
+
race: patch.race,
|
|
223
|
+
note: patch.note,
|
|
224
|
+
persona: patch.persona ?? '',
|
|
225
|
+
home: patch.home ?? (patch.location ? [patch.location] : []),
|
|
226
|
+
roaming: patch.roaming ?? 0.1,
|
|
227
|
+
mobility: patch.mobility ?? 'anchored',
|
|
228
|
+
location: patch.location ?? (patch.home?.[0] ?? ''),
|
|
229
|
+
state: patch.state ?? '',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// 更新:所有字段都可后续丰富(了解越多、写得越细),只按传入的字段更新
|
|
234
|
+
if (patch.location !== undefined)
|
|
235
|
+
prev.location = patch.location;
|
|
236
|
+
if (patch.state !== undefined)
|
|
237
|
+
prev.state = patch.state;
|
|
238
|
+
if (patch.desc !== undefined)
|
|
239
|
+
prev.desc = patch.desc;
|
|
240
|
+
if (patch.persona !== undefined)
|
|
241
|
+
prev.persona = patch.persona;
|
|
242
|
+
if (patch.race !== undefined)
|
|
243
|
+
prev.race = patch.race; // 种族:属性,非身份
|
|
244
|
+
if (patch.note !== undefined)
|
|
245
|
+
prev.note = patch.note; // 认知留痕
|
|
246
|
+
if (patch.home !== undefined)
|
|
247
|
+
prev.home = patch.home;
|
|
248
|
+
if (patch.roaming !== undefined)
|
|
249
|
+
prev.roaming = patch.roaming;
|
|
250
|
+
if (patch.mobility !== undefined)
|
|
251
|
+
prev.mobility = patch.mobility;
|
|
252
|
+
if (patch.aliases?.length) {
|
|
253
|
+
prev.aliases = Array.from(new Set([...(prev.aliases ?? []), ...patch.aliases]));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/** WorldAgent:声明一个自定义动态类型(框架据此演化该类对象) */
|
|
259
|
+
defineKind(spec) {
|
|
260
|
+
return this.mutate(w => {
|
|
261
|
+
w.customKinds[spec.kind] = spec;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/** WorldAgent:生成一个框架维护的动态对象(雪/植物/计时器等) */
|
|
265
|
+
spawnSimObject(id, kind, location, desc, params) {
|
|
266
|
+
return this.mutate(w => {
|
|
267
|
+
// 不预设 amount,交给 initSim 按 kind(内置或自定义)设默认
|
|
268
|
+
const sim = { id, kind, location, desc, params };
|
|
269
|
+
initSim(sim, w.customKinds);
|
|
270
|
+
w.simObjects[id] = sim;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
/** WorldAgent:移除动态对象 */
|
|
274
|
+
removeSimObject(id) {
|
|
275
|
+
return this.mutate(w => {
|
|
276
|
+
delete w.simObjects[id];
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/** WorldAgent:设置物品的相对位置(object 在 anchor 的 relation 处),记在主角当前地点 */
|
|
280
|
+
placeObject(object, relation, anchor) {
|
|
281
|
+
return this.mutate(w => {
|
|
282
|
+
const loc = w.locations[this.sceneLocation(w)];
|
|
283
|
+
if (!loc)
|
|
284
|
+
return;
|
|
285
|
+
// 确保物品与参照物都在场
|
|
286
|
+
for (const name of [object, anchor]) {
|
|
287
|
+
if (name && !loc.objects.includes(name))
|
|
288
|
+
loc.objects.push(name);
|
|
289
|
+
}
|
|
290
|
+
if (!loc.layout)
|
|
291
|
+
loc.layout = [];
|
|
292
|
+
const existing = loc.layout.find(p => p.object === object);
|
|
293
|
+
if (existing) {
|
|
294
|
+
existing.relation = relation;
|
|
295
|
+
existing.anchor = anchor;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
loc.layout.push({ object, relation, anchor });
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* WorldAgent:把物体搬到另一个地点(静物或动态对象都适用)。
|
|
304
|
+
* 静物:从原地点的 objects 移除、加到目标地点;动态对象:改其 location。
|
|
305
|
+
* 搬动会清掉该物品在原地的相对位置(它不再在原来的柜子上了)。
|
|
306
|
+
*/
|
|
307
|
+
moveObject(object, to) {
|
|
308
|
+
return this.mutate(w => {
|
|
309
|
+
const sim = w.simObjects[object];
|
|
310
|
+
if (sim) {
|
|
311
|
+
sim.location = to;
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
for (const loc of Object.values(w.locations)) {
|
|
315
|
+
const i = loc.objects.indexOf(object);
|
|
316
|
+
if (i >= 0)
|
|
317
|
+
loc.objects.splice(i, 1);
|
|
318
|
+
clearLayoutFor(loc, object);
|
|
319
|
+
}
|
|
320
|
+
const target = w.locations[to];
|
|
321
|
+
if (target && !target.objects.includes(object))
|
|
322
|
+
target.objects.push(object);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/** WorldAgent:物体被消耗/用掉/毁坏而消失(静物或动态对象) */
|
|
326
|
+
removeObject(object) {
|
|
327
|
+
return this.mutate(w => {
|
|
328
|
+
if (w.simObjects[object]) {
|
|
329
|
+
delete w.simObjects[object];
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
for (const loc of Object.values(w.locations)) {
|
|
333
|
+
const i = loc.objects.indexOf(object);
|
|
334
|
+
if (i >= 0)
|
|
335
|
+
loc.objects.splice(i, 1);
|
|
336
|
+
clearLayoutFor(loc, object);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* WorldAgent:采摘植物类动态对象。
|
|
342
|
+
* 多茬生 → 成熟度归零重新生长;一茬生 → 直接消失。
|
|
343
|
+
*/
|
|
344
|
+
harvestSim(id) {
|
|
345
|
+
return this.mutate(w => {
|
|
346
|
+
const s = w.simObjects[id];
|
|
347
|
+
if (!s)
|
|
348
|
+
return;
|
|
349
|
+
const multi = s.params?.multiHarvest === true;
|
|
350
|
+
if (multi) {
|
|
351
|
+
s.amount = 0;
|
|
352
|
+
s.phase = '已采摘';
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
delete w.simObjects[id];
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/** Ticker 演化时用(在 batch 内直接改 world.simObjects,此处无需单独方法) */
|
|
360
|
+
// 对称关系类型:两人互为同一种关系,全自动去重
|
|
361
|
+
static SYMMETRIC = new Set([
|
|
362
|
+
'朋友', '好友', '恋人', '伴侣', '夫妻', '家人',
|
|
363
|
+
'同事', '同学', '熟人', '陌生人', '邻居', '室友',
|
|
364
|
+
]);
|
|
365
|
+
/** WorldAgent:创建/更新一条社会关系。对称关系全自动归一化——若同对已存在任一方向的条目则原地更新,保证一对人永远只保留一条。 */
|
|
366
|
+
setRelationship(from, to, type, note) {
|
|
367
|
+
return this.mutate(w => {
|
|
368
|
+
if (from === to)
|
|
369
|
+
return; // 自指跳过
|
|
370
|
+
if (WorldStore.SYMMETRIC.has(type)) {
|
|
371
|
+
// 对称关系:检查两个方向,找到就原地更新(不关心 from/to 顺序)
|
|
372
|
+
const existing = w.relationships.find(r => (r.from === from && r.to === to) || (r.from === to && r.to === from));
|
|
373
|
+
if (existing) {
|
|
374
|
+
existing.type = type;
|
|
375
|
+
if (note !== undefined)
|
|
376
|
+
existing.note = note;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
w.relationships.push({ from, to, type, note });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
// 有向关系:按精确方向匹配
|
|
384
|
+
const existing = w.relationships.find(r => r.from === from && r.to === to);
|
|
385
|
+
if (existing) {
|
|
386
|
+
existing.type = type;
|
|
387
|
+
if (note !== undefined)
|
|
388
|
+
existing.note = note;
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
w.relationships.push({ from, to, type, note });
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
/** WorldAgent:删除误建的重复角色条目(如把同一人的别名当成了独立角色)。 */
|
|
397
|
+
removeCharacter(name) {
|
|
398
|
+
return this.mutate(w => {
|
|
399
|
+
delete w.state.characters[name];
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
/** WorldAgent:创建/更新主角或陪伴角色的动态身份信息(种族/别名/留痕)。
|
|
403
|
+
* 以规范名(如 天角兽)为键;只增补、不覆盖已有配置——旁路补学到的种族/别名/来由。 */
|
|
404
|
+
setCharacter(name, info) {
|
|
405
|
+
return this.mutate(w => {
|
|
406
|
+
if (!w.state.characters[name])
|
|
407
|
+
w.state.characters[name] = {};
|
|
408
|
+
const c = w.state.characters[name];
|
|
409
|
+
if (info.race !== undefined)
|
|
410
|
+
c.race = info.race;
|
|
411
|
+
if (info.note !== undefined)
|
|
412
|
+
c.note = info.note;
|
|
413
|
+
if (info.aliases?.length) {
|
|
414
|
+
c.aliases = Array.from(new Set([...(c.aliases ?? []), ...info.aliases]));
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
/** WorldAgent:删除一条社会关系(建错的、或已结束的) */
|
|
419
|
+
removeRelationship(from, to) {
|
|
420
|
+
return this.mutate(w => {
|
|
421
|
+
w.relationships = w.relationships.filter(r => !(r.from === from && r.to === to));
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/** WorldAgent:删除误建的 NPC(如把主角/陪伴角色错建成了 NPC) */
|
|
425
|
+
removeNpc(id) {
|
|
426
|
+
return this.mutate(w => {
|
|
427
|
+
delete w.npcs[id];
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
/** WorldAgent:移动用户/主角当前地点(用户单独行动时) */
|
|
431
|
+
moveUser(location) {
|
|
432
|
+
return this.mutate(w => {
|
|
433
|
+
w.state.location = location;
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
/** WorldAgent:移动陪伴角色当前地点(她单独行动时;narrate 的场景以此为准) */
|
|
437
|
+
moveCompanion(location) {
|
|
438
|
+
return this.mutate(w => {
|
|
439
|
+
w.state.companionLocation = location;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
/** WorldAgent:两人一起移动(最常见)——同时更新用户与陪伴角色地点 */
|
|
443
|
+
moveBoth(location) {
|
|
444
|
+
return this.mutate(w => {
|
|
445
|
+
w.state.location = location;
|
|
446
|
+
w.state.companionLocation = location;
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
/** WorldAgent:设置/清除对环境的临时变更 */
|
|
450
|
+
setSceneOverride(key, value) {
|
|
451
|
+
return this.mutate(w => {
|
|
452
|
+
if (value === null)
|
|
453
|
+
delete w.state.sceneOverrides[key];
|
|
454
|
+
else
|
|
455
|
+
w.state.sceneOverrides[key] = value;
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
/** WorldAgent:追加事件(自动截断) */
|
|
459
|
+
addEvent(event) {
|
|
460
|
+
return this.mutate(w => {
|
|
461
|
+
w.state.recentEvents.push(event);
|
|
462
|
+
if (w.state.recentEvents.length > MAX_EVENTS) {
|
|
463
|
+
w.state.recentEvents = w.state.recentEvents.slice(-MAX_EVENTS);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
// 【未来·用户↔NPC 交互】此处曾有 pinNpc/unpinNpc(剧情钉住 NPC)、setPendingNpcResponse(待注入 NPC 回应),
|
|
468
|
+
// 因隔离 NPC 交互后无触发者,已作为死代码清理。重做 NPC 交互时在此重新添加相应写方法。
|
|
469
|
+
// ── 存档 ────────────────────────────────────────────────
|
|
470
|
+
async save(label) {
|
|
471
|
+
const w = this.world;
|
|
472
|
+
if (!w)
|
|
473
|
+
throw new Error('No active world to save.');
|
|
474
|
+
const savesDir = path.join(this.worldDir(w.meta.id), 'saves');
|
|
475
|
+
await fs.mkdir(savesDir, { recursive: true });
|
|
476
|
+
const file = path.join(savesDir, `${label}.json`);
|
|
477
|
+
await this.atomicWrite(file, JSON.stringify(w, null, 2));
|
|
478
|
+
return file;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* 批量修改:多处变更合并为一次持久化(供 WorldTicker 每次心跳使用)。
|
|
482
|
+
* 注意:绕过按方法的所有权约束,仅供受信任的内部模块调用。
|
|
483
|
+
*/
|
|
484
|
+
batch(fn) {
|
|
485
|
+
return this.mutate(fn);
|
|
486
|
+
}
|
|
487
|
+
// ── 内部:mutate + 持久化 ────────────────────────────────
|
|
488
|
+
mutate(fn) {
|
|
489
|
+
if (!this.world)
|
|
490
|
+
return Promise.resolve();
|
|
491
|
+
fn(this.world);
|
|
492
|
+
return this.persist();
|
|
493
|
+
}
|
|
494
|
+
/** 串行持久化当前内存世界 */
|
|
495
|
+
persist() {
|
|
496
|
+
const run = async () => {
|
|
497
|
+
const w = this.world;
|
|
498
|
+
if (!w)
|
|
499
|
+
return;
|
|
500
|
+
// 用 characterName(而非 w.meta.id)保证路径始终正确——meta.id 可能因旧数据迁移不一致
|
|
501
|
+
const file = this.worldFilePath(this.characterName);
|
|
502
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
503
|
+
await this.atomicWrite(file, JSON.stringify(w, null, 2));
|
|
504
|
+
};
|
|
505
|
+
this.writeQueue = this.writeQueue.then(run, run);
|
|
506
|
+
return this.writeQueue;
|
|
507
|
+
}
|
|
508
|
+
/** 写临时文件再 rename,保证磁盘上永远是完整文件 */
|
|
509
|
+
async atomicWrite(file, content) {
|
|
510
|
+
const tmp = `${file}.tmp`;
|
|
511
|
+
await fs.writeFile(tmp, content, 'utf-8');
|
|
512
|
+
await fs.rename(tmp, file);
|
|
513
|
+
}
|
|
514
|
+
/** 等待所有挂起的写完成(stop 时调用,确保落盘) */
|
|
515
|
+
async flush() {
|
|
516
|
+
await this.writeQueue;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { WorldStore } from './store.js';
|
|
2
|
+
export interface WorldTickerOptions {
|
|
3
|
+
/** 心跳间隔(毫秒),默认 5s */
|
|
4
|
+
heartbeatMs?: number;
|
|
5
|
+
/** 世界时间流速倍率:世界时间 = 现实流逝 × timeScale。默认 1(与现实时间 1:1 同步),>1 则世界更快 */
|
|
6
|
+
timeScale?: number;
|
|
7
|
+
/** 一种天气平均持续的【世界小时】数,默认 4(随 timeScale 自动缩放:1:1 时约 4 现实小时) */
|
|
8
|
+
weatherAvgHours?: number;
|
|
9
|
+
/** 降水前"阴天"需持续的【世界小时】数,默认 1.5(下雨前先阴一阵,符合现实) */
|
|
10
|
+
overcastHoursBeforeRain?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class WorldTicker {
|
|
13
|
+
private readonly store;
|
|
14
|
+
private readonly heartbeatMs;
|
|
15
|
+
private readonly timeScale;
|
|
16
|
+
private readonly weatherAvgHours;
|
|
17
|
+
private readonly overcastHoursBeforeRain;
|
|
18
|
+
private timer;
|
|
19
|
+
/** 当前天气已持续的【世界小时】数(用于"阴天酝酿够久才下雨",按世界时间而非心跳数计) */
|
|
20
|
+
private weatherDwellHours;
|
|
21
|
+
constructor(store: WorldStore, opts?: WorldTickerOptions);
|
|
22
|
+
/** 本次心跳流逝的世界小时数(= 现实流逝 × timeScale) */
|
|
23
|
+
private worldHoursPerTick;
|
|
24
|
+
start(): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
/** 单次推进(也可供测试直接调用) */
|
|
27
|
+
tick(now?: Date): void;
|
|
28
|
+
private evolveSimObjects;
|
|
29
|
+
private advanceTime;
|
|
30
|
+
/** 温度平滑趋近"季节基准+昼夜偏移"的目标,每次最多变 1 度,不突变 */
|
|
31
|
+
private driftTemperature;
|
|
32
|
+
private maybeChangeWeather;
|
|
33
|
+
private placeNpcs;
|
|
34
|
+
/** 从当前地点的相邻可达地点里挑一个(只走一步,不会瞬移到地图另一端) */
|
|
35
|
+
private pickRoamTarget;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=ticker.d.ts.map
|