project-brain 0.42.0 → 0.44.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.
@@ -0,0 +1,118 @@
1
+ export type CallStatus = 'running' | 'ok' | 'error' | 'denied' | 'interrupted'
2
+
3
+ export type Decision = { question: string; answer: string; refused?: boolean }
4
+
5
+ export type TestFile = { file: string; ok: boolean }
6
+
7
+ export type ToolEntry = {
8
+ id: string
9
+ tool: string
10
+ summary: string
11
+ status: CallStatus
12
+ output: string
13
+ startedAt: number
14
+ durationMs?: number
15
+ agentId?: string
16
+ command?: string
17
+ file?: string
18
+ note?: string
19
+ exitCode?: number
20
+ testFiles?: TestFile[]
21
+ decisions?: Decision[]
22
+ spawned?: string
23
+ }
24
+
25
+ export type Tab = 'summary' | 'commands' | 'diff' | 'history'
26
+
27
+ export type CambiosScope = 'commits' | 'uncommitted' | 'branch'
28
+
29
+ export type AgentState = 'running' | 'done' | 'failed'
30
+
31
+ export type AgentRecord = {
32
+ id: string
33
+ description: string
34
+ type: string
35
+ name?: string
36
+ state: AgentState
37
+ startedAt: number
38
+ }
39
+
40
+ export type PaneScroll = { offset: number; follow: boolean }
41
+
42
+ export type FileChange = { path: string; added: number; removed: number; untracked?: boolean; binary?: boolean }
43
+
44
+ export type CommitRecord = {
45
+ sha: string
46
+ subject: string
47
+ branch: string
48
+ agentId?: string
49
+ at: number
50
+ isMerge?: boolean
51
+ added?: number
52
+ removed?: number
53
+ files?: FileChange[]
54
+ statsFailed?: boolean
55
+ }
56
+
57
+ export type BranchCommit = { sha: string; subject: string }
58
+
59
+ export type BranchView = {
60
+ isLoaded: boolean
61
+ baseRef?: string
62
+ base?: string
63
+ files: FileChange[]
64
+ commits: BranchCommit[]
65
+ error?: string
66
+ }
67
+
68
+ /** A commit-verb Bash call: when it ran, who ran it, and the worktree it ran in when the command named one. */
69
+ export type CommitCall = { agentId?: string; top?: string; startedAt: number; endedAt: number }
70
+
71
+ /** One line of `git log --graph`: graph glyphs alone, or a commit with its fields. */
72
+ export type HistoryRow = { graph: string; sha?: string; refs?: string[]; subject?: string; at?: number; author?: string }
73
+
74
+ export type HistoryState = 'idle' | 'loading' | 'ready' | 'error'
75
+
76
+ export type HistoryView = { state: HistoryState; rows: HistoryRow[]; more: number; loadedAt: number; error?: string }
77
+
78
+ export type HistoryFiles = { files?: FileChange[]; failed?: boolean }
79
+
80
+ export type DiffRow = { gutter: string; sign: string; text: string; kind: 'add' | 'del' | 'hunk' | 'same' }
81
+
82
+ export type DiffPatch = { rows: DiffRow[]; total: number }
83
+
84
+ export type ContextUsage = { tokens?: number; window: number; percent?: number }
85
+
86
+ export type StepContext = { tokens: number; model: string }
87
+
88
+ export type EditorState = { dir: string; tab: string }
89
+
90
+ declare module 'claude-code' {
91
+ interface PluginState {
92
+ 'project-brain-activity': {
93
+ entries: Shaped<ToolEntry[]>
94
+ tabs: Shaped<Record<string, Tab>>
95
+ toggled: Shaped<string[]>
96
+ changes: Shaped<FileChange[]>
97
+ costUsd: Shaped<number>
98
+ context: Shaped<ContextUsage>
99
+ stepContext: Shaped<Record<string, StepContext>>
100
+ openFiles: Shaped<string[]>
101
+ diffs: Shaped<Record<string, DiffPatch>>
102
+ agents: Shaped<AgentRecord[]>
103
+ pickedAgent: Shaped<string>
104
+ working: Shaped<boolean>
105
+ scroll: Shaped<PaneScroll>
106
+ commits: Shaped<CommitRecord[]>
107
+ scopes: Shaped<Record<string, CambiosScope>>
108
+ branch: Shaped<BranchView>
109
+ autoOpen: Shaped<boolean>
110
+ editor: Shaped<EditorState>
111
+ sessionStart: Shaped<number>
112
+ commitCalls: Shaped<CommitCall[]>
113
+ history: Shaped<HistoryView>
114
+ accent: Shaped<string>
115
+ historyFiles: Shaped<Record<string, HistoryFiles>>
116
+ }
117
+ }
118
+ }
@@ -0,0 +1,65 @@
1
+ ---
2
+ name: brain-design-review
3
+ description: "Trigger: design review, design audit, visual QA, revisa el diseño, AI slop, polish this UI, audit and fix the design, does this look designed. Audits a rendered UI like a designer, scores it, then fixes the findings one commit each and re-verifies."
4
+ license: Apache-2.0
5
+ metadata:
6
+ author: jcsoftdev
7
+ version: "1.0"
8
+ generator: project-brain
9
+ ---
10
+
11
+ <!--
12
+ `generator: project-brain` is an ownership marker, not decoration.
13
+ `project-brain setup` overwrites this directory only when it finds that line;
14
+ without it, setup treats the directory as hand-written and leaves it alone.
15
+ Strip it and you pin this copy forever — no upgrade will ever reach it.
16
+ -->
17
+
18
+ ## Activation Contract
19
+
20
+ Use when a live or local UI must be judged on how it looks and feels, and the findings should be fixed. Report-only: use `brain-qa-only`. Whole-product MVP verdict: `mvp-ui-review`. Building new UI: `impeccable`.
21
+
22
+ ## Hard Rules
23
+
24
+ - Judge the rendered page, never the source. Source is read only in the fix phase.
25
+ - Every finding carries a screenshot and a measured value from `evaluate_script`. "Spacing feels off" is not a finding: "gap is 13px, scale is 8/16, use 16" is.
26
+ - Browser ladder: `chrome-devtools` first; `claude-in-chrome` only for a session the user said to reuse; never Playwright by default.
27
+ - Own the tab you open and close it before finishing. Never type passwords or payment data; on a login wall ask the user to sign in, then continue.
28
+ - Non-local targets are read-only: no submit, create or delete.
29
+ - Calibrate against the project's own system: `DESIGN.md`, then `:root` tokens and the tailwind or theme config. A departure from a token ranks higher; name the token.
30
+ - Fix only on a clean tree and on a branch. One fix, one commit, message by `brain-commit`. Code follows `brain-style`.
31
+ - Information on screen must be real data or an honest empty state; fixtures that look real are a finding.
32
+
33
+ ## Decision Gates
34
+
35
+ | Situation | Action |
36
+ |-----------|--------|
37
+ | No URL, feature branch | Diff-aware: `git diff <base>...HEAD --name-only`, map files to routes, audit those. Base from `gh pr view`, else the default branch, never assumed |
38
+ | No URL, default branch | Detect a dev server through `port_acquire` leases or ask |
39
+ | Dirty tree | Ask once: commit, stash, or abort. Prefer a `brain-worktree` when other work is in flight |
40
+ | Surface is native (SwiftUI, AppKit) | Render offscreen and read the image. `ImageRenderer` draws AppKit-backed controls as yellow placeholders: say so, do not grade them |
41
+ | `impeccable` installed | Run its detector and `audit` as a second opinion; dedupe against your findings |
42
+ | Finding is a third-party widget or copy | Defer, do not fix |
43
+ | Needs the cause in code | `search_context` / `find_symbol` to reach the component, not grep |
44
+
45
+ ## Execution Steps
46
+
47
+ 1. Classify each surface first: Persuade (landing), Operate (app UI), Read (docs), Experience (showcase). Rules differ; see `references/audit.md`.
48
+ 2. Capture the system: tokens and `DESIGN.md`, then the rendered one with `references/probes.md` (fonts, colors, heading scale, touch targets).
49
+ 3. First impression: full-page screenshot, then write what it says, the first three things the eye lands on, one word. Run the Trunk Test (6 questions) per page.
50
+ 4. Per page: `take_snapshot`, `take_screenshot` at 375, 768, 1440 via `resize_page` or `emulate`, `list_console_messages`, `list_network_requests`, `lighthouse_audit` for a11y and perf. Score the ten categories in `references/audit.md`.
51
+ 5. Walk 2-3 flows and keep the goodwill meter from `references/audit.md`. Check consistency across pages.
52
+ 6. Report baseline: Design Score and AI Slop Score (A-F), per-category grades, quick wins (3-5, under 30 minutes each).
53
+ 7. Triage by impact, then fix loop (`references/fix-loop.md`): locate, smallest CSS-first change, commit, re-render, classify verified, best-effort or reverted.
54
+ 8. Re-audit affected pages. If a score got worse, say so first.
55
+ 9. Save pitfalls worth keeping to engram (`mem_save`, topic `design-review/<project>`); a lasting constraint goes to the OKF bundle through `brain-okf`.
56
+
57
+ ## Output Contract
58
+
59
+ Report in `.design-review/<date>/report.md` (git-excluded, never tracked): scores before and after, findings (id, category, impact, evidence, fix status, commit SHA), before/after screenshot pairs, deferred list, one-line PR summary. Show the key screenshots inline with `Read`. Update `TODOS.md` only if it exists. State what was not covered.
60
+
61
+ ## References
62
+
63
+ - `references/audit.md` — ten-category checklist, AI-slop list, scoring, goodwill meter, hard rules.
64
+ - `references/probes.md` — `evaluate_script` functions for the rendered design system.
65
+ - `references/fix-loop.md` — fix, commit, re-test, risk cap.
@@ -0,0 +1,56 @@
1
+ # Design audit reference
2
+
3
+ Each finding: category, impact (high, medium, polish), screenshot, measured value.
4
+
5
+ ## Surface mode
6
+
7
+ | Mode | Visitor's win | Rules |
8
+ |---|---|---|
9
+ | Persuade (landing, pricing) | decides and acts | brand > headline > body > CTA; one composition in the first viewport; one job per section; cards only when the card is the interaction; one authored motion moment |
10
+ | Operate (app, dashboard, settings) | finishes a task | scanability and native expectations; calm surfaces, few colors; utility copy; headings say what the area is |
11
+ | Read (docs, articles) | understands | 65-75ch measure, one column, wayfinding; no hero or CTA theater |
12
+ | Experience (portfolio) | is inside the work | artifact owns the first viewport; one transition, no scroll-jacking |
13
+ | Hybrid | per section | classify each section |
14
+
15
+ Instant-fail patterns: generic SaaS card grid as first impression; strong headline with no clear action; busy imagery behind text; carousel with no narrative; app UI made of stacked cards.
16
+
17
+ ## Trunk test (per page)
18
+
19
+ Answer at once: what site, what page, major sections, my options, where am I, how do I search. All six pass; four or five partial; three or fewer is a high finding.
20
+
21
+ ## Ten categories
22
+
23
+ 1. **Hierarchy**: one focal point, one primary CTA per view, squint test, intentional white space, purpose clear in 3 seconds.
24
+ 2. **Typography**: at most 3 families; scale ratio 1.25-1.333; line-height 1.5 body and 1.15-1.25 headings; 45-75 chars per line; no skipped heading levels; at least 2 weights; body at least 16px, labels at least 12px; `text-wrap: balance` on headings; `tabular-nums` on number columns; curly quotes and `…`.
25
+ 3. **Color and contrast**: at most 12 non-gray colors; AA 4.5:1 body, 3:1 large text and UI; no color-only encoding; semantic colors consistent; dark mode uses elevation, off-white text and `color-scheme`.
26
+ 4. **Spacing and layout**: 4 or 8 base scale; consistent grid and alignment; related items closer than sections; radius hierarchy, inner radius = outer minus gap; max content width; URL reflects state.
27
+ 5. **Interaction states**: hover, `focus-visible` ring, active, disabled; skeletons match content; empty states with an action; specific errors with the next step; targets at least 44px; every decision a mindless click.
28
+ 6. **Responsive**: 375, 768, 1024, 1440; mobile is designed, not stacked; no horizontal scroll; no `user-scalable=no`.
29
+ 7. **Motion**: ease-out enter, 50-700ms, purposeful, `prefers-reduced-motion` honored, no `transition: all`, animate transform and opacity only.
30
+ 8. **Content**: specific button labels, no lorem, truncation handled, active voice, destructive actions confirmed or undoable, happy-talk word count reported, instructions longer than a sentence mean the design failed.
31
+ 9. **AI slop**: purple or blue-to-purple gradients; the 3-column icon-circle feature grid; icons in colored circles; everything centered; uniform bubbly radius; blobs and wavy dividers; emoji as design; colored left-border cards; generic hero copy; cookie-cutter section rhythm; system-ui as the display face; gradient buttons; stock hero; testimonial rows with invented quotes; three big vanity numbers; same-shape card grids; frosted glass everywhere; generated SVG mascots; sparklines or avatars as filler; only the happy path designed. Polish-only: bounce easing, pulsing dots, thin border plus wide shadow, numbered section labels, em-dash overuse.
32
+ 10. **Performance as design**: LCP under 2.0s (1.5s informational), CLS under 0.1, image dimensions and lazy loading, `font-display: swap`. Use `lighthouse_audit` and a performance trace for the numbers.
33
+
34
+ ## Reflexes no detector catches
35
+
36
+ Shadows have an offset; a zero-offset colored halo is decoration. Secondary text on a colored surface is tinted, not gray. More space above a heading than below. Light or dark follows the use scene (who, where, under what light), not the category. Labels never live only as placeholders. Visited links differ.
37
+
38
+ ## Scoring
39
+
40
+ Each category starts at A. High impact: minus one letter. Medium: minus half. Polish: no change. Floor F.
41
+
42
+ | Category | Weight |
43
+ |---|---|
44
+ | Hierarchy, Typography, Spacing | 15% each |
45
+ | Color, Interaction, Responsive, Content | 10% each |
46
+ | AI slop, Motion, Performance | 5% each |
47
+
48
+ Report Design Score (weighted) and AI Slop Score (standalone, with a one-line verdict). Regression: load the prior baseline, print per-category deltas, new and resolved findings.
49
+
50
+ ## Goodwill meter
51
+
52
+ Start 70. Drains: hidden info the user wants -15; interstitial or forced tour -15; format punishment -10; unnecessary data request -10; sloppy look -10; ambiguous choice -5. Fills: obvious top task +10. Print one line per step and a final value. Under 30 critical, 30-60 needs work, over 60 healthy.
53
+
54
+ ## Rules
55
+
56
+ Specific and actionable, "change X to Y because Z". Depth over breadth: 5-10 documented findings beat 20 vague ones. Name AI slop directly. Document each finding as found.
@@ -0,0 +1,36 @@
1
+ # Fix loop
2
+
3
+ Runs only after the report is written and the user has not said report-only.
4
+
5
+ ## Preconditions
6
+
7
+ - `git status --porcelain` is empty, on a feature branch. Otherwise ask once: commit, stash or abort, and offer a `brain-worktree` first.
8
+ - Findings triaged: high, then medium, then polish. Mark as deferred what source cannot fix: third-party widgets, copy the team must supply.
9
+
10
+ ## Per finding
11
+
12
+ 1. **Locate.** `search_context` for the concept, `find_symbol` and `find_callers` for the component. Touch only files the finding needs. Prefer CSS, tokens and class changes over structure.
13
+ 2. **Target.** For layout or hierarchy fixes where the intent is not obvious, describe the target in words from the captured system (same colors, fonts, radii) and show it next to the screenshot. Skip for a wrong hex or a missing padding.
14
+ 3. **Fix.** Smallest change that resolves it. No refactor, no unrelated improvement. New code follows `brain-style`: no comments, name things, reuse the existing token or component.
15
+ 4. **Commit.** `git add` the changed files only. One finding per commit, message in the convention `brain-commit` reads from the log, referencing the finding id.
16
+ 5. **Re-test.** Re-render the page, take the after screenshot, compare with the before one. `list_console_messages` must be no worse than baseline.
17
+ 6. **Classify.** verified (re-test confirms, no new errors); best-effort (applied, state could not be reproduced); reverted (regression: `git revert HEAD`, mark deferred).
18
+ 7. **Regression test.** Only for fixes that change JavaScript behavior (dropdowns, conditional rendering, interaction state). CSS-only fixes get none; re-running the review catches them. Add the test beside the existing ones, never edit existing tests or CI config.
19
+
20
+ ## Self-regulation
21
+
22
+ Every 5 fixes, and after any revert, compute the risk:
23
+
24
+ | Event | Risk |
25
+ |---|---|
26
+ | Revert | +15% |
27
+ | Component file touched (tsx, jsx, vue, svelte) | +5% per file |
28
+ | Fix after the 10th | +1% each |
29
+ | Unrelated file touched | +20% |
30
+ | CSS-only file | +0% |
31
+
32
+ Above 20%: stop, show what is done, ask. Hard cap of 30 fixes.
33
+
34
+ ## Closing
35
+
36
+ Re-audit affected pages, recompute both scores. Worse than baseline: say so first. Never push or open the PR; hand over the one-line summary: "Design review found N issues, fixed M. Design score X to Y, AI slop score X to Y."
@@ -0,0 +1,80 @@
1
+ # Rendered-design probes
2
+
3
+ Pass each body as the `function` of chrome-devtools `evaluate_script`. They return JSON-serializable values. Scans cap at 500 elements.
4
+
5
+ ## Fonts, colors, headings
6
+
7
+ ```js
8
+ () => {
9
+ const els = [...document.querySelectorAll("*")].slice(0, 500);
10
+ const cs = els.map((e) => getComputedStyle(e));
11
+ const count = (xs) => Object.entries(xs.reduce((m, x) => ((m[x] = (m[x] || 0) + 1), m), {})).sort((a, b) => b[1] - a[1]);
12
+ return {
13
+ fonts: count(cs.map((s) => s.fontFamily)),
14
+ colors: count(cs.flatMap((s) => [s.color, s.backgroundColor]).filter((c) => c !== "rgba(0, 0, 0, 0)")).slice(0, 30),
15
+ headings: [...document.querySelectorAll("h1,h2,h3,h4,h5,h6")].map((h) => ({
16
+ tag: h.tagName,
17
+ text: h.textContent.trim().slice(0, 50),
18
+ size: getComputedStyle(h).fontSize,
19
+ weight: getComputedStyle(h).fontWeight,
20
+ textWrap: getComputedStyle(h).textWrap,
21
+ })),
22
+ };
23
+ }
24
+ ```
25
+
26
+ Flag more than 3 families, more than 12 non-gray colors, skipped heading levels, non-systematic size jumps.
27
+
28
+ ## Touch targets under 44px
29
+
30
+ ```js
31
+ () => [...document.querySelectorAll("a,button,input,select,textarea,[role=button]")]
32
+ .map((e) => ({ e, r: e.getBoundingClientRect() }))
33
+ .filter(({ r }) => r.width > 0 && (r.width < 44 || r.height < 44))
34
+ .slice(0, 20)
35
+ .map(({ e, r }) => ({ tag: e.tagName, text: (e.textContent || "").trim().slice(0, 30), w: Math.round(r.width), h: Math.round(r.height) }))
36
+ ```
37
+
38
+ ## Spacing values in use
39
+
40
+ ```js
41
+ () => {
42
+ const vals = new Map();
43
+ for (const e of [...document.querySelectorAll("*")].slice(0, 500)) {
44
+ const s = getComputedStyle(e);
45
+ for (const p of ["paddingTop", "paddingLeft", "marginTop", "marginBottom", "rowGap", "columnGap"]) {
46
+ const v = s[p];
47
+ if (v && v !== "0px" && v !== "normal") vals.set(v, (vals.get(v) || 0) + 1);
48
+ }
49
+ }
50
+ return [...vals].sort((a, b) => b[1] - a[1]).slice(0, 25);
51
+ }
52
+ ```
53
+
54
+ Compare against the 4 or 8 scale; list the off-scale values with counts.
55
+
56
+ ## Contrast of text against its background
57
+
58
+ ```js
59
+ () => {
60
+ const lum = ([r, g, b]) => { const f = (c) => { c /= 255; return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; }; return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b); };
61
+ const rgb = (s) => s.match(/\d+(\.\d+)?/g).slice(0, 3).map(Number);
62
+ const bg = (e) => { for (let n = e; n; n = n.parentElement) { const c = getComputedStyle(n).backgroundColor; if (c !== "rgba(0, 0, 0, 0)") return c; } return "rgb(255,255,255)"; };
63
+ return [...document.querySelectorAll("p,span,a,li,label,button,h1,h2,h3,td")]
64
+ .filter((e) => e.childNodes.length && e.textContent.trim())
65
+ .slice(0, 300)
66
+ .map((e) => { const a = lum(rgb(getComputedStyle(e).color)), b = lum(rgb(bg(e))); const r = (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05); return { text: e.textContent.trim().slice(0, 30), ratio: +r.toFixed(2), size: getComputedStyle(e).fontSize }; })
67
+ .filter((x) => x.ratio < 4.5)
68
+ .slice(0, 20);
69
+ }
70
+ ```
71
+
72
+ Background with gradients or images is not resolved; confirm those by eye on the screenshot.
73
+
74
+ ## Other single reads
75
+
76
+ - Reduced motion honored: `() => matchMedia("(prefers-reduced-motion: reduce)").matches` after `emulate` with the media feature.
77
+ - Horizontal scroll: `() => document.documentElement.scrollWidth > innerWidth`.
78
+ - Viewport meta: `() => document.querySelector('meta[name=viewport]')?.content`.
79
+ - Navigation timing: `() => JSON.stringify(performance.getEntriesByType("navigation")[0])`; stringify in the page, entry fields are getters.
80
+ - Page errors: read `list_console_messages` after load, not a hand-installed hook.
@@ -0,0 +1,59 @@
1
+ ---
2
+ name: brain-qa-only
3
+ description: "Trigger: qa report only, just report bugs, test but don't fix, QA this branch, find bugs without fixing, prueba y reporta, reproduce and document. Explores a browser, API, CLI or worker surface and reports reproducible bugs with evidence; never edits product code."
4
+ license: Apache-2.0
5
+ metadata:
6
+ author: jcsoftdev
7
+ version: "1.0"
8
+ generator: project-brain
9
+ ---
10
+
11
+ <!--
12
+ `generator: project-brain` is an ownership marker, not decoration.
13
+ `project-brain setup` overwrites this directory only when it finds that line;
14
+ without it, setup treats the directory as hand-written and leaves it alone.
15
+ Strip it and you pin this copy forever — no upgrade will ever reach it.
16
+ -->
17
+
18
+ ## Activation Contract
19
+
20
+ Use when the ask is to find and document bugs, not to fix them. Design judgment: `brain-design-review`. Every screen of a product and an MVP verdict: `mvp-ui-review`. Recording a demo: `brain-record`.
21
+
22
+ ## Hard Rules
23
+
24
+ - Never edit product code, tests, dependencies or config. No commit, stash, install or push. Writes go only to the report directory and owned fixtures.
25
+ - Browser surfaces are black-box: observe behavior, do not read source to explain it. Source and diff reads only map changes to routes and flows.
26
+ - Write the charters to the report and wait for the write before the first probe: expected result, risk, entrypoint, isolation, exit condition. The plan is not invented afterwards.
27
+ - Reproduce before reporting. A finding without steps, expected versus actual and evidence is a note, not a bug. Rerun a failure once in a clean state before calling it product or environment.
28
+ - Isolated synthetic identity and data. Prod or signed-in sessions: no create, submit, send or delete; never ask for passwords in chat.
29
+ - Browser ladder: `chrome-devtools` first, `claude-in-chrome` only for a session the user asked to reuse. Close the tabs you opened.
30
+ - Never invoke a fixing skill from here. A proposed fix is text in the report.
31
+
32
+ ## Decision Gates
33
+
34
+ | Surface | Method |
35
+ |---------|--------|
36
+ | Browser | `new_page`, `take_snapshot`, interact, `list_console_messages`, `list_network_requests`, `take_screenshot` on every failure |
37
+ | HTTP API | Real requests against a local instance; assert status, body, headers, idempotency, duplicate delivery |
38
+ | CLI / job / worker / webhook | Run the documented command in a `mktemp -d` HOME; capture exit code, stdout, stderr, persisted state |
39
+ | Feature branch, no scope | Diff-aware: changed and adjacent behavior |
40
+ | `--quick` | Smoke on the critical path only |
41
+ | `--regression <report>` | Replay the prior report's steps; classify fixed, still failing, new |
42
+ | Port needed | `port_acquire`, never assume 3000 or 9222 |
43
+
44
+ ## Execution Steps
45
+
46
+ 1. Parse target, mode, output dir (default `.qa-reports/`, git-excluded) and scope; ask once if the target is unknown.
47
+ 2. Gather context: this session's test plan, `TODOS.md`, known failures in engram (`mem_search`); treat them as leads, not proof.
48
+ 3. Create `run-<UTC timestamp>/` and the report file. Write the charters. Check the documented test command and framework; if none, report the gap and propose cases, install nothing.
49
+ 4. Probe each charter. Capture per finding: steps, expected, actual, screenshot or log line, console and network evidence, severity (Blocker, Major, Minor, Polish) and a one-line suspected area.
50
+ 5. Rank the proposed regression tests with the value bar in `references/report.md`; reject duplicates of existing coverage.
51
+ 6. Write the report from `references/report.md`, check it is consistent with the evidence, and finish.
52
+
53
+ ## Output Contract
54
+
55
+ Report: charters, health summary, findings table, per-finding repro, proposed tests with value card, coverage not reached and why, cleanup done. Offer the fix as a separate, user-authorized step. Remove scratch you created and say what you removed.
56
+
57
+ ## References
58
+
59
+ - `references/report.md` — report template, severity scale, test value bar.
@@ -0,0 +1,63 @@
1
+ # QA report
2
+
3
+ Write to `<report dir>/run-<UTC timestamp>/qa-report-<target>-<date>.md`. `<target>` is the hostname, executable basename or service name, with anything but letters, digits and hyphens replaced by hyphens. Never overwrite an earlier run.
4
+
5
+ ## Template
6
+
7
+ ```markdown
8
+ # QA report: <target>
9
+
10
+ Date, branch and revision, mode, scope, who authorized what, timing and stop reason.
11
+
12
+ ## Charters
13
+ One per probe: expected result, risk, entrypoint, isolation, exit condition. Written before probing.
14
+
15
+ ## Summary
16
+ Health in a sentence, counts by severity, the three findings that matter most.
17
+
18
+ ## Findings
19
+ ### QA-001 <title>
20
+ - Severity: Blocker | Major | Minor | Polish
21
+ - Surface and entrypoint
22
+ - Steps to reproduce (numbered, from a clean state)
23
+ - Expected / Actual
24
+ - Evidence: screenshot path, console or network line, command output, exit code
25
+ - Reproduced: N of N runs
26
+ - Suspected area: one line, no fix
27
+
28
+ ## Proposed tests
29
+ Each with a value card.
30
+
31
+ ## Coverage
32
+ Reached, not reached and why, blocked by environment.
33
+
34
+ ## Cleanup
35
+ What was created and removed.
36
+ ```
37
+
38
+ ## Severity
39
+
40
+ | Level | Meaning |
41
+ |---|---|
42
+ | Blocker | core flow cannot complete, data loss, security boundary crossed |
43
+ | Major | core flow degraded, wrong result, no workaround |
44
+ | Minor | wrong but with a workaround, or off the core path |
45
+ | Polish | cosmetic or wording |
46
+
47
+ ## Test value bar
48
+
49
+ Propose a test only when it answers: what it protects, what makes it fail, why existing coverage does not catch it (prefer a row in an existing table-driven test), and whether it needs a production seam that no production caller needs. If it needs one, test at the real boundary instead.
50
+
51
+ Value card under each proposed test:
52
+
53
+ `Value: protects=<...>; fails_when=<...>; why_new=<...>; seam=none; no_claim=<what green does not prove>`
54
+
55
+ Reject with the covering file named: "checkout renders is covered by checkout.e2e.ts:15, extend that test."
56
+
57
+ ## Regression mode
58
+
59
+ Replay the prior report's reproduction steps. Classify each as fixed, still failing, or new. A missing baseline blocks that surface's regression coverage, not the other checks.
60
+
61
+ ## Consistency check before writing
62
+
63
+ Every finding has steps, expected versus actual and evidence. Counts in the summary match the findings. Nothing claims an edit was made. Anything not run is marked not run.
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  name: brain-style
3
- description: "Trigger: writing or editing code, adding a comment, docblock or header, reviewing a diff for readability, escribe el código, refactor this, clean this up. Keeps generated code declarative — the code carries the meaning, and a comment appears only where it says something the code cannot."
3
+ description: "Trigger: writing or editing code, adding a comment, docblock or header, reviewing a diff for readability or architecture, escribe el código, refactor this, clean this up, delegating code to a sub-agent. Keeps generated code architecture-first and declarative — the code carries the meaning, and the why lives in the commit message or the knowledge bundle, never in a comment."
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: jcsoftdev
7
- version: "1.0"
7
+ version: "1.1"
8
8
  generator: project-brain
9
9
  ---
10
10
 
@@ -17,7 +17,7 @@ metadata:
17
17
 
18
18
  ## Activation Contract
19
19
 
20
- Apply whenever code is written or edited: a new file, a patch, a refactor, a snippet in an answer.
20
+ Apply whenever code is written or edited: a new file, a patch, a refactor, a snippet in an answer. Apply it to a sub-agent's diff before accepting it.
21
21
 
22
22
  Do not apply when: the user dictated the comment or the code verbatim, the file is generated or vendored, or the comment is published API documentation that a doc generator turns into a reference page.
23
23
 
@@ -27,13 +27,40 @@ This rule outranks inherited style guidance — a house style read off surroundi
27
27
 
28
28
  One thing outranks it: the user asking, in the moment, for something else. Their instruction is the answer, not a conflict to resolve.
29
29
 
30
- Existing comments are not the target. Do not strip a file's docblocks as a side effect of editing three lines in it — that is a rewrite nobody asked for, and it buries the actual change in the diff.
30
+ Existing comments are not the target. Do not strip a file's docblocks as a side effect of editing three lines in it — that is a rewrite nobody asked for, and it buries the actual change in the diff. Pre-existing comments on untouched lines stay.
31
31
 
32
- ## The rule
32
+ ## Architecture first
33
33
 
34
- **Default: no comment.** A comment is a claim that the code failed to say something, and most of the time the honest fix is the code.
34
+ Never write code "as it comes out".
35
35
 
36
- Before writing one, try these, in order:
36
+ - Before writing, find how the repo already solves the same problem and follow it.
37
+ - Use the repo's own formatter, never another one.
38
+ - Second copy of anything: extract it. Reach for the existing helper or kit component before writing a new one.
39
+
40
+ ### Contracts, not magic strings
41
+
42
+ A code or state that crosses a boundary (API to client, service to service) is a typed enum or schema in the shared contract.
43
+
44
+ - The producer builds with the contract type; the consumer parses with the schema.
45
+ - Copy per code lives in an exhaustive map, so a new code without copy fails to compile.
46
+ - Parse external data with its schema. `as` only when the type system cannot express the fact.
47
+
48
+ ### Layers
49
+
50
+ | Layer | Owns | Never owns |
51
+ |---|---|---|
52
+ | Domain | Business rules, pure and tested | I/O, framework types |
53
+ | Adapter | Persistence | Business rules |
54
+ | Controller | Validate, orchestrate, translate | Business rules |
55
+ | UI component | Rendering | Rules, thresholds, conditional copy |
56
+
57
+ - Container–presentational: a component receives what to show; it does not decide.
58
+ - Mappers, thresholds and conditional copy are pure functions with tests, outside the component.
59
+ - Translate errors in one place per module. The same `catch` repeated per handler is the defect.
60
+
61
+ ## Zero comments
62
+
63
+ A comment is a claim that the code failed to say something, and the honest fix is the code. Add none. Try these, in order:
37
64
 
38
65
  | Instead of a comment | Do this |
39
66
  |---|---|
@@ -43,26 +70,30 @@ Before writing one, try these, in order:
43
70
  | `// this branch handles the empty case` | Make the branch read as the empty case: guard clause, early return |
44
71
  | `// args: name, retries, timeout` | Take a named object, or a type the reader can open |
45
72
  | `// returns null when not found` | Say it in the signature: `T \| null`, `Option<T>`, a typed result |
73
+ | `// must stay sorted, bisect depends on it` | A type or a named function that enforces it |
46
74
 
47
75
  If one of those works, the comment was a naming problem wearing a disguise.
48
76
 
49
- ## What earns a comment
77
+ ### Where the why goes
78
+
79
+ A reason the code cannot hold — a rejected alternative, an external constraint, a vendor quirk, a workaround pinned to a bug or version — does not go in the file.
80
+
81
+ - The commit message carries the why of this change.
82
+ - The knowledge bundle carries the lasting why: a constraint that must keep holding, a trap that already cost a debugging session. Use the `brain-okf` skill.
83
+
84
+ Banners, commented-out code (delete it), changelog lines, attribution, dates and ownerless `TODO`s never belong in the file either.
50
85
 
51
- Three things, all of them the *why* — never the *what*:
86
+ ### Check before every commit
52
87
 
53
- - **A reason the code cannot hold.** A rejected alternative and why it lost, an external constraint, a spec or vendor quirk that makes correct code look wrong.
54
- - **An invariant that breaks non-locally.** "This must stay sorted, `bisect` downstream depends on it." The reader cannot see the downstream from here.
55
- - **A workaround pinned to something external.** Name the bug, version, or ticket, so the next person can tell whether it is still needed.
88
+ ```sh
89
+ git diff --cached | rg '^\+\s*(//|/\*|\*\s|\{/\*)'
90
+ ```
56
91
 
57
- Write those in full sentences. They are for a reader a year out with no memory of this week.
92
+ The output must be empty.
58
93
 
59
- ## What never earns one
94
+ ## Delegating code
60
95
 
61
- - Restating the line below it.
62
- - Section banners (`// ---- helpers ----`) — that is a file asking to be split.
63
- - Commented-out code. Delete it; that is what version control is for.
64
- - Changelog, attribution, or a date. The log holds those, and it stays accurate.
65
- - A `TODO` with no owner and no condition. Either it blocks and belongs in an issue, or it does not and belongs nowhere.
96
+ Restate this whole rule in every sub-agent prompt that writes code, and review its diff against it before accepting. A sub-agent that was not told produces code as it comes out.
66
97
 
67
98
  ## Reporting back
68
99
 
@@ -44,6 +44,24 @@ only the files that actually differ get embedded. It copies nothing when the mai
44
44
  has no index, when the worktree already has one, or when the two would disagree about the
45
45
  embedding model, and a full index in those cases is the correct answer, not a failure.
46
46
 
47
+ ## Dependencies
48
+
49
+ `worktree create` also gives the worktree the main checkout's `node_modules` without a
50
+ second copy on disk: the root one and every workspace package's (from `package.json`
51
+ `workspaces` or `pnpm-workspace.yaml`), each only where that package exists in the worktree
52
+ and has none yet. It clones them copy-on-write (`cp -c -R` on macOS/APFS,
53
+ `cp --reflink=always` on Linux). A clone is independent: changing a dependency inside the
54
+ worktree never touches the main checkout. When the lockfile content hash differs from the
55
+ main checkout's, it clones anyway and then runs the lockfile's package manager install in
56
+ the worktree (`bun`, `pnpm`, `npm` or `yarn install`), which only writes what changed.
57
+ That install runs the package manager's lifecycle scripts (such as `postinstall`) from the
58
+ worktree's `package.json`. If it fails, times out (10 minutes), or the tool is missing,
59
+ every clone is removed, along with any `node_modules` the install created, and `create`
60
+ prints one line saying why; install in the worktree yourself. On macOS the main checkout
61
+ and the worktree must be on the same APFS volume; on HFS+, exFAT, or another volume, and
62
+ whenever the filesystem cannot clone, nothing is copied (never a full copy) and `create`
63
+ prints one line saying why.
64
+
47
65
  ## The one identifier rule
48
66
 
49
67
  `project-brain worktree status --json` returns both spellings. They are not