codebyplan 1.13.38 → 1.13.40

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 (54) hide show
  1. package/dist/cli.js +25142 -425
  2. package/package.json +4 -2
  3. package/templates/agents/cbp-cc-executor.md +4 -4
  4. package/templates/agents/cbp-map-architecture.md +90 -0
  5. package/templates/agents/cbp-round-executor.md +2 -0
  6. package/templates/agents/cbp-task-check.md +2 -0
  7. package/templates/agents/cbp-task-planner.md +2 -0
  8. package/templates/context/architecture/arch-map-spec.md +204 -0
  9. package/templates/context/architecture-map.md +117 -0
  10. package/templates/hooks/README.md +14 -2
  11. package/templates/hooks/cbp-session-start-hook.sh +32 -0
  12. package/templates/hooks/cbp-test-coverage-gate.sh +20 -6
  13. package/templates/hooks/cbp-test-hooks.sh +72 -0
  14. package/templates/hooks/hooks.json +11 -0
  15. package/templates/hooks/validate-structure.sh +3 -2
  16. package/templates/rules/architecture-map.md +30 -0
  17. package/templates/rules/context-file-loading.md +3 -0
  18. package/templates/rules/supabase-branch-lifecycle.md +1 -1
  19. package/templates/settings.project.base.json +15 -1
  20. package/templates/skills/cbp-checkpoint-check/SKILL.md +10 -10
  21. package/templates/skills/cbp-checkpoint-complete/SKILL.md +7 -7
  22. package/templates/skills/cbp-checkpoint-create/SKILL.md +11 -9
  23. package/templates/skills/cbp-checkpoint-end/SKILL.md +4 -4
  24. package/templates/skills/cbp-checkpoint-plan/SKILL.md +10 -10
  25. package/templates/skills/cbp-checkpoint-start/SKILL.md +6 -6
  26. package/templates/skills/cbp-checkpoint-update/SKILL.md +9 -9
  27. package/templates/skills/cbp-git-commit/SKILL.md +8 -4
  28. package/templates/skills/cbp-git-worktree-remove/SKILL.md +3 -2
  29. package/templates/skills/cbp-map-architecture/SKILL.md +170 -0
  30. package/templates/skills/cbp-merge-main/SKILL.md +2 -5
  31. package/templates/skills/cbp-refresh-arch-map/SKILL.md +191 -0
  32. package/templates/skills/cbp-round-check/SKILL.md +12 -8
  33. package/templates/skills/cbp-round-complete/SKILL.md +16 -10
  34. package/templates/skills/cbp-round-end/SKILL.md +9 -10
  35. package/templates/skills/cbp-round-execute/SKILL.md +7 -6
  36. package/templates/skills/cbp-round-input/SKILL.md +24 -12
  37. package/templates/skills/cbp-round-start/SKILL.md +36 -16
  38. package/templates/skills/cbp-round-update/SKILL.md +14 -10
  39. package/templates/skills/cbp-session-end/SKILL.md +22 -12
  40. package/templates/skills/cbp-session-start/SKILL.md +19 -15
  41. package/templates/skills/cbp-ship/SKILL.md +4 -4
  42. package/templates/skills/cbp-ship/reference/surface-supabase.md +3 -3
  43. package/templates/skills/cbp-ship-configure/SKILL.md +1 -1
  44. package/templates/skills/cbp-ship-configure/reference/railway-backend.md +2 -2
  45. package/templates/skills/cbp-ship-configure/reference/vercel.md +1 -1
  46. package/templates/skills/cbp-ship-main/SKILL.md +2 -2
  47. package/templates/skills/cbp-standalone-task-complete/SKILL.md +3 -2
  48. package/templates/skills/cbp-supabase-migrate/SKILL.md +6 -7
  49. package/templates/skills/cbp-task-check/SKILL.md +10 -10
  50. package/templates/skills/cbp-task-complete/SKILL.md +11 -9
  51. package/templates/skills/cbp-task-create/SKILL.md +7 -5
  52. package/templates/skills/cbp-task-start/SKILL.md +15 -17
  53. package/templates/skills/cbp-task-testing/SKILL.md +18 -18
  54. package/templates/skills/cbp-todo/SKILL.md +21 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebyplan",
3
- "version": "1.13.38",
3
+ "version": "1.13.40",
4
4
  "description": "CLI for CodeByPlan — AI-powered development planning and tracking",
5
5
  "type": "module",
6
6
  "bin": {
@@ -45,7 +45,9 @@
45
45
  "node": ">=18"
46
46
  },
47
47
  "dependencies": {
48
- "@napi-rs/keyring": "^1.1.6"
48
+ "@napi-rs/keyring": "^1.1.6",
49
+ "@supabase/supabase-js": "^2.106.0",
50
+ "ws": ">=8.20.1"
49
51
  },
50
52
  "devDependencies": {
51
53
  "@eslint/js": "^9.18.0",
@@ -2,7 +2,7 @@
2
2
  scope: org-shared
3
3
  name: cbp-cc-executor
4
4
  description: Authoring executor for `.claude/` infrastructure. Applies approved changes across rules, skills, agents, context, CLAUDE.md, settings, and hooks — with update-first discipline, scope-marker enforcement, and length-limit awareness. Callable by the main conversation, `/cbp-checkpoint-end`, and `round-executor` (for in-scope `.claude/` infra deliverables).
5
- tools: Read, Write, Edit, Glob, Grep, Skill, Task, AskUserQuestion, mcp__codebyplan__create_task
5
+ tools: Read, Write, Edit, Glob, Grep, Skill, Task, AskUserQuestion, Bash(npx codebyplan task create *)
6
6
  model: sonnet
7
7
  effort: xhigh
8
8
  ---
@@ -134,7 +134,7 @@ Record every applied change with `authored_via` and `status`.
134
134
 
135
135
  - **Downgrade `create` → `update`** — apply silently, note in output.
136
136
  - **Unclear fit between two existing files** — `AskUserQuestion` with the two candidates and their descriptions.
137
- - **Change exceeds this invocation's scope** (e.g. proposal implies a broader refactor) — create a task via MCP `create_task` per `cbp-task-create` Step 3.5 "Immediate Issue Capture Contract", record in `deferred_changes` with `task_id_created`.
137
+ - **Change exceeds this invocation's scope** (e.g. proposal implies a broader refactor) — create a task via CLI write-through `codebyplan task create --checkpoint-id <id> ...` per `cbp-task-create` Step 3.5 "Immediate Issue Capture Contract"; MCP `create_task` as documented break-glass when CLI unavailable. Record in `deferred_changes` with `task_id_created`.
138
138
  - **Hook or settings change with cross-environment implications** — require explicit `scope` field from caller; if missing or ambiguous, ask.
139
139
 
140
140
  ### Phase 5: Post-Apply Sanity
@@ -197,7 +197,7 @@ Block-limit violations are non-negotiable — split before applying.
197
197
  - **Signed creates, edited updates** — creates route through build-cc skills (they embed the signature); updates use direct Edit on already-signed files.
198
198
  - **Never create agents** — only `update`. Agent creation requires a planning-level decision outside the fix pipeline.
199
199
  - **Length limits are enforced pre-apply** — refuse to produce a file that will fail the block limit.
200
- - **Surface, don't silently swallow** — ambiguity → `AskUserQuestion`; out-of-scope → MCP `create_task`.
200
+ - **Surface, don't silently swallow** — ambiguity → `AskUserQuestion`; out-of-scope → CLI `codebyplan task create` (MCP `create_task` as documented break-glass).
201
201
  - **Fresh inventory per invocation** — never reuse a cached inventory from a prior call.
202
202
 
203
203
  ## Integration
@@ -206,5 +206,5 @@ Block-limit violations are non-negotiable — split before applying.
206
206
  - **Reads**: `.claude/` inventory, `validate-structure-lengths.sh`, target files
207
207
  - **Writes**: `.claude/` files (via `/cbp-build-cc-*` skills for creates, direct Edit for updates)
208
208
  - **Calls skills**: `/cbp-build-cc-rule`, `/cbp-build-cc-skill`, `/cbp-build-cc-claude-file`, `/cbp-build-cc-settings`
209
- - **Creates tasks**: via MCP `create_task` when a change exceeds invocation scope
209
+ - **Creates tasks**: via CLI write-through `codebyplan task create` when a change exceeds invocation scope; MCP `create_task` as documented break-glass when CLI unavailable
210
210
  - **Enforced by**: `validate-structure-lengths.sh` (length), `validate-structure-scope.sh` (scope marker), `validate-structure-patterns.sh` (path layout)
@@ -0,0 +1,90 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-map-architecture
4
+ description: Read-only agent that analyzes a repository module and produces a structured architecture map following the canonical spec. Invoke when generating or refreshing a module's .claude/architecture/<module>.md map file. Returns the full map content as text for the caller to write.
5
+ tools: Read, Glob, Grep
6
+ model: sonnet
7
+ effort: high
8
+ ---
9
+
10
+ # Architecture Map Agent
11
+
12
+ You are a read-only code analyst that produces architecture map content for a single repository module.
13
+
14
+ ## Purpose
15
+
16
+ Analyze a module's source files and produce the complete content of a `.claude/architecture/<module>.md` map file, following the canonical format defined in `.claude/context/architecture/arch-map-spec.md`. The caller writes the returned content to disk — this agent does NOT write files.
17
+
18
+ ## Input Contract
19
+
20
+ ```yaml
21
+ input:
22
+ module_path: string # Module root path relative to repo root (e.g. "apps/web", "packages/codebyplan-package")
23
+ depth: skeleton|deep # Map fidelity level — skeleton omits Data-Flow Traces (section 5)
24
+ ```
25
+
26
+ ## Output Contract
27
+
28
+ Returns the complete `.claude/architecture/<module>.md` file content as a text block — starting with `---` (YAML frontmatter) and ending after section 7. The caller writes this text to the appropriate path and then runs `codebyplan arch-map stamp` to update `architecture.json`.
29
+
30
+ ## Workflow
31
+
32
+ ### Phase 1 — Load the canonical spec
33
+
34
+ 1. Read `.claude/context/architecture/arch-map-spec.md`.
35
+ 2. Confirm the 7 canonical section names, frontmatter fields, and depth rules.
36
+
37
+ ### Phase 2 — Discover module files
38
+
39
+ 1. Derive `source_globs` from `module_path`:
40
+ - For `apps/<name>`: `["apps/<name>/src/**/*.ts", "apps/<name>/src/**/*.tsx", "apps/<name>/**/*.ts", "apps/<name>/**/*.tsx"]` (deduplicated to what actually exists)
41
+ - For `packages/<name>`: `["packages/<name>/src/**/*.ts"]`
42
+ - For cross-cutting paths (`supabase/`, root config dirs): glob the directory directly
43
+ 2. Run Glob for each pattern. Record the file list.
44
+ 3. Read the module's `package.json` (if present) for name, dependencies, scripts.
45
+ 4. Read the primary entry file (e.g. `src/index.ts`, `src/index.tsx`, `app/layout.tsx`, `main.ts`) if it exists.
46
+
47
+ ### Phase 3 — Analyze the module
48
+
49
+ Use Read and Grep to gather the signal for each section:
50
+
51
+ | Section | Analysis action |
52
+ |---------|----------------|
53
+ | 1 — Boundaries | Read README or top-level comments; grep for `// @module`, `@description`, or doc headers |
54
+ | 2 — Public surface | Grep for `export (function\|class\|const\|type\|interface\|default)` in entry files |
55
+ | 3 — Internal structure | List top-level directories; read key non-entry files to understand their role |
56
+ | 4 — Dependencies | Parse `package.json` dependencies; grep `from '../'` patterns for cross-module imports |
57
+ | 5 — Data-flow [deep only] | Trace 2–5 representative flows by reading route handlers, service methods, or CLI entry points end-to-end |
58
+ | 6 — Conventions | Note naming patterns, linting config files, test file locations, framework idioms |
59
+ | 7 — Landmarks | Record the most commonly-needed paths (config file, main entry, types, tests) |
60
+
61
+ ### Phase 4 — Produce the map content
62
+
63
+ Assemble the output following the spec exactly:
64
+
65
+ 1. YAML frontmatter block with all 5 fields (`module`, `generated_from_sha: null`, `depth`, `generated_at: null`, `source_globs`).
66
+ 2. Sections 1–4 and 6–7 (always).
67
+ 3. Section 5 (only when `depth: deep`).
68
+ 4. Each section must have substantive content — no empty sections, no "N/A" placeholders. If information is genuinely unavailable, write a one-line note explaining why.
69
+
70
+ ## Completion Criteria
71
+
72
+ - All 7 sections present (or section 5 explicitly omitted for `depth: skeleton`).
73
+ - Frontmatter matches the spec schema exactly.
74
+ - `generated_from_sha` and `generated_at` are `null` (the caller sets these via `stamp`).
75
+ - Output is returned as text, not written to disk.
76
+
77
+ ## Failure Modes
78
+
79
+ | Condition | Action |
80
+ |-----------|--------|
81
+ | `module_path` does not exist in the repo | Return `blocked`: "Module path {path} not found — verify the path and retry" |
82
+ | Spec file `.claude/context/architecture/arch-map-spec.md` missing | Return `failed`: "Required spec file not found" |
83
+ | Glob finds zero files for all patterns | Return `blocked`: "No source files found under {module_path} — check source_globs" |
84
+
85
+ ## Integration
86
+
87
+ - **Spawned by**: `cbp-map-architecture` skill or direct agent invocation
88
+ - **Returns to**: caller writes output text to `.claude/architecture/<module-slug>.md`, then runs `codebyplan arch-map stamp`
89
+ - **Input from**: caller provides `module_path` and `depth`
90
+ - **Reads**: `.claude/context/architecture/arch-map-spec.md`, module source files
@@ -600,6 +600,8 @@ Which would you prefer?
600
600
  - **Spawned by**: `/cbp-round-execute` Step 3 (single-wave 3-AGENT path or per-wave 3-WAVE path)
601
601
  - **Returns to**: `/cbp-round-execute` which collects output and runs per-wave `cbp-testing-qa-agent`
602
602
  - **Depends on**: `cbp-task-planner` agent (provides approved plan)
603
+ - **Reads**: All task/round context arrives via the Input Contract (approved plan from `/cbp-round-start`). When the executor needs to read additional round or task state, read `.codebyplan/state/checkpoints/<id>/tasks/<id>/rounds/<id>.json` (local-first). If missing/stale, run `npx codebyplan sync` once and re-read. Break-glass fallback: MCP `get_*` tools when the state dir is absent and sync fails.
604
+ - **Writes**: DB-side mutations are surfaced as `improvements_noted` entries for the orchestrator to execute (executor frontmatter excludes MCP DB tools — see Step 0.2 carve-out).
603
605
  - **May spawn**: `cbp-database-agent` (Supabase operations), `general-purpose` (background batch writes), and `cbp-cc-executor` (in-scope `.claude/` infra deliverables, `source: 'round-executor'`) as sub-executors. (NOT any `cbp-e2e-*` specialist — e2e is orchestrator-owned, spawned by `/cbp-round-execute` Step 5 per the Step 0.2 carve-out.)
604
606
 
605
607
  ## Structure Knowledge
@@ -216,3 +216,5 @@ When no divergence is detected, set `scope_divergence_detected: false` and proce
216
216
 
217
217
  - **Spawned by**: `/cbp-task-check` command
218
218
  - **Returns to**: `/cbp-task-check` which routes based on verdict
219
+ - **Reads**: All task, checkpoint, and rounds data arrives via the Input Contract (passed by `/cbp-task-check`). Local `.codebyplan/state/` files are the preferred source when `/cbp-task-check` pre-fetches context — read `.codebyplan/state/checkpoints/<checkpointId>/tasks/<taskId>.json` and `rounds/*.json` (local-first; break-glass: MCP `get_*` tools when state dir is absent and sync fails). The agent itself reads only filesystem content (changed files) via the Read tool — it never calls MCP or CLI directly.
220
+ - **Writes**: None — review only, never edits.
@@ -585,3 +585,5 @@ Use TaskCreate for plan step visibility.
585
585
 
586
586
  - **Spawned by**: `/cbp-round-start` (Step 5)
587
587
  - **Returns to**: `/cbp-round-start` for user approval
588
+ - **Reads**: All DB state arrives via the Input Contract (pre-fetched by `/cbp-round-start`). Local `.codebyplan/state/` files are the preferred source when `/cbp-round-start` reads context before passing it in. Break-glass: MCP `get_*` tools when the state dir is absent and sync fails (daemon-dead + CLI-unavailable). The planner itself never calls MCP or the CLI directly (frontmatter excludes those tools).
589
+ - **Writes**: None — planner never mutates DB state.
@@ -0,0 +1,204 @@
1
+ ---
2
+ scope: org-shared
3
+ ---
4
+
5
+ # Architecture Map Spec
6
+
7
+ Canonical format specification for the `codebyplan arch-map` engine. Both the
8
+ `cbp-map-architecture` agent and the `arch-map` CLI reference this file as the
9
+ authoritative definition of all artifact formats.
10
+
11
+ ---
12
+
13
+ ## Per-Module Map File
14
+
15
+ Location: `.claude/architecture/<module>.md`
16
+
17
+ Where `<module>` is a slug derived from the module path, e.g.:
18
+ - `apps/web` → `apps-web.md`
19
+ - `packages/codebyplan-package` → `packages-codebyplan-package.md`
20
+ - `backend` → `backend.md`
21
+ - `.github` → `dot-github.md` (a leading dot in the module path is normalized to `dot-` so the map file is never hidden; the manifest `path` keeps the leading dot for git drift)
22
+
23
+ ### YAML Frontmatter
24
+
25
+ Every map file MUST open with a YAML block containing these exact fields:
26
+
27
+ ```yaml
28
+ ---
29
+ module: <path> # Module root path relative to repo root (e.g. "apps/web")
30
+ generated_from_sha: <sha>|null # Full git commit SHA the map was produced from, or null if never stamped
31
+ depth: skeleton|deep # Map fidelity level (see Depth Levels below)
32
+ generated_at: <iso>|null # ISO 8601 UTC timestamp of last generation, or null
33
+ source_globs: # Glob patterns used to discover files for this map
34
+ - <glob>
35
+ - <glob>
36
+ ---
37
+ ```
38
+
39
+ **Field rules:**
40
+ - `module` is the canonical path — used as the key in `architecture.json` and INDEX.md rows.
41
+ - `generated_from_sha` is `null` until `codebyplan arch-map stamp` is run for the first time.
42
+ - `depth` must be exactly `skeleton` or `deep` — no other values are valid.
43
+ - `generated_at` is `null` until first generation; set to an ISO 8601 UTC string on each regeneration.
44
+ - `source_globs` lists the patterns actually used; empty array is valid for cross-cutting modules.
45
+
46
+ ### Depth Levels
47
+
48
+ **`skeleton`** — structural overview only. Covers sections 1–4 and 6–7 (excludes Data-flow traces).
49
+ Fast to generate; useful for unfamiliar or rarely-changed modules.
50
+
51
+ **`deep`** — full analysis including Data-flow traces (section 5). Costs more tokens; used when
52
+ the agent or developer needs end-to-end data-flow understanding.
53
+
54
+ ### The 7 Canonical Sections
55
+
56
+ Every map file MUST include all applicable sections in this order. Sections marked `[deep only]`
57
+ are omitted for `depth: skeleton` maps.
58
+
59
+ ```
60
+ ## 1. Boundaries & Responsibility
61
+ ## 2. Public Surface / Entry Points
62
+ ## 3. Internal Structure
63
+ ## 4. Dependencies (In / Out)
64
+ ## 5. Data-Flow Traces [deep only]
65
+ ## 6. Conventions
66
+ ## 7. Where-Things-Live Landmarks
67
+ ```
68
+
69
+ **Section guidance:**
70
+
71
+ **1. Boundaries & Responsibility**
72
+ One-paragraph statement of what this module owns and does NOT own. Include the decision
73
+ boundary (which concerns belong here vs. adjacent modules).
74
+
75
+ **2. Public Surface / Entry Points**
76
+ Exported functions, classes, components, API routes, CLI entry points, or RPC endpoints
77
+ that other modules may depend on. For each: name, type, brief purpose.
78
+
79
+ **3. Internal Structure**
80
+ Key directories and their roles. Package sub-folders, layers, major files that are not
81
+ part of the public surface. Use a flat list or nested bullets.
82
+
83
+ **4. Dependencies (In / Out)**
84
+ - **Consumes**: modules, packages, or services this module imports/calls.
85
+ - **Consumed by**: modules that import from this module's public surface.
86
+ Cross-module edges only — internal sub-folder imports are not listed here.
87
+
88
+ **5. Data-Flow Traces [deep only]**
89
+ 2–5 named traces showing data end-to-end through this module. Format per trace:
90
+ ```
91
+ ### <trace name>
92
+ Source → [step] → [step] → Sink
93
+ ```
94
+ Include key transforms, async boundaries, and error paths.
95
+
96
+ **6. Conventions**
97
+ Patterns specific to this module: naming rules, file layout expectations, linting configs,
98
+ framework conventions, testing approach.
99
+
100
+ **7. Where-Things-Live Landmarks**
101
+ Quick-lookup table or list for "where is X?" questions. List landmark paths and one-line
102
+ descriptions. Aimed at a developer who has never opened this module.
103
+
104
+ ---
105
+
106
+ ## INDEX.md
107
+
108
+ Location: `.claude/architecture/INDEX.md`
109
+
110
+ The INDEX.md is the grep-native registry of all module maps in this repo. Format mirrors
111
+ `vendor/INDEX.md` — one pipe-delimited row per module, designed so `grep <term> INDEX.md`
112
+ produces a readable hit.
113
+
114
+ ### Row Format
115
+
116
+ ```
117
+ | <module> | <depth> | <generated_from_sha_short> | <generated_at_date> | <map_file> |
118
+ ```
119
+
120
+ - `<module>` — the `module` frontmatter value (e.g. `apps/web`)
121
+ - `<depth>` — `skeleton` or `deep`
122
+ - `<generated_from_sha_short>` — first 8 chars of `generated_from_sha`, or `unset` if null
123
+ - `<generated_at_date>` — `YYYY-MM-DD` portion of `generated_at`, or `unset` if null
124
+ - `<map_file>` — relative path from `.claude/architecture/` (e.g. `apps-web.md`)
125
+
126
+ ### Header
127
+
128
+ ```markdown
129
+ # Architecture Map Index
130
+
131
+ Grep-friendly registry of per-module architecture maps. Layout convention in `context/architecture/arch-map-spec.md`.
132
+
133
+ | Module | Depth | SHA | Generated | Map File |
134
+ |--------|-------|-----|-----------|----------|
135
+ ```
136
+
137
+ Each module map added or updated MUST have a corresponding row upserted in INDEX.md.
138
+
139
+ ---
140
+
141
+ ## graph.md
142
+
143
+ Location: `.claude/architecture/graph.md`
144
+
145
+ Adjacency-list representation of cross-module dependency edges. Used for dependency impact
146
+ analysis ("if I change module X, what else might be affected?").
147
+
148
+ ### Format
149
+
150
+ ```markdown
151
+ # Architecture Dependency Graph
152
+
153
+ Adjacency list of cross-module edges. Each entry: `<from> -> <to>`.
154
+ Generated from the `Dependencies (In / Out)` sections of individual map files
155
+ (first-party `@codebyplan/*` workspace imports, verified against each module's `package.json`).
156
+
157
+ Scope: edges are TypeScript workspace package imports only. Runtime/service dependencies
158
+ (shared schema directories, HTTP calls between apps) are documented per-map in
159
+ `## 4. Dependencies (In / Out)` and are intentionally NOT graphed here — a module with
160
+ no edge is not necessarily isolated; consult its map file for runtime coupling.
161
+
162
+ ## Edges
163
+
164
+ <module-A> -> <module-B>
165
+ <module-A> -> <module-C>
166
+ <module-B> -> <module-D>
167
+ ```
168
+
169
+ **Rules:**
170
+ - One edge per line: `<from> -> <to>` (exact module path values from frontmatter).
171
+ - Edges are directed (A depends on B = A -> B).
172
+ - Edges ARE deduplicated at write time by `/cbp-map-architecture` — each unique `<from> -> <to>` pair appears exactly once in graph.md, regardless of how many map files declare the same dependency.
173
+ - The file is regenerated wholesale by both `/cbp-map-architecture` (full generation) and `/cbp-refresh-arch-map` (drift-scoped refresh) — it is not appended incrementally by the CLI (`arch-map status`/`drift` are read-only).
174
+ - Edges represent first-party `@codebyplan/*` TypeScript workspace package imports only, verified against each module's `package.json`. Runtime/service dependencies (shared schema directories, HTTP calls between apps) are intentionally NOT graphed — consult each module's `## 4. Dependencies (In / Out)` section for runtime coupling.
175
+
176
+ ---
177
+
178
+ ## architecture.json
179
+
180
+ Location: `.codebyplan/architecture.json`
181
+
182
+ The committed manifest tracking which modules have been mapped and their freshness state.
183
+ Written by `setup` (empty stub) and `config` (create-if-absent). Updated by
184
+ `codebyplan arch-map stamp`.
185
+
186
+ ### Schema
187
+
188
+ ```json
189
+ {
190
+ "version": 1,
191
+ "modules": [
192
+ {
193
+ "path": "apps/web",
194
+ "map_file": ".claude/architecture/apps-web.md",
195
+ "generated_from_sha": "abc12345def...",
196
+ "depth": "skeleton",
197
+ "generated_at": "2026-06-02T10:00:00.000Z"
198
+ }
199
+ ]
200
+ }
201
+ ```
202
+
203
+ The TypeScript types for this schema are `ArchitectureConfig` and `ArchitectureModuleEntry`
204
+ in `packages/codebyplan-package/src/lib/types.ts`.
@@ -0,0 +1,117 @@
1
+ ---
2
+ scope: org-shared
3
+ ---
4
+
5
+ # Architecture Map Consultation Contract
6
+
7
+ This file is the **consumer contract** for the `.claude/architecture/` per-module map
8
+ files: what the artifacts are, when to read them, how to parse them, and what to do when
9
+ they are absent. Artifact format spec is in `context/architecture/arch-map-spec.md`.
10
+
11
+ ## What the Architecture Map Is
12
+
13
+ A committed set of per-module `.md` files under `.claude/architecture/` that record the
14
+ structure, public surface, internal layout, dependencies, conventions, and landmarks of
15
+ each repository module. They are authored by the `cbp-map-architecture` agent and stamped
16
+ by the `codebyplan arch-map stamp` CLI.
17
+
18
+ | Artifact | Location | Purpose |
19
+ |----------|----------|---------|
20
+ | Per-module map | `.claude/architecture/<module-slug>.md` | Full analysis of one module |
21
+ | Index | `.claude/architecture/INDEX.md` | Grep-friendly registry of all mapped modules |
22
+ | Dependency graph | `.claude/architecture/graph.md` | Cross-module dependency edges (adjacency list) |
23
+
24
+ **Depth levels** (from the module's `depth:` frontmatter field):
25
+
26
+ | Level | Sections included | When used |
27
+ |-------|-------------------|-----------|
28
+ | `skeleton` | 1–4, 6–7 (no data-flow traces) | Structural overview, unfamiliar or rarely-changed modules |
29
+ | `deep` | 1–7 including data-flow traces | End-to-end understanding of active modules |
30
+
31
+ **Slug derivation**: `apps/web` → `apps-web.md`; `.github` → `dot-github.md` (leading dot
32
+ normalized to `dot-` so the map file is never hidden). The manifest `path` keeps the
33
+ leading dot for git drift tracking.
34
+
35
+ ## When To Consult
36
+
37
+ ### cbp-task-planner — Phase 3: Check Rules and Architecture
38
+
39
+ Before finalizing scope for the target module(s), check whether a map exists:
40
+
41
+ 1. Glob `.claude/architecture/<module-slug>.md` for each module in scope.
42
+ 2. If found, read the map file — sections 1–4 + 6–7 give structural context that reduces
43
+ the need for broad file-system scans; section 5 (deep maps) gives data-flow traces.
44
+ 3. Use the `## 4. Dependencies (In / Out)` section to identify cross-module impact that
45
+ the planner's Explore subagent might otherwise miss.
46
+
47
+ ### cbp-round-executor — Step 2.4: Architecture Map Consultation
48
+
49
+ Before editing files in a module, check whether a map exists:
50
+
51
+ 1. Glob `.claude/architecture/<module-slug>.md` for the module being edited.
52
+ 2. If found, read the relevant sections before making changes — `## 7. Where-Things-Live
53
+ Landmarks` is the fastest orientation; `## 3. Internal Structure` disambiguates layout.
54
+ 3. The map is a pre-computed index — reading it replaces N individual file-reads for the
55
+ same structural signal.
56
+
57
+ ## How To Read
58
+
59
+ ```bash
60
+ # Check whether a map exists for a module
61
+ Glob: .claude/architecture/<module-slug>.md
62
+
63
+ # Read the map
64
+ Read: .claude/architecture/<module-slug>.md
65
+
66
+ # Browse all mapped modules
67
+ Read: .claude/architecture/INDEX.md
68
+
69
+ # Inspect cross-module dependencies
70
+ Read: .claude/architecture/graph.md
71
+ ```
72
+
73
+ Parse sections per the spec in `context/architecture/arch-map-spec.md`:
74
+ the 7 canonical section headings are `## 1. Boundaries & Responsibility` through
75
+ `## 7. Where-Things-Live Landmarks`. A `skeleton` map omits `## 5. Data-Flow Traces`.
76
+
77
+ YAML frontmatter fields: `module`, `generated_from_sha`, `depth`, `generated_at`,
78
+ `source_globs`. Check `generated_from_sha` against HEAD if you need to know whether the
79
+ map is stale (or run `codebyplan arch-map drift`).
80
+
81
+ ## If No Map Exists
82
+
83
+ The map is **not a prerequisite** — its absence is NOT a blocker for planning or execution.
84
+
85
+ - Proceed with the standard file-system analysis (Explore subagent / Read + Grep).
86
+ - Optionally note in your output that `/cbp-map-architecture --module <path>` would
87
+ pre-compute structural context for future rounds.
88
+ - Do NOT fail or block solely because a map is missing.
89
+
90
+ ## Agent Consumption Contract
91
+
92
+ | Agent | Phase / Step | Action |
93
+ |-------|-------------|--------|
94
+ | `cbp-task-planner` | Phase 3 — Check Rules and Architecture | Glob for map; read if present before finalizing scope |
95
+ | `cbp-round-executor` | Step 2.4 — Architecture Map Consultation | Glob for map; read if present before editing files in module |
96
+
97
+ Both agents follow the same read-or-skip pattern: Glob → if found, Read → use signal;
98
+ if absent, continue without blocking.
99
+
100
+ ## What This File Is NOT
101
+
102
+ - Not the artifact format spec — that is `context/architecture/arch-map-spec.md`.
103
+ - Not how to generate maps — use `/cbp-map-architecture` (map all/selected modules).
104
+ - Not how to refresh stale maps — use `/cbp-refresh-arch-map` (drift-scoped refresh).
105
+ - Not a substitute for reading the actual source files — the map is a pre-computed index,
106
+ not a replacement for code inspection when fine-grained detail is needed.
107
+
108
+ ## Related
109
+
110
+ | Concern | Reference |
111
+ |---------|-----------|
112
+ | Artifact format spec | `context/architecture/arch-map-spec.md` |
113
+ | Generate / regenerate maps | `/cbp-map-architecture` skill |
114
+ | Refresh only drifted modules | `/cbp-refresh-arch-map` skill (TASK-3) |
115
+ | CLI subcommands | `codebyplan arch-map status \| drift \| stamp` |
116
+ | Always-loaded pointer rule | `.claude/rules/architecture-map.md` |
117
+ | Loading rule registration | `.claude/rules/context-file-loading.md` |
@@ -2,7 +2,7 @@
2
2
 
3
3
  The `codebyplan` npm package ships a small, portable set of Claude Code hooks. They run in your project, use only generic primitives (`git rev-parse`, `${CLAUDE_PROJECT_DIR}`, `${CLAUDE_PLUGIN_ROOT}`), and degrade gracefully (exit 0) when their preconditions aren't met.
4
4
 
5
- Hook registration lives in [`hooks/hooks.json`](./hooks.json) — PreToolUse, PostToolUse, and UserPromptSubmit events are wired. (`Notification`, `SessionStart`, `SessionEnd`, `Stop`, and `SubagentStop` are also schema-permitted but unused here.)
5
+ Hook registration lives in [`hooks/hooks.json`](./hooks.json) — PreToolUse, PostToolUse, UserPromptSubmit, and SessionStart events are wired. (`Notification`, `SessionEnd`, `Stop`, and `SubagentStop` are also schema-permitted but unused here.)
6
6
 
7
7
  **`cbp-statusline.sh` is auto-wired via `settings.project.base.json`.** The `statusLine` block is shipped inside `templates/settings.project.base.json` and merged into the consumer's `.claude/settings.json` automatically by `codebyplan claude install` (and on every `codebyplan claude update`). No manual copy-paste is required.
8
8
 
@@ -243,13 +243,25 @@ drops below threshold (e.g. after `/compact` or `/clear`), so the notice re-fire
243
243
 
244
244
  ---
245
245
 
246
+ ### `cbp-session-start-hook.sh` — SessionStart
247
+
248
+ Hydrates the local-first state mirror at session start: runs `codebyplan sync` (full hydrate when cold, delta pull otherwise) and `codebyplan watch start` (idempotent — pidfile + process-alive check) so the per-worktree Realtime down-sync daemon is running for the session.
249
+
250
+ **Blocks vs warns**: never blocks — exit 0 always. All command errors are swallowed.
251
+
252
+ **Skips when**: no `.codebyplan/repo.json` in the project directory (not a CodeByPlan repo), or the CLI is unauthenticated/offline (both subcommands self-guard and the hook ignores their failures).
253
+
254
+ **Opt out**: settings.json override removing the `SessionStart` entry, or plugin disable.
255
+
256
+ ---
257
+
246
258
  ## Supporting (not registered)
247
259
 
248
260
  ### `test-hooks.sh` — invoked by `auto-test-hooks.sh`
249
261
 
250
262
  Test suite for the plugin's 9 registered hooks. Runs two passes:
251
263
 
252
- 1. **Header check** — every registered hook (`lint-format-on-edit`, `test-coverage-gate`, `pre-commit-quality-gate`, `maestro-yaml-validate`, `auto-test-hooks`, `mcp-migration-guard`, `validate-git-stash-deny`, `cbp-mcp-round-sync`, `cbp-context-window-notify`) carries the required `# Hook:` and `# Purpose:` header comments. `statusline` uses its own `# Claude Code Status Line` marker.
264
+ 1. **Header check** — every registered hook (`lint-format-on-edit`, `test-coverage-gate`, `pre-commit-quality-gate`, `maestro-yaml-validate`, `auto-test-hooks`, `mcp-migration-guard`, `validate-git-stash-deny`, `cbp-mcp-round-sync`, `cbp-context-window-notify`, `cbp-session-start-hook`) carries the required `# Hook:` and `# Purpose:` header comments. `statusline` uses its own `# Claude Code Status Line` marker.
253
265
  2. **Functional smoke tests** — each hook is invoked with synthetic stdin matching its fast-path / graceful-degrade input; all must exit 0.
254
266
 
255
267
  Not in `hooks.json` — invoked indirectly via `auto-test-hooks.sh` on hook edits, or directly via `bash ${CLAUDE_PLUGIN_ROOT}/hooks/test-hooks.sh`.
@@ -0,0 +1,32 @@
1
+ #!/bin/bash
2
+ # @scope: org-shared
3
+ # Hook: SessionStart
4
+ # Purpose: Hydrate .codebyplan/state/ via `codebyplan sync` and ensure the
5
+ # per-worktree watch daemon is running. Hook-safe: all errors
6
+ # swallowed, always exits 0. No-op when unauthenticated/offline.
7
+ #
8
+ # Runtime bound: the registered settings entry carries "timeout": 30 so the
9
+ # Claude Code hook runtime kills a hung sync/start — never shell-wrap with
10
+ # `timeout` (absent on macOS). `codebyplan sync` self-bounds its HTTP calls;
11
+ # `watch start` returns immediately after the detached spawn.
12
+ #
13
+ # Concurrency: `codebyplan watch start` is atomically idempotent — it takes an
14
+ # exclusive-create .pid.lock (O_EXCL) around the pidfile check + spawn, so two
15
+ # SessionStart hooks firing together in the same worktree start at most one
16
+ # daemon (the loser exits 0 with "start already in progress").
17
+
18
+ # Resolve the project dir: Claude Code sets CLAUDE_PROJECT_DIR; fall back to pwd.
19
+ PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(pwd)}"
20
+
21
+ # No-op when not inside a codebyplan repo (sentinel file absent).
22
+ if [ ! -f "$PROJECT_DIR/.codebyplan/repo.json" ]; then
23
+ exit 0
24
+ fi
25
+
26
+ # Hydrate state cache from backend (no-op offline / unauthenticated).
27
+ npx codebyplan sync >/dev/null 2>&1 || true
28
+
29
+ # Ensure per-worktree watch daemon is running (no-op when already up).
30
+ npx codebyplan watch start >/dev/null 2>&1 || true
31
+
32
+ exit 0
@@ -59,15 +59,20 @@ CHECKED=0
59
59
  SKIPPED=0
60
60
 
61
61
  while IFS= read -r FILE; do
62
- # Skip test files themselves
63
- if echo "$FILE" | grep -qE '\.(test|spec)\.(ts|tsx|js|jsx)$'; then
62
+ # Skip test files themselves. The leading [.-] class also matches framework
63
+ # spec conventions that suffix the marker with a dash — e.g. NestJS
64
+ # `*.e2e-spec.ts` (dot-form `.spec.ts` plus dash-form `-spec.ts`/`-test.ts`).
65
+ if echo "$FILE" | grep -qE '[.-](test|spec)\.(ts|tsx|js|jsx)$'; then
64
66
  continue
65
67
  fi
66
68
 
67
- # Skip files under a __tests__/ or __mocks__/ directory — fixtures, helpers,
68
- # setup, manual mocks, and other test infrastructure are imported by the test
69
- # files that exercise them; requiring a dedicated .test.ts is nonsensical.
70
- if echo "$FILE" | grep -qE '/__tests__/|/__mocks__/'; then
69
+ # Skip files under a __tests__/, __mocks__/, or top-level test/ directory —
70
+ # fixtures, helpers, setup (seed.ts, load-env.ts), manual mocks, and other
71
+ # test infrastructure are imported by the test files that exercise them;
72
+ # requiring a dedicated .test.ts for a fixture is nonsensical. `/test/` covers
73
+ # the NestJS e2e convention (apps/<app>/test/*.e2e-spec.ts) alongside the
74
+ # __tests__/ and __mocks__/ layouts.
75
+ if echo "$FILE" | grep -qE '/__tests__/|/__mocks__/|/test/'; then
71
76
  SKIPPED=$((SKIPPED + 1))
72
77
  continue
73
78
  fi
@@ -88,6 +93,15 @@ while IFS= read -r FILE; do
88
93
  continue
89
94
  fi
90
95
 
96
+ # Skip NestJS framework wrappers — *.module.ts are dependency-injection wiring
97
+ # barrels and *.decorator.ts are metadata-only; behavior lives in the
98
+ # providers/handlers they wire, which carry their own specs. Same category as
99
+ # the index barrel skip above.
100
+ if echo "$FILE" | grep -qE '\.(module|decorator)\.(ts|js)$'; then
101
+ SKIPPED=$((SKIPPED + 1))
102
+ continue
103
+ fi
104
+
91
105
  # Skip Next.js App Router framework files — page/layout/loading/error/route/
92
106
  # etc. are framework-convention wrappers, not logic-bearing modules. Same
93
107
  # category as the barrel/index skip above: behavior lives in the components