@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
@@ -42,7 +42,7 @@ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync
42
42
  import path from 'node:path';
43
43
 
44
44
  import { hashBytes } from './echo-guard.ts';
45
- import type { LaneProposal, ProposalOutcome } from './projection.ts';
45
+ import type { LaneProposal, ProposalLane, ProposalOutcome } from './projection.ts';
46
46
  import { mergeSource } from './source-merge.ts';
47
47
  import type { Operation, ProposalResult } from './transaction-client.ts';
48
48
 
@@ -92,15 +92,17 @@ export interface RunStage {
92
92
  touched: Record<string, string[]>;
93
93
  /**
94
94
  * p8-a1-claims (Michal 2026-10-29) — EVERY run is claim-only: it takes a write only when a tool
95
- * claimed exactly those bytes for it (`claim`), never because it is the one run open. The one named
96
- * exception is a call that cannot claim (S7 interpreter, terminal-lane verb): while it is open
97
- * (`shellCalls`, call → the canvases its command names) or within SHELL_SETTLE_MS of it closing
98
- * (`shellClosed`), an unclaimed write to ONE OF THOSE canvases joins the run. p8-sec2-attrib A1 — a
99
- * call that names none (a glob, `find -exec`, a computed name) covers EVERY canvas (`ALL_CANVASES`):
100
- * only outside writes reach the stage at all (a person's studio save is never stageable).
95
+ * claimed exactly those bytes for it (`claim`), never because it is the one run open. #164 T5.1 — a
96
+ * call that cannot claim (S7 interpreter, terminal-lane verb) no longer lifts that: while its window
97
+ * is open (`shellCalls`, call → the canvases it covers; p8-sec2-attrib A1 `ALL_CANVASES` for a call
98
+ * that names none), and after it closes until its settle (at most SETTLE_WAIT_MS), an unclaimed
99
+ * outside write to a covered canvas is PARKED — neither staged nor proposed. The call's settle
100
+ * (`settleShellCall`, the hook's post-call bytes, claimed first) moves the parked writes whose bytes
101
+ * it claimed into the run as one write and releases every other one as outside. Every failure
102
+ * releases as outside; nothing falls to the AI. A person's studio save is never stageable, so it is
103
+ * never parked.
101
104
  */
102
- shellCalls?: Map<string, ShellSlugs>;
103
- shellClosed?: Array<{ slugs: ShellSlugs; at: number }>;
105
+ shellCalls?: Map<string, ShellCall>;
104
106
  /**
105
107
  * p8-a1-claims (F17) — canvases this run DELETED (a claimed `maude design trash move`): doc id → the
106
108
  * canvas path. Published as `doc.delete` in the run's one action, so its undo brings the canvas back.
@@ -192,11 +194,82 @@ export interface ActionStageOptions {
192
194
  base: string;
193
195
  content: string;
194
196
  }) => void;
197
+ /**
198
+ * #164 — parked writes to one canvas released as OUTSIDE (no run), in arrival order: send them as
199
+ * the writes they were. Absent: one `edit` proposal per canvas through `propose`.
200
+ */
201
+ release?: (w: { slug: string; doc: string; writes: LaneProposal[] }) => Promise<ProposalOutcome>;
202
+ /**
203
+ * D1 — merge a canvas lane's parked writes into one (first base, last bytes). Only for a `release`
204
+ * that sends a canvas's writes as ONE change anyway (the default and the local home); a release
205
+ * that sends each write as its own edit (a hub link) keeps them apart. Default: no `release` given.
206
+ */
207
+ mergeParked?: boolean;
208
+ }
209
+
210
+ /** #164 — one call's window: what it covers, and (once closed) the wait for its settle. */
211
+ interface ShellCall {
212
+ slugs: ShellSlugs;
213
+ closedAt?: number;
214
+ settleTimer?: ReturnType<typeof setTimeout>;
215
+ staleTimer?: ReturnType<typeof setTimeout>;
216
+ /** D4 — canvases it covered that left the disk while it was open (a settle may bind only these). */
217
+ gone?: Set<string>;
218
+ }
219
+
220
+ /**
221
+ * #164 N2 — what a call's settle claimed: one lane of a canvas. A bare slug is its source (`html`) lane;
222
+ * a `.meta.json` / `.annotations.json` file claims only its own lane (`shellClaimLane`).
223
+ */
224
+ export type ShellClaim = string | { slug: string; lane: ProposalLane };
225
+
226
+ /** #164 N2 — the lane a claimed design file is: its layout, its board, else its source. */
227
+ export function shellClaimLane(rel: string): ProposalLane {
228
+ if (/\.meta\.json$/i.test(rel)) return 'meta';
229
+ if (/\.annotations\.json$/i.test(rel)) return 'annotations';
230
+ return 'html';
231
+ }
232
+
233
+ /** #164 — an unclaimed outside write a window holds back until the call settles. */
234
+ interface Parked {
235
+ slug: string;
236
+ doc: string;
237
+ p: LaneProposal;
238
+ resolve: (o: ProposalOutcome) => void;
239
+ /** D1 — the transactions merged into this entry (first base, last bytes), first one first. */
240
+ txs: string[];
241
+ /** The windows (`callKey`) that keep it parked; empty = it only waits behind an earlier one. */
242
+ keys: Set<string>;
243
+ /** F1 — the windows that covered it when it parked: only a settle of one of them may claim it. */
244
+ wins: ReadonlySet<string>;
245
+ /** F1 — the settle of this run claimed the canvas: its bytes, when they arrive, take this along. */
246
+ joinRun?: string;
195
247
  }
196
248
 
197
249
  const STOPPED = ' — stopped';
198
- /** A1 — the watcher delivers a verb's last write a beat after the call returns (cf. AI settle 250 ms). */
250
+ /**
251
+ * A1 — the watcher delivers a verb's last write a beat after the call returns (cf. AI settle 250 ms).
252
+ * #164 — it no longer admits unclaimed writes into a run; a person's held save (ai/save-hold.ts) still
253
+ * lands this long after the window closes.
254
+ */
199
255
  export const SHELL_SETTLE_MS = 1_000;
256
+ /**
257
+ * #164 — a closed window parks until its settle arrives, at most this long (the hook's post-call
258
+ * timeout is 5 s); then its parked writes are released as outside.
259
+ */
260
+ export const SETTLE_WAIT_MS = 3_000;
261
+ /** #164 — a window that never closes (a killed call, no PostToolUse) releases at this age. */
262
+ export const SHELL_STALE_MS = 10 * 60_000;
263
+ /** D1 — at most this many parked entries, and this many bytes of them, at once. */
264
+ export const PARKED_MAX = 1_024;
265
+ export const PARKED_MAX_BYTES = 64 * 1024 * 1024;
266
+ const unref = (t: ReturnType<typeof setTimeout>) => {
267
+ (t as { unref?: () => void }).unref?.();
268
+ return t;
269
+ };
270
+ const callKey = (runId: string, call: string) => `${runId}\u0000${call}`;
271
+ /** What `runsHolding` names for a dependency on a parked write (never a run id: RUN_ID has no `#`). */
272
+ const PARKED = '#parked';
200
273
 
201
274
  /** p8-sec2-attrib A1 — the window of a call that names no canvas: it covers every one. */
202
275
  const ALL_CANVASES = '*' as const;
@@ -223,6 +296,8 @@ export function createActionStage(opts: ActionStageOptions) {
223
296
  const dependents: Dependent[] = [];
224
297
  /** A staged transaction id → the run transaction that carried it. */
225
298
  const alias = new Map<string, string>();
299
+ /** #164 — parked writes, in arrival order (see `RunStage.shellCalls`). */
300
+ const parked: Parked[] = [];
226
301
 
227
302
  const runOf = (keyOrRun: string): RunStage | undefined =>
228
303
  runs.get(keyRun.get(keyOrRun) ?? keyOrRun);
@@ -459,38 +534,404 @@ export function createActionStage(opts: ActionStageOptions) {
459
534
  changed();
460
535
  }
461
536
 
462
- /** A1 — open/close the window of one call that cannot claim (no `shell`: nothing changes). */
537
+ /**
538
+ * A1 / #164 — open/close the window of one call that cannot claim (no `shell`: nothing changes).
539
+ * The ACP tracker and the design hook may both open the same call (its tool call id): the window
540
+ * covers what either named. Closing it starts the wait for its settle.
541
+ */
463
542
  function shellWindow(
464
543
  r: RunStage,
465
544
  shell: { call: string; open: boolean; slugs?: string[]; all?: boolean } | undefined
466
545
  ): void {
467
546
  if (!shell) return;
468
547
  r.shellCalls ??= new Map();
548
+ const prev = r.shellCalls.get(shell.call);
469
549
  if (shell.open) {
470
- if (shell.all) {
471
- r.shellCalls.set(shell.call, ALL_CANVASES);
550
+ const named = new Set(shell.slugs ?? []);
551
+ if (!shell.all && !named.size && !prev) return;
552
+ const slugs: ShellSlugs =
553
+ shell.all || prev?.slugs === ALL_CANVASES
554
+ ? ALL_CANVASES
555
+ : new Set([...((prev?.slugs as Set<string> | undefined) ?? []), ...named]);
556
+ if (prev?.settleTimer) clearTimeout(prev.settleTimer);
557
+ const call = shell.call;
558
+ r.shellCalls.set(call, {
559
+ slugs,
560
+ ...(prev?.gone ? { gone: prev.gone } : {}),
561
+ staleTimer:
562
+ prev?.staleTimer ??
563
+ unref(setTimeout(() => releaseShellCall(r.runId, call, 'stale'), SHELL_STALE_MS)),
564
+ });
565
+ return;
566
+ }
567
+ if (!prev || prev.closedAt !== undefined) return;
568
+ prev.closedAt = now();
569
+ const call = shell.call;
570
+ prev.settleTimer = unref(
571
+ setTimeout(() => releaseShellCall(r.runId, call, 'no-settle'), SETTLE_WAIT_MS)
572
+ );
573
+ }
574
+
575
+ /** #164 — the windows (open, or closed and waiting for their settle) that cover `slug`. */
576
+ function coveringKeys(slug: string): string[] {
577
+ const out: string[] = [];
578
+ for (const r of runs.values()) {
579
+ if (r.state !== 'open') continue;
580
+ for (const [call, c] of r.shellCalls ?? [])
581
+ if (coversShellSlug(c.slugs, slug)) out.push(callKey(r.runId, call));
582
+ }
583
+ return out;
584
+ }
585
+
586
+ /** #164 — would an unclaimed write to `slug` park? (a window covers it, or one waits before it) */
587
+ const parks = (slug: string) =>
588
+ parked.some((e) => e.slug === slug) || coveringKeys(slug).length > 0;
589
+
590
+ const clearCall = (c: ShellCall) => {
591
+ if (c.settleTimer) clearTimeout(c.settleTimer);
592
+ if (c.staleTimer) clearTimeout(c.staleTimer);
593
+ };
594
+
595
+ /**
596
+ * #164 — take call `call`'s window out of run `r` only: its key (none when `r` has no such window).
597
+ * Another run's window under the same call id is not this caller's to end.
598
+ */
599
+ function detachCall(r: RunStage | undefined, call: string): Set<string> {
600
+ const c = r?.shellCalls?.get(call);
601
+ if (!r || !c) return new Set();
602
+ clearCall(c);
603
+ r.shellCalls?.delete(call);
604
+ return new Set([callKey(r.runId, call)]);
605
+ }
606
+
607
+ /** #164 — take every window of run `r` out (the run ends): their keys. */
608
+ function detachRunCalls(r: RunStage): Set<string> {
609
+ const keys = new Set<string>();
610
+ for (const [call, c] of r.shellCalls ?? []) {
611
+ clearCall(c);
612
+ keys.add(callKey(r.runId, call));
613
+ }
614
+ r.shellCalls?.clear();
615
+ return keys;
616
+ }
617
+
618
+ /** Did run `r` claim exactly `content` for `slug`? */
619
+ const claimedBy = (r: RunStage, slug: string, content: string) =>
620
+ claims.get(r.runId)?.hashes.has(`${slug}|${hashBytes(content)}`) === true;
621
+
622
+ const sameKeys = (a: ReadonlySet<string>, b: readonly string[]) =>
623
+ a.size === b.length && b.every((k) => a.has(k));
624
+
625
+ function park(slug: string, doc: string, p: LaneProposal): Promise<ProposalOutcome> {
626
+ return new Promise((resolve) => {
627
+ const keys = coveringKeys(slug);
628
+ // D1 — the same canvas lane, parked again under the same windows, is one entry: the first base,
629
+ // the last bytes (a release or a join sends exactly that); its transactions and waiters ride along
630
+ let last: Parked | undefined;
631
+ for (let i = parked.length - 1; i >= 0 && !last; i--)
632
+ if (parked[i].slug === slug && parked[i].p.lane === p.lane) last = parked[i];
633
+ if (
634
+ mergeParked &&
635
+ last &&
636
+ !last.joinRun &&
637
+ sameKeys(last.keys, keys) &&
638
+ sameKeys(last.wins, keys)
639
+ ) {
640
+ const prev = last.resolve;
641
+ last.p = {
642
+ ...p,
643
+ baseContent: last.p.baseContent,
644
+ transactionId: last.p.transactionId,
645
+ ...(last.p.create ? { create: last.p.create } : {}),
646
+ };
647
+ last.txs.push(p.transactionId);
648
+ last.resolve = (o) => {
649
+ prev(o);
650
+ resolve(o);
651
+ };
652
+ capParked();
472
653
  return;
473
654
  }
474
- const slugs = new Set(shell.slugs ?? []);
475
- if (slugs.size) r.shellCalls.set(shell.call, slugs);
476
- return;
655
+ parked.push({
656
+ slug,
657
+ doc,
658
+ p,
659
+ resolve,
660
+ txs: [p.transactionId],
661
+ keys: new Set(keys),
662
+ wins: new Set(keys),
663
+ });
664
+ capParked();
665
+ });
666
+ }
667
+
668
+ const parkedSize = (e: Parked) => e.p.content.length + e.p.baseContent.length;
669
+
670
+ /**
671
+ * D1 — parked writes are bounded (entries and bytes). Past a cap the oldest canvas's parked writes go
672
+ * out as outside — the failure every other path has — and the log says so.
673
+ */
674
+ function capParked(): void {
675
+ let bytes = 0;
676
+ for (const e of parked) bytes += parkedSize(e);
677
+ while (parked.length && (parked.length > PARKED_MAX || bytes > PARKED_MAX_BYTES)) {
678
+ const slug = parked[0].slug;
679
+ const out = parked.filter((e) => e.slug === slug);
680
+ for (const e of out) bytes -= parkedSize(e);
681
+ log.warn(
682
+ `[sync/ai] too many writes held for running AI calls: ${slug} is recorded as an outside change.`
683
+ );
684
+ sendOutside(slug, out);
477
685
  }
478
- const was = r.shellCalls.get(shell.call);
479
- if (!was) return;
480
- r.shellCalls.delete(shell.call);
481
- const t = now();
482
- r.shellClosed = [
483
- ...(r.shellClosed ?? []).filter((c) => t - c.at <= SHELL_SETTLE_MS),
484
- { slugs: was, at: t },
485
- ];
486
686
  }
487
687
 
488
- /** May `r` take a write to `slug` nobody claimed? Only inside a named-file window (S7 fallback). */
489
- const takesUnclaimed = (r: RunStage, slug: string) =>
490
- [...(r.shellCalls?.values() ?? [])].some((s) => coversShellSlug(s, slug)) ||
491
- (r.shellClosed ?? []).some(
492
- (c) => now() - c.at <= SHELL_SETTLE_MS && coversShellSlug(c.slugs, slug)
688
+ function unpark(list: readonly Parked[]): void {
689
+ for (const e of list) {
690
+ const i = parked.indexOf(e);
691
+ if (i >= 0) parked.splice(i, 1);
692
+ }
693
+ }
694
+
695
+ /**
696
+ * #164 — parked writes `entries` (one lane, arrival order) join run `r` as ONE write: the first
697
+ * one's base → the last one's bytes.
698
+ */
699
+ function joinParked(r: RunStage, entries: readonly Parked[]): void {
700
+ if (!entries.length) return;
701
+ unpark(entries);
702
+ const first = entries[0];
703
+ const last = entries[entries.length - 1];
704
+ const create = entries.find((e) => e.p.create)?.p.create;
705
+ void stageWrite(
706
+ r,
707
+ last.slug,
708
+ last.doc,
709
+ { ...last.p, baseContent: first.p.baseContent, ...(create ? { create } : {}) },
710
+ entries
711
+ );
712
+ }
713
+
714
+ /** #164 — parked writes `out` of canvas `slug` go out as OUTSIDE (no run), in arrival order. */
715
+ function sendOutside(slug: string, out: readonly Parked[]): void {
716
+ if (!out.length) return;
717
+ unpark(out);
718
+ let sent: Promise<ProposalOutcome>;
719
+ try {
720
+ sent = release({ slug, doc: out[0].doc, writes: out.map((e) => e.p) });
721
+ } catch (err) {
722
+ sent = Promise.reject(err);
723
+ }
724
+ const settled = sent.catch(
725
+ (err: unknown): ProposalOutcome => ({
726
+ status: 'rejected',
727
+ code: (err as { code?: string })?.code ?? 'retryable',
728
+ })
493
729
  );
730
+ for (const e of out) void settled.then(e.resolve);
731
+ }
732
+
733
+ /** #164 — the parked writes of `slug` no window keeps any more go out as outside, in order. */
734
+ function releasePrefix(slug: string): void {
735
+ const out: Parked[] = [];
736
+ for (const e of parked) {
737
+ if (e.slug !== slug) continue;
738
+ if (e.keys.size) break;
739
+ out.push(e);
740
+ }
741
+ sendOutside(slug, out);
742
+ }
743
+
744
+ /**
745
+ * F1 — `entries` (one lane of `slug`, the call's own parked writes) join run `r`. Every OTHER write
746
+ * parked on that lane before them — a person's save, another run's or another call's write — is not
747
+ * the call's: it goes out as outside FIRST, so the run's write lands on top of it, never absorbs it.
748
+ */
749
+ function joinOwn(r: RunStage, slug: string, lane: string, entries: readonly Parked[]): void {
750
+ const lastAt = parked.indexOf(entries[entries.length - 1]);
751
+ sendOutside(
752
+ slug,
753
+ parked.filter(
754
+ (e, i) => i < lastAt && e.slug === slug && e.p.lane === lane && !entries.includes(e)
755
+ )
756
+ );
757
+ joinParked(r, entries);
758
+ }
759
+
760
+ /**
761
+ * #164 — windows `keys` no longer hold their parked writes. Only a SETTLE moves parked writes into
762
+ * a run (F1): the settling run's own call's writes (`settle.key` covered them when they parked), on a
763
+ * canvas it claimed, whose last bytes it claimed. A claimed canvas whose bytes have not reached the
764
+ * watcher yet waits for them (at most SETTLE_WAIT_MS). Everything else is released as outside.
765
+ */
766
+ function resolveKeys(
767
+ keys: ReadonlySet<string>,
768
+ settle?: {
769
+ run: RunStage;
770
+ key: string;
771
+ /** N2 — slug → the lanes whose files the settle claimed */
772
+ claimed: ReadonlyMap<string, ReadonlySet<string>>;
773
+ awaitKey: string;
774
+ }
775
+ ): void {
776
+ if (!keys.size) return;
777
+ const slugs = new Set<string>();
778
+ for (const e of parked) {
779
+ let hit = false;
780
+ for (const k of keys) if (e.keys.delete(k)) hit = true;
781
+ if (hit) slugs.add(e.slug);
782
+ }
783
+ let waits = false;
784
+ for (const slug of slugs) {
785
+ // N2 — only the lanes whose files the settle claimed (a create's other lanes follow its claimed
786
+ // source); an unclaimed sibling lane parked in the same window goes out as outside below
787
+ const ofClaim = settle?.claimed.get(slug);
788
+ const mine =
789
+ settle && ofClaim
790
+ ? parked.filter(
791
+ (e) =>
792
+ e.slug === slug &&
793
+ e.wins.has(settle.key) &&
794
+ (ofClaim.has(e.p.lane) || (!!e.p.create && ofClaim.has('html')))
795
+ )
796
+ : [];
797
+ if (settle && mine.length) {
798
+ const lanes = [...new Set(mine.map((e) => e.p.lane))];
799
+ const ofLane = (l: string) => mine.filter((e) => e.p.lane === l);
800
+ const matched = (l: string) => {
801
+ const last = ofLane(l).at(-1);
802
+ return !!last && claimedBy(settle.run, slug, last.p.content);
803
+ };
804
+ // a new canvas follows its source: claimed html bytes take every lane of the create along
805
+ const create = mine.some((e) => e.p.create);
806
+ const join = create ? (matched('html') ? lanes : []) : lanes.filter(matched);
807
+ for (const l of join) joinOwn(settle.run, slug, l, ofLane(l));
808
+ // the settle claimed this canvas, but the watcher has not delivered those bytes yet
809
+ for (const l of lanes) {
810
+ if (join.includes(l)) continue;
811
+ for (const e of ofLane(l)) {
812
+ e.joinRun = settle.run.runId;
813
+ e.keys.add(settle.awaitKey);
814
+ }
815
+ waits = true;
816
+ }
817
+ }
818
+ releasePrefix(slug);
819
+ }
820
+ if (waits && settle) {
821
+ const k = settle.awaitKey;
822
+ unref(setTimeout(() => resolveKeys(new Set([k])), SETTLE_WAIT_MS));
823
+ }
824
+ releaseDependents();
825
+ }
826
+
827
+ /**
828
+ * #164 — call `call`'s settle arrived: the hook re-read its post-call bytes and the studio CLAIMED
829
+ * the ones the disk still holds (`claimed`: their canvases). Its window closes; parked writes
830
+ * whose bytes are claimed join the claiming run as one write, the rest go out as outside.
831
+ */
832
+ function settleShellCall(
833
+ keyOrRun: string,
834
+ call: string,
835
+ claimed: readonly ShellClaim[] = []
836
+ ): boolean {
837
+ const r = runOf(keyOrRun);
838
+ // a settle for a call this run has no window for is refused: it resolves nothing
839
+ if (r?.state !== 'open' || !r.shellCalls?.has(call)) return false;
840
+ const key = callKey(r.runId, call);
841
+ const lanes = new Map<string, Set<string>>();
842
+ for (const c of claimed) {
843
+ const slug = typeof c === 'string' ? c : c.slug;
844
+ const lane = typeof c === 'string' ? 'html' : c.lane;
845
+ lanes.set(slug, (lanes.get(slug) ?? new Set()).add(lane));
846
+ }
847
+ resolveKeys(detachCall(r, call), {
848
+ run: r,
849
+ key,
850
+ claimed: lanes,
851
+ awaitKey: `${key}\u0000await\u0000${(++awaitSeq).toString(36)}`,
852
+ });
853
+ return true;
854
+ }
855
+ let awaitSeq = 0;
856
+
857
+ /**
858
+ * #164 — call `call` ends with no settle (the hook failed, a killed call, the studio was away):
859
+ * every write it parked is released as outside.
860
+ */
861
+ function releaseShellCall(
862
+ keyOrRun: string,
863
+ call: string,
864
+ _reason: 'no-settle' | 'stale' | 'run-end'
865
+ ): void {
866
+ resolveKeys(detachCall(runOf(keyOrRun), call));
867
+ }
868
+
869
+ /**
870
+ * #164 — run `keyOrRun`'s window for call `call` (open, or closed and waiting for its settle), or
871
+ * null when it has none: what the settle route may claim for it (F6 — a `named` window covers only
872
+ * its canvases).
873
+ */
874
+ function shellCall(
875
+ keyOrRun: string,
876
+ call: string
877
+ ): {
878
+ all: boolean;
879
+ covers: (slug: string) => boolean;
880
+ left: (slug: string) => boolean;
881
+ } | null {
882
+ const r = runOf(keyOrRun);
883
+ const c = r && r.state === 'open' ? r.shellCalls?.get(call) : undefined;
884
+ if (!c) return null;
885
+ return {
886
+ all: c.slugs === ALL_CANVASES,
887
+ covers: (slug) => coversShellSlug(c.slugs, slug),
888
+ left: (slug) => c.gone?.has(slug) === true,
889
+ };
890
+ }
891
+
892
+ /** The release a stage gets without `opts.release`: one `edit` proposal per canvas. */
893
+ function defaultRelease(w: {
894
+ slug: string;
895
+ doc: string;
896
+ writes: LaneProposal[];
897
+ }): Promise<ProposalOutcome> {
898
+ const lanes = [...new Set(w.writes.map((x) => x.lane))];
899
+ const firstOf = (l: string) => w.writes.find((x) => x.lane === l) as LaneProposal;
900
+ const lastOf = (l: string) => w.writes.filter((x) => x.lane === l).at(-1) as LaneProposal;
901
+ const create = w.writes.find((x) => x.create)?.create;
902
+ const operations: Operation[] = create
903
+ ? [
904
+ {
905
+ op: 'doc.create',
906
+ doc: w.doc,
907
+ path: create,
908
+ lanes: Object.fromEntries(
909
+ lanes.map((l) => [l, lastOf(l).content]).filter(([, v]) => v !== '')
910
+ ),
911
+ },
912
+ ]
913
+ : lanes.map((l) => ({
914
+ op: 'lane.replace',
915
+ doc: w.doc,
916
+ lane: l,
917
+ content: lastOf(l).content,
918
+ baseContent: firstOf(l).baseContent,
919
+ }));
920
+ return opts
921
+ .propose({
922
+ label: path.posix.basename(w.slug).replace(/\.tsx$/i, ''),
923
+ kind: 'edit',
924
+ operations,
925
+ transactionId: w.writes[0].transactionId,
926
+ })
927
+ .then((r) => ({
928
+ status: r.status,
929
+ ...(r.code ? { code: r.code } : {}),
930
+ ...(typeof r.actionId === 'string' ? { actionId: r.actionId } : {}),
931
+ }));
932
+ }
933
+ const release = opts.release ?? defaultRelease;
934
+ const mergeParked = opts.mergeParked ?? !opts.release;
494
935
 
495
936
  /** A tool reported writing `hash` (sha256 of the content) to canvas `slug`. */
496
937
  function claim(keyOrRun: string, slug: string, hash?: string | null): void {
@@ -543,6 +984,14 @@ export function createActionStage(opts: ActionStageOptions) {
543
984
  * go with it: a canvas the run made and then trashed is no change at all.
544
985
  */
545
986
  function stagesDelete(slug: string, doc: string, generation?: number): boolean {
987
+ // D4 — the windows open over this canvas saw it leave the disk (what their settle may bind)
988
+ for (const x of runs.values())
989
+ if (x.state === 'open')
990
+ for (const c of x.shellCalls?.values() ?? [])
991
+ if (coversShellSlug(c.slugs, slug)) {
992
+ c.gone ??= new Set();
993
+ c.gone.add(slug);
994
+ }
546
995
  const r = [...runs.values()].find(
547
996
  (x) => x.state === 'open' && claims.get(x.runId)?.deletes?.has(slug)
548
997
  );
@@ -584,14 +1033,8 @@ export function createActionStage(opts: ActionStageOptions) {
584
1033
  const covering = open.filter((r) => coversSlug(r, slug));
585
1034
  return covering.length === 1 ? covering[0] : null;
586
1035
  }
587
- // p8-a1-claims — no claim for these bytes: the write is the PERSON's, unless a call that cannot
588
- // claim (S7) has this canvas in its named-file window. Being the only open run is not a claim.
589
- const free = open.filter((r) => takesUnclaimed(r, slug));
590
- if (free.length === 1) return free[0];
591
- if (free.length > 1) {
592
- const covering = free.filter((r) => coversSlug(r, slug));
593
- return covering.length === 1 ? covering[0] : null;
594
- }
1036
+ // p8-a1-claims — no claim for these bytes: the write is not a run's. Being the only open run is
1037
+ // not a claim; #164 — nor is a window of a call that cannot claim (it parks the write instead).
595
1038
  if (open.length) return null;
596
1039
  // Nothing open: a held run that covers this canvas keeps its cold start.
597
1040
  return all.find((r) => r.state === 'held' && coversSlug(r, slug)) ?? null;
@@ -599,8 +1042,18 @@ export function createActionStage(opts: ActionStageOptions) {
599
1042
 
600
1043
  /** Should this proposal be staged instead of sent? */
601
1044
  function captures(slug: string, stageable: boolean, content?: string, explicit = false): boolean {
602
- if (!stageable || runs.size === 0) return false;
603
- return ownerOf(slug, content, explicit) !== null;
1045
+ if (!stageable || (runs.size === 0 && parked.length === 0)) return false;
1046
+ // #164 — a write a call's window covers is parked (the stage holds it until the call settles)
1047
+ return ownerOf(slug, content, explicit) !== null || parks(slug);
1048
+ }
1049
+
1050
+ /** Another run (open or held) whose staged lanes CREATE canvas `slug`, if any. */
1051
+ function creatorOf(slug: string, r: RunStage): RunStage | undefined {
1052
+ for (const other of runs.values()) {
1053
+ if (other === r) continue;
1054
+ for (const l of other.lanes.values()) if (l.slug === slug && l.create) return other;
1055
+ }
1056
+ return undefined;
604
1057
  }
605
1058
 
606
1059
  /** The accepted content of a lane: any staged run's base, else the write's own base. */
@@ -638,9 +1091,72 @@ export function createActionStage(opts: ActionStageOptions) {
638
1091
 
639
1092
  function capture(slug: string, doc: string, p: LaneProposal): Promise<ProposalOutcome> {
640
1093
  const r = ownerOf(slug, p.content, !!p.create);
641
- if (!r) return Promise.resolve({ status: 'rejected', code: 'not-staged' });
1094
+ if (!r) {
1095
+ // #164 — unclaimed, inside a call's window (or behind a write parked there): parked
1096
+ if (parks(slug)) return park(slug, doc, p);
1097
+ return Promise.resolve({ status: 'rejected', code: 'not-staged' });
1098
+ }
1099
+ // #164 — claimed bytes landing on a lane with parked writes. F1 — only what THIS run's settle
1100
+ // claimed of its own call (`joinRun`) folds in: the parked pre → these post bytes are ONE write.
1101
+ // Everything else parked on the lane (a person's save, another run's) goes out as outside first.
1102
+ const lane = parked.filter((e) => e.slug === slug && e.p.lane === p.lane);
1103
+ const before = lane.filter((e) => e.joinRun === r.runId);
1104
+ sendOutside(
1105
+ slug,
1106
+ lane.filter((e) => e.joinRun !== r.runId)
1107
+ );
1108
+ unpark(before);
1109
+ const create = p.create ?? before.find((e) => e.p.create)?.p.create;
1110
+ const out = stageWrite(
1111
+ r,
1112
+ slug,
1113
+ doc,
1114
+ before.length
1115
+ ? { ...p, baseContent: before[0].p.baseContent, ...(create ? { create } : {}) }
1116
+ : p,
1117
+ before
1118
+ );
1119
+ // a created canvas's other parked lanes (of the same settle) follow it into the run
1120
+ const rest = parked.filter((e) => e.slug === slug && e.p.create && e.joinRun === r.runId);
1121
+ if (create && rest.length)
1122
+ for (const l of new Set(rest.map((e) => e.p.lane)))
1123
+ joinParked(
1124
+ r,
1125
+ rest.filter((e) => e.p.lane === l)
1126
+ );
1127
+ if (lane.length) {
1128
+ releasePrefix(slug);
1129
+ releaseDependents();
1130
+ }
1131
+ return out;
1132
+ }
1133
+
1134
+ /**
1135
+ * Stage write `p` in run `r`. `joined` = parked writes it absorbs (#164): their transactions ride
1136
+ * with it and they get its outcome.
1137
+ */
1138
+ function stageWrite(
1139
+ r: RunStage,
1140
+ slug: string,
1141
+ doc: string,
1142
+ p: LaneProposal,
1143
+ joined: readonly Parked[] = [],
1144
+ hopped = false
1145
+ ): Promise<ProposalOutcome> {
1146
+ // A canvas another run CREATED and has not published has no accepted content: this run's
1147
+ // change cannot be told apart from the creator's (a three-way merge against nothing always
1148
+ // conflicts), and it cannot be published without that create. The write joins the creator —
1149
+ // ONE hop (2.1.1 T8): two runs that both hold a create lane for the canvas (a stage restored
1150
+ // from an older build) would otherwise hand the write back and forth without end.
1151
+ const creator = hopped || r.lanes.has(`${slug}|${p.lane}`) ? undefined : creatorOf(slug, r);
1152
+ if (creator) return stageWrite(creator, slug, doc, p, joined, true);
642
1153
  const k = `${slug}|${p.lane}`;
643
- return new Promise((resolve) => {
1154
+ const txs = [...joined.flatMap((e) => e.txs), p.transactionId];
1155
+ return new Promise<ProposalOutcome>((settle) => {
1156
+ const resolve = (o: ProposalOutcome) => {
1157
+ settle(o);
1158
+ for (const e of joined) e.resolve(o);
1159
+ };
644
1160
  const existing = r.lanes.get(k);
645
1161
  if (existing?.restored) {
646
1162
  // The cold start after a restart: the disk carries the run's bytes
@@ -648,7 +1164,7 @@ export function createActionStage(opts: ActionStageOptions) {
648
1164
  // v2 one kept them, and the write only rides along to settle.
649
1165
  if (existing.writes === 0) existing.mine = p.content;
650
1166
  delete existing.restored;
651
- existing.txs.push(p.transactionId);
1167
+ existing.txs.push(...txs);
652
1168
  existing.resolvers.push(resolve);
653
1169
  changed();
654
1170
  return;
@@ -671,7 +1187,7 @@ export function createActionStage(opts: ActionStageOptions) {
671
1187
  if (existing) {
672
1188
  existing.mine = merged.merged;
673
1189
  existing.writes += 1;
674
- existing.txs.push(p.transactionId);
1190
+ existing.txs.push(...txs);
675
1191
  existing.resolvers.push(resolve);
676
1192
  if (p.writeId) existing.writeId = p.writeId;
677
1193
  if (p.create) existing.create = p.create;
@@ -685,7 +1201,7 @@ export function createActionStage(opts: ActionStageOptions) {
685
1201
  writes: 1,
686
1202
  ...(p.writeId ? { writeId: p.writeId } : {}),
687
1203
  ...(p.create ? { create: p.create } : {}),
688
- txs: [p.transactionId],
1204
+ txs,
689
1205
  resolvers: [resolve],
690
1206
  });
691
1207
  }
@@ -717,6 +1233,8 @@ export function createActionStage(opts: ActionStageOptions) {
717
1233
  for (const r of runs.values())
718
1234
  for (const l of r.lanes.values())
719
1235
  if (l.txs.some((t) => dependsOn.includes(t))) out.add(r.runId);
1236
+ // #164 — an edit made on top of parked bytes waits for them, as it waits behind staged ones
1237
+ if (parked.some((e) => e.txs.some((t) => dependsOn.includes(t)))) out.add(PARKED);
720
1238
  for (const d of dependents) {
721
1239
  const tx = d.edit?.transactionId;
722
1240
  if (!tx || seen.has(tx) || !dependsOn.includes(tx)) continue;
@@ -791,9 +1309,13 @@ export function createActionStage(opts: ActionStageOptions) {
791
1309
  ): Promise<ProposalResult | null> {
792
1310
  const staged = [...r.lanes.values()].filter((l) => l.mine !== l.base || l.writes > 0);
793
1311
  const deletes = [...(r.deletes ?? new Map<string, { slug: string; generation?: number }>())];
1312
+ // #164 — the run's end ends its calls' windows: what they still park goes out as outside,
1313
+ // right behind the run's own action (released below, once the run is proposed)
1314
+ const calls = detachRunCalls(r);
794
1315
  if (staged.length === 0 && deletes.length === 0) {
795
1316
  forget(r);
796
1317
  changed();
1318
+ resolveKeys(calls);
797
1319
  releaseDependents();
798
1320
  return null;
799
1321
  }
@@ -853,6 +1375,7 @@ export function createActionStage(opts: ActionStageOptions) {
853
1375
  origin,
854
1376
  ...(o.fence ? { fence: o.fence } : {}),
855
1377
  });
1378
+ resolveKeys(calls);
856
1379
  releaseDependents();
857
1380
  const res = await sent.catch((err: unknown) => {
858
1381
  const code = (err as { code?: string })?.code ?? 'retryable';
@@ -903,6 +1426,8 @@ export function createActionStage(opts: ActionStageOptions) {
903
1426
  r.endedAt = now();
904
1427
  if (outcome === 'failed') {
905
1428
  r.state = 'held';
1429
+ // #164 — a held run takes nothing more: its calls' parked writes go out as outside
1430
+ resolveKeys(detachRunCalls(r));
906
1431
  changed();
907
1432
  log.warn(
908
1433
  `[sync/ai] ${r.label}: the run did not finish — ${r.lanes.size} change(s) kept on this device, not published.`
@@ -956,6 +1481,12 @@ export function createActionStage(opts: ActionStageOptions) {
956
1481
  discard,
957
1482
  captures,
958
1483
  capture,
1484
+ settleShellCall,
1485
+ releaseShellCall,
1486
+ shellCall,
1487
+ /** #164 — the writes parked right now (no bytes), in arrival order. */
1488
+ parked: (): Array<{ slug: string; lane: LaneProposal['lane'] }> =>
1489
+ parked.map((e) => ({ slug: e.slug, lane: e.p.lane })),
959
1490
  overlapWith,
960
1491
  holdsDependency,
961
1492
  wait,