spatial-views 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +245 -2
- package/dist/app/assets/abnfDiagram-S7VZAUFO-CFbb_Sz2.js +1 -0
- package/dist/app/assets/architecture-WOLXFQ4H-CsBD__5a.js +1 -0
- package/dist/app/assets/architectureDiagram-YGSQEFNW-C0ic4ib1.js +36 -0
- package/dist/app/assets/blockDiagram-APKKGZFW-BZDPbzAG.js +140 -0
- package/dist/app/assets/bpmnIcons-APHXDYXF-C0jbCElo.js +1 -0
- package/dist/app/assets/c4Diagram-KJ2TOQU5-BilBWuq5.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-BBl-4tQr.js +2 -0
- package/dist/app/assets/chunk-AXFCVDMN-BhsttQ-k.js +62 -0
- package/dist/app/assets/chunk-BG4553SI-mWcPcFZr.js +127 -0
- package/dist/app/assets/chunk-DQASFODM-7FKe2gLt.js +10 -0
- package/dist/app/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/dist/app/assets/chunk-HFQBQIA3-nXrQ08BL.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-swukhFmZ.js +2 -0
- package/dist/app/assets/chunk-KS47KZWR-DkDkwO82.js +1 -0
- package/dist/app/assets/chunk-LEVMRMFU-DXH6iXv3.js +1 -0
- package/dist/app/assets/chunk-M57EVK23-B-kEyOJF.js +1 -0
- package/dist/app/assets/chunk-NGNAAXSQ-DI_UYJZ4.js +136 -0
- package/dist/app/assets/chunk-OY52VR5R-DweG7qYw.js +88 -0
- package/dist/app/assets/chunk-QB3YPZ4I-DyozK3lV.js +213 -0
- package/dist/app/assets/chunk-R3KSYZAL-BEXCUN6J.js +1 -0
- package/dist/app/assets/chunk-STOXU5M4-BaTlty4O.js +72 -0
- package/dist/app/assets/chunk-TU62E6Q5-_rcUP1Fh.js +1 -0
- package/dist/app/assets/chunk-X3CZISLH-NOpCnvgE.js +1 -0
- package/dist/app/assets/chunk-X4PVCEUW-DGxTL3kB.js +1 -0
- package/dist/app/assets/chunk-XXDRQBXY-C02Gpej2.js +1 -0
- package/dist/app/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/dist/app/assets/classDiagram-v2-L25IHNXF-DLEBwpvk.js +217 -0
- 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-CLFstukD.js +62 -0
- package/dist/app/assets/cytoscape.esm-nTrd5EVq.js +321 -0
- package/dist/app/assets/d3-scale-CaJQQYkF.js +1 -0
- package/dist/app/assets/dagre-SPEB5RXH-BaSAny1T.js +4 -0
- package/dist/app/assets/diagram-3B7GL73J-DJNlt5Sg.js +200 -0
- package/dist/app/assets/diagram-DNEMPZML-DEHeuILB.js +24 -0
- package/dist/app/assets/diagram-L3MUGCDN-ob5Ka2Xc.js +41 -0
- package/dist/app/assets/diagram-LA4NIPWU-DNESzFAc.js +24 -0
- package/dist/app/assets/diagram-MHCOC4E2-CVi9zKjG.js +3 -0
- package/dist/app/assets/diagram-XPFHEONP-DInT4C7e.js +30 -0
- package/dist/app/assets/dist-CjvHN74u.js +1 -0
- package/dist/app/assets/ebnfDiagram-UZSYDL2S-CRCZNsji.js +1 -0
- package/dist/app/assets/elk-XV6XMXQE-D4fsWI2l.js +2 -0
- package/dist/app/assets/erDiagram-EYBAPDEH-YQNM5StV.js +99 -0
- package/dist/app/assets/eventmodeling-K75KTNOO-Bev08J2F.js +1 -0
- 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-D15ZdQ-Z.js +106 -0
- package/dist/app/assets/graphlib-DS17s2tU.js +1 -0
- 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-DT7LbBRQ.js +2 -0
- package/dist/app/assets/ishikawaDiagram-M35NCXHK-CF51lhjB.js +70 -0
- package/dist/app/assets/journeyDiagram-OPLOXDXO-_36FonKk.js +139 -0
- package/dist/app/assets/kanban-definition-BZKZHSQY-tLk_OlQ-.js +89 -0
- package/dist/app/assets/katex-MEuSR36T.js +257 -0
- package/dist/app/assets/mermaid-parser.core-_3Vo8x6b.js +7 -0
- package/dist/app/assets/mermaid.core-y-x1CYxC.js +44 -0
- package/dist/app/assets/mindmap-definition-I2QAS2VK-BCI4HRX3.js +98 -0
- package/dist/app/assets/packet-JDAUHWVQ-Cco3UoaI.js +1 -0
- package/dist/app/assets/pegDiagram-FD4XPPHP-BOzSoNji.js +1 -0
- package/dist/app/assets/pie-XZMESJXO-reOB2GXn.js +1 -0
- package/dist/app/assets/pieDiagram-J4AKIIQI-PlHpwT_c.js +39 -0
- package/dist/app/assets/quadrantDiagram-XTYBLID2-CdxZ0ael.js +7 -0
- 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-C49jJE4Y.js +1 -0
- package/dist/app/assets/railroad-ebnf-DWYD2UWJ-Bx-pcPc7.js +1 -0
- package/dist/app/assets/railroad-peg-JR7BVNR7-DjBPSCKV.js +1 -0
- package/dist/app/assets/railroadDiagram-MRQ6NCDL-wGcmIMqq.js +1 -0
- package/dist/app/assets/requirementDiagram-Y7LWUY3S-DprFI03z.js +84 -0
- package/dist/app/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/app/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/dist/app/assets/sankeyDiagram-WGJFYUXA-DygYWLTR.js +40 -0
- package/dist/app/assets/sequenceDiagram-5NDRBG5M-BzIr2DBO.js +169 -0
- package/dist/app/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
- package/dist/app/assets/stateDiagram-v2-FJ4FJNEA-MGCqKnm_.js +291 -0
- package/dist/app/assets/swimlanes-UMQ2AFYF-CIEH82Zt.js +1 -0
- package/dist/app/assets/swimlanesDiagram-OMPLPG4O-YWNJjl0g.js +8 -0
- package/dist/app/assets/timeline-definition-SEUHKTQE-BGYSqup2.js +120 -0
- 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-dy6oVOke.js +328 -0
- package/dist/app/assets/vennDiagram-NNMJR3RB-CUyuhcAk.js +34 -0
- package/dist/app/assets/wardley-7MLQ67FV-sYPAvQ06.js +1 -0
- package/dist/app/assets/wardleyDiagram-S7YFUSEH-DYtxYUHe.js +78 -0
- package/dist/app/assets/xychartDiagram-GGNKY7IX-ClR06AlB.js +7 -0
- package/dist/app/index.html +14 -0
- package/dist/cli/index.js +338 -0
- package/dist/core/api.js +420 -0
- package/dist/core/approvals.js +426 -0
- package/dist/core/context.js +259 -0
- package/dist/core/diff.js +156 -0
- package/dist/core/docs.js +140 -0
- package/dist/core/doctor.js +152 -0
- package/dist/core/doctypes.js +79 -0
- package/dist/core/edit.js +130 -0
- package/dist/core/errors.js +3 -0
- package/dist/core/flags.js +13 -0
- package/dist/core/gaps.js +119 -0
- package/dist/core/heading.js +4 -0
- package/dist/core/history.js +50 -0
- 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/links.js +68 -0
- package/dist/core/mermaid.js +175 -0
- package/dist/core/newdoc.js +66 -0
- package/dist/core/open-folder.js +30 -0
- package/dist/core/openspec.js +120 -0
- package/dist/core/paths.js +90 -0
- package/dist/core/project.js +392 -0
- package/dist/core/resolve.js +35 -0
- package/dist/core/route.js +420 -0
- package/dist/core/scan.js +514 -0
- package/dist/core/schema.js +270 -0
- package/dist/core/scope.js +126 -0
- package/dist/core/setup.js +134 -0
- package/dist/core/skills.js +181 -0
- 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 +589 -0
- 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 -0
- package/dist/core/versions.js +245 -0
- package/dist/core/watch.js +2 -0
- package/dist/core/xml.js +68 -0
- 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 +785 -0
- 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 +69 -4
- package/schema/approval.schema.json +173 -0
- package/schema/gap.schema.json +56 -0
- package/schema/pins.schema.json +122 -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 +240 -0
- package/skills/claude/build-gap/SKILL.md +28 -0
- package/skills/claude/check-ui/SKILL.md +40 -0
- package/skills/claude/draw-system/SKILL.md +38 -0
- package/skills/claude/gap-from-view/SKILL.md +29 -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 +38 -0
- 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 +212 -0
- 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
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { basename, resolve } from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { readSettings } from "../core/approvals.js";
|
|
4
|
+
import { UserError } from "../core/errors.js";
|
|
5
|
+
import { AuditKindSchema, localPath, SourceKindSchema } from "../core/project.js";
|
|
6
|
+
import { realPath, ScopeError } from "../core/scope.js";
|
|
7
|
+
import { samePath } from "../core/paths.js";
|
|
8
|
+
import { resolveView } from "../core/resolve.js";
|
|
9
|
+
import { compactScan, scanSource } from "../core/scan.js";
|
|
10
|
+
import { findRelated, parentsOf, siblingFolders } from "../core/suggest.js";
|
|
11
|
+
export const PROJECT_TOOL_NAMES = [
|
|
12
|
+
"list_projects",
|
|
13
|
+
"create_project",
|
|
14
|
+
"use_project",
|
|
15
|
+
"get_project",
|
|
16
|
+
"add_source",
|
|
17
|
+
"remove_source",
|
|
18
|
+
"list_sources",
|
|
19
|
+
"record_audit",
|
|
20
|
+
"save_report",
|
|
21
|
+
"scan_source",
|
|
22
|
+
"suggest_sources",
|
|
23
|
+
];
|
|
24
|
+
/** The tools that work with no project in use. Every other tool refuses until use_project. */
|
|
25
|
+
export const NO_PROJECT_TOOLS = ["list_projects", "create_project", "use_project"];
|
|
26
|
+
/**
|
|
27
|
+
* The Project tools (PRD §9.1, §9.3). The project is the boundary: the server
|
|
28
|
+
* reads only the folders added with add_source, and never writes to them.
|
|
29
|
+
* Everything the project makes goes in its own folder.
|
|
30
|
+
*/
|
|
31
|
+
export function registerProjectTools(server, session, guard, json, text,
|
|
32
|
+
/** The active project as the tools see it (the server passes it with its writes staged). */
|
|
33
|
+
current = () => session.current,
|
|
34
|
+
/** True when this agent run already has changes waiting in Approvals. */
|
|
35
|
+
hasPending = async () => false) {
|
|
36
|
+
const ws = current;
|
|
37
|
+
const spatial = () => ws().spatial;
|
|
38
|
+
const summary = async () => {
|
|
39
|
+
const w = ws();
|
|
40
|
+
const p = await w.info();
|
|
41
|
+
// How the project writes specs (Settings → Project → Spec format): the Skills follow it.
|
|
42
|
+
const { spec_format } = await readSettings(w.spatial);
|
|
43
|
+
return { ...p, spec_format, views: await w.spatial.views.list() };
|
|
44
|
+
};
|
|
45
|
+
server.registerTool("list_projects", {
|
|
46
|
+
description: "List the Spatial Views projects (slug, name, which one is active). Start every Skill here, then " +
|
|
47
|
+
"use_project. A new install has none: create_project makes one.",
|
|
48
|
+
}, async () => guard(async () => json(await session.list())));
|
|
49
|
+
server.registerTool("create_project", {
|
|
50
|
+
description: "Create a project in the Spatial Views home folder (~/SpatialViews/projects/<slug>/) with an empty " +
|
|
51
|
+
"System Overview View, and make it the active project. Then add_source each repo, docs or diagrams folder.",
|
|
52
|
+
inputSchema: { name: z.string().min(1) },
|
|
53
|
+
}, async ({ name }) => guard(async () => {
|
|
54
|
+
await session.create(name);
|
|
55
|
+
return json({ ...(await summary()), active: true });
|
|
56
|
+
}));
|
|
57
|
+
server.registerTool("use_project", {
|
|
58
|
+
description: "Make a project the active one (slug or name, from list_projects). Every other tool works on the " +
|
|
59
|
+
"active project only, and reads only its sources.",
|
|
60
|
+
inputSchema: { project: z.string().min(1).describe("slug or name") },
|
|
61
|
+
}, async ({ project }) => guard(async () => {
|
|
62
|
+
await session.use(project);
|
|
63
|
+
return json({ active: true, ...(await summary()) });
|
|
64
|
+
}));
|
|
65
|
+
server.registerTool("get_project", {
|
|
66
|
+
description: "The active project: name, slug, its sources (with last_audit_sha), past audits, its Views, and spec_format: " +
|
|
67
|
+
"spatial-views (specs are PRD, MDD and Gap docs) or openspec (openspec/specs and openspec/changes).",
|
|
68
|
+
}, async () => guard(async () => json(await summary())));
|
|
69
|
+
server.registerTool("add_source", {
|
|
70
|
+
description: "Add a folder to the active project as a read-only source: a repo, docs or diagrams. Give the full " +
|
|
71
|
+
"path, Windows (c:\\git\\api) or POSIX. Without kind: repo if it has .git, diagrams if its name says " +
|
|
72
|
+
"so, else docs. A repo gets a module on the System Overview. The server only ever reads it, and " +
|
|
73
|
+
"reads no folder that is not a source. Adding the same folder again returns the source already there.",
|
|
74
|
+
inputSchema: {
|
|
75
|
+
path: z.string().min(1),
|
|
76
|
+
kind: SourceKindSchema.optional(),
|
|
77
|
+
id: z.string().optional().describe("a file-safe id; made from the folder name if left out"),
|
|
78
|
+
name: z.string().optional().describe("what to call it (default: the folder name)"),
|
|
79
|
+
},
|
|
80
|
+
}, async (input) => guard(async () => json(await ws().addSource(input))));
|
|
81
|
+
server.registerTool("remove_source", {
|
|
82
|
+
description: "Take a source off the active project (id or path), and its module off the System Overview. The " +
|
|
83
|
+
"folder itself is not touched. After this the server no longer reads it.",
|
|
84
|
+
inputSchema: { source: z.string().min(1).describe("source id or path") },
|
|
85
|
+
}, async ({ source }) => guard(async () => json(await ws().removeSource(source))));
|
|
86
|
+
server.registerTool("list_sources", {
|
|
87
|
+
description: "List the active project's sources (id, name, kind, path, added, last_audit_sha), optionally of one kind.",
|
|
88
|
+
inputSchema: { kind: SourceKindSchema.optional() },
|
|
89
|
+
}, async ({ kind }) => guard(async () => json((await ws().project.get()).sources.filter((s) => !kind || s.kind === kind))));
|
|
90
|
+
server.registerTool("record_audit", {
|
|
91
|
+
description: "Record that an audit ran (pre-audit, update-state or post-audit), with its report. Each source it " +
|
|
92
|
+
"read gets last_audit_sha: the sha given in shas, else the repo's current commit, else the time " +
|
|
93
|
+
"(docs and diagrams). update-state reads changes since that. A pre-audit also sets the project's " +
|
|
94
|
+
"root_view_id (the System Overview), the View the project always opens on.",
|
|
95
|
+
inputSchema: {
|
|
96
|
+
kind: AuditKindSchema,
|
|
97
|
+
report: z.string().optional().describe("a report saved with save_report (its name, or reports/<name>.md)"),
|
|
98
|
+
sources: z.array(z.string()).optional().describe("the source ids read (default: all)"),
|
|
99
|
+
shas: z.record(z.string(), z.string()).optional().describe("source id -> commit sha"),
|
|
100
|
+
},
|
|
101
|
+
}, async (input) => guard(async () => {
|
|
102
|
+
const w = ws();
|
|
103
|
+
// A pre-audit sets root_view_id: the project always opens on its System Overview.
|
|
104
|
+
const root = input.kind === "pre-audit" ? (await w.landing())?.id : undefined;
|
|
105
|
+
return json(await w.project.recordAudit({ ...input, ...(root ? { root_view_id: root } : {}) }));
|
|
106
|
+
}));
|
|
107
|
+
server.registerTool("save_report", {
|
|
108
|
+
description: "Write a markdown report to the project's reports/<name>.md (never anywhere else, never into a source) " +
|
|
109
|
+
"and pin it to a View: the one given, else the System Overview. Use for onboarding, changes and audit-report.",
|
|
110
|
+
inputSchema: {
|
|
111
|
+
name: z.string().min(1).describe("e.g. onboarding, changes-2026-11-21, audit-report"),
|
|
112
|
+
markdown: z.string().min(1),
|
|
113
|
+
view: z.string().optional().describe("View id or name to pin to (default: the System Overview)"),
|
|
114
|
+
},
|
|
115
|
+
}, async ({ name, markdown, view }) => guard(async () => {
|
|
116
|
+
const all = await spatial().views.listViews();
|
|
117
|
+
const target = view ? resolveView(all, view) : await ws().overview(false);
|
|
118
|
+
if (view && !target)
|
|
119
|
+
throw new UserError(`no View ${view}`);
|
|
120
|
+
// A report goes with the run's changes: with approvals on, it waits in the same Approval.
|
|
121
|
+
// An audit that changed nothing has no Approval, so its report is written straight away
|
|
122
|
+
// (to the project's reports/, never to a source) and no empty Approval is made.
|
|
123
|
+
const w = (await hasPending()) ? ws() : session.current;
|
|
124
|
+
await w.project.get();
|
|
125
|
+
const path = await w.spatial.docs.write(w.project.reportRel(name), markdown.endsWith("\n") ? markdown : markdown + "\n");
|
|
126
|
+
if (!target)
|
|
127
|
+
return text(`wrote ${path}; not pinned (no System Overview yet; pass view, or pin it later)`);
|
|
128
|
+
await w.spatial.pins.add({ path, kind: "view", view_id: target.id });
|
|
129
|
+
return text(`wrote ${path}, pinned to View ${target.name} (${target.id})`);
|
|
130
|
+
}));
|
|
131
|
+
server.registerTool("scan_source", {
|
|
132
|
+
description: "Read one of the active project's sources (read-only, size-capped) so you can draw it. Only a " +
|
|
133
|
+
"source id (or its path) from list_sources: any other folder is refused. Symlinks are not followed. " +
|
|
134
|
+
"Repos: tree, languages, manifests, " +
|
|
135
|
+
"entry points, HTTP routes, queue and DB use, and calls to other sources (target is the source id). " +
|
|
136
|
+
"Docs: the .md files (kind prd, sdd, tdd, pbi, openspec-spec, ...) and OpenSpec specs and changes. " +
|
|
137
|
+
"Diagrams: Mermaid and draw.io parsed to nodes and edges (sequence diagrams to participants and " +
|
|
138
|
+
"messages); images, PDFs and Miro CSVs are listed for you to open and read. Empty lists are left " +
|
|
139
|
+
"out; truncated says a cap was hit.",
|
|
140
|
+
inputSchema: {
|
|
141
|
+
source_id: z.string().min(1).describe("a source id from list_sources"),
|
|
142
|
+
max_files: z.number().int().positive().max(20000).optional().describe("files walked (default 5000)"),
|
|
143
|
+
},
|
|
144
|
+
}, async ({ source_id, max_files }) => guard(async () => {
|
|
145
|
+
const w = ws();
|
|
146
|
+
const p = await w.project.get();
|
|
147
|
+
const s = p.sources.find((x) => x.id === source_id) ?? (await sourceByPath(w, source_id));
|
|
148
|
+
if (!s)
|
|
149
|
+
throw new ScopeError(`${source_id} is not a source of ${p.name}. Allowed: ${await w.allowed()}`);
|
|
150
|
+
const others = p.sources.filter((x) => x.id !== s.id).map((x) => x.id);
|
|
151
|
+
const abs = await realPath(w.project.sourcePath(s));
|
|
152
|
+
const r = await scanSource(abs, s.kind, others, max_files ? { maxFiles: max_files } : {});
|
|
153
|
+
return json({ source: s, ...compactScan(r) });
|
|
154
|
+
}));
|
|
155
|
+
server.registerTool("suggest_sources", {
|
|
156
|
+
description: "Which other repos does this source point at? Read-only, and only inside the source (a source id " +
|
|
157
|
+
"from list_sources). Evidence: internal package dependencies, API base URLs and hostnames, queue and " +
|
|
158
|
+
"topic names, git remotes and submodules, docker-compose and k8s service names, and docs that name " +
|
|
159
|
+
"another repo. Returns [{name, evidence: [{file, line, text}], candidate_paths}]. candidate_paths " +
|
|
160
|
+
"are folders next to the project's sources whose name matches, found by listing those folders only: " +
|
|
161
|
+
"nothing inside them is read. Adds nothing: ask the user, then add_source the ones they want.",
|
|
162
|
+
inputSchema: { source_id: z.string().min(1).describe("a source id from list_sources") },
|
|
163
|
+
}, async ({ source_id }) => guard(async () => {
|
|
164
|
+
const w = ws();
|
|
165
|
+
const p = await w.project.get();
|
|
166
|
+
const s = p.sources.find((x) => x.id === source_id) ?? (await sourceByPath(w, source_id));
|
|
167
|
+
if (!s)
|
|
168
|
+
throw new ScopeError(`${source_id} is not a source of ${p.name}. Allowed: ${await w.allowed()}`);
|
|
169
|
+
const real = await Promise.all(p.sources.map((x) => realPath(w.project.sourcePath(x))));
|
|
170
|
+
const mine = new Set(real.map((x) => resolve(x)));
|
|
171
|
+
const siblings = (await siblingFolders(parentsOf(real))).filter((x) => !mine.has(resolve(x)));
|
|
172
|
+
const self = p.sources.flatMap((x, i) => [x.id, x.name ?? x.id, basename(real[i])]);
|
|
173
|
+
const abs = real[p.sources.findIndex((x) => x.id === s.id)];
|
|
174
|
+
return json(await findRelated(abs, { self, siblings }));
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
/** The source whose folder is exactly this path, as written or by the source's real path (no other folder is looked at). */
|
|
178
|
+
async function sourceByPath(w, path) {
|
|
179
|
+
const p = await w.project.get();
|
|
180
|
+
let want;
|
|
181
|
+
try {
|
|
182
|
+
want = resolve(localPath(w.spatial.root, path));
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
for (const s of p.sources) {
|
|
188
|
+
const at = resolve(w.project.sourcePath(s));
|
|
189
|
+
if (s.path === path.trim() || samePath(at, want) || samePath(await realPath(at), want))
|
|
190
|
+
return s;
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|