@qlingzzy/qling 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +122 -0
- package/LICENSE +21 -0
- package/README.en.md +129 -0
- package/README.md +416 -0
- package/dist/agent/subtask.d.ts +21 -0
- package/dist/agent/subtask.d.ts.map +1 -0
- package/dist/agent/subtask.js +55 -0
- package/dist/agent-loop.d.ts +151 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent-loop.js +1498 -0
- package/dist/agents/isolation-policy.d.ts +14 -0
- package/dist/agents/isolation-policy.d.ts.map +1 -0
- package/dist/agents/isolation-policy.js +52 -0
- package/dist/channels/console-channel.d.ts +15 -0
- package/dist/channels/console-channel.d.ts.map +1 -0
- package/dist/channels/console-channel.js +66 -0
- package/dist/channels/registry.d.ts +10 -0
- package/dist/channels/registry.d.ts.map +1 -0
- package/dist/channels/registry.js +25 -0
- package/dist/channels/slack-channel.d.ts +35 -0
- package/dist/channels/slack-channel.d.ts.map +1 -0
- package/dist/channels/slack-channel.js +232 -0
- package/dist/channels/telegram-channel.d.ts +32 -0
- package/dist/channels/telegram-channel.d.ts.map +1 -0
- package/dist/channels/telegram-channel.js +167 -0
- package/dist/channels/types.d.ts +31 -0
- package/dist/channels/types.d.ts.map +1 -0
- package/dist/channels/types.js +4 -0
- package/dist/cli/bootstrap.d.ts +39 -0
- package/dist/cli/bootstrap.d.ts.map +1 -0
- package/dist/cli/bootstrap.js +138 -0
- package/dist/cli/channel-bootstrap.d.ts +23 -0
- package/dist/cli/channel-bootstrap.d.ts.map +1 -0
- package/dist/cli/channel-bootstrap.js +46 -0
- package/dist/cli/daemon-control.d.ts +31 -0
- package/dist/cli/daemon-control.d.ts.map +1 -0
- package/dist/cli/daemon-control.js +177 -0
- package/dist/cli/guidance-panel.d.ts +11 -0
- package/dist/cli/guidance-panel.d.ts.map +1 -0
- package/dist/cli/guidance-panel.js +16 -0
- package/dist/cli/mcp-control.d.ts +7 -0
- package/dist/cli/mcp-control.d.ts.map +1 -0
- package/dist/cli/mcp-control.js +119 -0
- package/dist/cli/mission-views.d.ts +13 -0
- package/dist/cli/mission-views.d.ts.map +1 -0
- package/dist/cli/mission-views.js +82 -0
- package/dist/cli/setup.d.ts +9 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +140 -0
- package/dist/cli/startup-contract.d.ts +23 -0
- package/dist/cli/startup-contract.d.ts.map +1 -0
- package/dist/cli/startup-contract.js +694 -0
- package/dist/commands/agents.d.ts +3 -0
- package/dist/commands/agents.d.ts.map +1 -0
- package/dist/commands/agents.js +44 -0
- package/dist/commands/checkpoint.d.ts +3 -0
- package/dist/commands/checkpoint.d.ts.map +1 -0
- package/dist/commands/checkpoint.js +52 -0
- package/dist/commands/claude-style.d.ts +12 -0
- package/dist/commands/claude-style.d.ts.map +1 -0
- package/dist/commands/claude-style.js +560 -0
- package/dist/commands/clear.d.ts +3 -0
- package/dist/commands/clear.d.ts.map +1 -0
- package/dist/commands/clear.js +20 -0
- package/dist/commands/compact.d.ts +3 -0
- package/dist/commands/compact.d.ts.map +1 -0
- package/dist/commands/compact.js +23 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +22 -0
- package/dist/commands/connect.d.ts +3 -0
- package/dist/commands/connect.d.ts.map +1 -0
- package/dist/commands/connect.js +102 -0
- package/dist/commands/context.d.ts +3 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +13 -0
- package/dist/commands/dashboard.d.ts +3 -0
- package/dist/commands/dashboard.d.ts.map +1 -0
- package/dist/commands/dashboard.js +22 -0
- package/dist/commands/detach.d.ts +3 -0
- package/dist/commands/detach.d.ts.map +1 -0
- package/dist/commands/detach.js +44 -0
- package/dist/commands/distill.d.ts +3 -0
- package/dist/commands/distill.d.ts.map +1 -0
- package/dist/commands/distill.js +23 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +13 -0
- package/dist/commands/dream.d.ts +3 -0
- package/dist/commands/dream.d.ts.map +1 -0
- package/dist/commands/dream.js +59 -0
- package/dist/commands/export.d.ts +3 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +18 -0
- package/dist/commands/exports.d.ts +3 -0
- package/dist/commands/exports.d.ts.map +1 -0
- package/dist/commands/exports.js +15 -0
- package/dist/commands/goal.d.ts +3 -0
- package/dist/commands/goal.d.ts.map +1 -0
- package/dist/commands/goal.js +147 -0
- package/dist/commands/help.d.ts +4 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +75 -0
- package/dist/commands/hooks.d.ts +3 -0
- package/dist/commands/hooks.d.ts.map +1 -0
- package/dist/commands/hooks.js +14 -0
- package/dist/commands/index.d.ts +29 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +417 -0
- package/dist/commands/knowledge.d.ts +8 -0
- package/dist/commands/knowledge.d.ts.map +1 -0
- package/dist/commands/knowledge.js +191 -0
- package/dist/commands/loop.d.ts +3 -0
- package/dist/commands/loop.d.ts.map +1 -0
- package/dist/commands/loop.js +138 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +57 -0
- package/dist/commands/memory.d.ts +3 -0
- package/dist/commands/memory.d.ts.map +1 -0
- package/dist/commands/memory.js +215 -0
- package/dist/commands/mission.d.ts +3 -0
- package/dist/commands/mission.d.ts.map +1 -0
- package/dist/commands/mission.js +129 -0
- package/dist/commands/permissions.d.ts +3 -0
- package/dist/commands/permissions.d.ts.map +1 -0
- package/dist/commands/permissions.js +82 -0
- package/dist/commands/privacy.d.ts +3 -0
- package/dist/commands/privacy.d.ts.map +1 -0
- package/dist/commands/privacy.js +13 -0
- package/dist/commands/recap.d.ts +3 -0
- package/dist/commands/recap.d.ts.map +1 -0
- package/dist/commands/recap.js +11 -0
- package/dist/commands/repomap.d.ts +3 -0
- package/dist/commands/repomap.d.ts.map +1 -0
- package/dist/commands/repomap.js +146 -0
- package/dist/commands/resume.d.ts +3 -0
- package/dist/commands/resume.d.ts.map +1 -0
- package/dist/commands/resume.js +42 -0
- package/dist/commands/runtime.d.ts +61 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +20 -0
- package/dist/commands/sessions.d.ts +3 -0
- package/dist/commands/sessions.d.ts.map +1 -0
- package/dist/commands/sessions.js +34 -0
- package/dist/commands/shortcuts.d.ts +3 -0
- package/dist/commands/shortcuts.d.ts.map +1 -0
- package/dist/commands/shortcuts.js +12 -0
- package/dist/commands/skill.d.ts +3 -0
- package/dist/commands/skill.d.ts.map +1 -0
- package/dist/commands/skill.js +20 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +31 -0
- package/dist/commands/statusline.d.ts +3 -0
- package/dist/commands/statusline.d.ts.map +1 -0
- package/dist/commands/statusline.js +40 -0
- package/dist/commands/storage.d.ts +3 -0
- package/dist/commands/storage.d.ts.map +1 -0
- package/dist/commands/storage.js +122 -0
- package/dist/commands/tasks.d.ts +3 -0
- package/dist/commands/tasks.d.ts.map +1 -0
- package/dist/commands/tasks.js +117 -0
- package/dist/commands/types.d.ts +14 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/verify.d.ts +3 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +86 -0
- package/dist/config-report.d.ts +35 -0
- package/dist/config-report.d.ts.map +1 -0
- package/dist/config-report.js +100 -0
- package/dist/config.d.ts +217 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +690 -0
- package/dist/context-compactor.d.ts +27 -0
- package/dist/context-compactor.d.ts.map +1 -0
- package/dist/context-compactor.js +489 -0
- package/dist/context-report.d.ts +35 -0
- package/dist/context-report.d.ts.map +1 -0
- package/dist/context-report.js +172 -0
- package/dist/daemon.d.ts +2 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +316 -0
- package/dist/dashboard-server.d.ts +18 -0
- package/dist/dashboard-server.d.ts.map +1 -0
- package/dist/dashboard-server.js +325 -0
- package/dist/discovery-registry.d.ts +28 -0
- package/dist/discovery-registry.d.ts.map +1 -0
- package/dist/discovery-registry.js +106 -0
- package/dist/discovery-types.d.ts +54 -0
- package/dist/discovery-types.d.ts.map +1 -0
- package/dist/discovery-types.js +5 -0
- package/dist/doctor.d.ts +31 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +343 -0
- package/dist/eval/runner.d.ts +10 -0
- package/dist/eval/runner.d.ts.map +1 -0
- package/dist/eval/runner.js +78 -0
- package/dist/eval/tasks.d.ts +3 -0
- package/dist/eval/tasks.d.ts.map +1 -0
- package/dist/eval/tasks.js +179 -0
- package/dist/eval/types.d.ts +31 -0
- package/dist/eval/types.d.ts.map +1 -0
- package/dist/eval/types.js +4 -0
- package/dist/git/auto-commit.d.ts +28 -0
- package/dist/git/auto-commit.d.ts.map +1 -0
- package/dist/git/auto-commit.js +112 -0
- package/dist/guard/approval.d.ts +16 -0
- package/dist/guard/approval.d.ts.map +1 -0
- package/dist/guard/approval.js +68 -0
- package/dist/guard/content-filter.d.ts +15 -0
- package/dist/guard/content-filter.d.ts.map +1 -0
- package/dist/guard/content-filter.js +102 -0
- package/dist/guard/permissions.d.ts +17 -0
- package/dist/guard/permissions.d.ts.map +1 -0
- package/dist/guard/permissions.js +54 -0
- package/dist/guard/rate-limit.d.ts +14 -0
- package/dist/guard/rate-limit.d.ts.map +1 -0
- package/dist/guard/rate-limit.js +47 -0
- package/dist/guard.d.ts +21 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +144 -0
- package/dist/help-topics.d.ts +19 -0
- package/dist/help-topics.d.ts.map +1 -0
- package/dist/help-topics.js +391 -0
- package/dist/hooks-report.d.ts +23 -0
- package/dist/hooks-report.d.ts.map +1 -0
- package/dist/hooks-report.js +44 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +4 -0
- package/dist/i18n/zh-cn.d.ts +180 -0
- package/dist/i18n/zh-cn.d.ts.map +1 -0
- package/dist/i18n/zh-cn.js +184 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1157 -0
- package/dist/knowledge-agent.d.ts +47 -0
- package/dist/knowledge-agent.d.ts.map +1 -0
- package/dist/knowledge-agent.js +320 -0
- package/dist/local-status-report.d.ts +23 -0
- package/dist/local-status-report.d.ts.map +1 -0
- package/dist/local-status-report.js +63 -0
- package/dist/local-storage-report.d.ts +32 -0
- package/dist/local-storage-report.d.ts.map +1 -0
- package/dist/local-storage-report.js +171 -0
- package/dist/mcp/bridge.d.ts +11 -0
- package/dist/mcp/bridge.d.ts.map +1 -0
- package/dist/mcp/bridge.js +37 -0
- package/dist/mcp/client.d.ts +26 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +209 -0
- package/dist/mcp/http-transport.d.ts +21 -0
- package/dist/mcp/http-transport.d.ts.map +1 -0
- package/dist/mcp/http-transport.js +126 -0
- package/dist/mcp/presets.d.ts +22 -0
- package/dist/mcp/presets.d.ts.map +1 -0
- package/dist/mcp/presets.js +80 -0
- package/dist/mcp/registry.d.ts +23 -0
- package/dist/mcp/registry.d.ts.map +1 -0
- package/dist/mcp/registry.js +85 -0
- package/dist/mcp/stdio-transport.d.ts +25 -0
- package/dist/mcp/stdio-transport.d.ts.map +1 -0
- package/dist/mcp/stdio-transport.js +92 -0
- package/dist/mcp/store.d.ts +41 -0
- package/dist/mcp/store.d.ts.map +1 -0
- package/dist/mcp/store.js +100 -0
- package/dist/mcp/types.d.ts +40 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +4 -0
- package/dist/mcp-report.d.ts +30 -0
- package/dist/mcp-report.d.ts.map +1 -0
- package/dist/mcp-report.js +104 -0
- package/dist/memory/cognitive-index.d.ts +56 -0
- package/dist/memory/cognitive-index.d.ts.map +1 -0
- package/dist/memory/cognitive-index.js +265 -0
- package/dist/memory/compactor.d.ts +28 -0
- package/dist/memory/compactor.d.ts.map +1 -0
- package/dist/memory/compactor.js +92 -0
- package/dist/memory/consolidation.d.ts +13 -0
- package/dist/memory/consolidation.d.ts.map +1 -0
- package/dist/memory/consolidation.js +77 -0
- package/dist/memory/embedding.d.ts +15 -0
- package/dist/memory/embedding.d.ts.map +1 -0
- package/dist/memory/embedding.js +59 -0
- package/dist/memory/memory-llm-dream.d.ts +3 -0
- package/dist/memory/memory-llm-dream.d.ts.map +1 -0
- package/dist/memory/memory-llm-dream.js +59 -0
- package/dist/memory/projection-worker.d.ts +30 -0
- package/dist/memory/projection-worker.d.ts.map +1 -0
- package/dist/memory/projection-worker.js +92 -0
- package/dist/memory/semantic-index.d.ts +18 -0
- package/dist/memory/semantic-index.d.ts.map +1 -0
- package/dist/memory/semantic-index.js +86 -0
- package/dist/memory/wal.d.ts +33 -0
- package/dist/memory/wal.d.ts.map +1 -0
- package/dist/memory/wal.js +131 -0
- package/dist/memory-report.d.ts +120 -0
- package/dist/memory-report.d.ts.map +1 -0
- package/dist/memory-report.js +726 -0
- package/dist/memory.d.ts +149 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +632 -0
- package/dist/metrics/agent-telemetry.d.ts +14 -0
- package/dist/metrics/agent-telemetry.d.ts.map +1 -0
- package/dist/metrics/agent-telemetry.js +44 -0
- package/dist/metrics/collector.d.ts +17 -0
- package/dist/metrics/collector.d.ts.map +1 -0
- package/dist/metrics/collector.js +137 -0
- package/dist/metrics/types.d.ts +14 -0
- package/dist/metrics/types.d.ts.map +1 -0
- package/dist/metrics/types.js +4 -0
- package/dist/mission/manager.d.ts +28 -0
- package/dist/mission/manager.d.ts.map +1 -0
- package/dist/mission/manager.js +208 -0
- package/dist/mission/types.d.ts +37 -0
- package/dist/mission/types.d.ts.map +1 -0
- package/dist/mission/types.js +5 -0
- package/dist/onboarding/tutorial.d.ts +33 -0
- package/dist/onboarding/tutorial.d.ts.map +1 -0
- package/dist/onboarding/tutorial.js +96 -0
- package/dist/output-style.d.ts +14 -0
- package/dist/output-style.d.ts.map +1 -0
- package/dist/output-style.js +29 -0
- package/dist/package-version.d.ts +12 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +42 -0
- package/dist/permissions-report.d.ts +42 -0
- package/dist/permissions-report.d.ts.map +1 -0
- package/dist/permissions-report.js +120 -0
- package/dist/pipeline/consistency-checker.d.ts +8 -0
- package/dist/pipeline/consistency-checker.d.ts.map +1 -0
- package/dist/pipeline/consistency-checker.js +40 -0
- package/dist/pipeline/example-generator.d.ts +4 -0
- package/dist/pipeline/example-generator.d.ts.map +1 -0
- package/dist/pipeline/example-generator.js +64 -0
- package/dist/pipeline/hooks.d.ts +68 -0
- package/dist/pipeline/hooks.d.ts.map +1 -0
- package/dist/pipeline/hooks.js +377 -0
- package/dist/pipeline/sections.d.ts +41 -0
- package/dist/pipeline/sections.d.ts.map +1 -0
- package/dist/pipeline/sections.js +244 -0
- package/dist/pipeline/verification.d.ts +12 -0
- package/dist/pipeline/verification.d.ts.map +1 -0
- package/dist/pipeline/verification.js +138 -0
- package/dist/privacy-report.d.ts +24 -0
- package/dist/privacy-report.d.ts.map +1 -0
- package/dist/privacy-report.js +78 -0
- package/dist/providers/presets.d.ts +25 -0
- package/dist/providers/presets.d.ts.map +1 -0
- package/dist/providers/presets.js +205 -0
- package/dist/recap.d.ts +38 -0
- package/dist/recap.d.ts.map +1 -0
- package/dist/recap.js +154 -0
- package/dist/repl.d.ts +41 -0
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +396 -0
- package/dist/runtime-paths.d.ts +32 -0
- package/dist/runtime-paths.d.ts.map +1 -0
- package/dist/runtime-paths.js +134 -0
- package/dist/sdk.d.ts +12 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +18 -0
- package/dist/session/daemon-session-api.d.ts +22 -0
- package/dist/session/daemon-session-api.d.ts.map +1 -0
- package/dist/session/daemon-session-api.js +48 -0
- package/dist/session/durable-session-supervisor.d.ts +24 -0
- package/dist/session/durable-session-supervisor.d.ts.map +1 -0
- package/dist/session/durable-session-supervisor.js +195 -0
- package/dist/session/goal-controller.d.ts +43 -0
- package/dist/session/goal-controller.d.ts.map +1 -0
- package/dist/session/goal-controller.js +77 -0
- package/dist/session/goal-evaluator.d.ts +29 -0
- package/dist/session/goal-evaluator.d.ts.map +1 -0
- package/dist/session/goal-evaluator.js +100 -0
- package/dist/session/loop-prompt.d.ts +14 -0
- package/dist/session/loop-prompt.d.ts.map +1 -0
- package/dist/session/loop-prompt.js +49 -0
- package/dist/session/session-goal-manager.d.ts +51 -0
- package/dist/session/session-goal-manager.d.ts.map +1 -0
- package/dist/session/session-goal-manager.js +118 -0
- package/dist/session/session-registry.d.ts +40 -0
- package/dist/session/session-registry.d.ts.map +1 -0
- package/dist/session/session-registry.js +124 -0
- package/dist/session/session-scheduler.d.ts +59 -0
- package/dist/session/session-scheduler.d.ts.map +1 -0
- package/dist/session/session-scheduler.js +170 -0
- package/dist/session-checkpoint-report.d.ts +22 -0
- package/dist/session-checkpoint-report.d.ts.map +1 -0
- package/dist/session-checkpoint-report.js +99 -0
- package/dist/session-export-index.d.ts +23 -0
- package/dist/session-export-index.d.ts.map +1 -0
- package/dist/session-export-index.js +96 -0
- package/dist/session-export.d.ts +28 -0
- package/dist/session-export.d.ts.map +1 -0
- package/dist/session-export.js +99 -0
- package/dist/session-goal-report.d.ts +37 -0
- package/dist/session-goal-report.d.ts.map +1 -0
- package/dist/session-goal-report.js +219 -0
- package/dist/session-list-report.d.ts +16 -0
- package/dist/session-list-report.d.ts.map +1 -0
- package/dist/session-list-report.js +60 -0
- package/dist/session-task-report.d.ts +23 -0
- package/dist/session-task-report.d.ts.map +1 -0
- package/dist/session-task-report.js +183 -0
- package/dist/shortcuts.d.ts +2 -0
- package/dist/shortcuts.d.ts.map +1 -0
- package/dist/shortcuts.js +32 -0
- package/dist/skills/registry.d.ts +8 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +119 -0
- package/dist/skills/types.d.ts +7 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +4 -0
- package/dist/statusline.d.ts +37 -0
- package/dist/statusline.d.ts.map +1 -0
- package/dist/statusline.js +207 -0
- package/dist/tools/bash.d.ts +10 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +278 -0
- package/dist/tools/browser-fetch.d.ts +7 -0
- package/dist/tools/browser-fetch.d.ts.map +1 -0
- package/dist/tools/browser-fetch.js +133 -0
- package/dist/tools/error-utils.d.ts +9 -0
- package/dist/tools/error-utils.d.ts.map +1 -0
- package/dist/tools/error-utils.js +35 -0
- package/dist/tools/index.d.ts +27 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +86 -0
- package/dist/tools/patch.d.ts +22 -0
- package/dist/tools/patch.d.ts.map +1 -0
- package/dist/tools/patch.js +458 -0
- package/dist/tools/planner.d.ts +7 -0
- package/dist/tools/planner.d.ts.map +1 -0
- package/dist/tools/planner.js +148 -0
- package/dist/tools/read.d.ts +8 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +114 -0
- package/dist/tools/search.d.ts +11 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +636 -0
- package/dist/tools/skill.d.ts +8 -0
- package/dist/tools/skill.d.ts.map +1 -0
- package/dist/tools/skill.js +181 -0
- package/dist/tools/subtask.d.ts +9 -0
- package/dist/tools/subtask.d.ts.map +1 -0
- package/dist/tools/subtask.js +120 -0
- package/dist/tools/todo.d.ts +8 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +170 -0
- package/dist/tools/url-fetch.d.ts +11 -0
- package/dist/tools/url-fetch.d.ts.map +1 -0
- package/dist/tools/url-fetch.js +208 -0
- package/dist/tools/vision-analyze.d.ts +9 -0
- package/dist/tools/vision-analyze.d.ts.map +1 -0
- package/dist/tools/vision-analyze.js +179 -0
- package/dist/tools/write.d.ts +7 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +128 -0
- package/dist/tui/chrome.d.ts +7 -0
- package/dist/tui/chrome.d.ts.map +1 -0
- package/dist/tui/chrome.js +22 -0
- package/dist/tui/input-buffer.d.ts +37 -0
- package/dist/tui/input-buffer.d.ts.map +1 -0
- package/dist/tui/input-buffer.js +228 -0
- package/dist/tui/input-history.d.ts +11 -0
- package/dist/tui/input-history.d.ts.map +1 -0
- package/dist/tui/input-history.js +69 -0
- package/dist/tui/input-queue.d.ts +27 -0
- package/dist/tui/input-queue.d.ts.map +1 -0
- package/dist/tui/input-queue.js +85 -0
- package/dist/tui/markdown.d.ts +10 -0
- package/dist/tui/markdown.d.ts.map +1 -0
- package/dist/tui/markdown.js +396 -0
- package/dist/tui/progress.d.ts +3 -0
- package/dist/tui/progress.d.ts.map +1 -0
- package/dist/tui/progress.js +13 -0
- package/dist/tui/shell.d.ts +67 -0
- package/dist/tui/shell.d.ts.map +1 -0
- package/dist/tui/shell.js +271 -0
- package/dist/tui/streaming-repl.d.ts +39 -0
- package/dist/tui/streaming-repl.d.ts.map +1 -0
- package/dist/tui/streaming-repl.js +460 -0
- package/dist/tui/streaming-tui.d.ts +174 -0
- package/dist/tui/streaming-tui.d.ts.map +1 -0
- package/dist/tui/streaming-tui.js +1049 -0
- package/dist/types.d.ts +221 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +37 -0
- package/dist/utils/symbol-extractor.d.ts +8 -0
- package/dist/utils/symbol-extractor.d.ts.map +1 -0
- package/dist/utils/symbol-extractor.js +190 -0
- package/dist/workflow-runtime.d.ts +45 -0
- package/dist/workflow-runtime.d.ts.map +1 -0
- package/dist/workflow-runtime.js +146 -0
- package/dist/workflow-types.d.ts +73 -0
- package/dist/workflow-types.d.ts.map +1 -0
- package/dist/workflow-types.js +34 -0
- package/docs/docker.md +66 -0
- package/docs/install.md +159 -0
- package/docs/sdk.md +67 -0
- package/docs/skills.md +51 -0
- package/package.json +102 -0
- package/scripts/bootstrap.mjs +63 -0
- package/scripts/check_image.ps1 +18 -0
- package/scripts/clean-dist.mjs +18 -0
- package/scripts/copy_image.ps1 +5 -0
- package/scripts/eval-smoke.mjs +17 -0
- package/skills/examples/repo-triage/SKILL.md +50 -0
- package/skills/qling.md +42 -0
- package/skills/templates/SKILL.md +37 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Cognitive Index (v0.5)
|
|
3
|
+
// 结合向量、图谱与经验蒸馏的综合认知引擎
|
|
4
|
+
// ============================================================
|
|
5
|
+
import Database from "better-sqlite3";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import * as fs from "fs/promises";
|
|
8
|
+
import { existsSync } from "fs";
|
|
9
|
+
export class CognitiveIndex {
|
|
10
|
+
db;
|
|
11
|
+
dbPath;
|
|
12
|
+
constructor(memoryDir) {
|
|
13
|
+
this.dbPath = path.join(memoryDir, "cognitive_knowledge.db");
|
|
14
|
+
}
|
|
15
|
+
async init() {
|
|
16
|
+
const dir = path.dirname(this.dbPath);
|
|
17
|
+
if (!existsSync(dir)) {
|
|
18
|
+
await fs.mkdir(dir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
this.db = new Database(this.dbPath);
|
|
21
|
+
this.db.pragma("journal_mode = WAL");
|
|
22
|
+
this.db.pragma("synchronous = NORMAL");
|
|
23
|
+
// 1. 向量存储表
|
|
24
|
+
this.db.exec(`
|
|
25
|
+
CREATE TABLE IF NOT EXISTS embeddings (
|
|
26
|
+
id TEXT PRIMARY KEY,
|
|
27
|
+
content TEXT NOT NULL,
|
|
28
|
+
vector BLOB NOT NULL,
|
|
29
|
+
metadata TEXT,
|
|
30
|
+
created_at INTEGER NOT NULL
|
|
31
|
+
)
|
|
32
|
+
`);
|
|
33
|
+
// 2. 知识图谱表 (Entity-Relation-Entity)
|
|
34
|
+
this.db.exec(`
|
|
35
|
+
CREATE TABLE IF NOT EXISTS kg_nodes (
|
|
36
|
+
id TEXT PRIMARY KEY,
|
|
37
|
+
type TEXT NOT NULL, -- task, file, command, technology
|
|
38
|
+
label TEXT NOT NULL,
|
|
39
|
+
metadata TEXT,
|
|
40
|
+
last_seen INTEGER NOT NULL
|
|
41
|
+
);
|
|
42
|
+
CREATE TABLE IF NOT EXISTS kg_edges (
|
|
43
|
+
source TEXT NOT NULL,
|
|
44
|
+
target TEXT NOT NULL,
|
|
45
|
+
relation TEXT NOT NULL, -- uses, writes, reads, part_of
|
|
46
|
+
weight REAL DEFAULT 1.0,
|
|
47
|
+
PRIMARY KEY (source, target, relation)
|
|
48
|
+
);
|
|
49
|
+
`);
|
|
50
|
+
// 3. 经验蒸馏表 (Best Practices)
|
|
51
|
+
this.db.exec(`
|
|
52
|
+
CREATE TABLE IF NOT EXISTS distilled_practices (
|
|
53
|
+
id TEXT PRIMARY KEY,
|
|
54
|
+
task_pattern TEXT UNIQUE NOT NULL,
|
|
55
|
+
action_json TEXT NOT NULL, -- 成功执行的指令序列
|
|
56
|
+
context_json TEXT NOT NULL, -- 涉及的文件与前置条件
|
|
57
|
+
confidence REAL DEFAULT 1.0,
|
|
58
|
+
hit_count INTEGER DEFAULT 1,
|
|
59
|
+
created_at INTEGER NOT NULL
|
|
60
|
+
)
|
|
61
|
+
`);
|
|
62
|
+
// Ensure existing tables enforce the unique index on task_pattern
|
|
63
|
+
try {
|
|
64
|
+
this.db.exec(`
|
|
65
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_distilled_practices_task_pattern ON distilled_practices(task_pattern);
|
|
66
|
+
`);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
console.warn("[CognitiveIndex] Failed to create unique index, attempting deduplication:", err.message);
|
|
70
|
+
try {
|
|
71
|
+
this.db.exec(`
|
|
72
|
+
DELETE FROM distilled_practices
|
|
73
|
+
WHERE id NOT IN (
|
|
74
|
+
SELECT MIN(id) FROM distilled_practices GROUP BY task_pattern
|
|
75
|
+
);
|
|
76
|
+
`);
|
|
77
|
+
this.db.exec(`
|
|
78
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_distilled_practices_task_pattern ON distilled_practices(task_pattern);
|
|
79
|
+
`);
|
|
80
|
+
}
|
|
81
|
+
catch (dedupErr) {
|
|
82
|
+
console.error("[CognitiveIndex] Deduplication and index migration failed:", dedupErr.message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// --- 向量操作 ---
|
|
87
|
+
upsertVector(entry, vector) {
|
|
88
|
+
const vectorBuffer = Buffer.from(new Float32Array(vector).buffer);
|
|
89
|
+
const stmt = this.db.prepare(`
|
|
90
|
+
INSERT INTO embeddings (id, content, vector, metadata, created_at)
|
|
91
|
+
VALUES (?, ?, ?, ?, ?)
|
|
92
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
93
|
+
content = excluded.content,
|
|
94
|
+
vector = excluded.vector,
|
|
95
|
+
metadata = excluded.metadata
|
|
96
|
+
`);
|
|
97
|
+
stmt.run(entry.id, entry.content, vectorBuffer, JSON.stringify({ source: entry.source, importance: entry.importance }), entry.createdAt);
|
|
98
|
+
}
|
|
99
|
+
searchVector(queryVector, limit = 10) {
|
|
100
|
+
const all = this.db.prepare("SELECT * FROM embeddings").all();
|
|
101
|
+
const results = [];
|
|
102
|
+
for (const row of all) {
|
|
103
|
+
const vector = Array.from(new Float32Array(row.vector.buffer, row.vector.byteOffset, row.vector.byteLength / 4));
|
|
104
|
+
const score = this.cosineSimilarity(queryVector, vector);
|
|
105
|
+
const metadata = JSON.parse(row.metadata || "{}");
|
|
106
|
+
results.push({
|
|
107
|
+
entry: {
|
|
108
|
+
id: row.id,
|
|
109
|
+
content: row.content,
|
|
110
|
+
source: metadata.source || "unknown",
|
|
111
|
+
importance: metadata.importance || 0.5,
|
|
112
|
+
createdAt: row.created_at,
|
|
113
|
+
},
|
|
114
|
+
score,
|
|
115
|
+
source: "vector",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return results.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
119
|
+
}
|
|
120
|
+
// --- 知识图谱操作 ---
|
|
121
|
+
link(source, relation, target) {
|
|
122
|
+
const upsertNode = this.db.prepare(`
|
|
123
|
+
INSERT INTO kg_nodes (id, type, label, last_seen)
|
|
124
|
+
VALUES (?, ?, ?, ?)
|
|
125
|
+
ON CONFLICT(id) DO UPDATE SET last_seen = excluded.last_seen
|
|
126
|
+
`);
|
|
127
|
+
const upsertEdge = this.db.prepare(`
|
|
128
|
+
INSERT INTO kg_edges (source, target, relation, weight)
|
|
129
|
+
VALUES (?, ?, ?, 1.0)
|
|
130
|
+
ON CONFLICT(source, target, relation) DO UPDATE SET weight = weight + 0.1
|
|
131
|
+
`);
|
|
132
|
+
const now = Date.now();
|
|
133
|
+
this.db.transaction(() => {
|
|
134
|
+
upsertNode.run(source.id, source.type, source.label, now);
|
|
135
|
+
upsertNode.run(target.id, target.type, target.label, now);
|
|
136
|
+
upsertEdge.run(source.id, target.id, relation);
|
|
137
|
+
})();
|
|
138
|
+
}
|
|
139
|
+
linkSessionToEntities(sessionId, summary, files, tasks) {
|
|
140
|
+
const sessionNode = { id: `session:${sessionId}`, type: "session", label: summary };
|
|
141
|
+
for (const file of files) {
|
|
142
|
+
const fileNode = { id: `file:${file}`, type: "file", label: file };
|
|
143
|
+
this.link(sessionNode, "modifies", fileNode);
|
|
144
|
+
}
|
|
145
|
+
for (const task of tasks) {
|
|
146
|
+
const taskNode = { id: `task:${task}`, type: "task", label: task };
|
|
147
|
+
this.link(sessionNode, "executes", taskNode);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// --- 经验蒸馏操作 ---
|
|
151
|
+
addPractice(practice) {
|
|
152
|
+
const stmt = this.db.prepare(`
|
|
153
|
+
INSERT INTO distilled_practices (id, task_pattern, action_json, context_json, confidence, created_at)
|
|
154
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
155
|
+
ON CONFLICT(task_pattern) DO UPDATE SET
|
|
156
|
+
hit_count = hit_count + 1,
|
|
157
|
+
confidence = (confidence + excluded.confidence) / 2.0
|
|
158
|
+
`);
|
|
159
|
+
stmt.run(practice.id, practice.task_pattern, JSON.stringify(practice.successful_commands), JSON.stringify(practice.files_involved), practice.confidence, Date.now());
|
|
160
|
+
}
|
|
161
|
+
getRelatedPractices(query) {
|
|
162
|
+
// 简单的关键词模式匹配,后期可升级为向量检索
|
|
163
|
+
return this.db.prepare(`
|
|
164
|
+
SELECT * FROM distilled_practices
|
|
165
|
+
WHERE task_pattern LIKE ?
|
|
166
|
+
ORDER BY confidence DESC, hit_count DESC
|
|
167
|
+
LIMIT 3
|
|
168
|
+
`).all(`%${query}%`);
|
|
169
|
+
}
|
|
170
|
+
// --- 符号索引相关操作 ---
|
|
171
|
+
upsertSymbolNode(fileRelativePath, symbol) {
|
|
172
|
+
const fileId = `file:${fileRelativePath}`;
|
|
173
|
+
const symbolId = `symbol:${fileRelativePath}:${symbol.name}`;
|
|
174
|
+
const now = Date.now();
|
|
175
|
+
const upsertNode = this.db.prepare(`
|
|
176
|
+
INSERT INTO kg_nodes (id, type, label, metadata, last_seen)
|
|
177
|
+
VALUES (?, ?, ?, ?, ?)
|
|
178
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
179
|
+
label = excluded.label,
|
|
180
|
+
metadata = excluded.metadata,
|
|
181
|
+
last_seen = excluded.last_seen
|
|
182
|
+
`);
|
|
183
|
+
const upsertEdge = this.db.prepare(`
|
|
184
|
+
INSERT INTO kg_edges (source, target, relation, weight)
|
|
185
|
+
VALUES (?, ?, ?, 1.0)
|
|
186
|
+
ON CONFLICT(source, target, relation) DO UPDATE SET weight = weight + 0.1
|
|
187
|
+
`);
|
|
188
|
+
this.db.transaction(() => {
|
|
189
|
+
upsertNode.run(fileId, "file", fileRelativePath, null, now);
|
|
190
|
+
const meta = JSON.stringify({ kind: symbol.type, line: symbol.line, signature: symbol.signature });
|
|
191
|
+
upsertNode.run(symbolId, "symbol", symbol.name, meta, now);
|
|
192
|
+
upsertEdge.run(symbolId, fileId, "part_of");
|
|
193
|
+
})();
|
|
194
|
+
}
|
|
195
|
+
getSymbolsForFile(fileRelativePath) {
|
|
196
|
+
const fileId = `file:${fileRelativePath}`;
|
|
197
|
+
const stmt = this.db.prepare(`
|
|
198
|
+
SELECT n.id, n.label, n.metadata
|
|
199
|
+
FROM kg_nodes n
|
|
200
|
+
JOIN kg_edges e ON n.id = e.source
|
|
201
|
+
WHERE e.target = ? AND e.relation = 'part_of' AND n.type = 'symbol'
|
|
202
|
+
`);
|
|
203
|
+
const rows = stmt.all(fileId);
|
|
204
|
+
return rows.map((r) => {
|
|
205
|
+
const meta = JSON.parse(r.metadata || "{}");
|
|
206
|
+
return {
|
|
207
|
+
name: r.label,
|
|
208
|
+
type: meta.kind || "function",
|
|
209
|
+
line: meta.line || 0,
|
|
210
|
+
signature: meta.signature || "",
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
clearSymbolsForFile(fileRelativePath) {
|
|
215
|
+
const fileId = `file:${fileRelativePath}`;
|
|
216
|
+
this.db.transaction(() => {
|
|
217
|
+
this.db.prepare(`
|
|
218
|
+
DELETE FROM kg_edges
|
|
219
|
+
WHERE target = ? AND relation = 'part_of'
|
|
220
|
+
`).run(fileId);
|
|
221
|
+
this.db.prepare(`
|
|
222
|
+
DELETE FROM kg_nodes
|
|
223
|
+
WHERE id LIKE ? AND type = 'symbol'
|
|
224
|
+
`).run(`symbol:${fileRelativePath}:%`);
|
|
225
|
+
})();
|
|
226
|
+
}
|
|
227
|
+
getAllSymbols() {
|
|
228
|
+
if (!this.db)
|
|
229
|
+
return [];
|
|
230
|
+
const stmt = this.db.prepare(`
|
|
231
|
+
SELECT n.label, n.metadata, e.target
|
|
232
|
+
FROM kg_nodes n
|
|
233
|
+
JOIN kg_edges e ON n.id = e.source
|
|
234
|
+
WHERE n.type = 'symbol' AND e.relation = 'part_of'
|
|
235
|
+
`);
|
|
236
|
+
const rows = stmt.all();
|
|
237
|
+
return rows.map((r) => {
|
|
238
|
+
const meta = JSON.parse(r.metadata || "{}");
|
|
239
|
+
const file = r.target.startsWith("file:") ? r.target.substring(5) : r.target;
|
|
240
|
+
return {
|
|
241
|
+
file,
|
|
242
|
+
name: r.label,
|
|
243
|
+
type: meta.kind || "function",
|
|
244
|
+
line: meta.line || 0,
|
|
245
|
+
signature: meta.signature || "",
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
// --- 辅助工具 ---
|
|
250
|
+
cosineSimilarity(v1, v2) {
|
|
251
|
+
if (v1.length !== v2.length)
|
|
252
|
+
return 0;
|
|
253
|
+
let dotProduct = 0, normA = 0, normB = 0;
|
|
254
|
+
for (let i = 0; i < v1.length; i++) {
|
|
255
|
+
dotProduct += v1[i] * v2[i];
|
|
256
|
+
normA += v1[i] * v1[i];
|
|
257
|
+
normB += v2[i] * v2[i];
|
|
258
|
+
}
|
|
259
|
+
const similarity = dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
260
|
+
return isNaN(similarity) ? 0 : similarity;
|
|
261
|
+
}
|
|
262
|
+
close() {
|
|
263
|
+
this.db.close();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PersistedEntry } from "../types.js";
|
|
2
|
+
export interface CompactionResult {
|
|
3
|
+
before: number;
|
|
4
|
+
after: number;
|
|
5
|
+
removed: number;
|
|
6
|
+
merged: number;
|
|
7
|
+
}
|
|
8
|
+
export interface CompactionApplyResult {
|
|
9
|
+
entries: PersistedEntry[];
|
|
10
|
+
stats: CompactionResult;
|
|
11
|
+
}
|
|
12
|
+
export interface CompactorOptions {
|
|
13
|
+
maxEntries: number;
|
|
14
|
+
expireAgeMs: number;
|
|
15
|
+
expireMinImportance: number;
|
|
16
|
+
dedupSimilarityThreshold: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class MemoryCompactor {
|
|
19
|
+
private options;
|
|
20
|
+
constructor(options?: Partial<CompactorOptions>);
|
|
21
|
+
compact(entries: PersistedEntry[]): CompactionResult;
|
|
22
|
+
compactWithEntries(entries: PersistedEntry[]): CompactionApplyResult;
|
|
23
|
+
private deduplicate;
|
|
24
|
+
private similarity;
|
|
25
|
+
private bigrams;
|
|
26
|
+
private capByImportance;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=compactor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compactor.d.ts","sourceRoot":"","sources":["../../src/memory/compactor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,wBAAwB,EAAE,MAAM,CAAC;CAClC;AASD,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAmB;gBAEtB,OAAO,GAAE,OAAO,CAAC,gBAAgB,CAAM;IAInD,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,gBAAgB;IAIpD,kBAAkB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,qBAAqB;IAgCpE,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,eAAe;CAMxB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Memory Compactor(记忆压缩)
|
|
3
|
+
// 去重 + 过期 + 上限裁剪
|
|
4
|
+
// ============================================================
|
|
5
|
+
const DEFAULT_OPTIONS = {
|
|
6
|
+
maxEntries: 1000,
|
|
7
|
+
expireAgeMs: 90 * 24 * 60 * 60 * 1000,
|
|
8
|
+
expireMinImportance: 0.3,
|
|
9
|
+
dedupSimilarityThreshold: 0.8,
|
|
10
|
+
};
|
|
11
|
+
export class MemoryCompactor {
|
|
12
|
+
options;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
15
|
+
}
|
|
16
|
+
compact(entries) {
|
|
17
|
+
return this.compactWithEntries(entries).stats;
|
|
18
|
+
}
|
|
19
|
+
compactWithEntries(entries) {
|
|
20
|
+
const before = entries.length;
|
|
21
|
+
let removed = 0;
|
|
22
|
+
// 1. 过期清理
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
const afterExpire = entries.filter((e) => {
|
|
25
|
+
const age = now - e.createdAt;
|
|
26
|
+
if (age > this.options.expireAgeMs && e.importance < this.options.expireMinImportance) {
|
|
27
|
+
removed++;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
// 2. 去重合并
|
|
33
|
+
const deduped = this.deduplicate(afterExpire);
|
|
34
|
+
const merged = afterExpire.length - deduped.length;
|
|
35
|
+
// 3. 上限裁剪(按重要性排序,保留高重要性的)
|
|
36
|
+
const capped = this.capByImportance(deduped, this.options.maxEntries);
|
|
37
|
+
const afterCapRemoved = deduped.length - capped.length;
|
|
38
|
+
removed += afterCapRemoved;
|
|
39
|
+
return {
|
|
40
|
+
entries: capped,
|
|
41
|
+
stats: { before, after: capped.length, removed, merged },
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// --- Private ---
|
|
45
|
+
deduplicate(entries) {
|
|
46
|
+
const kept = [];
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
const duplicate = kept.find((k) => this.similarity(k.content, entry.content) >= this.options.dedupSimilarityThreshold);
|
|
49
|
+
if (duplicate) {
|
|
50
|
+
// keep the one with higher importance
|
|
51
|
+
if (entry.importance > duplicate.importance) {
|
|
52
|
+
const idx = kept.indexOf(duplicate);
|
|
53
|
+
kept[idx] = entry;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
kept.push(entry);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return kept;
|
|
61
|
+
}
|
|
62
|
+
similarity(a, b) {
|
|
63
|
+
// simple bigram similarity (0-1)
|
|
64
|
+
const bigramsA = this.bigrams(a.toLowerCase());
|
|
65
|
+
const bigramsB = this.bigrams(b.toLowerCase());
|
|
66
|
+
if (bigramsA.size === 0 && bigramsB.size === 0)
|
|
67
|
+
return 1;
|
|
68
|
+
if (bigramsA.size === 0 || bigramsB.size === 0)
|
|
69
|
+
return 0;
|
|
70
|
+
let intersection = 0;
|
|
71
|
+
for (const bg of bigramsA) {
|
|
72
|
+
if (bigramsB.has(bg))
|
|
73
|
+
intersection++;
|
|
74
|
+
}
|
|
75
|
+
const union = bigramsA.size + bigramsB.size - intersection;
|
|
76
|
+
return union === 0 ? 0 : intersection / union;
|
|
77
|
+
}
|
|
78
|
+
bigrams(text) {
|
|
79
|
+
const set = new Set();
|
|
80
|
+
for (let i = 0; i < text.length - 1; i++) {
|
|
81
|
+
set.add(text.slice(i, i + 2));
|
|
82
|
+
}
|
|
83
|
+
return set;
|
|
84
|
+
}
|
|
85
|
+
capByImportance(entries, max) {
|
|
86
|
+
if (entries.length <= max)
|
|
87
|
+
return entries;
|
|
88
|
+
return entries
|
|
89
|
+
.sort((a, b) => b.importance - a.importance)
|
|
90
|
+
.slice(0, max);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PersistedEntry } from "../types.js";
|
|
2
|
+
export interface MemoryOperation {
|
|
3
|
+
action: "ADD" | "UPDATE" | "DELETE" | "NOOP";
|
|
4
|
+
fact: string;
|
|
5
|
+
targetId?: string;
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function consolidateMemoriesLLM(newCandidates: string[], existingMemories: PersistedEntry[], config: {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
endpoint: string;
|
|
11
|
+
model: string;
|
|
12
|
+
}): Promise<MemoryOperation[]>;
|
|
13
|
+
//# sourceMappingURL=consolidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consolidation.d.ts","sourceRoot":"","sources":["../../src/memory/consolidation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA+BD,wBAAsB,sBAAsB,CAC1C,aAAa,EAAE,MAAM,EAAE,EACvB,gBAAgB,EAAE,cAAc,EAAE,EAClC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1D,OAAO,CAAC,eAAe,EAAE,CAAC,CAqD5B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
const CONSOLIDATE_PROMPT = `你是一个记忆合并与冲突消解专家。请比对以下“新提取的候选记忆”和“已有的长期记忆”,消除冲突、冗余,并输出合并整理指令。
|
|
3
|
+
|
|
4
|
+
合并原则:
|
|
5
|
+
1. 冲突消解:若候选记忆与已有记忆存在矛盾(例如,已有记忆说“当前使用 python 3.12”,而新候选记忆说“项目已升级到 python 3.13”),应该将旧记忆标记为 DELETE(或用 UPDATE 修正它),不要保留过期的矛盾事实。
|
|
6
|
+
2. 消除冗余:如果候选记忆的内容已经包含在已有记忆中,或者意义完全一致,则无需重复添加,标记为 NOOP。
|
|
7
|
+
3. 新知识添加:若候选记忆是全新且不矛盾的信息,标记为 ADD。
|
|
8
|
+
4. 旧知识删除:若已有记忆已被新的会话上下文判定为过时或无效,标记为 DELETE。
|
|
9
|
+
|
|
10
|
+
请返回一个 JSON 数组,包含每个记忆的操作结果,格式如下:
|
|
11
|
+
[
|
|
12
|
+
{
|
|
13
|
+
"action": "ADD",
|
|
14
|
+
"fact": "新事实描述"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"action": "UPDATE",
|
|
18
|
+
"targetId": "mem_xxx",
|
|
19
|
+
"fact": "修正后的事实描述",
|
|
20
|
+
"reason": "更新理由"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"action": "DELETE",
|
|
24
|
+
"targetId": "mem_yyy",
|
|
25
|
+
"reason": "删除理由"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
请只返回 JSON 格式数据,不要包含 Markdown 格式标记或其他任何文本。`;
|
|
30
|
+
export async function consolidateMemoriesLLM(newCandidates, existingMemories, config) {
|
|
31
|
+
if (newCandidates.length === 0)
|
|
32
|
+
return [];
|
|
33
|
+
if (!config.apiKey) {
|
|
34
|
+
// If no API key, default to ADD for all new candidates that are not exact matches.
|
|
35
|
+
const existingContents = new Set(existingMemories.map(e => e.content));
|
|
36
|
+
return newCandidates
|
|
37
|
+
.filter(c => !existingContents.has(c))
|
|
38
|
+
.map(c => ({ action: "ADD", fact: c }));
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const payloadInput = {
|
|
42
|
+
candidates: newCandidates,
|
|
43
|
+
existing: existingMemories.map(e => ({ id: e.id, fact: e.content })),
|
|
44
|
+
};
|
|
45
|
+
const resp = await axios.post(config.endpoint + "/chat/completions", {
|
|
46
|
+
model: config.model,
|
|
47
|
+
messages: [
|
|
48
|
+
{ role: "system", content: CONSOLIDATE_PROMPT },
|
|
49
|
+
{ role: "user", content: JSON.stringify(payloadInput) },
|
|
50
|
+
],
|
|
51
|
+
max_tokens: 800,
|
|
52
|
+
temperature: 0.2,
|
|
53
|
+
}, {
|
|
54
|
+
headers: {
|
|
55
|
+
Authorization: "Bearer " + config.apiKey,
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
},
|
|
58
|
+
timeout: 30_000,
|
|
59
|
+
});
|
|
60
|
+
const content = resp.data.choices?.[0]?.message?.content?.trim() ?? "";
|
|
61
|
+
const jsonMatch = content.match(/\[[\s\S]*\]/);
|
|
62
|
+
if (jsonMatch) {
|
|
63
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
64
|
+
if (Array.isArray(parsed)) {
|
|
65
|
+
return parsed;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
console.error("[MemoryConsolidation] LLM request failed, falling back to direct add:", err);
|
|
71
|
+
}
|
|
72
|
+
// Fallback
|
|
73
|
+
const existingContents = new Set(existingMemories.map(e => e.content));
|
|
74
|
+
return newCandidates
|
|
75
|
+
.filter(c => !existingContents.has(c))
|
|
76
|
+
.map(c => ({ action: "ADD", fact: c }));
|
|
77
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface EmbeddingOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
endpoint: string;
|
|
4
|
+
model: string;
|
|
5
|
+
dimensions?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class EmbeddingClient {
|
|
8
|
+
private client;
|
|
9
|
+
private model;
|
|
10
|
+
private dimensions?;
|
|
11
|
+
constructor(options: EmbeddingOptions);
|
|
12
|
+
getEmbedding(text: string): Promise<number[]>;
|
|
13
|
+
getEmbeddings(texts: string[]): Promise<number[][]>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=embedding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../../src/memory/embedding.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,CAAC,CAAS;gBAEhB,OAAO,EAAE,gBAAgB;IAY/B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAmB7C,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CAmB1D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Embedding 向量生成工具
|
|
3
|
+
// 支持 OpenAI / DeepSeek 等主流 Embedding 接口
|
|
4
|
+
// ============================================================
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
export class EmbeddingClient {
|
|
7
|
+
client;
|
|
8
|
+
model;
|
|
9
|
+
dimensions;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.model = options.model;
|
|
12
|
+
this.dimensions = options.dimensions;
|
|
13
|
+
this.client = axios.create({
|
|
14
|
+
baseURL: options.endpoint,
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async getEmbedding(text) {
|
|
22
|
+
try {
|
|
23
|
+
const resp = await this.client.post("/embeddings", {
|
|
24
|
+
model: this.model,
|
|
25
|
+
input: text,
|
|
26
|
+
dimensions: this.dimensions, // 仅部分模型支持
|
|
27
|
+
});
|
|
28
|
+
const embedding = resp.data.data?.[0]?.embedding;
|
|
29
|
+
if (!Array.isArray(embedding)) {
|
|
30
|
+
throw new Error("Invalid embedding response format");
|
|
31
|
+
}
|
|
32
|
+
return embedding;
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
const msg = err.response?.data?.error?.message || err.message;
|
|
36
|
+
throw new Error(`Embedding failed: ${msg}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async getEmbeddings(texts) {
|
|
40
|
+
if (texts.length === 0)
|
|
41
|
+
return [];
|
|
42
|
+
try {
|
|
43
|
+
const resp = await this.client.post("/embeddings", {
|
|
44
|
+
model: this.model,
|
|
45
|
+
input: texts,
|
|
46
|
+
dimensions: this.dimensions,
|
|
47
|
+
});
|
|
48
|
+
const embeddings = resp.data.data?.map((d) => d.embedding);
|
|
49
|
+
if (!Array.isArray(embeddings)) {
|
|
50
|
+
throw new Error("Invalid embeddings response format");
|
|
51
|
+
}
|
|
52
|
+
return embeddings;
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
const msg = err.response?.data?.error?.message || err.message;
|
|
56
|
+
throw new Error(`Batch embedding failed: ${msg}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-llm-dream.d.ts","sourceRoot":"","sources":["../../src/memory/memory-llm-dream.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAelD,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,EAAE,EACpB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,MAAM,EAAE,CAAC,CAwDnB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - LLM 增强记忆提取
|
|
3
|
+
// 用 LLM 从对话中提取结构化记忆,regex 为降级兜底
|
|
4
|
+
// ============================================================
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
import { extractDreamMemories } from "../memory.js";
|
|
7
|
+
const DREAM_PROMPT = `你是一个记忆提取助手。从以下对话中提取值得长期记住的信息。
|
|
8
|
+
|
|
9
|
+
提取规则:
|
|
10
|
+
1. 项目决策(选用了什么技术/框架/方案)
|
|
11
|
+
2. 文件路径(重要的源文件、配置文件)
|
|
12
|
+
3. 用户偏好(编码风格、工具偏好)
|
|
13
|
+
4. 错误模式(遇到的 bug 及其解决方案)
|
|
14
|
+
5. 关键上下文(工作目录、环境信息)
|
|
15
|
+
|
|
16
|
+
返回 JSON 数组,每个元素是一句简洁的陈述(不超过50字)。
|
|
17
|
+
如果没有值得记忆的内容,返回空数组 []。
|
|
18
|
+
只返回 JSON 数组,不要其他文字。`;
|
|
19
|
+
export async function extractDreamMemoriesLLM(transcript, turnCount, config) {
|
|
20
|
+
if (!config.enabled || !config.apiKey) {
|
|
21
|
+
return extractDreamMemories({ turnCount, transcript }, { enabled: true, turnThreshold: 24, transcriptWindow: 4 });
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const recent = transcript.slice(-6);
|
|
25
|
+
const combined = recent.join("\n---\n");
|
|
26
|
+
const resp = await axios.post(config.endpoint + "/chat/completions", {
|
|
27
|
+
model: config.model,
|
|
28
|
+
messages: [
|
|
29
|
+
{ role: "system", content: DREAM_PROMPT },
|
|
30
|
+
{ role: "user", content: combined.slice(0, 4000) },
|
|
31
|
+
],
|
|
32
|
+
max_tokens: config.maxTokens,
|
|
33
|
+
temperature: 0.3,
|
|
34
|
+
}, {
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: "Bearer " + config.apiKey,
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
},
|
|
39
|
+
timeout: 30_000,
|
|
40
|
+
});
|
|
41
|
+
const content = resp.data.choices?.[0]?.message?.content?.trim() ?? "";
|
|
42
|
+
// parse JSON array from response
|
|
43
|
+
const jsonMatch = content.match(/\[[\s\S]*\]/);
|
|
44
|
+
if (jsonMatch) {
|
|
45
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
46
|
+
if (Array.isArray(parsed)) {
|
|
47
|
+
return parsed
|
|
48
|
+
.map((item) => String(item).trim())
|
|
49
|
+
.filter((s) => s.length > 0 && s.length <= 200);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// fallback to regex
|
|
53
|
+
return extractDreamMemories({ turnCount, transcript }, { enabled: true, turnThreshold: 24, transcriptWindow: 4 });
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// fallback to regex on any error
|
|
57
|
+
return extractDreamMemories({ turnCount, transcript }, { enabled: true, turnThreshold: 24, transcriptWindow: 4 });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { WriteAheadLog, WALEntry } from "./wal.js";
|
|
2
|
+
import type { PersistedEntry } from "../types.js";
|
|
3
|
+
export interface ProjectionWorkerOptions {
|
|
4
|
+
intervalMs: number;
|
|
5
|
+
maxPendingEntries: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class ProjectionWorker {
|
|
8
|
+
private wal;
|
|
9
|
+
private timer;
|
|
10
|
+
private running;
|
|
11
|
+
private applyEntry;
|
|
12
|
+
private getEntries;
|
|
13
|
+
private onCheckpoint?;
|
|
14
|
+
private options;
|
|
15
|
+
private firstRun;
|
|
16
|
+
private projectedCount;
|
|
17
|
+
constructor(wal: WriteAheadLog, callbacks: {
|
|
18
|
+
applyEntry: (entry: WALEntry) => void;
|
|
19
|
+
getEntries: () => PersistedEntry[];
|
|
20
|
+
onCheckpoint?: (entries: PersistedEntry[]) => Promise<void>;
|
|
21
|
+
}, options?: Partial<ProjectionWorkerOptions>);
|
|
22
|
+
start(): void;
|
|
23
|
+
stop(): void;
|
|
24
|
+
projectOnce(): Promise<number>;
|
|
25
|
+
forceCheckpoint(): Promise<void>;
|
|
26
|
+
isRunning(): boolean;
|
|
27
|
+
getProjectedCount(): number;
|
|
28
|
+
private tick;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=projection-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection-worker.d.ts","sourceRoot":"","sources":["../../src/memory/projection-worker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAOD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,KAAK,CAA+C;IAC5D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,YAAY,CAAC,CAA+C;IACpE,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,cAAc,CAAK;gBAGzB,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE;QACT,UAAU,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;QACtC,UAAU,EAAE,MAAM,cAAc,EAAE,CAAC;QACnC,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC7D,EACD,OAAO,GAAE,OAAO,CAAC,uBAAuB,CAAM;IAShD,KAAK,IAAI,IAAI;IAMb,IAAI,IAAI,IAAI;IAQN,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IA4B9B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtC,SAAS,IAAI,OAAO;IAIpB,iBAAiB,IAAI,MAAM;YAMb,IAAI;CAenB"}
|