Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes (#8377: put_page unfences a quoted read's title and frontmatter; takes sources quoted; tests assert the quoted claim)
garrytan2aeeeb2c2e64
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 889b4b2210..2f78c9953b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,8 +18,8 @@ Before, #8367 left `chronicle_day`, `chronicle_since`, `chronicle_on_this_day`,### Itemized changes-- Chronicle reads quote each timeline row by its own page; `takes_list` and `takes_search` quote claims below the owner's tier.-- Remote `get_page` and `fetch` quote a quoted page's title and every frontmatter string; `include_content` and fetch `text` fence the whole serialized markdown, and the `put_page` round trip still stores the page unchanged.+- Chronicle reads quote each timeline row's summary and detail by its own page; `takes_list` and `takes_search` quote a claim below the owner's tier and its free-text `source` and `resolved_source`.+- Remote `get_page` and `fetch` quote a quoted page's title and every frontmatter string; `include_content` and fetch `text` fence the whole serialized markdown, and the `put_page` round trip still stores the page unchanged. A thin client's `gbrain get` then `gbrain put`, or an agent that rebuilds the markdown from `title` and `frontmatter`, stores the title and frontmatter without the fences. Titles on search rows and context cards, and a chronicle entry's `kind`, are still returned as stored.- A thin client's paged `gbrain get` of a quoted page (above the inline limit) prints the page, and its `--json` content, inside one quote fence after verifying size and sha256.- The per-turn push hook and the pushed context pack quote hot and entity facts below the owner's tier; a fact injected before this change is not injected again.- `context_pack` counts the entity facts it withholds when the quote lookup fails (`suppressed`) instead of dropping them silently.diff --git a/docs/mcp/README.md b/docs/mcp/README.mdindex a72ea93e7b..8f6e0529cc 100644--- a/docs/mcp/README.md+++ b/docs/mcp/README.md@@ -134,7 +134,7 @@ notes" (written by an agent, tool data, external, or unverified origin) comesback quoted on search, `query`, `recall`, `assemble_evidence`, `get_page`(title and frontmatter included; `include_content` fences the whole markdown),`fetch`, `get_timeline`, `chronicle_day`, `chronicle_since`,-`chronicle_on_this_day`, `volunteer_chronicle`, `takes_list`, `takes_search`,+`chronicle_on_this_day`, `volunteer_chronicle`, `takes_list`, `takes_search` (claim and source),`get_chunks`, `search_exact`, `get_versions`, `known_as_of`, `think`'s extractiveanswer, `context_pack`, hot memory and write receipts. The context gbrain'shooks inject (the per-turn hook and the pushed context pack) quotes facts below@@ -143,7 +143,9 @@ timeline entry an agent copies back from a quoted read into `remember` or`add_timeline_entry` is stored without the fence. A note saved before gbraintracked trust reads as unverified, so it is quoted until the owner runs`gbrain trust claim-sources` or `gbrain trust backfill` (`gbrain doctor` names how-many pages that is). Local reads are unchanged.+many pages that is). Page titles are quoted on `get_page` and `fetch` only:+search rows and context cards return them as stored, and so is a chronicle+entry's `kind`. Local reads are unchanged.`effective_date` is the page's own date and `effective_date_source` sayswhich kind: `date`, `published` or `filename` is a document date,diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 3e85cdfee0..a18c831000 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1393,7 +1393,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;// GST-687 (GBRA-269) quote fence by trust tier. since stamped at the merge slot.{ since: '0.60.536.0', id: 'remote_quotes_unverified_text_gst687', text: 'Agents connected over MCP now get text quoted as source material (a line naming its page or fact, then a code fence) when its stored trust tier is below "your notes": text written by an agent, tool data, external text and text of unverified origin. This covers search, query, recall, assemble_evidence, get_page, fetch, get_timeline, get_chunks, search_exact, think\'s extractive answer, get_versions and known_as_of reads, context_pack, delta, hot memory and write receipts; chronicle, takes and page title reads are not quoted yet. A note saved before gbrain tracked trust reads as unverified origin, so it is quoted until the owner claims its source (`gbrain trust claim-sources`) or `gbrain trust backfill` classifies it; `gbrain doctor` names how many pages that is. Conversation pages also come back with tool-call blocks summarized on get_page, fetch, search_exact, get_chunks and think; `get_page` with `include_content` and the markdown view keep the stored text. Local reads, stored text and trust tiers are unchanged.' },// #8377 (GBRA-269) quote fence follow-ups. since stamped at the merge slot.- { since: '0.60.537.0', id: 'remote_quotes_followups_8377', text: 'Agents connected over MCP now also get text below "your notes" quoted on the chronicle reads (chronicle_day, chronicle_since, chronicle_on_this_day, volunteer_chronicle), takes_list and takes_search, and a quoted page\'s title and frontmatter; get_page include_content and fetch text fence the whole markdown, frontmatter included. The context gbrain\'s hooks inject (the per-turn hook and the pushed context pack) quotes facts below the owner\'s tier too, so hook output can hold quote fences. A thin client\'s paged `gbrain get` of a quoted page prints it inside the fence. remember and add_timeline_entry store text copied out of a quoted read without the fence, and put_page admits a conversation round trip whose stored tool call holds a summary in its arguments. Local reads are unchanged.' },+ { since: '0.60.537.0', id: 'remote_quotes_followups_8377', text: 'Agents connected over MCP now also get text below "your notes" quoted on the chronicle reads (chronicle_day, chronicle_since, chronicle_on_this_day, volunteer_chronicle), takes_list and takes_search (claim and source), and a quoted page\'s title and frontmatter (put_page of that read stores them unfenced); get_page include_content and fetch text fence the whole markdown, frontmatter included. The context gbrain\'s hooks inject (the per-turn hook and the pushed context pack) quotes facts below the owner\'s tier too, so hook output can hold quote fences. A thin client\'s paged `gbrain get` of a quoted page prints it inside the fence. remember and add_timeline_entry store text copied out of a quoted read without the fence, and put_page admits a conversation round trip whose stored tool call holds a summary in its arguments. Local reads are unchanged.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/ops/takes.ts b/src/core/ops/takes.tsindex 27a2ef5bc1..fd74169296 100644--- a/src/core/ops/takes.ts+++ b/src/core/ops/takes.ts@@ -60,10 +60,14 @@ export async function takesHiddenFromResult(ctx: OperationContext, op: string, rreturn { pages: [...new Set(withTakes.map(c => c.slug))], count: withTakes.reduce((n, c) => n + c.count, 0) };}-/** GST-687: a remote reader gets a claim below the owner's tier (an agent's take, an ingested one) quoted as its page's. */-function quoteTakes<T extends { claim: string; page_slug: string; trust_tier: string }>(ctx: OperationContext, rows: T[]): Array<T | (T & { quoted: 'transcript' })> {+/** GST-687: a remote reader gets a claim below the owner's tier (an agent's take, an ingested one) quoted as its page's, with its free-text sources. */+function quoteTakes<T extends { claim: string; page_slug: string; trust_tier: string; source?: string | null; resolved_source?: string | null }>(ctx: OperationContext, rows: T[]): Array<T | (T & { quoted: 'transcript' })> {if (ctx.remote === false) return rows;- return rows.map(r => quotesTier(r.trust_tier) ? { ...r, claim: fenceTranscriptText(r.claim, r.page_slug), quoted: 'transcript' as const } : r);+ return rows.map(r => {+ if (!quotesTier(r.trust_tier)) return r;+ const fence = (text: string) => fenceTranscriptText(text, r.page_slug);+ return { ...r, claim: fence(r.claim), ...(r.source ? { source: fence(r.source) } : {}), ...(r.resolved_source ? { resolved_source: fence(r.resolved_source) } : {}), quoted: 'transcript' as const };+ });}// --- v0.28: Takes ---diff --git a/src/core/persistence/page-mutations.ts b/src/core/persistence/page-mutations.tsindex 483e77b016..f95d655836 100644--- a/src/core/persistence/page-mutations.ts+++ b/src/core/persistence/page-mutations.ts@@ -22,7 +22,8 @@ import { parseWireWriteWaitMs } from './write-wait.ts';import { assertTimelineNotOmitted, isTimelineSection, timelineSectionOf, type TimelineSection } from './timeline-omission.ts';import { contentOriginTier } from '../trust/tier.ts';import { PAGE_MAX_BYTES } from '../page-size-policy.ts';-import { contentSizeHold, parseMarkdownHead } from '../markdown.ts';+import { contentSizeHold, frontmatterBodyOffset, parseMarkdownHead } from '../markdown.ts';+import { dataFrontmatter } from '../data-frontmatter.ts';import { throwIfHeld } from '../trust/gate-outcomes.ts';import { admitWrite, assertPageRequestIdentity, assertReplayIntent, getWriteRequest, intentDigest, type WriteAdmission } from './journal.ts';import { submissionAuthority, authorizeStoredRequest } from './authority.ts';@@ -262,8 +263,20 @@ export async function submitPageMutation(ctx: OperationContext,* GST-687: content carrying a tool-call summary that only the neutralized read of the stored chat page holds (get_page's* reading shape, fetch) is refused, so a read-then-write never replaces a stored tool call with its summary.*/+/** #8377: a quoted read fences the title and each frontmatter string as `slug`'s; YAML indents those fences, so the body's unquote misses them. */+function unquotedFrontmatter(content: string, slug: string): string {+ const offset = frontmatterBodyOffset(content);+ if (!offset || !content.slice(0, offset).includes('```text')) return content;+ const { frontmatter } = parseMarkdownHead(content);+ const unquote = (v: unknown): unknown => typeof v === 'string' ? unquoteTranscriptText(v, slug)+ : Array.isArray(v) ? v.map(unquote)+ : v && typeof v === 'object' && !(v instanceof Date) ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, unquote(x)])) : v;+ const data = unquote(frontmatter) as Record<string, unknown>;+ return JSON.stringify(data) === JSON.stringify(frontmatter) ? content : dataFrontmatter.stringify('', data) + content.slice(offset);+}+async function unquotedPutContent(engine: BrainEngine, sourceId: string, slug: string, content: string): Promise<string> {- const unquoted = unquoteTranscriptText(content, slug);+ const unquoted = unquotedFrontmatter(unquoteTranscriptText(content, slug), slug);const summarized = /, arguments omitted\]/.test(unquoted);const quotedType = isQuotedPageType(String(parseMarkdownHead(unquoted).frontmatter.type ?? ''));if (!summarized && (unquoted === content || quotedType)) return unquoted;diff --git a/test/e2e/engine-content-privacy.test.ts b/test/e2e/engine-content-privacy.test.tsindex 3a136e7c3c..b032277e51 100644--- a/test/e2e/engine-content-privacy.test.ts+++ b/test/e2e/engine-content-privacy.test.ts@@ -5,6 +5,7 @@ import type { BrainEngine } from '../../src/core/engine.ts';import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';import { listEntityIdentities, linkEntityIdentity, unionLinksAcrossIdentity } from '../../src/core/entity-identity.ts';import { operationsByName, type OperationContext } from '../../src/core/operations.ts';+import { fenceTranscriptText } from '../../src/core/search/transcript-quote.ts';import { runGather } from '../../src/core/think/gather.ts';import { runThink } from '../../src/core/think/index.ts';import { __resetPrivateVisibilityCacheForTests } from '../../src/core/search/private-visibility.ts';@@ -310,7 +311,7 @@ for (const kind of ['pglite', 'postgres'] as const) {expect(gathered.takes.map(r => r.claim)).toEqual(['privacy retrieval public']);const remote = { engine, remote: true, sourceId: A, auth: { allowedSources: [A, B] } } as OperationContext;for (const [op, args] of [['takes_list', {}], ['takes_search', { query: 'privacy retrieval' }]] as const) {- expect((await operationsByName[op].handler(remote, args) as Array<{ claim: string }>).map(r => r.claim)).toEqual(['privacy retrieval public']);+ expect((await operationsByName[op].handler(remote, args) as Array<{ claim: string }>).map(r => r.claim)).toEqual([fenceTranscriptText('privacy retrieval public', 'people/takes-shared')]); // #8377: quoted below the owner's tier}expect(await engine.listTakes({ sourceIds: [A, B] })).toHaveLength(3);expect(await engine.getScorecard(scope, ['world'])).toMatchObject({ total_bets: 1, resolved: 1, correct: 1, incorrect: 0 });diff --git a/test/e2e/serve-http-multi-agent.test.ts b/test/e2e/serve-http-multi-agent.test.tsindex d29fa51ca4..f07b1a14b0 100644--- a/test/e2e/serve-http-multi-agent.test.ts+++ b/test/e2e/serve-http-multi-agent.test.ts@@ -30,6 +30,7 @@ import { describe, test, expect, beforeAll, afterAll } from 'bun:test';import { spawnSync } from 'child_process';import { hasDatabase, setupDB, teardownDB, getConn } from './helpers.ts';import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';+import { fenceTranscriptText } from '../../src/core/search/transcript-quote.ts';const skip = !hasDatabase();// #3485 name floor: this suite opens direct SQL on the ambient URL and runs@@ -606,7 +607,7 @@ describeE2E('serve-http multi-agent E2E (cathedral-6)', () => {// the empty result above is scoping, not a broken op.const ownC = await callTool(tokenC!, 'takes_list', { page_slug: 'notes/nova-secret' });expect(ownC.isError).toBe(false);- expect((ownC.payload ?? []).some((t: any) => t.claim === 'nova secret take e2e-ma')).toBe(true);+ expect((ownC.payload ?? []).some((t: any) => t.claim === fenceTranscriptText('nova secret take e2e-ma', 'notes/nova-secret'))).toBe(true); // #8377: quoted below the owner's tier}, 30_000);// =========================================================================diff --git a/test/hidden-tool-hint.test.ts b/test/hidden-tool-hint.test.tsindex 7fa11e410c..182ecd1d77 100644--- a/test/hidden-tool-hint.test.ts+++ b/test/hidden-tool-hint.test.ts@@ -14,6 +14,7 @@import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { operations } from '../src/core/operations.ts';import type { AuthInfo } from '../src/core/operations.ts';+import { fenceTranscriptText } from '../src/core/search/transcript-quote.ts';import { allowedOpNames, createStdioSurfaceState, filterOpsForSurface, isReadOnlyOperation, stdioToolListing, type McpSurface } from '../src/mcp/surface.ts';import { hiddenToolHint, hiddenToolRoute } from '../src/mcp/hidden-tool-hint.ts';import { dispatchRenderContext, dispatchToolCall, toolConnection, type DispatchOpts } from '../src/mcp/dispatch.ts';@@ -150,7 +151,7 @@ describe('D2 hidden-takes scenario, installed configurations', () => {expect(n.fix!.mcp).toEqual({ tool: 'request_tools', arguments: { surface: 'full' } });expect(n.fix!.next).toBe('run');expect(await assertNextCallable(n, c.dispatchOpts)).toBe('request_tools');- expect(await takesVisibleBy(c.dispatchOpts)).toEqual(['Renewal ARR forecast 1.2M']);+ expect(await takesVisibleBy(c.dispatchOpts)).toEqual([fenceTranscriptText('Renewal ARR forecast 1.2M', SLUG)]); // #8377: a stdio reader gets a claim below the owner's tier quoted});test('callable full, advertised starter: next is the takes_list call itself, stdio lists it (tools/list_changed)', async () => {@@ -173,7 +174,7 @@ describe('D2 hidden-takes scenario, installed configurations', () => {const widen = stdioConnection({ surface: 'starter' });const w = hiddenNotice(await dispatchToolCall(engine, 'get_page', { slug: SLUG }, widen.dispatchOpts()))!;expect(await assertNextCallable(w, widen.dispatchOpts)).toBe('request_tools');- expect(await takesVisibleBy(widen.dispatchOpts)).toEqual(['Renewal ARR forecast 1.2M']);+ expect(await takesVisibleBy(widen.dispatchOpts)).toEqual([fenceTranscriptText('Renewal ARR forecast 1.2M', SLUG)]); // #8377: a stdio reader gets a claim below the owner's tier quoted});test('full (callable and advertised): takes_list is listed, so no notice', async () => {@@ -208,7 +209,7 @@ describe('D2 hidden-takes scenario, installed configurations', () => {expect(n.fix!.argv!.slice(0, 4)).toEqual(['gbrain', 'takes-list', '--page-slug', SLUG]);const full = stdioConnection({ surface: 'full', readOnly: true });expect(hiddenNotice(await dispatchToolCall(engine, 'get_page', { slug: SLUG }, full.dispatchOpts()))).toBeUndefined();- expect(await takesVisibleBy(full.dispatchOpts)).toEqual(['Renewal ARR forecast 1.2M']);+ expect(await takesVisibleBy(full.dispatchOpts)).toEqual([fenceTranscriptText('Renewal ARR forecast 1.2M', SLUG)]); // #8377: a stdio reader gets a claim below the owner's tier quoted});test('session widening off: the CLI equivalent, never request_tools', async () => {diff --git a/test/search-transcript-quote-followups.test.ts b/test/search-transcript-quote-followups.test.tsindex d0e4efec78..b98fc7a1de 100644--- a/test/search-transcript-quote-followups.test.ts+++ b/test/search-transcript-quote-followups.test.ts@@ -13,7 +13,7 @@ import { dispatchToolCall } from '../src/mcp/dispatch.ts';import { assembleContextPack, assembleTurnContext } from '../src/core/context/turn-context.ts';import { makeContextPackIpcHandler } from '../src/mcp/context-pack-handler.ts';import { withTrustPromotion } from '../src/core/persistence/context.ts';-import { printPagedPage, readWholePageMarkdown } from '../src/cli/page-render.ts';+import { formatGetPage, printPagedPage, readWholePageMarkdown } from '../src/cli/page-render.ts';import { fenceTranscriptText } from '../src/core/search/transcript-quote.ts';import { createHash } from 'node:crypto';import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';@@ -22,7 +22,7 @@ import { requirePostgresTestDatabase, testBackends } from './helpers/test-backenconst CODE = {title: 'gst8377-alder-prism-1201', frontmatter: 'gst8377-basalt-quiver-1302', body: 'gst8377-cedar-ripple-1403',- timeline: 'gst8377-dune-harrow-1504', take: 'gst8377-ember-lattice-1605', fact: 'gst8377-flint-meadow-1706',+ timeline: 'gst8377-dune-harrow-1504', take: 'gst8377-ember-lattice-1605', fact: 'gst8377-flint-meadow-1706', takeSource: 'gst8377-gale-orchid-1807',};const OWNER = { timeline: 'gst8377-grove-anchor-2101', take: 'gst8377-hazel-beacon-2202', fact: 'gst8377-iris-cobble-2303' };const AGENT_SLUG = 'notes/agent-probe';@@ -96,7 +96,7 @@ for (const backend of testBackends()) {await engine.setConfig('embedding_disabled', 'true');await ok('put_page', { slug: AGENT_SLUG, content: `---\ntype: note\ntitle: Probe ${CODE.title}\nsummary_line: Probe ${CODE.frontmatter}\n---\n\nReference for the probe: ${CODE.body}.` });await ok('add_timeline_entry', { slug: AGENT_SLUG, date: '2026-10-02', summary: `Probe entry ${CODE.timeline}.` });- await ok('takes_add', { slug: AGENT_SLUG, claim: `Probe claim ${CODE.take}`, kind: 'take', holder: 'world' });+ await ok('takes_add', { slug: AGENT_SLUG, claim: `Probe claim ${CODE.take}`, kind: 'take', holder: 'world', source: `Probe source ${CODE.takeSource}` });await ok('remember', { fact: `Probe fact about acme-example: ${CODE.fact}.`, entity: ENTITY_SLUG, provenance: 'follow-up probe' });await asOwner(engine, tx => tx.putPage(OWNER_SLUG, { type: 'note', title: 'Owner probe', compiled_truth: 'The owner wrote this.', timeline: '', frontmatter: {} }));await asOwner(engine, tx => tx.addTimelineEntry(OWNER_SLUG, { date: '2026-10-02', source: 'owner', summary: `Owner entry ${OWNER.timeline}.`, detail: '' }));@@ -130,9 +130,11 @@ for (const backend of testBackends()) {test('item 2: remote takes_list and takes_search quote an agent-written claim, not the owner\'s', async () => {const list = await call('takes_list', {});expect(cell(list, CODE.take)).toBe('fenced');+ expect(cell(list, CODE.takeSource)).toBe('fenced');expect(cell(list, OWNER.take)).toBe('raw');expect(cell(await call('takes_search', { query: words(CODE.take) }), CODE.take)).toBe('fenced');expect(cell(await call('takes_list', {}, local), CODE.take)).toBe('raw');+ expect(cell(await call('takes_list', {}, local), CODE.takeSource)).toBe('raw');}, 120_000);test('item 3: remote get_page and fetch quote a quoted page\'s title and frontmatter; the round trip stores the page unchanged', async () => {@@ -152,6 +154,15 @@ for (const backend of testBackends()) {expect(cell(await ok('get_page', { slug: AGENT_SLUG }, local), CODE.title)).toBe('raw');}, 120_000);+ test('item 3: a thin client\'s get then put of a quoted page stores its title and frontmatter unfenced', async () => {+ const before = await engine.getPage(AGENT_SLUG);+ const page = await ok('get_page', { slug: AGENT_SLUG });+ const printed = formatGetPage(page);+ await ok('put_page', { slug: AGENT_SLUG, content: printed, expected_revision: page.revision });+ const after = await engine.getPage(AGENT_SLUG);+ expect([after!.title, after!.compiled_truth, after!.frontmatter]).toEqual([before!.title, before!.compiled_truth, before!.frontmatter]);+ }, 120_000);+test('item 4: a reading shape of a chat page holding a call and a literal summary of it is refused as a write', async () => {const slug = 'conversations/guard-count';const call1 = JSON.stringify({ type: 'tool_use', id: 'toolu_c', name: 'search', input: { query: 'ledger' } });