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,156 @@
|
|
|
1
|
+
const eq = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
2
|
+
function fieldChanges(before, after, fields) {
|
|
3
|
+
return fields
|
|
4
|
+
.filter((f) => !eq(before[f], after[f]))
|
|
5
|
+
.map((f) => ({ field: String(f), before: before[f] ?? null, after: after[f] ?? null }));
|
|
6
|
+
}
|
|
7
|
+
function diffItems(before, after, fields) {
|
|
8
|
+
const old = new Map(before.map((x) => [x.id, x]));
|
|
9
|
+
const now = new Set(after.map((x) => x.id));
|
|
10
|
+
const byId = {};
|
|
11
|
+
const order = [];
|
|
12
|
+
for (const a of after) {
|
|
13
|
+
const b = old.get(a.id);
|
|
14
|
+
const changed = b ? fieldChanges(b, a, fields) : [];
|
|
15
|
+
byId[a.id] = { id: a.id, status: !b ? "added" : changed.length ? "amended" : "same", item: a, ...(b ? { before: b } : {}), changed };
|
|
16
|
+
order.push(a);
|
|
17
|
+
}
|
|
18
|
+
for (const b of before) {
|
|
19
|
+
if (now.has(b.id))
|
|
20
|
+
continue;
|
|
21
|
+
byId[b.id] = { id: b.id, status: "deleted", item: b, before: b, changed: [] };
|
|
22
|
+
order.push(b);
|
|
23
|
+
}
|
|
24
|
+
return { order, byId };
|
|
25
|
+
}
|
|
26
|
+
const MODULE_FIELDS = ["name", "description", "x", "y", "lane", "linked_view_id", "files"];
|
|
27
|
+
const CONNECTION_FIELDS = ["from", "to", "label"];
|
|
28
|
+
const MESSAGE_FIELDS = ["from", "to", "text", "kind"];
|
|
29
|
+
/** Diff two versions of a View (null before: a new View; null after: a removed one). */
|
|
30
|
+
export function diffView(before, after) {
|
|
31
|
+
const base = (after ?? before);
|
|
32
|
+
const b = before ?? { ...base, modules: [], connections: [], messages: base.messages ? [] : undefined };
|
|
33
|
+
const a = after ?? { ...base, modules: [], connections: [], messages: base.messages ? [] : undefined };
|
|
34
|
+
const mods = diffItems(b.modules, a.modules, MODULE_FIELDS);
|
|
35
|
+
const cons = diffItems(b.connections, a.connections, CONNECTION_FIELDS);
|
|
36
|
+
const msgs = diffItems(b.messages ?? [], a.messages ?? [], MESSAGE_FIELDS);
|
|
37
|
+
const fields = before && after ? fieldChanges(before, after, ["name", "type", "kind", "lanes", "features", "draft"]) : [];
|
|
38
|
+
const items = [mods, cons, msgs].flatMap((d) => Object.values(d.byId));
|
|
39
|
+
if (!after)
|
|
40
|
+
for (const x of items)
|
|
41
|
+
x.status = "deleted";
|
|
42
|
+
const counts = { added: 0, amended: 0, deleted: 0 };
|
|
43
|
+
for (const x of items)
|
|
44
|
+
if (x.status !== "same")
|
|
45
|
+
counts[x.status]++;
|
|
46
|
+
const status = !before ? "added" : !after ? "deleted" : counts.added + counts.amended + counts.deleted + fields.length ? "amended" : "same";
|
|
47
|
+
const merged = {
|
|
48
|
+
...base,
|
|
49
|
+
modules: mods.order,
|
|
50
|
+
connections: cons.order,
|
|
51
|
+
...(a.messages || b.messages ? { messages: msgs.order } : {}),
|
|
52
|
+
};
|
|
53
|
+
return { status, merged, modules: mods.byId, connections: cons.byId, messages: msgs.byId, fields, counts };
|
|
54
|
+
}
|
|
55
|
+
/** The Gap fields a reviewer reads, before and after. */
|
|
56
|
+
export function diffGap(before, after) {
|
|
57
|
+
if (!before)
|
|
58
|
+
return { status: "added", changed: [] };
|
|
59
|
+
if (!after)
|
|
60
|
+
return { status: "deleted", changed: [] };
|
|
61
|
+
const changed = fieldChanges(before, after, ["title", "intent", "state", "milestone", "module_ids", "view_id", "openspec_change"]);
|
|
62
|
+
return { status: changed.length ? "amended" : "same", changed };
|
|
63
|
+
}
|
|
64
|
+
/** Pins added and removed (a pin has no fields to amend). */
|
|
65
|
+
export function diffPins(before, after) {
|
|
66
|
+
const key = (p) => JSON.stringify(p);
|
|
67
|
+
const old = new Set(before.map(key));
|
|
68
|
+
const now = new Set(after.map(key));
|
|
69
|
+
return [
|
|
70
|
+
...after.filter((p) => !old.has(key(p))).map((pin) => ({ pin, status: "added" })),
|
|
71
|
+
...before.filter((p) => !now.has(key(p))).map((pin) => ({ pin, status: "deleted" })),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
/** A longest-common-subsequence diff; past `limit` cells it gives up and says "all replaced". */
|
|
75
|
+
export function diffSeq(a, b, same = (x, y) => x === y, limit = 4_000_000) {
|
|
76
|
+
let start = 0;
|
|
77
|
+
while (start < a.length && start < b.length && same(a[start], b[start]))
|
|
78
|
+
start++;
|
|
79
|
+
let endA = a.length;
|
|
80
|
+
let endB = b.length;
|
|
81
|
+
while (endA > start && endB > start && same(a[endA - 1], b[endB - 1]))
|
|
82
|
+
(endA--, endB--);
|
|
83
|
+
const head = a.slice(0, start).map((v) => ({ op: "same", v }));
|
|
84
|
+
const tail = a.slice(endA).map((v) => ({ op: "same", v }));
|
|
85
|
+
const A = a.slice(start, endA);
|
|
86
|
+
const B = b.slice(start, endB);
|
|
87
|
+
const n = A.length;
|
|
88
|
+
const m = B.length;
|
|
89
|
+
let mid;
|
|
90
|
+
if (n * m > limit) {
|
|
91
|
+
mid = [...A.map((v) => ({ op: "del", v })), ...B.map((v) => ({ op: "add", v }))];
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const L = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
|
95
|
+
for (let i = n - 1; i >= 0; i--)
|
|
96
|
+
for (let j = m - 1; j >= 0; j--)
|
|
97
|
+
L[i][j] = same(A[i], B[j]) ? L[i + 1][j + 1] + 1 : Math.max(L[i + 1][j], L[i][j + 1]);
|
|
98
|
+
mid = [];
|
|
99
|
+
let i = 0;
|
|
100
|
+
let j = 0;
|
|
101
|
+
while (i < n && j < m) {
|
|
102
|
+
if (same(A[i], B[j]))
|
|
103
|
+
(mid.push({ op: "same", v: A[i] }), i++, j++);
|
|
104
|
+
else if (L[i + 1][j] >= L[i][j + 1])
|
|
105
|
+
mid.push({ op: "del", v: A[i++] });
|
|
106
|
+
else
|
|
107
|
+
mid.push({ op: "add", v: B[j++] });
|
|
108
|
+
}
|
|
109
|
+
while (i < n)
|
|
110
|
+
mid.push({ op: "del", v: A[i++] });
|
|
111
|
+
while (j < m)
|
|
112
|
+
mid.push({ op: "add", v: B[j++] });
|
|
113
|
+
}
|
|
114
|
+
return [...head, ...mid, ...tail];
|
|
115
|
+
}
|
|
116
|
+
/** A line-by-line doc diff; a removed line followed by an added one is shown as one changed line. */
|
|
117
|
+
export function diffText(before, after) {
|
|
118
|
+
const lines = (s) => (s == null ? [] : s.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n"));
|
|
119
|
+
const ops = diffSeq(lines(before), lines(after));
|
|
120
|
+
const out = [];
|
|
121
|
+
for (let k = 0; k < ops.length;) {
|
|
122
|
+
if (ops[k].op === "same") {
|
|
123
|
+
out.push({ status: "same", text: ops[k].v });
|
|
124
|
+
k++;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const dels = [];
|
|
128
|
+
const adds = [];
|
|
129
|
+
while (k < ops.length && ops[k].op !== "same") {
|
|
130
|
+
const o = ops[k++];
|
|
131
|
+
(o.op === "del" ? dels : adds).push(o.v);
|
|
132
|
+
}
|
|
133
|
+
const pairs = Math.min(dels.length, adds.length);
|
|
134
|
+
for (let p = 0; p < pairs; p++)
|
|
135
|
+
out.push({ status: "amended", text: adds[p], spans: diffWords(dels[p], adds[p]) });
|
|
136
|
+
for (const t of dels.slice(pairs))
|
|
137
|
+
out.push({ status: "deleted", text: t });
|
|
138
|
+
for (const t of adds.slice(pairs))
|
|
139
|
+
out.push({ status: "added", text: t });
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
/** Word-level spans between two versions of a line (whitespace kept with the word before it). */
|
|
144
|
+
export function diffWords(before, after) {
|
|
145
|
+
const words = (s) => s.match(/\S+\s*|\s+/g) ?? [];
|
|
146
|
+
const spans = [];
|
|
147
|
+
for (const o of diffSeq(words(before), words(after))) {
|
|
148
|
+
const status = o.op === "same" ? "same" : o.op === "add" ? "added" : "deleted";
|
|
149
|
+
const last = spans[spans.length - 1];
|
|
150
|
+
if (last && last.status === status)
|
|
151
|
+
last.text += o.v;
|
|
152
|
+
else
|
|
153
|
+
spans.push({ status, text: o.v });
|
|
154
|
+
}
|
|
155
|
+
return spans;
|
|
156
|
+
}
|
package/dist/core/docs.js
CHANGED
|
@@ -5,6 +5,8 @@ import { slugId } from "./links.js";
|
|
|
5
5
|
import { flowToView, isFlowchart, parseFlowchart } from "./mermaid.js";
|
|
6
6
|
import { hasOpenSpec, listChanges, listSpecs } from "./openspec.js";
|
|
7
7
|
import { absPath, repoPath } from "./paths.js";
|
|
8
|
+
import { readDoc, resolveDocPath } from "./project.js";
|
|
9
|
+
import { realInside } from "./scope.js";
|
|
8
10
|
/** Doc folders: docs/ and openspec/ when they exist, plus any import_docs added. */
|
|
9
11
|
export const DEFAULT_SOURCES = ["docs", "openspec"];
|
|
10
12
|
const SKIP_DIRS = new Set(["node_modules", ".git", ".spatial", ".spatial-local", "dist"]);
|
|
@@ -67,10 +69,11 @@ export function mermaidBlocks(md) {
|
|
|
67
69
|
}
|
|
68
70
|
/** A draft View from the n-th Mermaid block of a doc. */
|
|
69
71
|
export async function draftViewFromDoc(spatial, path, index) {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
+
const doc = await resolveDocPath(spatial, path);
|
|
73
|
+
const rel = doc.rel;
|
|
74
|
+
const md = await readDoc(spatial, doc);
|
|
75
|
+
if (md === null)
|
|
72
76
|
throw new UserError(`cannot read ${rel}`);
|
|
73
|
-
});
|
|
74
77
|
const block = mermaidBlocks(md).find((b) => b.index === index);
|
|
75
78
|
if (!block)
|
|
76
79
|
throw new UserError(`${rel} has no Mermaid block ${index}`);
|
|
@@ -93,7 +96,10 @@ export async function draftViewFromDoc(spatial, path, index) {
|
|
|
93
96
|
* flowchart becomes a draft View (one per block; importing again keeps it).
|
|
94
97
|
*/
|
|
95
98
|
export async function importDocs(spatial, path, draftViews = false) {
|
|
99
|
+
if (spatial.mode === "home")
|
|
100
|
+
throw new UserError("in a project, docs are read where they are: scan_source the docs source, then pin each doc as <source_id>:<path>");
|
|
96
101
|
const rel = repoPath(spatial.root, path);
|
|
102
|
+
await realInside({ id: "repo", abs: spatial.root }, absPath(spatial.root, rel));
|
|
97
103
|
if (!(await isDir(join(spatial.root, rel))))
|
|
98
104
|
throw new UserError(`${rel} is not a folder`);
|
|
99
105
|
if (!DEFAULT_SOURCES.includes(rel) && rel !== ".")
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { commandLine } from "./launch.js";
|
|
4
|
+
import { configTargets } from "./setup.js";
|
|
5
|
+
import { VERSION } from "./version.js";
|
|
6
|
+
/** Every spatial-views entry in the IDE configs that exist. */
|
|
7
|
+
export async function findTargets(o) {
|
|
8
|
+
const out = [];
|
|
9
|
+
for (const t of o.ides.flatMap((ide) => configTargets(ide, o.home, o.windowsHome, o.wsl === true))) {
|
|
10
|
+
const { ide, file } = t;
|
|
11
|
+
if (!file)
|
|
12
|
+
continue;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(await readFile(file, "utf8"));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
for (const [name, entry] of Object.entries(data.mcpServers ?? {}))
|
|
21
|
+
if (name.startsWith("spatial-views") && entry && typeof entry.command === "string")
|
|
22
|
+
out.push({ ide, file, name, entry: { command: entry.command, args: Array.isArray(entry.args) ? entry.args : [], env: entry.env } });
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
function fixFor(entry, code, platform) {
|
|
27
|
+
const bare = /^npx(\.cmd)?$/i.test(entry.command);
|
|
28
|
+
if (platform === "win32" && (bare || code === "EINVAL"))
|
|
29
|
+
return 'npx is a .cmd on Windows: use "command": "cmd", "args": ["/c", "npx", ...] (spatial-views setup --force writes it)';
|
|
30
|
+
if (entry.command === "wsl" && platform !== "win32" && code === "EACCES")
|
|
31
|
+
return "this `wsl` entry is for a Windows IDE on a Windows folder; in WSL Remote mode use the `spatial-views` entry";
|
|
32
|
+
if (code === "ENOENT" || code === "EACCES")
|
|
33
|
+
return `${entry.command} was not found: write its absolute path (spatial-views setup --force)`;
|
|
34
|
+
return `run \`${commandLine(entry.command, entry.args)}\` in a terminal to see the error, then spatial-views setup --force`;
|
|
35
|
+
}
|
|
36
|
+
/** Stop the server, and on Windows what `cmd /c` started under it. */
|
|
37
|
+
function stop(pid, kill, platform) {
|
|
38
|
+
if (platform === "win32" && pid)
|
|
39
|
+
spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
40
|
+
else
|
|
41
|
+
kill();
|
|
42
|
+
}
|
|
43
|
+
/** Start one entry as written and run initialize, then tools/list. */
|
|
44
|
+
export async function checkEntry(entry, o = {}) {
|
|
45
|
+
if (!(o.wsl && entry.command === "wsl"))
|
|
46
|
+
return run(entry, entry.command, o);
|
|
47
|
+
// From inside WSL, a Windows `wsl` entry is what Windows would run: wsl.exe through interop.
|
|
48
|
+
for (const exe of ["wsl.exe", "/mnt/c/Windows/System32/wsl.exe"]) {
|
|
49
|
+
const r = await run(entry, exe, o);
|
|
50
|
+
if (!/ENOENT/.test(r.error ?? ""))
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
return { ok: false, skipped: true, error: "wsl.exe is not reachable from here (no WSL interop)", fix: "run `npx spatial-views doctor` in PowerShell to check it" };
|
|
54
|
+
}
|
|
55
|
+
function run(entry, command, o) {
|
|
56
|
+
const platform = o.platform ?? process.platform;
|
|
57
|
+
const timeoutMs = o.timeoutMs ?? 60_000;
|
|
58
|
+
return new Promise((done) => {
|
|
59
|
+
let settled = false;
|
|
60
|
+
let stderr = "";
|
|
61
|
+
let buf = "";
|
|
62
|
+
let child;
|
|
63
|
+
try {
|
|
64
|
+
child = spawn(command, entry.args, {
|
|
65
|
+
env: { ...process.env, ...(entry.env ?? {}) },
|
|
66
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
67
|
+
windowsHide: true,
|
|
68
|
+
shell: false,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
// Windows: a .cmd/.bat without a shell throws EINVAL here instead of emitting "error".
|
|
73
|
+
const e = err;
|
|
74
|
+
return done({ ok: false, error: `could not start ${command}: ${e.code ?? e.message}`, fix: fixFor(entry, e.code, platform) });
|
|
75
|
+
}
|
|
76
|
+
const finish = (r) => {
|
|
77
|
+
if (settled)
|
|
78
|
+
return;
|
|
79
|
+
settled = true;
|
|
80
|
+
clearTimeout(timer);
|
|
81
|
+
child.stdin?.end();
|
|
82
|
+
stop(child.pid, () => child.kill(), platform);
|
|
83
|
+
done(r);
|
|
84
|
+
};
|
|
85
|
+
const fail = (error, code) => finish({ ok: false, error, fix: fixFor(entry, code, platform) });
|
|
86
|
+
const timer = setTimeout(() => fail(`no answer in ${Math.round(timeoutMs / 1000)}s`), timeoutMs);
|
|
87
|
+
const send = (m) => child.stdin?.write(JSON.stringify(m) + "\n");
|
|
88
|
+
child.on("error", (e) => fail(`could not start ${command}: ${e.code ?? e.message}`, e.code));
|
|
89
|
+
child.stdin?.on("error", () => { });
|
|
90
|
+
child.stderr?.on("data", (d) => (stderr = (stderr + d.toString()).slice(-4000)));
|
|
91
|
+
child.on("exit", (code) => {
|
|
92
|
+
const last = stderr.trim().split(/\r?\n/).filter(Boolean).pop();
|
|
93
|
+
fail(`exited with code ${code}${last ? `: ${last}` : ""}`);
|
|
94
|
+
});
|
|
95
|
+
child.stdout?.on("data", (d) => {
|
|
96
|
+
buf += d.toString();
|
|
97
|
+
let nl;
|
|
98
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
99
|
+
const line = buf.slice(0, nl).trim();
|
|
100
|
+
buf = buf.slice(nl + 1);
|
|
101
|
+
if (!line.startsWith("{"))
|
|
102
|
+
continue;
|
|
103
|
+
let m;
|
|
104
|
+
try {
|
|
105
|
+
m = JSON.parse(line);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (m.error)
|
|
111
|
+
return fail(`the server said: ${m.error.message ?? "error"}`);
|
|
112
|
+
if (m.id === 1) {
|
|
113
|
+
send({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
114
|
+
send({ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} });
|
|
115
|
+
}
|
|
116
|
+
else if (m.id === 2) {
|
|
117
|
+
const n = m.result?.tools?.length ?? 0;
|
|
118
|
+
if (n > 0)
|
|
119
|
+
finish({ ok: true, tools: n });
|
|
120
|
+
else
|
|
121
|
+
fail("tools/list returned no tools");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
send({
|
|
126
|
+
jsonrpc: "2.0",
|
|
127
|
+
id: 1,
|
|
128
|
+
method: "initialize",
|
|
129
|
+
params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "spatial-views-doctor", version: VERSION } },
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
export async function doctor(o) {
|
|
134
|
+
const targets = await findTargets(o);
|
|
135
|
+
if (!targets.length)
|
|
136
|
+
return { ok: false, lines: ["FAIL no spatial-views entry in any IDE config. Fix: run `npx spatial-views setup`"] };
|
|
137
|
+
const lines = [];
|
|
138
|
+
let ok = true;
|
|
139
|
+
for (const t of targets) {
|
|
140
|
+
const r = await checkEntry(t.entry, o);
|
|
141
|
+
const where = `${t.ide} ${t.name} (${t.file})`;
|
|
142
|
+
if (r.ok)
|
|
143
|
+
lines.push(`OK ${where}: ${r.tools} tools`);
|
|
144
|
+
else if (r.skipped)
|
|
145
|
+
lines.push(`SKIP ${where}: ${r.error}`, ` ${r.fix}`);
|
|
146
|
+
else {
|
|
147
|
+
ok = false;
|
|
148
|
+
lines.push(`FAIL ${where}: ${r.error}`, ` fix: ${r.fix}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { ok, lines };
|
|
152
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse } from "yaml";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { UserError } from "./errors.js";
|
|
6
|
+
import { BUILTIN_DIR } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* A Project panel doc type (`toolboxes/types/docs/<id>.yaml`, or the project's
|
|
9
|
+
* `<data>/types/docs/<id>.yaml`, same id replaces): PRD, MDD, Gap, a plain doc.
|
|
10
|
+
* (The Docs toolbox's types, dropped on a module, are toolbox YAML: see types.ts.)
|
|
11
|
+
* A new doc is made from its markdown template ({{title}}, {{date}}) in its folder.
|
|
12
|
+
*/
|
|
13
|
+
export const DocTypeSchema = z.object({
|
|
14
|
+
id: z.string().regex(/^[a-z0-9][a-z0-9-]*$/),
|
|
15
|
+
name: z.string().min(1),
|
|
16
|
+
description: z.string().optional(),
|
|
17
|
+
icon: z.string().default("file-text"),
|
|
18
|
+
/** Where new docs of this type go, under the project (default docs). */
|
|
19
|
+
folder: z
|
|
20
|
+
.string()
|
|
21
|
+
.regex(/^[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/, "a folder is a relative path like docs or specs/prd")
|
|
22
|
+
.default("docs"),
|
|
23
|
+
/** The title a new doc gets until a person renames it. */
|
|
24
|
+
title: z.string().default("New doc"),
|
|
25
|
+
template: z.string().default("# {{title}}\n"),
|
|
26
|
+
});
|
|
27
|
+
export function parseDocType(text, id) {
|
|
28
|
+
const raw = (parse(text) ?? {});
|
|
29
|
+
return DocTypeSchema.parse({ ...raw, id: raw.id ?? id });
|
|
30
|
+
}
|
|
31
|
+
async function readDir(dir) {
|
|
32
|
+
const files = (await readdir(dir).catch(() => [])).filter((f) => /\.ya?ml$/.test(f)).sort();
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const f of files) {
|
|
35
|
+
try {
|
|
36
|
+
out.push(parseDocType(await readFile(join(dir, f), "utf8"), f.replace(/\.ya?ml$/, "")));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// A broken file is left out; the rest still load.
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** The order the built-in doc types are offered in. */
|
|
45
|
+
const ORDER = ["prd", "mdd", "gap", "plain"];
|
|
46
|
+
/** Every doc type: the built-in ones, then the project's (same id replaces). */
|
|
47
|
+
export async function loadDocTypes(dataDir, builtinDir = BUILTIN_DIR) {
|
|
48
|
+
const byId = new Map();
|
|
49
|
+
for (const t of await readDir(join(builtinDir, "types", "docs")))
|
|
50
|
+
byId.set(t.id, t);
|
|
51
|
+
if (dataDir)
|
|
52
|
+
for (const t of await readDir(join(dataDir, "types", "docs")))
|
|
53
|
+
byId.set(t.id, t);
|
|
54
|
+
const rank = (id) => (ORDER.includes(id) ? ORDER.indexOf(id) : ORDER.length);
|
|
55
|
+
return [...byId.values()].sort((a, b) => rank(a.id) - rank(b.id) || a.name.localeCompare(b.name));
|
|
56
|
+
}
|
|
57
|
+
export function findDocType(types, ref) {
|
|
58
|
+
const hit = types.find((t) => t.id === ref) ?? types.find((t) => t.name.toLowerCase() === ref.toLowerCase());
|
|
59
|
+
if (!hit)
|
|
60
|
+
throw new UserError(`no doc type "${ref}" (${types.map((t) => t.id).join(", ")})`);
|
|
61
|
+
return hit;
|
|
62
|
+
}
|
|
63
|
+
/** Fill a template's {{title}} and {{date}} (unknown names are left as they are). */
|
|
64
|
+
export function fillTemplate(template, vars) {
|
|
65
|
+
const values = { title: vars.title, date: vars.date ?? new Date().toISOString().slice(0, 10) };
|
|
66
|
+
return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, k) => values[k] ?? all);
|
|
67
|
+
}
|
|
68
|
+
/** A file or id name from a title: lower case, words joined by dashes. */
|
|
69
|
+
export function slugOf(title) {
|
|
70
|
+
return (title
|
|
71
|
+
.toLowerCase()
|
|
72
|
+
.normalize("NFKD")
|
|
73
|
+
.replace(/[^\w\s-]/g, "")
|
|
74
|
+
.trim()
|
|
75
|
+
.replace(/[\s_]+/g, "-")
|
|
76
|
+
.replace(/-+/g, "-")
|
|
77
|
+
.slice(0, 60)
|
|
78
|
+
.replace(/^-|-$/g, "") || "untitled");
|
|
79
|
+
}
|
package/dist/core/edit.js
CHANGED
|
@@ -35,6 +35,8 @@ export function addModule(view, input) {
|
|
|
35
35
|
x: input.x ?? slot.x,
|
|
36
36
|
y: input.y ?? slot.y,
|
|
37
37
|
...(input.description ? { description: input.description } : {}),
|
|
38
|
+
...(input.type ? { type: input.type } : {}),
|
|
39
|
+
...(input.properties && Object.keys(input.properties).length ? { properties: input.properties } : {}),
|
|
38
40
|
};
|
|
39
41
|
return { view: { ...view, modules: [...view.modules, module] }, module };
|
|
40
42
|
}
|
|
@@ -55,6 +57,16 @@ function withModule(view, ref, change) {
|
|
|
55
57
|
export function moveModule(view, ref, x, y) {
|
|
56
58
|
return withModule(view, ref, (m) => ({ ...m, x: Math.round(x), y: Math.round(y) }));
|
|
57
59
|
}
|
|
60
|
+
/** A name not yet used on the View: "Database", then "Database 2", "Database 3". */
|
|
61
|
+
export function uniqueName(view, base) {
|
|
62
|
+
const names = new Set(view.modules.map((m) => m.name.toLowerCase()));
|
|
63
|
+
if (!names.has(base.toLowerCase()))
|
|
64
|
+
return base;
|
|
65
|
+
let n = 2;
|
|
66
|
+
while (names.has(`${base} ${n}`.toLowerCase()))
|
|
67
|
+
n++;
|
|
68
|
+
return `${base} ${n}`;
|
|
69
|
+
}
|
|
58
70
|
export function updateModule(view, ref, patch) {
|
|
59
71
|
return withModule(view, ref, (m) => {
|
|
60
72
|
const next = { ...m };
|
|
@@ -69,6 +81,18 @@ export function updateModule(view, ref, patch) {
|
|
|
69
81
|
else
|
|
70
82
|
delete next.description;
|
|
71
83
|
}
|
|
84
|
+
if (patch.type !== undefined) {
|
|
85
|
+
if (patch.type)
|
|
86
|
+
next.type = patch.type;
|
|
87
|
+
else
|
|
88
|
+
delete next.type;
|
|
89
|
+
}
|
|
90
|
+
if (patch.properties !== undefined) {
|
|
91
|
+
if (patch.properties && Object.keys(patch.properties).length)
|
|
92
|
+
next.properties = patch.properties;
|
|
93
|
+
else
|
|
94
|
+
delete next.properties;
|
|
95
|
+
}
|
|
72
96
|
return next;
|
|
73
97
|
});
|
|
74
98
|
}
|
|
@@ -81,6 +105,7 @@ export function removeModule(view, ref) {
|
|
|
81
105
|
modules: view.modules.filter((m) => m.id !== target.id),
|
|
82
106
|
connections: view.connections.filter((c) => c.from !== target.id && c.to !== target.id),
|
|
83
107
|
...(features ? { features } : {}),
|
|
108
|
+
...(view.messages ? { messages: view.messages.filter((m) => m.from !== target.id && m.to !== target.id) } : {}),
|
|
84
109
|
};
|
|
85
110
|
}
|
|
86
111
|
export function removeConnection(view, id) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experimental features: Gaps, Features (the lasso's Make Gap and Make
|
|
3
|
+
* Feature) and the work-split steps in the Skills. They stay in the code but
|
|
4
|
+
* are hidden unless SPATIAL_VIEWS_EXPERIMENTAL=1 (Direction, 22 Nov 2026: the
|
|
5
|
+
* free version is Docs and Diagrams). Swim lanes are not experimental: they
|
|
6
|
+
* stay in the product (Settings: Lanes on this View), just not in the demo or
|
|
7
|
+
* the default pre-audit.
|
|
8
|
+
*/
|
|
9
|
+
export const EXPERIMENTAL_ENV = "SPATIAL_VIEWS_EXPERIMENTAL";
|
|
10
|
+
export function experimental(env = process.env) {
|
|
11
|
+
return env[EXPERIMENTAL_ENV] === "1";
|
|
12
|
+
}
|
|
13
|
+
export const flags = (env = process.env) => ({ experimental: experimental(env) });
|
package/dist/core/gaps.js
CHANGED
|
@@ -28,7 +28,7 @@ export async function createGap(spatial, input) {
|
|
|
28
28
|
if (input.modules.length === 0)
|
|
29
29
|
throw new UserError("select at least one module for the Gap");
|
|
30
30
|
const modules = [...new Map(input.modules.map((r) => findModule(view, r)).map((m) => [m.id, m])).values()];
|
|
31
|
-
const withSpec = input.openspec ?? (await hasOpenSpec(spatial.root));
|
|
31
|
+
const withSpec = input.openspec ?? (input.draft ? false : await hasOpenSpec(spatial.root));
|
|
32
32
|
const taken = [
|
|
33
33
|
...(await spatial.gaps.all()).map((g) => g.id),
|
|
34
34
|
...(withSpec ? (await listChanges(spatial.root)).map((c) => c.id) : []),
|
|
@@ -42,6 +42,7 @@ export async function createGap(spatial, input) {
|
|
|
42
42
|
module_ids: modules.map((m) => m.id),
|
|
43
43
|
state: "open",
|
|
44
44
|
...(input.milestone ? { milestone: input.milestone } : {}),
|
|
45
|
+
...(input.draft ? { draft: true } : {}),
|
|
45
46
|
};
|
|
46
47
|
if (withSpec) {
|
|
47
48
|
const path = await createChange(spatial.root, {
|
|
@@ -50,7 +51,7 @@ export async function createGap(spatial, input) {
|
|
|
50
51
|
intent: gap.intent,
|
|
51
52
|
view: view.name,
|
|
52
53
|
modules: modules.map((m) => m.name),
|
|
53
|
-
});
|
|
54
|
+
}, (rel, text) => spatial.docs.write(rel, text));
|
|
54
55
|
gap.openspec_change = id;
|
|
55
56
|
await spatial.pins.add({ path, kind: "gap", gap_id: id });
|
|
56
57
|
}
|
|
@@ -104,6 +105,10 @@ export async function updateGap(spatial, ref, patch) {
|
|
|
104
105
|
}
|
|
105
106
|
if (patch.state !== undefined)
|
|
106
107
|
next.state = patch.state;
|
|
108
|
+
if (patch.draft === false)
|
|
109
|
+
delete next.draft;
|
|
110
|
+
else if (patch.draft === true)
|
|
111
|
+
next.draft = true;
|
|
107
112
|
// A Gap with a change can't be marked done before the change is archived.
|
|
108
113
|
if (patch.state === "done" && gap.openspec_change) {
|
|
109
114
|
const c = await findChange(spatial.root, gap.openspec_change);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** A doc with its first `# heading` set to `title` (added at the top when it has none). Pure: the server and the editor share it. */
|
|
2
|
+
export function withTitle(text, title) {
|
|
3
|
+
return /^#\s+.*$/m.test(text) ? text.replace(/^#\s+.*$/m, `# ${title}`) : `# ${title}\n\n${text}`;
|
|
4
|
+
}
|
package/dist/core/history.js
CHANGED
|
@@ -1,19 +1,50 @@
|
|
|
1
|
-
/** A bounded undo stack of
|
|
1
|
+
/** A bounded undo stack of steps, with redo (the canvas keeps one). */
|
|
2
2
|
export class UndoStack {
|
|
3
3
|
limit;
|
|
4
4
|
items = [];
|
|
5
|
+
redos = [];
|
|
5
6
|
constructor(limit = 50) {
|
|
6
7
|
this.limit = limit;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
this.items.push(
|
|
9
|
+
keep(x) {
|
|
10
|
+
this.items.push(x);
|
|
10
11
|
if (this.items.length > this.limit)
|
|
11
12
|
this.items.shift();
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
/** A new change: keep what was there before it (or the step itself). Redo is cleared. */
|
|
15
|
+
push(before) {
|
|
16
|
+
this.keep(before);
|
|
17
|
+
this.redos = [];
|
|
18
|
+
}
|
|
19
|
+
/** Step back: the snapshot to restore. `current` (if given) can be redone. */
|
|
20
|
+
pop(current) {
|
|
21
|
+
const before = this.items.pop();
|
|
22
|
+
if (before !== undefined && current !== undefined)
|
|
23
|
+
this.redos.push(current);
|
|
24
|
+
return before;
|
|
25
|
+
}
|
|
26
|
+
/** Step forward again after an undo: the snapshot to restore. `current` goes back on the undo stack. */
|
|
27
|
+
redo(current) {
|
|
28
|
+
const next = this.redos.pop();
|
|
29
|
+
if (next !== undefined)
|
|
30
|
+
this.keep(current);
|
|
31
|
+
return next;
|
|
32
|
+
}
|
|
33
|
+
/** For steps that are their own inverse (a pin): put one on the redo stack, or take one off it. */
|
|
34
|
+
pushRedo(step) {
|
|
35
|
+
this.redos.push(step);
|
|
36
|
+
}
|
|
37
|
+
popRedo() {
|
|
38
|
+
return this.redos.pop();
|
|
39
|
+
}
|
|
40
|
+
/** Back on the undo stack after a redo, without clearing redo. */
|
|
41
|
+
pushBack(step) {
|
|
42
|
+
this.keep(step);
|
|
15
43
|
}
|
|
16
44
|
get size() {
|
|
17
45
|
return this.items.length;
|
|
18
46
|
}
|
|
47
|
+
get redoSize() {
|
|
48
|
+
return this.redos.length;
|
|
49
|
+
}
|
|
19
50
|
}
|