@1agh/maude 2.1.0 → 2.1.2

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 (153) hide show
  1. package/apps/studio/access/request.ts +1 -0
  2. package/apps/studio/actions/agents.ts +45 -42
  3. package/apps/studio/actions/defs/app.ts +28 -1
  4. package/apps/studio/actions/defs/sync.ts +4 -0
  5. package/apps/studio/actions/verbs.ts +49 -0
  6. package/apps/studio/actions.manifest.json +162 -20
  7. package/apps/studio/actions.parity.json +13 -1
  8. package/apps/studio/ai/create-claim.ts +1 -1
  9. package/apps/studio/bin/_asset-file.mjs +117 -0
  10. package/apps/studio/bin/_canvas-file.mjs +146 -0
  11. package/apps/studio/bin/_curl-local.mjs +7 -4
  12. package/apps/studio/bin/_footage.mjs +123 -0
  13. package/apps/studio/bin/_pdf-playwright.mjs +14 -0
  14. package/apps/studio/bin/_png-playwright.mjs +15 -1
  15. package/apps/studio/bin/_pw-launch.mjs +98 -0
  16. package/apps/studio/bin/_retry-save.mjs +49 -0
  17. package/apps/studio/bin/_sync.mjs +145 -2
  18. package/apps/studio/bin/asset-rename.sh +12 -0
  19. package/apps/studio/bin/asset-trash.sh +12 -0
  20. package/apps/studio/bin/canvas-move.sh +12 -0
  21. package/apps/studio/bin/canvas-new.sh +12 -0
  22. package/apps/studio/bin/footage.sh +12 -0
  23. package/apps/studio/bin/generate.sh +7 -0
  24. package/apps/studio/bin/retry-save.sh +13 -0
  25. package/apps/studio/bridge/canvas-mode-store.ts +11 -2
  26. package/apps/studio/bridge/dgn-protocol.ts +8 -3
  27. package/apps/studio/bridge/occlusion.ts +45 -0
  28. package/apps/studio/canvas-theme-pill.tsx +169 -26
  29. package/apps/studio/client/app.jsx +16 -4
  30. package/apps/studio/client/export-center.jsx +32 -3
  31. package/apps/studio/client/home/HomeAccountBanner.jsx +61 -0
  32. package/apps/studio/client/home/HomeAccountsChip.jsx +404 -0
  33. package/apps/studio/client/home/HomeConnection.jsx +112 -0
  34. package/apps/studio/client/home/ProjectRows.jsx +514 -0
  35. package/apps/studio/client/home/home-accounts-model.js +234 -76
  36. package/apps/studio/client/home/home-api.js +10 -2
  37. package/apps/studio/client/home/home-app.jsx +151 -394
  38. package/apps/studio/client/home/home-icons.jsx +8 -0
  39. package/apps/studio/client/home/home-model.js +149 -1
  40. package/apps/studio/client/home/home-where-model.js +105 -0
  41. package/apps/studio/client/home/home.css +621 -53
  42. package/apps/studio/client/home/use-account-fix.js +123 -0
  43. package/apps/studio/client/hooks/use-palette-and-panels.jsx +3 -1
  44. package/apps/studio/client/hooks/use-tabs.jsx +11 -4
  45. package/apps/studio/client/panels/TeamProjects.jsx +137 -134
  46. package/apps/studio/client/share-link.js +12 -0
  47. package/apps/studio/client/styles/_index.css +4 -0
  48. package/apps/studio/client/v2/assets/generate-ask.jsx +3 -1
  49. package/apps/studio/client/v2/diagnostics/diagnostics-host.jsx +1 -0
  50. package/apps/studio/client/v2/diagnostics/diagnostics-model.js +32 -2
  51. package/apps/studio/client/v2/diagnostics/diagnostics-sheet.jsx +35 -8
  52. package/apps/studio/client/v2/diagnostics/diagnostics.css +34 -0
  53. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +94 -3
  54. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +187 -4
  55. package/apps/studio/client/v2/export/done-toast.jsx +2 -5
  56. package/apps/studio/client/v2/export/export-sheet.jsx +9 -2
  57. package/apps/studio/client/v2/export/export.css +9 -0
  58. package/apps/studio/client/v2/export/exports-model.js +16 -3
  59. package/apps/studio/client/v2/export/file-rows.jsx +81 -5
  60. package/apps/studio/client/v2/export/native-save.js +33 -0
  61. package/apps/studio/client/v2/export/sections/print-copy.js +3 -0
  62. package/apps/studio/client/v2/export/sections/print.jsx +37 -20
  63. package/apps/studio/client/v2/link-server/LinkServerDialog.jsx +492 -0
  64. package/apps/studio/client/v2/link-server/LinkServerHost.jsx +42 -0
  65. package/apps/studio/client/v2/link-server/link-server-api.js +142 -0
  66. package/apps/studio/client/v2/link-server/link-server-model.js +438 -0
  67. package/apps/studio/client/v2/link-server/link-server.css +109 -0
  68. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +31 -86
  69. package/apps/studio/client/v2/onboarding/onboarding-model.js +1 -18
  70. package/apps/studio/client/v2/search/search-keywords.js +3 -2
  71. package/apps/studio/client/v2/settings/account.jsx +4 -2
  72. package/apps/studio/client/v2/settings/advanced-section.jsx +245 -148
  73. package/apps/studio/client/v2/settings/connection-row.jsx +3 -59
  74. package/apps/studio/client/v2/settings/connections-section.jsx +118 -425
  75. package/apps/studio/client/v2/settings/general-section.jsx +138 -43
  76. package/apps/studio/client/v2/settings/project-sync-settings.jsx +4 -3
  77. package/apps/studio/client/v2/settings/reset-section.jsx +14 -3
  78. package/apps/studio/client/v2/settings/settings-card.jsx +142 -0
  79. package/apps/studio/client/v2/settings/settings-cards.js +220 -0
  80. package/apps/studio/client/v2/settings/settings-handlers.js +7 -6
  81. package/apps/studio/client/v2/settings/settings-model.js +91 -31
  82. package/apps/studio/client/v2/settings/settings-sheet.jsx +25 -6
  83. package/apps/studio/client/v2/settings/settings.css +374 -64
  84. package/apps/studio/client/v2/settings/this-project-card.jsx +730 -0
  85. package/apps/studio/client/v2/settings/this-project-model.js +172 -0
  86. package/apps/studio/client/v2/settings/use-connections.js +3 -2
  87. package/apps/studio/client/v2/settings/use-open-card.js +37 -0
  88. package/apps/studio/client/v2/shell/connection-state.js +197 -0
  89. package/apps/studio/client/v2/shell/menu-runner.js +7 -2
  90. package/apps/studio/client/v2/shell/occlusion-insets.js +37 -9
  91. package/apps/studio/client/v2/shell/project-account-bus.js +36 -0
  92. package/apps/studio/client/v2/shell/project-account-card.jsx +357 -148
  93. package/apps/studio/client/v2/shell/project-account-model.js +272 -149
  94. package/apps/studio/client/v2/shell/project-account-toast.js +66 -0
  95. package/apps/studio/client/v2/shell/project-account.css +237 -0
  96. package/apps/studio/client/v2/shell/share-cluster-host.jsx +166 -83
  97. package/apps/studio/client/v2/shell/shell-parity.js +3 -2
  98. package/apps/studio/client/v2/shell/shell-parity.json +40 -26
  99. package/apps/studio/client/v2/shell/use-account.js +2 -0
  100. package/apps/studio/client/v2/shell/use-occluded-insets.js +13 -3
  101. package/apps/studio/client/v2/signin/use-signin.js +1 -1
  102. package/apps/studio/cloud/endpoints.ts +29 -4
  103. package/apps/studio/collab/room.ts +21 -7
  104. package/apps/studio/dist/client.bundle.js +886 -886
  105. package/apps/studio/dist/comment-mount.js +2 -2
  106. package/apps/studio/dist/styles.css +1 -1
  107. package/apps/studio/exporters/ghostscript.ts +78 -1
  108. package/apps/studio/exporters/pdf-fonts.ts +31 -4
  109. package/apps/studio/generation/jobs.ts +6 -0
  110. package/apps/studio/home/accounts.ts +30 -11
  111. package/apps/studio/home/cloud.ts +6 -1
  112. package/apps/studio/home/hub-health.ts +76 -0
  113. package/apps/studio/home/routes.ts +9 -3
  114. package/apps/studio/http.ts +14 -2
  115. package/apps/studio/migrate/hub.ts +8 -1
  116. package/apps/studio/routes/agent.ts +6 -2
  117. package/apps/studio/routes/hub-link-folder.ts +334 -0
  118. package/apps/studio/routes/hub-signin.ts +78 -1
  119. package/apps/studio/routes/index.ts +4 -0
  120. package/apps/studio/routes/project-undo.ts +10 -0
  121. package/apps/studio/routes/sync.ts +22 -4
  122. package/apps/studio/server.ts +25 -0
  123. package/apps/studio/shell/api-key.ts +11 -0
  124. package/apps/studio/shell/cli-yield.ts +48 -11
  125. package/apps/studio/sync/accepted-cold-start.ts +144 -8
  126. package/apps/studio/sync/action-stage.ts +18 -1
  127. package/apps/studio/sync/ctl-heal.ts +58 -0
  128. package/apps/studio/sync/file-ledger.ts +38 -4
  129. package/apps/studio/sync/file-plane.ts +226 -19
  130. package/apps/studio/sync/held-deletes.ts +86 -5
  131. package/apps/studio/sync/hub-link.ts +8 -0
  132. package/apps/studio/sync/index.ts +68 -4
  133. package/apps/studio/sync/link-consent.ts +22 -75
  134. package/apps/studio/sync/link-survey.ts +252 -0
  135. package/apps/studio/sync/local-kernel.ts +16 -1
  136. package/apps/studio/sync/seed-progress.ts +12 -0
  137. package/apps/studio/sync/source-recovery.ts +18 -2
  138. package/apps/studio/sync/status.ts +11 -1
  139. package/apps/studio/sync/writer-registry.ts +5 -0
  140. package/apps/studio/whats-new.json +36 -0
  141. package/cli/commands/design.mjs +74 -16
  142. package/cli/lib/bash-guard.mjs +23 -4
  143. package/cli/lib/confine-read.mjs +2 -0
  144. package/cli/lib/design-help.gen.mjs +15 -2
  145. package/cli/lib/design-hook.mjs +1 -1
  146. package/cli/lib/desktop-locate.mjs +36 -8
  147. package/cli/lib/studio-locate.mjs +8 -2
  148. package/cli/lib/sub-verbs.mjs +13 -1
  149. package/package.json +9 -8
  150. package/apps/studio/client/home/HomeAccounts.jsx +0 -262
  151. package/apps/studio/client/v2/onboarding/HubSheet.jsx +0 -212
  152. package/apps/studio/client/v2/shell/account-card-model.js +0 -114
  153. package/apps/studio/client/v2/shell/account-card.jsx +0 -189
@@ -32,6 +32,8 @@ import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
32
32
  import { tmpdir } from 'node:os';
33
33
  import path from 'node:path';
34
34
 
35
+ import { PDFArray, PDFDocument, PDFName, PDFNumber, type PDFPage } from 'pdf-lib';
36
+
35
37
  /**
36
38
  * argv prefix for Ghostscript. `MAUDE_GHOSTSCRIPT` overrides (space-separated,
37
39
  * so a wrapper or an absolute path both work); otherwise the usual binary
@@ -135,6 +137,80 @@ export const OUTLINE_FLAGS: readonly string[] = [
135
137
  '-dSAFER',
136
138
  ];
137
139
 
140
+ /** Boxes the outline pass carries over. Neither is inheritable, so each lives on its page leaf. */
141
+ const PRINT_BOXES = ['TrimBox', 'BleedBox'] as const;
142
+ /** Points. Ghostscript writes boxes at 4 decimals; anything closer than this is the same box. */
143
+ const BOX_TOLERANCE_PT = 0.05;
144
+
145
+ function boxNumbers(page: PDFPage, key: string): [number, number, number, number] | null {
146
+ const raw = page.node.lookup(PDFName.of(key));
147
+ if (!(raw instanceof PDFArray) || raw.size() !== 4) return null;
148
+ const nums = raw.asArray().map((v) => (v instanceof PDFNumber ? v.asNumber() : Number.NaN));
149
+ if (nums.some((n) => !Number.isFinite(n))) return null;
150
+ const [x1, y1, x2, y2] = nums as [number, number, number, number];
151
+ return [Math.min(x1, x2), Math.min(y1, y2), Math.max(x1, x2), Math.max(y1, y2)];
152
+ }
153
+
154
+ /**
155
+ * Put the input's TrimBox / BleedBox back on Ghostscript's output, shifted by however far
156
+ * Ghostscript moved the MediaBox origin (B4, fix-bulk 2026-11-10).
157
+ *
158
+ * A print page with crop marks has a MediaBox with a negative origin (the slug). `pdfwrite`
159
+ * re-bases every page to a 0,0 MediaBox, and a reported run also dropped both boxes — the
160
+ * outlined file then no longer says where to cut, which is the one thing a print PDF must say.
161
+ * Current Ghostscript keeps and shifts them itself; this makes the result independent of the
162
+ * build the user (or the image) has. Only a box the INPUT page set is restored, and only on a
163
+ * page whose MediaBox kept its size (a page Ghostscript rotated or resized is left alone rather
164
+ * than given a box that no longer fits it). Returns whether anything changed.
165
+ */
166
+ export function restorePageBoxes(input: PDFDocument, output: PDFDocument): boolean {
167
+ if (input.getPageCount() !== output.getPageCount()) return false;
168
+ let changed = false;
169
+ for (let i = 0; i < input.getPageCount(); i += 1) {
170
+ const src = input.getPage(i);
171
+ const dst = output.getPage(i);
172
+ const a = src.getMediaBox();
173
+ const b = dst.getMediaBox();
174
+ if (
175
+ Math.abs(a.width - b.width) > BOX_TOLERANCE_PT ||
176
+ Math.abs(a.height - b.height) > BOX_TOLERANCE_PT
177
+ )
178
+ continue;
179
+ const dx = b.x - a.x;
180
+ const dy = b.y - a.y;
181
+ for (const key of PRINT_BOXES) {
182
+ const want = boxNumbers(src, key);
183
+ if (!want) continue;
184
+ const [x1, y1, x2, y2] = [want[0] + dx, want[1] + dy, want[2] + dx, want[3] + dy];
185
+ const have = boxNumbers(dst, key);
186
+ if (
187
+ have &&
188
+ [x1, y1, x2, y2].every((v, n) => Math.abs(v - (have[n] as number)) <= BOX_TOLERANCE_PT)
189
+ )
190
+ continue;
191
+ dst.node.set(PDFName.of(key), output.context.obj([x1, y1, x2, y2]));
192
+ changed = true;
193
+ }
194
+ }
195
+ return changed;
196
+ }
197
+
198
+ /**
199
+ * `outlined` with the input's print boxes restored, re-saved only when a box was missing or
200
+ * moved. A document pdf-lib cannot read is returned as Ghostscript wrote it: the box repair is a
201
+ * best effort on top of an outline that already succeeded, never a reason to fail the export.
202
+ */
203
+ async function withPrintBoxes(input: Uint8Array, outlined: Uint8Array): Promise<Uint8Array> {
204
+ try {
205
+ const before = await PDFDocument.load(input, { updateMetadata: false });
206
+ const after = await PDFDocument.load(outlined, { updateMetadata: false });
207
+ if (!restorePageBoxes(before, after)) return outlined;
208
+ return await after.save();
209
+ } catch {
210
+ return outlined;
211
+ }
212
+ }
213
+
138
214
  export interface OutlineOptions {
139
215
  /** Aborts the pass and kills Ghostscript. */
140
216
  signal?: AbortSignal;
@@ -187,7 +263,8 @@ export async function outlinePdf(
187
263
  `Ghostscript failed to outline the PDF (exit ${code})${detail ? `: ${detail}` : ''}`
188
264
  );
189
265
  }
190
- return new Uint8Array(readFileSync(outPath));
266
+ const outlined = new Uint8Array(readFileSync(outPath));
267
+ return await withPrintBoxes(bytes, outlined);
191
268
  } finally {
192
269
  rmSync(dir, { recursive: true, force: true });
193
270
  }
@@ -27,10 +27,12 @@ import {
27
27
  PDFArray,
28
28
  PDFDict,
29
29
  type PDFDocument,
30
+ PDFHexString,
30
31
  PDFName,
31
32
  type PDFObject,
32
33
  PDFRef,
33
34
  PDFStream,
35
+ PDFString,
34
36
  } from 'pdf-lib';
35
37
 
36
38
  /**
@@ -88,6 +90,27 @@ function descriptorHasFontProgram(descriptor: PDFDict): boolean {
88
90
  return false;
89
91
  }
90
92
 
93
+ /** Read a string-valued key (`/FontFamily (Arvo)`) as plain text, or null. */
94
+ function stringValue(dict: PDFDict, key: string): string | null {
95
+ const v = dict.lookup(PDFName.of(key));
96
+ if (v instanceof PDFString || v instanceof PDFHexString) return v.decodeText() || null;
97
+ return v instanceof PDFName ? v.decodeText() || null : null;
98
+ }
99
+
100
+ /**
101
+ * A name for a font dict that has no `/BaseFont`: its descriptor's
102
+ * `/FontName`, then its `/FontFamily`, then the dict's own `/Name`.
103
+ */
104
+ function fallbackFontName(font: PDFDict): string | null {
105
+ const descriptor = font.lookup(PDFName.of('FontDescriptor'));
106
+ if (descriptor instanceof PDFDict) {
107
+ const fromDescriptor =
108
+ nameValue(descriptor, 'FontName') ?? stringValue(descriptor, 'FontFamily');
109
+ if (fromDescriptor) return fromDescriptor;
110
+ }
111
+ return nameValue(font, 'Name');
112
+ }
113
+
91
114
  /**
92
115
  * Classify ONE font dictionary.
93
116
  *
@@ -101,10 +124,14 @@ function classifyFontDict(font: PDFDict): PdfFontInfo | null {
101
124
  const subtype = nameValue(font, 'Subtype');
102
125
  if (!subtype) return null;
103
126
 
104
- const baseFontRaw = nameValue(font, 'BaseFont');
105
- // A Type 3 font is not required to have a /BaseFont at all. Chromium does set
106
- // one, but a hand-authored or third-party PDF may not — name it after the
107
- // subtype rather than dropping it from the report.
127
+ // A Type 3 font is not required to have a /BaseFont at all, and today's
128
+ // Chromium (Skia) writes none: it names the face only in the font's
129
+ // /FontDescriptor (`/FontName /AAAAAA+Arvo-Bold`, `/FontFamily (Arvo)`).
130
+ // Reading only /BaseFont reported a real Gators-Bold headline as
131
+ // "(unnamed Type3)" (B4, fix-bulk 2026-11-10), which tells the user nothing
132
+ // about which text to fix. Fall back through the descriptor, then the PDF 1.0
133
+ // `/Name`, and name it after the subtype only when nothing names it at all.
134
+ const baseFontRaw = nameValue(font, 'BaseFont') ?? fallbackFontName(font);
108
135
  const name = baseFontRaw ? stripSubsetPrefix(baseFontRaw) : `(unnamed ${subtype})`;
109
136
 
110
137
  if (subtype === 'Type3') {
@@ -230,6 +230,12 @@ export function createGenerationJobQueue(bus: Bus, designRoot: string): Generati
230
230
  release();
231
231
  }
232
232
  })();
233
+ // #220 — the failure is on the job record (status, error, the generate:job push), so a caller
234
+ // that drops `result` — POST /_api/generate-jobs answers 202 and never awaits it — must not leave
235
+ // a rejection nobody handles: the server has no unhandledRejection handler and Bun would end the
236
+ // whole project server (exit 1) on every failed generation. This marks it handled; a caller that
237
+ // awaits `result` still gets the rejection.
238
+ result.catch(() => {});
233
239
 
234
240
  return { id, result };
235
241
  }
@@ -1,7 +1,9 @@
1
1
  // home/accounts.ts — 2.0.5 W4b: the accounts each profile on this Mac is signed in with, for Home's
2
2
  // avatar, and the per-account sign-outs it offers.
3
3
  //
4
- // GET /_home/accounts?profiles=a,b → { ok, profiles: [{ id, hubs: [{ url, account }] }] }
4
+ // GET /_home/accounts?profiles=a,b → { ok, profiles: [{ id, hubs: [{ url, account, state }] }] }
5
+ // `state` (2.1.1): ok · rejected · unreachable · unknown — whether
6
+ // that sign-in still works (hub-health.ts; cached, never a token)
5
7
  // POST /_home/hub/signout { profile, url } → forget that profile's sign-in for that server
6
8
  // POST /_home/cloud/signout { profile } → forget that profile's Maude Cloud sign-in
7
9
  //
@@ -17,6 +19,7 @@ import { existsSync, unlinkSync } from 'node:fs';
17
19
  import { deleteHubCredential } from '../sync/hub-link.ts';
18
20
  import { loadHubsConfig, normalizeUrl, safeAccount } from '../sync/hubs-config.ts';
19
21
  import { profileCloudPath, profileHubsPath } from './cloud.ts';
22
+ import { createHubHealth, type HubHealth, type HubState } from './hub-health.ts';
20
23
  import type { HomeAnswer } from './signin.ts';
21
24
 
22
25
  const MAX_PROFILES = 16;
@@ -24,11 +27,18 @@ const MAX_HUBS = 50;
24
27
 
25
28
  export interface ProfileHubs {
26
29
  id: string;
27
- hubs: Array<{ url: string; account: string | null }>;
30
+ hubs: Array<{ url: string; account: string | null; state: HubState }>;
28
31
  }
29
32
 
30
- /** Each named profile's team-server sign-ins (no tokens). Unknown / invalid ids are skipped. */
31
- export function profileAccounts(ids: string[]): ProfileHubs[] {
33
+ /**
34
+ * Each named profile's team-server sign-ins (no tokens), each with whether it still works. Unknown /
35
+ * invalid ids are skipped. The servers are asked together (and each answer is cached), so the call
36
+ * takes about one round trip, not one per server.
37
+ */
38
+ export async function profileAccounts(
39
+ ids: string[],
40
+ health: HubHealth = createHubHealth()
41
+ ): Promise<ProfileHubs[]> {
32
42
  const out: ProfileHubs[] = [];
33
43
  for (const id of [...new Set(ids)].slice(0, MAX_PROFILES)) {
34
44
  const file = profileHubsPath(id);
@@ -36,10 +46,16 @@ export function profileAccounts(ids: string[]): ProfileHubs[] {
36
46
  let hubs: ProfileHubs['hubs'] = [];
37
47
  try {
38
48
  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) }));
49
+ hubs = await Promise.all(
50
+ Object.entries(cfg.hubs ?? {})
51
+ .filter(([, rec]) => rec && typeof rec.token === 'string' && rec.token)
52
+ .slice(0, MAX_HUBS)
53
+ .map(async ([url, rec]) => ({
54
+ url,
55
+ account: safeAccount(rec.account),
56
+ state: await health.state(url, rec.token).catch(() => 'unknown' as const),
57
+ }))
58
+ );
43
59
  } catch {
44
60
  hubs = [];
45
61
  }
@@ -50,11 +66,14 @@ export function profileAccounts(ids: string[]): ProfileHubs[] {
50
66
 
51
67
  const bad = (error: string): HomeAnswer => ({ status: 400, body: { ok: false, error } });
52
68
 
53
- export function createHomeAccounts(deps: { forgetCloud?: (profile: string) => void } = {}) {
69
+ export function createHomeAccounts(
70
+ deps: { forgetCloud?: (profile: string) => void; hubHealth?: HubHealth } = {}
71
+ ) {
72
+ const health = deps.hubHealth ?? createHubHealth();
54
73
  return {
55
- list(param: string | null): HomeAnswer {
74
+ async list(param: string | null): Promise<HomeAnswer> {
56
75
  const ids = (param ?? '').split(',').filter(Boolean);
57
- return { status: 200, body: { ok: true, profiles: profileAccounts(ids) } };
76
+ return { status: 200, body: { ok: true, profiles: await profileAccounts(ids, health) } };
58
77
  },
59
78
 
60
79
  hubSignOut(b: Record<string, unknown>): HomeAnswer {
@@ -134,6 +134,11 @@ export interface CloudListing {
134
134
  signedIn: boolean;
135
135
  /** the control plane could not be reached — these rows are the last good answer (or empty) */
136
136
  offline?: boolean;
137
+ /**
138
+ * 2.1.1 — the control plane refused this profile's saved sign-in (401/403): the person is not signed
139
+ * out of their own accord, the sign-in stopped working. Absent when there is no credential at all.
140
+ */
141
+ rejected?: boolean;
137
142
  /** the control plane has no /api/home yet: projects only, no `shared` */
138
143
  fallback?: boolean;
139
144
  account: { email: string | null } | null;
@@ -214,7 +219,7 @@ export function createHomeCloud(opts: { now?: () => number } = {}): HomeCloud {
214
219
  }
215
220
  if (r.status === 401 || r.status === 403) {
216
221
  cache.delete(profile);
217
- return empty({ error: 'This device was disconnected. Sign in again.' });
222
+ return empty({ rejected: true, error: 'This device was disconnected. Sign in again.' });
218
223
  }
219
224
  if (r.status !== 200 || !r.body || typeof r.body !== 'object') {
220
225
  // offline / 5xx / garbage → the last good answer for THIS token, flagged
@@ -0,0 +1,76 @@
1
+ // home/hub-health.ts — 2.1.1 B4: is a saved team-server sign-in still accepted, or does the server not
2
+ // answer at all? Home's accounts row and every project row's connection badge read this.
3
+ //
4
+ // ok the server took the token
5
+ // rejected the server answered 401: the sign-in stopped working (the person signs in again)
6
+ // unreachable no answer, or a 5xx: the server's side, not the person's
7
+ // unknown the question could not be asked (an address that may not carry a token, an old server
8
+ // without the route, a refusal that says nothing about the token) — never drawn as broken
9
+ //
10
+ // One authenticated `GET /api/documents` per server — the listing the sync client itself uses, so it
11
+ // answers exactly what sync would. Cheap by construction: a result is kept per (address, token) for
12
+ // `ttlMs`, and concurrent asks for the same pair share one request. The token goes only to the address
13
+ // it was saved against (https, or http on loopback), with no redirect followed and no ambient
14
+ // credentials, and is never part of any answer.
15
+
16
+ import { createHash } from 'node:crypto';
17
+
18
+ import { hubAddress } from './hub.ts';
19
+
20
+ export type HubState = 'ok' | 'rejected' | 'unreachable' | 'unknown';
21
+
22
+ export interface HubHealth {
23
+ state(url: string, token: string): Promise<HubState>;
24
+ }
25
+
26
+ const TTL_MS = 60_000;
27
+ const TIMEOUT_MS = 4000;
28
+ const MAX_ENTRIES = 200;
29
+
30
+ export function createHubHealth(
31
+ opts: { fetchImpl?: typeof fetch; now?: () => number; ttlMs?: number } = {}
32
+ ): HubHealth {
33
+ const doFetch = opts.fetchImpl ?? ((...a: Parameters<typeof fetch>) => fetch(...a));
34
+ const now = opts.now ?? Date.now;
35
+ const ttl = opts.ttlMs ?? TTL_MS;
36
+ const done = new Map<string, { at: number; value: HubState }>();
37
+ const flying = new Map<string, Promise<HubState>>();
38
+
39
+ async function ask(base: string, token: string): Promise<HubState> {
40
+ try {
41
+ const res = await doFetch(`${base}/api/documents`, {
42
+ method: 'GET',
43
+ headers: { authorization: `Bearer ${token}`, accept: 'application/json' },
44
+ signal: AbortSignal.timeout(TIMEOUT_MS),
45
+ redirect: 'error',
46
+ credentials: 'omit',
47
+ });
48
+ if (res.status === 200) return 'ok';
49
+ if (res.status === 401) return 'rejected';
50
+ if (res.status >= 500) return 'unreachable';
51
+ return 'unknown';
52
+ } catch {
53
+ return 'unreachable';
54
+ }
55
+ }
56
+
57
+ return {
58
+ async state(url, token) {
59
+ const a = hubAddress(url);
60
+ if (!a.ok || !token) return 'unknown';
61
+ const key = createHash('sha256').update(`${a.url}\n${token}`).digest('hex');
62
+ const hit = done.get(key);
63
+ if (hit && now() - hit.at < ttl) return hit.value;
64
+ const live = flying.get(key);
65
+ if (live) return live;
66
+ const p = ask(a.url, token).then((value) => {
67
+ flying.delete(key);
68
+ if (done.size >= MAX_ENTRIES) done.delete(done.keys().next().value as string);
69
+ done.set(key, { at: now(), value });
70
+ return value;
71
+ });
72
+ flying.set(key, p);
73
+ return p;
74
+ },
75
+ };
76
+ }
@@ -49,6 +49,7 @@ import type { HomeCloud } from './cloud.ts';
49
49
  import { checkLocationReason, createLocalProject } from './create-local.ts';
50
50
  import { createHomeGithub, type HomeGithub } from './github.ts';
51
51
  import { createHomeHub, type HomeHub } from './hub.ts';
52
+ import type { HubHealth } from './hub-health.ts';
52
53
  import { indexGcRequest } from './index-gc.ts';
53
54
  import { readHomeIndex, resolveProject, searchHome, thumbSource } from './index-reader.ts';
54
55
  import { createHomeInvite, type HomeInvite } from './invite.ts';
@@ -93,6 +94,8 @@ export interface HomeDeps {
93
94
  whatsNew?: HomeWhatsNew;
94
95
  /** S6.10 — the clone behind "From GitHub" (internal: Rust names the folder and the token) */
95
96
  github?: HomeGithub;
97
+ /** 2.1.1 — does each saved team-server sign-in still work (default: a cached real probe) */
98
+ hubHealth?: HubHealth;
96
99
  }
97
100
 
98
101
  const NO_STORE = { 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' };
@@ -282,7 +285,10 @@ export function homeRouteTable(deps: HomeDeps): HomeRoute[] {
282
285
  const cli = deps.cli ?? createHomeCli();
283
286
  const whatsNew = deps.whatsNew ?? createHomeWhatsNew();
284
287
  const github = deps.github ?? createHomeGithub();
285
- const accounts = createHomeAccounts({ forgetCloud: (p) => deps.cloud.forget(p) });
288
+ const accounts = createHomeAccounts({
289
+ forgetCloud: (p) => deps.cloud.forget(p),
290
+ hubHealth: deps.hubHealth,
291
+ });
286
292
  return [
287
293
  {
288
294
  method: 'GET',
@@ -494,8 +500,8 @@ export function homeRouteTable(deps: HomeDeps): HomeRoute[] {
494
500
  method: 'GET',
495
501
  path: '/_home/accounts',
496
502
  kind: 'home',
497
- handle: (_req, url) => {
498
- const r = accounts.list(url.searchParams.get('profiles'));
503
+ handle: async (_req, url) => {
504
+ const r = await accounts.list(url.searchParams.get('profiles'));
499
505
  return json(r.status, r.body);
500
506
  },
501
507
  },
@@ -1688,6 +1688,8 @@ export function createHttp(
1688
1688
  cloudRenderDoor?: () => CloudRenderDoor | null;
1689
1689
  /** V2-1.15 §4 #13 — the people holding an element of a canvas now (collab/holds.ts) */
1690
1690
  personHolds?: AgentRouteDeps['personHolds'];
1691
+ /** #216 — flush a canvas's live collab room (repo-relative path) before ⌘Z reads its stack */
1692
+ settleCanvasRoom?: (repoRel: string) => Promise<void>;
1691
1693
  } = {}
1692
1694
  ): Http {
1693
1695
  /** The current request's inspector state (Cloud Phase 27 D3). Resolved per
@@ -2454,6 +2456,7 @@ export function createHttp(
2454
2456
  control: () => ctx.syncControl?.current?.() ?? null,
2455
2457
  designRel: ctx.paths.designRel,
2456
2458
  emit: (e, p) => ctx.bus.emit(e, p),
2459
+ ...(opts.settleCanvasRoom ? { settle: opts.settleCanvasRoom } : {}),
2457
2460
  },
2458
2461
  // S1.12b — Version history (V2-1.9 §5.11): rows, words, names, kept-aside versions. The
2459
2462
  // session's access is `currentAccess()` (S9.9, server.ts withSession).
@@ -2832,6 +2835,14 @@ export function createHttp(
2832
2835
  linkedHubUrl: () => ctx.cfg.linkedHub?.url,
2833
2836
  restartSync: () => ctx.syncControl?.restart(),
2834
2837
  },
2838
+ // 2.1.1 — POST /_api/hub/link-folder (routes/hub-link-folder.ts): main origin, window only, on the attach lane.
2839
+ hubLinkFolder: {
2840
+ designRoot: ctx.paths.designRoot,
2841
+ repoRoot: ctx.paths.repoRoot,
2842
+ canvasGroups: () => ctx.cfg.canvasGroups,
2843
+ localFormat: () => asFormat(ctx.cfg.formatVersion),
2844
+ attachStored: (url) => cloudApi.attachStored(url),
2845
+ },
2835
2846
  }).map(guardTableRoute);
2836
2847
  // p8-a1-claims — outside the gates: a write that names an AI chat answers inside its run's claim
2837
2848
  // (in place, so every consumer of the table — the mount, the local gate — sees the same specs)
@@ -4253,7 +4264,7 @@ export function createHttp(
4253
4264
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
4254
4265
  );
4255
4266
  }
4256
- // S12.16 — the AI chat creates through `maude design curl-local`, which names its chat
4267
+ // S12.16 — the AI chat creates through `maude design canvas-new`, which names its chat
4257
4268
  // (ai/create-claim.ts): the new canvas is that chat's live run's write, not an outside one.
4258
4269
  const mine = runForCreate(req, runs);
4259
4270
  if (mine) {
@@ -6845,7 +6856,8 @@ export function createHttp(
6845
6856
  });
6846
6857
  // Don't await the run — the job's own status (GET + the generate:job WS
6847
6858
  // push) is the completion signal. A failure is recorded on the job
6848
- // record, so swallow the rejection here to avoid an unhandled rejection.
6859
+ // record; the queue itself marks the rejection handled (generation/jobs.ts,
6860
+ // #220 — before that, a failed job ended the whole server).
6849
6861
  return Response.json(
6850
6862
  { jobId: id },
6851
6863
  { status: 202, headers: { 'Cache-Control': 'no-store' } }
@@ -81,7 +81,11 @@ export function createHubFormatClient(
81
81
  return {
82
82
  async health() {
83
83
  try {
84
- const res = await fetchImpl(`${base}/health`, { signal: AbortSignal.timeout(10_000) });
84
+ // 2.1.1 T8 — never follow a redirect off the server (every call below carries the bearer)
85
+ const res = await fetchImpl(`${base}/health`, {
86
+ redirect: 'manual',
87
+ signal: AbortSignal.timeout(10_000),
88
+ });
85
89
  if (!res.ok) return { ok: false };
86
90
  const j = (await res.json()) as {
87
91
  formatVersion?: unknown;
@@ -115,6 +119,7 @@ export function createHubFormatClient(
115
119
  try {
116
120
  const res = await fetchImpl(`${base}${MODE_PATH}`, {
117
121
  headers: { authorization: `Bearer ${hub.token}` },
122
+ redirect: 'manual',
118
123
  signal: AbortSignal.timeout(10_000),
119
124
  });
120
125
  const j = (await res.json().catch(() => null)) as {
@@ -149,6 +154,7 @@ export function createHubFormatClient(
149
154
  const res = await fetchImpl(`${base}${MODE_PATH}`, {
150
155
  method: 'POST',
151
156
  headers: { 'content-type': 'application/json', authorization: `Bearer ${hub.token}` },
157
+ redirect: 'manual',
152
158
  // #166 (2.0.4): a dry run here reads only the blockers, so it asks for them alone —
153
159
  // the hub's full preview imports (opens) every document. An older hub ignores the flag.
154
160
  body: JSON.stringify({
@@ -205,6 +211,7 @@ export function createHubFormatClient(
205
211
  formatVersion,
206
212
  ...(expectEpoch !== undefined ? { expectEpoch } : {}),
207
213
  }),
214
+ redirect: 'manual',
208
215
  signal: AbortSignal.timeout(20_000),
209
216
  });
210
217
  const j = (await res.json().catch(() => null)) as {
@@ -809,11 +809,15 @@ function hookRouteSpecs(deps: AgentRouteDeps): RouteSpec[] {
809
809
  ? ('*' as const)
810
810
  : reach.artboards;
811
811
  const self = runs.get(session, chat);
812
- // G-AI-6: a ⌘/ selection-scoped run changes only its selection
812
+ // G-AI-6: a scoped run changes only its canvas. #219 (Michal): the ARTBOARDS a chat started from
813
+ // (the scope chip follows the selection) are a hint for the AI, never a write lock — another
814
+ // artboard of the canvas goes on to the lock, hold and lease checks below like any lazy write,
815
+ // so one AI per artboard still holds. Only an element-scoped ask (⌘/ on a selection, S2.19)
816
+ // keeps its artboards as a limit.
813
817
  const sc = self?.scope;
814
818
  if (sc) {
815
819
  const offCanvas = rel !== sc.canvas;
816
- const allowed = sc.artboards.length ? sc.artboards : null;
820
+ const allowed = sc.artboards.length && sc.elements?.length ? sc.artboards : null;
817
821
  const outside = offCanvas
818
822
  ? reach.artboards
819
823
  : allowed