create-merlin-brain 5.4.5 → 5.4.6

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.
package/bin/install.cjs CHANGED
@@ -351,6 +351,29 @@ function removeFile(filePath) {
351
351
  return false;
352
352
  }
353
353
 
354
+ // Non-destructive cleanup: move a legacy dir into a timestamped backup instead
355
+ // of hard-deleting it, so any custom files a user kept there stay recoverable.
356
+ // Dest names are flattened (commands/gsd -> commands__gsd) to avoid collisions.
357
+ function moveDirToBackup(dir, backupRoot) {
358
+ if (!fs.existsSync(dir)) return false;
359
+ const rel = dir.startsWith(CLAUDE_DIR + path.sep)
360
+ ? dir.slice(CLAUDE_DIR.length + 1)
361
+ : path.basename(dir);
362
+ const dest = path.join(backupRoot, rel.split(path.sep).join('__'));
363
+ try {
364
+ fs.mkdirSync(backupRoot, { recursive: true });
365
+ fs.renameSync(dir, dest);
366
+ return true;
367
+ } catch (e) {
368
+ // rename can fail across devices — copy then remove; never lose data silently
369
+ try {
370
+ fs.mkdirSync(dest, { recursive: true });
371
+ copyDirRecursive(dir, dest);
372
+ } catch (e2) { /* best effort backup */ }
373
+ return removeDirRecursive(dir);
374
+ }
375
+ }
376
+
354
377
  function setupShellIntegration() {
355
378
  const shell = process.env.SHELL || '/bin/zsh';
356
379
  const isZsh = shell.includes('zsh');
@@ -657,9 +680,12 @@ function cleanupLegacy() {
657
680
  path.join(CLAUDE_DIR, 'ralph-loop'),
658
681
  ];
659
682
 
683
+ // Back up legacy dirs instead of hard-deleting (recoverable if a user kept
684
+ // custom files in commands/gsd, workflows, templates, ccwiki, etc.).
685
+ const legacyBackupDir = path.join(CLAUDE_DIR, 'backups', 'legacy-' + Date.now());
660
686
  for (const dir of dirsToRemove) {
661
- if (removeDirRecursive(dir)) {
662
- cleaned.push('Removed ' + dir.replace(os.homedir(), '~'));
687
+ if (moveDirToBackup(dir, legacyBackupDir)) {
688
+ cleaned.push('Archived ' + dir.replace(os.homedir(), '~') + ' → ' + legacyBackupDir.replace(os.homedir(), '~'));
663
689
  }
664
690
  }
665
691
 
@@ -1071,6 +1097,22 @@ async function install() {
1071
1097
  logWarn('Skills not found in package');
1072
1098
  }
1073
1099
 
1100
+ // Step 7c: Install top-level native Claude Code skills (~/.claude/skills/<name>/)
1101
+ // These register as first-class skills (LLM-recommended via their description),
1102
+ // unlike the nested merlin/ tree. Source: files/skills/<name>/SKILL.md + refs.
1103
+ const nativeSkillsSrc = path.join(filesDir, 'skills');
1104
+ if (fs.existsSync(nativeSkillsSrc)) {
1105
+ const skillsRoot = path.join(CLAUDE_DIR, 'skills');
1106
+ ensureDir(skillsRoot);
1107
+ let nativeCount = 0;
1108
+ for (const entry of fs.readdirSync(nativeSkillsSrc, { withFileTypes: true })) {
1109
+ if (!entry.isDirectory() || entry.name === 'merlin') continue; // merlin tree handled in 7b
1110
+ copyDirRecursive(path.join(nativeSkillsSrc, entry.name), path.join(skillsRoot, entry.name));
1111
+ nativeCount++;
1112
+ }
1113
+ if (nativeCount > 0) logSuccess(`Installed ${nativeCount} native skill(s) (incl. ultimate-code-review)`);
1114
+ }
1115
+
1074
1116
  // Step 8: Install commands
1075
1117
  logStep('8/14', 'Installing /merlin:* commands...');
1076
1118
  const commandsSrc = path.join(filesDir, 'commands', 'merlin');
@@ -1240,6 +1282,14 @@ async function install() {
1240
1282
  hooks: [{ type: 'command', command: 'bash ~/.claude/hooks/post-edit-logger.sh' }]
1241
1283
  });
1242
1284
 
1285
+ // PostToolUse hook (ALL tools): user-visible Merlin feed marker — prints
1286
+ // "⟡🔮 MERLIN › <tool>" in the feed for every action so it is always clear
1287
+ // work is driven by Merlin. Opt out per-session with MERLIN_NO_ACTION_MARKER=1.
1288
+ addHookIfMissing(settings.hooks.PostToolUse, {
1289
+ matcher: '*',
1290
+ hooks: [{ type: 'command', command: 'bash ~/.claude/hooks/merlin-action-marker.sh' }]
1291
+ });
1292
+
1243
1293
  // Stop hook (session end)
1244
1294
  settings.hooks.Stop = settings.hooks.Stop || [];
1245
1295
  addHookIfMissing(settings.hooks.Stop, {
@@ -0,0 +1,48 @@
1
+ ---
2
+ name: merlin:ultimate-code-review
3
+ description: Run the Ultimate Code Review — map → parallel subagent review → classify findings → STOP for human approval → execute only approved fixes in minimum-risk order with verified proof. For a feature, subsystem, or product area (not quick single-file PRs).
4
+ argument-hint: "[subsystem / folder / feature to audit]"
5
+ allowed-tools:
6
+ - Read
7
+ - Grep
8
+ - Glob
9
+ - Bash
10
+ - Agent
11
+ - AskUserQuestion
12
+ - Skill
13
+ ---
14
+
15
+ <objective>
16
+ Invoke the `ultimate-code-review` skill and run it end to end on the target the
17
+ user names in arguments. This is the slash-command entry point; the skill itself
18
+ holds the full method (Phases 0–7 + verification gate).
19
+ </objective>
20
+
21
+ <process>
22
+ 1. **Load the skill.** Call `Skill("ultimate-code-review")` and follow its phases
23
+ exactly. If the Skill tool is unavailable in this harness, read the skill
24
+ directly from `~/.claude/skills/ultimate-code-review/SKILL.md` (and its
25
+ `references/*.md`) and follow it verbatim.
26
+
27
+ 2. **Scope.** Use the argument as the area to audit (subsystem, folder, feature).
28
+ If no argument is given, ask the user what to review — do not guess scope.
29
+
30
+ 3. **Honor the hard gate.** The entire review half is READ-ONLY. Map → batch
31
+ (≤5000 lines/group) → spawn one read-only subagent per group IN PARALLEL →
32
+ classify findings → synthesize → present the **decision artifact** and STOP.
33
+ Edit nothing until the human approves per-batch.
34
+
35
+ 4. **Execute only what's approved**, in the skill's minimum-risk order
36
+ (safety/truth → correctness → contract collapse → tests → graveyard →
37
+ enhancement), passing the verification gate after each change.
38
+
39
+ 5. **Badge every action** with `~/.claude/scripts/duo-badge.sh` output, per the
40
+ Merlin orchestrator contract.
41
+ </process>
42
+
43
+ <notes>
44
+ - This is heavyweight and explicit-invocation only. For a quick single-file or
45
+ PR-level pass, use the lighter `/code-review` instead.
46
+ - The orchestrator must NOT write code during the review half — route fixes
47
+ through the approved-batch execution phase.
48
+ </notes>
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Merlin Hook: PostToolUse (ALL tools) — user-visible feed marker.
4
+ #
5
+ # Prints a "⟡🔮 MERLIN › <tool>" line into the Claude transcript/feed on every
6
+ # tool action, so it is always clear that work is being driven by Merlin.
7
+ #
8
+ # Mechanism: Claude Code renders a hook's `systemMessage` field to the USER (the
9
+ # feed) — unlike `additionalContext`, which only the model sees. Fires once per
10
+ # tool call (matcher "*").
11
+ #
12
+ # Contract: pure bash, <50ms, no network, always exits 0. Emits valid JSON.
13
+ # Opt-out: set MERLIN_NO_ACTION_MARKER=1 to silence (hook stays installed).
14
+ #
15
+ set -uo pipefail
16
+
17
+ # Opt-out escape hatch — emit nothing actionable, stay silent.
18
+ if [ "${MERLIN_NO_ACTION_MARKER:-}" = "1" ]; then
19
+ echo "{}"
20
+ exit 0
21
+ fi
22
+
23
+ input=$(cat 2>/dev/null || true)
24
+
25
+ # ── Tool name (jq if present, grep fallback) ──
26
+ tool=""
27
+ if command -v jq >/dev/null 2>&1; then
28
+ tool=$(printf '%s' "$input" | jq -r '.tool_name // .tool // empty' 2>/dev/null || true)
29
+ else
30
+ tool=$(printf '%s' "$input" | grep -o '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"\([^"]*\)"$/\1/' 2>/dev/null || true)
31
+ fi
32
+ [ -z "$tool" ] && tool="action"
33
+
34
+ # ── Badge (duo-aware), cached ~10min to avoid spawning duo-badge.sh every call ──
35
+ badge="⟡🔮 MERLIN ›"
36
+ cache="${TMPDIR:-/tmp}/.merlin-action-badge"
37
+ if [ -f "$cache" ] && [ -n "$(find "$cache" -mmin -10 2>/dev/null || true)" ]; then
38
+ badge=$(cat "$cache" 2>/dev/null || echo "⟡🔮 MERLIN ›")
39
+ elif [ -x "$HOME/.claude/scripts/duo-badge.sh" ]; then
40
+ badge=$("$HOME/.claude/scripts/duo-badge.sh" 2>/dev/null || echo "⟡🔮 MERLIN ›")
41
+ printf '%s' "$badge" > "$cache" 2>/dev/null || true
42
+ fi
43
+
44
+ msg="${badge} ${tool}"
45
+
46
+ # ── Emit user-visible marker. suppressOutput hides the raw stdout echo but the
47
+ # systemMessage still renders in the feed. ──
48
+ if command -v jq >/dev/null 2>&1; then
49
+ jq -n --arg m "$msg" '{systemMessage:$m, suppressOutput:true}'
50
+ else
51
+ esc=$(printf '%s' "$msg" | sed 's/\\/\\\\/g; s/"/\\"/g' | tr -d '\000-\037')
52
+ printf '{"systemMessage":"%s","suppressOutput":true}\n' "$esc"
53
+ fi
54
+ exit 0
@@ -37,8 +37,12 @@ fi
37
37
  # ── Intent matching (order matters — most specific first) ─────────────────────
38
38
  suggestion=""
39
39
 
40
+ # Ultimate Code Review — explicit, heavyweight audit-and-fix (most specific, check first)
41
+ if echo "$prompt" | grep -qiE "ultimate code review|audit (this|the) (subsystem|codebase|module|feature|service|area)|full review.?and.?fix|review.?and.?fix pass|deep code audit"; then
42
+ suggestion='Detected: ultimate code review. Use: Skill("ultimate-code-review") or /merlin:ultimate-code-review (read-only review → approval gate → approved fixes only)'
43
+
40
44
  # Resume — check before generic "plan" or "build"
41
- if echo "$prompt" | grep -qiE "I'm back|im back|resume|pick up|continue|where were we"; then
45
+ elif echo "$prompt" | grep -qiE "I'm back|im back|resume|pick up|continue|where were we"; then
42
46
  suggestion='Detected: resume. Use: Skill("merlin:resume-work")'
43
47
 
44
48
  # Progress / status
@@ -114,6 +114,15 @@ ${TASK_TEXT}"
114
114
  # and codex-implementer returning empty diffs). Closing stdin tells Codex "no extra input"
115
115
  # and lets it proceed with just the prompt arg.
116
116
  #
117
+ # Merlin feed marker — Codex has no hook/feed-injection API (unlike Claude Code's
118
+ # PostToolUse systemMessage), so the best available signal is a stderr line shown
119
+ # in the feed whenever Merlin routes an action to Codex. Honest, wrapper-level.
120
+ if [ "${MERLIN_NO_ACTION_MARKER:-}" != "1" ]; then
121
+ _BADGE="⟡🔮 MERLIN ›"
122
+ [ -x "$HOME/.claude/scripts/duo-badge.sh" ] && _BADGE="$("$HOME/.claude/scripts/duo-badge.sh" 2>/dev/null || echo "⟡🔮 MERLIN ›")"
123
+ printf '%s Codex ▸ %s\n' "$_BADGE" "$AGENT_NAME" >&2
124
+ fi
125
+
117
126
  # Wrap with timeout using the portable with-timeout.sh wrapper.
118
127
  WITH_TIMEOUT="$(dirname "${BASH_SOURCE[0]}")/with-timeout.sh"
119
128
  if [[ -x "$WITH_TIMEOUT" ]]; then
@@ -0,0 +1,111 @@
1
+ ---
2
+ name: ultimate-code-review
3
+ description: End-to-end audit, refactor strategy, and approval-gated remediation for large or complex codebases. Use ONLY when explicitly invoked (e.g. "run the ultimate code review", "audit this subsystem", "do a full review-and-fix pass on X"). Requires Claude Code with subagents. The skill maps every related file, splits them into parallel review groups, runs line-by-line subagent reviews, classifies findings (bugs vs architecture vs dead code vs test gaps vs product gaps), produces a product-level decision artifact, STOPS for human approval, then executes only the approved fixes in minimum-risk order with verified proof of behavior. Do not trigger for ordinary single-file reviews or quick PR feedback.
4
+ ---
5
+
6
+ # Ultimate Code Review
7
+
8
+ Run a disciplined audit-and-fix pass on a feature, subsystem, or product area. Two halves, separated by a hard gate:
9
+
10
+ 1. **Review half (read-only):** map → batch → parallel review → synthesize → present a decision artifact.
11
+ 2. **Fix half (write):** execute ONLY what the human approved, in minimum-risk order, each change proven.
12
+
13
+ The skill is invoked explicitly. It assumes Claude Code with subagents — the parallel review depends on them. It is stack-agnostic: detect the project's real tools before assuming any command.
14
+
15
+ ## The One Rule That Matters Most
16
+
17
+ **Nothing is edited before the human approves.** The entire review half is read-only. The output of the review half is not a refactor — it is a decision the human can make using product logic: what is broken, what could break if touched, in what order to fix, and which batches to greenlight. Treat any urge to "just fix this small thing while I'm here" as a violation.
18
+
19
+ ## Operating Principles
20
+
21
+ - Read-only until approval. Map, batch, review, synthesize, present — then wait.
22
+ - Every review group is at or below 5000 physical lines. One subagent reviewer per group, one group per reviewer.
23
+ - Group files by ownership boundary: feature, runtime layer, data flow, or source-of-truth contract.
24
+ - Review line by line with concrete file references and behavioral reasoning, never by vibes.
25
+ - Separate current-state bugs from structural issues and from missing capabilities. These get fixed in different orders and carry different risk.
26
+ - Prefer deleting or collapsing duplicate paths over adding another abstraction.
27
+ - Fix toward enforceable contracts, not advisory guidance.
28
+ - The goal is not a giant refactor. It is a sequence of small, verified changes that steadily removes uncertainty.
29
+
30
+ ## Phase 0: Stack Detection
31
+
32
+ Before any search or command, detect what this codebase actually uses. Never assume `rg`, `pnpm`, `vitest`, or any specific toolchain. See `references/verification-gate.md` for the detection checklist.
33
+
34
+ Establish and record:
35
+ - primary language(s) and where source lives;
36
+ - the fast search tool available (`rg`, else `grep -r`);
37
+ - the test runner and how to invoke a single test;
38
+ - the build/type-check command;
39
+ - the repo's own conventions (file-size limits, folder structure, lint rules) — adopt them, do not impose your own.
40
+
41
+ If you cannot determine the test or build command, ask the human once. Do not guess and run.
42
+
43
+ ## Phase 1: Scope Discovery
44
+
45
+ Identify every file related to the requested area. Search source, tests, prompts/resources, schemas/manifests, docs, scripts, build config, UI surfaces, and any telemetry/policy/scheduler/persistence code.
46
+
47
+ Record *why* each file is in scope and classify it: primary, secondary, test, doc/resource, or possible graveyard. Do not pull in a file just because a keyword appears once.
48
+
49
+ ## Phase 2: Line Count And Grouping
50
+
51
+ Count lines for every in-scope file. Build virtual groups, each ≤5000 total lines.
52
+
53
+ - Keep strongly coupled files together.
54
+ - Split large areas by contract: routing, approval, scheduler, persistence, prompts, UI, tests, tools.
55
+ - A single file over 5000 lines becomes its own exception group, flagged as too large.
56
+ - Include tests with the code they prove when the group stays under budget; otherwise a separate test group.
57
+ - Keep generated/stale docs separate from executable code.
58
+
59
+ For each group record: id, purpose, included files, total lines, the review question, expected source-of-truth contracts, and adjacent groups to cross-check.
60
+
61
+ ## Phase 3: Parallel Reviewer Assignment
62
+
63
+ Spawn one subagent per group, in parallel, in the same turn. Give each the prompt in `references/reviewer-prompt.md`. Every reviewer is read-only and returns structured findings using the taxonomy in `references/findings-taxonomy.md`.
64
+
65
+ If there are more groups than is practical to spawn at once, batch the spawns — but never collapse two groups into one reviewer, and never let a reviewer exceed its 5000-line budget.
66
+
67
+ ## Phase 4: Line-By-Line Review Standard
68
+
69
+ This standard governs what reviewers look for. It is spelled out in `references/reviewer-prompt.md` so it can be handed to subagents verbatim. The core questions: what state does this read/write, is it authoritative or a cache, who else claims that truth, is this path reachable in production, does the test exercise real behavior, can success be marked before work is durable, can a schema/approval/UI claim something enforcement does not guarantee.
70
+
71
+ ## Phase 5: Synthesis
72
+
73
+ Merge group reports into one architecture picture and the document set defined in `references/synthesis-docs.md` (index, architecture, review-batches, findings, graveyard-and-duplication, testing-gaps, product-gap-analysis, remediation-guide). Keep each doc small; split anything approaching the repo's file-size rule.
74
+
75
+ Classify every finding using `references/findings-taxonomy.md`. Be consistent — the fix order in the next phase depends entirely on correct classification.
76
+
77
+ ## ⛔ Phase 6: The Approval Gate
78
+
79
+ This is the center of the skill. Stop here. Present a **decision artifact** — not the full doc set, not diffs. The human reasons in product logic, so speak in product logic.
80
+
81
+ For each proposed fix or fix-batch, present:
82
+ - **What** changes, in one plain sentence (no code).
83
+ - **Why** it matters — the user-facing or correctness consequence of leaving it.
84
+ - **Blast radius** — what else touches this, what could break, reversibility.
85
+ - **Class** — safety/truth bug, correctness, contract collapse, test repair, dead-code prune, or enhancement.
86
+ - **Order rank** — where it falls in the minimum-risk sequence.
87
+
88
+ Then present the ranked sequence and ask the human to approve, defer, or reject **each batch**. Offer a recommended default (usually: approve safety/truth and correctness now, hold enhancement). Explicitly state non-goals — what you will NOT touch.
89
+
90
+ Wait for an explicit yes. Approval is per-batch and does not generalize. If the human approves only some batches, execute only those.
91
+
92
+ ## Phase 7: Execute Approved Fixes
93
+
94
+ Fix only approved batches, in this order (skip any class the human deferred):
95
+
96
+ 1. **Safety & truth bugs** — approval gaps, irreversible side effects, external sends, destructive actions, premature success/cursor advancement.
97
+ 2. **Execution correctness** — scheduler completion, timeouts, retries, persistence/migrations.
98
+ 3. **Contract collapse** — one registry, one routing envelope, one executable schema, one status stream.
99
+ 4. **Test reliability** — stale tests, tests mirroring helpers, missing contract tests.
100
+ 5. **Graveyard pruning** — dead paths, stale resources, old shims (only after confirming unreachability).
101
+ 6. **Enhancement** — new capability, polish — only after the contracts above are stable.
102
+
103
+ Never build new capability on top of conflicting contracts. After each change, pass the verification gate in `references/verification-gate.md` before moving on. Respect the repo's file-size and structure conventions detected in Phase 0.
104
+
105
+ ## Verification Gate
106
+
107
+ No finding is closed until: the bug it addressed is named, the source of truth removed/enforced/validated is named, the line-level evidence of the old behavior is cited, a test or command proves the new behavior, and any remaining risk is stated. Full standard and commands in `references/verification-gate.md`. If verification cannot run, state exactly what was not run and why.
108
+
109
+ ## Final Handoff
110
+
111
+ End with: batch coverage summary, highest-risk bugs found, duplicated contracts collapsed, dead-code pruned or quarantined, tests repaired, what was executed vs deferred vs rejected, remaining product gaps, and explicit non-goals.
@@ -0,0 +1,57 @@
1
+ # Findings Taxonomy
2
+
3
+ Classify every finding into exactly one category. The fix order in Phase 7 depends on correct classification, so be strict about the boundaries.
4
+
5
+ ## Bug
6
+
7
+ Current behavior can produce wrong state, unsafe state, data loss, incorrect UI truth, failed execution, or misleading success.
8
+
9
+ Examples:
10
+ - success recorded before execution completes;
11
+ - approval shown as final before the side effect runs;
12
+ - a cursor or offset advanced before downstream success;
13
+ - schema accepts a field the runtime never implements;
14
+ - a test passes while the production path it claims to cover is never exercised.
15
+
16
+ ## Architecture Issue
17
+
18
+ The structure itself causes repeated bugs or blocks safe change. The code may "work" today but is shaped to break.
19
+
20
+ Examples:
21
+ - the same role/tool/permission policy duplicated in two places;
22
+ - multiple approval queues that can disagree;
23
+ - two schedulers, two status stores, two routing paths;
24
+ - prompt assembled one way in docs, another way at runtime;
25
+ - several UI surfaces each inferring truth from a different store.
26
+
27
+ ## Dead / Graveyard Code
28
+
29
+ Code that appears stale, unreachable, superseded, compatibility-only, or actively misleading.
30
+
31
+ Before recommending deletion:
32
+ - search across all languages, prompts, docs, tests, build files, and runtime assets;
33
+ - check generated text and resource bundles;
34
+ - if reintroduction would be dangerous, recommend adding a test that locks the removal;
35
+ - if removal changes user-facing behavior, require a migration or explicit fallback.
36
+
37
+ ## Test Gap
38
+
39
+ Tests are missing, stale, unregistered, mirror helper logic instead of production logic, or assert something misleading.
40
+
41
+ ## Product Gap
42
+
43
+ A capability the intended experience needs but the code does not provide. This is not a bug — nothing is wrong; something is absent. Kept separate because it is fixed last and only after contracts are stable.
44
+
45
+ ## Stabilize (the reliable path)
46
+
47
+ Changes that make the *current* product reliable, explainable, and safe. Stabilize work usually converges the system toward:
48
+ - one enforced lifecycle;
49
+ - one authoritative registry;
50
+ - one routing envelope;
51
+ - one executable schema;
52
+ - one status stream;
53
+ - tests that prove the drift cannot return.
54
+
55
+ ## Enhance (the capable path)
56
+
57
+ New capability that makes the product feel obviously better, not merely less broken. Enhance work starts only after stabilize-level contracts exist — otherwise you are building on sand. Examples: reliable automation with evidence and recovery, approval-and-rollback for changes, scoped secure builders, a unified status/control surface.
@@ -0,0 +1,48 @@
1
+ # Reviewer Subagent Prompt
2
+
3
+ Hand this to each review subagent verbatim, filling in the bracketed fields. One reviewer per group. The reviewer is **read-only** — it must not edit any file.
4
+
5
+ ---
6
+
7
+ ## Prompt Template
8
+
9
+ You are reviewing one group of files as part of a larger codebase audit. Do not edit anything. Your job is to understand how this code actually behaves today and report structured findings.
10
+
11
+ **Group:** [group id]
12
+ **Purpose of this group:** [one line]
13
+ **Review question:** [the specific question this group must answer]
14
+ **Files (read every one, line by line):**
15
+ [list with line counts]
16
+ **Expected source-of-truth contracts:** [what this group is supposed to own]
17
+ **Adjacent groups to keep in mind:** [for cross-checking]
18
+
19
+ ### How to review
20
+
21
+ Read every function, type, prompt, schema, test, and state transition. For each, ask:
22
+
23
+ - What state does this read or write?
24
+ - Is that state authoritative, or a cache of truth owned elsewhere?
25
+ - What other file claims to own the same truth?
26
+ - Is this path actually reachable in production, or is it dead/legacy/compat?
27
+ - Does the test exercise real production behavior, or mirror helper logic?
28
+ - Can this mark success before the work is durable?
29
+ - Can an approval, policy, prompt, or UI claim something that enforcement does not actually guarantee?
30
+ - Does a schema accept fields the runtime ignores?
31
+ - Can cancellation, retries, migrations, or async delivery race?
32
+ - Does the UI read from the same truth as the runtime?
33
+
34
+ Cite concrete file paths and line references. Distinguish confirmed findings from hypotheses. Do not draw broad conclusions without a concrete code path.
35
+
36
+ ### Return findings in this structure
37
+
38
+ - **Bugs** — behavior is wrong or unsafe now.
39
+ - **Architecture Issues** — duplicated, conflicting, or missing source-of-truth contracts.
40
+ - **Dead / Graveyard** — unused, stale, legacy, or compatibility-only paths.
41
+ - **Test Gaps** — missing, stale, unregistered, or misleading tests.
42
+ - **Product Gaps** — capability missing for the intended experience.
43
+ - **Stabilize** — narrow changes that make current behavior reliable.
44
+ - **Enhance** — future capability, only meaningful after stabilize work lands.
45
+
46
+ For each finding give: the file + lines, what actually happens today, why it matters, and (for bugs/architecture) what would need to be true for a safe fix.
47
+
48
+ Definitions for classifying findings are in `findings-taxonomy.md`.
@@ -0,0 +1,53 @@
1
+ # Synthesis Documents
2
+
3
+ After all reviewers return, merge their reports into one architecture picture plus the document set below. Keep each document small — if one approaches the repo's file-size rule, split it. Write them to a `review/` folder (or the repo's docs location).
4
+
5
+ ## The Document Set
6
+
7
+ - **README.md** — index, read order, one-paragraph system summary, and the source-of-truth map (which file owns which truth).
8
+ - **architecture.md** — current data flows and runtime layers, as they actually are, not as intended.
9
+ - **review-batches.md** — every group, its files, line counts, and headline findings.
10
+ - **findings.md** — consolidated bugs and risks grouped by theme.
11
+ - **graveyard-and-duplication.md** — dead paths and duplicate concepts.
12
+ - **testing-gaps.md** — stale tests and missing contract coverage.
13
+ - **product-gap-analysis.md** — what is missing versus the intended product.
14
+ - **remediation-guide.md** — a clean handoff a fresh agent could execute.
15
+
16
+ These are the *evidence*. They are not what you put in front of the human at the gate.
17
+
18
+ ## The Decision Artifact (Phase 6)
19
+
20
+ This is the only thing the human reads to decide. It is built from the docs above but contains no code and no diffs. Use this exact shape:
21
+
22
+ ```
23
+ # Decision: <area> review
24
+
25
+ ## What I found (one paragraph, plain language)
26
+ <the system in 3-4 sentences: what works, what's fragile, the single biggest risk>
27
+
28
+ ## Proposed fixes, ranked by minimum risk
29
+
30
+ ### Batch 1 — <name> [Class: safety/truth]
31
+ - What: <one plain sentence, no code>
32
+ - Why it matters: <user-facing or correctness consequence of leaving it>
33
+ - Blast radius: <what else touches this; what could break; reversible?>
34
+ - Recommend: APPROVE NOW
35
+
36
+ ### Batch 2 — <name> [Class: correctness]
37
+ ...
38
+
39
+ ### Batch N — <name> [Class: enhancement]
40
+ - Recommend: DEFER until contracts stable
41
+
42
+ ## What I will NOT touch (non-goals)
43
+ <explicit list>
44
+
45
+ ## Your call
46
+ Approve / defer / reject each batch. My default recommendation: <...>
47
+ ```
48
+
49
+ Rules for the artifact:
50
+ - One sentence of "what" per fix. If it needs a paragraph, the human can ask — keep the surface clean.
51
+ - Always state blast radius and reversibility; that is what the human reasons about.
52
+ - Always give a recommended default so the human can say "go with your defaults."
53
+ - Never include batches the human hasn't seen classified. No surprises at execution time.
@@ -0,0 +1,62 @@
1
+ # Stack Detection & Verification Gate
2
+
3
+ ## Phase 0: Stack Detection Checklist
4
+
5
+ Detect, never assume. Run these before any other work and record the answers.
6
+
7
+ **Language & layout**
8
+ - Look for manifest files: `package.json`, `pyproject.toml` / `requirements.txt`, `Cargo.toml`, `go.mod`, `*.xcodeproj` / `Package.swift`, `pom.xml` / `build.gradle`, `Gemfile`, `composer.json`.
9
+ - The manifest tells you the language, the package manager, and usually the scripts.
10
+
11
+ **Search tool**
12
+ - Prefer `rg` if present (`command -v rg`). Otherwise fall back to `grep -rn`.
13
+
14
+ **Test runner** (read the manifest's scripts/config first)
15
+ - JS/TS: check `package.json` scripts for `test`; detect `vitest` / `jest` / `mocha`. Find how to run ONE test file.
16
+ - Python: `pytest` vs `unittest`; how to run one test.
17
+ - Rust: `cargo test`. Go: `go test ./...`. Swift: `xcodebuild test` or `swift test`.
18
+ - Never invent a runner — if the manifest doesn't reveal one, ask the human.
19
+
20
+ **Build / type-check**
21
+ - TS: `tsc --noEmit` or the project's build script. Python: type checker if configured (`mypy`, `pyright`). Rust: `cargo build`. Swift: `xcodebuild`.
22
+
23
+ **Repo conventions**
24
+ - Look for `.editorconfig`, lint configs, a `CLAUDE.md` or `CONTRIBUTING.md`, and any stated file-size or folder-structure rules. Adopt the repo's rules; do not impose external ones.
25
+
26
+ If test or build commands can't be determined, ask once. Do not guess and run a command that could mutate state.
27
+
28
+ ## Verification Gate
29
+
30
+ No finding is closed until every answer is clear:
31
+
32
+ - What bug or issue did this address?
33
+ - What source of truth was removed, enforced, or validated?
34
+ - What line-level evidence showed the old behavior?
35
+ - What test or command proves the new behavior?
36
+ - What UI, event, or status now tells the truth?
37
+ - What graveyard path was deleted, quarantined, or intentionally left?
38
+ - What risk remains?
39
+
40
+ ## Verify narrowly, then broadly
41
+
42
+ After a change, prove it locally before widening:
43
+
44
+ ```sh
45
+ # 1. confirm the changed symbol/contract's call sites
46
+ <search-tool> -n "changedSymbol"
47
+
48
+ # 2. type-check / build (use the detected command)
49
+ <build-command>
50
+
51
+ # 3. run the single most relevant test first
52
+ <test-runner> <one-test>
53
+
54
+ # 4. then the surrounding suite
55
+ <test-runner> <suite>
56
+ ```
57
+
58
+ Use the repo's actual detected commands, not these placeholders. If full verification cannot run (missing credentials, no device, slow integration suite), state exactly what was not run and why, and what residual risk that leaves.
59
+
60
+ ## Order of execution (mirror of Phase 7)
61
+
62
+ Fix safety/truth → correctness → contract collapse → test reliability → graveyard pruning → enhancement. Each step passes this gate before the next begins. Never build enhancement on unstable contracts.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-merlin-brain",
3
- "version": "5.4.5",
3
+ "version": "5.4.6",
4
4
  "description": "Merlin - The Ultimate AI Brain for Claude Code, Codex, and other AI CLIs. One install: workflows, agents, loop, and Sights MCP server.",
5
5
  "type": "module",
6
6
  "main": "./dist/server/index.js",