Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(harness): shared-skills installer and capability verifier parse a tool result's body, not its notice blocks

time-attack85714be54721
diff --git a/src/core/connect-probe.ts b/src/core/connect-probe.ts
index 376e0b7d7e..a015e61e18 100644
--- a/src/core/connect-probe.ts
+++ b/src/core/connect-probe.ts
@@ -75,6 +75,16 @@ export function extractResultText(content: unknown): string {
.join('\n');
}
+/**
+ * The structured body of a tool result: content[0] only. Servers append notice
+ * blocks (`[gbrain notice ...]`) after it, so joining every block (as
+ * extractResultText does for display) is not parseable JSON.
+ */
+export function resultBodyText(content: unknown): string {
+ const first = Array.isArray(content) ? content[0] as { text?: unknown } | undefined : undefined;
+ return typeof first?.text === 'string' ? first.text : '';
+}
+
const DEFAULT_DEPS: ProbeDeps = {
connectAndCall: async (mcpUrl, token, signal) => {
const transport = new StreamableHTTPClientTransport(new URL(mcpUrl), {
diff --git a/src/core/harness/shared-skills.ts b/src/core/harness/shared-skills.ts
index 6405ee776c..c671080604 100644
--- a/src/core/harness/shared-skills.ts
+++ b/src/core/harness/shared-skills.ts
@@ -4,7 +4,7 @@ import { join } from 'node:path';
import { existsSync } from 'node:fs';
import { createSharedSkillsAdapter, type SharedSkillsToolCaller } from '../shared-skills/adapter.ts';
import { credentialAccessToken, type HarnessCredentials } from './credentials.ts';
-import { extractResultText } from '../connect-probe.ts';
+import { resultBodyText } from '../connect-probe.ts';
import { OperationError } from '../ops/contract.ts';
import { nativeSharedSkillsDirectory } from './native-router.ts';
@@ -39,7 +39,7 @@ export async function installSharedSkillsConnection(credentials: HarnessCredenti
await client.connect(transport);
}
const result = await client.callTool({ name, arguments: params }, undefined, { timeout: 30_000 });
- const text = extractResultText(result.content);
+ const text = resultBodyText(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.',
diff --git a/src/core/harness/verify.ts b/src/core/harness/verify.ts
index a341ed552a..071efcb77b 100644
--- a/src/core/harness/verify.ts
+++ b/src/core/harness/verify.ts
@@ -2,7 +2,7 @@ import { randomBytes, randomUUID } from 'node:crypto';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { credentialAccessToken, type HarnessCredentials } from './credentials.ts';
-import { extractResultText } from '../connect-probe.ts';
+import { resultBodyText } from '../connect-probe.ts';
import { shellQuote } from '../mcp-registration.ts';
export interface VerificationStage { name: string; status: 'passed' | 'failed' | 'unverified' | 'not_requested'; reason?: string }
@@ -18,7 +18,7 @@ async function createPeer(c: HarnessCredentials, signal: AbortSignal, timeout: n
call: async (name, args) => {
const result = await client.callTool({ name, arguments: args }, undefined, { signal, timeout });
if (result.isError) throw new Error('tool_error');
- return JSON.parse(extractResultText(result.content));
+ return JSON.parse(resultBodyText(result.content));
},
readCapabilities: async () => {
const result = await client.readResource({ uri: 'gbrain://capabilities' }, { signal, timeout });
diff --git a/test/harness-shared-skills-notice-block.test.ts b/test/harness-shared-skills-notice-block.test.ts
new file mode 100644
index 0000000000..0a5070f054
--- /dev/null
+++ b/test/harness-shared-skills-notice-block.test.ts
@@ -0,0 +1,44 @@
+/**
+ * The shared-skills installer and the capability verifier parse a tool
+ * result's structured body (content[0]) only. A host that predates the
+ * running release appends a one-time `behavior_changes` notice block to each
+ * HTTP client's first call; joining every block made `join_brain`'s answer
+ * unparseable and the installer reported `shared_skills_unsupported`.
+ *
+ * Protects: install over HTTP against an upgraded (older than an hour) brain
+ * still reaches `restart_required`, while the notice is really delivered to
+ * that client. Regression it catches: parsing the joined content blocks.
+ */
+import { expect, test } from 'bun:test';
+import { join } from 'node:path';
+import { randomUUID } from 'node:crypto';
+import { withTransportFixture } from './fixtures/shared-skills-transports.ts';
+import { writeCredentials, type HarnessCredentials } from '../src/core/harness/credentials.ts';
+import { installSharedSkillsConnection } from '../src/core/harness/shared-skills.ts';
+import { HTTP_SHOWN_KEY } from '../src/core/behavior-change-notice.ts';
+import { resultBodyText } from '../src/core/connect-probe.ts';
+
+test('resultBodyText reads content[0] and ignores appended notice blocks', () => {
+ expect(resultBodyText([{ type: 'text', text: '{"ok":true}' }, { type: 'text', text: '[gbrain notice behavior_changes kind=safety]\nwhy: ...' }])).toBe('{"ok":true}');
+ expect(resultBodyText([])).toBe('');
+ expect(resultBodyText(undefined)).toBe('');
+});
+
+test('installing shared skills on an upgraded brain survives the one-time behavior_changes notice', async () => {
+ await withTransportFixture(async f => {
+ await f.seed();
+ await f.engine.transaction(async tx => {
+ await tx.executeRaw("SELECT set_config('gbrain.topology_change','on',true)");
+ await tx.executeRaw("UPDATE sources SET created_at = now() - interval '2 hours'");
+ });
+ const peer = f.peers.reader;
+ const root = join(f.dir, 'gbrain-home', 'bootstrap', 'shared-skills', 'codex', randomUUID());
+ const credentials: HarnessCredentials = { version: 1, mcp_url: f.url, issuer_url: f.url.replace(/\/mcp$/, ''),
+ client_id: peer.id, access_token: peer.token, shared_skills: { follow: true } };
+ writeCredentials(join(root, 'credentials.json'), credentials);
+ const installed = await installSharedSkillsConnection(credentials, { harness: 'codex', root, name: 'gbrain', nativeSkillsDir: join(f.dir, 'codex-skills') });
+ expect(installed.status).toBe('restart_required');
+ const shown = JSON.parse((await f.engine.getConfig(HTTP_SHOWN_KEY)) ?? '{"clients":{}}') as { clients: Record<string, string> };
+ expect(Object.keys(shown.clients)).toContain(peer.id);
+ });
+}, 120_000);