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
package/dist/core/schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { TypeEntrySchema, ToolboxFileSchema } from "./types.js";
|
|
2
3
|
/**
|
|
3
4
|
* The data in `.spatial/`, one JSON file per View and per Gap, plus pins.json.
|
|
4
5
|
* React Flow reads the modules and connections directly; the AI is served the
|
|
@@ -16,12 +17,22 @@ export const ModuleSchema = z.object({
|
|
|
16
17
|
linked_view_id: z.string().min(1).optional(),
|
|
17
18
|
/** Source files on the module, repo-relative. */
|
|
18
19
|
files: z.array(z.string().min(1)).optional(),
|
|
20
|
+
/** The swim lane (a lane id on this View) the module sits in: who owns the work. */
|
|
21
|
+
lane: z.string().min(1).optional(),
|
|
22
|
+
/** Its module type (types/<id>.yaml): the icon, colour, size and properties schema. */
|
|
23
|
+
type: z.string().min(1).optional(),
|
|
24
|
+
/** Its property values, by the type's property names. */
|
|
25
|
+
properties: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
19
26
|
});
|
|
27
|
+
/** A point on the canvas (a bend in a connection). */
|
|
28
|
+
export const PointSchema = z.object({ x: z.number(), y: z.number() });
|
|
20
29
|
export const ConnectionSchema = z.object({
|
|
21
30
|
id: z.string().min(1),
|
|
22
31
|
from: z.string().min(1),
|
|
23
32
|
to: z.string().min(1),
|
|
24
33
|
label: z.string().optional(),
|
|
34
|
+
/** Bend points a person placed, in order from `from` to `to`. Left out: routed automatically (orthogonal). */
|
|
35
|
+
bends: z.array(PointSchema).optional(),
|
|
25
36
|
});
|
|
26
37
|
/** A Feature: a named group of modules on one View (made with the lasso). */
|
|
27
38
|
export const FeatureSchema = z.object({
|
|
@@ -29,13 +40,37 @@ export const FeatureSchema = z.object({
|
|
|
29
40
|
name: z.string().min(1),
|
|
30
41
|
module_ids: z.array(z.string().min(1)).default([]),
|
|
31
42
|
});
|
|
43
|
+
/** A swim lane: one per team or person, drawn as a horizontal band. */
|
|
44
|
+
export const LaneSchema = z.object({
|
|
45
|
+
id: Id,
|
|
46
|
+
label: z.string().min(1),
|
|
47
|
+
});
|
|
48
|
+
/** flow (the default): modules and connections. sequence: participants (the modules, left to right) and ordered messages. */
|
|
49
|
+
export const ViewKindSchema = z.enum(["flow", "sequence"]);
|
|
50
|
+
export const MessageKindSchema = z.enum(["sync", "async", "reply"]);
|
|
51
|
+
/** One message in a sequence View, from one participant to another, in order. */
|
|
52
|
+
export const MessageSchema = z.object({
|
|
53
|
+
id: z.string().min(1),
|
|
54
|
+
from: z.string().min(1),
|
|
55
|
+
to: z.string().min(1),
|
|
56
|
+
text: z.string(),
|
|
57
|
+
kind: MessageKindSchema.optional(),
|
|
58
|
+
});
|
|
32
59
|
export const ViewSchema = z.object({
|
|
33
60
|
id: Id,
|
|
34
61
|
name: z.string(),
|
|
35
62
|
type: ViewTypeSchema.default("sub-view"),
|
|
63
|
+
/** sequence: the modules are the participants and `messages` the ordered calls. Left out: flow. */
|
|
64
|
+
kind: ViewKindSchema.optional(),
|
|
65
|
+
/** Swim lanes, top to bottom. */
|
|
66
|
+
lanes: z.array(LaneSchema).optional(),
|
|
67
|
+
/** Sequence Views: the messages, in order. */
|
|
68
|
+
messages: z.array(MessageSchema).optional(),
|
|
36
69
|
modules: z.array(ModuleSchema).default([]),
|
|
37
70
|
connections: z.array(ConnectionSchema).default([]),
|
|
38
71
|
features: z.array(FeatureSchema).optional(),
|
|
72
|
+
/** The positions are still the auto-layout's: the AI may lay the View out again. Cleared once a person moves anything. */
|
|
73
|
+
auto_layout: z.boolean().optional(),
|
|
39
74
|
/** A View drafted by import (from a Mermaid flowchart), not yet reviewed. */
|
|
40
75
|
draft: z.boolean().optional(),
|
|
41
76
|
/** Where a drafted View came from: `<path>#<n>` (the n-th Mermaid block). */
|
|
@@ -53,6 +88,8 @@ export const GapSchema = z.object({
|
|
|
53
88
|
/** The OpenSpec change (openspec/changes/<id>/) this Gap follows. */
|
|
54
89
|
openspec_change: z.string().optional(),
|
|
55
90
|
milestone: z.string().optional(),
|
|
91
|
+
/** Raised by an audit (drift, a missing requirement) and not yet confirmed by a person. */
|
|
92
|
+
draft: z.boolean().optional(),
|
|
56
93
|
});
|
|
57
94
|
/** A pin maps a repo path (a spec, a change folder, any .md) to a part of the picture. */
|
|
58
95
|
export const PinSchema = z.discriminatedUnion("kind", [
|
|
@@ -77,15 +114,142 @@ export const PinsFileSchema = z.object({
|
|
|
77
114
|
sources: z.array(z.string().min(1)).default([]),
|
|
78
115
|
pins: z.array(PinSchema).default([]),
|
|
79
116
|
});
|
|
117
|
+
// ---- Projects (M1) ------------------------------------------------------
|
|
118
|
+
export const SourceKindSchema = z.enum(["repo", "docs", "diagrams"]);
|
|
119
|
+
export const AuditKindSchema = z.enum(["pre-audit", "update-state", "post-audit"]);
|
|
120
|
+
export const SourceSchema = z.object({
|
|
121
|
+
id: Id,
|
|
122
|
+
/** What people call it (the folder name unless given). */
|
|
123
|
+
name: z.string().optional(),
|
|
124
|
+
kind: SourceKindSchema,
|
|
125
|
+
/** As given: Windows (`c:\git\api`) or POSIX (`/home/me/api`), or relative to the project. */
|
|
126
|
+
path: z.string().min(1),
|
|
127
|
+
added: z.string(),
|
|
128
|
+
/** The commit (repos) or ISO time (docs, diagrams) of the last audit that read this source. */
|
|
129
|
+
last_audit_sha: z.string().optional(),
|
|
130
|
+
});
|
|
131
|
+
export const AuditSchema = z.object({
|
|
132
|
+
kind: AuditKindSchema,
|
|
133
|
+
at: z.string(),
|
|
134
|
+
/** The report, as pinned: `reports/<name>.md` (`.spatial/reports/<name>.md` in a single-repo project). */
|
|
135
|
+
report: z.string().optional(),
|
|
136
|
+
});
|
|
137
|
+
export const ProjectSchema = z.object({
|
|
138
|
+
name: z.string().min(1),
|
|
139
|
+
/** The folder name under `~/SpatialViews/projects/` (home projects). */
|
|
140
|
+
slug: z.string().optional(),
|
|
141
|
+
created: z.string(),
|
|
142
|
+
/** The View the project always opens on (set by create_project and pre-audit; default system-overview). */
|
|
143
|
+
root_view_id: Id.optional(),
|
|
144
|
+
sources: z.array(SourceSchema).default([]),
|
|
145
|
+
audits: z.array(AuditSchema).default([]),
|
|
146
|
+
});
|
|
147
|
+
// ---- Approvals (M1) ---------------------------------------------------------
|
|
148
|
+
/** What one change in an Approval is about: a View, a Gap, the pin map or a doc (repo path). */
|
|
149
|
+
export const ChangeTargetSchema = z.enum(["view", "gap", "pins", "doc"]);
|
|
150
|
+
export const ChangeOpSchema = z.enum(["create", "update", "delete"]);
|
|
151
|
+
export const DecisionSchema = z.enum(["approved", "denied"]);
|
|
152
|
+
export const ApprovalStatusSchema = z.enum(["pending", "approved", "denied"]);
|
|
153
|
+
/**
|
|
154
|
+
* One change in an Approval: the whole before and after of one file, so the
|
|
155
|
+
* review screen can draw both. Every MCP write to the same file in an Approval
|
|
156
|
+
* folds into one change (the first before, the last after).
|
|
157
|
+
*/
|
|
158
|
+
export const ApprovalChangeSchema = z.object({
|
|
159
|
+
id: Id,
|
|
160
|
+
target: ChangeTargetSchema,
|
|
161
|
+
/** View id, Gap id, "pins", or the doc's repo path. */
|
|
162
|
+
ref: z.string().min(1),
|
|
163
|
+
op: ChangeOpSchema,
|
|
164
|
+
/** JSON for views, gaps and pins; text for docs. null: did not exist / removed. */
|
|
165
|
+
before: z.unknown().nullable(),
|
|
166
|
+
after: z.unknown().nullable(),
|
|
167
|
+
/** The MCP tools that made it, in order. */
|
|
168
|
+
tools: z.array(z.string()).default([]),
|
|
169
|
+
at: z.string(),
|
|
170
|
+
/** The reviewer's call on this one change (none: goes with the whole Approval). */
|
|
171
|
+
decision: DecisionSchema.optional(),
|
|
172
|
+
});
|
|
173
|
+
/** One amendment the AI made to a pending draft. */
|
|
174
|
+
export const RevisionSchema = z.object({
|
|
175
|
+
/** 1, 2, 3, ... in order. */
|
|
176
|
+
n: z.number().int().positive(),
|
|
177
|
+
at: z.string(),
|
|
178
|
+
/** Who made it (the MCP client's name). */
|
|
179
|
+
by: z.string().min(1),
|
|
180
|
+
/** What it changed, e.g. "1 module added; 1 connection added". */
|
|
181
|
+
summary: z.string(),
|
|
182
|
+
/** The MCP tool that made it. */
|
|
183
|
+
tool: z.string().optional(),
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* `<data>/approvals/<id>.json`: a draft of one View or Doc (or a Gap, or the
|
|
187
|
+
* pin map), pending for a person and never live until approved. No send
|
|
188
|
+
* step: each AI write lands here at once, and a write to a file that already
|
|
189
|
+
* has a pending Approval folds into it as a new revision. Its one change
|
|
190
|
+
* holds the base (`before`: the live content, at `base_version`) and the head
|
|
191
|
+
* (`after`: the latest draft). Older Approvals may hold several changes.
|
|
192
|
+
*/
|
|
193
|
+
export const ApprovalSchema = z.object({
|
|
194
|
+
id: Id,
|
|
195
|
+
/** People's number for it in the project: #12. */
|
|
196
|
+
n: z.number().int().positive().optional(),
|
|
197
|
+
/** Generated from the changes, e.g. "Cursor: amended View Checkout". */
|
|
198
|
+
title: z.string().min(1),
|
|
199
|
+
/** The IDE that made it (the MCP client's name: claude-code, cursor, ...). */
|
|
200
|
+
author: z.string().min(1),
|
|
201
|
+
created: z.string(),
|
|
202
|
+
status: ApprovalStatusSchema.default("pending"),
|
|
203
|
+
/** The agent run (MCP server session) that last amended it. */
|
|
204
|
+
session: z.string().optional(),
|
|
205
|
+
decided: z.string().optional(),
|
|
206
|
+
/** A note from the reviewer, read back by get_approval. */
|
|
207
|
+
note: z.string().optional(),
|
|
208
|
+
/** The version of the live content the draft starts from (Views and Docs; null: none yet). */
|
|
209
|
+
base_version: z.number().int().positive().nullable().optional(),
|
|
210
|
+
/** Each amendment, oldest first. Approve names the one it saw (rev = their count). */
|
|
211
|
+
revisions: z.array(RevisionSchema).default([]),
|
|
212
|
+
changes: z.array(ApprovalChangeSchema).default([]),
|
|
213
|
+
});
|
|
214
|
+
/** `<data>/settings.json`: a project's settings. */
|
|
215
|
+
export const SettingsSchema = z.object({
|
|
216
|
+
/** approval (default): "AI changes need approval", writes land in Approvals. direct: "Apply directly" (M0). */
|
|
217
|
+
ai_changes: z.enum(["approval", "direct"]).default("approval"),
|
|
218
|
+
/** The canvas opens the View the AI is changing and shows the change as it happens. */
|
|
219
|
+
follow: z.boolean().default(true),
|
|
220
|
+
/** Toolbox ids turned off for this project (they leave the canvas's bar; modules of their types still draw). */
|
|
221
|
+
disabled_toolboxes: z.array(z.string()).default([]),
|
|
222
|
+
/** How many unnamed versions each View and Doc keeps (the newest; named ones always stay). Unset or null: all of them. */
|
|
223
|
+
keep_versions: z.number().int().positive().nullable().optional(),
|
|
224
|
+
/**
|
|
225
|
+
* How the project writes its specs. spatial-views (default): PRD, MDD and Gap
|
|
226
|
+
* docs from the doc-type templates. openspec: openspec/specs and
|
|
227
|
+
* openspec/changes in the OpenSpec layout; new docs are OpenSpec changes.
|
|
228
|
+
*/
|
|
229
|
+
spec_format: z.enum(["spatial-views", "openspec"]).default("spatial-views"),
|
|
230
|
+
/**
|
|
231
|
+
* The Project panel's folders (Specs, Docs, Diagrams, Logic, Software, Cloud
|
|
232
|
+
* by default; people add, rename and nest them: a folder's parent is the folder it sits in) and where each doc ("doc:<path>")
|
|
233
|
+
* or View ("view:<id>") was put. Anything not placed goes in its default folder.
|
|
234
|
+
*/
|
|
235
|
+
tree: z
|
|
236
|
+
.object({
|
|
237
|
+
folders: z.array(z.object({ id: z.string().min(1), name: z.string().min(1).max(60), parent: z.string().min(1).optional() })).optional(),
|
|
238
|
+
place: z.record(z.string(), z.string()).optional(),
|
|
239
|
+
})
|
|
240
|
+
.optional(),
|
|
241
|
+
});
|
|
80
242
|
export function summarize(view) {
|
|
81
243
|
const s = { id: view.id, name: view.name, type: view.type, modules: view.modules.length };
|
|
82
244
|
if (view.draft)
|
|
83
245
|
s.draft = true;
|
|
246
|
+
if (view.kind === "sequence")
|
|
247
|
+
s.kind = "sequence";
|
|
84
248
|
return s;
|
|
85
249
|
}
|
|
86
250
|
/** Where the published JSON Schemas live (schema/*.schema.json in the repo). */
|
|
87
251
|
export const SCHEMA_BASE = "https://raw.githubusercontent.com/Hotchilli-Cloud/spatial-views/main/schema/";
|
|
88
|
-
/** The JSON Schemas for the
|
|
252
|
+
/** The JSON Schemas for the file kinds in `.spatial/`. */
|
|
89
253
|
export function jsonSchemas() {
|
|
90
254
|
const one = (name, title, schema) => ({
|
|
91
255
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
@@ -97,5 +261,10 @@ export function jsonSchemas() {
|
|
|
97
261
|
view: one("view", "Spatial Views: a View (.spatial/views/<id>.json)", ViewSchema),
|
|
98
262
|
gap: one("gap", "Spatial Views: a Gap (.spatial/gaps/<id>.json)", GapSchema),
|
|
99
263
|
pins: one("pins", "Spatial Views: the pin map (.spatial/pins.json)", PinsFileSchema),
|
|
264
|
+
project: one("project", "Spatial Views: a project and its sources (~/SpatialViews/projects/<slug>/project.json)", ProjectSchema),
|
|
265
|
+
approval: one("approval", "Spatial Views: an Approval: a pending AI draft of one View or Doc, with its revisions (<data>/approvals/<id>.json)", ApprovalSchema),
|
|
266
|
+
settings: one("settings", "Spatial Views: a project's settings (<data>/settings.json)", SettingsSchema),
|
|
267
|
+
toolbox: one("toolbox", "Spatial Views: a toolbox (toolboxes/<id>.yaml): its module types and doc types", ToolboxFileSchema),
|
|
268
|
+
type: one("type", "Spatial Views: a module type, as written in a toolbox's types list", TypeEntrySchema),
|
|
100
269
|
};
|
|
101
270
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { lstat, readlink, realpath } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
import { UserError } from "./errors.js";
|
|
4
|
+
import { macReal } from "./paths.js";
|
|
5
|
+
/** The refusal when no project is active (PRD §9.1). */
|
|
6
|
+
export const PICK_PROJECT = "pick a project: list_projects, then use_project";
|
|
7
|
+
/** A path outside the active project's sources. The message lists what is allowed. */
|
|
8
|
+
export class ScopeError extends UserError {
|
|
9
|
+
}
|
|
10
|
+
/** No project is active yet. */
|
|
11
|
+
export class NoProjectError extends UserError {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(PICK_PROJECT);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The real path of `p`, following symlinks. Where `p` does not exist yet, the
|
|
18
|
+
* nearest folder above it that does is resolved, and the rest is put back.
|
|
19
|
+
*/
|
|
20
|
+
export async function realPath(p) {
|
|
21
|
+
const abs = resolve(p);
|
|
22
|
+
const rest = [];
|
|
23
|
+
let at = abs;
|
|
24
|
+
for (;;) {
|
|
25
|
+
const real = await realpath(at).catch(() => null);
|
|
26
|
+
if (real)
|
|
27
|
+
return rest.length ? join(real, ...rest.reverse()) : real;
|
|
28
|
+
const up = dirname(at);
|
|
29
|
+
if (up === at)
|
|
30
|
+
return abs;
|
|
31
|
+
rest.push(basename(at));
|
|
32
|
+
at = up;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** True when `child` is `parent` or inside it (both real, absolute paths). */
|
|
36
|
+
export function isInside(parent, child) {
|
|
37
|
+
const rel = relative(parent, child);
|
|
38
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
39
|
+
}
|
|
40
|
+
/** "api (/src/api), web (/src/web)": for refusals. */
|
|
41
|
+
export function describeRoots(roots) {
|
|
42
|
+
return roots.length ? roots.map((r) => `${r.id} (${r.abs})`).join(", ") : "none yet (add_source)";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `p` relative to a root, when it is written inside it: under the root's real
|
|
46
|
+
* path or as the root was given (macOS: /var is /private/var). Null otherwise.
|
|
47
|
+
* Compared as text: `p` itself is not looked at.
|
|
48
|
+
*/
|
|
49
|
+
function relIn(base, given, p) {
|
|
50
|
+
for (const want of [p, macReal(p)])
|
|
51
|
+
for (const from of [base, given])
|
|
52
|
+
if (isInside(from, want))
|
|
53
|
+
return relative(from, want);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Follow `rel` down from `base` one name at a time. A symlink is read (it is
|
|
58
|
+
* inside `base`) and followed only if it points inside `base`; a link out is
|
|
59
|
+
* refused without its target being touched. Names that don't exist yet are
|
|
60
|
+
* kept as written. Returns the real path, or null for a link out.
|
|
61
|
+
*/
|
|
62
|
+
async function follow(base, given, rel, depth = 0) {
|
|
63
|
+
if (depth > 40)
|
|
64
|
+
return null;
|
|
65
|
+
let cur = base;
|
|
66
|
+
const parts = rel.split(/[\\/]+/).filter((x) => x && x !== ".");
|
|
67
|
+
for (let i = 0; i < parts.length; i++) {
|
|
68
|
+
const next = parts[i] === ".." ? dirname(cur) : join(cur, parts[i]);
|
|
69
|
+
if (!isInside(base, next))
|
|
70
|
+
return null;
|
|
71
|
+
const st = await lstat(next).catch(() => null);
|
|
72
|
+
if (!st)
|
|
73
|
+
return join(next, ...parts.slice(i + 1));
|
|
74
|
+
if (st.isSymbolicLink()) {
|
|
75
|
+
const target = resolve(dirname(next), await readlink(next));
|
|
76
|
+
const to = relIn(base, given, target);
|
|
77
|
+
if (to === null)
|
|
78
|
+
return null;
|
|
79
|
+
const real = await follow(base, given, to, depth + 1);
|
|
80
|
+
if (!real)
|
|
81
|
+
return null;
|
|
82
|
+
cur = real;
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
cur = next;
|
|
86
|
+
}
|
|
87
|
+
return cur;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Where `abs` really is, if that is inside `root` (symlinks and `..` resolved).
|
|
91
|
+
* Throws a ScopeError otherwise. Nothing outside the root is ever looked at.
|
|
92
|
+
*/
|
|
93
|
+
export async function realInside(root, abs, allowed = [root]) {
|
|
94
|
+
const base = await realPath(root.abs);
|
|
95
|
+
const refuse = () => new ScopeError(`${abs} is outside the project's sources. Allowed: ${describeRoots(allowed)}`);
|
|
96
|
+
const want = resolve(abs);
|
|
97
|
+
const given = resolve(root.abs);
|
|
98
|
+
const rel = relIn(base, given, want);
|
|
99
|
+
// Not even written inside the root: refused without looking at it.
|
|
100
|
+
if (rel === null)
|
|
101
|
+
throw refuse();
|
|
102
|
+
const real = await follow(base, given, rel);
|
|
103
|
+
if (!real || !isInside(base, real))
|
|
104
|
+
throw refuse();
|
|
105
|
+
return real;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The root that really holds `abs`, or null. A path that is not even written
|
|
109
|
+
* inside a root (as given, or under the root's real path) is refused without
|
|
110
|
+
* touching the disk, so a folder outside every source is never so much as
|
|
111
|
+
* looked at. Inside one, symlinks are then resolved and checked again.
|
|
112
|
+
*/
|
|
113
|
+
export async function rootOf(roots, abs) {
|
|
114
|
+
const want = resolve(abs);
|
|
115
|
+
for (const r of roots) {
|
|
116
|
+
const base = await realPath(r.abs);
|
|
117
|
+
const given = resolve(r.abs);
|
|
118
|
+
const rel = relIn(base, given, want);
|
|
119
|
+
if (rel === null)
|
|
120
|
+
continue;
|
|
121
|
+
const real = await follow(base, given, rel);
|
|
122
|
+
if (real && isInside(base, real))
|
|
123
|
+
return { root: r, rel: relative(base, real).split(/[\\/]/).join("/") || "." };
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, posix } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { readSkillFile, shellQuote, skillNames } from "./skills.js";
|
|
7
|
+
export const IDES = ["cursor", "claude", "windsurf"];
|
|
8
|
+
/** The MCP entry: plain, or through `wsl bash -lc` for a Windows IDE talking to WSL. */
|
|
9
|
+
export function mcpEntry(launch, wsl, env) {
|
|
10
|
+
const [command, ...pre] = launch;
|
|
11
|
+
const args = [...pre, "mcp", "--global"];
|
|
12
|
+
const vars = Object.entries(env ?? {});
|
|
13
|
+
if (!wsl)
|
|
14
|
+
return vars.length ? { command: command, args, env: { ...env } } : { command: command, args };
|
|
15
|
+
const line = [...vars.map(([k, v]) => `${k}=${shellQuote(v)}`), ...[command, ...args].map(shellQuote)].join(" ");
|
|
16
|
+
return { command: "wsl", args: ["bash", "-lc", line] };
|
|
17
|
+
}
|
|
18
|
+
/** Where each IDE keeps its global MCP servers. */
|
|
19
|
+
export function configPath(ide, home) {
|
|
20
|
+
switch (ide) {
|
|
21
|
+
case "cursor":
|
|
22
|
+
return join(home, ".cursor", "mcp.json");
|
|
23
|
+
case "claude":
|
|
24
|
+
return join(home, ".claude.json");
|
|
25
|
+
case "windsurf":
|
|
26
|
+
return join(home, ".codeium", "windsurf", "mcp_config.json");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The config files for an IDE. Outside WSL: the one in ~. In WSL, Cursor and
|
|
31
|
+
* Windsurf read the Windows profile; Cursor in WSL Remote mode also reads the
|
|
32
|
+
* WSL-side ~/.cursor/mcp.json, so it gets the Linux entry there as well.
|
|
33
|
+
*/
|
|
34
|
+
export function configTargets(ide, home, windowsHome, wsl) {
|
|
35
|
+
if (!wsl || ide === "claude")
|
|
36
|
+
return [{ ide, file: configPath(ide, home), windows: false }];
|
|
37
|
+
const win = { ide, file: windowsHome ? configPath(ide, windowsHome) : null, windows: true };
|
|
38
|
+
return ide === "cursor" ? [win, { ide, file: configPath(ide, home), windows: false }] : [win];
|
|
39
|
+
}
|
|
40
|
+
/** `C:\Users\tony` as WSL sees it: `/mnt/c/Users/tony`. */
|
|
41
|
+
export function wslPath(winPath) {
|
|
42
|
+
const m = /^([A-Za-z]):[\\/](.*)$/.exec(winPath.trim());
|
|
43
|
+
if (!m)
|
|
44
|
+
return null;
|
|
45
|
+
return posix.join("/mnt", m[1].toLowerCase(), ...m[2].split(/[\\/]+/).filter(Boolean));
|
|
46
|
+
}
|
|
47
|
+
/** The Windows profile, from WSL: SPATIAL_VIEWS_WIN_HOME, else what cmd.exe says %USERPROFILE% is. */
|
|
48
|
+
export async function findWindowsHome(env = process.env) {
|
|
49
|
+
if (env.SPATIAL_VIEWS_WIN_HOME?.trim())
|
|
50
|
+
return wslPath(env.SPATIAL_VIEWS_WIN_HOME) ?? env.SPATIAL_VIEWS_WIN_HOME.trim();
|
|
51
|
+
try {
|
|
52
|
+
const { stdout } = await promisify(execFile)("cmd.exe", ["/d", "/c", "echo %USERPROFILE%"], { timeout: 5000, cwd: "/mnt/c" });
|
|
53
|
+
return wslPath(stdout.trim());
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const exists = (p) => stat(p).then(() => true, () => false);
|
|
60
|
+
async function writeAtomic(file, body) {
|
|
61
|
+
await mkdir(dirname(file), { recursive: true });
|
|
62
|
+
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
63
|
+
await writeFile(tmp, body, "utf8");
|
|
64
|
+
await rename(tmp, file);
|
|
65
|
+
}
|
|
66
|
+
/** Put our entries in an `mcpServers` JSON file, leaving everything else in it as it was. */
|
|
67
|
+
async function mergeEntries(file, entries, o, log) {
|
|
68
|
+
let data = {};
|
|
69
|
+
if (await exists(file)) {
|
|
70
|
+
try {
|
|
71
|
+
data = JSON.parse(await readFile(file, "utf8"));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
log.push(`skipped ${file} (not valid JSON; add this by hand under mcpServers: ${JSON.stringify(entries)})`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const servers = { ...(data.mcpServers ?? {}) };
|
|
79
|
+
let changed = false;
|
|
80
|
+
for (const [name, entry] of Object.entries(entries)) {
|
|
81
|
+
const had = servers[name];
|
|
82
|
+
if (had && JSON.stringify(had) === JSON.stringify(entry)) {
|
|
83
|
+
log.push(`ok ${name} in ${file} (already set up)`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (had && !o.force) {
|
|
87
|
+
log.push(`kept ${name} in ${file} (it has another ${name} entry; --force replaces it)`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
servers[name] = entry;
|
|
91
|
+
changed = true;
|
|
92
|
+
log.push(`${o.dryRun ? "would " : ""}${had ? "replace" : "add"} ${name} in ${file}`);
|
|
93
|
+
}
|
|
94
|
+
if (!changed || o.dryRun)
|
|
95
|
+
return;
|
|
96
|
+
data.mcpServers = servers;
|
|
97
|
+
await writeAtomic(file, JSON.stringify(data, null, 2) + "\n");
|
|
98
|
+
}
|
|
99
|
+
export async function setup(opts) {
|
|
100
|
+
const log = [];
|
|
101
|
+
const home = opts.home ?? homedir();
|
|
102
|
+
const o = { force: opts.force === true, dryRun: opts.dryRun === true };
|
|
103
|
+
const wsl = opts.wsl === true;
|
|
104
|
+
if (wsl)
|
|
105
|
+
log.push("WSL found: Cursor and Windsurf get `spatial-views` (absolute node path, for WSL Remote mode) and `spatial-views-win` (`wsl bash -lc`, for a plain Windows folder); Cursor also gets `spatial-views` in the WSL-side ~/.cursor/mcp.json.");
|
|
106
|
+
for (const ide of opts.ides) {
|
|
107
|
+
// Claude Code runs where you run it (inside WSL); Cursor and Windsurf keep their config on Windows,
|
|
108
|
+
// and Cursor in WSL Remote mode also reads the WSL-side ~/.cursor/mcp.json.
|
|
109
|
+
for (const t of configTargets(ide, home, opts.windowsHome, wsl)) {
|
|
110
|
+
const entries = { "spatial-views": mcpEntry(opts.launch, false, opts.env) };
|
|
111
|
+
if (t.windows)
|
|
112
|
+
entries["spatial-views-win"] = mcpEntry(opts.launch, true, opts.env);
|
|
113
|
+
if (!t.file) {
|
|
114
|
+
log.push(`skipped ${ide}: the Windows profile was not found (set SPATIAL_VIEWS_WIN_HOME=C:\\Users\\<you>), add by hand: ${JSON.stringify({ mcpServers: entries })}`);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
await mergeEntries(t.file, entries, o, log);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (opts.ides.includes("claude") && opts.skillsDir) {
|
|
121
|
+
for (const n of skillNames()) {
|
|
122
|
+
const file = join(home, ".claude", "skills", n, "SKILL.md");
|
|
123
|
+
if ((await exists(file)) && !o.force) {
|
|
124
|
+
log.push(`kept ${file} (exists; --force replaces it)`);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!o.dryRun)
|
|
128
|
+
await writeAtomic(file, await readSkillFile(opts.skillsDir, n));
|
|
129
|
+
log.push(`${o.dryRun ? "would write" : "wrote"} ${file}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
log.push("", "Restart the IDE. The server starts with no projects: ask for `pre-audit <name> <paths...>`, or", "list_projects, create_project and add_source. The Skills are also served as MCP prompts.", "Check it with `spatial-views doctor`.");
|
|
133
|
+
return log;
|
|
134
|
+
}
|
package/dist/core/skills.js
CHANGED
|
@@ -1,33 +1,89 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
2
3
|
import { dirname, join } from "node:path";
|
|
4
|
+
import { experimental } from "./flags.js";
|
|
3
5
|
/**
|
|
4
|
-
* The
|
|
6
|
+
* The Skills (draw-system, gap-from-view, build-gap, and the M1 audit Skills
|
|
7
|
+
* pre-audit, update-state, post-audit, and check-ui) are written once as
|
|
5
8
|
* Claude Code skills (skills/claude/<name>/SKILL.md). The Cursor rules and the
|
|
6
9
|
* Windsurf rules file are made from them, so the three never drift.
|
|
7
10
|
*/
|
|
8
|
-
export const SKILL_NAMES = ["draw-system", "gap-from-view", "build-gap"];
|
|
11
|
+
export const SKILL_NAMES = ["draw-system", "gap-from-view", "build-gap", "pre-audit", "update-state", "post-audit", "check-ui"];
|
|
12
|
+
/** The Skills about Gaps: shipped only with SPATIAL_VIEWS_EXPERIMENTAL=1. */
|
|
13
|
+
export const EXPERIMENTAL_SKILLS = ["gap-from-view", "build-gap"];
|
|
14
|
+
/** The Skills served and installed: without the experimental flag, the Gap Skills are left out. */
|
|
15
|
+
export const skillNames = (exp = experimental()) => SKILL_NAMES.filter((n) => exp || !EXPERIMENTAL_SKILLS.includes(n));
|
|
16
|
+
const block = (tag) => new RegExp(`^[ \\t]*<!-- ${tag} -->[ \\t]*\\n([\\s\\S]*?)^[ \\t]*<!-- /${tag} -->[ \\t]*\\n`, "gm");
|
|
17
|
+
const BLOCK = block("experimental");
|
|
18
|
+
/** The text used instead when the flag is off. */
|
|
19
|
+
const DEFAULT = block("default");
|
|
20
|
+
/** Renumber each ordered list 1, 2, 3 ... (after a step was taken out). A heading or a plain line ends a list. */
|
|
21
|
+
function renumber(md) {
|
|
22
|
+
let n = 0;
|
|
23
|
+
return md
|
|
24
|
+
.split("\n")
|
|
25
|
+
.map((line) => {
|
|
26
|
+
const m = /^(\d+)\. /.exec(line);
|
|
27
|
+
if (m)
|
|
28
|
+
return `${++n}. ${line.slice(m[0].length)}`;
|
|
29
|
+
if (line.trim() && !/^\s/.test(line))
|
|
30
|
+
n = 0;
|
|
31
|
+
return line;
|
|
32
|
+
})
|
|
33
|
+
.join("\n");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A SKILL.md as shipped. Parts between `<!-- experimental -->` and
|
|
37
|
+
* `<!-- /experimental -->` (swim lanes, work splits, Gaps) are kept only with
|
|
38
|
+
* the experimental flag; without it they go, and the steps are renumbered.
|
|
39
|
+
* `description_experimental:` in the frontmatter replaces `description:` when the flag is on.
|
|
40
|
+
*/
|
|
41
|
+
export function skillText(md, exp = experimental()) {
|
|
42
|
+
// A Windows checkout may have CRLF line endings: the Skills ship with LF.
|
|
43
|
+
md = md.replace(/\r\n/g, "\n");
|
|
44
|
+
if (exp) {
|
|
45
|
+
const m = /^description_experimental:\s*(.+)$/m.exec(md);
|
|
46
|
+
let out = md.replace(BLOCK, "$1").replace(DEFAULT, "");
|
|
47
|
+
if (m)
|
|
48
|
+
out = out.replace(/^description:.*$/m, `description: ${m[1]}`);
|
|
49
|
+
return out.replace(/^description_experimental:.*\n/m, "");
|
|
50
|
+
}
|
|
51
|
+
return renumber(md.replace(BLOCK, "").replace(DEFAULT, "$1").replace(/^description_experimental:.*\n/m, ""));
|
|
52
|
+
}
|
|
9
53
|
export function parseSkill(md) {
|
|
10
|
-
const m = /^---\n([\s\S]*?)\n---\n+([\s\S]*)$/.exec(md);
|
|
54
|
+
const m = /^---\n([\s\S]*?)\n---\n+([\s\S]*)$/.exec(md.replace(/\r\n/g, "\n"));
|
|
11
55
|
if (!m)
|
|
12
56
|
throw new Error("a skill needs --- frontmatter ---");
|
|
13
57
|
const field = (k) => new RegExp(`^${k}:\\s*(.+)$`, "m").exec(m[1])?.[1]?.trim() ?? "";
|
|
14
58
|
return { name: field("name"), description: field("description"), body: m[2].trimEnd() + "\n" };
|
|
15
59
|
}
|
|
16
|
-
|
|
60
|
+
/** One SKILL.md as shipped (see skillText). */
|
|
61
|
+
export const readSkillFile = async (skillsDir, name, exp = experimental()) => skillText(await readFile(join(skillsDir, "claude", name, "SKILL.md"), "utf8"), exp);
|
|
62
|
+
export async function readSkills(skillsDir, exp = experimental()) {
|
|
17
63
|
const out = [];
|
|
18
|
-
for (const n of
|
|
19
|
-
out.push(parseSkill(await
|
|
64
|
+
for (const n of skillNames(exp))
|
|
65
|
+
out.push(parseSkill(await readSkillFile(skillsDir, n, exp)));
|
|
20
66
|
return out;
|
|
21
67
|
}
|
|
22
68
|
/** A Cursor rule (.cursor/rules/<name>.mdc): applied by the agent when the description fits. */
|
|
23
69
|
export const cursorRule = (s) => `---\ndescription: ${JSON.stringify(s.description)}\nalwaysApply: false\n---\n\n${s.body}`;
|
|
24
70
|
/** One Windsurf rules file (.windsurf/rules/spatial-views.md) holding all three skills. */
|
|
71
|
+
/** The first line of every Skill: stop when the MCP tools are missing. */
|
|
72
|
+
export const NO_TOOLS = "> If the spatial-views MCP tools are not available, stop and tell the user to enable the spatial-views MCP server " +
|
|
73
|
+
"(and to check the WSL form on Windows). Do not write your own MCP client or call the CLI directly.";
|
|
25
74
|
export function windsurfRules(skills) {
|
|
26
|
-
const
|
|
27
|
-
|
|
75
|
+
const gaps = skills.some((s) => s.name === "gap-from-view");
|
|
76
|
+
const desc = gaps
|
|
77
|
+
? "Spatial Views: draw the system as Views (draw-system), scope a change as a Gap (gap-from-view), " +
|
|
78
|
+
"build a Gap from get_context (build-gap), and audit a project of repos and docs (pre-audit, " +
|
|
79
|
+
"update-state, post-audit), and check a built page against its View or spec (check-ui). Use for architecture, " +
|
|
80
|
+
"Gaps, OpenSpec changes, get_context, audits and UI checks."
|
|
81
|
+
: "Spatial Views: draw the system as Views (draw-system) and audit a project of repos and docs (pre-audit, " +
|
|
82
|
+
"update-state, post-audit), and check a built page against its View or spec (check-ui). Use for architecture " +
|
|
83
|
+
"diagrams, the docs pinned to them, audits and UI checks.";
|
|
28
84
|
// Each skill's headings move down one level, under the file's own title.
|
|
29
85
|
const parts = skills.map((s) => s.body.replace(/^(#{1,5}) /gm, "$1# "));
|
|
30
|
-
return `---\ntrigger: model_decision\ndescription: ${JSON.stringify(desc)}\n---\n\n# Spatial Views skills\n\nUse the \`spatial-views\` MCP tools. Pick the skill that fits:\n\n${skills
|
|
86
|
+
return `---\ntrigger: model_decision\ndescription: ${JSON.stringify(desc)}\n---\n\n# Spatial Views skills\n\n${NO_TOOLS}\n\nUse the \`spatial-views\` MCP tools. Pick the skill that fits:\n\n${skills
|
|
31
87
|
.map((s) => `- **${s.name}**: ${s.description}`)
|
|
32
88
|
.join("\n")}\n\n${parts.join("\n")}`;
|
|
33
89
|
}
|
|
@@ -70,6 +126,23 @@ async function mergeMcp(file, entry, log) {
|
|
|
70
126
|
await writeFile(file, JSON.stringify(data, null, 2) + "\n", "utf8");
|
|
71
127
|
log.push(`updated ${file}`);
|
|
72
128
|
}
|
|
129
|
+
/** True inside WSL: WSL_DISTRO_NAME is set, or /proc/version names Microsoft. */
|
|
130
|
+
export function detectWsl(env = process.env, procVersion) {
|
|
131
|
+
if (env.WSL_DISTRO_NAME)
|
|
132
|
+
return true;
|
|
133
|
+
let v = procVersion;
|
|
134
|
+
if (v === undefined) {
|
|
135
|
+
try {
|
|
136
|
+
v = readFileSync("/proc/version", "utf8");
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return /microsoft/i.test(v);
|
|
143
|
+
}
|
|
144
|
+
/** Quote one word for bash -lc: bare when it is safe, else in single quotes. */
|
|
145
|
+
export const shellQuote = (w) => (/^[A-Za-z0-9_@%+=:,./-]+$/.test(w) ? w : `'${w.replace(/'/g, `'\\''`)}'`);
|
|
73
146
|
/** `npx spatial-views init`: the Skills and the MCP config, for Cursor, Claude Code and Windsurf. */
|
|
74
147
|
export async function init(opts) {
|
|
75
148
|
const log = [];
|
|
@@ -77,14 +150,19 @@ export async function init(opts) {
|
|
|
77
150
|
const [command, ...pre] = opts.launch;
|
|
78
151
|
const force = opts.force === true;
|
|
79
152
|
if (opts.targets.claude) {
|
|
80
|
-
for (const n of
|
|
81
|
-
await put(join(opts.root, ".claude", "skills", n, "SKILL.md"), await
|
|
153
|
+
for (const n of skillNames())
|
|
154
|
+
await put(join(opts.root, ".claude", "skills", n, "SKILL.md"), await readSkillFile(opts.skillsDir, n), force, log);
|
|
82
155
|
await mergeMcp(join(opts.root, ".mcp.json"), { command, args: [...pre, "mcp"] }, log);
|
|
83
156
|
}
|
|
84
157
|
if (opts.targets.cursor) {
|
|
85
158
|
for (const s of skills)
|
|
86
159
|
await put(join(opts.root, ".cursor", "rules", `${s.name}.mdc`), cursorRule(s), force, log);
|
|
87
|
-
|
|
160
|
+
const entry = opts.wsl
|
|
161
|
+
? { command: "wsl", args: ["bash", "-lc", [command, ...pre, "mcp", "--dir", opts.root].map(shellQuote).join(" ")] }
|
|
162
|
+
: { command, args: [...pre, "mcp", "--dir", "${workspaceFolder}"] };
|
|
163
|
+
await mergeMcp(join(opts.root, ".cursor", "mcp.json"), entry, log);
|
|
164
|
+
if (opts.wsl)
|
|
165
|
+
log.push("note WSL found: .cursor/mcp.json runs the server through `wsl bash -lc`, because Cursor starts MCP servers on the Windows side.");
|
|
88
166
|
}
|
|
89
167
|
if (opts.targets.windsurf) {
|
|
90
168
|
await put(join(opts.root, ".windsurf", "rules", "spatial-views.md"), windsurfRules(skills), force, log);
|
|
@@ -92,9 +170,9 @@ export async function init(opts) {
|
|
|
92
170
|
}
|
|
93
171
|
return log;
|
|
94
172
|
}
|
|
95
|
-
/** Rewrite skills/cursor and skills/windsurf from skills/claude (npm run skills). */
|
|
173
|
+
/** Rewrite skills/cursor and skills/windsurf from skills/claude (npm run skills), as shipped without the flag. */
|
|
96
174
|
export async function writeGenerated(skillsDir) {
|
|
97
|
-
const files = generated(await readSkills(skillsDir));
|
|
175
|
+
const files = generated(await readSkills(skillsDir, false));
|
|
98
176
|
for (const [rel, body] of Object.entries(files)) {
|
|
99
177
|
await mkdir(dirname(join(skillsDir, rel)), { recursive: true });
|
|
100
178
|
await writeFile(join(skillsDir, rel), body, "utf8");
|