Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: Step 11 voice findings
garrytanbca3d15e6586
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 5899ca29b6..62b83b0a7a 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1397,7 +1397,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;// #8384 (GBRA-269) quote fence follow-ups 2. since stamped at the merge slot.{ since: '0.60.539.0', id: 'remote_quotes_followups_8384', text: 'Agents connected over MCP now get a timeline entry\'s free-text source quoted with its summary and detail (get_timeline, the chronicle reads, volunteer_chronicle), and ontology values (volunteer_chronicle, ontology_get, ontology_conflicts) quoted by their fact\'s trust tier; add_timeline_entry and ontology_propose store text copied out of those reads without the fence. A remote put_page of a whole-markdown read keeps a code block the agent added inside, in place of or after the read, and keeps the frontmatter when blank lines were added before the marker. A remote get_page or fetch of a page quoted only because its origin is unverified carries a quoted_unverified_origin notice naming gbrain trust claim-sources and gbrain trust backfill, once per session. Local reads are unchanged.' },// #8384 (GBRA-269) quote fence follow-ups 3. since stamped at the merge slot.- { since: '0.60.539.0', id: 'remote_quotes_followups_8384b', text: 'Agents connected over MCP now get a quoted page\'s title quoted on search, query, assemble_evidence and recall rows, its tags quoted on get_page, fetch and get_tags (add_tag and remove_tag take a copied tag without the fence), and a chronicle row\'s kind quoted by its event page\'s tier; a context_pack card below "your notes" carries its title under the card\'s trust label. A remote put_page of a whole-markdown read saved with CRLF line endings stores the page, not its fence, and a fenced value pasted into frontmatter leaves the other keys as sent. Local reads are unchanged.' },+ { since: '0.60.539.0', id: 'remote_quotes_followups_8384b', text: 'Agents connected over MCP now get a quoted page\'s title quoted on search, query, assemble_evidence and recall rows, its tags quoted on get_page, fetch and get_tags (add_tag and remove_tag take a copied tag without the fence), and a chronicle row\'s kind quoted by its event page\'s tier; a context_pack card below "your notes" carries its title under the card\'s trust label. A remote put_page of a whole-markdown read saved with CRLF line endings stores the page, not its fence, and a fenced value pasted into frontmatter leaves the other keys as sent. Facts from a quarantined page, or awaiting re-derivation after a purge, no longer appear in entity-fact reads, local ones included: recall, search and query entity facts, find_trajectory, the entity card\'s fact count, standing-question evidence and consolidate. Other 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/pages.ts b/src/core/ops/pages.tsindex f82014361e..dc5949b478 100644--- a/src/core/ops/pages.ts+++ b/src/core/ops/pages.ts@@ -30,6 +30,7 @@ import { getContentFlag } from '../quarantine.ts';import { fileHeldField, readHeldPages } from '../persistence/held-reads.ts';import { bumpLastRetrievedAt } from '../last-retrieved.ts';import { resolveExcludePrivatePages, isPrivatePage, findPrivateOnlySlugs, isPrivatePageForCaller } from '../search/private-visibility.ts';+import { unquoteAnyTranscriptText } from '../search/transcript-quote.ts';import { LIST_PAGES_DESCRIPTION, CAPTURE_DESCRIPTION } from '../operations-descriptions.ts';import { listPagesPagination, listingTruncatedNotice } from './list-pages-pagination.ts';import { OperationError, opError, type Operation, type OperationContext } from './contract.ts';@@ -612,7 +613,7 @@ const list_pages: Operation = {// the pages such consumers exist to find.const rows = scope.sourceIds?.length === 0 ? [] : await ctx.engine.listPages({type: p.type as any,- tag: p.tag as string,+ tag: typeof p.tag === 'string' && ctx.remote !== false ? unquoteAnyTranscriptText(p.tag) : p.tag as string,limit: limit + 1,offset,includeDeleted: (p.include_deleted as boolean) === true,diff --git a/src/core/persistence/page-mutations.ts b/src/core/persistence/page-mutations.tsindex b1ebc693ac..db14f3647f 100644--- a/src/core/persistence/page-mutations.ts+++ b/src/core/persistence/page-mutations.ts@@ -274,7 +274,9 @@ function unquotedStrings(value: unknown, slug: string): unknown {* #8377: a quoted read's reading shape fences the title and each frontmatter string as `slug`'s (a whole-markdown read is* fenced once instead, and its metadata is the page's own). YAML indents those fences, so the body's unquote misses them.* #8384: only the top-level keys that held a fence are rewritten; every other line keeps the bytes the caller sent, so a- * naive datetime keeps its brain-timezone reading. A fenced key not found on its own line rewrites the whole block.+ * naive datetime keeps its brain-timezone reading. A fenced key not found on its own line, or a line rewrite that does not+ * parse back to the unquoted values (a flow mapping continued on an unindented line, an anchor another key aliases),+ * rewrites the whole block.*/function unquotedFrontmatter(sent: string, content: string, slug: string): string {const offset = frontmatterBodyOffset(content);@@ -298,7 +300,14 @@ function unquotedFrontmatter(sent: string, content: string, slug: string): strin} else out.push(...lines.slice(i, end));i = end;}- return fenced.size ? dataFrontmatter.stringify('', data) + content.slice(offset) : [...out, ...lines.slice(close)].join('\n') + content.slice(offset);+ const whole = dataFrontmatter.stringify('', data) + content.slice(offset);+ if (fenced.size) return whole;+ const partial = [...out, ...lines.slice(close)].join('\n') + content.slice(offset);+ try {+ return JSON.stringify(parseMarkdownHead(partial).frontmatter) === JSON.stringify(data) ? partial : whole;+ } catch {+ return whole;+ }}async function unquotedPutContent(engine: BrainEngine, sourceId: string, slug: string, content: string): Promise<string> {diff --git a/src/core/search/transcript-quote.ts b/src/core/search/transcript-quote.tsindex 4dcb10352d..5f94777314 100644--- a/src/core/search/transcript-quote.ts+++ b/src/core/search/transcript-quote.ts@@ -627,9 +627,12 @@ export function deliveredQuoteText(row: Row, text: string, header = false, untrureturn label === null ? text : fenceTranscriptText(text, label, rowHeader(row, header));}-/** #8384: a row's title as step 2 delivers it to an untrusted reader: fenced with its quoted text (what capEvidenceToBudget counts). */+/**+ * #8384: a row's title as step 2 delivers it to an untrusted reader: fenced with its quoted text (what capEvidenceToBudget+ * counts), and fenced alone when the row carries no text (an evidence-omitted keyword row) but would be quoted with some.+ */export function deliveredQuoteTitle(row: Row, title: string, untrusted: boolean): string {- const label = untrusted && title ? quoteLabel(row, true) : null;+ const label = untrusted && title ? quoteLabel({ ...row, chunk_text: row.chunk_text || title }, true) : null;return label === null ? title : fenceTranscriptText(title, label);}@@ -645,11 +648,11 @@ export function fenceTranscriptRows<T extends Row>(rows: T[], recount?: { count:const header = recount?.delivery.date_header === true;return rows.map(r => {const label = quoteLabel(r, untrusted);- if (label === null) return r;- const head = rowHeader(r, header);- const chunk_text = fenceTranscriptText(r.chunk_text, label, head);const title = untrusted && r.title ? { title: deliveredQuoteTitle(r, r.title, true) } : {};if (recount && title.title) recount.delivery.budget_used += recount.count(title.title) - recount.count(r.title!);+ if (label === null) return title.title !== undefined && title.title !== r.title ? { ...r, ...title, quoted: 'transcript' } as T : r;+ const head = rowHeader(r, header);+ const chunk_text = fenceTranscriptText(r.chunk_text, label, head);const d = (r as { delivered?: Delivered }).delivered;if (!d) return { ...r, chunk_text, ...title, quoted: 'transcript' } as T;const headLen = headerLine(r.chunk_text, head).length;diff --git a/test/search-transcript-quote-8384b.test.ts b/test/search-transcript-quote-8384b.test.tsindex 5a6bab5a9f..b3a0b831e9 100644--- a/test/search-transcript-quote-8384b.test.ts+++ b/test/search-transcript-quote-8384b.test.ts@@ -103,6 +103,13 @@ for (const backend of testBackends()) {}, 120_000);test('a quoted page\'s title on search and query rows is quoted with its text, the owner\'s kept', async () => {+ for (let i = 0; i < 3; i++) {+ await ok('put_page', { slug: `notes/omit-${i}-8384b`, content: `---\ntype: note\ntitle: "Omitted ${CODE.title} ${i}"\n---\n\n${'gst8384bomit filler words about the probe. '.repeat(120)}` });+ }+ const omitted = (await ok('search', { query: 'gst8384bomit', match: 'keyword', return_unit: 'page', token_budget: 128 })) as Array<{ slug: string; title: string; chunk_text: string }>;+ const bare = omitted.filter(r => r.slug.startsWith('notes/omit-') && !r.chunk_text);+ expect(bare.length).toBeGreaterThan(0);+ for (const r of omitted.filter(r => r.slug.startsWith('notes/omit-'))) expect([r.slug, fenced(r.title, CODE.title)]).toEqual([r.slug, true]);for (const op of ['search', 'query'] as const) {const extra = op === 'query' ? { expand: false } : {};const row = (rows: Array<{ slug: string; title: string }>, slug: string) => rows.find(r => r.slug === slug)!;@@ -144,6 +151,8 @@ for (const backend of testBackends()) {await ok('put_page', { slug: AGENT_SLUG, content: formatGetPage(page), expected_revision: page.revision });expect([await stored(AGENT_SLUG), await engine.getTags(AGENT_SLUG)]).toEqual([before, [CODE.tag]]);const [copied] = await ok('get_tags', { slug: AGENT_SLUG });+ const listed = await ok('list_pages', { tag: copied });+ expect((Array.isArray(listed) ? listed : listed.pages ?? listed.results).map((pg: { slug: string }) => pg.slug)).toEqual([AGENT_SLUG]);await ok('remove_tag', { slug: AGENT_SLUG, tag: copied });expect(await engine.getTags(AGENT_SLUG)).toEqual([]);await ok('add_tag', { slug: AGENT_SLUG, tag: copied });@@ -168,6 +177,15 @@ for (const backend of testBackends()) {await ok('put_page', { slug: 'notes/flow-fenced', expected_revision: flow,content: `---\n{type: note, title: ${JSON.stringify(fenceTranscriptText('Pasted', 'notes/flow-fenced'))}}\n---\n\nPasted body.\n` });expect([(await stored('notes/flow-fenced'))!.title, (await stored('notes/flow-fenced'))!.frontmatter]).toEqual([(await stored('notes/flow-plain'))!.title, (await stored('notes/flow-plain'))!.frontmatter]);+ const nested = JSON.stringify(fenceTranscriptText('Pasted', 'notes/nested-fenced'));+ for (const [slug, head] of [['notes/nested-fenced', `metadata: {title: ${nested},\nstable: original}`], ['notes/anchor-fenced', `metadata: {title: ${nested.replace('nested', 'anchor')}, stable: &stable original}\ncopy: *stable`]] as const) {+ const plainHead = head.replace(/title: "(?:[^"\\]|\\.)*"/, 'title: Pasted');+ await ok('put_page', { slug: `${slug}-plain`, content: `---\ntype: note\ntitle: Pasted\n${plainHead}\n---\n\nPasted body.\n` });+ await ok('put_page', { slug, content: '---\ntype: note\ntitle: Old\n---\n\nOld body.\n' });+ const rev = (await ok('get_page', { slug })).revision;+ await ok('put_page', { slug, expected_revision: rev, content: `---\ntype: note\ntitle: Pasted\n${head}\n---\n\nPasted body.\n` });+ expect([slug, (await stored(slug))!.frontmatter]).toEqual([slug, (await stored(`${slug}-plain`))!.frontmatter]);+ }} finally {await engine.setConfig('brain.timezone', '');}