@1agh/maude 2.0.3 → 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 (242) hide show
  1. package/README.md +6 -5
  2. package/apps/hub/src/project-transactions/kernel.mjs +10 -1
  3. package/apps/studio/access/filters.ts +12 -5
  4. package/apps/studio/access/known-canvases.ts +24 -1
  5. package/apps/studio/access/refused-inputs.ts +89 -0
  6. package/apps/studio/access/request.ts +0 -1
  7. package/apps/studio/acp/adapter-stderr.ts +43 -13
  8. package/apps/studio/acp/background-tasks.ts +155 -0
  9. package/apps/studio/acp/bridge.ts +44 -5
  10. package/apps/studio/acp/connected-fact.ts +15 -4
  11. package/apps/studio/acp/index.ts +14 -5
  12. package/apps/studio/actions/agents.ts +10 -0
  13. package/apps/studio/actions/defs/app.ts +12 -0
  14. package/apps/studio/actions/defs/view.ts +12 -0
  15. package/apps/studio/actions.manifest.json +25 -1
  16. package/apps/studio/actions.parity.json +13 -1
  17. package/apps/studio/annotations/ui/element-node.tsx +139 -54
  18. package/apps/studio/annotations/ui/lod.tsx +1 -1
  19. package/apps/studio/annotations/ui/text-style.ts +1 -1
  20. package/apps/studio/annotations-layer.tsx +0 -12
  21. package/apps/studio/api.ts +73 -24
  22. package/apps/studio/artboard-live-gate.tsx +267 -0
  23. package/apps/studio/artboard-live.ts +336 -0
  24. package/apps/studio/artboard-webgl.ts +668 -0
  25. package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
  26. package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
  27. package/apps/studio/bin/_canvas-reasons.mjs +34 -0
  28. package/apps/studio/bin/_ds-check-live.mjs +37 -0
  29. package/apps/studio/bin/_ds-check.mjs +4 -1
  30. package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
  31. package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
  32. package/apps/studio/bin/_import-asset.mjs +2 -1
  33. package/apps/studio/bin/_perf-probe.mjs +2 -1
  34. package/apps/studio/bin/_png-playwright.mjs +10 -1
  35. package/apps/studio/bin/_pw-launch.mjs +14 -0
  36. package/apps/studio/bin/_studio-verb.mjs +24 -3
  37. package/apps/studio/bin/_thumb-blank.mjs +70 -0
  38. package/apps/studio/bin/_thumb-cover.mjs +35 -0
  39. package/apps/studio/bin/_thumbs-playwright.mjs +93 -13
  40. package/apps/studio/bin/ds-check.sh +5 -1
  41. package/apps/studio/bin/perf.sh +11 -1
  42. package/apps/studio/bin/server-up.sh +7 -2
  43. package/apps/studio/bin/smoke.sh +19 -0
  44. package/apps/studio/boot-progress.ts +31 -0
  45. package/apps/studio/canvas-build-sandbox.ts +275 -42
  46. package/apps/studio/canvas-build-worker.ts +10 -0
  47. package/apps/studio/canvas-create.ts +24 -0
  48. package/apps/studio/canvas-lib.tsx +131 -12
  49. package/apps/studio/canvas-module-cache.ts +93 -0
  50. package/apps/studio/canvas-source/errors.ts +39 -0
  51. package/apps/studio/canvas-source/waiting.ts +290 -0
  52. package/apps/studio/client/actions/shell-key-handlers.js +5 -0
  53. package/apps/studio/client/app.jsx +19 -9
  54. package/apps/studio/client/canvas-url.js +13 -0
  55. package/apps/studio/client/github.js +23 -3
  56. package/apps/studio/client/home/HomeAccounts.jsx +262 -0
  57. package/apps/studio/client/home/Shelves.jsx +4 -3
  58. package/apps/studio/client/home/home-accounts-model.js +121 -0
  59. package/apps/studio/client/home/home-api.js +36 -19
  60. package/apps/studio/client/home/home-app.jsx +141 -40
  61. package/apps/studio/client/home/home-model.js +172 -6
  62. package/apps/studio/client/home/home.css +169 -5
  63. package/apps/studio/client/home/shell-mode.js +8 -1
  64. package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
  65. package/apps/studio/client/hooks/use-project-data.jsx +2 -0
  66. package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
  67. package/apps/studio/client/hooks/use-tabs.jsx +64 -35
  68. package/apps/studio/client/index-loader.ts +23 -3
  69. package/apps/studio/client/panels/ChatPanel.jsx +49 -57
  70. package/apps/studio/client/panels/CreateProject.jsx +19 -5
  71. package/apps/studio/client/panels/DiffView.jsx +314 -248
  72. package/apps/studio/client/panels/TeamProjects.jsx +119 -69
  73. package/apps/studio/client/panels/acp-runtime.js +25 -0
  74. package/apps/studio/client/panels/caps-cache.js +46 -0
  75. package/apps/studio/client/panels/chat-finish.js +66 -0
  76. package/apps/studio/client/shell/frame-cap.js +53 -0
  77. package/apps/studio/client/shell/viewport.jsx +45 -8
  78. package/apps/studio/client/styles/_index.css +2 -0
  79. package/apps/studio/client/tree/tree.jsx +48 -21
  80. package/apps/studio/client/v2/access/access-client.js +2 -0
  81. package/apps/studio/client/v2/access/access-host.jsx +12 -1
  82. package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
  83. package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
  84. package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
  85. package/apps/studio/client/v2/ai/Composer.jsx +27 -10
  86. package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
  87. package/apps/studio/client/v2/ai/ai-run.css +87 -3
  88. package/apps/studio/client/v2/ai/background-model.js +113 -0
  89. package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
  90. package/apps/studio/client/v2/ai/run-api.js +7 -3
  91. package/apps/studio/client/v2/ai/runs-store.js +2 -1
  92. package/apps/studio/client/v2/annotations/vote-store.js +11 -5
  93. package/apps/studio/client/v2/assets/asset-state-lane.js +6 -3
  94. package/apps/studio/client/v2/assets/assets-bus.js +10 -8
  95. package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
  96. package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
  97. package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
  98. package/apps/studio/client/v2/assets/spotlight.css +153 -0
  99. package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
  100. package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
  101. package/apps/studio/client/v2/assets/tile.jsx +3 -0
  102. package/apps/studio/client/v2/assets/use-assets.js +2 -1
  103. package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
  104. package/apps/studio/client/v2/canvases/covers.js +11 -5
  105. package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
  106. package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
  107. package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
  108. package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
  109. package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
  110. package/apps/studio/client/v2/canvases/use-pins.js +2 -1
  111. package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
  112. package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
  113. package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
  114. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
  115. package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
  116. package/apps/studio/client/v2/code/code-bus.js +5 -0
  117. package/apps/studio/client/v2/code/code.css +67 -0
  118. package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
  119. package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
  120. package/apps/studio/client/v2/create/name-dialog.css +10 -0
  121. package/apps/studio/client/v2/ds/advanced-host.jsx +11 -23
  122. package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
  123. package/apps/studio/client/v2/ds/library-host.jsx +45 -45
  124. package/apps/studio/client/v2/ds/make-host.jsx +13 -12
  125. package/apps/studio/client/v2/ds/off-system-host.jsx +18 -16
  126. package/apps/studio/client/v2/ds/review-host.jsx +7 -1
  127. package/apps/studio/client/v2/ds/truth-host.jsx +15 -14
  128. package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
  129. package/apps/studio/client/v2/empty/arriving.jsx +29 -12
  130. package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
  131. package/apps/studio/client/v2/empty/not-local.jsx +31 -1
  132. package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
  133. package/apps/studio/client/v2/export/last-finished.js +2 -1
  134. package/apps/studio/client/v2/history/branch-actions.js +13 -9
  135. package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
  136. package/apps/studio/client/v2/history/git-model.js +21 -5
  137. package/apps/studio/client/v2/history/git-parts.jsx +76 -43
  138. package/apps/studio/client/v2/history/history.css +6 -0
  139. package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
  140. package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
  141. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
  142. package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
  143. package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
  144. package/apps/studio/client/v2/presence/faces.jsx +42 -14
  145. package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
  146. package/apps/studio/client/v2/search/search-recent.js +3 -1
  147. package/apps/studio/client/v2/search/search-remote.js +6 -4
  148. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  149. package/apps/studio/client/v2/shell/account-card.jsx +10 -4
  150. package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
  151. package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
  152. package/apps/studio/client/v2/shell/menu-runner.js +12 -0
  153. package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
  154. package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
  155. package/apps/studio/client/v2/shell/project-account-model.js +182 -0
  156. package/apps/studio/client/v2/shell/recovery-store.js +2 -1
  157. package/apps/studio/client/v2/shell/served-routes.js +120 -0
  158. package/apps/studio/client/v2/shell/share-cluster-host.jsx +139 -11
  159. package/apps/studio/client/v2/shell/share-cluster.css +58 -0
  160. package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
  161. package/apps/studio/client/v2/shell/shell-activity.js +19 -0
  162. package/apps/studio/client/v2/shell/team-switch.js +94 -0
  163. package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
  164. package/apps/studio/client/v2/shell/use-account.js +8 -1
  165. package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
  166. package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
  167. package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
  168. package/apps/studio/cloud/endpoints.ts +23 -1
  169. package/apps/studio/collab/persistence.ts +9 -1
  170. package/apps/studio/collab/registry.ts +32 -0
  171. package/apps/studio/collab/room.ts +8 -0
  172. package/apps/studio/config-reload-wire.ts +53 -0
  173. package/apps/studio/dist/client.bundle.js +1098 -1102
  174. package/apps/studio/dist/styles.css +1 -1
  175. package/apps/studio/ds/board/specimen.tsx +12 -1
  176. package/apps/studio/ds/canvas-cli.ts +58 -2
  177. package/apps/studio/ds/check.ts +26 -1
  178. package/apps/studio/ds/cli.ts +7 -3
  179. package/apps/studio/ds/convert.ts +34 -6
  180. package/apps/studio/ds/ds-verb.ts +13 -0
  181. package/apps/studio/ds/post-build.ts +38 -0
  182. package/apps/studio/ds/upgrade-apply.ts +27 -5
  183. package/apps/studio/ds/upgrade-cli.ts +22 -2
  184. package/apps/studio/ds/upgrade-prove.ts +198 -15
  185. package/apps/studio/ds/upgrade-stage.ts +4 -1
  186. package/apps/studio/editing/minimap-context.tsx +3 -3
  187. package/apps/studio/editing/page-activity.ts +251 -0
  188. package/apps/studio/editing/rotate-handle.tsx +9 -5
  189. package/apps/studio/editing/sticky-name.tsx +4 -4
  190. package/apps/studio/history/restore-artboard-action.ts +40 -0
  191. package/apps/studio/history/trash.ts +6 -0
  192. package/apps/studio/home/accounts.ts +87 -0
  193. package/apps/studio/home/hub.ts +77 -175
  194. package/apps/studio/home/index-reader.ts +24 -2
  195. package/apps/studio/home/routes.ts +66 -8
  196. package/apps/studio/http.ts +131 -68
  197. package/apps/studio/index-flight.ts +40 -0
  198. package/apps/studio/managed-projects.ts +52 -24
  199. package/apps/studio/migrate/hub.ts +7 -1
  200. package/apps/studio/routes/canvas-source.ts +44 -2
  201. package/apps/studio/routes/ds-convert.ts +18 -0
  202. package/apps/studio/routes/history.ts +28 -5
  203. package/apps/studio/routes/hub-signin.ts +115 -0
  204. package/apps/studio/routes/index.ts +4 -0
  205. package/apps/studio/routes/table.ts +7 -0
  206. package/apps/studio/routes/trash.ts +19 -1
  207. package/apps/studio/server.ts +19 -10
  208. package/apps/studio/sync/accepted-cold-start.ts +54 -16
  209. package/apps/studio/sync/accepted-link.ts +9 -4
  210. package/apps/studio/sync/asset-push.ts +146 -23
  211. package/apps/studio/sync/asset-state.ts +3 -2
  212. package/apps/studio/sync/code-module-consent.ts +74 -0
  213. package/apps/studio/sync/file-ledger.ts +35 -0
  214. package/apps/studio/sync/file-membership.ts +28 -3
  215. package/apps/studio/sync/file-plane.ts +483 -86
  216. package/apps/studio/sync/file-pull.ts +304 -33
  217. package/apps/studio/sync/hub-browser-signin.ts +377 -0
  218. package/apps/studio/sync/hub-link.ts +1 -2
  219. package/apps/studio/sync/hub-text-undo.ts +30 -10
  220. package/apps/studio/sync/index.ts +381 -161
  221. package/apps/studio/sync/journal-client.ts +94 -5
  222. package/apps/studio/sync/pending-deletes.ts +100 -0
  223. package/apps/studio/sync/projection.ts +121 -14
  224. package/apps/studio/sync/pull-pacer.ts +160 -0
  225. package/apps/studio/sync/pull-priority.ts +119 -0
  226. package/apps/studio/sync/seed-progress.ts +58 -3
  227. package/apps/studio/sync/status.ts +3 -1
  228. package/apps/studio/sync/transaction-client.ts +71 -6
  229. package/apps/studio/sync/workspace-signin.ts +6 -256
  230. package/apps/studio/sync/writer-registry.ts +5 -1
  231. package/apps/studio/thumbs/service.ts +12 -2
  232. package/apps/studio/thumbs/validate.ts +7 -0
  233. package/apps/studio/ui-prefs-migrate.ts +4 -0
  234. package/apps/studio/video-comp.tsx +23 -0
  235. package/apps/studio/video-links-overlay.tsx +3 -2
  236. package/apps/studio/whats-new.json +126 -0
  237. package/cli/lib/bash-guard.mjs +13 -1
  238. package/cli/lib/design-help.gen.mjs +1 -1
  239. package/cli/lib/design-hook.mjs +20 -0
  240. package/cli/lib/studio-locate.mjs +35 -10
  241. package/cli/lib/workspace-plan.mjs +14 -0
  242. package/package.json +8 -8
@@ -24,6 +24,8 @@ type Outcome = {
24
24
 
25
25
  /** What a splice restore reads and writes through (`ctx.syncControl.current()`). */
26
26
  export interface SpliceRuntime extends VersionsRuntime {
27
+ /** F14 — this disk's change goes up before the newest version is read (sync/index.ts). */
28
+ settleSource?(repoRel: string, ms?: number): Promise<'settled' | 'held' | 'pending' | null>;
27
29
  acceptedRestore?(repoRel: string, revision: number, o?: RestoreOptions): Promise<Outcome | null>;
28
30
  acceptedVersion?(
29
31
  repoRel: string,
@@ -132,6 +134,42 @@ export async function restoreArtboardAt(
132
134
  return { ...r, label: s.label, line, sharedKept: s.sharedKept, why: s.why };
133
135
  }
134
136
 
137
+ /** F14 — the refusals of a restore whose canvas has a change on this disk the project lacks. */
138
+ export const SETTLE_REFUSAL_LINES: Readonly<Record<string, string>> = {
139
+ 'unsaved-change': 'This canvas has a change on this Mac that isn’t saved. Compare it first.',
140
+ 'still-saving': 'This canvas is still saving. Try again in a moment.',
141
+ };
142
+
143
+ /**
144
+ * F14 (2.0.4, #166) — a restore splices onto the canvas's NEWEST version, but the person (and the
145
+ * all-trashed card) sees THIS disk. A change here the project has not taken yet (an AI run, an
146
+ * editor, a pull, still in the watcher's quiet window or in flight) goes up first, so the restore
147
+ * lands after it. A change the project refused stays held here, and the restore is refused rather
148
+ * than landing in the project while this file keeps the held candidate (the "answers ok but the
149
+ * file stays empty" bug). A home without the seam (a local project, an older runtime) is unchanged.
150
+ */
151
+ export async function settleBeforeRestore(
152
+ rt: SpliceRuntime,
153
+ repoRel: string
154
+ ): Promise<{ ok: true } | { ok: false; status: number; reason: string; line: string }> {
155
+ const s = rt.settleSource ? await rt.settleSource(repoRel).catch(() => null) : null;
156
+ if (s === 'held')
157
+ return {
158
+ ok: false,
159
+ status: 409,
160
+ reason: 'unsaved-change',
161
+ line: SETTLE_REFUSAL_LINES['unsaved-change'] as string,
162
+ };
163
+ if (s === 'pending')
164
+ return {
165
+ ok: false,
166
+ status: 409,
167
+ reason: 'still-saving',
168
+ line: SETTLE_REFUSAL_LINES['still-saving'] as string,
169
+ };
170
+ return { ok: true };
171
+ }
172
+
135
173
  /** "Restored “Hero” from the trash" — the canvas restore's words (sync/index.ts), for one artboard. */
136
174
  export const trashRestoreLine = (label: string): string => `Restored “${label}” from the trash`;
137
175
 
@@ -161,6 +199,8 @@ export function trashArtboardRestorer(deps: {
161
199
  if (!Number.isSafeInteger(item.rev) || item.rev < 1)
162
200
  return { status: 'rejected', code: 'not-in-version' };
163
201
  const repoRel = designRel ? `${designRel}/${canvas}` : canvas;
202
+ const settled = await settleBeforeRestore(rt, repoRel);
203
+ if (!settled.ok) return { status: 'rejected', code: settled.reason };
164
204
  const headRev = await newestRevision(rt, repoRel, canvas).catch(() => undefined);
165
205
  if (headRev === undefined) return { status: 'rejected', code: 'unreachable' };
166
206
  const r = await restoreArtboardAt(rt, {
@@ -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
+ }
@@ -1,31 +1,38 @@
1
1
  // home/hub.ts — Home's "Connect to your own hub" (S6.6; the TeamProjects door's hub form).
2
2
  //
3
- // POST /_home/hub/test { url } → is a Maude hub answering there?
4
- // POST /_home/hub/prepare { profile, url, email?, password? } → prepareManagedProject for THAT
5
- // profile (kind hub / known-hub)
6
- // POST /_home/hub/join { profile, url, token, email, password } → S6.11b: redeem a hub invite
7
- // (the hub's JSON POST /join), then
8
- // the same prepare-shaped answer
3
+ // POST /_home/hub/test { url } → is a Maude hub answering there?
4
+ // POST /_home/hub/prepare { profile, url } → prepareManagedProject (known-hub)
5
+ // for THAT profile
6
+ // POST /_home/hub/signin/start { profile, url, invite? } → #204 K2: the hub's own page to
7
+ // open in the browser
8
+ // POST /_home/hub/signin/poll { id } → pending · signed in · why not
9
+ // POST /_home/hub/signin/cancel { id }
10
+ // GET /_api/hub-signin/return ?state&code | ?state&error → the browser's hop back (routes.ts
11
+ // serves it outside the table)
9
12
  //
10
- // Rules (contract S6-slices S6.6):
13
+ // Rules (contract S6-slices S6.6; issue #204, decision maude/v2-michal-team-server-signin-via-hub-page):
11
14
  // - the address is https, or http only on loopback — checked before any byte leaves; never
12
15
  // userinfo, never a query or fragment;
13
16
  // - Test connection sends ONE tokenless GET /health: no credential, no body, no redirect followed;
14
- // - the password is posted once, to `<url>/auth/login`, after the same tokenless probe
15
- // (signInToWorkspace) — never stored, never echoed, never logged by Home. Only the minted token
16
- // is kept, in THIS profile's hubs.json. Every request to the hub refuses redirects, so a 307
17
- // cannot replay the password (or the token) at another host.
18
-
19
- import { ACCESS_VERSION } from '../access/scope.ts';
20
- import { type PrepareResult, prepareManagedProject } from '../managed-projects.ts';
17
+ // - Home owns NO login method for a team server: no email, no password, no invite redeem of its
18
+ // own. Sign in opens the hub's `/studio/signin` (an invite: the hub's own `/join/<key>`) in the
19
+ // browser with a desktop request (sync/hub-browser-signin.ts); the hub sends the browser back to
20
+ // HOME's loopback return with a one-time code that only this process's PKCE verifier redeems.
21
+ // Only the exchanged token is kept, in THIS profile's hubs.json (the profile is fixed when the
22
+ // attempt starts, never read from the return). Every request to the hub refuses redirects.
23
+
24
+ import { NO_PASSWORD_WORDS, prepareManagedProject } from '../managed-projects.ts';
25
+ import {
26
+ createHubBrowserSignIn,
27
+ HUB_SIGNIN_WORDS,
28
+ type PollAnswer,
29
+ } from '../sync/hub-browser-signin.ts';
21
30
  import { saveHubCredential } from '../sync/hub-link.ts';
22
31
  import { normalizeUrl } from '../sync/hubs-config.ts';
23
32
  import { profileCloudPath, profileHubsPath } from './cloud.ts';
24
33
  import type { HomeAnswer } from './signin.ts';
25
34
 
26
35
  const MAX_URL = 2048;
27
- const MAX_EMAIL = 320;
28
- const MAX_PASSWORD = 1024;
29
36
  const PROBE_TIMEOUT_MS = 4000;
30
37
  const MAX_HEALTH_BYTES = 64 * 1024;
31
38
  const VERSION_RE = /^[0-9A-Za-z.+-]{1,32}$/;
@@ -61,10 +68,17 @@ export function hubAddress(raw: unknown): { ok: true; url: string } | { ok: fals
61
68
  export interface HomeHub {
62
69
  test(body: unknown): Promise<HomeAnswer>;
63
70
  prepare(body: unknown): Promise<HomeAnswer>;
64
- /** S6.11b — redeem a hub invite (`POST /join`), keep the session, prepare the project. */
65
- join(body: unknown): Promise<HomeAnswer>;
71
+ /** #204 K2 — a sign-in (or an invite accept) on the hub's own page; `origin` is Home's. */
72
+ signInStart(body: unknown, origin: string): Promise<HomeAnswer>;
73
+ signInPoll(body: unknown): Promise<HomeAnswer>;
74
+ signInCancel(body: unknown): Promise<HomeAnswer>;
75
+ /** The browser came back to Home's loopback return. */
76
+ signInReturn(params: URLSearchParams): Promise<{ ok: boolean; message: string }>;
66
77
  }
67
78
 
79
+ /** The words for an email or password sent to Home — it takes neither (issue #204). */
80
+ export { NO_PASSWORD_WORDS };
81
+
68
82
  const answer = (status: number, body: unknown): HomeAnswer => ({ status, body });
69
83
 
70
84
  export function createHomeHub(opts: { fetchImpl?: typeof fetch } = {}): HomeHub {
@@ -76,6 +90,8 @@ export function createHomeHub(opts: { fetchImpl?: typeof fetch } = {}): HomeHub
76
90
  redirect: 'error',
77
91
  credentials: 'omit',
78
92
  })) as typeof fetch;
93
+ // #204 K2 — one flow per Home process; each attempt carries the profile it may write
94
+ const browserSignIn = createHubBrowserSignIn({ fetchImpl: hubFetch });
79
95
 
80
96
  async function test(body: unknown): Promise<HomeAnswer> {
81
97
  const a = hubAddress((body as { url?: unknown } | null)?.url);
@@ -126,138 +142,75 @@ export function createHomeHub(opts: { fetchImpl?: typeof fetch } = {}): HomeHub
126
142
  const a = hubAddress(body.url);
127
143
  if (!a.ok) return answer(400, { ok: false, error: a.error });
128
144
 
129
- const signIn = body.email !== undefined || body.password !== undefined;
130
- let r: PrepareResult;
131
- if (signIn) {
132
- const { email, password } = body;
133
- if (typeof email !== 'string' || !email.trim() || email.length > MAX_EMAIL)
134
- return answer(400, { ok: false, error: 'Enter your email address.' });
135
- if (typeof password !== 'string' || !password || password.length > MAX_PASSWORD)
136
- return answer(400, { ok: false, error: 'Enter your password.' });
137
- r = await prepareManagedProject(
138
- {},
139
- { kind: 'hub', url: a.url, email: email.trim(), password },
140
- { cloudConfigPath, hubsConfigPath, fetchImpl: hubFetch }
141
- );
142
- } else {
143
- r = await prepareManagedProject(
144
- {},
145
- { kind: 'known-hub', url: a.url },
146
- { cloudConfigPath, hubsConfigPath, fetchImpl: hubFetch }
147
- );
148
- }
145
+ // Home owns no login method for a team server (#204): a credential sent here is refused, unsent
146
+ if (body.email !== undefined || body.password !== undefined)
147
+ return answer(400, { ok: false, reason: 'password-retired', error: NO_PASSWORD_WORDS });
148
+ const r = await prepareManagedProject(
149
+ {},
150
+ { kind: 'known-hub', url: a.url },
151
+ { cloudConfigPath, hubsConfigPath, fetchImpl: hubFetch }
152
+ );
149
153
  if (!r.ok) return answer(r.status || 502, { ok: false, error: r.error });
150
154
  return answer(200, { ...r, profile });
151
155
  }
152
156
 
153
- // S6.11b — "Invite link or key": redeem a hub invite through the hub's own JSON `POST /join`
154
- // (apps/hub auth-routes.mjs), after the same tokenless probe. The invite token, the email and the
155
- // password ride that one POST body and nowhere else — never a URL, never a log line, never an
156
- // answer. Only the minted session is kept, in THIS profile's hubs.json; the project then prepares
157
- // exactly like a hub this Mac already holds a sign-in for.
158
- async function join(raw: unknown): Promise<HomeAnswer> {
157
+ // #204 K2 — "Sign in" / "Invite link or key": the hub's own page in the browser. The address and
158
+ // an invite are checked here before anything leaves; the invite key (or the hub's own invite link,
159
+ // which must name THIS hub) only ever becomes the path of the page the browser opens.
160
+ async function signInStart(raw: unknown, origin: string): Promise<HomeAnswer> {
159
161
  const body = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>;
160
162
  const profile = typeof body.profile === 'string' ? body.profile : '';
161
- const cloudConfigPath = profileCloudPath(profile);
162
163
  const hubsConfigPath = profileHubsPath(profile);
163
- if (!cloudConfigPath || !hubsConfigPath)
164
+ if (!profileCloudPath(profile) || !hubsConfigPath)
164
165
  return answer(400, { ok: false, error: 'unknown profile' });
165
166
  const a = hubAddress(body.url);
166
167
  if (!a.ok) return answer(400, { ok: false, error: a.error });
167
- const token = hubInviteToken(body.token, a.url);
168
- if (!token.ok) return answer(400, { ok: false, error: token.error });
169
- const { email, password } = body;
170
- if (typeof email !== 'string' || !email.trim() || email.length > MAX_EMAIL)
171
- return answer(400, { ok: false, error: 'Enter your email address.' });
172
- if (typeof password !== 'string' || !password || password.length > MAX_PASSWORD)
173
- return answer(400, { ok: false, error: 'Enter your password.' });
174
-
175
- // the same tokenless probe Test connection sends: nothing secret goes to a non-hub
176
- const probe = await test({ url: a.url });
177
- if (probe.status !== 200) {
178
- const b = probe.body as { error?: string };
179
- return answer(probe.status, { ok: false, error: b.error ?? JOIN_WORDS.unreachable });
180
- }
181
-
182
- let res: Response;
183
- try {
184
- res = await hubFetch(`${a.url}/join`, {
185
- method: 'POST',
186
- // the caller honours a canvas invite's access claim (S9.6b), or the hub refuses to spend it
187
- headers: {
188
- 'content-type': 'application/json',
189
- accept: 'application/json',
190
- 'x-maude-access': String(ACCESS_VERSION),
191
- },
192
- body: JSON.stringify({ token: token.value, email: email.trim(), password }),
193
- signal: AbortSignal.timeout(JOIN_TIMEOUT_MS),
194
- });
195
- } catch {
196
- return answer(502, { ok: false, error: JOIN_WORDS.unreachable });
197
- }
198
- let j: Record<string, unknown> | null = null;
199
- try {
200
- const text = await res.text();
201
- j = text.length <= MAX_HEALTH_BYTES ? (JSON.parse(text) as Record<string, unknown>) : null;
202
- } catch {
203
- j = null;
204
- }
205
- if (res.status !== 201 || j?.ok !== true || typeof j.token !== 'string' || !j.token) {
206
- return answer(joinStatus(res.status), {
207
- ok: false,
208
- reason: joinReason(res.status, j?.reason),
209
- error: joinError(res.status, j?.reason, j?.error),
210
- });
168
+ let invite: string | undefined;
169
+ if (body.invite !== undefined && body.invite !== null && body.invite !== '') {
170
+ const t = hubInviteToken(body.invite, a.url);
171
+ if (!t.ok) return answer(400, { ok: false, error: t.error });
172
+ invite = t.value;
211
173
  }
212
- const user = (j.user && typeof j.user === 'object' ? j.user : {}) as {
213
- role?: unknown;
214
- email?: unknown;
215
- };
216
- const role = typeof user.role === 'string' ? user.role : 'member';
217
- const expiresAt = typeof j.expiresAt === 'number' ? j.expiresAt : undefined;
218
- try {
219
- saveHubCredential(
220
- a.url,
221
- j.token,
222
- role,
223
- expiresAt,
224
- hubsConfigPath,
225
- typeof user.email === 'string' ? user.email : email.trim()
226
- );
227
- } catch {
228
- return answer(500, {
174
+ const r = await browserSignIn.start(a.url, origin, {
175
+ invite,
176
+ save: (u, token, role, expiresAt, account) =>
177
+ saveHubCredential(u, token, role, expiresAt, hubsConfigPath, account),
178
+ });
179
+ if (!r.ok)
180
+ return answer(r.status, {
229
181
  ok: false,
230
- error: "Couldn't save the hub connection on this computer.",
182
+ error: r.error,
183
+ ...(r.reason ? { reason: r.reason } : {}),
231
184
  });
232
- }
233
- const r = await prepareManagedProject(
234
- {},
235
- { kind: 'known-hub', url: a.url },
236
- { cloudConfigPath, hubsConfigPath, fetchImpl: hubFetch }
237
- );
238
- if (!r.ok) return answer(r.status || 502, { ok: false, error: r.error });
239
- return answer(200, { ...r, role: r.role ?? role, profile });
185
+ return answer(200, { ...r, profile });
186
+ }
187
+
188
+ async function signInPoll(raw: unknown): Promise<HomeAnswer> {
189
+ const r: PollAnswer = browserSignIn.poll((raw as { id?: unknown } | null)?.id);
190
+ return answer(200, r);
191
+ }
192
+
193
+ async function signInCancel(raw: unknown): Promise<HomeAnswer> {
194
+ browserSignIn.cancel((raw as { id?: unknown } | null)?.id);
195
+ return answer(200, { ok: true });
240
196
  }
241
197
 
242
- return { test, prepare, join };
198
+ const signInReturn = (params: URLSearchParams) => browserSignIn.onReturn(params);
199
+
200
+ return { test, prepare, signInStart, signInPoll, signInCancel, signInReturn };
243
201
  }
244
202
 
245
- const JOIN_TIMEOUT_MS = 15_000;
246
203
  const MAX_INVITE = 256;
247
204
  const INVITE_RE = /^inv_[A-Za-z0-9_-]{16,200}$/;
248
205
 
249
206
  const JOIN_WORDS = {
250
- unreachable: "Couldn't reach that hub. Check the address, or whether it's online.",
251
- badInvite: "That doesn't look like an invite link or key.",
207
+ badInvite: HUB_SIGNIN_WORDS.badInvite,
252
208
  otherHub: 'That invite is for a different hub address.',
253
- dead: "This invite doesn't work any more. Ask whoever invited you for a new one.",
254
- rateLimited: 'Too many attempts. Wait a minute and try again.',
255
- refused: 'The hub refused the invite.',
256
209
  };
257
210
 
258
211
  /**
259
212
  * The invite a person pasted: the key itself (`inv_…`), or the hub's own invite link
260
- * `<hub>/join/<key>` — which must name THIS hub, so a link can't send the password to another host.
213
+ * `<hub>/join/<key>` — which must name THIS hub, so a link can't send the person to another host's page.
261
214
  */
262
215
  export function hubInviteToken(
263
216
  raw: unknown,
@@ -287,54 +240,3 @@ export function hubInviteToken(
287
240
  if (!at.ok || at.url !== hubUrl) return { ok: false, error: JOIN_WORDS.otherHub };
288
241
  return { ok: true, value: key };
289
242
  }
290
-
291
- const joinStatus = (status: number) =>
292
- status === 410 || status === 400 || status === 403 || status === 429 || status === 426
293
- ? status
294
- : 502;
295
-
296
- const REASONS = new Set([
297
- 'expired',
298
- 'already-used',
299
- 'revoked',
300
- 'unknown',
301
- 'email-mismatch',
302
- 'email-required',
303
- 'account-failed',
304
- 'no-access',
305
- 'password-refused-oidc-strict',
306
- ]);
307
- const joinReason = (status: number, reason: unknown) =>
308
- typeof reason === 'string' && REASONS.has(reason)
309
- ? reason
310
- : status === 429
311
- ? 'rate-limited'
312
- : status === 410
313
- ? 'gone'
314
- : 'refused';
315
-
316
- /** A refused join's reason → our words. */
317
- const REASON_WORDS: Record<string, string> = {
318
- expired: JOIN_WORDS.dead,
319
- revoked: JOIN_WORDS.dead,
320
- 'already-used': 'This invite was already used. Ask whoever invited you for a new one.',
321
- 'email-mismatch': 'This invite is for a different email address.',
322
- 'email-required': 'Enter your email address.',
323
- 'account-failed': "The hub couldn't create your account. Try again in a minute.",
324
- 'no-access': "This account can't open that hub.",
325
- 'password-refused-oidc-strict':
326
- 'This hub signs you in through your organisation, not a password.',
327
- };
328
-
329
- /**
330
- * Always OUR words (gate-b-sec1): the hub's own `error` text is never shown — Home is a trusted surface and a
331
- * hostile or compromised hub could put phishing words there ("call support at …"). Only the status and the
332
- * reason code pick the sentence.
333
- */
334
- function joinError(status: number, reason: unknown, _error?: unknown): string {
335
- if (status === 429) return JOIN_WORDS.rateLimited;
336
- if (typeof reason === 'string' && Object.hasOwn(REASON_WORDS, reason))
337
- return REASON_WORDS[reason] as string;
338
- if (status === 410) return JOIN_WORDS.dead;
339
- return JOIN_WORDS.refused;
340
- }
@@ -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,