@1agh/maude 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/apps/studio/actions/agents.ts +18 -42
  2. package/apps/studio/actions/verbs.ts +49 -0
  3. package/apps/studio/actions.manifest.json +103 -19
  4. package/apps/studio/ai/create-claim.ts +1 -1
  5. package/apps/studio/bin/_asset-file.mjs +117 -0
  6. package/apps/studio/bin/_canvas-file.mjs +146 -0
  7. package/apps/studio/bin/_footage.mjs +123 -0
  8. package/apps/studio/bin/_pdf-playwright.mjs +14 -0
  9. package/apps/studio/bin/_png-playwright.mjs +15 -1
  10. package/apps/studio/bin/_pw-launch.mjs +98 -0
  11. package/apps/studio/bin/_retry-save.mjs +49 -0
  12. package/apps/studio/bin/_sync.mjs +145 -2
  13. package/apps/studio/bin/asset-rename.sh +12 -0
  14. package/apps/studio/bin/asset-trash.sh +12 -0
  15. package/apps/studio/bin/canvas-move.sh +12 -0
  16. package/apps/studio/bin/canvas-new.sh +12 -0
  17. package/apps/studio/bin/footage.sh +12 -0
  18. package/apps/studio/bin/generate.sh +7 -0
  19. package/apps/studio/bin/retry-save.sh +13 -0
  20. package/apps/studio/bridge/canvas-mode-store.ts +11 -2
  21. package/apps/studio/bridge/dgn-protocol.ts +8 -3
  22. package/apps/studio/bridge/occlusion.ts +45 -0
  23. package/apps/studio/canvas-theme-pill.tsx +182 -38
  24. package/apps/studio/client/export-center.jsx +32 -3
  25. package/apps/studio/client/home/HomeAccountBanner.jsx +61 -0
  26. package/apps/studio/client/home/HomeAccountsChip.jsx +404 -0
  27. package/apps/studio/client/home/HomeConnection.jsx +4 -3
  28. package/apps/studio/client/home/ProjectRows.jsx +514 -0
  29. package/apps/studio/client/home/home-accounts-model.js +148 -99
  30. package/apps/studio/client/home/home-api.js +4 -0
  31. package/apps/studio/client/home/home-app.jsx +127 -432
  32. package/apps/studio/client/home/home-icons.jsx +8 -0
  33. package/apps/studio/client/home/home-model.js +109 -0
  34. package/apps/studio/client/home/home.css +447 -111
  35. package/apps/studio/client/home/use-account-fix.js +123 -0
  36. package/apps/studio/client/v2/assets/generate-ask.jsx +3 -1
  37. package/apps/studio/client/v2/export/done-toast.jsx +2 -5
  38. package/apps/studio/client/v2/export/export-sheet.jsx +9 -2
  39. package/apps/studio/client/v2/export/export.css +9 -0
  40. package/apps/studio/client/v2/export/exports-model.js +16 -3
  41. package/apps/studio/client/v2/export/file-rows.jsx +81 -5
  42. package/apps/studio/client/v2/export/native-save.js +33 -0
  43. package/apps/studio/client/v2/export/sections/print-copy.js +3 -0
  44. package/apps/studio/client/v2/export/sections/print.jsx +37 -20
  45. package/apps/studio/client/v2/shell/occlusion-insets.js +37 -9
  46. package/apps/studio/client/v2/shell/use-occluded-insets.js +13 -3
  47. package/apps/studio/collab/room.ts +21 -7
  48. package/apps/studio/dist/client.bundle.js +692 -692
  49. package/apps/studio/dist/comment-mount.js +2 -2
  50. package/apps/studio/dist/styles.css +1 -1
  51. package/apps/studio/exporters/ghostscript.ts +78 -1
  52. package/apps/studio/exporters/pdf-fonts.ts +31 -4
  53. package/apps/studio/generation/jobs.ts +6 -0
  54. package/apps/studio/http.ts +6 -2
  55. package/apps/studio/routes/agent.ts +6 -2
  56. package/apps/studio/routes/project-undo.ts +10 -0
  57. package/apps/studio/server.ts +25 -0
  58. package/apps/studio/shell/cli-yield.ts +48 -11
  59. package/apps/studio/whats-new.json +18 -0
  60. package/cli/commands/design.mjs +74 -16
  61. package/cli/lib/bash-guard.mjs +4 -4
  62. package/cli/lib/confine-read.mjs +2 -0
  63. package/cli/lib/design-help.gen.mjs +15 -2
  64. package/cli/lib/design-hook.mjs +1 -1
  65. package/cli/lib/desktop-locate.mjs +36 -8
  66. package/cli/lib/studio-locate.mjs +8 -2
  67. package/cli/lib/sub-verbs.mjs +13 -1
  68. package/package.json +8 -8
  69. package/plugins/flow/.claude-plugin/config.schema.json +11 -1
  70. package/apps/studio/client/home/HomeAccounts.jsx +0 -262
  71. package/apps/studio/client/home/HomeAccountsRow.jsx +0 -221
@@ -0,0 +1,146 @@
1
+ // Internal shim behind canvas-new.sh / canvas-move.sh (`maude design canvas-new`, `canvas-move`).
2
+ //
3
+ // The app's own whole-file canvas operations, for the AI chat and a terminal (fix-bulk W1 follow-up):
4
+ // new POST /_api/canvas { kind, name?, group?, clips? } (effect project → auto)
5
+ // POST /_api/canvas { duplicateOf } (--duplicate; the same route)
6
+ // move POST /_api/fs-move { file, toName?, toDir? } (effect project → auto)
7
+ // The same routes Canvases › New canvas / Duplicate / Rename / Move to… call, so Version history
8
+ // records the create or move, and a create in a chat is claimed for that chat's live run
9
+ // (X-Maude-Chat, ai/create-claim.ts — `call` adds it on a write).
10
+ //
11
+ // Why verbs and not `curl-local`: since 2.1.0 the studio's main origin needs its key from every
12
+ // caller (contract sec-loopback-bearer §7). `curl-local` sends none, by design — it is a plain
13
+ // loopback curl and stays one. These verbs find the studio and its key the one way every verb does
14
+ // (studio-locate.mjs: the app's attested server, else a terminal server whose `/_health` names this
15
+ // project) and send it with each request (`studioHeaders`, via `call`).
16
+
17
+ import { call, clean, connect, field, parseWords, runVerb, UsageError } from './_studio-verb.mjs';
18
+
19
+ export const NEW_USAGE = `usage: maude design canvas-new [<name>] [--kind blank|brief-board|video-comp] [--group <folder>]
20
+ [--ds <design system>] [--from-prompt <sentence>] [--json] [--root <project>]
21
+ maude design canvas-new --duplicate <canvas path> [--json] [--root <project>]
22
+ Makes a canvas the way Canvases › New canvas does, and prints the file it made (.design/…tsx);
23
+ then Edit that file. No name: the app picks one ("Untitled", or the next free one).
24
+ --kind blank (default) · brief-board (a brief to annotate) · video-comp (an empty video)
25
+ --group one of the project's canvas folders (default: the new-canvas folder, usually ui)
26
+ --ds the canvas's design system (default: what New canvas picks; an unknown one → the default)
27
+ --from-prompt with no name, a blank canvas is named from this sentence ("A poster for…" → Poster)
28
+ --duplicate a copy of that canvas next to it, as Canvases › Duplicate does
29
+ Exit 0 made · 1 refused · 2 usage · 3 no studio running.
30
+ `;
31
+
32
+ export const MOVE_USAGE = `usage: maude design canvas-move <canvas path> [--name <new name>] [--to <folder>]
33
+ [--json] [--root <project>]
34
+ Renames or moves a canvas (the .tsx and everything that belongs to it) the way Canvases › Rename
35
+ and Move to… do, so Version history keeps it one canvas. Give --name, --to, or both.
36
+ --name the new name, without .tsx
37
+ --to the design-root-relative folder to move it to (ui/archive)
38
+ Exit 0 moved · 1 refused · 2 usage · 3 no studio running.
39
+ `;
40
+
41
+ const KINDS = new Set(['blank', 'brief-board', 'video-comp']);
42
+
43
+ /** `ui/home.tsx`, `.design/ui/home.tsx` or `./ui/home.tsx` → `ui/home.tsx`, or a UsageError. */
44
+ export function canvasOperand(word) {
45
+ const path = String(word)
46
+ .replace(/^\.\//, '')
47
+ .replace(/^\.design\//, '');
48
+ if (!/\.tsx$/i.test(path) || path.split('/').includes('..') || path.startsWith('/'))
49
+ throw new UsageError(`${clean(word)} is not a canvas path (ui/<name>.tsx)`);
50
+ return path;
51
+ }
52
+
53
+ /** The words after `canvas-new` → the `/_api/canvas` body. Pure; throws UsageError. */
54
+ export function newBody(words) {
55
+ const { flags, pos } = parseWords(words, {
56
+ bool: ['--json'],
57
+ value: ['--kind', '--group', '--ds', '--from-prompt', '--duplicate', '--root'],
58
+ });
59
+ if (pos.length > 1) throw new UsageError('give at most one name');
60
+ if (flags['--duplicate'] !== undefined) {
61
+ if (pos.length || ['--kind', '--group', '--ds', '--from-prompt'].some((f) => f in flags))
62
+ throw new UsageError('--duplicate takes no name, --kind, --group, --ds or --from-prompt');
63
+ return { flags, body: { duplicateOf: canvasOperand(flags['--duplicate']) } };
64
+ }
65
+ const kind = flags['--kind'] ?? 'blank';
66
+ if (!KINDS.has(kind)) throw new UsageError(`--kind must be blank, brief-board or video-comp`);
67
+ if (kind !== 'blank' && !pos.length) throw new UsageError(`a ${kind} needs a name`);
68
+ const body = { kind };
69
+ if (pos.length) body.name = pos[0];
70
+ if (flags['--group'] !== undefined) body.group = flags['--group'];
71
+ if (flags['--ds'] !== undefined) body.designSystem = flags['--ds'];
72
+ if (flags['--from-prompt'] !== undefined) {
73
+ if (pos.length || kind !== 'blank')
74
+ throw new UsageError('--from-prompt names an unnamed blank canvas: give it without a name');
75
+ body.fromPrompt = flags['--from-prompt'];
76
+ }
77
+ if (kind === 'video-comp') body.clips = [];
78
+ return { flags, body };
79
+ }
80
+
81
+ /** The words after `canvas-move` → the `/_api/fs-move` body. Pure; throws UsageError. */
82
+ export function moveBody(words) {
83
+ const { flags, pos } = parseWords(words, {
84
+ bool: ['--json'],
85
+ value: ['--name', '--to', '--root'],
86
+ });
87
+ if (pos.length !== 1) throw new UsageError('name one canvas path');
88
+ const to = flags['--to'];
89
+ if (flags['--name'] === undefined && to === undefined)
90
+ throw new UsageError('give --name, --to, or both');
91
+ const body = { file: canvasOperand(pos[0]) };
92
+ if (flags['--name'] !== undefined) body.toName = String(flags['--name']).replace(/\.tsx$/i, '');
93
+ if (to !== undefined) body.toDir = to;
94
+ return { flags, body };
95
+ }
96
+
97
+ function refused(name, r) {
98
+ const b = r?.body ?? {};
99
+ const why = clean(b.error ?? (r ? r.text?.trim() || `HTTP ${r.status}` : 'no answer'));
100
+ process.stderr.write(`maude design ${name}: refused — ${why}\n`);
101
+ return 1;
102
+ }
103
+
104
+ async function runNew(words) {
105
+ const { flags, body } = newBody(words);
106
+ const c = await connect('canvas-new', flags['--root']);
107
+ if (c.exit) return c.exit;
108
+ const r = await call(c.studio, '/_api/canvas', { method: 'POST', json: body });
109
+ const b = r?.body ?? {};
110
+ if (r?.status === 201 && b.ok) {
111
+ if (flags['--json']) process.stdout.write(`${JSON.stringify(b)}\n`);
112
+ else process.stdout.write(`→ made ${field(b.file ?? b.rel)} — Edit that file\n`);
113
+ return 0;
114
+ }
115
+ return refused('canvas-new', r);
116
+ }
117
+
118
+ async function runMove(words) {
119
+ const { flags, body } = moveBody(words);
120
+ const c = await connect('canvas-move', flags['--root']);
121
+ if (c.exit) return c.exit;
122
+ const r = await call(c.studio, '/_api/fs-move', { method: 'POST', json: body });
123
+ const b = r?.body ?? {};
124
+ if (r?.status === 200 && b.ok) {
125
+ if (flags['--json']) process.stdout.write(`${JSON.stringify(b)}\n`);
126
+ else process.stdout.write(`→ moved ${field(b.fromRel)} to ${field(b.toRel)}\n`);
127
+ return 0;
128
+ }
129
+ return refused('canvas-move', r);
130
+ }
131
+
132
+ if (import.meta.main) {
133
+ const sub = process.argv[2];
134
+ if (sub === 'new') {
135
+ process.argv.splice(2, 1);
136
+ runVerb('canvas-new', NEW_USAGE, runNew);
137
+ } else if (sub === 'move') {
138
+ process.argv.splice(2, 1);
139
+ runVerb('canvas-move', MOVE_USAGE, runMove);
140
+ } else {
141
+ process.stderr.write(
142
+ '_canvas-file.mjs: run it through `maude design canvas-new|canvas-move`\n'
143
+ );
144
+ process.exit(2);
145
+ }
146
+ }
@@ -0,0 +1,123 @@
1
+ // Internal shim behind footage.sh (`maude design footage show|save`).
2
+ //
3
+ // The footage sidecars of /design-video:reel and /design-video:video-analyze (feature-footage-analysis-
4
+ // director), for the orchestrator in the AI chat and a terminal (fix-bulk 2026-11-10 follow-up):
5
+ // show GET /_api/footage?asset=<…> | ?slug=<…> a clip's FootageAnalysis, or a cut's EDL ({} = none yet)
6
+ // save PUT /_api/footage?asset=<…> | ?slug=<…> validated and stamped by the studio (footage-store.ts)
7
+ // The analyst agent never runs this: it returns JSON, and the command persists it (DDR-183 F2).
8
+ //
9
+ // Why a verb and not a loopback curl: since 2.1.0 the studio's main origin needs its key from every
10
+ // caller (contract sec-loopback-bearer §7), and `curl-local` sends none. This finds the studio and its
11
+ // key the way every verb does (studio-locate.mjs). A `.footage.json` / EDL syncs between peers
12
+ // (DDR-054), so `show` prints it inside the untrusted-data block.
13
+ //
14
+ // `save --from <file>` reads the file the caller names: in a Maude chat that path is checked against the
15
+ // chat's read boundary by the dispatcher (cli/lib/confine-read.mjs SOURCE_FLAGS).
16
+
17
+ import { readFileSync } from 'node:fs';
18
+ import {
19
+ call,
20
+ clean,
21
+ connect,
22
+ parseWords,
23
+ runVerb,
24
+ UNTRUSTED_NOTICE,
25
+ UsageError,
26
+ writeUntrusted,
27
+ } from './_studio-verb.mjs';
28
+
29
+ export const USAGE = `usage: maude design footage show (--asset <clip> | --cut <slug>) [--json] [--root <project>]
30
+ maude design footage save (--asset <clip> | --cut <slug>) --from <file.json> [--root <project>]
31
+ show a clip's footage analysis (its shots), or a cut's EDL; {} when there is none yet
32
+ save store the analysis (or EDL) in the file, as the studio validates it; a refusal names the field
33
+ --asset the clip: assets/<sha8>.<ext>, or its <sha8>
34
+ --cut the cut's EDL slug (.design/<slug>.edl.json)
35
+ --from the JSON file to store (- reads stdin)
36
+ Exit 0 ok · 1 refused (the JSON did not validate) · 2 usage · 3 no studio running.
37
+ `;
38
+
39
+ /** The words after `show` / `save` → `{ flags, query }`. Pure; throws UsageError. */
40
+ export function footageQuery(words, { save }) {
41
+ const { flags, pos } = parseWords(words, {
42
+ bool: save ? [] : ['--json'],
43
+ value: save ? ['--asset', '--cut', '--from', '--root'] : ['--asset', '--cut', '--root'],
44
+ });
45
+ if (pos.length) throw new UsageError(`unexpected ${clean(pos[0])}`);
46
+ const asset = flags['--asset'];
47
+ const cut = flags['--cut'];
48
+ if ((asset === undefined) === (cut === undefined))
49
+ throw new UsageError('give exactly one of --asset <clip> or --cut <slug>');
50
+ if (save && flags['--from'] === undefined) throw new UsageError('save needs --from <file.json>');
51
+ const q = new URLSearchParams();
52
+ if (asset !== undefined)
53
+ q.set(
54
+ 'asset',
55
+ String(asset)
56
+ .replace(/^\.\//, '')
57
+ .replace(/^\.design\//, '')
58
+ );
59
+ else q.set('slug', String(cut));
60
+ return { flags, query: q.toString() };
61
+ }
62
+
63
+ function refused(r) {
64
+ const b = r?.body ?? {};
65
+ const why = clean(
66
+ b.error ?? b.reason ?? (r ? r.text?.trim() || `HTTP ${r.status}` : 'no answer')
67
+ );
68
+ process.stderr.write(`maude design footage: refused — ${why}\n`);
69
+ return 1;
70
+ }
71
+
72
+ async function show(words) {
73
+ const { flags, query } = footageQuery(words, { save: false });
74
+ const c = await connect('footage', flags['--root']);
75
+ if (c.exit) return c.exit;
76
+ const r = await call(c.studio, `/_api/footage?${query}`);
77
+ if (r?.status !== 200 || !r.body || typeof r.body !== 'object') return refused(r);
78
+ // JSON.stringify escapes every control character, so the text is safe to print as it is.
79
+ if (flags['--json'])
80
+ process.stdout.write(
81
+ `${JSON.stringify({ untrusted: true, notice: UNTRUSTED_NOTICE, data: r.body })}\n`
82
+ );
83
+ else writeUntrusted(JSON.stringify(r.body, null, 2));
84
+ return 0;
85
+ }
86
+
87
+ async function save(words) {
88
+ const { flags, query } = footageQuery(words, { save: true });
89
+ const from = flags['--from'];
90
+ let text;
91
+ try {
92
+ text = readFileSync(from === '-' ? 0 : from, 'utf8');
93
+ } catch {
94
+ throw new UsageError(`cannot read ${clean(from)}`);
95
+ }
96
+ let json;
97
+ try {
98
+ json = JSON.parse(text);
99
+ } catch {
100
+ throw new UsageError(`${clean(from)} is not JSON`);
101
+ }
102
+ const c = await connect('footage', flags['--root']);
103
+ if (c.exit) return c.exit;
104
+ const r = await call(c.studio, `/_api/footage?${query}`, { method: 'PUT', json });
105
+ if (r?.status === 200 && r.body?.ok) {
106
+ process.stdout.write(`→ saved ${query.startsWith('asset=') ? 'the analysis' : 'the EDL'}\n`);
107
+ return 0;
108
+ }
109
+ return refused(r);
110
+ }
111
+
112
+ const SUBS = { show, save };
113
+
114
+ if (import.meta.main) {
115
+ runVerb('footage', USAGE, async (words) => {
116
+ const sub = words[0];
117
+ if (!sub || !Object.hasOwn(SUBS, sub))
118
+ throw new UsageError(
119
+ sub ? `unknown sub-verb ${clean(sub)}` : 'name a sub-verb: show or save'
120
+ );
121
+ return SUBS[sub](words.slice(1));
122
+ });
123
+ }
@@ -29,6 +29,7 @@ import {
29
29
  launchChromium,
30
30
  newShellContext,
31
31
  safeArtboardFilename,
32
+ settleForCapture,
32
33
  } from './_pw-launch.mjs';
33
34
  import { layoutRegion, parseRegionArg } from './_region.mjs';
34
35
 
@@ -120,6 +121,11 @@ try {
120
121
  const box = await layoutRegion(page, region);
121
122
  assertRenderOutputSizeOk(box.width, box.height, deviceScaleFactor, '_pdf-playwright');
122
123
  await page.setViewportSize({ width: Math.max(1, box.width), height: Math.max(1, box.height) });
124
+ // B3 — the region spans artboards that were off screen until now; settle all of them.
125
+ const restoreCulling = await settleForCapture(page.locator('.dc-world').first(), {
126
+ budgetMs: timeoutMs,
127
+ label: 'region',
128
+ });
123
129
  const pdf = await page.pdf({
124
130
  width: `${box.width}px`,
125
131
  height: `${box.height}px`,
@@ -129,6 +135,7 @@ try {
129
135
  });
130
136
  writeFileSync(out, pdf);
131
137
  written.push(out);
138
+ await restoreCulling();
132
139
  }
133
140
 
134
141
  for (let i = 0; i < (region ? 0 : screens.length); i += 1) {
@@ -174,6 +181,12 @@ try {
174
181
  el.scrollIntoView({ block: 'start', inline: 'start' });
175
182
  window.scrollTo(0, 0);
176
183
  });
184
+ // B3 — an artboard that started off screen was never laid out (content-visibility), so its
185
+ // webfont was never requested and its pictures may still be loading: settle it first.
186
+ const restoreCulling = await settleForCapture(handle, {
187
+ budgetMs: timeoutMs,
188
+ label: screenId ?? `artboard ${i + 1}`,
189
+ });
177
190
  const pdf = await page.pdf({
178
191
  width: `${Math.ceil(rect.w)}px`,
179
192
  height: `${Math.ceil(rect.h)}px`,
@@ -183,6 +196,7 @@ try {
183
196
  });
184
197
  writeFileSync(targetPath, pdf);
185
198
  written.push(targetPath);
199
+ await restoreCulling();
186
200
  // Restore the artboard's original position now that its page is written.
187
201
  await handle.evaluate((el, prev) => {
188
202
  const ab = el.closest('[data-dc-screen]') ?? el;
@@ -6,12 +6,13 @@
6
6
  // viewport exactly and crop to the target element's bounding box.
7
7
 
8
8
  import { mkdirSync } from 'node:fs';
9
- import { dirname, join } from 'node:path';
9
+ import { basename, dirname, join } from 'node:path';
10
10
  import {
11
11
  afterPaint,
12
12
  launchChromium,
13
13
  newShellContext,
14
14
  safeArtboardFilename,
15
+ settleForCapture,
15
16
  } from './_pw-launch.mjs';
16
17
  import { layoutRegion, parseRegionArg } from './_region.mjs';
17
18
 
@@ -206,6 +207,12 @@ try {
206
207
  const vp = page.viewportSize();
207
208
  const clipX = Math.min(Math.max(0, Math.floor(finalRect.x)), Math.max(0, vp.width - 1));
208
209
  const clipY = Math.min(Math.max(0, Math.floor(finalRect.y)), Math.max(0, vp.height - 1));
210
+ // B3 — an artboard that started off screen was never laid out (content-visibility), so its
211
+ // webfont was never requested and its pictures may still be loading: settle it first.
212
+ const restoreCulling = await settleForCapture(widenedHandle, {
213
+ budgetMs: timeoutMs,
214
+ label: basename(target),
215
+ });
209
216
  // Shoot a frame painted at this size and position, never the previous surface (afterPaint).
210
217
  await afterPaint(page);
211
218
  await page.screenshot({
@@ -219,6 +226,7 @@ try {
219
226
  },
220
227
  });
221
228
  written.push(target);
229
+ await restoreCulling();
222
230
  // Restore the artboard's original position now that its capture is done,
223
231
  // so it doesn't stay pinned at (0,0) and corrupt the next target's clip.
224
232
  await widenedHandle.evaluate((el, prev) => {
@@ -239,6 +247,11 @@ try {
239
247
  const box = await layoutRegion(page, region);
240
248
  assertOutputSizeOk(box.width, box.height);
241
249
  await page.setViewportSize({ width: Math.max(1, box.width), height: Math.max(1, box.height) });
250
+ // B3 — the region spans artboards that were off screen until now; settle all of them.
251
+ const restoreCulling = await settleForCapture(page.locator('.dc-world').first(), {
252
+ budgetMs: timeoutMs,
253
+ label: 'region',
254
+ });
242
255
  // Shoot a frame painted at this size and position, never the previous surface (afterPaint).
243
256
  await afterPaint(page);
244
257
  await page.screenshot({
@@ -247,6 +260,7 @@ try {
247
260
  clip: { x: 0, y: 0, width: box.width, height: box.height },
248
261
  });
249
262
  written.push(out);
263
+ await restoreCulling();
250
264
  } else if (multi) {
251
265
  if (!outDir) {
252
266
  console.error('_png-playwright: --multi requires --out-dir');
@@ -192,6 +192,104 @@ export async function afterPaint(page) {
192
192
  );
193
193
  }
194
194
 
195
+ // B3 (fix-bulk 2026-11-10) — settle ONE capture target, right before its shot.
196
+ //
197
+ // Every `.dc-artboard-body` is `content-visibility: auto` (canvas-lib, the pan/zoom jank fix), so
198
+ // an artboard outside the viewport is neither laid out nor painted. The canvas mounts after
199
+ // `load`, so nothing about such an artboard is ready when the shim starts: its webfont has never
200
+ // been requested (the one `document.fonts.ready` awaited after load resolved without it) and its
201
+ // pictures may still be on the wire. A multi-page Print PDF of LetakA6 lost the photos and the
202
+ // colour font of exactly the artboard that started below the viewport; a warm re-run was fine.
203
+ //
204
+ // So, for the target's own artboard (or, for a region, the element given — the world plane):
205
+ // 1. render it now — `content-visibility: visible !important` on its culled bodies, restored
206
+ // by the returned function (set through CSSOM, which the canvas CSP allows);
207
+ // 2. lay it out, then wait until no font face is loading (re-checked after a frame: a face is
208
+ // requested only once text that needs it is shaped);
209
+ // 3. wait for every `<img>` (lazy ones made eager) to load or fail, then `decode()` it, and
210
+ // `decode()` every SVG `<image>`;
211
+ // 4. two frames, so the shot carries what was just decoded (`afterPaint`).
212
+ // Bounded by `budgetMs`: a picture that never arrives costs one budget and the shot goes ahead
213
+ // (the old behaviour) with a line on stderr, never a hung export.
214
+ //
215
+ // @param {import('playwright').ElementHandle | import('playwright').Locator} handle
216
+ // @param {{ budgetMs?: number, label?: string }} [opts]
217
+ // @returns {Promise<() => Promise<void>>} restores the culling it lifted
218
+ export async function settleForCapture(handle, opts = {}) {
219
+ const budgetMs = Math.max(1000, Math.min(60_000, opts.budgetMs ?? 15_000));
220
+ const result = await handle.evaluateHandle(async (el, budget) => {
221
+ const root = el.closest('[data-dc-screen]') ?? el;
222
+ const lifted = [];
223
+ const candidates = [
224
+ root,
225
+ ...root.querySelectorAll('.dc-artboard-body, [style*="content-visibility"]'),
226
+ ];
227
+ for (const node of candidates) {
228
+ if (getComputedStyle(node).contentVisibility === 'visible') continue;
229
+ lifted.push({
230
+ node,
231
+ value: node.style.getPropertyValue('content-visibility'),
232
+ priority: node.style.getPropertyPriority('content-visibility'),
233
+ });
234
+ node.style.setProperty('content-visibility', 'visible', 'important');
235
+ }
236
+ root.getBoundingClientRect(); // lay it out now, so the faces its text needs are requested
237
+
238
+ const frame = () => new Promise((r) => requestAnimationFrame(() => r()));
239
+ const settle = async () => {
240
+ for (const img of root.querySelectorAll('img')) {
241
+ if (img.loading === 'lazy') img.loading = 'eager';
242
+ }
243
+ for (let round = 0; round < 3; round += 1) {
244
+ await document.fonts.ready;
245
+ const loading = [...document.fonts].filter((f) => f.status === 'loading');
246
+ await Promise.all(loading.map((f) => f.loaded.catch(() => {})));
247
+ await Promise.all(
248
+ [...root.querySelectorAll('img')].map(async (img) => {
249
+ if (!img.complete) {
250
+ await new Promise((r) => {
251
+ img.addEventListener('load', r, { once: true });
252
+ img.addEventListener('error', r, { once: true });
253
+ });
254
+ }
255
+ if (img.naturalWidth > 0) await img.decode().catch(() => {});
256
+ })
257
+ );
258
+ await Promise.all(
259
+ [...root.querySelectorAll('image')].map((im) =>
260
+ typeof im.decode === 'function' ? im.decode().catch(() => {}) : null
261
+ )
262
+ );
263
+ await frame();
264
+ if (![...document.fonts].some((f) => f.status === 'loading')) break;
265
+ }
266
+ await frame();
267
+ await frame();
268
+ return true;
269
+ };
270
+ const settled = await Promise.race([
271
+ settle(),
272
+ new Promise((r) => setTimeout(() => r(false), budget)),
273
+ ]);
274
+ return { settled, lifted };
275
+ }, budgetMs);
276
+ const settled = await (await result.getProperty('settled')).jsonValue();
277
+ if (!settled) {
278
+ console.error(
279
+ `capture: ${opts.label ?? 'target'} still had fonts or pictures loading after ${budgetMs} ms — shooting it anyway`
280
+ );
281
+ }
282
+ return async () => {
283
+ await result.evaluate(({ lifted }) => {
284
+ for (const { node, value, priority } of lifted) {
285
+ if (value) node.style.setProperty('content-visibility', value, priority);
286
+ else node.style.removeProperty('content-visibility');
287
+ }
288
+ });
289
+ await result.dispose();
290
+ };
291
+ }
292
+
195
293
  // Shared by every raster-capture export shim (_png/_pdf-playwright.mjs) that
196
294
  // scales its render surface by `deviceScaleFactor` (feature-2-print-artboards
197
295
  // T4's DPI support). The requested pixel output is only knowable once the
@@ -0,0 +1,49 @@
1
+ // Internal shim behind retry-save.sh (`maude design retry-save`).
2
+ //
3
+ // Retry on the "Not saved — this Mac is out of space" status (S11.17): the canvas writes a full disk
4
+ // held try to land now (POST /_api/diagnostics/disk-retry → { landed, held, full }). They also land by
5
+ // themselves once there is room; an agent frees space first, then retries (fix-bulk 2026-11-10
6
+ // follow-up). An agent's own writes go straight to the files and are never held here.
7
+ //
8
+ // Why a verb and not `curl-local`: since 2.1.0 the studio's main origin needs its key from every caller
9
+ // (contract sec-loopback-bearer §7). `curl-local` sends none, by design; this finds the studio and its
10
+ // key the way every verb does (studio-locate.mjs).
11
+
12
+ import { call, clean, connect, parseWords, runVerb, UsageError } from './_studio-verb.mjs';
13
+
14
+ export const USAGE = `usage: maude design retry-save [--json] [--root <project>]
15
+ The saves this Mac held because its disk was full try to land now, as Retry on the "Not saved"
16
+ status does. Free some space first; they also land by themselves once there is room.
17
+ Exit 0 nothing is held any more · 1 some are still held / the studio refused · 2 usage · 3 no studio running.
18
+ `;
19
+
20
+ async function main(words) {
21
+ const { flags, pos } = parseWords(words, { bool: ['--json'], value: ['--root'] });
22
+ if (pos.length) throw new UsageError('retry-save takes no operand');
23
+ const c = await connect('retry-save', flags['--root']);
24
+ if (c.exit) return c.exit;
25
+ const r = await call(c.studio, '/_api/diagnostics/disk-retry', { method: 'POST' });
26
+ const b = r?.body ?? {};
27
+ if (r?.status !== 200 || !Number.isFinite(b.held)) {
28
+ const why = clean(
29
+ b.reason ?? b.error ?? (r ? r.text?.trim() || `HTTP ${r.status}` : 'no answer')
30
+ );
31
+ process.stderr.write(`maude design retry-save: refused — ${why}\n`);
32
+ return 1;
33
+ }
34
+ const out = { landed: Number(b.landed) || 0, held: b.held, full: b.held > 0 };
35
+ if (flags['--json']) process.stdout.write(`${JSON.stringify(out)}\n`);
36
+ else if (out.held === 0)
37
+ process.stdout.write(
38
+ out.landed
39
+ ? `→ ${out.landed} held saves landed\n`
40
+ : '→ nothing was held — every save is on disk\n'
41
+ );
42
+ else
43
+ process.stdout.write(
44
+ `· ${out.landed} landed, ${out.held} still held — the disk is still full; free some space and retry\n`
45
+ );
46
+ return out.held === 0 ? 0 : 1;
47
+ }
48
+
49
+ if (import.meta.main) runVerb('retry-save', USAGE, main);