architext 0.0.2

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 (115) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/LICENSE +21 -0
  3. package/README.md +326 -0
  4. package/README.zh-CN.md +326 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +46 -0
  7. package/dist/templates/en/briefs/_base.md +115 -0
  8. package/dist/templates/en/briefs/_modules.md +173 -0
  9. package/dist/templates/en/docs/global/data_snapshot.json +31 -0
  10. package/dist/templates/en/docs/global/design_tokens.json +150 -0
  11. package/dist/templates/en/docs/global/dictionary.json +35 -0
  12. package/dist/templates/en/docs/global/error_codes.json +19 -0
  13. package/dist/templates/en/docs/global/map.json +94 -0
  14. package/dist/templates/en/docs/global/roadmap.json +39 -0
  15. package/dist/templates/en/docs/global/vision.md +82 -0
  16. package/dist/templates/en/docs/prompts/audit.md +150 -0
  17. package/dist/templates/en/docs/prompts/code.md +160 -0
  18. package/dist/templates/en/docs/prompts/edit.md +87 -0
  19. package/dist/templates/en/docs/prompts/fix.md +86 -0
  20. package/dist/templates/en/docs/prompts/help.md +69 -0
  21. package/dist/templates/en/docs/prompts/inherit.md +270 -0
  22. package/dist/templates/en/docs/prompts/map.md +131 -0
  23. package/dist/templates/en/docs/prompts/plan.md +252 -0
  24. package/dist/templates/en/docs/prompts/remove.md +162 -0
  25. package/dist/templates/en/docs/prompts/revise.md +160 -0
  26. package/dist/templates/en/docs/prompts/scope.md +198 -0
  27. package/dist/templates/en/docs/prompts/start.md +258 -0
  28. package/dist/templates/en/docs/templates/plan.template.json +113 -0
  29. package/dist/templates/en/docs/templates/scope-brief.template.md +58 -0
  30. package/dist/templates/en/docs/templates/spec.template.md +51 -0
  31. package/dist/templates/en/docs/templates/ui.template.md +51 -0
  32. package/dist/templates/en/rules/00_system.md +123 -0
  33. package/dist/templates/en/rules/01_workflow.md +93 -0
  34. package/dist/templates/en/rules/02_tech_stack.md +197 -0
  35. package/dist/templates/en/rules/03_data_governance.md +102 -0
  36. package/dist/templates/en/rules/04_cli_tools.md +50 -0
  37. package/dist/templates/en/rules/90_custom_rules.md +22 -0
  38. package/dist/templates/en/rules/99_context_glue.md +53 -0
  39. package/dist/templates/en/skills/archi-decompose-roadmap/SKILL.md +292 -0
  40. package/dist/templates/en/skills/archi-interview-protocol/SKILL.md +86 -0
  41. package/dist/templates/en/skills/archi-plan-options/SKILL.md +364 -0
  42. package/dist/templates/en/skills/archi-ui-wireframe/SKILL.md +342 -0
  43. package/dist/templates/zh/briefs/_base.md +116 -0
  44. package/dist/templates/zh/briefs/_modules.md +173 -0
  45. package/dist/templates/zh/docs/global/data_snapshot.json +31 -0
  46. package/dist/templates/zh/docs/global/design_tokens.json +135 -0
  47. package/dist/templates/zh/docs/global/dictionary.json +35 -0
  48. package/dist/templates/zh/docs/global/error_codes.json +19 -0
  49. package/dist/templates/zh/docs/global/map.json +94 -0
  50. package/dist/templates/zh/docs/global/roadmap.json +39 -0
  51. package/dist/templates/zh/docs/global/vision.md +82 -0
  52. package/dist/templates/zh/docs/prompts/audit.md +150 -0
  53. package/dist/templates/zh/docs/prompts/code.md +160 -0
  54. package/dist/templates/zh/docs/prompts/edit.md +87 -0
  55. package/dist/templates/zh/docs/prompts/fix.md +86 -0
  56. package/dist/templates/zh/docs/prompts/help.md +69 -0
  57. package/dist/templates/zh/docs/prompts/inherit.md +270 -0
  58. package/dist/templates/zh/docs/prompts/map.md +131 -0
  59. package/dist/templates/zh/docs/prompts/plan.md +253 -0
  60. package/dist/templates/zh/docs/prompts/remove.md +162 -0
  61. package/dist/templates/zh/docs/prompts/revise.md +160 -0
  62. package/dist/templates/zh/docs/prompts/scope.md +198 -0
  63. package/dist/templates/zh/docs/prompts/start.md +258 -0
  64. package/dist/templates/zh/docs/templates/plan.template.json +88 -0
  65. package/dist/templates/zh/docs/templates/scope-brief.template.md +58 -0
  66. package/dist/templates/zh/docs/templates/spec.template.md +51 -0
  67. package/dist/templates/zh/docs/templates/ui.template.md +51 -0
  68. package/dist/templates/zh/rules/00_system.md +123 -0
  69. package/dist/templates/zh/rules/01_workflow.md +93 -0
  70. package/dist/templates/zh/rules/02_tech_stack.md +192 -0
  71. package/dist/templates/zh/rules/03_data_governance.md +102 -0
  72. package/dist/templates/zh/rules/04_cli_tools.md +50 -0
  73. package/dist/templates/zh/rules/90_custom_rules.md +21 -0
  74. package/dist/templates/zh/rules/99_context_glue.md +53 -0
  75. package/dist/templates/zh/skills/archi-decompose-roadmap/SKILL.md +293 -0
  76. package/dist/templates/zh/skills/archi-interview-protocol/SKILL.md +86 -0
  77. package/dist/templates/zh/skills/archi-plan-options/SKILL.md +364 -0
  78. package/dist/templates/zh/skills/archi-ui-wireframe/SKILL.md +339 -0
  79. package/dist/templates/zh-Hant/briefs/_base.md +115 -0
  80. package/dist/templates/zh-Hant/briefs/_modules.md +173 -0
  81. package/dist/templates/zh-Hant/docs/global/data_snapshot.json +31 -0
  82. package/dist/templates/zh-Hant/docs/global/design_tokens.json +135 -0
  83. package/dist/templates/zh-Hant/docs/global/dictionary.json +35 -0
  84. package/dist/templates/zh-Hant/docs/global/error_codes.json +19 -0
  85. package/dist/templates/zh-Hant/docs/global/map.json +94 -0
  86. package/dist/templates/zh-Hant/docs/global/roadmap.json +39 -0
  87. package/dist/templates/zh-Hant/docs/global/vision.md +82 -0
  88. package/dist/templates/zh-Hant/docs/prompts/audit.md +150 -0
  89. package/dist/templates/zh-Hant/docs/prompts/code.md +160 -0
  90. package/dist/templates/zh-Hant/docs/prompts/edit.md +87 -0
  91. package/dist/templates/zh-Hant/docs/prompts/fix.md +86 -0
  92. package/dist/templates/zh-Hant/docs/prompts/help.md +69 -0
  93. package/dist/templates/zh-Hant/docs/prompts/inherit.md +270 -0
  94. package/dist/templates/zh-Hant/docs/prompts/map.md +131 -0
  95. package/dist/templates/zh-Hant/docs/prompts/plan.md +252 -0
  96. package/dist/templates/zh-Hant/docs/prompts/remove.md +162 -0
  97. package/dist/templates/zh-Hant/docs/prompts/revise.md +160 -0
  98. package/dist/templates/zh-Hant/docs/prompts/scope.md +198 -0
  99. package/dist/templates/zh-Hant/docs/prompts/start.md +258 -0
  100. package/dist/templates/zh-Hant/docs/templates/plan.template.json +88 -0
  101. package/dist/templates/zh-Hant/docs/templates/scope-brief.template.md +58 -0
  102. package/dist/templates/zh-Hant/docs/templates/spec.template.md +51 -0
  103. package/dist/templates/zh-Hant/docs/templates/ui.template.md +51 -0
  104. package/dist/templates/zh-Hant/rules/00_system.md +123 -0
  105. package/dist/templates/zh-Hant/rules/01_workflow.md +93 -0
  106. package/dist/templates/zh-Hant/rules/02_tech_stack.md +192 -0
  107. package/dist/templates/zh-Hant/rules/03_data_governance.md +102 -0
  108. package/dist/templates/zh-Hant/rules/04_cli_tools.md +50 -0
  109. package/dist/templates/zh-Hant/rules/90_custom_rules.md +21 -0
  110. package/dist/templates/zh-Hant/rules/99_context_glue.md +53 -0
  111. package/dist/templates/zh-Hant/skills/archi-decompose-roadmap/SKILL.md +293 -0
  112. package/dist/templates/zh-Hant/skills/archi-interview-protocol/SKILL.md +86 -0
  113. package/dist/templates/zh-Hant/skills/archi-plan-options/SKILL.md +364 -0
  114. package/dist/templates/zh-Hant/skills/archi-ui-wireframe/SKILL.md +337 -0
  115. package/package.json +85 -0
@@ -0,0 +1,270 @@
1
+ <protocol_inherit>
2
+ **Trigger**: `/archi.inherit`
3
+ **Phase**: Legacy Adoption
4
+ **Goal**: Reverse-engineer an existing codebase to generate the Architext document skeleton, bringing the project under framework governance.
5
+
6
+ <meta>
7
+ <style>Analytical, Systematic, Evidence-Based</style>
8
+ <language>English</language>
9
+ <principles>
10
+ 1. **Code-Driven**: Code is the sole source of truth; do not speculate on tasks without evidence.
11
+ 2. **AI-Native Perspective**: All analysis from AI Agent perspective. Focus: Context Locality, Type Safety, Module Boundaries.
12
+ 3. **User Agency First**: AI analysis must be confirmed by the user. When code interpretation is ambiguous, ask the user; do not decide unilaterally.
13
+ 4. **Minimal Token**: Prioritize config files and entry points; avoid scanning every line of code.
14
+ 5. **Option Z Everywhere**: Supplementary questions must include `[Z] Custom`.
15
+ </principles>
16
+ </meta>
17
+
18
+ <step_0_recon>
19
+ **Role**: Intelligence Analyst
20
+ **Action**:
21
+ 1. Read project root config files (auto-detect type):
22
+
23
+ | Language/Ecosystem | Config Files |
24
+ |:---|:---|
25
+ | Node.js | package.json, tsconfig.json |
26
+ | Rust | Cargo.toml |
27
+ | Go | go.mod |
28
+ | Python | pyproject.toml, requirements.txt |
29
+ | Java | pom.xml, build.gradle |
30
+ | Other | Use root directory config files |
31
+
32
+ 2. Read README.md (if exists).
33
+ 3. Scan directory structure (top-level + core source directories, two levels deep).
34
+ 4. Infer project feature tags (UI / Data / CLI / Lib / API — from directory structure, dependencies, and config).
35
+ 5. Identify entry points and core modules.
36
+
37
+ **Output**: Internal summary (not shown to user), proceed to step_1.
38
+ </step_0_recon>
39
+
40
+ <step_1_analysis>
41
+ **Role**: System Analyst
42
+ **Scan Strategy**: Medium-depth scan — read each module's entry file and core business files, extract main flow chains. Do not traverse every file.
43
+
44
+ **Action**:
45
+ 1. For each identified functional module:
46
+ - Read entry file + 1-2 core business files
47
+ - Extract main flows (user action → system processing → result)
48
+ - Record associated file paths
49
+ 2. For shared/infrastructure code (utils, middleware, config):
50
+ - Record directory and responsibility only; do not treat as functional modules
51
+ 3. Extract domain terminology and naming conventions from code.
52
+
53
+ **Output**: Present structured analysis report to user:
54
+ ```
55
+ ### Codebase Analysis Report
56
+ > **Project**: [Name] | **Type**: [UI/Data/CLI/Lib/API] | **Scale**: ~[file count] files, [dir count] directories
57
+
58
+ **Tech Stack**:
59
+ | Category | Selection |
60
+ |:---|:---|
61
+ | Language | ... |
62
+ | Framework | ... |
63
+ | Build | ... |
64
+ | Testing | ... |
65
+ | Deployment | ... |
66
+
67
+ **Architecture Pattern**: [Inference] — [Evidence]
68
+
69
+ **Functional Module Inventory**:
70
+ | # | Module | Source Location | Responsibility | Key Flows |
71
+ |:---|:---|:---|:---|:---|
72
+ | 1 | [Name] | [Path] | [One sentence] | [Flow1], [Flow2] |
73
+
74
+ **Shared Infrastructure**:
75
+ | Directory | Responsibility |
76
+ |:---|:---|
77
+ | [Path] | [Description] |
78
+
79
+ **Domain Terminology**: [Term list]
80
+
81
+ **Uncertain Items** (if any):
82
+ - [Ambiguous item]
83
+ ```
84
+
85
+ **Gate**: User confirms or corrects. Do not proceed to step_2 without confirmation.
86
+ </step_1_analysis>
87
+
88
+ <step_2_supplementary>
89
+ **Role**: Product Consultant
90
+ **Trigger**: Only when step_1 has items AI cannot determine. Skip if no ambiguity.
91
+
92
+ **Action**: Ask ambiguous items in multiple-choice format.
93
+ - 3-5 options per question + `[Z] Custom`; AI recommendation marked `[Recommended]`.
94
+ - Total questions capped at 3.
95
+
96
+ Common ambiguities:
97
+ - Architecture pattern cannot be confirmed
98
+ - Certain directory responsibilities unclear
99
+ - Vision info (North Star Metric, design philosophy) cannot be inferred from code
100
+
101
+ **Output Format**:
102
+ ```
103
+ ### Supplementary Confirmation
104
+
105
+ **[Q1] Question Title**
106
+ > Why this information is needed
107
+
108
+ | ID | Option | Description |
109
+ |:---|:---|:---|
110
+ | A [Recommended] | ... | ... |
111
+ | B | ... | ... |
112
+ | Z | Custom | (Please describe) |
113
+
114
+ ---
115
+ **INPUT**: `Q1 answer | Q2 answer | ...`
116
+ ```
117
+ </step_2_supplementary>
118
+
119
+ <step_3_constitution>
120
+ **Role**: Chief Architect
121
+ **Input**: Step 1 analysis report + Step 2 supplements (if any).
122
+ **Action**: Generate project document skeleton in one pass.
123
+
124
+ ### Information Routing Rules
125
+
126
+ > Rule files (`02_tech_stack`, `90_custom_rules`, etc.) are already injected into context by the IDE — the AI knows their paths; write directly.
127
+
128
+ | Information from Code | Target File |
129
+ |:---|:---|
130
+ | README project description, target users, task list | `[[__DOCS_DIR__]]/global/vision.md` |
131
+ | Dependency list, config files, code patterns | rule file `02_tech_stack` |
132
+ | Directory structure, module dependencies, user journeys | `[[__DOCS_DIR__]]/global/map.json` |
133
+ | Domain terminology, abbreviations, naming conventions | `[[__DOCS_DIR__]]/global/dictionary.json` |
134
+ | eslint/prettier and existing standards | rule file `90_custom_rules` |
135
+ | Error code definitions in code | `[[__DOCS_DIR__]]/global/error_codes.json` |
136
+ | [?UI] CSS variables/theme config | `[[__DOCS_DIR__]]/global/design_tokens.json` |
137
+ | [?Data] Schema/Migration files | `[[__DOCS_DIR__]]/global/data_snapshot.json` |
138
+
139
+ ### 3.1 Vision (`[[__DOCS_DIR__]]/global/vision.md`)
140
+ - Derive from README + project config
141
+ - Items that cannot be derived: mark `(AI Inferred — user review recommended)`
142
+ - Do not retain template placeholders
143
+
144
+ ### 3.2 Tech Stack (rule file `02_tech_stack`)
145
+ - Existing dependencies/config → write directly
146
+ - Visible code conventions (naming, structure) → write to Coding Standards
147
+ - Must populate complete Section 1-8
148
+
149
+ ### 3.3 Custom Rules (rule file `90_custom_rules`)
150
+ - Extract rules from eslint/prettier/editorconfig
151
+ - Identify team conventions from code patterns (e.g., named export preference, async/await style)
152
+
153
+ ### 3.4 Roadmap (`[[__DOCS_DIR__]]/global/roadmap.json`)
154
+
155
+ **Structure**:
156
+ ```json
157
+ {
158
+ "version": 1,
159
+ "projectStatus": "active",
160
+ "lastUpdated": "<date>",
161
+ "phases": [
162
+ {
163
+ "id": "phase-0",
164
+ "name": "Legacy",
165
+ "tasks": [
166
+ {
167
+ "id": "LEG-01",
168
+ "title": "<Module Name>",
169
+ "status": "done",
170
+ "goal": "<One-line summary>. See tasks/LEG-01_<Slug>/spec.md",
171
+ "deps": [],
172
+ "tag": "Legacy",
173
+ "slug": "<Slug>"
174
+ }
175
+ ]
176
+ },
177
+ { "id": "phase-1", "name": "Infrastructure", "tasks": [] },
178
+ { "id": "phase-2", "name": "Core Features", "tasks": [] }
179
+ ]
180
+ }
181
+ ```
182
+
183
+ **Rules**:
184
+ - Functional modules → `phase-0: Legacy`, status `done`, tag `Legacy`, ID prefix `LEG-`
185
+ - Shared/infrastructure code does not enter roadmap; only goes to map.json directoryMapping
186
+ - phase-1/2 remain as empty skeletons
187
+ - Dependencies between LEG tasks must be reflected in deps
188
+
189
+ ### 3.5 Task Stub Specs
190
+
191
+ Create `[[__DOCS_DIR__]]/tasks/LEG-xx_<Slug>/spec.md` for each LEG task:
192
+
193
+ ```markdown
194
+ # LEG-xx: [Title]
195
+
196
+ > **Spec-Status**: Stub
197
+ > **Source**: Reverse-engineered from [source path]
198
+
199
+ ## Overview
200
+ [One paragraph description]
201
+
202
+ ## Key Flows
203
+ 1. **[Flow Name]**: [A] → [B] → [C]
204
+ 2. **[Flow Name]**: [A] → [B] → [C]
205
+
206
+ ## Associated Files
207
+ - [Role]: `[Path]`
208
+ - [Role]: `[Path]`
209
+ ```
210
+
211
+ > Stubs are a starting point, not the final state. Enrich later via `/archi.edit` (auto-triggers the `step_1_5_enrich` flow).
212
+
213
+ ### 3.6 map.json Population
214
+ - `directoryMapping`: Each core directory → `{ "path", "layer", "responsibility", "publicAPI" }`
215
+ - `logicalTopology`: Inter-module dependencies → `{ "from", "to", "type" }` (imports / calls / extends)
216
+ - `criticalUserJourneys`: Core flows → `{ "name", "steps": ["module → module → ..."] }`
217
+ - `featureRelations`: Scan code to identify "aggregator modules" and record them.
218
+ **Recognition patterns**: A module that iterates/enumerates/dynamically loads modules of the same type (e.g., `for (const cmd of allCommands)`, `Object.values(registry)`, reading a directory then dynamic import), or is described as "aggregating/listing/registering all X".
219
+ Record format: `{ "aggregator": "<ID or file path>", "sources": "<source range description>", "evidence": "<code basis>", "checkNote": "When tasks of this type are added or removed, check whether <aggregator> needs to be updated" }`
220
+
221
+ ### 3.7 Other Global Documents (as needed)
222
+ - `dictionary.json`: Extract domain terminology from code
223
+ - [?UI] `design_tokens.json`: Extract from CSS variables/theme
224
+ - [?UI] `ui_concept.html` + `ui_context.md`: **Not generated by this command.** After inherit completes, prompt the user to run the `archi-ui-wireframe` Skill to generate the global UI wireframe (Skill generates both files simultaneously).
225
+ - [?Data] `data_snapshot.json`: Extract from schema/migration
226
+ - `error_codes.json`: Extract from error definitions in code
227
+
228
+ **Output**: Write all files, then run `npx archi render`.
229
+ </step_3_constitution>
230
+
231
+ <step_4_audit>
232
+ **Role**: Chief Auditor
233
+ **Checklist**:
234
+ 1. **Vision Alignment**: Does vision.md match actual code functionality?
235
+ 2. **Tech Stack Consistency**: Does rule file `02_tech_stack` match package.json/config?
236
+ 3. **Map Coverage**: Does map.json cover all core directories?
237
+ 4. **Roadmap Completeness**: Does phase-0 cover all identified functional modules?
238
+ 5. **Stub Completeness**: Does every LEG-xx have a corresponding tasks/ directory and spec.md?
239
+ 6. **Dictionary Consistency**: No ambiguous or duplicate terms?
240
+
241
+ Silently fix issues; mark severe problems as `Risk Warning`.
242
+ </step_4_audit>
243
+
244
+ <step_5_signoff>
245
+ **Terminal Gate** (Do not skip; must complete before output summary):
246
+ | Step | Command | Pass Condition |
247
+ |:---|:---|:---|
248
+ | 1 | `npx archi task --check` | No ERROR-level issues |
249
+ | 2 | `npx archi render` | `.md` views generated |
250
+
251
+ **Action** (After Gate passes):
252
+ 1. Run `npx archi task` to display task overview.
253
+ 2. Output summary.
254
+
255
+ **Output**: Reverse-engineering summary containing:
256
+ - **Project Overview**: Type, scale, number of core modules
257
+ - **Legacy Tasks**: LEG-xx list (ID / Name / Source location)
258
+ - **Generated Documents**: File list
259
+ - **AI Inferred Items**: Mark confidence level (High/Medium/Low)
260
+ - **Next Steps**:
261
+
262
+ | Priority | Action | Description |
263
+ |:---|:---|:---|
264
+ | 1 | Review vision.md | Confirm AI-inferred vision description is accurate |
265
+ | 2 | `/archi.edit LEG-xx` | Enrich core module stubs into full specs (auto-triggers Enrich flow) |
266
+ | 3 | `/archi.scope [file_path]` | Plan new tasks/major modules |
267
+ | 4 | `/archi.plan <task ID>` | Deep-plan individual tasks |
268
+ </step_5_signoff>
269
+
270
+ </protocol_inherit>
@@ -0,0 +1,131 @@
1
+ <protocol_map>
2
+ **Trigger**: `/archi.map`
3
+ **Goal**: Scan actual project directory structure, diff against `map.json`, identify additions/stale/changes, and update the architecture map after user confirmation.
4
+
5
+ <meta>
6
+ <style>Systematic, Precise, Architecture-Aware</style>
7
+ <language>English</language>
8
+ <principles>
9
+ 1. **Scan vs Map**: Actual filesystem is Ground Truth; map.json is the old snapshot.
10
+ 2. **Smart Granularity**: Directory-level by default; drill to file-level when a single file carries multiple responsibilities.
11
+ 3. **Architecture Inference**: New entry classification must reference existing map patterns + `02_tech_stack.md`.
12
+ 4. **Batch Confirm**: Present all changes at once; user confirms in batch.
13
+ </principles>
14
+ </meta>
15
+
16
+ <step_1_scan>
17
+ **Role**: Surveyor
18
+ **Action**:
19
+ 1. **Read Map**: Read `[[__DOCS_DIR__]]/global/map.json` — current architecture map.
20
+ 2. **Read Tech Stack**: Read `02_tech_stack.md` — directory conventions, architecture patterns.
21
+ 3. **Scan Directory Tree**: Scan project directory structure.
22
+ - **Exclude**: `.git/`, `node_modules/`, `dist/`, `build/`, `[[__DOCS_DIR__]]/`, and paths declared in `.gitignore`.
23
+ - **Depth**: Follow granularity patterns of existing map.json entries. If existing entries include file-level → scan to file-level too.
24
+
25
+ **Output**: Internal data (actual tree + existing map structure), not shown to user.
26
+ </step_1_scan>
27
+
28
+ <step_2_diff>
29
+ **Role**: Diff Analyst
30
+ **Action**: Compare actual directory tree against map.json entry by entry, classify into three diff types.
31
+
32
+ | Diff Type | Criteria | Handling |
33
+ |:---|:---|:---|
34
+ | **New** | Exists on disk but not in map | Classify and register |
35
+ | **Stale** | In map but no longer exists on disk | Remove directly |
36
+ | **Possible Rename** | Map path missing, but a new path has highly similar structure/content | Flag as rename candidate |
37
+
38
+ ### File-Level Detection
39
+
40
+ Quick-scan files in new directories (read exports/declarations) to identify **single-file multi-responsibility** cases:
41
+ - A file exporting multiple unrelated classes/functions/modules
42
+ - An entry file aggregating multiple sub-module registrations (e.g. route registration, store registration)
43
+ - A file serving multiple Tasks
44
+
45
+ When detected → drill granularity to file-level, register the file separately in map with its contained responsibilities.
46
+
47
+ **Output**: Diff list (internal), proceed to step_3.
48
+ </step_2_diff>
49
+
50
+ <step_3_classify>
51
+ **Role**: Chief Architect
52
+ **Action**: Classify new entries by architectural layer.
53
+
54
+ ### Classification Strategy
55
+
56
+ 1. **Pattern Matching**: Reference existing entries at the same level. If `src/services/auth/` is "Service Layer", then `src/services/payment/` likely is too.
57
+ 2. **Tech Stack Conventions**: Directory structure rules defined in `02_tech_stack.md` (e.g. "commands/ is Task Layer").
58
+ 3. **Content Inference**: Read file contents (imports, export types) to determine architectural role.
59
+ 4. **Uncertain**: Mark as `[?]`, let user specify during confirmation.
60
+
61
+ For each new entry, populate:
62
+ - `path`: Directory or file path
63
+ - `layer`: Architectural layer
64
+ - `description`: One-line responsibility description
65
+ - `[?file-level]` `contains`: List of sub-responsibilities in the file
66
+
67
+ **Output**: Classified new entries list (internal), proceed to step_4.
68
+ </step_3_classify>
69
+
70
+ <step_4_propose>
71
+ **Role**: Advisor
72
+ **Action**: Present the full change manifest to user.
73
+
74
+ **Output**:
75
+ ```
76
+ ### Architecture Map Change Proposal
77
+
78
+ **Scan scope**: [project root]
79
+ **Current map entries**: N | **After update**: M
80
+
81
+ ---
82
+
83
+ #### Stale Entries (will remove)
84
+ | Path | Original Layer |
85
+ |:---|:---|
86
+ | src/legacy/old-module/ | Service Layer |
87
+
88
+ #### New Entries (will register)
89
+ | Path | Layer | Description | Granularity |
90
+ |:---|:---|:---|:---|
91
+ | src/services/payment/ | Service Layer | Payment service module | Directory |
92
+ | src/utils/validators.ts | Shared Layer | Form + data + API param validation | File |
93
+ | src/routes/api.ts [?] | [to specify] | Aggregates multiple API route registrations | File |
94
+
95
+ #### Possible Renames
96
+ | Original Path | New Path | Confidence |
97
+ |:---|:---|:---|
98
+ | src/helpers/ | src/utils/ | High (file content match) |
99
+
100
+ ---
101
+ > Reply **OK** to confirm all; or specify changes:
102
+ > - "src/routes/api.ts belongs to App Layer"
103
+ > - "src/helpers/ is not a rename, keep original entry"
104
+ > - "add src/config/ as Config Layer"
105
+ ```
106
+
107
+ **Gate**: Proceed to step_5 after user confirms.
108
+ </step_4_propose>
109
+
110
+ <step_5_apply>
111
+ **Role**: System Administrator
112
+ **Action**:
113
+ 1. Update `[[__DOCS_DIR__]]/global/map.json` per confirmed changes:
114
+ - Remove stale entries
115
+ - Add new entries (with layer, description)
116
+ - Handle renames (update path, preserve other metadata)
117
+ 2. Update `lastUpdated` field.
118
+
119
+ **Terminal Gate** (Do not skip; must complete before output summary):
120
+ | Step | Command | Pass Condition |
121
+ |:---|:---|:---|
122
+ | 1 | `npx archi render` | `.md` views generated |
123
+
124
+ **Output**: Update summary:
125
+ - **Removed**: N stale entries
126
+ - **Added**: N entries (M file-level)
127
+ - **Renamed**: N entries
128
+ - **Current map total**: X entries
129
+ </step_5_apply>
130
+
131
+ </protocol_map>
@@ -0,0 +1,252 @@
1
+ <protocol_plan>
2
+ **Trigger**: `/archi.plan <ID> [context]`
3
+ **Goal**: Define Task Spec/UI/Plan through deep architecture interview.
4
+ **Input**:
5
+ - `<ID>` (required): An existing task ID from the Roadmap. Tasks must be created first via `/archi.scope` or `/archi.inherit`.
6
+ - `[context]` (optional): Known context for the task (e.g., requirement descriptions, references, constraints). When provided, serves as pre-loaded input for step_2 interview, reducing questions.
7
+
8
+ <constraints_cursor>
9
+ **Mode Lock**: This protocol MUST execute in **Agent Mode (Normal Mode)**. Prohibited from switching to Plan Mode or any read-only mode.
10
+ </constraints_cursor>
11
+
12
+ <meta>
13
+ <style>Architectural, Exhaustive, Strict, Technology-Agnostic</style>
14
+ <language>English</language>
15
+ <principles>
16
+ 1. **Global First**: The birth of local tasks must be accompanied by updates to global indices (Map/Data/Dict).
17
+ 2. **AI-Native Perspective**: All option Pros/Cons written from AI Agent perspective. Focus: Context Locality, Type Safety, Boilerplate, Ambiguity.
18
+ 3. **Flexible Interaction**: Options are heuristic suggestions; support multi-select, hybrid, or custom.
19
+ 4. **Audit-Gated**: Only audited docs can be delivered.
20
+ </principles>
21
+ </meta>
22
+
23
+ <step_1_load>
24
+ **Role**: System Analyst
25
+ **Action**:
26
+ 1. **Read Roadmap**: Read `[[__DOCS_DIR__]]/global/roadmap.json`.
27
+ - **Pre-flight**: Read only the `<ID>` task entry and its direct deps' `id/title/status`; check whether deps are completed, reject Plan if not (unless user forces). No need to load other task data.
28
+ 2. **Read Vision**: Read `[[__DOCS_DIR__]]/global/vision.md` — extract North Star Metric and Design Philosophy sections only; skip remaining chapters.
29
+ 3. **Read Tech Stack**: `02_tech_stack.md` (technical red lines + **Section 9 Project Conventions**).
30
+ - Extract global architecture conventions from Section 9 (Error Handling / Data Flow / Auth & Access) for convention inheritance in step_2.
31
+ 4. [?UI] **Read Design Tokens**: `[[__DOCS_DIR__]]/global/design_tokens.json`.
32
+ 4.5 [?UI] **Read UI Context**: `[[__DOCS_DIR__]]/global/ui_context.md` (if it exists).
33
+ - Look up the screen inventory to locate the screen IDs (e.g. S-03) for this task and their state coverage.
34
+ - Lock the screen scope to fill in `ui.md §1` in step_4; do not invent new screen IDs.
35
+ - If `ui_context.md` does not exist → skip; write `ui.md` in full ITP format.
36
+ 5. [?Data] **Read Data Model**: `[[__DOCS_DIR__]]/global/data_snapshot.json`.
37
+ 6. **Read Dependency Context** (if dependent tasks exist):
38
+ - Read only the Interface/Type definitions section of the dep's `spec.md` (`## Interface` or `## Types` chapter); skip Scenarios and other content.
39
+ - Execute only when a `ref: tasks/<dep_id>/spec.md#X` reference appears in the current spec/plan; skip if no reference found.
40
+ - **Stub Compatibility**: If a dependency's Spec-Status is Stub, extract source files from the stub's "Associated Files", read entry files to extract public interfaces/exported types as upstream interface reference.
41
+ - Avoid re-defining upstream interfaces; ensure integration points are precisely aligned.
42
+
43
+ **Output**: Present a **Task Context Brief** to the user:
44
+ ```
45
+ ### Task Context: [Task Name] ([ID])
46
+
47
+ **Goal**: [roadmap task's goal; highlight any [User Presets] if present]
48
+ **Upstream Dependencies**: [completed dependency tasks and their key interfaces/types, or "None"]
49
+ **Project Features**: [activated UI/Data/CLI/Lib/API tags]
50
+ **Technical Constraints**: [key red lines from 02_tech_stack.md]
51
+ **Design Philosophy**: [North Star Metric and design principles from vision.md]
52
+ **Project Conventions**: [from 02_tech_stack.md §9 — Error Handling: X | Data Flow: X | Auth: X, or "Not set" if absent]
53
+ ```
54
+ Retain full context materials internally, proceed to step_2.
55
+ </step_1_load>
56
+
57
+ <step_1_5_complexity>
58
+ **Role**: Product Consultant
59
+ **Action**: Assess task complexity to decide whether to run the full step_2 flow:
60
+
61
+ **① Granularity hard-limit check (before complexity verdict)**:
62
+
63
+ | Metric | Limit |
64
+ |:---|:---|
65
+ | Estimated spec.md Scenario count | ≤ 6 |
66
+ | Estimated plan.json Phase count | ≤ 4 |
67
+
68
+ > Estimation method: based on the roadmap task goal and dependency context loaded in step_1, quickly enumerate the core behavior paths. Trigger if over the limit — no need for precise calculation.
69
+
70
+ **② Complexity verdict (only after granularity passes)**:
71
+
72
+ | Signal | Verdict | Flow |
73
+ |:---|:---|:---|
74
+ | No deps + no new entities + no architecture decisions + estimated ≤3 tasks | **Simple** | Skip step_2 interview; generate spec + plan directly |
75
+ | Has deps OR new entities OR architecture decisions needed | **Standard** | Execute step_2 Unified Proposal normally |
76
+
77
+ **Simple Mode**:
78
+ - Skip 5-dimension architecture recommendations and User Confirm Gate
79
+ - spec condensed to 1-2 Gherkin scenarios
80
+ - plan condensed to a single Phase
81
+ - Confirm at signoff (replacing step_2 Gate)
82
+ </step_1_5_complexity>
83
+
84
+ <step_2_interview>
85
+ **Role**: Architect
86
+
87
+ ---
88
+
89
+ ### Unified Proposal
90
+
91
+ **Core principle**: Merge task design and architecture decisions into **one single output**; user confirms or overrides in one round.
92
+
93
+ **Action**:
94
+
95
+ #### Part 1: Task Design
96
+
97
+ AI **selects which modules to output** based on the task's nature, from the following material library:
98
+
99
+ | Material | When applicable |
100
+ |:---|:---|
101
+ | Flow description (user journey / system flow / command flow) | Multi-step interaction or processing chain |
102
+ | Core entities & data | New or modified entities involved; existing entities use `→ ref: data_snapshot.json#EntityName` |
103
+ | Touchpoints (pages / commands / endpoints / methods) | User-facing or external interfaces exist |
104
+ | Pre-defined decisions | When goal contains `[User Preset]` → highlight and enforce strictly |
105
+
106
+ **Reference rules**:
107
+ - Entities/types already in global → `ref: data_snapshot.json#X`, only describe what this task **adds or modifies**
108
+ - Design philosophy/principles → `ref: vision.md#PrincipleName`, no need to restate
109
+ - Upstream interfaces → `ref: tasks/<dep_ID>/spec.md#InterfaceName`
110
+ - Existing design tokens/components → `ref: design_tokens.json#preset` / `ref: dictionary.json#component`
111
+
112
+ **Universal requirement**: Use this task's specific entity names and operation names; no generic descriptions
113
+
114
+
115
+ #### Part 2: Architecture Recommendations
116
+
117
+ [[SKILL: Follow `archi-plan-options` Skill's three-step selection logic (Convention Inheritance -> Tag Routing -> Recommend vs. Expand) to generate architecture recommendations across five dimensions.]][[NO-SKILL: (Skill not installed: read `[[__DOCS_DIR__]]/skills/archi-plan-options/SKILL.md` and follow its three-step logic)]]
118
+
119
+ When expanding a Q-table, follow the format in [[SKILL: `archi-interview-protocol` Skill's standard output format]][[NO-SKILL: `[[__DOCS_DIR__]]/skills/archi-interview-protocol/SKILL.md`]].
120
+
121
+ #### Output Format
122
+
123
+ ```
124
+ ## Task Proposal: [Task Name] ([ID])
125
+
126
+ ### Task Design
127
+ [Output per complexity level, see Part 1 above]
128
+
129
+ ### Architecture Recommendations
130
+ | Dimension | Recommended | Source | Rationale |
131
+ |:---|:---|:---|:---|
132
+ | Core Structure | [Recommended option] | Task | [1-2 sentences specific to this task] |
133
+ | Interaction Pattern | [Recommended option] | Task | [Rationale] |
134
+ | Error Handling | [Convention value] | Project Convention | ref: 02_tech_stack.md §9 |
135
+ | ... | ... | ... | ... |
136
+
137
+ [Only expand option table for dimensions requiring user decision]:
138
+ **[Q<n>] Question title**
139
+ > Why user decision is needed (one sentence)
140
+
141
+ | ID | Option | Description | AI+ | AI- |
142
+ |:---|:---|:---|:---|:---|
143
+ | A [Recommended] | ... | Concrete behavior (2-3 sentences) | Full sentence | Full sentence |
144
+ | B | ... | ... | ... | ... |
145
+ | Z | Custom | (Describe) | - | - |
146
+
147
+ ---
148
+ > Reply **OK** to accept all recommendations; or annotate what to change, e.g.:
149
+ > - Design correction: "Registration doesn't need email verification step"
150
+ > - Dimension override: "Core Structure=C, Error Handling=B D"
151
+ > - Question answer: "Q1=B"
152
+ ```
153
+
154
+ **⌨️ INPUT**: Reply **OK** to accept all; or free-text annotations for changes. No fixed format required.
155
+ </step_2_interview>
156
+
157
+ <step_2_5_refinement>
158
+ **Role**: Consultant
159
+ **Trigger**: User reply is not OK — contains corrections, questions, overrides, or logic conflicts.
160
+ **Action**: Do NOT generate docs. Incorporate user feedback, refresh Unified Proposal and re-output. Wait for confirmation.
161
+ - If task design question → Compare alternatives, re-propose design
162
+ - If architecture dimension question → Explain differences in this task's context, update recommendation
163
+ - If dimension override → Replace recommendation directly and adjust related design
164
+ </step_2_5_refinement>
165
+
166
+ <step_3_global_sync>
167
+ **Role**: System Admin
168
+ **Constraint**: MUST update the following global files **BEFORE** generating Task docs.
169
+
170
+ **Boundary**: Only register **project business domain** content. Architext framework concepts (scripts, scaffold, roadmap, plan, etc.) and framework infrastructure errors are prohibited from registration in global files.
171
+
172
+ **Action Checklist**:
173
+ 1. **`map.json`**: Register `[[__DOCS_DIR__]]/tasks/<ID>_<Slug>` in `directoryMapping`; define module responsibility and dependencies in `logicalTopology`.
174
+ 2. **`dictionary.json`**: Extract **project business** new terms from the proposal to fill `entities`/`verbs`; register new shared tools to `utilities`; register new public components to `components`.
175
+ 3. [?Data] **`data_snapshot.json`**: Add/modify Schema based on Core Structure recommendation. Prohibited from writing "TBD"; must write field names and types.
176
+ 4. **`error_codes.json`**: Register new **business** error codes based on Error Handling recommendation. Framework script errors are handled by exit code + stderr; prohibited from registration.
177
+ 5. **`map.json` featureRelations**: Determine if this task is an "aggregator" — i.e., its core responsibility is to **list, summarize, or dynamically reflect** a class of other tasks (e.g., "list all commands", "aggregate all page entries", "register all routes"). If yes, append one record to `featureRelations`:
178
+ ```json
179
+ {
180
+ "aggregator": "<this task ID or file path>",
181
+ "sources": "<one-sentence description of what is aggregated, e.g. 'all CLI command tasks'>",
182
+ "evidence": "<basis, e.g. 'spec.md §X states this task dynamically lists all Y-type tasks'>",
183
+ "checkNote": "When tasks of this type are added or removed, check whether <aggregator> needs to be updated"
184
+ }
185
+ ```
186
+ If not an aggregator, skip this step.
187
+
188
+ **Output**: Change diffs of above files (brief).
189
+ </step_3_global_sync>
190
+
191
+ <step_4_generate>
192
+ **Role**: Doc Engineer
193
+ **Input**: Confirmed Unified Proposal (task design + architecture recommendations) + updated global context.
194
+ **Action**: Generate standard docs under `[[__DOCS_DIR__]]/tasks/<ID>_<Slug>/`.
195
+
196
+ **1. `spec.md`** (Mandatory):
197
+ - Template: `templates/spec.template.md`.
198
+ - Convert confirmed task design and architecture recommendations to Gherkin Scenarios.
199
+ - Each Scenario must map to a concrete flow step or exception path from the task design; do not invent scenarios.
200
+ - If upstream task, must include explicit Interface/Type definitions.
201
+
202
+ **2. `ui.md`** [?UI]:
203
+ - Template: `templates/ui.template.md`.
204
+ - **With `ui_context.md` (primary path)**:
205
+ 1. **UI Divergence Check** (required before writing `ui.md`): Compare the confirmed task design from step_2 against the screen inventory in `ui_context.md`:
206
+
207
+ | Divergence type | Criteria | Action |
208
+ |:---|:---|:---|
209
+ | No divergence | Screen index matches design | Write `ui.md` directly, reference screen ID |
210
+ | Minor addition | New state / modal / local area, overall layout unchanged | Call `archi-ui-wireframe` Skill (Plan refinement mode) to update `ui_concept.html` + `ui_context.md`; note `MODIFIED: S-XX` in `ui.md` |
211
+ | Structural divergence | Layout restructure, new standalone screen, flow path change | **Pause** — present divergence summary to user, wait for **OK**, then call Skill to update `ui_concept.html` + `ui_context.md`, then write `ui.md` |
212
+
213
+ 2. After resolving divergence, fill in screen scope and delta components per `ui.template.md`.
214
+ - **Without `ui_context.md` (fallback path)**: Write full ITP v3.0 component tree, referencing `design_tokens.json` token definitions.
215
+
216
+ **3. `plan.json`** (Mandatory):
217
+ - Template: `templates/plan.template.json`.
218
+ - Dynamically adjust Phases by project type; ensure each Task's context is self-contained.
219
+ - Task descriptions explicitly state "Additive Only" + "Respect Unknowns".
220
+ - **`decisions`**: Fill per dimension; `choice` supports multi-select (e.g. `A B`, space-separated), custom (`Z: …`); `rationale` must explain reasoning for code phase; do not leave empty.
221
+ - **`notes`**: Fill each task's `notes` with: `[scope] · [spec ref] · [key constraints] · Verify: [concrete operation]`; used by `/archi.code` step_4 to locate context and run e2e; do not leave empty.
222
+ > Example: `Implement POST /auth/login · spec §3.1 · JWT must not contain password · Verify: curl POST /auth/login returns 200 + token field`
223
+ - Run `npx archi render` after generation to produce readable `.md` view.
224
+ </step_4_generate>
225
+
226
+ <step_5_audit>
227
+ **Role**: Chief Auditor
228
+ **Checklist**:
229
+ 1. **Design Fidelity**: Do Scenarios fully cover confirmed task design (flow steps and exception paths)?
230
+ 2. **Tech Consistency**: Any undeclared tech used?
231
+ 3. **Data Integrity**: Do Scenario entities match confirmed core entities?
232
+ 4. **Error Handling**: Is Error Handling recommendation covered?
233
+ 5. **AX Compliance**: Are Anti-Clobbering and Interface Stability rules followed?
234
+
235
+ Silently fix issues; mark critical issues with `⚠️ Risk Warning`.
236
+ </step_5_audit>
237
+
238
+ <step_6_signoff>
239
+ **Terminal Gate** (Do not skip; must complete before output summary):
240
+ | Step | Command | Pass Condition |
241
+ |:---|:---|:---|
242
+ | 1 | `npx archi task --check` | No ERROR-level issues |
243
+ | 2 | `npx archi task <ID> --status active` | Task marked as in-progress |
244
+ | 3 | `npx archi render` | `.md` views generated |
245
+
246
+ **Action** (After Gate passes):
247
+ 1. Output summary.
248
+
249
+ **Output**: Task definition summary with Architecture Confirmation table (each dimension's final choice and rationale) and Next Steps table.
250
+ </step_6_signoff>
251
+
252
+ </protocol_plan>