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.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -2
  3. package/dist/app/assets/abnfDiagram-S7VZAUFO-BVgtb0Hw.js +1 -0
  4. package/dist/app/assets/architecture-WOLXFQ4H-DxylGHqT.js +1 -0
  5. package/dist/app/assets/architectureDiagram-YGSQEFNW-BrBCHqUH.js +36 -0
  6. package/dist/app/assets/blockDiagram-APKKGZFW-C7fb3MCE.js +140 -0
  7. package/dist/app/assets/bpmnIcons-APHXDYXF-C0jbCElo.js +1 -0
  8. package/dist/app/assets/c4Diagram-KJ2TOQU5-Bkb_0fbd.js +38 -0
  9. package/dist/app/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  10. package/dist/app/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
  11. package/dist/app/assets/chunk-6MUBBAK2-DU4vZ03M.js +2 -0
  12. package/dist/app/assets/chunk-AXFCVDMN-De96BVTB.js +62 -0
  13. package/dist/app/assets/chunk-BG4553SI-J33jsRLV.js +127 -0
  14. package/dist/app/assets/chunk-DQASFODM-Bh85SSGO.js +10 -0
  15. package/dist/app/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
  16. package/dist/app/assets/chunk-HFQBQIA3-CCklgplR.js +1 -0
  17. package/dist/app/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
  18. package/dist/app/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  19. package/dist/app/assets/chunk-KQLB2F66-B04qR8ED.js +2 -0
  20. package/dist/app/assets/chunk-KS47KZWR-BsqDyyAt.js +1 -0
  21. package/dist/app/assets/chunk-LEVMRMFU-DwxrBz2u.js +1 -0
  22. package/dist/app/assets/chunk-M57EVK23-D9YIHjps.js +1 -0
  23. package/dist/app/assets/chunk-NGNAAXSQ-DI_UYJZ4.js +136 -0
  24. package/dist/app/assets/chunk-OY52VR5R-WB63DeTA.js +88 -0
  25. package/dist/app/assets/chunk-QB3YPZ4I-cHzzKdtb.js +213 -0
  26. package/dist/app/assets/chunk-R3KSYZAL-C7rDagaa.js +1 -0
  27. package/dist/app/assets/chunk-STOXU5M4-CG6pnJtH.js +72 -0
  28. package/dist/app/assets/chunk-TU62E6Q5-BbcGYfy_.js +1 -0
  29. package/dist/app/assets/chunk-X3CZISLH-FMl4PpWt.js +1 -0
  30. package/dist/app/assets/chunk-X4PVCEUW-BUI1Oi3q.js +1 -0
  31. package/dist/app/assets/chunk-XXDRQBXY-DYhK5YW-.js +1 -0
  32. package/dist/app/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  33. package/dist/app/assets/classDiagram-v2-L25IHNXF-K-k5GTUn.js +217 -0
  34. package/dist/app/assets/cose-bilkent-JH36ORCC-BJmLLpaN.js +1 -0
  35. package/dist/app/assets/cynefin-EF2NZ3EQ-DrzwMKdm.js +1 -0
  36. package/dist/app/assets/cynefinDiagram-L36ESFBY-mkV33_Xx.js +62 -0
  37. package/dist/app/assets/cytoscape.esm-nTrd5EVq.js +321 -0
  38. package/dist/app/assets/d3-scale-ygdFCUH8.js +1 -0
  39. package/dist/app/assets/dagre-SPEB5RXH-BNIymLsu.js +4 -0
  40. package/dist/app/assets/diagram-3B7GL73J-CGOiolFW.js +200 -0
  41. package/dist/app/assets/diagram-DNEMPZML-DZFkHNly.js +24 -0
  42. package/dist/app/assets/diagram-L3MUGCDN-B42GAYLq.js +41 -0
  43. package/dist/app/assets/diagram-LA4NIPWU-BYuLRYId.js +24 -0
  44. package/dist/app/assets/diagram-MHCOC4E2-DGzI6TJG.js +3 -0
  45. package/dist/app/assets/diagram-XPFHEONP-CTBEgDQ8.js +30 -0
  46. package/dist/app/assets/dist-1Q8ng3tu.js +1 -0
  47. package/dist/app/assets/ebnfDiagram-UZSYDL2S-GuMdOCvL.js +1 -0
  48. package/dist/app/assets/elk-XV6XMXQE-BpY3loT5.js +2 -0
  49. package/dist/app/assets/erDiagram-EYBAPDEH-nDZ2PMGl.js +99 -0
  50. package/dist/app/assets/eventmodeling-K75KTNOO-BN42Mgwh.js +1 -0
  51. package/dist/app/assets/flowDiagram-MALGAFMO-BCwwiLzb.js +1 -0
  52. package/dist/app/assets/ganttDiagram-23REXITY-xMRHaU3y.js +292 -0
  53. package/dist/app/assets/gitGraph-VSP46ZUC-DyGq5mdd.js +1 -0
  54. package/dist/app/assets/gitGraphDiagram-STJD7YCW-CDkKLrvO.js +106 -0
  55. package/dist/app/assets/graphlib-DS17s2tU.js +1 -0
  56. package/dist/app/assets/index-BY66fc8Q.js +95 -0
  57. package/dist/app/assets/index-ByetEVbs.css +1 -0
  58. package/dist/app/assets/info-OHQRW6UA-DOBf-fQH.js +1 -0
  59. package/dist/app/assets/infoDiagram-KBXO4MBG-B92P8pjY.js +2 -0
  60. package/dist/app/assets/ishikawaDiagram-M35NCXHK-BRZsbCvK.js +70 -0
  61. package/dist/app/assets/journeyDiagram-OPLOXDXO-Bppwb1oF.js +139 -0
  62. package/dist/app/assets/kanban-definition-BZKZHSQY-ByD_x5cm.js +89 -0
  63. package/dist/app/assets/katex-MEuSR36T.js +257 -0
  64. package/dist/app/assets/mermaid-parser.core-CKmnV0Md.js +7 -0
  65. package/dist/app/assets/mermaid.core-BoRvk1Q-.js +44 -0
  66. package/dist/app/assets/mindmap-definition-I2QAS2VK-fRbUh23C.js +98 -0
  67. package/dist/app/assets/packet-JDAUHWVQ-CgHq03Zj.js +1 -0
  68. package/dist/app/assets/pegDiagram-FD4XPPHP-qIABf6H8.js +1 -0
  69. package/dist/app/assets/pie-XZMESJXO-DtNh3cDE.js +1 -0
  70. package/dist/app/assets/pieDiagram-J4AKIIQI-Bb4RBdrc.js +39 -0
  71. package/dist/app/assets/quadrantDiagram-XTYBLID2-B0CpcVWE.js +7 -0
  72. package/dist/app/assets/radar-ABXABTNO-BS0FcsIX.js +1 -0
  73. package/dist/app/assets/railroad-I3PHUGI6-lO8vfGdI.js +1 -0
  74. package/dist/app/assets/railroad-abnf-LNEFI6M7-BUhw7Iuo.js +1 -0
  75. package/dist/app/assets/railroad-ebnf-DWYD2UWJ-nQNF56LJ.js +1 -0
  76. package/dist/app/assets/railroad-peg-JR7BVNR7-CwvbVIo6.js +1 -0
  77. package/dist/app/assets/railroadDiagram-MRQ6NCDL-Dwr-mPZL.js +1 -0
  78. package/dist/app/assets/requirementDiagram-Y7LWUY3S-Ctv2DKJM.js +84 -0
  79. package/dist/app/assets/rough.esm-Dy-Kn_BL.js +1 -0
  80. package/dist/app/assets/sankeyDiagram-WGJFYUXA-BvKX0eIe.js +40 -0
  81. package/dist/app/assets/sequenceDiagram-5NDRBG5M-Y4YqU2Xt.js +169 -0
  82. package/dist/app/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
  83. package/dist/app/assets/stateDiagram-v2-FJ4FJNEA-DmjIjn4u.js +291 -0
  84. package/dist/app/assets/swimlanes-UMQ2AFYF-B2O5JCjs.js +1 -0
  85. package/dist/app/assets/swimlanesDiagram-OMPLPG4O-DhCl-Cjg.js +8 -0
  86. package/dist/app/assets/timeline-definition-SEUHKTQE-DJJdixAI.js +120 -0
  87. package/dist/app/assets/treeView-D4JQ5SDB-Dd1no4eE.js +1 -0
  88. package/dist/app/assets/treemap-SAJKECNS-t6wtsaki.js +1 -0
  89. package/dist/app/assets/usecaseDiagram-AFA6YXN4-Bp8pXgvR.js +328 -0
  90. package/dist/app/assets/vennDiagram-NNMJR3RB-DYSfZMWT.js +34 -0
  91. package/dist/app/assets/wardley-7MLQ67FV-Bx60QTuu.js +1 -0
  92. package/dist/app/assets/wardleyDiagram-S7YFUSEH-CGJ8qg76.js +78 -0
  93. package/dist/app/assets/xychartDiagram-GGNKY7IX-CRSvraFc.js +7 -0
  94. package/dist/app/index.html +13 -0
  95. package/dist/cli/index.js +110 -0
  96. package/dist/core/api.js +209 -0
  97. package/dist/core/context.js +194 -0
  98. package/dist/core/docs.js +134 -0
  99. package/dist/core/edit.js +105 -0
  100. package/dist/core/errors.js +3 -0
  101. package/dist/core/gaps.js +114 -0
  102. package/dist/core/history.js +19 -0
  103. package/dist/core/links.js +68 -0
  104. package/dist/core/mermaid.js +175 -0
  105. package/dist/core/openspec.js +120 -0
  106. package/dist/core/paths.js +23 -0
  107. package/dist/core/resolve.js +35 -0
  108. package/dist/core/schema.js +101 -0
  109. package/dist/core/skills.js +103 -0
  110. package/dist/core/storage.js +183 -0
  111. package/dist/core/version.js +1 -0
  112. package/dist/core/watch.js +136 -0
  113. package/dist/core/xml.js +50 -0
  114. package/dist/mcp/server.js +357 -0
  115. package/package.json +53 -4
  116. package/schema/gap.schema.json +53 -0
  117. package/schema/pins.schema.json +122 -0
  118. package/schema/view.schema.json +134 -0
  119. package/skills/claude/build-gap/SKILL.md +21 -0
  120. package/skills/claude/draw-system/SKILL.md +23 -0
  121. package/skills/claude/gap-from-view/SKILL.md +22 -0
  122. package/skills/cursor/build-gap.mdc +21 -0
  123. package/skills/cursor/draw-system.mdc +23 -0
  124. package/skills/cursor/gap-from-view.mdc +22 -0
  125. package/skills/windsurf/spatial-views.md +66 -0
@@ -0,0 +1,357 @@
1
+ import { stat } from "node:fs/promises";
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { z, ZodError } from "zod";
4
+ import { buildContext, contextToJson, contextToXml } from "../core/context.js";
5
+ import { importDocs } from "../core/docs.js";
6
+ import { addFilePointer, addModule, connect, findModule, moveModule, removeConnection, removeModule, updateModule, } from "../core/edit.js";
7
+ import { UserError } from "../core/errors.js";
8
+ import { createGap, listGaps, resolveGap, updateGap } from "../core/gaps.js";
9
+ import { linkModule, slugId, unlinkModule } from "../core/links.js";
10
+ import { resolveChangePath } from "../core/openspec.js";
11
+ import { absPath, repoPath } from "../core/paths.js";
12
+ import { resolveModule, resolveView } from "../core/resolve.js";
13
+ import { GapStateSchema, summarize, ViewTypeSchema } from "../core/schema.js";
14
+ import { Spatial } from "../core/storage.js";
15
+ import { VERSION } from "../core/version.js";
16
+ import { viewToXml } from "../core/xml.js";
17
+ /** Every tool the server registers (PRD §7, plus link_module / unlink_module). */
18
+ export const TOOL_NAMES = [
19
+ "list_views",
20
+ "get_view",
21
+ "open_view",
22
+ "create_view",
23
+ "add_module",
24
+ "connect",
25
+ "move_module",
26
+ "update_module",
27
+ "remove",
28
+ "link_module",
29
+ "unlink_module",
30
+ "create_gap",
31
+ "list_gaps",
32
+ "update_gap",
33
+ "pin",
34
+ "list_pins",
35
+ "get_context",
36
+ "add_file_pointer",
37
+ "import_docs",
38
+ ];
39
+ const text = (t) => ({ content: [{ type: "text", text: t }] });
40
+ const json = (data) => text(JSON.stringify(data, null, 2));
41
+ const fail = (t) => ({ content: [{ type: "text", text: t }], isError: true });
42
+ /** Known errors go back to the AI as tool errors; anything else is a bug and throws. */
43
+ async function guard(fn) {
44
+ try {
45
+ return await fn();
46
+ }
47
+ catch (err) {
48
+ if (err instanceof UserError)
49
+ return fail(err.message);
50
+ if (err instanceof ZodError)
51
+ return fail(`invalid data: ${err.issues.map((i) => i.message).join("; ")}`);
52
+ throw err;
53
+ }
54
+ }
55
+ const Ref = {
56
+ view: z.string().describe("View id or name"),
57
+ module: z.string().describe("module id or name"),
58
+ in_view: z.string().optional().describe("the View the module is in, when its name is not unique"),
59
+ format: z.enum(["xml", "json"]).optional().describe("xml (default) or json"),
60
+ };
61
+ /** The Spatial Views MCP server: the AI draws Views, makes Gaps and pins docs in .spatial/. */
62
+ export function createServer(opts = {}) {
63
+ const spatial = new Spatial(opts.root ?? process.cwd());
64
+ const { views } = spatial;
65
+ const server = new McpServer({ name: "spatial-views", version: VERSION });
66
+ /** Load a View by ref, change it, save it. */
67
+ const editView = async (ref, change) => {
68
+ const v = resolveView(await views.listViews(), ref);
69
+ return views.save(change(v));
70
+ };
71
+ // ---- Read and show ------------------------------------------------------
72
+ server.registerTool("list_views", { description: "List the Views in .spatial/ (id, name, type, module count)." }, async () => json(await views.list()));
73
+ server.registerTool("get_view", {
74
+ description: "Read one View, as XML by default or format=json. A linked module carries its sub-view " +
75
+ "(LinkedView / LinkedViewName in XML, linked_view_id in JSON); a link to a missing View says Missing.",
76
+ inputSchema: { view: Ref.view, format: Ref.format },
77
+ }, async ({ view, format }) => guard(async () => {
78
+ const all = await views.listViews();
79
+ const v = resolveView(all, view);
80
+ if (format === "json")
81
+ return json(v);
82
+ return text(viewToXml(v, all.map(summarize)));
83
+ }));
84
+ server.registerTool("open_view", {
85
+ description: "Show a View on the canvas (npx spatial-views must be running for this repo).",
86
+ inputSchema: { view: Ref.view },
87
+ }, async ({ view }) => guard(async () => {
88
+ const v = resolveView(await views.listViews(), view);
89
+ await spatial.requestOpen(v.id);
90
+ return text(`asked the canvas to open ${v.name} (${v.id})`);
91
+ }));
92
+ // ---- Draw ----------------------------------------------------------------
93
+ server.registerTool("create_view", {
94
+ description: "Create an empty View. Give from_module (and in_view) to link that module to it, so it becomes " +
95
+ "the module's sub-view (double-click drills into it).",
96
+ inputSchema: {
97
+ name: z.string().min(1),
98
+ type: ViewTypeSchema.optional().describe("high-level, repo, sub-view (default) or feature"),
99
+ id: z.string().optional().describe("a file-safe id; made from the name if left out"),
100
+ from_module: z.string().optional().describe("a module to link to the new View"),
101
+ in_view: Ref.in_view,
102
+ },
103
+ }, async ({ name, type, id, from_module, in_view }) => guard(async () => {
104
+ const all = await views.listViews();
105
+ const newId = id ?? slugId(name, all.map((v) => v.id));
106
+ if (all.some((v) => v.id === newId))
107
+ throw new UserError(`a View ${newId} already exists`);
108
+ const parent = from_module ? resolveModule(all, from_module, in_view) : null;
109
+ const v = await views.save({ id: newId, name, type: type ?? "sub-view", modules: [], connections: [] });
110
+ if (parent)
111
+ await views.save(linkModule(parent.view, parent.module.id, v.id));
112
+ return text(`created ${v.type} View ${v.name} (${v.id})` +
113
+ (parent ? `, linked from ${parent.module.name} (${parent.view.id})` : ""));
114
+ }));
115
+ server.registerTool("add_module", {
116
+ description: "Add a module to a View. Without x/y it goes in the next free slot.",
117
+ inputSchema: {
118
+ view: Ref.view,
119
+ name: z.string().min(1),
120
+ id: z.string().optional(),
121
+ description: z.string().optional(),
122
+ x: z.number().optional(),
123
+ y: z.number().optional(),
124
+ },
125
+ }, async ({ view, ...input }) => guard(async () => {
126
+ let added = "";
127
+ const v = await editView(view, (cur) => {
128
+ const r = addModule(cur, input);
129
+ added = `${r.module.name} (${r.module.id})`;
130
+ return r.view;
131
+ });
132
+ return text(`added ${added} to ${v.id}`);
133
+ }));
134
+ server.registerTool("connect", {
135
+ description: "Connect two modules on a View (from -> to), with an optional label.",
136
+ inputSchema: {
137
+ view: Ref.view,
138
+ from: z.string().describe("module id or name"),
139
+ to: z.string().describe("module id or name"),
140
+ label: z.string().optional(),
141
+ },
142
+ }, async ({ view, from, to, label }) => guard(async () => {
143
+ let id = "";
144
+ const v = await editView(view, (cur) => {
145
+ const r = connect(cur, from, to, label);
146
+ id = r.connection.id;
147
+ return r.view;
148
+ });
149
+ return text(`connected ${from} -> ${to} on ${v.id} (${id})`);
150
+ }));
151
+ server.registerTool("move_module", {
152
+ description: "Move a module to x, y on its View.",
153
+ inputSchema: { module: Ref.module, in_view: Ref.in_view, x: z.number(), y: z.number() },
154
+ }, async ({ module, in_view, x, y }) => guard(async () => {
155
+ const hit = resolveModule(await views.listViews(), module, in_view);
156
+ await views.save(moveModule(hit.view, hit.module.id, x, y));
157
+ return text(`moved ${hit.module.name} to ${Math.round(x)}, ${Math.round(y)}`);
158
+ }));
159
+ server.registerTool("update_module", {
160
+ description: "Rename a module or set its description (an empty description clears it).",
161
+ inputSchema: {
162
+ module: Ref.module,
163
+ in_view: Ref.in_view,
164
+ name: z.string().optional(),
165
+ description: z.string().optional(),
166
+ },
167
+ }, async ({ module, in_view, name, description }) => guard(async () => {
168
+ const hit = resolveModule(await views.listViews(), module, in_view);
169
+ await views.save(updateModule(hit.view, hit.module.id, { name, description }));
170
+ return text(`updated ${hit.module.id} on ${hit.view.id}`);
171
+ }));
172
+ server.registerTool("remove", {
173
+ description: "Remove a module (with its connections), a connection (by id), or, with neither, the whole View. " +
174
+ "Removing a View needs confirm_view set to its id.",
175
+ inputSchema: {
176
+ view: Ref.view,
177
+ module: z.string().optional().describe("module id or name"),
178
+ connection: z.string().optional().describe("connection id"),
179
+ confirm_view: z.string().optional(),
180
+ },
181
+ }, async ({ view, module, connection, confirm_view }) => guard(async () => {
182
+ const v = resolveView(await views.listViews(), view);
183
+ if (module) {
184
+ const m = findModule(v, module);
185
+ await views.save(removeModule(v, m.id));
186
+ return text(`removed ${m.name} (${m.id}) from ${v.id}`);
187
+ }
188
+ if (connection) {
189
+ await views.save(removeConnection(v, connection));
190
+ return text(`removed connection ${connection} from ${v.id}`);
191
+ }
192
+ if (confirm_view !== v.id)
193
+ throw new UserError(`to remove the View itself, pass confirm_view: "${v.id}"`);
194
+ await views.remove(v.id);
195
+ return text(`removed View ${v.name} (${v.id})`);
196
+ }));
197
+ server.registerTool("link_module", {
198
+ description: "Link a module to a sub-view, so double-clicking it on the canvas drills into that View. " +
199
+ "Linking an already linked module changes its link.",
200
+ inputSchema: { module: Ref.module, view: z.string().describe("the target View, id or name"), in_view: Ref.in_view },
201
+ }, async ({ module, view, in_view }) => guard(async () => {
202
+ const all = await views.listViews();
203
+ const target = resolveView(all, view);
204
+ const hit = resolveModule(all, module, in_view);
205
+ await views.save(linkModule(hit.view, hit.module.id, target.id));
206
+ return text(`linked ${hit.module.name} (${hit.view.id}) to ${target.name} (${target.id})`);
207
+ }));
208
+ server.registerTool("unlink_module", {
209
+ description: "Remove a module's link to its sub-view. The sub-view itself is kept.",
210
+ inputSchema: { module: Ref.module, in_view: Ref.in_view },
211
+ }, async ({ module, in_view }) => guard(async () => {
212
+ const hit = resolveModule(await views.listViews(), module, in_view);
213
+ if (!hit.module.linked_view_id)
214
+ return text(`${hit.module.name} has no link`);
215
+ await views.save(unlinkModule(hit.view, hit.module.id));
216
+ return text(`removed the link from ${hit.module.name} (${hit.view.id})`);
217
+ }));
218
+ server.registerTool("add_file_pointer", {
219
+ description: "Record a source file (repo-relative) on a module, so get_context can point at it.",
220
+ inputSchema: { module: Ref.module, in_view: Ref.in_view, path: z.string().min(1) },
221
+ }, async ({ module, in_view, path }) => guard(async () => {
222
+ const rel = repoPath(spatial.root, path);
223
+ const hit = resolveModule(await views.listViews(), module, in_view);
224
+ await views.save(addFilePointer(hit.view, hit.module.id, rel));
225
+ return text(`${rel} is on ${hit.module.name} (${hit.view.id})`);
226
+ }));
227
+ // ---- Gaps ----------------------------------------------------------------
228
+ server.registerTool("create_gap", {
229
+ description: "Create a Gap from selected modules on a View. When the repo uses OpenSpec, this also creates the " +
230
+ "change (openspec/changes/<id>/ with proposal.md and tasks.md) and pins it to the Gap; the Gap then " +
231
+ "follows the change (proposed: open, applied: building, archived: done).",
232
+ inputSchema: {
233
+ title: z.string().min(1),
234
+ intent: z.string().optional().describe("why: the outcome wanted"),
235
+ view: Ref.view,
236
+ modules: z.array(z.string()).min(1).describe("module ids or names on that View"),
237
+ milestone: z.string().optional(),
238
+ openspec: z.boolean().optional().describe("force the OpenSpec change on or off"),
239
+ },
240
+ }, async (input) => guard(async () => json(await createGap(spatial, input))));
241
+ server.registerTool("list_gaps", {
242
+ description: "List Gaps (JSON), optionally for one View, state or milestone. States follow their OpenSpec change.",
243
+ inputSchema: { view: Ref.view.optional(), state: GapStateSchema.optional(), milestone: z.string().optional() },
244
+ }, async (filter) => guard(async () => json(await listGaps(spatial, filter))));
245
+ server.registerTool("update_gap", {
246
+ description: "Change a Gap: title, intent, state (open, building, done, cancelled), milestone or modules. " +
247
+ "A Gap with an OpenSpec change is done once the change is archived.",
248
+ inputSchema: {
249
+ gap: z.string().describe("Gap id or title"),
250
+ title: z.string().optional(),
251
+ intent: z.string().optional(),
252
+ state: GapStateSchema.optional(),
253
+ milestone: z.string().optional().describe("empty clears it"),
254
+ modules: z.array(z.string()).optional(),
255
+ },
256
+ }, async ({ gap, ...patch }) => guard(async () => json(await updateGap(spatial, gap, patch))));
257
+ server.registerTool("get_context", {
258
+ description: "Everything one Gap needs, and nothing else: the Big Picture (top View), the path down to the Gap's " +
259
+ "View, its modules with connections and files, and the specs, changes and docs pinned to them " +
260
+ "(their text included). XML by default, or format=json. Tokens is an estimate.",
261
+ inputSchema: { gap: z.string().describe("Gap id or title"), format: Ref.format },
262
+ }, async ({ gap, format }) => guard(async () => {
263
+ const ctx = await buildContext(spatial, gap);
264
+ if (format === "json")
265
+ return text(contextToJson(ctx));
266
+ return text(contextToXml(ctx, await views.list()));
267
+ }));
268
+ // ---- Pins and docs --------------------------------------------------------
269
+ server.registerTool("pin", {
270
+ description: "Pin a spec, change folder or doc (repo path) to a View, a module, a Feature or a Gap. Pins go in " +
271
+ ".spatial/pins.json; the doc is never rewritten. unpin: true removes the pin.",
272
+ inputSchema: {
273
+ path: z.string().min(1).describe("e.g. openspec/specs/auth/spec.md, openspec/changes/add-x, docs/prd.md"),
274
+ view: Ref.view.optional().describe("the View (alone: pin to the View; with module/feature: where they are)"),
275
+ module: z.string().optional(),
276
+ feature: z.string().optional().describe("Feature id or name"),
277
+ gap: z.string().optional().describe("Gap id or title"),
278
+ unpin: z.boolean().optional(),
279
+ },
280
+ }, async ({ path, view, module, feature, gap, unpin }) => guard(async () => {
281
+ const rel = repoPath(spatial.root, path);
282
+ if (!unpin && !(await stat(absPath(spatial.root, await resolveChangePath(spatial.root, rel))).catch(() => null)))
283
+ throw new UserError(`${rel} does not exist`);
284
+ const all = await views.listViews();
285
+ let pin;
286
+ let label;
287
+ if (gap) {
288
+ const g = resolveGap(await spatial.gaps.all(), gap);
289
+ pin = { path: rel, kind: "gap", gap_id: g.id };
290
+ label = `Gap ${g.title}`;
291
+ }
292
+ else if (module) {
293
+ const hit = resolveModule(all, module, view);
294
+ pin = { path: rel, kind: "module", view_id: hit.view.id, module_id: hit.module.id };
295
+ label = `${hit.module.name} (${hit.view.id})`;
296
+ }
297
+ else if (feature) {
298
+ const scope = view ? [resolveView(all, view)] : all;
299
+ const hits = scope.flatMap((v) => (v.features ?? [])
300
+ .filter((f) => f.id === feature || f.name.toLowerCase() === feature.toLowerCase())
301
+ .map((f) => ({ v, f })));
302
+ if (hits.length !== 1)
303
+ throw new UserError(hits.length ? `Feature "${feature}" is on more than one View; pass view` : `no Feature "${feature}"`);
304
+ pin = { path: rel, kind: "feature", view_id: hits[0].v.id, feature_id: hits[0].f.id };
305
+ label = `Feature ${hits[0].f.name}`;
306
+ }
307
+ else if (view) {
308
+ const v = resolveView(all, view);
309
+ pin = { path: rel, kind: "view", view_id: v.id };
310
+ label = `View ${v.name}`;
311
+ }
312
+ else
313
+ throw new UserError("say what to pin to: view, module, feature or gap");
314
+ if (unpin) {
315
+ const n = await spatial.pins.remove(pin);
316
+ return text(n ? `unpinned ${rel} from ${label}` : `${rel} was not pinned to ${label}`);
317
+ }
318
+ const added = await spatial.pins.add(pin);
319
+ return text(added ? `pinned ${rel} to ${label}` : `${rel} is already pinned to ${label}`);
320
+ }));
321
+ server.registerTool("list_pins", {
322
+ description: "List pins (JSON), optionally only those on one View, module, Gap or path.",
323
+ inputSchema: {
324
+ view: Ref.view.optional(),
325
+ module: z.string().optional(),
326
+ gap: z.string().optional(),
327
+ path: z.string().optional(),
328
+ },
329
+ }, async ({ view, module, gap, path }) => guard(async () => {
330
+ let pins = await spatial.pins.list();
331
+ const all = await views.listViews();
332
+ if (view && !module) {
333
+ const v = resolveView(all, view);
334
+ pins = pins.filter((p) => "view_id" in p && p.view_id === v.id);
335
+ }
336
+ if (module) {
337
+ const hit = resolveModule(all, module, view);
338
+ pins = pins.filter((p) => p.kind === "module" && p.view_id === hit.view.id && p.module_id === hit.module.id);
339
+ }
340
+ if (gap) {
341
+ const g = resolveGap(await spatial.gaps.all(), gap);
342
+ pins = pins.filter((p) => p.kind === "gap" && p.gap_id === g.id);
343
+ }
344
+ if (path) {
345
+ const rel = repoPath(spatial.root, path);
346
+ pins = pins.filter((p) => p.path === rel || p.path.startsWith(`${rel}/`));
347
+ }
348
+ return json(pins);
349
+ }));
350
+ server.registerTool("import_docs", {
351
+ description: "Import an existing docs/ or openspec/ folder (any repo folder): it is read as-is and shown beside " +
352
+ "the canvas. Reports the docs, OpenSpec specs and changes, and Mermaid flowcharts found. With " +
353
+ "draft_views, each flowchart becomes a draft View.",
354
+ inputSchema: { path: z.string().min(1), draft_views: z.boolean().optional() },
355
+ }, async ({ path, draft_views }) => guard(async () => json(await importDocs(spatial, path, draft_views === true))));
356
+ return server;
357
+ }
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "spatial-views",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Spatial Views: the picture for spec-driven development. A React Flow canvas and an MCP server for Cursor and Claude Code.",
5
+ "license": "MIT",
6
+ "author": "NODEMAX LIMITED",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Hotchilli-Cloud/spatial-views.git"
11
+ },
12
+ "bin": {
13
+ "spatial-views": "dist/cli/index.js"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "schema",
18
+ "skills"
19
+ ],
20
+ "engines": {
21
+ "node": ">=20"
22
+ },
23
+ "scripts": {
24
+ "dev": "vite",
25
+ "build": "vite build && tsc -p tsconfig.node.json",
26
+ "start": "node dist/cli/index.js",
27
+ "mcp": "node dist/cli/index.js mcp",
28
+ "schema": "tsc -p tsconfig.node.json && node dist/cli/index.js schema --out schema",
29
+ "skills": "tsc -p tsconfig.node.json && node dist/cli/index.js skills",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.node.json --noEmit",
31
+ "test": "vitest run",
32
+ "test:ui": "npm run build && playwright test",
33
+ "prepack": "npm run build"
34
+ },
35
+ "dependencies": {
36
+ "@modelcontextprotocol/sdk": "^1.32.2",
37
+ "@xyflow/react": "^13.0.2",
38
+ "dompurify": "^3.4.18",
39
+ "marked": "^18.2.1",
40
+ "mermaid": "^12.3.0",
41
+ "react": "^19.3.1",
42
+ "react-dom": "^19.3.1",
43
+ "zod": "^4.6.7"
44
+ },
45
+ "devDependencies": {
46
+ "@playwright/test": "^1.61.1",
47
+ "@types/node": "^26.6.6",
48
+ "@types/react": "^19.3.0",
49
+ "@types/react-dom": "^19.3.0",
50
+ "@vitejs/plugin-react": "^6.3.0",
51
+ "typescript": "^7.0.2",
52
+ "vite": "^8.3.8",
53
+ "vitest": "^4.1.12"
54
+ }
55
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://raw.githubusercontent.com/Hotchilli-Cloud/spatial-views/main/schema/gap.schema.json",
4
+ "title": "Spatial Views: a Gap (.spatial/gaps/<id>.json)",
5
+ "type": "object",
6
+ "properties": {
7
+ "id": {
8
+ "type": "string",
9
+ "pattern": "^[A-Za-z0-9_-]+$"
10
+ },
11
+ "title": {
12
+ "type": "string",
13
+ "minLength": 1
14
+ },
15
+ "intent": {
16
+ "default": "",
17
+ "type": "string"
18
+ },
19
+ "view_id": {
20
+ "type": "string",
21
+ "minLength": 1
22
+ },
23
+ "module_ids": {
24
+ "default": [],
25
+ "type": "array",
26
+ "items": {
27
+ "type": "string",
28
+ "minLength": 1
29
+ }
30
+ },
31
+ "state": {
32
+ "default": "open",
33
+ "type": "string",
34
+ "enum": [
35
+ "open",
36
+ "building",
37
+ "done",
38
+ "cancelled"
39
+ ]
40
+ },
41
+ "openspec_change": {
42
+ "type": "string"
43
+ },
44
+ "milestone": {
45
+ "type": "string"
46
+ }
47
+ },
48
+ "required": [
49
+ "id",
50
+ "title",
51
+ "view_id"
52
+ ]
53
+ }
@@ -0,0 +1,122 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://raw.githubusercontent.com/Hotchilli-Cloud/spatial-views/main/schema/pins.schema.json",
4
+ "title": "Spatial Views: the pin map (.spatial/pins.json)",
5
+ "type": "object",
6
+ "properties": {
7
+ "sources": {
8
+ "default": [],
9
+ "type": "array",
10
+ "items": {
11
+ "type": "string",
12
+ "minLength": 1
13
+ }
14
+ },
15
+ "pins": {
16
+ "default": [],
17
+ "type": "array",
18
+ "items": {
19
+ "oneOf": [
20
+ {
21
+ "type": "object",
22
+ "properties": {
23
+ "path": {
24
+ "type": "string",
25
+ "minLength": 1
26
+ },
27
+ "kind": {
28
+ "type": "string",
29
+ "const": "view"
30
+ },
31
+ "view_id": {
32
+ "type": "string",
33
+ "minLength": 1
34
+ }
35
+ },
36
+ "required": [
37
+ "path",
38
+ "kind",
39
+ "view_id"
40
+ ]
41
+ },
42
+ {
43
+ "type": "object",
44
+ "properties": {
45
+ "path": {
46
+ "type": "string",
47
+ "minLength": 1
48
+ },
49
+ "kind": {
50
+ "type": "string",
51
+ "const": "module"
52
+ },
53
+ "view_id": {
54
+ "type": "string",
55
+ "minLength": 1
56
+ },
57
+ "module_id": {
58
+ "type": "string",
59
+ "minLength": 1
60
+ }
61
+ },
62
+ "required": [
63
+ "path",
64
+ "kind",
65
+ "view_id",
66
+ "module_id"
67
+ ]
68
+ },
69
+ {
70
+ "type": "object",
71
+ "properties": {
72
+ "path": {
73
+ "type": "string",
74
+ "minLength": 1
75
+ },
76
+ "kind": {
77
+ "type": "string",
78
+ "const": "feature"
79
+ },
80
+ "view_id": {
81
+ "type": "string",
82
+ "minLength": 1
83
+ },
84
+ "feature_id": {
85
+ "type": "string",
86
+ "minLength": 1
87
+ }
88
+ },
89
+ "required": [
90
+ "path",
91
+ "kind",
92
+ "view_id",
93
+ "feature_id"
94
+ ]
95
+ },
96
+ {
97
+ "type": "object",
98
+ "properties": {
99
+ "path": {
100
+ "type": "string",
101
+ "minLength": 1
102
+ },
103
+ "kind": {
104
+ "type": "string",
105
+ "const": "gap"
106
+ },
107
+ "gap_id": {
108
+ "type": "string",
109
+ "minLength": 1
110
+ }
111
+ },
112
+ "required": [
113
+ "path",
114
+ "kind",
115
+ "gap_id"
116
+ ]
117
+ }
118
+ ]
119
+ }
120
+ }
121
+ }
122
+ }