@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
@@ -0,0 +1,276 @@
1
+ // A terminal-started server steps down for the desktop app's sidecar — #206 (DDR-250 decision 1;
2
+ // contract `client/v2/contracts/206-cli-reuses-desktop.md` §6 "Handover" step 3).
3
+ //
4
+ // While the app runs it owns a checkout's server. A server started by `server-up` / `maude design
5
+ // serve` runs as role `cli` (MAUDE_SERVER_ROLE=cli; a shell spawn is never `cli`). Such a server
6
+ // reads the app's registry (`<app_data_dir>/servers.json`, written only by the app) every 2 s.
7
+ // When it names a RUNNING sidecar for this same root AND that sidecar answers the attest
8
+ // challenge (shell/attest.ts — only the process the app gave the per-spawn key can), this server:
9
+ // 1. refuses every new mutating request with 409 `yielded` (`yieldRefusal`, server.ts);
10
+ // 2. waits for its export / generation jobs and unsent work, at most 120 s;
11
+ // 3. shuts down the ordinary way (server.ts `shutdown`): sync stopped, the store lock released,
12
+ // `_server.json` removed only if it still names this server, exit 0.
13
+ // The sidecar then takes the store lock within LOCK_RETRY_MS. The app never signals this process:
14
+ // it steps down by itself, so nothing ever acts on a pid read from a project file.
15
+ //
16
+ // What it trusts: only an attested answer. The registry is app-owned, but a stale or planted one
17
+ // (or a squatter on its port) cannot make this server quit — an entry that does not attest is
18
+ // skipped. The registry file is read only when it is a regular file of this user, at most 1 MiB,
19
+ // and not writable by group or others.
20
+
21
+ import { randomBytes } from 'node:crypto';
22
+ import { readFileSync, realpathSync, statSync } from 'node:fs';
23
+ import { homedir } from 'node:os';
24
+ import { isAbsolute, join } from 'node:path';
25
+
26
+ import { ATTEST_KEY_RE, attestMac, macMatches } from './attest.ts';
27
+
28
+ export const SERVER_ROLE_ENV = 'MAUDE_SERVER_ROLE';
29
+ /** Where the app's registry is, when not the platform default (harnesses, tests). */
30
+ export const REGISTRY_FILE_ENV = 'MAUDE_APP_REGISTRY_FILE';
31
+ /** Test seam: the watch interval in ms (default 2000). */
32
+ export const YIELD_INTERVAL_ENV = 'MAUDE_CLI_YIELD_INTERVAL_MS';
33
+ export const APP_IDENTIFIER = 'com.maude.app';
34
+ export const YIELD_INTERVAL_MS = 2000;
35
+ export const YIELD_MAX_WAIT_MS = 120_000;
36
+ const REGISTRY_MAX_BYTES = 1024 * 1024;
37
+ const ATTEST_TIMEOUT_MS = 2000;
38
+
39
+ /** Role `cli`, and not a server the desktop shell (or Home) spawned. */
40
+ export function isCliRole(env: Record<string, string | undefined>): boolean {
41
+ if (env[SERVER_ROLE_ENV] !== 'cli') return false;
42
+ return !(
43
+ env.MAUDE_SHELL_SIDECAR === '1' ||
44
+ !!env.MAUDE_SHELL_TOKEN ||
45
+ !!env.MAUDE_SHELL_INFO_FILE ||
46
+ !!env.MAUDE_HOME_TOKEN
47
+ );
48
+ }
49
+
50
+ /** The registry the app writes: Tauri's `app_data_dir()` + `servers.json`. */
51
+ export function registryPath(
52
+ env: Record<string, string | undefined> = process.env,
53
+ platform: NodeJS.Platform = process.platform,
54
+ home: string = homedir()
55
+ ): string | null {
56
+ const override = env[REGISTRY_FILE_ENV];
57
+ if (override && isAbsolute(override)) return override;
58
+ if (platform === 'darwin')
59
+ return join(home, 'Library', 'Application Support', APP_IDENTIFIER, 'servers.json');
60
+ if (platform === 'win32')
61
+ return env.APPDATA ? join(env.APPDATA, APP_IDENTIFIER, 'servers.json') : null;
62
+ const data = env.XDG_DATA_HOME && isAbsolute(env.XDG_DATA_HOME) ? env.XDG_DATA_HOME : null;
63
+ return join(data ?? join(home, '.local', 'share'), APP_IDENTIFIER, 'servers.json');
64
+ }
65
+
66
+ export interface RegistryServer {
67
+ root: string;
68
+ state: string;
69
+ port: number;
70
+ pid?: number;
71
+ attestKey: string;
72
+ }
73
+
74
+ export interface Registry {
75
+ appPid: number;
76
+ servers: RegistryServer[];
77
+ }
78
+
79
+ /** The registry, or null when it is absent, not this user's, writable by others, or malformed. */
80
+ export function readRegistry(file: string): Registry | null {
81
+ try {
82
+ const st = statSync(file);
83
+ if (!st.isFile() || st.size > REGISTRY_MAX_BYTES) return null;
84
+ const uid = process.getuid?.();
85
+ if (uid !== undefined && st.uid !== uid) return null;
86
+ if (process.platform !== 'win32' && (st.mode & 0o022) !== 0) return null;
87
+ const doc = JSON.parse(readFileSync(file, 'utf8')) as {
88
+ v?: unknown;
89
+ app?: { pid?: unknown };
90
+ servers?: unknown;
91
+ };
92
+ if (doc?.v !== 1 || !Array.isArray(doc.servers)) return null;
93
+ const appPid = doc.app?.pid;
94
+ if (!Number.isInteger(appPid) || (appPid as number) <= 0) return null;
95
+ const servers: RegistryServer[] = [];
96
+ for (const s of doc.servers as Record<string, unknown>[]) {
97
+ if (!s || typeof s !== 'object') continue;
98
+ const { root, state, port, pid, attestKey } = s;
99
+ if (typeof root !== 'string' || !isAbsolute(root)) continue;
100
+ if (typeof state !== 'string') continue;
101
+ if (!Number.isInteger(port) || (port as number) < 1 || (port as number) > 65535) continue;
102
+ if (typeof attestKey !== 'string' || !ATTEST_KEY_RE.test(attestKey)) continue;
103
+ servers.push({
104
+ root,
105
+ state,
106
+ port: port as number,
107
+ ...(Number.isInteger(pid) ? { pid: pid as number } : {}),
108
+ attestKey,
109
+ });
110
+ }
111
+ return { appPid: appPid as number, servers };
112
+ } catch {
113
+ return null;
114
+ }
115
+ }
116
+
117
+ /** Alive and ours to signal. EPERM (another user's process) is not the app. */
118
+ function pidAlive(pid: number): boolean {
119
+ try {
120
+ process.kill(pid, 0);
121
+ return true;
122
+ } catch {
123
+ return false;
124
+ }
125
+ }
126
+
127
+ function real(p: string): string | null {
128
+ try {
129
+ return realpathSync(p);
130
+ } catch {
131
+ return null;
132
+ }
133
+ }
134
+
135
+ /** Does the server at `entry.port` hold `entry.attestKey` for this root? Fresh nonce each call. */
136
+ export async function attests(
137
+ entry: RegistryServer,
138
+ rootId: string,
139
+ fetchImpl: typeof fetch = fetch
140
+ ): Promise<boolean> {
141
+ const n = randomBytes(16).toString('hex');
142
+ try {
143
+ const r = await fetchImpl(`http://127.0.0.1:${entry.port}/_api/shell/attest?n=${n}`, {
144
+ redirect: 'manual',
145
+ signal: AbortSignal.timeout(ATTEST_TIMEOUT_MS),
146
+ });
147
+ if (r.status !== 200) return false;
148
+ const body = (await r.json()) as { mac?: unknown };
149
+ return macMatches(body?.mac, attestMac(entry.attestKey, n, rootId, entry.port));
150
+ } catch {
151
+ return false;
152
+ }
153
+ }
154
+
155
+ /* ------------------------------------------------------------ the write refusal while yielding */
156
+
157
+ let yielding = false;
158
+ const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
159
+
160
+ /** 409 `yielded` for a mutating request once this server is stepping down; else null. */
161
+ export function yieldRefusal(req: Request): Response | null {
162
+ if (!yielding || SAFE_METHODS.has(req.method.toUpperCase())) return null;
163
+ return Response.json(
164
+ {
165
+ error: 'yielded',
166
+ reason: 'yielded',
167
+ message: 'Maude is taking over this project. Try again in a moment.',
168
+ },
169
+ { status: 409, headers: { 'Cache-Control': 'no-store' } }
170
+ );
171
+ }
172
+
173
+ /* ------------------------------------------------------------------------------- the watcher */
174
+
175
+ export interface CliYieldOptions {
176
+ /** this server's repo root (realpath'd here) and its http.ts `rootIdentity` */
177
+ root: string;
178
+ rootId: string;
179
+ selfPid: number;
180
+ selfPort: number;
181
+ /** the registry file (registryPath) */
182
+ file: string;
183
+ /** export + generation jobs + unsent work still in flight (routes/shell.ts shellPendingWork) */
184
+ pending?: () => number;
185
+ /** called once, when the work is done or maxWaitMs has passed: shut down */
186
+ onYield: () => void;
187
+ intervalMs?: number;
188
+ pendingPollMs?: number;
189
+ maxWaitMs?: number;
190
+ fetchImpl?: typeof fetch;
191
+ alive?: (pid: number) => boolean;
192
+ log?: (line: string) => void;
193
+ }
194
+
195
+ export type CliYieldState = 'watching' | 'yielding' | 'yielded' | 'stopped';
196
+
197
+ export function watchForAppSidecar(o: CliYieldOptions): {
198
+ stop(): void;
199
+ state(): CliYieldState;
200
+ } {
201
+ const ownRoot = real(o.root) ?? o.root;
202
+ const alive = o.alive ?? pidAlive;
203
+ const log = o.log ?? ((l: string) => console.log(l));
204
+ let state: CliYieldState = 'watching';
205
+ let checking = false;
206
+ let waitTimer: ReturnType<typeof setInterval> | null = null;
207
+
208
+ const finish = () => {
209
+ if (state !== 'yielding') return;
210
+ if (waitTimer) clearInterval(waitTimer);
211
+ waitTimer = null;
212
+ state = 'yielded';
213
+ o.onYield();
214
+ };
215
+
216
+ const beginYield = (port: number) => {
217
+ clearInterval(timer);
218
+ state = 'yielding';
219
+ yielding = true;
220
+ log(` Maude is serving this project now (port ${port}) — this server is stepping down.`);
221
+ const started = Date.now();
222
+ const maxWait = o.maxWaitMs ?? YIELD_MAX_WAIT_MS;
223
+ const left = () => {
224
+ try {
225
+ return o.pending?.() ?? 0;
226
+ } catch {
227
+ return 0;
228
+ }
229
+ };
230
+ if (left() === 0) return finish();
231
+ waitTimer = setInterval(() => {
232
+ if (left() === 0 || Date.now() - started >= maxWait) finish();
233
+ }, o.pendingPollMs ?? 500);
234
+ waitTimer.unref?.();
235
+ };
236
+
237
+ const tick = async () => {
238
+ if (state !== 'watching' || checking) return;
239
+ checking = true;
240
+ try {
241
+ const reg = readRegistry(o.file);
242
+ if (!reg || !alive(reg.appPid)) return;
243
+ for (const e of reg.servers) {
244
+ if (e.state !== 'running' || e.port === o.selfPort) continue;
245
+ if (e.pid !== undefined && e.pid === o.selfPid) continue;
246
+ if (real(e.root) !== ownRoot) continue;
247
+ if (await attests(e, o.rootId, o.fetchImpl)) {
248
+ if (state === 'watching') beginYield(e.port);
249
+ return;
250
+ }
251
+ }
252
+ } finally {
253
+ checking = false;
254
+ }
255
+ };
256
+
257
+ const timer = setInterval(() => void tick(), o.intervalMs ?? YIELD_INTERVAL_MS);
258
+ timer.unref?.();
259
+
260
+ return {
261
+ stop() {
262
+ clearInterval(timer);
263
+ if (waitTimer) clearInterval(waitTimer);
264
+ // a watcher stopped mid-wait (tests) takes its refusal with it
265
+ if (state === 'yielding') yielding = false;
266
+ if (state === 'watching' || state === 'yielding') state = 'stopped';
267
+ },
268
+ state: () => state,
269
+ };
270
+ }
271
+
272
+ /** The watch interval: the test seam when it is a sane number, else 2 s. */
273
+ export function yieldIntervalFrom(env: Record<string, string | undefined>): number {
274
+ const n = Number(env[YIELD_INTERVAL_ENV]);
275
+ return Number.isFinite(n) && n >= 50 && n <= 60_000 ? n : YIELD_INTERVAL_MS;
276
+ }
@@ -0,0 +1,302 @@
1
+ // shell/clip-transfer.ts — #122 (122-C): a clip between two projects on this Mac (contract
2
+ // client/v2/contracts/122-cross-canvas-clipboard.md §5.6). The routes are in routes/shell.ts; this is what
3
+ // they do, so a test can hold each rule without a server.
4
+ //
5
+ // export the source server: a desktop-shelf clip it read from its OWN disk, the sha256 of every module a
6
+ // carried relative import names, and the content-addressed assets the items use (rel + size).
7
+ // asset the source server: one of those assets, only one the clip lists.
8
+ // import the target server, AFTER the person said Paste in its tab: the clip re-checked item by item
9
+ // (edit-ops/clipboard.ts `checkTransfer`), every carried relative import kept only when this project
10
+ // has the same file (same designRoot-relative path, same sha256), every asset's bytes checked
11
+ // against its `<sha8>` name (a photo sidecar must parse and travel with its picture), then the
12
+ // assets written into `assets/` (skipped when present, tmp + rename) and the clip kept.
13
+ //
14
+ // Nothing is written before every check passed. The target never reads the source project (Rust carries the
15
+ // bytes): no server ever reaches another root, and text only comes from a server that read it from its disk.
16
+ //
17
+ // The frame Rust posts to `clip-import`: a 4-byte big-endian header length, the header JSON
18
+ // `{ clip, project, assets: [{ rel, size }] }`, then each asset's bytes in that order.
19
+
20
+ import { createHash, randomBytes } from 'node:crypto';
21
+ import {
22
+ existsSync,
23
+ lstatSync,
24
+ mkdirSync,
25
+ readFileSync,
26
+ realpathSync,
27
+ renameSync,
28
+ statSync,
29
+ writeFileSync,
30
+ } from 'node:fs';
31
+ import { join, resolve, sep } from 'node:path';
32
+ import { sanitizeSvgAllowlist } from '../bin/_import-asset.mjs';
33
+ import { CLIP_MEDIA_EXT, isClipMedia } from '../edit-ops/clip-carry.ts';
34
+ import {
35
+ type ClipHandle,
36
+ type ClipTransfer,
37
+ checkTransfer,
38
+ exportClip,
39
+ isDesignRel,
40
+ keepTransfer,
41
+ } from '../edit-ops/clipboard.ts';
42
+
43
+ /** Picture bytes one clip may bring (the server's own body bound is ~108 MB; the header rides under it). */
44
+ export const CLIP_ASSETS_MAX_BYTES = 80 * 1024 * 1024;
45
+ export const CLIP_HEADER_MAX_BYTES = 16 * 1024 * 1024;
46
+ export const CLIP_FRAME_MAX_BYTES = 4 + CLIP_HEADER_MAX_BYTES + CLIP_ASSETS_MAX_BYTES;
47
+ export const CLIP_ASSETS_MAX = 256;
48
+ const SIDECAR_MAX_BYTES = 256 * 1024;
49
+
50
+ // only media crosses (edit-ops/clip-carry.ts `CLIP_MEDIA_EXT`): a `.tsx` named by its own hash is still code
51
+ const CAS_RE = new RegExp(`^assets/([0-9a-f]{8})\\.(?:${CLIP_MEDIA_EXT.join('|')})$`);
52
+ const SIDECAR_RE = /^assets\/([0-9a-f]{8})(?:\.[0-9a-f]{8,16})?\.photo\.json$/;
53
+
54
+ export const GONE = 'That copy is gone; copy it again.';
55
+ export const CHANGED = 'That copy changed on the way; copy it again.';
56
+ export const TOO_BIG = 'That copy has too many pictures to paste in another project.';
57
+
58
+ /** A content-addressed picture, a photo sidecar, or nothing that can cross (a renamed `assets/logo.png`). */
59
+ export function assetShape(rel: string): { kind: 'cas' | 'sidecar'; sha8: string } | null {
60
+ const side = SIDECAR_RE.exec(rel);
61
+ if (side) return { kind: 'sidecar', sha8: side[1] as string };
62
+ const cas = CAS_RE.exec(rel);
63
+ return cas ? { kind: 'cas', sha8: cas[1] as string } : null;
64
+ }
65
+
66
+ const sha256 = (b: Uint8Array) => createHash('sha256').update(b).digest('hex');
67
+
68
+ /** `rel` under the design root, real path (symlinks followed) still inside it; null = outside or missing. */
69
+ function inside(designRoot: string, rel: string): string | null {
70
+ if (!isDesignRel(rel)) return null;
71
+ try {
72
+ const root = realpathSync(designRoot);
73
+ const real = realpathSync(resolve(root, rel));
74
+ return real.startsWith(root + sep) ? real : null;
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ function fileSha(designRoot: string, rel: string): string | null {
81
+ const abs = inside(designRoot, rel);
82
+ if (!abs) return null;
83
+ try {
84
+ if (!statSync(abs).isFile()) return null;
85
+ return sha256(readFileSync(abs));
86
+ } catch {
87
+ return null;
88
+ }
89
+ }
90
+
91
+ export interface ClipExport extends Omit<ClipTransfer, 'carry'> {
92
+ carry: ClipTransfer['carry'];
93
+ /** every module a carried relative import names, with its sha256 here (null = not here) */
94
+ modules: Array<{ path: string; sha256: string | null }>;
95
+ /** the content-addressed pictures (+ sidecars) that cross */
96
+ assets: Array<{ rel: string; size: number }>;
97
+ }
98
+
99
+ export type Refusal = { ok: false; status: number; error: string; message?: string };
100
+
101
+ /** The source half: what crosses for clip `id`. */
102
+ export function exportForShell(
103
+ id: string,
104
+ designRoot: string
105
+ ): { ok: true; body: ClipExport } | Refusal {
106
+ const clip = exportClip(id);
107
+ if (!clip) return { ok: false, status: 404, error: 'gone', message: GONE };
108
+ const modules = new Map<string, string | null>();
109
+ for (const i of clip.carry.imports)
110
+ if (i.spec.startsWith('.') && i.module && !modules.has(i.module))
111
+ modules.set(i.module, fileSha(designRoot, i.module));
112
+ const assets: Array<{ rel: string; size: number }> = [];
113
+ let total = 0;
114
+ for (const rel of clip.carry.assets) {
115
+ if (!assetShape(rel)) continue;
116
+ const abs = inside(designRoot, rel);
117
+ if (!abs) continue;
118
+ let size: number;
119
+ try {
120
+ const st = statSync(abs);
121
+ if (!st.isFile()) continue;
122
+ size = st.size;
123
+ } catch {
124
+ continue;
125
+ }
126
+ total += size;
127
+ assets.push({ rel, size });
128
+ }
129
+ if (total > CLIP_ASSETS_MAX_BYTES || assets.length > CLIP_ASSETS_MAX)
130
+ return { ok: false, status: 413, error: 'too-big', message: TOO_BIG };
131
+ return {
132
+ ok: true,
133
+ body: { ...clip, modules: [...modules].map(([path, s]) => ({ path, sha256: s })), assets },
134
+ };
135
+ }
136
+
137
+ /** The source half of `clip-asset`: the file of one asset clip `id` lists; null = not one of its assets. */
138
+ export function assetForShell(id: string, rel: string, designRoot: string): string | null {
139
+ const clip = exportClip(id);
140
+ if (!clip?.carry.assets.includes(rel) || !assetShape(rel)) return null;
141
+ const abs = inside(designRoot, rel);
142
+ try {
143
+ return abs && statSync(abs).isFile() ? abs : null;
144
+ } catch {
145
+ return null;
146
+ }
147
+ }
148
+
149
+ /** Split Rust's frame; null = not one. */
150
+ export function parseFrame(buf: Uint8Array): { header: unknown; blobs: Uint8Array } | null {
151
+ if (buf.length < 4) return null;
152
+ const n = new DataView(buf.buffer, buf.byteOffset, buf.byteLength).getUint32(0);
153
+ if (n > CLIP_HEADER_MAX_BYTES || 4 + n > buf.length) return null;
154
+ try {
155
+ const header = JSON.parse(
156
+ new TextDecoder('utf-8', { fatal: true }).decode(buf.subarray(4, 4 + n))
157
+ );
158
+ return { header, blobs: buf.subarray(4 + n) };
159
+ } catch {
160
+ return null;
161
+ }
162
+ }
163
+
164
+ const isRec = (v: unknown): v is Record<string, unknown> =>
165
+ v !== null && typeof v === 'object' && !Array.isArray(v);
166
+
167
+ const whatUses = (t: ClipTransfer) =>
168
+ t.kind === 'artboards'
169
+ ? t.items.length === 1
170
+ ? 'That artboard uses'
171
+ : 'Those artboards use'
172
+ : t.items.length === 1
173
+ ? 'That object uses'
174
+ : 'Those objects use';
175
+
176
+ const copyOver = (t: ClipTransfer, rel: string) =>
177
+ `${whatUses(t)} ${rel}, which this project doesn’t have. Copy that file over first.`;
178
+
179
+ /**
180
+ * An SVG crosses only as the import-asset sanitizer (bin/_import-asset.mjs) leaves it: sanitizing it again
181
+ * changes nothing. One that came in another way is brought in through import-asset, not the clip lane.
182
+ */
183
+ function svgAsSanitized(bytes: Uint8Array): boolean {
184
+ try {
185
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
186
+ return sanitizeSvgAllowlist(text) === text;
187
+ } catch {
188
+ return false;
189
+ }
190
+ }
191
+
192
+ /** The target half: check everything, then write the pictures and keep the clip. */
193
+ export function importFromShell(
194
+ frame: { header: unknown; blobs: Uint8Array },
195
+ designRoot: string
196
+ ): { ok: true; handle: ClipHandle; wrote: number } | Refusal {
197
+ const invalid: Refusal = { ok: false, status: 400, error: 'invalid' };
198
+ const { header, blobs } = frame;
199
+ if (!isRec(header) || !isRec(header.clip)) return invalid;
200
+ const t = checkTransfer(header.clip);
201
+ const project = header.project;
202
+ if (!t || typeof project !== 'string' || !project.trim() || project.length > 200) return invalid;
203
+
204
+ // a carried relative import is kept only when this project has the very same file
205
+ const sent = new Map<string, string | null>();
206
+ const mods = header.clip.modules;
207
+ if (!Array.isArray(mods) || mods.length > 64) return invalid;
208
+ for (const m of mods) {
209
+ if (!isRec(m) || !isDesignRel(m.path)) return invalid;
210
+ if (!(m.sha256 === null || (typeof m.sha256 === 'string' && /^[0-9a-f]{64}$/.test(m.sha256))))
211
+ return invalid;
212
+ sent.set(m.path, m.sha256);
213
+ }
214
+ for (const i of t.carry.imports) {
215
+ if (!i.spec.startsWith('.')) continue;
216
+ const want = i.module ? sent.get(i.module) : null;
217
+ if (!i.module || !want || fileSha(designRoot, i.module) !== want)
218
+ return {
219
+ ok: false,
220
+ status: 409,
221
+ error: 'module-missing',
222
+ message: `${whatUses(t)} ${i.local} from ${i.module ?? i.spec}, which this project doesn’t have. Copy that file over first.`,
223
+ };
224
+ }
225
+
226
+ // the pictures: listed by the clip, shaped, sized, and their bytes what their names say
227
+ const list = header.assets;
228
+ if (!Array.isArray(list) || list.length > CLIP_ASSETS_MAX) return invalid;
229
+ const listed = new Set(t.carry.assets);
230
+ const files: Array<{ rel: string; bytes: Uint8Array }> = [];
231
+ const seen = new Set<string>();
232
+ let at = 0;
233
+ for (const a of list) {
234
+ if (!isRec(a) || typeof a.rel !== 'string' || !Number.isSafeInteger(a.size)) return invalid;
235
+ const size = a.size as number;
236
+ if (size < 0 || seen.has(a.rel) || !listed.has(a.rel) || !assetShape(a.rel)) return invalid;
237
+ seen.add(a.rel);
238
+ if (at + size > blobs.length) return invalid;
239
+ files.push({ rel: a.rel, bytes: blobs.subarray(at, at + size) });
240
+ at += size;
241
+ }
242
+ if (at !== blobs.length || at > CLIP_ASSETS_MAX_BYTES) return invalid;
243
+
244
+ // a file under assets/ that is not media never crosses: the person copies it over first, as with a module
245
+ for (const rel of t.carry.assets)
246
+ if (!isClipMedia(rel) && !SIDECAR_RE.test(rel) && !inside(designRoot, rel))
247
+ return { ok: false, status: 409, error: 'asset-not-media', message: copyOver(t, rel) };
248
+ const pictures = new Set<string>();
249
+ for (const f of files) {
250
+ const shape = assetShape(f.rel) as { kind: 'cas' | 'sidecar'; sha8: string };
251
+ if (shape.kind !== 'cas') continue;
252
+ if (sha256(f.bytes).slice(0, 8) !== shape.sha8)
253
+ return { ok: false, status: 422, error: 'asset-mismatch', message: CHANGED };
254
+ if (f.rel.endsWith('.svg') && !svgAsSanitized(f.bytes))
255
+ return { ok: false, status: 422, error: 'asset-not-media', message: copyOver(t, f.rel) };
256
+ pictures.add(shape.sha8);
257
+ }
258
+ for (const f of files) {
259
+ const shape = assetShape(f.rel) as { kind: 'cas' | 'sidecar'; sha8: string };
260
+ if (shape.kind !== 'sidecar') continue;
261
+ if (f.bytes.length > SIDECAR_MAX_BYTES || !pictures.has(shape.sha8))
262
+ return { ok: false, status: 422, error: 'asset-mismatch', message: CHANGED };
263
+ try {
264
+ if (!isRec(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(f.bytes))))
265
+ throw new Error('not an object');
266
+ } catch {
267
+ return { ok: false, status: 422, error: 'asset-mismatch', message: CHANGED };
268
+ }
269
+ }
270
+
271
+ // every check passed: write what is not here yet, then keep the clip
272
+ let wrote = 0;
273
+ if (files.length) {
274
+ let dir: string;
275
+ try {
276
+ const root = realpathSync(designRoot);
277
+ dir = join(root, 'assets');
278
+ if (existsSync(dir)) {
279
+ if (lstatSync(dir).isSymbolicLink() || !statSync(dir).isDirectory())
280
+ return { ok: false, status: 409, error: 'assets-dir' };
281
+ } else mkdirSync(dir);
282
+ } catch {
283
+ return { ok: false, status: 500, error: 'assets-dir' };
284
+ }
285
+ for (const f of files) {
286
+ // never a name that is not media or a sidecar (checked above; held again at the one write)
287
+ if (!assetShape(f.rel)) return invalid;
288
+ const name = f.rel.slice('assets/'.length);
289
+ const abs = join(dir, name);
290
+ if (existsSync(abs)) continue;
291
+ const tmp = join(dir, `.tmp-clip-${randomBytes(6).toString('hex')}`);
292
+ try {
293
+ writeFileSync(tmp, f.bytes, { flag: 'wx' });
294
+ renameSync(tmp, abs);
295
+ wrote++;
296
+ } catch {
297
+ return { ok: false, status: 500, error: 'asset-write' };
298
+ }
299
+ }
300
+ }
301
+ return { ok: true, handle: keepTransfer(t, project.trim()), wrote };
302
+ }
@@ -0,0 +1,108 @@
1
+ // The terminal-started server's key file — contract `client/v2/contracts/sec-loopback-bearer.md` §7.5.
2
+ //
3
+ // A server started from a terminal (`maude design serve`, `maude design server-up`: role `cli`,
4
+ // shell/cli-yield.ts) mints its own API key (shell/api-key.ts) and is in required mode, like a
5
+ // desktop spawn. The CLI on this machine needs that key to reach it, so the server writes
6
+ // `{ v:1, port, pid, rootId, apiKey }` to `<state>/maude/servers/<rootId>.json`:
7
+ // • `<state>` is `$XDG_STATE_HOME` when absolute, else `~/.local/state` — a per-user directory
8
+ // OUTSIDE the project, so nothing in the design root (synced, committed, readable by the AI
9
+ // through ordinary file tools) ever holds it;
10
+ // • the directory is 0700 and the file 0600 (atomic tmp + rename, sync/atomic-write.ts);
11
+ // • the server removes the file on shutdown when it still names this process.
12
+ // Only the CLI reads it (cli/lib/desktop-locate.mjs `terminalKeyFor`), and only for a port the
13
+ // project's own `/_health` check already tied to this root.
14
+
15
+ import { randomBytes } from 'node:crypto';
16
+ import { chmodSync, lstatSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
17
+ import { homedir } from 'node:os';
18
+ import { isAbsolute, join } from 'node:path';
19
+
20
+ import { atomicWrite } from '../sync/atomic-write.ts';
21
+
22
+ export interface ServerKeyRecord {
23
+ v: 1;
24
+ port: number;
25
+ pid: number;
26
+ rootId: string;
27
+ apiKey: string;
28
+ }
29
+
30
+ /** `<state>/maude/servers` for this user (the CLI's copy is desktop-locate.mjs `serverKeyDir`). */
31
+ export function serverKeyDir(env: Record<string, string | undefined> = process.env): string {
32
+ const s = env.XDG_STATE_HOME;
33
+ const state = s && isAbsolute(s) ? s : join(env.HOME || homedir(), '.local', 'state');
34
+ return join(state, 'maude', 'servers');
35
+ }
36
+
37
+ const ROOT_ID_RE = /^[0-9a-f]{12}$/;
38
+
39
+ /**
40
+ * Write the record; returns its path, or null when it could not be written (logged — the server
41
+ * still serves, and its printed link still opens it; the CLI then reports no studio).
42
+ */
43
+ export function writeServerKeyFile(
44
+ rec: Omit<ServerKeyRecord, 'v'>,
45
+ env: Record<string, string | undefined> = process.env
46
+ ): string | null {
47
+ if (!ROOT_ID_RE.test(rec.rootId)) return null;
48
+ const dir = serverKeyDir(env);
49
+ try {
50
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
51
+ const st = lstatSync(dir);
52
+ const uid = typeof process.getuid === 'function' ? process.getuid() : null;
53
+ if (!st.isDirectory() || (uid !== null && st.uid !== uid)) {
54
+ console.warn(
55
+ '[maude] the server key directory is not a directory of this user; not written.'
56
+ );
57
+ return null;
58
+ }
59
+ if ((st.mode & 0o077) !== 0) chmodSync(dir, 0o700);
60
+ const path = join(dir, `${rec.rootId}.json`);
61
+ atomicWrite(path, `${JSON.stringify({ v: 1, ...rec })}\n`);
62
+ return path;
63
+ } catch (e) {
64
+ console.warn(`[maude] could not write the server key file: ${(e as Error).message}`);
65
+ return null;
66
+ }
67
+ }
68
+
69
+ /** Remove `path` when it still names `pid` (a newer server for the same root keeps its own). */
70
+ export function removeServerKeyFile(path: string | null, pid = process.pid): void {
71
+ if (!path) return;
72
+ try {
73
+ const rec = JSON.parse(readFileSync(path, 'utf8')) as Partial<ServerKeyRecord>;
74
+ if (rec.pid === pid) unlinkSync(path);
75
+ } catch {
76
+ /* gone already, or not ours */
77
+ }
78
+ }
79
+
80
+ /**
81
+ * re-check A/C — `<state>/maude/servers/links`: where the server leaves a one-time opening link for a
82
+ * capture helper it spawns (the bug-report shell capture → `screenshot.sh --url-file`). Inside the key
83
+ * folder the AI chat's Read is denied (`credentialDenyRules`), so the link never sits in a folder the
84
+ * agent reads; the helper takes only a file from here (bin/_url-guard.mjs `takeLinkFile`).
85
+ */
86
+ export function serverLinkDir(env: Record<string, string | undefined> = process.env): string {
87
+ return join(serverKeyDir(env), 'links');
88
+ }
89
+
90
+ /** Write `url` to a fresh `<serverLinkDir>/<32 hex>.url` (0600, 0700 folder); its path, or null. */
91
+ export function writeLinkFile(
92
+ url: string,
93
+ env: Record<string, string | undefined> = process.env
94
+ ): string | null {
95
+ const dir = serverLinkDir(env);
96
+ try {
97
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
98
+ const st = lstatSync(dir);
99
+ const uid = typeof process.getuid === 'function' ? process.getuid() : null;
100
+ if (!st.isDirectory() || (uid !== null && st.uid !== uid)) return null;
101
+ if ((st.mode & 0o077) !== 0) chmodSync(dir, 0o700);
102
+ const path = join(dir, `${randomBytes(16).toString('hex')}.url`);
103
+ writeFileSync(path, `${url}\n`, { mode: 0o600, flag: 'wx' });
104
+ return path;
105
+ } catch {
106
+ return null;
107
+ }
108
+ }