@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,28 @@
|
|
|
1
|
+
export type GitAutoCommitMode = "off" | "on" | "ask";
|
|
2
|
+
export interface AutoCommitInput {
|
|
3
|
+
workspaceDir: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
toolName: string;
|
|
6
|
+
mode?: GitAutoCommitMode;
|
|
7
|
+
/** 可注入以便单测 */
|
|
8
|
+
runGit?: (args: string[], cwd: string) => Promise<{
|
|
9
|
+
stdout: string;
|
|
10
|
+
stderr: string;
|
|
11
|
+
}>;
|
|
12
|
+
isGitRepo?: (cwd: string) => boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface AutoCommitResult {
|
|
15
|
+
mode: GitAutoCommitMode;
|
|
16
|
+
attempted: boolean;
|
|
17
|
+
committed: boolean;
|
|
18
|
+
message: string;
|
|
19
|
+
commitSubject?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function resolveGitAutoCommitMode(env?: NodeJS.ProcessEnv | Record<string, string | undefined>): GitAutoCommitMode;
|
|
22
|
+
export declare function buildAutoCommitSubject(toolName: string, relPath: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* 在 write/patch 成功后按策略尝试 git add + commit。
|
|
25
|
+
* 失败不抛到调用方工具结果(返回 message 由上层附加提示)。
|
|
26
|
+
*/
|
|
27
|
+
export declare function maybeAutoCommitAfterWrite(input: AutoCommitInput): Promise<AutoCommitResult>;
|
|
28
|
+
//# sourceMappingURL=auto-commit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-commit.d.ts","sourceRoot":"","sources":["../../src/git/auto-commit.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,cAAc;IACd,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtF,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CACtC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,iBAAiB,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,wBAAwB,CACtC,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACxE,iBAAiB,CAKnB;AAmBD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIhF;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAyEjG"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - 写工具后的可选 Git 自动提交策略
|
|
3
|
+
// QLING_GIT_AUTO_COMMIT=off|on|ask (默认 off)
|
|
4
|
+
// ============================================================
|
|
5
|
+
import { execFile } from "child_process";
|
|
6
|
+
import { promisify } from "util";
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
import { join, relative, resolve } from "path";
|
|
9
|
+
const execFileAsync = promisify(execFile);
|
|
10
|
+
export function resolveGitAutoCommitMode(env = process.env) {
|
|
11
|
+
const raw = String(env.QLING_GIT_AUTO_COMMIT ?? "off").trim().toLowerCase();
|
|
12
|
+
if (raw === "on" || raw === "true" || raw === "1" || raw === "yes")
|
|
13
|
+
return "on";
|
|
14
|
+
if (raw === "ask" || raw === "prompt")
|
|
15
|
+
return "ask";
|
|
16
|
+
return "off";
|
|
17
|
+
}
|
|
18
|
+
function defaultIsGitRepo(cwd) {
|
|
19
|
+
return existsSync(join(cwd, ".git"));
|
|
20
|
+
}
|
|
21
|
+
async function defaultRunGit(args, cwd) {
|
|
22
|
+
const res = await execFileAsync("git", args, {
|
|
23
|
+
cwd,
|
|
24
|
+
timeout: 15_000,
|
|
25
|
+
windowsHide: true,
|
|
26
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
stdout: String(res.stdout ?? ""),
|
|
30
|
+
stderr: String(res.stderr ?? ""),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function buildAutoCommitSubject(toolName, relPath) {
|
|
34
|
+
const safeTool = toolName.replace(/[^\w.-]+/g, "") || "edit";
|
|
35
|
+
const safePath = relPath.replace(/\\/g, "/");
|
|
36
|
+
return `qling: ${safeTool} ${safePath}`.slice(0, 200);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 在 write/patch 成功后按策略尝试 git add + commit。
|
|
40
|
+
* 失败不抛到调用方工具结果(返回 message 由上层附加提示)。
|
|
41
|
+
*/
|
|
42
|
+
export async function maybeAutoCommitAfterWrite(input) {
|
|
43
|
+
const mode = input.mode ?? resolveGitAutoCommitMode();
|
|
44
|
+
const workspaceDir = resolve(input.workspaceDir || process.cwd());
|
|
45
|
+
const absPath = resolve(input.filePath);
|
|
46
|
+
let relPath;
|
|
47
|
+
try {
|
|
48
|
+
relPath = relative(workspaceDir, absPath).replace(/\\/g, "/") || absPath;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
relPath = absPath;
|
|
52
|
+
}
|
|
53
|
+
if (mode === "off") {
|
|
54
|
+
return {
|
|
55
|
+
mode,
|
|
56
|
+
attempted: false,
|
|
57
|
+
committed: false,
|
|
58
|
+
message: "git auto-commit=off",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (mode === "ask") {
|
|
62
|
+
return {
|
|
63
|
+
mode,
|
|
64
|
+
attempted: false,
|
|
65
|
+
committed: false,
|
|
66
|
+
message: `git auto-commit=ask:已修改 ${relPath}。确认后可运行 /commit 提交。`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// mode === "on"
|
|
70
|
+
const isGit = (input.isGitRepo ?? defaultIsGitRepo)(workspaceDir);
|
|
71
|
+
if (!isGit) {
|
|
72
|
+
return {
|
|
73
|
+
mode,
|
|
74
|
+
attempted: false,
|
|
75
|
+
committed: false,
|
|
76
|
+
message: `git auto-commit=on 但 ${workspaceDir} 不是 git 仓库,已跳过。`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const runGit = input.runGit ?? defaultRunGit;
|
|
80
|
+
const subject = buildAutoCommitSubject(input.toolName, relPath);
|
|
81
|
+
try {
|
|
82
|
+
await runGit(["add", "--", absPath], workspaceDir);
|
|
83
|
+
const status = await runGit(["status", "--porcelain", "--", absPath], workspaceDir);
|
|
84
|
+
if (!String(status.stdout || "").trim()) {
|
|
85
|
+
return {
|
|
86
|
+
mode,
|
|
87
|
+
attempted: true,
|
|
88
|
+
committed: false,
|
|
89
|
+
message: `git auto-commit: ${relPath} 无待提交变更(可能已被忽略)。`,
|
|
90
|
+
commitSubject: subject,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
await runGit(["commit", "-m", subject], workspaceDir);
|
|
94
|
+
return {
|
|
95
|
+
mode,
|
|
96
|
+
attempted: true,
|
|
97
|
+
committed: true,
|
|
98
|
+
message: `git auto-commit: 已提交「${subject}」`,
|
|
99
|
+
commitSubject: subject,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
104
|
+
return {
|
|
105
|
+
mode,
|
|
106
|
+
attempted: true,
|
|
107
|
+
committed: false,
|
|
108
|
+
message: `git auto-commit 失败: ${detail}`,
|
|
109
|
+
commitSubject: subject,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ApprovalRequest, ApprovalResponse } from "../channels/types.js";
|
|
2
|
+
export declare class ApprovalGate {
|
|
3
|
+
private pending;
|
|
4
|
+
requestApproval(request: ApprovalRequest, channel: {
|
|
5
|
+
requestApproval: (req: ApprovalRequest) => Promise<ApprovalResponse>;
|
|
6
|
+
}, timeoutMs?: number): Promise<ApprovalResponse>;
|
|
7
|
+
getPendingCount(): number;
|
|
8
|
+
cancelAll(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class ApprovalRequiredError extends Error {
|
|
11
|
+
toolCallId: string;
|
|
12
|
+
toolName: string;
|
|
13
|
+
reasons: string[];
|
|
14
|
+
constructor(toolCallId: string, toolName: string, reasons: string[]);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=approval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval.d.ts","sourceRoot":"","sources":["../../src/guard/approval.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAMX;IAEE,eAAe,CACnB,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE;QAAE,eAAe,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAA;KAAE,EACjF,SAAS,GAAE,MAAgB,GAC1B,OAAO,CAAC,gBAAgB,CAAC;IAsC5B,eAAe,IAAI,MAAM;IAIzB,SAAS,IAAI,IAAI;CAWlB;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;gBAEN,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;CAOpE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Approval Gate(审批流)
|
|
3
|
+
// Promise 暂停机制 + 超时自动拒绝
|
|
4
|
+
// ============================================================
|
|
5
|
+
export class ApprovalGate {
|
|
6
|
+
pending = new Map();
|
|
7
|
+
async requestApproval(request, channel, timeoutMs = 300_000) {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
const timer = setTimeout(() => {
|
|
10
|
+
if (this.pending.has(request.id)) {
|
|
11
|
+
this.pending.delete(request.id);
|
|
12
|
+
resolve({
|
|
13
|
+
requestId: request.id,
|
|
14
|
+
decision: "deny",
|
|
15
|
+
timestamp: Date.now(),
|
|
16
|
+
});
|
|
17
|
+
console.error("[Approval] Timeout auto-denied: " + request.id);
|
|
18
|
+
}
|
|
19
|
+
}, timeoutMs);
|
|
20
|
+
this.pending.set(request.id, { resolve, timer });
|
|
21
|
+
channel.requestApproval(request).then((response) => {
|
|
22
|
+
const pending = this.pending.get(request.id);
|
|
23
|
+
if (pending) {
|
|
24
|
+
clearTimeout(pending.timer);
|
|
25
|
+
this.pending.delete(request.id);
|
|
26
|
+
resolve(response);
|
|
27
|
+
}
|
|
28
|
+
}).catch(() => {
|
|
29
|
+
const pending = this.pending.get(request.id);
|
|
30
|
+
if (pending) {
|
|
31
|
+
clearTimeout(pending.timer);
|
|
32
|
+
this.pending.delete(request.id);
|
|
33
|
+
resolve({
|
|
34
|
+
requestId: request.id,
|
|
35
|
+
decision: "deny",
|
|
36
|
+
timestamp: Date.now(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getPendingCount() {
|
|
43
|
+
return this.pending.size;
|
|
44
|
+
}
|
|
45
|
+
cancelAll() {
|
|
46
|
+
for (const [id, { resolve, timer }] of this.pending) {
|
|
47
|
+
clearTimeout(timer);
|
|
48
|
+
resolve({
|
|
49
|
+
requestId: id,
|
|
50
|
+
decision: "deny",
|
|
51
|
+
timestamp: Date.now(),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
this.pending.clear();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export class ApprovalRequiredError extends Error {
|
|
58
|
+
toolCallId;
|
|
59
|
+
toolName;
|
|
60
|
+
reasons;
|
|
61
|
+
constructor(toolCallId, toolName, reasons) {
|
|
62
|
+
super("approval_required");
|
|
63
|
+
this.name = "ApprovalRequiredError";
|
|
64
|
+
this.toolCallId = toolCallId;
|
|
65
|
+
this.toolName = toolName;
|
|
66
|
+
this.reasons = reasons;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ContentFilterResult {
|
|
2
|
+
blocked: boolean;
|
|
3
|
+
reason?: string;
|
|
4
|
+
matches?: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function setCustomPatterns(patterns: string[]): void;
|
|
7
|
+
export declare function filterPII(text: string): ContentFilterResult;
|
|
8
|
+
export declare function filterInjection(text: string): ContentFilterResult;
|
|
9
|
+
export declare function filterCustom(text: string): ContentFilterResult;
|
|
10
|
+
export declare function applyContentFilter(text: string, options?: {
|
|
11
|
+
pii?: boolean;
|
|
12
|
+
injection?: boolean;
|
|
13
|
+
custom?: boolean;
|
|
14
|
+
}): ContentFilterResult;
|
|
15
|
+
//# sourceMappingURL=content-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-filter.d.ts","sourceRoot":"","sources":["../../src/guard/content-filter.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAmCD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAU1D;AAID,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAY3D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAYjE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAY9D;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CACb,GACL,mBAAmB,CAgBrB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Guard M2: 内容过滤器
|
|
3
|
+
// PII 检测 + Prompt Injection 扫描
|
|
4
|
+
// ============================================================
|
|
5
|
+
// --- PII Patterns ---
|
|
6
|
+
const PII_PATTERNS = [
|
|
7
|
+
// 中国手机号(1开头11位)
|
|
8
|
+
{ name: "phone_cn", pattern: /1[3-9]\d{9}/g, mask: "***phone***" },
|
|
9
|
+
// 中国身份证号(18位)
|
|
10
|
+
{ name: "id_card_cn", pattern: /\d{6}(19|20)\d{9}[0-9Xx]/g, mask: "***id***" },
|
|
11
|
+
// 邮箱地址
|
|
12
|
+
{ name: "email", pattern: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g, mask: "***email***" },
|
|
13
|
+
// 信用卡号(13-19位数字,可能有空格/横线分隔)
|
|
14
|
+
{ name: "credit_card", pattern: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{1,7}\b/g, mask: "***card***" },
|
|
15
|
+
];
|
|
16
|
+
// --- Prompt Injection Patterns ---
|
|
17
|
+
const INJECTION_PATTERNS = [
|
|
18
|
+
/ignore\s+(all\s+)?previous\s+instructions/i,
|
|
19
|
+
/disregard\s+(all\s+)?prior\s+(instructions|prompts)/i,
|
|
20
|
+
/forget\s+(everything|all)\s+(you|about)/i,
|
|
21
|
+
/you\s+are\s+now\s+(a|an)\s+/i,
|
|
22
|
+
/new\s+instructions?:/i,
|
|
23
|
+
/system\s*:\s*you\s+are/i,
|
|
24
|
+
/\[INST\]/i,
|
|
25
|
+
/\[\/INST\]/i,
|
|
26
|
+
/<\|im_start\|>/i,
|
|
27
|
+
/<\|im_end\|>/i,
|
|
28
|
+
/override\s+(safety|security|content)\s+(filter|policy)/i,
|
|
29
|
+
];
|
|
30
|
+
// --- Custom Patterns ---
|
|
31
|
+
let customPatterns = [];
|
|
32
|
+
export function setCustomPatterns(patterns) {
|
|
33
|
+
customPatterns = patterns
|
|
34
|
+
.map((p) => {
|
|
35
|
+
try {
|
|
36
|
+
return new RegExp(p, "i");
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
.filter((p) => p !== null);
|
|
43
|
+
}
|
|
44
|
+
// --- Filter Functions ---
|
|
45
|
+
export function filterPII(text) {
|
|
46
|
+
const matches = [];
|
|
47
|
+
for (const { name, pattern } of PII_PATTERNS) {
|
|
48
|
+
const found = text.match(pattern);
|
|
49
|
+
if (found) {
|
|
50
|
+
matches.push(...found.map((m) => name + ": " + m));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (matches.length > 0) {
|
|
54
|
+
return { blocked: true, reason: "PII detected", matches };
|
|
55
|
+
}
|
|
56
|
+
return { blocked: false };
|
|
57
|
+
}
|
|
58
|
+
export function filterInjection(text) {
|
|
59
|
+
const matches = [];
|
|
60
|
+
for (const pattern of INJECTION_PATTERNS) {
|
|
61
|
+
const found = text.match(pattern);
|
|
62
|
+
if (found) {
|
|
63
|
+
matches.push(found[0]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (matches.length > 0) {
|
|
67
|
+
return { blocked: true, reason: "prompt injection pattern detected", matches };
|
|
68
|
+
}
|
|
69
|
+
return { blocked: false };
|
|
70
|
+
}
|
|
71
|
+
export function filterCustom(text) {
|
|
72
|
+
const matches = [];
|
|
73
|
+
for (const pattern of customPatterns) {
|
|
74
|
+
const found = text.match(pattern);
|
|
75
|
+
if (found) {
|
|
76
|
+
matches.push(found[0]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (matches.length > 0) {
|
|
80
|
+
return { blocked: true, reason: "custom pattern matched", matches };
|
|
81
|
+
}
|
|
82
|
+
return { blocked: false };
|
|
83
|
+
}
|
|
84
|
+
export function applyContentFilter(text, options = {}) {
|
|
85
|
+
const { pii = true, injection = true, custom = true } = options;
|
|
86
|
+
if (pii) {
|
|
87
|
+
const r = filterPII(text);
|
|
88
|
+
if (r.blocked)
|
|
89
|
+
return r;
|
|
90
|
+
}
|
|
91
|
+
if (injection) {
|
|
92
|
+
const r = filterInjection(text);
|
|
93
|
+
if (r.blocked)
|
|
94
|
+
return r;
|
|
95
|
+
}
|
|
96
|
+
if (custom) {
|
|
97
|
+
const r = filterCustom(text);
|
|
98
|
+
if (r.blocked)
|
|
99
|
+
return r;
|
|
100
|
+
}
|
|
101
|
+
return { blocked: false };
|
|
102
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PermissionRule {
|
|
2
|
+
tool_pattern: string;
|
|
3
|
+
decision: "allow" | "deny" | "ask";
|
|
4
|
+
reason?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface PermissionResult {
|
|
7
|
+
decision: "allow" | "deny" | "ask";
|
|
8
|
+
reason?: string;
|
|
9
|
+
matched_rule?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class PermissionMatrix {
|
|
12
|
+
private defaultDecision;
|
|
13
|
+
private rules;
|
|
14
|
+
constructor(defaultDecision?: "allow" | "deny" | "ask", rules?: PermissionRule[]);
|
|
15
|
+
evaluate(toolName: string): PermissionResult;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/guard/permissions.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,KAAK,CAAmB;gBAEpB,eAAe,GAAE,OAAO,GAAG,MAAM,GAAG,KAAe,EAAE,KAAK,GAAE,cAAc,EAAO;IAK7F,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB;CAY7C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Guard M2: 工具权限矩阵
|
|
3
|
+
// 配置驱动的 per-tool allow/deny/ask,glob 匹配
|
|
4
|
+
// ============================================================
|
|
5
|
+
export class PermissionMatrix {
|
|
6
|
+
defaultDecision;
|
|
7
|
+
rules;
|
|
8
|
+
constructor(defaultDecision = "allow", rules = []) {
|
|
9
|
+
this.defaultDecision = defaultDecision;
|
|
10
|
+
this.rules = rules;
|
|
11
|
+
}
|
|
12
|
+
evaluate(toolName) {
|
|
13
|
+
for (const rule of this.rules) {
|
|
14
|
+
if (matchGlob(rule.tool_pattern, toolName)) {
|
|
15
|
+
return {
|
|
16
|
+
decision: rule.decision,
|
|
17
|
+
reason: rule.reason,
|
|
18
|
+
matched_rule: rule.tool_pattern,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { decision: this.defaultDecision };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function matchGlob(pattern, value) {
|
|
26
|
+
if (pattern === "*")
|
|
27
|
+
return true;
|
|
28
|
+
if (pattern === value)
|
|
29
|
+
return true;
|
|
30
|
+
// Convert glob to regex: * -> .*, ? -> ., escape rest
|
|
31
|
+
let regex = "^";
|
|
32
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
33
|
+
const ch = pattern[i];
|
|
34
|
+
if (ch === "*") {
|
|
35
|
+
regex += ".*";
|
|
36
|
+
}
|
|
37
|
+
else if (ch === "?") {
|
|
38
|
+
regex += ".";
|
|
39
|
+
}
|
|
40
|
+
else if (/[.+^${}()|[\]\\]/.test(ch)) {
|
|
41
|
+
regex += "\\" + ch;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
regex += ch;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
regex += "$";
|
|
48
|
+
try {
|
|
49
|
+
return new RegExp(regex).test(value);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return pattern === value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface RateLimitResult {
|
|
2
|
+
allowed: boolean;
|
|
3
|
+
retryAfterMs?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class RateLimiter {
|
|
6
|
+
private windowMs;
|
|
7
|
+
private maxPerWindow;
|
|
8
|
+
private windows;
|
|
9
|
+
constructor(maxPerMinute?: number, windowMs?: number);
|
|
10
|
+
check(tool: string, sessionId: string): RateLimitResult;
|
|
11
|
+
reset(tool?: string, sessionId?: string): void;
|
|
12
|
+
getWindowSize(): number;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=rate-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/guard/rate-limit.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAkC;gBAErC,YAAY,GAAE,MAAW,EAAE,QAAQ,GAAE,MAAe;IAKhE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,eAAe;IAwBvD,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAa9C,aAAa,IAAI,MAAM;CAGxB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// 轻灵 - Guard M2: 滑动窗口速率限制器
|
|
3
|
+
// per (tool, session) 维度,60s 窗口
|
|
4
|
+
// ============================================================
|
|
5
|
+
export class RateLimiter {
|
|
6
|
+
windowMs;
|
|
7
|
+
maxPerWindow;
|
|
8
|
+
windows = new Map();
|
|
9
|
+
constructor(maxPerMinute = 30, windowMs = 60_000) {
|
|
10
|
+
this.maxPerWindow = maxPerMinute;
|
|
11
|
+
this.windowMs = windowMs;
|
|
12
|
+
}
|
|
13
|
+
check(tool, sessionId) {
|
|
14
|
+
const key = tool + ":" + sessionId;
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
const cutoff = now - this.windowMs;
|
|
17
|
+
let entry = this.windows.get(key);
|
|
18
|
+
if (!entry) {
|
|
19
|
+
entry = { timestamps: [] };
|
|
20
|
+
this.windows.set(key, entry);
|
|
21
|
+
}
|
|
22
|
+
// Prune expired timestamps
|
|
23
|
+
entry.timestamps = entry.timestamps.filter((t) => t > cutoff);
|
|
24
|
+
if (entry.timestamps.length >= this.maxPerWindow) {
|
|
25
|
+
const oldest = entry.timestamps[0];
|
|
26
|
+
const retryAfterMs = oldest + this.windowMs - now;
|
|
27
|
+
return { allowed: false, retryAfterMs: Math.max(0, retryAfterMs) };
|
|
28
|
+
}
|
|
29
|
+
entry.timestamps.push(now);
|
|
30
|
+
return { allowed: true };
|
|
31
|
+
}
|
|
32
|
+
reset(tool, sessionId) {
|
|
33
|
+
if (!tool && !sessionId) {
|
|
34
|
+
this.windows.clear();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (const key of this.windows.keys()) {
|
|
38
|
+
const [t, s] = key.split(":");
|
|
39
|
+
if ((!tool || t === tool) && (!sessionId || s === sessionId)) {
|
|
40
|
+
this.windows.delete(key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
getWindowSize() {
|
|
45
|
+
return this.windows.size;
|
|
46
|
+
}
|
|
47
|
+
}
|
package/dist/guard.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { GuardConfig } from "./config.js";
|
|
2
|
+
export type GuardCategory = "network" | "redaction" | "permission" | "rate_limit" | "content_filter";
|
|
3
|
+
export interface GuardDecision {
|
|
4
|
+
allowed: boolean;
|
|
5
|
+
reason?: string;
|
|
6
|
+
category?: GuardCategory;
|
|
7
|
+
}
|
|
8
|
+
export interface GuardAuditEvent {
|
|
9
|
+
tool: string;
|
|
10
|
+
action: "allow" | "deny";
|
|
11
|
+
category?: GuardCategory;
|
|
12
|
+
target?: string;
|
|
13
|
+
reason?: string;
|
|
14
|
+
status?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function redactText(text: string, guard: GuardConfig): string;
|
|
17
|
+
export type NetworkGuardMode = "strict" | "open" | "deny";
|
|
18
|
+
export declare function resolveNetworkGuardMode(env?: NodeJS.ProcessEnv | Record<string, string | undefined>): NetworkGuardMode;
|
|
19
|
+
export declare function checkUrlFetchPolicy(url: URL, guard: GuardConfig, env?: NodeJS.ProcessEnv | Record<string, string | undefined>): Promise<GuardDecision>;
|
|
20
|
+
export declare function appendGuardAudit(guard: GuardConfig, event: GuardAuditEvent): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAErG,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAuBnE;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1D,wBAAgB,uBAAuB,CACrC,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACxE,gBAAgB,CAOlB;AAED,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,WAAW,EAClB,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACxE,OAAO,CAAC,aAAa,CAAC,CA2DxB;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAahG"}
|
package/dist/guard.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { lookup } from "dns/promises";
|
|
2
|
+
import * as net from "net";
|
|
3
|
+
import { appendFile, mkdir } from "fs/promises";
|
|
4
|
+
import { dirname } from "path";
|
|
5
|
+
export function redactText(text, guard) {
|
|
6
|
+
if (!guard.enabled || !guard.redaction.enabled)
|
|
7
|
+
return text;
|
|
8
|
+
let out = text;
|
|
9
|
+
// Built-in masks
|
|
10
|
+
const builtins = [
|
|
11
|
+
/\b(sk-[a-zA-Z0-9]{16,})\b/g,
|
|
12
|
+
/\b(Bearer\s+[A-Za-z0-9\-._~+/]+=*)\b/g,
|
|
13
|
+
/\b(AKIA[0-9A-Z]{16})\b/g,
|
|
14
|
+
];
|
|
15
|
+
for (const pattern of builtins) {
|
|
16
|
+
out = out.replace(pattern, "[REDACTED]");
|
|
17
|
+
}
|
|
18
|
+
for (const raw of guard.redaction.patterns) {
|
|
19
|
+
try {
|
|
20
|
+
const re = new RegExp(raw, "g");
|
|
21
|
+
out = out.replace(re, "[REDACTED]");
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// ignore invalid pattern
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
export function resolveNetworkGuardMode(env = process.env) {
|
|
30
|
+
const raw = String(env.QLING_GUARD_NETWORK_MODE ?? "strict").trim().toLowerCase();
|
|
31
|
+
if (raw === "deny" || raw === "deny_all" || raw === "off" || raw === "none" || raw === "block") {
|
|
32
|
+
return "deny";
|
|
33
|
+
}
|
|
34
|
+
if (raw === "open" || raw === "permissive" || raw === "http")
|
|
35
|
+
return "open";
|
|
36
|
+
return "strict";
|
|
37
|
+
}
|
|
38
|
+
export async function checkUrlFetchPolicy(url, guard, env = process.env) {
|
|
39
|
+
if (!guard.enabled)
|
|
40
|
+
return { allowed: true };
|
|
41
|
+
const mode = resolveNetworkGuardMode(env);
|
|
42
|
+
if (mode === "deny") {
|
|
43
|
+
return {
|
|
44
|
+
allowed: false,
|
|
45
|
+
category: "network",
|
|
46
|
+
reason: "network mode=deny: all outbound fetches blocked (QLING_GUARD_NETWORK_MODE)",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const policy = guard.network.url_fetch;
|
|
50
|
+
const href = url.toString();
|
|
51
|
+
if (mode === "open") {
|
|
52
|
+
// 允许 http/https,仍受私网策略约束;忽略自定义前缀收紧
|
|
53
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
54
|
+
return {
|
|
55
|
+
allowed: false,
|
|
56
|
+
category: "network",
|
|
57
|
+
reason: `unsupported protocol in open mode: ${url.protocol}`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (!policy.allowed_url_prefixes.some((prefix) => href.startsWith(prefix))) {
|
|
62
|
+
return {
|
|
63
|
+
allowed: false,
|
|
64
|
+
category: "network",
|
|
65
|
+
reason: `url not allowed by prefix policy: ${href}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (policy.deny_private_ips) {
|
|
69
|
+
const host = url.hostname;
|
|
70
|
+
if (isLiteralPrivateHost(host)) {
|
|
71
|
+
return {
|
|
72
|
+
allowed: false,
|
|
73
|
+
category: "network",
|
|
74
|
+
reason: `private ip host blocked: ${host}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const ips = await lookup(host, { all: true });
|
|
79
|
+
for (const ip of ips) {
|
|
80
|
+
if (isPrivateIp(ip.address)) {
|
|
81
|
+
return {
|
|
82
|
+
allowed: false,
|
|
83
|
+
category: "network",
|
|
84
|
+
reason: `resolved private ip blocked: ${ip.address}`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// DNS failure is handled by caller fetch path.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { allowed: true };
|
|
94
|
+
}
|
|
95
|
+
export async function appendGuardAudit(guard, event) {
|
|
96
|
+
if (!guard.enabled)
|
|
97
|
+
return;
|
|
98
|
+
const line = JSON.stringify({
|
|
99
|
+
ts: new Date().toISOString(),
|
|
100
|
+
...event,
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
const targetPath = guard.audit.jsonl_path;
|
|
104
|
+
await mkdir(dirname(targetPath), { recursive: true });
|
|
105
|
+
await appendFile(targetPath, line + "\n", "utf-8");
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// 审计写入失败不阻断主流程
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function isLiteralPrivateHost(hostname) {
|
|
112
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1")
|
|
113
|
+
return true;
|
|
114
|
+
if (net.isIP(hostname) === 0)
|
|
115
|
+
return false;
|
|
116
|
+
return isPrivateIp(hostname);
|
|
117
|
+
}
|
|
118
|
+
function isPrivateIp(ip) {
|
|
119
|
+
if (net.isIP(ip) === 4) {
|
|
120
|
+
const [a, b] = ip.split(".").map((x) => Number(x));
|
|
121
|
+
if (a === 10)
|
|
122
|
+
return true;
|
|
123
|
+
if (a === 127)
|
|
124
|
+
return true;
|
|
125
|
+
if (a === 169 && b === 254)
|
|
126
|
+
return true;
|
|
127
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
128
|
+
return true;
|
|
129
|
+
if (a === 192 && b === 168)
|
|
130
|
+
return true;
|
|
131
|
+
if (a === 0)
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
if (net.isIP(ip) === 6) {
|
|
135
|
+
const lower = ip.toLowerCase();
|
|
136
|
+
if (lower === "::1")
|
|
137
|
+
return true;
|
|
138
|
+
if (lower.startsWith("fc") || lower.startsWith("fd"))
|
|
139
|
+
return true; // ULA
|
|
140
|
+
if (lower.startsWith("fe80"))
|
|
141
|
+
return true; // link-local
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|