project-brain 0.23.0 → 0.26.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.
- package/README.md +1 -1
- package/package.json +6 -6
- package/templates/project.claude.md +1 -1
- package/templates/skills/brain-audit/SKILL.md +38 -11
- package/templates/skills/brain-audit/references/abuse.md +36 -11
- package/templates/skills/brain-audit/references/accessibility.md +50 -22
- package/templates/skills/brain-audit/references/ai.md +39 -15
- package/templates/skills/brain-audit/references/analytics.md +34 -11
- package/templates/skills/brain-audit/references/api.md +38 -13
- package/templates/skills/brain-audit/references/backend.md +41 -9
- package/templates/skills/brain-audit/references/browser.md +146 -0
- package/templates/skills/brain-audit/references/complexity.md +22 -12
- package/templates/skills/brain-audit/references/concurrency.md +36 -18
- package/templates/skills/brain-audit/references/consistency.md +32 -9
- package/templates/skills/brain-audit/references/contract-drift.md +34 -16
- package/templates/skills/brain-audit/references/cost.md +45 -23
- package/templates/skills/brain-audit/references/cross-surface-parity.md +38 -11
- package/templates/skills/brain-audit/references/database.md +43 -17
- package/templates/skills/brain-audit/references/dependencies-licensing.md +27 -12
- package/templates/skills/brain-audit/references/design-system.md +40 -17
- package/templates/skills/brain-audit/references/devops.md +32 -17
- package/templates/skills/brain-audit/references/documentation.md +38 -16
- package/templates/skills/brain-audit/references/failure.md +40 -18
- package/templates/skills/brain-audit/references/feature-flags.md +31 -15
- package/templates/skills/brain-audit/references/flow-integrity.md +42 -10
- package/templates/skills/brain-audit/references/frontend.md +40 -12
- package/templates/skills/brain-audit/references/functional.md +31 -11
- package/templates/skills/brain-audit/references/future.md +28 -7
- package/templates/skills/brain-audit/references/goal.md +15 -6
- package/templates/skills/brain-audit/references/i18n.md +30 -8
- package/templates/skills/brain-audit/references/idempotency.md +46 -24
- package/templates/skills/brain-audit/references/infrastructure.md +43 -13
- package/templates/skills/brain-audit/references/mobile.md +37 -15
- package/templates/skills/brain-audit/references/multi-tenancy.md +41 -12
- package/templates/skills/brain-audit/references/numeric.md +33 -16
- package/templates/skills/brain-audit/references/observability.md +43 -19
- package/templates/skills/brain-audit/references/packaging.md +39 -13
- package/templates/skills/brain-audit/references/performance.md +43 -13
- package/templates/skills/brain-audit/references/privacy.md +38 -15
- package/templates/skills/brain-audit/references/product.md +29 -10
- package/templates/skills/brain-audit/references/prompt-spec-gap.md +34 -10
- package/templates/skills/brain-audit/references/reachability.md +38 -18
- package/templates/skills/brain-audit/references/repo-history.md +23 -16
- package/templates/skills/brain-audit/references/runtime.md +121 -0
- package/templates/skills/brain-audit/references/scalability.md +37 -10
- package/templates/skills/brain-audit/references/security.md +46 -22
- package/templates/skills/brain-audit/references/state-model.md +44 -15
- package/templates/skills/brain-audit/references/supply-chain.md +42 -13
- package/templates/skills/brain-audit/references/temporal.md +37 -14
- package/templates/skills/brain-audit/references/testing.md +39 -15
- package/templates/skills/brain-audit/references/tooling-baseline.md +34 -18
- package/templates/skills/brain-audit/references/type-safety.md +38 -19
- package/templates/skills/brain-audit/references/usability.md +78 -0
- package/templates/skills/brain-audit/references/versioning-compatibility.md +34 -12
- package/templates/skills/brain-audit/references/visual-design.md +38 -12
- package/templates/skills/brain-audit/references/web-metadata.md +47 -19
- package/templates/skills/brain-record/SKILL.md +297 -0
- package/templates/skills/brain-record/assets/build-video.sh +142 -0
- package/templates/skills/brain-record/assets/record.mjs +283 -0
- package/templates/skills/brain-record/references/pitfalls.md +233 -0
- package/templates/skills/brain-worktree/SKILL.md +103 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* brain-record's recording engine: capture a driven browser flow by CDP
|
|
4
|
+
* screencast, not by screen capture.
|
|
5
|
+
*
|
|
6
|
+
* WHY SCREENCAST, NOT SCREEN CAPTURE — verified live, not reasoned. The prior
|
|
7
|
+
* engine drove the browser through the Chrome MCP and captured the SCREEN with
|
|
8
|
+
* `ffmpeg -f avfoundation`. That cannot work: the MCP drives a tab that is not
|
|
9
|
+
* frontmost, so the page reports `visibilityState: "hidden"`, `hasFocus: false`,
|
|
10
|
+
* and therefore `outerWidth: 0, outerHeight: 0, screenX: 0, screenY: 0` — a
|
|
11
|
+
* "read the window rect from the page" instruction returns zeros. Worse, screen
|
|
12
|
+
* capture records the FOREGROUND, which is a different tab entirely; capturing
|
|
13
|
+
* one frame of each attached display confirmed the automated page was on
|
|
14
|
+
* neither. Screen capture and a background-tab driver are structurally
|
|
15
|
+
* incompatible. `Page.startScreencast` captures the PAGE over CDP, so
|
|
16
|
+
* foreground and tab visibility stop mattering.
|
|
17
|
+
*
|
|
18
|
+
* node, never bun [measured]. `chromium.connectOverCDP` from Bun hangs at the
|
|
19
|
+
* websocket upgrade and dies at the 30s timeout, while a plain HTTP GET to
|
|
20
|
+
* `/json/version` succeeds instantly from the same process. The identical
|
|
21
|
+
* script under node connects immediately. Always invoke this file with `node`
|
|
22
|
+
* — see SKILL.md for how playwright-core is resolved without becoming a
|
|
23
|
+
* project-brain dependency.
|
|
24
|
+
*
|
|
25
|
+
* Usage: node record.mjs <outdir> <flow.json> [cdpUrl]
|
|
26
|
+
* <outdir> directory to write frames/NNNNN.jpg + stamps.json into
|
|
27
|
+
* <flow.json> { startUrl, viewport?, pageUrlIncludes?, beats: [...] } — see
|
|
28
|
+
* the beat shapes below. Not hardcoded to any one app: every
|
|
29
|
+
* selector, url and value the flow needs comes from this file,
|
|
30
|
+
* written by SKILL.md's phase 1 (derive beats).
|
|
31
|
+
* [cdpUrl] defaults to http://127.0.0.1:9222
|
|
32
|
+
*
|
|
33
|
+
* Beat shapes (each beat prints a `beat: ...` line to stdout as it completes):
|
|
34
|
+
* { "action": "click", "label", "selector", "settleMs"? }
|
|
35
|
+
* Scroll the target to centre, THEN measure its box (see "scroll first,
|
|
36
|
+
* measure second" below), verify the click guard, move the drawn pointer,
|
|
37
|
+
* flash the ripple, and click.
|
|
38
|
+
* { "action": "fill", "label", "selector", "value", "settleMs"? }
|
|
39
|
+
* Same centring, then `<select>.selectOption` falling back to `.fill`.
|
|
40
|
+
* { "action": "centre", "label"?, "selector", "ms"? }
|
|
41
|
+
* Scroll only, no click — e.g. bringing a response panel into frame once
|
|
42
|
+
* the flow's proof has rendered.
|
|
43
|
+
* { "action": "wait", "ms" }
|
|
44
|
+
* A plain pause, e.g. letting an async response arrive before the next beat.
|
|
45
|
+
*/
|
|
46
|
+
import { chromium } from "playwright-core";
|
|
47
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
48
|
+
|
|
49
|
+
const OUT = process.argv[2];
|
|
50
|
+
const FLOW_PATH = process.argv[3];
|
|
51
|
+
const CDP = process.argv[4] ?? "http://127.0.0.1:9222";
|
|
52
|
+
|
|
53
|
+
if (!OUT || !FLOW_PATH) {
|
|
54
|
+
console.error("usage: node record.mjs <outdir> <flow.json> [cdpUrl]");
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const flow = JSON.parse(await readFile(FLOW_PATH, "utf8"));
|
|
59
|
+
const { startUrl, viewport = { width: 1280, height: 800 }, pageUrlIncludes, beats = [] } = flow;
|
|
60
|
+
if (!startUrl) {
|
|
61
|
+
console.error(`${FLOW_PATH}: "startUrl" is required`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const POINTER = `(() => {
|
|
66
|
+
if (window.__brp) return;
|
|
67
|
+
// project-brain palette (landing/src/styles/global.css). --sea, the
|
|
68
|
+
// STRUCTURAL accent, not --terra: terra is #e87a52, near enough to Claude's
|
|
69
|
+
// own terracotta that a viewer reads the pointer as Claude's rather than as
|
|
70
|
+
// this product's. The ring is --bg (near-black) instead of --fg, because most
|
|
71
|
+
// app UIs under recording are light and a white ring vanishes on them.
|
|
72
|
+
const SEA = '#5fbfae';
|
|
73
|
+
const SEA_LO = 'rgba(95, 191, 174, 0.16)';
|
|
74
|
+
const INK = '#17121d';
|
|
75
|
+
const dot = document.createElement('div');
|
|
76
|
+
dot.id = '__brain-record-pointer';
|
|
77
|
+
Object.assign(dot.style, {
|
|
78
|
+
position:'fixed', width:'18px', height:'18px', borderRadius:'50%',
|
|
79
|
+
background:SEA, border:'2px solid ' + INK,
|
|
80
|
+
boxShadow:'0 0 0 2px rgba(243,236,230,0.85), 0 2px 10px rgba(23,18,29,0.5)',
|
|
81
|
+
pointerEvents:'none', zIndex:2147483647,
|
|
82
|
+
left:'0px', top:'0px', marginLeft:'-9px', marginTop:'-9px',
|
|
83
|
+
});
|
|
84
|
+
document.documentElement.appendChild(dot);
|
|
85
|
+
const kf = document.createElement('style');
|
|
86
|
+
kf.textContent = '@keyframes brPing{from{transform:scale(1);opacity:1}to{transform:scale(2.8);opacity:0}}';
|
|
87
|
+
document.head.appendChild(kf);
|
|
88
|
+
|
|
89
|
+
const ease = t => t * t * (3 - 2 * t);
|
|
90
|
+
const frame = () => new Promise(r => requestAnimationFrame(r));
|
|
91
|
+
|
|
92
|
+
window.__brp = {
|
|
93
|
+
async moveTo(x, y, ms = 320) {
|
|
94
|
+
const x0 = parseFloat(dot.style.left) || 0, y0 = parseFloat(dot.style.top) || 0;
|
|
95
|
+
const t0 = performance.now();
|
|
96
|
+
for (;;) {
|
|
97
|
+
const t = Math.min((performance.now() - t0) / ms, 1), e = ease(t);
|
|
98
|
+
dot.style.left = (x0 + (x - x0) * e) + 'px';
|
|
99
|
+
dot.style.top = (y0 + (y - y0) * e) + 'px';
|
|
100
|
+
if (t >= 1) break;
|
|
101
|
+
await frame();
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
// Eased, frame-by-frame scroll. scrollIntoView({behavior:'smooth'}) is not
|
|
105
|
+
// used: its duration is browser-chosen and untunable, and a screencast
|
|
106
|
+
// records exactly what the page paints, so a jump-cut scroll is a jump-cut
|
|
107
|
+
// in the deliverable. Driving it per rAF keeps the pointer glued to its
|
|
108
|
+
// target while the page moves under it.
|
|
109
|
+
async scrollToY(targetY, ms = 700) {
|
|
110
|
+
const max = document.documentElement.scrollHeight - window.innerHeight;
|
|
111
|
+
const to = Math.max(0, Math.min(targetY, max));
|
|
112
|
+
const from = window.scrollY;
|
|
113
|
+
if (Math.abs(to - from) < 2) return;
|
|
114
|
+
const t0 = performance.now();
|
|
115
|
+
for (;;) {
|
|
116
|
+
const t = Math.min((performance.now() - t0) / ms, 1);
|
|
117
|
+
window.scrollTo(0, from + (to - from) * ease(t));
|
|
118
|
+
if (t >= 1) break;
|
|
119
|
+
await frame();
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
async centre(sel, ms = 700) {
|
|
123
|
+
const el = document.querySelector(sel);
|
|
124
|
+
if (!el) return;
|
|
125
|
+
const r = el.getBoundingClientRect();
|
|
126
|
+
await this.scrollToY(window.scrollY + r.top - (window.innerHeight - r.height) / 2, ms);
|
|
127
|
+
},
|
|
128
|
+
click() {
|
|
129
|
+
const r = document.createElement('div');
|
|
130
|
+
Object.assign(r.style, {
|
|
131
|
+
position:'fixed', left:dot.style.left, top:dot.style.top,
|
|
132
|
+
width:'18px', height:'18px', marginLeft:'-9px', marginTop:'-9px',
|
|
133
|
+
borderRadius:'50%', border:'2px solid ' + SEA, background:SEA_LO,
|
|
134
|
+
pointerEvents:'none', zIndex:2147483647, animation:'brPing 560ms ease-out',
|
|
135
|
+
});
|
|
136
|
+
document.documentElement.appendChild(r);
|
|
137
|
+
setTimeout(() => r.remove(), 560);
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
})()`;
|
|
141
|
+
|
|
142
|
+
const browser = await chromium.connectOverCDP(CDP);
|
|
143
|
+
const ctx = browser.contexts()[0];
|
|
144
|
+
const page = pageUrlIncludes
|
|
145
|
+
? (ctx.pages().find((p) => p.url().includes(pageUrlIncludes)) ?? ctx.pages()[0])
|
|
146
|
+
: ctx.pages()[0];
|
|
147
|
+
await page.setViewportSize(viewport).catch(() => {});
|
|
148
|
+
await page.goto(startUrl, { waitUntil: "networkidle" });
|
|
149
|
+
|
|
150
|
+
await mkdir(`${OUT}/frames`, { recursive: true });
|
|
151
|
+
const session = await ctx.newCDPSession(page);
|
|
152
|
+
|
|
153
|
+
let n = 0;
|
|
154
|
+
const stamps = [];
|
|
155
|
+
session.on("Page.screencastFrame", async (f) => {
|
|
156
|
+
const i = ++n;
|
|
157
|
+
stamps.push(f.metadata.timestamp);
|
|
158
|
+
await writeFile(`${OUT}/frames/${String(i).padStart(5, "0")}.jpg`, Buffer.from(f.data, "base64"));
|
|
159
|
+
await session.send("Page.screencastFrameAck", { sessionId: f.sessionId }).catch(() => {});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
await page.addInitScript(POINTER);
|
|
163
|
+
await page.evaluate(POINTER);
|
|
164
|
+
|
|
165
|
+
// Consent overlays are removed GENERICALLY, never by vendor selector. Two runs
|
|
166
|
+
// against the SAME url served two different consent libraries (OneTrust, then
|
|
167
|
+
// ch2), so a hardcoded list is a coin flip. What they share is the shape: a
|
|
168
|
+
// fixed/sticky element with a large z-index covering most of the viewport,
|
|
169
|
+
// which swallows coordinate clicks while locator.click() would still report
|
|
170
|
+
// success.
|
|
171
|
+
//
|
|
172
|
+
// REMOVED, never ACCEPTED. Clicking "allow all" on someone's behalf is consent
|
|
173
|
+
// this script has no standing to give, and it would also be recorded as if the
|
|
174
|
+
// user had agreed. Re-run after every scroll — an overlay that reappears (or a
|
|
175
|
+
// new one a later step triggers) must not survive into the next beat.
|
|
176
|
+
const clearOverlays = async () => page.evaluate(() => {
|
|
177
|
+
const vw = innerWidth, vh = innerHeight, killed = [];
|
|
178
|
+
for (const el of document.querySelectorAll('body *')) {
|
|
179
|
+
const cs = getComputedStyle(el);
|
|
180
|
+
if (cs.position !== 'fixed' && cs.position !== 'sticky') continue;
|
|
181
|
+
if (cs.visibility === 'hidden' || cs.display === 'none') continue;
|
|
182
|
+
const z = parseInt(cs.zIndex, 10);
|
|
183
|
+
if (!(z > 1000)) continue;
|
|
184
|
+
const r = el.getBoundingClientRect();
|
|
185
|
+
if (r.width * r.height < vw * vh * 0.25) continue;
|
|
186
|
+
if (el.id === '__brain-record-pointer' || el.contains(document.querySelector('#__brain-record-pointer'))) continue;
|
|
187
|
+
killed.push((el.id || el.className || el.tagName).toString().slice(0, 40));
|
|
188
|
+
el.remove();
|
|
189
|
+
}
|
|
190
|
+
return killed;
|
|
191
|
+
});
|
|
192
|
+
console.log("overlays removed:", JSON.stringify(await clearOverlays()));
|
|
193
|
+
|
|
194
|
+
await session.send("Page.startScreencast", {
|
|
195
|
+
format: "jpeg", quality: 90, everyNthFrame: 1, maxWidth: viewport.width, maxHeight: viewport.height,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const beat = async (label, sel, settleMs = 900) => {
|
|
199
|
+
// Scroll first and eased, THEN measure. The box moves while the page scrolls,
|
|
200
|
+
// so a rect taken before the scroll points at empty space when the click
|
|
201
|
+
// lands. This broke two runs of the flow this engine was ported from.
|
|
202
|
+
await page.evaluate(([s]) => window.__brp.centre(s), [sel]);
|
|
203
|
+
await page.waitForTimeout(220);
|
|
204
|
+
const el = page.locator(sel).first();
|
|
205
|
+
const box = await el.boundingBox();
|
|
206
|
+
if (!box) throw new Error(`no box for ${label} (${sel})`);
|
|
207
|
+
const x = Math.round(box.x + box.width / 2), y = Math.round(box.y + box.height / 2);
|
|
208
|
+
await clearOverlays();
|
|
209
|
+
// Every click is guarded by elementFromPoint resolving to the target or an
|
|
210
|
+
// ancestor/descendant of it. Without this a coordinate click can silently
|
|
211
|
+
// hit a curtain (a leftover overlay, a tooltip, anything) while
|
|
212
|
+
// `locator.click()` would still report success.
|
|
213
|
+
const onTop = await page.evaluate(([x, y, sel]) => {
|
|
214
|
+
const e = document.elementFromPoint(x, y);
|
|
215
|
+
const want = document.querySelector(sel);
|
|
216
|
+
return { cls: e ? (e.className || e.tagName) + '' : 'none',
|
|
217
|
+
ok: !!(e && want && (want === e || want.contains(e) || e.contains(want))) };
|
|
218
|
+
}, [x, y, sel]);
|
|
219
|
+
if (!onTop.ok) throw new Error(`${label}: "${onTop.cls}" is on top at ${x},${y} — a click here would hit that, not the target`);
|
|
220
|
+
await page.evaluate(([x, y]) => window.__brp.moveTo(x, y), [x, y]);
|
|
221
|
+
await page.evaluate(() => window.__brp.click());
|
|
222
|
+
await page.mouse.click(x, y);
|
|
223
|
+
await page.waitForTimeout(settleMs);
|
|
224
|
+
console.log(`beat: ${label} @ ${x},${y} topmost=${onTop.cls}`);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const fill = async (label, sel, value, settleMs = 700) => {
|
|
228
|
+
await page.evaluate(([s]) => window.__brp.centre(s), [sel]);
|
|
229
|
+
await page.waitForTimeout(220);
|
|
230
|
+
await clearOverlays();
|
|
231
|
+
const el = page.locator(sel).first();
|
|
232
|
+
const box = await el.boundingBox();
|
|
233
|
+
if (box) {
|
|
234
|
+
await page.evaluate(([x, y]) => window.__brp.moveTo(x, y),
|
|
235
|
+
[Math.round(box.x + box.width / 2), Math.round(box.y + box.height / 2)]);
|
|
236
|
+
}
|
|
237
|
+
await el.selectOption(value).catch(async () => { await el.fill(value); });
|
|
238
|
+
await page.waitForTimeout(settleMs);
|
|
239
|
+
console.log(`beat: ${label}`);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const centre = async (label, sel, ms = 700) => {
|
|
243
|
+
await page.evaluate(([s, ms]) => window.__brp.centre(s, ms), [sel, ms]);
|
|
244
|
+
await page.waitForTimeout(220);
|
|
245
|
+
await clearOverlays();
|
|
246
|
+
console.log(`beat: ${label ?? `centre ${sel}`}`);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const wait = async (ms) => {
|
|
250
|
+
await page.waitForTimeout(ms);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
await page.waitForTimeout(600);
|
|
254
|
+
|
|
255
|
+
for (const b of beats) {
|
|
256
|
+
switch (b.action) {
|
|
257
|
+
case "click":
|
|
258
|
+
await beat(b.label, b.selector, b.settleMs);
|
|
259
|
+
break;
|
|
260
|
+
case "fill":
|
|
261
|
+
await fill(b.label, b.selector, b.value, b.settleMs);
|
|
262
|
+
break;
|
|
263
|
+
case "centre":
|
|
264
|
+
await centre(b.label, b.selector, b.ms);
|
|
265
|
+
break;
|
|
266
|
+
case "wait":
|
|
267
|
+
await wait(b.ms);
|
|
268
|
+
break;
|
|
269
|
+
default:
|
|
270
|
+
throw new Error(`${FLOW_PATH}: unknown beat action "${b.action}"`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
await session.send("Page.stopScreencast");
|
|
275
|
+
await browser.close();
|
|
276
|
+
|
|
277
|
+
// The screencast is VARIABLE-rate: it only emits a frame when the page
|
|
278
|
+
// actually repaints, so idle time produces none. stamps.json is what lets
|
|
279
|
+
// assets/build-video.sh reconstruct real elapsed time between frames — never
|
|
280
|
+
// encode this sequence at a fixed input rate.
|
|
281
|
+
const first = stamps[0] ?? 0;
|
|
282
|
+
await writeFile(`${OUT}/stamps.json`, JSON.stringify(stamps.map((t) => t - first)));
|
|
283
|
+
console.log(`frames=${n} span=${(((stamps.at(-1) ?? first)) - first).toFixed(2)}s`);
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Traps, with the numbers that produced them
|
|
2
|
+
|
|
3
|
+
Every screen-capture pitfall from the previous engine (`CGWindowListCopyWindowInfo`,
|
|
4
|
+
avfoundation device matching, HiDPI logical-vs-physical pixel math, browser-chrome crop,
|
|
5
|
+
foreign-window frame filtering) is gone from this file. Not trimmed for length — gone
|
|
6
|
+
because the mechanism that produced every one of them is gone: this engine captures the
|
|
7
|
+
PAGE over CDP (`Page.startScreencast`), and a page screencast cannot contain a frame of
|
|
8
|
+
another window, cannot be affected by which display the browser is on, and has no OS
|
|
9
|
+
window chrome in it to crop. Each item below is labelled measured or derived; several
|
|
10
|
+
were reproduced directly while building this rewrite, on this machine, and say so.
|
|
11
|
+
|
|
12
|
+
## Screen capture and a background-tab driver are structurally incompatible [measured]
|
|
13
|
+
|
|
14
|
+
The finding that forced this rewrite. The Chrome MCP drives a tab that is NOT
|
|
15
|
+
frontmost — verified live: the page reported `visibilityState: "hidden"`, `hasFocus:
|
|
16
|
+
false`, and therefore `window.screenX/screenY/outerWidth/outerHeight` were all `0`. An
|
|
17
|
+
engine whose central instruction was "read the window rect from the page" got zeros, and
|
|
18
|
+
a 0×0 crop is not a recoverable degraded case. Separately, screen capture records the
|
|
19
|
+
FOREGROUND — capturing one frame of each attached display confirmed the automated page
|
|
20
|
+
was on neither. `Page.startScreencast` captures the page itself, so neither fact matters
|
|
21
|
+
any more.
|
|
22
|
+
|
|
23
|
+
## node, never bun [measured]
|
|
24
|
+
|
|
25
|
+
`chromium.connectOverCDP` from Bun hangs at the websocket upgrade and dies at the 30s
|
|
26
|
+
timeout. A plain HTTP GET to `/json/version` from the same Bun process succeeds
|
|
27
|
+
instantly — so the failure is specific to Bun's websocket client during the CDP
|
|
28
|
+
handshake, not to reaching the port at all. The identical script under `node` connects
|
|
29
|
+
immediately. Always invoke `assets/record.mjs` with `node`.
|
|
30
|
+
|
|
31
|
+
## `NODE_PATH` and `npx --package` do NOT make `playwright-core` resolve [measured]
|
|
32
|
+
|
|
33
|
+
Reproduced directly while building this rewrite, on Node 26.7.0. Both of these fail with
|
|
34
|
+
`ERR_MODULE_NOT_FOUND: Cannot find package 'playwright-core' imported from
|
|
35
|
+
.../record.mjs`:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
NODE_PATH=$SCRATCH/node_modules node assets/record.mjs ...
|
|
39
|
+
npx --package=playwright-core -- node assets/record.mjs ...
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The reason: Node's ESM resolver walks up `node_modules` directories starting from the
|
|
43
|
+
importING file's own path — `NODE_PATH` is a legacy mechanism the ESM loader does not
|
|
44
|
+
consult at all, and `npx --package` puts the installed package on `PATH`/makes its bins
|
|
45
|
+
runnable, but does not change where `record.mjs`'s own `import` statement looks. The fix
|
|
46
|
+
that was verified to work: copy (or symlink) `record.mjs` INTO the directory that owns
|
|
47
|
+
`node_modules/playwright-core` before running it —
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
cp assets/record.mjs "$SCRATCH/record.mjs"
|
|
51
|
+
node "$SCRATCH/record.mjs" <outdir> <flow.json> <cdpUrl>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
— so Node's own upward walk from the script's location finds it. Do not "simplify" this
|
|
55
|
+
back to `NODE_PATH` or a bare `npx` invocation; both were tried first and both fail.
|
|
56
|
+
|
|
57
|
+
## The screencast is variable-rate — idle time produces zero frames [measured]
|
|
58
|
+
|
|
59
|
+
Reproduced on a real smoke-test flow (a local static page, two beats: a click and a
|
|
60
|
+
select-fill). `stamps.json` came back as 117 entries; the run of consecutive deltas
|
|
61
|
+
included one gap of `1.5517 - 1.2906 ≈ 0.261s` with no frame in between — a stretch where
|
|
62
|
+
the page was not repainting (a settle wait between beats). `Page.startScreencast` only
|
|
63
|
+
emits a frame when the page's compositor actually produces one; it is not a fixed-rate
|
|
64
|
+
tap. `assets/build-video.sh` exists specifically to turn this variable-rate sequence,
|
|
65
|
+
via `stamps.json`, into a normal constant-rate file — never encode the raw frame sequence
|
|
66
|
+
at a flat input `-framerate`, which would play back faster than real time across any gap
|
|
67
|
+
like the one above.
|
|
68
|
+
|
|
69
|
+
## Fresh-Chrome launch is not instant, but it is fast [measured]
|
|
70
|
+
|
|
71
|
+
Timed directly: `chrome --headless=new --remote-debugging-port=<n>
|
|
72
|
+
--user-data-dir=<fresh tmp dir>` took **0.73s** on this machine before `/json/version`
|
|
73
|
+
answered. Poll for it (`until curl -s ... ; do sleep 0.05; done`) rather than sleeping a
|
|
74
|
+
fixed guess — the old engine's ~2.7s avfoundation-probe number no longer applies at all
|
|
75
|
+
(there is nothing to probe: no device enumeration, no multi-display matching), but a
|
|
76
|
+
single measurement on one machine is not a promise for every machine either.
|
|
77
|
+
|
|
78
|
+
## Consent overlays: sweep generically, verified working [measured]
|
|
79
|
+
|
|
80
|
+
Reproduced on the same smoke-test flow: a synthetic full-viewport `position: fixed;
|
|
81
|
+
z-index: 99999` banner covering 75% of the viewport was swept before the screencast
|
|
82
|
+
started, logged as `overlays removed: ["banner"]`, and the driven click subsequently
|
|
83
|
+
landed on the real target underneath. The sweep's shape — `position: fixed|sticky`,
|
|
84
|
+
`z-index > 1000`, more than 25% of viewport area, excluding the pointer overlay itself —
|
|
85
|
+
is deliberately vendor-agnostic: two runs against the same URL, on the engine this was
|
|
86
|
+
ported from, served two different consent libraries (OneTrust, then a second one) on
|
|
87
|
+
separate occasions. A hardcoded selector list would have been a coin flip both times.
|
|
88
|
+
REMOVE, never ACCEPT — clicking "allow all" on someone's behalf is consent this tool has
|
|
89
|
+
no standing to give, and it would be recorded as if the user had agreed. Re-run after
|
|
90
|
+
every scroll: an overlay a later step triggers, or one that reappears, must not survive
|
|
91
|
+
into the next beat.
|
|
92
|
+
|
|
93
|
+
## Scroll first, measure second [derived from the ported engine's own history]
|
|
94
|
+
|
|
95
|
+
The bounding box a beat clicks moves while the page scrolls to bring it into view, so a
|
|
96
|
+
rect taken BEFORE the scroll points at empty space by the time the click lands. This cost
|
|
97
|
+
two runs to find in the engine `record.mjs` was ported from. `beat()`/`fill()` always
|
|
98
|
+
call `window.__brp.centre(sel)` and wait for it to settle before calling
|
|
99
|
+
`el.boundingBox()` — never reorder this.
|
|
100
|
+
|
|
101
|
+
## Every click is guarded, and the guard has already caught a real defect [derived]
|
|
102
|
+
|
|
103
|
+
`document.elementFromPoint(x, y)` must resolve to the click target or an ancestor/
|
|
104
|
+
descendant of it, or `record.mjs` throws naming whatever WAS on top. Without this guard a
|
|
105
|
+
coordinate click can silently hit a leftover overlay while `locator.click()` would still
|
|
106
|
+
report success — the take would show a click that visibly did nothing, with no error
|
|
107
|
+
anywhere. In the engine this was ported from, the guard caught exactly this class of bug
|
|
108
|
+
once already: a Swagger `opblock`'s clickable header is the `.opblock-summary-control`,
|
|
109
|
+
not the whole `opblock` box, whose centre falls below the header once it expands.
|
|
110
|
+
|
|
111
|
+
## Pointer colour is `--sea`, not `--terra` — and it renders correctly [measured]
|
|
112
|
+
|
|
113
|
+
Verified visually on the smoke-test recording: the drawn pointer is a filled teal circle
|
|
114
|
+
(`#5fbfae`, `--sea` from `landing/src/styles/global.css`) with a dark ring (`--bg`,
|
|
115
|
+
`#17121d`). `--terra` (`#e87a52`) is deliberately never used — it is close enough to
|
|
116
|
+
Claude's own terracotta that a viewer reads the pointer as Claude's rather than as this
|
|
117
|
+
product's.
|
|
118
|
+
|
|
119
|
+
## Fluidity costs bitrate — a trade, not a regression [measured, from the ported engine]
|
|
120
|
+
|
|
121
|
+
Measured on the same flow: 199 frames / 226,017 bytes with jump-cut scrolling versus 609
|
|
122
|
+
frames / 1,509,635 bytes with eased scrolling. `record.mjs`'s `scrollToY`/`centre` drive
|
|
123
|
+
the scroll per `requestAnimationFrame` step rather than `scrollIntoView({behavior:
|
|
124
|
+
"smooth"})` (whose duration is browser-chosen and untunable) specifically because a
|
|
125
|
+
screencast records exactly what the page paints — a jump-cut scroll is a jump-cut in the
|
|
126
|
+
deliverable. State the size difference as the cost of legibility, not as something to
|
|
127
|
+
optimise away.
|
|
128
|
+
|
|
129
|
+
## ffmpeg's concat demuxer drops the last frame's duration [measured]
|
|
130
|
+
|
|
131
|
+
Reproduced twice while building `assets/build-video.sh`: on a 5-frame synthetic take, the
|
|
132
|
+
sum of `stamps.json` deltas was 1.4s but the encoded file's `ffprobe`-reported duration
|
|
133
|
+
came back 1.867s; on the 117-frame smoke-test take, the span from `record.mjs` was 2.89s
|
|
134
|
+
against an encoded duration of 2.967s. Both times the file was still fully correct —
|
|
135
|
+
every frame present, in order, at the right relative pacing — just longer by roughly the
|
|
136
|
+
final frame's own duration. This is ffmpeg's documented concat-demuxer behaviour: a
|
|
137
|
+
`duration` line applies to the file ABOVE it, so the very last file's duration is
|
|
138
|
+
otherwise silently dropped unless that file is listed a second time with no duration
|
|
139
|
+
after it. `assets/build-video.sh`'s generator already does this (see its
|
|
140
|
+
`gen-concat.mjs` heredoc) — the small overshoot is the accepted cost of the last frame
|
|
141
|
+
actually appearing at all, not a bug to chase further.
|
|
142
|
+
|
|
143
|
+
## The output format is H.264 MP4, and a GIF is never shipped [measured, from the ported engine]
|
|
144
|
+
|
|
145
|
+
A GIF cannot carry a screen recording at quality. 256 colours per frame and no real
|
|
146
|
+
interframe prediction means it either bands visibly on gradients and antialiased text or
|
|
147
|
+
balloons in size, and it has to drop framerate and resolution just to stay embeddable.
|
|
148
|
+
Measured on one 191-frame take of a 1200x800 window:
|
|
149
|
+
|
|
150
|
+
| output | frames | dimensions | colour | size |
|
|
151
|
+
|---|---|---|---|---|
|
|
152
|
+
| GIF, 12fps, palettegen `stats_mode=diff` | 92 | 900x526 | 256 | 260K |
|
|
153
|
+
| H.264 MP4, 30fps, crf 18 | 191 | 1200x700 | full | 149K |
|
|
154
|
+
|
|
155
|
+
Better on every axis and 43% smaller. That is why there is no GIF output.
|
|
156
|
+
|
|
157
|
+
## H.264 over AV1, H.265 and VP9 — measured at matched quality [measured, from the ported engine]
|
|
158
|
+
|
|
159
|
+
Quality matched with ffmpeg's `libvmaf` against a lossless FFV1 reference built from the
|
|
160
|
+
same frames, so these are sizes at equal quality rather than sizes at equal CRF:
|
|
161
|
+
|
|
162
|
+
| codec | static take (VMAF ~97) | motion take (VMAF ~90) |
|
|
163
|
+
|---|---|---|
|
|
164
|
+
| H.264 | 149,067 B | 206,889 B |
|
|
165
|
+
| H.265 | 150,000 B | 179,425 B |
|
|
166
|
+
| AV1 (SVT, `scm=1`) | 286,450 B | 290,857 B |
|
|
167
|
+
| VP9 | 283,369 B | 270,715 B |
|
|
168
|
+
|
|
169
|
+
AV1 and VP9 lose on both, by roughly 2x, which inverts the usual expectation. These takes
|
|
170
|
+
are SHORT — seconds, not minutes — so the long-GOP efficiency those codecs are known for
|
|
171
|
+
never gets paid back against their container and keyframe overhead. Do not generalise
|
|
172
|
+
this to long video; it is a finding about short screen-recording takes.
|
|
173
|
+
|
|
174
|
+
H.265 wins the motion case by ~13% and is still not used: Chrome and Firefox will not
|
|
175
|
+
reliably decode HEVC in MP4, and this file exists to be opened by a reviewer who is not
|
|
176
|
+
you. Universal playback beats 13%. This table did not change with the rewrite — the
|
|
177
|
+
encode step in `assets/build-video.sh` is the same `libx264 -preset slow -crf 18`
|
|
178
|
+
invocation it always was, just fed by a concat file instead of a raw window-cropped
|
|
179
|
+
sequence.
|
|
180
|
+
|
|
181
|
+
## The "live" connection mode's cost is real, and is Chrome's own words [given, not independently re-verified visually]
|
|
182
|
+
|
|
183
|
+
Confirmed present in Chrome 152 (the version this engine's smoke test ran against, via
|
|
184
|
+
`/json/version`): `chrome://inspect/#remote-debugging`'s "Allow remote debugging for this
|
|
185
|
+
browser instance" toggle. Its own warning, to be shown to the user before this mode is
|
|
186
|
+
used, not paraphrased: it "allows external apps to request full control of this browser.
|
|
187
|
+
This includes read access to your saved data, cookies and site data, and the ability to
|
|
188
|
+
navigate to any URL." This skill never flips that toggle itself — only the user, in their
|
|
189
|
+
own already-running Chrome, and it is their choice to turn it back off afterward.
|
|
190
|
+
|
|
191
|
+
## `$var[x]` is an array subscript in zsh, not string concatenation
|
|
192
|
+
|
|
193
|
+
`assets/build-video.sh` is `#!/bin/zsh`. Building a shell string the bash way can
|
|
194
|
+
silently destroy it:
|
|
195
|
+
|
|
196
|
+
F="crop=1:2,fps=12"
|
|
197
|
+
echo "$F[x]" -> (empty)
|
|
198
|
+
echo "${F}[x]" -> crop=1:2,fps=12[x]
|
|
199
|
+
|
|
200
|
+
Nothing in the current script triggers this — there is no ffmpeg filtergraph labelling
|
|
201
|
+
(`[out]`-style) left now that there is no crop step — but it remains a standing footgun
|
|
202
|
+
for anyone editing these zsh assets. Always brace a variable that is followed by `[`.
|
|
203
|
+
|
|
204
|
+
## Housekeeping
|
|
205
|
+
|
|
206
|
+
A take's raw frames are tens of megabytes of JPEGs even for a short flow (117 frames at
|
|
207
|
+
1280x800 in the smoke test that verified this engine). Delete `frames/` and
|
|
208
|
+
`stamps.json` once `build-video.sh` has produced the final MP4. There is no `clean/`
|
|
209
|
+
directory any more — that existed only for the old engine's foreign-window filtering
|
|
210
|
+
step, which has no equivalent here: a page screencast cannot contain a frame of another
|
|
211
|
+
window, so there is nothing to filter.
|
|
212
|
+
|
|
213
|
+
## The light path's GIF recorder is a slideshow, by design [measured, carried over]
|
|
214
|
+
|
|
215
|
+
Carried from `branch-demo`, which this skill absorbed. `gif_creator` captures one frame
|
|
216
|
+
per `computer` action — discrete screenshots. It cannot show motion at all, which is why
|
|
217
|
+
the Decision Gates send anything with a scroll, a transition or a drag to `record.mjs`
|
|
218
|
+
instead.
|
|
219
|
+
|
|
220
|
+
It also caps at **50 frames, silently**: a take that reaches the cap stops capturing
|
|
221
|
+
while your calls keep succeeding, so the tail looks fine in the tool results and is
|
|
222
|
+
simply missing from the file. Check the last frame before believing the ending shipped:
|
|
223
|
+
|
|
224
|
+
magick out.gif'[N]' last.png
|
|
225
|
+
|
|
226
|
+
`form_input` does NOT create a frame; `computer` actions do. That is useful rather than
|
|
227
|
+
annoying — fill fields with `form_input` and spend the frame budget only on the states
|
|
228
|
+
worth showing.
|
|
229
|
+
|
|
230
|
+
Turn the orange overlays off: `showClickIndicators`, `showProgressBar`, `showWatermark`,
|
|
231
|
+
`showActionLabels`. They read as decoration on a document meant for reviewers, and the
|
|
232
|
+
full path draws its own pointer in the product's own `--sea` instead.
|
|
233
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: brain-worktree
|
|
3
|
+
description: "Trigger: before starting an isolated task, run this in a worktree, parallel agents, e2e in a worktree, worktree ports, aísla esta tarea, puertos por worktree. Decides whether work belongs in a git worktree, then gives that worktree its own brain and its own port so an agent can run end-to-end checks without colliding with any sibling."
|
|
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
|
+
Apply before delegating a task that will change code AND be checked by running the app:
|
|
21
|
+
an end-to-end pass, a browser walkthrough, a recorded demo, anything that needs a server
|
|
22
|
+
listening on a port.
|
|
23
|
+
|
|
24
|
+
Do not apply to read-only questions, to work that never boots the app, or when the
|
|
25
|
+
session is already inside a worktree that `worktree status` reports as indexed.
|
|
26
|
+
|
|
27
|
+
## Why a worktree needs its own brain
|
|
28
|
+
|
|
29
|
+
project-brain resolves a project by walking UP from the current directory to the nearest
|
|
30
|
+
`.project-brain/`. Worktrees are created *inside* the main checkout, so an uninitialized
|
|
31
|
+
worktree used to resolve to the main checkout and answer every structural query from
|
|
32
|
+
main's graph while the caller sat on a different branch. Wrong answers, no warning.
|
|
33
|
+
|
|
34
|
+
Two guards close that now: the upward walk stops at a linked worktree's own toplevel, and
|
|
35
|
+
the MCP server refuses to boot in an uninitialized worktree instead of minting an empty
|
|
36
|
+
graph there. Both turn a silent lie into a message that names the fix. Your job is to run
|
|
37
|
+
the fix before the agent hits it.
|
|
38
|
+
|
|
39
|
+
## The one identifier rule
|
|
40
|
+
|
|
41
|
+
`project-brain worktree status --json` returns both spellings. They are not
|
|
42
|
+
interchangeable:
|
|
43
|
+
|
|
44
|
+
| Field | Goes to | Note |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `project` + `worktree` | `port_acquire`, `port_release` | lowercased; the pair mcp-port-registry leases on |
|
|
47
|
+
| `projectId` | every project-brain MCP tool | project-brain's own casing, suffixed `@<worktree>` |
|
|
48
|
+
|
|
49
|
+
Pass `projectId` where `project` belongs and the port registry leases a port for a
|
|
50
|
+
worktree nobody indexed. The two halves drift apart and nothing errors.
|
|
51
|
+
|
|
52
|
+
## Execution Steps
|
|
53
|
+
|
|
54
|
+
1. Run `project-brain worktree status --json`. If `isMain` is false and `indexed` is
|
|
55
|
+
true, the worktree is ready — skip to step 5. A session that started inside a
|
|
56
|
+
worktree already has this in context: the `SessionStart` hook injects it, and says
|
|
57
|
+
nothing at all in a main checkout.
|
|
58
|
+
2. Decide isolation. Needed when the task changes code and something else must keep
|
|
59
|
+
running on the current branch, or when sibling agents work in parallel. Not needed for
|
|
60
|
+
a read-only task. Ask before creating one unless the user already said to.
|
|
61
|
+
3. Create it with the harness's own tool (`EnterWorktree`, or the `using-git-worktrees`
|
|
62
|
+
skill). Never `git worktree add` by hand when a native tool exists — the harness
|
|
63
|
+
cannot see or clean up what it did not create.
|
|
64
|
+
4. In the worktree: `project-brain init` then `project-brain sync`. Only now does the
|
|
65
|
+
agent have a graph that matches its branch.
|
|
66
|
+
5. `port_acquire(project, worktree, technology)` with the pair from step 1, once per
|
|
67
|
+
service the task boots. The lease is sticky, so re-running returns the same port.
|
|
68
|
+
6. Delegate. The sub-agent starts with an empty context and never reads CLAUDE.md, so
|
|
69
|
+
its prompt must carry, as text: the worktree path, `projectId`, every acquired port,
|
|
70
|
+
and the model-routing table if it will spawn its own sub-agents. A sub-agent has the
|
|
71
|
+
`Agent` tool and can nest; it does NOT have `Workflow`, so deterministic
|
|
72
|
+
orchestration stays with you.
|
|
73
|
+
7. Tear down. `project-brain setup` installs hooks that do this for you: `WorktreeRemove`
|
|
74
|
+
reclaims the worktree's index, and mcp-port-registry's own hook releases its ports.
|
|
75
|
+
Run `project-brain worktree prune` and `port_release` by hand only when you removed a
|
|
76
|
+
worktree outside the harness, or when a non-interactive run skipped hooks entirely.
|
|
77
|
+
Both sides reconcile against `git worktree list` on the next session start anyway,
|
|
78
|
+
which is why neither trusts the removal event alone.
|
|
79
|
+
|
|
80
|
+
## Hard Rules
|
|
81
|
+
|
|
82
|
+
- Never `sync` a worktree you did not `init` first — sync exits "project not initialized"
|
|
83
|
+
rather than guessing, and that is the correct answer.
|
|
84
|
+
- Never write durable knowledge expecting it to live in the worktree. `add_knowledge`
|
|
85
|
+
from a worktree is routed to the BASE project on purpose: a worktree index is
|
|
86
|
+
disposable and `worktree prune` will drop it.
|
|
87
|
+
- Never run `worktree prune` to fix a confusing result. It reclaims by asking git which
|
|
88
|
+
worktrees are live, with no grace window, because a worktree index is re-derivable by
|
|
89
|
+
one `sync`. That is safe for worktrees and wrong for projects — whole projects belong
|
|
90
|
+
to `prune`, which has the grace window.
|
|
91
|
+
- Never hardcode a port. Two agents that both assume 3000 collide, and the failure looks
|
|
92
|
+
like a broken app rather than a taken port.
|
|
93
|
+
- If a delegation from the main checkout is blocked with a message about isolation, that
|
|
94
|
+
is the opt-in `PreToolUse` guard, not a bug. It asks for a decision, not a worktree:
|
|
95
|
+
re-issue with the word `worktree` in the description, either naming the one it runs in
|
|
96
|
+
or saying plainly that the task does not need one. Do not disable the guard to get past
|
|
97
|
+
it.
|
|
98
|
+
|
|
99
|
+
## Output Contract
|
|
100
|
+
|
|
101
|
+
Report: the worktree path and branch, its `projectId`, each technology with the port
|
|
102
|
+
leased for it, what was delegated and to which model, and whether teardown ran or was
|
|
103
|
+
deliberately left open.
|