@1agh/maude 2.0.2 → 2.0.3

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.
@@ -12,6 +12,12 @@
12
12
  //
13
13
  // Anything uncertain is "Not here yet", never Missing. Outside a shell (an export capture, a
14
14
  // headless screenshot) nothing is ever sent, so nothing is ever drawn — exports carry no frames.
15
+ //
16
+ // 2.0.3 — a Git LFS placeholder (`lfs-pointer`: the file here is a pointer, not the picture) says so
17
+ // in plain words. Where the shell can repair it (`lfsActions`, the desktop app's AI chat) the frame
18
+ // adds "Fix with AI" and "Copy prompt"; both only NAME the rel (`asset-lfs-fix-request`,
19
+ // `asset-lfs-copy-request`) — the shell builds the prompt from its own answer and does the clipboard
20
+ // write (this iframe has no clipboard rights), then answers `asset-lfs-copied` for the "Copied" word.
15
21
 
16
22
  import { useEffect, useMemo, useRef, useState } from 'react';
17
23
  import { createPortal } from 'react-dom';
@@ -21,11 +27,16 @@ import { type AssetStateItem, acceptFromShell } from './bridge/dgn-protocol.ts';
21
27
 
22
28
  /** What a frame says. `null` = draw nothing (the picture is here, or still uploading from here). */
23
29
  export interface FrameWords {
24
- state: 'waiting' | 'missing';
30
+ state: 'waiting' | 'missing' | 'lfs-pointer';
25
31
  line: string;
26
32
  relink: boolean;
27
33
  }
28
34
 
35
+ /** 2.0.3 — the line a Git LFS placeholder wears. */
36
+ export const LFS_LINE = 'Not downloaded — Git LFS placeholder';
37
+ /** How long "Copy prompt" reads "Copied" after the shell said it copied. */
38
+ export const LFS_COPIED_MS = 1500;
39
+
29
40
  const KIND_WORD = { mac: 'Mac', pc: 'PC', linux: 'computer' } as const;
30
41
 
31
42
  /**
@@ -43,6 +54,7 @@ function possessive(name: string): string {
43
54
  /** The §5.5 words. A name only, never an address: "Jonas's device" when the kind is unknown. */
44
55
  export function frameWords(item: AssetStateItem | undefined): FrameWords | null {
45
56
  if (!item || item.state === 'here' || item.state === 'uploading') return null;
57
+ if (item.state === 'lfs-pointer') return { state: 'lfs-pointer', line: LFS_LINE, relink: false };
46
58
  if (item.state === 'missing') {
47
59
  return { state: 'missing', line: 'Missing — no device has it', relink: RELINK_LIVE };
48
60
  }
@@ -209,6 +221,10 @@ const CSS = `
209
221
  .dc-absent-btn { pointer-events: auto; margin-top: 2px; padding: 3px 10px; border: 0; border-radius: 6px; cursor: pointer;
210
222
  font: inherit; font-weight: 600; background: var(--dc-absent-accent); color: var(--dc-absent-accent-fg); }
211
223
  .dc-absent-btn:focus-visible { outline: 2px solid var(--dc-absent-accent); outline-offset: 2px; }
224
+ .dc-absent[data-state="lfs-pointer"] { background-image: repeating-linear-gradient(135deg, var(--dc-absent-stripe) 0 2px, transparent 2px 9px);
225
+ box-shadow: inset 0 0 0 1px var(--dc-absent-edge); }
226
+ .dc-absent-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
227
+ .dc-absent-btn--quiet { background: transparent; color: var(--dc-absent-ink); box-shadow: inset 0 0 0 1px var(--dc-absent-edge); }
212
228
  `;
213
229
 
214
230
  function ensureStyles(): void {
@@ -246,21 +262,48 @@ export function AssetPlaceholderLayer({
246
262
  const [items, setItems] = useState<ReadonlyMap<string, AssetStateItem>>(new Map());
247
263
  const [frames, setFrames] = useState<Frame[]>([]);
248
264
  const nodes = useRef(new Map<string, HTMLDivElement>());
265
+ // 2.0.3: the shell can repair an LFS placeholder (its AI chat exists); rel → what Copy prompt says now.
266
+ const [lfsActions, setLfsActions] = useState(false);
267
+ const [copied, setCopied] = useState<ReadonlyMap<string, 'copied' | 'failed'>>(new Map());
268
+ const copiedTimers = useRef(new Map<string, ReturnType<typeof setTimeout>>());
249
269
 
250
270
  useEffect(() => {
251
271
  if (typeof window === 'undefined') return;
272
+ const timers = copiedTimers.current;
252
273
  const onMessage = (e: MessageEvent) => {
253
274
  // Only the shell may say it (DDR-054); the table parses it (≤ 256 items, no e-mail names).
254
275
  if (e.source !== window.parent) return;
255
- if ((e.data as { dgn?: string } | null)?.dgn !== 'asset-state') return;
276
+ const dgn = (e.data as { dgn?: string } | null)?.dgn;
277
+ if (dgn !== 'asset-state' && dgn !== 'asset-lfs-copied') return;
256
278
  const m = acceptFromShell(e, window);
257
279
  if (m && m.dgn === 'asset-state') {
258
280
  ensureStyles();
259
281
  setItems(new Map(m.items.map((it) => [it.rel, it])));
282
+ setLfsActions(m.lfsActions === true);
283
+ } else if (m && m.dgn === 'asset-lfs-copied') {
284
+ const rel = m.rel;
285
+ setCopied((prev) => new Map(prev).set(rel, m.ok ? 'copied' : 'failed'));
286
+ const old = timers.get(rel);
287
+ if (old) clearTimeout(old);
288
+ timers.set(
289
+ rel,
290
+ setTimeout(() => {
291
+ timers.delete(rel);
292
+ setCopied((prev) => {
293
+ const next = new Map(prev);
294
+ next.delete(rel);
295
+ return next;
296
+ });
297
+ }, LFS_COPIED_MS)
298
+ );
260
299
  }
261
300
  };
262
301
  window.addEventListener('message', onMessage);
263
- return () => window.removeEventListener('message', onMessage);
302
+ return () => {
303
+ window.removeEventListener('message', onMessage);
304
+ for (const t of timers.values()) clearTimeout(t);
305
+ timers.clear();
306
+ };
264
307
  }, []);
265
308
 
266
309
  // Which elements need a frame: rescanned on news, and on every media load / error (capture
@@ -413,66 +456,118 @@ export function AssetPlaceholderLayer({
413
456
  {bars}
414
457
  {createPortal(
415
458
  <div className="dc-absent-layer" data-testid="asset-frames">
416
- {frames.map((f) => (
417
- // biome-ignore lint/a11y/useAriaPropsSupportedByRole: role is `group` or `img` (both take a name)
418
- <div
419
- key={f.key}
420
- ref={(el) => {
421
- if (el) nodes.current.set(f.key, el);
422
- else nodes.current.delete(f.key);
423
- }}
424
- className="dc-absent"
425
- data-testid="asset-frame"
426
- data-rel={f.rel}
427
- data-state={f.words.state}
428
- data-lost={f.lost ? '1' : undefined}
429
- // gate-b-a11y: `img` cannot hold the Relink… button (axe nested-interactive) — a labelled group can
430
- role={f.words.relink ? 'group' : 'img'}
431
- aria-label={
432
- f.lost && f.words.line === LOST_VIDEO_LINE
433
- ? `${f.words.line} · ${f.rel}`
434
- : `${f.lost ? f.rel : baseName(f.rel)} · ${f.words.line}`
435
- }
436
- >
437
- <span className="dc-absent-in">
438
- <svg
439
- className="dc-absent-ic"
440
- width="16"
441
- height="16"
442
- viewBox="0 0 16 16"
443
- fill="none"
444
- stroke="currentColor"
445
- strokeWidth="1.4"
446
- strokeLinecap="round"
447
- strokeLinejoin="round"
448
- aria-hidden="true"
449
- >
450
- <path d="M8 2.2 14.2 13H1.8z" />
451
- <path d="M8 6.4v3.2" />
452
- <circle cx="8" cy="11.3" r="0.4" fill="currentColor" />
453
- </svg>
454
- <span className="dc-absent-n">{f.lost ? f.rel : baseName(f.rel)}</span>
455
- <span className="dc-absent-d">{f.words.line}</span>
456
- {f.words.relink ? (
457
- <button
458
- type="button"
459
- className="dc-absent-btn"
460
- data-testid="asset-frame-relink"
461
- onClick={() => {
462
- // A literal `{ dgn }` so the bridge inventory sees this send site.
463
- try {
464
- window.parent.postMessage({ dgn: 'asset-relink-request', rel: f.rel }, '*');
465
- } catch {
466
- /* detached */
467
- }
468
- }}
459
+ {frames.map((f) => {
460
+ const lfs = f.words.state === 'lfs-pointer' && lfsActions && !f.lost;
461
+ const copyWord = copied.get(f.rel);
462
+ return (
463
+ // biome-ignore lint/a11y/useAriaPropsSupportedByRole: role is `group` or `img` (both take a name)
464
+ <div
465
+ key={f.key}
466
+ ref={(el) => {
467
+ if (el) nodes.current.set(f.key, el);
468
+ else nodes.current.delete(f.key);
469
+ }}
470
+ className="dc-absent"
471
+ data-testid="asset-frame"
472
+ data-rel={f.rel}
473
+ data-state={f.words.state}
474
+ data-lost={f.lost ? '1' : undefined}
475
+ // gate-b-a11y: `img` cannot hold the Relink… button (axe nested-interactive) — a labelled group can
476
+ role={f.words.relink || lfs ? 'group' : 'img'}
477
+ aria-label={
478
+ f.lost && f.words.line === LOST_VIDEO_LINE
479
+ ? `${f.words.line} · ${f.rel}`
480
+ : `${f.lost ? f.rel : baseName(f.rel)} · ${f.words.line}`
481
+ }
482
+ >
483
+ <span className="dc-absent-in">
484
+ <svg
485
+ className="dc-absent-ic"
486
+ width="16"
487
+ height="16"
488
+ viewBox="0 0 16 16"
489
+ fill="none"
490
+ stroke="currentColor"
491
+ strokeWidth="1.4"
492
+ strokeLinecap="round"
493
+ strokeLinejoin="round"
494
+ aria-hidden="true"
469
495
  >
470
- Relink…
471
- </button>
472
- ) : null}
473
- </span>
474
- </div>
475
- ))}
496
+ <path d="M8 2.2 14.2 13H1.8z" />
497
+ <path d="M8 6.4v3.2" />
498
+ <circle cx="8" cy="11.3" r="0.4" fill="currentColor" />
499
+ </svg>
500
+ <span className="dc-absent-n">{f.lost ? f.rel : baseName(f.rel)}</span>
501
+ <span className="dc-absent-d">{f.words.line}</span>
502
+ {f.words.relink ? (
503
+ <button
504
+ type="button"
505
+ className="dc-absent-btn"
506
+ data-testid="asset-frame-relink"
507
+ onClick={() => {
508
+ // A literal `{ dgn }` so the bridge inventory sees this send site.
509
+ try {
510
+ window.parent.postMessage(
511
+ { dgn: 'asset-relink-request', rel: f.rel },
512
+ '*'
513
+ );
514
+ } catch {
515
+ /* detached */
516
+ }
517
+ }}
518
+ >
519
+ Relink…
520
+ </button>
521
+ ) : null}
522
+ {lfs ? (
523
+ <span className="dc-absent-row">
524
+ <button
525
+ type="button"
526
+ className="dc-absent-btn"
527
+ data-testid="asset-frame-lfs-fix"
528
+ onClick={() => {
529
+ // A literal `{ dgn }` so the bridge inventory sees this send site.
530
+ try {
531
+ window.parent.postMessage(
532
+ { dgn: 'asset-lfs-fix-request', rel: f.rel },
533
+ '*'
534
+ );
535
+ } catch {
536
+ /* detached */
537
+ }
538
+ }}
539
+ >
540
+ Fix with AI
541
+ </button>
542
+ <button
543
+ type="button"
544
+ className="dc-absent-btn dc-absent-btn--quiet"
545
+ data-testid="asset-frame-lfs-copy"
546
+ aria-live="polite"
547
+ onClick={() => {
548
+ // A literal `{ dgn }` so the bridge inventory sees this send site.
549
+ try {
550
+ window.parent.postMessage(
551
+ { dgn: 'asset-lfs-copy-request', rel: f.rel },
552
+ '*'
553
+ );
554
+ } catch {
555
+ /* detached */
556
+ }
557
+ }}
558
+ >
559
+ {copyWord === 'copied'
560
+ ? 'Copied'
561
+ : copyWord === 'failed'
562
+ ? 'Couldn’t copy'
563
+ : 'Copy prompt'}
564
+ </button>
565
+ </span>
566
+ ) : null}
567
+ </span>
568
+ </div>
569
+ );
570
+ })}
476
571
  </div>,
477
572
  document.body
478
573
  )}
@@ -439,12 +439,18 @@ export interface CanvasToShell {
439
439
  // S8.19 — the placeholder frame's Relink… (a Missing picture): the shell opens its relink sheet for
440
440
  // that rel. The canvas asks; the shell decides (the write is the shell's `asset.relink` edit op).
441
441
  'asset-relink-request': { rel: string };
442
+ // 2.0.3 — a Git LFS placeholder frame's two buttons (desktop only). The canvas only NAMES a rel; the
443
+ // shell checks it against its own asset-state answer (`lfs-pointer`) and builds the prompt itself.
444
+ 'asset-lfs-fix-request': { rel: string };
445
+ 'asset-lfs-copy-request': { rel: string };
442
446
  }
443
447
 
444
448
  /** S8.19 — one picture's state, as the shell tells the canvas (contract S8-S9-asset-presence §5.5). */
445
449
  export interface AssetStateItem {
446
450
  rel: string;
447
- state: 'here' | 'uploading' | 'waiting' | 'missing';
451
+ state: 'here' | 'uploading' | 'waiting' | 'missing' | 'lfs-pointer';
452
+ /** 2.0.3, `lfs-pointer` only: the real bytes are already in this repo's `.git/lfs/objects`. */
453
+ localObject?: boolean;
448
454
  /** A display name only — never an e-mail, never a device id. */
449
455
  who?: { name: string | null; kind: 'mac' | 'pc' | 'linux' | null; self: boolean };
450
456
  /** The hub already has the bytes; this Mac has not pulled them yet ("Syncing…"). */
@@ -747,7 +753,12 @@ export interface ShellToCanvas {
747
753
  // S8.19 — "Waiting for Jonas's Mac" vs Missing for the open canvas's media. State, not an event: the
748
754
  // shell sends the whole list on open, every 60 s while something waits, at reconnect and after a
749
755
  // sweep ends. ≤ 256 items; a name with an `@` is refused whole (the canvas never sees an e-mail).
750
- 'asset-state': { items: AssetStateItem[] };
756
+ // 2.0.3: `lfsActions` — this shell can repair a Git LFS placeholder (the desktop's AI chat), so its
757
+ // frame offers "Fix with AI" and "Copy prompt". Absent / false: the words only.
758
+ 'asset-state': { items: AssetStateItem[]; lfsActions?: boolean };
759
+ // 2.0.3 — the shell's answer to `asset-lfs-copy-request`: it wrote the prompt to the clipboard (`ok`)
760
+ // or could not. The frame's button reads "Copied" for a moment.
761
+ 'asset-lfs-copied': { rel: string; ok: boolean };
751
762
  // S8.16 — the pictures of the open canvas that have other takes (`assets/<sha8>.<ext>`): with one of them
752
763
  // selected, ← → are `take-step`, not a nudge. State, not an event: the whole set each time. ≤ 256 items,
753
764
  // each an asset path; a planted or oversized list is refused whole.
@@ -1188,7 +1199,8 @@ const assetWho = shape({
1188
1199
  });
1189
1200
  const assetStateItem = shape({
1190
1201
  rel: shortStr(512),
1191
- state: lit('here', 'uploading', 'waiting', 'missing'),
1202
+ state: lit('here', 'uploading', 'waiting', 'missing', 'lfs-pointer'),
1203
+ localObject: opt(bool),
1192
1204
  who: opt(assetWho),
1193
1205
  syncing: opt(bool),
1194
1206
  progress: opt(unit),
@@ -1939,6 +1951,18 @@ const c2s: C2S = {
1939
1951
  owner: 'client/v2/assets/asset-state-lane (S8.19)',
1940
1952
  parse: p({ rel: shortStr(512) }),
1941
1953
  },
1954
+ 'asset-lfs-fix-request': {
1955
+ gate: 'active',
1956
+ status: 'live',
1957
+ owner: 'client/v2/assets/asset-state-lane (2.0.3 LFS placeholder)',
1958
+ parse: p({ rel: shortStr(512) }),
1959
+ },
1960
+ 'asset-lfs-copy-request': {
1961
+ gate: 'active',
1962
+ status: 'live',
1963
+ owner: 'client/v2/assets/asset-state-lane (2.0.3 LFS placeholder)',
1964
+ parse: p({ rel: shortStr(512) }),
1965
+ },
1942
1966
  };
1943
1967
 
1944
1968
  const s2c: S2C = {
@@ -2565,7 +2589,13 @@ const s2c: S2C = {
2565
2589
  gate: 'parent',
2566
2590
  status: 'live',
2567
2591
  owner: 'canvas-lib asset placeholder frame (S8.19, L1)',
2568
- parse: p({ items: assetStateList }),
2592
+ parse: p({ items: assetStateList, lfsActions: opt(bool) }),
2593
+ },
2594
+ 'asset-lfs-copied': {
2595
+ gate: 'parent',
2596
+ status: 'live',
2597
+ owner: 'canvas-lib asset placeholder frame (2.0.3 LFS placeholder)',
2598
+ parse: p({ rel: shortStr(512), ok: bool }),
2569
2599
  },
2570
2600
  'gen-takes': {
2571
2601
  gate: 'parent',
@@ -3098,6 +3098,9 @@ function ShellTree() {
3098
3098
  const relink = useRelinkSheet({ canEdit: !viewerMode });
3099
3099
  useAssetStateLane({
3100
3100
  onRelink: relink.onRelink,
3101
+ // 2.0.3 — a Git LFS placeholder's Fix with AI / Copy prompt: where the error card offers Ask AI.
3102
+ askAiAvailable: isNativeApp() && !cfg?.readOnly,
3103
+ designRel: cfg?.designRel || cfg?.designRoot || '.design',
3101
3104
  syncStatus,
3102
3105
  wsConnected,
3103
3106
  canvasOrigin: () => cfg?.canvasOrigin || window.location.origin,
@@ -14,10 +14,22 @@
14
14
  // heard (origin + source gate). The canvas's string is only ever MATCHED against this lane's own
15
15
  // answer for that canvas (S8.19c): a rel the studio did not say is missing is dropped, so a canvas
16
16
  // cannot make the shell open a relink for a path of its choosing. `onRelink` gets the studio's rel.
17
+ //
18
+ // 2.0.3 — a Git LFS placeholder (`lfs-pointer`: the file is here, but it is a pointer, the project was
19
+ // cloned without `git lfs pull`). Where the AI chat exists (`lfsActions`, the desktop app) the frame
20
+ // offers "Fix with AI" (`asset-lfs-fix-request`) and "Copy prompt" (`asset-lfs-copy-request`). Same
21
+ // gate as Relink: the active canvas only, and only a rel this lane's own answer calls `lfs-pointer`.
22
+ // The prompt is built HERE from that answer (`lfsRepairPrompt`), never from canvas text. Fix with AI
23
+ // pre-fills the AI chat (the error card's "Ask AI" path, never sent); Copy prompt writes the clipboard
24
+ // here (the canvas iframe has no clipboard rights) and answers the frame `asset-lfs-copied {rel, ok}`
25
+ // so its button can say "Copied".
17
26
 
18
27
  import { useEffect, useRef, useSyncExternalStore } from 'react';
19
28
  import { acceptFromCanvas } from '../../../bridge/dgn-protocol.ts';
20
29
  import { INDEX_CHANGED_EVENT } from '../canvases/use-canvas-index.js';
30
+ import { nativeSave } from '../export/native-save.js';
31
+ import { dispatchCanvasOp } from '../left-panel/left-panel-bus.js';
32
+ import { ASK_AI_MAX } from '../search/search-env.js';
21
33
 
22
34
  /** canvas file → (rel → item): what the studio last said about each canvas. The relink gate and the
23
35
  * Inspector's absent-picture box read it; nothing else does. */
@@ -78,6 +90,96 @@ export function useAssetAnswers() {
78
90
  return useSyncExternalStore(subscribeAssetAnswers, assetAnswersVersion, assetAnswersVersion);
79
91
  }
80
92
 
93
+ /** The prompt lists at most this many paths, then "and N more". */
94
+ export const LFS_PROMPT_MAX_PATHS = 50;
95
+ const LFS_SPEC = 'version https://git-lfs.github.com/spec/v1';
96
+
97
+ /** `2026-11-04` in local time (the backup folder's name). */
98
+ function dayStamp(d) {
99
+ const pad = (n) => String(n).padStart(2, '0');
100
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
101
+ }
102
+
103
+ /**
104
+ * The repair prompt for a canvas's Git LFS placeholders. Built from the STUDIO's answer only: `items`
105
+ * are this lane's own items for the canvas; anything not `lfs-pointer` is ignored. Pure.
106
+ *
107
+ * It fits `maxChars` (default ASK_AI_MAX): Fix with AI pre-fills the chat through `sendToAskAI`, which
108
+ * keeps only that many chars, so a long path list would push the steps off the end. Paths are listed
109
+ * while they fit (at most LFS_PROMPT_MAX_PATHS); the rest are "…and N more", with how to find them.
110
+ *
111
+ * The restore goes through `git lfs` only (2.0.3 e2e): the design plugin's Bash guard refuses a `cp`
112
+ * into the design root and Write cannot put binary bytes back, so a prompt that said "copy the object
113
+ * over the placeholder" stopped after the backup. `git lfs checkout` restores a local object offline.
114
+ *
115
+ * @param {{ items: Iterable<any>, designRel?: string, date?: Date, maxChars?: number }} o
116
+ */
117
+ export function lfsRepairPrompt({
118
+ items,
119
+ designRel = '.design',
120
+ date = new Date(),
121
+ maxChars = ASK_AI_MAX,
122
+ }) {
123
+ const root = String(designRel || '')
124
+ .replace(/^\/+|\/+$/g, '')
125
+ .replace(/^\.\/?$/, '');
126
+ const inRoot = (rel) => (root ? `${root}/${rel}` : rel);
127
+ const ptrs = [];
128
+ for (const it of items) {
129
+ // a path is shown in backticks: one with a backtick or a line break is not listed
130
+ if (it?.state === 'lfs-pointer' && typeof it.rel === 'string' && !/[`\r\n]/.test(it.rel))
131
+ ptrs.push(it);
132
+ }
133
+ const backup = inRoot(`_trash/lfs-pointers-${dayStamp(date)}`);
134
+ const lineOf = (it) =>
135
+ `- \`${inRoot(it.rel)}\`${it.localObject ? ' (its object is already in .git/lfs/objects)' : ''}`;
136
+ const moreLine = (n) =>
137
+ `- …and ${n} more. Find the rest: every file of at most 1 KB under \`${root || '.'}/\` whose first line is exactly \`${LFS_SPEC}\`.`;
138
+ const head = [
139
+ 'Some pictures and videos in this project are Git LFS placeholders: small text files that stand where the real media should be (the project was cloned without `git lfs pull`). Please put the real files back.',
140
+ '',
141
+ 'The placeholder files, from the project root:',
142
+ ];
143
+ const steps = [
144
+ '',
145
+ 'Do this, step by step:',
146
+ `1. Back up the placeholder files first. Copy each one, keeping its path, into \`${backup}/\` (for example \`${inRoot('assets/a.png')}\` goes to \`${backup}/assets/a.png\`). That folder is ignored by git and never syncs.`,
147
+ '2. Restore them with Git LFS. Check it is installed with `git lfs version`; if it is not, say so (it installs with `brew install git-lfs`, then `git lfs install`) and stop. A file whose object is already in `.git/lfs/objects/<oid[0:2]>/<oid[2:4]>/<oid>` (the `oid sha256:<oid>` line of its pointer) comes back with `git lfs checkout <its path>`, with no network. For the ones left, run `git lfs pull --include "<their paths, comma-separated>"`; if that fails, say why. Do not copy or write the media files any other way.',
148
+ '3. Check each restored file: its sha256 must equal the oid, and its size must equal the `size <n>` line of its pointer. If one does not match, write its placeholder text back from the backup and tell me which file.',
149
+ '4. Do not commit anything, and do not change any other file.',
150
+ '5. Leave the restored files where they are. Maude uploads them by itself; there is nothing else to do.',
151
+ ];
152
+ // +1 per line for the joining '\n'
153
+ const len = (lines) => lines.reduce((n, l) => n + l.length + 1, -1);
154
+ const fixed = len([...head, ...steps]) + 1;
155
+ const lines = [];
156
+ let used = fixed;
157
+ for (const it of ptrs.slice(0, LFS_PROMPT_MAX_PATHS)) {
158
+ const line = lineOf(it);
159
+ const rest = ptrs.length - lines.length - 1;
160
+ // room for this line, and for the "…and N more" line if any are left after it
161
+ const need = line.length + 1 + (rest > 0 ? moreLine(rest).length + 1 : 0);
162
+ if (used + need > maxChars) break;
163
+ lines.push(line);
164
+ used += line.length + 1;
165
+ }
166
+ const more = ptrs.length - lines.length;
167
+ if (more > 0) lines.push(moreLine(more));
168
+ return [...head, ...lines, ...steps].join('\n');
169
+ }
170
+
171
+ /**
172
+ * Copy `text` from the shell; false when it was refused. The click was inside the canvas iframe, so the shell
173
+ * has no user activation: `navigator.clipboard` is tried briefly, then the desktop's `clipboard_write_text`.
174
+ */
175
+ async function shellCopyText(text) {
176
+ try {
177
+ return (await nativeSave().copyText(String(text))).ok === true;
178
+ } catch {
179
+ return false;
180
+ }
181
+ }
182
+
81
183
  const FRAME = 'iframe[data-testid="canvas-frame"]';
82
184
  export const ASSET_STATE_POLL_MS = 60_000;
83
185
  /** While something of this Mac's is still going up, ask again soon: the bar moves and goes away when the last byte lands. */
@@ -94,6 +196,11 @@ const pathOf = (frame) => frame?.getAttribute?.('data-path') || frame?.dataset?.
94
196
  * @param {() => Window | null} [deps.activeWindow] — the active canvas window (relink gate)
95
197
  * @param {() => string} deps.canvasOrigin
96
198
  * @param {(rel: string, canvas: string) => void} [deps.onRelink]
199
+ * @param {() => boolean} [deps.lfsActions] — this shell can repair an LFS placeholder (the AI chat exists)
200
+ * @param {() => string} [deps.designRel] — the design root, project-relative (the prompt's paths)
201
+ * @param {(prompt: string, canvas: string) => void} [deps.onLfsFix] — open the AI chat, pre-filled
202
+ * @param {(text: string) => Promise<boolean>} [deps.copyText]
203
+ * @param {() => Date} [deps.now]
97
204
  * @param {Window} [deps.win]
98
205
  * @param {(fn: () => void, ms: number) => unknown} [deps.setTimer]
99
206
  * @param {(t: unknown) => void} [deps.clearTimer]
@@ -105,6 +212,8 @@ export function createAssetStateLane(deps) {
105
212
  const win = deps.win ?? globalThis.window;
106
213
  const setTimer = deps.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
107
214
  const clearTimer = deps.clearTimer ?? ((t) => clearTimeout(t));
215
+ const lfsActions = () => deps.lfsActions?.() === true;
216
+ const copyText = deps.copyText ?? shellCopyText;
108
217
  /** Window → the JSON last said to it; `waiting` → whether it needs the 60 s poll. */
109
218
  const spoken = new WeakMap();
110
219
  const waiting = new Set();
@@ -143,14 +252,19 @@ export function createAssetStateLane(deps) {
143
252
  if (items.some((it) => it?.state === 'uploading')) uploading.add(canvas);
144
253
  else uploading.delete(canvas);
145
254
  arm();
146
- const json = JSON.stringify(items);
255
+ // The buttons are offered only where the AI chat exists, and only when there is a placeholder.
256
+ const offer = lfsActions() && items.some((it) => it?.state === 'lfs-pointer');
257
+ const json = JSON.stringify(offer ? [items, true] : items);
147
258
  const before = spoken.get(target);
148
259
  if (!force && before === json) return;
149
260
  if (before === undefined && items.length === 0) return;
150
261
  spoken.set(target, json);
151
262
  try {
152
263
  // A literal `{ dgn }` (not postToCanvas) so the bridge inventory sees this send site.
153
- target.postMessage({ dgn: 'asset-state', items }, deps.canvasOrigin() || '*');
264
+ target.postMessage(
265
+ offer ? { dgn: 'asset-state', items, lfsActions: true } : { dgn: 'asset-state', items },
266
+ deps.canvasOrigin() || '*'
267
+ );
154
268
  } catch {
155
269
  /* detached */
156
270
  }
@@ -182,6 +296,10 @@ export function createAssetStateLane(deps) {
182
296
  }
183
297
  return;
184
298
  }
299
+ if (dgn === 'asset-lfs-fix-request' || dgn === 'asset-lfs-copy-request') {
300
+ void onLfsRequest(e);
301
+ return;
302
+ }
185
303
  if (dgn !== 'asset-relink-request') return;
186
304
  const m = acceptFromCanvas(e, {
187
305
  canvasOrigin: deps.canvasOrigin(),
@@ -195,6 +313,39 @@ export function createAssetStateLane(deps) {
195
313
  const item = assetItemsFor(canvas).get(m.rel);
196
314
  if (item?.state === 'missing') deps.onRelink?.(item.rel, canvas);
197
315
  };
316
+ // 2.0.3 — Fix with AI / Copy prompt. The canvas names a rel; everything else is this lane's.
317
+ async function onLfsRequest(e) {
318
+ if (!lfsActions()) return;
319
+ const m = acceptFromCanvas(e, {
320
+ canvasOrigin: deps.canvasOrigin(),
321
+ active: deps.activeWindow?.() ?? null,
322
+ });
323
+ if (!m || (m.dgn !== 'asset-lfs-fix-request' && m.dgn !== 'asset-lfs-copy-request')) return;
324
+ const frame = frames().find((f) => f.contentWindow === e.source);
325
+ const canvas = pathOf(frame);
326
+ const mine = assetItemsFor(canvas);
327
+ const item = mine.get(m.rel);
328
+ if (!canvas || item?.state !== 'lfs-pointer') return;
329
+ const prompt = lfsRepairPrompt({
330
+ items: mine.values(),
331
+ designRel: deps.designRel?.() ?? '.design',
332
+ date: deps.now?.() ?? new Date(),
333
+ });
334
+ if (m.dgn === 'asset-lfs-fix-request') {
335
+ deps.onLfsFix?.(prompt, canvas);
336
+ return;
337
+ }
338
+ const ok = await copyText(prompt);
339
+ try {
340
+ // A literal `{ dgn }` so the bridge inventory sees this send site.
341
+ frame.contentWindow.postMessage(
342
+ { dgn: 'asset-lfs-copied', rel: item.rel, ok: ok === true },
343
+ deps.canvasOrigin() || '*'
344
+ );
345
+ } catch {
346
+ /* detached */
347
+ }
348
+ }
198
349
  win?.addEventListener?.('message', onMessage);
199
350
  // S8.14 — photos just placed from Finder reach the canvas file before their bytes reach the hub: when the index moves (the
200
351
  // placement is one), ask again shortly, so the new pictures hear `uploading` and wear a bar. One quiet read per burst.
@@ -238,7 +389,9 @@ export function assetStateTriggers(prev, next) {
238
389
 
239
390
  /**
240
391
  * Mount once in the shell. `syncStatus` / `wsConnected` are the app's live values; `onRelink` opens
241
- * the relink sheet for (rel, canvas).
392
+ * the relink sheet for (rel, canvas). `askAiAvailable` is the shell's answer the canvas error card
393
+ * uses (the desktop app's AI chat, not read-only): it alone turns on the LFS placeholder's buttons,
394
+ * and "Fix with AI" goes the error card's way — `ask-ai-fix` opens the chat with the prompt, unsent.
242
395
  */
243
396
  export function useAssetStateLane({
244
397
  syncStatus,
@@ -246,18 +399,30 @@ export function useAssetStateLane({
246
399
  canvasOrigin,
247
400
  activeWindow,
248
401
  onRelink,
402
+ askAiAvailable = false,
403
+ designRel = '.design',
249
404
  }) {
250
405
  const lane = useRef(null);
251
- const live = useRef({ canvasOrigin, activeWindow, onRelink });
252
- live.current = { canvasOrigin, activeWindow, onRelink };
406
+ const live = useRef({ canvasOrigin, activeWindow, onRelink, askAiAvailable, designRel });
407
+ live.current = { canvasOrigin, activeWindow, onRelink, askAiAvailable, designRel };
253
408
  useEffect(() => {
254
409
  lane.current = createAssetStateLane({
255
410
  canvasOrigin: () => live.current.canvasOrigin?.() ?? '',
256
411
  activeWindow: () => live.current.activeWindow?.() ?? null,
257
412
  onRelink: (rel, canvas) => live.current.onRelink?.(rel, canvas),
413
+ lfsActions: () => live.current.askAiAvailable === true,
414
+ designRel: () => live.current.designRel || '.design',
415
+ onLfsFix: (prompt, canvas) => dispatchCanvasOp('ask-ai-fix', canvas, prompt),
258
416
  });
259
417
  return () => lane.current?.stop();
260
418
  }, []);
419
+ // The answer can arrive after the first tell (config loads late): say it again with the buttons.
420
+ const askedAi = useRef(askAiAvailable);
421
+ useEffect(() => {
422
+ if (askedAi.current === askAiAvailable) return;
423
+ askedAi.current = askAiAvailable;
424
+ void lane.current?.refresh();
425
+ }, [askAiAvailable]);
261
426
  const prev = useRef(null);
262
427
  useEffect(() => {
263
428
  const next = { syncStatus, wsConnected };
@@ -54,17 +54,21 @@ export function AssetAbsentBox({ el, canvas, onReplace }) {
54
54
  const words = item ? frameWords(item) : null;
55
55
  if (!item || !words) return null;
56
56
  const missing = words.state === 'missing';
57
+ // 2.0.3 — a Git LFS placeholder: the file IS here, so Relink… has nothing to point at.
58
+ const lfs = words.state === 'lfs-pointer';
57
59
  return (
58
60
  <div className="asset-absent" data-testid="asset-absent-box" data-state={words.state}>
59
61
  <p className="asset-absent-t">
60
62
  <strong data-testid="asset-absent-word">{missing ? 'Missing' : words.line}</strong>
61
63
  </p>
62
64
  <p className="asset-absent-d">
63
- {missing
64
- ? 'No device has this file now. The rest of the design is safe.'
65
- : 'Not synced yet. Your design is safe — the picture fills in by itself.'}
65
+ {lfs
66
+ ? 'The file here is a Git LFS placeholder, not the picture. Run git lfs pull, or use Fix with AI on the picture.'
67
+ : missing
68
+ ? 'No device has this file now. The rest of the design is safe.'
69
+ : 'Not synced yet. Your design is safe — the picture fills in by itself.'}
66
70
  </p>
67
- {canEdit ? (
71
+ {canEdit && !lfs ? (
68
72
  <p className="asset-absent-a">
69
73
  {missing ? null : <span>Have it here?</span>}
70
74
  <button