@warlock.js/grimoire 5.62.0 → 5.63.1
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/query.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/query.ts"],"sourcesContent":["/**\n * Answers one scry query from a snapshot. Pure: reads the snapshot only.\n */\nimport { packagesOf } from \"../book\";\nimport { normalizeRoutePath, routeMatches } from \"../bookmap\";\nimport { checkGrimoire } from \"../check\";\nimport { GrimoireError } from \"../codes\";\nimport type { BookFile, BookRoute } from \"../contracts/adapter\";\nimport { BOOK_SCHEMA_VERSION, type BookEntry } from \"../contracts/book\";\nimport type { FeatureBookmap, FlowBookmap } from \"../contracts/bookmap\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryHit,\n ScryHitType,\n ScryImpactResult,\n ScryNotes,\n ScryPageRef,\n ScryQuery,\n ScryResult,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { WrittenFeature, WrittenFlow } from \"../contracts/written\";\nimport { fileGraph, importClosure, importerClosure } from \"../graph\";\nimport { bookEntryPaths, projectPath, toPosixPath } from \"../paths\";\n\nconst byText = (left: string, right: string): number => (left < right ? -1 : left > right ? 1 : 0);\nconst sortedUnique = (items: Iterable<string>): string[] => [...new Set(items)].sort(byText);\n\n/** Notes every answer carries: how fresh the route facts are. */\nfunction notesOf(snapshot: GrimoireSnapshot, needsRoutes: boolean): ScryNotes {\n const notes: string[] = [];\n\n if (snapshot.routes === \"stale\") notes.push(\"route facts are stale; run warlock grimoire build\");\n if (snapshot.routes === \"missing\" && needsRoutes) {\n notes.push(\"route facts were never read; run warlock grimoire build\");\n }\n\n return { routes: snapshot.routes, notes };\n}\n\n/** A project-relative POSIX path for what the caller typed (either separator, absolute or relative). */\nfunction fileOf(snapshot: GrimoireSnapshot, file: string): string {\n return projectPath(snapshot.root, toPosixPath(file.trim()));\n}\n\nfunction bookFile(snapshot: GrimoireSnapshot, file: string): BookFile {\n const found = snapshot.book.facts.files.find((item) => item.file === file);\n\n if (!found) {\n const roots = [\n ...new Set(snapshot.book.facts.files.map((item) => item.file.split(\"/\")[0] ?? \"\")),\n ]\n .filter((root) => root !== \"\")\n .sort(byText);\n\n throw new GrimoireError(\n \"GR9001\",\n `${file} is not in the book. Pass a code file under ${roots.join(\", \") || \"the source roots\"} as a project-relative path; if the file is new, run warlock grimoire build.`,\n );\n }\n\n return found;\n}\n\n/** The written app id that shows a site, or the site id when no written app matches it. */\nfunction siteApp(snapshot: GrimoireSnapshot, site: string): string {\n const match = Object.values(snapshot.apps).find((app) => app.site?.id === site);\n\n return match?.app ?? site;\n}\n\n/** The written app id of a mobile app, or its own id. */\nfunction mobileApp(snapshot: GrimoireSnapshot, mobile: string): string {\n const match = Object.values(snapshot.apps).find((app) => app.mobile?.id === mobile);\n\n return match?.app ?? mobile;\n}\n\n/** The project files a file imports only through type-only imports, sorted. */\nfunction typeOnlyImportsOf(file: BookFile): string[] {\n const value = new Set<string>();\n const typeOnly = new Set<string>();\n\n for (const entry of file.imports) {\n if (entry.file === null) continue;\n\n (entry.typeOnly === true ? typeOnly : value).add(entry.file);\n }\n\n return sortedUnique([...typeOnly].filter((target) => !value.has(target)));\n}\n\n/** The book entry of one file, as the book writes it. */\nfunction entryOf(snapshot: GrimoireSnapshot, file: BookFile): BookEntry {\n const facts = snapshot.book.facts;\n const annotation = snapshot.annotations.files[file.file];\n const routeRef = (route: BookRoute) => ({\n method: route.method,\n path: route.path,\n name: route.name,\n });\n const routes = facts.routes ?? [];\n\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n file: file.file,\n module: file.module,\n type: file.type,\n lines: file.lines,\n about: file.about,\n feature: annotation?.feature ?? null,\n borrowedBy: sortedUnique(annotation?.borrowedBy ?? []),\n flows: sortedUnique(annotation?.flows ?? []),\n exports: file.exports.map((entry) => ({ name: entry.name, about: entry.about })),\n // The same list the book entry holds (bare Node builtins such as `fs` left out too).\n packages: packagesOf(file),\n imports: sortedUnique(\n file.imports.flatMap((entry) => (entry.file === null ? [] : [entry.file])),\n ),\n // The same rule as the book entry: project files whose every import edge is type-only.\n typeOnlyImports: typeOnlyImportsOf(file),\n importedBy: sortedUnique(file.importedBy),\n routes: [\n ...routes\n .filter((route) => route.sourceFile === file.file)\n .map((route) => ({ ...routeRef(route), via: \"registers\" as const })),\n ...routes\n .filter((route) => route.handlerFile === file.file)\n .map((route) => ({ ...routeRef(route), via: \"handles\" as const })),\n ],\n pages: facts.pages\n .flatMap((page) => [\n ...(page.file === file.file\n ? [{ site: page.site, route: page.route, via: \"page\" as const }]\n : []),\n ...(page.setupFile === file.file\n ? [{ site: page.site, route: page.route, via: \"setup\" as const }]\n : []),\n ...(page.layouts.includes(file.file)\n ? [{ site: page.site, route: page.route, via: \"layout\" as const }]\n : []),\n ])\n .sort(\n (left, right) =>\n byText(left.site, right.site) ||\n byText(left.route, right.route) ||\n byText(left.via, right.via),\n ),\n screens: facts.mobile\n .flatMap((app) =>\n app.screens.flatMap((screen) => [\n ...(screen.file === file.file\n ? [{ app: app.id, route: screen.route, via: \"screen\" as const }]\n : []),\n ...(screen.layouts.includes(file.file)\n ? [{ app: app.id, route: screen.route, via: \"layout\" as const }]\n : []),\n ]),\n )\n .sort(\n (left, right) =>\n byText(left.app, right.app) ||\n byText(left.route, right.route) ||\n byText(left.via, right.via),\n ),\n };\n}\n\n/** Where the book keeps the entry of `file`, or `null` when it has none. */\nfunction bookEntryOf(snapshot: GrimoireSnapshot, file: string): string | null {\n const facts = snapshot.book.facts;\n const roots = new Map(facts.mobile.map((app) => [app.id, app.root]));\n const paths = bookEntryPaths(\n facts.files.map((item) => {\n const root = item.mobileApp === null ? undefined : roots.get(item.mobileApp);\n\n return {\n file: item.file,\n mobileApp:\n item.mobileApp === null || root === undefined ? null : { id: item.mobileApp, root },\n };\n }),\n );\n const entry = paths.get(file);\n\n return entry === undefined || entry.split(\"/\").includes(\"..\") ? null : entry;\n}\n\nfunction scryFile(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"file\" }>,\n): ScryFileResult {\n const file = bookFile(snapshot, fileOf(snapshot, query.file));\n\n return {\n type: \"file\",\n ...notesOf(snapshot, false),\n entry: entryOf(snapshot, file),\n bookEntry: bookEntryOf(snapshot, file.file),\n };\n}\n\nfunction flowBookmaps(snapshot: GrimoireSnapshot): FlowBookmap[] {\n return Object.values(snapshot.collected.flows).sort((left, right) => byText(left.ref, right.ref));\n}\n\nfunction scryImpact(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"impact\" }>,\n): ScryImpactResult {\n const facts = snapshot.book.facts;\n const target = bookFile(snapshot, fileOf(snapshot, query.file));\n const graph = fileGraph(facts.files);\n const reach = new Set(importerClosure(graph, [target.file]));\n const importers = [...reach].filter((file) => file !== target.file).sort(byText);\n const routes = (facts.routes ?? []).filter(\n (route) =>\n !route.isPage &&\n (route.handlerFile !== null\n ? reach.has(route.handlerFile)\n : route.sourceFile !== null && reach.has(route.sourceFile)),\n );\n const pages: ScryPageRef[] = [\n ...facts.pages\n .filter(\n (page) =>\n reach.has(page.file) ||\n (page.setupFile !== null && reach.has(page.setupFile)) ||\n page.layouts.some((layout) => reach.has(layout)),\n )\n .map((page) => ({\n app: siteApp(snapshot, page.site),\n route: page.route,\n file: page.file,\n type: \"page\" as const,\n })),\n ...facts.mobile.flatMap((app) =>\n app.screens\n .filter(\n (screen) => reach.has(screen.file) || screen.layouts.some((layout) => reach.has(layout)),\n )\n .map((screen) => ({\n app: mobileApp(snapshot, app.id),\n route: screen.route,\n file: screen.file,\n type: \"screen\" as const,\n })),\n ),\n ];\n const flows = flowBookmaps(snapshot)\n .filter((bookmap) =>\n bookmap.steps.some(\n (step) => step.files.includes(target.file) || step.typeOnlyFiles.includes(target.file),\n ),\n )\n .map((bookmap) => bookmap.ref);\n const ownership = snapshot.ownership.files;\n const owner = ownership[target.file]?.owner ?? null;\n // Looked up once per importer: an app with thousands of files stays linear.\n const specFiles = new Set(\n facts.files.filter((item) => item.type === \"spec\").map((item) => item.file),\n );\n const borrowers = sortedUnique([\n ...(ownership[target.file]?.borrowedBy ?? []),\n ...importers.flatMap((file) => {\n const ownerOf = ownership[file]?.owner;\n\n return ownerOf === undefined || ownerOf === null || specFiles.has(file) ? [] : [ownerOf];\n }),\n ]).filter((feature) => feature !== owner);\n const testFiles = new Set(facts.tests);\n const flowSet = new Set(flows);\n const tests = sortedUnique([\n ...importers.filter((file) => testFiles.has(file) || specFiles.has(file)),\n ...snapshot.proofs.filter((proof) => flowSet.has(proof.ref)).map((proof) => proof.at.file),\n ]);\n\n return {\n type: \"impact\",\n ...notesOf(snapshot, true),\n file: target.file,\n importers: { direct: sortedUnique(target.importedBy), all: importers },\n routes: routes.map((route) => ({\n method: route.method,\n path: route.path,\n name: route.name,\n handlerFile: route.handlerFile,\n })),\n pages,\n flows,\n features: [\n ...(owner === null ? [] : [{ id: owner, via: \"owner\" as const }]),\n ...borrowers.map((id) => ({ id, via: \"borrower\" as const })),\n ],\n tests,\n };\n}\n\nfunction scryRoute(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"route\" }>,\n): ScryRouteResult {\n const facts = snapshot.book.facts;\n const method = query.method.toUpperCase();\n const asked = `${method} ${query.path}`;\n\n if (facts.routes === null) {\n throw new GrimoireError(\n \"GR9002\",\n `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.`,\n );\n }\n\n const route = facts.routes.find((item) => routeMatches(item, method, query.path));\n\n if (!route) {\n const samePath = facts.routes\n .filter((item) => normalizeRoutePath(item.path) === normalizeRoutePath(query.path))\n .map((item) => `${item.method} ${item.path}`);\n const hint =\n samePath.length > 0\n ? ` Routes on that path: ${samePath.join(\", \")}.`\n : \" Run warlock routes to list them, or warlock grimoire build when the route is new.\";\n\n throw new GrimoireError(\"GR9002\", `No route matches ${asked}.${hint}`);\n }\n\n const graph = fileGraph(facts.files);\n const start = route.handlerFile ?? route.sourceFile;\n const files = start === null ? [] : importClosure(graph, [start]);\n const steps = snapshot.written.features.flatMap((feature) =>\n feature.flows.flatMap((flow) =>\n flow.steps\n .filter(\n (step) =>\n step.type === \"route\" &&\n step.route !== null &&\n routeMatches(route, step.route.method, step.route.path),\n )\n .map((step) => ({ flow: flow.ref, index: step.index })),\n ),\n );\n const page = route.isPage\n ? (facts.pages.find((item) => item.file === route.handlerFile) ??\n facts.pages.find(\n (item) => normalizeRoutePath(item.route) === normalizeRoutePath(route.path),\n ) ??\n null)\n : null;\n\n return {\n type: \"route\",\n ...notesOf(snapshot, true),\n route,\n files,\n steps: steps.sort((left, right) => byText(left.flow, right.flow) || left.index - right.index),\n page,\n };\n}\n\nfunction writtenFeature(snapshot: GrimoireSnapshot, id: string): WrittenFeature {\n const feature = snapshot.written.features.find((item) => item.id === id);\n\n if (!feature) {\n const known = snapshot.written.features.map((item) => item.id).sort(byText);\n const list =\n known.length > 0\n ? ` Features: ${known.join(\", \")}.`\n : \" The project has no grimoire/features/ folder yet.\";\n\n throw new GrimoireError(\"GR9003\", `No feature has the id ${JSON.stringify(id)}.${list}`);\n }\n\n return feature;\n}\n\nfunction findingsFor(\n snapshot: GrimoireSnapshot,\n match: (finding: GrimoireFinding) => boolean,\n): GrimoireFinding[] {\n return checkGrimoire(snapshot).findings.filter(match);\n}\n\nfunction emptyFeatureBookmap(feature: string): FeatureBookmap {\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n feature,\n own: [],\n borrowed: [],\n routes: [],\n pages: {},\n unreached: [],\n };\n}\n\nfunction scryFeature(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"feature\" }>,\n): ScryFeatureResult {\n const feature = writtenFeature(snapshot, query.feature);\n\n if (feature.readme === null) {\n throw new GrimoireError(\n \"GR9003\",\n `grimoire/features/${feature.id} has no README.md, so the feature cannot be shown. Write the README (see warlock grimoire check), then ask again.`,\n );\n }\n\n const findings = findingsFor(\n snapshot,\n (finding) =>\n finding.subject.feature === feature.id ||\n (finding.subject.flow ?? \"\").startsWith(`${feature.id}/`),\n );\n\n return {\n type: \"feature\",\n ...notesOf(snapshot, false),\n readme: feature.readme,\n flows: [...feature.flows]\n .sort((left, right) => byText(left.id.value, right.id.value))\n .map((flow) => {\n const criteria = snapshot.collected.flows[flow.ref]?.criteria ?? [];\n\n return {\n id: flow.id.value,\n status: flow.status.value,\n since: flow.since.value,\n heading: flow.heading?.value ?? null,\n steps: flow.steps.length,\n cases: flow.cases.length,\n criteria: flow.criteria.length,\n tested: criteria.filter((criterion) => criterion.tests.length > 0).length,\n findings: findings.filter(\n (finding) => !finding.expected && finding.subject.flow === flow.ref,\n ).length,\n };\n }),\n bookmap: snapshot.collected.features[feature.id] ?? emptyFeatureBookmap(feature.id),\n changes: (feature.changelog?.entries ?? []).slice(0, 10),\n tasks: snapshot.collected.tasksIndex.open.filter((task) => task.feature === feature.id),\n findings,\n };\n}\n\nfunction scryFlow(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"flow\" }>,\n): ScryFlowResult {\n const feature = writtenFeature(snapshot, query.feature);\n const flow: WrittenFlow | undefined = feature.flows.find((item) => item.id.value === query.flow);\n\n if (!flow) {\n const known = feature.flows.map((item) => item.id.value).sort(byText);\n const list =\n known.length > 0\n ? ` Flows of ${feature.id}: ${known.join(\", \")}.`\n : ` ${feature.id} has no flows yet.`;\n\n throw new GrimoireError(\"GR9004\", `No flow ${feature.id}/${query.flow}.${list}`);\n }\n\n const bookmap =\n Object.values(snapshot.collected.flows).find(\n (item) => item.feature === feature.id && item.flow === flow.id.value,\n ) ?? snapshot.collected.flows[flow.ref];\n\n if (!bookmap) {\n throw new GrimoireError(\n \"GR9004\",\n `${flow.ref} has no book map yet. Run warlock grimoire build, then ask again.`,\n );\n }\n\n return {\n type: \"flow\",\n ...notesOf(snapshot, true),\n flow,\n bookmap,\n history: (feature.changelog?.entries ?? []).filter((entry) => entry.flow === flow.id.value),\n findings: findingsFor(snapshot, (finding) => finding.subject.flow === flow.ref),\n };\n}\n\n// ── Search ─────────────────────────────────────────────────────────────────\n\nconst TYPE_ORDER: readonly ScryHitType[] = [\n \"feature\",\n \"flow\",\n \"block\",\n \"page\",\n \"screen\",\n \"route\",\n \"mail\",\n \"job\",\n \"file\",\n \"export\",\n \"task\",\n];\n\n/** Lower-case words: `catalog/new-arrivals.service.ts` → `catalog new arrivals service ts`. */\nfunction words(text: string): string {\n return text\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \" \")\n .trim();\n}\n\n/** The last segment of an id (`catalog/new-arrivals` → `new-arrivals`). */\nfunction lastSegment(id: string): string {\n const parts = id.split(/[\\s/#]+/).filter((part) => part !== \"\");\n\n return parts[parts.length - 1] ?? id;\n}\n\n/** The slug of a block name (`New arrivals` → `new-arrivals`). */\nfunction slug(text: string): string {\n return words(text).split(\" \").join(\"-\");\n}\n\n/** One searchable piece of written text of a feature or flow (a summary, a story, a case, a criterion). */\ntype BodyPart = { label: string; text: string };\n\ntype Candidate = Omit<ScryHit, \"score\" | \"matched\"> & { body?: BodyPart[] };\n\n/** The searchable written text of a flow: summary, who, story, cases, criteria. */\nfunction flowBody(flow: WrittenFlow): BodyPart[] {\n return [\n ...(flow.summary === null ? [] : [{ label: \"summary\", text: flow.summary }]),\n { label: \"who\", text: flow.who.value },\n ...flow.story.map((step) => ({ label: `story ${step.index}`, text: step.text })),\n ...flow.cases.map((item) => ({\n label: `case ${item.question}`,\n text: `${item.question} ${item.answer} ${item.criteria.join(\" \")}`,\n })),\n ...flow.criteria.map((item) => ({ label: item.id, text: `${item.id} ${item.text}` })),\n ];\n}\n\n/** The searchable written text of a feature: summary, why, audience. */\nfunction featureBody(feature: WrittenFeature): BodyPart[] {\n const readme = feature.readme;\n\n if (readme === null) return [];\n\n return [\n ...(readme.summary === null ? [] : [{ label: \"summary\", text: readme.summary }]),\n ...(readme.why === null ? [] : [{ label: \"why\", text: readme.why }]),\n ...readme.audience.map((item) => ({ label: \"audience\", text: item.value })),\n ];\n}\n\nfunction candidates(snapshot: GrimoireSnapshot): Candidate[] {\n const facts = snapshot.book.facts;\n const list: Candidate[] = [];\n\n for (const feature of snapshot.written.features) {\n list.push({\n type: \"feature\",\n id: feature.id,\n detail: feature.readme?.title.value ?? null,\n body: featureBody(feature),\n });\n\n for (const flow of feature.flows) {\n list.push({\n type: \"flow\",\n id: flow.ref,\n detail: flow.heading?.value ?? null,\n body: flowBody(flow),\n });\n }\n }\n\n for (const app of snapshot.written.apps) {\n const appId = app.id.value;\n\n for (const layout of app.layouts) {\n for (const row of layout.blocks) {\n list.push({\n type: \"block\",\n id: `${appId}/${layout.id}/${slug(row.block)}`,\n detail: row.flow ?? row.block,\n });\n }\n }\n\n for (const page of [...app.pages, ...app.screens]) {\n for (const row of page.blocks) {\n list.push({\n type: \"block\",\n id: `${appId}/${page.id}/${slug(row.block)}`,\n detail: row.flow ?? row.block,\n });\n }\n }\n }\n\n for (const page of facts.pages) {\n list.push({\n type: \"page\",\n id: `${siteApp(snapshot, page.site)} ${page.route}`,\n detail: page.file,\n });\n }\n\n for (const app of facts.mobile) {\n for (const screen of app.screens) {\n list.push({\n type: \"screen\",\n id: `${mobileApp(snapshot, app.id)} ${screen.route}`,\n detail: screen.file,\n });\n }\n }\n\n for (const route of facts.routes ?? []) {\n if (route.isPage) continue;\n\n list.push({ type: \"route\", id: `${route.method} ${route.path}`, detail: route.name });\n }\n\n for (const thing of facts.named) {\n if (thing.type !== \"mail\" && thing.type !== \"job\") continue;\n\n list.push({ type: thing.type, id: thing.name, detail: thing.file });\n }\n\n for (const file of facts.files) {\n list.push({ type: \"file\", id: file.file, detail: file.about });\n\n for (const entry of file.exports) {\n if (entry.name === \"default\" || entry.name === \"*\") continue;\n\n list.push({ type: \"export\", id: `${file.file}#${entry.name}`, detail: entry.about });\n }\n }\n\n for (const task of [\n ...snapshot.collected.tasksIndex.open,\n ...snapshot.collected.tasksIndex.done,\n ]) {\n list.push({ type: \"task\", id: task.id, detail: task.title });\n }\n\n return list;\n}\n\n/** Whether every character of `needle` appears in `text` in order. */\nfunction isSubsequence(needle: string, text: string): boolean {\n let position = 0;\n\n for (const char of text) {\n if (char === needle[position]) position++;\n\n if (position === needle.length) return true;\n }\n\n return needle.length === 0;\n}\n\n/** Shortest query that may match by fuzzy (in-order letters), so short queries stay precise. */\nconst FUZZY_MIN = 4;\n\n/** Added to the score of written content (features, flows) so it ranks above files and exports of the same match. */\nconst WRITTEN_BOOST = 2;\n\n/** Whether a word list holds a word that is, or starts with, every token (a short token must equal a word). */\nfunction partMatches(partWords: readonly string[], tokens: readonly string[]): boolean {\n return tokens.every((token) =>\n partWords.some((word) => (token.length >= 3 ? word.startsWith(token) : word === token)),\n );\n}\n\n/** The first body part holding every token, as `label: text`, or `null`. */\nfunction bodyMatch(candidate: Candidate, tokens: readonly string[], base: string): string | null {\n for (const part of candidate.body ?? []) {\n const partWords = words(part.text).split(\" \");\n // Tokens may be split between the name and one written part.\n const rest = tokens.filter((token) => !base.includes(token));\n\n if (rest.length > 0 && partMatches(partWords, rest)) {\n const text = part.text.replace(/\\s+/g, \" \").trim();\n\n return `${part.label}: ${text.length > 90 ? `${text.slice(0, 89)}…` : text}`;\n }\n }\n\n return null;\n}\n\n/**\n * Score of a candidate for the query words, or 0 when it does not match. From best\n * to worst: exact name or path (7), prefix (6), whole-word match (5), substring of\n * the name or path (4), the words found only in the detail or in written text (3),\n * fuzzy (2). Features and flows add {@link WRITTEN_BOOST} to a match.\n */\nfunction scoreOf(\n candidate: Candidate,\n query: string,\n tokens: readonly string[],\n): { score: number; matched: string | null } {\n const id = words(\n candidate.type === \"export\" ? (candidate.id.split(\"#\")[1] ?? candidate.id) : candidate.id,\n );\n const last = words(lastSegment(candidate.id));\n const base = `${id} ${words(candidate.detail ?? \"\")}`;\n const boost = candidate.type === \"feature\" || candidate.type === \"flow\" ? WRITTEN_BOOST : 0;\n\n if (!tokens.every((token) => base.includes(token))) {\n const matched = bodyMatch(candidate, tokens, base);\n\n if (matched !== null) return { score: 3 + boost, matched };\n\n const squeezed = id.replace(/ /g, \"\");\n\n return query.length >= FUZZY_MIN && tokens.every((token) => isSubsequence(token, squeezed))\n ? { score: 2, matched: null }\n : { score: 0, matched: null };\n }\n\n if (id === query || last === query) return { score: 7 + boost, matched: null };\n if (id.startsWith(query) || last.startsWith(query)) return { score: 6 + boost, matched: null };\n\n const idWords = id.split(\" \");\n\n if (tokens.every((token) => idWords.includes(token))) return { score: 5 + boost, matched: null };\n if (tokens.every((token) => id.includes(token))) return { score: 4 + boost, matched: null };\n\n return { score: 3 + boost, matched: null };\n}\n\n/** The most hits of features and flows set aside before files and exports fill the list (a share of the limit). */\nconst WRITTEN_SHARE = 0.75;\n\nconst byRank = (left: ScryHit, right: ScryHit): number =>\n right.score - left.score ||\n TYPE_ORDER.indexOf(left.type) - TYPE_ORDER.indexOf(right.type) ||\n byText(left.id, right.id);\n\n/**\n * The hits to return: the best features and flows first (up to a share of the\n * limit, so files and exports never push matching written content out), then\n * the best of the rest. Grouped by type in {@link TYPE_ORDER}, best first.\n */\nfunction pickHits(hits: ScryHit[], limit: number): ScryHit[] {\n const ranked = [...hits].sort(byRank);\n const written = ranked\n .filter((hit) => hit.type === \"feature\" || hit.type === \"flow\")\n .slice(0, Math.max(1, Math.ceil(limit * WRITTEN_SHARE)));\n const chosen = new Set(written);\n\n for (const hit of ranked) {\n if (chosen.size >= limit) break;\n\n chosen.add(hit);\n }\n\n return [...chosen]\n .slice(0, limit)\n .sort(\n (left, right) =>\n TYPE_ORDER.indexOf(left.type) - TYPE_ORDER.indexOf(right.type) ||\n right.score - left.score ||\n byText(left.id, right.id),\n );\n}\n\nfunction scrySearch(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"search\" }>,\n): ScrySearchResult {\n const text = words(query.text);\n const tokens = text.split(\" \").filter((token) => token !== \"\");\n\n if (tokens.length === 0) {\n throw new GrimoireError(\n \"GR9006\",\n `Search text ${JSON.stringify(query.text)} has no letters or digits; pass a word to look for.`,\n );\n }\n\n const seen = new Set<string>();\n const hits: ScryHit[] = [];\n\n for (const candidate of candidates(snapshot)) {\n const key = `${candidate.type} ${candidate.id}`;\n\n if (seen.has(key)) continue;\n\n seen.add(key);\n\n const { score, matched } = scoreOf(candidate, text, tokens);\n\n if (score > 0) {\n hits.push({\n type: candidate.type,\n id: candidate.id,\n detail: candidate.detail,\n score,\n ...(matched === null ? {} : { matched }),\n });\n }\n }\n\n const counts: Partial<Record<ScryHitType, number>> = {};\n\n for (const hit of hits) counts[hit.type] = (counts[hit.type] ?? 0) + 1;\n\n return {\n type: \"search\",\n ...notesOf(snapshot, false),\n text: query.text,\n counts,\n hits: pickHits(hits, query.limit ?? 20),\n };\n}\n\n/**\n * Answer one query. Throws a `GrimoireError`: `GR9001` for a file not in the\n * book, `GR9002` no route, `GR9003` no feature, `GR9004` no flow, `GR9006`\n * a search with no words. Pure.\n */\nexport function scry(snapshot: GrimoireSnapshot, query: ScryQuery): ScryResult {\n switch (query.type) {\n case \"file\":\n return scryFile(snapshot, query);\n case \"impact\":\n return scryImpact(snapshot, query);\n case \"route\":\n return scryRoute(snapshot, query);\n case \"feature\":\n return scryFeature(snapshot, query);\n case \"flow\":\n return scryFlow(snapshot, query);\n case \"search\":\n return scrySearch(snapshot, query);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,MAAM,UAAU,MAAc,UAA2B,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAChG,MAAM,gBAAgB,UAAsC,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,MAAM;;AAG3F,SAAS,QAAQ,UAA4B,aAAiC;CAC5E,MAAM,QAAkB,CAAC;CAEzB,IAAI,SAAS,WAAW,SAAS,MAAM,KAAK,mDAAmD;CAC/F,IAAI,SAAS,WAAW,aAAa,aACnC,MAAM,KAAK,yDAAyD;CAGtE,OAAO;EAAE,QAAQ,SAAS;EAAQ;CAAM;AAC1C;;AAGA,SAAS,OAAO,UAA4B,MAAsB;CAChE,OAAO,YAAY,SAAS,MAAM,YAAY,KAAK,KAAK,CAAC,CAAC;AAC5D;AAEA,SAAS,SAAS,UAA4B,MAAwB;CACpE,MAAM,QAAQ,SAAS,KAAK,MAAM,MAAM,MAAM,SAAS,KAAK,SAAS,IAAI;CAEzE,IAAI,CAAC,OAAO;EACV,MAAM,QAAQ,CACZ,GAAG,IAAI,IAAI,SAAS,KAAK,MAAM,MAAM,KAAK,SAAS,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CACnF,CAAC,CACE,QAAQ,SAAS,SAAS,EAAE,CAAC,CAC7B,KAAK,MAAM;EAEd,MAAM,IAAI,cACR,UACA,GAAG,KAAK,8CAA8C,MAAM,KAAK,IAAI,KAAK,mBAAmB,6EAC/F;CACF;CAEA,OAAO;AACT;;AAGA,SAAS,QAAQ,UAA4B,MAAsB;CAGjE,OAFc,OAAO,OAAO,SAAS,IAAI,CAAC,CAAC,MAAM,QAAQ,IAAI,MAAM,OAAO,IAE/D,CAAC,EAAE,OAAO;AACvB;;AAGA,SAAS,UAAU,UAA4B,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ACjC,KAAK,UACH,OAAO,WAAW,UAAU,KAAK;EACnC,KAAK,SACH,OAAO,UAAU,UAAU,KAAK;EAClC,KAAK,WACH,OAAO,YAAY,UAAU,KAAK;EACpC,KAAK,QACH,OAAO,SAAS,UAAU,KAAK;EACjC,KAAK,UACH,OAAO,WAAW,UAAU,KAAK;CACrC;AACF"}
|
|
1
|
+
{"version":3,"file":"query.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/query.ts"],"sourcesContent":["/**\n * Answers one scry query from a snapshot. Pure: reads the snapshot only.\n */\nimport { packagesOf } from \"../book\";\nimport { normalizeRoutePath, routeMatches } from \"../bookmap\";\nimport { checkGrimoire } from \"../check\";\nimport { GrimoireError } from \"../codes\";\nimport type { BookFile, BookRoute } from \"../contracts/adapter\";\nimport { BOOK_SCHEMA_VERSION, type BookEntry } from \"../contracts/book\";\nimport type { FeatureBookmap, FlowBookmap } from \"../contracts/bookmap\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryImpactResult,\n ScryNotes,\n ScryPageRef,\n ScryQuery,\n ScryResult,\n ScryRoutePage,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { WrittenFeature, WrittenFlow } from \"../contracts/written\";\nimport { fileGraph, importClosure, importerClosure } from \"../graph\";\nimport { bookEntryPaths, projectPath, toPosixPath } from \"../paths\";\nimport { searchSnapshot, wordsOf } from \"./search\";\n\nconst byText = (left: string, right: string): number => (left < right ? -1 : left > right ? 1 : 0);\nconst sortedUnique = (items: Iterable<string>): string[] => [...new Set(items)].sort(byText);\n\n/** Route facts with routes but none that names its source file: only the core list was read, not the app's routes files. */\nconst INCOMPLETE_ROUTES = \"route facts look incomplete; run warlock grimoire build\";\n\nfunction routeFactsIncomplete(facts: GrimoireSnapshot[\"book\"][\"facts\"]): boolean {\n return (\n facts.routes !== null &&\n facts.routes.length > 0 &&\n facts.routes.every((route) => route.sourceFile === null)\n );\n}\n\n/** Notes every answer carries: whether the stored book is behind the files, and how fresh the route facts are. */\nfunction notesOf(snapshot: GrimoireSnapshot, needsRoutes: boolean): ScryNotes {\n const notes: string[] = [];\n\n if (snapshot.behind !== undefined) {\n const count = snapshot.behind.changed;\n\n notes.push(\n `book is stale (${count} ${count === 1 ? \"file\" : \"files\"} changed); run warlock grimoire build`,\n );\n }\n\n if (snapshot.routes === \"stale\") notes.push(\"route facts are stale; run warlock grimoire build\");\n if (snapshot.routes === \"missing\" && needsRoutes) {\n notes.push(\"route facts were never read; run warlock grimoire build\");\n }\n\n if (snapshot.book.routeNote !== undefined) notes.push(snapshot.book.routeNote);\n if (needsRoutes && routeFactsIncomplete(snapshot.book.facts)) notes.push(INCOMPLETE_ROUTES);\n\n return { routes: snapshot.routes, notes };\n}\n\n/** A project-relative POSIX path for what the caller typed (either separator, absolute or relative). */\nfunction fileOf(snapshot: GrimoireSnapshot, file: string): string {\n return projectPath(snapshot.root, toPosixPath(file.trim()));\n}\n\nfunction bookFile(snapshot: GrimoireSnapshot, file: string): BookFile {\n const found = snapshot.book.facts.files.find((item) => item.file === file);\n\n if (!found) {\n const roots = [\n ...new Set(snapshot.book.facts.files.map((item) => item.file.split(\"/\")[0] ?? \"\")),\n ]\n .filter((root) => root !== \"\")\n .sort(byText);\n\n throw new GrimoireError(\n \"GR9001\",\n `${file} is not in the book. Pass a code file under ${roots.join(\", \") || \"the source roots\"} as a project-relative path; if the file is new, run warlock grimoire build.`,\n );\n }\n\n return found;\n}\n\n/** The written app id that shows a site, or the site id when no written app matches it. */\nfunction siteApp(snapshot: GrimoireSnapshot, site: string): string {\n const match = Object.values(snapshot.apps).find((app) => app.site?.id === site);\n\n return match?.app ?? site;\n}\n\n/** The written app id of a mobile app, or its own id. */\nfunction mobileApp(snapshot: GrimoireSnapshot, mobile: string): string {\n const match = Object.values(snapshot.apps).find((app) => app.mobile?.id === mobile);\n\n return match?.app ?? mobile;\n}\n\n/** The project files a file imports only through type-only imports, sorted. */\nfunction typeOnlyImportsOf(file: BookFile): string[] {\n const value = new Set<string>();\n const typeOnly = new Set<string>();\n\n for (const entry of file.imports) {\n if (entry.file === null) continue;\n\n (entry.typeOnly === true ? typeOnly : value).add(entry.file);\n }\n\n return sortedUnique([...typeOnly].filter((target) => !value.has(target)));\n}\n\n/** The book entry of one file, as the book writes it. */\nfunction entryOf(snapshot: GrimoireSnapshot, file: BookFile): BookEntry {\n const facts = snapshot.book.facts;\n const annotation = snapshot.annotations.files[file.file];\n const routeRef = (route: BookRoute) => ({\n method: route.method,\n path: route.path,\n name: route.name,\n });\n const routes = facts.routes ?? [];\n\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n file: file.file,\n module: file.module,\n type: file.type,\n lines: file.lines,\n about: file.about,\n feature: annotation?.feature ?? null,\n borrowedBy: sortedUnique(annotation?.borrowedBy ?? []),\n flows: sortedUnique(annotation?.flows ?? []),\n exports: file.exports.map((entry) => ({ name: entry.name, about: entry.about })),\n // The same list the book entry holds (bare Node builtins such as `fs` left out too).\n packages: packagesOf(file),\n imports: sortedUnique(\n file.imports.flatMap((entry) => (entry.file === null ? [] : [entry.file])),\n ),\n // The same rule as the book entry: project files whose every import edge is type-only.\n typeOnlyImports: typeOnlyImportsOf(file),\n importedBy: sortedUnique(file.importedBy),\n routes: [\n ...routes\n .filter((route) => route.sourceFile === file.file)\n .map((route) => ({ ...routeRef(route), via: \"registers\" as const })),\n ...routes\n .filter((route) => route.handlerFile === file.file)\n .map((route) => ({ ...routeRef(route), via: \"handles\" as const })),\n ],\n pages: facts.pages\n .flatMap((page) => [\n ...(page.file === file.file\n ? [{ site: page.site, route: page.route, via: \"page\" as const }]\n : []),\n ...(page.setupFile === file.file\n ? [{ site: page.site, route: page.route, via: \"setup\" as const }]\n : []),\n ...(page.layouts.includes(file.file)\n ? [{ site: page.site, route: page.route, via: \"layout\" as const }]\n : []),\n ])\n .sort(\n (left, right) =>\n byText(left.site, right.site) ||\n byText(left.route, right.route) ||\n byText(left.via, right.via),\n ),\n screens: facts.mobile\n .flatMap((app) =>\n app.screens.flatMap((screen) => [\n ...(screen.file === file.file\n ? [{ app: app.id, route: screen.route, via: \"screen\" as const }]\n : []),\n ...(screen.layouts.includes(file.file)\n ? [{ app: app.id, route: screen.route, via: \"layout\" as const }]\n : []),\n ]),\n )\n .sort(\n (left, right) =>\n byText(left.app, right.app) ||\n byText(left.route, right.route) ||\n byText(left.via, right.via),\n ),\n };\n}\n\n/** Where the book keeps the entry of `file`, or `null` when it has none. */\nfunction bookEntryOf(snapshot: GrimoireSnapshot, file: string): string | null {\n const facts = snapshot.book.facts;\n const roots = new Map(facts.mobile.map((app) => [app.id, app.root]));\n const paths = bookEntryPaths(\n facts.files.map((item) => {\n const root = item.mobileApp === null ? undefined : roots.get(item.mobileApp);\n\n return {\n file: item.file,\n mobileApp:\n item.mobileApp === null || root === undefined ? null : { id: item.mobileApp, root },\n };\n }),\n );\n const entry = paths.get(file);\n\n return entry === undefined || entry.split(\"/\").includes(\"..\") ? null : entry;\n}\n\nfunction scryFile(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"file\" }>,\n): ScryFileResult {\n const file = bookFile(snapshot, fileOf(snapshot, query.file));\n\n return {\n type: \"file\",\n ...notesOf(snapshot, false),\n entry: entryOf(snapshot, file),\n bookEntry: bookEntryOf(snapshot, file.file),\n };\n}\n\nfunction flowBookmaps(snapshot: GrimoireSnapshot): FlowBookmap[] {\n return Object.values(snapshot.collected.flows).sort((left, right) => byText(left.ref, right.ref));\n}\n\nfunction scryImpact(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"impact\" }>,\n): ScryImpactResult {\n const facts = snapshot.book.facts;\n const target = bookFile(snapshot, fileOf(snapshot, query.file));\n const graph = fileGraph(facts.files);\n const reach = new Set(importerClosure(graph, [target.file]));\n const importers = [...reach].filter((file) => file !== target.file).sort(byText);\n const routes = (facts.routes ?? []).filter(\n (route) =>\n !route.isPage &&\n (route.handlerFile !== null\n ? reach.has(route.handlerFile)\n : route.sourceFile !== null && reach.has(route.sourceFile)),\n );\n const pages: ScryPageRef[] = [\n ...facts.pages\n .filter(\n (page) =>\n reach.has(page.file) ||\n (page.setupFile !== null && reach.has(page.setupFile)) ||\n page.layouts.some((layout) => reach.has(layout)),\n )\n .map((page) => ({\n app: siteApp(snapshot, page.site),\n route: page.route,\n file: page.file,\n type: \"page\" as const,\n })),\n ...facts.mobile.flatMap((app) =>\n app.screens\n .filter(\n (screen) => reach.has(screen.file) || screen.layouts.some((layout) => reach.has(layout)),\n )\n .map((screen) => ({\n app: mobileApp(snapshot, app.id),\n route: screen.route,\n file: screen.file,\n type: \"screen\" as const,\n })),\n ),\n ];\n const flows = flowBookmaps(snapshot)\n .filter((bookmap) =>\n bookmap.steps.some(\n (step) => step.files.includes(target.file) || step.typeOnlyFiles.includes(target.file),\n ),\n )\n .map((bookmap) => bookmap.ref);\n const ownership = snapshot.ownership.files;\n const owner = ownership[target.file]?.owner ?? null;\n // Looked up once per importer: an app with thousands of files stays linear.\n const specFiles = new Set(\n facts.files.filter((item) => item.type === \"spec\").map((item) => item.file),\n );\n const borrowers = sortedUnique([\n ...(ownership[target.file]?.borrowedBy ?? []),\n ...importers.flatMap((file) => {\n const ownerOf = ownership[file]?.owner;\n\n return ownerOf === undefined || ownerOf === null || specFiles.has(file) ? [] : [ownerOf];\n }),\n ]).filter((feature) => feature !== owner);\n const testFiles = new Set(facts.tests);\n const flowSet = new Set(flows);\n const tests = sortedUnique([\n ...importers.filter((file) => testFiles.has(file) || specFiles.has(file)),\n ...snapshot.proofs.filter((proof) => flowSet.has(proof.ref)).map((proof) => proof.at.file),\n ]);\n\n return {\n type: \"impact\",\n ...notesOf(snapshot, true),\n file: target.file,\n importers: { direct: sortedUnique(target.importedBy), all: importers },\n routes: routes.map((route) => ({\n method: route.method,\n path: route.path,\n name: route.name,\n handlerFile: route.handlerFile,\n })),\n pages,\n flows,\n features: [\n ...(owner === null ? [] : [{ id: owner, via: \"owner\" as const }]),\n ...borrowers.map((id) => ({ id, via: \"borrower\" as const })),\n ],\n tests,\n };\n}\n\nfunction scryRoute(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"route\" }>,\n): ScryRouteResult {\n const facts = snapshot.book.facts;\n const method = query.method.toUpperCase();\n const asked = `${method} ${query.path}`;\n // Pages and screens come from the code scan, so a page URL is found with or without route facts.\n const pageMethod = method === \"GET\" || method === \"HEAD\";\n\n if (facts.routes === null) {\n const pages = pageMethod ? pagesAt(snapshot, query) : [];\n\n if (pages.length > 0) return pageRouteResult(snapshot, pages);\n\n throw new GrimoireError(\n \"GR9002\",\n `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.`,\n );\n }\n\n const route = facts.routes.find((item) => routeMatches(item, method, query.path));\n\n if (!route) {\n const pages = pageMethod ? pagesAt(snapshot, query) : [];\n\n if (pages.length > 0) return pageRouteResult(snapshot, pages);\n\n const samePath = facts.routes\n .filter((item) => normalizeRoutePath(item.path) === normalizeRoutePath(query.path))\n .map((item) => `${item.method} ${item.path}`);\n\n if (routeFactsIncomplete(facts)) {\n throw new GrimoireError(\"GR9002\", `No route matches ${asked}; ${INCOMPLETE_ROUTES}.`);\n }\n\n const pagePaths = pagesAt(snapshot, { path: query.path }).map(\n (page) => `${page.app} ${page.route}`,\n );\n const hint = [\n samePath.length > 0 ? ` Routes on that path: ${samePath.join(\", \")}.` : \"\",\n pagePaths.length > 0\n ? ` Pages on that path (GET or HEAD only${query.site === undefined ? \"\" : `, none on site ${query.site}`}): ${pagePaths.join(\", \")}.`\n : \"\",\n samePath.length === 0 && pagePaths.length === 0\n ? \" Run warlock routes to list them, or warlock grimoire build when the route is new.\"\n : \"\",\n ].join(\"\");\n\n throw new GrimoireError(\"GR9002\", `No route matches ${asked}.${hint}`);\n }\n\n const graph = fileGraph(facts.files);\n const start = route.handlerFile ?? route.sourceFile;\n const files = start === null ? [] : importClosure(graph, [start]);\n const steps = snapshot.written.features.flatMap((feature) =>\n feature.flows.flatMap((flow) =>\n flow.steps\n .filter(\n (step) =>\n step.type === \"route\" &&\n step.route !== null &&\n routeMatches(route, step.route.method, step.route.path),\n )\n .map((step) => ({ flow: flow.ref, index: step.index })),\n ),\n );\n const page = route.isPage\n ? (facts.pages.find((item) => item.file === route.handlerFile) ??\n facts.pages.find(\n (item) => normalizeRoutePath(item.route) === normalizeRoutePath(route.path),\n ) ??\n null)\n : null;\n\n return {\n type: \"route\",\n ...notesOf(snapshot, true),\n route,\n files,\n steps: steps.sort((left, right) => byText(left.flow, right.flow) || left.index - right.index),\n page,\n pages: [],\n };\n}\n\n/** Pages and mobile screens whose URL is the asked path, narrowed to `--site` when given. */\nfunction pagesAt(\n snapshot: GrimoireSnapshot,\n query: { path: string; site?: string | undefined },\n): ScryRoutePage[] {\n const facts = snapshot.book.facts;\n const graph = fileGraph(facts.files);\n const wanted = normalizeRoutePath(query.path);\n const site = query.site;\n const closure = (files: (string | null)[]): string[] =>\n importClosure(\n graph,\n files.filter((file): file is string => file !== null),\n );\n\n return [\n ...facts.pages\n .filter(\n (page) =>\n normalizeRoutePath(page.route) === wanted &&\n (site === undefined || page.site === site || siteApp(snapshot, page.site) === site),\n )\n .map((page) => ({\n app: siteApp(snapshot, page.site),\n site: page.site,\n route: page.route,\n file: page.file,\n type: \"page\" as const,\n setupFile: page.setupFile,\n layouts: page.layouts,\n files: closure([page.file, page.setupFile, ...page.layouts]),\n })),\n ...facts.mobile.flatMap((app) =>\n site !== undefined && app.id !== site && mobileApp(snapshot, app.id) !== site\n ? []\n : app.screens\n .filter((screen) => normalizeRoutePath(screen.route) === wanted)\n .map((screen) => ({\n app: mobileApp(snapshot, app.id),\n site: app.id,\n route: screen.route,\n file: screen.file,\n type: \"screen\" as const,\n setupFile: null,\n layouts: screen.layouts,\n files: closure([screen.file, ...screen.layouts]),\n })),\n ),\n ].sort((left, right) => byText(left.app, right.app) || byText(left.file, right.file));\n}\n\n/** The answer for a URL that only pages or screens serve. */\nfunction pageRouteResult(snapshot: GrimoireSnapshot, pages: ScryRoutePage[]): ScryRouteResult {\n const first = pages[0];\n\n return {\n type: \"route\",\n ...notesOf(snapshot, true),\n route: null,\n files: sortedUnique(pages.flatMap((page) => page.files)),\n steps: [],\n page:\n first === undefined\n ? null\n : (snapshot.book.facts.pages.find(\n (item) => item.file === first.file && item.site === first.site,\n ) ?? null),\n pages,\n };\n}\n\nfunction writtenFeature(snapshot: GrimoireSnapshot, id: string): WrittenFeature {\n const feature = snapshot.written.features.find((item) => item.id === id);\n\n if (!feature) {\n const known = snapshot.written.features.map((item) => item.id).sort(byText);\n const list =\n known.length > 0\n ? ` Features: ${known.join(\", \")}.`\n : \" The project has no grimoire/features/ folder yet.\";\n\n throw new GrimoireError(\"GR9003\", `No feature has the id ${JSON.stringify(id)}.${list}`);\n }\n\n return feature;\n}\n\nfunction findingsFor(\n snapshot: GrimoireSnapshot,\n match: (finding: GrimoireFinding) => boolean,\n): GrimoireFinding[] {\n return checkGrimoire(snapshot).findings.filter(match);\n}\n\nfunction emptyFeatureBookmap(feature: string): FeatureBookmap {\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n feature,\n own: [],\n borrowed: [],\n routes: [],\n pages: {},\n unreached: [],\n };\n}\n\nfunction scryFeature(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"feature\" }>,\n): ScryFeatureResult {\n const feature = writtenFeature(snapshot, query.feature);\n\n if (feature.readme === null) {\n throw new GrimoireError(\n \"GR9003\",\n `grimoire/features/${feature.id} has no README.md, so the feature cannot be shown. Write the README (see warlock grimoire check), then ask again.`,\n );\n }\n\n const findings = findingsFor(\n snapshot,\n (finding) =>\n finding.subject.feature === feature.id ||\n (finding.subject.flow ?? \"\").startsWith(`${feature.id}/`),\n );\n\n return {\n type: \"feature\",\n ...notesOf(snapshot, false),\n readme: feature.readme,\n flows: [...feature.flows]\n .sort((left, right) => byText(left.id.value, right.id.value))\n .map((flow) => {\n const criteria = snapshot.collected.flows[flow.ref]?.criteria ?? [];\n\n return {\n id: flow.id.value,\n status: flow.status.value,\n since: flow.since.value,\n heading: flow.heading?.value ?? null,\n steps: flow.steps.length,\n cases: flow.cases.length,\n criteria: flow.criteria.length,\n tested: criteria.filter((criterion) => criterion.tests.length > 0).length,\n findings: findings.filter(\n (finding) => !finding.expected && finding.subject.flow === flow.ref,\n ).length,\n };\n }),\n bookmap: snapshot.collected.features[feature.id] ?? emptyFeatureBookmap(feature.id),\n changes: (feature.changelog?.entries ?? []).slice(0, 10),\n tasks: snapshot.collected.tasksIndex.open.filter((task) => task.feature === feature.id),\n findings,\n };\n}\n\nfunction scryFlow(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"flow\" }>,\n): ScryFlowResult {\n const feature = writtenFeature(snapshot, query.feature);\n const flow: WrittenFlow | undefined = feature.flows.find((item) => item.id.value === query.flow);\n\n if (!flow) {\n const known = feature.flows.map((item) => item.id.value).sort(byText);\n const list =\n known.length > 0\n ? ` Flows of ${feature.id}: ${known.join(\", \")}.`\n : ` ${feature.id} has no flows yet.`;\n\n throw new GrimoireError(\"GR9004\", `No flow ${feature.id}/${query.flow}.${list}`);\n }\n\n const bookmap =\n Object.values(snapshot.collected.flows).find(\n (item) => item.feature === feature.id && item.flow === flow.id.value,\n ) ?? snapshot.collected.flows[flow.ref];\n\n if (!bookmap) {\n throw new GrimoireError(\n \"GR9004\",\n `${flow.ref} has no book map yet. Run warlock grimoire build, then ask again.`,\n );\n }\n\n return {\n type: \"flow\",\n ...notesOf(snapshot, true),\n flow,\n bookmap,\n history: (feature.changelog?.entries ?? []).filter((entry) => entry.flow === flow.id.value),\n findings: findingsFor(snapshot, (finding) => finding.subject.flow === flow.ref),\n };\n}\n\n// ── Search ─────────────────────────────────────────────────────────────────\n\nfunction scrySearch(\n snapshot: GrimoireSnapshot,\n query: Extract<ScryQuery, { type: \"search\" }>,\n): ScrySearchResult {\n if (wordsOf(query.text).length === 0) {\n throw new GrimoireError(\n \"GR9006\",\n `Search text ${JSON.stringify(query.text)} has no letters or digits; pass a word to look for.`,\n );\n }\n\n const { counts, hits } = searchSnapshot(snapshot, query);\n\n return { type: \"search\", ...notesOf(snapshot, false), text: query.text, counts, hits };\n}\n\n/**\n * Answer one query. Throws a `GrimoireError`: `GR9001` for a file not in the\n * book, `GR9002` no route, `GR9003` no feature, `GR9004` no flow, `GR9006`\n * a search with no words. Pure.\n */\nexport function scry(snapshot: GrimoireSnapshot, query: ScryQuery): ScryResult {\n switch (query.type) {\n case \"file\":\n return scryFile(snapshot, query);\n case \"impact\":\n return scryImpact(snapshot, query);\n case \"route\":\n return scryRoute(snapshot, query);\n case \"feature\":\n return scryFeature(snapshot, query);\n case \"flow\":\n return scryFlow(snapshot, query);\n case \"search\":\n return scrySearch(snapshot, query);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8BA,MAAM,UAAU,MAAc,UAA2B,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAChG,MAAM,gBAAgB,UAAsC,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,MAAM;;AAG3F,MAAM,oBAAoB;AAE1B,SAAS,qBAAqB,OAAmD;CAC/E,OACE,MAAM,WAAW,QACjB,MAAM,OAAO,SAAS,KACtB,MAAM,OAAO,OAAO,UAAU,MAAM,eAAe,IAAI;AAE3D;;AAGA,SAAS,QAAQ,UAA4B,aAAiC;CAC5E,MAAM,QAAkB,CAAC;CAEzB,IAAI,SAAS,WAAW,QAAW;EACjC,MAAM,QAAQ,SAAS,OAAO;EAE9B,MAAM,KACJ,kBAAkB,MAAM,GAAG,UAAU,IAAI,SAAS,QAAQ,sCAC5D;CACF;CAEA,IAAI,SAAS,WAAW,SAAS,MAAM,KAAK,mDAAmD;CAC/F,IAAI,SAAS,WAAW,aAAa,aACnC,MAAM,KAAK,yDAAyD;CAGtE,IAA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UAAU,KAAK;EACjC,KAAK,UACH,OAAO,WAAW,UAAU,KAAK;CACrC;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region ../../packages/grimoire/src/scry/search.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Words that carry no meaning in a sentence and are left out of the query and the
|
|
4
|
+
* index. The set is extendable: add words before the first search of a process.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SCRY_STOP_WORDS: Set<string>;
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=search.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/search.ts"],"mappings":";;;;;qBAsBa,iBAAiB"}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
//#region ../../packages/grimoire/src/scry/search.ts
|
|
2
|
+
/**
|
|
3
|
+
* Words that carry no meaning in a sentence and are left out of the query and the
|
|
4
|
+
* index. The set is extendable: add words before the first search of a process.
|
|
5
|
+
*/
|
|
6
|
+
const SCRY_STOP_WORDS = new Set("the a an and or of to in on for with at by from is are was be been not no only its it their this that these those into through after before when then than so as has have had do does did can will should would via per if but also each any".split(" "));
|
|
7
|
+
/** BM25 term saturation. */
|
|
8
|
+
const K1 = 1.2;
|
|
9
|
+
/** BM25 length normalisation. */
|
|
10
|
+
const B = .75;
|
|
11
|
+
/** Field weights of the BM25F score. */
|
|
12
|
+
const WEIGHT = {
|
|
13
|
+
id: 3,
|
|
14
|
+
exports: 2,
|
|
15
|
+
about: 1,
|
|
16
|
+
body: 1
|
|
17
|
+
};
|
|
18
|
+
/** Added to the name level of features and flows, so written content ranks above files of the same match. */
|
|
19
|
+
const WRITTEN_BOOST = 2;
|
|
20
|
+
const TYPE_ORDER = [
|
|
21
|
+
"feature",
|
|
22
|
+
"flow",
|
|
23
|
+
"block",
|
|
24
|
+
"page",
|
|
25
|
+
"screen",
|
|
26
|
+
"route",
|
|
27
|
+
"mail",
|
|
28
|
+
"job",
|
|
29
|
+
"file",
|
|
30
|
+
"export",
|
|
31
|
+
"task"
|
|
32
|
+
];
|
|
33
|
+
const byText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
34
|
+
/** An id such as `AC-5` is one word (`ac5`), so it never matches `ac` alone. */
|
|
35
|
+
const ID_PATTERN = /\b([a-z]{1,5})-(\d+)\b/gi;
|
|
36
|
+
/** Lower-case words: `catalog/new-arrivals.service.ts` → `catalog new arrivals service ts`; `AC-5` → `ac5`. */
|
|
37
|
+
function wordsOf(text) {
|
|
38
|
+
return text.replace(ID_PATTERN, "$1$2").replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().replace(/[^a-z0-9]+/g, " ").split(" ").filter((word) => word !== "");
|
|
39
|
+
}
|
|
40
|
+
/** Light stemming: `ies`, `ing`, `ed`, `es` and a plural `s` come off a longer word. */
|
|
41
|
+
function stem(word) {
|
|
42
|
+
if (word.length > 4 && word.endsWith("ies")) return `${word.slice(0, -3)}y`;
|
|
43
|
+
if (word.length > 5 && word.endsWith("ing")) return word.slice(0, -3);
|
|
44
|
+
if (word.length > 4 && word.endsWith("ed")) return word.slice(0, -2);
|
|
45
|
+
if (word.length > 4 && word.endsWith("es")) return word.slice(0, -2);
|
|
46
|
+
if (word.length > 3 && word.endsWith("s") && !word.endsWith("ss")) return word.slice(0, -1);
|
|
47
|
+
return word;
|
|
48
|
+
}
|
|
49
|
+
/** The searchable tokens of a text: whole words without stop words, stemmed. */
|
|
50
|
+
function tokensOf(text) {
|
|
51
|
+
return wordsOf(text).filter((word) => !SCRY_STOP_WORDS.has(word)).map(stem);
|
|
52
|
+
}
|
|
53
|
+
/** The last segment of an id (`catalog/new-arrivals` → `new-arrivals`). */
|
|
54
|
+
function lastSegment(id) {
|
|
55
|
+
const parts = id.split(/[\s/#]+/).filter((part) => part !== "");
|
|
56
|
+
return parts[parts.length - 1] ?? id;
|
|
57
|
+
}
|
|
58
|
+
/** The slug of a block name (`New arrivals` → `new-arrivals`). */
|
|
59
|
+
function slug(text) {
|
|
60
|
+
return wordsOf(text).join("-");
|
|
61
|
+
}
|
|
62
|
+
function flowBody(flow) {
|
|
63
|
+
return [
|
|
64
|
+
...flow.summary === null ? [] : [{
|
|
65
|
+
label: "summary",
|
|
66
|
+
text: flow.summary
|
|
67
|
+
}],
|
|
68
|
+
{
|
|
69
|
+
label: "who",
|
|
70
|
+
text: flow.who.value
|
|
71
|
+
},
|
|
72
|
+
...flow.story.map((step) => ({
|
|
73
|
+
label: `story ${step.index}`,
|
|
74
|
+
text: step.text
|
|
75
|
+
})),
|
|
76
|
+
...flow.cases.map((item) => ({
|
|
77
|
+
label: `case ${item.question}`,
|
|
78
|
+
text: `${item.question} ${item.answer} ${item.criteria.join(" ")}`
|
|
79
|
+
})),
|
|
80
|
+
...flow.criteria.map((item) => ({
|
|
81
|
+
label: item.id,
|
|
82
|
+
text: `${item.id} ${item.text}`
|
|
83
|
+
}))
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
function featureBody(feature) {
|
|
87
|
+
const readme = feature.readme;
|
|
88
|
+
if (readme === null) return [];
|
|
89
|
+
return [
|
|
90
|
+
...readme.summary === null ? [] : [{
|
|
91
|
+
label: "summary",
|
|
92
|
+
text: readme.summary
|
|
93
|
+
}],
|
|
94
|
+
...readme.why === null ? [] : [{
|
|
95
|
+
label: "why",
|
|
96
|
+
text: readme.why
|
|
97
|
+
}],
|
|
98
|
+
...readme.audience.map((item) => ({
|
|
99
|
+
label: "audience",
|
|
100
|
+
text: item.value
|
|
101
|
+
}))
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
/** The written app id of a site, or its own id. */
|
|
105
|
+
function siteApp(snapshot, site) {
|
|
106
|
+
return Object.values(snapshot.apps).find((app) => app.site?.id === site)?.app ?? site;
|
|
107
|
+
}
|
|
108
|
+
/** The written app id of a mobile app, or its own id. */
|
|
109
|
+
function mobileApp(snapshot, mobile) {
|
|
110
|
+
return Object.values(snapshot.apps).find((app) => app.mobile?.id === mobile)?.app ?? mobile;
|
|
111
|
+
}
|
|
112
|
+
/** The app a file belongs to: the mobile app that owns it, else the site or mobile root that holds it. */
|
|
113
|
+
function appOfFile(snapshot, file) {
|
|
114
|
+
if (file.mobileApp !== null) return mobileApp(snapshot, file.mobileApp);
|
|
115
|
+
let best;
|
|
116
|
+
for (const match of Object.values(snapshot.apps)) {
|
|
117
|
+
const root = match.site?.root ?? match.mobile?.root;
|
|
118
|
+
if (root === void 0 || root === "" || root === ".") continue;
|
|
119
|
+
if (file.file !== root && !file.file.startsWith(`${root}/`)) continue;
|
|
120
|
+
if (best === void 0 || root.length > best.length) best = {
|
|
121
|
+
app: match.app,
|
|
122
|
+
length: root.length
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return best?.app;
|
|
126
|
+
}
|
|
127
|
+
function candidates(snapshot) {
|
|
128
|
+
const facts = snapshot.book.facts;
|
|
129
|
+
const list = [];
|
|
130
|
+
const pageFiles = /* @__PURE__ */ new Set([...facts.pages.map((page) => page.file), ...facts.mobile.flatMap((app) => app.screens.map((screen) => screen.file))]);
|
|
131
|
+
const add = (hit, extra = {}) => {
|
|
132
|
+
list.push({
|
|
133
|
+
hit,
|
|
134
|
+
name: extra.name ?? hit.id,
|
|
135
|
+
idText: extra.idText ?? hit.id,
|
|
136
|
+
exportNames: extra.exportNames ?? [],
|
|
137
|
+
about: extra.about ?? hit.detail ?? "",
|
|
138
|
+
body: extra.body ?? [],
|
|
139
|
+
scored: extra.scored ?? true,
|
|
140
|
+
pageFile: extra.pageFile ?? false
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
for (const feature of snapshot.written.features) {
|
|
144
|
+
add({
|
|
145
|
+
type: "feature",
|
|
146
|
+
id: feature.id,
|
|
147
|
+
detail: feature.readme?.title.value ?? null
|
|
148
|
+
}, { body: featureBody(feature) });
|
|
149
|
+
for (const flow of feature.flows) add({
|
|
150
|
+
type: "flow",
|
|
151
|
+
id: flow.ref,
|
|
152
|
+
detail: flow.heading?.value ?? null
|
|
153
|
+
}, { body: flowBody(flow) });
|
|
154
|
+
}
|
|
155
|
+
for (const app of snapshot.written.apps) {
|
|
156
|
+
const appId = app.id.value;
|
|
157
|
+
const rows = [...app.layouts.flatMap((layout) => layout.blocks.map((row) => ({
|
|
158
|
+
page: layout.id,
|
|
159
|
+
row
|
|
160
|
+
}))), ...[...app.pages, ...app.screens].flatMap((page) => page.blocks.map((row) => ({
|
|
161
|
+
page: page.id,
|
|
162
|
+
row
|
|
163
|
+
})))];
|
|
164
|
+
for (const { page, row } of rows) add({
|
|
165
|
+
type: "block",
|
|
166
|
+
id: `${appId}/${page}/${slug(row.block)}`,
|
|
167
|
+
detail: row.flow ?? row.block,
|
|
168
|
+
app: appId
|
|
169
|
+
}, {
|
|
170
|
+
name: `${appId}/${page}`,
|
|
171
|
+
idText: `${appId}/${page}`,
|
|
172
|
+
about: row.block
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
for (const page of facts.pages) {
|
|
176
|
+
const app = siteApp(snapshot, page.site);
|
|
177
|
+
add({
|
|
178
|
+
type: "page",
|
|
179
|
+
id: `${app} ${page.route}`,
|
|
180
|
+
detail: page.file,
|
|
181
|
+
app
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
for (const mobile of facts.mobile) {
|
|
185
|
+
const app = mobileApp(snapshot, mobile.id);
|
|
186
|
+
for (const screen of mobile.screens) add({
|
|
187
|
+
type: "screen",
|
|
188
|
+
id: `${app} ${screen.route}`,
|
|
189
|
+
detail: screen.file,
|
|
190
|
+
app
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
for (const route of facts.routes ?? []) {
|
|
194
|
+
if (route.isPage) continue;
|
|
195
|
+
add({
|
|
196
|
+
type: "route",
|
|
197
|
+
id: `${route.method} ${route.path}`,
|
|
198
|
+
detail: route.name
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
for (const thing of facts.named) {
|
|
202
|
+
if (thing.type !== "mail" && thing.type !== "job") continue;
|
|
203
|
+
add({
|
|
204
|
+
type: thing.type,
|
|
205
|
+
id: thing.name,
|
|
206
|
+
detail: thing.file
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
for (const file of facts.files) {
|
|
210
|
+
const app = appOfFile(snapshot, file);
|
|
211
|
+
add({
|
|
212
|
+
type: "file",
|
|
213
|
+
id: file.file,
|
|
214
|
+
detail: file.about,
|
|
215
|
+
...app === void 0 ? {} : { app }
|
|
216
|
+
}, {
|
|
217
|
+
exportNames: file.exports.filter((entry) => entry.name !== "default" && entry.name !== "*").map((entry) => entry.name),
|
|
218
|
+
pageFile: pageFiles.has(file.file)
|
|
219
|
+
});
|
|
220
|
+
for (const entry of file.exports) {
|
|
221
|
+
if (entry.name === "default" || entry.name === "*") continue;
|
|
222
|
+
add({
|
|
223
|
+
type: "export",
|
|
224
|
+
id: `${file.file}#${entry.name}`,
|
|
225
|
+
detail: entry.about
|
|
226
|
+
}, {
|
|
227
|
+
name: entry.name,
|
|
228
|
+
scored: false
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const task of [...snapshot.collected.tasksIndex.open, ...snapshot.collected.tasksIndex.done]) add({
|
|
233
|
+
type: "task",
|
|
234
|
+
id: task.id,
|
|
235
|
+
detail: task.title
|
|
236
|
+
});
|
|
237
|
+
const seen = /* @__PURE__ */ new Set();
|
|
238
|
+
return list.filter((item) => {
|
|
239
|
+
const key = `${item.hit.type} ${item.hit.id}`;
|
|
240
|
+
if (seen.has(key)) return false;
|
|
241
|
+
seen.add(key);
|
|
242
|
+
return true;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function buildIndex(snapshot) {
|
|
246
|
+
const docs = [];
|
|
247
|
+
const postings = /* @__PURE__ */ new Map();
|
|
248
|
+
let scoredCount = 0;
|
|
249
|
+
let totalLength = 0;
|
|
250
|
+
for (const candidate of candidates(snapshot)) {
|
|
251
|
+
const nameWords = wordsOf(candidate.name);
|
|
252
|
+
const titleWords = wordsOf(candidate.hit.detail ?? "");
|
|
253
|
+
const bodyTokens = candidate.body.map((part) => tokensOf(part.text));
|
|
254
|
+
const doc = {
|
|
255
|
+
candidate,
|
|
256
|
+
nameText: nameWords.join(" "),
|
|
257
|
+
lastText: wordsOf(lastSegment(candidate.name)).join(" "),
|
|
258
|
+
nameWords,
|
|
259
|
+
titleText: titleWords.join(" "),
|
|
260
|
+
titleWords,
|
|
261
|
+
boost: candidate.hit.type === "feature" || candidate.hit.type === "flow" ? WRITTEN_BOOST : 0,
|
|
262
|
+
length: 0,
|
|
263
|
+
bodyTokens
|
|
264
|
+
};
|
|
265
|
+
if (candidate.scored) {
|
|
266
|
+
const frequency = /* @__PURE__ */ new Map();
|
|
267
|
+
const count = (tokens, weight) => {
|
|
268
|
+
for (const token of tokens) {
|
|
269
|
+
frequency.set(token, (frequency.get(token) ?? 0) + weight);
|
|
270
|
+
doc.length += weight;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
count(tokensOf(candidate.idText), WEIGHT.id);
|
|
274
|
+
count(tokensOf(candidate.exportNames.join(" ")), WEIGHT.exports);
|
|
275
|
+
count(tokensOf(candidate.about), WEIGHT.about);
|
|
276
|
+
for (const tokens of bodyTokens) count(tokens, WEIGHT.body);
|
|
277
|
+
for (const [token, weighted] of frequency) {
|
|
278
|
+
const list = postings.get(token) ?? [];
|
|
279
|
+
list.push([docs.length, weighted]);
|
|
280
|
+
postings.set(token, list);
|
|
281
|
+
}
|
|
282
|
+
scoredCount++;
|
|
283
|
+
totalLength += doc.length;
|
|
284
|
+
}
|
|
285
|
+
docs.push(doc);
|
|
286
|
+
}
|
|
287
|
+
const idf = /* @__PURE__ */ new Map();
|
|
288
|
+
for (const [token, list] of postings) idf.set(token, Math.log(1 + (scoredCount - list.length + .5) / (list.length + .5)));
|
|
289
|
+
return {
|
|
290
|
+
docs,
|
|
291
|
+
postings,
|
|
292
|
+
idf,
|
|
293
|
+
average: scoredCount === 0 ? 1 : totalLength / scoredCount
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const indexes = /* @__PURE__ */ new WeakMap();
|
|
297
|
+
function indexOf(snapshot) {
|
|
298
|
+
let index = indexes.get(snapshot);
|
|
299
|
+
if (index === void 0) {
|
|
300
|
+
index = buildIndex(snapshot);
|
|
301
|
+
indexes.set(snapshot, index);
|
|
302
|
+
}
|
|
303
|
+
return index;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* The name level of a candidate for the query, or 0: the whole query is the name
|
|
307
|
+
* or the title (7), starts it (6), every word is a whole word of the name or of the
|
|
308
|
+
* title (5), or the words are spread over both (4).
|
|
309
|
+
*/
|
|
310
|
+
function nameLevel(doc, query, words) {
|
|
311
|
+
if (doc.nameText === query || doc.lastText === query || doc.titleText === query) return 7;
|
|
312
|
+
if (doc.nameText.startsWith(query) || doc.lastText.startsWith(query) || doc.titleText.startsWith(query)) return 6;
|
|
313
|
+
if (words.every((word) => doc.nameWords.includes(word)) || words.every((word) => doc.titleWords.includes(word))) return 5;
|
|
314
|
+
return words.every((word) => doc.nameWords.includes(word) || doc.titleWords.includes(word)) ? 4 : 0;
|
|
315
|
+
}
|
|
316
|
+
/** The written part that holds most of the query tokens, as `label: text`, or `undefined`. */
|
|
317
|
+
function matchedPart(doc, tokens) {
|
|
318
|
+
let best = 0;
|
|
319
|
+
let found;
|
|
320
|
+
doc.bodyTokens.forEach((partTokens, position) => {
|
|
321
|
+
const count = tokens.filter((token) => partTokens.includes(token)).length;
|
|
322
|
+
if (count > best) {
|
|
323
|
+
best = count;
|
|
324
|
+
found = doc.candidate.body[position];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
if (found === void 0) return void 0;
|
|
328
|
+
const text = found.text.replace(/\s+/g, " ").trim();
|
|
329
|
+
return `${found.label}: ${text.length > 90 ? `${text.slice(0, 89)}…` : text}`;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Rank the book for a search query. A query of stop words only matches nothing.
|
|
333
|
+
* Hits are in score order; on an equal score written content comes first, then a
|
|
334
|
+
* page or screen file before helper files, then the type, then the id.
|
|
335
|
+
*/
|
|
336
|
+
function searchSnapshot(snapshot, query) {
|
|
337
|
+
const index = indexOf(snapshot);
|
|
338
|
+
const words = wordsOf(query.text);
|
|
339
|
+
const queryText = words.join(" ");
|
|
340
|
+
const tokens = [...new Set(tokensOf(query.text))];
|
|
341
|
+
const outcome = {
|
|
342
|
+
counts: {},
|
|
343
|
+
hits: []
|
|
344
|
+
};
|
|
345
|
+
if (tokens.length === 0) return outcome;
|
|
346
|
+
const bm25 = /* @__PURE__ */ new Map();
|
|
347
|
+
for (const token of tokens) {
|
|
348
|
+
const list = index.postings.get(token);
|
|
349
|
+
const idf = index.idf.get(token);
|
|
350
|
+
if (list === void 0 || idf === void 0) continue;
|
|
351
|
+
for (const [position, weighted] of list) {
|
|
352
|
+
const length = index.docs[position]?.length ?? 0;
|
|
353
|
+
const part = idf * weighted * 2.2 / (weighted + K1 * (.25 + B * length / index.average));
|
|
354
|
+
bm25.set(position, (bm25.get(position) ?? 0) + part);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const levels = /* @__PURE__ */ new Map();
|
|
358
|
+
index.docs.forEach((doc, position) => {
|
|
359
|
+
const level = nameLevel(doc, queryText, words);
|
|
360
|
+
if (level > 0) levels.set(position, level);
|
|
361
|
+
});
|
|
362
|
+
let highest = 0;
|
|
363
|
+
for (const value of bm25.values()) highest = Math.max(highest, value);
|
|
364
|
+
const offset = highest + 1;
|
|
365
|
+
const matched = /* @__PURE__ */ new Set([...bm25.keys(), ...levels.keys()]);
|
|
366
|
+
const ranked = [];
|
|
367
|
+
for (const position of matched) {
|
|
368
|
+
const doc = index.docs[position];
|
|
369
|
+
if (doc === void 0) continue;
|
|
370
|
+
if (query.app !== void 0 && doc.candidate.hit.app !== query.app) continue;
|
|
371
|
+
const level = levels.get(position);
|
|
372
|
+
const score = bm25.get(position) ?? 0;
|
|
373
|
+
ranked.push(level === void 0 ? {
|
|
374
|
+
doc,
|
|
375
|
+
score,
|
|
376
|
+
named: false
|
|
377
|
+
} : {
|
|
378
|
+
doc,
|
|
379
|
+
score: offset + level + doc.boost + score / offset,
|
|
380
|
+
named: true
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
ranked.sort((left, right) => right.score - left.score || Number(right.doc.boost > 0) - Number(left.doc.boost > 0) || Number(right.doc.candidate.pageFile) - Number(left.doc.candidate.pageFile) || TYPE_ORDER.indexOf(left.doc.candidate.hit.type) - TYPE_ORDER.indexOf(right.doc.candidate.hit.type) || byText(left.doc.candidate.hit.id, right.doc.candidate.hit.id));
|
|
384
|
+
for (const { doc } of ranked) {
|
|
385
|
+
const type = doc.candidate.hit.type;
|
|
386
|
+
outcome.counts[type] = (outcome.counts[type] ?? 0) + 1;
|
|
387
|
+
}
|
|
388
|
+
for (const { doc, score, named } of ranked.slice(0, query.limit ?? 20)) {
|
|
389
|
+
const part = named || doc.boost === 0 ? void 0 : matchedPart(doc, tokens);
|
|
390
|
+
outcome.hits.push({
|
|
391
|
+
...doc.candidate.hit,
|
|
392
|
+
score,
|
|
393
|
+
...part === void 0 ? {} : { matched: part }
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return outcome;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
//#endregion
|
|
400
|
+
export { SCRY_STOP_WORDS, searchSnapshot, wordsOf };
|
|
401
|
+
//# sourceMappingURL=search.mjs.map
|