@warlock.js/grimoire 5.56.0 → 5.57.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 +15 -0
- package/esm/devtools/data.mjs +34 -3
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/index.d.mts +5 -1
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +7 -1
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +14 -10
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +66 -21
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/llms-full.txt +2 -0
- package/package.json +3 -3
- package/skills/use-the-grimoire/SKILL.md +2 -0
- package/ui/grimoire-view.js +1371 -354
- package/ui/grimoire.css +611 -45
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
`@warlock.js/grimoire` is new in 5.55.0 and experimental: its file layout, `GR` codes and API may change in any release until it is marked stable.
|
|
4
4
|
|
|
5
|
+
## 5.57.0 - 2026-11-18
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- The devtools Grimoire tab has a Features view: every feature with its status, version, summary and flows, with a status filter, a text filter, sorting and counts.
|
|
10
|
+
- New `/features` data route. `/apps` rows carry each page or screen's route, heading, layout, blocks and whether it is confirmed or inferred, and `/summary` gains app, page, screen and release counts. Existing fields are unchanged.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- The Grimoire tab is rebuilt: a tab bar (Overview, Features, Apps, Tasks, Releases, Check, Modules) with counts and breadcrumbs, and a search box with the `/` shortcut, results grouped by type and arrow-key navigation.
|
|
15
|
+
- The Overview shows stat cards, recent releases and the top check problems. Apps groups pages and screens by route segment with a filter. Tasks, Releases, Check and Modules are filterable lists, and Check keeps what to fix apart from expected findings.
|
|
16
|
+
- The tab shows an "Opening the book…" state while a large book opens, and a failed view says what failed and what to do next.
|
|
17
|
+
- The tab uses the dashboard's colour tokens, so links and status text are readable in the light and the dark theme. The static export defines the same tokens for both themes.
|
|
18
|
+
- The tab keeps its snapshot until the book changes in production (no time limit) and starts opening the book when the panel is created, so the first view is fast on large apps. In development it serves the cached snapshot at once and refreshes it in the background; a failed refresh keeps the old snapshot. Set `ttlMs` through the panel options (`[specifier, options]` in devtools' `panels`) to choose a fixed reuse time.
|
|
19
|
+
|
|
5
20
|
## 5.56.0 - 2026-11-17
|
|
6
21
|
|
|
7
22
|
### Added
|
package/esm/devtools/data.mjs
CHANGED
|
@@ -52,9 +52,31 @@ function summary(snapshot) {
|
|
|
52
52
|
files: files.length,
|
|
53
53
|
modules: new Set(files.map((file) => file.module)).size,
|
|
54
54
|
builtAt: snapshot.book.manifest.builtAt
|
|
55
|
-
}
|
|
55
|
+
},
|
|
56
|
+
apps: {
|
|
57
|
+
apps: written.apps.length,
|
|
58
|
+
pages: written.apps.reduce((total, app) => total + app.pages.length, 0),
|
|
59
|
+
screens: written.apps.reduce((total, app) => total + app.screens.length, 0)
|
|
60
|
+
},
|
|
61
|
+
releases: written.releases.length
|
|
56
62
|
};
|
|
57
63
|
}
|
|
64
|
+
/** The features listing: the features index with each README summary and flow headings. */
|
|
65
|
+
function features(snapshot) {
|
|
66
|
+
const written = new Map(snapshot.written.features.map((feature) => [feature.id, feature]));
|
|
67
|
+
return { features: snapshot.collected.featuresIndex.features.map((entry) => {
|
|
68
|
+
const source = written.get(entry.id);
|
|
69
|
+
const headings = new Map((source?.flows ?? []).map((flow) => [flow.id.value, flow.heading?.value ?? null]));
|
|
70
|
+
return {
|
|
71
|
+
...entry,
|
|
72
|
+
summary: source?.readme?.summary ?? null,
|
|
73
|
+
flows: entry.flows.map((flow) => ({
|
|
74
|
+
...flow,
|
|
75
|
+
heading: headings.get(flow.id) ?? null
|
|
76
|
+
}))
|
|
77
|
+
};
|
|
78
|
+
}) };
|
|
79
|
+
}
|
|
58
80
|
function search(snapshot, text, limit) {
|
|
59
81
|
return ask(snapshot, {
|
|
60
82
|
type: "search",
|
|
@@ -100,7 +122,16 @@ function apps(snapshot) {
|
|
|
100
122
|
type: app.type.value,
|
|
101
123
|
root: app.root.value,
|
|
102
124
|
pages: app.pages.map((page) => page.id),
|
|
103
|
-
screens: app.screens.map((screen) => screen.id)
|
|
125
|
+
screens: app.screens.map((screen) => screen.id),
|
|
126
|
+
rows: [...app.pages, ...app.screens].map((item) => ({
|
|
127
|
+
id: item.id,
|
|
128
|
+
type: item.type,
|
|
129
|
+
route: item.route?.value ?? item.screen?.value ?? null,
|
|
130
|
+
heading: item.heading?.value ?? null,
|
|
131
|
+
origin: item.origin?.value ?? null,
|
|
132
|
+
layout: item.layout?.value ?? null,
|
|
133
|
+
blocks: item.blocks.length
|
|
134
|
+
}))
|
|
104
135
|
})) };
|
|
105
136
|
}
|
|
106
137
|
function findApp(snapshot, id) {
|
|
@@ -167,5 +198,5 @@ function graphOfModules(snapshot) {
|
|
|
167
198
|
}
|
|
168
199
|
|
|
169
200
|
//#endregion
|
|
170
|
-
export { GrimoirePanelError, apps, check, feature, file, findPage, flow, graphOfFeature, graphOfFile, graphOfModules, graphOfPage, impact, page, release, releases, route, search, summary, tasks };
|
|
201
|
+
export { GrimoirePanelError, apps, check, feature, features, file, findPage, flow, graphOfFeature, graphOfFile, graphOfModules, graphOfPage, impact, page, release, releases, route, search, summary, tasks };
|
|
171
202
|
//# sourceMappingURL=data.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/data.ts"],"sourcesContent":["/**\n * The answers of the tab, as functions of the snapshot. The devtools routes\n * and the static export both call them; questions about one item go to\n * `scry()`, the rest read the snapshot directly.\n */\nimport { isGrimoireCode } from \"../codes\";\nimport { checkGrimoire } from \"../check\";\nimport type { BookPage, BookScreen } from \"../contracts/adapter\";\nimport type { TasksIndex, FeaturesIndex } from \"../contracts/bookmap\";\nimport type { GrimoireCheckReport, RouteFreshness } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryImpactResult,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { WrittenApp, WrittenLayout, WrittenPage, WrittenRelease } from \"../contracts/written\";\nimport { scry } from \"../scry\";\nimport { featureGraph, fileGraph, moduleGraph, pageGraph, type GrimoireGraph } from \"./graphs\";\n\n/** An error a route answers with a status (devtools turns `statusCode` into the response status). */\nexport class GrimoirePanelError extends Error {\n public readonly statusCode: number;\n\n public constructor(statusCode: number, message: string) {\n super(message);\n this.name = \"GrimoirePanelError\";\n this.statusCode = statusCode;\n }\n}\n\nexport type GrimoireSummary = {\n routes: RouteFreshness;\n features: FeaturesIndex;\n tasks: TasksIndex;\n counts: GrimoireCheckReport[\"counts\"];\n /** Whether any feature, app, task or release is written, and how big the book is. */\n written: boolean;\n book: { files: number; modules: number; builtAt: string };\n};\n\nexport type GrimoireAppsAnswer = {\n apps: { id: string; type: string; root: string; pages: string[]; screens: string[] }[];\n};\n\nexport type GrimoirePageAnswer = {\n page: WrittenPage;\n layout: WrittenLayout | null;\n book: BookPage | BookScreen | null;\n};\n\nexport type GrimoireReleasesAnswer = {\n releases: { release: string; date: string; file: string }[];\n};\n\n/** `scry()` with its not-found codes turned into a 404 and the rest into a 400. */\nfunction ask<Result>(snapshot: GrimoireSnapshot, query: Parameters<typeof scry>[1]): Result {\n try {\n return scry(snapshot, query) as Result;\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n\n if (typeof code === \"string\" && isGrimoireCode(code)) {\n throw new GrimoirePanelError(code === \"GR9006\" ? 400 : 404, (error as Error).message);\n }\n\n throw error;\n }\n}\n\nfunction required(value: string | undefined, name: string): string {\n if (value === undefined || value === \"\") throw new GrimoirePanelError(400, `Missing \"${name}\".`);\n\n return value;\n}\n\nexport function summary(snapshot: GrimoireSnapshot): GrimoireSummary {\n const files = snapshot.book.facts.files;\n const written = snapshot.written;\n\n return {\n routes: snapshot.routes,\n features: snapshot.collected.featuresIndex,\n tasks: snapshot.collected.tasksIndex,\n counts: checkGrimoire(snapshot).counts,\n written: [written.features, written.apps, written.tasks, written.releases].some(\n (items) => items.length > 0,\n ),\n book: {\n files: files.length,\n modules: new Set(files.map((file) => file.module)).size,\n builtAt: snapshot.book.manifest.builtAt,\n },\n };\n}\n\nexport function search(snapshot: GrimoireSnapshot, text: string, limit?: number): ScrySearchResult {\n return ask<ScrySearchResult>(snapshot, {\n type: \"search\",\n text,\n ...(limit !== undefined && Number.isFinite(limit) && limit > 0\n ? { limit: Math.min(limit, 100) }\n : {}),\n });\n}\n\nexport function file(snapshot: GrimoireSnapshot, path: string | undefined): ScryFileResult {\n return ask(snapshot, { type: \"file\", file: required(path, \"path\") });\n}\n\nexport function impact(snapshot: GrimoireSnapshot, path: string | undefined): ScryImpactResult {\n return ask(snapshot, { type: \"impact\", file: required(path, \"path\") });\n}\n\nexport function route(\n snapshot: GrimoireSnapshot,\n method: string | undefined,\n path: string | undefined,\n): ScryRouteResult {\n return ask(snapshot, {\n type: \"route\",\n method: required(method, \"method\"),\n path: required(path, \"path\"),\n });\n}\n\nexport function feature(snapshot: GrimoireSnapshot, id: string | undefined): ScryFeatureResult {\n return ask(snapshot, { type: \"feature\", feature: required(id, \"feature\") });\n}\n\nexport function flow(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n): ScryFlowResult {\n return ask(snapshot, {\n type: \"flow\",\n feature: required(featureId, \"feature\"),\n flow: required(flowId, \"flow\"),\n });\n}\n\nexport function apps(snapshot: GrimoireSnapshot): GrimoireAppsAnswer {\n return {\n apps: snapshot.written.apps.map((app) => ({\n id: app.id.value,\n type: app.type.value,\n root: app.root.value,\n pages: app.pages.map((page) => page.id),\n screens: app.screens.map((screen) => screen.id),\n })),\n };\n}\n\nfunction findApp(snapshot: GrimoireSnapshot, id: string | undefined): WrittenApp {\n const app = snapshot.written.apps.find((candidate) => candidate.id.value === id);\n\n if (app === undefined)\n throw new GrimoirePanelError(404, `No app \"${id ?? \"\"}\" is written in grimoire/apps.`);\n\n return app;\n}\n\n/** A page or screen by its id or its route. */\nexport function findPage(app: WrittenApp, key: string): WrittenPage | undefined {\n return [...app.pages, ...app.screens].find(\n (page) => page.id === key || page.route?.value === key || page.screen?.value === key,\n );\n}\n\nexport function page(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoirePageAnswer {\n const app = findApp(snapshot, appId);\n const written = findPage(app, required(key, \"page\"));\n\n if (written === undefined) {\n throw new GrimoirePanelError(\n 404,\n `App \"${app.id.value}\" has no page or screen \"${key ?? \"\"}\".`,\n );\n }\n\n const match = snapshot.apps[app.id.value];\n const route = written.route?.value ?? written.screen?.value ?? null;\n let book: BookPage | BookScreen | null = null;\n\n if (route !== null && match?.site) {\n book =\n snapshot.book.facts.pages.find(\n (candidate) => candidate.site === match.site?.id && candidate.route === route,\n ) ?? null;\n } else if (route !== null && match?.mobile) {\n book = match.mobile.screens.find((screen) => screen.route === route) ?? null;\n }\n\n const layoutId = written.layout?.value ?? null;\n\n return {\n page: written,\n layout:\n layoutId === null ? null : (app.layouts.find((layout) => layout.id === layoutId) ?? null),\n book,\n };\n}\n\nexport function tasks(snapshot: GrimoireSnapshot): TasksIndex {\n return snapshot.collected.tasksIndex;\n}\n\nexport function releases(snapshot: GrimoireSnapshot): GrimoireReleasesAnswer {\n return {\n releases: snapshot.written.releases.map((release) => ({\n release: release.release.value,\n date: release.date.value,\n file: release.file,\n })),\n };\n}\n\nexport function release(snapshot: GrimoireSnapshot, id: string | undefined): WrittenRelease {\n const found = snapshot.written.releases.find((candidate) => candidate.release.value === id);\n\n if (found === undefined)\n throw new GrimoirePanelError(404, `No release \"${id ?? \"\"}\" in grimoire/releases.`);\n\n return found;\n}\n\nexport function check(snapshot: GrimoireSnapshot): GrimoireCheckReport {\n return checkGrimoire(snapshot);\n}\n\nfunction graphOrNotFound(graph: GrimoireGraph | null, what: string): GrimoireGraph {\n if (graph === null) throw new GrimoirePanelError(404, `${what} is not in the book.`);\n\n return graph;\n}\n\nexport function graphOfFile(snapshot: GrimoireSnapshot, path: string | undefined): GrimoireGraph {\n const target = required(path, \"path\");\n\n return graphOrNotFound(fileGraph(snapshot, target), `\"${target}\"`);\n}\n\nexport function graphOfFeature(snapshot: GrimoireSnapshot, id: string | undefined): GrimoireGraph {\n const target = required(id, \"feature\");\n\n return graphOrNotFound(featureGraph(snapshot, target), `Feature \"${target}\"`);\n}\n\nexport function graphOfPage(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoireGraph {\n const target = required(key, \"page\");\n\n return graphOrNotFound(pageGraph(snapshot, required(appId, \"app\"), target), `Page \"${target}\"`);\n}\n\nexport function graphOfModules(snapshot: GrimoireSnapshot): GrimoireGraph {\n return moduleGraph(snapshot);\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,AAAgB;CAEhB,AAAO,YAAY,YAAoB,SAAiB;EACtD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;;AA2BA,SAAS,IAAY,UAA4B,OAA2C;CAC1F,IAAI;EACF,OAAO,KAAK,UAAU,KAAK;CAC7B,SAAS,OAAO;EACd,MAAM,OAAQ,MAA6B;EAE3C,IAAI,OAAO,SAAS,YAAY,eAAe,IAAI,GACjD,MAAM,IAAI,mBAAmB,SAAS,WAAW,MAAM,KAAM,MAAgB,OAAO;EAGtF,MAAM;CACR;AACF;AAEA,SAAS,SAAS,OAA2B,MAAsB;CACjE,IAAI,UAAU,UAAa,UAAU,IAAI,MAAM,IAAI,mBAAmB,KAAK,YAAY,KAAK,GAAG;CAE/F,OAAO;AACT;AAEA,SAAgB,QAAQ,U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EnC,OAAO,gBAAgB,UAAU,UAAU,SAAS,OAAO,KAAK,GAAG,MAAM,GAAG,SAAS,OAAO,EAAE;AAChG;AAEA,SAAgB,eAAe,UAA2C;CACxE,OAAO,YAAY,QAAQ;AAC7B"}
|
|
1
|
+
{"version":3,"file":"data.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/data.ts"],"sourcesContent":["/**\n * The answers of the tab, as functions of the snapshot. The devtools routes\n * and the static export both call them; questions about one item go to\n * `scry()`, the rest read the snapshot directly.\n */\nimport { isGrimoireCode } from \"../codes\";\nimport { checkGrimoire } from \"../check\";\nimport type { BookPage, BookScreen } from \"../contracts/adapter\";\nimport type { TasksIndex, FeaturesIndex } from \"../contracts/bookmap\";\nimport type { GrimoireCheckReport, RouteFreshness } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryImpactResult,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { WrittenApp, WrittenLayout, WrittenPage, WrittenRelease } from \"../contracts/written\";\nimport { scry } from \"../scry\";\nimport { featureGraph, fileGraph, moduleGraph, pageGraph, type GrimoireGraph } from \"./graphs\";\n\n/** An error a route answers with a status (devtools turns `statusCode` into the response status). */\nexport class GrimoirePanelError extends Error {\n public readonly statusCode: number;\n\n public constructor(statusCode: number, message: string) {\n super(message);\n this.name = \"GrimoirePanelError\";\n this.statusCode = statusCode;\n }\n}\n\nexport type GrimoireSummary = {\n routes: RouteFreshness;\n features: FeaturesIndex;\n tasks: TasksIndex;\n counts: GrimoireCheckReport[\"counts\"];\n /** Whether any feature, app, task or release is written, and how big the book is. */\n written: boolean;\n book: { files: number; modules: number; builtAt: string };\n /** How many apps, pages, screens and releases are written (the tab's navigation and overview badges). */\n apps: { apps: number; pages: number; screens: number };\n releases: number;\n};\n\n/** One feature of the listing: the index entry plus what the cards show. */\nexport type GrimoireFeatureRow = Omit<FeaturesIndex[\"features\"][number], \"flows\"> & {\n /** The README paragraph under the heading, or `null`. */\n summary: string | null;\n /** The index flows with their headings. */\n flows: (FeaturesIndex[\"features\"][number][\"flows\"][number] & { heading: string | null })[];\n};\n\nexport type GrimoireFeaturesAnswer = { features: GrimoireFeatureRow[] };\n\n/** One page or screen of an app, as the listing shows it. */\nexport type GrimoireAppRow = {\n id: string;\n type: \"page\" | \"screen\";\n /** The page route or the screen name, or `null` when the file gives none. */\n route: string | null;\n heading: string | null;\n /** `confirmed` or `inferred` when the file says so, otherwise `null`. */\n origin: \"confirmed\" | \"inferred\" | null;\n layout: string | null;\n /** How many block rows the page lists itself. */\n blocks: number;\n};\n\nexport type GrimoireAppsAnswer = {\n apps: {\n id: string;\n type: string;\n root: string;\n pages: string[];\n screens: string[];\n /** Every page and screen with what the listing needs. */\n rows: GrimoireAppRow[];\n }[];\n};\n\nexport type GrimoirePageAnswer = {\n page: WrittenPage;\n layout: WrittenLayout | null;\n book: BookPage | BookScreen | null;\n};\n\nexport type GrimoireReleasesAnswer = {\n releases: { release: string; date: string; file: string }[];\n};\n\n/** `scry()` with its not-found codes turned into a 404 and the rest into a 400. */\nfunction ask<Result>(snapshot: GrimoireSnapshot, query: Parameters<typeof scry>[1]): Result {\n try {\n return scry(snapshot, query) as Result;\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n\n if (typeof code === \"string\" && isGrimoireCode(code)) {\n throw new GrimoirePanelError(code === \"GR9006\" ? 400 : 404, (error as Error).message);\n }\n\n throw error;\n }\n}\n\nfunction required(value: string | undefined, name: string): string {\n if (value === undefined || value === \"\") throw new GrimoirePanelError(400, `Missing \"${name}\".`);\n\n return value;\n}\n\nexport function summary(snapshot: GrimoireSnapshot): GrimoireSummary {\n const files = snapshot.book.facts.files;\n const written = snapshot.written;\n\n return {\n routes: snapshot.routes,\n features: snapshot.collected.featuresIndex,\n tasks: snapshot.collected.tasksIndex,\n counts: checkGrimoire(snapshot).counts,\n written: [written.features, written.apps, written.tasks, written.releases].some(\n (items) => items.length > 0,\n ),\n book: {\n files: files.length,\n modules: new Set(files.map((file) => file.module)).size,\n builtAt: snapshot.book.manifest.builtAt,\n },\n apps: {\n apps: written.apps.length,\n pages: written.apps.reduce((total, app) => total + app.pages.length, 0),\n screens: written.apps.reduce((total, app) => total + app.screens.length, 0),\n },\n releases: written.releases.length,\n };\n}\n\n/** The features listing: the features index with each README summary and flow headings. */\nexport function features(snapshot: GrimoireSnapshot): GrimoireFeaturesAnswer {\n const written = new Map(snapshot.written.features.map((feature) => [feature.id, feature]));\n\n return {\n features: snapshot.collected.featuresIndex.features.map((entry) => {\n const source = written.get(entry.id);\n const headings = new Map(\n (source?.flows ?? []).map((flow) => [flow.id.value, flow.heading?.value ?? null]),\n );\n\n return {\n ...entry,\n summary: source?.readme?.summary ?? null,\n flows: entry.flows.map((flow) => ({ ...flow, heading: headings.get(flow.id) ?? null })),\n };\n }),\n };\n}\n\nexport function search(snapshot: GrimoireSnapshot, text: string, limit?: number): ScrySearchResult {\n return ask<ScrySearchResult>(snapshot, {\n type: \"search\",\n text,\n ...(limit !== undefined && Number.isFinite(limit) && limit > 0\n ? { limit: Math.min(limit, 100) }\n : {}),\n });\n}\n\nexport function file(snapshot: GrimoireSnapshot, path: string | undefined): ScryFileResult {\n return ask(snapshot, { type: \"file\", file: required(path, \"path\") });\n}\n\nexport function impact(snapshot: GrimoireSnapshot, path: string | undefined): ScryImpactResult {\n return ask(snapshot, { type: \"impact\", file: required(path, \"path\") });\n}\n\nexport function route(\n snapshot: GrimoireSnapshot,\n method: string | undefined,\n path: string | undefined,\n): ScryRouteResult {\n return ask(snapshot, {\n type: \"route\",\n method: required(method, \"method\"),\n path: required(path, \"path\"),\n });\n}\n\nexport function feature(snapshot: GrimoireSnapshot, id: string | undefined): ScryFeatureResult {\n return ask(snapshot, { type: \"feature\", feature: required(id, \"feature\") });\n}\n\nexport function flow(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n): ScryFlowResult {\n return ask(snapshot, {\n type: \"flow\",\n feature: required(featureId, \"feature\"),\n flow: required(flowId, \"flow\"),\n });\n}\n\nexport function apps(snapshot: GrimoireSnapshot): GrimoireAppsAnswer {\n return {\n apps: snapshot.written.apps.map((app) => ({\n id: app.id.value,\n type: app.type.value,\n root: app.root.value,\n pages: app.pages.map((page) => page.id),\n screens: app.screens.map((screen) => screen.id),\n rows: [...app.pages, ...app.screens].map((item) => ({\n id: item.id,\n type: item.type,\n route: item.route?.value ?? item.screen?.value ?? null,\n heading: item.heading?.value ?? null,\n origin: item.origin?.value ?? null,\n layout: item.layout?.value ?? null,\n blocks: item.blocks.length,\n })),\n })),\n };\n}\n\nfunction findApp(snapshot: GrimoireSnapshot, id: string | undefined): WrittenApp {\n const app = snapshot.written.apps.find((candidate) => candidate.id.value === id);\n\n if (app === undefined)\n throw new GrimoirePanelError(404, `No app \"${id ?? \"\"}\" is written in grimoire/apps.`);\n\n return app;\n}\n\n/** A page or screen by its id or its route. */\nexport function findPage(app: WrittenApp, key: string): WrittenPage | undefined {\n return [...app.pages, ...app.screens].find(\n (page) => page.id === key || page.route?.value === key || page.screen?.value === key,\n );\n}\n\nexport function page(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoirePageAnswer {\n const app = findApp(snapshot, appId);\n const written = findPage(app, required(key, \"page\"));\n\n if (written === undefined) {\n throw new GrimoirePanelError(\n 404,\n `App \"${app.id.value}\" has no page or screen \"${key ?? \"\"}\".`,\n );\n }\n\n const match = snapshot.apps[app.id.value];\n const route = written.route?.value ?? written.screen?.value ?? null;\n let book: BookPage | BookScreen | null = null;\n\n if (route !== null && match?.site) {\n book =\n snapshot.book.facts.pages.find(\n (candidate) => candidate.site === match.site?.id && candidate.route === route,\n ) ?? null;\n } else if (route !== null && match?.mobile) {\n book = match.mobile.screens.find((screen) => screen.route === route) ?? null;\n }\n\n const layoutId = written.layout?.value ?? null;\n\n return {\n page: written,\n layout:\n layoutId === null ? null : (app.layouts.find((layout) => layout.id === layoutId) ?? null),\n book,\n };\n}\n\nexport function tasks(snapshot: GrimoireSnapshot): TasksIndex {\n return snapshot.collected.tasksIndex;\n}\n\nexport function releases(snapshot: GrimoireSnapshot): GrimoireReleasesAnswer {\n return {\n releases: snapshot.written.releases.map((release) => ({\n release: release.release.value,\n date: release.date.value,\n file: release.file,\n })),\n };\n}\n\nexport function release(snapshot: GrimoireSnapshot, id: string | undefined): WrittenRelease {\n const found = snapshot.written.releases.find((candidate) => candidate.release.value === id);\n\n if (found === undefined)\n throw new GrimoirePanelError(404, `No release \"${id ?? \"\"}\" in grimoire/releases.`);\n\n return found;\n}\n\nexport function check(snapshot: GrimoireSnapshot): GrimoireCheckReport {\n return checkGrimoire(snapshot);\n}\n\nfunction graphOrNotFound(graph: GrimoireGraph | null, what: string): GrimoireGraph {\n if (graph === null) throw new GrimoirePanelError(404, `${what} is not in the book.`);\n\n return graph;\n}\n\nexport function graphOfFile(snapshot: GrimoireSnapshot, path: string | undefined): GrimoireGraph {\n const target = required(path, \"path\");\n\n return graphOrNotFound(fileGraph(snapshot, target), `\"${target}\"`);\n}\n\nexport function graphOfFeature(snapshot: GrimoireSnapshot, id: string | undefined): GrimoireGraph {\n const target = required(id, \"feature\");\n\n return graphOrNotFound(featureGraph(snapshot, target), `Feature \"${target}\"`);\n}\n\nexport function graphOfPage(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoireGraph {\n const target = required(key, \"page\");\n\n return graphOrNotFound(pageGraph(snapshot, required(appId, \"app\"), target), `Page \"${target}\"`);\n}\n\nexport function graphOfModules(snapshot: GrimoireSnapshot): GrimoireGraph {\n return moduleGraph(snapshot);\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,AAAgB;CAEhB,AAAO,YAAY,YAAoB,SAAiB;EACtD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;A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U,MAAM,GAAG,IAAI,OAAO,EAAE;AACnE;AAEA,SAAgB,eAAe,UAA4B,IAAuC;CAChG,MAAM,SAAS,SAAS,IAAI,SAAS;CAErC,OAAO,gBAAgB,aAAa,UAAU,MAAM,GAAG,YAAY,OAAO,EAAE;AAC9E;AAEA,SAAgB,YACd,UACA,OACA,KACe;CACf,MAAM,SAAS,SAAS,KAAK,MAAM;CAEnC,OAAO,gBAAgB,UAAU,UAAU,SAAS,OAAO,KAAK,GAAG,MAAM,GAAG,SAAS,OAAO,EAAE;AAChG;AAEA,SAAgB,eAAe,UAA2C;CACxE,OAAO,YAAY,QAAQ;AAC7B"}
|
package/esm/devtools/index.d.mts
CHANGED
|
@@ -32,7 +32,11 @@ export type GrimoirePanelContext = {
|
|
|
32
32
|
mode?: "development" | "production";
|
|
33
33
|
/** The adapter to open the book with. Default: the Warlock adapter, loaded on first request. */
|
|
34
34
|
adapter?: BookAdapter | (() => Promise<BookAdapter>);
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* How long an opened snapshot is reused when the book did not change (ms).
|
|
37
|
+
* Default in development: 2000, longer after a slow open; the old snapshot is served while a
|
|
38
|
+
* background open refreshes it. Default in production: until the book changes.
|
|
39
|
+
*/
|
|
36
40
|
ttlMs?: number;
|
|
37
41
|
};
|
|
38
42
|
/** Build the panel for the app at `root`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"mappings":";;;;YAuBY;EACV,QAAQ,SAAS;EACjB,OAAO,SAAS;EAChB;;;YAIU;EACV;EACA;EACA,eAAe;EACf;IACE;IACA;IACA,UAAU,SAAS;;EAErB,SAAS,SAAS,wBAAwB;;EAE1C;;;YAIU;;EAEV;;;;;EAKA;;EAEA,UAAU,qBAAqB,QAAQ
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"mappings":";;;;YAuBY;EACV,QAAQ,SAAS;EACjB,OAAO,SAAS;EAChB;;;YAIU;EACV;EACA;EACA,eAAe;EACf;IACE;IACA;IACA,UAAU,SAAS;;EAErB,SAAS,SAAS,wBAAwB;;EAE1C;;;YAIU;;EAEV;;;;;EAKA;;EAEA,UAAU,qBAAqB,QAAQ;;;;;;EAMvC;;;wBAWoB,sBACpB,SAAS,uBACR,QAAQ"}
|
package/esm/devtools/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apps, check, feature, file, flow, graphOfFeature, graphOfFile, graphOfModules, graphOfPage, impact, page, release, releases, route, search, summary, tasks } from "./data.mjs";
|
|
1
|
+
import { apps, check, feature, features, file, flow, graphOfFeature, graphOfFile, graphOfModules, graphOfPage, impact, page, release, releases, route, search, summary, tasks } from "./data.mjs";
|
|
2
2
|
import { createSnapshotSource } from "./snapshot-source.mjs";
|
|
3
3
|
import { exportGrimoireSite } from "./site.mjs";
|
|
4
4
|
|
|
@@ -12,9 +12,11 @@ function one(query, name) {
|
|
|
12
12
|
async function grimoireDevtoolsPanel(context) {
|
|
13
13
|
const source = createSnapshotSource(context.root, {
|
|
14
14
|
write: context.mode !== "production",
|
|
15
|
+
mode: context.mode ?? "development",
|
|
15
16
|
...context.adapter === void 0 ? {} : { adapter: context.adapter },
|
|
16
17
|
...context.ttlMs === void 0 ? {} : { ttlMs: context.ttlMs }
|
|
17
18
|
});
|
|
19
|
+
if (context.mode === "production") source.warm();
|
|
18
20
|
const answer = (read) => async (request) => read(await source.get(), request);
|
|
19
21
|
return {
|
|
20
22
|
id: "grimoire",
|
|
@@ -46,6 +48,10 @@ async function grimoireDevtoolsPanel(context) {
|
|
|
46
48
|
path: "/route",
|
|
47
49
|
handler: answer((snapshot, { query }) => route(snapshot, one(query, "method"), one(query, "path")))
|
|
48
50
|
},
|
|
51
|
+
{
|
|
52
|
+
path: "/features",
|
|
53
|
+
handler: answer((snapshot) => features(snapshot))
|
|
54
|
+
},
|
|
49
55
|
{
|
|
50
56
|
path: "/features/:feature",
|
|
51
57
|
handler: answer((snapshot, { params }) => feature(snapshot, params.feature))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["data.summary","data.search","data.file","data.impact","data.route","data.feature","data.flow","data.apps","data.page","data.tasks","data.releases","data.release","data.check","data.graphOfFile","data.graphOfFeature","data.graphOfPage","data.graphOfModules"],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"sourcesContent":["/**\n * `@warlock.js/grimoire/devtools`: the Grimoire tab of the devtools\n * dashboard. An app enables it in `src/config/devtools.ts`:\n *\n * ```ts\n * panels: [\"@warlock.js/grimoire/devtools\"]\n * ```\n *\n * The default export is a panel factory (devtools' `DevtoolsPanelExport`),\n * typed structurally here so this entry needs no `@warlock.js/devtools`\n * import. The browser view lives in the package's `ui/` folder. Data routes\n * open the snapshot with `routes: \"cached\"` (never booting the app) and keep\n * the generated book up to date; agent-written files are only read.\n */\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport * as data from \"./data\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\nexport { exportGrimoireSite } from \"./site\";\nexport type { ExportGrimoireSiteOptions } from \"./site\";\n\n/** The parts of devtools' `DevtoolsPanelRequest` the routes read. */\nexport type GrimoirePanelRequest = {\n params: Readonly<Record<string, string>>;\n query: Readonly<Record<string, string | readonly string[]>>;\n body: unknown;\n};\n\n/** Devtools' `DevtoolsPanel`, structurally. */\nexport type GrimoireDevtoolsPanel = {\n id: string;\n title: string;\n view: string | URL;\n routes?: readonly {\n method?: \"GET\" | \"POST\";\n path: string;\n handler: (request: GrimoirePanelRequest) => unknown;\n }[];\n assets?: Readonly<Record<string, string | URL>>;\n /** Safe for the production monitor: the tab only reads (see `GrimoirePanelContext.mode`). */\n production?: boolean;\n};\n\n/** What the panel factory takes: devtools passes `{ root, mode }`; the rest is for tests and custom setups. */\nexport type GrimoirePanelContext = {\n /** The app root. */\n root: string;\n /**\n * Where the dashboard runs. In `\"production\"` the tab writes no files:\n * it reads the book as it is on disk. Default: development.\n */\n mode?: \"development\" | \"production\";\n /** The adapter to open the book with. Default: the Warlock adapter, loaded on first request. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["data.summary","data.search","data.file","data.impact","data.route","data.features","data.feature","data.flow","data.apps","data.page","data.tasks","data.releases","data.release","data.check","data.graphOfFile","data.graphOfFeature","data.graphOfPage","data.graphOfModules"],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"sourcesContent":["/**\n * `@warlock.js/grimoire/devtools`: the Grimoire tab of the devtools\n * dashboard. An app enables it in `src/config/devtools.ts`:\n *\n * ```ts\n * panels: [\"@warlock.js/grimoire/devtools\"]\n * ```\n *\n * The default export is a panel factory (devtools' `DevtoolsPanelExport`),\n * typed structurally here so this entry needs no `@warlock.js/devtools`\n * import. The browser view lives in the package's `ui/` folder. Data routes\n * open the snapshot with `routes: \"cached\"` (never booting the app) and keep\n * the generated book up to date; agent-written files are only read.\n */\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport * as data from \"./data\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\nexport { exportGrimoireSite } from \"./site\";\nexport type { ExportGrimoireSiteOptions } from \"./site\";\n\n/** The parts of devtools' `DevtoolsPanelRequest` the routes read. */\nexport type GrimoirePanelRequest = {\n params: Readonly<Record<string, string>>;\n query: Readonly<Record<string, string | readonly string[]>>;\n body: unknown;\n};\n\n/** Devtools' `DevtoolsPanel`, structurally. */\nexport type GrimoireDevtoolsPanel = {\n id: string;\n title: string;\n view: string | URL;\n routes?: readonly {\n method?: \"GET\" | \"POST\";\n path: string;\n handler: (request: GrimoirePanelRequest) => unknown;\n }[];\n assets?: Readonly<Record<string, string | URL>>;\n /** Safe for the production monitor: the tab only reads (see `GrimoirePanelContext.mode`). */\n production?: boolean;\n};\n\n/** What the panel factory takes: devtools passes `{ root, mode }`; the rest is for tests and custom setups. */\nexport type GrimoirePanelContext = {\n /** The app root. */\n root: string;\n /**\n * Where the dashboard runs. In `\"production\"` the tab writes no files:\n * it reads the book as it is on disk. Default: development.\n */\n mode?: \"development\" | \"production\";\n /** The adapter to open the book with. Default: the Warlock adapter, loaded on first request. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long an opened snapshot is reused when the book did not change (ms).\n * Default in development: 2000, longer after a slow open; the old snapshot is served while a\n * background open refreshes it. Default in production: until the book changes.\n */\n ttlMs?: number;\n};\n\n/** The first value of a query parameter. */\nfunction one(query: GrimoirePanelRequest[\"query\"], name: string): string | undefined {\n const value = query[name];\n\n return Array.isArray(value) ? value[0] : (value as string | undefined);\n}\n\n/** Build the panel for the app at `root`. */\nexport async function grimoireDevtoolsPanel(\n context: GrimoirePanelContext,\n): Promise<GrimoireDevtoolsPanel> {\n // In development the tab keeps Warlock's generated files (book, book maps, indexes) up to date, so\n // the next open is incremental. In production it writes nothing. Agent-written files are only read,\n // and cached routes never boot the app.\n const source = createSnapshotSource(context.root, {\n write: context.mode !== \"production\",\n mode: context.mode ?? \"development\",\n ...(context.adapter === undefined ? {} : { adapter: context.adapter }),\n ...(context.ttlMs === undefined ? {} : { ttlMs: context.ttlMs }),\n });\n\n // In production, start opening the book now so the first tab view is fast.\n if (context.mode === \"production\") source.warm();\n\n const answer =\n <Answer>(read: (snapshot: GrimoireSnapshot, request: GrimoirePanelRequest) => Answer) =>\n async (request: GrimoirePanelRequest): Promise<Answer> =>\n read(await source.get(), request);\n\n return {\n id: \"grimoire\",\n title: \"Grimoire\",\n production: true,\n view: new URL(\"../../ui/grimoire-view.js\", import.meta.url),\n assets: { \"grimoire.css\": new URL(\"../../ui/grimoire.css\", import.meta.url) },\n routes: [\n { path: \"/summary\", handler: answer((snapshot) => data.summary(snapshot)) },\n {\n path: \"/search\",\n handler: answer((snapshot, { query }) => {\n const limit = Number(one(query, \"limit\"));\n\n return data.search(\n snapshot,\n one(query, \"q\") ?? \"\",\n Number.isFinite(limit) && limit > 0 ? limit : undefined,\n );\n }),\n },\n {\n path: \"/file\",\n handler: answer((snapshot, { query }) => data.file(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/impact\",\n handler: answer((snapshot, { query }) => data.impact(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/route\",\n handler: answer((snapshot, { query }) =>\n data.route(snapshot, one(query, \"method\"), one(query, \"path\")),\n ),\n },\n { path: \"/features\", handler: answer((snapshot) => data.features(snapshot)) },\n {\n path: \"/features/:feature\",\n handler: answer((snapshot, { params }) => data.feature(snapshot, params.feature)),\n },\n {\n path: \"/flows/:feature/:flow\",\n handler: answer((snapshot, { params }) => data.flow(snapshot, params.feature, params.flow)),\n },\n { path: \"/apps\", handler: answer((snapshot) => data.apps(snapshot)) },\n {\n path: \"/apps/:app/pages/:page\",\n handler: answer((snapshot, { params }) => data.page(snapshot, params.app, params.page)),\n },\n { path: \"/tasks\", handler: answer((snapshot) => data.tasks(snapshot)) },\n { path: \"/releases\", handler: answer((snapshot) => data.releases(snapshot)) },\n {\n path: \"/releases/:release\",\n handler: answer((snapshot, { params }) => data.release(snapshot, params.release)),\n },\n { path: \"/check\", handler: answer((snapshot) => data.check(snapshot)) },\n {\n path: \"/graph/file\",\n handler: answer((snapshot, { query }) => data.graphOfFile(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/graph/feature/:feature\",\n handler: answer((snapshot, { params }) => data.graphOfFeature(snapshot, params.feature)),\n },\n {\n path: \"/graph/page\",\n handler: answer((snapshot, { query }) =>\n data.graphOfPage(snapshot, one(query, \"app\"), one(query, \"page\")),\n ),\n },\n { path: \"/graph/modules\", handler: answer((snapshot) => data.graphOfModules(snapshot)) },\n ],\n };\n}\n\nexport default grimoireDevtoolsPanel;\n"],"mappings":";;;;;;AAgEA,SAAS,IAAI,OAAsC,MAAkC;CACnF,MAAM,QAAQ,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ire/src/devtools/site.ts"],"mappings":";;;;YAgBY;;EAEV;;EAEA,UAAU,qBAAqB,QAAQ;;EAEvC,WAAW;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"site.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"mappings":";;;;YAgBY;;EAEV;;EAEA,UAAU,qBAAqB,QAAQ;;EAEvC,WAAW;;;;;;;;;;;;;wBAgMS,mBACpB,cACA,UAAS,4BACR"}
|
package/esm/devtools/site.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GRIMOIRE_PATHS, projectPath, toPosixPath } from "../paths/index.mjs";
|
|
2
2
|
import { featureGraph, fileGraph, pageGraph } from "./graphs.mjs";
|
|
3
|
-
import { apps, check, feature, file, flow, graphOfModules, page, releases, summary, tasks } from "./data.mjs";
|
|
3
|
+
import { apps, check, feature, features, file, flow, graphOfModules, page, releases, summary, tasks } from "./data.mjs";
|
|
4
4
|
import { createSnapshotSource } from "./snapshot-source.mjs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
@@ -19,6 +19,7 @@ const uiFolder = fileURLToPath(new URL("../../ui/", import.meta.url));
|
|
|
19
19
|
function buildSiteData(snapshot) {
|
|
20
20
|
const routes = {
|
|
21
21
|
summary: summary(snapshot),
|
|
22
|
+
features: features(snapshot),
|
|
22
23
|
apps: apps(snapshot),
|
|
23
24
|
tasks: tasks(snapshot),
|
|
24
25
|
releases: releases(snapshot),
|
|
@@ -126,14 +127,17 @@ function inlineView(source) {
|
|
|
126
127
|
if (!source.includes(marker)) throw new Error("grimoire-view.js must end with `export default renderGrimoire;`.");
|
|
127
128
|
return source.replace(marker, "");
|
|
128
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* The page's own styles: it defines every devtools panel token (light, then dark under
|
|
132
|
+
* `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.
|
|
133
|
+
* The values keep text AA on `--background` and `--card`.
|
|
134
|
+
*/
|
|
129
135
|
const PAGE_STYLE = `
|
|
130
|
-
:root{color-scheme:light dark;--
|
|
131
|
-
@media (prefers-color-scheme:dark){:root{--
|
|
132
|
-
*{box-sizing:border-box}body{margin:0;background:var(--
|
|
133
|
-
main{max-width:
|
|
134
|
-
.
|
|
135
|
-
.badge{display:inline-block;padding:0 6px;border:1px solid var(--line);border-radius:10px;font-size:12px}
|
|
136
|
-
.empty,.error{padding:12px;color:var(--muted)}.error{color:var(--bad)}
|
|
136
|
+
:root{color-scheme:light dark;--background:#f7f8fa;--foreground:#161b22;--card:#fff;--card-foreground:#161b22;--popover:#fff;--popover-foreground:#161b22;--primary:#1f2937;--primary-foreground:#fff;--secondary:#eceff3;--secondary-foreground:#1f2937;--muted:#eceff3;--muted-foreground:#4b5565;--accent:#e4e9f2;--accent-foreground:#161b22;--destructive:#b42318;--border:#d5dae3;--input:#c3cad6;--ring:#2f5fd0;--radius:10px;--brand:#2757c4;--brand-foreground:#fff;--success:#13693b;--warning:#8a5300;--info:#0b66a3;--chart-1:#2757c4;--chart-2:#13693b;--chart-3:#8a5300;--chart-4:#6d3ac7;--chart-5:#b4306b;font-family:system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
137
|
+
@media (prefers-color-scheme:dark){:root{--background:#14171c;--foreground:#eceff4;--card:#1c2027;--card-foreground:#eceff4;--popover:#1c2027;--popover-foreground:#eceff4;--primary:#eceff4;--primary-foreground:#14171c;--secondary:#272c35;--secondary-foreground:#eceff4;--muted:#272c35;--muted-foreground:#a9b2c1;--accent:#2d3440;--accent-foreground:#eceff4;--destructive:#ff8f86;--border:#343b47;--input:#3f4756;--ring:#8fb0ff;--radius:10px;--brand:#86adff;--brand-foreground:#0d1320;--success:#5fd391;--warning:#f3b25a;--info:#6cc0f5;--chart-1:#86adff;--chart-2:#5fd391;--chart-3:#f3b25a;--chart-4:#b79cff;--chart-5:#ff8fbd}}
|
|
138
|
+
*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}
|
|
139
|
+
main{max-width:1180px;margin:0 auto;padding:16px}
|
|
140
|
+
.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}
|
|
137
141
|
`;
|
|
138
142
|
/** The `index.html` text. */
|
|
139
143
|
function renderSiteHtml(siteData, sources) {
|
|
@@ -148,7 +152,7 @@ function renderSiteHtml(siteData, sources) {
|
|
|
148
152
|
<style>${PAGE_STYLE}${sources.css}</style>
|
|
149
153
|
</head>
|
|
150
154
|
<body>
|
|
151
|
-
<main id="grimoire-root"><p class="empty">
|
|
155
|
+
<main id="grimoire-root"><p class="empty">Opening the book…</p></main>
|
|
152
156
|
<script type="application/json" id="grimoire-data">${json}<\/script>
|
|
153
157
|
<script type="module">${script}<\/script>
|
|
154
158
|
</body>
|
|
@@ -186,5 +190,5 @@ async function exportGrimoireSite(root, options = {}) {
|
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
//#endregion
|
|
189
|
-
export { SITE_FILE_LIMIT, buildSiteData, exportGrimoireSite, inlineView, renderSiteHtml };
|
|
193
|
+
export { PAGE_STYLE, SITE_FILE_LIMIT, buildSiteData, exportGrimoireSite, inlineView, renderSiteHtml };
|
|
190
194
|
//# sourceMappingURL=site.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.mjs","names":["data.summary","data.apps","data.tasks","data.releases","data.check","data.graphOfModules","feature","data.feature","flow","data.flow","page","data.page","file","data.file"],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"sourcesContent":["/**\n * The static export: one folder with an `index.html` that holds the view, the\n * loader, the styles and the data as JSON. It opens from disk (`file://`) or\n * any static host and needs no running app.\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS, projectPath, toPosixPath } from \"../paths\";\nimport * as data from \"./data\";\nimport { featureGraph, fileGraph, pageGraph } from \"./graphs\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\n/** Options of `exportGrimoireSite()`. */\nexport type ExportGrimoireSiteOptions = {\n /** Output folder, project-relative or absolute. Default `grimoire/book/site` (the book writer leaves it alone and git ignores it). */\n outDir?: string;\n /** The adapter to open the book with. Default: the Warlock adapter. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /** An already opened snapshot; skips opening one. */\n snapshot?: GrimoireSnapshot;\n};\n\n/** The most files the export keeps per-file answers for (the most imported first). */\nexport const SITE_FILE_LIMIT = 3000;\n\ntype SearchItem = { type: string; id: string; detail: string | null };\n\nconst uiFolder = fileURLToPath(new URL(\"../../ui/\", import.meta.url));\n\n/** Every answer the static page can give, keyed by the data route it replaces. */\nexport function buildSiteData(snapshot: GrimoireSnapshot) {\n const routes: Record<string, unknown> = {\n summary: data.summary(snapshot),\n apps: data.apps(snapshot),\n tasks: data.tasks(snapshot),\n releases: data.releases(snapshot),\n // The page is meant to be shared: it does not name where the project sits on this machine.\n check: { ...data.check(snapshot), root: \".\" },\n \"graph/modules\": data.graphOfModules(snapshot),\n };\n const search: SearchItem[] = [];\n\n for (const release of snapshot.written.releases) {\n routes[`releases/${release.release.value}`] = release;\n }\n\n for (const feature of snapshot.written.features) {\n const readme = feature.readme;\n\n search.push({ type: \"feature\", id: feature.id, detail: readme?.title.value ?? null });\n const answered = attempt(() => data.feature(snapshot, feature.id));\n\n if (answered !== undefined) routes[`features/${feature.id}`] = answered;\n\n const graph = featureGraph(snapshot, feature.id);\n\n if (graph !== null) routes[`graph/feature/${feature.id}`] = graph;\n\n for (const flow of feature.flows) {\n search.push({ type: \"flow\", id: flow.ref, detail: flow.heading?.value ?? null });\n const flowAnswer = attempt(() => data.flow(snapshot, feature.id, flow.id.value));\n\n if (flowAnswer !== undefined) routes[`flows/${flow.ref}`] = flowAnswer;\n }\n }\n\n for (const app of snapshot.written.apps) {\n const appId = app.id.value;\n\n for (const page of [...app.pages, ...app.screens]) {\n const route = page.route?.value ?? page.screen?.value ?? null;\n const answer = attempt(() => data.page(snapshot, appId, page.id));\n const graph = pageGraph(snapshot, appId, page.id);\n\n for (const key of new Set([page.id, ...(route === null ? [] : [route])])) {\n if (answer !== undefined) routes[`apps/${appId}/pages/${key}`] = answer;\n\n if (graph !== null) routes[`graph/page/${appId}/${key}`] = graph;\n }\n\n if (route !== null)\n search.push({\n type: page.type,\n id: `${appId} ${route}`,\n detail: page.heading?.value ?? null,\n });\n\n for (const block of page.blockFiles) {\n search.push({\n type: \"block\",\n id: `${appId}/${page.id}/${block.id}`,\n detail: block.flow?.value ?? null,\n });\n }\n }\n }\n\n for (const found of snapshot.book.facts.routes ?? []) {\n search.push({\n type: \"route\",\n id: `${found.method} ${found.path}`,\n detail: found.description ?? found.handler,\n });\n }\n\n for (const task of snapshot.collected.tasksIndex.open.concat(\n snapshot.collected.tasksIndex.done,\n )) {\n search.push({ type: \"task\", id: task.id, detail: task.title });\n }\n\n const files: Record<string, { result: unknown; graph: unknown }> = {};\n const ranked = [...snapshot.book.facts.files].sort(\n (left, right) =>\n right.importedBy.length - left.importedBy.length || left.file.localeCompare(right.file),\n );\n\n for (const [index, file] of ranked.entries()) {\n search.push({ type: \"file\", id: file.file, detail: file.about });\n\n if (index >= SITE_FILE_LIMIT) continue;\n\n const result = attempt(() => data.file(snapshot, file.file));\n\n if (result !== undefined) files[file.file] = { result, graph: fileGraph(snapshot, file.file) };\n }\n\n return { routes, files, search };\n}\n\n/** JSON for an inline `<script>`: every `<` is escaped, so no `</script` or `<!--` can appear. */\nfunction inlineJson(value: unknown): string {\n return JSON.stringify(value).replaceAll(\"<\", \"\\\\u003c\");\n}\n\n/** Code for an inline `<script>`: `</script` (in any case) and `<!--` (only possible in strings and comments) are broken up. */\nfunction inlineCode(code: string): string {\n return code.replace(/<\\/(script)/gi, \"<\\\\/$1\").replaceAll(\"<!--\", \"<\\\\!--\");\n}\n\n/** The answer, or `undefined` when the item cannot be answered (the export skips it). */\nfunction attempt<Value>(answer: () => Value): Value | undefined {\n try {\n return answer();\n } catch {\n return undefined;\n }\n}\n\n/** Everything before the page's `export default`, so the view can sit in an inline module. */\nexport function inlineView(source: string): string {\n const marker = \"export default renderGrimoire;\";\n\n if (!source.includes(marker))\n throw new Error(\"grimoire-view.js must end with `export default renderGrimoire;`.\");\n\n return source.replace(marker, \"\");\n}\n\nconst PAGE_STYLE = `\n:root{color-scheme:light dark;--bg:#f5f6f8;--surface:#fff;--line:#d9dde5;--text:#18202a;--muted:#667085;--accent:#285fc1;--good:#167a43;--warn:#a96000;--bad:#b42318;--bar:#5b7cfa;font-family:system-ui,-apple-system,\"Segoe UI\",sans-serif}\n@media (prefers-color-scheme:dark){:root{--bg:#16191f;--surface:#20242c;--line:#383e49;--text:#edf0f5;--muted:#aab3c2;--accent:#83adff;--good:#65d394;--warn:#f6b65a;--bad:#ff9c95;--bar:#8ca7ff}}\n*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font-size:14px}\nmain{max-width:1100px;margin:0 auto;padding:16px}\n.card{background:var(--surface);border:1px solid var(--line);border-radius:8px;padding:12px 14px}\n.badge{display:inline-block;padding:0 6px;border:1px solid var(--line);border-radius:10px;font-size:12px}\n.empty,.error{padding:12px;color:var(--muted)}.error{color:var(--bad)}\n`;\n\n/** The `index.html` text. */\nexport function renderSiteHtml(\n siteData: unknown,\n sources: { view: string; loader: string; css: string },\n): string {\n const json = inlineJson(siteData);\n const script = inlineCode(\n `${inlineView(sources.view)}\\n${sources.loader}\\ngrimoireStaticMount(JSON.parse(document.getElementById(\"grimoire-data\").textContent), document.getElementById(\"grimoire-root\"), renderGrimoire);\\n`,\n );\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Grimoire</title>\n<style>${PAGE_STYLE}${sources.css}</style>\n</head>\n<body>\n<main id=\"grimoire-root\"><p class=\"empty\">Loading the Grimoire…</p></main>\n<script type=\"application/json\" id=\"grimoire-data\">${json}</script>\n<script type=\"module\">${script}</script>\n</body>\n</html>\n`;\n}\n\n/**\n * Write the tab as a static folder for people without the app running.\n *\n * The folder holds `index.html` only: the view, the loader, the styles and\n * the data (as JSON) are inside it, so it opens straight from disk. Open the\n * page and use `#grimoire/...` links; the answers that need the running app\n * (impact of a file) say so in place.\n *\n * @param root Absolute project root.\n * @returns The output folder, project-relative.\n */\nexport async function exportGrimoireSite(\n root: string,\n options: ExportGrimoireSiteOptions = {},\n): Promise<string> {\n // Project-relative from here on; an absolute folder is kept where it is.\n const outDir = projectPath(\n root,\n toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite),\n ).replace(/\\/+$/, \"\");\n const snapshot =\n options.snapshot ??\n (await createSnapshotSource(\n root,\n options.adapter === undefined ? {} : { adapter: options.adapter },\n ).get());\n const [view, loader, css] = await Promise.all(\n [\"grimoire-view.js\", \"grimoire-static.js\", \"grimoire.css\"].map((name) =>\n readFile(path.join(uiFolder, name), \"utf8\"),\n ),\n );\n const html = renderSiteHtml(buildSiteData(snapshot), {\n view: view ?? \"\",\n loader: loader ?? \"\",\n css: css ?? \"\",\n });\n const absolute = path.resolve(root, outDir);\n\n await mkdir(absolute, { recursive: true });\n await writeFile(path.join(absolute, \"index.html\"), html);\n\n return outDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB;AAI/B,MAAM,WAAW,cAAc,IAAI,IAAI,aAAa,YAAY,GAAG,CAAC;;AAGpE,SAAgB,cAAc,UAA4B;CACxD,MAAM,SAAkC;EACtC,SAASA,QAAa,QAAQ;EAC9B,MAAMC,KAAU,QAAQ;EACxB,OAAOC,MAAW,QAAQ;EAC1B,UAAUC,SAAc,QAAQ;EAEhC,OAAO;GAAE,GAAGC,MAAW,QAAQ;GAAG,MAAM;EAAI;EAC5C,iBAAiBC,e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M,QAAQ;EACd,QAAQ,UAAU;EAClB,KAAK,OAAO;CACd,CAAC;CACD,MAAM,WAAW,KAAK,QAAQ,MAAM,MAAM;CAE1C,MAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;CACzC,MAAM,UAAU,KAAK,KAAK,UAAU,YAAY,GAAG,IAAI;CAEvD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"site.mjs","names":["data.summary","data.features","data.apps","data.tasks","data.releases","data.check","data.graphOfModules","feature","data.feature","flow","data.flow","page","data.page","file","data.file"],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"sourcesContent":["/**\n * The static export: one folder with an `index.html` that holds the view, the\n * loader, the styles and the data as JSON. It opens from disk (`file://`) or\n * any static host and needs no running app.\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS, projectPath, toPosixPath } from \"../paths\";\nimport * as data from \"./data\";\nimport { featureGraph, fileGraph, pageGraph } from \"./graphs\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\n/** Options of `exportGrimoireSite()`. */\nexport type ExportGrimoireSiteOptions = {\n /** Output folder, project-relative or absolute. Default `grimoire/book/site` (the book writer leaves it alone and git ignores it). */\n outDir?: string;\n /** The adapter to open the book with. Default: the Warlock adapter. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /** An already opened snapshot; skips opening one. */\n snapshot?: GrimoireSnapshot;\n};\n\n/** The most files the export keeps per-file answers for (the most imported first). */\nexport const SITE_FILE_LIMIT = 3000;\n\ntype SearchItem = { type: string; id: string; detail: string | null };\n\nconst uiFolder = fileURLToPath(new URL(\"../../ui/\", import.meta.url));\n\n/** Every answer the static page can give, keyed by the data route it replaces. */\nexport function buildSiteData(snapshot: GrimoireSnapshot) {\n const routes: Record<string, unknown> = {\n summary: data.summary(snapshot),\n features: data.features(snapshot),\n apps: data.apps(snapshot),\n tasks: data.tasks(snapshot),\n releases: data.releases(snapshot),\n // The page is meant to be shared: it does not name where the project sits on this machine.\n check: { ...data.check(snapshot), root: \".\" },\n \"graph/modules\": data.graphOfModules(snapshot),\n };\n const search: SearchItem[] = [];\n\n for (const release of snapshot.written.releases) {\n routes[`releases/${release.release.value}`] = release;\n }\n\n for (const feature of snapshot.written.features) {\n const readme = feature.readme;\n\n search.push({ type: \"feature\", id: feature.id, detail: readme?.title.value ?? null });\n const answered = attempt(() => data.feature(snapshot, feature.id));\n\n if (answered !== undefined) routes[`features/${feature.id}`] = answered;\n\n const graph = featureGraph(snapshot, feature.id);\n\n if (graph !== null) routes[`graph/feature/${feature.id}`] = graph;\n\n for (const flow of feature.flows) {\n search.push({ type: \"flow\", id: flow.ref, detail: flow.heading?.value ?? null });\n const flowAnswer = attempt(() => data.flow(snapshot, feature.id, flow.id.value));\n\n if (flowAnswer !== undefined) routes[`flows/${flow.ref}`] = flowAnswer;\n }\n }\n\n for (const app of snapshot.written.apps) {\n const appId = app.id.value;\n\n for (const page of [...app.pages, ...app.screens]) {\n const route = page.route?.value ?? page.screen?.value ?? null;\n const answer = attempt(() => data.page(snapshot, appId, page.id));\n const graph = pageGraph(snapshot, appId, page.id);\n\n for (const key of new Set([page.id, ...(route === null ? [] : [route])])) {\n if (answer !== undefined) routes[`apps/${appId}/pages/${key}`] = answer;\n\n if (graph !== null) routes[`graph/page/${appId}/${key}`] = graph;\n }\n\n if (route !== null)\n search.push({\n type: page.type,\n id: `${appId} ${route}`,\n detail: page.heading?.value ?? null,\n });\n\n for (const block of page.blockFiles) {\n search.push({\n type: \"block\",\n id: `${appId}/${page.id}/${block.id}`,\n detail: block.flow?.value ?? null,\n });\n }\n }\n }\n\n for (const found of snapshot.book.facts.routes ?? []) {\n search.push({\n type: \"route\",\n id: `${found.method} ${found.path}`,\n detail: found.description ?? found.handler,\n });\n }\n\n for (const task of snapshot.collected.tasksIndex.open.concat(\n snapshot.collected.tasksIndex.done,\n )) {\n search.push({ type: \"task\", id: task.id, detail: task.title });\n }\n\n const files: Record<string, { result: unknown; graph: unknown }> = {};\n const ranked = [...snapshot.book.facts.files].sort(\n (left, right) =>\n right.importedBy.length - left.importedBy.length || left.file.localeCompare(right.file),\n );\n\n for (const [index, file] of ranked.entries()) {\n search.push({ type: \"file\", id: file.file, detail: file.about });\n\n if (index >= SITE_FILE_LIMIT) continue;\n\n const result = attempt(() => data.file(snapshot, file.file));\n\n if (result !== undefined) files[file.file] = { result, graph: fileGraph(snapshot, file.file) };\n }\n\n return { routes, files, search };\n}\n\n/** JSON for an inline `<script>`: every `<` is escaped, so no `</script` or `<!--` can appear. */\nfunction inlineJson(value: unknown): string {\n return JSON.stringify(value).replaceAll(\"<\", \"\\\\u003c\");\n}\n\n/** Code for an inline `<script>`: `</script` (in any case) and `<!--` (only possible in strings and comments) are broken up. */\nfunction inlineCode(code: string): string {\n return code.replace(/<\\/(script)/gi, \"<\\\\/$1\").replaceAll(\"<!--\", \"<\\\\!--\");\n}\n\n/** The answer, or `undefined` when the item cannot be answered (the export skips it). */\nfunction attempt<Value>(answer: () => Value): Value | undefined {\n try {\n return answer();\n } catch {\n return undefined;\n }\n}\n\n/** Everything before the page's `export default`, so the view can sit in an inline module. */\nexport function inlineView(source: string): string {\n const marker = \"export default renderGrimoire;\";\n\n if (!source.includes(marker))\n throw new Error(\"grimoire-view.js must end with `export default renderGrimoire;`.\");\n\n return source.replace(marker, \"\");\n}\n\n/**\n * The page's own styles: it defines every devtools panel token (light, then dark under\n * `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.\n * The values keep text AA on `--background` and `--card`.\n */\nexport const PAGE_STYLE = `\n:root{color-scheme:light dark;--background:#f7f8fa;--foreground:#161b22;--card:#fff;--card-foreground:#161b22;--popover:#fff;--popover-foreground:#161b22;--primary:#1f2937;--primary-foreground:#fff;--secondary:#eceff3;--secondary-foreground:#1f2937;--muted:#eceff3;--muted-foreground:#4b5565;--accent:#e4e9f2;--accent-foreground:#161b22;--destructive:#b42318;--border:#d5dae3;--input:#c3cad6;--ring:#2f5fd0;--radius:10px;--brand:#2757c4;--brand-foreground:#fff;--success:#13693b;--warning:#8a5300;--info:#0b66a3;--chart-1:#2757c4;--chart-2:#13693b;--chart-3:#8a5300;--chart-4:#6d3ac7;--chart-5:#b4306b;font-family:system-ui,-apple-system,\"Segoe UI\",sans-serif}\n@media (prefers-color-scheme:dark){:root{--background:#14171c;--foreground:#eceff4;--card:#1c2027;--card-foreground:#eceff4;--popover:#1c2027;--popover-foreground:#eceff4;--primary:#eceff4;--primary-foreground:#14171c;--secondary:#272c35;--secondary-foreground:#eceff4;--muted:#272c35;--muted-foreground:#a9b2c1;--accent:#2d3440;--accent-foreground:#eceff4;--destructive:#ff8f86;--border:#343b47;--input:#3f4756;--ring:#8fb0ff;--radius:10px;--brand:#86adff;--brand-foreground:#0d1320;--success:#5fd391;--warning:#f3b25a;--info:#6cc0f5;--chart-1:#86adff;--chart-2:#5fd391;--chart-3:#f3b25a;--chart-4:#b79cff;--chart-5:#ff8fbd}}\n*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}\nmain{max-width:1180px;margin:0 auto;padding:16px}\n.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}\n`;\n\n/** The `index.html` text. */\nexport function renderSiteHtml(\n siteData: unknown,\n sources: { view: string; loader: string; css: string },\n): string {\n const json = inlineJson(siteData);\n const script = inlineCode(\n `${inlineView(sources.view)}\\n${sources.loader}\\ngrimoireStaticMount(JSON.parse(document.getElementById(\"grimoire-data\").textContent), document.getElementById(\"grimoire-root\"), renderGrimoire);\\n`,\n );\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Grimoire</title>\n<style>${PAGE_STYLE}${sources.css}</style>\n</head>\n<body>\n<main id=\"grimoire-root\"><p class=\"empty\">Opening the book…</p></main>\n<script type=\"application/json\" id=\"grimoire-data\">${json}</script>\n<script type=\"module\">${script}</script>\n</body>\n</html>\n`;\n}\n\n/**\n * Write the tab as a static folder for people without the app running.\n *\n * The folder holds `index.html` only: the view, the loader, the styles and\n * the data (as JSON) are inside it, so it opens straight from disk. Open the\n * page and use `#grimoire/...` links; the answers that need the running app\n * (impact of a file) say so in place.\n *\n * @param root Absolute project root.\n * @returns The output folder, project-relative.\n */\nexport async function exportGrimoireSite(\n root: string,\n options: ExportGrimoireSiteOptions = {},\n): Promise<string> {\n // Project-relative from here on; an absolute folder is kept where it is.\n const outDir = projectPath(\n root,\n toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite),\n ).replace(/\\/+$/, \"\");\n const snapshot =\n options.snapshot ??\n (await createSnapshotSource(\n root,\n options.adapter === undefined ? {} : { adapter: options.adapter },\n ).get());\n const [view, loader, css] = await Promise.all(\n [\"grimoire-view.js\", \"grimoire-static.js\", \"grimoire.css\"].map((name) =>\n readFile(path.join(uiFolder, name), \"utf8\"),\n ),\n );\n const html = renderSiteHtml(buildSiteData(snapshot), {\n view: view ?? \"\",\n loader: loader ?? \"\",\n css: css ?? \"\",\n });\n const absolute = path.resolve(root, outDir);\n\n await mkdir(absolute, { recursive: true });\n await writeFile(path.join(absolute, \"index.html\"), html);\n\n return outDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB;AAI/B,MAAM,WAAW,cAAc,IAAI,IAAI,aAAa,YAAY,GAAG,CAAC;;AAGpE,SAAgB,cAAc,UAA4B;CACxD,MAAM,SAAkC;EACtC,SAASA,QAAa,QAAQ;EAC9B,UAAUC,SAAc,QAAQ;EAChC,MAAMC,KAAU,QAAQ;EACxB,OAAOC,MAAW,QAAQ;EAC1B,UAAUC,SAAc,QAAQ;EAEhC,OAAO;GAAE,GAAGC,MAAW,QAAQ;GAAG,MAAM;EAAI;EAC5C,i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AG;EACnD,MAAM,QAAQ;EACd,QAAQ,UAAU;EAClB,KAAK,OAAO;CACd,CAAC;CACD,MAAM,WAAW,KAAK,QAAQ,MAAM,MAAM;CAE1C,MAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;CACzC,MAAM,UAAU,KAAK,KAAK,UAAU,YAAY,GAAG,IAAI;CAEvD,OAAO;AACT"}
|
|
@@ -6,20 +6,48 @@ import { stat } from "node:fs/promises";
|
|
|
6
6
|
//#region ../../packages/grimoire/src/devtools/snapshot-source.ts
|
|
7
7
|
/**
|
|
8
8
|
* Where the panel's routes get the snapshot: opened once with
|
|
9
|
-
* `routes: "cached"` (a devtools request never boots the app)
|
|
10
|
-
* memory
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
9
|
+
* `routes: "cached"` (a devtools request never boots the app) and kept in
|
|
10
|
+
* memory. Concurrent requests share one open. A change stamp (the book
|
|
11
|
+
* manifest plus the agent-written folders and indexes, a few `stat` calls and
|
|
12
|
+
* no directory walk) tells when the book changed.
|
|
13
|
+
*
|
|
14
|
+
* - Production (`mode: "production"`): a snapshot is reused until the stamp
|
|
15
|
+
* changes, with no time limit, unless `ttlMs` is set. A request that finds
|
|
16
|
+
* the stamp changed waits for the new open. `warm()` opens the book ahead
|
|
17
|
+
* of the first request.
|
|
18
|
+
* - Development: the snapshot is reused for a short window (2 s, or five times
|
|
19
|
+
* the last open when that is longer, so a slow open on a large app is not
|
|
20
|
+
* repeated on every view; written files change while an agent works). A
|
|
21
|
+
* request that finds the stamp changed waits for the new open. After the
|
|
22
|
+
* window, with the stamp unchanged (a file edited in place), the cached
|
|
23
|
+
* snapshot is served at once and one background open refreshes it (stale
|
|
24
|
+
* while revalidate).
|
|
25
|
+
*
|
|
26
|
+
* An open that fails keeps serving the old snapshot; its error surfaces on a
|
|
27
|
+
* request only when there is no snapshot at all. The panel passes
|
|
28
|
+
* `write: true` in development, so the generated book stays current and the
|
|
29
|
+
* next open is incremental; with `write: false` a stored book behind the
|
|
30
|
+
* sources is rebuilt in memory on every open.
|
|
16
31
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
/** Files and folders whose modified time moves when the book or an agent-written file is added, removed or regenerated. */
|
|
33
|
+
const STAMPED = [
|
|
34
|
+
GRIMOIRE_PATHS.bookManifest,
|
|
35
|
+
GRIMOIRE_PATHS.featuresIndex,
|
|
36
|
+
GRIMOIRE_PATHS.tasksIndex,
|
|
37
|
+
GRIMOIRE_PATHS.features,
|
|
38
|
+
GRIMOIRE_PATHS.apps,
|
|
39
|
+
GRIMOIRE_PATHS.openTasks,
|
|
40
|
+
GRIMOIRE_PATHS.doneTasks,
|
|
41
|
+
GRIMOIRE_PATHS.releases
|
|
42
|
+
];
|
|
43
|
+
async function changeStamp(root) {
|
|
44
|
+
return (await Promise.all(STAMPED.map(async (entry) => {
|
|
45
|
+
try {
|
|
46
|
+
return (await stat(path.join(root, ...entry.split("/")))).mtimeMs;
|
|
47
|
+
} catch {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
}))).join(",");
|
|
23
51
|
}
|
|
24
52
|
async function loadAdapter(option) {
|
|
25
53
|
if (option === void 0) {
|
|
@@ -32,6 +60,7 @@ async function loadAdapter(option) {
|
|
|
32
60
|
function createSnapshotSource(root, options = {}) {
|
|
33
61
|
let cached = null;
|
|
34
62
|
let opening = null;
|
|
63
|
+
const keepUntilChanged = options.mode === "production" && options.ttlMs === void 0;
|
|
35
64
|
const reuseFor = (took) => options.ttlMs ?? Math.max(2e3, took * 5);
|
|
36
65
|
async function open() {
|
|
37
66
|
const started = Date.now();
|
|
@@ -44,23 +73,39 @@ function createSnapshotSource(root, options = {}) {
|
|
|
44
73
|
cached = {
|
|
45
74
|
snapshot,
|
|
46
75
|
at,
|
|
47
|
-
stamp: await
|
|
76
|
+
stamp: await changeStamp(root),
|
|
48
77
|
took: at - started
|
|
49
78
|
};
|
|
50
79
|
return snapshot;
|
|
51
80
|
}
|
|
81
|
+
/** The open in flight, or a new one; concurrent callers share it. */
|
|
82
|
+
function ensureOpening() {
|
|
83
|
+
opening ??= open().finally(() => {
|
|
84
|
+
opening = null;
|
|
85
|
+
});
|
|
86
|
+
return opening;
|
|
87
|
+
}
|
|
52
88
|
return {
|
|
53
89
|
async get() {
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
90
|
+
if (cached === null) return ensureOpening();
|
|
91
|
+
const known = cached;
|
|
92
|
+
const changed = await changeStamp(root) !== known.stamp;
|
|
93
|
+
if (changed || options.mode === "production") {
|
|
94
|
+
if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) return known.snapshot;
|
|
95
|
+
return ensureOpening().catch(() => known.snapshot);
|
|
96
|
+
}
|
|
97
|
+
if (Date.now() - known.at < reuseFor(known.took)) return known.snapshot;
|
|
98
|
+
ensureOpening().catch(() => {});
|
|
99
|
+
return known.snapshot;
|
|
61
100
|
},
|
|
62
101
|
invalidate() {
|
|
63
102
|
cached = null;
|
|
103
|
+
},
|
|
104
|
+
warm() {
|
|
105
|
+
if (cached === null) ensureOpening().catch(() => {});
|
|
106
|
+
},
|
|
107
|
+
async idle() {
|
|
108
|
+
await opening?.catch(() => {});
|
|
64
109
|
}
|
|
65
110
|
};
|
|
66
111
|
}
|
|
@@ -1 +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)
|
|
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) and kept in\n * memory. Concurrent requests share one open. A change stamp (the book\n * manifest plus the agent-written folders and indexes, a few `stat` calls and\n * no directory walk) tells when the book changed.\n *\n * - Production (`mode: \"production\"`): a snapshot is reused until the stamp\n * changes, with no time limit, unless `ttlMs` is set. A request that finds\n * the stamp changed waits for the new open. `warm()` opens the book ahead\n * of the first request.\n * - Development: the snapshot is reused for a short window (2 s, or five times\n * the last open when that is longer, so a slow open on a large app is not\n * repeated on every view; written files change while an agent works). A\n * request that finds the stamp changed waits for the new open. After the\n * window, with the stamp unchanged (a file edited in place), the cached\n * snapshot is served at once and one background open refreshes it (stale\n * while revalidate).\n *\n * An open that fails keeps serving the old snapshot; its error surfaces on a\n * request only when there is no snapshot at all. The panel passes\n * `write: true` in development, so the generated book stays current and the\n * next open is incremental; with `write: false` a stored book behind the\n * sources is rebuilt in memory on every open.\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 book did not change (ms).\n * Default in development: 2000, or five times as long as the last open took\n * when that is longer. Default in production: no limit (reused until the\n * book changes).\n */\n ttlMs?: number;\n /** Where the source runs. `\"production\"` keeps a snapshot until the book changes. Default: `\"development\"`. */\n mode?: \"development\" | \"production\";\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 /** Start opening the book now, so the first `get()` is fast. Failures are ignored here and surface on `get()`. */\n warm(): void;\n /** Resolves when no open is running (specs and shutdown). Never rejects. */\n idle(): Promise<void>;\n};\n\n/** Files and folders whose modified time moves when the book or an agent-written file is added, removed or regenerated. */\nconst STAMPED = [\n GRIMOIRE_PATHS.bookManifest,\n GRIMOIRE_PATHS.featuresIndex,\n GRIMOIRE_PATHS.tasksIndex,\n GRIMOIRE_PATHS.features,\n GRIMOIRE_PATHS.apps,\n GRIMOIRE_PATHS.openTasks,\n GRIMOIRE_PATHS.doneTasks,\n GRIMOIRE_PATHS.releases,\n];\n\nasync function changeStamp(root: string): Promise<string> {\n const times = await Promise.all(\n STAMPED.map(async (entry) => {\n try {\n return (await stat(path.join(root, ...entry.split(\"/\")))).mtimeMs;\n } catch {\n return 0;\n }\n }),\n );\n\n return times.join(\",\");\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: string; took: number } | null = null;\n let opening: Promise<GrimoireSnapshot> | null = null;\n\n const keepUntilChanged = options.mode === \"production\" && options.ttlMs === undefined;\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 changeStamp(root), took: at - started };\n\n return snapshot;\n }\n\n /** The open in flight, or a new one; concurrent callers share it. */\n function ensureOpening(): Promise<GrimoireSnapshot> {\n opening ??= open().finally(() => {\n opening = null;\n });\n\n return opening;\n }\n\n return {\n async get() {\n if (cached === null) return ensureOpening();\n\n const known = cached;\n const changed = (await changeStamp(root)) !== known.stamp;\n\n if (changed || options.mode === \"production\") {\n if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) {\n return known.snapshot;\n }\n\n // A failed open keeps the old snapshot; the next request tries again.\n return ensureOpening().catch(() => known.snapshot);\n }\n\n if (Date.now() - known.at < reuseFor(known.took)) return known.snapshot;\n\n // Development, nothing known to have changed: serve the old snapshot now and refresh behind it.\n ensureOpening().catch(() => {});\n\n return known.snapshot;\n },\n invalidate() {\n cached = null;\n },\n warm() {\n if (cached === null) ensureOpening().catch(() => {});\n },\n async idle() {\n await opening?.catch(() => {});\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAM,UAAU;CACd,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AAEA,eAAe,YAAY,MAA+B;CAWxD,QAAO,MAVa,QAAQ,IAC1B,QAAQ,IAAI,OAAO,UAAU;EAC3B,IAAI;GACF,QAAQ,MAAM,KAAK,KAAK,KAAK,MAAM,GAAG,MAAM,MAAM,GAAG,CAAC,CAAC,EAAC,CAAE;EAC5D,QAAQ;GACN,OAAO;EACT;CACF,CAAC,CACH,EAEY,CAAC,KAAK,GAAG;AACvB;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,mBAAmB,QAAQ,SAAS,gBAAgB,QAAQ,UAAU;CAC5E,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,YAAY,IAAI;GAAG,MAAM,KAAK;EAAQ;EAE5E,OAAO;CACT;;CAGA,SAAS,gBAA2C;EAClD,YAAY,KAAK,CAAC,CAAC,cAAc;GAC/B,UAAU;EACZ,CAAC;EAED,OAAO;CACT;CAEA,OAAO;EACL,MAAM,MAAM;GACV,IAAI,WAAW,MAAM,OAAO,cAAc;GAE1C,MAAM,QAAQ;GACd,MAAM,UAAW,MAAM,YAAY,IAAI,MAAO,MAAM;GAEpD,IAAI,WAAW,QAAQ,SAAS,cAAc;IAC5C,IAAI,CAAC,YAAY,oBAAoB,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,IAC9E,OAAO,MAAM;IAIf,OAAO,cAAc,CAAC,CAAC,YAAY,MAAM,QAAQ;GACnD;GAEA,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,GAAG,OAAO,MAAM;GAG/D,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;GAE9B,OAAO,MAAM;EACf;EACA,aAAa;GACX,SAAS;EACX;EACA,OAAO;GACL,IAAI,WAAW,MAAM,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;EACrD;EACA,MAAM,OAAO;GACX,MAAM,SAAS,YAAY,CAAC,CAAC;EAC/B;CACF;AACF"}
|
package/llms-full.txt
CHANGED
|
@@ -693,6 +693,8 @@ From `@warlock.js/grimoire/vitest`: `grimoireReporter` records the last result o
|
|
|
693
693
|
From `@warlock.js/grimoire/devtools`: `grimoireDevtoolsPanel` (the default export) is the Grimoire
|
|
694
694
|
tab for `@warlock.js/devtools`, listed in `panels` of `src/config/devtools.ts`;
|
|
695
695
|
`exportGrimoireSite` writes the same view as a static site.
|
|
696
|
+
The tab keeps its snapshot until the book changes in production and refreshes it in the background in
|
|
697
|
+
development; set `ttlMs` with `panels: [["@warlock.js/grimoire/devtools", { ttlMs: 60_000 }]]`.
|
|
696
698
|
|
|
697
699
|
|
|
698
700
|
## write-a-feature `@warlock.js/grimoire/skills/write-a-feature/SKILL.md`
|
package/package.json
CHANGED
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"environment": "server"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@warlock.js/core": "5.
|
|
30
|
-
"@warlock.js/web": "5.
|
|
29
|
+
"@warlock.js/core": "5.57.0",
|
|
30
|
+
"@warlock.js/web": "5.57.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
"@warlock.js/web": {
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"version": "5.
|
|
37
|
+
"version": "5.57.0",
|
|
38
38
|
"type": "module",
|
|
39
39
|
"main": "./esm/index.mjs",
|
|
40
40
|
"module": "./esm/index.mjs",
|
|
@@ -135,3 +135,5 @@ From `@warlock.js/grimoire/vitest`: `grimoireReporter` records the last result o
|
|
|
135
135
|
From `@warlock.js/grimoire/devtools`: `grimoireDevtoolsPanel` (the default export) is the Grimoire
|
|
136
136
|
tab for `@warlock.js/devtools`, listed in `panels` of `src/config/devtools.ts`;
|
|
137
137
|
`exportGrimoireSite` writes the same view as a static site.
|
|
138
|
+
The tab keeps its snapshot until the book changes in production and refreshes it in the background in
|
|
139
|
+
development; set `ttlMs` with `panels: [["@warlock.js/grimoire/devtools", { ttlMs: 60_000 }]]`.
|