Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Skill resolver: a JSON catalog over 8 MB reads fresh right after its build; Hermes lane guide gives a command Hermes can run
garrytana8d5590947aa
diff --git a/docs/guides/skill-resolver.md b/docs/guides/skill-resolver.mdindex 8265d7a936..fcac3ba4b8 100644--- a/docs/guides/skill-resolver.md+++ b/docs/guides/skill-resolver.md@@ -94,11 +94,16 @@ per-turn hook that puts the block in front of the model on every prompt:`--dry-run` lists every write, and re-running changes nothing. A bare`gbrain setup <harness>` refreshes a lane that is on.-**Hermes** runs the same lane as a `pre_llm_call` shell hook:-`GBRAIN_HOOK_LANE=skill-resolver gbrain hook user-prompt --harness hermes`.+**Hermes** runs the same lane as a `pre_llm_call` shell hook. Hermes splits+the command without a shell and needs its first word to be a path that+exists, so pass the environment through `/usr/bin/env` and name gbrain by its+absolute path:+`/usr/bin/env GBRAIN_HOOK_LANE=skill-resolver /abs/path/to/gbrain hook user-prompt --harness hermes`.Setup does not wire it yet, so build `hermes-user` yourself(`gbrain skills index build --catalog hermes-user --dir ~/.hermes/skills---harness hermes`) and add `hermes` to `skills.resolver.harnesses`. The lane+--harness hermes`) and add `hermes` to `skills.resolver.harnesses` in+`~/.gbrain/config.json` by hand (`gbrain config set` refuses that key, which+setup owns). Doctor's `skill_resolver` check does not cover Hermes yet. The lanereads `extra.user_message`, `session_id` and `cwd` from the hook's stdin andanswers `{"context": "<block>"}`. Hermes sends the whole conversation historyon every turn, so the lane streams stdin and keeps only those three stringsdiff --git a/src/core/skills/resolver/sources.ts b/src/core/skills/resolver/sources.tsindex bd2e727c67..b1b7314b9a 100644--- a/src/core/skills/resolver/sources.ts+++ b/src/core/skills/resolver/sources.ts@@ -203,6 +203,12 @@ const optStr = (v: unknown) => v === undefined || typeof v === 'string';const optStrList = (v: unknown) => v === undefined || (Array.isArray(v) && v.every(x => typeof x === 'string'));const optBool = (v: unknown) => v === undefined || typeof v === 'boolean';const OPENCLAW_HIDDEN = ['disabled', 'blockedByAllowlist', 'blockedByAgentFilter'] as const;+/** boundBody repeated until it changes nothing (each pass only removes text): an over-cap snapshot stores this, so its re-read bounds every body to itself. */+function settledBody(text: string): string {+ let b = boundBody(text);+ for (let next = boundBody(b); next !== b; next = boundBody(b)) b = next;+ return b;+}/** The first field that makes entry `o` invalid, or null. OpenClaw entries carry no id: the name stands in. */function badField(o: Record<string, unknown>, openclaw: boolean): string | null {@@ -228,6 +234,7 @@ export function readJsonSource(text: string): SourceRead {if (!list) throw invalid('The JSON catalog must be an array of skills (or {"skills": [...]}).');if (list.length > MAX_SKILLS) throw invalid(`The JSON catalog has ${list.length} skills; the bound is ${MAX_SKILLS}.`);const openclaw = !!doc && ('workspaceDir' in doc || 'managedSkillsDir' in doc);+ const bodyOf = bytes > JSON_SOURCE_CAP_BYTES ? settledBody : boundBody;const skills: SkillRecord[] = [];const skipped: SkippedSkill[] = [];const seen = new Map<string, string>();@@ -249,10 +256,10 @@ export function readJsonSource(text: string): SourceRead {skills.push({ id, name: cut(cleanText(o.name), MAX_NAME), description: cut(cleanText(o.description ?? ''), MAX_DESCRIPTION), ...(whenToUse ? { whenToUse } : {}),triggers: boundTriggers(((o.triggers as string[] | undefined) ?? []).map(cleanText).filter(Boolean)),routing: ((o.routing as string[] | undefined) ?? []).map(cleanText).filter(Boolean).slice(0, MAX_ROUTING_ROWS),- body: typeof o.body === 'string' ? boundBody(o.body) : '', ...at });+ body: typeof o.body === 'string' ? bodyOf(o.body) : '', ...at });});if (bytes <= JSON_SOURCE_CAP_BYTES) return { kind: 'json', skills, skipped, snapshot: text };- for (const e of list) { const o = e as Record<string, unknown>; if (typeof o.body === 'string') o.body = boundBody(o.body); }+ for (const e of list) { const o = e as Record<string, unknown>; if (typeof o.body === 'string') o.body = settledBody(o.body); }return { kind: 'json', skills, skipped, snapshot: JSON.stringify(parsed) };}diff --git a/test/skill-resolver.test.ts b/test/skill-resolver.test.tsindex fb6b33f0bb..435ab30707 100644--- a/test/skill-resolver.test.ts+++ b/test/skill-resolver.test.ts@@ -595,6 +595,16 @@ describe('catalog sources and bounds', () => {expect((await resolveSkills({ message: 'zebrafinch' }, { home, catalogs: ['full'] })).output.suggestions[0]?.id).toBe('s7');});+ test('a JSON catalog over 8 MB stays fresh when a 4 KB cut ends on whitespace or a body opens with two frontmatter blocks', async () => {+ const home = tmp();+ const full = Array.from({ length: 900 }, (_, i) => ({ id: `s${i}`, name: `skill-${i}`, description: `${word(i, 9)} task`,+ body: i === 1 ? `---\nkind: a\n---\n---\nkind: b\n---\n${'abc '.repeat(2500)}` : 'abc '.repeat(2500) }));+ const text = JSON.stringify(full);+ expect(Buffer.byteLength(text)).toBeGreaterThan(8 * 1024 * 1024);+ await buildSkillIndex({ catalog: 'ws', fromJson: text, fromJsonStdin: true }, { home });+ expect(await catalogStatus('ws', { home })).toMatchObject({ fresh: true, stale_reason: null });+ });+test('a SKILL.md over 64 KB is skipped as unreadable, not read whole', async () => {const home = tmp();const root = tmp('skres-dir-');