@haaaiawd/anws 1.2.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +208 -172
  2. package/bin/cli.js +22 -9
  3. package/lib/adapters/index.js +157 -0
  4. package/lib/agents.js +136 -1
  5. package/lib/changelog.js +187 -0
  6. package/lib/copy.js +72 -1
  7. package/lib/diff.js +270 -0
  8. package/lib/init.js +143 -125
  9. package/lib/install-state.js +195 -0
  10. package/lib/manifest.js +184 -42
  11. package/lib/output.js +185 -13
  12. package/lib/prompt.js +284 -0
  13. package/lib/resources/index.js +27 -0
  14. package/lib/update.js +291 -83
  15. package/package.json +10 -6
  16. package/templates/.agents/skills/concept-modeler/SKILL.md +176 -0
  17. package/templates/{.agent → .agents}/skills/design-reviewer/SKILL.md +6 -6
  18. package/templates/.agents/skills/nexus-mapper/SKILL.md +306 -0
  19. package/templates/.agents/skills/nexus-mapper/references/language-customization.md +164 -0
  20. package/templates/.agents/skills/nexus-mapper/references/output-schema.md +298 -0
  21. package/templates/.agents/skills/nexus-mapper/references/probe-protocol.md +246 -0
  22. package/templates/.agents/skills/nexus-mapper/scripts/extract_ast.py +706 -0
  23. package/templates/.agents/skills/nexus-mapper/scripts/git_detective.py +194 -0
  24. package/templates/.agents/skills/nexus-mapper/scripts/languages.json +127 -0
  25. package/templates/.agents/skills/nexus-mapper/scripts/query_graph.py +556 -0
  26. package/templates/.agents/skills/nexus-mapper/scripts/requirements.txt +6 -0
  27. package/templates/{.agent → .agents}/skills/report-template/SKILL.md +11 -14
  28. package/templates/.agents/skills/report-template/references/REPORT_TEMPLATE.md +100 -0
  29. package/templates/{.agent → .agents}/skills/runtime-inspector/SKILL.md +1 -1
  30. package/templates/.agents/skills/sequential-thinking/SKILL.md +166 -0
  31. package/templates/.agents/skills/spec-writer/SKILL.md +108 -0
  32. package/templates/{.agent → .agents}/skills/spec-writer/references/prd_template.md +1 -1
  33. package/templates/{.agent → .agents}/skills/system-architect/SKILL.md +3 -3
  34. package/templates/.agents/skills/system-architect/references/rfc_template.md +59 -0
  35. package/templates/{.agent → .agents}/skills/system-designer/SKILL.md +6 -6
  36. package/templates/{.agent → .agents}/skills/system-designer/references/system-design-template.md +75 -25
  37. package/templates/{.agent → .agents}/skills/task-planner/SKILL.md +1 -1
  38. package/templates/.agents/skills/task-planner/references/TASK_TEMPLATE.md +144 -0
  39. package/templates/{.agent → .agents}/skills/task-reviewer/SKILL.md +4 -3
  40. package/templates/{.agent → .agents}/skills/tech-evaluator/SKILL.md +2 -2
  41. package/templates/{.agent → .agents}/skills/tech-evaluator/references/ADR_TEMPLATE.md +10 -0
  42. package/templates/{.agent → .agents}/workflows/blueprint.md +32 -27
  43. package/templates/{.agent → .agents}/workflows/challenge.md +21 -15
  44. package/templates/{.agent → .agents}/workflows/change.md +23 -14
  45. package/templates/{.agent → .agents}/workflows/craft.md +8 -19
  46. package/templates/{.agent → .agents}/workflows/design-system.md +81 -54
  47. package/templates/{.agent → .agents}/workflows/explore.md +6 -19
  48. package/templates/{.agent → .agents}/workflows/forge.md +30 -32
  49. package/templates/{.agent → .agents}/workflows/genesis.md +68 -56
  50. package/templates/.agents/workflows/probe.md +168 -0
  51. package/templates/{.agent → .agents}/workflows/quickstart.md +7 -12
  52. package/templates/.agents/workflows/upgrade.md +192 -0
  53. package/templates/AGENTS.md +66 -45
  54. package/templates/.agent/skills/build-inspector/SKILL.md +0 -83
  55. package/templates/.agent/skills/complexity-guard/SKILL.md +0 -71
  56. package/templates/.agent/skills/complexity-guard/references/anti_patterns.md +0 -21
  57. package/templates/.agent/skills/concept-modeler/SKILL.md +0 -112
  58. package/templates/.agent/skills/concept-modeler/prompts/GLOSSARY_PROMPT.md +0 -40
  59. package/templates/.agent/skills/concept-modeler/references/ENTITY_EXTRACTION_PROMPT.md +0 -299
  60. package/templates/.agent/skills/concept-modeler/scripts/glossary_gen.py +0 -66
  61. package/templates/.agent/skills/git-forensics/SKILL.md +0 -74
  62. package/templates/.agent/skills/git-forensics/references/ANALYSIS_METHODOLOGY.md +0 -193
  63. package/templates/.agent/skills/git-forensics/scripts/__pycache__/git_forensics.cpython-313.pyc +0 -0
  64. package/templates/.agent/skills/git-forensics/scripts/git_forensics.py +0 -615
  65. package/templates/.agent/skills/git-forensics/scripts/git_hotspots.py +0 -118
  66. package/templates/.agent/skills/report-template/references/REPORT_TEMPLATE.md +0 -100
  67. package/templates/.agent/skills/spec-writer/SKILL.md +0 -108
  68. package/templates/.agent/skills/system-architect/references/rfc_template.md +0 -59
  69. package/templates/.agent/skills/task-planner/references/TASK_TEMPLATE.md +0 -144
  70. package/templates/.agent/workflows/scout.md +0 -139
  71. /package/templates/{.agent → .agents}/skills/system-designer/references/system-design-detail-template.md +0 -0
@@ -0,0 +1,298 @@
1
+ # 输出 Schema 规范
2
+
3
+ > **EMIT 阶段硬门控**:本文件由 `probe-protocol.md` 的 EMIT 阶段门控强制触发读取,
4
+ > 写入任何 `.nexus-map/` 文件前必须完成本文阅读。
5
+ > 本文 Schema 均基于实际运行输出校正,与脚本当前版本保持一致。
6
+
7
+ ---
8
+
9
+ ## raw/ast_nodes.json(extract_ast.py 产出)
10
+
11
+ ### 顶层结构
12
+ ```json
13
+ {
14
+ "languages": ["cpp", "python"],
15
+ "stats": {
16
+ "total_files": 101,
17
+ "total_lines": 23184,
18
+ "parse_errors": 0,
19
+ "truncated": true,
20
+ "truncated_nodes": 298,
21
+ "supported_file_counts": {"python": 101},
22
+ "languages_with_structural_queries": ["python", "javascript", "typescript"],
23
+ "languages_with_custom_queries": ["gdscript"],
24
+ "module_only_file_counts": {"vue": 12},
25
+ "known_unsupported_file_counts": {"customdsl": 24},
26
+ "configured_but_unavailable_file_counts": {"templ": 6},
27
+ "custom_language_config_paths": ["/custom/path/to/language-config.json"]
28
+ },
29
+ "warnings": [
30
+ "custom language configuration loaded: /custom/path/to/language-config.json",
31
+ "some languages were parsed with module-only coverage because no structural query template is bundled: vue (12 files)",
32
+ "known unsupported languages present; downstream outputs must mark inferred sections explicitly: customdsl (24 files)",
33
+ "some configured languages were detected in source files but no parser could be loaded: templ (6 files)"
34
+ ],
35
+ "nodes": [...],
36
+ "edges": [...]
37
+ }
38
+ ```
39
+
40
+ ### Module 节点
41
+ ```json
42
+ {
43
+ "id": "src.nexus.application.weaving.treesitter_parser",
44
+ "type": "Module",
45
+ "label": "treesitter_parser",
46
+ "path": "src/nexus/application/weaving/treesitter_parser.py",
47
+ "lines": 320,
48
+ "lang": "python"
49
+ }
50
+ ```
51
+
52
+ ### Class 节点
53
+ ```json
54
+ {
55
+ "id": "src.nexus.application.weaving.treesitter_parser.TreeSitterParser",
56
+ "type": "Class",
57
+ "label": "TreeSitterParser",
58
+ "path": "src/nexus/application/weaving/treesitter_parser.py",
59
+ "parent": "src.nexus.application.weaving.treesitter_parser",
60
+ "start_line": 15,
61
+ "end_line": 287
62
+ }
63
+ ```
64
+
65
+ ### Edge
66
+ ```json
67
+ {
68
+ "source": "src.nexus.infrastructure",
69
+ "target": "src.nexus.infrastructure.db_client",
70
+ "type": "contains"
71
+ }
72
+ ```
73
+
74
+ **Edge 类型**:`contains`(模块→类,类→方法)/ `imports`(import 语句解析)
75
+
76
+ ### warnings 字段
77
+
78
+ `warnings` 是可选数组,用来暴露不会导致 PROFILE 失败、但会影响下游可信度的降级信息,例如:
79
+ - grammar 可加载,但当前仅有 Module 级覆盖
80
+ - 已知但未支持的语言存在
81
+ - AST 被截断
82
+ - 部分解析器不可用
83
+
84
+ ### 覆盖分层字段
85
+
86
+ | 字段 | 含义 |
87
+ | ---------------------------------------- | ----------------------------------------------------------------- |
88
+ | `supported_file_counts` | 成功进入 AST 流程的文件数(含完整结构覆盖和 module-only 覆盖) |
89
+ | `languages_with_structural_queries` | 当前 bundled query 模板覆盖到的语言 |
90
+ | `languages_with_custom_queries` | 通过 `--add-query` 或 `--language-config` 新增或覆盖 query 的语言 |
91
+ | `module_only_file_counts` | grammar 可加载,但当前没有结构 query,只产出 Module 节点的语言 |
92
+ | `known_unsupported_file_counts` | 已知存在但完全未进入 AST 流程的语言 |
93
+ | `configured_but_unavailable_file_counts` | agent 明确要求支持该语言,但当前环境没有可用 parser |
94
+ | `custom_language_config_paths` | 本次实际加载的显式语言配置文件路径;纯 CLI 模式下为空 |
95
+
96
+ ---
97
+
98
+ ## raw/git_stats.json(git_detective.py 产出)
99
+
100
+ ```json
101
+ {
102
+ "analysis_period_days": 90,
103
+ "stats": {
104
+ "total_commits": 42,
105
+ "total_authors": 1
106
+ },
107
+ "hotspots": [
108
+ {"path": "src/nexus/tasks/analysis_tasks.py", "changes": 21, "risk": "high"}
109
+ ],
110
+ "coupling_pairs": [
111
+ {"file_a": "...", "file_b": "...", "co_changes": 5, "coupling_score": 0.71}
112
+ ]
113
+ }
114
+ ```
115
+
116
+ **risk 阈值**:`changes < 5` → `low` / `5–15` → `medium` / `> 15` → `high`
117
+
118
+ ---
119
+
120
+ ## 生成的 Markdown 文件头部
121
+
122
+ `INDEX.md`、`arch/*.md`、`concepts/domains.md`、`hotspots/git_forensics.md` 的头部至少包含:
123
+
124
+ ```markdown
125
+ > generated_by: nexus-mapper v2
126
+ > verified_at: 2026-03-07
127
+ > provenance: AST-backed except where explicitly marked inferred
128
+ ```
129
+
130
+ 如存在语言降级或人工推断,`provenance` 必须扩展说明:
131
+
132
+ ```markdown
133
+ > provenance: AST-backed for Python; some custom DSL files were detected but not parsed by bundled AST tooling, so the affected dependency notes below are inferred from file tree and manual inspection.
134
+ ```
135
+
136
+ ---
137
+
138
+ ## concepts/concept_model.json — Schema V1
139
+
140
+ Schema V1 的人类可读名称字段只有 `label`,不要额外引入 `title`;若出现 `title`,视为非规范字段,应删除。
141
+
142
+ ```json
143
+ {
144
+ "$schema": "nexus-mapper/concept-model/v1",
145
+ "generated_at": "2026-03-05T15:00:00Z",
146
+ "repo_path": "/absolute/path/to/repo",
147
+ "generator": "nexus-mapper v2",
148
+ "nodes": [
149
+ {
150
+ "id": "nexus.ast-extractor",
151
+ "type": "System",
152
+ "label": "AST Extractor",
153
+ "responsibility": "使用 Tree-sitter 解析 Python 仓库,提取模块/类/函数节点及 import 关系,输出机器可读 JSON",
154
+ "implementation_status": "implemented",
155
+ "code_path": "src/nexus/application/weaving/",
156
+ "evidence_path": null,
157
+ "evidence_gap": null,
158
+ "tech_stack": ["tree-sitter", "python"],
159
+ "related_reqs": ["REQ-101"],
160
+ "complexity": "medium",
161
+ "hotspot": true
162
+ }
163
+ ],
164
+ "edges": [
165
+ {
166
+ "source": "nexus.ast-extractor",
167
+ "target": "nexus.task-dispatcher",
168
+ "type": "depends_on",
169
+ "description": "可选说明"
170
+ }
171
+ ],
172
+ "metadata": {
173
+ "total_files": 101,
174
+ "total_lines": 23184,
175
+ "languages": ["python"],
176
+ "git_commits_analyzed": 42,
177
+ "analysis_days": 90
178
+ }
179
+ }
180
+ ```
181
+
182
+ ### 节点字段校验规则
183
+
184
+ | 字段 | 必需 | 触发 `[!ERROR]` 的情况 |
185
+ | ----------------------- | :------: | --------------------------------------------------------------------------- |
186
+ | `id` | 是 | 全局重复;含大写字母或空格(必须为 kebab-case 小写) |
187
+ | `type` | 是 | 不在枚举 `System / Domain / Module / Class / Function` 中 |
188
+ | `label` | 是 | 空字符串 |
189
+ | `title` | 否 | Schema V1 不定义该字段;若写入,视为多余字段 |
190
+ | `responsibility` | 是 | 空泛到无法验证;字数 < 10 或 > 120 |
191
+ | `implementation_status` | 是 | 不在枚举 `implemented / planned / inferred` 中 |
192
+ | `code_path` | 条件必需 | `implementation_status=implemented` 但为空;或路径在 repo 中不实际存在 |
193
+ | `evidence_path` | 条件必需 | `implementation_status=planned/inferred` 但为空;或路径在 repo 中不实际存在 |
194
+ | `evidence_gap` | 条件必需 | `implementation_status=planned/inferred` 但为空 |
195
+
196
+ ### 节点状态表达规范
197
+
198
+ **已实现节点**
199
+ ```json
200
+ {
201
+ "implementation_status": "implemented",
202
+ "code_path": "src/server/",
203
+ "evidence_path": null,
204
+ "evidence_gap": null
205
+ }
206
+ ```
207
+
208
+ **计划中节点**
209
+ ```json
210
+ {
211
+ "implementation_status": "planned",
212
+ "code_path": null,
213
+ "evidence_path": "docs/architecture.md",
214
+ "evidence_gap": "设计文档提到 Monarch/Executor,但仓库中未发现 src/agents/monarch/"
215
+ }
216
+ ```
217
+
218
+ **推断节点**
219
+ ```json
220
+ {
221
+ "implementation_status": "inferred",
222
+ "code_path": null,
223
+ "evidence_path": "docs/architecture.md",
224
+ "evidence_gap": "仓库包含当前未支持的 DSL 文件;此边界来自文件树与人工阅读"
225
+ }
226
+ ```
227
+
228
+ ---
229
+
230
+ ## query_graph.py 输出格式参考(stdout,非写入文件)
231
+
232
+ ### --file
233
+
234
+ ```
235
+ === <file_path> ===
236
+ Module: <module_id> (<lines> lines, <lang>)
237
+
238
+ Classes:
239
+ <ClassName> (L<start>-L<end>)
240
+ ├─ <method_name> (L<start>-L<end>)
241
+ └─ <method_name> (L<start>-L<end>)
242
+
243
+ Top-level Functions:
244
+ <func_name> (L<start>-L<end>)
245
+
246
+ Imports:
247
+ → <internal_module> (<path>)
248
+ → <external_package> (external)
249
+ ```
250
+
251
+ ### --who-imports
252
+
253
+ ```
254
+ === Who imports <module>? ===
255
+ Imported by N module(s):
256
+ ← <module_id> (<path>)
257
+ ```
258
+
259
+ ### --impact
260
+
261
+ ```
262
+ === Impact radius: <file_path> ===
263
+
264
+ Depends on (this file imports):
265
+ → <module_id> (<path>)
266
+
267
+ Depended by (other files import this):
268
+ ← <module_id> (<path>)
269
+
270
+ Impact summary: N upstream dependencies, M downstream dependents
271
+
272
+ # 以下仅在传入 --git-stats 且该文件存在 hotspot/coupling 数据时输出
273
+ Git risk: high (N changes in 90 days)
274
+ Coupled files (co-change):
275
+ - <peer_path> (coupling: 0.XX, N co-changes)
276
+ ```
277
+
278
+ ### --hub-analysis
279
+
280
+ ```
281
+ === Hub Analysis ===
282
+
283
+ Top fan-in (most imported by others):
284
+ 1. <module_id> — imported by N module(s) [<path>]
285
+
286
+ Top fan-out (imports most others):
287
+ 1. <module_id> — imports N internal module(s) [<path>]
288
+ ```
289
+
290
+ ### --summary
291
+
292
+ ```
293
+ === Directory Summary ===
294
+
295
+ <dir>/ (N modules, N classes, N functions, N lines)
296
+ Key classes: ClassA, ClassB, ...
297
+ Key imports from: <other_dir>, ...
298
+ ```
@@ -0,0 +1,246 @@
1
+ # PROBE 协议 — 各阶段详细步骤
2
+
3
+ > 本文件是 SKILL.md 的执行蓝图,Skill 激活后**第一步**即读取本文件,一次性完整读取。
4
+ > EMIT 前还需读 `references/output-schema.md`(Schema 太具体,单独放以节约激活时的 context)。
5
+ > 非标准语言支持见 `references/language-customization.md`(按需,非门控)。
6
+
7
+ ---
8
+
9
+ ## P — PROFILE 阶段
10
+
11
+ **前置验证**
12
+ 1. 确认 `$repo_path` 目录存在
13
+ 2. 检查 `$repo_path/.git` 是否存在
14
+ - 存在:执行 git 热点分析
15
+ - 不存在:记录 `git analysis skipped`,继续进行 AST 与文件树探测
16
+
17
+ **执行步骤**
18
+
19
+ ```bash
20
+ # 步骤 1: 运行 AST 提取器(同时生成过滤后的文件树)
21
+ python $SKILL_DIR/scripts/extract_ast.py $repo_path [--max-nodes 500] \
22
+ --file-tree-out .nexus-map/raw/file_tree.txt \
23
+ > $repo_path/.nexus-map/raw/ast_nodes.json
24
+
25
+ # 若仓库包含内置未覆盖的语言,通过命令行参数补充支持
26
+ python $SKILL_DIR/scripts/extract_ast.py $repo_path [--max-nodes 500] \
27
+ --add-extension .templ=templ \
28
+ --add-query templ struct "(component_declaration name: (identifier) @class.name) @class.def" \
29
+ --file-tree-out .nexus-map/raw/file_tree.txt \
30
+ > $repo_path/.nexus-map/raw/ast_nodes.json
31
+
32
+ # 或使用显式 JSON 配置文件(配置较复杂时,详见 references/language-customization.md)
33
+ python $SKILL_DIR/scripts/extract_ast.py $repo_path [--max-nodes 500] \
34
+ --language-config /custom/path/to/language-config.json \
35
+ --file-tree-out .nexus-map/raw/file_tree.txt \
36
+ > $repo_path/.nexus-map/raw/ast_nodes.json
37
+
38
+ # 步骤 2: 运行 git 热点分析(仅在存在 .git 时)
39
+ python $SKILL_DIR/scripts/git_detective.py $repo_path --days 90 \
40
+ > $repo_path/.nexus-map/raw/git_stats.json
41
+ ```
42
+
43
+ > `$SKILL_DIR` 为本 Skill 的安装路径(`.agent/skills/nexus-mapper` 或独立 repo 路径)。
44
+ > `$repo_path` 为目标仓库的绝对路径。
45
+ > `extract_ast.py --file-tree-out` 默认排除 `.git/`、`.nexus-map/`、`node_modules/`、`__pycache__/`、`.venv/`、`dist/`、`build/` 等噪音目录及文件。
46
+
47
+ **完成检查(任一失败 → 停止,不进入 REASON)**
48
+ - [ ] `raw/ast_nodes.json` 已写入(`nodes` 为空列表也属正常降级)
49
+ - [ ] `raw/file_tree.txt` 非空
50
+ - [ ] 若存在 git 历史:`raw/git_stats.json` 非空,包含 `hotspots` 字段
51
+ - [ ] 若不存在 git 历史:已明确记录这是一次无 git 降级探测
52
+ - [ ] 若 `ast_nodes.json.stats.known_unsupported_file_counts` 非空:已记录语言覆盖降级
53
+ - [ ] 若 `ast_nodes.json.stats.module_only_file_counts` 非空:已记录哪些语言只有 Module 级覆盖
54
+ - [ ] 若 `ast_nodes.json.stats.configured_but_unavailable_file_counts` 非空:已记录这部分视为未覆盖
55
+
56
+ ---
57
+
58
+ ## R — REASON 阶段
59
+
60
+ **边界场景前置检查**(开始阅读项目文件前先过以下清单,命中任何一项需调整执行策略)
61
+
62
+ | 场景 | 识别方式 | 处理 |
63
+ | ----------------------------- | --------------------------- | ---------------------------------------------------------------------------------------- |
64
+ | 无 git 历史的新仓库 | `.git` 存在但只有 1 次提交 | 跳过 `git_detective.py`,输出中写明 `git analysis skipped: insufficient history` |
65
+ | 非 git 仓库 | `.git` 不存在 | 跳过 `git_detective.py`,最终输出标注 `hotspots skipped: no git metadata` |
66
+ | 大型 Monorepo(>1000 文件) | `stats.truncated=true` | 告知用户使用 `--max-nodes 200`;`truncated=true` 是预期行为 |
67
+ | Git 历史过长(>3000 commits) | 分析慢 / git 数据过大 | 改用 `--days 30` 代替默认 90 天 |
68
+ | 无 README 的项目 | 根目录无 README | 直接跳至 `pyproject.toml` / `package.json`;假说日志注明 evidence gap |
69
+ | 带路线图/Sprint 状态的仓库 | README/TASKS 含时间敏感状态 | 允许摘要,必须附 `verified_at` 和源文档路径;禁止把无日期状态写成当前事实 |
70
+ | 截断行为(truncated=true) | `stats.truncated_nodes > 0` | Function 节点被丢弃,不会生成 `raw/functions.json`;可基于 Module/Class 节点产出完整产物 |
71
+
72
+ > [!DEVIATION]
73
+ > **已知实现偏差**:截断的 Function 节点被**直接丢弃**,**不会生成** `raw/functions.json`。
74
+ > 如任何文档描述截断节点写入单独文件,均以本实际行为为准。
75
+
76
+ **多语言覆盖分层**
77
+
78
+ | 状态 | 识别字段 | EMIT 要求 |
79
+ | ---------------------- | ---------------------------------------- | ------------------------------------------------------------ |
80
+ | 完整结构覆盖 | `languages_with_structural_queries` | 正常输出 |
81
+ | 仅 Module 级覆盖 | `module_only_file_counts` | 不得描述为"完整 AST 覆盖";细粒度结论需保守表述 |
82
+ | 配置了但 parser 不可用 | `configured_but_unavailable_file_counts` | 视为未覆盖,不是 module-only;依赖结论只写 `inferred` |
83
+ | 完全未接入 | `known_unsupported_file_counts` | `INDEX.md` 标注降级;相关区域加 `inferred/manual inspection` |
84
+
85
+ **阅读策略(优先级从高到低)**
86
+ 1. `README.md` / `README.rst` — 项目总体描述
87
+ 2. `pyproject.toml` / `package.json` / `pom.xml` — 技术栈与依赖
88
+ 3. 主入口文件(`main.py`, `index.ts`, `Application.java`)
89
+ 4. `raw/file_tree.txt` — 目录结构感知
90
+ 5. `raw/git_stats.json` hotspots Top 5 — 最活跃文件(仅 git 数据可用时)
91
+ 6. 测试目录 — 建立静态测试面,不需要运行测试
92
+
93
+ **执行要求**
94
+ - 进行深度思考,逐步推演足够支撑结论的关键决策点,通常 3-5 个
95
+ - 识别仓库的主要 System 级节点,通常 1-5 个;不要为凑数量把纯技术细节拆成独立系统
96
+ - **[推荐]** 运行 hub-analysis 用扇入/扇出数据验证核心系统假说:
97
+ ```bash
98
+ python $SKILL_DIR/scripts/query_graph.py $repo_path/.nexus-map/raw/ast_nodes.json --hub-analysis
99
+ ```
100
+
101
+ **记录格式**(工作记忆,不写文件)
102
+ ```
103
+ [REASON LOG]
104
+ - System A: 推断职责=X, implementation_status=implemented, code_path=Y (置信度: 高/中/低)
105
+ - System B: 推断职责=X, implementation_status=planned, evidence_path=Y (置信度: 高/中/低)
106
+ - Evidence gap: Z 目录归属缺少直接证据(将在 OBJECT 中质疑)
107
+ ```
108
+
109
+ ---
110
+
111
+ ## O — OBJECT 阶段
112
+
113
+ **为什么需要质疑**:第一直觉建立的系统假说有三类典型偏差——目录名不等于职责、git 热点揭示真正的核心、import 方向揭示层次错误。三维度(下文)系统性覆盖这三类偏差。
114
+
115
+ **质疑协议** — 提出足以挑战当前假设的最少一组高价值质疑,通常 1-3 个,每个附证据线索
116
+
117
+ 质疑点格式:
118
+ ```
119
+ Q{N}: [具体的矛盾或可疑之处]
120
+ 证据线索: [在哪里发现的矛盾 — 文件路径/行号/git 数据]
121
+ 验证计划: [BENCHMARK 阶段如何验证]
122
+ ```
123
+
124
+ 不合格质疑(禁止提交):
125
+ ```
126
+ Q1: 我对系统结构的把握还不够扎实
127
+ Q2: xxx 目录的职责暂时没有直接证据
128
+ ```
129
+ 问题不在措辞,而在于没有代码引证,也没有可执行的验证计划。
130
+
131
+ 合格示例:
132
+ ```
133
+ Q1: git_stats 显示 tasks/analysis_tasks.py 变更 21 次(high risk),
134
+ 但 REASON 认为编排入口是 evolution/detective_loop.py。
135
+ 矛盾:若 detective_loop 是入口,analysis_tasks 为何热度更高?
136
+ 证据线索: raw/git_stats.json hotspots[0]
137
+ 验证计划: view tasks/analysis_tasks.py 的 class 定义 + import 树
138
+ ```
139
+
140
+ **三维度质疑框架**(对应 Structure / Evolution / Dependency)
141
+
142
+ | 维度 | 数据来源 | 高价值质疑模式 |
143
+ | ---------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------ |
144
+ | Structure | `raw/file_tree.txt`、ast edges(`contains`) | 假设的"基础设施层"目录下出现业务命名文件;多个 System 文件都在同一 `utils/` 里(边界模糊) |
145
+ | Evolution | `raw/git_stats.json` hotspots + coupling_pairs | 热点榜首不在假设的"核心系统"内;coupling_score > 0.7 的文件对分属不同 System(边界划错) |
146
+ | Dependency | ast edges(`imports`) | 假设的底层 module import 了上层 module(循环依赖/分层错误);import 方向与假设相反 |
147
+
148
+ **质疑分级**
149
+
150
+ | 级别 | 定义 | BENCHMARK 优先级 |
151
+ | -------- | -------------------------------------------------------- | :---------------------------: |
152
+ | Critical | 假设的系统边界完全错误,`code_path` 应指向完全不同的位置 | 立即验证,验证前不得进入 EMIT |
153
+ | High | 核心系统的 `code_path` 可能有误或遗漏了重要子目录 | BENCHMARK 首批 |
154
+ | Medium | 子目录职责划分模糊,可能影响 `responsibility` 准确性 | BENCHMARK 第二批 |
155
+
156
+ > 如果证据只支持 Medium,就保持 Medium。至少有一条质疑必须真正可能改变系统边界、主入口或依赖方向。
157
+
158
+ **三维度执行检查单**
159
+ - [ ] Structure: file_tree.txt 是否有与假设系统无法匹配的文件/目录?
160
+ - [ ] Structure: 是否有跨系统的 `utils/`/`common/` 目录存在模糊地带?
161
+ - [ ] Evolution: git 数据可用时,热点前列是否支持"核心系统"的判断?
162
+ - [ ] Evolution: coupling_pairs 中是否有跨假设系统边界的强耦合对(score > 0.5)?
163
+ - [ ] Dependency: 是否有违反假设分层方向的 import 边(下层 imports 上层)?
164
+ - [ ] Dependency: 是否有 System 的 imports 方向与假设的"依赖者-被依赖者"关系相反?
165
+
166
+ ---
167
+
168
+ ## B — BENCHMARK 阶段
169
+
170
+ **对每个质疑点执行验证**
171
+ 1. 用 `grep_search` / `view_file` 查找具体证据
172
+ 2. **[推荐]** 用 `query_graph.py --impact` 查看目标文件的真实上下游依赖:
173
+ ```bash
174
+ python $SKILL_DIR/scripts/query_graph.py $repo_path/.nexus-map/raw/ast_nodes.json \
175
+ --impact <目标文件> --git-stats $repo_path/.nexus-map/raw/git_stats.json
176
+ ```
177
+ 3. 判断结果:
178
+ - 质疑成立 → 修正节点的 `code_path` 或 `responsibility`,在 LOG 中标记「修正」
179
+ - 质疑不成立 → 确认原假设,标记「验证通过」
180
+
181
+ **全局节点校验(全部 System 节点逐一执行)**
182
+ - [ ] `implemented` 节点的 `code_path` 在 repo 中实际存在
183
+ - [ ] `planned/inferred` 节点不伪造 `code_path`,改用 `evidence_path + evidence_gap`
184
+ - [ ] 每个 `planned/inferred` 节点的 `evidence_path` 在 repo 中实际存在
185
+ - [ ] `responsibility` 表意清晰、具体;若证据不足,明确记录 evidence gap
186
+ - [ ] 节点 `id` 全局唯一,kebab-case,全部小写
187
+
188
+ > 发现关键系统完全识别错误 → 允许返回 REASON 重建模型,并重新执行 OBJECT。
189
+
190
+ ---
191
+
192
+ ## E — EMIT 阶段
193
+
194
+ > [!IMPORTANT]
195
+ > **阶段门控**:写入任何文件之前,必须先读:
196
+ > `references/output-schema.md`
197
+ > 未读取该文件即写入 → 产出的 JSON/Markdown 结构无法通过 Schema 校验,视为无效。
198
+
199
+ **幂等性检查(写入前必做)**
200
+
201
+ | 检查结果 | 处理方式 |
202
+ | ------------------------------------ | ------------------------------------------------- |
203
+ | `.nexus-map/` 不存在 | 直接继续 |
204
+ | `.nexus-map/` 存在且 `INDEX.md` 有效 | 询问用户:「检测到已有分析结果,是否覆盖?[y/n]」 |
205
+ | `.nexus-map/` 存在但文件不完整 | 「检测到未完成分析,将重新生成」,继续 |
206
+
207
+ **[推荐] 写入前先获取结构摘要**
208
+ ```bash
209
+ python $SKILL_DIR/scripts/query_graph.py $repo_path/.nexus-map/raw/ast_nodes.json --summary
210
+ ```
211
+
212
+ **写入顺序(先写 `.tmp/`,全部成功后整体移动)**
213
+ ```
214
+ 1. .nexus-map/.tmp/concepts/concept_model.json ← Schema V1
215
+ 2. .nexus-map/.tmp/INDEX.md ← L0 摘要, < 2000 tokens
216
+ 3. .nexus-map/.tmp/arch/systems.md ← 各 System 边界
217
+ 4. .nexus-map/.tmp/arch/dependencies.md ← Mermaid 依赖图
218
+ 5. .nexus-map/.tmp/arch/test_coverage.md ← 静态测试面与证据缺口
219
+ 6. .nexus-map/.tmp/concepts/domains.md ← Domain 概念说明
220
+ 7. .nexus-map/.tmp/hotspots/git_forensics.md ← Git 热点摘要
221
+ ```
222
+
223
+ 全部写入成功 → 移动 `.tmp/` 内容到 `.nexus-map/` → 删除 `.tmp/`
224
+
225
+ **INDEX.md 写入要求**
226
+ - token 数 < 2000,超过就重写
227
+ - 结论具体,不使用模糊词搪塞;证据不足时明确写 `evidence gap` 或 `unknown`
228
+ - **必须包含 SKILL.md 守则4 定义的「操作指南」硬路由块**
229
+
230
+ **每个 Markdown 文件的头部最少包含**
231
+ ```markdown
232
+ > generated_by: nexus-mapper v2
233
+ > verified_at: 2026-03-07
234
+ > provenance: AST-backed except where explicitly marked inferred
235
+ ```
236
+
237
+ **edges 合并协议(写入 concept_model.json 前执行)**
238
+ 1. 导入 `raw/ast_nodes.json` 中的 edges(`imports`/`contains`,机器层精确)
239
+ 2. 追加 BENCHMARK 阶段推断的语义边(`depends_on`/`calls`)
240
+ 3. 去重:`(source, target, type)` 三元组相同的边保留一条
241
+
242
+ **完成校验**
243
+ - [ ] `INDEX.md` 存在,结论具体且对证据缺口诚实,< 2000 tokens,包含硬路由块
244
+ - [ ] `concept_model.json` 中 `implemented` 节点都有已验证 `code_path`
245
+ - [ ] `arch/dependencies.md` 包含 >= 1 个 Mermaid 图
246
+ - [ ] `arch/test_coverage.md` 说明了静态测试面,并明确未运行测试的证据缺口