@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
@@ -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, {