Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytan928b19d9fbdf
diff --git a/docs/guides/skill-resolver.md b/docs/guides/skill-resolver.md
index e28e3c584a..2405405a84 100644
--- a/docs/guides/skill-resolver.md
+++ b/docs/guides/skill-resolver.md
@@ -330,7 +330,9 @@ Run `gbrain setup cursor --skill-loading resolve` in the project:
`gbrain skills pin add|remove` rewrites the rule from any directory, and
Cursor applies it from its next request. `gbrain setup cursor --skill-loading
off` in the project removes the rule, its exclude line and the record; pins
-stay in config.json.
+stay in config.json. The pins sit beside the skills index that
+`--skill-loading spring` writes into the brain-first rule: resolve leaves that
+index alone, and spring leaves the pins alone.
## Pinned skills
diff --git a/src/commands/setup.ts b/src/commands/setup.ts
index 761609239b..a751d869fd 100644
--- a/src/commands/setup.ts
+++ b/src/commands/setup.ts
@@ -326,9 +326,10 @@ function parseFlags(args: string[]): SetupFlags | string {
if (owners.some((o) => !/^[\x21-\x7e]{1,128}$/.test(o))) return '--owner-sender needs a sender id';
const openclawTuning = { ...(liveFraction !== undefined ? { live_fraction: Number(liveFraction) } : {}), ...(pinsRoute ? { pins_route: pinsRoute as 'system' | 'first_turn' } : {}), ...(owners.length ? { owner_sender_ids: owners } : {}) };
const chosenLoading = flagLoading ?? (envLoading || undefined);
- const skillResolver = !resolverHarness || chosenLoading === undefined ? undefined : chosenLoading === 'resolve' ? 'on' as const : chosenLoading === 'shadow' ? 'shadow' as const : 'off' as const;
- // resolve replaces the spring index: the skills block is decided as off, explicitly, so GBRAIN_SKILL_LOADING=resolve is never read as a block mode.
- const skillLoading = skillResolver === 'on' || skillResolver === 'shadow' ? 'off' : flagLoading;
+ const cursor = positionals[0] === 'cursor';
+ const skillResolver = !resolverHarness || chosenLoading === undefined || (cursor && chosenLoading === 'spring') ? undefined : chosenLoading === 'resolve' ? 'on' as const : chosenLoading === 'shadow' ? 'shadow' as const : 'off' as const;
+ // resolve replaces the spring index (on Cursor the pins sit beside it, so neither run removes the other): the skills block is decided as off, explicitly, so GBRAIN_SKILL_LOADING=resolve is never read as a block mode.
+ const skillLoading = skillResolver === 'on' || skillResolver === 'shadow' ? (cursor ? undefined : 'off') : flagLoading;
return {
harness: positionals[0],
dryRun: args.includes('--dry-run'),
@@ -896,6 +897,7 @@ function removeBrainFirstFor(harness: BrainFirstHarness, where: { scope?: Wiring
* It sits beside the brain-first block, so declining that block (--no-instructions) removes the index too.
*/
function skillsFor(harness: BrainFirstHarness, flags: SetupFlags, launcher: string, where: { scope?: WiringScope; projectDir?: string }, brainFirst: BrainFirstOutcome | null): SkillsBlockOutcome | null {
+ if (harness === 'cursor' && flags.skillResolver === 'on') return null;
const target = brainFirstTarget(harness, { ...where, workspace: flags.workspace });
if ('error' in target) return null;
return installerSkillsBlock({ target, launcher, writer: `gbrain setup ${harness}`, brainFirstDeclined: brainFirst?.decision.value === 'declined', skillLoading: flags.skillLoading, audience: isThinClient(loadConfig()) ? 'downstream' : 'owner', dryRun: flags.dryRun });
diff --git a/src/core/setup/cursor-skill-pins.ts b/src/core/setup/cursor-skill-pins.ts
index 613c05d09a..56240d4298 100644
--- a/src/core/setup/cursor-skill-pins.ts
+++ b/src/core/setup/cursor-skill-pins.ts
@@ -193,7 +193,9 @@ export function refreshCursorPins(home: string, catalog: string): CursorPinsResu
const state = readCursorPinsState(home);
const project = Object.keys(state.projects).find((p) => state.projects[p]!.catalog === catalog);
if (!project) return null;
- return place(home, { mode: 'pinned', project, catalog, skills: 0, pins: 0, steps: [], notes: [] }, state.projects[project]!.skill_dirs, false);
+ const out: CursorPinsResult = { mode: 'pinned', project, catalog, skills: 0, pins: 0, steps: [], notes: [] };
+ if (!existsSync(project)) return { ...out, error: { code: 'skill_resolver_setup_incomplete', message: project + ' no longer exists, so no rule was written there; the pins are saved in config.json. Recreate the project and run gbrain setup cursor --skill-loading resolve in it.' } };
+ return place(home, out, state.projects[project]!.skill_dirs, false);
}
/** Remove the project's rule (only gbrain's), its exclude line and its record; pins stay in config.json. Null when none of them exists. */
diff --git a/test/setup-cursor-skill-pins.test.ts b/test/setup-cursor-skill-pins.test.ts
index 3774e10839..2b85317c1a 100644
--- a/test/setup-cursor-skill-pins.test.ts
+++ b/test/setup-cursor-skill-pins.test.ts
@@ -153,6 +153,16 @@ describe('gbrain setup cursor --skill-loading resolve (pinned skills only)', ()
expect(r.doc.skill_pins.notes.join('\n')).toContain('not in a git repository');
});
+ test('pin add for a recorded project that no longer exists saves the pin and recreates nothing', async () => {
+ const b = box();
+ const catalog = (await setup(b, ['--skill-loading', 'resolve'])).doc.skill_pins.catalog;
+ rmSync(b.repo, { recursive: true, force: true });
+ const r = await runCli(['skills', 'pin', 'add', 'deploy-service', '--catalog', catalog, '--json'], { env: b.env, cwd: b.home, timeoutMs: 110_000 });
+ expect(JSON.parse(r.stdout).cursor_rule.error).toMatchObject({ code: 'skill_resolver_setup_incomplete' });
+ expect(existsSync(b.project)).toBe(false);
+ expect(JSON.parse(readFileSync(join(gbrainHome(b), 'config.json'), 'utf8')).skills.resolver.pins[catalog]).toEqual([{ name: 'deploy-service' }]);
+ });
+
test('a rule file gbrain did not write is left as it is and setup exits non-zero', async () => {
const b = box();
mkdirSync(join(b.project, '.cursor', 'rules'), { recursive: true });
@@ -184,6 +194,26 @@ describe('gbrain setup cursor --skill-loading resolve (pinned skills only)', ()
expect((await setup(b, ['--skill-loading', 'off'])).doc.skill_pins).toBeUndefined();
});
+ test('resolve leaves the spring skills index in the brain-first rule, and spring leaves the pins rule', async () => {
+ const b = box();
+ const launcher = join(b.root, 'gbrain');
+ writeFileSync(launcher, `#!/bin/sh\nexec '${process.execPath}' --no-env-file '${join(import.meta.dir, '..', 'src', 'cli.ts')}' "$@"\n`, { mode: 0o755 });
+ const spring = await setup(b, ['--skill-loading', 'spring', '--gbrain-bin', launcher]);
+ expect(spring.exitCode).toBe(0);
+ expect(spring.doc.skills).toMatchObject({ action: 'write', decision: { value: 'spring' } });
+ const index = readFileSync(join(b.project, BRAIN_FIRST), 'utf8');
+ const r = await setup(b, ['--skill-loading', 'resolve', '--gbrain-bin', launcher]);
+ expect(r.exitCode).toBe(0);
+ expect(r.doc.skills?.action).not.toBe('remove');
+ expect(readFileSync(join(b.project, BRAIN_FIRST), 'utf8')).toBe(index);
+ await cli(b, ['skills', 'pin', 'add', 'deploy-service', '--catalog', r.doc.skill_pins.catalog]);
+ const rule = readFileSync(rulePath(b), 'utf8');
+ const again = await setup(b, ['--skill-loading', 'spring', '--gbrain-bin', launcher]);
+ expect(again.exitCode).toBe(0);
+ expect(readFileSync(rulePath(b), 'utf8')).toBe(rule);
+ expect(readFileSync(join(b.project, BRAIN_FIRST), 'utf8')).toBe(index);
+ });
+
test('a plain gbrain setup cursor writes no pins, and a project with no skill directory refuses resolve', async () => {
const b = box({ skills: false });
const plain = await setup(b, []);