Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(code-intel): the remote code-read suspension names its follow-up and the search that still works (#5052)
time-attack690f58603a22
diff --git a/src/core/ops/code-intel.ts b/src/core/ops/code-intel.tsindex 50332b8754..693cd270cc 100644--- a/src/core/ops/code-intel.ts+++ b/src/core/ops/code-intel.ts@@ -314,18 +314,21 @@ const SYMBOL_ARG = /^[A-Za-z_$][\w$.:/-]{0,199}$/;* trusted local `gbrain call` lane on the brain host. The symbol and source* are interpolated only when they match strict id shapes.*/+const CODE_READ_FOLLOW_UP = 'garrytan/gbrain#5052';+function codeReadRefusal(ctx: OperationContext, op: Operation, params: Record<string, unknown>): OperationError {- const message = `${op.name} is temporarily unavailable to agent callers. Use the trusted local CLI for code reads.`;+ const message = `${op.name} is temporarily unavailable to agent callers: remote code reads stay suspended until they support the remote read policy (follow-up: ${CODE_READ_FOLLOW_UP}). `+ + 'Code search (search, query) still works here.';const key = 'entry_point' in op.params ? 'entry_point' : 'symbol';const symbol = params[key];if (typeof symbol !== 'string' || !SYMBOL_ARG.test(symbol)) {return opError('permission_denied', message,- `Code reads over MCP are suspended; ask the user to run ${op.name} with the trusted local CLI on the brain host (gbrain call ${op.name}).`);+ `Use search or query for code text now, or ask the user to run ${op.name} with the trusted local CLI on the brain host (gbrain call ${op.name} '<params_json>').`);}const source = typeof params.source_id === 'string' && isValidSourceId(params.source_id) ? ['--source', params.source_id] : [];return hostOnlyError(ctx, 'permission_denied', message,['gbrain', 'call', ...source, op.name, JSON.stringify({ [key]: symbol })],- 'Raw code fragments do not yet support the remote read policy, so code reads run only through the trusted local CLI on the brain host.');+ `Symbol definitions, references, callers, callees, blast radius and flow run only through the trusted local CLI on the brain host until remote code reads return (${CODE_READ_FOLLOW_UP}).`);}const codeReadOperations: Operation[] = [diff --git a/test/code-intel-remote-suspension-message.test.ts b/test/code-intel-remote-suspension-message.test.tsnew file mode 100644index 0000000000..b574f21298--- /dev/null+++ b/test/code-intel-remote-suspension-message.test.ts@@ -0,0 +1,50 @@+/**+ * #5052 (kept suspended): every remote code read is refused with an error+ * that names the follow-up and the code search that still works, while the+ * trusted local CLI keeps the read. Authoring gate: (1) protects the refusal+ * text and fix for all six code-read ops on stdio and HTTP and the local+ * lane; (2) fails when a refusal stops naming the follow-up or the local+ * read starts refusing; (3) code-intel-source-scope pins the suspension+ * itself, not what it tells the agent; (4) no production seam.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { operationsByName, type OperationContext } from '../src/core/operations.ts';+import { OperationError } from '../src/core/ops/contract.ts';+import { dispatchToolCall } from '../src/mcp/dispatch.ts';++const CODE_READS = ['code_callers', 'code_callees', 'code_def', 'code_refs', 'code_blast', 'code_flow'] as const;+let engine: PGLiteEngine;+beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); }, 60_000);+afterAll(async () => { await engine.disconnect(); });++const ctxOf = (overrides: Partial<OperationContext>): OperationContext => ({+ engine, config: {} as never, logger: { info() {}, warn() {}, error() {} } as never, dryRun: false, remote: true, transport: 'stdio', ...overrides,+} as OperationContext);+const paramsFor = (name: string) => ('entry_point' in operationsByName[name]!.params ? { entry_point: 'exampleFn' } : { symbol: 'exampleFn' });++describe('remote code reads stay suspended with a useful refusal', () => {+ for (const name of CODE_READS) {+ for (const transport of ['stdio', 'http'] as const) {+ test(`${name} over ${transport}`, async () => {+ let thrown: unknown;+ try { await operationsByName[name]!.handler(ctxOf({ transport }), paramsFor(name)); } catch (e) { thrown = e; }+ expect(thrown).toBeInstanceOf(OperationError);+ const error = thrown as OperationError;+ expect(error.code).toBe('permission_denied');+ expect(error.message).toContain('remote code reads stay suspended');+ expect(error.message).toContain('garrytan/gbrain#5052');+ expect(error.message).toContain('Code search (search, query) still works here.');+ expect(JSON.stringify(error.toJSON())).toContain(`"gbrain","call","${name}"`);+ });+ }+ test(`${name} through MCP stdio dispatch`, async () => {+ const result = await dispatchToolCall(engine, name, paramsFor(name), { remote: true, transport: 'stdio', sourceId: 'default' });+ expect(result.isError).toBe(true);+ expect(result.content[0]!.text).toContain('garrytan/gbrain#5052');+ });+ test(`${name} on the trusted local CLI still runs`, async () => {+ await expect(operationsByName[name]!.handler(ctxOf({ remote: false, transport: undefined }), paramsFor(name))).resolves.toBeDefined();+ });+ }+});