Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: adversarial review fix (the {} absence rule applies only to read ops, so edit_page within: {} still refuses)
garrytanc6219212e2e8
diff --git a/src/mcp/validate-params.ts b/src/mcp/validate-params.tsindex 01d8d5bfde..504db54980 100644--- a/src/mcp/validate-params.ts+++ b/src/mcp/validate-params.ts@@ -144,7 +144,7 @@ export function normalizeOptionalParams(op: Operation, params: Record<string, undelete out[key];};for (const [key, def] of Object.entries(op.params)) {- if (!def.required && isAbsentValue(def, params[key])) drop(key);+ if (!def.required && isAbsentValue(op, def, params[key])) drop(key);}for (const [key, def] of Object.entries(op.params)) {const current = out ?? params;@@ -156,16 +156,16 @@ export function normalizeOptionalParams(op: Operation, params: Record<string, un/*** GST-927: a value that can only mean "not provided" for this param's schema. `null` anywhere and `''` on a string* (GST-923), plus the empty values GPT-style callers fill in that the schema rules out: 0 below a numeric range that- * excludes it, `[]` where the list must be non-empty, `{}` where the object requires a member, and `false` on a+ * excludes it, `[]` where the list must be non-empty, `{}` where a read op's object requires a member, and `false` on a* flag that acts only when true. Every other value, including any value inside the valid range, is kept.*/-function isAbsentValue(def: Operation['params'][string], val: unknown): boolean {+function isAbsentValue(op: Operation, def: Operation['params'][string], val: unknown): boolean {if (val === null) return true;if (val === '') return def.type === 'string';if (val === 0) return (def.minimum ?? 0) > 0 || (def.exclusiveMinimum ?? -1) >= 0;if (val === false) return def.actsWhenTrue === true;if (Array.isArray(val)) return val.length === 0 && (def.minItems ?? 0) >= 1;- if (typeof val === 'object' && def.type === 'object') {+ if (typeof val === 'object' && def.type === 'object' && op.mutating === false) {return Object.keys(val as object).length === 0 && Object.values(def.properties ?? {}).some(member => member.required);}return false;diff --git a/test/tool-args-empty-optional-sol.test.ts b/test/tool-args-empty-optional-sol.test.tsindex 78427877fb..eabec3e707 100644--- a/test/tool-args-empty-optional-sol.test.ts+++ b/test/tool-args-empty-optional-sol.test.ts@@ -18,7 +18,7 @@*/import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { PGLiteEngine } from '../src/core/pglite-engine.ts';-import { dispatchToolCall } from '../src/mcp/dispatch.ts';+import { dispatchToolCall, normalizeOptionalParams } from '../src/mcp/dispatch.ts';import { handleToolCall } from '../src/mcp/server.ts';import { runRollout } from '../src/core/skillopt/rollout.ts';import { buildWriteCaptureRegistry } from '../src/core/skillopt/write-capture.ts';@@ -348,3 +348,19 @@ describe('GST-927: refusal fixes keep only arguments the target read takes', ()expect(e?.fix?.mcp?.arguments).toEqual({ slug: SLUG, known_as_of: '2026-10-01T12:00:00Z' });});});++test('GST-927: normalization drops no schema-empty value (0, [], {}, false) from a write op', () => {+ const dropped = operations.filter(op => op.mutating !== false).flatMap(op => Object.entries(op.params)+ .filter(([, d]) => !d.required)+ .flatMap(([k]) => [0, [], {}, false].filter(v => !(k in normalizeOptionalParams(op, { [k]: v }))).map(v => `${op.name}.${k}=${JSON.stringify(v)}`)));+ expect(dropped).toEqual([]);+});++test('GST-927: edit_page within: {} still refuses instead of editing the whole page', async () => {+ const opts = { remote: true, transport: 'http', sourceId: 'default' } as const;+ const page = JSON.parse(fromDispatch(await dispatchToolCall(engine, 'get_page', { slug: SLUG, include_content: true }, opts)).text);+ const e = fromDispatch(await dispatchToolCall(engine, 'edit_page', { slug: SLUG, expected_revision: page.revision, edits: [{ old_text: BODY_MARKER, new_text: 'replaced' }], within: {} }, opts));+ expect(e.ok).toBe(false);+ expect(e.text).toContain('edit_invalid');+});+