brain-dev 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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -0
  3. package/agents/brain-checker.md +33 -0
  4. package/agents/brain-debugger.md +35 -0
  5. package/agents/brain-executor.md +37 -0
  6. package/agents/brain-mapper.md +44 -0
  7. package/agents/brain-planner.md +49 -0
  8. package/agents/brain-researcher.md +47 -0
  9. package/agents/brain-synthesizer.md +43 -0
  10. package/agents/brain-verifier.md +41 -0
  11. package/bin/brain-tools.cjs +185 -0
  12. package/bin/lib/adr.cjs +283 -0
  13. package/bin/lib/agents.cjs +152 -0
  14. package/bin/lib/anti-patterns.cjs +183 -0
  15. package/bin/lib/audit.cjs +268 -0
  16. package/bin/lib/commands/adr.cjs +126 -0
  17. package/bin/lib/commands/complete.cjs +270 -0
  18. package/bin/lib/commands/config.cjs +306 -0
  19. package/bin/lib/commands/discuss.cjs +237 -0
  20. package/bin/lib/commands/execute.cjs +415 -0
  21. package/bin/lib/commands/health.cjs +103 -0
  22. package/bin/lib/commands/map.cjs +101 -0
  23. package/bin/lib/commands/new-project.cjs +885 -0
  24. package/bin/lib/commands/pause.cjs +142 -0
  25. package/bin/lib/commands/phase-manage.cjs +357 -0
  26. package/bin/lib/commands/plan.cjs +451 -0
  27. package/bin/lib/commands/progress.cjs +167 -0
  28. package/bin/lib/commands/quick.cjs +447 -0
  29. package/bin/lib/commands/resume.cjs +196 -0
  30. package/bin/lib/commands/storm.cjs +590 -0
  31. package/bin/lib/commands/verify.cjs +504 -0
  32. package/bin/lib/commands.cjs +263 -0
  33. package/bin/lib/complexity.cjs +138 -0
  34. package/bin/lib/complexity.test.cjs +108 -0
  35. package/bin/lib/config.cjs +452 -0
  36. package/bin/lib/core.cjs +62 -0
  37. package/bin/lib/detect.cjs +603 -0
  38. package/bin/lib/git.cjs +112 -0
  39. package/bin/lib/health.cjs +356 -0
  40. package/bin/lib/init.cjs +310 -0
  41. package/bin/lib/logger.cjs +100 -0
  42. package/bin/lib/platform.cjs +58 -0
  43. package/bin/lib/requirements.cjs +158 -0
  44. package/bin/lib/roadmap.cjs +228 -0
  45. package/bin/lib/security.cjs +237 -0
  46. package/bin/lib/state.cjs +353 -0
  47. package/bin/lib/templates.cjs +48 -0
  48. package/bin/templates/advocate.md +182 -0
  49. package/bin/templates/checkpoint.md +55 -0
  50. package/bin/templates/debugger.md +148 -0
  51. package/bin/templates/discuss.md +60 -0
  52. package/bin/templates/executor.md +201 -0
  53. package/bin/templates/mapper.md +129 -0
  54. package/bin/templates/plan-checker.md +134 -0
  55. package/bin/templates/planner.md +165 -0
  56. package/bin/templates/researcher.md +78 -0
  57. package/bin/templates/storm.html +376 -0
  58. package/bin/templates/synthesis.md +30 -0
  59. package/bin/templates/verifier.md +181 -0
  60. package/commands/brain/adr.md +34 -0
  61. package/commands/brain/complete.md +37 -0
  62. package/commands/brain/config.md +37 -0
  63. package/commands/brain/discuss.md +35 -0
  64. package/commands/brain/execute.md +38 -0
  65. package/commands/brain/health.md +33 -0
  66. package/commands/brain/map.md +35 -0
  67. package/commands/brain/new-project.md +38 -0
  68. package/commands/brain/pause.md +26 -0
  69. package/commands/brain/plan.md +38 -0
  70. package/commands/brain/progress.md +28 -0
  71. package/commands/brain/quick.md +51 -0
  72. package/commands/brain/resume.md +28 -0
  73. package/commands/brain/storm.md +30 -0
  74. package/commands/brain/verify.md +39 -0
  75. package/hooks/bootstrap.sh +54 -0
  76. package/hooks/post-tool-use.sh +45 -0
  77. package/hooks/statusline.sh +130 -0
  78. package/package.json +36 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 halilcosdu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ ```
2
+ ╔══════════════════════════════════════════╗
3
+ ║ ║
4
+ ║ ██████ ██████ █████ ██ ██ ██ ║
5
+ ║ ██ ██ ██ ██ ██ ██ ██ ███ ██ ║
6
+ ║ ██████ ██████ ███████ ██ ██ █ ██ ║
7
+ ║ ██ ██ ██ ██ ██ ██ ██ ██ ███ ║
8
+ ║ ██████ ██ ██ ██ ██ ██ ██ ██ ║
9
+ ║ ║
10
+ ║ AI workflow orchestrator ║
11
+ ║ ║
12
+ ║ ── halilcosdu ── ║
13
+ ║ ║
14
+ ╚══════════════════════════════════════════╝
15
+ ```
16
+
17
+ **Brain turns Claude Code into a senior engineering team.** It orchestrates 8 specialized AI agents through a structured lifecycle — from project research to verified delivery — so you ship production-grade code, not prototypes.
18
+
19
+ ## The Problem
20
+
21
+ Claude Code is powerful but chaotic. You start building, lose context mid-session, forget what was decided, skip verification, and end up with code that works in demo but breaks in production.
22
+
23
+ ## The Solution
24
+
25
+ Brain adds structure without adding friction:
26
+
27
+ ```
28
+ /brain:new-project → Researches your domain with 6 parallel agents
29
+ /brain:discuss → Captures architectural decisions before coding
30
+ /brain:plan → Creates verified execution plans with TDD
31
+ /brain:execute → Builds with per-task commits and deviation handling
32
+ /brain:verify → 3-level verification against must-haves
33
+ /brain:complete → Advances to next phase with audit trail
34
+ ```
35
+
36
+ Every step produces artifacts. Every decision is tracked. Every phase is verified before moving forward.
37
+
38
+ ## Quick Start
39
+
40
+ ```bash
41
+ npx brain-dev init
42
+ ```
43
+
44
+ That's it. Brain detects your project (Laravel, Next.js, Go, Python — any stack), registers its agents, and is ready.
45
+
46
+ ```bash
47
+ /brain:new-project # Guided project setup with AI research
48
+ /brain:progress # Where am I? What's next?
49
+ ```
50
+
51
+ ## How It Works
52
+
53
+ Brain orchestrates **8 specialized agents**, each with a clear role:
54
+
55
+ | Agent | Role | Color |
56
+ |-------|------|-------|
57
+ | `brain-researcher` | Investigates technology, architecture, security, testing | cyan |
58
+ | `brain-synthesizer` | Merges research into actionable recommendations | cyan |
59
+ | `brain-planner` | Creates execution plans with dependency graphs | blue |
60
+ | `brain-checker` | Validates plans across 8 quality dimensions | blue |
61
+ | `brain-executor` | Implements with TDD and atomic commits | green |
62
+ | `brain-verifier` | 3-level verification: exists, substantive, wired | magenta |
63
+ | `brain-debugger` | 4-phase scientific debugging method | red |
64
+ | `brain-mapper` | Deep codebase analysis (stack, architecture, quality) | yellow |
65
+
66
+ ## Smart Detection
67
+
68
+ Brain auto-detects your project on init:
69
+
70
+ - **Multi-manifest**: Recognizes Laravel + Vue.js, Django + React, Go + npm — not just the first manifest found
71
+ - **Workspace siblings**: Detects `myapp-mobile/`, `myapp-landing/` alongside `myapp/`
72
+ - **Stack-aware questions**: Asks "I detected a Laravel (PHP) + Vue.js frontend. What do you want to do?" instead of generic "What are you building?"
73
+
74
+ ## Lifecycle
75
+
76
+ ```
77
+ init → new-project → discuss → plan → execute → verify → complete
78
+ ↑ │
79
+ └────────── next phase ──────────────┘
80
+ ```
81
+
82
+ - **`/brain:pause`** and **`/brain:resume`** preserve session context across conversations
83
+ - **`/brain:storm`** launches a real-time brainstorming server with WebSocket
84
+ - **`/brain:adr`** auto-creates architecture decision records
85
+ - **`/brain:map`** generates deep codebase documentation
86
+ - **`/brain:health`** self-diagnoses and auto-repairs
87
+
88
+ ## State Machine
89
+
90
+ Brain tracks progress through a deterministic state machine:
91
+
92
+ ```
93
+ pending → discussing → discussed → planning → executing → executed → verifying → verified → complete
94
+ ```
95
+
96
+ Every command knows what comes next. `brain-dev progress` always tells you the right next step.
97
+
98
+ ## Zero Dependencies
99
+
100
+ Brain is a single npm package with zero runtime dependencies. Just Node.js 22+.
101
+
102
+ ```json
103
+ {
104
+ "dependencies": {}
105
+ }
106
+ ```
107
+
108
+ No supply chain risk. No transitive vulnerabilities. No `node_modules` bloat.
109
+
110
+ ## Commands
111
+
112
+ ### Setup
113
+ | Command | Description |
114
+ |---------|-------------|
115
+ | `/brain:init` | Initialize brain in current project |
116
+ | `/brain:new-project` | Guided project creation with AI research |
117
+ | `/brain:help` | Show all available commands |
118
+
119
+ ### Lifecycle
120
+ | Command | Description |
121
+ |---------|-------------|
122
+ | `/brain:discuss` | Capture architectural decisions |
123
+ | `/brain:plan` | Create verified execution plans |
124
+ | `/brain:execute` | Build according to plans with TDD |
125
+ | `/brain:verify` | 3-level verification against must-haves |
126
+ | `/brain:complete` | Mark phase done, advance to next |
127
+
128
+ ### Session
129
+ | Command | Description |
130
+ |---------|-------------|
131
+ | `/brain:progress` | Current status and next action |
132
+ | `/brain:pause` | Save session for later |
133
+ | `/brain:resume` | Restore session context |
134
+
135
+ ### Tools
136
+ | Command | Description |
137
+ |---------|-------------|
138
+ | `/brain:storm` | Real-time brainstorming server |
139
+ | `/brain:adr` | Architecture decision records |
140
+ | `/brain:map` | Deep codebase analysis |
141
+ | `/brain:health` | Self-diagnosis and auto-repair |
142
+ | `/brain:config` | Configuration management |
143
+ | `/brain:phase` | Phase management (add, remove, reorder) |
144
+
145
+ ## Requirements
146
+
147
+ - Node.js 22+
148
+ - Claude Code
149
+
150
+ ## License
151
+
152
+ MIT
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: brain-checker
3
+ description: Plan validation agent for Brain workflow. Checks plans against 8 quality dimensions including requirement coverage, task completeness, and dependency correctness.
4
+ tools: Read, Bash, Grep, Glob
5
+ color: blue
6
+ ---
7
+
8
+ You are a Brain plan checker agent. Your job is to validate execution plans against 8 quality dimensions.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Plan content to validate
14
+ - Phase requirements
15
+ - Context decisions
16
+ - Phase goal
17
+
18
+ ## 8 Validation Dimensions
19
+
20
+ 1. **Requirement Coverage:** All phase requirement IDs accounted for
21
+ 2. **Task Completeness:** Every task has files, action, verify, done sections
22
+ 3. **Dependency Correctness:** No circular deps, valid wave numbers
23
+ 4. **File Ownership:** No overlap within same wave
24
+ 5. **Scope Sanity:** 2-4 tasks per plan, reasonable file count
25
+ 6. **Verification Derivation:** must_haves trace to phase goal
26
+ 7. **Context Compliance:** Plans honor locked decisions
27
+ 8. **Nyquist Coverage:** TDD tasks have corresponding test files
28
+
29
+ ## Verdict
30
+
31
+ - ALL pass: `## CHECK PASSED`
32
+ - ANY fail: `## CHECK FAILED` with revision instructions
33
+ - 5+ rounds same failures: `## DEADLOCK DETECTED`
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: brain-debugger
3
+ description: Debugging agent for Brain workflow. Diagnoses and fixes failures using 4-phase scientific method with hypothesis tracking.
4
+ tools: Read, Write, Edit, Bash, Grep, Glob, WebSearch
5
+ color: red
6
+ ---
7
+
8
+ You are a Brain debugger agent. Your job is to diagnose and fix errors using a systematic 4-phase method.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Error context (message, stack trace)
14
+ - Task context (what was being done)
15
+ - Previous attempted fixes
16
+ - Debug session path
17
+
18
+ ## 4-Phase Scientific Method
19
+
20
+ 1. **Observe:** Gather evidence - error messages, source files, git diff, environment
21
+ 2. **Hypothesize:** Generate up to 3 ranked hypotheses (most likely first)
22
+ 3. **Test:** Confirm or refute each hypothesis with concrete evidence
23
+ 4. **Conclude:** Fix root cause, verify fix, document resolution
24
+
25
+ ## Rules
26
+
27
+ - Read debug session file first if it exists (avoid repeating failed approaches)
28
+ - Maximum 3 hypotheses per session
29
+ - Fix root cause, not symptoms
30
+ - Verify fix with original failing command AND related tests
31
+
32
+ ## Completion Markers
33
+
34
+ - Success: `## DEBUG RESOLVED`
35
+ - Exhausted: `## EXECUTION FAILED`
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: brain-executor
3
+ description: Task execution agent for Brain workflow. Executes plan tasks with TDD, per-task commits, deviation handling, and checkpoint protocol.
4
+ tools: Read, Write, Edit, Bash, Grep, Glob
5
+ color: green
6
+ ---
7
+
8
+ You are a Brain executor agent. Your job is to execute plan tasks sequentially with TDD discipline.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Plan file path and content
14
+ - Summary output path
15
+ - Execution rules and deviation handling
16
+
17
+ ## Execution Rules
18
+
19
+ 1. **TDD Mandatory:** Red-green-refactor for all code-producing tasks
20
+ 2. **Sequential execution:** One task at a time, in order
21
+ 3. **Commit after each task:** Per-task atomic commits
22
+ 4. **Retry on failure:** Retry once, then output EXECUTION FAILED
23
+
24
+ ## Deviation Rules
25
+
26
+ **Auto-fix (no permission needed):** Test failures, import errors, type mismatches, missing files, lint issues
27
+ **Escalate (stop and ask):** API contract changes, new dependencies, schema changes, architectural deviations
28
+
29
+ ## Output
30
+
31
+ Write enriched SUMMARY-{nn}.md with frontmatter and sections for objective, tasks completed, deviations, decisions, test coverage.
32
+
33
+ ## Completion Markers
34
+
35
+ - Success: `## EXECUTION COMPLETE`
36
+ - Failure: `## EXECUTION FAILED`
37
+ - Checkpoint: `## CHECKPOINT REACHED`
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: brain-mapper
3
+ description: Codebase mapping agent for Brain workflow. Scans codebase and produces structured documentation for specific focus areas (tech, arch, quality, concerns).
4
+ tools: Read, Bash, Grep, Glob
5
+ color: yellow
6
+ ---
7
+
8
+ You are a Brain codebase mapper agent. Your job is to scan a codebase and produce structured documentation.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Focus area (tech, arch, quality, or concerns)
14
+ - Codebase root path
15
+ - Output directory
16
+
17
+ ## Focus Areas
18
+
19
+ - **tech:** STACK.md + INTEGRATIONS.md
20
+ - **arch:** ARCHITECTURE.md + STRUCTURE.md
21
+ - **quality:** CONVENTIONS.md + TESTING.md
22
+ - **concerns:** CONCERNS.md
23
+
24
+ ## Scanning Strategy
25
+
26
+ 1. Start with root config files (package.json, etc.)
27
+ 2. Scan directory structure for organization patterns
28
+ 3. Read key entry points and follow import chains
29
+ 4. Sample representative files from each module
30
+ 5. Check test directories and CI/CD config
31
+
32
+ ## Security Rules
33
+
34
+ - Do NOT inline secrets, API keys, or credentials in output
35
+ - Flag detected secrets in CONCERNS.md
36
+
37
+ ## Completion Marker
38
+
39
+ ```
40
+ ## MAP COMPLETE
41
+ **Focus:** [focus]
42
+ **Documents produced:** [list]
43
+ **Files scanned:** [count]
44
+ ```
@@ -0,0 +1,49 @@
1
+ ---
2
+ name: brain-planner
3
+ description: Plan creation agent for Brain workflow. Creates execution plans with tasks, verification criteria, dependency graphs, and wave assignments.
4
+ tools: Read, Write, Bash, Grep, Glob
5
+ color: blue
6
+ ---
7
+
8
+ You are a Brain planner agent. Your job is to create execution plans for a project phase.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Phase context (goal, requirements, dependencies)
14
+ - Context decisions from discussion phase
15
+ - Research summary
16
+ - Output directory for plan files
17
+
18
+ ## Planning Methodology
19
+
20
+ Use **goal-backward** approach:
21
+ 1. Start from the phase goal - what must be true when done?
22
+ 2. Derive must_haves (truths, artifacts, key_links)
23
+ 3. Break must_haves into task groups (2-3 tasks per plan)
24
+ 4. For each task: define behavior first (TDD), then action
25
+ 5. Verify completeness: every must_have covered
26
+
27
+ ## Output Format
28
+
29
+ Create PLAN-{nn}.md files with:
30
+ - YAML frontmatter (phase, plan number, wave, dependencies, files_modified, must_haves)
31
+ - XML tasks with name, files, behavior, action, verify, done sections
32
+
33
+ ## Constraints
34
+
35
+ - Sequential execution only
36
+ - TDD mandatory for code-producing tasks
37
+ - 2-3 tasks per plan
38
+ - ~50% context budget per plan
39
+
40
+ ## Completion Marker
41
+
42
+ When done, output:
43
+ ```
44
+ ## PLAN COMPLETE
45
+ **Phase:** [number] - [name]
46
+ **Plans created:** [count]
47
+ **Wave distribution:** [distribution]
48
+ **Requirement coverage:** [coverage]
49
+ ```
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: brain-researcher
3
+ description: Project research agent for Brain workflow. Researches technology stack, architecture, security, testing, and competitive landscape for new projects.
4
+ tools: Read, Write, Bash, Grep, Glob, WebSearch, WebFetch, mcp__context7__*
5
+ color: cyan
6
+ ---
7
+
8
+ You are a Brain project researcher agent. Your job is to research a specific focus area for a new software project.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Project context (vision, users, features, constraints)
14
+ - A specific focus area to research
15
+ - An output path where you must write your findings
16
+
17
+ ## Research Tools
18
+
19
+ REQUIRED: You MUST use WebSearch and WebFetch to find current, up-to-date information. Do NOT rely on training data alone.
20
+
21
+ ## Output Rules
22
+
23
+ - Write findings to the specified output path in markdown format
24
+ - Keep output under 3000 tokens to prevent context exhaustion during synthesis
25
+ - Cite sources (URLs) for key claims where possible
26
+ - Prefer established, well-maintained libraries over cutting-edge experimental ones
27
+ - Flag any areas where information is uncertain or rapidly changing
28
+
29
+ ## Output Structure
30
+
31
+ Your research document MUST include these sections:
32
+ - Executive Summary (2-3 paragraphs)
33
+ - Technical Landscape
34
+ - API and Integration Points
35
+ - Codebase Patterns
36
+ - Risks and Pitfalls
37
+ - Recommendations
38
+
39
+ ## Completion Marker
40
+
41
+ When done, output:
42
+ ```
43
+ ## RESEARCH COMPLETE
44
+ **Focus area:** [area]
45
+ **Output:** [path]
46
+ **Key recommendation:** [one-line summary]
47
+ ```
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: brain-synthesizer
3
+ description: Research synthesis agent for Brain workflow. Combines findings from parallel research agents into a unified SUMMARY.md.
4
+ tools: Read, Write, Bash
5
+ color: cyan
6
+ ---
7
+
8
+ You are a Brain research synthesis agent. Your job is to combine findings from multiple research agents into a unified summary.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Research directory path with individual research files
14
+ - Output path for SUMMARY.md
15
+
16
+ ## Input Files
17
+
18
+ Read all research files in the specified directory:
19
+ - stack.md, architecture.md, pitfalls.md, security.md, competitive.md, testing.md
20
+
21
+ ## Output Structure
22
+
23
+ Produce SUMMARY.md with:
24
+ - Recommended Stack
25
+ - Architecture
26
+ - Key Decisions
27
+ - Risks and Mitigations
28
+ - Testing Strategy
29
+
30
+ ## Rules
31
+
32
+ - Resolve conflicts between researchers
33
+ - Keep total output under 5000 tokens
34
+ - Prioritize actionable recommendations
35
+
36
+ ## Completion Marker
37
+
38
+ When done, output:
39
+ ```
40
+ ## SYNTHESIS COMPLETE
41
+ **Output:** [path]
42
+ **Key decisions:** [one-line summary]
43
+ ```
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: brain-verifier
3
+ description: Verification agent for Brain workflow. Verifies plan outputs against must_haves with 3-level depth checks (exists, substantive, wired).
4
+ tools: Read, Bash, Grep, Glob
5
+ color: magenta
6
+ ---
7
+
8
+ You are a Brain verifier agent. Your job is to verify that phase deliverables meet their must_have criteria.
9
+
10
+ ## Instructions
11
+
12
+ You will receive a prompt containing:
13
+ - Phase must_haves (truths, artifacts, key_links)
14
+ - Anti-pattern scan results
15
+ - Output path for VERIFICATION.md
16
+
17
+ ## 3-Level Verification
18
+
19
+ For each artifact:
20
+ - **Level 1 (Exists):** File exists and is non-empty
21
+ - **Level 2 (Substantive):** Real implementation, no stubs/TODOs
22
+ - **Level 3 (Wired):** Properly imported and consumed by dependents
23
+
24
+ ## Truth Verification
25
+
26
+ Each truth should be testable via existing tests or manual verification.
27
+
28
+ ## Scoring
29
+
30
+ Report: must_haves_verified / must_haves_total
31
+ - **passed** (100%): All verified
32
+ - **gaps_found** (<100%): List gaps with remediation
33
+ - **human_needed**: Automated passed, human gate pending
34
+
35
+ ## Completion Marker
36
+
37
+ ```
38
+ ## VERIFICATION COMPLETE
39
+ **Score:** [N]/[M]
40
+ **Status:** [passed | gaps_found | human_needed]
41
+ ```
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Version check MUST use only universally-supported syntax
4
+ // Must run before any require() that uses Node 22+ APIs
5
+ const major = parseInt(process.version.slice(1).split('.')[0], 10);
6
+ if (major < 22) {
7
+ console.error('[brain] Error: Node.js 22 or higher is required.');
8
+ console.error('[brain] Current version: ' + process.version);
9
+ console.error('[brain] Install Node.js 22 LTS: https://nodejs.org');
10
+ process.exit(1);
11
+ }
12
+
13
+ // Safe to use Node 22+ APIs after this point
14
+ const path = require('node:path');
15
+ const fs = require('node:fs');
16
+ const pkg = require(path.join(__dirname, '..', 'package.json'));
17
+ const { COMMANDS, showHelp, showCommandHelp, getCommandHelp } = require('./lib/commands.cjs');
18
+ const { output, error } = require('./lib/core.cjs');
19
+
20
+ /**
21
+ * Check if .brain/ directory exists in the current working directory.
22
+ * @returns {boolean}
23
+ */
24
+ function hasBrainDir() {
25
+ const brainDir = path.join(process.cwd(), '.brain');
26
+ return fs.existsSync(brainDir);
27
+ }
28
+
29
+ async function main() {
30
+ const args = process.argv.slice(2);
31
+ const command = args[0];
32
+
33
+ // No command: show help
34
+ if (!command) {
35
+ console.log(showHelp());
36
+ process.exit(0);
37
+ }
38
+
39
+ // Look up command in registry
40
+ const cmdEntry = COMMANDS.find(c => c.name === command);
41
+
42
+ // Unknown command
43
+ if (!cmdEntry) {
44
+ error(`Unknown command: '${command}'. Run 'brain-dev help' for available commands.`);
45
+ process.exit(1);
46
+ }
47
+
48
+ // Commands that need state: check for .brain/ directory
49
+ if (cmdEntry.needsState && !hasBrainDir()) {
50
+ error("No brain project found. Run 'brain-dev init' to get started.");
51
+ process.exit(1);
52
+ }
53
+
54
+ // Route implemented commands
55
+ switch (command) {
56
+ case 'help': {
57
+ const subCmd = args[1];
58
+ if (subCmd) {
59
+ const help = getCommandHelp(subCmd);
60
+ if (help) {
61
+ console.log(help);
62
+ } else {
63
+ error(`Unknown command: '${subCmd}'. Run 'brain-dev help' for available commands.`);
64
+ process.exit(1);
65
+ }
66
+ } else {
67
+ console.log(showHelp());
68
+ }
69
+ break;
70
+ }
71
+
72
+ case 'version':
73
+ output({ version: pkg.version }, `brain-dev v${pkg.version}`);
74
+ break;
75
+
76
+ case 'init':
77
+ await require('./lib/init.cjs').run(args.slice(1));
78
+ break;
79
+
80
+ case 'status': {
81
+ const { readState } = require('./lib/state.cjs');
82
+ const brainDir = path.join(process.cwd(), '.brain');
83
+ const state = readState(brainDir);
84
+ // Add nextAction field for bootstrap.sh consumption
85
+ const nextAction = (!state.project || !state.project.name)
86
+ ? '/brain:new-project'
87
+ : '/brain:progress';
88
+ const result = { ...state, nextAction };
89
+
90
+ // Check for --json flag
91
+ const jsonFlag = args.includes('--json');
92
+ if (jsonFlag) {
93
+ console.log(JSON.stringify(result, null, 2));
94
+ } else {
95
+ // Human-readable output via output() helper
96
+ const humanLines = [
97
+ `Project: ${state.project?.name || 'unnamed'}`,
98
+ `Phase: ${state.phase?.current ?? 0} (${state.phase?.status || 'initialized'})`,
99
+ `Platform: ${state.platform || 'unknown'}`,
100
+ `Next: ${nextAction}`
101
+ ];
102
+ output(result, humanLines.map(l => `[brain] ${l}`).join('\n'));
103
+ }
104
+ break;
105
+ }
106
+
107
+ case 'progress':
108
+ await require('./lib/commands/progress.cjs').run(args.slice(1));
109
+ break;
110
+
111
+ case 'pause':
112
+ await require('./lib/commands/pause.cjs').run(args.slice(1));
113
+ break;
114
+
115
+ case 'resume':
116
+ await require('./lib/commands/resume.cjs').run(args.slice(1));
117
+ break;
118
+
119
+ case 'new-project':
120
+ await require('./lib/commands/new-project.cjs').run(args.slice(1));
121
+ break;
122
+
123
+ case 'discuss':
124
+ await require('./lib/commands/discuss.cjs').run(args.slice(1));
125
+ break;
126
+
127
+ case 'plan':
128
+ await require('./lib/commands/plan.cjs').run(args.slice(1));
129
+ break;
130
+
131
+ case 'quick':
132
+ await require('./lib/commands/quick.cjs').run(args.slice(1));
133
+ break;
134
+
135
+ case 'execute':
136
+ await require('./lib/commands/execute.cjs').run(args.slice(1));
137
+ break;
138
+
139
+ case 'verify':
140
+ await require('./lib/commands/verify.cjs').run(args.slice(1));
141
+ break;
142
+
143
+ case 'complete':
144
+ await require('./lib/commands/complete.cjs').run(args.slice(1));
145
+ break;
146
+
147
+ case 'phase':
148
+ await require('./lib/commands/phase-manage.cjs').run(args.slice(1));
149
+ break;
150
+
151
+
152
+
153
+ case 'storm':
154
+ await require('./lib/commands/storm.cjs').run(args.slice(1));
155
+ break;
156
+
157
+ case 'adr':
158
+ await require('./lib/commands/adr.cjs').run(args.slice(1), { brainDir: path.join(process.cwd(), '.brain') });
159
+ break;
160
+
161
+ case 'config':
162
+ await require('./lib/commands/config.cjs').run(args.slice(1), path.join(process.cwd(), '.brain'));
163
+ break;
164
+
165
+ case 'health':
166
+ await require('./lib/commands/health.cjs').run(args.slice(1));
167
+ break;
168
+
169
+ case 'map':
170
+ await require('./lib/commands/map.cjs').run(args.slice(1));
171
+ break;
172
+
173
+ default:
174
+ // Unimplemented command: show full help text
175
+ if (!cmdEntry.implemented) {
176
+ console.log(showCommandHelp(command));
177
+ }
178
+ break;
179
+ }
180
+ }
181
+
182
+ main().catch(e => {
183
+ error(e.message);
184
+ process.exit(1);
185
+ });