@1agh/maude 2.0.8 → 2.1.1

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 (401) hide show
  1. package/README.md +2 -1
  2. package/apps/hub/src/project-transactions/kernel.mjs +13 -7
  3. package/apps/studio/access/closure.ts +86 -10
  4. package/apps/studio/access/filters.ts +18 -1
  5. package/apps/studio/access/request.ts +8 -0
  6. package/apps/studio/acp/design-write-verb.ts +12 -2
  7. package/apps/studio/acp/env.ts +7 -2
  8. package/apps/studio/acp/index.ts +15 -4
  9. package/apps/studio/acp/login-state.ts +22 -5
  10. package/apps/studio/acp/may-scope.ts +38 -1
  11. package/apps/studio/acp/plugin-bootstrap.ts +13 -1
  12. package/apps/studio/acp/probe.ts +11 -4
  13. package/apps/studio/actions/agents.ts +110 -28
  14. package/apps/studio/actions/canvas-keys.ts +4 -2
  15. package/apps/studio/actions/ctx.ts +3 -0
  16. package/apps/studio/actions/defs/annotation.ts +84 -2
  17. package/apps/studio/actions/defs/app.ts +28 -1
  18. package/apps/studio/actions/defs/edit.ts +13 -0
  19. package/apps/studio/actions/defs/export.ts +12 -0
  20. package/apps/studio/actions/defs/sync.ts +18 -0
  21. package/apps/studio/actions/defs/video.ts +9 -0
  22. package/apps/studio/actions/documents.ts +6 -1
  23. package/apps/studio/actions/keymap.gen.ts +147 -9
  24. package/apps/studio/actions/menu.ts +5 -1
  25. package/apps/studio/actions/types.ts +4 -2
  26. package/apps/studio/actions/verbs.ts +9 -0
  27. package/apps/studio/actions.manifest.json +300 -45
  28. package/apps/studio/actions.parity.json +19 -1
  29. package/apps/studio/ai/save-hold.ts +2 -1
  30. package/apps/studio/ai/write-claim-scope.ts +7 -1
  31. package/apps/studio/ai/write-claim.ts +154 -3
  32. package/apps/studio/annotations/ai-read.ts +42 -6
  33. package/apps/studio/annotations/ai-write.ts +145 -2
  34. package/apps/studio/annotations/board-ops.ts +34 -3
  35. package/apps/studio/annotations/checklist-ops.ts +374 -0
  36. package/apps/studio/annotations/elements/checkitem.model.ts +129 -0
  37. package/apps/studio/annotations/elements/sticky.model.ts +54 -2
  38. package/apps/studio/annotations/ops.ts +30 -0
  39. package/apps/studio/annotations/registry.ts +9 -1
  40. package/apps/studio/annotations/templates.ts +4 -2
  41. package/apps/studio/annotations/text-steps.ts +114 -10
  42. package/apps/studio/annotations/ui/checklist-wire.ts +129 -0
  43. package/apps/studio/annotations/ui/checklist.tsx +429 -0
  44. package/apps/studio/annotations/ui/element-node.tsx +48 -2
  45. package/apps/studio/annotations/ui/template-place.ts +11 -1
  46. package/apps/studio/annotations/v1-adapter.ts +22 -3
  47. package/apps/studio/annotations-context-toolbar.tsx +12 -0
  48. package/apps/studio/annotations-layer.tsx +442 -49
  49. package/apps/studio/annotations-model.ts +4 -2
  50. package/apps/studio/api.ts +148 -21
  51. package/apps/studio/artboard-live-gate.tsx +54 -17
  52. package/apps/studio/artboard-still-persist.ts +166 -0
  53. package/apps/studio/artboard-still-raster.ts +6 -2
  54. package/apps/studio/artboard-still.ts +390 -20
  55. package/apps/studio/asset-added.ts +154 -0
  56. package/apps/studio/asset-details.ts +46 -3
  57. package/apps/studio/asset-origins.ts +5 -3
  58. package/apps/studio/asset-trash.ts +6 -1
  59. package/apps/studio/bin/_agent-browser-safe.mjs +3 -4
  60. package/apps/studio/bin/_annotate-post.mjs +14 -5
  61. package/apps/studio/bin/_audio-search.mjs +8 -2
  62. package/apps/studio/bin/_curl-local.mjs +7 -4
  63. package/apps/studio/bin/_desktop-locate.sh +145 -0
  64. package/apps/studio/bin/_ds-check-live.mjs +2 -1
  65. package/apps/studio/bin/_exports.mjs +38 -2
  66. package/apps/studio/bin/_history.mjs +79 -8
  67. package/apps/studio/bin/_import-asset.mjs +14 -9
  68. package/apps/studio/bin/_import-figma.mjs +510 -98
  69. package/apps/studio/bin/_index-cli.mjs +10 -21
  70. package/apps/studio/bin/_ingest-footage.mjs +24 -6
  71. package/apps/studio/bin/_media-probe.mjs +232 -0
  72. package/apps/studio/bin/_perf-probe-open.mjs +6 -0
  73. package/apps/studio/bin/_perf-probe-safari.mjs +6 -0
  74. package/apps/studio/bin/_perf-probe-studio.mjs +6 -1
  75. package/apps/studio/bin/_perf-probe.mjs +8 -3
  76. package/apps/studio/bin/_perf-sweep-shared.mjs +789 -0
  77. package/apps/studio/bin/_perf-sweep.mjs +240 -0
  78. package/apps/studio/bin/_record-shot.sh +33 -8
  79. package/apps/studio/bin/_screenshot-playwright.mjs +45 -2
  80. package/apps/studio/bin/_studio-verb.mjs +8 -3
  81. package/apps/studio/bin/_thumb-route.mjs +21 -0
  82. package/apps/studio/bin/_thumbs-playwright.mjs +83 -1
  83. package/apps/studio/bin/_transcribe.mjs +22 -6
  84. package/apps/studio/bin/_unsynced-refs.mjs +22 -0
  85. package/apps/studio/bin/_url-guard.mjs +120 -5
  86. package/apps/studio/bin/_url-guard.sh +29 -7
  87. package/apps/studio/bin/_video-limits.mjs +104 -0
  88. package/apps/studio/bin/_video-playwright.mjs +119 -19
  89. package/apps/studio/bin/_video-proxy.mjs +130 -0
  90. package/apps/studio/bin/_write-claim.mjs +38 -16
  91. package/apps/studio/bin/annotate.mjs +12 -2
  92. package/apps/studio/bin/canvas-rects.sh +19 -4
  93. package/apps/studio/bin/chat-open.sh +7 -1
  94. package/apps/studio/bin/draw-proof.sh +6 -2
  95. package/apps/studio/bin/generate.sh +32 -10
  96. package/apps/studio/bin/handoff.sh +2 -2
  97. package/apps/studio/bin/perf.sh +96 -15
  98. package/apps/studio/bin/photo-adjust.sh +6 -3
  99. package/apps/studio/bin/photo-bg-remove.sh +2 -2
  100. package/apps/studio/bin/prep.sh +21 -4
  101. package/apps/studio/bin/read-annotations.mjs +3 -0
  102. package/apps/studio/bin/runtime-health.sh +27 -1
  103. package/apps/studio/bin/screenshot.sh +152 -12
  104. package/apps/studio/bin/server-up.sh +64 -6
  105. package/apps/studio/bin/smoke.sh +43 -8
  106. package/apps/studio/bin/to-lottie.sh +3 -2
  107. package/apps/studio/bin/video-proxy.sh +27 -0
  108. package/apps/studio/bin/visual-sanity.sh +3 -1
  109. package/apps/studio/bridge/dgn-protocol.ts +157 -1
  110. package/apps/studio/bridge/mode-shows.ts +8 -6
  111. package/apps/studio/bridge/still-webp.ts +233 -0
  112. package/apps/studio/build.ts +18 -0
  113. package/apps/studio/canvas-build.ts +93 -11
  114. package/apps/studio/canvas-comment-mount.tsx +53 -8
  115. package/apps/studio/canvas-edit.ts +34 -1
  116. package/apps/studio/canvas-lib-module.ts +210 -0
  117. package/apps/studio/canvas-lib.tsx +3 -12
  118. package/apps/studio/canvas-pipeline.ts +111 -5
  119. package/apps/studio/canvas-shell.tsx +8 -11
  120. package/apps/studio/canvas-theme-pill.tsx +5 -3
  121. package/apps/studio/check/index.ts +12 -5
  122. package/apps/studio/check/video.ts +18 -2
  123. package/apps/studio/client/app.jsx +65 -7
  124. package/apps/studio/client/clipboard-relay.ts +193 -16
  125. package/apps/studio/client/comments-overlay.css +18 -0
  126. package/apps/studio/client/export-center.jsx +30 -0
  127. package/apps/studio/client/generate-dialog.jsx +49 -4
  128. package/apps/studio/client/github.js +7 -0
  129. package/apps/studio/client/home/HomeAccountsRow.jsx +221 -0
  130. package/apps/studio/client/home/HomeConnection.jsx +111 -0
  131. package/apps/studio/client/home/home-accounts-model.js +110 -1
  132. package/apps/studio/client/home/home-api.js +9 -2
  133. package/apps/studio/client/home/home-app.jsx +126 -13
  134. package/apps/studio/client/home/home-model.js +69 -1
  135. package/apps/studio/client/home/home-where-model.js +105 -0
  136. package/apps/studio/client/home/home.css +239 -1
  137. package/apps/studio/client/hooks/use-canvas-bridge.jsx +173 -98
  138. package/apps/studio/client/hooks/use-palette-and-panels.jsx +5 -1
  139. package/apps/studio/client/hooks/use-tabs.jsx +11 -4
  140. package/apps/studio/client/panels/DiffView.jsx +7 -1
  141. package/apps/studio/client/panels/TeamProjects.jsx +137 -134
  142. package/apps/studio/client/panels/chat-context.js +2 -0
  143. package/apps/studio/client/panels/slash-commands.gen.js +13 -13
  144. package/apps/studio/client/selection-scope.js +16 -9
  145. package/apps/studio/client/share-link.js +12 -0
  146. package/apps/studio/client/shell/viewport.jsx +11 -1
  147. package/apps/studio/client/shell-events.js +8 -0
  148. package/apps/studio/client/styles/3-kit-maude-v2.css +16 -0
  149. package/apps/studio/client/styles/_index.css +4 -0
  150. package/apps/studio/client/v2/ai/Feed.jsx +1 -1
  151. package/apps/studio/client/v2/ai/OfferCard.jsx +34 -0
  152. package/apps/studio/client/v2/ai/activity-line.js +54 -1
  153. package/apps/studio/client/v2/ai/ai-offer.js +21 -1
  154. package/apps/studio/client/v2/ai/run-model.js +3 -1
  155. package/apps/studio/client/v2/annotations/vote-store.js +28 -4
  156. package/apps/studio/client/v2/assets/asset-drop-session.js +37 -2
  157. package/apps/studio/client/v2/assets/canvas-drop-catcher.jsx +7 -5
  158. package/apps/studio/client/v2/assets/details-model.js +1 -1
  159. package/apps/studio/client/v2/assets/details.jsx +5 -0
  160. package/apps/studio/client/v2/assets/tile-drag.js +11 -7
  161. package/apps/studio/client/v2/comments/comments-panel.jsx +22 -3
  162. package/apps/studio/client/v2/create/duplicate-done.js +6 -2
  163. package/apps/studio/client/v2/diagnostics/diagnostics-host.jsx +1 -0
  164. package/apps/studio/client/v2/diagnostics/diagnostics-model.js +32 -2
  165. package/apps/studio/client/v2/diagnostics/diagnostics-sheet.jsx +35 -8
  166. package/apps/studio/client/v2/diagnostics/diagnostics.css +34 -0
  167. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +113 -3
  168. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +343 -6
  169. package/apps/studio/client/v2/diagnostics/sync-details/unsynced-refs.js +55 -0
  170. package/apps/studio/client/v2/ds/review.css +1 -1
  171. package/apps/studio/client/v2/export/exports-model.js +7 -0
  172. package/apps/studio/client/v2/export/exports-panel.jsx +1 -0
  173. package/apps/studio/client/v2/export/job-row.jsx +32 -2
  174. package/apps/studio/client/v2/handoff/ready-card.jsx +1 -1
  175. package/apps/studio/client/v2/history/compare-view.jsx +1 -0
  176. package/apps/studio/client/v2/inspector/css-write.js +6 -1
  177. package/apps/studio/client/v2/inspector/frame.jsx +28 -4
  178. package/apps/studio/client/v2/inspector/kinds/clip-model.js +51 -0
  179. package/apps/studio/client/v2/inspector/kinds/clip.jsx +75 -2
  180. package/apps/studio/client/v2/inspector/model.js +21 -0
  181. package/apps/studio/client/v2/inspector/sections/fill.jsx +12 -3
  182. package/apps/studio/client/v2/inspector/sections/recent-colours.js +8 -5
  183. package/apps/studio/client/v2/inspector/view-mode.jsx +11 -1
  184. package/apps/studio/client/v2/link-server/LinkServerDialog.jsx +492 -0
  185. package/apps/studio/client/v2/link-server/LinkServerHost.jsx +42 -0
  186. package/apps/studio/client/v2/link-server/link-server-api.js +142 -0
  187. package/apps/studio/client/v2/link-server/link-server-model.js +438 -0
  188. package/apps/studio/client/v2/link-server/link-server.css +109 -0
  189. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +31 -86
  190. package/apps/studio/client/v2/onboarding/onboarding-model.js +1 -18
  191. package/apps/studio/client/v2/preview/link-follow.js +4 -2
  192. package/apps/studio/client/v2/preview/preview-chrome-host.jsx +16 -6
  193. package/apps/studio/client/v2/search/help-model.js +2 -0
  194. package/apps/studio/client/v2/search/search-keywords.js +3 -2
  195. package/apps/studio/client/v2/settings/account.jsx +4 -2
  196. package/apps/studio/client/v2/settings/advanced-section.jsx +344 -137
  197. package/apps/studio/client/v2/settings/connection-row.jsx +3 -59
  198. package/apps/studio/client/v2/settings/connections-section.jsx +118 -425
  199. package/apps/studio/client/v2/settings/general-section.jsx +155 -24
  200. package/apps/studio/client/v2/settings/project-sync-settings.jsx +4 -3
  201. package/apps/studio/client/v2/settings/reset-section.jsx +14 -3
  202. package/apps/studio/client/v2/settings/settings-card.jsx +142 -0
  203. package/apps/studio/client/v2/settings/settings-cards.js +220 -0
  204. package/apps/studio/client/v2/settings/settings-handlers.js +7 -6
  205. package/apps/studio/client/v2/settings/settings-model.js +100 -31
  206. package/apps/studio/client/v2/settings/settings-sheet.jsx +25 -6
  207. package/apps/studio/client/v2/settings/settings.css +374 -64
  208. package/apps/studio/client/v2/settings/this-project-card.jsx +730 -0
  209. package/apps/studio/client/v2/settings/this-project-model.js +172 -0
  210. package/apps/studio/client/v2/settings/use-connections.js +3 -2
  211. package/apps/studio/client/v2/settings/use-open-card.js +37 -0
  212. package/apps/studio/client/v2/share/share-sheet.jsx +28 -11
  213. package/apps/studio/client/v2/shell/api-session-boot.js +6 -0
  214. package/apps/studio/client/v2/shell/api-session.js +126 -0
  215. package/apps/studio/client/v2/shell/connection-state.js +197 -0
  216. package/apps/studio/client/v2/shell/floating-panels.css +31 -1
  217. package/apps/studio/client/v2/shell/image-pick.js +61 -8
  218. package/apps/studio/client/v2/shell/menu-aim.js +43 -0
  219. package/apps/studio/client/v2/shell/menu-runner.js +25 -7
  220. package/apps/studio/client/v2/shell/occlusion-insets.js +18 -1
  221. package/apps/studio/client/v2/shell/project-account-bus.js +36 -0
  222. package/apps/studio/client/v2/shell/project-account-card.jsx +357 -148
  223. package/apps/studio/client/v2/shell/project-account-model.js +272 -149
  224. package/apps/studio/client/v2/shell/project-account-toast.js +66 -0
  225. package/apps/studio/client/v2/shell/project-account.css +237 -0
  226. package/apps/studio/client/v2/shell/project-pill.jsx +52 -6
  227. package/apps/studio/client/v2/shell/share-cluster-host.jsx +166 -83
  228. package/apps/studio/client/v2/shell/shell-parity.js +3 -2
  229. package/apps/studio/client/v2/shell/shell-parity.json +71 -36
  230. package/apps/studio/client/v2/shell/still-bridge.js +194 -0
  231. package/apps/studio/client/v2/shell/still-store.js +319 -0
  232. package/apps/studio/client/v2/shell/use-account.js +2 -0
  233. package/apps/studio/client/v2/shell/use-tool-panels.js +2 -1
  234. package/apps/studio/client/v2/signin/use-signin.js +1 -1
  235. package/apps/studio/client/v2/timeline/Timeline.jsx +15 -0
  236. package/apps/studio/client/v2/timeline/frame-handle-model.js +142 -0
  237. package/apps/studio/client/v2/timeline/frame-handle.jsx +151 -0
  238. package/apps/studio/clip-ops.ts +126 -8
  239. package/apps/studio/cloud/endpoints.ts +29 -4
  240. package/apps/studio/collab/ai-activity.ts +10 -8
  241. package/apps/studio/collab/awareness-bridge.ts +34 -9
  242. package/apps/studio/collab/index.ts +3 -0
  243. package/apps/studio/collab/registry.ts +41 -10
  244. package/apps/studio/comment-reattach.ts +149 -0
  245. package/apps/studio/comments/mine-stamp.ts +15 -7
  246. package/apps/studio/comments/ops.ts +52 -8
  247. package/apps/studio/comments-overlay.tsx +146 -9
  248. package/apps/studio/dist/client.bundle.js +892 -885
  249. package/apps/studio/dist/comment-mount.js +2 -2
  250. package/apps/studio/dist/styles.css +1 -1
  251. package/apps/studio/dom-selection.ts +87 -18
  252. package/apps/studio/ds/board/directions.css +8 -0
  253. package/apps/studio/ds/board/outline.tsx +16 -0
  254. package/apps/studio/ds/canvas-check.ts +6 -0
  255. package/apps/studio/edit-ops/clip/reframe.ts +19 -3
  256. package/apps/studio/edit-ops/clip-carry.ts +602 -0
  257. package/apps/studio/edit-ops/clipboard.ts +318 -23
  258. package/apps/studio/edit-ops/dispatch.ts +20 -2
  259. package/apps/studio/edit-ops/scope-names.ts +249 -40
  260. package/apps/studio/edit-ops/slot-defaults.ts +3 -0
  261. package/apps/studio/edit-ops/types.ts +6 -0
  262. package/apps/studio/editing/align-bar.tsx +33 -9
  263. package/apps/studio/editing/artboard-actions.ts +5 -0
  264. package/apps/studio/editing/artboard-menu.tsx +6 -2
  265. package/apps/studio/editing/click-to-type.ts +1 -1
  266. package/apps/studio/editing/clip-words.ts +48 -0
  267. package/apps/studio/editing/clipboard.ts +21 -6
  268. package/apps/studio/editing/declared-background.ts +25 -0
  269. package/apps/studio/editing/index.tsx +3 -0
  270. package/apps/studio/editing/object-keys.ts +4 -4
  271. package/apps/studio/editing/object-menu.tsx +13 -3
  272. package/apps/studio/editing/pen/points.tsx +61 -0
  273. package/apps/studio/editing/text-in-place.tsx +11 -0
  274. package/apps/studio/editing/video-frame-handle.tsx +425 -0
  275. package/apps/studio/exporters/capture-prepass.ts +374 -0
  276. package/apps/studio/exporters/degraded.ts +148 -0
  277. package/apps/studio/exporters/hub-render-door.ts +28 -2
  278. package/apps/studio/exporters/index.ts +3 -1
  279. package/apps/studio/exporters/job-budget.ts +93 -0
  280. package/apps/studio/exporters/jobs.ts +215 -28
  281. package/apps/studio/exporters/parity-check.ts +254 -0
  282. package/apps/studio/exporters/remote.ts +209 -15
  283. package/apps/studio/exporters/svg-inline.ts +87 -0
  284. package/apps/studio/exporters/video-render-lib.ts +88 -26
  285. package/apps/studio/exporters/video.ts +29 -6
  286. package/apps/studio/figma/assets.ts +58 -43
  287. package/apps/studio/figma/codegen-fonts.ts +100 -0
  288. package/apps/studio/figma/fig-decode.ts +390 -25
  289. package/apps/studio/figma/fig-kiwi.ts +18 -4
  290. package/apps/studio/figma/fig-vector.ts +59 -3
  291. package/apps/studio/figma/sanitize.ts +2 -0
  292. package/apps/studio/figma/style-map.ts +293 -48
  293. package/apps/studio/figma/to-artboard.ts +455 -69
  294. package/apps/studio/figma/to-strokes.ts +44 -11
  295. package/apps/studio/figma/types.ts +13 -0
  296. package/apps/studio/footage/schema.ts +3 -3
  297. package/apps/studio/generation/adapters/elevenlabs.ts +7 -1
  298. package/apps/studio/generation/adapters/groq.ts +8 -1
  299. package/apps/studio/generation/spend.ts +312 -0
  300. package/apps/studio/generation/types.ts +12 -0
  301. package/apps/studio/handoff/run.ts +1 -1
  302. package/apps/studio/handoff/targets.ts +2 -2
  303. package/apps/studio/handoff/write-scopes.ts +1 -1
  304. package/apps/studio/history/describe-annotations.ts +4 -0
  305. package/apps/studio/home/accounts.ts +30 -11
  306. package/apps/studio/home/cloud.ts +6 -1
  307. package/apps/studio/home/create-local.ts +32 -3
  308. package/apps/studio/home/hub-health.ts +76 -0
  309. package/apps/studio/home/routes.ts +15 -4
  310. package/apps/studio/http.ts +438 -86
  311. package/apps/studio/imported-module-ids.ts +91 -0
  312. package/apps/studio/inspect.ts +2 -0
  313. package/apps/studio/migrate/hub.ts +8 -1
  314. package/apps/studio/notifications.tsx +47 -5
  315. package/apps/studio/paths.ts +10 -1
  316. package/apps/studio/port.ts +3 -2
  317. package/apps/studio/preview/preview-camera.tsx +15 -382
  318. package/apps/studio/readiness.ts +10 -1
  319. package/apps/studio/release-build.ts +51 -0
  320. package/apps/studio/routes/agent.ts +188 -9
  321. package/apps/studio/routes/ai.ts +43 -11
  322. package/apps/studio/routes/annotations.ts +27 -1
  323. package/apps/studio/routes/assets.ts +18 -1
  324. package/apps/studio/routes/canvas-origin.ts +12 -9
  325. package/apps/studio/routes/cloud-move.ts +15 -0
  326. package/apps/studio/routes/edit.ts +3 -0
  327. package/apps/studio/routes/export.ts +51 -0
  328. package/apps/studio/routes/generate.ts +42 -12
  329. package/apps/studio/routes/hub-link-folder.ts +334 -0
  330. package/apps/studio/routes/hub-signin.ts +78 -1
  331. package/apps/studio/routes/index.ts +9 -1
  332. package/apps/studio/routes/shell.ts +217 -5
  333. package/apps/studio/routes/sync.ts +136 -8
  334. package/apps/studio/routes/votes.ts +2 -1
  335. package/apps/studio/schema/annotations.v2.schema.json +143 -1
  336. package/apps/studio/schema/beats.v1.schema.json +1 -1
  337. package/apps/studio/schema/edl.v1.schema.json +1 -1
  338. package/apps/studio/schema/formats.ts +3 -3
  339. package/apps/studio/schema/transcript.v1.schema.json +1 -1
  340. package/apps/studio/server.ts +142 -43
  341. package/apps/studio/shell/api-key.ts +503 -0
  342. package/apps/studio/shell/attest.ts +59 -0
  343. package/apps/studio/shell/capture-url.ts +20 -0
  344. package/apps/studio/shell/cli-yield.ts +276 -0
  345. package/apps/studio/shell/clip-transfer.ts +302 -0
  346. package/apps/studio/shell/key-file.ts +108 -0
  347. package/apps/studio/shell/server-json.ts +75 -0
  348. package/apps/studio/shell/worktree.ts +19 -0
  349. package/apps/studio/spoof-chars.ts +9 -0
  350. package/apps/studio/studio-page-host.ts +1 -1
  351. package/apps/studio/sync/accepted-cold-start.ts +144 -8
  352. package/apps/studio/sync/accepted-link.ts +76 -29
  353. package/apps/studio/sync/action-stage.ts +575 -44
  354. package/apps/studio/sync/adopt-held.ts +85 -0
  355. package/apps/studio/sync/ctl-heal.ts +58 -0
  356. package/apps/studio/sync/file-ledger.ts +38 -4
  357. package/apps/studio/sync/file-membership.ts +16 -1
  358. package/apps/studio/sync/file-plane.ts +289 -22
  359. package/apps/studio/sync/held-deletes.ts +86 -5
  360. package/apps/studio/sync/hub-link.ts +8 -0
  361. package/apps/studio/sync/index.ts +196 -12
  362. package/apps/studio/sync/journal-client.ts +50 -4
  363. package/apps/studio/sync/link-consent.ts +22 -75
  364. package/apps/studio/sync/link-survey.ts +252 -0
  365. package/apps/studio/sync/local-kernel.ts +296 -8
  366. package/apps/studio/sync/projection.ts +22 -3
  367. package/apps/studio/sync/seed-progress.ts +12 -0
  368. package/apps/studio/sync/source-recovery.ts +59 -3
  369. package/apps/studio/sync/status.ts +19 -2
  370. package/apps/studio/sync/unsynced-refs.ts +397 -0
  371. package/apps/studio/sync/writer-registry.ts +20 -0
  372. package/apps/studio/thumbs/service.ts +4 -1
  373. package/apps/studio/tool-palette.tsx +23 -0
  374. package/apps/studio/ui-prefs.ts +40 -0
  375. package/apps/studio/use-agent-presence.tsx +2 -2
  376. package/apps/studio/use-canvas-keys.ts +6 -1
  377. package/apps/studio/video/format-ids.ts +2 -2
  378. package/apps/studio/video/inject.ts +31 -0
  379. package/apps/studio/video/media-risk.ts +58 -0
  380. package/apps/studio/video/object-fit.ts +137 -0
  381. package/apps/studio/video/provider-transcript.ts +141 -0
  382. package/apps/studio/whats-new.json +137 -0
  383. package/apps/studio/workspace-mode.ts +1 -0
  384. package/apps/studio/ws.ts +5 -0
  385. package/cli/commands/design.mjs +119 -8
  386. package/cli/lib/bash-guard.mjs +366 -6
  387. package/cli/lib/confine-read.mjs +1 -0
  388. package/cli/lib/design-help.gen.mjs +3 -2
  389. package/cli/lib/design-hook.mjs +387 -81
  390. package/cli/lib/design-link.mjs +16 -1
  391. package/cli/lib/design-open.mjs +49 -3
  392. package/cli/lib/desktop-locate.mjs +770 -0
  393. package/cli/lib/handoff.mjs +1 -1
  394. package/cli/lib/hook-state.mjs +291 -0
  395. package/cli/lib/pkg-root.mjs +65 -13
  396. package/cli/lib/studio-locate.mjs +59 -16
  397. package/package.json +15 -8
  398. package/plugins/design/templates/_shell.html +13 -0
  399. package/apps/studio/client/v2/onboarding/HubSheet.jsx +0 -212
  400. package/apps/studio/client/v2/shell/account-card-model.js +0 -114
  401. package/apps/studio/client/v2/shell/account-card.jsx +0 -189
@@ -63,11 +63,25 @@ export interface JournalPage {
63
63
  * project OWNER only. Absent for everyone else (and from an older hub); an
64
64
  * empty list from the hub is "nothing is held".
65
65
  */
66
- held?: { count: number; paths: { path: string; reason: HeldReason }[] };
66
+ held?: {
67
+ count: number;
68
+ paths: HeldEntry[];
69
+ /** #167 T5.3 — the hub's list may be short (its hold cap or a cut walk): more are held. */
70
+ overflow?: true;
71
+ };
67
72
  }
68
73
 
69
74
  export type HeldReason = 'canvas-before-folders' | 'changed-as-canvas';
70
75
 
76
+ /** One held file. `sha256` + `size` name the version on the hub (additive): "Adopt as code" sends the
77
+ * sha back and the hub adopts only those bytes. Absent from an older hub — that row has no button. */
78
+ export interface HeldEntry {
79
+ path: string;
80
+ reason: HeldReason;
81
+ sha256?: string;
82
+ size?: number;
83
+ }
84
+
71
85
  /** How many held paths one page may carry here (the hub sends at most 200). */
72
86
  const MAX_HELD = 200;
73
87
 
@@ -78,7 +92,7 @@ const MAX_HELD = 200;
78
92
  */
79
93
  function parseHeld(body: Record<string, unknown>): JournalPage['held'] | undefined {
80
94
  if (!Array.isArray(body?.held)) return undefined;
81
- const paths: { path: string; reason: HeldReason }[] = [];
95
+ const paths: HeldEntry[] = [];
82
96
  // p8-holds-fix (recheck info D): one row per path — the panel keys rows by it.
83
97
  const seen = new Set<string>();
84
98
  for (const raw of (body.held as unknown[]).slice(0, MAX_HELD)) {
@@ -89,14 +103,23 @@ function parseHeld(body: Record<string, unknown>): JournalPage['held'] | undefin
89
103
  seen.add(h.path);
90
104
  const reason: HeldReason =
91
105
  h.reason === 'changed-as-canvas' ? 'changed-as-canvas' : 'canvas-before-folders';
92
- paths.push({ path: h.path, reason });
106
+ const version =
107
+ typeof h.sha256 === 'string' &&
108
+ /^[0-9a-f]{64}$/.test(h.sha256) &&
109
+ typeof h.size === 'number' &&
110
+ Number.isSafeInteger(h.size) &&
111
+ h.size >= 0
112
+ ? { sha256: h.sha256, size: h.size }
113
+ : {};
114
+ paths.push({ path: h.path, reason, ...version });
93
115
  }
94
116
  const rawCount = body.heldCount;
95
117
  const count =
96
118
  typeof rawCount === 'number' && Number.isInteger(rawCount) && rawCount >= paths.length
97
119
  ? Math.min(rawCount, 1_000_000)
98
120
  : paths.length;
99
- return { count, paths };
121
+ // #167 T5.3 — additive (`heldOverflow`, owner reads only); anything but a strict true is absent.
122
+ return body.heldOverflow === true ? { count, paths, overflow: true } : { count, paths };
100
123
  }
101
124
 
102
125
  // A designRoot-relative path a peer will turn into a real file: the SAME shape
@@ -376,6 +399,17 @@ export function hasFileClassesV2(capabilities: string[] | null): boolean {
376
399
  return Array.isArray(capabilities) && capabilities.includes(FILE_CLASSES_V2_CAPABILITY);
377
400
  }
378
401
 
402
+ /** The capability a hub advertises when its file door takes the who-added sidecar (#172). */
403
+ export const ASSET_ADDED_CAPABILITY = 'asset-added-v1';
404
+
405
+ /**
406
+ * Does this hub's file door take `assets/<stem>.added.json` (#172)? A hub before it answers `400
407
+ * invalid path`, so the desktop holds the file for it with a reason (`olderDoorRefusesAdded`).
408
+ */
409
+ export function hasAssetAddedV1(capabilities: string[] | null): boolean {
410
+ return Array.isArray(capabilities) && capabilities.includes(ASSET_ADDED_CAPABILITY);
411
+ }
412
+
379
413
  /** The capability a hub advertises when its doors take paths up to 32 segments deep (fix/205). */
380
414
  export const FILE_DEPTH_V2_CAPABILITY = 'file-depth-v2';
381
415
 
@@ -386,3 +420,15 @@ export const FILE_DEPTH_V2_CAPABILITY = 'file-depth-v2';
386
420
  export function hasFileDepthV2(capabilities: string[] | null): boolean {
387
421
  return Array.isArray(capabilities) && capabilities.includes(FILE_DEPTH_V2_CAPABILITY);
388
422
  }
423
+
424
+ /** The capability a hub advertises when it stamps every presence role itself (T5.2, #165). */
425
+ export const PRESENCE_ROLE_CAPABILITY = 'presence-role-v1';
426
+
427
+ /**
428
+ * Does this hub stamp presence roles (`roleBy: 'hub'`, apps/hub access-docs.mjs `stampHubRole`)? An
429
+ * older hub relays the mark as a peer sent it, so a hub-relayed role is kept only where this is true
430
+ * (collab/awareness-bridge.ts `rolesVouched`).
431
+ */
432
+ export function hasPresenceRoleV1(capabilities: unknown): boolean {
433
+ return Array.isArray(capabilities) && capabilities.includes(PRESENCE_ROLE_CAPABILITY);
434
+ }
@@ -20,22 +20,16 @@
20
20
  // and the app's own managed copies (the desktop passes its registry binding as
21
21
  // `MAUDE_APP_BOUND_HUB`, which a repo cannot set).
22
22
  //
23
- // MIGRATION (a project already syncing on this Mac before this shipped keeps syncing, no prompt).
24
- // The record is derived ONCE from this Mac's own evidence of the link — `_sync.json` (its `url`) or
25
- // `_state/sync-journal.json` (its `hubUrl`) naming the same hub. Why that is safe:
26
- // - both are runtime state, gitignored in every DDR-115 list, so a clone does not carry them;
27
- // - a repo that force-adds one anyway is refused: the file must not be tracked by git;
28
- // - and it must be OLDER than this store (`since` — stamped the first time this build looked), so
29
- // evidence written after the fix (a clone, an unzip with fresh times) never counts. Only a
30
- // consented runtime writes either file from now on, and that one already has a record;
31
- // - it must be a plain file in a plain `_state/` (no symlink to another project's genuine file).
32
- // What is NOT closed: an archive that restores backdated mtimes AND carries a forged `_sync.json`,
33
- // with no `.git`, extracted before this build first ran. Narrow, and the old build trusted it anyway.
23
+ // NO MIGRATION FROM FOLDER CONTENT (2.1.1, N1). Builds before 2.1.1 derived a `migrated` record at
24
+ // boot from the folder's own runtime sync files when their mtime predated this store. Retired:
25
+ // whoever made the folder controls both the files and their timestamps (archives restore stored
26
+ // mtimes), so that lane let folder content say "confirmed". Nothing inside the folder writes a
27
+ // record now. A `migrated` record an earlier build already wrote stays valid (`LinkHow` keeps the
28
+ // value, `matches` honours it like any other); a folder with no record gets the neutral Review…
29
+ // state and one Connect.
34
30
 
35
31
  import {
36
32
  chmodSync,
37
- existsSync,
38
- lstatSync,
39
33
  mkdirSync,
40
34
  readdirSync,
41
35
  readFileSync,
@@ -69,13 +63,12 @@ export interface LinkClaim {
69
63
  export interface ConsentOptions {
70
64
  /** the folder holding `.design/` — the record's key (by realpath) */
71
65
  repoRoot: string;
66
+ /** kept for callers; nothing under it is read as evidence of a link (N1) */
72
67
  designRoot: string;
73
68
  /** the store file (default `linksPath()`) */
74
69
  file?: string;
75
70
  env?: Record<string, string | undefined>;
76
71
  now?: () => number;
77
- /** is `abs` tracked by git in `repoRoot`? (injected in tests; default runs git) */
78
- tracked?: (repoRoot: string, abs: string) => boolean;
79
72
  }
80
73
 
81
74
  export type ConsentVerdict =
@@ -161,7 +154,7 @@ function loadOrInit(file: string, now: number): LinksFile {
161
154
  try {
162
155
  writeStore(file, fresh);
163
156
  } catch {
164
- /* unwritable: `since` stays now for this boot, which only narrows migration */
157
+ /* unwritable: the store is created on the next write */
165
158
  }
166
159
  return fresh;
167
160
  }
@@ -177,6 +170,15 @@ export function projectLinkOf(repoRoot: string, file: string = linksPath()): Pro
177
170
  return readStore(file)?.links[folderKey(repoRoot)] ?? null;
178
171
  }
179
172
 
173
+ /** 2.1.1 T8 — has ANY folder on this Mac been linked to `url`? (Link your server asks before the
174
+ * first link to a server this Mac never linked, whatever that server says it holds.) */
175
+ export function hubEverLinked(url: string, file: string = linksPath()): boolean {
176
+ const hub = normHub(url);
177
+ if (!hub) return false;
178
+ const links = readStore(file)?.links ?? {};
179
+ return Object.values(links).some((r) => !!r && typeof r === 'object' && r.hub === hub);
180
+ }
181
+
180
182
  /** Write (or replace) this folder's record — a person linked or confirmed it on this Mac. */
181
183
  export function recordProjectLink(
182
184
  repoRoot: string,
@@ -243,63 +245,10 @@ export function forgetFolderEverywhere(
243
245
  return n;
244
246
  }
245
247
 
246
- function gitTracked(repoRoot: string, abs: string): boolean {
247
- try {
248
- const r = Bun.spawnSync(['git', 'ls-files', '--error-unmatch', '--', abs], {
249
- cwd: repoRoot,
250
- stdout: 'ignore',
251
- stderr: 'ignore',
252
- env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' },
253
- });
254
- return r.exitCode === 0;
255
- } catch {
256
- return false;
257
- }
258
- }
259
-
260
- /** A plain file (not a symlink) inside a plain directory chain under `designRoot`. */
261
- function plainFile(designRoot: string, rel: string): boolean {
262
- let cur = designRoot;
263
- for (const part of rel.split('/')) {
264
- cur = path.join(cur, part);
265
- try {
266
- if (lstatSync(cur).isSymbolicLink()) return false;
267
- } catch {
268
- return false;
269
- }
270
- }
271
- return true;
272
- }
273
-
274
- /** This Mac's own pre-fix evidence of syncing `hub` here — see the header for why it is safe. */
275
- function migrationEvidence(o: ConsentOptions, hub: string, since: number): boolean {
276
- const tracked = o.tracked ?? gitTracked;
277
- const lanes: Array<[string, string]> = [
278
- ['_sync.json', 'url'],
279
- ['_state/sync-journal.json', 'hubUrl'],
280
- ];
281
- for (const [rel, key] of lanes) {
282
- const abs = path.join(o.designRoot, rel);
283
- if (!existsSync(abs) || !plainFile(o.designRoot, rel)) continue;
284
- let named: string | null = null;
285
- let mtime = Number.POSITIVE_INFINITY;
286
- try {
287
- mtime = lstatSync(abs).mtimeMs;
288
- named = normHub((JSON.parse(readFileSync(abs, 'utf8')) as Record<string, unknown>)?.[key]);
289
- } catch {
290
- continue;
291
- }
292
- if (named !== hub || !(mtime < since)) continue;
293
- if (tracked(o.repoRoot, abs)) continue;
294
- return true;
295
- }
296
- return false;
297
- }
298
-
299
248
  /**
300
249
  * May this Mac honour `claim` for this folder? A matching record → yes. Else the app's own binding
301
- * (`MAUDE_APP_BOUND_HUB`, the desktop registry's managed copy) or this Mac's pre-fix evidence →
302
- * yes, and the record is written so the question is never asked again. Else no: park the claim.
250
+ * (`MAUDE_APP_BOUND_HUB`, the desktop registry's managed copy) → yes, and the record is written so
251
+ * the question is never asked again. Else no: park the claim. Nothing in the folder counts (N1).
303
252
  */
304
253
  export function linkConsent(claim: LinkClaim, o: ConsentOptions): ConsentVerdict {
305
254
  const hub = normHub(claim.url);
@@ -313,10 +262,8 @@ export function linkConsent(claim: LinkClaim, o: ConsentOptions): ConsentVerdict
313
262
  // A record for ANOTHER hub is a person's choice on this Mac; a claim that differs from it is not
314
263
  // migrated past — it waits for Connect like any other.
315
264
  if (rec) return { ok: false, reason: 'other-hub' };
316
- let how: LinkHow | null = null;
317
- if (normHub(env.MAUDE_APP_BOUND_HUB) === hub) how = 'app';
318
- else if (migrationEvidence(o, hub, store.since)) how = 'migrated';
319
- if (!how) return { ok: false, reason: 'no-record' };
265
+ if (normHub(env.MAUDE_APP_BOUND_HUB) !== hub) return { ok: false, reason: 'no-record' };
266
+ const how: LinkHow = 'app';
320
267
  try {
321
268
  recordProjectLink(o.repoRoot, claim, how, { file, now: () => now });
322
269
  } catch {
@@ -0,0 +1,252 @@
1
+ // 2.1.1 — what linking THIS folder to a team server would do, counted before anything moves
2
+ // (routes/hub-link-folder.ts, decision maude/v2-2.1.1-b5-link-folder-confirm-before-merge).
3
+ //
4
+ // A self-hosted server holds ONE project. When it is empty, linking seeds it from this folder (the
5
+ // sync runtime's ordinary seed-up). When it already holds work, the two sides would be merged, so the
6
+ // person is told first, in counts:
7
+ //
8
+ // onlyHere canvases + files on this Mac the server does not have (they go up)
9
+ // onlyThere canvases + files on the server this Mac does not have (they come down)
10
+ // differ on both sides with different content (they are merged)
11
+ // same on both sides, identical
12
+ //
13
+ // Both sides are read the way the sync runtime reads them: the server through its own manifests
14
+ // (`GET /api/projects/current/v1/bootstrap` — canvas paths + the `html` lane's sha256 — and
15
+ // `GET /api/files`, the file plane's sha256 manifest), this Mac through the file plane's walk and
16
+ // classifier (`walkClassifiedAll`). Nothing here writes, and the credential only rides requests to
17
+ // the server it belongs to: a redirect is refused, never followed.
18
+ //
19
+ // An older server without the accepted-revisions bootstrap answers its document listing instead
20
+ // (`GET /api/documents`: names and byte counts). Content cannot be compared from that, so a canvas
21
+ // on both sides counts as `differ` — the safe direction: it can only ask for a confirm, never skip one.
22
+
23
+ import { createHash } from 'node:crypto';
24
+ import { readFileSync } from 'node:fs';
25
+ import path from 'node:path';
26
+ import type { CanvasGroupLike } from './file-membership.ts';
27
+ import { walkClassifiedAll } from './file-plane.ts';
28
+ import { slugFromDocName } from './remote-docs.ts';
29
+
30
+ export interface SideSurvey {
31
+ /** design-root-relative canvas body path (`ui/home.tsx`) → sha256 of its source, null = unknown */
32
+ canvases: Map<string, string | null>;
33
+ /** design-root-relative file path → sha256 */
34
+ files: Map<string, string>;
35
+ /** canvases are compared by slug only (an older server's listing) */
36
+ bySlug?: boolean;
37
+ /** This Mac's side only: the files that are pictures, video and the like (the inert-media class). */
38
+ media?: Set<string>;
39
+ /**
40
+ * The server's side only (2.1.1 T14): whether it has a place to store media. `false` only when it
41
+ * said so (no file journal and no checkout); a server that did not answer is assumed to store it.
42
+ */
43
+ storesMedia?: boolean;
44
+ }
45
+
46
+ export interface LinkCounts {
47
+ onlyHere: number;
48
+ onlyThere: number;
49
+ differ: number;
50
+ same: number;
51
+ }
52
+
53
+ export type HubSurvey =
54
+ | { ok: true; survey: SideSurvey }
55
+ | { ok: false; reason: 'signed-out' | 'offline' };
56
+
57
+ const TIMEOUT_MS = 15_000;
58
+ const sha256 = (b: Uint8Array | string) => createHash('sha256').update(b).digest('hex');
59
+ const HEX64 = /^[0-9a-f]{64}$/;
60
+
61
+ /** A canvas body path's slug, the way a flat document name spells it. */
62
+ export function slugOfRel(rel: string): string {
63
+ return path.posix
64
+ .basename(rel)
65
+ .replace(/\.tsx$/i, '')
66
+ .toLowerCase();
67
+ }
68
+
69
+ /** This Mac's side: canvas bodies + file-plane files, through the plane's own walk. */
70
+ export function surveyLocal(
71
+ designRoot: string,
72
+ canvasGroups?: readonly CanvasGroupLike[]
73
+ ): SideSurvey {
74
+ const canvases = new Map<string, string | null>();
75
+ const files = new Map<string, string>();
76
+ const media = new Set<string>();
77
+ for (const f of walkClassifiedAll(designRoot, canvasGroups)) {
78
+ if (f.cls === 'never') continue;
79
+ let hash: string | null = null;
80
+ try {
81
+ hash = sha256(readFileSync(f.abs));
82
+ } catch {
83
+ hash = null;
84
+ }
85
+ if (f.cls === 'canvas-owned') {
86
+ if (/\.tsx$/i.test(f.rel)) canvases.set(f.rel, hash);
87
+ continue;
88
+ }
89
+ if (hash) {
90
+ files.set(f.rel, hash);
91
+ if (f.cls === 'inert-media') media.add(f.rel);
92
+ }
93
+ }
94
+ return { canvases, files, media };
95
+ }
96
+
97
+ type Got = { status: number; body: Record<string, unknown> | null };
98
+
99
+ async function getJson(url: string, token: string, doFetch: typeof fetch): Promise<Got> {
100
+ try {
101
+ const res = await doFetch(url, {
102
+ headers: { authorization: `Bearer ${token}` },
103
+ // the credential belongs to this server: a redirect would carry it elsewhere
104
+ redirect: 'manual',
105
+ signal: AbortSignal.timeout(TIMEOUT_MS),
106
+ });
107
+ if (res.status !== 200) return { status: res.status, body: null };
108
+ const body = (await res.json().catch(() => null)) as Record<string, unknown> | null;
109
+ return { status: 200, body: body && typeof body === 'object' ? body : null };
110
+ } catch {
111
+ return { status: 0, body: null };
112
+ }
113
+ }
114
+
115
+ const refused = (s: number) => s === 401 || s === 403;
116
+
117
+ /**
118
+ * Does the server have a place for pictures and videos? A server that carries the file journal
119
+ * (`ledger`) stores them in it; an older one stores them in its project checkout. With neither, its
120
+ * media door answers 405 and they stay on this Mac (sync/media-gate.ts). Unknown is "yes": the line
121
+ * this feeds is only said when the server told us it can't.
122
+ */
123
+ export function serverStoresMedia(health: Record<string, unknown> | null): boolean {
124
+ if (!health) return true;
125
+ const caps = health.capabilities;
126
+ if (!Array.isArray(caps)) return true; // a server that predates capabilities: say nothing
127
+ if (caps.includes('ledger')) return true;
128
+ const checkout = (health.workspace as { checkout?: unknown } | undefined)?.checkout;
129
+ return checkout === 'present';
130
+ }
131
+
132
+ /** The server's side, with the credential this Mac holds for it. */
133
+ export async function surveyHub(
134
+ hubUrl: string,
135
+ token: string,
136
+ doFetch: typeof fetch = fetch
137
+ ): Promise<HubSurvey> {
138
+ const base = hubUrl.replace(/\/+$/, '');
139
+ const canvases = new Map<string, string | null>();
140
+ const files = new Map<string, string>();
141
+ let bySlug = false;
142
+
143
+ const boot = await getJson(`${base}/api/projects/current/v1/bootstrap`, token, doFetch);
144
+ if (refused(boot.status)) return { ok: false, reason: 'signed-out' };
145
+ if (boot.status === 200 && Array.isArray(boot.body?.docs)) {
146
+ for (const d of boot.body.docs as unknown[]) {
147
+ const row = d as { path?: unknown; retired?: unknown; lanes?: unknown };
148
+ if (!row || row.retired || typeof row.path !== 'string' || !row.path) continue;
149
+ const html = (row.lanes as { html?: { hash?: unknown } } | undefined)?.html?.hash;
150
+ canvases.set(row.path, typeof html === 'string' && HEX64.test(html) ? html : null);
151
+ }
152
+ } else {
153
+ // an older server: its listing (names + byte counts) — a name that holds nothing is not work
154
+ const list = await getJson(`${base}/api/documents`, token, doFetch);
155
+ if (refused(list.status)) return { ok: false, reason: 'signed-out' };
156
+ if (list.status !== 200 || !Array.isArray(list.body?.documents))
157
+ return { ok: false, reason: 'offline' };
158
+ bySlug = true;
159
+ for (const d of list.body.documents as unknown[]) {
160
+ const row = d as { name?: unknown; bytes?: unknown };
161
+ const slug = typeof row?.name === 'string' ? slugFromDocName(row.name) : null;
162
+ if (slug && Number(row.bytes) > 0) canvases.set(slug, null);
163
+ }
164
+ }
165
+
166
+ const manifest = await getJson(`${base}/api/files`, token, doFetch);
167
+ if (refused(manifest.status)) return { ok: false, reason: 'signed-out' };
168
+ if (manifest.status === 200 && Array.isArray(manifest.body?.files)) {
169
+ for (const f of manifest.body.files as unknown[]) {
170
+ const row = f as { path?: unknown; sha256?: unknown };
171
+ if (typeof row?.path === 'string' && typeof row.sha256 === 'string' && HEX64.test(row.sha256))
172
+ files.set(row.path, row.sha256);
173
+ }
174
+ } else if (manifest.status === 0) {
175
+ return { ok: false, reason: 'offline' };
176
+ }
177
+ // any other answer (an older server without the file plane) = no files there
178
+
179
+ // 2.1.1 T14 — can this server store media at all? (`/health` needs no credential)
180
+ const health = await getJson(`${base}/health`, token, doFetch);
181
+ const storesMedia = serverStoresMedia(health.status === 200 ? health.body : null);
182
+
183
+ return {
184
+ ok: true,
185
+ survey: {
186
+ canvases,
187
+ files,
188
+ ...(bySlug ? { bySlug } : {}),
189
+ ...(storesMedia ? {} : { storesMedia }),
190
+ },
191
+ };
192
+ }
193
+
194
+ /** Does the server hold any work at all? */
195
+ export function holdsWork(s: SideSurvey): boolean {
196
+ return s.canvases.size > 0 || s.files.size > 0;
197
+ }
198
+
199
+ function countMaps(
200
+ here: ReadonlyMap<string, string | null>,
201
+ there: ReadonlyMap<string, string | null>,
202
+ out: LinkCounts
203
+ ): void {
204
+ for (const [k, h] of here) {
205
+ if (!there.has(k)) out.onlyHere++;
206
+ else {
207
+ const t = there.get(k) ?? null;
208
+ if (h && t && h === t) out.same++;
209
+ else out.differ++;
210
+ }
211
+ }
212
+ for (const k of there.keys()) if (!here.has(k)) out.onlyThere++;
213
+ }
214
+
215
+ export interface LinkComparison extends LinkCounts {
216
+ /** the same four counts, canvases only and files only (the dialog names each) */
217
+ canvases: LinkCounts;
218
+ files: LinkCounts;
219
+ /**
220
+ * 2.1.1 T14 — pictures and videos only this Mac has that the server has no place for: they stay
221
+ * here, so they are NOT in `onlyHere` ("sent up"). Absent when there are none.
222
+ */
223
+ stayHere?: number;
224
+ }
225
+
226
+ const zero = (): LinkCounts => ({ onlyHere: 0, onlyThere: 0, differ: 0, same: 0 });
227
+
228
+ /** Here vs there: the four counts the dialog words, in total and per kind. */
229
+ export function compareSurveys(here: SideSurvey, there: SideSurvey): LinkComparison {
230
+ const canvases = zero();
231
+ const files = zero();
232
+ const localCanvases = there.bySlug
233
+ ? new Map([...here.canvases.keys()].map((rel) => [slugOfRel(rel), null as string | null]))
234
+ : here.canvases;
235
+ countMaps(localCanvases, there.canvases, canvases);
236
+ countMaps(here.files, there.files, files);
237
+ // media only this Mac has, on a server that can't store it: counted apart, never "sent up"
238
+ let stay = 0;
239
+ if (there.storesMedia === false && here.media) {
240
+ for (const rel of here.media) if (here.files.has(rel) && !there.files.has(rel)) stay++;
241
+ files.onlyHere -= stay;
242
+ }
243
+ return {
244
+ ...(stay ? { stayHere: stay } : {}),
245
+ onlyHere: canvases.onlyHere + files.onlyHere,
246
+ onlyThere: canvases.onlyThere + files.onlyThere,
247
+ differ: canvases.differ + files.differ,
248
+ same: canvases.same + files.same,
249
+ canvases,
250
+ files,
251
+ };
252
+ }