@1agh/maude 2.0.3 → 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.
Files changed (242) hide show
  1. package/README.md +6 -5
  2. package/apps/hub/src/project-transactions/kernel.mjs +10 -1
  3. package/apps/studio/access/filters.ts +12 -5
  4. package/apps/studio/access/known-canvases.ts +24 -1
  5. package/apps/studio/access/refused-inputs.ts +89 -0
  6. package/apps/studio/access/request.ts +0 -1
  7. package/apps/studio/acp/adapter-stderr.ts +43 -13
  8. package/apps/studio/acp/background-tasks.ts +155 -0
  9. package/apps/studio/acp/bridge.ts +44 -5
  10. package/apps/studio/acp/connected-fact.ts +15 -4
  11. package/apps/studio/acp/index.ts +14 -5
  12. package/apps/studio/actions/agents.ts +10 -0
  13. package/apps/studio/actions/defs/app.ts +12 -0
  14. package/apps/studio/actions/defs/view.ts +12 -0
  15. package/apps/studio/actions.manifest.json +25 -1
  16. package/apps/studio/actions.parity.json +13 -1
  17. package/apps/studio/annotations/ui/element-node.tsx +139 -54
  18. package/apps/studio/annotations/ui/lod.tsx +1 -1
  19. package/apps/studio/annotations/ui/text-style.ts +1 -1
  20. package/apps/studio/annotations-layer.tsx +0 -12
  21. package/apps/studio/api.ts +73 -24
  22. package/apps/studio/artboard-live-gate.tsx +267 -0
  23. package/apps/studio/artboard-live.ts +336 -0
  24. package/apps/studio/artboard-webgl.ts +668 -0
  25. package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
  26. package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
  27. package/apps/studio/bin/_canvas-reasons.mjs +34 -0
  28. package/apps/studio/bin/_ds-check-live.mjs +37 -0
  29. package/apps/studio/bin/_ds-check.mjs +4 -1
  30. package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
  31. package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
  32. package/apps/studio/bin/_import-asset.mjs +2 -1
  33. package/apps/studio/bin/_perf-probe.mjs +2 -1
  34. package/apps/studio/bin/_png-playwright.mjs +10 -1
  35. package/apps/studio/bin/_pw-launch.mjs +14 -0
  36. package/apps/studio/bin/_studio-verb.mjs +24 -3
  37. package/apps/studio/bin/_thumb-blank.mjs +70 -0
  38. package/apps/studio/bin/_thumb-cover.mjs +35 -0
  39. package/apps/studio/bin/_thumbs-playwright.mjs +93 -13
  40. package/apps/studio/bin/ds-check.sh +5 -1
  41. package/apps/studio/bin/perf.sh +11 -1
  42. package/apps/studio/bin/server-up.sh +7 -2
  43. package/apps/studio/bin/smoke.sh +19 -0
  44. package/apps/studio/boot-progress.ts +31 -0
  45. package/apps/studio/canvas-build-sandbox.ts +275 -42
  46. package/apps/studio/canvas-build-worker.ts +10 -0
  47. package/apps/studio/canvas-create.ts +24 -0
  48. package/apps/studio/canvas-lib.tsx +131 -12
  49. package/apps/studio/canvas-module-cache.ts +93 -0
  50. package/apps/studio/canvas-source/errors.ts +39 -0
  51. package/apps/studio/canvas-source/waiting.ts +290 -0
  52. package/apps/studio/client/actions/shell-key-handlers.js +5 -0
  53. package/apps/studio/client/app.jsx +19 -9
  54. package/apps/studio/client/canvas-url.js +13 -0
  55. package/apps/studio/client/github.js +23 -3
  56. package/apps/studio/client/home/HomeAccounts.jsx +262 -0
  57. package/apps/studio/client/home/Shelves.jsx +4 -3
  58. package/apps/studio/client/home/home-accounts-model.js +121 -0
  59. package/apps/studio/client/home/home-api.js +36 -19
  60. package/apps/studio/client/home/home-app.jsx +141 -40
  61. package/apps/studio/client/home/home-model.js +172 -6
  62. package/apps/studio/client/home/home.css +169 -5
  63. package/apps/studio/client/home/shell-mode.js +8 -1
  64. package/apps/studio/client/hooks/use-git-actions.jsx +2 -1
  65. package/apps/studio/client/hooks/use-project-data.jsx +2 -0
  66. package/apps/studio/client/hooks/use-shell-core.jsx +3 -0
  67. package/apps/studio/client/hooks/use-tabs.jsx +64 -35
  68. package/apps/studio/client/index-loader.ts +23 -3
  69. package/apps/studio/client/panels/ChatPanel.jsx +49 -57
  70. package/apps/studio/client/panels/CreateProject.jsx +19 -5
  71. package/apps/studio/client/panels/DiffView.jsx +314 -248
  72. package/apps/studio/client/panels/TeamProjects.jsx +119 -69
  73. package/apps/studio/client/panels/acp-runtime.js +25 -0
  74. package/apps/studio/client/panels/caps-cache.js +46 -0
  75. package/apps/studio/client/panels/chat-finish.js +66 -0
  76. package/apps/studio/client/shell/frame-cap.js +53 -0
  77. package/apps/studio/client/shell/viewport.jsx +45 -8
  78. package/apps/studio/client/styles/_index.css +2 -0
  79. package/apps/studio/client/tree/tree.jsx +48 -21
  80. package/apps/studio/client/v2/access/access-client.js +2 -0
  81. package/apps/studio/client/v2/access/access-host.jsx +12 -1
  82. package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
  83. package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
  84. package/apps/studio/client/v2/ai/BackgroundStrip.jsx +120 -0
  85. package/apps/studio/client/v2/ai/Composer.jsx +27 -10
  86. package/apps/studio/client/v2/ai/StoppedDivider.jsx +2 -1
  87. package/apps/studio/client/v2/ai/ai-run.css +87 -3
  88. package/apps/studio/client/v2/ai/background-model.js +113 -0
  89. package/apps/studio/client/v2/ai/needs-you-store.js +2 -1
  90. package/apps/studio/client/v2/ai/run-api.js +7 -3
  91. package/apps/studio/client/v2/ai/runs-store.js +2 -1
  92. package/apps/studio/client/v2/annotations/vote-store.js +11 -5
  93. package/apps/studio/client/v2/assets/asset-state-lane.js +6 -3
  94. package/apps/studio/client/v2/assets/assets-bus.js +10 -8
  95. package/apps/studio/client/v2/assets/browse-view.jsx +2 -0
  96. package/apps/studio/client/v2/assets/ds-library-view.jsx +47 -0
  97. package/apps/studio/client/v2/assets/spotlight-model.js +75 -0
  98. package/apps/studio/client/v2/assets/spotlight.css +153 -0
  99. package/apps/studio/client/v2/assets/spotlight.jsx +199 -0
  100. package/apps/studio/client/v2/assets/tile-menu.jsx +3 -1
  101. package/apps/studio/client/v2/assets/tile.jsx +3 -0
  102. package/apps/studio/client/v2/assets/use-assets.js +2 -1
  103. package/apps/studio/client/v2/canvases/canvases-panel.jsx +13 -2
  104. package/apps/studio/client/v2/canvases/covers.js +11 -5
  105. package/apps/studio/client/v2/canvases/folder-ask.js +139 -0
  106. package/apps/studio/client/v2/canvases/folder-dialogs.jsx +150 -0
  107. package/apps/studio/client/v2/canvases/trash-canvas.js +10 -2
  108. package/apps/studio/client/v2/canvases/trash-queue.js +152 -0
  109. package/apps/studio/client/v2/canvases/use-canvas-index.js +42 -18
  110. package/apps/studio/client/v2/canvases/use-pins.js +2 -1
  111. package/apps/studio/client/v2/code/canvas-error-card.jsx +70 -5
  112. package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
  113. package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
  114. package/apps/studio/client/v2/code/canvas-waiting-card.jsx +128 -0
  115. package/apps/studio/client/v2/code/canvas-waiting.js +164 -0
  116. package/apps/studio/client/v2/code/code-bus.js +5 -0
  117. package/apps/studio/client/v2/code/code.css +67 -0
  118. package/apps/studio/client/v2/code/use-canvas-source.js +19 -4
  119. package/apps/studio/client/v2/create/NameDialog.jsx +4 -2
  120. package/apps/studio/client/v2/create/name-dialog.css +10 -0
  121. package/apps/studio/client/v2/ds/advanced-host.jsx +11 -23
  122. package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
  123. package/apps/studio/client/v2/ds/library-host.jsx +45 -45
  124. package/apps/studio/client/v2/ds/make-host.jsx +13 -12
  125. package/apps/studio/client/v2/ds/off-system-host.jsx +18 -16
  126. package/apps/studio/client/v2/ds/review-host.jsx +7 -1
  127. package/apps/studio/client/v2/ds/truth-host.jsx +15 -14
  128. package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
  129. package/apps/studio/client/v2/empty/arriving.jsx +29 -12
  130. package/apps/studio/client/v2/empty/empty-host.jsx +8 -2
  131. package/apps/studio/client/v2/empty/not-local.jsx +31 -1
  132. package/apps/studio/client/v2/empty/use-empty-canvas.js +10 -1
  133. package/apps/studio/client/v2/export/last-finished.js +2 -1
  134. package/apps/studio/client/v2/history/branch-actions.js +13 -9
  135. package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
  136. package/apps/studio/client/v2/history/git-model.js +21 -5
  137. package/apps/studio/client/v2/history/git-parts.jsx +76 -43
  138. package/apps/studio/client/v2/history/history.css +6 -0
  139. package/apps/studio/client/v2/left-panel/assets-panel.jsx +87 -10
  140. package/apps/studio/client/v2/left-panel/use-trash.js +2 -1
  141. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +100 -33
  142. package/apps/studio/client/v2/onboarding/HubSheet.jsx +51 -83
  143. package/apps/studio/client/v2/onboarding/onboarding-model.js +10 -6
  144. package/apps/studio/client/v2/presence/faces.jsx +42 -14
  145. package/apps/studio/client/v2/present/order-notes-artboards.js +2 -1
  146. package/apps/studio/client/v2/search/search-recent.js +3 -1
  147. package/apps/studio/client/v2/search/search-remote.js +6 -4
  148. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  149. package/apps/studio/client/v2/shell/account-card.jsx +10 -4
  150. package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
  151. package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
  152. package/apps/studio/client/v2/shell/menu-runner.js +12 -0
  153. package/apps/studio/client/v2/shell/occlusion-insets.js +14 -2
  154. package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
  155. package/apps/studio/client/v2/shell/project-account-model.js +182 -0
  156. package/apps/studio/client/v2/shell/recovery-store.js +2 -1
  157. package/apps/studio/client/v2/shell/served-routes.js +120 -0
  158. package/apps/studio/client/v2/shell/share-cluster-host.jsx +139 -11
  159. package/apps/studio/client/v2/shell/share-cluster.css +58 -0
  160. package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
  161. package/apps/studio/client/v2/shell/shell-activity.js +19 -0
  162. package/apps/studio/client/v2/shell/team-switch.js +94 -0
  163. package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
  164. package/apps/studio/client/v2/shell/use-account.js +8 -1
  165. package/apps/studio/client/v2/shell/use-occluded-insets.js +3 -0
  166. package/apps/studio/client/v2/sync-states/conflict-card.jsx +7 -2
  167. package/apps/studio/client/v2/undo/use-undo-projection.jsx +3 -1
  168. package/apps/studio/cloud/endpoints.ts +23 -1
  169. package/apps/studio/collab/persistence.ts +9 -1
  170. package/apps/studio/collab/registry.ts +32 -0
  171. package/apps/studio/collab/room.ts +8 -0
  172. package/apps/studio/config-reload-wire.ts +53 -0
  173. package/apps/studio/dist/client.bundle.js +1098 -1102
  174. package/apps/studio/dist/styles.css +1 -1
  175. package/apps/studio/ds/board/specimen.tsx +12 -1
  176. package/apps/studio/ds/canvas-cli.ts +58 -2
  177. package/apps/studio/ds/check.ts +26 -1
  178. package/apps/studio/ds/cli.ts +7 -3
  179. package/apps/studio/ds/convert.ts +34 -6
  180. package/apps/studio/ds/ds-verb.ts +13 -0
  181. package/apps/studio/ds/post-build.ts +38 -0
  182. package/apps/studio/ds/upgrade-apply.ts +27 -5
  183. package/apps/studio/ds/upgrade-cli.ts +22 -2
  184. package/apps/studio/ds/upgrade-prove.ts +198 -15
  185. package/apps/studio/ds/upgrade-stage.ts +4 -1
  186. package/apps/studio/editing/minimap-context.tsx +3 -3
  187. package/apps/studio/editing/page-activity.ts +251 -0
  188. package/apps/studio/editing/rotate-handle.tsx +9 -5
  189. package/apps/studio/editing/sticky-name.tsx +4 -4
  190. package/apps/studio/history/restore-artboard-action.ts +40 -0
  191. package/apps/studio/history/trash.ts +6 -0
  192. package/apps/studio/home/accounts.ts +87 -0
  193. package/apps/studio/home/hub.ts +77 -175
  194. package/apps/studio/home/index-reader.ts +24 -2
  195. package/apps/studio/home/routes.ts +66 -8
  196. package/apps/studio/http.ts +131 -68
  197. package/apps/studio/index-flight.ts +40 -0
  198. package/apps/studio/managed-projects.ts +52 -24
  199. package/apps/studio/migrate/hub.ts +7 -1
  200. package/apps/studio/routes/canvas-source.ts +44 -2
  201. package/apps/studio/routes/ds-convert.ts +18 -0
  202. package/apps/studio/routes/history.ts +28 -5
  203. package/apps/studio/routes/hub-signin.ts +115 -0
  204. package/apps/studio/routes/index.ts +4 -0
  205. package/apps/studio/routes/table.ts +7 -0
  206. package/apps/studio/routes/trash.ts +19 -1
  207. package/apps/studio/server.ts +19 -10
  208. package/apps/studio/sync/accepted-cold-start.ts +54 -16
  209. package/apps/studio/sync/accepted-link.ts +9 -4
  210. package/apps/studio/sync/asset-push.ts +146 -23
  211. package/apps/studio/sync/asset-state.ts +3 -2
  212. package/apps/studio/sync/code-module-consent.ts +74 -0
  213. package/apps/studio/sync/file-ledger.ts +35 -0
  214. package/apps/studio/sync/file-membership.ts +28 -3
  215. package/apps/studio/sync/file-plane.ts +483 -86
  216. package/apps/studio/sync/file-pull.ts +304 -33
  217. package/apps/studio/sync/hub-browser-signin.ts +377 -0
  218. package/apps/studio/sync/hub-link.ts +1 -2
  219. package/apps/studio/sync/hub-text-undo.ts +30 -10
  220. package/apps/studio/sync/index.ts +381 -161
  221. package/apps/studio/sync/journal-client.ts +94 -5
  222. package/apps/studio/sync/pending-deletes.ts +100 -0
  223. package/apps/studio/sync/projection.ts +121 -14
  224. package/apps/studio/sync/pull-pacer.ts +160 -0
  225. package/apps/studio/sync/pull-priority.ts +119 -0
  226. package/apps/studio/sync/seed-progress.ts +58 -3
  227. package/apps/studio/sync/status.ts +3 -1
  228. package/apps/studio/sync/transaction-client.ts +71 -6
  229. package/apps/studio/sync/workspace-signin.ts +6 -256
  230. package/apps/studio/sync/writer-registry.ts +5 -1
  231. package/apps/studio/thumbs/service.ts +12 -2
  232. package/apps/studio/thumbs/validate.ts +7 -0
  233. package/apps/studio/ui-prefs-migrate.ts +4 -0
  234. package/apps/studio/video-comp.tsx +23 -0
  235. package/apps/studio/video-links-overlay.tsx +3 -2
  236. package/apps/studio/whats-new.json +126 -0
  237. package/cli/lib/bash-guard.mjs +13 -1
  238. package/cli/lib/design-help.gen.mjs +1 -1
  239. package/cli/lib/design-hook.mjs +20 -0
  240. package/cli/lib/studio-locate.mjs +35 -10
  241. package/cli/lib/workspace-plan.mjs +14 -0
  242. package/package.json +8 -8
@@ -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,30 @@ 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
+ /**
99
+ * 2.0.5 — the ledger reason for a file this person deleted here while the project keeps deletes
100
+ * to itself (`linkedHub.propagateDeletes: false`). Neither side will move it, so it is held — and
101
+ * no longer counted as delivered, which the field ledger did for 1 814 files that were not here.
102
+ */
103
+ export const DELETED_HERE_HELD_REASON =
104
+ 'deleted on this Mac — this project does not sync deletions, so the project keeps it and it is not put back here';
105
+
106
+ /** A row the receiver itself refuses, by consent: held, not waiting. */
107
+ export function isHeldByConsent(row: LedgerRow): boolean {
108
+ return (
109
+ row.state === 'stuck' &&
110
+ (row.reason === CODE_MODULE_HELD_REASON || row.reason === DELETED_HERE_HELD_REASON)
111
+ );
112
+ }
113
+
75
114
  /** States that will not move again without something changing. */
76
115
  const BLOCKED: ReadonlySet<DeliveryState> = new Set<DeliveryState>([
77
116
  'refused',
@@ -106,20 +145,33 @@ export function computeSeedProgress(input: SeedProgressInput): SeedProgress {
106
145
  let tracked = 0;
107
146
  let delivered = 0;
108
147
  let bytesRemaining = 0;
148
+ let held = 0;
149
+ let retrying = 0;
150
+ let retryingFile: { rel: string; reason: string } | undefined;
109
151
  const blockedCounts = new Map<BlockedClass, number>();
110
152
 
111
- for (const row of Object.values(rows)) {
153
+ for (const [rel, row] of Object.entries(rows)) {
112
154
  tracked += 1;
113
155
  const state = row.state;
114
156
  if (state && DELIVERED.has(state)) {
115
157
  delivered += 1;
116
158
  continue;
117
159
  }
160
+ if (isHeldByConsent(row)) {
161
+ held += 1;
162
+ continue;
163
+ }
118
164
  if (state && BLOCKED.has(state)) {
119
165
  const cls = classifyBlocked(row);
120
166
  blockedCounts.set(cls, (blockedCounts.get(cls) ?? 0) + 1);
121
167
  continue;
122
168
  }
169
+ if (state === 'stuck' && (row.attempts ?? 0) >= 1) {
170
+ retrying += 1;
171
+ if (retryingFile === undefined || rel < retryingFile.rel) {
172
+ retryingFile = { rel, reason: row.reason ?? 'the last attempt failed' };
173
+ }
174
+ }
123
175
  // Outstanding. `size` is the stat cache, so it is what we know rather than
124
176
  // what is true — a row we have never stat'd contributes nothing, which is
125
177
  // why `bytesRemaining` is documented as best-effort rather than exact.
@@ -130,7 +182,7 @@ export function computeSeedProgress(input: SeedProgressInput): SeedProgress {
130
182
  .map(([cls, count]) => ({ class: cls, count }))
131
183
  .sort((a, b) => b.count - a.count);
132
184
  const blockedTotal = blocked.reduce((n, b) => n + b.count, 0);
133
- const remaining = Math.max(0, tracked - delivered - blockedTotal);
185
+ const remaining = Math.max(0, tracked - delivered - blockedTotal - held);
134
186
 
135
187
  const paused =
136
188
  typeof input.pausedUntil === 'number' && Number.isFinite(input.pausedUntil)
@@ -152,6 +204,9 @@ export function computeSeedProgress(input: SeedProgressInput): SeedProgress {
152
204
  tracked,
153
205
  delivered,
154
206
  remaining,
207
+ held,
208
+ retrying,
209
+ ...(retryingFile ? { retryingFile } : {}),
155
210
  bytesRemaining,
156
211
  blocked,
157
212
  ...(input.passCapped ? { passCapped: input.passCapped } : {}),
@@ -165,7 +165,9 @@ export interface FilePlaneStatus {
165
165
  | 'reanchor'
166
166
  | 'code-held'
167
167
  | 'hub-older'
168
- | 'hub-refused';
168
+ | 'hub-refused'
169
+ /** 2.0.5: files the legacy (v1) pull could not save here; retried later, less often. */
170
+ | 'pull-failed';
169
171
  count: number;
170
172
  paths: string[];
171
173
  /** One sentence, in the user's terms, about what is waiting and why. */
@@ -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(method: string, route: string, body?: string, format?: number) {
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(20_000),
365
+ signal: lim.signal ? AbortSignal.any([timeout, lim.signal]) : timeout,
324
366
  });
325
- const json = (await res.json().catch(() => null)) as unknown;
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
- /** A read route (`history`, `lane`, `revisions`) — no retry, bounded. */
985
- async function read(route: string, params: Record<string, string | number>): Promise<unknown> {
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('GET', `${route}?${qs.toString()}`);
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
  }
@@ -1,260 +1,10 @@
1
- // "Sign in to workspace" — Cloud Phase 3 Task 3.
1
+ // What the operator of a team server can see — the disclosure shown where the person is.
2
2
  //
3
- // The Phase-2 hub can authenticate a PERSON (`POST /auth/login` → a scoped,
4
- // expiring peer token). This is the client half: the flow that turns "my
5
- // teammate sent me an address" into a working, synced project without the
6
- // person ever seeing the word "token".
7
- //
8
- // The vocabulary rule is not cosmetic (DDR-193 §5). The persona this product
9
- // lives or dies by is the invited teammate who has never used git. Every string
10
- // on this path says "sign in", "workspace", "project" — never token, never
11
- // repository, never OAuth. A flow that says "paste your bearer token" has
12
- // already told that person the product is not for them.
13
- //
14
- // TOKEN CUSTODY (unchanged from DDR-054 / the phase-29 A2 finding, and the
15
- // reason this file reuses hub-link.ts rather than writing its own storage):
16
- //
17
- // • the health probe is TOKENLESS — a lookalike address must never receive a
18
- // credential;
19
- // • the password goes ONLY to the address the user typed, once, and is never
20
- // stored anywhere, in memory or on disk, after the request;
21
- // • what IS stored is the minted peer token, in `~/.config/maude/hubs.json`
22
- // at mode 0600, keyed by normalized URL — the same store `maude design
23
- // link` writes, so a project opened later just works.
24
- //
25
- // The token now EXPIRES (Phase 2), which changes one thing for the client: a
26
- // sync failure can mean "your session ran out" rather than "something broke",
27
- // and the honest response is to ask the person to sign in again rather than to
28
- // silently retry forever.
29
-
30
- import { saveHubCredential } from './hub-link.ts';
31
- import { normalizeUrl } from './hubs-config.ts';
32
-
33
- const PROBE_TIMEOUT_MS = 4000;
34
- const LOGIN_TIMEOUT_MS = 15_000;
35
-
36
- export interface SignInResult {
37
- status: number;
38
- json:
39
- | {
40
- ok: true;
41
- url: string;
42
- /** Plain-words identity for the UI header — never a token. */
43
- user: { email: string; role: string };
44
- /** ms-epoch. The UI surfaces "signed in until <date>", not a raw number. */
45
- expiresAt: number | null;
46
- version: string | null;
47
- }
48
- | { ok: false; error: string; reason?: SignInFailure };
49
- }
50
-
51
- export type SignInFailure =
52
- | 'bad-address'
53
- | 'unreachable'
54
- | 'not-a-maude-workspace'
55
- | 'bad-credentials'
56
- | 'cloud-identity'
57
- | 'rate-limited'
58
- | 'save-failed'
59
- | 'server-error';
60
-
61
- export interface SignInInput {
62
- url?: unknown;
63
- email?: unknown;
64
- password?: unknown;
65
- }
66
-
67
- /** Injected in tests. */
68
- export interface SignInDeps {
69
- fetchImpl?: typeof fetch;
70
- save?: (
71
- normUrl: string,
72
- token: string,
73
- role?: string,
74
- expiresAt?: number,
75
- /** the account the workspace vouched (`user.email`), for "Signed in as" */
76
- account?: string
77
- ) => void;
78
- }
79
-
80
- /**
81
- * Address → reachability → sign in → credential stored. One call, because the
82
- * person doing this is not debugging a network stack; they were sent a link.
83
- */
84
- export async function signInToWorkspace(
85
- input: SignInInput,
86
- deps: SignInDeps = {}
87
- ): Promise<SignInResult> {
88
- const doFetch = deps.fetchImpl ?? fetch;
89
- const save =
90
- deps.save ??
91
- ((u: string, t: string, r?: string, e?: number, a?: string) =>
92
- saveHubCredential(u, t, r, e, undefined, a));
93
-
94
- if (typeof input.url !== 'string' || !input.url.trim()) {
95
- return fail(400, 'Enter the workspace address your team sent you.', 'bad-address');
96
- }
97
- if (typeof input.email !== 'string' || !input.email.trim()) {
98
- return fail(400, 'Enter your email address.', 'bad-credentials');
99
- }
100
- if (typeof input.password !== 'string' || input.password === '') {
101
- return fail(400, 'Enter your password.', 'bad-credentials');
102
- }
103
-
104
- let norm: string;
105
- try {
106
- norm = normalizeUrl(input.url.trim());
107
- const parsed = new URL(norm);
108
- if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
109
- return fail(400, 'The workspace address must start with http:// or https://.', 'bad-address');
110
- }
111
- } catch {
112
- return fail(400, "That doesn't look like a workspace address.", 'bad-address');
113
- }
114
-
115
- // 1. TOKENLESS reachability probe. Also tells us it is a Maude workspace at
116
- // all, so a typo'd address fails here with a sentence a person can act on
117
- // instead of failing later as a mysterious auth error.
118
- const probe = await probe200(doFetch, `${norm}/health`, PROBE_TIMEOUT_MS);
119
- if (!probe.reached) {
120
- return fail(
121
- 502,
122
- "Couldn't reach that workspace. Check the address, or ask whoever invited you whether it's online.",
123
- 'unreachable'
124
- );
125
- }
126
- if (!probe.isMaude) {
127
- return fail(
128
- 502,
129
- "That address answered, but it isn't a Maude workspace. Double-check the link you were sent.",
130
- 'not-a-maude-workspace'
131
- );
132
- }
133
-
134
- // 2. Sign in. The password goes to this address once and is never retained.
135
- let res: Response;
136
- try {
137
- const ctrl = new AbortController();
138
- const timer = setTimeout(() => ctrl.abort(), LOGIN_TIMEOUT_MS);
139
- try {
140
- res = await doFetch(`${norm}/auth/login`, {
141
- method: 'POST',
142
- headers: { 'Content-Type': 'application/json' },
143
- body: JSON.stringify({ email: input.email.trim(), password: input.password }),
144
- signal: ctrl.signal,
145
- });
146
- } finally {
147
- clearTimeout(timer);
148
- }
149
- } catch {
150
- return fail(502, "Couldn't reach that workspace to sign in.", 'unreachable');
151
- }
152
-
153
- if (res.status === 401) {
154
- // The hub deliberately cannot tell us WHICH part was wrong (it refuses to be
155
- // a user-existence oracle), so neither can we. Saying "wrong password" when
156
- // the account may not exist would be a guess presented as fact.
157
- return fail(401, 'That email and password combination was not accepted.', 'bad-credentials');
158
- }
159
- if (res.status === 429) {
160
- return fail(429, 'Too many attempts. Wait a minute and try again.', 'rate-limited');
161
- }
162
- if (res.status === 400) {
163
- // The ONE refusal that comes with directions (Phase 23 B3): a cloud
164
- // workspace saying "this door signs in through Maude Cloud" — or a viewer
165
- // being told what viewing needs. Swallowing it into "try again shortly"
166
- // turned the most actionable message on this path into a shrug.
167
- let message = 'The workspace refused the sign-in.';
168
- try {
169
- const body = (await res.json()) as { error?: unknown };
170
- if (typeof body.error === 'string' && body.error) message = body.error;
171
- } catch {
172
- /* keep the generic sentence */
173
- }
174
- return fail(400, message, 'cloud-identity');
175
- }
176
- if (!res.ok) {
177
- return fail(502, 'The workspace refused the sign-in. Try again shortly.', 'server-error');
178
- }
179
-
180
- let body: {
181
- token?: unknown;
182
- expiresAt?: unknown;
183
- user?: { email?: unknown; role?: unknown };
184
- };
185
- try {
186
- body = (await res.json()) as typeof body;
187
- } catch {
188
- return fail(502, 'The workspace sent an unexpected reply.', 'server-error');
189
- }
190
- if (typeof body.token !== 'string' || !body.token) {
191
- return fail(502, 'The workspace sent an unexpected reply.', 'server-error');
192
- }
193
-
194
- // 3. Persist ONLY the minted token, 0600, in the shared credential store —
195
- // plus the role the workspace vouched for (Cloud Phase 25 C2), so a
196
- // viewer is known to be one at BOOT. Learning it from the first refusal
197
- // instead means showing somebody an editor and then taking it away.
198
- const vouchedRole = typeof body.user?.role === 'string' ? body.user.role : 'member';
199
- // …and WHEN it dies. The expiry was already read (it is echoed to the UI
200
- // below) — discarding it from the store is what left the sync runtime
201
- // with no deadline to renew against.
202
- const expiresAt = typeof body.expiresAt === 'number' ? body.expiresAt : undefined;
203
- try {
204
- const account = typeof body.user?.email === 'string' ? body.user.email : undefined;
205
- save(norm, body.token, vouchedRole, expiresAt, account);
206
- } catch {
207
- return fail(500, "Couldn't save the workspace connection on this computer.", 'save-failed');
208
- }
209
-
210
- return {
211
- status: 200,
212
- json: {
213
- ok: true,
214
- url: norm,
215
- user: {
216
- email: typeof body.user?.email === 'string' ? body.user.email : String(input.email).trim(),
217
- role: vouchedRole,
218
- },
219
- expiresAt: expiresAt ?? null,
220
- version: probe.version,
221
- },
222
- };
223
- }
224
-
225
- function fail(status: number, error: string, reason: SignInFailure): SignInResult {
226
- return { status, json: { ok: false, error, reason } };
227
- }
228
-
229
- async function probe200(
230
- doFetch: typeof fetch,
231
- url: string,
232
- timeoutMs: number
233
- ): Promise<{ reached: boolean; isMaude: boolean; version: string | null }> {
234
- const ctrl = new AbortController();
235
- const timer = setTimeout(() => ctrl.abort(), timeoutMs);
236
- try {
237
- const res = await doFetch(url, { signal: ctrl.signal });
238
- if (!res.ok) return { reached: true, isMaude: false, version: null };
239
- try {
240
- const j = (await res.json()) as { ok?: unknown; version?: unknown };
241
- // A Maude hub's /health always carries `ok`. Anything else answered on
242
- // that path is some other service.
243
- const isMaude = j?.ok === true;
244
- return {
245
- reached: true,
246
- isMaude,
247
- version: typeof j?.version === 'string' ? j.version : null,
248
- };
249
- } catch {
250
- return { reached: true, isMaude: false, version: null };
251
- }
252
- } catch {
253
- return { reached: false, isMaude: false, version: null };
254
- } finally {
255
- clearTimeout(timer);
256
- }
257
- }
3
+ // This file used to hold "Sign in to workspace" too: an address, an email and a password, posted to
4
+ // the hub's `/auth/login`. Issue #204 retired it — the desktop owns no login method for a team
5
+ // server. A team server is signed in to on its OWN page (`routes/hub-signin.ts`,
6
+ // `sync/hub-browser-signin.ts`: a one-time code comes back, the token is stored), and the one
7
+ // fallback is a pasted access token (`/_api/hub/link`). Only the disclosure stays here.
258
8
 
259
9
  // ---------------------------------------------------------------- disclosure
260
10
 
@@ -552,7 +552,11 @@ export const WRITER_REGISTRY: Record<string, WriterEntry> = {
552
552
  '/_api/tree-state': { class: 'local' },
553
553
  '/_api/ui-prefs': { class: 'local' },
554
554
  '/_api/workspace/disclosure': { class: 'local' },
555
- '/_api/workspace/sign-in': { class: 'local' },
555
+ // Issue #204 — the team-server browser sign-in: a credential in this Mac's hubs.json
556
+ '/_api/hub-signin/start': { class: 'local' },
557
+ '/_api/hub-signin/poll': { class: 'local' },
558
+ '/_api/hub-signin/cancel': { class: 'local' },
559
+ '/_api/hub-signin/return': { class: 'local' },
556
560
  // --- the V2-2.5 table (routes/*.ts) — classified by the lead (decision v2-2.5 classification)
557
561
  '/_api/outbox': { class: 'read' }, // routes/outbox.ts: the queue's view
558
562
  '/_api/outbox/:id': { class: 'read' },
@@ -44,7 +44,7 @@ import {
44
44
  versionLaneHashes,
45
45
  } from './keys.ts';
46
46
  import { hasThumb, pruneThumbs, readThumb, writeThumb } from './store.ts';
47
- import { checkJpeg, jpegSize } from './validate.ts';
47
+ import { checkJpeg, coverWorthy, jpegSize } from './validate.ts';
48
48
 
49
49
  export type ThumbAt = 'now' | { rev: number } | { sha: string };
50
50
  export interface ThumbRequest {
@@ -517,11 +517,18 @@ export function createThumbService(o: ThumbServiceOptions): ThumbService {
517
517
  }
518
518
  }
519
519
 
520
+ /** A canvas's whole-canvas picture (its Home cover) — what W5's blank / sliver checks are for. */
521
+ const isCover = (job: Job, t: Target): boolean => job.kind === 'canvas' && t.artboard === null;
522
+
520
523
  function store(job: Job, t: Target, b64: unknown): boolean {
521
524
  if (typeof b64 !== 'string' || b64.length > 2 * 1024 * 1024) return false;
522
525
  const bytes = Uint8Array.from(Buffer.from(b64, 'base64'));
523
526
  const check = checkJpeg(bytes, t.px);
524
527
  if (!check.ok) return false;
528
+ // W5: a cover is shown at ~16:10 on Home — a sliver (a header strip, a 3320 x 200 artboard) or a
529
+ // thumbnail under the floor is not a cover. Not stored; Home keeps its placeholder. A canvas COVER
530
+ // only: an asset tile (also artboard-less) is the picture itself, whatever its shape.
531
+ if (isCover(job, t) && !coverWorthy(check.w, check.h)) return false;
525
532
  writeThumb(o.pid, t.key, bytes);
526
533
  dims.set(t.key, { w: check.w, h: check.h });
527
534
  reference(t.key);
@@ -626,7 +633,10 @@ export function createThumbService(o: ThumbServiceOptions): ThumbService {
626
633
  noArtboard.add(t.key);
627
634
  continue;
628
635
  }
629
- if (!shot || !store(job, t, shot.jpeg)) fail(t.key);
636
+ // W5: a flat-colour cover (the renderer looked at its pixels) is a miss like any other failure —
637
+ // a canvas cover only; a tile of a flat picture is that picture
638
+ if (!shot || (isCover(job, t) && shot.blank === true) || !store(job, t, shot.jpeg))
639
+ fail(t.key);
630
640
  else if (shot.partial === true) partial = true;
631
641
  }
632
642
  if (partial && !job.retryOfPartial)
@@ -60,3 +60,10 @@ export function checkJpeg(b: Uint8Array | null | undefined, px: number): JpegChe
60
60
  if (size.w > px + 1 || size.h > px + 1) return { ok: false, reason: 'too-big' };
61
61
  return { ok: true, ...size };
62
62
  }
63
+
64
+ /** The smallest side and the longest aspect a stored COVER may have (W5): below 48 px or more than 10 : 1
65
+ * it is a strip of a header, not a picture of the canvas. Applies to cover targets only. */
66
+ export const MIN_COVER_PX = 48;
67
+ export const MAX_COVER_ASPECT = 10;
68
+ export const coverWorthy = (w: number, h: number): boolean =>
69
+ Math.min(w, h) >= MIN_COVER_PX && Math.max(w, h) / Math.min(w, h) <= MAX_COVER_ASPECT;