@haaaiawd/anws 2.3.0 → 2.4.1

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 (95) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +53 -23
  3. package/lib/diff.js +5 -2
  4. package/lib/init.js +217 -96
  5. package/lib/install-state.js +18 -3
  6. package/lib/manifest.js +364 -79
  7. package/lib/prompt.js +68 -0
  8. package/lib/resources/index.js +36 -2
  9. package/lib/update.js +12 -6
  10. package/package.json +48 -47
  11. package/templates/.agents/skills/anws-system/SKILL.md +107 -105
  12. package/templates/.agents/skills/code-reviewer/SKILL.md +171 -115
  13. package/templates/.agents/skills/concept-modeler/SKILL.md +230 -179
  14. package/templates/.agents/skills/craft-authoring/SKILL.md +186 -183
  15. package/templates/.agents/skills/craft-authoring/references/BUNDLE_POLICY.md +42 -0
  16. package/templates/.agents/skills/design-reviewer/SKILL.md +265 -190
  17. package/templates/.agents/skills/e2e-testing-guide/SKILL.md +246 -135
  18. package/templates/.agents/skills/nexus-mapper/SKILL.md +321 -321
  19. package/templates/.agents/skills/nexus-mapper/references/probe-protocol.md +1 -1
  20. package/templates/.agents/skills/nexus-query/SKILL.md +1 -1
  21. package/templates/.agents/skills/output-contract/SKILL.md +37 -0
  22. package/templates/.agents/skills/runtime-inspector/SKILL.md +150 -99
  23. package/templates/.agents/skills/sequential-thinking/SKILL.md +222 -225
  24. package/templates/.agents/skills/spec-writer/SKILL.md +75 -30
  25. package/templates/.agents/skills/system-architect/SKILL.md +538 -678
  26. package/templates/.agents/skills/system-designer/SKILL.md +124 -537
  27. package/templates/.agents/skills/task-planner/SKILL.md +1 -2
  28. package/templates/.agents/skills/task-planner/references/TASK_TEMPLATE_05A.md +2 -2
  29. package/templates/.agents/skills/task-reviewer/SKILL.md +421 -386
  30. package/templates/.agents/skills/tech-evaluator/SKILL.md +252 -144
  31. package/templates/.agents/workflows/blueprint.md +156 -68
  32. package/templates/.agents/workflows/challenge.md +322 -494
  33. package/templates/.agents/workflows/change.md +182 -339
  34. package/templates/.agents/workflows/craft.md +159 -197
  35. package/templates/.agents/workflows/design-system.md +202 -674
  36. package/templates/.agents/workflows/explore.md +187 -399
  37. package/templates/.agents/workflows/forge.md +650 -609
  38. package/templates/.agents/workflows/genesis.md +438 -351
  39. package/templates/.agents/workflows/probe.md +215 -240
  40. package/templates/.agents/workflows/quickstart.md +304 -123
  41. package/templates/.agents/workflows/upgrade.md +145 -182
  42. package/templates_en/.agents/skills/anws-system/SKILL.md +110 -0
  43. package/templates_en/.agents/skills/code-reviewer/SKILL.md +171 -0
  44. package/templates_en/.agents/skills/concept-modeler/SKILL.md +230 -0
  45. package/templates_en/.agents/skills/craft-authoring/SKILL.md +179 -0
  46. package/templates_en/.agents/skills/craft-authoring/references/BUNDLE_POLICY.md +42 -0
  47. package/templates_en/.agents/skills/craft-authoring/references/PROMPT_QUALITY_RUBRIC.md +92 -0
  48. package/templates_en/.agents/skills/craft-authoring/references/SCORECARD_TEMPLATE.md +52 -0
  49. package/templates_en/.agents/skills/design-reviewer/SKILL.md +264 -0
  50. package/templates_en/.agents/skills/e2e-testing-guide/SKILL.md +246 -0
  51. package/templates_en/.agents/skills/nexus-mapper/SKILL.md +306 -0
  52. package/templates_en/.agents/skills/nexus-mapper/references/language-customization.md +167 -0
  53. package/templates_en/.agents/skills/nexus-mapper/references/output-schema.md +311 -0
  54. package/templates_en/.agents/skills/nexus-mapper/references/probe-protocol.md +246 -0
  55. package/templates_en/.agents/skills/nexus-mapper/scripts/extract_ast.py +706 -0
  56. package/templates_en/.agents/skills/nexus-mapper/scripts/git_detective.py +194 -0
  57. package/templates_en/.agents/skills/nexus-mapper/scripts/languages.json +127 -0
  58. package/templates_en/.agents/skills/nexus-mapper/scripts/query_graph.py +556 -0
  59. package/templates_en/.agents/skills/nexus-mapper/scripts/requirements.txt +6 -0
  60. package/templates_en/.agents/skills/nexus-query/SKILL.md +114 -0
  61. package/templates_en/.agents/skills/nexus-query/scripts/extract_ast.py +706 -0
  62. package/templates_en/.agents/skills/nexus-query/scripts/git_detective.py +194 -0
  63. package/templates_en/.agents/skills/nexus-query/scripts/languages.json +127 -0
  64. package/templates_en/.agents/skills/nexus-query/scripts/query_graph.py +556 -0
  65. package/templates_en/.agents/skills/nexus-query/scripts/requirements.txt +6 -0
  66. package/templates_en/.agents/skills/output-contract/SKILL.md +37 -0
  67. package/templates_en/.agents/skills/runtime-inspector/SKILL.md +150 -0
  68. package/templates_en/.agents/skills/sequential-thinking/SKILL.md +214 -0
  69. package/templates_en/.agents/skills/spec-writer/SKILL.md +153 -0
  70. package/templates_en/.agents/skills/spec-writer/references/prd_template.md +177 -0
  71. package/templates_en/.agents/skills/system-architect/SKILL.md +538 -0
  72. package/templates_en/.agents/skills/system-architect/references/rfc_template.md +59 -0
  73. package/templates_en/.agents/skills/system-designer/SKILL.md +188 -0
  74. package/templates_en/.agents/skills/system-designer/references/system-design-detail-template.md +187 -0
  75. package/templates_en/.agents/skills/system-designer/references/system-design-template.md +605 -0
  76. package/templates_en/.agents/skills/task-planner/SKILL.md +251 -0
  77. package/templates_en/.agents/skills/task-planner/references/TASK_TEMPLATE_05A.md +109 -0
  78. package/templates_en/.agents/skills/task-planner/references/TASK_TEMPLATE_05B.md +176 -0
  79. package/templates_en/.agents/skills/task-reviewer/SKILL.md +422 -0
  80. package/templates_en/.agents/skills/tech-evaluator/SKILL.md +252 -0
  81. package/templates_en/.agents/skills/tech-evaluator/references/ADR_TEMPLATE.md +78 -0
  82. package/templates_en/.agents/workflows/blueprint.md +200 -0
  83. package/templates_en/.agents/workflows/challenge.md +326 -0
  84. package/templates_en/.agents/workflows/change.md +182 -0
  85. package/templates_en/.agents/workflows/craft.md +159 -0
  86. package/templates_en/.agents/workflows/design-system.md +202 -0
  87. package/templates_en/.agents/workflows/explore.md +187 -0
  88. package/templates_en/.agents/workflows/forge.md +651 -0
  89. package/templates_en/.agents/workflows/genesis.md +438 -0
  90. package/templates_en/.agents/workflows/probe.md +215 -0
  91. package/templates_en/.agents/workflows/quickstart.md +305 -0
  92. package/templates_en/.agents/workflows/upgrade.md +145 -0
  93. package/templates_en/AGENTS.md +149 -0
  94. package/templates/.agents/skills/report-template/SKILL.md +0 -92
  95. package/templates/.agents/skills/report-template/references/REPORT_TEMPLATE.md +0 -100
@@ -0,0 +1,306 @@
1
+ ---
2
+ name: nexus-mapper
3
+ description: "Generate a persistent .nexus-map/ knowledge base that lets any AI session instantly understand a codebase's architecture, systems, dependencies, and change hotspots. Use when starting work on an unfamiliar repository, onboarding with AI-assisted context, preparing for a major refactoring initiative, or enabling reliable cold-start AI sessions across a team. Produces INDEX.md, systems.md, concept_model.json, git_forensics.md and more. Requires shell execution and Python 3.10+. For ad-hoc file queries or instant impact analysis during active development, use nexus-query instead."
4
+ ---
5
+
6
+ # nexus-mapper — AI Project Exploration Protocol
7
+
8
+ This Skill guides AI Agents to use the **PROBE Five-Phase Protocol** to systematically explore any local Git repository and produce a `.nexus-map/` layered knowledge base.
9
+
10
+ ---
11
+
12
+ ## When to Call / When Not to Call
13
+
14
+ | Scenario | Call |
15
+ | ----------------------------------------------------------------------- | :---: |
16
+ | User provides local repo path, wants AI to understand its architecture | Yes |
17
+ | Need to generate `.nexus-map/INDEX.md` for subsequent AI session cold start | Yes |
18
+ | User says "help me analyze project", "build project knowledge base", "let AI understand this repo" | Yes |
19
+ | Runtime environment has no shell execution capability (pure API mode, no `run_command` tool) | No |
20
+ | Host machine has no local Python 3.10+ | No |
21
+ | Target repo has no known language source files (no `.py/.ts/.java/.go/.rs/.cpp` etc.) | No |
22
+ | User only wants to query specific file/function → use `view_file` / `grep_search` directly | No |
23
+
24
+ ---
25
+
26
+ ## Prerequisite Check
27
+
28
+ Explicitly inform users of missing items; remind users when downgrade is needed, continue only after consent.
29
+
30
+ | Prerequisite | Check Method |
31
+ | ------------------- | ------------------------------------------- |
32
+ | Target path exists | `$repo_path` accessible |
33
+ | Python 3.10+ | `python --version` >= 3.10 |
34
+ | Script deps installed | `python -c "import tree_sitter"` no error |
35
+ | Has shell execution | Agent environment supports `run_command` tool call |
36
+
37
+ `git` history is a bonus, not a hard blocker. When no `.git` or insufficient history, skip hotspot analysis and explicitly record in output that this is a degraded exploration.
38
+
39
+ ---
40
+
41
+ ## Input Contract
42
+
43
+ ```
44
+ repo_path: Local absolute path to target repository (required)
45
+ ```
46
+
47
+ **Language support**: Automatically dispatch by file extension, language configuration (extension mapping + Tree-sitter queries) stored in `scripts/languages.json`. Currently supports Python/JavaScript/TypeScript/TSX/Bash/Java/Go/Rust/C#/C/C++/Kotlin/Ruby/Swift/Scala/PHP/Lua/Elixir/GDScript/Dart/Haskell/Clojure/SQL/Proto/Solidity/Vue/Svelte/R/Perl and 30+ languages.
48
+
49
+ **Non-standard languages**: If repo contains unsupported languages, dynamically supplement via command line args (see `references/language-customization.md`):
50
+ - `--add-extension .templ=templ` add new file extension mapping
51
+ - `--add-query templ struct "(component_declaration ...)"` add structure query
52
+ - `--language-config <JSON_FILE>` use JSON file for complex configuration
53
+
54
+ ---
55
+
56
+ ## Output Format
57
+
58
+ After execution, target repository root will produce:
59
+
60
+ ```text
61
+ .nexus-map/
62
+ ├── INDEX.md ← AI cold start main entry (< 2000 tokens)
63
+ ├── arch/
64
+ │ ├── systems.md ← System boundaries + code locations
65
+ │ ├── dependencies.md ← Mermaid dependency graph + sequence diagram
66
+ │ └── test_coverage.md ← Static test surface: test files, covered core modules, evidence gaps
67
+ ├── concepts/
68
+ │ ├── concept_model.json ← Schema V1 machine-readable graph
69
+ │ └── domains.md ← Core domain concept explanations
70
+ ├── hotspots/
71
+ │ └── git_forensics.md ← Git hotspots + coupling pair analysis
72
+ └── raw/
73
+ ├── ast_nodes.json ← Tree-sitter parsed raw data
74
+ ├── git_stats.json ← Git hotspots and coupling data
75
+ └── file_tree.txt ← Filtered file tree
76
+ ```
77
+
78
+ All generated Markdown files must include a brief header, at minimum containing: `generated_by`, `verified_at`, `provenance`.
79
+
80
+ Human-readable name fields in `concept_model.json` uniformly use `label`, do not add `title`.
81
+
82
+ If PROFILE phase detects language coverage downgrade or manual inference, `provenance` must be explicitly marked.
83
+
84
+ ---
85
+
86
+ ## PROBE Phase Gate
87
+
88
+ > [!IMPORTANT]
89
+ > **Must read corresponding reference before entering each phase, do not skip.**
90
+ > Detailed steps, completion checklists, and boundary scenario handling for each phase are defined in references.
91
+
92
+ ```
93
+ [Skill activation] → read references/probe-protocol.md (phase step blueprint, includes boundary scenarios and three-dimensional questioning framework)
94
+ [Before EMIT] → read references/output-schema.md (Schema validation spec)
95
+ [Non-standard language] → read references/language-customization.md (as needed, not gated)
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Execution Rules
101
+
102
+ ### Rule 1: OBJECT Rejects Formalism
103
+
104
+ The purpose of OBJECT is to break REASON's survivor bias. Massive engineering facts hide behind directory naming and git hotspots, first intuition is almost always wrong.
105
+
106
+ Unqualified challenges (prohibited to submit):
107
+ ```
108
+ Q1: My grasp of system structure is not solid enough
109
+ Q2: xxx directory responsibilities have no direct evidence yet
110
+ ```
111
+ Problem is not wording, but lack of evidence clues, nor can it be verified in BENCHMARK phase.
112
+
113
+ Qualified challenge format:
114
+ ```
115
+ Q1: git_stats shows tasks/analysis_tasks.py changed 21 times (high risk),
116
+ but HYPOTHESIS thinks orchestration entry is evolution/detective_loop.py.
117
+ Contradiction: If detective_loop is entry, why is analysis_tasks hotter?
118
+ Evidence clue: git_stats.json hotspots[0].path
119
+ Verification plan: view tasks/analysis_tasks.py class definition + import tree
120
+ ```
121
+
122
+ ---
123
+
124
+ ### Rule 2: implemented Nodes Must Have Real code_path
125
+
126
+ > [!IMPORTANT]
127
+ > Before writing to `concept_model.json`, must first distinguish if node is `implemented`, `planned`, or `inferred`.
128
+ > Only `implemented` nodes allowed to write `code_path`, and must personally verify existence.
129
+
130
+ ```bash
131
+ # BENCHMARK phase verification method
132
+ ls $repo_path/src/nexus/application/weaving/ # directory exists → node valid
133
+ ls $repo_path/src/nexus/application/nonexist/ # [!ERROR] → fix or delete this node
134
+ ```
135
+
136
+ For `planned` or `inferred` nodes, use:
137
+
138
+ ```json
139
+ {
140
+ "implementation_status": "planned",
141
+ "code_path": null,
142
+ "evidence_path": "docs/architecture.md",
143
+ "evidence_gap": "src/agents/monarch/ not found in repo, only appears in design docs"
144
+ }
145
+ ```
146
+
147
+ Prohibited: using barely related files to fake `code_path`, stuffing status into path field (like `code_path: "PLANNED"`).
148
+
149
+ ---
150
+
151
+ ### Rule 3: EMIT Atomicity
152
+
153
+ First write everything to `.nexus-map/.tmp/`, after all successful move all to formal directory, delete `.tmp/`.
154
+ Purpose: no half-finished products on mid-failure. Next execution detects `.tmp/` exists → clean up and regenerate.
155
+
156
+ Idempotency rules:
157
+
158
+ | State | Handling |
159
+ | --------------------------------------- | ------------------------------------------- |
160
+ | `.nexus-map/` does not exist | Continue directly |
161
+ | `.nexus-map/` exists and `INDEX.md` valid | Ask user: "Overwrite? [y/n]" |
162
+ | `.nexus-map/` exists but files incomplete | "Detected incomplete analysis, will regenerate", continue directly |
163
+
164
+ ---
165
+
166
+ ### Rule 4: INDEX.md Role — Cold Start Router, Not Static Dictionary
167
+
168
+ Readers of `INDEX.md` are **AI that have never seen this repo before**. Two hard constraints:
169
+ - **< 2000 tokens** — rewrite if exceeded, not truncate
170
+ - **Conclusions must be specific** — when evidence insufficient, explicitly write `evidence gap` or `unknown`, and explain what evidence is missing
171
+
172
+ After writing, execute token estimation: line count × average 30 tokens/line = rough value.
173
+
174
+ **INDEX.md must include mandatory routing block (Hard-Trigger Block)** — write this structure at end of file when generating:
175
+
176
+ ```markdown
177
+ ## [Operation Guide] Mandatory Execution Steps
178
+
179
+ > This section issues hard operation instructions to all AI reading this file, not suggestions.
180
+
181
+ ### Step 1 — Must First Read All Following Files (order unrestricted)
182
+
183
+ After reading this file, before executing any task, must sequentially read full content of following files:
184
+
185
+ - `.nexus-map/arch/systems.md` — System boundaries and code locations
186
+ - `.nexus-map/arch/dependencies.md` — Inter-system dependencies and Mermaid graphs
187
+ - `.nexus-map/arch/test_coverage.md` — Test surface and evidence gaps
188
+ - `.nexus-map/hotspots/git_forensics.md` — Git hotspots and coupling risks
189
+ - `.nexus-map/concepts/domains.md` — Core domain concepts
190
+
191
+ > These files are all high-density summaries, total usually < 5000 tokens, necessary context cost.
192
+ > Do not skip with excuse "task simple" or "only changing one file".
193
+
194
+ ### Step 2 — Add Operations by Task Type (execute after Step 1 complete)
195
+
196
+ - If task involves **interface modification, new cross-module calls, delete/rename public functions**:
197
+ → Must run `query_graph.py --impact <target file>` to confirm impact radius before writing code.
198
+ - If task needs to **determine who references certain file**:
199
+ → Run `query_graph.py --who-imports <module name>`.
200
+ - If repo structure has major changes (new system, refactored module boundaries):
201
+ → After task completion, evaluate whether need to re-run nexus-mapper to update knowledge base.
202
+ ```
203
+
204
+ ---
205
+
206
+ ### Rule 5: Minimal Execution Surface and Sensitive Information Protection
207
+
208
+ > [!IMPORTANT]
209
+ > By default only run this Skill's own scripts and necessary read-only checks. Do not execute target repo's build scripts, test scripts, or custom commands just because "want to understand repo better".
210
+
211
+ - By default allowed: `extract_ast.py`, `git_detective.py`, directory traversal, text search, read-only file viewing
212
+ - By default prohibited: execute target repo's `npm install`, `pnpm dev`, `python main.py`, `docker compose up`, etc., unless user explicitly requests
213
+ - When encountering `.env`, key files, credential configs: only record their existence and purpose, do not copy out specific values
214
+
215
+ ---
216
+
217
+ ### Rule 6: Downgrade and Manual Inference Must Be Explicitly Visible
218
+
219
+ > [!IMPORTANT]
220
+ > If AST coverage is incomplete, or certain parts come from manual reading rather than script output, must explicitly mark provenance in final files.
221
+
222
+ - In `dependencies.md`, any dependency relationship not directly supported by AST must mark `inferred from file tree/manual inspection`
223
+ - `domains.md`, `systems.md`, `INDEX.md` if involving unsupported language areas, must explain `unsupported language downgrade`
224
+ - If writing progress snapshots, Sprint status, must attach `verified_at`, avoid expired info masquerading as current fact
225
+
226
+ ---
227
+
228
+ ## Uncertainty Expression Specification
229
+
230
+ Avoid only writing: pending · maybe · possibly · TBD
231
+
232
+ If evidence insufficient, write in following format:
233
+ - `unknown: No direct evidence found indicating api/ is main entry, currently only can confirm cli.py is referenced by README`
234
+ - `evidence gap: Repo has no git history, therefore hotspots section skipped`
235
+
236
+ Allowed to honestly write uncertainty, but must explain which missing evidence causes uncertainty.
237
+
238
+ ---
239
+
240
+ ## Script Toolchain
241
+
242
+ ```bash
243
+ # Set SKILL_DIR (adjust based on actual installation path)
244
+ # Scenario A: Installed as .agents/skills
245
+ SKILL_DIR=".agents/skills/nexus-mapper"
246
+ # Scenario B: Independent repo (during development/debugging)
247
+ SKILL_DIR="/path/to/nexus-mapper"
248
+
249
+ # PROFILE phase — basic usage
250
+ python $SKILL_DIR/scripts/extract_ast.py <repo_path> [--max-nodes 500] \
251
+ --file-tree-out <repo_path>/.nexus-map/raw/file_tree.txt \
252
+ > <repo_path>/.nexus-map/raw/ast_nodes.json
253
+
254
+ # Add non-standard language support
255
+ python $SKILL_DIR/scripts/extract_ast.py <repo_path> [--max-nodes 500] \
256
+ --add-extension .templ=templ \
257
+ --add-query templ struct "(component_declaration name: (identifier) @class.name) @class.def" \
258
+ > <repo_path>/.nexus-map/raw/ast_nodes.json
259
+
260
+ # Complex configuration: use JSON config file
261
+ python $SKILL_DIR/scripts/extract_ast.py <repo_path> [--max-nodes 500] \
262
+ --language-config /custom/path/to/language-config.json \
263
+ > <repo_path>/.nexus-map/raw/ast_nodes.json
264
+ ```
265
+
266
+ **Dependency installation (first use)**:
267
+ ```bash
268
+ pip install -r $SKILL_DIR/scripts/requirements.txt
269
+ ```
270
+
271
+ ---
272
+
273
+ ## Persistent Memory Rules (write to host AGENTS.md)
274
+
275
+ Suggest writing following rules to repo's `AGENTS.md`, `CLAUDE.md` or similar persistent memory files, keeping knowledge base active in long-term conversations:
276
+
277
+ ```md
278
+ If .nexus-map/INDEX.md exists in repo, read it first, then read all files listed in its routing block before executing tasks.
279
+
280
+ If .nexus-map/ does not exist, and current task involves cross-module modification or interface changes, first propose running nexus-mapper to user; if user needs to start immediately, at least run query_graph.py --summary first to establish structure awareness.
281
+
282
+ When task changes project structure cognition (system boundaries, entry points, dependencies), evaluate before delivery whether need to update .nexus-map.
283
+ ```
284
+
285
+ ---
286
+
287
+ ## On-Demand Query Tools (PROBE auxiliary)
288
+
289
+ `scripts/query_graph.py` reads `raw/ast_nodes.json`, zero extra dependencies (pure Python standard library).
290
+
291
+ ```bash
292
+ python $SKILL_DIR/scripts/query_graph.py <ast_nodes.json> --file <path> # file skeleton
293
+ python $SKILL_DIR/scripts/query_graph.py <ast_nodes.json> --who-imports <mod> # reverse dependency
294
+ python $SKILL_DIR/scripts/query_graph.py <ast_nodes.json> --impact <path> # impact radius
295
+ python $SKILL_DIR/scripts/query_graph.py <ast_nodes.json> --impact <path> --git-stats <git_stats.json>
296
+ python $SKILL_DIR/scripts/query_graph.py <ast_nodes.json> --hub-analysis # core nodes
297
+ python $SKILL_DIR/scripts/query_graph.py <ast_nodes.json> --summary # directory aggregation
298
+ ```
299
+
300
+ | Phase | Recommended Query | Purpose |
301
+ | -------- | ---------------------- | ------------------------------------------------ |
302
+ | REASON | `--hub-analysis` | Data validate core system hypothesis, not guess by directory name |
303
+ | OBJECT | `--impact --git-stats` | Validate boundary hypothesis, view real upstream/downstream dependencies |
304
+ | EMIT | `--summary`, `--file` | Generate data support for systems.md / dependencies.md |
305
+
306
+ Core value of each query mode: `--hub-analysis` for validating architecture hypothesis in REASON phase; `--impact --git-stats` for quantifying boundary risk in OBJECT phase; `--summary` and `--file` for generating precise data support in EMIT phase.
@@ -0,0 +1,167 @@
1
+ # Adding Language Support for nexus-mapper
2
+
3
+ > This file is not a phase gate file. When built-in language coverage is insufficient, subsequent agents should prioritize referencing this file to supplement support via command line arguments; only use explicit JSON config file when configuration is complex.
4
+
5
+ ---
6
+
7
+ ## Goal
8
+
9
+ The default model of current scripts is:
10
+
11
+ 1. First use built-in extension mapping and built-in Tree-sitter query
12
+ 2. If built-in coverage insufficient, then agent supplements language support via command line
13
+ 3. If command line args too many or query too long, then fall back to `--language-config <JSON_FILE>`
14
+
15
+ This means:
16
+
17
+ - Does not require repo to have fixed path language config file
18
+ - Not recommended to modify core scripts for single repo single analysis
19
+ - New agent can directly plug additional languages into analysis flow in one command
20
+
21
+ ---
22
+
23
+ ## Preferred Approach: Command Line Supplement
24
+
25
+ ### Applicable Scenarios
26
+
27
+ Prioritize command line when following conditions met:
28
+
29
+ - Repo contains extensions not covered by built-in
30
+ - Only need to supplement 1-3 language mappings
31
+ - Query is short, suitable for inline in command line
32
+
33
+ ### Step 1: Confirm Language Name
34
+
35
+ First confirm language name recognizable by `tree-sitter-language-pack` or current environment. For example:
36
+
37
+ - `.templ` -> `templ`
38
+ - `.hbs` -> `handlebars`
39
+ - `.rego` -> `rego`
40
+
41
+ If language name uncertain, first check official grammar name; do not guess a language name and directly write into final conclusion.
42
+
43
+ ### Step 2: Supplement Extension Mapping
44
+
45
+ ```bash
46
+ python extract_ast.py <repo_path> \
47
+ --add-extension .templ=templ \
48
+ --add-extension .hbs=handlebars
49
+ ```
50
+
51
+ This brings originally unrecognized extensions into language dispatch flow.
52
+
53
+ ### Step 3: Supplement Query as Needed
54
+
55
+ If only Module-level coverage needed, can stop here.
56
+
57
+ If need class/function-level structure, continue appending `--add-query`:
58
+
59
+ ```bash
60
+ python extract_ast.py <repo_path> \
61
+ --add-extension .templ=templ \
62
+ --add-query templ struct "(component_declaration name: (identifier) @class.name) @class.def"
63
+ ```
64
+
65
+ Parameter format:
66
+
67
+ ```text
68
+ --add-query <LANG> <TYPE> <QUERY_STRING>
69
+ ```
70
+
71
+ Where:
72
+
73
+ - `<LANG>`: language name, e.g., `templ`
74
+ - `<TYPE>`: `struct` or `imports`
75
+ - `<QUERY_STRING>`: Tree-sitter query string
76
+
77
+ Capture naming must continue to follow existing convention:
78
+
79
+ - Class: `@class.def` / `@class.name`
80
+ - Function: `@func.def` / `@func.name`
81
+ - Import: `@mod`
82
+
83
+ ---
84
+
85
+ ## Alternative Approach: Explicit JSON Config File
86
+
87
+ When any of following holds, can use `--language-config`:
88
+
89
+ - Need to supplement multiple languages, command line already too long
90
+ - Query is complex, not suitable for inline in shell command
91
+ - Want to centrally save extension mapping and query needed for one analysis
92
+
93
+ Example:
94
+
95
+ ```json
96
+ {
97
+ "extensions": {
98
+ ".templ": "templ",
99
+ ".hbs": "handlebars"
100
+ },
101
+ "queries": {
102
+ "templ": {
103
+ "struct": "(component_declaration name: (identifier) @class.name) @class.def",
104
+ "imports": ""
105
+ }
106
+ },
107
+ "unsupported_extensions": {
108
+ ".legacydsl": "legacydsl"
109
+ }
110
+ }
111
+ ```
112
+
113
+ Execution method:
114
+
115
+ ```bash
116
+ python extract_ast.py <repo_path> --language-config /custom/path/to/language-config.json
117
+ ```
118
+
119
+ Explanation:
120
+
121
+ - `extensions`: extension to language name mapping
122
+ - `queries`: custom `struct` / `imports` query
123
+ - `unsupported_extensions`: explicitly declare extensions still not currently supported, avoid silent skip
124
+
125
+ This JSON file is explicit input for one analysis, does not require fixed placement in repo default location.
126
+
127
+ ---
128
+
129
+ ## Coverage Honesty Rules
130
+
131
+ Whether command line or explicit JSON, new languages must follow same layered standard:
132
+
133
+ 1. `structural coverage`
134
+ Condition: parser loadable, and `struct` query exists
135
+ 2. `module-only coverage`
136
+ Condition: parser loadable, but no `struct` query
137
+ 3. `configured-but-unavailable`
138
+ Condition: agent explicitly requested support for this language, but current environment cannot load parser
139
+ 4. `unsupported`
140
+ Condition: language still not included in this AST flow, or explicitly marked as unsupported
141
+
142
+ Prohibited:
143
+
144
+ - Write `configured-but-unavailable` as `module-only`
145
+ - Disguise `unsupported` as "not present in repo"
146
+
147
+ ---
148
+
149
+ ## Recommended Decision Order
150
+
151
+ When subsequent agent encounters an uncovered language, handle in following order:
152
+
153
+ 1. First confirm whether that extension file actually exists in current repo
154
+ 2. Then confirm whether current environment can load corresponding parser
155
+ 3. If loadable: prioritize `--add-extension`; supplement `--add-query` when need structure nodes
156
+ 4. If command too long: switch to `--language-config`
157
+ 5. If parser cannot load: keep `configured-but-unavailable`, do not fake results
158
+
159
+ ---
160
+
161
+ ## Design Principles
162
+
163
+ - Built-in languages first, command line supplement second, explicit JSON last
164
+ - For single analysis, prioritize minimum extra input, do not modify core scripts first
165
+ - Custom query is formal input, not bypass hack
166
+ - All new languages must follow same metadata and provenance rules
167
+