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