@warlock.js/grimoire 0.0.0-stage → 5.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +55 -2
- package/esm/apps/check-apps.mjs +207 -0
- package/esm/apps/check-apps.mjs.map +1 -0
- package/esm/apps/index.mjs +4 -0
- package/esm/apps/match-apps.d.mts +12 -0
- package/esm/apps/match-apps.d.mts.map +1 -0
- package/esm/apps/match-apps.mjs +30 -0
- package/esm/apps/match-apps.mjs.map +1 -0
- package/esm/book/build.d.mts +14 -0
- package/esm/book/build.d.mts.map +1 -0
- package/esm/book/build.mjs +300 -0
- package/esm/book/build.mjs.map +1 -0
- package/esm/book/index.mjs +5 -0
- package/esm/book/io.mjs +162 -0
- package/esm/book/io.mjs.map +1 -0
- package/esm/book/normalize.mjs +71 -0
- package/esm/book/normalize.mjs.map +1 -0
- package/esm/book/render.mjs +262 -0
- package/esm/book/render.mjs.map +1 -0
- package/esm/book/write.d.mts +12 -0
- package/esm/book/write.d.mts.map +1 -0
- package/esm/book/write.mjs +90 -0
- package/esm/book/write.mjs.map +1 -0
- package/esm/bookmap/build.d.mts +21 -0
- package/esm/bookmap/build.d.mts.map +1 -0
- package/esm/bookmap/build.mjs +272 -0
- package/esm/bookmap/build.mjs.map +1 -0
- package/esm/bookmap/index.mjs +5 -0
- package/esm/bookmap/steps.mjs +137 -0
- package/esm/bookmap/steps.mjs.map +1 -0
- package/esm/bookmap/write.d.mts +19 -0
- package/esm/bookmap/write.d.mts.map +1 -0
- package/esm/bookmap/write.mjs +118 -0
- package/esm/bookmap/write.mjs.map +1 -0
- package/esm/check/check-grimoire.d.mts +7 -0
- package/esm/check/check-grimoire.d.mts.map +1 -0
- package/esm/check/check-grimoire.mjs +98 -0
- package/esm/check/check-grimoire.mjs.map +1 -0
- package/esm/check/format-check-report.d.mts +20 -0
- package/esm/check/format-check-report.d.mts.map +1 -0
- package/esm/check/format-check-report.mjs +55 -0
- package/esm/check/format-check-report.mjs.map +1 -0
- package/esm/check/index.mjs +4 -0
- package/esm/check/rules/book-notes.mjs +18 -0
- package/esm/check/rules/book-notes.mjs.map +1 -0
- package/esm/check/rules/criteria.mjs +48 -0
- package/esm/check/rules/criteria.mjs.map +1 -0
- package/esm/check/rules/links.mjs +196 -0
- package/esm/check/rules/links.mjs.map +1 -0
- package/esm/check/rules/lookup.mjs +41 -0
- package/esm/check/rules/lookup.mjs.map +1 -0
- package/esm/check/rules/source-files.mjs +119 -0
- package/esm/check/rules/source-files.mjs.map +1 -0
- package/esm/check/rules/versions.mjs +92 -0
- package/esm/check/rules/versions.mjs.map +1 -0
- package/esm/codes/codes.d.mts +182 -0
- package/esm/codes/codes.d.mts.map +1 -0
- package/esm/codes/codes.mjs +111 -0
- package/esm/codes/codes.mjs.map +1 -0
- package/esm/codes/index.d.mts +33 -0
- package/esm/codes/index.d.mts.map +1 -0
- package/esm/codes/index.mjs +63 -0
- package/esm/codes/index.mjs.map +1 -0
- package/esm/contracts/adapter.d.mts +209 -0
- package/esm/contracts/adapter.d.mts.map +1 -0
- package/esm/contracts/book.d.mts +233 -0
- package/esm/contracts/book.d.mts.map +1 -0
- package/esm/contracts/book.mjs +7 -0
- package/esm/contracts/book.mjs.map +1 -0
- package/esm/contracts/bookmap.d.mts +175 -0
- package/esm/contracts/bookmap.d.mts.map +1 -0
- package/esm/contracts/findings.d.mts +79 -0
- package/esm/contracts/findings.d.mts.map +1 -0
- package/esm/contracts/location.d.mts +22 -0
- package/esm/contracts/location.d.mts.map +1 -0
- package/esm/contracts/releases.d.mts +53 -0
- package/esm/contracts/releases.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +143 -0
- package/esm/contracts/scry.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +52 -0
- package/esm/contracts/snapshot.d.mts.map +1 -0
- package/esm/contracts/test-results.d.mts +63 -0
- package/esm/contracts/test-results.d.mts.map +1 -0
- package/esm/contracts/written.d.mts +363 -0
- package/esm/contracts/written.d.mts.map +1 -0
- package/esm/contracts/written.mjs +19 -0
- package/esm/contracts/written.mjs.map +1 -0
- package/esm/devtools/data.mjs +171 -0
- package/esm/devtools/data.mjs.map +1 -0
- package/esm/devtools/graphs.mjs +142 -0
- package/esm/devtools/graphs.mjs.map +1 -0
- package/esm/devtools/index.d.mts +35 -0
- package/esm/devtools/index.d.mts.map +1 -0
- package/esm/devtools/index.mjs +102 -0
- package/esm/devtools/index.mjs.map +1 -0
- package/esm/devtools/site.d.mts +26 -0
- package/esm/devtools/site.d.mts.map +1 -0
- package/esm/devtools/site.mjs +190 -0
- package/esm/devtools/site.mjs.map +1 -0
- package/esm/devtools/snapshot-source.mjs +70 -0
- package/esm/devtools/snapshot-source.mjs.map +1 -0
- package/esm/front-matter/index.d.mts +33 -0
- package/esm/front-matter/index.d.mts.map +1 -0
- package/esm/front-matter/index.mjs +130 -0
- package/esm/front-matter/index.mjs.map +1 -0
- package/esm/graph/index.d.mts +15 -0
- package/esm/graph/index.d.mts.map +1 -0
- package/esm/graph/index.mjs +42 -0
- package/esm/graph/index.mjs.map +1 -0
- package/esm/index.d.mts +33 -0
- package/esm/index.mjs +33 -0
- package/esm/ownership/index.d.mts +8 -0
- package/esm/ownership/index.d.mts.map +1 -0
- package/esm/ownership/index.mjs +137 -0
- package/esm/ownership/index.mjs.map +1 -0
- package/esm/paths/index.d.mts +58 -0
- package/esm/paths/index.d.mts.map +1 -0
- package/esm/paths/index.mjs +137 -0
- package/esm/paths/index.mjs.map +1 -0
- package/esm/proves/index.mjs +3 -0
- package/esm/proves/scan-proofs.d.mts +22 -0
- package/esm/proves/scan-proofs.d.mts.map +1 -0
- package/esm/proves/scan-proofs.mjs +214 -0
- package/esm/proves/scan-proofs.mjs.map +1 -0
- package/esm/releases/index.d.mts +29 -0
- package/esm/releases/index.d.mts.map +1 -0
- package/esm/releases/index.mjs +157 -0
- package/esm/releases/index.mjs.map +1 -0
- package/esm/scry/format.d.mts +14 -0
- package/esm/scry/format.d.mts.map +1 -0
- package/esm/scry/format.mjs +193 -0
- package/esm/scry/format.mjs.map +1 -0
- package/esm/scry/index.mjs +5 -0
- package/esm/scry/parse.d.mts +10 -0
- package/esm/scry/parse.d.mts.map +1 -0
- package/esm/scry/parse.mjs +108 -0
- package/esm/scry/parse.mjs.map +1 -0
- package/esm/scry/query.d.mts +11 -0
- package/esm/scry/query.d.mts.map +1 -0
- package/esm/scry/query.mjs +457 -0
- package/esm/scry/query.mjs.map +1 -0
- package/esm/tasks/index.mjs +116 -0
- package/esm/tasks/index.mjs.map +1 -0
- package/esm/test-results/criterion-status.d.mts +15 -0
- package/esm/test-results/criterion-status.d.mts.map +1 -0
- package/esm/test-results/criterion-status.mjs +17 -0
- package/esm/test-results/criterion-status.mjs.map +1 -0
- package/esm/test-results/index.d.mts +8 -0
- package/esm/test-results/index.d.mts.map +1 -0
- package/esm/test-results/index.mjs +124 -0
- package/esm/test-results/index.mjs.map +1 -0
- package/esm/vitest/index.d.mts +15 -0
- package/esm/vitest/index.d.mts.map +1 -0
- package/esm/vitest/index.mjs +146 -0
- package/esm/vitest/index.mjs.map +1 -0
- package/esm/warlock/actions.mjs +265 -0
- package/esm/warlock/actions.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts +28 -0
- package/esm/warlock/adapter.d.mts.map +1 -0
- package/esm/warlock/adapter.mjs +377 -0
- package/esm/warlock/adapter.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +15 -0
- package/esm/warlock/commands.d.mts.map +1 -0
- package/esm/warlock/commands.mjs +199 -0
- package/esm/warlock/commands.mjs.map +1 -0
- package/esm/warlock/index.d.mts +4 -0
- package/esm/warlock/index.mjs +5 -0
- package/esm/warlock/mcp-tools.mjs +247 -0
- package/esm/warlock/mcp-tools.mjs.map +1 -0
- package/esm/warlock/mobile-facts.d.mts +32 -0
- package/esm/warlock/mobile-facts.d.mts.map +1 -0
- package/esm/warlock/mobile-facts.mjs +185 -0
- package/esm/warlock/mobile-facts.mjs.map +1 -0
- package/esm/workspace/index.d.mts +11 -0
- package/esm/workspace/index.d.mts.map +1 -0
- package/esm/workspace/index.mjs +122 -0
- package/esm/workspace/index.mjs.map +1 -0
- package/esm/written/apps.mjs +227 -0
- package/esm/written/apps.mjs.map +1 -0
- package/esm/written/features.mjs +400 -0
- package/esm/written/features.mjs.map +1 -0
- package/esm/written/fields.mjs +173 -0
- package/esm/written/fields.mjs.map +1 -0
- package/esm/written/index.mjs +3 -0
- package/esm/written/lists.mjs +68 -0
- package/esm/written/lists.mjs.map +1 -0
- package/esm/written/markdown.mjs +173 -0
- package/esm/written/markdown.mjs.map +1 -0
- package/esm/written/parse-grimoire.d.mts +20 -0
- package/esm/written/parse-grimoire.d.mts.map +1 -0
- package/esm/written/parse-grimoire.mjs +552 -0
- package/esm/written/parse-grimoire.mjs.map +1 -0
- package/esm/written/sink.mjs +65 -0
- package/esm/written/sink.mjs.map +1 -0
- package/esm/written/tasks-releases.mjs +166 -0
- package/esm/written/tasks-releases.mjs.map +1 -0
- package/llms-full.txt +869 -0
- package/llms.txt +15 -0
- package/package.json +66 -4
- package/skills/backfill-a-grimoire/SKILL.md +128 -0
- package/skills/describe-an-app/SKILL.md +162 -0
- package/skills/document-a-file/SKILL.md +75 -0
- package/skills/index.md +26 -0
- package/skills/record-a-change/SKILL.md +139 -0
- package/skills/use-the-grimoire/SKILL.md +137 -0
- package/skills/write-a-feature/SKILL.md +168 -0
- package/ui/grimoire-static.js +136 -0
- package/ui/grimoire-view.js +1005 -0
- package/ui/grimoire.css +88 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { isCodeFile, isInsideFolder, toPosixPath } from "../paths/index.mjs";
|
|
2
|
+
import { collectMobileFacts } from "./mobile-facts.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readdir } from "node:fs/promises";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
//#region ../../packages/grimoire/src/warlock/adapter.ts
|
|
9
|
+
/**
|
|
10
|
+
* The Warlock adapter: turns core's inspect report into the book's facts.
|
|
11
|
+
* It never parses app source itself: files come from `collectFiles()`,
|
|
12
|
+
* routes, events and jobs from `inspectApp()` after the `warlock inspect`
|
|
13
|
+
* boot pass, pages from `inspectApp()` (the web page graph, no boot), and
|
|
14
|
+
* mobile apps from their folders.
|
|
15
|
+
*
|
|
16
|
+
* `@warlock.js/core/tooling` is imported inside the methods, never at the
|
|
17
|
+
* top: this module is reached from `warlock.config.ts`.
|
|
18
|
+
*/
|
|
19
|
+
/** The `version` of a `package.json` named `name`, or `null` when the file is not that package's. */
|
|
20
|
+
function versionIn(file, name) {
|
|
21
|
+
try {
|
|
22
|
+
const manifest = JSON.parse(readFileSync(file, "utf8"));
|
|
23
|
+
return manifest.name === name && typeof manifest.version === "string" ? manifest.version : null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The installed version of a package, read from its `package.json` without
|
|
30
|
+
* going through its `exports` (published `@warlock.js/core` exports neither
|
|
31
|
+
* `./package.json` nor a `require` condition). It resolves the package's
|
|
32
|
+
* entry and walks up to the `package.json` with that name; when the entry
|
|
33
|
+
* cannot be resolved, it looks in each `node_modules` above `from`.
|
|
34
|
+
*
|
|
35
|
+
* @param from Absolute folder to look from.
|
|
36
|
+
* @param resolve Resolves a bare specifier to a file URL or path (`import.meta.resolve`).
|
|
37
|
+
*/
|
|
38
|
+
function installedVersion(name, from, resolve) {
|
|
39
|
+
try {
|
|
40
|
+
const entry = resolve?.(name);
|
|
41
|
+
if (entry !== void 0) {
|
|
42
|
+
let folder = path.dirname(entry.startsWith("file:") ? fileURLToPath(entry) : entry);
|
|
43
|
+
for (;;) {
|
|
44
|
+
const version = versionIn(path.join(folder, "package.json"), name);
|
|
45
|
+
if (version !== null) return version;
|
|
46
|
+
const parent = path.dirname(folder);
|
|
47
|
+
if (parent === folder) break;
|
|
48
|
+
folder = parent;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch {}
|
|
52
|
+
for (let folder = from;; folder = path.dirname(folder)) {
|
|
53
|
+
const version = versionIn(path.join(folder, "node_modules", ...name.split("/"), "package.json"), name);
|
|
54
|
+
if (version !== null) return version;
|
|
55
|
+
if (path.dirname(folder) === folder) return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The framework version, for the book manifest (a core upgrade rebuilds the book). */
|
|
59
|
+
function coreVersion() {
|
|
60
|
+
const resolve = typeof import.meta.resolve === "function" ? (specifier) => import.meta.resolve(specifier) : void 0;
|
|
61
|
+
return installedVersion("@warlock.js/core", path.dirname(fileURLToPath(import.meta.url)), resolve) ?? "unknown";
|
|
62
|
+
}
|
|
63
|
+
/** Run `work` with `console.log`/`info`/`debug` on stderr, so a boot never mixes with `--json` output. */
|
|
64
|
+
async function withConsoleOnStderr(work) {
|
|
65
|
+
const { log, info, debug } = console;
|
|
66
|
+
const toStderr = (...args) => console.error(...args);
|
|
67
|
+
console.log = toStderr;
|
|
68
|
+
console.info = toStderr;
|
|
69
|
+
console.debug = toStderr;
|
|
70
|
+
try {
|
|
71
|
+
return await work();
|
|
72
|
+
} finally {
|
|
73
|
+
console.log = log;
|
|
74
|
+
console.info = info;
|
|
75
|
+
console.debug = debug;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** The default booted `inspect`: one boot pass, shared by every call. */
|
|
79
|
+
function bootedInspect() {
|
|
80
|
+
let boot;
|
|
81
|
+
return async (root, sections) => {
|
|
82
|
+
const tooling = await import("@warlock.js/core/tooling");
|
|
83
|
+
boot ??= withConsoleOnStderr(() => tooling.bootForInspect(root));
|
|
84
|
+
const booted = await boot;
|
|
85
|
+
if (!booted.context.booted) {
|
|
86
|
+
const failures = booted.context.moduleFailures.map((failure) => `${failure.file}: ${failure.message}`);
|
|
87
|
+
throw new Error(`the app did not boot${failures.length > 0 ? ` (${failures.join("; ")})` : ""}. Run warlock doctor to see why.`);
|
|
88
|
+
}
|
|
89
|
+
return tooling.inspectApp({
|
|
90
|
+
...tooling.inspectOptionsFromBoot(booted),
|
|
91
|
+
cwd: root,
|
|
92
|
+
sections
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** `send-receipt.job.ts` → `send-receipt` (the stem without the role suffix). */
|
|
97
|
+
function stemOf(file, ...suffixes) {
|
|
98
|
+
const base = path.posix.basename(file).replace(/\.(?:d\.ts|[cm]?[jt]sx?)$/, "");
|
|
99
|
+
for (const suffix of suffixes) if (base.endsWith(`.${suffix}`)) return base.slice(0, -suffix.length - 1);
|
|
100
|
+
return base;
|
|
101
|
+
}
|
|
102
|
+
function toBookFile(file, mobile) {
|
|
103
|
+
const docs = file.exportDocs ?? {};
|
|
104
|
+
const app = mobile.find((item) => isInsideFolder(file.file, item.root));
|
|
105
|
+
return {
|
|
106
|
+
file: file.file,
|
|
107
|
+
module: file.module,
|
|
108
|
+
type: file.role,
|
|
109
|
+
lines: file.lines ?? 0,
|
|
110
|
+
about: file.about ?? null,
|
|
111
|
+
tags: file.tags ?? {},
|
|
112
|
+
exports: file.exports.map((name) => ({
|
|
113
|
+
name,
|
|
114
|
+
about: docs[name] ?? null
|
|
115
|
+
})),
|
|
116
|
+
imports: file.imports.map((entry) => ({
|
|
117
|
+
specifier: entry.specifier,
|
|
118
|
+
file: entry.file
|
|
119
|
+
})),
|
|
120
|
+
importedBy: [...file.importedBy],
|
|
121
|
+
mobileApp: app?.id ?? null
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function exportIndex(files) {
|
|
125
|
+
let index;
|
|
126
|
+
return () => {
|
|
127
|
+
if (index) return index;
|
|
128
|
+
index = /* @__PURE__ */ new Map();
|
|
129
|
+
for (const file of files.values()) for (const entry of file.exports) {
|
|
130
|
+
const list = index.get(entry.name) ?? [];
|
|
131
|
+
list.push(file.file);
|
|
132
|
+
index.set(entry.name, list);
|
|
133
|
+
}
|
|
134
|
+
return index;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** The file that defines a route's handler: the controller's file for a tuple, else the file exporting the handler. */
|
|
138
|
+
function handlerFileOf(route, files, pages, exporters) {
|
|
139
|
+
if (route.isPage) return pages.find((page) => page.route === route.path)?.file ?? null;
|
|
140
|
+
const exportsName = (file, name) => file !== null && file !== void 0 && files.get(file)?.exports.some((entry) => entry.name === name) === true;
|
|
141
|
+
const imported = route.sourceFile === null ? [] : (files.get(route.sourceFile)?.imports ?? []).map((entry) => entry.file);
|
|
142
|
+
const name = route.controller ?? route.handler;
|
|
143
|
+
if (!name || name === "anonymous") return null;
|
|
144
|
+
const fromImports = imported.find((file) => exportsName(file, name));
|
|
145
|
+
if (fromImports) return fromImports;
|
|
146
|
+
if (exportsName(route.sourceFile, name)) return route.sourceFile;
|
|
147
|
+
const anywhere = [...new Set(exporters().get(name) ?? [])];
|
|
148
|
+
return anywhere.length === 1 ? anywhere[0] ?? null : null;
|
|
149
|
+
}
|
|
150
|
+
function toBookRoute(route, files, pages, exporters) {
|
|
151
|
+
const controller = route.controller ?? null;
|
|
152
|
+
const action = route.action ?? null;
|
|
153
|
+
const handler = controller !== null && action !== null && !route.handler.includes(".") ? `${controller}.${action}` : route.handler;
|
|
154
|
+
return {
|
|
155
|
+
method: route.method.toUpperCase(),
|
|
156
|
+
path: route.path,
|
|
157
|
+
name: route.name,
|
|
158
|
+
sourceFile: route.sourceFile === null ? null : toPosixPath(route.sourceFile),
|
|
159
|
+
handler,
|
|
160
|
+
controller,
|
|
161
|
+
action,
|
|
162
|
+
handlerFile: handlerFileOf(route, files, pages, exporters),
|
|
163
|
+
middleware: [...route.middleware],
|
|
164
|
+
auth: {
|
|
165
|
+
required: route.auth.required,
|
|
166
|
+
userTypes: [...route.auth.userTypes]
|
|
167
|
+
},
|
|
168
|
+
isPage: route.isPage,
|
|
169
|
+
description: route.description
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async function folderNames(dir) {
|
|
173
|
+
try {
|
|
174
|
+
return (await readdir(dir, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
175
|
+
} catch {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** The site folders of a multi-site app (`src/web/$sites/<id>`), sorted; empty for a single site. */
|
|
180
|
+
function siteFolders(root) {
|
|
181
|
+
return folderNames(path.join(root, "src", "web", "$sites"));
|
|
182
|
+
}
|
|
183
|
+
/** `web.sites` from the loaded config, or `undefined` when `src/config/web.ts` is not loaded. */
|
|
184
|
+
async function webSitesConfig() {
|
|
185
|
+
const { config } = await import("@warlock.js/core");
|
|
186
|
+
const sites = config.key("web.sites");
|
|
187
|
+
return typeof sites === "object" && sites !== null ? sites : void 0;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Folders of a mobile app that hold native projects, build output or tool
|
|
191
|
+
* caches, never app source. `node_modules` and dot folders are skipped too.
|
|
192
|
+
*/
|
|
193
|
+
const MOBILE_SKIPPED_FOLDERS = /* @__PURE__ */ new Set([
|
|
194
|
+
"android",
|
|
195
|
+
"ios",
|
|
196
|
+
"build",
|
|
197
|
+
"dist",
|
|
198
|
+
"web-build",
|
|
199
|
+
"coverage",
|
|
200
|
+
"node_modules"
|
|
201
|
+
]);
|
|
202
|
+
/**
|
|
203
|
+
* The source folders of a mobile app: its top-level folders minus native
|
|
204
|
+
* projects and build output (`android/`, `ios/` with Pods and builds can hold
|
|
205
|
+
* hundreds of megabytes). Code files directly in the app folder (`App.tsx`)
|
|
206
|
+
* are not read: `collectFiles` scans folders only.
|
|
207
|
+
*/
|
|
208
|
+
async function mobileSourceFolders(root, app) {
|
|
209
|
+
return (await folderNames(path.join(root, ...app.root.split("/")))).filter((name) => !name.startsWith(".") && !MOBILE_SKIPPED_FOLDERS.has(name)).map((name) => `${app.root}/${name}`);
|
|
210
|
+
}
|
|
211
|
+
/** The adapter over `inspectApp()`, `collectFiles()` and the mobile app folders. */
|
|
212
|
+
function createWarlockAdapter(options = {}) {
|
|
213
|
+
const inspect = options.inspect ?? bootedInspect();
|
|
214
|
+
const mobileOptions = options.mobile === void 0 ? {} : { mobile: options.mobile };
|
|
215
|
+
let lastFiles = null;
|
|
216
|
+
let lastPages = null;
|
|
217
|
+
const mobileApps = (root) => collectMobileFacts(root, mobileOptions);
|
|
218
|
+
/** `src` and each mobile app's source folders: what `files()` reads and the book fingerprints. */
|
|
219
|
+
async function sourceFolders(root, mobile) {
|
|
220
|
+
return ["src", ...(await Promise.all(mobile.map((app) => mobileSourceFolders(root, app)))).flat()];
|
|
221
|
+
}
|
|
222
|
+
async function files(root) {
|
|
223
|
+
const { collectFiles } = await import("@warlock.js/core/tooling");
|
|
224
|
+
const mobile = await mobileApps(root);
|
|
225
|
+
const collected = collectFiles(root, [], { dirs: await sourceFolders(root, mobile) }).filter((file) => isCodeFile(file.file)).map((file) => toBookFile(file, mobile));
|
|
226
|
+
lastFiles = {
|
|
227
|
+
root,
|
|
228
|
+
files: collected
|
|
229
|
+
};
|
|
230
|
+
return collected;
|
|
231
|
+
}
|
|
232
|
+
/** File facts for the routes: the last `files()` answer, else the book's cache, else a new scan. */
|
|
233
|
+
async function currentFiles(root) {
|
|
234
|
+
if (lastFiles?.root === root) return lastFiles.files;
|
|
235
|
+
const { loadBook } = await import("../book/index.mjs");
|
|
236
|
+
return (await loadBook(root))?.facts.files ?? files(root);
|
|
237
|
+
}
|
|
238
|
+
async function pages(root) {
|
|
239
|
+
if ((await siteFolders(root)).length > 0 && await webSitesConfig() === void 0) throw new Error("This app has several sites (src/web/$sites), and their page routes need src/config/web.ts, which is not loaded. Run the command through the warlock CLI, which loads it.");
|
|
240
|
+
const { inspectApp } = await import("@warlock.js/core/tooling");
|
|
241
|
+
const found = ((await inspectApp({
|
|
242
|
+
cwd: root,
|
|
243
|
+
sections: ["pages"]
|
|
244
|
+
})).pages ?? []).map((page) => ({
|
|
245
|
+
site: page.site ?? "default",
|
|
246
|
+
route: page.path,
|
|
247
|
+
name: page.name,
|
|
248
|
+
file: toPosixPath(page.file),
|
|
249
|
+
setupFile: page.setupFile === null ? null : toPosixPath(page.setupFile),
|
|
250
|
+
layouts: page.layouts.map(toPosixPath),
|
|
251
|
+
loaders: page.loaders.map(toPosixPath),
|
|
252
|
+
actions: [...page.actions],
|
|
253
|
+
requires: page.guard === null ? [] : [page.guard],
|
|
254
|
+
reachedFrom: null
|
|
255
|
+
}));
|
|
256
|
+
lastPages = {
|
|
257
|
+
root,
|
|
258
|
+
pages: found
|
|
259
|
+
};
|
|
260
|
+
return found;
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
name: "warlock",
|
|
264
|
+
version: coreVersion(),
|
|
265
|
+
async sourceRoots(root) {
|
|
266
|
+
return sourceFolders(root, await mobileApps(root));
|
|
267
|
+
},
|
|
268
|
+
files,
|
|
269
|
+
async routes(root) {
|
|
270
|
+
const report = await inspect(root, ["routes"]);
|
|
271
|
+
const known = new Map((await currentFiles(root)).map((file) => [file.file, file]));
|
|
272
|
+
const sitePages = lastPages?.root === root ? lastPages.pages : await pages(root).catch(() => []);
|
|
273
|
+
const exporters = exportIndex(known);
|
|
274
|
+
return (report.routes ?? []).map((route) => toBookRoute(route, known, sitePages, exporters));
|
|
275
|
+
},
|
|
276
|
+
async named(root) {
|
|
277
|
+
const report = await inspect(root, [
|
|
278
|
+
"events",
|
|
279
|
+
"jobs",
|
|
280
|
+
"schedules"
|
|
281
|
+
]);
|
|
282
|
+
const known = await currentFiles(root);
|
|
283
|
+
const ofType = (type) => known.filter((file) => file.type === type);
|
|
284
|
+
const named = [];
|
|
285
|
+
for (const file of ofType("mail")) named.push({
|
|
286
|
+
type: "mail",
|
|
287
|
+
name: stemOf(file.file, "mail", "email"),
|
|
288
|
+
file: file.file
|
|
289
|
+
});
|
|
290
|
+
const jobFiles = ofType("job");
|
|
291
|
+
const jobFileOf = (name) => jobFiles.find((item) => {
|
|
292
|
+
const stem = stemOf(item.file, "job");
|
|
293
|
+
return name === stem || name.endsWith(`.${stem}`) || name.endsWith(`/${stem}`);
|
|
294
|
+
})?.file ?? null;
|
|
295
|
+
const seen = /* @__PURE__ */ new Set();
|
|
296
|
+
for (const name of [...(report.jobs ?? []).map((job) => job.name), ...(report.schedules ?? []).map((schedule) => schedule.name)]) {
|
|
297
|
+
if (seen.has(name)) continue;
|
|
298
|
+
seen.add(name);
|
|
299
|
+
named.push({
|
|
300
|
+
type: "job",
|
|
301
|
+
name,
|
|
302
|
+
file: jobFileOf(name)
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
for (const file of jobFiles) {
|
|
306
|
+
const name = stemOf(file.file, "job");
|
|
307
|
+
if (seen.has(name) || [...seen].some((item) => jobFileOf(item) === file.file)) continue;
|
|
308
|
+
seen.add(name);
|
|
309
|
+
named.push({
|
|
310
|
+
type: "job",
|
|
311
|
+
name,
|
|
312
|
+
file: file.file
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
for (const event of report.events ?? []) {
|
|
316
|
+
const source = event.listeners[0]?.sourceFile;
|
|
317
|
+
named.push({
|
|
318
|
+
type: "event",
|
|
319
|
+
name: event.event,
|
|
320
|
+
file: source === void 0 ? null : toPosixPath(source)
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
for (const file of known) if (/\.notification\.[cm]?[jt]sx?$/.test(file.file)) named.push({
|
|
324
|
+
type: "notification",
|
|
325
|
+
name: stemOf(file.file, "notification"),
|
|
326
|
+
file: file.file
|
|
327
|
+
});
|
|
328
|
+
return named;
|
|
329
|
+
},
|
|
330
|
+
async sites(root) {
|
|
331
|
+
const multi = await siteFolders(root);
|
|
332
|
+
if (multi.length > 0) {
|
|
333
|
+
const configured = await webSitesConfig();
|
|
334
|
+
return multi.map((id) => {
|
|
335
|
+
const basePath = configured?.[id]?.basePath;
|
|
336
|
+
return {
|
|
337
|
+
id,
|
|
338
|
+
root: `src/web/$sites/${id}`,
|
|
339
|
+
basePath: typeof basePath === "string" ? basePath : null
|
|
340
|
+
};
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return (await folderNames(path.join(root, "src"))).includes("web") ? [{
|
|
344
|
+
id: "default",
|
|
345
|
+
root: "src/web",
|
|
346
|
+
basePath: null
|
|
347
|
+
}] : [];
|
|
348
|
+
},
|
|
349
|
+
pages,
|
|
350
|
+
mobile: mobileApps,
|
|
351
|
+
async tests(root) {
|
|
352
|
+
const specs = (await currentFiles(root)).filter((file) => file.type === "spec").map((file) => file.file);
|
|
353
|
+
const outside = [];
|
|
354
|
+
const walk = async (dir, pattern) => {
|
|
355
|
+
let entries;
|
|
356
|
+
try {
|
|
357
|
+
entries = await readdir(path.join(root, dir), { withFileTypes: true });
|
|
358
|
+
} catch {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
for (const entry of entries) {
|
|
362
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
363
|
+
const relative = `${dir}/${entry.name}`;
|
|
364
|
+
if (entry.isDirectory()) await walk(relative, pattern);
|
|
365
|
+
else if (entry.isFile() && pattern.test(entry.name)) outside.push(relative);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
await walk("e2e", /\.e2e\.(?:ts|mts|js|mjs)$/);
|
|
369
|
+
await walk("tests", /\.(?:test|spec)\.ts$/);
|
|
370
|
+
return [.../* @__PURE__ */ new Set([...specs, ...outside])].sort();
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
//#endregion
|
|
376
|
+
export { createWarlockAdapter, installedVersion };
|
|
377
|
+
//# sourceMappingURL=adapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/adapter.ts"],"sourcesContent":["/**\n * The Warlock adapter: turns core's inspect report into the book's facts.\n * It never parses app source itself: files come from `collectFiles()`,\n * routes, events and jobs from `inspectApp()` after the `warlock inspect`\n * boot pass, pages from `inspectApp()` (the web page graph, no boot), and\n * mobile apps from their folders.\n *\n * `@warlock.js/core/tooling` is imported inside the methods, never at the\n * top: this module is reached from `warlock.config.ts`.\n */\nimport { readFileSync } from \"node:fs\";\nimport { readdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type {\n InspectFile,\n InspectReport,\n InspectRoute,\n InspectSection,\n} from \"@warlock.js/core/tooling\";\nimport type {\n BookAdapter,\n BookFile,\n BookMobileApp,\n BookNamedThing,\n BookPage,\n BookRoute,\n BookSite,\n} from \"../contracts/adapter\";\nimport { isCodeFile, isInsideFolder, toPosixPath } from \"../paths\";\nimport { collectMobileFacts, type MobileAppOption } from \"./mobile-facts\";\n\n/**\n * Reads the sections of the inspect report that need the app booted\n * (`routes`, `events`, `jobs`) for the project at `root`. The default boots\n * the app once, the `warlock inspect` way (connectors boot, none starts).\n * `warlock mcp` passes its own, which shares the server's boot.\n */\nexport type WarlockInspect = (\n root: string,\n sections: readonly InspectSection[],\n) => Promise<InspectReport>;\n\n/** Options of `createWarlockAdapter()`. */\nexport type WarlockAdapterOptions = {\n /**\n * Mobile apps in the repository: folder, id and routing. Default: every\n * top-level folder with an `app.json` or an `app.config.*` file; it is\n * file-routed when its `package.json` lists `expo-router` (screens come\n * from the files), and code-navigated otherwise (no screens: the agent\n * declares them in `grimoire/apps/<app>/screens/`).\n */\n mobile?: readonly MobileAppOption[];\n /** How the booted sections are read. Default: the `warlock inspect` boot pass, run at most once. Pages never boot. */\n inspect?: WarlockInspect;\n};\n\n/** The `version` of a `package.json` named `name`, or `null` when the file is not that package's. */\nfunction versionIn(file: string, name: string): string | null {\n try {\n const manifest = JSON.parse(readFileSync(file, \"utf8\")) as {\n name?: unknown;\n version?: unknown;\n };\n\n return manifest.name === name && typeof manifest.version === \"string\" ? manifest.version : null;\n } catch {\n return null;\n }\n}\n\n/**\n * The installed version of a package, read from its `package.json` without\n * going through its `exports` (published `@warlock.js/core` exports neither\n * `./package.json` nor a `require` condition). It resolves the package's\n * entry and walks up to the `package.json` with that name; when the entry\n * cannot be resolved, it looks in each `node_modules` above `from`.\n *\n * @param from Absolute folder to look from.\n * @param resolve Resolves a bare specifier to a file URL or path (`import.meta.resolve`).\n */\nexport function installedVersion(\n name: string,\n from: string,\n resolve: ((specifier: string) => string) | undefined,\n): string | null {\n try {\n const entry = resolve?.(name);\n\n if (entry !== undefined) {\n let folder = path.dirname(entry.startsWith(\"file:\") ? fileURLToPath(entry) : entry);\n\n for (;;) {\n const version = versionIn(path.join(folder, \"package.json\"), name);\n\n if (version !== null) return version;\n\n const parent = path.dirname(folder);\n\n if (parent === folder) break;\n\n folder = parent;\n }\n }\n } catch {\n // Not resolvable from here: look in the node_modules folders below.\n }\n\n for (let folder = from; ; folder = path.dirname(folder)) {\n const version = versionIn(\n path.join(folder, \"node_modules\", ...name.split(\"/\"), \"package.json\"),\n name,\n );\n\n if (version !== null) return version;\n if (path.dirname(folder) === folder) return null;\n }\n}\n\n/** The framework version, for the book manifest (a core upgrade rebuilds the book). */\nfunction coreVersion(): string {\n const resolve =\n typeof import.meta.resolve === \"function\"\n ? (specifier: string) => import.meta.resolve(specifier)\n : undefined;\n\n return (\n installedVersion(\"@warlock.js/core\", path.dirname(fileURLToPath(import.meta.url)), resolve) ??\n \"unknown\"\n );\n}\n\n/** Run `work` with `console.log`/`info`/`debug` on stderr, so a boot never mixes with `--json` output. */\nasync function withConsoleOnStderr<T>(work: () => Promise<T>): Promise<T> {\n const { log, info, debug } = console;\n const toStderr = (...args: unknown[]) => console.error(...args);\n\n console.log = toStderr;\n console.info = toStderr;\n console.debug = toStderr;\n\n try {\n return await work();\n } finally {\n console.log = log;\n console.info = info;\n console.debug = debug;\n }\n}\n\n/** The default booted `inspect`: one boot pass, shared by every call. */\nfunction bootedInspect(): WarlockInspect {\n let boot: Promise<unknown> | undefined;\n\n return async (root, sections) => {\n const tooling = await import(\"@warlock.js/core/tooling\");\n\n boot ??= withConsoleOnStderr(() => tooling.bootForInspect(root));\n\n const booted = (await boot) as Awaited<ReturnType<typeof tooling.bootForInspect>>;\n\n if (!booted.context.booted) {\n const failures = booted.context.moduleFailures.map(\n (failure) => `${failure.file}: ${failure.message}`,\n );\n\n throw new Error(\n `the app did not boot${failures.length > 0 ? ` (${failures.join(\"; \")})` : \"\"}. Run warlock doctor to see why.`,\n );\n }\n\n return tooling.inspectApp({ ...tooling.inspectOptionsFromBoot(booted), cwd: root, sections });\n };\n}\n\n/** `send-receipt.job.ts` → `send-receipt` (the stem without the role suffix). */\nfunction stemOf(file: string, ...suffixes: string[]): string {\n const base = path.posix.basename(file).replace(/\\.(?:d\\.ts|[cm]?[jt]sx?)$/, \"\");\n\n for (const suffix of suffixes) {\n if (base.endsWith(`.${suffix}`)) return base.slice(0, -suffix.length - 1);\n }\n\n return base;\n}\n\nfunction toBookFile(file: InspectFile, mobile: readonly BookMobileApp[]): BookFile {\n const docs = file.exportDocs ?? {};\n const app = mobile.find((item) => isInsideFolder(file.file, item.root));\n\n return {\n file: file.file,\n module: file.module,\n type: file.role,\n lines: file.lines ?? 0,\n about: file.about ?? null,\n tags: file.tags ?? {},\n exports: file.exports.map((name) => ({ name, about: docs[name] ?? null })),\n imports: file.imports.map((entry) => ({ specifier: entry.specifier, file: entry.file })),\n importedBy: [...file.importedBy],\n mobileApp: app?.id ?? null,\n };\n}\n\n/** Files by the names they export, built once per `routes()` call. */\ntype ExportIndex = () => ReadonlyMap<string, readonly string[]>;\n\nfunction exportIndex(files: ReadonlyMap<string, BookFile>): ExportIndex {\n let index: Map<string, string[]> | undefined;\n\n return () => {\n if (index) return index;\n\n index = new Map();\n\n for (const file of files.values()) {\n for (const entry of file.exports) {\n const list = index.get(entry.name) ?? [];\n\n list.push(file.file);\n index.set(entry.name, list);\n }\n }\n\n return index;\n };\n}\n\n/** The file that defines a route's handler: the controller's file for a tuple, else the file exporting the handler. */\nfunction handlerFileOf(\n route: InspectRoute,\n files: ReadonlyMap<string, BookFile>,\n pages: readonly BookPage[],\n exporters: ExportIndex,\n): string | null {\n if (route.isPage) {\n return pages.find((page) => page.route === route.path)?.file ?? null;\n }\n\n const exportsName = (file: string | null | undefined, name: string): boolean =>\n file !== null &&\n file !== undefined &&\n files.get(file)?.exports.some((entry) => entry.name === name) === true;\n const imported =\n route.sourceFile === null\n ? []\n : (files.get(route.sourceFile)?.imports ?? []).map((entry) => entry.file);\n const name = route.controller ?? route.handler;\n\n if (!name || name === \"anonymous\") return null;\n\n const fromImports = imported.find((file) => exportsName(file, name));\n\n if (fromImports) return fromImports;\n if (exportsName(route.sourceFile, name)) return route.sourceFile;\n\n // Not imported by the routes file: the one file in the project exporting it, when there is only one.\n const anywhere = [...new Set(exporters().get(name) ?? [])];\n\n return anywhere.length === 1 ? (anywhere[0] ?? null) : null;\n}\n\nfunction toBookRoute(\n route: InspectRoute,\n files: ReadonlyMap<string, BookFile>,\n pages: readonly BookPage[],\n exporters: ExportIndex,\n): BookRoute {\n const controller = route.controller ?? null;\n const action = route.action ?? null;\n const handler =\n controller !== null && action !== null && !route.handler.includes(\".\")\n ? `${controller}.${action}`\n : route.handler;\n\n return {\n method: route.method.toUpperCase(),\n path: route.path,\n name: route.name,\n sourceFile: route.sourceFile === null ? null : toPosixPath(route.sourceFile),\n handler,\n controller,\n action,\n handlerFile: handlerFileOf(route, files, pages, exporters),\n middleware: [...route.middleware],\n auth: { required: route.auth.required, userTypes: [...route.auth.userTypes] },\n isPage: route.isPage,\n description: route.description,\n };\n}\n\nasync function folderNames(dir: string): Promise<string[]> {\n try {\n return (await readdir(dir, { withFileTypes: true }))\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name)\n .sort();\n } catch {\n return [];\n }\n}\n\n/** The site folders of a multi-site app (`src/web/$sites/<id>`), sorted; empty for a single site. */\nfunction siteFolders(root: string): Promise<string[]> {\n return folderNames(path.join(root, \"src\", \"web\", \"$sites\"));\n}\n\n/** `web.sites` from the loaded config, or `undefined` when `src/config/web.ts` is not loaded. */\nasync function webSitesConfig(): Promise<\n Record<string, { basePath?: unknown } | undefined> | undefined\n> {\n const { config } = await import(\"@warlock.js/core\");\n const sites: unknown = config.key(\"web.sites\");\n\n return typeof sites === \"object\" && sites !== null\n ? (sites as Record<string, { basePath?: unknown }>)\n : undefined;\n}\n\n/**\n * Folders of a mobile app that hold native projects, build output or tool\n * caches, never app source. `node_modules` and dot folders are skipped too.\n */\nconst MOBILE_SKIPPED_FOLDERS = new Set([\n \"android\",\n \"ios\",\n \"build\",\n \"dist\",\n \"web-build\",\n \"coverage\",\n \"node_modules\",\n]);\n\n/**\n * The source folders of a mobile app: its top-level folders minus native\n * projects and build output (`android/`, `ios/` with Pods and builds can hold\n * hundreds of megabytes). Code files directly in the app folder (`App.tsx`)\n * are not read: `collectFiles` scans folders only.\n */\nasync function mobileSourceFolders(root: string, app: BookMobileApp): Promise<string[]> {\n return (await folderNames(path.join(root, ...app.root.split(\"/\"))))\n .filter((name) => !name.startsWith(\".\") && !MOBILE_SKIPPED_FOLDERS.has(name))\n .map((name) => `${app.root}/${name}`);\n}\n\n/** The adapter over `inspectApp()`, `collectFiles()` and the mobile app folders. */\nexport function createWarlockAdapter(options: WarlockAdapterOptions = {}): BookAdapter {\n const inspect = options.inspect ?? bootedInspect();\n const mobileOptions = options.mobile === undefined ? {} : { mobile: options.mobile };\n let lastFiles: { root: string; files: BookFile[] } | null = null;\n let lastPages: { root: string; pages: BookPage[] } | null = null;\n\n const mobileApps = (root: string) => collectMobileFacts(root, mobileOptions);\n\n /** `src` and each mobile app's source folders: what `files()` reads and the book fingerprints. */\n async function sourceFolders(root: string, mobile: readonly BookMobileApp[]): Promise<string[]> {\n const folders = await Promise.all(mobile.map((app) => mobileSourceFolders(root, app)));\n\n return [\"src\", ...folders.flat()];\n }\n\n async function files(root: string): Promise<BookFile[]> {\n const { collectFiles } = await import(\"@warlock.js/core/tooling\");\n const mobile = await mobileApps(root);\n const dirs = await sourceFolders(root, mobile);\n const collected = collectFiles(root, [], { dirs })\n .filter((file) => isCodeFile(file.file))\n .map((file) => toBookFile(file, mobile));\n\n lastFiles = { root, files: collected };\n\n return collected;\n }\n\n /** File facts for the routes: the last `files()` answer, else the book's cache, else a new scan. */\n async function currentFiles(root: string): Promise<BookFile[]> {\n if (lastFiles?.root === root) return lastFiles.files;\n\n const { loadBook } = await import(\"../book\");\n const book = await loadBook(root);\n\n return book?.facts.files ?? files(root);\n }\n\n async function pages(root: string): Promise<BookPage[]> {\n // A multi-site app's routes depend on `web.sites` (base paths), which only `src/config/web.ts` holds.\n if ((await siteFolders(root)).length > 0 && (await webSitesConfig()) === undefined) {\n throw new Error(\n \"This app has several sites (src/web/$sites), and their page routes need src/config/web.ts, which is not loaded. Run the command through the warlock CLI, which loads it.\",\n );\n }\n\n // Pages come from the web page graph: files only, never a boot.\n const { inspectApp } = await import(\"@warlock.js/core/tooling\");\n const report = await inspectApp({ cwd: root, sections: [\"pages\"] });\n const found = (report.pages ?? []).map((page): BookPage => ({\n site: page.site ?? \"default\",\n route: page.path,\n name: page.name,\n file: toPosixPath(page.file),\n setupFile: page.setupFile === null ? null : toPosixPath(page.setupFile),\n layouts: page.layouts.map(toPosixPath),\n loaders: page.loaders.map(toPosixPath),\n actions: [...page.actions],\n requires: page.guard === null ? [] : [page.guard],\n reachedFrom: null,\n }));\n\n lastPages = { root, pages: found };\n\n return found;\n }\n\n return {\n name: \"warlock\",\n version: coreVersion(),\n async sourceRoots(root) {\n return sourceFolders(root, await mobileApps(root));\n },\n files,\n async routes(root) {\n const report = await inspect(root, [\"routes\"]);\n const known = new Map((await currentFiles(root)).map((file) => [file.file, file]));\n // Pages only name the file of a page route; a page problem is reported by `pages()` itself.\n const sitePages =\n lastPages?.root === root ? lastPages.pages : await pages(root).catch(() => []);\n\n const exporters = exportIndex(known);\n\n return (report.routes ?? []).map((route) => toBookRoute(route, known, sitePages, exporters));\n },\n async named(root) {\n const report = await inspect(root, [\"events\", \"jobs\", \"schedules\"]);\n const known = await currentFiles(root);\n const ofType = (type: string) => known.filter((file) => file.type === type);\n const named: BookNamedThing[] = [];\n\n // `*.mail.ts`, `*.email.ts` and the files of a `mails/` or `emails/` folder are all typed as mails.\n for (const file of ofType(\"mail\")) {\n named.push({\n type: \"mail\",\n name: stemOf(file.file, \"mail\", \"email\"),\n file: file.file,\n });\n }\n\n const jobFiles = ofType(\"job\");\n const jobFileOf = (name: string): string | null =>\n jobFiles.find((item) => {\n const stem = stemOf(item.file, \"job\");\n\n return name === stem || name.endsWith(`.${stem}`) || name.endsWith(`/${stem}`);\n })?.file ?? null;\n const seen = new Set<string>();\n\n // Queue jobs (`defineJob()`) and scheduled tasks are both jobs a flow can name.\n for (const name of [\n ...(report.jobs ?? []).map((job) => job.name),\n ...(report.schedules ?? []).map((schedule) => schedule.name),\n ]) {\n if (seen.has(name)) continue;\n\n seen.add(name);\n named.push({ type: \"job\", name, file: jobFileOf(name) });\n }\n\n // A job file the registries do not list is still a job by its file name.\n for (const file of jobFiles) {\n const name = stemOf(file.file, \"job\");\n\n if (seen.has(name) || [...seen].some((item) => jobFileOf(item) === file.file)) continue;\n\n seen.add(name);\n named.push({ type: \"job\", name, file: file.file });\n }\n\n for (const event of report.events ?? []) {\n const source = event.listeners[0]?.sourceFile;\n\n named.push({\n type: \"event\",\n name: event.event,\n file: source === undefined ? null : toPosixPath(source),\n });\n }\n\n for (const file of known) {\n if (/\\.notification\\.[cm]?[jt]sx?$/.test(file.file)) {\n named.push({\n type: \"notification\",\n name: stemOf(file.file, \"notification\"),\n file: file.file,\n });\n }\n }\n\n return named;\n },\n async sites(root): Promise<BookSite[]> {\n const multi = await siteFolders(root);\n\n if (multi.length > 0) {\n const configured = await webSitesConfig();\n\n return multi.map((id) => {\n const basePath: unknown = configured?.[id]?.basePath;\n\n return {\n id,\n root: `src/web/$sites/${id}`,\n basePath: typeof basePath === \"string\" ? basePath : null,\n };\n });\n }\n\n return (await folderNames(path.join(root, \"src\"))).includes(\"web\")\n ? [{ id: \"default\", root: \"src/web\", basePath: null }]\n : [];\n },\n pages,\n mobile: mobileApps,\n async tests(root) {\n const known = await currentFiles(root);\n const specs = known.filter((file) => file.type === \"spec\").map((file) => file.file);\n const outside: string[] = [];\n\n const walk = async (dir: string, pattern: RegExp): Promise<void> => {\n let entries;\n\n try {\n entries = await readdir(path.join(root, dir), { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n\n const relative = `${dir}/${entry.name}`;\n\n if (entry.isDirectory()) await walk(relative, pattern);\n else if (entry.isFile() && pattern.test(entry.name)) outside.push(relative);\n }\n };\n\n await walk(\"e2e\", /\\.e2e\\.(?:ts|mts|js|mjs)$/);\n await walk(\"tests\", /\\.(?:test|spec)\\.ts$/);\n\n return [...new Set([...specs, ...outside])].sort();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0DA,SAAS,UAAU,MAAc,MAA6B;CAC5D,IAAI;EACF,MAAM,WAAW,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;EAKtD,OAAO,SAAS,SAAS,QAAQ,OAAO,SAAS,YAAY,WAAW,SAAS,UAAU;CAC7F,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;AAYA,SAAgB,iBACd,MACA,MACA,SACe;CACf,IAAI;EACF,MAAM,QAAQ,UAAU,IAAI;EAE5B,IAAI,UAAU,QAAW;GACvB,IAAI,SAAS,KAAK,QAAQ,MAAM,WAAW,OAAO,IAAI,cAAc,KAAK,IAAI,KAAK;GAElF,SAAS;IACP,MAAM,UAAU,UAAU,KAAK,KAAK,QAAQ,cAAc,GAAG,IAAI;IAEjE,IAAI,YAAY,MAAM,OAAO;IAE7B,MAAM,SAAS,KAAK,QAAQ,MAAM;IAElC,IAAI,WAAW,QAAQ;IAEvB,SAAS;GACX;EACF;CACF,QAAQ,CAER;CAEA,KAAK,IAAI,SAAS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AW,UAAU;GAAK,CAAC,IACnD,CAAC;EACP;EACA;EACA,QAAQ;EACR,MAAM,MAAM,MAAM;GAEhB,MAAM,SAAQ,MADM,aAAa,IAAI,EAClB,CAAC,QAAQ,SAAS,KAAK,SAAS,MAAM,CAAC,CAAC,KAAK,SAAS,KAAK,IAAI;GAClF,MAAM,UAAoB,CAAC;GAE3B,MAAM,OAAO,OAAO,KAAa,YAAmC;IAClE,IAAI;IAEJ,IAAI;KACF,UAAU,MAAM,QAAQ,KAAK,KAAK,MAAM,GAAG,GAAG,EAAE,eAAe,KAAK,CAAC;IACvE,QAAQ;KACN;IACF;IAEA,KAAK,MAAM,SAAS,SAAS;KAC3B,IAAI,MAAM,SAAS,kBAAkB,MAAM,KAAK,WAAW,GAAG,GAAG;KAEjE,MAAM,WAAW,GAAG,IAAI,GAAG,MAAM;KAEjC,IAAI,MAAM,YAAY,GAAG,MAAM,KAAK,UAAU,OAAO;UAChD,IAAI,MAAM,OAAO,KAAK,QAAQ,KAAK,MAAM,IAAI,GAAG,QAAQ,KAAK,QAAQ;IAC5E;GACF;GAEA,MAAM,KAAK,OAAO,2BAA2B;GAC7C,MAAM,KAAK,SAAS,sBAAsB;GAE1C,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK;EACnD;CACF;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WarlockAdapterOptions } from "./adapter.mjs";
|
|
2
|
+
import { CLICommand } from "@warlock.js/core";
|
|
3
|
+
//#region ../../packages/grimoire/src/warlock/commands.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The `grimoire <action> [release]` and `scry [file]` commands, with the
|
|
6
|
+
* Grimoire MCP tools and the `GRnnnn` explainer attached. `cli.commands`
|
|
7
|
+
* accepts this array as one entry.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // warlock.config.ts
|
|
11
|
+
* export default defineConfig({ cli: { commands: [registerGrimoireCommands()] } });
|
|
12
|
+
*/
|
|
13
|
+
export declare function registerGrimoireCommands(options?: WarlockAdapterOptions): CLICommand[];
|
|
14
|
+
//#endregion
|
|
15
|
+
//# sourceMappingURL=commands.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/commands.ts"],"mappings":";;;;;;;;;;;;wBA4FgB,yBAAyB,UAAS,wBAA6B"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { explainGrimoireCode, grimoireCodeDocsUrl } from "../codes/index.mjs";
|
|
2
|
+
import { createGrimoireMcpTools } from "./mcp-tools.mjs";
|
|
3
|
+
import { command, withExplainCodes, withMcpTools } from "@warlock.js/core";
|
|
4
|
+
|
|
5
|
+
//#region ../../packages/grimoire/src/warlock/commands.ts
|
|
6
|
+
/**
|
|
7
|
+
* The `warlock grimoire` and `warlock scry` commands. Light on purpose: the
|
|
8
|
+
* work lives in `./actions`, imported when a command runs.
|
|
9
|
+
*/
|
|
10
|
+
/** The preload of a command that reads routes: the `warlock inspect` boot. */
|
|
11
|
+
const BOOT = {
|
|
12
|
+
runtimeStrategy: "development",
|
|
13
|
+
config: true,
|
|
14
|
+
env: true,
|
|
15
|
+
bootstrap: true
|
|
16
|
+
};
|
|
17
|
+
/** No boot, but a multi-site app's `src/config/web.ts` (its sites' base paths shape the page routes). */
|
|
18
|
+
const WEB_CONFIG = { config: ["web"] };
|
|
19
|
+
/** The preload of a question that boots only when `boot` says so. */
|
|
20
|
+
async function preloadFor(boot) {
|
|
21
|
+
try {
|
|
22
|
+
const actions = await import("./actions.mjs");
|
|
23
|
+
if (await boot()) return BOOT;
|
|
24
|
+
return await actions.isMultiSite(process.cwd()) ? WEB_CONFIG : void 0;
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const GRIMOIRE_ACTIONS = [
|
|
30
|
+
"build",
|
|
31
|
+
"check",
|
|
32
|
+
"release"
|
|
33
|
+
];
|
|
34
|
+
/** Print with the stream's own write, so a boot that moves `console.log` never mixes into the answer. */
|
|
35
|
+
const io = {
|
|
36
|
+
out: (line) => void process.stdout.write(`${line}\n`),
|
|
37
|
+
err: (line) => void process.stderr.write(`${line}\n`)
|
|
38
|
+
};
|
|
39
|
+
/** Exit with `code` once stdout and stderr are flushed (a non-zero code only; 0 lets the CLI finish). */
|
|
40
|
+
async function exitWith(code) {
|
|
41
|
+
if (code === 0) return;
|
|
42
|
+
process.exitCode = code;
|
|
43
|
+
await Promise.race([Promise.all([process.stdout, process.stderr].map((stream) => new Promise((resolve) => stream.write("", () => resolve())))), new Promise((resolve) => setTimeout(resolve, 500).unref())]);
|
|
44
|
+
process.exit(code);
|
|
45
|
+
}
|
|
46
|
+
/** Explain a Grimoire code for `warlock explain GR2001`. */
|
|
47
|
+
function explainCode(code) {
|
|
48
|
+
const definition = explainGrimoireCode(code);
|
|
49
|
+
return definition ? {
|
|
50
|
+
code: definition.code,
|
|
51
|
+
title: definition.title,
|
|
52
|
+
area: definition.area,
|
|
53
|
+
fix: definition.fix,
|
|
54
|
+
skill: definition.skill,
|
|
55
|
+
docs: grimoireCodeDocsUrl(definition.code)
|
|
56
|
+
} : void 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `grimoire <action> [release]` and `scry [file]` commands, with the
|
|
60
|
+
* Grimoire MCP tools and the `GRnnnn` explainer attached. `cli.commands`
|
|
61
|
+
* accepts this array as one entry.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // warlock.config.ts
|
|
65
|
+
* export default defineConfig({ cli: { commands: [registerGrimoireCommands()] } });
|
|
66
|
+
*/
|
|
67
|
+
function registerGrimoireCommands(options = {}) {
|
|
68
|
+
let adapter;
|
|
69
|
+
const loadAdapter = () => {
|
|
70
|
+
adapter ??= import("./adapter.mjs").then(({ createWarlockAdapter }) => createWarlockAdapter(options));
|
|
71
|
+
return adapter;
|
|
72
|
+
};
|
|
73
|
+
const context = async () => ({
|
|
74
|
+
root: process.cwd(),
|
|
75
|
+
adapter: await loadAdapter(),
|
|
76
|
+
io
|
|
77
|
+
});
|
|
78
|
+
const grimoire = command({
|
|
79
|
+
name: "grimoire <action> [release]",
|
|
80
|
+
description: "Grimoire (experimental): build the book (build [--force] [--site [--out <dir>]]), check the written files (check [--all]), collect a release (release <version>); --json for JSON",
|
|
81
|
+
preAction: async ({ args, options: flags }) => {
|
|
82
|
+
grimoire.commandPreload = void 0;
|
|
83
|
+
if (args[0] !== "build" && args[0] !== "check") return;
|
|
84
|
+
const preload = await preloadFor(async () => (await import("./actions.mjs")).needsBoot(process.cwd(), flags.force === true));
|
|
85
|
+
if (preload) grimoire.commandPreload = preload;
|
|
86
|
+
},
|
|
87
|
+
action: async ({ args, options: flags }) => {
|
|
88
|
+
const actions = await import("./actions.mjs");
|
|
89
|
+
const ctx = await context();
|
|
90
|
+
const [name, release] = args;
|
|
91
|
+
let code;
|
|
92
|
+
switch (name) {
|
|
93
|
+
case "build":
|
|
94
|
+
code = await actions.runBuild(ctx, flags);
|
|
95
|
+
break;
|
|
96
|
+
case "check":
|
|
97
|
+
code = await actions.runCheck(ctx, flags);
|
|
98
|
+
break;
|
|
99
|
+
case "release":
|
|
100
|
+
code = await actions.runRelease(ctx, release, flags);
|
|
101
|
+
break;
|
|
102
|
+
default: {
|
|
103
|
+
const { GrimoireError } = await import("../codes/index.mjs");
|
|
104
|
+
code = actions.reportError(io, new GrimoireError("GR9006", `Unknown action ${JSON.stringify(name ?? "")}. Use one of: ${GRIMOIRE_ACTIONS.join(", ")} (warlock grimoire build).`));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
await exitWith(code);
|
|
108
|
+
},
|
|
109
|
+
options: [
|
|
110
|
+
{
|
|
111
|
+
text: "--json, -j",
|
|
112
|
+
description: "Print the result as JSON",
|
|
113
|
+
type: "boolean"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
text: "--all",
|
|
117
|
+
description: "check: list every finding (text output groups warnings by code)",
|
|
118
|
+
type: "boolean"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
text: "--force, -f",
|
|
122
|
+
description: "build: rebuild every book entry and read the routes again",
|
|
123
|
+
type: "boolean"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
text: "--site",
|
|
127
|
+
description: "build: also write the static Grimoire site (default grimoire/book/site)",
|
|
128
|
+
type: "boolean"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
text: "--out",
|
|
132
|
+
description: "build --site: the folder to write the site to (project-relative)",
|
|
133
|
+
type: "string"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
const scry = command({
|
|
138
|
+
name: "scry [file]",
|
|
139
|
+
description: "Grimoire (experimental): ask about a file, --impact <file>, --route \"<METHOD path>\", --feature <id>, --flow <feature>/<flow> or --search \"<text>\"; --json for JSON",
|
|
140
|
+
preAction: async ({ options: flags }) => {
|
|
141
|
+
scry.commandPreload = void 0;
|
|
142
|
+
const preload = await preloadFor(async () => flags.route !== void 0 && !await (await import("./actions.mjs")).hasRouteFacts(process.cwd()));
|
|
143
|
+
if (preload) scry.commandPreload = preload;
|
|
144
|
+
},
|
|
145
|
+
action: async ({ args, options: flags }) => {
|
|
146
|
+
const { runScry } = await import("./actions.mjs");
|
|
147
|
+
await exitWith(await runScry(await context(), args, flags));
|
|
148
|
+
},
|
|
149
|
+
options: [
|
|
150
|
+
{
|
|
151
|
+
text: "--impact",
|
|
152
|
+
description: "What a change to this file reaches",
|
|
153
|
+
type: "string"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
text: "--route",
|
|
157
|
+
description: "One route: \"<METHOD> <path>\"",
|
|
158
|
+
type: "string"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
text: "--feature",
|
|
162
|
+
description: "One feature by id",
|
|
163
|
+
type: "string"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
text: "--flow",
|
|
167
|
+
description: "One flow: <feature>/<flow>",
|
|
168
|
+
type: "string"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
text: "--search",
|
|
172
|
+
description: "Search by words",
|
|
173
|
+
type: "string"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
text: "--limit",
|
|
177
|
+
description: "--search: most hits (default 20)",
|
|
178
|
+
type: "number"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
text: "--all",
|
|
182
|
+
description: "--impact: print every line of every list (text output stops at 20)",
|
|
183
|
+
type: "boolean"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
text: "--json, -j",
|
|
187
|
+
description: "Print the answer as JSON",
|
|
188
|
+
type: "boolean"
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
});
|
|
192
|
+
withMcpTools(grimoire, [(mcp) => createGrimoireMcpTools(mcp, options)]);
|
|
193
|
+
withExplainCodes(grimoire, explainCode);
|
|
194
|
+
return [grimoire, scry];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { registerGrimoireCommands };
|
|
199
|
+
//# sourceMappingURL=commands.mjs.map
|