specdacular 0.5.3 → 0.6.1

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.
@@ -24,8 +24,61 @@ The 4 documents answer questions Claude can't get from reading code:
24
24
 
25
25
  <process>
26
26
 
27
+ <step name="detect_mode">
28
+ Determine if this is a single-project or multi-project setup.
29
+
30
+ Use AskUserQuestion:
31
+ - header: "Setup Mode"
32
+ - question: "Is this a multi-project setup (monorepo or multiple related projects)?"
33
+ - options:
34
+ - "Single project" — One codebase, one .specd/ (most common)
35
+ - "Multi-project" — Multiple projects that coordinate (monorepo, multi-repo)
36
+
37
+ **If Single project:**
38
+ Set mode = "project".
39
+ Continue to check_existing.
40
+
41
+ **If Multi-project:**
42
+ Set mode = "orchestrator".
43
+ Continue to check_existing.
44
+ </step>
45
+
27
46
  <step name="check_existing">
28
- Check if .specd/codebase/ already exists:
47
+ **First, check for legacy setup (DEC-012):**
48
+
49
+ ```bash
50
+ # Check if .specd/ exists but has no config.json (legacy setup)
51
+ if [ -d ".specd" ] && [ ! -f ".specd/config.json" ]; then
52
+ echo "legacy_setup"
53
+ fi
54
+ ```
55
+
56
+ **If legacy_setup detected:**
57
+
58
+ ```
59
+ Your codebase map was created with an older version of Specdacular.
60
+ Re-mapping is recommended — this will also ask about multi-project support.
61
+ ```
62
+
63
+ Use AskUserQuestion:
64
+ - header: "Legacy Setup"
65
+ - question: "Re-map your codebase with the latest Specdacular?"
66
+ - options:
67
+ - "Yes, re-map (Recommended)" — Re-run mapping with multi-project detection
68
+ - "Skip for now" — Keep existing map, continue without re-mapping
69
+
70
+ **If "Yes, re-map":** Delete .specd/codebase/, continue with detect_mode flow.
71
+ **If "Skip for now":** Exit workflow.
72
+
73
+ **If .specd/config.json exists, check version:**
74
+
75
+ ```bash
76
+ cat .specd/config.json 2>/dev/null
77
+ ```
78
+
79
+ If `specd_version` is less than current version (1), offer to re-map with same prompt as legacy flow above.
80
+
81
+ **Then check if .specd/codebase/ already exists:**
29
82
 
30
83
  ```bash
31
84
  ls -la .specd/codebase/ 2>/dev/null
@@ -55,11 +108,15 @@ Use the AskUserQuestion tool:
55
108
  }
56
109
  ```
57
110
 
58
- If "Refresh": Delete .specd/codebase/, continue to check_existing_docs
111
+ If "Refresh": Delete .specd/codebase/, continue based on mode.
59
112
  If "Skip": Exit workflow
60
113
 
61
114
  **If doesn't exist:**
62
- Continue to check_existing_docs.
115
+ Continue based on mode.
116
+
117
+ **Mode branching (after check_existing resolves):**
118
+ - If mode = "project": continue to check_existing_docs (existing single-project flow)
119
+ - If mode = "orchestrator": continue to register_projects (multi-project flow, see below)
63
120
  </step>
64
121
 
65
122
  <step name="check_existing_docs">
@@ -111,6 +168,19 @@ Create .specd/codebase/ directory:
111
168
  mkdir -p .specd/codebase
112
169
  ```
113
170
 
171
+ **Create project-level config (DEC-012):**
172
+
173
+ Write `.specd/config.json`:
174
+ ```json
175
+ {
176
+ "type": "project",
177
+ "specd_version": 1,
178
+ "created": "{YYYY-MM-DD}"
179
+ }
180
+ ```
181
+
182
+ This enables future version detection and mode detection for all workflows.
183
+
114
184
  **Documents to be created:**
115
185
  - MAP.md (from map mapper) — Navigation: function signatures, entry points, modules
116
186
  - PATTERNS.md (from patterns mapper) — Code examples: services, error handling, testing
@@ -289,7 +359,7 @@ Continue to commit_codebase_map.
289
359
  Commit the codebase map:
290
360
 
291
361
  ```bash
292
- git add .specd/codebase/*.md
362
+ git add .specd/codebase/*.md .specd/config.json
293
363
  git commit -m "$(cat <<'EOF'
294
364
  docs: map codebase for Claude
295
365
 
@@ -333,13 +403,308 @@ To review: `cat .specd/codebase/MAP.md`
333
403
  End workflow.
334
404
  </step>
335
405
 
406
+ <!-- ═══════════════════════════════════════════════════════
407
+ MULTI-PROJECT FLOW
408
+ Reached when detect_mode sets mode = "orchestrator".
409
+ check_existing branches here instead of to check_existing_docs.
410
+ ═══════════════════════════════════════════════════════ -->
411
+
412
+ <step name="register_projects">
413
+ Register sub-projects for orchestrator mode.
414
+
415
+ **Scan for project markers in immediate subdirectories:**
416
+
417
+ ```bash
418
+ # Find directories with common project markers
419
+ for dir in */; do
420
+ if [ -f "${dir}package.json" ] || [ -f "${dir}go.mod" ] || [ -f "${dir}Cargo.toml" ] || [ -f "${dir}pyproject.toml" ] || [ -f "${dir}pom.xml" ] || [ -f "${dir}build.gradle" ] || [ -f "${dir}Makefile" ] || [ -f "${dir}Gemfile" ]; then
421
+ echo "${dir%/}"
422
+ fi
423
+ done
424
+ ```
425
+
426
+ **Present found projects:**
427
+ ```
428
+ Found these potential projects:
429
+ - {dir1}/ (has package.json)
430
+ - {dir2}/ (has go.mod)
431
+ - {dir3}/ (has package.json)
432
+
433
+ These will be registered as sub-projects.
434
+ ```
435
+
436
+ Use AskUserQuestion:
437
+ - header: "Projects"
438
+ - question: "Are these the right projects? You can adjust in the next step."
439
+ - options:
440
+ - "Yes, these are correct" — Continue with found projects
441
+ - "I need to adjust" — Let user add/remove projects
442
+
443
+ **If "I need to adjust":**
444
+ Ask user to describe which projects to add or remove. Update the list accordingly.
445
+
446
+ **For each project, ask for a one-liner description:**
447
+ Use AskUserQuestion for each project (or batch if 3 or fewer):
448
+ - header: "{project-name}"
449
+ - question: "Brief description of {project-name}?"
450
+ - options: Provide 2-3 inferred descriptions based on directory contents + "Something else"
451
+
452
+ **Build project registry:**
453
+ ```json
454
+ [
455
+ {"name": "{dir1}", "path": "./{dir1}", "description": "{user description}"},
456
+ {"name": "{dir2}", "path": "./{dir2}", "description": "{user description}"}
457
+ ]
458
+ ```
459
+
460
+ Continue to create_orchestrator_structure.
461
+ </step>
462
+
463
+ <step name="create_orchestrator_structure">
464
+ Create orchestrator-level .specd/ directory and config.
465
+
466
+ ```bash
467
+ mkdir -p .specd/codebase
468
+ ```
469
+
470
+ **Write .specd/config.json (DEC-006, DEC-012):**
471
+ ```json
472
+ {
473
+ "type": "orchestrator",
474
+ "specd_version": 1,
475
+ "created": "{YYYY-MM-DD}",
476
+ "projects": [
477
+ {"name": "{name}", "path": "{path}", "description": "{description}"}
478
+ ]
479
+ }
480
+ ```
481
+
482
+ **Create per-project .specd/ structures:**
483
+ For each registered project:
484
+ ```bash
485
+ mkdir -p {project-path}/.specd/codebase
486
+ ```
487
+
488
+ **Write per-project config.json (DEC-012):**
489
+ For each registered project, write `{project-path}/.specd/config.json`:
490
+ ```json
491
+ {
492
+ "type": "project",
493
+ "specd_version": 1,
494
+ "created": "{YYYY-MM-DD}"
495
+ }
496
+ ```
497
+
498
+ Continue to check_existing_docs_multi.
499
+ </step>
500
+
501
+ <step name="check_existing_docs_multi">
502
+ Check for existing documentation across all projects.
503
+
504
+ For each registered project, check for docs:
505
+ ```bash
506
+ ls {project-path}/README* {project-path}/CONTRIBUTING* {project-path}/ARCHITECTURE* {project-path}/docs/ 2>/dev/null
507
+ ```
508
+
509
+ Also check root-level docs:
510
+ ```bash
511
+ ls README* CONTRIBUTING* ARCHITECTURE* docs/ 2>/dev/null
512
+ ```
513
+
514
+ **Always read and incorporate any docs found** — same as single-project flow.
515
+
516
+ Ask user for additional docs (same AskUserQuestion as check_existing_docs).
517
+
518
+ Continue to spawn_per_project_agents.
519
+ </step>
520
+
521
+ <step name="spawn_per_project_agents">
522
+ Spawn 4 mapper agents per sub-project, all in parallel.
523
+
524
+ For each registered project, spawn the same 4 agents as the single-project flow (map, patterns, structure, concerns), but scoped to the project's directory.
525
+
526
+ **CRITICAL:** Each agent's prompt must specify the project path so it writes to `{project-path}/.specd/codebase/`.
527
+
528
+ Use Task tool with `subagent_type="specd-codebase-mapper"` and `run_in_background=true`.
529
+
530
+ **Per project, spawn 4 agents:**
531
+
532
+ Agent prompts follow the same pattern as the single-project agents in `spawn_agents`, with these modifications:
533
+ - Working directory context: "This project is at {project-path}/"
534
+ - Output path: "Write to {project-path}/.specd/codebase/{DOC}.md"
535
+ - Scope: "Only analyze code within {project-path}/"
536
+
537
+ **If existing documentation was found for a project:**
538
+ Include project-specific docs in that project's agent prompts (same as single-project).
539
+
540
+ All agents (across all projects) are spawned simultaneously for maximum parallelism.
541
+
542
+ Wait for all agents to complete. Verify each project has all 4 documents:
543
+
544
+ ```bash
545
+ # Verify per-project docs
546
+ for project in {project-paths}; do
547
+ echo "Checking $project..."
548
+ ls -la "$project/.specd/codebase/"
549
+ wc -l "$project/.specd/codebase/"*.md 2>/dev/null
550
+ done
551
+ ```
552
+
553
+ If any agents failed, note which project/document and continue.
554
+
555
+ Continue to spawn_orchestrator_agent.
556
+ </step>
557
+
558
+ <step name="spawn_orchestrator_agent">
559
+ Spawn a single orchestrator mapper agent to synthesize system-level docs (DEC-007: runs AFTER all per-project mappers complete).
560
+
561
+ This agent reads sub-project codebase docs and scans codebases for system-level artifacts.
562
+
563
+ Use Task tool:
564
+ ```
565
+ subagent_type: "specd-codebase-mapper"
566
+ model: "sonnet"
567
+ run_in_background: true
568
+ description: "Map orchestrator system docs"
569
+ ```
570
+
571
+ Prompt:
572
+ ```
573
+ Focus: orchestrator
574
+
575
+ You are mapping a multi-project system. Sub-project analysis is already complete.
576
+
577
+ **Projects in this system:**
578
+ {For each project: name, path, description}
579
+
580
+ **Sub-project docs available:**
581
+ {For each project: list the 4 .specd/codebase/ files with paths}
582
+
583
+ **Your job:**
584
+ 1. Read all sub-project codebase docs (MAP.md, PATTERNS.md, STRUCTURE.md, CONCERNS.md for each project)
585
+ 2. Scan codebases for system-level artifacts:
586
+ - docker-compose.yml, docker files
587
+ - CI/CD configs (.github/workflows/, .gitlab-ci.yml, etc.)
588
+ - Shared configs (eslint, prettier, tsconfig at root)
589
+ - Cross-project imports or references
590
+ - Shared databases, APIs, message queues
591
+ 3. Write 4 orchestrator-level docs to .specd/codebase/:
592
+
593
+ **PROJECTS.md** — Project registry with responsibilities and entry points
594
+ Follow template structure: registry table, per-project details, codebase doc links.
595
+
596
+ **TOPOLOGY.md** — How projects communicate
597
+ Follow template: per-relationship sections with communication method, pattern, shared domains, source of truth, data flow. Include shared resources table and Mermaid diagram.
598
+
599
+ **CONTRACTS.md** — Shared interface descriptions (keep loose per DEC-008)
600
+ Follow template: per-relationship contract nature. Describe relationships, not specific endpoints.
601
+
602
+ **CONCERNS.md** — Cross-cutting system-level gotchas
603
+ Follow template: per-concern with scope, issue, impact, mitigation. Focus on SYSTEM-level concerns that span projects, not project-internal concerns.
604
+
605
+ Return confirmation with line counts for all 4 docs.
606
+ ```
607
+
608
+ Wait for orchestrator agent to complete. Verify docs exist:
609
+
610
+ ```bash
611
+ ls -la .specd/codebase/
612
+ wc -l .specd/codebase/*.md
613
+ ```
614
+
615
+ Continue to commit_orchestrator_map.
616
+ </step>
617
+
618
+ <step name="commit_orchestrator_map">
619
+ Commit all mapping results (orchestrator + all sub-projects).
620
+
621
+ ```bash
622
+ # Add orchestrator docs and config
623
+ git add .specd/codebase/*.md .specd/config.json
624
+
625
+ # Add per-project docs and configs
626
+ # {For each project:}
627
+ git add {project-path}/.specd/codebase/*.md {project-path}/.specd/config.json
628
+
629
+ git commit -m "$(cat <<'EOF'
630
+ docs: map multi-project codebase for Claude
631
+
632
+ Orchestrator:
633
+ - PROJECTS.md - Project registry
634
+ - TOPOLOGY.md - Communication patterns
635
+ - CONTRACTS.md - Shared interfaces
636
+ - CONCERNS.md - System-level gotchas
637
+
638
+ Projects mapped:
639
+ {For each project: - {name}: MAP, PATTERNS, STRUCTURE, CONCERNS}
640
+
641
+ Co-Authored-By: Claude <noreply@anthropic.com>
642
+ EOF
643
+ )"
644
+ ```
645
+
646
+ Continue to orchestrator_completion.
647
+ </step>
648
+
649
+ <step name="orchestrator_completion">
650
+ Present multi-project completion summary.
651
+
652
+ **Get line counts for orchestrator and each project:**
653
+ ```bash
654
+ wc -l .specd/codebase/*.md
655
+ # For each project:
656
+ wc -l {project-path}/.specd/codebase/*.md
657
+ ```
658
+
659
+ **Output format:**
660
+
661
+ ```
662
+ Multi-project codebase mapped for Claude.
663
+
664
+ Orchestrator (.specd/codebase/):
665
+ - PROJECTS.md ({N} lines) — Project registry
666
+ - TOPOLOGY.md ({N} lines) — Communication patterns
667
+ - CONTRACTS.md ({N} lines) — Shared interfaces
668
+ - CONCERNS.md ({N} lines) — System-level concerns
669
+
670
+ {For each project:}
671
+ {project-name} ({project-path}/.specd/codebase/):
672
+ - MAP.md ({N} lines) — Navigation
673
+ - PATTERNS.md ({N} lines) — Code patterns
674
+ - STRUCTURE.md ({N} lines) — File organization
675
+ - CONCERNS.md ({N} lines) — Project-level gotchas
676
+
677
+ These docs help Claude understand your system across projects.
678
+ They'll be referenced during planning and implementation.
679
+ ```
680
+
681
+ End workflow.
682
+ </step>
683
+
336
684
  </process>
337
685
 
338
686
  <success_criteria>
687
+ **Single-project mode:**
339
688
  - .specd/codebase/ directory created
689
+ - .specd/config.json created with type and specd_version (DEC-012)
340
690
  - 4 parallel specd-codebase-mapper agents spawned with run_in_background=true
341
691
  - Agents write documents directly (orchestrator doesn't receive document contents)
342
692
  - All 4 documents exist: MAP.md, PATTERNS.md, STRUCTURE.md, CONCERNS.md
343
693
  - Documents contain real code examples (not placeholders)
344
694
  - Clear completion summary with line counts
695
+
696
+ **Multi-project mode (additional):**
697
+ - detect_mode correctly identifies multi-project setup
698
+ - Projects registered with name, path, description
699
+ - .specd/config.json created with type=orchestrator and projects array (DEC-006)
700
+ - Per-project .specd/config.json created with type=project (DEC-012)
701
+ - 4 agents spawned per project, all in parallel
702
+ - Orchestrator agent runs after per-project agents complete (DEC-007)
703
+ - Orchestrator docs: PROJECTS.md, TOPOLOGY.md, CONTRACTS.md, CONCERNS.md
704
+ - Per-project docs: MAP.md, PATTERNS.md, STRUCTURE.md, CONCERNS.md per project
705
+ - Multi-project completion summary with per-project line counts
706
+
707
+ **Legacy detection:**
708
+ - .specd/ without config.json detected as legacy
709
+ - User prompted to re-map
345
710
  </success_criteria>