Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

skill resolver lane: pin resolver-off setup files and user-prompt output to the pre-resolver golden

garrytan632b2809e49f
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 2370e2145b..b9c2eea827 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -387,6 +387,7 @@ test/shared-skills-writer-boundary.test.ts (file-level) 7 readFileSync
test/skill-resolver-hook-lane.test.ts skill-resolver lane: compiled binaries 1 readFileSync
test/skill-resolver-hook-lane.test.ts skill-resolver lane: delivery per harness 3 readFileSync
test/skill-resolver-hook-lane.test.ts skill-resolver lane: fail open 6 readFileSync
+test/skill-resolver-off-pin.test.ts (file-level) 1 readFileSync
test/skill-resolver-packaging.test.ts skill resolver packaging 1 bun-file
test/skillify-scaffold.test.ts 11-item scaffold contract (T9 + Phase 3 cross-modal eval) 1 readFileSync
test/skillify-scaffold.test.ts applyScaffold 3 readFileSync
diff --git a/test/fixtures/goldens/skill-resolver/off-pin.json b/test/fixtures/goldens/skill-resolver/off-pin.json
new file mode 100644
index 0000000000..3594e98cd9
--- /dev/null
+++ b/test/fixtures/goldens/skill-resolver/off-pin.json
@@ -0,0 +1,29 @@
+{
+ "setup:claude-code:exit": 0,
+ "setup:codex:exit": 0,
+ "files": {
+ ".agents/skills/deploy-widget/SKILL.md": "sha256:c4396aa5aeb3d35353ddd456241f1df05addcc7f5902ca7970b859599490e485",
+ ".claude/CLAUDE.md": "sha256:fa254b30e33c9c5baed507b4d6a65e8f699b536f4b87e07f8491192b0ce75518",
+ ".claude/settings.json": "sha256:db51e7114b74f6d6c3867758c85170bf02978ebedcf843415cf647b43c680281",
+ ".claude/skills/deploy-widget/SKILL.md": "sha256:c4396aa5aeb3d35353ddd456241f1df05addcc7f5902ca7970b859599490e485",
+ ".codex/AGENTS.md": "sha256:fbd2eee597daf65939a4558b6b62585fc3e136cc5ae0713d13c0b0bf31d8ed4e",
+ ".codex/config.toml": "sha256:c7ba1932425aeea910224a2b6876a43845f1e925c8abfbe52e83cb35a28771be",
+ ".codex/hooks.json": "sha256:85519b7b2cf4f84208fe47e59bf87224a793bcf303fda59f45d98e541f526eb1",
+ ".gbrain/agent-instructions.json": "sha256:4f541f2d3531804b89ca5e2fac1af49b4a77668938580dd0d07e245770866efd",
+ ".gbrain/agent-instructions.lock": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
+ ".gbrain/hook-launcher/gbrain-hook": "sha256:a194491363199f9b91090e473c6931790b72daaf2ed28d3e23e9c85ef89eec10",
+ ".gbrain/integrations/hooks/heartbeat.jsonl": "sha256:83625960782a0c6d354105f787839fad3f4883efb3a752fa90c2f7be1805e545"
+ },
+ "userPromptHooks": [
+ {
+ "command": "env GBRAIN_HOME=<ROOT>/home GBRAIN_HOOK_LANE=turn-rule <ROOT>/home/.gbrain/hook-launcher/gbrain-hook <ROOT>/bin/gbrain hook user-prompt",
+ "exitCode": 0,
+ "stdout": "{\"hookSpecificOutput\":{\"hookEventName\":\"UserPromptSubmit\",\"additionalContext\":\"GBrain: before answering this turn, check GBrain first (`search` or `query` on the `gbrain` MCP server) for the people, companies, projects, meetings and decisions it touches. Results span every source it holds: use only what the current requester may see. Then answer and finish the task.\"}}\n"
+ },
+ {
+ "command": "env GBRAIN_HOOK_LANE=turn-rule GBRAIN_HOME=<ROOT>/home <ROOT>/home/.gbrain/hook-launcher/gbrain-hook <ROOT>/bin/gbrain hook user-prompt --harness codex",
+ "exitCode": 0,
+ "stdout": "{\"hookSpecificOutput\":{\"hookEventName\":\"UserPromptSubmit\",\"additionalContext\":\"GBrain: before answering this turn, check GBrain first (`search` or `query` on the `gbrain` MCP server) for the people, companies, projects, meetings and decisions it touches. Results span every source it holds: use only what the current requester may see. Then answer and finish the task.\"}}\n"
+ }
+ ]
+}
diff --git a/test/helpers/skill-resolver-off-capture.ts b/test/helpers/skill-resolver-off-capture.ts
new file mode 100644
index 0000000000..afca800f9c
--- /dev/null
+++ b/test/helpers/skill-resolver-off-capture.ts
@@ -0,0 +1,83 @@
+/**
+ * Captures what plain setup and the user-prompt hook produce with the skill
+ * resolver off, for test/skill-resolver-off-pin.test.ts. Pass the CLI to
+ * run: `bun test/helpers/skill-resolver-off-capture.ts <path/to/src/cli.ts>`
+ * prints the capture as JSON. The golden was captured from master before the
+ * resolver existed. To regenerate it, run this against a tree where the
+ * resolver is off, and review the diff.
+ */
+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, readlinkSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+/** Machine and clock parts: the temp root, the bun path, timestamps, durations, and Codex's trust hash (it hashes hooks.json, which is pinned itself). */
+function normalize(text: string, root: string): string {
+ return text.split(root).join('<ROOT>').split(process.execPath).join('<BUN>')
+ .replace(/"(updated_at|ts)":\s*"[^"]*"/g, '"$1":"<TS>"')
+ .replace(/"duration_ms":\s*\d+/g, '"duration_ms":"<MS>"')
+ .replace(/trusted_hash = "sha256:[0-9a-f]+"/g, 'trusted_hash = "<HASH>"');
+}
+const sha256 = (s: string) => new Bun.CryptoHasher('sha256').update(s).digest('hex');
+
+const PROMPT = { prompt: 'Deploy the widget service to staging, then write a changelog entry.', session_id: 'off-pin-session', hook_event_name: 'UserPromptSubmit' };
+
+function tree(dir: string, base: string, root: string, out: Record<string, string>): Record<string, string> {
+ if (!existsSync(dir)) return out;
+ for (const e of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
+ const p = join(dir, e.name);
+ if (dir === base && e.name === '.bun') continue;
+ if (e.isSymbolicLink()) out[p.slice(base.length + 1)] = `symlink -> ${normalize(readlinkSync(p), root)}`;
+ else if (e.isDirectory()) tree(p, base, root, out);
+ else out[p.slice(base.length + 1)] = `sha256:${sha256(normalize(readFileSync(p, 'utf8'), root))}`;
+ }
+ return out;
+}
+
+async function run(argv: string[], env: Record<string, string>, cwd: string, stdin?: string) {
+ const proc = Bun.spawn(argv, { env, cwd, stdin: stdin === undefined ? 'ignore' : new TextEncoder().encode(stdin), stdout: 'pipe', stderr: 'pipe' });
+ const [stdout, stderr, exitCode] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);
+ return { stdout, stderr, exitCode };
+}
+
+export async function captureResolverOff(cli: string): Promise<Record<string, unknown>> {
+ const root = mkdtempSync(join(tmpdir(), 'gbrain-off-pin-'));
+ try {
+ const home = join(root, 'home'), project = join(root, 'project'), bin = join(root, 'bin', 'gbrain');
+ for (const d of [home, project, join(root, 'bin')]) mkdirSync(d, { recursive: true });
+ writeFileSync(bin, `#!/bin/sh\nexec '${process.execPath}' --no-env-file '${cli}' "$@"\n`);
+ chmodSync(bin, 0o755);
+ for (const dir of [join(home, '.claude', 'skills'), join(home, '.agents', 'skills')]) {
+ mkdirSync(join(dir, 'deploy-widget'), { recursive: true });
+ writeFileSync(join(dir, 'deploy-widget', 'SKILL.md'), '---\nname: deploy-widget\ndescription: Deploy the widget service to staging or production.\n---\nSteps.\n');
+ }
+ const env: Record<string, string> = { HOME: home, GBRAIN_HOME: home, PATH: '/usr/bin:/bin', GBRAIN_SKIP_STARTUP_HOOKS: '1', NO_COLOR: '1' };
+ const out: Record<string, unknown> = {};
+ for (const harness of ['claude-code', 'codex']) {
+ const r = await run([process.execPath, '--no-env-file', cli, 'setup', harness, '--instructions-only', '--gbrain-bin', bin], env, project);
+ out[`setup:${harness}:exit`] = r.exitCode;
+ }
+ out.files = tree(home, home, root, {});
+ const commands: string[] = [];
+ const claude = join(home, '.claude', 'settings.json'), codex = join(home, '.codex', 'hooks.json');
+ for (const f of [claude, codex]) {
+ if (!existsSync(f)) continue;
+ const doc = JSON.parse(readFileSync(f, 'utf8'));
+ for (const g of doc.hooks?.UserPromptSubmit ?? []) for (const h of g.hooks ?? []) commands.push(h.command);
+ }
+ const hooks: Record<string, unknown>[] = [];
+ for (const command of commands) {
+ const r = await run(['sh', '-c', command], env, project, JSON.stringify({ cwd: project, ...PROMPT }));
+ hooks.push({ command: normalize(command, root), exitCode: r.exitCode, stdout: normalize(r.stdout, root) });
+ }
+ out.userPromptHooks = hooks;
+ return out;
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+}
+
+if (import.meta.main) {
+ const cli = process.argv[2];
+ if (!cli) { console.error('usage: bun test/helpers/skill-resolver-off-capture.ts <path/to/src/cli.ts>'); process.exit(2); }
+ console.log(JSON.stringify(await captureResolverOff(cli), null, 2));
+}
diff --git a/test/skill-resolver-off-pin.test.ts b/test/skill-resolver-off-pin.test.ts
new file mode 100644
index 0000000000..e0fc03eedc
--- /dev/null
+++ b/test/skill-resolver-off-pin.test.ts
@@ -0,0 +1,21 @@
+/**
+ * GBRA-377: with the skill resolver off, plain `gbrain setup claude-code`
+ * and `setup codex` write byte-identical files, and every UserPromptSubmit
+ * hook they wire prints byte-identical output, compared with master before
+ * the resolver existed. The golden holds a sha256 per file and the full
+ * hook output. Machine and clock parts are normalized in
+ * test/helpers/skill-resolver-off-capture.ts, which also says how to
+ * regenerate the golden.
+ */
+import { expect, setDefaultTimeout, test } from 'bun:test';
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { captureResolverOff } from './helpers/skill-resolver-off-capture.ts';
+
+setDefaultTimeout(120_000);
+
+test('resolver off: setup files and user-prompt hook output match the pre-resolver golden byte for byte', async () => {
+ const golden = JSON.parse(readFileSync(join(import.meta.dir, 'fixtures', 'goldens', 'skill-resolver', 'off-pin.json'), 'utf8'));
+ const now = await captureResolverOff(join(import.meta.dir, '..', 'src', 'cli.ts'));
+ expect(now).toEqual(golden);
+});