Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: admin smoke no longer inherits the runner's database or hangs on failure; recorded-time get_page keeps refusing include_quarantined
garrytanc12a184c8b5a
diff --git a/scripts/native/compiled-admin-smoke.ts b/scripts/native/compiled-admin-smoke.tsindex 99a4603fa5..7488c7a902 100644--- a/scripts/native/compiled-admin-smoke.ts+++ b/scripts/native/compiled-admin-smoke.ts@@ -22,12 +22,26 @@ const port = await new Promise<number>((done, fail) => {});const home = mkdtempSync(join(tmpdir(), 'gbrain-admin-smoke-'));mkdirSync(join(home, '.gbrain', 'brain.pglite'), { recursive: true });+mkdirSync(join(home, 'tmp'));writeFileSync(join(home, '.gbrain', 'config.json'), `${JSON.stringify({ engine: 'pglite', database_path: join(home, '.gbrain', 'brain.pglite'), embedding_dimensions: 1536 })}\n`);-const server = Bun.spawn([binary, 'serve', '--http', '--port', String(port), '--bind', '127.0.0.1'], {- cwd: home,- env: { ...process.env, HOME: home, GBRAIN_HOME: home, GBRAIN_SKIP_STARTUP_HOOKS: '1', GBRAIN_ADMIN_BOOTSTRAP_TOKEN: 'admin-smoke-bootstrap-token-aaaaaaaaaaaa', OPENAI_API_KEY: '', ANTHROPIC_API_KEY: '' },- stdout: 'pipe', stderr: 'pipe',-});+const env: Record<string, string> = {+ PATH: process.env.PATH ?? '/usr/bin:/bin',+ HOME: home, USERPROFILE: home, GBRAIN_HOME: home,+ XDG_CONFIG_HOME: join(home, 'config'), XDG_CACHE_HOME: join(home, 'cache'), XDG_STATE_HOME: join(home, 'state'),+ TMPDIR: join(home, 'tmp'), TMP: join(home, 'tmp'), TEMP: join(home, 'tmp'),+ LANG: 'C.UTF-8', LC_ALL: 'C',+ GBRAIN_NO_BANNER: '1', GBRAIN_SKIP_STARTUP_HOOKS: '1', GBRAIN_BACKUP_CHECK: '0', GBRAIN_SWEEP: '0',+ GBRAIN_ADMIN_BOOTSTRAP_TOKEN: 'admin-smoke-bootstrap-token-aaaaaaaaaaaa',+};+// Never spread process.env: an inherited GBRAIN_DATABASE_URL or DATABASE_URL outranks config.json, and this server opens /admin with a public token.+for (const name of ['SystemRoot', 'WINDIR', 'ComSpec']) if (process.env[name]) env[name] = process.env[name]!;+const server = Bun.spawn([binary, 'serve', '--http', '--port', String(port), '--bind', '127.0.0.1'], { cwd: home, env, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' });+let output = '';+const drain = async (stream: ReadableStream<Uint8Array>) => {+ const decoder = new TextDecoder();+ for await (const part of stream) output = (output + decoder.decode(part, { stream: true })).slice(-4000);+};+void Promise.all([drain(server.stdout), drain(server.stderr)]).catch(() => {});const base = `http://127.0.0.1:${port}`;try {const deadline = performance.now() + 60_000;@@ -36,20 +50,24 @@ try {ready = await fetch(`${base}/health`, { signal: AbortSignal.timeout(2000) }).then(r => r.ok, () => false);if (!ready) await Bun.sleep(250);}- if (!ready) throw new Error(`serve --http never answered /health (exit ${server.exitCode}): ${(await new Response(server.stderr).text().catch(() => '')).slice(0, 2000)}`);+ if (!ready) throw new Error(`serve --http never answered /health (exit ${server.exitCode}): ${output.slice(-2000)}`);const page = await fetch(`${base}/admin/`, { signal: AbortSignal.timeout(10_000) });const html = await page.text();if (page.status !== 200 || !/text\/html/.test(page.headers.get('content-type') ?? '') || !html.includes('<div id="root">')) {throw new Error(`/admin/ did not return the admin shell (status ${page.status}, ${page.headers.get('content-type')})`);}- const assets = [...html.matchAll(/<(script|link)\b[^>]*?\b(?:src|href)="(\/admin\/[^"]+)"/g)].map(([, tag, path]) => ({ tag: tag!, path: path! }));+ const assets = [...html.matchAll(/<(script|link)\b([^>]*)>/g)].flatMap(([, tag, attrs]) => {+ const path = /\b(?:src|href)="(\/admin\/[^"]+)"/.exec(attrs!)?.[1];+ const rel = /\brel="([^"]*)"/.exec(attrs!)?.[1] ?? '';+ const want = tag === 'script' || /\bmodulepreload\b/.test(rel) ? /javascript/ : /\bstylesheet\b/.test(rel) ? /css/ : /./;+ return path ? [{ tag: tag!, path, want }] : [];+ });if (!assets.some(a => a.tag === 'script')) throw new Error('/admin/ loads no same-origin script');- for (const { tag, path } of assets) {+ for (const { path, want } of assets) {const res = await fetch(`${base}${path}`, { signal: AbortSignal.timeout(10_000) });const body = await res.arrayBuffer();const type = res.headers.get('content-type') ?? '';- const want = tag === 'script' ? /javascript/ : /css/;if (res.status !== 200 || body.byteLength === 0 || !want.test(type)) throw new Error(`${path}: status ${res.status}, ${body.byteLength} bytes, ${type}`);}console.log(`Compiled admin smoke passed: /admin/ and ${assets.length} asset(s)`);diff --git a/src/core/ops/known-as-of.ts b/src/core/ops/known-as-of.tsindex a8e252e09c..f3f7779bea 100644--- a/src/core/ops/known-as-of.ts+++ b/src/core/ops/known-as-of.ts@@ -21,7 +21,7 @@ export const KNOWN_AS_OF_PARAM: ParamDef = { type: 'string', fullSurfaceOnly: trexport const VERSIONS_DIFF_PARAM: ParamDef = { type: 'boolean', actsWhenTrue: true, fullSurfaceOnly: true, description: 'With known_as_of: each version also carries a unified diff from the version before it.' };/** get_page parameters that select a body window, a fuzzy match or an edit view, none of which a historical read serves: a recorded-time read sets them aside and names them (GST-2214: GPT-6.1 Sol fills every one). */-const GET_PAGE_UNSUPPORTED = ['fuzzy', 'include_content', 'content_only', 'include_timeline_entries', 'grammar_diagnostics', 'include_quarantined',+const GET_PAGE_UNSUPPORTED = ['fuzzy', 'include_content', 'content_only', 'include_timeline_entries', 'grammar_diagnostics','lines', 'bytes', 'around_chunk_id', 'context_lines', 'cursor', 'max_bytes', 'view', 'outline_from', 'section', 'grep', 'context'] as const;/** The get_page arguments a recorded-time read serves; the refusal's fix keeps only these. */@@ -102,11 +102,13 @@ function ledgerView(read: PageAtTime) {/** `get_page {known_as_of}`: the page at the slug as recorded at the instant, with the interval it was in and whether the ledger certifies it. */export async function getPageKnownAsOf(ctx: OperationContext, p: Record<string, unknown>): Promise<Record<string, unknown>> {const at = parseKnownAsOf(p.known_as_of);- if (p.body !== undefined && p.body !== 'auto' && p.body !== 'full' && p.body !== 'none') {+ const badBody = p.body !== undefined && p.body !== 'auto' && p.body !== 'full' && p.body !== 'none';+ const drop = [...(p.include_quarantined === true ? ['include_quarantined'] : []), ...(badBody ? ['body'] : [])];+ if (drop.length) {const name = (k: string) => opTransport(ctx) === 'cli' ? `--${k.replace(/_/g, '-')}` : `\`${k}\``;- const kept = Object.fromEntries(GET_PAGE_AS_OF_ARGS.filter(k => p[k] !== undefined && k !== 'body').map(k => [k, p[k]]));- throw opError('invalid_params', `get_page: known_as_of does not combine with body: ${String(p.body)}.`,- `Drop ${name('body')} to read the page as recorded at known_as_of, or drop ${name('known_as_of')} for the current page. A recorded-time read takes only ${GET_PAGE_AS_OF_ARGS.slice(2).map(name).join(', ')} (auto, full or none).`,+ const kept = Object.fromEntries(GET_PAGE_AS_OF_ARGS.filter(k => p[k] !== undefined && !drop.includes(k)).map(k => [k, p[k]]));+ throw opError('invalid_params', `get_page: known_as_of does not combine with ${drop.map(k => k === 'body' ? `body: ${String(p.body)}` : k).join(' or ')}.`,+ `Drop ${drop.map(name).join(', ')} to read the page as recorded at known_as_of, or drop ${name('known_as_of')} for the current page. A recorded-time read takes only ${GET_PAGE_AS_OF_ARGS.slice(2).map(name).join(', ')} (auto, full or none).`,{ fix: readFix('The same call without the arguments that select a window or view of the current page, which a recorded-time read does not serve.',{ argv: ['gbrain', 'get', ...Object.entries(kept).filter(([k]) => k !== 'slug').flatMap(([k, v]) => v === true ? [`--${k.replace(/_/g, '-')}`] : v === false ? [] : [`--${k.replace(/_/g, '-')}`, String(v)]), '--', String(p.slug)],mcp: { tool: 'get_page', arguments: kept } }) });diff --git a/test/tool-args-empty-optional-sol.test.ts b/test/tool-args-empty-optional-sol.test.tsindex d184fd6669..0d1a4507a4 100644--- a/test/tool-args-empty-optional-sol.test.ts+++ b/test/tool-args-empty-optional-sol.test.ts@@ -355,6 +355,15 @@ describe("GST-927: GBEV-3's replayed Sol shapes", () => {expect(served as Record<string, unknown>).toEqual(plain);});+ test('GST-2214: a recorded-time read still refuses include_quarantined: true, which it would not honour', async () => {+ await enableBeliefLedger(engine, 'default');+ const at = new Date(Date.now() + 1000).toISOString();+ await Bun.sleep(1100);+ const out = await paths['mcp remote (http)']!('get_page', { slug: SLUG, known_as_of: at, include_quarantined: true, include_content: true });+ expect([out.ok, summary(out), out.text.includes('get_page: known_as_of does not combine with include_quarantined.')]).toEqual([false, 'invalid_params', true]);+ expect(out.text).not.toContain(BODY_MARKER);+ });+test('GST-2214: traverse_graph with hops beside depth, link_type and direction walks the chain on every entry point, naming what was set aside', async () => {const hops = [{ link_type: 'founded', toward: 'object' }];const results: Record<string, string> = {};