@warlock.js/grimoire 5.57.0 → 5.59.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 +44 -0
- package/esm/apps/check-apps.mjs +11 -5
- package/esm/apps/check-apps.mjs.map +1 -1
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +2 -1
- package/esm/book/build.mjs.map +1 -1
- package/esm/book/render.mjs +10 -0
- package/esm/book/render.mjs.map +1 -1
- package/esm/bookmap/build.d.mts.map +1 -1
- package/esm/bookmap/build.mjs +7 -5
- package/esm/bookmap/build.mjs.map +1 -1
- package/esm/bookmap/steps.mjs +85 -39
- package/esm/bookmap/steps.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +4 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/criteria.mjs +21 -2
- package/esm/check/rules/criteria.mjs.map +1 -1
- package/esm/check/rules/screenshots.mjs +57 -0
- package/esm/check/rules/screenshots.mjs.map +1 -0
- package/esm/codes/codes.d.mts +12 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +6 -0
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +28 -1
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/book.d.mts +2 -0
- package/esm/contracts/book.d.mts.map +1 -1
- package/esm/contracts/book.mjs.map +1 -1
- package/esm/contracts/bookmap.d.mts +19 -1
- package/esm/contracts/bookmap.d.mts.map +1 -1
- package/esm/contracts/scry.d.mts +26 -6
- package/esm/contracts/scry.d.mts.map +1 -1
- package/esm/contracts/snapshot.d.mts +14 -1
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/test-results.d.mts +34 -0
- package/esm/contracts/test-results.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +44 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/data.mjs +116 -5
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/feature-map.mjs +149 -0
- package/esm/devtools/feature-map.mjs.map +1 -0
- package/esm/devtools/index.d.mts +28 -2
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +111 -7
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/product-map.d.mts +14 -0
- package/esm/devtools/product-map.d.mts.map +1 -0
- package/esm/devtools/product-map.mjs +460 -0
- package/esm/devtools/product-map.mjs.map +1 -0
- package/esm/devtools/site.d.mts +43 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +190 -22
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +24 -7
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/graph/index.d.mts +10 -1
- package/esm/graph/index.d.mts.map +1 -1
- package/esm/graph/index.mjs +3 -2
- package/esm/graph/index.mjs.map +1 -1
- package/esm/index.d.mts +5 -5
- package/esm/ownership/index.d.mts.map +1 -1
- package/esm/ownership/index.mjs +60 -1
- package/esm/ownership/index.mjs.map +1 -1
- package/esm/paths/index.d.mts +2 -0
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +3 -1
- package/esm/paths/index.mjs.map +1 -1
- package/esm/scry/compact.mjs +170 -0
- package/esm/scry/compact.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +19 -2
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +159 -24
- package/esm/scry/query.mjs.map +1 -1
- package/esm/test-results/index.d.mts +7 -2
- package/esm/test-results/index.d.mts.map +1 -1
- package/esm/test-results/index.mjs +79 -12
- package/esm/test-results/index.mjs.map +1 -1
- package/esm/vitest/index.d.mts +6 -0
- package/esm/vitest/index.d.mts.map +1 -1
- package/esm/vitest/index.mjs +22 -6
- package/esm/vitest/index.mjs.map +1 -1
- package/esm/warlock/actions.mjs +15 -7
- package/esm/warlock/actions.mjs.map +1 -1
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +42 -4
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/commands.mjs +7 -2
- package/esm/warlock/commands.mjs.map +1 -1
- package/esm/warlock/logo.mjs +12 -0
- package/esm/warlock/logo.mjs.map +1 -0
- package/esm/warlock/mcp-tools.mjs +51 -15
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/workspace/cache.mjs +194 -0
- package/esm/workspace/cache.mjs.map +1 -0
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +7 -3
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/written/apps.mjs +4 -2
- package/esm/written/apps.mjs.map +1 -1
- package/esm/written/features.mjs +119 -6
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/markdown.mjs +66 -1
- package/esm/written/markdown.mjs.map +1 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +1 -1
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/llms-full.txt +108 -12
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +5 -0
- package/skills/describe-an-app/SKILL.md +12 -0
- package/skills/record-a-change/SKILL.md +10 -0
- package/skills/use-the-grimoire/SKILL.md +44 -10
- package/skills/write-a-feature/SKILL.md +37 -2
- package/ui/grimoire-static.js +61 -6
- package/ui/grimoire-view.js +2133 -316
- package/ui/grimoire.css +1030 -24
- package/ui/product-map.css +785 -0
- package/ui/product-map.js +1265 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { GRIMOIRE_PATHS } from "../paths/index.mjs";
|
|
2
|
+
import { resolveResultsFile } from "../test-results/index.mjs";
|
|
3
|
+
import { openGrimoire } from "./index.mjs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { readdir, stat } from "node:fs/promises";
|
|
7
|
+
|
|
8
|
+
//#region ../../packages/grimoire/src/workspace/cache.ts
|
|
9
|
+
/**
|
|
10
|
+
* Keeps the opened book in memory between calls of one process (the MCP
|
|
11
|
+
* server answers many questions per process) and says cheaply whether it is
|
|
12
|
+
* still current.
|
|
13
|
+
*
|
|
14
|
+
* Freshness is a stamp of `stat` results, no file is read: the size and
|
|
15
|
+
* modified time of every code and test file the book lists, the modified time
|
|
16
|
+
* of each folder that holds one and of every folder above it up to the project root (a new or removed file moves its
|
|
17
|
+
* folder; a new module folder moves its parent), every
|
|
18
|
+
* file under the written folders (`grimoire/features`, `apps`, `releases`,
|
|
19
|
+
* `tasks`, `screenshots`), the book manifest, the test results file and
|
|
20
|
+
* `package.json`. A stamp that equals the one taken after the last open
|
|
21
|
+
* returns the same snapshot; any difference opens the book again.
|
|
22
|
+
*/
|
|
23
|
+
/** The written folders whose every file is part of the stamp. */
|
|
24
|
+
const WRITTEN_TREES = [
|
|
25
|
+
GRIMOIRE_PATHS.features,
|
|
26
|
+
GRIMOIRE_PATHS.apps,
|
|
27
|
+
GRIMOIRE_PATHS.releases,
|
|
28
|
+
GRIMOIRE_PATHS.tasks,
|
|
29
|
+
GRIMOIRE_PATHS.screenshots
|
|
30
|
+
];
|
|
31
|
+
const STAT_BATCH = 256;
|
|
32
|
+
async function statLine(absolute, withSize) {
|
|
33
|
+
try {
|
|
34
|
+
const info = await stat(absolute);
|
|
35
|
+
return withSize ? `${info.size}:${info.mtimeMs}` : String(info.mtimeMs);
|
|
36
|
+
} catch {
|
|
37
|
+
return "-";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function statAll(files, withSize) {
|
|
41
|
+
const lines = [];
|
|
42
|
+
for (let start = 0; start < files.length; start += STAT_BATCH) lines.push(...await Promise.all(files.slice(start, start + STAT_BATCH).map((file) => statLine(file, withSize))));
|
|
43
|
+
return lines;
|
|
44
|
+
}
|
|
45
|
+
/** Every file below `folder` (absolute paths, sorted); a missing folder gives none. */
|
|
46
|
+
async function filesUnder(folder) {
|
|
47
|
+
const found = [];
|
|
48
|
+
const walk = async (current) => {
|
|
49
|
+
let entries;
|
|
50
|
+
try {
|
|
51
|
+
entries = await readdir(current, { withFileTypes: true });
|
|
52
|
+
} catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
const next = path.join(current, entry.name);
|
|
57
|
+
if (entry.isDirectory()) await walk(next);
|
|
58
|
+
else found.push(next);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
await walk(folder);
|
|
62
|
+
return found.sort();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The freshness stamp of a project, from the files of `snapshot` (its code and
|
|
66
|
+
* test files) and the written folders as they are now. Reads no file content.
|
|
67
|
+
*/
|
|
68
|
+
async function stampOf(root, snapshot, testResultsFile) {
|
|
69
|
+
return (await takeStamp(root, snapshot, testResultsFile)).stamp;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The stat lines of a stamp hold `size:mtime` or `mtime`; the newest mtime of them that is not after `until`
|
|
73
|
+
* (a time in the future is clock skew, not an edit), 0 when none.
|
|
74
|
+
*/
|
|
75
|
+
function newestOf(lines, until) {
|
|
76
|
+
let newest = 0;
|
|
77
|
+
for (const line of lines) {
|
|
78
|
+
const value = Number(line.split(":").pop());
|
|
79
|
+
if (Number.isFinite(value) && value <= until && value > newest) newest = value;
|
|
80
|
+
}
|
|
81
|
+
return newest;
|
|
82
|
+
}
|
|
83
|
+
/** Every folder above `folder` up to (not including) the project root. */
|
|
84
|
+
function withAncestors(folders) {
|
|
85
|
+
const all = /* @__PURE__ */ new Set();
|
|
86
|
+
for (const folder of folders) {
|
|
87
|
+
let current = folder;
|
|
88
|
+
while (current !== "." && current !== "" && current !== "/") {
|
|
89
|
+
all.add(current);
|
|
90
|
+
current = path.posix.dirname(current.split(path.sep).join("/"));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return [...all].sort();
|
|
94
|
+
}
|
|
95
|
+
/** The stamp, and the newest modified time among the code, test and written files and their folders. */
|
|
96
|
+
async function takeStamp(root, snapshot, testResultsFile) {
|
|
97
|
+
const listed = [...snapshot.book.facts.files.map((file) => file.file), ...snapshot.book.facts.tests];
|
|
98
|
+
const folders = withAncestors([...new Set(listed.map((file) => path.dirname(file)))]);
|
|
99
|
+
const written = (await Promise.all(WRITTEN_TREES.map((tree) => filesUnder(path.join(root, ...tree.split("/")))))).flat();
|
|
100
|
+
const singles = [
|
|
101
|
+
path.join(root, ...GRIMOIRE_PATHS.bookManifest.split("/")),
|
|
102
|
+
path.join(root, ...GRIMOIRE_PATHS.bookRoutes.split("/")),
|
|
103
|
+
resolveResultsFile(root, testResultsFile),
|
|
104
|
+
path.join(root, "package.json")
|
|
105
|
+
];
|
|
106
|
+
const [fileLines, folderLines, writtenLines, singleLines] = await Promise.all([
|
|
107
|
+
statAll(listed.map((file) => path.join(root, ...file.split("/"))), true),
|
|
108
|
+
statAll(folders.map((folder) => path.join(root, ...folder.split(path.sep))), false),
|
|
109
|
+
statAll(written, true),
|
|
110
|
+
statAll(singles, true)
|
|
111
|
+
]);
|
|
112
|
+
return {
|
|
113
|
+
stamp: createHash("sha1").update(JSON.stringify([
|
|
114
|
+
listed,
|
|
115
|
+
fileLines,
|
|
116
|
+
folders,
|
|
117
|
+
folderLines,
|
|
118
|
+
written,
|
|
119
|
+
writtenLines,
|
|
120
|
+
singleLines
|
|
121
|
+
])).digest("hex"),
|
|
122
|
+
newest: newestOf([
|
|
123
|
+
...fileLines,
|
|
124
|
+
...folderLines,
|
|
125
|
+
...writtenLines
|
|
126
|
+
], Date.now())
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** What a cached open is asked with; two different asks never share an entry. */
|
|
130
|
+
function keyOf(root, options) {
|
|
131
|
+
return JSON.stringify([
|
|
132
|
+
root,
|
|
133
|
+
options.write !== false,
|
|
134
|
+
options.testResultsFile ?? null
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create a cache. `reopen` is how the book is opened (default `openGrimoire`);
|
|
139
|
+
* specs pass a counter to see how many times the book was really opened.
|
|
140
|
+
*/
|
|
141
|
+
function createBookCache(reopen = openGrimoire) {
|
|
142
|
+
const kept = /* @__PURE__ */ new Map();
|
|
143
|
+
const opening = /* @__PURE__ */ new Map();
|
|
144
|
+
const writing = /* @__PURE__ */ new Map();
|
|
145
|
+
const openOnce = async (key, root, adapter, options) => {
|
|
146
|
+
const startedAt = Date.now();
|
|
147
|
+
const snapshot = await reopen(root, adapter, options);
|
|
148
|
+
const { stamp, newest } = await takeStamp(root, snapshot, options.testResultsFile);
|
|
149
|
+
kept.set(key, {
|
|
150
|
+
snapshot,
|
|
151
|
+
stamp: newest > startedAt ? `unsettled:${stamp}` : stamp
|
|
152
|
+
});
|
|
153
|
+
return snapshot;
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
async open(root, adapter, options = {}) {
|
|
157
|
+
const key = keyOf(root, options);
|
|
158
|
+
const known = kept.get(key);
|
|
159
|
+
const mustOpen = options.force === true || options.routes === "fresh";
|
|
160
|
+
if (known !== void 0 && !mustOpen) {
|
|
161
|
+
if (await stampOf(root, known.snapshot, options.testResultsFile) === known.stamp) return known.snapshot;
|
|
162
|
+
}
|
|
163
|
+
const running = opening.get(key);
|
|
164
|
+
if (running !== void 0 && !mustOpen) return running;
|
|
165
|
+
let started;
|
|
166
|
+
if (options.write === false) started = openOnce(key, root, adapter, options);
|
|
167
|
+
else {
|
|
168
|
+
started = (writing.get(root) ?? Promise.resolve()).catch(() => void 0).then(() => openOnce(key, root, adapter, options));
|
|
169
|
+
writing.set(root, started);
|
|
170
|
+
started.catch(() => void 0).finally(() => {
|
|
171
|
+
if (writing.get(root) === started) writing.delete(root);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const tracked = started.finally(() => {
|
|
175
|
+
if (opening.get(key) === tracked) opening.delete(key);
|
|
176
|
+
});
|
|
177
|
+
opening.set(key, tracked);
|
|
178
|
+
return tracked;
|
|
179
|
+
},
|
|
180
|
+
clear() {
|
|
181
|
+
kept.clear();
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** The process-wide cache the MCP tools and `warlock scry` use. */
|
|
186
|
+
const openedBooks = createBookCache();
|
|
187
|
+
/** `openGrimoire` that keeps the book in memory while nothing changed. */
|
|
188
|
+
function openGrimoireCached(root, adapter, options = {}) {
|
|
189
|
+
return openedBooks.open(root, adapter, options);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { createBookCache, openGrimoireCached, openedBooks, stampOf };
|
|
194
|
+
//# sourceMappingURL=cache.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/cache.ts"],"sourcesContent":["/**\n * Keeps the opened book in memory between calls of one process (the MCP\n * server answers many questions per process) and says cheaply whether it is\n * still current.\n *\n * Freshness is a stamp of `stat` results, no file is read: the size and\n * modified time of every code and test file the book lists, the modified time\n * of each folder that holds one and of every folder above it up to the project root (a new or removed file moves its\n * folder; a new module folder moves its parent), every\n * file under the written folders (`grimoire/features`, `apps`, `releases`,\n * `tasks`, `screenshots`), the book manifest, the test results file and\n * `package.json`. A stamp that equals the one taken after the last open\n * returns the same snapshot; any difference opens the book again.\n */\nimport { createHash } from \"node:crypto\";\nimport { readdir, stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { resolveResultsFile } from \"../test-results\";\nimport { openGrimoire } from \"./index\";\n\n/** The written folders whose every file is part of the stamp. */\nconst WRITTEN_TREES = [\n GRIMOIRE_PATHS.features,\n GRIMOIRE_PATHS.apps,\n GRIMOIRE_PATHS.releases,\n GRIMOIRE_PATHS.tasks,\n GRIMOIRE_PATHS.screenshots,\n];\n\nconst STAT_BATCH = 256;\n\nasync function statLine(absolute: string, withSize: boolean): Promise<string> {\n try {\n const info = await stat(absolute);\n\n return withSize ? `${info.size}:${info.mtimeMs}` : String(info.mtimeMs);\n } catch {\n return \"-\";\n }\n}\n\nasync function statAll(files: readonly string[], withSize: boolean): Promise<string[]> {\n const lines: string[] = [];\n\n for (let start = 0; start < files.length; start += STAT_BATCH) {\n lines.push(\n ...(await Promise.all(\n files.slice(start, start + STAT_BATCH).map((file) => statLine(file, withSize)),\n )),\n );\n }\n\n return lines;\n}\n\n/** Every file below `folder` (absolute paths, sorted); a missing folder gives none. */\nasync function filesUnder(folder: string): Promise<string[]> {\n const found: string[] = [];\n const walk = async (current: string): Promise<void> => {\n let entries;\n\n try {\n entries = await readdir(current, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n const next = path.join(current, entry.name);\n\n if (entry.isDirectory()) await walk(next);\n else found.push(next);\n }\n };\n\n await walk(folder);\n\n return found.sort();\n}\n\n/**\n * The freshness stamp of a project, from the files of `snapshot` (its code and\n * test files) and the written folders as they are now. Reads no file content.\n */\nexport async function stampOf(\n root: string,\n snapshot: GrimoireSnapshot,\n testResultsFile?: string,\n): Promise<string> {\n return (await takeStamp(root, snapshot, testResultsFile)).stamp;\n}\n\n/**\n * The stat lines of a stamp hold `size:mtime` or `mtime`; the newest mtime of them that is not after `until`\n * (a time in the future is clock skew, not an edit), 0 when none.\n */\nfunction newestOf(lines: readonly string[], until: number): number {\n let newest = 0;\n\n for (const line of lines) {\n const value = Number(line.split(\":\").pop());\n\n if (Number.isFinite(value) && value <= until && value > newest) newest = value;\n }\n\n return newest;\n}\n\n/** Every folder above `folder` up to (not including) the project root. */\nfunction withAncestors(folders: readonly string[]): string[] {\n const all = new Set<string>();\n\n for (const folder of folders) {\n let current = folder;\n\n while (current !== \".\" && current !== \"\" && current !== \"/\") {\n all.add(current);\n current = path.posix.dirname(current.split(path.sep).join(\"/\"));\n }\n }\n\n return [...all].sort();\n}\n\n/** The stamp, and the newest modified time among the code, test and written files and their folders. */\nasync function takeStamp(\n root: string,\n snapshot: GrimoireSnapshot,\n testResultsFile?: string,\n): Promise<{ stamp: string; newest: number }> {\n const listed = [\n ...snapshot.book.facts.files.map((file) => file.file),\n ...snapshot.book.facts.tests,\n ];\n const folders = withAncestors([...new Set(listed.map((file) => path.dirname(file)))]);\n const written = (\n await Promise.all(WRITTEN_TREES.map((tree) => filesUnder(path.join(root, ...tree.split(\"/\")))))\n ).flat();\n const singles = [\n path.join(root, ...GRIMOIRE_PATHS.bookManifest.split(\"/\")),\n path.join(root, ...GRIMOIRE_PATHS.bookRoutes.split(\"/\")),\n resolveResultsFile(root, testResultsFile),\n path.join(root, \"package.json\"),\n ];\n const [fileLines, folderLines, writtenLines, singleLines] = await Promise.all([\n statAll(\n listed.map((file) => path.join(root, ...file.split(\"/\"))),\n true,\n ),\n statAll(\n folders.map((folder) => path.join(root, ...folder.split(path.sep))),\n false,\n ),\n statAll(written, true),\n statAll(singles, true),\n ]);\n\n const stamp = createHash(\"sha1\")\n .update(\n JSON.stringify([listed, fileLines, folders, folderLines, written, writtenLines, singleLines]),\n )\n .digest(\"hex\");\n\n return { stamp, newest: newestOf([...fileLines, ...folderLines, ...writtenLines], Date.now()) };\n}\n\ntype Entry = { snapshot: GrimoireSnapshot; stamp: string };\n\n/** What a cached open is asked with; two different asks never share an entry. */\nfunction keyOf(root: string, options: OpenGrimoireOptions): string {\n return JSON.stringify([root, options.write !== false, options.testResultsFile ?? null]);\n}\n\n/** A book cache: `open()` returns the kept snapshot while the stamp holds. */\nexport type BookCache = {\n /** The snapshot for `root`: kept when nothing changed, else opened again. `force`, or `routes: \"fresh\"`, always opens. */\n open(\n root: string,\n adapter: BookAdapter,\n options?: OpenGrimoireOptions,\n ): Promise<GrimoireSnapshot>;\n /** Forget everything kept. */\n clear(): void;\n};\n\n/**\n * Create a cache. `reopen` is how the book is opened (default `openGrimoire`);\n * specs pass a counter to see how many times the book was really opened.\n */\nexport function createBookCache(reopen: typeof openGrimoire = openGrimoire): BookCache {\n const kept = new Map<string, Entry>();\n const opening = new Map<string, Promise<GrimoireSnapshot>>();\n // Opens that write the book's files wait for each other, per project.\n const writing = new Map<string, Promise<unknown>>();\n\n const openOnce = async (\n key: string,\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions,\n ): Promise<GrimoireSnapshot> => {\n // The clock is read before the open, so a file edited while it ran is seen as newer than the stamp.\n const startedAt = Date.now();\n const snapshot = await reopen(root, adapter, options);\n const { stamp, newest } = await takeStamp(root, snapshot, options.testResultsFile);\n\n // A change after the start may not be in the snapshot: keep it unstamped so the next call opens again.\n kept.set(key, {\n snapshot,\n stamp: newest > startedAt ? `unsettled:${stamp}` : stamp,\n });\n\n return snapshot;\n };\n\n return {\n async open(root, adapter, options = {}) {\n const key = keyOf(root, options);\n const known = kept.get(key);\n const mustOpen = options.force === true || options.routes === \"fresh\";\n\n if (known !== undefined && !mustOpen) {\n const stamp = await stampOf(root, known.snapshot, options.testResultsFile);\n\n if (stamp === known.stamp) return known.snapshot;\n }\n\n // Concurrent callers wait for the same open.\n const running = opening.get(key);\n\n if (running !== undefined && !mustOpen) return running;\n\n let started: Promise<GrimoireSnapshot>;\n\n if (options.write === false) {\n started = openOnce(key, root, adapter, options);\n } else {\n const before = writing.get(root) ?? Promise.resolve();\n\n started = before.catch(() => undefined).then(() => openOnce(key, root, adapter, options));\n writing.set(root, started);\n started\n .catch(() => undefined)\n .finally(() => {\n if (writing.get(root) === started) writing.delete(root);\n });\n }\n\n const tracked = started.finally(() => {\n if (opening.get(key) === tracked) opening.delete(key);\n });\n\n opening.set(key, tracked);\n\n return tracked;\n },\n clear() {\n kept.clear();\n },\n };\n}\n\n/** The process-wide cache the MCP tools and `warlock scry` use. */\nexport const openedBooks: BookCache = createBookCache();\n\n/** `openGrimoire` that keeps the book in memory while nothing changed. */\nexport function openGrimoireCached(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return openedBooks.open(root, adapter, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,gBAAgB;CACpB,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AAEA,MAAM,aAAa;AAEnB,eAAe,SAAS,UAAkB,UAAoC;CAC5E,IAAI;EACF,MAAM,OAAO,MAAM,KAAK,QAAQ;EAEhC,OAAO,WAAW,GAAG,KAAK,KAAK,GAAG,KAAK,YAAY,OAAO,KAAK,OAAO;CACxE,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAe,QAAQ,OAA0B,UAAsC;CACrF,MAAM,QAAkB,CAAC;CAEzB,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,YACjD,MAAM,KACJ,GAAI,MAAM,QAAQ,IAChB,MAAM,MAAM,OAAO,QAAQ,UAAU,CAAC,CAAC,KAAK,SAAS,SAAS,MAAM,QAAQ,CAAC,CAC/E,CACF;CAGF,OAAO;AACT;;AAGA,eAAe,WAAW,QAAmC;CAC3D,MAAM,QAAkB,CAAC;CACzB,MAAM,OAAO,OAAO,YAAmC;EACrD,IAAI;EAEJ,IAAI;GACF,UAAU,MAAM,QAAQ,SAAS,EAAE,eAAe,KAAK,CAAC;EAC1D,QAAQ;GACN;EACF;EAEA,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,OAAO,KAAK,KAAK,SAAS,MAAM,IAAI;GAE1C,IAAI,MAAM,YAAY,GAAG,MAAM,KAAK,IAAI;QACnC,MAAM,KAAK,IAAI;EACtB;CACF;CAEA,MAAM,KAAK,MAAM;CAEjB,OAAO,MAAM,KAAK;AACpB;;;;;AAMA,eAAsB,QACpB,MACA,UACA,iBACiB;CACjB,QAAQ,M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AK,IAAI,GAAG;GAC1B,MAAM,WAAW,QAAQ,UAAU,QAAQ,QAAQ,WAAW;GAE9D,IAAI,UAAU,UAAa,CAAC,UAG1B;QAAI,MAFgB,QAAQ,MAAM,MAAM,UAAU,QAAQ,eAAe,MAE3D,MAAM,OAAO,OAAO,MAAM;GAAQ;GAIlD,MAAM,UAAU,QAAQ,IAAI,GAAG;GAE/B,IAAI,YAAY,UAAa,CAAC,UAAU,OAAO;GAE/C,IAAI;GAEJ,IAAI,QAAQ,UAAU,OACpB,UAAU,SAAS,KAAK,MAAM,SAAS,OAAO;QACzC;IAGL,WAFe,QAAQ,IAAI,IAAI,KAAK,QAAQ,QAAQ,EAEpC,CAAC,YAAY,MAAS,CAAC,CAAC,WAAW,SAAS,KAAK,MAAM,SAAS,OAAO,CAAC;IACxF,QAAQ,IAAI,MAAM,OAAO;IACzB,QACG,YAAY,MAAS,CAAC,CACtB,cAAc;KACb,IAAI,QAAQ,IAAI,IAAI,MAAM,SAAS,QAAQ,OAAO,IAAI;IACxD,CAAC;GACL;GAEA,MAAM,UAAU,QAAQ,cAAc;IACpC,IAAI,QAAQ,IAAI,GAAG,MAAM,SAAS,QAAQ,OAAO,GAAG;GACtD,CAAC;GAED,QAAQ,IAAI,KAAK,OAAO;GAExB,OAAO;EACT;EACA,QAAQ;GACN,KAAK,MAAM;EACb;CACF;AACF;;AAGA,MAAa,cAAyB,gBAAgB;;AAGtD,SAAgB,mBACd,MACA,SACA,UAA+B,CAAC,GACL;CAC3B,OAAO,YAAY,KAAK,MAAM,SAAS,OAAO;AAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"mappings":";;;;;;;;wBAuJsB,aACpB,cACA,SAAS,aACT,UAAS,sBACR,QAAQ"}
|
package/esm/workspace/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import "../book/index.mjs";
|
|
|
7
7
|
import { resolveOwnership } from "../ownership/index.mjs";
|
|
8
8
|
import { matchApps } from "../apps/match-apps.mjs";
|
|
9
9
|
import "../apps/index.mjs";
|
|
10
|
-
import { readTestResults } from "../test-results/index.mjs";
|
|
10
|
+
import { readTestResults, resultsFileLabel } from "../test-results/index.mjs";
|
|
11
11
|
import { annotationsFrom, buildCollectedFiles } from "../bookmap/build.mjs";
|
|
12
12
|
import { writeCollectedFiles } from "../bookmap/write.mjs";
|
|
13
13
|
import "../bookmap/index.mjs";
|
|
@@ -62,7 +62,8 @@ async function runGrimoire(root, adapter, options = {}) {
|
|
|
62
62
|
const apps = matchApps(written.apps, book.facts);
|
|
63
63
|
const ownership = resolveOwnership(written, book.facts);
|
|
64
64
|
const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);
|
|
65
|
-
const
|
|
65
|
+
const resultsFile = resultsFileLabel(root, options.testResultsFile);
|
|
66
|
+
const results = await readTestResults(root, options.testResultsFile);
|
|
66
67
|
const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);
|
|
67
68
|
const input = {
|
|
68
69
|
written,
|
|
@@ -87,6 +88,7 @@ async function runGrimoire(root, adapter, options = {}) {
|
|
|
87
88
|
bookWrite = await writeBook(book, annotations);
|
|
88
89
|
collectedWrite = await writeCollectedFiles(root, collected);
|
|
89
90
|
}
|
|
91
|
+
const host = await adapter.host?.(root) ?? null;
|
|
90
92
|
return {
|
|
91
93
|
snapshot: {
|
|
92
94
|
root,
|
|
@@ -98,9 +100,11 @@ async function runGrimoire(root, adapter, options = {}) {
|
|
|
98
100
|
proofs,
|
|
99
101
|
proofFindings,
|
|
100
102
|
results,
|
|
103
|
+
resultsFile,
|
|
101
104
|
collected,
|
|
102
105
|
annotations,
|
|
103
|
-
routes: book.routes
|
|
106
|
+
routes: book.routes,
|
|
107
|
+
host
|
|
104
108
|
},
|
|
105
109
|
rebuilt,
|
|
106
110
|
changed,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"sourcesContent":["/**\n * The pipeline every command runs first (owned by T-128):\n *\n * 1. `parseGrimoire(root)`;\n * 2. `buildBook(root, adapter, { routes })`;\n * 3. `matchApps`, `resolveOwnership`, `scanProofs`, `readTestResults`;\n * 4. `buildCollectedFiles`, `annotationsFrom`;\n * 5. when `write` is not `false`: `writeBook` and `writeCollectedFiles`.\n *\n * A second run with nothing changed calls no adapter method and writes no file.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { matchApps } from \"../apps\";\nimport { buildBook, writeBook } from \"../book\";\nimport {\n annotationsFrom,\n buildCollectedFiles,\n writeCollectedFiles,\n type CollectedInput,\n} from \"../bookmap\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { BuildBookOptions, WriteBookResult } from \"../contracts/book\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { resolveOwnership } from \"../ownership\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofs } from \"../proves\";\nimport { readTestResults } from \"../test-results\";\nimport { parseGrimoire } from \"../written\";\n\n/** The current sha256 of each test file: the manifest's, else read now (missing files are left out). */\nasync function testFileHashes(\n root: string,\n tests: readonly string[],\n known: Readonly<Record<string, string>>,\n): Promise<Record<string, string>> {\n const hashes: Record<string, string> = {};\n\n for (const test of [...new Set(tests.map(toPosixPath))].sort()) {\n const hash = known[test];\n\n if (hash !== undefined) {\n hashes[test] = hash;\n continue;\n }\n\n try {\n const content = await readFile(path.join(root, ...test.split(\"/\")));\n hashes[test] = createHash(\"sha256\").update(content).digest(\"hex\");\n } catch {\n // A listed test file that is gone has no hash; its results are not marked stale.\n }\n }\n\n return hashes;\n}\n\n/** What one pass of the pipeline did, with the snapshot it produced (`warlock grimoire build` prints it). */\nexport type GrimoireRun = {\n snapshot: GrimoireSnapshot;\n /** `false` when the book's fingerprint matched and the adapter was not asked for files. */\n rebuilt: boolean;\n /** Source files added, changed or removed since the last build. */\n changed: string[];\n /** Book files written and removed (both empty with `write: false`). */\n book: WriteBookResult;\n /** Collected files (book maps, indexes) written and removed (both empty with `write: false`). */\n collected: { written: string[]; removed: string[] };\n};\n\n/**\n * Run the pipeline and say what it wrote. `openGrimoire` is this without the\n * counts.\n *\n * @param root Absolute project root.\n */\nexport async function runGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireRun> {\n const write = options.write !== false;\n const { written, findings: structure } = await parseGrimoire(root);\n\n const bookOptions: BuildBookOptions & { write?: boolean } = {\n routes: options.routes ?? \"cached\",\n };\n\n if (options.force !== undefined) bookOptions.force = options.force;\n if (options.now !== undefined) bookOptions.now = options.now;\n if (!write) bookOptions.write = false;\n\n const { book, rebuilt, changed } = await buildBook(root, adapter, bookOptions);\n const apps = matchApps(written.apps, book.facts);\n const ownership = resolveOwnership(written, book.facts);\n const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);\n const results = await readTestResults(root);\n const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);\n\n const input: CollectedInput = {\n written,\n facts: book.facts,\n ownership,\n apps,\n proofs,\n results,\n testHashes,\n };\n const collected = buildCollectedFiles(input);\n const annotations = annotationsFrom(input, collected, { tests: testHashes });\n let bookWrite: WriteBookResult = { written: [], removed: [] };\n let collectedWrite: { written: string[]; removed: string[] } = { written: [], removed: [] };\n\n if (write) {\n bookWrite = await writeBook(book, annotations);\n collectedWrite = await writeCollectedFiles(root, collected);\n }\n\n return {\n snapshot: {\n root,\n written,\n structure,\n book,\n ownership,\n apps,\n proofs,\n proofFindings,\n results,\n collected,\n annotations,\n routes: book.routes,\n },\n rebuilt,\n changed,\n book: bookWrite,\n collected: collectedWrite,\n };\n}\n\n/**\n * Load, refresh and return everything about the project's grimoire.\n *\n * @param root Absolute project root.\n */\nexport async function openGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return (await runGrimoire(root, adapter, options)).snapshot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAe,eACb,MACA,OACA,OACiC;CACjC,MAAM,SAAiC,CAAC;CAExC,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;EAC9D,MAAM,OAAO,MAAM;EAEnB,IAAI,SAAS,QAAW;GACtB,OAAO,QAAQ;GACf;EACF;EAEA,IAAI;GACF,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC;GAClE,OAAO,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;EAClE,QAAQ,CAER;CACF;CAEA,OAAO;AACT;;;;;;;AAqBA,eAAsB,YACpB,MACA,SACA,UAA+B,CAAC,GACV;CACtB,MAAM,QAAQ,QAAQ,UAAU;CAChC,MAAM,EAAE,SAAS,UAAU,cAAc,MAAM,cAAc,IAAI;CAEjE,MAAM,cAAsD,EAC1D,QAAQ,QAAQ,UAAU,SAC5B;CAEA,IAAI,QAAQ,UAAU,QAAW,YAAY,QAAQ,QAAQ;CAC7D,IAAI,QAAQ,QAAQ,QAAW,YAAY,MAAM,QAAQ;CACzD,IAAI,CAAC,OAAO,YAAY,QAAQ;CAEhC,MAAM,EAAE,MAAM,SAAS,YAAY,MAAM,UAAU,MAAM,SAAS,WAAW;CAC7E,MAAM,OAAO,UAAU,QAAQ,MAAM,KAAK,KAAK;CAC/C,MAAM,YAAY,iBAAiB,SAAS,KAAK,KAAK;CACtD,MAAM,EAAE,QAAQ,UAAU,kBAAkB,MAAM,WAAW,MAAM,KAAK,MAAM,KAAK;CACnF,MAAM,UAAU,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"sourcesContent":["/**\n * The pipeline every command runs first (owned by T-128):\n *\n * 1. `parseGrimoire(root)`;\n * 2. `buildBook(root, adapter, { routes })`;\n * 3. `matchApps`, `resolveOwnership`, `scanProofs`, `readTestResults`;\n * 4. `buildCollectedFiles`, `annotationsFrom`;\n * 5. when `write` is not `false`: `writeBook` and `writeCollectedFiles`.\n *\n * A second run with nothing changed calls no adapter method and writes no file.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { matchApps } from \"../apps\";\nimport { buildBook, writeBook } from \"../book\";\nimport {\n annotationsFrom,\n buildCollectedFiles,\n writeCollectedFiles,\n type CollectedInput,\n} from \"../bookmap\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { BuildBookOptions, WriteBookResult } from \"../contracts/book\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { resolveOwnership } from \"../ownership\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofs } from \"../proves\";\nimport { readTestResults, resultsFileLabel } from \"../test-results\";\nimport { parseGrimoire } from \"../written\";\n\n/** The current sha256 of each test file: the manifest's, else read now (missing files are left out). */\nasync function testFileHashes(\n root: string,\n tests: readonly string[],\n known: Readonly<Record<string, string>>,\n): Promise<Record<string, string>> {\n const hashes: Record<string, string> = {};\n\n for (const test of [...new Set(tests.map(toPosixPath))].sort()) {\n const hash = known[test];\n\n if (hash !== undefined) {\n hashes[test] = hash;\n continue;\n }\n\n try {\n const content = await readFile(path.join(root, ...test.split(\"/\")));\n hashes[test] = createHash(\"sha256\").update(content).digest(\"hex\");\n } catch {\n // A listed test file that is gone has no hash; its results are not marked stale.\n }\n }\n\n return hashes;\n}\n\n/** What one pass of the pipeline did, with the snapshot it produced (`warlock grimoire build` prints it). */\nexport type GrimoireRun = {\n snapshot: GrimoireSnapshot;\n /** `false` when the book's fingerprint matched and the adapter was not asked for files. */\n rebuilt: boolean;\n /** Source files added, changed or removed since the last build. */\n changed: string[];\n /** Book files written and removed (both empty with `write: false`). */\n book: WriteBookResult;\n /** Collected files (book maps, indexes) written and removed (both empty with `write: false`). */\n collected: { written: string[]; removed: string[] };\n};\n\n/**\n * Run the pipeline and say what it wrote. `openGrimoire` is this without the\n * counts.\n *\n * @param root Absolute project root.\n */\nexport async function runGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireRun> {\n const write = options.write !== false;\n const { written, findings: structure } = await parseGrimoire(root);\n\n const bookOptions: BuildBookOptions & { write?: boolean } = {\n routes: options.routes ?? \"cached\",\n };\n\n if (options.force !== undefined) bookOptions.force = options.force;\n if (options.now !== undefined) bookOptions.now = options.now;\n if (!write) bookOptions.write = false;\n\n const { book, rebuilt, changed } = await buildBook(root, adapter, bookOptions);\n const apps = matchApps(written.apps, book.facts);\n const ownership = resolveOwnership(written, book.facts);\n const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);\n const resultsFile = resultsFileLabel(root, options.testResultsFile);\n const results = await readTestResults(root, options.testResultsFile);\n const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);\n\n const input: CollectedInput = {\n written,\n facts: book.facts,\n ownership,\n apps,\n proofs,\n results,\n testHashes,\n };\n const collected = buildCollectedFiles(input);\n const annotations = annotationsFrom(input, collected, { tests: testHashes });\n let bookWrite: WriteBookResult = { written: [], removed: [] };\n let collectedWrite: { written: string[]; removed: string[] } = { written: [], removed: [] };\n\n if (write) {\n bookWrite = await writeBook(book, annotations);\n collectedWrite = await writeCollectedFiles(root, collected);\n }\n\n const host = (await adapter.host?.(root)) ?? null;\n\n return {\n snapshot: {\n root,\n written,\n structure,\n book,\n ownership,\n apps,\n proofs,\n proofFindings,\n results,\n resultsFile,\n collected,\n annotations,\n routes: book.routes,\n host,\n },\n rebuilt,\n changed,\n book: bookWrite,\n collected: collectedWrite,\n };\n}\n\n/**\n * Load, refresh and return everything about the project's grimoire.\n *\n * @param root Absolute project root.\n */\nexport async function openGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return (await runGrimoire(root, adapter, options)).snapshot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAe,eACb,MACA,OACA,OACiC;CACjC,MAAM,SAAiC,CAAC;CAExC,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;EAC9D,MAAM,OAAO,MAAM;EAEnB,IAAI,SAAS,QAAW;GACtB,OAAO,QAAQ;GACf;EACF;EAEA,IAAI;GACF,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC;GAClE,OAAO,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;EAClE,QAAQ,CAER;CACF;CAEA,OAAO;AACT;;;;;;;AAqBA,eAAsB,YACpB,MACA,SACA,UAA+B,CAAC,GACV;CACtB,MAAM,QAAQ,QAAQ,UAAU;CAChC,MAAM,EAAE,SAAS,UAAU,cAAc,MAAM,cAAc,IAAI;CAEjE,MAAM,cAAsD,EAC1D,QAAQ,QAAQ,UAAU,SAC5B;CAEA,IAAI,QAAQ,UAAU,QAAW,YAAY,QAAQ,QAAQ;CAC7D,IAAI,QAAQ,QAAQ,QAAW,YAAY,MAAM,QAAQ;CACzD,IAAI,CAAC,OAAO,YAAY,QAAQ;CAEhC,MAAM,EAAE,MAAM,SAAS,YAAY,MAAM,UAAU,MAAM,SAAS,WAAW;CAC7E,MAAM,OAAO,UAAU,QAAQ,MAAM,KAAK,KAAK;CAC/C,MAAM,YAAY,iBAAiB,SAAS,KAAK,KAAK;CACtD,MAAM,EAAE,QAAQ,UAAU,kBAAkB,MAAM,WAAW,MAAM,KAAK,MAAM,KAAK;CACnF,MAAM,cAAc,iBAAiB,MAAM,QAAQ,eAAe;CAClE,MAAM,UAAU,MAAM,gBAAgB,MAAM,QAAQ,eAAe;CACnE,MAAM,aAAa,MAAM,eAAe,MAAM,KAAK,MAAM,OAAO,KAAK,SAAS,KAAK;CAEnF,MAAM,QAAwB;EAC5B;EACA,OAAO,KAAK;EACZ;EACA;EACA;EACA;EACA;CACF;CACA,MAAM,YAAY,oBAAoB,KAAK;CAC3C,MAAM,cAAc,gBAAgB,OAAO,WAAW,EAAE,OAAO,WAAW,CAAC;CAC3E,IAAI,YAA6B;EAAE,SAAS,CAAC;EAAG,SAAS,CAAC;CAAE;CAC5D,IAAI,iBAA2D;EAAE,SAAS,CAAC;EAAG,SAAS,CAAC;CAAE;CAE1F,IAAI,OAAO;EACT,YAAY,MAAM,UAAU,MAAM,WAAW;EAC7C,iBAAiB,MAAM,oBAAoB,MAAM,SAAS;CAC5D;CAEA,MAAM,OAAQ,MAAM,QAAQ,OAAO,IAAI,KAAM;CAE7C,OAAO;EACL,UAAU;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,QAAQ,KAAK;GACb;EACF;EACA;EACA;EACA,MAAM;EACN,WAAW;CACb;AACF;;;;;;AAOA,eAAsB,aACpB,MACA,SACA,UAA+B,CAAC,GACL;CAC3B,QAAQ,MAAM,YAAY,MAAM,SAAS,OAAO,EAAC,CAAE;AACrD"}
|
package/esm/written/apps.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkHeadings, findSection, lineAt, normalizeKey, paragraphAfterTitle, readDocument } from "./markdown.mjs";
|
|
1
|
+
import { checkHeadings, findSection, lineAt, normalizeKey, paragraphAfterTitle, readDocument, readScreenshots } from "./markdown.mjs";
|
|
2
2
|
import { FLOW_REF, FrontMatterReader, checks, projectFolder } from "./fields.mjs";
|
|
3
3
|
import { readListLines } from "./lists.mjs";
|
|
4
4
|
import { ORIGINS } from "./features.mjs";
|
|
@@ -198,6 +198,7 @@ function parsePage(file, text, app, type, id, sink) {
|
|
|
198
198
|
origin: fields.optionalOneOf("origin", ORIGINS),
|
|
199
199
|
heading: heading(document),
|
|
200
200
|
purpose: paragraphAfterTitle(document),
|
|
201
|
+
screenshots: readScreenshots(file, document.body, sink),
|
|
201
202
|
blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],
|
|
202
203
|
alsoReachedFrom,
|
|
203
204
|
blockFiles: []
|
|
@@ -218,7 +219,8 @@ function parseBlockFile(file, text, app, page, id, sink) {
|
|
|
218
219
|
check: checks.flowRef
|
|
219
220
|
}),
|
|
220
221
|
heading: heading(document),
|
|
221
|
-
details: readListLines(file, document.body, "detail", sink)
|
|
222
|
+
details: readListLines(file, document.body, "detail", sink),
|
|
223
|
+
screenshots: readScreenshots(file, document.body, sink)
|
|
222
224
|
};
|
|
223
225
|
}
|
|
224
226
|
|
package/esm/written/apps.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/apps.ts"],"sourcesContent":["/**\n * The files of one app folder: `README.md`, `layouts/<id>.md`,\n * `pages/<id>/README.md`, `screens/<id>/README.md` and their\n * `blocks/<id>.md` files, and the `## Blocks` table they share.\n */\nimport type {\n WrittenBlockFile,\n WrittenBlockRow,\n WrittenChangesWith,\n WrittenEntryPoint,\n WrittenLayout,\n WrittenListLine,\n WrittenOrigin,\n WrittenPage,\n} from \"../contracts/written\";\nimport type { Located } from \"../contracts/location\";\nimport { ORIGINS } from \"./features\";\nimport { FLOW_REF, FrontMatterReader, checks, projectFolder } from \"./fields\";\nimport { readListLines } from \"./lists\";\nimport {\n checkHeadings,\n findSection,\n lineAt,\n normalizeKey,\n paragraphAfterTitle,\n readDocument,\n type BodyLine,\n type WrittenDocument,\n} from \"./markdown\";\nimport type { FindingSink } from \"./sink\";\n\n/** The parts of `grimoire/apps/<id>/README.md` (the folder's other files are added by the walker). */\nexport type AppReadme = {\n id: Located<string>;\n type: Located<\"site\" | \"mobile\">;\n root: Located<string>;\n origin: Located<WrittenOrigin> | null;\n heading: Located<string> | null;\n conditions: WrittenListLine[];\n};\n\nconst BLOCK_COLUMNS = [\"block\", \"flow\", \"who sees it\", \"changes with\"];\nconst EMPTY_CELL = /^(?:—|–|-+)?$/;\nconst SEPARATOR_CELL = /^:?-+:?$/;\nconst CONDITION_ITEM = /^([a-z][a-z0-9-]*(?::[a-z0-9-]+)?):[ \\t]+(\\S.*)$/;\n\nfunction heading(document: WrittenDocument): Located<string> | null {\n return document.title\n ? { value: document.title.text, at: lineAt(document.file, document.title.line) }\n : null;\n}\n\n/** The cells of a table row, with or without outer pipes; `\\|` stays a pipe inside a cell. */\nexport function tableCells(row: string): string[] {\n let text = row.trim();\n\n if (text.startsWith(\"|\")) text = text.slice(1);\n if (text.endsWith(\"|\") && !text.endsWith(\"\\\\|\")) text = text.slice(0, -1);\n\n return text.split(/(?<!\\\\)\\|/).map((cell) => cell.trim().replace(/\\\\\\|/g, \"|\"));\n}\n\n/**\n * Read the `## Blocks` table: a header row `Block | Flow | Who sees it |\n * Changes with`, a separator row, then one row per block. Text before the\n * table is allowed; the table ends at the first line without a `|`.\n */\nexport function parseBlocksTable(\n file: string,\n section: { line: number; lines: readonly BodyLine[] },\n sink: FindingSink,\n): WrittenBlockRow[] {\n const rows: WrittenBlockRow[] = [];\n const lines = section.lines;\n const start = lines.findIndex((line) => !line.fenced && line.text.includes(\"|\"));\n\n if (start === -1) {\n sink.report(\"GR1018\", \"the Blocks section has no table.\", lineAt(file, section.line));\n\n return rows;\n }\n\n const header = lines[start];\n const separator = lines[start + 1];\n\n if (header === undefined) return rows;\n\n const columns = tableCells(header.text).map(normalizeKey);\n\n if (\n columns.length !== BLOCK_COLUMNS.length ||\n columns.some((column, index) => column !== BLOCK_COLUMNS[index])\n ) {\n sink.report(\n \"GR1018\",\n `the Blocks table header is ${JSON.stringify(header.text.trim())}; use the columns Block | Flow | Who sees it | Changes with.`,\n lineAt(file, header.line),\n );\n\n return rows;\n }\n\n const separatorCells =\n separator === undefined || separator.fenced ? [] : tableCells(separator.text);\n\n if (\n separatorCells.length !== BLOCK_COLUMNS.length ||\n !separatorCells.every((cell) => SEPARATOR_CELL.test(cell))\n ) {\n sink.report(\n \"GR1018\",\n \"the Blocks table header is not followed by a separator row (`| --- | --- | --- | --- |`).\",\n lineAt(file, separator?.line ?? header.line),\n );\n\n return rows;\n }\n\n for (let index = start + 2; index < lines.length; index++) {\n const line = lines[index];\n\n if (line === undefined || line.fenced || !line.text.includes(\"|\")) break;\n\n const at = lineAt(file, line.line);\n const cells = tableCells(line.text);\n\n if (cells.length !== BLOCK_COLUMNS.length) {\n sink.report(\"GR1018\", `the Blocks row has ${cells.length} cells instead of 4.`, at);\n continue;\n }\n\n const [block = \"\", flow = \"\", who = \"\", changesWith = \"\"] = cells;\n\n if (block === \"\") {\n sink.report(\"GR1018\", \"the Blocks row has no block name.\", at);\n continue;\n }\n\n if (!EMPTY_CELL.test(flow) && !FLOW_REF.test(flow)) {\n sink.report(\n \"GR1018\",\n `the Flow cell ${JSON.stringify(flow)} of block \"${block}\" is not <feature>/<flow> or —.`,\n at,\n );\n continue;\n }\n\n if (EMPTY_CELL.test(who)) {\n sink.report(\n \"GR1018\",\n `the \"Who sees it\" cell of block \"${block}\" is empty; write everyone or condition names.`,\n at,\n );\n continue;\n }\n\n const whoItems = who\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\");\n\n rows.push({\n block,\n flow: EMPTY_CELL.test(flow) ? null : flow,\n who: {\n everyone: whoItems.some((item) => item.toLowerCase() === \"everyone\"),\n conditions: whoItems.filter((item) => item.toLowerCase() !== \"everyone\"),\n },\n changesWith: EMPTY_CELL.test(changesWith)\n ? []\n : changesWith\n .split(\";\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\")\n .map((item): WrittenChangesWith => {\n const condition = CONDITION_ITEM.exec(item);\n\n return condition\n ? { condition: condition[1] ?? \"\", text: (condition[2] ?? \"\").trim() }\n : { condition: null, text: item };\n }),\n at,\n });\n }\n\n return rows;\n}\n\n/** `grimoire/apps/<id>/README.md`. */\nexport function parseAppReadme(\n file: string,\n text: string,\n folder: string,\n fallbackType: \"site\" | \"mobile\",\n sink: FindingSink,\n): AppReadme {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"id\", \"type\", \"root\", \"origin\"], \"app README\");\n\n const id = fields.required(\"id\", checks.id);\n\n if (id.value !== \"\" && id.value !== folder) {\n sink.report(\n \"GR1019\",\n `the app id ${JSON.stringify(id.value)} must equal its folder name ${JSON.stringify(folder)}.`,\n id.at,\n );\n }\n\n const root = fields.required(\"root\", checks.folder);\n\n checkHeadings(document, { title: false, required: [\"Conditions\"], optional: [] }, sink);\n\n return {\n id: id.value === \"\" ? { value: folder, at: id.at } : id,\n type: fields.oneOf(\"type\", [\"site\", \"mobile\"] as const, fallbackType),\n root: { value: projectFolder(root.value) ?? root.value, at: root.at },\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n conditions: readListLines(file, findSection(document, \"conditions\")?.lines, \"Conditions\", sink),\n };\n}\n\n/** `grimoire/apps/<app>/layouts/<id>.md`. */\nexport function parseLayout(\n file: string,\n text: string,\n app: string,\n id: string,\n sink: FindingSink,\n): WrittenLayout {\n const document = readDocument(file, text, \"none\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"origin\"], \"a layout\");\n checkHeadings(document, { title: false, required: [\"Blocks\"], optional: [] }, sink);\n\n const blocks = findSection(document, \"blocks\");\n\n return {\n file,\n app,\n id,\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<id>/README.md` or `screens/<id>/README.md`. */\nexport function parsePage(\n file: string,\n text: string,\n app: string,\n type: \"page\" | \"screen\",\n id: string,\n sink: FindingSink,\n): WrittenPage {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys(\n type === \"page\" ? [\"route\", \"layout\", \"origin\"] : [\"route\", \"screen\", \"layout\", \"origin\"],\n type,\n );\n\n const route = fields.scalar(\"route\", { required: type === \"page\", check: checks.route });\n const screen =\n type === \"screen\" ? fields.scalar(\"screen\", { required: false, check: checks.name }) : null;\n\n if (type === \"screen\" && fields.present && route === null && screen === null) {\n sink.report(\n \"GR1003\",\n 'a screen needs the front matter key \"route\" (file-based routing) or \"screen\" (its name in code).',\n lineAt(file, 1),\n );\n }\n\n checkHeadings(\n document,\n { title: true, required: [], optional: [\"Blocks\", \"Also reached from\"] },\n sink,\n );\n\n const blocks = findSection(document, \"blocks\");\n const alsoReachedFrom: WrittenEntryPoint[] = readListLines(\n file,\n findSection(document, \"also reached from\")?.lines,\n \"Also reached from\",\n sink,\n ).map((line) => ({ type: line.name, name: line.text, at: line.at }));\n\n return {\n file,\n app,\n type,\n id,\n route,\n screen,\n layout: fields.scalar(\"layout\", { required: false, check: checks.id }),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n purpose: paragraphAfterTitle(document),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n alsoReachedFrom,\n blockFiles: [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<page>/blocks/<id>.md`. */\nexport function parseBlockFile(\n file: string,\n text: string,\n app: string,\n page: string,\n id: string,\n sink: FindingSink,\n): WrittenBlockFile {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"flow\"], \"block file\");\n\n return {\n file,\n app,\n page,\n id,\n flow: fields.scalar(\"flow\", { required: true, check: checks.flowRef }),\n heading: heading(document),\n details: readListLines(file, document.body, \"detail\", sink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AAU,mBAAmB;CAAE,GACvE,IACF;CAEA,MAAM,SAAS,YAAY,UAAU,QAAQ;CAC7C,MAAM,kBAAuC,cAC3C,MACA,YAAY,UAAU,mBAAmB,CAAC,EAAE,OAC5C,qBACA,IACF,CAAC,CAAC,KAAK,UAAU;EAAE,MAAM,KAAK;EAAM,MAAM,KAAK;EAAM,IAAI,KAAK;CAAG,EAAE;CAEnE,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ,OAAO,OAAO,UAAU;GAAE,UAAU;GAAO,OAAO,OAAO;EAAG,CAAC;EACrE,QAAQ,OAAO,cAAc,UAAU,OAAO;EAC9C,SAAS,QAAQ,QAAQ;EACzB,SAAS,oBAAoB,QAAQ;EACrC,QAAQ,SAAS,iBAAiB,MAAM,QAAQ,IAAI,IAAI,CAAC;EACzD;EACA,YAAY,CAAC;CACf;AACF;;AAGA,SAAgB,eACd,MACA,MACA,KACA,MACA,IACA,MACkB;CAClB,MAAM,WAAW,aAAa,MAAM,MAAM,YAAY,IAAI;CAC1D,MAAM,SAAS,IAAI,kBAAkB,UAAU,IAAI;CAEnD,OAAO,SAAS,CAAC,MAAM,GAAG,YAAY;CAEtC,OAAO;EACL;EACA;EACA;EACA;EACA,MAAM,OAAO,OAAO,QAAQ;GAAE,UAAU;GAAM,OAAO,OAAO;EAAQ,CAAC;EACrE,SAAS,QAAQ,QAAQ;EACzB,SAAS,cAAc,MAAM,SAAS,MAAM,UAAU,IAAI;CAC5D;AACF"}
|
|
1
|
+
{"version":3,"file":"apps.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/apps.ts"],"sourcesContent":["/**\n * The files of one app folder: `README.md`, `layouts/<id>.md`,\n * `pages/<id>/README.md`, `screens/<id>/README.md` and their\n * `blocks/<id>.md` files, and the `## Blocks` table they share.\n */\nimport type {\n WrittenBlockFile,\n WrittenBlockRow,\n WrittenChangesWith,\n WrittenEntryPoint,\n WrittenLayout,\n WrittenListLine,\n WrittenOrigin,\n WrittenPage,\n} from \"../contracts/written\";\nimport type { Located } from \"../contracts/location\";\nimport { ORIGINS } from \"./features\";\nimport { FLOW_REF, FrontMatterReader, checks, projectFolder } from \"./fields\";\nimport { readListLines } from \"./lists\";\nimport {\n checkHeadings,\n findSection,\n lineAt,\n normalizeKey,\n paragraphAfterTitle,\n readDocument,\n readScreenshots,\n type BodyLine,\n type WrittenDocument,\n} from \"./markdown\";\nimport type { FindingSink } from \"./sink\";\n\n/** The parts of `grimoire/apps/<id>/README.md` (the folder's other files are added by the walker). */\nexport type AppReadme = {\n id: Located<string>;\n type: Located<\"site\" | \"mobile\">;\n root: Located<string>;\n origin: Located<WrittenOrigin> | null;\n heading: Located<string> | null;\n conditions: WrittenListLine[];\n};\n\nconst BLOCK_COLUMNS = [\"block\", \"flow\", \"who sees it\", \"changes with\"];\nconst EMPTY_CELL = /^(?:—|–|-+)?$/;\nconst SEPARATOR_CELL = /^:?-+:?$/;\nconst CONDITION_ITEM = /^([a-z][a-z0-9-]*(?::[a-z0-9-]+)?):[ \\t]+(\\S.*)$/;\n\nfunction heading(document: WrittenDocument): Located<string> | null {\n return document.title\n ? { value: document.title.text, at: lineAt(document.file, document.title.line) }\n : null;\n}\n\n/** The cells of a table row, with or without outer pipes; `\\|` stays a pipe inside a cell. */\nexport function tableCells(row: string): string[] {\n let text = row.trim();\n\n if (text.startsWith(\"|\")) text = text.slice(1);\n if (text.endsWith(\"|\") && !text.endsWith(\"\\\\|\")) text = text.slice(0, -1);\n\n return text.split(/(?<!\\\\)\\|/).map((cell) => cell.trim().replace(/\\\\\\|/g, \"|\"));\n}\n\n/**\n * Read the `## Blocks` table: a header row `Block | Flow | Who sees it |\n * Changes with`, a separator row, then one row per block. Text before the\n * table is allowed; the table ends at the first line without a `|`.\n */\nexport function parseBlocksTable(\n file: string,\n section: { line: number; lines: readonly BodyLine[] },\n sink: FindingSink,\n): WrittenBlockRow[] {\n const rows: WrittenBlockRow[] = [];\n const lines = section.lines;\n const start = lines.findIndex((line) => !line.fenced && line.text.includes(\"|\"));\n\n if (start === -1) {\n sink.report(\"GR1018\", \"the Blocks section has no table.\", lineAt(file, section.line));\n\n return rows;\n }\n\n const header = lines[start];\n const separator = lines[start + 1];\n\n if (header === undefined) return rows;\n\n const columns = tableCells(header.text).map(normalizeKey);\n\n if (\n columns.length !== BLOCK_COLUMNS.length ||\n columns.some((column, index) => column !== BLOCK_COLUMNS[index])\n ) {\n sink.report(\n \"GR1018\",\n `the Blocks table header is ${JSON.stringify(header.text.trim())}; use the columns Block | Flow | Who sees it | Changes with.`,\n lineAt(file, header.line),\n );\n\n return rows;\n }\n\n const separatorCells =\n separator === undefined || separator.fenced ? [] : tableCells(separator.text);\n\n if (\n separatorCells.length !== BLOCK_COLUMNS.length ||\n !separatorCells.every((cell) => SEPARATOR_CELL.test(cell))\n ) {\n sink.report(\n \"GR1018\",\n \"the Blocks table header is not followed by a separator row (`| --- | --- | --- | --- |`).\",\n lineAt(file, separator?.line ?? header.line),\n );\n\n return rows;\n }\n\n for (let index = start + 2; index < lines.length; index++) {\n const line = lines[index];\n\n if (line === undefined || line.fenced || !line.text.includes(\"|\")) break;\n\n const at = lineAt(file, line.line);\n const cells = tableCells(line.text);\n\n if (cells.length !== BLOCK_COLUMNS.length) {\n sink.report(\"GR1018\", `the Blocks row has ${cells.length} cells instead of 4.`, at);\n continue;\n }\n\n const [block = \"\", flow = \"\", who = \"\", changesWith = \"\"] = cells;\n\n if (block === \"\") {\n sink.report(\"GR1018\", \"the Blocks row has no block name.\", at);\n continue;\n }\n\n if (!EMPTY_CELL.test(flow) && !FLOW_REF.test(flow)) {\n sink.report(\n \"GR1018\",\n `the Flow cell ${JSON.stringify(flow)} of block \"${block}\" is not <feature>/<flow> or —.`,\n at,\n );\n continue;\n }\n\n if (EMPTY_CELL.test(who)) {\n sink.report(\n \"GR1018\",\n `the \"Who sees it\" cell of block \"${block}\" is empty; write everyone or condition names.`,\n at,\n );\n continue;\n }\n\n const whoItems = who\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\");\n\n rows.push({\n block,\n flow: EMPTY_CELL.test(flow) ? null : flow,\n who: {\n everyone: whoItems.some((item) => item.toLowerCase() === \"everyone\"),\n conditions: whoItems.filter((item) => item.toLowerCase() !== \"everyone\"),\n },\n changesWith: EMPTY_CELL.test(changesWith)\n ? []\n : changesWith\n .split(\";\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\")\n .map((item): WrittenChangesWith => {\n const condition = CONDITION_ITEM.exec(item);\n\n return condition\n ? { condition: condition[1] ?? \"\", text: (condition[2] ?? \"\").trim() }\n : { condition: null, text: item };\n }),\n at,\n });\n }\n\n return rows;\n}\n\n/** `grimoire/apps/<id>/README.md`. */\nexport function parseAppReadme(\n file: string,\n text: string,\n folder: string,\n fallbackType: \"site\" | \"mobile\",\n sink: FindingSink,\n): AppReadme {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"id\", \"type\", \"root\", \"origin\"], \"app README\");\n\n const id = fields.required(\"id\", checks.id);\n\n if (id.value !== \"\" && id.value !== folder) {\n sink.report(\n \"GR1019\",\n `the app id ${JSON.stringify(id.value)} must equal its folder name ${JSON.stringify(folder)}.`,\n id.at,\n );\n }\n\n const root = fields.required(\"root\", checks.folder);\n\n checkHeadings(document, { title: false, required: [\"Conditions\"], optional: [] }, sink);\n\n return {\n id: id.value === \"\" ? { value: folder, at: id.at } : id,\n type: fields.oneOf(\"type\", [\"site\", \"mobile\"] as const, fallbackType),\n root: { value: projectFolder(root.value) ?? root.value, at: root.at },\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n conditions: readListLines(file, findSection(document, \"conditions\")?.lines, \"Conditions\", sink),\n };\n}\n\n/** `grimoire/apps/<app>/layouts/<id>.md`. */\nexport function parseLayout(\n file: string,\n text: string,\n app: string,\n id: string,\n sink: FindingSink,\n): WrittenLayout {\n const document = readDocument(file, text, \"none\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"origin\"], \"a layout\");\n checkHeadings(document, { title: false, required: [\"Blocks\"], optional: [] }, sink);\n\n const blocks = findSection(document, \"blocks\");\n\n return {\n file,\n app,\n id,\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<id>/README.md` or `screens/<id>/README.md`. */\nexport function parsePage(\n file: string,\n text: string,\n app: string,\n type: \"page\" | \"screen\",\n id: string,\n sink: FindingSink,\n): WrittenPage {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys(\n type === \"page\" ? [\"route\", \"layout\", \"origin\"] : [\"route\", \"screen\", \"layout\", \"origin\"],\n type,\n );\n\n const route = fields.scalar(\"route\", { required: type === \"page\", check: checks.route });\n const screen =\n type === \"screen\" ? fields.scalar(\"screen\", { required: false, check: checks.name }) : null;\n\n if (type === \"screen\" && fields.present && route === null && screen === null) {\n sink.report(\n \"GR1003\",\n 'a screen needs the front matter key \"route\" (file-based routing) or \"screen\" (its name in code).',\n lineAt(file, 1),\n );\n }\n\n checkHeadings(\n document,\n { title: true, required: [], optional: [\"Blocks\", \"Also reached from\"] },\n sink,\n );\n\n const blocks = findSection(document, \"blocks\");\n const alsoReachedFrom: WrittenEntryPoint[] = readListLines(\n file,\n findSection(document, \"also reached from\")?.lines,\n \"Also reached from\",\n sink,\n ).map((line) => ({ type: line.name, name: line.text, at: line.at }));\n\n return {\n file,\n app,\n type,\n id,\n route,\n screen,\n layout: fields.scalar(\"layout\", { required: false, check: checks.id }),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n purpose: paragraphAfterTitle(document),\n screenshots: readScreenshots(file, document.body, sink),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n alsoReachedFrom,\n blockFiles: [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<page>/blocks/<id>.md`. */\nexport function parseBlockFile(\n file: string,\n text: string,\n app: string,\n page: string,\n id: string,\n sink: FindingSink,\n): WrittenBlockFile {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"flow\"], \"block file\");\n\n return {\n file,\n app,\n page,\n id,\n flow: fields.scalar(\"flow\", { required: true, check: checks.flowRef }),\n heading: heading(document),\n details: readListLines(file, document.body, \"detail\", sink),\n screenshots: readScreenshots(file, document.body, sink),\n };\n}\n"],"mappings":";;;;;;AA0CA,MAAM,gBAAgB;CAAC;CAAS;CAAQ;CAAe;AAAc;AACrE,MAAM,aAAa;AACnB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,SAAS,QAAQ,UAAmD;CAClE,OAAO,SAAS,QACZ;EAAE,OAAO,SAAS,MAAM;EAAM,IAAI,OAAO,SAAS,MAAM,SAAS,MAAM,IAAI;CAAE,IAC7E;AACN;;AAGA,SAAgB,WAAW,KAAuB;CAChD,IAAI,OAAO,IAAI,KAAK;CAEpB,IAAI,KAAK,WAAW,GAAG,GAAG,OAAO,KAAK,MAAM,CAAC;CAC7C,IAAI,KAAK,SAAS,GAAG,KAAK,CAAC,KAAK,SAAS,KAAK,GAAG,OAAO,KAAK,MAAM,GAAG,EAAE;CAExE,OAAO,KAAK,MAAM,WAAW,CAAC,CAAC,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG,CAAC;AAChF;;;;;;AAOA,SAAgB,iBACd,MACA,SACA,MACmB;CACnB,MAAM,OAA0B,CAAC;CACjC,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,MAAM,WAAW,SAAS,CAAC,KAAK,UAAU,KAAK,KAAK,SAAS,GAAG,CAAC;CAE/E,IAAI,UAAU,IAAI;EAChB,KAAK,OAAO,UAAU,oCAAoC,OAAO,MAAM,QAAQ,IAAI,CAAC;EAEpF,OAAO;CACT;CAEA,MAAM,SAAS,MAAM;CAC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Ac,MAAM,SAAS,MAAM,UAAU,IAAI;EAC1D,aAAa,gBAAgB,MAAM,SAAS,MAAM,IAAI;CACxD;AACF"}
|
package/esm/written/features.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CASE_QUESTIONS } from "../contracts/written.mjs";
|
|
2
|
-
import { checkHeadings, findSection, lineAt, logicalLines, normalizeKey, paragraphAfterTitle, readDocument } from "./markdown.mjs";
|
|
2
|
+
import { checkHeadings, findSection, isImageLine, lineAt, logicalLines, normalizeKey, paragraphAfterTitle, readDocument, readScreenshots, withoutImages } from "./markdown.mjs";
|
|
3
3
|
import { FrontMatterReader, ID, SEP, VERSION, checks, isDate, projectFolder } from "./fields.mjs";
|
|
4
4
|
import { BULLET, bulletLines, readListLines, splitListLine } from "./lists.mjs";
|
|
5
5
|
|
|
@@ -75,6 +75,22 @@ function splitEntryText(text) {
|
|
|
75
75
|
text: rest
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
+
/** `## Why`: the paragraphs of the section, joined with a blank line; `null` when absent or empty. */
|
|
79
|
+
function readWhy(document) {
|
|
80
|
+
const paragraphs = [];
|
|
81
|
+
let open = [];
|
|
82
|
+
const close = () => {
|
|
83
|
+
if (open.length > 0) paragraphs.push(open.join(" "));
|
|
84
|
+
open = [];
|
|
85
|
+
};
|
|
86
|
+
for (const line of findSection(document, "why")?.lines ?? []) {
|
|
87
|
+
const trimmed = line.text.trim();
|
|
88
|
+
if (line.fenced || trimmed === "") close();
|
|
89
|
+
else open.push(trimmed);
|
|
90
|
+
}
|
|
91
|
+
close();
|
|
92
|
+
return paragraphs.length > 0 ? paragraphs.join("\n\n") : null;
|
|
93
|
+
}
|
|
78
94
|
/** `grimoire/features/<id>/README.md`. */
|
|
79
95
|
function parseFeatureReadme(file, text, folder, sink) {
|
|
80
96
|
const document = readDocument(file, text, "required", sink);
|
|
@@ -87,7 +103,8 @@ function parseFeatureReadme(file, text, folder, sink) {
|
|
|
87
103
|
"updated",
|
|
88
104
|
"apps",
|
|
89
105
|
"folders",
|
|
90
|
-
"origin"
|
|
106
|
+
"origin",
|
|
107
|
+
"audience"
|
|
91
108
|
], "feature README");
|
|
92
109
|
const id = fields.required("id", checks.id);
|
|
93
110
|
sameAsName(id, folder, "feature id", sink);
|
|
@@ -110,13 +127,22 @@ function parseFeatureReadme(file, text, folder, sink) {
|
|
|
110
127
|
origin: fields.optionalOneOf("origin", ORIGINS),
|
|
111
128
|
heading: heading(document),
|
|
112
129
|
summary: paragraphAfterTitle(document),
|
|
130
|
+
audience: fields.list("audience", {
|
|
131
|
+
required: false,
|
|
132
|
+
check: checks.text
|
|
133
|
+
}),
|
|
134
|
+
why: readWhy(document),
|
|
113
135
|
flows: [],
|
|
114
136
|
relations: []
|
|
115
137
|
};
|
|
116
138
|
checkHeadings(document, {
|
|
117
139
|
title: true,
|
|
118
140
|
required: [],
|
|
119
|
-
optional: [
|
|
141
|
+
optional: [
|
|
142
|
+
"Why",
|
|
143
|
+
"Flows",
|
|
144
|
+
"Affects and affected by"
|
|
145
|
+
]
|
|
120
146
|
}, sink);
|
|
121
147
|
for (const flow of readListLines(file, findSection(document, "flows")?.lines, "Flows", sink)) {
|
|
122
148
|
if (!ID.test(flow.name)) {
|
|
@@ -280,6 +306,82 @@ function parseSteps(file, document, sink) {
|
|
|
280
306
|
if (first !== void 0) sink.report("GR1010", `step ${first.number} should be step ${wrong + 1}; number the steps 1, 2, 3 in order.`, lineAt(file, first.line));
|
|
281
307
|
return steps;
|
|
282
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* `## Story`: numbered sentences in the user's words. Indented lines continue
|
|
311
|
+
* the item, image lines attach screenshots. GR1008 for any other line, GR1010
|
|
312
|
+
* for numbers out of order.
|
|
313
|
+
*/
|
|
314
|
+
function parseStory(file, document, sink) {
|
|
315
|
+
const story = [];
|
|
316
|
+
const numbers = [];
|
|
317
|
+
let open = null;
|
|
318
|
+
let continuing = false;
|
|
319
|
+
const finish = () => {
|
|
320
|
+
if (open !== null) open.step.text = open.text.join(" ");
|
|
321
|
+
open = null;
|
|
322
|
+
};
|
|
323
|
+
const attach = (line) => {
|
|
324
|
+
open?.step.screenshots.push(...readScreenshots(file, [line], sink));
|
|
325
|
+
};
|
|
326
|
+
for (const line of findSection(document, "story")?.lines ?? []) {
|
|
327
|
+
const trimmed = line.text.trim();
|
|
328
|
+
const at = lineAt(file, line.line);
|
|
329
|
+
if (line.fenced) {
|
|
330
|
+
continuing = false;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (trimmed === "") {
|
|
334
|
+
continuing = false;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const numbered = NUMBERED.exec(trimmed);
|
|
338
|
+
if (numbered) {
|
|
339
|
+
finish();
|
|
340
|
+
const sentence = withoutImages(trimmed.replace(NUMBERED, ""));
|
|
341
|
+
if (sentence === "") {
|
|
342
|
+
sink.report("GR1008", `the story line ${JSON.stringify(trimmed)} is not \`<n>. <sentence>\`.`, at);
|
|
343
|
+
continuing = false;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const number = Number(numbered[1]);
|
|
347
|
+
const step = {
|
|
348
|
+
index: number,
|
|
349
|
+
text: sentence,
|
|
350
|
+
screenshots: [],
|
|
351
|
+
at
|
|
352
|
+
};
|
|
353
|
+
numbers.push({
|
|
354
|
+
number,
|
|
355
|
+
line: line.line
|
|
356
|
+
});
|
|
357
|
+
story.push(step);
|
|
358
|
+
open = {
|
|
359
|
+
step,
|
|
360
|
+
text: [sentence]
|
|
361
|
+
};
|
|
362
|
+
continuing = true;
|
|
363
|
+
attach(line);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (isImageLine(trimmed)) {
|
|
367
|
+
if (open === null) sink.report("GR1008", `the story line ${JSON.stringify(trimmed)} is an image before any story step.`, at);
|
|
368
|
+
else attach(line);
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (open !== null && continuing && /^[ \t]/.test(line.text)) {
|
|
372
|
+
const more = withoutImages(trimmed);
|
|
373
|
+
if (more !== "") open.text.push(more);
|
|
374
|
+
attach(line);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
sink.report("GR1008", `the story line ${JSON.stringify(trimmed)} is not \`<n>. <sentence>\`.`, at);
|
|
378
|
+
}
|
|
379
|
+
finish();
|
|
380
|
+
const wrong = numbers.findIndex((entry, position) => entry.number !== position + 1);
|
|
381
|
+
const first = numbers[wrong];
|
|
382
|
+
if (first !== void 0) sink.report("GR1010", `story step ${first.number} should be story step ${wrong + 1}; number the story steps 1, 2, 3 in order.`, lineAt(file, first.line));
|
|
383
|
+
return story;
|
|
384
|
+
}
|
|
283
385
|
function parseCases(file, document, sink) {
|
|
284
386
|
const cases = [];
|
|
285
387
|
for (const line of bulletLines(findSection(document, "cases")?.lines ?? [])) {
|
|
@@ -289,11 +391,14 @@ function parseCases(file, document, sink) {
|
|
|
289
391
|
continue;
|
|
290
392
|
}
|
|
291
393
|
const question = normalizeKey(split.name);
|
|
394
|
+
const suffix = CRITERIA_SUFFIX.exec(split.text);
|
|
395
|
+
const answer = suffix ? split.text.slice(0, suffix.index).trimEnd() : split.text;
|
|
292
396
|
cases.push({
|
|
293
397
|
question,
|
|
294
398
|
fixed: CASE_QUESTIONS.includes(question),
|
|
295
|
-
answer
|
|
296
|
-
doesNotApply: /^does not apply\b/i.test(
|
|
399
|
+
answer,
|
|
400
|
+
doesNotApply: /^does not apply\b/i.test(answer),
|
|
401
|
+
criteria: suffix ? (suffix[1] ?? "").split(",").map((criterion) => criterion.trim()) : [],
|
|
297
402
|
at: lineAt(file, line.line)
|
|
298
403
|
});
|
|
299
404
|
}
|
|
@@ -348,6 +453,8 @@ function parseFlow(file, text, feature, name, sink) {
|
|
|
348
453
|
who: fields.required("who", checks.text),
|
|
349
454
|
origin: fields.optionalOneOf("origin", ORIGINS),
|
|
350
455
|
heading: heading(document),
|
|
456
|
+
summary: paragraphAfterTitle(document),
|
|
457
|
+
story: [],
|
|
351
458
|
steps: [],
|
|
352
459
|
differs: [],
|
|
353
460
|
cases: [],
|
|
@@ -362,8 +469,14 @@ function parseFlow(file, text, feature, name, sink) {
|
|
|
362
469
|
"Cases",
|
|
363
470
|
"Acceptance criteria"
|
|
364
471
|
],
|
|
365
|
-
optional: [
|
|
472
|
+
optional: [
|
|
473
|
+
"Story",
|
|
474
|
+
"Differs by app",
|
|
475
|
+
"Not handled"
|
|
476
|
+
]
|
|
366
477
|
}, sink);
|
|
478
|
+
if (flow.summary === null) sink.report("GR1030", "the flow has no summary; write one or two sentences under the title.", lineAt(file, document.title?.line ?? document.bodyStartLine));
|
|
479
|
+
flow.story = parseStory(file, document, sink);
|
|
367
480
|
flow.steps = parseSteps(file, document, sink);
|
|
368
481
|
flow.differs = readListLines(file, findSection(document, "differs by app")?.lines, "Differs by app", sink);
|
|
369
482
|
flow.cases = parseCases(file, document, sink);
|