@1agh/maude 2.0.0-rc.1 → 2.0.0-rc.2

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 (36) hide show
  1. package/apps/studio/acp/index.ts +35 -2
  2. package/apps/studio/agent-runs.ts +3 -0
  3. package/apps/studio/ai/lease-home.ts +11 -1
  4. package/apps/studio/ai/run-lifecycle.ts +17 -0
  5. package/apps/studio/ai/runs.ts +64 -12
  6. package/apps/studio/api.ts +31 -5
  7. package/apps/studio/canvas-imports.ts +23 -4
  8. package/apps/studio/client/app.jsx +4 -0
  9. package/apps/studio/client/fonts/LICENSE-Inter-Tight.txt +93 -0
  10. package/apps/studio/client/fonts/LICENSE-Inter.txt +93 -0
  11. package/apps/studio/client/fonts/LICENSE-JetBrains-Mono.txt +93 -0
  12. package/apps/studio/client/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  13. package/apps/studio/client/fonts/inter-latin-wght-normal.woff2 +0 -0
  14. package/apps/studio/client/fonts/inter-tight-latin-ext-wght-normal.woff2 +0 -0
  15. package/apps/studio/client/fonts/inter-tight-latin-wght-normal.woff2 +0 -0
  16. package/apps/studio/client/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  17. package/apps/studio/client/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  18. package/apps/studio/client/index.html +0 -3
  19. package/apps/studio/client/styles/_index.css +2 -0
  20. package/apps/studio/client/styles/fonts.css +63 -0
  21. package/apps/studio/client/v2/ai/needs-you.js +10 -0
  22. package/apps/studio/dist/client.bundle.js +89 -89
  23. package/apps/studio/dist/styles.css +1 -1
  24. package/apps/studio/sync/ctl-provider.ts +4 -1
  25. package/apps/studio/sync/file-ledger.ts +12 -0
  26. package/apps/studio/sync/file-membership.ts +28 -0
  27. package/apps/studio/sync/file-plane.ts +119 -5
  28. package/apps/studio/sync/index.ts +55 -1
  29. package/apps/studio/sync/journal-client.ts +12 -0
  30. package/apps/studio/sync/poke.ts +30 -0
  31. package/apps/studio/sync/presentation.ts +6 -1
  32. package/apps/studio/sync/projection.ts +7 -0
  33. package/apps/studio/sync/retry-after.ts +27 -0
  34. package/apps/studio/sync/status.ts +9 -1
  35. package/apps/studio/whats-new.json +45 -0
  36. package/package.json +8 -8
@@ -24,6 +24,7 @@ import {
24
24
  type ElementRef,
25
25
  isLive,
26
26
  type RunRecord,
27
+ type RunRefusal,
27
28
  type RunScope,
28
29
  } from '../ai/run-lifecycle.ts';
29
30
  import type { RunRegistry } from '../ai/runs.ts';
@@ -193,6 +194,19 @@ export function audienceIsCanvas(
193
194
  }
194
195
  }
195
196
 
197
+ /** rc2-e — a run the lease home refused, in plain words (what happened · what to do). */
198
+ export function refusedWords(r: RunRefusal): string {
199
+ if (r.code === 'capacity' && r.why === 'artboards')
200
+ return 'This canvas has too many artboards for one AI run. Select the artboards you mean and ask again.';
201
+ if (r.code === 'capacity' && r.why === 'runs')
202
+ return 'Too many AI runs are open in this project. Stop one, then ask again.';
203
+ if (r.code === 'capacity' && r.why === 'waiting')
204
+ return 'Too many of these artboards are busy with other AI runs. Select fewer, then ask again.';
205
+ if (r.code === 'forbidden')
206
+ return 'AI can’t change this canvas with your access. Ask an owner for edit access.';
207
+ return 'AI could not start on this. Ask again.';
208
+ }
209
+
196
210
  /** The refusal a read-only session's state-changing frame gets (CONTRACT §4 voice). */
197
211
  export const READ_ONLY_CHAT_WORDS =
198
212
  'This project is view only for you, so AI can’t change it. Ask the owner for edit access.';
@@ -678,6 +692,8 @@ interface BridgeEntry {
678
692
  runId: string | null;
679
693
  /** S5.6 — the last `{t:'run'}` frame sent per run, so only a change is sent again. */
680
694
  sentRuns: Map<string, string>;
695
+ /** rc2-e — runs whose refused `begin` this chat was already told about (once, never again) */
696
+ toldRefused: Set<string>;
681
697
  }
682
698
 
683
699
  export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOptions = {}): Acp {
@@ -815,6 +831,7 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
815
831
  reapTimer: null,
816
832
  runId: null,
817
833
  sentRuns: new Map(),
834
+ toldRefused: new Set(),
818
835
  };
819
836
  entry.bridge = new AcpBridge({
820
837
  // V2-1.15 §5.4 — the adapter carries MAUDE_CHAT_ID=<this chat> (the hook's run binding).
@@ -1100,6 +1117,11 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
1100
1117
  if (runId && runs && cur && isLive(cur)) {
1101
1118
  void runs.turnEnded(runId, turnOutcome).catch(() => null);
1102
1119
  }
1120
+ // rc2-e — a run this turn's own hooks opened (its run had ended mid-turn) ends with the turn, even
1121
+ // when no Stop hook says so: left live it would hold the chat's line for every next prompt.
1122
+ for (const r of runs?.live() ?? [])
1123
+ if (r.chatId === entry.chatId && r.hookOpened && r.runId !== runId)
1124
+ void runs?.turnEnded(r.runId, turnOutcome).catch(() => null);
1103
1125
  }
1104
1126
  }
1105
1127
 
@@ -1109,7 +1131,17 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
1109
1131
  for (const run of runs.view().mine) {
1110
1132
  if (run.chatId !== entry.chatId) continue;
1111
1133
  const prior = entry.sentRuns.get(run.runId);
1112
- if (prior === undefined && run.state === 'ended') continue;
1134
+ // rc2-e — the home refused this run before any turn: say why, once. The coded error ends the
1135
+ // prompt's working state (client `prompt()` throws on it; with no prompt in flight it is a card).
1136
+ if (run.state === 'ended' && run.refused && !entry.toldRefused.has(run.runId)) {
1137
+ entry.toldRefused.add(run.runId);
1138
+ broadcast(entry, {
1139
+ t: 'error',
1140
+ code: 'run-refused',
1141
+ chat: entry.chatId,
1142
+ message: refusedWords(run.refused),
1143
+ });
1144
+ } else if (prior === undefined && run.state === 'ended') continue;
1113
1145
  const json = JSON.stringify(run);
1114
1146
  if (json === prior) continue;
1115
1147
  entry.sentRuns.set(run.runId, json);
@@ -1258,7 +1290,8 @@ export function createAcp(ctx: Context, aiActivity?: AiActivity, options: AcpOpt
1258
1290
  /** The registry's `turns.cancel` — see `Acp.cancelTurn`. */
1259
1291
  async function cancelTurn(rec: RunRecord): Promise<void> {
1260
1292
  const entry = rec.chatId ? bridges.get(sanitizeChatId(rec.chatId)) : undefined;
1261
- if (!entry || entry.runId !== rec.runId) return;
1293
+ // rc2-e — Stop on a run the chat's agent hook opened stops the turn that is writing for it
1294
+ if (!entry || (entry.runId !== rec.runId && !(rec.hookOpened && entry.turnActive))) return;
1262
1295
  entry.tracker?.endTurn();
1263
1296
  await entry.bridge.cancel();
1264
1297
  }
@@ -233,6 +233,9 @@ export function createAgentRuns(
233
233
  label: b.label,
234
234
  scope: toScope(b.scope),
235
235
  agent: 'Claude Code',
236
+ // rc2-e — a Maude chat's hook with no live run of that chat: the agent's turn is running already.
237
+ // Never a run that wants a turn sent (it failed at once, and every next hook call opened another).
238
+ hookOpened: b.actor === 'maude-chat',
236
239
  });
237
240
  if (b.promptId) promptIds.set(rec.runId, [b.promptId]);
238
241
  remember(b.session, b.chat, rec.runId);
@@ -14,7 +14,11 @@
14
14
 
15
15
  import { Database } from 'bun:sqlite';
16
16
  // The hub's own runs half of store-core (plain JS, zero imports) — one implementation of L1–L10.
17
- import { createRunsCore, RUNS_DDL } from '../../hub/src/project-transactions/runs-core.mjs';
17
+ import {
18
+ createRunsCore,
19
+ MAX_KEYS_PER_RUN,
20
+ RUNS_DDL,
21
+ } from '../../hub/src/project-transactions/runs-core.mjs';
18
22
  import type { LeaseKey, RunOrigin, RunOutcome, RunPublic } from './run-lifecycle.ts';
19
23
 
20
24
  export type Granted = LeaseKey & { token: number };
@@ -55,6 +59,12 @@ export interface LeaseHome {
55
59
  close?(): void;
56
60
  }
57
61
 
62
+ /**
63
+ * The most lease keys one run may hold or line up for — the home's cap (runs-core, every hub since
64
+ * runs-v1). A whole-canvas ask past it begins lazily (runs.ts `wantsOf`).
65
+ */
66
+ export const MAX_LEASE_KEYS_PER_RUN: number = MAX_KEYS_PER_RUN;
67
+
58
68
  /** `<canvas>|<artboard>` — the `expectFence` key (runs-core `leaseKeyId`). */
59
69
  export const leaseKeyId = (k: LeaseKey) => `${k.canvas}|${k.artboard}`;
60
70
 
@@ -92,6 +92,23 @@ export interface RunRecord {
92
92
  busyDenied?: LeaseKey[];
93
93
  /** studio-local (S7.15): the footage the ask attached (`assets/<sha8>.<ext>` + the name it was given) */
94
94
  attached?: Array<{ asset: string; name: string; durationSec?: number }>;
95
+ /**
96
+ * studio-local (rc2-e): the lease home refused this run's `begin` — it ended `failed` before any turn.
97
+ * `why` is classified here from the home's reason (never the home's own words: a hub is not trusted
98
+ * to write the chat's copy). The chat is told in plain words (acp/index.ts `refusedWords`).
99
+ */
100
+ refused?: RunRefusal;
101
+ /**
102
+ * studio-local (rc2-e): opened by the agent's own hook call for a Maude chat that had no live run —
103
+ * its turn is already running in the agent, so the registry never sends it one (a generated turn
104
+ * with no text failed it at once, and the next hook call opened another: the rc.1 loop).
105
+ */
106
+ hookOpened?: true;
107
+ }
108
+
109
+ export interface RunRefusal {
110
+ code: 'capacity' | 'forbidden' | 'invalid' | 'ended';
111
+ why?: 'artboards' | 'runs' | 'waiting';
95
112
  }
96
113
 
97
114
  export type RunEvent =
@@ -27,7 +27,13 @@ import {
27
27
  } from 'node:fs';
28
28
  import path from 'node:path';
29
29
 
30
- import { type Busy, type Granted, type LeaseHome, leaseKeyId } from './lease-home.ts';
30
+ import {
31
+ type Busy,
32
+ type Granted,
33
+ type LeaseHome,
34
+ leaseKeyId,
35
+ MAX_LEASE_KEYS_PER_RUN,
36
+ } from './lease-home.ts';
31
37
  import { doingOf } from './run-doing.ts';
32
38
  import {
33
39
  ASK_ID_RE,
@@ -43,6 +49,7 @@ import {
43
49
  type RunProgress,
44
50
  type RunPublic,
45
51
  type RunRecord,
52
+ type RunRefusal,
46
53
  type RunScope,
47
54
  type RunView,
48
55
  reduceRun,
@@ -61,6 +68,19 @@ export const MAX_RECORDS = 500;
61
68
  /** S5.5b — the most elements one run holds (the oldest go first). */
62
69
  export const MAX_OBJECTS = 200;
63
70
 
71
+ /** The home's refusal → what the chat may say (rc2-e). The reason text is matched, never shown. */
72
+ export function refusalOf(code: RunRefusal['code'], reason: string | undefined): RunRefusal {
73
+ const r = typeof reason === 'string' ? reason : '';
74
+ const why = /artboards a run/.test(r)
75
+ ? 'artboards'
76
+ : /live runs/.test(r)
77
+ ? 'runs'
78
+ : /waiting artboards/.test(r)
79
+ ? 'waiting'
80
+ : undefined;
81
+ return code === 'capacity' && why ? { code, why } : { code };
82
+ }
83
+
64
84
  export interface RunsView {
65
85
  seq: number;
66
86
  mine: RunView[];
@@ -85,6 +105,11 @@ export interface AskInput {
85
105
  attached?: RunRecord['attached'];
86
106
  /** lease nothing up front: each edit claims what it reaches (terminal Claude, /design:edit) */
87
107
  lazy?: boolean;
108
+ /**
109
+ * rc2-e — the agent's own hook opened this run for a Maude chat with no live run: its turn is already
110
+ * running in the agent, so it is never sent one (see RunRecord.hookOpened)
111
+ */
112
+ hookOpened?: boolean;
88
113
  }
89
114
 
90
115
  export interface PublishResult {
@@ -285,15 +310,33 @@ export function createRunRegistry(opts: RegistryOptions) {
285
310
 
286
311
  // ── keys ──────────────────────────────────────────────────────────────────────────────────
287
312
 
313
+ /**
314
+ * The keys an ask leases up front. A whole-canvas ask takes every artboard (V2-1.15 A4/Q7) — up to
315
+ * the home's per-run cap. Past it (rc.1: a 267-artboard canvas) the home refuses the whole `begin`,
316
+ * so the ask leases nothing up front and begins lazily: each write claims the artboard it reaches
317
+ * through the hook (edit/check → `claim`), where one AI per artboard and a member's lease hold as
318
+ * for every lazy run (decision v2-rc2-e-whole-canvas-lazy-past-cap).
319
+ */
288
320
  function wantsOf(scope: RunScope | null | undefined): LeaseKey[] {
289
321
  if (!scope?.canvas) return [];
290
- const ids =
291
- scope.artboards === '*' ? (opts.artboardsOf?.(scope.canvas) ?? []) : scope.artboards;
322
+ const ids = [
323
+ ...new Set(
324
+ scope.artboards === '*' ? (opts.artboardsOf?.(scope.canvas) ?? []) : scope.artboards
325
+ ),
326
+ ];
327
+ if (scope.artboards === '*' && ids.length > MAX_LEASE_KEYS_PER_RUN) return [];
292
328
  const canvas = canvasKey(scope.canvas);
293
- return [...new Set(ids)].map((artboard) => ({ canvas, artboard }));
329
+ return ids.map((artboard) => ({ canvas, artboard }));
294
330
  }
295
331
 
296
332
  const hid = (rec: RunRecord) => rec.homeRunId ?? rec.runId;
333
+ /**
334
+ * The run's turn runs in the agent already, never sent by this registry: a hook-driven run (terminal
335
+ * Claude, /design:edit) or, rc2-e, one the chat's agent hook opened. It is accepted at once and lapses
336
+ * after HOOK_LAPSE_MS without a hook event, like every hook run.
337
+ */
338
+ const turnIsTheAgents = (rec: RunRecord) =>
339
+ rec.origin !== 'maude-chat' || rec.hookOpened === true;
297
340
  const mineLive = (runId: string) => {
298
341
  const r = records.get(runId);
299
342
  return r && isLive(r) ? r : null;
@@ -400,7 +443,8 @@ export function createRunRegistry(opts: RegistryOptions) {
400
443
  if (lost && eff !== 'end-leases') continue;
401
444
  switch (eff) {
402
445
  case 'send-turn': {
403
- if (rec.origin !== 'maude-chat') break; // a hook run's turn is already in the terminal
446
+ // a hook run's turn is already in the terminal — or, rc2-e, in the chat's own agent
447
+ if (turnIsTheAgents(rec)) break;
404
448
  const text = rec.continuationOf ? continuationText(rec) : null;
405
449
  void Promise.resolve()
406
450
  .then(() => opts.turns?.send?.(rec, text))
@@ -532,7 +576,7 @@ export function createRunRegistry(opts: RegistryOptions) {
532
576
  const started = await transition(runId, { type: 'granted' });
533
577
  // P8 G2 — as startIfReady: a hook-driven run's turn is already running in the terminal, so a
534
578
  // grant to a waiting one makes it `running` (left `starting`, its turn-end was refused for good)
535
- if (started && rec.origin !== 'maude-chat') await transition(runId, { type: 'accepted' });
579
+ if (started && turnIsTheAgents(rec)) await transition(runId, { type: 'accepted' });
536
580
  } else changed();
537
581
  }
538
582
  }
@@ -606,7 +650,8 @@ export function createRunRegistry(opts: RegistryOptions) {
606
650
  objects: heldElements(input.scope),
607
651
  createdAt: now(),
608
652
  ...(ahead ? { behind: ahead.runId } : {}),
609
- ...(input.origin !== 'maude-chat' ? { hookAt: now() } : {}),
653
+ ...(input.origin !== 'maude-chat' || input.hookOpened ? { hookAt: now() } : {}),
654
+ ...(input.hookOpened && input.origin === 'maude-chat' ? { hookOpened: true as const } : {}),
610
655
  ...(input.agent ? { agent: input.agent } : {}),
611
656
  };
612
657
  persist(rec);
@@ -621,7 +666,7 @@ export function createRunRegistry(opts: RegistryOptions) {
621
666
  // lazy (terminal Claude, a selection-less /design:edit): it starts at once and leases what
622
667
  // each edit reaches. The home learns of it in the background (renewal needs the row).
623
668
  const s = transitionSync(rec0.runId, { type: 'granted' });
624
- if (s && rec0.origin !== 'maude-chat') transitionSync(rec0.runId, { type: 'accepted' });
669
+ if (s && turnIsTheAgents(rec0)) transitionSync(rec0.runId, { type: 'accepted' });
625
670
  beginning.add(rec0.runId);
626
671
  void home
627
672
  .begin({
@@ -669,7 +714,15 @@ export function createRunRegistry(opts: RegistryOptions) {
669
714
  return (await startIfReady(rec0.runId, true)) ?? rec;
670
715
  }
671
716
  if (ans.refused) {
672
- persist({ ...rec, state: 'ended', outcome: 'failed', endedAt: now(), waiting: [] });
717
+ // rc2-e: the refusal rides on the record, so the chat says why instead of "working" forever
718
+ persist({
719
+ ...rec,
720
+ state: 'ended',
721
+ outcome: 'failed',
722
+ endedAt: now(),
723
+ waiting: [],
724
+ refused: refusalOf(ans.refused, ans.reason),
725
+ });
673
726
  changed();
674
727
  return records.get(rec0.runId) as RunRecord;
675
728
  }
@@ -703,8 +756,7 @@ export function createRunRegistry(opts: RegistryOptions) {
703
756
  }
704
757
  const started = await transition(runId, { type: 'granted' });
705
758
  // a hook-driven run's turn is already running in the terminal
706
- if (started && rec.origin !== 'maude-chat')
707
- return await transition(runId, { type: 'accepted' });
759
+ if (started && turnIsTheAgents(rec)) return await transition(runId, { type: 'accepted' });
708
760
  return started;
709
761
  }
710
762
 
@@ -800,7 +852,7 @@ export function createRunRegistry(opts: RegistryOptions) {
800
852
  isLive(r) &&
801
853
  !r.behind &&
802
854
  !beginning.has(r.runId) &&
803
- (r.origin === 'maude-chat' || t - (r.hookAt ?? r.createdAt) < HOOK_LAPSE_MS)
855
+ (!turnIsTheAgents(r) || t - (r.hookAt ?? r.createdAt) < HOOK_LAPSE_MS)
804
856
  );
805
857
  if (live.length) {
806
858
  const ans = await home.renew({
@@ -4995,8 +4995,13 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
4995
4995
  * half-moved tree — strictly worse than the un-rewritten imports that were
4996
4996
  * the status quo. A no-op rewrite writes nothing.
4997
4997
  */
4998
- async function rewriteCanvasImports(abs: string, fromDir: string, toDir: string): Promise<void> {
4999
- if (fromDir === toDir) return;
4998
+ async function rewriteCanvasImports(
4999
+ abs: string,
5000
+ fromDir: string,
5001
+ toDir: string,
5002
+ relocate?: (target: string) => string | null
5003
+ ): Promise<void> {
5004
+ if (fromDir === toDir && !relocate) return;
5000
5005
  try {
5001
5006
  // NEVER DEREFERENCE A SYMLINK HERE. The move's containment checks cover
5002
5007
  // the source *directory* (`assertRealpathContained(path.dirname(...))`)
@@ -5011,7 +5016,7 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
5011
5016
  const st = await lstat(abs);
5012
5017
  if (!st.isFile()) return;
5013
5018
  const source = await readFile(abs, 'utf8');
5014
- const next = rewriteRelativeImports(source, fromDir, toDir);
5019
+ const next = rewriteRelativeImports(source, fromDir, toDir, relocate);
5015
5020
  // atomicWrite, not `writeFile` — this lands on a `.tsx` the fs-mirror is
5016
5021
  // watching, so a truncate-then-write can surface a partial-content watch
5017
5022
  // event (the exact hazard atomic-write.ts was built for), and a crash
@@ -5242,7 +5247,22 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
5242
5247
  // itself already succeeded, and a rewrite failure must not leave the tree
5243
5248
  // half-moved — it leaves a build error the user can fix by hand, which is
5244
5249
  // exactly where they were before this existed.
5245
- await rewriteCanvasImports(toAbs, path.posix.dirname(rel), path.posix.dirname(toRel));
5250
+ // issue #153 — the canvas's own files travel with it (`<name>.css` → `<new>.css`), so a specifier that named
5251
+ // one must name where it went, in a same-folder rename too; the rest re-root for the new depth.
5252
+ const travelling = new Map<string, string>();
5253
+ for (const artifact of canvasArtifacts({ rel, paths })) {
5254
+ if (artifact.kind === 'primary' || artifact.carryOnMove === false) continue;
5255
+ const dest = relocatedName(artifact, rel, toRel, paths);
5256
+ if (path.resolve(dest) === path.resolve(artifact.abs)) continue;
5257
+ const posix = (abs: string) => path.relative(paths.designRoot, abs).split(path.sep).join('/');
5258
+ travelling.set(posix(artifact.abs), posix(dest));
5259
+ }
5260
+ await rewriteCanvasImports(
5261
+ toAbs,
5262
+ path.posix.dirname(rel),
5263
+ path.posix.dirname(toRel),
5264
+ (target) => travelling.get(target) ?? null
5265
+ );
5246
5266
 
5247
5267
  const moved: string[] = [path.relative(paths.repoRoot, toAbs)];
5248
5268
  for (const artifact of canvasArtifacts({ rel, paths })) {
@@ -5554,10 +5574,16 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
5554
5574
  // Same depth change as moveCanvas, once per nested canvas (issue #114).
5555
5575
  // A folder move relocates every canvas inside it by the same delta, but
5556
5576
  // each one's own dir differs, so the rewrite is per file, not per folder.
5577
+ // a sibling inside the moved folder moved with it (issue #153): point at its new place, don't re-root back
5557
5578
  await rewriteCanvasImports(
5558
5579
  path.join(paths.designRoot, toRel),
5559
5580
  path.posix.dirname(fromRel),
5560
- path.posix.dirname(toRel)
5581
+ path.posix.dirname(toRel),
5582
+ (target) =>
5583
+ target === relDir.replace(/\/+$/, '') ||
5584
+ target.startsWith(`${relDir.replace(/\/+$/, '')}/`)
5585
+ ? path.posix.join(toRelDir, target.slice(relDir.replace(/\/+$/, '').length))
5586
+ : null
5561
5587
  );
5562
5588
  for (const artifact of canvasArtifacts({ rel: fromRel, paths })) {
5563
5589
  if (artifact.kind !== 'slug-keyed') continue; // primary/siblings already moved with the dir
@@ -71,19 +71,38 @@ export function rerootSpecifier(spec: string, fromDir: string, toDir: string): s
71
71
  * Rewrite every relative import in `source` for a file that moved from
72
72
  * `fromDir` to `toDir` (both POSIX, design-root-relative).
73
73
  *
74
- * Returns the source unchanged when the two dirs are the same or nothing
75
- * relative was found, so a caller can cheaply skip the write.
74
+ * `relocate` answers for the files that moved WITH the canvas (issue #153): a target it maps — the canvas's own
75
+ * `<name>.css` renamed to `<new>.css`, a sibling inside a moved folder — is pointed at where that file went,
76
+ * not re-rooted back to where it was. Every other relative specifier re-roots for the new folder depth.
77
+ *
78
+ * Returns the source unchanged when nothing relative needed a change, so a caller can cheaply skip the write.
76
79
  */
77
- export function rewriteRelativeImports(source: string, fromDir: string, toDir: string): string {
80
+ export function rewriteRelativeImports(
81
+ source: string,
82
+ fromDir: string,
83
+ toDir: string,
84
+ relocate?: (target: string) => string | null
85
+ ): string {
78
86
  const from = path.posix.normalize(fromDir === '' ? '.' : fromDir);
79
87
  const to = path.posix.normalize(toDir === '' ? '.' : toDir);
80
- if (from === to) return source;
88
+ if (from === to && !relocate) return source;
81
89
  let out = source;
82
90
  for (const pattern of SPECIFIER_PATTERNS) {
83
91
  out = out.replace(pattern, (whole, lead: string, quote: string, spec: string) => {
84
92
  if (!isRelativeSpecifier(spec)) return whole;
93
+ const moved = relocate?.(path.posix.normalize(path.posix.join(from, spec)));
94
+ if (moved) return `${lead}${quote}${specifierTo(moved, to, spec.endsWith('/'))}${quote}`;
95
+ if (from === to) return whole;
85
96
  return `${lead}${quote}${rerootSpecifier(spec, from, to)}${quote}`;
86
97
  });
87
98
  }
88
99
  return out;
89
100
  }
101
+
102
+ /** The relative specifier from `dir` to the design-root-relative `target` (`./` kept, a trailing `/` kept). */
103
+ function specifierTo(target: string, dir: string, trailingSlash: boolean): string {
104
+ let next = path.posix.relative(dir, target);
105
+ if (!next.startsWith('.')) next = `./${next}`;
106
+ if (trailingSlash && !next.endsWith('/')) next = `${next}/`;
107
+ return next;
108
+ }
@@ -3572,6 +3572,10 @@ function App() {
3572
3572
  );
3573
3573
  }
3574
3574
 
3575
+ // The web fonts (Inter, Inter Tight, JetBrains Mono) are self-hosted: `client/styles/fonts.css` declares them from
3576
+ // `/_client/fonts/` with `font-display: swap`, so the app makes no request to Google Fonts (#175 item 4) and the
3577
+ // first paint waits on nothing (v2.0.0-rc.1's white Home was a parser-blocking Google stylesheet).
3578
+
3575
3579
  // DDR-247 — `?embed=1` is a different root, not a mode of <App>: nothing the
3576
3580
  // shell does (prefs, address bar, panels) runs inside another app's frame.
3577
3581
  // V2-3.3 — so is Home (`/_config.mode === 'home'`, client/home/shell-mode.js).
@@ -0,0 +1,93 @@
1
+ Copyright 2022 The Inter Project Authors (https://github.com/rsms/inter-tight) InterTight-Italic[wght].ttf: Copyright 2022 The Inter Project Authors (https://github.com/rsms/inter-tight)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter) Inter-Italic[opsz,wght].ttf: Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.