@1agh/maude 2.0.3 → 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 (143) 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/bin/_png-playwright.mjs +10 -1
  14. package/apps/studio/bin/_pw-launch.mjs +14 -0
  15. package/apps/studio/bin/_thumbs-playwright.mjs +4 -1
  16. package/apps/studio/boot-progress.ts +31 -0
  17. package/apps/studio/canvas-build-sandbox.ts +275 -42
  18. package/apps/studio/canvas-build-worker.ts +10 -0
  19. package/apps/studio/canvas-create.ts +24 -0
  20. package/apps/studio/canvas-module-cache.ts +93 -0
  21. package/apps/studio/canvas-source/errors.ts +39 -0
  22. package/apps/studio/canvas-source/waiting.ts +290 -0
  23. package/apps/studio/client/actions/shell-key-handlers.js +5 -0
  24. package/apps/studio/client/app.jsx +19 -9
  25. package/apps/studio/client/github.js +23 -3
  26. package/apps/studio/client/home/home-api.js +30 -19
  27. package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
  28. package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
  29. package/apps/studio/client/hooks/use-tabs.jsx +64 -35
  30. package/apps/studio/client/index-loader.ts +23 -3
  31. package/apps/studio/client/panels/ChatPanel.jsx +22 -37
  32. package/apps/studio/client/panels/DiffView.jsx +314 -248
  33. package/apps/studio/client/panels/TeamProjects.jsx +119 -69
  34. package/apps/studio/client/panels/acp-runtime.js +25 -0
  35. package/apps/studio/client/panels/chat-finish.js +66 -0
  36. package/apps/studio/client/shell/frame-cap.js +53 -0
  37. package/apps/studio/client/shell/viewport.jsx +9 -0
  38. package/apps/studio/client/styles/_index.css +2 -0
  39. package/apps/studio/client/tree/tree.jsx +48 -21
  40. package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
  41. package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
  42. package/apps/studio/client/v2/ai/ai-run.css +87 -3
  43. package/apps/studio/client/v2/ai/background-model.js +113 -0
  44. package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
  45. package/apps/studio/client/v2/ai/run-api.js +7 -3
  46. package/apps/studio/client/v2/ai/runs-store.js +2 -1
  47. package/apps/studio/client/v2/annotations/vote-store.js +11 -5
  48. package/apps/studio/client/v2/assets/asset-state-lane.js +6 -3
  49. package/apps/studio/client/v2/assets/assets-bus.js +10 -8
  50. package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
  51. package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
  52. package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
  53. package/apps/studio/client/v2/assets/spotlight.css +153 -0
  54. package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
  55. package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
  56. package/apps/studio/client/v2/assets/tile.jsx +3 -0
  57. package/apps/studio/client/v2/assets/use-assets.js +2 -1
  58. package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
  59. package/apps/studio/client/v2/canvases/covers.js +11 -5
  60. package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
  61. package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
  62. package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
  63. package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
  64. package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
  65. package/apps/studio/client/v2/canvases/use-pins.js +2 -1
  66. package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
  67. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
  68. package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
  69. package/apps/studio/client/v2/code/code.css +67 -0
  70. package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
  71. package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
  72. package/apps/studio/client/v2/create/name-dialog.css +10 -0
  73. package/apps/studio/client/v2/ds/advanced-host.jsx +5 -2
  74. package/apps/studio/client/v2/ds/make-host.jsx +5 -2
  75. package/apps/studio/client/v2/ds/off-system-host.jsx +5 -2
  76. package/apps/studio/client/v2/ds/truth-host.jsx +5 -2
  77. package/apps/studio/client/v2/empty/arriving.jsx +29 -12
  78. package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
  79. package/apps/studio/client/v2/empty/not-local.jsx +31 -1
  80. package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
  81. package/apps/studio/client/v2/export/last-finished.js +2 -1
  82. package/apps/studio/client/v2/history/git-model.js +18 -4
  83. package/apps/studio/client/v2/history/git-parts.jsx +60 -42
  84. package/apps/studio/client/v2/history/history.css +6 -0
  85. package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
  86. package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
  87. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
  88. package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
  89. package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
  90. package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
  91. package/apps/studio/client/v2/search/search-recent.js +3 -1
  92. package/apps/studio/client/v2/search/search-remote.js +6 -4
  93. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  94. package/apps/studio/client/v2/shell/menu-runner.js +1 -0
  95. package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
  96. package/apps/studio/client/v2/shell/recovery-store.js +2 -1
  97. package/apps/studio/client/v2/shell/served-routes.js +120 -0
  98. package/apps/studio/client/v2/shell/share-cluster-host.jsx +2 -1
  99. package/apps/studio/client/v2/shell/shell-activity.js +19 -0
  100. package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
  101. package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
  102. package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
  103. package/apps/studio/cloud/endpoints.ts +23 -1
  104. package/apps/studio/dist/client.bundle.js +977 -981
  105. package/apps/studio/dist/styles.css +1 -1
  106. package/apps/studio/editing/minimap-context.tsx +3 -3
  107. package/apps/studio/editing/page-activity.ts +251 -0
  108. package/apps/studio/editing/rotate-handle.tsx +9 -5
  109. package/apps/studio/editing/sticky-name.tsx +4 -4
  110. package/apps/studio/history/restore-artboard-action.ts +40 -0
  111. package/apps/studio/home/hub.ts +77 -175
  112. package/apps/studio/home/routes.ts +47 -8
  113. package/apps/studio/http.ts +117 -66
  114. package/apps/studio/index-flight.ts +40 -0
  115. package/apps/studio/managed-projects.ts +52 -24
  116. package/apps/studio/migrate/hub.ts +7 -1
  117. package/apps/studio/routes/canvas-source.ts +44 -2
  118. package/apps/studio/routes/history.ts +28 -5
  119. package/apps/studio/routes/hub-signin.ts +115 -0
  120. package/apps/studio/routes/index.ts +4 -0
  121. package/apps/studio/routes/table.ts +7 -0
  122. package/apps/studio/routes/trash.ts +3 -0
  123. package/apps/studio/server.ts +11 -0
  124. package/apps/studio/sync/accepted-cold-start.ts +26 -3
  125. package/apps/studio/sync/accepted-link.ts +9 -4
  126. package/apps/studio/sync/code-module-consent.ts +74 -0
  127. package/apps/studio/sync/file-ledger.ts +35 -0
  128. package/apps/studio/sync/file-plane.ts +443 -77
  129. package/apps/studio/sync/hub-browser-signin.ts +377 -0
  130. package/apps/studio/sync/hub-text-undo.ts +30 -10
  131. package/apps/studio/sync/index.ts +73 -11
  132. package/apps/studio/sync/projection.ts +44 -2
  133. package/apps/studio/sync/pull-pacer.ts +160 -0
  134. package/apps/studio/sync/pull-priority.ts +119 -0
  135. package/apps/studio/sync/seed-progress.ts +47 -3
  136. package/apps/studio/sync/transaction-client.ts +71 -6
  137. package/apps/studio/sync/workspace-signin.ts +6 -256
  138. package/apps/studio/sync/writer-registry.ts +5 -1
  139. package/apps/studio/video-links-overlay.tsx +3 -2
  140. package/apps/studio/whats-new.json +54 -0
  141. package/cli/lib/design-help.gen.mjs +1 -1
  142. package/cli/lib/workspace-plan.mjs +14 -0
  143. package/package.json +8 -8
@@ -0,0 +1,150 @@
1
+ // client/v2/canvases/folder-dialogs.jsx — #195 (2.0.4): the tree's folder and file asks, in the shell's own
2
+ // centered dialog instead of `window.prompt` / `window.confirm` (both are no-ops in Tauri's WKWebView, which is
3
+ // why "New folder here" and "Rename folder" did nothing on the desktop).
4
+ //
5
+ // `TreeAsk` owns one ask at a time: the name check before anything is sent, the busy state while the request
6
+ // runs, and the refusal under the field (folder-ask.js `askFailure`). `run(ask, name?)` is the request; it
7
+ // answers `{ ok, status?, error?, network? }`.
8
+
9
+ import { useCallback, useId, useRef, useState } from 'react';
10
+
11
+ import NameDialog from '../create/NameDialog.jsx';
12
+ import { useModalFocus } from '../shell/modal-focus.js';
13
+ import { askFailure, asksForName, checkAskName, folderAskWords } from './folder-ask.js';
14
+
15
+ /**
16
+ * A yes/no ask on the same material as NameDialog: title, one line, Cancel and the verb. `over` lifts it above a
17
+ * modal sheet that is already open (the version diff) — it is the shell's replacement for `window.confirm`.
18
+ */
19
+ export function ConfirmAskDialog({
20
+ title,
21
+ body,
22
+ confirm,
23
+ busyLabel,
24
+ busy,
25
+ error,
26
+ over = false,
27
+ onConfirm,
28
+ onCancel,
29
+ }) {
30
+ const okRef = useRef(null);
31
+ const ref = useModalFocus({ onClose: onCancel, initialRef: okRef });
32
+ const titleId = useId();
33
+ return (
34
+ <div className={over ? 'nd-scrim nd-scrim--over' : 'nd-scrim'} data-testid="tree-ask-scrim">
35
+ <form
36
+ ref={ref}
37
+ className="island nd-dialog"
38
+ role="alertdialog"
39
+ aria-modal="true"
40
+ aria-labelledby={titleId}
41
+ tabIndex={-1}
42
+ data-testid="tree-ask-confirm"
43
+ onSubmit={(e) => {
44
+ e.preventDefault();
45
+ if (!busy) onConfirm();
46
+ }}
47
+ >
48
+ <h2 id={titleId} className="nd-title" data-testid="tree-ask-title">
49
+ {title}
50
+ </h2>
51
+ {body ? <p className="nd-body">{body}</p> : null}
52
+ {error ? (
53
+ <p className="nd-err" role="alert" data-testid="tree-ask-error">
54
+ {error}
55
+ </p>
56
+ ) : null}
57
+ <div className="nd-acts">
58
+ <button
59
+ type="button"
60
+ className="btn"
61
+ disabled={busy}
62
+ data-testid="tree-ask-cancel"
63
+ onClick={onCancel}
64
+ >
65
+ Cancel
66
+ </button>
67
+ <button
68
+ ref={okRef}
69
+ type="submit"
70
+ className="btn btn--primary"
71
+ disabled={busy}
72
+ data-testid="tree-ask-ok"
73
+ >
74
+ {busy ? busyLabel : confirm}
75
+ </button>
76
+ </div>
77
+ </form>
78
+ </div>
79
+ );
80
+ }
81
+
82
+ /**
83
+ * The host: `ask` is `{ kind, path, name? }` or null; `run(ask, name)` sends it; `onClose()` ends the ask.
84
+ */
85
+ export function TreeAsk({ ask, run, onClose }) {
86
+ const [busy, setBusy] = useState(false);
87
+ const [error, setError] = useState('');
88
+ const words = folderAskWords(ask);
89
+
90
+ const close = useCallback(() => {
91
+ setBusy(false);
92
+ setError('');
93
+ onClose();
94
+ }, [onClose]);
95
+
96
+ const send = useCallback(
97
+ async (name) => {
98
+ if (!ask || busy) return;
99
+ if (asksForName(ask)) {
100
+ const v = checkAskName(ask, name);
101
+ if (v.kind === 'keep') return close();
102
+ if (v.kind === 'error') return setError(v.error);
103
+ name = v.name;
104
+ }
105
+ setBusy(true);
106
+ setError('');
107
+ let res;
108
+ try {
109
+ res = await run(ask, name);
110
+ } catch {
111
+ res = { ok: false, network: true };
112
+ }
113
+ if (res?.ok) return close();
114
+ setBusy(false);
115
+ setError(askFailure(ask.kind, res));
116
+ return undefined;
117
+ },
118
+ [ask, busy, run, close]
119
+ );
120
+
121
+ if (!ask || !words) return null;
122
+ if (asksForName(ask)) {
123
+ return (
124
+ <NameDialog
125
+ key={`${ask.kind}:${ask.path}`}
126
+ title={words.title}
127
+ label={words.label}
128
+ initial={words.initial}
129
+ confirm={words.confirm}
130
+ busyLabel={words.busy}
131
+ busy={busy}
132
+ error={error}
133
+ onSubmit={send}
134
+ onCancel={close}
135
+ />
136
+ );
137
+ }
138
+ return (
139
+ <ConfirmAskDialog
140
+ title={words.title}
141
+ body={words.body}
142
+ confirm={words.confirm}
143
+ busyLabel={words.busy}
144
+ busy={busy}
145
+ error={error}
146
+ onConfirm={() => send()}
147
+ onCancel={close}
148
+ />
149
+ );
150
+ }
@@ -6,6 +6,8 @@
6
6
  // `DELETE /_api/canvas` answers with the folder it made, and `sync/trash.ts` reads that folder's manifest to
7
7
  // say where each file goes. The kernel's `trash.restore` (S1.6) replaces this; the words stay.
8
8
 
9
+ import { fetchIfServed } from '../shell/served-routes.js';
10
+
9
11
  export const TRASH_WORDS = {
10
12
  moved: (label) => `“${label}” moved to the trash.`,
11
13
  back: (label) => `“${label}” is back.`,
@@ -37,7 +39,7 @@ export async function restoreTrashedCanvas({ trashDir, fetchImpl = fetch }) {
37
39
  if (!folder) return { ok: false, restored: 0, failed: 0 };
38
40
  let entries = [];
39
41
  try {
40
- const r = await fetchImpl('/_api/sync/trash', { cache: 'no-store' });
42
+ const r = await fetchIfServed('/_api/sync/trash', { cache: 'no-store' }, fetchImpl);
41
43
  if (r.ok) entries = (await jsonOf(r)).entries || [];
42
44
  } catch {
43
45
  return { ok: false, restored: 0, failed: 0 };
@@ -71,6 +73,10 @@ const TRASH_TOAST = Object.freeze({ icon: 'trash' });
71
73
  * @param reload re-reads the tree (`loadTree`)
72
74
  * @param onTrashed (path) — the shell closes the canvas if it was open
73
75
  * @param onUndone (path) — the shell opens it again if it had been open
76
+ * @param onRemoved () — #194: the server took the move (the trash queue hides the row at once)
77
+ *
78
+ * #194 (2.0.4): the row, the tab and the toast follow the SERVER's answer; the list re-read comes after and
79
+ * no longer holds them back (it used to: a slow `/_index-data` read was the "nothing happens for a while").
74
80
  */
75
81
  export async function trashCanvas({
76
82
  path,
@@ -80,6 +86,7 @@ export async function trashCanvas({
80
86
  reload,
81
87
  onTrashed,
82
88
  onUndone,
89
+ onRemoved,
83
90
  }) {
84
91
  let j = {};
85
92
  try {
@@ -95,7 +102,7 @@ export async function trashCanvas({
95
102
  toast?.(TRASH_WORDS.failed(label), false);
96
103
  return { ok: false, error: 'network error' };
97
104
  }
98
- await reload?.();
105
+ onRemoved?.();
99
106
  onTrashed?.(path);
100
107
  // the board's toast wears the trash glyph, not a check (11 · pn-trash)
101
108
  toast?.(
@@ -116,5 +123,6 @@ export async function trashCanvas({
116
123
  },
117
124
  TRASH_TOAST
118
125
  );
126
+ await reload?.();
119
127
  return { ok: true, trashDir: j.trashDir };
120
128
  }
@@ -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
  );