@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
package/dist/memory.js
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Memory 系统 v3(WAL + 投影 Worker + LLM Dream)
|
|
3
|
+
// 三层架构:Scratchpad(会话)→ Conversation(对话)→ Persisted(持久化)
|
|
4
|
+
// ============================================================
|
|
5
|
+
import * as fs from "fs/promises";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import { ProjectionWorker } from "./memory/projection-worker.js";
|
|
8
|
+
import { MemoryCompactor } from "./memory/compactor.js";
|
|
9
|
+
import * as crypto from "crypto";
|
|
10
|
+
const DEFAULT_CONFIG = {
|
|
11
|
+
enabled: true,
|
|
12
|
+
turnThreshold: 24,
|
|
13
|
+
transcriptWindow: 4,
|
|
14
|
+
semanticEnabled: false,
|
|
15
|
+
};
|
|
16
|
+
// --- PersistedMemory(长期存储,WAL 模式可选)---
|
|
17
|
+
export class PersistedMemory {
|
|
18
|
+
entries = [];
|
|
19
|
+
memoryDir;
|
|
20
|
+
wal = null;
|
|
21
|
+
projectionWorker = null;
|
|
22
|
+
// v0.5 认知引擎
|
|
23
|
+
cognitiveIndex = null;
|
|
24
|
+
embeddingClient = null;
|
|
25
|
+
constructor(memoryDir) {
|
|
26
|
+
this.memoryDir = memoryDir;
|
|
27
|
+
}
|
|
28
|
+
setWAL(wal, options = {}) {
|
|
29
|
+
this.wal = wal;
|
|
30
|
+
this.projectionWorker = new ProjectionWorker(wal, {
|
|
31
|
+
applyEntry: (entry) => this.applyWALEntry(entry),
|
|
32
|
+
getEntries: () => this.entries,
|
|
33
|
+
onCheckpoint: async (entries) => this.syncCognitiveIndex(entries),
|
|
34
|
+
}, {
|
|
35
|
+
intervalMs: options.intervalMs,
|
|
36
|
+
maxPendingEntries: options.maxPendingEntries,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
setCognitiveIndex(index, client) {
|
|
40
|
+
this.cognitiveIndex = index;
|
|
41
|
+
this.embeddingClient = client;
|
|
42
|
+
}
|
|
43
|
+
async init() {
|
|
44
|
+
await fs.mkdir(this.memoryDir, { recursive: true });
|
|
45
|
+
await this.loadFromDisk();
|
|
46
|
+
if (this.cognitiveIndex) {
|
|
47
|
+
await this.cognitiveIndex.init();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
add(content, source, importance = 0.5) {
|
|
51
|
+
const entry = {
|
|
52
|
+
id: "mem_" + Date.now() + "_" + Math.random().toString(36).slice(2, 7),
|
|
53
|
+
content,
|
|
54
|
+
source,
|
|
55
|
+
createdAt: Date.now(),
|
|
56
|
+
importance,
|
|
57
|
+
};
|
|
58
|
+
this.entries.push(entry);
|
|
59
|
+
this.entries.sort((a, b) => b.importance - a.importance);
|
|
60
|
+
}
|
|
61
|
+
remove(id) {
|
|
62
|
+
const idx = this.entries.findIndex((e) => e.id === id);
|
|
63
|
+
if (idx === -1)
|
|
64
|
+
return false;
|
|
65
|
+
this.entries.splice(idx, 1);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
update(id, updates) {
|
|
69
|
+
const entry = this.entries.find((e) => e.id === id);
|
|
70
|
+
if (!entry)
|
|
71
|
+
return false;
|
|
72
|
+
if (updates.content !== undefined)
|
|
73
|
+
entry.content = updates.content;
|
|
74
|
+
if (updates.importance !== undefined)
|
|
75
|
+
entry.importance = updates.importance;
|
|
76
|
+
this.entries.sort((a, b) => b.importance - a.importance);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
applyWALEntry(entry) {
|
|
80
|
+
switch (entry.op) {
|
|
81
|
+
case "add": {
|
|
82
|
+
const data = entry.data;
|
|
83
|
+
if (!this.entries.some((e) => e.id === data.id)) {
|
|
84
|
+
this.entries.push(data);
|
|
85
|
+
this.entries.sort((a, b) => b.importance - a.importance);
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case "remove": {
|
|
90
|
+
const data = entry.data;
|
|
91
|
+
this.entries = this.entries.filter((e) => e.id !== data.id);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "update": {
|
|
95
|
+
const data = entry.data;
|
|
96
|
+
const existing = this.entries.find((e) => e.id === data.id);
|
|
97
|
+
if (existing) {
|
|
98
|
+
if (data.content !== undefined)
|
|
99
|
+
existing.content = data.content;
|
|
100
|
+
if (data.importance !== undefined)
|
|
101
|
+
existing.importance = data.importance;
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "compact": {
|
|
106
|
+
const data = entry.data;
|
|
107
|
+
this.entries = data;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async getRelevant(query, limit = 5) {
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
// 1. 关键词检索
|
|
115
|
+
const keywordResults = this.entries.map((e) => {
|
|
116
|
+
let score = e.importance;
|
|
117
|
+
const ageHours = (now - e.createdAt) / (1000 * 60 * 60);
|
|
118
|
+
score *= Math.pow(0.9, ageHours / 24);
|
|
119
|
+
const keywords = query.toLowerCase().split(/\s+/);
|
|
120
|
+
const content = e.content.toLowerCase();
|
|
121
|
+
const matches = keywords.filter((k) => content.includes(k)).length;
|
|
122
|
+
score += matches * 0.1;
|
|
123
|
+
return { entry: e, score, source: "keyword" };
|
|
124
|
+
});
|
|
125
|
+
// 2. 向量检索 (v0.3+)
|
|
126
|
+
let semanticResults = [];
|
|
127
|
+
if (this.cognitiveIndex && this.embeddingClient && query.trim()) {
|
|
128
|
+
try {
|
|
129
|
+
const queryVector = await this.embeddingClient.getEmbedding(query);
|
|
130
|
+
const searchHits = this.cognitiveIndex.searchVector(queryVector, limit * 2);
|
|
131
|
+
semanticResults = searchHits.map(h => ({
|
|
132
|
+
entry: h.entry,
|
|
133
|
+
score: h.score * 0.8,
|
|
134
|
+
source: "vector"
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
// 专项修复:处理 404 (Endpoint 不支持)
|
|
139
|
+
if (err.message.includes("404")) {
|
|
140
|
+
if (!this._warned404) {
|
|
141
|
+
console.warn(`[Memory] ⚠️ 当前提供商不支持 Embedding 接口 (404),已降级为纯关键词检索模式。`);
|
|
142
|
+
this._warned404 = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.error(`[PersistedMemory] Vector search failed: ${err.message}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// 3. 经验检索 (v0.5 M1)
|
|
151
|
+
const practices = this.cognitiveIndex?.getRelatedPractices(query) || [];
|
|
152
|
+
const practiceResults = practices.map(p => ({
|
|
153
|
+
id: p.id,
|
|
154
|
+
content: `[最佳实践] 任务模式: ${p.task_pattern} | 成功路径: ${JSON.parse(p.action_json).join(" -> ")}`,
|
|
155
|
+
source: "practice",
|
|
156
|
+
importance: p.confidence,
|
|
157
|
+
createdAt: p.created_at
|
|
158
|
+
}));
|
|
159
|
+
// 4. 混合排序 (Hybrid Rerank)
|
|
160
|
+
const merged = new Map();
|
|
161
|
+
keywordResults.forEach(r => merged.set(r.entry.id, r));
|
|
162
|
+
semanticResults.forEach(r => {
|
|
163
|
+
const existing = merged.get(r.entry.id);
|
|
164
|
+
if (existing)
|
|
165
|
+
existing.score += r.score;
|
|
166
|
+
else
|
|
167
|
+
merged.set(r.entry.id, r);
|
|
168
|
+
});
|
|
169
|
+
practiceResults.forEach(p => {
|
|
170
|
+
merged.set(p.id, { entry: p, score: 2.0 });
|
|
171
|
+
});
|
|
172
|
+
return Array.from(merged.values())
|
|
173
|
+
.sort((a, b) => b.score - a.score)
|
|
174
|
+
.slice(0, limit)
|
|
175
|
+
.map((s) => s.entry);
|
|
176
|
+
}
|
|
177
|
+
async syncCognitiveIndex(entries) {
|
|
178
|
+
if (!this.cognitiveIndex || !this.embeddingClient)
|
|
179
|
+
return;
|
|
180
|
+
const batchSize = 10;
|
|
181
|
+
const entriesToIndex = entries.slice(-batchSize);
|
|
182
|
+
try {
|
|
183
|
+
const vectors = await this.embeddingClient.getEmbeddings(entriesToIndex.map(e => e.content));
|
|
184
|
+
for (let i = 0; i < entriesToIndex.length; i++) {
|
|
185
|
+
this.cognitiveIndex.upsertVector(entriesToIndex[i], vectors[i]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
const msg = err.message || String(err);
|
|
190
|
+
if (msg.includes("404")) {
|
|
191
|
+
if (!this._semanticWarned404) {
|
|
192
|
+
console.warn(`[Memory] ⚠️ 当前提供商不支持 Embedding 接口 (404),已禁用语义索引(降级为关键词+实践检索)。请为语义记忆配置支持 embeddings 的 provider(如 OpenAI)或设置 QLING_MEMORY_SEMANTIC_ENDPOINT / _MODEL。`);
|
|
193
|
+
this._semanticWarned404 = true;
|
|
194
|
+
// 禁用后续索引
|
|
195
|
+
this.embeddingClient = null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
console.error(`[PersistedMemory] Async cognitive indexing failed: ${msg}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/** 建立知识关联 */
|
|
204
|
+
link(source, relation, target) {
|
|
205
|
+
this.cognitiveIndex?.link(source, relation, target);
|
|
206
|
+
}
|
|
207
|
+
linkSessionToEntities(sessionId, summary, files, tasks) {
|
|
208
|
+
this.cognitiveIndex?.linkSessionToEntities(sessionId, summary, files, tasks);
|
|
209
|
+
}
|
|
210
|
+
/** 记录最佳实践 */
|
|
211
|
+
addPractice(pattern, commands, files, confidence = 1.0) {
|
|
212
|
+
this.cognitiveIndex?.addPractice({
|
|
213
|
+
id: "prac_" + Date.now(),
|
|
214
|
+
task_pattern: pattern,
|
|
215
|
+
successful_commands: commands,
|
|
216
|
+
files_involved: files,
|
|
217
|
+
confidence,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
formatForPrompt(limit = 10) {
|
|
221
|
+
if (this.entries.length === 0)
|
|
222
|
+
return "";
|
|
223
|
+
const relevant = this.getRelevantSync("", limit);
|
|
224
|
+
if (relevant.length === 0)
|
|
225
|
+
return "";
|
|
226
|
+
return relevant
|
|
227
|
+
.map((e) => "[" + e.source + "] " + e.content)
|
|
228
|
+
.join("\n");
|
|
229
|
+
}
|
|
230
|
+
getRelevantSync(query, limit = 5) {
|
|
231
|
+
const now = Date.now();
|
|
232
|
+
const scored = this.entries.map((e) => {
|
|
233
|
+
let score = e.importance;
|
|
234
|
+
const ageHours = (now - e.createdAt) / (1000 * 60 * 60);
|
|
235
|
+
score *= Math.pow(0.9, ageHours / 24);
|
|
236
|
+
const keywords = query.toLowerCase().split(/\s+/);
|
|
237
|
+
const content = e.content.toLowerCase();
|
|
238
|
+
const matches = keywords.filter((k) => content.includes(k)).length;
|
|
239
|
+
score += matches * 0.1;
|
|
240
|
+
return { entry: e, score };
|
|
241
|
+
});
|
|
242
|
+
return scored
|
|
243
|
+
.sort((a, b) => b.score - a.score)
|
|
244
|
+
.slice(0, limit)
|
|
245
|
+
.map((s) => s.entry);
|
|
246
|
+
}
|
|
247
|
+
async saveToDisk() {
|
|
248
|
+
if (this.wal) {
|
|
249
|
+
await this.wal.append("compact", this.entries);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const file = path.join(this.memoryDir, "memory.json");
|
|
253
|
+
await fs.writeFile(file, JSON.stringify(this.entries, null, 2), "utf-8");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async loadFromDisk() {
|
|
257
|
+
try {
|
|
258
|
+
const file = path.join(this.memoryDir, "memory.json");
|
|
259
|
+
const data = await fs.readFile(file, "utf-8");
|
|
260
|
+
this.entries = JSON.parse(data);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
this.entries = [];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
merge(entries) {
|
|
267
|
+
const existing = new Map(this.entries.map((e) => [e.id, e]));
|
|
268
|
+
for (const entry of entries) {
|
|
269
|
+
existing.set(entry.id, entry);
|
|
270
|
+
}
|
|
271
|
+
this.entries = Array.from(existing.values());
|
|
272
|
+
this.entries.sort((a, b) => b.importance - a.importance);
|
|
273
|
+
}
|
|
274
|
+
getAll() {
|
|
275
|
+
return [...this.entries];
|
|
276
|
+
}
|
|
277
|
+
compact(maxEntries = 1000) {
|
|
278
|
+
const compactor = new MemoryCompactor({ maxEntries });
|
|
279
|
+
const result = compactor.compactWithEntries(this.entries);
|
|
280
|
+
this.entries = result.entries;
|
|
281
|
+
}
|
|
282
|
+
startProjection() {
|
|
283
|
+
this.projectionWorker?.start();
|
|
284
|
+
}
|
|
285
|
+
stopProjection() {
|
|
286
|
+
this.projectionWorker?.stop();
|
|
287
|
+
}
|
|
288
|
+
async forceCheckpoint() {
|
|
289
|
+
await this.projectionWorker?.forceCheckpoint();
|
|
290
|
+
}
|
|
291
|
+
async rebuildSemanticIndex() {
|
|
292
|
+
if (!this.cognitiveIndex || !this.embeddingClient)
|
|
293
|
+
return;
|
|
294
|
+
this.cognitiveIndex.close();
|
|
295
|
+
await this.cognitiveIndex.init();
|
|
296
|
+
const batchSize = 10;
|
|
297
|
+
for (let i = 0; i < this.entries.length; i += batchSize) {
|
|
298
|
+
const batch = this.entries.slice(i, i + batchSize);
|
|
299
|
+
try {
|
|
300
|
+
const vectors = await this.embeddingClient.getEmbeddings(batch.map(e => e.content));
|
|
301
|
+
for (let j = 0; j < batch.length; j++) {
|
|
302
|
+
this.cognitiveIndex.upsertVector(batch[j], vectors[j]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
console.error(`[PersistedMemory] rebuildSemanticIndex batch failed: ${err.message}`);
|
|
307
|
+
break; // stop on failure
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async shutdown() {
|
|
312
|
+
this.stopProjection();
|
|
313
|
+
await this.forceCheckpoint();
|
|
314
|
+
if (this.cognitiveIndex) {
|
|
315
|
+
this.cognitiveIndex.close();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
getCognitiveIndex() {
|
|
319
|
+
return this.cognitiveIndex;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// --- ScratchpadMemory(会话笔记,临时,Agent 自己写入读取)---
|
|
323
|
+
export class ScratchpadMemory {
|
|
324
|
+
notes = new Map();
|
|
325
|
+
set(key, value) {
|
|
326
|
+
this.notes.set(key, value);
|
|
327
|
+
}
|
|
328
|
+
get(key) {
|
|
329
|
+
return this.notes.get(key);
|
|
330
|
+
}
|
|
331
|
+
has(key) {
|
|
332
|
+
return this.notes.has(key);
|
|
333
|
+
}
|
|
334
|
+
delete(key) {
|
|
335
|
+
this.notes.delete(key);
|
|
336
|
+
}
|
|
337
|
+
entries() {
|
|
338
|
+
return this.notes.entries();
|
|
339
|
+
}
|
|
340
|
+
formatForPrompt() {
|
|
341
|
+
if (this.notes.size === 0)
|
|
342
|
+
return "";
|
|
343
|
+
const lines = Array.from(this.notes.entries()).map(([k, v]) => "- " + k + ": " + v);
|
|
344
|
+
return "[会话笔记]\n" + lines.join("\n");
|
|
345
|
+
}
|
|
346
|
+
clear() {
|
|
347
|
+
this.notes.clear();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
export class ConversationMemory {
|
|
351
|
+
turns = [];
|
|
352
|
+
add(role, content) {
|
|
353
|
+
this.turns.push({ role, content, timestamp: Date.now() });
|
|
354
|
+
}
|
|
355
|
+
getRecent(count = 10) {
|
|
356
|
+
return this.turns.slice(-count);
|
|
357
|
+
}
|
|
358
|
+
getAll() {
|
|
359
|
+
return [...this.turns];
|
|
360
|
+
}
|
|
361
|
+
count() {
|
|
362
|
+
return this.turns.length;
|
|
363
|
+
}
|
|
364
|
+
clear() {
|
|
365
|
+
this.turns = [];
|
|
366
|
+
}
|
|
367
|
+
extractKeyInfo() {
|
|
368
|
+
const recent = this.turns.slice(-8);
|
|
369
|
+
const lines = [];
|
|
370
|
+
for (const t of recent) {
|
|
371
|
+
const paths = t.content.match(/[/\.a-zA-Z0-9_-]+\.(ts|js|py|md|json|yml|yaml|sh)/g);
|
|
372
|
+
if (paths)
|
|
373
|
+
lines.push(...paths);
|
|
374
|
+
const techs = t.content.match(/(?:使用|调用|通过)\s+(\S+)/g);
|
|
375
|
+
if (techs)
|
|
376
|
+
lines.push(...techs);
|
|
377
|
+
}
|
|
378
|
+
return Array.from(new Set(lines));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// --- Unified MemoryStore(统一入口,组合三层)---
|
|
382
|
+
export class MemoryStore {
|
|
383
|
+
persisted; // Workspace persisted memory (for compatibility)
|
|
384
|
+
globalPersisted;
|
|
385
|
+
scratchpad;
|
|
386
|
+
conversation;
|
|
387
|
+
config;
|
|
388
|
+
workspaceMemoryDir;
|
|
389
|
+
globalMemoryDir;
|
|
390
|
+
constructor(memoryDir, config = {}) {
|
|
391
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
392
|
+
const workspaceDir = config.workspaceDir || process.cwd();
|
|
393
|
+
const wsHash = crypto.createHash("sha256").update(path.resolve(workspaceDir)).digest("hex").slice(0, 16);
|
|
394
|
+
// If memoryDir ends with "memory", assume it is the runtime root memory directory.
|
|
395
|
+
const parentDir = memoryDir.endsWith("memory") ? memoryDir : path.join(path.dirname(memoryDir), "memory");
|
|
396
|
+
this.globalMemoryDir = path.join(parentDir, "global");
|
|
397
|
+
this.workspaceMemoryDir = path.join(parentDir, "workspace", wsHash);
|
|
398
|
+
this.persisted = new PersistedMemory(this.workspaceMemoryDir);
|
|
399
|
+
this.globalPersisted = new PersistedMemory(this.globalMemoryDir);
|
|
400
|
+
this.scratchpad = new ScratchpadMemory();
|
|
401
|
+
this.conversation = new ConversationMemory();
|
|
402
|
+
}
|
|
403
|
+
async init() {
|
|
404
|
+
await this.globalPersisted.init();
|
|
405
|
+
await this.persisted.init();
|
|
406
|
+
}
|
|
407
|
+
setWAL(wal, options = {}) {
|
|
408
|
+
this.persisted.setWAL(wal, options);
|
|
409
|
+
}
|
|
410
|
+
setCognitiveIndex(index, client) {
|
|
411
|
+
this.persisted.setCognitiveIndex(index, client);
|
|
412
|
+
}
|
|
413
|
+
startProjection() {
|
|
414
|
+
this.persisted.startProjection();
|
|
415
|
+
}
|
|
416
|
+
stopProjection() {
|
|
417
|
+
this.persisted.stopProjection();
|
|
418
|
+
}
|
|
419
|
+
async forceCheckpoint() {
|
|
420
|
+
await this.persisted.forceCheckpoint();
|
|
421
|
+
}
|
|
422
|
+
async shutdown() {
|
|
423
|
+
await this.globalPersisted.shutdown();
|
|
424
|
+
await this.persisted.shutdown();
|
|
425
|
+
}
|
|
426
|
+
async rebuildSemanticIndex() {
|
|
427
|
+
await this.persisted.rebuildSemanticIndex();
|
|
428
|
+
}
|
|
429
|
+
getCognitiveIndex() {
|
|
430
|
+
return this.persisted.getCognitiveIndex();
|
|
431
|
+
}
|
|
432
|
+
// --- Persisted(对外 API)---
|
|
433
|
+
add(content, source, importance = 0.5, scope = "workspace") {
|
|
434
|
+
if (scope === "global") {
|
|
435
|
+
this.globalPersisted.add(content, source, importance);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
this.persisted.add(content, source, importance);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
remove(id, scope = "workspace") {
|
|
442
|
+
if (scope === "global") {
|
|
443
|
+
return this.globalPersisted.remove(id);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
return this.persisted.remove(id);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
update(id, updates, scope = "workspace") {
|
|
450
|
+
if (scope === "global") {
|
|
451
|
+
return this.globalPersisted.update(id, updates);
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
return this.persisted.update(id, updates);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
applyOperations(ops, scope = "workspace") {
|
|
458
|
+
for (const op of ops) {
|
|
459
|
+
switch (op.action) {
|
|
460
|
+
case "ADD":
|
|
461
|
+
this.add(op.fact, "dream-consolidation", 0.6, scope);
|
|
462
|
+
break;
|
|
463
|
+
case "UPDATE":
|
|
464
|
+
if (op.targetId) {
|
|
465
|
+
this.update(op.targetId, { content: op.fact }, scope);
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
case "DELETE":
|
|
469
|
+
if (op.targetId) {
|
|
470
|
+
this.remove(op.targetId, scope);
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async getRelevant(query, limit = 5) {
|
|
477
|
+
const wsHits = await this.persisted.getRelevant(query, limit);
|
|
478
|
+
const globalHits = await this.globalPersisted.getRelevant(query, limit);
|
|
479
|
+
const merged = new Map();
|
|
480
|
+
// Project/workspace memories get a weight multiplier of 1.0
|
|
481
|
+
wsHits.forEach((entry, idx) => {
|
|
482
|
+
const score = (limit - idx) * 1.0;
|
|
483
|
+
merged.set("ws:" + entry.id, { entry, score });
|
|
484
|
+
});
|
|
485
|
+
// Global memories get a weight multiplier of 0.7
|
|
486
|
+
globalHits.forEach((entry, idx) => {
|
|
487
|
+
const score = (limit - idx) * 0.7;
|
|
488
|
+
const key = "global:" + entry.id;
|
|
489
|
+
merged.set(key, { entry, score });
|
|
490
|
+
});
|
|
491
|
+
return Array.from(merged.values())
|
|
492
|
+
.sort((a, b) => b.score - a.score)
|
|
493
|
+
.slice(0, limit)
|
|
494
|
+
.map((s) => s.entry);
|
|
495
|
+
}
|
|
496
|
+
// --- Cognitive Layer (M1) ---
|
|
497
|
+
link(source, relation, target) {
|
|
498
|
+
this.persisted.link(source, relation, target);
|
|
499
|
+
}
|
|
500
|
+
linkSessionToEntities(sessionId, summary, files, tasks) {
|
|
501
|
+
this.persisted.linkSessionToEntities(sessionId, summary, files, tasks);
|
|
502
|
+
}
|
|
503
|
+
addPractice(pattern, commands, files) {
|
|
504
|
+
this.persisted.addPractice(pattern, commands, files);
|
|
505
|
+
}
|
|
506
|
+
// --- Scratchpad(对外 API)---
|
|
507
|
+
setNote(key, value) {
|
|
508
|
+
this.scratchpad.set(key, value);
|
|
509
|
+
}
|
|
510
|
+
getNote(key) {
|
|
511
|
+
return this.scratchpad.get(key);
|
|
512
|
+
}
|
|
513
|
+
deleteNote(key) {
|
|
514
|
+
this.scratchpad.delete(key);
|
|
515
|
+
}
|
|
516
|
+
// --- Conversation(对外 API)---
|
|
517
|
+
addConversationTurn(role, content) {
|
|
518
|
+
this.conversation.add(role, content);
|
|
519
|
+
}
|
|
520
|
+
getConversationCount() {
|
|
521
|
+
return this.conversation.count();
|
|
522
|
+
}
|
|
523
|
+
// --- Scratchpad → Persisted(笔记提升为持久记忆)---
|
|
524
|
+
promoteNoteToMemory(key, importance = 0.6) {
|
|
525
|
+
const value = this.scratchpad.get(key);
|
|
526
|
+
if (!value)
|
|
527
|
+
return false;
|
|
528
|
+
this.persisted.add("[笔记->记忆] " + key + ": " + value, "manual", importance);
|
|
529
|
+
this.scratchpad.delete(key);
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
// --- 统一接口:格式化提示字符串 ---
|
|
533
|
+
formatPromptForContext(limit = 10) {
|
|
534
|
+
const parts = [];
|
|
535
|
+
const scratchpadStr = this.scratchpad.formatForPrompt();
|
|
536
|
+
if (scratchpadStr)
|
|
537
|
+
parts.push(scratchpadStr);
|
|
538
|
+
const persistedStr = this.persisted.formatForPrompt(limit);
|
|
539
|
+
if (persistedStr)
|
|
540
|
+
parts.push(persistedStr);
|
|
541
|
+
const globalStr = this.globalPersisted.formatForPrompt(limit);
|
|
542
|
+
if (globalStr)
|
|
543
|
+
parts.push("[全局记忆]\n" + globalStr);
|
|
544
|
+
if (parts.length === 0)
|
|
545
|
+
return null;
|
|
546
|
+
return parts.join("\n\n");
|
|
547
|
+
}
|
|
548
|
+
// --- 统一接口:保存到磁盘 ---
|
|
549
|
+
async saveToDisk() {
|
|
550
|
+
await this.globalPersisted.saveToDisk();
|
|
551
|
+
await this.persisted.saveToDisk();
|
|
552
|
+
}
|
|
553
|
+
// --- 会话重置(不清持久化)---
|
|
554
|
+
resetSession() {
|
|
555
|
+
this.scratchpad.clear();
|
|
556
|
+
this.conversation.clear();
|
|
557
|
+
}
|
|
558
|
+
// --- 全量导出(用于压缩合并)---
|
|
559
|
+
exportPersisted() {
|
|
560
|
+
return this.persisted.getAll();
|
|
561
|
+
}
|
|
562
|
+
// --- 全量导入(用于压缩合并后恢复)---
|
|
563
|
+
importPersisted(entries) {
|
|
564
|
+
this.persisted.merge(entries);
|
|
565
|
+
}
|
|
566
|
+
compactPersisted(maxEntries) {
|
|
567
|
+
this.persisted.compact(maxEntries);
|
|
568
|
+
}
|
|
569
|
+
getWorkspaceMemoryDir() {
|
|
570
|
+
return this.workspaceMemoryDir;
|
|
571
|
+
}
|
|
572
|
+
getGlobalMemoryDir() {
|
|
573
|
+
return this.globalMemoryDir;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
export async function extractDreamMemories(ctx, config) {
|
|
577
|
+
if (ctx.turnCount < config.turnThreshold)
|
|
578
|
+
return [];
|
|
579
|
+
const recent = ctx.transcript.slice(-(config.transcriptWindow ?? 4));
|
|
580
|
+
const combined = recent.join("\n---\n");
|
|
581
|
+
const patterns = [
|
|
582
|
+
/(?:记住|记得|重要|不要忘记)[::]\s*(.+)/gi,
|
|
583
|
+
/(?:项目|技术栈|框架)[::]\s*(\S+)/gi,
|
|
584
|
+
/(?:工作目录)[::]\s*(\S+)/gi,
|
|
585
|
+
/(?:使用|调用)[::]\s*(\S+)/gi,
|
|
586
|
+
/([/\.a-zA-Z0-9_-]+\.(?:ts|js|py|md|json|yml|yaml|sh))/g,
|
|
587
|
+
];
|
|
588
|
+
const memories = [];
|
|
589
|
+
for (const pat of patterns) {
|
|
590
|
+
let match;
|
|
591
|
+
while ((match = pat.exec(combined)) !== null) {
|
|
592
|
+
memories.push(match[1].trim());
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return Array.from(new Set(memories));
|
|
596
|
+
}
|
|
597
|
+
// --- Token Budget Manager ---
|
|
598
|
+
export class TokenBudgetManager {
|
|
599
|
+
maxTokens;
|
|
600
|
+
nudgeThreshold;
|
|
601
|
+
usedTokens;
|
|
602
|
+
constructor(maxTokens, nudgeThreshold = 0.2, usedTokens = 0) {
|
|
603
|
+
this.maxTokens = maxTokens;
|
|
604
|
+
this.nudgeThreshold = nudgeThreshold;
|
|
605
|
+
this.usedTokens = usedTokens;
|
|
606
|
+
}
|
|
607
|
+
addUsage(tokens) {
|
|
608
|
+
this.usedTokens += tokens;
|
|
609
|
+
}
|
|
610
|
+
syncUsage(actualTokens) {
|
|
611
|
+
this.usedTokens = actualTokens;
|
|
612
|
+
}
|
|
613
|
+
reset() {
|
|
614
|
+
this.usedTokens = 0;
|
|
615
|
+
}
|
|
616
|
+
getRemaining() {
|
|
617
|
+
return this.maxTokens - this.usedTokens;
|
|
618
|
+
}
|
|
619
|
+
getRemainingPct() {
|
|
620
|
+
return this.getRemaining() / this.maxTokens;
|
|
621
|
+
}
|
|
622
|
+
shouldNudge() {
|
|
623
|
+
return this.getRemainingPct() < this.nudgeThreshold;
|
|
624
|
+
}
|
|
625
|
+
buildNudgeMessage() {
|
|
626
|
+
const pct = Math.round(this.getRemainingPct() * 100);
|
|
627
|
+
return "Token 预算即将耗尽(剩余 " + pct + "%),请精简回复,减少工具调用频率。";
|
|
628
|
+
}
|
|
629
|
+
estimateMessagesCost(messages) {
|
|
630
|
+
return messages.reduce((sum, m) => sum + m.content.length * 4, 0);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MetricsCollector } from "./collector.js";
|
|
2
|
+
export declare class AgentTelemetry {
|
|
3
|
+
private collector;
|
|
4
|
+
private sessionId;
|
|
5
|
+
constructor(collector: MetricsCollector, sessionId: string);
|
|
6
|
+
recordTurnStart(turn: number): void;
|
|
7
|
+
recordTurnEnd(turn: number, toolCalls: number, toolFailures: number, tokens: number): void;
|
|
8
|
+
recordToolCall(toolName: string, durationMs: number, success: boolean): void;
|
|
9
|
+
recordCompaction(before: number, after: number): void;
|
|
10
|
+
recordMemoryWrite(source: string): void;
|
|
11
|
+
recordSessionEnd(): void;
|
|
12
|
+
flush(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=agent-telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-telemetry.d.ts","sourceRoot":"","sources":["../../src/metrics/agent-telemetry.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,SAAS,CAAS;gBAEd,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM;IAK1D,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAInC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO1F,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAO5E,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAOrD,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAOvC,gBAAgB,IAAI,IAAI;IAIlB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Agent Telemetry(Agent 遥测封装)
|
|
3
|
+
// ============================================================
|
|
4
|
+
export class AgentTelemetry {
|
|
5
|
+
collector;
|
|
6
|
+
sessionId;
|
|
7
|
+
constructor(collector, sessionId) {
|
|
8
|
+
this.collector = collector;
|
|
9
|
+
this.sessionId = sessionId;
|
|
10
|
+
}
|
|
11
|
+
recordTurnStart(turn) {
|
|
12
|
+
this.collector.record({ type: "turn_complete", data: { turn, phase: "start" } });
|
|
13
|
+
}
|
|
14
|
+
recordTurnEnd(turn, toolCalls, toolFailures, tokens) {
|
|
15
|
+
this.collector.record({
|
|
16
|
+
type: "turn_complete",
|
|
17
|
+
data: { turn, toolCalls, toolFailures, tokens },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
recordToolCall(toolName, durationMs, success) {
|
|
21
|
+
this.collector.record({
|
|
22
|
+
type: success ? "tool_call" : "tool_error",
|
|
23
|
+
data: { toolName, durationMs },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
recordCompaction(before, after) {
|
|
27
|
+
this.collector.record({
|
|
28
|
+
type: "compaction",
|
|
29
|
+
data: { before, after, removed: before - after },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
recordMemoryWrite(source) {
|
|
33
|
+
this.collector.record({
|
|
34
|
+
type: "memory_write",
|
|
35
|
+
data: { source },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
recordSessionEnd() {
|
|
39
|
+
this.collector.record({ type: "session_end", data: {} });
|
|
40
|
+
}
|
|
41
|
+
async flush() {
|
|
42
|
+
await this.collector.flush();
|
|
43
|
+
}
|
|
44
|
+
}
|