@warlock.js/grimoire 0.0.0-stage → 5.56.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 +52 -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 +42 -0
- package/esm/devtools/index.d.mts.map +1 -0
- package/esm/devtools/index.mjs +103 -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,70 @@
|
|
|
1
|
+
import { GRIMOIRE_PATHS } from "../paths/index.mjs";
|
|
2
|
+
import { openGrimoire } from "../workspace/index.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { stat } from "node:fs/promises";
|
|
5
|
+
|
|
6
|
+
//#region ../../packages/grimoire/src/devtools/snapshot-source.ts
|
|
7
|
+
/**
|
|
8
|
+
* Where the panel's routes get the snapshot: opened once with
|
|
9
|
+
* `routes: "cached"` (a devtools request never boots the app), kept in
|
|
10
|
+
* memory, and opened again when the book manifest changed or the copy is a
|
|
11
|
+
* few seconds old (the written files change while an agent works).
|
|
12
|
+
* Concurrent requests share one open. The panel passes `write: true`, so the
|
|
13
|
+
* generated book stays current and the next open is incremental; with
|
|
14
|
+
* `write: false` a stored book behind the sources is rebuilt in memory on
|
|
15
|
+
* every open, and a slow open widens the reuse window.
|
|
16
|
+
*/
|
|
17
|
+
async function manifestStamp(root) {
|
|
18
|
+
try {
|
|
19
|
+
return (await stat(path.join(root, ...GRIMOIRE_PATHS.bookManifest.split("/")))).mtimeMs;
|
|
20
|
+
} catch {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function loadAdapter(option) {
|
|
25
|
+
if (option === void 0) {
|
|
26
|
+
const { createWarlockAdapter } = await import("../warlock/index.mjs");
|
|
27
|
+
return createWarlockAdapter();
|
|
28
|
+
}
|
|
29
|
+
return typeof option === "function" ? option() : option;
|
|
30
|
+
}
|
|
31
|
+
/** Create the source for the project at `root`. */
|
|
32
|
+
function createSnapshotSource(root, options = {}) {
|
|
33
|
+
let cached = null;
|
|
34
|
+
let opening = null;
|
|
35
|
+
const reuseFor = (took) => options.ttlMs ?? Math.max(2e3, took * 5);
|
|
36
|
+
async function open() {
|
|
37
|
+
const started = Date.now();
|
|
38
|
+
const adapter = await loadAdapter(options.adapter);
|
|
39
|
+
const snapshot = await openGrimoire(root, adapter, {
|
|
40
|
+
routes: "cached",
|
|
41
|
+
write: options.write ?? false
|
|
42
|
+
});
|
|
43
|
+
const at = Date.now();
|
|
44
|
+
cached = {
|
|
45
|
+
snapshot,
|
|
46
|
+
at,
|
|
47
|
+
stamp: await manifestStamp(root),
|
|
48
|
+
took: at - started
|
|
49
|
+
};
|
|
50
|
+
return snapshot;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
async get() {
|
|
54
|
+
if (opening !== null) return opening;
|
|
55
|
+
if (cached !== null && Date.now() - cached.at < reuseFor(cached.took) && await manifestStamp(root) === cached.stamp) return cached.snapshot;
|
|
56
|
+
if (opening !== null) return opening;
|
|
57
|
+
opening = open().finally(() => {
|
|
58
|
+
opening = null;
|
|
59
|
+
});
|
|
60
|
+
return opening;
|
|
61
|
+
},
|
|
62
|
+
invalidate() {
|
|
63
|
+
cached = null;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { createSnapshotSource };
|
|
70
|
+
//# sourceMappingURL=snapshot-source.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-source.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/snapshot-source.ts"],"sourcesContent":["/**\n * Where the panel's routes get the snapshot: opened once with\n * `routes: \"cached\"` (a devtools request never boots the app), kept in\n * memory, and opened again when the book manifest changed or the copy is a\n * few seconds old (the written files change while an agent works).\n * Concurrent requests share one open. The panel passes `write: true`, so the\n * generated book stays current and the next open is incremental; with\n * `write: false` a stored book behind the sources is rebuilt in memory on\n * every open, and a slow open widens the reuse window.\n */\nimport { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { openGrimoire } from \"../workspace\";\n\n/** Options of the panel's snapshot source. */\nexport type SnapshotSourceOptions = {\n /** The adapter, or a function that loads it. Default: the Warlock adapter, imported on first use. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long a snapshot is reused when the manifest did not change (ms).\n * Default: 2000, or five times as long as the last open took when that is\n * longer, so a slow open (a large app whose stored book is behind its\n * sources) is not repeated on every view.\n */\n ttlMs?: number;\n /** Let `openGrimoire` write the generated book and collected files (never agent-written files). Default `false`; the devtools panel passes `true`. */\n write?: boolean;\n};\n\n/** A cached, shared snapshot of one project. */\nexport type SnapshotSource = {\n get(): Promise<GrimoireSnapshot>;\n /** Forget the cached snapshot; the next `get()` opens again. */\n invalidate(): void;\n};\n\nasync function manifestStamp(root: string): Promise<number> {\n try {\n return (await stat(path.join(root, ...GRIMOIRE_PATHS.bookManifest.split(\"/\")))).mtimeMs;\n } catch {\n return 0;\n }\n}\n\nasync function loadAdapter(option: SnapshotSourceOptions[\"adapter\"]): Promise<BookAdapter> {\n if (option === undefined) {\n const { createWarlockAdapter } = await import(\"../warlock\");\n\n return createWarlockAdapter();\n }\n\n return typeof option === \"function\" ? option() : option;\n}\n\n/** Create the source for the project at `root`. */\nexport function createSnapshotSource(\n root: string,\n options: SnapshotSourceOptions = {},\n): SnapshotSource {\n let cached: { snapshot: GrimoireSnapshot; at: number; stamp: number; took: number } | null = null;\n let opening: Promise<GrimoireSnapshot> | null = null;\n\n const reuseFor = (took: number): number => options.ttlMs ?? Math.max(2000, took * 5);\n\n async function open(): Promise<GrimoireSnapshot> {\n const started = Date.now();\n const adapter = await loadAdapter(options.adapter);\n const snapshot = await openGrimoire(root, adapter, {\n routes: \"cached\",\n write: options.write ?? false,\n });\n\n const at = Date.now();\n\n cached = { snapshot, at, stamp: await manifestStamp(root), took: at - started };\n\n return snapshot;\n }\n\n return {\n async get() {\n if (opening !== null) return opening;\n\n if (\n cached !== null &&\n Date.now() - cached.at < reuseFor(cached.took) &&\n (await manifestStamp(root)) === cached.stamp\n ) {\n return cached.snapshot;\n }\n\n // Another request may have started an open while this one read the manifest.\n if (opening !== null) return opening;\n\n opening = open().finally(() => {\n opening = null;\n });\n\n return opening;\n },\n invalidate() {\n cached = null;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,eAAe,cAAc,MAA+B;CAC1D,IAAI;EACF,QAAQ,MAAM,KAAK,KAAK,KAAK,MAAM,GAAG,eAAe,aAAa,MAAM,GAAG,CAAC,CAAC,EAAC,CAAE;CAClF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAe,YAAY,QAAgE;CACzF,IAAI,WAAW,QAAW;EACxB,MAAM,EAAE,yBAAyB,MAAM,OAAO;EAE9C,OAAO,qBAAqB;CAC9B;CAEA,OAAO,OAAO,WAAW,aAAa,OAAO,IAAI;AACnD;;AAGA,SAAgB,qBACd,MACA,UAAiC,CAAC,GAClB;CAChB,IAAI,SAAyF;CAC7F,IAAI,UAA4C;CAEhD,MAAM,YAAY,SAAyB,QAAQ,SAAS,KAAK,IAAI,KAAM,OAAO,CAAC;CAEnF,eAAe,OAAkC;EAC/C,MAAM,UAAU,KAAK,IAAI;EACzB,MAAM,UAAU,MAAM,YAAY,QAAQ,OAAO;EACjD,MAAM,WAAW,MAAM,aAAa,MAAM,SAAS;GACjD,QAAQ;GACR,OAAO,QAAQ,SAAS;EAC1B,CAAC;EAED,MAAM,KAAK,KAAK,IAAI;EAEpB,SAAS;GAAE;GAAU;GAAI,OAAO,MAAM,cAAc,IAAI;GAAG,MAAM,KAAK;EAAQ;EAE9E,OAAO;CACT;CAEA,OAAO;EACL,MAAM,MAAM;GACV,IAAI,YAAY,MAAM,OAAO;GAE7B,IACE,WAAW,QACX,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,OAAO,IAAI,KAC5C,MAAM,cAAc,IAAI,MAAO,OAAO,OAEvC,OAAO,OAAO;GAIhB,IAAI,YAAY,MAAM,OAAO;GAE7B,UAAU,KAAK,CAAC,CAAC,cAAc;IAC7B,UAAU;GACZ,CAAC;GAED,OAAO;EACT;EACA,aAAa;GACX,SAAS;EACX;CACF;AACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GrimoireFinding } from "../contracts/findings.mjs";
|
|
2
|
+
//#region ../../packages/grimoire/src/front-matter/index.d.ts
|
|
3
|
+
/** A front matter value: a scalar or a list. */
|
|
4
|
+
export type FrontMatterValue = string | string[];
|
|
5
|
+
/** One key with its value and where it was written. */
|
|
6
|
+
export type FrontMatterField = {
|
|
7
|
+
key: string;
|
|
8
|
+
value: FrontMatterValue;
|
|
9
|
+
/** 1-based line of the key. */
|
|
10
|
+
line: number;
|
|
11
|
+
/** 1-based line of each list item (the key's line for an inline list). */
|
|
12
|
+
itemLines: number[];
|
|
13
|
+
};
|
|
14
|
+
/** A file split into its front matter and body. */
|
|
15
|
+
export type FrontMatterResult = {
|
|
16
|
+
/** `null` when the file does not start with `---`. */
|
|
17
|
+
fields: Map<string, FrontMatterField> | null;
|
|
18
|
+
/** Everything after the closing `---` (or the whole text without front matter). */
|
|
19
|
+
body: string;
|
|
20
|
+
/** 1-based line of the body's first line in the file. */
|
|
21
|
+
bodyStartLine: number;
|
|
22
|
+
/** `GR1002` findings for lines that could not be read. */
|
|
23
|
+
errors: GrimoireFinding[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Split `text` into front matter and body.
|
|
27
|
+
*
|
|
28
|
+
* @param text The file's content.
|
|
29
|
+
* @param file Project-relative path, used in the findings' locations.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readFrontMatter(text: string, file: string): FrontMatterResult;
|
|
32
|
+
//#endregion
|
|
33
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/front-matter/index.ts"],"mappings":";;;YA0BY;;YAGA;EACV;EACA,OAAO;;EAEP;;EAEA;;;YAIU;;EAEV,QAAQ,YAAY;;EAEpB;;EAEA;;EAEA,QAAQ;;;;;;;;wBAmCM,gBAAgB,cAAc,eAAe"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createFinding } from "../codes/index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/grimoire/src/front-matter/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Reads the restricted front matter of a written file. The grammar, and
|
|
6
|
+
* nothing more:
|
|
7
|
+
*
|
|
8
|
+
* ```md
|
|
9
|
+
* ---
|
|
10
|
+
* id: catalog
|
|
11
|
+
* title: "Product catalog"
|
|
12
|
+
* apps: [web-client, mobile]
|
|
13
|
+
* folders:
|
|
14
|
+
* - src/app/catalog
|
|
15
|
+
* - src/web/$sites/client/products
|
|
16
|
+
* ---
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* - The file starts with a `---` line (after an optional BOM); the block ends
|
|
20
|
+
* at the next `---` line.
|
|
21
|
+
* - Each line is `key: value`. Keys are lower-case letters, digits, `-` and `_`.
|
|
22
|
+
* - A value is a scalar (quotes around it are removed), an inline list
|
|
23
|
+
* `[a, b]`, or empty with `- item` lines following it (a block list).
|
|
24
|
+
* - Blank lines are ignored. Anything else is an error with its line.
|
|
25
|
+
*/
|
|
26
|
+
const KEY_LINE = /^([a-z][a-z0-9_-]*):(?:\s+(.*?))?\s*$/;
|
|
27
|
+
const ITEM_LINE = /^\s*-\s+(.*?)\s*$/;
|
|
28
|
+
const FENCE = /^---\s*$/;
|
|
29
|
+
function unquote(value) {
|
|
30
|
+
const trimmed = value.trim();
|
|
31
|
+
if (trimmed.length >= 2 && (trimmed.startsWith("\"") && trimmed.endsWith("\"") || trimmed.startsWith("'") && trimmed.endsWith("'"))) return trimmed.slice(1, -1);
|
|
32
|
+
return trimmed;
|
|
33
|
+
}
|
|
34
|
+
function inlineList(value) {
|
|
35
|
+
if (!value.startsWith("[") || !value.endsWith("]")) return void 0;
|
|
36
|
+
const inner = value.slice(1, -1).trim();
|
|
37
|
+
return inner === "" ? [] : inner.split(",").map(unquote);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Split `text` into front matter and body.
|
|
41
|
+
*
|
|
42
|
+
* @param text The file's content.
|
|
43
|
+
* @param file Project-relative path, used in the findings' locations.
|
|
44
|
+
*/
|
|
45
|
+
function readFrontMatter(text, file) {
|
|
46
|
+
const lines = text.replace(/^/, "").split(/\r?\n/);
|
|
47
|
+
const errors = [];
|
|
48
|
+
const fail = (line, message) => {
|
|
49
|
+
errors.push(createFinding({
|
|
50
|
+
code: "GR1002",
|
|
51
|
+
message,
|
|
52
|
+
at: {
|
|
53
|
+
file,
|
|
54
|
+
line,
|
|
55
|
+
column: null
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
};
|
|
59
|
+
if (lines[0] === void 0 || !FENCE.test(lines[0])) return {
|
|
60
|
+
fields: null,
|
|
61
|
+
body: lines.join("\n"),
|
|
62
|
+
bodyStartLine: 1,
|
|
63
|
+
errors
|
|
64
|
+
};
|
|
65
|
+
const end = lines.findIndex((line, index) => index > 0 && FENCE.test(line));
|
|
66
|
+
if (end === -1) {
|
|
67
|
+
fail(1, "the front matter starts with `---` but is never closed by another `---` line.");
|
|
68
|
+
return {
|
|
69
|
+
fields: null,
|
|
70
|
+
body: "",
|
|
71
|
+
bodyStartLine: lines.length + 1,
|
|
72
|
+
errors
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const fields = /* @__PURE__ */ new Map();
|
|
76
|
+
let open;
|
|
77
|
+
for (let index = 1; index < end; index++) {
|
|
78
|
+
const raw = lines[index] ?? "";
|
|
79
|
+
const lineNumber = index + 1;
|
|
80
|
+
if (raw.trim() === "") continue;
|
|
81
|
+
const item = ITEM_LINE.exec(raw);
|
|
82
|
+
if (item && open && Array.isArray(open.value)) {
|
|
83
|
+
open.value.push(unquote(item[1] ?? ""));
|
|
84
|
+
open.itemLines.push(lineNumber);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const match = KEY_LINE.exec(raw);
|
|
88
|
+
if (!match) {
|
|
89
|
+
fail(lineNumber, `front matter line ${JSON.stringify(raw.trim())} is not \`key: value\`.`);
|
|
90
|
+
open = void 0;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const key = match[1] ?? "";
|
|
94
|
+
const rawValue = (match[2] ?? "").trim();
|
|
95
|
+
if (fields.has(key)) {
|
|
96
|
+
fail(lineNumber, `front matter key "${key}" is written twice.`);
|
|
97
|
+
open = void 0;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const list = inlineList(rawValue);
|
|
101
|
+
const field = rawValue === "" ? {
|
|
102
|
+
key,
|
|
103
|
+
value: [],
|
|
104
|
+
line: lineNumber,
|
|
105
|
+
itemLines: []
|
|
106
|
+
} : list ? {
|
|
107
|
+
key,
|
|
108
|
+
value: list,
|
|
109
|
+
line: lineNumber,
|
|
110
|
+
itemLines: list.map(() => lineNumber)
|
|
111
|
+
} : {
|
|
112
|
+
key,
|
|
113
|
+
value: unquote(rawValue),
|
|
114
|
+
line: lineNumber,
|
|
115
|
+
itemLines: []
|
|
116
|
+
};
|
|
117
|
+
fields.set(key, field);
|
|
118
|
+
open = rawValue === "" ? field : void 0;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
fields,
|
|
122
|
+
body: lines.slice(end + 1).join("\n"),
|
|
123
|
+
bodyStartLine: end + 2,
|
|
124
|
+
errors
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
export { readFrontMatter };
|
|
130
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/front-matter/index.ts"],"sourcesContent":["/**\n * Reads the restricted front matter of a written file. The grammar, and\n * nothing more:\n *\n * ```md\n * ---\n * id: catalog\n * title: \"Product catalog\"\n * apps: [web-client, mobile]\n * folders:\n * - src/app/catalog\n * - src/web/$sites/client/products\n * ---\n * ```\n *\n * - The file starts with a `---` line (after an optional BOM); the block ends\n * at the next `---` line.\n * - Each line is `key: value`. Keys are lower-case letters, digits, `-` and `_`.\n * - A value is a scalar (quotes around it are removed), an inline list\n * `[a, b]`, or empty with `- item` lines following it (a block list).\n * - Blank lines are ignored. Anything else is an error with its line.\n */\nimport { createFinding } from \"../codes\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\n\n/** A front matter value: a scalar or a list. */\nexport type FrontMatterValue = string | string[];\n\n/** One key with its value and where it was written. */\nexport type FrontMatterField = {\n key: string;\n value: FrontMatterValue;\n /** 1-based line of the key. */\n line: number;\n /** 1-based line of each list item (the key's line for an inline list). */\n itemLines: number[];\n};\n\n/** A file split into its front matter and body. */\nexport type FrontMatterResult = {\n /** `null` when the file does not start with `---`. */\n fields: Map<string, FrontMatterField> | null;\n /** Everything after the closing `---` (or the whole text without front matter). */\n body: string;\n /** 1-based line of the body's first line in the file. */\n bodyStartLine: number;\n /** `GR1002` findings for lines that could not be read. */\n errors: GrimoireFinding[];\n};\n\nconst KEY_LINE = /^([a-z][a-z0-9_-]*):(?:\\s+(.*?))?\\s*$/;\nconst ITEM_LINE = /^\\s*-\\s+(.*?)\\s*$/;\nconst FENCE = /^---\\s*$/;\n\nfunction unquote(value: string): string {\n const trimmed = value.trim();\n\n if (\n trimmed.length >= 2 &&\n ((trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\")))\n ) {\n return trimmed.slice(1, -1);\n }\n\n return trimmed;\n}\n\nfunction inlineList(value: string): string[] | undefined {\n if (!value.startsWith(\"[\") || !value.endsWith(\"]\")) return undefined;\n\n const inner = value.slice(1, -1).trim();\n\n return inner === \"\" ? [] : inner.split(\",\").map(unquote);\n}\n\n/**\n * Split `text` into front matter and body.\n *\n * @param text The file's content.\n * @param file Project-relative path, used in the findings' locations.\n */\nexport function readFrontMatter(text: string, file: string): FrontMatterResult {\n const lines = text.replace(/^/, \"\").split(/\\r?\\n/);\n const errors: GrimoireFinding[] = [];\n const fail = (line: number, message: string): void => {\n errors.push(createFinding({ code: \"GR1002\", message, at: { file, line, column: null } }));\n };\n\n if (lines[0] === undefined || !FENCE.test(lines[0])) {\n return { fields: null, body: lines.join(\"\\n\"), bodyStartLine: 1, errors };\n }\n\n const end = lines.findIndex((line, index) => index > 0 && FENCE.test(line));\n\n if (end === -1) {\n fail(1, \"the front matter starts with `---` but is never closed by another `---` line.\");\n\n return { fields: null, body: \"\", bodyStartLine: lines.length + 1, errors };\n }\n\n const fields = new Map<string, FrontMatterField>();\n let open: FrontMatterField | undefined;\n\n for (let index = 1; index < end; index++) {\n const raw = lines[index] ?? \"\";\n const lineNumber = index + 1;\n\n if (raw.trim() === \"\") continue;\n\n const item = ITEM_LINE.exec(raw);\n\n if (item && open && Array.isArray(open.value)) {\n open.value.push(unquote(item[1] ?? \"\"));\n open.itemLines.push(lineNumber);\n continue;\n }\n\n const match = KEY_LINE.exec(raw);\n\n if (!match) {\n fail(lineNumber, `front matter line ${JSON.stringify(raw.trim())} is not \\`key: value\\`.`);\n open = undefined;\n continue;\n }\n\n const key = match[1] ?? \"\";\n const rawValue = (match[2] ?? \"\").trim();\n\n if (fields.has(key)) {\n fail(lineNumber, `front matter key \"${key}\" is written twice.`);\n open = undefined;\n continue;\n }\n\n const list = inlineList(rawValue);\n const field: FrontMatterField =\n rawValue === \"\"\n ? { key, value: [], line: lineNumber, itemLines: [] }\n : list\n ? { key, value: list, line: lineNumber, itemLines: list.map(() => lineNumber) }\n : { key, value: unquote(rawValue), line: lineNumber, itemLines: [] };\n\n fields.set(key, field);\n open = rawValue === \"\" ? field : undefined;\n }\n\n return {\n fields,\n body: lines.slice(end + 1).join(\"\\n\"),\n bodyStartLine: end + 2,\n errors,\n };\n}\n\n/** A field's value as a string; a list is joined with `, `. `undefined` when absent. */\nexport function frontMatterString(\n fields: Map<string, FrontMatterField> | null,\n key: string,\n): string | undefined {\n const field = fields?.get(key);\n\n if (!field) return undefined;\n\n return Array.isArray(field.value) ? field.value.join(\", \") : field.value;\n}\n\n/** A field's value as a list; a scalar becomes a one-item list. `[]` when absent. */\nexport function frontMatterList(\n fields: Map<string, FrontMatterField> | null,\n key: string,\n): string[] {\n const field = fields?.get(key);\n\n if (!field) return [];\n\n return Array.isArray(field.value) ? [...field.value] : field.value === \"\" ? [] : [field.value];\n}\n"],"mappings":";;;;;;;;;;;;;;;;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/index.d.ts
|
|
3
|
+
/** Files indexed by path, for the walks below. */
|
|
4
|
+
export type FileGraph = ReadonlyMap<string, Pick<BookFile, "file" | "imports" | "importedBy">>;
|
|
5
|
+
/** Index files by path. */
|
|
6
|
+
export declare function fileGraph(files: readonly Pick<BookFile, "file" | "imports" | "importedBy">[]): FileGraph;
|
|
7
|
+
/**
|
|
8
|
+
* The start files and every project file they import, transitively, sorted.
|
|
9
|
+
* Files not in the graph are left out. Cycles are walked once.
|
|
10
|
+
*/
|
|
11
|
+
export declare function importClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
12
|
+
/** The start files and every project file that imports them, transitively, sorted. */
|
|
13
|
+
export declare function importerClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
14
|
+
//#endregion
|
|
15
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"mappings":";;;YAQY,YAAY,oBAAoB,KAAK;;wBAGjC,UACd,gBAAgB,KAAK,iDACpB;;;;;wBA4Ba,cAAc,OAAO,WAAW;;wBAOhC,gBAAgB,OAAO,WAAW"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region ../../packages/grimoire/src/graph/index.ts
|
|
2
|
+
/** Index files by path. */
|
|
3
|
+
function fileGraph(files) {
|
|
4
|
+
return new Map(files.map((file) => [file.file, file]));
|
|
5
|
+
}
|
|
6
|
+
function walk(graph, start, next) {
|
|
7
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8
|
+
const pending = [...start];
|
|
9
|
+
while (pending.length > 0) {
|
|
10
|
+
const current = pending.pop();
|
|
11
|
+
if (current === void 0 || seen.has(current) || !graph.has(current)) continue;
|
|
12
|
+
seen.add(current);
|
|
13
|
+
pending.push(...next(current));
|
|
14
|
+
}
|
|
15
|
+
return [...seen].sort();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The start files and every project file they import, transitively, sorted.
|
|
19
|
+
* Files not in the graph are left out. Cycles are walked once.
|
|
20
|
+
*/
|
|
21
|
+
function importClosure(graph, start) {
|
|
22
|
+
return walk(graph, start, (file) => (graph.get(file)?.imports ?? []).flatMap((entry) => entry.file === null ? [] : [entry.file]));
|
|
23
|
+
}
|
|
24
|
+
/** The start files and every project file that imports them, transitively, sorted. */
|
|
25
|
+
function importerClosure(graph, start) {
|
|
26
|
+
return walk(graph, start, (file) => [...graph.get(file)?.importedBy ?? []]);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The package name of a bare import specifier (`@warlock.js/core/tooling` →
|
|
30
|
+
* `@warlock.js/core`, `dayjs/plugin/utc` → `dayjs`), or `null` for a relative
|
|
31
|
+
* path, a `node:` builtin or an alias that starts with a path character.
|
|
32
|
+
*/
|
|
33
|
+
function packageNameOf(specifier) {
|
|
34
|
+
if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("node:")) return null;
|
|
35
|
+
const parts = specifier.split("/");
|
|
36
|
+
if (specifier.startsWith("@")) return parts.length >= 2 && parts[1] ? `${parts[0]}/${parts[1]}` : null;
|
|
37
|
+
return parts[0] || null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { fileGraph, importClosure, importerClosure, packageNameOf };
|
|
42
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"sourcesContent":["/**\n * Walks over the import graph of the book's files. Shared by the book maps\n * (files behind a step), `scry --route` (files behind a handler) and\n * `scry --impact` (files that reach a file).\n */\nimport type { BookFile } from \"../contracts/adapter\";\n\n/** Files indexed by path, for the walks below. */\nexport type FileGraph = ReadonlyMap<string, Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">>;\n\n/** Index files by path. */\nexport function fileGraph(\n files: readonly Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">[],\n): FileGraph {\n return new Map(files.map((file) => [file.file, file]));\n}\n\nfunction walk(\n graph: FileGraph,\n start: readonly string[],\n next: (file: string) => string[],\n): string[] {\n const seen = new Set<string>();\n const pending = [...start];\n\n while (pending.length > 0) {\n const current = pending.pop();\n\n if (current === undefined || seen.has(current) || !graph.has(current)) continue;\n\n seen.add(current);\n pending.push(...next(current));\n }\n\n return [...seen].sort();\n}\n\n/**\n * The start files and every project file they import, transitively, sorted.\n * Files not in the graph are left out. Cycles are walked once.\n */\nexport function importClosure(graph: FileGraph, start: readonly string[]): string[] {\n return walk(graph, start, (file) =>\n (graph.get(file)?.imports ?? []).flatMap((entry) => (entry.file === null ? [] : [entry.file])),\n );\n}\n\n/** The start files and every project file that imports them, transitively, sorted. */\nexport function importerClosure(graph: FileGraph, start: readonly string[]): string[] {\n return walk(graph, start, (file) => [...(graph.get(file)?.importedBy ?? [])]);\n}\n\n/**\n * The package name of a bare import specifier (`@warlock.js/core/tooling` →\n * `@warlock.js/core`, `dayjs/plugin/utc` → `dayjs`), or `null` for a relative\n * path, a `node:` builtin or an alias that starts with a path character.\n */\nexport function packageNameOf(specifier: string): string | null {\n if (specifier.startsWith(\".\") || specifier.startsWith(\"/\") || specifier.startsWith(\"node:\")) {\n return null;\n }\n\n const parts = specifier.split(\"/\");\n\n if (specifier.startsWith(\"@\")) {\n return parts.length >= 2 && parts[1] ? `${parts[0]}/${parts[1]}` : null;\n }\n\n return parts[0] || null;\n}\n"],"mappings":";;AAWA,SAAgB,UACd,OACW;CACX,OAAO,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC;AACvD;AAEA,SAAS,KACP,OACA,OACA,MACU;CACV,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,UAAU,CAAC,GAAG,KAAK;CAEzB,OAAO,QAAQ,SAAS,GAAG;EACzB,MAAM,UAAU,QAAQ,IAAI;EAE5B,IAAI,YAAY,UAAa,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,IAAI,OAAO,GAAG;EAEvE,KAAK,IAAI,OAAO;EAChB,QAAQ,KAAK,GAAG,KAAK,OAAO,CAAC;CAC/B;CAEA,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK;AACxB;;;;;AAMA,SAAgB,cAAc,OAAkB,OAAoC;CAClF,OAAO,KAAK,OAAO,QAAQ,UACxB,MAAM,IAAI,IAAI,CAAC,EAAE,WAAW,CAAC,EAAC,CAAE,SAAS,UAAW,MAAM,SAAS,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAE,CAC/F;AACF;;AAGA,SAAgB,gBAAgB,OAAkB,OAAoC;CACpF,OAAO,KAAK,OAAO,QAAQ,SAAS,CAAC,GAAI,MAAM,IAAI,IAAI,CAAC,EAAE,cAAc,CAAC,CAAE,CAAC;AAC9E;;;;;;AAOA,SAAgB,cAAc,WAAkC;CAC9D,IAAI,UAAU,WAAW,GAAG,KAAK,UAAU,WAAW,GAAG,KAAK,UAAU,WAAW,OAAO,GACxF,OAAO;CAGT,MAAM,QAAQ,UAAU,MAAM,GAAG;CAEjC,IAAI,UAAU,WAAW,GAAG,GAC1B,OAAO,MAAM,UAAU,KAAK,MAAM,KAAK,GAAG,MAAM,GAAG,GAAG,MAAM,OAAO;CAGrE,OAAO,MAAM,MAAM;AACrB"}
|
package/esm/index.d.mts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BookAdapter, BookExport, BookFacts, BookFile, BookFileType, BookImport, BookMobileApp, BookNamedThing, BookNamedType, BookPage, BookPageLink, BookRoute, BookScreen, BookSite } from "./contracts/adapter.mjs";
|
|
2
|
+
import { Located, SourceLocation } from "./contracts/location.mjs";
|
|
3
|
+
import { GrimoireCheckReport, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireFinding, GrimoireFindingInput, GrimoireSeverity, RouteFreshness } from "./contracts/findings.mjs";
|
|
4
|
+
import { BOOK_SCHEMA_VERSION, BookAnnotations, BookEntry, BookFactsCache, BookManifest, BookManifestFile, BookMobileScreensFile, BookModuleSummary, BookRouteRef, BookRoutesFile, BookSitePagesFile, BuildBookOptions, BuildBookResult, LoadedBook, WriteBookResult } from "./contracts/book.mjs";
|
|
5
|
+
import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CriterionId, FeatureVersion, FlowRef, StepType, TaskStatus, TaskType, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenStatus, WrittenStep, WrittenTask, WrittenVersionBrief, WrittenWho } from "./contracts/written.mjs";
|
|
6
|
+
import { CriterionStatus, ProofLine, ProofResult, TestOutcome, TestResultsStore } from "./contracts/test-results.mjs";
|
|
7
|
+
import { CollectedFiles, FeatureBookmap, FeaturesIndex, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, Ownership, TaskSummary, TasksIndex } from "./contracts/bookmap.mjs";
|
|
8
|
+
import { AppMatch, GrimoireRule, GrimoireSnapshot, OpenGrimoireOptions } from "./contracts/snapshot.mjs";
|
|
9
|
+
import { CollectedListText, ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "./contracts/releases.mjs";
|
|
10
|
+
import { ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult } from "./contracts/scry.mjs";
|
|
11
|
+
import { GRIMOIRE_CODES, GRIMOIRE_CODE_LIST, GrimoireCode } from "./codes/codes.mjs";
|
|
12
|
+
import { GRIMOIRE_CODES_DOCS_URL, GrimoireError, createFinding, explainGrimoireCode, grimoireCodeDocsUrl, isGrimoireCode } from "./codes/index.mjs";
|
|
13
|
+
import { BookPathInput, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, toPosixPath } from "./paths/index.mjs";
|
|
14
|
+
import { FrontMatterField, FrontMatterResult, FrontMatterValue, readFrontMatter } from "./front-matter/index.mjs";
|
|
15
|
+
import { FileGraph, fileGraph, importClosure, importerClosure } from "./graph/index.mjs";
|
|
16
|
+
import { ParseGrimoireResult, parseGrimoire } from "./written/parse-grimoire.mjs";
|
|
17
|
+
import { buildBook, loadBook } from "./book/build.mjs";
|
|
18
|
+
import { writeBook } from "./book/write.mjs";
|
|
19
|
+
import { resolveOwnership } from "./ownership/index.mjs";
|
|
20
|
+
import { matchApps } from "./apps/match-apps.mjs";
|
|
21
|
+
import { CollectedInput, buildCollectedFiles } from "./bookmap/build.mjs";
|
|
22
|
+
import { writeCollectedFiles } from "./bookmap/write.mjs";
|
|
23
|
+
import { openGrimoire } from "./workspace/index.mjs";
|
|
24
|
+
import { ScanProofsResult, scanProofs, scanProofsInText } from "./proves/scan-proofs.mjs";
|
|
25
|
+
import { checkGrimoire } from "./check/check-grimoire.mjs";
|
|
26
|
+
import { formatCheckReport } from "./check/format-check-report.mjs";
|
|
27
|
+
import { collectRelease, renderCollectedList, writeRelease } from "./releases/index.mjs";
|
|
28
|
+
import { CriterionTestResult, criterionStatus } from "./test-results/criterion-status.mjs";
|
|
29
|
+
import { readTestResults } from "./test-results/index.mjs";
|
|
30
|
+
import { formatScryResult } from "./scry/format.mjs";
|
|
31
|
+
import { parseScryQuery } from "./scry/parse.mjs";
|
|
32
|
+
import { scry } from "./scry/query.mjs";
|
|
33
|
+
export { AppMatch, BOOK_SCHEMA_VERSION, BookAdapter, BookAnnotations, BookEntry, BookExport, BookFacts, BookFactsCache, BookFile, BookFileType, BookImport, BookManifest, BookManifestFile, BookMobileApp, BookMobileScreensFile, BookModuleSummary, BookNamedThing, BookNamedType, BookPage, BookPageLink, type BookPathInput, BookRoute, BookRouteRef, BookRoutesFile, BookScreen, BookSite, BookSitePagesFile, BuildBookOptions, BuildBookResult, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CollectedFiles, type CollectedInput, CollectedListText, CriterionId, CriterionStatus, type CriterionTestResult, FeatureBookmap, FeatureVersion, FeaturesIndex, type FileGraph, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, FlowRef, type FrontMatterField, type FrontMatterResult, type FrontMatterValue, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireCheckReport, type GrimoireCode, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireError, GrimoireFinding, GrimoireFindingInput, GrimoireRule, GrimoireSeverity, GrimoireSnapshot, LoadedBook, Located, OpenGrimoireOptions, Ownership, type ParseGrimoireResult, ProofLine, ProofResult, ReleaseCollection, ReleaseEntry, RouteFreshness, type ScanProofsResult, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult, SourceLocation, StepType, TaskStatus, TaskSummary, TaskType, TasksIndex, TestOutcome, TestResultsStore, WriteBookResult, WriteReleaseResult, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenStatus, WrittenStep, WrittenTask, WrittenVersionBrief, WrittenWho, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BOOK_SCHEMA_VERSION } from "./contracts/book.mjs";
|
|
2
|
+
import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER } from "./contracts/written.mjs";
|
|
3
|
+
import { GRIMOIRE_CODES, GRIMOIRE_CODE_LIST } from "./codes/codes.mjs";
|
|
4
|
+
import { GRIMOIRE_CODES_DOCS_URL, GrimoireError, createFinding, explainGrimoireCode, grimoireCodeDocsUrl, isGrimoireCode } from "./codes/index.mjs";
|
|
5
|
+
import { GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, toPosixPath } from "./paths/index.mjs";
|
|
6
|
+
import { readFrontMatter } from "./front-matter/index.mjs";
|
|
7
|
+
import { fileGraph, importClosure, importerClosure } from "./graph/index.mjs";
|
|
8
|
+
import { parseGrimoire } from "./written/parse-grimoire.mjs";
|
|
9
|
+
import "./written/index.mjs";
|
|
10
|
+
import { buildBook, loadBook } from "./book/build.mjs";
|
|
11
|
+
import { writeBook } from "./book/write.mjs";
|
|
12
|
+
import "./book/index.mjs";
|
|
13
|
+
import { resolveOwnership } from "./ownership/index.mjs";
|
|
14
|
+
import { matchApps } from "./apps/match-apps.mjs";
|
|
15
|
+
import "./apps/index.mjs";
|
|
16
|
+
import { criterionStatus } from "./test-results/criterion-status.mjs";
|
|
17
|
+
import { readTestResults } from "./test-results/index.mjs";
|
|
18
|
+
import { buildCollectedFiles } from "./bookmap/build.mjs";
|
|
19
|
+
import { writeCollectedFiles } from "./bookmap/write.mjs";
|
|
20
|
+
import "./bookmap/index.mjs";
|
|
21
|
+
import { scanProofs, scanProofsInText } from "./proves/scan-proofs.mjs";
|
|
22
|
+
import "./proves/index.mjs";
|
|
23
|
+
import { openGrimoire } from "./workspace/index.mjs";
|
|
24
|
+
import { collectRelease, renderCollectedList, writeRelease } from "./releases/index.mjs";
|
|
25
|
+
import { checkGrimoire } from "./check/check-grimoire.mjs";
|
|
26
|
+
import { formatCheckReport } from "./check/format-check-report.mjs";
|
|
27
|
+
import "./check/index.mjs";
|
|
28
|
+
import { formatScryResult } from "./scry/format.mjs";
|
|
29
|
+
import { parseScryQuery } from "./scry/parse.mjs";
|
|
30
|
+
import { scry } from "./scry/query.mjs";
|
|
31
|
+
import "./scry/index.mjs";
|
|
32
|
+
|
|
33
|
+
export { BOOK_SCHEMA_VERSION, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireError, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BookFacts } from "../contracts/adapter.mjs";
|
|
2
|
+
import { WrittenGrimoire } from "../contracts/written.mjs";
|
|
3
|
+
import { Ownership } from "../contracts/bookmap.mjs";
|
|
4
|
+
//#region ../../packages/grimoire/src/ownership/index.d.ts
|
|
5
|
+
/** Owner, conflicts and borrowers of every code file in `facts`. Pure. */
|
|
6
|
+
export declare function resolveOwnership(written: WrittenGrimoire, facts: BookFacts): Ownership;
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/ownership/index.ts"],"mappings":";;;;;wBAqIgB,iBAAiB,SAAS,iBAAiB,OAAO,YAAY"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { isCodeFile, isInsideFolder, toPosixPath } from "../paths/index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/grimoire/src/ownership/index.ts
|
|
4
|
+
/** Whether a `folders` entry names one code file instead of a folder. */
|
|
5
|
+
function isFileEntry(entry) {
|
|
6
|
+
return isCodeFile(entry);
|
|
7
|
+
}
|
|
8
|
+
function normalizeFolder(folder) {
|
|
9
|
+
return toPosixPath(folder.trim()).replace(/^\.\//, "").replace(/\/+$/, "");
|
|
10
|
+
}
|
|
11
|
+
/** Feature ids named by a file's `@feature` tags, trimmed, unique, in tag order. */
|
|
12
|
+
function taggedFeatures(file) {
|
|
13
|
+
const values = (file.tags.feature ?? []).map((value) => value.trim().split(/\s+/)[0] ?? "").filter((value) => value.length > 0);
|
|
14
|
+
return [...new Set(values)];
|
|
15
|
+
}
|
|
16
|
+
/** Whether a file counts as an own, borrowed or unreached file of a feature. */
|
|
17
|
+
function countsForFeature(file) {
|
|
18
|
+
return file.type !== "spec";
|
|
19
|
+
}
|
|
20
|
+
function decide(file, features, folders) {
|
|
21
|
+
const result = {
|
|
22
|
+
file: file.file,
|
|
23
|
+
owner: null,
|
|
24
|
+
via: null,
|
|
25
|
+
folder: null,
|
|
26
|
+
conflicts: [],
|
|
27
|
+
borrowedBy: []
|
|
28
|
+
};
|
|
29
|
+
const tags = taggedFeatures(file).filter((feature) => features.has(feature));
|
|
30
|
+
if (tags.length === 1) {
|
|
31
|
+
result.owner = tags[0] ?? null;
|
|
32
|
+
result.via = "tag";
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
if (tags.length > 1) {
|
|
36
|
+
result.conflicts = tags.sort().map((feature) => ({
|
|
37
|
+
feature,
|
|
38
|
+
via: "tag"
|
|
39
|
+
}));
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
const fileOwners = [...folders].filter(([, list]) => list.includes(file.file)).map(([feature]) => feature).sort();
|
|
43
|
+
if (fileOwners.length === 1) {
|
|
44
|
+
result.owner = fileOwners[0] ?? null;
|
|
45
|
+
result.via = "file";
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
if (fileOwners.length > 1) {
|
|
49
|
+
result.conflicts = fileOwners.map((feature) => ({
|
|
50
|
+
feature,
|
|
51
|
+
via: "file"
|
|
52
|
+
}));
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
let deepest = [];
|
|
56
|
+
let depth = -1;
|
|
57
|
+
for (const [feature, list] of folders) for (const folder of list) {
|
|
58
|
+
if (isFileEntry(folder)) continue;
|
|
59
|
+
if (!isInsideFolder(file.file, folder)) continue;
|
|
60
|
+
const folderDepth = folder.split("/").length;
|
|
61
|
+
if (folderDepth > depth) {
|
|
62
|
+
depth = folderDepth;
|
|
63
|
+
deepest = [{
|
|
64
|
+
feature,
|
|
65
|
+
via: "folder",
|
|
66
|
+
folder
|
|
67
|
+
}];
|
|
68
|
+
} else if (folderDepth === depth && !deepest.some((claim) => claim.feature === feature)) deepest.push({
|
|
69
|
+
feature,
|
|
70
|
+
via: "folder",
|
|
71
|
+
folder
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (deepest.length === 1) {
|
|
75
|
+
const claim = deepest[0];
|
|
76
|
+
if (claim) {
|
|
77
|
+
result.owner = claim.feature;
|
|
78
|
+
result.via = "folder";
|
|
79
|
+
result.folder = claim.folder;
|
|
80
|
+
}
|
|
81
|
+
} else if (deepest.length > 1) result.conflicts = deepest.map((claim) => ({
|
|
82
|
+
feature: claim.feature,
|
|
83
|
+
via: claim.via
|
|
84
|
+
})).sort((left, right) => left.feature.localeCompare(right.feature));
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** Owner, conflicts and borrowers of every code file in `facts`. Pure. */
|
|
88
|
+
function resolveOwnership(written, facts) {
|
|
89
|
+
const featureIds = new Set(written.features.map((feature) => feature.id));
|
|
90
|
+
const folders = /* @__PURE__ */ new Map();
|
|
91
|
+
for (const feature of written.features) {
|
|
92
|
+
const list = (feature.readme?.folders ?? []).map((folder) => normalizeFolder(folder.value)).filter((folder) => folder.length > 0);
|
|
93
|
+
folders.set(feature.id, [...new Set(list)]);
|
|
94
|
+
}
|
|
95
|
+
const files = {};
|
|
96
|
+
for (const file of facts.files) files[file.file] = decide(file, featureIds, folders);
|
|
97
|
+
const features = {};
|
|
98
|
+
for (const id of [...featureIds].sort()) features[id] = {
|
|
99
|
+
own: [],
|
|
100
|
+
borrowed: []
|
|
101
|
+
};
|
|
102
|
+
const byPath = new Map(facts.files.map((file) => [file.file, file]));
|
|
103
|
+
const borrowers = /* @__PURE__ */ new Map();
|
|
104
|
+
for (const file of facts.files) {
|
|
105
|
+
const owner = files[file.file]?.owner ?? null;
|
|
106
|
+
if (owner === null || !countsForFeature(file)) continue;
|
|
107
|
+
features[owner]?.own.push(file.file);
|
|
108
|
+
for (const entry of file.imports) {
|
|
109
|
+
if (entry.file === null || entry.file === file.file) continue;
|
|
110
|
+
const imported = files[entry.file];
|
|
111
|
+
if (!imported || imported.owner === owner) continue;
|
|
112
|
+
const importedFile = byPath.get(entry.file);
|
|
113
|
+
if (importedFile && !countsForFeature(importedFile)) continue;
|
|
114
|
+
const set = borrowers.get(entry.file) ?? /* @__PURE__ */ new Set();
|
|
115
|
+
set.add(owner);
|
|
116
|
+
borrowers.set(entry.file, set);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const [file, set] of borrowers) {
|
|
120
|
+
const ownership = files[file];
|
|
121
|
+
const sorted = [...set].sort();
|
|
122
|
+
if (ownership) ownership.borrowedBy = sorted;
|
|
123
|
+
for (const feature of sorted) features[feature]?.borrowed.push(file);
|
|
124
|
+
}
|
|
125
|
+
for (const entry of Object.values(features)) {
|
|
126
|
+
entry.own.sort();
|
|
127
|
+
entry.borrowed.sort();
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
files,
|
|
131
|
+
features
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { countsForFeature, resolveOwnership };
|
|
137
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/ownership/index.ts"],"sourcesContent":["/**\n * Who owns each source file (owned by T-128). Rules in `FileOwnership`.\n *\n * - A `@feature <id>` header tag that names a feature wins. A tag that names\n * no feature is left out here (the check reports it as `GR3004`), so the\n * folder rule decides.\n * - Otherwise a `folders` entry that names the file itself (an entry with a\n * code-file extension) owns it: a file entry is more specific than any\n * folder entry, so it wins over the folder of another feature.\n * - Otherwise the feature whose `folders` entry is the deepest folder holding\n * the file owns it.\n * - Two features claiming the file the same way (two different tags, the\n * same file listed by two features, or the same deepest folder listed by\n * two features) is a conflict: the file gets no owner and `conflicts`\n * lists the claims (`GR3003`).\n * - A feature borrows a file it does not own when one of its own files\n * imports it directly. Spec files are never own or borrowed files and do\n * not make a feature borrow anything.\n */\nimport type { BookFacts, BookFile } from \"../contracts/adapter\";\nimport type { FileOwnership, Ownership } from \"../contracts/bookmap\";\nimport type { WrittenGrimoire } from \"../contracts/written\";\nimport { isCodeFile, isInsideFolder, toPosixPath } from \"../paths\";\n\ntype Claim = { feature: string; via: \"tag\" | \"folder\"; folder: string | null };\n\n/** Whether a `folders` entry names one code file instead of a folder. */\nfunction isFileEntry(entry: string): boolean {\n return isCodeFile(entry);\n}\n\nfunction normalizeFolder(folder: string): string {\n return toPosixPath(folder.trim()).replace(/^\\.\\//, \"\").replace(/\\/+$/, \"\");\n}\n\n/** Feature ids named by a file's `@feature` tags, trimmed, unique, in tag order. */\nfunction taggedFeatures(file: BookFile): string[] {\n const values = (file.tags.feature ?? [])\n .map((value) => value.trim().split(/\\s+/)[0] ?? \"\")\n .filter((value) => value.length > 0);\n\n return [...new Set(values)];\n}\n\n/** Whether a file counts as an own, borrowed or unreached file of a feature. */\nexport function countsForFeature(file: Pick<BookFile, \"type\">): boolean {\n return file.type !== \"spec\";\n}\n\nfunction decide(\n file: BookFile,\n features: Set<string>,\n folders: Map<string, string[]>,\n): FileOwnership {\n const result: FileOwnership = {\n file: file.file,\n owner: null,\n via: null,\n folder: null,\n conflicts: [],\n borrowedBy: [],\n };\n const tags = taggedFeatures(file).filter((feature) => features.has(feature));\n\n if (tags.length === 1) {\n result.owner = tags[0] ?? null;\n result.via = \"tag\";\n\n return result;\n }\n\n if (tags.length > 1) {\n result.conflicts = tags.sort().map((feature) => ({ feature, via: \"tag\" }));\n\n return result;\n }\n\n const fileOwners = [...folders]\n .filter(([, list]) => list.includes(file.file))\n .map(([feature]) => feature)\n .sort();\n\n if (fileOwners.length === 1) {\n result.owner = fileOwners[0] ?? null;\n result.via = \"file\";\n\n return result;\n }\n\n if (fileOwners.length > 1) {\n result.conflicts = fileOwners.map((feature) => ({ feature, via: \"file\" }));\n\n return result;\n }\n\n let deepest: Claim[] = [];\n let depth = -1;\n\n for (const [feature, list] of folders) {\n for (const folder of list) {\n if (isFileEntry(folder)) continue;\n\n if (!isInsideFolder(file.file, folder)) continue;\n\n const folderDepth = folder.split(\"/\").length;\n\n if (folderDepth > depth) {\n depth = folderDepth;\n deepest = [{ feature, via: \"folder\", folder }];\n } else if (folderDepth === depth && !deepest.some((claim) => claim.feature === feature)) {\n deepest.push({ feature, via: \"folder\", folder });\n }\n }\n }\n\n if (deepest.length === 1) {\n const claim = deepest[0];\n\n if (claim) {\n result.owner = claim.feature;\n result.via = \"folder\";\n result.folder = claim.folder;\n }\n } else if (deepest.length > 1) {\n result.conflicts = deepest\n .map((claim) => ({ feature: claim.feature, via: claim.via }))\n .sort((left, right) => left.feature.localeCompare(right.feature));\n }\n\n return result;\n}\n\n/** Owner, conflicts and borrowers of every code file in `facts`. Pure. */\nexport function resolveOwnership(written: WrittenGrimoire, facts: BookFacts): Ownership {\n const featureIds = new Set(written.features.map((feature) => feature.id));\n const folders = new Map<string, string[]>();\n\n for (const feature of written.features) {\n const list = (feature.readme?.folders ?? [])\n .map((folder) => normalizeFolder(folder.value))\n .filter((folder) => folder.length > 0);\n\n folders.set(feature.id, [...new Set(list)]);\n }\n\n const files: Record<string, FileOwnership> = {};\n\n for (const file of facts.files) {\n files[file.file] = decide(file, featureIds, folders);\n }\n\n const features: Ownership[\"features\"] = {};\n\n for (const id of [...featureIds].sort()) {\n features[id] = { own: [], borrowed: [] };\n }\n\n const byPath = new Map(facts.files.map((file) => [file.file, file]));\n const borrowers = new Map<string, Set<string>>();\n\n for (const file of facts.files) {\n const owner = files[file.file]?.owner ?? null;\n\n if (owner === null || !countsForFeature(file)) continue;\n\n features[owner]?.own.push(file.file);\n\n for (const entry of file.imports) {\n if (entry.file === null || entry.file === file.file) continue;\n\n const imported = files[entry.file];\n\n if (!imported || imported.owner === owner) continue;\n\n const importedFile = byPath.get(entry.file);\n\n if (importedFile && !countsForFeature(importedFile)) continue;\n\n const set = borrowers.get(entry.file) ?? new Set<string>();\n set.add(owner);\n borrowers.set(entry.file, set);\n }\n }\n\n for (const [file, set] of borrowers) {\n const ownership = files[file];\n const sorted = [...set].sort();\n\n if (ownership) ownership.borrowedBy = sorted;\n\n for (const feature of sorted) features[feature]?.borrowed.push(file);\n }\n\n for (const entry of Object.values(features)) {\n entry.own.sort();\n entry.borrowed.sort();\n }\n\n return { files, features };\n}\n"],"mappings":";;;;AA2BA,SAAS,YAAY,OAAwB;CAC3C,OAAO,WAAW,KAAK;AACzB;AAEA,SAAS,gBAAgB,QAAwB;CAC/C,OAAO,YAAY,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,SAA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