@warlock.js/grimoire 5.63.1 → 5.65.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 +61 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +24 -2
- package/esm/book/build.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +11 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/api-snapshot.mjs +39 -0
- package/esm/check/rules/api-snapshot.mjs.map +1 -0
- package/esm/check/rules/code-rules.mjs +45 -0
- package/esm/check/rules/code-rules.mjs.map +1 -0
- package/esm/check/rules/drift.mjs +54 -0
- package/esm/check/rules/drift.mjs.map +1 -0
- package/esm/check/rules/focused-tests.mjs +39 -0
- package/esm/check/rules/focused-tests.mjs.map +1 -0
- package/esm/check/rules/shows.mjs +52 -0
- package/esm/check/rules/shows.mjs.map +1 -0
- package/esm/codes/codes.d.mts +48 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +26 -1
- 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/guard.d.mts +104 -0
- package/esm/contracts/guard.d.mts.map +1 -0
- package/esm/contracts/index.mjs +5 -0
- package/esm/contracts/matrix.d.mts +75 -0
- package/esm/contracts/matrix.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +42 -0
- package/esm/contracts/scry.d.mts.map +1 -1
- package/esm/contracts/settings.d.mts +71 -0
- package/esm/contracts/settings.d.mts.map +1 -0
- package/esm/contracts/settings.mjs +67 -0
- package/esm/contracts/settings.mjs.map +1 -0
- package/esm/contracts/shots.d.mts +146 -0
- package/esm/contracts/shots.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +10 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +13 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs +7 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/approvals.mjs +59 -0
- package/esm/devtools/approvals.mjs.map +1 -0
- package/esm/devtools/data.mjs +2 -0
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/graphs.mjs +13 -3
- package/esm/devtools/graphs.mjs.map +1 -1
- package/esm/devtools/index.d.mts +7 -0
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +33 -3
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/matrix.mjs +207 -0
- package/esm/devtools/matrix.mjs.map +1 -0
- package/esm/devtools/product-map.d.mts.map +1 -1
- package/esm/devtools/product-map.mjs +87 -1
- package/esm/devtools/product-map.mjs.map +1 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +12 -3
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +13 -3
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/git/index.d.mts +20 -0
- package/esm/git/index.d.mts.map +1 -0
- package/esm/git/index.mjs +280 -0
- package/esm/git/index.mjs.map +1 -0
- package/esm/guard/api.mjs +70 -0
- package/esm/guard/api.mjs.map +1 -0
- package/esm/guard/assertions.mjs +18 -0
- package/esm/guard/assertions.mjs.map +1 -0
- package/esm/guard/collect.mjs +139 -0
- package/esm/guard/collect.mjs.map +1 -0
- package/esm/guard/format.mjs +27 -0
- package/esm/guard/format.mjs.map +1 -0
- package/esm/guard/glob.mjs +79 -0
- package/esm/guard/glob.mjs.map +1 -0
- package/esm/guard/index.mjs +9 -0
- package/esm/guard/rules.mjs +310 -0
- package/esm/guard/rules.mjs.map +1 -0
- package/esm/guard/scope.mjs +95 -0
- package/esm/guard/scope.mjs.map +1 -0
- package/esm/index.d.mts +10 -3
- package/esm/index.mjs +6 -2
- package/esm/paths/index.d.mts +15 -1
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +27 -3
- package/esm/paths/index.mjs.map +1 -1
- package/esm/proves/index.mjs +2 -1
- package/esm/proves/scan-proofs.mjs +1 -1
- package/esm/proves/scan-proofs.mjs.map +1 -1
- package/esm/proves/scan-shows.d.mts +21 -0
- package/esm/proves/scan-shows.d.mts.map +1 -0
- package/esm/proves/scan-shows.mjs +168 -0
- package/esm/proves/scan-shows.mjs.map +1 -0
- package/esm/releases/index.d.mts.map +1 -1
- package/esm/releases/index.mjs +5 -3
- package/esm/releases/index.mjs.map +1 -1
- package/esm/releases/stamp.mjs +121 -0
- package/esm/releases/stamp.mjs.map +1 -0
- package/esm/rules/focused.mjs +26 -0
- package/esm/rules/focused.mjs.map +1 -0
- package/esm/rules/index.mjs +88 -0
- package/esm/rules/index.mjs.map +1 -0
- package/esm/rules/logical-css.mjs +112 -0
- package/esm/rules/logical-css.mjs.map +1 -0
- package/esm/rules/no-js-imports.mjs +22 -0
- package/esm/rules/no-js-imports.mjs.map +1 -0
- package/esm/rules/scan.mjs +196 -0
- package/esm/rules/scan.mjs.map +1 -0
- package/esm/rules/specific-errors.mjs +51 -0
- package/esm/rules/specific-errors.mjs.map +1 -0
- package/esm/rules/type-discriminator.mjs +27 -0
- package/esm/rules/type-discriminator.mjs.map +1 -0
- package/esm/scry/also-changes.mjs +107 -0
- package/esm/scry/also-changes.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +35 -0
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +40 -2
- package/esm/scry/query.mjs.map +1 -1
- package/esm/scry/search.d.mts.map +1 -1
- package/esm/scry/search.mjs +43 -11
- package/esm/scry/search.mjs.map +1 -1
- package/esm/shots/approve.mjs +195 -0
- package/esm/shots/approve.mjs.map +1 -0
- package/esm/shots/drift.mjs +174 -0
- package/esm/shots/drift.mjs.map +1 -0
- package/esm/shots/png.mjs +166 -0
- package/esm/shots/png.mjs.map +1 -0
- package/esm/shots/state.mjs +43 -0
- package/esm/shots/state.mjs.map +1 -0
- package/esm/shots/store.mjs +66 -0
- package/esm/shots/store.mjs.map +1 -0
- package/esm/shots/touched.mjs +38 -0
- package/esm/shots/touched.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +22 -2
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/api-command.mjs +41 -0
- package/esm/warlock/api-command.mjs.map +1 -0
- package/esm/warlock/approve-command.mjs +80 -0
- package/esm/warlock/approve-command.mjs.map +1 -0
- package/esm/warlock/collect-off-thread.mjs +66 -0
- package/esm/warlock/collect-off-thread.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +1 -1
- package/esm/warlock/commands.d.mts.map +1 -1
- package/esm/warlock/commands.mjs +61 -8
- package/esm/warlock/commands.mjs.map +1 -1
- package/esm/warlock/guard-command.mjs +116 -0
- package/esm/warlock/guard-command.mjs.map +1 -0
- package/esm/warlock/index.d.mts +2 -1
- package/esm/warlock/index.mjs +2 -1
- package/esm/warlock/languages.mjs +75 -0
- package/esm/warlock/languages.mjs.map +1 -0
- package/esm/warlock/mcp-tools.mjs +2 -2
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/warlock/release-command.mjs +65 -0
- package/esm/warlock/release-command.mjs.map +1 -0
- package/esm/warlock/shows.d.mts +35 -0
- package/esm/warlock/shows.d.mts.map +1 -0
- package/esm/warlock/shows.mjs +195 -0
- package/esm/warlock/shows.mjs.map +1 -0
- package/esm/workspace/cache.mjs +4 -1
- package/esm/workspace/cache.mjs.map +1 -1
- package/esm/workspace/derived.mjs +11 -6
- package/esm/workspace/derived.mjs.map +1 -1
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +8 -1
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/workspace/stored.mjs +4 -1
- package/esm/workspace/stored.mjs.map +1 -1
- package/esm/written/features.mjs +21 -5
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/index.mjs +2 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +16 -3
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/esm/written/settings.d.mts +11 -0
- package/esm/written/settings.d.mts.map +1 -0
- package/esm/written/settings.mjs +88 -0
- package/esm/written/settings.mjs.map +1 -0
- package/llms-full.txt +282 -39
- package/llms.txt +2 -0
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +4 -0
- package/skills/describe-an-app/SKILL.md +4 -1
- package/skills/guard-a-change/SKILL.md +85 -0
- package/skills/index.md +7 -3
- package/skills/record-a-change/SKILL.md +52 -16
- package/skills/review-a-change/SKILL.md +53 -0
- package/skills/use-the-grimoire/SKILL.md +27 -18
- package/skills/write-a-feature/SKILL.md +42 -1
- package/ui/grimoire-view.js +756 -40
- package/ui/grimoire.css +303 -28
- package/ui/product-map.css +43 -7
- package/ui/product-map.js +212 -37
|
@@ -2,7 +2,7 @@ import { WarlockAdapterOptions } from "./adapter.mjs";
|
|
|
2
2
|
import { CLICommand } from "@warlock.js/core";
|
|
3
3
|
//#region ../../packages/grimoire/src/warlock/commands.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* The `grimoire <action> [
|
|
5
|
+
* The `grimoire <action> [name]` and `scry [file]` commands, with the
|
|
6
6
|
* Grimoire MCP tools and the `GRnnnn` explainer attached. `cli.commands`
|
|
7
7
|
* accepts this array as one entry.
|
|
8
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/commands.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"commands.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/commands.ts"],"mappings":";;;;;;;;;;;;wBA8FgB,yBAAyB,UAAS,wBAA6B"}
|
package/esm/warlock/commands.mjs
CHANGED
|
@@ -12,7 +12,8 @@ const BOOT = {
|
|
|
12
12
|
runtimeStrategy: "development",
|
|
13
13
|
config: true,
|
|
14
14
|
env: true,
|
|
15
|
-
bootstrap: true
|
|
15
|
+
bootstrap: true,
|
|
16
|
+
tolerant: true
|
|
16
17
|
};
|
|
17
18
|
/** No boot, but a multi-site app's `src/config/web.ts` (its sites' base paths shape the page routes). */
|
|
18
19
|
const WEB_CONFIG = { config: ["web"] };
|
|
@@ -29,7 +30,10 @@ async function preloadFor(boot) {
|
|
|
29
30
|
const GRIMOIRE_ACTIONS = [
|
|
30
31
|
"build",
|
|
31
32
|
"check",
|
|
32
|
-
"release"
|
|
33
|
+
"release",
|
|
34
|
+
"guard",
|
|
35
|
+
"approve",
|
|
36
|
+
"reject"
|
|
33
37
|
];
|
|
34
38
|
/** Print with the stream's own write, so a boot that moves `console.log` never mixes into the answer. */
|
|
35
39
|
const io = {
|
|
@@ -56,7 +60,7 @@ function explainCode(code) {
|
|
|
56
60
|
} : void 0;
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
59
|
-
* The `grimoire <action> [
|
|
63
|
+
* The `grimoire <action> [name]` and `scry [file]` commands, with the
|
|
60
64
|
* Grimoire MCP tools and the `GRnnnn` explainer attached. `cli.commands`
|
|
61
65
|
* accepts this array as one entry.
|
|
62
66
|
*
|
|
@@ -76,10 +80,15 @@ function registerGrimoireCommands(options = {}) {
|
|
|
76
80
|
io
|
|
77
81
|
});
|
|
78
82
|
const grimoire = command({
|
|
79
|
-
name: "grimoire <action> [
|
|
80
|
-
description: "Grimoire (experimental): build the book (build [--force] [--site [--product] [--out <dir>]]), check the written files (check [--all]), collect a release (release <version>); --json for JSON",
|
|
83
|
+
name: "grimoire <action> [name]",
|
|
84
|
+
description: "Grimoire (experimental): build the book (build [--force] [--site [--product] [--out <dir>]]), check the written files (check [--all]), collect a release (release <version> [--stamp]), check a change against its task (guard [task] [--base <ref>] [--commits <range>]), approve or reject a change (approve|reject <id|feature/flow|api> [--all]); --json for JSON",
|
|
81
85
|
preAction: async ({ args, options: flags }) => {
|
|
82
86
|
grimoire.commandPreload = void 0;
|
|
87
|
+
if (args[0] === "guard" || args[0] === "approve" || args[0] === "reject") {
|
|
88
|
+
const preload = await preloadFor(async () => false);
|
|
89
|
+
if (preload) grimoire.commandPreload = preload;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
83
92
|
if (args[0] !== "build" && args[0] !== "check") return;
|
|
84
93
|
const preload = await preloadFor(async () => (await import("./actions.mjs")).needsBoot(process.cwd(), flags.force === true));
|
|
85
94
|
if (preload) grimoire.commandPreload = preload;
|
|
@@ -87,7 +96,7 @@ function registerGrimoireCommands(options = {}) {
|
|
|
87
96
|
action: async ({ args, options: flags }) => {
|
|
88
97
|
const actions = await import("./actions.mjs");
|
|
89
98
|
const ctx = await context();
|
|
90
|
-
const [name,
|
|
99
|
+
const [name, target] = args;
|
|
91
100
|
let code;
|
|
92
101
|
switch (name) {
|
|
93
102
|
case "build":
|
|
@@ -97,7 +106,16 @@ function registerGrimoireCommands(options = {}) {
|
|
|
97
106
|
code = await actions.runCheck(ctx, flags);
|
|
98
107
|
break;
|
|
99
108
|
case "release":
|
|
100
|
-
code = await actions.runRelease(ctx,
|
|
109
|
+
code = flags.stamp === true ? await (await import("./release-command.mjs")).runStampRelease(ctx, target, flags) : await actions.runRelease(ctx, target, flags);
|
|
110
|
+
break;
|
|
111
|
+
case "guard":
|
|
112
|
+
code = await (await import("./guard-command.mjs")).runGuard(ctx, target, flags);
|
|
113
|
+
break;
|
|
114
|
+
case "approve":
|
|
115
|
+
code = target === "api" ? await (await import("./api-command.mjs")).runApproveApi(ctx, flags) : await (await import("./approve-command.mjs")).runApprove(ctx, target, flags);
|
|
116
|
+
break;
|
|
117
|
+
case "reject":
|
|
118
|
+
code = await (await import("./approve-command.mjs")).runReject(ctx, target, flags);
|
|
101
119
|
break;
|
|
102
120
|
default: {
|
|
103
121
|
const { GrimoireError } = await import("../codes/index.mjs");
|
|
@@ -114,7 +132,7 @@ function registerGrimoireCommands(options = {}) {
|
|
|
114
132
|
},
|
|
115
133
|
{
|
|
116
134
|
text: "--all",
|
|
117
|
-
description: "check: list every finding (text output groups warnings by code)",
|
|
135
|
+
description: "check: list every finding (text output groups warnings by code); approve, reject: every change not approved",
|
|
118
136
|
type: "boolean"
|
|
119
137
|
},
|
|
120
138
|
{
|
|
@@ -136,6 +154,41 @@ function registerGrimoireCommands(options = {}) {
|
|
|
136
154
|
text: "--out",
|
|
137
155
|
description: "build --site: the folder to write the site to (project-relative)",
|
|
138
156
|
type: "string"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
text: "--stamp",
|
|
160
|
+
description: "release: move every changelog's Unreleased entries under the release (version from package.json when omitted), write the release file, then collect",
|
|
161
|
+
type: "boolean"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
text: "--date",
|
|
165
|
+
description: "release --stamp: the release date, yyyy-mm-dd (default today)",
|
|
166
|
+
type: "string"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
text: "--base",
|
|
170
|
+
description: "guard: the git ref the change is compared with (default the merge base with the default branch)",
|
|
171
|
+
type: "string"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
text: "--commits",
|
|
175
|
+
description: "guard: a commit range (origin/main..HEAD); every commit must name its task, and the tasks it names are guarded",
|
|
176
|
+
type: "string"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
text: "--hook",
|
|
180
|
+
description: "guard: agent-hook mode, findings on stderr and exit code 2 when the change must not stop here",
|
|
181
|
+
type: "boolean"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
text: "--lang",
|
|
185
|
+
description: "approve, reject: only the images of this language",
|
|
186
|
+
type: "string"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
text: "--note",
|
|
190
|
+
description: "reject: why, in the owner's words",
|
|
191
|
+
type: "string"
|
|
139
192
|
}
|
|
140
193
|
]
|
|
141
194
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/commands.ts"],"sourcesContent":["/**\n * The `warlock grimoire` and `warlock scry` commands. Light on purpose: the\n * work lives in `./actions`, imported when a command runs.\n */\nimport {\n command,\n withExplainCodes,\n withMcpTools,\n type CLICommand,\n type CLICommandPreload,\n} from \"@warlock.js/core\";\nimport { explainGrimoireCode, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\nimport { createGrimoireMcpTools } from \"./mcp-tools\";\n\n/** The preload of a command that reads routes: the `warlock inspect` boot. */\nconst BOOT: CLICommandPreload = {\n runtimeStrategy: \"development\",\n config: true,\n env: true,\n bootstrap: true,\n};\n\n/** No boot, but a multi-site app's `src/config/web.ts` (its sites' base paths shape the page routes). */\nconst WEB_CONFIG: CLICommandPreload = { config: [\"web\"] };\n\n/** The preload of a question that boots only when `boot` says so. */\nasync function preloadFor(boot: () => Promise<boolean>): Promise<CLICommandPreload | undefined> {\n try {\n const actions = await import(\"./actions\");\n\n if (await boot()) return BOOT;\n\n return (await actions.isMultiSite(process.cwd())) ? WEB_CONFIG : undefined;\n } catch {\n // The action runs the same steps and reports the problem with its code.\n return undefined;\n }\n}\n\nconst GRIMOIRE_ACTIONS = [\"build\", \"check\", \"release\"] as const;\n\n/** Print with the stream's own write, so a boot that moves `console.log` never mixes into the answer. */\nconst io = {\n out: (line: string) => void process.stdout.write(`${line}\\n`),\n err: (line: string) => void process.stderr.write(`${line}\\n`),\n};\n\n/** Exit with `code` once stdout and stderr are flushed (a non-zero code only; 0 lets the CLI finish). */\nasync function exitWith(code: number): Promise<void> {\n if (code === 0) return;\n\n process.exitCode = code;\n\n await Promise.race([\n Promise.all(\n [process.stdout, process.stderr].map(\n (stream) => new Promise<void>((resolve) => stream.write(\"\", () => resolve())),\n ),\n ),\n new Promise<void>((resolve) => setTimeout(resolve, 500).unref()),\n ]);\n\n process.exit(code);\n}\n\n/** Explain a Grimoire code for `warlock explain GR2001`. */\nfunction explainCode(code: string) {\n const definition = explainGrimoireCode(code);\n\n return definition\n ? {\n code: definition.code,\n title: definition.title,\n area: definition.area,\n fix: definition.fix,\n skill: definition.skill,\n docs: grimoireCodeDocsUrl(definition.code),\n }\n : undefined;\n}\n\n/**\n * The `grimoire <action> [release]` and `scry [file]` commands, with the\n * Grimoire MCP tools and the `GRnnnn` explainer attached. `cli.commands`\n * accepts this array as one entry.\n *\n * @example\n * // warlock.config.ts\n * export default defineConfig({ cli: { commands: [registerGrimoireCommands()] } });\n */\nexport function registerGrimoireCommands(options: WarlockAdapterOptions = {}): CLICommand[] {\n let adapter: Promise<BookAdapter> | undefined;\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??= import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter(options),\n );\n\n return adapter;\n };\n const context = async () => ({ root: process.cwd(), adapter: await loadAdapter(), io });\n\n const grimoire: CLICommand = command({\n name: \"grimoire <action> [release]\",\n description:\n \"Grimoire (experimental): build the book (build [--force] [--site [--product] [--out <dir>]]), check the written files (check [--all]), collect a release (release <version>); --json for JSON\",\n preAction: async ({ args, options: flags }) => {\n grimoire.commandPreload = undefined;\n\n if (args[0] !== \"build\" && args[0] !== \"check\") return;\n\n const preload = await preloadFor(async () =>\n (await import(\"./actions\")).needsBoot(process.cwd(), flags.force === true),\n );\n\n if (preload) grimoire.commandPreload = preload;\n },\n action: async ({ args, options: flags }) => {\n const actions = await import(\"./actions\");\n const ctx = await context();\n const [name, release] = args;\n let code: number;\n\n switch (name) {\n case \"build\":\n code = await actions.runBuild(ctx, flags);\n break;\n case \"check\":\n code = await actions.runCheck(ctx, flags);\n break;\n case \"release\":\n code = await actions.runRelease(ctx, release, flags);\n break;\n default: {\n const { GrimoireError } = await import(\"../codes\");\n\n code = actions.reportError(\n io,\n new GrimoireError(\n \"GR9006\",\n `Unknown action ${JSON.stringify(name ?? \"\")}. Use one of: ${GRIMOIRE_ACTIONS.join(\", \")} (warlock grimoire build).`,\n ),\n );\n }\n }\n\n await exitWith(code);\n },\n options: [\n { text: \"--json, -j\", description: \"Print the result as JSON\", type: \"boolean\" },\n {\n text: \"--all\",\n description: \"check: list every finding (text output groups warnings by code)\",\n type: \"boolean\",\n },\n {\n text: \"--force, -f\",\n description:\n \"build: rebuild every book entry and read the routes again, and write the site even when it is up to date\",\n type: \"boolean\",\n },\n {\n text: \"--site\",\n description: \"build: also write the static Grimoire site (default grimoire/book/site)\",\n type: \"boolean\",\n },\n {\n text: \"--product\",\n description:\n \"build --site: export the share-safe Product map only (no file paths, test names or per-file answers; opens on the map)\",\n type: \"boolean\",\n },\n {\n text: \"--out\",\n description: \"build --site: the folder to write the site to (project-relative)\",\n type: \"string\",\n },\n ],\n });\n\n const scry: CLICommand = command({\n name: \"scry [file]\",\n description:\n 'Grimoire (experimental): ask the stored book about a file, --impact <file>, --route \"<METHOD path>\" (an API route or a page URL), --feature <id>, --flow <feature>/<flow> or --search \"<text>\" (pass the whole sentence; hits come in score order, --app limits to one app); --json for JSON. Reads only; run warlock grimoire build after editing',\n preAction: async ({ options: flags }) => {\n scry.commandPreload = undefined;\n\n // scry only reads the stored book: it never boots the app (a multi-site app still loads its web config).\n const preload = await preloadFor(async () => false);\n\n if (preload) scry.commandPreload = preload;\n },\n action: async ({ args, options: flags }) => {\n const { runScry } = await import(\"./actions\");\n\n await exitWith(await runScry(await context(), args, flags));\n },\n options: [\n { text: \"--impact\", description: \"What a change to this file reaches\", type: \"string\" },\n {\n text: \"--route\",\n description:\n 'One route or page URL: \"<METHOD> <path>\" (GET and HEAD also find pages and screens)',\n type: \"string\",\n },\n { text: \"--site\", description: \"--route: only the page of this site or app\", type: \"string\" },\n { text: \"--feature\", description: \"One feature by id\", type: \"string\" },\n { text: \"--flow\", description: \"One flow: <feature>/<flow>\", type: \"string\" },\n {\n text: \"--search\",\n description:\n \"Search by a sentence (a commit title, a bug report) or words; names first, then best match\",\n type: \"string\",\n },\n { text: \"--app\", description: \"--search: only hits of this app\", type: \"string\" },\n { text: \"--limit\", description: \"--search: most hits (default 20)\", type: \"number\" },\n {\n text: \"--all\",\n description: \"--impact: print every line of every list (text output stops at 20)\",\n type: \"boolean\",\n },\n { text: \"--json, -j\", description: \"Print the answer as JSON\", type: \"boolean\" },\n ],\n });\n\n withMcpTools(grimoire, [(mcp) => createGrimoireMcpTools(mcp, options)]);\n withExplainCodes(grimoire, explainCode);\n\n return [grimoire, scry];\n}\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,OAA0B;CAC9B,iBAAiB;CACjB,QAAQ;CACR,KAAK;CACL,WAAW;AACb;;AAGA,MAAM,aAAgC,EAAE,QAAQ,CAAC,KAAK,EAAE;;AAGxD,eAAe,WAAW,MAAsE;CAC9F,IAAI;EACF,MAAM,UAAU,MAAM,OAAO;EAE7B,IAAI,MAAM,KAAK,GAAG,OAAO;EAEzB,OAAQ,MAAM,QAAQ,YAAY,QAAQ,IAAI,CAAC,IAAK,aAAa;CACnE,QAAQ;EAEN;CACF;AACF;AAEA,MAAM,mBAAmB;CAAC;CAAS;CAAS;AAAS;;AAGrD,MAAM,KAAK;CACT,MAAM,SAAiB,KAAK,QAAQ,OAAO,MAAM,GAAG,KAAK,GAAG;CAC5D,MAAM,SAAiB,KAAK,QAAQ,OAAO,MAAM,GAAG,KAAK,GAAG;AAC9D;;AAGA,eAAe,SAAS,MAA6B;CACnD,IAAI,SAAS,GAAG;CAEhB,QAAQ,WAAW;CAEnB,MAAM,QAAQ,KAAK,CACjB,QAAQ,IACN,CAAC,QAAQ,QAAQ,QAAQ,MAAM,CAAC,CAAC,KAC9B,WAAW,IAAI,SAAe,YAAY,OAAO,MAAM,UAAU,QAAQ,CAAC,CAAC,CAC9E,CACF,GACA,IAAI,SAAe,YAAY,WAAW,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,CACjE,CAAC;CAED,QAAQ,KAAK,IAA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B,MAAM;GAAU;EACjF;CACF,CAAC;CAED,aAAa,UAAU,EAAE,QAAQ,uBAAuB,KAAK,OAAO,CAAC,CAAC;CACtE,iBAAiB,UAAU,WAAW;CAEtC,OAAO,CAAC,UAAU,IAAI;AACxB"}
|
|
1
|
+
{"version":3,"file":"commands.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/commands.ts"],"sourcesContent":["/**\n * The `warlock grimoire` and `warlock scry` commands. Light on purpose: the\n * work lives in `./actions`, imported when a command runs.\n */\nimport {\n command,\n withExplainCodes,\n withMcpTools,\n type CLICommand,\n type CLICommandPreload,\n} from \"@warlock.js/core\";\nimport { explainGrimoireCode, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\nimport { createGrimoireMcpTools } from \"./mcp-tools\";\n\n/** The preload of a command that reads routes: the `warlock inspect` boot. */\nconst BOOT: CLICommandPreload = {\n runtimeStrategy: \"development\",\n config: true,\n env: true,\n bootstrap: true,\n // An app that does not boot still gets its cached routes (GR8002).\n tolerant: true,\n};\n\n/** No boot, but a multi-site app's `src/config/web.ts` (its sites' base paths shape the page routes). */\nconst WEB_CONFIG: CLICommandPreload = { config: [\"web\"] };\n\n/** The preload of a question that boots only when `boot` says so. */\nasync function preloadFor(boot: () => Promise<boolean>): Promise<CLICommandPreload | undefined> {\n try {\n const actions = await import(\"./actions\");\n\n if (await boot()) return BOOT;\n\n return (await actions.isMultiSite(process.cwd())) ? WEB_CONFIG : undefined;\n } catch {\n // The action runs the same steps and reports the problem with its code.\n return undefined;\n }\n}\n\nconst GRIMOIRE_ACTIONS = [\"build\", \"check\", \"release\", \"guard\", \"approve\", \"reject\"] as const;\n\n/** Print with the stream's own write, so a boot that moves `console.log` never mixes into the answer. */\nconst io = {\n out: (line: string) => void process.stdout.write(`${line}\\n`),\n err: (line: string) => void process.stderr.write(`${line}\\n`),\n};\n\n/** Exit with `code` once stdout and stderr are flushed (a non-zero code only; 0 lets the CLI finish). */\nasync function exitWith(code: number): Promise<void> {\n if (code === 0) return;\n\n process.exitCode = code;\n\n await Promise.race([\n Promise.all(\n [process.stdout, process.stderr].map(\n (stream) => new Promise<void>((resolve) => stream.write(\"\", () => resolve())),\n ),\n ),\n new Promise<void>((resolve) => setTimeout(resolve, 500).unref()),\n ]);\n\n process.exit(code);\n}\n\n/** Explain a Grimoire code for `warlock explain GR2001`. */\nfunction explainCode(code: string) {\n const definition = explainGrimoireCode(code);\n\n return definition\n ? {\n code: definition.code,\n title: definition.title,\n area: definition.area,\n fix: definition.fix,\n skill: definition.skill,\n docs: grimoireCodeDocsUrl(definition.code),\n }\n : undefined;\n}\n\n/**\n * The `grimoire <action> [name]` and `scry [file]` commands, with the\n * Grimoire MCP tools and the `GRnnnn` explainer attached. `cli.commands`\n * accepts this array as one entry.\n *\n * @example\n * // warlock.config.ts\n * export default defineConfig({ cli: { commands: [registerGrimoireCommands()] } });\n */\nexport function registerGrimoireCommands(options: WarlockAdapterOptions = {}): CLICommand[] {\n let adapter: Promise<BookAdapter> | undefined;\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??= import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter(options),\n );\n\n return adapter;\n };\n const context = async () => ({ root: process.cwd(), adapter: await loadAdapter(), io });\n\n const grimoire: CLICommand = command({\n name: \"grimoire <action> [name]\",\n description:\n \"Grimoire (experimental): build the book (build [--force] [--site [--product] [--out <dir>]]), check the written files (check [--all]), collect a release (release <version> [--stamp]), check a change against its task (guard [task] [--base <ref>] [--commits <range>]), approve or reject a change (approve|reject <id|feature/flow|api> [--all]); --json for JSON\",\n preAction: async ({ args, options: flags }) => {\n grimoire.commandPreload = undefined;\n\n // guard, approve and reject read the cached route facts: they never boot the app.\n if (args[0] === \"guard\" || args[0] === \"approve\" || args[0] === \"reject\") {\n const preload = await preloadFor(async () => false);\n\n if (preload) grimoire.commandPreload = preload;\n\n return;\n }\n\n if (args[0] !== \"build\" && args[0] !== \"check\") return;\n\n const preload = await preloadFor(async () =>\n (await import(\"./actions\")).needsBoot(process.cwd(), flags.force === true),\n );\n\n if (preload) grimoire.commandPreload = preload;\n },\n action: async ({ args, options: flags }) => {\n const actions = await import(\"./actions\");\n const ctx = await context();\n const [name, target] = args;\n let code: number;\n\n switch (name) {\n case \"build\":\n code = await actions.runBuild(ctx, flags);\n break;\n case \"check\":\n code = await actions.runCheck(ctx, flags);\n break;\n case \"release\":\n code =\n flags.stamp === true\n ? await (await import(\"./release-command\")).runStampRelease(ctx, target, flags)\n : await actions.runRelease(ctx, target, flags);\n break;\n case \"guard\":\n code = await (await import(\"./guard-command\")).runGuard(ctx, target, flags);\n break;\n case \"approve\":\n code =\n target === \"api\"\n ? await (await import(\"./api-command\")).runApproveApi(ctx, flags)\n : await (await import(\"./approve-command\")).runApprove(ctx, target, flags);\n break;\n case \"reject\":\n code = await (await import(\"./approve-command\")).runReject(ctx, target, flags);\n break;\n default: {\n const { GrimoireError } = await import(\"../codes\");\n\n code = actions.reportError(\n io,\n new GrimoireError(\n \"GR9006\",\n `Unknown action ${JSON.stringify(name ?? \"\")}. Use one of: ${GRIMOIRE_ACTIONS.join(\", \")} (warlock grimoire build).`,\n ),\n );\n }\n }\n\n await exitWith(code);\n },\n options: [\n { text: \"--json, -j\", description: \"Print the result as JSON\", type: \"boolean\" },\n {\n text: \"--all\",\n description:\n \"check: list every finding (text output groups warnings by code); approve, reject: every change not approved\",\n type: \"boolean\",\n },\n {\n text: \"--force, -f\",\n description:\n \"build: rebuild every book entry and read the routes again, and write the site even when it is up to date\",\n type: \"boolean\",\n },\n {\n text: \"--site\",\n description: \"build: also write the static Grimoire site (default grimoire/book/site)\",\n type: \"boolean\",\n },\n {\n text: \"--product\",\n description:\n \"build --site: export the share-safe Product map only (no file paths, test names or per-file answers; opens on the map)\",\n type: \"boolean\",\n },\n {\n text: \"--out\",\n description: \"build --site: the folder to write the site to (project-relative)\",\n type: \"string\",\n },\n {\n text: \"--stamp\",\n description:\n \"release: move every changelog's Unreleased entries under the release (version from package.json when omitted), write the release file, then collect\",\n type: \"boolean\",\n },\n {\n text: \"--date\",\n description: \"release --stamp: the release date, yyyy-mm-dd (default today)\",\n type: \"string\",\n },\n {\n text: \"--base\",\n description:\n \"guard: the git ref the change is compared with (default the merge base with the default branch)\",\n type: \"string\",\n },\n {\n text: \"--commits\",\n description:\n \"guard: a commit range (origin/main..HEAD); every commit must name its task, and the tasks it names are guarded\",\n type: \"string\",\n },\n {\n text: \"--hook\",\n description:\n \"guard: agent-hook mode, findings on stderr and exit code 2 when the change must not stop here\",\n type: \"boolean\",\n },\n {\n text: \"--lang\",\n description: \"approve, reject: only the images of this language\",\n type: \"string\",\n },\n {\n text: \"--note\",\n description: \"reject: why, in the owner's words\",\n type: \"string\",\n },\n ],\n });\n\n const scry: CLICommand = command({\n name: \"scry [file]\",\n description:\n 'Grimoire (experimental): ask the stored book about a file, --impact <file>, --route \"<METHOD path>\" (an API route or a page URL), --feature <id>, --flow <feature>/<flow> or --search \"<text>\" (pass the whole sentence; hits come in score order, --app limits to one app); --json for JSON. Reads only; run warlock grimoire build after editing',\n preAction: async ({ options: flags }) => {\n scry.commandPreload = undefined;\n\n // scry only reads the stored book: it never boots the app (a multi-site app still loads its web config).\n const preload = await preloadFor(async () => false);\n\n if (preload) scry.commandPreload = preload;\n },\n action: async ({ args, options: flags }) => {\n const { runScry } = await import(\"./actions\");\n\n await exitWith(await runScry(await context(), args, flags));\n },\n options: [\n { text: \"--impact\", description: \"What a change to this file reaches\", type: \"string\" },\n {\n text: \"--route\",\n description:\n 'One route or page URL: \"<METHOD> <path>\" (GET and HEAD also find pages and screens)',\n type: \"string\",\n },\n { text: \"--site\", description: \"--route: only the page of this site or app\", type: \"string\" },\n { text: \"--feature\", description: \"One feature by id\", type: \"string\" },\n { text: \"--flow\", description: \"One flow: <feature>/<flow>\", type: \"string\" },\n {\n text: \"--search\",\n description:\n \"Search by a sentence (a commit title, a bug report) or words; names first, then best match\",\n type: \"string\",\n },\n { text: \"--app\", description: \"--search: only hits of this app\", type: \"string\" },\n { text: \"--limit\", description: \"--search: most hits (default 20)\", type: \"number\" },\n {\n text: \"--all\",\n description: \"--impact: print every line of every list (text output stops at 20)\",\n type: \"boolean\",\n },\n { text: \"--json, -j\", description: \"Print the answer as JSON\", type: \"boolean\" },\n ],\n });\n\n withMcpTools(grimoire, [(mcp) => createGrimoireMcpTools(mcp, options)]);\n withExplainCodes(grimoire, explainCode);\n\n return [grimoire, scry];\n}\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,OAA0B;CAC9B,iBAAiB;CACjB,QAAQ;CACR,KAAK;CACL,WAAW;CAEX,UAAU;AACZ;;AAGA,MAAM,aAAgC,EAAE,QAAQ,CAAC,KAAK,EAAE;;AAGxD,eAAe,WAAW,MAAsE;CAC9F,IAAI;EACF,MAAM,UAAU,MAAM,OAAO;EAE7B,IAAI,MAAM,KAAK,GAAG,OAAO;EAEzB,OAAQ,MAAM,QAAQ,YAAY,QAAQ,IAAI,CAAC,IAAK,aAAa;CACnE,QAAQ;EAEN;CACF;AACF;AAEA,MAAM,mBAAmB;CAAC;CAAS;CAAS;CAAW;CAAS;CAAW;AAAQ;;AAGnF,MAAM,KAAK;CACT,MAAM,SAAiB,KAAK,QAAQ,OAAO,MAAM,GAAG,KAAK,GAAG;CAC5D,MAAM,SAAiB,KAAK,QAAQ,OAAO,MAAM,GAAG,KAAK,GAAG;AAC9D;;AAGA,eAAe,SAAS,MAA6B;CACnD,IAAI,SAAS,GAAG;CAEhB,QAAQ,WAAW;CAEnB,MAAM,QAAQ,KAAK,CACjB,QAAQ,IACN,CAAC,QAAQ,QAAQ,QAAQ,MAAM,CAAC,CAAC,KAC9B,WAAW,IAAI,SAAe,YAAY,OAAO,MAAM,UAAU,QAAQ,CAAC,CAAC,CAC9E,CACF,GACA,IAAI,SAAe,YAAY,WAAW,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,CACjE,CAAC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MAAM;GACR;GACA;IACE,MAAM;IACN,aAAa;IACb,MAAM;GACR;EACF;CACF,CAAC;CAED,MAAM,OAAmB,QAAQ;EAC/B,MAAM;EACN,aACE;EACF,WAAW,OAAO,EAAE,SAAS,YAAY;GACvC,KAAK,iBAAiB;GAGtB,MAAM,UAAU,MAAM,WAAW,YAAY,KAAK;GAElD,IAAI,SAAS,KAAK,iBAAiB;EACrC;EACA,QAAQ,OAAO,EAAE,MAAM,SAAS,YAAY;GAC1C,MAAM,EAAE,YAAY,MAAM,OAAO;GAEjC,MAAM,SAAS,MAAM,QAAQ,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC;EAC5D;EACA,SAAS;GACP;IAAE,MAAM;IAAY,aAAa;IAAsC,MAAM;GAAS;GACtF;IACE,MAAM;IACN,aACE;IACF,MAAM;GACR;GACA;IAAE,MAAM;IAAU,aAAa;IAA8C,MAAM;GAAS;GAC5F;IAAE,MAAM;IAAa,aAAa;IAAqB,MAAM;GAAS;GACtE;IAAE,MAAM;IAAU,aAAa;IAA8B,MAAM;GAAS;GAC5E;IACE,MAAM;IACN,aACE;IACF,MAAM;GACR;GACA;IAAE,MAAM;IAAS,aAAa;IAAmC,MAAM;GAAS;GAChF;IAAE,MAAM;IAAW,aAAa;IAAoC,MAAM;GAAS;GACnF;IACE,MAAM;IACN,aAAa;IACb,MAAM;GACR;GACA;IAAE,MAAM;IAAc,aAAa;IAA4B,MAAM;GAAU;EACjF;CACF,CAAC;CAED,aAAa,UAAU,EAAE,QAAQ,uBAAuB,KAAK,OAAO,CAAC,CAAC;CACtE,iBAAiB,UAAU,WAAW;CAEtC,OAAO,CAAC,UAAU,IAAI;AACxB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { GrimoireError } from "../codes/index.mjs";
|
|
2
|
+
import { openGrimoire } from "../workspace/index.mjs";
|
|
3
|
+
import { runGuardChecks } from "../guard/rules.mjs";
|
|
4
|
+
import { finishReport } from "../check/check-grimoire.mjs";
|
|
5
|
+
import { changedFiles, resolveBase } from "../git/index.mjs";
|
|
6
|
+
import { reportError } from "./actions.mjs";
|
|
7
|
+
import { collectGuardInput, guardedChanges } from "../guard/collect.mjs";
|
|
8
|
+
import { formatGuardReport } from "../guard/format.mjs";
|
|
9
|
+
import "../guard/index.mjs";
|
|
10
|
+
|
|
11
|
+
//#region ../../packages/grimoire/src/warlock/guard-command.ts
|
|
12
|
+
/**
|
|
13
|
+
* `warlock grimoire guard [task]`: the change (git diff against the base)
|
|
14
|
+
* checked against its task. The snapshot is opened with the cached route
|
|
15
|
+
* facts, so the app never boots; the book is refreshed like `check` does.
|
|
16
|
+
*/
|
|
17
|
+
const text = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
18
|
+
/**
|
|
19
|
+
* What an agent's Stop hook writes on stdin (JSON), read for at most
|
|
20
|
+
* `timeoutMs`; `""` when stdin is a terminal, closed or silent.
|
|
21
|
+
*/
|
|
22
|
+
function readHookInput(stream = process.stdin, timeoutMs = 1e3) {
|
|
23
|
+
if (stream.isTTY) return Promise.resolve("");
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
const chunks = [];
|
|
26
|
+
const finish = () => {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
stream.off("data", onData);
|
|
29
|
+
stream.off("end", finish);
|
|
30
|
+
stream.off("error", finish);
|
|
31
|
+
stream.pause();
|
|
32
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
33
|
+
};
|
|
34
|
+
const onData = (chunk) => {
|
|
35
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
36
|
+
};
|
|
37
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
38
|
+
timer.unref?.();
|
|
39
|
+
stream.on("data", onData);
|
|
40
|
+
stream.once("end", finish);
|
|
41
|
+
stream.once("error", finish);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** True when the hook input says the agent already continued once because of this hook (`stop_hook_active`). */
|
|
45
|
+
function stopHookActive(raw) {
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(raw);
|
|
48
|
+
return typeof parsed === "object" && parsed !== null && parsed.stop_hook_active === true;
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Run the guard and print its report. Exit code: 0 when no error, 1 on an
|
|
55
|
+
* error finding; with `--hook`, 2 instead of 1 (everything on stderr), and 0
|
|
56
|
+
* when the guard cannot run (no task, no git) or when the hook input on stdin
|
|
57
|
+
* says the agent already went on once because of it (`stop_hook_active`): a
|
|
58
|
+
* hook never traps an agent.
|
|
59
|
+
*/
|
|
60
|
+
async function runGuard(context, task, options = {}) {
|
|
61
|
+
const { root, adapter, io } = context;
|
|
62
|
+
const hook = options.hook === true;
|
|
63
|
+
const out = hook ? io.err : io.out;
|
|
64
|
+
try {
|
|
65
|
+
const base = await resolveBase(root, text(options.base));
|
|
66
|
+
const changed = guardedChanges(await changedFiles(root, base));
|
|
67
|
+
const snapshot = await openGrimoire(root, adapter, { routes: "cached" });
|
|
68
|
+
const input = await collectGuardInput(root, snapshot, changed, {
|
|
69
|
+
...task === void 0 ? {} : { task },
|
|
70
|
+
base,
|
|
71
|
+
...text(options.commits) === void 0 ? {} : { commits: text(options.commits) }
|
|
72
|
+
});
|
|
73
|
+
if (hook && input.scope === null) {
|
|
74
|
+
const missing = runGuardChecks({
|
|
75
|
+
...input,
|
|
76
|
+
changed: [],
|
|
77
|
+
commits: null
|
|
78
|
+
});
|
|
79
|
+
for (const finding of missing.filter((item) => item.code === "GR9008")) {
|
|
80
|
+
io.err(`note: ${finding.code} ${finding.message}`);
|
|
81
|
+
io.err(` fix: ${finding.hint}`);
|
|
82
|
+
}
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
const checked = finishReport(snapshot, runGuardChecks(input));
|
|
86
|
+
const report = {
|
|
87
|
+
schemaVersion: 1,
|
|
88
|
+
task: input.scope?.id ?? null,
|
|
89
|
+
base,
|
|
90
|
+
changed,
|
|
91
|
+
findings: checked.findings,
|
|
92
|
+
notApproved: snapshot.shots?.drift ?? [],
|
|
93
|
+
counts: checked.counts,
|
|
94
|
+
ok: checked.ok
|
|
95
|
+
};
|
|
96
|
+
if (options.json === true) out(JSON.stringify(report, null, 2));
|
|
97
|
+
else for (const line of formatGuardReport(report, root)) out(line);
|
|
98
|
+
if (report.ok) return 0;
|
|
99
|
+
if (!hook) return 1;
|
|
100
|
+
if (stopHookActive(typeof options.hookInput === "string" ? options.hookInput : await readHookInput())) {
|
|
101
|
+
io.err("note: the guard already stopped this agent once; the findings above are left for the reviewer.");
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
return 2;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (hook && error instanceof GrimoireError) {
|
|
107
|
+
io.err(`note: ${error.code} ${error.message}`);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
return reportError(io, error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { readHookInput, runGuard, stopHookActive };
|
|
116
|
+
//# sourceMappingURL=guard-command.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard-command.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/guard-command.ts"],"sourcesContent":["/**\n * `warlock grimoire guard [task]`: the change (git diff against the base)\n * checked against its task. The snapshot is opened with the cached route\n * facts, so the app never boots; the book is refreshed like `check` does.\n */\nimport { finishReport } from \"../check/check-grimoire\";\nimport { GrimoireError } from \"../codes\";\nimport type { GuardReport } from \"../contracts/guard\";\nimport { changedFiles, resolveBase } from \"../git\";\nimport { collectGuardInput, formatGuardReport, guardedChanges, runGuardChecks } from \"../guard\";\nimport { openGrimoire } from \"../workspace\";\nimport { reportError, type CommandContext } from \"./actions\";\n\n/** Options the command passes (`--base`, `--commits`, `--hook`, `--json`). */\nexport type GuardCommandOptions = Record<string, unknown>;\n\nconst text = (value: unknown): string | undefined =>\n typeof value === \"string\" && value.trim() !== \"\" ? value.trim() : undefined;\n\n/**\n * What an agent's Stop hook writes on stdin (JSON), read for at most\n * `timeoutMs`; `\"\"` when stdin is a terminal, closed or silent.\n */\nexport function readHookInput(\n stream: NodeJS.ReadStream = process.stdin,\n timeoutMs = 1000,\n): Promise<string> {\n if (stream.isTTY) return Promise.resolve(\"\");\n\n return new Promise((resolve) => {\n const chunks: Buffer[] = [];\n const finish = (): void => {\n clearTimeout(timer);\n stream.off(\"data\", onData);\n stream.off(\"end\", finish);\n stream.off(\"error\", finish);\n stream.pause();\n resolve(Buffer.concat(chunks).toString(\"utf8\"));\n };\n const onData = (chunk: Buffer | string): void => {\n chunks.push(typeof chunk === \"string\" ? Buffer.from(chunk) : chunk);\n };\n const timer = setTimeout(finish, timeoutMs);\n\n timer.unref?.();\n stream.on(\"data\", onData);\n stream.once(\"end\", finish);\n stream.once(\"error\", finish);\n });\n}\n\n/** True when the hook input says the agent already continued once because of this hook (`stop_hook_active`). */\nexport function stopHookActive(raw: string): boolean {\n try {\n const parsed: unknown = JSON.parse(raw);\n\n return (\n typeof parsed === \"object\" &&\n parsed !== null &&\n (parsed as Record<string, unknown>).stop_hook_active === true\n );\n } catch {\n return false;\n }\n}\n\n/**\n * Run the guard and print its report. Exit code: 0 when no error, 1 on an\n * error finding; with `--hook`, 2 instead of 1 (everything on stderr), and 0\n * when the guard cannot run (no task, no git) or when the hook input on stdin\n * says the agent already went on once because of it (`stop_hook_active`): a\n * hook never traps an agent.\n */\nexport async function runGuard(\n context: CommandContext,\n task: string | undefined,\n options: GuardCommandOptions = {},\n): Promise<number> {\n const { root, adapter, io } = context;\n const hook = options.hook === true;\n const out = hook ? io.err : io.out;\n\n try {\n const base = await resolveBase(root, text(options.base));\n // Listed before the snapshot is opened: opening writes the book, and a project without the ignore lines must not see it as a change.\n const changed = guardedChanges(await changedFiles(root, base));\n const snapshot = await openGrimoire(root, adapter, { routes: \"cached\" });\n const input = await collectGuardInput(root, snapshot, changed, {\n ...(task === undefined ? {} : { task }),\n base,\n ...(text(options.commits) === undefined ? {} : { commits: text(options.commits) as string }),\n });\n\n if (hook && input.scope === null) {\n const missing = runGuardChecks({ ...input, changed: [], commits: null });\n\n for (const finding of missing.filter((item) => item.code === \"GR9008\")) {\n io.err(`note: ${finding.code} ${finding.message}`);\n io.err(` fix: ${finding.hint}`);\n }\n\n return 0;\n }\n\n const checked = finishReport(snapshot, runGuardChecks(input));\n const report: GuardReport = {\n schemaVersion: 1,\n task: input.scope?.id ?? null,\n base,\n changed,\n findings: checked.findings,\n notApproved: snapshot.shots?.drift ?? [],\n counts: checked.counts,\n ok: checked.ok,\n };\n\n if (options.json === true) out(JSON.stringify(report, null, 2));\n else for (const line of formatGuardReport(report, root)) out(line);\n\n if (report.ok) return 0;\n\n if (!hook) return 1;\n\n // The agent already went on once because of this hook: report again, but let it stop, so a finding it may\n // not fix itself (a locked test, a wrong Files: line) never keeps it running.\n const hookInput =\n typeof options.hookInput === \"string\" ? options.hookInput : await readHookInput();\n\n if (stopHookActive(hookInput)) {\n io.err(\n \"note: the guard already stopped this agent once; the findings above are left for the reviewer.\",\n );\n\n return 0;\n }\n\n return 2;\n } catch (error) {\n if (hook && error instanceof GrimoireError) {\n io.err(`note: ${error.code} ${error.message}`);\n\n return 0;\n }\n\n return reportError(io, error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,QAAQ,UACZ,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,IAAI;;;;;AAMpE,SAAgB,cACd,SAA4B,QAAQ,OACpC,YAAY,KACK;CACjB,IAAI,OAAO,OAAO,OAAO,QAAQ,QAAQ,EAAE;CAE3C,OAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,SAAmB,CAAC;EAC1B,MAAM,eAAqB;GACzB,aAAa,KAAK;GAClB,OAAO,IAAI,QAAQ,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AO,SAAS,CAAC;IAAG,SAAS;GAAK,CAAC;GAEvE,KAAK,MAAM,WAAW,QAAQ,QAAQ,SAAS,KAAK,SAAS,QAAQ,GAAG;IACtE,GAAG,IAAI,SAAS,QAAQ,KAAK,IAAI,QAAQ,SAAS;IAClD,GAAG,IAAI,UAAU,QAAQ,MAAM;GACjC;GAEA,OAAO;EACT;EAEA,MAAM,UAAU,aAAa,UAAU,eAAe,KAAK,CAAC;EAC5D,MAAM,SAAsB;GAC1B,eAAe;GACf,MAAM,MAAM,OAAO,MAAM;GACzB;GACA;GACA,UAAU,QAAQ;GAClB,aAAa,SAAS,OAAO,SAAS,CAAC;GACvC,QAAQ,QAAQ;GAChB,IAAI,QAAQ;EACd;EAEA,IAAI,QAAQ,SAAS,MAAM,IAAI,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;OACzD,KAAK,MAAM,QAAQ,kBAAkB,QAAQ,IAAI,GAAG,IAAI,IAAI;EAEjE,IAAI,OAAO,IAAI,OAAO;EAEtB,IAAI,CAAC,MAAM,OAAO;EAOlB,IAAI,eAFF,OAAO,QAAQ,cAAc,WAAW,QAAQ,YAAY,MAAM,cAAc,CAEtD,GAAG;GAC7B,GAAG,IACD,gGACF;GAEA,OAAO;EACT;EAEA,OAAO;CACT,SAAS,OAAO;EACd,IAAI,QAAQ,iBAAiB,eAAe;GAC1C,GAAG,IAAI,SAAS,MAAM,KAAK,IAAI,MAAM,SAAS;GAE9C,OAAO;EACT;EAEA,OAAO,YAAY,IAAI,KAAK;CAC9B;AACF"}
|
package/esm/warlock/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CollectMobileFactsOptions, MobileAppOption, collectMobileFacts } from "./mobile-facts.mjs";
|
|
2
2
|
import { LiveInspectTooling, WarlockAdapterOptions, WarlockInspect, createWarlockAdapter, liveInspect } from "./adapter.mjs";
|
|
3
3
|
import { registerGrimoireCommands } from "./commands.mjs";
|
|
4
|
-
|
|
4
|
+
import { ShowsOptions, ShowsScene, shows } from "./shows.mjs";
|
|
5
|
+
export { type CollectMobileFactsOptions, type LiveInspectTooling, type MobileAppOption, type ShowsOptions, type ShowsScene, type WarlockAdapterOptions, type WarlockInspect, collectMobileFacts, createWarlockAdapter, liveInspect, registerGrimoireCommands, shows };
|
package/esm/warlock/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { collectMobileFacts } from "./mobile-facts.mjs";
|
|
2
2
|
import { createWarlockAdapter, liveInspect } from "./adapter.mjs";
|
|
3
3
|
import { registerGrimoireCommands } from "./commands.mjs";
|
|
4
|
+
import { shows } from "./shows.mjs";
|
|
4
5
|
|
|
5
|
-
export { collectMobileFacts, createWarlockAdapter, liveInspect, registerGrimoireCommands };
|
|
6
|
+
export { collectMobileFacts, createWarlockAdapter, liveInspect, registerGrimoireCommands, shows };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/grimoire/src/warlock/languages.ts
|
|
5
|
+
/**
|
|
6
|
+
* The app's languages and how its URLs carry them, read without booting the
|
|
7
|
+
* app: from the config already loaded in the process when there is one, else
|
|
8
|
+
* from the string literals in `src/config/app.ts` and `src/config/web.ts`.
|
|
9
|
+
*/
|
|
10
|
+
const STRATEGIES = [
|
|
11
|
+
"none",
|
|
12
|
+
"prefix",
|
|
13
|
+
"prefix-except-default"
|
|
14
|
+
];
|
|
15
|
+
async function readConfigFile(root, name) {
|
|
16
|
+
for (const extension of [
|
|
17
|
+
"ts",
|
|
18
|
+
"js",
|
|
19
|
+
"mjs",
|
|
20
|
+
"mts"
|
|
21
|
+
]) try {
|
|
22
|
+
return await readFile(path.join(root, "src", "config", `${name}.${extension}`), "utf8");
|
|
23
|
+
} catch {}
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
/** The config value already loaded in this process, or `undefined`. */
|
|
27
|
+
async function loadedConfig(key) {
|
|
28
|
+
try {
|
|
29
|
+
return (await import("@warlock.js/core")).config.key(key);
|
|
30
|
+
} catch {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function stringArray(value) {
|
|
35
|
+
return Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string") ? value : null;
|
|
36
|
+
}
|
|
37
|
+
/** The string literals of `localeCodes: ["en", "ar"]`. */
|
|
38
|
+
function literalCodes(source) {
|
|
39
|
+
const match = /\blocaleCodes\s*:\s*\[([^\]]*)\]/.exec(source);
|
|
40
|
+
if (!match) return [];
|
|
41
|
+
return [...(match[1] ?? "").matchAll(/["'`]([^"'`]+)["'`]/g)].flatMap((code) => code[1] ? [code[1]] : []);
|
|
42
|
+
}
|
|
43
|
+
/** The app's language codes in order (`["en", "ar"]`), or `[]` when it names none. Never boots the app. */
|
|
44
|
+
async function readAppLanguages(root) {
|
|
45
|
+
const loaded = stringArray(await loadedConfig("app.localeCodes"));
|
|
46
|
+
if (loaded !== null) return loaded;
|
|
47
|
+
return literalCodes(await readConfigFile(root, "app"));
|
|
48
|
+
}
|
|
49
|
+
/** The default language: `localeCode` of the loaded config, else its literal (or the `env()` fallback) in `app.ts`, else the first code. */
|
|
50
|
+
async function defaultLanguage(root, languages) {
|
|
51
|
+
const loaded = await loadedConfig("app.localeCode");
|
|
52
|
+
if (typeof loaded === "string" && loaded !== "") return loaded;
|
|
53
|
+
return /\blocaleCode\s*:\s*(?:env\(\s*["'`][^"'`]*["'`]\s*,\s*)?["'`]([^"'`]+)["'`]/.exec(await readConfigFile(root, "app"))?.[1] ?? languages[0] ?? "";
|
|
54
|
+
}
|
|
55
|
+
/** How a page URL carries the language, and the default language. */
|
|
56
|
+
async function readLocaleRouting(root, languages) {
|
|
57
|
+
const loaded = await loadedConfig("web.localeRouting");
|
|
58
|
+
const loadedStrategy = typeof loaded === "object" && loaded !== null ? loaded.strategy : void 0;
|
|
59
|
+
const written = /\blocaleRouting\s*:\s*\{[^}]*?\bstrategy\s*:\s*["'`]([^"'`]+)["'`]/.exec(await readConfigFile(root, "web"))?.[1];
|
|
60
|
+
const candidate = loadedStrategy ?? written;
|
|
61
|
+
return {
|
|
62
|
+
strategy: STRATEGIES.find((value) => value === candidate) ?? "none",
|
|
63
|
+
defaultLanguage: await defaultLanguage(root, languages)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The URL path of `pagePath` in `language` under the routing strategy. */
|
|
67
|
+
function localizedPath(pagePath, language, routing) {
|
|
68
|
+
const normal = pagePath.startsWith("/") ? pagePath : `/${pagePath}`;
|
|
69
|
+
if (language === "" || routing.strategy === "none" || routing.strategy === "prefix-except-default" && language === routing.defaultLanguage) return normal;
|
|
70
|
+
return `/${language}${normal === "/" ? "" : normal}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { localizedPath, readAppLanguages, readLocaleRouting };
|
|
75
|
+
//# sourceMappingURL=languages.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languages.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/languages.ts"],"sourcesContent":["/**\n * The app's languages and how its URLs carry them, read without booting the\n * app: from the config already loaded in the process when there is one, else\n * from the string literals in `src/config/app.ts` and `src/config/web.ts`.\n */\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\n/** How a page URL carries the language (`web.localeRouting.strategy`). */\nexport type LocaleStrategy = \"none\" | \"prefix\" | \"prefix-except-default\";\n\nconst STRATEGIES: readonly LocaleStrategy[] = [\"none\", \"prefix\", \"prefix-except-default\"];\n\nasync function readConfigFile(root: string, name: string): Promise<string> {\n for (const extension of [\"ts\", \"js\", \"mjs\", \"mts\"]) {\n try {\n return await readFile(path.join(root, \"src\", \"config\", `${name}.${extension}`), \"utf8\");\n } catch {\n // Try the next extension.\n }\n }\n\n return \"\";\n}\n\n/** The config value already loaded in this process, or `undefined`. */\nasync function loadedConfig(key: string): Promise<unknown> {\n try {\n const core = await import(\"@warlock.js/core\");\n\n return core.config.key(key);\n } catch {\n return undefined;\n }\n}\n\nfunction stringArray(value: unknown): string[] | null {\n return Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === \"string\")\n ? (value as string[])\n : null;\n}\n\n/** The string literals of `localeCodes: [\"en\", \"ar\"]`. */\nfunction literalCodes(source: string): string[] {\n const match = /\\blocaleCodes\\s*:\\s*\\[([^\\]]*)\\]/.exec(source);\n\n if (!match) return [];\n\n return [...(match[1] ?? \"\").matchAll(/[\"'`]([^\"'`]+)[\"'`]/g)].flatMap((code) =>\n code[1] ? [code[1]] : [],\n );\n}\n\n/** The app's language codes in order (`[\"en\", \"ar\"]`), or `[]` when it names none. Never boots the app. */\nexport async function readAppLanguages(root: string): Promise<string[]> {\n const loaded = stringArray(await loadedConfig(\"app.localeCodes\"));\n\n if (loaded !== null) return loaded;\n\n return literalCodes(await readConfigFile(root, \"app\"));\n}\n\n/** The default language: `localeCode` of the loaded config, else its literal (or the `env()` fallback) in `app.ts`, else the first code. */\nasync function defaultLanguage(root: string, languages: readonly string[]): Promise<string> {\n const loaded = await loadedConfig(\"app.localeCode\");\n\n if (typeof loaded === \"string\" && loaded !== \"\") return loaded;\n\n const match = /\\blocaleCode\\s*:\\s*(?:env\\(\\s*[\"'`][^\"'`]*[\"'`]\\s*,\\s*)?[\"'`]([^\"'`]+)[\"'`]/.exec(\n await readConfigFile(root, \"app\"),\n );\n\n return match?.[1] ?? languages[0] ?? \"\";\n}\n\n/** How a page URL carries the language, and the default language. */\nexport async function readLocaleRouting(\n root: string,\n languages: readonly string[],\n): Promise<{ strategy: LocaleStrategy; defaultLanguage: string }> {\n const loaded = await loadedConfig(\"web.localeRouting\");\n const loadedStrategy =\n typeof loaded === \"object\" && loaded !== null\n ? (loaded as { strategy?: unknown }).strategy\n : undefined;\n const written = /\\blocaleRouting\\s*:\\s*\\{[^}]*?\\bstrategy\\s*:\\s*[\"'`]([^\"'`]+)[\"'`]/.exec(\n await readConfigFile(root, \"web\"),\n )?.[1];\n const candidate = loadedStrategy ?? written;\n const strategy = STRATEGIES.find((value) => value === candidate) ?? \"none\";\n\n return { strategy, defaultLanguage: await defaultLanguage(root, languages) };\n}\n\n/** The URL path of `pagePath` in `language` under the routing strategy. */\nexport function localizedPath(\n pagePath: string,\n language: string,\n routing: { strategy: LocaleStrategy; defaultLanguage: string },\n): string {\n const normal = pagePath.startsWith(\"/\") ? pagePath : `/${pagePath}`;\n\n if (\n language === \"\" ||\n routing.strategy === \"none\" ||\n (routing.strategy === \"prefix-except-default\" && language === routing.defaultLanguage)\n ) {\n return normal;\n }\n\n return `/${language}${normal === \"/\" ? \"\" : normal}`;\n}\n"],"mappings":";;;;;;;;;AAWA,MAAM,aAAwC;CAAC;CAAQ;CAAU;AAAuB;AAExF,eAAe,eAAe,MAAc,MAA+B;CACzE,KAAK,MAAM,aAAa;EAAC;EAAM;EAAM;EAAO;CAAK,GAC/C,IAAI;EACF,OAAO,MAAM,SAAS,KAAK,KAAK,MAAM,OAAO,UAAU,GAAG,KAAK,GAAG,WAAW,GAAG,MAAM;CACxF,QAAQ,CAER;CAGF,OAAO;AACT;;AAGA,eAAe,aAAa,KAA+B;CACzD,IAAI;EAGF,QAAO,MAFY,OAAO,oBAEf,CAAC,OAAO,IAAI,GAAG;CAC5B,QAAQ;EACN;CACF;AACF;AAEA,SAAS,YAAY,OAAiC;CACpD,OAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,MAAM,OAAO,SAAS,OAAO,SAAS,QAAQ,IAC5F,QACD;AACN;;AAGA,SAAS,aAAa,QAA0B;CAC9C,MAAM,QAAQ,mCAAmC,KAAK,MAAM;CAE5D,IAAI,CAAC,OAAO,OAAO,CAAC;CAEpB,OAAO,CAAC,IAAI,MAAM,MAAM,GAAE,CAAE,SAAS,sBAAsB,CAAC,CAAC,CAAC,SAAS,SACrE,KAAK,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CACzB;AACF;;AAGA,eAAsB,iBAAiB,MAAiC;CACtE,MAAM,SAAS,YAAY,MAAM,aAAa,iBAAiB,CAAC;CAEhE,IAAI,WAAW,MAAM,OAAO;CAE5B,OAAO,aAAa,MAAM,eAAe,MAAM,KAAK,CAAC;AACvD;;AAGA,eAAe,gBAAgB,MAAc,WAA+C;CAC1F,MAAM,SAAS,MAAM,aAAa,gBAAgB;CAElD,IAAI,OAAO,WAAW,YAAY,WAAW,IAAI,OAAO;CAMxD,OAJc,8EAA8E,KAC1F,MAAM,eAAe,MAAM,KAAK,CAGvB,CAAC,GAAG,MAAM,UAAU,MAAM;AACvC;;AAGA,eAAsB,kBACpB,MACA,WACgE;CAChE,MAAM,SAAS,MAAM,aAAa,mBAAmB;CACrD,MAAM,iBACJ,OAAO,WAAW,YAAY,WAAW,OACpC,OAAkC,WACnC;CACN,MAAM,UAAU,qEAAqE,KACnF,MAAM,eAAe,MAAM,KAAK,CAClC,CAAC,GAAG;CACJ,MAAM,YAAY,kBAAkB;CAGpC,OAAO;EAAE,UAFQ,WAAW,MAAM,UAAU,UAAU,SAAS,KAAK;EAEjD,iBAAiB,MAAM,gBAAgB,MAAM,SAAS;CAAE;AAC7E;;AAGA,SAAgB,cACd,UACA,UACA,SACQ;CACR,MAAM,SAAS,SAAS,WAAW,GAAG,IAAI,WAAW,IAAI;CAEzD,IACE,aAAa,MACb,QAAQ,aAAa,UACpB,QAAQ,aAAa,2BAA2B,aAAa,QAAQ,iBAEtE,OAAO;CAGT,OAAO,IAAI,WAAW,WAAW,MAAM,KAAK;AAC9C"}
|
|
@@ -65,7 +65,7 @@ function createGrimoireMcpTools(context, options = {}, adapterFor) {
|
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
name: "grimoire_impact",
|
|
68
|
-
description: "What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. Read-only.",
|
|
68
|
+
description: "What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. grimoire_search already folds a shortened version into its answer for the top hit; call this for the full lists, or for another file. Read the importers and tests: they are the files that usually change with it. Read-only.",
|
|
69
69
|
input: inputSchema({ file: {
|
|
70
70
|
type: "string",
|
|
71
71
|
description: "Project-relative path of the file to change."
|
|
@@ -174,7 +174,7 @@ function createGrimoireMcpTools(context, options = {}, adapterFor) {
|
|
|
174
174
|
},
|
|
175
175
|
{
|
|
176
176
|
name: "grimoire_search",
|
|
177
|
-
description: "Search the Grimoire with a sentence or words (pass the whole commit title or bug report, not two keywords): features, flows, blocks, pages, screens, routes, file paths, export names, header sentences, written text (summary, story, cases, criteria such as AC-5) and tasks. Hits whose name or title holds the words come first; every other hit follows by BM25F score. Hits are in score order and carry their score and app. Read-only.",
|
|
177
|
+
description: "Search the Grimoire with a sentence or words (pass the whole commit title or bug report, not two keywords): features, flows, blocks, pages, screens, routes, file paths, export names, header sentences, written text (summary, story, cases, criteria such as AC-5) and tasks. Hits whose name or title holds the words come first; every other hit follows by BM25F score. Hits are in score order and carry their score and app. Search first: the answer already holds what changes with the top hit, so you do not need grimoire_impact for it. Its alsoChanges list names the files that usually change with the top hits, `impact` lists the importers, routes, flows and tests that reach the top file, `next` is the full impact command (present when `impact` is not), and `weak: true` means no hit holds most of the request's words (use grep for literal text). Read-only.",
|
|
178
178
|
input: inputSchema({
|
|
179
179
|
text: {
|
|
180
180
|
type: "string",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tools.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/mcp-tools.ts"],"sourcesContent":["/**\n * The Grimoire tools `warlock mcp` and `warlock dev --mcp` serve. Each tool\n * loads its code inside `run`, so registering them costs nothing at start.\n * Answers are the same JSON objects `--json` prints.\n */\nimport { inputSchema, type WarlockMcpContext, type WarlockMcpTool } from \"@warlock.js/core\";\nimport { explainGrimoireCode, GrimoireError, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { ScryQuery } from \"../contracts/scry\";\nimport { scryErrorOf } from \"../scry/error\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\n\n/** The names of the tools, in the order they are listed. */\nexport const GRIMOIRE_MCP_TOOL_NAMES = [\n \"grimoire_file\",\n \"grimoire_impact\",\n \"grimoire_route\",\n \"grimoire_feature\",\n \"grimoire_flow\",\n \"grimoire_search\",\n \"grimoire_check\",\n \"grimoire_build\",\n \"grimoire_release\",\n \"grimoire_explain\",\n] as const;\n\n/** A Grimoire error of a non-scry tool (check, build, release) as a tool error: the code, what failed, and what to do. */\nfunction toolError(error: unknown): never {\n if (error instanceof GrimoireError) {\n const fix = explainGrimoireCode(error.code)?.fix;\n\n throw new Error(`${error.code}: ${error.message}${fix ? ` Fix: ${fix}` : \"\"}`);\n }\n\n throw error;\n}\n\n/**\n * A scry error as a tool error whose text is the `ScryError` JSON that\n * `warlock scry --json` prints (`{ \"type\": \"error\", \"code\", \"message\", \"fix\" }`).\n * It stays a thrown error so the MCP result is still marked `isError`.\n */\nfunction scryToolError(error: unknown): never {\n if (error instanceof GrimoireError) throw new Error(JSON.stringify(scryErrorOf(error)));\n\n throw error;\n}\n\nfunction text(input: Record<string, unknown>, name: string): string {\n const value = input[name];\n\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** The tools for one MCP server. `adapterFor` is replaced in specs. */\nexport function createGrimoireMcpTools(\n context: Pick<WarlockMcpContext, \"cwd\" | \"inspect\">,\n options: WarlockAdapterOptions = {},\n adapterFor?: () => Promise<BookAdapter>,\n): WarlockMcpTool[] {\n const root = context.cwd;\n let adapter: Promise<BookAdapter> | undefined;\n\n // The server's own inspect: `warlock mcp` boots once for every tool, `warlock dev --mcp` reads the live app.\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??=\n adapterFor?.() ??\n import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter({\n ...options,\n inspect: (_root, sections) => context.inspect(sections),\n }),\n );\n\n return adapter;\n };\n\n const ask =\n (query: (input: Record<string, unknown>) => Promise<ScryQuery> | ScryQuery) =>\n async (input: Record<string, unknown>): Promise<unknown> => {\n try {\n const { answer } = await import(\"./actions\");\n\n return await answer(root, await loadAdapter(), await query(input));\n } catch (error) {\n return scryToolError(error);\n }\n };\n\n const scryParts = () => import(\"../scry\");\n\n return [\n {\n name: \"grimoire_file\",\n description:\n \"One source file from the Grimoire book: header sentence, owning feature and borrowers, flows that reach it, exports, imports, importers, routes, pages. Read-only; reads cached route facts and never boots the app.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path (either separator).\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"file\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_impact\",\n description:\n \"What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. Read-only.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path of the file to change.\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"impact\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_route\",\n description:\n \"One HTTP route: handler and its file, routes file, middleware, guard, the files behind it and the flow steps that name it. For GET and HEAD a page or screen URL also works: it returns every site serving the page with its file, setup file, layouts and their imports. Read-only.\",\n input: inputSchema(\n {\n method: { type: \"string\", description: \"HTTP method (GET, POST…).\" },\n path: {\n type: \"string\",\n description: \"Path as registered (/api/products/:id), or a page URL for GET and HEAD.\",\n },\n site: {\n type: \"string\",\n description: \"Only the page of this site or mobile app, when several serve the path.\",\n },\n },\n [\"method\", \"path\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseRouteText } = await scryParts();\n\n const site = text(input, \"site\").trim();\n\n return {\n type: \"route\",\n ...parseRouteText(`${text(input, \"method\")} ${text(input, \"path\")}`),\n ...(site === \"\" ? {} : { site }),\n };\n }),\n },\n {\n name: \"grimoire_feature\",\n description:\n \"One feature: README, flows with status, its book map (own, borrowed and unreached files, routes, pages), recent changes, open tasks and its check findings. Read-only.\",\n input: inputSchema(\n {\n feature: { type: \"string\", description: \"Feature id (folder under grimoire/features/).\" },\n },\n [\"feature\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseFeatureText } = await scryParts();\n\n return { type: \"feature\", feature: parseFeatureText(text(input, \"feature\")) };\n }),\n },\n {\n name: \"grimoire_flow\",\n description:\n \"One flow: its summary, steps with file counts (direct, in the feature, reachable, type-only) and the first direct imports of each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Pass files with step to list one step's reachable or type-only files, a page at a time. Read-only.\",\n input: inputSchema(\n {\n flow: { type: \"string\", description: \"<feature>/<flow>, like catalog/new-arrivals.\" },\n files: {\n type: \"string\",\n enum: [\"reachable\", \"type-only\"],\n description:\n \"With step: list the step's files that run (reachable) or only type imports reach (type-only).\",\n },\n step: { type: \"integer\", description: \"Step number, for files.\", minimum: 0 },\n offset: {\n type: \"integer\",\n description: \"First file to list (default 0); a page holds 200.\",\n minimum: 0,\n },\n },\n [\"flow\"],\n ),\n writes: false,\n run: async (input) => {\n try {\n const [{ parseFlowText, scry }, { openStoredGrimoireCached }, compact] =\n await Promise.all([\n scryParts(),\n import(\"../workspace/cache\"),\n import(\"../scry/compact\"),\n ]);\n const query = { type: \"flow\" as const, ...parseFlowText(text(input, \"flow\")) };\n const snapshot = await openStoredGrimoireCached(root, await loadAdapter());\n const result = scry(snapshot, query);\n\n if (result.type !== \"flow\") return result;\n\n const set = input.files;\n\n if (set === undefined || set === null) return compact.compactFlow(snapshot, result);\n\n if (set !== \"reachable\" && set !== \"type-only\") {\n throw new GrimoireError(\"GR9006\", 'Pass files as \"reachable\" or \"type-only\".');\n }\n\n const stepNumber = input.step;\n const step = result.bookmap.steps.find((item) => item.index === stepNumber);\n\n if (typeof stepNumber !== \"number\" || step === undefined) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass step as one of the step numbers of ${result.bookmap.ref} (${result.bookmap.steps.map((item) => item.index).join(\", \")}).`,\n );\n }\n\n const offset = typeof input.offset === \"number\" && input.offset > 0 ? input.offset : 0;\n\n return compact.stepFilePage(snapshot, result.bookmap, step, set, offset, 200);\n } catch (error) {\n return scryToolError(error);\n }\n },\n },\n {\n name: \"grimoire_search\",\n description:\n \"Search the Grimoire with a sentence or words (pass the whole commit title or bug report, not two keywords): features, flows, blocks, pages, screens, routes, file paths, export names, header sentences, written text (summary, story, cases, criteria such as AC-5) and tasks. Hits whose name or title holds the words come first; every other hit follows by BM25F score. Hits are in score order and carry their score and app. Read-only.\",\n input: inputSchema(\n {\n text: {\n type: \"string\",\n description: \"A sentence or words to look for; whole words, in any order.\",\n },\n limit: { type: \"integer\", description: \"Most hits to return (default 20).\", minimum: 1 },\n app: {\n type: \"string\",\n description: \"Keep only the hits of this app (a page, screen, block or file of it).\",\n },\n },\n [\"text\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { limit, app } = input;\n const { parseLimit, parseApp } = await scryParts();\n\n // A limit of 0, a negative or a fraction is refused with GR9006, as `--limit` is.\n return {\n type: \"search\",\n text: text(input, \"text\"),\n ...(limit === undefined || limit === null\n ? {}\n : {\n limit: parseLimit(\n typeof limit === \"number\" || typeof limit === \"string\" ? limit : true,\n ),\n }),\n ...(app === undefined || app === null\n ? {}\n : { app: parseApp(typeof app === \"string\" ? app : true) }),\n };\n }),\n },\n {\n name: \"grimoire_check\",\n description:\n \"Run the Grimoire check: written names that point at nothing, files without a header or feature, criteria without tests, version and changelog problems. Findings on proposed work are marked expected. Read-only; checks the stored book (run warlock grimoire build after editing); `note` says when the book is behind the files.\",\n input: inputSchema({}),\n writes: false,\n run: async () => {\n try {\n const [{ openStoredGrimoireCached }, { checkGrimoire }] = await Promise.all([\n import(\"../workspace/cache\"),\n import(\"../check\"),\n ]);\n\n const snapshot = await openStoredGrimoireCached(root, await loadAdapter());\n const report = checkGrimoire(snapshot);\n const changed = snapshot.behind?.changed;\n\n // The stored book may be behind the files: say so, as scry answers do.\n return changed === undefined\n ? report\n : {\n ...report,\n note: `book is stale (${changed} ${changed === 1 ? \"file\" : \"files\"} changed); run warlock grimoire build`,\n };\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_build\",\n description:\n \"Bring the generated book (grimoire/book, a git-ignored cache) up to date, reading the routes again when they changed. Writes no project file.\",\n input: inputSchema({ force: { type: \"boolean\", description: \"Rebuild every entry.\" } }),\n writes: false,\n run: async (input) => {\n try {\n const { runGrimoire } = await import(\"../workspace\");\n const loaded = await loadAdapter();\n const force = input.force === true;\n let run;\n let note: string | null = null;\n\n try {\n run = await runGrimoire(root, loaded, { routes: \"fresh\", force });\n } catch (error) {\n if (!(error instanceof GrimoireError) || error.code !== \"GR8002\") throw error;\n\n note = `${error.code}: ${error.message}`;\n run = await runGrimoire(root, loaded, { routes: \"cached\", force });\n }\n\n const routeNote = run.snapshot.book.routeNote;\n const notes = [note, routeNote ?? null].filter((item): item is string => item !== null);\n\n return {\n rebuilt: run.rebuilt,\n written: [...run.book.written, ...run.collected.written],\n removed: [...run.book.removed, ...run.collected.removed],\n routes: run.snapshot.routes,\n ...(notes.length === 0 ? {} : { note: notes.join(\"; \") }),\n };\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_release\",\n description:\n \"Write the collected list of a release into grimoire/releases/<release>.md (between its markers; the agent writes the brief and stamps the changelog entries first). Writes a project file.\",\n input: inputSchema(\n { release: { type: \"string\", description: \"Release name, like 1.1.0.\" } },\n [\"release\"],\n ),\n writes: true,\n run: async (input) => {\n try {\n const [{ parseGrimoire }, { writeRelease }] = await Promise.all([\n import(\"../written\"),\n import(\"../releases\"),\n ]);\n const release = text(input, \"release\").trim();\n\n if (release === \"\" || /[\\\\/]/.test(release)) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass a release name like 1.1.0 (got ${JSON.stringify(release)}).`,\n );\n }\n\n return await writeRelease(root, (await parseGrimoire(root)).written, release);\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_explain\",\n description:\n \"What a Grimoire code (GR1001…GR9006) means, what to do, the skill that explains it and its docs link. Read-only.\",\n input: inputSchema({ code: { type: \"string\", description: \"The code, like GR2001.\" } }, [\n \"code\",\n ]),\n writes: false,\n run: async (input) => {\n const definition = explainGrimoireCode(text(input, \"code\"));\n\n if (!definition) {\n throw new Error(\n `Unknown Grimoire code ${JSON.stringify(text(input, \"code\"))}. Codes look like GR2001; the full list is at the check guide.`,\n );\n }\n\n return { ...definition, docs: grimoireCodeDocsUrl(definition.code) };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAS,UAAU,OAAuB;CACxC,IAAI,iBAAiB,eAAe;EAClC,MAAM,MAAM,oBAAoB,MAAM,IAAI,CAAC,EAAE;EAE7C,MAAM,IAAI,MAAM,GAAG,MAAM,KAAK,IAAI,MAAM,UAAU,MAAM,SAAS,QAAQ,IAAI;CAC/E;CAEA,MAAM;AACR;;;;;;AAOA,SAAS,cAAc,OAAuB;CAC5C,IAAI,iBAAiB,eAAe,MAAM,IAAI,MAAM,KAAK,UAAU,YAAY,KAAK,CAAC,CAAC;CAEtF,MAAM;AACR;AAEA,SAAS,KAAK,OAAgC,MAAsB;CAClE,MAAM,QAAQ,MAAM;CAEpB,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;;AAGA,SAAgB,uBACd,SACA,UAAiC,CAAC,GAClC,YACkB;CAClB,MAAM,OAAO,QAAQ;CACrB,IAAI;CAGJ,MAAM,oBAA0C;EAC9C,YACE,aAAa,KACb,OAAO,gBAAY,CAAC,MAAM,EAAE,2BAC1B,qBAAqB;GACnB,GAAG;GACH,UAAU,OAAO,aAAa,QAAQ,QAAQ,QAAQ;EACxD,CAAC,CACH;EAEF,OAAO;CACT;CAEA,MAAM,OACH,UACD,OAAO,UAAqD;EAC1D,IAAI;GACF,MAAM,EAAE,WAAW,MAAM,OAAO;GAEhC,OAAO,MAAM,OAAO,MAAM,MAAM,YAAY,GAAG,MAAM,MAAM,KAAK,CAAC;EACnE,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,wBACT,CAAC;KACD,MAAM,UAAU,KAAK,OAAO,SAAS,CAAC,CAAC,KAAK;KAE5C,IAAI,YAAY,MAAM,QAAQ,KAAK,OAAO,GACxC,MAAM,IAAI,cACR,UACA,uCAAuC,KAAK,UAAU,OAAO,EAAE,GACjE;KAGF,OAAO,MAAM,aAAa,OAAO,MAAM,cAAc,IAAI,EAAC,CAAE,SAAS,OAAO;IAC9E,SAAS,OAAO;KACd,OAAO,UAAU,KAAK;IACxB;GACF;EACF;EACA;GACE,MAAM;GACN,aACE;GACF,OAAO,YAAY,EAAE,MAAM;IAAE,MAAM;IAAU,aAAa;GAAyB,EAAE,GAAG,CACtF,MACF,CAAC;GACD,QAAQ;GACR,KAAK,OAAO,UAAU;IACpB,MAAM,aAAa,oBAAoB,KAAK,OAAO,MAAM,CAAC;IAE1D,IAAI,CAAC,YACH,MAAM,IAAI,MACR,yBAAyB,KAAK,UAAU,KAAK,OAAO,MAAM,CAAC,EAAE,+DAC/D;IAGF,OAAO;KAAE,GAAG;KAAY,MAAM,oBAAoB,WAAW,IAAI;IAAE;GACrE;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"mcp-tools.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/mcp-tools.ts"],"sourcesContent":["/**\n * The Grimoire tools `warlock mcp` and `warlock dev --mcp` serve. Each tool\n * loads its code inside `run`, so registering them costs nothing at start.\n * Answers are the same JSON objects `--json` prints.\n */\nimport { inputSchema, type WarlockMcpContext, type WarlockMcpTool } from \"@warlock.js/core\";\nimport { explainGrimoireCode, GrimoireError, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { ScryQuery } from \"../contracts/scry\";\nimport { scryErrorOf } from \"../scry/error\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\n\n/** The names of the tools, in the order they are listed. */\nexport const GRIMOIRE_MCP_TOOL_NAMES = [\n \"grimoire_file\",\n \"grimoire_impact\",\n \"grimoire_route\",\n \"grimoire_feature\",\n \"grimoire_flow\",\n \"grimoire_search\",\n \"grimoire_check\",\n \"grimoire_build\",\n \"grimoire_release\",\n \"grimoire_explain\",\n] as const;\n\n/** A Grimoire error of a non-scry tool (check, build, release) as a tool error: the code, what failed, and what to do. */\nfunction toolError(error: unknown): never {\n if (error instanceof GrimoireError) {\n const fix = explainGrimoireCode(error.code)?.fix;\n\n throw new Error(`${error.code}: ${error.message}${fix ? ` Fix: ${fix}` : \"\"}`);\n }\n\n throw error;\n}\n\n/**\n * A scry error as a tool error whose text is the `ScryError` JSON that\n * `warlock scry --json` prints (`{ \"type\": \"error\", \"code\", \"message\", \"fix\" }`).\n * It stays a thrown error so the MCP result is still marked `isError`.\n */\nfunction scryToolError(error: unknown): never {\n if (error instanceof GrimoireError) throw new Error(JSON.stringify(scryErrorOf(error)));\n\n throw error;\n}\n\nfunction text(input: Record<string, unknown>, name: string): string {\n const value = input[name];\n\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** The tools for one MCP server. `adapterFor` is replaced in specs. */\nexport function createGrimoireMcpTools(\n context: Pick<WarlockMcpContext, \"cwd\" | \"inspect\">,\n options: WarlockAdapterOptions = {},\n adapterFor?: () => Promise<BookAdapter>,\n): WarlockMcpTool[] {\n const root = context.cwd;\n let adapter: Promise<BookAdapter> | undefined;\n\n // The server's own inspect: `warlock mcp` boots once for every tool, `warlock dev --mcp` reads the live app.\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??=\n adapterFor?.() ??\n import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter({\n ...options,\n inspect: (_root, sections) => context.inspect(sections),\n }),\n );\n\n return adapter;\n };\n\n const ask =\n (query: (input: Record<string, unknown>) => Promise<ScryQuery> | ScryQuery) =>\n async (input: Record<string, unknown>): Promise<unknown> => {\n try {\n const { answer } = await import(\"./actions\");\n\n return await answer(root, await loadAdapter(), await query(input));\n } catch (error) {\n return scryToolError(error);\n }\n };\n\n const scryParts = () => import(\"../scry\");\n\n return [\n {\n name: \"grimoire_file\",\n description:\n \"One source file from the Grimoire book: header sentence, owning feature and borrowers, flows that reach it, exports, imports, importers, routes, pages. Read-only; reads cached route facts and never boots the app.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path (either separator).\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"file\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_impact\",\n description:\n \"What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. grimoire_search already folds a shortened version into its answer for the top hit; call this for the full lists, or for another file. Read the importers and tests: they are the files that usually change with it. Read-only.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path of the file to change.\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"impact\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_route\",\n description:\n \"One HTTP route: handler and its file, routes file, middleware, guard, the files behind it and the flow steps that name it. For GET and HEAD a page or screen URL also works: it returns every site serving the page with its file, setup file, layouts and their imports. Read-only.\",\n input: inputSchema(\n {\n method: { type: \"string\", description: \"HTTP method (GET, POST…).\" },\n path: {\n type: \"string\",\n description: \"Path as registered (/api/products/:id), or a page URL for GET and HEAD.\",\n },\n site: {\n type: \"string\",\n description: \"Only the page of this site or mobile app, when several serve the path.\",\n },\n },\n [\"method\", \"path\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseRouteText } = await scryParts();\n\n const site = text(input, \"site\").trim();\n\n return {\n type: \"route\",\n ...parseRouteText(`${text(input, \"method\")} ${text(input, \"path\")}`),\n ...(site === \"\" ? {} : { site }),\n };\n }),\n },\n {\n name: \"grimoire_feature\",\n description:\n \"One feature: README, flows with status, its book map (own, borrowed and unreached files, routes, pages), recent changes, open tasks and its check findings. Read-only.\",\n input: inputSchema(\n {\n feature: { type: \"string\", description: \"Feature id (folder under grimoire/features/).\" },\n },\n [\"feature\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseFeatureText } = await scryParts();\n\n return { type: \"feature\", feature: parseFeatureText(text(input, \"feature\")) };\n }),\n },\n {\n name: \"grimoire_flow\",\n description:\n \"One flow: its summary, steps with file counts (direct, in the feature, reachable, type-only) and the first direct imports of each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Pass files with step to list one step's reachable or type-only files, a page at a time. Read-only.\",\n input: inputSchema(\n {\n flow: { type: \"string\", description: \"<feature>/<flow>, like catalog/new-arrivals.\" },\n files: {\n type: \"string\",\n enum: [\"reachable\", \"type-only\"],\n description:\n \"With step: list the step's files that run (reachable) or only type imports reach (type-only).\",\n },\n step: { type: \"integer\", description: \"Step number, for files.\", minimum: 0 },\n offset: {\n type: \"integer\",\n description: \"First file to list (default 0); a page holds 200.\",\n minimum: 0,\n },\n },\n [\"flow\"],\n ),\n writes: false,\n run: async (input) => {\n try {\n const [{ parseFlowText, scry }, { openStoredGrimoireCached }, compact] =\n await Promise.all([\n scryParts(),\n import(\"../workspace/cache\"),\n import(\"../scry/compact\"),\n ]);\n const query = { type: \"flow\" as const, ...parseFlowText(text(input, \"flow\")) };\n const snapshot = await openStoredGrimoireCached(root, await loadAdapter());\n const result = scry(snapshot, query);\n\n if (result.type !== \"flow\") return result;\n\n const set = input.files;\n\n if (set === undefined || set === null) return compact.compactFlow(snapshot, result);\n\n if (set !== \"reachable\" && set !== \"type-only\") {\n throw new GrimoireError(\"GR9006\", 'Pass files as \"reachable\" or \"type-only\".');\n }\n\n const stepNumber = input.step;\n const step = result.bookmap.steps.find((item) => item.index === stepNumber);\n\n if (typeof stepNumber !== \"number\" || step === undefined) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass step as one of the step numbers of ${result.bookmap.ref} (${result.bookmap.steps.map((item) => item.index).join(\", \")}).`,\n );\n }\n\n const offset = typeof input.offset === \"number\" && input.offset > 0 ? input.offset : 0;\n\n return compact.stepFilePage(snapshot, result.bookmap, step, set, offset, 200);\n } catch (error) {\n return scryToolError(error);\n }\n },\n },\n {\n name: \"grimoire_search\",\n description:\n \"Search the Grimoire with a sentence or words (pass the whole commit title or bug report, not two keywords): features, flows, blocks, pages, screens, routes, file paths, export names, header sentences, written text (summary, story, cases, criteria such as AC-5) and tasks. Hits whose name or title holds the words come first; every other hit follows by BM25F score. Hits are in score order and carry their score and app. Search first: the answer already holds what changes with the top hit, so you do not need grimoire_impact for it. Its alsoChanges list names the files that usually change with the top hits, `impact` lists the importers, routes, flows and tests that reach the top file, `next` is the full impact command (present when `impact` is not), and `weak: true` means no hit holds most of the request's words (use grep for literal text). Read-only.\",\n input: inputSchema(\n {\n text: {\n type: \"string\",\n description: \"A sentence or words to look for; whole words, in any order.\",\n },\n limit: { type: \"integer\", description: \"Most hits to return (default 20).\", minimum: 1 },\n app: {\n type: \"string\",\n description: \"Keep only the hits of this app (a page, screen, block or file of it).\",\n },\n },\n [\"text\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { limit, app } = input;\n const { parseLimit, parseApp } = await scryParts();\n\n // A limit of 0, a negative or a fraction is refused with GR9006, as `--limit` is.\n return {\n type: \"search\",\n text: text(input, \"text\"),\n ...(limit === undefined || limit === null\n ? {}\n : {\n limit: parseLimit(\n typeof limit === \"number\" || typeof limit === \"string\" ? limit : true,\n ),\n }),\n ...(app === undefined || app === null\n ? {}\n : { app: parseApp(typeof app === \"string\" ? app : true) }),\n };\n }),\n },\n {\n name: \"grimoire_check\",\n description:\n \"Run the Grimoire check: written names that point at nothing, files without a header or feature, criteria without tests, version and changelog problems. Findings on proposed work are marked expected. Read-only; checks the stored book (run warlock grimoire build after editing); `note` says when the book is behind the files.\",\n input: inputSchema({}),\n writes: false,\n run: async () => {\n try {\n const [{ openStoredGrimoireCached }, { checkGrimoire }] = await Promise.all([\n import(\"../workspace/cache\"),\n import(\"../check\"),\n ]);\n\n const snapshot = await openStoredGrimoireCached(root, await loadAdapter());\n const report = checkGrimoire(snapshot);\n const changed = snapshot.behind?.changed;\n\n // The stored book may be behind the files: say so, as scry answers do.\n return changed === undefined\n ? report\n : {\n ...report,\n note: `book is stale (${changed} ${changed === 1 ? \"file\" : \"files\"} changed); run warlock grimoire build`,\n };\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_build\",\n description:\n \"Bring the generated book (grimoire/book, a git-ignored cache) up to date, reading the routes again when they changed. Writes no project file.\",\n input: inputSchema({ force: { type: \"boolean\", description: \"Rebuild every entry.\" } }),\n writes: false,\n run: async (input) => {\n try {\n const { runGrimoire } = await import(\"../workspace\");\n const loaded = await loadAdapter();\n const force = input.force === true;\n let run;\n let note: string | null = null;\n\n try {\n run = await runGrimoire(root, loaded, { routes: \"fresh\", force });\n } catch (error) {\n if (!(error instanceof GrimoireError) || error.code !== \"GR8002\") throw error;\n\n note = `${error.code}: ${error.message}`;\n run = await runGrimoire(root, loaded, { routes: \"cached\", force });\n }\n\n const routeNote = run.snapshot.book.routeNote;\n const notes = [note, routeNote ?? null].filter((item): item is string => item !== null);\n\n return {\n rebuilt: run.rebuilt,\n written: [...run.book.written, ...run.collected.written],\n removed: [...run.book.removed, ...run.collected.removed],\n routes: run.snapshot.routes,\n ...(notes.length === 0 ? {} : { note: notes.join(\"; \") }),\n };\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_release\",\n description:\n \"Write the collected list of a release into grimoire/releases/<release>.md (between its markers; the agent writes the brief and stamps the changelog entries first). Writes a project file.\",\n input: inputSchema(\n { release: { type: \"string\", description: \"Release name, like 1.1.0.\" } },\n [\"release\"],\n ),\n writes: true,\n run: async (input) => {\n try {\n const [{ parseGrimoire }, { writeRelease }] = await Promise.all([\n import(\"../written\"),\n import(\"../releases\"),\n ]);\n const release = text(input, \"release\").trim();\n\n if (release === \"\" || /[\\\\/]/.test(release)) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass a release name like 1.1.0 (got ${JSON.stringify(release)}).`,\n );\n }\n\n return await writeRelease(root, (await parseGrimoire(root)).written, release);\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_explain\",\n description:\n \"What a Grimoire code (GR1001…GR9006) means, what to do, the skill that explains it and its docs link. Read-only.\",\n input: inputSchema({ code: { type: \"string\", description: \"The code, like GR2001.\" } }, [\n \"code\",\n ]),\n writes: false,\n run: async (input) => {\n const definition = explainGrimoireCode(text(input, \"code\"));\n\n if (!definition) {\n throw new Error(\n `Unknown Grimoire code ${JSON.stringify(text(input, \"code\"))}. Codes look like GR2001; the full list is at the check guide.`,\n );\n }\n\n return { ...definition, docs: grimoireCodeDocsUrl(definition.code) };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAS,UAAU,OAAuB;CACxC,IAAI,iBAAiB,eAAe;EAClC,MAAM,MAAM,oBAAoB,MAAM,IAAI,CAAC,EAAE;EAE7C,MAAM,IAAI,MAAM,GAAG,MAAM,KAAK,IAAI,MAAM,UAAU,MAAM,SAAS,QAAQ,IAAI;CAC/E;CAEA,MAAM;AACR;;;;;;AAOA,SAAS,cAAc,OAAuB;CAC5C,IAAI,iBAAiB,eAAe,MAAM,IAAI,MAAM,KAAK,UAAU,YAAY,KAAK,CAAC,CAAC;CAEtF,MAAM;AACR;AAEA,SAAS,KAAK,OAAgC,MAAsB;CAClE,MAAM,QAAQ,MAAM;CAEpB,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;;AAGA,SAAgB,uBACd,SACA,UAAiC,CAAC,GAClC,YACkB;CAClB,MAAM,OAAO,QAAQ;CACrB,IAAI;CAGJ,MAAM,oBAA0C;EAC9C,YACE,aAAa,KACb,OAAO,gBAAY,CAAC,MAAM,EAAE,2BAC1B,qBAAqB;GACnB,GAAG;GACH,UAAU,OAAO,aAAa,QAAQ,QAAQ,QAAQ;EACxD,CAAC,CACH;EAEF,OAAO;CACT;CAEA,MAAM,OACH,UACD,OAAO,UAAqD;EAC1D,IAAI;GACF,MAAM,EAAE,WAAW,MAAM,OAAO;GAEhC,OAAO,MAAM,OAAO,MAAM,MAAM,YAAY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