mcp-probe-kit 3.2.0 → 3.6.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.
Files changed (180) hide show
  1. package/README.md +25 -7
  2. package/build/index.js +45 -79
  3. package/build/lib/__tests__/agents-md-template.unit.test.js +1 -0
  4. package/build/lib/__tests__/dev-workflow.unit.test.js +22 -0
  5. package/build/lib/__tests__/handles.unit.test.js +19 -0
  6. package/build/lib/__tests__/mcp-apps.unit.test.d.ts +1 -0
  7. package/build/lib/__tests__/mcp-apps.unit.test.js +52 -0
  8. package/build/lib/__tests__/mcp-tool-skill-registry.unit.test.d.ts +1 -0
  9. package/build/lib/__tests__/mcp-tool-skill-registry.unit.test.js +18 -0
  10. package/build/lib/__tests__/memory-client.unit.test.js +105 -0
  11. package/build/lib/__tests__/memory-orchestration.unit.test.d.ts +1 -0
  12. package/build/lib/__tests__/memory-orchestration.unit.test.js +88 -0
  13. package/build/lib/__tests__/memory-payload.unit.test.d.ts +1 -0
  14. package/build/lib/__tests__/memory-payload.unit.test.js +35 -0
  15. package/build/lib/__tests__/quality-constraints.unit.test.d.ts +1 -0
  16. package/build/lib/__tests__/quality-constraints.unit.test.js +54 -0
  17. package/build/lib/__tests__/spec-gate.unit.test.d.ts +1 -0
  18. package/build/lib/__tests__/spec-gate.unit.test.js +54 -0
  19. package/build/lib/__tests__/spec-validator.unit.test.js +106 -74
  20. package/build/lib/__tests__/task-defaults.unit.test.d.ts +1 -0
  21. package/build/lib/__tests__/task-defaults.unit.test.js +27 -0
  22. package/build/lib/__tests__/workflow-skill-installer.unit.test.d.ts +1 -0
  23. package/build/lib/__tests__/workflow-skill-installer.unit.test.js +110 -0
  24. package/build/lib/agents-md-template.js +40 -32
  25. package/build/lib/cursor-history-client.d.ts +54 -0
  26. package/build/lib/cursor-history-client.js +240 -0
  27. package/build/lib/dev-workflow.d.ts +36 -0
  28. package/build/lib/dev-workflow.js +497 -0
  29. package/build/lib/handles.d.ts +31 -0
  30. package/build/lib/handles.js +36 -0
  31. package/build/lib/mcp-apps.d.ts +14 -0
  32. package/build/lib/mcp-apps.js +234 -0
  33. package/build/lib/mcp-tool-skill-registry.d.ts +46 -0
  34. package/build/lib/mcp-tool-skill-registry.js +256 -0
  35. package/build/lib/memory-client.d.ts +19 -0
  36. package/build/lib/memory-client.js +69 -0
  37. package/build/lib/memory-orchestration.d.ts +5 -0
  38. package/build/lib/memory-orchestration.js +20 -0
  39. package/build/lib/merge-agents-md.d.ts +2 -2
  40. package/build/lib/merge-agents-md.js +7 -4
  41. package/build/lib/output-schema-registry.d.ts +11 -0
  42. package/build/lib/output-schema-registry.js +80 -0
  43. package/build/lib/quality-constraints.d.ts +54 -0
  44. package/build/lib/quality-constraints.js +155 -0
  45. package/build/lib/skill-bridge.js +12 -12
  46. package/build/lib/spec-gate.d.ts +32 -0
  47. package/build/lib/spec-gate.js +83 -0
  48. package/build/lib/spec-validator.js +16 -3
  49. package/build/lib/task-defaults.d.ts +6 -0
  50. package/build/lib/task-defaults.js +20 -0
  51. package/build/lib/template-loader.js +83 -23
  52. package/build/lib/tool-annotations.js +3 -0
  53. package/build/lib/toolset-manager.js +2 -0
  54. package/build/lib/workflow-skill-installer.d.ts +38 -0
  55. package/build/lib/workflow-skill-installer.js +158 -0
  56. package/build/lib/workflow-skill-template.d.ts +9 -0
  57. package/build/lib/workflow-skill-template.js +85 -0
  58. package/build/lib/workflow-skill-version.d.ts +15 -0
  59. package/build/lib/workflow-skill-version.js +68 -0
  60. package/build/resources/ui-ux-data/guidelines/vercel-web-interface.json +1632 -1632
  61. package/build/resources/ui-ux-data/metadata.json +30 -30
  62. package/build/resources/ui-ux-data/shadcn/blocks.json +2541 -2541
  63. package/build/resources/ui-ux-data/shadcn/components.json +997 -997
  64. package/build/resources/ui-ux-data/themes/presets.json +483 -483
  65. package/build/schemas/index.d.ts +110 -0
  66. package/build/schemas/index.js +1 -0
  67. package/build/schemas/memory-tools.d.ts +83 -0
  68. package/build/schemas/memory-tools.js +43 -0
  69. package/build/schemas/orchestration-tools.d.ts +8 -0
  70. package/build/schemas/orchestration-tools.js +8 -0
  71. package/build/schemas/output/code-insight-tools.d.ts +65 -0
  72. package/build/schemas/output/code-insight-tools.js +42 -0
  73. package/build/schemas/output/memory-tools.d.ts +576 -0
  74. package/build/schemas/output/memory-tools.js +148 -0
  75. package/build/schemas/project-tools.d.ts +19 -0
  76. package/build/schemas/project-tools.js +20 -0
  77. package/build/tools/__tests__/cursor-history.unit.test.d.ts +1 -0
  78. package/build/tools/__tests__/cursor-history.unit.test.js +38 -0
  79. package/build/tools/__tests__/delete_memory_asset.unit.test.d.ts +1 -0
  80. package/build/tools/__tests__/delete_memory_asset.unit.test.js +87 -0
  81. package/build/tools/__tests__/search_memory.unit.test.js +1 -0
  82. package/build/tools/__tests__/start_bugfix.unit.test.js +34 -1
  83. package/build/tools/__tests__/update_memory_asset.unit.test.d.ts +1 -0
  84. package/build/tools/__tests__/update_memory_asset.unit.test.js +82 -0
  85. package/build/tools/__tests__/workflow.unit.test.d.ts +1 -0
  86. package/build/tools/__tests__/workflow.unit.test.js +24 -0
  87. package/build/tools/check_spec.js +16 -16
  88. package/build/tools/code_insight.js +46 -42
  89. package/build/tools/code_review.js +11 -4
  90. package/build/tools/cursor_read_conversation.d.ts +7 -0
  91. package/build/tools/cursor_read_conversation.js +36 -0
  92. package/build/tools/delete_memory_asset.d.ts +7 -0
  93. package/build/tools/delete_memory_asset.js +57 -0
  94. package/build/tools/fix_bug.js +161 -161
  95. package/build/tools/gencommit.js +60 -60
  96. package/build/tools/index.d.ts +3 -0
  97. package/build/tools/index.js +3 -0
  98. package/build/tools/init_project_context.js +432 -432
  99. package/build/tools/search_memory.js +5 -2
  100. package/build/tools/start_bugfix.js +37 -4
  101. package/build/tools/start_feature.js +4 -3
  102. package/build/tools/start_product.js +1 -1
  103. package/build/tools/start_ui.js +22 -4
  104. package/build/tools/ui-ux-tools.d.ts +3 -0
  105. package/build/tools/ui-ux-tools.js +302 -290
  106. package/build/tools/update_memory_asset.d.ts +7 -0
  107. package/build/tools/update_memory_asset.js +98 -0
  108. package/build/tools/workflow.d.ts +13 -0
  109. package/build/tools/workflow.js +69 -0
  110. package/build/utils/__tests__/vercel-guidelines-sync.unit.test.js +12 -12
  111. package/build/utils/design-reasoning-engine.d.ts +2 -0
  112. package/build/utils/design-reasoning-engine.js +3 -0
  113. package/build/utils/themes-sync.js +8 -8
  114. package/package.json +6 -3
  115. package/build/resources/index.d.ts +0 -4
  116. package/build/resources/index.js +0 -4
  117. package/build/resources/tool-params-guide.d.ts +0 -571
  118. package/build/resources/tool-params-guide.js +0 -488
  119. package/build/tools/analyze_project.d.ts +0 -1
  120. package/build/tools/analyze_project.js +0 -527
  121. package/build/tools/check_deps.d.ts +0 -13
  122. package/build/tools/check_deps.js +0 -204
  123. package/build/tools/convert.d.ts +0 -13
  124. package/build/tools/convert.js +0 -599
  125. package/build/tools/css_order.d.ts +0 -13
  126. package/build/tools/css_order.js +0 -81
  127. package/build/tools/debug.d.ts +0 -13
  128. package/build/tools/debug.js +0 -131
  129. package/build/tools/design2code.d.ts +0 -20
  130. package/build/tools/design2code.js +0 -426
  131. package/build/tools/detect_shell.d.ts +0 -6
  132. package/build/tools/detect_shell.js +0 -151
  133. package/build/tools/explain.d.ts +0 -13
  134. package/build/tools/explain.js +0 -390
  135. package/build/tools/fix.d.ts +0 -13
  136. package/build/tools/fix.js +0 -303
  137. package/build/tools/gen_mock.d.ts +0 -22
  138. package/build/tools/gen_mock.js +0 -269
  139. package/build/tools/gen_skill.d.ts +0 -13
  140. package/build/tools/gen_skill.js +0 -560
  141. package/build/tools/genapi.d.ts +0 -13
  142. package/build/tools/genapi.js +0 -174
  143. package/build/tools/genchangelog.d.ts +0 -13
  144. package/build/tools/genchangelog.js +0 -250
  145. package/build/tools/gendoc.d.ts +0 -13
  146. package/build/tools/gendoc.js +0 -232
  147. package/build/tools/genpr.d.ts +0 -13
  148. package/build/tools/genpr.js +0 -194
  149. package/build/tools/genreadme.d.ts +0 -13
  150. package/build/tools/genreadme.js +0 -626
  151. package/build/tools/gensql.d.ts +0 -13
  152. package/build/tools/gensql.js +0 -320
  153. package/build/tools/genui.d.ts +0 -13
  154. package/build/tools/genui.js +0 -803
  155. package/build/tools/init_component_catalog.d.ts +0 -22
  156. package/build/tools/init_component_catalog.js +0 -809
  157. package/build/tools/init_setting.d.ts +0 -13
  158. package/build/tools/init_setting.js +0 -47
  159. package/build/tools/perf.d.ts +0 -13
  160. package/build/tools/perf.js +0 -409
  161. package/build/tools/render_ui.d.ts +0 -22
  162. package/build/tools/render_ui.js +0 -384
  163. package/build/tools/resolve_conflict.d.ts +0 -13
  164. package/build/tools/resolve_conflict.js +0 -349
  165. package/build/tools/security_scan.d.ts +0 -22
  166. package/build/tools/security_scan.js +0 -323
  167. package/build/tools/split.d.ts +0 -13
  168. package/build/tools/split.js +0 -599
  169. package/build/tools/start_api.d.ts +0 -13
  170. package/build/tools/start_api.js +0 -193
  171. package/build/tools/start_doc.d.ts +0 -13
  172. package/build/tools/start_doc.js +0 -207
  173. package/build/tools/start_refactor.d.ts +0 -13
  174. package/build/tools/start_refactor.js +0 -188
  175. package/build/tools/start_release.d.ts +0 -13
  176. package/build/tools/start_release.js +0 -167
  177. package/build/tools/start_review.d.ts +0 -13
  178. package/build/tools/start_review.js +0 -175
  179. /package/build/{utils/design-docs-generator.d.ts → lib/__tests__/dev-workflow.unit.test.d.ts} +0 -0
  180. /package/build/{utils/design-docs-generator.js → lib/__tests__/handles.unit.test.d.ts} +0 -0
@@ -0,0 +1,497 @@
1
+ /**
2
+ * 开发工作流路由:根据用户意图生成「何时调哪个 MCP 工具」的委托式指南。
3
+ * 解决 Agent 直接写代码、跳过 start_* / code_insight / check_spec 的问题。
4
+ */
5
+ const SCENARIO_PATTERNS = [
6
+ {
7
+ scenario: 'bugfix',
8
+ patterns: [/bug|错误|异常|报错|修复|排查|回归|失败|crash|堆栈|stack|不生效|白屏|typeerror|referenceerror|error/i],
9
+ },
10
+ {
11
+ scenario: 'ui',
12
+ patterns: [/ui|界面|页面|组件|布局|样式|tailwind|shadcn|设计系统|交互/i],
13
+ },
14
+ {
15
+ scenario: 'explore',
16
+ patterns: [/架构|调用链|影响面|不熟|读懂|图谱|依赖|入口|code_insight|上下文/i],
17
+ },
18
+ {
19
+ scenario: 'commit',
20
+ patterns: [/提交|commit|changelog|写提交/i],
21
+ },
22
+ {
23
+ scenario: 'review',
24
+ patterns: [/审查|review|代码评审|安全检查/i],
25
+ },
26
+ {
27
+ scenario: 'refactor',
28
+ patterns: [/重构|refactor|整理代码|降复杂度/i],
29
+ },
30
+ {
31
+ scenario: 'onboard',
32
+ patterns: [/上手|onboard|新项目|熟悉项目|项目概览/i],
33
+ },
34
+ {
35
+ scenario: 'spec',
36
+ patterns: [/规格|spec|requirements|check_spec|验收/i],
37
+ },
38
+ {
39
+ scenario: 'memory',
40
+ patterns: [/记忆|沉淀|memorize|search_memory|历史经验|踩坑/i],
41
+ },
42
+ {
43
+ scenario: 'feature',
44
+ patterns: [/新功能|添加|实现|开发|feature|需求|做一?个/i],
45
+ },
46
+ ];
47
+ const SCENARIO_LABELS = {
48
+ feature: '新功能开发',
49
+ bugfix: 'Bug 修复',
50
+ ui: 'UI 开发',
51
+ explore: '代码探索 / 影响分析',
52
+ commit: '生成提交',
53
+ review: '代码审查',
54
+ refactor: '重构',
55
+ onboard: '项目上手',
56
+ spec: '规格校验',
57
+ memory: '记忆检索 / 沉淀',
58
+ unknown: '未明确(需先澄清)',
59
+ };
60
+ function scoreScenario(text, scenario) {
61
+ const entry = SCENARIO_PATTERNS.find((item) => item.scenario === scenario);
62
+ if (!entry) {
63
+ return 0;
64
+ }
65
+ return entry.patterns.reduce((score, pattern) => score + (pattern.test(text) ? 1 : 0), 0);
66
+ }
67
+ export function detectWorkflowScenario(intent, explicit) {
68
+ const normalizedExplicit = (explicit || '').trim().toLowerCase();
69
+ const explicitMap = {
70
+ feature: 'feature',
71
+ bugfix: 'bugfix',
72
+ bug: 'bugfix',
73
+ ui: 'ui',
74
+ explore: 'explore',
75
+ commit: 'commit',
76
+ review: 'review',
77
+ refactor: 'refactor',
78
+ onboard: 'onboard',
79
+ spec: 'spec',
80
+ memory: 'memory',
81
+ auto: 'unknown',
82
+ };
83
+ if (normalizedExplicit && normalizedExplicit !== 'auto' && explicitMap[normalizedExplicit]) {
84
+ return { scenario: explicitMap[normalizedExplicit], confidence: 'high' };
85
+ }
86
+ const text = intent.trim();
87
+ if (!text) {
88
+ return { scenario: 'unknown', confidence: 'low' };
89
+ }
90
+ const scores = SCENARIO_PATTERNS.map((item) => ({
91
+ scenario: item.scenario,
92
+ score: scoreScenario(text, item.scenario),
93
+ })).sort((a, b) => b.score - a.score);
94
+ const top = scores[0];
95
+ const second = scores[1];
96
+ if (!top || top.score === 0) {
97
+ return { scenario: 'feature', confidence: 'low' };
98
+ }
99
+ if (second && top.score === second.score) {
100
+ return { scenario: top.scenario, confidence: 'medium' };
101
+ }
102
+ return { scenario: top.scenario, confidence: top.score >= 2 ? 'high' : 'medium' };
103
+ }
104
+ function baseContextPhase() {
105
+ return {
106
+ id: 'context',
107
+ title: '补齐项目上下文(写代码前)',
108
+ when: '缺少 AGENTS.md / docs/project-context / graph-insights/latest.*',
109
+ steps: [
110
+ {
111
+ tool: 'init_project_context',
112
+ required: true,
113
+ when: '索引或图谱缺失',
114
+ note: '生成 AGENTS.md 与 project-context;Agent 应先读再动手',
115
+ },
116
+ ],
117
+ };
118
+ }
119
+ function memoryPhase() {
120
+ return {
121
+ id: 'memory',
122
+ title: '记忆(可选但推荐)',
123
+ when: '需要历史坑或可复用模式',
124
+ steps: [
125
+ {
126
+ tool: 'search_memory',
127
+ required: false,
128
+ when: 'start_* 未覆盖、或中途补查',
129
+ },
130
+ {
131
+ tool: 'memorize_asset',
132
+ required: false,
133
+ when: 'Bug 验证通过 / 有可复用产出后沉淀',
134
+ note: 'Bug → type=bugfix;功能/UI → pattern/component',
135
+ },
136
+ ],
137
+ };
138
+ }
139
+ function buildPlanForScenario(scenario, intent) {
140
+ const commonAvoid = [
141
+ '不要跳过 start_* 返回的 delegated plan 直接写实现代码',
142
+ '不要在不读 project-context / graph-insights 的情况下做大改',
143
+ '不要用 source_project/source_path 做跨仓库记忆沉淀',
144
+ ];
145
+ const commonMemory = [
146
+ 'start_* 会自动注入记忆;仍可用 search_memory 补查',
147
+ 'Bug 修完验证通过 → 必须 memorize_asset type=bugfix',
148
+ ];
149
+ switch (scenario) {
150
+ case 'bugfix':
151
+ return {
152
+ scenario,
153
+ scenarioLabel: SCENARIO_LABELS[scenario],
154
+ confidence: 'high',
155
+ summary: '先 TBP 真因分析再修,修复后回归测试 + 可选规格闸门 + 沉淀记忆',
156
+ firstTool: 'start_bugfix',
157
+ firstToolArgsHint: { error_message: intent },
158
+ phases: [
159
+ baseContextPhase(),
160
+ {
161
+ id: 'orchestrate',
162
+ title: 'Bug 修复编排(必须先调)',
163
+ when: '收到错误描述后第一步',
164
+ steps: [
165
+ {
166
+ tool: 'start_bugfix',
167
+ required: true,
168
+ when: '任何 Bug / 异常 / 排查任务',
169
+ note: '返回 delegated plan;按 steps 调用 fix_bug → gentest',
170
+ },
171
+ {
172
+ tool: 'code_insight',
173
+ required: false,
174
+ when: '需要调用链 / 影响面 / 不熟模块',
175
+ note: 'mode=impact 或 context',
176
+ },
177
+ ],
178
+ },
179
+ {
180
+ id: 'verify',
181
+ title: '验证与闸门',
182
+ when: '修复与测试通过后',
183
+ steps: [
184
+ {
185
+ tool: 'check_spec',
186
+ required: false,
187
+ when: 'Bug 关联 docs/specs/<feature>/ 时(可传 feature_name)',
188
+ },
189
+ {
190
+ tool: 'gencommit',
191
+ required: false,
192
+ when: '准备提交时',
193
+ },
194
+ ],
195
+ },
196
+ memoryPhase(),
197
+ ],
198
+ avoid: [...commonAvoid, '不要未闭合真因就改代码', '不要修完不跑测试'],
199
+ memoryNotes: commonMemory,
200
+ };
201
+ case 'ui':
202
+ return {
203
+ scenario,
204
+ scenarioLabel: SCENARIO_LABELS[scenario],
205
+ confidence: 'high',
206
+ summary: 'UI 任务统一走 start_ui,按设计系统 → 模板 → 实现',
207
+ firstTool: 'start_ui',
208
+ firstToolArgsHint: { description: intent },
209
+ phases: [
210
+ baseContextPhase(),
211
+ {
212
+ id: 'orchestrate',
213
+ title: 'UI 编排(必须先调)',
214
+ when: '任何页面/组件/样式任务',
215
+ steps: [{ tool: 'start_ui', required: true, when: 'UI 相关需求', note: '不要直接手写大段 UI 跳过设计系统' }],
216
+ },
217
+ memoryPhase(),
218
+ ],
219
+ avoid: [...commonAvoid, '不要跳过 ui_design_system / 一致性约束'],
220
+ memoryNotes: [...commonMemory, '可复用 UI 模式 → memorize_asset type=component'],
221
+ };
222
+ case 'explore':
223
+ return {
224
+ scenario,
225
+ scenarioLabel: SCENARIO_LABELS[scenario],
226
+ confidence: 'high',
227
+ summary: '先图谱/上下文理解,再决定改动范围',
228
+ firstTool: 'code_insight',
229
+ firstToolArgsHint: { mode: 'auto', query: intent },
230
+ phases: [
231
+ baseContextPhase(),
232
+ {
233
+ id: 'insight',
234
+ title: '代码洞察',
235
+ when: '不熟代码、评估影响、找入口',
236
+ steps: [
237
+ {
238
+ tool: 'code_insight',
239
+ required: true,
240
+ when: '探索架构/调用链/影响面',
241
+ note: '长耗时默认 Task;save_to_docs=true 可落盘',
242
+ },
243
+ ],
244
+ },
245
+ {
246
+ id: 'next',
247
+ title: '再进入具体任务',
248
+ when: '理解清楚后',
249
+ steps: [
250
+ { tool: 'start_feature', required: false, when: '确认要开发新功能' },
251
+ { tool: 'start_bugfix', required: false, when: '确认是 Bug 修复' },
252
+ ],
253
+ },
254
+ ],
255
+ avoid: [...commonAvoid, '不要没读图谱就大范围改文件'],
256
+ memoryNotes: commonMemory,
257
+ };
258
+ case 'commit':
259
+ return {
260
+ scenario,
261
+ scenarioLabel: SCENARIO_LABELS[scenario],
262
+ confidence: 'high',
263
+ summary: '用 gencommit 生成规范提交信息',
264
+ firstTool: 'gencommit',
265
+ phases: [
266
+ {
267
+ id: 'commit',
268
+ title: '提交信息',
269
+ when: '变更已完成、准备提交',
270
+ steps: [{ tool: 'gencommit', required: true, when: '需要 commit message' }],
271
+ },
272
+ ],
273
+ avoid: ['不要编造未发生的变更'],
274
+ memoryNotes: [],
275
+ };
276
+ case 'review':
277
+ return {
278
+ scenario,
279
+ scenarioLabel: SCENARIO_LABELS[scenario],
280
+ confidence: 'high',
281
+ summary: 'code_review 出结构化审查报告',
282
+ firstTool: 'code_review',
283
+ phases: [
284
+ {
285
+ id: 'review',
286
+ title: '代码审查',
287
+ when: '需要评审质量/安全',
288
+ steps: [{ tool: 'code_review', required: true, when: '审查指定文件或 diff' }],
289
+ },
290
+ ],
291
+ avoid: ['不要审查时直接改代码而不说明'],
292
+ memoryNotes: [],
293
+ };
294
+ case 'refactor':
295
+ return {
296
+ scenario,
297
+ scenarioLabel: SCENARIO_LABELS[scenario],
298
+ confidence: 'high',
299
+ summary: 'refactor 出计划;大改前先 code_insight',
300
+ firstTool: 'refactor',
301
+ phases: [
302
+ {
303
+ id: 'insight',
304
+ title: '影响面(推荐)',
305
+ when: '重构范围不清晰',
306
+ steps: [{ tool: 'code_insight', required: false, when: 'mode=impact', note: '评估上下游' }],
307
+ },
308
+ {
309
+ id: 'refactor',
310
+ title: '重构计划',
311
+ when: '明确重构目标后',
312
+ steps: [{ tool: 'refactor', required: true, when: '需要分步重构方案' }],
313
+ },
314
+ ],
315
+ avoid: [...commonAvoid, '不要无测试覆盖的大重构'],
316
+ memoryNotes: commonMemory,
317
+ };
318
+ case 'onboard':
319
+ return {
320
+ scenario,
321
+ scenarioLabel: SCENARIO_LABELS[scenario],
322
+ confidence: 'high',
323
+ summary: 'start_onboard 生成上手路径',
324
+ firstTool: 'start_onboard',
325
+ phases: [
326
+ {
327
+ id: 'onboard',
328
+ title: '项目上手',
329
+ when: '新成员或新仓库',
330
+ steps: [
331
+ { tool: 'start_onboard', required: true, when: '需要快速理解项目' },
332
+ { tool: 'init_project_context', required: false, when: '缺少上下文文档' },
333
+ ],
334
+ },
335
+ ],
336
+ avoid: ['不要跳过文档直接改业务代码'],
337
+ memoryNotes: [],
338
+ };
339
+ case 'spec':
340
+ return {
341
+ scenario,
342
+ scenarioLabel: SCENARIO_LABELS[scenario],
343
+ confidence: 'high',
344
+ summary: '规格闸门:check_spec 通过前不写实现',
345
+ firstTool: 'check_spec',
346
+ phases: [
347
+ {
348
+ id: 'spec',
349
+ title: '规格校验',
350
+ when: '已有 docs/specs/<feature>/',
351
+ steps: [
352
+ { tool: 'check_spec', required: true, when: '实现前或修复后', note: '未通过则补全再重跑' },
353
+ { tool: 'add_feature', required: false, when: '规格尚不存在', note: '通常由 start_feature 触发' },
354
+ ],
355
+ },
356
+ ],
357
+ avoid: ['不要 check_spec 未通过就写实现代码'],
358
+ memoryNotes: [],
359
+ };
360
+ case 'memory':
361
+ return {
362
+ scenario,
363
+ scenarioLabel: SCENARIO_LABELS[scenario],
364
+ confidence: 'high',
365
+ summary: '主动检索或沉淀共享记忆',
366
+ firstTool: 'search_memory',
367
+ firstToolArgsHint: { query: intent },
368
+ phases: [memoryPhase()],
369
+ avoid: ['删除记忆前不 confirm'],
370
+ memoryNotes: [
371
+ 'delete_memory_asset 默认预览,confirm=true 才删除',
372
+ 'update_memory_asset 保留原 asset_id',
373
+ ],
374
+ };
375
+ case 'unknown':
376
+ return {
377
+ scenario,
378
+ scenarioLabel: SCENARIO_LABELS[scenario],
379
+ confidence: 'low',
380
+ summary: '意图不明确:先用 ask_user 澄清,或按最可能场景重试 workflow',
381
+ firstTool: 'ask_user',
382
+ phases: [
383
+ {
384
+ id: 'clarify',
385
+ title: '澄清意图',
386
+ when: '无法判断 feature / bugfix / ui / explore',
387
+ steps: [
388
+ {
389
+ tool: 'ask_user',
390
+ required: true,
391
+ when: '缺少目标描述',
392
+ note: '问清:新功能、修 Bug、UI、还是只读探索',
393
+ },
394
+ {
395
+ tool: 'workflow',
396
+ required: false,
397
+ when: '澄清后带 scenario 重跑',
398
+ },
399
+ ],
400
+ },
401
+ ],
402
+ avoid: ['不要猜测意图后直接写大量代码'],
403
+ memoryNotes: commonMemory,
404
+ };
405
+ case 'feature':
406
+ default:
407
+ return {
408
+ scenario: 'feature',
409
+ scenarioLabel: SCENARIO_LABELS.feature,
410
+ confidence: 'high',
411
+ summary: '规格驱动开发:start_feature → add_feature → check_spec → 再实现',
412
+ firstTool: 'start_feature',
413
+ firstToolArgsHint: { description: intent },
414
+ phases: [
415
+ baseContextPhase(),
416
+ {
417
+ id: 'orchestrate',
418
+ title: '功能开发编排(必须先调)',
419
+ when: '任何新功能 / 需求实现',
420
+ steps: [
421
+ {
422
+ tool: 'start_feature',
423
+ required: true,
424
+ when: '新功能、增强、模块开发',
425
+ note: '返回 plan:add_feature → check_spec → estimate',
426
+ },
427
+ {
428
+ tool: 'code_insight',
429
+ required: false,
430
+ when: '涉及多模块 / 不熟代码',
431
+ },
432
+ ],
433
+ },
434
+ {
435
+ id: 'gate',
436
+ title: '规格闸门',
437
+ when: 'add_feature 完成后、写实现前',
438
+ steps: [
439
+ {
440
+ tool: 'check_spec',
441
+ required: true,
442
+ when: 'check_spec 未通过不得写实现',
443
+ },
444
+ ],
445
+ },
446
+ memoryPhase(),
447
+ ],
448
+ avoid: [...commonAvoid, '不要 check_spec 未通过就写实现', '不要跳过 estimate/tasks.md'],
449
+ memoryNotes: [...commonMemory, '可复用实现 → memorize_asset type=pattern'],
450
+ };
451
+ }
452
+ }
453
+ export function buildDevWorkflow(intent, options) {
454
+ const detection = detectWorkflowScenario(intent, options?.scenario);
455
+ const plan = buildPlanForScenario(detection.scenario, intent);
456
+ plan.confidence = detection.confidence;
457
+ return plan;
458
+ }
459
+ export function renderWorkflowMarkdown(plan, intent) {
460
+ const phaseBlocks = plan.phases
461
+ .map((phase, index) => {
462
+ const steps = phase.steps
463
+ .map((step) => {
464
+ const req = step.required ? '**必须**' : '可选';
465
+ return ` - ${req} \`${step.tool}\` — ${step.when}${step.note ? `(${step.note})` : ''}`;
466
+ })
467
+ .join('\n');
468
+ return `### ${index + 1}. ${phase.title}\n**时机**: ${phase.when}\n${steps}`;
469
+ })
470
+ .join('\n\n');
471
+ const avoid = plan.avoid.map((item) => `- ${item}`).join('\n');
472
+ const memory = plan.memoryNotes.length > 0
473
+ ? `\n## 记忆\n${plan.memoryNotes.map((item) => `- ${item}`).join('\n')}`
474
+ : '';
475
+ return `# 开发工作流 · ${plan.scenarioLabel}
476
+
477
+ **识别场景**: ${plan.scenario}(置信度: ${plan.confidence})
478
+ **摘要**: ${plan.summary}
479
+ **第一步应调**: \`${plan.firstTool}\`${plan.firstToolArgsHint ? `\n**参数提示**: \`${JSON.stringify(plan.firstToolArgsHint)}\`` : ''}
480
+
481
+ **用户意图**: ${intent || '(未提供)'}
482
+
483
+ ---
484
+
485
+ ## 阶段与 MCP 工具
486
+
487
+ ${phaseBlocks}
488
+
489
+ ## 禁止事项
490
+
491
+ ${avoid}
492
+ ${memory}
493
+
494
+ ---
495
+
496
+ *本指南由 \`workflow\` 工具生成。请按 \`${plan.firstTool}\` 返回的 delegated plan 逐步执行,不要跳过 MCP 编排直接写代码。*`;
497
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 统一 Handle 约定:供 Agent 从 structuredContent 直接取 ID/URI,无需从长文本解析。
3
+ */
4
+ export type MemoryAssetHandleTool = 'read_memory_asset' | 'update_memory_asset' | 'delete_memory_asset';
5
+ export interface MemoryAssetHandle {
6
+ id: string;
7
+ tool: MemoryAssetHandleTool;
8
+ name?: string;
9
+ type?: string;
10
+ summary?: string;
11
+ }
12
+ export interface ToolHandles {
13
+ memory_assets?: MemoryAssetHandle[];
14
+ graph_snapshot?: string | null;
15
+ graph_resource?: string | null;
16
+ }
17
+ export interface MemoryHandleInput {
18
+ id: string;
19
+ name?: string;
20
+ type?: string;
21
+ summary?: string;
22
+ }
23
+ export declare function buildMemoryAssetHandles(items: MemoryHandleInput[], tool?: MemoryAssetHandleTool): MemoryAssetHandle[];
24
+ export declare function mergeHandles(base?: ToolHandles, patch?: Partial<ToolHandles>): ToolHandles;
25
+ export declare function attachHandles<T extends Record<string, unknown>>(structured: T, handles: ToolHandles): T & {
26
+ handles: ToolHandles;
27
+ };
28
+ export declare function attachHandles<T extends object>(structured: T, handles: ToolHandles): T & {
29
+ handles: ToolHandles;
30
+ };
31
+ export declare const DEFAULT_GRAPH_RESOURCE_URI = "probe://graph/latest";
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 统一 Handle 约定:供 Agent 从 structuredContent 直接取 ID/URI,无需从长文本解析。
3
+ */
4
+ export function buildMemoryAssetHandles(items, tool = 'read_memory_asset') {
5
+ return items
6
+ .filter((item) => typeof item.id === 'string' && item.id.trim().length > 0)
7
+ .map((item) => ({
8
+ id: item.id.trim(),
9
+ tool,
10
+ ...(item.name ? { name: item.name } : {}),
11
+ ...(item.type ? { type: item.type } : {}),
12
+ ...(item.summary ? { summary: item.summary } : {}),
13
+ }));
14
+ }
15
+ export function mergeHandles(base = {}, patch = {}) {
16
+ return {
17
+ ...base,
18
+ ...patch,
19
+ memory_assets: patch.memory_assets ?? base.memory_assets,
20
+ graph_snapshot: patch.graph_snapshot !== undefined ? patch.graph_snapshot : base.graph_snapshot,
21
+ graph_resource: patch.graph_resource !== undefined ? patch.graph_resource : base.graph_resource,
22
+ };
23
+ }
24
+ export function attachHandles(structured, handles) {
25
+ const record = structured && typeof structured === 'object' && !Array.isArray(structured)
26
+ ? structured
27
+ : {};
28
+ const existing = record.handles && typeof record.handles === 'object' && !Array.isArray(record.handles)
29
+ ? record.handles
30
+ : {};
31
+ return {
32
+ ...record,
33
+ handles: mergeHandles(existing, handles),
34
+ };
35
+ }
36
+ export const DEFAULT_GRAPH_RESOURCE_URI = 'probe://graph/latest';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * MCP Apps 预览 HTML 生成(text/html resource)
3
+ */
4
+ export interface McpAppToolResult {
5
+ content?: unknown;
6
+ structuredContent?: unknown;
7
+ }
8
+ export declare const MCP_UI_APP_TOOLS: Set<string>;
9
+ export declare function isMcpUiAppTool(name: string): boolean;
10
+ export declare function escapeHtml(value: string): string;
11
+ export declare function buildGenericMcpAppHtml(toolName: string, args: unknown, result: McpAppToolResult): string;
12
+ export declare function buildSearchMemoryAppHtml(args: unknown, result: McpAppToolResult): string;
13
+ export declare function buildCodeInsightAppHtml(args: unknown, result: McpAppToolResult): string;
14
+ export declare function buildMcpAppHtml(toolName: string, args: unknown, result: McpAppToolResult): string;