@warlock.js/grimoire 5.56.0 → 5.58.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 +35 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +2 -1
- package/esm/book/build.mjs.map +1 -1
- package/esm/book/render.mjs +10 -0
- package/esm/book/render.mjs.map +1 -1
- package/esm/bookmap/build.d.mts.map +1 -1
- package/esm/bookmap/build.mjs +2 -2
- package/esm/bookmap/build.mjs.map +1 -1
- package/esm/bookmap/steps.mjs +53 -38
- package/esm/bookmap/steps.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +4 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/criteria.mjs +21 -2
- package/esm/check/rules/criteria.mjs.map +1 -1
- package/esm/check/rules/screenshots.mjs +57 -0
- package/esm/check/rules/screenshots.mjs.map +1 -0
- package/esm/codes/codes.d.mts +12 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +6 -0
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +6 -0
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/book.d.mts +2 -0
- package/esm/contracts/book.d.mts.map +1 -1
- package/esm/contracts/book.mjs.map +1 -1
- package/esm/contracts/bookmap.d.mts +19 -1
- package/esm/contracts/bookmap.d.mts.map +1 -1
- package/esm/contracts/snapshot.d.mts +11 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/test-results.d.mts +34 -0
- package/esm/contracts/test-results.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +44 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/data.mjs +126 -4
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/index.d.mts +31 -1
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +94 -5
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/product-map.d.mts +14 -0
- package/esm/devtools/product-map.d.mts.map +1 -0
- package/esm/devtools/product-map.mjs +385 -0
- package/esm/devtools/product-map.mjs.map +1 -0
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +97 -21
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +71 -22
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/graph/index.d.mts +10 -1
- package/esm/graph/index.d.mts.map +1 -1
- package/esm/graph/index.mjs +3 -2
- package/esm/graph/index.mjs.map +1 -1
- package/esm/index.d.mts +4 -4
- package/esm/paths/index.d.mts +2 -0
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +3 -1
- package/esm/paths/index.mjs.map +1 -1
- package/esm/scry/compact.mjs +169 -0
- package/esm/scry/compact.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +7 -1
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +12 -1
- package/esm/scry/query.mjs.map +1 -1
- package/esm/test-results/index.d.mts +7 -2
- package/esm/test-results/index.d.mts.map +1 -1
- package/esm/test-results/index.mjs +79 -12
- package/esm/test-results/index.mjs.map +1 -1
- package/esm/vitest/index.d.mts +6 -0
- package/esm/vitest/index.d.mts.map +1 -1
- package/esm/vitest/index.mjs +22 -6
- package/esm/vitest/index.mjs.map +1 -1
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +6 -2
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/mcp-tools.mjs +48 -12
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +4 -2
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/written/apps.mjs +4 -2
- package/esm/written/apps.mjs.map +1 -1
- package/esm/written/features.mjs +119 -6
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/markdown.mjs +66 -1
- package/esm/written/markdown.mjs.map +1 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +1 -1
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/llms-full.txt +77 -2
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +5 -0
- package/skills/describe-an-app/SKILL.md +12 -0
- package/skills/record-a-change/SKILL.md +8 -0
- package/skills/use-the-grimoire/SKILL.md +15 -0
- package/skills/write-a-feature/SKILL.md +37 -2
- package/ui/grimoire-static.js +4 -0
- package/ui/grimoire-view.js +2283 -428
- package/ui/grimoire.css +1036 -45
- package/ui/product-map.css +636 -0
- package/ui/product-map.js +817 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-map.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/product-map.ts"],"sourcesContent":["/**\n * The product map answers: the Grimoire in plain words for readers who do\n * not read code. Built from the written files, the book maps, the test\n * results, the open tasks, the changelogs and (when the devtools monitor\n * reports them) the captured errors. A shared answer (`options.shared`)\n * carries no file paths, code or test names.\n */\nimport { checkGrimoire } from \"../check\";\nimport { normalizeRoutePath } from \"../bookmap\";\nimport type { FlowBookmap, FlowBookmapCriterion } from \"../contracts/bookmap\";\nimport type { GrimoireCheckReport } from \"../contracts/findings\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type {\n WrittenApp,\n WrittenFeature,\n WrittenFlow,\n WrittenScreenshot,\n WrittenStep,\n} from \"../contracts/written\";\nimport { compactStep, flowOrder, neighboursOf } from \"../scry/compact\";\nimport type {\n ProductAppearance,\n ProductFeatureAnswer,\n ProductFeatureCard,\n ProductFlowAnswer,\n ProductFlowCard,\n ProductHealth,\n ProductMapAnswer,\n ProductPlannedItem,\n ProductRelease,\n ProductScreenshot,\n ProductStoryStep,\n} from \"./answers\";\nimport { GrimoirePanelError } from \"./data\";\n\n/** One captured error group as devtools hands it to a panel: counts only. */\nexport type ProductErrorSummary = {\n /** The route pattern (`/products/:id`), or `null` outside a request. */\n route: string | null;\n status: number | null;\n name: string | null;\n source: \"request\" | \"log\";\n count: number;\n firstSeen: number;\n lastSeen: number;\n};\n\n/** How the product map answers are built. */\nexport type ProductMapOptions = {\n /** `true` for a read-only share link: no developer detail. */\n shared: boolean;\n /** Captured error groups, or `null` when the monitor reports none. */\n errors: readonly ProductErrorSummary[] | null;\n};\n\n/** How far back captured errors count (one hour). */\nconst ERROR_WINDOW_MS = 3_600_000;\n\ntype ErrorCount = { count: number; lastSeen: number };\n\n/** Everything the answers share, computed once per request. */\ntype Context = {\n snapshot: GrimoireSnapshot;\n options: ProductMapOptions;\n report: GrimoireCheckReport;\n featureErrors: Map<string, number>;\n flowErrors: Map<string, number>;\n captured: { features: Map<string, ErrorCount>; flows: Map<string, ErrorCount> } | null;\n resultsMissing: boolean;\n};\n\nfunction addCount(map: Map<string, ErrorCount>, key: string, group: ProductErrorSummary): void {\n const known = map.get(key);\n\n map.set(key, {\n count: (known?.count ?? 0) + group.count,\n lastSeen: Math.max(known?.lastSeen ?? 0, group.lastSeen),\n });\n}\n\n/** Map the last hour's error groups to the features and flows that use their route. */\nfunction captureErrors(\n snapshot: GrimoireSnapshot,\n errors: readonly ProductErrorSummary[],\n now: number,\n): NonNullable<Context[\"captured\"]> {\n const features = new Map<string, ErrorCount>();\n const flows = new Map<string, ErrorCount>();\n const routes = snapshot.book.facts.routes ?? [];\n\n for (const group of errors) {\n if (group.route === null || group.lastSeen < now - ERROR_WINDOW_MS) continue;\n\n const path = normalizeRoutePath(group.route);\n\n for (const route of routes) {\n if (normalizeRoutePath(route.path) !== path) continue;\n\n const file = route.handlerFile ?? route.sourceFile;\n const owner = file === null ? null : (snapshot.ownership.files[file]?.owner ?? null);\n\n if (owner !== null) addCount(features, owner, group);\n }\n\n for (const feature of snapshot.written.features) {\n for (const flow of feature.flows) {\n const hit = flow.steps.some(\n (step) =>\n (step.type === \"route\" &&\n step.route !== null &&\n normalizeRoutePath(step.route.path) === path) ||\n (step.type === \"page\" && normalizeRoutePath(step.target) === path),\n );\n\n if (hit) addCount(flows, flow.ref, group);\n }\n }\n }\n\n return { features, flows };\n}\n\n/**\n * The check report of a snapshot, run once per snapshot. A share link reaches\n * these answers without an account, so a page view must not run the whole\n * check again; a changed book opens a new snapshot and a new report.\n */\nconst reports = new WeakMap<GrimoireSnapshot, GrimoireCheckReport>();\n\nfunction reportOf(snapshot: GrimoireSnapshot): GrimoireCheckReport {\n let report = reports.get(snapshot);\n\n if (report === undefined) {\n report = checkGrimoire(snapshot);\n reports.set(snapshot, report);\n }\n\n return report;\n}\n\nfunction contextOf(snapshot: GrimoireSnapshot, options: ProductMapOptions): Context {\n const report = reportOf(snapshot);\n const featureErrors = new Map<string, number>();\n const flowErrors = new Map<string, number>();\n\n for (const finding of report.findings) {\n if (finding.expected || finding.severity !== \"error\") continue;\n\n const flow = finding.subject.flow;\n const feature = finding.subject.feature ?? flow?.split(\"/\")[0] ?? null;\n\n if (feature !== null) featureErrors.set(feature, (featureErrors.get(feature) ?? 0) + 1);\n if (flow !== null) flowErrors.set(flow, (flowErrors.get(flow) ?? 0) + 1);\n }\n\n return {\n snapshot,\n options,\n report,\n featureErrors,\n flowErrors,\n captured:\n options.errors === null ? null : captureErrors(snapshot, options.errors, Date.now()),\n resultsMissing: snapshot.results === null && snapshot.proofs.length > 0,\n };\n}\n\nconst plural = (count: number, word: string): string => `${count} ${word}${count === 1 ? \"\" : \"s\"}`;\n\n/** The traffic light and its sentence (the rules of the product map). */\nfunction healthOf(\n context: Context,\n criteria: readonly Pick<FlowBookmapCriterion, \"status\">[],\n checkErrors: number,\n captured: ErrorCount | undefined,\n): ProductHealth {\n const counts = { total: criteria.length, pass: 0, fail: 0, stale: 0, notRun: 0, noTest: 0 };\n\n for (const criterion of criteria) {\n if (criterion.status === \"pass\") counts.pass += 1;\n else if (criterion.status === \"fail\") counts.fail += 1;\n else if (criterion.status === \"stale\") counts.stale += 1;\n else if (criterion.status === \"not-run\") counts.notRun += 1;\n else counts.noTest += 1;\n }\n\n const errors =\n context.captured === null ? null : { count: captured?.count ?? 0, lastSeen: captured?.lastSeen ?? null };\n const recent = errors?.count ?? 0;\n const total = counts.total;\n let level: ProductHealth[\"level\"];\n let reason: string;\n\n if (counts.fail > 0) {\n level = \"problem\";\n reason = `${counts.fail} of ${total} checks fail`;\n } else if (checkErrors > 0) {\n level = \"problem\";\n reason = `The check found ${plural(checkErrors, \"error\")}`;\n } else if (counts.noTest > 0) {\n level = \"attention\";\n reason = `${counts.noTest} of ${total} checks have no test`;\n } else if (context.resultsMissing && total > 0) {\n level = \"attention\";\n reason = \"No test results recorded\";\n } else if (counts.stale > 0 || counts.notRun > 0) {\n level = \"attention\";\n reason = \"Tests have not run since they changed\";\n } else if (recent > 0) {\n level = \"attention\";\n reason = `${plural(recent, \"error\")} in the last hour`;\n } else if (total > 0) {\n level = \"good\";\n reason = `All ${total} checks pass`;\n } else {\n level = \"unknown\";\n reason = \"No checks written yet\";\n }\n\n return { level, reason, criteria: counts, errors };\n}\n\nfunction featureHealth(context: Context, feature: WrittenFeature): ProductHealth {\n const criteria = feature.flows.flatMap(\n (flow) => context.snapshot.collected.flows[flow.ref]?.criteria ?? [],\n );\n\n return healthOf(\n context,\n criteria,\n context.featureErrors.get(feature.id) ?? 0,\n context.captured?.features.get(feature.id),\n );\n}\n\nfunction flowHealthOf(context: Context, flow: WrittenFlow): ProductHealth {\n return healthOf(\n context,\n context.snapshot.collected.flows[flow.ref]?.criteria ?? [],\n context.flowErrors.get(flow.ref) ?? 0,\n context.captured?.flows.get(flow.ref),\n );\n}\n\nfunction findFeature(snapshot: GrimoireSnapshot, id: string | undefined): WrittenFeature {\n if (id === undefined || id === \"\") throw new GrimoirePanelError(400, 'Missing \"feature\".');\n\n const feature = snapshot.written.features.find((item) => item.id === id);\n\n if (feature === undefined || feature.readme === null) {\n throw new GrimoirePanelError(404, `No feature \"${id}\" is written in grimoire/features.`);\n }\n\n return feature;\n}\n\nfunction audienceOf(feature: WrittenFeature): string[] {\n const listed = (feature.readme?.audience ?? []).map((item) => item.value);\n\n if (listed.length > 0) return listed;\n\n return [...new Set(feature.flows.map((flow) => flow.who.value))];\n}\n\nfunction card(context: Context, feature: WrittenFeature): ProductFeatureCard {\n const readme = feature.readme;\n\n if (readme === null) throw new Error(\"A feature card needs a README.\");\n\n return {\n id: feature.id,\n title: readme.title.value,\n summary: readme.summary,\n audience: audienceOf(feature),\n apps: readme.apps.map((app) => app.value),\n status: readme.status.value,\n version: readme.version.value,\n flows: feature.flows.length,\n health: featureHealth(context, feature),\n };\n}\n\n/** `GET /product`: the feature map. */\nexport function productMap(snapshot: GrimoireSnapshot, options: ProductMapOptions): ProductMapAnswer {\n const context = contextOf(snapshot, options);\n\n return {\n builtAt: snapshot.book.manifest.builtAt,\n features: snapshot.written.features\n .filter((feature) => feature.readme !== null)\n .map((feature) => card(context, feature)),\n apps: snapshot.written.apps.map((app) => ({\n id: app.id.value,\n type: app.type.value,\n title: app.heading?.value ?? null,\n })),\n developer: !options.shared,\n };\n}\n\nconst slugOf = (text: string): string =>\n text\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n\nfunction screenshotsOf(items: readonly WrittenScreenshot[]): ProductScreenshot[] {\n return items.flatMap((item) => (item.path === null ? [] : [{ src: item.path, alt: item.alt }]));\n}\n\n/** Where the flows are shown, with the screenshots of the block (else of the page). */\nfunction appearancesOf(snapshot: GrimoireSnapshot, bookmaps: readonly FlowBookmap[]): ProductAppearance[] {\n const seen = new Set<string>();\n const list: ProductAppearance[] = [];\n const apps = new Map<string, WrittenApp>(snapshot.written.apps.map((app) => [app.id.value, app]));\n\n for (const bookmap of bookmaps) {\n for (const shown of bookmap.shownBy) {\n const key = `${shown.app}|${shown.type}|${shown.id}|${shown.block}|${bookmap.ref}`;\n\n if (seen.has(key)) continue;\n\n seen.add(key);\n\n const app = apps.get(shown.app);\n let title: string | null = null;\n let route: string | null = null;\n let screenshots: ProductScreenshot[] = [];\n\n if (app !== undefined && shown.type === \"layout\") {\n title = app.layouts.find((layout) => layout.id === shown.id)?.heading?.value ?? null;\n } else if (app !== undefined) {\n const page = [...app.pages, ...app.screens].find((item) => item.id === shown.id);\n\n if (page !== undefined) {\n title = page.heading?.value ?? null;\n route = page.route?.value ?? page.screen?.value ?? null;\n\n const block =\n page.blockFiles.find((item) => item.id === slugOf(shown.block)) ??\n page.blockFiles.find((item) => item.flow?.value === bookmap.ref);\n\n screenshots = screenshotsOf(block?.screenshots ?? []);\n\n if (screenshots.length === 0) screenshots = screenshotsOf(page.screenshots);\n }\n }\n\n list.push({\n app: shown.app,\n type: shown.type,\n id: shown.id,\n title,\n route,\n block: shown.block,\n flow: bookmap.ref,\n screenshots,\n });\n }\n }\n\n return list;\n}\n\nfunction releasesOf(snapshot: GrimoireSnapshot, feature: WrittenFeature): ProductRelease[] {\n const dates = new Map(snapshot.written.releases.map((item) => [item.release.value, item.date.value]));\n const entries = feature.changelog?.entries ?? [];\n // Unreleased entries first, then the stamped ones in file order (newest first).\n const ordered = [\n ...entries.filter((entry) => entry.release === null),\n ...entries.filter((entry) => entry.release !== null),\n ];\n const groups = new Map<string, ProductRelease>();\n\n for (const entry of ordered) {\n const key = `${entry.version.value}|${entry.release ?? \"\"}`;\n let group = groups.get(key);\n\n if (group === undefined) {\n group = {\n version: entry.version.value,\n release: entry.release,\n date: entry.date ?? (entry.release === null ? null : (dates.get(entry.release) ?? null)),\n changes: [],\n };\n groups.set(key, group);\n }\n\n group.changes.push({ word: entry.word, flow: entry.flow, text: entry.text });\n }\n\n return [...groups.values()];\n}\n\nfunction plannedOf(snapshot: GrimoireSnapshot, feature: string): ProductPlannedItem[] {\n return snapshot.collected.tasksIndex.open\n .filter((task) => task.feature === feature)\n .map((task) => ({\n id: task.id,\n title: task.title,\n type: task.type,\n status: task.status,\n flow: task.flow === null ? null : task.flow.replace(`${feature}/`, \"\"),\n }));\n}\n\nfunction flowCard(context: Context, flow: WrittenFlow): ProductFlowCard {\n return {\n id: flow.id.value,\n ref: flow.ref,\n title: flow.heading?.value ?? flow.id.value,\n summary: flow.summary,\n who: flow.who.value,\n status: flow.status.value,\n health: flowHealthOf(context, flow),\n };\n}\n\n/** `GET /product/features/:feature`. */\nexport function productFeature(\n snapshot: GrimoireSnapshot,\n id: string | undefined,\n options: ProductMapOptions,\n): ProductFeatureAnswer {\n const feature = findFeature(snapshot, id);\n const readme = feature.readme;\n\n if (readme === null) throw new Error(\"unreachable\");\n\n const context = contextOf(snapshot, options);\n const bookmaps = feature.flows.flatMap((flow) => {\n const bookmap = snapshot.collected.flows[flow.ref];\n\n return bookmap === undefined ? [] : [bookmap];\n });\n const own = snapshot.collected.features[feature.id];\n const unexpected = context.report.findings.filter(\n (finding) =>\n (finding.subject.feature ?? finding.subject.flow?.split(\"/\")[0]) === feature.id,\n );\n const unexpectedNow = unexpected.filter((finding) => !finding.expected);\n const errors = unexpectedNow.filter((finding) => finding.severity === \"error\").length;\n\n return {\n feature: {\n id: feature.id,\n title: readme.title.value,\n summary: readme.summary,\n why: readme.why,\n audience: audienceOf(feature),\n apps: readme.apps.map((app) => app.value),\n status: readme.status.value,\n version: readme.version.value,\n updated: readme.updated.value,\n origin: readme.origin?.value ?? null,\n },\n flows: flowOrder(feature).map((flow) => flowCard(context, flow)),\n appearances: appearancesOf(snapshot, bookmaps),\n releases: releasesOf(snapshot, feature),\n planned: plannedOf(snapshot, feature.id),\n health: featureHealth(context, feature),\n developer: options.shared\n ? null\n : {\n folders: readme.folders.map((folder) => folder.value),\n routes: (own?.routes ?? []).map(({ file: _file, ...route }) => route),\n files: own?.own.length ?? 0,\n findings: {\n errors,\n warnings: unexpectedNow.length - errors,\n expected: unexpected.length - unexpectedNow.length,\n },\n },\n };\n}\n\nconst STEP_WORDS: Record<WrittenStep[\"type\"], (target: string) => string> = {\n page: (target) => `Open ${target}`,\n route: () => \"The server takes the request\",\n mail: (target) => `An email \"${target}\" is sent`,\n notification: (target) => `A notification \"${target}\" is sent`,\n job: (target) => `The job \"${target}\" runs in the background`,\n event: (target) => `The event \"${target}\" happens`,\n \"outside service\": (target) => `The outside service \"${target}\" is used`,\n affects: (target) => `This also affects ${target}`,\n};\n\nfunction storyOf(flow: WrittenFlow): ProductStoryStep[] {\n if (flow.story.length > 0) {\n return flow.story.map((step) => ({\n index: step.index,\n text: step.text,\n screenshots: screenshotsOf(step.screenshots),\n derived: false,\n }));\n }\n\n return flow.steps.map((step) => ({\n index: step.index,\n text: step.note ?? STEP_WORDS[step.type](step.target),\n screenshots: [],\n derived: true,\n }));\n}\n\nconst DOES_NOT_APPLY = /^does not apply\\b[:\\s—-]*/i;\n\n/** `GET /product/flows/:feature/:flow`. */\nexport function productFlow(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n options: ProductMapOptions,\n): ProductFlowAnswer {\n const feature = findFeature(snapshot, featureId);\n const flow = feature.flows.find((item) => item.id.value === flowId);\n\n if (flow === undefined) {\n throw new GrimoirePanelError(404, `No flow \"${flowId ?? \"\"}\" in feature \"${feature.id}\".`);\n }\n\n const context = contextOf(snapshot, options);\n const bookmap = snapshot.collected.flows[flow.ref];\n const { previous, next } = neighboursOf(feature, flow.id.value);\n\n return {\n flow: {\n ref: flow.ref,\n feature: feature.id,\n featureTitle: feature.readme?.title.value ?? feature.id,\n title: flow.heading?.value ?? flow.id.value,\n summary: flow.summary,\n who: flow.who.value,\n status: flow.status.value,\n since: flow.since.value,\n },\n story: storyOf(flow),\n proof: (bookmap?.criteria ?? []).map((criterion) => ({\n id: criterion.id,\n text: criterion.text,\n status: criterion.status,\n tests: options.shared ? null : criterion.tests,\n })),\n cases: flow.cases.map((item) => {\n const answer = item.doesNotApply ? item.answer.replace(DOES_NOT_APPLY, \"\").trim() : item.answer;\n\n return {\n question: item.question,\n answer: answer === \"\" ? \"Does not apply\" : answer,\n handled: !item.doesNotApply,\n criteria: item.criteria,\n };\n }),\n appearances: bookmap === undefined ? [] : appearancesOf(snapshot, [bookmap]),\n previous,\n next,\n health: flowHealthOf(context, flow),\n developer: options.shared\n ? null\n : {\n steps: (bookmap?.steps ?? []).map((step) => compactStep(snapshot, feature, step, flow)),\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwDA,MAAM,kBAAkB;AAexB,SAAS,SAAS,KAA8B,KAAa,OAAkC;CAC7F,MAAM,QAAQ,IAAI,IAAI,GAAG;CAEzB,IAAI,IAAI,KAAK;EACX,QAAQ,OAAO,SAAS,KAAK,MAAM;EACnC,UAAU,KAAK,IAAI,OAAO,YAAY,GAAG,MAAM,QAAQ;CACzD,CAAC;AACH;;AAGA,SAAS,cACP,UACA,QACA,KACkC;CAClC,MAAM,2BAAW,IAAI,IAAwB;CAC7C,MAAM,wBAAQ,IAAI,IAAwB;CAC1C,MAAM,SAAS,SAAS,KAAK,MAAM,UAAU,CAAC;CAE9C,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,UAAU,QAAQ,MAAM,WAAW,MAAM,iBAAiB;EAEpE,MAAM,OAAO,mBAAmB,MAAM,KAAK;EAE3C,KAAK,MAAM,SAAS,QAAQ;GAC1B,IAAI,mBAAmB,MAAM,IAAI,MAAM,MAAM;GAE7C,MAAM,OAAO,MAAM,eAAe,MAAM;GACxC,MAAM,QAAQ,SAAS,OAAO,OAAQ,SAAS,UAAU,MAAM,KAAK,EAAE,SAAS;GAE/E,IAAI,UAAU,MAAM,SAAS,UAAU,OAAO,KAAK;EACrD;EAEA,KAAK,MAAM,WAAW,SAAS,QAAQ,UACrC,KAAK,MAAM,QAAQ,QAAQ,OASzB,IARY,KAAK,MAAM,MACpB,SACE,KAAK,SAAS,WACb,KAAK,UAAU,QACf,mBAAmB,KAAK,MAAM,IAAI,MAAM,QACzC,KAAK,SAAS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,gBAAgB,EAAE,CAAC,CAAC,KAAK,IAAI,KAAK;GAEzF,OAAO;IACL,UAAU,KAAK;IACf,QAAQ,WAAW,KAAK,mBAAmB;IAC3C,SAAS,CAAC,KAAK;IACf,UAAU,KAAK;GACjB;EACF,CAAC;EACD,aAAa,YAAY,SAAY,CAAC,IAAI,cAAc,UAAU,CAAC,OAAO,CAAC;EAC3E;EACA;EACA,QAAQ,aAAa,SAAS,IAAI;EAClC,WAAW,QAAQ,SACf,OACA,EACE,QAAQ,SAAS,SAAS,CAAC,EAAC,CAAE,KAAK,SAAS,YAAY,UAAU,SAAS,MAAM,IAAI,CAAC,EACxF;CACN;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"site.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"mappings":";;;;YAiBY;;EAEV;;EAEA,UAAU,qBAAqB,QAAQ;;EAEvC,WAAW;;;;;;;;;;;;;wBAwSS,mBACpB,cACA,UAAS,4BACR"}
|
package/esm/devtools/site.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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,
|
|
3
|
+
import { apps, check, checkGroups, feature, features, file, flowAnswer, graphOfModules, page, releases, summary, tasks } from "./data.mjs";
|
|
4
|
+
import { productFeature, productFlow, productMap } from "./product-map.mjs";
|
|
4
5
|
import { createSnapshotSource } from "./snapshot-source.mjs";
|
|
5
6
|
import path from "node:path";
|
|
6
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
import { copyFile, mkdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
|
|
7
8
|
import { fileURLToPath } from "node:url";
|
|
8
9
|
|
|
9
10
|
//#region ../../packages/grimoire/src/devtools/site.ts
|
|
@@ -19,6 +20,7 @@ const uiFolder = fileURLToPath(new URL("../../ui/", import.meta.url));
|
|
|
19
20
|
function buildSiteData(snapshot) {
|
|
20
21
|
const routes = {
|
|
21
22
|
summary: summary(snapshot),
|
|
23
|
+
features: features(snapshot),
|
|
22
24
|
apps: apps(snapshot),
|
|
23
25
|
tasks: tasks(snapshot),
|
|
24
26
|
releases: releases(snapshot),
|
|
@@ -28,6 +30,14 @@ function buildSiteData(snapshot) {
|
|
|
28
30
|
},
|
|
29
31
|
"graph/modules": graphOfModules(snapshot)
|
|
30
32
|
};
|
|
33
|
+
const productOptions = {
|
|
34
|
+
shared: false,
|
|
35
|
+
errors: null
|
|
36
|
+
};
|
|
37
|
+
const productAnswer = attempt(() => productMap(snapshot, productOptions));
|
|
38
|
+
const groups = attempt(() => checkGroups(snapshot));
|
|
39
|
+
if (productAnswer !== void 0) routes.product = productAnswer;
|
|
40
|
+
if (groups !== void 0) routes["check/groups"] = groups;
|
|
31
41
|
const search = [];
|
|
32
42
|
for (const release of snapshot.written.releases) routes[`releases/${release.release.value}`] = release;
|
|
33
43
|
for (const feature$1 of snapshot.written.features) {
|
|
@@ -41,14 +51,18 @@ function buildSiteData(snapshot) {
|
|
|
41
51
|
if (answered !== void 0) routes[`features/${feature$1.id}`] = answered;
|
|
42
52
|
const graph = featureGraph(snapshot, feature$1.id);
|
|
43
53
|
if (graph !== null) routes[`graph/feature/${feature$1.id}`] = graph;
|
|
44
|
-
|
|
54
|
+
const product = attempt(() => productFeature(snapshot, feature$1.id, productOptions));
|
|
55
|
+
if (product !== void 0) routes[`product/features/${feature$1.id}`] = product;
|
|
56
|
+
for (const flow of feature$1.flows) {
|
|
45
57
|
search.push({
|
|
46
58
|
type: "flow",
|
|
47
|
-
id: flow
|
|
48
|
-
detail: flow
|
|
59
|
+
id: flow.ref,
|
|
60
|
+
detail: flow.heading?.value ?? null
|
|
49
61
|
});
|
|
50
|
-
const flowAnswer = attempt(() =>
|
|
51
|
-
|
|
62
|
+
const flowAnswer$1 = attempt(() => flowAnswer(snapshot, feature$1.id, flow.id.value));
|
|
63
|
+
const productFlowAnswer = attempt(() => productFlow(snapshot, feature$1.id, flow.id.value, productOptions));
|
|
64
|
+
if (flowAnswer$1 !== void 0) routes[`flows/${flow.ref}`] = flowAnswer$1;
|
|
65
|
+
if (productFlowAnswer !== void 0) routes[`product/flows/${flow.ref}`] = productFlowAnswer;
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
for (const app of snapshot.written.apps) {
|
|
@@ -112,6 +126,51 @@ function inlineJson(value) {
|
|
|
112
126
|
function inlineCode(code) {
|
|
113
127
|
return code.replace(/<\/(script)/gi, "<\\/$1").replaceAll("<!--", "<\\!--");
|
|
114
128
|
}
|
|
129
|
+
/** The image types the export copies (the same list the devtools panel serves). */
|
|
130
|
+
const SCREENSHOT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
131
|
+
".png",
|
|
132
|
+
".jpg",
|
|
133
|
+
".jpeg",
|
|
134
|
+
".webp",
|
|
135
|
+
".gif"
|
|
136
|
+
]);
|
|
137
|
+
/** Every `WrittenScreenshot.path` in the written files, once each. */
|
|
138
|
+
function collectScreenshotPaths(written) {
|
|
139
|
+
const found = /* @__PURE__ */ new Set();
|
|
140
|
+
const walk = (value) => {
|
|
141
|
+
if (Array.isArray(value)) for (const item of value) walk(item);
|
|
142
|
+
else if (value !== null && typeof value === "object") {
|
|
143
|
+
const record = value;
|
|
144
|
+
if (typeof record.path === "string" && typeof record.written === "string" && typeof record.alt === "string") found.add(record.path);
|
|
145
|
+
for (const item of Object.values(record)) walk(item);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
walk(written);
|
|
149
|
+
return [...found].sort();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Copy the screenshots the written files use into `<out>/screenshots/`. A path that leaves
|
|
153
|
+
* `grimoire/screenshots/`, has another extension or does not exist is skipped.
|
|
154
|
+
*
|
|
155
|
+
* @returns The paths that were copied.
|
|
156
|
+
*/
|
|
157
|
+
async function copyScreenshots(root, outFolder, paths) {
|
|
158
|
+
const folder = await realpath(path.join(root, GRIMOIRE_PATHS.screenshots)).catch(() => null);
|
|
159
|
+
const copied = [];
|
|
160
|
+
if (folder === null) return copied;
|
|
161
|
+
for (const written of paths) {
|
|
162
|
+
const segments = written.split("/");
|
|
163
|
+
if (written === "" || written.includes("\\") || written.includes("\0") || path.isAbsolute(written) || segments.some((segment) => segment === "" || segment === "." || segment === "..") || !SCREENSHOT_EXTENSIONS.has(path.extname(written).toLowerCase())) continue;
|
|
164
|
+
const source = await realpath(path.join(folder, ...segments)).catch(() => null);
|
|
165
|
+
if (source === null || !source.startsWith(folder + path.sep)) continue;
|
|
166
|
+
if (!(await stat(source)).isFile()) continue;
|
|
167
|
+
const target = path.join(outFolder, "screenshots", ...segments);
|
|
168
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
169
|
+
await copyFile(source, target);
|
|
170
|
+
copied.push(written);
|
|
171
|
+
}
|
|
172
|
+
return copied;
|
|
173
|
+
}
|
|
115
174
|
/** The answer, or `undefined` when the item cannot be answered (the export skips it). */
|
|
116
175
|
function attempt(answer) {
|
|
117
176
|
try {
|
|
@@ -126,29 +185,41 @@ function inlineView(source) {
|
|
|
126
185
|
if (!source.includes(marker)) throw new Error("grimoire-view.js must end with `export default renderGrimoire;`.");
|
|
127
186
|
return source.replace(marker, "");
|
|
128
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* The product map module as inline code: its `export` keywords are removed and the Grimoire view
|
|
190
|
+
* finds it as `globalThis.grimoireProductMap`.
|
|
191
|
+
*/
|
|
192
|
+
function inlineProductMap(source) {
|
|
193
|
+
const marker = "export default renderProductMap;";
|
|
194
|
+
if (!source.includes(marker)) throw new Error("product-map.js must end with `export default renderProductMap;`.");
|
|
195
|
+
return `${source.replace(marker, "").replace(/^export (async )?function /gm, "$1function ")}\nglobalThis.grimoireProductMap = { productMapView };\n`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The page's own styles: it defines every devtools panel token (light, then dark under
|
|
199
|
+
* `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.
|
|
200
|
+
* The values keep text AA on `--background` and `--card`.
|
|
201
|
+
*/
|
|
129
202
|
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)}
|
|
203
|
+
: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}
|
|
204
|
+
@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}}
|
|
205
|
+
*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}
|
|
206
|
+
main{max-width:1180px;margin:0 auto;padding:16px}
|
|
207
|
+
.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}
|
|
137
208
|
`;
|
|
138
209
|
/** The `index.html` text. */
|
|
139
210
|
function renderSiteHtml(siteData, sources) {
|
|
140
211
|
const json = inlineJson(siteData);
|
|
141
|
-
const script = inlineCode(`${inlineView(sources.view)}\n${sources.loader}\ngrimoireStaticMount(JSON.parse(document.getElementById("grimoire-data").textContent), document.getElementById("grimoire-root"), renderGrimoire);\n`);
|
|
212
|
+
const script = inlineCode(`${sources.productMap === void 0 ? "" : inlineProductMap(sources.productMap)}${inlineView(sources.view)}\n${sources.loader}\ngrimoireStaticMount(JSON.parse(document.getElementById("grimoire-data").textContent), document.getElementById("grimoire-root"), renderGrimoire);\n`);
|
|
142
213
|
return `<!doctype html>
|
|
143
214
|
<html lang="en">
|
|
144
215
|
<head>
|
|
145
216
|
<meta charset="utf-8">
|
|
146
217
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
147
218
|
<title>Grimoire</title>
|
|
148
|
-
<style>${PAGE_STYLE}${sources.css}</style>
|
|
219
|
+
<style>${PAGE_STYLE}${sources.css}${sources.productCss ?? ""}</style>
|
|
149
220
|
</head>
|
|
150
221
|
<body>
|
|
151
|
-
<main id="grimoire-root"><p class="empty">
|
|
222
|
+
<main id="grimoire-root"><p class="empty">Opening the book…</p></main>
|
|
152
223
|
<script type="application/json" id="grimoire-data">${json}<\/script>
|
|
153
224
|
<script type="module">${script}<\/script>
|
|
154
225
|
</body>
|
|
@@ -169,22 +240,27 @@ function renderSiteHtml(siteData, sources) {
|
|
|
169
240
|
async function exportGrimoireSite(root, options = {}) {
|
|
170
241
|
const outDir = projectPath(root, toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite)).replace(/\/+$/, "");
|
|
171
242
|
const snapshot = options.snapshot ?? await createSnapshotSource(root, options.adapter === void 0 ? {} : { adapter: options.adapter }).get();
|
|
172
|
-
const [view, loader, css] = await Promise.all([
|
|
243
|
+
const [view, loader, css, productMapSource, productCss] = await Promise.all([
|
|
173
244
|
"grimoire-view.js",
|
|
174
245
|
"grimoire-static.js",
|
|
175
|
-
"grimoire.css"
|
|
246
|
+
"grimoire.css",
|
|
247
|
+
"product-map.js",
|
|
248
|
+
"product-map.css"
|
|
176
249
|
].map((name) => readFile(path.join(uiFolder, name), "utf8")));
|
|
177
250
|
const html = renderSiteHtml(buildSiteData(snapshot), {
|
|
178
251
|
view: view ?? "",
|
|
179
252
|
loader: loader ?? "",
|
|
180
|
-
css: css ?? ""
|
|
253
|
+
css: css ?? "",
|
|
254
|
+
productMap: productMapSource ?? "",
|
|
255
|
+
productCss: productCss ?? ""
|
|
181
256
|
});
|
|
182
257
|
const absolute = path.resolve(root, outDir);
|
|
183
258
|
await mkdir(absolute, { recursive: true });
|
|
184
259
|
await writeFile(path.join(absolute, "index.html"), html);
|
|
260
|
+
await copyScreenshots(root, absolute, collectScreenshotPaths(snapshot.written));
|
|
185
261
|
return outDir;
|
|
186
262
|
}
|
|
187
263
|
|
|
188
264
|
//#endregion
|
|
189
|
-
export { SITE_FILE_LIMIT, buildSiteData, exportGrimoireSite, inlineView, renderSiteHtml };
|
|
265
|
+
export { PAGE_STYLE, SITE_FILE_LIMIT, buildSiteData, collectScreenshotPaths, copyScreenshots, exportGrimoireSite, inlineProductMap, inlineView, renderSiteHtml };
|
|
190
266
|
//# 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"],"m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MAAM,WACJ,QAAQ,YACP,MAAM,qBACL,MACA,QAAQ,YAAY,SAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ,CAClE,CAAC,CAAC,IAAI;CACR,MAAM,CAAC,MAAM,QAAQ,OAAO,MAAM,QAAQ,IACxC;EAAC;EAAoB;EAAsB;CAAc,CAAC,CAAC,KAAK,SAC9D,SAAS,KAAK,KAAK,UAAU,IAAI,GAAG,MAAM,CAC5C,CACF;CACA,MAAM,OAAO,eAAe,cAAc,QAAQ,GAAG;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"}
|
|
1
|
+
{"version":3,"file":"site.mjs","names":["data.summary","data.features","data.apps","data.tasks","data.releases","data.check","data.graphOfModules","data.checkGroups","feature","data.feature","flowAnswer","data.flowAnswer","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 { copyFile, mkdir, readFile, realpath, stat, 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 { productFeature, productFlow, productMap } from \"./product-map\";\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 // The static page is the signed-in view: developer detail stays, and no monitor reports errors.\n const productOptions = { shared: false, errors: null } as const;\n const productAnswer = attempt(() => productMap(snapshot, productOptions));\n const groups = attempt(() => data.checkGroups(snapshot));\n\n if (productAnswer !== undefined) routes.product = productAnswer;\n\n if (groups !== undefined) routes[\"check/groups\"] = groups;\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 const product = attempt(() => productFeature(snapshot, feature.id, productOptions));\n\n if (product !== undefined) routes[`product/features/${feature.id}`] = product;\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.flowAnswer(snapshot, feature.id, flow.id.value));\n const productFlowAnswer = attempt(() =>\n productFlow(snapshot, feature.id, flow.id.value, productOptions),\n );\n\n if (flowAnswer !== undefined) routes[`flows/${flow.ref}`] = flowAnswer;\n\n if (productFlowAnswer !== undefined) routes[`product/flows/${flow.ref}`] = productFlowAnswer;\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 image types the export copies (the same list the devtools panel serves). */\nconst SCREENSHOT_EXTENSIONS = new Set([\".png\", \".jpg\", \".jpeg\", \".webp\", \".gif\"]);\n\n/** Every `WrittenScreenshot.path` in the written files, once each. */\nexport function collectScreenshotPaths(written: unknown): string[] {\n const found = new Set<string>();\n const walk = (value: unknown): void => {\n if (Array.isArray(value)) {\n for (const item of value) walk(item);\n } else if (value !== null && typeof value === \"object\") {\n const record = value as Record<string, unknown>;\n\n if (\n typeof record.path === \"string\" &&\n typeof record.written === \"string\" &&\n typeof record.alt === \"string\"\n )\n found.add(record.path);\n\n for (const item of Object.values(record)) walk(item);\n }\n };\n\n walk(written);\n\n return [...found].sort();\n}\n\n/**\n * Copy the screenshots the written files use into `<out>/screenshots/`. A path that leaves\n * `grimoire/screenshots/`, has another extension or does not exist is skipped.\n *\n * @returns The paths that were copied.\n */\nexport async function copyScreenshots(\n root: string,\n outFolder: string,\n paths: readonly string[],\n): Promise<string[]> {\n const folder = await realpath(path.join(root, GRIMOIRE_PATHS.screenshots)).catch(() => null);\n const copied: string[] = [];\n\n if (folder === null) return copied;\n\n for (const written of paths) {\n const segments = written.split(\"/\");\n\n if (\n written === \"\" ||\n written.includes(\"\\\\\") ||\n written.includes(\"\\0\") ||\n path.isAbsolute(written) ||\n segments.some((segment) => segment === \"\" || segment === \".\" || segment === \"..\") ||\n !SCREENSHOT_EXTENSIONS.has(path.extname(written).toLowerCase())\n )\n continue;\n\n const source = await realpath(path.join(folder, ...segments)).catch(() => null);\n\n if (source === null || !source.startsWith(folder + path.sep)) continue;\n\n if (!(await stat(source)).isFile()) continue;\n\n const target = path.join(outFolder, \"screenshots\", ...segments);\n\n await mkdir(path.dirname(target), { recursive: true });\n await copyFile(source, target);\n copied.push(written);\n }\n\n return copied;\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 product map module as inline code: its `export` keywords are removed and the Grimoire view\n * finds it as `globalThis.grimoireProductMap`.\n */\nexport function inlineProductMap(source: string): string {\n const marker = \"export default renderProductMap;\";\n\n if (!source.includes(marker))\n throw new Error(\"product-map.js must end with `export default renderProductMap;`.\");\n\n return `${source.replace(marker, \"\").replace(/^export (async )?function /gm, \"$1function \")}\\nglobalThis.grimoireProductMap = { productMapView };\\n`;\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; productMap?: string; productCss?: string },\n): string {\n const json = inlineJson(siteData);\n const script = inlineCode(\n `${sources.productMap === undefined ? \"\" : inlineProductMap(sources.productMap)}${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}${sources.productCss ?? \"\"}</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, productMapSource, productCss] = await Promise.all(\n [\n \"grimoire-view.js\",\n \"grimoire-static.js\",\n \"grimoire.css\",\n \"product-map.js\",\n \"product-map.css\",\n ].map((name) => readFile(path.join(uiFolder, name), \"utf8\")),\n );\n const html = renderSiteHtml(buildSiteData(snapshot), {\n view: view ?? \"\",\n loader: loader ?? \"\",\n css: css ?? \"\",\n productMap: productMapSource ?? \"\",\n productCss: productCss ?? \"\",\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 await copyScreenshots(root, absolute, collectScreenshotPaths(snapshot.written));\n\n return outDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,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,iBAAiBC,eAAoB,QAAQ;CAC/C;CAEA,MAAM,iBAAiB;EAAE,QAAQ;EAAO,QAAQ;CAAK;CACr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UAAU,uBAAuB,SAAS,OAAO,CAAC;CAE9E,OAAO;AACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRIMOIRE_PATHS } from "../paths/index.mjs";
|
|
2
|
+
import { resolveResultsFile } from "../test-results/index.mjs";
|
|
2
3
|
import { openGrimoire } from "../workspace/index.mjs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { stat } from "node:fs/promises";
|
|
@@ -6,20 +7,49 @@ import { stat } from "node:fs/promises";
|
|
|
6
7
|
//#region ../../packages/grimoire/src/devtools/snapshot-source.ts
|
|
7
8
|
/**
|
|
8
9
|
* 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
|
-
*
|
|
10
|
+
* `routes: "cached"` (a devtools request never boots the app) and kept in
|
|
11
|
+
* memory. Concurrent requests share one open. A change stamp (the book
|
|
12
|
+
* manifest plus the agent-written folders and indexes, a few `stat` calls and
|
|
13
|
+
* no directory walk) tells when the book changed.
|
|
14
|
+
*
|
|
15
|
+
* - Production (`mode: "production"`): a snapshot is reused until the stamp
|
|
16
|
+
* changes, with no time limit, unless `ttlMs` is set. A request that finds
|
|
17
|
+
* the stamp changed waits for the new open. `warm()` opens the book ahead
|
|
18
|
+
* of the first request.
|
|
19
|
+
* - Development: the snapshot is reused for a short window (2 s, or five times
|
|
20
|
+
* the last open when that is longer, so a slow open on a large app is not
|
|
21
|
+
* repeated on every view; written files change while an agent works). A
|
|
22
|
+
* request that finds the stamp changed waits for the new open. After the
|
|
23
|
+
* window, with the stamp unchanged (a file edited in place), the cached
|
|
24
|
+
* snapshot is served at once and one background open refreshes it (stale
|
|
25
|
+
* while revalidate).
|
|
26
|
+
*
|
|
27
|
+
* An open that fails keeps serving the old snapshot; its error surfaces on a
|
|
28
|
+
* request only when there is no snapshot at all. The panel passes
|
|
29
|
+
* `write: true` in development, so the generated book stays current and the
|
|
30
|
+
* next open is incremental; with `write: false` a stored book behind the
|
|
31
|
+
* sources is rebuilt in memory on every open.
|
|
16
32
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
/** Files and folders whose modified time moves when the book or an agent-written file is added, removed or regenerated. */
|
|
34
|
+
const STAMPED = [
|
|
35
|
+
GRIMOIRE_PATHS.bookManifest,
|
|
36
|
+
GRIMOIRE_PATHS.featuresIndex,
|
|
37
|
+
GRIMOIRE_PATHS.tasksIndex,
|
|
38
|
+
GRIMOIRE_PATHS.features,
|
|
39
|
+
GRIMOIRE_PATHS.apps,
|
|
40
|
+
GRIMOIRE_PATHS.openTasks,
|
|
41
|
+
GRIMOIRE_PATHS.doneTasks,
|
|
42
|
+
GRIMOIRE_PATHS.releases
|
|
43
|
+
];
|
|
44
|
+
async function changeStamp(root, resultsFile) {
|
|
45
|
+
const files = [...STAMPED.map((entry) => path.join(root, ...entry.split("/"))), resultsFile];
|
|
46
|
+
return (await Promise.all(files.map(async (file) => {
|
|
47
|
+
try {
|
|
48
|
+
return (await stat(file)).mtimeMs;
|
|
49
|
+
} catch {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
}))).join(",");
|
|
23
53
|
}
|
|
24
54
|
async function loadAdapter(option) {
|
|
25
55
|
if (option === void 0) {
|
|
@@ -32,35 +62,54 @@ async function loadAdapter(option) {
|
|
|
32
62
|
function createSnapshotSource(root, options = {}) {
|
|
33
63
|
let cached = null;
|
|
34
64
|
let opening = null;
|
|
65
|
+
const resultsFile = resolveResultsFile(root, options.testResultsFile);
|
|
66
|
+
const keepUntilChanged = options.mode === "production" && options.ttlMs === void 0;
|
|
35
67
|
const reuseFor = (took) => options.ttlMs ?? Math.max(2e3, took * 5);
|
|
36
68
|
async function open() {
|
|
37
69
|
const started = Date.now();
|
|
38
70
|
const adapter = await loadAdapter(options.adapter);
|
|
39
71
|
const snapshot = await openGrimoire(root, adapter, {
|
|
40
72
|
routes: "cached",
|
|
41
|
-
write: options.write ?? false
|
|
73
|
+
write: options.write ?? false,
|
|
74
|
+
...options.testResultsFile === void 0 ? {} : { testResultsFile: options.testResultsFile }
|
|
42
75
|
});
|
|
43
76
|
const at = Date.now();
|
|
44
77
|
cached = {
|
|
45
78
|
snapshot,
|
|
46
79
|
at,
|
|
47
|
-
stamp: await
|
|
80
|
+
stamp: await changeStamp(root, resultsFile),
|
|
48
81
|
took: at - started
|
|
49
82
|
};
|
|
50
83
|
return snapshot;
|
|
51
84
|
}
|
|
85
|
+
/** The open in flight, or a new one; concurrent callers share it. */
|
|
86
|
+
function ensureOpening() {
|
|
87
|
+
opening ??= open().finally(() => {
|
|
88
|
+
opening = null;
|
|
89
|
+
});
|
|
90
|
+
return opening;
|
|
91
|
+
}
|
|
52
92
|
return {
|
|
53
93
|
async get() {
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
94
|
+
if (cached === null) return ensureOpening();
|
|
95
|
+
const known = cached;
|
|
96
|
+
const changed = await changeStamp(root, resultsFile) !== known.stamp;
|
|
97
|
+
if (changed || options.mode === "production") {
|
|
98
|
+
if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) return known.snapshot;
|
|
99
|
+
return ensureOpening().catch(() => known.snapshot);
|
|
100
|
+
}
|
|
101
|
+
if (Date.now() - known.at < reuseFor(known.took)) return known.snapshot;
|
|
102
|
+
ensureOpening().catch(() => {});
|
|
103
|
+
return known.snapshot;
|
|
61
104
|
},
|
|
62
105
|
invalidate() {
|
|
63
106
|
cached = null;
|
|
107
|
+
},
|
|
108
|
+
warm() {
|
|
109
|
+
if (cached === null) ensureOpening().catch(() => {});
|
|
110
|
+
},
|
|
111
|
+
async idle() {
|
|
112
|
+
await opening?.catch(() => {});
|
|
64
113
|
}
|
|
65
114
|
};
|
|
66
115
|
}
|
|
@@ -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 { resolveResultsFile } from \"../test-results\";\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 * Where the test results are read from (project-relative or absolute).\n * Default `grimoire/book/test-results.json`. The file's modified time is part\n * of the change stamp, so results written after the snapshot opened show up\n * without a restart.\n */\n testResultsFile?: string;\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, resultsFile: string): Promise<string> {\n const files = [...STAMPED.map((entry) => path.join(root, ...entry.split(\"/\"))), resultsFile];\n const times = await Promise.all(\n files.map(async (file) => {\n try {\n return (await stat(file)).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 resultsFile = resolveResultsFile(root, options.testResultsFile);\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 ...(options.testResultsFile === undefined ? {} : { testResultsFile: options.testResultsFile }),\n });\n\n const at = Date.now();\n\n cached = { snapshot, at, stamp: await changeStamp(root, resultsFile), 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, resultsFile)) !== 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,MAAM,UAAU;CACd,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AAEA,eAAe,YAAY,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CACT;CAEA,OAAO;EACL,MAAM,MAAM;GACV,IAAI,WAAW,MAAM,OAAO,cAAc;GAE1C,MAAM,QAAQ;GACd,MAAM,UAAW,MAAM,YAAY,MAAM,WAAW,MAAO,MAAM;GAEjE,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/esm/graph/index.d.mts
CHANGED
|
@@ -4,11 +4,20 @@ import { BookFile } from "../contracts/adapter.mjs";
|
|
|
4
4
|
export type FileGraph = ReadonlyMap<string, Pick<BookFile, "file" | "imports" | "importedBy">>;
|
|
5
5
|
/** Index files by path. */
|
|
6
6
|
export declare function fileGraph(files: readonly Pick<BookFile, "file" | "imports" | "importedBy">[]): FileGraph;
|
|
7
|
+
/** Options of {@link importClosure}. */
|
|
8
|
+
export type ImportClosureOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Leave out import edges marked `typeOnly` (erased at runtime), so a page
|
|
11
|
+
* that imports a type through a barrel does not reach the barrel's server
|
|
12
|
+
* files. Default `false`: every edge is followed.
|
|
13
|
+
*/
|
|
14
|
+
skipTypeOnly?: boolean;
|
|
15
|
+
};
|
|
7
16
|
/**
|
|
8
17
|
* The start files and every project file they import, transitively, sorted.
|
|
9
18
|
* Files not in the graph are left out. Cycles are walked once.
|
|
10
19
|
*/
|
|
11
|
-
export declare function importClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
20
|
+
export declare function importClosure(graph: FileGraph, start: readonly string[], options?: ImportClosureOptions): string[];
|
|
12
21
|
/** The start files and every project file that imports them, transitively, sorted. */
|
|
13
22
|
export declare function importerClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
14
23
|
//#endregion
|
|
@@ -1 +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
|
|
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;;YAyBS;;;;;;EAMV;;;;;;wBAOc,cACd,OAAO,WACP,0BACA,UAAS;;wBAYK,gBAAgB,OAAO,WAAW"}
|
package/esm/graph/index.mjs
CHANGED
|
@@ -18,8 +18,9 @@ function walk(graph, start, next) {
|
|
|
18
18
|
* The start files and every project file they import, transitively, sorted.
|
|
19
19
|
* Files not in the graph are left out. Cycles are walked once.
|
|
20
20
|
*/
|
|
21
|
-
function importClosure(graph, start) {
|
|
22
|
-
|
|
21
|
+
function importClosure(graph, start, options = {}) {
|
|
22
|
+
const skipTypeOnly = options.skipTypeOnly === true;
|
|
23
|
+
return walk(graph, start, (file) => (graph.get(file)?.imports ?? []).flatMap((entry) => entry.file === null || skipTypeOnly && entry.typeOnly === true ? [] : [entry.file]));
|
|
23
24
|
}
|
|
24
25
|
/** The start files and every project file that imports them, transitively, sorted. */
|
|
25
26
|
function importerClosure(graph, start) {
|
package/esm/graph/index.mjs.map
CHANGED
|
@@ -1 +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
|
|
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/** Options of {@link importClosure}. */\nexport type ImportClosureOptions = {\n /**\n * Leave out import edges marked `typeOnly` (erased at runtime), so a page\n * that imports a type through a barrel does not reach the barrel's server\n * files. Default `false`: every edge is followed.\n */\n skipTypeOnly?: boolean;\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(\n graph: FileGraph,\n start: readonly string[],\n options: ImportClosureOptions = {},\n): string[] {\n const skipTypeOnly = options.skipTypeOnly === true;\n\n return walk(graph, start, (file) =>\n (graph.get(file)?.imports ?? []).flatMap((entry) =>\n entry.file === null || (skipTypeOnly && entry.typeOnly === true) ? [] : [entry.file],\n ),\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,U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