@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,377 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Pipeline Hook 系统(参考 Claude Code 5.x Hook 架构)
|
|
3
|
+
// ============================================================
|
|
4
|
+
import { PermissionMatrix } from "../guard/permissions.js";
|
|
5
|
+
import { RateLimiter } from "../guard/rate-limit.js";
|
|
6
|
+
import { appendGuardAudit } from "../guard.js";
|
|
7
|
+
// --- 0. 动态工具选择器(<30 工具限制 + 场景路由)---
|
|
8
|
+
const MAX_TOOLS_DEFAULT = 30;
|
|
9
|
+
export class DynamicToolSelector {
|
|
10
|
+
allTools;
|
|
11
|
+
maxTools;
|
|
12
|
+
constructor(allTools, maxTools = MAX_TOOLS_DEFAULT) {
|
|
13
|
+
this.allTools = allTools;
|
|
14
|
+
this.maxTools = maxTools;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 根据场景选择工具子集。
|
|
18
|
+
* 策略:
|
|
19
|
+
* 1. activeScene 中声明的工具优先
|
|
20
|
+
* 2. 未声明场景的工具(通用工具如 read/write)始终保留
|
|
21
|
+
* 3. 按 priority 排序后截断到 maxTools
|
|
22
|
+
*/
|
|
23
|
+
selectForScene(activeScene) {
|
|
24
|
+
if (this.allTools.length <= this.maxTools) {
|
|
25
|
+
return this.allTools;
|
|
26
|
+
}
|
|
27
|
+
const scored = this.allTools.map((tool) => {
|
|
28
|
+
let score = tool.priority ?? 5;
|
|
29
|
+
// 场景匹配加 20 分
|
|
30
|
+
if (tool.scenes?.includes(activeScene)) {
|
|
31
|
+
score += 20;
|
|
32
|
+
}
|
|
33
|
+
// 核心工具(read/write/bash)不受场景限制
|
|
34
|
+
const coreTools = ["read", "write", "bash"];
|
|
35
|
+
if (coreTools.includes(tool.name)) {
|
|
36
|
+
score += 50;
|
|
37
|
+
}
|
|
38
|
+
return { tool, score };
|
|
39
|
+
});
|
|
40
|
+
scored.sort((a, b) => b.score - a.score);
|
|
41
|
+
return scored.slice(0, this.maxTools).map((s) => s.tool);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 根据任务类型关键词选择工具。
|
|
45
|
+
* 关键词匹配 scenes 或 name。
|
|
46
|
+
*/
|
|
47
|
+
selectByKeywords(keywords) {
|
|
48
|
+
if (this.allTools.length <= this.maxTools) {
|
|
49
|
+
return this.allTools;
|
|
50
|
+
}
|
|
51
|
+
const scored = this.allTools.map((tool) => {
|
|
52
|
+
let score = tool.priority ?? 5;
|
|
53
|
+
for (const kw of keywords) {
|
|
54
|
+
if (tool.name.includes(kw))
|
|
55
|
+
score += 10;
|
|
56
|
+
if (tool.scenes?.some((s) => s.includes(kw)))
|
|
57
|
+
score += 5;
|
|
58
|
+
if (tool.description.toLowerCase().includes(kw.toLowerCase()))
|
|
59
|
+
score += 2;
|
|
60
|
+
}
|
|
61
|
+
return { tool, score };
|
|
62
|
+
});
|
|
63
|
+
scored.sort((a, b) => b.score - a.score);
|
|
64
|
+
return scored.slice(0, this.maxTools).map((s) => s.tool);
|
|
65
|
+
}
|
|
66
|
+
getAll() {
|
|
67
|
+
return this.allTools;
|
|
68
|
+
}
|
|
69
|
+
getCount() {
|
|
70
|
+
return this.allTools.length;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// --- 1. Dangerous Pattern Registry ---
|
|
74
|
+
const BUILT_IN_DANGEROUS_PATTERNS = [
|
|
75
|
+
// 文件删除
|
|
76
|
+
/\brm\s+-rf\s+\//,
|
|
77
|
+
/\bdel\s+\/[sfq]\b/i,
|
|
78
|
+
/rmdir\s+\/[efqs]/i,
|
|
79
|
+
// 格式化
|
|
80
|
+
/\bformat\b.*\b[a-z]:/i,
|
|
81
|
+
/\bnewfs\b/,
|
|
82
|
+
// 权限修改
|
|
83
|
+
/\bchmod\s+777\b/,
|
|
84
|
+
/\bchmod\s+-R\s+777\b/,
|
|
85
|
+
// 网络相关
|
|
86
|
+
/\bwget\b.*\s--no-check-certificate/,
|
|
87
|
+
/\bcurl\b.*\s-k\b/,
|
|
88
|
+
// 提权
|
|
89
|
+
/\bsudo\s+su\b/,
|
|
90
|
+
/\bsu\s+-\b/,
|
|
91
|
+
// 危险管道
|
|
92
|
+
/\|.*\s*sh\b/,
|
|
93
|
+
/\|.*\s*bash\b/,
|
|
94
|
+
// 进程终止
|
|
95
|
+
/\bkill\s+-9\b/,
|
|
96
|
+
/\bpkill\s+-9\b/,
|
|
97
|
+
// 敏感文件
|
|
98
|
+
/\/etc\/passwd/,
|
|
99
|
+
/\/etc\/shadow/,
|
|
100
|
+
/\.ssh\/authorized_keys/,
|
|
101
|
+
// 内存修改
|
|
102
|
+
/\bdd\b.*\sif=.*\bof=\/dev/,
|
|
103
|
+
];
|
|
104
|
+
function matchDangerousPatterns(cmd, patterns) {
|
|
105
|
+
const allPatterns = [
|
|
106
|
+
...BUILT_IN_DANGEROUS_PATTERNS,
|
|
107
|
+
...patterns,
|
|
108
|
+
];
|
|
109
|
+
const matched = [];
|
|
110
|
+
for (const p of allPatterns) {
|
|
111
|
+
const re = typeof p === "string" ? new RegExp(p) : p;
|
|
112
|
+
if (re.test(cmd)) {
|
|
113
|
+
matched.push(typeof p === "string" ? p : String(p));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return matched;
|
|
117
|
+
}
|
|
118
|
+
// --- 2. Speculative Classifier(3.2 节)---
|
|
119
|
+
export class SpeculativeClassifier {
|
|
120
|
+
toolDefs;
|
|
121
|
+
constructor(toolDefs) {
|
|
122
|
+
this.toolDefs = toolDefs;
|
|
123
|
+
}
|
|
124
|
+
classify(toolCall) {
|
|
125
|
+
const def = this.toolDefs.find((t) => t.name === toolCall.name);
|
|
126
|
+
// bash 类工具才需要分类
|
|
127
|
+
if (toolCall.name !== "bash") {
|
|
128
|
+
return { label: "safe" };
|
|
129
|
+
}
|
|
130
|
+
const cmd = String(toolCall.arguments.command ?? "");
|
|
131
|
+
if (!cmd)
|
|
132
|
+
return { label: "safe" };
|
|
133
|
+
const matched = matchDangerousPatterns(cmd, def?.dangerousPatterns ?? []);
|
|
134
|
+
if (matched.length > 0) {
|
|
135
|
+
return {
|
|
136
|
+
label: "dangerous",
|
|
137
|
+
reason: `匹配危险模式: ${matched.join(", ")}`,
|
|
138
|
+
patterns: matched,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// 读操作风险低
|
|
142
|
+
if (def?.readOnly ||
|
|
143
|
+
/^\s*(ls|git\s+(status|log|diff)|cat|head|tail|grep|find|wc|echo|pwd)\s/.test(cmd)) {
|
|
144
|
+
return { label: "safe" };
|
|
145
|
+
}
|
|
146
|
+
// 写/删除操作需要询问(仅明确危险的操作才拦截)
|
|
147
|
+
// curl/wget GET 请求是只读的,不拦截
|
|
148
|
+
// tee / 追加写入属于中等风险,放宽判断
|
|
149
|
+
if (def?.destructive ||
|
|
150
|
+
/\b(del|rmdir|rm\s+-rf|mkfs|truncate\s+-s\s+0)\b/.test(cmd)) {
|
|
151
|
+
return { label: "ask" };
|
|
152
|
+
}
|
|
153
|
+
return { label: "safe" };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// --- 3. Hook Manager ---
|
|
157
|
+
/** Plan 模式下禁止的写/执行类工具(OpenCode plan agent 语义) */
|
|
158
|
+
export const PLAN_MODE_DENY_TOOLS = [
|
|
159
|
+
"write",
|
|
160
|
+
"patch",
|
|
161
|
+
"bash",
|
|
162
|
+
"subtask",
|
|
163
|
+
"browser_fetch",
|
|
164
|
+
];
|
|
165
|
+
export class HookManager {
|
|
166
|
+
preHooks = [];
|
|
167
|
+
postHooks = [];
|
|
168
|
+
failureHooks = [];
|
|
169
|
+
classifier;
|
|
170
|
+
permissionMatrix = null;
|
|
171
|
+
rateLimiter = null;
|
|
172
|
+
guardConfig = null;
|
|
173
|
+
planMode = false;
|
|
174
|
+
constructor(toolDefs, guardConfig) {
|
|
175
|
+
this.classifier = new SpeculativeClassifier(toolDefs);
|
|
176
|
+
if (guardConfig) {
|
|
177
|
+
this.guardConfig = guardConfig;
|
|
178
|
+
if (guardConfig.permissions) {
|
|
179
|
+
this.permissionMatrix = new PermissionMatrix(guardConfig.permissions.default, this.mergePermissionRules(guardConfig.permissions.rules));
|
|
180
|
+
}
|
|
181
|
+
if (guardConfig.rate_limit?.enabled) {
|
|
182
|
+
this.rateLimiter = new RateLimiter(guardConfig.rate_limit.max_per_minute);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
planModeRules() {
|
|
187
|
+
return PLAN_MODE_DENY_TOOLS.map((tool) => ({
|
|
188
|
+
tool_pattern: tool,
|
|
189
|
+
decision: "deny",
|
|
190
|
+
reason: `Plan Mode: 工具 ${tool} 已禁用(只读规划)。使用 /plan off 退出。`,
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
mergePermissionRules(baseRules = []) {
|
|
194
|
+
// plan 规则优先(放前面)
|
|
195
|
+
return this.planMode ? [...this.planModeRules(), ...baseRules] : baseRules;
|
|
196
|
+
}
|
|
197
|
+
rebuildPermissionMatrix() {
|
|
198
|
+
const defaultDecision = this.guardConfig?.permissions?.default ?? "allow";
|
|
199
|
+
const rules = this.mergePermissionRules(this.guardConfig?.permissions?.rules ?? []);
|
|
200
|
+
this.permissionMatrix = new PermissionMatrix(defaultDecision, rules);
|
|
201
|
+
}
|
|
202
|
+
isPlanMode() {
|
|
203
|
+
return this.planMode;
|
|
204
|
+
}
|
|
205
|
+
setPlanMode(enabled) {
|
|
206
|
+
this.planMode = Boolean(enabled);
|
|
207
|
+
this.rebuildPermissionMatrix();
|
|
208
|
+
}
|
|
209
|
+
getPermissionDefaultDecision() {
|
|
210
|
+
return this.guardConfig?.permissions?.default ?? "allow";
|
|
211
|
+
}
|
|
212
|
+
setPermissionDefaultDecision(decision) {
|
|
213
|
+
const currentRules = this.guardConfig?.permissions?.rules ?? [];
|
|
214
|
+
if (this.guardConfig) {
|
|
215
|
+
this.guardConfig.permissions = {
|
|
216
|
+
...(this.guardConfig.permissions ?? { rules: [] }),
|
|
217
|
+
default: decision,
|
|
218
|
+
rules: currentRules,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
this.rebuildPermissionMatrix();
|
|
222
|
+
}
|
|
223
|
+
register(name, handler) {
|
|
224
|
+
if (name === "PreToolUse")
|
|
225
|
+
this.preHooks.push(handler);
|
|
226
|
+
else if (name === "PostToolUse")
|
|
227
|
+
this.postHooks.push(handler);
|
|
228
|
+
else if (name === "PostToolUseFailure")
|
|
229
|
+
this.failureHooks.push(handler);
|
|
230
|
+
}
|
|
231
|
+
async runPreHook(ctx, sessionId) {
|
|
232
|
+
// 1. Permission matrix check (highest priority)
|
|
233
|
+
if (this.permissionMatrix && this.guardConfig) {
|
|
234
|
+
const permResult = this.permissionMatrix.evaluate(ctx.toolName);
|
|
235
|
+
if (permResult.decision === "deny") {
|
|
236
|
+
await appendGuardAudit(this.guardConfig, {
|
|
237
|
+
tool: ctx.toolName,
|
|
238
|
+
action: "deny",
|
|
239
|
+
category: "permission",
|
|
240
|
+
reason: permResult.reason ?? "denied by permission rule: " + (permResult.matched_rule ?? "default"),
|
|
241
|
+
});
|
|
242
|
+
return {
|
|
243
|
+
decision: "deny",
|
|
244
|
+
blockingError: permResult.reason ?? "工具权限拒绝: " + ctx.toolName,
|
|
245
|
+
preventContinuation: true,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (permResult.decision === "ask") {
|
|
249
|
+
await appendGuardAudit(this.guardConfig, {
|
|
250
|
+
tool: ctx.toolName,
|
|
251
|
+
action: "allow",
|
|
252
|
+
category: "permission",
|
|
253
|
+
reason: "ask triggered by rule: " + (permResult.matched_rule ?? "default"),
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
decision: "ask",
|
|
257
|
+
additionalContexts: [permResult.reason ?? "工具需要确认: " + ctx.toolName],
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// 2. Rate limit check
|
|
262
|
+
if (this.rateLimiter && sessionId) {
|
|
263
|
+
const rlResult = this.rateLimiter.check(ctx.toolName, sessionId);
|
|
264
|
+
if (!rlResult.allowed) {
|
|
265
|
+
if (this.guardConfig) {
|
|
266
|
+
await appendGuardAudit(this.guardConfig, {
|
|
267
|
+
tool: ctx.toolName,
|
|
268
|
+
action: "deny",
|
|
269
|
+
category: "rate_limit",
|
|
270
|
+
reason: `rate limit exceeded, retry after ${rlResult.retryAfterMs}ms`,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
decision: "deny",
|
|
275
|
+
blockingError: `速率限制: 工具 ${ctx.toolName} 调用过于频繁,请 ${Math.ceil((rlResult.retryAfterMs ?? 0) / 1000)}s 后重试`,
|
|
276
|
+
preventContinuation: false,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// 3. Speculative classifier
|
|
281
|
+
const fakeCall = {
|
|
282
|
+
id: "speculative",
|
|
283
|
+
name: ctx.toolName,
|
|
284
|
+
arguments: ctx.arguments,
|
|
285
|
+
};
|
|
286
|
+
const classification = this.classifier.classify(fakeCall);
|
|
287
|
+
if (classification.label === "dangerous") {
|
|
288
|
+
return {
|
|
289
|
+
decision: "deny",
|
|
290
|
+
blockingError: classification.reason ?? "危险命令",
|
|
291
|
+
preventContinuation: true,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (classification.label === "ask") {
|
|
295
|
+
return {
|
|
296
|
+
decision: "ask",
|
|
297
|
+
additionalContexts: classification.patterns
|
|
298
|
+
? [`⚠️ 匹配危险模式: ${classification.patterns.join(", ")}`]
|
|
299
|
+
: ["⚠️ 这个操作可能具有破坏性"],
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// 4. Custom pre-hooks
|
|
303
|
+
for (const handler of this.preHooks) {
|
|
304
|
+
const result = await handler(ctx);
|
|
305
|
+
if (result.decision === "deny")
|
|
306
|
+
return result;
|
|
307
|
+
if (result.decision === "ask")
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
return { decision: "allow" };
|
|
311
|
+
}
|
|
312
|
+
async runPostHook(ctx, result) {
|
|
313
|
+
for (const handler of this.postHooks) {
|
|
314
|
+
await handler(ctx, result);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async runFailureHook(ctx, error) {
|
|
318
|
+
for (const handler of this.failureHooks) {
|
|
319
|
+
await handler(ctx, error);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
export class ToolPipeline {
|
|
324
|
+
toolDefs;
|
|
325
|
+
hookManager;
|
|
326
|
+
sessionId = null;
|
|
327
|
+
constructor(toolDefs, hookManager) {
|
|
328
|
+
this.toolDefs = toolDefs;
|
|
329
|
+
this.hookManager = hookManager;
|
|
330
|
+
}
|
|
331
|
+
setSessionId(id) {
|
|
332
|
+
this.sessionId = id;
|
|
333
|
+
}
|
|
334
|
+
async execute(toolCall, runner) {
|
|
335
|
+
const def = this.toolDefs.find((t) => t.name === toolCall.name);
|
|
336
|
+
const hookCtx = this.buildHookContext(toolCall, def);
|
|
337
|
+
// 1. PreHook(含 Permission Matrix + Rate Limiter + Speculative Classifier)
|
|
338
|
+
const preResult = await this.hookManager.runPreHook(hookCtx, this.sessionId ?? undefined);
|
|
339
|
+
if (preResult.decision === "deny") {
|
|
340
|
+
console.error(`🚫 [Pipeline] 工具 ${toolCall.name} 被 Hook 拦截: ${preResult.blockingError}`);
|
|
341
|
+
return {
|
|
342
|
+
tool_call_id: toolCall.id,
|
|
343
|
+
output: `【权限拒绝】${preResult.blockingError ?? "Hook denied"}`,
|
|
344
|
+
is_error: true,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (preResult.decision === "ask") {
|
|
348
|
+
const { ApprovalRequiredError } = await import("../guard/approval.js");
|
|
349
|
+
throw new ApprovalRequiredError(toolCall.id, toolCall.name, preResult.additionalContexts ?? ["需要确认"]);
|
|
350
|
+
}
|
|
351
|
+
// 2. 执行工具
|
|
352
|
+
try {
|
|
353
|
+
const result = await runner(toolCall);
|
|
354
|
+
// 3. PostHook
|
|
355
|
+
await this.hookManager.runPostHook(hookCtx, result);
|
|
356
|
+
return result;
|
|
357
|
+
}
|
|
358
|
+
catch (err) {
|
|
359
|
+
// 4. Failure Hook
|
|
360
|
+
await this.hookManager.runFailureHook(hookCtx, err);
|
|
361
|
+
throw err;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
buildHookContext(toolCall, def) {
|
|
365
|
+
const cmd = String(toolCall.arguments.command ?? "");
|
|
366
|
+
const matched = matchDangerousPatterns(cmd, def?.dangerousPatterns ?? []);
|
|
367
|
+
return {
|
|
368
|
+
toolName: toolCall.name,
|
|
369
|
+
arguments: toolCall.arguments,
|
|
370
|
+
inputSchema: def?.parameters ?? {},
|
|
371
|
+
isReadOnly: def?.readOnly ?? toolCall.name !== "bash",
|
|
372
|
+
isDestructive: def?.destructive ?? /\b(rm|del|rmdir)\b/.test(cmd),
|
|
373
|
+
isConcurrencySafe: def?.concurrencySafe ?? false,
|
|
374
|
+
dangerousPatterns: matched,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PromptSection, PromptSectionRegistry, AgentConfig } from "../types.js";
|
|
2
|
+
import type { SkillMeta } from "../skills/types.js";
|
|
3
|
+
export declare const SECTION_IDS: {
|
|
4
|
+
readonly INTRO: "intro";
|
|
5
|
+
readonly TOOLS: "tools";
|
|
6
|
+
readonly WORKFLOW: "workflow";
|
|
7
|
+
readonly RESTRICTIONS: "restrictions";
|
|
8
|
+
readonly TONE: "tone";
|
|
9
|
+
readonly REPOMAP: "repomap";
|
|
10
|
+
readonly TOKEN_BUDGET: "token_budget";
|
|
11
|
+
readonly SESSION: "session";
|
|
12
|
+
readonly MCP: "mcp";
|
|
13
|
+
readonly MEMORY: "memory";
|
|
14
|
+
readonly SKILLS: "skills";
|
|
15
|
+
readonly DYNAMIC: "dynamic";
|
|
16
|
+
readonly REFLECTION: "reflection";
|
|
17
|
+
};
|
|
18
|
+
export declare function buildReflectionPrompt(toolName: string, args: any): string;
|
|
19
|
+
export declare function buildIntroSection(name: string, version: string): PromptSection;
|
|
20
|
+
export declare function buildToolsSection(tools: AgentConfig["tools"]): PromptSection;
|
|
21
|
+
export declare function buildWorkflowSection(): PromptSection;
|
|
22
|
+
export declare function buildRestrictionsSection(): PromptSection;
|
|
23
|
+
export declare function buildToneSection(): PromptSection;
|
|
24
|
+
export declare function buildSessionSection(): PromptSection;
|
|
25
|
+
export declare function buildMemorySection(): PromptSection;
|
|
26
|
+
export declare function buildTokenBudgetSection(usedTokens: number, maxTokens: number): PromptSection;
|
|
27
|
+
export declare function buildSkillsSection(skills: SkillMeta[]): PromptSection;
|
|
28
|
+
export declare function buildMCPSection(serverInfo?: string): PromptSection;
|
|
29
|
+
export declare function buildRepoMapSection(symbols: {
|
|
30
|
+
file: string;
|
|
31
|
+
name: string;
|
|
32
|
+
type: string;
|
|
33
|
+
line: number;
|
|
34
|
+
signature: string;
|
|
35
|
+
}[]): PromptSection;
|
|
36
|
+
export declare function buildDefaultRegistry(tools: AgentConfig["tools"], usedTokens?: number, maxTokens?: number): PromptSectionRegistry;
|
|
37
|
+
export declare function buildSystemPrompt(registry: PromptSectionRegistry, dynamicSections?: {
|
|
38
|
+
memory?: string;
|
|
39
|
+
session?: string;
|
|
40
|
+
}): string;
|
|
41
|
+
//# sourceMappingURL=sections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sections.d.ts","sourceRoot":"","sources":["../../src/pipeline/sections.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKpD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAcd,CAAC;AAEX,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,MAAM,CAgBzE;AAID,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAS9E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,aAAa,CAwB5E;AAED,wBAAgB,oBAAoB,IAAI,aAAa,CAYpD;AAED,wBAAgB,wBAAwB,IAAI,aAAa,CAkBxD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAYhD;AAED,wBAAgB,mBAAmB,IAAI,aAAa,CAYnD;AAED,wBAAgB,kBAAkB,IAAI,aAAa,CAUlD;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAe5F;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,aAAa,CAoBrE;AAED,wBAAgB,eAAe,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,aAAa,CAWlE;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,GACvF,aAAa,CA+Bf;AAID,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,EAC3B,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAgB,GAC1B,qBAAqB,CAcvB;AAID,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,MAAM,CAgBR"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Section-based System Prompt(参考 Claude Code 2.4/2.5 节)
|
|
3
|
+
// ============================================================
|
|
4
|
+
import { PromptSectionRegistry } from "../types.js";
|
|
5
|
+
import { buildToolSpecBoostPrompt } from "./example-generator.js";
|
|
6
|
+
import { getPackageVersion } from "../package-version.js";
|
|
7
|
+
// --- 默认 Section IDs ---
|
|
8
|
+
export const SECTION_IDS = {
|
|
9
|
+
INTRO: "intro",
|
|
10
|
+
TOOLS: "tools",
|
|
11
|
+
WORKFLOW: "workflow",
|
|
12
|
+
RESTRICTIONS: "restrictions",
|
|
13
|
+
TONE: "tone",
|
|
14
|
+
REPOMAP: "repomap",
|
|
15
|
+
TOKEN_BUDGET: "token_budget",
|
|
16
|
+
SESSION: "session",
|
|
17
|
+
MCP: "mcp",
|
|
18
|
+
MEMORY: "memory",
|
|
19
|
+
SKILLS: "skills",
|
|
20
|
+
DYNAMIC: "dynamic",
|
|
21
|
+
REFLECTION: "reflection",
|
|
22
|
+
};
|
|
23
|
+
export function buildReflectionPrompt(toolName, args) {
|
|
24
|
+
return `【内心独白 / 风险评估】
|
|
25
|
+
你正准备执行一项具有潜在风险的操作:调用工具 "${toolName}"。
|
|
26
|
+
参数为: ${JSON.stringify(args)}
|
|
27
|
+
|
|
28
|
+
请在内心进行预演评估(无需输出到最终回复,仅作为逻辑判定依据):
|
|
29
|
+
1. 该操作是否具有破坏性?(如删除文件、强制重启、网络请求敏感地址)
|
|
30
|
+
2. 该操作是否与之前的用户指令冲突?
|
|
31
|
+
3. 如果执行失败,是否有恢复预案?
|
|
32
|
+
|
|
33
|
+
请输出 JSON 格式判定:
|
|
34
|
+
{
|
|
35
|
+
"risk_level": "low" | "medium" | "high",
|
|
36
|
+
"decision": "proceed" | "ask" | "block",
|
|
37
|
+
"reason": "简短理由"
|
|
38
|
+
}`;
|
|
39
|
+
}
|
|
40
|
+
// --- 内置 Section Builders ---
|
|
41
|
+
export function buildIntroSection(name, version) {
|
|
42
|
+
return {
|
|
43
|
+
id: SECTION_IDS.INTRO,
|
|
44
|
+
title: "身份",
|
|
45
|
+
content: `你是一个通用的命令行 Agent,名为"${name}" v${version}。你轻量、敏捷、专注。
|
|
46
|
+
当处理艺术、设计、图片分析等创意任务时,你应当展现出细腻的描述能力,完整传达视觉意象,而不仅仅是数据提取。`,
|
|
47
|
+
cacheable: true,
|
|
48
|
+
cached: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function buildToolsSection(tools) {
|
|
52
|
+
const toolList = (tools ?? [])
|
|
53
|
+
.map((t) => `• ${t.name}: ${t.description}${t.effortHint ? ` [effort: ${t.effortHint}]` : ""}`)
|
|
54
|
+
.join("\n");
|
|
55
|
+
let content = `你可用的工具:\n\n${toolList}`;
|
|
56
|
+
// v0.3 Tool Spec Boost
|
|
57
|
+
if (process.env.QLING_FEATURES_TOOL_SPEC_BOOST === "true") {
|
|
58
|
+
content += "\n\n" + buildToolSpecBoostPrompt(tools);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
id: SECTION_IDS.TOOLS,
|
|
62
|
+
title: "工具列表",
|
|
63
|
+
content,
|
|
64
|
+
cacheable: true,
|
|
65
|
+
cached: false,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function buildWorkflowSection() {
|
|
69
|
+
return {
|
|
70
|
+
id: SECTION_IDS.WORKFLOW,
|
|
71
|
+
title: "工作流程",
|
|
72
|
+
content: `【重要工作流程】收到任务时:
|
|
73
|
+
1. 先思考:这个任务需要几步?是否需要规划?
|
|
74
|
+
2. 如果任务复杂(超过2步),先用 todo add 依次列出执行步骤
|
|
75
|
+
3. 然后逐个执行:每完成一步用 todo done 标记
|
|
76
|
+
4. 所有步骤完成后返回清晰总结`,
|
|
77
|
+
cacheable: true,
|
|
78
|
+
cached: false,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function buildRestrictionsSection() {
|
|
82
|
+
return {
|
|
83
|
+
id: SECTION_IDS.RESTRICTIONS,
|
|
84
|
+
title: "限制",
|
|
85
|
+
content: `【工具使用原则】
|
|
86
|
+
- bash:执行命令、安装、构建、运行
|
|
87
|
+
- read:查看文件内容后再决定怎么写
|
|
88
|
+
- write:创建或覆盖文件
|
|
89
|
+
- todo:规划步骤、跟踪进度
|
|
90
|
+
- skill:遇到不熟悉的工具/API/框架时,用 skill 加载对应知识文件
|
|
91
|
+
|
|
92
|
+
【安全限制】
|
|
93
|
+
- 危险命令(rm -rf /、格式化磁盘等)会被自动拒绝
|
|
94
|
+
- 删除/覆盖操作前必须先读取确认
|
|
95
|
+
- 不确定的操作先问用户`,
|
|
96
|
+
cacheable: true,
|
|
97
|
+
cached: false,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function buildToneSection() {
|
|
101
|
+
return {
|
|
102
|
+
id: SECTION_IDS.TONE,
|
|
103
|
+
title: "风格",
|
|
104
|
+
content: `始终用中文回复,除非用户用英文。
|
|
105
|
+
回答应当平衡“简洁”与“丰富”:
|
|
106
|
+
- 对于纯技术、文件或系统操作:保持极致简洁,给出完成报告。
|
|
107
|
+
- 对于图片分析、创意设计或意境咨询:**禁止使用表格 (Table)**。你应当使用分段的叙述性文字、文学化的词汇和排比句,完整转述视觉意象和氛围。**绝对不要将感性描述提取为结构化数据列。**
|
|
108
|
+
工具执行结果用 ✅(成功)或 ❌(失败)标记。`,
|
|
109
|
+
cacheable: true,
|
|
110
|
+
cached: false,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function buildSessionSection() {
|
|
114
|
+
return {
|
|
115
|
+
id: SECTION_IDS.SESSION,
|
|
116
|
+
title: "会话",
|
|
117
|
+
content: `当前会话可以用来:
|
|
118
|
+
- 记住项目上下文(当前工作目录、使用的技术栈)
|
|
119
|
+
- 记住用户的偏好设置
|
|
120
|
+
- 跨任务保持状态`,
|
|
121
|
+
cacheable: false, // 动态,每次都重新生成
|
|
122
|
+
dynamic: true,
|
|
123
|
+
cached: false,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function buildMemorySection() {
|
|
127
|
+
return {
|
|
128
|
+
id: SECTION_IDS.MEMORY,
|
|
129
|
+
title: "记忆",
|
|
130
|
+
content: `【长期记忆】(从 ~/.qling/memory/ 加载)
|
|
131
|
+
如无记忆则忽略此节。`,
|
|
132
|
+
cacheable: false,
|
|
133
|
+
dynamic: true,
|
|
134
|
+
cached: false,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export function buildTokenBudgetSection(usedTokens, maxTokens) {
|
|
138
|
+
const remaining = maxTokens - usedTokens;
|
|
139
|
+
const pct = Math.round((remaining / maxTokens) * 100);
|
|
140
|
+
return {
|
|
141
|
+
id: SECTION_IDS.TOKEN_BUDGET,
|
|
142
|
+
title: "Token 预算",
|
|
143
|
+
content: `【Token 预算】
|
|
144
|
+
已使用: ~${usedTokens.toLocaleString()} tokens
|
|
145
|
+
剩余: ~${remaining.toLocaleString()} tokens (${pct}%)
|
|
146
|
+
当剩余低于 20% 时,主动精简回复,减少工具调用频率。`,
|
|
147
|
+
cacheable: false,
|
|
148
|
+
dynamic: true,
|
|
149
|
+
cached: false,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export function buildSkillsSection(skills) {
|
|
153
|
+
if (skills.length === 0) {
|
|
154
|
+
return {
|
|
155
|
+
id: SECTION_IDS.SKILLS,
|
|
156
|
+
title: "可用技能",
|
|
157
|
+
content: "当前无可用技能。在 skills/ 目录下创建 .md 文件即可添加。",
|
|
158
|
+
cacheable: false,
|
|
159
|
+
dynamic: true,
|
|
160
|
+
cached: false,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const lines = skills.map((s) => `- ${s.name}: ${s.description || "(无描述)"}`);
|
|
164
|
+
return {
|
|
165
|
+
id: SECTION_IDS.SKILLS,
|
|
166
|
+
title: "可用技能",
|
|
167
|
+
content: `【可用技能】(用 skill name="xxx" 加载)\n${lines.join("\n")}`,
|
|
168
|
+
cacheable: false,
|
|
169
|
+
dynamic: true,
|
|
170
|
+
cached: false,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export function buildMCPSection(serverInfo) {
|
|
174
|
+
return {
|
|
175
|
+
id: SECTION_IDS.MCP,
|
|
176
|
+
title: "MCP 服务器",
|
|
177
|
+
content: serverInfo
|
|
178
|
+
? `【MCP 服务器】\n${serverInfo}`
|
|
179
|
+
: `【MCP 服务器】\n当前无可用 MCP 服务器。如有配置将在此处显示。`,
|
|
180
|
+
cacheable: false,
|
|
181
|
+
dynamic: true,
|
|
182
|
+
cached: false,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export function buildRepoMapSection(symbols) {
|
|
186
|
+
const fileGroups = new Map();
|
|
187
|
+
for (const sym of symbols) {
|
|
188
|
+
if (!fileGroups.has(sym.file)) {
|
|
189
|
+
fileGroups.set(sym.file, []);
|
|
190
|
+
}
|
|
191
|
+
fileGroups.get(sym.file).push(sym);
|
|
192
|
+
}
|
|
193
|
+
const lines = [];
|
|
194
|
+
const sortedFiles = Array.from(fileGroups.keys()).sort();
|
|
195
|
+
for (const file of sortedFiles) {
|
|
196
|
+
lines.push(`📄 ${file}`);
|
|
197
|
+
const fileSymbols = fileGroups.get(file);
|
|
198
|
+
fileSymbols.sort((a, b) => a.line - b.line);
|
|
199
|
+
for (const sym of fileSymbols) {
|
|
200
|
+
lines.push(` - [${sym.type}] L${sym.line}: ${sym.name} (${sym.signature})`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const content = lines.length > 0
|
|
204
|
+
? `已编制项目符号索引,供全局参考:\n\n${lines.join("\n")}`
|
|
205
|
+
: "当前没有索引到项目符号。运行 /repomap 命令来索引符号。";
|
|
206
|
+
return {
|
|
207
|
+
id: SECTION_IDS.REPOMAP,
|
|
208
|
+
title: "代码地图",
|
|
209
|
+
content,
|
|
210
|
+
cacheable: true,
|
|
211
|
+
cached: false,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
// --- 默认 Registry Builder ---
|
|
215
|
+
export function buildDefaultRegistry(tools, usedTokens = 0, maxTokens = 120_000) {
|
|
216
|
+
const registry = new PromptSectionRegistry();
|
|
217
|
+
registry.register(buildIntroSection("轻灵", getPackageVersion()));
|
|
218
|
+
registry.register(buildToolsSection(tools));
|
|
219
|
+
registry.register(buildWorkflowSection());
|
|
220
|
+
registry.register(buildRestrictionsSection());
|
|
221
|
+
registry.register(buildToneSection());
|
|
222
|
+
registry.register(buildRepoMapSection([]));
|
|
223
|
+
registry.register(buildSessionSection());
|
|
224
|
+
registry.register(buildMemorySection());
|
|
225
|
+
registry.register(buildTokenBudgetSection(usedTokens, maxTokens));
|
|
226
|
+
return registry;
|
|
227
|
+
}
|
|
228
|
+
// --- Prompt Builder Utility ---
|
|
229
|
+
export function buildSystemPrompt(registry, dynamicSections) {
|
|
230
|
+
// 更新动态 section
|
|
231
|
+
const sessionSec = registry.get(SECTION_IDS.SESSION);
|
|
232
|
+
if (sessionSec && dynamicSections?.session) {
|
|
233
|
+
sessionSec.content = `【会话上下文】\n${dynamicSections.session}`;
|
|
234
|
+
}
|
|
235
|
+
const memorySec = registry.get(SECTION_IDS.MEMORY);
|
|
236
|
+
if (memorySec && dynamicSections?.memory) {
|
|
237
|
+
memorySec.content = `【长期记忆】(从 ~/.qling/memory/ 加载)\n${dynamicSections.memory}`;
|
|
238
|
+
}
|
|
239
|
+
else if (memorySec) {
|
|
240
|
+
memorySec.content = `【长期记忆】(从 ~/.qling/memory/ 加载)\n如无记忆则忽略此节。`;
|
|
241
|
+
}
|
|
242
|
+
// 按顺序拼装
|
|
243
|
+
return registry.buildPrompt();
|
|
244
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VerificationResult } from "../types.js";
|
|
2
|
+
export declare class VerificationAgent {
|
|
3
|
+
private apiKey;
|
|
4
|
+
private model;
|
|
5
|
+
constructor(apiKey: string, model?: string);
|
|
6
|
+
verify(operation: string, expectedOutcome: string, actualOutput: string, context?: string): Promise<VerificationResult>;
|
|
7
|
+
private verifyWithLLM;
|
|
8
|
+
private callLLM;
|
|
9
|
+
private parseResponse;
|
|
10
|
+
private ruleBasedVerify;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=verification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/pipeline/verification.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,kBAAkB,EAGnB,MAAM,aAAa,CAAC;AAmBrB,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;gBADL,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAwB;IAGnC,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,kBAAkB,CAAC;YAiBhB,aAAa;YAkBb,OAAO;IAoBrB,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,eAAe;CAyCxB"}
|