@1agh/maude 2.0.4 → 2.0.6

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 (129) hide show
  1. package/apps/hub/src/project-transactions/kernel.mjs +10 -1
  2. package/apps/studio/access/filters.ts +12 -5
  3. package/apps/studio/access/known-canvases.ts +24 -1
  4. package/apps/studio/access/refused-inputs.ts +89 -0
  5. package/apps/studio/actions/agents.ts +5 -0
  6. package/apps/studio/actions/defs/app.ts +12 -0
  7. package/apps/studio/actions.manifest.json +13 -1
  8. package/apps/studio/actions.parity.json +7 -1
  9. package/apps/studio/annotations/ui/element-node.tsx +139 -54
  10. package/apps/studio/annotations/ui/lod.tsx +1 -1
  11. package/apps/studio/annotations/ui/text-style.ts +1 -1
  12. package/apps/studio/annotations-layer.tsx +0 -12
  13. package/apps/studio/api.ts +42 -0
  14. package/apps/studio/artboard-live-gate.tsx +267 -0
  15. package/apps/studio/artboard-live.ts +336 -0
  16. package/apps/studio/artboard-webgl.ts +668 -0
  17. package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
  18. package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
  19. package/apps/studio/bin/_canvas-reasons.mjs +34 -0
  20. package/apps/studio/bin/_ds-check-live.mjs +37 -0
  21. package/apps/studio/bin/_ds-check.mjs +4 -1
  22. package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
  23. package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
  24. package/apps/studio/bin/_import-asset.mjs +2 -1
  25. package/apps/studio/bin/_perf-probe.mjs +2 -1
  26. package/apps/studio/bin/_studio-verb.mjs +24 -3
  27. package/apps/studio/bin/_thumb-blank.mjs +70 -0
  28. package/apps/studio/bin/_thumb-cover.mjs +35 -0
  29. package/apps/studio/bin/_thumbs-playwright.mjs +89 -12
  30. package/apps/studio/bin/ds-check.sh +5 -1
  31. package/apps/studio/bin/perf.sh +11 -1
  32. package/apps/studio/bin/server-up.sh +7 -2
  33. package/apps/studio/bin/smoke.sh +19 -0
  34. package/apps/studio/canvas-lib.tsx +131 -12
  35. package/apps/studio/client/canvas-url.js +13 -0
  36. package/apps/studio/client/home/HomeAccounts.jsx +262 -0
  37. package/apps/studio/client/home/Shelves.jsx +4 -3
  38. package/apps/studio/client/home/home-accounts-model.js +121 -0
  39. package/apps/studio/client/home/home-api.js +6 -0
  40. package/apps/studio/client/home/home-app.jsx +141 -40
  41. package/apps/studio/client/home/home-model.js +172 -6
  42. package/apps/studio/client/home/home.css +169 -5
  43. package/apps/studio/client/home/shell-mode.js +8 -1
  44. package/apps/studio/client/hooks/use-project-data.jsx +2 -0
  45. package/apps/studio/client/panels/ChatPanel.jsx +27 -20
  46. package/apps/studio/client/panels/CreateProject.jsx +19 -5
  47. package/apps/studio/client/panels/caps-cache.js +46 -0
  48. package/apps/studio/client/shell/viewport.jsx +36 -8
  49. package/apps/studio/client/v2/access/access-client.js +2 -0
  50. package/apps/studio/client/v2/access/access-host.jsx +12 -1
  51. package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
  52. package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
  53. package/apps/studio/client/v2/ai/Composer.jsx +27 -10
  54. package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
  55. package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
  56. package/apps/studio/client/v2/code/code-bus.js +5 -0
  57. package/apps/studio/client/v2/ds/advanced-host.jsx +11 -26
  58. package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
  59. package/apps/studio/client/v2/ds/library-host.jsx +45 -45
  60. package/apps/studio/client/v2/ds/make-host.jsx +13 -15
  61. package/apps/studio/client/v2/ds/off-system-host.jsx +18 -19
  62. package/apps/studio/client/v2/ds/review-host.jsx +7 -1
  63. package/apps/studio/client/v2/ds/truth-host.jsx +15 -17
  64. package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
  65. package/apps/studio/client/v2/history/branch-actions.js +13 -9
  66. package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
  67. package/apps/studio/client/v2/history/git-model.js +3 -1
  68. package/apps/studio/client/v2/history/git-parts.jsx +16 -1
  69. package/apps/studio/client/v2/presence/faces.jsx +42 -14
  70. package/apps/studio/client/v2/shell/account-card.jsx +10 -4
  71. package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
  72. package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
  73. package/apps/studio/client/v2/shell/menu-runner.js +11 -0
  74. package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
  75. package/apps/studio/client/v2/shell/project-account-model.js +182 -0
  76. package/apps/studio/client/v2/shell/share-cluster-host.jsx +137 -10
  77. package/apps/studio/client/v2/shell/share-cluster.css +58 -0
  78. package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
  79. package/apps/studio/client/v2/shell/team-switch.js +94 -0
  80. package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
  81. package/apps/studio/client/v2/shell/use-account.js +8 -1
  82. package/apps/studio/collab/persistence.ts +9 -1
  83. package/apps/studio/collab/registry.ts +32 -0
  84. package/apps/studio/collab/room.ts +8 -0
  85. package/apps/studio/config-reload-wire.ts +53 -0
  86. package/apps/studio/dist/client.bundle.js +1232 -1232
  87. package/apps/studio/dist/styles.css +1 -1
  88. package/apps/studio/ds/board/specimen.tsx +12 -1
  89. package/apps/studio/ds/canvas-cli.ts +58 -2
  90. package/apps/studio/ds/check.ts +26 -1
  91. package/apps/studio/ds/cli.ts +7 -3
  92. package/apps/studio/ds/convert.ts +34 -6
  93. package/apps/studio/ds/ds-verb.ts +13 -0
  94. package/apps/studio/ds/post-build.ts +38 -0
  95. package/apps/studio/ds/upgrade-apply.ts +27 -5
  96. package/apps/studio/ds/upgrade-cli.ts +22 -2
  97. package/apps/studio/ds/upgrade-prove.ts +198 -15
  98. package/apps/studio/ds/upgrade-stage.ts +4 -1
  99. package/apps/studio/history/trash.ts +6 -0
  100. package/apps/studio/home/accounts.ts +87 -0
  101. package/apps/studio/home/index-reader.ts +24 -2
  102. package/apps/studio/home/routes.ts +19 -0
  103. package/apps/studio/http.ts +14 -2
  104. package/apps/studio/routes/ds-convert.ts +18 -0
  105. package/apps/studio/routes/trash.ts +16 -1
  106. package/apps/studio/server.ts +8 -10
  107. package/apps/studio/sync/accepted-cold-start.ts +28 -13
  108. package/apps/studio/sync/asset-push.ts +146 -23
  109. package/apps/studio/sync/asset-state.ts +3 -2
  110. package/apps/studio/sync/file-membership.ts +28 -3
  111. package/apps/studio/sync/file-plane.ts +40 -9
  112. package/apps/studio/sync/file-pull.ts +304 -33
  113. package/apps/studio/sync/hub-link.ts +1 -2
  114. package/apps/studio/sync/index.ts +308 -150
  115. package/apps/studio/sync/journal-client.ts +94 -5
  116. package/apps/studio/sync/pending-deletes.ts +100 -0
  117. package/apps/studio/sync/projection.ts +77 -12
  118. package/apps/studio/sync/seed-progress.ts +12 -1
  119. package/apps/studio/sync/status.ts +3 -1
  120. package/apps/studio/thumbs/service.ts +12 -2
  121. package/apps/studio/thumbs/validate.ts +7 -0
  122. package/apps/studio/ui-prefs-migrate.ts +4 -0
  123. package/apps/studio/video-comp.tsx +23 -0
  124. package/apps/studio/whats-new.json +72 -0
  125. package/cli/lib/bash-guard.mjs +13 -1
  126. package/cli/lib/design-help.gen.mjs +1 -1
  127. package/cli/lib/design-hook.mjs +20 -0
  128. package/cli/lib/studio-locate.mjs +35 -10
  129. package/package.json +8 -8
@@ -16,12 +16,12 @@
16
16
  // Output: `diff.json` (every measurement) and `review.json` (the four SCHEMA_FIX lines) beside the
17
17
  // stage record.
18
18
 
19
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
19
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
20
20
  import { tmpdir } from 'node:os';
21
21
  import { basename, dirname, join } from 'node:path';
22
22
  import type { Subprocess } from 'bun';
23
23
  import { exportShimPath, spawnShim } from '../exporters/_runtime.ts';
24
- import { DEV_SERVER_ROOT } from '../paths.ts';
24
+ import { DEV_SERVER_ROOT, IS_COMPILED_BINARY } from '../paths.ts';
25
25
  import { checkCanvas } from './canvas-check.ts';
26
26
  import { canvasContext, listCanvases } from './canvas-cli.ts';
27
27
  import { systemConfigsFrom } from './system.ts';
@@ -46,11 +46,15 @@ export const DIFF_FORMAT = 'maude.ds-upgrade-diff';
46
46
  export const REVIEW_FORMAT = 'maude.ds-upgrade-review';
47
47
  export const DELTA_E = 2;
48
48
  export const FAIL_RATIO = 0.005;
49
+ /** one canvas's hard deadline in the visual gate */
50
+ export const CANVAS_TIMEOUT = 180_000;
49
51
 
50
52
  export interface RenderCanvas {
51
53
  path: string;
52
54
  tokens: string | null;
53
55
  components: string | null;
56
+ /** the system's themes: an artboard that carries none of its own is measured in each */
57
+ themes?: string[];
54
58
  }
55
59
  export interface RenderJob {
56
60
  before: string;
@@ -59,6 +63,8 @@ export interface RenderJob {
59
63
  deltaE: number;
60
64
  ratio: number;
61
65
  timeout: number;
66
+ /** the hard deadline of one canvas (ms): past it the canvas is `timeout` and the run goes on */
67
+ canvasTimeout?: number;
62
68
  }
63
69
  export interface ArtboardDiff {
64
70
  id: string;
@@ -69,9 +75,23 @@ export interface ArtboardDiff {
69
75
  area?: number;
70
76
  fail: boolean;
71
77
  reason?: string;
78
+ /** failed before x after, but before x before failed alike: the gate's own noise, not a change */
79
+ noise?: boolean;
80
+ /** nothing rendered on either side */
81
+ empty?: boolean;
82
+ /** before x before (the noise control), when it ran */
83
+ control?: { changed: number; area: number; sized: boolean };
72
84
  }
73
85
  export interface RenderResult {
74
- canvases: { path: string; error?: string; detail?: string; artboards: ArtboardDiff[] }[];
86
+ canvases: {
87
+ path: string;
88
+ /** before / after: that side showed an error; render: the gate threw; timeout: no answer */
89
+ error?: string;
90
+ detail?: string;
91
+ /** no artboard: the canvas's whole mount was measured */
92
+ specimen?: boolean;
93
+ artboards: ArtboardDiff[];
94
+ }[];
75
95
  }
76
96
 
77
97
  export interface Studio {
@@ -114,18 +134,117 @@ export interface Review {
114
134
  keepsOwn: { native: string; as: string }[];
115
135
  updatesCanvases: { path: string; edits: number; diff: 'pass' | 'fail' }[];
116
136
  refused: { path: string; reason: string }[];
137
+ /** canvases the gate could not measure (a timeout, a broken before): they block nothing, and a
138
+ * codemod on one is not applied (it is in `refused` too) */
139
+ unmeasured?: { path: string; reason: string }[];
117
140
  needsPick: string[];
118
141
  }
119
142
 
120
143
  /* ------------------------------------------------------------- studios */
121
144
 
122
- function serverCommand(): string[] {
123
- const serverTs = join(DEV_SERVER_ROOT, 'server.ts');
124
- if (!existsSync(serverTs)) return [process.execPath]; // the compiled studio binary IS the server
125
- const bun = basename(process.execPath).startsWith('bun')
126
- ? process.execPath
127
- : (Bun.which('bun') ?? process.execPath);
128
- return [bun, 'run', serverTs];
145
+ /** A compiled studio by its shape: the desktop sidecar `maude-server`, or npm's `maude-<slug>/maude`. */
146
+ export function isCompiledStudioBinary(p: string | undefined | null): boolean {
147
+ if (!p) return false;
148
+ const b = basename(p);
149
+ if (b === 'maude-server' || b === 'maude-server.exe') return true;
150
+ return (b === 'maude' || b === 'maude.exe') && /^maude-[a-z0-9-]+$/.test(basename(dirname(p)));
151
+ }
152
+
153
+ export interface ServerResolveInput {
154
+ env: Record<string, string | undefined>;
155
+ /** this process's executable (the compiled studio, a compiled binary run as bun, or bun) */
156
+ execPath: string;
157
+ /** apps/studio as paths.ts resolved it */
158
+ devServerRoot: string;
159
+ /** true inside the compiled studio itself (paths.ts IS_COMPILED_BINARY) */
160
+ compiled: boolean;
161
+ exists: (p: string) => boolean;
162
+ readText?: (p: string) => string | null;
163
+ /** npm platform-package slugs to look for (`darwin-arm64`, `linux-x64`, `linux-x64-musl`…) */
164
+ platformSlugs?: string[];
165
+ }
166
+
167
+ export interface ServerCommand {
168
+ cmd: string[];
169
+ /** env the compiled studio needs to find its served tree (the desktop sidecar sets the same) */
170
+ env: Record<string, string>;
171
+ kind: 'compiled' | 'source';
172
+ }
173
+
174
+ /**
175
+ * How a staged studio is started — the same resolution the desktop sidecar and `maude design serve`
176
+ * use (DDR-084, DDR-177): the COMPILED studio whenever one exists, because it embeds every dependency
177
+ * the source server imports (the hub's transaction core, jszip, yjs…), none of which a packaged app or
178
+ * an npm install has on disk. Source (`bun run server.ts`) only in a dev tree, or when nothing
179
+ * compiled is there.
180
+ *
181
+ * 1. this process IS the compiled studio (a prove started from the studio's own route)
182
+ * 2. MAUDE_DEV_SERVER_BIN (the desktop sidecar hands it to every child; `maude design` to boot verbs)
183
+ * 3. not a dev tree: this process's executable when it is a compiled studio run as bun (the
184
+ * desktop's bun shim), the .app's Contents/MacOS/maude-server, npm's maude-<slug>/maude
185
+ * 4. server.ts from source
186
+ */
187
+ export function resolveStudioServer(o: ServerResolveInput): ServerCommand {
188
+ const pkgRoot = join(o.devServerRoot, '..', '..');
189
+ const compiledEnv = (): Record<string, string> => ({
190
+ MAUDE_DEV_SERVER_ROOT: o.devServerRoot,
191
+ ...(o.exists(join(pkgRoot, 'cli', 'commands', 'design.mjs'))
192
+ ? { MAUDE_PKG_ROOT: pkgRoot }
193
+ : {}),
194
+ });
195
+ const compiled = (bin: string): ServerCommand => ({
196
+ cmd: [bin],
197
+ env: compiledEnv(),
198
+ kind: 'compiled',
199
+ });
200
+ if (o.compiled && !o.env.BUN_BE_BUN) return compiled(o.execPath);
201
+ const fromEnv = o.env.MAUDE_DEV_SERVER_BIN;
202
+ if (fromEnv && isCompiledStudioBinary(fromEnv) && o.exists(fromEnv)) return compiled(fromEnv);
203
+ const serverTs = join(o.devServerRoot, 'server.ts');
204
+ const devTree =
205
+ o.env.MAUDE_FORCE_SOURCE === '1' ||
206
+ o.exists(join(pkgRoot, 'packages', 'maude-darwin-arm64', 'package.json'));
207
+ if (!devTree) {
208
+ const exe = process.platform === 'win32' ? 'maude-server.exe' : 'maude-server';
209
+ const candidates = [
210
+ o.execPath,
211
+ join(o.devServerRoot, '..', '..', '..', 'MacOS', exe),
212
+ ...(o.platformSlugs ?? []).map((slug) =>
213
+ join(pkgRoot, '..', `maude-${slug}`, process.platform === 'win32' ? 'maude.exe' : 'maude')
214
+ ),
215
+ ];
216
+ const side = o.readText?.(join(pkgRoot, 'cli', '.platform-binary-path'))?.trim();
217
+ if (side) candidates.push(side);
218
+ for (const c of candidates) if (isCompiledStudioBinary(c) && o.exists(c)) return compiled(c);
219
+ }
220
+ if (!o.exists(serverTs)) return compiled(o.execPath); // nothing else to run
221
+ const bun = basename(o.execPath).startsWith('bun')
222
+ ? o.execPath
223
+ : (Bun.which('bun') ?? o.execPath);
224
+ return { cmd: [bun, 'run', serverTs], env: {}, kind: 'source' };
225
+ }
226
+
227
+ function platformSlugs(): string[] {
228
+ const base = `${process.platform}-${process.platform === 'win32' ? 'x64' : process.arch}`;
229
+ return process.platform === 'linux' ? [base, `${base}-musl`] : [base];
230
+ }
231
+
232
+ function serverCommand(): ServerCommand {
233
+ return resolveStudioServer({
234
+ env: process.env,
235
+ execPath: process.execPath,
236
+ devServerRoot: DEV_SERVER_ROOT,
237
+ compiled: IS_COMPILED_BINARY,
238
+ exists: existsSync,
239
+ readText: (p) => {
240
+ try {
241
+ return readFileSync(p, 'utf8');
242
+ } catch {
243
+ return null;
244
+ }
245
+ },
246
+ platformSlugs: platformSlugs(),
247
+ });
129
248
  }
130
249
 
131
250
  /**
@@ -139,15 +258,33 @@ const STAGED_DROP =
139
258
  export function studioEnv(
140
259
  projectRoot: string,
141
260
  machineFile: string,
142
- from: Record<string, string | undefined> = process.env
261
+ from: Record<string, string | undefined> = process.env,
262
+ /** a throwaway home: the staged studio writes prefs (fold state…) under HOME/XDG_CONFIG_HOME,
263
+ * and a staged copy must never write the person's real ~/.config/maude */
264
+ home?: string
143
265
  ): Record<string, string> {
144
266
  // the staged studio picks its own port, and runs as the studio (never as a bare bun)
145
267
  const drop = new Set(['BUN_BE_BUN', 'PORT', 'MDCC_DEV_PORT']);
268
+ // with a throwaway home, nothing may point back at the person's own config stores
269
+ const homeDrop = new Set([
270
+ 'XDG_CONFIG_HOME',
271
+ 'HUBS_CONFIG_PATH',
272
+ 'MAUDE_CLOUD_CONFIG',
273
+ 'MAUDE_INDEX_DIR',
274
+ ]);
146
275
  const env: Record<string, string> = {};
147
276
  for (const [k, v] of Object.entries(from))
148
- if (v !== undefined && !drop.has(k) && !STAGED_DROP.test(k)) env[k] = v;
277
+ if (v !== undefined && !drop.has(k) && !STAGED_DROP.test(k) && !(home && homeDrop.has(k)))
278
+ env[k] = v;
149
279
  return {
150
280
  ...env,
281
+ ...(home
282
+ ? {
283
+ HOME: home,
284
+ XDG_CONFIG_HOME: join(home, '.config'),
285
+ MAUDE_INDEX_DIR: join(home, 'index'),
286
+ }
287
+ : {}),
151
288
  NO_OPEN: '1',
152
289
  MAUDE_NO_AUTOBUILD: '1',
153
290
  MAUDE_MACHINE_FILE: machineFile,
@@ -159,12 +296,35 @@ export function studioEnv(
159
296
  export async function bootHeadlessStudio(projectRoot: string): Promise<Studio> {
160
297
  const designRoot = join(projectRoot, '.design');
161
298
  const scratch = mkdtempSync(join(tmpdir(), 'maude-ds-prove-machine-'));
162
- const proc: Subprocess = Bun.spawn([...serverCommand(), '--root', projectRoot, '--port', '0'], {
299
+ mkdirSync(join(scratch, 'home', '.config'), { recursive: true });
300
+ const server = serverCommand();
301
+ const proc: Subprocess = Bun.spawn([...server.cmd, '--root', projectRoot, '--port', '0'], {
163
302
  cwd: DEV_SERVER_ROOT,
164
- env: studioEnv(projectRoot, join(scratch, 'machine.json')),
303
+ env: {
304
+ ...studioEnv(projectRoot, join(scratch, 'machine.json'), process.env, join(scratch, 'home')),
305
+ ...server.env,
306
+ },
165
307
  stdout: 'ignore',
166
308
  stderr: 'pipe',
167
309
  });
310
+ // drain stderr (an unread pipe can stall a chatty child) and keep its tail for the error
311
+ let errTail = '';
312
+ void (async () => {
313
+ try {
314
+ const dec = new TextDecoder();
315
+ for await (const chunk of proc.stderr as ReadableStream<Uint8Array>)
316
+ errTail = (errTail + dec.decode(chunk)).slice(-2000);
317
+ } catch {
318
+ /* gone */
319
+ }
320
+ })();
321
+ const lastLine = () =>
322
+ errTail
323
+ .trim()
324
+ .split('\n')
325
+ .filter((l) => l.trim())
326
+ .at(-1)
327
+ ?.slice(0, 240) ?? '';
168
328
  const stop = async () => {
169
329
  const exited = proc.exited.then(
170
330
  () => true,
@@ -189,7 +349,13 @@ export async function bootHeadlessStudio(projectRoot: string): Promise<Studio> {
189
349
  try {
190
350
  const started = Date.now();
191
351
  while (Date.now() - started < 60000) {
192
- if (proc.exitCode !== null) throw new Error(`the staged studio exited ${proc.exitCode}`);
352
+ if (proc.exitCode !== null) {
353
+ await Bun.sleep(50); // the last stderr chunk
354
+ const why = lastLine();
355
+ throw new Error(
356
+ `the staged ${server.kind} studio exited ${proc.exitCode}${why ? `: ${why}` : ''}`
357
+ );
358
+ }
193
359
  try {
194
360
  const s = JSON.parse(readFileSync(join(designRoot, '_server.json'), 'utf8')) as {
195
361
  pid?: number;
@@ -252,6 +418,7 @@ function affectedCanvases(stageDir: string, ds: string): RenderCanvas[] {
252
418
  out.push({
253
419
  path: rel,
254
420
  tokens: sys?.tokensCssRel ?? null,
421
+ themes: sys?.themes ?? [],
255
422
  components: sys ? `${sys.path}/preview/_components.css` : null,
256
423
  });
257
424
  }
@@ -271,7 +438,21 @@ function reviewOf(
271
438
  path: r.path,
272
439
  reason: r.invariant,
273
440
  }));
441
+ const unmeasured: { path: string; reason: string }[] = [];
274
442
  for (const c of result.canvases) {
443
+ // A canvas that could not be measured (no answer in time, an error before the upgrade touched
444
+ // anything, the gate itself threw) proves nothing either way: it never blocks the system files,
445
+ // and its own codemod is not applied unproved. `after` alone is a finding: the upgrade broke it.
446
+ // Noise the control explained away is not a failure (`noise`, the shim's judge).
447
+ if (c.error && c.error !== 'after') {
448
+ const reason = c.error === 'timeout' ? 'timeout' : 'unmeasured';
449
+ unmeasured.push({ path: c.path, reason });
450
+ if (codemodded.has(c.path)) {
451
+ failedCanvases.add(c.path);
452
+ refused.push({ path: c.path, reason });
453
+ }
454
+ continue;
455
+ }
275
456
  const failed = c.error === 'after' || c.artboards.some((a) => a.fail);
276
457
  if (!failed) continue;
277
458
  if (codemodded.has(c.path)) {
@@ -317,6 +498,7 @@ function reviewOf(
317
498
  diff: failedCanvases.has(c.path) ? 'fail' : 'pass',
318
499
  })),
319
500
  refused,
501
+ ...(unmeasured.length ? { unmeasured } : {}),
320
502
  needsPick: items.filter((i) => i.status === 'needs-pick' && i.picked == null).map((i) => i.id),
321
503
  };
322
504
  return { review, failedCanvases };
@@ -390,6 +572,7 @@ export async function proveStage(
390
572
  deltaE: DELTA_E,
391
573
  ratio: FAIL_RATIO,
392
574
  timeout: 20000,
575
+ canvasTimeout: CANVAS_TIMEOUT,
393
576
  },
394
577
  {
395
578
  signal: ctl.signal,
@@ -189,7 +189,10 @@ export function systemOf(designRoot: string, ds: string): SystemConfig {
189
189
  /** `<designRoot>/_state/ds-upgrade/<ds>/<stamp>` — the stamp is digits only (never a path). */
190
190
  export function stateDirOf(designRoot: string, ds: string, stamp: string): string {
191
191
  if (!/^[0-9]{1,20}(?:-[0-9]{1,4})?$/.test(stamp))
192
- throw new DsUpgradeError('ds-upgrade-usage', 'a stage is named by its stamp');
192
+ throw new DsUpgradeError(
193
+ 'ds-upgrade-usage',
194
+ 'a stage is named by its stamp: the digits `ds-upgrade <ds> --stage` printed as "stamp" (`ds-upgrade <ds> --status` lists them; the record is _state/ds-upgrade/<ds>/<stamp>/)'
195
+ );
193
196
  return join(designRoot, STATE_REL, ds, stamp);
194
197
  }
195
198
 
@@ -93,6 +93,12 @@ export interface CanvasItem extends StoreCanvasItem, ItemWho {
93
93
  id: `canvas:${string}`;
94
94
  kind: 'canvas';
95
95
  group: 'today' | 'earlier';
96
+ /**
97
+ * A live canvas holds this item's path right now (one made again at the old place): this is an OLDER
98
+ * copy, not the canvas a tab has open. The "moved to the trash" bar never shows for it. Set by
99
+ * GET /_api/trash (routes/trash.ts); absent when the home cannot list live documents.
100
+ */
101
+ liveAtPath?: boolean;
96
102
  }
97
103
 
98
104
  export interface ArtboardItem extends StoreArtboardItem, ItemWho {
@@ -0,0 +1,87 @@
1
+ // home/accounts.ts — 2.0.5 W4b: the accounts each profile on this Mac is signed in with, for Home's
2
+ // avatar, and the per-account sign-outs it offers.
3
+ //
4
+ // GET /_home/accounts?profiles=a,b → { ok, profiles: [{ id, hubs: [{ url, account }] }] }
5
+ // POST /_home/hub/signout { profile, url } → forget that profile's sign-in for that server
6
+ // POST /_home/cloud/signout { profile } → forget that profile's Maude Cloud sign-in
7
+ //
8
+ // Public handles only: a server address and the account the server vouched for at sign-in
9
+ // (`hubs.json` `account`, display data) — never a token. A profile id is `[a-z0-9-]{1,32}`
10
+ // (`profileHubsPath` refuses anything else); a profile's files are named from its id the same way
11
+ // `profiles.rs` `paths_in` names them. A sign-out removes ONE credential from that profile's own
12
+ // file (atomic, 0600) — the project servers watch `hubs.json` and drop the link's sync themselves.
13
+ // Home serves every profile, so it never reads its own process-global path for a non-default one.
14
+
15
+ import { existsSync, unlinkSync } from 'node:fs';
16
+
17
+ import { deleteHubCredential } from '../sync/hub-link.ts';
18
+ import { loadHubsConfig, normalizeUrl, safeAccount } from '../sync/hubs-config.ts';
19
+ import { profileCloudPath, profileHubsPath } from './cloud.ts';
20
+ import type { HomeAnswer } from './signin.ts';
21
+
22
+ const MAX_PROFILES = 16;
23
+ const MAX_HUBS = 50;
24
+
25
+ export interface ProfileHubs {
26
+ id: string;
27
+ hubs: Array<{ url: string; account: string | null }>;
28
+ }
29
+
30
+ /** Each named profile's team-server sign-ins (no tokens). Unknown / invalid ids are skipped. */
31
+ export function profileAccounts(ids: string[]): ProfileHubs[] {
32
+ const out: ProfileHubs[] = [];
33
+ for (const id of [...new Set(ids)].slice(0, MAX_PROFILES)) {
34
+ const file = profileHubsPath(id);
35
+ if (!file) continue;
36
+ let hubs: ProfileHubs['hubs'] = [];
37
+ try {
38
+ const cfg = loadHubsConfig(file);
39
+ hubs = Object.entries(cfg.hubs ?? {})
40
+ .filter(([, rec]) => rec && typeof rec.token === 'string' && rec.token)
41
+ .slice(0, MAX_HUBS)
42
+ .map(([url, rec]) => ({ url, account: safeAccount(rec.account) }));
43
+ } catch {
44
+ hubs = [];
45
+ }
46
+ out.push({ id, hubs });
47
+ }
48
+ return out;
49
+ }
50
+
51
+ const bad = (error: string): HomeAnswer => ({ status: 400, body: { ok: false, error } });
52
+
53
+ export function createHomeAccounts(deps: { forgetCloud?: (profile: string) => void } = {}) {
54
+ return {
55
+ list(param: string | null): HomeAnswer {
56
+ const ids = (param ?? '').split(',').filter(Boolean);
57
+ return { status: 200, body: { ok: true, profiles: profileAccounts(ids) } };
58
+ },
59
+
60
+ hubSignOut(b: Record<string, unknown>): HomeAnswer {
61
+ const profile = typeof b.profile === 'string' ? b.profile : '';
62
+ const file = profileHubsPath(profile);
63
+ if (!file) return bad('That account isn’t on this Mac.');
64
+ let url: string;
65
+ try {
66
+ url = normalizeUrl(String(b.url ?? ''));
67
+ } catch {
68
+ return bad('That server address isn’t valid.');
69
+ }
70
+ deleteHubCredential(url, file);
71
+ return { status: 200, body: { ok: true } };
72
+ },
73
+
74
+ cloudSignOut(b: Record<string, unknown>): HomeAnswer {
75
+ const profile = typeof b.profile === 'string' ? b.profile : '';
76
+ const file = profileCloudPath(profile);
77
+ if (!file) return bad('That account isn’t on this Mac.');
78
+ try {
79
+ if (existsSync(file)) unlinkSync(file);
80
+ } catch {
81
+ return { status: 500, body: { ok: false, error: 'Couldn’t sign out. Try again.' } };
82
+ }
83
+ deps.forgetCloud?.(profile);
84
+ return { status: 200, body: { ok: true } };
85
+ },
86
+ };
87
+ }
@@ -67,6 +67,13 @@ export interface HomeProjectIndex {
67
67
  linkedHub: { url: string } | null;
68
68
  managed: boolean;
69
69
  };
70
+ /**
71
+ * 2.0.5 W4b — the realpath of the project's design root, so Home shows two folders that share
72
+ * one `.design` (a symlink) as ONE project. Set for `ok`, and for a `mismatch` whose root IS this
73
+ * pid but whose design dir resolves elsewhere through a symlink (nothing is read there — W5 — the
74
+ * path is only compared). Never for a snapshot that names another folder.
75
+ */
76
+ designReal?: string;
70
77
  counts?: ProjectIndexSnapshot['counts'];
71
78
  canvases?: HomeCanvasRow[];
72
79
  }
@@ -82,7 +89,12 @@ export function resolveProject(
82
89
  snap: ProjectIndexSnapshot | null = readSnapshot(pid)
83
90
  ):
84
91
  | { ok: true; snap: ProjectIndexSnapshot; root: string; designRoot: string }
85
- | { ok: false; state: Exclude<HomeProjectState, 'ok'>; snap: ProjectIndexSnapshot | null } {
92
+ | {
93
+ ok: false;
94
+ state: Exclude<HomeProjectState, 'ok'>;
95
+ snap: ProjectIndexSnapshot | null;
96
+ designReal?: string;
97
+ } {
86
98
  if (!snap || snap.pid !== pid) return { ok: false, state: 'missing', snap: null };
87
99
  const root = snap.project?.root;
88
100
  const designRel = snap.project?.designRel;
@@ -115,7 +127,15 @@ export function resolveProject(
115
127
  } catch {
116
128
  return { ok: false, state: 'gone', snap };
117
129
  }
118
- if (st.isSymbolicLink()) return { ok: false, state: 'mismatch', snap };
130
+ if (st.isSymbolicLink()) {
131
+ let designReal: string | undefined;
132
+ try {
133
+ designReal = realpathSync(designRoot);
134
+ } catch {
135
+ designReal = undefined;
136
+ }
137
+ return { ok: false, state: 'mismatch', snap, ...(designReal ? { designReal } : {}) };
138
+ }
119
139
  }
120
140
  if (!existsSync(designRoot)) return { ok: false, state: 'gone', snap };
121
141
  return { ok: true, snap, root: real, designRoot };
@@ -191,6 +211,7 @@ export function readHomeIndex(pids: string[], running: ReadonlySet<string> = new
191
211
  pid,
192
212
  state: r.state,
193
213
  stale: false,
214
+ ...(r.designReal ? { designReal: r.designReal } : {}),
194
215
  ...(snap
195
216
  ? {
196
217
  project: {
@@ -232,6 +253,7 @@ export function readHomeIndex(pids: string[], running: ReadonlySet<string> = new
232
253
  state: 'ok',
233
254
  stale,
234
255
  ...(rebuilt ? { rebuilt } : {}),
256
+ designReal: r.designRoot,
235
257
  project: {
236
258
  root: r.root,
237
259
  name: snap.project.name,
@@ -42,6 +42,7 @@ import { HUB_SIGNIN_RETURN_PATH, returnPage } from '../sync/hub-browser-signin.t
42
42
  import { thumbNotFound, thumbResponse } from '../thumbs/routes.ts';
43
43
  import { checkJpeg } from '../thumbs/validate.ts';
44
44
  import { isLoopbackHost } from '../ws.ts';
45
+ import { createHomeAccounts } from './accounts.ts';
45
46
  import { createHomeAi, type HomeAi } from './ai.ts';
46
47
  import { createHomeCli, type HomeCli } from './cli.ts';
47
48
  import type { HomeCloud } from './cloud.ts';
@@ -281,6 +282,7 @@ export function homeRouteTable(deps: HomeDeps): HomeRoute[] {
281
282
  const cli = deps.cli ?? createHomeCli();
282
283
  const whatsNew = deps.whatsNew ?? createHomeWhatsNew();
283
284
  const github = deps.github ?? createHomeGithub();
285
+ const accounts = createHomeAccounts({ forgetCloud: (p) => deps.cloud.forget(p) });
284
286
  return [
285
287
  {
286
288
  method: 'GET',
@@ -481,6 +483,23 @@ export function homeRouteTable(deps: HomeDeps): HomeRoute[] {
481
483
  ),
482
484
  post('/_home/hub/signin/poll', 'home', (b) => hub.signInPoll(b)),
483
485
  post('/_home/hub/signin/cancel', 'home', (b) => hub.signInCancel(b)),
486
+ // 2.0.5 W4b — Home's avatar: each profile's team-server sign-ins (no tokens), and a sign-out per
487
+ // account (one credential out of that profile's own file)
488
+ {
489
+ method: 'GET',
490
+ path: '/_home/accounts',
491
+ kind: 'home',
492
+ handle: (_req, url) => {
493
+ const r = accounts.list(url.searchParams.get('profiles'));
494
+ return json(r.status, r.body);
495
+ },
496
+ },
497
+ post('/_home/hub/signout', 'home', (b) =>
498
+ accounts.hubSignOut((b ?? {}) as Record<string, unknown>)
499
+ ),
500
+ post('/_home/cloud/signout', 'home', (b) =>
501
+ accounts.cloudSignOut((b ?? {}) as Record<string, unknown>)
502
+ ),
484
503
  get('/_home/ai/status', () => ai.status()),
485
504
  post('/_home/ai/connect', 'home', (b) => ai.connect(b)),
486
505
  get('/_home/cli/status', () => cli.status()),
@@ -60,6 +60,7 @@ import {
60
60
  verifyFrameCap,
61
61
  } from './access/frame.ts';
62
62
  import { closureConfigFor } from './access/known-canvases.ts';
63
+ import { entryRel, refusedDesignInputs, refusedInputsFor } from './access/refused-inputs.ts';
63
64
  import {
64
65
  ACP_REFUSAL,
65
66
  accessForDesktop,
@@ -7962,8 +7963,19 @@ export function createHttp(
7962
7963
  function canvasInputsGate(req: Request): CanvasInputsGate | undefined {
7963
7964
  const see = seerFor(req);
7964
7965
  if (see === null) return undefined;
7965
- const gate: CanvasInputsGate = (inputs, entry) =>
7966
- inputsRefusal(inputs, designRoots, see, { entry });
7966
+ const gate: CanvasInputsGate = (inputs, entry) => {
7967
+ const refused = inputsRefusal(inputs, designRoots, see, { entry });
7968
+ // 2.0.5 (#205) — keep WHY on the server, per canvas; the main origin's /_index-data reports it
7969
+ // (`canvasRefusedInputs`). The answer here stays the bare not-in-scope body.
7970
+ const canvas = entryRel(entry, designRoots);
7971
+ if (canvas) {
7972
+ const names = refused ? refusedDesignInputs(inputs, designRoots, see) : [];
7973
+ const store = refusedInputsFor(ctx);
7974
+ const changed = names.length ? store.record(canvas, names) : store.clear(canvas);
7975
+ if (changed) ctx.bus.emit('canvas-list-update', { action: 'refused', rel: canvas });
7976
+ }
7977
+ return refused;
7978
+ };
7967
7979
  // gate-b-c4l (L-b) — a canvas whose import walk the closure blocked is refused before the build.
7968
7980
  gate.before = (entry) => {
7969
7981
  const closure = closureOf(accessOf(req));
@@ -9,10 +9,27 @@
9
9
  // Permissions (S10 Q15, V2-1.6 §5.12, rule 12): convert and Restore need Can edit on the WHOLE
10
10
  // project; a canvas-scoped grant is refused, the dry run included (it lists every system).
11
11
 
12
+ import { canvasSlugFromRel } from '../canvas-slug.ts';
12
13
  import { createDsConvert, DsConvertError } from '../ds/convert.ts';
14
+ import { DS_CANVAS } from '../ds/engine.ts';
13
15
  import type { DsOpAnswer, DsOpContext } from './ds.ts';
14
16
 
15
17
  const invalid = (m: string) => new DsConvertError('ds-convert-usage', m);
18
+
19
+ /**
20
+ * fix/ds-convert-hooks-cli #7 — Restore moved the Design system canvas to the Trash: say so the way
21
+ * the canvas delete route does. `canvas-deleted` is what sync turns into a project deletion (a
22
+ * tombstone); a bare rename is only "gone from this disk", and the hub brought the canvas straight
23
+ * back (and with it, on the next convert, `ds-convert-exists`).
24
+ */
25
+ function noteDsCanvasTrashed(c: DsOpContext, system: string): void {
26
+ const s = c.engine.systems().find((x) => x.name === system);
27
+ if (!s || !c.emit) return;
28
+ const rel = `${s.path}/${DS_CANVAS}`;
29
+ const slug = canvasSlugFromRel(rel, '');
30
+ c.emit('canvas-list-update', { action: 'removed', rel, slug });
31
+ c.emit('canvas-deleted', { slug });
32
+ }
16
33
  const NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
17
34
 
18
35
  export async function runConvertOp(
@@ -33,6 +50,7 @@ export async function runConvertOp(
33
50
  const r = await cv.restore({ ds: input.restore, by: c.by });
34
51
  c.outside?.invalidate(r.system);
35
52
  c.emit?.('ds:changed', { system: r.system });
53
+ if (r.moved.includes(DS_CANVAS)) noteDsCanvasTrashed(c, r.system);
36
54
  return { status: 200, body: { format: 'maude.ds-result', v: 1, ...r } };
37
55
  }
38
56
  let systems: string[] | undefined;
@@ -276,10 +276,25 @@ export function createTrashRoutes(deps: TrashRouteDeps): RouteSpec[] {
276
276
  if (!runtime?.acceptedTrash) return null;
277
277
  const listing = await runtime.acceptedTrash().catch(() => undefined);
278
278
  if (!listing) return listing;
279
- return visibleTrash(
279
+ const items = visibleTrash(
280
280
  deriveTrash(listing, { readSource: deps.readSource, now: deps.now?.() }),
281
281
  access
282
282
  );
283
+ // 2.0.5: which canvas items sit at the path of a LIVE canvas (the same test the write stop uses) —
284
+ // they are older copies, never "the canvas you have open, moved to the trash".
285
+ const linkDocs = (
286
+ runtime as {
287
+ acceptedLinkDocs?(): Promise<{ path: string | null; retired: boolean }[] | null>;
288
+ }
289
+ ).acceptedLinkDocs;
290
+ const docs = linkDocs ? await linkDocs.call(runtime).catch(() => null) : null;
291
+ if (!docs) return items;
292
+ const live = new Set(
293
+ docs.filter((d) => !d.retired && d.path).map((d) => canvasStemOf(d.path as string))
294
+ );
295
+ return items.map((i) =>
296
+ i.kind === 'canvas' ? { ...i, liveAtPath: live.has(canvasStemOf(i.path)) } : i
297
+ );
283
298
  }
284
299
 
285
300
  return [
@@ -49,7 +49,8 @@ import { type AiActivityEntry, createAiActivity } from './collab/ai-activity.ts'
49
49
  import { createGitLifecycle } from './collab/git-lifecycle.ts';
50
50
  import { personHoldsOf } from './collab/holds.ts';
51
51
  import { createCollab } from './collab/index.ts';
52
- import { createContext, reloadConfig } from './context.ts';
52
+ import { wireConfigReload } from './config-reload-wire.ts';
53
+ import { createContext } from './context.ts';
53
54
  import { installLogRing } from './debug-bundle.ts';
54
55
  import { initDiagnostics, registerStatus, stopDiagnostics } from './diagnostics/store.ts';
55
56
  import { parseEmbedOrigins } from './embed-origins.ts';
@@ -1127,18 +1128,15 @@ const canvasListWatch = createCanvasListWatch(ctx);
1127
1128
  // canvasListWatch's set-diff emit `canvas-list-update` for canvases the new
1128
1129
  // groups uncover, and tell shells to refetch /_config.
1129
1130
  // RCA: .ai/logs/rca/issue-ds-scaffold-files-not-in-filetree-stale-config.md
1130
- const CONFIG_RELOAD_DEBOUNCE_MS = 150;
1131
- let configReloadTimer: ReturnType<typeof setTimeout> | null = null;
1132
- ctx.bus.on('fs:json', (rel: string) => {
1133
- if (rel.replace(/\\/g, '/').replace(/^\/+/, '') !== 'config.json') return;
1134
- if (configReloadTimer) clearTimeout(configReloadTimer);
1135
- configReloadTimer = setTimeout(() => {
1136
- configReloadTimer = null;
1137
- if (!reloadConfig(ctx)) return;
1131
+ // A cell child has no watcher, so a peer's config.json write arrives as
1132
+ // `fs:any` only (journal heal) — wireConfigReload listens on both events
1133
+ // behind one debounce (#205, config-reload-wire.ts).
1134
+ wireConfigReload(ctx, {
1135
+ onReloaded: () => {
1138
1136
  console.log(' config.json changed — reloaded live.');
1139
1137
  void canvasListWatch.refresh();
1140
1138
  ctx.bus.emit('config-updated');
1141
- }, CONFIG_RELOAD_DEBOUNCE_MS);
1139
+ },
1142
1140
  });
1143
1141
 
1144
1142
  // Phase 9 Task 4 — bidirectional sync agent. No-op when the project isn't