Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Keep skillpack scaffold succeeding when the state file cannot be recorded
garrytan44fed86b775a
diff --git a/src/core/skillpack/safe-update.ts b/src/core/skillpack/safe-update.tsindex 2c36086cd4..ef73c53bb5 100644--- a/src/core/skillpack/safe-update.ts+++ b/src/core/skillpack/safe-update.ts@@ -505,7 +505,9 @@ export interface ScaffoldedFile {* byte-identical to the bundle. Shared dependencies, paired sources and* pre-existing files that differ are not recorded (they are not gbrain's* install). Without a `source` (the harness bridge's rendered files), the- * written bytes on disk are the base.+ * written bytes on disk are the base. The files are already written, so a+ * state file that cannot be read or locked is a warning on stderr, not a+ * failure: without a base, a later --update-untouched skips the skill.*/export async function recordScaffoldBases(skillsRoot: string, files: readonly ScaffoldedFile[], opts: { statePath?: string } = {}): Promise<void> {const root = skillsRootKey(skillsRoot);@@ -520,5 +522,9 @@ export async function recordScaffoldBases(skillsRoot: string, files: readonly Sc(bases[rel.split('/')[0]!] ??= {})[rel] = current;}if (Object.keys(bases).length === 0) return;- await updateState(state => ({ state: withSkillBases(state, root, bases), result: null }), opts);+ try {+ await updateState(state => ({ state: withSkillBases(state, root, bases), result: null }), opts);+ } catch (err) {+ console.error(`[skillpack] the skill files were written, but their install bases were not recorded (${(err as Error).message}); a later --update-untouched treats these skills as locally edited and skips them.`);+ }}diff --git a/test/skillpack-safe-update.test.ts b/test/skillpack-safe-update.test.tsindex 6e1c3d77f0..ee4e568d00 100644--- a/test/skillpack-safe-update.test.ts+++ b/test/skillpack-safe-update.test.ts@@ -83,6 +83,23 @@ const write = (env: Env, rel: string, body: string) => writeFileSync(join(env.wsconst outcome = (result: Awaited<ReturnType<typeof update>>, slug: string) => result.skills.find(s => s.slug === slug)!;describe('base recording and whole-skill update', () => {+ test('scaffold: a state file that cannot be read warns after the files are written instead of failing', async () => {+ const env = setup();+ mkdirSync(dirname(env.statePath), { recursive: true });+ writeFileSync(env.statePath, JSON.stringify({ schema_version: 'gbrain-skillpack-state-v99' }));+ const warnings: string[] = [];+ const original = console.error;+ console.error = (...args: unknown[]) => { warnings.push(args.join(' ')); };+ try {+ await scaffold(env);+ } finally {+ console.error = original;+ }+ expect(read(env, 'demo/SKILL.md')).toBe(V1['demo/SKILL.md']);+ expect(warnings.some(w => w.includes('install bases were not recorded'))).toBe(true);+ expect(JSON.parse(readFileSync(env.statePath, 'utf-8')).schema_version).toBe('gbrain-skillpack-state-v99');+ });+test('a state save that fails after the files land keeps the skill updated, leaves the next skill untouched and finishes the journal', async () => {const env = setup();await scaffold(env);