@1agh/maude 2.0.6 → 2.0.8

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 (177) hide show
  1. package/apps/studio/access/closure.ts +156 -16
  2. package/apps/studio/access/filters.ts +27 -0
  3. package/apps/studio/actions/agents.ts +54 -0
  4. package/apps/studio/actions/ctx.ts +3 -0
  5. package/apps/studio/actions/defs/sync.ts +13 -0
  6. package/apps/studio/actions/defs/view.ts +59 -3
  7. package/apps/studio/actions/keymap.gen.ts +35 -0
  8. package/apps/studio/actions/menu.ts +2 -0
  9. package/apps/studio/actions/types.ts +3 -1
  10. package/apps/studio/actions.manifest.json +136 -1
  11. package/apps/studio/actions.parity.json +25 -1
  12. package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
  13. package/apps/studio/annotations/ui/ride.ts +2 -1
  14. package/apps/studio/annotations-context-toolbar.tsx +5 -4
  15. package/apps/studio/annotations-layer.tsx +4 -3
  16. package/apps/studio/api.ts +383 -128
  17. package/apps/studio/artboard-activity-overlay.tsx +4 -4
  18. package/apps/studio/artboard-ai-copies.tsx +4 -4
  19. package/apps/studio/artboard-freeze.ts +108 -0
  20. package/apps/studio/artboard-live-gate.tsx +414 -45
  21. package/apps/studio/artboard-live.ts +526 -31
  22. package/apps/studio/artboard-placeholder.ts +197 -0
  23. package/apps/studio/artboard-still-raster.ts +485 -0
  24. package/apps/studio/artboard-still-warmup.ts +221 -0
  25. package/apps/studio/artboard-still.ts +1188 -0
  26. package/apps/studio/artboard-webgl.ts +2 -1
  27. package/apps/studio/asset-placeholder.tsx +237 -132
  28. package/apps/studio/asset-upload-bars.tsx +4 -4
  29. package/apps/studio/bin/_perf-probe-open.mjs +364 -0
  30. package/apps/studio/bin/_perf-shared.mjs +12 -7
  31. package/apps/studio/bin/_pw-launch.mjs +26 -1
  32. package/apps/studio/bin/perf.sh +19 -0
  33. package/apps/studio/bridge/dgn-protocol.ts +35 -0
  34. package/apps/studio/canvas-build-sandbox.ts +69 -13
  35. package/apps/studio/canvas-camera.ts +90 -0
  36. package/apps/studio/canvas-comment-mount.tsx +9 -9
  37. package/apps/studio/canvas-lib.tsx +160 -34
  38. package/apps/studio/canvas-pages-view.tsx +465 -0
  39. package/apps/studio/canvas-pages.ts +305 -0
  40. package/apps/studio/canvas-rows.ts +62 -0
  41. package/apps/studio/canvas-shell.tsx +62 -16
  42. package/apps/studio/canvas-theme-icons.tsx +41 -0
  43. package/apps/studio/canvas-theme-pill.tsx +15 -6
  44. package/apps/studio/canvas-theme.ts +12 -11
  45. package/apps/studio/client/app.jsx +7 -0
  46. package/apps/studio/client/canvas-url.js +23 -1
  47. package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
  48. package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
  49. package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
  50. package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
  51. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
  52. package/apps/studio/client/hooks/use-project-data.jsx +11 -2
  53. package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
  54. package/apps/studio/client/index-loader.ts +41 -21
  55. package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
  56. package/apps/studio/client/shell/viewport.jsx +32 -16
  57. package/apps/studio/client/tree/tree.jsx +17 -0
  58. package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
  59. package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
  60. package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
  61. package/apps/studio/client/v2/code/canvas-imports-card.jsx +7 -3
  62. package/apps/studio/client/v2/code/canvas-imports-words.js +16 -0
  63. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
  64. package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
  65. package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
  66. package/apps/studio/client/v2/code/code-consent.js +67 -0
  67. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
  68. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
  69. package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
  70. package/apps/studio/client/v2/layers/layers-request.js +49 -0
  71. package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
  72. package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
  73. package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
  74. package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
  75. package/apps/studio/client/v2/shell/canvas-crash-guard.js +40 -5
  76. package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
  77. package/apps/studio/client/v2/shell/floating-panels.css +37 -1
  78. package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
  79. package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
  80. package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
  81. package/apps/studio/client/v2/shell/pages-pick.js +49 -0
  82. package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
  83. package/apps/studio/client/v2/shell/share-cluster-host.jsx +3 -1
  84. package/apps/studio/client/v2/shell/shell-parity.json +8 -0
  85. package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
  86. package/apps/studio/comments-overlay.tsx +12 -11
  87. package/apps/studio/config-reload-wire.ts +4 -1
  88. package/apps/studio/config.schema.json +6 -0
  89. package/apps/studio/context.ts +37 -1
  90. package/apps/studio/dist/client.bundle.js +720 -720
  91. package/apps/studio/dist/comment-mount.js +2 -2
  92. package/apps/studio/dist/styles.css +1 -1
  93. package/apps/studio/ds/board/board.css +6 -0
  94. package/apps/studio/ds/board/ds-bar.tsx +21 -3
  95. package/apps/studio/ds/board/specimen.tsx +6 -3
  96. package/apps/studio/ds/board/template.ts +39 -19
  97. package/apps/studio/ds/cli.ts +7 -1
  98. package/apps/studio/ds/component-list.ts +2 -1
  99. package/apps/studio/ds/default.ts +6 -1
  100. package/apps/studio/ds/ds-resolver.ts +58 -8
  101. package/apps/studio/ds/engine.ts +3 -1
  102. package/apps/studio/ds/folder-systems.ts +199 -0
  103. package/apps/studio/ds/pairing-css.ts +2 -1
  104. package/apps/studio/ds/rename.ts +10 -3
  105. package/apps/studio/ds/shell-fallbacks.ts +2 -1
  106. package/apps/studio/ds/upgrade-stage.ts +6 -2
  107. package/apps/studio/editing/ai-point-ring.tsx +4 -4
  108. package/apps/studio/editing/ai-scope-outline.tsx +4 -4
  109. package/apps/studio/editing/align-bar.tsx +4 -4
  110. package/apps/studio/editing/anchor-report.ts +3 -2
  111. package/apps/studio/editing/artboard-handles.tsx +4 -4
  112. package/apps/studio/editing/corner-dots.tsx +4 -4
  113. package/apps/studio/editing/crop-mode.tsx +4 -4
  114. package/apps/studio/editing/drop-chip.tsx +4 -4
  115. package/apps/studio/editing/empty-report.ts +3 -2
  116. package/apps/studio/editing/focus-model.tsx +4 -4
  117. package/apps/studio/editing/gap-bands.tsx +3 -3
  118. package/apps/studio/editing/hold-rings.tsx +4 -4
  119. package/apps/studio/editing/lock-badge.tsx +3 -3
  120. package/apps/studio/editing/long-page.ts +23 -1
  121. package/apps/studio/editing/nudge.tsx +2 -2
  122. package/apps/studio/editing/page-activity.ts +4 -3
  123. package/apps/studio/editing/paste-bar.tsx +4 -4
  124. package/apps/studio/editing/pen/overlay.tsx +4 -3
  125. package/apps/studio/editing/place-freely.tsx +3 -3
  126. package/apps/studio/editing/reorder-slot.tsx +3 -3
  127. package/apps/studio/editing/selection.tsx +4 -4
  128. package/apps/studio/editing/size-ghost.tsx +4 -4
  129. package/apps/studio/editing/tab-order.tsx +4 -4
  130. package/apps/studio/editing/text-in-place.tsx +4 -4
  131. package/apps/studio/editing/undo-preview.tsx +3 -3
  132. package/apps/studio/equal-spacing-handles.tsx +3 -3
  133. package/apps/studio/frame-clock.ts +89 -0
  134. package/apps/studio/http.ts +66 -32
  135. package/apps/studio/index/ds-usage.ts +4 -1
  136. package/apps/studio/index-cache.ts +272 -0
  137. package/apps/studio/inspect-overlay.tsx +4 -3
  138. package/apps/studio/inspect.ts +7 -2
  139. package/apps/studio/link-chip-overlay.tsx +4 -3
  140. package/apps/studio/measure-overlay.tsx +4 -3
  141. package/apps/studio/present/pointer-dot.tsx +3 -2
  142. package/apps/studio/present/present-media.ts +6 -2
  143. package/apps/studio/present/present-stage.tsx +3 -2
  144. package/apps/studio/preview/preview-camera.tsx +3 -2
  145. package/apps/studio/routes/sync.ts +176 -0
  146. package/apps/studio/safe-zones-overlay.tsx +3 -2
  147. package/apps/studio/skip-dirs.ts +103 -47
  148. package/apps/studio/studio-page-host.ts +70 -0
  149. package/apps/studio/sync/code-module-consent.ts +86 -0
  150. package/apps/studio/sync/file-ledger.ts +24 -0
  151. package/apps/studio/sync/file-plane.ts +458 -53
  152. package/apps/studio/sync/held-deletes.ts +230 -0
  153. package/apps/studio/sync/hubs-config.ts +59 -2
  154. package/apps/studio/sync/index.ts +99 -15
  155. package/apps/studio/sync/seed-progress.ts +92 -2
  156. package/apps/studio/sync/settings.ts +36 -1
  157. package/apps/studio/sync/status.ts +15 -1
  158. package/apps/studio/sync/writer-registry.ts +5 -0
  159. package/apps/studio/text-caret.ts +5 -3
  160. package/apps/studio/toolbars/toolbar-rect.ts +3 -2
  161. package/apps/studio/use-annotation-resize.tsx +4 -3
  162. package/apps/studio/use-artboard-drag.tsx +3 -2
  163. package/apps/studio/use-element-resize.tsx +7 -6
  164. package/apps/studio/use-grid-track-handles.tsx +5 -4
  165. package/apps/studio/use-selection-set.tsx +64 -4
  166. package/apps/studio/use-spacing-handles.tsx +7 -6
  167. package/apps/studio/video-comp.tsx +55 -42
  168. package/apps/studio/video-play-overlay.tsx +4 -3
  169. package/apps/studio/whats-new.json +27 -0
  170. package/cli/commands/design.mjs +5 -2
  171. package/cli/commands/hub.mjs +10 -1
  172. package/cli/lib/bash-guard.mjs +14 -0
  173. package/cli/lib/design-help.gen.mjs +1 -1
  174. package/cli/lib/design-link.mjs +42 -17
  175. package/cli/lib/hub-purge.mjs +183 -0
  176. package/package.json +8 -8
  177. package/plugins/design/templates/_shell.html +164 -1
@@ -0,0 +1,230 @@
1
+ // sync/held-deletes.ts — the person's answer to "Deleted on this Mac, held" (issue #207, 7b).
2
+ //
3
+ // A batch of local deletes larger than sync removes from the project unasked waits in Sync details
4
+ // (`delete-held` rows, file-plane.ts). Two answers:
5
+ //
6
+ // Delete on the hub too — one confirmed batch. Within the hub door's own window budget (the
7
+ // member one, or the owner's higher one) the plane sends them through the door on its next
8
+ // passes, each a CAS on the hash this Mac last saw. Past it, the project OWNER's confirmed purge
9
+ // (`POST /api/file-purge`: a dry run, then a confirmation bound to that exact set, paced
10
+ // batches — apps/hub/src/owner-purge.mjs). Anyone else gets an honest no: only the owner can
11
+ // delete this many at once.
12
+ // Keep on the hub — the rows become `hub-only`: no delete is proposed, the same bytes are never
13
+ // downloaded again. Recorded in this Mac's file ledger (per-machine runtime state), never in the
14
+ // project config: the choice is about this Mac's copy, and teammates keep syncing the files.
15
+ //
16
+ // Which path to TRY comes from this Mac's stored role and its own record of deletes sent; the hub
17
+ // decides the rest (a member's door 429, an owner check on the purge). Nothing here is a hub claim.
18
+
19
+ import { inHeldFolder } from './file-plane.ts';
20
+
21
+ /** The hub door's delete window — apps/hub/src/journal.mjs `DELETE_BUDGET_PER_WINDOW`. */
22
+ export const DOOR_DELETES_MEMBER = 25;
23
+ /** The owner's own window — journal.mjs `OWNER_DELETE_BUDGET_PER_WINDOW`. */
24
+ export const DOOR_DELETES_OWNER = 200;
25
+ /** The most paths one purge names — owner-purge.mjs `MAX_PURGE_FILES`. */
26
+ export const PURGE_MAX_FILES = 20_000;
27
+
28
+ export const NOT_OWNER_DETAIL =
29
+ 'Only the project owner can delete this many at once — ask them, or keep them on the hub.';
30
+
31
+ export interface HeldDeletePlane {
32
+ heldDeletes(): { count: number; paths: string[]; folders: { folder: string; count: number }[] };
33
+ answerHeldDeletes(how: 'send' | 'purging' | 'keep', folder: string | null): string[];
34
+ endPurge(rels: readonly string[]): void;
35
+ }
36
+
37
+ export interface HeldDeletesDeps {
38
+ plane: () => HeldDeletePlane | null;
39
+ /** Deletes this Mac sent inside the door's window (the ledger's outbound budget). */
40
+ sentInWindow: () => number;
41
+ /** This Mac's stored role on the hub is owner (it only decides which path to TRY). */
42
+ isOwner: () => boolean;
43
+ hubUrl: string;
44
+ token: () => string | null;
45
+ fetchImpl?: typeof fetch;
46
+ /** Start a pass now (the answer applies without waiting for the next tick). */
47
+ runPass: () => Promise<void> | void;
48
+ sleep?: (ms: number) => Promise<void>;
49
+ log?: Pick<Console, 'log' | 'warn'>;
50
+ }
51
+
52
+ export interface HeldDeletesView {
53
+ count: number;
54
+ folders: { folder: string; count: number }[];
55
+ /** An owner purge in progress (or the last one's failure). */
56
+ purge: { total: number; done: number; running: boolean; error?: string } | null;
57
+ }
58
+
59
+ export type HeldDeleteAnswer =
60
+ | { ok: true; how: 'door' | 'purge' | 'keep'; count: number }
61
+ | {
62
+ ok: false;
63
+ reason: 'nothing-held' | 'not-owner' | 'busy' | 'not-linked';
64
+ detail: string;
65
+ };
66
+
67
+ export interface HeldDeletesControl {
68
+ view(): HeldDeletesView;
69
+ answer(answer: 'delete' | 'keep', folder: string | null): Promise<HeldDeleteAnswer>;
70
+ /** Test seam: the running purge, if any. */
71
+ idle(): Promise<void>;
72
+ }
73
+
74
+ const thousands = (n: number) => n.toLocaleString('en-US');
75
+
76
+ export function createHeldDeletes(deps: HeldDeletesDeps): HeldDeletesControl {
77
+ const fetchImpl = deps.fetchImpl ?? fetch;
78
+ const sleep = deps.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
79
+ const log = deps.log ?? console;
80
+ const base = deps.hubUrl.replace(/\/+$/, '');
81
+ let purge: HeldDeletesView['purge'] = null;
82
+ let job: Promise<void> | null = null;
83
+
84
+ async function post(body: unknown): Promise<{ status: number; json: Record<string, unknown> }> {
85
+ const res = await fetchImpl(`${base}/api/file-purge`, {
86
+ method: 'POST',
87
+ headers: {
88
+ authorization: `Bearer ${deps.token() ?? ''}`,
89
+ 'content-type': 'application/json',
90
+ },
91
+ body: JSON.stringify(body),
92
+ });
93
+ let json: Record<string, unknown> = {};
94
+ try {
95
+ json = (await res.json()) as Record<string, unknown>;
96
+ } catch {
97
+ /* a non-JSON answer reads as a failure below */
98
+ }
99
+ return { status: res.status, json };
100
+ }
101
+
102
+ /** One purge set: the dry run, then paced confirms until the hub says done. */
103
+ async function purgeSet(paths: string[], state: NonNullable<HeldDeletesView['purge']>) {
104
+ const dry = await post({ paths, dryRun: true });
105
+ if (dry.status === 403) throw new Error(NOT_OWNER_DETAIL);
106
+ if (dry.status !== 200 || dry.json.ok !== true) {
107
+ throw new Error('The hub did not take the deletion. Nothing more was deleted. Try again.');
108
+ }
109
+ const confirm = typeof dry.json.confirm === 'string' ? dry.json.confirm : null;
110
+ // Every one is gone on the hub already: nothing to confirm.
111
+ if (!confirm) return;
112
+ for (let guard = 0; guard < 10_000; guard += 1) {
113
+ const r = await post({ paths, confirm });
114
+ const wait = Number(r.json.retryAfterMs);
115
+ const pause = Number.isFinite(wait) && wait > 0 ? Math.min(wait, 60_000) : 1000;
116
+ if (r.status === 429 || r.status === 503) {
117
+ if (r.status === 503) state.done += Number(r.json.purged) || 0;
118
+ await sleep(pause);
119
+ continue;
120
+ }
121
+ if (r.status === 409) {
122
+ throw new Error(
123
+ 'Some of these files changed on the hub since. Nothing more was deleted. Try again to delete the rest.'
124
+ );
125
+ }
126
+ if (r.status === 403) throw new Error(NOT_OWNER_DETAIL);
127
+ if (r.status !== 200 || r.json.ok !== true) {
128
+ throw new Error('The hub stopped the deletion. Nothing more was deleted. Try again.');
129
+ }
130
+ state.done += Number(r.json.purged) || 0;
131
+ if (r.json.done === true) return;
132
+ await sleep(pause);
133
+ }
134
+ }
135
+
136
+ async function runPurge(rels: string[]) {
137
+ const state = { total: rels.length, done: 0, running: true } as NonNullable<
138
+ HeldDeletesView['purge']
139
+ >;
140
+ purge = state;
141
+ try {
142
+ for (let i = 0; i < rels.length; i += PURGE_MAX_FILES) {
143
+ await purgeSet(rels.slice(i, i + PURGE_MAX_FILES), state);
144
+ }
145
+ log.log?.(`[sync/files] deleted ${state.done} held files on the hub (owner purge).`);
146
+ purge = null;
147
+ } catch (err) {
148
+ state.error = err instanceof Error ? err.message : String(err);
149
+ log.warn?.(`[sync/files] the held deletes stopped: ${state.error}`);
150
+ } finally {
151
+ state.running = false;
152
+ // The hub's tombstones arrive on this pass and the rows leave; anything it did not delete is
153
+ // held again, still waiting for an answer.
154
+ try {
155
+ await deps.runPass();
156
+ } catch {
157
+ /* the next tick reads them */
158
+ }
159
+ deps.plane()?.endPurge(rels);
160
+ }
161
+ }
162
+
163
+ return {
164
+ view() {
165
+ const held = deps.plane()?.heldDeletes() ?? { count: 0, folders: [] };
166
+ return {
167
+ count: held.count,
168
+ folders: held.folders,
169
+ purge: purge ? { ...purge } : null,
170
+ };
171
+ },
172
+ async answer(answer, folder) {
173
+ const plane = deps.plane();
174
+ if (!plane) {
175
+ return {
176
+ ok: false,
177
+ reason: 'not-linked',
178
+ detail: 'This project isn’t syncing with a hub right now.',
179
+ };
180
+ }
181
+ if (answer === 'keep') {
182
+ const kept = plane.answerHeldDeletes('keep', folder);
183
+ if (kept.length === 0) return nothingHeld();
184
+ void Promise.resolve(deps.runPass()).catch(() => {});
185
+ return { ok: true, how: 'keep', count: kept.length };
186
+ }
187
+ if (job) {
188
+ return {
189
+ ok: false,
190
+ reason: 'busy',
191
+ detail: 'The hub is still deleting the last batch. Try again when it is done.',
192
+ };
193
+ }
194
+ const n = plane.heldDeletes().paths.filter((r) => inHeldFolder(r, folder)).length;
195
+ if (n === 0) return nothingHeld();
196
+ const owner = deps.isOwner();
197
+ const room = (owner ? DOOR_DELETES_OWNER : DOOR_DELETES_MEMBER) - deps.sentInWindow();
198
+ if (n <= room) {
199
+ const sent = plane.answerHeldDeletes('send', folder);
200
+ void Promise.resolve(deps.runPass()).catch(() => {});
201
+ return { ok: true, how: 'door', count: sent.length };
202
+ }
203
+ if (!owner) return { ok: false, reason: 'not-owner', detail: NOT_OWNER_DETAIL };
204
+ const rels = plane.answerHeldDeletes('purging', folder);
205
+ job = runPurge(rels).finally(() => {
206
+ job = null;
207
+ });
208
+ return { ok: true, how: 'purge', count: rels.length };
209
+ },
210
+ async idle() {
211
+ await job;
212
+ },
213
+ };
214
+ }
215
+
216
+ function nothingHeld(): HeldDeleteAnswer {
217
+ return { ok: false, reason: 'nothing-held', detail: 'Nothing here is waiting to be deleted.' };
218
+ }
219
+
220
+ /** Sync details' sentence for the held row (CONTRACT §4: what happened · what is safe · the verbs). */
221
+ export function heldDeleteDetail(count: number, folders: { folder: string; count: number }[]) {
222
+ const where =
223
+ folders.length === 1
224
+ ? ` in ${folders[0]?.folder || 'the project folder'}`
225
+ : folders.length > 1
226
+ ? ` in ${thousands(folders.length)} folders`
227
+ : '';
228
+ const files = count === 1 ? '1 file' : `${thousands(count)} files`;
229
+ return `${files} deleted on this Mac${where} — more than sync deletes on the hub without asking. They are still on the hub. Delete them on the hub too, or keep them there.`;
230
+ }
@@ -1,11 +1,22 @@
1
1
  // Read-only mirror of cli/lib/hubs-config.mjs for the dev-server runtime.
2
2
  //
3
3
  // The CLI owns writes (`maude design link` adds + removes entries); the
4
- // dev-server only ever reads. This module deliberately re-implements the
4
+ // dev-server only reads — except `recordCodeModulesAllowed` (fix/207), the
5
+ // person's in-app answer to the shared-code question. This module deliberately re-implements the
5
6
  // reader instead of importing from cli/lib so the Bun-side ts compile chain
6
7
  // doesn't pull in the .mjs CLI surface.
7
8
 
8
- import { existsSync, readFileSync, type Stats, statSync, unwatchFile, watchFile } from 'node:fs';
9
+ import {
10
+ chmodSync,
11
+ existsSync,
12
+ readFileSync,
13
+ renameSync,
14
+ type Stats,
15
+ statSync,
16
+ unwatchFile,
17
+ watchFile,
18
+ writeFileSync,
19
+ } from 'node:fs';
9
20
  import { homedir, platform } from 'node:os';
10
21
  import { join } from 'node:path';
11
22
 
@@ -251,6 +262,52 @@ export function getHubRecord(url: string, path?: string): HubRecord | null {
251
262
  }
252
263
  }
253
264
 
265
+ /**
266
+ * fix/207 — record THIS Mac's answer to "may this hub deliver shared code (`.ts`/`.js`)?" on the
267
+ * stored record of `url`, in the profile's hubs.json (`hubsConfigPath()` — `HUBS_CONFIG_PATH` /
268
+ * `MAUDE_PROFILE_ID`, never a hard-coded `~/.config/maude`). The one writer besides the CLI's
269
+ * `maude design link` prompt: the in-app consent sheet (`POST /_api/sync/code-consent/set`).
270
+ *
271
+ * Only an existing SIGNED-IN record (one holding a token) is changed — consent for a hub this Mac
272
+ * holds no credential for is meaningless and would mint a record the link flow never made. Every
273
+ * other field is carried untouched; the write is temp-then-rename (0600), like `saveHubCredential`,
274
+ * because the file holds every hub credential on the machine. Returns false when there is no such
275
+ * record (nothing written).
276
+ */
277
+ export function recordCodeModulesAllowed(
278
+ url: string,
279
+ allowed: boolean,
280
+ path: string = hubsConfigPath()
281
+ ): boolean {
282
+ let norm: string;
283
+ try {
284
+ norm = normalizeUrl(url);
285
+ } catch {
286
+ return false;
287
+ }
288
+ if (!existsSync(path)) return false;
289
+ let cfg: Record<string, unknown> & { hubs: Record<string, HubRecord> };
290
+ try {
291
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
292
+ if (!parsed || typeof parsed.hubs !== 'object' || parsed.hubs === null) return false;
293
+ cfg = parsed;
294
+ } catch {
295
+ return false; // malformed: never overwrite what we cannot read
296
+ }
297
+ const rec = cfg.hubs[norm];
298
+ if (!rec || typeof rec !== 'object' || typeof rec.token !== 'string') return false;
299
+ cfg.hubs[norm] = { ...rec, codeModulesAllowed: allowed === true };
300
+ const tmp = `${path}.${process.pid}.consent.tmp`;
301
+ writeFileSync(tmp, `${JSON.stringify(cfg, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
302
+ try {
303
+ chmodSync(tmp, 0o600);
304
+ } catch {
305
+ /* windows / read-only fs — best effort */
306
+ }
307
+ renameSync(tmp, path);
308
+ return true;
309
+ }
310
+
254
311
  /**
255
312
  * S9.12b (V2-1.16 U6, desktop) — call `onChange` whenever hubs.json is written, replaced,
256
313
  * created or removed (a re-sign-in, a role drop, a link or unlink — from this process, the
@@ -67,7 +67,7 @@ import {
67
67
  resolveCanvasBodyRel,
68
68
  } from './canvas-path.ts';
69
69
  import { type CellPairing, resolveCellPairing, sanitizeForLog } from './cell-pairing.ts';
70
- import { codeModuleConsent } from './code-module-consent.ts';
70
+ import { type CodeConsentControl, createCodeConsentControl } from './code-module-consent.ts';
71
71
  import {
72
72
  canvasPathFromDoc,
73
73
  clearMovedTo,
@@ -90,7 +90,12 @@ import { createDocNameResolver } from './doc-name.ts';
90
90
  import { createDocumentDiscovery } from './document-discovery.ts';
91
91
  import { createEchoGuard, hashBytes } from './echo-guard.ts';
92
92
  import { createFileLedger } from './file-ledger.ts';
93
- import { createFilePlane, MAX_DORUCEKA_ROWS } from './file-plane.ts';
93
+ import {
94
+ createFilePlane,
95
+ DELETE_BUDGET_WINDOW_MS,
96
+ MAX_DORUCEKA_ROWS,
97
+ normalizeIgnoreFolders,
98
+ } from './file-plane.ts';
94
99
  import {
95
100
  createLegacyPullGate,
96
101
  createPullFailureMemory,
@@ -107,10 +112,11 @@ import {
107
112
  withFormatParam,
108
113
  } from './format-sync.ts';
109
114
  import { createFsReader, type FsReader } from './fs-mirror.ts';
115
+ import { createHeldDeletes, type HeldDeletesControl, heldDeleteDetail } from './held-deletes.ts';
110
116
  import { canvasLanes, namedField, type RowNamed } from './history-fields.ts';
111
117
  import { type HubDocRow, hubHolds, indexHubDocs } from './hub-listing.ts';
112
118
  import { HUB_UNDO_READ_MAX_BYTES, hubTextUndoConflict } from './hub-text-undo.ts';
113
- import { accessFor, getHubRecord } from './hubs-config.ts';
119
+ import { accessFor, getHubRecord, watchHubsConfig } from './hubs-config.ts';
114
120
  import { loadJournal, type SyncJournal } from './journal.ts';
115
121
  import {
116
122
  hasAnnotationsV2,
@@ -155,7 +161,13 @@ import {
155
161
  tombstonedSlugs,
156
162
  } from './remote-docs.ts';
157
163
  import { createRevisionBarrier } from './revision-barrier.ts';
158
- import { computeSeedProgress } from './seed-progress.ts';
164
+ import {
165
+ codeConsentHeldDetail,
166
+ codeConsentHeldPaths,
167
+ computeSeedProgress,
168
+ heldWords,
169
+ } from './seed-progress.ts';
170
+ import { livePropagateDeletes, readSyncSettings } from './settings.ts';
159
171
  import { mergeSource } from './source-merge.ts';
160
172
  import { replaySourceOp, type SourceOp } from './source-ops.ts';
161
173
  import { createSyncStatusStore, type FilePlaneStatus, type SyncStatusStore } from './status.ts';
@@ -586,6 +598,10 @@ export interface SyncRuntime {
586
598
  * schedule. Test seam, and the hook behind a manual "check now".
587
599
  */
588
600
  pullRemoteNow(): Promise<void>;
601
+ /** fix/207 — this runtime's live shared-code consent (the in-app sheet's control). */
602
+ codeConsent?(): CodeConsentControl | null;
603
+ /** Issue #207 (7b) — the held local deletes and the person's answer (Sync details). */
604
+ heldDeletes?(): HeldDeletesControl | null;
589
605
  /** Number of active per-canvas agents. */
590
606
  size(): number;
591
607
  /** Test inspection — get the agent for a slug if one was created. */
@@ -1107,6 +1123,12 @@ export function createSyncRuntime(
1107
1123
  : ctx.cfg.linkedHub;
1108
1124
  if (!linked) return null;
1109
1125
  const linkedHub = linked;
1126
+ /**
1127
+ * Issue #207 — folders this project does not sync, read from the project config per pass (a
1128
+ * choice made mid-upload applies at the next pass; cleaned, so a committed `..` entry is dropped).
1129
+ */
1130
+ const planeIgnoreFolders = (): string[] =>
1131
+ normalizeIgnoreFolders(readSyncSettings(ctx.paths.repoRoot)?.ignoreFolders);
1110
1132
  // p8-hub-folder-boundary — a hub's own studio, while the owner has declared no
1111
1133
  // canvas folders, takes and scans every folder the hub's kernel takes. Read per
1112
1134
  // call: the owner may declare groups mid-session (the project-config door), and
@@ -1290,13 +1312,17 @@ export function createSyncRuntime(
1290
1312
  // (2.0.4) the Maude Cloud cell the desktop app itself bound this copy to
1291
1313
  // (`MAUDE_APP_BOUND_HUB` + the compiled-in cell zone; never a committed
1292
1314
  // linkedHub, never a self-hosted hub). See sync/code-module-consent.ts.
1293
- const allowCodeModules =
1294
- codeModuleConsent({
1295
- cellPairing: cellPairing !== null,
1296
- hubUrl: linkedHub.url,
1297
- storedRecord,
1298
- env: process.env,
1299
- }) !== null;
1315
+ //
1316
+ // fix/207 — LIVE, not fixed at boot: the person can answer in the app (Sync details / the
1317
+ // canvas-waiting card → `POST /_api/sync/code-consent/set`) or re-link in a terminal, and the
1318
+ // next pass admits what was held (the file plane reads `allowCodeModules()` at every gate).
1319
+ // The control re-reads the profile's hubs.json through `getHubRecord` — the same local record.
1320
+ const codeConsent = createCodeConsentControl({
1321
+ cellPairing: cellPairing !== null,
1322
+ hubUrl: linkedHub.url,
1323
+ env: process.env,
1324
+ });
1325
+ const allowCodeModules = (): boolean => codeConsent.allowed();
1300
1326
  // Same shape of consent for the OUTBOUND delete breaker: only what this
1301
1327
  // machine's owner recorded (`maude design bulk-deletes on`), never the hub.
1302
1328
  const unlimitedDeletes = storedRecord?.unlimitedDeletes === true;
@@ -1937,6 +1963,8 @@ export function createSyncRuntime(
1937
1963
  * Built with the plane; never in a cell (a cell IS the hub).
1938
1964
  */
1939
1965
  let heldReporter: ReturnType<typeof createHeldReporter> | null = null;
1966
+ /** Issue #207 (7b) — Delete on the hub too / Keep on the hub, for the held local deletes. */
1967
+ let heldDeletesControl: HeldDeletesControl | null = null;
1940
1968
  /** Cumulative files sent up this boot — the doručenka's push half. */
1941
1969
  let filePushed = 0;
1942
1970
  /** Debounce for a plane pass triggered by a local write. */
@@ -1950,6 +1978,7 @@ export function createSyncRuntime(
1950
1978
  let pokesSeen = 0;
1951
1979
  /** Assigned by `start()`; the seam `pullRemoteNow()` and tests reach. */
1952
1980
  let remotePull: (() => Promise<void>) | null = null;
1981
+ let codeConsentUnwatch: (() => void) | null = null;
1953
1982
  let documentDiscovery: ReturnType<typeof createDocumentDiscovery> | null = null;
1954
1983
  let documentDiscoveryUnsub: (() => void) | null = null;
1955
1984
  /**
@@ -5314,7 +5343,9 @@ export function createSyncRuntime(
5314
5343
  // Issue #204 — rows this Mac refuses are HELD, not waiting: they never move on their own, so
5315
5344
  // the line says how many and why instead of "N waiting" every 20 s forever.
5316
5345
  const held = p.held ?? 0;
5317
- if (held > 0) bits.push(`${held} held: shared code not accepted on this Mac`);
5346
+ // fix/207 — one phrase per reason: a PNG deleted here is never "shared code" (Michal's
5347
+ // 6 942 "held: shared code not accepted" were mostly render PNGs moved out of the project).
5348
+ if (held > 0) bits.push(...heldWords(p));
5318
5349
  if (r.backedOff) bits.push(`${r.backedOff} backing off`);
5319
5350
  if (r.storageMisses) bits.push(`${r.storageMisses} still coming from cloud storage`);
5320
5351
  // NOTHING MOVING ⇒ SAY IT ONCE. A converged or only-held/blocked project prints its line when
@@ -5428,6 +5459,18 @@ export function createSyncRuntime(
5428
5459
  // target user never opens a terminal — so a control whose only output
5429
5460
  // is a log line is a control nobody can act on.
5430
5461
  const held = filePlaneHeld(result);
5462
+ // fix/207 — what THIS Mac holds by its own answer, with the one place to change it (Sync
5463
+ // details' "Allow shared code…"). Not while allowed: the next pass is already bringing them.
5464
+ if (!allowCodeModules()) {
5465
+ const codeHeld = codeConsentHeldPaths(fileLedger?.rows() ?? {});
5466
+ if (codeHeld.length > 0)
5467
+ held.push({
5468
+ kind: 'code-consent',
5469
+ count: codeHeld.length,
5470
+ paths: codeHeld.slice(0, 200),
5471
+ detail: codeConsentHeldDetail(codeHeld.length),
5472
+ });
5473
+ }
5431
5474
  // THE DENOMINATOR, from the LEDGER — not from this pass.
5432
5475
  //
5433
5476
  // `fileTotals` below is derived from per-pass results, and a pass that
@@ -5461,6 +5504,8 @@ export function createSyncRuntime(
5461
5504
  // Read once: calling it inside the spread evaluated it twice and made
5462
5505
  // its `null` case the object's type.
5463
5506
  const blockedMedia = filePlane?.blocked() ?? null;
5507
+ const ignoreFoldersNow = planeIgnoreFolders();
5508
+ const purgeNow = heldDeletesControl?.view().purge ?? null;
5464
5509
  statusStore?.updateFiles?.({
5465
5510
  ...fileTotals,
5466
5511
  pushed: filePushed,
@@ -5490,6 +5535,11 @@ export function createSyncRuntime(
5490
5535
  },
5491
5536
  }
5492
5537
  : {}),
5538
+ // Issue #207 — a render sequence going up, and the folders the project leaves out.
5539
+ ...(result.largeSequences ? { largeSequences: result.largeSequences } : {}),
5540
+ ...(ignoreFoldersNow.length > 0 ? { ignoreFolders: ignoreFoldersNow } : {}),
5541
+ // Issue #207 (7b) — an owner purge of held deletes in progress (or why it stopped).
5542
+ ...(purgeNow ? { deletePurge: purgeNow } : {}),
5493
5543
  });
5494
5544
  if (result.rateLimited) {
5495
5545
  // Once per boot (the store dedupes by id): a pause is not an error,
@@ -5552,7 +5602,7 @@ export function createSyncRuntime(
5552
5602
  hubUrl: linkedHub.url,
5553
5603
  token: () => token,
5554
5604
  canvasGroups: ctx.cfg.canvasGroups,
5555
- allowCodeModules,
5605
+ allowCodeModules: allowCodeModules(),
5556
5606
  failures: legacyPullFailures,
5557
5607
  }).then((result) => {
5558
5608
  if (!stopped) noteFilePull(result);
@@ -5584,6 +5634,13 @@ export function createSyncRuntime(
5584
5634
  await discovery.flush();
5585
5635
  await pullFilesOnce();
5586
5636
  };
5637
+ // fix/207 — an answer written by ANOTHER writer (a terminal re-link, a second window) is taken
5638
+ // the same way as the in-app one: re-read, and a changed answer runs a pass at once.
5639
+ if (!cellPairing) {
5640
+ codeConsentUnwatch = watchHubsConfig(() => {
5641
+ if (codeConsent.refresh() && !stopped) void remotePull?.().catch(() => {});
5642
+ });
5643
+ }
5587
5644
  remotePollTimer = setInterval(pollRemote, REMOTE_POLL_MS);
5588
5645
  // `setInterval` keeps a Bun process alive; a poll is not a reason for the
5589
5646
  // dev server to refuse to exit.
@@ -5988,7 +6045,10 @@ export function createSyncRuntime(
5988
6045
  // deletes contradicts the model it is selling — you delete a
5989
6046
  // file and it comes back. `linkedHub.propagateDeletes: false`
5990
6047
  // is the per-project opt-out; the breakers hold either way.
5991
- propagateDeletes: linkedHub.propagateDeletes !== false,
6048
+ // Issue #207 — read every pass (like the ignore list): a change in config.json
6049
+ // applies at the next pass, not at the next restart.
6050
+ propagateDeletes: () =>
6051
+ livePropagateDeletes(ctx.paths.repoRoot, linkedHub.propagateDeletes !== false),
5992
6052
  // The answer to a first-anchor hold. A config key rather than a
5993
6053
  // prompt because the hold outlives the pass that raised it, and
5994
6054
  // DDR-177's user has no terminal to answer in.
@@ -5996,6 +6056,8 @@ export function createSyncRuntime(
5996
6056
  linkedHub.resolveFirstAnchor === 'keep-cloud'
5997
6057
  ? { resolveFirstAnchor: linkedHub.resolveFirstAnchor }
5998
6058
  : {}),
6059
+ // Issue #207 — folders the project does not sync (Sync details › Don't sync this folder).
6060
+ ignoreFolders: planeIgnoreFolders,
5999
6061
  // Same exposure class as `syncMeta.by`, and the same reasoning:
6000
6062
  // a conflict copy nobody can attribute is a conflict copy nobody
6001
6063
  // resolves.
@@ -6009,6 +6071,21 @@ export function createSyncRuntime(
6009
6071
  send: (rels) =>
6010
6072
  reportHeld({ fetchImpl: hubFetch, base: linkedHub.url, token, rels }),
6011
6073
  });
6074
+ // Issue #207 (7b) — the answer to "Deleted on this Mac, held". The role only decides
6075
+ // which door to TRY (the hub's own check decides the rest); the count of deletes this
6076
+ // Mac sent is its ledger's outbound window.
6077
+ {
6078
+ const ledgerNow = fileLedger;
6079
+ heldDeletesControl = createHeldDeletes({
6080
+ plane: () => filePlane,
6081
+ sentInWindow: () => ledgerNow.deletesInWindow('out', DELETE_BUDGET_WINDOW_MS),
6082
+ isOwner: () => isProjectOwner,
6083
+ hubUrl: linkedHub.url,
6084
+ token: () => token,
6085
+ fetchImpl: hubFetch,
6086
+ runPass: () => schedulePlanePass(),
6087
+ });
6088
+ }
6012
6089
  console.log(
6013
6090
  '[sync/files] journal file plane active — one lane, both directions, per-file delivery state in the Sync panel.'
6014
6091
  );
@@ -6087,6 +6164,7 @@ export function createSyncRuntime(
6087
6164
  fileLedger = null;
6088
6165
  filePlane = null;
6089
6166
  heldReporter = null;
6167
+ heldDeletesControl = null;
6090
6168
  // The control channel is a doorbell into this runtime; it goes with it.
6091
6169
  // Reported on the way out so the poke-miss question is answerable from a
6092
6170
  // session's log rather than from a hunch (DDR-226 §10).
@@ -6129,6 +6207,8 @@ export function createSyncRuntime(
6129
6207
  documentDiscoveryUnsub?.();
6130
6208
  documentDiscoveryUnsub = null;
6131
6209
  projectConfigUnsub?.();
6210
+ codeConsentUnwatch?.();
6211
+ codeConsentUnwatch = null;
6132
6212
  documentDiscovery?.stop();
6133
6213
  documentDiscovery = null;
6134
6214
  remotePull = null;
@@ -6273,6 +6353,8 @@ export function createSyncRuntime(
6273
6353
  }),
6274
6354
  rescanNow: () => discoveryRescan?.flush() ?? Promise.resolve(),
6275
6355
  pullRemoteNow: () => remotePull?.() ?? Promise.resolve(),
6356
+ codeConsent: () => codeConsent,
6357
+ heldDeletes: () => heldDeletesControl,
6276
6358
  // Under sharedDoc the per-canvas handler is a projection, not an agent;
6277
6359
  // count both so size() reflects the synced-canvas count in either mode.
6278
6360
  size: () => agents.size + projections.size,
@@ -6938,9 +7020,11 @@ export function filePlaneHeld(
6938
7020
  kind: result.deleteHeld.direction === 'out' ? 'delete-out' : 'delete-in',
6939
7021
  count: result.deleteHeld.count,
6940
7022
  paths: result.deleteHeld.paths,
7023
+ ...(result.deleteHeld.folders ? { folders: result.deleteHeld.folders } : {}),
6941
7024
  detail:
6942
7025
  result.deleteHeld.direction === 'out'
6943
- ? `${result.deleteHeld.count} files are gone from this machine — more than sync will remove from the project without you saying so. Nothing was deleted anywhere else. Set linkedHub.propagateDeletes: false to stop asking, or delete them again once you have confirmed this was deliberate.`
7026
+ ? // Issue #207 (7b) — the row's two buttons are the answer (Delete on the hub too · Keep on the hub).
7027
+ heldDeleteDetail(result.deleteHeld.count, result.deleteHeld.folders ?? [])
6944
7028
  : `The project wants to remove ${result.deleteHeld.count} files here — more than sync will delete without you saying so. Nothing was removed. They stay until you accept or the project puts them back.`,
6945
7029
  });
6946
7030
  }