spatial-views 0.1.0 → 0.2.0

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 (223) hide show
  1. package/README.md +201 -19
  2. package/dist/app/assets/{abnfDiagram-S7VZAUFO-BVgtb0Hw.js → abnfDiagram-S7VZAUFO-CFbb_Sz2.js} +1 -1
  3. package/dist/app/assets/{architecture-WOLXFQ4H-DxylGHqT.js → architecture-WOLXFQ4H-CsBD__5a.js} +1 -1
  4. package/dist/app/assets/architectureDiagram-YGSQEFNW-C0ic4ib1.js +36 -0
  5. package/dist/app/assets/{blockDiagram-APKKGZFW-C7fb3MCE.js → blockDiagram-APKKGZFW-BZDPbzAG.js} +1 -1
  6. package/dist/app/assets/{c4Diagram-KJ2TOQU5-Bkb_0fbd.js → c4Diagram-KJ2TOQU5-BilBWuq5.js} +1 -1
  7. package/dist/app/assets/{chunk-6MUBBAK2-DU4vZ03M.js → chunk-6MUBBAK2-BBl-4tQr.js} +1 -1
  8. package/dist/app/assets/{chunk-AXFCVDMN-De96BVTB.js → chunk-AXFCVDMN-BhsttQ-k.js} +1 -1
  9. package/dist/app/assets/{chunk-BG4553SI-J33jsRLV.js → chunk-BG4553SI-mWcPcFZr.js} +2 -2
  10. package/dist/app/assets/{chunk-DQASFODM-Bh85SSGO.js → chunk-DQASFODM-7FKe2gLt.js} +1 -1
  11. package/dist/app/assets/{chunk-HFQBQIA3-CCklgplR.js → chunk-HFQBQIA3-nXrQ08BL.js} +1 -1
  12. package/dist/app/assets/{chunk-KQLB2F66-B04qR8ED.js → chunk-KQLB2F66-swukhFmZ.js} +1 -1
  13. package/dist/app/assets/{chunk-KS47KZWR-BsqDyyAt.js → chunk-KS47KZWR-DkDkwO82.js} +1 -1
  14. package/dist/app/assets/{chunk-LEVMRMFU-DwxrBz2u.js → chunk-LEVMRMFU-DXH6iXv3.js} +1 -1
  15. package/dist/app/assets/{chunk-M57EVK23-D9YIHjps.js → chunk-M57EVK23-B-kEyOJF.js} +1 -1
  16. package/dist/app/assets/{chunk-OY52VR5R-WB63DeTA.js → chunk-OY52VR5R-DweG7qYw.js} +1 -1
  17. package/dist/app/assets/{chunk-QB3YPZ4I-cHzzKdtb.js → chunk-QB3YPZ4I-DyozK3lV.js} +1 -1
  18. package/dist/app/assets/{chunk-R3KSYZAL-C7rDagaa.js → chunk-R3KSYZAL-BEXCUN6J.js} +1 -1
  19. package/dist/app/assets/{chunk-STOXU5M4-CG6pnJtH.js → chunk-STOXU5M4-BaTlty4O.js} +1 -1
  20. package/dist/app/assets/{chunk-TU62E6Q5-BbcGYfy_.js → chunk-TU62E6Q5-_rcUP1Fh.js} +1 -1
  21. package/dist/app/assets/chunk-X3CZISLH-NOpCnvgE.js +1 -0
  22. package/dist/app/assets/{chunk-X4PVCEUW-BUI1Oi3q.js → chunk-X4PVCEUW-DGxTL3kB.js} +1 -1
  23. package/dist/app/assets/{chunk-XXDRQBXY-DYhK5YW-.js → chunk-XXDRQBXY-C02Gpej2.js} +1 -1
  24. package/dist/app/assets/{classDiagram-v2-L25IHNXF-K-k5GTUn.js → classDiagram-v2-L25IHNXF-DLEBwpvk.js} +1 -1
  25. package/dist/app/assets/cose-bilkent-JH36ORCC-kNCXOm8k.js +1 -0
  26. package/dist/app/assets/cynefin-EF2NZ3EQ-6MWNLbuF.js +1 -0
  27. package/dist/app/assets/{cynefinDiagram-L36ESFBY-mkV33_Xx.js → cynefinDiagram-L36ESFBY-CLFstukD.js} +1 -1
  28. package/dist/app/assets/{d3-scale-ygdFCUH8.js → d3-scale-CaJQQYkF.js} +1 -1
  29. package/dist/app/assets/{dagre-SPEB5RXH-BNIymLsu.js → dagre-SPEB5RXH-BaSAny1T.js} +1 -1
  30. package/dist/app/assets/{diagram-3B7GL73J-CGOiolFW.js → diagram-3B7GL73J-DJNlt5Sg.js} +1 -1
  31. package/dist/app/assets/{diagram-DNEMPZML-DZFkHNly.js → diagram-DNEMPZML-DEHeuILB.js} +1 -1
  32. package/dist/app/assets/{diagram-L3MUGCDN-B42GAYLq.js → diagram-L3MUGCDN-ob5Ka2Xc.js} +1 -1
  33. package/dist/app/assets/{diagram-LA4NIPWU-BYuLRYId.js → diagram-LA4NIPWU-DNESzFAc.js} +1 -1
  34. package/dist/app/assets/{diagram-MHCOC4E2-DGzI6TJG.js → diagram-MHCOC4E2-CVi9zKjG.js} +1 -1
  35. package/dist/app/assets/{diagram-XPFHEONP-CTBEgDQ8.js → diagram-XPFHEONP-DInT4C7e.js} +1 -1
  36. package/dist/app/assets/dist-CjvHN74u.js +1 -0
  37. package/dist/app/assets/{ebnfDiagram-UZSYDL2S-GuMdOCvL.js → ebnfDiagram-UZSYDL2S-CRCZNsji.js} +1 -1
  38. package/dist/app/assets/{elk-XV6XMXQE-BpY3loT5.js → elk-XV6XMXQE-D4fsWI2l.js} +1 -1
  39. package/dist/app/assets/{erDiagram-EYBAPDEH-nDZ2PMGl.js → erDiagram-EYBAPDEH-YQNM5StV.js} +1 -1
  40. package/dist/app/assets/{eventmodeling-K75KTNOO-BN42Mgwh.js → eventmodeling-K75KTNOO-Bev08J2F.js} +1 -1
  41. package/dist/app/assets/flowDiagram-MALGAFMO-BhJ554DH.js +1 -0
  42. package/dist/app/assets/ganttDiagram-23REXITY-CkaBMYM4.js +292 -0
  43. package/dist/app/assets/gitGraph-VSP46ZUC-CtbZ0sIS.js +1 -0
  44. package/dist/app/assets/{gitGraphDiagram-STJD7YCW-CDkKLrvO.js → gitGraphDiagram-STJD7YCW-D15ZdQ-Z.js} +1 -1
  45. package/dist/app/assets/index-Bn6_wHEp.js +98 -0
  46. package/dist/app/assets/index-H-Z7MFhZ.css +1 -0
  47. package/dist/app/assets/info-OHQRW6UA-CfUW1XFR.js +1 -0
  48. package/dist/app/assets/{infoDiagram-KBXO4MBG-B92P8pjY.js → infoDiagram-KBXO4MBG-DT7LbBRQ.js} +1 -1
  49. package/dist/app/assets/{ishikawaDiagram-M35NCXHK-BRZsbCvK.js → ishikawaDiagram-M35NCXHK-CF51lhjB.js} +1 -1
  50. package/dist/app/assets/{journeyDiagram-OPLOXDXO-Bppwb1oF.js → journeyDiagram-OPLOXDXO-_36FonKk.js} +1 -1
  51. package/dist/app/assets/{kanban-definition-BZKZHSQY-ByD_x5cm.js → kanban-definition-BZKZHSQY-tLk_OlQ-.js} +1 -1
  52. package/dist/app/assets/{mermaid-parser.core-CKmnV0Md.js → mermaid-parser.core-_3Vo8x6b.js} +3 -3
  53. package/dist/app/assets/mermaid.core-y-x1CYxC.js +44 -0
  54. package/dist/app/assets/{mindmap-definition-I2QAS2VK-fRbUh23C.js → mindmap-definition-I2QAS2VK-BCI4HRX3.js} +1 -1
  55. package/dist/app/assets/packet-JDAUHWVQ-Cco3UoaI.js +1 -0
  56. package/dist/app/assets/{pegDiagram-FD4XPPHP-qIABf6H8.js → pegDiagram-FD4XPPHP-BOzSoNji.js} +1 -1
  57. package/dist/app/assets/pie-XZMESJXO-reOB2GXn.js +1 -0
  58. package/dist/app/assets/{pieDiagram-J4AKIIQI-Bb4RBdrc.js → pieDiagram-J4AKIIQI-PlHpwT_c.js} +1 -1
  59. package/dist/app/assets/{quadrantDiagram-XTYBLID2-B0CpcVWE.js → quadrantDiagram-XTYBLID2-CdxZ0ael.js} +1 -1
  60. package/dist/app/assets/radar-ABXABTNO-DfCl8uV2.js +1 -0
  61. package/dist/app/assets/railroad-I3PHUGI6-4s14UyW1.js +1 -0
  62. package/dist/app/assets/{railroad-abnf-LNEFI6M7-BUhw7Iuo.js → railroad-abnf-LNEFI6M7-C49jJE4Y.js} +1 -1
  63. package/dist/app/assets/{railroad-ebnf-DWYD2UWJ-nQNF56LJ.js → railroad-ebnf-DWYD2UWJ-Bx-pcPc7.js} +1 -1
  64. package/dist/app/assets/{railroad-peg-JR7BVNR7-CwvbVIo6.js → railroad-peg-JR7BVNR7-DjBPSCKV.js} +1 -1
  65. package/dist/app/assets/{railroadDiagram-MRQ6NCDL-Dwr-mPZL.js → railroadDiagram-MRQ6NCDL-wGcmIMqq.js} +1 -1
  66. package/dist/app/assets/{requirementDiagram-Y7LWUY3S-Ctv2DKJM.js → requirementDiagram-Y7LWUY3S-DprFI03z.js} +1 -1
  67. package/dist/app/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  68. package/dist/app/assets/{sankeyDiagram-WGJFYUXA-BvKX0eIe.js → sankeyDiagram-WGJFYUXA-DygYWLTR.js} +1 -1
  69. package/dist/app/assets/{sequenceDiagram-5NDRBG5M-Y4YqU2Xt.js → sequenceDiagram-5NDRBG5M-BzIr2DBO.js} +1 -1
  70. package/dist/app/assets/{stateDiagram-v2-FJ4FJNEA-DmjIjn4u.js → stateDiagram-v2-FJ4FJNEA-MGCqKnm_.js} +1 -1
  71. package/dist/app/assets/{swimlanes-UMQ2AFYF-B2O5JCjs.js → swimlanes-UMQ2AFYF-CIEH82Zt.js} +1 -1
  72. package/dist/app/assets/swimlanesDiagram-OMPLPG4O-YWNJjl0g.js +8 -0
  73. package/dist/app/assets/{timeline-definition-SEUHKTQE-DJJdixAI.js → timeline-definition-SEUHKTQE-BGYSqup2.js} +1 -1
  74. package/dist/app/assets/treeView-D4JQ5SDB-B39o1sJo.js +1 -0
  75. package/dist/app/assets/treemap-SAJKECNS-BoGxrUH4.js +1 -0
  76. package/dist/app/assets/{usecaseDiagram-AFA6YXN4-Bp8pXgvR.js → usecaseDiagram-AFA6YXN4-dy6oVOke.js} +1 -1
  77. package/dist/app/assets/{vennDiagram-NNMJR3RB-DYSfZMWT.js → vennDiagram-NNMJR3RB-CUyuhcAk.js} +1 -1
  78. package/dist/app/assets/wardley-7MLQ67FV-sYPAvQ06.js +1 -0
  79. package/dist/app/assets/{wardleyDiagram-S7YFUSEH-CGJ8qg76.js → wardleyDiagram-S7YFUSEH-DYtxYUHe.js} +1 -1
  80. package/dist/app/assets/{xychartDiagram-GGNKY7IX-CRSvraFc.js → xychartDiagram-GGNKY7IX-ClR06AlB.js} +1 -1
  81. package/dist/app/index.html +3 -2
  82. package/dist/cli/index.js +281 -53
  83. package/dist/core/api.js +262 -51
  84. package/dist/core/approvals.js +426 -0
  85. package/dist/core/context.js +68 -3
  86. package/dist/core/diff.js +156 -0
  87. package/dist/core/docs.js +9 -3
  88. package/dist/core/doctor.js +152 -0
  89. package/dist/core/doctypes.js +79 -0
  90. package/dist/core/edit.js +25 -0
  91. package/dist/core/flags.js +13 -0
  92. package/dist/core/gaps.js +7 -2
  93. package/dist/core/heading.js +4 -0
  94. package/dist/core/history.js +36 -5
  95. package/dist/core/home.js +345 -0
  96. package/dist/core/lanes.js +134 -0
  97. package/dist/core/launch.js +34 -0
  98. package/dist/core/layout.js +362 -0
  99. package/dist/core/newdoc.js +66 -0
  100. package/dist/core/open-folder.js +30 -0
  101. package/dist/core/openspec.js +6 -6
  102. package/dist/core/paths.js +71 -4
  103. package/dist/core/project.js +392 -0
  104. package/dist/core/route.js +420 -0
  105. package/dist/core/scan.js +514 -0
  106. package/dist/core/schema.js +170 -1
  107. package/dist/core/scope.js +126 -0
  108. package/dist/core/setup.js +134 -0
  109. package/dist/core/skills.js +92 -14
  110. package/dist/core/storage/config.js +74 -0
  111. package/dist/core/storage/events.js +54 -0
  112. package/dist/core/storage/folder-watch.js +147 -0
  113. package/dist/core/storage/folder.js +469 -0
  114. package/dist/core/storage/index.js +8 -0
  115. package/dist/core/storage/local.js +22 -0
  116. package/dist/core/storage/migrate.js +48 -0
  117. package/dist/core/storage/postgres.js +290 -0
  118. package/dist/core/storage/types.js +101 -0
  119. package/dist/core/storage.js +483 -77
  120. package/dist/core/suggest.js +283 -0
  121. package/dist/core/tree.js +254 -0
  122. package/dist/core/types.js +583 -0
  123. package/dist/core/version.js +1 -1
  124. package/dist/core/versions.js +245 -0
  125. package/dist/core/watch.js +2 -136
  126. package/dist/core/xml.js +23 -5
  127. package/dist/demo/args.js +58 -0
  128. package/dist/demo/browser.js +301 -0
  129. package/dist/demo/platform.js +147 -0
  130. package/dist/demo/run.js +198 -0
  131. package/dist/demo/steps.js +328 -0
  132. package/dist/mcp/project-tools.js +193 -0
  133. package/dist/mcp/server.js +493 -65
  134. package/examples/platform/README.md +33 -0
  135. package/examples/platform/api/package.json +8 -0
  136. package/examples/platform/api/src/auth-middleware.js +16 -0
  137. package/examples/platform/api/src/proxy.js +7 -0
  138. package/examples/platform/api/src/rate-limit.js +13 -0
  139. package/examples/platform/api/src/server.js +40 -0
  140. package/examples/platform/auth/package.json +9 -0
  141. package/examples/platform/auth/src/server.js +24 -0
  142. package/examples/platform/auth/src/tokens.js +19 -0
  143. package/examples/platform/auth/src/users.js +16 -0
  144. package/examples/platform/docs/api/PRD.md +10 -0
  145. package/examples/platform/docs/api/SDD.md +15 -0
  146. package/examples/platform/docs/auth/PRD.md +10 -0
  147. package/examples/platform/docs/auth/SDD.md +8 -0
  148. package/examples/platform/docs/frontend/PRD.md +18 -0
  149. package/examples/platform/docs/frontend/SDD.md +13 -0
  150. package/examples/platform/docs/pricing/PRD.md +9 -0
  151. package/examples/platform/docs/pricing/SDD.md +8 -0
  152. package/examples/platform/docs/products/PRD.md +9 -0
  153. package/examples/platform/docs/products/SDD.md +8 -0
  154. package/examples/platform/frontend/package.json +8 -0
  155. package/examples/platform/frontend/src/api-client.js +21 -0
  156. package/examples/platform/frontend/src/main.js +21 -0
  157. package/examples/platform/frontend/src/pages/products.js +12 -0
  158. package/examples/platform/frontend/src/pages/sign-in.js +14 -0
  159. package/examples/platform/frontend/src/session.js +11 -0
  160. package/examples/platform/pricing/package.json +9 -0
  161. package/examples/platform/pricing/src/cache.js +19 -0
  162. package/examples/platform/pricing/src/product-events.js +17 -0
  163. package/examples/platform/pricing/src/rules.js +19 -0
  164. package/examples/platform/pricing/src/server.js +32 -0
  165. package/examples/platform/products/package.json +9 -0
  166. package/examples/platform/products/src/catalog.js +20 -0
  167. package/examples/platform/products/src/events.js +11 -0
  168. package/examples/platform/products/src/search.js +9 -0
  169. package/examples/platform/products/src/server.js +31 -0
  170. package/migrations/postgres/001_init.sql +55 -0
  171. package/migrations/postgres/002_view_versions.sql +18 -0
  172. package/package.json +18 -2
  173. package/schema/approval.schema.json +173 -0
  174. package/schema/gap.schema.json +3 -0
  175. package/schema/project.schema.json +93 -0
  176. package/schema/settings.schema.json +86 -0
  177. package/schema/toolbox.schema.json +206 -0
  178. package/schema/type.schema.json +121 -0
  179. package/schema/view.schema.json +106 -0
  180. package/skills/claude/build-gap/SKILL.md +7 -0
  181. package/skills/claude/check-ui/SKILL.md +40 -0
  182. package/skills/claude/draw-system/SKILL.md +24 -9
  183. package/skills/claude/gap-from-view/SKILL.md +7 -0
  184. package/skills/claude/post-audit/SKILL.md +58 -0
  185. package/skills/claude/pre-audit/SKILL.md +82 -0
  186. package/skills/claude/update-state/SKILL.md +56 -0
  187. package/skills/cursor/check-ui.mdc +40 -0
  188. package/skills/cursor/draw-system.mdc +24 -9
  189. package/skills/cursor/post-audit.mdc +44 -0
  190. package/skills/cursor/pre-audit.mdc +49 -0
  191. package/skills/cursor/update-state.mdc +45 -0
  192. package/skills/windsurf/spatial-views.md +182 -36
  193. package/toolboxes/aws.yaml +43 -0
  194. package/toolboxes/azure.yaml +41 -0
  195. package/toolboxes/cloud.yaml +95 -0
  196. package/toolboxes/docs.yaml +111 -0
  197. package/toolboxes/software.yaml +114 -0
  198. package/toolboxes/types/docs/gap.yaml +15 -0
  199. package/toolboxes/types/docs/mdd.yaml +19 -0
  200. package/toolboxes/types/docs/plain.yaml +7 -0
  201. package/toolboxes/types/docs/prd.yaml +17 -0
  202. package/dist/app/assets/architectureDiagram-YGSQEFNW-BrBCHqUH.js +0 -36
  203. package/dist/app/assets/chunk-X3CZISLH-FMl4PpWt.js +0 -1
  204. package/dist/app/assets/cose-bilkent-JH36ORCC-BJmLLpaN.js +0 -1
  205. package/dist/app/assets/cynefin-EF2NZ3EQ-DrzwMKdm.js +0 -1
  206. package/dist/app/assets/dist-1Q8ng3tu.js +0 -1
  207. package/dist/app/assets/flowDiagram-MALGAFMO-BCwwiLzb.js +0 -1
  208. package/dist/app/assets/ganttDiagram-23REXITY-xMRHaU3y.js +0 -292
  209. package/dist/app/assets/gitGraph-VSP46ZUC-DyGq5mdd.js +0 -1
  210. package/dist/app/assets/index-BY66fc8Q.js +0 -95
  211. package/dist/app/assets/index-ByetEVbs.css +0 -1
  212. package/dist/app/assets/info-OHQRW6UA-DOBf-fQH.js +0 -1
  213. package/dist/app/assets/mermaid.core-BoRvk1Q-.js +0 -44
  214. package/dist/app/assets/packet-JDAUHWVQ-CgHq03Zj.js +0 -1
  215. package/dist/app/assets/pie-XZMESJXO-DtNh3cDE.js +0 -1
  216. package/dist/app/assets/radar-ABXABTNO-BS0FcsIX.js +0 -1
  217. package/dist/app/assets/railroad-I3PHUGI6-lO8vfGdI.js +0 -1
  218. package/dist/app/assets/swimlanesDiagram-OMPLPG4O-DhCl-Cjg.js +0 -8
  219. package/dist/app/assets/treeView-D4JQ5SDB-Dd1no4eE.js +0 -1
  220. package/dist/app/assets/treemap-SAJKECNS-t6wtsaki.js +0 -1
  221. package/dist/app/assets/wardley-7MLQ67FV-Bx60QTuu.js +0 -1
  222. package/skills/cursor/build-gap.mdc +0 -21
  223. package/skills/cursor/gap-from-view.mdc +0 -22
@@ -0,0 +1,301 @@
1
+ import { mkdir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { UserError } from "../core/errors.js";
4
+ /**
5
+ * The window the demo records: Chromium through Playwright, 1920x1080, light,
6
+ * with no address bar or "controlled by automated software" bar. Captions and a
7
+ * visible cursor are drawn by a script the runner adds to every page; the app
8
+ * itself is not changed.
9
+ */
10
+ export const VIEWPORT = { width: 1920, height: 1080 };
11
+ const INSTALL = "npx playwright install chromium";
12
+ /** Playwright's Chromium: `playwright`, else `@playwright/test` (a dev dependency here). */
13
+ export async function loadChromium() {
14
+ for (const name of ["playwright", "@playwright/test"]) {
15
+ try {
16
+ const mod = (await import(name));
17
+ const chromium = mod.chromium ?? mod.default?.chromium;
18
+ if (chromium)
19
+ return chromium;
20
+ }
21
+ catch {
22
+ // try the next one
23
+ }
24
+ }
25
+ throw new UserError("The demo drives a browser with Playwright, which is not installed next to spatial-views.\n" +
26
+ " In a clone of the repo: npm install (it is a dev dependency)\n" +
27
+ " Otherwise: npm install playwright, in the folder spatial-views is installed in\n" +
28
+ `Then, once: ${INSTALL}`);
29
+ }
30
+ /** Launch errors that mean "the browser was never downloaded" get the one command that fixes it. */
31
+ export function launchError(err) {
32
+ const msg = err instanceof Error ? err.message : String(err);
33
+ if (/Executable doesn't exist|browserType\.launch.*(install|download)|playwright install/i.test(msg))
34
+ return new UserError(`Playwright's Chromium is not installed. Run:\n ${INSTALL}\nthen run the demo again.`);
35
+ if (/Missing X server|\$DISPLAY|cannot open display|Looks like you launched a headed browser/i.test(msg))
36
+ return new UserError("The demo opens a browser window, and there is no display here (no $DISPLAY). Run it on a desktop.");
37
+ return err instanceof Error ? err : new Error(msg);
38
+ }
39
+ /** Open the window on `url`. `profile` is a fresh folder (so the theme is the default: light). */
40
+ export async function openWindow(url, profile, headless, onSpace) {
41
+ const chromium = await loadChromium();
42
+ let context;
43
+ try {
44
+ context = await chromium.launchPersistentContext(profile, {
45
+ headless,
46
+ viewport: VIEWPORT,
47
+ screen: VIEWPORT,
48
+ deviceScaleFactor: 1,
49
+ colorScheme: "light",
50
+ reducedMotion: "no-preference",
51
+ // No "Chrome is being controlled by automated test software" bar.
52
+ ignoreDefaultArgs: ["--enable-automation"],
53
+ args: [
54
+ // An app window: no tabs, no address bar. Window capture records just the page.
55
+ `--app=${url}`,
56
+ "--window-position=0,0",
57
+ `--window-size=${VIEWPORT.width},${VIEWPORT.height}`,
58
+ "--disable-infobars",
59
+ "--no-first-run",
60
+ "--no-default-browser-check",
61
+ "--disable-features=Translate,AutofillServerCommunication,MediaRouter",
62
+ "--disable-session-crashed-bubble",
63
+ "--hide-crash-restore-bubble",
64
+ "--password-store=basic",
65
+ ],
66
+ });
67
+ }
68
+ catch (err) {
69
+ throw launchError(err);
70
+ }
71
+ await context.exposeFunction("__svDemoSpace", onSpace);
72
+ await context.addInitScript({ content: OVERLAY });
73
+ // A leave prompt (unsaved changes) must never stall a take.
74
+ context.on("page", (p) => p.on("dialog", (d) => void d.accept().catch(() => undefined)));
75
+ const page = context.pages()[0] ?? (await context.newPage());
76
+ page.on("dialog", (d) => void d.accept().catch(() => undefined));
77
+ if (page.url() !== url)
78
+ await page.goto(url);
79
+ else
80
+ await page.reload();
81
+ return { context, page };
82
+ }
83
+ /**
84
+ * The overlay: a caption card at the bottom and a cursor that follows the
85
+ * mouse events Playwright sends (the OS cursor does not move). Space is caught
86
+ * here while the runner waits for it, so it never clicks a focused button.
87
+ */
88
+ const OVERLAY = String.raw `(() => {
89
+ if (window.__svDemo) return;
90
+ window.__svDemo = { waiting: false };
91
+ const css = [
92
+ "#sv-demo-cursor { position: fixed; left: 0; top: 0; width: 28px; height: 28px; z-index: 2147483647; pointer-events: none; transform: translate(-100px, -100px); will-change: transform; }",
93
+ "#sv-demo-cursor svg { display: block; filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.35)); }",
94
+ "#sv-demo-cursor .ring { position: absolute; left: -14px; top: -14px; width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(37, 99, 235, 0.7); opacity: 0; transform: scale(0.4); }",
95
+ "#sv-demo-cursor .ring.on { animation: sv-demo-ring 420ms ease-out; }",
96
+ "@keyframes sv-demo-ring { 0% { opacity: 0.9; transform: scale(0.4); } 100% { opacity: 0; transform: scale(1.5); } }",
97
+ "#sv-demo-caption { position: fixed; left: 50%; bottom: 18px; z-index: 2147483646; pointer-events: none; display: flex; align-items: center; gap: 14px; white-space: nowrap; transform: translate(-50%, 10px); opacity: 0; transition: opacity 320ms ease, transform 320ms ease; padding: 12px 26px 12px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.97); border: 1px solid rgba(15, 23, 42, 0.08); box-shadow: 0 10px 36px rgba(15, 23, 42, 0.14); font-family: Inter, \"Segoe UI\", system-ui, -apple-system, sans-serif; color: #0f172a; }",
98
+ "#sv-demo-caption.on { opacity: 1; transform: translate(-50%, 0); }",
99
+ "#sv-demo-caption.plain { padding-left: 26px; }",
100
+ "#sv-demo-caption .kicker { flex: none; padding: 5px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #1d4ed8; background: #dbeafe; }",
101
+ "#sv-demo-caption .kicker.ai { color: #6d28d9; background: #ede9fe; }",
102
+ "#sv-demo-caption .text { font-size: 23px; line-height: 1.3; font-weight: 500; }",
103
+ ].join("\n");
104
+ const mount = () => {
105
+ if (document.getElementById("sv-demo-cursor")) return;
106
+ const style = document.createElement("style");
107
+ style.textContent = css;
108
+ document.head.appendChild(style);
109
+ const cursor = document.createElement("div");
110
+ cursor.id = "sv-demo-cursor";
111
+ cursor.innerHTML = '<svg width="26" height="26" viewBox="0 0 26 26"><path d="M3 2 L3 21 L8.2 16.3 L11.6 24 L15 22.5 L11.7 15 L19 15 Z" fill="#0f172a" stroke="#fff" stroke-width="1.6" stroke-linejoin="round"/></svg><span class="ring"></span>';
112
+ document.body.appendChild(cursor);
113
+ const caption = document.createElement("div");
114
+ caption.id = "sv-demo-caption";
115
+ caption.innerHTML = '<span class="kicker"></span><span class="text"></span>';
116
+ document.body.appendChild(caption);
117
+ const at = window.__svDemo.at;
118
+ if (at) cursor.style.transform = "translate(" + at[0] + "px, " + at[1] + "px)";
119
+ if (window.__svDemo.caption) window.__svDemoCaption(window.__svDemo.caption.text, window.__svDemo.caption.kicker, true);
120
+ };
121
+ window.__svDemoCaption = (text, kicker, instant) => {
122
+ window.__svDemo.caption = text ? { text, kicker } : null;
123
+ const el = document.getElementById("sv-demo-caption");
124
+ if (!el) return;
125
+ const set = () => {
126
+ el.querySelector(".kicker").textContent = kicker || "";
127
+ el.querySelector(".kicker").className = "kicker" + (/^AI/.test(kicker || "") ? " ai" : "");
128
+ el.querySelector(".kicker").style.display = kicker ? "" : "none";
129
+ el.classList.toggle("plain", !kicker);
130
+ el.querySelector(".text").textContent = text || "";
131
+ if (text) el.classList.add("on");
132
+ };
133
+ if (!text) return el.classList.remove("on");
134
+ if (instant || !el.classList.contains("on")) return set();
135
+ el.classList.remove("on");
136
+ setTimeout(set, 260);
137
+ };
138
+ const move = (e) => {
139
+ window.__svDemo.at = [e.clientX, e.clientY];
140
+ const c = document.getElementById("sv-demo-cursor");
141
+ if (c) c.style.transform = "translate(" + e.clientX + "px, " + e.clientY + "px)";
142
+ };
143
+ window.addEventListener("mousemove", move, true);
144
+ window.addEventListener("pointermove", move, true);
145
+ window.addEventListener("mousedown", () => {
146
+ const r = document.querySelector("#sv-demo-cursor .ring");
147
+ if (!r) return;
148
+ r.classList.remove("on");
149
+ void r.offsetWidth;
150
+ r.classList.add("on");
151
+ }, true);
152
+ const editable = (t) => t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName));
153
+ window.addEventListener("keydown", (e) => {
154
+ if (e.key !== " " || e.repeat) return;
155
+ // Typing a space into a field goes through, unless the runner is waiting for the key.
156
+ if (!window.__svDemo.waiting && editable(e.target)) return;
157
+ e.preventDefault();
158
+ e.stopImmediatePropagation();
159
+ if (window.__svDemo.waiting && typeof window.__svDemoSpace === "function") window.__svDemoSpace();
160
+ }, true);
161
+ if (document.body) mount();
162
+ else document.addEventListener("DOMContentLoaded", mount);
163
+ })();`;
164
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
165
+ const ease = (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);
166
+ const isPoint = (t) => typeof t.x === "number" && typeof t.y === "number";
167
+ /** The person at the keyboard: the cursor glides, clicks land where it is, typing has a rhythm. */
168
+ export class Human {
169
+ page;
170
+ pace;
171
+ at = { x: VIEWPORT.width / 2, y: VIEWPORT.height * 0.62 };
172
+ constructor(page, pace = { speed: 1 }) {
173
+ this.page = page;
174
+ this.pace = pace;
175
+ }
176
+ pause(ms) {
177
+ return sleep(ms * this.pace.speed);
178
+ }
179
+ /** Put the cursor where the last one was (after a reload) without a glide. */
180
+ async place() {
181
+ await this.page.mouse.move(this.at.x, this.at.y);
182
+ }
183
+ /** Where a target is: a point, or the middle of a locator (nudged by dx, dy). */
184
+ async point(t, dx = 0, dy = 0) {
185
+ if (isPoint(t))
186
+ return { x: t.x + dx, y: t.y + dy };
187
+ await t.waitFor({ state: "visible" });
188
+ await t.scrollIntoViewIfNeeded().catch(() => undefined);
189
+ const b = await t.boundingBox();
190
+ if (!b)
191
+ throw new Error(`not on screen: ${t.toString()}`);
192
+ return { x: b.x + b.width / 2 + dx, y: b.y + b.height / 2 + dy };
193
+ }
194
+ /** Glide to a point, easing in and out, about 0.25 to 0.7 s. */
195
+ async moveTo(p) {
196
+ const from = this.at;
197
+ const d = Math.hypot(p.x - from.x, p.y - from.y);
198
+ const steps = Math.max(6, Math.min(42, Math.round(d / 22)));
199
+ for (let i = 1; i <= steps; i++) {
200
+ const k = ease(i / steps);
201
+ await this.page.mouse.move(from.x + (p.x - from.x) * k, from.y + (p.y - from.y) * k);
202
+ await sleep(14 * this.pace.speed);
203
+ }
204
+ this.at = p;
205
+ }
206
+ async hover(t, dx = 0, dy = 0) {
207
+ const p = await this.point(t, dx, dy);
208
+ await this.moveTo(p);
209
+ return p;
210
+ }
211
+ async click(t, opts = {}) {
212
+ const p = await this.hover(t, opts.dx, opts.dy);
213
+ await this.pause(140);
214
+ await this.page.mouse.click(p.x, p.y, { delay: 60 });
215
+ await this.pause(220);
216
+ }
217
+ async dblclick(t, opts = {}) {
218
+ const p = await this.hover(t, opts.dx, opts.dy);
219
+ await this.pause(160);
220
+ await this.page.mouse.dblclick(p.x, p.y, { delay: 40 });
221
+ await this.pause(260);
222
+ }
223
+ /** Press on a target, carry it by (dx, dy) at a hand's pace, let go. */
224
+ async drag(t, by, from = {}) {
225
+ const p = await this.hover(t, from.dx, from.dy);
226
+ await this.pause(160);
227
+ await this.page.mouse.down();
228
+ await this.pause(120);
229
+ // A small first move, so the canvas sees a drag start, then the rest.
230
+ await this.moveTo({ x: p.x + Math.sign(by.x) * 4, y: p.y + Math.sign(by.y) * 4 });
231
+ const steps = Math.max(18, Math.round(Math.hypot(by.x, by.y) / 6));
232
+ const start = this.at;
233
+ const end = { x: p.x + by.x, y: p.y + by.y };
234
+ for (let i = 1; i <= steps; i++) {
235
+ const k = ease(i / steps);
236
+ await this.page.mouse.move(start.x + (end.x - start.x) * k, start.y + (end.y - start.y) * k);
237
+ await sleep(16 * this.pace.speed);
238
+ }
239
+ this.at = end;
240
+ await this.pause(120);
241
+ await this.page.mouse.up();
242
+ await this.pause(260);
243
+ }
244
+ /** Type at a person's rhythm. */
245
+ async type(text) {
246
+ for (const ch of text) {
247
+ await this.page.keyboard.type(ch);
248
+ await sleep((70 + Math.round(Math.random() * 60)) * this.pace.speed);
249
+ }
250
+ }
251
+ async press(key) {
252
+ await this.page.keyboard.press(key);
253
+ await this.pause(160);
254
+ }
255
+ /** Scroll with the wheel where the cursor is, in small notches. */
256
+ async scroll(dy) {
257
+ const notches = Math.max(1, Math.round(Math.abs(dy) / 90));
258
+ for (let i = 0; i < notches; i++) {
259
+ await this.page.mouse.wheel(0, Math.sign(dy) * 90);
260
+ await sleep(90 * this.pace.speed);
261
+ }
262
+ }
263
+ }
264
+ /** Captions, fit-to-view, screenshots: what the runner does to the window that is not a person's input. */
265
+ export class Screen {
266
+ page;
267
+ shotsDir;
268
+ constructor(page, shotsDir) {
269
+ this.page = page;
270
+ this.shotsDir = shotsDir;
271
+ }
272
+ /** Show a caption (a kicker such as "AI · over MCP" above it); empty hides it. */
273
+ async caption(text, kicker = "") {
274
+ await this.page
275
+ .evaluate(([t, k]) => globalThis.__svDemoCaption?.(t, k), [text, kicker])
276
+ .catch(() => undefined);
277
+ }
278
+ /** Fit the View to the window, without the cursor going to the button (the change, not the click, is the point). */
279
+ async fit() {
280
+ const btn = this.page.getByRole("button", { name: /^fit view$/i }).first();
281
+ if (await btn.count())
282
+ await btn.dispatchEvent("click").catch(() => undefined);
283
+ }
284
+ /** Put away the app's last toast ("Saved", "Pending in Approvals"): it stays until dismissed. */
285
+ async dismissToast() {
286
+ const x = this.page.locator('.sv-toast button[aria-label="Dismiss"]');
287
+ if (await x.count())
288
+ await x.first().dispatchEvent("click").catch(() => undefined);
289
+ }
290
+ /** Mark the page as waiting for space (the overlay then catches it). */
291
+ async waiting(on) {
292
+ await this.page.evaluate((w) => (globalThis.__svDemo ??= { waiting: w }).waiting = w, on).catch(() => undefined);
293
+ }
294
+ /** SV_SHOTS=<dir>: a screenshot per beat, to check a run without watching it. */
295
+ async shot(name) {
296
+ if (!this.shotsDir)
297
+ return;
298
+ await mkdir(this.shotsDir, { recursive: true });
299
+ await this.page.screenshot({ path: join(this.shotsDir, `${name}.png`) }).catch(() => undefined);
300
+ }
301
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * What pre-audit draws for examples/platform (Direction, 22 Nov 2026): the
3
+ * System Overview (Frontend, API, Auth, Products, Pricing), one Sub View per
4
+ * area (3 to 6 typed modules, with file pointers), and each area's PRD and
5
+ * SDD pinned to its module. Nothing else: no lanes, no Gaps, no reports.
6
+ *
7
+ * The end-to-end test (test/demo-platform.test.ts), the screenshot test
8
+ * (test/ui/platform.spec.ts) and `spatial-views demo` all draw it through the
9
+ * MCP tools, as the Skill does.
10
+ */
11
+ export const AREAS = [
12
+ {
13
+ id: "frontend",
14
+ name: "Frontend",
15
+ type: "frontend",
16
+ description: "The storefront: browse, search, a product's price, sign in.",
17
+ modules: [
18
+ { name: "Shell and routing", type: "frontend", files: ["frontend:src/main.js"] },
19
+ { name: "Product pages", type: "frontend", files: ["frontend:src/pages/products.js"] },
20
+ { name: "Sign-in", type: "frontend", files: ["frontend:src/pages/sign-in.js"] },
21
+ { name: "API client", type: "api", files: ["frontend:src/api-client.js"] },
22
+ { name: "Session", type: "database", files: ["frontend:src/session.js"], properties: { engine: "Other", managed: false } },
23
+ ],
24
+ connections: [
25
+ ["Shell and routing", "Product pages", "/"],
26
+ ["Shell and routing", "Sign-in", "/sign-in"],
27
+ ["Product pages", "API client", "products, prices"],
28
+ ["Sign-in", "API client", "login"],
29
+ ["Sign-in", "Session", "token"],
30
+ ],
31
+ },
32
+ {
33
+ id: "api",
34
+ name: "API",
35
+ type: "api",
36
+ description: "The gateway: one front door; checks tokens, limits rates, forwards.",
37
+ modules: [
38
+ { name: "Rate limiter", type: "service", files: ["api:src/rate-limit.js"] },
39
+ { name: "Router", type: "api", files: ["api:src/server.js"] },
40
+ { name: "Auth middleware", type: "auth", files: ["api:src/auth-middleware.js"] },
41
+ { name: "Proxy", type: "service", files: ["api:src/proxy.js"] },
42
+ ],
43
+ connections: [
44
+ ["Rate limiter", "Router", "allowed"],
45
+ ["Router", "Auth middleware", "POST /quotes"],
46
+ ["Router", "Proxy", "forward"],
47
+ ["Auth middleware", "Proxy", "token ok"],
48
+ ],
49
+ },
50
+ {
51
+ id: "auth",
52
+ name: "Auth",
53
+ type: "auth",
54
+ description: "Signs users in and issues short-lived tokens.",
55
+ modules: [
56
+ { name: "Login handler", type: "api", files: ["auth:src/server.js"] },
57
+ { name: "JWKS endpoint", type: "api", files: ["auth:src/server.js"] },
58
+ { name: "Token service", type: "service", files: ["auth:src/tokens.js"] },
59
+ { name: "Users DB", type: "database", files: ["auth:src/users.js"], properties: { engine: "PostgreSQL" } },
60
+ ],
61
+ connections: [
62
+ ["Login handler", "Users DB", "find user"],
63
+ ["Login handler", "Token service", "issue"],
64
+ ["JWKS endpoint", "Token service", "public keys"],
65
+ ],
66
+ },
67
+ {
68
+ id: "products",
69
+ name: "Products",
70
+ type: "service",
71
+ description: "The catalogue: list, search, and announce changes.",
72
+ modules: [
73
+ { name: "Catalogue API", type: "api", files: ["products:src/server.js"] },
74
+ { name: "Search", type: "service", files: ["products:src/search.js"] },
75
+ { name: "Products DB", type: "database", files: ["products:src/catalog.js"], properties: { engine: "PostgreSQL" } },
76
+ { name: "Change events", type: "queue", files: ["products:src/events.js"], properties: { kind: "Topic", broker: "RabbitMQ" } },
77
+ ],
78
+ connections: [
79
+ ["Catalogue API", "Search", "?q="],
80
+ ["Catalogue API", "Products DB", "SQL"],
81
+ ["Search", "Products DB", "full text"],
82
+ ["Catalogue API", "Change events", "products.changed"],
83
+ ],
84
+ },
85
+ {
86
+ id: "pricing",
87
+ name: "Pricing",
88
+ type: "service",
89
+ description: "Prices and quotes, with discounts; never stale.",
90
+ modules: [
91
+ { name: "Price API", type: "api", files: ["pricing:src/server.js"] },
92
+ { name: "Rules engine", type: "service", files: ["pricing:src/rules.js"] },
93
+ { name: "Price cache", type: "database", files: ["pricing:src/cache.js"], properties: { engine: "Redis" } },
94
+ { name: "Product events", type: "queue", files: ["pricing:src/product-events.js"], properties: { broker: "RabbitMQ" } },
95
+ ],
96
+ connections: [
97
+ ["Price API", "Price cache", "price:id"],
98
+ ["Price API", "Rules engine", "on a miss"],
99
+ ["Product events", "Price cache", "forget"],
100
+ ],
101
+ },
102
+ ];
103
+ /** The System Overview's connections, between areas (by repo id). */
104
+ export const OVERVIEW = [
105
+ ["frontend", "api", "https"],
106
+ ["api", "auth", "login, JWKS"],
107
+ ["api", "products", "/products"],
108
+ ["api", "pricing", "/prices, /quotes"],
109
+ ["products", "pricing", "products.changed"],
110
+ ];
111
+ export const SOURCES = ["frontend", "api", "auth", "products", "pricing", "docs"];
112
+ /** Run one tool and fail loudly on a tool error. */
113
+ export async function must(call, tool, args = {}) {
114
+ const r = (await call(tool, args));
115
+ if (r && typeof r === "object" && r.isError)
116
+ throw new Error(`${tool} ${JSON.stringify(args)}: ${r.text}`);
117
+ return r;
118
+ }
119
+ /**
120
+ * pre-audit's drawing, after the sources are added: type and name the System
121
+ * Overview's modules and connect them, one Sub View per area, and pin each
122
+ * area's PRD and SDD to its module.
123
+ */
124
+ export async function drawPlatform(call, beat = async () => { }) {
125
+ for (const a of AREAS) {
126
+ await must(call, "update_module", { module: a.id, in_view: "system-overview", name: a.name, type: a.type, description: a.description });
127
+ await beat("module");
128
+ }
129
+ for (const [from, to, label] of OVERVIEW) {
130
+ await must(call, "connect", { view: "system-overview", from, to, ...(label ? { label } : {}) });
131
+ await beat("connection");
132
+ }
133
+ await beat("details");
134
+ for (const a of AREAS) {
135
+ const view = `${a.id}-view`;
136
+ await must(call, "create_view", { name: a.name, id: view, type: "sub-view", from_module: a.id, in_view: "system-overview" });
137
+ for (const m of a.modules)
138
+ await must(call, "add_module", { view, name: m.name, type: m.type, ...(m.properties ? { properties: m.properties } : {}) });
139
+ for (const [from, to, label] of a.connections)
140
+ await must(call, "connect", { view, from, to, ...(label ? { label } : {}) });
141
+ for (const m of a.modules)
142
+ for (const f of m.files)
143
+ await must(call, "add_file_pointer", { module: m.name, in_view: view, path: f });
144
+ for (const doc of ["PRD", "SDD"])
145
+ await must(call, "pin", { path: `docs:${a.id}/${doc}.md`, module: a.id, view: "system-overview" });
146
+ }
147
+ }
@@ -0,0 +1,198 @@
1
+ import { spawn } from "node:child_process";
2
+ import { cp, mkdir, mkdtemp, readFile, rm, stat } from "node:fs/promises";
3
+ import { createServer } from "node:net";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
8
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
9
+ import { UserError } from "../core/errors.js";
10
+ import { DEMO_USAGE, parseDemoArgs } from "./args.js";
11
+ import { Human, loadChromium, openWindow, Screen } from "./browser.js";
12
+ import { SOURCES } from "./platform.js";
13
+ import { OVERVIEW_ID, STEP_COUNT, steps } from "./steps.js";
14
+ /**
15
+ * `spatial-views demo`: the scripted demo, for recording. A throwaway home
16
+ * folder, the canvas on it, the repo's own MCP server over stdio as the AI,
17
+ * and a Chromium window driven by Playwright as the person. Everything runs on
18
+ * 127.0.0.1; nothing is fetched from the network.
19
+ */
20
+ const EXAMPLES = fileURLToPath(new URL("../../examples/platform/", import.meta.url));
21
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
22
+ function freePort() {
23
+ return new Promise((resolve, reject) => {
24
+ const srv = createServer();
25
+ srv.unref();
26
+ srv.on("error", reject);
27
+ srv.listen(0, "127.0.0.1", () => {
28
+ const a = srv.address();
29
+ srv.close(() => (a && typeof a === "object" ? resolve(a.port) : reject(new Error("no free port"))));
30
+ });
31
+ });
32
+ }
33
+ /** The environment both servers run with: the throwaway home, folder storage, no experimental features. */
34
+ export function demoEnv(home, env = process.env) {
35
+ const out = { ...env, SPATIAL_VIEWS_HOME: home };
36
+ for (const k of ["SPATIAL_VIEWS_STORAGE", "SPATIAL_VIEWS_DATABASE_URL", "SPATIAL_VIEWS_EXPERIMENTAL", "NODE_CHANNEL_FD", "NODE_CHANNEL_SERIALIZATION_MODE"])
37
+ delete out[k];
38
+ return out;
39
+ }
40
+ /** examples/platform, copied out; each repo marked as one (a .git folder), so add_source sees a repo. */
41
+ export async function copyPlatform(to) {
42
+ await cp(EXAMPLES, to, { recursive: true });
43
+ for (const s of SOURCES)
44
+ if (s !== "docs")
45
+ await mkdir(join(to, s, ".git"), { recursive: true });
46
+ }
47
+ /** A client for the canvas's local API. */
48
+ export function httpClient(base) {
49
+ return async (method, path, body) => {
50
+ const res = await fetch(base + path, {
51
+ method,
52
+ ...(body !== undefined ? { headers: { "content-type": "application/json" }, body: JSON.stringify(body) } : {}),
53
+ });
54
+ const text = await res.text();
55
+ if (!res.ok)
56
+ throw new Error(`${method} ${path}: ${res.status} ${text}`);
57
+ return (text ? JSON.parse(text) : undefined);
58
+ };
59
+ }
60
+ /** An MCP tool call that returns {isError, text}, like the tests' helpers. */
61
+ export function mcpCall(client) {
62
+ return async (name, args = {}) => {
63
+ const res = (await client.callTool({ name, arguments: args }));
64
+ return { isError: res.isError === true, text: res.content.map((c) => c.text).join("\n") };
65
+ };
66
+ }
67
+ async function waitForCanvas(base, child, err) {
68
+ for (let i = 0; i < 150; i++) {
69
+ if (child.exitCode !== null)
70
+ throw new Error(`the canvas stopped before it started:\n${err()}`);
71
+ if (await fetch(`${base}/api/projects`).then((r) => r.ok, () => false))
72
+ return;
73
+ await sleep(100);
74
+ }
75
+ throw new Error(`the canvas did not start on ${base}:\n${err()}`);
76
+ }
77
+ /** Space (in the window or this terminal) or a timer: when to go on. */
78
+ class Advance {
79
+ opts;
80
+ screen;
81
+ resolve = null;
82
+ constructor(opts, screen) {
83
+ this.opts = opts;
84
+ this.screen = screen;
85
+ }
86
+ /** A space press, from the page or the terminal. Ignored unless something is waiting for it. */
87
+ fire() {
88
+ const r = this.resolve;
89
+ this.resolve = null;
90
+ r?.();
91
+ }
92
+ async next(label, ms = this.opts.delay) {
93
+ if (this.opts.auto) {
94
+ console.log(` ${label}`);
95
+ return sleep(ms);
96
+ }
97
+ console.log(` [space] ${label}`);
98
+ await this.screen()?.waiting(true);
99
+ await new Promise((r) => (this.resolve = r));
100
+ await this.screen()?.waiting(false);
101
+ }
102
+ }
103
+ export async function runDemo(argv, cli) {
104
+ if (argv.includes("--help") || argv.includes("-h")) {
105
+ console.log(DEMO_USAGE);
106
+ return 0;
107
+ }
108
+ const opts = parseDemoArgs(argv, STEP_COUNT);
109
+ if (!(await stat(EXAMPLES).catch(() => null))?.isDirectory())
110
+ throw new UserError(`the demo's example platform is missing (${EXAMPLES})`);
111
+ // Fail before anything starts if the browser driver is not there.
112
+ await loadChromium();
113
+ const tmp = await mkdtemp(join(tmpdir(), "sv-demo-"));
114
+ const home = join(tmp, "home");
115
+ const disk = join(tmp, "platform");
116
+ // The app adds an example toolbox to a home with no toolboxes/ folder: make it, so the Toolbox stays as shipped.
117
+ await mkdir(join(home, "toolboxes"), { recursive: true });
118
+ await copyPlatform(disk);
119
+ const env = demoEnv(home);
120
+ const port = opts.port ?? (await freePort());
121
+ const base = `http://127.0.0.1:${port}`;
122
+ let canvas = null;
123
+ let ai = null;
124
+ let context = null;
125
+ let screen = null;
126
+ const advance = new Advance(opts, () => screen);
127
+ const tty = process.stdin.isTTY ? process.stdin : null;
128
+ let cleaning = null;
129
+ const cleanup = () => (cleaning ??= (async () => {
130
+ if (tty) {
131
+ tty.setRawMode(false);
132
+ tty.pause();
133
+ }
134
+ await context?.close().catch(() => undefined);
135
+ await ai?.close().catch(() => undefined);
136
+ canvas?.kill();
137
+ await rm(tmp, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 }).catch(() => undefined);
138
+ })());
139
+ const quit = (code) => void cleanup().finally(() => process.exit(code));
140
+ const onSignal = () => quit(130);
141
+ process.once("SIGINT", onSignal);
142
+ process.once("SIGTERM", onSignal);
143
+ if (tty) {
144
+ tty.setRawMode(true);
145
+ tty.resume();
146
+ tty.on("data", (b) => {
147
+ const k = b.toString();
148
+ if (k === "\u0003" || k === "q")
149
+ quit(130);
150
+ else if (k === " " || k === "\r" || k === "\n")
151
+ advance.fire();
152
+ });
153
+ }
154
+ try {
155
+ let err = "";
156
+ canvas = spawn(process.execPath, [cli, "--port", String(port)], { env, cwd: home, stdio: ["ignore", "ignore", "pipe"] });
157
+ canvas.stderr?.on("data", (d) => (err = (err + d).slice(-4000)));
158
+ await waitForCanvas(base, canvas, () => err);
159
+ // The AI: the repo's own MCP server, global (no project until use_project), on the same home.
160
+ ai = new Client({ name: "claude-code", version: "1.0.0" });
161
+ await ai.connect(new StdioClientTransport({ command: process.execPath, args: [cli, "mcp", "--global"], env: env, cwd: home, stderr: "ignore" }));
162
+ const stage = { ai: mcpCall(ai), http: httpClient(base), disk };
163
+ const list = steps((rel) => readFile(join(disk, rel), "utf8"));
164
+ console.log(`Spatial Views demo on ${base} (a throwaway home: ${home})`);
165
+ for (let i = 0; i < opts.step - 1; i++)
166
+ await list[i].seed(stage);
167
+ if (opts.step > 1)
168
+ console.log(` ${opts.step === 2 ? "step 1" : `steps 1-${opts.step - 1}`} set up`);
169
+ const url = opts.step > 1 ? `${base}/#/view/${OVERVIEW_ID}` : `${base}/`;
170
+ const win = await openWindow(url, join(tmp, "browser"), opts.headless, () => advance.fire());
171
+ context = win.context;
172
+ const page = win.page;
173
+ // Closing the window ends the demo.
174
+ page.on("close", () => void (cleaning ?? quit(0)));
175
+ screen = new Screen(page, process.env.SV_SHOTS);
176
+ const human = new Human(page);
177
+ if (opts.step > 1)
178
+ await page.getByTestId("sv-crumbs").waitFor();
179
+ await human.place();
180
+ await screen.fit();
181
+ console.log(opts.auto ? `--auto: a step every ${opts.delay} ms` : "space (in the window or here) for the next step; q or Ctrl+C to stop");
182
+ for (let n = opts.step; n <= list.length; n++) {
183
+ const step = list[n - 1];
184
+ await advance.next(n === opts.step ? `ready: step ${n} of ${list.length}, ${step.title}` : `step ${n} of ${list.length}: ${step.title}`);
185
+ await screen.dismissToast();
186
+ await step.play(stage, { page, human, screen });
187
+ await screen.shot(`step-${n}`);
188
+ }
189
+ await screen.caption("");
190
+ await advance.next("done: space to close");
191
+ return 0;
192
+ }
193
+ finally {
194
+ process.off("SIGINT", onSignal);
195
+ process.off("SIGTERM", onSignal);
196
+ await cleanup();
197
+ }
198
+ }