Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(errors): B10 backfill small shared-skills, writer-guard and harness shared-skills refusals

garrytan630427fda31c
diff --git a/scripts/agent-contract-baselines/suggestionless-operation-error.tsv b/scripts/agent-contract-baselines/suggestionless-operation-error.tsv
index 404a18e585..c0a6583bda 100644
--- a/scripts/agent-contract-baselines/suggestionless-operation-error.tsv
+++ b/scripts/agent-contract-baselines/suggestionless-operation-error.tsv
@@ -21,7 +21,6 @@ src/core/embed-facts-options.ts 1
src/core/embed-facts.ts 2
src/core/facts/backstop.ts 1
src/core/harness/native-router.ts 1
-src/core/harness/shared-skills.ts 2
src/core/minions/submission-authority.ts 1
src/core/minions/tool-write-identity.ts 1
src/core/page-state/import-guard.ts 1
@@ -75,11 +74,6 @@ src/core/repair/extractor-facts.ts 2
src/core/repair/stale-atoms.ts 2
src/core/search/evidence-delivery.ts 1
src/core/shared-skills/adapter.ts 2
-src/core/shared-skills/compatibility.ts 2
-src/core/shared-skills/membership-authority.ts 1
src/core/shared-skills/membership.ts 1
-src/core/shared-skills/migration-projection.ts 2
-src/core/shared-skills/setup-source-policy.ts 2
-src/core/skillpack/writer-guard.ts 1
src/core/source-local-reference-index.ts 2
src/mcp/dispatch.ts 1
diff --git a/src/core/harness/shared-skills.ts b/src/core/harness/shared-skills.ts
index dc425e5be7..6405ee776c 100644
--- a/src/core/harness/shared-skills.ts
+++ b/src/core/harness/shared-skills.ts
@@ -41,8 +41,14 @@ export async function installSharedSkillsConnection(credentials: HarnessCredenti
const result = await client.callTool({ name, arguments: params }, undefined, { timeout: 30_000 });
const text = extractResultText(result.content);
let data: any;
- try { data = JSON.parse(text); } catch { throw new OperationError('shared_skills_unsupported', 'The server does not expose the shared-skills protocol.'); }
- if (result.isError || data.error) throw new OperationError(typeof data.error === 'string' ? data.error : 'shared_skills_unavailable', 'The shared-skills operation was refused. Memory remains independently available.');
+ try { data = JSON.parse(text); } catch {
+ throw new OperationError('shared_skills_unsupported', 'The server does not expose the shared-skills protocol.',
+ `The gbrain server at ${credentials.mcp_url} answered ${name} without the shared-skills protocol; it probably runs an older gbrain. Ask its operator to run gbrain upgrade; memory keeps working meanwhile.`);
+ }
+ if (result.isError || data.error) {
+ throw new OperationError(typeof data.error === 'string' ? data.error : 'shared_skills_unavailable', 'The shared-skills operation was refused. Memory remains independently available.',
+ `The server refused ${name}. Tell the user; following shared skills needs the server operator to publish them and grant this connection, while memory keeps working.`);
+ }
return data as T;
};
}
diff --git a/src/core/shared-skills/compatibility.ts b/src/core/shared-skills/compatibility.ts
index cb85981b90..c1db8d9e4c 100644
--- a/src/core/shared-skills/compatibility.ts
+++ b/src/core/shared-skills/compatibility.ts
@@ -31,7 +31,9 @@ export async function listLegacySharedSkills(ctx: OperationContext, section?: st
instructions: { summary: SKILL_CATALOG_INSTRUCTIONS.summary, how_to_use: [...SKILL_CATALOG_INSTRUCTIONS.how_to_use], available_brain_tools: access, fetch_op: 'get_skill' } };
}
export async function getLegacySharedSkill(ctx: OperationContext, name: unknown, sourceId?: string): Promise<GetSkillResult | ResidentSkillDetail> {
- if (typeof name !== 'string' || !name) throw new OperationError('invalid_params', 'A legacy skill request requires name.');
+ if (typeof name !== 'string' || !name) {
+ throw new OperationError('invalid_params', 'A legacy skill request requires name.', 'Pass name exactly as list_skills returned it.');
+ }
const skill = await getSharedSkill(ctx, { name, source_id: sourceId });
if (sourceId) return { source_id: skill.source_id, pack_name: skill.pack_id, slug: skill.name, description: skill.description, body: skill.body };
const fm = parseSkillFrontmatter(skill.body);
@@ -51,7 +53,10 @@ export async function listLegacySharedPacks(ctx: OperationContext): Promise<Resi
if (!pack) {
const [stored] = await ctx.engine.executeRaw<{ manifest: Record<string, unknown> }>(`SELECT manifest FROM shared_skill_packs
WHERE source_id=$1 AND source_incarnation=$2::uuid AND pack_id=$3`, [skill.source_id, skill.source_incarnation, skill.pack_id]);
- if (!stored) throw new OperationError('catalog_unavailable', 'A canonical pack changed during enumeration.');
+ if (!stored) {
+ throw new OperationError('catalog_unavailable', 'A canonical pack changed during enumeration.',
+ `Pack ${skill.pack_id} on source ${skill.source_id} was republished while the list was being built; list the packs again.`);
+ }
pack = { source_id: skill.source_id, name: skill.pack_id, version: typeof stored.manifest.version === 'string' ? stored.manifest.version : '0.0.0',
schema_pack: typeof stored.manifest.schema_pack === 'string' ? stored.manifest.schema_pack : null,
active_schema_pack: null, schema_pack_match: null, skills: [], scaffold_spec: null, installed: false };
diff --git a/src/core/shared-skills/membership-authority.ts b/src/core/shared-skills/membership-authority.ts
index 04850eabfb..5bb23990a0 100644
--- a/src/core/shared-skills/membership-authority.ts
+++ b/src/core/shared-skills/membership-authority.ts
@@ -7,7 +7,10 @@ import { normalizeTokenScopes } from '../legacy-token-scope.ts';
import { authSourcesFromGrant, grantFromTokenRow } from '../grants/model.ts';
import { hasScope } from '../scope.ts';
-const deny = (): never => { throw new OperationError('permission_denied', 'An intact, current skills_member_self grant and explicit operation approval are required. Membership grants no other authority.'); };
+const deny = (): never => {
+ throw new OperationError('permission_denied', 'An intact, current skills_member_self grant and explicit operation approval are required. Membership grants no other authority.',
+ 'Ask the brain host\'s operator to grant this connection the skills_member_self scope and the membership operation it calls, then reconnect; nothing was enrolled or changed.');
+};
export async function memberAuthority(ctx: OperationContext, operation: string): Promise<{ principal: Principal; digest: string; ctx: OperationContext }> {
const auth = ctx.auth;
diff --git a/src/core/shared-skills/migration-projection.ts b/src/core/shared-skills/migration-projection.ts
index 7790d146ad..e443ddca41 100644
--- a/src/core/shared-skills/migration-projection.ts
+++ b/src/core/shared-skills/migration-projection.ts
@@ -63,7 +63,10 @@ export async function assertExportProjectionRoundtrip(engine: BrainEngine, page:
if (!take || !base) { conflicts.push(`takes row ${stored.row_num}: missing canonical row`); continue; }
let resolution: ReturnType<typeof deriveResolutionTuple> | null = null;
if (take.resolvedQuality !== undefined) {
- if (!take.resolvedBy) throw new OperationError('unsupported_export_data', `Canonical takes row ${take.rowNum} has a resolution without resolved_by. Restore the recorded resolver in the fence before export; no identity was inferred.`);
+ if (!take.resolvedBy) {
+ throw new OperationError('unsupported_export_data', `Canonical takes row ${take.rowNum} has a resolution without resolved_by. Restore the recorded resolver in the fence before export; no identity was inferred.`,
+ `Add the resolver to takes row ${take.rowNum}'s resolved_by column, then preview the export again; gbrain never guesses who resolved a take.`);
+ }
resolution = deriveResolutionTuple({ quality: take.resolvedQuality, resolvedBy: take.resolvedBy });
}
const expected: Row = { ...base, resolved_at: take.resolvedAt ?? null, resolved_quality: resolution?.quality ?? null,
@@ -74,5 +77,8 @@ export async function assertExportProjectionRoundtrip(engine: BrainEngine, page:
if (changed.length) conflicts.push(`takes row ${take.rowNum}: ${changed.join(', ')}`);
}
for (const take of takes) if (!storedTakes.some(row => row.row_num === take.rowNum)) conflicts.push(`takes row ${take.rowNum}: would insert a missing database row`);
- if (conflicts.length) throw new OperationError('unsupported_export_data', `Canonical projection would change database fields (${conflicts.slice(0, 20).join('; ')}${conflicts.length > 20 ? '; additional rows differ' : ''}). Reconcile the source fences before export; no rows or files were changed.`);
+ if (conflicts.length) {
+ throw new OperationError('unsupported_export_data', `Canonical projection would change database fields (${conflicts.slice(0, 20).join('; ')}${conflicts.length > 20 ? '; additional rows differ' : ''}). Reconcile the source fences before export; no rows or files were changed.`,
+ 'Make the page\'s Facts and Takes fences match the stored rows listed in the message (or leave the page database-only), then preview the export again.');
+ }
}
diff --git a/src/core/shared-skills/setup-source-policy.ts b/src/core/shared-skills/setup-source-policy.ts
index 0a1ed7fa2a..a26beac5d8 100644
--- a/src/core/shared-skills/setup-source-policy.ts
+++ b/src/core/shared-skills/setup-source-policy.ts
@@ -12,7 +12,10 @@ export async function sharedSkillSourcePolicy(engine: BrainEngine, sourceId: str
if (company?.noWriteback) return { mode: 'preserve_files',
reason: 'source_writeback_required: the approved company-brain ingestion contract is file-preserving (noWriteback:true). Shared-skill setup cannot modify this repository, even if it contains a pack. Use a separately authorized content source; ingestion approval, files and grants remain unchanged.' };
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.');
+ if (!source) {
+ throw new OperationError('source_changed', 'The selected content source is missing or archived.',
+ `Source ${sourceId} is archived or not registered; choose an active content source (gbrain sources list --json shows them).`);
+ }
const config = parseSourceConfig(source.config);
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.' };
@@ -23,5 +26,8 @@ export async function sharedSkillSourcePolicy(engine: BrainEngine, sourceId: str
export async function assertPackagedSkillSource(engine: BrainEngine, sourceId: string): Promise<void> {
const policy = await sharedSkillSourcePolicy(engine, sourceId);
- if (policy.mode !== 'content') throw new OperationError('source_writeback_required', policy.reason);
+ if (policy.mode !== 'content') {
+ throw new OperationError('source_writeback_required', policy.reason,
+ `Source ${sourceId} is not a shared-skill write target, so nothing was added to it. Install packaged skills into a separate content source the user owns (gbrain init --content-root with a new directory creates one).`);
+ }
}
diff --git a/src/core/skillpack/writer-guard.ts b/src/core/skillpack/writer-guard.ts
index 5679621e3d..e34eac8d56 100644
--- a/src/core/skillpack/writer-guard.ts
+++ b/src/core/skillpack/writer-guard.ts
@@ -41,7 +41,8 @@ function resolveExistingAncestor(path: string): string {
}
export function confinedSkillChildWrite(root: string, child: string, opts: { dryRun?: boolean } = {}): string {
- const invalid = () => new OperationError('target_escape', 'The skill target must remain within its selected root.');
+ const invalid = () => new OperationError('target_escape', 'The skill target must remain within its selected root.',
+ `Write to a relative path under ${root} with forward slashes and no empty, . or .. segments; absolute and drive-letter paths are refused.`);
if (typeof root !== 'string' || !root || root.includes('\0') || typeof child !== 'string' || !child ||
/[\x00-\x1f\x7f]/.test(child) || isAbsolute(child) || win32.isAbsolute(child) || /^[a-z]:/i.test(child) ||
sep !== '\\' && child.includes('\\')) throw invalid();