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
package/dist/cli/index.js CHANGED
@@ -1,29 +1,68 @@
1
1
  #!/usr/bin/env node
2
2
  import { createServer as createHttpServer } from "node:http";
3
- import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
4
4
  import { extname, join, normalize, resolve, sep } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
7
  import { createServer } from "../mcp/server.js";
8
8
  import { createApiHandler } from "../core/api.js";
9
- import { Spatial } from "../core/storage.js";
10
- import { ViewWatcher } from "../core/watch.js";
9
+ import { homeDir, prepareHome, Session } from "../core/home.js";
10
+ import { homedir } from "node:os";
11
+ import { doctor } from "../core/doctor.js";
12
+ import { portError, resolveLaunch } from "../core/launch.js";
13
+ import { findWindowsHome, IDES, setup } from "../core/setup.js";
14
+ import { FolderStore } from "../core/storage/folder.js";
15
+ import { ProjectEvents } from "../core/storage/events.js";
16
+ import { openStorage, readStorageConfig } from "../core/storage/config.js";
17
+ import { describeUrl, PostgresStore } from "../core/storage/postgres.js";
18
+ import { migrateStore } from "../core/storage/migrate.js";
11
19
  import { VERSION } from "../core/version.js";
12
20
  import { jsonSchemas } from "../core/schema.js";
13
- import { init, writeGenerated } from "../core/skills.js";
21
+ import { checkToolboxFiles, formatError, loadToolbox, newToolboxFile, projectToolboxDir, userToolboxDir } from "../core/types.js";
22
+ import { UserError } from "../core/errors.js";
23
+ import { detectWsl, init, writeGenerated } from "../core/skills.js";
24
+ import { runDemo } from "../demo/run.js";
14
25
  const HELP = `spatial-views ${VERSION}
15
26
 
16
27
  Usage:
17
- npx spatial-views open the canvas on http://127.0.0.1:4317 for the current repo
18
- npx spatial-views mcp run the MCP server on stdio (for Cursor, Claude Code, Windsurf)
19
- npx spatial-views init add the Skills and MCP config for Cursor, Claude Code and Windsurf
20
- to this repo (--cursor / --claude / --windsurf for one; --force)
21
- npx spatial-views schema write the JSON Schemas for .spatial/ files to ./schema
28
+ npx spatial-views setup install once: add spatial-views to the global MCP config of Cursor,
29
+ Claude Code and Windsurf (the WSL form when in WSL), and the Skills
30
+ to ~/.claude/skills (--cursor / --claude / --windsurf for some;
31
+ --force replaces; --dry-run shows what it would write)
32
+ npx spatial-views doctor start each spatial-views entry in the IDE configs exactly as written,
33
+ run MCP initialize and tools/list, and print OK or the fix.
34
+ Exits non-zero on any failure (--timeout <seconds>, default 60)
35
+ npx spatial-views open the canvas on http://127.0.0.1:4317: your projects, or the repo
36
+ in --dir (or here, when it has .spatial/)
37
+ npx spatial-views mcp run the MCP server on stdio. --global: no project until use_project
38
+ (what setup writes). Without it: the repo in --dir, or here
39
+ npx spatial-views init one repo as its own project: the Skills and MCP config in this repo
40
+ (--cursor / --claude / --windsurf for one; --force)
41
+ npx spatial-views schema write the JSON Schemas (data files, toolbox and type YAML) to ./schema
42
+ (--out <dir>)
43
+ npx spatial-views toolbox new <name>
44
+ scaffold toolboxes/<name>.yaml: in this repo's .spatial/ (else your
45
+ home folder); --user for ~/SpatialViews/toolboxes, --out <dir> for any
46
+ npx spatial-views toolbox check [file...]
47
+ check toolbox YAML (default: this project's and your own); errors
48
+ name the file and line
49
+ npx spatial-views toolbox list
50
+ the toolboxes in load order: built-in, user, project
51
+ npx spatial-views demo the scripted demo, for recording: a throwaway home, the canvas and a
52
+ 1920x1080 browser window; space for each step (--auto [--delay <ms>]
53
+ runs on a timer; --step <n> starts at step n). Needs Playwright's
54
+ Chromium: npx playwright install chromium
55
+ npx spatial-views migrate --to postgres|folder
56
+ copy every project to the other store, then check counts and hashes;
57
+ the source is left as it was (--home <dir>: the folder side)
22
58
 
23
59
  Options:
24
60
  --port <n> canvas port (default 4317)
25
- --dir <path> the repo to open (default: the current directory)
26
- --help, --version`;
61
+ --dir <path> a single-repo project to open
62
+ --help, --version
63
+
64
+ Projects live in ${homeDir()} (SPATIAL_VIEWS_HOME to move it), or in Postgres:
65
+ Settings → Storage, or SPATIAL_VIEWS_STORAGE=postgres and SPATIAL_VIEWS_DATABASE_URL.`;
27
66
  const TYPES = {
28
67
  ".html": "text/html; charset=utf-8",
29
68
  ".js": "text/javascript; charset=utf-8",
@@ -39,12 +78,91 @@ async function writeSchemas(outDir) {
39
78
  console.log(`wrote ${file}`);
40
79
  }
41
80
  }
42
- async function runMcp(root) {
43
- await createServer({ root }).connect(new StdioServerTransport());
81
+ /**
82
+ * End the process on purpose, once stdout has drained. Letting Node exit on
83
+ * its own (an empty event loop) aborts with a core dump when the shell has
84
+ * leaked a parent's IPC channel (NODE_CHANNEL_FD, e.g. from pm2) whose fd is
85
+ * not open here: Node adopts it at start-up and asserts when it tears it down.
86
+ */
87
+ function exitNow(code = 0) {
88
+ process.stdout.write("", () => process.exit(code));
44
89
  }
45
- function runApp(port, root) {
90
+ /** The flag's value (`--out x`), or undefined. */
91
+ const flag = (a, name) => {
92
+ const i = a.indexOf(name);
93
+ return i >= 0 && a[i + 1] && !a[i + 1].startsWith("--") ? a[i + 1] : undefined;
94
+ };
95
+ /** spatial-views toolbox new | check | list. The repo here (or --dir) is the project when it has .spatial/. */
96
+ async function runToolbox(a) {
97
+ const repoData = join(root, ".spatial");
98
+ const hasRepo = !!(await stat(repoData).catch(() => null))?.isDirectory();
99
+ const project = hasRepo ? repoData : null;
100
+ try {
101
+ if (a[0] === "new") {
102
+ const name = a.slice(1).find((x, i, all) => !x.startsWith("--") && !["--out", "--dir"].includes(all[i - 1] ?? ""));
103
+ if (!name)
104
+ throw new UserError("usage: spatial-views toolbox new <name> [--user | --out <dir>]");
105
+ const out = flag(a, "--out");
106
+ const dir = out ? resolve(out) : a.includes("--user") || !project ? userToolboxDir() : projectToolboxDir(project);
107
+ const file = await newToolboxFile(dir, name);
108
+ console.log(`wrote ${file}\ncheck it: spatial-views toolbox check ${file}`);
109
+ return 0;
110
+ }
111
+ if (a[0] === "check") {
112
+ const files = a.slice(1).filter((x, i, all) => !x.startsWith("--") && all[i - 1] !== "--dir");
113
+ const { toolbox, errors } = files.length
114
+ ? await checkToolboxFiles(files)
115
+ : await loadToolbox(project).then((t) => ({ toolbox: t, errors: t.errors }));
116
+ for (const e of errors)
117
+ console.error(formatError(e));
118
+ const ok = toolbox.toolboxes.filter((t) => files.length === 0 || t.files.some((f) => files.map((x) => resolve(x)).includes(f)));
119
+ for (const t of ok)
120
+ console.log(`${t.id}: ${t.types.length} types, ${t.docs.length} doc types (${t.files.join(", ")})`);
121
+ console.log(errors.length ? `${errors.length} problem${errors.length === 1 ? "" : "s"}` : "ok");
122
+ return errors.length ? 1 : 0;
123
+ }
124
+ if (a[0] === "list") {
125
+ const t = await loadToolbox(project);
126
+ for (const x of t.toolboxes)
127
+ console.log(`${x.enabled ? " " : "-"} ${x.id.padEnd(12)} ${x.name.padEnd(14)} ${String(x.types.length + x.docs.length).padStart(3)} types ${x.source}`);
128
+ for (const e of t.errors)
129
+ console.error(formatError(e));
130
+ return 0;
131
+ }
132
+ throw new UserError("usage: spatial-views toolbox new <name> | check [file...] | list");
133
+ }
134
+ catch (e) {
135
+ if (!(e instanceof UserError))
136
+ throw e;
137
+ console.error(e.message);
138
+ return 1;
139
+ }
140
+ }
141
+ async function runMcp(root, global, storage) {
142
+ const server = createServer({ session: new Session(global ? { storage } : { repo: root, storage }) });
143
+ // The client closing stdin is the end of the session: close and exit 0.
144
+ let closing = false;
145
+ const end = () => {
146
+ if (closing)
147
+ return;
148
+ closing = true;
149
+ void server
150
+ .close()
151
+ .catch(() => { })
152
+ .then(() => storage.close())
153
+ .catch(() => { })
154
+ .finally(() => exitNow(0));
155
+ };
156
+ process.stdin.once("end", end);
157
+ process.stdin.once("close", end);
158
+ await server.connect(new StdioServerTransport());
159
+ }
160
+ function runApp(port, session, label, storage) {
46
161
  const appDir = fileURLToPath(new URL("../app/", import.meta.url));
47
- const api = createApiHandler(new Spatial(root), ViewWatcher.forRepo(root));
162
+ const api = createApiHandler(session, (sp) => new ProjectEvents(sp.storage, sp.ref.project, sp.localDir, undefined, sp.dataDir, userToolboxDir(session.home.dir)), {
163
+ home: homeDir(),
164
+ running: storage.backend,
165
+ });
48
166
  const server = createHttpServer(async (req, res) => {
49
167
  if (await api(req, res))
50
168
  return;
@@ -63,48 +181,158 @@ function runApp(port, root) {
63
181
  res.writeHead(404).end("not found");
64
182
  }
65
183
  });
184
+ server.on("error", (err) => {
185
+ console.error(portError(port, err));
186
+ exitNow(1);
187
+ });
66
188
  server.listen(port, "127.0.0.1", () => {
67
- console.log(`Spatial Views on http://127.0.0.1:${port} (repo: ${root})`);
189
+ console.log(`Spatial Views on http://127.0.0.1:${port} (${label})`);
68
190
  });
69
191
  }
70
192
  const args = process.argv.slice(2);
71
193
  const dirAt = args.indexOf("--dir");
72
- const root = resolve(dirAt >= 0 && args[dirAt + 1] ? args[dirAt + 1] : process.cwd());
73
- if (args.includes("--help") || args.includes("-h")) {
74
- console.log(HELP);
75
- }
76
- else if (args.includes("--version")) {
77
- console.log(VERSION);
78
- }
79
- else if (args[0] === "init") {
80
- const pick = ["--cursor", "--claude", "--windsurf"].filter((f) => args.includes(f));
81
- const all = pick.length === 0;
82
- const self = fileURLToPath(import.meta.url);
83
- // Run through npx: write npx into the config. Run from a clone: write this file's path.
84
- const launch = /[\\/](_npx|node_modules)[\\/]/.test(self) ? ["npx", "-y", "spatial-views"] : ["node", self];
85
- const log = await init({
86
- root,
87
- skillsDir: fileURLToPath(new URL("../../skills/", import.meta.url)),
88
- launch,
89
- targets: { cursor: all || pick.includes("--cursor"), claude: all || pick.includes("--claude"), windsurf: all || pick.includes("--windsurf") },
90
- force: args.includes("--force"),
91
- });
92
- console.log(log.join("\n"));
93
- }
94
- else if (args[0] === "skills") {
95
- // For this repo: rebuild skills/cursor and skills/windsurf from skills/claude.
96
- for (const f of await writeGenerated(fileURLToPath(new URL("../../skills/", import.meta.url))))
97
- console.log(`wrote skills/${f}`);
98
- }
99
- else if (args[0] === "schema") {
100
- const o = args.indexOf("--out");
101
- await writeSchemas(resolve(o >= 0 && args[o + 1] ? args[o + 1] : "schema"));
102
- }
103
- else if (args[0] === "mcp") {
104
- await runMcp(root);
194
+ const dirGiven = dirAt >= 0 && !!args[dirAt + 1];
195
+ const root = resolve(dirGiven ? args[dirAt + 1] : process.cwd());
196
+ const self = fileURLToPath(import.meta.url);
197
+ // What an IDE runs, absolute: cmd /c npx on Windows, else node plus this file or npx-cli.js.
198
+ const resolved = resolveLaunch({ platform: process.platform, execPath: process.execPath, cli: self });
199
+ const launch = resolved.argv;
200
+ // A leaked parent IPC channel (see exitNow) must not reach anything we start.
201
+ delete process.env.NODE_CHANNEL_FD;
202
+ delete process.env.NODE_CHANNEL_SERIALIZATION_MODE;
203
+ /** The commands; anything else as the first word is an error, not the canvas. */
204
+ const COMMANDS = ["setup", "doctor", "mcp", "init", "schema", "skills", "toolbox", "migrate", "demo"];
205
+ /** Run the command. "stay" means it serves (canvas, MCP) and ends itself; else exit when done. */
206
+ async function main() {
207
+ // Move an old ~/.spatial-views to ~/SpatialViews, and make the toolboxes folder (README, example) on first run.
208
+ const cmd = args[0] && !args[0].startsWith("-") ? args[0] : undefined;
209
+ if (cmd && !COMMANDS.includes(cmd)) {
210
+ console.error(`spatial-views: unknown command "${cmd}". Commands: ${COMMANDS.join(", ")}. See spatial-views --help`);
211
+ process.exitCode = 2;
212
+ return;
213
+ }
214
+ const usesHome = !["--help", "-h", "--version"].some((f) => args.includes(f)) && !["init", "setup", "doctor", "skills", "schema", "demo"].includes(cmd ?? "");
215
+ if (usesHome)
216
+ await prepareHome();
217
+ if (cmd === "demo") {
218
+ // Its own throwaway home folder: never the user's.
219
+ process.exitCode = await runDemo(args.slice(1), self);
220
+ }
221
+ else if (args.includes("--help") || args.includes("-h")) {
222
+ console.log(HELP);
223
+ }
224
+ else if (args.includes("--version")) {
225
+ console.log(VERSION);
226
+ }
227
+ else if (args[0] === "init") {
228
+ const pick = ["--cursor", "--claude", "--windsurf"].filter((f) => args.includes(f));
229
+ const all = pick.length === 0;
230
+ const log = await init({
231
+ root,
232
+ skillsDir: fileURLToPath(new URL("../../skills/", import.meta.url)),
233
+ launch,
234
+ targets: { cursor: all || pick.includes("--cursor"), claude: all || pick.includes("--claude"), windsurf: all || pick.includes("--windsurf") },
235
+ force: args.includes("--force"),
236
+ wsl: detectWsl(),
237
+ });
238
+ console.log(log.join("\n"));
239
+ }
240
+ else if (args[0] === "setup") {
241
+ const pick = IDES.filter((i) => args.includes(`--${i}`));
242
+ const wsl = detectWsl();
243
+ const log = await setup({
244
+ launch,
245
+ ides: pick.length ? pick : IDES,
246
+ env: resolved.env,
247
+ wsl,
248
+ windowsHome: wsl ? await findWindowsHome() : null,
249
+ skillsDir: fileURLToPath(new URL("../../skills/", import.meta.url)),
250
+ force: args.includes("--force"),
251
+ dryRun: args.includes("--dry-run"),
252
+ });
253
+ console.log(log.join("\n"));
254
+ }
255
+ else if (args[0] === "doctor") {
256
+ const pick = IDES.filter((i) => args.includes(`--${i}`));
257
+ const wsl = detectWsl();
258
+ const t = args.indexOf("--timeout");
259
+ const secs = t >= 0 ? Number(args[t + 1]) : 60;
260
+ const r = await doctor({
261
+ ides: pick.length ? pick : IDES,
262
+ home: homedir(),
263
+ wsl,
264
+ windowsHome: wsl ? await findWindowsHome() : null,
265
+ timeoutMs: (Number.isFinite(secs) && secs > 0 ? secs : 60) * 1000,
266
+ });
267
+ console.log(r.lines.join("\n"));
268
+ process.exitCode = r.ok ? 0 : 1;
269
+ }
270
+ else if (args[0] === "skills") {
271
+ // For this repo: rebuild skills/cursor and skills/windsurf from skills/claude.
272
+ for (const f of await writeGenerated(fileURLToPath(new URL("../../skills/", import.meta.url))))
273
+ console.log(`wrote skills/${f}`);
274
+ }
275
+ else if (args[0] === "schema") {
276
+ const o = args.indexOf("--out");
277
+ await writeSchemas(resolve(o >= 0 && args[o + 1] ? args[o + 1] : "schema"));
278
+ }
279
+ else if (args[0] === "toolbox") {
280
+ process.exitCode = await runToolbox(args.slice(1));
281
+ }
282
+ else if (args[0] === "mcp") {
283
+ await runMcp(root, args.includes("--global"), await openStorage(homeDir()));
284
+ return "stay";
285
+ }
286
+ else if (args[0] === "migrate") {
287
+ await runMigrate();
288
+ }
289
+ else {
290
+ const i = args.indexOf("--port");
291
+ const port = i >= 0 ? Number(args[i + 1]) : 4317;
292
+ // A repo given with --dir, or one here with .spatial/ (0.1.0, init), opens as its own project;
293
+ // anywhere else the canvas starts on your projects.
294
+ const repo = !args.includes("--global") && (dirGiven || (await stat(join(root, ".spatial")).catch(() => null))?.isDirectory());
295
+ const storage = await openStorage(homeDir());
296
+ const session = new Session(repo ? { repo: root, storage } : { storage });
297
+ const where = storage instanceof PostgresStore ? `projects: Postgres ${storage.where}` : `projects: ${homeDir()}`;
298
+ runApp(Number.isInteger(port) && port > 0 ? port : 4317, session, repo ? `repo: ${root}` : where, storage);
299
+ return "stay";
300
+ }
105
301
  }
106
- else {
107
- const i = args.indexOf("--port");
108
- const port = i >= 0 ? Number(args[i + 1]) : 4317;
109
- runApp(Number.isInteger(port) && port > 0 ? port : 4317, root);
302
+ /** `migrate --to postgres|folder`: copy every project across, verify, never touch the source. */
303
+ async function runMigrate() {
304
+ const at = args.indexOf("--to");
305
+ const to = at >= 0 ? args[at + 1] : undefined;
306
+ if (to !== "postgres" && to !== "folder")
307
+ throw new Error("say where to: migrate --to postgres, or migrate --to folder");
308
+ const h = args.indexOf("--home");
309
+ const home = h >= 0 && args[h + 1] ? resolve(args[h + 1]) : homeDir();
310
+ const cfg = await readStorageConfig(homeDir());
311
+ const url = process.env.SPATIAL_VIEWS_DATABASE_URL?.trim() || cfg.url;
312
+ if (!url)
313
+ throw new Error("no database URL: set SPATIAL_VIEWS_DATABASE_URL, or save one in Settings → Storage");
314
+ const pg = await PostgresStore.connect({ url });
315
+ const folder = new FolderStore({ home });
316
+ const [source, target] = to === "postgres" ? [folder, pg] : [pg, folder];
317
+ const label = (s) => (s === pg ? `Postgres ${describeUrl(url)}` : home);
318
+ try {
319
+ console.log(`copying from ${label(source)} to ${label(target)}`);
320
+ const report = await migrateStore(source, target, { by: "spatial-views migrate" });
321
+ for (const p of report.projects) {
322
+ const counts = p.kinds.filter((k) => k.count).map((k) => `${k.count} ${k.kind}`);
323
+ console.log(` ${p.slug}: ${counts.join(", ")}: counts and hashes match`);
324
+ }
325
+ console.log(report.projects.length
326
+ ? `done: ${report.projects.length} project(s), ${report.total} objects; ${label(source)} is unchanged`
327
+ : `nothing to copy: ${label(source)} has no projects`);
328
+ if (to === "postgres")
329
+ console.log("to use it: Settings → Storage → Postgres, or SPATIAL_VIEWS_STORAGE=postgres");
330
+ }
331
+ finally {
332
+ await pg.close();
333
+ }
110
334
  }
335
+ main().then((r) => r !== "stay" && exitNow(Number(process.exitCode ?? 0)), (err) => {
336
+ console.error(err instanceof Error ? err.message : err);
337
+ exitNow(1);
338
+ });