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.
- package/README.md +201 -19
- package/dist/app/assets/{abnfDiagram-S7VZAUFO-BVgtb0Hw.js → abnfDiagram-S7VZAUFO-CFbb_Sz2.js} +1 -1
- package/dist/app/assets/{architecture-WOLXFQ4H-DxylGHqT.js → architecture-WOLXFQ4H-CsBD__5a.js} +1 -1
- package/dist/app/assets/architectureDiagram-YGSQEFNW-C0ic4ib1.js +36 -0
- package/dist/app/assets/{blockDiagram-APKKGZFW-C7fb3MCE.js → blockDiagram-APKKGZFW-BZDPbzAG.js} +1 -1
- package/dist/app/assets/{c4Diagram-KJ2TOQU5-Bkb_0fbd.js → c4Diagram-KJ2TOQU5-BilBWuq5.js} +1 -1
- package/dist/app/assets/{chunk-6MUBBAK2-DU4vZ03M.js → chunk-6MUBBAK2-BBl-4tQr.js} +1 -1
- package/dist/app/assets/{chunk-AXFCVDMN-De96BVTB.js → chunk-AXFCVDMN-BhsttQ-k.js} +1 -1
- package/dist/app/assets/{chunk-BG4553SI-J33jsRLV.js → chunk-BG4553SI-mWcPcFZr.js} +2 -2
- package/dist/app/assets/{chunk-DQASFODM-Bh85SSGO.js → chunk-DQASFODM-7FKe2gLt.js} +1 -1
- package/dist/app/assets/{chunk-HFQBQIA3-CCklgplR.js → chunk-HFQBQIA3-nXrQ08BL.js} +1 -1
- package/dist/app/assets/{chunk-KQLB2F66-B04qR8ED.js → chunk-KQLB2F66-swukhFmZ.js} +1 -1
- package/dist/app/assets/{chunk-KS47KZWR-BsqDyyAt.js → chunk-KS47KZWR-DkDkwO82.js} +1 -1
- package/dist/app/assets/{chunk-LEVMRMFU-DwxrBz2u.js → chunk-LEVMRMFU-DXH6iXv3.js} +1 -1
- package/dist/app/assets/{chunk-M57EVK23-D9YIHjps.js → chunk-M57EVK23-B-kEyOJF.js} +1 -1
- package/dist/app/assets/{chunk-OY52VR5R-WB63DeTA.js → chunk-OY52VR5R-DweG7qYw.js} +1 -1
- package/dist/app/assets/{chunk-QB3YPZ4I-cHzzKdtb.js → chunk-QB3YPZ4I-DyozK3lV.js} +1 -1
- package/dist/app/assets/{chunk-R3KSYZAL-C7rDagaa.js → chunk-R3KSYZAL-BEXCUN6J.js} +1 -1
- package/dist/app/assets/{chunk-STOXU5M4-CG6pnJtH.js → chunk-STOXU5M4-BaTlty4O.js} +1 -1
- package/dist/app/assets/{chunk-TU62E6Q5-BbcGYfy_.js → chunk-TU62E6Q5-_rcUP1Fh.js} +1 -1
- package/dist/app/assets/chunk-X3CZISLH-NOpCnvgE.js +1 -0
- package/dist/app/assets/{chunk-X4PVCEUW-BUI1Oi3q.js → chunk-X4PVCEUW-DGxTL3kB.js} +1 -1
- package/dist/app/assets/{chunk-XXDRQBXY-DYhK5YW-.js → chunk-XXDRQBXY-C02Gpej2.js} +1 -1
- package/dist/app/assets/{classDiagram-v2-L25IHNXF-K-k5GTUn.js → classDiagram-v2-L25IHNXF-DLEBwpvk.js} +1 -1
- package/dist/app/assets/cose-bilkent-JH36ORCC-kNCXOm8k.js +1 -0
- package/dist/app/assets/cynefin-EF2NZ3EQ-6MWNLbuF.js +1 -0
- package/dist/app/assets/{cynefinDiagram-L36ESFBY-mkV33_Xx.js → cynefinDiagram-L36ESFBY-CLFstukD.js} +1 -1
- package/dist/app/assets/{d3-scale-ygdFCUH8.js → d3-scale-CaJQQYkF.js} +1 -1
- package/dist/app/assets/{dagre-SPEB5RXH-BNIymLsu.js → dagre-SPEB5RXH-BaSAny1T.js} +1 -1
- package/dist/app/assets/{diagram-3B7GL73J-CGOiolFW.js → diagram-3B7GL73J-DJNlt5Sg.js} +1 -1
- package/dist/app/assets/{diagram-DNEMPZML-DZFkHNly.js → diagram-DNEMPZML-DEHeuILB.js} +1 -1
- package/dist/app/assets/{diagram-L3MUGCDN-B42GAYLq.js → diagram-L3MUGCDN-ob5Ka2Xc.js} +1 -1
- package/dist/app/assets/{diagram-LA4NIPWU-BYuLRYId.js → diagram-LA4NIPWU-DNESzFAc.js} +1 -1
- package/dist/app/assets/{diagram-MHCOC4E2-DGzI6TJG.js → diagram-MHCOC4E2-CVi9zKjG.js} +1 -1
- package/dist/app/assets/{diagram-XPFHEONP-CTBEgDQ8.js → diagram-XPFHEONP-DInT4C7e.js} +1 -1
- package/dist/app/assets/dist-CjvHN74u.js +1 -0
- package/dist/app/assets/{ebnfDiagram-UZSYDL2S-GuMdOCvL.js → ebnfDiagram-UZSYDL2S-CRCZNsji.js} +1 -1
- package/dist/app/assets/{elk-XV6XMXQE-BpY3loT5.js → elk-XV6XMXQE-D4fsWI2l.js} +1 -1
- package/dist/app/assets/{erDiagram-EYBAPDEH-nDZ2PMGl.js → erDiagram-EYBAPDEH-YQNM5StV.js} +1 -1
- package/dist/app/assets/{eventmodeling-K75KTNOO-BN42Mgwh.js → eventmodeling-K75KTNOO-Bev08J2F.js} +1 -1
- package/dist/app/assets/flowDiagram-MALGAFMO-BhJ554DH.js +1 -0
- package/dist/app/assets/ganttDiagram-23REXITY-CkaBMYM4.js +292 -0
- package/dist/app/assets/gitGraph-VSP46ZUC-CtbZ0sIS.js +1 -0
- package/dist/app/assets/{gitGraphDiagram-STJD7YCW-CDkKLrvO.js → gitGraphDiagram-STJD7YCW-D15ZdQ-Z.js} +1 -1
- package/dist/app/assets/index-Bn6_wHEp.js +98 -0
- package/dist/app/assets/index-H-Z7MFhZ.css +1 -0
- package/dist/app/assets/info-OHQRW6UA-CfUW1XFR.js +1 -0
- package/dist/app/assets/{infoDiagram-KBXO4MBG-B92P8pjY.js → infoDiagram-KBXO4MBG-DT7LbBRQ.js} +1 -1
- package/dist/app/assets/{ishikawaDiagram-M35NCXHK-BRZsbCvK.js → ishikawaDiagram-M35NCXHK-CF51lhjB.js} +1 -1
- package/dist/app/assets/{journeyDiagram-OPLOXDXO-Bppwb1oF.js → journeyDiagram-OPLOXDXO-_36FonKk.js} +1 -1
- package/dist/app/assets/{kanban-definition-BZKZHSQY-ByD_x5cm.js → kanban-definition-BZKZHSQY-tLk_OlQ-.js} +1 -1
- package/dist/app/assets/{mermaid-parser.core-CKmnV0Md.js → mermaid-parser.core-_3Vo8x6b.js} +3 -3
- package/dist/app/assets/mermaid.core-y-x1CYxC.js +44 -0
- package/dist/app/assets/{mindmap-definition-I2QAS2VK-fRbUh23C.js → mindmap-definition-I2QAS2VK-BCI4HRX3.js} +1 -1
- package/dist/app/assets/packet-JDAUHWVQ-Cco3UoaI.js +1 -0
- package/dist/app/assets/{pegDiagram-FD4XPPHP-qIABf6H8.js → pegDiagram-FD4XPPHP-BOzSoNji.js} +1 -1
- package/dist/app/assets/pie-XZMESJXO-reOB2GXn.js +1 -0
- package/dist/app/assets/{pieDiagram-J4AKIIQI-Bb4RBdrc.js → pieDiagram-J4AKIIQI-PlHpwT_c.js} +1 -1
- package/dist/app/assets/{quadrantDiagram-XTYBLID2-B0CpcVWE.js → quadrantDiagram-XTYBLID2-CdxZ0ael.js} +1 -1
- package/dist/app/assets/radar-ABXABTNO-DfCl8uV2.js +1 -0
- package/dist/app/assets/railroad-I3PHUGI6-4s14UyW1.js +1 -0
- package/dist/app/assets/{railroad-abnf-LNEFI6M7-BUhw7Iuo.js → railroad-abnf-LNEFI6M7-C49jJE4Y.js} +1 -1
- package/dist/app/assets/{railroad-ebnf-DWYD2UWJ-nQNF56LJ.js → railroad-ebnf-DWYD2UWJ-Bx-pcPc7.js} +1 -1
- package/dist/app/assets/{railroad-peg-JR7BVNR7-CwvbVIo6.js → railroad-peg-JR7BVNR7-DjBPSCKV.js} +1 -1
- package/dist/app/assets/{railroadDiagram-MRQ6NCDL-Dwr-mPZL.js → railroadDiagram-MRQ6NCDL-wGcmIMqq.js} +1 -1
- package/dist/app/assets/{requirementDiagram-Y7LWUY3S-Ctv2DKJM.js → requirementDiagram-Y7LWUY3S-DprFI03z.js} +1 -1
- package/dist/app/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/app/assets/{sankeyDiagram-WGJFYUXA-BvKX0eIe.js → sankeyDiagram-WGJFYUXA-DygYWLTR.js} +1 -1
- package/dist/app/assets/{sequenceDiagram-5NDRBG5M-Y4YqU2Xt.js → sequenceDiagram-5NDRBG5M-BzIr2DBO.js} +1 -1
- package/dist/app/assets/{stateDiagram-v2-FJ4FJNEA-DmjIjn4u.js → stateDiagram-v2-FJ4FJNEA-MGCqKnm_.js} +1 -1
- package/dist/app/assets/{swimlanes-UMQ2AFYF-B2O5JCjs.js → swimlanes-UMQ2AFYF-CIEH82Zt.js} +1 -1
- package/dist/app/assets/swimlanesDiagram-OMPLPG4O-YWNJjl0g.js +8 -0
- package/dist/app/assets/{timeline-definition-SEUHKTQE-DJJdixAI.js → timeline-definition-SEUHKTQE-BGYSqup2.js} +1 -1
- package/dist/app/assets/treeView-D4JQ5SDB-B39o1sJo.js +1 -0
- package/dist/app/assets/treemap-SAJKECNS-BoGxrUH4.js +1 -0
- package/dist/app/assets/{usecaseDiagram-AFA6YXN4-Bp8pXgvR.js → usecaseDiagram-AFA6YXN4-dy6oVOke.js} +1 -1
- package/dist/app/assets/{vennDiagram-NNMJR3RB-DYSfZMWT.js → vennDiagram-NNMJR3RB-CUyuhcAk.js} +1 -1
- package/dist/app/assets/wardley-7MLQ67FV-sYPAvQ06.js +1 -0
- package/dist/app/assets/{wardleyDiagram-S7YFUSEH-CGJ8qg76.js → wardleyDiagram-S7YFUSEH-DYtxYUHe.js} +1 -1
- package/dist/app/assets/{xychartDiagram-GGNKY7IX-CRSvraFc.js → xychartDiagram-GGNKY7IX-ClR06AlB.js} +1 -1
- package/dist/app/index.html +3 -2
- package/dist/cli/index.js +281 -53
- package/dist/core/api.js +262 -51
- package/dist/core/approvals.js +426 -0
- package/dist/core/context.js +68 -3
- package/dist/core/diff.js +156 -0
- package/dist/core/docs.js +9 -3
- package/dist/core/doctor.js +152 -0
- package/dist/core/doctypes.js +79 -0
- package/dist/core/edit.js +25 -0
- package/dist/core/flags.js +13 -0
- package/dist/core/gaps.js +7 -2
- package/dist/core/heading.js +4 -0
- package/dist/core/history.js +36 -5
- package/dist/core/home.js +345 -0
- package/dist/core/lanes.js +134 -0
- package/dist/core/launch.js +34 -0
- package/dist/core/layout.js +362 -0
- package/dist/core/newdoc.js +66 -0
- package/dist/core/open-folder.js +30 -0
- package/dist/core/openspec.js +6 -6
- package/dist/core/paths.js +71 -4
- package/dist/core/project.js +392 -0
- package/dist/core/route.js +420 -0
- package/dist/core/scan.js +514 -0
- package/dist/core/schema.js +170 -1
- package/dist/core/scope.js +126 -0
- package/dist/core/setup.js +134 -0
- package/dist/core/skills.js +92 -14
- package/dist/core/storage/config.js +74 -0
- package/dist/core/storage/events.js +54 -0
- package/dist/core/storage/folder-watch.js +147 -0
- package/dist/core/storage/folder.js +469 -0
- package/dist/core/storage/index.js +8 -0
- package/dist/core/storage/local.js +22 -0
- package/dist/core/storage/migrate.js +48 -0
- package/dist/core/storage/postgres.js +290 -0
- package/dist/core/storage/types.js +101 -0
- package/dist/core/storage.js +483 -77
- package/dist/core/suggest.js +283 -0
- package/dist/core/tree.js +254 -0
- package/dist/core/types.js +583 -0
- package/dist/core/version.js +1 -1
- package/dist/core/versions.js +245 -0
- package/dist/core/watch.js +2 -136
- package/dist/core/xml.js +23 -5
- package/dist/demo/args.js +58 -0
- package/dist/demo/browser.js +301 -0
- package/dist/demo/platform.js +147 -0
- package/dist/demo/run.js +198 -0
- package/dist/demo/steps.js +328 -0
- package/dist/mcp/project-tools.js +193 -0
- package/dist/mcp/server.js +493 -65
- package/examples/platform/README.md +33 -0
- package/examples/platform/api/package.json +8 -0
- package/examples/platform/api/src/auth-middleware.js +16 -0
- package/examples/platform/api/src/proxy.js +7 -0
- package/examples/platform/api/src/rate-limit.js +13 -0
- package/examples/platform/api/src/server.js +40 -0
- package/examples/platform/auth/package.json +9 -0
- package/examples/platform/auth/src/server.js +24 -0
- package/examples/platform/auth/src/tokens.js +19 -0
- package/examples/platform/auth/src/users.js +16 -0
- package/examples/platform/docs/api/PRD.md +10 -0
- package/examples/platform/docs/api/SDD.md +15 -0
- package/examples/platform/docs/auth/PRD.md +10 -0
- package/examples/platform/docs/auth/SDD.md +8 -0
- package/examples/platform/docs/frontend/PRD.md +18 -0
- package/examples/platform/docs/frontend/SDD.md +13 -0
- package/examples/platform/docs/pricing/PRD.md +9 -0
- package/examples/platform/docs/pricing/SDD.md +8 -0
- package/examples/platform/docs/products/PRD.md +9 -0
- package/examples/platform/docs/products/SDD.md +8 -0
- package/examples/platform/frontend/package.json +8 -0
- package/examples/platform/frontend/src/api-client.js +21 -0
- package/examples/platform/frontend/src/main.js +21 -0
- package/examples/platform/frontend/src/pages/products.js +12 -0
- package/examples/platform/frontend/src/pages/sign-in.js +14 -0
- package/examples/platform/frontend/src/session.js +11 -0
- package/examples/platform/pricing/package.json +9 -0
- package/examples/platform/pricing/src/cache.js +19 -0
- package/examples/platform/pricing/src/product-events.js +17 -0
- package/examples/platform/pricing/src/rules.js +19 -0
- package/examples/platform/pricing/src/server.js +32 -0
- package/examples/platform/products/package.json +9 -0
- package/examples/platform/products/src/catalog.js +20 -0
- package/examples/platform/products/src/events.js +11 -0
- package/examples/platform/products/src/search.js +9 -0
- package/examples/platform/products/src/server.js +31 -0
- package/migrations/postgres/001_init.sql +55 -0
- package/migrations/postgres/002_view_versions.sql +18 -0
- package/package.json +18 -2
- package/schema/approval.schema.json +173 -0
- package/schema/gap.schema.json +3 -0
- package/schema/project.schema.json +93 -0
- package/schema/settings.schema.json +86 -0
- package/schema/toolbox.schema.json +206 -0
- package/schema/type.schema.json +121 -0
- package/schema/view.schema.json +106 -0
- package/skills/claude/build-gap/SKILL.md +7 -0
- package/skills/claude/check-ui/SKILL.md +40 -0
- package/skills/claude/draw-system/SKILL.md +24 -9
- package/skills/claude/gap-from-view/SKILL.md +7 -0
- package/skills/claude/post-audit/SKILL.md +58 -0
- package/skills/claude/pre-audit/SKILL.md +82 -0
- package/skills/claude/update-state/SKILL.md +56 -0
- package/skills/cursor/check-ui.mdc +40 -0
- package/skills/cursor/draw-system.mdc +24 -9
- package/skills/cursor/post-audit.mdc +44 -0
- package/skills/cursor/pre-audit.mdc +49 -0
- package/skills/cursor/update-state.mdc +45 -0
- package/skills/windsurf/spatial-views.md +182 -36
- package/toolboxes/aws.yaml +43 -0
- package/toolboxes/azure.yaml +41 -0
- package/toolboxes/cloud.yaml +95 -0
- package/toolboxes/docs.yaml +111 -0
- package/toolboxes/software.yaml +114 -0
- package/toolboxes/types/docs/gap.yaml +15 -0
- package/toolboxes/types/docs/mdd.yaml +19 -0
- package/toolboxes/types/docs/plain.yaml +7 -0
- package/toolboxes/types/docs/prd.yaml +17 -0
- package/dist/app/assets/architectureDiagram-YGSQEFNW-BrBCHqUH.js +0 -36
- package/dist/app/assets/chunk-X3CZISLH-FMl4PpWt.js +0 -1
- package/dist/app/assets/cose-bilkent-JH36ORCC-BJmLLpaN.js +0 -1
- package/dist/app/assets/cynefin-EF2NZ3EQ-DrzwMKdm.js +0 -1
- package/dist/app/assets/dist-1Q8ng3tu.js +0 -1
- package/dist/app/assets/flowDiagram-MALGAFMO-BCwwiLzb.js +0 -1
- package/dist/app/assets/ganttDiagram-23REXITY-xMRHaU3y.js +0 -292
- package/dist/app/assets/gitGraph-VSP46ZUC-DyGq5mdd.js +0 -1
- package/dist/app/assets/index-BY66fc8Q.js +0 -95
- package/dist/app/assets/index-ByetEVbs.css +0 -1
- package/dist/app/assets/info-OHQRW6UA-DOBf-fQH.js +0 -1
- package/dist/app/assets/mermaid.core-BoRvk1Q-.js +0 -44
- package/dist/app/assets/packet-JDAUHWVQ-CgHq03Zj.js +0 -1
- package/dist/app/assets/pie-XZMESJXO-DtNh3cDE.js +0 -1
- package/dist/app/assets/radar-ABXABTNO-BS0FcsIX.js +0 -1
- package/dist/app/assets/railroad-I3PHUGI6-lO8vfGdI.js +0 -1
- package/dist/app/assets/swimlanesDiagram-OMPLPG4O-DhCl-Cjg.js +0 -8
- package/dist/app/assets/treeView-D4JQ5SDB-Dd1no4eE.js +0 -1
- package/dist/app/assets/treemap-SAJKECNS-t6wtsaki.js +0 -1
- package/dist/app/assets/wardley-7MLQ67FV-Bx60QTuu.js +0 -1
- package/skills/cursor/build-gap.mdc +0 -21
- package/skills/cursor/gap-from-view.mdc +0 -22
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { afterAiChange, typeLayout } from "./layout.js";
|
|
2
|
+
import { APP } from "./versions.js";
|
|
3
|
+
import { loadTypes } from "./types.js";
|
|
4
|
+
import { cp, mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { basename, join, resolve } from "node:path";
|
|
7
|
+
import { UserError } from "./errors.js";
|
|
8
|
+
import { TOOLBOX_SCHEMA_URL } from "./types.js";
|
|
9
|
+
import { addModule, removeModule } from "./edit.js";
|
|
10
|
+
import { landingView } from "./context.js";
|
|
11
|
+
import { ProjectStore } from "./project.js";
|
|
12
|
+
import { describeRoots, NoProjectError } from "./scope.js";
|
|
13
|
+
import { NotFoundError, Spatial } from "./storage.js";
|
|
14
|
+
import { FolderStore } from "./storage/folder.js";
|
|
15
|
+
/**
|
|
16
|
+
* The home folder (PRD §9.1): one global install, many projects.
|
|
17
|
+
*
|
|
18
|
+
* ~/SpatialViews/ (SPATIAL_VIEWS_HOME overrides it)
|
|
19
|
+
* projects.json {projects: [{slug, name, created}]}
|
|
20
|
+
* projects/<slug>/
|
|
21
|
+
* project.json views/ gaps/ pins.json reports/
|
|
22
|
+
* toolboxes/ the user's toolboxes (*.yaml), with a README
|
|
23
|
+
*
|
|
24
|
+
* The folder is visible on purpose (C:\Users\<you>\SpatialViews on Windows,
|
|
25
|
+
* /Users/<you>/SpatialViews on a Mac, ~/SpatialViews on Linux and WSL). An old
|
|
26
|
+
* hidden ~/.spatial-views is moved here on first run (migrateHome).
|
|
27
|
+
*
|
|
28
|
+
* It starts with no projects. Sources (repos, docs, diagrams) stay where they
|
|
29
|
+
* are and are only ever read; everything the project makes lives here, or in
|
|
30
|
+
* Postgres (Settings → Storage): the same objects, one row each.
|
|
31
|
+
*/
|
|
32
|
+
export const SYSTEM_OVERVIEW = { id: "system-overview", name: "System Overview" };
|
|
33
|
+
export const HOME_NAME = "SpatialViews";
|
|
34
|
+
/** The hidden home folder of earlier builds; migrateHome moves it to ~/SpatialViews. */
|
|
35
|
+
export const LEGACY_HOME_NAME = ".spatial-views";
|
|
36
|
+
export function homeDir(env = process.env, home = homedir()) {
|
|
37
|
+
return resolve(env.SPATIAL_VIEWS_HOME?.trim() || join(home, HOME_NAME));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Move an old ~/.spatial-views to ~/SpatialViews, once. Nothing happens when
|
|
41
|
+
* SPATIAL_VIEWS_HOME is set, when there is no old folder, or when the new one
|
|
42
|
+
* is already there (then the old one is left alone and reported).
|
|
43
|
+
*/
|
|
44
|
+
export async function migrateHome(env = process.env, home = homedir()) {
|
|
45
|
+
const from = join(home, LEGACY_HOME_NAME);
|
|
46
|
+
const to = join(home, HOME_NAME);
|
|
47
|
+
if (env.SPATIAL_VIEWS_HOME?.trim())
|
|
48
|
+
return { moved: false, reason: "override", from, to: homeDir(env, home) };
|
|
49
|
+
if (!(await stat(from).catch(() => null))?.isDirectory())
|
|
50
|
+
return { moved: false, reason: "no-legacy", from, to };
|
|
51
|
+
if (await stat(to).catch(() => null))
|
|
52
|
+
return { moved: false, reason: "both-exist", from, to };
|
|
53
|
+
try {
|
|
54
|
+
await rename(from, to);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
// Another drive or a locked folder: copy, then remove the old one.
|
|
58
|
+
if (!["EXDEV", "EPERM", "EACCES", "EBUSY"].includes(e.code ?? ""))
|
|
59
|
+
throw e;
|
|
60
|
+
await cp(from, to, { recursive: true, errorOnExist: true, force: false });
|
|
61
|
+
await rm(from, { recursive: true, force: true }).catch(() => undefined);
|
|
62
|
+
}
|
|
63
|
+
return { moved: true, from, to };
|
|
64
|
+
}
|
|
65
|
+
export const TOOLBOX_README = `# Your toolboxes
|
|
66
|
+
|
|
67
|
+
Each \`*.yaml\` file in this folder is a toolbox: one icon on the canvas's
|
|
68
|
+
right-hand bar, holding module types and doc types. Save a file and the bar
|
|
69
|
+
updates live, with no restart. A mistake shows as a message naming the file and
|
|
70
|
+
line; the rest still loads.
|
|
71
|
+
|
|
72
|
+
- Start from \`my-toolbox.yaml\` here, or run \`npx spatial-views toolbox new <name> --user\`.
|
|
73
|
+
- Check a file: \`npx spatial-views toolbox check <file>.yaml\`.
|
|
74
|
+
- Icons: \`lucide:<name>\` (https://lucide.dev/icons), or \`./icons/<file>.svg\` in this folder.
|
|
75
|
+
- Same toolbox id as a built-in one (software, cloud, aws, azure, docs) extends it,
|
|
76
|
+
field by field; a type with the same id changes that type.
|
|
77
|
+
- Turn a toolbox off per project in Settings.
|
|
78
|
+
|
|
79
|
+
Load order (a later file wins): built-in, then this folder, then the project's
|
|
80
|
+
\`toolboxes/\` folder (\`.spatial/toolboxes/\` in a repo).
|
|
81
|
+
|
|
82
|
+
This folder lives in your Spatial Views home: \`~/SpatialViews\`
|
|
83
|
+
(\`C:\\Users\\<you>\\SpatialViews\` on Windows). Set \`SPATIAL_VIEWS_HOME\` to move
|
|
84
|
+
it. An old \`~/.spatial-views\` is moved here on first run.
|
|
85
|
+
`;
|
|
86
|
+
export const EXAMPLE_TOOLBOX = `# yaml-language-server: $schema=${TOOLBOX_SCHEMA_URL}
|
|
87
|
+
# An example toolbox: change it, copy it, or delete it.
|
|
88
|
+
name: My toolbox
|
|
89
|
+
icon: lucide:briefcase
|
|
90
|
+
description: My own module types.
|
|
91
|
+
order: 200
|
|
92
|
+
types:
|
|
93
|
+
- id: my-toolbox-service
|
|
94
|
+
name: My service
|
|
95
|
+
description: A service of mine.
|
|
96
|
+
icon: lucide:box
|
|
97
|
+
color: teal
|
|
98
|
+
properties:
|
|
99
|
+
- { name: owner, type: string }
|
|
100
|
+
`;
|
|
101
|
+
/**
|
|
102
|
+
* First run: the home folder and its toolboxes folder, with a README and one
|
|
103
|
+
* example toolbox. The example is written only when the folder is new, so a
|
|
104
|
+
* person who deletes it does not get it back. Returns what it wrote.
|
|
105
|
+
*/
|
|
106
|
+
export async function ensureHome(dir = homeDir()) {
|
|
107
|
+
const tb = join(dir, "toolboxes");
|
|
108
|
+
const fresh = !(await stat(tb).catch(() => null));
|
|
109
|
+
await mkdir(tb, { recursive: true });
|
|
110
|
+
const wrote = [];
|
|
111
|
+
const put = async (file, text) => {
|
|
112
|
+
try {
|
|
113
|
+
await writeFile(file, text, { encoding: "utf8", flag: "wx" });
|
|
114
|
+
wrote.push(file);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
if (e.code !== "EEXIST")
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
await put(join(tb, "README.md"), TOOLBOX_README);
|
|
122
|
+
if (fresh)
|
|
123
|
+
await put(join(tb, "my-toolbox.yaml"), EXAMPLE_TOOLBOX);
|
|
124
|
+
return wrote;
|
|
125
|
+
}
|
|
126
|
+
/** Migrate the old home, then make sure the folder and its toolboxes are there. Never throws. */
|
|
127
|
+
export async function prepareHome(env = process.env, log = console.error) {
|
|
128
|
+
try {
|
|
129
|
+
const m = await migrateHome(env);
|
|
130
|
+
if (m.moved)
|
|
131
|
+
log(`Spatial Views: moved ${m.from} to ${m.to}`);
|
|
132
|
+
else if (m.reason === "both-exist")
|
|
133
|
+
log(`Spatial Views: using ${m.to}; ${m.from} is still there (move what you need, then delete it)`);
|
|
134
|
+
await ensureHome(homeDir(env));
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
log(`Spatial Views: could not set up ${homeDir(env)}: ${e.message}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function projectSlug(name) {
|
|
141
|
+
return (name
|
|
142
|
+
.toLowerCase()
|
|
143
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
144
|
+
.replace(/^-+|-+$/g, "")
|
|
145
|
+
.slice(0, 60) || "project");
|
|
146
|
+
}
|
|
147
|
+
/** The active project: its data, its project.json, and the folders it may read. */
|
|
148
|
+
export class Workspace {
|
|
149
|
+
kind;
|
|
150
|
+
slug;
|
|
151
|
+
spatial;
|
|
152
|
+
project;
|
|
153
|
+
constructor(kind, slug, spatial) {
|
|
154
|
+
this.kind = kind;
|
|
155
|
+
this.slug = slug;
|
|
156
|
+
this.spatial = spatial;
|
|
157
|
+
this.project = ProjectStore.of(spatial);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A project in the home folder. `dir` is `<home>/projects/<slug>`: the folder
|
|
161
|
+
* store keeps it there; with another store it only names the project's paths
|
|
162
|
+
* (its local hand-off, `.local/`, is always on this machine).
|
|
163
|
+
*/
|
|
164
|
+
static home(dir, slug, storage) {
|
|
165
|
+
const ref = { storage: storage ?? FolderStore.single({ dataDir: dir, slug }), project: slug };
|
|
166
|
+
return new Workspace("home", slug, new Spatial(dir, { dataDir: dir, localDir: join(dir, ".local"), mode: "home", ref }));
|
|
167
|
+
}
|
|
168
|
+
/** A single-repo project: a repo with `.spatial/` (0.1.0, `init`). */
|
|
169
|
+
static repo(root) {
|
|
170
|
+
return new Workspace("repo", projectSlug(basename(resolve(root))), new Spatial(resolve(root)));
|
|
171
|
+
}
|
|
172
|
+
async info() {
|
|
173
|
+
const p = await this.project.get();
|
|
174
|
+
return { ...p, slug: this.slug, kind: this.kind, dir: this.spatial.dataDir };
|
|
175
|
+
}
|
|
176
|
+
/** The folders this project may read: its sources, plus the repo itself for a single-repo project. */
|
|
177
|
+
async roots() {
|
|
178
|
+
const sources = await this.project.roots();
|
|
179
|
+
return this.kind === "repo" ? [{ id: "repo", abs: this.spatial.root }, ...sources] : sources;
|
|
180
|
+
}
|
|
181
|
+
async allowed() {
|
|
182
|
+
return describeRoots(await this.roots());
|
|
183
|
+
}
|
|
184
|
+
/** The View the project always opens on: root_view_id, else the System Overview, else the top View. */
|
|
185
|
+
async landing() {
|
|
186
|
+
const p = await this.project.get().catch(() => null);
|
|
187
|
+
return landingView(await this.spatial.views.listViews(), p?.root_view_id);
|
|
188
|
+
}
|
|
189
|
+
/** The View sources go on: System Overview, else the first high-level View, else a new System Overview. */
|
|
190
|
+
async overview(create = true) {
|
|
191
|
+
const views = await this.spatial.views.listViews();
|
|
192
|
+
const hit = views.find((v) => v.id === SYSTEM_OVERVIEW.id) ?? views.find((v) => v.type === "high-level");
|
|
193
|
+
if (hit || !create)
|
|
194
|
+
return hit ?? null;
|
|
195
|
+
// Drawn by the AI as sources are added: laid out until a person moves something.
|
|
196
|
+
// Saved by the app, not a person: nobody has approved it yet, so the AI draws on it directly.
|
|
197
|
+
return this.spatial.views.save({ ...SYSTEM_OVERVIEW, type: "high-level", auto_layout: true, modules: [], connections: [] }, { by: APP });
|
|
198
|
+
}
|
|
199
|
+
/** Add a source; a repo also gets a module on the System Overview. */
|
|
200
|
+
async addSource(input) {
|
|
201
|
+
const r = await this.project.addSource(input);
|
|
202
|
+
let module;
|
|
203
|
+
if (r.source.kind === "repo") {
|
|
204
|
+
const v = (await this.overview());
|
|
205
|
+
if (!v.modules.some((m) => m.id === r.source.id)) {
|
|
206
|
+
const next = addModule(v, { id: r.source.id, name: r.source.name ?? r.source.id, description: `repo: ${r.source.path}` }).view;
|
|
207
|
+
await this.spatial.views.save(await afterAiChange(next, "auto", new Set([r.source.id]), typeLayout(next, await loadTypes(this.spatial.dataDir))));
|
|
208
|
+
}
|
|
209
|
+
module = `${v.id}/${r.source.id}`;
|
|
210
|
+
}
|
|
211
|
+
return { ...r, ...(module ? { module } : {}) };
|
|
212
|
+
}
|
|
213
|
+
/** Take a source off the project, and its module off the System Overview. The folder is not touched. */
|
|
214
|
+
async removeSource(ref) {
|
|
215
|
+
const source = await this.project.removeSource(ref);
|
|
216
|
+
const v = await this.overview(false);
|
|
217
|
+
const had = v?.modules.some((m) => m.id === source.id) ?? false;
|
|
218
|
+
if (v && had)
|
|
219
|
+
await this.spatial.views.save(removeModule(v, source.id));
|
|
220
|
+
return { removed: source, ...(had ? { module_removed: `${v.id}/${source.id}` } : {}) };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** The projects (projects.json and projects/<slug>/ in the folder store). */
|
|
224
|
+
export class Home {
|
|
225
|
+
dir;
|
|
226
|
+
file;
|
|
227
|
+
storage;
|
|
228
|
+
constructor(dir = homeDir(), storage) {
|
|
229
|
+
this.dir = dir;
|
|
230
|
+
this.file = join(dir, "projects.json");
|
|
231
|
+
this.storage = storage ?? new FolderStore({ home: dir });
|
|
232
|
+
}
|
|
233
|
+
projectDir(slug) {
|
|
234
|
+
return join(this.dir, "projects", slug);
|
|
235
|
+
}
|
|
236
|
+
async list() {
|
|
237
|
+
const all = await this.storage.list("project", "");
|
|
238
|
+
return all
|
|
239
|
+
.map((p) => ({ slug: p.id, name: p.data?.name ?? p.id, created: p.data?.created ?? "" }))
|
|
240
|
+
.sort((a, b) => (a.created < b.created ? -1 : a.created > b.created ? 1 : a.slug < b.slug ? -1 : 1));
|
|
241
|
+
}
|
|
242
|
+
async find(ref) {
|
|
243
|
+
const all = await this.list();
|
|
244
|
+
const r = ref.trim().toLowerCase();
|
|
245
|
+
const hit = all.find((p) => p.slug === r) ?? all.find((p) => p.name.toLowerCase() === r) ?? all.find((p) => p.slug === projectSlug(r));
|
|
246
|
+
if (!hit)
|
|
247
|
+
throw new NotFoundError(`no project ${ref} (have: ${all.map((p) => p.slug).join(", ") || "none; create_project"})`);
|
|
248
|
+
return hit;
|
|
249
|
+
}
|
|
250
|
+
open(entry) {
|
|
251
|
+
return Workspace.home(this.projectDir(entry.slug), entry.slug, this.storage);
|
|
252
|
+
}
|
|
253
|
+
/** A new project: its folder, project.json, and an empty System Overview View. */
|
|
254
|
+
async create(name, now = new Date()) {
|
|
255
|
+
const clean = name.trim();
|
|
256
|
+
if (!clean)
|
|
257
|
+
throw new UserError("a project needs a name");
|
|
258
|
+
const all = await this.list();
|
|
259
|
+
const slug = projectSlug(clean);
|
|
260
|
+
if (all.some((p) => p.slug === slug))
|
|
261
|
+
throw new UserError(`a project ${slug} already exists (use_project ${slug})`);
|
|
262
|
+
const dir = this.projectDir(slug);
|
|
263
|
+
const ws = Workspace.home(dir, slug, this.storage);
|
|
264
|
+
if (await ws.project.exists())
|
|
265
|
+
throw new UserError(`${dir} already holds a project`);
|
|
266
|
+
await ws.spatial.pins.write({ sources: [], pins: [] });
|
|
267
|
+
await ws.overview();
|
|
268
|
+
// The project itself last: once it is there it is listed, with its System Overview.
|
|
269
|
+
await ws.project.create(clean, now, slug, SYSTEM_OVERVIEW.id);
|
|
270
|
+
return ws;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Which project is active. Everything that reads or writes project data goes
|
|
275
|
+
* through `current`, which refuses until a project is picked.
|
|
276
|
+
*/
|
|
277
|
+
export class Session {
|
|
278
|
+
home;
|
|
279
|
+
repo;
|
|
280
|
+
active;
|
|
281
|
+
listeners = new Set();
|
|
282
|
+
constructor(opts = {}) {
|
|
283
|
+
this.home = new Home(opts.home ?? homeDir(), opts.storage);
|
|
284
|
+
const given = opts.workspace ?? null;
|
|
285
|
+
this.repo = given?.kind === "repo" ? given : opts.repo ? Workspace.repo(opts.repo) : null;
|
|
286
|
+
this.active = given ?? this.repo;
|
|
287
|
+
}
|
|
288
|
+
/** A session over one project's data that someone already opened (tests, and createApiHandler(spatial)). */
|
|
289
|
+
static fixed(spatial, home) {
|
|
290
|
+
const ws = spatial.mode === "home"
|
|
291
|
+
? new Workspace("home", basename(spatial.root), spatial)
|
|
292
|
+
: new Workspace("repo", projectSlug(basename(resolve(spatial.root))), spatial);
|
|
293
|
+
return new Session({ ...(home ? { home } : {}), workspace: ws });
|
|
294
|
+
}
|
|
295
|
+
get hasProject() {
|
|
296
|
+
return this.active !== null;
|
|
297
|
+
}
|
|
298
|
+
/** The active project, or the "pick a project" refusal. */
|
|
299
|
+
get current() {
|
|
300
|
+
if (!this.active)
|
|
301
|
+
throw new NoProjectError();
|
|
302
|
+
return this.active;
|
|
303
|
+
}
|
|
304
|
+
get spatial() {
|
|
305
|
+
return this.current.spatial;
|
|
306
|
+
}
|
|
307
|
+
onChange(fn) {
|
|
308
|
+
this.listeners.add(fn);
|
|
309
|
+
return () => this.listeners.delete(fn);
|
|
310
|
+
}
|
|
311
|
+
set(ws) {
|
|
312
|
+
const changed = this.active !== ws;
|
|
313
|
+
this.active = ws;
|
|
314
|
+
if (changed)
|
|
315
|
+
for (const fn of this.listeners)
|
|
316
|
+
fn(ws);
|
|
317
|
+
return ws;
|
|
318
|
+
}
|
|
319
|
+
async list() {
|
|
320
|
+
const out = [];
|
|
321
|
+
if (this.repo) {
|
|
322
|
+
const p = await this.repo.project.get();
|
|
323
|
+
out.push({ slug: this.repo.slug, name: p.name, kind: "repo", active: this.active === this.repo, dir: this.repo.spatial.root });
|
|
324
|
+
}
|
|
325
|
+
for (const e of await this.home.list())
|
|
326
|
+
out.push({ ...e, kind: "home", active: this.active?.kind === "home" && this.active.slug === e.slug });
|
|
327
|
+
return out;
|
|
328
|
+
}
|
|
329
|
+
async use(ref) {
|
|
330
|
+
if (this.repo) {
|
|
331
|
+
const r = ref.trim().toLowerCase();
|
|
332
|
+
const name = (await this.repo.project.get()).name.toLowerCase();
|
|
333
|
+
if (r === this.repo.slug || r === name)
|
|
334
|
+
return this.set(this.repo);
|
|
335
|
+
}
|
|
336
|
+
const entry = await this.home.find(ref);
|
|
337
|
+
if (this.active?.kind === "home" && this.active.slug === entry.slug)
|
|
338
|
+
return this.active;
|
|
339
|
+
return this.set(this.home.open(entry));
|
|
340
|
+
}
|
|
341
|
+
/** Create a project in the home folder and make it the active one. */
|
|
342
|
+
async create(name) {
|
|
343
|
+
return this.set(await this.home.create(name));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { findModule } from "./edit.js";
|
|
2
|
+
import { UserError } from "./errors.js";
|
|
3
|
+
import { slugId } from "./links.js";
|
|
4
|
+
/**
|
|
5
|
+
* Swim lanes and sequence Views (PRD §9.3): pure functions shared by the MCP
|
|
6
|
+
* tools and the canvas. Every change returns a new View.
|
|
7
|
+
*/
|
|
8
|
+
/** Each lane is a fixed-height horizontal band, top to bottom in `lanes` order. */
|
|
9
|
+
export const LANE_HEIGHT = 200;
|
|
10
|
+
/** Where a module dropped into a lane sits, from the band's top. */
|
|
11
|
+
export const LANE_INSET = 70;
|
|
12
|
+
export function laneBands(view) {
|
|
13
|
+
return (view.lanes ?? []).map((lane, i) => ({ lane, y: i * LANE_HEIGHT, height: LANE_HEIGHT }));
|
|
14
|
+
}
|
|
15
|
+
/** The lane whose band holds y, if any. */
|
|
16
|
+
export function laneAt(view, y) {
|
|
17
|
+
return laneBands(view).find((b) => y >= b.y && y < b.y + b.height)?.lane;
|
|
18
|
+
}
|
|
19
|
+
/** A lane on this View by id or label (case-insensitive). */
|
|
20
|
+
export function findLane(view, ref) {
|
|
21
|
+
const lanes = view.lanes ?? [];
|
|
22
|
+
const hit = lanes.find((l) => l.id === ref) ?? lanes.find((l) => l.label.toLowerCase() === ref.toLowerCase());
|
|
23
|
+
if (!hit)
|
|
24
|
+
throw new UserError(`no lane "${ref}" on View ${view.id} (lanes: ${lanes.map((l) => l.label).join(", ") || "none"})`);
|
|
25
|
+
return hit;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set a View's lanes (top to bottom). Lanes may be given as labels or
|
|
29
|
+
* {id, label}. A module whose lane is gone loses its lane; an empty list
|
|
30
|
+
* removes lanes from the View.
|
|
31
|
+
*/
|
|
32
|
+
export function setLanes(view, input) {
|
|
33
|
+
const lanes = [];
|
|
34
|
+
for (const l of input) {
|
|
35
|
+
const label = (typeof l === "string" ? l : l.label).trim();
|
|
36
|
+
if (!label)
|
|
37
|
+
throw new UserError("a lane needs a label");
|
|
38
|
+
const id = (typeof l === "string" ? undefined : l.id) ?? slugId(label, lanes.map((x) => x.id));
|
|
39
|
+
if (lanes.some((x) => x.id === id))
|
|
40
|
+
throw new UserError(`lane id ${id} is used twice`);
|
|
41
|
+
lanes.push({ id, label });
|
|
42
|
+
}
|
|
43
|
+
const ids = new Set(lanes.map((l) => l.id));
|
|
44
|
+
const modules = view.modules.map((m) => {
|
|
45
|
+
if (!m.lane || ids.has(m.lane))
|
|
46
|
+
return m;
|
|
47
|
+
const { lane: _gone, ...rest } = m;
|
|
48
|
+
return rest;
|
|
49
|
+
});
|
|
50
|
+
const next = { ...view, modules };
|
|
51
|
+
if (lanes.length)
|
|
52
|
+
next.lanes = lanes;
|
|
53
|
+
else
|
|
54
|
+
delete next.lanes;
|
|
55
|
+
return next;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Put a module in a lane (or take it out with `null`). On a flow View the
|
|
59
|
+
* module moves into the lane's band if it is outside it, so the picture matches.
|
|
60
|
+
*/
|
|
61
|
+
export function assignLane(view, moduleRef, laneRef) {
|
|
62
|
+
const m = findModule(view, moduleRef);
|
|
63
|
+
const lane = laneRef === null ? null : findLane(view, laneRef);
|
|
64
|
+
const band = lane ? laneBands(view).find((b) => b.lane.id === lane.id) : undefined;
|
|
65
|
+
return {
|
|
66
|
+
...view,
|
|
67
|
+
modules: view.modules.map((x) => {
|
|
68
|
+
if (x.id !== m.id)
|
|
69
|
+
return x;
|
|
70
|
+
if (!lane) {
|
|
71
|
+
const { lane: _gone, ...rest } = x;
|
|
72
|
+
return rest;
|
|
73
|
+
}
|
|
74
|
+
const inside = band && x.y >= band.y && x.y < band.y + band.height - 40;
|
|
75
|
+
return { ...x, lane: lane.id, ...(band && !inside && view.kind !== "sequence" ? { y: band.y + LANE_INSET } : {}) };
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** A connection between modules in two different lanes: a dependency of one lane on another. */
|
|
80
|
+
export function isCrossLane(view, c) {
|
|
81
|
+
const lane = (id) => view.modules.find((m) => m.id === id)?.lane;
|
|
82
|
+
const a = lane(c.from);
|
|
83
|
+
const b = lane(c.to);
|
|
84
|
+
return !!a && !!b && a !== b;
|
|
85
|
+
}
|
|
86
|
+
// ---- Sequence Views ---------------------------------------------------------
|
|
87
|
+
export function isSequence(view) {
|
|
88
|
+
return view.kind === "sequence";
|
|
89
|
+
}
|
|
90
|
+
/** Add a message to a sequence View, at the end or at a 1-based position. */
|
|
91
|
+
export function addMessage(view, input) {
|
|
92
|
+
if (!isSequence(view))
|
|
93
|
+
throw new UserError(`View ${view.id} is not a sequence View (create it with kind: sequence)`);
|
|
94
|
+
const from = findModule(view, input.from);
|
|
95
|
+
const to = findModule(view, input.to);
|
|
96
|
+
const list = view.messages ?? [];
|
|
97
|
+
const ids = new Set(list.map((x) => x.id));
|
|
98
|
+
let n = list.length + 1;
|
|
99
|
+
while (ids.has(`m${n}`))
|
|
100
|
+
n++;
|
|
101
|
+
const message = { id: `m${n}`, from: from.id, to: to.id, text: input.text.trim(), ...(input.kind ? { kind: input.kind } : {}) };
|
|
102
|
+
const at = input.at === undefined ? list.length : Math.min(Math.max(1, Math.round(input.at)), list.length + 1) - 1;
|
|
103
|
+
return { view: { ...view, messages: [...list.slice(0, at), message, ...list.slice(at)] }, message };
|
|
104
|
+
}
|
|
105
|
+
export function removeMessage(view, id) {
|
|
106
|
+
if (!(view.messages ?? []).some((m) => m.id === id))
|
|
107
|
+
throw new UserError(`no message ${id} on View ${view.id}`);
|
|
108
|
+
return { ...view, messages: view.messages.filter((m) => m.id !== id) };
|
|
109
|
+
}
|
|
110
|
+
/** Removing a participant takes its messages too. */
|
|
111
|
+
export function dropMessagesOf(view, moduleId) {
|
|
112
|
+
if (!view.messages)
|
|
113
|
+
return view;
|
|
114
|
+
return { ...view, messages: view.messages.filter((m) => m.from !== moduleId && m.to !== moduleId) };
|
|
115
|
+
}
|
|
116
|
+
/** Where things go on the canvas for a sequence View. */
|
|
117
|
+
export const SEQ = { colWidth: 220, headY: 0, firstRow: 110, rowHeight: 56 };
|
|
118
|
+
export function sequenceLayout(view) {
|
|
119
|
+
const xs = new Map(view.modules.map((m, i) => [m.id, i * SEQ.colWidth]));
|
|
120
|
+
const rows = (view.messages ?? [])
|
|
121
|
+
.filter((m) => xs.has(m.from) && xs.has(m.to))
|
|
122
|
+
.map((message, index) => ({
|
|
123
|
+
message,
|
|
124
|
+
index,
|
|
125
|
+
y: SEQ.firstRow + index * SEQ.rowHeight,
|
|
126
|
+
fromX: xs.get(message.from),
|
|
127
|
+
toX: xs.get(message.to),
|
|
128
|
+
}));
|
|
129
|
+
return {
|
|
130
|
+
participants: view.modules.map((m) => ({ id: m.id, x: xs.get(m.id) })),
|
|
131
|
+
rows,
|
|
132
|
+
height: SEQ.firstRow + Math.max(1, rows.length) * SEQ.rowHeight,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { posix } from "node:path";
|
|
3
|
+
/** Run through npx: the CLI is in npx's cache, which is not a place to point an IDE at. */
|
|
4
|
+
export const viaNpx = (cli) => /[\\/]_npx[\\/]/.test(cli);
|
|
5
|
+
export function resolveLaunch(i) {
|
|
6
|
+
const npx = viaNpx(i.cli);
|
|
7
|
+
if (i.platform === "win32")
|
|
8
|
+
return { argv: npx ? ["cmd", "/c", "npx", "-y", "spatial-views"] : [i.execPath, i.cli] };
|
|
9
|
+
if (!npx)
|
|
10
|
+
return { argv: [i.execPath, i.cli] };
|
|
11
|
+
const exists = i.exists ?? existsSync;
|
|
12
|
+
const bin = posix.dirname(i.execPath);
|
|
13
|
+
const path = [bin, ...(i.platform === "darwin" ? ["/opt/homebrew/bin"] : []), "/usr/local/bin", "/usr/bin", "/bin"];
|
|
14
|
+
const env = { PATH: [...new Set(path)].join(":") };
|
|
15
|
+
const npxCli = posix.join(bin, "..", "lib", "node_modules", "npm", "bin", "npx-cli.js");
|
|
16
|
+
if (exists(npxCli))
|
|
17
|
+
return { argv: [i.execPath, npxCli, "-y", "spatial-views"], env };
|
|
18
|
+
if (exists(posix.join(bin, "npx")))
|
|
19
|
+
return { argv: [posix.join(bin, "npx"), "-y", "spatial-views"], env };
|
|
20
|
+
// No npm next to node: point at this copy (it may go when npx's cache is cleared).
|
|
21
|
+
return { argv: [i.execPath, i.cli] };
|
|
22
|
+
}
|
|
23
|
+
/** The command line of an entry, for messages. */
|
|
24
|
+
export function commandLine(command, args) {
|
|
25
|
+
return [command, ...args].map((a) => (/[\s"]/.test(a) ? JSON.stringify(a) : a)).join(" ");
|
|
26
|
+
}
|
|
27
|
+
/** Why the canvas could not listen, and what to do about it. */
|
|
28
|
+
export function portError(port, err) {
|
|
29
|
+
if (err.code === "EADDRINUSE")
|
|
30
|
+
return `port ${port} is in use: Spatial Views (or something else) is already running there. Open http://127.0.0.1:${port}, or start on another port: spatial-views --port ${port + 1}`;
|
|
31
|
+
if (err.code === "EACCES")
|
|
32
|
+
return `port ${port} is not allowed here: start on another port: spatial-views --port ${port >= 1024 ? port + 1 : 4317}`;
|
|
33
|
+
return `Spatial Views could not start on port ${port}: ${err.message}`;
|
|
34
|
+
}
|