@haaaiawd/anws 1.2.4 → 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 -173
  2. package/bin/cli.js +22 -9
  3. package/lib/adapters/index.js +157 -0
  4. package/lib/agents.js +185 -0
  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 +238 -174
  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 +355 -149
  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 +38 -33
  43. package/templates/{.agent → .agents}/workflows/challenge.md +21 -15
  44. package/templates/{.agent → .agents}/workflows/change.md +24 -15
  45. package/templates/{.agent → .agents}/workflows/craft.md +9 -20
  46. package/templates/{.agent → .agents}/workflows/design-system.md +83 -56
  47. package/templates/{.agent → .agents}/workflows/explore.md +6 -19
  48. package/templates/{.agent → .agents}/workflows/forge.md +36 -38
  49. package/templates/{.agent → .agents}/workflows/genesis.md +76 -64
  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 +134 -113
  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,164 @@
1
+ # 为 nexus-mapper 补充语言支持
2
+
3
+ > 本文件不是阶段门控文件。当内置语言覆盖不足时,后续 agent 应优先参考本文件,通过命令行参数补充支持;只有在配置较复杂时,才使用显式 JSON 配置文件。
4
+
5
+ ---
6
+
7
+ ## 目标
8
+
9
+ 当前脚本的默认模型是:
10
+
11
+ 1. 先使用内置扩展名映射和内置 Tree-sitter query
12
+ 2. 若内置覆盖不足,再由 agent 通过命令行补充语言支持
13
+ 3. 若命令行参数过多或 query 过长,再退回到 `--language-config <JSON_FILE>`
14
+
15
+ 这意味着:
16
+ - 不要求仓库内必须存在固定路径的语言配置文件
17
+ - 不建议为了单个仓库的单次分析先改核心脚本
18
+ - 新接手的 agent 可以在一次命令中直接把额外语言接入分析流程
19
+
20
+ ---
21
+
22
+ ## 优先方案:命令行补充
23
+
24
+ ### 适用场景
25
+
26
+ 满足以下条件时,优先用命令行:
27
+
28
+ - 仓库里出现了内置未覆盖的扩展名
29
+ - 只需要补 1 到 3 个语言映射
30
+ - query 较短,适合直接写在命令行中
31
+
32
+ ### 步骤 1:确认语言名
33
+
34
+ 先确认 `tree-sitter-language-pack` 或当前环境可识别的语言名。例如:
35
+
36
+ - `.templ` -> `templ`
37
+ - `.hbs` -> `handlebars`
38
+ - `.rego` -> `rego`
39
+
40
+ 如果语言名不确定,先查官方 grammar 名称;不要猜测一个语言名直接写入最终结论。
41
+
42
+ ### 步骤 2:补扩展名映射
43
+
44
+ ```bash
45
+ python extract_ast.py <repo_path> \
46
+ --add-extension .templ=templ \
47
+ --add-extension .hbs=handlebars
48
+ ```
49
+
50
+ 这会把原本不认识的扩展名纳入语言分发流程。
51
+
52
+ ### 步骤 3:按需补 query
53
+
54
+ 如果只需要 Module 级覆盖,可以到此为止。
55
+
56
+ 如果需要类/函数级结构,继续追加 `--add-query`:
57
+
58
+ ```bash
59
+ python extract_ast.py <repo_path> \
60
+ --add-extension .templ=templ \
61
+ --add-query templ struct "(component_declaration name: (identifier) @class.name) @class.def"
62
+ ```
63
+
64
+ 参数格式:
65
+
66
+ ```text
67
+ --add-query <LANG> <TYPE> <QUERY_STRING>
68
+ ```
69
+
70
+ 其中:
71
+ - `<LANG>`:语言名,例如 `templ`
72
+ - `<TYPE>`:`struct` 或 `imports`
73
+ - `<QUERY_STRING>`:Tree-sitter query 字符串
74
+
75
+ capture 命名必须继续遵守现有约定:
76
+ - 类:`@class.def` / `@class.name`
77
+ - 函数:`@func.def` / `@func.name`
78
+ - 导入:`@mod`
79
+
80
+ ---
81
+
82
+ ## 备选方案:显式 JSON 配置文件
83
+
84
+ 当下面任一情况成立时,可使用 `--language-config`:
85
+
86
+ - 需要补多个语言,命令行已经过长
87
+ - query 很复杂,不适合内联在 shell 命令里
88
+ - 希望把一次分析所需的扩展映射和 query 集中保存
89
+
90
+ 示例:
91
+
92
+ ```json
93
+ {
94
+ "extensions": {
95
+ ".templ": "templ",
96
+ ".hbs": "handlebars"
97
+ },
98
+ "queries": {
99
+ "templ": {
100
+ "struct": "(component_declaration name: (identifier) @class.name) @class.def",
101
+ "imports": ""
102
+ }
103
+ },
104
+ "unsupported_extensions": {
105
+ ".legacydsl": "legacydsl"
106
+ }
107
+ }
108
+ ```
109
+
110
+ 执行方式:
111
+
112
+ ```bash
113
+ python extract_ast.py <repo_path> --language-config /custom/path/to/language-config.json
114
+ ```
115
+
116
+ 说明:
117
+ - `extensions`:扩展名到语言名的映射
118
+ - `queries`:自定义 `struct` / `imports` query
119
+ - `unsupported_extensions`:显式声明当前仍不支持的扩展名,避免静默跳过
120
+
121
+ 这里的 JSON 文件是一次分析的显式输入,不要求固定放在仓库某个默认位置。
122
+
123
+ ---
124
+
125
+ ## 覆盖诚实度规则
126
+
127
+ 不管是命令行还是显式 JSON,新增语言都必须遵守同一套分层标准:
128
+
129
+ 1. `structural coverage`
130
+ 条件:parser 可加载,且存在 `struct` query
131
+
132
+ 2. `module-only coverage`
133
+ 条件:parser 可加载,但没有 `struct` query
134
+
135
+ 3. `configured-but-unavailable`
136
+ 条件:agent 明确要求支持该语言,但当前环境无法加载 parser
137
+
138
+ 4. `unsupported`
139
+ 条件:该语言仍未纳入本次 AST 流程,或被显式标记为未支持
140
+
141
+ 禁止:
142
+ - 把 `configured-but-unavailable` 写成 `module-only`
143
+ - 把 `unsupported` 伪装成“仓库里没出现”
144
+
145
+ ---
146
+
147
+ ## 推荐决策顺序
148
+
149
+ 当后续 agent 遇到一个未覆盖语言时,按以下顺序处理:
150
+
151
+ 1. 先确认当前仓库里是否真的存在该扩展名文件
152
+ 2. 再确认当前环境能否加载对应 parser
153
+ 3. 若能加载:优先用 `--add-extension`;需要结构节点时再补 `--add-query`
154
+ 4. 若命令太长:改用 `--language-config`
155
+ 5. 若 parser 不能加载:保留 `configured-but-unavailable`,不要伪造结果
156
+
157
+ ---
158
+
159
+ ## 设计原则
160
+
161
+ - 内置语言优先,命令行补充其次,显式 JSON 最后
162
+ - 对单次分析,优先使用最小额外输入,不要先改核心脚本
163
+ - 自定义 query 是正式输入,不是旁路 hack
164
+ - 所有新增语言都必须遵守同一套 metadata 和 provenance 规则
@@ -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
+ ```