@1agh/maude 1.6.5 → 1.6.7

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.
@@ -1003,6 +1003,37 @@ export function cacheControlFor(absPath: string): { cacheControl: string; addEta
1003
1003
  return { cacheControl: 'no-cache', addEtag: true };
1004
1004
  }
1005
1005
 
1006
+ /**
1007
+ * The studio page, with its bundle and stylesheet URLs VERSIONED.
1008
+ *
1009
+ * `/_client/client.bundle.js` used to be a fixed URL answered `no-cache`. Behind
1010
+ * Cloudflare that header does not survive: the zone's default Browser Cache
1011
+ * TTL turns a `.js` into `max-age=14400`, so after a release a cloud user ran
1012
+ * the previous client for up to four hours, against a server that had moved on
1013
+ * (measured on alligators after v1.6.5: new server, old bundle, none of the
1014
+ * release's UI). A query that changes whenever the built file does makes every
1015
+ * cache, ours or anyone's in front of us, fetch it again. `serveFile` ignores
1016
+ * the query, so the old URL keeps working for anything that still asks for it.
1017
+ */
1018
+ export async function serveIndexHtml(): Promise<Response> {
1019
+ const index = Bun.file(join(CLIENT_DIR, 'index.html'));
1020
+ if (!(await index.exists())) return new Response('Not found', { status: 404 });
1021
+ let html = await index.text();
1022
+ for (const name of ['client.bundle.js', 'styles.css']) {
1023
+ const built = Bun.file(join(DIST_DIR, name));
1024
+ if (!(await built.exists())) continue;
1025
+ const v = `${built.size.toString(16)}-${Math.trunc(built.lastModified).toString(16)}`;
1026
+ html = html.replaceAll(`"/_client/${name}"`, `"/_client/${name}?v=${v}"`);
1027
+ }
1028
+ return new Response(html, {
1029
+ headers: {
1030
+ 'Content-Type': 'text/html; charset=utf-8',
1031
+ 'Cache-Control': 'no-cache',
1032
+ 'X-Content-Type-Options': 'nosniff',
1033
+ },
1034
+ });
1035
+ }
1036
+
1006
1037
  /** A weak validator from the file's own metadata — no read, no hash. */
1007
1038
  function etagFor(file: { size: number; lastModified: number }): string {
1008
1039
  return `W/"${file.size.toString(16)}-${Math.trunc(file.lastModified).toString(16)}"`;
@@ -5671,8 +5702,8 @@ export function createHttp(
5671
5702
  return new Response(null, { status: 204 });
5672
5703
  },
5673
5704
 
5674
- '/': () => serveFile(join(CLIENT_DIR, 'index.html')),
5675
- '/index.html': () => serveFile(join(CLIENT_DIR, 'index.html')),
5705
+ '/': () => serveIndexHtml(),
5706
+ '/index.html': () => serveIndexHtml(),
5676
5707
  } satisfies Record<string, (req: Request) => Response | Promise<Response>>;
5677
5708
 
5678
5709
  // Named `handleFallthrough`, not `fetch` — a same-named local function shadows
@@ -5954,7 +5985,18 @@ export function createHttp(
5954
5985
  }
5955
5986
 
5956
5987
  async function serveCanvasShell(applyCsp: boolean, capture = false): Promise<Response> {
5957
- const shellHtml = await Bun.file(join(TEMPLATES_DIR, '_shell.html')).text();
5988
+ // `comment-mount.js` is versioned for the same reason as the studio page's
5989
+ // bundle (see `serveIndexHtml`): a fixed URL outlives a release in any
5990
+ // cache in front of the canvas origin. Replaced BEFORE the CSP hashes are
5991
+ // taken over the inline scripts, so the policy matches what is served.
5992
+ const mount = Bun.file(join(DIST_DIR, 'comment-mount.js'));
5993
+ const mountV = (await mount.exists())
5994
+ ? `?v=${mount.size.toString(16)}-${Math.trunc(mount.lastModified).toString(16)}`
5995
+ : '';
5996
+ const shellHtml = (await Bun.file(join(TEMPLATES_DIR, '_shell.html')).text()).replace(
5997
+ "'/_client/comment-mount.js'",
5998
+ `'/_client/comment-mount.js${mountV}'`
5999
+ );
5958
6000
  // Inject inspector overlay — Cmd+Click selection + add-comment flow.
5959
6001
  const injected = inspect().injectInspector(shellHtml);
5960
6002
  const headers: Record<string, string> = {
@@ -423,6 +423,15 @@ export interface FilePlaneOptions {
423
423
  * half a gate, so both ask.
424
424
  */
425
425
  allowCodeModules: boolean;
426
+ /**
427
+ * Whether this peer may SEND a `code-module` the hub does not hold yet. The
428
+ * hub's file door takes one only from an owner-role token (403 otherwise);
429
+ * asking first keeps that refusal from reading as a dead credential and
430
+ * ending the pass. This is the hub's own word about our role, and that is
431
+ * fine here: it only decides whether to TRY — the door decides the rest.
432
+ * Absent ⇒ `allowCodeModules` (the receive consent), the pre-existing reading.
433
+ */
434
+ canUploadCodeModules?: boolean;
426
435
  /** Names conflict copies. Same exposure class as `syncMeta.by` (hostname). */
427
436
  label: string;
428
437
  /** Increment 6. Off means a local absence is HELD, never propagated. */
@@ -1815,6 +1824,28 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
1815
1824
  }
1816
1825
  }
1817
1826
 
1827
+ // THE UPWARD HALF OF THE SAME GATE. The hub refuses a code module from
1828
+ // anyone but an owner (file-door: 403), and that 403 used to come back
1829
+ // here as "the workspace did not accept this connection" — a credential
1830
+ // failure, which asked for a new token and ENDED THE PASS. One `.ts`
1831
+ // helper written by a member therefore stalled every other upload behind
1832
+ // it (2026-10-02, alligators: five `ui/club-web/_*.ts`, 264 refusals,
1833
+ // passes stopped with 2 500+ paths still to do). Never ask: report it,
1834
+ // keep the file, and let the rest of the pass run.
1835
+ if (remoteHash === null && here && !(opts.canUploadCodeModules ?? opts.allowCodeModules)) {
1836
+ const cls = classifyProjectFile(rel, {
1837
+ canvasGroups: opts.canvasGroups,
1838
+ hasFile: (r) => local.has(r) || existsSync(path.join(designRoot, r)),
1839
+ });
1840
+ if (cls === 'code-module') {
1841
+ out.dropped.push({
1842
+ rel,
1843
+ reason: 'only the project owner can upload code modules (.ts/.js) to this workspace',
1844
+ });
1845
+ continue;
1846
+ }
1847
+ }
1848
+
1818
1849
  const state: FileState = {
1819
1850
  path: rel,
1820
1851
  local: here?.hash ?? null,
@@ -78,6 +78,7 @@ import { isLoopbackHost } from './loopback.ts';
78
78
  import { migrateFlatFallback } from './migrate-flat-fallback.ts';
79
79
  import { migrateSeed } from './migrate-seed.ts';
80
80
  import { ORIGINS } from './origins.ts';
81
+ import { createProjectConfigPusher } from './project-config-push.ts';
81
82
  import { createDocProjection, type DocProjection } from './projection.ts';
82
83
  import {
83
84
  acceptedListing,
@@ -916,6 +917,22 @@ export function createSyncRuntime(
916
917
  // Same shape of consent for the OUTBOUND delete breaker: only what this
917
918
  // machine's owner recorded (`maude design bulk-deletes on`), never the hub.
918
919
  const unlimitedDeletes = storedRecord?.unlimitedDeletes === true;
920
+ // The OWNER's copy tells its workspace the project's name and design systems
921
+ // (project-config-push.ts) — a cell synced from a desktop has no config.json
922
+ // of its own. Only when the hub says we own the project (it enforces that
923
+ // itself — this only decides whether to try); never from inside a cell.
924
+ const isProjectOwner = storedRecord?.role === 'owner';
925
+ const projectConfigPusher =
926
+ !cellPairing && isProjectOwner
927
+ ? createProjectConfigPusher({
928
+ designRoot: ctx.paths.designRoot,
929
+ hubUrl: linkedHub.url,
930
+ token: () => token,
931
+ })
932
+ : null;
933
+ const projectConfigUnsub = projectConfigPusher
934
+ ? ctx.bus.on('config-updated', () => void projectConfigPusher.push())
935
+ : null;
919
936
 
920
937
  // DDR-102 — the default factory multiplexes every provider over ONE shared
921
938
  // WebSocket per hub URL; the runtime owns its disposal (stop(), after the
@@ -983,6 +1000,7 @@ export function createSyncRuntime(
983
1000
  onStage: (summary) => statusStore?.updateAiAction?.(summary),
984
1001
  onBootstrap: (b) => {
985
1002
  noteProjectConfig(b.projectConfig);
1003
+ void projectConfigPusher?.push();
986
1004
  // F3 S17 — a save made as the socket died is held (the connection
987
1005
  // was not writable). After the reconnect the handshake re-admits the
988
1006
  // socket read-only BEFORE this peer learns the project now takes
@@ -4741,6 +4759,7 @@ export function createSyncRuntime(
4741
4759
  ledger: fileLedger,
4742
4760
  canvasGroups: ctx.cfg.canvasGroups,
4743
4761
  allowCodeModules,
4762
+ canUploadCodeModules: cellPairing !== null || isProjectOwner,
4744
4763
  unlimitedOutboundDeletes: unlimitedDeletes,
4745
4764
  // Increment 6, DEFAULT ON: a hub-owned mirror that ignores
4746
4765
  // deletes contradicts the model it is selling — you delete a
@@ -4859,6 +4878,7 @@ export function createSyncRuntime(
4859
4878
  remotePollSoonTimer = null;
4860
4879
  documentDiscoveryUnsub?.();
4861
4880
  documentDiscoveryUnsub = null;
4881
+ projectConfigUnsub?.();
4862
4882
  documentDiscovery?.stop();
4863
4883
  documentDiscovery = null;
4864
4884
  remotePull = null;
@@ -0,0 +1,155 @@
1
+ // The owner's desktop tells its cloud workspace what the project is called and
2
+ // where its design systems live (`PUT /api/project-config`, hub
3
+ // project-config-door.mjs).
4
+ //
5
+ // A cell reads `config.json` from its checkout, and a project that reached its
6
+ // cell by syncing from a desktop has none there — the file plane never carries
7
+ // `config.json` (file-membership: `never`). The cell then ran on defaults: no
8
+ // design systems and a tokens path that did not exist, so canvases relying on
9
+ // the shell's tokens stylesheet lost their brand fonts (2026-10-02, alligators).
10
+ //
11
+ // OWNER ONLY, and decided from LOCAL state (the stored hub record), never from
12
+ // anything the hub said — the same rule as code modules. Only a sanitized
13
+ // subset leaves this machine: names and contained relative paths. `linkedHub`,
14
+ // tokens and everything else in config.json stay here.
15
+
16
+ import { readFileSync } from 'node:fs';
17
+ import path from 'node:path';
18
+
19
+ const isContainedRel = (p: unknown): p is string =>
20
+ typeof p === 'string' &&
21
+ p.length > 0 &&
22
+ p.length <= 256 &&
23
+ !p.startsWith('/') &&
24
+ !/(^|\/)\.\.(\/|$)/.test(p) &&
25
+ !/[\\\0]/.test(p);
26
+
27
+ const isLabel = (s: unknown, max = 64): s is string =>
28
+ typeof s === 'string' && s.trim().length > 0 && s.length <= max && !/[\0\r\n]/.test(s);
29
+
30
+ export interface ProjectConfigSubset {
31
+ name?: string;
32
+ projectLabel?: string;
33
+ tokensCssRel?: string;
34
+ componentsCssRel?: string | null;
35
+ canvasGroups?: { label: string; path: string }[];
36
+ designSystems?: { name: string; path: string; tokensCssRel?: string }[];
37
+ defaultDesignSystem?: string;
38
+ }
39
+
40
+ /** The part of a config that may travel to the hub — mirrors the hub's own filter. */
41
+ export function projectConfigSubset(raw: unknown): ProjectConfigSubset | null {
42
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
43
+ const r = raw as Record<string, unknown>;
44
+ const out: ProjectConfigSubset = {};
45
+ if (isLabel(r.name)) out.name = r.name;
46
+ if (isLabel(r.projectLabel, 120)) out.projectLabel = r.projectLabel;
47
+ if (isContainedRel(r.tokensCssRel)) out.tokensCssRel = r.tokensCssRel;
48
+ if (r.componentsCssRel === null || isContainedRel(r.componentsCssRel)) {
49
+ out.componentsCssRel = r.componentsCssRel as string | null;
50
+ }
51
+ if (Array.isArray(r.canvasGroups)) {
52
+ const groups = r.canvasGroups
53
+ .filter(
54
+ (g): g is { label: string; path: string } =>
55
+ !!g && typeof g === 'object' && isLabel(g.label) && isContainedRel(g.path)
56
+ )
57
+ .slice(0, 32)
58
+ .map((g) => ({ label: g.label, path: g.path.replace(/\/+$/, '') }));
59
+ if (groups.length) out.canvasGroups = groups;
60
+ }
61
+ if (Array.isArray(r.designSystems)) {
62
+ out.designSystems = r.designSystems
63
+ .filter(
64
+ (d): d is { name: string; path: string; tokensCssRel?: string } =>
65
+ !!d &&
66
+ typeof d === 'object' &&
67
+ typeof d.name === 'string' &&
68
+ /^[\w .-]{1,64}$/.test(d.name) &&
69
+ isContainedRel(d.path) &&
70
+ (d.tokensCssRel == null || isContainedRel(d.tokensCssRel))
71
+ )
72
+ .slice(0, 16)
73
+ .map((d) => ({
74
+ name: d.name,
75
+ path: d.path.replace(/\/+$/, ''),
76
+ ...(typeof d.tokensCssRel === 'string' ? { tokensCssRel: d.tokensCssRel } : {}),
77
+ }));
78
+ }
79
+ if (
80
+ typeof r.defaultDesignSystem === 'string' &&
81
+ (out.designSystems ?? []).some((d) => d.name === r.defaultDesignSystem)
82
+ ) {
83
+ out.defaultDesignSystem = r.defaultDesignSystem;
84
+ }
85
+ return Object.keys(out).length ? out : null;
86
+ }
87
+
88
+ export interface ProjectConfigPusher {
89
+ /** Send the current subset if it changed since the last accepted send. */
90
+ push(): Promise<'sent' | 'unchanged' | 'refused' | 'failed' | 'nothing'>;
91
+ }
92
+
93
+ export function createProjectConfigPusher({
94
+ designRoot,
95
+ hubUrl,
96
+ token,
97
+ fetchImpl = fetch,
98
+ log = console,
99
+ }: {
100
+ designRoot: string;
101
+ hubUrl: string;
102
+ token: () => string;
103
+ fetchImpl?: typeof fetch;
104
+ log?: Pick<Console, 'log' | 'warn'>;
105
+ }): ProjectConfigPusher {
106
+ let lastAccepted: string | null = null;
107
+ let inflight: Promise<'sent' | 'unchanged' | 'refused' | 'failed' | 'nothing'> | null = null;
108
+ const run = async () => {
109
+ let subset: ProjectConfigSubset | null = null;
110
+ try {
111
+ subset = projectConfigSubset(
112
+ JSON.parse(readFileSync(path.join(designRoot, 'config.json'), 'utf8'))
113
+ );
114
+ } catch {
115
+ subset = null;
116
+ }
117
+ if (!subset) return 'nothing' as const;
118
+ const body = JSON.stringify(subset);
119
+ if (body === lastAccepted) return 'unchanged' as const;
120
+ let res: Response;
121
+ try {
122
+ res = await fetchImpl(new URL('/api/project-config', hubUrl), {
123
+ method: 'PUT',
124
+ headers: { authorization: `Bearer ${token()}`, 'content-type': 'application/json' },
125
+ body,
126
+ signal: AbortSignal.timeout(15_000),
127
+ });
128
+ } catch {
129
+ return 'failed' as const;
130
+ }
131
+ // An older hub has no such door — nothing to do, and nothing to retry.
132
+ if (res.status === 404 || res.status === 405) {
133
+ lastAccepted = body;
134
+ return 'refused' as const;
135
+ }
136
+ if (res.status === 401 || res.status === 403) {
137
+ lastAccepted = body;
138
+ log.warn(`[sync] the workspace did not take this project's config (${res.status}).`);
139
+ return 'refused' as const;
140
+ }
141
+ if (!res.ok) return 'failed' as const;
142
+ lastAccepted = body;
143
+ const answer = (await res.json().catch(() => null)) as { changed?: boolean } | null;
144
+ if (answer?.changed) {
145
+ log.log("[sync] sent the project's name and design systems to the workspace.");
146
+ }
147
+ return 'sent' as const;
148
+ };
149
+ return {
150
+ push() {
151
+ if (!inflight) inflight = run().finally(() => (inflight = null));
152
+ return inflight;
153
+ },
154
+ };
155
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agh/maude",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "description": "Marketplace of Claude Code plugins by Michal Dovrtěl: `design` (canvas-first design iteration) + `flow` (generic agentic workflow loop with .ai second brain). Ships the `maude` CLI (with `mdcc` legacy alias) to scaffold workspace, run the design dev server, and manage configs.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -58,13 +58,13 @@
58
58
  "test:e2e:desktop:parity:cloud": "pnpm --filter @maude/desktop-e2e e2e:parity:cloud"
59
59
  },
60
60
  "optionalDependencies": {
61
- "@1agh/maude-darwin-arm64": "1.6.5",
62
- "@1agh/maude-darwin-x64": "1.6.5",
63
- "@1agh/maude-linux-arm64": "1.6.5",
64
- "@1agh/maude-linux-arm64-musl": "1.6.5",
65
- "@1agh/maude-linux-x64": "1.6.5",
66
- "@1agh/maude-linux-x64-musl": "1.6.5",
67
- "@1agh/maude-win32-x64": "1.6.5"
61
+ "@1agh/maude-darwin-arm64": "1.6.7",
62
+ "@1agh/maude-darwin-x64": "1.6.7",
63
+ "@1agh/maude-linux-arm64": "1.6.7",
64
+ "@1agh/maude-linux-arm64-musl": "1.6.7",
65
+ "@1agh/maude-linux-x64": "1.6.7",
66
+ "@1agh/maude-linux-x64-musl": "1.6.7",
67
+ "@1agh/maude-win32-x64": "1.6.7"
68
68
  },
69
69
  "files": [
70
70
  "cli",