@warlock.js/grimoire 5.63.0 → 5.64.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 +44 -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 +21 -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.map +1 -1
- package/esm/devtools/index.mjs +32 -2
- 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 +5 -1
- 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 +106 -0
- package/esm/scry/also-changes.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +22 -0
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +7 -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 +15 -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/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 +276 -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 +21 -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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { GrimoireError } from "../codes/index.mjs";
|
|
2
|
+
import { openGrimoire } from "../workspace/index.mjs";
|
|
3
|
+
import { approveItems, rejectItems, selectDrift } from "../shots/approve.mjs";
|
|
4
|
+
import { reportError } from "./actions.mjs";
|
|
5
|
+
|
|
6
|
+
//#region ../../packages/grimoire/src/warlock/approve-command.ts
|
|
7
|
+
/**
|
|
8
|
+
* `warlock grimoire approve <target>` and `reject <target>`: accept or refuse
|
|
9
|
+
* a change since the approved baseline (`grimoire/approved/baseline.json`).
|
|
10
|
+
*/
|
|
11
|
+
function openFor(context) {
|
|
12
|
+
return openGrimoire(context.root, context.adapter, {
|
|
13
|
+
routes: "cached",
|
|
14
|
+
write: false
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function targetsOf(target, options) {
|
|
18
|
+
if (options.all === true) return ["all"];
|
|
19
|
+
if (typeof target !== "string" || target.trim() === "") throw new GrimoireError("GR9010", "Name what to approve: a change id from the check, a <feature>/<flow>, or --all.");
|
|
20
|
+
return [target.trim()];
|
|
21
|
+
}
|
|
22
|
+
function print(context, done, options, verb) {
|
|
23
|
+
if (options.json === true) {
|
|
24
|
+
context.io.out(JSON.stringify({ done }, null, 2));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (verb === "approved" && done.length === 1 && done[0] === "baseline") {
|
|
28
|
+
context.io.out("created the approved baseline from the current state (grimoire/approved/baseline.json)");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const id of done) context.io.out(id);
|
|
32
|
+
context.io.out(`${verb} ${done.length}`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Approve the drift items `target` names: a drift id, a `<feature>/<flow>`
|
|
36
|
+
* (every item of the flow), or every item with `--all`; `--lang` keeps one
|
|
37
|
+
* language's images. `--all` with no baseline creates it from the current
|
|
38
|
+
* state. Exit code 0 when it ran.
|
|
39
|
+
*/
|
|
40
|
+
async function runApprove(context, target, options = {}) {
|
|
41
|
+
try {
|
|
42
|
+
const targets = targetsOf(target, options);
|
|
43
|
+
const snapshot = await openFor(context);
|
|
44
|
+
const language = typeof options.lang === "string" ? options.lang : void 0;
|
|
45
|
+
if (snapshot.shots?.baseline == null) {
|
|
46
|
+
if (options.all !== true) throw new GrimoireError("GR9010", "Nothing is approved yet, so there is no change to name. Approve the current state with --all.");
|
|
47
|
+
print(context, await approveItems(snapshot, [], void 0, { createWhenMissing: true }), options, "approved");
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
const items = selectDrift(snapshot, {
|
|
51
|
+
targets,
|
|
52
|
+
...language === void 0 ? {} : { language }
|
|
53
|
+
});
|
|
54
|
+
print(context, await approveItems(snapshot, items), options, "approved");
|
|
55
|
+
return 0;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return reportError(context.io, error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Reject the drift items `target` names (same targets as approve; `--note` records why). */
|
|
61
|
+
async function runReject(context, target, options = {}) {
|
|
62
|
+
try {
|
|
63
|
+
const targets = targetsOf(target, options);
|
|
64
|
+
const snapshot = await openFor(context);
|
|
65
|
+
const language = typeof options.lang === "string" ? options.lang : void 0;
|
|
66
|
+
const note = typeof options.note === "string" && options.note.trim() !== "" ? options.note.trim() : null;
|
|
67
|
+
const items = selectDrift(snapshot, {
|
|
68
|
+
targets,
|
|
69
|
+
...language === void 0 ? {} : { language }
|
|
70
|
+
});
|
|
71
|
+
print(context, await rejectItems(snapshot, items, note), options, "rejected");
|
|
72
|
+
return 0;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return reportError(context.io, error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { runApprove, runReject };
|
|
80
|
+
//# sourceMappingURL=approve-command.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approve-command.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/approve-command.ts"],"sourcesContent":["/**\n * `warlock grimoire approve <target>` and `reject <target>`: accept or refuse\n * a change since the approved baseline (`grimoire/approved/baseline.json`).\n */\nimport { GrimoireError } from \"../codes\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { approveItems, rejectItems, selectDrift } from \"../shots/approve\";\nimport { openGrimoire } from \"../workspace\";\nimport { reportError, type CommandContext } from \"./actions\";\n\nfunction openFor(context: CommandContext): Promise<GrimoireSnapshot> {\n return openGrimoire(context.root, context.adapter, { routes: \"cached\", write: false });\n}\n\nfunction targetsOf(target: string | undefined, options: Record<string, unknown>): string[] {\n if (options.all === true) return [\"all\"];\n\n if (typeof target !== \"string\" || target.trim() === \"\") {\n throw new GrimoireError(\n \"GR9010\",\n \"Name what to approve: a change id from the check, a <feature>/<flow>, or --all.\",\n );\n }\n\n return [target.trim()];\n}\n\nfunction print(\n context: CommandContext,\n done: readonly string[],\n options: Record<string, unknown>,\n verb: \"approved\" | \"rejected\",\n): void {\n if (options.json === true) {\n context.io.out(JSON.stringify({ done }, null, 2));\n\n return;\n }\n\n // The first approval writes the whole current state as the baseline.\n if (verb === \"approved\" && done.length === 1 && done[0] === \"baseline\") {\n context.io.out(\n \"created the approved baseline from the current state (grimoire/approved/baseline.json)\",\n );\n\n return;\n }\n\n for (const id of done) context.io.out(id);\n\n context.io.out(`${verb} ${done.length}`);\n}\n\n/**\n * Approve the drift items `target` names: a drift id, a `<feature>/<flow>`\n * (every item of the flow), or every item with `--all`; `--lang` keeps one\n * language's images. `--all` with no baseline creates it from the current\n * state. Exit code 0 when it ran.\n */\nexport async function runApprove(\n context: CommandContext,\n target: string | undefined,\n options: Record<string, unknown> = {},\n): Promise<number> {\n try {\n const targets = targetsOf(target, options);\n const snapshot = await openFor(context);\n const language = typeof options.lang === \"string\" ? options.lang : undefined;\n\n if (snapshot.shots?.baseline == null) {\n if (options.all !== true) {\n throw new GrimoireError(\n \"GR9010\",\n \"Nothing is approved yet, so there is no change to name. Approve the current state with --all.\",\n );\n }\n\n print(\n context,\n await approveItems(snapshot, [], undefined, { createWhenMissing: true }),\n options,\n \"approved\",\n );\n\n return 0;\n }\n\n const items = selectDrift(snapshot, {\n targets,\n ...(language === undefined ? {} : { language }),\n });\n\n print(context, await approveItems(snapshot, items), options, \"approved\");\n\n return 0;\n } catch (error) {\n return reportError(context.io, error);\n }\n}\n\n/** Reject the drift items `target` names (same targets as approve; `--note` records why). */\nexport async function runReject(\n context: CommandContext,\n target: string | undefined,\n options: Record<string, unknown> = {},\n): Promise<number> {\n try {\n const targets = targetsOf(target, options);\n const snapshot = await openFor(context);\n const language = typeof options.lang === \"string\" ? options.lang : undefined;\n const note =\n typeof options.note === \"string\" && options.note.trim() !== \"\" ? options.note.trim() : null;\n const items = selectDrift(snapshot, {\n targets,\n ...(language === undefined ? {} : { language }),\n });\n\n print(context, await rejectItems(snapshot, items, note), options, \"rejected\");\n\n return 0;\n } catch (error) {\n return reportError(context.io, error);\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAS,QAAQ,SAAoD;CACnE,OAAO,aAAa,Q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,OAAO;EACd,OAAO,YAAY,QAAQ,IAAI,KAAK;CACtC;AACF;;AAGA,eAAsB,UACpB,SACA,QACA,UAAmC,CAAC,GACnB;CACjB,IAAI;EACF,MAAM,UAAU,UAAU,QAAQ,OAAO;EACzC,MAAM,WAAW,MAAM,QAAQ,OAAO;EACtC,MAAM,WAAW,OAAO,QAAQ,SAAS,WAAW,QAAQ,OAAO;EACnE,MAAM,OACJ,OAAO,QAAQ,SAAS,YAAY,QAAQ,KAAK,KAAK,MAAM,KAAK,QAAQ,KAAK,KAAK,IAAI;EACzF,MAAM,QAAQ,YAAY,UAAU;GAClC;GACA,GAAI,aAAa,SAAY,CAAC,IAAI,EAAE,SAAS;EAC/C,CAAC;EAED,MAAM,SAAS,MAAM,YAAY,UAAU,OAAO,IAAI,GAAG,SAAS,UAAU;EAE5E,OAAO;CACT,SAAS,OAAO;EACd,OAAO,YAAY,QAAQ,IAAI,KAAK;CACtC;AACF"}
|
|
@@ -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,IAAI;AACnB;;AAGA,SAAS,YAAY,MAAc;CACjC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Aa,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;CAED,QAAQ,KAAK,IAAI;AACnB;;AAGA,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ACb,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,MAAM;GACzB,OAAO,IAAI,OAAO,MAAM;GAC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;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. Run it on the top hit of grimoire_search, and 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, then run grimoire_impact on the top hit: the answer's alsoChanges list names the files that usually change with the top hits, `next` is the impact command, 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",
|