@warlock.js/grimoire 0.0.0-stage → 5.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +55 -2
- package/esm/apps/check-apps.mjs +207 -0
- package/esm/apps/check-apps.mjs.map +1 -0
- package/esm/apps/index.mjs +4 -0
- package/esm/apps/match-apps.d.mts +12 -0
- package/esm/apps/match-apps.d.mts.map +1 -0
- package/esm/apps/match-apps.mjs +30 -0
- package/esm/apps/match-apps.mjs.map +1 -0
- package/esm/book/build.d.mts +14 -0
- package/esm/book/build.d.mts.map +1 -0
- package/esm/book/build.mjs +300 -0
- package/esm/book/build.mjs.map +1 -0
- package/esm/book/index.mjs +5 -0
- package/esm/book/io.mjs +162 -0
- package/esm/book/io.mjs.map +1 -0
- package/esm/book/normalize.mjs +71 -0
- package/esm/book/normalize.mjs.map +1 -0
- package/esm/book/render.mjs +262 -0
- package/esm/book/render.mjs.map +1 -0
- package/esm/book/write.d.mts +12 -0
- package/esm/book/write.d.mts.map +1 -0
- package/esm/book/write.mjs +90 -0
- package/esm/book/write.mjs.map +1 -0
- package/esm/bookmap/build.d.mts +21 -0
- package/esm/bookmap/build.d.mts.map +1 -0
- package/esm/bookmap/build.mjs +272 -0
- package/esm/bookmap/build.mjs.map +1 -0
- package/esm/bookmap/index.mjs +5 -0
- package/esm/bookmap/steps.mjs +137 -0
- package/esm/bookmap/steps.mjs.map +1 -0
- package/esm/bookmap/write.d.mts +19 -0
- package/esm/bookmap/write.d.mts.map +1 -0
- package/esm/bookmap/write.mjs +118 -0
- package/esm/bookmap/write.mjs.map +1 -0
- package/esm/check/check-grimoire.d.mts +7 -0
- package/esm/check/check-grimoire.d.mts.map +1 -0
- package/esm/check/check-grimoire.mjs +98 -0
- package/esm/check/check-grimoire.mjs.map +1 -0
- package/esm/check/format-check-report.d.mts +20 -0
- package/esm/check/format-check-report.d.mts.map +1 -0
- package/esm/check/format-check-report.mjs +55 -0
- package/esm/check/format-check-report.mjs.map +1 -0
- package/esm/check/index.mjs +4 -0
- package/esm/check/rules/book-notes.mjs +18 -0
- package/esm/check/rules/book-notes.mjs.map +1 -0
- package/esm/check/rules/criteria.mjs +48 -0
- package/esm/check/rules/criteria.mjs.map +1 -0
- package/esm/check/rules/links.mjs +196 -0
- package/esm/check/rules/links.mjs.map +1 -0
- package/esm/check/rules/lookup.mjs +41 -0
- package/esm/check/rules/lookup.mjs.map +1 -0
- package/esm/check/rules/source-files.mjs +119 -0
- package/esm/check/rules/source-files.mjs.map +1 -0
- package/esm/check/rules/versions.mjs +92 -0
- package/esm/check/rules/versions.mjs.map +1 -0
- package/esm/codes/codes.d.mts +182 -0
- package/esm/codes/codes.d.mts.map +1 -0
- package/esm/codes/codes.mjs +111 -0
- package/esm/codes/codes.mjs.map +1 -0
- package/esm/codes/index.d.mts +33 -0
- package/esm/codes/index.d.mts.map +1 -0
- package/esm/codes/index.mjs +63 -0
- package/esm/codes/index.mjs.map +1 -0
- package/esm/contracts/adapter.d.mts +209 -0
- package/esm/contracts/adapter.d.mts.map +1 -0
- package/esm/contracts/book.d.mts +233 -0
- package/esm/contracts/book.d.mts.map +1 -0
- package/esm/contracts/book.mjs +7 -0
- package/esm/contracts/book.mjs.map +1 -0
- package/esm/contracts/bookmap.d.mts +175 -0
- package/esm/contracts/bookmap.d.mts.map +1 -0
- package/esm/contracts/findings.d.mts +79 -0
- package/esm/contracts/findings.d.mts.map +1 -0
- package/esm/contracts/location.d.mts +22 -0
- package/esm/contracts/location.d.mts.map +1 -0
- package/esm/contracts/releases.d.mts +53 -0
- package/esm/contracts/releases.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +143 -0
- package/esm/contracts/scry.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +52 -0
- package/esm/contracts/snapshot.d.mts.map +1 -0
- package/esm/contracts/test-results.d.mts +63 -0
- package/esm/contracts/test-results.d.mts.map +1 -0
- package/esm/contracts/written.d.mts +363 -0
- package/esm/contracts/written.d.mts.map +1 -0
- package/esm/contracts/written.mjs +19 -0
- package/esm/contracts/written.mjs.map +1 -0
- package/esm/devtools/data.mjs +171 -0
- package/esm/devtools/data.mjs.map +1 -0
- package/esm/devtools/graphs.mjs +142 -0
- package/esm/devtools/graphs.mjs.map +1 -0
- package/esm/devtools/index.d.mts +35 -0
- package/esm/devtools/index.d.mts.map +1 -0
- package/esm/devtools/index.mjs +102 -0
- package/esm/devtools/index.mjs.map +1 -0
- package/esm/devtools/site.d.mts +26 -0
- package/esm/devtools/site.d.mts.map +1 -0
- package/esm/devtools/site.mjs +190 -0
- package/esm/devtools/site.mjs.map +1 -0
- package/esm/devtools/snapshot-source.mjs +70 -0
- package/esm/devtools/snapshot-source.mjs.map +1 -0
- package/esm/front-matter/index.d.mts +33 -0
- package/esm/front-matter/index.d.mts.map +1 -0
- package/esm/front-matter/index.mjs +130 -0
- package/esm/front-matter/index.mjs.map +1 -0
- package/esm/graph/index.d.mts +15 -0
- package/esm/graph/index.d.mts.map +1 -0
- package/esm/graph/index.mjs +42 -0
- package/esm/graph/index.mjs.map +1 -0
- package/esm/index.d.mts +33 -0
- package/esm/index.mjs +33 -0
- package/esm/ownership/index.d.mts +8 -0
- package/esm/ownership/index.d.mts.map +1 -0
- package/esm/ownership/index.mjs +137 -0
- package/esm/ownership/index.mjs.map +1 -0
- package/esm/paths/index.d.mts +58 -0
- package/esm/paths/index.d.mts.map +1 -0
- package/esm/paths/index.mjs +137 -0
- package/esm/paths/index.mjs.map +1 -0
- package/esm/proves/index.mjs +3 -0
- package/esm/proves/scan-proofs.d.mts +22 -0
- package/esm/proves/scan-proofs.d.mts.map +1 -0
- package/esm/proves/scan-proofs.mjs +214 -0
- package/esm/proves/scan-proofs.mjs.map +1 -0
- package/esm/releases/index.d.mts +29 -0
- package/esm/releases/index.d.mts.map +1 -0
- package/esm/releases/index.mjs +157 -0
- package/esm/releases/index.mjs.map +1 -0
- package/esm/scry/format.d.mts +14 -0
- package/esm/scry/format.d.mts.map +1 -0
- package/esm/scry/format.mjs +193 -0
- package/esm/scry/format.mjs.map +1 -0
- package/esm/scry/index.mjs +5 -0
- package/esm/scry/parse.d.mts +10 -0
- package/esm/scry/parse.d.mts.map +1 -0
- package/esm/scry/parse.mjs +108 -0
- package/esm/scry/parse.mjs.map +1 -0
- package/esm/scry/query.d.mts +11 -0
- package/esm/scry/query.d.mts.map +1 -0
- package/esm/scry/query.mjs +457 -0
- package/esm/scry/query.mjs.map +1 -0
- package/esm/tasks/index.mjs +116 -0
- package/esm/tasks/index.mjs.map +1 -0
- package/esm/test-results/criterion-status.d.mts +15 -0
- package/esm/test-results/criterion-status.d.mts.map +1 -0
- package/esm/test-results/criterion-status.mjs +17 -0
- package/esm/test-results/criterion-status.mjs.map +1 -0
- package/esm/test-results/index.d.mts +8 -0
- package/esm/test-results/index.d.mts.map +1 -0
- package/esm/test-results/index.mjs +124 -0
- package/esm/test-results/index.mjs.map +1 -0
- package/esm/vitest/index.d.mts +15 -0
- package/esm/vitest/index.d.mts.map +1 -0
- package/esm/vitest/index.mjs +146 -0
- package/esm/vitest/index.mjs.map +1 -0
- package/esm/warlock/actions.mjs +265 -0
- package/esm/warlock/actions.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts +28 -0
- package/esm/warlock/adapter.d.mts.map +1 -0
- package/esm/warlock/adapter.mjs +377 -0
- package/esm/warlock/adapter.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +15 -0
- package/esm/warlock/commands.d.mts.map +1 -0
- package/esm/warlock/commands.mjs +199 -0
- package/esm/warlock/commands.mjs.map +1 -0
- package/esm/warlock/index.d.mts +4 -0
- package/esm/warlock/index.mjs +5 -0
- package/esm/warlock/mcp-tools.mjs +247 -0
- package/esm/warlock/mcp-tools.mjs.map +1 -0
- package/esm/warlock/mobile-facts.d.mts +32 -0
- package/esm/warlock/mobile-facts.d.mts.map +1 -0
- package/esm/warlock/mobile-facts.mjs +185 -0
- package/esm/warlock/mobile-facts.mjs.map +1 -0
- package/esm/workspace/index.d.mts +11 -0
- package/esm/workspace/index.d.mts.map +1 -0
- package/esm/workspace/index.mjs +122 -0
- package/esm/workspace/index.mjs.map +1 -0
- package/esm/written/apps.mjs +227 -0
- package/esm/written/apps.mjs.map +1 -0
- package/esm/written/features.mjs +400 -0
- package/esm/written/features.mjs.map +1 -0
- package/esm/written/fields.mjs +173 -0
- package/esm/written/fields.mjs.map +1 -0
- package/esm/written/index.mjs +3 -0
- package/esm/written/lists.mjs +68 -0
- package/esm/written/lists.mjs.map +1 -0
- package/esm/written/markdown.mjs +173 -0
- package/esm/written/markdown.mjs.map +1 -0
- package/esm/written/parse-grimoire.d.mts +20 -0
- package/esm/written/parse-grimoire.d.mts.map +1 -0
- package/esm/written/parse-grimoire.mjs +552 -0
- package/esm/written/parse-grimoire.mjs.map +1 -0
- package/esm/written/sink.mjs +65 -0
- package/esm/written/sink.mjs.map +1 -0
- package/esm/written/tasks-releases.mjs +166 -0
- package/esm/written/tasks-releases.mjs.map +1 -0
- package/llms-full.txt +869 -0
- package/llms.txt +15 -0
- package/package.json +66 -4
- package/skills/backfill-a-grimoire/SKILL.md +128 -0
- package/skills/describe-an-app/SKILL.md +162 -0
- package/skills/document-a-file/SKILL.md +75 -0
- package/skills/index.md +26 -0
- package/skills/record-a-change/SKILL.md +139 -0
- package/skills/use-the-grimoire/SKILL.md +137 -0
- package/skills/write-a-feature/SKILL.md +168 -0
- package/ui/grimoire-static.js +136 -0
- package/ui/grimoire-view.js +1005 -0
- package/ui/grimoire.css +88 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { BOOK_SCHEMA_VERSION } from "../contracts/book.mjs";
|
|
2
|
+
import { GrimoireError } from "../codes/index.mjs";
|
|
3
|
+
import { bookEntryPaths, projectPath, toPosixPath } from "../paths/index.mjs";
|
|
4
|
+
import { fileGraph, importClosure, importerClosure } from "../graph/index.mjs";
|
|
5
|
+
import { packagesOf } from "../book/render.mjs";
|
|
6
|
+
import "../book/index.mjs";
|
|
7
|
+
import { normalizeRoutePath, routeMatches } from "../bookmap/steps.mjs";
|
|
8
|
+
import "../bookmap/index.mjs";
|
|
9
|
+
import { checkGrimoire } from "../check/check-grimoire.mjs";
|
|
10
|
+
import "../check/index.mjs";
|
|
11
|
+
|
|
12
|
+
//#region ../../packages/grimoire/src/scry/query.ts
|
|
13
|
+
/**
|
|
14
|
+
* Answers one scry query from a snapshot. Pure: reads the snapshot only.
|
|
15
|
+
*/
|
|
16
|
+
const byText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
17
|
+
const sortedUnique = (items) => [...new Set(items)].sort(byText);
|
|
18
|
+
/** Notes every answer carries: how fresh the route facts are. */
|
|
19
|
+
function notesOf(snapshot, needsRoutes) {
|
|
20
|
+
const notes = [];
|
|
21
|
+
if (snapshot.routes === "stale") notes.push("route facts are stale; run warlock grimoire build");
|
|
22
|
+
if (snapshot.routes === "missing" && needsRoutes) notes.push("route facts were never read; run warlock grimoire build");
|
|
23
|
+
return {
|
|
24
|
+
routes: snapshot.routes,
|
|
25
|
+
notes
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** A project-relative POSIX path for what the caller typed (either separator, absolute or relative). */
|
|
29
|
+
function fileOf(snapshot, file) {
|
|
30
|
+
return projectPath(snapshot.root, toPosixPath(file.trim()));
|
|
31
|
+
}
|
|
32
|
+
function bookFile(snapshot, file) {
|
|
33
|
+
const found = snapshot.book.facts.files.find((item) => item.file === file);
|
|
34
|
+
if (!found) {
|
|
35
|
+
const roots = [...new Set(snapshot.book.facts.files.map((item) => item.file.split("/")[0] ?? ""))].filter((root) => root !== "").sort(byText);
|
|
36
|
+
throw new GrimoireError("GR9001", `${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.`);
|
|
37
|
+
}
|
|
38
|
+
return found;
|
|
39
|
+
}
|
|
40
|
+
/** The written app id that shows a site, or the site id when no written app matches it. */
|
|
41
|
+
function siteApp(snapshot, site) {
|
|
42
|
+
return Object.values(snapshot.apps).find((app) => app.site?.id === site)?.app ?? site;
|
|
43
|
+
}
|
|
44
|
+
/** The written app id of a mobile app, or its own id. */
|
|
45
|
+
function mobileApp(snapshot, mobile) {
|
|
46
|
+
return Object.values(snapshot.apps).find((app) => app.mobile?.id === mobile)?.app ?? mobile;
|
|
47
|
+
}
|
|
48
|
+
/** The book entry of one file, as the book writes it. */
|
|
49
|
+
function entryOf(snapshot, file) {
|
|
50
|
+
const facts = snapshot.book.facts;
|
|
51
|
+
const annotation = snapshot.annotations.files[file.file];
|
|
52
|
+
const routeRef = (route) => ({
|
|
53
|
+
method: route.method,
|
|
54
|
+
path: route.path,
|
|
55
|
+
name: route.name
|
|
56
|
+
});
|
|
57
|
+
const routes = facts.routes ?? [];
|
|
58
|
+
return {
|
|
59
|
+
schemaVersion: 1,
|
|
60
|
+
file: file.file,
|
|
61
|
+
module: file.module,
|
|
62
|
+
type: file.type,
|
|
63
|
+
lines: file.lines,
|
|
64
|
+
about: file.about,
|
|
65
|
+
feature: annotation?.feature ?? null,
|
|
66
|
+
borrowedBy: sortedUnique(annotation?.borrowedBy ?? []),
|
|
67
|
+
flows: sortedUnique(annotation?.flows ?? []),
|
|
68
|
+
exports: file.exports.map((entry) => ({
|
|
69
|
+
name: entry.name,
|
|
70
|
+
about: entry.about
|
|
71
|
+
})),
|
|
72
|
+
packages: packagesOf(file),
|
|
73
|
+
imports: sortedUnique(file.imports.flatMap((entry) => entry.file === null ? [] : [entry.file])),
|
|
74
|
+
importedBy: sortedUnique(file.importedBy),
|
|
75
|
+
routes: [...routes.filter((route) => route.sourceFile === file.file).map((route) => ({
|
|
76
|
+
...routeRef(route),
|
|
77
|
+
via: "registers"
|
|
78
|
+
})), ...routes.filter((route) => route.handlerFile === file.file).map((route) => ({
|
|
79
|
+
...routeRef(route),
|
|
80
|
+
via: "handles"
|
|
81
|
+
}))],
|
|
82
|
+
pages: facts.pages.flatMap((page) => [
|
|
83
|
+
...page.file === file.file ? [{
|
|
84
|
+
site: page.site,
|
|
85
|
+
route: page.route,
|
|
86
|
+
via: "page"
|
|
87
|
+
}] : [],
|
|
88
|
+
...page.setupFile === file.file ? [{
|
|
89
|
+
site: page.site,
|
|
90
|
+
route: page.route,
|
|
91
|
+
via: "setup"
|
|
92
|
+
}] : [],
|
|
93
|
+
...page.layouts.includes(file.file) ? [{
|
|
94
|
+
site: page.site,
|
|
95
|
+
route: page.route,
|
|
96
|
+
via: "layout"
|
|
97
|
+
}] : []
|
|
98
|
+
]).sort((left, right) => byText(left.site, right.site) || byText(left.route, right.route) || byText(left.via, right.via)),
|
|
99
|
+
screens: facts.mobile.flatMap((app) => app.screens.flatMap((screen) => [...screen.file === file.file ? [{
|
|
100
|
+
app: app.id,
|
|
101
|
+
route: screen.route,
|
|
102
|
+
via: "screen"
|
|
103
|
+
}] : [], ...screen.layouts.includes(file.file) ? [{
|
|
104
|
+
app: app.id,
|
|
105
|
+
route: screen.route,
|
|
106
|
+
via: "layout"
|
|
107
|
+
}] : []])).sort((left, right) => byText(left.app, right.app) || byText(left.route, right.route) || byText(left.via, right.via))
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Where the book keeps the entry of `file`, or `null` when it has none. */
|
|
111
|
+
function bookEntryOf(snapshot, file) {
|
|
112
|
+
const facts = snapshot.book.facts;
|
|
113
|
+
const roots = new Map(facts.mobile.map((app) => [app.id, app.root]));
|
|
114
|
+
const entry = bookEntryPaths(facts.files.map((item) => {
|
|
115
|
+
const root = item.mobileApp === null ? void 0 : roots.get(item.mobileApp);
|
|
116
|
+
return {
|
|
117
|
+
file: item.file,
|
|
118
|
+
mobileApp: item.mobileApp === null || root === void 0 ? null : {
|
|
119
|
+
id: item.mobileApp,
|
|
120
|
+
root
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
})).get(file);
|
|
124
|
+
return entry === void 0 || entry.split("/").includes("..") ? null : entry;
|
|
125
|
+
}
|
|
126
|
+
function scryFile(snapshot, query) {
|
|
127
|
+
const file = bookFile(snapshot, fileOf(snapshot, query.file));
|
|
128
|
+
return {
|
|
129
|
+
type: "file",
|
|
130
|
+
...notesOf(snapshot, false),
|
|
131
|
+
entry: entryOf(snapshot, file),
|
|
132
|
+
bookEntry: bookEntryOf(snapshot, file.file)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function flowBookmaps(snapshot) {
|
|
136
|
+
return Object.values(snapshot.collected.flows).sort((left, right) => byText(left.ref, right.ref));
|
|
137
|
+
}
|
|
138
|
+
function scryImpact(snapshot, query) {
|
|
139
|
+
const facts = snapshot.book.facts;
|
|
140
|
+
const target = bookFile(snapshot, fileOf(snapshot, query.file));
|
|
141
|
+
const graph = fileGraph(facts.files);
|
|
142
|
+
const reach = new Set(importerClosure(graph, [target.file]));
|
|
143
|
+
const importers = [...reach].filter((file) => file !== target.file).sort(byText);
|
|
144
|
+
const routes = (facts.routes ?? []).filter((route) => !route.isPage && (route.handlerFile !== null ? reach.has(route.handlerFile) : route.sourceFile !== null && reach.has(route.sourceFile)));
|
|
145
|
+
const pages = [...facts.pages.filter((page) => reach.has(page.file) || page.setupFile !== null && reach.has(page.setupFile) || page.layouts.some((layout) => reach.has(layout))).map((page) => ({
|
|
146
|
+
app: siteApp(snapshot, page.site),
|
|
147
|
+
route: page.route,
|
|
148
|
+
file: page.file,
|
|
149
|
+
type: "page"
|
|
150
|
+
})), ...facts.mobile.flatMap((app) => app.screens.filter((screen) => reach.has(screen.file) || screen.layouts.some((layout) => reach.has(layout))).map((screen) => ({
|
|
151
|
+
app: mobileApp(snapshot, app.id),
|
|
152
|
+
route: screen.route,
|
|
153
|
+
file: screen.file,
|
|
154
|
+
type: "screen"
|
|
155
|
+
})))];
|
|
156
|
+
const flows = flowBookmaps(snapshot).filter((bookmap) => bookmap.steps.some((step) => step.files.includes(target.file))).map((bookmap) => bookmap.ref);
|
|
157
|
+
const ownership = snapshot.ownership.files;
|
|
158
|
+
const owner = ownership[target.file]?.owner ?? null;
|
|
159
|
+
const specFiles = new Set(facts.files.filter((item) => item.type === "spec").map((item) => item.file));
|
|
160
|
+
const borrowers = sortedUnique([...ownership[target.file]?.borrowedBy ?? [], ...importers.flatMap((file) => {
|
|
161
|
+
const ownerOf = ownership[file]?.owner;
|
|
162
|
+
return ownerOf === void 0 || ownerOf === null || specFiles.has(file) ? [] : [ownerOf];
|
|
163
|
+
})]).filter((feature) => feature !== owner);
|
|
164
|
+
const testFiles = new Set(facts.tests);
|
|
165
|
+
const flowSet = new Set(flows);
|
|
166
|
+
const tests = sortedUnique([...importers.filter((file) => testFiles.has(file) || specFiles.has(file)), ...snapshot.proofs.filter((proof) => flowSet.has(proof.ref)).map((proof) => proof.at.file)]);
|
|
167
|
+
return {
|
|
168
|
+
type: "impact",
|
|
169
|
+
...notesOf(snapshot, true),
|
|
170
|
+
file: target.file,
|
|
171
|
+
importers: {
|
|
172
|
+
direct: sortedUnique(target.importedBy),
|
|
173
|
+
all: importers
|
|
174
|
+
},
|
|
175
|
+
routes: routes.map((route) => ({
|
|
176
|
+
method: route.method,
|
|
177
|
+
path: route.path,
|
|
178
|
+
name: route.name,
|
|
179
|
+
handlerFile: route.handlerFile
|
|
180
|
+
})),
|
|
181
|
+
pages,
|
|
182
|
+
flows,
|
|
183
|
+
features: [...owner === null ? [] : [{
|
|
184
|
+
id: owner,
|
|
185
|
+
via: "owner"
|
|
186
|
+
}], ...borrowers.map((id) => ({
|
|
187
|
+
id,
|
|
188
|
+
via: "borrower"
|
|
189
|
+
}))],
|
|
190
|
+
tests
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function scryRoute(snapshot, query) {
|
|
194
|
+
const facts = snapshot.book.facts;
|
|
195
|
+
const method = query.method.toUpperCase();
|
|
196
|
+
const asked = `${method} ${query.path}`;
|
|
197
|
+
if (facts.routes === null) 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.`);
|
|
198
|
+
const route = facts.routes.find((item) => routeMatches(item, method, query.path));
|
|
199
|
+
if (!route) {
|
|
200
|
+
const samePath = facts.routes.filter((item) => normalizeRoutePath(item.path) === normalizeRoutePath(query.path)).map((item) => `${item.method} ${item.path}`);
|
|
201
|
+
const hint = samePath.length > 0 ? ` Routes on that path: ${samePath.join(", ")}.` : " Run warlock routes to list them, or warlock grimoire build when the route is new.";
|
|
202
|
+
throw new GrimoireError("GR9002", `No route matches ${asked}.${hint}`);
|
|
203
|
+
}
|
|
204
|
+
const graph = fileGraph(facts.files);
|
|
205
|
+
const start = route.handlerFile ?? route.sourceFile;
|
|
206
|
+
const files = start === null ? [] : importClosure(graph, [start]);
|
|
207
|
+
const steps = snapshot.written.features.flatMap((feature) => feature.flows.flatMap((flow) => flow.steps.filter((step) => step.type === "route" && step.route !== null && routeMatches(route, step.route.method, step.route.path)).map((step) => ({
|
|
208
|
+
flow: flow.ref,
|
|
209
|
+
index: step.index
|
|
210
|
+
}))));
|
|
211
|
+
const page = route.isPage ? facts.pages.find((item) => item.file === route.handlerFile) ?? facts.pages.find((item) => normalizeRoutePath(item.route) === normalizeRoutePath(route.path)) ?? null : null;
|
|
212
|
+
return {
|
|
213
|
+
type: "route",
|
|
214
|
+
...notesOf(snapshot, true),
|
|
215
|
+
route,
|
|
216
|
+
files,
|
|
217
|
+
steps: steps.sort((left, right) => byText(left.flow, right.flow) || left.index - right.index),
|
|
218
|
+
page
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function writtenFeature(snapshot, id) {
|
|
222
|
+
const feature = snapshot.written.features.find((item) => item.id === id);
|
|
223
|
+
if (!feature) {
|
|
224
|
+
const known = snapshot.written.features.map((item) => item.id).sort(byText);
|
|
225
|
+
const list = known.length > 0 ? ` Features: ${known.join(", ")}.` : " The project has no grimoire/features/ folder yet.";
|
|
226
|
+
throw new GrimoireError("GR9003", `No feature has the id ${JSON.stringify(id)}.${list}`);
|
|
227
|
+
}
|
|
228
|
+
return feature;
|
|
229
|
+
}
|
|
230
|
+
function findingsFor(snapshot, match) {
|
|
231
|
+
return checkGrimoire(snapshot).findings.filter(match);
|
|
232
|
+
}
|
|
233
|
+
function emptyFeatureBookmap(feature) {
|
|
234
|
+
return {
|
|
235
|
+
schemaVersion: 1,
|
|
236
|
+
feature,
|
|
237
|
+
own: [],
|
|
238
|
+
borrowed: [],
|
|
239
|
+
routes: [],
|
|
240
|
+
pages: {},
|
|
241
|
+
unreached: []
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function scryFeature(snapshot, query) {
|
|
245
|
+
const feature = writtenFeature(snapshot, query.feature);
|
|
246
|
+
if (feature.readme === null) throw new GrimoireError("GR9003", `grimoire/features/${feature.id} has no README.md, so the feature cannot be shown. Write the README (see warlock grimoire check), then ask again.`);
|
|
247
|
+
return {
|
|
248
|
+
type: "feature",
|
|
249
|
+
...notesOf(snapshot, false),
|
|
250
|
+
readme: feature.readme,
|
|
251
|
+
flows: [...feature.flows].sort((left, right) => byText(left.id.value, right.id.value)).map((flow) => ({
|
|
252
|
+
id: flow.id.value,
|
|
253
|
+
status: flow.status.value,
|
|
254
|
+
since: flow.since.value,
|
|
255
|
+
heading: flow.heading?.value ?? null
|
|
256
|
+
})),
|
|
257
|
+
bookmap: snapshot.collected.features[feature.id] ?? emptyFeatureBookmap(feature.id),
|
|
258
|
+
changes: (feature.changelog?.entries ?? []).slice(0, 10),
|
|
259
|
+
tasks: snapshot.collected.tasksIndex.open.filter((task) => task.feature === feature.id),
|
|
260
|
+
findings: findingsFor(snapshot, (finding) => finding.subject.feature === feature.id || (finding.subject.flow ?? "").startsWith(`${feature.id}/`))
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function scryFlow(snapshot, query) {
|
|
264
|
+
const feature = writtenFeature(snapshot, query.feature);
|
|
265
|
+
const flow = feature.flows.find((item) => item.id.value === query.flow);
|
|
266
|
+
if (!flow) {
|
|
267
|
+
const known = feature.flows.map((item) => item.id.value).sort(byText);
|
|
268
|
+
const list = known.length > 0 ? ` Flows of ${feature.id}: ${known.join(", ")}.` : ` ${feature.id} has no flows yet.`;
|
|
269
|
+
throw new GrimoireError("GR9004", `No flow ${feature.id}/${query.flow}.${list}`);
|
|
270
|
+
}
|
|
271
|
+
const bookmap = Object.values(snapshot.collected.flows).find((item) => item.feature === feature.id && item.flow === flow.id.value) ?? snapshot.collected.flows[flow.ref];
|
|
272
|
+
if (!bookmap) throw new GrimoireError("GR9004", `${flow.ref} has no book map yet. Run warlock grimoire build, then ask again.`);
|
|
273
|
+
return {
|
|
274
|
+
type: "flow",
|
|
275
|
+
...notesOf(snapshot, true),
|
|
276
|
+
flow,
|
|
277
|
+
bookmap,
|
|
278
|
+
history: (feature.changelog?.entries ?? []).filter((entry) => entry.flow === flow.id.value),
|
|
279
|
+
findings: findingsFor(snapshot, (finding) => finding.subject.flow === flow.ref)
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const TYPE_ORDER = [
|
|
283
|
+
"feature",
|
|
284
|
+
"flow",
|
|
285
|
+
"block",
|
|
286
|
+
"page",
|
|
287
|
+
"screen",
|
|
288
|
+
"route",
|
|
289
|
+
"mail",
|
|
290
|
+
"job",
|
|
291
|
+
"file",
|
|
292
|
+
"export",
|
|
293
|
+
"task"
|
|
294
|
+
];
|
|
295
|
+
/** Lower-case words: `catalog/new-arrivals.service.ts` → `catalog new arrivals service ts`. */
|
|
296
|
+
function words(text) {
|
|
297
|
+
return text.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
298
|
+
}
|
|
299
|
+
/** The last segment of an id (`catalog/new-arrivals` → `new-arrivals`). */
|
|
300
|
+
function lastSegment(id) {
|
|
301
|
+
const parts = id.split(/[\s/#]+/).filter((part) => part !== "");
|
|
302
|
+
return parts[parts.length - 1] ?? id;
|
|
303
|
+
}
|
|
304
|
+
/** The slug of a block name (`New arrivals` → `new-arrivals`). */
|
|
305
|
+
function slug(text) {
|
|
306
|
+
return words(text).split(" ").join("-");
|
|
307
|
+
}
|
|
308
|
+
function candidates(snapshot) {
|
|
309
|
+
const facts = snapshot.book.facts;
|
|
310
|
+
const list = [];
|
|
311
|
+
for (const feature of snapshot.written.features) {
|
|
312
|
+
list.push({
|
|
313
|
+
type: "feature",
|
|
314
|
+
id: feature.id,
|
|
315
|
+
detail: feature.readme?.title.value ?? null
|
|
316
|
+
});
|
|
317
|
+
for (const flow of feature.flows) list.push({
|
|
318
|
+
type: "flow",
|
|
319
|
+
id: flow.ref,
|
|
320
|
+
detail: flow.heading?.value ?? null
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
for (const app of snapshot.written.apps) {
|
|
324
|
+
const appId = app.id.value;
|
|
325
|
+
for (const layout of app.layouts) for (const row of layout.blocks) list.push({
|
|
326
|
+
type: "block",
|
|
327
|
+
id: `${appId}/${layout.id}/${slug(row.block)}`,
|
|
328
|
+
detail: row.flow ?? row.block
|
|
329
|
+
});
|
|
330
|
+
for (const page of [...app.pages, ...app.screens]) for (const row of page.blocks) list.push({
|
|
331
|
+
type: "block",
|
|
332
|
+
id: `${appId}/${page.id}/${slug(row.block)}`,
|
|
333
|
+
detail: row.flow ?? row.block
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
for (const page of facts.pages) list.push({
|
|
337
|
+
type: "page",
|
|
338
|
+
id: `${siteApp(snapshot, page.site)} ${page.route}`,
|
|
339
|
+
detail: page.file
|
|
340
|
+
});
|
|
341
|
+
for (const app of facts.mobile) for (const screen of app.screens) list.push({
|
|
342
|
+
type: "screen",
|
|
343
|
+
id: `${mobileApp(snapshot, app.id)} ${screen.route}`,
|
|
344
|
+
detail: screen.file
|
|
345
|
+
});
|
|
346
|
+
for (const route of facts.routes ?? []) {
|
|
347
|
+
if (route.isPage) continue;
|
|
348
|
+
list.push({
|
|
349
|
+
type: "route",
|
|
350
|
+
id: `${route.method} ${route.path}`,
|
|
351
|
+
detail: route.name
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
for (const thing of facts.named) {
|
|
355
|
+
if (thing.type !== "mail" && thing.type !== "job") continue;
|
|
356
|
+
list.push({
|
|
357
|
+
type: thing.type,
|
|
358
|
+
id: thing.name,
|
|
359
|
+
detail: thing.file
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
for (const file of facts.files) {
|
|
363
|
+
list.push({
|
|
364
|
+
type: "file",
|
|
365
|
+
id: file.file,
|
|
366
|
+
detail: file.about
|
|
367
|
+
});
|
|
368
|
+
for (const entry of file.exports) {
|
|
369
|
+
if (entry.name === "default" || entry.name === "*") continue;
|
|
370
|
+
list.push({
|
|
371
|
+
type: "export",
|
|
372
|
+
id: `${file.file}#${entry.name}`,
|
|
373
|
+
detail: entry.about
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
for (const task of [...snapshot.collected.tasksIndex.open, ...snapshot.collected.tasksIndex.done]) list.push({
|
|
378
|
+
type: "task",
|
|
379
|
+
id: task.id,
|
|
380
|
+
detail: task.title
|
|
381
|
+
});
|
|
382
|
+
return list;
|
|
383
|
+
}
|
|
384
|
+
/** Whether every character of `needle` appears in `text` in order. */
|
|
385
|
+
function isSubsequence(needle, text) {
|
|
386
|
+
let position = 0;
|
|
387
|
+
for (const char of text) {
|
|
388
|
+
if (char === needle[position]) position++;
|
|
389
|
+
if (position === needle.length) return true;
|
|
390
|
+
}
|
|
391
|
+
return needle.length === 0;
|
|
392
|
+
}
|
|
393
|
+
/** Shortest query that may match by fuzzy (in-order letters), so short queries stay precise. */
|
|
394
|
+
const FUZZY_MIN = 4;
|
|
395
|
+
/**
|
|
396
|
+
* Score of a candidate for the query words, or 0 when it does not match. From best
|
|
397
|
+
* to worst: exact name or path (7), prefix (6), whole-word match (5), substring of
|
|
398
|
+
* the name or path (4), the words found only in the detail (3), fuzzy (2).
|
|
399
|
+
*/
|
|
400
|
+
function scoreOf(candidate, query, tokens) {
|
|
401
|
+
const id = words(candidate.type === "export" ? candidate.id.split("#")[1] ?? candidate.id : candidate.id);
|
|
402
|
+
const last = words(lastSegment(candidate.id));
|
|
403
|
+
const all = `${id} ${words(candidate.detail ?? "")}`;
|
|
404
|
+
if (!tokens.every((token) => all.includes(token))) {
|
|
405
|
+
const squeezed = id.replace(/ /g, "");
|
|
406
|
+
return query.length >= FUZZY_MIN && tokens.every((token) => isSubsequence(token, squeezed)) ? 2 : 0;
|
|
407
|
+
}
|
|
408
|
+
if (id === query || last === query) return 7;
|
|
409
|
+
if (id.startsWith(query) || last.startsWith(query)) return 6;
|
|
410
|
+
const idWords = id.split(" ");
|
|
411
|
+
if (tokens.every((token) => idWords.includes(token))) return 5;
|
|
412
|
+
if (tokens.every((token) => id.includes(token))) return 4;
|
|
413
|
+
return 3;
|
|
414
|
+
}
|
|
415
|
+
function scrySearch(snapshot, query) {
|
|
416
|
+
const text = words(query.text);
|
|
417
|
+
const tokens = text.split(" ").filter((token) => token !== "");
|
|
418
|
+
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.`);
|
|
419
|
+
const seen = /* @__PURE__ */ new Set();
|
|
420
|
+
const hits = [];
|
|
421
|
+
for (const candidate of candidates(snapshot)) {
|
|
422
|
+
const key = `${candidate.type} ${candidate.id}`;
|
|
423
|
+
if (seen.has(key)) continue;
|
|
424
|
+
seen.add(key);
|
|
425
|
+
const score = scoreOf(candidate, text, tokens);
|
|
426
|
+
if (score > 0) hits.push({
|
|
427
|
+
...candidate,
|
|
428
|
+
score
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
hits.sort((left, right) => right.score - left.score || TYPE_ORDER.indexOf(left.type) - TYPE_ORDER.indexOf(right.type) || byText(left.id, right.id));
|
|
432
|
+
return {
|
|
433
|
+
type: "search",
|
|
434
|
+
...notesOf(snapshot, false),
|
|
435
|
+
text: query.text,
|
|
436
|
+
hits: hits.slice(0, query.limit ?? 20)
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Answer one query. Throws a `GrimoireError`: `GR9001` for a file not in the
|
|
441
|
+
* book, `GR9002` no route, `GR9003` no feature, `GR9004` no flow, `GR9006`
|
|
442
|
+
* a search with no words. Pure.
|
|
443
|
+
*/
|
|
444
|
+
function scry(snapshot, query) {
|
|
445
|
+
switch (query.type) {
|
|
446
|
+
case "file": return scryFile(snapshot, query);
|
|
447
|
+
case "impact": return scryImpact(snapshot, query);
|
|
448
|
+
case "route": return scryRoute(snapshot, query);
|
|
449
|
+
case "feature": return scryFeature(snapshot, query);
|
|
450
|
+
case "flow": return scryFlow(snapshot, query);
|
|
451
|
+
case "search": return scrySearch(snapshot, query);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
//#endregion
|
|
456
|
+
export { scry };
|
|
457
|
+
//# sourceMappingURL=query.mjs.map
|
|
@@ -0,0 +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 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 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) => bookmap.steps.some((step) => step.files.includes(target.file)))\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 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 id: flow.id.value,\n status: flow.status.value,\n since: flow.since.value,\n heading: flow.heading?.value ?? null,\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: findingsFor(\n snapshot,\n (finding) =>\n finding.subject.feature === feature.id ||\n (finding.subject.flow ?? \"\").startsWith(`${feature.id}/`),\n ),\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\ntype Candidate = Omit<ScryHit, \"score\">;\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({ type: \"feature\", id: feature.id, detail: feature.readme?.title.value ?? null });\n\n for (const flow of feature.flows) {\n list.push({ type: \"flow\", id: flow.ref, detail: flow.heading?.value ?? null });\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/**\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 (3), fuzzy (2).\n */\nfunction scoreOf(candidate: Candidate, query: string, tokens: readonly string[]): number {\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 all = `${id} ${words(candidate.detail ?? \"\")}`;\n\n if (!tokens.every((token) => all.includes(token))) {\n const squeezed = id.replace(/ /g, \"\");\n\n return query.length >= FUZZY_MIN && tokens.every((token) => isSubsequence(token, squeezed))\n ? 2\n : 0;\n }\n\n if (id === query || last === query) return 7;\n if (id.startsWith(query) || last.startsWith(query)) return 6;\n\n const idWords = id.split(\" \");\n\n if (tokens.every((token) => idWords.includes(token))) return 5;\n if (tokens.every((token) => id.includes(token))) return 4;\n\n return 3;\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 = scoreOf(candidate, text, tokens);\n\n if (score > 0) hits.push({ ...candidate, score });\n }\n\n hits.sort(\n (left, right) =>\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 return {\n type: \"search\",\n ...notesOf(snapshot, false),\n text: query.text,\n hits: hits.slice(0, 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,IA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AU,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"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createFinding } from "../codes/index.mjs";
|
|
2
|
+
import { toPosixPath } from "../paths/index.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
|
|
6
|
+
//#region ../../packages/grimoire/src/tasks/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Task files: the GR7xxx rules. Parsing is `parseGrimoire`'s; the index is the
|
|
9
|
+
* workspace's. Read-only.
|
|
10
|
+
*/
|
|
11
|
+
function subjectOf(task, feature) {
|
|
12
|
+
return {
|
|
13
|
+
feature,
|
|
14
|
+
task: task.id.value,
|
|
15
|
+
file: task.file
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The feature and flow id a task's `flow` value names, or `null` when it cannot be read. */
|
|
19
|
+
function resolveFlow(task) {
|
|
20
|
+
const value = task.flow?.value;
|
|
21
|
+
if (value === void 0) return null;
|
|
22
|
+
if (value.includes("/")) {
|
|
23
|
+
const [feature = "", flow = ""] = value.split("/");
|
|
24
|
+
return {
|
|
25
|
+
feature,
|
|
26
|
+
flow
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return task.feature ? {
|
|
30
|
+
feature: task.feature.value,
|
|
31
|
+
flow: value
|
|
32
|
+
} : null;
|
|
33
|
+
}
|
|
34
|
+
function hasVersion(written, feature, version) {
|
|
35
|
+
return ((written.features.find((item) => item.id === feature)?.changelog)?.entries ?? []).some((entry) => entry.version.value === version);
|
|
36
|
+
}
|
|
37
|
+
function briefPath(task) {
|
|
38
|
+
const value = task.fields.find((item) => item.key.toLowerCase() === "brief")?.value.trim().replace(/^`|`$/g, "");
|
|
39
|
+
if (!value || /^[a-z]+:\/\//i.test(value)) return null;
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
/** The GR7xxx rules. Read-only. */
|
|
43
|
+
function checkTasks(snapshot) {
|
|
44
|
+
const { written, root } = snapshot;
|
|
45
|
+
const findings = [];
|
|
46
|
+
const featureIds = new Set(written.features.map((feature) => feature.id));
|
|
47
|
+
for (const task of written.tasks) {
|
|
48
|
+
const id = task.id.value;
|
|
49
|
+
if (task.feature && !featureIds.has(task.feature.value)) findings.push(createFinding({
|
|
50
|
+
code: "GR7001",
|
|
51
|
+
message: `task ${id} names feature "${task.feature.value}", which has no folder in grimoire/features`,
|
|
52
|
+
at: task.feature.at,
|
|
53
|
+
...subjectOf(task, task.feature.value)
|
|
54
|
+
}));
|
|
55
|
+
const flow = resolveFlow(task);
|
|
56
|
+
if (task.flow && flow === null) findings.push(createFinding({
|
|
57
|
+
code: "GR7002",
|
|
58
|
+
message: `task ${id} names flow "${task.flow.value}" without a feature; write \`<feature>/<flow>\` or set \`feature\``,
|
|
59
|
+
at: task.flow.at,
|
|
60
|
+
...subjectOf(task, null)
|
|
61
|
+
}));
|
|
62
|
+
else if (task.flow && flow !== null) {
|
|
63
|
+
const feature = written.features.find((item) => item.id === flow.feature);
|
|
64
|
+
if (!(task.feature?.value === flow.feature && !featureIds.has(flow.feature)) && !feature?.flows.some((item) => item.id.value === flow.flow)) findings.push(createFinding({
|
|
65
|
+
code: "GR7002",
|
|
66
|
+
message: `task ${id} names flow "${flow.feature}/${flow.flow}", which has no file`,
|
|
67
|
+
at: task.flow.at,
|
|
68
|
+
...subjectOf(task, flow.feature),
|
|
69
|
+
flow: `${flow.feature}/${flow.flow}`
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
const status = task.status.value;
|
|
73
|
+
if (task.folder === "done" && (status !== "done" || task.shipped === null)) findings.push(createFinding({
|
|
74
|
+
code: "GR7003",
|
|
75
|
+
message: `task ${id} is in tasks/done but ${status !== "done" ? `has status "${status}"` : "has no `shipped`"}`,
|
|
76
|
+
at: status !== "done" ? task.status.at : task.id.at,
|
|
77
|
+
...subjectOf(task, task.feature?.value ?? null)
|
|
78
|
+
}));
|
|
79
|
+
else if (task.folder === "open" && status === "done") findings.push(createFinding({
|
|
80
|
+
code: "GR7003",
|
|
81
|
+
message: `task ${id} has status "done" but is in tasks/open; move it to tasks/done/<yyyy-mm>/`,
|
|
82
|
+
at: task.status.at,
|
|
83
|
+
...subjectOf(task, task.feature?.value ?? null)
|
|
84
|
+
}));
|
|
85
|
+
if (task.shipped) {
|
|
86
|
+
const { feature, version } = task.shipped.value;
|
|
87
|
+
if (!hasVersion(written, feature, version)) findings.push(createFinding({
|
|
88
|
+
code: "GR7004",
|
|
89
|
+
message: `task ${id} shipped "${feature} ${version}", but the ${feature} changelog has no entry for version ${version}`,
|
|
90
|
+
at: task.shipped.at,
|
|
91
|
+
...subjectOf(task, feature)
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
const brief = briefPath(task);
|
|
95
|
+
if (brief !== null) {
|
|
96
|
+
const folder = path.resolve(root, "grimoire");
|
|
97
|
+
const target = path.resolve(folder, ...toPosixPath(brief).split("/"));
|
|
98
|
+
const relative = path.relative(folder, target);
|
|
99
|
+
const inside = relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
100
|
+
if (!inside || !existsSync(target)) {
|
|
101
|
+
const line = task.fields.find((item) => item.key.toLowerCase() === "brief");
|
|
102
|
+
findings.push(createFinding({
|
|
103
|
+
code: "GR7005",
|
|
104
|
+
message: inside ? `task ${id} points at brief "${brief}", which does not exist under grimoire/` : `task ${id} points at brief "${brief}", which is not a path inside grimoire/`,
|
|
105
|
+
at: line?.at ?? null,
|
|
106
|
+
...subjectOf(task, task.feature?.value ?? null)
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return findings;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { checkTasks };
|
|
116
|
+
//# sourceMappingURL=index.mjs.map
|