Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes (two-selector fix keeps declared get_page args and carries gbrain get argv)

garrytan2bf85cab3db2
diff --git a/src/core/ops/get-page-body.ts b/src/core/ops/get-page-body.ts
index 41ec7f5dd3..4e549a8ac1 100644
--- a/src/core/ops/get-page-body.ts
+++ b/src/core/ops/get-page-body.ts
@@ -99,6 +99,10 @@ export interface BodyRequest {
slice?: SliceRequest;
}
+/** The get_page arguments the two-selector refusal's fix keeps; anything else the caller sent (CLI-only keys, unknown keys) is left out. */
+const WINDOW_FIX_ARGS = ['slug', 'fuzzy', 'include_deleted', 'include_timeline_entries', 'grammar_diagnostics', 'source_id', 'include_quarantined', 'min_trust',
+ ...Object.keys(GET_PAGE_BODY_PARAMS)];
+
const SELECTOR_EXAMPLE = { slug: 'notes/acme-example-log', body: 'window', lines: { from: 1, count: 200 } };
function int(v: unknown): v is number { return typeof v === 'number' && Number.isSafeInteger(v); }
@@ -138,12 +142,17 @@ export function parseBodyRequest(ctx: Pick<OperationContext, 'remote' | 'transpo
if (selectors.length > 1) {
const [keep, ...drop]: string[] = selectors.map(s => s.kind === 'around' ? 'around_chunk_id' : s.kind);
const conflicts = ['include_content', 'content_only', ...(keep === 'around_chunk_id' && p.view === 'markdown' ? ['view'] : [])];
- const args = Object.fromEntries(Object.entries(p).filter(([k, v]) => v !== undefined && k !== '_meta' && !drop.includes(k) && !conflicts.includes(k)));
- const name = (k: string) => opTransport(ctx) === 'cli' ? `--${k.replace(/_/g, '-')}` : `\`${k}\``;
+ const args: Record<string, unknown> = Object.fromEntries(WINDOW_FIX_ARGS.filter(k => p[k] !== undefined && !drop.includes(k) && !conflicts.includes(k)).map(k => [k, p[k]]));
+ args.body = 'window';
+ const flag = (k: string) => `--${k.replace(/_/g, '-')}`;
+ const name = (k: string) => opTransport(ctx) === 'cli' ? flag(k) : `\`${k}\``;
+ const range = (k: string, v: Record<string, number>) => k === 'lines' ? `${v.from}-${v.from + v.count - 1}` : `${v.offset}-${v.offset + v.length - 1}`;
+ const argv = ['gbrain', 'get', ...Object.entries(args).filter(([k]) => k !== 'slug').flatMap(([k, v]) => v === true ? [flag(k)] : v === false ? []
+ : [flag(k), typeof v === 'object' && v ? range(k, v as Record<string, number>) : String(v)]), '--', String(p.slug)];
throw opError('invalid_params', `get_page: pass one window selector, not ${selectors.length} (got ${[keep, ...drop].join(' and ')}).`,
`Pass at most one window selector: lines, bytes, around_chunk_id or cursor. Drop ${drop.map(name).join(' and ')} to read the ${keep} window, or pass one of them alone to read there instead.`,
{ fix: readFix(`The same call with one window selector (${keep}) and body: "window"; ${[...drop, ...conflicts.filter(k => p[k] !== undefined)].join(', ')} dropped.`,
- { mcp: { tool: 'get_page', arguments: { ...args, body: 'window' } } }) });
+ { argv, mcp: { tool: 'get_page', arguments: args } }) });
}
const includeContent = p.include_content === true;
const contentOnly = p.content_only === true;
diff --git a/test/tool-args-empty-optional-sol.test.ts b/test/tool-args-empty-optional-sol.test.ts
index d46f5ae25e..78427877fb 100644
--- a/test/tool-args-empty-optional-sol.test.ts
+++ b/test/tool-args-empty-optional-sol.test.ts
@@ -290,6 +290,7 @@ describe("GST-927: GBEV-3's replayed Sol shapes", () => {
expect(Object.keys(fixed).filter(k => ['lines', 'bytes', 'around_chunk_id', 'cursor'].includes(k))).toEqual(['lines']);
expect(fixed).toMatchObject({ slug: SLUG, lines: { from: 1, count: 200 }, body: 'window', max_bytes: 40000, view: 'read', source_id: 'default' });
expect(fixed.include_content).toBeUndefined();
+ expect((local as { fix?: { argv?: string[] } } | null)?.fix?.argv).toEqual(['gbrain', 'get', '--source-id', 'default', '--body', 'window', '--lines', '1-200', '--context-lines', '20', '--max-bytes', '40000', '--view', 'read', '--outline-from', '0', '--', SLUG]);
const retried = await paths['mcp remote (http)']!('get_page', fixed);
expect([retried.ok, retried.text.includes(BODY_MARKER)]).toEqual([true, true]);
});
@@ -328,3 +329,22 @@ test('GST-927: the absence annotations sit only on optional params of read ops,
.map(([k]) => `${op.name}.${k}`));
expect(misplaced).toEqual([]);
});
+
+describe('GST-927: refusal fixes keep only arguments the target read takes', () => {
+ const fixOf = (args: Record<string, unknown>) => handleToolCall(engine, 'get_page', args).then(() => null,
+ (e: { message?: string; suggestion?: string; fix?: { argv?: string[]; mcp?: { arguments: Record<string, unknown> } } }) => e);
+
+ test('two selectors: the fix drops undeclared keys, and around_chunk_id kept first drops view: markdown', async () => {
+ const e = await fixOf({ slug: SLUG, around_chunk_id: 3, cursor: 'gpw1.x', view: 'markdown', json: true, stray: 'x' });
+ expect(e?.message).toContain('pass one window selector, not 2 (got around_chunk_id and cursor)');
+ expect(e?.fix?.mcp?.arguments).toEqual({ slug: SLUG, around_chunk_id: 3, body: 'window' });
+ expect(e?.fix?.argv).toEqual(['gbrain', 'get', '--around-chunk-id', '3', '--body', 'window', '--', SLUG]);
+ });
+
+ test('known_as_of with body: window names body to drop, and the fix leaves body out', async () => {
+ const e = await fixOf({ slug: SLUG, known_as_of: '2026-10-01T12:00:00Z', body: 'window' });
+ expect(e?.message).toContain('known_as_of does not combine with body: window');
+ expect(e?.suggestion).toContain('Drop --body to read the page as recorded');
+ expect(e?.fix?.mcp?.arguments).toEqual({ slug: SLUG, known_as_of: '2026-10-01T12:00:00Z' });
+ });
+});