spatial-views 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +63 -2
- package/dist/app/assets/abnfDiagram-S7VZAUFO-BVgtb0Hw.js +1 -0
- package/dist/app/assets/architecture-WOLXFQ4H-DxylGHqT.js +1 -0
- package/dist/app/assets/architectureDiagram-YGSQEFNW-BrBCHqUH.js +36 -0
- package/dist/app/assets/blockDiagram-APKKGZFW-C7fb3MCE.js +140 -0
- package/dist/app/assets/bpmnIcons-APHXDYXF-C0jbCElo.js +1 -0
- package/dist/app/assets/c4Diagram-KJ2TOQU5-Bkb_0fbd.js +38 -0
- package/dist/app/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/dist/app/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/dist/app/assets/chunk-6MUBBAK2-DU4vZ03M.js +2 -0
- package/dist/app/assets/chunk-AXFCVDMN-De96BVTB.js +62 -0
- package/dist/app/assets/chunk-BG4553SI-J33jsRLV.js +127 -0
- package/dist/app/assets/chunk-DQASFODM-Bh85SSGO.js +10 -0
- package/dist/app/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/dist/app/assets/chunk-HFQBQIA3-CCklgplR.js +1 -0
- package/dist/app/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
- package/dist/app/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/dist/app/assets/chunk-KQLB2F66-B04qR8ED.js +2 -0
- package/dist/app/assets/chunk-KS47KZWR-BsqDyyAt.js +1 -0
- package/dist/app/assets/chunk-LEVMRMFU-DwxrBz2u.js +1 -0
- package/dist/app/assets/chunk-M57EVK23-D9YIHjps.js +1 -0
- package/dist/app/assets/chunk-NGNAAXSQ-DI_UYJZ4.js +136 -0
- package/dist/app/assets/chunk-OY52VR5R-WB63DeTA.js +88 -0
- package/dist/app/assets/chunk-QB3YPZ4I-cHzzKdtb.js +213 -0
- package/dist/app/assets/chunk-R3KSYZAL-C7rDagaa.js +1 -0
- package/dist/app/assets/chunk-STOXU5M4-CG6pnJtH.js +72 -0
- package/dist/app/assets/chunk-TU62E6Q5-BbcGYfy_.js +1 -0
- package/dist/app/assets/chunk-X3CZISLH-FMl4PpWt.js +1 -0
- package/dist/app/assets/chunk-X4PVCEUW-BUI1Oi3q.js +1 -0
- package/dist/app/assets/chunk-XXDRQBXY-DYhK5YW-.js +1 -0
- package/dist/app/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/dist/app/assets/classDiagram-v2-L25IHNXF-K-k5GTUn.js +217 -0
- package/dist/app/assets/cose-bilkent-JH36ORCC-BJmLLpaN.js +1 -0
- package/dist/app/assets/cynefin-EF2NZ3EQ-DrzwMKdm.js +1 -0
- package/dist/app/assets/cynefinDiagram-L36ESFBY-mkV33_Xx.js +62 -0
- package/dist/app/assets/cytoscape.esm-nTrd5EVq.js +321 -0
- package/dist/app/assets/d3-scale-ygdFCUH8.js +1 -0
- package/dist/app/assets/dagre-SPEB5RXH-BNIymLsu.js +4 -0
- package/dist/app/assets/diagram-3B7GL73J-CGOiolFW.js +200 -0
- package/dist/app/assets/diagram-DNEMPZML-DZFkHNly.js +24 -0
- package/dist/app/assets/diagram-L3MUGCDN-B42GAYLq.js +41 -0
- package/dist/app/assets/diagram-LA4NIPWU-BYuLRYId.js +24 -0
- package/dist/app/assets/diagram-MHCOC4E2-DGzI6TJG.js +3 -0
- package/dist/app/assets/diagram-XPFHEONP-CTBEgDQ8.js +30 -0
- package/dist/app/assets/dist-1Q8ng3tu.js +1 -0
- package/dist/app/assets/ebnfDiagram-UZSYDL2S-GuMdOCvL.js +1 -0
- package/dist/app/assets/elk-XV6XMXQE-BpY3loT5.js +2 -0
- package/dist/app/assets/erDiagram-EYBAPDEH-nDZ2PMGl.js +99 -0
- package/dist/app/assets/eventmodeling-K75KTNOO-BN42Mgwh.js +1 -0
- package/dist/app/assets/flowDiagram-MALGAFMO-BCwwiLzb.js +1 -0
- package/dist/app/assets/ganttDiagram-23REXITY-xMRHaU3y.js +292 -0
- package/dist/app/assets/gitGraph-VSP46ZUC-DyGq5mdd.js +1 -0
- package/dist/app/assets/gitGraphDiagram-STJD7YCW-CDkKLrvO.js +106 -0
- package/dist/app/assets/graphlib-DS17s2tU.js +1 -0
- package/dist/app/assets/index-BY66fc8Q.js +95 -0
- package/dist/app/assets/index-ByetEVbs.css +1 -0
- package/dist/app/assets/info-OHQRW6UA-DOBf-fQH.js +1 -0
- package/dist/app/assets/infoDiagram-KBXO4MBG-B92P8pjY.js +2 -0
- package/dist/app/assets/ishikawaDiagram-M35NCXHK-BRZsbCvK.js +70 -0
- package/dist/app/assets/journeyDiagram-OPLOXDXO-Bppwb1oF.js +139 -0
- package/dist/app/assets/kanban-definition-BZKZHSQY-ByD_x5cm.js +89 -0
- package/dist/app/assets/katex-MEuSR36T.js +257 -0
- package/dist/app/assets/mermaid-parser.core-CKmnV0Md.js +7 -0
- package/dist/app/assets/mermaid.core-BoRvk1Q-.js +44 -0
- package/dist/app/assets/mindmap-definition-I2QAS2VK-fRbUh23C.js +98 -0
- package/dist/app/assets/packet-JDAUHWVQ-CgHq03Zj.js +1 -0
- package/dist/app/assets/pegDiagram-FD4XPPHP-qIABf6H8.js +1 -0
- package/dist/app/assets/pie-XZMESJXO-DtNh3cDE.js +1 -0
- package/dist/app/assets/pieDiagram-J4AKIIQI-Bb4RBdrc.js +39 -0
- package/dist/app/assets/quadrantDiagram-XTYBLID2-B0CpcVWE.js +7 -0
- package/dist/app/assets/radar-ABXABTNO-BS0FcsIX.js +1 -0
- package/dist/app/assets/railroad-I3PHUGI6-lO8vfGdI.js +1 -0
- package/dist/app/assets/railroad-abnf-LNEFI6M7-BUhw7Iuo.js +1 -0
- package/dist/app/assets/railroad-ebnf-DWYD2UWJ-nQNF56LJ.js +1 -0
- package/dist/app/assets/railroad-peg-JR7BVNR7-CwvbVIo6.js +1 -0
- package/dist/app/assets/railroadDiagram-MRQ6NCDL-Dwr-mPZL.js +1 -0
- package/dist/app/assets/requirementDiagram-Y7LWUY3S-Ctv2DKJM.js +84 -0
- package/dist/app/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/dist/app/assets/sankeyDiagram-WGJFYUXA-BvKX0eIe.js +40 -0
- package/dist/app/assets/sequenceDiagram-5NDRBG5M-Y4YqU2Xt.js +169 -0
- package/dist/app/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
- package/dist/app/assets/stateDiagram-v2-FJ4FJNEA-DmjIjn4u.js +291 -0
- package/dist/app/assets/swimlanes-UMQ2AFYF-B2O5JCjs.js +1 -0
- package/dist/app/assets/swimlanesDiagram-OMPLPG4O-DhCl-Cjg.js +8 -0
- package/dist/app/assets/timeline-definition-SEUHKTQE-DJJdixAI.js +120 -0
- package/dist/app/assets/treeView-D4JQ5SDB-Dd1no4eE.js +1 -0
- package/dist/app/assets/treemap-SAJKECNS-t6wtsaki.js +1 -0
- package/dist/app/assets/usecaseDiagram-AFA6YXN4-Bp8pXgvR.js +328 -0
- package/dist/app/assets/vennDiagram-NNMJR3RB-DYSfZMWT.js +34 -0
- package/dist/app/assets/wardley-7MLQ67FV-Bx60QTuu.js +1 -0
- package/dist/app/assets/wardleyDiagram-S7YFUSEH-CGJ8qg76.js +78 -0
- package/dist/app/assets/xychartDiagram-GGNKY7IX-CRSvraFc.js +7 -0
- package/dist/app/index.html +13 -0
- package/dist/cli/index.js +110 -0
- package/dist/core/api.js +209 -0
- package/dist/core/context.js +194 -0
- package/dist/core/docs.js +134 -0
- package/dist/core/edit.js +105 -0
- package/dist/core/errors.js +3 -0
- package/dist/core/gaps.js +114 -0
- package/dist/core/history.js +19 -0
- package/dist/core/links.js +68 -0
- package/dist/core/mermaid.js +175 -0
- package/dist/core/openspec.js +120 -0
- package/dist/core/paths.js +23 -0
- package/dist/core/resolve.js +35 -0
- package/dist/core/schema.js +101 -0
- package/dist/core/skills.js +103 -0
- package/dist/core/storage.js +183 -0
- package/dist/core/version.js +1 -0
- package/dist/core/watch.js +136 -0
- package/dist/core/xml.js +50 -0
- package/dist/mcp/server.js +357 -0
- package/package.json +53 -4
- package/schema/gap.schema.json +53 -0
- package/schema/pins.schema.json +122 -0
- package/schema/view.schema.json +134 -0
- package/skills/claude/build-gap/SKILL.md +21 -0
- package/skills/claude/draw-system/SKILL.md +23 -0
- package/skills/claude/gap-from-view/SKILL.md +22 -0
- package/skills/cursor/build-gap.mdc +21 -0
- package/skills/cursor/draw-system.mdc +23 -0
- package/skills/cursor/gap-from-view.mdc +22 -0
- package/skills/windsurf/spatial-views.md +66 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { findModule } from "./edit.js";
|
|
2
|
+
import { UserError } from "./errors.js";
|
|
3
|
+
import { slugId } from "./links.js";
|
|
4
|
+
import { changeState, createChange, findChange, gapStateFor, hasOpenSpec, listChanges } from "./openspec.js";
|
|
5
|
+
import { resolveView } from "./resolve.js";
|
|
6
|
+
/** A Gap by id, or else by title (case-insensitive). */
|
|
7
|
+
export function resolveGap(gaps, ref) {
|
|
8
|
+
const byId = gaps.find((g) => g.id === ref);
|
|
9
|
+
if (byId)
|
|
10
|
+
return byId;
|
|
11
|
+
const byTitle = gaps.filter((g) => g.title.toLowerCase() === ref.toLowerCase());
|
|
12
|
+
if (byTitle.length === 1)
|
|
13
|
+
return byTitle[0];
|
|
14
|
+
if (byTitle.length > 1)
|
|
15
|
+
throw new UserError(`more than one Gap is titled "${ref}"; use the id`);
|
|
16
|
+
throw new UserError(`no Gap "${ref}"`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A Gap from selected modules. With OpenSpec, the change folder is created
|
|
20
|
+
* (openspec/changes/<id>/) and pinned to the Gap, and the Gap follows it.
|
|
21
|
+
*/
|
|
22
|
+
export async function createGap(spatial, input) {
|
|
23
|
+
const title = input.title.trim();
|
|
24
|
+
if (!title)
|
|
25
|
+
throw new UserError("a Gap needs a title");
|
|
26
|
+
const views = await spatial.views.listViews();
|
|
27
|
+
const view = resolveView(views, input.view);
|
|
28
|
+
if (input.modules.length === 0)
|
|
29
|
+
throw new UserError("select at least one module for the Gap");
|
|
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));
|
|
32
|
+
const taken = [
|
|
33
|
+
...(await spatial.gaps.all()).map((g) => g.id),
|
|
34
|
+
...(withSpec ? (await listChanges(spatial.root)).map((c) => c.id) : []),
|
|
35
|
+
];
|
|
36
|
+
const id = slugId(title, taken);
|
|
37
|
+
const gap = {
|
|
38
|
+
id,
|
|
39
|
+
title,
|
|
40
|
+
intent: input.intent?.trim() ?? "",
|
|
41
|
+
view_id: view.id,
|
|
42
|
+
module_ids: modules.map((m) => m.id),
|
|
43
|
+
state: "open",
|
|
44
|
+
...(input.milestone ? { milestone: input.milestone } : {}),
|
|
45
|
+
};
|
|
46
|
+
if (withSpec) {
|
|
47
|
+
const path = await createChange(spatial.root, {
|
|
48
|
+
id,
|
|
49
|
+
title,
|
|
50
|
+
intent: gap.intent,
|
|
51
|
+
view: view.name,
|
|
52
|
+
modules: modules.map((m) => m.name),
|
|
53
|
+
});
|
|
54
|
+
gap.openspec_change = id;
|
|
55
|
+
await spatial.pins.add({ path, kind: "gap", gap_id: id });
|
|
56
|
+
}
|
|
57
|
+
return spatial.gaps.save(gap);
|
|
58
|
+
}
|
|
59
|
+
/** Bring a Gap's state in line with its OpenSpec change, and save it if that moved it. */
|
|
60
|
+
export async function syncGap(spatial, gap) {
|
|
61
|
+
if (!gap.openspec_change)
|
|
62
|
+
return gap;
|
|
63
|
+
const state = gapStateFor(await changeState(spatial.root, gap.openspec_change), gap.state);
|
|
64
|
+
if (state === gap.state)
|
|
65
|
+
return gap;
|
|
66
|
+
return spatial.gaps.save({ ...gap, state });
|
|
67
|
+
}
|
|
68
|
+
export async function listGaps(spatial, filter = {}) {
|
|
69
|
+
const viewId = filter.view ? resolveView(await spatial.views.listViews(), filter.view).id : undefined;
|
|
70
|
+
const out = [];
|
|
71
|
+
for (const g of await spatial.gaps.all()) {
|
|
72
|
+
const gap = await syncGap(spatial, g);
|
|
73
|
+
if (viewId && gap.view_id !== viewId)
|
|
74
|
+
continue;
|
|
75
|
+
if (filter.state && gap.state !== filter.state)
|
|
76
|
+
continue;
|
|
77
|
+
if (filter.milestone !== undefined && (gap.milestone ?? "") !== filter.milestone)
|
|
78
|
+
continue;
|
|
79
|
+
out.push(gap);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
export async function updateGap(spatial, ref, patch) {
|
|
84
|
+
const gap = resolveGap(await spatial.gaps.all(), ref);
|
|
85
|
+
const next = { ...gap };
|
|
86
|
+
if (patch.title !== undefined) {
|
|
87
|
+
if (!patch.title.trim())
|
|
88
|
+
throw new UserError("a Gap needs a title");
|
|
89
|
+
next.title = patch.title.trim();
|
|
90
|
+
}
|
|
91
|
+
if (patch.intent !== undefined)
|
|
92
|
+
next.intent = patch.intent;
|
|
93
|
+
if (patch.milestone !== undefined) {
|
|
94
|
+
if (patch.milestone)
|
|
95
|
+
next.milestone = patch.milestone;
|
|
96
|
+
else
|
|
97
|
+
delete next.milestone;
|
|
98
|
+
}
|
|
99
|
+
if (patch.modules !== undefined) {
|
|
100
|
+
const view = await spatial.views.get(gap.view_id);
|
|
101
|
+
if (patch.modules.length === 0)
|
|
102
|
+
throw new UserError("a Gap needs at least one module");
|
|
103
|
+
next.module_ids = [...new Set(patch.modules.map((r) => findModule(view, r).id))];
|
|
104
|
+
}
|
|
105
|
+
if (patch.state !== undefined)
|
|
106
|
+
next.state = patch.state;
|
|
107
|
+
// A Gap with a change can't be marked done before the change is archived.
|
|
108
|
+
if (patch.state === "done" && gap.openspec_change) {
|
|
109
|
+
const c = await findChange(spatial.root, gap.openspec_change);
|
|
110
|
+
if (c && !c.archived)
|
|
111
|
+
throw new UserError(`archive the OpenSpec change ${gap.openspec_change} first (openspec archive ${gap.openspec_change})`);
|
|
112
|
+
}
|
|
113
|
+
return spatial.gaps.save(next);
|
|
114
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A bounded undo stack of snapshots (the canvas keeps one per View). */
|
|
2
|
+
export class UndoStack {
|
|
3
|
+
limit;
|
|
4
|
+
items = [];
|
|
5
|
+
constructor(limit = 50) {
|
|
6
|
+
this.limit = limit;
|
|
7
|
+
}
|
|
8
|
+
push(before) {
|
|
9
|
+
this.items.push(before);
|
|
10
|
+
if (this.items.length > this.limit)
|
|
11
|
+
this.items.shift();
|
|
12
|
+
}
|
|
13
|
+
pop() {
|
|
14
|
+
return this.items.pop();
|
|
15
|
+
}
|
|
16
|
+
get size() {
|
|
17
|
+
return this.items.length;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { UserError } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Module to sub-view links: pure functions shared by the canvas, the HTTP API
|
|
4
|
+
* and the MCP tools. Every change returns a new View; nothing is mutated, so
|
|
5
|
+
* the canvas can keep the previous View for undo.
|
|
6
|
+
*/
|
|
7
|
+
export class LinkError extends UserError {
|
|
8
|
+
}
|
|
9
|
+
function findModule(view, moduleId) {
|
|
10
|
+
const mod = view.modules.find((m) => m.id === moduleId);
|
|
11
|
+
if (!mod)
|
|
12
|
+
throw new LinkError(`module ${moduleId} is not in View ${view.id}`);
|
|
13
|
+
return mod;
|
|
14
|
+
}
|
|
15
|
+
function withModule(view, moduleId, change) {
|
|
16
|
+
findModule(view, moduleId);
|
|
17
|
+
return { ...view, modules: view.modules.map((m) => (m.id === moduleId ? change(m) : m)) };
|
|
18
|
+
}
|
|
19
|
+
/** Link a module to a View. Linking again changes the link. */
|
|
20
|
+
export function linkModule(view, moduleId, targetViewId) {
|
|
21
|
+
if (!targetViewId)
|
|
22
|
+
throw new LinkError("a link needs a target View id");
|
|
23
|
+
if (targetViewId === view.id)
|
|
24
|
+
throw new LinkError("a module cannot link to its own View");
|
|
25
|
+
return withModule(view, moduleId, (m) => ({ ...m, linked_view_id: targetViewId }));
|
|
26
|
+
}
|
|
27
|
+
/** Remove a module's link. Removing a link that isn't there is a no-op. */
|
|
28
|
+
export function unlinkModule(view, moduleId) {
|
|
29
|
+
return withModule(view, moduleId, ({ linked_view_id: _drop, ...rest }) => rest);
|
|
30
|
+
}
|
|
31
|
+
/** Is the module linked, and does its target still exist? */
|
|
32
|
+
export function linkState(mod, views) {
|
|
33
|
+
if (!mod.linked_view_id)
|
|
34
|
+
return { kind: "none" };
|
|
35
|
+
const target = views.find((v) => v.id === mod.linked_view_id);
|
|
36
|
+
return target ? { kind: "linked", view: target } : { kind: "missing", view_id: mod.linked_view_id };
|
|
37
|
+
}
|
|
38
|
+
/** A file-safe id from a name, unique among `taken`. */
|
|
39
|
+
export function slugId(name, taken) {
|
|
40
|
+
const base = name
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
43
|
+
.replace(/^-+|-+$/g, "")
|
|
44
|
+
.slice(0, 48) || "view";
|
|
45
|
+
let id = base;
|
|
46
|
+
for (let n = 2; taken.includes(id); n++)
|
|
47
|
+
id = `${base}-${n}`;
|
|
48
|
+
return id;
|
|
49
|
+
}
|
|
50
|
+
/** "+ New sub-view": an empty View named after the module, and the parent linked to it. */
|
|
51
|
+
export function newSubView(parent, moduleId, takenIds) {
|
|
52
|
+
const mod = findModule(parent, moduleId);
|
|
53
|
+
const child = {
|
|
54
|
+
id: slugId(mod.name, [...takenIds, parent.id]),
|
|
55
|
+
name: mod.name,
|
|
56
|
+
type: "sub-view",
|
|
57
|
+
modules: [],
|
|
58
|
+
connections: [],
|
|
59
|
+
};
|
|
60
|
+
return { parent: linkModule(parent, moduleId, child.id), child };
|
|
61
|
+
}
|
|
62
|
+
/** Case-insensitive search for the View picker, current View left out. */
|
|
63
|
+
export function filterViews(views, query, excludeId) {
|
|
64
|
+
const q = query.trim().toLowerCase();
|
|
65
|
+
return views
|
|
66
|
+
.filter((v) => v.id !== excludeId)
|
|
67
|
+
.filter((v) => !q || v.name.toLowerCase().includes(q) || v.id.toLowerCase().includes(q));
|
|
68
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
const SKIP = /^(subgraph|end|classDef|class|style|linkStyle|click|direction|%%)\b/;
|
|
2
|
+
// Longest openers first, so `((x))` isn't read as `(` ... `)`.
|
|
3
|
+
const SHAPES = [
|
|
4
|
+
["(((", ")))"],
|
|
5
|
+
["((", "))"],
|
|
6
|
+
["([", "])"],
|
|
7
|
+
["[[", "]]"],
|
|
8
|
+
["[(", ")]"],
|
|
9
|
+
["{{", "}}"],
|
|
10
|
+
["[/", "]"],
|
|
11
|
+
["[\\", "]"],
|
|
12
|
+
["[", "]"],
|
|
13
|
+
["(", ")"],
|
|
14
|
+
["{", "}"],
|
|
15
|
+
[">", "]"],
|
|
16
|
+
];
|
|
17
|
+
const unquote = (s) => s.trim().replace(/^"(.*)"$/s, "$1").replace(/[/\\]$/, "").trim();
|
|
18
|
+
function ws(c) {
|
|
19
|
+
while (c.i < c.s.length && /\s/.test(c.s[c.i]))
|
|
20
|
+
c.i++;
|
|
21
|
+
}
|
|
22
|
+
function readNode(c, labels) {
|
|
23
|
+
ws(c);
|
|
24
|
+
const m = /^[\w$]+/.exec(c.s.slice(c.i));
|
|
25
|
+
if (!m)
|
|
26
|
+
return null;
|
|
27
|
+
const id = m[0];
|
|
28
|
+
c.i += id.length;
|
|
29
|
+
for (const [open, close] of SHAPES) {
|
|
30
|
+
if (!c.s.startsWith(open, c.i))
|
|
31
|
+
continue;
|
|
32
|
+
const end = c.s.indexOf(close, c.i + open.length);
|
|
33
|
+
if (end < 0)
|
|
34
|
+
return null;
|
|
35
|
+
labels.set(id, unquote(c.s.slice(c.i + open.length, end)));
|
|
36
|
+
c.i = end + close.length;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
const cls = /^:::[\w-]+/.exec(c.s.slice(c.i));
|
|
40
|
+
if (cls)
|
|
41
|
+
c.i += cls[0].length;
|
|
42
|
+
if (!labels.has(id))
|
|
43
|
+
labels.set(id, "");
|
|
44
|
+
return id;
|
|
45
|
+
}
|
|
46
|
+
function readGroup(c, labels) {
|
|
47
|
+
const first = readNode(c, labels);
|
|
48
|
+
if (!first)
|
|
49
|
+
return null;
|
|
50
|
+
const ids = [first];
|
|
51
|
+
for (;;) {
|
|
52
|
+
const save = c.i;
|
|
53
|
+
ws(c);
|
|
54
|
+
if (c.s[c.i] !== "&")
|
|
55
|
+
return (c.i = save), ids;
|
|
56
|
+
c.i++;
|
|
57
|
+
const next = readNode(c, labels);
|
|
58
|
+
if (!next)
|
|
59
|
+
return null;
|
|
60
|
+
ids.push(next);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** An edge at the cursor; returns its label ("" for none), or null if there is no edge. */
|
|
64
|
+
function readEdge(c) {
|
|
65
|
+
const rest = c.s.slice(c.i);
|
|
66
|
+
// A -- text --> B, A -. text .-> B, A == text ==> B
|
|
67
|
+
const texted = /^\s*[<ox]?(--|==|-\.)\s+(.+?)\s+(-{2,}[>ox]|={2,}[>ox]|\.-[>ox]?|-{3,}|={3,})/.exec(rest);
|
|
68
|
+
if (texted) {
|
|
69
|
+
c.i += texted[0].length;
|
|
70
|
+
return unquote(texted[2]);
|
|
71
|
+
}
|
|
72
|
+
const piped = /^\s*[<ox]?(-{2,}[>ox-]?|={2,}[>ox=]?|-\.+-[>ox]?|~~~)\s*(?:\|([^|]*)\|)?/.exec(rest);
|
|
73
|
+
if (!piped)
|
|
74
|
+
return null;
|
|
75
|
+
c.i += piped[0].length;
|
|
76
|
+
return piped[2] ? unquote(piped[2]) : "";
|
|
77
|
+
}
|
|
78
|
+
export function isFlowchart(code) {
|
|
79
|
+
return /^\s*(flowchart|graph)\b/.test(code.replace(/^\s*%%.*$/gm, "").trimStart());
|
|
80
|
+
}
|
|
81
|
+
export function parseFlowchart(code) {
|
|
82
|
+
const stmts = code
|
|
83
|
+
.split("\n")
|
|
84
|
+
.flatMap((l) => l.split(";"))
|
|
85
|
+
.map((l) => l.trim())
|
|
86
|
+
.filter((l) => l && !l.startsWith("%%"));
|
|
87
|
+
const head = /^(flowchart|graph)(?:\s+(LR|RL|TB|TD|BT))?\s*$/.exec(stmts[0] ?? "");
|
|
88
|
+
if (!head)
|
|
89
|
+
return null;
|
|
90
|
+
const d = head[2] ?? "TB";
|
|
91
|
+
const direction = d === "TD" ? "TB" : d;
|
|
92
|
+
const labels = new Map();
|
|
93
|
+
const edges = [];
|
|
94
|
+
for (const stmt of stmts.slice(1)) {
|
|
95
|
+
if (SKIP.test(stmt))
|
|
96
|
+
continue;
|
|
97
|
+
const c = { s: stmt, i: 0 };
|
|
98
|
+
const local = new Map(labels);
|
|
99
|
+
const found = [];
|
|
100
|
+
let left = readGroup(c, local);
|
|
101
|
+
if (!left)
|
|
102
|
+
continue;
|
|
103
|
+
let ok = true;
|
|
104
|
+
for (;;) {
|
|
105
|
+
ws(c);
|
|
106
|
+
if (c.i >= c.s.length)
|
|
107
|
+
break;
|
|
108
|
+
const label = readEdge(c);
|
|
109
|
+
const right = label === null ? null : readGroup(c, local);
|
|
110
|
+
if (!right) {
|
|
111
|
+
ok = false;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
for (const from of left)
|
|
115
|
+
for (const to of right)
|
|
116
|
+
found.push({ from, to, ...(label ? { label } : {}) });
|
|
117
|
+
left = right;
|
|
118
|
+
}
|
|
119
|
+
if (!ok)
|
|
120
|
+
continue;
|
|
121
|
+
for (const [k, v] of local)
|
|
122
|
+
if (!labels.has(k) || (v && !labels.get(k)))
|
|
123
|
+
labels.set(k, v);
|
|
124
|
+
edges.push(...found);
|
|
125
|
+
}
|
|
126
|
+
if (labels.size === 0)
|
|
127
|
+
return null;
|
|
128
|
+
return { direction, nodes: [...labels].map(([id, label]) => ({ id, label: label || id })), edges };
|
|
129
|
+
}
|
|
130
|
+
/** Lay a flow out in ranks along its direction (a longest-path layering). */
|
|
131
|
+
export function layout(flow) {
|
|
132
|
+
const rank = new Map(flow.nodes.map((n) => [n.id, 0]));
|
|
133
|
+
for (let pass = 0; pass < flow.nodes.length; pass++) {
|
|
134
|
+
let changed = false;
|
|
135
|
+
for (const e of flow.edges) {
|
|
136
|
+
if (e.from === e.to)
|
|
137
|
+
continue;
|
|
138
|
+
const r = rank.get(e.from) + 1;
|
|
139
|
+
if (r > rank.get(e.to) && r < flow.nodes.length)
|
|
140
|
+
(rank.set(e.to, r), (changed = true));
|
|
141
|
+
}
|
|
142
|
+
if (!changed)
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
const maxRank = Math.max(0, ...rank.values());
|
|
146
|
+
const slot = new Map();
|
|
147
|
+
const pos = new Map();
|
|
148
|
+
for (const n of flow.nodes) {
|
|
149
|
+
let r = rank.get(n.id);
|
|
150
|
+
if (flow.direction === "RL" || flow.direction === "BT")
|
|
151
|
+
r = maxRank - r;
|
|
152
|
+
const k = slot.get(r) ?? 0;
|
|
153
|
+
slot.set(r, k + 1);
|
|
154
|
+
const across = flow.direction === "LR" || flow.direction === "RL";
|
|
155
|
+
pos.set(n.id, across ? { x: r * 240, y: k * 120 } : { x: k * 240, y: r * 140 });
|
|
156
|
+
}
|
|
157
|
+
return pos;
|
|
158
|
+
}
|
|
159
|
+
export function flowToView(flow, meta) {
|
|
160
|
+
const pos = layout(flow);
|
|
161
|
+
return {
|
|
162
|
+
id: meta.id,
|
|
163
|
+
name: meta.name,
|
|
164
|
+
type: "sub-view",
|
|
165
|
+
draft: true,
|
|
166
|
+
source: meta.source,
|
|
167
|
+
modules: flow.nodes.map((n) => ({ id: n.id, name: n.label, ...pos.get(n.id) })),
|
|
168
|
+
connections: flow.edges.map((e, i) => ({
|
|
169
|
+
id: `c${i + 1}`,
|
|
170
|
+
from: e.from,
|
|
171
|
+
to: e.to,
|
|
172
|
+
...(e.label ? { label: e.label } : {}),
|
|
173
|
+
})),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { UserError } from "./errors.js";
|
|
4
|
+
const isDir = async (p) => (await stat(p).catch(() => null))?.isDirectory() === true;
|
|
5
|
+
const read = (p) => readFile(p, "utf8").catch(() => undefined);
|
|
6
|
+
const ls = (p) => readdir(p).catch(() => []);
|
|
7
|
+
export const hasOpenSpec = (root) => isDir(join(root, "openspec"));
|
|
8
|
+
export async function listSpecs(root) {
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const cap of (await ls(join(root, "openspec", "specs"))).sort()) {
|
|
11
|
+
const rel = `openspec/specs/${cap}/spec.md`;
|
|
12
|
+
if (await read(join(root, rel)) !== undefined)
|
|
13
|
+
out.push({ capability: cap, path: rel });
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
const ARCHIVED = /^(\d{4}-\d{2}-\d{2})-(.+)$/;
|
|
18
|
+
export async function listChanges(root) {
|
|
19
|
+
const base = join(root, "openspec", "changes");
|
|
20
|
+
const out = [];
|
|
21
|
+
for (const name of (await ls(base)).sort()) {
|
|
22
|
+
if (name === "archive" || !(await isDir(join(base, name))))
|
|
23
|
+
continue;
|
|
24
|
+
out.push({ id: name, path: `openspec/changes/${name}`, archived: false });
|
|
25
|
+
}
|
|
26
|
+
for (const name of (await ls(join(base, "archive"))).sort()) {
|
|
27
|
+
if (!(await isDir(join(base, "archive", name))))
|
|
28
|
+
continue;
|
|
29
|
+
const m = ARCHIVED.exec(name);
|
|
30
|
+
out.push({
|
|
31
|
+
id: m ? m[2] : name,
|
|
32
|
+
path: `openspec/changes/archive/${name}`,
|
|
33
|
+
archived: true,
|
|
34
|
+
...(m ? { archived_on: m[1] } : {}),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/** The change folder for an id: the active one, else the newest archived one. */
|
|
40
|
+
export async function findChange(root, id) {
|
|
41
|
+
const all = (await listChanges(root)).filter((c) => c.id === id);
|
|
42
|
+
return all.find((c) => !c.archived) ?? all.filter((c) => c.archived).pop() ?? null;
|
|
43
|
+
}
|
|
44
|
+
/** A path pinned as `openspec/changes/<id>` still resolves after the change is archived. */
|
|
45
|
+
export async function resolveChangePath(root, path) {
|
|
46
|
+
const m = /^openspec\/changes\/([^/]+)(\/.*)?$/.exec(path);
|
|
47
|
+
if (!m || m[1] === "archive" || (await stat(join(root, path)).catch(() => null)))
|
|
48
|
+
return path;
|
|
49
|
+
const found = await findChange(root, m[1]);
|
|
50
|
+
return found ? found.path + (m[2] ?? "") : path;
|
|
51
|
+
}
|
|
52
|
+
export function taskProgress(tasks) {
|
|
53
|
+
const lines = (tasks ?? "").split("\n");
|
|
54
|
+
const total = lines.filter((l) => /^\s*[-*]\s+\[[ xX]\]/.test(l)).length;
|
|
55
|
+
const done = lines.filter((l) => /^\s*[-*]\s+\[[xX]\]/.test(l)).length;
|
|
56
|
+
return { done, total };
|
|
57
|
+
}
|
|
58
|
+
export async function changeState(root, id) {
|
|
59
|
+
const c = await findChange(root, id);
|
|
60
|
+
if (!c)
|
|
61
|
+
return "missing";
|
|
62
|
+
if (c.archived)
|
|
63
|
+
return "archived";
|
|
64
|
+
return taskProgress(await read(join(root, c.path, "tasks.md"))).done > 0 ? "applied" : "proposed";
|
|
65
|
+
}
|
|
66
|
+
/** A Gap follows its change: proposed is open, applied is building, archived is done. */
|
|
67
|
+
export function gapStateFor(state, current) {
|
|
68
|
+
if (current === "cancelled")
|
|
69
|
+
return current;
|
|
70
|
+
if (state === "proposed")
|
|
71
|
+
return current === "building" || current === "done" ? current : "open";
|
|
72
|
+
if (state === "applied")
|
|
73
|
+
return current === "done" ? current : "building";
|
|
74
|
+
if (state === "archived")
|
|
75
|
+
return "done";
|
|
76
|
+
return current;
|
|
77
|
+
}
|
|
78
|
+
/** Which delta operations a delta spec uses (its `## ADDED Requirements` headings and so on). */
|
|
79
|
+
export function deltaOps(md) {
|
|
80
|
+
const ops = new Set();
|
|
81
|
+
for (const m of md.matchAll(/^##\s+(ADDED|MODIFIED|REMOVED|RENAMED)\b/gm))
|
|
82
|
+
ops.add(m[1]);
|
|
83
|
+
return [...ops];
|
|
84
|
+
}
|
|
85
|
+
export async function readChange(root, entry) {
|
|
86
|
+
const dir = join(root, entry.path);
|
|
87
|
+
const tasks = await read(join(dir, "tasks.md"));
|
|
88
|
+
const deltas = [];
|
|
89
|
+
for (const cap of (await ls(join(dir, "specs"))).sort()) {
|
|
90
|
+
const rel = `${entry.path}/specs/${cap}/spec.md`;
|
|
91
|
+
const text = await read(join(root, rel));
|
|
92
|
+
if (text !== undefined)
|
|
93
|
+
deltas.push({ capability: cap, path: rel, text, ops: deltaOps(text) });
|
|
94
|
+
}
|
|
95
|
+
const doc = { ...entry, progress: taskProgress(tasks), deltas };
|
|
96
|
+
const proposal = await read(join(dir, "proposal.md"));
|
|
97
|
+
const design = await read(join(dir, "design.md"));
|
|
98
|
+
if (proposal !== undefined)
|
|
99
|
+
doc.proposal = proposal;
|
|
100
|
+
if (design !== undefined)
|
|
101
|
+
doc.design = design;
|
|
102
|
+
if (tasks !== undefined)
|
|
103
|
+
doc.tasks = tasks;
|
|
104
|
+
return doc;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Start a change for a Gap: openspec/changes/<id>/ with a proposal and a
|
|
108
|
+
* tasks list, in the shape OpenSpec's own commands read and fill in.
|
|
109
|
+
*/
|
|
110
|
+
export async function createChange(root, input) {
|
|
111
|
+
const rel = `openspec/changes/${input.id}`;
|
|
112
|
+
if (await findChange(root, input.id))
|
|
113
|
+
throw new UserError(`an OpenSpec change ${input.id} already exists`);
|
|
114
|
+
const dir = join(root, rel);
|
|
115
|
+
await mkdir(dir, { recursive: true });
|
|
116
|
+
const where = input.modules.map((m) => `- ${m} (View: ${input.view})`).join("\n");
|
|
117
|
+
await writeFile(join(dir, "proposal.md"), `# ${input.title}\n\n## Why\n${input.intent || "TBD"}\n\n## What Changes\n- TBD\n\n## Impact\n${where || "- TBD"}\n`, "utf8");
|
|
118
|
+
await writeFile(join(dir, "tasks.md"), `## 1. Implementation\n- [ ] 1.1 TBD\n`, "utf8");
|
|
119
|
+
return rel;
|
|
120
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
2
|
+
import { UserError } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* A repo-relative, forward-slash path for `p`, refusing anything outside the
|
|
5
|
+
* repo (absolute paths elsewhere, `..` escapes). Pins and pointers are stored
|
|
6
|
+
* in this form so they diff the same on every OS.
|
|
7
|
+
*/
|
|
8
|
+
export function repoPath(root, p) {
|
|
9
|
+
const raw = p.trim();
|
|
10
|
+
if (!raw)
|
|
11
|
+
throw new UserError("a path is needed");
|
|
12
|
+
const abs = isAbsolute(raw) ? resolve(raw) : resolve(root, raw);
|
|
13
|
+
const rel = relative(resolve(root), abs);
|
|
14
|
+
if (rel === "")
|
|
15
|
+
return ".";
|
|
16
|
+
if (rel.startsWith("..") || isAbsolute(rel))
|
|
17
|
+
throw new UserError(`${p} is outside the repo`);
|
|
18
|
+
return rel.split(sep).join("/");
|
|
19
|
+
}
|
|
20
|
+
/** The absolute path of a repo-relative path (already checked by repoPath). */
|
|
21
|
+
export function absPath(root, rel) {
|
|
22
|
+
return resolve(root, repoPath(root, rel));
|
|
23
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LinkError } from "./links.js";
|
|
2
|
+
/** Find a View by id, or else by name (case-insensitive). */
|
|
3
|
+
export function resolveView(views, ref) {
|
|
4
|
+
const byId = views.find((v) => v.id === ref);
|
|
5
|
+
if (byId)
|
|
6
|
+
return byId;
|
|
7
|
+
const byName = views.filter((v) => v.name.toLowerCase() === ref.toLowerCase());
|
|
8
|
+
if (byName.length === 1)
|
|
9
|
+
return byName[0];
|
|
10
|
+
if (byName.length > 1)
|
|
11
|
+
throw new LinkError(`more than one View is named "${ref}": ${byName.map((v) => v.id).join(", ")}; use the id`);
|
|
12
|
+
throw new LinkError(`no View "${ref}"`);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Find a module by id, or else by name, across every View (or only `inView`).
|
|
16
|
+
* An ambiguous name is refused with the Views it is in, so the caller can say which.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveModule(views, ref, inView) {
|
|
19
|
+
const scope = inView ? [resolveView(views, inView)] : views;
|
|
20
|
+
const hits = [];
|
|
21
|
+
for (const view of scope)
|
|
22
|
+
for (const m of view.modules)
|
|
23
|
+
if (m.id === ref)
|
|
24
|
+
hits.push({ view, module: m });
|
|
25
|
+
if (hits.length === 0)
|
|
26
|
+
for (const view of scope)
|
|
27
|
+
for (const m of view.modules)
|
|
28
|
+
if (m.name.toLowerCase() === ref.toLowerCase())
|
|
29
|
+
hits.push({ view, module: m });
|
|
30
|
+
if (hits.length === 1)
|
|
31
|
+
return hits[0];
|
|
32
|
+
if (hits.length > 1)
|
|
33
|
+
throw new LinkError(`module "${ref}" is in more than one View (${hits.map((h) => h.view.id).join(", ")}); pass in_view`);
|
|
34
|
+
throw new LinkError(`no module "${ref}"${inView ? ` in View ${inView}` : ""}`);
|
|
35
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The data in `.spatial/`, one JSON file per View and per Gap, plus pins.json.
|
|
4
|
+
* React Flow reads the modules and connections directly; the AI is served the
|
|
5
|
+
* same data as XML. `npm run schema` writes these as JSON Schema to schema/.
|
|
6
|
+
*/
|
|
7
|
+
const Id = z.string().regex(/^[A-Za-z0-9_-]+$/, "an id is letters, digits, - and _");
|
|
8
|
+
export const ViewTypeSchema = z.enum(["high-level", "repo", "sub-view", "feature"]);
|
|
9
|
+
export const ModuleSchema = z.object({
|
|
10
|
+
id: z.string().min(1),
|
|
11
|
+
name: z.string(),
|
|
12
|
+
x: z.number().default(0),
|
|
13
|
+
y: z.number().default(0),
|
|
14
|
+
description: z.string().optional(),
|
|
15
|
+
/** The sub-view this module drills into (the View hierarchy). */
|
|
16
|
+
linked_view_id: z.string().min(1).optional(),
|
|
17
|
+
/** Source files on the module, repo-relative. */
|
|
18
|
+
files: z.array(z.string().min(1)).optional(),
|
|
19
|
+
});
|
|
20
|
+
export const ConnectionSchema = z.object({
|
|
21
|
+
id: z.string().min(1),
|
|
22
|
+
from: z.string().min(1),
|
|
23
|
+
to: z.string().min(1),
|
|
24
|
+
label: z.string().optional(),
|
|
25
|
+
});
|
|
26
|
+
/** A Feature: a named group of modules on one View (made with the lasso). */
|
|
27
|
+
export const FeatureSchema = z.object({
|
|
28
|
+
id: Id,
|
|
29
|
+
name: z.string().min(1),
|
|
30
|
+
module_ids: z.array(z.string().min(1)).default([]),
|
|
31
|
+
});
|
|
32
|
+
export const ViewSchema = z.object({
|
|
33
|
+
id: Id,
|
|
34
|
+
name: z.string(),
|
|
35
|
+
type: ViewTypeSchema.default("sub-view"),
|
|
36
|
+
modules: z.array(ModuleSchema).default([]),
|
|
37
|
+
connections: z.array(ConnectionSchema).default([]),
|
|
38
|
+
features: z.array(FeatureSchema).optional(),
|
|
39
|
+
/** A View drafted by import (from a Mermaid flowchart), not yet reviewed. */
|
|
40
|
+
draft: z.boolean().optional(),
|
|
41
|
+
/** Where a drafted View came from: `<path>#<n>` (the n-th Mermaid block). */
|
|
42
|
+
source: z.string().optional(),
|
|
43
|
+
});
|
|
44
|
+
export const GapStateSchema = z.enum(["open", "building", "done", "cancelled"]);
|
|
45
|
+
/** A Gap, one per file in `.spatial/gaps/<id>.json`. */
|
|
46
|
+
export const GapSchema = z.object({
|
|
47
|
+
id: Id,
|
|
48
|
+
title: z.string().min(1),
|
|
49
|
+
intent: z.string().default(""),
|
|
50
|
+
view_id: z.string().min(1),
|
|
51
|
+
module_ids: z.array(z.string().min(1)).default([]),
|
|
52
|
+
state: GapStateSchema.default("open"),
|
|
53
|
+
/** The OpenSpec change (openspec/changes/<id>/) this Gap follows. */
|
|
54
|
+
openspec_change: z.string().optional(),
|
|
55
|
+
milestone: z.string().optional(),
|
|
56
|
+
});
|
|
57
|
+
/** A pin maps a repo path (a spec, a change folder, any .md) to a part of the picture. */
|
|
58
|
+
export const PinSchema = z.discriminatedUnion("kind", [
|
|
59
|
+
z.object({ path: z.string().min(1), kind: z.literal("view"), view_id: z.string().min(1) }),
|
|
60
|
+
z.object({
|
|
61
|
+
path: z.string().min(1),
|
|
62
|
+
kind: z.literal("module"),
|
|
63
|
+
view_id: z.string().min(1),
|
|
64
|
+
module_id: z.string().min(1),
|
|
65
|
+
}),
|
|
66
|
+
z.object({
|
|
67
|
+
path: z.string().min(1),
|
|
68
|
+
kind: z.literal("feature"),
|
|
69
|
+
view_id: z.string().min(1),
|
|
70
|
+
feature_id: z.string().min(1),
|
|
71
|
+
}),
|
|
72
|
+
z.object({ path: z.string().min(1), kind: z.literal("gap"), gap_id: z.string().min(1) }),
|
|
73
|
+
]);
|
|
74
|
+
/** `.spatial/pins.json`. The docs themselves are never rewritten to hold pins. */
|
|
75
|
+
export const PinsFileSchema = z.object({
|
|
76
|
+
/** Extra doc folders added by import_docs (docs/ and openspec/ are always read). */
|
|
77
|
+
sources: z.array(z.string().min(1)).default([]),
|
|
78
|
+
pins: z.array(PinSchema).default([]),
|
|
79
|
+
});
|
|
80
|
+
export function summarize(view) {
|
|
81
|
+
const s = { id: view.id, name: view.name, type: view.type, modules: view.modules.length };
|
|
82
|
+
if (view.draft)
|
|
83
|
+
s.draft = true;
|
|
84
|
+
return s;
|
|
85
|
+
}
|
|
86
|
+
/** Where the published JSON Schemas live (schema/*.schema.json in the repo). */
|
|
87
|
+
export const SCHEMA_BASE = "https://raw.githubusercontent.com/Hotchilli-Cloud/spatial-views/main/schema/";
|
|
88
|
+
/** The JSON Schemas for the three file kinds in `.spatial/`. */
|
|
89
|
+
export function jsonSchemas() {
|
|
90
|
+
const one = (name, title, schema) => ({
|
|
91
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
92
|
+
$id: `${SCHEMA_BASE}${name}.schema.json`,
|
|
93
|
+
title,
|
|
94
|
+
...z.toJSONSchema(schema, { io: "input", target: "draft-2020-12" }),
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
view: one("view", "Spatial Views: a View (.spatial/views/<id>.json)", ViewSchema),
|
|
98
|
+
gap: one("gap", "Spatial Views: a Gap (.spatial/gaps/<id>.json)", GapSchema),
|
|
99
|
+
pins: one("pins", "Spatial Views: the pin map (.spatial/pins.json)", PinsFileSchema),
|
|
100
|
+
};
|
|
101
|
+
}
|