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,66 @@
|
|
|
1
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { DEFAULT_SOURCES } from "./docs.js";
|
|
4
|
+
import { UserError } from "./errors.js";
|
|
5
|
+
import { resolveDocPath, ProjectStore } from "./project.js";
|
|
6
|
+
import { fillTemplate, findDocType, loadDocTypes, slug } from "./types.js";
|
|
7
|
+
const exists = async (abs) => !!(await stat(abs).catch(() => null));
|
|
8
|
+
/**
|
|
9
|
+
* Make a doc from a doc type's template (a toolbox's docs) and pin it to a
|
|
10
|
+
* module or a View. In a repo it goes in the type's folder (docs/ by default),
|
|
11
|
+
* named from the title; in a project (home mode) it goes in the project's
|
|
12
|
+
* reports. An existing file is never overwritten: the name gets -2, -3...
|
|
13
|
+
*/
|
|
14
|
+
export async function createDoc(spatial, input) {
|
|
15
|
+
const type = findDocType(await loadDocTypes(spatial.dataDir, input.dirs), input.type);
|
|
16
|
+
const owner = input.module?.name ?? input.view?.name ?? "";
|
|
17
|
+
const title = input.title?.trim() ||
|
|
18
|
+
fillTemplate(type.title, { type: type.name, module: owner, view: input.view?.name ?? "" }).replace(/\s+/g, " ").trim() ||
|
|
19
|
+
type.name;
|
|
20
|
+
const text = fillTemplate(type.template, { title, module: input.module?.name ?? "", view: input.view?.name ?? "" });
|
|
21
|
+
let path;
|
|
22
|
+
if (spatial.mode === "home") {
|
|
23
|
+
const store = ProjectStore.of(spatial);
|
|
24
|
+
const base = slug(input.path?.replace(/\.md$/i, "") ?? title);
|
|
25
|
+
let name = base;
|
|
26
|
+
for (let n = 2; await exists(await store.reportPath(name)); n++)
|
|
27
|
+
name = `${base}-${n}`;
|
|
28
|
+
path = await store.saveReport(name, text);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
let rel;
|
|
32
|
+
if (input.path) {
|
|
33
|
+
rel = input.path.trim();
|
|
34
|
+
if (!rel.toLowerCase().endsWith(".md"))
|
|
35
|
+
throw new UserError(`${rel}: a doc is a .md file`);
|
|
36
|
+
const doc = await resolveDocPath(spatial, rel);
|
|
37
|
+
if (doc.source)
|
|
38
|
+
throw new UserError(`${rel}: new docs go in the repo, not in a source`);
|
|
39
|
+
if (await exists(doc.abs))
|
|
40
|
+
throw new UserError(`${doc.rel} already exists`);
|
|
41
|
+
rel = doc.rel;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const base = `${type.folder}/${slug(title)}`;
|
|
45
|
+
rel = `${base}.md`;
|
|
46
|
+
for (let n = 2; await exists((await resolveDocPath(spatial, rel)).abs); n++)
|
|
47
|
+
rel = `${base}-${n}.md`;
|
|
48
|
+
}
|
|
49
|
+
const doc = await resolveDocPath(spatial, rel);
|
|
50
|
+
await mkdir(dirname(doc.abs), { recursive: true });
|
|
51
|
+
await writeFile(doc.abs, text.endsWith("\n") ? text : `${text}\n`, { encoding: "utf8", flag: "wx" });
|
|
52
|
+
path = doc.rel;
|
|
53
|
+
// A folder outside docs/ and openspec/ becomes a doc source, so the Docs panel lists it.
|
|
54
|
+
const top = path.split("/")[0];
|
|
55
|
+
if (path.includes("/") && !DEFAULT_SOURCES.includes(top))
|
|
56
|
+
await spatial.pins.addSource(top);
|
|
57
|
+
}
|
|
58
|
+
let pin;
|
|
59
|
+
if (input.view && input.module)
|
|
60
|
+
pin = { path, kind: "module", view_id: input.view.id, module_id: input.module.id };
|
|
61
|
+
else if (input.view)
|
|
62
|
+
pin = { path, kind: "view", view_id: input.view.id };
|
|
63
|
+
if (pin)
|
|
64
|
+
await spatial.pins.add(pin);
|
|
65
|
+
return { path, type, title, ...(pin ? { pin } : {}) };
|
|
66
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
2
|
+
import { detectWsl } from "./skills.js";
|
|
3
|
+
/** How to open a folder in the system's file manager, for this platform. */
|
|
4
|
+
export function folderCommand(dir, platform = process.platform, wsl = detectWsl()) {
|
|
5
|
+
if (platform === "win32")
|
|
6
|
+
return ["explorer.exe", [dir]];
|
|
7
|
+
if (platform === "darwin")
|
|
8
|
+
return ["open", [dir]];
|
|
9
|
+
if (wsl) {
|
|
10
|
+
// Windows Explorer, on the folder's \\wsl$ path.
|
|
11
|
+
let win = dir;
|
|
12
|
+
try {
|
|
13
|
+
win = execFileSync("wslpath", ["-w", dir], { encoding: "utf8" }).trim() || dir;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// wslpath missing: Explorer still opens on the Linux path's parent, if at all.
|
|
17
|
+
}
|
|
18
|
+
return ["explorer.exe", [win]];
|
|
19
|
+
}
|
|
20
|
+
return ["xdg-open", [dir]];
|
|
21
|
+
}
|
|
22
|
+
/** Open `dir` in the file manager. Resolves once launched; rejects if the command can't start. */
|
|
23
|
+
export function openFolder(dir) {
|
|
24
|
+
const [cmd, args] = folderCommand(dir);
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
|
|
27
|
+
child.once("error", (e) => reject(new Error(`could not open ${dir} (${cmd}: ${e.message})`)));
|
|
28
|
+
child.once("spawn", () => (child.unref(), resolve()));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { readFile, readdir, stat } 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
|
+
/** Writes a doc into the project's store (Spatial.docs.write). */
|
|
112
|
+
write) {
|
|
113
|
+
const rel = `openspec/changes/${input.id}`;
|
|
114
|
+
if (await findChange(root, input.id))
|
|
115
|
+
throw new UserError(`an OpenSpec change ${input.id} already exists`);
|
|
116
|
+
const where = input.modules.map((m) => `- ${m} (View: ${input.view})`).join("\n");
|
|
117
|
+
await write(`${rel}/proposal.md`, `# ${input.title}\n\n## Why\n${input.intent || "TBD"}\n\n## What Changes\n- TBD\n\n## Impact\n${where || "- TBD"}\n`);
|
|
118
|
+
await write(`${rel}/tasks.md`, `## 1. Implementation\n- [ ] 1.1 TBD\n`);
|
|
119
|
+
return rel;
|
|
120
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, posix, relative, resolve, sep, win32 } from "node:path";
|
|
3
|
+
import { UserError } from "./errors.js";
|
|
4
|
+
/** A Windows drive path (`c:\git\x`, `D:/docs`) or a network path (`\\server\share`). */
|
|
5
|
+
export const WIN_ABS = /^[A-Za-z]:[\\/]|^\\\\/;
|
|
6
|
+
/** A Windows drive as WSL mounts it: `/mnt/c/git/x`. */
|
|
7
|
+
const MNT = /^\/mnt\/([A-Za-z])(?:\/(.*))?$/;
|
|
8
|
+
/**
|
|
9
|
+
* An absolute path in this OS's spelling, or null when `p` is not absolute in
|
|
10
|
+
* either spelling. A Windows path made in WSL and a WSL path made on Windows
|
|
11
|
+
* both work: `c:\git\x` is `/mnt/c/git/x` in WSL and Linux, and `/mnt/c/git/x`
|
|
12
|
+
* is `c:\git\x` on Windows.
|
|
13
|
+
*/
|
|
14
|
+
export function nativeAbs(p, platform = process.platform) {
|
|
15
|
+
const raw = p.trim();
|
|
16
|
+
if (platform === "win32") {
|
|
17
|
+
const m = MNT.exec(raw.replace(/\\/g, "/"));
|
|
18
|
+
if (m)
|
|
19
|
+
return win32.join(`${m[1].toLowerCase()}:\\`, ...(m[2] ?? "").split("/").filter(Boolean));
|
|
20
|
+
return win32.isAbsolute(raw) ? win32.resolve(raw) : null;
|
|
21
|
+
}
|
|
22
|
+
if (WIN_ABS.test(raw)) {
|
|
23
|
+
if (raw.startsWith("\\\\"))
|
|
24
|
+
throw new UserError(`${p}: network paths are not supported here`);
|
|
25
|
+
return posix.join("/mnt", raw[0].toLowerCase(), ...raw.slice(3).split(/[\\/]+/).filter(Boolean));
|
|
26
|
+
}
|
|
27
|
+
return posix.isAbsolute(raw) ? posix.resolve(raw) : null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* macOS keeps /var, /tmp and /etc as links into /private. The real spelling of
|
|
31
|
+
* such a path, worked out from the text alone (nothing on disk is looked at).
|
|
32
|
+
*/
|
|
33
|
+
export function macReal(p, platform = process.platform) {
|
|
34
|
+
return platform === "darwin" && /^\/(?:var|tmp|etc)(?:\/|$)/.test(p) ? `/private${p}` : p;
|
|
35
|
+
}
|
|
36
|
+
/** True when `p` is a file system root: `/`, a drive (`C:\`, `D:\`) or a share (`\\server\share\`). */
|
|
37
|
+
export function isFsRoot(p, platform = process.platform) {
|
|
38
|
+
const path = platform === "win32" ? win32 : posix;
|
|
39
|
+
const r = path.resolve(p);
|
|
40
|
+
return r === path.parse(r).root;
|
|
41
|
+
}
|
|
42
|
+
/** True when `p` is absolute in either spelling (`c:\git\x` or `/mnt/c/git/x`). */
|
|
43
|
+
export function isAnyAbs(p) {
|
|
44
|
+
const raw = p.trim();
|
|
45
|
+
return WIN_ABS.test(raw) || isAbsolute(raw) || raw.startsWith("/");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The same folder, compared as written: Windows paths ignore case (the file
|
|
49
|
+
* system does), both spellings of a drive path are equal, and so are /var and
|
|
50
|
+
* /private/var on macOS.
|
|
51
|
+
*/
|
|
52
|
+
export function samePath(a, b, platform = process.platform) {
|
|
53
|
+
const na = nativeAbs(a, platform) ?? a;
|
|
54
|
+
const nb = nativeAbs(b, platform) ?? b;
|
|
55
|
+
return platform === "win32" ? na.toLowerCase() === nb.toLowerCase() : macReal(na, platform) === macReal(nb, platform);
|
|
56
|
+
}
|
|
57
|
+
/** The root's real path (the root itself is always in scope). */
|
|
58
|
+
function realRoot(root) {
|
|
59
|
+
try {
|
|
60
|
+
return realpathSync.native(root);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return resolve(root);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A repo-relative, forward-slash path for `p`, refusing anything outside the
|
|
68
|
+
* repo (absolute paths elsewhere, `..` escapes). Pins and pointers are stored
|
|
69
|
+
* in this form so they diff the same on every OS.
|
|
70
|
+
*/
|
|
71
|
+
export function repoPath(root, p) {
|
|
72
|
+
const raw = p.trim();
|
|
73
|
+
if (!raw)
|
|
74
|
+
throw new UserError("a path is needed");
|
|
75
|
+
const abs = nativeAbs(raw) ?? resolve(root, raw);
|
|
76
|
+
const out = (r) => r.startsWith("..") || isAbsolute(r);
|
|
77
|
+
let rel = relative(resolve(root), abs);
|
|
78
|
+
// The root may be given through a symlink and the path by its real name.
|
|
79
|
+
if (out(rel))
|
|
80
|
+
rel = relative(realRoot(root), macReal(abs));
|
|
81
|
+
if (rel === "")
|
|
82
|
+
return ".";
|
|
83
|
+
if (out(rel))
|
|
84
|
+
throw new UserError(`${p} is outside the repo`);
|
|
85
|
+
return rel.split(sep).join("/");
|
|
86
|
+
}
|
|
87
|
+
/** The absolute path of a repo-relative path (already checked by repoPath). */
|
|
88
|
+
export function absPath(root, rel) {
|
|
89
|
+
return resolve(root, repoPath(root, rel));
|
|
90
|
+
}
|