@1agh/maude 1.7.1 → 1.9.0

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 (108) hide show
  1. package/apps/studio/acp/bridge.ts +15 -2
  2. package/apps/studio/acp/login-state.ts +1 -0
  3. package/apps/studio/acp/probe.ts +52 -1
  4. package/apps/studio/api.ts +431 -39
  5. package/apps/studio/asset-upload.ts +174 -0
  6. package/apps/studio/assets-s3.ts +37 -2
  7. package/apps/studio/bin/_curl-local.mjs +7 -0
  8. package/apps/studio/bin/_pdf-playwright.mjs +22 -1
  9. package/apps/studio/bin/_png-playwright.mjs +20 -1
  10. package/apps/studio/bin/_region.mjs +92 -0
  11. package/apps/studio/bin/annotate.mjs +16 -7
  12. package/apps/studio/bin/read-annotations.mjs +62 -4
  13. package/apps/studio/canvas-build.ts +59 -4
  14. package/apps/studio/canvas-lib.tsx +48 -1
  15. package/apps/studio/canvas-shell.tsx +28 -4
  16. package/apps/studio/client/app.jsx +441 -15903
  17. package/apps/studio/client/canvas-url.js +9 -0
  18. package/apps/studio/client/dialogs/asset-picker.jsx +331 -0
  19. package/apps/studio/client/dialogs/command-palette.jsx +112 -0
  20. package/apps/studio/client/dialogs/export-dialog.jsx +782 -0
  21. package/apps/studio/client/dialogs/help-modal.jsx +324 -0
  22. package/apps/studio/client/dialogs/shortcuts-overlay.jsx +144 -0
  23. package/apps/studio/client/embed-view.jsx +284 -0
  24. package/apps/studio/client/embed.js +101 -0
  25. package/apps/studio/client/export-center.jsx +2 -0
  26. package/apps/studio/client/github.js +36 -3
  27. package/apps/studio/client/hooks/use-canvas-bridge.jsx +2150 -0
  28. package/apps/studio/client/hooks/use-git-actions.jsx +236 -0
  29. package/apps/studio/client/hooks/use-keyboard-shortcuts.jsx +297 -0
  30. package/apps/studio/client/hooks/use-palette-and-panels.jsx +474 -0
  31. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +901 -0
  32. package/apps/studio/client/hooks/use-project-data.jsx +90 -0
  33. package/apps/studio/client/hooks/use-shell-core.jsx +1212 -0
  34. package/apps/studio/client/hooks/use-tabs.jsx +723 -0
  35. package/apps/studio/client/hooks/use-web-socket.jsx +13 -0
  36. package/apps/studio/client/inspector/artboard-knobs.jsx +456 -0
  37. package/apps/studio/client/inspector/color-picker.jsx +196 -0
  38. package/apps/studio/client/inspector/color.js +92 -0
  39. package/apps/studio/client/inspector/css-knobs.jsx +1720 -0
  40. package/apps/studio/client/inspector/css-vocab.jsx +131 -0
  41. package/apps/studio/client/inspector/ds-tokens.js +90 -0
  42. package/apps/studio/client/inspector/grid-tracks-editor.jsx +97 -0
  43. package/apps/studio/client/inspector/inspect-computed.jsx +68 -0
  44. package/apps/studio/client/inspector/inspector-panel.jsx +769 -0
  45. package/apps/studio/client/inspector/layers.jsx +322 -0
  46. package/apps/studio/client/inspector/selection.js +65 -0
  47. package/apps/studio/client/inspector/token-popover.jsx +301 -0
  48. package/apps/studio/client/menus/menubar.jsx +856 -0
  49. package/apps/studio/client/report-bug.jsx +8 -2
  50. package/apps/studio/client/selection-scope.js +40 -0
  51. package/apps/studio/client/shell/banners.jsx +272 -0
  52. package/apps/studio/client/shell/collapsed-rail.jsx +23 -0
  53. package/apps/studio/client/shell/comments-panel.jsx +177 -0
  54. package/apps/studio/client/shell/constants.js +60 -0
  55. package/apps/studio/client/shell/dock.jsx +131 -0
  56. package/apps/studio/client/shell/icons.jsx +370 -0
  57. package/apps/studio/client/shell/status-bar.jsx +215 -0
  58. package/apps/studio/client/shell/util.js +332 -0
  59. package/apps/studio/client/shell/viewport.jsx +254 -0
  60. package/apps/studio/client/system/system-view.jsx +255 -0
  61. package/apps/studio/client/tree/tree.jsx +1243 -0
  62. package/apps/studio/comments-overlay.tsx +6 -4
  63. package/apps/studio/config.schema.json +5 -0
  64. package/apps/studio/context.ts +20 -0
  65. package/apps/studio/dist/client.bundle.js +2728 -2728
  66. package/apps/studio/dist/comment-mount.js +2 -2
  67. package/apps/studio/embed-origins.ts +52 -0
  68. package/apps/studio/export-dialog.tsx +55 -3
  69. package/apps/studio/exporters/_browser-bundles.ts +21 -2
  70. package/apps/studio/exporters/format-scopes.ts +11 -3
  71. package/apps/studio/exporters/index.ts +17 -2
  72. package/apps/studio/exporters/jobs.ts +91 -23
  73. package/apps/studio/exporters/pdf.ts +10 -2
  74. package/apps/studio/exporters/png.ts +10 -2
  75. package/apps/studio/exporters/scope.ts +89 -15
  76. package/apps/studio/format.ts +296 -0
  77. package/apps/studio/generation/runtime-probe.ts +1 -1
  78. package/apps/studio/git/service.ts +1 -0
  79. package/apps/studio/http.ts +399 -36
  80. package/apps/studio/input-router.tsx +7 -1
  81. package/apps/studio/path-containment.ts +72 -0
  82. package/apps/studio/paths.ts +14 -1
  83. package/apps/studio/read-only-mode.ts +53 -0
  84. package/apps/studio/server.ts +123 -25
  85. package/apps/studio/sync/accepted-link.ts +6 -0
  86. package/apps/studio/sync/agent.ts +9 -1
  87. package/apps/studio/sync/cold-start-apply.ts +29 -4
  88. package/apps/studio/sync/cold-start.ts +78 -0
  89. package/apps/studio/sync/file-plane.ts +61 -1
  90. package/apps/studio/sync/format-sync.ts +160 -0
  91. package/apps/studio/sync/index.ts +208 -23
  92. package/apps/studio/sync/journal-client.ts +25 -5
  93. package/apps/studio/sync/migrate-seed.ts +8 -1
  94. package/apps/studio/sync/park.ts +39 -0
  95. package/apps/studio/sync/presentation.ts +9 -3
  96. package/apps/studio/sync/status.ts +2 -0
  97. package/apps/studio/sync/transaction-client.ts +130 -13
  98. package/apps/studio/sync/writer-registry.ts +5 -0
  99. package/apps/studio/ui-prefs.ts +95 -10
  100. package/apps/studio/use-canvas-media-drop.tsx +8 -28
  101. package/apps/studio/whats-new.json +36 -0
  102. package/apps/studio/ws.ts +19 -4
  103. package/cli/bin/claude-design-server.mjs +0 -0
  104. package/cli/commands/design.mjs +9 -2
  105. package/cli/commands/hub-workspace.mjs +25 -0
  106. package/cli/lib/workspace-plan.mjs +51 -0
  107. package/package.json +11 -9
  108. package/plugins/design/templates/_shell.html +58 -0
@@ -0,0 +1,296 @@
1
+ // Project format version — the studio side of V2-1.12 (Gate 0 A17), §5.2/§5.6.
2
+ //
3
+ // One integer per project. `.design/config.json` `formatVersion` (absent = 1)
4
+ // for local, git and Syncthing projects; for a hub-linked project the hub's
5
+ // store is the authority and this Mac mirrors it raise-only in
6
+ // `_state/hub-format.json`. A build EDITS a project only when the project's
7
+ // format equals the format it supports; any other format opens view only.
8
+ //
9
+ // projectFormat = max(config.formatVersion ?? 1, linked ? (hubLive ?? hubCached ?? 1) : 1)
10
+ //
11
+ // This module is pure policy + the one cache file. The lead wires it:
12
+ // http.ts projectReadOnly(req) ||= formatGate(ctx) !== null; the refusal;
13
+ // /_config + formatVersion / formatGate / readOnlyReason
14
+ // context.ts DevServerConfig.formatVersion?: number
15
+ // sync/index.ts noteHubFormat() from /health + the `maude.mode` notice (H1–H5)
16
+ // (see the V2-2.14 hand-back for the exact patch).
17
+
18
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
19
+ import path from 'node:path';
20
+
21
+ /**
22
+ * The format THIS build edits. The v2 branch is 2. The 1.x compatibility
23
+ * release (V2-2.18) cuts this module with 1 — the one-line difference between
24
+ * the two builds' gates. THIS is the 1.x cut: a format-2 project opens view
25
+ * only here ("Update Maude to edit"); a format-1 project stays fully editable.
26
+ */
27
+ export const SUPPORTED_FORMAT = 1;
28
+
29
+ /** The highest format any build knows of (the hub's 422 `max`). */
30
+ export const MAX_KNOWN_FORMAT = 2;
31
+
32
+ /**
33
+ * In a cloud cell the studio is the hub's own child: the hub writes the mirror
34
+ * itself under this key (V2-1.12 §5.2 — "studio child reads its paired hub"),
35
+ * whether or not the child also runs a paired sync link.
36
+ */
37
+ export const CELL_SELF_HUB = 'cell:self';
38
+
39
+ /** Which hub's mirror applies to this studio: its own cell hub, the linked hub, or none. */
40
+ export function formatHubUrl(
41
+ ctx: FormatCtx,
42
+ env: Record<string, string | undefined> = process.env
43
+ ): string | null {
44
+ if (env.MAUDE_WORKSPACE_MODE === '1') return CELL_SELF_HUB;
45
+ return ctx.cfg.linkedHub?.url ?? null;
46
+ }
47
+
48
+ /** Design-root-relative cache of the linked hub's format (runtime, DDR-115). */
49
+ export const HUB_FORMAT_REL = path.join('_state', 'hub-format.json');
50
+
51
+ export interface FormatCtx {
52
+ cfg: { formatVersion?: unknown; linkedHub?: { url: string } | null };
53
+ paths: { designRoot: string };
54
+ }
55
+
56
+ export interface FormatGate {
57
+ projectFormat: number;
58
+ supported: number;
59
+ source: 'config' | 'hub';
60
+ }
61
+
62
+ /** A config value → a format: a positive integer, else 1 (absent = 1). */
63
+ export function asFormat(v: unknown): number {
64
+ return typeof v === 'number' && Number.isInteger(v) && v >= 1 ? v : 1;
65
+ }
66
+
67
+ export interface HubFormatCache {
68
+ hub: string;
69
+ formatVersion: number;
70
+ epoch: number;
71
+ seenAt: string;
72
+ /** SUPPORTED_FORMAT of the build that wrote the record (absent = an older build). */
73
+ writtenBy?: number;
74
+ }
75
+
76
+ const normHub = (u: string) => u.replace(/\/+$/, '');
77
+
78
+ /** The cached hub format for THIS link, or null (absent, unreadable, or a
79
+ * cache left by another hub — a relink starts from nothing). */
80
+ export function readHubFormatCache(
81
+ designRoot: string,
82
+ hubUrl: string,
83
+ env: Record<string, string | undefined> = process.env
84
+ ): HubFormatCache | null {
85
+ // A cell's own hub keeps the mirror in ITS data dir and points the studio
86
+ // child at it (MAUDE_HUB_FORMAT_FILE) — never inside the tenant's checkout.
87
+ const file =
88
+ hubUrl === CELL_SELF_HUB
89
+ ? env.MAUDE_HUB_FORMAT_FILE || null
90
+ : path.join(designRoot, HUB_FORMAT_REL);
91
+ if (!file) return null;
92
+ try {
93
+ const raw = JSON.parse(readFileSync(file, 'utf8')) as Partial<HubFormatCache>;
94
+ if (typeof raw?.hub !== 'string' || normHub(raw.hub) !== normHub(hubUrl)) return null;
95
+ return {
96
+ hub: raw.hub,
97
+ formatVersion: asFormat(raw.formatVersion),
98
+ epoch: typeof raw.epoch === 'number' ? raw.epoch : 0,
99
+ seenAt: typeof raw.seenAt === 'string' ? raw.seenAt : '',
100
+ ...(typeof raw.writtenBy === 'number' ? { writtenBy: raw.writtenBy } : {}),
101
+ };
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Record what the hub said (from `/health` or the `maude.mode` notice).
109
+ * RAISE-ONLY per hub (§5.2): a hub can raise the mirrored value, never lower
110
+ * it — only the owner's `maude migrate v2 --reverse` lowers both, and it does
111
+ * that by unflipping the hub (epoch + 1) and calling this with `allowLower`.
112
+ * Returns true when the cached value changed (the caller emits
113
+ * `config-updated` so shells refetch `/_config`).
114
+ */
115
+ export function noteHubFormat(
116
+ designRoot: string,
117
+ seen: { hub: string; formatVersion: number; epoch?: number },
118
+ opts: { now?: () => Date; allowLower?: boolean } = {}
119
+ ): boolean {
120
+ // The cell's mirror belongs to its hub; the child only reads it.
121
+ if (seen.hub === CELL_SELF_HUB) return false;
122
+ const cur = readHubFormatCache(designRoot, seen.hub);
123
+ const next = asFormat(seen.formatVersion);
124
+ if (cur && !opts.allowLower && next <= cur.formatVersion) return false;
125
+ if (cur && cur.formatVersion === next) return false;
126
+ const file = path.join(designRoot, HUB_FORMAT_REL);
127
+ mkdirSync(path.dirname(file), { recursive: true });
128
+ const rec: HubFormatCache = {
129
+ hub: normHub(seen.hub),
130
+ formatVersion: next,
131
+ epoch: seen.epoch ?? cur?.epoch ?? 0,
132
+ seenAt: (opts.now?.() ?? new Date()).toISOString(),
133
+ // Which build wrote it: a newer build seeing a mirror written by an older
134
+ // one has not seen the flip with its own eyes (§5.9 first sight).
135
+ writtenBy: SUPPORTED_FORMAT,
136
+ };
137
+ writeFileSync(`${file}.tmp`, `${JSON.stringify(rec)}\n`);
138
+ renameSync(`${file}.tmp`, file);
139
+ return true;
140
+ }
141
+
142
+ /** The project's format, and which authority set it. */
143
+ export function projectFormat(
144
+ ctx: FormatCtx,
145
+ live: { hubFormat?: number | null } = {}
146
+ ): { value: number; source: 'config' | 'hub' } {
147
+ const fromConfig = asFormat(ctx.cfg.formatVersion);
148
+ const hub = formatHubUrl(ctx);
149
+ if (!hub) return { value: fromConfig, source: 'config' };
150
+ const hubValue =
151
+ typeof live.hubFormat === 'number'
152
+ ? asFormat(live.hubFormat)
153
+ : (readHubFormatCache(ctx.paths.designRoot, hub)?.formatVersion ?? 1);
154
+ return hubValue > fromConfig
155
+ ? { value: hubValue, source: 'hub' }
156
+ : { value: fromConfig, source: 'config' };
157
+ }
158
+
159
+ /** Null when this build may edit the project; else why not. */
160
+ export interface FormatGateOptions {
161
+ supported?: number;
162
+ hubFormat?: number | null;
163
+ /**
164
+ * Gate only projects NEWER than this build (the 1.x direction), and leave
165
+ * older ones editable. The contract's full behaviour (§4.1: v2 opens a
166
+ * format-1 project view only until it is updated) is `false`; `true` is the
167
+ * staged wiring for the branch until the "Update project" dialog and
168
+ * format-2 test sandboxes exist — measured: the full gate turns every
169
+ * existing project and test sandbox view-only (V2-2.14 hand-back).
170
+ */
171
+ newerOnly?: boolean;
172
+ }
173
+
174
+ export function formatGate(ctx: FormatCtx, opts: FormatGateOptions = {}): FormatGate | null {
175
+ const supported = opts.supported ?? SUPPORTED_FORMAT;
176
+ const p = projectFormat(ctx, { hubFormat: opts.hubFormat });
177
+ if (p.value === supported) return null;
178
+ if (opts.newerOnly && p.value < supported) return null;
179
+ return { projectFormat: p.value, supported, source: p.source };
180
+ }
181
+
182
+ /** CONTRACT §4 voice; "Update Maude to edit" is the signed A17 wording (§5.8). */
183
+ export const FORMAT_COPY = {
184
+ /** A newer project in an older build — the 1.x refusal text. */
185
+ newerRefusal: 'This project now uses Maude 2. Update Maude to edit it.',
186
+ newerBanner: "This project now uses Maude 2. It's open here to look at — nothing in it is lost.",
187
+ newerBannerAction: 'Update Maude to edit',
188
+ newerBannerNoBuild:
189
+ "This project now uses Maude 2, which isn't out yet. It stays open here to look at.",
190
+ newerCloudTab: "This project now uses Maude 2. It's open here to look at.",
191
+ newerCanvas: 'This canvas uses Maude 2. Update Maude to see it.',
192
+ /** An older project in v2 — view only until it is updated. */
193
+ olderStatus: 'View only — this project still uses Maude 1.',
194
+ olderStatusAction: 'Update project',
195
+ olderNonOwner: "View only — the owner hasn't updated this project for Maude 2 yet.",
196
+ olderHubTooOld:
197
+ 'View only — the team server needs an update before this project can move to Maude 2.',
198
+ olderOwnerOffline:
199
+ 'View only — updating the project needs the team server, and this Mac is offline.',
200
+ dialogTitle: (projectName: string) => `Update "${projectName}" for Maude 2?`,
201
+ dialogBody:
202
+ "People still on Maude 1 can look at it but can't change it until they update. Nothing in the project is lost.",
203
+ dialogAction: 'Update project',
204
+ toastUpdated: 'Updated for Maude 2. People on Maude 1 can look but not edit.',
205
+ } as const;
206
+
207
+ /** The line a refusal carries, by direction. */
208
+ export function gateMessage(gate: FormatGate): string {
209
+ return gate.projectFormat > gate.supported ? FORMAT_COPY.newerRefusal : FORMAT_COPY.olderStatus;
210
+ }
211
+
212
+ /** §5.6 — the studio's 403 for a write while gated (NOT 426: that is the
213
+ * hub's door; a studio refusal must read like the read-only one, plus why). */
214
+ export function formatRefusalResponse(gate: FormatGate): Response {
215
+ return Response.json(
216
+ {
217
+ error: 'read-only',
218
+ reason: 'read-only',
219
+ detail: 'format',
220
+ formatVersion: gate.projectFormat,
221
+ message: gateMessage(gate),
222
+ },
223
+ { status: 403, headers: { 'Cache-Control': 'no-store' } }
224
+ );
225
+ }
226
+
227
+ /**
228
+ * The format-gate allowlist (§5.6): what a read-only session may write
229
+ * (per-user runtime, export/download, reports, link/sign-in/sign-out) MINUS
230
+ * comments (§9 Q3 — v2 anchors may grow and 1.x re-clamps them: look only),
231
+ * PLUS the one route that leaves the gate: `POST /_api/project/migrate`.
232
+ */
233
+ export const FORMAT_GATE_REFUSED_WRITES: ReadonlySet<string> = new Set(['/_comments']);
234
+ export const FORMAT_GATE_REFUSED_PATTERNS: readonly RegExp[] = [
235
+ /^\/_api\/comments\/[A-Za-z0-9_-]+\/reply$/,
236
+ ];
237
+ export const FORMAT_GATE_EXTRA_WRITES: ReadonlySet<string> = new Set(['/_api/project/migrate']);
238
+
239
+ export function formatGateAllowsWrite(
240
+ pathname: string,
241
+ readOnlyAllowed: { exact: ReadonlySet<string>; patterns: readonly RegExp[] }
242
+ ): boolean {
243
+ if (FORMAT_GATE_EXTRA_WRITES.has(pathname)) return true;
244
+ if (FORMAT_GATE_REFUSED_WRITES.has(pathname)) return false;
245
+ if (FORMAT_GATE_REFUSED_PATTERNS.some((re) => re.test(pathname))) return false;
246
+ return (
247
+ readOnlyAllowed.exact.has(pathname) || readOnlyAllowed.patterns.some((re) => re.test(pathname))
248
+ );
249
+ }
250
+
251
+ /**
252
+ * The gate options the studio runs with today — STAGED (V2-2.14): only a
253
+ * project NEWER than this build is gated. `http.ts` and the sync runtime both
254
+ * pass this constant (test/format-sync.test.ts pins it).
255
+ */
256
+ export const STAGED_FORMAT_GATE_OPTS: FormatGateOptions = { newerOnly: true };
257
+
258
+ /**
259
+ * A canvas build that failed because the canvas imports a `@maude/canvas-lib`
260
+ * export this build does not have — the shape of "this canvas uses a Maude 2
261
+ * feature" (V2-1.12 §5.3: v2 canvas-lib exports; 1.x maps it to a line).
262
+ */
263
+ export function isMissingCanvasLibExport(message: string): boolean {
264
+ return /No matching export in "[^"]*canvas-lib[^"]*" for import/.test(message);
265
+ }
266
+
267
+ /**
268
+ * §5.8 — the line a gated project's canvas build error leads with when the
269
+ * canvas needs a newer canvas-lib; null otherwise (the raw error stands alone).
270
+ */
271
+ export function canvasFormatLine(message: string, gate: FormatGate | null): string | null {
272
+ if (!gate || gate.projectFormat <= gate.supported) return null;
273
+ return isMissingCanvasLibExport(message) ? FORMAT_COPY.newerCanvas : null;
274
+ }
275
+
276
+ /** The `/_config` additions (§5.6). `roleReadOnly` = the existing role gate. */
277
+ export function formatConfigFields(
278
+ ctx: FormatCtx,
279
+ roleReadOnly: boolean,
280
+ opts: FormatGateOptions = {}
281
+ ): {
282
+ formatVersion: number;
283
+ formatGate: FormatGate | null;
284
+ readOnly: boolean;
285
+ readOnlyReason: 'role' | 'format' | null;
286
+ } {
287
+ const gate = formatGate(ctx, opts);
288
+ return {
289
+ formatVersion: projectFormat(ctx, { hubFormat: opts.hubFormat }).value,
290
+ formatGate: gate,
291
+ readOnly: roleReadOnly || gate !== null,
292
+ // The role is the stronger statement (it survives an update), so it names
293
+ // the reason when both hold.
294
+ readOnlyReason: roleReadOnly ? 'role' : gate ? 'format' : null,
295
+ };
296
+ }
@@ -33,7 +33,7 @@ export function cachedProbe(key: string, compute: () => boolean): boolean {
33
33
  export function hasCommandCached(cmd: string): boolean {
34
34
  return cachedProbe(`has:${cmd}`, () => {
35
35
  const finder = process.platform === 'win32' ? 'where' : 'which';
36
- return spawnSync(finder, [cmd], { stdio: 'ignore' }).status === 0;
36
+ return spawnSync(finder, [cmd], { stdio: 'ignore', windowsHide: true }).status === 0;
37
37
  });
38
38
  }
39
39
 
@@ -353,6 +353,7 @@ function runGit(
353
353
  return new Promise((resolveRun) => {
354
354
  const child = spawn('git', args, {
355
355
  cwd: dir,
356
+ windowsHide: true, // #141 — no console window per git call on Windows
356
357
  env: { ...process.env, GIT_TERMINAL_PROMPT: '0', ...env },
357
358
  stdio: ['ignore', 'pipe', 'pipe'],
358
359
  });