@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
@@ -390,6 +390,14 @@ export interface FilePlaneResult {
390
390
  requestsExhausted?: true;
391
391
  /** The door refused our credential; a renewal was requested and the pass ended. */
392
392
  authRefused?: true;
393
+ /**
394
+ * V2-1.12 §5.4 — the door refused our FILE FORMAT (426): the project now
395
+ * uses a newer format than this build writes. Not a credential failure (no
396
+ * renewal) and not this file's fault (no backoff); the pass ended.
397
+ */
398
+ formatRefused?: { formatVersion: number | null };
399
+ /** Outbound changes held this pass because the project is format-gated. */
400
+ heldForFormat?: number;
393
401
  /**
394
402
  * Paths skipped this pass because they are inside their per-path backoff
395
403
  * window. NOT a failure and NOT converged — work that is deliberately
@@ -471,6 +479,17 @@ export interface FilePlaneOptions {
471
479
  * renewals/s storm.
472
480
  */
473
481
  onAuthFailure?: (rel: string, status: number) => void;
482
+ /**
483
+ * V2-1.12 §5.4 — a write door answered 426 (format). Called once per pass
484
+ * with the project format the hub named, so the runtime can mirror it and
485
+ * engage the gate. Never a credential renewal.
486
+ */
487
+ onFormatRefused?: (formatVersion: number | null) => void;
488
+ /**
489
+ * V2-1.12 §5.6 — while true nothing goes UP (no push, revive or delete);
490
+ * pulls continue. The runtime passes "this build does not edit the project".
491
+ */
492
+ outboundPaused?: () => boolean;
474
493
  /**
475
494
  * A pass delivered at least one file.
476
495
  *
@@ -710,6 +729,8 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
710
729
  let unreachableInARow = 0;
711
730
  /** The door refused our credential this pass. */
712
731
  let authRefused = false;
732
+ /** Set when a write door answered 426 (format) this pass. */
733
+ let formatRefused: { formatVersion: number | null } | null = null;
713
734
  /** Bytes this pass has successfully pushed, charged against the window. */
714
735
  let quotaSpentThisPass = 0;
715
736
  /** The door's own ceilings, learned once per boot. Null until asked. */
@@ -874,6 +895,24 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
874
895
  authRefused = true;
875
896
  return { ok: false, reason: 'The workspace did not accept this connection' };
876
897
  }
898
+ // V2-1.12 §5.4 — 426 is the hub's FORMAT door: this project now uses a
899
+ // newer format than this build writes. Deliberately NOT the branch above —
900
+ // the credential is fine, and renewing it would change nothing.
901
+ if (res.status === 426) {
902
+ // The CONTRACT's words (§5.8), never the hub's text — the hub is
903
+ // untrusted to peers (DDR-054), and this line reaches the Sync panel.
904
+ let fv: number | null = null;
905
+ try {
906
+ const text = await res.clone().text();
907
+ const body = text.length <= 4096 ? (JSON.parse(text) as { formatVersion?: unknown }) : null;
908
+ const v = body?.formatVersion;
909
+ if (typeof v === 'number' && Number.isSafeInteger(v) && v >= 1) fv = v;
910
+ } catch {
911
+ /* a bare 426 still means "format" */
912
+ }
913
+ formatRefused = { formatVersion: fv };
914
+ return { ok: false, reason: 'This project now uses Maude 2. Update Maude to edit it.' };
915
+ }
877
916
  const reason = await failureReason(res);
878
917
  // BACKPRESSURE, not just 429 — a cell that is starting answers 503 with a
879
918
  // Retry-After, and firing this pass's remaining request budget into that
@@ -1542,6 +1581,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
1542
1581
  hitRateLimit = null;
1543
1582
  unreachableInARow = 0;
1544
1583
  authRefused = false;
1584
+ formatRefused = null;
1545
1585
  quotaSpentThisPass = 0;
1546
1586
  await ensureHubLimits();
1547
1587
  requestsThisPass = 0;
@@ -2053,7 +2093,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
2053
2093
  // it. A rate limit is excluded: that is the DOOR's state, not this
2054
2094
  // path's, and punishing the file for it would push a whole project into
2055
2095
  // backoff for something none of its files did.
2056
- if (hitRateLimit === null) {
2096
+ if (hitRateLimit === null && formatRefused === null) {
2057
2097
  if (out.failed.length > before.failed) {
2058
2098
  const delay = ledger.noteAttemptFailed(item.rel, now());
2059
2099
  log.warn?.(
@@ -2070,6 +2110,18 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
2070
2110
  // A RATE LIMIT ENDS THE PASS. Every other refusal is about one file and
2071
2111
  // the next one is worth trying; this one is about the door, and the
2072
2112
  // remaining requests would do nothing but hold it shut for longer.
2113
+ // (A cast: TS cannot see the assignment inside `refusal()`.)
2114
+ const refusedFormat = formatRefused as { formatVersion: number | null } | null;
2115
+ if (refusedFormat !== null) {
2116
+ // ONE notification, and the pass ends: every other write would meet
2117
+ // the same door. No backoff is armed (the file did nothing wrong).
2118
+ opts.onFormatRefused?.(refusedFormat.formatVersion);
2119
+ out.formatRefused = refusedFormat;
2120
+ log.warn?.(
2121
+ `[sync/files] the project now uses a newer file format than this build writes; nothing more goes up until Maude is updated (${work.length - seen} path(s) still to do).`
2122
+ );
2123
+ break;
2124
+ }
2073
2125
  if (authRefused) {
2074
2126
  // ONE notification for the whole pass. `renewCredentialNow()` is
2075
2127
  // single-flight with a 60 s floor, so 803 refused paths collapse to one
@@ -2241,6 +2293,10 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
2241
2293
  case 'push':
2242
2294
  case 'revive': {
2243
2295
  if (!here) return false;
2296
+ if (opts.outboundPaused?.()) {
2297
+ out.heldForFormat = (out.heldForFormat ?? 0) + 1;
2298
+ return false;
2299
+ }
2244
2300
  ledger.setState(rel, 'pushing');
2245
2301
  const expect = decision.action === 'revive' ? null : remoteHash;
2246
2302
  const res = await push(here, expect);
@@ -2386,6 +2442,10 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
2386
2442
  }
2387
2443
 
2388
2444
  case 'propagate-delete': {
2445
+ if (opts.outboundPaused?.()) {
2446
+ out.heldForFormat = (out.heldForFormat ?? 0) + 1;
2447
+ return false;
2448
+ }
2389
2449
  // Gone here, and the hub still holds exactly what we last reconciled —
2390
2450
  // the Syncthing rule. The CAS carries our ancestor, so an edit that
2391
2451
  // landed in between wins and this comes back as a conflict instead.
@@ -0,0 +1,160 @@
1
+ // The sync runtime's side of the project file format — V2-1.12 §5.4, §5.6,
2
+ // §5.7 P1 (V2-2.18).
3
+ //
4
+ // • DECLARE: every studio → hub request carries `X-Maude-Format: <n>` and
5
+ // every socket `maude-format=<n>`, so the hub can fence a writer of another
6
+ // format (426 on its doors, a read-only connection on the doc lanes).
7
+ // • LEARN: the hub's format arrives on `/health` and on the `maude.mode`
8
+ // notice; it is mirrored raise-only into `_state/hub-format.json`
9
+ // (`format.ts` noteHubFormat), and a change makes shells refetch
10
+ // `/_config` so the gate and the banner engage.
11
+ // • PAUSE: while this build does not edit the project, nothing goes up —
12
+ // no fs → doc imports, no file-plane pushes, no proposals. Pulls continue.
13
+ // • 426 IS NOT A CREDENTIAL FAILURE: a format refusal never renews a token.
14
+ //
15
+ // Pure helpers + the decisions; `sync/index.ts` wires them.
16
+
17
+ import {
18
+ asFormat,
19
+ type FormatCtx,
20
+ type FormatGateOptions,
21
+ formatGate,
22
+ formatHubUrl,
23
+ noteHubFormat,
24
+ projectFormat,
25
+ readHubFormatCache,
26
+ STAGED_FORMAT_GATE_OPTS,
27
+ SUPPORTED_FORMAT,
28
+ } from '../format.ts';
29
+
30
+ /**
31
+ * The gate the studio enforces — the SAME options `http.ts` passes
32
+ * (`STAGED_FORMAT_GATE_OPTS`: only a project newer than this build is
33
+ * gated). Pinned against http.ts by test/format-sync.test.ts so the sync
34
+ * runtime and the HTTP gate can never disagree about whether a project is
35
+ * editable here.
36
+ */
37
+ export const SYNC_FORMAT_GATE_OPTS: FormatGateOptions = STAGED_FORMAT_GATE_OPTS;
38
+
39
+ /** Does this build NOT edit the project right now? (Outbound is paused.) */
40
+ export function formatGated(ctx: FormatCtx): boolean {
41
+ if (formatGate(ctx, SYNC_FORMAT_GATE_OPTS) !== null) return true;
42
+ // The owner moved the project back (an unflip) and this copy's config.json
43
+ // still says the newer format: every write would be refused by the hub, so
44
+ // none is made until the two agree (the copy's own `--reverse`, or git).
45
+ const hub = formatHubUrl(ctx);
46
+ const mirror = hub ? readHubFormatCache(ctx.paths.designRoot, hub) : null;
47
+ return mirror !== null && mirror.formatVersion < asFormat(ctx.cfg.formatVersion);
48
+ }
49
+
50
+ /**
51
+ * The format this studio WRITES in, for the hub's fence. While the project is
52
+ * editable here that is the project's format (under the staged gate a v2 build
53
+ * still writes a format-1 project as a format-1 writer); while it is gated it
54
+ * is this build's own format, so a mismatch is exactly what the hub sees.
55
+ */
56
+ export function declaredFormat(ctx: FormatCtx): number {
57
+ return formatGated(ctx) ? SUPPORTED_FORMAT : projectFormat(ctx).value;
58
+ }
59
+
60
+ /** `ws(s)://host[/path]` + `maude-format=<n>` (keeps any existing query). */
61
+ export function withFormatParam(wsUrl: string, format: number | undefined): string {
62
+ if (format === undefined) return wsUrl;
63
+ try {
64
+ const u = new URL(wsUrl);
65
+ u.searchParams.set('maude-format', String(asFormat(format)));
66
+ return u.toString();
67
+ } catch {
68
+ return wsUrl;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * A fetch that declares the format on every request. The base fetch is
74
+ * resolved at CALL time (`globalThis.fetch` when none is given), so a test
75
+ * that swaps the global still sees every request.
76
+ */
77
+ export function withFormatHeader(
78
+ base: typeof fetch | undefined,
79
+ format: () => number
80
+ ): typeof fetch {
81
+ const wrapped = (input: RequestInfo | URL, init?: RequestInit) => {
82
+ const fn = base ?? globalThis.fetch;
83
+ const from =
84
+ init?.headers ??
85
+ (typeof Request !== 'undefined' && input instanceof Request ? input.headers : undefined);
86
+ const headers = new Headers(from);
87
+ // A request that already names its format keeps it: a queued proposal
88
+ // declares the format it was WRITTEN in, not whatever this build is now.
89
+ if (!headers.has('x-maude-format')) headers.set('x-maude-format', String(asFormat(format())));
90
+ return fn(input, { ...init, headers });
91
+ };
92
+ return wrapped as typeof fetch;
93
+ }
94
+
95
+ /** A hub's answer is a FORMAT refusal (V2-1.12 §5.4) — not a credential one. */
96
+ export function isFormatRefusal(status: number, body?: unknown): boolean {
97
+ if (status !== 426) return false;
98
+ if (!body || typeof body !== 'object') return true;
99
+ const b = body as { reason?: unknown; code?: unknown };
100
+ return (
101
+ b.reason === 'format' || b.code === 'format' || (b.reason === undefined && b.code === undefined)
102
+ );
103
+ }
104
+
105
+ /** The project format a `/health` body or a `maude.mode` notice states, or null. */
106
+ export function formatFromHub(body: unknown): number | null {
107
+ const v = (body as { formatVersion?: unknown } | null)?.formatVersion;
108
+ return typeof v === 'number' && Number.isSafeInteger(v) && v >= 1 ? v : null;
109
+ }
110
+
111
+ /**
112
+ * Record what the hub said. Returns true when the mirrored value changed, so
113
+ * the caller emits `config-updated` (shells refetch `/_config`, the gate and
114
+ * banner engage within the reload — §5.14 "≤ 1 s after the notice").
115
+ */
116
+ export function learnHubFormat(
117
+ ctx: FormatCtx,
118
+ seen: { formatVersion: number | null; epoch?: number }
119
+ ): boolean {
120
+ const hub = formatHubUrl(ctx);
121
+ if (!hub || seen.formatVersion === null) return false;
122
+ // An epoch is a non-negative safe integer or it is not one: a hostile hub
123
+ // sending 1e308 must not freeze this mirror against every later unflip.
124
+ const epoch =
125
+ typeof seen.epoch === 'number' && Number.isSafeInteger(seen.epoch) && seen.epoch >= 0
126
+ ? seen.epoch
127
+ : undefined;
128
+ // RAISE-ONLY, with one exception: the owner's unflip (`--reverse`) reaches
129
+ // peers as a `maude.mode` notice carrying a NEWER epoch than the one this
130
+ // mirror recorded — a later decision by the authority, not a stale hub.
131
+ // `/health` carries no public epoch, so it can only ever raise.
132
+ const cached = readHubFormatCache(ctx.paths.designRoot, hub);
133
+ const newerDecision = epoch !== undefined && cached !== null && epoch > cached.epoch;
134
+ return noteHubFormat(
135
+ ctx.paths.designRoot,
136
+ {
137
+ hub,
138
+ formatVersion: seen.formatVersion,
139
+ ...(epoch !== undefined ? { epoch } : {}),
140
+ },
141
+ { allowLower: newerDecision }
142
+ );
143
+ }
144
+
145
+ /**
146
+ * §5.9 FIRST SIGHT of a flip: this Mac's mirror is absent or older than what
147
+ * the hub now says. Evaluated BEFORE `learnHubFormat` writes the mirror. A
148
+ * format-1 hub is never a flip (nothing to have missed).
149
+ */
150
+ export function isFormatFirstSight(ctx: FormatCtx, hubFormat: number | null): boolean {
151
+ const hub = formatHubUrl(ctx);
152
+ if (!hub || hubFormat === null || hubFormat <= 1) return false;
153
+ const cached = readHubFormatCache(ctx.paths.designRoot, hub);
154
+ return (
155
+ cached === null ||
156
+ cached.formatVersion < hubFormat ||
157
+ // A mirror an OLDER build wrote: this build has not seen the flip itself.
158
+ (cached.writtenBy ?? 1) < SUPPORTED_FORMAT
159
+ );
160
+ }