@1agh/maude 2.1.1 → 2.1.2

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 (70) 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 +169 -26
  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/apps/studio/client/home/HomeAccounts.jsx +0 -262
  70. package/apps/studio/client/home/HomeAccountsRow.jsx +0 -221
@@ -8,6 +8,16 @@
8
8
  // same sentence the toast shows (effect shared → prompt: it re-compares every file with the
9
9
  // cloud copy and sends what is newer here). Nothing is overwritten.
10
10
  //
11
+ // Sync details' own buttons (fix-bulk 2026-11-10 follow-up — they were taught as `curl-local` recipes,
12
+ // which a keyed studio answers 401, sec-loopback-bearer §7; `call` sends the studio's key). Each falls
13
+ // to the `sync` tier entry (prompt), as the recipes did:
14
+ // compare <canvas> GET /_api/project/conflict?file= a held source conflict's two sides
15
+ // keep-mine|use-theirs|keep-both <canvas>
16
+ // POST /_api/project/conflict { file, choice }
17
+ // publish-ai-edit|discard-ai-edit [--run <id>]
18
+ // POST /_api/project/ai-action { choice, runId? }
19
+ // cancel-transfer POST /_api/sync/cancel-assets stops the picture/video transfer
20
+ //
11
21
  // Hub URLs, file names and conflict paths come from a peer or a config: only counts, the word and the
12
22
  // hub's host are printed, inside the untrusted block (`--json` carries `untrusted: true`).
13
23
 
@@ -19,7 +29,10 @@ import {
19
29
  } from '../client/v2/diagnostics/resync-model.js';
20
30
  import {
21
31
  call,
32
+ clean,
33
+ cleanLines,
22
34
  connect,
35
+ DESIGN_REL,
23
36
  field,
24
37
  parseWords,
25
38
  runVerb,
@@ -30,11 +43,23 @@ import {
30
43
 
31
44
  export const USAGE = `usage: maude design sync status [--json] [--root <project>]
32
45
  maude design sync resync [--no-wait] [--json] [--root <project>]
46
+ maude design sync compare <canvas> [--json] [--root <project>]
47
+ maude design sync keep-mine|use-theirs|keep-both <canvas> [--json] [--root <project>]
48
+ maude design sync publish-ai-edit|discard-ai-edit [--run <id>] [--json] [--root <project>]
49
+ maude design sync cancel-transfer [--json] [--root <project>]
33
50
  status Sync in one word (Up to date · Syncing… · Offline · Needs you · Local project), the hub's
34
51
  host, the file counts, and the last resync's result
35
52
  resync compare every file with the cloud copy: what is newer here is sent, what is newer there is
36
53
  fetched, a file changed on both sides becomes a conflict in Sync details. Nothing is
37
54
  overwritten. Waits and prints the result; --no-wait only starts it.
55
+ compare a held source conflict's two versions: this Mac's and the project's (Sync details › Compare)
56
+ keep-mine · use-theirs · keep-both
57
+ answer a held source conflict, as its card does; keep-both keeps this Mac's version as a
58
+ new canvas "<name> this Mac". <canvas> is the canvas path or the slug \`sync status\` names.
59
+ publish-ai-edit · discard-ai-edit
60
+ the answer to an unfinished AI edit held from the project (--run: that run only)
61
+ cancel-transfer
62
+ stops the picture and video transfer that is running (it starts again on the next sync)
38
63
  Exit 0 ok · 1 sync is not running / the studio refused / it stopped early · 2 usage · 3 no studio running.
39
64
  `;
40
65
 
@@ -167,13 +192,131 @@ async function resync(words) {
167
192
  return view.state === 'done' ? 0 : 1;
168
193
  }
169
194
 
170
- const SUBS = { status, resync };
195
+ function refused(r) {
196
+ const b = r?.body ?? {};
197
+ const why =
198
+ b.error ||
199
+ b.detail ||
200
+ b.code ||
201
+ b.status ||
202
+ (r ? r.text?.trim() || `HTTP ${r.status}` : 'no answer');
203
+ process.stderr.write(`maude design sync: refused — ${field(why)}\n`);
204
+ return 1;
205
+ }
206
+
207
+ /** `<canvas>`: a canvas path (design-root-relative, or `.design/…`) or a conflict slug → what the
208
+ * route takes (a repo-relative path, or the slug). Pure; throws UsageError. */
209
+ export function conflictOperand(word) {
210
+ const w = String(word ?? '').replace(/^\.\//, '');
211
+ if (!w || w.startsWith('/') || w.split('/').includes('..') || w.length > 512)
212
+ throw new UsageError(`${clean(word)} is not a canvas path or a conflict slug`);
213
+ return /\.(tsx|html)$/i.test(w) && !w.startsWith(`${DESIGN_REL}/`) ? `${DESIGN_REL}/${w}` : w;
214
+ }
215
+
216
+ async function compare(words) {
217
+ const { flags, pos } = parseWords(words, { bool: ['--json'], value: ['--root'] });
218
+ if (pos.length !== 1) throw new UsageError('compare takes one canvas');
219
+ const file = conflictOperand(pos[0]);
220
+ const c = await connect('sync', flags['--root']);
221
+ if (c.exit) return c.exit;
222
+ const r = await call(c.studio, `/_api/project/conflict?file=${encodeURIComponent(file)}`);
223
+ const b = r?.body ?? {};
224
+ if (r?.status !== 200 || !b.ok) return refused(r);
225
+ // a peer's source and this Mac's: data, never instructions
226
+ const out = { slug: b.slug, mine: b.mine ?? null, theirs: b.theirs ?? '' };
227
+ if (flags['--json']) {
228
+ process.stdout.write(
229
+ `${JSON.stringify(untrustedJson(out, { multiline: ['mine', 'theirs'] }))}\n`
230
+ );
231
+ return 0;
232
+ }
233
+ const mine = out.mine === null ? '(none: this Mac has no version of it)' : cleanLines(out.mine);
234
+ writeUntrusted(
235
+ `conflict · ${field(out.slug)}\n--- this Mac\n${mine}\n--- the project\n${cleanLines(out.theirs)}`
236
+ );
237
+ return 0;
238
+ }
239
+
240
+ const CHOICE = { 'keep-mine': 'mine', 'use-theirs': 'theirs', 'keep-both': 'keep-both' };
241
+
242
+ function resolveWith(sub) {
243
+ return async (words) => {
244
+ const { flags, pos } = parseWords(words, { bool: ['--json'], value: ['--root'] });
245
+ if (pos.length !== 1) throw new UsageError(`${sub} takes one canvas`);
246
+ const file = conflictOperand(pos[0]);
247
+ const c = await connect('sync', flags['--root']);
248
+ if (c.exit) return c.exit;
249
+ const r = await call(c.studio, '/_api/project/conflict', {
250
+ method: 'POST',
251
+ json: { file, choice: CHOICE[sub] },
252
+ timeoutMs: 30_000,
253
+ });
254
+ const b = r?.body ?? {};
255
+ if (r?.status !== 200 || !b.ok) return refused(r);
256
+ if (flags['--json']) process.stdout.write(`${JSON.stringify(b)}\n`);
257
+ else process.stdout.write(`→ ${sub}: ${field(b.status ?? 'done')}\n`);
258
+ return 0;
259
+ };
260
+ }
261
+
262
+ function aiEdit(choice) {
263
+ return async (words) => {
264
+ const { flags, pos } = parseWords(words, { bool: ['--json'], value: ['--run', '--root'] });
265
+ if (pos.length) throw new UsageError(`${choice}-ai-edit takes no operand`);
266
+ const body = { choice };
267
+ if (flags['--run'] !== undefined) {
268
+ if (!/^[A-Za-z0-9_-]{1,64}$/.test(flags['--run'])) throw new UsageError('--run is a run id');
269
+ body.runId = flags['--run'];
270
+ }
271
+ const c = await connect('sync', flags['--root']);
272
+ if (c.exit) return c.exit;
273
+ const r = await call(c.studio, '/_api/project/ai-action', {
274
+ method: 'POST',
275
+ json: body,
276
+ timeoutMs: 30_000,
277
+ });
278
+ const b = r?.body ?? {};
279
+ if (r?.status !== 200 || !b.ok) return refused(r);
280
+ if (flags['--json']) process.stdout.write(`${JSON.stringify(b)}\n`);
281
+ else
282
+ process.stdout.write(`→ ${choice === 'publish' ? 'published' : 'discarded'} the AI edit\n`);
283
+ return 0;
284
+ };
285
+ }
286
+
287
+ async function cancelTransfer(words) {
288
+ const { flags, pos } = parseWords(words, { bool: ['--json'], value: ['--root'] });
289
+ if (pos.length) throw new UsageError('cancel-transfer takes no operand');
290
+ const c = await connect('sync', flags['--root']);
291
+ if (c.exit) return c.exit;
292
+ const r = await call(c.studio, '/_api/sync/cancel-assets', { method: 'POST' });
293
+ const b = r?.body ?? {};
294
+ if (r?.status !== 200 || !b.ok) return refused(r);
295
+ if (flags['--json']) process.stdout.write(`${JSON.stringify({ cancelled: !!b.cancelled })}\n`);
296
+ else
297
+ process.stdout.write(b.cancelled ? '→ the transfer stopped\n' : '→ no transfer was running\n');
298
+ return 0;
299
+ }
300
+
301
+ const SUBS = {
302
+ status,
303
+ resync,
304
+ compare,
305
+ 'keep-mine': resolveWith('keep-mine'),
306
+ 'use-theirs': resolveWith('use-theirs'),
307
+ 'keep-both': resolveWith('keep-both'),
308
+ 'publish-ai-edit': aiEdit('publish'),
309
+ 'discard-ai-edit': aiEdit('discard'),
310
+ 'cancel-transfer': cancelTransfer,
311
+ };
171
312
 
172
313
  if (import.meta.main) {
173
314
  runVerb('sync', USAGE, async (words) => {
174
315
  const sub = words[0];
175
316
  if (!sub || !Object.hasOwn(SUBS, sub))
176
- throw new UsageError(sub ? `unknown sub-verb ${sub}` : 'name a sub-verb: status or resync');
317
+ throw new UsageError(
318
+ sub ? `unknown sub-verb ${clean(sub)}` : `name a sub-verb: ${Object.keys(SUBS).join(', ')}`
319
+ );
177
320
  return SUBS[sub](words.slice(1));
178
321
  });
179
322
  }
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ # asset-rename.sh — `maude design asset-rename` (fix-bulk 2026-11-10 follow-up). Reached via `maude design
3
+ # asset-rename` (DDR-062), never a raw bin path. The Assets panel's Rename… (POST /_api/assets/rename),
4
+ # sent with the studio's key — see _asset-file.mjs. Exit 0 ok · 1 refused · 2 usage · 3 no studio.
5
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
+
7
+ if ! command -v bun >/dev/null 2>&1; then
8
+ echo "asset-rename.sh: bun is required (hard dependency — see plugins/design/dependencies.json)." >&2
9
+ exit 1
10
+ fi
11
+
12
+ exec bun run "$SCRIPT_DIR/_asset-file.mjs" rename "$@"
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ # asset-trash.sh — `maude design asset-trash` (fix-bulk 2026-11-10 follow-up). Reached via `maude design
3
+ # asset-trash` (DDR-062), never a raw bin path. The Assets panel's Move to trash (POST /_api/assets/trash),
4
+ # sent with the studio's key — see _asset-file.mjs. Exit 0 ok · 1 refused · 2 usage · 3 no studio.
5
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
+
7
+ if ! command -v bun >/dev/null 2>&1; then
8
+ echo "asset-trash.sh: bun is required (hard dependency — see plugins/design/dependencies.json)." >&2
9
+ exit 1
10
+ fi
11
+
12
+ exec bun run "$SCRIPT_DIR/_asset-file.mjs" trash "$@"
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ # canvas-move.sh — `maude design canvas-move` (fix-bulk W1 follow-up). Reached via `maude design
3
+ # canvas-move` (DDR-062), never a raw bin path. The studio's own rename / move (POST /_api/fs-move),
4
+ # sent with the studio's key — see _canvas-file.mjs. Exit 0 ok · 1 refused · 2 usage · 3 no studio.
5
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
+
7
+ if ! command -v bun >/dev/null 2>&1; then
8
+ echo "canvas-move.sh: bun is required (hard dependency — see plugins/design/dependencies.json)." >&2
9
+ exit 1
10
+ fi
11
+
12
+ exec bun run "$SCRIPT_DIR/_canvas-file.mjs" move "$@"
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ # canvas-new.sh — `maude design canvas-new` (fix-bulk W1 follow-up). Reached via `maude design
3
+ # canvas-new` (DDR-062), never a raw bin path. The studio's own create (POST /_api/canvas), sent with
4
+ # the studio's key — see _canvas-file.mjs. Exit 0 ok · 1 refused · 2 usage · 3 no studio running.
5
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
+
7
+ if ! command -v bun >/dev/null 2>&1; then
8
+ echo "canvas-new.sh: bun is required (hard dependency — see plugins/design/dependencies.json)." >&2
9
+ exit 1
10
+ fi
11
+
12
+ exec bun run "$SCRIPT_DIR/_canvas-file.mjs" new "$@"
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ # footage.sh — `maude design footage show|save` (fix-bulk 2026-11-10 follow-up). Reached via `maude design
3
+ # footage` (DDR-062), never a raw bin path. A clip's footage analysis or a cut's EDL (GET / PUT
4
+ # /_api/footage), sent with the studio's key — see _footage.mjs. Exit 0 ok · 1 refused · 2 usage · 3 no studio.
5
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
+
7
+ if ! command -v bun >/dev/null 2>&1; then
8
+ echo "footage.sh: bun is required (hard dependency — see plugins/design/dependencies.json)." >&2
9
+ exit 1
10
+ fi
11
+
12
+ exec bun run "$SCRIPT_DIR/_footage.mjs" "$@"
@@ -178,6 +178,13 @@ JOB_ID=$(printf '%s' "$RESP" | jq -r '.jobId // empty' 2>/dev/null || echo "")
178
178
  if [ -z "$JOB_ID" ]; then
179
179
  REASON=$(printf '%s' "$RESP" | jq -r '.reason // empty' 2>/dev/null || echo "")
180
180
  MSG=$(printf '%s' "$RESP" | jq -r '.message // empty' 2>/dev/null || echo "")
181
+ # #218 — the studio refused THIS helper (its own local access key was missing or wrong), before
182
+ # any provider was asked. Never word it as a provider key: the person's Gemini key was never read.
183
+ case "$(printf '%s' "$RESP" | jq -r '.error // empty' 2>/dev/null || echo "")" in
184
+ api-key-required|api-key-invalid)
185
+ echo "generate.sh: Maude's project server refused this command: it could not prove it runs on this Mac for this project. This is not your provider key — that was never read. Run the command again as it is, in a fresh shell; if HOME was changed in this shell, unset that change first." >&2
186
+ exit 1 ;;
187
+ esac
181
188
  case "$REASON" in
182
189
  needs-confirm)
183
190
  echo "generate.sh: $MSG" >&2
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bash
2
+ # retry-save.sh — `maude design retry-save` (fix-bulk 2026-11-10 follow-up). Reached via `maude design
3
+ # retry-save` (DDR-062), never a raw bin path. Retry on the saves a full disk held (POST
4
+ # /_api/diagnostics/disk-retry), sent with the studio's key — see _retry-save.mjs.
5
+ # Exit 0 every held save landed · 1 some still held / refused · 2 usage · 3 no studio.
6
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7
+
8
+ if ! command -v bun >/dev/null 2>&1; then
9
+ echo "retry-save.sh: bun is required (hard dependency — see plugins/design/dependencies.json)." >&2
10
+ exit 1
11
+ fi
12
+
13
+ exec bun run "$SCRIPT_DIR/_retry-save.mjs" "$@"
@@ -31,12 +31,15 @@ import {
31
31
  type ToolId,
32
32
  } from './canvas-modes.ts';
33
33
  import { acceptFromShell } from './dgn-protocol.ts';
34
- import { type Insets, ZERO_INSETS } from './occlusion.ts';
34
+ import { type Insets, type TopBand, ZERO_INSETS } from './occlusion.ts';
35
35
 
36
36
  export interface CanvasModeSnapshot {
37
37
  readonly insets: Readonly<Insets>;
38
38
  /** The `seq` of the applied `occluded-insets` (-1 = none yet). */
39
39
  readonly insetsSeq: number;
40
+ /** #217 — the free top band between the shell's top islands (iframe px), with the insets; null when the
41
+ * shell sent none (an older shell, Present, no room) — the top-centre pill then centres on the frame. */
42
+ readonly topBand: Readonly<TopBand> | null;
40
43
  /** Governed (V2-4.3b): the shell's mode; null until the first applied `set-mode`. */
41
44
  readonly mode: CanvasModeV2 | null;
42
45
  readonly present: PresentSpec | null;
@@ -86,6 +89,7 @@ export function canvasModeStore(win: Window): CanvasModeStore {
86
89
  let snap: CanvasModeSnapshot = {
87
90
  insets: ZERO_INSETS,
88
91
  insetsSeq: -1,
92
+ topBand: null,
89
93
  mode: null,
90
94
  present: null,
91
95
  caps: null,
@@ -176,7 +180,12 @@ export function canvasModeStore(win: Window): CanvasModeStore {
176
180
  }
177
181
  if (m?.dgn !== 'occluded-insets') return;
178
182
  if (m.seq <= snap.insetsSeq) return; // I4 — an older (or repeated) seq is dropped
179
- snap = { ...snap, insets: Object.freeze({ ...m.insets }), insetsSeq: m.seq };
183
+ snap = {
184
+ ...snap,
185
+ insets: Object.freeze({ ...m.insets }),
186
+ insetsSeq: m.seq,
187
+ topBand: m.topBand ? Object.freeze({ ...m.topBand }) : null,
188
+ };
180
189
  for (const fn of subs) fn(snap);
181
190
  });
182
191
  Object.defineProperty(store, 'doc', { value: win.document });
@@ -32,7 +32,7 @@ import {
32
32
  TOOL_IDS,
33
33
  type ToolId,
34
34
  } from './canvas-modes.ts';
35
- import { clampInsets, type Insets } from './occlusion.ts';
35
+ import { clampInsets, clampTopBand, type Insets, type TopBand } from './occlusion.ts';
36
36
  import { parsePasteData } from './paste-data.ts';
37
37
  import { stillImageBytes } from './still-webp.ts';
38
38
 
@@ -743,7 +743,9 @@ export interface ShellToCanvas {
743
743
  tool?: ToolId;
744
744
  caps: ModeCaps;
745
745
  };
746
- 'occluded-insets': { seq: number; insets: Insets };
746
+ // #217 — `topBand`: the free stretch of the top edge between the top islands (iframe px); the canvas
747
+ // centres its top-centre pill there. Absent from an older shell (the pill centres on the frame).
748
+ 'occluded-insets': { seq: number; insets: Insets; topBand?: TopBand };
747
749
  'present-step': { to: number | 'next' | 'prev' };
748
750
  // S3.7a — the follower page tells its canvas which session to follow (`sid: null` = the first
749
751
  // presenter seen), whether it is live, and whether it is the locked audience window.
@@ -1069,6 +1071,9 @@ const sid: V = (v) => (typeof v === 'string' && PRESENT_SID.test(v) ? v : BAD);
1069
1071
  export const PRESENT_NAME_MAX = 64;
1070
1072
  const presenterName: V = (v) => (typeof v === 'string' && v.length <= PRESENT_NAME_MAX ? v : BAD);
1071
1073
  const insets: V = (v) => clampInsets(v) ?? BAD;
1074
+ /** #217 — an optional cosmetic hint: a bad band is dropped (the pill centres on the frame), never the insets
1075
+ * the camera needs. */
1076
+ const topBand: V = (v) => (v === undefined ? undefined : (clampTopBand(v) ?? undefined));
1072
1077
  /** S10.4 — a designRoot-relative `.css` path; the same rule as the shell's `DS_CSS_REL` (no URL, no `..`). */
1073
1078
  const DS_CSS_REL = /^(?!\/)(?!.*\.\.)[A-Za-z0-9_][A-Za-z0-9 ._/-]{0,255}\.css$/;
1074
1079
  const dsCssPath: V = (v) => (typeof v === 'string' && DS_CSS_REL.test(v) ? v : BAD);
@@ -2685,7 +2690,7 @@ const s2c: S2C = {
2685
2690
  gate: 'parent',
2686
2691
  status: 'new',
2687
2692
  owner: 'bridge/canvas-mode-store',
2688
- parse: p({ seq: num, insets }),
2693
+ parse: p({ seq: num, insets, topBand }),
2689
2694
  },
2690
2695
  // S3.1 — live: the shell lane's `step` sends it; canvas-mode-store keeps it for the Present stage.
2691
2696
  'present-step': {
@@ -106,3 +106,48 @@ export function revealViewBox(host: Box, ins: Insets | null | undefined): Box {
106
106
  bottom: host.top + v.y + v.h,
107
107
  };
108
108
  }
109
+
110
+ /** #217 — the free stretch of the top edge between the top islands, in iframe px from its left edge
111
+ * (`left` = the left island's right edge, `right` = the right cluster's left edge). The canvas centres
112
+ * its top-centre pill (canvas-theme-pill.tsx) in it instead of in the whole frame. */
113
+ export interface TopBand {
114
+ left: number;
115
+ right: number;
116
+ }
117
+
118
+ /** Validate an untrusted top band: both edges finite, 0 ≤ left < right ≤ 8192, rounded; else null. */
119
+ export function clampTopBand(raw: unknown): TopBand | null {
120
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
121
+ const { left, right } = raw as Record<string, unknown>;
122
+ if (typeof left !== 'number' || typeof right !== 'number') return null;
123
+ if (!Number.isFinite(left) || !Number.isFinite(right)) return null;
124
+ const l = Math.round(left);
125
+ const r = Math.round(right);
126
+ if (l < 0 || r > MAX_INSET_PX || !(l < r)) return null;
127
+ return { left: l, right: r };
128
+ }
129
+
130
+ /** Shell side: the top band the `top` islands leave free on the frame. An island whose centre is left of
131
+ * the frame's centre bounds the band on the left (its right edge), any other on the right (its left
132
+ * edge). Hidden islands, other edges and islands off the frame count for nothing. Null when no room is
133
+ * left. */
134
+ export function topBandFromIslands(
135
+ frame: Box,
136
+ islands: ReadonlyArray<{ rect: Box; edge: IslandEdge }>
137
+ ): TopBand | null {
138
+ if (!(frame.right > frame.left)) return null;
139
+ const mid = (frame.left + frame.right) / 2;
140
+ let lo = frame.left;
141
+ let hi = frame.right;
142
+ for (const { rect: r, edge } of islands) {
143
+ if (edge !== 'top' || !(r.right > r.left && r.bottom > r.top)) continue;
144
+ const ix = Math.min(r.right, frame.right) - Math.max(r.left, frame.left);
145
+ const iy = Math.min(r.bottom, frame.bottom) - Math.max(r.top, frame.top);
146
+ if (ix <= 0 || iy <= 0) continue; // off the frame (docked beside it)
147
+ if ((r.left + r.right) / 2 <= mid) lo = Math.max(lo, r.right);
148
+ else hi = Math.min(hi, r.left);
149
+ }
150
+ const left = Math.ceil(lo - frame.left);
151
+ const right = Math.floor(hi - frame.left);
152
+ return left < right ? { left, right } : null;
153
+ }
@@ -10,17 +10,33 @@
10
10
  // canvas (which draws its own bar over the same mode). It also steps aside while a people pill holds the same spot
11
11
  // ("Following …" / "Everyone here is following you … Stop", presence/canvas-presence.tsx): the pill sat on top of it and
12
12
  // took the Stop click.
13
+ //
14
+ // #217 — a dynamic island between the shell's top islands (Michal): two lines, the system's name over the canvas's path
15
+ // (smaller, grey), centred in the free band the shell reports with its `occluded-insets` (`topBand`, the stretch
16
+ // between the project pill and the Share cluster) and never wider than it. Short of room the path line goes first,
17
+ // then the name truncates. An older shell sends no band: the pill centres on the frame, as before.
13
18
 
14
- import { type ReactNode, useEffect, useState } from 'react';
19
+ import {
20
+ type ReactNode,
21
+ useEffect,
22
+ useLayoutEffect,
23
+ useRef,
24
+ useState,
25
+ useSyncExternalStore,
26
+ } from 'react';
27
+ import { canvasModeStore } from './bridge/canvas-mode-store.ts';
28
+ import type { TopBand } from './bridge/occlusion.ts';
15
29
  import { DsIcon } from './canvas-ds-icons.tsx';
16
30
  import { getCanvasThemeSystemName, setCanvasTheme, useCanvasTheme } from './canvas-theme.ts';
17
31
  import { THEME_WORD, ThemeIcon } from './canvas-theme-icons.tsx';
18
32
 
19
33
  /** The pill's chrome. Kept in step with the `.ds-bar` block of ds/board/board.css (same pill, other canvases). */
20
34
  const PILL_CSS = `
21
- .dc-theme-pill{position:fixed;left:50%;top:16px;translate:-50% 0;z-index:2147483000;display:flex;align-items:center;gap:8px;height:44px;padding:0 8px 0 12px;border-radius:var(--maude-hud-radius-lg,14px);background:var(--maude-hud-island-bg);color:var(--maude-chrome-fg-0);-webkit-backdrop-filter:saturate(1.4) blur(18px);backdrop-filter:saturate(1.4) blur(18px);box-shadow:var(--maude-hud-island-shadow),inset 0 0 0 .5px var(--maude-hud-island-edge);font:400 var(--maude-hud-type-sm,12px)/1 var(--maude-chrome-font-body);white-space:nowrap}
35
+ .dc-theme-pill{position:fixed;left:50%;top:16px;translate:-50% 0;z-index:2147483000;box-sizing:border-box;display:flex;align-items:center;gap:8px;min-width:0;min-height:44px;padding:4px 8px 4px 12px;overflow:hidden;border-radius:var(--maude-hud-radius-lg,14px);background:var(--maude-hud-island-bg);color:var(--maude-chrome-fg-0);-webkit-backdrop-filter:saturate(1.4) blur(18px);backdrop-filter:saturate(1.4) blur(18px);box-shadow:var(--maude-hud-island-shadow),inset 0 0 0 .5px var(--maude-hud-island-edge);font:400 var(--maude-hud-type-sm,12px)/1 var(--maude-chrome-font-body);white-space:nowrap}
36
+ .dc-theme-pill>:not(.dc-theme-pill-text){flex:none}
22
37
  .dc-theme-pill-ic{display:grid;place-items:center;width:24px;height:24px;border-radius:var(--maude-hud-radius-xs,4px);background:var(--maude-hud-accent-muted);color:var(--maude-hud-accent-text)}
23
- .dc-theme-pill b{font-weight:600}
38
+ .dc-theme-pill-text{display:flex;flex-direction:column;justify-content:center;align-items:flex-start;min-width:0;flex:0 1 auto}
39
+ .dc-theme-pill-title{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;font-weight:600;line-height:16px}
24
40
  .dc-theme-pill-seg{display:inline-flex;margin:0 0 0 8px;min-width:0;border:0;padding:2px;border-radius:var(--maude-hud-radius-md,10px);background:var(--maude-chrome-bg-3)}
25
41
  .dc-theme-pill-seg:first-child{margin-left:0}
26
42
  .dc-theme-pill-b{appearance:none;border:0;border-radius:calc(var(--maude-hud-radius-md,10px) - 2px);padding:4px 12px;background:transparent;color:var(--maude-chrome-fg-1);font:inherit;font-size:var(--maude-hud-type-xs,11px);cursor:pointer}
@@ -28,7 +44,8 @@ const PILL_CSS = `
28
44
  .dc-theme-pill-b:disabled{opacity:.4;cursor:default}
29
45
  .dc-theme-pill-b--ic{display:grid;place-items:center;padding:4px 7px}
30
46
  .dc-theme-pill-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
31
- .dc-theme-pill-path{appearance:none;border:0;border-radius:var(--maude-hud-radius-xs,4px);padding:4px 6px;margin:0;background:transparent;color:var(--maude-chrome-fg-1);font:inherit;font-size:var(--maude-hud-type-xs,11px);font-family:var(--maude-chrome-font-mono,ui-monospace,monospace);cursor:pointer;max-width:260px;overflow:hidden;text-overflow:ellipsis}
47
+ .dc-theme-pill-path{appearance:none;display:block;border:0;border-radius:var(--maude-hud-radius-xs,4px);padding:0 2px;margin:0 -2px;background:transparent;color:var(--maude-chrome-fg-2);font:inherit;font-size:var(--maude-hud-type-xs,11px);line-height:14px;font-family:var(--maude-chrome-font-mono,ui-monospace,monospace);text-align:left;cursor:pointer;max-width:calc(100% + 4px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
48
+ .dc-theme-pill[data-path="hidden"] .dc-theme-pill-path{position:absolute;visibility:hidden;pointer-events:none}
32
49
  .dc-theme-pill-path:hover{background:var(--maude-chrome-bg-3);color:var(--maude-chrome-fg-0)}
33
50
  .dc-theme-pill-path:focus-visible{outline:2px solid var(--maude-hud-focus-ring);outline-offset:1px}
34
51
  .dc-theme-pill-b:focus-visible{outline:2px solid var(--maude-hud-focus-ring);outline-offset:1px}
@@ -53,6 +70,79 @@ export function shortenCanvasPath(path: string, max = PATH_MAX): string {
53
70
  return `…/${out}`;
54
71
  }
55
72
 
73
+ /** #217 — the room the pill keeps from each top island, and from the frame's edges with no band. */
74
+ export const PILL_BAND_GAP = 12;
75
+ /** #217 — the path line stays while it can show at least this much (an ellipsis eats the rest); narrower, it goes. */
76
+ export const PATH_MIN_PX = 96;
77
+
78
+ /**
79
+ * #217 — where the pill sits: centred in the shell's free top band (clamped to the frame), never wider than the band
80
+ * less a gap on each side. No band (an older shell, nothing usable) ⇒ the frame's centre, as before.
81
+ * @returns `left` (px from the frame's left edge, the pill's centre) and `maxWidth` (px, ≥ 0)
82
+ */
83
+ export function pillPlacement(
84
+ band: Readonly<TopBand> | null,
85
+ viewportWidth: number
86
+ ): { left: number; maxWidth: number; banded: boolean } {
87
+ const vw = Math.max(0, viewportWidth);
88
+ if (band) {
89
+ const l = Math.max(0, band.left);
90
+ const r = Math.min(vw, band.right);
91
+ if (r > l)
92
+ return {
93
+ left: Math.round((l + r) / 2),
94
+ maxWidth: Math.max(0, Math.floor(r - l - 2 * PILL_BAND_GAP)),
95
+ banded: true,
96
+ };
97
+ }
98
+ return { left: Math.round(vw / 2), maxWidth: Math.max(0, vw - 2 * PILL_BAND_GAP), banded: false };
99
+ }
100
+
101
+ /**
102
+ * #217 — does the path line stay? `avail` is the width the two-line text column may take (the pill's max width
103
+ * less its icon, Light | Dark and the rest); `title` / `path` are the lines' natural widths. The path goes first:
104
+ * it stays only while the name fits whole AND the path can show at least PATH_MIN_PX (or all of itself).
105
+ */
106
+ export function showPathLine(avail: number, title: number, path: number): boolean {
107
+ if (!(path > 0)) return false;
108
+ return avail >= Math.max(title, Math.min(path, PATH_MIN_PX));
109
+ }
110
+
111
+ const noSub = () => () => {};
112
+
113
+ /** The laid-out width of an element's text, overflow or not (0 without layout). */
114
+ function textWidthOf(el: Element): number {
115
+ try {
116
+ const r = el.ownerDocument.createRange();
117
+ r.selectNodeContents(el);
118
+ return r.getBoundingClientRect().width;
119
+ } catch {
120
+ return 0;
121
+ }
122
+ }
123
+
124
+ /** The shell's top band, live (null outside a browser document or before the shell sent one). */
125
+ function useTopBand(): Readonly<TopBand> | null {
126
+ const s = typeof window === 'undefined' ? null : canvasModeStore(window);
127
+ return useSyncExternalStore(
128
+ s ? s.subscribe : noSub,
129
+ () => s?.get().topBand ?? null,
130
+ () => null
131
+ );
132
+ }
133
+
134
+ /** The frame's width, live (the fallback centring and the band's clamp read it). */
135
+ function useViewportWidth(): number {
136
+ const [w, setW] = useState(() => (typeof window === 'undefined' ? 0 : window.innerWidth));
137
+ useEffect(() => {
138
+ if (typeof window === 'undefined') return undefined;
139
+ const on = () => setW(window.innerWidth);
140
+ window.addEventListener('resize', on);
141
+ return () => window.removeEventListener('resize', on);
142
+ }, []);
143
+ return w;
144
+ }
145
+
56
146
  /** The canvas's project-relative path (`.design/ui/v2/02 Onboarding.tsx`), as the shell stored it on the frame. */
57
147
  function canvasFilePath(): string | null {
58
148
  if (typeof window === 'undefined') return null;
@@ -109,40 +199,93 @@ export function CanvasThemePill({
109
199
  };
110
200
  const both = bothThemes();
111
201
  const name = getCanvasThemeSystemName();
202
+ // #217 — placed in the shell's free top band; the path line goes first when the band is short
203
+ const band = useTopBand();
204
+ const vw = useViewportWidth();
205
+ const place = pillPlacement(band, vw);
206
+ const pillRef = useRef<HTMLDivElement>(null);
207
+ const textRef = useRef<HTMLSpanElement>(null);
208
+ const titleRef = useRef<HTMLElement>(null);
209
+ const pathRef = useRef<HTMLButtonElement>(null);
210
+ const [pathShown, setPathShown] = useState(true);
211
+ // how many characters of the path fit: it loses its leading folders first, never its file name
212
+ const [pathChars, setPathChars] = useState(PATH_MAX);
213
+ // biome-ignore lint/correctness/useExhaustiveDependencies: name, file and copied change the lines' natural widths
214
+ useLayoutEffect(() => {
215
+ const pill = pillRef.current;
216
+ if (!pill) return undefined;
217
+ const fit = () => {
218
+ // the column is the only part that shrinks (the rest is flex: none), so the pill less the column is fixed
219
+ const fixed =
220
+ pill.getBoundingClientRect().width - (textRef.current?.getBoundingClientRect().width ?? 0);
221
+ const avail = place.maxWidth - fixed;
222
+ const btn = pathRef.current;
223
+ let pathW = btn?.scrollWidth ?? 0;
224
+ let chars = PATH_MAX;
225
+ const shown = btn?.textContent ?? '';
226
+ const textW = btn && file && copied === 'no' && shown ? textWidthOf(btn) : 0;
227
+ if (btn && file && textW > 0) {
228
+ // the path is set in a monospace face: one character's width prices the whole path and what fits
229
+ const charW = textW / shown.length;
230
+ const pad = Math.max(0, btn.scrollWidth - textW);
231
+ pathW = charW * shortenCanvasPath(file).length + pad;
232
+ chars = Math.max(8, Math.min(PATH_MAX, Math.floor((avail - pad) / charW)));
233
+ }
234
+ const next = showPathLine(avail, titleRef.current?.scrollWidth ?? 0, pathW);
235
+ setPathShown((cur) => (cur === next ? cur : next));
236
+ setPathChars((cur) => (cur === chars ? cur : chars));
237
+ };
238
+ fit();
239
+ if (typeof ResizeObserver !== 'function') return undefined;
240
+ const ro = new ResizeObserver(fit); // Light | Dark and Canvas | Pages may change width after first paint
241
+ ro.observe(pill);
242
+ return () => ro.disconnect();
243
+ }, [place.maxWidth, name, file, copied]);
112
244
  return (
113
245
  <>
114
246
  <style data-dc-theme-pill-css="">{PILL_CSS}</style>
115
247
  <div
248
+ ref={pillRef}
116
249
  className="dc-theme-pill"
117
250
  data-dc-overlay=""
118
251
  data-testid="canvas-theme-pill"
252
+ data-band={place.banded ? 'band' : 'frame'}
253
+ data-path={file ? (pathShown ? 'shown' : 'hidden') : undefined}
254
+ style={{ left: `${place.left}px`, maxWidth: `${place.maxWidth}px` }}
119
255
  role="toolbar"
120
256
  aria-label="Canvas theme"
121
257
  >
122
258
  {name ? (
123
- <>
124
- <span className="dc-theme-pill-ic" aria-hidden="true">
125
- <DsIcon name="system" size={14} />
126
- </span>
127
- <b>{name}</b>
128
- </>
259
+ <span className="dc-theme-pill-ic" aria-hidden="true">
260
+ <DsIcon name="system" size={14} />
261
+ </span>
129
262
  ) : null}
130
- {file ? (
131
- <button
132
- type="button"
133
- className="dc-theme-pill-path"
134
- data-testid="canvas-theme-path"
135
- title={`Copy relative path — ${file}`}
136
- aria-label={`Copy relative path ${file}`}
137
- aria-live="polite"
138
- onClick={copyPath}
139
- >
140
- {copied === 'ok'
141
- ? 'Copied'
142
- : copied === 'failed'
143
- ? 'Couldn’t copy'
144
- : shortenCanvasPath(file)}
145
- </button>
263
+ {name || file ? (
264
+ <span ref={textRef} className="dc-theme-pill-text" data-testid="canvas-theme-text">
265
+ {name ? (
266
+ <b ref={titleRef} className="dc-theme-pill-title" data-testid="canvas-theme-title">
267
+ {name}
268
+ </b>
269
+ ) : null}
270
+ {file ? (
271
+ <button
272
+ ref={pathRef}
273
+ type="button"
274
+ className="dc-theme-pill-path"
275
+ data-testid="canvas-theme-path"
276
+ title={`Copy relative path — ${file}`}
277
+ aria-label={`Copy relative path ${file}`}
278
+ aria-live="polite"
279
+ onClick={copyPath}
280
+ >
281
+ {copied === 'ok'
282
+ ? 'Copied'
283
+ : copied === 'failed'
284
+ ? 'Couldn’t copy'
285
+ : shortenCanvasPath(file, pathChars)}
286
+ </button>
287
+ ) : null}
288
+ </span>
146
289
  ) : null}
147
290
  <fieldset className="dc-theme-pill-seg" aria-label="Show every artboard in">
148
291
  {(['light', 'dark'] as const).map((m) => (