@1agh/maude 2.0.2 → 2.0.4

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 (154) hide show
  1. package/README.md +6 -5
  2. package/apps/studio/access/request.ts +0 -1
  3. package/apps/studio/acp/adapter-stderr.ts +43 -13
  4. package/apps/studio/acp/background-tasks.ts +155 -0
  5. package/apps/studio/acp/bridge.ts +44 -5
  6. package/apps/studio/acp/connected-fact.ts +15 -4
  7. package/apps/studio/acp/index.ts +14 -5
  8. package/apps/studio/actions/agents.ts +5 -0
  9. package/apps/studio/actions/defs/view.ts +12 -0
  10. package/apps/studio/actions.manifest.json +13 -1
  11. package/apps/studio/actions.parity.json +7 -1
  12. package/apps/studio/api.ts +31 -24
  13. package/apps/studio/asset-placeholder.tsx +157 -62
  14. package/apps/studio/bin/_png-playwright.mjs +10 -1
  15. package/apps/studio/bin/_pw-launch.mjs +14 -0
  16. package/apps/studio/bin/_thumbs-playwright.mjs +4 -1
  17. package/apps/studio/boot-progress.ts +31 -0
  18. package/apps/studio/bridge/dgn-protocol.ts +34 -4
  19. package/apps/studio/canvas-build-sandbox.ts +275 -42
  20. package/apps/studio/canvas-build-worker.ts +10 -0
  21. package/apps/studio/canvas-create.ts +24 -0
  22. package/apps/studio/canvas-module-cache.ts +93 -0
  23. package/apps/studio/canvas-source/errors.ts +39 -0
  24. package/apps/studio/canvas-source/waiting.ts +290 -0
  25. package/apps/studio/client/actions/shell-key-handlers.js +5 -0
  26. package/apps/studio/client/app.jsx +22 -9
  27. package/apps/studio/client/github.js +23 -3
  28. package/apps/studio/client/home/home-api.js +30 -19
  29. package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
  30. package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
  31. package/apps/studio/client/hooks/use-tabs.jsx +64 -35
  32. package/apps/studio/client/index-loader.ts +23 -3
  33. package/apps/studio/client/panels/ChatPanel.jsx +22 -37
  34. package/apps/studio/client/panels/DiffView.jsx +314 -248
  35. package/apps/studio/client/panels/TeamProjects.jsx +119 -69
  36. package/apps/studio/client/panels/acp-runtime.js +25 -0
  37. package/apps/studio/client/panels/chat-finish.js +66 -0
  38. package/apps/studio/client/shell/frame-cap.js +53 -0
  39. package/apps/studio/client/shell/viewport.jsx +9 -0
  40. package/apps/studio/client/styles/_index.css +2 -0
  41. package/apps/studio/client/tree/tree.jsx +48 -21
  42. package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
  43. package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
  44. package/apps/studio/client/v2/ai/ai-run.css +87 -3
  45. package/apps/studio/client/v2/ai/background-model.js +113 -0
  46. package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
  47. package/apps/studio/client/v2/ai/run-api.js +7 -3
  48. package/apps/studio/client/v2/ai/runs-store.js +2 -1
  49. package/apps/studio/client/v2/annotations/vote-store.js +11 -5
  50. package/apps/studio/client/v2/assets/asset-state-lane.js +176 -8
  51. package/apps/studio/client/v2/assets/assets-bus.js +10 -8
  52. package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
  53. package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
  54. package/apps/studio/client/v2/assets/missing-frame.jsx +8 -4
  55. package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
  56. package/apps/studio/client/v2/assets/spotlight.css +153 -0
  57. package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
  58. package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
  59. package/apps/studio/client/v2/assets/tile.jsx +3 -0
  60. package/apps/studio/client/v2/assets/use-assets.js +2 -1
  61. package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
  62. package/apps/studio/client/v2/canvases/covers.js +11 -5
  63. package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
  64. package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
  65. package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
  66. package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
  67. package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
  68. package/apps/studio/client/v2/canvases/use-pins.js +2 -1
  69. package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
  70. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
  71. package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
  72. package/apps/studio/client/v2/code/code.css +67 -0
  73. package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
  74. package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
  75. package/apps/studio/client/v2/create/name-dialog.css +10 -0
  76. package/apps/studio/client/v2/ds/advanced-host.jsx +5 -2
  77. package/apps/studio/client/v2/ds/make-host.jsx +5 -2
  78. package/apps/studio/client/v2/ds/off-system-host.jsx +5 -2
  79. package/apps/studio/client/v2/ds/truth-host.jsx +5 -2
  80. package/apps/studio/client/v2/empty/arriving.jsx +29 -12
  81. package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
  82. package/apps/studio/client/v2/empty/not-local.jsx +31 -1
  83. package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
  84. package/apps/studio/client/v2/export/last-finished.js +2 -1
  85. package/apps/studio/client/v2/export/native-save.js +44 -0
  86. package/apps/studio/client/v2/history/git-model.js +18 -4
  87. package/apps/studio/client/v2/history/git-parts.jsx +60 -42
  88. package/apps/studio/client/v2/history/history.css +6 -0
  89. package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
  90. package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
  91. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
  92. package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
  93. package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
  94. package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
  95. package/apps/studio/client/v2/search/search-recent.js +3 -1
  96. package/apps/studio/client/v2/search/search-remote.js +6 -4
  97. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  98. package/apps/studio/client/v2/shell/menu-runner.js +1 -0
  99. package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
  100. package/apps/studio/client/v2/shell/recovery-store.js +2 -1
  101. package/apps/studio/client/v2/shell/served-routes.js +120 -0
  102. package/apps/studio/client/v2/shell/share-cluster-host.jsx +2 -1
  103. package/apps/studio/client/v2/shell/shell-activity.js +19 -0
  104. package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
  105. package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
  106. package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
  107. package/apps/studio/cloud/endpoints.ts +23 -1
  108. package/apps/studio/dist/client.bundle.js +798 -801
  109. package/apps/studio/dist/comment-mount.js +2 -2
  110. package/apps/studio/dist/styles.css +1 -1
  111. package/apps/studio/ds-assets.ts +138 -48
  112. package/apps/studio/editing/minimap-context.tsx +3 -3
  113. package/apps/studio/editing/page-activity.ts +251 -0
  114. package/apps/studio/editing/rotate-handle.tsx +9 -5
  115. package/apps/studio/editing/sticky-name.tsx +4 -4
  116. package/apps/studio/history/restore-artboard-action.ts +40 -0
  117. package/apps/studio/home/hub.ts +77 -175
  118. package/apps/studio/home/routes.ts +47 -8
  119. package/apps/studio/http.ts +117 -66
  120. package/apps/studio/index-flight.ts +40 -0
  121. package/apps/studio/managed-projects.ts +52 -24
  122. package/apps/studio/migrate/hub.ts +7 -1
  123. package/apps/studio/routes/asset-state.ts +12 -0
  124. package/apps/studio/routes/canvas-source.ts +44 -2
  125. package/apps/studio/routes/ds-assets.ts +8 -0
  126. package/apps/studio/routes/history.ts +28 -5
  127. package/apps/studio/routes/hub-signin.ts +115 -0
  128. package/apps/studio/routes/index.ts +4 -0
  129. package/apps/studio/routes/table.ts +7 -0
  130. package/apps/studio/routes/trash.ts +3 -0
  131. package/apps/studio/server.ts +11 -0
  132. package/apps/studio/sync/accepted-cold-start.ts +26 -3
  133. package/apps/studio/sync/accepted-link.ts +9 -4
  134. package/apps/studio/sync/asset-push.ts +8 -1
  135. package/apps/studio/sync/asset-state.ts +27 -2
  136. package/apps/studio/sync/code-module-consent.ts +74 -0
  137. package/apps/studio/sync/file-ledger.ts +35 -0
  138. package/apps/studio/sync/file-plane.ts +479 -84
  139. package/apps/studio/sync/hub-browser-signin.ts +377 -0
  140. package/apps/studio/sync/hub-text-undo.ts +30 -10
  141. package/apps/studio/sync/index.ts +73 -11
  142. package/apps/studio/sync/lfs-pointer.ts +137 -0
  143. package/apps/studio/sync/projection.ts +44 -2
  144. package/apps/studio/sync/pull-pacer.ts +160 -0
  145. package/apps/studio/sync/pull-priority.ts +119 -0
  146. package/apps/studio/sync/seed-progress.ts +47 -3
  147. package/apps/studio/sync/transaction-client.ts +71 -6
  148. package/apps/studio/sync/workspace-signin.ts +6 -256
  149. package/apps/studio/sync/writer-registry.ts +5 -1
  150. package/apps/studio/video-links-overlay.tsx +3 -2
  151. package/apps/studio/whats-new.json +63 -0
  152. package/cli/lib/design-help.gen.mjs +1 -1
  153. package/cli/lib/workspace-plan.mjs +14 -0
  154. package/package.json +8 -8
@@ -0,0 +1,152 @@
1
+ // client/v2/canvases/trash-queue.js — #194 (2.0.4): Move to trash answers at once, and several in a row all land.
2
+ //
3
+ // The report: "nothing happens for a while when I click the trash can … moving several canvases one after
4
+ // another doesn't do anything". Before, the row stayed as it was until `DELETE /_api/canvas` answered AND a
5
+ // whole fresh project index (`/_index-data`) had been read — and every new delete's tree refresh threw the
6
+ // read in flight away (`index-loader.ts`: a newer request wins), so three quick deletes showed nothing until
7
+ // the last read settled. On a Maude Cloud project each of those is a trip to the cell.
8
+ //
9
+ // Now every door (the row menu, ⌘K, the File menu) goes through ONE queue:
10
+ // 1. the row says "Moving to trash…" and fades the moment it is asked (a `trash` row slot, row-slots.js);
11
+ // 2. the moves go out one at a time, in the order asked — none is dropped, a second ask for the same canvas
12
+ // while it is waiting is the same move;
13
+ // 3. the server's yes takes the row out of the list at once (`gone`, the panel hides it) and the toast with
14
+ // Undo shows; the list then re-reads, and the row stays out once the index agrees;
15
+ // 4. a refusal brings the row back as it was, and the toast says why (TRASH_WORDS.failed).
16
+ // Undo is unchanged (trash-canvas.js).
17
+
18
+ import { useSyncExternalStore } from 'react';
19
+
20
+ import { registerRowSlot } from './row-slots.js';
21
+ import { trashCanvas } from './trash-canvas.js';
22
+
23
+ export const TRASH_QUEUE_WORDS = Object.freeze({
24
+ moving: 'Moving to trash…',
25
+ });
26
+
27
+ /** How long a confirmed move keeps its row hidden after the list re-read, so the fresh list lands first. */
28
+ export const GONE_SETTLE_MS = 400;
29
+
30
+ /**
31
+ * A queue of canvas moves to the trash, with its own small store: which canvases are on their way
32
+ * (`moving`) and which the server has taken (`gone`).
33
+ * @param {{ settleMs?: number, slot?: typeof registerRowSlot }} [opts]
34
+ */
35
+ export function createTrashQueue({ settleMs = GONE_SETTLE_MS, slot = registerRowSlot } = {}) {
36
+ /** path → { state: 'moving' | 'gone', dispose?: () => void } */
37
+ const items = new Map();
38
+ const listeners = new Set();
39
+ let gone = Object.freeze(new Set());
40
+ let chain = Promise.resolve();
41
+
42
+ const publish = () => {
43
+ gone = Object.freeze(
44
+ new Set([...items].filter(([, it]) => it.state === 'gone').map(([p]) => p))
45
+ );
46
+ for (const fn of [...listeners]) fn();
47
+ };
48
+ const forget = (path) => {
49
+ const it = items.get(path);
50
+ if (!it) return;
51
+ it.dispose?.();
52
+ items.delete(path);
53
+ publish();
54
+ };
55
+
56
+ /**
57
+ * Ask for one move. `run({ path, label, removed })` does the move and calls `removed()` the moment the
58
+ * server has taken it; it resolves `{ ok }` when it is completely done (list re-read included).
59
+ * @returns {Promise<{ ok: boolean, error?: string, queued?: boolean }>}
60
+ */
61
+ function enqueue({ path, label, rel }, run) {
62
+ if (typeof path !== 'string' || !path) return Promise.resolve({ ok: false });
63
+ if (items.has(path)) return Promise.resolve({ ok: true, queued: true });
64
+ const dispose = slot(
65
+ 'trash',
66
+ rel || path,
67
+ Object.freeze({ sub: { text: TRASH_QUEUE_WORDS.moving, icon: 'trash' }, dim: true })
68
+ );
69
+ items.set(path, { state: 'moving', dispose });
70
+ publish();
71
+ let finish;
72
+ const result = new Promise((resolve) => {
73
+ finish = resolve;
74
+ });
75
+ // The queue moves on once the SERVER has answered this move — it never waits on the list re-read.
76
+ chain = chain.then(
77
+ () =>
78
+ new Promise((answered) => {
79
+ const removed = () => {
80
+ const it = items.get(path);
81
+ if (it && it.state === 'moving') {
82
+ it.dispose?.();
83
+ items.set(path, { state: 'gone' });
84
+ publish();
85
+ }
86
+ answered();
87
+ };
88
+ Promise.resolve()
89
+ .then(() => run({ path, label, removed }))
90
+ .catch(() => ({ ok: false }))
91
+ .then((res) => {
92
+ answered();
93
+ if (res?.ok) setTimeout(() => forget(path), settleMs);
94
+ else forget(path); // the row comes back as it was
95
+ finish(res ?? { ok: false });
96
+ });
97
+ })
98
+ );
99
+ return result;
100
+ }
101
+
102
+ return {
103
+ enqueue,
104
+ /** Canvases the server has taken whose row is still listed until the list re-reads. */
105
+ gone: () => gone,
106
+ stateOf: (path) => items.get(path)?.state ?? null,
107
+ subscribe(fn) {
108
+ listeners.add(fn);
109
+ return () => listeners.delete(fn);
110
+ },
111
+ /** Forget everything (tests, a project switch). */
112
+ reset() {
113
+ for (const it of items.values()) it.dispose?.();
114
+ items.clear();
115
+ chain = Promise.resolve();
116
+ publish();
117
+ },
118
+ };
119
+ }
120
+
121
+ /** The window's one queue. */
122
+ export const trashQueue = createTrashQueue();
123
+
124
+ /** The panel's hook: the set of repo paths to leave out of the list until the index agrees. */
125
+ export function useTrashGone(queue = trashQueue) {
126
+ return useSyncExternalStore(queue.subscribe, queue.gone, queue.gone);
127
+ }
128
+
129
+ /**
130
+ * `groups` (the `/_index-data` groups) without the canvases the server has taken: the canvas and its
131
+ * same-name sidecars (`<name>.meta.json` …) leave every group's `paths`, so folder counts follow.
132
+ */
133
+ export function withoutGone(groups, gone) {
134
+ if (!gone?.size || !Array.isArray(groups)) return groups;
135
+ const prefixes = [...gone].map((p) => p.replace(/\.tsx$/i, '.'));
136
+ const hidden = (p) => gone.has(p) || prefixes.some((pre) => p.startsWith(pre));
137
+ return groups.map((g) =>
138
+ Array.isArray(g.paths) && g.paths.some(hidden)
139
+ ? { ...g, paths: g.paths.filter((p) => !hidden(p)) }
140
+ : g
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Move one canvas to the trash through the queue: the shell's `deleteBoard`. Same arguments as
146
+ * `trashCanvas`, plus `rel` (the designRoot-relative path the row slots are keyed by) and `queue`.
147
+ */
148
+ export function queueTrashCanvas({ queue = trashQueue, path, label, rel, ...rest }) {
149
+ return queue.enqueue({ path, label, rel }, ({ removed }) =>
150
+ trashCanvas({ ...rest, path, label, onRemoved: removed })
151
+ );
152
+ }
@@ -8,6 +8,7 @@
8
8
  // no index (an older server, a cloud tab that does not serve it) the panel is simply without badges.
9
9
 
10
10
  import { useEffect, useRef, useState } from 'react';
11
+ import { fetchIfServed } from '../shell/served-routes.js';
11
12
 
12
13
  /** The shell's relay of the socket's `index-changed { seq, rels }` (client/app.jsx). */
13
14
  export const INDEX_CHANGED_EVENT = 'maude:index-changed';
@@ -23,27 +24,50 @@ export function useCanvasIndex({ stamp, fetchImpl } = {}) {
23
24
  const fetchRef = useRef(fetchImpl || ((...a) => fetch(...a)));
24
25
  fetchRef.current = fetchImpl || fetchRef.current;
25
26
  const seq = useRef(0);
26
-
27
- // biome-ignore lint/correctness/useExhaustiveDependencies: `stamp` and `moved` are the "something changed" signals
27
+ // #204 R — ONE read at a time. A change that lands while a read is out asks once more after it (with
28
+ // `?since=`), instead of dropping that answer and asking the whole index again: on boot the tree stamp
29
+ // moves several times inside the first read, and each move used to discard it and ask anew (7 full reads
30
+ // per load against a cell, where the route is withheld anyway — `fetchIfServed` no longer asks it there).
31
+ const flight = useRef({ busy: false, again: false, alive: true });
28
32
  useEffect(() => {
29
- let cancelled = false;
30
- const t = setTimeout(async () => {
31
- try {
32
- const url = seq.current ? `/_api/index?since=${seq.current}` : '/_api/index';
33
- const r = await fetchRef.current(url, { cache: 'no-store' });
34
- if (!r.ok || cancelled) return;
35
- const data = await r.json();
36
- if (cancelled || data?.unchanged || !Array.isArray(data?.canvases)) return;
37
- seq.current = data.writer?.seq || 0;
38
- setSnapshot(data);
39
- } catch {
40
- /* no index: no badges */
41
- }
42
- }, 200);
33
+ const f = flight.current;
34
+ f.alive = true;
43
35
  return () => {
44
- cancelled = true;
45
- clearTimeout(t);
36
+ f.alive = false;
46
37
  };
38
+ }, []);
39
+ const read = useRef(null);
40
+ read.current ??= async () => {
41
+ const f = flight.current;
42
+ if (f.busy) {
43
+ f.again = true;
44
+ return;
45
+ }
46
+ f.busy = true;
47
+ try {
48
+ do {
49
+ f.again = false;
50
+ const url = seq.current ? `/_api/index?since=${seq.current}` : '/_api/index';
51
+ const r = await fetchIfServed(url, { cache: 'no-store' }, fetchRef.current);
52
+ if (!r.ok || !f.alive) break; // not here (or refused): asking again cannot help
53
+ const data = await r.json();
54
+ if (!f.alive) break;
55
+ if (!data?.unchanged && Array.isArray(data?.canvases)) {
56
+ seq.current = data.writer?.seq || 0;
57
+ setSnapshot(data);
58
+ }
59
+ } while (f.again);
60
+ } catch {
61
+ /* no index: no badges */
62
+ } finally {
63
+ f.busy = false;
64
+ }
65
+ };
66
+
67
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `stamp` and `moved` are the "something changed" signals
68
+ useEffect(() => {
69
+ const t = setTimeout(() => read.current(), 200);
70
+ return () => clearTimeout(t);
47
71
  }, [stamp, moved]);
48
72
 
49
73
  return snapshot;
@@ -7,6 +7,7 @@
7
7
  // "Recently opened" sort uses it when it is there and falls back to when a canvas last changed.
8
8
 
9
9
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
10
+ import { fetchIfServed } from '../shell/served-routes.js';
10
11
 
11
12
  /** The list with `rel` pinned or unpinned — a new array, pin order kept (oldest first). */
12
13
  export function withPin(pins, rel, pinned, at = Date.now()) {
@@ -34,7 +35,7 @@ export function usePins({ stamp, fetchImpl } = {}) {
34
35
 
35
36
  const load = useCallback(async () => {
36
37
  try {
37
- const r = await fetchRef.current('/_api/pins', { cache: 'no-store' });
38
+ const r = await fetchIfServed('/_api/pins', { cache: 'no-store' }, fetchRef.current);
38
39
  if (!r.ok) return;
39
40
  setState({ ...normalisePins(await r.json()), loaded: true });
40
41
  } catch {
@@ -21,7 +21,10 @@ import { useEffect, useRef, useState } from 'react';
21
21
  import { StIcon } from '../../shell/icons.jsx';
22
22
  import { AdvancedFold } from '../fold/advanced-fold.jsx';
23
23
  import { Check, Copy, Spark } from '../ai/icons.jsx';
24
+ import { INDEX_CHANGED_EVENT } from '../canvases/use-canvas-index.js';
24
25
  import { projectRel } from '../shell/native-doors.js';
26
+ import { BUILD_FAILURE_BODY, buildFailureReason } from './canvas-waiting.js';
27
+ import { CanvasBuildingCard, CanvasWaitingCard } from './canvas-waiting-card.jsx';
25
28
  import { registerErrorCard } from './code-bus.js';
26
29
  import {
27
30
  askAiText,
@@ -36,6 +39,8 @@ import {
36
39
  } from './use-canvas-source.js';
37
40
 
38
41
  const pad2 = (n) => String(n).padStart(2, '0');
42
+ /** 2.0.4 — the waiting card re-asks this often (a landed file re-asks at once, via the index). */
43
+ export const WAITING_WATCH_MS = 4000;
39
44
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
40
45
 
41
46
  /** "14:05" (24 hour, local). */
@@ -53,7 +58,7 @@ export function whenLabel(at) {
53
58
  }
54
59
 
55
60
  /** The card's sentence under the title. */
56
- export function cardBody({ kind, error, lastGood }) {
61
+ export function cardBody({ kind, error, lastGood, buildFailure = null }) {
57
62
  const tail = 'Other canvases are fine; the last good version is in Version history.';
58
63
  if (kind === 'render') {
59
64
  const when = lastGood ? whenLabel(lastGood.at) : '';
@@ -62,6 +67,8 @@ export function cardBody({ kind, error, lastGood }) {
62
67
  : "The last change has a mistake the canvas can't show. Nothing is lost; every version stays in Version history.";
63
68
  }
64
69
  // 01 cf-render-error: the body is one plain sentence; the error and the line live under Show details
70
+ // #189 — the build stopped on the app's side (engine, time, memory, refused imports): not the code
71
+ if (!error && buildFailure) return BUILD_FAILURE_BODY;
65
72
  // the load gave up and the server knows of no mistake in the code: say that, not a guess about it
66
73
  if (!error)
67
74
  return "It didn't finish loading. Nothing is lost. Reload the canvas, or ask AI to look.";
@@ -143,10 +150,14 @@ export function CanvasErrorCard({
143
150
  onReload,
144
151
  onCopy,
145
152
  askAiAvailable = true,
153
+ /** #189 — the build stopped outside the code (`{ class, count? }`): no Ask AI, the reason under the fold. */
154
+ buildFailure = null,
146
155
  /** The fold starts open (a test / a caller that wants the details up front). */
147
156
  detailsOpen = false,
148
157
  }) {
149
158
  const [open, setOpen] = useState(detailsOpen);
159
+ // AI can't fix the app's own build: Ask AI is offered only when the cause may be the code
160
+ const offerAi = askAiAvailable && !(buildFailure && !error);
150
161
  const name = canvasTitle(canvas);
151
162
  const where = whereLabel(error);
152
163
  const excerpt = excerptOf(error, lines);
@@ -155,7 +166,16 @@ export function CanvasErrorCard({
155
166
  // The registry's three card actions (canvas.copy-error · canvas.ask-ai-fix · canvas.last-good) reach the
156
167
  // card that is showing through the bus; a ref keeps the newest props without re-registering.
157
168
  const live = useRef({});
158
- live.current = { canvas, kind, error, lastGood, onAskAi, onGoBack, onCopy, askAiAvailable };
169
+ live.current = {
170
+ canvas,
171
+ kind,
172
+ error,
173
+ lastGood,
174
+ onAskAi,
175
+ onGoBack,
176
+ onCopy,
177
+ askAiAvailable: offerAi,
178
+ };
159
179
  useEffect(
160
180
  () =>
161
181
  registerErrorCard({
@@ -191,7 +211,7 @@ export function CanvasErrorCard({
191
211
  </h2>
192
212
  </header>
193
213
  <p className="v2-err-d" data-testid="canvas-error-body">
194
- {cardBody({ kind, error, lastGood })}
214
+ {cardBody({ kind, error, lastGood, buildFailure })}
195
215
  </p>
196
216
  {lastGood ? (
197
217
  <p className="v2-err-lg" data-testid="canvas-error-last-good-line">
@@ -209,7 +229,7 @@ export function CanvasErrorCard({
209
229
  {clock ? `Go back to ${clock}` : 'Go back'}
210
230
  </button>
211
231
  ) : null}
212
- {askAiAvailable && onAskAi ? (
232
+ {offerAi && onAskAi ? (
213
233
  <button
214
234
  type="button"
215
235
  className="btn btn--sm btn--spark"
@@ -247,6 +267,13 @@ export function CanvasErrorCard({
247
267
  ) : null}
248
268
  <ErrorExcerpt excerpt={excerpt} />
249
269
  </>
270
+ ) : buildFailure ? (
271
+ <div className="v2-err-row">
272
+ <span className="v2-err-k">Reason</span>
273
+ <span className="v2-err-v" data-testid="canvas-error-build-reason">
274
+ {buildFailureReason(buildFailure)}
275
+ </span>
276
+ </div>
250
277
  ) : (
251
278
  <p className="v2-err-none" data-testid="canvas-error-none">
252
279
  No details were reported. Reload the canvas, or ask AI to look.
@@ -359,10 +386,44 @@ export function CanvasLoadFailure({
359
386
  onNotify,
360
387
  onCopy,
361
388
  fetchImpl,
389
+ /** How often the waiting card re-asks (a file landing also re-asks at once). */
390
+ watchMs = WAITING_WATCH_MS,
362
391
  }) {
363
- const err = useCanvasError({ canvas, fetchImpl });
392
+ const [stamp, setStamp] = useState(0);
393
+ const err = useCanvasError({ canvas, stamp, quiet: true, fetchImpl });
364
394
  const ghosts = useGhostBoxes({ canvas, fetchImpl });
365
395
  const error = err.status === 'ok' ? err.error : null;
396
+ const waiting = err.status === 'ok' ? err.waiting : null;
397
+ const buildFailure = err.status === 'ok' ? err.buildFailure : null;
398
+ // 2.0.4 task P — its build is still running on the server (no file is missing, nothing failed)
399
+ const building = err.status === 'ok' && !error && !waiting && err.building === true;
400
+ // 2.0.4 — while it waits for files (or, task P, for its build), watch: re-ask when the project index
401
+ // moves (a file landed) and on a modest timer, and load the canvas by itself the moment nothing is
402
+ // missing any more. This is not a retry of a failure (CONTRACT C20): the cause it named went away.
403
+ const waitingNow = !!waiting || building;
404
+ useEffect(() => {
405
+ if (!waitingNow) return undefined;
406
+ const again = () => setStamp((n) => n + 1);
407
+ const timer = setInterval(again, watchMs);
408
+ globalThis.addEventListener?.(INDEX_CHANGED_EVENT, again);
409
+ return () => {
410
+ clearInterval(timer);
411
+ globalThis.removeEventListener?.(INDEX_CHANGED_EVENT, again);
412
+ };
413
+ }, [waitingNow, watchMs]);
414
+ const wasWaiting = useRef(false);
415
+ const reloadRef = useRef(onReload);
416
+ reloadRef.current = onReload;
417
+ useEffect(() => {
418
+ if (err.status !== 'ok') return;
419
+ if (err.waiting || (err.building && !err.error)) wasWaiting.current = true;
420
+ else if (wasWaiting.current) {
421
+ wasWaiting.current = false;
422
+ // a build that stopped (past its ceiling, out of memory …) stays on the card that says why: a
423
+ // reload would only start the same build again
424
+ if (!err.buildFailure && !err.error) reloadRef.current?.();
425
+ }
426
+ }, [err]);
366
427
  // Context lines come from the source — for people who may read it (Can view gets the one quoted line).
367
428
  const src = useCanvasSource({ canvas, enabled: !!error?.line, fetchImpl });
368
429
  const lines = src.status === 'ok' ? src.lines : null;
@@ -387,6 +448,9 @@ export function CanvasLoadFailure({
387
448
  </p>
388
449
  );
389
450
  }
451
+ // files it imports haven't reached this Mac, or are held back: not a mistake in its code
452
+ if (waiting) return <CanvasWaitingCard canvas={canvas} waiting={waiting} />;
453
+ if (building) return <CanvasBuildingCard canvas={canvas} />;
390
454
  return (
391
455
  <>
392
456
  <LastGoodGhosts boxes={ghosts} />
@@ -401,6 +465,7 @@ export function CanvasLoadFailure({
401
465
  onGoBack={canEdit ? goBack : undefined}
402
466
  onReload={onReload}
403
467
  onCopy={onCopy}
468
+ buildFailure={buildFailure}
404
469
  />
405
470
  </>
406
471
  );
@@ -0,0 +1,128 @@
1
+ // client/v2/code/canvas-waiting-card.jsx — 2.0.4 task B: the card for a canvas that can't load YET,
2
+ // because files it imports haven't reached this Mac (first sync) or are held back (a refusal).
3
+ //
4
+ // waiting "Uniformy-2027 is still downloading." · a bar of the files this canvas needs (3 of 5
5
+ // files) · the project's sync (Project sync: 5,029 of 5,041 files) · the names it waits
6
+ // for (five, then "and N more"). No button: the canvas opens by itself when they land
7
+ // (CanvasLoadFailure watches and reloads it).
8
+ // refused "Uniformy-2027 can't open on this Mac yet." · why, in plain words; for the code consent,
9
+ // linking the folder again (the link asks — Settings has no per-hub consent row, and a
10
+ // Maude Cloud project opened from Home accepts by itself). No "Ask AI to fix it": AI can't change a
11
+ // sync consent, and nothing in the code is wrong.
12
+ //
13
+ // Same card frame as the broken-canvas card (`.v2-err`); the words are canvas-waiting.js's.
14
+
15
+ import { StIcon } from '../../shell/icons.jsx';
16
+ import {
17
+ BUILDING_BODY,
18
+ baseName,
19
+ buildingTitle,
20
+ fileNote,
21
+ moreCount,
22
+ needLabel,
23
+ projectLabel,
24
+ refusedFile,
25
+ SHOWN_FILES,
26
+ waitingBody,
27
+ waitingTitle,
28
+ } from './canvas-waiting.js';
29
+ import { canvasTitle } from './use-canvas-source.js';
30
+
31
+ export function CanvasWaitingCard({ canvas, waiting }) {
32
+ const name = canvasTitle(canvas);
33
+ const held = !!refusedFile(waiting);
34
+ const { need, progress } = waiting;
35
+ const shown = waiting.files.slice(0, SHOWN_FILES);
36
+ const more = moreCount(waiting);
37
+ const pct = need ? Math.round((need.here / need.total) * 100) : 0;
38
+ return (
39
+ <section
40
+ className="v2-err v2-err--waiting"
41
+ aria-labelledby="v2-err-title"
42
+ data-testid="canvas-waiting-card"
43
+ data-kind={held ? 'refused' : 'waiting'}
44
+ aria-live="polite"
45
+ >
46
+ <header className="v2-err-hd">
47
+ <span className={`v2-err-ic${held ? '' : ' v2-err-ic--calm'}`} aria-hidden="true">
48
+ <StIcon name={held ? 'lock' : 'sync'} size={20} />
49
+ </span>
50
+ <h2 className="v2-err-t" id="v2-err-title" data-testid="canvas-waiting-title">
51
+ {waitingTitle(name, waiting)}
52
+ </h2>
53
+ </header>
54
+ <p className="v2-err-d" data-testid="canvas-waiting-body">
55
+ {waitingBody(waiting)}
56
+ </p>
57
+ {need && !held ? (
58
+ <div className="v2-err-prog" data-testid="canvas-waiting-progress">
59
+ <span
60
+ className="v2-err-bar"
61
+ role="progressbar"
62
+ aria-label={`Files ${name} needs`}
63
+ aria-valuemin={0}
64
+ aria-valuemax={need.total}
65
+ aria-valuenow={need.here}
66
+ aria-valuetext={needLabel(need)}
67
+ >
68
+ <i style={{ width: `${pct}%` }} />
69
+ </span>
70
+ <span className="v2-err-prog-l">{needLabel(need)}</span>
71
+ </div>
72
+ ) : null}
73
+ {progress && !held ? (
74
+ <p className="v2-err-lg" data-testid="canvas-waiting-project">
75
+ {projectLabel(progress)}
76
+ </p>
77
+ ) : null}
78
+ {shown.length > (held ? 1 : 0) ? (
79
+ <div className="v2-err-files">
80
+ <span className="v2-err-files-h">Waiting for</span>
81
+ <ul className="v2-err-files-l" data-testid="canvas-waiting-files">
82
+ {shown.map((f) => (
83
+ <li key={f.rel} className="v2-err-file" title={f.rel}>
84
+ <span className="v2-err-file-n">{baseName(f.rel)}</span>
85
+ {fileNote(f) ? <span className="v2-err-file-s">{fileNote(f)}</span> : null}
86
+ </li>
87
+ ))}
88
+ {more > 0 ? (
89
+ <li className="v2-err-file v2-err-file--more" data-testid="canvas-waiting-more">
90
+ and {more} more
91
+ </li>
92
+ ) : null}
93
+ </ul>
94
+ </div>
95
+ ) : null}
96
+ </section>
97
+ );
98
+ }
99
+
100
+ /**
101
+ * 2.0.4 task P — its build is still running (it outlived the request that started it; a big canvas
102
+ * on a busy server). Not a failure: no Ask AI, no Reload. CanvasLoadFailure watches and loads the
103
+ * canvas by itself when the build is done; a build that died past its ceiling turns into the
104
+ * ordinary "can't be drawn" card with "The build timed out" under Show details.
105
+ */
106
+ export function CanvasBuildingCard({ canvas }) {
107
+ return (
108
+ <section
109
+ className="v2-err v2-err--waiting"
110
+ aria-labelledby="v2-err-title"
111
+ data-testid="canvas-waiting-card"
112
+ data-kind="building"
113
+ aria-live="polite"
114
+ >
115
+ <header className="v2-err-hd">
116
+ <span className="v2-err-ic v2-err-ic--calm" aria-hidden="true">
117
+ <StIcon name="sync" size={20} />
118
+ </span>
119
+ <h2 className="v2-err-t" id="v2-err-title" data-testid="canvas-waiting-title">
120
+ {buildingTitle(canvas, canvasTitle(canvas))}
121
+ </h2>
122
+ </header>
123
+ <p className="v2-err-d" data-testid="canvas-waiting-body">
124
+ {BUILDING_BODY}
125
+ </p>
126
+ </section>
127
+ );
128
+ }