@warlock.js/grimoire 5.61.0 → 5.63.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 +28 -0
- package/esm/book/build.d.mts +17 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +78 -16
- package/esm/book/build.mjs.map +1 -1
- package/esm/book/index.mjs +2 -2
- package/esm/codes/codes.d.mts +2 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +2 -1
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/book.d.mts +7 -0
- package/esm/contracts/book.d.mts.map +1 -1
- package/esm/contracts/book.mjs.map +1 -1
- package/esm/contracts/scry.d.mts +29 -5
- package/esm/contracts/scry.d.mts.map +1 -1
- package/esm/contracts/snapshot.d.mts +8 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/devtools/snapshot-source.mjs +27 -7
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/index.d.mts +5 -3
- package/esm/index.mjs +4 -2
- package/esm/scry/error.mjs +20 -0
- package/esm/scry/error.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +22 -1
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/index.mjs +3 -2
- package/esm/scry/parse.d.mts +1 -1
- package/esm/scry/parse.d.mts.map +1 -1
- package/esm/scry/parse.mjs +12 -9
- package/esm/scry/parse.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +77 -268
- package/esm/scry/query.mjs.map +1 -1
- package/esm/scry/search.d.mts +8 -0
- package/esm/scry/search.d.mts.map +1 -0
- package/esm/scry/search.mjs +401 -0
- package/esm/scry/search.mjs.map +1 -0
- package/esm/warlock/actions.mjs +15 -12
- package/esm/warlock/actions.mjs.map +1 -1
- package/esm/warlock/commands.mjs +14 -4
- package/esm/warlock/commands.mjs.map +1 -1
- package/esm/warlock/mcp-tools.mjs +46 -21
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/workspace/cache.mjs +13 -1
- package/esm/workspace/cache.mjs.map +1 -1
- package/esm/workspace/derived.mjs +107 -0
- package/esm/workspace/derived.mjs.map +1 -0
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +22 -18
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/workspace/stored.d.mts +12 -0
- package/esm/workspace/stored.d.mts.map +1 -0
- package/esm/workspace/stored.mjs +46 -0
- package/esm/workspace/stored.mjs.map +1 -0
- package/llms-full.txt +28 -12
- package/package.json +3 -3
- package/skills/use-the-grimoire/SKILL.md +28 -12
- package/ui/grimoire-view.js +16 -0
package/esm/scry/parse.mjs
CHANGED
|
@@ -54,9 +54,13 @@ function parseLimit(value) {
|
|
|
54
54
|
if (typeof value === "boolean" || !Number.isInteger(limit) || limit < 1) throw malformed(`--limit must be a whole number above 0, got ${JSON.stringify(value)}.`);
|
|
55
55
|
return limit;
|
|
56
56
|
}
|
|
57
|
+
/** An app id for `--app`, checked to have a value. */
|
|
58
|
+
function parseApp(value) {
|
|
59
|
+
return textOf("app", value);
|
|
60
|
+
}
|
|
57
61
|
/**
|
|
58
62
|
* The query of `warlock scry` arguments: a positional file, or one of the
|
|
59
|
-
* options `impact`, `route`, `feature`, `flow`, `search` (with `limit`).
|
|
63
|
+
* options `impact`, `route`, `feature`, `flow`, `search` (with `limit` and `app`).
|
|
60
64
|
* Throws `GrimoireError` `GR9006` for none, several, or a malformed value.
|
|
61
65
|
*/
|
|
62
66
|
function parseScryQuery(args, options) {
|
|
@@ -79,7 +83,8 @@ function parseScryQuery(args, options) {
|
|
|
79
83
|
};
|
|
80
84
|
case "route": return {
|
|
81
85
|
type: "route",
|
|
82
|
-
...parseRouteText(text)
|
|
86
|
+
...parseRouteText(text),
|
|
87
|
+
...options.site === void 0 ? {} : { site: textOf("site", options.site) }
|
|
83
88
|
};
|
|
84
89
|
case "feature": return {
|
|
85
90
|
type: "feature",
|
|
@@ -90,19 +95,17 @@ function parseScryQuery(args, options) {
|
|
|
90
95
|
...parseFlowText(text)
|
|
91
96
|
};
|
|
92
97
|
case "search": {
|
|
93
|
-
const limit = options
|
|
94
|
-
return
|
|
95
|
-
type: "search",
|
|
96
|
-
text
|
|
97
|
-
} : {
|
|
98
|
+
const { limit, app } = options;
|
|
99
|
+
return {
|
|
98
100
|
type: "search",
|
|
99
101
|
text,
|
|
100
|
-
limit: parseLimit(limit)
|
|
102
|
+
...limit === void 0 ? {} : { limit: parseLimit(limit) },
|
|
103
|
+
...app === void 0 ? {} : { app: parseApp(app) }
|
|
101
104
|
};
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
//#endregion
|
|
107
|
-
export { parseFeatureText, parseFlowText, parseLimit, parseRouteText, parseScryQuery };
|
|
110
|
+
export { parseApp, parseFeatureText, parseFlowText, parseLimit, parseRouteText, parseScryQuery };
|
|
108
111
|
//# sourceMappingURL=parse.mjs.map
|
package/esm/scry/parse.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/parse.ts"],"sourcesContent":["/**\n * Turns `warlock scry` arguments (and MCP tool inputs) into one `ScryQuery`.\n */\nimport { GrimoireError } from \"../codes\";\nimport type { ScryQuery } from \"../contracts/scry\";\n\nconst ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst ROUTE = /^\\s*([A-Za-z]+)\\s+(\\/\\S*)\\s*$/;\nconst QUERY_OPTIONS = [\"impact\", \"route\", \"feature\", \"flow\", \"search\"] as const;\nconst FORMS =\n 'warlock scry <file> | --impact <file> | --route \"<METHOD path>\" | --feature <id> | --flow <feature>/<flow> | --search \"<text>\"';\n\nfunction malformed(message: string): GrimoireError {\n return new GrimoireError(\"GR9006\", message);\n}\n\n/** A string option value, or an error naming the option when it was given without one. */\nfunction textOf(name: string, value: string | boolean | number): string {\n if (typeof value === \"boolean\") throw malformed(`--${name} needs a value. Use: ${FORMS}.`);\n\n const text = String(value).trim();\n\n if (text === \"\") throw malformed(`--${name} needs a value. Use: ${FORMS}.`);\n\n return text;\n}\n\n/** `GET /api/products` → `{ method: \"GET\", path: \"/api/products\" }`. */\nexport function parseRouteText(text: string): { method: string; path: string } {\n const match = ROUTE.exec(text);\n\n if (!match || match[1] === undefined || match[2] === undefined) {\n throw malformed(\n `route ${JSON.stringify(text)} is not \"<METHOD> <path>\"; pass it like \"GET /api/products\".`,\n );\n }\n\n return { method: match[1].toUpperCase(), path: match[2] };\n}\n\n/** `catalog/new-arrivals` → `{ feature, flow }`. */\nexport function parseFlowText(text: string): { feature: string; flow: string } {\n const [feature, flow, ...rest] = text.trim().split(\"/\");\n\n if (\n feature === undefined ||\n flow === undefined ||\n rest.length > 0 ||\n !ID.test(feature) ||\n !ID.test(flow)\n ) {\n throw malformed(\n `flow ${JSON.stringify(text)} is not \"<feature>/<flow>\"; pass it like \"catalog/new-arrivals\".`,\n );\n }\n\n return { feature, flow };\n}\n\n/** A feature id, checked. */\nexport function parseFeatureText(text: string): string {\n const feature = text.trim();\n\n if (!ID.test(feature)) {\n throw malformed(\n `feature ${JSON.stringify(text)} is not a feature id; use the folder name under grimoire/features/.`,\n );\n }\n\n return feature;\n}\n\n/** A positive whole number of hits, or an error. */\nexport function parseLimit(value: string | boolean | number): number {\n const limit = typeof value === \"number\" ? value : Number(String(value).trim());\n\n if (typeof value === \"boolean\" || !Number.isInteger(limit) || limit < 1) {\n throw malformed(`--limit must be a whole number above 0, got ${JSON.stringify(value)}.`);\n }\n\n return limit;\n}\n\n/**\n * The query of `warlock scry` arguments: a positional file, or one of the\n * options `impact`, `route`, `feature`, `flow`, `search` (with `limit`).\n * Throws `GrimoireError` `GR9006` for none, several, or a malformed value.\n */\nexport function parseScryQuery(\n args: readonly string[],\n options: Readonly<Record<string, string | boolean | number>>,\n): ScryQuery {\n const given = QUERY_OPTIONS.filter(\n (name) => options[name] !== undefined && options[name] !== false,\n );\n const files = args.filter((arg) => arg.trim() !== \"\");\n\n if (given.length + (files.length > 0 ? 1 : 0) === 0)\n throw malformed(`Nothing to look up. Use: ${FORMS}.`);\n\n if (files.length > 1 || given.length + (files.length > 0 ? 1 : 0) > 1) {\n const asked = [...(files.length > 0 ? [\"<file>\"] : []), ...given.map((name) => `--${name}`)];\n\n throw malformed(`Ask one question at a time; got ${asked.join(\", \")}. Use: ${FORMS}.`);\n }\n\n if (files[0] !== undefined) return { type: \"file\", file: files[0].trim() };\n\n const name = given[0];\n const value = name === undefined ? undefined : options[name];\n\n if (name === undefined || value === undefined)\n throw malformed(`Nothing to look up. Use: ${FORMS}.`);\n\n const text = textOf(name, value);\n\n switch (name) {\n case \"impact\":\n return { type: \"impact\", file: text };\n case \"route\":\n return {
|
|
1
|
+
{"version":3,"file":"parse.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/parse.ts"],"sourcesContent":["/**\n * Turns `warlock scry` arguments (and MCP tool inputs) into one `ScryQuery`.\n */\nimport { GrimoireError } from \"../codes\";\nimport type { ScryQuery } from \"../contracts/scry\";\n\nconst ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst ROUTE = /^\\s*([A-Za-z]+)\\s+(\\/\\S*)\\s*$/;\nconst QUERY_OPTIONS = [\"impact\", \"route\", \"feature\", \"flow\", \"search\"] as const;\nconst FORMS =\n 'warlock scry <file> | --impact <file> | --route \"<METHOD path>\" | --feature <id> | --flow <feature>/<flow> | --search \"<text>\"';\n\nfunction malformed(message: string): GrimoireError {\n return new GrimoireError(\"GR9006\", message);\n}\n\n/** A string option value, or an error naming the option when it was given without one. */\nfunction textOf(name: string, value: string | boolean | number): string {\n if (typeof value === \"boolean\") throw malformed(`--${name} needs a value. Use: ${FORMS}.`);\n\n const text = String(value).trim();\n\n if (text === \"\") throw malformed(`--${name} needs a value. Use: ${FORMS}.`);\n\n return text;\n}\n\n/** `GET /api/products` → `{ method: \"GET\", path: \"/api/products\" }`. */\nexport function parseRouteText(text: string): { method: string; path: string } {\n const match = ROUTE.exec(text);\n\n if (!match || match[1] === undefined || match[2] === undefined) {\n throw malformed(\n `route ${JSON.stringify(text)} is not \"<METHOD> <path>\"; pass it like \"GET /api/products\".`,\n );\n }\n\n return { method: match[1].toUpperCase(), path: match[2] };\n}\n\n/** `catalog/new-arrivals` → `{ feature, flow }`. */\nexport function parseFlowText(text: string): { feature: string; flow: string } {\n const [feature, flow, ...rest] = text.trim().split(\"/\");\n\n if (\n feature === undefined ||\n flow === undefined ||\n rest.length > 0 ||\n !ID.test(feature) ||\n !ID.test(flow)\n ) {\n throw malformed(\n `flow ${JSON.stringify(text)} is not \"<feature>/<flow>\"; pass it like \"catalog/new-arrivals\".`,\n );\n }\n\n return { feature, flow };\n}\n\n/** A feature id, checked. */\nexport function parseFeatureText(text: string): string {\n const feature = text.trim();\n\n if (!ID.test(feature)) {\n throw malformed(\n `feature ${JSON.stringify(text)} is not a feature id; use the folder name under grimoire/features/.`,\n );\n }\n\n return feature;\n}\n\n/** A positive whole number of hits, or an error. */\nexport function parseLimit(value: string | boolean | number): number {\n const limit = typeof value === \"number\" ? value : Number(String(value).trim());\n\n if (typeof value === \"boolean\" || !Number.isInteger(limit) || limit < 1) {\n throw malformed(`--limit must be a whole number above 0, got ${JSON.stringify(value)}.`);\n }\n\n return limit;\n}\n\n/** An app id for `--app`, checked to have a value. */\nexport function parseApp(value: string | boolean | number): string {\n return textOf(\"app\", value);\n}\n\n/**\n * The query of `warlock scry` arguments: a positional file, or one of the\n * options `impact`, `route`, `feature`, `flow`, `search` (with `limit` and `app`).\n * Throws `GrimoireError` `GR9006` for none, several, or a malformed value.\n */\nexport function parseScryQuery(\n args: readonly string[],\n options: Readonly<Record<string, string | boolean | number>>,\n): ScryQuery {\n const given = QUERY_OPTIONS.filter(\n (name) => options[name] !== undefined && options[name] !== false,\n );\n const files = args.filter((arg) => arg.trim() !== \"\");\n\n if (given.length + (files.length > 0 ? 1 : 0) === 0)\n throw malformed(`Nothing to look up. Use: ${FORMS}.`);\n\n if (files.length > 1 || given.length + (files.length > 0 ? 1 : 0) > 1) {\n const asked = [...(files.length > 0 ? [\"<file>\"] : []), ...given.map((name) => `--${name}`)];\n\n throw malformed(`Ask one question at a time; got ${asked.join(\", \")}. Use: ${FORMS}.`);\n }\n\n if (files[0] !== undefined) return { type: \"file\", file: files[0].trim() };\n\n const name = given[0];\n const value = name === undefined ? undefined : options[name];\n\n if (name === undefined || value === undefined)\n throw malformed(`Nothing to look up. Use: ${FORMS}.`);\n\n const text = textOf(name, value);\n\n switch (name) {\n case \"impact\":\n return { type: \"impact\", file: text };\n case \"route\":\n return {\n type: \"route\",\n ...parseRouteText(text),\n ...(options.site === undefined ? {} : { site: textOf(\"site\", options.site) }),\n };\n case \"feature\":\n return { type: \"feature\", feature: parseFeatureText(text) };\n case \"flow\":\n return { type: \"flow\", ...parseFlowText(text) };\n case \"search\": {\n const { limit, app } = options;\n\n return {\n type: \"search\",\n text,\n ...(limit === undefined ? {} : { limit: parseLimit(limit) }),\n ...(app === undefined ? {} : { app: parseApp(app) }),\n };\n }\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,KAAK;AACX,MAAM,QAAQ;AACd,MAAM,gBAAgB;CAAC;CAAU;CAAS;CAAW;CAAQ;AAAQ;AACrE,MAAM,QACJ;AAEF,SAAS,UAAU,SAAgC;CACjD,OAAO,IAAI,cAAc,UAAU,OAAO;AAC5C;;AAGA,SAAS,OAAO,MAAc,OAA0C;CACtE,IAAI,OAAO,UAAU,WAAW,MAAM,UAAU,KAAK,KAAK,uBAAuB,MAAM,EAAE;CAEzF,MAAM,OAAO,OAAO,KAAK,CAAC,CAAC,KAAK;CAEhC,IAAI,SAAS,IAAI,MAAM,UAAU,KAAK,KAAK,uBAAuB,MAAM,EAAE;CAE1E,OAAO;AACT;;AAGA,SAAgB,eAAe,MAAgD;CAC7E,MAAM,QAAQ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":"query.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/query.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"query.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/query.ts"],"mappings":";;;;;;;;wBAqnBgB,KAAK,UAAU,kBAAkB,OAAO,YAAY"}
|
package/esm/scry/query.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { normalizeRoutePath, routeMatches } from "../bookmap/steps.mjs";
|
|
|
8
8
|
import "../bookmap/index.mjs";
|
|
9
9
|
import { checkGrimoire } from "../check/check-grimoire.mjs";
|
|
10
10
|
import "../check/index.mjs";
|
|
11
|
+
import { searchSnapshot, wordsOf } from "./search.mjs";
|
|
11
12
|
|
|
12
13
|
//#region ../../packages/grimoire/src/scry/query.ts
|
|
13
14
|
/**
|
|
@@ -15,11 +16,22 @@ import "../check/index.mjs";
|
|
|
15
16
|
*/
|
|
16
17
|
const byText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
17
18
|
const sortedUnique = (items) => [...new Set(items)].sort(byText);
|
|
18
|
-
/**
|
|
19
|
+
/** Route facts with routes but none that names its source file: only the core list was read, not the app's routes files. */
|
|
20
|
+
const INCOMPLETE_ROUTES = "route facts look incomplete; run warlock grimoire build";
|
|
21
|
+
function routeFactsIncomplete(facts) {
|
|
22
|
+
return facts.routes !== null && facts.routes.length > 0 && facts.routes.every((route) => route.sourceFile === null);
|
|
23
|
+
}
|
|
24
|
+
/** Notes every answer carries: whether the stored book is behind the files, and how fresh the route facts are. */
|
|
19
25
|
function notesOf(snapshot, needsRoutes) {
|
|
20
26
|
const notes = [];
|
|
27
|
+
if (snapshot.behind !== void 0) {
|
|
28
|
+
const count = snapshot.behind.changed;
|
|
29
|
+
notes.push(`book is stale (${count} ${count === 1 ? "file" : "files"} changed); run warlock grimoire build`);
|
|
30
|
+
}
|
|
21
31
|
if (snapshot.routes === "stale") notes.push("route facts are stale; run warlock grimoire build");
|
|
22
32
|
if (snapshot.routes === "missing" && needsRoutes) notes.push("route facts were never read; run warlock grimoire build");
|
|
33
|
+
if (snapshot.book.routeNote !== void 0) notes.push(snapshot.book.routeNote);
|
|
34
|
+
if (needsRoutes && routeFactsIncomplete(snapshot.book.facts)) notes.push(INCOMPLETE_ROUTES);
|
|
23
35
|
return {
|
|
24
36
|
routes: snapshot.routes,
|
|
25
37
|
notes
|
|
@@ -205,11 +217,24 @@ function scryRoute(snapshot, query) {
|
|
|
205
217
|
const facts = snapshot.book.facts;
|
|
206
218
|
const method = query.method.toUpperCase();
|
|
207
219
|
const asked = `${method} ${query.path}`;
|
|
208
|
-
|
|
220
|
+
const pageMethod = method === "GET" || method === "HEAD";
|
|
221
|
+
if (facts.routes === null) {
|
|
222
|
+
const pages = pageMethod ? pagesAt(snapshot, query) : [];
|
|
223
|
+
if (pages.length > 0) return pageRouteResult(snapshot, pages);
|
|
224
|
+
throw new GrimoireError("GR9002", `No route facts yet, so ${asked} cannot be looked up. Run warlock grimoire build (it boots the app once to read the routes), then ask again.`);
|
|
225
|
+
}
|
|
209
226
|
const route = facts.routes.find((item) => routeMatches(item, method, query.path));
|
|
210
227
|
if (!route) {
|
|
228
|
+
const pages = pageMethod ? pagesAt(snapshot, query) : [];
|
|
229
|
+
if (pages.length > 0) return pageRouteResult(snapshot, pages);
|
|
211
230
|
const samePath = facts.routes.filter((item) => normalizeRoutePath(item.path) === normalizeRoutePath(query.path)).map((item) => `${item.method} ${item.path}`);
|
|
212
|
-
|
|
231
|
+
if (routeFactsIncomplete(facts)) throw new GrimoireError("GR9002", `No route matches ${asked}; ${INCOMPLETE_ROUTES}.`);
|
|
232
|
+
const pagePaths = pagesAt(snapshot, { path: query.path }).map((page) => `${page.app} ${page.route}`);
|
|
233
|
+
const hint = [
|
|
234
|
+
samePath.length > 0 ? ` Routes on that path: ${samePath.join(", ")}.` : "",
|
|
235
|
+
pagePaths.length > 0 ? ` Pages on that path (GET or HEAD only${query.site === void 0 ? "" : `, none on site ${query.site}`}): ${pagePaths.join(", ")}.` : "",
|
|
236
|
+
samePath.length === 0 && pagePaths.length === 0 ? " Run warlock routes to list them, or warlock grimoire build when the route is new." : ""
|
|
237
|
+
].join("");
|
|
213
238
|
throw new GrimoireError("GR9002", `No route matches ${asked}.${hint}`);
|
|
214
239
|
}
|
|
215
240
|
const graph = fileGraph(facts.files);
|
|
@@ -226,7 +251,52 @@ function scryRoute(snapshot, query) {
|
|
|
226
251
|
route,
|
|
227
252
|
files,
|
|
228
253
|
steps: steps.sort((left, right) => byText(left.flow, right.flow) || left.index - right.index),
|
|
229
|
-
page
|
|
254
|
+
page,
|
|
255
|
+
pages: []
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/** Pages and mobile screens whose URL is the asked path, narrowed to `--site` when given. */
|
|
259
|
+
function pagesAt(snapshot, query) {
|
|
260
|
+
const facts = snapshot.book.facts;
|
|
261
|
+
const graph = fileGraph(facts.files);
|
|
262
|
+
const wanted = normalizeRoutePath(query.path);
|
|
263
|
+
const site = query.site;
|
|
264
|
+
const closure = (files) => importClosure(graph, files.filter((file) => file !== null));
|
|
265
|
+
return [...facts.pages.filter((page) => normalizeRoutePath(page.route) === wanted && (site === void 0 || page.site === site || siteApp(snapshot, page.site) === site)).map((page) => ({
|
|
266
|
+
app: siteApp(snapshot, page.site),
|
|
267
|
+
site: page.site,
|
|
268
|
+
route: page.route,
|
|
269
|
+
file: page.file,
|
|
270
|
+
type: "page",
|
|
271
|
+
setupFile: page.setupFile,
|
|
272
|
+
layouts: page.layouts,
|
|
273
|
+
files: closure([
|
|
274
|
+
page.file,
|
|
275
|
+
page.setupFile,
|
|
276
|
+
...page.layouts
|
|
277
|
+
])
|
|
278
|
+
})), ...facts.mobile.flatMap((app) => site !== void 0 && app.id !== site && mobileApp(snapshot, app.id) !== site ? [] : app.screens.filter((screen) => normalizeRoutePath(screen.route) === wanted).map((screen) => ({
|
|
279
|
+
app: mobileApp(snapshot, app.id),
|
|
280
|
+
site: app.id,
|
|
281
|
+
route: screen.route,
|
|
282
|
+
file: screen.file,
|
|
283
|
+
type: "screen",
|
|
284
|
+
setupFile: null,
|
|
285
|
+
layouts: screen.layouts,
|
|
286
|
+
files: closure([screen.file, ...screen.layouts])
|
|
287
|
+
})))].sort((left, right) => byText(left.app, right.app) || byText(left.file, right.file));
|
|
288
|
+
}
|
|
289
|
+
/** The answer for a URL that only pages or screens serve. */
|
|
290
|
+
function pageRouteResult(snapshot, pages) {
|
|
291
|
+
const first = pages[0];
|
|
292
|
+
return {
|
|
293
|
+
type: "route",
|
|
294
|
+
...notesOf(snapshot, true),
|
|
295
|
+
route: null,
|
|
296
|
+
files: sortedUnique(pages.flatMap((page) => page.files)),
|
|
297
|
+
steps: [],
|
|
298
|
+
page: first === void 0 ? null : snapshot.book.facts.pages.find((item) => item.file === first.file && item.site === first.site) ?? null,
|
|
299
|
+
pages
|
|
230
300
|
};
|
|
231
301
|
}
|
|
232
302
|
function writtenFeature(snapshot, id) {
|
|
@@ -299,276 +369,15 @@ function scryFlow(snapshot, query) {
|
|
|
299
369
|
findings: findingsFor(snapshot, (finding) => finding.subject.flow === flow.ref)
|
|
300
370
|
};
|
|
301
371
|
}
|
|
302
|
-
const TYPE_ORDER = [
|
|
303
|
-
"feature",
|
|
304
|
-
"flow",
|
|
305
|
-
"block",
|
|
306
|
-
"page",
|
|
307
|
-
"screen",
|
|
308
|
-
"route",
|
|
309
|
-
"mail",
|
|
310
|
-
"job",
|
|
311
|
-
"file",
|
|
312
|
-
"export",
|
|
313
|
-
"task"
|
|
314
|
-
];
|
|
315
|
-
/** Lower-case words: `catalog/new-arrivals.service.ts` → `catalog new arrivals service ts`. */
|
|
316
|
-
function words(text) {
|
|
317
|
-
return text.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
318
|
-
}
|
|
319
|
-
/** The last segment of an id (`catalog/new-arrivals` → `new-arrivals`). */
|
|
320
|
-
function lastSegment(id) {
|
|
321
|
-
const parts = id.split(/[\s/#]+/).filter((part) => part !== "");
|
|
322
|
-
return parts[parts.length - 1] ?? id;
|
|
323
|
-
}
|
|
324
|
-
/** The slug of a block name (`New arrivals` → `new-arrivals`). */
|
|
325
|
-
function slug(text) {
|
|
326
|
-
return words(text).split(" ").join("-");
|
|
327
|
-
}
|
|
328
|
-
/** The searchable written text of a flow: summary, who, story, cases, criteria. */
|
|
329
|
-
function flowBody(flow) {
|
|
330
|
-
return [
|
|
331
|
-
...flow.summary === null ? [] : [{
|
|
332
|
-
label: "summary",
|
|
333
|
-
text: flow.summary
|
|
334
|
-
}],
|
|
335
|
-
{
|
|
336
|
-
label: "who",
|
|
337
|
-
text: flow.who.value
|
|
338
|
-
},
|
|
339
|
-
...flow.story.map((step) => ({
|
|
340
|
-
label: `story ${step.index}`,
|
|
341
|
-
text: step.text
|
|
342
|
-
})),
|
|
343
|
-
...flow.cases.map((item) => ({
|
|
344
|
-
label: `case ${item.question}`,
|
|
345
|
-
text: `${item.question} ${item.answer} ${item.criteria.join(" ")}`
|
|
346
|
-
})),
|
|
347
|
-
...flow.criteria.map((item) => ({
|
|
348
|
-
label: item.id,
|
|
349
|
-
text: `${item.id} ${item.text}`
|
|
350
|
-
}))
|
|
351
|
-
];
|
|
352
|
-
}
|
|
353
|
-
/** The searchable written text of a feature: summary, why, audience. */
|
|
354
|
-
function featureBody(feature) {
|
|
355
|
-
const readme = feature.readme;
|
|
356
|
-
if (readme === null) return [];
|
|
357
|
-
return [
|
|
358
|
-
...readme.summary === null ? [] : [{
|
|
359
|
-
label: "summary",
|
|
360
|
-
text: readme.summary
|
|
361
|
-
}],
|
|
362
|
-
...readme.why === null ? [] : [{
|
|
363
|
-
label: "why",
|
|
364
|
-
text: readme.why
|
|
365
|
-
}],
|
|
366
|
-
...readme.audience.map((item) => ({
|
|
367
|
-
label: "audience",
|
|
368
|
-
text: item.value
|
|
369
|
-
}))
|
|
370
|
-
];
|
|
371
|
-
}
|
|
372
|
-
function candidates(snapshot) {
|
|
373
|
-
const facts = snapshot.book.facts;
|
|
374
|
-
const list = [];
|
|
375
|
-
for (const feature of snapshot.written.features) {
|
|
376
|
-
list.push({
|
|
377
|
-
type: "feature",
|
|
378
|
-
id: feature.id,
|
|
379
|
-
detail: feature.readme?.title.value ?? null,
|
|
380
|
-
body: featureBody(feature)
|
|
381
|
-
});
|
|
382
|
-
for (const flow of feature.flows) list.push({
|
|
383
|
-
type: "flow",
|
|
384
|
-
id: flow.ref,
|
|
385
|
-
detail: flow.heading?.value ?? null,
|
|
386
|
-
body: flowBody(flow)
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
for (const app of snapshot.written.apps) {
|
|
390
|
-
const appId = app.id.value;
|
|
391
|
-
for (const layout of app.layouts) for (const row of layout.blocks) list.push({
|
|
392
|
-
type: "block",
|
|
393
|
-
id: `${appId}/${layout.id}/${slug(row.block)}`,
|
|
394
|
-
detail: row.flow ?? row.block
|
|
395
|
-
});
|
|
396
|
-
for (const page of [...app.pages, ...app.screens]) for (const row of page.blocks) list.push({
|
|
397
|
-
type: "block",
|
|
398
|
-
id: `${appId}/${page.id}/${slug(row.block)}`,
|
|
399
|
-
detail: row.flow ?? row.block
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
for (const page of facts.pages) list.push({
|
|
403
|
-
type: "page",
|
|
404
|
-
id: `${siteApp(snapshot, page.site)} ${page.route}`,
|
|
405
|
-
detail: page.file
|
|
406
|
-
});
|
|
407
|
-
for (const app of facts.mobile) for (const screen of app.screens) list.push({
|
|
408
|
-
type: "screen",
|
|
409
|
-
id: `${mobileApp(snapshot, app.id)} ${screen.route}`,
|
|
410
|
-
detail: screen.file
|
|
411
|
-
});
|
|
412
|
-
for (const route of facts.routes ?? []) {
|
|
413
|
-
if (route.isPage) continue;
|
|
414
|
-
list.push({
|
|
415
|
-
type: "route",
|
|
416
|
-
id: `${route.method} ${route.path}`,
|
|
417
|
-
detail: route.name
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
for (const thing of facts.named) {
|
|
421
|
-
if (thing.type !== "mail" && thing.type !== "job") continue;
|
|
422
|
-
list.push({
|
|
423
|
-
type: thing.type,
|
|
424
|
-
id: thing.name,
|
|
425
|
-
detail: thing.file
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
for (const file of facts.files) {
|
|
429
|
-
list.push({
|
|
430
|
-
type: "file",
|
|
431
|
-
id: file.file,
|
|
432
|
-
detail: file.about
|
|
433
|
-
});
|
|
434
|
-
for (const entry of file.exports) {
|
|
435
|
-
if (entry.name === "default" || entry.name === "*") continue;
|
|
436
|
-
list.push({
|
|
437
|
-
type: "export",
|
|
438
|
-
id: `${file.file}#${entry.name}`,
|
|
439
|
-
detail: entry.about
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
for (const task of [...snapshot.collected.tasksIndex.open, ...snapshot.collected.tasksIndex.done]) list.push({
|
|
444
|
-
type: "task",
|
|
445
|
-
id: task.id,
|
|
446
|
-
detail: task.title
|
|
447
|
-
});
|
|
448
|
-
return list;
|
|
449
|
-
}
|
|
450
|
-
/** Whether every character of `needle` appears in `text` in order. */
|
|
451
|
-
function isSubsequence(needle, text) {
|
|
452
|
-
let position = 0;
|
|
453
|
-
for (const char of text) {
|
|
454
|
-
if (char === needle[position]) position++;
|
|
455
|
-
if (position === needle.length) return true;
|
|
456
|
-
}
|
|
457
|
-
return needle.length === 0;
|
|
458
|
-
}
|
|
459
|
-
/** Shortest query that may match by fuzzy (in-order letters), so short queries stay precise. */
|
|
460
|
-
const FUZZY_MIN = 4;
|
|
461
|
-
/** Added to the score of written content (features, flows) so it ranks above files and exports of the same match. */
|
|
462
|
-
const WRITTEN_BOOST = 2;
|
|
463
|
-
/** Whether a word list holds a word that is, or starts with, every token (a short token must equal a word). */
|
|
464
|
-
function partMatches(partWords, tokens) {
|
|
465
|
-
return tokens.every((token) => partWords.some((word) => token.length >= 3 ? word.startsWith(token) : word === token));
|
|
466
|
-
}
|
|
467
|
-
/** The first body part holding every token, as `label: text`, or `null`. */
|
|
468
|
-
function bodyMatch(candidate, tokens, base) {
|
|
469
|
-
for (const part of candidate.body ?? []) {
|
|
470
|
-
const partWords = words(part.text).split(" ");
|
|
471
|
-
const rest = tokens.filter((token) => !base.includes(token));
|
|
472
|
-
if (rest.length > 0 && partMatches(partWords, rest)) {
|
|
473
|
-
const text = part.text.replace(/\s+/g, " ").trim();
|
|
474
|
-
return `${part.label}: ${text.length > 90 ? `${text.slice(0, 89)}…` : text}`;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
return null;
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Score of a candidate for the query words, or 0 when it does not match. From best
|
|
481
|
-
* to worst: exact name or path (7), prefix (6), whole-word match (5), substring of
|
|
482
|
-
* the name or path (4), the words found only in the detail or in written text (3),
|
|
483
|
-
* fuzzy (2). Features and flows add {@link WRITTEN_BOOST} to a match.
|
|
484
|
-
*/
|
|
485
|
-
function scoreOf(candidate, query, tokens) {
|
|
486
|
-
const id = words(candidate.type === "export" ? candidate.id.split("#")[1] ?? candidate.id : candidate.id);
|
|
487
|
-
const last = words(lastSegment(candidate.id));
|
|
488
|
-
const base = `${id} ${words(candidate.detail ?? "")}`;
|
|
489
|
-
const boost = candidate.type === "feature" || candidate.type === "flow" ? WRITTEN_BOOST : 0;
|
|
490
|
-
if (!tokens.every((token) => base.includes(token))) {
|
|
491
|
-
const matched = bodyMatch(candidate, tokens, base);
|
|
492
|
-
if (matched !== null) return {
|
|
493
|
-
score: 3 + boost,
|
|
494
|
-
matched
|
|
495
|
-
};
|
|
496
|
-
const squeezed = id.replace(/ /g, "");
|
|
497
|
-
return query.length >= FUZZY_MIN && tokens.every((token) => isSubsequence(token, squeezed)) ? {
|
|
498
|
-
score: 2,
|
|
499
|
-
matched: null
|
|
500
|
-
} : {
|
|
501
|
-
score: 0,
|
|
502
|
-
matched: null
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
if (id === query || last === query) return {
|
|
506
|
-
score: 7 + boost,
|
|
507
|
-
matched: null
|
|
508
|
-
};
|
|
509
|
-
if (id.startsWith(query) || last.startsWith(query)) return {
|
|
510
|
-
score: 6 + boost,
|
|
511
|
-
matched: null
|
|
512
|
-
};
|
|
513
|
-
const idWords = id.split(" ");
|
|
514
|
-
if (tokens.every((token) => idWords.includes(token))) return {
|
|
515
|
-
score: 5 + boost,
|
|
516
|
-
matched: null
|
|
517
|
-
};
|
|
518
|
-
if (tokens.every((token) => id.includes(token))) return {
|
|
519
|
-
score: 4 + boost,
|
|
520
|
-
matched: null
|
|
521
|
-
};
|
|
522
|
-
return {
|
|
523
|
-
score: 3 + boost,
|
|
524
|
-
matched: null
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
/** The most hits of features and flows set aside before files and exports fill the list (a share of the limit). */
|
|
528
|
-
const WRITTEN_SHARE = .75;
|
|
529
|
-
const byRank = (left, right) => right.score - left.score || TYPE_ORDER.indexOf(left.type) - TYPE_ORDER.indexOf(right.type) || byText(left.id, right.id);
|
|
530
|
-
/**
|
|
531
|
-
* The hits to return: the best features and flows first (up to a share of the
|
|
532
|
-
* limit, so files and exports never push matching written content out), then
|
|
533
|
-
* the best of the rest. Grouped by type in {@link TYPE_ORDER}, best first.
|
|
534
|
-
*/
|
|
535
|
-
function pickHits(hits, limit) {
|
|
536
|
-
const ranked = [...hits].sort(byRank);
|
|
537
|
-
const written = ranked.filter((hit) => hit.type === "feature" || hit.type === "flow").slice(0, Math.max(1, Math.ceil(limit * WRITTEN_SHARE)));
|
|
538
|
-
const chosen = new Set(written);
|
|
539
|
-
for (const hit of ranked) {
|
|
540
|
-
if (chosen.size >= limit) break;
|
|
541
|
-
chosen.add(hit);
|
|
542
|
-
}
|
|
543
|
-
return [...chosen].slice(0, limit).sort((left, right) => TYPE_ORDER.indexOf(left.type) - TYPE_ORDER.indexOf(right.type) || right.score - left.score || byText(left.id, right.id));
|
|
544
|
-
}
|
|
545
372
|
function scrySearch(snapshot, query) {
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
if (tokens.length === 0) throw new GrimoireError("GR9006", `Search text ${JSON.stringify(query.text)} has no letters or digits; pass a word to look for.`);
|
|
549
|
-
const seen = /* @__PURE__ */ new Set();
|
|
550
|
-
const hits = [];
|
|
551
|
-
for (const candidate of candidates(snapshot)) {
|
|
552
|
-
const key = `${candidate.type} ${candidate.id}`;
|
|
553
|
-
if (seen.has(key)) continue;
|
|
554
|
-
seen.add(key);
|
|
555
|
-
const { score, matched } = scoreOf(candidate, text, tokens);
|
|
556
|
-
if (score > 0) hits.push({
|
|
557
|
-
type: candidate.type,
|
|
558
|
-
id: candidate.id,
|
|
559
|
-
detail: candidate.detail,
|
|
560
|
-
score,
|
|
561
|
-
...matched === null ? {} : { matched }
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
const counts = {};
|
|
565
|
-
for (const hit of hits) counts[hit.type] = (counts[hit.type] ?? 0) + 1;
|
|
373
|
+
if (wordsOf(query.text).length === 0) throw new GrimoireError("GR9006", `Search text ${JSON.stringify(query.text)} has no letters or digits; pass a word to look for.`);
|
|
374
|
+
const { counts, hits } = searchSnapshot(snapshot, query);
|
|
566
375
|
return {
|
|
567
376
|
type: "search",
|
|
568
377
|
...notesOf(snapshot, false),
|
|
569
378
|
text: query.text,
|
|
570
379
|
counts,
|
|
571
|
-
hits
|
|
380
|
+
hits
|
|
572
381
|
};
|
|
573
382
|
}
|
|
574
383
|
/**
|