@1agh/maude 2.0.4 → 2.0.6
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/apps/hub/src/project-transactions/kernel.mjs +10 -1
- package/apps/studio/access/filters.ts +12 -5
- package/apps/studio/access/known-canvases.ts +24 -1
- package/apps/studio/access/refused-inputs.ts +89 -0
- package/apps/studio/actions/agents.ts +5 -0
- package/apps/studio/actions/defs/app.ts +12 -0
- package/apps/studio/actions.manifest.json +13 -1
- package/apps/studio/actions.parity.json +7 -1
- package/apps/studio/annotations/ui/element-node.tsx +139 -54
- package/apps/studio/annotations/ui/lod.tsx +1 -1
- package/apps/studio/annotations/ui/text-style.ts +1 -1
- package/apps/studio/annotations-layer.tsx +0 -12
- package/apps/studio/api.ts +42 -0
- package/apps/studio/artboard-live-gate.tsx +267 -0
- package/apps/studio/artboard-live.ts +336 -0
- package/apps/studio/artboard-webgl.ts +668 -0
- package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
- package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
- package/apps/studio/bin/_canvas-reasons.mjs +34 -0
- package/apps/studio/bin/_ds-check-live.mjs +37 -0
- package/apps/studio/bin/_ds-check.mjs +4 -1
- package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
- package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
- package/apps/studio/bin/_import-asset.mjs +2 -1
- package/apps/studio/bin/_perf-probe.mjs +2 -1
- package/apps/studio/bin/_studio-verb.mjs +24 -3
- package/apps/studio/bin/_thumb-blank.mjs +70 -0
- package/apps/studio/bin/_thumb-cover.mjs +35 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +89 -12
- package/apps/studio/bin/ds-check.sh +5 -1
- package/apps/studio/bin/perf.sh +11 -1
- package/apps/studio/bin/server-up.sh +7 -2
- package/apps/studio/bin/smoke.sh +19 -0
- package/apps/studio/canvas-lib.tsx +131 -12
- package/apps/studio/client/canvas-url.js +13 -0
- package/apps/studio/client/home/HomeAccounts.jsx +262 -0
- package/apps/studio/client/home/Shelves.jsx +4 -3
- package/apps/studio/client/home/home-accounts-model.js +121 -0
- package/apps/studio/client/home/home-api.js +6 -0
- package/apps/studio/client/home/home-app.jsx +141 -40
- package/apps/studio/client/home/home-model.js +172 -6
- package/apps/studio/client/home/home.css +169 -5
- package/apps/studio/client/home/shell-mode.js +8 -1
- package/apps/studio/client/hooks/use-project-data.jsx +2 -0
- package/apps/studio/client/panels/ChatPanel.jsx +27 -20
- package/apps/studio/client/panels/CreateProject.jsx +19 -5
- package/apps/studio/client/panels/caps-cache.js +46 -0
- package/apps/studio/client/shell/viewport.jsx +36 -8
- package/apps/studio/client/v2/access/access-client.js +2 -0
- package/apps/studio/client/v2/access/access-host.jsx +12 -1
- package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
- package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
- package/apps/studio/client/v2/ai/Composer.jsx +27 -10
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
- package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
- package/apps/studio/client/v2/code/code-bus.js +5 -0
- package/apps/studio/client/v2/ds/advanced-host.jsx +11 -26
- package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
- package/apps/studio/client/v2/ds/library-host.jsx +45 -45
- package/apps/studio/client/v2/ds/make-host.jsx +13 -15
- package/apps/studio/client/v2/ds/off-system-host.jsx +18 -19
- package/apps/studio/client/v2/ds/review-host.jsx +7 -1
- package/apps/studio/client/v2/ds/truth-host.jsx +15 -17
- package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
- package/apps/studio/client/v2/history/branch-actions.js +13 -9
- package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
- package/apps/studio/client/v2/history/git-model.js +3 -1
- package/apps/studio/client/v2/history/git-parts.jsx +16 -1
- package/apps/studio/client/v2/presence/faces.jsx +42 -14
- package/apps/studio/client/v2/shell/account-card.jsx +10 -4
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
- package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
- package/apps/studio/client/v2/shell/menu-runner.js +11 -0
- package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
- package/apps/studio/client/v2/shell/project-account-model.js +182 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +137 -10
- package/apps/studio/client/v2/shell/share-cluster.css +58 -0
- package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
- package/apps/studio/client/v2/shell/team-switch.js +94 -0
- package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
- package/apps/studio/client/v2/shell/use-account.js +8 -1
- package/apps/studio/collab/persistence.ts +9 -1
- package/apps/studio/collab/registry.ts +32 -0
- package/apps/studio/collab/room.ts +8 -0
- package/apps/studio/config-reload-wire.ts +53 -0
- package/apps/studio/dist/client.bundle.js +1232 -1232
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/specimen.tsx +12 -1
- package/apps/studio/ds/canvas-cli.ts +58 -2
- package/apps/studio/ds/check.ts +26 -1
- package/apps/studio/ds/cli.ts +7 -3
- package/apps/studio/ds/convert.ts +34 -6
- package/apps/studio/ds/ds-verb.ts +13 -0
- package/apps/studio/ds/post-build.ts +38 -0
- package/apps/studio/ds/upgrade-apply.ts +27 -5
- package/apps/studio/ds/upgrade-cli.ts +22 -2
- package/apps/studio/ds/upgrade-prove.ts +198 -15
- package/apps/studio/ds/upgrade-stage.ts +4 -1
- package/apps/studio/history/trash.ts +6 -0
- package/apps/studio/home/accounts.ts +87 -0
- package/apps/studio/home/index-reader.ts +24 -2
- package/apps/studio/home/routes.ts +19 -0
- package/apps/studio/http.ts +14 -2
- package/apps/studio/routes/ds-convert.ts +18 -0
- package/apps/studio/routes/trash.ts +16 -1
- package/apps/studio/server.ts +8 -10
- package/apps/studio/sync/accepted-cold-start.ts +28 -13
- package/apps/studio/sync/asset-push.ts +146 -23
- package/apps/studio/sync/asset-state.ts +3 -2
- package/apps/studio/sync/file-membership.ts +28 -3
- package/apps/studio/sync/file-plane.ts +40 -9
- package/apps/studio/sync/file-pull.ts +304 -33
- package/apps/studio/sync/hub-link.ts +1 -2
- package/apps/studio/sync/index.ts +308 -150
- package/apps/studio/sync/journal-client.ts +94 -5
- package/apps/studio/sync/pending-deletes.ts +100 -0
- package/apps/studio/sync/projection.ts +77 -12
- package/apps/studio/sync/seed-progress.ts +12 -1
- package/apps/studio/sync/status.ts +3 -1
- package/apps/studio/thumbs/service.ts +12 -2
- package/apps/studio/thumbs/validate.ts +7 -0
- package/apps/studio/ui-prefs-migrate.ts +4 -0
- package/apps/studio/video-comp.tsx +23 -0
- package/apps/studio/whats-new.json +72 -0
- package/cli/lib/bash-guard.mjs +13 -1
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-hook.mjs +20 -0
- package/cli/lib/studio-locate.mjs +35 -10
- package/package.json +8 -8
|
@@ -6,25 +6,26 @@
|
|
|
6
6
|
// (`/_index-data` `canvasImportsCanvases`, canvas-url.js `canvasImportsOf`) and says so on the stage
|
|
7
7
|
// (shell/viewport.jsx), in place of the generic "can't be drawn" card. What happened · what to do; no
|
|
8
8
|
// action — the fix is in the code (move the shared part into a component file).
|
|
9
|
+
//
|
|
10
|
+
// 2.0.5 (#205): a walk the closure did not block can still be refused AFTER the build, when the module inlined
|
|
11
|
+
// a design-root file the frame does not admit (http.ts `canvasInputsGate`). The server keeps those files per
|
|
12
|
+
// canvas and the index reports them (`canvasRefusedInputs`, canvas-url.js `canvasRefusedOf`): the card names
|
|
13
|
+
// them too — "This canvas uses <file>, which belongs to another canvas."
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const dir =
|
|
14
|
-
String(componentDir || 'ui/components').replace(/^\.?\/+|\/+$/g, '') || 'ui/components';
|
|
15
|
-
return {
|
|
16
|
-
title: names.length
|
|
17
|
-
? `This canvas imports another canvas (${names.join(', ')}).`
|
|
18
|
-
: 'This canvas imports another canvas.',
|
|
19
|
-
body: `Move the shared part into a component file (e.g. ${dir}/…) to render it here.`,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
15
|
+
import { canvasImportsText } from './canvas-imports-words.js';
|
|
16
|
+
|
|
17
|
+
export { canvasImportsText };
|
|
22
18
|
|
|
23
|
-
export function CanvasImportsCard({ imports, componentDir }) {
|
|
24
|
-
const { title, body } = canvasImportsText(imports, componentDir);
|
|
19
|
+
export function CanvasImportsCard({ imports, refused, componentDir }) {
|
|
20
|
+
const { title, also, body } = canvasImportsText(imports, componentDir, refused);
|
|
25
21
|
return (
|
|
26
22
|
<div className="sh-canvas-error-card" data-testid="canvas-imports-card">
|
|
27
23
|
<div className="sh-canvas-error-title">{title}</div>
|
|
24
|
+
{also.map((line) => (
|
|
25
|
+
<div key={line} className="sh-canvas-error-body">
|
|
26
|
+
{line}
|
|
27
|
+
</div>
|
|
28
|
+
))}
|
|
28
29
|
<div className="sh-canvas-error-body">{body}</div>
|
|
29
30
|
</div>
|
|
30
31
|
);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// client/v2/code/canvas-imports-words.js — the words for a canvas whose frame refuses its module because it
|
|
2
|
+
// reaches another canvas's code (gate-b-c4j) or, 2.0.5 (#205), because its built module inlined a file another
|
|
3
|
+
// canvas owns. Pure: the shell's card (canvas-imports-card.jsx), `maude design ds-check` (ds/canvas-cli.ts) and
|
|
4
|
+
// `/design:smoke` (bin/_canvas-reasons.mjs) say the same thing.
|
|
5
|
+
|
|
6
|
+
/** "a.tsx", "a.tsx and b.tsx", "a.tsx, b.tsx and c.tsx" */
|
|
7
|
+
function listWords(names) {
|
|
8
|
+
if (names.length < 2) return names[0] ?? '';
|
|
9
|
+
return `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const namesOf = (list) =>
|
|
13
|
+
Array.isArray(list) ? list.filter((x) => typeof x === 'string' && x) : [];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The card's lines. `imports`: designRoot-relative canvases it imports that the viewer may see (may be empty);
|
|
17
|
+
* `refused` (2.0.5, #205): the design-root files its built module was refused for — a file another canvas owns.
|
|
18
|
+
* `title` is the first reason, `also` the other one (when both are on record), `body` what to do.
|
|
19
|
+
*/
|
|
20
|
+
export function canvasImportsText(imports, componentDir, refused = []) {
|
|
21
|
+
const names = namesOf(imports);
|
|
22
|
+
const uses = namesOf(refused);
|
|
23
|
+
const dir =
|
|
24
|
+
String(componentDir || 'ui/components').replace(/^\.?\/+|\/+$/g, '') || 'ui/components';
|
|
25
|
+
const importsLine = names.length
|
|
26
|
+
? `This canvas imports another canvas (${names.join(', ')}).`
|
|
27
|
+
: 'This canvas imports another canvas.';
|
|
28
|
+
const usesLine = uses.length
|
|
29
|
+
? `This canvas uses ${listWords(uses)}, which ${uses.length > 1 ? 'belong' : 'belongs'} to another canvas.`
|
|
30
|
+
: null;
|
|
31
|
+
const lines = names.length || !usesLine ? [importsLine, usesLine] : [usesLine];
|
|
32
|
+
const [title, ...also] = lines.filter(Boolean);
|
|
33
|
+
return {
|
|
34
|
+
title,
|
|
35
|
+
also,
|
|
36
|
+
body: `Move the shared part into a component file (e.g. ${dir}/…) to render it here.`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The card's words as plain lines (title, the other reason, what to do) — for a terminal or a report. */
|
|
41
|
+
export function canvasImportsLines(imports, componentDir, refused = []) {
|
|
42
|
+
const { title, also, body } = canvasImportsText(imports, componentDir, refused);
|
|
43
|
+
return [title, ...also, body];
|
|
44
|
+
}
|
|
@@ -47,6 +47,11 @@ export function registerErrorCard(handlers) {
|
|
|
47
47
|
return () => cards.delete(key);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** Whether a broken-canvas card is showing (2.0.5: the design-system slow read waits while one is). */
|
|
51
|
+
export function errorCardShown() {
|
|
52
|
+
return cards.size > 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
/** Run `op` ('copy' | 'ask-ai' | 'last-good') on the newest mounted card. @returns whether one answered */
|
|
51
56
|
export function runErrorOp(op) {
|
|
52
57
|
const handlers = [...cards.values()].at(-1);
|
|
@@ -18,18 +18,16 @@
|
|
|
18
18
|
// The system comes from the canvas the person has open, never from a message.
|
|
19
19
|
|
|
20
20
|
import { useEffect, useRef } from 'react';
|
|
21
|
-
import { pacedInterval } from '../../../editing/page-activity.ts';
|
|
22
|
-
import { shellActivity } from '../shell/shell-activity.js';
|
|
23
21
|
import { dispatchCanvasOp } from '../left-panel/left-panel-bus.js';
|
|
24
22
|
import { menuRunner } from '../shell/menu-runner.js';
|
|
25
23
|
import { nativeDoors } from '../shell/native-doors.js';
|
|
26
24
|
import { onDsAdvancedRequest } from './advanced-bus.js';
|
|
27
25
|
import { ADVANCED_WORDS, askAiText, checkToast, revealRel } from './advanced-model.js';
|
|
28
26
|
import { setAdvanced, setAdvancedActions } from './advanced-store.js';
|
|
27
|
+
import { dsRefresh } from './ds-refresh.js';
|
|
29
28
|
import { fetchBoard } from './token-write.js';
|
|
30
29
|
import { ownSystemOf } from './truth-model.js';
|
|
31
30
|
|
|
32
|
-
export const ADVANCED_POLL_MS = 8000;
|
|
33
31
|
const JSON_HEADERS = { 'content-type': 'application/json' };
|
|
34
32
|
const NO_FINDER = 'Open this project in the Mac app to work with its files.';
|
|
35
33
|
|
|
@@ -109,16 +107,9 @@ export async function revealSystem(cfg, ds, doors = nativeDoors()) {
|
|
|
109
107
|
|
|
110
108
|
/**
|
|
111
109
|
* @param {{ cfg: any, activePath: string | null, toast?: (m: string) => void,
|
|
112
|
-
* fetchImpl?: typeof fetch
|
|
110
|
+
* fetchImpl?: typeof fetch }} props
|
|
113
111
|
*/
|
|
114
|
-
export function DsAdvancedHost({
|
|
115
|
-
cfg,
|
|
116
|
-
activePath,
|
|
117
|
-
toast,
|
|
118
|
-
project = '',
|
|
119
|
-
fetchImpl,
|
|
120
|
-
pollMs = ADVANCED_POLL_MS,
|
|
121
|
-
}) {
|
|
112
|
+
export function DsAdvancedHost({ cfg, activePath, toast, project = '', fetchImpl }) {
|
|
122
113
|
const ds = ownSystemOf(activePath, cfg);
|
|
123
114
|
const live = useRef({ cfg, activePath, toast, fetchImpl, project });
|
|
124
115
|
live.current = { cfg, activePath, toast, fetchImpl, project };
|
|
@@ -147,7 +138,7 @@ export function DsAdvancedHost({
|
|
|
147
138
|
[ds]
|
|
148
139
|
);
|
|
149
140
|
|
|
150
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: `ds`
|
|
141
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `ds` is the trigger; the rest rides on `live`
|
|
151
142
|
useEffect(() => {
|
|
152
143
|
if (!ds) {
|
|
153
144
|
setAdvanced(null);
|
|
@@ -159,10 +150,10 @@ export function DsAdvancedHost({
|
|
|
159
150
|
let seq = 0;
|
|
160
151
|
const native = nativeDoors().available;
|
|
161
152
|
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
// the board's facts are read with the files: a write or a redraw can change its name, canvases or modes
|
|
154
|
+
const refresh = async (fetchImpl) => {
|
|
164
155
|
const n = ++seq;
|
|
165
|
-
const got = await loadAdvanced(ds,
|
|
156
|
+
const got = await loadAdvanced(ds, fetchImpl, null);
|
|
166
157
|
if (dead || n !== seq) return;
|
|
167
158
|
if (!got) {
|
|
168
159
|
setAdvanced(null);
|
|
@@ -211,21 +202,15 @@ export function DsAdvancedHost({
|
|
|
211
202
|
},
|
|
212
203
|
});
|
|
213
204
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const stopPoll = pacedInterval(() => refresh(), pollMs, shellActivity());
|
|
217
|
-
const onVisible = () => {
|
|
218
|
-
if (document.visibilityState === 'visible') refresh({ withBoard: true });
|
|
219
|
-
};
|
|
220
|
-
document.addEventListener('visibilitychange', onVisible);
|
|
205
|
+
// 2.0.5: once, then on a write or a return to the window — never on a clock
|
|
206
|
+
const reads = dsRefresh(refresh, { fetchImpl: f });
|
|
221
207
|
return () => {
|
|
222
208
|
dead = true;
|
|
223
|
-
|
|
224
|
-
document.removeEventListener('visibilitychange', onVisible);
|
|
209
|
+
reads.stop();
|
|
225
210
|
setAdvancedActions(null);
|
|
226
211
|
setAdvanced(null);
|
|
227
212
|
};
|
|
228
|
-
}, [ds
|
|
213
|
+
}, [ds]);
|
|
229
214
|
|
|
230
215
|
return null;
|
|
231
216
|
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// client/v2/ds/ds-refresh.js — 2.0.5 (#205): when the shell's design-system hosts read the server.
|
|
2
|
+
//
|
|
3
|
+
// Before, each host (make · truth · advanced · off-system) re-read on its own timer every 2.5–8 s while the
|
|
4
|
+
// window was looked at. On a cell that was ~50 requests a minute per open DS board, each one a closure walk
|
|
5
|
+
// and a system read, and the hub's studio child sat at 1.5 GB / 138 % CPU. Nothing those reads show changes
|
|
6
|
+
// on its own clock: it changes when someone writes, and every write the shell makes says so
|
|
7
|
+
// (DS_STATE_CHANGED, door-write.js), and a write the canvas sees redraws it (`dgn:'loaded'`).
|
|
8
|
+
//
|
|
9
|
+
// So a host reads:
|
|
10
|
+
// - once when it starts (per system),
|
|
11
|
+
// - when the window is looked at again (`visibilitychange` → visible),
|
|
12
|
+
// - when the shell wrote the system (DS_STATE_CHANGED),
|
|
13
|
+
// - when the open canvas has drawn again (`dgn:'loaded'` from its own frame, only with `frameFor`),
|
|
14
|
+
// - when one of `events` (window events the host names — e.g. `maude:ai-runs`, the AI run registry moved) fires,
|
|
15
|
+
// - after a failed read, again after 5 s, 10 s, 20 s … at most 5 min (one success resets it),
|
|
16
|
+
// - and, only with `slowMs`, on ONE slow clock — visible window only, held while the canvas is loading or
|
|
17
|
+
// broken. Only the "changed outside" card needs it (truth-host): a file edited outside Maude has no event; and
|
|
18
|
+
// the upgrade sheet while a check is running (a proof's progress has no push).
|
|
19
|
+
//
|
|
20
|
+
// `load(fetchImpl)` reads through the fetch it is given; a read that throws, or any answer that is not ok, is a
|
|
21
|
+
// failure. The host keeps its own sequence guard; this only decides WHEN.
|
|
22
|
+
|
|
23
|
+
import { errorCardShown } from '../code/code-bus.js';
|
|
24
|
+
import { DS_STATE_CHANGED } from './door-write.js';
|
|
25
|
+
|
|
26
|
+
export const DS_BACKOFF_FIRST_MS = 5_000;
|
|
27
|
+
export const DS_BACKOFF_CAP_MS = 5 * 60_000;
|
|
28
|
+
/** The one slow clock (truth-host's "changed outside" card). */
|
|
29
|
+
export const DS_SLOW_POLL_MS = 60_000;
|
|
30
|
+
|
|
31
|
+
/** The canvas pane is still opening, or shows a broken-canvas card: the slow clock waits. */
|
|
32
|
+
export function canvasPaused(doc = globalThis.document) {
|
|
33
|
+
if (errorCardShown()) return true;
|
|
34
|
+
const state = doc
|
|
35
|
+
?.querySelector?.('main.viewport[data-canvas-state]')
|
|
36
|
+
?.getAttribute?.('data-canvas-state');
|
|
37
|
+
return state === 'loading' || state === 'error';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The delay before the retry after `failures` failed reads in a row (1 → first). */
|
|
41
|
+
export function backoffMs(failures, first = DS_BACKOFF_FIRST_MS, cap = DS_BACKOFF_CAP_MS) {
|
|
42
|
+
if (failures <= 0) return 0;
|
|
43
|
+
return Math.min(cap, first * 2 ** (failures - 1));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {(fetchImpl: typeof fetch) => Promise<unknown>} load
|
|
48
|
+
* @param {{
|
|
49
|
+
* fetchImpl?: () => typeof fetch,
|
|
50
|
+
* slowMs?: number,
|
|
51
|
+
* events?: string[],
|
|
52
|
+
* skipFirst?: boolean,
|
|
53
|
+
* failed?: (res: Response) => boolean,
|
|
54
|
+
* paused?: () => boolean,
|
|
55
|
+
* frameFor?: () => ({ contentWindow?: unknown } | null),
|
|
56
|
+
* firstMs?: number,
|
|
57
|
+
* backoffFirstMs?: number,
|
|
58
|
+
* backoffCapMs?: number,
|
|
59
|
+
* win?: Window,
|
|
60
|
+
* doc?: Document,
|
|
61
|
+
* timers?: { set: typeof setTimeout, clear: typeof clearTimeout },
|
|
62
|
+
* }} [opts]
|
|
63
|
+
* @returns {{ now(): Promise<void>, stop(): void }}
|
|
64
|
+
*/
|
|
65
|
+
export function dsRefresh(load, opts = {}) {
|
|
66
|
+
const win = opts.win ?? globalThis.window;
|
|
67
|
+
const doc = opts.doc ?? globalThis.document;
|
|
68
|
+
const set = opts.timers?.set ?? ((fn, ms) => setTimeout(fn, ms));
|
|
69
|
+
const clear = opts.timers?.clear ?? ((t) => clearTimeout(t));
|
|
70
|
+
const paused = opts.paused ?? (() => canvasPaused(doc));
|
|
71
|
+
const getFetch = opts.fetchImpl ?? (() => globalThis.fetch);
|
|
72
|
+
const slowMs = opts.slowMs ?? 0;
|
|
73
|
+
const failedRes = opts.failed ?? ((res) => !res?.ok);
|
|
74
|
+
const hidden = () => doc?.visibilityState === 'hidden';
|
|
75
|
+
|
|
76
|
+
let dead = false;
|
|
77
|
+
let failures = 0;
|
|
78
|
+
let timer = null;
|
|
79
|
+
|
|
80
|
+
const schedule = (ms, fn) => {
|
|
81
|
+
if (timer !== null) clear(timer);
|
|
82
|
+
timer = ms > 0 ? set(fn, ms) : null;
|
|
83
|
+
};
|
|
84
|
+
const next = () => {
|
|
85
|
+
if (dead) return;
|
|
86
|
+
if (failures > 0)
|
|
87
|
+
return schedule(backoffMs(failures, opts.backoffFirstMs, opts.backoffCapMs), retry);
|
|
88
|
+
if (slowMs > 0) return schedule(slowMs, tick);
|
|
89
|
+
schedule(0);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const now = async () => {
|
|
93
|
+
if (dead || hidden()) return;
|
|
94
|
+
let failed = false;
|
|
95
|
+
const base = getFetch();
|
|
96
|
+
const tracked = async (...args) => {
|
|
97
|
+
try {
|
|
98
|
+
const res = await base(...args);
|
|
99
|
+
if (failedRes(res)) failed = true;
|
|
100
|
+
return res;
|
|
101
|
+
} catch (err) {
|
|
102
|
+
failed = true;
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
await load(tracked);
|
|
108
|
+
} catch {
|
|
109
|
+
failed = true;
|
|
110
|
+
}
|
|
111
|
+
if (dead) return;
|
|
112
|
+
failures = failed ? failures + 1 : 0;
|
|
113
|
+
next();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// a retry waits for a looked-at window: `visibilitychange` reads at once when it is looked at again
|
|
117
|
+
function retry() {
|
|
118
|
+
timer = null;
|
|
119
|
+
if (!hidden()) void now();
|
|
120
|
+
}
|
|
121
|
+
function tick() {
|
|
122
|
+
timer = null;
|
|
123
|
+
if (hidden() || paused()) return next();
|
|
124
|
+
void now();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const onVisible = () => {
|
|
128
|
+
if (doc?.visibilityState === 'visible') void now();
|
|
129
|
+
};
|
|
130
|
+
const onChanged = () => void now();
|
|
131
|
+
const onMessage = (e) => {
|
|
132
|
+
const frame = opts.frameFor?.() ?? null;
|
|
133
|
+
if (!frame || e?.source !== frame.contentWindow) return;
|
|
134
|
+
if (e.data && typeof e.data === 'object' && e.data.dgn === 'loaded') void now();
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
doc?.addEventListener?.('visibilitychange', onVisible);
|
|
138
|
+
win?.addEventListener?.(DS_STATE_CHANGED, onChanged);
|
|
139
|
+
if (opts.frameFor) win?.addEventListener?.('message', onMessage);
|
|
140
|
+
for (const name of opts.events ?? []) win?.addEventListener?.(name, onChanged);
|
|
141
|
+
|
|
142
|
+
let first = null;
|
|
143
|
+
if (opts.skipFirst)
|
|
144
|
+
next(); // the host just read: wait for an event (or the slow clock)
|
|
145
|
+
else if (opts.firstMs && opts.firstMs > 0) first = set(() => void now(), opts.firstMs);
|
|
146
|
+
else void now();
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
now,
|
|
150
|
+
stop() {
|
|
151
|
+
dead = true;
|
|
152
|
+
if (first !== null) clear(first);
|
|
153
|
+
if (timer !== null) clear(timer);
|
|
154
|
+
timer = null;
|
|
155
|
+
doc?.removeEventListener?.('visibilitychange', onVisible);
|
|
156
|
+
win?.removeEventListener?.(DS_STATE_CHANGED, onChanged);
|
|
157
|
+
if (opts.frameFor) win?.removeEventListener?.('message', onMessage);
|
|
158
|
+
for (const name of opts.events ?? []) win?.removeEventListener?.(name, onChanged);
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// ds-many-linked; V2-1.6 §5.14).
|
|
3
3
|
//
|
|
4
4
|
// Mounted once inside DsReviewHost. It
|
|
5
|
-
// - reads which systems are linked (`GET /_api/ds/state`) and asks the library whether it moved: on project open
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
// - reads which systems are linked (`GET /_api/ds/state`) and asks the library whether it moved: on project open,
|
|
6
|
+
// when the window is looked at again and when the shell wrote a system (client/v2/ds/ds-refresh.js — no clock;
|
|
7
|
+
// `POST /_api/ds/library {action:'check'}` — the server bounds it to one hub request per system per
|
|
8
|
+
// 30 minutes anyway). A hub that does not answer (5xx / no answer) is retried after 5 s doubling to 5 min; a
|
|
9
|
+
// refusal (no grant, denied) is an answer, not a failure, and stays quiet until the card is looked at,
|
|
8
10
|
// - keeps the open linked system's card in a tiny store (library-store.js → the inspector's empty place),
|
|
9
11
|
// - answers the registry actions through library-bus.js: `ds.library-link`, `ds.library-update`, `ds.library-unlink`,
|
|
10
12
|
// - runs "Update from <system>? N changes" and then the existing DsReviewSheet, whose Update posts the ONE
|
|
@@ -24,7 +26,6 @@ import {
|
|
|
24
26
|
changeLines,
|
|
25
27
|
dialogTitle,
|
|
26
28
|
isWaiting,
|
|
27
|
-
LIBRARY_CHECK_MS,
|
|
28
29
|
LIBRARY_WORDS,
|
|
29
30
|
linkedRows,
|
|
30
31
|
refusalWords,
|
|
@@ -38,6 +39,7 @@ import {
|
|
|
38
39
|
DsLibraryLink,
|
|
39
40
|
DsLibraryUnlink,
|
|
40
41
|
} from './library-card.jsx';
|
|
42
|
+
import { dsRefresh } from './ds-refresh.js';
|
|
41
43
|
import { onDsLibraryRequest } from './library-bus.js';
|
|
42
44
|
import { setLibrary, setLibraryActions } from './library-store.js';
|
|
43
45
|
import { DsReviewSheet } from './review-sheet.jsx';
|
|
@@ -139,7 +141,7 @@ export async function linkLibrary(url, grant, fetchImpl = globalThis.fetch) {
|
|
|
139
141
|
|
|
140
142
|
/**
|
|
141
143
|
* @param {{ cfg: any, activePath: string | null, toast?: (m: string, ok?: boolean) => void, scope?: string,
|
|
142
|
-
* fetchImpl?: typeof fetch,
|
|
144
|
+
* fetchImpl?: typeof fetch, delayMs?: number, open?: (url: string) => any, canOpen?: (url: string) => boolean }} props
|
|
143
145
|
*/
|
|
144
146
|
export function DsLibraryHost({
|
|
145
147
|
cfg,
|
|
@@ -147,7 +149,6 @@ export function DsLibraryHost({
|
|
|
147
149
|
toast,
|
|
148
150
|
scope = '',
|
|
149
151
|
fetchImpl,
|
|
150
|
-
pollMs = LIBRARY_CHECK_MS,
|
|
151
152
|
delayMs = OPEN_DELAY_MS,
|
|
152
153
|
open = openExternal,
|
|
153
154
|
canOpen = (url) => isDisplayableUrl(url),
|
|
@@ -172,48 +173,47 @@ export function DsLibraryHost({
|
|
|
172
173
|
const openDs = ownSystemOf(activePath, cfg);
|
|
173
174
|
const openRow = rows.find((r) => r.ds === openDs) ?? null;
|
|
174
175
|
|
|
175
|
-
/** The state, then a check of each linked system, then the state again (a check can move `upstreamHead`).
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
176
|
+
/** The state, then a check of each linked system, then the state again (a check can move `upstreamHead`).
|
|
177
|
+
* `fx`: the fetch ds-refresh tracks, so a hub that does not answer backs the next read off. */
|
|
178
|
+
const refresh = useCallback(
|
|
179
|
+
async (fx) => {
|
|
180
|
+
const fetchFn = typeof fx === 'function' ? fx : f();
|
|
181
|
+
const first = await loadLinked(fetchFn);
|
|
182
|
+
setRows(first);
|
|
183
|
+
for (const r of first) {
|
|
184
|
+
const c = await checkLibrary(r.ds, fetchFn);
|
|
185
|
+
if (c.ok) {
|
|
186
|
+
setAccess((a) => ({ ...a, [r.ds]: 'yes' }));
|
|
187
|
+
setErrors((e) => ({ ...e, [r.ds]: null }));
|
|
188
|
+
setUsed((u) => ({ ...u, [r.ds]: c.usedBy }));
|
|
189
|
+
} else if (c.noGrant || c.relink) {
|
|
190
|
+
setAccess((a) => ({ ...a, [r.ds]: c.relink ? 'relink' : 'no' }));
|
|
191
|
+
setErrors((e) => ({ ...e, [r.ds]: null }));
|
|
192
|
+
} else if (c.code === 'ds-library-unreachable' || c.code === 'unreachable') {
|
|
193
|
+
setErrors((e) => ({ ...e, [r.ds]: LIBRARY_WORDS.offline }));
|
|
194
|
+
} else if (c.code === 'ds-library-denied') {
|
|
195
|
+
setErrors((e) => ({ ...e, [r.ds]: LIBRARY_WORDS.denied }));
|
|
196
|
+
}
|
|
192
197
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
setRows(await loadLinked(fetchFn));
|
|
199
|
+
},
|
|
200
|
+
[f]
|
|
201
|
+
);
|
|
196
202
|
|
|
197
|
-
// project open
|
|
198
|
-
//
|
|
203
|
+
// project open (after the first paint), then when the window is looked at again or the shell wrote a system —
|
|
204
|
+
// no clock. A refusal (no grant 409, denied 403) is the library's answer; only a 5xx is a failure to back off.
|
|
205
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `refresh` reads the live ref; the first read is the trigger
|
|
199
206
|
useEffect(() => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const timer = setInterval(go, pollMs);
|
|
211
|
-
return () => {
|
|
212
|
-
dead = true;
|
|
213
|
-
clearTimeout(first);
|
|
214
|
-
clearInterval(timer);
|
|
215
|
-
};
|
|
216
|
-
}, [pollMs, delayMs]);
|
|
207
|
+
const r = dsRefresh(
|
|
208
|
+
async (fx) => {
|
|
209
|
+
// a project with no converted system has no linked library: nothing to read, nothing to ask
|
|
210
|
+
if (!Object.values(live.current.cfg?.dsConverted ?? {}).some((v) => v === true)) return;
|
|
211
|
+
await refresh(fx);
|
|
212
|
+
},
|
|
213
|
+
{ fetchImpl: f, firstMs: delayMs, failed: (res) => res.status >= 500 }
|
|
214
|
+
);
|
|
215
|
+
return () => r.stop();
|
|
216
|
+
}, [delayMs]);
|
|
217
217
|
|
|
218
218
|
// the open linked system: how many updates wait (one read of the review per moved head; never for a Mac without a grant)
|
|
219
219
|
const openHead = openRow?.library?.upstreamHead ?? null;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// folder, the Design system canvas with `ds-dir-*` and seven outlines), then the brief goes to AI through the
|
|
8
8
|
// composer with origin `ds-make` (the person's gesture: every composer gate applies), and the new canvas opens;
|
|
9
9
|
// 3 while the open canvas is the Design system canvas of a system that is being made, reads `GET make-state`
|
|
10
|
-
//
|
|
10
|
+
// when it opens, when the canvas has drawn again and after a write (ds-refresh.js, 2.0.5) and tells the canvas which sections wait, are being drawn or are done
|
|
11
11
|
// (the dgn message `ds-make-states` — to the canvas origin, never `*`);
|
|
12
12
|
// 4 the ready card (13 · ds-make-done): "<name> system is ready." with one button that publishes the first
|
|
13
13
|
// revision and makes it the project's style (`POST … {action:'done'}`, then switch-bus `finishedMaking` so the
|
|
@@ -30,15 +30,12 @@ import {
|
|
|
30
30
|
systemLabelFor,
|
|
31
31
|
systemNameFor,
|
|
32
32
|
} from './make-model.js';
|
|
33
|
-
import {
|
|
34
|
-
import { shellActivity } from '../shell/shell-activity.js';
|
|
33
|
+
import { dsRefresh } from './ds-refresh.js';
|
|
35
34
|
import { DsMakeSheet } from './make-sheet.jsx';
|
|
36
35
|
import { finishMaking, makeSystem, readMakeState, uploadLogo } from './make-write.js';
|
|
37
36
|
import { finishedMaking } from './switch-bus.js';
|
|
38
37
|
import { ownSystemOf } from './truth-model.js';
|
|
39
38
|
|
|
40
|
-
export const MAKE_POLL_MS = 2500;
|
|
41
|
-
|
|
42
39
|
/** How many canvases the project has that a system could learn from (a system's own folder is not one). */
|
|
43
40
|
export function canvasCount(cfg) {
|
|
44
41
|
const root = (cfg?.designRel || '.design').replace(/^\/+|\/+$/g, '');
|
|
@@ -86,9 +83,9 @@ export function MakeReadyBanner({ label, complete, missing, busy = false, note =
|
|
|
86
83
|
|
|
87
84
|
/**
|
|
88
85
|
* @param {{ cfg: any, activePath: string | null, toast?: (m: string) => void, frameFor?: () => (HTMLIFrameElement | null),
|
|
89
|
-
* fetchImpl?: typeof fetch,
|
|
86
|
+
* fetchImpl?: typeof fetch, openSystem?: (ds: string) => void }} props
|
|
90
87
|
*/
|
|
91
|
-
export function DsMakeHost({ cfg, activePath, toast, frameFor, fetchImpl,
|
|
88
|
+
export function DsMakeHost({ cfg, activePath, toast, frameFor, fetchImpl, openSystem }) {
|
|
92
89
|
const [sheet, setSheet] = useState(null); // { project }
|
|
93
90
|
const [state, setState] = useState(null);
|
|
94
91
|
const [finishing, setFinishing] = useState(false);
|
|
@@ -172,9 +169,8 @@ export function DsMakeHost({ cfg, activePath, toast, frameFor, fetchImpl, pollMs
|
|
|
172
169
|
}
|
|
173
170
|
let off = false;
|
|
174
171
|
let was = false;
|
|
175
|
-
const look = async () => {
|
|
176
|
-
|
|
177
|
-
const s = await readMakeState(ds, f());
|
|
172
|
+
const look = async (fetchImpl) => {
|
|
173
|
+
const s = await readMakeState(ds, fetchImpl);
|
|
178
174
|
if (off || !s) return;
|
|
179
175
|
setState(s);
|
|
180
176
|
const sections = sectionsToPost(s);
|
|
@@ -190,14 +186,16 @@ export function DsMakeHost({ cfg, activePath, toast, frameFor, fetchImpl, pollMs
|
|
|
190
186
|
/* the frame went away */
|
|
191
187
|
}
|
|
192
188
|
};
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
// 2.0.5: once, then on a write, a redraw of the canvas or a return to the window — never on a clock
|
|
190
|
+
const reads = dsRefresh(look, {
|
|
191
|
+
fetchImpl: f,
|
|
192
|
+
frameFor: () => live.current.frameFor?.() ?? null,
|
|
193
|
+
});
|
|
196
194
|
return () => {
|
|
197
195
|
off = true;
|
|
198
|
-
|
|
196
|
+
reads.stop();
|
|
199
197
|
};
|
|
200
|
-
}, [ds
|
|
198
|
+
}, [ds]);
|
|
201
199
|
|
|
202
200
|
// 4 — "Use as <name>'s style"
|
|
203
201
|
const label =
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// client/v2/ds/off-system-host.jsx — S10.17: the shell's side of the off-system question (13 · ds-edge-suggest).
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// hand-picked colours on the lines changed since the last commit (`GET /_api/ds/off-system`, the S1 rule of S10 Q12)
|
|
3
|
+
// When a canvas that follows a design system opens, has drawn again, or the system was written (ds-refresh.js,
|
|
4
|
+
// 2.0.5 — never on a clock), it asks the server for the hand-picked colours on the lines changed since the last commit (`GET /_api/ds/off-system`, the S1 rule of S10 Q12)
|
|
5
5
|
// and draws the first one the person has not put away as ONE quiet question. "Use <closest>" is an edit on the element
|
|
6
6
|
// that carries the colour (`ds.use-nearest`, one ⌘Z); "Add it to the system" is a waiting new colour (`ds.add-colour`);
|
|
7
7
|
// "Not now" puts the question away until the canvas is opened again. Mounted once, inside the DS review host.
|
|
@@ -12,12 +12,10 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
12
12
|
import { canvasDsSystem } from '../../canvas-url.js';
|
|
13
13
|
import { EDGE_WORDS, findingKey, nextFinding } from './edge-model.js';
|
|
14
14
|
import { addColourNow, fetchOffSystem, applyNearestNow } from './edge-write.js';
|
|
15
|
-
import {
|
|
16
|
-
import { shellActivity } from '../shell/shell-activity.js';
|
|
15
|
+
import { dsRefresh } from './ds-refresh.js';
|
|
17
16
|
import { OffSystemQuestion } from './off-system.jsx';
|
|
18
17
|
import { openCanvasRel } from './switch-host.jsx';
|
|
19
18
|
|
|
20
|
-
export const OFF_SYSTEM_POLL_MS = 8000;
|
|
21
19
|
/** the first look comes a moment after the canvas opens: the question is a courtesy, never in the way */
|
|
22
20
|
export const OFF_SYSTEM_FIRST_MS = 2500;
|
|
23
21
|
|
|
@@ -32,7 +30,7 @@ export function DsOffSystemHost({
|
|
|
32
30
|
activePath,
|
|
33
31
|
toast,
|
|
34
32
|
fetchImpl,
|
|
35
|
-
|
|
33
|
+
frameFor,
|
|
36
34
|
firstMs = OFF_SYSTEM_FIRST_MS,
|
|
37
35
|
}) {
|
|
38
36
|
const rel = openCanvasRel(activePath, cfg);
|
|
@@ -42,37 +40,38 @@ export function DsOffSystemHost({
|
|
|
42
40
|
const [answer, setAnswer] = useState(null);
|
|
43
41
|
const [, bump] = useState(0);
|
|
44
42
|
const dismissed = useRef(new Set());
|
|
45
|
-
const live = useRef({ toast, fetchImpl });
|
|
46
|
-
live.current = { toast, fetchImpl };
|
|
43
|
+
const live = useRef({ toast, fetchImpl, frameFor });
|
|
44
|
+
live.current = { toast, fetchImpl, frameFor };
|
|
47
45
|
const f = () => live.current.fetchImpl ?? globalThis.fetch;
|
|
48
46
|
const refreshRef = useRef(null);
|
|
49
47
|
|
|
50
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: the canvas and the
|
|
48
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the canvas and the first delay are the triggers
|
|
51
49
|
useEffect(() => {
|
|
52
50
|
dismissed.current = new Set();
|
|
53
51
|
setAnswer(null);
|
|
54
52
|
if (!canvas) return undefined;
|
|
55
53
|
let dead = false;
|
|
56
54
|
let seq = 0;
|
|
57
|
-
const
|
|
58
|
-
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
|
|
55
|
+
const read = async (fetchImpl) => {
|
|
59
56
|
const n = ++seq;
|
|
60
|
-
const got = await fetchOffSystem({ canvas },
|
|
57
|
+
const got = await fetchOffSystem({ canvas }, fetchImpl);
|
|
61
58
|
if (dead || n !== seq) return;
|
|
62
59
|
// a refusal or an unreachable studio says nothing: the question is a courtesy, never an error
|
|
63
60
|
setAnswer(got.ok ? got.answer : null);
|
|
64
61
|
};
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
// 2.0.5: a moment after the canvas opens, then on a redraw, a write or a return to the window
|
|
63
|
+
const reads = dsRefresh(read, {
|
|
64
|
+
fetchImpl: f,
|
|
65
|
+
firstMs,
|
|
66
|
+
frameFor: () => live.current.frameFor?.() ?? null,
|
|
67
|
+
});
|
|
68
|
+
refreshRef.current = reads.now;
|
|
69
69
|
return () => {
|
|
70
70
|
dead = true;
|
|
71
|
-
|
|
72
|
-
stopPoll();
|
|
71
|
+
reads.stop();
|
|
73
72
|
refreshRef.current = null;
|
|
74
73
|
};
|
|
75
|
-
}, [canvas,
|
|
74
|
+
}, [canvas, firstMs]);
|
|
76
75
|
|
|
77
76
|
const finding = nextFinding(answer?.findings, dismissed.current);
|
|
78
77
|
const putAway = useCallback((fd) => {
|