@daweifu/capability-menu 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Dawei Fu
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ <h1 align="center">dsh-capability-menu</h1>
2
+
3
+ <p align="center">
4
+ <strong>为 DeepSeek Harness 提供统一的能力发现与按需执行。</strong><br>
5
+ 海量tools/skills也不会塞满一次请求, 节省token和上下文<br>
6
+ 所有能力分为exposed/progressive/blocked三级管理暴露程度和执行方式
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@daweifu/capability-menu"><img src="https://img.shields.io/npm/v/@daweifu/capability-menu.svg?style=flat-square&color=cb3837&labelColor=161b22&logo=npm&logoColor=white" alt="npm version"/></a>
11
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-2EA44F?style=flat-square&labelColor=161b22" alt="license"/></a>
12
+ <a href="https://github.com/PKUfudawei/dsh-capability-menu"><img src="https://img.shields.io/github/stars/PKUfudawei/dsh-capability-menu.svg?style=flat-square&color=dbab09&labelColor=161b22&logo=github&logoColor=white" alt="GitHub stars"/></a>
13
+ <a href="https://github.com/koishijs/cordis"><img src="https://img.shields.io/badge/stack-Cordis%20bundle-58a6ff.svg?style=flat-square&labelColor=161b22&logo=cardano&logoColor=white" alt="Cordis bundle"/></a>
14
+ <a href="https://github.com/deepseek-ai/deepseek-harness"><img src="https://img.shields.io/badge/engine-DeepSeek%20Harness-7c8cff.svg?style=flat-square&labelColor=161b22&logo=deepseek&logoColor=white" alt="DeepSeek Harness"/></a>
15
+ <a href="https://github.com/PKUfudawei/dsh-capability-menu/actions"><img src="https://img.shields.io/github/actions/workflow/status/PKUfudawei/dsh-capability-menu/ci.yml?branch=master&label=CI&style=flat-square&labelColor=161b22&logo=github&logoColor=white" alt="CI"/></a>
16
+ </p>
17
+
18
+ <br/>
19
+
20
+ dsh-capability-menu 是一个可独立安装的 Cordis 插件(`@daweifu/capability-menu`),为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 提供统一的能力目录(`ctx.meta`)、两个元工具(`meta_search` / `meta_invoke`)、以及 Exposed / Progressive / Blocked 三档能力策略(含 server 侧能力管理面)。它不修改上游源码,完全通过 Cordis 插件机制与 Harness 组合进同一个运行时。
21
+
22
+ ## 快速安装
23
+
24
+ 先构建并打包(源码仓库,`lib/` 需先产出):
25
+
26
+ ```bash
27
+ cd dsh-capability-menu
28
+ npm run build # tsc 产出 lib/(registry/search/invoke/policy/invariant/index)
29
+ pnpm pack # 生成 daweifu-capability-menu-0.1.0.tgz
30
+ ```
31
+
32
+ 把 `.tgz` 交给对方安装:
33
+
34
+ ```bash
35
+ dsh plugin --profile web add ./daweifu-capability-menu-0.1.0.tgz
36
+ ```
37
+
38
+ > `dsh plugin add` 一个**目录**会以 `link:` 方式安装,`lib/` 需要已构建,本地自测请用 `.tgz`。
39
+
40
+ 验证(应看到本包自己的 patch 层):
41
+
42
+ ```bash
43
+ dsh --profile web --dump-config | grep -E 'capability-menu'
44
+ ```
45
+
46
+ ```
47
+ # == @daweifu/capability-menu
48
+ - id: capability-menu-registry
49
+ name: '@daweifu/capability-menu/registry'
50
+ - id: capability-menu-search
51
+ name: '@daweifu/capability-menu/search'
52
+ - id: capability-menu-invoke
53
+ name: '@daweifu/capability-menu/invoke'
54
+ - id: capability-menu-policy
55
+ name: '@daweifu/capability-menu/policy'
56
+ ```
57
+
58
+ 卸载:
59
+
60
+ ```bash
61
+ dsh plugin --profile web remove @daweifu/capability-menu
62
+ ```
63
+
64
+ ## 能力模型
65
+
66
+ Capability 是上位概念,Tool / Skill 是不同类型的 capability,不是「两种工具」:
67
+
68
+ | kind | 对 Agent 提供 | action | 备注 |
69
+ | --- | --- | --- | --- |
70
+ | `tool` | 执行一个动作(MCP 工具) | `execute` | 由 `ctx.tools` 索引 |
71
+ | `skill` | 某类任务的方法/流程/知识 | `load` | 由 `ctx.skills` 索引 |
72
+
73
+ > `execute` / `load` 是 capability 对外声明的**规范 action**(`CapabilityAction = 'execute' | 'load'`)。tool 的 `execute` 在底层由 `ctx.tools.execute` 走完整工具管线执行;skill 的 `load` 加载方法/流程正文。当前版本(`0.1.0`)只有这两种 kind 与两种 action。
74
+
75
+ 模型获得两个元工具:
76
+
77
+ | 工具 | 作用 | 对应 entry |
78
+ | --- | --- | --- |
79
+ | `meta_search` | 检索能力目录(Tool / Skill),list/detail 双模式 | `@daweifu/capability-menu/search` |
80
+ | `meta_invoke` | 统一执行面:Tool 真执行(走完整 `ctx.tools` 管线)+ Skill 加载 | `@daweifu/capability-menu/invoke` |
81
+
82
+ > 边界:Command / Prompt / Memory 不是可发现可调用的能力,不进 registry。需要查知识/文档时直接用底层检索类 MCP 工具(如 `mcp__km__search`),它们和其他 MCP 工具一样被 `meta_search` 编目、被 `meta_invoke` 转发。
83
+ >
84
+ > 边界:非 `mcp__` 前缀的原生工具(`bash` / `read` / `write` / `edit` / `read_image` / `glob` / `grep` 等)**不进 registry**——不被 `meta_search` 编目、不被 `meta_invoke` 派发、也不在能力管理(`classifyAll`)枚举中。它们只受投影链(`system-prompt/assemble` 对 `assembly.tools` 的裁剪)影响可见性;且因不可 `meta_invoke`,一旦被投影掉就真的不可调用,所以请保留在 `tools.exposed` 保活(见下方配置示例;默认即 Exposed,但若被 `progressive`/`blocked` 通配规则覆盖则不可调用)。
85
+
86
+ ## 核心:Exposed / Progressive / Blocked 三档能力策略
87
+
88
+ 所有能力(Tool 与 Skill)按 **暴露程度**(模型在上下文中看到什么)与 **执行方式** 分为三档:
89
+
90
+ ### Tools / Skills 三档暴露与执行对照
91
+
92
+ | 档位 | 能力 | 暴露方式(模型视野) | 发现 | 执行方式 |
93
+ | --- | --- | --- | --- | --- |
94
+ | **Exposed** | tool | 完整 schema 进 `assembly.tools` → 模型请求 `tools` payload,每步可见 | 无需发现(已常驻) | 模型直接调用,运行时走完整 `ctx.tools` 管线 |
95
+ | | skill | 名字+描述进 `<available_skills>` 目录(正文不在目录) | 无需发现(已常驻) | `skill` 工具按需加载正文(渐进加载) |
96
+ | **Progressive** | tool | 不进 payload(零上下文成本) | `meta_search` list 返回 name+summary | `meta_invoke` 执行(走 `ctx.tools.execute`,管线完整);或 detail 拿 schema 后直接调 |
97
+ | | skill | 不进 `<available_skills>` 目录 | `meta_search` 检索(`progressiveSkillCatalog` 条目) | `meta_invoke` 按 `path` 加载 SKILL.md 正文 |
98
+ | **Blocked** | tool | 不进 payload | `meta_search` 不返回 | `meta_invoke` 拒绝,直接调用被投影排除 |
99
+ | | skill | 不进目录 | `meta_search` 不返回 | `meta_invoke` 拒绝 |
100
+
101
+ > **Exposed / Progressive 就是「高频 vs 低频」的具象化。** Exposed = 常驻、随叫随到的高频能力(拿 payload/目录体积换单跳可靠);Progressive = 归档进目录、用到才翻出来的低频能力(省 token、按需取用);Blocked = 明确禁止使用。它是**由你配置的驻留策略**(`tools.exposed`/`tools.progressive`/`tools.blocked` 规则),而不是按使用次数自动统计的标签。
102
+ >
103
+ > 上表的 tool 档位均指 `mcp__` 编目工具;原生工具不参与三档管理,只能以 `tools.exposed` 保活可见性(见"能力模型"边界说明)。
104
+
105
+ ## 配置(在 `@daweifu/capability-menu/policy` 上)
106
+
107
+ ```yaml
108
+ - insert:
109
+ - id: capability-menu-policy
110
+ name: '@daweifu/capability-menu/policy'
111
+ config:
112
+ tools:
113
+ exposed:
114
+ - execute_cmd
115
+ - get_session_context
116
+ - search_kb
117
+ - 'mcp__gongfeng__*' # 通配:该 server 下全部 Exposed
118
+ progressive:
119
+ - 'mcp__*' # 该规则覆盖所有未显式列出的 MCP 工具
120
+ - 'server:km:*' # 按 server 前缀批量 Progressive
121
+ blocked:
122
+ - 'mcp__secret__*' # 明确禁用(优先级最高,压过 Exposed)
123
+ skills:
124
+ exposed:
125
+ - debugging
126
+ - coding
127
+ progressive:
128
+ - legacy_skill # 显式 Progressive(未列出即默认 Exposed)
129
+ blocked:
130
+ - forbidden_skill
131
+ metaTools:
132
+ - meta_search # 恒 Exposed,不可被 Blocked
133
+ - meta_invoke
134
+ progressiveSkillCatalog: ~/.dsh/progressive-skills.yaml # Progressive skill 的 name+description+path 目录
135
+ ```
136
+
137
+ **规则优先级**(命中即停):`blocked` 精确 > `blocked` 通配 > `exposed` 精确 > `exposed` 通配 > `progressive` 精确 > `progressive` 通配 > 默认 Exposed。**blocked 压过 exposed**(控制语义)。meta 工具(`meta_search`/`meta_invoke`)恒为 Exposed,出现在 `blocked` 里会 fail loud。
138
+
139
+ > `tools.exposed` 里列原生工具名(`execute_cmd` 等)是**保活**语义:原生工具不进能力管理编目(`classifyAll` 列表里看不到它们),但投影链会裁剪其可见性,列在这里保持模型直接可见可调。不要因为"它不在能力管理里"就把它从 exposed 移除——一旦被 `progressive`/`blocked` 规则覆盖,模型既看不到也调不到。
140
+
141
+ ### 默认(不配置 policy)
142
+
143
+ - 不挂 `capability-menu-policy` → 全部工具/技能照旧可见(不投影)。
144
+ - 挂了 policy 但没有任何规则 → 全部能力默认 Exposed(`classify` 兜底),不投影、不隐藏。需要把低频能力归档进目录时,显式配置 `progressive`(或 `blocked`)规则把它们从模型视野中移出。
145
+
146
+ ### Progressive skill
147
+
148
+ Progressive skill 的 name + description + path 汇总进独立 YAML(`progressiveSkillCatalog`),由 registry 索引、`meta_search` 检索;完整 SKILL.md 由 `meta_invoke` 按需加载(`ctx.skills` 未注册时按 YAML 的 `path` 读取)。Progressive skill 不进固定上下文。
149
+
150
+ > 关于 `<available_skills>`:Exposed skill 走渐进加载(名字表 → load);Progressive/Blocked skill 不进入 `dsh-tool-skill` 注入的目录。目录级裁剪需要上游 `dsh-tool-skill` 提供 filter 钩子(超出本 bundle 范围);当前 Exposed skill = 会话 registry 中所有 model-invocable skill,Progressive skill = `progressiveSkillCatalog` 条目。
151
+
152
+ ## 机制设计
153
+
154
+ **核心第一性原则**:模型可见性(投影)与能力注册(registry 索引 + 执行能力)**必须解耦**。`ctx.tools.restrict` 会把工具从 `view.visible` 移除、连 `execute` 一起挡住(`UNKNOWN_TOOL`),因此本策略**不用 restrict 隐藏 Progressive**,而是在投影链 `system-prompt/assemble` 裁剪 `assembly.tools`,让 Progressive 工具保持全局注册、可检索、可执行。
155
+
156
+ Progressive 的**发现层(catalog)与执行层(`ctx.tools` 管线)分离**:catalog 只存元数据(name + description),完整 schema 从 `ctx.tools` 实时解析;无论哪一档,工具执行都落在 `ctx.tools` 管线上——审批/guard/沙箱/会话日志/取消齐全,不绕过。skill 无"执行",只有正文加载。Blocked 能力保留在 catalog 中(供管理面展示),但 `meta_search` 不返回、`meta_invoke` 拒绝。
157
+
158
+ ## 能力管理(server 侧 `ctx.capabilityPolicy`)
159
+
160
+ > 后端能力管理面,前端「能力菜单」tab 正是消费它。前端 React 包 `@daweifu/capability-menu-web`(本仓库 `web/`)的浏览器 bundle 与 host Typert 网关由 `web/` 的构建产出(见 `web/README.md`);`capabilityPolicy/*` remote 由网关托管,浏览器端 `ctx.remote.capabilityPolicy` 消费。
161
+
162
+ `@daweifu/capability-menu/policy` 注册 `ctx.capabilityPolicy` 服务,同时支撑运行期投影与前端管理:
163
+
164
+ | 方法 | 用途 |
165
+ | --- | --- |
166
+ | `getConfig()` / `updateConfig(partial)` | 读取/热更新策略配置(`tools`/`skills`/`metaTools` 等),改动立即重编译规则、无需重启。 |
167
+ | `classifyAll()` | 枚举 `ctx.meta` 目录中每个能力及其当前分类,返回 `{ id, kind, name, server?, class: 'exposed'\|'progressive'\|'blocked', classLabel, mandatory }`;`classLabel` 为「Exposed · 常驻(直接调用)/ Progressive · 按需(目录渐进加载)/ Blocked · 禁用」,供前端只读分类列表展示。 |
168
+ | `classifyTool`/`classifySkill`/`classifyCapability` | 单个能力的分类判定。 |
169
+ | `isExposedTool`/`isExposedSkill`/`isBlockedCapability`/`metaTools`/`toolRules`/`skillRules` | 投影链与执行面消费的判定与规则视图。 |
170
+
171
+ 这些方法全部是纯 server 方法(可单测),前端通过 harness 的 remote/RPC 层调用。
172
+
173
+ ## 仓库结构
174
+
175
+ ```
176
+ dsh-capability-menu/ # 单包 = @daweifu/capability-menu
177
+ ├── package.json # exports 子路径 + dsh.bundle → ./cordis.patch.yml
178
+ ├── cordis.patch.yml # insert registry/search/invoke/policy 四个子路径 entry
179
+ ├── tsconfig.json / vitest.config.ts
180
+ ├── src/
181
+ │ ├── registry.ts # (P0)能力目录 + ctx.meta 服务(不注册工具)
182
+ │ ├── search.ts # (P1)注册 meta_search
183
+ │ ├── invoke.ts # (P2)注册 meta_invoke
184
+ │ ├── policy.ts # (P3)Exposed/Progressive/Blocked 投影策略 + ctx.capabilityPolicy 能力管理
185
+ │ ├── invariant.ts
186
+ │ └── index.ts # re-export 全部
187
+ ├── tests/ # registry / search / invoke / policy 四套用例
188
+ └── web/ # 前端「能力菜单」tab(client bundle + host Typert 网关,见 web/README.md)
189
+ ```
190
+
191
+ ## 开发
192
+
193
+ - `src/` 为 TypeScript 源码,`lib/` 为预构建产物(`npm run build` 产出,本仓库直接分发 `lib/`)。`package.json` 的 `exports` 声明 `/registry` `/search` `/invoke` `/policy` `/invariant` 五个子路径,`cordis.patch.yml` 挂载前四个为 entry。
194
+ - `@deepseek-ai/*` 依赖为 peer 依赖(运行时从 dsh 安装闭包解析);`@deepseek-ai/schemastery` 与 `js-yaml` 为运行时依赖(后者解析 `progressiveSkillCatalog`)。
195
+ - 安装时自动构建:本包 `prepare` 脚本会在支持 lifecycle 的安装路径(git / 打包安装)下自动执行 `npm run build` 产出 `lib/`;前端包 `web/` 的 `prepare` 同样自动执行 `npm run bundle` 产出客户端 bundle(需 dsh-client 环境)。
196
+ - 测试:`pnpm install && npx vitest run`(33 个用例,覆盖 registry / search / invoke / policy,含能力管理面用例)。
197
+
198
+ ## 环境前置
199
+
200
+ - 已安装 dsh CLI 和 pnpm(`dsh plugin` 内部会转发给 pnpm)。
201
+
202
+ ## License
203
+
204
+ 本项目遵循 [Apache License 2.0](LICENSE)。
205
+
206
+ > 一个可独立安装的 Cordis 插件,为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 提供能力发现、按需执行与 Exposed/Progressive/Blocked 投影策略。核心的智能体、模型、工具、会话、Web UI 与插件生态都来自上游项目。
@@ -0,0 +1,87 @@
1
+ # dsh-capability-menu aggregate bundle patch: mounts the meta plugins in one
2
+ # layer, from a single installable package.
3
+ #
4
+ # One package, four plugin entries — each mounts a subpath of
5
+ # `@daweifu/capability-menu` (the loader resolves package subpath exports; see
6
+ # `@deepseek-ai/dsh-web-app/startup` for the same pattern in the harness):
7
+ #
8
+ # - id: capability-menu-registry
9
+ # name: '@daweifu/capability-menu/registry'
10
+ # - id: capability-menu-search
11
+ # name: '@daweifu/capability-menu/search'
12
+ # - id: capability-menu-invoke
13
+ # name: '@daweifu/capability-menu/invoke'
14
+ # - id: capability-menu-policy
15
+ # name: '@daweifu/capability-menu/policy'
16
+ # config:
17
+ # tools:
18
+ # exposed:
19
+ # - execute_cmd
20
+ # - get_session_context
21
+ # - search_kb
22
+ # - 'mcp__gongfeng__*'
23
+ # progressive:
24
+ # - 'mcp__*'
25
+ # - 'server:km:*'
26
+ # blocked: []
27
+ # skills:
28
+ # exposed:
29
+ # - debugging
30
+ # - coding
31
+ # metaTools:
32
+ # - meta_search
33
+ # - meta_invoke
34
+ # progressiveSkillCatalog: ~/.dsh/progressive-skills.yaml
35
+ #
36
+ # - `capability-menu-registry` (P0): builds/indexes the capability catalog and
37
+ # exposes the `ctx.meta` service (search/get/getDetail/refresh). It registers
38
+ # no model-facing tool itself. Indexes the GLOBAL registry (no visibility
39
+ # filter) and additionally indexes Progressive skills from
40
+ # `progressiveSkillCatalog` (§7.2).
41
+ # - `capability-menu-search` (P1): registers the `meta_search` tool (list + detail).
42
+ # - `capability-menu-invoke` (P2): registers the `meta_invoke` tool (unified
43
+ # execution of MCP tools and skill loading). Executes on the GLOBAL view
44
+ # (no agent) so Progressive tools stay runnable; dedups already-loaded skills.
45
+ # Rejects Blocked capabilities.
46
+ # - `capability-menu-policy` (P3): Exposed/Progressive/Blocked projection
47
+ # strategy + 能力管理 surface. Reads explicit exposed/progressive/blocked
48
+ # rules (exact name + glob + server:<name>:*) and filters `assembly.tools` at
49
+ # `system-prompt/assemble` to Exposed + meta tools only. The execution chain
50
+ # (`ctx.tools.execute`) is untouched, so Progressive tools remain executable
51
+ # via `meta_invoke`. Exposes `ctx.capabilityPolicy` with
52
+ # `classifyAll`/`getConfig`/`updateConfig` for the frontend 能力菜单 tab
53
+ # (Exposed/Progressive/Blocked rules + click-to-cycle classification +
54
+ # read-only list), plus skill file browsing (`getDetail`/`listSkillDir`/
55
+ # `readSkillFile`) via the Typert gateway.
56
+ #
57
+ # Default (policy present but no config): every capability is Exposed — the
58
+ # `classify` fallback, nothing is hidden. Add explicit `progressive`/`blocked`
59
+ # rules to pull capabilities out of the model surface. This bundle ships the
60
+ # harness-native coding tools under `tools.exposed` so the model keeps direct
61
+ # bash/file access.
62
+ - insert:
63
+ - id: capability-menu-registry
64
+ name: '@daweifu/capability-menu/registry'
65
+ - id: capability-menu-search
66
+ name: '@daweifu/capability-menu/search'
67
+ - id: capability-menu-invoke
68
+ name: '@daweifu/capability-menu/invoke'
69
+ - id: capability-menu-policy
70
+ name: '@daweifu/capability-menu/policy'
71
+ config:
72
+ # Harness-native coding tools stay context-resident (Exposed) so the
73
+ # model can call them directly. meta_invoke only dispatches MCP `mcp__*`
74
+ # tools, so native tools (bash/read/write/edit/glob/grep) MUST stay
75
+ # Exposed — listing them Progressive/Blocked would make them neither
76
+ # visible nor invocable. The default (unlisted) class is Exposed; add
77
+ # explicit `progressive`/`blocked` rules to pull MCP servers and skills
78
+ # out of the model surface.
79
+ tools:
80
+ exposed:
81
+ - bash
82
+ - read
83
+ - write
84
+ - edit
85
+ - read_image
86
+ - glob
87
+ - grep
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @daweifu/capability-menu — consolidated plugin package.
3
+ *
4
+ * One installable source package exposing four cordis plugin factories that the
5
+ * bundle mounts as separate entries via subpath exports (`/registry`, `/search`,
6
+ * `/invoke`, `/policy`):
7
+ *
8
+ * - `registry` (P0): capability catalog + `ctx.meta` service (no model tool).
9
+ * - `search` (P1): registers `meta_search`.
10
+ * - `invoke` (P2): registers `meta_invoke`.
11
+ * - `policy` (P3): Exposed/Progressive/Blocked projection policy + `ctx.capabilityPolicy`.
12
+ *
13
+ * @module @daweifu/capability-menu
14
+ */
15
+ export * from "./registry.js";
16
+ export * as registry from "./registry.js";
17
+ export * as search from "./search.js";
18
+ export * as invoke from "./invoke.js";
19
+ export * as policy from "./policy.js";
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Package-owned invariant companion for `@daweifu/capability-menu`.
3
+ * @module @daweifu/capability-menu/invariant
4
+ */
5
+ const PACKAGE_NAME = '@daweifu/capability-menu';
6
+ /** Cordis companion plugin name. */
7
+ export const name = 'capability-menu-invariant';
8
+ /** Service required before the companion can reserve package ownership. */
9
+ export const inject = ['invariants'];
10
+ /**
11
+ * No runtime invariant: the capability catalog has no independent lifecycle
12
+ * stream; its index mirrors the tools/skills registries it observes.
13
+ */
14
+ const install = () => { };
15
+ /**
16
+ * Register this package's invariant companion.
17
+ * @param ctx - Cordis context carrying the invariant service.
18
+ * @returns the installed registration's disposer after setup succeeds.
19
+ */
20
+ export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
21
+ /* jscpd:ignore-end */
22
+ //# sourceMappingURL=invariant.js.map