spatial-views 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -19
- package/dist/app/assets/{abnfDiagram-S7VZAUFO-BVgtb0Hw.js → abnfDiagram-S7VZAUFO-CFbb_Sz2.js} +1 -1
- package/dist/app/assets/{architecture-WOLXFQ4H-DxylGHqT.js → architecture-WOLXFQ4H-CsBD__5a.js} +1 -1
- package/dist/app/assets/architectureDiagram-YGSQEFNW-C0ic4ib1.js +36 -0
- package/dist/app/assets/{blockDiagram-APKKGZFW-C7fb3MCE.js → blockDiagram-APKKGZFW-BZDPbzAG.js} +1 -1
- package/dist/app/assets/{c4Diagram-KJ2TOQU5-Bkb_0fbd.js → c4Diagram-KJ2TOQU5-BilBWuq5.js} +1 -1
- package/dist/app/assets/{chunk-6MUBBAK2-DU4vZ03M.js → chunk-6MUBBAK2-BBl-4tQr.js} +1 -1
- package/dist/app/assets/{chunk-AXFCVDMN-De96BVTB.js → chunk-AXFCVDMN-BhsttQ-k.js} +1 -1
- package/dist/app/assets/{chunk-BG4553SI-J33jsRLV.js → chunk-BG4553SI-mWcPcFZr.js} +2 -2
- package/dist/app/assets/{chunk-DQASFODM-Bh85SSGO.js → chunk-DQASFODM-7FKe2gLt.js} +1 -1
- package/dist/app/assets/{chunk-HFQBQIA3-CCklgplR.js → chunk-HFQBQIA3-nXrQ08BL.js} +1 -1
- package/dist/app/assets/{chunk-KQLB2F66-B04qR8ED.js → chunk-KQLB2F66-swukhFmZ.js} +1 -1
- package/dist/app/assets/{chunk-KS47KZWR-BsqDyyAt.js → chunk-KS47KZWR-DkDkwO82.js} +1 -1
- package/dist/app/assets/{chunk-LEVMRMFU-DwxrBz2u.js → chunk-LEVMRMFU-DXH6iXv3.js} +1 -1
- package/dist/app/assets/{chunk-M57EVK23-D9YIHjps.js → chunk-M57EVK23-B-kEyOJF.js} +1 -1
- package/dist/app/assets/{chunk-OY52VR5R-WB63DeTA.js → chunk-OY52VR5R-DweG7qYw.js} +1 -1
- package/dist/app/assets/{chunk-QB3YPZ4I-cHzzKdtb.js → chunk-QB3YPZ4I-DyozK3lV.js} +1 -1
- package/dist/app/assets/{chunk-R3KSYZAL-C7rDagaa.js → chunk-R3KSYZAL-BEXCUN6J.js} +1 -1
- package/dist/app/assets/{chunk-STOXU5M4-CG6pnJtH.js → chunk-STOXU5M4-BaTlty4O.js} +1 -1
- package/dist/app/assets/{chunk-TU62E6Q5-BbcGYfy_.js → chunk-TU62E6Q5-_rcUP1Fh.js} +1 -1
- package/dist/app/assets/chunk-X3CZISLH-NOpCnvgE.js +1 -0
- package/dist/app/assets/{chunk-X4PVCEUW-BUI1Oi3q.js → chunk-X4PVCEUW-DGxTL3kB.js} +1 -1
- package/dist/app/assets/{chunk-XXDRQBXY-DYhK5YW-.js → chunk-XXDRQBXY-C02Gpej2.js} +1 -1
- package/dist/app/assets/{classDiagram-v2-L25IHNXF-K-k5GTUn.js → classDiagram-v2-L25IHNXF-DLEBwpvk.js} +1 -1
- package/dist/app/assets/cose-bilkent-JH36ORCC-kNCXOm8k.js +1 -0
- package/dist/app/assets/cynefin-EF2NZ3EQ-6MWNLbuF.js +1 -0
- package/dist/app/assets/{cynefinDiagram-L36ESFBY-mkV33_Xx.js → cynefinDiagram-L36ESFBY-CLFstukD.js} +1 -1
- package/dist/app/assets/{d3-scale-ygdFCUH8.js → d3-scale-CaJQQYkF.js} +1 -1
- package/dist/app/assets/{dagre-SPEB5RXH-BNIymLsu.js → dagre-SPEB5RXH-BaSAny1T.js} +1 -1
- package/dist/app/assets/{diagram-3B7GL73J-CGOiolFW.js → diagram-3B7GL73J-DJNlt5Sg.js} +1 -1
- package/dist/app/assets/{diagram-DNEMPZML-DZFkHNly.js → diagram-DNEMPZML-DEHeuILB.js} +1 -1
- package/dist/app/assets/{diagram-L3MUGCDN-B42GAYLq.js → diagram-L3MUGCDN-ob5Ka2Xc.js} +1 -1
- package/dist/app/assets/{diagram-LA4NIPWU-BYuLRYId.js → diagram-LA4NIPWU-DNESzFAc.js} +1 -1
- package/dist/app/assets/{diagram-MHCOC4E2-DGzI6TJG.js → diagram-MHCOC4E2-CVi9zKjG.js} +1 -1
- package/dist/app/assets/{diagram-XPFHEONP-CTBEgDQ8.js → diagram-XPFHEONP-DInT4C7e.js} +1 -1
- package/dist/app/assets/dist-CjvHN74u.js +1 -0
- package/dist/app/assets/{ebnfDiagram-UZSYDL2S-GuMdOCvL.js → ebnfDiagram-UZSYDL2S-CRCZNsji.js} +1 -1
- package/dist/app/assets/{elk-XV6XMXQE-BpY3loT5.js → elk-XV6XMXQE-D4fsWI2l.js} +1 -1
- package/dist/app/assets/{erDiagram-EYBAPDEH-nDZ2PMGl.js → erDiagram-EYBAPDEH-YQNM5StV.js} +1 -1
- package/dist/app/assets/{eventmodeling-K75KTNOO-BN42Mgwh.js → eventmodeling-K75KTNOO-Bev08J2F.js} +1 -1
- package/dist/app/assets/flowDiagram-MALGAFMO-BhJ554DH.js +1 -0
- package/dist/app/assets/ganttDiagram-23REXITY-CkaBMYM4.js +292 -0
- package/dist/app/assets/gitGraph-VSP46ZUC-CtbZ0sIS.js +1 -0
- package/dist/app/assets/{gitGraphDiagram-STJD7YCW-CDkKLrvO.js → gitGraphDiagram-STJD7YCW-D15ZdQ-Z.js} +1 -1
- package/dist/app/assets/index-Bn6_wHEp.js +98 -0
- package/dist/app/assets/index-H-Z7MFhZ.css +1 -0
- package/dist/app/assets/info-OHQRW6UA-CfUW1XFR.js +1 -0
- package/dist/app/assets/{infoDiagram-KBXO4MBG-B92P8pjY.js → infoDiagram-KBXO4MBG-DT7LbBRQ.js} +1 -1
- package/dist/app/assets/{ishikawaDiagram-M35NCXHK-BRZsbCvK.js → ishikawaDiagram-M35NCXHK-CF51lhjB.js} +1 -1
- package/dist/app/assets/{journeyDiagram-OPLOXDXO-Bppwb1oF.js → journeyDiagram-OPLOXDXO-_36FonKk.js} +1 -1
- package/dist/app/assets/{kanban-definition-BZKZHSQY-ByD_x5cm.js → kanban-definition-BZKZHSQY-tLk_OlQ-.js} +1 -1
- package/dist/app/assets/{mermaid-parser.core-CKmnV0Md.js → mermaid-parser.core-_3Vo8x6b.js} +3 -3
- package/dist/app/assets/mermaid.core-y-x1CYxC.js +44 -0
- package/dist/app/assets/{mindmap-definition-I2QAS2VK-fRbUh23C.js → mindmap-definition-I2QAS2VK-BCI4HRX3.js} +1 -1
- package/dist/app/assets/packet-JDAUHWVQ-Cco3UoaI.js +1 -0
- package/dist/app/assets/{pegDiagram-FD4XPPHP-qIABf6H8.js → pegDiagram-FD4XPPHP-BOzSoNji.js} +1 -1
- package/dist/app/assets/pie-XZMESJXO-reOB2GXn.js +1 -0
- package/dist/app/assets/{pieDiagram-J4AKIIQI-Bb4RBdrc.js → pieDiagram-J4AKIIQI-PlHpwT_c.js} +1 -1
- package/dist/app/assets/{quadrantDiagram-XTYBLID2-B0CpcVWE.js → quadrantDiagram-XTYBLID2-CdxZ0ael.js} +1 -1
- package/dist/app/assets/radar-ABXABTNO-DfCl8uV2.js +1 -0
- package/dist/app/assets/railroad-I3PHUGI6-4s14UyW1.js +1 -0
- package/dist/app/assets/{railroad-abnf-LNEFI6M7-BUhw7Iuo.js → railroad-abnf-LNEFI6M7-C49jJE4Y.js} +1 -1
- package/dist/app/assets/{railroad-ebnf-DWYD2UWJ-nQNF56LJ.js → railroad-ebnf-DWYD2UWJ-Bx-pcPc7.js} +1 -1
- package/dist/app/assets/{railroad-peg-JR7BVNR7-CwvbVIo6.js → railroad-peg-JR7BVNR7-DjBPSCKV.js} +1 -1
- package/dist/app/assets/{railroadDiagram-MRQ6NCDL-Dwr-mPZL.js → railroadDiagram-MRQ6NCDL-wGcmIMqq.js} +1 -1
- package/dist/app/assets/{requirementDiagram-Y7LWUY3S-Ctv2DKJM.js → requirementDiagram-Y7LWUY3S-DprFI03z.js} +1 -1
- package/dist/app/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/app/assets/{sankeyDiagram-WGJFYUXA-BvKX0eIe.js → sankeyDiagram-WGJFYUXA-DygYWLTR.js} +1 -1
- package/dist/app/assets/{sequenceDiagram-5NDRBG5M-Y4YqU2Xt.js → sequenceDiagram-5NDRBG5M-BzIr2DBO.js} +1 -1
- package/dist/app/assets/{stateDiagram-v2-FJ4FJNEA-DmjIjn4u.js → stateDiagram-v2-FJ4FJNEA-MGCqKnm_.js} +1 -1
- package/dist/app/assets/{swimlanes-UMQ2AFYF-B2O5JCjs.js → swimlanes-UMQ2AFYF-CIEH82Zt.js} +1 -1
- package/dist/app/assets/swimlanesDiagram-OMPLPG4O-YWNJjl0g.js +8 -0
- package/dist/app/assets/{timeline-definition-SEUHKTQE-DJJdixAI.js → timeline-definition-SEUHKTQE-BGYSqup2.js} +1 -1
- package/dist/app/assets/treeView-D4JQ5SDB-B39o1sJo.js +1 -0
- package/dist/app/assets/treemap-SAJKECNS-BoGxrUH4.js +1 -0
- package/dist/app/assets/{usecaseDiagram-AFA6YXN4-Bp8pXgvR.js → usecaseDiagram-AFA6YXN4-dy6oVOke.js} +1 -1
- package/dist/app/assets/{vennDiagram-NNMJR3RB-DYSfZMWT.js → vennDiagram-NNMJR3RB-CUyuhcAk.js} +1 -1
- package/dist/app/assets/wardley-7MLQ67FV-sYPAvQ06.js +1 -0
- package/dist/app/assets/{wardleyDiagram-S7YFUSEH-CGJ8qg76.js → wardleyDiagram-S7YFUSEH-DYtxYUHe.js} +1 -1
- package/dist/app/assets/{xychartDiagram-GGNKY7IX-CRSvraFc.js → xychartDiagram-GGNKY7IX-ClR06AlB.js} +1 -1
- package/dist/app/index.html +3 -2
- package/dist/cli/index.js +281 -53
- package/dist/core/api.js +262 -51
- package/dist/core/approvals.js +426 -0
- package/dist/core/context.js +68 -3
- package/dist/core/diff.js +156 -0
- package/dist/core/docs.js +9 -3
- package/dist/core/doctor.js +152 -0
- package/dist/core/doctypes.js +79 -0
- package/dist/core/edit.js +25 -0
- package/dist/core/flags.js +13 -0
- package/dist/core/gaps.js +7 -2
- package/dist/core/heading.js +4 -0
- package/dist/core/history.js +36 -5
- package/dist/core/home.js +345 -0
- package/dist/core/lanes.js +134 -0
- package/dist/core/launch.js +34 -0
- package/dist/core/layout.js +362 -0
- package/dist/core/newdoc.js +66 -0
- package/dist/core/open-folder.js +30 -0
- package/dist/core/openspec.js +6 -6
- package/dist/core/paths.js +71 -4
- package/dist/core/project.js +392 -0
- package/dist/core/route.js +420 -0
- package/dist/core/scan.js +514 -0
- package/dist/core/schema.js +170 -1
- package/dist/core/scope.js +126 -0
- package/dist/core/setup.js +134 -0
- package/dist/core/skills.js +92 -14
- package/dist/core/storage/config.js +74 -0
- package/dist/core/storage/events.js +54 -0
- package/dist/core/storage/folder-watch.js +147 -0
- package/dist/core/storage/folder.js +469 -0
- package/dist/core/storage/index.js +8 -0
- package/dist/core/storage/local.js +22 -0
- package/dist/core/storage/migrate.js +48 -0
- package/dist/core/storage/postgres.js +290 -0
- package/dist/core/storage/types.js +101 -0
- package/dist/core/storage.js +483 -77
- package/dist/core/suggest.js +283 -0
- package/dist/core/tree.js +254 -0
- package/dist/core/types.js +583 -0
- package/dist/core/version.js +1 -1
- package/dist/core/versions.js +245 -0
- package/dist/core/watch.js +2 -136
- package/dist/core/xml.js +23 -5
- package/dist/demo/args.js +58 -0
- package/dist/demo/browser.js +301 -0
- package/dist/demo/platform.js +147 -0
- package/dist/demo/run.js +198 -0
- package/dist/demo/steps.js +328 -0
- package/dist/mcp/project-tools.js +193 -0
- package/dist/mcp/server.js +493 -65
- package/examples/platform/README.md +33 -0
- package/examples/platform/api/package.json +8 -0
- package/examples/platform/api/src/auth-middleware.js +16 -0
- package/examples/platform/api/src/proxy.js +7 -0
- package/examples/platform/api/src/rate-limit.js +13 -0
- package/examples/platform/api/src/server.js +40 -0
- package/examples/platform/auth/package.json +9 -0
- package/examples/platform/auth/src/server.js +24 -0
- package/examples/platform/auth/src/tokens.js +19 -0
- package/examples/platform/auth/src/users.js +16 -0
- package/examples/platform/docs/api/PRD.md +10 -0
- package/examples/platform/docs/api/SDD.md +15 -0
- package/examples/platform/docs/auth/PRD.md +10 -0
- package/examples/platform/docs/auth/SDD.md +8 -0
- package/examples/platform/docs/frontend/PRD.md +18 -0
- package/examples/platform/docs/frontend/SDD.md +13 -0
- package/examples/platform/docs/pricing/PRD.md +9 -0
- package/examples/platform/docs/pricing/SDD.md +8 -0
- package/examples/platform/docs/products/PRD.md +9 -0
- package/examples/platform/docs/products/SDD.md +8 -0
- package/examples/platform/frontend/package.json +8 -0
- package/examples/platform/frontend/src/api-client.js +21 -0
- package/examples/platform/frontend/src/main.js +21 -0
- package/examples/platform/frontend/src/pages/products.js +12 -0
- package/examples/platform/frontend/src/pages/sign-in.js +14 -0
- package/examples/platform/frontend/src/session.js +11 -0
- package/examples/platform/pricing/package.json +9 -0
- package/examples/platform/pricing/src/cache.js +19 -0
- package/examples/platform/pricing/src/product-events.js +17 -0
- package/examples/platform/pricing/src/rules.js +19 -0
- package/examples/platform/pricing/src/server.js +32 -0
- package/examples/platform/products/package.json +9 -0
- package/examples/platform/products/src/catalog.js +20 -0
- package/examples/platform/products/src/events.js +11 -0
- package/examples/platform/products/src/search.js +9 -0
- package/examples/platform/products/src/server.js +31 -0
- package/migrations/postgres/001_init.sql +55 -0
- package/migrations/postgres/002_view_versions.sql +18 -0
- package/package.json +18 -2
- package/schema/approval.schema.json +173 -0
- package/schema/gap.schema.json +3 -0
- package/schema/project.schema.json +93 -0
- package/schema/settings.schema.json +86 -0
- package/schema/toolbox.schema.json +206 -0
- package/schema/type.schema.json +121 -0
- package/schema/view.schema.json +106 -0
- package/skills/claude/build-gap/SKILL.md +7 -0
- package/skills/claude/check-ui/SKILL.md +40 -0
- package/skills/claude/draw-system/SKILL.md +24 -9
- package/skills/claude/gap-from-view/SKILL.md +7 -0
- package/skills/claude/post-audit/SKILL.md +58 -0
- package/skills/claude/pre-audit/SKILL.md +82 -0
- package/skills/claude/update-state/SKILL.md +56 -0
- package/skills/cursor/check-ui.mdc +40 -0
- package/skills/cursor/draw-system.mdc +24 -9
- package/skills/cursor/post-audit.mdc +44 -0
- package/skills/cursor/pre-audit.mdc +49 -0
- package/skills/cursor/update-state.mdc +45 -0
- package/skills/windsurf/spatial-views.md +182 -36
- package/toolboxes/aws.yaml +43 -0
- package/toolboxes/azure.yaml +41 -0
- package/toolboxes/cloud.yaml +95 -0
- package/toolboxes/docs.yaml +111 -0
- package/toolboxes/software.yaml +114 -0
- package/toolboxes/types/docs/gap.yaml +15 -0
- package/toolboxes/types/docs/mdd.yaml +19 -0
- package/toolboxes/types/docs/plain.yaml +7 -0
- package/toolboxes/types/docs/prd.yaml +17 -0
- package/dist/app/assets/architectureDiagram-YGSQEFNW-BrBCHqUH.js +0 -36
- package/dist/app/assets/chunk-X3CZISLH-FMl4PpWt.js +0 -1
- package/dist/app/assets/cose-bilkent-JH36ORCC-BJmLLpaN.js +0 -1
- package/dist/app/assets/cynefin-EF2NZ3EQ-DrzwMKdm.js +0 -1
- package/dist/app/assets/dist-1Q8ng3tu.js +0 -1
- package/dist/app/assets/flowDiagram-MALGAFMO-BCwwiLzb.js +0 -1
- package/dist/app/assets/ganttDiagram-23REXITY-xMRHaU3y.js +0 -292
- package/dist/app/assets/gitGraph-VSP46ZUC-DyGq5mdd.js +0 -1
- package/dist/app/assets/index-BY66fc8Q.js +0 -95
- package/dist/app/assets/index-ByetEVbs.css +0 -1
- package/dist/app/assets/info-OHQRW6UA-DOBf-fQH.js +0 -1
- package/dist/app/assets/mermaid.core-BoRvk1Q-.js +0 -44
- package/dist/app/assets/packet-JDAUHWVQ-CgHq03Zj.js +0 -1
- package/dist/app/assets/pie-XZMESJXO-DtNh3cDE.js +0 -1
- package/dist/app/assets/radar-ABXABTNO-BS0FcsIX.js +0 -1
- package/dist/app/assets/railroad-I3PHUGI6-lO8vfGdI.js +0 -1
- package/dist/app/assets/swimlanesDiagram-OMPLPG4O-DhCl-Cjg.js +0 -8
- package/dist/app/assets/treeView-D4JQ5SDB-Dd1no4eE.js +0 -1
- package/dist/app/assets/treemap-SAJKECNS-t6wtsaki.js +0 -1
- package/dist/app/assets/wardley-7MLQ67FV-Bx60QTuu.js +0 -1
- package/skills/cursor/build-gap.mdc +0 -21
- package/skills/cursor/gap-from-view.mdc +0 -22
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { lstat, readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import { basename, extname, join } from "node:path";
|
|
3
|
+
import { inflateRawSync } from "node:zlib";
|
|
4
|
+
import { mermaidBlocks } from "./docs.js";
|
|
5
|
+
import { UserError } from "./errors.js";
|
|
6
|
+
import { parseFlowchart } from "./mermaid.js";
|
|
7
|
+
export const DEFAULT_LIMITS = {
|
|
8
|
+
maxFiles: 5000,
|
|
9
|
+
maxFileBytes: 256 * 1024,
|
|
10
|
+
maxTotalBytes: 16 * 1024 * 1024,
|
|
11
|
+
maxTree: 400,
|
|
12
|
+
maxDepth: 12,
|
|
13
|
+
maxHits: 200,
|
|
14
|
+
};
|
|
15
|
+
const SKIP_DIRS = new Set([
|
|
16
|
+
".git", "node_modules", "dist", "build", "out", ".next", ".nuxt", "coverage", "vendor", "target",
|
|
17
|
+
"__pycache__", ".venv", "venv", ".tox", ".idea", ".vscode", ".spatial-local", "bin", "obj",
|
|
18
|
+
]);
|
|
19
|
+
const LANGS = {
|
|
20
|
+
".ts": "TypeScript", ".tsx": "TypeScript", ".mts": "TypeScript", ".cts": "TypeScript",
|
|
21
|
+
".js": "JavaScript", ".jsx": "JavaScript", ".mjs": "JavaScript", ".cjs": "JavaScript",
|
|
22
|
+
".py": "Python", ".go": "Go", ".rs": "Rust", ".java": "Java", ".kt": "Kotlin", ".cs": "C#",
|
|
23
|
+
".rb": "Ruby", ".php": "PHP", ".swift": "Swift", ".scala": "Scala", ".c": "C", ".h": "C",
|
|
24
|
+
".cpp": "C++", ".hpp": "C++", ".sql": "SQL", ".sh": "Shell", ".ps1": "PowerShell",
|
|
25
|
+
".vue": "Vue", ".svelte": "Svelte", ".html": "HTML", ".css": "CSS", ".scss": "CSS",
|
|
26
|
+
};
|
|
27
|
+
const CODE = new Set(Object.keys(LANGS).filter((e) => ![".html", ".css", ".scss", ".sql"].includes(e)));
|
|
28
|
+
const MANIFESTS = {
|
|
29
|
+
"package.json": "npm", "pyproject.toml": "python", "requirements.txt": "python", "setup.py": "python",
|
|
30
|
+
"go.mod": "go", "Cargo.toml": "cargo", "pom.xml": "maven", "build.gradle": "gradle",
|
|
31
|
+
"build.gradle.kts": "gradle", "Gemfile": "ruby", "composer.json": "php", "Dockerfile": "docker",
|
|
32
|
+
"docker-compose.yml": "compose", "docker-compose.yaml": "compose", "compose.yml": "compose",
|
|
33
|
+
"compose.yaml": "compose", "serverless.yml": "serverless", "Procfile": "procfile",
|
|
34
|
+
};
|
|
35
|
+
const ENTRY = /^(main|index|server|app|worker|cli|program|handler|lambda)\.[a-z]+$/i;
|
|
36
|
+
/** Walk a folder breadth-first, without following symlinks, within the limits. */
|
|
37
|
+
async function walk(root, lim, out) {
|
|
38
|
+
const files = [];
|
|
39
|
+
let queue = [{ rel: "", depth: 0 }];
|
|
40
|
+
while (queue.length) {
|
|
41
|
+
const next = [];
|
|
42
|
+
for (const dir of queue) {
|
|
43
|
+
let names;
|
|
44
|
+
try {
|
|
45
|
+
names = (await readdir(join(root, dir.rel))).sort();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
const rel = dir.rel ? `${dir.rel}/${name}` : name;
|
|
52
|
+
const st = await lstat(join(root, rel)).catch(() => null);
|
|
53
|
+
if (!st || st.isSymbolicLink())
|
|
54
|
+
continue;
|
|
55
|
+
if (st.isDirectory()) {
|
|
56
|
+
if (SKIP_DIRS.has(name) || dir.depth + 1 > lim.maxDepth) {
|
|
57
|
+
if (out.skipped.dirs.length < 50)
|
|
58
|
+
out.skipped.dirs.push(rel);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
next.push({ rel, depth: dir.depth + 1 });
|
|
62
|
+
}
|
|
63
|
+
else if (st.isFile()) {
|
|
64
|
+
if (files.length >= lim.maxFiles) {
|
|
65
|
+
out.skipped.over_limit++;
|
|
66
|
+
out.truncated = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
files.push({ rel, abs: join(root, rel), size: st.size });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
queue = next;
|
|
74
|
+
}
|
|
75
|
+
return files.sort((a, b) => a.rel.localeCompare(b.rel));
|
|
76
|
+
}
|
|
77
|
+
const push = (list, item, lim, out) => {
|
|
78
|
+
if (list.length < lim.maxHits)
|
|
79
|
+
list.push(item);
|
|
80
|
+
else
|
|
81
|
+
out.truncated = true;
|
|
82
|
+
};
|
|
83
|
+
const lineOf = (text, index) => text.slice(0, index).split("\n").length;
|
|
84
|
+
// ---- Code ------------------------------------------------------------------
|
|
85
|
+
const ROUTE_PATTERNS = [
|
|
86
|
+
// Express, Fastify, Hono, Koa-router: app.get("/x", ...), router.post('/x'
|
|
87
|
+
/\b(?:app|router|server|api|route[rs]?|fastify|hono)\s*\.\s*(get|post|put|patch|delete|options|head|all)\s*\(\s*["'`]([^"'`]+)["'`]/gi,
|
|
88
|
+
// Python: @app.get("/x"), @router.post("/x")
|
|
89
|
+
/@\s*(?:app|router|api|bp|blueprint)\s*\.\s*(get|post|put|patch|delete)\s*\(\s*["']([^"']+)["']/gi,
|
|
90
|
+
// Spring: @GetMapping("/x")
|
|
91
|
+
/@(Get|Post|Put|Patch|Delete)Mapping\s*\(\s*(?:value\s*=\s*)?["']([^"']+)["']/g,
|
|
92
|
+
// ASP.NET minimal APIs: app.MapGet("/x"
|
|
93
|
+
/\.Map(Get|Post|Put|Patch|Delete)\s*\(\s*"([^"]+)"/g,
|
|
94
|
+
// Go: http.HandleFunc("/x", r.HandleFunc("/x"
|
|
95
|
+
/\b(?:http|mux|r|router)\s*\.\s*(Handle(?:Func)?)\s*\(\s*"([^"]+)"/g,
|
|
96
|
+
];
|
|
97
|
+
// A small route table: route("GET", "/x", ...), on('POST', '/x' ...), handle("GET", "/x"
|
|
98
|
+
const ROUTE_TABLE = /\b(?:route|addRoute|on|handle|register)\s*\(\s*["'](GET|POST|PUT|PATCH|DELETE)["']\s*,\s*["'`](\/[^"'`]*)["'`]/g;
|
|
99
|
+
// Flask: @app.route("/x", methods=["POST"])
|
|
100
|
+
const FLASK = /@\s*(?:app|bp|blueprint)\s*\.\s*route\s*\(\s*["']([^"']+)["'](?:[^)]*methods\s*=\s*\[([^\]]*)\])?/g;
|
|
101
|
+
// A plain node:http server: `if (req.method === "POST" && url === "/orders")`, either order.
|
|
102
|
+
const NODE_HTTP = [
|
|
103
|
+
/method\s*===?\s*["'](GET|POST|PUT|PATCH|DELETE)["'][^\n]{0,80}?(?:url|pathname|path)\s*===?\s*["'](\/[^"']*)["']/g,
|
|
104
|
+
/(?:url|pathname|path)\s*===?\s*["'](\/[^"']*)["'][^\n]{0,80}?method\s*===?\s*["'](GET|POST|PUT|PATCH|DELETE)["']/g,
|
|
105
|
+
];
|
|
106
|
+
const QUEUE_PATTERNS = [
|
|
107
|
+
{ re: /\.\s*(?:publish|sendToQueue|send|enqueue|produce|add|emit|sendMessage|lpush|rpush|xadd)\s*\(\s*["'`]([\w.:/-]+)["'`]/g, op: "publish" },
|
|
108
|
+
{ re: /\.\s*(?:consume|subscribe|process|on[A-Z]\w*|listen|receive|brpop|blpop|xreadgroup)\s*\(\s*["'`]([\w.:/-]+)["'`]/g, op: "consume" },
|
|
109
|
+
{ re: /new\s+(?:Queue|Topic|Exchange)\s*\(\s*["'`]([\w.:/-]+)["'`]/g, op: "declare" },
|
|
110
|
+
{ re: /new\s+(?:Worker|Consumer)\s*\(\s*["'`]([\w.:/-]+)["'`]/g, op: "consume" },
|
|
111
|
+
{ re: /\b(?:assertQueue|assertExchange|createQueue|declare_queue|queue_declare)\s*\(\s*["'`]([\w.:/-]+)["'`]/g, op: "declare" },
|
|
112
|
+
{ re: /\b(?:QueueUrl|queueUrl|queue_url|TopicArn|topic)\s*[:=]\s*["'`]([\w.:/-]+)["'`]/g, op: "publish" },
|
|
113
|
+
];
|
|
114
|
+
// Calls that only look like queue calls when the receiver says so (`.send` / `.add` are common words).
|
|
115
|
+
const QUEUE_RECEIVER = /(queue|bus|channel|broker|producer|consumer|publisher|subscriber|topic|sqs|sns|kafka|amqp|rabbit|redis|nats|pubsub|events?|mq|jobs?)\w*\s*$/i;
|
|
116
|
+
const DB_CLIENTS = [
|
|
117
|
+
[/from\s+["'](pg|postgres|mysql2?|sqlite3?|better-sqlite3|mongodb|mongoose|redis|ioredis|@prisma\/client|knex|typeorm|sequelize|drizzle-orm|kysely)["']|require\(\s*["'](pg|postgres|mysql2?|sqlite3?|better-sqlite3|mongodb|mongoose|redis|ioredis|@prisma\/client|knex|typeorm|sequelize)["']\s*\)/g, ""],
|
|
118
|
+
[/^\s*(?:import|from)\s+(psycopg2?|sqlalchemy|pymongo|redis|sqlite3|asyncpg|django\.db)\b/gm, ""],
|
|
119
|
+
[/"(database\/sql|gorm\.io\/gorm|github\.com\/lib\/pq|github\.com\/jackc\/pgx[^"]*)"/g, ""],
|
|
120
|
+
];
|
|
121
|
+
const SQL = /\b(SELECT\b[\s\S]{0,200}?\bFROM|INSERT\s+INTO|UPDATE|DELETE\s+FROM|CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?)\s+["`]?([A-Za-z_][\w.]*)["`]?/g;
|
|
122
|
+
const ORM = /\b(?:prisma|db|knex)\s*(?:\.\s*([a-z]\w*)\s*\.\s*(findMany|findUnique|findFirst|create|update|delete|upsert)\b|\(\s*["']([a-z_]\w*)["']\s*\))/g;
|
|
123
|
+
const MODEL = /\bmongoose\.model\s*\(\s*["'](\w+)["']|\bcollection\s*\(\s*["'](\w+)["']\s*\)/g;
|
|
124
|
+
const URL_LIT = /["'`](https?:\/\/[^"'`\s$]+|https?:\/\/\$\{[^}]+\}[^"'`\s]*)["'`]/g;
|
|
125
|
+
const ENV_URL = /(?:process\.env\.|os\.environ\[["']|os\.getenv\(\s*["']|Environment\.GetEnvironmentVariable\(\s*")([A-Z][A-Z0-9_]*_(?:URL|HOST|BASE|ENDPOINT|ADDR|SERVICE))/g;
|
|
126
|
+
const LOCAL_HOST = /^(localhost|127\.0\.0\.1|0\.0\.0\.0|example\.com|www\.w3\.org|schemas\.)/;
|
|
127
|
+
function scanCode(rel, text, lim, out, others) {
|
|
128
|
+
for (const re of ROUTE_PATTERNS)
|
|
129
|
+
for (const m of text.matchAll(re)) {
|
|
130
|
+
const method = /^handle/i.test(m[1]) ? "ANY" : m[1].toUpperCase();
|
|
131
|
+
push(out.http_routes, { method, path: m[2], file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
132
|
+
}
|
|
133
|
+
for (const m of text.matchAll(ROUTE_TABLE))
|
|
134
|
+
push(out.http_routes, { method: m[1], path: m[2], file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
135
|
+
for (const m of text.matchAll(FLASK)) {
|
|
136
|
+
const methods = m[2] ? [...m[2].matchAll(/["'](\w+)["']/g)].map((x) => x[1].toUpperCase()) : ["GET"];
|
|
137
|
+
for (const method of methods)
|
|
138
|
+
push(out.http_routes, { method, path: m[1], file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
139
|
+
}
|
|
140
|
+
NODE_HTTP.forEach((re, i) => {
|
|
141
|
+
for (const m of text.matchAll(re)) {
|
|
142
|
+
const [method, path] = i === 0 ? [m[1], m[2]] : [m[2], m[1]];
|
|
143
|
+
push(out.http_routes, { method, path, file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
for (const { re, op } of QUEUE_PATTERNS)
|
|
147
|
+
for (const m of text.matchAll(re)) {
|
|
148
|
+
const before = text.slice(Math.max(0, m.index - 40), m.index);
|
|
149
|
+
if (re === QUEUE_PATTERNS[0].re || re === QUEUE_PATTERNS[1].re) {
|
|
150
|
+
const verb = /\.\s*(\w+)/.exec(m[0])[1];
|
|
151
|
+
const always = /^(publish|sendToQueue|enqueue|produce|consume|subscribe|sendMessage|lpush|rpush|xadd|brpop|blpop|xreadgroup)$/.test(verb);
|
|
152
|
+
if (!always && !QUEUE_RECEIVER.test(before))
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
push(out.queues, { name: m[1], op, file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
156
|
+
}
|
|
157
|
+
for (const [re] of DB_CLIENTS)
|
|
158
|
+
for (const m of text.matchAll(re)) {
|
|
159
|
+
const name = m.slice(1).find(Boolean);
|
|
160
|
+
push(out.db, { kind: "client", name, file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
161
|
+
}
|
|
162
|
+
for (const m of text.matchAll(SQL)) {
|
|
163
|
+
const op = m[1].split(/\s+/)[0].toUpperCase();
|
|
164
|
+
push(out.db, { kind: "sql", name: m[2], op, file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
165
|
+
}
|
|
166
|
+
for (const m of text.matchAll(ORM)) {
|
|
167
|
+
const name = m[1] ?? m[3];
|
|
168
|
+
if (name)
|
|
169
|
+
push(out.db, { kind: "sql", name, op: m[2] ?? "query", file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
170
|
+
}
|
|
171
|
+
for (const m of text.matchAll(MODEL))
|
|
172
|
+
push(out.db, { kind: "sql", name: (m[1] ?? m[2]), op: "model", file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
173
|
+
const target = (s) => others.find((o) => s.toLowerCase().replace(/[_-]/g, "").includes(o.toLowerCase().replace(/[_-]/g, "")));
|
|
174
|
+
for (const m of text.matchAll(URL_LIT)) {
|
|
175
|
+
const url = m[1];
|
|
176
|
+
const host = /^https?:\/\/([^/:?#]+)/.exec(url)?.[1];
|
|
177
|
+
if (host && LOCAL_HOST.test(host) && !/:\d+/.test(url))
|
|
178
|
+
continue;
|
|
179
|
+
if (host && /^(github\.com|npmjs|registry|json-schema|spatialthinking|reactflow|mermaid)/.test(host))
|
|
180
|
+
continue;
|
|
181
|
+
const t = host ? target(host) : undefined;
|
|
182
|
+
push(out.cross_repo_calls, { url, ...(host ? { host } : {}), ...(t ? { target: t } : {}), file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
183
|
+
}
|
|
184
|
+
for (const m of text.matchAll(ENV_URL)) {
|
|
185
|
+
const t = target(m[1].replace(/_(URL|HOST|BASE|ENDPOINT|ADDR|SERVICE)$/, ""));
|
|
186
|
+
push(out.cross_repo_calls, { url: `$${m[1]}`, ...(t ? { target: t } : {}), file: rel, line: lineOf(text, m.index) }, lim, out);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function readManifest(rel, kind, text) {
|
|
190
|
+
const m = { path: rel, kind };
|
|
191
|
+
try {
|
|
192
|
+
if (kind === "npm" || kind === "php") {
|
|
193
|
+
const j = JSON.parse(text);
|
|
194
|
+
if (j.name)
|
|
195
|
+
m.name = j.name;
|
|
196
|
+
const deps = Object.keys(j.dependencies ?? j.require ?? {});
|
|
197
|
+
if (deps.length)
|
|
198
|
+
m.dependencies = deps.slice(0, 100);
|
|
199
|
+
if (j.scripts)
|
|
200
|
+
m.scripts = Object.fromEntries(Object.entries(j.scripts).slice(0, 30));
|
|
201
|
+
}
|
|
202
|
+
else if (kind === "go") {
|
|
203
|
+
m.name = /^module\s+(\S+)/m.exec(text)?.[1];
|
|
204
|
+
m.dependencies = [...text.matchAll(/^\s+([\w.\-/]+)\s+v[\d.]/gm)].map((x) => x[1]).slice(0, 100);
|
|
205
|
+
}
|
|
206
|
+
else if (kind === "python" || kind === "cargo") {
|
|
207
|
+
m.name = /^name\s*=\s*["']([^"']+)["']/m.exec(text)?.[1];
|
|
208
|
+
if (basename(rel) === "requirements.txt")
|
|
209
|
+
m.dependencies = text.split("\n").map((l) => l.trim().split(/[=<>~!\s[;]/)[0]).filter((l) => l && !l.startsWith("#")).slice(0, 100);
|
|
210
|
+
}
|
|
211
|
+
else if (kind === "compose") {
|
|
212
|
+
const services = /^services:\s*\n((?:[ \t]+.*\n?|\s*\n)*)/m.exec(text)?.[1] ?? "";
|
|
213
|
+
m.dependencies = [...services.matchAll(/^ {2}([\w.-]+):\s*$/gm)].map((x) => x[1]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// A broken manifest is still listed.
|
|
218
|
+
}
|
|
219
|
+
if (m.name === undefined)
|
|
220
|
+
delete m.name;
|
|
221
|
+
if (m.dependencies && !m.dependencies.length)
|
|
222
|
+
delete m.dependencies;
|
|
223
|
+
return m;
|
|
224
|
+
}
|
|
225
|
+
function entryPoints(files, manifests, texts) {
|
|
226
|
+
const out = new Set();
|
|
227
|
+
for (const m of manifests) {
|
|
228
|
+
const dir = m.path.includes("/") ? m.path.slice(0, m.path.lastIndexOf("/") + 1) : "";
|
|
229
|
+
if (m.kind === "npm") {
|
|
230
|
+
try {
|
|
231
|
+
const j = JSON.parse(texts.get(m.path) ?? "{}");
|
|
232
|
+
if (j.main)
|
|
233
|
+
out.add(`${dir}${j.main.replace(/^\.\//, "")}`);
|
|
234
|
+
for (const b of typeof j.bin === "string" ? [j.bin] : Object.values(j.bin ?? {}))
|
|
235
|
+
out.add(`${dir}${b.replace(/^\.\//, "")}`);
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
// skip
|
|
239
|
+
}
|
|
240
|
+
const start = m.scripts?.start ?? m.scripts?.dev;
|
|
241
|
+
const f = start && /\b(?:node|tsx|ts-node|bun|deno run)\s+(\S+\.[cm]?[jt]s)/.exec(start)?.[1];
|
|
242
|
+
if (f)
|
|
243
|
+
out.add(`${dir}${f.replace(/^\.\//, "")}`);
|
|
244
|
+
}
|
|
245
|
+
if (m.kind === "docker") {
|
|
246
|
+
const cmd = /^(?:CMD|ENTRYPOINT)\s+(.+)$/m.exec(texts.get(m.path) ?? "")?.[1];
|
|
247
|
+
if (cmd)
|
|
248
|
+
out.add(`${m.path}: ${cmd.trim()}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const f of files) {
|
|
252
|
+
const depth = f.rel.split("/").length;
|
|
253
|
+
if (ENTRY.test(basename(f.rel)) && CODE.has(extname(f.rel)) && (depth === 1 || (depth <= 3 && /^(src|cmd|app|lib)\//.test(f.rel))))
|
|
254
|
+
out.add(f.rel);
|
|
255
|
+
if (/\bif\s+__name__\s*==\s*["']__main__["']/.test(texts.get(f.rel) ?? ""))
|
|
256
|
+
out.add(f.rel);
|
|
257
|
+
if (/^func\s+main\s*\(\s*\)/m.test(texts.get(f.rel) ?? "") && f.rel.endsWith(".go"))
|
|
258
|
+
out.add(f.rel);
|
|
259
|
+
}
|
|
260
|
+
return [...out].sort();
|
|
261
|
+
}
|
|
262
|
+
// ---- Docs ------------------------------------------------------------------
|
|
263
|
+
function docKind(rel, title) {
|
|
264
|
+
if (/(^|\/)openspec\/specs\//.test(rel))
|
|
265
|
+
return "openspec-spec";
|
|
266
|
+
if (/(^|\/)openspec\/changes\//.test(rel))
|
|
267
|
+
return "openspec-change";
|
|
268
|
+
const s = `${basename(rel)} ${title ?? ""}`.toLowerCase();
|
|
269
|
+
if (/\bprd\b|product requirement/.test(s))
|
|
270
|
+
return "prd";
|
|
271
|
+
if (/\bsdd\b|system design|software design/.test(s))
|
|
272
|
+
return "sdd";
|
|
273
|
+
if (/\btdd\b|technical design/.test(s))
|
|
274
|
+
return "tdd";
|
|
275
|
+
if (/\bpbi\b|pbi[-_ ]?\d|backlog item|user story|\bstory\b/.test(s) || /(^|\/)(pbis?|stories|backlog)\//i.test(rel))
|
|
276
|
+
return "pbi";
|
|
277
|
+
if (/^readme\.md$/i.test(basename(rel)))
|
|
278
|
+
return "readme";
|
|
279
|
+
return "md";
|
|
280
|
+
}
|
|
281
|
+
// ---- Diagrams --------------------------------------------------------------
|
|
282
|
+
/** A Mermaid sequenceDiagram: participants (in order of first use) and messages. */
|
|
283
|
+
export function parseSequence(code) {
|
|
284
|
+
const lines = code.split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("%%"));
|
|
285
|
+
if (!/^sequenceDiagram\b/.test(lines[0] ?? ""))
|
|
286
|
+
return null;
|
|
287
|
+
const alias = new Map();
|
|
288
|
+
const participants = [];
|
|
289
|
+
const add = (id) => {
|
|
290
|
+
const name = alias.get(id) ?? id;
|
|
291
|
+
if (!participants.includes(name))
|
|
292
|
+
participants.push(name);
|
|
293
|
+
return name;
|
|
294
|
+
};
|
|
295
|
+
const messages = [];
|
|
296
|
+
for (const l of lines.slice(1)) {
|
|
297
|
+
const p = /^(?:participant|actor)\s+(\S+)(?:\s+as\s+(.+))?$/.exec(l);
|
|
298
|
+
if (p) {
|
|
299
|
+
if (p[2])
|
|
300
|
+
alias.set(p[1], p[2].trim());
|
|
301
|
+
add(p[1]);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const m = /^([^\s:>-]+?)\s*(-{1,2}>>|-{1,2}>|-{1,2}x|-{1,2}\))[+-]?\s*([^\s:]+)\s*:\s*(.*)$/.exec(l);
|
|
305
|
+
if (m)
|
|
306
|
+
messages.push({ from: add(m[1]), to: add(m[3]), text: m[4].trim() });
|
|
307
|
+
}
|
|
308
|
+
return { participants, messages };
|
|
309
|
+
}
|
|
310
|
+
function mermaidDiagram(path, code) {
|
|
311
|
+
const flow = parseFlowchart(code);
|
|
312
|
+
if (flow)
|
|
313
|
+
return { path, format: "mermaid", type: "flowchart", nodes: flow.nodes, edges: flow.edges };
|
|
314
|
+
const seq = parseSequence(code);
|
|
315
|
+
if (seq)
|
|
316
|
+
return {
|
|
317
|
+
path,
|
|
318
|
+
format: "mermaid",
|
|
319
|
+
type: "sequence",
|
|
320
|
+
nodes: seq.participants.map((p) => ({ id: p, label: p })),
|
|
321
|
+
edges: seq.messages.map((m) => ({ from: m.from, to: m.to, label: m.text })),
|
|
322
|
+
participants: seq.participants,
|
|
323
|
+
messages: seq.messages,
|
|
324
|
+
};
|
|
325
|
+
return { path, format: "mermaid", type: "other", nodes: [], edges: [] };
|
|
326
|
+
}
|
|
327
|
+
const decodeXml = (s) => s
|
|
328
|
+
.replace(/</g, "<")
|
|
329
|
+
.replace(/>/g, ">")
|
|
330
|
+
.replace(/"/g, '"')
|
|
331
|
+
.replace(/'|'/g, "'")
|
|
332
|
+
.replace(/&#(\d+);/g, (_, n) => String.fromCharCode(Number(n)))
|
|
333
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, n) => String.fromCharCode(parseInt(n, 16)))
|
|
334
|
+
.replace(/&/g, "&");
|
|
335
|
+
/** Labels in draw.io are often HTML; keep the text. */
|
|
336
|
+
const plain = (s) => decodeXml(decodeXml(s).replace(/<br\s*\/?>|<br\s*\/?>/gi, " ").replace(/<[^&]*?>|<[^>]+>/g, ""))
|
|
337
|
+
.replace(/<[^>]+>/g, "")
|
|
338
|
+
.replace(/\s+/g, " ")
|
|
339
|
+
.trim();
|
|
340
|
+
const attr = (tag, name) => new RegExp(`\\s${name}="([^"]*)"`).exec(tag)?.[1];
|
|
341
|
+
/** One draw.io page's model: vertices become nodes, edges edges (labels from value). */
|
|
342
|
+
function drawioModel(path, xml, page) {
|
|
343
|
+
const d = { path, format: "drawio", type: "flowchart", ...(page ? { page } : {}), nodes: [], edges: [] };
|
|
344
|
+
const labels = new Map();
|
|
345
|
+
const edges = [];
|
|
346
|
+
const edgeLabels = [];
|
|
347
|
+
// A cell is <mxCell .../> or <mxCell ...>...</mxCell>; <object label=".."><mxCell/></object> wraps some.
|
|
348
|
+
const cell = /<(?:object|UserObject)\b([^>]*)>\s*<mxCell\b([^>]*?)\/?>|<mxCell\b([^>]*?)\/?>/g;
|
|
349
|
+
for (const m of xml.matchAll(cell)) {
|
|
350
|
+
const wrap = m[1];
|
|
351
|
+
const tag = m[2] ?? m[3] ?? "";
|
|
352
|
+
const id = (wrap ? attr(wrap, "id") : undefined) ?? attr(tag, "id");
|
|
353
|
+
if (!id)
|
|
354
|
+
continue;
|
|
355
|
+
const value = plain((wrap ? attr(wrap, "label") : undefined) ?? attr(tag, "value") ?? "");
|
|
356
|
+
if (/\svertex="1"/.test(tag)) {
|
|
357
|
+
if (/edgeLabel/.test(attr(tag, "style") ?? "")) {
|
|
358
|
+
edgeLabels.push({ parent: attr(tag, "parent") ?? "", value });
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
labels.set(id, value);
|
|
362
|
+
if (value)
|
|
363
|
+
d.nodes.push({ id, label: value });
|
|
364
|
+
}
|
|
365
|
+
else if (/\sedge="1"/.test(tag)) {
|
|
366
|
+
const from = attr(tag, "source");
|
|
367
|
+
const to = attr(tag, "target");
|
|
368
|
+
labels.set(id, value);
|
|
369
|
+
if (from && to)
|
|
370
|
+
edges.push({ id, from, to, ...(value ? { label: value } : {}) });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
for (const l of edgeLabels) {
|
|
374
|
+
const e = edges.find((x) => x.id === l.parent);
|
|
375
|
+
if (e && l.value && !e.label)
|
|
376
|
+
e.label = l.value;
|
|
377
|
+
}
|
|
378
|
+
// Edges between vertices only (an edge to an edge or a group is skipped).
|
|
379
|
+
const ids = new Set(d.nodes.map((n) => n.id));
|
|
380
|
+
d.edges = edges.filter((e) => ids.has(e.from) && ids.has(e.to)).map(({ id: _id, ...e }) => e);
|
|
381
|
+
return d;
|
|
382
|
+
}
|
|
383
|
+
/** draw.io XML: plain or compressed (deflate + base64 + URI) pages. */
|
|
384
|
+
export function parseDrawio(path, xml) {
|
|
385
|
+
const pages = [...xml.matchAll(/<diagram\b([^>]*)>([\s\S]*?)<\/diagram>/g)];
|
|
386
|
+
if (!pages.length)
|
|
387
|
+
return xml.includes("<mxGraphModel") ? [drawioModel(path, xml)] : [];
|
|
388
|
+
const out = [];
|
|
389
|
+
for (const p of pages) {
|
|
390
|
+
const name = attr(p[1], "name");
|
|
391
|
+
let body = p[2].trim();
|
|
392
|
+
if (!body.includes("<mxGraphModel")) {
|
|
393
|
+
try {
|
|
394
|
+
body = decodeURIComponent(inflateRawSync(Buffer.from(body, "base64")).toString("utf8"));
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
out.push(drawioModel(path, body, pages.length > 1 ? name : undefined));
|
|
401
|
+
}
|
|
402
|
+
return out;
|
|
403
|
+
}
|
|
404
|
+
// ---- The scan ----------------------------------------------------------------
|
|
405
|
+
const IMAGE = /\.(png|jpe?g|gif|svg|webp|bmp)$/i;
|
|
406
|
+
/**
|
|
407
|
+
* Scan one source. `others` are the ids of the project's other sources, so a
|
|
408
|
+
* call to `http://worker:8080` or `$WORKER_URL` can be matched to them.
|
|
409
|
+
*/
|
|
410
|
+
export async function scanSource(abs, kind, others = [], limits = {}) {
|
|
411
|
+
const lim = { ...DEFAULT_LIMITS, ...limits };
|
|
412
|
+
if (!(await lstat(abs).catch(() => null))?.isDirectory())
|
|
413
|
+
throw new UserError(`${abs} is not a folder (moved or not mounted?)`);
|
|
414
|
+
const out = {
|
|
415
|
+
kind, files: 0, bytes_read: 0, truncated: false, skipped: { too_big: 0, over_limit: 0, dirs: [] }, tree: [],
|
|
416
|
+
languages: {}, manifests: [], entry_points: [], http_routes: [], queues: [], db: [], cross_repo_calls: [],
|
|
417
|
+
docs: [], openspec: { specs: [], changes: [] }, diagrams: [], images: [], pdfs: [], miro_csv: [],
|
|
418
|
+
};
|
|
419
|
+
const files = await walk(abs, lim, out);
|
|
420
|
+
out.files = files.length;
|
|
421
|
+
out.tree = files.slice(0, lim.maxTree).map((f) => f.rel);
|
|
422
|
+
if (files.length > lim.maxTree)
|
|
423
|
+
out.truncated = true;
|
|
424
|
+
const texts = new Map();
|
|
425
|
+
const read = async (f) => {
|
|
426
|
+
if (texts.has(f.rel))
|
|
427
|
+
return texts.get(f.rel);
|
|
428
|
+
if (f.size > lim.maxFileBytes) {
|
|
429
|
+
out.skipped.too_big++;
|
|
430
|
+
out.truncated = true;
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
if (out.bytes_read + f.size > lim.maxTotalBytes) {
|
|
434
|
+
out.skipped.over_limit++;
|
|
435
|
+
out.truncated = true;
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
const t = await readFile(f.abs, "utf8").catch(() => undefined);
|
|
439
|
+
if (t !== undefined) {
|
|
440
|
+
out.bytes_read += f.size;
|
|
441
|
+
texts.set(f.rel, t);
|
|
442
|
+
}
|
|
443
|
+
return t;
|
|
444
|
+
};
|
|
445
|
+
for (const f of files) {
|
|
446
|
+
const ext = extname(f.rel).toLowerCase();
|
|
447
|
+
const name = basename(f.rel);
|
|
448
|
+
if (LANGS[ext])
|
|
449
|
+
out.languages[LANGS[ext]] = (out.languages[LANGS[ext]] ?? 0) + 1;
|
|
450
|
+
// Anything can be a manifest, a doc or a diagram, whatever the source kind.
|
|
451
|
+
const mk = MANIFESTS[name] ?? (/\.csproj$/.test(name) ? "dotnet" : undefined);
|
|
452
|
+
if (mk && kind === "repo") {
|
|
453
|
+
const t = await read(f);
|
|
454
|
+
push(out.manifests, t === undefined ? { path: f.rel, kind: mk } : readManifest(f.rel, mk, t), lim, out);
|
|
455
|
+
}
|
|
456
|
+
if (kind === "repo" && CODE.has(ext) && !/\.(test|spec)\.[a-z]+$|(^|\/)(test|tests|__tests__)\//.test(f.rel)) {
|
|
457
|
+
const t = await read(f);
|
|
458
|
+
if (t !== undefined)
|
|
459
|
+
scanCode(f.rel, t, lim, out, others);
|
|
460
|
+
}
|
|
461
|
+
if (ext === ".md" && (kind !== "repo" || /(^|\/)(docs?|openspec)\//.test(f.rel) || !f.rel.includes("/"))) {
|
|
462
|
+
const t = await read(f);
|
|
463
|
+
const title = t ? /^#\s+(.+)$/m.exec(t)?.[1]?.trim() : undefined;
|
|
464
|
+
const blocks = t ? mermaidBlocks(t) : [];
|
|
465
|
+
push(out.docs, { path: f.rel, ...(title ? { title } : {}), kind: docKind(f.rel, title), mermaid: blocks.length, bytes: f.size }, lim, out);
|
|
466
|
+
if (/(^|\/)openspec\/specs\/[^/]+\/spec\.md$/.test(f.rel))
|
|
467
|
+
out.openspec.specs.push(f.rel);
|
|
468
|
+
const ch = /(^|\/)(openspec\/changes\/(?:archive\/)?[^/]+)\/proposal\.md$/.exec(f.rel);
|
|
469
|
+
if (ch)
|
|
470
|
+
out.openspec.changes.push(ch[2]);
|
|
471
|
+
if (kind === "diagrams" && t)
|
|
472
|
+
blocks.forEach((b) => push(out.diagrams, mermaidDiagram(`${f.rel}#${b.index}`, b.code), lim, out));
|
|
473
|
+
}
|
|
474
|
+
if (ext === ".mmd" || ext === ".mermaid") {
|
|
475
|
+
const t = await read(f);
|
|
476
|
+
if (t !== undefined)
|
|
477
|
+
push(out.diagrams, mermaidDiagram(f.rel, t), lim, out);
|
|
478
|
+
}
|
|
479
|
+
if (ext === ".drawio" || name.endsWith(".drawio.xml") || (ext === ".xml" && kind === "diagrams")) {
|
|
480
|
+
const t = await read(f);
|
|
481
|
+
if (t !== undefined)
|
|
482
|
+
for (const d of parseDrawio(f.rel, t))
|
|
483
|
+
push(out.diagrams, d, lim, out);
|
|
484
|
+
}
|
|
485
|
+
if (IMAGE.test(name) && name.toLowerCase() !== "favicon.ico" && (kind !== "repo" || /(^|\/)(docs?|diagrams?)\//.test(f.rel)))
|
|
486
|
+
push(out.images, { path: f.rel, bytes: f.size }, lim, out);
|
|
487
|
+
if (ext === ".pdf")
|
|
488
|
+
push(out.pdfs, { path: f.rel, bytes: f.size }, lim, out);
|
|
489
|
+
if (ext === ".csv" && (kind === "diagrams" || /miro/i.test(f.rel))) {
|
|
490
|
+
const t = f.size <= lim.maxFileBytes ? await read(f) : undefined;
|
|
491
|
+
const header = t?.split(/\r?\n/)[0];
|
|
492
|
+
const columns = header ? header.split(",").map((c) => c.trim().replace(/^"|"$/g, "")) : undefined;
|
|
493
|
+
push(out.miro_csv, { path: f.rel, bytes: f.size, ...(columns ? { columns } : {}) }, lim, out);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
out.entry_points = kind === "repo" ? entryPoints(files, out.manifests, texts) : [];
|
|
497
|
+
return out;
|
|
498
|
+
}
|
|
499
|
+
/** Leave out empty lists, so the AI reads only what was found. */
|
|
500
|
+
export function compactScan(r) {
|
|
501
|
+
const o = {};
|
|
502
|
+
for (const [k, v] of Object.entries(r)) {
|
|
503
|
+
if (Array.isArray(v) && v.length === 0)
|
|
504
|
+
continue;
|
|
505
|
+
if (k === "openspec" && !r.openspec.specs.length && !r.openspec.changes.length)
|
|
506
|
+
continue;
|
|
507
|
+
if (k === "languages" && !Object.keys(r.languages).length)
|
|
508
|
+
continue;
|
|
509
|
+
if (k === "skipped" && !r.skipped.too_big && !r.skipped.over_limit && !r.skipped.dirs.length)
|
|
510
|
+
continue;
|
|
511
|
+
o[k] = v;
|
|
512
|
+
}
|
|
513
|
+
return o;
|
|
514
|
+
}
|