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,328 @@
1
+ import { join } from "node:path";
2
+ import { drawPlatform, must, SOURCES } from "./platform.js";
3
+ /**
4
+ * The demo, as a fixed list of steps. Each step can be played (on screen, at a
5
+ * person's pace: the AI's parts through the MCP server, the person's through
6
+ * Playwright) or seeded (its end state, at once, with no animation), so
7
+ * `--step N` seeds 1..N-1 and plays from N.
8
+ */
9
+ export const PROJECT = "Platform";
10
+ export const PROJECT_SLUG = "platform";
11
+ export const OVERVIEW_ID = "system-overview";
12
+ /** The PRD the Docs step opens: the API gateway's, from examples/platform. */
13
+ export const PRD_TITLE = "API gateway";
14
+ const AI = "AI · over MCP";
15
+ const YOU = "You";
16
+ /** Parse the first text block of a tool reply as JSON. */
17
+ async function aiJson(s, tool, args = {}) {
18
+ const r = (await must(s.ai, tool, args));
19
+ return JSON.parse((r.text ?? "").split("\n(pending in Approvals")[0]);
20
+ }
21
+ const overview = (s) => s.http("GET", `/api/views/${OVERVIEW_ID}`);
22
+ const connection = (v, from, to) => v.connections.find((c) => c.from === from && c.to === to);
23
+ // ---- What each step does to the data (shared by play and seed) -------------------
24
+ /** pre-audit's first move: the project's sources. Each repo becomes a module on the System Overview. */
25
+ async function addSources(s, beat = async () => { }) {
26
+ await must(s.ai, "use_project", { project: PROJECT_SLUG });
27
+ for (const src of SOURCES) {
28
+ await must(s.ai, "add_source", { path: join(s.disk, src) });
29
+ await beat(src !== "docs");
30
+ }
31
+ }
32
+ /** The person's edit, as the canvas would save it: Auth moved, a bend on Frontend to API, Products renamed. */
33
+ export function humanEdit(v) {
34
+ const next = structuredClone(v);
35
+ delete next.auto_layout;
36
+ const auth = next.modules.find((m) => m.id === "auth");
37
+ const api = next.modules.find((m) => m.id === "api");
38
+ if (auth)
39
+ auth.y += 60;
40
+ const products = next.modules.find((m) => m.id === "products");
41
+ if (products)
42
+ products.name = "Catalogue";
43
+ const frontend = next.modules.find((m) => m.id === "frontend");
44
+ const c = connection(next, "frontend", "api");
45
+ if (c && frontend && api)
46
+ c.bends = [{ x: Math.round(api.x + 160), y: Math.round((frontend.y + api.y) / 2) }];
47
+ return next;
48
+ }
49
+ /**
50
+ * The AI's amendment to the System Overview: a Notifications service (green),
51
+ * Auth renamed Identity (amber), the direct products feed to Pricing retired
52
+ * (red). The View has a person's Save on it, so every write waits in Approvals.
53
+ */
54
+ async function propose(s, beat = async () => { }) {
55
+ await must(s.ai, "use_project", { project: PROJECT_SLUG });
56
+ await must(s.ai, "add_module", {
57
+ view: OVERVIEW_ID,
58
+ name: "Notifications",
59
+ type: "service",
60
+ description: "Tells a customer when their quote is ready.",
61
+ });
62
+ await beat();
63
+ await must(s.ai, "connect", { view: OVERVIEW_ID, from: "pricing", to: "Notifications", label: "quote ready" });
64
+ await beat();
65
+ await must(s.ai, "update_module", { module: "auth", in_view: OVERVIEW_ID, name: "Identity", description: "Sign-in, short-lived tokens and JWKS." });
66
+ await beat();
67
+ const v = await aiJson(s, "get_view", { view: OVERVIEW_ID, format: "json" });
68
+ const feed = connection(v, "products", "pricing");
69
+ if (feed)
70
+ await must(s.ai, "remove", { view: OVERVIEW_ID, connection: feed.id });
71
+ await beat();
72
+ }
73
+ const pendingApproval = async (s) => (await s.http("GET", "/api/approvals")).find((p) => p.status === "pending");
74
+ /**
75
+ * The PRD in the project's Specs (the Docs tree): made from the PRD template,
76
+ * as New PRD does, with the API gateway's PRD from examples/platform as its
77
+ * text. Set up rather than shown: MCP create_doc puts a home project's docs in
78
+ * its reports, which the Docs tree leaves out.
79
+ */
80
+ export async function ensurePrd(s, readExample) {
81
+ const tree = await s.http("GET", "/api/tree");
82
+ const have = tree.items.find((i) => i.kind === "doc" && i.doc_type === "prd" && i.name.toLowerCase() === PRD_TITLE.toLowerCase());
83
+ if (have)
84
+ return have.ref;
85
+ const made = await s.http("POST", "/api/tree/new-doc", { type: "prd", title: PRD_TITLE });
86
+ const text = (await readExample("docs/api/PRD.md")).replace(/^# .*$/m, `# ${PRD_TITLE}`);
87
+ await s.http("PUT", `/api/doc?path=${encodeURIComponent(made.ref)}`, { text });
88
+ return made.ref;
89
+ }
90
+ /** The version to restore in step 7: the person's Save, from before the AI's change went live. */
91
+ async function restoreTarget(s) {
92
+ const rows = await s.http("GET", `/api/views/${OVERVIEW_ID}/versions`);
93
+ return rows.find((r) => r.by === "human") ?? rows[1];
94
+ }
95
+ // ---- On screen -------------------------------------------------------------------
96
+ const moduleNode = (page, name) => page.locator(".react-flow__node").filter({ has: page.getByText(name, { exact: true }) }).first();
97
+ /** A beat for the AI's drawing: let the change arrive, fit the View, hold. */
98
+ const settle = (show, hold) => async () => {
99
+ await show.human.pause(260);
100
+ await show.screen.fit();
101
+ await show.human.pause(hold);
102
+ };
103
+ /** A point along a connection's path (0: its start, 1: its end), on screen. */
104
+ async function edgePoint(page, id, at) {
105
+ return page.locator(`.react-flow__edge[data-id="${id}"] path.react-flow__edge-path`).first().evaluate((el, at) => {
106
+ // An SVG path (no DOM types on the Node side).
107
+ const path = el;
108
+ const p = path.getPointAtLength(path.getTotalLength() * at);
109
+ const m = path.getScreenCTM();
110
+ return { x: p.x * m.a + m.e, y: p.y * m.d + m.f };
111
+ }, at);
112
+ }
113
+ /** The bend handle nearest a point (a double-click can add more than one). */
114
+ async function nearestBend(page, p) {
115
+ const all = await page.getByTestId("sv-bend").all();
116
+ let best = null;
117
+ for (const [i, b] of all.entries()) {
118
+ const box = await b.boundingBox();
119
+ if (!box)
120
+ continue;
121
+ const d = Math.hypot(box.x + box.width / 2 - p.x, box.y + box.height / 2 - p.y);
122
+ if (!best || d < best.d)
123
+ best = { i, d };
124
+ }
125
+ return best ? all[best.i] : null;
126
+ }
127
+ export function steps(readExample) {
128
+ return [
129
+ {
130
+ title: "Projects: an empty start, then a new project",
131
+ async seed(s) {
132
+ await s.http("POST", "/api/projects", { name: PROJECT });
133
+ },
134
+ async play(_s, { page, human, screen }) {
135
+ await screen.caption("A fresh install: no projects yet.", "Spatial Views");
136
+ await human.pause(1800);
137
+ await screen.caption("Start a project for the platform.", YOU);
138
+ await human.click(page.getByRole("textbox").first());
139
+ await human.type(PROJECT);
140
+ await human.pause(300);
141
+ await human.click(page.getByRole("button", { name: "Create" }));
142
+ await page.getByTestId("sv-crumbs").waitFor();
143
+ await human.pause(900);
144
+ },
145
+ },
146
+ {
147
+ title: "pre-audit draws the System Overview over MCP",
148
+ async seed(s) {
149
+ await addSources(s);
150
+ await drawPlatform(s.ai);
151
+ await must(s.ai, "record_audit", { kind: "pre-audit" });
152
+ },
153
+ async play(s, show) {
154
+ const { screen, human } = show;
155
+ await screen.caption("pre-audit reads the platform's five repos, and adds each one as a module.", AI);
156
+ await human.pause(900);
157
+ await addSources(s, async (repo) => {
158
+ if (repo)
159
+ await settle(show, 650)();
160
+ });
161
+ await screen.caption("It names and types each module, then connects them: the System Overview.", AI);
162
+ await human.pause(600);
163
+ let said = false;
164
+ await drawPlatform(s.ai, async (kind) => {
165
+ if (kind === "details") {
166
+ if (!said)
167
+ await screen.caption("Then a Sub View for each area, with its PRD and SDD pinned.", AI);
168
+ said = true;
169
+ return;
170
+ }
171
+ await settle(show, kind === "module" ? 450 : 650)();
172
+ });
173
+ await must(s.ai, "record_audit", { kind: "pre-audit" });
174
+ await settle(show, 1400)();
175
+ },
176
+ },
177
+ {
178
+ title: "Drill into the API, then back",
179
+ async seed() { },
180
+ async play(_s, { page, human, screen }) {
181
+ await screen.caption("Double-click a module to go into its Sub View.", YOU);
182
+ await human.dblclick(moduleNode(page, "API"));
183
+ await page.getByTestId("sv-crumbs").getByText("API", { exact: true }).waitFor();
184
+ await human.pause(600);
185
+ await screen.fit();
186
+ await human.pause(2600);
187
+ await screen.caption("And back up to the System Overview.", YOU);
188
+ await human.click(page.getByTestId("sv-crumbs").getByRole("button", { name: "System Overview" }));
189
+ await moduleNode(page, "Frontend").waitFor();
190
+ await human.pause(1200);
191
+ },
192
+ },
193
+ {
194
+ title: "A person's edit: drag, bend, rename, Save",
195
+ async seed(s) {
196
+ await s.http("PUT", `/api/views/${OVERVIEW_ID}`, humanEdit(await overview(s)));
197
+ },
198
+ async play(s, { page, human, screen }) {
199
+ await screen.caption("Arrange it by hand: drag a module…", YOU);
200
+ await human.pause(500);
201
+ await human.drag(moduleNode(page, "Auth"), { x: -40, y: 90 }, { dx: 30 });
202
+ await human.pause(700);
203
+ await screen.shot("step-4a-dragged");
204
+ await screen.caption("…double-click a connection to bend it, and drag the bend…", YOU);
205
+ const c = connection(await overview(s), "frontend", "api");
206
+ if (c) {
207
+ // A third of the way down, clear of the label.
208
+ const at = await edgePoint(page, c.id, 0.3);
209
+ await human.dblclick(at);
210
+ if (!(await page.getByTestId("sv-bend").count()))
211
+ await human.click(at);
212
+ const bend = await nearestBend(page, at);
213
+ if (bend)
214
+ await human.drag(bend, { x: 160, y: 0 });
215
+ await human.pause(500);
216
+ await screen.shot("step-4b-bend");
217
+ // Let go of the connection, so its Properties close.
218
+ await human.click({ x: 260, y: 200 });
219
+ }
220
+ await human.pause(500);
221
+ await screen.caption("…rename a module, and Save.", YOU);
222
+ await human.click(moduleNode(page, "Products"), { dx: 40 });
223
+ const name = page.getByTestId("sv-prop-name");
224
+ await human.click(name);
225
+ await human.press("Control+a");
226
+ await human.type("Catalogue");
227
+ await human.press("Enter");
228
+ await human.pause(600);
229
+ await screen.shot("step-4c-renamed");
230
+ await human.click(page.getByTestId("sv-save"));
231
+ await page.getByTestId("sv-unsaved").waitFor({ state: "hidden" });
232
+ await human.click({ x: 260, y: 200 });
233
+ await human.pause(1200);
234
+ },
235
+ },
236
+ {
237
+ title: "The AI amends the View; Approvals; Approve",
238
+ async seed(s) {
239
+ await propose(s);
240
+ const p = await pendingApproval(s);
241
+ if (p)
242
+ await s.http("POST", `/api/approvals/${encodeURIComponent(p.id)}/approve`, {});
243
+ },
244
+ async play(s, show) {
245
+ const { page, human, screen } = show;
246
+ await screen.caption("The AI proposes a change. It waits for a person to approve it.", AI);
247
+ await human.pause(900);
248
+ await propose(s, settle(show, 900));
249
+ await human.pause(800);
250
+ await screen.shot("step-5a-proposed");
251
+ await screen.dismissToast();
252
+ await screen.caption("Approvals: green added, amber amended, red removed.", YOU);
253
+ await human.click(page.getByRole("button", { name: /^Approvals/ }));
254
+ await page.getByTestId("sv-review").waitFor();
255
+ await human.pause(1800);
256
+ await screen.shot("step-5b-review");
257
+ const amended = page.getByTestId("sv-diff-after").locator('.sv-module[data-diff="amended"]').first();
258
+ if (await amended.count()) {
259
+ await human.click(amended);
260
+ await human.pause(1800);
261
+ await screen.shot("step-5c-amended");
262
+ }
263
+ await screen.caption("Approve, and it goes live.", YOU);
264
+ await human.click(page.getByRole("button", { name: /^Approve( all)?$/ }).first());
265
+ await page.getByTestId("sv-approval-status").getByText("approved").waitFor();
266
+ await human.pause(1200);
267
+ await human.click(page.getByRole("button", { name: "Close approvals", exact: true }));
268
+ await moduleNode(page, "Notifications").waitFor();
269
+ await screen.dismissToast();
270
+ await screen.fit();
271
+ await human.pause(1600);
272
+ },
273
+ },
274
+ {
275
+ title: "The Docs tree: open a PRD",
276
+ async seed(s) {
277
+ await ensurePrd(s, readExample);
278
+ },
279
+ async play(s, { page, human, screen }) {
280
+ const ref = await ensurePrd(s, readExample);
281
+ await screen.caption("The Docs tree: the project's specs, beside the picture.", YOU);
282
+ await human.click(page.getByTestId("sv-rbar-docs"));
283
+ const item = page.getByTestId("sv-docs-tree").locator(`[data-testid="sv-tree-item"][data-ref="${ref}"]`);
284
+ await item.waitFor();
285
+ await human.pause(900);
286
+ await screen.caption("Open the API gateway's PRD.", YOU);
287
+ await human.click(item.locator(".sv-tree-open").first());
288
+ await page.getByTestId("sv-doc-editor").waitFor();
289
+ await human.pause(1400);
290
+ await screen.shot("step-6a-prd");
291
+ await screen.caption("Close it, and the picture has the room again.", YOU);
292
+ await human.click(page.getByRole("button", { name: "Close the doc", exact: true }));
293
+ await human.click(page.getByRole("button", { name: "Close the Docs panel", exact: true }));
294
+ await human.pause(600);
295
+ await screen.fit();
296
+ await human.pause(1200);
297
+ },
298
+ },
299
+ {
300
+ title: "Version history, then restore",
301
+ async seed() { },
302
+ async play(s, { page, human, screen }) {
303
+ await screen.caption("Every save is a version. Open the View's history…", YOU);
304
+ await human.pause(500);
305
+ await human.click(page.getByTestId("sv-view-menu-btn"));
306
+ await human.click(page.getByTestId("sv-view-menu").getByRole("menuitem", { name: "Version history" }));
307
+ await page.getByTestId("sv-versions").waitFor();
308
+ await human.pause(1200);
309
+ await screen.shot("step-7a-history");
310
+ const target = await restoreTarget(s);
311
+ if (!target)
312
+ return;
313
+ await screen.caption("…preview the one from before the AI's change…", YOU);
314
+ await human.click(page.getByTestId(`sv-version-${target.n}`).locator(".sv-version-pick"));
315
+ await page.getByTestId("sv-version-canvas").waitFor();
316
+ await human.pause(2600);
317
+ await screen.shot("step-7b-preview");
318
+ await screen.caption("…and restore it. It comes back as a new version: nothing is lost.", YOU);
319
+ await human.click(page.getByTestId("sv-version-restore"));
320
+ await page.getByTestId("sv-version-preview").waitFor({ state: "hidden" });
321
+ await screen.fit();
322
+ await human.pause(2400);
323
+ },
324
+ },
325
+ ];
326
+ }
327
+ /** How many steps there are (for --step), without building them. */
328
+ export const STEP_COUNT = 7;
@@ -0,0 +1,193 @@
1
+ import { basename, resolve } from "node:path";
2
+ import { z } from "zod";
3
+ import { readSettings } from "../core/approvals.js";
4
+ import { UserError } from "../core/errors.js";
5
+ import { AuditKindSchema, localPath, SourceKindSchema } from "../core/project.js";
6
+ import { realPath, ScopeError } from "../core/scope.js";
7
+ import { samePath } from "../core/paths.js";
8
+ import { resolveView } from "../core/resolve.js";
9
+ import { compactScan, scanSource } from "../core/scan.js";
10
+ import { findRelated, parentsOf, siblingFolders } from "../core/suggest.js";
11
+ export const PROJECT_TOOL_NAMES = [
12
+ "list_projects",
13
+ "create_project",
14
+ "use_project",
15
+ "get_project",
16
+ "add_source",
17
+ "remove_source",
18
+ "list_sources",
19
+ "record_audit",
20
+ "save_report",
21
+ "scan_source",
22
+ "suggest_sources",
23
+ ];
24
+ /** The tools that work with no project in use. Every other tool refuses until use_project. */
25
+ export const NO_PROJECT_TOOLS = ["list_projects", "create_project", "use_project"];
26
+ /**
27
+ * The Project tools (PRD §9.1, §9.3). The project is the boundary: the server
28
+ * reads only the folders added with add_source, and never writes to them.
29
+ * Everything the project makes goes in its own folder.
30
+ */
31
+ export function registerProjectTools(server, session, guard, json, text,
32
+ /** The active project as the tools see it (the server passes it with its writes staged). */
33
+ current = () => session.current,
34
+ /** True when this agent run already has changes waiting in Approvals. */
35
+ hasPending = async () => false) {
36
+ const ws = current;
37
+ const spatial = () => ws().spatial;
38
+ const summary = async () => {
39
+ const w = ws();
40
+ const p = await w.info();
41
+ // How the project writes specs (Settings → Project → Spec format): the Skills follow it.
42
+ const { spec_format } = await readSettings(w.spatial);
43
+ return { ...p, spec_format, views: await w.spatial.views.list() };
44
+ };
45
+ server.registerTool("list_projects", {
46
+ description: "List the Spatial Views projects (slug, name, which one is active). Start every Skill here, then " +
47
+ "use_project. A new install has none: create_project makes one.",
48
+ }, async () => guard(async () => json(await session.list())));
49
+ server.registerTool("create_project", {
50
+ description: "Create a project in the Spatial Views home folder (~/SpatialViews/projects/<slug>/) with an empty " +
51
+ "System Overview View, and make it the active project. Then add_source each repo, docs or diagrams folder.",
52
+ inputSchema: { name: z.string().min(1) },
53
+ }, async ({ name }) => guard(async () => {
54
+ await session.create(name);
55
+ return json({ ...(await summary()), active: true });
56
+ }));
57
+ server.registerTool("use_project", {
58
+ description: "Make a project the active one (slug or name, from list_projects). Every other tool works on the " +
59
+ "active project only, and reads only its sources.",
60
+ inputSchema: { project: z.string().min(1).describe("slug or name") },
61
+ }, async ({ project }) => guard(async () => {
62
+ await session.use(project);
63
+ return json({ active: true, ...(await summary()) });
64
+ }));
65
+ server.registerTool("get_project", {
66
+ description: "The active project: name, slug, its sources (with last_audit_sha), past audits, its Views, and spec_format: " +
67
+ "spatial-views (specs are PRD, MDD and Gap docs) or openspec (openspec/specs and openspec/changes).",
68
+ }, async () => guard(async () => json(await summary())));
69
+ server.registerTool("add_source", {
70
+ description: "Add a folder to the active project as a read-only source: a repo, docs or diagrams. Give the full " +
71
+ "path, Windows (c:\\git\\api) or POSIX. Without kind: repo if it has .git, diagrams if its name says " +
72
+ "so, else docs. A repo gets a module on the System Overview. The server only ever reads it, and " +
73
+ "reads no folder that is not a source. Adding the same folder again returns the source already there.",
74
+ inputSchema: {
75
+ path: z.string().min(1),
76
+ kind: SourceKindSchema.optional(),
77
+ id: z.string().optional().describe("a file-safe id; made from the folder name if left out"),
78
+ name: z.string().optional().describe("what to call it (default: the folder name)"),
79
+ },
80
+ }, async (input) => guard(async () => json(await ws().addSource(input))));
81
+ server.registerTool("remove_source", {
82
+ description: "Take a source off the active project (id or path), and its module off the System Overview. The " +
83
+ "folder itself is not touched. After this the server no longer reads it.",
84
+ inputSchema: { source: z.string().min(1).describe("source id or path") },
85
+ }, async ({ source }) => guard(async () => json(await ws().removeSource(source))));
86
+ server.registerTool("list_sources", {
87
+ description: "List the active project's sources (id, name, kind, path, added, last_audit_sha), optionally of one kind.",
88
+ inputSchema: { kind: SourceKindSchema.optional() },
89
+ }, async ({ kind }) => guard(async () => json((await ws().project.get()).sources.filter((s) => !kind || s.kind === kind))));
90
+ server.registerTool("record_audit", {
91
+ description: "Record that an audit ran (pre-audit, update-state or post-audit), with its report. Each source it " +
92
+ "read gets last_audit_sha: the sha given in shas, else the repo's current commit, else the time " +
93
+ "(docs and diagrams). update-state reads changes since that. A pre-audit also sets the project's " +
94
+ "root_view_id (the System Overview), the View the project always opens on.",
95
+ inputSchema: {
96
+ kind: AuditKindSchema,
97
+ report: z.string().optional().describe("a report saved with save_report (its name, or reports/<name>.md)"),
98
+ sources: z.array(z.string()).optional().describe("the source ids read (default: all)"),
99
+ shas: z.record(z.string(), z.string()).optional().describe("source id -> commit sha"),
100
+ },
101
+ }, async (input) => guard(async () => {
102
+ const w = ws();
103
+ // A pre-audit sets root_view_id: the project always opens on its System Overview.
104
+ const root = input.kind === "pre-audit" ? (await w.landing())?.id : undefined;
105
+ return json(await w.project.recordAudit({ ...input, ...(root ? { root_view_id: root } : {}) }));
106
+ }));
107
+ server.registerTool("save_report", {
108
+ description: "Write a markdown report to the project's reports/<name>.md (never anywhere else, never into a source) " +
109
+ "and pin it to a View: the one given, else the System Overview. Use for onboarding, changes and audit-report.",
110
+ inputSchema: {
111
+ name: z.string().min(1).describe("e.g. onboarding, changes-2026-11-21, audit-report"),
112
+ markdown: z.string().min(1),
113
+ view: z.string().optional().describe("View id or name to pin to (default: the System Overview)"),
114
+ },
115
+ }, async ({ name, markdown, view }) => guard(async () => {
116
+ const all = await spatial().views.listViews();
117
+ const target = view ? resolveView(all, view) : await ws().overview(false);
118
+ if (view && !target)
119
+ throw new UserError(`no View ${view}`);
120
+ // A report goes with the run's changes: with approvals on, it waits in the same Approval.
121
+ // An audit that changed nothing has no Approval, so its report is written straight away
122
+ // (to the project's reports/, never to a source) and no empty Approval is made.
123
+ const w = (await hasPending()) ? ws() : session.current;
124
+ await w.project.get();
125
+ const path = await w.spatial.docs.write(w.project.reportRel(name), markdown.endsWith("\n") ? markdown : markdown + "\n");
126
+ if (!target)
127
+ return text(`wrote ${path}; not pinned (no System Overview yet; pass view, or pin it later)`);
128
+ await w.spatial.pins.add({ path, kind: "view", view_id: target.id });
129
+ return text(`wrote ${path}, pinned to View ${target.name} (${target.id})`);
130
+ }));
131
+ server.registerTool("scan_source", {
132
+ description: "Read one of the active project's sources (read-only, size-capped) so you can draw it. Only a " +
133
+ "source id (or its path) from list_sources: any other folder is refused. Symlinks are not followed. " +
134
+ "Repos: tree, languages, manifests, " +
135
+ "entry points, HTTP routes, queue and DB use, and calls to other sources (target is the source id). " +
136
+ "Docs: the .md files (kind prd, sdd, tdd, pbi, openspec-spec, ...) and OpenSpec specs and changes. " +
137
+ "Diagrams: Mermaid and draw.io parsed to nodes and edges (sequence diagrams to participants and " +
138
+ "messages); images, PDFs and Miro CSVs are listed for you to open and read. Empty lists are left " +
139
+ "out; truncated says a cap was hit.",
140
+ inputSchema: {
141
+ source_id: z.string().min(1).describe("a source id from list_sources"),
142
+ max_files: z.number().int().positive().max(20000).optional().describe("files walked (default 5000)"),
143
+ },
144
+ }, async ({ source_id, max_files }) => guard(async () => {
145
+ const w = ws();
146
+ const p = await w.project.get();
147
+ const s = p.sources.find((x) => x.id === source_id) ?? (await sourceByPath(w, source_id));
148
+ if (!s)
149
+ throw new ScopeError(`${source_id} is not a source of ${p.name}. Allowed: ${await w.allowed()}`);
150
+ const others = p.sources.filter((x) => x.id !== s.id).map((x) => x.id);
151
+ const abs = await realPath(w.project.sourcePath(s));
152
+ const r = await scanSource(abs, s.kind, others, max_files ? { maxFiles: max_files } : {});
153
+ return json({ source: s, ...compactScan(r) });
154
+ }));
155
+ server.registerTool("suggest_sources", {
156
+ description: "Which other repos does this source point at? Read-only, and only inside the source (a source id " +
157
+ "from list_sources). Evidence: internal package dependencies, API base URLs and hostnames, queue and " +
158
+ "topic names, git remotes and submodules, docker-compose and k8s service names, and docs that name " +
159
+ "another repo. Returns [{name, evidence: [{file, line, text}], candidate_paths}]. candidate_paths " +
160
+ "are folders next to the project's sources whose name matches, found by listing those folders only: " +
161
+ "nothing inside them is read. Adds nothing: ask the user, then add_source the ones they want.",
162
+ inputSchema: { source_id: z.string().min(1).describe("a source id from list_sources") },
163
+ }, async ({ source_id }) => guard(async () => {
164
+ const w = ws();
165
+ const p = await w.project.get();
166
+ const s = p.sources.find((x) => x.id === source_id) ?? (await sourceByPath(w, source_id));
167
+ if (!s)
168
+ throw new ScopeError(`${source_id} is not a source of ${p.name}. Allowed: ${await w.allowed()}`);
169
+ const real = await Promise.all(p.sources.map((x) => realPath(w.project.sourcePath(x))));
170
+ const mine = new Set(real.map((x) => resolve(x)));
171
+ const siblings = (await siblingFolders(parentsOf(real))).filter((x) => !mine.has(resolve(x)));
172
+ const self = p.sources.flatMap((x, i) => [x.id, x.name ?? x.id, basename(real[i])]);
173
+ const abs = real[p.sources.findIndex((x) => x.id === s.id)];
174
+ return json(await findRelated(abs, { self, siblings }));
175
+ }));
176
+ }
177
+ /** The source whose folder is exactly this path, as written or by the source's real path (no other folder is looked at). */
178
+ async function sourceByPath(w, path) {
179
+ const p = await w.project.get();
180
+ let want;
181
+ try {
182
+ want = resolve(localPath(w.spatial.root, path));
183
+ }
184
+ catch {
185
+ return undefined;
186
+ }
187
+ for (const s of p.sources) {
188
+ const at = resolve(w.project.sourcePath(s));
189
+ if (s.path === path.trim() || samePath(at, want) || samePath(await realPath(at), want))
190
+ return s;
191
+ }
192
+ return undefined;
193
+ }