@1agh/maude 2.1.0 → 2.1.1

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 (100) hide show
  1. package/apps/studio/access/request.ts +1 -0
  2. package/apps/studio/actions/agents.ts +27 -0
  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.manifest.json +60 -2
  6. package/apps/studio/actions.parity.json +13 -1
  7. package/apps/studio/bin/_curl-local.mjs +7 -4
  8. package/apps/studio/client/app.jsx +16 -4
  9. package/apps/studio/client/home/HomeAccountsRow.jsx +221 -0
  10. package/apps/studio/client/home/HomeConnection.jsx +111 -0
  11. package/apps/studio/client/home/home-accounts-model.js +110 -1
  12. package/apps/studio/client/home/home-api.js +6 -2
  13. package/apps/studio/client/home/home-app.jsx +74 -12
  14. package/apps/studio/client/home/home-model.js +40 -1
  15. package/apps/studio/client/home/home-where-model.js +105 -0
  16. package/apps/studio/client/home/home.css +233 -1
  17. package/apps/studio/client/hooks/use-palette-and-panels.jsx +3 -1
  18. package/apps/studio/client/hooks/use-tabs.jsx +11 -4
  19. package/apps/studio/client/panels/TeamProjects.jsx +137 -134
  20. package/apps/studio/client/share-link.js +12 -0
  21. package/apps/studio/client/styles/_index.css +4 -0
  22. package/apps/studio/client/v2/diagnostics/diagnostics-host.jsx +1 -0
  23. package/apps/studio/client/v2/diagnostics/diagnostics-model.js +32 -2
  24. package/apps/studio/client/v2/diagnostics/diagnostics-sheet.jsx +35 -8
  25. package/apps/studio/client/v2/diagnostics/diagnostics.css +34 -0
  26. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +94 -3
  27. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +187 -4
  28. package/apps/studio/client/v2/link-server/LinkServerDialog.jsx +492 -0
  29. package/apps/studio/client/v2/link-server/LinkServerHost.jsx +42 -0
  30. package/apps/studio/client/v2/link-server/link-server-api.js +142 -0
  31. package/apps/studio/client/v2/link-server/link-server-model.js +438 -0
  32. package/apps/studio/client/v2/link-server/link-server.css +109 -0
  33. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +31 -86
  34. package/apps/studio/client/v2/onboarding/onboarding-model.js +1 -18
  35. package/apps/studio/client/v2/search/search-keywords.js +3 -2
  36. package/apps/studio/client/v2/settings/account.jsx +4 -2
  37. package/apps/studio/client/v2/settings/advanced-section.jsx +245 -148
  38. package/apps/studio/client/v2/settings/connection-row.jsx +3 -59
  39. package/apps/studio/client/v2/settings/connections-section.jsx +118 -425
  40. package/apps/studio/client/v2/settings/general-section.jsx +138 -43
  41. package/apps/studio/client/v2/settings/project-sync-settings.jsx +4 -3
  42. package/apps/studio/client/v2/settings/reset-section.jsx +14 -3
  43. package/apps/studio/client/v2/settings/settings-card.jsx +142 -0
  44. package/apps/studio/client/v2/settings/settings-cards.js +220 -0
  45. package/apps/studio/client/v2/settings/settings-handlers.js +7 -6
  46. package/apps/studio/client/v2/settings/settings-model.js +91 -31
  47. package/apps/studio/client/v2/settings/settings-sheet.jsx +25 -6
  48. package/apps/studio/client/v2/settings/settings.css +374 -64
  49. package/apps/studio/client/v2/settings/this-project-card.jsx +730 -0
  50. package/apps/studio/client/v2/settings/this-project-model.js +172 -0
  51. package/apps/studio/client/v2/settings/use-connections.js +3 -2
  52. package/apps/studio/client/v2/settings/use-open-card.js +37 -0
  53. package/apps/studio/client/v2/shell/connection-state.js +197 -0
  54. package/apps/studio/client/v2/shell/menu-runner.js +7 -2
  55. package/apps/studio/client/v2/shell/project-account-bus.js +36 -0
  56. package/apps/studio/client/v2/shell/project-account-card.jsx +357 -148
  57. package/apps/studio/client/v2/shell/project-account-model.js +272 -149
  58. package/apps/studio/client/v2/shell/project-account-toast.js +66 -0
  59. package/apps/studio/client/v2/shell/project-account.css +237 -0
  60. package/apps/studio/client/v2/shell/share-cluster-host.jsx +166 -83
  61. package/apps/studio/client/v2/shell/shell-parity.js +3 -2
  62. package/apps/studio/client/v2/shell/shell-parity.json +40 -26
  63. package/apps/studio/client/v2/shell/use-account.js +2 -0
  64. package/apps/studio/client/v2/signin/use-signin.js +1 -1
  65. package/apps/studio/cloud/endpoints.ts +29 -4
  66. package/apps/studio/dist/client.bundle.js +834 -834
  67. package/apps/studio/dist/styles.css +1 -1
  68. package/apps/studio/home/accounts.ts +30 -11
  69. package/apps/studio/home/cloud.ts +6 -1
  70. package/apps/studio/home/hub-health.ts +76 -0
  71. package/apps/studio/home/routes.ts +9 -3
  72. package/apps/studio/http.ts +8 -0
  73. package/apps/studio/migrate/hub.ts +8 -1
  74. package/apps/studio/routes/hub-link-folder.ts +334 -0
  75. package/apps/studio/routes/hub-signin.ts +78 -1
  76. package/apps/studio/routes/index.ts +4 -0
  77. package/apps/studio/routes/sync.ts +22 -4
  78. package/apps/studio/shell/api-key.ts +11 -0
  79. package/apps/studio/sync/accepted-cold-start.ts +144 -8
  80. package/apps/studio/sync/action-stage.ts +18 -1
  81. package/apps/studio/sync/ctl-heal.ts +58 -0
  82. package/apps/studio/sync/file-ledger.ts +38 -4
  83. package/apps/studio/sync/file-plane.ts +226 -19
  84. package/apps/studio/sync/held-deletes.ts +86 -5
  85. package/apps/studio/sync/hub-link.ts +8 -0
  86. package/apps/studio/sync/index.ts +68 -4
  87. package/apps/studio/sync/link-consent.ts +22 -75
  88. package/apps/studio/sync/link-survey.ts +252 -0
  89. package/apps/studio/sync/local-kernel.ts +16 -1
  90. package/apps/studio/sync/seed-progress.ts +12 -0
  91. package/apps/studio/sync/source-recovery.ts +18 -2
  92. package/apps/studio/sync/status.ts +11 -1
  93. package/apps/studio/sync/writer-registry.ts +5 -0
  94. package/apps/studio/whats-new.json +18 -0
  95. package/cli/lib/bash-guard.mjs +19 -0
  96. package/cli/lib/design-help.gen.mjs +1 -1
  97. package/package.json +9 -8
  98. package/apps/studio/client/v2/onboarding/HubSheet.jsx +0 -212
  99. package/apps/studio/client/v2/shell/account-card-model.js +0 -114
  100. package/apps/studio/client/v2/shell/account-card.jsx +0 -189
@@ -0,0 +1,172 @@
1
+ // client/v2/settings/this-project-model.js — 2.1.1 T6: Settings › General › This project (canvas 17 · 08 · 09).
2
+ //
3
+ // PURE (no DOM, no React, no fetch). The card says three things about THIS project — where it lives, which
4
+ // account it uses, whether it connects — and carries the one fix in its header when a sign-in broke:
5
+ //
6
+ // This project Brand site
7
+ // Your folder · ~/git/brand-site · also on Maude Cloud
8
+ // ● Connected · synced 2 min ago
9
+ // Lives in [Your folder ~/git/brand-site] Change…
10
+ // Account alice@example.com Switch…
11
+ // Connection ● Connected · synced 2 min ago
12
+ // › Sync details Project files · trash · first link
13
+ //
14
+ // The connection is the shell's one model (shell/connection-state.js, 2.1.1 T2): the same seven states and
15
+ // words the avatar, the save word and the toast say. Where it lives is `/_api/cloud/status` `place`
16
+ // (`{ kept: true }` for a copy Maude keeps, else `{ kept: false, folder }` with home as `~`).
17
+
18
+ import { syncPresentation } from '../../../sync/presentation.ts';
19
+ import { connectionState, connectionWords } from '../shell/connection-state.js';
20
+
21
+ /** The status dot per state (canvas 17 `StatusWord`: ok · busy · off · error · warn). */
22
+ const DOT = Object.freeze({
23
+ connected: 'ok',
24
+ syncing: 'busy',
25
+ offline: 'off',
26
+ 'signin-missing': 'error',
27
+ 'signin-rejected': 'error',
28
+ unreachable: 'warn',
29
+ unconfirmed: 'off',
30
+ local: 'off',
31
+ });
32
+
33
+ const str = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
34
+
35
+ /** "synced just now" · "synced 2 min ago" · "synced at 14:05" · null. */
36
+ export function syncedWords(ms, now = Date.now()) {
37
+ if (!Number.isFinite(ms) || ms <= 0) return null;
38
+ const age = Math.max(0, now - ms);
39
+ if (age < 60_000) return 'synced just now';
40
+ if (age < 60 * 60_000) return `synced ${Math.floor(age / 60_000)} min ago`;
41
+ const d = new Date(ms);
42
+ return `synced at ${d.getHours()}:${String(d.getMinutes()).padStart(2, '0')}`;
43
+ }
44
+
45
+ /** The card's status line for a connection (the header line and the Connection row say the same). */
46
+ export function statusLine(conn, { syncStatus = null, pending = 0, now = Date.now() } = {}) {
47
+ const w = connectionWords(conn, { pending });
48
+ switch (conn.state) {
49
+ case 'connected': {
50
+ const synced = syncedWords(syncStatus?.lastSyncAt, now);
51
+ return synced ? `Connected · ${synced}` : 'Connected';
52
+ }
53
+ case 'syncing':
54
+ return w.line;
55
+ default:
56
+ return w.word;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * The whole card.
62
+ * @param in.status `/_api/cloud/status` json (`connected`, `email`, `url`, `project`, `linkedHub`, `place`)
63
+ * @param in.syncStatus the shell's sync payload
64
+ * @param in.hubAccount the team-server sign-in's recorded account (`/_api/connections/hub` `account`)
65
+ * @param in.native the desktop app (Show in Finder is the Mac app's door)
66
+ */
67
+ export function thisProjectModel({
68
+ status = null,
69
+ syncStatus = null,
70
+ hubAccount = null,
71
+ online = true,
72
+ native = false,
73
+ now = Date.now(),
74
+ } = {}) {
75
+ const linkedHub = status?.linkedHub?.url ? status.linkedHub : null;
76
+ const pending = Number(syncStatus?.queuedOps) || Number(syncStatus?.docs?.pending) || 0;
77
+ const conn = connectionState({
78
+ linkedHub,
79
+ cloudUrl: status?.url ?? '',
80
+ syncStatus,
81
+ phase: syncPresentation(syncStatus ?? null)?.phase ?? null,
82
+ pending,
83
+ online,
84
+ });
85
+ const words = connectionWords(conn, { pending });
86
+ const host = conn.host ?? '';
87
+ const linkKind = conn.kind === 'local' ? null : conn.kind;
88
+ const kept = status?.place?.kept === true;
89
+ const folder = !kept ? (str(status?.place?.folder) ?? '') : '';
90
+
91
+ // Lives in: the person's folder, or a copy Maude keeps — of a server project it reads "On <host>".
92
+ let place;
93
+ if (kept && linkKind === 'server') place = { kind: 'server', label: `On ${host}`, path: '' };
94
+ else if (kept) place = { kind: 'kept', label: 'Kept by Maude', path: '' };
95
+ else place = { kind: 'folder', label: 'Your folder', path: folder };
96
+
97
+ const where = place.kind === 'folder' && folder ? `Your folder · ${folder}` : place.label;
98
+ let desc;
99
+ if (place.kind === 'server') desc = `${where} · copy kept by Maude`;
100
+ else if (linkKind === 'cloud') desc = `${where} · also on Maude Cloud`;
101
+ else if (linkKind === 'server') desc = `${where} · also on ${host}`;
102
+ else desc = `${where} · only on this Mac`;
103
+
104
+ // Account: who this project talks as — never a token, only the name the page already holds.
105
+ let account;
106
+ if (linkKind === 'cloud')
107
+ account = { kind: 'cloud', label: str(status?.email) ?? 'Maude Cloud', host };
108
+ else if (linkKind === 'server')
109
+ account = { kind: 'server', label: str(hubAccount) ?? host, host };
110
+ else account = { kind: 'local', label: 'No account', host: '' };
111
+
112
+ const bad = conn.state === 'signin-missing' || conn.state === 'signin-rejected';
113
+ const where2 = linkKind === 'cloud' ? 'Maude Cloud' : host || 'the server';
114
+ const callout =
115
+ conn.state === 'signin-rejected'
116
+ ? {
117
+ title: `Your sign-in to ${where2} stopped working.`,
118
+ line: 'Changes wait on this Mac and go out after you sign in.',
119
+ }
120
+ : conn.state === 'signin-missing'
121
+ ? {
122
+ title: `This project is on ${where2} — sign in to sync.`,
123
+ line: 'Changes wait on this Mac and go out after you sign in.',
124
+ }
125
+ : null;
126
+
127
+ // Change…: only what this Mac can do today. Moving a project between the person's folder and a copy
128
+ // Maude keeps has no backend yet, so those rows are listed as unavailable and never drawn.
129
+ const changeOptions = [
130
+ {
131
+ id: 'folder',
132
+ label: 'Your folder',
133
+ detail: place.kind === 'folder' ? folder : '',
134
+ current: place.kind === 'folder',
135
+ available: place.kind === 'folder',
136
+ },
137
+ { id: 'another-folder', label: 'Use another folder…', current: false, available: false },
138
+ {
139
+ id: 'kept',
140
+ label: 'Let Maude keep it',
141
+ detail: 'no path',
142
+ current: place.kind !== 'folder',
143
+ available: place.kind !== 'folder',
144
+ },
145
+ { id: 'finder', label: 'Show in Finder', current: false, available: !!native },
146
+ ];
147
+
148
+ return {
149
+ name: str(status?.project) ?? 'this project',
150
+ conn,
151
+ statusWord: statusLine(conn, { syncStatus, pending, now }),
152
+ sw: DOT[conn.state] ?? 'off',
153
+ bad,
154
+ fixLabel: bad ? (words.fix?.label ?? 'Sign in') : null,
155
+ callout,
156
+ place,
157
+ desc,
158
+ account,
159
+ linkKind,
160
+ // an address this Mac never confirmed is never handed to a sign-in (2.1.1 T8): Review… instead
161
+ unconfirmed:
162
+ conn.state === 'unconfirmed'
163
+ ? { line: words.line, label: words.fix?.label ?? 'Review…' }
164
+ : null,
165
+ hubUrl: conn.state === 'unconfirmed' ? null : (linkedHub?.url ?? null),
166
+ host,
167
+ local: conn.state === 'local',
168
+ changeOptions,
169
+ // the menu is drawn only when it has something to do beyond saying where the project is
170
+ canChange: changeOptions.some((o) => o.available && !o.current),
171
+ };
172
+ }
@@ -50,7 +50,8 @@ export function useCloudConnection({ onLinkedHub, onLocalProject, syncStatus } =
50
50
  const [email, setEmail] = useState(null);
51
51
  // The address this Mac signs in against (`status.url`) — never a hard-coded vendor URL.
52
52
  const [cloudUrl, setCloudUrl] = useState('');
53
- const [local, setLocal] = useState({ project: '', linkedHub: null });
53
+ // `place` (2.1.1 T2): `{ kept: true }` or `{ kept: false, folder }` — where this project lives
54
+ const [local, setLocal] = useState({ project: '', linkedHub: null, place: null });
54
55
  const [projects, setProjects] = useState(null);
55
56
  const [busy, setBusy] = useState('');
56
57
  const [error, setError] = useState('');
@@ -76,7 +77,7 @@ export function useCloudConnection({ onLinkedHub, onLocalProject, syncStatus } =
76
77
  const r = await api('/_api/cloud/status');
77
78
  if (r.json?.url) setCloudUrl(r.json.url);
78
79
  const linkedHub = r.json?.linkedHub ?? null;
79
- setLocal({ project: r.json?.project ?? '', linkedHub });
80
+ setLocal({ project: r.json?.project ?? '', linkedHub, place: r.json?.place ?? null });
80
81
  liftRef.current.onLinkedHub?.(linkedHub);
81
82
  liftRef.current.onLocalProject?.(r.json?.project ?? null);
82
83
  if (r.ok && r.json?.connected) {
@@ -0,0 +1,37 @@
1
+ // client/v2/settings/use-open-card.js — 2.1.1 T6: which card of a Settings tab is open (one at a time),
2
+ // remembered per tab for this session (settings-cards.js). `focus` is ⌘K's ask — `{ card, n }`, a new `n`
3
+ // each time — and opens the card that holds the hit even when the person had closed it.
4
+
5
+ import { useCallback, useEffect, useState } from 'react';
6
+
7
+ import { openCardOf, readOpenCards, toggleCard, writeOpenCard } from './settings-cards.js';
8
+
9
+ export function useOpenCard(tab, focus = null) {
10
+ const [open, setOpen] = useState(() => focus?.card ?? openCardOf(tab, readOpenCards()));
11
+ const focusCard = focus?.card ?? null;
12
+ const focusN = focus?.n ?? 0;
13
+ // biome-ignore lint/correctness/useExhaustiveDependencies: a new ask (`n`) re-opens the same card
14
+ useEffect(() => {
15
+ if (!focusCard) return;
16
+ setOpen(focusCard);
17
+ writeOpenCard(tab, focusCard);
18
+ }, [tab, focusCard, focusN]);
19
+ const toggle = useCallback(
20
+ (id) =>
21
+ setOpen((cur) => {
22
+ const next = toggleCard(cur, id);
23
+ writeOpenCard(tab, next);
24
+ return next;
25
+ }),
26
+ [tab]
27
+ );
28
+ /** Open `id` (a header action that needs its card's body, e.g. Manage…). */
29
+ const show = useCallback(
30
+ (id) => {
31
+ setOpen(id);
32
+ writeOpenCard(tab, id);
33
+ },
34
+ [tab]
35
+ );
36
+ return { open, toggle, show };
37
+ }
@@ -0,0 +1,197 @@
1
+ // client/v2/shell/connection-state.js — 2.1.1 T2: is THIS project's connection working, and whose move
2
+ // is it? (canvas 17 · ac-states). PURE: one place derives the state the account chip's badge, the save
3
+ // word, the avatar menu's project block and the once-per-session toast all say.
4
+ //
5
+ // Eight states, from what the page already holds:
6
+ // local no `linkedHub` in this folder: nothing leaves this Mac (a plain laptop, never a badge)
7
+ // unconfirmed the folder NAMES a server this Mac never linked or confirmed (`/_api/cloud/status`
8
+ // `linkedHub.confirmed === false`, from this Mac's link record — gate-b-sec4 parked it).
9
+ // A committed address is a peer's text: no toast, no badge, no prefilled sign-in — only
10
+ // a neutral line and Review…, which opens the Share sheet's Connect (the consent step).
11
+ // signin-missing a server this Mac linked (`confirmed`) and holds no sign-in for
12
+ // (`linkedHub.credentialed === false`)
13
+ // signin-rejected the server refuses the sign-in this Mac holds: the accepted lane's
14
+ // `accepted.credentialRefused` (sync/status.ts), or every document refused with
15
+ // `invalid-token` (DDR-102's own classification, sync/index.ts `AuthFailureClass`)
16
+ // offline this Mac has no network (`navigator.onLine === false`) — the face greys, nothing to do
17
+ // unreachable the network is up but the server does not answer (the hub monitor's offline /
18
+ // offline-long, or syncPresentation's offline / stalled)
19
+ // syncing a pass is running or changes are going out
20
+ // connected everything else on a linked folder
21
+ //
22
+ // The badge says whose move it is (canvas 17 note 2): `broken` only for a sign-in the person can repair
23
+ // in one click, `warn` for the server's side, `grey` for the network, a turning `ring` while syncing.
24
+
25
+ import { isCloudHub } from '../settings/connections-model.js';
26
+
27
+ export const CONNECTION_STATES = Object.freeze([
28
+ 'connected',
29
+ 'syncing',
30
+ 'offline',
31
+ 'signin-missing',
32
+ 'signin-rejected',
33
+ 'unreachable',
34
+ 'unconfirmed',
35
+ 'local',
36
+ ]);
37
+
38
+ const UNREACHABLE_PHASES = new Set(['offline', 'stalled']);
39
+ const SYNCING_PHASES = new Set(['connecting', 'syncing']);
40
+
41
+ /** host, plus the port when it is not the scheme's default — how every surface names a server */
42
+ export function hostOf(url) {
43
+ try {
44
+ return new URL(String(url)).host.toLowerCase();
45
+ } catch {
46
+ return '';
47
+ }
48
+ }
49
+
50
+ const str = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
51
+ const count = (n) => (Number.isFinite(n) && n > 0 ? n : 0);
52
+
53
+ /** The sign-in this Mac holds is refused (only a literal `true`, never a guess). */
54
+ export function signInRefused(syncStatus) {
55
+ const s = syncStatus && typeof syncStatus === 'object' ? syncStatus : null;
56
+ if (!s) return false;
57
+ if (s.accepted && typeof s.accepted === 'object' && s.accepted.credentialRefused === true)
58
+ return true;
59
+ // Every document refused, and refused for an invalid token: the sign-in itself stopped working.
60
+ const docs = s.docs && typeof s.docs === 'object' ? s.docs : null;
61
+ const items = Array.isArray(s.items) ? s.items : [];
62
+ if (!docs || count(docs.rejected) === 0 || count(docs.synced) > 0) return false;
63
+ return items.some((i) => i?.state === 'auth-rejected' && i?.reason === 'invalid-token');
64
+ }
65
+
66
+ /**
67
+ * @param in.linkedHub `/_api/cloud/status` `linkedHub` — `{ url, credentialed, confirmed }` or null
68
+ * @param in.cloudUrl the Maude Cloud address this Mac signs in against (tells cloud from your server)
69
+ * @param in.syncStatus the shell's raw sync status (the hub monitor + the accepted lane)
70
+ * @param in.phase syncPresentation(syncStatus).phase, or null
71
+ * @param in.pending changes still going out (queued ops + the outbox)
72
+ * @param in.online false only when the browser says there is no network
73
+ * @returns {{ state, kind: 'cloud'|'server'|'local', host: string|null, url: string|null,
74
+ * (an unconfirmed claim is kind 'local' — nothing leaves this Mac — with the named host)
75
+ * badge: 'broken'|'warn'|'grey'|'ring'|null }}
76
+ */
77
+ export function connectionState(input = {}) {
78
+ const {
79
+ linkedHub = null,
80
+ cloudUrl = '',
81
+ syncStatus = null,
82
+ phase = null,
83
+ pending = 0,
84
+ online = true,
85
+ } = input ?? {};
86
+ const url = str(linkedHub?.url);
87
+ if (!url) return { state: 'local', kind: 'local', host: null, url: null, badge: null };
88
+ // An address this Mac never confirmed: what the repo says, worded as such — never as a repair.
89
+ if (linkedHub?.confirmed === false)
90
+ return { state: 'unconfirmed', kind: 'local', host: hostOf(url) || null, url, badge: null };
91
+ const kind = isCloudHub(url, cloudUrl) ? 'cloud' : 'server';
92
+ const host = hostOf(url) || url;
93
+ const out = (state, badge) => ({ state, kind, host, url, badge });
94
+ if (linkedHub?.credentialed !== true) return out('signin-missing', 'broken');
95
+ if (signInRefused(syncStatus)) return out('signin-rejected', 'broken');
96
+ if (online === false) return out('offline', 'grey');
97
+ const hub = syncStatus?.state;
98
+ if (hub === 'offline' || hub === 'offline-long' || UNREACHABLE_PHASES.has(phase))
99
+ return out('unreachable', 'warn');
100
+ if (SYNCING_PHASES.has(phase) || count(pending) > 0) return out('syncing', 'ring');
101
+ return out('connected', null);
102
+ }
103
+
104
+ /** Where the sign-in lives, in the menu's words: "Maude Cloud" or the server's host. */
105
+ const placeName = (c) => (c.kind === 'cloud' ? 'Maude Cloud' : c.host || 'the server');
106
+
107
+ /**
108
+ * The words each state says (canvas 17 · ac-states, CONTRACT voice): the save word beside the chip, the
109
+ * status line of the avatar menu, and the one-click fix.
110
+ * @param c connectionState()
111
+ * @param in.pending changes going out ("Syncing · 3 changes going out")
112
+ * @returns {{ word, icon, tone, line, fix: null | { id: 'sign-in'|'retry'|'move-to-cloud', label } }}
113
+ */
114
+ export function connectionWords(c, { pending = 0 } = {}) {
115
+ const where = placeName(c ?? {});
116
+ const n = count(pending);
117
+ switch (c?.state) {
118
+ case 'signin-missing':
119
+ return {
120
+ word: 'Sign in to sync',
121
+ icon: 'lock',
122
+ tone: 'error',
123
+ line: `This project is on ${where} — sign in to sync.`,
124
+ fix: { id: 'sign-in', label: 'Sign in' },
125
+ };
126
+ case 'signin-rejected':
127
+ return {
128
+ word: 'Sign-in stopped working',
129
+ icon: 'lock',
130
+ tone: 'error',
131
+ line: `Your sign-in to ${where} stopped working. Changes wait on this Mac.`,
132
+ fix: { id: 'sign-in', label: 'Sign in again' },
133
+ };
134
+ case 'unreachable':
135
+ return {
136
+ word: `Can’t reach ${where}`,
137
+ icon: 'problem',
138
+ tone: 'warn',
139
+ line: `${where} doesn’t answer. Changes wait on this Mac.`,
140
+ fix: { id: 'retry', label: `Retry ${where}` },
141
+ };
142
+ case 'offline':
143
+ return {
144
+ word: 'Offline — changes wait on this Mac',
145
+ icon: 'offline',
146
+ tone: 'warn',
147
+ line: 'Offline — changes wait on this Mac. They go out when it’s back online.',
148
+ fix: null,
149
+ };
150
+ case 'syncing':
151
+ return {
152
+ word: 'Syncing…',
153
+ icon: 'sync',
154
+ tone: '',
155
+ line: n > 0 ? `Syncing · ${n} change${n === 1 ? '' : 's'} going out` : 'Syncing',
156
+ fix: null,
157
+ };
158
+ case 'connected':
159
+ return { word: 'Saved', icon: 'cloud', tone: '', line: 'Connected', fix: null };
160
+ case 'unconfirmed':
161
+ return {
162
+ word: 'Not linked on this Mac',
163
+ icon: 'laptop',
164
+ tone: '',
165
+ line: `This project names ${c.host || 'a server'}. Not linked on this Mac.`,
166
+ fix: { id: 'review-link', label: 'Review…' },
167
+ };
168
+ default:
169
+ return {
170
+ word: 'Only on this Mac',
171
+ icon: 'laptop',
172
+ tone: '',
173
+ line: 'Nothing leaves this Mac.',
174
+ fix: { id: 'move-to-cloud', label: 'Put on Maude Cloud…' },
175
+ };
176
+ }
177
+ }
178
+
179
+ /** True for the two states the person repairs with one sign-in (the broken-link badge, the toast). */
180
+ export const isBrokenSignIn = (c) =>
181
+ c?.state === 'signin-missing' || c?.state === 'signin-rejected';
182
+
183
+ /**
184
+ * The once-per-session toast for a broken sign-in (canvas 17 · ac-toast), or null. Keyed by project and
185
+ * state, so a missing sign-in fixed and later rejected is told again — but never twice for the same.
186
+ */
187
+ export function signInToast(c, { project = '' } = {}) {
188
+ if (!isBrokenSignIn(c)) return null;
189
+ const w = connectionWords(c);
190
+ return {
191
+ key: `${project || '-'}|${c.url || ''}|${c.state}`,
192
+ id: `signin-${c.state}`,
193
+ title: w.line,
194
+ kind: 'warning',
195
+ actionLabel: w.fix.label,
196
+ };
197
+ }
@@ -27,6 +27,7 @@ import { createAccessHandlers } from '../access/access-client.js';
27
27
  import { createDiagnosticsHandlers } from '../diagnostics/diagnostics-handlers.js';
28
28
  import { runFillAsk } from '../empty/fill-ask.js';
29
29
  import { runAssetsAction } from '../assets/assets-bus.js';
30
+ import { runLinkServer } from './project-account-bus.js';
30
31
  import { runTakeStepNow } from '../assets/use-takes-lane.js';
31
32
  import { runCopyPng } from '../export/copy-png.js';
32
33
  import { foldStore } from '../fold/use-fold.js';
@@ -280,6 +281,9 @@ export function createMenuHandlers(d) {
280
281
  'handoff.open': () => d.setExportDialog({ mode: 'handoff' }),
281
282
  'canvas.close': () => d.onCloseCanvas(),
282
283
  'account.switch': () => d.onSwitchAccount(),
284
+ // 2.1.1 T4 — the Switch account list's foot (account-menu.js)
285
+ 'account.add-cloud': () => d.onAddCloudAccount?.(),
286
+ 'account.link-server': (params) => runLinkServer(params, d),
283
287
  // 2.0.5 W4 — the GitHub device flow is the mounted host's (github-signin-host.jsx: its code sheet
284
288
  // and state); it hears this the way IdentityBar hears project.new. A browser tab has no keychain.
285
289
  'account.github-signin': () => {
@@ -591,9 +595,10 @@ export function createMenuHandlers(d) {
591
595
  requestShareFocus('link');
592
596
  d.onShare();
593
597
  },
594
- 'share.move-to-cloud': () => d.onShare(),
598
+ // 2.1.1 T7 — about the project, not a canvas: the project's sheet when no canvas is open
599
+ 'share.move-to-cloud': () => d.onShare({ project: true }),
595
600
  // gate-b-sec4 — Connect lives in the Share sheet
596
- 'sync.connect-link': () => d.onShare(),
601
+ 'sync.connect-link': () => d.onShare({ project: true }),
597
602
  // S9.21 — Ask to edit (the Viewing button, ⌘K) and the owner's answer (the request block's buttons)
598
603
  ...createAccessHandlers(d),
599
604
  // `{ tab }` lands on that section ("Connect a Google key?" → connections); the sheet resolves a name it lacks
@@ -0,0 +1,36 @@
1
+ // client/v2/shell/project-account-bus.js — 2.1.1 T2/T4: how the registry reaches the avatar menu and the
2
+ // team-server dialog without a new key handler.
3
+ //
4
+ // ACCOUNT_MENU_EVENT `account.switch` (⌘K, the tab menu) opens the avatar menu on its Switch account
5
+ // list; the Share cluster host hears it (share-cluster-host.jsx).
6
+ // LINK_SERVER_EVENT `account.link-server` — "Link your server…" / "Sign in with custom server…". The one
7
+ // team-server dialog (2.1.1 T5) hears it and calls `preventDefault()`. Nobody did → the
8
+ // row opens Settings › General › This project, where today's team-server dialog lives — a row never
9
+ // does nothing.
10
+
11
+ export const ACCOUNT_MENU_EVENT = 'maude:account-menu';
12
+ export const LINK_SERVER_EVENT = 'maude:link-server';
13
+
14
+ /** Open the avatar menu (`view`: 'menu' | 'switch'). */
15
+ export function openAccountMenu(view = 'switch') {
16
+ window.dispatchEvent(new CustomEvent(ACCOUNT_MENU_EVENT, { detail: { view } }));
17
+ }
18
+
19
+ /**
20
+ * `account.link-server`.
21
+ * @param params `{ intent?: 'link' | 'sign-in', url?: string }` — sign-in = "Sign in with custom server…"
22
+ * @param d the menu runner's deps (`setSettingsOpen`)
23
+ * @returns 'dialog' when the dialog took it, 'settings' when it fell back
24
+ */
25
+ export function runLinkServer(params, d) {
26
+ const detail = {
27
+ intent: params?.intent === 'sign-in' ? 'sign-in' : 'link',
28
+ ...(typeof params?.url === 'string' && params.url ? { url: params.url } : {}),
29
+ };
30
+ const ev = new CustomEvent(LINK_SERVER_EVENT, { detail, cancelable: true });
31
+ window.dispatchEvent(ev);
32
+ if (ev.defaultPrevented) return 'dialog';
33
+ // 2.1.1 T6: the project's link lives in General › This project (canvas 17 · 10)
34
+ d?.setSettingsOpen?.('general#this-project');
35
+ return 'settings';
36
+ }