claudeos-core 2.1.1 → 2.3.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 (62) hide show
  1. package/CHANGELOG.md +1649 -481
  2. package/CONTRIBUTING.md +92 -92
  3. package/README.de.md +64 -5
  4. package/README.es.md +64 -5
  5. package/README.fr.md +64 -5
  6. package/README.hi.md +64 -5
  7. package/README.ja.md +64 -5
  8. package/README.ko.md +1018 -959
  9. package/README.md +1020 -960
  10. package/README.ru.md +66 -5
  11. package/README.vi.md +1019 -960
  12. package/README.zh-CN.md +64 -5
  13. package/bin/cli.js +152 -148
  14. package/bin/commands/init.js +1673 -1518
  15. package/bin/commands/lint.js +62 -0
  16. package/bin/commands/memory.js +438 -438
  17. package/bin/lib/cli-utils.js +206 -206
  18. package/claude-md-validator/index.js +184 -0
  19. package/claude-md-validator/reporter.js +66 -0
  20. package/claude-md-validator/structural-checks.js +528 -0
  21. package/content-validator/index.js +666 -436
  22. package/lib/env-parser.js +317 -0
  23. package/lib/expected-guides.js +23 -23
  24. package/lib/expected-outputs.js +90 -90
  25. package/lib/language-config.js +35 -35
  26. package/lib/memory-scaffold.js +1058 -1052
  27. package/lib/plan-parser.js +165 -165
  28. package/lib/staged-rules.js +118 -118
  29. package/manifest-generator/index.js +174 -174
  30. package/package.json +90 -87
  31. package/pass-json-validator/index.js +337 -337
  32. package/pass-prompts/templates/angular/pass3.md +28 -13
  33. package/pass-prompts/templates/common/claude-md-scaffold.md +686 -0
  34. package/pass-prompts/templates/common/pass3-footer.md +402 -39
  35. package/pass-prompts/templates/common/pass3b-core-header.md +43 -0
  36. package/pass-prompts/templates/common/pass4.md +375 -302
  37. package/pass-prompts/templates/common/staging-override.md +26 -26
  38. package/pass-prompts/templates/java-spring/pass3.md +31 -21
  39. package/pass-prompts/templates/kotlin-spring/pass3.md +34 -22
  40. package/pass-prompts/templates/node-express/pass3.md +30 -21
  41. package/pass-prompts/templates/node-fastify/pass3.md +28 -14
  42. package/pass-prompts/templates/node-nestjs/pass3.md +29 -14
  43. package/pass-prompts/templates/node-nextjs/pass3.md +34 -21
  44. package/pass-prompts/templates/node-vite/pass1.md +117 -117
  45. package/pass-prompts/templates/node-vite/pass2.md +78 -78
  46. package/pass-prompts/templates/node-vite/pass3.md +30 -13
  47. package/pass-prompts/templates/python-django/pass3.md +32 -21
  48. package/pass-prompts/templates/python-fastapi/pass3.md +33 -21
  49. package/pass-prompts/templates/python-flask/pass1.md +119 -119
  50. package/pass-prompts/templates/python-flask/pass2.md +85 -85
  51. package/pass-prompts/templates/python-flask/pass3.md +31 -13
  52. package/pass-prompts/templates/vue-nuxt/pass3.md +32 -13
  53. package/plan-installer/domain-grouper.js +76 -76
  54. package/plan-installer/index.js +137 -129
  55. package/plan-installer/prompt-generator.js +188 -128
  56. package/plan-installer/scanners/scan-frontend.js +505 -473
  57. package/plan-installer/scanners/scan-java.js +226 -226
  58. package/plan-installer/scanners/scan-node.js +57 -57
  59. package/plan-installer/scanners/scan-python.js +85 -85
  60. package/plan-installer/stack-detector.js +482 -466
  61. package/plan-installer/structure-scanner.js +65 -65
  62. package/sync-checker/index.js +177 -177
@@ -0,0 +1,686 @@
1
+ # CLAUDE.md Scaffold Template (v2.2.0+)
2
+
3
+ This scaffold enforces structural determinism across all generated CLAUDE.md files.
4
+ CONTENT adapts to each project based on pass2-merged.json.
5
+ STRUCTURE is FIXED and MUST NOT be reordered, renamed, merged, or extended.
6
+
7
+ ## Why this scaffold exists
8
+
9
+ Prior to v2.2.0, CLAUDE.md generation specified required CONTENT items but did not
10
+ fix the structure. LLM choices varied between runs and between projects, producing
11
+ inconsistent section counts, names, and ordering. This problem only became visible
12
+ when claudeos-core was applied to multiple projects in the same organization.
13
+
14
+ This scaffold makes CLAUDE.md generation deterministic:
15
+ - Section count: EXACTLY 8
16
+ - Section titles: FIXED (see below)
17
+ - Section order: FIXED
18
+ - Section formats: SPECIFIED per section
19
+
20
+ ## Hard constraints
21
+
22
+ **EXACTLY 8 SECTIONS. No more, no less.**
23
+
24
+ Before finalizing CLAUDE.md, count `^## ` lines. The count MUST be 8.
25
+ If the count is 9 or more, merge surplus content into existing sections:
26
+ - Memory-related surplus → Section 8 sub-section 2 (L4 Memory)
27
+ - Common rules (51·52, doc-writing, ai-work) → Section 8 sub-section 1 (Common Rules)
28
+ - Rules-reference (directory index) → Section 6 (Standard / Rules / Skills Reference)
29
+ - Rule enumeration beyond those → MOVE to `.claude/rules/*` or `standard/*`, not CLAUDE.md
30
+
31
+ DO NOT:
32
+ - Add new top-level (`##`) sections beyond the 8 defined
33
+ - Remove any of the 8 sections (use minimal content if empty)
34
+ - Rename sections
35
+ - Change section order
36
+ - Merge the 8 sections with each other
37
+ - Create a `##`-level section whose name (or its translation in the
38
+ target output language) has the semantic meaning of "Common Rules",
39
+ "Required to Observe While Working", "Rules Summary", "Documentation
40
+ Writing Rules", "AI Common Rules", "L4 Memory Integration Rules",
41
+ or "Memory Layer" (as a standalone section), or any variation that
42
+ collects rules, procedures, or memory content. "Common Rules" and
43
+ "L4 Memory" each belong as a SUB-SECTION (`###`) inside Section 8,
44
+ not as their own top-level `##` section.
45
+ All other enforcement rule BODIES belong in `.claude/rules/*`
46
+ (auto-loaded via paths glob) or `claudeos-core/standard/*`.
47
+ - Restate the L4 memory table or workflow twice under different headings
48
+ — it appears exactly once, only in Section 8 sub-section 2.
49
+
50
+ ## Section heading format (MANDATORY)
51
+
52
+ The 8 canonical section headings below (`## 1. Role Definition` through
53
+ `## 8. Common Rules & Memory (L4)`) use English as their canonical form.
54
+ When generating CLAUDE.md in a non-English output language, the English
55
+ canonical heading MUST remain the primary heading text. A native-language
56
+ translation MAY be appended in parentheses, but is optional.
57
+
58
+ This rule exists because multiple projects in the same organization will
59
+ have their CLAUDE.md files consumed together (multi-repo grep, cross-repo
60
+ navigation, side-by-side review). When every project uses a different
61
+ native-language translation for the same section, even when the structure
62
+ is otherwise identical, discoverability breaks: `grep "## 7. DO NOT Read"`
63
+ no longer matches all siblings.
64
+
65
+ Format rule:
66
+ - Primary (required): English canonical heading exactly as listed.
67
+ - Parenthetical (optional): native-language translation, added at the end.
68
+
69
+ Examples (ko output):
70
+
71
+ ✅ `## 7. DO NOT Read`
72
+ ✅ `## 7. DO NOT Read (직접 읽지 말아야 할 파일)`
73
+ ❌ `## 7. 읽지 말 것 (Files Not to Be Read Directly)`
74
+ — English must be primary, not parenthetical
75
+ ❌ `## 7. 읽지 말 것`
76
+ — English canonical must appear
77
+
78
+ Examples (ja output):
79
+
80
+ ✅ `## 7. DO NOT Read (直接読まないファイル)`
81
+ ❌ `## 7. 直接読まないファイル (DO NOT Read)`
82
+
83
+ The same rule applies to all 8 sections. When in doubt, emit only the
84
+ English canonical heading; the parenthetical translation is a courtesy,
85
+ not a requirement. The CONTENT below the heading is still written
86
+ entirely in the target language.
87
+
88
+ DO:
89
+ - Adapt content within each section to project facts from pass2-merged.json
90
+ - Use placeholder values (`{PROJECT_CONTEXT}`, `{OUTPUT_LANG}`) where specified
91
+ - Follow per-section format rules
92
+ - When unsure where information belongs, consult the "Per-section generation rules"
93
+ below. Anything not fitting the 8 sections belongs OUTSIDE CLAUDE.md.
94
+
95
+ ## Template structure
96
+
97
+ Use the following structure EXACTLY:
98
+
99
+ ```markdown
100
+ # CLAUDE.md — {PROJECT_NAME}
101
+
102
+ > {1-2 line project intro}
103
+
104
+ ## 1. Role Definition
105
+
106
+ As the senior developer for this repository, you are responsible for writing, modifying, and reviewing code. Responses must be written in {OUTPUT_LANG}.
107
+ {PROJECT_CONTEXT}.
108
+
109
+ ## 2. Project Overview
110
+
111
+ | Item | Value |
112
+ |---|---|
113
+ | Language | {language with version} |
114
+ | Framework | {framework with version} |
115
+ | ... (8-12 rows total) |
116
+
117
+ ## 3. Build & Run Commands
118
+
119
+ {OPTIONAL: Top warning - [CRITICAL] for env requirements, or bold text for package manager rules}
120
+
121
+ ```bash
122
+ # {install command with comment}
123
+ {install command}
124
+
125
+ # {dev/build/test commands with inline comments}
126
+ {command 1} # {purpose / port / build engine}
127
+ {command 2}
128
+ ...
129
+ ```
130
+
131
+ {OPTIONAL: Bottom reference to single source of truth}
132
+
133
+ ## 4. Core Architecture
134
+
135
+ ### Overall Structure
136
+
137
+ {ASCII diagram in code block}
138
+
139
+ ### Data Flow
140
+
141
+ {Arrow chain or numbered list of data flow steps}
142
+
143
+ ### Core Patterns
144
+
145
+ - **{pattern name}**: {explanation}
146
+ - **{pattern name}**: {explanation}
147
+ - ... (3-5 bullets)
148
+
149
+ ### Absent / Not Adopted (OPTIONAL — include only if project deliberately avoids categories)
150
+
151
+ - {Generic category} ({optional parenthetical examples})
152
+ - ...
153
+
154
+ ## 5. Directory Structure
155
+
156
+ ```
157
+ {project root or src/}/
158
+ ├─ {dir}/ # {role}
159
+ ├─ {dir}/ # {role}
160
+ │ └─ {subdir}/ # {role}
161
+ └─ ...
162
+ ```
163
+
164
+ **{emphasis 1}**: {explanation}
165
+ **{emphasis 2}**: {explanation}
166
+ (Maximum 3 emphasis bullets below the tree)
167
+
168
+ ## 6. Standard / Rules / Skills Reference
169
+
170
+ ### Standard (Single Source of Truth)
171
+
172
+ | Path | Description |
173
+ |---|---|
174
+ | `claudeos-core/standard/{path}` | {1-line description} |
175
+ | ... (list ALL generated standard files individually) |
176
+
177
+ ### Rules (Auto-loaded Guardrails)
178
+
179
+ | Path | Description |
180
+ |---|---|
181
+ | `.claude/rules/00.core/00.standard-reference.md` | Standard documentation index |
182
+ | `.claude/rules/{category}/*` | {what's enforced} |
183
+ | ... (use wildcards per category) |
184
+
185
+ ### Skills (Automated Repeated-task Procedures)
186
+
187
+ - `claudeos-core/skills/00.shared/MANIFEST.md` — Skill registry
188
+ - `claudeos-core/skills/{path}` — {purpose}
189
+
190
+ ## 7. DO NOT Read (Files Not to Be Read Directly)
191
+
192
+ | Path | Reason |
193
+ |---|---|
194
+ | `claudeos-core/guide/` | Human-oriented documentation. Key content already captured in rules files. |
195
+ | `claudeos-core/generated/` | Auto-generated metadata. Internal use only. |
196
+ | `claudeos-core/mcp-guide/` | Key content already captured in rules files. Internal use only. |
197
+ | {conventional build output} | {1-line reason} |
198
+
199
+ ## 8. Common Rules & Memory (L4)
200
+
201
+ ### Common Rules (auto-loaded on every edit)
202
+
203
+ Global guardrails applied automatically to every documentation and code edit. Loaded via `paths: ["**/*"]`.
204
+
205
+ | Rule File | Role | Core Enforcement |
206
+ |---|---|---|
207
+ | `.claude/rules/00.core/51.doc-writing-rules.md` | Documentation writing rules | {1-line meta summary} |
208
+ | `.claude/rules/00.core/52.ai-work-rules.md` | AI work rules | {1-line meta summary} |
209
+ {| additional paths-universal rules if any |}
210
+
211
+ For detailed guidance, Read `claudeos-core/standard/00.core/04.doc-writing-guide.md`.
212
+
213
+ ### L4 Memory (on-demand reference)
214
+
215
+ Long-term context (decisions · failures · compaction · auto-proposals) is stored in `claudeos-core/memory/`.
216
+ Unlike rules that auto-load via `paths` glob, this layer is referenced **on-demand**.
217
+
218
+ #### L4 Memory Files
219
+
220
+ | File | Purpose | Behavior |
221
+ |---|---|---|
222
+ | `claudeos-core/memory/decision-log.md` | Permanent record of the "why" behind design choices | Append-only. Skim at session start; Read before any architectural change. Add a new entry when a decision is made. |
223
+ | `claudeos-core/memory/failure-patterns.md` | Repeated errors and their remedies | Searched at session start and whenever an error occurs. Record only when the pattern repeats (≥2 occurrences), the root cause is non-obvious, and the remedy is undocumented. |
224
+ | `claudeos-core/memory/compaction.md` | Declares the 4-stage compaction policy | Modify only when the policy itself changes. Execute compaction solely via `npx claudeos-core memory compact`. |
225
+ | `claudeos-core/memory/auto-rule-update.md` | Machine-generated rule change proposals | Review → Accept → Edit the rule → Record in `decision-log.md`. Do NOT edit this file directly. Regenerate via `npx claudeos-core memory propose-rules`. |
226
+
227
+ #### Memory Workflow
228
+
229
+ 1. **Session start**: Scan `failure-patterns.md` to be aware of frequently occurring errors.
230
+ 2. **Skim recent decisions**: Skim recent entries in `decision-log.md` to avoid overwriting architectural decisions that have already been agreed upon.
231
+ 3. **Record new decisions**: When making a significant design decision (choosing between competing patterns, adopting or rejecting a library, fixing a convention, etc.), append to `decision-log.md`.
232
+ 4. **Record repeated errors**: If the same error occurs ≥2 times and the root cause is non-obvious, register it in `failure-patterns.md` with a new pattern-id.
233
+ 5. **Periodic compaction**: When a memory file approaches 400 lines or has not been tidied up for over a month, run `npx claudeos-core memory compact`.
234
+ 6. **Review rule-update proposals**: Review proposals in `auto-rule-update.md` with confidence ≥ 0.70. When accepting, edit the corresponding rule file and log the decision in `decision-log.md`.
235
+ ```
236
+
237
+ ---
238
+
239
+ ## Per-section generation rules
240
+
241
+ ### Section 1: Role Definition
242
+
243
+ **Structure**: EXACTLY 2 lines.
244
+
245
+ **Line 1** (fixed text with `{OUTPUT_LANG}` substitution; emit in the target output language):
246
+ ```
247
+ As the senior developer for this repository, you are responsible for writing, modifying, and reviewing code. Responses must be written in {OUTPUT_LANG}.
248
+ ```
249
+
250
+ **Line 2** (`{PROJECT_CONTEXT}` — dynamically generated, Level 2 abstraction):
251
+
252
+ Generate `{PROJECT_CONTEXT}` as a single sentence combining:
253
+ - Stack name (generic form): `Java Spring Boot`, `React + Vite`, `Python Django`, `Node.js Express`, `Next.js App Router`
254
+ - Project type: "Backend Application", "Back Office SPA", "Front Office SPA", "REST API Server", "Full-stack Web Application"
255
+ - 1-2 architectural differentiators (using generic category terms)
256
+
257
+ **INCLUDE** (Level 2 — generic terms):
258
+ - Stack labels: "Java Spring Boot", "React + Vite"
259
+ - Architecture pattern names: "Layered Architecture", "Multi-entry", "Dual Build"
260
+ - Generic category terms: "Dual RDBMS", "XML-based SQL Mapper", "3-tier Authentication"
261
+
262
+ **EXCLUDE** (no hardcoding):
263
+ - Specific component names (PrimaryButton, ApiClient, AuthProvider)
264
+ - Specific product names (PostgreSQL, MariaDB, Redis, MyBatis, Prisma)
265
+ - Specific file paths (apiClient.ts, vite.config.desktop.ts)
266
+ - Specific counts (18 domains, 3 layers)
267
+ - Specific versions (React 19.1.0, Spring Boot 3.2)
268
+ - Specific domain names (admin, guide, orders)
269
+
270
+ **Source**: pass2-merged.json architecture/stack sections.
271
+
272
+ ### Section 2: Project Overview
273
+
274
+ **Format**: 2-column table with 8-12 rows.
275
+
276
+ **Required rows** (adapt per stack; column labels and row titles are emitted in the target output language):
277
+ - Language (with version)
278
+ - Framework (with version; use "Not X" for disambiguation if needed)
279
+ - Build Tool or Package Manager
280
+ - Main library (UI library for frontend, ORM/SQL mapper for backend)
281
+ - Execution environment (server port / dev server port)
282
+ - External dependencies (backend server, DB, session store)
283
+
284
+ **Optional rows** (include if distinctive):
285
+ - SPA Entry (multi-entry projects)
286
+ - Build Structure (dual builds, special configurations)
287
+ - Test Status (if notable — e.g., "0% coverage")
288
+ - Development Status Caveat (in-progress migrations, MOCK data usage)
289
+ - Forbidden Package Manager (brief form, e.g., "npm (pnpm, yarn forbidden)")
290
+
291
+ **Environment variables** (REQUIRED when `stack.envInfo` exists in pass2-merged.json):
292
+
293
+ When the project declares environment variables (via `.env.example` or
294
+ `.env`), the table MUST reflect what the project actually declares, not
295
+ framework defaults. Specifically:
296
+
297
+ - **Port row**: use `stack.envInfo.port` or `stack.port` (both already
298
+ resolved from the project's env file). Annotate with the env var name
299
+ in parentheses. Example (emit row labels in target output language):
300
+ `| Dev Server Port | 3000 (\`VITE_DESKTOP_PORT\`) |`
301
+ NOT `| Dev Server Port | 5173 |` when the project declares 3000.
302
+ - **Host row** (if `stack.envInfo.host` exists): add a row showing the
303
+ declared dev host. Example:
304
+ `| Dev Server Host | \`localhost\` (\`VITE_DEV_HOST\`) |`
305
+ - **API target row** (if `stack.envInfo.apiTarget` exists): add a row
306
+ showing the backend proxy/API target. Example:
307
+ `| API Proxy Target | \`http://localhost:8080\` (\`VITE_API_TARGET\`) |`
308
+ - **Additional ports** (if `stack.envInfo.vars` contains multi-port
309
+ patterns like `*_MOBILE_PORT`, `*_STORYBOOK_PORT`): inline them in the
310
+ port row using ` · ` as separator, OR add dedicated rows.
311
+ - **Source file** (`stack.envInfo.source`, e.g., `.env.example`): do NOT
312
+ include the source filename in the table itself — that metadata is for
313
+ prompt-time attribution, not user-facing CLAUDE.md content. Use it only
314
+ to verify which file the values came from.
315
+
316
+ General rule: if the project's env file declares something, the CLAUDE.md
317
+ table must match it. Framework defaults (Vite 5173, Next.js 3000, Django
318
+ 8000) are LAST RESORT — only used when env files are silent.
319
+
320
+ **SECURITY — Do NOT include sensitive values in CLAUDE.md**:
321
+ - Only reference PORT / HOST / API_TARGET variables (the three scaffolded
322
+ row types above). These are non-sensitive runtime configuration values.
323
+ - DO NOT populate table rows with values from variables named like
324
+ `*_PASSWORD`, `*_SECRET`, `API_KEY`, `*_TOKEN`, `*_CREDENTIAL`,
325
+ `PRIVATE_KEY`, `JWT_SECRET`, `CLIENT_SECRET`, etc. These are
326
+ automatically redacted to `***REDACTED***` by env-parser anyway, but
327
+ the scaffold explicitly forbids referencing them as a defense-in-depth.
328
+ - If `stack.envInfo.vars` contains a value equal to `***REDACTED***`,
329
+ that variable was redacted for security. Treat it as non-existent for
330
+ CLAUDE.md purposes — do NOT write the sentinel string into the table.
331
+ - Rationale: CLAUDE.md is committed to VCS and sometimes published. A
332
+ misconfigured `.env.example` (containing real secrets by mistake) must
333
+ not have those secrets amplified into project documentation.
334
+
335
+ **DO NOT INCLUDE** (belongs in other sections):
336
+ - Response wrapping style → Section 4
337
+ - Exception handling strategy → should go in rules/standard
338
+ - Encryption details → rules/standard
339
+ - Connection pool details → Section 4 or omit
340
+ - DB migration warnings → rules/standard
341
+ - Route guard details → Section 4
342
+
343
+ **Style**:
344
+ - Prefer specific versions (e.g., "5.8.3") but major-only is acceptable
345
+ - Negation allowed concisely: "Not Next.js", "TanStack Query Not Adopted"
346
+ - Use parentheses for clarifying annotations
347
+
348
+ **Source**: pass2-merged.json stack/tooling sections, including `stack.envInfo`.
349
+
350
+ ### Section 3: Build & Run Commands
351
+
352
+ **Structure**: 3 parts.
353
+
354
+ **Part 1 (OPTIONAL)**: Top warning
355
+ - Use `**[CRITICAL] {warning}**` for environmental requirements (JDK version, runtime)
356
+ - Use **bold text** for package manager restrictions
357
+ - Examples (emit in target output language):
358
+ - `**[CRITICAL] Java 21 required** — the system default Java may not be 21, so ...`
359
+ - `This project standardizes on **npm** as its package manager. \`yarn\` / \`pnpm\` commands are forbidden.`
360
+
361
+ **Part 2 (REQUIRED)**: Single bash code block with 4-7 commands
362
+ - Include dependency install command
363
+ - Include dev/run command
364
+ - Include build command
365
+ - Include test command (if applicable)
366
+ - Include project-specific commands if critical (migration, codegen trigger)
367
+ - Add inline comments for: port number, build engine, purpose, current state warnings
368
+ - **Port comment accuracy**: When adding a port comment next to a dev/run
369
+ command (e.g., `# dev server (port 3000)`), use the port from
370
+ `stack.envInfo.port` or `stack.port` in pass2-merged.json. Do NOT write
371
+ the framework's theoretical default (5173 for Vite, 3000 for Next.js,
372
+ 8000 for Django) if the project's env file declares a different value.
373
+
374
+ **Part 3 (OPTIONAL)**: Bottom reference
375
+ - Point to single source of truth: "Treat package.json's scripts as the single source of truth"
376
+ - Reference skill files for complex procedures
377
+ - Restate critical restrictions briefly
378
+
379
+ **Source**: pass2-merged.json scripts/buildTool/packageManager sections,
380
+ plus `stack.envInfo` for port accuracy.
381
+
382
+ ### Section 4: Core Architecture
383
+
384
+ **Structure**: 3-4 sub-sections.
385
+
386
+ **Sub-section 1 (REQUIRED)**: `### Overall Structure` (emit heading in target output language)
387
+ - ASCII diagram in code block
388
+ - Choose shape based on project type:
389
+ - Layered backend: vertical chain
390
+ - Multi-entry frontend: boxes + tree
391
+ - Single-app frontend: vertical tree
392
+ - Microservices: boxes with arrows
393
+ - Under 15 lines
394
+
395
+ **Sub-section 2 (REQUIRED)**: `### Data Flow`
396
+ - Arrow chain (1-2 lines) for simple flows
397
+ - Numbered list (3+ steps) for complex flows with transformations
398
+
399
+ **Sub-section 3 (REQUIRED)**: `### Core Patterns`
400
+ - 3-5 bullets
401
+ - Each reflects a distinctive architectural decision
402
+ - Use bold prefix: `- **{pattern name}**: {explanation}`
403
+
404
+ **Sub-section 4 (OPTIONAL)**: `### Absent / Not Adopted`
405
+ - Include when pass2-merged.json reveals deliberate NON-adoption
406
+ - Common candidates: state management libs, server state cache, error tracking, route guards
407
+ - Each item: single line, generic category + parenthetical examples
408
+
409
+ **DO NOT INCLUDE**:
410
+ - Specific file paths (→ Section 5)
411
+ - Version numbers (→ Section 2)
412
+ - Build/run commands (→ Section 3)
413
+
414
+ ### Section 5: Directory Structure
415
+
416
+ **Structure**: Tree diagram + up to 3 emphasis bullets below.
417
+
418
+ **Tree format**:
419
+ - Use UTF-8 box drawing: `├─`, `└─`, `│`
420
+ - Maximum 30-40 lines per tree
421
+ - For backend projects: separate trees for source packages vs resources
422
+ - For frontend/fullstack: single unified tree
423
+ - Include inline comments for key folders only
424
+ - Use placeholders where applicable: `{domain}/`, `{screen}/`, `{Table}`, `{DB}`
425
+
426
+ **Emphasis bullets (MAX 3)**:
427
+ Priority order:
428
+ 1. Auto-generated / do-not-modify paths
429
+ 2. Synchronization requirements (multi-file sync, dual-write)
430
+ 3. Separation/sharing boundaries (device split, module boundaries)
431
+
432
+ Format: `**{category}**: {explanation}`
433
+
434
+ **If 4+ items seem necessary**, move overflow to rules/standard instead of cramming.
435
+
436
+ ### Section 6: Standard / Rules / Skills Reference
437
+
438
+ **Structure**: EXACTLY 3 sub-sections.
439
+
440
+ **Sub-section 1**: `### Standard (Single Source of Truth)`
441
+ - Table format: `| Path | Description |` OR `| Area | Path |` (pick one, stay consistent)
442
+ - List EVERY generated standard file individually
443
+ - Description: 1-line
444
+ - Source: list of generated standard files
445
+
446
+ **Sub-section 2**: `### Rules (Auto-loaded Guardrails)`
447
+ - Table format OR bullet list (choose based on project size)
448
+ - Use WILDCARDS by category: `.claude/rules/{category}/*`
449
+ - Always include: `00.standard-reference.md`, `50.sync/*`, `60.memory/*`
450
+ - **`60.memory/*` is mandatory** — the directory itself is created by
451
+ Pass 4 (4 rule files: 01.decision-log, 02.failure-patterns, 03.compaction,
452
+ 04.auto-rule-update), but Section 6's Rules table MUST include a
453
+ `.claude/rules/60.memory/*` row at Pass 3 generation time as a
454
+ forward reference. This keeps the table's category index complete
455
+ and tells Claude Code that L4 memory rules auto-load when editing
456
+ the corresponding memory files. DO NOT omit it on the grounds that
457
+ "Pass 4 hasn't run yet" — the row describes the CATEGORY, not the
458
+ individual files.
459
+ - Description: what's enforced per category (not per file)
460
+ - **IMPORTANT**: `.claude/rules/00.core/*` wildcard row COVERS
461
+ `51.doc-writing-rules.md`, `52.ai-work-rules.md`, and all other 00.core rules.
462
+ Do NOT list these individually in Section 6 and do NOT create a separate
463
+ `##`-level section ("Documentation Writing Rules", "AI Common Rules")
464
+ for them — the wildcard already references them, and they are
465
+ auto-loaded via their `paths` frontmatter. The DETAILED universal-rules
466
+ table (with per-file meta-summary) belongs in Section 8 sub-section 1,
467
+ not here. Section 6's role is the directory index; Section 8's role
468
+ is the always-on layer summary. When a reader wants to see "what gets
469
+ auto-loaded on every edit", they go to Section 8.
470
+ Example row (emit text in target output language):
471
+ `.claude/rules/00.core/*` | Project / Architecture / Naming /
472
+ Documentation / AI-work rules (see §8 Common Rules table for the
473
+ detailed enforcement of 51·52, which auto-load on every edit) |
474
+ Example row for 60.memory:
475
+ `.claude/rules/60.memory/*` | Auto-loaded when editing L4 memory
476
+ files (decision-log · failure-patterns · compaction · auto-rule-update) |
477
+
478
+ **Sub-section 3**: `### Skills (Automated Repeated-task Procedures)`
479
+ - Bullet list
480
+ - Include ONLY skills that actually exist
481
+ - Always include: `00.shared/MANIFEST.md`
482
+ - Format: `path — purpose`
483
+
484
+ **DO NOT INCLUDE** (moves to Section 7):
485
+ - `claudeos-core/guide/` (go to Section 7)
486
+ - `claudeos-core/generated/` (go to Section 7)
487
+ - `claudeos-core/mcp-guide/` (go to Section 7)
488
+
489
+ ### Section 7: DO NOT Read
490
+
491
+ **Structure**: 2-column table, 3-5 rows total.
492
+
493
+ **ALWAYS INCLUDE (3 common items)** (emit row text in target output language):
494
+ ```
495
+ | claudeos-core/guide/ | Human-oriented documentation. Key content already captured in rules files. |
496
+ | claudeos-core/generated/ | Auto-generated metadata. Internal use only. |
497
+ | claudeos-core/mcp-guide/ | Key content already captured in rules files. Internal use only. |
498
+ ```
499
+
500
+ **INCLUDE conventional build outputs** (detect from pass2-merged.json buildTool):
501
+ - Vite / Webpack / Rollup → `dist/`
502
+ - Next.js → `.next/`
503
+ - Gradle → `build/`
504
+ - Maven → `target/`
505
+ - Python → `__pycache__/`, `dist/`
506
+ - Storybook (if present) → `storybook-static/`
507
+
508
+ **DO NOT INCLUDE**:
509
+ - Auto-generated source code directories (generated-api-client/, dto/generate/, etc.) — handled in Section 5 emphasis
510
+ - Project-specific build variants (dist-guide/, dist-mobile/) — not conventional
511
+ - Project-specific documentation output paths
512
+ - Environment files (.env*) — handled by rules/40.infra/*
513
+
514
+ **TARGET ITEM COUNT**: 3-5 items.
515
+
516
+ ### Section 8: Common Rules & Memory (L4)
517
+
518
+ **Structure**: 2 sub-sections.
519
+
520
+ **Rationale**: CLAUDE.md's Section 6 Rules table is a structural INDEX
521
+ ("which rule files exist, grouped by category"). Section 8's first
522
+ sub-section serves a different purpose: it documents WHICH rules
523
+ auto-load on EVERY edit (i.e., the universal guardrails the developer
524
+ should keep mentally active), plus a meta-summary of what each enforces.
525
+ These two views are complementary, not redundant — Section 6 shows the
526
+ map, Section 8 sub-section 1 shows the always-on layer.
527
+
528
+ **Sub-section 1 (REQUIRED)**: `### Common Rules (auto-loaded on every edit)` (emit heading in target output language)
529
+
530
+ - 2-column or 3-column table. Recommended: `| Rule File | Role | Core Enforcement |`
531
+ - Include ONLY rules whose `paths` frontmatter is `["**/*"]` (universal
532
+ auto-load). Typical entries:
533
+ - `.claude/rules/00.core/51.doc-writing-rules.md`
534
+ - `.claude/rules/00.core/52.ai-work-rules.md`
535
+ - Any other `paths: ["**/*"]` rule generated for this stack.
536
+ - Each row's "Core Enforcement" column must be a META SUMMARY (one
537
+ line, what the rule enforces at a high level), NOT a copy of the
538
+ rule body.
539
+ - ✅ "paths frontmatter required, no hardcoding, topic repetition is acknowledged as intentional reinforcement"
540
+ - ❌ Copying 5 paragraphs from the rule file
541
+ - End with a 1-line reference: "For detailed guidance, Read `claudeos-core/standard/...`"
542
+ when a corresponding standard file exists.
543
+
544
+ **Sub-section 2 (REQUIRED)**: `### L4 Memory (on-demand reference)` (emit heading in target output language)
545
+
546
+ Intro (1-2 sentences, fixed template — emit in target output language):
547
+ ```
548
+ Long-term context (decisions · failures · compaction · auto-proposals) is stored in `claudeos-core/memory/`.
549
+ Unlike rules that auto-load via `paths` glob, this layer is referenced **on-demand**.
550
+ ```
551
+
552
+ Table: `#### L4 Memory Files` — FIXED 4-row table
553
+ - decision-log.md — Append-only. Permanent record of the "why" behind design choices.
554
+ - failure-patterns.md — Repeated errors and their remedies (conditions: ≥2 occurrences, non-obvious root cause, undocumented remedy).
555
+ - compaction.md — 4-stage compaction policy.
556
+ - auto-rule-update.md — Machine-generated rule change proposals (regenerate via `npx claudeos-core memory propose-rules`).
557
+
558
+ Workflow: `#### Memory Workflow` — FIXED 6-step numbered list
559
+ 1. Session start — failure-patterns scan
560
+ 2. Skim recent decisions — decision-log recent
561
+ 3. Record new decisions — decision-log append
562
+ 4. Record repeated errors — failure-patterns add
563
+ 5. Periodic compaction — memory compact command
564
+ 6. Review rule-update proposals — auto-rule-update review
565
+
566
+ **Section 8 single-occurrence rule** (enforces the "one canonical home"
567
+ principle):
568
+ - The L4 Memory Files table appears EXACTLY ONCE in the entire document
569
+ — inside sub-section 2 (`L4 Memory`). No other location.
570
+ - The Memory Workflow (6-step numbered list) appears EXACTLY ONCE — same
571
+ location, after the L4 Memory Files table.
572
+ - The Common Rules meta-summary table appears EXACTLY ONCE — inside
573
+ sub-section 1. No sibling, no echo, no restatement.
574
+
575
+ **Out-of-scope content** (do NOT place under Section 8):
576
+ - Project-specific memory details — those go inside `memory/*.md` files
577
+ - Master plan references — `plan/` was removed in v2.1.0
578
+
579
+ **Language**: Use `{OUTPUT_LANG}` throughout this section. All headings,
580
+ table column labels, intro sentences, and workflow step labels shown
581
+ above in English MUST be emitted in the target output language.
582
+
583
+ ---
584
+
585
+ ## Dynamic substitution variables
586
+
587
+ | Variable | Source | Example |
588
+ |---|---|---|
589
+ | `{PROJECT_NAME}` | pass2-merged.json `project.name` or directory name | `my-backend-api` |
590
+ | `{OUTPUT_LANG}` | Target output language resolved from the CLI `--lang` flag | `en`, `ko`, `ja`, `zh-CN`, ... (10 supported) |
591
+ | `{PROJECT_CONTEXT}` | LLM-generated Level 2 description | See Section 1 rules |
592
+
593
+ ---
594
+
595
+ ## Validation checks (post-generation)
596
+
597
+ **MANDATORY FINAL CHECK — count `^## ` lines in the generated CLAUDE.md.**
598
+ The count MUST be exactly 8. If it is 9 or more, a surplus section was created
599
+ — locate it and either merge its content into the correct section from 1-8,
600
+ move it to `.claude/rules/*` or `standard/*`, or delete it entirely if it
601
+ duplicates existing rules. Then recount.
602
+
603
+ Common surplus sections that MUST be removed/merged (match by
604
+ semantic meaning in ANY output language — the English labels below
605
+ are canonical, target-language renderings are equivalent):
606
+ - "Common Rules" (as a `##` section) → move content to Section 8
607
+ sub-section 1 ("Common Rules (auto-loaded on every edit)")
608
+ - "L4 Memory Integration Rules" / "Memory Layer (L4)" (as a `##`
609
+ section) → merge into Section 8 sub-section 2; delete duplicate
610
+ tables/workflows
611
+ - "Documentation Writing Rules" / "AI Common Rules" (as standalone
612
+ `##` sections) → move as rows into Section 8 sub-section 1's
613
+ common-rules table
614
+ - "Required to Observe While Working" / "Rules Summary" → move
615
+ enforcement content to `.claude/rules/*`, not CLAUDE.md
616
+ - Any section whose title has the semantic meaning of "rules" beyond
617
+ Section 8's "Common Rules & Memory (L4)" top-level title
618
+
619
+ Before finalizing, verify:
620
+
621
+ - [ ] **Exactly 8 `##` top-level sections (count them!)**
622
+ - [ ] Section titles match the FIXED set (Role Definition, Project
623
+ Overview, Build & Run Commands, Core Architecture, Directory
624
+ Structure, Standard / Rules / Skills Reference, DO NOT Read,
625
+ Common Rules & Memory (L4)) — rendered in the target output
626
+ language with equivalent meaning and order
627
+ - [ ] Section order is correct
628
+ - [ ] No sections renamed, merged, or split
629
+ - [ ] No sections added beyond the 8
630
+ - [ ] Section 1 is 2 lines
631
+ - [ ] Section 2 is 8-12 rows table
632
+ - [ ] Section 5 has at most 3 emphasis bullets below tree
633
+ - [ ] Section 6 has EXACTLY 3 sub-sections (Standard / Rules / Skills)
634
+ - [ ] Section 6 Rules row for `00.core/*` includes a reference pointing
635
+ to Section 8's Common Rules table for auto-loaded rules
636
+ - [ ] Section 7 has the 3 common claudeos-core/* entries
637
+ - [ ] Section 8 has EXACTLY 2 sub-sections (Common Rules + L4 Memory)
638
+ - [ ] Section 8 sub-section 1 (Common Rules) lists ONLY rules with `paths: ["**/*"]`
639
+ - [ ] Section 8 sub-section 1 meta-summary column is 1 line per row, NOT a rule-body copy
640
+ - [ ] Section 8 sub-section 2 L4 memory table has exactly 4 rows
641
+ - [ ] Section 8 sub-section 2 workflow has exactly 6 steps
642
+ - [ ] Section 8 L4 table and workflow appear EXACTLY ONCE in the whole document
643
+ - [ ] Section 1 PROJECT_CONTEXT contains NO hardcoded component/product names
644
+
645
+ ---
646
+
647
+ ## Examples
648
+
649
+ ### Example: Section 1 for different stacks
650
+
651
+ Examples below are shown in English. Emit the final output in the
652
+ target output language; the semantic content should match.
653
+
654
+ **Java Spring Boot backend**:
655
+ ```
656
+ As the senior developer for this repository, you are responsible for writing, modifying, and reviewing code. Responses must be written in {OUTPUT_LANG}.
657
+ A Java Spring Boot backend application with a layered architecture, implemented on top of a dual RDBMS with an XML-based SQL mapper and a read/write mapper split.
658
+ ```
659
+
660
+ **React + Vite Back Office SPA**:
661
+ ```
662
+ As the senior developer for this repository, you are responsible for writing, modifying, and reviewing code. Responses must be written in {OUTPUT_LANG}.
663
+ A React + Vite Back Office SPA that, on top of multiple HTML entry points and per-domain page separation, follows a 3-tier authentication approach combining API response normalization, session guards, and button-level permission checks.
664
+ ```
665
+
666
+ **Python Django API**:
667
+ ```
668
+ As the senior developer for this repository, you are responsible for writing, modifying, and reviewing code. Responses must be written in {OUTPUT_LANG}.
669
+ A Python Django REST API server providing a multi-tenant structure on top of an RDBMS + cache layer, including an asynchronous task queue.
670
+ ```
671
+
672
+ ---
673
+
674
+ ## Usage from pass3 prompts
675
+
676
+ Pass 3b prompts for each stack MUST reference this scaffold:
677
+
678
+ ```
679
+ CLAUDE.md generation MUST follow the scaffold at:
680
+ `pass-prompts/templates/common/claude-md-scaffold.md`
681
+
682
+ Section structure, titles, and order are FIXED.
683
+ Content within each section adapts to this project based on pass2-merged.json.
684
+ ```
685
+
686
+ The scaffold supersedes any previous CLAUDE.md generation instructions.