Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: quote ontology_conflicts values in one batch; widen the unquote scan budget so a few cut-off fences keep later quotes unquoted
garrytane41c8a224bd1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 90c7018227..f915055d37 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,7 +18,7 @@ Before, an agent that read a page with `include_content`, added a fenced code bl### Itemized changes-- Remote `put_page` finds a whole-markdown read's closing fence as the first line that is exactly that fence outside a code block the content opens itself, so a code block added inside, in place of or after the read is stored whole; a read with blank lines before its marker and its closing line replaced keeps its frontmatter. A fence naming another page, or one after other text, is stored as written. Content holding many markers that never close is kept as written in linear time (the unquote shares one scan budget per text).+- Remote `put_page` finds a whole-markdown read's closing fence as the first line that is exactly that fence outside a code block the content opens itself, so a backtick code block added inside, in place of or after the read is stored whole; a read with blank lines before its marker and its closing line replaced keeps its frontmatter. A fence naming another page, or one after other text, is stored as written. Content holding many markers that never close is kept as written in linear time (the unquote shares one scan budget per text).- `get_timeline`, the chronicle reads and `volunteer_chronicle` quote a timeline row's `source` with its summary and detail; remote `add_timeline_entry` stores a copied source without the fence.- `volunteer_chronicle`'s `ontologies`, `ontology_get` and `ontology_conflicts` quote a value by its fact's stored tier for remote readers (`quoted: "transcript"`); remote `ontology_propose` stores a copied value without the fence.- A remote `get_page` or `fetch` of a page quoted because its trust tier is `unknown` carries a `quoted_unverified_origin` info notice, once per session, naming `gbrain trust claim-sources` (preview with `--dry-run --json`) and `gbrain trust backfill`. Quoting is unchanged.diff --git a/docs/mcp/README.md b/docs/mcp/README.mdindex 36b3fe7c7e..2de54ed46f 100644--- a/docs/mcp/README.md+++ b/docs/mcp/README.md@@ -116,7 +116,7 @@ and `view: markdown` keep the stored text byte-exact inside the fence, so`put_page` given that `content` back removes exactly the fences get_pageadded around this page before writing (a fence-like text in an owner-tiernote's stored body is kept; a whole-markdown read whose closing fence the edit replaced or appended past is unfenced too,-as is one with blank lines added before its marker, and a code block the edit added inside, in place of or after the read+as is one with blank lines added before its marker, and a backtick code block the edit added inside, in place of or after the readis kept whole). A remote `put_page` whose content holds atool-call summary that a whole read of the stored page never produces, orthat keeps fewer of a summarized call than the stored page holds, isdiff --git a/src/core/ops/chronicle.ts b/src/core/ops/chronicle.tsindex d185d4b62b..583eee373e 100644--- a/src/core/ops/chronicle.ts+++ b/src/core/ops/chronicle.ts@@ -279,10 +279,12 @@ const ontology_conflicts: Operation = {if (ctx.remote === false) return conflicts;// Remote: redact diary-sourced values; drop conflicts that no longer have// ≥2 distinct values once diary provenance is removed (no leak via conflicts).- return Promise.all(conflicts+ const kept = conflicts.map((c) => ({ ...c, values: c.values.filter((v) => !(v.source ?? '').startsWith('life/diary/')) }))- .filter((c) => new Set(c.values.map((v) => v.value)).size >= 2)- .map(async (c) => ({ ...c, values: await remoteOntology(ctx, c.values) })));+ .filter((c) => new Set(c.values.map((v) => v.value)).size >= 2);+ const quoted = await remoteOntology(ctx, kept.flatMap((c) => c.values));+ let at = 0;+ return kept.map((c) => ({ ...c, values: c.values.map(() => quoted[at++]!) }));},cliHints: { name: 'ontology-contradictions' },};diff --git a/src/core/search/transcript-quote.ts b/src/core/search/transcript-quote.tsindex cd1d3b13e2..1b57911ff0 100644--- a/src/core/search/transcript-quote.ts+++ b/src/core/search/transcript-quote.ts@@ -551,7 +551,7 @@ export function unquoteFactText(text: string): string {function unquoteMarked(text: string, find: (from: number) => { i: number; length: number } | null, unclosed = false): string {let out = '';let at = 0;- const work = { left: 2 * text.length + 1 };+ const work = { left: 8 * text.length + 1 };for (let found = find(0); found; found = find(at)) {const { i, length } = found;const open = /^(`{3,})text\n/.exec(text.slice(i + length));@@ -572,8 +572,9 @@ function unquoteMarked(text: string, find: (from: number) => { i: number; length* so an agent's added block (```js … ```) is kept whole. A host's quoted text never holds a backtick run as long as its* fence, so a line of exactly `fence` inside a shorter or tilde block (an unclosed one in a cut window too) still closes it.* `end` is the newline before that line and `after` the end of the fence and its blanks. Every search of one text shares- * `work` (twice the text's length): closes found are disjoint, so only fences that never close spend it twice, and past- * it ('spent') the rest of the text is kept as written, so hostile content of many unclosed markers stays linear.+ * `work` (eight times the text's length): closes found are disjoint and a fence that never closes spends the rest of the+ * text, so about seven such fences unquote as before; past it ('spent') the rest of the text is kept as written, so+ * hostile content of many unclosed markers stays linear.*/function closingLine(text: string, start: number, fence: string, work: { left: number }): { end: number; after: number } | null | 'spent' {let inner: { char: string; length: number } | null = null;diff --git a/test/search-transcript-quote-8384.test.ts b/test/search-transcript-quote-8384.test.tsindex 8297aeda7e..ceeaebb2c7 100644--- a/test/search-transcript-quote-8384.test.ts+++ b/test/search-transcript-quote-8384.test.ts@@ -167,6 +167,12 @@ describe('#8384: a host\'s own quoted text unquotes exactly, whatever code fenceexpect(unquoteTranscriptText(parts.join('\n'), 'slack/a', true)).toBe([1, 2, 3, 4, 5].map(k => `${pad}window ${k}\n~~~\ncut code ${k}`).join('\n'));});+ test('a whole quote after a few cut-off ones still unquotes', () => {+ const head = (id: number) => fenceTranscriptText(`cut ${id}`, `fact ${id}`).replace(/\n`+$/, '');+ const whole = 'real fact line\n'.repeat(200).trimEnd();+ expect(unquoteFactText(`${head(1)}\n${head(2)}\n${head(3)}\n${fenceTranscriptText(whole, 'fact 4')}`).endsWith(`\n${whole}`)).toBe(true);+ });+test('a megabyte of markers that never close is kept as written in linear time', () => {const fence = fenceTranscriptText('x', 'slack/a').split('\n').slice(0, 2).join('\n');const hostile = `intro\n${`${fence}\n`.repeat(Math.ceil(1_048_576 / (fence.length + 1)))}`;