@1agh/maude 2.0.3 → 2.0.4
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.
- package/README.md +6 -5
- package/apps/studio/access/request.ts +0 -1
- package/apps/studio/acp/adapter-stderr.ts +43 -13
- package/apps/studio/acp/background-tasks.ts +155 -0
- package/apps/studio/acp/bridge.ts +44 -5
- package/apps/studio/acp/connected-fact.ts +15 -4
- package/apps/studio/acp/index.ts +14 -5
- package/apps/studio/actions/agents.ts +5 -0
- package/apps/studio/actions/defs/view.ts +12 -0
- package/apps/studio/actions.manifest.json +13 -1
- package/apps/studio/actions.parity.json +7 -1
- package/apps/studio/api.ts +31 -24
- package/apps/studio/bin/_png-playwright.mjs +10 -1
- package/apps/studio/bin/_pw-launch.mjs +14 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +4 -1
- package/apps/studio/boot-progress.ts +31 -0
- package/apps/studio/canvas-build-sandbox.ts +275 -42
- package/apps/studio/canvas-build-worker.ts +10 -0
- package/apps/studio/canvas-create.ts +24 -0
- package/apps/studio/canvas-module-cache.ts +93 -0
- package/apps/studio/canvas-source/errors.ts +39 -0
- package/apps/studio/canvas-source/waiting.ts +290 -0
- package/apps/studio/client/actions/shell-key-handlers.js +5 -0
- package/apps/studio/client/app.jsx +19 -9
- package/apps/studio/client/github.js +23 -3
- package/apps/studio/client/home/home-api.js +30 -19
- package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
- package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
- package/apps/studio/client/hooks/use-tabs.jsx +64 -35
- package/apps/studio/client/index-loader.ts +23 -3
- package/apps/studio/client/panels/ChatPanel.jsx +22 -37
- package/apps/studio/client/panels/DiffView.jsx +314 -248
- package/apps/studio/client/panels/TeamProjects.jsx +119 -69
- package/apps/studio/client/panels/acp-runtime.js +25 -0
- package/apps/studio/client/panels/chat-finish.js +66 -0
- package/apps/studio/client/shell/frame-cap.js +53 -0
- package/apps/studio/client/shell/viewport.jsx +9 -0
- package/apps/studio/client/styles/_index.css +2 -0
- package/apps/studio/client/tree/tree.jsx +48 -21
- package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
- package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
- package/apps/studio/client/v2/ai/ai-run.css +87 -3
- package/apps/studio/client/v2/ai/background-model.js +113 -0
- package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
- package/apps/studio/client/v2/ai/run-api.js +7 -3
- package/apps/studio/client/v2/ai/runs-store.js +2 -1
- package/apps/studio/client/v2/annotations/vote-store.js +11 -5
- package/apps/studio/client/v2/assets/asset-state-lane.js +6 -3
- package/apps/studio/client/v2/assets/assets-bus.js +10 -8
- package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
- package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
- package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
- package/apps/studio/client/v2/assets/spotlight.css +153 -0
- package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
- package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
- package/apps/studio/client/v2/assets/tile.jsx +3 -0
- package/apps/studio/client/v2/assets/use-assets.js +2 -1
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
- package/apps/studio/client/v2/canvases/covers.js +11 -5
- package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
- package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
- package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
- package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
- package/apps/studio/client/v2/canvases/use-pins.js +2 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
- package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
- package/apps/studio/client/v2/code/code.css +67 -0
- package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
- package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
- package/apps/studio/client/v2/create/name-dialog.css +10 -0
- package/apps/studio/client/v2/ds/advanced-host.jsx +5 -2
- package/apps/studio/client/v2/ds/make-host.jsx +5 -2
- package/apps/studio/client/v2/ds/off-system-host.jsx +5 -2
- package/apps/studio/client/v2/ds/truth-host.jsx +5 -2
- package/apps/studio/client/v2/empty/arriving.jsx +29 -12
- package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
- package/apps/studio/client/v2/empty/not-local.jsx +31 -1
- package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
- package/apps/studio/client/v2/export/last-finished.js +2 -1
- package/apps/studio/client/v2/history/git-model.js +18 -4
- package/apps/studio/client/v2/history/git-parts.jsx +60 -42
- package/apps/studio/client/v2/history/history.css +6 -0
- package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
- package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
- package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
- package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
- package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
- package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
- package/apps/studio/client/v2/search/search-recent.js +3 -1
- package/apps/studio/client/v2/search/search-remote.js +6 -4
- package/apps/studio/client/v2/settings/connections-model.js +1 -1
- package/apps/studio/client/v2/shell/menu-runner.js +1 -0
- package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
- package/apps/studio/client/v2/shell/recovery-store.js +2 -1
- package/apps/studio/client/v2/shell/served-routes.js +120 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +2 -1
- package/apps/studio/client/v2/shell/shell-activity.js +19 -0
- package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
- package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
- package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
- package/apps/studio/cloud/endpoints.ts +23 -1
- package/apps/studio/dist/client.bundle.js +977 -981
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/editing/minimap-context.tsx +3 -3
- package/apps/studio/editing/page-activity.ts +251 -0
- package/apps/studio/editing/rotate-handle.tsx +9 -5
- package/apps/studio/editing/sticky-name.tsx +4 -4
- package/apps/studio/history/restore-artboard-action.ts +40 -0
- package/apps/studio/home/hub.ts +77 -175
- package/apps/studio/home/routes.ts +47 -8
- package/apps/studio/http.ts +117 -66
- package/apps/studio/index-flight.ts +40 -0
- package/apps/studio/managed-projects.ts +52 -24
- package/apps/studio/migrate/hub.ts +7 -1
- package/apps/studio/routes/canvas-source.ts +44 -2
- package/apps/studio/routes/history.ts +28 -5
- package/apps/studio/routes/hub-signin.ts +115 -0
- package/apps/studio/routes/index.ts +4 -0
- package/apps/studio/routes/table.ts +7 -0
- package/apps/studio/routes/trash.ts +3 -0
- package/apps/studio/server.ts +11 -0
- package/apps/studio/sync/accepted-cold-start.ts +26 -3
- package/apps/studio/sync/accepted-link.ts +9 -4
- package/apps/studio/sync/code-module-consent.ts +74 -0
- package/apps/studio/sync/file-ledger.ts +35 -0
- package/apps/studio/sync/file-plane.ts +443 -77
- package/apps/studio/sync/hub-browser-signin.ts +377 -0
- package/apps/studio/sync/hub-text-undo.ts +30 -10
- package/apps/studio/sync/index.ts +73 -11
- package/apps/studio/sync/projection.ts +44 -2
- package/apps/studio/sync/pull-pacer.ts +160 -0
- package/apps/studio/sync/pull-priority.ts +119 -0
- package/apps/studio/sync/seed-progress.ts +47 -3
- package/apps/studio/sync/transaction-client.ts +71 -6
- package/apps/studio/sync/workspace-signin.ts +6 -256
- package/apps/studio/sync/writer-registry.ts +5 -1
- package/apps/studio/video-links-overlay.tsx +3 -2
- package/apps/studio/whats-new.json +54 -0
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/workspace-plan.mjs +14 -0
- package/package.json +8 -8
|
@@ -77,6 +77,8 @@ export const ACCEPTED_FLUSH_MS = 30;
|
|
|
77
77
|
export const MAX_OP_REPLAYS = 3;
|
|
78
78
|
/** How long an announced API write may hold the doc→file writer at most. */
|
|
79
79
|
export const LOCAL_WRITE_HOLD_MS = 3_000;
|
|
80
|
+
/** How long a restore waits for this disk's html proposals to be answered (`settleDisk`). */
|
|
81
|
+
export const SETTLE_DISK_MS = 8_000;
|
|
80
82
|
/** `MAUDE_SYNC_DEBUG=1` — one line per proposal and per disk write (diagnosis). */
|
|
81
83
|
const SYNC_DEBUG = process.env.MAUDE_SYNC_DEBUG === '1';
|
|
82
84
|
export const CIRCUIT_MAX_STRIKES = 3;
|
|
@@ -261,8 +263,10 @@ export interface DocProjection {
|
|
|
261
263
|
* Adopt `body` as the shared base before `reconcile()`. A restart that could
|
|
262
264
|
* not merge a local candidate (cold start) hands the base back here, so the
|
|
263
265
|
* write stays blocked with a visible conflict and a later save can merge.
|
|
266
|
+
* `remember` persists it as the recorded base (an accepted create — never a
|
|
267
|
+
* hold, whose base must stay unagreed so the next restart holds again).
|
|
264
268
|
*/
|
|
265
|
-
adoptBase(body: string): void;
|
|
269
|
+
adoptBase(body: string, o?: { remember?: boolean }): void;
|
|
266
270
|
/**
|
|
267
271
|
* S6.13b — this Mac's canvas moved away from this path on purpose (its name
|
|
268
272
|
* was taken while it was away): the file is gone by agreement, and what the
|
|
@@ -321,6 +325,18 @@ export interface DocProjection {
|
|
|
321
325
|
* (false); then the doc→file writer is flushed, so an accepted action is on disk on return.
|
|
322
326
|
*/
|
|
323
327
|
settleLane(lane: ProposalLane, value: string, ms?: number): Promise<boolean>;
|
|
328
|
+
/**
|
|
329
|
+
* F14 (2.0.4, #166) — a restore is about to splice onto the project's newest version: bring
|
|
330
|
+
* THIS disk's source up to the project first. A change on disk the watcher has not delivered
|
|
331
|
+
* yet (its quiet window) is proposed now, exactly as its file event would propose it, and every
|
|
332
|
+
* html proposal in flight is waited for (at most `ms`). Without this the restore was spliced onto
|
|
333
|
+
* a head that lacked the change the person was looking at; the change, proposed after it from
|
|
334
|
+
* the older base, overlapped the restore and was held here — the click answered ok and the file
|
|
335
|
+
* stayed as it was. `held`: this disk keeps a refused change (the restore must not land over
|
|
336
|
+
* it); `pending`: a proposal is still unanswered after `ms`; `settled`: the project's newest
|
|
337
|
+
* version is what this disk shows.
|
|
338
|
+
*/
|
|
339
|
+
settleDisk(ms?: number): Promise<'settled' | 'held' | 'pending'>;
|
|
324
340
|
/** Lanes with an unresolved proposal (status surfaces). */
|
|
325
341
|
pendingCount(): number;
|
|
326
342
|
/**
|
|
@@ -1345,9 +1361,12 @@ export function createDocProjection(opts: DocProjectionOptions): DocProjection {
|
|
|
1345
1361
|
applyFromFs,
|
|
1346
1362
|
reconcile,
|
|
1347
1363
|
flush,
|
|
1348
|
-
adoptBase(body: string) {
|
|
1364
|
+
adoptBase(body: string, o?: { remember?: boolean }) {
|
|
1349
1365
|
lastHtml = body;
|
|
1350
1366
|
observedBody = body;
|
|
1367
|
+
// v2-204 — an accepted create IS agreement with the project: persist it like any other
|
|
1368
|
+
// accepted value, or the creator restarts with no base and its next offline edit is held.
|
|
1369
|
+
if (o?.remember) rememberBase(body);
|
|
1351
1370
|
},
|
|
1352
1371
|
vacate() {
|
|
1353
1372
|
observedBody = null;
|
|
@@ -1476,6 +1495,29 @@ export function createDocProjection(opts: DocProjectionOptions): DocProjection {
|
|
|
1476
1495
|
if (text !== null) applyFromFs({ path: p, bytes: new TextEncoder().encode(text), hash });
|
|
1477
1496
|
}
|
|
1478
1497
|
},
|
|
1498
|
+
async settleDisk(ms = SETTLE_DISK_MS) {
|
|
1499
|
+
if (!acceptedOn() || stopped) return 'settled';
|
|
1500
|
+
if (held.has('html')) return 'held';
|
|
1501
|
+
if (ready && movedToFromDoc(doc) === null) {
|
|
1502
|
+
const str = readLocal(paths.html);
|
|
1503
|
+
// Only a change nobody proposed yet: what this projection wrote or proposed last is
|
|
1504
|
+
// `observedBody`, and an invalid source is left to its own file event (one strike each).
|
|
1505
|
+
if (
|
|
1506
|
+
str !== null &&
|
|
1507
|
+
str !== observedBody &&
|
|
1508
|
+
!isQuarantined(paths.html, hashBytes(str)) &&
|
|
1509
|
+
validation(str) === null
|
|
1510
|
+
) {
|
|
1511
|
+
proposeFromFs({ path: paths.html, hash: hashBytes(str) }, str);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
const end = Date.now() + ms;
|
|
1515
|
+
while (pending.has('html') && !stopped && Date.now() < end) {
|
|
1516
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
1517
|
+
}
|
|
1518
|
+
if (held.has('html')) return 'held';
|
|
1519
|
+
return pending.has('html') ? 'pending' : 'settled';
|
|
1520
|
+
},
|
|
1479
1521
|
pendingCount() {
|
|
1480
1522
|
let n = 0;
|
|
1481
1523
|
for (const p of pending.values()) n += p.count;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// How fast the file plane talks to a hub — issue #204 (a 5 041-file cloud project took ≈ 1.5 h to
|
|
2
|
+
// reach a new Mac: 200 files per pass, ONE request at a time, and the next pass only on the 20 s
|
|
3
|
+
// tick — so the wall clock was the sum of every round trip plus the waits between passes).
|
|
4
|
+
//
|
|
5
|
+
// Two independent bounds, because they protect different things:
|
|
6
|
+
//
|
|
7
|
+
// CONCURRENCY — how many transfers are in flight at once. A cold cell fills every first read of a
|
|
8
|
+
// media file from its bucket with `MAX_CONCURRENT_FILLS = 4` slots and a 15 s deadline
|
|
9
|
+
// (apps/hub/src/materializer.mjs); more parallel GETs than that only queue inside the cell until
|
|
10
|
+
// they time out as `503 fetching from storage`. So we start AT the cell's fill width, may grow a
|
|
11
|
+
// little past it on a hub that keeps up (a warm cache or a self-hosted disk), halve on a 429 and
|
|
12
|
+
// step down on every storage miss — additive increase, multiplicative decrease.
|
|
13
|
+
//
|
|
14
|
+
// RATE — how many requests start in any rolling minute. The hub meters every file read AND every
|
|
15
|
+
// journal read against ONE per-label bucket of 600 a minute (`fileReadBuckets`, server.mjs), and
|
|
16
|
+
// writes against a separate one of the same size. Concurrency alone does not bound that: on a fast
|
|
17
|
+
// hub six parallel GETs of small files run past 600 in well under a minute, and a plane that then
|
|
18
|
+
// meets a 429 is a client manufacturing the limit it fails on (issue #109). We stay at 480, leaving
|
|
19
|
+
// the remaining fifth for the cursor reads, the presence report and anything else on the label.
|
|
20
|
+
//
|
|
21
|
+
// Leaf on purpose: no imports, a clock and a sleep injected, so the tests drive it without timers.
|
|
22
|
+
|
|
23
|
+
/** Transfers in flight at the start — the cold cell's bucket-fill width. */
|
|
24
|
+
export const PULL_CONCURRENCY_START = 4;
|
|
25
|
+
/** Never more than this, however well the hub keeps up. */
|
|
26
|
+
export const PULL_CONCURRENCY_MAX = 6;
|
|
27
|
+
/** Never fewer than one: a wall is a hold (the plane's job), not a zero. */
|
|
28
|
+
export const PULL_CONCURRENCY_MIN = 1;
|
|
29
|
+
|
|
30
|
+
/** Requests of one kind per rolling minute — under the hub's 600-per-label buckets. */
|
|
31
|
+
export const REQUESTS_PER_MINUTE = 480;
|
|
32
|
+
/**
|
|
33
|
+
* A hub that advertises its read ceiling (`/api/file-limits` `readsPerMinute`, #204 — 1 800 on a
|
|
34
|
+
* current hub) is paced at this share of it: the rest of the bucket is the cursor reads' and the
|
|
35
|
+
* presence report's. The advertised figure is hub-supplied (DDR-054), so it is clamped: a hub can
|
|
36
|
+
* slow its own sync down to `MIN_TRUSTED_READS_PER_MINUTE`, never talk us past the maximum.
|
|
37
|
+
*/
|
|
38
|
+
export const ADVERTISED_SHARE = 0.8;
|
|
39
|
+
export const MIN_TRUSTED_READS_PER_MINUTE = 60;
|
|
40
|
+
export const MAX_TRUSTED_READS_PER_MINUTE = 6000;
|
|
41
|
+
const WINDOW_MS = 60_000;
|
|
42
|
+
|
|
43
|
+
export type RequestKind = 'read' | 'write';
|
|
44
|
+
|
|
45
|
+
export interface PullPacer {
|
|
46
|
+
/** How many transfers may be in flight right now. */
|
|
47
|
+
limit(): number;
|
|
48
|
+
/** The hub said slow down (a 429, a 5xx with Retry-After): halve. */
|
|
49
|
+
onBackpressure(): void;
|
|
50
|
+
/** The cell's bucket fill timed out for one file: one step down. */
|
|
51
|
+
onStorageMiss(): void;
|
|
52
|
+
/** A pass moved real work and met no wall: one step up. */
|
|
53
|
+
onCleanPass(): void;
|
|
54
|
+
/** The hub advertised its per-label read ceiling: pace reads at a share of it (clamped). */
|
|
55
|
+
setReadCeiling(perMinute: number): void;
|
|
56
|
+
/** Reads per rolling minute in force right now. */
|
|
57
|
+
readsPerMinute(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Wait until one more request of this kind fits in the rolling minute, then charge it. Resolves
|
|
60
|
+
* at once while there is room — a pass that stays under the budget never waits at all.
|
|
61
|
+
*/
|
|
62
|
+
admit(kind: RequestKind): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface PullPacerOptions {
|
|
66
|
+
now?: () => number;
|
|
67
|
+
sleep?: (ms: number) => Promise<void>;
|
|
68
|
+
start?: number;
|
|
69
|
+
max?: number;
|
|
70
|
+
perMinute?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function createPullPacer(opts: PullPacerOptions = {}): PullPacer {
|
|
74
|
+
const now = opts.now ?? Date.now;
|
|
75
|
+
const sleep = opts.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
|
|
76
|
+
const max = Math.max(PULL_CONCURRENCY_MIN, opts.max ?? PULL_CONCURRENCY_MAX);
|
|
77
|
+
const writesPerMinute = Math.max(1, opts.perMinute ?? REQUESTS_PER_MINUTE);
|
|
78
|
+
let readsPerMinute = writesPerMinute;
|
|
79
|
+
let limit = Math.min(max, Math.max(PULL_CONCURRENCY_MIN, opts.start ?? PULL_CONCURRENCY_START));
|
|
80
|
+
// Start times of the requests inside the last minute, oldest first, per kind. Bounded by
|
|
81
|
+
// `perMinute` — `admit` never lets one in past the ceiling.
|
|
82
|
+
const starts: Record<RequestKind, number[]> = { read: [], write: [] };
|
|
83
|
+
|
|
84
|
+
const prune = (log: number[], at: number): void => {
|
|
85
|
+
while (log.length > 0 && at - (log[0] as number) >= WINDOW_MS) log.shift();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
limit: () => limit,
|
|
90
|
+
onBackpressure() {
|
|
91
|
+
limit = Math.max(PULL_CONCURRENCY_MIN, Math.floor(limit / 2));
|
|
92
|
+
},
|
|
93
|
+
onStorageMiss() {
|
|
94
|
+
limit = Math.max(PULL_CONCURRENCY_MIN, limit - 1);
|
|
95
|
+
},
|
|
96
|
+
onCleanPass() {
|
|
97
|
+
limit = Math.min(max, limit + 1);
|
|
98
|
+
},
|
|
99
|
+
setReadCeiling(advertised) {
|
|
100
|
+
if (!Number.isFinite(advertised) || advertised <= 0) return;
|
|
101
|
+
const clamped = Math.min(
|
|
102
|
+
MAX_TRUSTED_READS_PER_MINUTE,
|
|
103
|
+
Math.max(MIN_TRUSTED_READS_PER_MINUTE, advertised)
|
|
104
|
+
);
|
|
105
|
+
readsPerMinute = Math.max(1, Math.floor(clamped * ADVERTISED_SHARE));
|
|
106
|
+
},
|
|
107
|
+
readsPerMinute: () => readsPerMinute,
|
|
108
|
+
async admit(kind) {
|
|
109
|
+
const log = starts[kind];
|
|
110
|
+
const perMinute = kind === 'read' ? readsPerMinute : writesPerMinute;
|
|
111
|
+
for (;;) {
|
|
112
|
+
const at = now();
|
|
113
|
+
prune(log, at);
|
|
114
|
+
if (log.length < perMinute) {
|
|
115
|
+
log.push(at);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// The oldest start leaves the window first; come back the moment it does.
|
|
119
|
+
await sleep(Math.max(1, WINDOW_MS - (at - (log[0] as number))));
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The parts of a pass result the follow-up decision reads (a `FilePlaneResult` fits). */
|
|
126
|
+
export interface PassOutcome {
|
|
127
|
+
pulled: readonly unknown[];
|
|
128
|
+
pushed: readonly unknown[];
|
|
129
|
+
rateLimited?: unknown;
|
|
130
|
+
authRefused?: true;
|
|
131
|
+
formatRefused?: unknown;
|
|
132
|
+
reanchorHeld?: true;
|
|
133
|
+
requestsExhausted?: true;
|
|
134
|
+
filesCapped?: true;
|
|
135
|
+
budgetExhausted?: true;
|
|
136
|
+
nextAttemptInMs?: number;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* When the NEXT plane pass should run, instead of waiting for the poll tick — issue #204.
|
|
141
|
+
*
|
|
142
|
+
* 0 — the pass moved files and stopped on a COUNT ceiling: there is more of the same, now.
|
|
143
|
+
* ms — a path is waiting out a short backoff (a storage miss): come back when it ends, never
|
|
144
|
+
* sooner than the pass floor.
|
|
145
|
+
* null — leave it to the tick: a wall (rate limit, credential, format, re-anchor storm), a pass
|
|
146
|
+
* that moved nothing (so a pass whose requests all fail can never spin — issue #109), and
|
|
147
|
+
* a byte-budget stop (the 2 GiB per-pass ceiling, DDR-226 F6, stays a per-tick bound).
|
|
148
|
+
*/
|
|
149
|
+
export function followUpDelayMs(
|
|
150
|
+
r: PassOutcome,
|
|
151
|
+
timing: { pollMs: number; floorMs: number }
|
|
152
|
+
): number | null {
|
|
153
|
+
if (r.rateLimited || r.authRefused || r.formatRefused || r.reanchorHeld) return null;
|
|
154
|
+
const moved = r.pulled.length + r.pushed.length;
|
|
155
|
+
if (moved > 0 && !r.budgetExhausted && (r.requestsExhausted || r.filesCapped)) return 0;
|
|
156
|
+
if (r.nextAttemptInMs !== undefined && r.nextAttemptInMs < timing.pollMs) {
|
|
157
|
+
return Math.max(timing.floorMs, r.nextAttemptInMs);
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// What the open canvas needs, so a first sync fetches it first — issue #204.
|
|
2
|
+
//
|
|
3
|
+
// A fresh link of a 5 000-file project used to deliver in size order: the forty pictures on the
|
|
4
|
+
// canvas a person is looking at waited behind thousands of thumbnails they are not. The plane already
|
|
5
|
+
// puts annotation-referenced assets first (DDR-223); this puts the ACTIVE canvas's closure ahead of
|
|
6
|
+
// that: its sidecars, the modules it imports (transitively, as far as they are on disk yet) and the
|
|
7
|
+
// assets those files name.
|
|
8
|
+
//
|
|
9
|
+
// CHEAP AND BEST-EFFORT ON PURPOSE. It only ORDERS work the plane already decided to do — it never
|
|
10
|
+
// admits a path, never names one the hub did not offer, and a wrong answer costs a slower first
|
|
11
|
+
// paint, never a wrong file. So a regex scan is enough: no transpiler, no build, a bounded walk.
|
|
12
|
+
// Everything it reads is this machine's own disk (`_active.json` is written by the studio itself).
|
|
13
|
+
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
|
|
17
|
+
/** Files the walk reads at most — a canvas imports a handful, a design system a few dozen. */
|
|
18
|
+
const MAX_FILES_READ = 64;
|
|
19
|
+
/** Bytes read per file at most. */
|
|
20
|
+
const MAX_READ_BYTES = 512 * 1024;
|
|
21
|
+
|
|
22
|
+
const IMPORT_RES = [
|
|
23
|
+
/\bimport\s*["']([^"'\n]+)["']/g,
|
|
24
|
+
/\bfrom\s*["']([^"'\n]+)["']/g,
|
|
25
|
+
/\b(?:import|require)\s*\(\s*["']([^"'\n]+)["']\s*\)/g,
|
|
26
|
+
/@import\s+url\(\s*["']?([^"')\s]+)["']?\s*\)/g,
|
|
27
|
+
];
|
|
28
|
+
/** A path that ends in an extension, inside quotes or `url()` — asset references in JSX/CSS/JSON. */
|
|
29
|
+
const QUOTED_PATH_RE = /["'`(]((?:\.{1,2}\/|\/)?[A-Za-z0-9_\-./]+\.[A-Za-z0-9]{1,8})["'`)]/g;
|
|
30
|
+
const MODULE_EXT_RE = /\.(tsx|ts|jsx|js|mjs|cjs|css)$/i;
|
|
31
|
+
const RESOLVE_EXTS = ['.tsx', '.ts', '.jsx', '.js', '.css', '/index.tsx', '/index.ts'];
|
|
32
|
+
const SIDECARS = ['.meta.json', '.annotations.json', '.annotations.svg', '.css'];
|
|
33
|
+
|
|
34
|
+
function readCapped(abs: string): string | null {
|
|
35
|
+
try {
|
|
36
|
+
const buf = readFileSync(abs);
|
|
37
|
+
return buf.subarray(0, MAX_READ_BYTES).toString('utf8');
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A design-root-relative POSIX path, or null when it leaves the root. */
|
|
44
|
+
function inRoot(rel: string): string | null {
|
|
45
|
+
const norm = path.posix.normalize(rel).replace(/^\/+/, '');
|
|
46
|
+
if (norm === '' || norm === '.' || norm.startsWith('../') || norm === '..') return null;
|
|
47
|
+
return norm;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The active canvas's want-set, as design-root-relative paths. Empty when no canvas is open or
|
|
52
|
+
* `_active.json` is missing/unreadable. Paths may not exist yet — that is the point: they are the
|
|
53
|
+
* ones the hub should send first.
|
|
54
|
+
*/
|
|
55
|
+
export function activeCanvasWants(designRoot: string): Set<string> {
|
|
56
|
+
const wants = new Set<string>();
|
|
57
|
+
let active: unknown = null;
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(readFileSync(path.join(designRoot, '_active.json'), 'utf8')) as {
|
|
60
|
+
active?: unknown;
|
|
61
|
+
};
|
|
62
|
+
active = parsed?.active;
|
|
63
|
+
} catch {
|
|
64
|
+
return wants;
|
|
65
|
+
}
|
|
66
|
+
if (typeof active !== 'string' || active.length === 0 || active.length > 1024) return wants;
|
|
67
|
+
// `_active.json` names the canvas by its design-root-relative path; a stray absolute or `.design/`
|
|
68
|
+
// prefix is tolerated, anything that leaves the root is not.
|
|
69
|
+
const start = inRoot(active.replace(/^\.design\//, ''));
|
|
70
|
+
if (start === null) return wants;
|
|
71
|
+
|
|
72
|
+
const queue: string[] = [start];
|
|
73
|
+
const seen = new Set<string>();
|
|
74
|
+
let read = 0;
|
|
75
|
+
while (queue.length > 0 && read < MAX_FILES_READ) {
|
|
76
|
+
const rel = queue.shift() as string;
|
|
77
|
+
if (seen.has(rel)) continue;
|
|
78
|
+
seen.add(rel);
|
|
79
|
+
wants.add(rel);
|
|
80
|
+
if (rel === start) {
|
|
81
|
+
const stem = rel.replace(/\.(tsx|jsx|html)$/i, '');
|
|
82
|
+
for (const s of SIDECARS) wants.add(`${stem}${s}`);
|
|
83
|
+
}
|
|
84
|
+
if (!MODULE_EXT_RE.test(rel)) continue;
|
|
85
|
+
const text = readCapped(path.join(designRoot, rel));
|
|
86
|
+
if (text === null) continue;
|
|
87
|
+
read += 1;
|
|
88
|
+
const dir = path.posix.dirname(rel);
|
|
89
|
+
for (const re of IMPORT_RES) {
|
|
90
|
+
re.lastIndex = 0;
|
|
91
|
+
for (let m = re.exec(text); m !== null; m = re.exec(text)) {
|
|
92
|
+
const spec = m[1] ?? '';
|
|
93
|
+
if (!spec.startsWith('.')) continue;
|
|
94
|
+
const base = inRoot(path.posix.join(dir, spec));
|
|
95
|
+
if (base === null) continue;
|
|
96
|
+
if (/\.[A-Za-z0-9]{1,8}$/.test(spec)) {
|
|
97
|
+
wants.add(base);
|
|
98
|
+
if (MODULE_EXT_RE.test(base)) queue.push(base);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
for (const ext of RESOLVE_EXTS) {
|
|
102
|
+
const cand = `${base}${ext}`;
|
|
103
|
+
wants.add(cand);
|
|
104
|
+
queue.push(cand);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
QUOTED_PATH_RE.lastIndex = 0;
|
|
109
|
+
for (let m = QUOTED_PATH_RE.exec(text); m !== null; m = QUOTED_PATH_RE.exec(text)) {
|
|
110
|
+
const ref = m[1] ?? '';
|
|
111
|
+
// Relative to the file, and — the house convention for assets — relative to the root.
|
|
112
|
+
const rel1 = ref.startsWith('.') ? inRoot(path.posix.join(dir, ref)) : null;
|
|
113
|
+
const rel2 = inRoot(ref.replace(/^\.design\//, ''));
|
|
114
|
+
if (rel1) wants.add(rel1);
|
|
115
|
+
if (rel2) wants.add(rel2);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return wants;
|
|
119
|
+
}
|
|
@@ -41,8 +41,23 @@ export interface SeedProgress {
|
|
|
41
41
|
tracked: number;
|
|
42
42
|
/** Rows in a terminal-good state. */
|
|
43
43
|
delivered: number;
|
|
44
|
-
/** `tracked - delivered - blocked`, floored at 0. */
|
|
44
|
+
/** `tracked - delivered - blocked - held`, floored at 0. */
|
|
45
45
|
remaining: number;
|
|
46
|
+
/**
|
|
47
|
+
* Issue #204 — rows this Mac REFUSES to take (a code module from a hub it has not vouched for).
|
|
48
|
+
* Not waiting — nothing moves them but a person's consent — and not "blocked" on the hub's side
|
|
49
|
+
* either, so they get their own count and their own words, said once. Always set by
|
|
50
|
+
* `computeSeedProgress`; optional only so older snapshots still type.
|
|
51
|
+
*/
|
|
52
|
+
held?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Outstanding rows whose last attempt FAILED and that wait out a backoff (`stuck`, `attempts`
|
|
55
|
+
* ≥ 1) — counted inside `remaining` (they are not delivered), named here so a status line can say
|
|
56
|
+
* "retrying" and which file, instead of "waiting" forever (#204 follow-up). `retryingFile` is the
|
|
57
|
+
* first such row and its reason.
|
|
58
|
+
*/
|
|
59
|
+
retrying?: number;
|
|
60
|
+
retryingFile?: { rel: string; reason: string };
|
|
46
61
|
/** Bytes still to move, as far as the ledger knows. Best-effort. */
|
|
47
62
|
bytesRemaining: number;
|
|
48
63
|
/** Outstanding rows no retry will clear on its own, by class. */
|
|
@@ -72,6 +87,19 @@ const DELIVERED: ReadonlySet<DeliveryState> = new Set<DeliveryState>([
|
|
|
72
87
|
'everywhere',
|
|
73
88
|
]);
|
|
74
89
|
|
|
90
|
+
/**
|
|
91
|
+
* The ledger reason the file plane writes for a code module this Mac will not take (file-plane.ts,
|
|
92
|
+
* the admission gate). Matched EXACTLY — a reason built from a hub's words always starts `HTTP …` or
|
|
93
|
+
* `The project’s server …`, so a peer cannot write this sentence into a row.
|
|
94
|
+
*/
|
|
95
|
+
export const CODE_MODULE_HELD_REASON =
|
|
96
|
+
'code modules replicate only from an owner-vouched or loopback hub';
|
|
97
|
+
|
|
98
|
+
/** A row the receiver itself refuses, by consent: held, not waiting. */
|
|
99
|
+
export function isHeldByConsent(row: LedgerRow): boolean {
|
|
100
|
+
return row.state === 'stuck' && row.reason === CODE_MODULE_HELD_REASON;
|
|
101
|
+
}
|
|
102
|
+
|
|
75
103
|
/** States that will not move again without something changing. */
|
|
76
104
|
const BLOCKED: ReadonlySet<DeliveryState> = new Set<DeliveryState>([
|
|
77
105
|
'refused',
|
|
@@ -106,20 +134,33 @@ export function computeSeedProgress(input: SeedProgressInput): SeedProgress {
|
|
|
106
134
|
let tracked = 0;
|
|
107
135
|
let delivered = 0;
|
|
108
136
|
let bytesRemaining = 0;
|
|
137
|
+
let held = 0;
|
|
138
|
+
let retrying = 0;
|
|
139
|
+
let retryingFile: { rel: string; reason: string } | undefined;
|
|
109
140
|
const blockedCounts = new Map<BlockedClass, number>();
|
|
110
141
|
|
|
111
|
-
for (const row of Object.
|
|
142
|
+
for (const [rel, row] of Object.entries(rows)) {
|
|
112
143
|
tracked += 1;
|
|
113
144
|
const state = row.state;
|
|
114
145
|
if (state && DELIVERED.has(state)) {
|
|
115
146
|
delivered += 1;
|
|
116
147
|
continue;
|
|
117
148
|
}
|
|
149
|
+
if (isHeldByConsent(row)) {
|
|
150
|
+
held += 1;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
118
153
|
if (state && BLOCKED.has(state)) {
|
|
119
154
|
const cls = classifyBlocked(row);
|
|
120
155
|
blockedCounts.set(cls, (blockedCounts.get(cls) ?? 0) + 1);
|
|
121
156
|
continue;
|
|
122
157
|
}
|
|
158
|
+
if (state === 'stuck' && (row.attempts ?? 0) >= 1) {
|
|
159
|
+
retrying += 1;
|
|
160
|
+
if (retryingFile === undefined || rel < retryingFile.rel) {
|
|
161
|
+
retryingFile = { rel, reason: row.reason ?? 'the last attempt failed' };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
123
164
|
// Outstanding. `size` is the stat cache, so it is what we know rather than
|
|
124
165
|
// what is true — a row we have never stat'd contributes nothing, which is
|
|
125
166
|
// why `bytesRemaining` is documented as best-effort rather than exact.
|
|
@@ -130,7 +171,7 @@ export function computeSeedProgress(input: SeedProgressInput): SeedProgress {
|
|
|
130
171
|
.map(([cls, count]) => ({ class: cls, count }))
|
|
131
172
|
.sort((a, b) => b.count - a.count);
|
|
132
173
|
const blockedTotal = blocked.reduce((n, b) => n + b.count, 0);
|
|
133
|
-
const remaining = Math.max(0, tracked - delivered - blockedTotal);
|
|
174
|
+
const remaining = Math.max(0, tracked - delivered - blockedTotal - held);
|
|
134
175
|
|
|
135
176
|
const paused =
|
|
136
177
|
typeof input.pausedUntil === 'number' && Number.isFinite(input.pausedUntil)
|
|
@@ -152,6 +193,9 @@ export function computeSeedProgress(input: SeedProgressInput): SeedProgress {
|
|
|
152
193
|
tracked,
|
|
153
194
|
delivered,
|
|
154
195
|
remaining,
|
|
196
|
+
held,
|
|
197
|
+
retrying,
|
|
198
|
+
...(retryingFile ? { retryingFile } : {}),
|
|
155
199
|
bytesRemaining,
|
|
156
200
|
blocked,
|
|
157
201
|
...(input.passCapped ? { passCapped: input.passCapped } : {}),
|
|
@@ -246,6 +246,41 @@ export function laneHash(content: string): string {
|
|
|
246
246
|
|
|
247
247
|
export const EMPTY_LANE_HASH = laneHash('');
|
|
248
248
|
|
|
249
|
+
/** #166 R3 — what a read may be bounded by beyond the 20 s transport timeout. */
|
|
250
|
+
export interface ReadLimits {
|
|
251
|
+
/** aborts the read (its fetch and the body still streaming) */
|
|
252
|
+
signal?: AbortSignal;
|
|
253
|
+
/** the body's byte cap, enforced on the stream; past it the body is cancelled and the read refuses */
|
|
254
|
+
maxBytes?: number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* A response body as text, never more than `maxBytes`: a declared length over the cap refuses
|
|
259
|
+
* before reading, and a stream that passes it is cancelled there (a hub can omit the length).
|
|
260
|
+
*/
|
|
261
|
+
async function readCappedText(res: Response, maxBytes: number): Promise<string> {
|
|
262
|
+
const declared = Number(res.headers.get('content-length'));
|
|
263
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
264
|
+
await res.body?.cancel().catch(() => {});
|
|
265
|
+
throw new TransactionError(`read over ${maxBytes} bytes`, 'too-large');
|
|
266
|
+
}
|
|
267
|
+
if (!res.body) return '';
|
|
268
|
+
const reader = res.body.getReader();
|
|
269
|
+
const chunks: Uint8Array[] = [];
|
|
270
|
+
let total = 0;
|
|
271
|
+
for (;;) {
|
|
272
|
+
const { done, value } = await reader.read();
|
|
273
|
+
if (done) break;
|
|
274
|
+
total += value.byteLength;
|
|
275
|
+
if (total > maxBytes) {
|
|
276
|
+
await reader.cancel().catch(() => {});
|
|
277
|
+
throw new TransactionError(`read over ${maxBytes} bytes`, 'too-large');
|
|
278
|
+
}
|
|
279
|
+
chunks.push(value);
|
|
280
|
+
}
|
|
281
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
282
|
+
}
|
|
283
|
+
|
|
249
284
|
export class TransactionError extends Error {
|
|
250
285
|
constructor(
|
|
251
286
|
message: string,
|
|
@@ -315,14 +350,31 @@ export function createTransactionClient(opts: TransactionClientOptions) {
|
|
|
315
350
|
};
|
|
316
351
|
}
|
|
317
352
|
|
|
318
|
-
async function request(
|
|
353
|
+
async function request(
|
|
354
|
+
method: string,
|
|
355
|
+
route: string,
|
|
356
|
+
body?: string,
|
|
357
|
+
format?: number,
|
|
358
|
+
lim: ReadLimits = {}
|
|
359
|
+
) {
|
|
360
|
+
const timeout = AbortSignal.timeout(20_000);
|
|
319
361
|
const res = await fetchImpl(`${base}/api/projects/${projectId ?? 'current'}/v1/${route}`, {
|
|
320
362
|
method,
|
|
321
363
|
headers: headers(format),
|
|
322
364
|
...(body !== undefined ? { body } : {}),
|
|
323
|
-
signal: AbortSignal.timeout
|
|
365
|
+
signal: lim.signal ? AbortSignal.any([timeout, lim.signal]) : timeout,
|
|
324
366
|
});
|
|
325
|
-
|
|
367
|
+
if (lim.maxBytes === undefined) {
|
|
368
|
+
const json = (await res.json().catch(() => null)) as unknown;
|
|
369
|
+
return { status: res.status, json };
|
|
370
|
+
}
|
|
371
|
+
const text = await readCappedText(res, lim.maxBytes);
|
|
372
|
+
let json: unknown = null;
|
|
373
|
+
try {
|
|
374
|
+
json = JSON.parse(text);
|
|
375
|
+
} catch {
|
|
376
|
+
/* not JSON — the caller reads null, as res.json() would */
|
|
377
|
+
}
|
|
326
378
|
return { status: res.status, json };
|
|
327
379
|
}
|
|
328
380
|
|
|
@@ -981,13 +1033,26 @@ export function createTransactionClient(opts: TransactionClientOptions) {
|
|
|
981
1033
|
}
|
|
982
1034
|
}
|
|
983
1035
|
|
|
984
|
-
/**
|
|
985
|
-
|
|
1036
|
+
/**
|
|
1037
|
+
* A read route (`history`, `lane`, `revisions`) — no retry, bounded. #166 R3: `signal` ends a
|
|
1038
|
+
* read its caller stopped waiting for; `maxBytes` caps the body while it streams in.
|
|
1039
|
+
*/
|
|
1040
|
+
async function read(
|
|
1041
|
+
route: string,
|
|
1042
|
+
params: Record<string, string | number>,
|
|
1043
|
+
lim: ReadLimits = {}
|
|
1044
|
+
): Promise<unknown> {
|
|
986
1045
|
if (projectId === null) await bootstrap();
|
|
987
1046
|
const qs = new URLSearchParams(
|
|
988
1047
|
Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
989
1048
|
);
|
|
990
|
-
const { status, json } = await request(
|
|
1049
|
+
const { status, json } = await request(
|
|
1050
|
+
'GET',
|
|
1051
|
+
`${route}?${qs.toString()}`,
|
|
1052
|
+
undefined,
|
|
1053
|
+
undefined,
|
|
1054
|
+
lim
|
|
1055
|
+
);
|
|
991
1056
|
if (status !== 200) throw new TransactionError(`${route} failed (${status})`, 'read');
|
|
992
1057
|
return json;
|
|
993
1058
|
}
|