@warlock.js/grimoire 5.58.0 → 5.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/esm/apps/check-apps.mjs +11 -5
  3. package/esm/apps/check-apps.mjs.map +1 -1
  4. package/esm/book/build.d.mts.map +1 -1
  5. package/esm/book/build.mjs.map +1 -1
  6. package/esm/bookmap/build.d.mts.map +1 -1
  7. package/esm/bookmap/build.mjs +5 -3
  8. package/esm/bookmap/build.mjs.map +1 -1
  9. package/esm/bookmap/steps.mjs +34 -3
  10. package/esm/bookmap/steps.mjs.map +1 -1
  11. package/esm/contracts/adapter.d.mts +22 -1
  12. package/esm/contracts/adapter.d.mts.map +1 -1
  13. package/esm/contracts/scry.d.mts +26 -6
  14. package/esm/contracts/scry.d.mts.map +1 -1
  15. package/esm/contracts/snapshot.d.mts +3 -1
  16. package/esm/contracts/snapshot.d.mts.map +1 -1
  17. package/esm/devtools/data.mjs +23 -3
  18. package/esm/devtools/data.mjs.map +1 -1
  19. package/esm/devtools/feature-map.mjs +149 -0
  20. package/esm/devtools/feature-map.mjs.map +1 -0
  21. package/esm/devtools/index.d.mts +2 -2
  22. package/esm/devtools/index.mjs +30 -9
  23. package/esm/devtools/index.mjs.map +1 -1
  24. package/esm/devtools/product-map.d.mts.map +1 -1
  25. package/esm/devtools/product-map.mjs +82 -7
  26. package/esm/devtools/product-map.mjs.map +1 -1
  27. package/esm/devtools/site.d.mts +43 -1
  28. package/esm/devtools/site.d.mts.map +1 -1
  29. package/esm/devtools/site.mjs +111 -15
  30. package/esm/devtools/site.mjs.map +1 -1
  31. package/esm/devtools/snapshot-source.mjs +15 -2
  32. package/esm/devtools/snapshot-source.mjs.map +1 -1
  33. package/esm/index.d.mts +3 -3
  34. package/esm/ownership/index.d.mts.map +1 -1
  35. package/esm/ownership/index.mjs +60 -1
  36. package/esm/ownership/index.mjs.map +1 -1
  37. package/esm/scry/compact.mjs +2 -1
  38. package/esm/scry/compact.mjs.map +1 -1
  39. package/esm/scry/format.d.mts.map +1 -1
  40. package/esm/scry/format.mjs +12 -1
  41. package/esm/scry/format.mjs.map +1 -1
  42. package/esm/scry/query.d.mts.map +1 -1
  43. package/esm/scry/query.mjs +147 -23
  44. package/esm/scry/query.mjs.map +1 -1
  45. package/esm/test-results/index.d.mts.map +1 -1
  46. package/esm/test-results/index.mjs.map +1 -1
  47. package/esm/warlock/actions.mjs +15 -7
  48. package/esm/warlock/actions.mjs.map +1 -1
  49. package/esm/warlock/adapter.d.mts.map +1 -1
  50. package/esm/warlock/adapter.mjs +36 -2
  51. package/esm/warlock/adapter.mjs.map +1 -1
  52. package/esm/warlock/commands.mjs +7 -2
  53. package/esm/warlock/commands.mjs.map +1 -1
  54. package/esm/warlock/logo.mjs +12 -0
  55. package/esm/warlock/logo.mjs.map +1 -0
  56. package/esm/warlock/mcp-tools.mjs +6 -6
  57. package/esm/warlock/mcp-tools.mjs.map +1 -1
  58. package/esm/workspace/cache.mjs +194 -0
  59. package/esm/workspace/cache.mjs.map +1 -0
  60. package/esm/workspace/index.d.mts.map +1 -1
  61. package/esm/workspace/index.mjs +3 -1
  62. package/esm/workspace/index.mjs.map +1 -1
  63. package/llms-full.txt +32 -9
  64. package/package.json +3 -3
  65. package/skills/record-a-change/SKILL.md +2 -0
  66. package/skills/use-the-grimoire/SKILL.md +30 -9
  67. package/ui/grimoire-static.js +57 -6
  68. package/ui/grimoire-view.js +1289 -310
  69. package/ui/grimoire.css +583 -2
  70. package/ui/product-map.css +157 -8
  71. package/ui/product-map.js +507 -59
@@ -1 +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: its summary, steps with file counts (direct, in the feature, reachable, type-only) and the first direct imports of each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Pass files with step to list one step's reachable or type-only files, a page at a time. Read-only.\",\n input: inputSchema(\n {\n flow: { type: \"string\", description: \"<feature>/<flow>, like catalog/new-arrivals.\" },\n files: {\n type: \"string\",\n enum: [\"reachable\", \"type-only\"],\n description: \"With step: list the step's files that run (reachable) or only type imports reach (type-only).\",\n },\n step: { type: \"integer\", description: \"Step number, for files.\", minimum: 0 },\n offset: { type: \"integer\", description: \"First file to list (default 0); a page holds 200.\", minimum: 0 },\n },\n [\"flow\"],\n ),\n writes: false,\n run: async (input) => {\n try {\n const [{ parseFlowText, scry }, { openGrimoire }, compact] = await Promise.all([\n scryParts(),\n import(\"../workspace\"),\n import(\"../scry/compact\"),\n ]);\n const query = { type: \"flow\" as const, ...parseFlowText(text(input, \"flow\")) };\n const snapshot = await openGrimoire(root, await loadAdapter(), { routes: \"cached\" });\n const result = scry(snapshot, query);\n\n if (result.type !== \"flow\") return result;\n\n const set = input.files;\n\n if (set === undefined || set === null) return compact.compactFlow(snapshot, result);\n\n if (set !== \"reachable\" && set !== \"type-only\") {\n throw new GrimoireError(\"GR9006\", 'Pass files as \"reachable\" or \"type-only\".');\n }\n\n const stepNumber = input.step;\n const step = result.bookmap.steps.find((item) => item.index === stepNumber);\n\n if (typeof stepNumber !== \"number\" || step === undefined) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass step as one of the step numbers of ${result.bookmap.ref} (${result.bookmap.steps.map((item) => item.index).join(\", \")}).`,\n );\n }\n\n const offset = typeof input.offset === \"number\" && input.offset > 0 ? input.offset : 0;\n\n return compact.stepFilePage(snapshot, result.bookmap, step, set, offset, 200);\n } catch (error) {\n return toolError(error);\n }\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,2BAC1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AAS,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"}
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: its summary, steps with file counts (direct, in the feature, reachable, type-only) and the first direct imports of each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Pass files with step to list one step's reachable or type-only files, a page at a time. Read-only.\",\n input: inputSchema(\n {\n flow: { type: \"string\", description: \"<feature>/<flow>, like catalog/new-arrivals.\" },\n files: {\n type: \"string\",\n enum: [\"reachable\", \"type-only\"],\n description:\n \"With step: list the step's files that run (reachable) or only type imports reach (type-only).\",\n },\n step: { type: \"integer\", description: \"Step number, for files.\", minimum: 0 },\n offset: {\n type: \"integer\",\n description: \"First file to list (default 0); a page holds 200.\",\n minimum: 0,\n },\n },\n [\"flow\"],\n ),\n writes: false,\n run: async (input) => {\n try {\n const [{ parseFlowText, scry }, { openGrimoireCached }, compact] = await Promise.all([\n scryParts(),\n import(\"../workspace/cache\"),\n import(\"../scry/compact\"),\n ]);\n const query = { type: \"flow\" as const, ...parseFlowText(text(input, \"flow\")) };\n const snapshot = await openGrimoireCached(root, await loadAdapter(), {\n routes: \"cached\",\n });\n const result = scry(snapshot, query);\n\n if (result.type !== \"flow\") return result;\n\n const set = input.files;\n\n if (set === undefined || set === null) return compact.compactFlow(snapshot, result);\n\n if (set !== \"reachable\" && set !== \"type-only\") {\n throw new GrimoireError(\"GR9006\", 'Pass files as \"reachable\" or \"type-only\".');\n }\n\n const stepNumber = input.step;\n const step = result.bookmap.steps.find((item) => item.index === stepNumber);\n\n if (typeof stepNumber !== \"number\" || step === undefined) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass step as one of the step numbers of ${result.bookmap.ref} (${result.bookmap.steps.map((item) => item.index).join(\", \")}).`,\n );\n }\n\n const offset = typeof input.offset === \"number\" && input.offset > 0 ? input.offset : 0;\n\n return compact.stepFilePage(snapshot, result.bookmap, step, set, offset, 200);\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_search\",\n description:\n \"Search the Grimoire by words (the written text of flows too: summary, story, cases, criteria such as AC-5; written content ranks first and hits are grouped by type): 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 [{ openGrimoireCached }, { checkGrimoire }] = await Promise.all([\n import(\"../workspace/cache\"),\n import(\"../check\"),\n ]);\n\n return checkGrimoire(\n await openGrimoireCached(root, await loadAdapter(), { routes: \"cached\" }),\n );\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,UAAqD;EAC1D,IAAI;GACF,MAAM,EAAE,WAAW,MAAM,OAAO;GAEhC,OAAO,MAAM,OAAO,MAAM,MAAM,YAAY,GAAG,MAAM,MAAM,KAAK,CAAC;EACnE,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEF,MAAM,kBAAkB,OAAO;CAE/B,OAAO;EACL;GACE,MAAM;GACN,aACE;GACF,OAAO,YACL,EAAE,MAAM;IAAE,MAAM;IAAU,aAAa;GAA4C,EAAE,GACrF,CAAC,MAAM,CACT;GACA,QAAQ;GACR,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_PATHS } from "../paths/index.mjs";
2
+ import { resolveResultsFile } from "../test-results/index.mjs";
3
+ import { openGrimoire } from "./index.mjs";
4
+ import path from "node:path";
5
+ import { createHash } from "node:crypto";
6
+ import { readdir, stat } from "node:fs/promises";
7
+
8
+ //#region ../../packages/grimoire/src/workspace/cache.ts
9
+ /**
10
+ * Keeps the opened book in memory between calls of one process (the MCP
11
+ * server answers many questions per process) and says cheaply whether it is
12
+ * still current.
13
+ *
14
+ * Freshness is a stamp of `stat` results, no file is read: the size and
15
+ * modified time of every code and test file the book lists, the modified time
16
+ * of each folder that holds one and of every folder above it up to the project root (a new or removed file moves its
17
+ * folder; a new module folder moves its parent), every
18
+ * file under the written folders (`grimoire/features`, `apps`, `releases`,
19
+ * `tasks`, `screenshots`), the book manifest, the test results file and
20
+ * `package.json`. A stamp that equals the one taken after the last open
21
+ * returns the same snapshot; any difference opens the book again.
22
+ */
23
+ /** The written folders whose every file is part of the stamp. */
24
+ const WRITTEN_TREES = [
25
+ GRIMOIRE_PATHS.features,
26
+ GRIMOIRE_PATHS.apps,
27
+ GRIMOIRE_PATHS.releases,
28
+ GRIMOIRE_PATHS.tasks,
29
+ GRIMOIRE_PATHS.screenshots
30
+ ];
31
+ const STAT_BATCH = 256;
32
+ async function statLine(absolute, withSize) {
33
+ try {
34
+ const info = await stat(absolute);
35
+ return withSize ? `${info.size}:${info.mtimeMs}` : String(info.mtimeMs);
36
+ } catch {
37
+ return "-";
38
+ }
39
+ }
40
+ async function statAll(files, withSize) {
41
+ const lines = [];
42
+ for (let start = 0; start < files.length; start += STAT_BATCH) lines.push(...await Promise.all(files.slice(start, start + STAT_BATCH).map((file) => statLine(file, withSize))));
43
+ return lines;
44
+ }
45
+ /** Every file below `folder` (absolute paths, sorted); a missing folder gives none. */
46
+ async function filesUnder(folder) {
47
+ const found = [];
48
+ const walk = async (current) => {
49
+ let entries;
50
+ try {
51
+ entries = await readdir(current, { withFileTypes: true });
52
+ } catch {
53
+ return;
54
+ }
55
+ for (const entry of entries) {
56
+ const next = path.join(current, entry.name);
57
+ if (entry.isDirectory()) await walk(next);
58
+ else found.push(next);
59
+ }
60
+ };
61
+ await walk(folder);
62
+ return found.sort();
63
+ }
64
+ /**
65
+ * The freshness stamp of a project, from the files of `snapshot` (its code and
66
+ * test files) and the written folders as they are now. Reads no file content.
67
+ */
68
+ async function stampOf(root, snapshot, testResultsFile) {
69
+ return (await takeStamp(root, snapshot, testResultsFile)).stamp;
70
+ }
71
+ /**
72
+ * The stat lines of a stamp hold `size:mtime` or `mtime`; the newest mtime of them that is not after `until`
73
+ * (a time in the future is clock skew, not an edit), 0 when none.
74
+ */
75
+ function newestOf(lines, until) {
76
+ let newest = 0;
77
+ for (const line of lines) {
78
+ const value = Number(line.split(":").pop());
79
+ if (Number.isFinite(value) && value <= until && value > newest) newest = value;
80
+ }
81
+ return newest;
82
+ }
83
+ /** Every folder above `folder` up to (not including) the project root. */
84
+ function withAncestors(folders) {
85
+ const all = /* @__PURE__ */ new Set();
86
+ for (const folder of folders) {
87
+ let current = folder;
88
+ while (current !== "." && current !== "" && current !== "/") {
89
+ all.add(current);
90
+ current = path.posix.dirname(current.split(path.sep).join("/"));
91
+ }
92
+ }
93
+ return [...all].sort();
94
+ }
95
+ /** The stamp, and the newest modified time among the code, test and written files and their folders. */
96
+ async function takeStamp(root, snapshot, testResultsFile) {
97
+ const listed = [...snapshot.book.facts.files.map((file) => file.file), ...snapshot.book.facts.tests];
98
+ const folders = withAncestors([...new Set(listed.map((file) => path.dirname(file)))]);
99
+ const written = (await Promise.all(WRITTEN_TREES.map((tree) => filesUnder(path.join(root, ...tree.split("/")))))).flat();
100
+ const singles = [
101
+ path.join(root, ...GRIMOIRE_PATHS.bookManifest.split("/")),
102
+ path.join(root, ...GRIMOIRE_PATHS.bookRoutes.split("/")),
103
+ resolveResultsFile(root, testResultsFile),
104
+ path.join(root, "package.json")
105
+ ];
106
+ const [fileLines, folderLines, writtenLines, singleLines] = await Promise.all([
107
+ statAll(listed.map((file) => path.join(root, ...file.split("/"))), true),
108
+ statAll(folders.map((folder) => path.join(root, ...folder.split(path.sep))), false),
109
+ statAll(written, true),
110
+ statAll(singles, true)
111
+ ]);
112
+ return {
113
+ stamp: createHash("sha1").update(JSON.stringify([
114
+ listed,
115
+ fileLines,
116
+ folders,
117
+ folderLines,
118
+ written,
119
+ writtenLines,
120
+ singleLines
121
+ ])).digest("hex"),
122
+ newest: newestOf([
123
+ ...fileLines,
124
+ ...folderLines,
125
+ ...writtenLines
126
+ ], Date.now())
127
+ };
128
+ }
129
+ /** What a cached open is asked with; two different asks never share an entry. */
130
+ function keyOf(root, options) {
131
+ return JSON.stringify([
132
+ root,
133
+ options.write !== false,
134
+ options.testResultsFile ?? null
135
+ ]);
136
+ }
137
+ /**
138
+ * Create a cache. `reopen` is how the book is opened (default `openGrimoire`);
139
+ * specs pass a counter to see how many times the book was really opened.
140
+ */
141
+ function createBookCache(reopen = openGrimoire) {
142
+ const kept = /* @__PURE__ */ new Map();
143
+ const opening = /* @__PURE__ */ new Map();
144
+ const writing = /* @__PURE__ */ new Map();
145
+ const openOnce = async (key, root, adapter, options) => {
146
+ const startedAt = Date.now();
147
+ const snapshot = await reopen(root, adapter, options);
148
+ const { stamp, newest } = await takeStamp(root, snapshot, options.testResultsFile);
149
+ kept.set(key, {
150
+ snapshot,
151
+ stamp: newest > startedAt ? `unsettled:${stamp}` : stamp
152
+ });
153
+ return snapshot;
154
+ };
155
+ return {
156
+ async open(root, adapter, options = {}) {
157
+ const key = keyOf(root, options);
158
+ const known = kept.get(key);
159
+ const mustOpen = options.force === true || options.routes === "fresh";
160
+ if (known !== void 0 && !mustOpen) {
161
+ if (await stampOf(root, known.snapshot, options.testResultsFile) === known.stamp) return known.snapshot;
162
+ }
163
+ const running = opening.get(key);
164
+ if (running !== void 0 && !mustOpen) return running;
165
+ let started;
166
+ if (options.write === false) started = openOnce(key, root, adapter, options);
167
+ else {
168
+ started = (writing.get(root) ?? Promise.resolve()).catch(() => void 0).then(() => openOnce(key, root, adapter, options));
169
+ writing.set(root, started);
170
+ started.catch(() => void 0).finally(() => {
171
+ if (writing.get(root) === started) writing.delete(root);
172
+ });
173
+ }
174
+ const tracked = started.finally(() => {
175
+ if (opening.get(key) === tracked) opening.delete(key);
176
+ });
177
+ opening.set(key, tracked);
178
+ return tracked;
179
+ },
180
+ clear() {
181
+ kept.clear();
182
+ }
183
+ };
184
+ }
185
+ /** The process-wide cache the MCP tools and `warlock scry` use. */
186
+ const openedBooks = createBookCache();
187
+ /** `openGrimoire` that keeps the book in memory while nothing changed. */
188
+ function openGrimoireCached(root, adapter, options = {}) {
189
+ return openedBooks.open(root, adapter, options);
190
+ }
191
+
192
+ //#endregion
193
+ export { createBookCache, openGrimoireCached, openedBooks, stampOf };
194
+ //# sourceMappingURL=cache.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/cache.ts"],"sourcesContent":["/**\n * Keeps the opened book in memory between calls of one process (the MCP\n * server answers many questions per process) and says cheaply whether it is\n * still current.\n *\n * Freshness is a stamp of `stat` results, no file is read: the size and\n * modified time of every code and test file the book lists, the modified time\n * of each folder that holds one and of every folder above it up to the project root (a new or removed file moves its\n * folder; a new module folder moves its parent), every\n * file under the written folders (`grimoire/features`, `apps`, `releases`,\n * `tasks`, `screenshots`), the book manifest, the test results file and\n * `package.json`. A stamp that equals the one taken after the last open\n * returns the same snapshot; any difference opens the book again.\n */\nimport { createHash } from \"node:crypto\";\nimport { readdir, stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { resolveResultsFile } from \"../test-results\";\nimport { openGrimoire } from \"./index\";\n\n/** The written folders whose every file is part of the stamp. */\nconst WRITTEN_TREES = [\n GRIMOIRE_PATHS.features,\n GRIMOIRE_PATHS.apps,\n GRIMOIRE_PATHS.releases,\n GRIMOIRE_PATHS.tasks,\n GRIMOIRE_PATHS.screenshots,\n];\n\nconst STAT_BATCH = 256;\n\nasync function statLine(absolute: string, withSize: boolean): Promise<string> {\n try {\n const info = await stat(absolute);\n\n return withSize ? `${info.size}:${info.mtimeMs}` : String(info.mtimeMs);\n } catch {\n return \"-\";\n }\n}\n\nasync function statAll(files: readonly string[], withSize: boolean): Promise<string[]> {\n const lines: string[] = [];\n\n for (let start = 0; start < files.length; start += STAT_BATCH) {\n lines.push(\n ...(await Promise.all(\n files.slice(start, start + STAT_BATCH).map((file) => statLine(file, withSize)),\n )),\n );\n }\n\n return lines;\n}\n\n/** Every file below `folder` (absolute paths, sorted); a missing folder gives none. */\nasync function filesUnder(folder: string): Promise<string[]> {\n const found: string[] = [];\n const walk = async (current: string): Promise<void> => {\n let entries;\n\n try {\n entries = await readdir(current, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n const next = path.join(current, entry.name);\n\n if (entry.isDirectory()) await walk(next);\n else found.push(next);\n }\n };\n\n await walk(folder);\n\n return found.sort();\n}\n\n/**\n * The freshness stamp of a project, from the files of `snapshot` (its code and\n * test files) and the written folders as they are now. Reads no file content.\n */\nexport async function stampOf(\n root: string,\n snapshot: GrimoireSnapshot,\n testResultsFile?: string,\n): Promise<string> {\n return (await takeStamp(root, snapshot, testResultsFile)).stamp;\n}\n\n/**\n * The stat lines of a stamp hold `size:mtime` or `mtime`; the newest mtime of them that is not after `until`\n * (a time in the future is clock skew, not an edit), 0 when none.\n */\nfunction newestOf(lines: readonly string[], until: number): number {\n let newest = 0;\n\n for (const line of lines) {\n const value = Number(line.split(\":\").pop());\n\n if (Number.isFinite(value) && value <= until && value > newest) newest = value;\n }\n\n return newest;\n}\n\n/** Every folder above `folder` up to (not including) the project root. */\nfunction withAncestors(folders: readonly string[]): string[] {\n const all = new Set<string>();\n\n for (const folder of folders) {\n let current = folder;\n\n while (current !== \".\" && current !== \"\" && current !== \"/\") {\n all.add(current);\n current = path.posix.dirname(current.split(path.sep).join(\"/\"));\n }\n }\n\n return [...all].sort();\n}\n\n/** The stamp, and the newest modified time among the code, test and written files and their folders. */\nasync function takeStamp(\n root: string,\n snapshot: GrimoireSnapshot,\n testResultsFile?: string,\n): Promise<{ stamp: string; newest: number }> {\n const listed = [\n ...snapshot.book.facts.files.map((file) => file.file),\n ...snapshot.book.facts.tests,\n ];\n const folders = withAncestors([...new Set(listed.map((file) => path.dirname(file)))]);\n const written = (\n await Promise.all(WRITTEN_TREES.map((tree) => filesUnder(path.join(root, ...tree.split(\"/\")))))\n ).flat();\n const singles = [\n path.join(root, ...GRIMOIRE_PATHS.bookManifest.split(\"/\")),\n path.join(root, ...GRIMOIRE_PATHS.bookRoutes.split(\"/\")),\n resolveResultsFile(root, testResultsFile),\n path.join(root, \"package.json\"),\n ];\n const [fileLines, folderLines, writtenLines, singleLines] = await Promise.all([\n statAll(\n listed.map((file) => path.join(root, ...file.split(\"/\"))),\n true,\n ),\n statAll(\n folders.map((folder) => path.join(root, ...folder.split(path.sep))),\n false,\n ),\n statAll(written, true),\n statAll(singles, true),\n ]);\n\n const stamp = createHash(\"sha1\")\n .update(\n JSON.stringify([listed, fileLines, folders, folderLines, written, writtenLines, singleLines]),\n )\n .digest(\"hex\");\n\n return { stamp, newest: newestOf([...fileLines, ...folderLines, ...writtenLines], Date.now()) };\n}\n\ntype Entry = { snapshot: GrimoireSnapshot; stamp: string };\n\n/** What a cached open is asked with; two different asks never share an entry. */\nfunction keyOf(root: string, options: OpenGrimoireOptions): string {\n return JSON.stringify([root, options.write !== false, options.testResultsFile ?? null]);\n}\n\n/** A book cache: `open()` returns the kept snapshot while the stamp holds. */\nexport type BookCache = {\n /** The snapshot for `root`: kept when nothing changed, else opened again. `force`, or `routes: \"fresh\"`, always opens. */\n open(\n root: string,\n adapter: BookAdapter,\n options?: OpenGrimoireOptions,\n ): Promise<GrimoireSnapshot>;\n /** Forget everything kept. */\n clear(): void;\n};\n\n/**\n * Create a cache. `reopen` is how the book is opened (default `openGrimoire`);\n * specs pass a counter to see how many times the book was really opened.\n */\nexport function createBookCache(reopen: typeof openGrimoire = openGrimoire): BookCache {\n const kept = new Map<string, Entry>();\n const opening = new Map<string, Promise<GrimoireSnapshot>>();\n // Opens that write the book's files wait for each other, per project.\n const writing = new Map<string, Promise<unknown>>();\n\n const openOnce = async (\n key: string,\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions,\n ): Promise<GrimoireSnapshot> => {\n // The clock is read before the open, so a file edited while it ran is seen as newer than the stamp.\n const startedAt = Date.now();\n const snapshot = await reopen(root, adapter, options);\n const { stamp, newest } = await takeStamp(root, snapshot, options.testResultsFile);\n\n // A change after the start may not be in the snapshot: keep it unstamped so the next call opens again.\n kept.set(key, {\n snapshot,\n stamp: newest > startedAt ? `unsettled:${stamp}` : stamp,\n });\n\n return snapshot;\n };\n\n return {\n async open(root, adapter, options = {}) {\n const key = keyOf(root, options);\n const known = kept.get(key);\n const mustOpen = options.force === true || options.routes === \"fresh\";\n\n if (known !== undefined && !mustOpen) {\n const stamp = await stampOf(root, known.snapshot, options.testResultsFile);\n\n if (stamp === known.stamp) return known.snapshot;\n }\n\n // Concurrent callers wait for the same open.\n const running = opening.get(key);\n\n if (running !== undefined && !mustOpen) return running;\n\n let started: Promise<GrimoireSnapshot>;\n\n if (options.write === false) {\n started = openOnce(key, root, adapter, options);\n } else {\n const before = writing.get(root) ?? Promise.resolve();\n\n started = before.catch(() => undefined).then(() => openOnce(key, root, adapter, options));\n writing.set(root, started);\n started\n .catch(() => undefined)\n .finally(() => {\n if (writing.get(root) === started) writing.delete(root);\n });\n }\n\n const tracked = started.finally(() => {\n if (opening.get(key) === tracked) opening.delete(key);\n });\n\n opening.set(key, tracked);\n\n return tracked;\n },\n clear() {\n kept.clear();\n },\n };\n}\n\n/** The process-wide cache the MCP tools and `warlock scry` use. */\nexport const openedBooks: BookCache = createBookCache();\n\n/** `openGrimoire` that keeps the book in memory while nothing changed. */\nexport function openGrimoireCached(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return openedBooks.open(root, adapter, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,gBAAgB;CACpB,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AAEA,MAAM,aAAa;AAEnB,eAAe,SAAS,UAAkB,UAAoC;CAC5E,IAAI;EACF,MAAM,OAAO,MAAM,KAAK,QAAQ;EAEhC,OAAO,WAAW,GAAG,KAAK,KAAK,GAAG,KAAK,YAAY,OAAO,KAAK,OAAO;CACxE,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAe,QAAQ,OAA0B,UAAsC;CACrF,MAAM,QAAkB,CAAC;CAEzB,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,YACjD,MAAM,KACJ,GAAI,MAAM,QAAQ,IAChB,MAAM,MAAM,OAAO,QAAQ,UAAU,CAAC,CAAC,KAAK,SAAS,SAAS,MAAM,QAAQ,CAAC,CAC/E,CACF;CAGF,OAAO;AACT;;AAGA,eAAe,WAAW,QAAmC;CAC3D,MAAM,QAAkB,CAAC;CACzB,MAAM,OAAO,OAAO,YAAmC;EACrD,IAAI;EAEJ,IAAI;GACF,UAAU,MAAM,QAAQ,SAAS,EAAE,eAAe,KAAK,CAAC;EAC1D,QAAQ;GACN;EACF;EAEA,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,OAAO,KAAK,KAAK,SAAS,MAAM,IAAI;GAE1C,IAAI,MAAM,YAAY,GAAG,MAAM,KAAK,IAAI;QACnC,MAAM,KAAK,IAAI;EACtB;CACF;CAEA,MAAM,KAAK,MAAM;CAEjB,OAAO,MAAM,KAAK;AACpB;;;;;AAMA,eAAsB,QACpB,MACA,UACA,iBACiB;CACjB,QAAQ,MAAM,UAAU,MAAM,UAAU,eAAe,EAA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W,QAAQ,UAAU,QAAQ,QAAQ,WAAW;GAE9D,IAAI,UAAU,UAAa,CAAC,UAG1B;QAAI,MAFgB,QAAQ,MAAM,MAAM,UAAU,QAAQ,eAAe,MAE3D,MAAM,OAAO,OAAO,MAAM;GAAQ;GAIlD,MAAM,UAAU,QAAQ,IAAI,GAAG;GAE/B,IAAI,YAAY,UAAa,CAAC,UAAU,OAAO;GAE/C,IAAI;GAEJ,IAAI,QAAQ,UAAU,OACpB,UAAU,SAAS,KAAK,MAAM,SAAS,OAAO;QACzC;IAGL,WAFe,QAAQ,IAAI,IAAI,KAAK,QAAQ,QAAQ,EAEpC,CAAC,YAAY,MAAS,CAAC,CAAC,WAAW,SAAS,KAAK,MAAM,SAAS,OAAO,CAAC;IACxF,QAAQ,IAAI,MAAM,OAAO;IACzB,QACG,YAAY,MAAS,CAAC,CACtB,cAAc;KACb,IAAI,QAAQ,IAAI,IAAI,MAAM,SAAS,QAAQ,OAAO,IAAI;IACxD,CAAC;GACL;GAEA,MAAM,UAAU,QAAQ,cAAc;IACpC,IAAI,QAAQ,IAAI,GAAG,MAAM,SAAS,QAAQ,OAAO,GAAG;GACtD,CAAC;GAED,QAAQ,IAAI,KAAK,OAAO;GAExB,OAAO;EACT;EACA,QAAQ;GACN,KAAK,MAAM;EACb;CACF;AACF;;AAGA,MAAa,cAAyB,gBAAgB;;AAGtD,SAAgB,mBACd,MACA,SACA,UAA+B,CAAC,GACL;CAC3B,OAAO,YAAY,KAAK,MAAM,SAAS,OAAO;AAChD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"mappings":";;;;;;;;wBAoJsB,aACpB,cACA,SAAS,aACT,UAAS,sBACR,QAAQ"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"mappings":";;;;;;;;wBAuJsB,aACpB,cACA,SAAS,aACT,UAAS,sBACR,QAAQ"}
@@ -88,6 +88,7 @@ async function runGrimoire(root, adapter, options = {}) {
88
88
  bookWrite = await writeBook(book, annotations);
89
89
  collectedWrite = await writeCollectedFiles(root, collected);
90
90
  }
91
+ const host = await adapter.host?.(root) ?? null;
91
92
  return {
92
93
  snapshot: {
93
94
  root,
@@ -102,7 +103,8 @@ async function runGrimoire(root, adapter, options = {}) {
102
103
  resultsFile,
103
104
  collected,
104
105
  annotations,
105
- routes: book.routes
106
+ routes: book.routes,
107
+ host
106
108
  },
107
109
  rebuilt,
108
110
  changed,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"sourcesContent":["/**\n * The pipeline every command runs first (owned by T-128):\n *\n * 1. `parseGrimoire(root)`;\n * 2. `buildBook(root, adapter, { routes })`;\n * 3. `matchApps`, `resolveOwnership`, `scanProofs`, `readTestResults`;\n * 4. `buildCollectedFiles`, `annotationsFrom`;\n * 5. when `write` is not `false`: `writeBook` and `writeCollectedFiles`.\n *\n * A second run with nothing changed calls no adapter method and writes no file.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { matchApps } from \"../apps\";\nimport { buildBook, writeBook } from \"../book\";\nimport {\n annotationsFrom,\n buildCollectedFiles,\n writeCollectedFiles,\n type CollectedInput,\n} from \"../bookmap\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { BuildBookOptions, WriteBookResult } from \"../contracts/book\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { resolveOwnership } from \"../ownership\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofs } from \"../proves\";\nimport { readTestResults, resultsFileLabel } from \"../test-results\";\nimport { parseGrimoire } from \"../written\";\n\n/** The current sha256 of each test file: the manifest's, else read now (missing files are left out). */\nasync function testFileHashes(\n root: string,\n tests: readonly string[],\n known: Readonly<Record<string, string>>,\n): Promise<Record<string, string>> {\n const hashes: Record<string, string> = {};\n\n for (const test of [...new Set(tests.map(toPosixPath))].sort()) {\n const hash = known[test];\n\n if (hash !== undefined) {\n hashes[test] = hash;\n continue;\n }\n\n try {\n const content = await readFile(path.join(root, ...test.split(\"/\")));\n hashes[test] = createHash(\"sha256\").update(content).digest(\"hex\");\n } catch {\n // A listed test file that is gone has no hash; its results are not marked stale.\n }\n }\n\n return hashes;\n}\n\n/** What one pass of the pipeline did, with the snapshot it produced (`warlock grimoire build` prints it). */\nexport type GrimoireRun = {\n snapshot: GrimoireSnapshot;\n /** `false` when the book's fingerprint matched and the adapter was not asked for files. */\n rebuilt: boolean;\n /** Source files added, changed or removed since the last build. */\n changed: string[];\n /** Book files written and removed (both empty with `write: false`). */\n book: WriteBookResult;\n /** Collected files (book maps, indexes) written and removed (both empty with `write: false`). */\n collected: { written: string[]; removed: string[] };\n};\n\n/**\n * Run the pipeline and say what it wrote. `openGrimoire` is this without the\n * counts.\n *\n * @param root Absolute project root.\n */\nexport async function runGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireRun> {\n const write = options.write !== false;\n const { written, findings: structure } = await parseGrimoire(root);\n\n const bookOptions: BuildBookOptions & { write?: boolean } = {\n routes: options.routes ?? \"cached\",\n };\n\n if (options.force !== undefined) bookOptions.force = options.force;\n if (options.now !== undefined) bookOptions.now = options.now;\n if (!write) bookOptions.write = false;\n\n const { book, rebuilt, changed } = await buildBook(root, adapter, bookOptions);\n const apps = matchApps(written.apps, book.facts);\n const ownership = resolveOwnership(written, book.facts);\n const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);\n const resultsFile = resultsFileLabel(root, options.testResultsFile);\n const results = await readTestResults(root, options.testResultsFile);\n const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);\n\n const input: CollectedInput = {\n written,\n facts: book.facts,\n ownership,\n apps,\n proofs,\n results,\n testHashes,\n };\n const collected = buildCollectedFiles(input);\n const annotations = annotationsFrom(input, collected, { tests: testHashes });\n let bookWrite: WriteBookResult = { written: [], removed: [] };\n let collectedWrite: { written: string[]; removed: string[] } = { written: [], removed: [] };\n\n if (write) {\n bookWrite = await writeBook(book, annotations);\n collectedWrite = await writeCollectedFiles(root, collected);\n }\n\n return {\n snapshot: {\n root,\n written,\n structure,\n book,\n ownership,\n apps,\n proofs,\n proofFindings,\n results,\n resultsFile,\n collected,\n annotations,\n routes: book.routes,\n },\n rebuilt,\n changed,\n book: bookWrite,\n collected: collectedWrite,\n };\n}\n\n/**\n * Load, refresh and return everything about the project's grimoire.\n *\n * @param root Absolute project root.\n */\nexport async function openGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return (await runGrimoire(root, adapter, options)).snapshot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAe,eACb,MACA,OACA,OACiC;CACjC,MAAM,SAAiC,CAAC;CAExC,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;EAC9D,MAAM,OAAO,MAAM;EAEnB,IAAI,SAAS,QAAW;GACtB,OAAO,QAAQ;GACf;EACF;EAEA,IAAI;GACF,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC;GAClE,OAAO,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;EAClE,QAAQ,CAER;CACF;CAEA,OAAO;AACT;;;;;;;AAqBA,eAAsB,YACpB,MACA,SACA,UAA+B,CAAC,GACV;CACtB,MAAM,QAAQ,QAAQ,UAAU;CAChC,MAAM,EAAE,SAAS,UAAU,cAAc,MAAM,cAAc,IAAI;CAEjE,MAAM,cAAsD,EAC1D,QAAQ,QAAQ,UAAU,SAC5B;CAEA,IAAI,QAAQ,UAAU,QAAW,Y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ire/src/workspace/index.ts"],"sourcesContent":["/**\n * The pipeline every command runs first (owned by T-128):\n *\n * 1. `parseGrimoire(root)`;\n * 2. `buildBook(root, adapter, { routes })`;\n * 3. `matchApps`, `resolveOwnership`, `scanProofs`, `readTestResults`;\n * 4. `buildCollectedFiles`, `annotationsFrom`;\n * 5. when `write` is not `false`: `writeBook` and `writeCollectedFiles`.\n *\n * A second run with nothing changed calls no adapter method and writes no file.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { matchApps } from \"../apps\";\nimport { buildBook, writeBook } from \"../book\";\nimport {\n annotationsFrom,\n buildCollectedFiles,\n writeCollectedFiles,\n type CollectedInput,\n} from \"../bookmap\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { BuildBookOptions, WriteBookResult } from \"../contracts/book\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { resolveOwnership } from \"../ownership\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofs } from \"../proves\";\nimport { readTestResults, resultsFileLabel } from \"../test-results\";\nimport { parseGrimoire } from \"../written\";\n\n/** The current sha256 of each test file: the manifest's, else read now (missing files are left out). */\nasync function testFileHashes(\n root: string,\n tests: readonly string[],\n known: Readonly<Record<string, string>>,\n): Promise<Record<string, string>> {\n const hashes: Record<string, string> = {};\n\n for (const test of [...new Set(tests.map(toPosixPath))].sort()) {\n const hash = known[test];\n\n if (hash !== undefined) {\n hashes[test] = hash;\n continue;\n }\n\n try {\n const content = await readFile(path.join(root, ...test.split(\"/\")));\n hashes[test] = createHash(\"sha256\").update(content).digest(\"hex\");\n } catch {\n // A listed test file that is gone has no hash; its results are not marked stale.\n }\n }\n\n return hashes;\n}\n\n/** What one pass of the pipeline did, with the snapshot it produced (`warlock grimoire build` prints it). */\nexport type GrimoireRun = {\n snapshot: GrimoireSnapshot;\n /** `false` when the book's fingerprint matched and the adapter was not asked for files. */\n rebuilt: boolean;\n /** Source files added, changed or removed since the last build. */\n changed: string[];\n /** Book files written and removed (both empty with `write: false`). */\n book: WriteBookResult;\n /** Collected files (book maps, indexes) written and removed (both empty with `write: false`). */\n collected: { written: string[]; removed: string[] };\n};\n\n/**\n * Run the pipeline and say what it wrote. `openGrimoire` is this without the\n * counts.\n *\n * @param root Absolute project root.\n */\nexport async function runGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireRun> {\n const write = options.write !== false;\n const { written, findings: structure } = await parseGrimoire(root);\n\n const bookOptions: BuildBookOptions & { write?: boolean } = {\n routes: options.routes ?? \"cached\",\n };\n\n if (options.force !== undefined) bookOptions.force = options.force;\n if (options.now !== undefined) bookOptions.now = options.now;\n if (!write) bookOptions.write = false;\n\n const { book, rebuilt, changed } = await buildBook(root, adapter, bookOptions);\n const apps = matchApps(written.apps, book.facts);\n const ownership = resolveOwnership(written, book.facts);\n const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);\n const resultsFile = resultsFileLabel(root, options.testResultsFile);\n const results = await readTestResults(root, options.testResultsFile);\n const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);\n\n const input: CollectedInput = {\n written,\n facts: book.facts,\n ownership,\n apps,\n proofs,\n results,\n testHashes,\n };\n const collected = buildCollectedFiles(input);\n const annotations = annotationsFrom(input, collected, { tests: testHashes });\n let bookWrite: WriteBookResult = { written: [], removed: [] };\n let collectedWrite: { written: string[]; removed: string[] } = { written: [], removed: [] };\n\n if (write) {\n bookWrite = await writeBook(book, annotations);\n collectedWrite = await writeCollectedFiles(root, collected);\n }\n\n const host = (await adapter.host?.(root)) ?? null;\n\n return {\n snapshot: {\n root,\n written,\n structure,\n book,\n ownership,\n apps,\n proofs,\n proofFindings,\n results,\n resultsFile,\n collected,\n annotations,\n routes: book.routes,\n host,\n },\n rebuilt,\n changed,\n book: bookWrite,\n collected: collectedWrite,\n };\n}\n\n/**\n * Load, refresh and return everything about the project's grimoire.\n *\n * @param root Absolute project root.\n */\nexport async function openGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return (await runGrimoire(root, adapter, options)).snapshot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAe,eACb,MACA,OACA,OACiC;CACjC,MAAM,SAAiC,CAAC;CAExC,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;EAC9D,MAAM,OAAO,MAAM;EAEnB,IAAI,SAAS,QAAW;GACtB,OAAO,QAAQ;GACf;EACF;EAEA,IAAI;GACF,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC;GAClE,OAAO,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;EAClE,QAAQ,CAER;CACF;CAEA,OAAO;AACT;;;;;;;AAqBA,eAAsB,YACpB,MACA,SACA,UAA+B,CAAC,GACV;CACtB,MAAM,QAAQ,QAAQ,UAAU;CAChC,MAAM,EAAE,SAAS,UAAU,cAAc,MAAM,cAAc,IAAI;CAEjE,MAAM,cAAsD,EAC1D,QAAQ,QAAQ,UAAU,SAC5B;CAEA,IAAI,QAAQ,UAAU,QAAW,YAAY,QAAQ,QAAQ;CAC7D,IAAI,QAAQ,QAAQ,QAAW,YAAY,MAAM,QAAQ;CACzD,IAAI,CAAC,OAAO,YAAY,QAAQ;CAEhC,MAAM,EAAE,MAAM,SAAS,YAAY,MAAM,UAAU,MAAM,SAAS,WAAW;CAC7E,MAAM,OAAO,UAAU,QAAQ,MAAM,KAAK,KAAK;CAC/C,MAAM,YAAY,iBAAiB,SAAS,KAAK,KAAK;CACtD,MAAM,EAAE,QAAQ,UAAU,kBAAkB,MAAM,WAAW,MAAM,KAAK,MAAM,KAAK;CACnF,MAAM,cAAc,iBAAiB,MAAM,QAAQ,eAAe;CAClE,MAAM,UAAU,MAAM,gBAAgB,MAAM,QAAQ,eAAe;CACnE,MAAM,aAAa,MAAM,eAAe,MAAM,KAAK,MAAM,OAAO,KAAK,SAAS,KAAK;CAEnF,MAAM,QAAwB;EAC5B;EACA,OAAO,KAAK;EACZ;EACA;EACA;EACA;EACA;CACF;CACA,MAAM,YAAY,oBAAoB,KAAK;CAC3C,MAAM,cAAc,gBAAgB,OAAO,WAAW,EAAE,OAAO,WAAW,CAAC;CAC3E,IAAI,YAA6B;EAAE,SAAS,CAAC;EAAG,SAAS,CAAC;CAAE;CAC5D,IAAI,iBAA2D;EAAE,SAAS,CAAC;EAAG,SAAS,CAAC;CAAE;CAE1F,IAAI,OAAO;EACT,YAAY,MAAM,UAAU,MAAM,WAAW;EAC7C,iBAAiB,MAAM,oBAAoB,MAAM,SAAS;CAC5D;CAEA,MAAM,OAAQ,MAAM,QAAQ,OAAO,IAAI,KAAM;CAE7C,OAAO;EACL,UAAU;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,QAAQ,KAAK;GACb;EACF;EACA;EACA;EACA,MAAM;EACN,WAAW;CACb;AACF;;;;;;AAOA,eAAsB,aACpB,MACA,SACA,UAA+B,CAAC,GACL;CAC3B,QAAQ,MAAM,YAAY,MAAM,SAAS,OAAO,EAAC,CAAE;AACrD"}
package/llms-full.txt CHANGED
@@ -518,6 +518,8 @@ npx warlock grimoire check
518
518
  | A README `updated` older than its newest changelog entry | Reshape the README |
519
519
  | A changelog version that does not fit the word (`added` with `2.1`) | Fix the version |
520
520
 
521
+ Migrations, seeds, commands, the main file, layouts, roots and test helpers only specs import are never reported (`GR3006`); a route step reaches the middleware its route names. Do not try to describe those in a flow.
522
+
521
523
  **Recording results.** The check and the devtools tab read test results from
522
524
  `grimoire/book/test-results.json`, written by the Grimoire Vitest reporter when the tests run. That
523
525
  folder is not committed, so run the tests with the reporter in CI and ship the results file with the
@@ -644,7 +646,7 @@ npx warlock scry --flow catalog/new-arrivals # one flow,
644
646
 
645
647
  Add `--json` for machine-readable output. `--impact` lists API routes, pages, flows and features,
646
648
  including features that only borrow the file; each list has a count and stops at 20 lines, and `--all`
647
- prints every line. `--search` ranks exact matches first. Read the flows it names and run their tests after
649
+ prints every line. `--search` also reads a flow's summary, story, cases and criteria (`AC-5` works), ranks features and flows above files, and groups hits by type; a hit found by written text shows the part that matched in brackets. Read the flows it names and run their tests after
648
650
  your change.
649
651
 
650
652
  A file's entry is also at a fixed path: `src/app/auth/controllers/login.controller.ts` is described
@@ -652,13 +654,14 @@ in `grimoire/book/app/auth/controllers/login.controller.json`.
652
654
 
653
655
  ## Commands
654
656
 
655
- | Command | Does |
656
- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
657
- | `warlock grimoire build` | Builds or refreshes the book. `scry` and `check` do it when it is stale |
658
- | `warlock grimoire build --site [--out dir]` | Also writes the book as a static site (default `grimoire/book/site`) |
659
- | `warlock grimoire check` | Reports broken names, untested criteria, files with no owner. Exit 1 on an error; `--all` lists every warning |
660
- | `warlock grimoire release <release>` | Writes the collected list into `grimoire/releases/<release>.md` |
661
- | `warlock explain GR2001` | Explains a finding code |
657
+ | Command | Does |
658
+ | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
659
+ | `warlock grimoire build` | Builds or refreshes the book. `scry` and `check` do it when it is stale |
660
+ | `warlock grimoire build --site [--out dir]` | Also writes the book as a static site (default `grimoire/book/site`); skipped when the folder is already current (`--force` writes it) |
661
+ | `warlock grimoire build --site --product` | Writes the business export: the Product map only, no file paths, test names or per-file answers |
662
+ | `warlock grimoire check` | Reports broken names, untested criteria, files with no owner. Exit 1 on an error; `--all` lists every warning |
663
+ | `warlock grimoire release <release>` | Writes the collected list into `grimoire/releases/<release>.md` |
664
+ | `warlock explain GR2001` | Explains a finding code |
662
665
 
663
666
  Every finding has a code (`GR2001`) and a fix hint. A finding marked `(expected)` belongs to work
664
667
  that is still `proposed`; it does not fail the check.
@@ -666,6 +669,8 @@ that is still `proposed`; it does not fail the check.
666
669
  ## What to trust
667
670
 
668
671
  - **Exports, imports, importers, routes, middleware, pages:** read from the code. Trust them.
672
+ - **Route middleware:** a route step also reaches the middleware files the matched route names (not the routes file's other imports). Roles that run by being present (migration, seed, command, main, layout, root) and spec-only helpers are not listed as unreached.
673
+ - **Without route facts** (`routes: missing`): route, mail, notification, job and event steps are `found: null` (not checked), not resolved and not failed; `GR5008` skips mail and notification entries.
669
674
  - **Files behind a route:** every file the handler can reach through imports. It is not the exact
670
675
  call path; open the handler to see which ones it really uses.
671
676
  - **Reached from:** only links and redirects written as plain values. `unknown` means look.
@@ -714,9 +719,27 @@ From `@warlock.js/grimoire` (no dependency on core or web):
714
719
 
715
720
  From `@warlock.js/grimoire/warlock` (needs `@warlock.js/core`): `registerGrimoireCommands` returns
716
721
  the `grimoire` and `scry` commands for `cli.commands` in `warlock.config.ts`;
717
- `createWarlockAdapter` builds the adapter that feeds the book from the inspect report;
722
+ `createWarlockAdapter` builds the adapter that feeds the book from the inspect report (it also supplies the
723
+ optional `host()` described below);
718
724
  `collectMobileFacts` lists mobile screens from Expo Router file names.
719
725
 
726
+ A custom `BookAdapter` may add `host(root)`, returning `{ name, version, logo, app }` (the framework's name,
727
+ installed version and a small `data:` logo, and the app's own `{ name, version }`), or `null`. The tab shows the
728
+ framework logo and version in its header and the app name and version at the bottom, in the static export and
729
+ in the shared Product map too; an adapter without `host()` shows nothing. The summary and product answers carry it
730
+ as `host` (`null` when absent); the feature answer's `flows` also carry `steps`, `cases`, `criteria`, `tested` and
731
+ `findings` counts.
732
+
733
+ The devtools feature route (`/features/:feature`) adds three fields for the tabbed page: `map` (the feature map:
734
+ `columns` are each site and mobile app the flows touch, titled by the app's heading, then `api`, then `background`;
735
+ `rows` has one entry per flow with `cells` keyed by column id, each cell a list of chips `{ step, type, label, found,
736
+ app, page, method, path, file }` taken from the steps the book already resolved), `fileGroups` (the own files by module)
737
+ and `proofs` (each flow's criteria with their tests). Each product map feature card carries `strip`: `flows`
738
+ `{ total, shipped }`, `criteria` `{ total, proven, failing, measured }` (`measured` is `false` when tagged tests have no
739
+ recorded results), `screenshots` `{ places, present }` and `findings` `{ errors, warnings }`. The feature and flow pages
740
+ have tabs with their own hash routes: `feature/<id>[/flows|files|findings|tests]` and
741
+ `flow/<feature>/<flow>[/proof|files|findings]`.
742
+
720
743
  From `@warlock.js/grimoire/vitest`: `grimoireReporter` records the last result of every test marked
721
744
  `// @proves` into `grimoire/book/test-results.json`. Add it to the Vitest `reporters` list.
722
745
  `grimoireReporter({ file })` writes to another path (for a deploy that ships CI results); `readTestResults(root, file?)`
package/package.json CHANGED
@@ -26,15 +26,15 @@
26
26
  "environment": "server"
27
27
  },
28
28
  "peerDependencies": {
29
- "@warlock.js/core": "5.58.0",
30
- "@warlock.js/web": "5.58.0"
29
+ "@warlock.js/core": "5.60.0",
30
+ "@warlock.js/web": "5.60.0"
31
31
  },
32
32
  "peerDependenciesMeta": {
33
33
  "@warlock.js/web": {
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "version": "5.58.0",
37
+ "version": "5.60.0",
38
38
  "type": "module",
39
39
  "main": "./esm/index.mjs",
40
40
  "module": "./esm/index.mjs",
@@ -86,6 +86,8 @@ npx warlock grimoire check
86
86
  | A README `updated` older than its newest changelog entry | Reshape the README |
87
87
  | A changelog version that does not fit the word (`added` with `2.1`) | Fix the version |
88
88
 
89
+ Migrations, seeds, commands, the main file, layouts, roots and test helpers only specs import are never reported (`GR3006`); a route step reaches the middleware its route names. Do not try to describe those in a flow.
90
+
89
91
  **Recording results.** The check and the devtools tab read test results from
90
92
  `grimoire/book/test-results.json`, written by the Grimoire Vitest reporter when the tests run. That
91
93
  folder is not committed, so run the tests with the reporter in CI and ship the results file with the
@@ -61,7 +61,7 @@ npx warlock scry --flow catalog/new-arrivals # one flow,
61
61
 
62
62
  Add `--json` for machine-readable output. `--impact` lists API routes, pages, flows and features,
63
63
  including features that only borrow the file; each list has a count and stops at 20 lines, and `--all`
64
- prints every line. `--search` ranks exact matches first. Read the flows it names and run their tests after
64
+ prints every line. `--search` also reads a flow's summary, story, cases and criteria (`AC-5` works), ranks features and flows above files, and groups hits by type; a hit found by written text shows the part that matched in brackets. Read the flows it names and run their tests after
65
65
  your change.
66
66
 
67
67
  A file's entry is also at a fixed path: `src/app/auth/controllers/login.controller.ts` is described
@@ -69,13 +69,14 @@ in `grimoire/book/app/auth/controllers/login.controller.json`.
69
69
 
70
70
  ## Commands
71
71
 
72
- | Command | Does |
73
- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
74
- | `warlock grimoire build` | Builds or refreshes the book. `scry` and `check` do it when it is stale |
75
- | `warlock grimoire build --site [--out dir]` | Also writes the book as a static site (default `grimoire/book/site`) |
76
- | `warlock grimoire check` | Reports broken names, untested criteria, files with no owner. Exit 1 on an error; `--all` lists every warning |
77
- | `warlock grimoire release <release>` | Writes the collected list into `grimoire/releases/<release>.md` |
78
- | `warlock explain GR2001` | Explains a finding code |
72
+ | Command | Does |
73
+ | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
74
+ | `warlock grimoire build` | Builds or refreshes the book. `scry` and `check` do it when it is stale |
75
+ | `warlock grimoire build --site [--out dir]` | Also writes the book as a static site (default `grimoire/book/site`); skipped when the folder is already current (`--force` writes it) |
76
+ | `warlock grimoire build --site --product` | Writes the business export: the Product map only, no file paths, test names or per-file answers |
77
+ | `warlock grimoire check` | Reports broken names, untested criteria, files with no owner. Exit 1 on an error; `--all` lists every warning |
78
+ | `warlock grimoire release <release>` | Writes the collected list into `grimoire/releases/<release>.md` |
79
+ | `warlock explain GR2001` | Explains a finding code |
79
80
 
80
81
  Every finding has a code (`GR2001`) and a fix hint. A finding marked `(expected)` belongs to work
81
82
  that is still `proposed`; it does not fail the check.
@@ -83,6 +84,8 @@ that is still `proposed`; it does not fail the check.
83
84
  ## What to trust
84
85
 
85
86
  - **Exports, imports, importers, routes, middleware, pages:** read from the code. Trust them.
87
+ - **Route middleware:** a route step also reaches the middleware files the matched route names (not the routes file's other imports). Roles that run by being present (migration, seed, command, main, layout, root) and spec-only helpers are not listed as unreached.
88
+ - **Without route facts** (`routes: missing`): route, mail, notification, job and event steps are `found: null` (not checked), not resolved and not failed; `GR5008` skips mail and notification entries.
86
89
  - **Files behind a route:** every file the handler can reach through imports. It is not the exact
87
90
  call path; open the handler to see which ones it really uses.
88
91
  - **Reached from:** only links and redirects written as plain values. `unknown` means look.
@@ -131,9 +134,27 @@ From `@warlock.js/grimoire` (no dependency on core or web):
131
134
 
132
135
  From `@warlock.js/grimoire/warlock` (needs `@warlock.js/core`): `registerGrimoireCommands` returns
133
136
  the `grimoire` and `scry` commands for `cli.commands` in `warlock.config.ts`;
134
- `createWarlockAdapter` builds the adapter that feeds the book from the inspect report;
137
+ `createWarlockAdapter` builds the adapter that feeds the book from the inspect report (it also supplies the
138
+ optional `host()` described below);
135
139
  `collectMobileFacts` lists mobile screens from Expo Router file names.
136
140
 
141
+ A custom `BookAdapter` may add `host(root)`, returning `{ name, version, logo, app }` (the framework's name,
142
+ installed version and a small `data:` logo, and the app's own `{ name, version }`), or `null`. The tab shows the
143
+ framework logo and version in its header and the app name and version at the bottom, in the static export and
144
+ in the shared Product map too; an adapter without `host()` shows nothing. The summary and product answers carry it
145
+ as `host` (`null` when absent); the feature answer's `flows` also carry `steps`, `cases`, `criteria`, `tested` and
146
+ `findings` counts.
147
+
148
+ The devtools feature route (`/features/:feature`) adds three fields for the tabbed page: `map` (the feature map:
149
+ `columns` are each site and mobile app the flows touch, titled by the app's heading, then `api`, then `background`;
150
+ `rows` has one entry per flow with `cells` keyed by column id, each cell a list of chips `{ step, type, label, found,
151
+ app, page, method, path, file }` taken from the steps the book already resolved), `fileGroups` (the own files by module)
152
+ and `proofs` (each flow's criteria with their tests). Each product map feature card carries `strip`: `flows`
153
+ `{ total, shipped }`, `criteria` `{ total, proven, failing, measured }` (`measured` is `false` when tagged tests have no
154
+ recorded results), `screenshots` `{ places, present }` and `findings` `{ errors, warnings }`. The feature and flow pages
155
+ have tabs with their own hash routes: `feature/<id>[/flows|files|findings|tests]` and
156
+ `flow/<feature>/<flow>[/proof|files|findings]`.
157
+
137
158
  From `@warlock.js/grimoire/vitest`: `grimoireReporter` records the last result of every test marked
138
159
  `// @proves` into `grimoire/book/test-results.json`. Add it to the Vitest `reporters` list.
139
160
  `grimoireReporter({ file })` writes to another path (for a deploy that ships CI results); `readTestResults(root, file?)`