dsh-plugin-dev-kb 1.5.2 → 1.8.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 +51 -0
- package/README.en.md +31 -9
- package/README.md +42 -14
- package/kb/INDEX.md +3 -3
- package/kb/README.md +9 -4
- package/kb/extra/AGENTS.md +1 -1
- package/kb/extra/cli-help.md +15 -7
- package/kb/extra/cli-help.zh.md +15 -7
- package/kb/extra/cookbook/adding-a-plugin-preview.md +18 -25
- package/kb/extra/cookbook/adding-a-plugin-preview.zh.md +18 -25
- package/kb/extra/cookbook/reviewing-persistence-type-changes.md +1 -1
- package/kb/extra/cookbook/reviewing-persistence-type-changes.zh.md +1 -1
- package/kb/extra/cookbook/reviewing-ui-design.md +166 -0
- package/kb/extra/cookbook/reviewing-ui-design.zh.md +166 -0
- package/kb/extra/deepseek-llm-api-wire-extensions.md +2 -2
- package/kb/extra/deepseek-llm-api-wire-extensions.zh.md +2 -2
- package/kb/extra/defensive-patterns/conversation-and-session.md +2 -2
- package/kb/extra/defensive-patterns/conversation-and-session.zh.md +2 -2
- package/kb/extra/defensive-patterns/general.md +2 -0
- package/kb/extra/defensive-patterns/general.zh.md +2 -0
- package/kb/extra/defensive-patterns/package-surface.md +1 -0
- package/kb/extra/defensive-patterns/package-surface.zh.md +1 -0
- package/kb/extra/defensive-patterns/remote-and-api.md +5 -3
- package/kb/extra/defensive-patterns/remote-and-api.zh.md +5 -3
- package/kb/extra/development.md +16 -9
- package/kb/extra/development.zh.md +16 -9
- package/kb/extra/event-producer-consumer.md +64 -51
- package/kb/extra/event-producer-consumer.zh.md +64 -51
- package/kb/extra/i18n/README.md +2 -0
- package/kb/extra/i18n/README.zh.md +2 -0
- package/kb/extra/module-graph.md +204 -92
- package/kb/extra/module-graph.zh.md +204 -92
- package/kb/extra/persistence-changes/2026-10-13-liveshare-share-viewer-principal.md +60 -0
- package/kb/extra/persistence-changes/2026-10-13-liveshare-share-viewer-principal.zh.md +60 -0
- package/kb/extra/persistence-changes/2026-10-19-session-team-mode.md +48 -0
- package/kb/extra/persistence-changes/2026-10-19-session-team-mode.zh.md +48 -0
- package/kb/extra/persistence-changes/2026-10-22-action-card-status.md +60 -0
- package/kb/extra/persistence-changes/2026-10-22-action-card-status.zh.md +60 -0
- package/kb/extra/persistence-changes/2026-10-25-skill-catalog-incomplete.md +60 -0
- package/kb/extra/persistence-changes/2026-10-25-skill-catalog-incomplete.zh.md +60 -0
- package/kb/extra/persistence-changes/2026-10-27-retry-control-input.md +60 -0
- package/kb/extra/persistence-changes/2026-10-27-retry-control-input.zh.md +60 -0
- package/kb/extra/persistence-changes/2026-10-27-subagent-settlement-attribution.md +60 -0
- package/kb/extra/persistence-changes/2026-10-27-subagent-settlement-attribution.zh.md +60 -0
- package/kb/extra/persistence-changes/2026-11-02-subagent-catalog-names.md +48 -0
- package/kb/extra/persistence-changes/2026-11-02-subagent-catalog-names.zh.md +48 -0
- package/kb/extra/persistence-changes/2026-11-02-team-task-owner-names.md +48 -0
- package/kb/extra/persistence-changes/2026-11-02-team-task-owner-names.zh.md +48 -0
- package/kb/extra/persistence-changes/README.md +2 -0
- package/kb/extra/persistence-changes/README.zh.md +2 -0
- package/kb/extra/persistence-changes/historical-formats/README.md +1 -1
- package/kb/extra/persistence-changes/historical-formats/README.zh.md +1 -1
- package/kb/extra/rescope.md +7 -5
- package/kb/extra/rescope.zh.md +7 -5
- package/kb/extra/subsystems/agent-team.md +38 -75
- package/kb/extra/subsystems/agent-team.zh.md +38 -75
- package/kb/extra/subsystems/attachment.md +36 -13
- package/kb/extra/subsystems/attachment.zh.md +36 -13
- package/kb/extra/subsystems/boot.md +179 -5
- package/kb/extra/subsystems/boot.zh.md +179 -5
- package/kb/extra/subsystems/computer-use.md +78 -0
- package/kb/extra/subsystems/computer-use.zh.md +78 -0
- package/kb/extra/subsystems/deliverables.md +2 -0
- package/kb/extra/subsystems/deliverables.zh.md +2 -0
- package/kb/extra/subsystems/forge.md +1226 -0
- package/kb/extra/subsystems/forge.zh.md +1226 -0
- package/kb/extra/subsystems/liveshare.md +158 -0
- package/kb/extra/subsystems/liveshare.zh.md +158 -0
- package/kb/extra/subsystems/mcp.md +96 -1
- package/kb/extra/subsystems/mcp.zh.md +96 -1
- package/kb/extra/subsystems/worktrees.md +54 -3
- package/kb/extra/subsystems/worktrees.zh.md +54 -3
- package/kb/extra/testing.md +1 -1
- package/kb/extra/testing.zh.md +1 -1
- package/kb/extra/ui-design-review-cases.md +445 -0
- package/kb/extra/ui-design-review-cases.zh.md +445 -0
- package/kb/extra/ui-radius.md +3 -1
- package/kb/extra/ui-radius.zh.md +3 -1
- package/kb/extra/upgrade-guide/v0.2.1-alpha.1/team-direct-inbox/guide.md +1 -1
- package/kb/extra/upgrade-guide/v0.2.1-alpha.1/team-direct-inbox/guide.zh.md +1 -1
- package/kb/extra/upgrade-guide/v0.2.1-alpha.2/cordis-timer-wrappers/guide.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.1-alpha.2/cordis-timer-wrappers/guide.zh.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.1-alpha.2/plugin-manager-view-fields/guide.md +25 -0
- package/kb/extra/upgrade-guide/v0.2.1-alpha.2/plugin-manager-view-fields/guide.zh.md +25 -0
- package/kb/extra/upgrade-guide/v0.2.1-alpha.4/model-switch-compaction/guide.md +30 -0
- package/kb/extra/upgrade-guide/v0.2.1-alpha.4/model-switch-compaction/guide.zh.md +30 -0
- package/kb/extra/upgrade-guide/v0.2.1-alpha.4/session-model-selection/guide.md +28 -0
- package/kb/extra/upgrade-guide/v0.2.1-alpha.4/session-model-selection/guide.zh.md +28 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.1/agent-instructions-chain-budgets/guide.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.1/agent-instructions-chain-budgets/guide.zh.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.1/subagent-control-tools/guide.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.1/subagent-control-tools/guide.zh.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/agent-runtime-owner/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/agent-runtime-owner/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/agent-team-subagents/guide.md +31 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/agent-team-subagents/guide.zh.md +31 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/approval-projection-dependency/guide.md +34 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/approval-projection-dependency/guide.zh.md +34 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/auto-review-shutdown/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/auto-review-shutdown/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/auto-review-user-sources/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/auto-review-user-sources/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/built-in-japanese/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/built-in-japanese/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/conditional-tools/guide.md +25 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/conditional-tools/guide.zh.md +25 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/context-menu-services/guide.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/context-menu-services/guide.zh.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/cua-consent-storage/guide.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/cua-consent-storage/guide.zh.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/cua-preset-scope/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/cua-preset-scope/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/cua-relative-coordinates/guide.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/cua-relative-coordinates/guide.zh.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/file-drag-callbacks/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/file-drag-callbacks/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/headless-policy-composition/guide.md +27 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/headless-policy-composition/guide.zh.md +27 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/model-badge-package-removal/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/model-badge-package-removal/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/new-session-blank-reuse/guide.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/new-session-blank-reuse/guide.zh.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/node-24/guide.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/node-24/guide.zh.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/official-bundle-lists/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/official-bundle-lists/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/persistent-terminal-controls/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/persistent-terminal-controls/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/pi-ai-default-capacities/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/pi-ai-default-capacities/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/pi-ai-model-catalog/guide.md +53 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/pi-ai-model-catalog/guide.zh.md +53 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/pi-ai-protocol-replay/guide.md +30 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/pi-ai-protocol-replay/guide.zh.md +30 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/ptc-script-format/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/ptc-script-format/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/sdk-desktop-context/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/sdk-desktop-context/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/sdk-minimal-checkpoints/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/sdk-minimal-checkpoints/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/session-projection-handles/guide.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/session-projection-handles/guide.zh.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/session-store-writes/guide.md +25 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/session-store-writes/guide.zh.md +25 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/session-team-mode/guide.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/session-team-mode/guide.zh.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/subagent-activation-options/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/subagent-activation-options/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/subagent-service-methods/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/subagent-service-methods/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/subagent-user-controls/guide.md +26 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/subagent-user-controls/guide.zh.md +26 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/tool-executor-plugins/guide.md +35 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/tool-executor-plugins/guide.zh.md +35 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/web-fetch-private-destinations/guide.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/web-fetch-private-destinations/guide.zh.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/webserver-index-peer/guide.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.2/webserver-index-peer/guide.zh.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/attachment-read-access/guide.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/attachment-read-access/guide.zh.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/computer-use-helper-permissions/guide.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/computer-use-helper-permissions/guide.zh.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/generated-worktree-names/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/generated-worktree-names/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/inbox-only-agent-wait/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/inbox-only-agent-wait/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/independent-session-forks/guide.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/independent-session-forks/guide.zh.md +23 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/ptc-caller-cancellation/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/ptc-caller-cancellation/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/session-follow-activation/guide.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/session-follow-activation/guide.zh.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/subagent-runtime-ownership/guide.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/subagent-runtime-ownership/guide.zh.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/team-mode-menu/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/team-mode-menu/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/team-projection/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/team-projection/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/web-file-downloads/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/web-file-downloads/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/web-search-defaults/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.3/web-search-defaults/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.4/model-listing-refresh/guide.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.4/model-listing-refresh/guide.zh.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.4/reasoning-body-props/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.1-rc.4/reasoning-body-props/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/context-menu-target/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/context-menu-target/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/cordis-loader-entry-trees/guide.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/cordis-loader-entry-trees/guide.zh.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/css-anchored-menus/guide.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/css-anchored-menus/guide.zh.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/cua-source-dev-helper/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/cua-source-dev-helper/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/desktop-stable-channel/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/desktop-stable-channel/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/forge-git-permissions/guide.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/forge-git-permissions/guide.zh.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/forge-worktree-entry/guide.md +29 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/forge-worktree-entry/guide.zh.md +29 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/fs-observation-policy-default-off/guide.md +29 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/fs-observation-policy-default-off/guide.zh.md +29 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/llm-request-purpose-declarations/guide.md +29 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/llm-request-purpose-declarations/guide.zh.md +29 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/pi-ai-request-image-count/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/pi-ai-request-image-count/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/projection-event-frames/guide.md +32 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/projection-event-frames/guide.zh.md +32 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/projection-released-checkpoint/guide.md +30 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/projection-released-checkpoint/guide.zh.md +30 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/projection-snapshot-scope/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/projection-snapshot-scope/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/retained-ptc-timeout/guide.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/retained-ptc-timeout/guide.zh.md +21 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/schedule-agent-tools/guide.md +37 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/schedule-agent-tools/guide.zh.md +37 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/schedule-remote-host-tasks/guide.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/schedule-remote-host-tasks/guide.zh.md +22 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/sdk-run-commands/guide.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/sdk-run-commands/guide.zh.md +24 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/session-header-menu/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/session-header-menu/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/subagent-explicit-reasoning/guide.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/subagent-explicit-reasoning/guide.zh.md +20 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/web-search-credential-modes/guide.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/web-search-credential-modes/guide.zh.md +17 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/web-search-default-provider/guide.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.2/web-search-default-provider/guide.zh.md +19 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.3/chat-process-activity-context/guide.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.3/chat-process-activity-context/guide.zh.md +18 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.3/subagent-names/guide.md +29 -0
- package/kb/extra/upgrade-guide/v0.2.2-alpha.3/subagent-names/guide.zh.md +29 -0
- package/kb/extra/web-styling.md +19 -1
- package/kb/extra/web-styling.zh.md +19 -1
- package/kb/meta/search-index.json +1272 -1098
- package/kb/meta/source.json +8 -4
- package/kb/site/develop/cordis-tutorial/04-events.md +1 -1
- package/kb/site/develop/cordis-tutorial/07-into-the-harness.md +5 -4
- package/kb/site/develop/framework/events.md +1 -1
- package/kb/site/develop/practice/dynamic-cordis.md +1 -1
- package/kb/site/en/develop/cordis-tutorial/04-events.md +1 -1
- package/kb/site/en/develop/cordis-tutorial/07-into-the-harness.md +5 -4
- package/kb/site/en/develop/framework/events.md +1 -1
- package/kb/site/en/develop/practice/dynamic-cordis.md +1 -1
- package/kb/site/en/guide/network-proxy.md +1 -1
- package/kb/site/en/guide/plugin-market.md +10 -10
- package/kb/site/en/guide/providers.md +5 -1
- package/kb/site/en/guide/python-sdk.md +17 -2
- package/kb/site/en/guide/schedule.md +45 -26
- package/kb/site/en/reference/agent-lifecycle.md +3 -1
- package/kb/site/en/reference/api-gateway.md +4 -4
- package/kb/site/en/reference/capability-seams.md +65 -17
- package/kb/site/en/reference/config-catalog.md +560 -238
- package/kb/site/en/reference/cookbook/adding-a-package.md +4 -2
- package/kb/site/en/reference/cookbook/extension-cookbook.md +1 -1
- package/kb/site/en/reference/cordis-api/context.md +1 -1
- package/kb/site/en/reference/cordis-api/events.md +9 -9
- package/kb/site/en/reference/cordis-api/fiber.md +85 -32
- package/kb/site/en/reference/cordis-api/inherited.md +10 -9
- package/kb/site/en/reference/experimental-persistence-catalog.md +3 -0
- package/kb/site/en/reference/index.md +14 -8
- package/kb/site/en/reference/persistence-catalog.md +532 -246
- package/kb/site/en/reference/subsystems/client-modules.md +19 -11
- package/kb/site/en/reference/subsystems/compaction.md +1 -1
- package/kb/site/en/reference/subsystems/conversation.md +2 -0
- package/kb/site/en/reference/subsystems/core.md +119 -65
- package/kb/site/en/reference/subsystems/filesystem.md +202 -28
- package/kb/site/en/reference/subsystems/index.md +3 -1
- package/kb/site/en/reference/subsystems/llm-streaming.md +92 -4
- package/kb/site/en/reference/subsystems/persistence.md +17 -7
- package/kb/site/en/reference/subsystems/plan.md +4 -4
- package/kb/site/en/reference/subsystems/ptc-runtime.md +12 -5
- package/kb/site/en/reference/subsystems/sandbox.md +11 -4
- package/kb/site/en/reference/subsystems/schedule.md +194 -430
- package/kb/site/en/reference/subsystems/session-projection.md +186 -44
- package/kb/site/en/reference/subsystems/session-reference.md +4 -3
- package/kb/site/en/reference/subsystems/session.md +119 -31
- package/kb/site/en/reference/subsystems/sidebar-right.md +12 -11
- package/kb/site/en/reference/subsystems/skills.md +4 -4
- package/kb/site/en/reference/subsystems/slots.md +30 -3
- package/kb/site/en/reference/subsystems/storage.md +26 -9
- package/kb/site/en/reference/subsystems/subagent.md +119 -102
- package/kb/site/en/reference/subsystems/system-prompt.md +13 -11
- package/kb/site/en/reference/subsystems/token-meter.md +45 -0
- package/kb/site/en/reference/subsystems/tools.md +222 -82
- package/kb/site/en/reference/subsystems/typert.md +21 -11
- package/kb/site/en/reference/subsystems/user-questions.md +22 -6
- package/kb/site/en/reference/subsystems/web-client.md +1 -1
- package/kb/site/en/reference/subsystems/web-server.md +68 -23
- package/kb/site/en/reference/subsystems/web.md +79 -21
- package/kb/site/en/reference/tool-catalog.md +270 -395
- package/kb/site/en/reference/tool-execution-pipeline.md +5 -4
- package/kb/site/guide/network-proxy.md +1 -1
- package/kb/site/guide/plugin-market.md +10 -10
- package/kb/site/guide/providers.md +5 -1
- package/kb/site/guide/python-sdk.md +17 -2
- package/kb/site/guide/schedule.md +45 -26
- package/kb/site/reference/agent-lifecycle.md +3 -1
- package/kb/site/reference/api-gateway.md +4 -4
- package/kb/site/reference/capability-seams.md +65 -17
- package/kb/site/reference/config-catalog.md +560 -238
- package/kb/site/reference/cookbook/adding-a-package.md +4 -2
- package/kb/site/reference/cookbook/extension-cookbook.md +1 -1
- package/kb/site/reference/cordis-api/context.md +1 -1
- package/kb/site/reference/cordis-api/events.md +9 -9
- package/kb/site/reference/cordis-api/fiber.md +87 -32
- package/kb/site/reference/cordis-api/inherited.md +10 -9
- package/kb/site/reference/experimental-persistence-catalog.md +3 -0
- package/kb/site/reference/index.md +14 -8
- package/kb/site/reference/persistence-catalog.md +532 -246
- package/kb/site/reference/subsystems/client-modules.md +19 -11
- package/kb/site/reference/subsystems/compaction.md +1 -1
- package/kb/site/reference/subsystems/conversation.md +4 -0
- package/kb/site/reference/subsystems/core.md +119 -65
- package/kb/site/reference/subsystems/filesystem.md +202 -28
- package/kb/site/reference/subsystems/index.md +3 -1
- package/kb/site/reference/subsystems/llm-streaming.md +92 -4
- package/kb/site/reference/subsystems/persistence.md +17 -7
- package/kb/site/reference/subsystems/plan.md +4 -4
- package/kb/site/reference/subsystems/ptc-runtime.md +12 -5
- package/kb/site/reference/subsystems/sandbox.md +11 -4
- package/kb/site/reference/subsystems/schedule.md +197 -433
- package/kb/site/reference/subsystems/session-projection.md +186 -44
- package/kb/site/reference/subsystems/session-reference.md +4 -3
- package/kb/site/reference/subsystems/session.md +119 -31
- package/kb/site/reference/subsystems/sidebar-right.md +12 -11
- package/kb/site/reference/subsystems/skills.md +4 -4
- package/kb/site/reference/subsystems/slots.md +30 -3
- package/kb/site/reference/subsystems/storage.md +26 -9
- package/kb/site/reference/subsystems/subagent.md +119 -102
- package/kb/site/reference/subsystems/system-prompt.md +13 -11
- package/kb/site/reference/subsystems/token-meter.md +45 -0
- package/kb/site/reference/subsystems/tools.md +222 -82
- package/kb/site/reference/subsystems/typert.md +21 -11
- package/kb/site/reference/subsystems/user-questions.md +22 -6
- package/kb/site/reference/subsystems/web-client.md +1 -1
- package/kb/site/reference/subsystems/web-server.md +68 -23
- package/kb/site/reference/subsystems/web.md +79 -21
- package/kb/site/reference/tool-catalog.md +273 -399
- package/kb/site/reference/tool-execution-pipeline.md +4 -3
- package/lib/index.js +268 -11
- package/lib/kb-search.js +261 -0
- package/lib/kb-version.js +118 -0
- package/package.json +5 -3
- package/scripts/refresh-kb.mjs +153 -0
- package/scripts/selfcheck.mjs +28 -0
- package/scripts/smoke.mjs +77 -0
- package/skills/dsh-plugin-dev-kb.md +8 -7
- package/skills/dsh-plugin-starter.md +65 -0
- package/skills/dsh-upgrade-assistant.md +62 -0
- package/kb/extra/agent-lifecycle.md +0 -91
- package/kb/extra/agent-lifecycle.zh.md +0 -93
- package/kb/extra/api-gateway.md +0 -172
- package/kb/extra/api-gateway.zh.md +0 -178
- package/kb/extra/architecture.md +0 -165
- package/kb/extra/architecture.zh.md +0 -169
- package/kb/extra/capability-seams.md +0 -714
- package/kb/extra/capability-seams.zh.md +0 -716
- package/kb/extra/config-catalog.md +0 -4801
- package/kb/extra/config-catalog.zh.md +0 -4803
- package/kb/extra/cookbook/adding-a-package.md +0 -170
- package/kb/extra/cookbook/adding-a-package.zh.md +0 -170
- package/kb/extra/cookbook/adding-a-settings-card.md +0 -72
- package/kb/extra/cookbook/adding-a-settings-card.zh.md +0 -72
- package/kb/extra/cookbook/adding-a-tool.md +0 -101
- package/kb/extra/cookbook/adding-a-tool.zh.md +0 -103
- package/kb/extra/cookbook/adding-an-llm-adapter.md +0 -43
- package/kb/extra/cookbook/adding-an-llm-adapter.zh.md +0 -43
- package/kb/extra/cookbook/extension-cookbook.md +0 -132
- package/kb/extra/cookbook/extension-cookbook.zh.md +0 -136
- package/kb/extra/cordis-api/context.md +0 -364
- package/kb/extra/cordis-api/context.zh.md +0 -366
- package/kb/extra/cordis-api/events.md +0 -207
- package/kb/extra/cordis-api/events.zh.md +0 -209
- package/kb/extra/cordis-api/fiber.md +0 -375
- package/kb/extra/cordis-api/fiber.zh.md +0 -377
- package/kb/extra/cordis-api/inherited.md +0 -38
- package/kb/extra/cordis-api/registry.md +0 -152
- package/kb/extra/cordis-api/registry.zh.md +0 -154
- package/kb/extra/cordis-api/service.md +0 -102
- package/kb/extra/cordis-api/service.zh.md +0 -104
- package/kb/extra/cordis-tutorial/01-first-plugin.md +0 -95
- package/kb/extra/cordis-tutorial/01-first-plugin.zh.md +0 -95
- package/kb/extra/cordis-tutorial/02-lifecycle-and-effects.md +0 -98
- package/kb/extra/cordis-tutorial/02-lifecycle-and-effects.zh.md +0 -98
- package/kb/extra/cordis-tutorial/03-services.md +0 -98
- package/kb/extra/cordis-tutorial/03-services.zh.md +0 -98
- package/kb/extra/cordis-tutorial/04-events.md +0 -144
- package/kb/extra/cordis-tutorial/04-events.zh.md +0 -144
- package/kb/extra/cordis-tutorial/05-config.md +0 -111
- package/kb/extra/cordis-tutorial/05-config.zh.md +0 -111
- package/kb/extra/cordis-tutorial/06-composition-and-hmr.md +0 -113
- package/kb/extra/cordis-tutorial/06-composition-and-hmr.zh.md +0 -113
- package/kb/extra/cordis-tutorial/07-into-the-harness.md +0 -108
- package/kb/extra/cordis-tutorial/07-into-the-harness.zh.md +0 -108
- package/kb/extra/cordis-tutorial/index.md +0 -60
- package/kb/extra/cordis-tutorial/index.zh.md +0 -62
- package/kb/extra/experimental-persistence-catalog.md +0 -17
- package/kb/extra/experimental-persistence-catalog.zh.md +0 -17
- package/kb/extra/persistence-catalog.md +0 -9140
- package/kb/extra/persistence-catalog.zh.md +0 -9142
- package/kb/extra/subsystems/README.md +0 -76
- package/kb/extra/subsystems/README.zh.md +0 -76
- package/kb/extra/subsystems/approval.md +0 -170
- package/kb/extra/subsystems/approval.zh.md +0 -170
- package/kb/extra/subsystems/client-modules.md +0 -198
- package/kb/extra/subsystems/client-modules.zh.md +0 -198
- package/kb/extra/subsystems/client-resources.md +0 -92
- package/kb/extra/subsystems/client-resources.zh.md +0 -92
- package/kb/extra/subsystems/commands.md +0 -223
- package/kb/extra/subsystems/commands.zh.md +0 -223
- package/kb/extra/subsystems/compaction.md +0 -284
- package/kb/extra/subsystems/compaction.zh.md +0 -284
- package/kb/extra/subsystems/conversation.md +0 -301
- package/kb/extra/subsystems/conversation.zh.md +0 -303
- package/kb/extra/subsystems/core.md +0 -1113
- package/kb/extra/subsystems/core.zh.md +0 -1125
- package/kb/extra/subsystems/credentials.md +0 -493
- package/kb/extra/subsystems/credentials.zh.md +0 -493
- package/kb/extra/subsystems/filesystem.md +0 -530
- package/kb/extra/subsystems/filesystem.zh.md +0 -530
- package/kb/extra/subsystems/goal.md +0 -313
- package/kb/extra/subsystems/goal.zh.md +0 -313
- package/kb/extra/subsystems/jobs.md +0 -554
- package/kb/extra/subsystems/jobs.zh.md +0 -554
- package/kb/extra/subsystems/llm-streaming.md +0 -1196
- package/kb/extra/subsystems/llm-streaming.zh.md +0 -1202
- package/kb/extra/subsystems/lsp.md +0 -202
- package/kb/extra/subsystems/lsp.zh.md +0 -202
- package/kb/extra/subsystems/permission-presets.md +0 -167
- package/kb/extra/subsystems/permission-presets.zh.md +0 -167
- package/kb/extra/subsystems/persistence.md +0 -418
- package/kb/extra/subsystems/persistence.zh.md +0 -418
- package/kb/extra/subsystems/plan.md +0 -87
- package/kb/extra/subsystems/plan.zh.md +0 -87
- package/kb/extra/subsystems/ptc-runtime.md +0 -250
- package/kb/extra/subsystems/ptc-runtime.zh.md +0 -250
- package/kb/extra/subsystems/sandbox.md +0 -221
- package/kb/extra/subsystems/sandbox.zh.md +0 -221
- package/kb/extra/subsystems/schedule.md +0 -550
- package/kb/extra/subsystems/schedule.zh.md +0 -550
- package/kb/extra/subsystems/scope.md +0 -59
- package/kb/extra/subsystems/scope.zh.md +0 -61
- package/kb/extra/subsystems/session-projection.md +0 -356
- package/kb/extra/subsystems/session-projection.zh.md +0 -356
- package/kb/extra/subsystems/session-query.md +0 -511
- package/kb/extra/subsystems/session-query.zh.md +0 -511
- package/kb/extra/subsystems/session-reference.md +0 -224
- package/kb/extra/subsystems/session-reference.zh.md +0 -224
- package/kb/extra/subsystems/session-telemetry.md +0 -212
- package/kb/extra/subsystems/session-telemetry.zh.md +0 -212
- package/kb/extra/subsystems/session-title.md +0 -213
- package/kb/extra/subsystems/session-title.zh.md +0 -213
- package/kb/extra/subsystems/session.md +0 -1339
- package/kb/extra/subsystems/session.zh.md +0 -1343
- package/kb/extra/subsystems/settings.md +0 -155
- package/kb/extra/subsystems/settings.zh.md +0 -155
- package/kb/extra/subsystems/shell.md +0 -314
- package/kb/extra/subsystems/shell.zh.md +0 -314
- package/kb/extra/subsystems/sidebar-right.md +0 -160
- package/kb/extra/subsystems/sidebar-right.zh.md +0 -160
- package/kb/extra/subsystems/skills.md +0 -352
- package/kb/extra/subsystems/skills.zh.md +0 -352
- package/kb/extra/subsystems/slots.md +0 -200
- package/kb/extra/subsystems/slots.zh.md +0 -204
- package/kb/extra/subsystems/spill.md +0 -124
- package/kb/extra/subsystems/spill.zh.md +0 -124
- package/kb/extra/subsystems/storage.md +0 -259
- package/kb/extra/subsystems/storage.zh.md +0 -259
- package/kb/extra/subsystems/subagent.md +0 -686
- package/kb/extra/subsystems/subagent.zh.md +0 -688
- package/kb/extra/subsystems/subprocess.md +0 -321
- package/kb/extra/subsystems/subprocess.zh.md +0 -321
- package/kb/extra/subsystems/system-prompt.md +0 -254
- package/kb/extra/subsystems/system-prompt.zh.md +0 -254
- package/kb/extra/subsystems/terminal.md +0 -184
- package/kb/extra/subsystems/terminal.zh.md +0 -184
- package/kb/extra/subsystems/token-meter.md +0 -106
- package/kb/extra/subsystems/token-meter.zh.md +0 -106
- package/kb/extra/subsystems/tools.md +0 -747
- package/kb/extra/subsystems/tools.zh.md +0 -747
- package/kb/extra/subsystems/typert.md +0 -690
- package/kb/extra/subsystems/typert.zh.md +0 -690
- package/kb/extra/subsystems/user-questions.md +0 -307
- package/kb/extra/subsystems/user-questions.zh.md +0 -307
- package/kb/extra/subsystems/web-client.md +0 -100
- package/kb/extra/subsystems/web-client.zh.md +0 -100
- package/kb/extra/subsystems/web-server.md +0 -302
- package/kb/extra/subsystems/web-server.zh.md +0 -302
- package/kb/extra/subsystems/web.md +0 -206
- package/kb/extra/subsystems/web.zh.md +0 -206
- package/kb/extra/subsystems/workflow.md +0 -278
- package/kb/extra/subsystems/workflow.zh.md +0 -278
- package/kb/extra/subsystems/workspace.md +0 -647
- package/kb/extra/subsystems/workspace.zh.md +0 -647
- package/kb/extra/tool-catalog.md +0 -2824
- package/kb/extra/tool-catalog.zh.md +0 -2832
- package/kb/extra/tool-execution-pipeline.md +0 -65
- package/kb/extra/tool-execution-pipeline.zh.md +0 -67
|
@@ -8,7 +8,7 @@ rawMarkdownPath: "reference/tool-execution-pipeline.md"
|
|
|
8
8
|
|
|
9
9
|
# 工具执行流水线
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
内置执行器负责原始批次解析、调度、取消和 Session 调用/结果日志。此图展示其共享调用流水线如何执行策略、钩子、沙箱、文件系统守卫、结果改写、最终结果观测和 UI 呈现,而无需改动循环。`tools/pre-execute` 瀑布先执行,然后是单调守卫,再是 `tools/execute` 和 `tools/post-execute` 瀑布;三个瀑布可以转换调用。定义拥有的 `projectContent` 在后置策略之前安装准备好的内容,`finalizeContent` 和 `tools/result` 在之后执行。
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart TD
|
|
@@ -25,14 +25,15 @@ flowchart TD
|
|
|
25
25
|
owned["Tool-owned session events<br/><code>todo/write</code>, <code>fs/observed</code>, <code>hook/invoked</code>, <code>hook/result</code>, <code>tool/ptc-dispatch</code>"]
|
|
26
26
|
project["ToolDefinition.projectContent<br/>execution-prepared text and images"]
|
|
27
27
|
post["<code>tools/post-execute</code> waterfall<br/>accept, block, replace, add context"]
|
|
28
|
-
normalized["
|
|
28
|
+
normalized["Invocation pipeline normalization<br/>pipeline/result snapshot throws become isError"]
|
|
29
29
|
finalize["ToolDefinition.finalizeContent<br/>last content-only invariant"]
|
|
30
30
|
final["<code>tools/result</code> synchronous notification<br/>frozen authoritative outcome"]
|
|
31
31
|
context["Active-batch additionalContexts FIFO<br/>injected user/message after recorded tool results"]
|
|
32
32
|
toolResult["Session event: <code>tool/result</code><br/>single model-facing outcome"]
|
|
33
33
|
allResults["Tool batch settled<br/>recorded tool/result events complete"]
|
|
34
34
|
presentResult["UI completed card<br/>presentResult(args, result)"]
|
|
35
|
-
|
|
35
|
+
executor["Selected ToolExecutor.execute<br/>raw batch, Agent, optional logging step"]
|
|
36
|
+
model --> executor --> toolCall
|
|
36
37
|
toolCall --> presentCall
|
|
37
38
|
toolCall --> pre
|
|
38
39
|
pre -->|allow| guards
|
package/lib/index.js
CHANGED
|
@@ -1,30 +1,237 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-plugin-dev-kb —
|
|
2
|
+
* dsh-plugin-dev-kb — 主机插件(技能载体 + 知识库检索工具)。
|
|
3
3
|
*
|
|
4
|
-
* 挂载于 profile
|
|
5
|
-
* dsh-plugin-dev-kb 技能注册为 runtime skill,让每个会话的 agent
|
|
6
|
-
* 在插件开发 / 查询 dsh 能力 / 写 Tool / 配置 cordis.yml 类任务时,
|
|
7
|
-
* 能按技能 description 自动加载,从而获知知识库位置与阅读路径。
|
|
4
|
+
* 挂载于 profile 根层(全局层),两部分职责:
|
|
8
5
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* A. 技能层:把 skills/ 目录下的 dsh-plugin-dev-kb / dsh-dev-sandbox 技能
|
|
7
|
+
* 注册为 runtime skill,让每个会话的 agent 在插件开发 / 查询 dsh 能力 /
|
|
8
|
+
* 写 Tool / 配置 cordis.yml 类任务时按技能 description 自动加载。
|
|
9
|
+
*
|
|
10
|
+
* B. 工具层(1.6.0 起):注册 dsh_kb_search 工具——知识库本地打分检索,
|
|
11
|
+
* 一次调用返回命中文件 + 行号 + 上下文片段,替代 agent 多轮 grep/read。
|
|
12
|
+
* 索引在内存(宿主启动时构建中文索引,英文索引按需惰性构建),只读不写。
|
|
13
|
+
*
|
|
14
|
+
* 知识库数据(kb/ 目录)是纯文档,模型仍可通过文件工具按技能指示直接读取。
|
|
11
15
|
*
|
|
12
16
|
* 依赖纪律:本模块不 import 任何 @deepseek-ai/* 运行时包(插件以
|
|
13
17
|
* link: 方式装入 profile,Node ESM 按 realpath 解析链接包,外部依赖
|
|
14
|
-
*
|
|
18
|
+
* 从插件目录解析不到);工具走 ctx.tools.register 的原始 definition
|
|
19
|
+
* 形状(标准 JSON Schema,参照 dsh-plugin-windows-guard 的先例)。
|
|
15
20
|
*/
|
|
16
21
|
|
|
17
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
18
|
-
import { dirname, join } from 'node:path'
|
|
22
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
23
|
+
import { dirname, join, resolve, sep } from 'node:path'
|
|
19
24
|
import { fileURLToPath } from 'node:url'
|
|
25
|
+
import { buildIndex, search as kbSearch } from './kb-search.js'
|
|
26
|
+
import { detectHostVersion, versionBanner } from './kb-version.js'
|
|
20
27
|
|
|
21
28
|
export const name = 'dsh-plugin-dev-kb'
|
|
22
|
-
export const inject = ['skills']
|
|
29
|
+
export const inject = ['skills', 'tools']
|
|
23
30
|
|
|
24
31
|
const PKG_DIR = dirname(fileURLToPath(import.meta.url))
|
|
25
32
|
const SKILLS_DIR = join(PKG_DIR, '..', 'skills')
|
|
26
33
|
const KB_DIR = join(PKG_DIR, '..', 'kb')
|
|
27
34
|
|
|
35
|
+
const DEFAULT_CONFIG = {
|
|
36
|
+
/** 注册 dsh_kb_search 知识库检索工具(false = 只保留技能,不注册工具)。 */
|
|
37
|
+
searchTool: true,
|
|
38
|
+
/** 注册 dsh_kb_read 知识库局部阅读工具(1.8.0 起,false = 只用 search)。 */
|
|
39
|
+
readTool: true,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// dsh_kb_search 工具(原始 definition 形状,零依赖)
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
/** 把 search 结果渲染为模型可读 Markdown。 */
|
|
47
|
+
function renderResult(value) {
|
|
48
|
+
if (value.kind === 'topics') {
|
|
49
|
+
return [
|
|
50
|
+
`【知识库主题导航】${value.topicsPath ?? ''}`,
|
|
51
|
+
value.text ?? '',
|
|
52
|
+
value.hint ?? '',
|
|
53
|
+
].filter(Boolean).join('\n')
|
|
54
|
+
}
|
|
55
|
+
if (value.kind === 'empty') {
|
|
56
|
+
return `【无命中】query: ${value.query}\n${value.hint}`
|
|
57
|
+
}
|
|
58
|
+
const lines = [`【知识库检索】query: ${value.query}(scope=${value.scope},命中 ${value.files.length} 个文件${value.truncatedFiles ? `,另有 ${value.truncatedFiles} 个未展示` : ''})`]
|
|
59
|
+
for (const f of value.files) {
|
|
60
|
+
lines.push('')
|
|
61
|
+
lines.push(`### ${f.path}(score ${f.score}${f.title ? `,标题「${f.title}」` : ''})`)
|
|
62
|
+
lines.push(`绝对路径:${f.absPath}|命中行:${f.hitLines.join(', ')}`)
|
|
63
|
+
for (const s of f.snippets) {
|
|
64
|
+
lines.push('')
|
|
65
|
+
lines.push(`--- L${s.from} 起(命中行 L${s.line})---`)
|
|
66
|
+
lines.push(s.text)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
lines.push('')
|
|
70
|
+
lines.push(value.hint ?? '')
|
|
71
|
+
return lines.join('\n')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** dsh_kb_search 工具定义。 */
|
|
75
|
+
function kbSearchTool(getIndex, hostVersion) {
|
|
76
|
+
return {
|
|
77
|
+
name: 'dsh_kb_search',
|
|
78
|
+
description:
|
|
79
|
+
'dsh 插件开发知识库本地打分检索(零 token、毫秒级):在官方文档完整镜像(站点 192 页 + 仓库补充文档)中' +
|
|
80
|
+
'按关键词检索,返回命中文件路径、行号与上下文片段,用 read 工具按行号局部读原文。' +
|
|
81
|
+
'query 为空或 "topics" 返回主题导航(任务场景 → 文档清单)。写 dsh 插件 / Tool / 配置 / 服务 / 事件 /' +
|
|
82
|
+
'查 ctx.* API 签名 / 打包发布 / LLM 适配器时先用本工具定位文档,找不到再用文件工具 grep。' +
|
|
83
|
+
'仅限 dsh(DeepSeek Harness)插件开发知识库。',
|
|
84
|
+
parameters: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
required: ['query'],
|
|
88
|
+
properties: {
|
|
89
|
+
query: {
|
|
90
|
+
type: 'string',
|
|
91
|
+
description:
|
|
92
|
+
'检索关键词,空白分隔多词(如 "ctx.tools.register"、"插件配置 发布");空串或 "topics" 返回主题导航。'
|
|
93
|
+
},
|
|
94
|
+
scope: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
enum: ['all', 'api'],
|
|
97
|
+
description:
|
|
98
|
+
'all = 全部文档(默认);api = 只搜 API 签名/目录类文档(tool-catalog、config-catalog、capability-seams、cordis-api、subsystems 等),适合查 ctx.* API。'
|
|
99
|
+
},
|
|
100
|
+
lang: {
|
|
101
|
+
type: 'string',
|
|
102
|
+
enum: ['zh', 'en'],
|
|
103
|
+
description: '文档语言(默认 zh;en 首次调用会现场建英文索引,稍慢)'
|
|
104
|
+
},
|
|
105
|
+
maxResults: {
|
|
106
|
+
type: 'integer',
|
|
107
|
+
description: '返回文件数上限(默认 8,最大 20)'
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
output: {
|
|
112
|
+
schema: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
additionalProperties: false,
|
|
115
|
+
required: ['kind', 'text'],
|
|
116
|
+
properties: {
|
|
117
|
+
kind: { type: 'string', enum: ['hits', 'empty', 'topics'] },
|
|
118
|
+
text: { type: 'string' }
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
render: (_args, value) => [{ type: 'text', text: value.text }]
|
|
122
|
+
},
|
|
123
|
+
async execute(args) {
|
|
124
|
+
const { index, error } = getIndex(args.lang === 'en' ? 'en' : 'zh')
|
|
125
|
+
if (error) throw new Error(error)
|
|
126
|
+
const result = kbSearch(index, args.query, {
|
|
127
|
+
scope: args.scope === 'api' ? 'api' : 'all',
|
|
128
|
+
maxResults: args.maxResults,
|
|
129
|
+
})
|
|
130
|
+
const banner = versionBanner(index.kbDir, hostVersion)
|
|
131
|
+
return { kind: result.kind, text: banner ? `${banner}\n\n${renderResult(result)}` : renderResult(result) }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** dsh_kb_read 工具定义(1.8.0):知识库局部阅读,带行号窗口 + 中英对照提示。 */
|
|
137
|
+
function kbReadTool(getIndex, hostVersion) {
|
|
138
|
+
return {
|
|
139
|
+
name: 'dsh_kb_read',
|
|
140
|
+
description:
|
|
141
|
+
'dsh 插件开发知识库局部阅读:按知识库相对路径 + 行号窗口读原文,输出带行号,' +
|
|
142
|
+
'自动防大文件整读(单次窗口有上限)、自动处理编码,并提示中英对照版本的对应路径。' +
|
|
143
|
+
'通常与 dsh_kb_search 配套:先 search 拿到 path + 命中行号,再用本工具按行号窗口读上下文。' +
|
|
144
|
+
'仅限知识库目录内的 .md 文件(路径越界会被拒绝)。' +
|
|
145
|
+
'仅限 dsh(DeepSeek Harness)插件开发知识库。',
|
|
146
|
+
parameters: {
|
|
147
|
+
type: 'object',
|
|
148
|
+
additionalProperties: false,
|
|
149
|
+
required: ['path'],
|
|
150
|
+
properties: {
|
|
151
|
+
path: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
description: '知识库相对路径(正斜杠,如 "site/develop/basic/tool.md"、"extra/upgrade-guide/v0.2.0-rc.2/guide.zh.md")'
|
|
154
|
+
},
|
|
155
|
+
offset: {
|
|
156
|
+
type: 'integer',
|
|
157
|
+
description: '起始行(1 基,默认 1)'
|
|
158
|
+
},
|
|
159
|
+
limit: {
|
|
160
|
+
type: 'integer',
|
|
161
|
+
description: '读取行数(默认 120,最大 400)'
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
output: {
|
|
166
|
+
schema: {
|
|
167
|
+
type: 'object',
|
|
168
|
+
additionalProperties: false,
|
|
169
|
+
required: ['kind', 'text'],
|
|
170
|
+
properties: {
|
|
171
|
+
kind: { type: 'string', enum: ['text', 'error'] },
|
|
172
|
+
text: { type: 'string' }
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
render: (_args, value) => [{ type: 'text', text: value.text }]
|
|
176
|
+
},
|
|
177
|
+
async execute(args) {
|
|
178
|
+
const { index, error } = getIndex('zh')
|
|
179
|
+
if (error) throw new Error(error)
|
|
180
|
+
const rel = String(args.path ?? '').replaceAll('\\', '/').replace(/^\/+/, '')
|
|
181
|
+
if (!rel || !rel.endsWith('.md')) {
|
|
182
|
+
return { kind: 'error', text: `【拒绝】path 必须是知识库内的 .md 相对路径,收到:${rel || '(空)'}` }
|
|
183
|
+
}
|
|
184
|
+
const abs = resolve(index.kbDir, ...rel.split('/'))
|
|
185
|
+
const kbRootResolved = resolve(index.kbDir)
|
|
186
|
+
if (abs !== kbRootResolved && !abs.startsWith(kbRootResolved + sep)) {
|
|
187
|
+
return { kind: 'error', text: `【拒绝】路径越界:${rel}(只允许知识库目录内的文件)` }
|
|
188
|
+
}
|
|
189
|
+
let lines
|
|
190
|
+
try {
|
|
191
|
+
const st = statSync(abs)
|
|
192
|
+
if (st.size > 8_000_000) {
|
|
193
|
+
return { kind: 'error', text: `【拒绝】文件过大(${st.size} 字节):${rel}` }
|
|
194
|
+
}
|
|
195
|
+
lines = readFileSync(abs, 'utf8').split(/\r?\n/)
|
|
196
|
+
} catch (err) {
|
|
197
|
+
return { kind: 'error', text: `【读取失败】${rel}(${err?.message ?? err})。提示:先用 dsh_kb_search 确认路径是否在索引内。` }
|
|
198
|
+
}
|
|
199
|
+
const total = lines.length
|
|
200
|
+
const offset = Math.min(Math.max(Number(args.offset) > 0 ? Number(args.offset) : 1, 1), Math.max(total, 1))
|
|
201
|
+
const limit = Math.min(Math.max(Number(args.limit) > 0 ? Number(args.limit) : 120, 1), 400)
|
|
202
|
+
const end = Math.min(offset - 1 + limit, total)
|
|
203
|
+
const width = String(end).length
|
|
204
|
+
const body = lines.slice(offset - 1, end)
|
|
205
|
+
.map((l, i) => `${String(offset + i).padStart(width)}| ${l}`)
|
|
206
|
+
.join('\n')
|
|
207
|
+
const footer = []
|
|
208
|
+
if (end < total) footer.push(`(未完:共 ${total} 行,已读 L${offset}-${end};续读传 offset=${end + 1})`)
|
|
209
|
+
const alt = altLangPath(rel)
|
|
210
|
+
if (alt) footer.push(`中英对照:${alt.exists ? alt.rel : alt.rel + '(未收录)'}`)
|
|
211
|
+
const banner = versionBanner(index.kbDir, hostVersion)
|
|
212
|
+
const text = [
|
|
213
|
+
banner ?? '',
|
|
214
|
+
`【知识库阅读】${rel}(共 ${total} 行,窗口 L${offset}-${end})`,
|
|
215
|
+
body,
|
|
216
|
+
...footer,
|
|
217
|
+
].filter(Boolean).join('\n')
|
|
218
|
+
return { kind: 'text', text }
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** 中英对照路径推导:site/ ↔ site/en/,extra/*.zh.md ↔ extra/*.md。存在性现场检查。 */
|
|
224
|
+
function altLangPath(rel) {
|
|
225
|
+
let counter
|
|
226
|
+
if (rel.startsWith('site/en/')) counter = rel.replace('site/en/', 'site/')
|
|
227
|
+
else if (rel.startsWith('site/')) counter = rel.replace('site/', 'site/en/')
|
|
228
|
+
else if (rel.startsWith('extra/') && rel.endsWith('.zh.md')) counter = rel.slice(0, -'.zh.md'.length) + '.md'
|
|
229
|
+
else if (rel.startsWith('extra/') && rel.endsWith('.md') && !rel.endsWith('.zh.md')) counter = rel.slice(0, -'.md'.length) + '.zh.md'
|
|
230
|
+
else return null
|
|
231
|
+
const abs = join(KB_DIR, ...counter.split('/'))
|
|
232
|
+
return { rel: counter, exists: existsSync(abs) }
|
|
233
|
+
}
|
|
234
|
+
|
|
28
235
|
/** logger 拿不到时降级 console。 */
|
|
29
236
|
function makeLogger(ctx, tag) {
|
|
30
237
|
return {
|
|
@@ -77,6 +284,11 @@ function loadSkills(log) {
|
|
|
77
284
|
|
|
78
285
|
export function apply(ctx, config) {
|
|
79
286
|
const log = makeLogger(ctx, '[dsh-plugin-dev-kb]')
|
|
287
|
+
const cfg = { ...DEFAULT_CONFIG, ...(config ?? {}) }
|
|
288
|
+
// 显式布尔归一(patch 配置可能是字符串)
|
|
289
|
+
for (const key of Object.keys(DEFAULT_CONFIG)) {
|
|
290
|
+
if (typeof cfg[key] === 'string') cfg[key] = cfg[key] === 'true'
|
|
291
|
+
}
|
|
80
292
|
|
|
81
293
|
// 契约(dsh-skill validateDefinition):定义必须含 name/description/
|
|
82
294
|
// source/content 四个字符串;provider 缺省为 'runtime'。
|
|
@@ -98,5 +310,50 @@ export function apply(ctx, config) {
|
|
|
98
310
|
log.info(`技能已注册:${skill.name}`)
|
|
99
311
|
}
|
|
100
312
|
|
|
313
|
+
// B. 检索工具(1.6.0 起)+ 局部阅读工具(1.8.0 起):
|
|
314
|
+
// 索引惰性构建(首次调用时建,宿主启动零开销),zh/en 各缓存一份;
|
|
315
|
+
// 宿主版本探测一次性完成(拿不到 → 工具输出不带版本横幅);
|
|
316
|
+
// kb 目录缺失 → 工具执行时报错并提示退回文件工具检索。
|
|
317
|
+
const hostVersion = detectHostVersion(PKG_DIR)
|
|
318
|
+
if (hostVersion) {
|
|
319
|
+
log.info(`宿主 dsh 版本探测:${hostVersion.version}(${hostVersion.source})`)
|
|
320
|
+
} else {
|
|
321
|
+
log.warn('宿主 dsh 版本探测失败(工具输出将不带版本横幅)')
|
|
322
|
+
}
|
|
323
|
+
if (cfg.searchTool || cfg.readTool) {
|
|
324
|
+
if (typeof ctx.tools?.register === 'function') {
|
|
325
|
+
const indexCache = new Map()
|
|
326
|
+
const getIndex = (lang) => {
|
|
327
|
+
if (indexCache.has(lang)) return { index: indexCache.get(lang), error: undefined }
|
|
328
|
+
if (!existsSync(KB_DIR)) {
|
|
329
|
+
return {
|
|
330
|
+
index: undefined,
|
|
331
|
+
error: `知识库目录缺失:${KB_DIR.replaceAll('\\', '/')}(插件安装不完整?请改用文件工具 grep 检索,或重装插件)`
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
const t0 = Date.now()
|
|
336
|
+
const index = buildIndex(KB_DIR, lang, log)
|
|
337
|
+
indexCache.set(lang, index)
|
|
338
|
+
log.info(`知识库${lang} 索引就绪:${index.files.length} 个文件(${Date.now() - t0}ms)`)
|
|
339
|
+
return { index, error: undefined }
|
|
340
|
+
} catch (err) {
|
|
341
|
+
return {
|
|
342
|
+
index: undefined,
|
|
343
|
+
error: `知识库索引构建失败:${err?.message ?? err}(请改用文件工具 grep 检索知识库目录)`
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
ctx.effect(() => ctx.tools.register(kbSearchTool(getIndex, hostVersion), 'dsh-plugin-dev-kb: register dsh_kb_search'), 'dsh-plugin-dev-kb: register dsh_kb_search')
|
|
348
|
+
log.info('工具已注册:dsh_kb_search')
|
|
349
|
+
if (cfg.readTool) {
|
|
350
|
+
ctx.effect(() => ctx.tools.register(kbReadTool(getIndex, hostVersion), 'dsh-plugin-dev-kb: register dsh_kb_read'), 'dsh-plugin-dev-kb: register dsh_kb_read')
|
|
351
|
+
log.info('工具已注册:dsh_kb_read')
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
log.warn('ctx.tools.register 不可用,dsh_kb_search 未注册(工具子系统的注入可能失败)')
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
101
358
|
log.info(`已挂载(知识库在 kb/ 目录)`)
|
|
102
359
|
}
|
package/lib/kb-search.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kb-search — 知识库本地打分检索(零依赖,纯函数)。
|
|
3
|
+
*
|
|
4
|
+
* 为 dsh_kb_search 工具提供两段式能力:
|
|
5
|
+
* buildIndex(kbDir, log) 扫描 kb/ 构建 内存索引(每文件:相对路径、标题、行数组)。
|
|
6
|
+
* 中文索引默认扫 site/(跳过 site/en/)+ extra/(跳过 *.zh.md
|
|
7
|
+
* 的英文原文对?不——extra 中英成对,跳过无 .zh 后缀的英文版)
|
|
8
|
+
* + meta/topics.md;英文索引按需构建(lang=en)。
|
|
9
|
+
* search(index, query, opts) 按空白分词打分:标题命中 ×8、路径命中 ×4、
|
|
10
|
+
* 正文行命中 ×1(多词同现加权),返回 top N 文件,
|
|
11
|
+
* 每文件附命中行号与上下文片段(每文件最多 maxSnippets 处)。
|
|
12
|
+
*
|
|
13
|
+
* 设计约束:
|
|
14
|
+
* - 只读 kb/,绝不写任何文件;索引在内存,宿主重启重建(构建毫秒级)。
|
|
15
|
+
* - 大文件不整读返回:只回片段 + 行号,模型再按行号 read 局部。
|
|
16
|
+
* - 输出总量截断保护(renderChars),超出提示用文件工具局部读。
|
|
17
|
+
* - 失败安全:任何文件读不了就跳过并计数警告,绝不让索引构建抛错崩掉宿主。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs'
|
|
21
|
+
import { join, relative, sep } from 'node:path'
|
|
22
|
+
|
|
23
|
+
/** 单文件大小上限(1.5MB):超过则跳过正文索引,只保留标题/路径(防止异常大文件拖慢启动)。 */
|
|
24
|
+
const MAX_FILE_BYTES = 1_500_000
|
|
25
|
+
|
|
26
|
+
/** 递归收集目录下全部 .md 文件(相对路径,正斜杠)。 */
|
|
27
|
+
function listMarkdownFiles(dir, base) {
|
|
28
|
+
const out = []
|
|
29
|
+
let entries
|
|
30
|
+
try {
|
|
31
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
32
|
+
} catch {
|
|
33
|
+
return out
|
|
34
|
+
}
|
|
35
|
+
for (const e of entries) {
|
|
36
|
+
const full = join(dir, e.name)
|
|
37
|
+
if (e.isDirectory()) {
|
|
38
|
+
out.push(...listMarkdownFiles(full, base))
|
|
39
|
+
} else if (e.isFile() && e.name.endsWith('.md')) {
|
|
40
|
+
out.push(relative(base, full).split(sep).join('/'))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 判断相对路径是否纳入指定语言的索引。 */
|
|
47
|
+
function includeForLang(rel, lang) {
|
|
48
|
+
if (lang === 'en') {
|
|
49
|
+
// 英文:site/en/** 或 extra 下无 .zh.md 对应的英文原文;topics 导航保留(中文但导航有效)
|
|
50
|
+
if (rel.startsWith('site/en/')) return true
|
|
51
|
+
if (rel.startsWith('extra/')) return !isZhPair(rel)
|
|
52
|
+
if (rel === 'meta/topics.md') return true
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
// 中文:site/ 下除 en/ 外全部;extra/ 下仅 *.zh.md;meta/topics.md
|
|
56
|
+
if (rel.startsWith('site/en/')) return false
|
|
57
|
+
if (rel.startsWith('site/')) return true
|
|
58
|
+
if (rel.startsWith('extra/')) return rel.endsWith('.zh.md')
|
|
59
|
+
if (rel === 'meta/topics.md') return true
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** rel 是否为 extra 下成对的中文版(*.zh.md)——中文索引收 .zh.md,英文索引收无后缀原文。 */
|
|
64
|
+
function isZhPair(rel) {
|
|
65
|
+
return rel.endsWith('.zh.md')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 读文件并切行;读失败返回 null。 */
|
|
69
|
+
function readLines(absPath) {
|
|
70
|
+
try {
|
|
71
|
+
const st = statSync(absPath)
|
|
72
|
+
if (st.size > MAX_FILE_BYTES) return null
|
|
73
|
+
return readFileSync(absPath, 'utf8').split(/\r?\n/)
|
|
74
|
+
} catch {
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 取文件首个 ATX 标题作为 title。 */
|
|
80
|
+
function firstHeading(lines) {
|
|
81
|
+
for (const line of lines) {
|
|
82
|
+
const m = /^#{1,6}\s+(.+)$/.exec(line)
|
|
83
|
+
if (m) return m[1].trim()
|
|
84
|
+
}
|
|
85
|
+
return ''
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 构建索引。
|
|
90
|
+
* @param {string} kbDir 知识库根(插件内 kb/ 绝对路径)
|
|
91
|
+
* @param {'zh'|'en'} [lang] 中文索引(默认):site/ 非 en + extra/*.zh.md + topics;
|
|
92
|
+
* 英文索引:site/en/** + extra/ 无 .zh 后缀原文。
|
|
93
|
+
* @param {{warn:(...a:any[])=>void}} [log]
|
|
94
|
+
* @returns {{ kbDir: string, lang: string, files: Array<{rel:string, abs:string, title:string, lines:string[]}> }}
|
|
95
|
+
*/
|
|
96
|
+
export function buildIndex(kbDir, lang = 'zh', log) {
|
|
97
|
+
const warn = log?.warn ?? (() => {})
|
|
98
|
+
const files = []
|
|
99
|
+
const rels = listMarkdownFiles(kbDir, kbDir)
|
|
100
|
+
for (const rel of rels) {
|
|
101
|
+
if (!includeForLang(rel, lang)) continue
|
|
102
|
+
const lines = readLines(join(kbDir, ...rel.split('/')))
|
|
103
|
+
if (!lines) {
|
|
104
|
+
warn(`索引跳过(读取失败或过大):${rel}`)
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
files.push({ rel, abs: join(kbDir, ...rel.split('/')), title: firstHeading(lines), lines })
|
|
108
|
+
}
|
|
109
|
+
// topics.md 永远排最前候选位(搜索无结果时兜底展示)
|
|
110
|
+
files.sort((a, b) => (a.rel === 'meta/topics.md' ? -1 : b.rel === 'meta/topics.md' ? 1 : a.rel < b.rel ? -1 : 1))
|
|
111
|
+
return { kbDir, lang, files }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** query 按空白分词 + 小写化;空结果返回 []。 */
|
|
115
|
+
function tokenize(query) {
|
|
116
|
+
return String(query ?? '')
|
|
117
|
+
.toLowerCase()
|
|
118
|
+
.split(/\s+/)
|
|
119
|
+
.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) // 转成正则安全串
|
|
120
|
+
.filter((t) => t.length > 0)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 从主词派生标题/路径子词(ctx.tools.register → ctx/tools/register),用于路径与标题的弱匹配。 */
|
|
124
|
+
function derivePathTerms(terms) {
|
|
125
|
+
const out = []
|
|
126
|
+
for (const t of terms) {
|
|
127
|
+
for (const seg of t.split(/[._/\\-]+/)) {
|
|
128
|
+
if (seg.length >= 3 && !out.includes(seg)) out.push(seg)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return out
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** API 类文件(scope='api' 时只搜这些):签名/目录/缝合点文档。 */
|
|
135
|
+
const API_PATH_RE = /(tool-catalog|config-catalog|capability-seams|cordis-api\/|subsystems\/|api-gateway|agent-lifecycle|persistence-catalog)/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 检索。
|
|
139
|
+
* @param {{kbDir:string, files:Array}} index buildIndex 产物
|
|
140
|
+
* @param {string} query 关键词(空白分隔多词);空或 'topics' 返回主题导航
|
|
141
|
+
* @param {{scope?:'all'|'api', maxResults?:number, maxSnippets?:number, renderChars?:number}} [opts]
|
|
142
|
+
*/
|
|
143
|
+
export function search(index, query, opts = {}) {
|
|
144
|
+
const maxResults = Math.min(Math.max(opts.maxResults ?? 8, 1), 20)
|
|
145
|
+
const maxSnippets = opts.maxSnippets ?? 3
|
|
146
|
+
const renderChars = opts.renderChars ?? 12000
|
|
147
|
+
const scope = opts.scope === 'api' ? 'api' : 'all'
|
|
148
|
+
|
|
149
|
+
const raw = String(query ?? '').trim()
|
|
150
|
+
if (!raw || raw.toLowerCase() === 'topics') {
|
|
151
|
+
return topicsDigest(index, renderChars)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const terms = tokenize(raw)
|
|
155
|
+
if (!terms.length) return topicsDigest(index, renderChars)
|
|
156
|
+
const termRes = terms.map((t) => new RegExp(t, 'i'))
|
|
157
|
+
const pathTermRes = derivePathTerms(terms).map((t) => new RegExp(t, 'i'))
|
|
158
|
+
|
|
159
|
+
const scored = []
|
|
160
|
+
for (const f of index.files) {
|
|
161
|
+
if (scope === 'api' && !API_PATH_RE.test(f.rel)) continue
|
|
162
|
+
let score = 0
|
|
163
|
+
const hitLineNums = []
|
|
164
|
+
for (let i = 0; i < f.lines.length; i++) {
|
|
165
|
+
let lineHit = 0
|
|
166
|
+
for (let k = 0; k < termRes.length; k++) {
|
|
167
|
+
if (termRes[k].test(f.lines[i])) lineHit++
|
|
168
|
+
}
|
|
169
|
+
if (lineHit > 0) {
|
|
170
|
+
// 多词同现的行更强:词数平方和近似
|
|
171
|
+
score += lineHit * lineHit
|
|
172
|
+
if (hitLineNums.length < 50) hitLineNums.push(i + 1)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (score === 0) continue
|
|
176
|
+
// 教程优先:入门/开发/指南路径下的文档在同等得分时更靠前
|
|
177
|
+
if (/^site\/(develop|guide)\//.test(f.rel)) score += 2
|
|
178
|
+
const titleLower = f.title.toLowerCase()
|
|
179
|
+
const relLower = f.rel.toLowerCase()
|
|
180
|
+
for (let k = 0; k < termRes.length; k++) {
|
|
181
|
+
if (termRes[k].test(titleLower)) score += 8
|
|
182
|
+
if (termRes[k].test(relLower)) score += 4
|
|
183
|
+
}
|
|
184
|
+
for (let k = 0; k < pathTermRes.length; k++) {
|
|
185
|
+
if (pathTermRes[k].test(titleLower)) score += 2
|
|
186
|
+
if (pathTermRes[k].test(relLower)) score += 3
|
|
187
|
+
}
|
|
188
|
+
scored.push({ file: f, score, hitLineNums })
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
scored.sort((a, b) => b.score - a.score || (a.file.rel < b.file.rel ? -1 : 1))
|
|
192
|
+
|
|
193
|
+
const files = []
|
|
194
|
+
let used = 0
|
|
195
|
+
for (const s of scored.slice(0, maxResults)) {
|
|
196
|
+
const f = s.file
|
|
197
|
+
const snippets = []
|
|
198
|
+
// 挑前 maxSnippets 个命中行,每个给前后各 2 行上下文
|
|
199
|
+
for (const ln of s.hitLineNums.slice(0, maxSnippets)) {
|
|
200
|
+
const from = Math.max(1, ln - 2)
|
|
201
|
+
const to = Math.min(f.lines.length, ln + 2)
|
|
202
|
+
const text = f.lines.slice(from - 1, to).join('\n')
|
|
203
|
+
snippets.push({ line: ln, from, text })
|
|
204
|
+
}
|
|
205
|
+
const entry = {
|
|
206
|
+
path: f.rel,
|
|
207
|
+
absPath: f.abs.replaceAll('\\', '/'),
|
|
208
|
+
title: f.title,
|
|
209
|
+
score: s.score,
|
|
210
|
+
hitLines: s.hitLineNums.slice(0, 12),
|
|
211
|
+
snippets,
|
|
212
|
+
}
|
|
213
|
+
// 预算控制:超过 renderChars 就不再多塞文件
|
|
214
|
+
const est = JSON.stringify(entry).length
|
|
215
|
+
if (used + est > renderChars && files.length > 0) break
|
|
216
|
+
used += est
|
|
217
|
+
files.push(entry)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (!files.length) {
|
|
221
|
+
return {
|
|
222
|
+
kind: 'empty',
|
|
223
|
+
query: raw,
|
|
224
|
+
scope,
|
|
225
|
+
hint: `无命中。建议:① 换更短的关键词(如 "tool" "config" "event");② query 传 "topics" 看主题导航;③ 用文件工具 grep 知识库目录。`,
|
|
226
|
+
topicsPath: absOf(index, 'meta/topics.md'),
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
kind: 'hits',
|
|
232
|
+
query: raw,
|
|
233
|
+
scope,
|
|
234
|
+
truncatedFiles: scored.length > files.length ? scored.length - files.length : 0,
|
|
235
|
+
files,
|
|
236
|
+
hint: '用 read 工具按 absPath + 行号局部读取原文;大文件禁止整读。',
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** 主题导航摘要(query 空 / 'topics' / 无命中兜底)。 */
|
|
241
|
+
function topicsDigest(index, renderChars) {
|
|
242
|
+
const f = index.files.find((x) => x.rel === 'meta/topics.md')
|
|
243
|
+
if (!f) {
|
|
244
|
+
return {
|
|
245
|
+
kind: 'topics',
|
|
246
|
+
hint: '知识库缺 meta/topics.md;请直接用文件工具 grep 知识库目录。',
|
|
247
|
+
kbRoot: index.kbDir.replaceAll('\\', '/'),
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
kind: 'topics',
|
|
252
|
+
topicsPath: f.abs.replaceAll('\\', '/'),
|
|
253
|
+
text: f.lines.join('\n').slice(0, renderChars),
|
|
254
|
+
hint: '按主题里的文件清单直接 read 对应文档。',
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function absOf(index, rel) {
|
|
259
|
+
const f = index.files.find((x) => x.rel === rel)
|
|
260
|
+
return f ? f.abs.replaceAll('\\', '/') : `${index.kbDir.replaceAll('\\', '/')}/${rel}`
|
|
261
|
+
}
|