procedure-cli 0.1.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 (104) hide show
  1. package/.claude/settings.local.json +23 -0
  2. package/.env.example +2 -0
  3. package/AGENTS.md +113 -0
  4. package/CLAUDE.md +136 -0
  5. package/CODE-FIXED.md +124 -0
  6. package/CODE-REVIEW.md +253 -0
  7. package/README.md +130 -0
  8. package/config/defaults.json +8 -0
  9. package/config/powerline-config.json +52 -0
  10. package/config/stacks/typescript-node.json +15 -0
  11. package/dist/app.d.ts +1 -0
  12. package/dist/app.js +131 -0
  13. package/dist/app.js.map +1 -0
  14. package/dist/cli.d.ts +2 -0
  15. package/dist/cli.js +6 -0
  16. package/dist/cli.js.map +1 -0
  17. package/dist/components/banner.d.ts +1 -0
  18. package/dist/components/banner.js +11 -0
  19. package/dist/components/banner.js.map +1 -0
  20. package/dist/components/gutter-line.d.ts +5 -0
  21. package/dist/components/gutter-line.js +9 -0
  22. package/dist/components/gutter-line.js.map +1 -0
  23. package/dist/components/guttered-select.d.ts +25 -0
  24. package/dist/components/guttered-select.js +68 -0
  25. package/dist/components/guttered-select.js.map +1 -0
  26. package/dist/components/step-indicator.d.ts +7 -0
  27. package/dist/components/step-indicator.js +12 -0
  28. package/dist/components/step-indicator.js.map +1 -0
  29. package/dist/components/timeline.d.ts +13 -0
  30. package/dist/components/timeline.js +26 -0
  31. package/dist/components/timeline.js.map +1 -0
  32. package/dist/lib/fs.d.ts +3 -0
  33. package/dist/lib/fs.js +15 -0
  34. package/dist/lib/fs.js.map +1 -0
  35. package/dist/lib/git.d.ts +4 -0
  36. package/dist/lib/git.js +37 -0
  37. package/dist/lib/git.js.map +1 -0
  38. package/dist/lib/powerline.d.ts +1 -0
  39. package/dist/lib/powerline.js +30 -0
  40. package/dist/lib/powerline.js.map +1 -0
  41. package/dist/lib/template.d.ts +9 -0
  42. package/dist/lib/template.js +46 -0
  43. package/dist/lib/template.js.map +1 -0
  44. package/dist/lib/types.d.ts +44 -0
  45. package/dist/lib/types.js +2 -0
  46. package/dist/lib/types.js.map +1 -0
  47. package/dist/providers/openai.d.ts +1 -0
  48. package/dist/providers/openai.js +5 -0
  49. package/dist/providers/openai.js.map +1 -0
  50. package/dist/providers/zai.d.ts +1 -0
  51. package/dist/providers/zai.js +7 -0
  52. package/dist/providers/zai.js.map +1 -0
  53. package/dist/steps/architecture.d.ts +6 -0
  54. package/dist/steps/architecture.js +39 -0
  55. package/dist/steps/architecture.js.map +1 -0
  56. package/dist/steps/build-test.d.ts +7 -0
  57. package/dist/steps/build-test.js +38 -0
  58. package/dist/steps/build-test.js.map +1 -0
  59. package/dist/steps/generation.d.ts +7 -0
  60. package/dist/steps/generation.js +60 -0
  61. package/dist/steps/generation.js.map +1 -0
  62. package/dist/steps/powerline.d.ts +7 -0
  63. package/dist/steps/powerline.js +62 -0
  64. package/dist/steps/powerline.js.map +1 -0
  65. package/dist/steps/product-context.d.ts +7 -0
  66. package/dist/steps/product-context.js +90 -0
  67. package/dist/steps/product-context.js.map +1 -0
  68. package/dist/steps/project-info.d.ts +6 -0
  69. package/dist/steps/project-info.js +61 -0
  70. package/dist/steps/project-info.js.map +1 -0
  71. package/dist/steps/stack-style.d.ts +6 -0
  72. package/dist/steps/stack-style.js +67 -0
  73. package/dist/steps/stack-style.js.map +1 -0
  74. package/docs/GIAI-THICH-CLAUDE-MD.md +206 -0
  75. package/docs/PRD.md +130 -0
  76. package/docs/USER-STORIES.md +181 -0
  77. package/package.json +38 -0
  78. package/src/app.tsx +201 -0
  79. package/src/cli.tsx +6 -0
  80. package/src/components/banner.tsx +23 -0
  81. package/src/components/gutter-line.tsx +10 -0
  82. package/src/components/guttered-select.tsx +137 -0
  83. package/src/components/step-indicator.tsx +19 -0
  84. package/src/components/timeline.tsx +49 -0
  85. package/src/lib/fs.ts +18 -0
  86. package/src/lib/git.ts +41 -0
  87. package/src/lib/powerline.ts +48 -0
  88. package/src/lib/template.ts +59 -0
  89. package/src/lib/types.ts +68 -0
  90. package/src/providers/openai.ts +5 -0
  91. package/src/providers/zai.ts +7 -0
  92. package/src/steps/architecture.tsx +71 -0
  93. package/src/steps/build-test.tsx +78 -0
  94. package/src/steps/generation.tsx +146 -0
  95. package/src/steps/powerline.tsx +149 -0
  96. package/src/steps/product-context.tsx +182 -0
  97. package/src/steps/project-info.tsx +135 -0
  98. package/src/steps/stack-style.tsx +117 -0
  99. package/templates/.env.example.hbs +6 -0
  100. package/templates/CLAUDE.md.hbs +105 -0
  101. package/templates/README.md.hbs +26 -0
  102. package/templates/docs/PRD.md.hbs +29 -0
  103. package/templates/docs/USER-STORIES.md.hbs +46 -0
  104. package/tsconfig.json +17 -0
@@ -0,0 +1,23 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "WebFetch(domain:z.ai)",
5
+ "mcp__plugin_context7_context7__resolve-library-id",
6
+ "mcp__plugin_context7_context7__query-docs",
7
+ "Bash(npm init:*)",
8
+ "Bash(npm install:*)",
9
+ "Bash(npx tsc:*)",
10
+ "Bash(npx tsx:*)",
11
+ "WebFetch(domain:skills.sh)",
12
+ "WebFetch(domain:openclaw.com)",
13
+ "WebSearch",
14
+ "Bash(npm run typecheck:*)",
15
+ "Bash(npm run build:*)",
16
+ "Bash(pnpm install:*)",
17
+ "Bash(node -e:*)",
18
+ "Bash(git add:*)",
19
+ "Bash(git commit:*)",
20
+ "Bash(git push:*)"
21
+ ]
22
+ }
23
+ }
package/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ ZAI_API_KEY=
2
+ OPENAI_API_KEY=
package/AGENTS.md ADDED
@@ -0,0 +1,113 @@
1
+ # Repository Guidelines
2
+
3
+ This file provides guidance to coding agents (including Codex) working in this repository.
4
+
5
+ See `docs/PRD.md` for product requirements and `docs/USER-STORIES.md` for acceptance criteria.
6
+
7
+ ## Build & Test
8
+
9
+ ```bash
10
+ npm run dev # Run CLI directly (tsx, no build step)
11
+ npm run typecheck # Typecheck (fast — run first)
12
+ npm run lint # Alias of typecheck
13
+ npm run build # Compile to dist/
14
+ npx tsx src/cli.tsx # Run entry point directly
15
+ ```
16
+
17
+ Important safety note: never run `npm run dev` from this repo root when validating scaffolding behavior. Generation writes to `process.cwd()`. Use a temp directory.
18
+
19
+ ## Code Style
20
+
21
+ - TypeScript strict mode, ESM (`"type": "module"` in `package.json`).
22
+ - JSX runtime: `react-jsx`.
23
+ - Ink UI components use `.tsx`; pure logic modules use `.ts`.
24
+ - Handlebars templates use `.hbs` in `templates/`.
25
+ - Providers live in `src/providers/`, one provider per file.
26
+ - Never hardcode API keys; use `ZAI_API_KEY` and `OPENAI_API_KEY`.
27
+
28
+ ## Architecture
29
+
30
+ - Entry point: `src/cli.tsx`
31
+ - UI root / wizard controller: `src/app.tsx`
32
+ - Step implementations: `src/steps/`
33
+ - Reusable UI components: `src/components/`
34
+ - Core logic: `src/lib/`
35
+ - `template.ts`: Handlebars rendering + file scaffolding
36
+ - `powerline.ts`: Claude powerline setup
37
+ - `git.ts`: git init + initial commit flow
38
+ - `fs.ts`: filesystem helpers
39
+ - `types.ts`: shared type definitions
40
+ - Templates: `templates/`
41
+ - Config: `config/`
42
+ - Docs: `docs/`
43
+
44
+ ## Workflow
45
+
46
+ ### Planning
47
+ - Use planning for non-trivial changes (3+ steps or architecture-impacting work).
48
+ - If execution deviates materially, stop and re-plan.
49
+
50
+ ### Verification
51
+ - Do not mark work complete without evidence.
52
+ - Minimum verification: `npm run typecheck` and `npm run build`.
53
+
54
+ ### Bug Fixing
55
+ - Resolve root cause; avoid temporary patches.
56
+ - Ground fixes in reproducible evidence (logs, failing behavior, code path).
57
+
58
+ ### Elegance
59
+ - For non-trivial changes, prefer clean, maintainable solutions over tactical hacks.
60
+ - Avoid over-engineering simple fixes.
61
+
62
+ ## Task Management
63
+
64
+ ### Solo Work
65
+ 1. Plan the approach.
66
+ 2. Implement in small, coherent changes.
67
+ 3. Verify before claiming completion.
68
+ 4. Update procedural docs when corrected by the user.
69
+
70
+ ### Agent Teams
71
+ 1. Plan before delegation.
72
+ 2. Assign clear deliverables per task.
73
+ 3. Keep file ownership non-overlapping across agents.
74
+ 4. Include file paths and constraints in handoffs.
75
+
76
+ ## Code Review & Fix Logging
77
+
78
+ Two append-only logs live at repo root: `CODE-REVIEW.md` and `CODE-FIXED.md`.
79
+
80
+ ### CODE-REVIEW.md
81
+ - For review findings only.
82
+ - Entry ID format: `CR-YYYYMMDD-###`.
83
+ - Findings ordered by severity (`High`, `Medium`, `Low`).
84
+ - Each finding must include: `file:line` evidence, recommendation, and status (`New`, `Still Open`, `Fixed`, `Regressed`, `Not Reproducible`).
85
+ - Scope boundary: when reviewing, write only to `CODE-REVIEW.md`.
86
+
87
+ ### CODE-FIXED.md
88
+ - For fixes applied to review findings.
89
+ - Entry ID format: `CF-YYYYMMDD-###`.
90
+ - Each entry references source `CR-` entry ID.
91
+ - Log only actions taken, changed files/lines, deferred rationale, and verification results.
92
+ - Scope boundary: when fixing, write only to `CODE-FIXED.md`.
93
+
94
+ ### Procedure
95
+ 1. Reviewing: read latest `CODE-REVIEW.md` and latest `CODE-FIXED.md` first; append a new `CR-` entry to `CODE-REVIEW.md`.
96
+ 2. Fixing: read review + fix logs; fix unresolved findings; append a new `CF-` entry to `CODE-FIXED.md`.
97
+ 3. Re-reviewing: append a new `CR-` entry with validation matrix and status updates.
98
+
99
+ ## Core Principles
100
+
101
+ - Simplicity first.
102
+ - Root-cause rigor over temporary fixes.
103
+ - Minimal necessary code impact.
104
+
105
+ ## Lessons (Project-Specific)
106
+
107
+ - Keep timeline `│` lines vertically aligned.
108
+ - Validate required wizard inputs.
109
+ - Use select menus for known-option fields (package manager, license, architecture).
110
+ - Keep errors visually distinct and below inputs.
111
+ - Keep generation confirmation explicit before file writes.
112
+ - Tech stack multi-select should prefill from Stack & Style selections.
113
+ - If generation is skipped, end-state messaging must not imply files were scaffolded.
package/CLAUDE.md ADDED
@@ -0,0 +1,136 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ See docs/PRD.md for product requirements and docs/USER-STORIES.md for user stories with acceptance criteria.
6
+
7
+ ## Build & Test
8
+
9
+ ```bash
10
+ npm run dev # Run CLI directly (tsx, no build step)
11
+ npm run typecheck # Typecheck (fast — run first)
12
+ npm run build # Compile to dist/
13
+ npx tsx src/cli.tsx # Run entry point directly
14
+ ```
15
+
16
+ ## Code Style
17
+
18
+ - TypeScript strict mode, ESM (`"type": "module"` in package.json)
19
+ - JSX runtime: `react-jsx` (no `import React` needed in components, but keep it for clarity in entry points)
20
+ - Ink components use `.tsx` extension; pure logic uses `.ts`
21
+ - Handlebars templates use `.hbs` extension in `templates/`
22
+ - Providers live in `src/providers/` — one file per provider, each exports a single provider instance
23
+ - Environment variables for API keys: `ZAI_API_KEY`, `OPENAI_API_KEY` (never hardcode)
24
+
25
+ ## Architecture
26
+
27
+ - **Entry point**: `src/cli.tsx` — parses args, calls `render(<App />)`
28
+ - **UI layer**: `src/app.tsx` — Ink root component, wizard controller with 7-step flow
29
+ - **Wizard steps**: `src/steps/` — one component per step, each receives `onComplete` callback
30
+ - **UI components**: `src/components/` — banner, timeline, step-indicator, gutter-line, guttered-select
31
+ - **Core logic**: `src/lib/` — pure functions, no UI
32
+ - `template.ts` — Handlebars rendering, file scaffolding
33
+ - `powerline.ts` — Claude Code powerline setup (from setup-powerline.sh logic)
34
+ - `git.ts` — git init + initial commit
35
+ - `fs.ts` — directory/file helpers
36
+ - `types.ts` — WizardAnswers interface, StepId type
37
+ - **Templates**: `templates/` — Handlebars files (.hbs) rendered with wizard answers into target projects
38
+ - **Config**: `config/` — defaults, stack presets, bundled powerline config
39
+ - **AI providers**: `src/providers/` — Z.ai uses `@ai-sdk/openai-compatible` (GLM models), OpenAI uses `@ai-sdk/openai`
40
+ - **AI SDK 6**: All AI calls go through Vercel AI SDK 6 (`ai` package). Use `generateText`, `streamText`, or `generateObject` — not raw fetch
41
+ - **Docs**: `docs/` — PRD, User Stories (Gherkin A/C), methodology explainer (Vietnamese)
42
+
43
+ ## Workflow
44
+
45
+ ### Planning
46
+ - Enter plan mode for ANY non-trivial task (3+ steps or architectural decisions)
47
+ - If something goes sideways, STOP and re-plan — don't keep pushing
48
+ - A good plan lets you one-shot the implementation
49
+
50
+ ### Verification
51
+ - Never mark a task complete without proving it works
52
+ - Run `npm run typecheck` then `npm run dev` to verify
53
+ - Ask yourself: "Would a staff engineer approve this?"
54
+
55
+ ### Self-Improvement
56
+ - After ANY correction from the user: update the Lessons section below
57
+ - Write rules that prevent the same mistake from recurring
58
+
59
+ ### Bug Fixing
60
+ - Given a bug report: just fix it. Don't ask for hand-holding
61
+ - Point at logs, errors, failing tests — then resolve them
62
+
63
+ ### Elegance
64
+ - For non-trivial changes: pause and ask "is there a more elegant way?"
65
+ - If a fix feels hacky, step back and implement the clean solution
66
+ - Skip this for simple, obvious fixes — don't over-engineer
67
+
68
+ ## Task Management
69
+
70
+ ### Solo Work
71
+ 1. Plan first (plan mode for complex tasks)
72
+ 2. Track progress with TaskCreate/TaskUpdate for multi-step work
73
+ 3. Verify before claiming done
74
+ 4. Update Lessons after corrections
75
+
76
+ ### Agent Teams
77
+ 1. Plan-then-team: design approach BEFORE spawning a team
78
+ 2. Each task = one clear deliverable with verification steps
79
+ 3. File ownership: each teammate owns specific files — NEVER have two edit the same file
80
+ 4. Include file paths and constraints in task descriptions — teammates don't inherit context
81
+ 5. DMs by default, broadcast only for critical blocking issues
82
+ 6. 3-5 teammates max
83
+
84
+ ## Code Review & Fix Logging
85
+
86
+ Two tracking files live at the project root. Both are append-only logs — never delete or rewrite past entries.
87
+
88
+ ### CODE-REVIEW.md — review findings
89
+ - Created/appended during code review sessions.
90
+ - Entry ID format: `CR-YYYYMMDD-###` (zero-padded sequence per day).
91
+ - Findings ordered by severity (`High`, `Medium`, `Low`).
92
+ - Every finding includes `file:line` evidence, a clear recommendation, and `Status` (`New`, `Still Open`, `Fixed`, `Regressed`, `Not Reproducible`).
93
+
94
+ ### CODE-FIXED.md — fix results
95
+ - Created/appended when fixing findings from CODE-REVIEW.md.
96
+ - Entry ID format: `CF-YYYYMMDD-###`.
97
+ - Each entry references its source review by `CR-` Entry ID — do NOT re-describe findings, only document actions taken.
98
+ - Fixed findings include `file:line` for every change made.
99
+ - Deferred findings include rationale and a revisit trigger.
100
+ - Verification section must confirm `npm run typecheck` + `npm run build` status after fixes.
101
+
102
+ ### Procedure
103
+ 1. **Reviewing**:
104
+ - **First**: Read CODE-REVIEW.md → Read CODE-FIXED.md → understand current state of findings and fixes.
105
+ - **Then**: Read codebase → append findings to CODE-REVIEW.md with a new `CR-` entry (write to CODE-REVIEW.md only, never modify CODE-FIXED.md).
106
+ - **Never** fix code during a reviewing process.
107
+ 2. **Fixing**:
108
+ - **First**: Read CODE-REVIEW.md → Read CODE-FIXED.md → identify unfixed findings.
109
+ - **Then**: Fix only unfixed findings → append a new `CF-` entry to CODE-FIXED.md (write to CODE-FIXED.md only, never modify CODE-REVIEW.md).
110
+ - **Never** perform a code review during a fixing process.
111
+
112
+ ## Core Principles
113
+
114
+ - **Simplicity First**: Make every change as simple as possible. Minimal code impact.
115
+ - **No Laziness**: Find root causes. No temporary fixes. Senior developer standards.
116
+ - **Minimal Impact**: Changes should only touch what's necessary.
117
+
118
+ ## Lessons
119
+
120
+ - Timeline `│` lines must stay vertically aligned — never indent content in a way that breaks the straight line from dot to dot
121
+ - Required wizard fields must validate: don't allow empty submissions for project name, description, etc.
122
+ - Active step needs visual animation (spinner/pulse) so user knows the CLI is waiting for input
123
+ - Errors display below the input field in a distinct color (red/yellow) — never inline with the prompt
124
+ - Completed steps need visual acknowledgment (checkmark, color change) beyond just swapping the dot symbol
125
+ - Always add an intro/tagline under the ASCII banner so the user knows what the tool does
126
+ - NEVER run `npm run dev` from the procedure project directory — scaffolding writes to cwd and overwrites procedure's own files. Always test in a temp directory.
127
+ - Select menus (not text input) for fields with known options: package manager, license, architecture pattern
128
+ - Don't prefill fields from unrelated previous answers (e.g., project name → description)
129
+ - Architecture notes should be auto-generated from the selected pattern — users may not know best practices
130
+ - Generation step must show a summary and ask for confirmation before writing files
131
+ - Use `<Text>` not `<Box>` for single-line elements — `<Box>` creates flex containers that add visual gaps
132
+ - Step components must return `<>` fragments, NOT `<Box flexDirection="column">` — only timeline.tsx gets the outer Box
133
+ - Completed step summaries go on a SEPARATE `│ ` line below the step name, not on the same line (prevents wrapping)
134
+ - Custom GutteredSelect/GutteredMultiSelect for select menus — `@inkjs/ui` Select breaks the `│` gutter line
135
+ - Tech stack multi-select should prefill from Stack & Style selections (language + framework)
136
+ - Stack & Style = dev setup (language, framework, code style → CLAUDE.md). Tech Stack = full product stack (databases, infra → PRD/README)
package/CODE-FIXED.md ADDED
@@ -0,0 +1,124 @@
1
+ # Code Fix Log
2
+
3
+ ## Writing Standard
4
+ - Each entry documents fixes applied for a specific `CODE-REVIEW.md` entry.
5
+ - Reference the source review by its Entry ID (e.g., `CR-20260221-001`). Do NOT re-describe findings — only document actions taken.
6
+ - For finding details, the reader should consult the referenced `CODE-REVIEW.md` entry.
7
+ - Each finding is referenced as `Finding #N (Severity)` matching the review's numbering.
8
+ - Fixed findings must include `file:line` for every change made.
9
+ - Deferred findings must include rationale and a revisit trigger.
10
+ - Verification section must confirm `npm run typecheck` + `npm run build` status after fixes.
11
+ - Language: English only. Tone: Technical, concise, action-focused.
12
+
13
+ ### Entry ID Convention
14
+ - Required field for every entry: `Entry ID`.
15
+ - Format: `CF-YYYYMMDD-###`
16
+ - Example: `CF-20260222-001`
17
+ - `###` is a zero-padded sequence number for that day.
18
+
19
+ ---
20
+
21
+ ## Entry 2026-02-22
22
+
23
+ ### Entry ID
24
+ - `CF-20260222-001`
25
+
26
+ ### Source Review
27
+ - `CR-20260221-001` (CODE-REVIEW.md entry 2026-02-21)
28
+
29
+ ### Fixes Applied
30
+
31
+ 1. Finding #1 (High) — **Fixed**
32
+ - `src/lib/powerline.ts:33` — Changed `--config=~/.claude/powerline-config.json` to `--config=.claude/powerline-config.json` so the status-line command reads from the project-local path where the config is actually written.
33
+
34
+ 2. Finding #2 (Medium) — **Fixed**
35
+ - `src/lib/git.ts:3-11` — Added `hasGitIdentity()` helper that pre-checks `git config user.name` and `git config user.email`.
36
+ - `src/lib/git.ts:13-28` — Refactored `initGit()` to return `{ committed: boolean; reason?: string }`. Skips `git commit` when identity is missing and returns a descriptive reason string.
37
+
38
+ 3. Finding #3 (Medium) — **Fixed**
39
+ - `src/lib/powerline.ts:21-29` — Wrapped `JSON.parse(raw)` in try/catch; malformed `.claude/settings.json` now falls back to empty object instead of throwing.
40
+
41
+ 4. Finding #4 (Medium) — **Fixed**
42
+ - `src/lib/template.ts:38-44` — Added `checkConflicts(targetDir)` function that returns list of existing output files that would be overwritten.
43
+ - `src/steps/generation.tsx:5,61,102-113` — Imported `checkConflicts`, added yellow warning in summary phase listing files that will be overwritten before user confirms.
44
+
45
+ 5. Finding #5 (Low) — **Fixed**
46
+ - `src/lib/types.ts:64` — Added `generationSkipped: boolean` field to `WizardAnswers`.
47
+ - `src/app.tsx:49` — Added `generationSkipped: false` to `EMPTY_ANSWERS`.
48
+ - `src/app.tsx:83` — Updated `getSummary` case 5 to return `"skipped"` when `generationSkipped` is true.
49
+ - `src/steps/generation.tsx:9` — Changed `onComplete` prop type to `(partial: Partial<WizardAnswers>) => void`.
50
+ - `src/steps/generation.tsx:35` — On successful generation, calls `onComplete({ generationSkipped: false })`.
51
+ - `src/steps/generation.tsx:48` — On cancel, calls `onComplete({ generationSkipped: true })`.
52
+ - `src/app.tsx:179` — Changed `onComplete={() => handleStepComplete({})}` to `onComplete={handleStepComplete}`.
53
+
54
+ 6. Finding #6 (Low) — **Fixed**
55
+ - `templates/docs/USER-STORIES.md.hbs:1-32` — Added Handlebars `{{#if userStories.length}}` conditional with fallback starter template content when `userStories` is empty. Fallback includes example user story in Gherkin format with clear TODO instructions.
56
+
57
+ ### Deferred
58
+ None — all 6 findings fixed.
59
+
60
+ ### Verification Notes
61
+ - `npm run typecheck`: pass (0 errors)
62
+ - All fixes verified through code inspection.
63
+
64
+ ### Residual Risks / Testing Gaps
65
+ - No automated tests for `checkConflicts()` behavior.
66
+ - No automated tests for `initGit()` across machines with missing git identity.
67
+ - No automated tests for malformed `.claude/settings.json` handling.
68
+ - No automated tests asserting generation summary truthfulness when user cancels.
69
+ - No runtime test for Handlebars `{{#if userStories.length}}` fallback rendering.
70
+
71
+ ---
72
+
73
+ ## Entry 2026-02-22
74
+
75
+ ### Entry ID
76
+ - `CF-20260222-002`
77
+
78
+ ### Source Review
79
+ - `CR-20260221-002` (CODE-REVIEW.md entry 2026-02-21)
80
+
81
+ ### Fixes Applied
82
+
83
+ 1. Finding #7 (Medium) — **Fixed**
84
+ - `src/lib/git.ts:13-20` — Added `hasStagedFiles()` helper that runs `git status --porcelain`; returns `false` when index is empty.
85
+ - `src/lib/git.ts:30-33` — Added early return `{ committed: false, reason: 'Nothing to commit — directory is empty.' }` before identity check, preventing hard crash on empty-directory init.
86
+
87
+ 2. Finding #8 (Low) — **Fixed**
88
+ - `src/app.tsx:133-141` — Wrapped completion message in `answers.generationSkipped` conditional. Skip path shows neutral `"Generation was skipped — no files were written."` Scaffold path retains original project name + doc check message.
89
+
90
+ 3. Finding #6 re-raised (Low, Still Open in CR-20260221-002) — **Already Fixed**
91
+ - Covered by `CF-20260222-001` Finding #6: `templates/docs/USER-STORIES.md.hbs` Handlebars fallback added in previous fix cycle. No further action required.
92
+
93
+ ### Deferred
94
+ None.
95
+
96
+ ### Verification Notes
97
+ - `npm run typecheck`: pass (0 errors)
98
+ - `npm run build`: pass
99
+
100
+ ---
101
+
102
+ ## Entry 2026-02-22
103
+
104
+ ### Entry ID
105
+ - `CF-20260222-003`
106
+
107
+ ### Source Review
108
+ - `CR-20260221-004` (CODE-REVIEW.md entry 2026-02-21)
109
+
110
+ ### Fixes Applied
111
+
112
+ 1. Finding #9 (Low, Still Open) — **Fixed**
113
+ - `src/steps/powerline.tsx:22` — Added `gitCommitted?: boolean` to `SetupResult` interface.
114
+ - `src/steps/powerline.tsx:41-44` — `runSetup()` now stores `gitResult.committed` in `setupResult.gitCommitted`.
115
+ - `src/steps/powerline.tsx:125-133` — "Git repository initialized." only renders when `setupResult.gitCommitted` is true. When commit failed, only the yellow warning with reason is shown (no mixed success/failure messaging).
116
+
117
+ ### Deferred
118
+ None.
119
+
120
+ ### Verification Notes
121
+ - `npm run typecheck`: pass
122
+ - `npm run build`: pass
123
+
124
+ ---
package/CODE-REVIEW.md ADDED
@@ -0,0 +1,253 @@
1
+ # Code Review Log
2
+
3
+ ## Writing Standard
4
+ - Language: English only.
5
+ - Tone: Technical, concise, objective, and evidence-based.
6
+ - Ordering: Findings listed by severity (`High`, `Medium`, `Low`).
7
+ - Evidence: Every finding includes at least one concrete file reference (`path:line`).
8
+ - Actionability: Every finding includes a clear recommendation.
9
+ - Validation: Verification notes must be based on actual checks (inspection and/or command output).
10
+ - Lifecycle: Each finding includes `Status`: `New`, `Still Open`, `Fixed`, `Regressed`, or `Not Reproducible`.
11
+
12
+ ### Entry ID Convention
13
+ - Required field for every entry: `Entry ID`
14
+ - Format: `CR-YYYYMMDD-###`
15
+ - Example: `CR-20260221-001`
16
+
17
+ ---
18
+
19
+ ## Entry 2026-02-21
20
+
21
+ ### Entry ID
22
+ - `CR-20260221-001`
23
+
24
+ ### Scope
25
+ - Full review of current `procedure` CLI codebase.
26
+ - Focus areas: scaffolding safety, setup reliability, output integrity, and runtime checks.
27
+
28
+ ### Findings (ordered by severity)
29
+
30
+ 1. High - Powerline setup writes config to project-local path but references home-directory config (`Status: New`)
31
+ - `src/lib/powerline.ts:29`
32
+ - `src/lib/powerline.ts:41`
33
+ - `settings.json` is configured with `--config=~/.claude/powerline-config.json`, but setup copies config to `<targetDir>/.claude/powerline-config.json`.
34
+ - This creates a path mismatch: generated config may not be the file that the configured command reads.
35
+ - Recommendation: align both paths. Either copy config to `~/.claude/powerline-config.json` or point the status-line command at `<targetDir>/.claude/powerline-config.json`.
36
+
37
+ 2. Medium - Git bootstrap can fail on machines without global git identity (`Status: New`)
38
+ - `src/lib/git.ts:8`
39
+ - `initGit()` runs `git commit` unconditionally; this fails when `user.name`/`user.email` are not configured.
40
+ - Recommendation: pre-check git identity and show a guided fallback, or skip initial commit when identity is missing.
41
+
42
+ 3. Medium - `settings.json` parsing is not resilient to malformed existing config (`Status: New`)
43
+ - `src/lib/powerline.ts:22`
44
+ - `src/lib/powerline.ts:23`
45
+ - Existing `.claude/settings.json` is parsed without `try/catch`; malformed JSON aborts setup.
46
+ - Recommendation: wrap JSON parse in defensive handling (fallback to empty object + warning message).
47
+
48
+ 4. Medium - Generation flow can overwrite existing files without confirmation (`Status: New`)
49
+ - `src/lib/template.ts:23`
50
+ - `src/lib/template.ts:44`
51
+ - `src/steps/generation.tsx:33`
52
+ - Scaffolding writes directly into `process.cwd()` and unconditionally overwrites files such as `README.md`, `CLAUDE.md`, and docs.
53
+ - Recommendation: add collision detection and explicit overwrite confirmation (or backup/skip mode).
54
+
55
+ 5. Low - "Skip generation" path still marks generation step as completed in timeline summary (`Status: New`)
56
+ - `src/steps/generation.tsx:47`
57
+ - `src/app.tsx:82`
58
+ - `src/app.tsx:177`
59
+ - Canceling generation advances the wizard, and summary still reports `"files generated"`, which can be inaccurate.
60
+ - Recommendation: track generation result explicitly (`generated: true/false`) and render truthful summary text.
61
+
62
+ 6. Low - Generated `USER-STORIES.md` can be nearly empty in normal flow (`Status: New`)
63
+ - `src/steps/product-context.tsx:80`
64
+ - `templates/docs/USER-STORIES.md.hbs:3`
65
+ - Wizard currently sets `userStories: []` with no later collection step, so output often contains only title/header.
66
+ - Recommendation: either collect at least one story in wizard flow or generate a starter template section when `userStories` is empty.
67
+
68
+ ### Verification Notes
69
+ - `npm run lint`: pass (`tsc --noEmit`).
70
+ - `npm run build`: pass (`tsc`).
71
+ - Runtime checks performed in temp directories with compiled modules:
72
+ - `setupPowerline()` writes `.claude/powerline-config.json` but status command references `~/.claude/powerline-config.json`.
73
+ - `setupPowerline()` throws on malformed `.claude/settings.json` (`SyntaxError`).
74
+ - `initGit()` failed at `git commit` in environment without configured identity.
75
+ - `scaffoldAll()` overwrote pre-existing `README.md` content.
76
+ - `scaffoldAll()` with default wizard-shaped payload produced a mostly empty `docs/USER-STORIES.md` (`# demo — User Stories` only).
77
+
78
+ ### Residual Risks / Testing Gaps
79
+ - No automated tests for overwrite-protection behavior in generation flow.
80
+ - No automated tests for malformed `.claude/settings.json` handling.
81
+ - No automated tests for `initGit()` behavior across machines with missing git identity.
82
+ - No tests asserting generation summary truthfulness when user cancels.
83
+
84
+ ---
85
+
86
+ ## Entry 2026-02-21
87
+
88
+ ### Entry ID
89
+ - `CR-20260221-002`
90
+
91
+ ### Supersedes
92
+ - `CR-20260221-001`
93
+
94
+ ### Scope
95
+ - Validate `CR-20260221-001` findings against current code.
96
+ - Perform a fresh review pass for post-fix regressions and remaining issues.
97
+
98
+ ### Validation Matrix
99
+ | Finding # | Previous Severity | Current Status | Evidence | Notes |
100
+ |-----------|-------------------|----------------|----------|-------|
101
+ | 1 | High | Fixed | `src/lib/powerline.ts:34`, `src/lib/powerline.ts:46` | Status-line command now points to project-local `.claude/powerline-config.json`, matching copied destination. |
102
+ | 2 | Medium | Fixed | `src/lib/git.ts:13`, `src/lib/git.ts:19`, `src/lib/git.ts:27` | `initGit()` now checks identity and can return `{ committed: false, reason }` instead of failing immediately for missing identity. |
103
+ | 3 | Medium | Fixed | `src/lib/powerline.ts:22`, `src/lib/powerline.ts:25` | Existing `settings.json` parse is wrapped in `try/catch`; malformed JSON no longer aborts setup. |
104
+ | 4 | Medium | Fixed | `src/lib/template.ts:38`, `src/steps/generation.tsx:61`, `src/steps/generation.tsx:108` | Generation step now detects collisions and explicitly warns users before proceeding. |
105
+ | 5 | Low | Fixed | `src/steps/generation.tsx:48`, `src/app.tsx:84` | Generation skip state is tracked and reflected in step summary (`"skipped"`). |
106
+ | 6 | Low | Still Open | `src/steps/product-context.tsx:80`, `templates/docs/USER-STORIES.md.hbs:3` | `userStories` remains hardcoded to empty with no collection step. |
107
+
108
+ ### Findings (ordered by severity)
109
+ 1. Medium - Git init flow can hard-fail when Generation is skipped in an empty directory (`Finding #7`, `Status: New`)
110
+ - `src/lib/git.ts:26`
111
+ - `src/steps/powerline.tsx:47`
112
+ - `initGit()` always attempts a commit. If no files exist (e.g., user skips generation in an empty folder), `git commit` fails and Powerline step enters unrecoverable error state.
113
+ - Recommendation: allow empty initial commit (`--allow-empty`) or skip commit when index is empty while still completing setup.
114
+
115
+ 2. Low - Final completion message can be misleading when Generation was skipped (`Finding #8`, `Status: New`)
116
+ - `src/app.tsx:134`
117
+ - `src/app.tsx:137`
118
+ - Completion text always says project "has been scaffolded" and prompts to check generated docs, even when step 6 was skipped.
119
+ - Recommendation: gate final message content on `generationSkipped` and show a neutral completion message for skip flow.
120
+
121
+ 3. Low - Generated `USER-STORIES.md` can still be nearly empty (`Finding #6`, `Status: Still Open`)
122
+ - `src/steps/product-context.tsx:80`
123
+ - `templates/docs/USER-STORIES.md.hbs:3`
124
+ - Wizard still outputs `userStories: []`, so file may contain only title/header.
125
+ - Recommendation: collect user stories during wizard flow or render a starter section/template when array is empty.
126
+
127
+ ### Verification Notes
128
+ - `npm run typecheck`: pass.
129
+ - `npm run build`: pass.
130
+ - Runtime probes:
131
+ - `setupPowerline()` now writes a status command using `--config=.claude/powerline-config.json` and succeeds with malformed existing settings (parse fallback observed).
132
+ - `initGit()` succeeds when files exist; still fails on empty repo commit path.
133
+
134
+ ### Residual Risks / Testing Gaps
135
+ - No automated test for `initGit()` empty-index behavior.
136
+ - No integration test for skip-generation + git-init flow.
137
+ - No automated test asserting end-screen messaging for `generationSkipped`.
138
+
139
+ ---
140
+
141
+ ## Entry 2026-02-21
142
+
143
+ ### Entry ID
144
+ - `CR-20260221-003`
145
+
146
+ ### Supersedes
147
+ - `CR-20260221-002`
148
+
149
+ ### Scope
150
+ - Validate `CR-20260221-002` findings against current code.
151
+ - Perform a new post-fix review pass for regressions and unresolved issues.
152
+
153
+ ### Validation Matrix
154
+ | Finding # | Previous Severity | Current Status | Evidence | Notes |
155
+ |-----------|-------------------|----------------|----------|-------|
156
+ | 7 | Medium | Fixed | `src/lib/git.ts:28`, `src/lib/git.ts:29` | Empty-index case is now handled; commit is skipped with a structured reason. |
157
+ | 8 | Low | Fixed | `src/app.tsx:133`, `src/app.tsx:134`, `src/app.tsx:137` | Final completion messaging now reflects `generationSkipped`. |
158
+ | 6 | Low | Still Open | `src/steps/product-context.tsx:80`, `templates/docs/USER-STORIES.md.hbs:3` | User stories are still not collected in wizard flow. |
159
+
160
+ ### Findings (ordered by severity)
161
+ 1. Low - Powerline step can claim git initialized even when commit was skipped (`Finding #9`, `Status: New`)
162
+ - `src/steps/powerline.tsx:125`
163
+ - `src/steps/powerline.tsx:127`
164
+ - `src/steps/powerline.tsx:130`
165
+ - `src/steps/powerline.tsx:132`
166
+ - UI always shows "Git repository initialized." when user selected git setup (`wantGit === true`), even if `initGit()` returned `committed: false` (e.g., empty directory or missing identity). This creates mixed success/failure messaging.
167
+ - Recommendation: track commit outcome separately (e.g., `gitCommitted`) and render success text only when true; otherwise show warning-only state.
168
+
169
+ 2. Low - Generated `USER-STORIES.md` can still be nearly empty (`Finding #6`, `Status: Still Open`)
170
+ - `src/steps/product-context.tsx:80`
171
+ - `templates/docs/USER-STORIES.md.hbs:3`
172
+ - Wizard still outputs `userStories: []`, so generated file may contain only title/header.
173
+ - Recommendation: collect at least one story in wizard flow or render a fallback starter template when empty.
174
+
175
+ ### Verification Notes
176
+ - `npm run typecheck`: pass.
177
+ - `npm run build`: pass.
178
+ - Runtime probe:
179
+ - `initGit()` in empty directory now returns `{ committed: false, reason: "Nothing to commit — directory is empty." }` instead of throwing.
180
+
181
+ ### Residual Risks / Testing Gaps
182
+ - No UI test covering mixed-result messaging in Powerline step (`wantGit` true + `committed` false).
183
+ - No automated test asserting non-empty/default content for generated `docs/USER-STORIES.md`.
184
+
185
+ ---
186
+
187
+ ## Entry 2026-02-21
188
+
189
+ ### Entry ID
190
+ - `CR-20260221-004`
191
+
192
+ ### Supersedes
193
+ - `CR-20260221-003`
194
+
195
+ ### Scope
196
+ - Correct review status drift by reconciling against latest `CODE-FIXED.md`.
197
+ - Run a fresh current-state review after reconciliation.
198
+
199
+ ### Validation Matrix
200
+ | Finding # | Previous Severity | Current Status | Evidence | Notes |
201
+ |-----------|-------------------|----------------|----------|-------|
202
+ | 6 | Low | Fixed | `CODE-FIXED.md:54`, `templates/docs/USER-STORIES.md.hbs:3`, `templates/docs/USER-STORIES.md.hbs:23` | Previously mis-labeled as open in `CR-20260221-003`; fix existed in `CF-20260222-001` and template fallback is present. |
203
+ | 9 | Low | Still Open | `src/steps/powerline.tsx:125`, `src/steps/powerline.tsx:130` | Success and warning can render together when commit is skipped. |
204
+
205
+ ### Findings (ordered by severity)
206
+ 1. Low - Powerline step can claim git initialized even when commit was skipped (`Finding #9`, `Status: Still Open`)
207
+ - `src/steps/powerline.tsx:125`
208
+ - `src/steps/powerline.tsx:127`
209
+ - `src/steps/powerline.tsx:130`
210
+ - `src/steps/powerline.tsx:132`
211
+ - UI always shows "Git repository initialized." when `wantGit` is true, even when `initGit()` reports `{ committed: false, reason }`.
212
+ - Recommendation: track commit outcome (e.g., `gitCommitted`) and render the success line only when a commit actually succeeded.
213
+
214
+ ### Verification Notes
215
+ - Procedure compliance: read latest `CODE-REVIEW.md` and latest `CODE-FIXED.md` before this review.
216
+ - `npm run typecheck`: pass.
217
+ - `npm run build`: pass.
218
+ - Runtime probe: scaffolding with empty `userStories` now renders fallback user-story starter content (`fallback-ok`), confirming `Finding #6` is fixed.
219
+
220
+ ### Residual Risks / Testing Gaps
221
+ - No UI test for Powerline mixed-result messaging (`wantGit` true + `committed` false).
222
+
223
+ ---
224
+
225
+ ## Entry 2026-02-21
226
+
227
+ ### Entry ID
228
+ - `CR-20260221-005`
229
+
230
+ ### Supersedes
231
+ - `CR-20260221-004`
232
+
233
+ ### Scope
234
+ - Fresh review cycle after `CF-20260222-003`.
235
+ - Validate open findings against latest code and current build/typecheck status.
236
+
237
+ ### Validation Matrix
238
+ | Finding # | Previous Severity | Current Status | Evidence | Notes |
239
+ |-----------|-------------------|----------------|----------|-------|
240
+ | 9 | Low | Fixed | `CODE-FIXED.md:112`, `src/steps/powerline.tsx:22`, `src/steps/powerline.tsx:127`, `src/steps/powerline.tsx:132` | Powerline now separates success and warning states by commit outcome (`gitCommitted`). |
241
+ | 6 | Low | Fixed | `CODE-FIXED.md:54`, `templates/docs/USER-STORIES.md.hbs:3`, `templates/docs/USER-STORIES.md.hbs:23` | USER-STORIES fallback remains in place for empty `userStories`. |
242
+
243
+ ### Findings (ordered by severity)
244
+ - No new functional findings identified in this review cycle.
245
+
246
+ ### Verification Notes
247
+ - Procedure compliance: read latest `CODE-REVIEW.md` and latest `CODE-FIXED.md` before review.
248
+ - `npm run typecheck`: pass.
249
+ - `npm run build`: pass.
250
+ - Code inspection confirms `CF-20260222-003` fix is present in current `src/steps/powerline.tsx`.
251
+
252
+ ### Residual Risks / Testing Gaps
253
+ - No automated UI tests currently cover end-to-end Powerline branching (`gitCommitted` true/false).