Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge origin/master into p8-own-gaps (#6025 remote bulk writes; remember.replaces and forget.semantic_review are full-surface params so the starter list stays within 25,000 characters)

garrytan82932b856631
diff --cc src/core/persistence/effects.ts
index 804e16d858,97ab4c282f..2db352d2e4
--- a/src/core/persistence/effects.ts
+++ b/src/core/persistence/effects.ts
@@@ -516,9 -516,9 +517,10 @@@ export async function runPersistenceEff
effect = await upgradeWithdrawalEffect(engine, effect, opts.hostId);
if (effect.kind === 'withdrawal-mirror') await mirrorPage(engine, effect, binding, opts, attempt);
else if (effect.kind === 'git') await gitPage(engine, effect, binding, opts, attempt, hardened);
- else if (effect.kind === 'facts-backstop') await dispatchFactsBackstopEffect(engine, effect, opts.hostId);
- else if (effect.kind === 'links') await runLinksEffect(engine, effect, opts.hostId);
- else await embedPage(engine, config, effect, opts);
+ else await withAIAttribution({ request_id: effect.request_id, effect: effect.kind }, () => effect.kind === 'facts-backstop'
+ ? dispatchFactsBackstopEffect(engine, effect, opts.hostId)
- : embedPage(engine, config, effect, opts));
++ : effect.kind === 'links' ? runLinksEffect(engine, effect, opts.hostId)
++ : embedPage(engine, config, effect, opts));
} catch (error) { await recordFailure(engine, effect, error, opts.signal, attempt.target); }
finally { await lock?.release(); }
};
diff --cc src/core/verbs.ts
index 91d7315b58,f1a3634946..e0306cb7dd
--- a/src/core/verbs.ts
+++ b/src/core/verbs.ts
@@@ -92,7 -92,6 +92,7 @@@ const remember: Operation =
enum: ['world', 'private'],
description: 'world (default) or private (local CLI only).',
},
- replaces: { type: 'string', description: 'fact_id this fact replaces (same entity).' },
++ replaces: { type: 'string', description: 'fact_id this fact replaces (same entity).', fullSurfaceOnly: true },
},
mutating: true,
scope: 'write',
@@@ -367,7 -357,6 +367,7 @@@ const forget: Operation =
request_id: WRITE_REQUEST_PARAM,
id: { type: 'string', required: true, description: 'fact_id from remember or recall.' },
reason: { type: 'string', description: 'Audit note (default "forgotten").' },
- semantic_review: { type: 'boolean', description: 'false: skip overnight rewording review.' },
++ semantic_review: { type: 'boolean', description: 'false: skip overnight rewording review.', fullSurfaceOnly: true },
},
mutating: true,
scope: 'write',
diff --cc test/fixtures/goldens/cli/tools-json.json
index c57ed90793,2fbdc0c446..cafb08cda3
--- a/test/fixtures/goldens/cli/tools-json.json
+++ b/test/fixtures/goldens/cli/tools-json.json
@@@ -2,8 -2,8 +2,8 @@@
"golden": {
"exitCode": 0,
"stderr": "",
- "stdoutBytes": 200661,
- "stdoutSha256": "66ad32bb146efc0c21ccd010369c9fc73582aa46e00d76b4c9400578bce9804f",
- "stdoutBytes": 203001,
- "stdoutSha256": "1c7a6e9584099345f3d0f2ef2756bce55121ef709144cc7e60a78ec9ee6c6e0d",
++ "stdoutBytes": 203333,
++ "stdoutSha256": "d72973b500ff9c0c60d99ba97eaef520b3aaa4da77173d559b66ac17228cf1e2",
"toolNames": [
"remember",
"entity",
diff --cc test/remote-graph-freshness.test.ts
index 0000000000,0000000000..a7af07c84f
new file mode 100644
--- /dev/null
+++ b/test/remote-graph-freshness.test.ts
@@@ -1,0 -1,0 +1,131 @@@
++/**
++ * Graph freshness after a remote (OAuth) put_page, measured end to end on
++ * PGLite: what is queryable at commit, what the post-commit `links` effect
++ * adds, and what the extract phase adds. Report-only for P8: it pins the
++ * order of arrival and prints the time to each stage.
++ *
++ * at commit the page and its dated timeline row; no links yet
++ * links effect plain `mentions` edges to visible same-source pages
++ * extract phase typed edges (works_at) from the prose; the untrusted
++ * remote write never produces them before extract runs
++ *
++ * `mcp.remote_auto_links=false` leaves the effect off; extract still runs.
++ */
++import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
++import { randomUUID } from 'node:crypto';
++import { mkdtempSync, rmSync } from 'node:fs';
++import { tmpdir } from 'node:os';
++import { join } from 'node:path';
++import { PGLiteEngine } from '../src/core/pglite-engine.ts';
++import type { OperationContext } from '../src/core/ops/contract.ts';
++import { submissionAuthority } from '../src/core/persistence/authority.ts';
++import { admitWrite, claimNextWrite } from '../src/core/persistence/journal.ts';
++import { localHostId, registerLocalWriter } from '../src/core/persistence/identity.ts';
++import { preparePageMutation } from '../src/core/persistence/page-prepare.ts';
++import { publishMutation } from '../src/core/persistence/coordinator.ts';
++import { runPersistenceEffects } from '../src/core/persistence/effects.ts';
++import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
++import { runCycle } from '../src/core/cycle.ts';
++import { withEnv } from './helpers/with-env.ts';
++
++const config = { engine: 'pglite' as const, embedding_disabled: true };
++const SOURCE = 'freshness';
++const CLIENT = 'client-freshness';
++let engine: PGLiteEngine;
++let home: string;
++
++const BODY = `---
++type: note
++title: Freshness example
++---
++
++Met [[people/alice-example]] today. Alice works at [[companies/acme-example]] as head of research.
++
++## Timeline
++
++- **2026-09-14** | meeting — Alice joined [[companies/acme-example]].
++`;
++
++beforeAll(async () => {
++ home = mkdtempSync(join(tmpdir(), 'gbrain-freshness-'));
++ engine = new PGLiteEngine();
++ await engine.connect({});
++ await engine.initSchema();
++ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
++ await engine.executeRaw('INSERT INTO sources(id,name) VALUES($1,$1)', [SOURCE]);
++ for (const [slug, type] of [['people/alice-example', 'person'], ['companies/acme-example', 'company']] as const) {
++ await engine.putPage(slug, { type, title: slug, compiled_truth: `${slug} fixture.`, timeline: '', frontmatter: {} }, { sourceId: SOURCE });
++ }
++ await engine.executeRaw(`INSERT INTO oauth_clients(client_id,client_secret_hash,client_name,scope,source_id) VALUES($1,'fixture-hash','freshness-client','read write',$2)`, [CLIENT, SOURCE]);
++}, 120_000);
++
++afterAll(async () => {
++ await disposePersistenceConsumer(engine);
++ await engine.disconnect();
++ rmSync(home, { recursive: true, force: true });
++});
++
++async function remoteWrite(slug: string, content: string) {
++ return withEnv({ GBRAIN_HOME: home }, async () => {
++ await registerLocalWriter(engine, 'cli');
++ const [source] = await engine.executeRaw<{ incarnation: string }>('SELECT incarnation FROM sources WHERE id=$1', [SOURCE]);
++ const ctx: OperationContext = { engine, config, dryRun: false, remote: true, sourceId: SOURCE, logger: { info() {}, warn() {}, error() {} },
++ auth: { token: 'fixture', clientId: CLIENT, principal: { kind: 'oauth_client', id: CLIENT }, scopes: ['read', 'write'], sourceId: SOURCE } as OperationContext['auth'] };
++ const authority = await submissionAuthority(ctx, 'put_page', SOURCE, source!.incarnation, slug);
++ await admitWrite(engine, { principal: authority.principal, authority, operation: 'put_page', sourceId: SOURCE, sourceIncarnation: source!.incarnation,
++ slug, pageId: null, requestId: randomUUID(), callerIntent: { content }, intent: { content } });
++ const row = (await claimNextWrite(engine, localHostId()))!;
++ const committed = await publishMutation(engine, row, await preparePageMutation(engine, row, config));
++ expect(committed.state).toBe('committed');
++ return committed;
++ });
++}
++
++/** Run the effect worker until no effect is queued (each pass takes a bounded batch). */
++async function drainEffects() {
++ for (let i = 0; i < 10; i++) {
++ await withEnv({ GBRAIN_HOME: home }, () => runPersistenceEffects(engine, config, { hostId: localHostId() }));
++ const [q] = await engine.executeRaw<{ n: number }>("SELECT count(*)::int AS n FROM persistence_effects WHERE state='queued'");
++ if (!q || q.n === 0) return;
++ }
++}
++
++const edges = (from: string) => engine.executeRaw<{ to_slug: string; link_type: string }>(`SELECT t.slug AS to_slug, l.link_type
++ FROM links l JOIN pages f ON f.id=l.from_page_id JOIN pages t ON t.id=l.to_page_id WHERE f.source_id=$1 AND f.slug=$2 ORDER BY t.slug, l.link_type`, [SOURCE, from]);
++const timelineRows = (slug: string) => engine.executeRaw<{ date: string }>(`SELECT t.date::text AS date FROM timeline_entries t JOIN pages p ON p.id=t.page_id
++ WHERE p.source_id=$1 AND p.slug=$2`, [SOURCE, slug]);
++
++describe('remote put_page graph freshness', () => {
++ test('commit, then mention links from the effect, then typed edges from extract', async () => {
++ const t0 = Date.now();
++ await remoteWrite('notes/freshness-example', BODY);
++ const commitMs = Date.now() - t0;
++ expect(await timelineRows('notes/freshness-example')).toEqual([{ date: '2026-09-14' }]);
++ expect(await edges('notes/freshness-example')).toEqual([]);
++
++ await drainEffects();
++ const mentionMs = Date.now() - t0;
++ const afterEffect = await edges('notes/freshness-example');
++ expect(afterEffect.filter(e => e.link_type === 'mentions').map(e => e.to_slug)).toEqual(['companies/acme-example', 'people/alice-example']);
++ expect(afterEffect.some(e => e.link_type === 'works_at')).toBe(false);
++
++ await withEnv({ GBRAIN_HOME: home }, () => runCycle(engine, { brainDir: null, sourceId: SOURCE, phases: ['extract'] } as never));
++ const typedMs = Date.now() - t0;
++ const afterExtract = await edges('notes/freshness-example');
++ console.log(`[remote-graph-freshness] commit=${commitMs}ms mention_links=${mentionMs}ms typed_edges=${typedMs}ms edges=${JSON.stringify(afterExtract)}`);
++ expect(afterExtract.some(e => e.link_type === 'mentions' && e.to_slug === 'people/alice-example')).toBe(true);
++ expect(afterExtract.some(e => e.link_type !== 'mentions')).toBe(true);
++ }, 120_000);
++
++ test('mcp.remote_auto_links=false queues no mention pass', async () => {
++ await engine.setConfig('mcp.remote_auto_links', 'false');
++ try {
++ const row = await remoteWrite('notes/freshness-off', BODY.replace('Freshness example', 'Freshness off'));
++ expect((row.outcome?.auto_links as Record<string, unknown> | undefined)?.mention_links).toBeUndefined();
++ await drainEffects();
++ expect((await edges('notes/freshness-off')).filter(e => e.link_type === 'mentions')).toEqual([]);
++ } finally {
++ await engine.unsetConfig('mcp.remote_auto_links');
++ }
++ }, 120_000);
++});