@warlock.js/grimoire 0.0.0-stage → 5.55.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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +55 -2
- package/esm/apps/check-apps.mjs +207 -0
- package/esm/apps/check-apps.mjs.map +1 -0
- package/esm/apps/index.mjs +4 -0
- package/esm/apps/match-apps.d.mts +12 -0
- package/esm/apps/match-apps.d.mts.map +1 -0
- package/esm/apps/match-apps.mjs +30 -0
- package/esm/apps/match-apps.mjs.map +1 -0
- package/esm/book/build.d.mts +14 -0
- package/esm/book/build.d.mts.map +1 -0
- package/esm/book/build.mjs +300 -0
- package/esm/book/build.mjs.map +1 -0
- package/esm/book/index.mjs +5 -0
- package/esm/book/io.mjs +162 -0
- package/esm/book/io.mjs.map +1 -0
- package/esm/book/normalize.mjs +71 -0
- package/esm/book/normalize.mjs.map +1 -0
- package/esm/book/render.mjs +262 -0
- package/esm/book/render.mjs.map +1 -0
- package/esm/book/write.d.mts +12 -0
- package/esm/book/write.d.mts.map +1 -0
- package/esm/book/write.mjs +90 -0
- package/esm/book/write.mjs.map +1 -0
- package/esm/bookmap/build.d.mts +21 -0
- package/esm/bookmap/build.d.mts.map +1 -0
- package/esm/bookmap/build.mjs +272 -0
- package/esm/bookmap/build.mjs.map +1 -0
- package/esm/bookmap/index.mjs +5 -0
- package/esm/bookmap/steps.mjs +137 -0
- package/esm/bookmap/steps.mjs.map +1 -0
- package/esm/bookmap/write.d.mts +19 -0
- package/esm/bookmap/write.d.mts.map +1 -0
- package/esm/bookmap/write.mjs +118 -0
- package/esm/bookmap/write.mjs.map +1 -0
- package/esm/check/check-grimoire.d.mts +7 -0
- package/esm/check/check-grimoire.d.mts.map +1 -0
- package/esm/check/check-grimoire.mjs +98 -0
- package/esm/check/check-grimoire.mjs.map +1 -0
- package/esm/check/format-check-report.d.mts +20 -0
- package/esm/check/format-check-report.d.mts.map +1 -0
- package/esm/check/format-check-report.mjs +55 -0
- package/esm/check/format-check-report.mjs.map +1 -0
- package/esm/check/index.mjs +4 -0
- package/esm/check/rules/book-notes.mjs +18 -0
- package/esm/check/rules/book-notes.mjs.map +1 -0
- package/esm/check/rules/criteria.mjs +48 -0
- package/esm/check/rules/criteria.mjs.map +1 -0
- package/esm/check/rules/links.mjs +196 -0
- package/esm/check/rules/links.mjs.map +1 -0
- package/esm/check/rules/lookup.mjs +41 -0
- package/esm/check/rules/lookup.mjs.map +1 -0
- package/esm/check/rules/source-files.mjs +119 -0
- package/esm/check/rules/source-files.mjs.map +1 -0
- package/esm/check/rules/versions.mjs +92 -0
- package/esm/check/rules/versions.mjs.map +1 -0
- package/esm/codes/codes.d.mts +182 -0
- package/esm/codes/codes.d.mts.map +1 -0
- package/esm/codes/codes.mjs +111 -0
- package/esm/codes/codes.mjs.map +1 -0
- package/esm/codes/index.d.mts +33 -0
- package/esm/codes/index.d.mts.map +1 -0
- package/esm/codes/index.mjs +63 -0
- package/esm/codes/index.mjs.map +1 -0
- package/esm/contracts/adapter.d.mts +209 -0
- package/esm/contracts/adapter.d.mts.map +1 -0
- package/esm/contracts/book.d.mts +233 -0
- package/esm/contracts/book.d.mts.map +1 -0
- package/esm/contracts/book.mjs +7 -0
- package/esm/contracts/book.mjs.map +1 -0
- package/esm/contracts/bookmap.d.mts +175 -0
- package/esm/contracts/bookmap.d.mts.map +1 -0
- package/esm/contracts/findings.d.mts +79 -0
- package/esm/contracts/findings.d.mts.map +1 -0
- package/esm/contracts/location.d.mts +22 -0
- package/esm/contracts/location.d.mts.map +1 -0
- package/esm/contracts/releases.d.mts +53 -0
- package/esm/contracts/releases.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +143 -0
- package/esm/contracts/scry.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +52 -0
- package/esm/contracts/snapshot.d.mts.map +1 -0
- package/esm/contracts/test-results.d.mts +63 -0
- package/esm/contracts/test-results.d.mts.map +1 -0
- package/esm/contracts/written.d.mts +363 -0
- package/esm/contracts/written.d.mts.map +1 -0
- package/esm/contracts/written.mjs +19 -0
- package/esm/contracts/written.mjs.map +1 -0
- package/esm/devtools/data.mjs +171 -0
- package/esm/devtools/data.mjs.map +1 -0
- package/esm/devtools/graphs.mjs +142 -0
- package/esm/devtools/graphs.mjs.map +1 -0
- package/esm/devtools/index.d.mts +35 -0
- package/esm/devtools/index.d.mts.map +1 -0
- package/esm/devtools/index.mjs +102 -0
- package/esm/devtools/index.mjs.map +1 -0
- package/esm/devtools/site.d.mts +26 -0
- package/esm/devtools/site.d.mts.map +1 -0
- package/esm/devtools/site.mjs +190 -0
- package/esm/devtools/site.mjs.map +1 -0
- package/esm/devtools/snapshot-source.mjs +70 -0
- package/esm/devtools/snapshot-source.mjs.map +1 -0
- package/esm/front-matter/index.d.mts +33 -0
- package/esm/front-matter/index.d.mts.map +1 -0
- package/esm/front-matter/index.mjs +130 -0
- package/esm/front-matter/index.mjs.map +1 -0
- package/esm/graph/index.d.mts +15 -0
- package/esm/graph/index.d.mts.map +1 -0
- package/esm/graph/index.mjs +42 -0
- package/esm/graph/index.mjs.map +1 -0
- package/esm/index.d.mts +33 -0
- package/esm/index.mjs +33 -0
- package/esm/ownership/index.d.mts +8 -0
- package/esm/ownership/index.d.mts.map +1 -0
- package/esm/ownership/index.mjs +137 -0
- package/esm/ownership/index.mjs.map +1 -0
- package/esm/paths/index.d.mts +58 -0
- package/esm/paths/index.d.mts.map +1 -0
- package/esm/paths/index.mjs +137 -0
- package/esm/paths/index.mjs.map +1 -0
- package/esm/proves/index.mjs +3 -0
- package/esm/proves/scan-proofs.d.mts +22 -0
- package/esm/proves/scan-proofs.d.mts.map +1 -0
- package/esm/proves/scan-proofs.mjs +214 -0
- package/esm/proves/scan-proofs.mjs.map +1 -0
- package/esm/releases/index.d.mts +29 -0
- package/esm/releases/index.d.mts.map +1 -0
- package/esm/releases/index.mjs +157 -0
- package/esm/releases/index.mjs.map +1 -0
- package/esm/scry/format.d.mts +14 -0
- package/esm/scry/format.d.mts.map +1 -0
- package/esm/scry/format.mjs +193 -0
- package/esm/scry/format.mjs.map +1 -0
- package/esm/scry/index.mjs +5 -0
- package/esm/scry/parse.d.mts +10 -0
- package/esm/scry/parse.d.mts.map +1 -0
- package/esm/scry/parse.mjs +108 -0
- package/esm/scry/parse.mjs.map +1 -0
- package/esm/scry/query.d.mts +11 -0
- package/esm/scry/query.d.mts.map +1 -0
- package/esm/scry/query.mjs +457 -0
- package/esm/scry/query.mjs.map +1 -0
- package/esm/tasks/index.mjs +116 -0
- package/esm/tasks/index.mjs.map +1 -0
- package/esm/test-results/criterion-status.d.mts +15 -0
- package/esm/test-results/criterion-status.d.mts.map +1 -0
- package/esm/test-results/criterion-status.mjs +17 -0
- package/esm/test-results/criterion-status.mjs.map +1 -0
- package/esm/test-results/index.d.mts +8 -0
- package/esm/test-results/index.d.mts.map +1 -0
- package/esm/test-results/index.mjs +124 -0
- package/esm/test-results/index.mjs.map +1 -0
- package/esm/vitest/index.d.mts +15 -0
- package/esm/vitest/index.d.mts.map +1 -0
- package/esm/vitest/index.mjs +146 -0
- package/esm/vitest/index.mjs.map +1 -0
- package/esm/warlock/actions.mjs +265 -0
- package/esm/warlock/actions.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts +28 -0
- package/esm/warlock/adapter.d.mts.map +1 -0
- package/esm/warlock/adapter.mjs +377 -0
- package/esm/warlock/adapter.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +15 -0
- package/esm/warlock/commands.d.mts.map +1 -0
- package/esm/warlock/commands.mjs +199 -0
- package/esm/warlock/commands.mjs.map +1 -0
- package/esm/warlock/index.d.mts +4 -0
- package/esm/warlock/index.mjs +5 -0
- package/esm/warlock/mcp-tools.mjs +247 -0
- package/esm/warlock/mcp-tools.mjs.map +1 -0
- package/esm/warlock/mobile-facts.d.mts +32 -0
- package/esm/warlock/mobile-facts.d.mts.map +1 -0
- package/esm/warlock/mobile-facts.mjs +185 -0
- package/esm/warlock/mobile-facts.mjs.map +1 -0
- package/esm/workspace/index.d.mts +11 -0
- package/esm/workspace/index.d.mts.map +1 -0
- package/esm/workspace/index.mjs +122 -0
- package/esm/workspace/index.mjs.map +1 -0
- package/esm/written/apps.mjs +227 -0
- package/esm/written/apps.mjs.map +1 -0
- package/esm/written/features.mjs +400 -0
- package/esm/written/features.mjs.map +1 -0
- package/esm/written/fields.mjs +173 -0
- package/esm/written/fields.mjs.map +1 -0
- package/esm/written/index.mjs +3 -0
- package/esm/written/lists.mjs +68 -0
- package/esm/written/lists.mjs.map +1 -0
- package/esm/written/markdown.mjs +173 -0
- package/esm/written/markdown.mjs.map +1 -0
- package/esm/written/parse-grimoire.d.mts +20 -0
- package/esm/written/parse-grimoire.d.mts.map +1 -0
- package/esm/written/parse-grimoire.mjs +552 -0
- package/esm/written/parse-grimoire.mjs.map +1 -0
- package/esm/written/sink.mjs +65 -0
- package/esm/written/sink.mjs.map +1 -0
- package/esm/written/tasks-releases.mjs +166 -0
- package/esm/written/tasks-releases.mjs.map +1 -0
- package/llms-full.txt +869 -0
- package/llms.txt +15 -0
- package/package.json +66 -4
- package/skills/backfill-a-grimoire/SKILL.md +128 -0
- package/skills/describe-an-app/SKILL.md +162 -0
- package/skills/document-a-file/SKILL.md +75 -0
- package/skills/index.md +26 -0
- package/skills/record-a-change/SKILL.md +139 -0
- package/skills/use-the-grimoire/SKILL.md +137 -0
- package/skills/write-a-feature/SKILL.md +168 -0
- package/ui/grimoire-static.js +136 -0
- package/ui/grimoire-view.js +1005 -0
- package/ui/grimoire.css +88 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/commands.ts"],"sourcesContent":["/**\n * The `warlock grimoire` and `warlock scry` commands. Light on purpose: the\n * work lives in `./actions`, imported when a command runs.\n */\nimport {\n command,\n withExplainCodes,\n withMcpTools,\n type CLICommand,\n type CLICommandPreload,\n} from \"@warlock.js/core\";\nimport { explainGrimoireCode, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\nimport { createGrimoireMcpTools } from \"./mcp-tools\";\n\n/** The preload of a command that reads routes: the `warlock inspect` boot. */\nconst BOOT: CLICommandPreload = {\n runtimeStrategy: \"development\",\n config: true,\n env: true,\n bootstrap: true,\n};\n\n/** No boot, but a multi-site app's `src/config/web.ts` (its sites' base paths shape the page routes). */\nconst WEB_CONFIG: CLICommandPreload = { config: [\"web\"] };\n\n/** The preload of a question that boots only when `boot` says so. */\nasync function preloadFor(boot: () => Promise<boolean>): Promise<CLICommandPreload | undefined> {\n try {\n const actions = await import(\"./actions\");\n\n if (await boot()) return BOOT;\n\n return (await actions.isMultiSite(process.cwd())) ? WEB_CONFIG : undefined;\n } catch {\n // The action runs the same steps and reports the problem with its code.\n return undefined;\n }\n}\n\nconst GRIMOIRE_ACTIONS = [\"build\", \"check\", \"release\"] as const;\n\n/** Print with the stream's own write, so a boot that moves `console.log` never mixes into the answer. */\nconst io = {\n out: (line: string) => void process.stdout.write(`${line}\\n`),\n err: (line: string) => void process.stderr.write(`${line}\\n`),\n};\n\n/** Exit with `code` once stdout and stderr are flushed (a non-zero code only; 0 lets the CLI finish). */\nasync function exitWith(code: number): Promise<void> {\n if (code === 0) return;\n\n process.exitCode = code;\n\n await Promise.race([\n Promise.all(\n [process.stdout, process.stderr].map(\n (stream) => new Promise<void>((resolve) => stream.write(\"\", () => resolve())),\n ),\n ),\n new Promise<void>((resolve) => setTimeout(resolve, 500).unref()),\n ]);\n\n process.exit(code);\n}\n\n/** Explain a Grimoire code for `warlock explain GR2001`. */\nfunction explainCode(code: string) {\n const definition = explainGrimoireCode(code);\n\n return definition\n ? {\n code: definition.code,\n title: definition.title,\n area: definition.area,\n fix: definition.fix,\n skill: definition.skill,\n docs: grimoireCodeDocsUrl(definition.code),\n }\n : undefined;\n}\n\n/**\n * The `grimoire <action> [release]` and `scry [file]` commands, with the\n * Grimoire MCP tools and the `GRnnnn` explainer attached. `cli.commands`\n * accepts this array as one entry.\n *\n * @example\n * // warlock.config.ts\n * export default defineConfig({ cli: { commands: [registerGrimoireCommands()] } });\n */\nexport function registerGrimoireCommands(options: WarlockAdapterOptions = {}): CLICommand[] {\n let adapter: Promise<BookAdapter> | undefined;\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??= import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter(options),\n );\n\n return adapter;\n };\n const context = async () => ({ root: process.cwd(), adapter: await loadAdapter(), io });\n\n const grimoire: CLICommand = command({\n name: \"grimoire <action> [release]\",\n description:\n \"Grimoire (experimental): build the book (build [--force] [--site [--out <dir>]]), check the written files (check [--all]), collect a release (release <version>); --json for JSON\",\n preAction: async ({ args, options: flags }) => {\n grimoire.commandPreload = undefined;\n\n if (args[0] !== \"build\" && args[0] !== \"check\") return;\n\n const preload = await preloadFor(async () =>\n (await import(\"./actions\")).needsBoot(process.cwd(), flags.force === true),\n );\n\n if (preload) grimoire.commandPreload = preload;\n },\n action: async ({ args, options: flags }) => {\n const actions = await import(\"./actions\");\n const ctx = await context();\n const [name, release] = args;\n let code: number;\n\n switch (name) {\n case \"build\":\n code = await actions.runBuild(ctx, flags);\n break;\n case \"check\":\n code = await actions.runCheck(ctx, flags);\n break;\n case \"release\":\n code = await actions.runRelease(ctx, release, flags);\n break;\n default: {\n const { GrimoireError } = await import(\"../codes\");\n\n code = actions.reportError(\n io,\n new GrimoireError(\n \"GR9006\",\n `Unknown action ${JSON.stringify(name ?? \"\")}. Use one of: ${GRIMOIRE_ACTIONS.join(\", \")} (warlock grimoire build).`,\n ),\n );\n }\n }\n\n await exitWith(code);\n },\n options: [\n { text: \"--json, -j\", description: \"Print the result as JSON\", type: \"boolean\" },\n {\n text: \"--all\",\n description: \"check: list every finding (text output groups warnings by code)\",\n type: \"boolean\",\n },\n {\n text: \"--force, -f\",\n description: \"build: rebuild every book entry and read the routes again\",\n type: \"boolean\",\n },\n {\n text: \"--site\",\n description: \"build: also write the static Grimoire site (default grimoire/book/site)\",\n type: \"boolean\",\n },\n {\n text: \"--out\",\n description: \"build --site: the folder to write the site to (project-relative)\",\n type: \"string\",\n },\n ],\n });\n\n const scry: CLICommand = command({\n name: \"scry [file]\",\n description:\n 'Grimoire (experimental): ask about a file, --impact <file>, --route \"<METHOD path>\", --feature <id>, --flow <feature>/<flow> or --search \"<text>\"; --json for JSON',\n preAction: async ({ options: flags }) => {\n scry.commandPreload = undefined;\n\n // The first route question of a project with no route facts reads them once.\n const preload = await preloadFor(\n async () =>\n flags.route !== undefined &&\n !(await (await import(\"./actions\")).hasRouteFacts(process.cwd())),\n );\n\n if (preload) scry.commandPreload = preload;\n },\n action: async ({ args, options: flags }) => {\n const { runScry } = await import(\"./actions\");\n\n await exitWith(await runScry(await context(), args, flags));\n },\n options: [\n { text: \"--impact\", description: \"What a change to this file reaches\", type: \"string\" },\n { text: \"--route\", description: 'One route: \"<METHOD> <path>\"', type: \"string\" },\n { text: \"--feature\", description: \"One feature by id\", type: \"string\" },\n { text: \"--flow\", description: \"One flow: <feature>/<flow>\", type: \"string\" },\n { text: \"--search\", description: \"Search by words\", type: \"string\" },\n { text: \"--limit\", description: \"--search: most hits (default 20)\", type: \"number\" },\n {\n text: \"--all\",\n description: \"--impact: print every line of every list (text output stops at 20)\",\n type: \"boolean\",\n },\n { text: \"--json, -j\", description: \"Print the answer as JSON\", type: \"boolean\" },\n ],\n });\n\n withMcpTools(grimoire, [(mcp) => createGrimoireMcpTools(mcp, options)]);\n withExplainCodes(grimoire, explainCode);\n\n return [grimoire, scry];\n}\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,OAA0B;CAC9B,iBAAiB;CACjB,QAAQ;CACR,KAAK;CACL,WAAW;AACb;;AAGA,MAAM,aAAgC,EAAE,QAAQ,CAAC,KAAK,EAAE;;AAGxD,eAAe,WAAW,MAAsE;CAC9F,IAAI;EACF,MAA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AAE,OAAO,MAAM,OAAO,iBAAY,CAAE,cAAc,QAAQ,IAAI,CAAC,CACnE;GAEA,IAAI,SAAS,KAAK,iBAAiB;EACrC;EACA,QAAQ,OAAO,EAAE,MAAM,SAAS,YAAY;GAC1C,MAAM,EAAE,YAAY,MAAM,OAAO;GAEjC,MAAM,SAAS,MAAM,QAAQ,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC;EAC5D;EACA,SAAS;GACP;IAAE,MAAM;IAAY,aAAa;IAAsC,MAAM;GAAS;GACtF;IAAE,MAAM;IAAW,aAAa;IAAgC,MAAM;GAAS;GAC/E;IAAE,MAAM;IAAa,aAAa;IAAqB,MAAM;GAAS;GACtE;IAAE,MAAM;IAAU,aAAa;IAA8B,MAAM;GAAS;GAC5E;IAAE,MAAM;IAAY,aAAa;IAAmB,MAAM;GAAS;GACnE;IAAE,MAAM;IAAW,aAAa;IAAoC,MAAM;GAAS;GACnF;IACE,MAAM;IACN,aAAa;IACb,MAAM;GACR;GACA;IAAE,MAAM;IAAc,aAAa;IAA4B,MAAM;GAAU;EACjF;CACF,CAAC;CAED,aAAa,UAAU,EAAE,QAAQ,uBAAuB,KAAK,OAAO,CAAC,CAAC;CACtE,iBAAiB,UAAU,WAAW;CAEtC,OAAO,CAAC,UAAU,IAAI;AACxB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CollectMobileFactsOptions, MobileAppOption, collectMobileFacts } from "./mobile-facts.mjs";
|
|
2
|
+
import { WarlockAdapterOptions, WarlockInspect, createWarlockAdapter } from "./adapter.mjs";
|
|
3
|
+
import { registerGrimoireCommands } from "./commands.mjs";
|
|
4
|
+
export { type CollectMobileFactsOptions, type MobileAppOption, type WarlockAdapterOptions, type WarlockInspect, collectMobileFacts, createWarlockAdapter, registerGrimoireCommands };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { GrimoireError, explainGrimoireCode, grimoireCodeDocsUrl } from "../codes/index.mjs";
|
|
2
|
+
import { inputSchema } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/grimoire/src/warlock/mcp-tools.ts
|
|
5
|
+
/**
|
|
6
|
+
* The Grimoire tools `warlock mcp` and `warlock dev --mcp` serve. Each tool
|
|
7
|
+
* loads its code inside `run`, so registering them costs nothing at start.
|
|
8
|
+
* Answers are the same JSON objects `--json` prints.
|
|
9
|
+
*/
|
|
10
|
+
/** A Grimoire error as a tool error: the code, what failed, and what to do. */
|
|
11
|
+
function toolError(error) {
|
|
12
|
+
if (error instanceof GrimoireError) {
|
|
13
|
+
const fix = explainGrimoireCode(error.code)?.fix;
|
|
14
|
+
throw new Error(`${error.code}: ${error.message}${fix ? ` Fix: ${fix}` : ""}`);
|
|
15
|
+
}
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
function text(input, name) {
|
|
19
|
+
const value = input[name];
|
|
20
|
+
return typeof value === "string" ? value : "";
|
|
21
|
+
}
|
|
22
|
+
/** The tools for one MCP server. `adapterFor` is replaced in specs. */
|
|
23
|
+
function createGrimoireMcpTools(context, options = {}, adapterFor) {
|
|
24
|
+
const root = context.cwd;
|
|
25
|
+
let adapter;
|
|
26
|
+
const loadAdapter = () => {
|
|
27
|
+
adapter ??= adapterFor?.() ?? import("./adapter.mjs").then(({ createWarlockAdapter }) => createWarlockAdapter({
|
|
28
|
+
...options,
|
|
29
|
+
inspect: (_root, sections) => context.inspect(sections)
|
|
30
|
+
}));
|
|
31
|
+
return adapter;
|
|
32
|
+
};
|
|
33
|
+
const ask = (query) => async (input) => {
|
|
34
|
+
try {
|
|
35
|
+
const { answer } = await import("./actions.mjs");
|
|
36
|
+
return await answer(root, await loadAdapter(), await query(input));
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return toolError(error);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const scryParts = () => import("../scry/index.mjs");
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
name: "grimoire_file",
|
|
45
|
+
description: "One source file from the Grimoire book: header sentence, owning feature and borrowers, flows that reach it, exports, imports, importers, routes, pages. Read-only; reads cached route facts and never boots the app.",
|
|
46
|
+
input: inputSchema({ file: {
|
|
47
|
+
type: "string",
|
|
48
|
+
description: "Project-relative path (either separator)."
|
|
49
|
+
} }, ["file"]),
|
|
50
|
+
writes: false,
|
|
51
|
+
run: ask((input) => ({
|
|
52
|
+
type: "file",
|
|
53
|
+
file: text(input, "file")
|
|
54
|
+
}))
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "grimoire_impact",
|
|
58
|
+
description: "What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. Read-only.",
|
|
59
|
+
input: inputSchema({ file: {
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "Project-relative path of the file to change."
|
|
62
|
+
} }, ["file"]),
|
|
63
|
+
writes: false,
|
|
64
|
+
run: ask((input) => ({
|
|
65
|
+
type: "impact",
|
|
66
|
+
file: text(input, "file")
|
|
67
|
+
}))
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "grimoire_route",
|
|
71
|
+
description: "One HTTP route: handler and its file, routes file, middleware, guard, the files behind it and the flow steps that name it. Read-only.",
|
|
72
|
+
input: inputSchema({
|
|
73
|
+
method: {
|
|
74
|
+
type: "string",
|
|
75
|
+
description: "HTTP method (GET, POST…)."
|
|
76
|
+
},
|
|
77
|
+
path: {
|
|
78
|
+
type: "string",
|
|
79
|
+
description: "Path as registered (/api/products/:id)."
|
|
80
|
+
}
|
|
81
|
+
}, ["method", "path"]),
|
|
82
|
+
writes: false,
|
|
83
|
+
run: ask(async (input) => {
|
|
84
|
+
const { parseRouteText } = await scryParts();
|
|
85
|
+
return {
|
|
86
|
+
type: "route",
|
|
87
|
+
...parseRouteText(`${text(input, "method")} ${text(input, "path")}`)
|
|
88
|
+
};
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "grimoire_feature",
|
|
93
|
+
description: "One feature: README, flows with status, its book map (own, borrowed and unreached files, routes, pages), recent changes, open tasks and its check findings. Read-only.",
|
|
94
|
+
input: inputSchema({ feature: {
|
|
95
|
+
type: "string",
|
|
96
|
+
description: "Feature id (folder under grimoire/features/)."
|
|
97
|
+
} }, ["feature"]),
|
|
98
|
+
writes: false,
|
|
99
|
+
run: ask(async (input) => {
|
|
100
|
+
const { parseFeatureText } = await scryParts();
|
|
101
|
+
return {
|
|
102
|
+
type: "feature",
|
|
103
|
+
feature: parseFeatureText(text(input, "feature"))
|
|
104
|
+
};
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "grimoire_flow",
|
|
109
|
+
description: "One flow: steps with the files behind each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Read-only.",
|
|
110
|
+
input: inputSchema({ flow: {
|
|
111
|
+
type: "string",
|
|
112
|
+
description: "<feature>/<flow>, like catalog/new-arrivals."
|
|
113
|
+
} }, ["flow"]),
|
|
114
|
+
writes: false,
|
|
115
|
+
run: ask(async (input) => {
|
|
116
|
+
const { parseFlowText } = await scryParts();
|
|
117
|
+
return {
|
|
118
|
+
type: "flow",
|
|
119
|
+
...parseFlowText(text(input, "flow"))
|
|
120
|
+
};
|
|
121
|
+
})
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "grimoire_search",
|
|
125
|
+
description: "Search the Grimoire by words: features, flows, blocks, pages, screens, routes, file paths, export names, header sentences and tasks, best match first. Read-only.",
|
|
126
|
+
input: inputSchema({
|
|
127
|
+
text: {
|
|
128
|
+
type: "string",
|
|
129
|
+
description: "Words to look for, in any order."
|
|
130
|
+
},
|
|
131
|
+
limit: {
|
|
132
|
+
type: "integer",
|
|
133
|
+
description: "Most hits to return (default 20).",
|
|
134
|
+
minimum: 1
|
|
135
|
+
}
|
|
136
|
+
}, ["text"]),
|
|
137
|
+
writes: false,
|
|
138
|
+
run: ask(async (input) => {
|
|
139
|
+
const limit = input.limit;
|
|
140
|
+
if (limit === void 0 || limit === null) return {
|
|
141
|
+
type: "search",
|
|
142
|
+
text: text(input, "text")
|
|
143
|
+
};
|
|
144
|
+
const { parseLimit } = await scryParts();
|
|
145
|
+
return {
|
|
146
|
+
type: "search",
|
|
147
|
+
text: text(input, "text"),
|
|
148
|
+
limit: parseLimit(typeof limit === "number" || typeof limit === "string" ? limit : true)
|
|
149
|
+
};
|
|
150
|
+
})
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "grimoire_check",
|
|
154
|
+
description: "Run the Grimoire check: written names that point at nothing, files without a header or feature, criteria without tests, version and changelog problems. Findings on proposed work are marked expected. Read-only; uses cached route facts.",
|
|
155
|
+
input: inputSchema({}),
|
|
156
|
+
writes: false,
|
|
157
|
+
run: async () => {
|
|
158
|
+
try {
|
|
159
|
+
const [{ openGrimoire }, { checkGrimoire }] = await Promise.all([import("../workspace/index.mjs"), import("../check/index.mjs")]);
|
|
160
|
+
return checkGrimoire(await openGrimoire(root, await loadAdapter(), { routes: "cached" }));
|
|
161
|
+
} catch (error) {
|
|
162
|
+
return toolError(error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "grimoire_build",
|
|
168
|
+
description: "Bring the generated book (grimoire/book, a git-ignored cache) up to date, reading the routes again when they changed. Writes no project file.",
|
|
169
|
+
input: inputSchema({ force: {
|
|
170
|
+
type: "boolean",
|
|
171
|
+
description: "Rebuild every entry."
|
|
172
|
+
} }),
|
|
173
|
+
writes: false,
|
|
174
|
+
run: async (input) => {
|
|
175
|
+
try {
|
|
176
|
+
const { runGrimoire } = await import("../workspace/index.mjs");
|
|
177
|
+
const loaded = await loadAdapter();
|
|
178
|
+
const force = input.force === true;
|
|
179
|
+
let run;
|
|
180
|
+
let note = null;
|
|
181
|
+
try {
|
|
182
|
+
run = await runGrimoire(root, loaded, {
|
|
183
|
+
routes: "fresh",
|
|
184
|
+
force
|
|
185
|
+
});
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (!(error instanceof GrimoireError) || error.code !== "GR8002") throw error;
|
|
188
|
+
note = `${error.code}: ${error.message}`;
|
|
189
|
+
run = await runGrimoire(root, loaded, {
|
|
190
|
+
routes: "cached",
|
|
191
|
+
force
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
rebuilt: run.rebuilt,
|
|
196
|
+
written: [...run.book.written, ...run.collected.written],
|
|
197
|
+
removed: [...run.book.removed, ...run.collected.removed],
|
|
198
|
+
routes: run.snapshot.routes,
|
|
199
|
+
...note === null ? {} : { note }
|
|
200
|
+
};
|
|
201
|
+
} catch (error) {
|
|
202
|
+
return toolError(error);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "grimoire_release",
|
|
208
|
+
description: "Write the collected list of a release into grimoire/releases/<release>.md (between its markers; the agent writes the brief and stamps the changelog entries first). Writes a project file.",
|
|
209
|
+
input: inputSchema({ release: {
|
|
210
|
+
type: "string",
|
|
211
|
+
description: "Release name, like 1.1.0."
|
|
212
|
+
} }, ["release"]),
|
|
213
|
+
writes: true,
|
|
214
|
+
run: async (input) => {
|
|
215
|
+
try {
|
|
216
|
+
const [{ parseGrimoire }, { writeRelease }] = await Promise.all([import("../written/index.mjs"), import("../releases/index.mjs")]);
|
|
217
|
+
const release = text(input, "release").trim();
|
|
218
|
+
if (release === "" || /[\\/]/.test(release)) throw new GrimoireError("GR9006", `Pass a release name like 1.1.0 (got ${JSON.stringify(release)}).`);
|
|
219
|
+
return await writeRelease(root, (await parseGrimoire(root)).written, release);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return toolError(error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "grimoire_explain",
|
|
227
|
+
description: "What a Grimoire code (GR1001…GR9006) means, what to do, the skill that explains it and its docs link. Read-only.",
|
|
228
|
+
input: inputSchema({ code: {
|
|
229
|
+
type: "string",
|
|
230
|
+
description: "The code, like GR2001."
|
|
231
|
+
} }, ["code"]),
|
|
232
|
+
writes: false,
|
|
233
|
+
run: async (input) => {
|
|
234
|
+
const definition = explainGrimoireCode(text(input, "code"));
|
|
235
|
+
if (!definition) throw new Error(`Unknown Grimoire code ${JSON.stringify(text(input, "code"))}. Codes look like GR2001; the full list is at the check guide.`);
|
|
236
|
+
return {
|
|
237
|
+
...definition,
|
|
238
|
+
docs: grimoireCodeDocsUrl(definition.code)
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
export { createGrimoireMcpTools };
|
|
247
|
+
//# sourceMappingURL=mcp-tools.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/mcp-tools.ts"],"sourcesContent":["/**\n * The Grimoire tools `warlock mcp` and `warlock dev --mcp` serve. Each tool\n * loads its code inside `run`, so registering them costs nothing at start.\n * Answers are the same JSON objects `--json` prints.\n */\nimport { inputSchema, type WarlockMcpContext, type WarlockMcpTool } from \"@warlock.js/core\";\nimport { explainGrimoireCode, GrimoireError, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { ScryQuery } from \"../contracts/scry\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\n\n/** The names of the tools, in the order they are listed. */\nexport const GRIMOIRE_MCP_TOOL_NAMES = [\n \"grimoire_file\",\n \"grimoire_impact\",\n \"grimoire_route\",\n \"grimoire_feature\",\n \"grimoire_flow\",\n \"grimoire_search\",\n \"grimoire_check\",\n \"grimoire_build\",\n \"grimoire_release\",\n \"grimoire_explain\",\n] as const;\n\n/** A Grimoire error as a tool error: the code, what failed, and what to do. */\nfunction toolError(error: unknown): never {\n if (error instanceof GrimoireError) {\n const fix = explainGrimoireCode(error.code)?.fix;\n\n throw new Error(`${error.code}: ${error.message}${fix ? ` Fix: ${fix}` : \"\"}`);\n }\n\n throw error;\n}\n\nfunction text(input: Record<string, unknown>, name: string): string {\n const value = input[name];\n\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** The tools for one MCP server. `adapterFor` is replaced in specs. */\nexport function createGrimoireMcpTools(\n context: Pick<WarlockMcpContext, \"cwd\" | \"inspect\">,\n options: WarlockAdapterOptions = {},\n adapterFor?: () => Promise<BookAdapter>,\n): WarlockMcpTool[] {\n const root = context.cwd;\n let adapter: Promise<BookAdapter> | undefined;\n\n // The server's own inspect: `warlock mcp` boots once for every tool, `warlock dev --mcp` reads the live app.\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??=\n adapterFor?.() ??\n import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter({\n ...options,\n inspect: (_root, sections) => context.inspect(sections),\n }),\n );\n\n return adapter;\n };\n\n const ask =\n (query: (input: Record<string, unknown>) => Promise<ScryQuery> | ScryQuery) =>\n async (input: Record<string, unknown>): Promise<unknown> => {\n try {\n const { answer } = await import(\"./actions\");\n\n return await answer(root, await loadAdapter(), await query(input));\n } catch (error) {\n return toolError(error);\n }\n };\n\n const scryParts = () => import(\"../scry\");\n\n return [\n {\n name: \"grimoire_file\",\n description:\n \"One source file from the Grimoire book: header sentence, owning feature and borrowers, flows that reach it, exports, imports, importers, routes, pages. Read-only; reads cached route facts and never boots the app.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path (either separator).\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"file\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_impact\",\n description:\n \"What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. Read-only.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path of the file to change.\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"impact\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_route\",\n description:\n \"One HTTP route: handler and its file, routes file, middleware, guard, the files behind it and the flow steps that name it. Read-only.\",\n input: inputSchema(\n {\n method: { type: \"string\", description: \"HTTP method (GET, POST…).\" },\n path: { type: \"string\", description: \"Path as registered (/api/products/:id).\" },\n },\n [\"method\", \"path\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseRouteText } = await scryParts();\n\n return {\n type: \"route\",\n ...parseRouteText(`${text(input, \"method\")} ${text(input, \"path\")}`),\n };\n }),\n },\n {\n name: \"grimoire_feature\",\n description:\n \"One feature: README, flows with status, its book map (own, borrowed and unreached files, routes, pages), recent changes, open tasks and its check findings. Read-only.\",\n input: inputSchema(\n {\n feature: { type: \"string\", description: \"Feature id (folder under grimoire/features/).\" },\n },\n [\"feature\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseFeatureText } = await scryParts();\n\n return { type: \"feature\", feature: parseFeatureText(text(input, \"feature\")) };\n }),\n },\n {\n name: \"grimoire_flow\",\n description:\n \"One flow: steps with the files behind each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Read-only.\",\n input: inputSchema(\n { flow: { type: \"string\", description: \"<feature>/<flow>, like catalog/new-arrivals.\" } },\n [\"flow\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseFlowText } = await scryParts();\n\n return { type: \"flow\", ...parseFlowText(text(input, \"flow\")) };\n }),\n },\n {\n name: \"grimoire_search\",\n description:\n \"Search the Grimoire by words: features, flows, blocks, pages, screens, routes, file paths, export names, header sentences and tasks, best match first. Read-only.\",\n input: inputSchema(\n {\n text: { type: \"string\", description: \"Words to look for, in any order.\" },\n limit: { type: \"integer\", description: \"Most hits to return (default 20).\", minimum: 1 },\n },\n [\"text\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const limit = input.limit;\n\n if (limit === undefined || limit === null)\n return { type: \"search\", text: text(input, \"text\") };\n\n const { parseLimit } = await scryParts();\n\n // A limit of 0, a negative or a fraction is refused with GR9006, as `--limit` is.\n return {\n type: \"search\",\n text: text(input, \"text\"),\n limit: parseLimit(typeof limit === \"number\" || typeof limit === \"string\" ? limit : true),\n };\n }),\n },\n {\n name: \"grimoire_check\",\n description:\n \"Run the Grimoire check: written names that point at nothing, files without a header or feature, criteria without tests, version and changelog problems. Findings on proposed work are marked expected. Read-only; uses cached route facts.\",\n input: inputSchema({}),\n writes: false,\n run: async () => {\n try {\n const [{ openGrimoire }, { checkGrimoire }] = await Promise.all([\n import(\"../workspace\"),\n import(\"../check\"),\n ]);\n\n return checkGrimoire(await openGrimoire(root, await loadAdapter(), { routes: \"cached\" }));\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_build\",\n description:\n \"Bring the generated book (grimoire/book, a git-ignored cache) up to date, reading the routes again when they changed. Writes no project file.\",\n input: inputSchema({ force: { type: \"boolean\", description: \"Rebuild every entry.\" } }),\n writes: false,\n run: async (input) => {\n try {\n const { runGrimoire } = await import(\"../workspace\");\n const loaded = await loadAdapter();\n const force = input.force === true;\n let run;\n let note: string | null = null;\n\n try {\n run = await runGrimoire(root, loaded, { routes: \"fresh\", force });\n } catch (error) {\n if (!(error instanceof GrimoireError) || error.code !== \"GR8002\") throw error;\n\n note = `${error.code}: ${error.message}`;\n run = await runGrimoire(root, loaded, { routes: \"cached\", force });\n }\n\n return {\n rebuilt: run.rebuilt,\n written: [...run.book.written, ...run.collected.written],\n removed: [...run.book.removed, ...run.collected.removed],\n routes: run.snapshot.routes,\n ...(note === null ? {} : { note }),\n };\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_release\",\n description:\n \"Write the collected list of a release into grimoire/releases/<release>.md (between its markers; the agent writes the brief and stamps the changelog entries first). Writes a project file.\",\n input: inputSchema(\n { release: { type: \"string\", description: \"Release name, like 1.1.0.\" } },\n [\"release\"],\n ),\n writes: true,\n run: async (input) => {\n try {\n const [{ parseGrimoire }, { writeRelease }] = await Promise.all([\n import(\"../written\"),\n import(\"../releases\"),\n ]);\n const release = text(input, \"release\").trim();\n\n if (release === \"\" || /[\\\\/]/.test(release)) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass a release name like 1.1.0 (got ${JSON.stringify(release)}).`,\n );\n }\n\n return await writeRelease(root, (await parseGrimoire(root)).written, release);\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_explain\",\n description:\n \"What a Grimoire code (GR1001…GR9006) means, what to do, the skill that explains it and its docs link. Read-only.\",\n input: inputSchema({ code: { type: \"string\", description: \"The code, like GR2001.\" } }, [\n \"code\",\n ]),\n writes: false,\n run: async (input) => {\n const definition = explainGrimoireCode(text(input, \"code\"));\n\n if (!definition) {\n throw new Error(\n `Unknown Grimoire code ${JSON.stringify(text(input, \"code\"))}. Codes look like GR2001; the full list is at the check guide.`,\n );\n }\n\n return { ...definition, docs: grimoireCodeDocsUrl(definition.code) };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;AA0BA,SAAS,UAAU,OAAuB;CACxC,IAAI,iBAAiB,eAAe;EAClC,MAAM,MAAM,oBAAoB,MAAM,IAAI,CAAC,EAAE;EAE7C,MAAM,IAAI,MAAM,GAAG,MAAM,KAAK,IAAI,MAAM,UAAU,MAAM,SAAS,QAAQ,IAAI;CAC/E;CAEA,MAAM;AACR;AAEA,SAAS,KAAK,OAAgC,MAAsB;CAClE,MAAM,QAAQ,MAAM;CAEpB,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;;AAGA,SAAgB,uBACd,SACA,UAAiC,CAAC,GAClC,YACkB;CAClB,MAAM,OAAO,QAAQ;CACrB,IAAI;CAGJ,MAAM,oBAA0C;EAC9C,YACE,aAAa,KACb,OAAO,gBAAY,CAAC,MAAM,EAAE,2BAC1B,qBAAqB;GACnB,GAAG;GACH,UAAU,OAAO,aAAa,QAAQ,QAAQ,QAAQ;EACxD,CAAC,CACH;EAEF,OAAO;CACT;CAEA,MAAM,OACH,UACD,OAAO,UAA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,MAAM,aAAa,OAAO,MAAM,cAAc,IAAI,EAAC,CAAE,SAAS,OAAO;IAC9E,SAAS,OAAO;KACd,OAAO,UAAU,KAAK;IACxB;GACF;EACF;EACA;GACE,MAAM;GACN,aACE;GACF,OAAO,YAAY,EAAE,MAAM;IAAE,MAAM;IAAU,aAAa;GAAyB,EAAE,GAAG,CACtF,MACF,CAAC;GACD,QAAQ;GACR,KAAK,OAAO,UAAU;IACpB,MAAM,aAAa,oBAAoB,KAAK,OAAO,MAAM,CAAC;IAE1D,IAAI,CAAC,YACH,MAAM,IAAI,MACR,yBAAyB,KAAK,UAAU,KAAK,OAAO,MAAM,CAAC,EAAE,+DAC/D;IAGF,OAAO;KAAE,GAAG;KAAY,MAAM,oBAAoB,WAAW,IAAI;IAAE;GACrE;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BookMobileApp } from "../contracts/adapter.mjs";
|
|
2
|
+
//#region ../../packages/grimoire/src/warlock/mobile-facts.d.ts
|
|
3
|
+
/** One mobile app to look at: its folder, its id, and how it routes. */
|
|
4
|
+
export type MobileAppOption = {
|
|
5
|
+
root: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
routing?: "files" | "code";
|
|
8
|
+
};
|
|
9
|
+
/** Options of `collectMobileFacts()`. */
|
|
10
|
+
export type CollectMobileFactsOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* Mobile apps in the repository. Default: every top-level folder with an
|
|
13
|
+
* `app.json` or an `app.config.*` file; it is file-routed when its
|
|
14
|
+
* `package.json` lists `expo-router`, and code-navigated otherwise.
|
|
15
|
+
*/
|
|
16
|
+
mobile?: readonly MobileAppOption[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The mobile apps of the repository as `BookFacts.mobile`.
|
|
20
|
+
*
|
|
21
|
+
* A file-routed app (Expo Router: `app/` or `src/app/`) lists its screens
|
|
22
|
+
* from the file names: groups `(tabs)` are not part of the route, `index` is
|
|
23
|
+
* the folder's route, `[id]` stays as written, and `_layout`, `+not-found`,
|
|
24
|
+
* `+html` and `+api` files are not screens. A code-navigated app has
|
|
25
|
+
* `routing: "code"`, `routesDir: null` and no screens; the agent declares
|
|
26
|
+
* them in `grimoire/apps/<app>/screens/`.
|
|
27
|
+
*
|
|
28
|
+
* @param root Absolute project root.
|
|
29
|
+
*/
|
|
30
|
+
export declare function collectMobileFacts(root: string, options?: CollectMobileFactsOptions): Promise<BookMobileApp[]>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//# sourceMappingURL=mobile-facts.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile-facts.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/mobile-facts.ts"],"mappings":";;;YAaY;EAAoB;EAAc;EAAa;;;YAG/C;;;;;;EAMV,kBAAkB;;;;;;;;;;;;;;wBAoME,mBACpB,cACA,UAAS,4BACR,QAAQ"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { promises } from "node:fs";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/grimoire/src/warlock/mobile-facts.ts
|
|
5
|
+
/**
|
|
6
|
+
* The `mobile` facts of the Warlock adapter: mobile apps that live in the
|
|
7
|
+
* same repository, with their screens when they use file-based routing.
|
|
8
|
+
*
|
|
9
|
+
* Reads file and folder names only (and `package.json` to see whether the app
|
|
10
|
+
* uses Expo Router). It never parses app source and never imports
|
|
11
|
+
* `@warlock.js/core`.
|
|
12
|
+
*/
|
|
13
|
+
const CODE_EXTENSIONS = [
|
|
14
|
+
".ts",
|
|
15
|
+
".tsx",
|
|
16
|
+
".js",
|
|
17
|
+
".jsx"
|
|
18
|
+
];
|
|
19
|
+
const PLATFORM_SUFFIX = /\.(web|native|ios|android)$/;
|
|
20
|
+
const IGNORED_FOLDERS = /* @__PURE__ */ new Set([
|
|
21
|
+
"node_modules",
|
|
22
|
+
".git",
|
|
23
|
+
".expo",
|
|
24
|
+
"dist",
|
|
25
|
+
"build",
|
|
26
|
+
"android",
|
|
27
|
+
"ios"
|
|
28
|
+
]);
|
|
29
|
+
/** Code-point order, the same on every machine and locale. */
|
|
30
|
+
function compare(left, right) {
|
|
31
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
async function exists(file) {
|
|
34
|
+
try {
|
|
35
|
+
await promises.access(file);
|
|
36
|
+
return true;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function readJson(file) {
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(await promises.readFile(file, "utf8"));
|
|
44
|
+
return parsed !== null && typeof parsed === "object" ? parsed : null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function hasDependency(manifest, name) {
|
|
50
|
+
if (!manifest) return false;
|
|
51
|
+
return [
|
|
52
|
+
"dependencies",
|
|
53
|
+
"devDependencies",
|
|
54
|
+
"peerDependencies"
|
|
55
|
+
].some((key) => {
|
|
56
|
+
const group = manifest[key];
|
|
57
|
+
return group !== null && typeof group === "object" && name in group;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async function isMobileFolder(dir) {
|
|
61
|
+
if (await exists(path.join(dir, "app.json"))) return true;
|
|
62
|
+
return (await promises.readdir(dir).catch(() => [])).some((entry) => /^app\.config\.(ts|js|mjs|cjs|json)$/.test(entry));
|
|
63
|
+
}
|
|
64
|
+
/** Top-level folders that look like a mobile app, with their routing. */
|
|
65
|
+
async function discover(root) {
|
|
66
|
+
const entries = await promises.readdir(root, { withFileTypes: true }).catch(() => []);
|
|
67
|
+
const found = [];
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || IGNORED_FOLDERS.has(entry.name)) continue;
|
|
70
|
+
const dir = path.join(root, entry.name);
|
|
71
|
+
if (!await isMobileFolder(dir)) continue;
|
|
72
|
+
const manifest = await readJson(path.join(dir, "package.json"));
|
|
73
|
+
found.push({
|
|
74
|
+
root: entry.name,
|
|
75
|
+
routing: hasDependency(manifest, "expo-router") ? "files" : "code"
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return found.sort((left, right) => compare(left.root, right.root));
|
|
79
|
+
}
|
|
80
|
+
/** Every code file under a folder, as POSIX paths relative to it. */
|
|
81
|
+
async function walk(dir, base = "") {
|
|
82
|
+
const entries = await promises.readdir(path.join(dir, base), { withFileTypes: true }).catch(() => []);
|
|
83
|
+
const files = [];
|
|
84
|
+
for (const entry of entries) {
|
|
85
|
+
const relative = base === "" ? entry.name : `${base}/${entry.name}`;
|
|
86
|
+
if (entry.isDirectory()) {
|
|
87
|
+
if (!IGNORED_FOLDERS.has(entry.name)) files.push(...await walk(dir, relative));
|
|
88
|
+
} else if (entry.isFile()) files.push(relative);
|
|
89
|
+
}
|
|
90
|
+
return files;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The route of a file under the routes folder, or `null` when it is not a
|
|
94
|
+
* screen: `_layout`, `+not-found`, `+html`, `+native-intent`, API routes
|
|
95
|
+
* (`name+api`), declaration and test files.
|
|
96
|
+
*/
|
|
97
|
+
function routeOf(relative) {
|
|
98
|
+
const extension = CODE_EXTENSIONS.find((item) => relative.endsWith(item));
|
|
99
|
+
if (!extension || relative.endsWith(".d.ts")) return null;
|
|
100
|
+
const segments = relative.slice(0, -extension.length).replace(PLATFORM_SUFFIX, "").split("/");
|
|
101
|
+
const name = segments[segments.length - 1] ?? "";
|
|
102
|
+
if (name === "_layout" || name.startsWith("+") || name.endsWith("+api")) return null;
|
|
103
|
+
if (/\.(spec|test)$/.test(name) || segments.includes("__tests__")) return null;
|
|
104
|
+
return `/${segments.filter((segment) => !/^\(.*\)$/.test(segment) && segment !== "index").join("/")}`;
|
|
105
|
+
}
|
|
106
|
+
/** `_layout` files that wrap a screen, outermost first. */
|
|
107
|
+
function layoutsOf(relative, layouts) {
|
|
108
|
+
const folders = relative.split("/").slice(0, -1);
|
|
109
|
+
const result = [];
|
|
110
|
+
const outermost = layouts.get("");
|
|
111
|
+
if (outermost) result.push(outermost);
|
|
112
|
+
folders.forEach((_folder, index) => {
|
|
113
|
+
const layout = layouts.get(folders.slice(0, index + 1).join("/"));
|
|
114
|
+
if (layout) result.push(layout);
|
|
115
|
+
});
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
async function screensOf(root, routesDir) {
|
|
119
|
+
const files = (await walk(path.join(root, routesDir))).sort();
|
|
120
|
+
const layouts = /* @__PURE__ */ new Map();
|
|
121
|
+
for (const relative of files) {
|
|
122
|
+
const extension = CODE_EXTENSIONS.find((item) => relative.endsWith(item));
|
|
123
|
+
const name = extension ? relative.slice(0, -extension.length).replace(PLATFORM_SUFFIX, "") : "";
|
|
124
|
+
if (name === "_layout" || name.endsWith("/_layout")) {
|
|
125
|
+
const folder = name.slice(0, -7).replace(/\/$/, "");
|
|
126
|
+
if (!layouts.has(folder)) layouts.set(folder, `${routesDir}/${relative}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const seen = /* @__PURE__ */ new Set();
|
|
130
|
+
const screens = [];
|
|
131
|
+
for (const relative of files) {
|
|
132
|
+
const route = routeOf(relative);
|
|
133
|
+
if (route === null) continue;
|
|
134
|
+
const stem = relative.replace(/\.[^./]+$/, "").replace(PLATFORM_SUFFIX, "");
|
|
135
|
+
if (seen.has(stem)) continue;
|
|
136
|
+
seen.add(stem);
|
|
137
|
+
screens.push({
|
|
138
|
+
route,
|
|
139
|
+
file: `${routesDir}/${relative}`,
|
|
140
|
+
layouts: layoutsOf(relative, layouts)
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return screens.sort((left, right) => compare(left.route, right.route) || compare(left.file, right.file));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The mobile apps of the repository as `BookFacts.mobile`.
|
|
147
|
+
*
|
|
148
|
+
* A file-routed app (Expo Router: `app/` or `src/app/`) lists its screens
|
|
149
|
+
* from the file names: groups `(tabs)` are not part of the route, `index` is
|
|
150
|
+
* the folder's route, `[id]` stays as written, and `_layout`, `+not-found`,
|
|
151
|
+
* `+html` and `+api` files are not screens. A code-navigated app has
|
|
152
|
+
* `routing: "code"`, `routesDir: null` and no screens; the agent declares
|
|
153
|
+
* them in `grimoire/apps/<app>/screens/`.
|
|
154
|
+
*
|
|
155
|
+
* @param root Absolute project root.
|
|
156
|
+
*/
|
|
157
|
+
async function collectMobileFacts(root, options = {}) {
|
|
158
|
+
const configured = options.mobile ?? await discover(root);
|
|
159
|
+
const apps = [];
|
|
160
|
+
for (const item of configured) {
|
|
161
|
+
const appRoot = item.root.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
|
|
162
|
+
const routing = item.routing ?? (hasDependency(await readJson(path.join(root, appRoot, "package.json")), "expo-router") ? "files" : "code");
|
|
163
|
+
let routesDir = null;
|
|
164
|
+
let screens = [];
|
|
165
|
+
if (routing === "files") {
|
|
166
|
+
for (const candidate of ["app", "src/app"]) if (await exists(path.join(root, appRoot, candidate))) {
|
|
167
|
+
routesDir = `${appRoot}/${candidate}`;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
if (routesDir !== null) screens = await screensOf(root, routesDir);
|
|
171
|
+
}
|
|
172
|
+
apps.push({
|
|
173
|
+
id: item.id ?? path.posix.basename(appRoot),
|
|
174
|
+
root: appRoot,
|
|
175
|
+
routing,
|
|
176
|
+
routesDir,
|
|
177
|
+
screens
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return apps;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
export { collectMobileFacts };
|
|
185
|
+
//# sourceMappingURL=mobile-facts.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile-facts.mjs","names":["fs"],"sources":["../../../../../../../../packages/grimoire/src/warlock/mobile-facts.ts"],"sourcesContent":["/**\n * The `mobile` facts of the Warlock adapter: mobile apps that live in the\n * same repository, with their screens when they use file-based routing.\n *\n * Reads file and folder names only (and `package.json` to see whether the app\n * uses Expo Router). It never parses app source and never imports\n * `@warlock.js/core`.\n */\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport type { BookMobileApp, BookScreen } from \"../contracts/adapter\";\n\n/** One mobile app to look at: its folder, its id, and how it routes. */\nexport type MobileAppOption = { root: string; id?: string; routing?: \"files\" | \"code\" };\n\n/** Options of `collectMobileFacts()`. */\nexport type CollectMobileFactsOptions = {\n /**\n * Mobile apps in the repository. Default: every top-level folder with an\n * `app.json` or an `app.config.*` file; it is file-routed when its\n * `package.json` lists `expo-router`, and code-navigated otherwise.\n */\n mobile?: readonly MobileAppOption[];\n};\n\nconst CODE_EXTENSIONS = [\".ts\", \".tsx\", \".js\", \".jsx\"];\nconst PLATFORM_SUFFIX = /\\.(web|native|ios|android)$/;\nconst IGNORED_FOLDERS = new Set([\n \"node_modules\",\n \".git\",\n \".expo\",\n \"dist\",\n \"build\",\n \"android\",\n \"ios\",\n]);\n\n/** Code-point order, the same on every machine and locale. */\nfunction compare(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\nasync function exists(file: string): Promise<boolean> {\n try {\n await fs.access(file);\n\n return true;\n } catch {\n return false;\n }\n}\n\nasync function readJson(file: string): Promise<Record<string, unknown> | null> {\n try {\n const parsed: unknown = JSON.parse(await fs.readFile(file, \"utf8\"));\n\n return parsed !== null && typeof parsed === \"object\"\n ? (parsed as Record<string, unknown>)\n : null;\n } catch {\n return null;\n }\n}\n\nfunction hasDependency(manifest: Record<string, unknown> | null, name: string): boolean {\n if (!manifest) return false;\n\n return [\"dependencies\", \"devDependencies\", \"peerDependencies\"].some((key) => {\n const group = manifest[key];\n\n return (\n group !== null && typeof group === \"object\" && name in (group as Record<string, unknown>)\n );\n });\n}\n\nasync function isMobileFolder(dir: string): Promise<boolean> {\n if (await exists(path.join(dir, \"app.json\"))) return true;\n\n const entries = await fs.readdir(dir).catch(() => [] as string[]);\n\n return entries.some((entry) => /^app\\.config\\.(ts|js|mjs|cjs|json)$/.test(entry));\n}\n\n/** Top-level folders that look like a mobile app, with their routing. */\nasync function discover(root: string): Promise<MobileAppOption[]> {\n const entries = await fs.readdir(root, { withFileTypes: true }).catch(() => []);\n const found: MobileAppOption[] = [];\n\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name.startsWith(\".\") || IGNORED_FOLDERS.has(entry.name))\n continue;\n\n const dir = path.join(root, entry.name);\n\n if (!(await isMobileFolder(dir))) continue;\n\n const manifest = await readJson(path.join(dir, \"package.json\"));\n\n found.push({\n root: entry.name,\n routing: hasDependency(manifest, \"expo-router\") ? \"files\" : \"code\",\n });\n }\n\n return found.sort((left, right) => compare(left.root, right.root));\n}\n\n/** Every code file under a folder, as POSIX paths relative to it. */\nasync function walk(dir: string, base = \"\"): Promise<string[]> {\n const entries = await fs.readdir(path.join(dir, base), { withFileTypes: true }).catch(() => []);\n const files: string[] = [];\n\n for (const entry of entries) {\n const relative = base === \"\" ? entry.name : `${base}/${entry.name}`;\n\n if (entry.isDirectory()) {\n if (!IGNORED_FOLDERS.has(entry.name)) files.push(...(await walk(dir, relative)));\n } else if (entry.isFile()) {\n files.push(relative);\n }\n }\n\n return files;\n}\n\n/**\n * The route of a file under the routes folder, or `null` when it is not a\n * screen: `_layout`, `+not-found`, `+html`, `+native-intent`, API routes\n * (`name+api`), declaration and test files.\n */\nfunction routeOf(relative: string): string | null {\n const extension = CODE_EXTENSIONS.find((item) => relative.endsWith(item));\n\n if (!extension || relative.endsWith(\".d.ts\")) return null;\n\n const withoutExtension = relative.slice(0, -extension.length).replace(PLATFORM_SUFFIX, \"\");\n const segments = withoutExtension.split(\"/\");\n const name = segments[segments.length - 1] ?? \"\";\n\n if (name === \"_layout\" || name.startsWith(\"+\") || name.endsWith(\"+api\")) return null;\n if (/\\.(spec|test)$/.test(name) || segments.includes(\"__tests__\")) return null;\n\n const url = segments.filter((segment) => !/^\\(.*\\)$/.test(segment) && segment !== \"index\");\n\n return `/${url.join(\"/\")}`;\n}\n\n/** `_layout` files that wrap a screen, outermost first. */\nfunction layoutsOf(relative: string, layouts: ReadonlyMap<string, string>): string[] {\n const folders = relative.split(\"/\").slice(0, -1);\n const result: string[] = [];\n const outermost = layouts.get(\"\");\n\n if (outermost) result.push(outermost);\n\n folders.forEach((_folder, index) => {\n const layout = layouts.get(folders.slice(0, index + 1).join(\"/\"));\n\n if (layout) result.push(layout);\n });\n\n return result;\n}\n\nasync function screensOf(root: string, routesDir: string): Promise<BookScreen[]> {\n const files = (await walk(path.join(root, routesDir))).sort();\n const layouts = new Map<string, string>();\n\n for (const relative of files) {\n const extension = CODE_EXTENSIONS.find((item) => relative.endsWith(item));\n const name = extension ? relative.slice(0, -extension.length).replace(PLATFORM_SUFFIX, \"\") : \"\";\n\n if (name === \"_layout\" || name.endsWith(\"/_layout\")) {\n const folder = name.slice(0, -\"_layout\".length).replace(/\\/$/, \"\");\n\n if (!layouts.has(folder)) layouts.set(folder, `${routesDir}/${relative}`);\n }\n }\n\n const seen = new Set<string>();\n const screens: BookScreen[] = [];\n\n for (const relative of files) {\n const route = routeOf(relative);\n\n if (route === null) continue;\n\n // `home.tsx` and `home.web.tsx` are one screen.\n const stem = relative.replace(/\\.[^./]+$/, \"\").replace(PLATFORM_SUFFIX, \"\");\n\n if (seen.has(stem)) continue;\n\n seen.add(stem);\n screens.push({\n route,\n file: `${routesDir}/${relative}`,\n layouts: layoutsOf(relative, layouts),\n });\n }\n\n return screens.sort(\n (left, right) => compare(left.route, right.route) || compare(left.file, right.file),\n );\n}\n\n/**\n * The mobile apps of the repository as `BookFacts.mobile`.\n *\n * A file-routed app (Expo Router: `app/` or `src/app/`) lists its screens\n * from the file names: groups `(tabs)` are not part of the route, `index` is\n * the folder's route, `[id]` stays as written, and `_layout`, `+not-found`,\n * `+html` and `+api` files are not screens. A code-navigated app has\n * `routing: \"code\"`, `routesDir: null` and no screens; the agent declares\n * them in `grimoire/apps/<app>/screens/`.\n *\n * @param root Absolute project root.\n */\nexport async function collectMobileFacts(\n root: string,\n options: CollectMobileFactsOptions = {},\n): Promise<BookMobileApp[]> {\n const configured = options.mobile ?? (await discover(root));\n const apps: BookMobileApp[] = [];\n\n for (const item of configured) {\n const appRoot = item.root.replace(/\\\\/g, \"/\").replace(/^\\.\\//, \"\").replace(/\\/+$/, \"\");\n const routing =\n item.routing ??\n (hasDependency(await readJson(path.join(root, appRoot, \"package.json\")), \"expo-router\")\n ? \"files\"\n : \"code\");\n let routesDir: string | null = null;\n let screens: BookScreen[] = [];\n\n if (routing === \"files\") {\n for (const candidate of [\"app\", \"src/app\"]) {\n if (await exists(path.join(root, appRoot, candidate))) {\n routesDir = `${appRoot}/${candidate}`;\n break;\n }\n }\n\n if (routesDir !== null) screens = await screensOf(root, routesDir);\n }\n\n apps.push({\n id: item.id ?? path.posix.basename(appRoot),\n root: appRoot,\n routing,\n routesDir,\n screens,\n });\n }\n\n return apps;\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,kBAAkB;CAAC;CAAO;CAAQ;CAAO;AAAM;AACrD,MAAM,kBAAkB;AACxB,MAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAS,QAAQ,MAAc,OAAuB;CACpD,OAAO,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAChD;AAEA,eAAe,OAAO,MAAgC;CACpD,IAAI;EACF,MAAMA,SAAG,OAAO,IAAI;EAEpB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAe,SAAS,MAAuD;CAC7E,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,MAAMA,SAAG,SAAS,MAAM,MAAM,CAAC;EAElE,OAAO,WAAW,QAAQ,OAAO,WAAW,WACvC,SACD;CACN,QAAQ;EACN,OA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zD,MAAM,OAAwB,CAAC;CAE/B,KAAK,MAAM,QAAQ,YAAY;EAC7B,MAAM,UAAU,KAAK,KAAK,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,SAAS,EAAE,CAAC,CAAC,QAAQ,QAAQ,EAAE;EACrF,MAAM,UACJ,KAAK,YACJ,cAAc,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,cAAc,CAAC,GAAG,aAAa,IAClF,UACA;EACN,IAAI,YAA2B;EAC/B,IAAI,UAAwB,CAAC;EAE7B,IAAI,YAAY,SAAS;GACvB,KAAK,MAAM,aAAa,CAAC,OAAO,SAAS,GACvC,IAAI,MAAM,OAAO,KAAK,KAAK,MAAM,SAAS,SAAS,CAAC,GAAG;IACrD,YAAY,GAAG,QAAQ,GAAG;IAC1B;GACF;GAGF,IAAI,cAAc,MAAM,UAAU,MAAM,UAAU,MAAM,SAAS;EACnE;EAEA,KAAK,KAAK;GACR,IAAI,KAAK,MAAM,KAAK,MAAM,SAAS,OAAO;GAC1C,MAAM;GACN;GACA;GACA;EACF,CAAC;CACH;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BookAdapter } from "../contracts/adapter.mjs";
|
|
2
|
+
import { GrimoireSnapshot, OpenGrimoireOptions } from "../contracts/snapshot.mjs";
|
|
3
|
+
//#region ../../packages/grimoire/src/workspace/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Load, refresh and return everything about the project's grimoire.
|
|
6
|
+
*
|
|
7
|
+
* @param root Absolute project root.
|
|
8
|
+
*/
|
|
9
|
+
export declare function openGrimoire(root: string, adapter: BookAdapter, options?: OpenGrimoireOptions): Promise<GrimoireSnapshot>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"mappings":";;;;;;;;wBAkJsB,aACpB,cACA,SAAS,aACT,UAAS,sBACR,QAAQ"}
|