@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
@@ -19,6 +19,12 @@
19
19
  // nor shifts a page); `limit` defaults to 200 and is capped at 500.
20
20
  // - `candidates` (a canvas-only session): the listing is built from THOSE paths only (the session's closure), never
21
21
  // from the disk — such a session learns nothing about a file its canvases do not show.
22
+ // - `journal` (2.0.3, a materializing cell): on a cell the disk is a cache (DDR-243) — a system's media lives in the
23
+ // bucket and is served from a hub-owned cache outside the design root, never at its checkout path, so a disk-only
24
+ // listing showed every folder with 0 files. The hub's inert-media listing (`listMaterializable`, the source the file
25
+ // tree and the closure's `withJournalMedia` read) joins the disk: its paths under the library count, list, search and
26
+ // page like files on disk (size/mtime 0 — the hub hands out paths only). It only ADDS names: a disk entry at the same
27
+ // path (a symlink included) is judged as before, and a folder that is a symlink on disk stays refused.
22
28
 
23
29
  import type { Dirent } from 'node:fs';
24
30
  import { lstat, readdir } from 'node:fs/promises';
@@ -120,19 +126,37 @@ function clampLimit(raw: unknown): number {
120
126
  return Math.min(Math.trunc(n), DS_ASSETS_LIMIT_MAX);
121
127
  }
122
128
 
123
- /** Every segment from the designRoot down to `rel` is a real folder (no symlink on the way). */
124
- async function realDirChain(designRoot: string, rel: string): Promise<boolean> {
129
+ /**
130
+ * The folders from the designRoot down to `rel`: `real` when every one is a real folder, `bad` when one is a symlink or
131
+ * not a folder, `absent` when the chain stops at a name that is not there (only the journal can hold files below it).
132
+ */
133
+ async function dirChain(designRoot: string, rel: string): Promise<'real' | 'absent' | 'bad'> {
125
134
  let cur = designRoot;
126
135
  for (const seg of rel.split('/')) {
127
136
  cur = path.join(cur, seg);
128
137
  try {
129
138
  const st = await lstat(cur);
130
- if (!st.isDirectory()) return false;
131
- } catch {
132
- return false;
139
+ if (!st.isDirectory()) return 'bad';
140
+ } catch (err) {
141
+ return (err as NodeJS.ErrnoException)?.code === 'ENOENT' ? 'absent' : 'bad';
133
142
  }
134
143
  }
135
- return true;
144
+ return 'real';
145
+ }
146
+
147
+ /** The journal's media below `base` (designRoot-relative), shape-checked: no empty / `..` / `_` / `.` segment. */
148
+ function journalUnder(base: string, journal: Iterable<string> | null | undefined): Set<string> {
149
+ const out = new Set<string>();
150
+ if (!journal) return out;
151
+ const under = `${base}/`;
152
+ for (const rel of journal) {
153
+ if (typeof rel !== 'string' || !rel.startsWith(under) || rel.length > 1024) continue;
154
+ const segs = rel.slice(under.length).split('/');
155
+ if (segs.some((s) => !s || s === '..' || hiddenName(s) || s.includes('\\') || s.includes('\0')))
156
+ continue;
157
+ if (dsAssetKindOf(rel)) out.add(rel);
158
+ }
159
+ return out;
136
160
  }
137
161
 
138
162
  async function dirents(abs: string): Promise<Dirent[]> {
@@ -143,16 +167,16 @@ async function dirents(abs: string): Promise<Dirent[]> {
143
167
  }
144
168
  }
145
169
 
146
- /** Media files directly inside, and whether a folder is inside (a folder with neither is not one to open). */
147
- async function shallowCount(abs: string): Promise<{ count: number; dirs: boolean }> {
148
- let count = 0;
170
+ /** Media files directly inside (by name), and whether a folder is inside (a folder with neither is not one to open). */
171
+ async function shallowCount(abs: string): Promise<{ names: Set<string>; dirs: boolean }> {
172
+ const names = new Set<string>();
149
173
  let dirs = false;
150
174
  for (const e of await dirents(abs)) {
151
175
  if (hiddenName(e.name)) continue;
152
176
  if (e.isDirectory()) dirs = true;
153
- else if (e.isFile() && dsAssetKindOf(e.name)) count++;
177
+ else if (e.isFile() && dsAssetKindOf(e.name)) names.add(e.name);
154
178
  }
155
- return { count, dirs };
179
+ return { names, dirs };
156
180
  }
157
181
 
158
182
  /** Media files under `startRel` (designRoot-relative), readdir only. */
@@ -174,23 +198,30 @@ async function walkMedia(designRoot: string, startRel: string): Promise<string[]
174
198
  return out;
175
199
  }
176
200
 
177
- async function rowOf(designRoot: string, rel: string): Promise<DsAssetFile | null> {
201
+ async function rowOf(
202
+ designRoot: string,
203
+ rel: string,
204
+ journal: ReadonlySet<string>
205
+ ): Promise<DsAssetFile | null> {
178
206
  const name = rel.slice(rel.lastIndexOf('/') + 1);
179
207
  const kind = dsAssetKindOf(name);
180
208
  if (!kind) return null;
209
+ const row = (size: number, mtimeMs: number): DsAssetFile => ({
210
+ path: rel,
211
+ name,
212
+ ext: path.extname(name).slice(1).toLowerCase(),
213
+ kind,
214
+ size,
215
+ mtimeMs,
216
+ placeable: kind !== 'audio' && dsAssetRel(rel) !== null,
217
+ });
181
218
  try {
182
219
  const st = await lstat(path.join(designRoot, rel));
183
220
  if (!st.isFile()) return null;
184
- return {
185
- path: rel,
186
- name,
187
- ext: path.extname(name).slice(1).toLowerCase(),
188
- kind,
189
- size: st.size,
190
- mtimeMs: st.mtimeMs,
191
- placeable: kind !== 'audio' && dsAssetRel(rel) !== null,
192
- };
193
- } catch {
221
+ return row(st.size, st.mtimeMs);
222
+ } catch (err) {
223
+ // not on this disk: a materializing cell's journal names it (the hub serves it from its cache)
224
+ if ((err as NodeJS.ErrnoException)?.code === 'ENOENT' && journal.has(rel)) return row(0, 0);
194
225
  return null;
195
226
  }
196
227
  }
@@ -205,6 +236,8 @@ export interface ListDsAssetsInput {
205
236
  limit?: unknown;
206
237
  /** a canvas-only session: the designRoot-relative paths it may see (its closure); the disk is not walked */
207
238
  candidates?: Iterable<string>;
239
+ /** a materializing cell: inert media the hub serves although the checkout does not hold it (designRoot-relative) */
240
+ journal?: Iterable<string> | null;
208
241
  }
209
242
 
210
243
  export async function listDsAssets(
@@ -219,6 +252,23 @@ export async function listDsAssets(
219
252
  const words = searchWords(input.q);
220
253
  const limit = clampLimit(input.limit);
221
254
  const cursor = typeof input.cursor === 'string' && input.cursor ? input.cursor : null;
255
+ const journal = journalUnder(base, input.journal);
256
+ // one lstat chain per folder, shared by every path below it
257
+ const chains = new Map<string, Promise<'real' | 'absent' | 'bad'>>();
258
+ const chainOf = (d: string) => {
259
+ let p = chains.get(d);
260
+ if (!p) {
261
+ p = dirChain(designRoot, d);
262
+ chains.set(d, p);
263
+ }
264
+ return p;
265
+ };
266
+ const parentOf = (rel: string) => rel.slice(0, rel.lastIndexOf('/'));
267
+ /** journal paths, minus any whose folder on the way is a symlink (or not a folder) on this disk */
268
+ const journalOk = async (rels: string[]) => {
269
+ const ok = await Promise.all(rels.map(async (r) => (await chainOf(parentOf(r))) !== 'bad'));
270
+ return rels.filter((_, i) => ok[i]);
271
+ };
222
272
 
223
273
  // The candidate files (designRoot-relative) and the folders directly below `base`.
224
274
  let files: string[];
@@ -247,42 +297,82 @@ export async function listDsAssets(
247
297
  // listed file is a real one (a symlinked folder is not walked in a project listing either)
248
298
  if (dir && !files.length && !dirCounts.size)
249
299
  return { ok: false, status: 404, reason: 'not-found' };
250
- const real = new Map<string, Promise<boolean>>();
251
- const chainOk = (rel: string) => {
252
- const d = rel.slice(0, rel.lastIndexOf('/'));
253
- const known = real.get(d);
254
- if (known) return known;
255
- const p = realDirChain(designRoot, d);
256
- real.set(d, p);
257
- return p;
300
+ // on a cell a closure path may be the journal's only, in a folder this disk does not hold at all
301
+ const journalBelow = (d: string) => {
302
+ for (const r of journal) if (r.startsWith(`${d}/`)) return true;
303
+ return false;
304
+ };
305
+ const fileOk = async (rel: string) => {
306
+ const c = await chainOf(parentOf(rel));
307
+ return c === 'real' || (c === 'absent' && journal.has(rel));
258
308
  };
259
- const ok = await Promise.all(files.map(chainOk));
309
+ const ok = await Promise.all(files.map(fileOk));
260
310
  files = files.filter((_, i) => ok[i]);
261
- for (const d of [...dirCounts.keys()])
262
- if (!(await realDirChain(designRoot, d))) dirCounts.delete(d);
311
+ for (const d of [...dirCounts.keys()]) {
312
+ const c = await chainOf(d);
313
+ if (!(c === 'real' || (c === 'absent' && journalBelow(d)))) dirCounts.delete(d);
314
+ }
263
315
  } else {
264
- if (!(await realDirChain(designRoot, base))) {
316
+ const baseChain = await chainOf(base);
317
+ if (baseChain === 'bad' || (baseChain === 'absent' && !journal.size)) {
265
318
  // no library yet is an empty one; a folder that is not there (or a symlink) is not found
266
- if (!dir && !(await realDirChain(designRoot, root)))
319
+ if (!dir && (await chainOf(root)) === 'absent')
267
320
  return { ok: true, root, dir, dirs: [], files: [], total: 0, next: null };
268
321
  return { ok: false, status: 404, reason: 'not-found' };
269
322
  }
323
+ const onDisk = baseChain === 'real';
270
324
  if (words.length) {
271
- files = (await walkMedia(designRoot, base)).filter((rel) =>
272
- matches(rel.slice(rel.lastIndexOf('/') + 1), words)
273
- );
325
+ const all = new Set(onDisk ? await walkMedia(designRoot, base) : []);
326
+ for (const r of await journalOk([...journal].filter((r) => !all.has(r)))) all.add(r);
327
+ files = [...all].filter((rel) => matches(rel.slice(rel.lastIndexOf('/') + 1), words));
274
328
  } else {
275
- files = [];
276
- const subdirs: string[] = [];
277
- for (const e of await dirents(path.join(designRoot, base))) {
278
- if (hiddenName(e.name)) continue;
279
- if (e.isDirectory()) subdirs.push(`${base}/${e.name}`);
280
- else if (e.isFile() && dsAssetKindOf(e.name)) files.push(`${base}/${e.name}`);
329
+ const here = new Set<string>();
330
+ const subdirs = new Set<string>();
331
+ if (onDisk)
332
+ for (const e of await dirents(path.join(designRoot, base))) {
333
+ if (hiddenName(e.name)) continue;
334
+ if (e.isDirectory()) subdirs.add(`${base}/${e.name}`);
335
+ else if (e.isFile() && dsAssetKindOf(e.name)) here.add(`${base}/${e.name}`);
336
+ }
337
+ // the journal's: files directly in this folder, and the folders below it (by their first segment)
338
+ const direct: string[] = [];
339
+ const below = new Map<string, string[]>();
340
+ for (const r of journal) {
341
+ const rest = r.slice(base.length + 1);
342
+ const slash = rest.indexOf('/');
343
+ if (slash < 0) {
344
+ if (!here.has(r)) direct.push(r);
345
+ continue;
346
+ }
347
+ const d = `${base}/${rest.slice(0, slash)}`;
348
+ const list = below.get(d);
349
+ if (list) list.push(r);
350
+ else below.set(d, [r]);
281
351
  }
352
+ for (const r of await journalOk(direct)) here.add(r);
353
+ files = [...here];
282
354
  if (!cursor) {
283
- subdirs.sort(byPath);
284
- const shown = subdirs.slice(0, DIRS_MAX);
285
- const counts = await Promise.all(shown.map((d) => shallowCount(path.join(designRoot, d))));
355
+ for (const d of below.keys()) subdirs.add(d);
356
+ const shown: string[] = [];
357
+ for (const d of [...subdirs].sort(byPath)) {
358
+ if (shown.length >= DIRS_MAX) break;
359
+ // a journal folder whose name is a symlink (or a file) on this disk is not one to open
360
+ if ((await chainOf(d)) !== 'bad') shown.push(d);
361
+ }
362
+ const counts = await Promise.all(
363
+ shown.map(async (d) => {
364
+ const c =
365
+ (await chainOf(d)) === 'real' ? await shallowCount(path.join(designRoot, d)) : null;
366
+ const names = c?.names ?? new Set<string>();
367
+ let dirs = c?.dirs ?? false;
368
+ for (const r of below.get(d) ?? []) {
369
+ const rest = r.slice(d.length + 1);
370
+ if (rest.includes('/')) dirs = true;
371
+ else names.add(rest);
372
+ }
373
+ return { count: names.size, dirs };
374
+ })
375
+ );
286
376
  shown.forEach((d, i) => {
287
377
  const c = counts[i] as { count: number; dirs: boolean };
288
378
  if (c.count || c.dirs) dirCounts.set(d, c.count);
@@ -295,7 +385,7 @@ export async function listDsAssets(
295
385
  const total = files.length;
296
386
  const from = cursor ? files.findIndex((f) => byPath(f, cursor) > 0) : 0;
297
387
  const slice = from < 0 ? [] : files.slice(from, from + limit);
298
- const rows = (await Promise.all(slice.map((rel) => rowOf(designRoot, rel)))).filter(
388
+ const rows = (await Promise.all(slice.map((rel) => rowOf(designRoot, rel, journal)))).filter(
299
389
  (r): r is DsAssetFile => r !== null
300
390
  );
301
391
  const more = from >= 0 && from + limit < files.length;
@@ -11,6 +11,7 @@ import { type ReactNode, useEffect, useState } from 'react';
11
11
  import { getLiveViewport, useViewportControllerContext } from '../canvas-lib.tsx';
12
12
  import { jumpTarget, type PageSection, sectionAt, visibleSentence } from './artboard-resize.ts';
13
13
  import { type LongPage, measureLongPages, pageInView, pageSections } from './long-page.ts';
14
+ import { activeInterval } from './page-activity.ts';
14
15
 
15
16
  export interface MiniModel {
16
17
  id: string;
@@ -91,9 +92,8 @@ export function MinimapContext({ pollMs = 200 }: { pollMs?: number }): ReactNode
91
92
  : next
92
93
  );
93
94
  };
94
- run();
95
- const t = setInterval(run, pollMs);
96
- return () => clearInterval(t);
95
+ // only while the page is in use: an idle or hidden canvas is not polled (page-activity.ts, 2.0.4)
96
+ return activeInterval(run, pollMs);
97
97
  }, [pollMs]);
98
98
 
99
99
  if (!model) return null;
@@ -0,0 +1,251 @@
1
+ // editing/page-activity.ts — Maude 2.0.4 (task O): one "is anyone using this canvas right now" clock for the
2
+ // canvas runtime's per-frame and polling loops.
3
+ //
4
+ // Measured on 2.0.3 (headless WebKit, an idle canvas with nothing selected): the rotate handle's rAF loop ran 72×/s
5
+ // and the sticky-name / minimap polls measured every long page 15×/s, forever — the idle CPU of every open project
6
+ // tab. A loop built on this clock runs only while the page is ACTIVE and stops outright (no timer, no frame) when it
7
+ // goes idle or hidden; the next sign of use starts it again and runs it at once, so nothing lags the person.
8
+ //
9
+ // Active = visible AND something happened in the last IDLE_AFTER_MS: input (pointer, wheel, keys), a message from
10
+ // the shell (camera moves, selections and file pushes all arrive as `message`), a resize or scroll, a focus, or a
11
+ // change to the page's nodes (an AI write, a hot swap). Attribute changes are deliberately NOT activity: the loops
12
+ // themselves write styles every frame and would keep the page awake forever.
13
+ //
14
+ // Pure core (`createPageActivity`) over an injected environment, so the clock is tested without a DOM;
15
+ // `pageActivity()` is the one per-window instance the canvas uses.
16
+
17
+ /** How long after the last sign of use the page counts as idle. Long enough to cover a camera glide (≤ 1 s). */
18
+ export const IDLE_AFTER_MS = 3000;
19
+
20
+ /** Window events that count as use. */
21
+ export const WAKE_EVENTS = [
22
+ 'pointermove',
23
+ 'pointerdown',
24
+ 'pointerup',
25
+ 'wheel',
26
+ 'keydown',
27
+ 'keyup',
28
+ 'message',
29
+ 'resize',
30
+ 'scroll',
31
+ 'focus',
32
+ ] as const;
33
+
34
+ export interface ActivityEnv {
35
+ now(): number;
36
+ hidden(): boolean;
37
+ /** Subscribe to every wake source (events, visibility, node changes); returns the unsubscribe. */
38
+ listen(onWake: () => void, onVisibility: () => void): () => void;
39
+ setTimer(fn: () => void, ms: number): unknown;
40
+ clearTimer(t: unknown): void;
41
+ }
42
+
43
+ export interface PageActivity {
44
+ active(): boolean;
45
+ /** The page is hidden (a background tab, a minimized window). */
46
+ hidden(): boolean;
47
+ /** Called with the new state on every change. Returns the unsubscribe. */
48
+ subscribe(fn: (active: boolean) => void): () => void;
49
+ /** Count as use now (a caller that knows the page changed). */
50
+ poke(): void;
51
+ dispose(): void;
52
+ }
53
+
54
+ export function createPageActivity(env: ActivityEnv, idleAfter = IDLE_AFTER_MS): PageActivity {
55
+ let last = env.now();
56
+ let state = !env.hidden();
57
+ let timer: unknown = null;
58
+ const subs = new Set<(active: boolean) => void>();
59
+ const set = (next: boolean) => {
60
+ if (next === state) return;
61
+ state = next;
62
+ for (const fn of [...subs]) fn(next);
63
+ };
64
+ // One timer while active, re-armed only when it fires (not on every pointermove): it checks how long ago the last
65
+ // use was and either sleeps the rest or turns the page idle. Idle = no timer at all.
66
+ const arm = (ms: number) => {
67
+ timer = env.setTimer(() => {
68
+ timer = null;
69
+ const since = env.now() - last;
70
+ if (env.hidden()) set(false);
71
+ else if (since >= idleAfter) set(false);
72
+ else arm(idleAfter - since);
73
+ }, ms);
74
+ };
75
+ const poke = () => {
76
+ last = env.now();
77
+ if (env.hidden()) return;
78
+ set(true);
79
+ if (timer === null) arm(idleAfter);
80
+ };
81
+ const onVisibility = () => {
82
+ if (env.hidden()) {
83
+ if (timer !== null) env.clearTimer(timer);
84
+ timer = null;
85
+ set(false);
86
+ } else poke();
87
+ };
88
+ const off = env.listen(poke, onVisibility);
89
+ if (state) arm(idleAfter);
90
+ return {
91
+ active: () => state,
92
+ hidden: () => env.hidden(),
93
+ subscribe(fn) {
94
+ subs.add(fn);
95
+ return () => void subs.delete(fn);
96
+ },
97
+ poke,
98
+ dispose() {
99
+ off();
100
+ if (timer !== null) env.clearTimer(timer);
101
+ timer = null;
102
+ subs.clear();
103
+ },
104
+ };
105
+ }
106
+
107
+ /** The real environment: window events, `visibilitychange`, and node (not attribute) changes. */
108
+ export function domActivityEnv(
109
+ win: Window,
110
+ { nodes = true }: { nodes?: boolean } = {}
111
+ ): ActivityEnv {
112
+ const doc = win.document;
113
+ return {
114
+ now: () => win.performance?.now?.() ?? Date.now(),
115
+ hidden: () => doc.hidden === true,
116
+ listen(onWake, onVisibility) {
117
+ const opts = { passive: true, capture: true } as const;
118
+ for (const t of WAKE_EVENTS) win.addEventListener(t, onWake, opts);
119
+ doc.addEventListener('visibilitychange', onVisibility);
120
+ const MO = (win as Window & { MutationObserver?: typeof MutationObserver }).MutationObserver;
121
+ const mo = nodes && typeof MO === 'function' && doc.documentElement ? new MO(onWake) : null;
122
+ mo?.observe(doc.documentElement, { childList: true, subtree: true, characterData: true });
123
+ return () => {
124
+ for (const t of WAKE_EVENTS) win.removeEventListener(t, onWake, opts);
125
+ doc.removeEventListener('visibilitychange', onVisibility);
126
+ mo?.disconnect();
127
+ };
128
+ },
129
+ setTimer: (fn, ms) => win.setTimeout(fn, ms),
130
+ clearTimer: (t) => win.clearTimeout(t as number),
131
+ };
132
+ }
133
+
134
+ const KEY = Symbol.for('maude.pageActivity');
135
+
136
+ /** The window's one activity clock (made on first use). */
137
+ export function pageActivity(win: Window = window): PageActivity {
138
+ const w = win as unknown as Record<symbol, PageActivity | undefined>;
139
+ let a = w[KEY];
140
+ if (!a) {
141
+ a = createPageActivity(domActivityEnv(win));
142
+ w[KEY] = a;
143
+ }
144
+ return a;
145
+ }
146
+
147
+ /**
148
+ * `setInterval(fn, ms)` that runs only while the page is active: `fn` runs at once, every `ms` while active, once
149
+ * more as the page goes idle (so what it draws settles on the final state), and again at once when use resumes.
150
+ */
151
+ export function activeInterval(
152
+ fn: () => void,
153
+ ms: number,
154
+ activity: PageActivity = pageActivity()
155
+ ): () => void {
156
+ let t: ReturnType<typeof setInterval> | null = null;
157
+ const start = () => {
158
+ if (t === null) t = setInterval(fn, ms);
159
+ };
160
+ const stop = () => {
161
+ if (t !== null) clearInterval(t);
162
+ t = null;
163
+ };
164
+ fn();
165
+ if (activity.active()) start();
166
+ const off = activity.subscribe((on) => {
167
+ fn();
168
+ if (on) start();
169
+ else stop();
170
+ });
171
+ return () => {
172
+ off();
173
+ stop();
174
+ };
175
+ }
176
+
177
+ /**
178
+ * A `requestAnimationFrame` loop that runs only while the page is active. `tick` runs every frame while active and
179
+ * once more as the page goes idle; the loop restarts on the next use. Returns the stop.
180
+ */
181
+ export function activeFrameLoop(
182
+ tick: () => void,
183
+ activity: PageActivity = pageActivity()
184
+ ): () => void {
185
+ let raf = 0;
186
+ let running = false;
187
+ const frame = () => {
188
+ if (!running) return;
189
+ raf = requestAnimationFrame(frame);
190
+ tick();
191
+ };
192
+ const start = () => {
193
+ if (running) return;
194
+ running = true;
195
+ raf = requestAnimationFrame(frame);
196
+ };
197
+ const stop = () => {
198
+ running = false;
199
+ cancelAnimationFrame(raf);
200
+ };
201
+ if (activity.active()) start();
202
+ else tick();
203
+ const off = activity.subscribe((on) => {
204
+ if (on) start();
205
+ else {
206
+ stop();
207
+ tick();
208
+ }
209
+ });
210
+ return () => {
211
+ off();
212
+ stop();
213
+ };
214
+ }
215
+
216
+ /**
217
+ * A poll that keeps its pace while the page is in use, slows to `idleMs` while it is visible but unused, and holds
218
+ * no timer at all while it is hidden. Coming back (visible again, or used again) runs `fn` at once and restores the
219
+ * pace. For the shell's server polls (2.0.4), where "unused" still means someone may be looking.
220
+ */
221
+ export function pacedInterval(
222
+ fn: () => void,
223
+ ms: number,
224
+ activity: PageActivity | null,
225
+ idleMs: number = Math.max(ms * 4, 30_000)
226
+ ): () => void {
227
+ if (!activity) {
228
+ const t = setInterval(fn, ms);
229
+ return () => clearInterval(t);
230
+ }
231
+ let t: ReturnType<typeof setInterval> | null = null;
232
+ let every = 0;
233
+ const pace = () => (activity.hidden() ? 0 : activity.active() ? ms : idleMs);
234
+ const apply = () => {
235
+ const next = pace();
236
+ if (next === every) return;
237
+ if (t !== null) clearInterval(t);
238
+ t = next ? setInterval(fn, next) : null;
239
+ every = next;
240
+ };
241
+ apply();
242
+ const off = activity.subscribe((on) => {
243
+ if (on) fn();
244
+ apply();
245
+ });
246
+ return () => {
247
+ off();
248
+ if (t !== null) clearInterval(t);
249
+ t = null;
250
+ };
251
+ }
@@ -21,6 +21,7 @@ import { useSelectionSet } from '../use-selection-set.tsx';
21
21
  import { useToolModeOptional } from '../use-tool-mode.tsx';
22
22
  import { useUndoStackOptional } from '../use-undo-stack.tsx';
23
23
  import { type ObjectTarget, objectTargets, runArranged } from './arrange.ts';
24
+ import { activeFrameLoop } from './page-activity.ts';
24
25
 
25
26
  export const SNAP_DEGREES = 15;
26
27
 
@@ -143,14 +144,18 @@ export function RotateHandle({ readOnly = false }: { readOnly?: boolean }) {
143
144
  };
144
145
  }, []);
145
146
 
146
- // keep the handle at the selection's bottom-right corner, every frame (pan / zoom / write)
147
+ // keep the handle at the selection's bottom-right corner, every frame (pan / zoom / write) — but only while there is
148
+ // a selection to turn and the page is in use (2.0.4: this loop ran 72×/s on every idle canvas, selection or not)
147
149
  useEffect(() => {
148
150
  const h = handle.current;
149
151
  const tip = hint.current;
150
152
  if (!h || !tip) return;
151
- let raf = 0;
153
+ if (!canRotate) {
154
+ h.style.display = 'none';
155
+ tip.style.display = 'none';
156
+ return;
157
+ }
152
158
  const tick = () => {
153
- raf = requestAnimationFrame(tick);
154
159
  const els = live.current.targets.map((t) => t.el);
155
160
  const locked = els.some((e) => e.hasAttribute('data-cd-locked'));
156
161
  const mode = canvasModeStore(window).get().mode;
@@ -178,8 +183,7 @@ export function RotateHandle({ readOnly = false }: { readOnly?: boolean }) {
178
183
  tip.style.left = `${Math.round(box.r + 36)}px`;
179
184
  tip.style.top = `${Math.round(box.b + 10)}px`;
180
185
  };
181
- raf = requestAnimationFrame(tick);
182
- return () => cancelAnimationFrame(raf);
186
+ return activeFrameLoop(tick);
183
187
  }, [canRotate]);
184
188
 
185
189
  const restore = (t: Turning) => {
@@ -8,6 +8,7 @@ import { type ReactNode, useEffect, useState } from 'react';
8
8
 
9
9
  import { sizeText, stickyNameTop } from './artboard-resize.ts';
10
10
  import { type LongPage, measureLongPages, pageInView } from './long-page.ts';
11
+ import { activeInterval } from './page-activity.ts';
11
12
 
12
13
  export interface StickyChip {
13
14
  id: string;
@@ -77,7 +78,8 @@ const same = (a: StickyChip[], b: StickyChip[]) =>
77
78
  );
78
79
  });
79
80
 
80
- /** Polls the canvas ~10×/s (a scroll is a pan — the DOM does not tell us) and draws the chip when there is one. */
81
+ /** Polls the canvas ~10×/s while it is in use (a scroll is a pan — the DOM does not tell us) and draws the chip when
82
+ * there is one. An idle or hidden page is not polled at all (page-activity.ts, 2.0.4). */
81
83
  export function StickyName({ pollMs = 100 }: { pollMs?: number }): ReactNode {
82
84
  const [chips, setChips] = useState<StickyChip[]>([]);
83
85
  useEffect(() => {
@@ -87,9 +89,7 @@ export function StickyName({ pollMs = 100 }: { pollMs?: number }): ReactNode {
87
89
  const next = planStickyChips(measureLongPages(document));
88
90
  setChips((prev) => (same(prev, next) ? prev : next));
89
91
  };
90
- run();
91
- const t = setInterval(run, pollMs);
92
- return () => clearInterval(t);
92
+ return activeInterval(run, pollMs);
93
93
  }, [pollMs]);
94
94
  if (!chips.length) return null;
95
95
  return (
@@ -24,6 +24,8 @@ type Outcome = {
24
24
 
25
25
  /** What a splice restore reads and writes through (`ctx.syncControl.current()`). */
26
26
  export interface SpliceRuntime extends VersionsRuntime {
27
+ /** F14 — this disk's change goes up before the newest version is read (sync/index.ts). */
28
+ settleSource?(repoRel: string, ms?: number): Promise<'settled' | 'held' | 'pending' | null>;
27
29
  acceptedRestore?(repoRel: string, revision: number, o?: RestoreOptions): Promise<Outcome | null>;
28
30
  acceptedVersion?(
29
31
  repoRel: string,
@@ -132,6 +134,42 @@ export async function restoreArtboardAt(
132
134
  return { ...r, label: s.label, line, sharedKept: s.sharedKept, why: s.why };
133
135
  }
134
136
 
137
+ /** F14 — the refusals of a restore whose canvas has a change on this disk the project lacks. */
138
+ export const SETTLE_REFUSAL_LINES: Readonly<Record<string, string>> = {
139
+ 'unsaved-change': 'This canvas has a change on this Mac that isn’t saved. Compare it first.',
140
+ 'still-saving': 'This canvas is still saving. Try again in a moment.',
141
+ };
142
+
143
+ /**
144
+ * F14 (2.0.4, #166) — a restore splices onto the canvas's NEWEST version, but the person (and the
145
+ * all-trashed card) sees THIS disk. A change here the project has not taken yet (an AI run, an
146
+ * editor, a pull, still in the watcher's quiet window or in flight) goes up first, so the restore
147
+ * lands after it. A change the project refused stays held here, and the restore is refused rather
148
+ * than landing in the project while this file keeps the held candidate (the "answers ok but the
149
+ * file stays empty" bug). A home without the seam (a local project, an older runtime) is unchanged.
150
+ */
151
+ export async function settleBeforeRestore(
152
+ rt: SpliceRuntime,
153
+ repoRel: string
154
+ ): Promise<{ ok: true } | { ok: false; status: number; reason: string; line: string }> {
155
+ const s = rt.settleSource ? await rt.settleSource(repoRel).catch(() => null) : null;
156
+ if (s === 'held')
157
+ return {
158
+ ok: false,
159
+ status: 409,
160
+ reason: 'unsaved-change',
161
+ line: SETTLE_REFUSAL_LINES['unsaved-change'] as string,
162
+ };
163
+ if (s === 'pending')
164
+ return {
165
+ ok: false,
166
+ status: 409,
167
+ reason: 'still-saving',
168
+ line: SETTLE_REFUSAL_LINES['still-saving'] as string,
169
+ };
170
+ return { ok: true };
171
+ }
172
+
135
173
  /** "Restored “Hero” from the trash" — the canvas restore's words (sync/index.ts), for one artboard. */
136
174
  export const trashRestoreLine = (label: string): string => `Restored “${label}” from the trash`;
137
175
 
@@ -161,6 +199,8 @@ export function trashArtboardRestorer(deps: {
161
199
  if (!Number.isSafeInteger(item.rev) || item.rev < 1)
162
200
  return { status: 'rejected', code: 'not-in-version' };
163
201
  const repoRel = designRel ? `${designRel}/${canvas}` : canvas;
202
+ const settled = await settleBeforeRestore(rt, repoRel);
203
+ if (!settled.ok) return { status: 'rejected', code: settled.reason };
164
204
  const headRev = await newestRevision(rt, repoRel, canvas).catch(() => undefined);
165
205
  if (headRev === undefined) return { status: 'rejected', code: 'unreachable' };
166
206
  const r = await restoreArtboardAt(rt, {