Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

shared-skills: let a source opt out of catalog adoption explicitly

Dov Sternfd48b0d2df0d
diff --git a/src/core/shared-skills/setup-source-policy.ts b/src/core/shared-skills/setup-source-policy.ts
index 0a1ed7fa2a..84a49c43a1 100644
--- a/src/core/shared-skills/setup-source-policy.ts
+++ b/src/core/shared-skills/setup-source-policy.ts
@@ -14,6 +14,16 @@ export async function sharedSkillSourcePolicy(engine: BrainEngine, sourceId: str
const [source] = await engine.executeRaw<{ config: unknown }>('SELECT config FROM sources WHERE id=$1 AND NOT archived', [sourceId]);
if (!source) throw new OperationError('source_changed', 'The selected content source is missing or archived.');
const config = parseSourceConfig(source.config);
+ // A source can already decline adoption implicitly by being connector-managed
+ // or an unapproved external repo (below). Some sources have a working
+ // skill-delivery path entirely outside this migration (their own
+ // brain-resident skillpack served over MCP, or an external plugin install)
+ // and need an explicit way to decline too: `inventorySkillpack`'s fixed
+ // file-count/byte-size bound throws on any skillpack that exceeds it, and
+ // after enough consecutive failures the migration wedges permanently for
+ // that source, with no other way to opt out per source.
+ if (config.shared_skills === false) return { mode: 'preserve_files',
+ reason: 'source_shared_skills_disabled: this source opted out of shared-skills catalog adoption (config.shared_skills=false). Its existing skill-delivery path (e.g. list_brain_skillpack/get_skill, or an external plugin install) is unaffected; no files or grants were touched.' };
if (config.kind != null) return { mode: 'preserve_files',
reason: 'source_skill_adoption_required: this connector-managed source is not a shared-skill write target. Preserve its generated/imported files and put approved shared skills in a separate content source.' };
if (config.remote_url != null || config.managed_clone === true) return { mode: 'explicit_pack_required',
diff --git a/test/shared-skills-source-policy.serial.test.ts b/test/shared-skills-source-policy.serial.test.ts
index 3c259e01f9..8b9405c70e 100644
--- a/test/shared-skills-source-policy.serial.test.ts
+++ b/test/shared-skills-source-policy.serial.test.ts
@@ -88,6 +88,30 @@ test('a real approved company source remains byte-identical across shared-skill
});
}, 180_000);
+test('a source with config.shared_skills=false opts out of adoption without touching its files', async () => {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-shared-optout-'));
+ await withEnv({ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {
+ const { engine, close } = await isolatedSharedSkillsEngine();
+ try {
+ const ctx: OperationContext = { engine, config: { engine: 'pglite' }, sourceId: 'default', remote: false, dryRun: false, logger: { info() {}, warn() {}, error() {} } };
+ expect(await sharedSkillSourcePolicy(engine, 'default')).toEqual({ mode: 'content' });
+ await engine.executeRaw("UPDATE sources SET config='{\"shared_skills\": false}'::jsonb WHERE id='default'");
+ const policy = await sharedSkillSourcePolicy(engine, 'default');
+ expect(policy.mode).toBe('preserve_files');
+ expect(policy.mode === 'preserve_files' && policy.reason).toContain('source_shared_skills_disabled');
+ const migration = await runSharedSkillsMigration(ctx);
+ expect(migration.sources[0].status).not.toBe('conflict');
+ expect(migration.sources[0].stages[0].reason).toContain('source_shared_skills_disabled');
+ await expect(installPackagedSharedSkills(ctx, 'default')).rejects.toMatchObject({ code: 'source_writeback_required' });
+ // Only an explicit `false` opts out — absent or `true` stays eligible.
+ await engine.executeRaw("UPDATE sources SET config='{\"shared_skills\": true}'::jsonb WHERE id='default'");
+ expect(await sharedSkillSourcePolicy(engine, 'default')).toEqual({ mode: 'content' });
+ await engine.executeRaw("UPDATE sources SET config='{}'::jsonb WHERE id='default'");
+ expect(await sharedSkillSourcePolicy(engine, 'default')).toEqual({ mode: 'content' });
+ } finally { await close(); rmSync(home, { recursive: true, force: true }); }
+ });
+}, 60_000);
+
test('connector and unapproved external sources cannot receive packaged content or DB-export scaffolding', async () => {
const home = mkdtempSync(join(tmpdir(), 'gbrain-shared-connectors-'));
await withEnv({ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {