maxsimcli 3.5.3 → 3.7.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 (37) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/assets/CHANGELOG.md +21 -0
  3. package/dist/assets/dashboard/server.js +1 -1
  4. package/dist/assets/templates/agents/maxsim-code-reviewer.md +169 -0
  5. package/dist/assets/templates/agents/maxsim-debugger.md +47 -0
  6. package/dist/assets/templates/agents/maxsim-executor.md +113 -0
  7. package/dist/assets/templates/agents/maxsim-phase-researcher.md +46 -0
  8. package/dist/assets/templates/agents/maxsim-plan-checker.md +45 -0
  9. package/dist/assets/templates/agents/maxsim-planner.md +48 -0
  10. package/dist/assets/templates/agents/maxsim-spec-reviewer.md +150 -0
  11. package/dist/assets/templates/agents/maxsim-verifier.md +43 -0
  12. package/dist/assets/templates/commands/maxsim/init-existing.md +42 -0
  13. package/dist/assets/templates/skills/systematic-debugging/SKILL.md +118 -0
  14. package/dist/assets/templates/skills/tdd/SKILL.md +118 -0
  15. package/dist/assets/templates/skills/verification-before-completion/SKILL.md +102 -0
  16. package/dist/assets/templates/workflows/init-existing.md +1099 -0
  17. package/dist/cli.cjs +55 -4
  18. package/dist/cli.cjs.map +1 -1
  19. package/dist/cli.js +2 -1
  20. package/dist/cli.js.map +1 -1
  21. package/dist/core/core.js +1 -1
  22. package/dist/core/core.js.map +1 -1
  23. package/dist/core/index.d.ts +2 -2
  24. package/dist/core/index.d.ts.map +1 -1
  25. package/dist/core/index.js +2 -1
  26. package/dist/core/index.js.map +1 -1
  27. package/dist/core/init.d.ts +24 -2
  28. package/dist/core/init.d.ts.map +1 -1
  29. package/dist/core/init.js +61 -0
  30. package/dist/core/init.js.map +1 -1
  31. package/dist/core/roadmap.js +2 -2
  32. package/dist/core/roadmap.js.map +1 -1
  33. package/dist/install.cjs +38 -0
  34. package/dist/install.cjs.map +1 -1
  35. package/dist/install.js +49 -0
  36. package/dist/install.js.map +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,1099 @@
1
+ <purpose>
2
+ Initialize MAXSIM in an existing codebase through a scan-first-then-ask flow. This workflow detects existing `.planning/` state, runs codebase analysis (4 mapper agents), validates README against scan findings, asks scan-informed questions with smart defaults, and generates stage-aware planning documents. Supports `--auto` mode for fully autonomous initialization.
3
+
4
+ Output: `.planning/` directory with config.json, PROJECT.md, REQUIREMENTS.md, ROADMAP.md, STATE.md, and codebase/ analysis docs.
5
+ </purpose>
6
+
7
+ <required_reading>
8
+ Read all files referenced by the invoking prompt's execution_context before starting.
9
+ </required_reading>
10
+
11
+ <auto_mode>
12
+ ## Auto Mode Detection
13
+
14
+ Check if `--auto` flag is present in $ARGUMENTS.
15
+
16
+ **If auto mode:**
17
+ - Skip all questions (conflict resolution, config, existing state, future direction, milestone)
18
+ - Run full codebase scan (always)
19
+ - Infer everything from code: purpose, stack, architecture, stage, vision
20
+ - Auto mode does NOT require an idea document (unlike new-project's --auto)
21
+ - Default config: stage=MVP, branching_strategy=none, model_profile=balanced, mode=yolo, depth=standard
22
+ - After scan: generate all documents with smart inferences
23
+ - Add `<!-- Auto-generated by /maxsim:init-existing --auto. Review recommended. -->` comment at top of each generated document
24
+ - Auto mode still creates all documents: config.json, PROJECT.md, REQUIREMENTS.md, ROADMAP.md, STATE.md
25
+ - If `.planning/` exists: auto mode defaults to merge behavior (keep existing, fill gaps, re-scan)
26
+ - If `.planning/` does not exist: create fresh
27
+ </auto_mode>
28
+
29
+ <process>
30
+
31
+ ## Step 1: Setup (Init Context)
32
+
33
+ **MANDATORY FIRST STEP — Execute these checks before ANY user interaction:**
34
+
35
+ ```bash
36
+ INIT=$(node ~/.claude/maxsim/bin/maxsim-tools.cjs init init-existing)
37
+ ```
38
+
39
+ Parse JSON for: `researcher_model`, `synthesizer_model`, `roadmapper_model`, `mapper_model`, `commit_docs`, `project_exists`, `planning_exists`, `planning_files`, `has_codebase_map`, `has_existing_code`, `has_package_file`, `has_git`, `has_readme`, `conflict_detected`, `existing_file_count`, `brave_search_available`, `parallelization`, `project_path`, `codebase_dir`.
40
+
41
+ **If `has_existing_code` is false AND `has_package_file` is false:**
42
+
43
+ ```
44
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
45
+ MAXSIM ► NO CODE DETECTED
46
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
47
+
48
+ No source code or package manifest detected in this directory.
49
+ For greenfield projects, use /maxsim:new-project instead.
50
+ ```
51
+
52
+ Use AskUserQuestion:
53
+ - header: "Continue?"
54
+ - question: "No code detected. Continue with init-existing anyway, or switch to new-project?"
55
+ - options:
56
+ - "Continue anyway" -- I know there's code here (maybe in subdirectories)
57
+ - "Switch to /maxsim:new-project" -- This is a greenfield project
58
+
59
+ **If "Switch":** Print "Run `/maxsim:new-project` to start a greenfield project." and exit.
60
+ **If "Continue":** Proceed to Step 2.
61
+
62
+ **In auto mode:** If no code detected, proceed anyway (scan will find what it can).
63
+
64
+ **If `has_git` is false:** Initialize git:
65
+ ```bash
66
+ git init
67
+ ```
68
+
69
+ ## Step 2: Conflict Resolution
70
+
71
+ **If auto mode:** Skip dialog. If `conflict_detected`, use merge behavior automatically (keep existing files, fill gaps, always re-scan codebase). Proceed to Step 3.
72
+
73
+ **If `conflict_detected` is false:** Create `.planning/` directory, proceed to Step 3:
74
+ ```bash
75
+ mkdir -p .planning
76
+ ```
77
+
78
+ **If `conflict_detected` is true:**
79
+
80
+ Show existing files:
81
+ ```bash
82
+ ls -la .planning/ 2>/dev/null
83
+ ```
84
+
85
+ Present conflict dialog:
86
+
87
+ ```
88
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
89
+ MAXSIM ► EXISTING .planning/ DETECTED
90
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
91
+
92
+ Found {existing_file_count} files in .planning/:
93
+ [list files with last-modified dates from ls output]
94
+
95
+ How should I proceed?
96
+ ```
97
+
98
+ Use AskUserQuestion:
99
+ - header: "Conflict"
100
+ - question: "`.planning/` already exists. How should I proceed?"
101
+ - options:
102
+ - "Merge (Recommended)" -- Keep existing files, fill gaps, re-scan codebase
103
+ - "Overwrite" -- Delete existing .planning/ and start fresh
104
+ - "Cancel" -- Exit (run /maxsim:health to diagnose)
105
+
106
+ **On Merge:**
107
+ - Note which core files exist: config.json, PROJECT.md, REQUIREMENTS.md, ROADMAP.md, STATE.md
108
+ - For each missing file: will be created in Step 9
109
+ - For each existing file: check for required section headers in Step 9. If missing headers, fill gaps
110
+ - Always re-scan codebase (Step 3 deletes and recreates `.planning/codebase/`)
111
+ - Proceed to Step 3
112
+
113
+ **On Overwrite:**
114
+
115
+ Use AskUserQuestion:
116
+ - header: "Backup"
117
+ - question: "Back up existing .planning/ to .planning.bak/ before overwrite?"
118
+ - options:
119
+ - "Yes (Recommended)" -- Save backup to .planning.bak/
120
+ - "No" -- Delete without backup
121
+
122
+ If yes:
123
+ ```bash
124
+ rm -rf .planning.bak/ 2>/dev/null
125
+ mv .planning/ .planning.bak/
126
+ mkdir -p .planning
127
+ ```
128
+
129
+ If no:
130
+ ```bash
131
+ rm -rf .planning/
132
+ mkdir -p .planning
133
+ ```
134
+
135
+ Proceed to Step 3.
136
+
137
+ **On Cancel:**
138
+ Print: "Cancelled. Run `/maxsim:health` to diagnose your .planning/ state."
139
+ Exit workflow.
140
+
141
+ ## Step 3: Codebase Scan
142
+
143
+ Always runs, regardless of conflict mode. The codebase scan is always fresh.
144
+
145
+ ```
146
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
147
+ MAXSIM ► SCANNING CODEBASE
148
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
149
+ ```
150
+
151
+ Ensure `.planning/codebase/` exists (delete and recreate if exists):
152
+ ```bash
153
+ rm -rf .planning/codebase/
154
+ mkdir -p .planning/codebase/
155
+ ```
156
+
157
+ ```
158
+ ◆ Spawning 4 codebase mappers in parallel...
159
+ → Tech mapper (STACK.md)
160
+ → Architecture mapper (ARCHITECTURE.md)
161
+ → Quality mapper (CONVENTIONS.md)
162
+ → Concerns mapper (CONCERNS.md)
163
+ ```
164
+
165
+ Spawn 4 mapper agents using the Task tool. Follow the EXACT pattern from `templates/workflows/map-codebase.md`.
166
+
167
+ **CRITICAL:** Spawn mapper agents directly using the Task tool. Do NOT invoke `/maxsim:map-codebase` command (that would exit the current workflow context).
168
+
169
+ **Agent 1: Tech Focus**
170
+
171
+ ```
172
+ Task(
173
+ subagent_type="maxsim-codebase-mapper",
174
+ model="{mapper_model}",
175
+ run_in_background=true,
176
+ description="Map codebase tech stack",
177
+ prompt="Focus: tech
178
+
179
+ Analyze this codebase for technology stack and external integrations.
180
+
181
+ Write these documents to .planning/codebase/:
182
+ - STACK.md - Languages, runtime, frameworks, dependencies, configuration
183
+
184
+ Explore thoroughly. Write documents directly using templates. Return confirmation only."
185
+ )
186
+ ```
187
+
188
+ **Agent 2: Architecture Focus**
189
+
190
+ ```
191
+ Task(
192
+ subagent_type="maxsim-codebase-mapper",
193
+ model="{mapper_model}",
194
+ run_in_background=true,
195
+ description="Map codebase architecture",
196
+ prompt="Focus: arch
197
+
198
+ Analyze this codebase architecture and directory structure.
199
+
200
+ Write these documents to .planning/codebase/:
201
+ - ARCHITECTURE.md - Pattern, layers, data flow, abstractions, entry points
202
+
203
+ Explore thoroughly. Write documents directly using templates. Return confirmation only."
204
+ )
205
+ ```
206
+
207
+ **Agent 3: Quality Focus**
208
+
209
+ ```
210
+ Task(
211
+ subagent_type="maxsim-codebase-mapper",
212
+ model="{mapper_model}",
213
+ run_in_background=true,
214
+ description="Map codebase conventions",
215
+ prompt="Focus: quality
216
+
217
+ Analyze this codebase for coding conventions and testing patterns.
218
+
219
+ Write these documents to .planning/codebase/:
220
+ - CONVENTIONS.md - Code style, naming, patterns, error handling
221
+
222
+ Explore thoroughly. Write documents directly using templates. Return confirmation only."
223
+ )
224
+ ```
225
+
226
+ **Agent 4: Concerns Focus**
227
+
228
+ ```
229
+ Task(
230
+ subagent_type="maxsim-codebase-mapper",
231
+ model="{mapper_model}",
232
+ run_in_background=true,
233
+ description="Map codebase concerns",
234
+ prompt="Focus: concerns
235
+
236
+ Analyze this codebase for technical debt, known issues, and areas of concern.
237
+
238
+ Write this document to .planning/codebase/:
239
+ - CONCERNS.md - Tech debt, bugs, security, performance, fragile areas
240
+
241
+ Explore thoroughly. Write document directly using template. Return confirmation only."
242
+ )
243
+ ```
244
+
245
+ If `parallelization` is true, spawn all 4 with `run_in_background=true` (parallel). Otherwise spawn sequentially (no `run_in_background`).
246
+
247
+ Wait for all agents to complete.
248
+
249
+ Print per-agent completion status:
250
+ ```
251
+ ✓ Tech mapper complete: STACK.md
252
+ ✓ Architecture mapper complete: ARCHITECTURE.md
253
+ ✓ Quality mapper complete: CONVENTIONS.md
254
+ ✓ Concerns mapper complete: CONCERNS.md
255
+ ```
256
+
257
+ After all agents complete, also create a file tree overview:
258
+
259
+ ```bash
260
+ find . -type f | grep -v node_modules | grep -v .git | grep -v .planning | grep -v __pycache__ | grep -v .next | grep -v dist/ | grep -v build/ | head -200 > .planning/codebase/STRUCTURE.md
261
+ ```
262
+
263
+ Then wrap it with a header:
264
+
265
+ Read `.planning/codebase/STRUCTURE.md`, prepend:
266
+
267
+ ```markdown
268
+ # Codebase File Structure
269
+
270
+ **Generated:** [date]
271
+
272
+ ## File Tree
273
+
274
+ ```
275
+ [file tree content]
276
+ ```
277
+
278
+ ---
279
+ *Structure snapshot: [date]*
280
+ ```
281
+
282
+ Verify all documents created:
283
+ ```bash
284
+ ls -la .planning/codebase/
285
+ wc -l .planning/codebase/*.md
286
+ ```
287
+
288
+ If any document is missing or empty, note the failure and continue.
289
+
290
+ ## Step 4: README Validation
291
+
292
+ **If `has_readme` is true:**
293
+
294
+ Read README.md:
295
+ ```bash
296
+ cat README.md
297
+ ```
298
+
299
+ Read key scan findings from `.planning/codebase/STACK.md` and `.planning/codebase/ARCHITECTURE.md`.
300
+
301
+ Compare README claims against scan findings. **Only flag clear contradictions:**
302
+ - README says "React app" but code is all Python → flag
303
+ - README describes features not visible in code → do NOT flag (different scopes are normal)
304
+ - README mentions deprecated tech but code uses current versions → flag
305
+ - README is empty or minimal → note for later (PROJECT.md will capture this)
306
+
307
+ Store discrepancy notes in a variable for use in Steps 6 and 9.
308
+
309
+ **If `has_readme` is false:** Skip. Note that no README exists for Step 9 context.
310
+
311
+ ## Step 5: Config Questions
312
+
313
+ **If auto mode:** Skip. Use defaults and write config:
314
+ ```json
315
+ {
316
+ "mode": "yolo",
317
+ "depth": "standard",
318
+ "parallelization": true,
319
+ "commit_docs": false,
320
+ "model_profile": "balanced",
321
+ "workflow": {
322
+ "research": true,
323
+ "plan_check": true,
324
+ "verifier": true
325
+ }
326
+ }
327
+ ```
328
+
329
+ Write `.planning/config.json` with defaults and proceed to Step 9 (document generation).
330
+
331
+ **If interactive mode:**
332
+
333
+ ```
334
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
335
+ MAXSIM ► CONFIGURATION
336
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
337
+ ```
338
+
339
+ **Check for global defaults** at `~/.maxsim/defaults.json`. If the file exists, offer to use saved defaults:
340
+
341
+ ```
342
+ AskUserQuestion([
343
+ {
344
+ question: "Use your saved default settings? (from ~/.maxsim/defaults.json)",
345
+ header: "Defaults",
346
+ multiSelect: false,
347
+ options: [
348
+ { label: "Yes (Recommended)", description: "Use saved defaults, skip settings questions" },
349
+ { label: "No", description: "Configure settings manually" }
350
+ ]
351
+ }
352
+ ])
353
+ ```
354
+
355
+ If "Yes": read `~/.maxsim/defaults.json`, use those values, skip to **Write config.json** below.
356
+
357
+ If "No" or defaults.json doesn't exist, ask:
358
+
359
+ **Round 1 -- Core settings:**
360
+
361
+ ```
362
+ AskUserQuestion([
363
+ {
364
+ header: "Mode",
365
+ question: "How do you want to work?",
366
+ multiSelect: false,
367
+ options: [
368
+ { label: "YOLO (Recommended)", description: "Auto-approve, just execute" },
369
+ { label: "Interactive", description: "Confirm at each step" }
370
+ ]
371
+ },
372
+ {
373
+ header: "Depth",
374
+ question: "How thorough should planning be?",
375
+ multiSelect: false,
376
+ options: [
377
+ { label: "Quick", description: "Ship fast (3-5 phases, 1-3 plans each)" },
378
+ { label: "Standard (Recommended)", description: "Balanced scope and speed (5-8 phases, 3-5 plans each)" },
379
+ { label: "Comprehensive", description: "Thorough coverage (8-12 phases, 5-10 plans each)" }
380
+ ]
381
+ },
382
+ {
383
+ header: "AI Models",
384
+ question: "Which AI models for planning agents?",
385
+ multiSelect: false,
386
+ options: [
387
+ { label: "Balanced (Recommended)", description: "Sonnet for most agents -- good quality/cost ratio" },
388
+ { label: "Quality", description: "Opus for research/roadmap -- higher cost, deeper analysis" },
389
+ { label: "Budget", description: "Haiku where possible -- fastest, lowest cost" }
390
+ ]
391
+ }
392
+ ])
393
+ ```
394
+
395
+ **Round 2 -- Git and branching:**
396
+
397
+ Auto-detect branching strategy from git:
398
+ ```bash
399
+ git branch -a 2>/dev/null
400
+ ```
401
+
402
+ If feature/* or develop branches exist, suggest that strategy. Otherwise default to 'none'.
403
+
404
+ ```
405
+ AskUserQuestion([
406
+ {
407
+ header: "Git Tracking",
408
+ question: "Commit planning docs to git?",
409
+ multiSelect: false,
410
+ options: [
411
+ { label: "Yes (Recommended)", description: "Planning docs tracked in version control" },
412
+ { label: "No", description: "Keep .planning/ local-only (add to .gitignore)" }
413
+ ]
414
+ }
415
+ ])
416
+ ```
417
+
418
+ **Round 3 -- Workflow agents:**
419
+
420
+ ```
421
+ AskUserQuestion([
422
+ {
423
+ header: "Research",
424
+ question: "Research before planning each phase? (adds tokens/time)",
425
+ multiSelect: false,
426
+ options: [
427
+ { label: "Yes (Recommended)", description: "Investigate domain, find patterns, surface gotchas" },
428
+ { label: "No", description: "Plan directly from requirements" }
429
+ ]
430
+ },
431
+ {
432
+ header: "Plan Check",
433
+ question: "Verify plans will achieve their goals? (adds tokens/time)",
434
+ multiSelect: false,
435
+ options: [
436
+ { label: "Yes (Recommended)", description: "Catch gaps before execution starts" },
437
+ { label: "No", description: "Execute plans without verification" }
438
+ ]
439
+ },
440
+ {
441
+ header: "Verifier",
442
+ question: "Verify work satisfies requirements after each phase? (adds tokens/time)",
443
+ multiSelect: false,
444
+ options: [
445
+ { label: "Yes (Recommended)", description: "Confirm deliverables match phase goals" },
446
+ { label: "No", description: "Trust execution, skip verification" }
447
+ ]
448
+ }
449
+ ])
450
+ ```
451
+
452
+ **Write config.json:**
453
+
454
+ ```json
455
+ {
456
+ "mode": "[yolo|interactive]",
457
+ "depth": "[quick|standard|comprehensive]",
458
+ "parallelization": true,
459
+ "commit_docs": [true|false],
460
+ "model_profile": "[quality|balanced|budget]",
461
+ "workflow": {
462
+ "research": [true|false],
463
+ "plan_check": [true|false],
464
+ "verifier": [true|false]
465
+ }
466
+ }
467
+ ```
468
+
469
+ **If commit_docs = No:** Add `.planning/` to `.gitignore`.
470
+
471
+ Write `.planning/config.json`:
472
+ ```bash
473
+ mkdir -p .planning
474
+ ```
475
+ Use the Write tool to create `.planning/config.json`.
476
+
477
+ ## Step 6: Existing State Confirmation
478
+
479
+ **If auto mode:** Skip. Use scan findings as-is. Proceed to Step 9.
480
+
481
+ Read the scan outputs:
482
+ ```bash
483
+ cat .planning/codebase/STACK.md
484
+ cat .planning/codebase/ARCHITECTURE.md
485
+ cat .planning/codebase/CONVENTIONS.md
486
+ cat .planning/codebase/CONCERNS.md
487
+ ```
488
+
489
+ Present scan findings as a "new developer onboarding overview":
490
+
491
+ ```
492
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
493
+ MAXSIM ► CODEBASE SCAN COMPLETE
494
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
495
+
496
+ ## Your Project
497
+
498
+ **Purpose:** [Inferred from README + ARCHITECTURE.md analysis]
499
+ **Tech Stack:** [From STACK.md -- e.g., React 18 + TypeScript 5.3, Express.js backend]
500
+ **Architecture:** [From ARCHITECTURE.md -- e.g., Monorepo with 3 packages]
501
+ **Key Patterns:** [From CONVENTIONS.md -- e.g., repository pattern, React hooks]
502
+ **Known Concerns:** [From CONCERNS.md -- e.g., 12 TODOs, no auth test coverage]
503
+
504
+ Confidence: ~85% -- some inferences may need correction.
505
+ ```
506
+
507
+ Include confidence qualifiers for uncertain findings:
508
+ - Stack detection from package.json = HIGH confidence
509
+ - Architecture inference from file structure = MEDIUM confidence
510
+ - Purpose inference from README = MEDIUM-HIGH confidence
511
+ - Pattern inference from code sampling = MEDIUM confidence
512
+
513
+ If README discrepancies were found in Step 4, flag them:
514
+ ```
515
+ Warning: README Discrepancy: Your README describes [X] but the code implements [Y]. Which is current?
516
+ ```
517
+
518
+ Ask user to confirm or correct via AskUserQuestion:
519
+ - header: "Scan"
520
+ - question: "Does this look right? Correct anything that's wrong."
521
+ - options:
522
+ - "Looks correct" -- Proceed with these findings
523
+ - "Some corrections" -- Let me fix some details
524
+
525
+ If "Some corrections": ask "What needs correcting?" (freeform), capture corrections, apply to working context.
526
+
527
+ ## Step 7: Future Direction Questions
528
+
529
+ **If auto mode:** Skip. Generate generic "continue development" goals. Proceed to Step 9.
530
+
531
+ Ask these questions sequentially using AskUserQuestion:
532
+
533
+ **Question 1: Pain Points**
534
+
535
+ Use AskUserQuestion:
536
+ - header: "Pain Points"
537
+ - question: "What pain points or issues brought you to MAXSIM?"
538
+ - options:
539
+ - "Codebase complexity" -- Hard to track what's where, need structure
540
+ - "No planning" -- Building ad-hoc, want a roadmap
541
+ - "Tech debt" -- Need organized approach to cleanup
542
+ - "New features" -- Want to add features systematically
543
+ - "Other" -- Let me explain
544
+
545
+ If "Other": capture freeform response.
546
+
547
+ **Question 2: Project Stage**
548
+
549
+ Infer default from scan: tests exist + CI config = production; some tests = MVP; no tests = prototype.
550
+
551
+ Use AskUserQuestion:
552
+ - header: "Stage"
553
+ - question: "What stage is your project in?"
554
+ - options:
555
+ - "Prototype" -- Early exploration, things change rapidly
556
+ - "MVP" -- Core features working, refining toward release
557
+ - "Production" -- Users depend on it, stability matters
558
+ - "Maintenance" -- Stable, focused on fixes and incremental improvements
559
+
560
+ **Question 3: Production Sub-Questions (only if stage = Production or Maintenance)**
561
+
562
+ If the user selected Production or Maintenance:
563
+
564
+ Use AskUserQuestion:
565
+ - header: "Constraints"
566
+ - question: "What absolutely cannot be broken? (These become MUST NOT requirements)"
567
+ - options:
568
+ - "Let me describe" -- I'll list specific things
569
+
570
+ Capture their response (freeform). These become MUST NOT entries in REQUIREMENTS.md.
571
+
572
+ Use AskUserQuestion:
573
+ - header: "Deployment"
574
+ - question: "Deployment requirements?"
575
+ - options:
576
+ - "Zero-downtime required" -- Can't take the service down for deploys
577
+ - "Downtime OK" -- Brief maintenance windows are acceptable
578
+ - "No deployments planned" -- Not deploying changes to production
579
+
580
+ Use AskUserQuestion:
581
+ - header: "Staging"
582
+ - question: "Do you have a staging environment?"
583
+ - options:
584
+ - "Yes" -- Changes go through staging first
585
+ - "No" -- Deploy directly to production
586
+ - "Partial" -- Some things have staging, others don't
587
+
588
+ Use AskUserQuestion:
589
+ - header: "Rollback"
590
+ - question: "Is a rollback plan needed for changes?"
591
+ - options:
592
+ - "Yes" -- Must be able to undo any change quickly
593
+ - "No" -- Forward-fix is acceptable
594
+ - "Depends" -- For some changes yes, others no
595
+
596
+ **Question 4: General Constraints**
597
+
598
+ Use AskUserQuestion:
599
+ - header: "Limits"
600
+ - question: "What constraints should I know about? (deadlines, backward compatibility, things that can't change)"
601
+ - options:
602
+ - "No major constraints" -- Flexible on approach
603
+ - "Some constraints" -- Let me describe them
604
+
605
+ If "Some constraints": capture freeform response.
606
+
607
+ **Question 5: Missing Context**
608
+
609
+ Use AskUserQuestion:
610
+ - header: "Context"
611
+ - question: "Is there anything the scan may have missed? (external integrations, business rules, organizational constraints)"
612
+ - options:
613
+ - "Scan covered it" -- Nothing major missing
614
+ - "Yes, some things" -- Let me add context
615
+
616
+ If "Yes, some things": capture freeform response.
617
+
618
+ **Question 6: Vision**
619
+
620
+ Ask inline (freeform, NOT AskUserQuestion):
621
+
622
+ "What is your vision for this project? What are you trying to build? No time horizon needed -- just purpose and direction."
623
+
624
+ Wait for response.
625
+
626
+ ## Step 8: Milestone Suggestion
627
+
628
+ **If auto mode:** Generate a milestone name from the inferred project purpose. Proceed to Step 9.
629
+
630
+ Synthesize all gathered information and suggest a first milestone:
631
+
632
+ ```
633
+ Based on what you have and where you're going, I'd suggest:
634
+
635
+ **Milestone: [Suggested Name]**
636
+ Reasoning: [Why this milestone makes sense given current state and goals]
637
+ ```
638
+
639
+ Use AskUserQuestion:
640
+ - header: "Milestone"
641
+ - question: "Does this milestone name work?"
642
+ - options:
643
+ - "Yes" -- Use this name
644
+ - "Rename" -- I have a different name in mind
645
+
646
+ If "Rename": ask "What would you like to call it?" (freeform), capture response.
647
+
648
+ ## Step 9: Document Generation
649
+
650
+ Generate all planning documents. In merge mode, check if each file exists first. For existing files, check for required section headers. If a required header is missing, add the section. If present, leave it. For missing files, create from scratch.
651
+
652
+ **Merge mode section-detection rules:**
653
+ - PROJECT.md: required headers `## Core Value`, `## Key Decisions`
654
+ - REQUIREMENTS.md: required headers `## Requirements` (or `## v1` / `## v2` etc.)
655
+ - ROADMAP.md: required headers `## Phases`, `## Progress`
656
+ - STATE.md: required headers `## Current Position`, `## Accumulated Context`
657
+
658
+ If a required header is missing from an existing file, add the section at the end. If present, leave the file as-is.
659
+
660
+ ### 9a: PROJECT.md
661
+
662
+ **Skip if merge mode and file exists with all required headers.**
663
+
664
+ Use template from `templates/project.md` as base. Fill in:
665
+
666
+ **Standard sections:**
667
+ - Project name (from README or directory name)
668
+ - What This Is (from scan findings + README + user corrections)
669
+ - Core Value (inferred from scan purpose or user's vision)
670
+ - Requirements section (initial Active requirements from user goals)
671
+ - Context section (technical environment from scan)
672
+ - Constraints (from production sub-questions + general constraints)
673
+ - Key Decisions table (from config choices + user decisions)
674
+
675
+ **Extra sections for existing projects (per CONTEXT.md Decision 4):**
676
+
677
+ Add these AFTER the standard sections:
678
+
679
+ ```markdown
680
+ ## Current State Summary
681
+
682
+ [Condensed scan findings as onboarding overview for future agents.
683
+ Include: tech stack, architecture pattern, key design patterns, current capabilities.]
684
+
685
+ ## Known Risks / Tech Debt
686
+
687
+ [From CONCERNS.md + user additions from Step 7.
688
+ Format as actionable list with severity indicators.]
689
+
690
+ ## Codebase Analysis
691
+
692
+ Detailed codebase analysis available in:
693
+ - `.planning/codebase/STACK.md` -- Technology stack
694
+ - `.planning/codebase/ARCHITECTURE.md` -- Architecture patterns
695
+ - `.planning/codebase/CONVENTIONS.md` -- Code conventions
696
+ - `.planning/codebase/CONCERNS.md` -- Known issues and tech debt
697
+ - `.planning/codebase/STRUCTURE.md` -- File tree overview
698
+ ```
699
+
700
+ If README discrepancies were found in Step 4:
701
+ ```markdown
702
+ ## README Validation Note
703
+
704
+ README may be outdated in the following areas:
705
+ - [discrepancy 1]
706
+ - [discrepancy 2]
707
+ Consider updating README to reflect current state.
708
+ ```
709
+
710
+ If no discrepancies, omit this section.
711
+
712
+ **If auto mode:** Add at top of file:
713
+ ```markdown
714
+ <!-- Auto-generated by /maxsim:init-existing --auto. Review recommended. -->
715
+ ```
716
+
717
+ ### 9b: REQUIREMENTS.md
718
+
719
+ **Skip if merge mode and file exists with all required headers.**
720
+
721
+ Use stage-aware format per CONTEXT.md Decision 4:
722
+
723
+ **Prototype stage:**
724
+ ```markdown
725
+ # Requirements: [Project Name]
726
+
727
+ **Defined:** [date]
728
+ **Core Value:** [from PROJECT.md]
729
+ **Stage:** Prototype
730
+
731
+ ## Requirements
732
+
733
+ Lightweight requirements for rapid exploration.
734
+
735
+ - [ ] [Goal 1 -- informal description]
736
+ - [ ] [Goal 2 -- informal description]
737
+ - [ ] [Goal 3 -- informal description]
738
+
739
+ ## Out of Scope
740
+
741
+ - [Exclusion] -- [reason]
742
+
743
+ ## Traceability
744
+
745
+ | Requirement | Phase | Status |
746
+ |-------------|-------|--------|
747
+ | [Goal 1] | Phase 1 | Pending |
748
+
749
+ ---
750
+ *Requirements defined: [date]*
751
+ ```
752
+
753
+ **MVP stage:**
754
+ ```markdown
755
+ # Requirements: [Project Name]
756
+
757
+ **Defined:** [date]
758
+ **Core Value:** [from PROJECT.md]
759
+ **Stage:** MVP
760
+
761
+ ## v1 Requirements
762
+
763
+ User stories for initial release.
764
+
765
+ ### [Category 1]
766
+
767
+ - [ ] **[CAT]-01**: As a user, I can [action] so that [benefit]
768
+ - [ ] **[CAT]-02**: As a user, I can [action] so that [benefit]
769
+
770
+ ### [Category 2]
771
+
772
+ - [ ] **[CAT]-01**: As a user, I can [action] so that [benefit]
773
+
774
+ ## v2 Requirements
775
+
776
+ Deferred to future release.
777
+
778
+ - **[CAT]-01**: [description]
779
+
780
+ ## Out of Scope
781
+
782
+ | Feature | Reason |
783
+ |---------|--------|
784
+ | [Feature] | [Why excluded] |
785
+
786
+ ## Traceability
787
+
788
+ | Requirement | Phase | Status |
789
+ |-------------|-------|--------|
790
+ | [CAT]-01 | Phase 1 | Pending |
791
+
792
+ **Coverage:**
793
+ - v1 requirements: [X] total
794
+ - Mapped to phases: [Y]
795
+ - Unmapped: [Z]
796
+
797
+ ---
798
+ *Requirements defined: [date]*
799
+ ```
800
+
801
+ **Production stage:**
802
+ ```markdown
803
+ # Requirements: [Project Name]
804
+
805
+ **Defined:** [date]
806
+ **Core Value:** [from PROJECT.md]
807
+ **Stage:** Production
808
+
809
+ ## v1 Requirements
810
+
811
+ Formal acceptance criteria with stability guards.
812
+
813
+ ### [Category 1]
814
+
815
+ - [ ] **[CAT]-01**: [Specific, testable requirement]
816
+ - Acceptance: [measurable criterion]
817
+ - [ ] **[CAT]-02**: [Specific, testable requirement]
818
+ - Acceptance: [measurable criterion]
819
+
820
+ ### Stability Guards
821
+
822
+ These are MUST NOT requirements derived from production constraints:
823
+
824
+ - [ ] **GUARD-01**: MUST NOT break [critical thing from production sub-questions]
825
+ - [ ] **GUARD-02**: MUST NOT cause downtime during [operation]
826
+ - [ ] **GUARD-03**: MUST NOT remove backward compatibility with [system]
827
+
828
+ ## v2 Requirements
829
+
830
+ - **[CAT]-01**: [description]
831
+
832
+ ## Out of Scope
833
+
834
+ | Feature | Reason |
835
+ |---------|--------|
836
+ | [Feature] | [Why excluded] |
837
+
838
+ ## Traceability
839
+
840
+ | Requirement | Phase | Status |
841
+ |-------------|-------|--------|
842
+ | [CAT]-01 | Phase 1 | Pending |
843
+ | GUARD-01 | All phases | Active |
844
+
845
+ **Coverage:**
846
+ - v1 requirements: [X] total
847
+ - Guards: [Y] total
848
+ - Mapped to phases: [Z]
849
+
850
+ ---
851
+ *Requirements defined: [date]*
852
+ ```
853
+
854
+ **Maintenance stage:** Same as Production format with additional stability focus:
855
+ ```markdown
856
+ ### Maintenance Focus
857
+
858
+ - [ ] **MAINT-01**: All existing tests continue to pass after changes
859
+ - [ ] **MAINT-02**: No regression in [critical metric]
860
+ ```
861
+
862
+ **If auto mode:** Add at top of file:
863
+ ```markdown
864
+ <!-- Auto-generated by /maxsim:init-existing --auto. Review recommended. -->
865
+ ```
866
+
867
+ ### 9c: ROADMAP.md
868
+
869
+ **Skip if merge mode and file exists with all required headers.**
870
+
871
+ Use template from `templates/roadmap.md`.
872
+
873
+ ```
874
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
875
+ MAXSIM ► CREATING ROADMAP
876
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
877
+
878
+ ◆ Spawning roadmapper...
879
+ ```
880
+
881
+ Spawn the `maxsim-roadmapper` agent via Task tool to generate the roadmap:
882
+
883
+ ```
884
+ Task(prompt="
885
+ <planning_context>
886
+
887
+ <files_to_read>
888
+ - .planning/PROJECT.md (Project context)
889
+ - .planning/REQUIREMENTS.md (Requirements)
890
+ - .planning/config.json (Depth and mode settings)
891
+ </files_to_read>
892
+
893
+ <scan_context>
894
+ The project is an EXISTING codebase being initialized. Scan findings summary:
895
+
896
+ **Tech Stack:** [from STACK.md]
897
+ **Architecture:** [from ARCHITECTURE.md]
898
+ **Key Patterns:** [from CONVENTIONS.md]
899
+ **Known Concerns:** [from CONCERNS.md]
900
+ </scan_context>
901
+
902
+ <user_context>
903
+ **Vision:** [user's vision from Step 7, or inferred from scan in auto mode]
904
+ **Pain Points:** [from Step 7]
905
+ **Stage:** [prototype/MVP/production/maintenance]
906
+ **Milestone:** [suggested milestone name from Step 8]
907
+ </user_context>
908
+
909
+ </planning_context>
910
+
911
+ <instructions>
912
+ Create roadmap for an EXISTING project:
913
+ 1. Derive 3-5 concrete suggested phases based on actual scan findings and stated goals
914
+ 2. NO TBD placeholder phases -- every phase must be specific and actionable
915
+ 3. Map every v1 requirement to exactly one phase
916
+ 4. Derive 2-5 success criteria per phase (observable user behaviors)
917
+ 5. Validate 100% coverage
918
+ 6. Write files immediately (ROADMAP.md, STATE.md, update REQUIREMENTS.md traceability)
919
+ 7. Return ROADMAP CREATED with summary
920
+
921
+ This is an existing project -- phases should address real found issues and user goals,
922
+ not generic setup phases. The codebase already exists.
923
+
924
+ Write files first, then return. This ensures artifacts persist even if context is lost.
925
+ </instructions>
926
+ ", subagent_type="maxsim-roadmapper", model="{roadmapper_model}", description="Create roadmap for existing project")
927
+ ```
928
+
929
+ **Handle roadmapper return:**
930
+
931
+ **If `## ROADMAP BLOCKED`:**
932
+ - Present blocker information
933
+ - Work with user to resolve
934
+ - Re-spawn when resolved
935
+
936
+ **If `## ROADMAP CREATED`:**
937
+
938
+ Read the created ROADMAP.md and present it inline:
939
+
940
+ ```
941
+ ## Proposed Roadmap
942
+
943
+ **[N] phases** | **[X] requirements mapped** | All v1 requirements covered
944
+
945
+ | # | Phase | Goal | Requirements |
946
+ |---|-------|------|--------------|
947
+ | 1 | [Name] | [Goal] | [REQ-IDs] |
948
+ | 2 | [Name] | [Goal] | [REQ-IDs] |
949
+ | 3 | [Name] | [Goal] | [REQ-IDs] |
950
+ ```
951
+
952
+ **If auto mode:** Skip approval gate. Proceed to Step 9d.
953
+
954
+ **If interactive mode:**
955
+
956
+ Use AskUserQuestion:
957
+ - header: "Roadmap"
958
+ - question: "Does this roadmap structure work for you?"
959
+ - options:
960
+ - "Approve" -- Commit and continue
961
+ - "Adjust phases" -- Tell me what to change
962
+ - "Review full file" -- Show raw ROADMAP.md
963
+
964
+ If "Approve": continue.
965
+ If "Adjust phases": get feedback, re-spawn roadmapper with revision context, re-present. Loop until approved.
966
+ If "Review full file": display raw `cat .planning/ROADMAP.md`, then re-ask.
967
+
968
+ ### 9d: STATE.md
969
+
970
+ **Skip if merge mode and file exists with all required headers.**
971
+
972
+ If the roadmapper already created STATE.md (it usually does), verify it exists. If not, create using template from `templates/state.md`.
973
+
974
+ Pre-populate:
975
+ - **Project Reference:** Core value from PROJECT.md, current focus = Phase 1
976
+ - **Current Position:** Phase 1 of [N], ready to plan
977
+ - **Decisions section:** Add constraints as decisions (e.g., "Must maintain backward compatibility with API v1")
978
+ - **Blockers section:** Add known tech debt and risks from CONCERNS.md as blockers
979
+
980
+ **If auto mode:** Add at top of file:
981
+ ```markdown
982
+ <!-- Auto-generated by /maxsim:init-existing --auto. Review recommended. -->
983
+ ```
984
+
985
+ ### 9e: config.json
986
+
987
+ Already written in Step 5. If merge mode and config.json existed, it was preserved (unless user chose overwrite).
988
+
989
+ ## Step 10: Git Stage and Summary
990
+
991
+ Stage all changed files:
992
+ ```bash
993
+ git add .planning/
994
+ ```
995
+
996
+ If `commit_docs` is true:
997
+ ```bash
998
+ git commit -m "docs: initialize MAXSIM in existing project via /maxsim:init-existing"
999
+ ```
1000
+
1001
+ Print structured summary:
1002
+
1003
+ ```
1004
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1005
+ MAXSIM ► INITIALIZATION COMPLETE ✓
1006
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1007
+
1008
+ Created:
1009
+ ✓ .planning/config.json -- Workflow preferences
1010
+ ✓ .planning/PROJECT.md -- Project context + current state
1011
+ ✓ .planning/REQUIREMENTS.md -- [Stage]-format requirements
1012
+ ✓ .planning/ROADMAP.md -- [Milestone name] + [N] phases
1013
+ ✓ .planning/STATE.md -- Pre-populated project memory
1014
+ ✓ .planning/codebase/ -- Full codebase analysis (4 docs + structure)
1015
+ ```
1016
+
1017
+ If auto mode, append:
1018
+ ```
1019
+ Documents were auto-generated from codebase analysis. Review recommended before starting execution.
1020
+ ```
1021
+
1022
+ Print next steps:
1023
+
1024
+ ```
1025
+ ───────────────────────────────────────────────────────────────
1026
+
1027
+ ## ▶ Next Up
1028
+
1029
+ **Phase 1: [Phase Name]** -- [Goal from ROADMAP.md]
1030
+
1031
+ /maxsim:plan-phase 1 -- plan the first phase
1032
+
1033
+ <sub>/clear first → fresh context window</sub>
1034
+
1035
+ ───────────────────────────────────────────────────────────────
1036
+
1037
+ **Also available:**
1038
+ - /maxsim:roadmap -- review the generated roadmap
1039
+ - /maxsim:progress -- see project status
1040
+
1041
+ ───────────────────────────────────────────────────────────────
1042
+ ```
1043
+
1044
+ **End of workflow.**
1045
+
1046
+ </process>
1047
+
1048
+ <output>
1049
+
1050
+ - `.planning/config.json`
1051
+ - `.planning/PROJECT.md`
1052
+ - `.planning/REQUIREMENTS.md`
1053
+ - `.planning/ROADMAP.md`
1054
+ - `.planning/STATE.md`
1055
+ - `.planning/codebase/STACK.md`
1056
+ - `.planning/codebase/ARCHITECTURE.md`
1057
+ - `.planning/codebase/CONVENTIONS.md`
1058
+ - `.planning/codebase/CONCERNS.md`
1059
+ - `.planning/codebase/STRUCTURE.md`
1060
+
1061
+ </output>
1062
+
1063
+ <success_criteria>
1064
+
1065
+ - [ ] .planning/ directory created (or merged)
1066
+ - [ ] Git repo initialized (if not already)
1067
+ - [ ] Conflict detection completed (merge/overwrite/cancel dialog)
1068
+ - [ ] Codebase scan completed (4 mapper agents spawned)
1069
+ - [ ] README validated against scan findings
1070
+ - [ ] Config questions answered (or auto-defaulted)
1071
+ - [ ] Existing state presented and confirmed (or auto-inferred)
1072
+ - [ ] Future direction gathered (pain points, stage, constraints, vision)
1073
+ - [ ] Production sub-questions asked (if production/maintenance stage)
1074
+ - [ ] Milestone suggested and confirmed
1075
+ - [ ] PROJECT.md created with brownfield extra sections
1076
+ - [ ] REQUIREMENTS.md created with stage-aware format
1077
+ - [ ] ROADMAP.md created with 3-5 concrete phases (no TBD)
1078
+ - [ ] STATE.md created with pre-populated decisions and blockers
1079
+ - [ ] config.json created with workflow settings
1080
+ - [ ] .planning/codebase/ populated with scan documents
1081
+ - [ ] Git staging completed
1082
+ - [ ] Structured summary printed
1083
+ - [ ] Next steps suggested: /maxsim:roadmap then /maxsim:plan-phase 1
1084
+
1085
+ **Auto mode criteria:**
1086
+ - [ ] All questions skipped
1087
+ - [ ] Smart defaults applied
1088
+ - [ ] All documents flagged as auto-generated
1089
+ - [ ] Review recommendation printed
1090
+
1091
+ **Merge mode criteria:**
1092
+ - [ ] Existing files preserved where complete
1093
+ - [ ] Missing files created
1094
+ - [ ] Incomplete files had gaps filled
1095
+ - [ ] Codebase always re-scanned
1096
+
1097
+ **Atomic commits:** Each artifact committed if commit_docs is true.
1098
+
1099
+ </success_criteria>