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,74 @@
|
|
|
1
|
+
import { chmod } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { UserError } from "../errors.js";
|
|
5
|
+
import { FolderStore, readText, writeJson } from "./folder.js";
|
|
6
|
+
import { describeUrl, PostgresStore } from "./postgres.js";
|
|
7
|
+
/**
|
|
8
|
+
* Which backend holds the projects (Settings → Storage):
|
|
9
|
+
* <home>/config.json {"storage": {"kind": "folder" | "postgres", "url": "postgres://..."}}
|
|
10
|
+
* or, over it, the environment:
|
|
11
|
+
* SPATIAL_VIEWS_STORAGE=folder|postgres SPATIAL_VIEWS_DATABASE_URL=postgres://...
|
|
12
|
+
*
|
|
13
|
+
* config.json is written owner-only (it may hold a password). The URL is never
|
|
14
|
+
* logged, sent to the canvas, or put in a message: describeUrl gives host/db.
|
|
15
|
+
*/
|
|
16
|
+
export const StorageKindSchema = z.enum(["folder", "postgres"]);
|
|
17
|
+
const ConfigSchema = z.object({
|
|
18
|
+
storage: z.object({ kind: StorageKindSchema.default("folder"), url: z.string().optional() }).default({ kind: "folder" }),
|
|
19
|
+
});
|
|
20
|
+
export const configFile = (home) => join(home, "config.json");
|
|
21
|
+
async function readConfig(home) {
|
|
22
|
+
const raw = await readText(configFile(home));
|
|
23
|
+
if (!raw)
|
|
24
|
+
return ConfigSchema.parse({});
|
|
25
|
+
try {
|
|
26
|
+
return ConfigSchema.parse(JSON.parse(raw));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return ConfigSchema.parse({});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function readStorageConfig(home, env = process.env) {
|
|
33
|
+
const file = (await readConfig(home)).storage;
|
|
34
|
+
const envKind = env.SPATIAL_VIEWS_STORAGE?.trim().toLowerCase();
|
|
35
|
+
const envUrl = env.SPATIAL_VIEWS_DATABASE_URL?.trim();
|
|
36
|
+
if (envKind) {
|
|
37
|
+
const kind = StorageKindSchema.safeParse(envKind);
|
|
38
|
+
if (!kind.success)
|
|
39
|
+
throw new UserError(`SPATIAL_VIEWS_STORAGE is folder or postgres`);
|
|
40
|
+
const url = envUrl || (kind.data === "postgres" ? file.url : undefined);
|
|
41
|
+
return { kind: kind.data, ...(url ? { url } : {}), from: "env" };
|
|
42
|
+
}
|
|
43
|
+
if (envUrl && file.kind === "postgres")
|
|
44
|
+
return { kind: "postgres", url: envUrl, from: "env" };
|
|
45
|
+
const from = (await readText(configFile(home))) ? "config" : "default";
|
|
46
|
+
return { kind: file.kind, ...(file.url ? { url: file.url } : {}), from };
|
|
47
|
+
}
|
|
48
|
+
export function storageInfo(c) {
|
|
49
|
+
return { kind: c.kind, from: c.from, url_set: !!c.url, ...(c.url ? { where: describeUrl(c.url) } : {}) };
|
|
50
|
+
}
|
|
51
|
+
/** Save the choice (takes effect when Spatial Views next starts). An omitted URL keeps the saved one. */
|
|
52
|
+
export async function writeStorageConfig(home, input) {
|
|
53
|
+
const cur = await readConfig(home);
|
|
54
|
+
const url = input.url?.trim() || (input.kind === "postgres" ? cur.storage.url : undefined);
|
|
55
|
+
if (input.kind === "postgres") {
|
|
56
|
+
if (!url)
|
|
57
|
+
throw new UserError("Postgres needs a database URL (postgres://host:5432/db, with its user and password)");
|
|
58
|
+
if (!/^postgres(ql)?:\/\//i.test(url))
|
|
59
|
+
throw new UserError("the database URL starts postgres://");
|
|
60
|
+
}
|
|
61
|
+
const next = { ...cur, storage: { kind: input.kind, ...(url ? { url } : {}) } };
|
|
62
|
+
await writeJson(configFile(home), next);
|
|
63
|
+
await chmod(configFile(home), 0o600).catch(() => undefined);
|
|
64
|
+
return { kind: input.kind, ...(url ? { url } : {}), from: "config" };
|
|
65
|
+
}
|
|
66
|
+
/** Open the configured backend. */
|
|
67
|
+
export async function openStorage(home, env = process.env) {
|
|
68
|
+
const c = await readStorageConfig(home, env);
|
|
69
|
+
if (c.kind === "folder")
|
|
70
|
+
return new FolderStore({ home });
|
|
71
|
+
if (!c.url)
|
|
72
|
+
throw new UserError("storage is postgres but no database URL is set (SPATIAL_VIEWS_DATABASE_URL or Settings → Storage)");
|
|
73
|
+
return PostgresStore.connect({ url: c.url });
|
|
74
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { projectToolboxDir, userToolboxDir } from "../types.js";
|
|
2
|
+
import { ViewWatcher, only, yamlId } from "./folder-watch.js";
|
|
3
|
+
/** The kinds the canvas hears about (by the same names as before storage backends). */
|
|
4
|
+
const EVENT = {
|
|
5
|
+
view: "view",
|
|
6
|
+
gap: "gap",
|
|
7
|
+
pins: "pins",
|
|
8
|
+
approval: "approval",
|
|
9
|
+
settings: "settings",
|
|
10
|
+
doc: "doc",
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* One project's live changes for the canvas: the store's change stream (fs
|
|
14
|
+
* watch for folders, LISTEN/NOTIFY for Postgres) plus this machine's open_view
|
|
15
|
+
* hand-off file.
|
|
16
|
+
*/
|
|
17
|
+
export class ProjectEvents {
|
|
18
|
+
listeners = new Set();
|
|
19
|
+
store;
|
|
20
|
+
local;
|
|
21
|
+
/** `dataDir`: the folder whose toolboxes/*.yaml are watched too (toolboxes are files); `userDir`: the user's toolboxes. */
|
|
22
|
+
constructor(storage, project, localDir, pollMs, dataDir, userDir) {
|
|
23
|
+
const emit = (e) => this.listeners.forEach((fn) => fn(e));
|
|
24
|
+
this.store = storage.watch(project, (c) => {
|
|
25
|
+
const type = EVENT[c.kind];
|
|
26
|
+
if (type)
|
|
27
|
+
emit({ type, id: c.id, removed: c.removed });
|
|
28
|
+
});
|
|
29
|
+
this.local = new ViewWatcher([
|
|
30
|
+
{ type: "open", dir: localDir, match: only("open.json", "open") },
|
|
31
|
+
...(dataDir
|
|
32
|
+
? [
|
|
33
|
+
// The project's toolboxes (YAML files, whatever the store).
|
|
34
|
+
{ type: "types", dir: projectToolboxDir(dataDir), match: yamlId },
|
|
35
|
+
]
|
|
36
|
+
: []),
|
|
37
|
+
// The user's toolboxes (~/SpatialViews/toolboxes).
|
|
38
|
+
{ type: "types", dir: userDir ?? userToolboxDir(), match: yamlId },
|
|
39
|
+
], pollMs);
|
|
40
|
+
this.local.subscribe(emit);
|
|
41
|
+
}
|
|
42
|
+
async whenReady() {
|
|
43
|
+
await Promise.all([this.store.ready, this.local.whenReady()]);
|
|
44
|
+
}
|
|
45
|
+
subscribe(fn) {
|
|
46
|
+
this.listeners.add(fn);
|
|
47
|
+
return () => this.listeners.delete(fn);
|
|
48
|
+
}
|
|
49
|
+
close() {
|
|
50
|
+
this.store.close();
|
|
51
|
+
this.local.close();
|
|
52
|
+
this.listeners.clear();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { watch } from "node:fs";
|
|
2
|
+
import { readdir, stat } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { projectToolboxDir, userToolboxDir } from "../types.js";
|
|
5
|
+
export const jsonId = (f) => (f.endsWith(".json") ? f.slice(0, -5) : null);
|
|
6
|
+
export const yamlId = (f) => (/\.ya?ml$/.test(f) ? f.replace(/\.ya?ml$/, "") : null);
|
|
7
|
+
export const only = (name, id) => (f) => (f === name ? id : null);
|
|
8
|
+
/**
|
|
9
|
+
* Watches a project's data folder and reports what changed, so the canvas can
|
|
10
|
+
* show what the AI does through MCP (a separate process) live. This is the
|
|
11
|
+
* folder store's change stream (FolderStore.watch).
|
|
12
|
+
*
|
|
13
|
+
* fs.watch triggers a rescan straight away; a slow poll is the fallback where
|
|
14
|
+
* fs.watch is unreliable (WSL /mnt drives, network file systems) or a folder
|
|
15
|
+
* does not exist yet. A file counts as changed when its mtime, size or inode
|
|
16
|
+
* changes (the stores save by rename, so every save is a new inode).
|
|
17
|
+
*/
|
|
18
|
+
export class ViewWatcher {
|
|
19
|
+
channels;
|
|
20
|
+
pollMs;
|
|
21
|
+
seen = new Map();
|
|
22
|
+
listeners = new Set();
|
|
23
|
+
timer = null;
|
|
24
|
+
debounce = null;
|
|
25
|
+
scanning = null;
|
|
26
|
+
again = false;
|
|
27
|
+
ready;
|
|
28
|
+
constructor(channels, pollMs = 1000) {
|
|
29
|
+
this.channels = channels;
|
|
30
|
+
this.pollMs = pollMs;
|
|
31
|
+
this.ready = this.scan(false);
|
|
32
|
+
this.timer = setInterval(() => void this.rescan(), this.pollMs);
|
|
33
|
+
this.timer.unref?.();
|
|
34
|
+
}
|
|
35
|
+
static forRepo(repoRoot, pollMs) {
|
|
36
|
+
return ViewWatcher.forData(join(repoRoot, ".spatial"), join(repoRoot, ".spatial-local"), pollMs);
|
|
37
|
+
}
|
|
38
|
+
/** Watch one project's data folder (views/, gaps/, pins.json) and its local hand-off folder. */
|
|
39
|
+
static forData(dataDir, localDir, pollMs, userDir) {
|
|
40
|
+
return new ViewWatcher([
|
|
41
|
+
{ type: "view", dir: join(dataDir, "views"), match: jsonId },
|
|
42
|
+
{ type: "gap", dir: join(dataDir, "gaps"), match: jsonId },
|
|
43
|
+
{ type: "pins", dir: dataDir, match: only("pins.json", "pins") },
|
|
44
|
+
{ type: "open", dir: localDir, match: only("open.json", "open") },
|
|
45
|
+
{ type: "approval", dir: join(dataDir, "approvals"), match: jsonId },
|
|
46
|
+
{ type: "settings", dir: dataDir, match: only("settings.json", "settings") },
|
|
47
|
+
// The project's toolboxes and the user's (~/SpatialViews/toolboxes).
|
|
48
|
+
{ type: "types", dir: projectToolboxDir(dataDir), match: yamlId },
|
|
49
|
+
{ type: "types", dir: userDir ?? userToolboxDir(), match: yamlId },
|
|
50
|
+
], pollMs);
|
|
51
|
+
}
|
|
52
|
+
/** Resolves once the first scan (the baseline, which emits nothing) is done. */
|
|
53
|
+
whenReady() {
|
|
54
|
+
return this.ready;
|
|
55
|
+
}
|
|
56
|
+
subscribe(fn) {
|
|
57
|
+
this.listeners.add(fn);
|
|
58
|
+
return () => this.listeners.delete(fn);
|
|
59
|
+
}
|
|
60
|
+
close() {
|
|
61
|
+
if (this.timer)
|
|
62
|
+
clearInterval(this.timer);
|
|
63
|
+
if (this.debounce)
|
|
64
|
+
clearTimeout(this.debounce);
|
|
65
|
+
for (const c of this.channels)
|
|
66
|
+
(c.fsw?.close(), (c.fsw = null));
|
|
67
|
+
this.timer = this.debounce = null;
|
|
68
|
+
this.listeners.clear();
|
|
69
|
+
}
|
|
70
|
+
/** Scan now (serialised: a call during a scan queues one more scan). */
|
|
71
|
+
rescan() {
|
|
72
|
+
if (this.scanning) {
|
|
73
|
+
this.again = true;
|
|
74
|
+
return this.scanning;
|
|
75
|
+
}
|
|
76
|
+
this.scanning = this.scan(true).finally(() => {
|
|
77
|
+
this.scanning = null;
|
|
78
|
+
if (this.again) {
|
|
79
|
+
this.again = false;
|
|
80
|
+
void this.rescan();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return this.scanning;
|
|
84
|
+
}
|
|
85
|
+
ensureFsWatch(c) {
|
|
86
|
+
if (c.fsw || !this.timer)
|
|
87
|
+
return;
|
|
88
|
+
try {
|
|
89
|
+
c.fsw = watch(c.dir, () => {
|
|
90
|
+
if (this.debounce)
|
|
91
|
+
clearTimeout(this.debounce);
|
|
92
|
+
this.debounce = setTimeout(() => void this.rescan(), 30);
|
|
93
|
+
});
|
|
94
|
+
c.fsw.on("error", () => {
|
|
95
|
+
c.fsw?.close();
|
|
96
|
+
c.fsw = null; // the poll carries on, and the next scan tries again
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
c.fsw = null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async scan(emit) {
|
|
104
|
+
const now = new Map();
|
|
105
|
+
const meta = new Map();
|
|
106
|
+
for (const c of this.channels) {
|
|
107
|
+
let files = [];
|
|
108
|
+
try {
|
|
109
|
+
files = await readdir(c.dir);
|
|
110
|
+
this.ensureFsWatch(c);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// The folder isn't there (yet): everything we knew in it is gone.
|
|
114
|
+
}
|
|
115
|
+
for (const f of files) {
|
|
116
|
+
const id = c.match(f);
|
|
117
|
+
if (id === null)
|
|
118
|
+
continue;
|
|
119
|
+
try {
|
|
120
|
+
const s = await stat(join(c.dir, f));
|
|
121
|
+
const key = `${c.type}:${id}`;
|
|
122
|
+
now.set(key, `${s.mtimeMs}:${s.size}:${s.ino}`);
|
|
123
|
+
meta.set(key, { type: c.type, id });
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Removed between readdir and stat; the next scan settles it.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const events = [];
|
|
131
|
+
for (const [key, sig] of now)
|
|
132
|
+
if (this.seen.get(key) !== sig)
|
|
133
|
+
events.push({ ...meta.get(key), removed: false });
|
|
134
|
+
for (const key of this.seen.keys()) {
|
|
135
|
+
if (now.has(key))
|
|
136
|
+
continue;
|
|
137
|
+
const at = key.indexOf(":");
|
|
138
|
+
events.push({ type: key.slice(0, at), id: key.slice(at + 1), removed: true });
|
|
139
|
+
}
|
|
140
|
+
this.seen = now;
|
|
141
|
+
if (!emit)
|
|
142
|
+
return;
|
|
143
|
+
for (const e of events)
|
|
144
|
+
for (const fn of this.listeners)
|
|
145
|
+
fn(e);
|
|
146
|
+
}
|
|
147
|
+
}
|