autosnippet 3.1.6 → 3.1.8

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.
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>AutoSnippet Dashboard</title>
8
- <script type="module" crossorigin src="/assets/index-D9fV5GGQ.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-Ciz4nd_4.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/yaml-qRaU8Ldn.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/vendor-CEnWn7aV.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/axios-C0Zqfgkc.js">
@@ -55,7 +55,7 @@ export const DIMENSION_SOP = {
55
55
  ],
56
56
  },
57
57
  ],
58
- timeEstimate: '10-15 min',
58
+ timeEstimate: '1-5 min',
59
59
  commonMistakes: [
60
60
  '不要只扫描 1 个文件就提交 — 至少读 5+ 个文件验证模式一致性',
61
61
  '不要把"类名前缀"和"方法签名风格"合并成一个候选 — 每种规范应独立成条',
@@ -94,7 +94,7 @@ export const DIMENSION_SOP = {
94
94
  ],
95
95
  },
96
96
  ],
97
- timeEstimate: '10-15 min',
97
+ timeEstimate: '1-5 min',
98
98
  commonMistakes: [
99
99
  '不要只列出模式名称而不分析实现 — 必须展示项目的具体实现代码',
100
100
  '不要把 Singleton 和 Factory 合并成一个候选 — 每种模式独立提交',
@@ -132,7 +132,7 @@ export const DIMENSION_SOP = {
132
132
  ],
133
133
  },
134
134
  ],
135
- timeEstimate: '10-15 min',
135
+ timeEstimate: '1-5 min',
136
136
  commonMistakes: [
137
137
  '不要只描述目录名 — 要分析每层的职责和通信方式',
138
138
  '不要忽略依赖方向 — 是 Controller→Service 还是双向依赖?',
@@ -170,7 +170,7 @@ export const DIMENSION_SOP = {
170
170
  ],
171
171
  },
172
172
  ],
173
- timeEstimate: '10-15 min',
173
+ timeEstimate: '1-5 min',
174
174
  commonMistakes: [
175
175
  '不要笼统写"项目有错误处理" — 必须说明具体的处理策略(Result/throw/错误码)',
176
176
  '不要忽略反模式 — dontClause 要具体说明禁止的做法',
@@ -208,7 +208,7 @@ export const DIMENSION_SOP = {
208
208
  ],
209
209
  },
210
210
  ],
211
- timeEstimate: '10-15 min',
211
+ timeEstimate: '1-5 min',
212
212
  commonMistakes: [
213
213
  '不要只列出"项目使用 Notification" — 要说明具体的通知名、发送者、接收者',
214
214
  '不要混淆事件传播和数据流 — Delegate 是事件机制,CoreData 是数据流',
@@ -247,7 +247,7 @@ export const DIMENSION_SOP = {
247
247
  ],
248
248
  },
249
249
  ],
250
- timeEstimate: '10-15 min',
250
+ timeEstimate: '1-5 min',
251
251
  commonMistakes: [
252
252
  '不要直接复制依赖列表 — 要说明每个关键依赖的用途和版本',
253
253
  '不要只写"项目使用 MVC" — 要说明具体的分层职责和文件组织方式',
@@ -285,7 +285,7 @@ export const DIMENSION_SOP = {
285
285
  ],
286
286
  },
287
287
  ],
288
- timeEstimate: '8-12 min',
288
+ timeEstimate: '1-5 min',
289
289
  commonMistakes: [
290
290
  '【重要】不要在标题或内容中使用 "Agent" 字样 — 这是项目编码规范,不是 Agent 说明书',
291
291
  '不要只写通用编程建议 — 必须是此项目特有的约束',
@@ -330,7 +330,7 @@ export const DIMENSION_SOP = {
330
330
  ],
331
331
  },
332
332
  ],
333
- timeEstimate: '10-15 min',
333
+ timeEstimate: '1-5 min',
334
334
  commonMistakes: [
335
335
  '不要只列出宏名 — 必须包含宏定义的完整值和使用场景',
336
336
  'Hook 必须说明 hook 的目的和潜在风险',
@@ -369,7 +369,7 @@ export const DIMENSION_SOP = {
369
369
  ],
370
370
  },
371
371
  ],
372
- timeEstimate: '10-15 min',
372
+ timeEstimate: '1-5 min',
373
373
  commonMistakes: [
374
374
  '不要遗漏任何 Category 方法 — 要做到全量扫描',
375
375
  '不要只列出方法名不含实现 — Agent 需要实现代码才能正确使用',
@@ -407,7 +407,7 @@ export const DIMENSION_SOP = {
407
407
  ],
408
408
  },
409
409
  ],
410
- timeEstimate: '10-15 min',
410
+ timeEstimate: '1-5 min',
411
411
  commonMistakes: [
412
412
  '不要只说"项目使用 named export" — 要展示具体的 export 模式和约定',
413
413
  '不要忽略 re-export 链路 — barrel export 结构对项目维护很重要',
@@ -446,7 +446,7 @@ export const DIMENSION_SOP = {
446
446
  ],
447
447
  },
448
448
  ],
449
- timeEstimate: '12-18 min',
449
+ timeEstimate: '1-5 min',
450
450
  commonMistakes: [
451
451
  '不要假设框架版本 — 从 package.json 确认具体版本再分析',
452
452
  '不要只分析组件结构忽略状态管理 — 状态管理模式对项目开发至关重要',
@@ -485,7 +485,7 @@ export const DIMENSION_SOP = {
485
485
  ],
486
486
  },
487
487
  ],
488
- timeEstimate: '10-15 min',
488
+ timeEstimate: '1-5 min',
489
489
  commonMistakes: [
490
490
  '不要忽略 __all__ 定义 — 它决定了 from pkg import * 的行为',
491
491
  '不要假设所有包都有 type hints — 先统计覆盖率再分析',
@@ -524,7 +524,7 @@ export const DIMENSION_SOP = {
524
524
  ],
525
525
  },
526
526
  ],
527
- timeEstimate: '10-15 min',
527
+ timeEstimate: '1-5 min',
528
528
  commonMistakes: [
529
529
  '不要只扫描 Spring 注解 — 项目可能使用 Guice/Dagger/Hilt',
530
530
  '不要忽略自定义注解 — 它们编码了项目特有的规则',
@@ -563,7 +563,7 @@ export const DIMENSION_SOP = {
563
563
  ],
564
564
  },
565
565
  ],
566
- timeEstimate: '10-15 min',
566
+ timeEstimate: '1-5 min',
567
567
  commonMistakes: [
568
568
  '不要忽略 internal/ 包的隔离边界 — 这是 Go 的强制约束',
569
569
  '不要只列出依赖不说明用途',
@@ -230,8 +230,8 @@ export function buildInternalNextSteps(dimensions) {
230
230
  '',
231
231
  '== 完成后可执行的后续操作 ==',
232
232
  '1. 调用 autosnippet_enrich_candidates(candidateIds) 补全候选缺失字段',
233
- '2. 调用 autosnippet_bootstrap({ operation: "refine" }) 对候选进行 AI 精炼',
234
- '3. 使用 autosnippet_submit_knowledge_batch 手动提交更多知识条目',
233
+ '2. 使用 autosnippet_submit_knowledge_batch 手动提交更多知识条目',
234
+ '3. 使用 autosnippet_submit_knowledge 逐条提交高质量知识',
235
235
  '4. 使用 autosnippet_skill({ operation: "load", name }) 加载自动生成的 Project Skills',
236
236
  '',
237
237
  '== 宏观维度 → Project Skills ==',
@@ -106,6 +106,22 @@ export async function health(ctx) {
106
106
  const allCritical = checks.database; // DB 是唯一硬性依赖
107
107
  const status = allCritical ? 'ok' : 'degraded';
108
108
 
109
+ // 如果 DB 不可用但冷启动仍可执行,附加提示避免 Agent 浪费时间修复 DB
110
+ const actionHints = [];
111
+ if (!checks.database) {
112
+ actionHints.push(
113
+ 'DB 不可用不影响冷启动:autosnippet_bootstrap 不依赖数据库(纯文件系统分析),可直接调用。DB 会在首次 submit_knowledge 时自动重试初始化。'
114
+ );
115
+ }
116
+ if (!knowledgeBase || knowledgeBase.recipes.total === 0) {
117
+ actionHints.push(
118
+ '知识库为空,建议执行冷启动:(1) 调用 autosnippet_bootstrap 获取 Mission Briefing → (2) 按维度分析代码并提交知识 → (3) 调用 autosnippet_dimension_complete 完成每个维度。'
119
+ );
120
+ actionHints.push(
121
+ '💡 冷启动前建议先加载 Skill 获取详细指引:autosnippet_skill({ operation: "load", name: "autosnippet-coldstart" })'
122
+ );
123
+ }
124
+
109
125
  return envelope({
110
126
  success: true,
111
127
  data: {
@@ -118,6 +134,7 @@ export async function health(ctx) {
118
134
  services: ctx.container.getServiceNames(),
119
135
  knowledgeBase,
120
136
  ...(issues.length ? { issues } : {}),
137
+ ...(actionHints.length ? { actionHints } : {}),
121
138
  },
122
139
  meta: { tool: 'autosnippet_health' },
123
140
  });
@@ -224,8 +241,10 @@ export function capabilities() {
224
241
  {
225
242
  name: '冷启动(外部 Agent)',
226
243
  steps: [
227
- 'bootstrap(获取 Mission Briefing)',
228
- 'Agent 分析代码 + submit_knowledge × N',
244
+ '⚠️ 先加载 Skill 获取详细指引: autosnippet_skill({ operation: "load", name: "autosnippet-coldstart" })',
245
+ 'bootstrap(获取 Mission Briefing,无参数直接调用)',
246
+ '按 Briefing 中的 submissionSchema.example 格式提交知识(注意: content 和 reasoning 都是 JSON 对象)',
247
+ 'Agent 分析代码 + submit_knowledge / submit_knowledge_batch × N',
229
248
  'dimension_complete × N',
230
249
  'wiki_plan → Agent 写文章 → wiki_finalize(可选)',
231
250
  ],
@@ -230,7 +230,9 @@ export const TOOLS = [
230
230
  description:
231
231
  '提交单条知识到知识库(V3 统一实体)。严格前置校验,缺少必要字段将被直接拒绝(不入库)。\n' +
232
232
  '所有必填字段必须在单次调用中一次性提供,不要分步提交。\n' +
233
- '必填: title, language, content(pattern或markdown + rationale), kind, doClause, dontClause, whenClause, coreCode, category, trigger, description, headers, usageGuide, knowledgeType, reasoning',
233
+ '⚠️ content 必须是对象: { "pattern": "代码片段", "markdown": "## 标题\\n正文...", "rationale": "设计原理" }(pattern/markdown 至少一个 + rationale 必填)\n' +
234
+ '⚠️ reasoning 必须是对象: { "whyStandard": "原因", "sources": ["file.ts"], "confidence": 0.85 }\n' +
235
+ '必填: title, language, content, kind, doClause, dontClause, whenClause, coreCode, category, trigger, description, headers, usageGuide, knowledgeType, reasoning',
234
236
  inputSchema: {
235
237
  type: 'object',
236
238
  properties: {
@@ -239,15 +241,18 @@ export const TOOLS = [
239
241
  language: { type: 'string', description: '编程语言(小写)' },
240
242
  content: {
241
243
  type: 'object',
242
- description: '内容值对象(必须有 pattern 或 markdown + rationale)',
244
+ description:
245
+ '内容值对象(JSON 对象,不是字符串!)。必须包含: pattern(代码片段) 或 markdown(Markdown正文) 至少一个 + rationale(设计原理) 必填。' +
246
+ '示例: { "pattern": "func example() { ... }", "markdown": "## 标题\\n正文≥200字...", "rationale": "为什么这样设计" }',
243
247
  properties: {
244
- pattern: { type: 'string' },
245
- markdown: { type: 'string' },
248
+ pattern: { type: 'string', description: '核心代码片段(与 markdown 至少提供一个)' },
249
+ markdown: { type: 'string', description: 'Markdown 正文(≥200字符,与 pattern 至少提供一个)' },
246
250
  rationale: { type: 'string', description: '设计原理说明(必填)' },
247
251
  steps: { type: 'array', items: { type: 'object' } },
248
252
  codeChanges: { type: 'array', items: { type: 'object' } },
249
253
  verification: { type: 'object' },
250
254
  },
255
+ required: ['rationale'],
251
256
  },
252
257
  kind: {
253
258
  type: 'string',
@@ -289,14 +294,16 @@ export const TOOLS = [
289
294
  relations: { type: 'object', description: '关系' },
290
295
  reasoning: {
291
296
  type: 'object',
292
- description: '推理依据(必填){whyStandard, sources[], confidence}',
297
+ description:
298
+ '推理依据(JSON 对象,必填)。示例: { "whyStandard": "28/30 files follow this pattern", "sources": ["src/UserService.ts"], "confidence": 0.85 }',
293
299
  properties: {
294
- whyStandard: { type: 'string' },
295
- sources: { type: 'array', items: { type: 'string' } },
296
- confidence: { type: 'number' },
300
+ whyStandard: { type: 'string', description: '为什么这是标准做法(必填)' },
301
+ sources: { type: 'array', items: { type: 'string' }, description: '参考的文件路径数组(必填,至少 1 个)' },
302
+ confidence: { type: 'number', description: '置信度 0.0-1.0(推荐 0.7-0.9)' },
297
303
  qualitySignals: { type: 'object' },
298
304
  alternatives: { type: 'array', items: { type: 'string' } },
299
305
  },
306
+ required: ['whyStandard', 'sources', 'confidence'],
300
307
  },
301
308
  headerPaths: { type: 'array', items: { type: 'string' } },
302
309
  moduleName: { type: 'string' },
@@ -330,7 +337,11 @@ export const TOOLS = [
330
337
  {
331
338
  name: 'autosnippet_submit_knowledge_batch',
332
339
  tier: 'agent',
333
- description: '批量提交知识条目(V3 统一实体)。每条须含 kind/doClause/dontClause/whenClause/coreCode。支持去重。',
340
+ description:
341
+ '批量提交知识条目(V3 统一实体)。每条字段要求同 submit_knowledge。支持去重。\n' +
342
+ '⚠️ items 数组中每条的 content 和 reasoning 都必须是 JSON 对象(不是字符串)。\n' +
343
+ 'content 格式: { "pattern": "代码...", "markdown": "正文...", "rationale": "原理..." }\n' +
344
+ 'reasoning 格式: { "whyStandard": "原因", "sources": ["file.ts"], "confidence": 0.85 }',
334
345
  inputSchema: {
335
346
  type: 'object',
336
347
  properties: {
@@ -408,7 +419,9 @@ export const TOOLS = [
408
419
  name: 'autosnippet_bootstrap',
409
420
  tier: 'agent',
410
421
  description:
411
- '冷启动 Mission Briefing — 自动分析项目结构、AST、依赖图和 Guard 审计,返回完整的执行计划和维度任务清单。无需任何参数,直接调用即可。',
422
+ '冷启动 Mission Briefing — 自动分析项目结构、AST、依赖图和 Guard 审计,返回完整的执行计划和维度任务清单。无需任何参数,直接调用即可。不依赖数据库,DB 不可用时也能正常工作。\n' +
423
+ '💡 建议先加载 Skill 获取详细冷启动指引: autosnippet_skill({ operation: "load", name: "autosnippet-coldstart" })\n' +
424
+ '返回的 submissionSchema.example 包含完整的提交 JSON 示例,请严格按其格式提交知识。',
412
425
  inputSchema: {
413
426
  type: 'object',
414
427
  properties: {},
@@ -46,15 +46,21 @@ export function checkRecipeReadiness(item) {
46
46
  }
47
47
 
48
48
  // content 有效性(pattern/markdown/rationale 至少有实质内容)
49
- const hasCode = !!(item.code || item.content?.pattern || item.content?.markdown);
50
- if (!hasCode) {
49
+ // 先检查 content 是否为对象(Agent 常犯错误:传字符串而非对象)
50
+ if (item.content && typeof item.content !== 'object') {
51
51
  missing.push('content');
52
- suggestions.push('content 需包含 pattern markdown(代码片段或正文)');
52
+ suggestions.push('⚠️ content 必须是 JSON 对象(不是字符串!)。正确格式: { "pattern": "代码片段", "markdown": "## 标题\\n正文...", "rationale": "设计原理" }');
53
+ } else {
54
+ const hasCode = !!(item.code || item.content?.pattern || item.content?.markdown);
55
+ if (!hasCode) {
56
+ missing.push('content');
57
+ suggestions.push('content 必须是 JSON 对象且包含 pattern 或 markdown 至少一个。格式: { "pattern": "代码片段...", "rationale": "设计原理..." }');
58
+ }
53
59
  }
54
60
 
55
61
  if (!item.content?.rationale && !item.rationale) {
56
62
  missing.push('rationale');
57
- suggestions.push('content.rationale 必须提供设计原理说明');
63
+ suggestions.push('content.rationale 必须提供设计原理说明(在 content 对象中: { ..., "rationale": "为什么这样设计" })');
58
64
  }
59
65
 
60
66
  if (!item.language) {
@@ -130,13 +136,15 @@ export function checkRecipeReadiness(item) {
130
136
  // reasoning 检查
131
137
  if (!item.reasoning || typeof item.reasoning !== 'object') {
132
138
  missing.push('reasoning');
133
- suggestions.push('reasoning 必须包含 whyStandard + sources + confidence');
139
+ suggestions.push('⚠️ reasoning 必须是 JSON 对象(不是字符串!)。正确格式: { "whyStandard": "为什么是标准做法", "sources": ["file1.ts", "file2.ts"], "confidence": 0.85 }');
134
140
  } else {
135
141
  if (!item.reasoning.whyStandard?.trim()) {
136
142
  missing.push('reasoning.whyStandard');
143
+ suggestions.push('reasoning.whyStandard 必须说明为什么这是标准做法');
137
144
  }
138
145
  if (!Array.isArray(item.reasoning.sources) || item.reasoning.sources.length === 0) {
139
146
  missing.push('reasoning.sources');
147
+ suggestions.push('reasoning.sources 必须是文件路径数组且至少包含 1 个来源');
140
148
  }
141
149
  }
142
150
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosnippet",
3
- "version": "3.1.6",
3
+ "version": "3.1.8",
4
4
  "description": "Extract code patterns into a knowledge base for AI coding assistants",
5
5
  "type": "module",
6
6
  "main": "lib/bootstrap.js",
@@ -26,7 +26,7 @@ description: Deep project analysis — full scan + semantic field enrichment + g
26
26
  ### Workflow
27
27
 
28
28
  #### Phase 1: Collect & Baseline
29
- 1. 调用 `autosnippet_bootstrap(operation=scan)` 获取文件列表 + Guard 审计基线
29
+ 1. 调用 `autosnippet_bootstrap`(无参数)获取 Mission Briefing(文件列表 + Guard 审计基线)
30
30
  2. 审视 Guard 违规 — 静态规则问题 (命名/API 使用/废弃 API)
31
31
  3. 确定高优先级文件 (核心模块/共享工具/Service 层)
32
32
 
@@ -116,11 +116,11 @@ Use `autosnippet_submit_knowledge_batch` for batch submission.
116
116
  **方式 B: 对已有候选调用 AI 补全**
117
117
  > 注:`autosnippet_enrich_candidates` 已移入 admin 层级,Agent 推荐使用方式 A 直接填写完整字段。
118
118
 
119
- **方式 C: Bootstrap 候选 AI 润色**
119
+ **方式 C: 候选字段诊断**
120
120
  ```
121
- autosnippet_bootstrap(operation=refine, candidateIds: ["id1", "id2", ...])
121
+ autosnippet_enrich_candidates({ candidateIds: ["id1", "id2", ...] })
122
122
  ```
123
- 使用 AI 对 Bootstrap 候选做内容润色(改善 summary、补充 insight、推断 relations、调整 confidence)。
123
+ 诊断候选缺失字段(不使用 AI),Agent 根据诊断结果自行补全。
124
124
 
125
125
  ---
126
126
 
@@ -133,7 +133,7 @@ autosnippet_bootstrap(operation=refine, candidateIds: ["id1", "id2", ...])
133
133
  ### Workflow
134
134
 
135
135
  1. 对目标候选做结构补齐(确保所有字段完整)
136
- 2. 调用 `autosnippet_bootstrap(operation=refine)` 对候选做 AI 润色(summary/insight/relations)
136
+ 2. 调用 `autosnippet_enrich_candidates` 诊断候选缺失字段,根据结果自行补全
137
137
  3. 提交时使用 `autosnippet_submit_knowledge`(内置自动校验 + 去重检查)
138
138
  4. 报告补全情况 + 缺失字段 + 重复风险
139
139
  5. 如缺失字段 AI 无法填充,提示用户手动补充
@@ -1,12 +1,13 @@
1
1
  ---
2
2
  name: autosnippet-coldstart
3
- description: Cold-start knowledge base initialization. Full 9-dimension analysis workflow works with both external Agent and internal AI. Call bootstrap_knowledge, then systematically analyze code and submit candidates.
3
+ description: Cold-start knowledge base initialization (V3). Full 9-dimension analysis workflow for external Agent. Call autosnippet_bootstrap (no params) analyze code submit_knowledge → dimension_complete.
4
4
  ---
5
5
 
6
- # AutoSnippet — Cold Start (知识库冷启动)
6
+ # AutoSnippet — Cold Start (知识库冷启动) V3
7
7
 
8
8
  > 首次接入项目 / 知识库重建 / 大版本升级后使用。目标:从零建立完整知识库,覆盖 9 大知识维度。
9
9
  > Self-check & Fallback: MCP 工具返回 JSON Envelope({ success, errorCode?, data?, meta })。失败时不在同一轮重试,缩小范围再试。
10
+ > **DB 不可用不影响冷启动**: autosnippet_bootstrap 不依赖数据库(纯文件系统分析),可直接调用。
10
11
 
11
12
  ## Quick Decision
12
13
 
@@ -16,51 +17,62 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
16
17
  | 已有知识库,查/用 Recipe | → autosnippet-recipes |
17
18
  | 只扫描单个文件/模块 | → autosnippet-candidates |
18
19
  | 只做 Guard 审计 | → autosnippet-guard |
19
- | 快速看看项目结构 | → autosnippet-structure(用 `autosnippet_bootstrap(operation=scan)`) |
20
+ | 快速看看项目结构 | → autosnippet-structure(用 `autosnippet_structure(operation=targets)`) |
20
21
 
21
22
  ---
22
23
 
23
24
  ## Phase 0: 启动扫描
24
25
 
25
- 调用 `autosnippet_bootstrap(operation=knowledge)` 收集项目结构化数据:
26
+ 调用 `autosnippet_bootstrap`(**无参数**)获取 Mission Briefing:
26
27
 
27
- ```json
28
- { "aiMode": "external", "maxFiles": 500, "contentMaxLines": 150 }
29
28
  ```
29
+ autosnippet_bootstrap()
30
+ ```
31
+
32
+ > 💡 Bootstrap 不依赖数据库,DB 不可用时也能正常工作。
30
33
 
31
- 返回数据(你需要的上下文):
34
+ ### Mission Briefing 返回数据
32
35
 
33
36
  | 字段 | 内容 |
34
37
  |------|------|
35
- | `targets` | 所有模块 Target(含 `inferredRole`: core/service/ui/networking/…) |
36
- | `filesByTarget` | Target 分组的文件内容(含 `priority`: high/medium/low) |
38
+ | `projectMeta` | 项目元数据(name, primaryLanguage, fileCount, projectType) |
39
+ | `ast` | AST 分析摘要(classes, protocols, functions, imports) |
40
+ | `codeEntityGraph` | 代码实体图谱(类/协议/函数之间的关系) |
37
41
  | `dependencyGraph` | `{ nodes, edges }` 模块间依赖关系 |
38
- | `guardViolationFiles` | Guard 规则违规列表 |
39
- | `languageStats` | 文件扩展名统计 |
40
- | `primaryLanguage` | 推断的主语言(swift/objectivec/typescript/…) |
41
- | `languageExtension` | 语言特有扩展(**重要**,见下方) |
42
- | `analysisFramework` | 9 维度分析框架(维度清单 + 候选模板) |
42
+ | `guardFindings` | Guard 规则违规摘要 |
43
+ | `targets` | 所有模块 Target(含 `inferredRole`: core/service/ui/networking/…) |
44
+ | `dimensions` | 激活的分析维度任务列表(每个维度含 analysisGuide + evidenceStarters) |
45
+ | `submissionSchema` | **提交格式定义 + 语言自适应 JSON 示例**(⚠️ 必须严格按此格式提交) |
46
+ | `executionPlan` | Tier 执行计划(Tier 1 → Tier 2 → Tier 3) |
47
+ | `session` | Bootstrap 会话信息(session.id 供 dimension_complete 使用) |
43
48
 
44
- ### languageExtension语言特有分析指引
49
+ ### submissionSchema提交格式(关键!)
45
50
 
46
- `languageExtension` 包含当前项目主语言的特有信息:
51
+ Mission Briefing 的 `submissionSchema.example` 包含**完整的提交 JSON 示例**,按项目主语言自适应。
52
+ **你必须严格按照该示例的字段格式提交知识**,特别注意:
53
+ - `content` 是 JSON 对象:`{ "pattern": "...", "markdown": "...", "rationale": "..." }`
54
+ - `reasoning` 是 JSON 对象:`{ "whyStandard": "...", "sources": [...], "confidence": 0.85 }`
55
+ - `headers` 是数组:`["import Foundation"]`(无 import 时传 `[]`)
47
56
 
48
- | 字段 | 类型 | 说明 |
49
- |------|------|------|
50
- | `language` | string | 主语言名称 |
51
- | `extraDimensions` | array | 语言特有的额外分析维度(如 Swift Concurrency、ObjC Block 模式、Go goroutine/channel、Python async/decorator、Java Stream/Optional、Dart Widget/BLoC/Riverpod、Rust ownership/borrowing/lifetime/trait 等) |
52
- | `typicalPatterns` | array | 该语言中典型的代码模式提示 |
53
- | `commonAntiPatterns` | array | 该语言常见反模式(bad/why/fix) |
54
- | `suggestedGuardRules` | array | 建议的 Guard 规则(pattern/severity/message) |
55
- | `agentCautions` | array | 该语言下 Agent 开发必须遵守的注意事项 |
56
- | `customFields` | object | 预留扩展字段(供用户/插件自定义) |
57
+ ### dimensions 维度任务
57
58
 
58
- **你的分析应同时覆盖 `analysisFramework.dimensions`(9 通用维度)和 `languageExtension.extraDimensions`(语言特有维度)。**
59
+ 每个维度对象包含:
60
+ - `id` — 维度标识
61
+ - `label` — 维度名称
62
+ - `analysisGuide` — 分析步骤指引(SOP)
63
+ - `evidenceStarters` — 从 Phase 1-4 数据中提取的证据启发
64
+ - `submissionSpec` — 提交规范(含 preSubmitChecklist)
59
65
 
60
- > **aiMode 选择**:
61
- > - `external`(默认)= 你自己分析代码,功能最完整,质量最高
62
- > - `internal` = 内置 AI 分析,你不需要逐文件阅读,适合 context window 不够的情况
63
- > - `auto` = 先试 internal,失败自动降级 external
66
+ ### executionPlan — 分 Tier 执行
67
+
68
+ ```
69
+ Tier 1(项目特征/深度扫描/分类扫描)→ Tier 2(代码规范/架构/设计模式)→ Tier 3(事件流/最佳实践/开发指南)
70
+ ```
71
+
72
+ 每个维度的工作流:
73
+ 1. 用原生能力(read_file/grep_search)阅读代码分析
74
+ 2. 调用 `autosnippet_submit_knowledge_batch` 批量提交 3-5 条候选
75
+ 3. 调用 `autosnippet_dimension_complete` 完成维度(传 referencedFiles + keyFindings)
64
76
 
65
77
  ---
66
78
 
@@ -93,6 +105,9 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
93
105
  "category": "Service",
94
106
  "kind": "rule",
95
107
  "doClause": "Follow Presentation → Domain → Data layered architecture with no cross-layer access",
108
+ "dontClause": "Never import Data layer modules directly from Presentation layer",
109
+ "whenClause": "When creating new modules, reviewing code, or making architectural decisions",
110
+ "coreCode": "// Presentation → Domain → Data\n// ✅ Presentation imports Domain\nimport DomainModule\n// ✅ Domain imports Data\nimport DataModule\n// ❌ Presentation must NOT import Data directly",
96
111
  "knowledgeType": "architecture",
97
112
  "usageGuide": "### 何时使用\n- 新建模块时确定放置层级\n- 代码审查检查跨层调用\n\n### 规则\n- View 层只调 Domain\n- Domain 层只调 Data\n- 禁止反向依赖",
98
113
  "difficulty": "intermediate",
@@ -177,26 +192,32 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
177
192
  {
178
193
  "title": "项目技术特征 — [ProjectName]",
179
194
  "trigger": "@projectProfile",
180
- "code": "techStack:\n primaryLanguage: <language>\n frameworks: [<framework1>, <framework2>]\n minDeployment: <platform version>\n\nprojectStructure:\n pattern: <modular-spm|monorepo|workspace|...>\n keyModules:\n - ModuleA: 核心业务SDK\n - ModuleB: UI组件库\n\ndependencies:\n thirdParty:\n - LibA: 用途\n - LibB: 用途",
181
- "summary_cn": "项目技术栈全貌:语言、框架、模块结构、三方依赖",
182
- "summary_en": "Project tech profile: language, frameworks, module structure, dependencies",
195
+ "content": {
196
+ "markdown": "## 技术栈全貌\n\n| 维度 | 值 |\n|------|------|\n| 主语言 | <language> |\n| 框架 | <framework1>, <framework2> |\n| 最低部署版本 | <platform version> |\n\n### 项目结构\n- 类型: <modular-spm|monorepo|workspace|...>\n- 核心模块: ModuleA(核心业务SDK), ModuleB(UI组件库)\n\n### 三方依赖\n- LibA: 用途\n- LibB: 用途",
197
+ "pattern": "techStack:\n primaryLanguage: <language>\n frameworks: [<fw1>, <fw2>]\n projectStructure: <modular|monorepo|workspace>\n keyModules: [ModuleA, ModuleB]",
198
+ "rationale": "项目技术栈全貌,新人 onboarding 和 Agent 理解项目的基础上下文"
199
+ },
200
+ "description": "项目技术栈全貌:语言、框架、模块结构、三方依赖",
183
201
  "language": "<primaryLanguage>",
184
202
  "headers": [],
185
203
  "category": "Architecture",
204
+ "kind": "fact",
205
+ "doClause": "Understand the project tech stack before making architectural decisions",
206
+ "dontClause": "Do not introduce frameworks or patterns that conflict with the established tech stack",
207
+ "whenClause": "When onboarding to the project or making technology choices",
208
+ "coreCode": "// Project: [ProjectName]\n// Language: <language>\n// Frameworks: <fw1>, <fw2>\n// Structure: <modular|monorepo|workspace>\n// Key Modules: ModuleA, ModuleB",
186
209
  "knowledgeType": "architecture",
187
- "difficulty": "beginner",
188
- "scope": "project-specific",
189
- "rationale": "项目技术栈全貌,新人 onboarding 和 Agent 理解项目的基础",
210
+ "usageGuide": "### 何时查阅\n新人入职、技术选型、跨模块开发时参考\n### 注意事项\n版本升级时同步更新此条目",
190
211
  "reasoning": {
191
212
  "whyStandard": "项目技术选型摘要,所有开发决策的基础上下文",
192
- "sources": ["<project manifest: Package.swift / package.json / go.mod / pom.xml / etc.>", "languageStats", "dependencyGraph"],
213
+ "sources": ["<project manifest: Package.swift / package.json / go.mod / pom.xml / etc.>", "projectMeta", "dependencyGraph"],
193
214
  "confidence": 0.95
194
215
  }
195
216
  }
196
217
  ```
197
218
 
198
219
  **分析要点**:
199
- - 从 `languageStats` 推断主要语言
220
+ - 从 `projectMeta` 获取主语言和项目类型
200
221
  - 从 `targets` 推断项目结构(单体/模块化)
201
222
  - 从 `dependencyGraph` 推断三方/自有模块依赖
202
223
  - 从代码中的 import 语句推断框架使用
@@ -224,15 +245,22 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
224
245
  {
225
246
  "title": "[must] UI 更新必须在主线程",
226
247
  "trigger": "@agent-threading",
227
- "code": "// ✅ 正确 — 使用语言/框架提供的主线程机制\n// Swift: @MainActor func updateUI() { ... }\n// JS/TS: 无需显式处理(单线程)但 Web Worker 返回需 postMessage\n// Python: 使用 loop.call_soon_threadsafe() 或框架 API\n// Go: 使用 channel 或 sync 包\n// Java/Kotlin: runOnUiThread { ... } 或 Dispatchers.Main\n// Rust: 使用 tokio::spawn + channel 或 Arc<Mutex<T>> 跨线程共享\n// Dart: 使用 WidgetsBinding.instance.addPostFrameCallback 或 setState\n\n// ❌ 错误 — 在后台线程直接操作 UI",
228
- "summary_cn": "UI 更新必须在主线程/主 Actor 执行,违反会导致崩溃或数据竞争",
229
- "summary_en": "UI updates must run on the main thread/actor to prevent crashes and data races",
248
+ "content": {
249
+ "markdown": "## UI 线程安全\n\n所有 UI 更新操作必须在主线程/主 Actor 执行。\n\n### 各语言实现\n- **Swift**: `@MainActor func updateUI() { ... }`\n- **JS/TS**: 单线程无需处理,Web Worker 返回需 `postMessage`\n- **Python**: `loop.call_soon_threadsafe()` 或框架 API\n- **Go**: 使用 channel 或 sync 包\n- **Java/Kotlin**: `runOnUiThread { }` 或 `Dispatchers.Main`\n- **Rust**: `tokio::spawn` + channel 或 `Arc<Mutex<T>>`\n- **Dart**: `setState` 或 `WidgetsBinding.instance.addPostFrameCallback`\n\n### 反例\n在后台线程直接操作 UI 会导致崩溃或数据竞争。",
250
+ "pattern": "// 正确 使用语言/框架提供的主线程机制\n// Swift: @MainActor func updateUI() { ... }\n// Kotlin: runOnUiThread { updateView() }\n\n// ❌ 错误 — 在后台线程直接操作 UI",
251
+ "rationale": "UI 框架通常要求在主线程更新界面,违反会导致崩溃或数据竞争"
252
+ },
253
+ "description": "UI 更新必须在主线程/主 Actor 执行,违反会导致崩溃或数据竞争",
230
254
  "language": "<primaryLanguage>",
231
255
  "headers": [],
232
256
  "category": "Tool",
257
+ "kind": "rule",
258
+ "doClause": "Always dispatch UI updates to the main thread or main actor",
259
+ "dontClause": "Never update UI elements from background threads or non-main dispatchers",
260
+ "whenClause": "When writing code that updates UI after async operations or background tasks",
261
+ "coreCode": "// Swift: @MainActor func updateUI() { ... }\n// Kotlin: runOnUiThread { updateView() }\n// JS/TS: postMessage from Worker\n// Python: loop.call_soon_threadsafe(callback)",
233
262
  "knowledgeType": "boundary-constraint",
234
- "difficulty": "intermediate",
235
- "rationale": "UI 框架通常要求在主线程更新界面,违反会导致崩溃或数据竞争",
263
+ "usageGuide": "### 适用场景\n所有涉及 UI 更新的异步操作\n### 检查方式\n确认回调/闭包中的 UI 操作是否已切换到主线程",
236
264
  "reasoning": {
237
265
  "whyStandard": "项目 UI 层需在主线程操作,Agent 新写的代码也必须遵守",
238
266
  "sources": ["<relevant source files>"],
@@ -310,19 +338,6 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
310
338
 
311
339
  ---
312
340
 
313
- ## scan_project vs bootstrap_knowledge
314
-
315
- | | `bootstrap(op=scan)` | `bootstrap(op=knowledge)` |
316
- |---|---|---|
317
- | **用途** | 快速结构探查(不写库) | 完整知识库初始化(写 knowledge_edges) |
318
- | **SPM 图谱写入** | ❌ | ✅ |
319
- | **文件内容** | 可选 (includeContent) | external 模式自动包含 |
320
- | **Guard 审计** | ✅ | ✅ |
321
- | **后续动作** | 看看就好 | Agent 分析 → submit_candidates |
322
- | **适合场景** | 了解项目、检查 Guard | 首次接入、知识库重建 |
323
-
324
- ---
325
-
326
341
  ## Per-Dimension Industry Reference Templates
327
342
 
328
343
  > 以下是每个分析维度的**高质量候选模板**,基于业界最佳实践。分析时请以此为参考产出同等质量的候选。
@@ -952,7 +967,7 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
952
967
  |------|------|
953
968
  | 文件太多超出 context window | 减小 `maxFiles`,或先分析 high priority 文件 |
954
969
  | 分析维度太多一次做不完 | 分 Target 分批进行,每次分析 1-2 个 Target |
955
- | 分析质量不高 | 切换 `aiMode="internal"` 使用内置 AI |
970
+ | 分析质量不高 | 检查 submissionSchema 中的示例,确保字段格式严格匹配 |
956
971
  | Guard 违规太多 | 先处理 Guard 违规,再做知识分析 |
957
972
  | 提交后候选在哪里 | Dashboard → Candidates 页面审核 |
958
973
  | 不知道该语言的最佳实践 | 查阅 autosnippet-reference-{lang} Skill |
@@ -963,9 +978,9 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
963
978
 
964
979
  | Tool | 用途 |
965
980
  |------|------|
966
- | `autosnippet_bootstrap(operation=knowledge)` | 启动冷启动扫描(本 Skill 核心工具) |
967
- | `autosnippet_bootstrap(operation=refine)` | AI 精炼候选质量(summary/insight/relations) |
968
- | `autosnippet_bootstrap(operation=scan)` | 轻量探查(不写库) |
981
+ | `autosnippet_bootstrap` | 冷启动 Mission Briefing(无参数,返回项目分析 + 维度任务清单) |
982
+ | `autosnippet_dimension_complete` | 维度分析完成通知(提交 recipe 后调用) |
983
+ | `autosnippet_enrich_candidates` | 候选字段完整性诊断 |
969
984
  | `autosnippet_submit_knowledge_batch` | 批量提交候选 |
970
985
  | `autosnippet_submit_knowledge` | 提交单条候选(内置自动校验 + 去重检查) |
971
986
  | `autosnippet_search(mode=context)` | 查找已有知识(避免重复) |
@@ -87,8 +87,8 @@ This is a conceptual map. Skills stay semantic; MCP provides capability.
87
87
  | 候选提交 | `autosnippet_submit_knowledge`, `autosnippet_submit_knowledge_batch` |
88
88
  | Guard 检查 | `autosnippet_guard`(code 单条 / files[] 批量 — 自动路由) |
89
89
  | 使用确认 | `autosnippet_knowledge(operation=confirm_usage)` |
90
- | 项目扫描 | `autosnippet_bootstrap(operation=scan)` |
91
- | 冷启动 | `autosnippet_bootstrap(operation=knowledge/refine)` |
90
+ | 项目扫描 | `autosnippet_bootstrap`(无参数,返回 Mission Briefing) |
91
+ | 冷启动 | `autosnippet_bootstrap` + `autosnippet_dimension_complete` |
92
92
  | Skills 管理 | `autosnippet_skill(operation=list/load/create/update/delete/suggest)` |
93
93
  | 自检 | `autosnippet_health` |
94
94
 
@@ -81,7 +81,7 @@ Guard uses the **same Recipe content** in `AutoSnippet/recipes/` as the standard
81
81
  | Tool | Purpose | Input |
82
82
  |------|---------|-------|
83
83
  | `autosnippet_guard` | Code Guard check (single or batch — auto-routed by params) | `code` for single, `files[]` for batch, `language`, `filePath`, `scope` |
84
- | `autosnippet_bootstrap(operation=scan)` | Full project scan + Guard audit | `maxFiles`, `includeContent` |
84
+ | `autosnippet_bootstrap` | Full project scan + Guard audit (no params, returns Mission Briefing) | — |
85
85
  | `autosnippet_knowledge(operation=list, kind=rule)` | List all Guard rules (kind=rule) | `limit`, `status`, `language`, `category` |
86
86
 
87
87
  ---
@@ -100,7 +100,7 @@ Guard uses the **same Recipe content** in `AutoSnippet/recipes/` as the standard
100
100
  4. Suggest fixes based on Recipe standards
101
101
 
102
102
  ### Project-wide Compliance
103
- 1. Call `autosnippet_bootstrap(operation=scan)` for full project scan
103
+ 1. Call `autosnippet_bootstrap` (no params) for full project scan
104
104
  2. Present high-severity findings first
105
105
 
106
106
  ---
@@ -117,6 +117,6 @@ Guard uses the **same Recipe content** in `AutoSnippet/recipes/` as the standard
117
117
 
118
118
  - **autosnippet-recipes**: Recipe content IS the Guard standard. Use for looking up what the standard says.
119
119
  - **autosnippet-intent**: General router; may route Guard-related intents here.
120
- - **autosnippet-analysis**: Deep project scan + Guard baseline via `autosnippet_bootstrap(operation=scan)`.
120
+ - **autosnippet-analysis**: Deep project scan + Guard baseline via `autosnippet_bootstrap`.
121
121
 
122
122
  ```
@@ -44,7 +44,7 @@ Use this skill when the user's intent is unclear or overlaps multiple capabiliti
44
44
  - Submit: `autosnippet_submit_knowledge`, `autosnippet_submit_knowledge_batch`
45
45
  - Document: `autosnippet_save_document`
46
46
  - Guard: `autosnippet_guard` (code 单文件 / files[] 批量)
47
- - Bootstrap: `autosnippet_bootstrap` (operation: knowledge / refine / scan)
47
+ - Bootstrap: `autosnippet_bootstrap` (no params Mission Briefing) + `autosnippet_dimension_complete`
48
48
  - Skills: `autosnippet_skill` (operation: list / load / create / update / delete / suggest)
49
49
 
50
50
  This skill is a router only; it does not perform actions itself.