Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: review-voice fixes for the shared-dep hand-off and the eval spend cap

garrytan166931eb5f5f
diff --git a/src/core/skillpack/safe-update.ts b/src/core/skillpack/safe-update.ts
index 120ec81abc..6d728d7bed 100644
--- a/src/core/skillpack/safe-update.ts
+++ b/src/core/skillpack/safe-update.ts
@@ -358,14 +358,13 @@ export async function runSkillpackUpdate(opts: UpdateOptions): Promise<UpdateRes
records: loadState({ statePath: opts.statePath }).roots?.[opts.skillsRoot] ?? {},
acceptHistorical: opts.acceptHistorical === true, noDiff: opts.noDiff === true,
};
- const claimed = new Set<string>();
- const outcomes = slugs.map(slug => classifySkill(ctx, slug)).map((o): SkillOutcome => {
- if (o.result !== 'would_update') return o;
- const files = o.files.filter(f => !(f.sharedDep && f.state !== 'unchanged' && claimed.has(f.rel)));
- for (const f of files) if (f.sharedDep && f.state !== 'unchanged') claimed.add(f.rel);
+ const outcomes = slugs.map(slug => classifySkill(ctx, slug));
+ const withoutShared = (o: SkillOutcome, taken: Set<string>): SkillOutcome => {
+ const files = o.files.filter(f => !(f.sharedDep && f.state !== 'unchanged' && taken.has(f.rel)));
const changes = files.filter(f => f.state !== 'unchanged').map(f => f.rel);
return changes.length ? { ...o, files, changes } : { ...o, files, changes, result: 'current' };
- });
+ };
+ const claim = (o: SkillOutcome, taken: Set<string>) => { for (const f of o.files) if (f.sharedDep && f.state !== 'unchanged') taken.add(f.rel); };
const base = {
dry_run: opts.dryRun === true, skills_root: opts.skillsRoot,
history: history.ok ? { verified: true } : { verified: false, reason: history.reason },
@@ -373,7 +372,14 @@ export async function runSkillpackUpdate(opts: UpdateOptions): Promise<UpdateRes
};
const updatable = outcomes.filter(o => o.result === 'would_update');
if (opts.dryRun || updatable.length === 0) {
- return { ...base, journal: null, summary: summarize(outcomes), skills: outcomes, restore_command: null };
+ const claimed = new Set<string>();
+ const preview = outcomes.map(o => {
+ if (o.result !== 'would_update') return o;
+ const planned = withoutShared(o, claimed);
+ claim(planned, claimed);
+ return planned;
+ });
+ return { ...base, journal: null, summary: summarize(preview), skills: preview, restore_command: null };
}
removeStaleStages(opts.skillsRoot);
const journal: Journal = {
@@ -387,9 +393,24 @@ export async function runSkillpackUpdate(opts: UpdateOptions): Promise<UpdateRes
writeJournal(journal, backups);
const apply: ApplyContext = { opts, journal, backups, validate: opts.validate ?? defaultValidator(opts.skillsRoot) };
const results: SkillOutcome[] = [];
+ const written = new Set<string>();
for (const outcome of outcomes) {
const js = journal.skills.find(s => s.slug === outcome.slug);
- results.push(js ? await applySkill(apply, outcome, js) : outcome);
+ if (!js) {
+ results.push(outcome);
+ continue;
+ }
+ const planned = withoutShared(outcome, written);
+ if (planned.result !== 'would_update') {
+ journal.skills = journal.skills.filter(s => s !== js);
+ writeJournal(journal, backups);
+ results.push(planned);
+ continue;
+ }
+ js.files = js.files.filter(file => planned.changes.includes(file.rel));
+ const result = await applySkill(apply, planned, js);
+ if (result.result === 'updated') claim(planned, written);
+ results.push(result);
}
journal.status = 'complete';
writeJournal(journal, backups);
@@ -455,7 +476,7 @@ export async function setSkillPinned(skillsRoot: string, slug: string, pinned: b
if ((record?.pinned === true) === pinned) return { state: null, result: false };
const { pinned: _old, ...rest } = record ?? { files: {}, recorded_at: new Date().toISOString() };
if (pinned) root[slug] = { ...rest, pinned: true };
- else if (Object.keys(rest.files).length) root[slug] = rest;
+ else if (Object.keys(rest.files ?? {}).length) root[slug] = rest;
else delete root[slug];
return { state: { ...state, roots: { ...state.roots, [skillsRoot]: root } }, result: true };
}, { statePath: opts.statePath });
diff --git a/test/fixtures/skill-evals/_lib/adapter.mjs b/test/fixtures/skill-evals/_lib/adapter.mjs
index 88822c55aa..d2bbb138d5 100755
--- a/test/fixtures/skill-evals/_lib/adapter.mjs
+++ b/test/fixtures/skill-evals/_lib/adapter.mjs
@@ -26,6 +26,7 @@ const LEDGER = process.env.EVAL_LEDGER;
const CAP = Number(process.env.EVAL_SPEND_CAP ?? "0");
const spent = () => (LEDGER && existsSync(LEDGER) ? readFileSync(LEDGER, "utf8").split("\n").filter(Boolean).reduce((s, l) => s + (JSON.parse(l).costUsd ?? 0), 0) : 0);
if (CAP && spent() >= CAP) { console.error(`SPEND_CAP: ${spent().toFixed(2)} >= ${CAP} USD; stopping before another session`); process.exit(3); }
+if (CAP && !model.startsWith("claude-") && !PRICES[model]) { console.error(`SPEND_CAP: no price for ${model}, so its sessions cannot count against the cap; add it to PRICES`); process.exit(2); }
const home = join(work, ".home");
mkdirSync(home, { recursive: true });
diff --git a/test/skill-evals-adapter.test.ts b/test/skill-evals-adapter.test.ts
new file mode 100644
index 0000000000..a1b552f396
--- /dev/null
+++ b/test/skill-evals-adapter.test.ts
@@ -0,0 +1,31 @@
+/**
+ * The skill-diet eval adapter (test/fixtures/skill-evals/_lib/adapter.mjs) enforces
+ * EVAL_SPEND_CAP from its ledger. A Codex model with no price row would log a null
+ * cost that the cap reads as 0, so a capped run refuses it before starting a session.
+ */
+import { afterEach, expect, test } from 'bun:test';
+import { existsSync, mkdtempSync, rmSync } from 'fs';
+import { join } from 'path';
+import { tmpdir } from 'os';
+import { spawnSync } from 'child_process';
+
+const ADAPTER = join(import.meta.dir, 'fixtures', 'skill-evals', '_lib', 'adapter.mjs');
+const created: string[] = [];
+afterEach(() => {
+ while (created.length) rmSync(created.pop()!, { recursive: true, force: true });
+});
+
+test('a capped run refuses an unpriced Codex model before starting a session', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'skill-evals-adapter-'));
+ created.push(dir);
+ const out = join(dir, 'out');
+ const work = join(dir, 'work');
+ const r = spawnSync('node', [ADAPTER, '', 'prompt', out, work], {
+ encoding: 'utf-8',
+ env: { PATH: process.env.PATH, EVAL_MODEL: 'gpt-unpriced-example', EVAL_LEDGER: join(dir, 'ledger.jsonl'), EVAL_SPEND_CAP: '1', EVAL_AGENTS_BIN: join(dir, 'bin') },
+ });
+ expect(r.status).toBe(2);
+ expect(r.stderr).toContain('no price for gpt-unpriced-example');
+ expect(existsSync(join(out, 'raw.jsonl'))).toBe(false);
+ expect(existsSync(work)).toBe(false);
+});
diff --git a/test/skillpack-safe-update.test.ts b/test/skillpack-safe-update.test.ts
index bc39c30553..87064ef0ec 100644
--- a/test/skillpack-safe-update.test.ts
+++ b/test/skillpack-safe-update.test.ts
@@ -178,6 +178,20 @@ describe('base recording and whole-skill update', () => {
expect(read(env, 'other/SKILL.md')).toBe(V1['other/SKILL.md']);
});
+ test('a shared dependency whose first skill fails is written by the next skill that needs it', async () => {
+ const env = setup({ sharedDeps: ['skills/conventions'], first: { ...V1, 'conventions/a.md': 'a v1\n' } });
+ await scaffold(env);
+ release(env.gbrainRoot, { ...V2, 'conventions/b.md': 'b v2\n' });
+ const result = await update(env, { validate: (_root, slug) => (slug === 'demo' ? ['forced failure'] : []) });
+ expect(outcome(result, 'demo').result).toBe('failed');
+ expect(outcome(result, 'other').result).toBe('updated');
+ expect(read(env, 'conventions/b.md')).toBe('b v2\n');
+ const [journal] = listJournals(env.backups);
+ await runSkillpackRestore({ id: journal!.id, statePath: env.statePath, backups: env.backups });
+ expect(existsSync(join(env.ws, 'skills', 'conventions/b.md'))).toBe(false);
+ expect(read(env, 'other/SKILL.md')).toBe(V1['other/SKILL.md']);
+ });
+
test('a pinned skill is skipped until unpinned', async () => {
const env = setup();
await scaffold(env);