Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(quote): #8384 wave 3 — CRLF whole-markdown put, chronicle kind, search/card titles, tags, naive-datetime frontmatter

garrytan4bd4927a1e7b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b6906fc4f..f283db7d71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,22 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**Agents connected over MCP now get a quoted page's title on search rows, its tags, and a chronicle event's kind quoted too, and a remote `put_page` of a whole-markdown read saved with CRLF line endings stores the page instead of its fence.**
+
+Before, a remote reader got a page's title raw on `search` and `query` rows, its tags raw on `get_page`, `fetch` and `get_tags`, a context card's title outside the card's trust label, and a chronicle row's `kind` (from an event page an agent may have rewritten) raw, while the rest of each row was quoted. A whole-markdown read whose line endings an editor converted to CRLF was stored with the read's marker and fence in the body and its frontmatter lost. A fenced title pasted into frontmatter next to a naive datetime (`date: 2026-10-03 23:30:00`) moved that date to UTC, so `effective_date` could land on another day. Local reads and owner-tier text are unchanged.
+
+### Itemized changes
+
+- Remote `put_page` unfences a whole-markdown read whose lines end in CRLF, closing fence kept or replaced, and stores what a plain CRLF write of the unfenced markdown stores.
+- `search`, `query`, `assemble_evidence` and remote `recall` rows quote a quoted row's `title` with its text (`fenceTranscriptRows`).
+- `context_pack` and the pushed pack render a card below the owner's tier with its title under the card's trust label.
+- Remote `get_page` (every shape), `fetch` and `get_tags` quote a quoted page's tags; remote `add_tag` and `remove_tag` take a tag copied out of those reads without the fence.
+- The chronicle reads and `volunteer_chronicle` quote an event row's `kind` by its event page's type and tier; `--narrative` keeps that fence on its own lines.
+- Remote `put_page` rewrites only the frontmatter keys that held a fence, so every other line (a naive datetime included) keeps the bytes sent.
+- Tests: `test/search-transcript-quote-8384b.test.ts` (PGLite and Postgres), red on master for each change.
+
## [0.60.539.0] - 2026-11-01
**A remote `put_page` of a page an agent read whole now keeps its frontmatter and the code blocks it added, and timeline sources and ontology values are quoted below "your notes" like the rest of their rows.**
diff --git a/docs/architecture/key-files/core-search-evidence.md b/docs/architecture/key-files/core-search-evidence.md
index e5001223ca..b938261636 100644
--- a/docs/architecture/key-files/core-search-evidence.md
+++ b/docs/architecture/key-files/core-search-evidence.md
@@ -5,6 +5,6 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/core/search/evidence-date.ts` — C1 dated evidence blocks: the fixed header grammar (`[observed YYYY-MM-DD|unknown]` for page blocks; `[observed unknown; valid FROM to UNTIL]` for `recall` facts), `pageObservationDate` (effective-date precedence with `event_date` removed and no row-timestamp fallback; mirrors #6020's `resolveObservationDate`, the seam to swap once it lands), `formatBrainDay` from `effective-date.ts` (midnight UTC renders as written, other instants in `brain.timezone`; the one function think's `<page date>` also renders through, while the header's `observed` stays when the text was said, never the content date), `loadPageDateHeaders` (one `pages` read per delivery; only the derived day leaves it) `evidenceDateHeaderEnabled` (`search.evidence_date_header`, default off) and `evidenceTitlesEnabled` (`search.evidence_titles`, GBRA-205, default off: with the header on, `blockDateHeaders` ends a page block's line with its title via `titledPageHeader`, fact headers unchanged; think's `<page>` tag gets a `title` attribute). Tests: `test/evidence-date-header.test.ts`, `test/search-8k-conversion.test.ts`.
- `src/core/search/evidence-tail-trim.ts` — the protected tail trim (`search.evidence_tail_trim`, default off, GBRA-156). `resolveEvidencePlan` sets `EvidencePlan.tailTrim` only for `unit: auto` with the key on; `deliverEvidence` calls `trimEvidenceTail(results, opts.query)` on the rank-order delivered rows after redaction and before the token totals, and only when `DeliverOptions.query` is set (`search`/`query` pass `p.query`; the library `assembleEvidenceForHits` passes `input.query` and frozen hits may carry `score`; the `assemble_evidence` op passes neither, so the trim never runs there). Rows past `TAIL_TRIM_PROTECTED` = 3 that are whole-conversation blocks (`delivered.reason` `conversation_type`/`conversation_slug`) and score under `TAIL_TRIM_SCORE_FRACTION` = 0.5 of rank one are dropped, unless their `chunk_text` holds at least `TAIL_TRIM_TERM_FRACTION` = 0.8 of rank one's share of the query's terms (`queryTerms`: letter/digit runs, stopwords and single characters dropped, cut to six characters). Rank one's score must be a positive finite number and every row's finite, or nothing changes. `delivery.tail_trim` is `{ dropped, kept_by_query_terms }`; `dropped_reasons.tail_trim` counts drops. Pinned by `test/evidence-tail-trim.test.ts` (the knowledge-update regression case).
-- `src/core/search/transcript-quote.ts` — quotes third-party text on every read that hands it to a model (#7600, #8042). The signal is stored metadata, in one place: `isQuotedPageType` (every concrete type in `facts/conversation-types.ts` `ALLOWED_TYPE_ALIASES` plus `transcript` and `chat`) for page rows, and for fact rows `isQuotedFactSource` (`facts.source` starting `cli:extract-conversation-facts`, the prefix in `facts/audit-sources.ts`) or `factsFromQuotedPages` (one bounded read, same source: the fact's `source_markdown_slug` page, a `derivation_inputs` page edge the backstop and extract_facts already write, or for a `sync:import` / `mcp:put_page` fact the page its `source_session` names (`sync:<slug>`, `put_page:<slug>`, covering facts saved before edges or rebuilt from git) has a quoted type; it writes nothing, and a lookup failure withholds `saved_facts` (stage `saved_facts_withheld`) and remote recall facts (`facts_degraded.reason`) and fails the delta facts arm; the facts arm carries both on `fact_row.source`/`from_quoted_page`, stripped by `factRowOutput`; marker `fact <id>`); nothing reads the text to decide, so other rows come back byte-for-byte unchanged. `quoteLabel` is the row decision. GST-687: for an untrusted (remote, `ctx.remote !== false`) reader the signal also includes the stored trust tier: `quotesTier` (below `OWNER_TIER_FLOOR`, `operator_curated`; a missing tier reads as `unknown`, so it fails closed) and `quotesStored` (page type or tier) quote agent-written, tool-data, external and unverified-origin text. `quoteLabel(row, untrusted)`, `deliveredQuoteText`, `fenceTranscriptRows` and `quoteFacts(engine, facts, untrusted)` take that flag (`quoteFacts` reads each fact's stored tier from `facts`, never from the caller's row); only third-party types get tool calls summarized. `quotePageText` and `pageTypesById` serve reads whose rows name only a page (`get_timeline`, `get_chunks`). Local reads are unchanged. Beyond search: `recall` (remote callers: neutralize + fence its results before packing, `quoteFacts` its facts), think's pages block (`think/gather.ts renderPagesBlockDetailed`: neutralize before the excerpt, fence what it renders, every run), `saved_facts` in search/query meta, remote `delta` facts and `_meta.brain_hot_memory` (`quoteFacts`, which also quotes a representative when a collapsed member qualifies), remote `get_page known_as_of` and `get_versions` bodies and diffs (`ops/known-as-of.ts intervalView`, `ops/admin.ts`), and remote `get_page`/`fetch` (`ops/get-page-projection.ts projectGetPage` `quote`, which `projectFetchText` reuses: compiled_truth, timeline and `content` fenced without the tool-call summary, so text inside stays byte-exact; windows fenced in `get-page-body.ts envelopeText`; `quoted: "transcript"`; `quotesBody(ctx, page, trust)` also quotes a page below the owner's tier, and `neutralizesBody` summarizes tool calls only on a third-party page's reading shapes, never for the thin client, with `include_content` and `view: markdown` keeping the stored bytes inside the fence). Remote `get_timeline`, `get_chunks`, `search_exact`, think's extractive fallback, `context_pack` and `list_write_requests`/`get_write_request` outcome text quote by tier too, and so (#8377) do the `chronicle_*` reads and `volunteer_chronicle`'s timeline (`ops/chronicle.ts remoteTimeline`, each row by its own page; `quoteTimelineRows` fences a row's free-text `source` with summary and detail, #8384), its ontology values, `ontology_get`'s and `ontology_conflicts`' (`remoteOntology`, `quoteFacts` by `fact_id`; remote `ontology_propose` drops a fact fence), `takes_list`/`takes_search` (`ops/takes.ts quoteTakes`), a quoted page's title and frontmatter strings (`quotedPageMeta`; `include_content` and fetch `text` fence the whole serialized markdown), the per-turn push hook's hot facts and the pushed context pack (`untrusted: true`); `context_pack` counts entity facts a failed quote lookup withholds in `suppressed`. Remote `remember` drops a fact fence (`unquoteFactText`) and `add_timeline_entry` a fence naming its page, so a copied-back entry keeps its replay key. Remote `put_page` (`ctx.remote !== false`) runs `unquoteTranscriptText` over `content` (`persistence/page-mutations.ts unquotedPutContent`, after the replay check so the request digest covers what the caller sent; slug lowercased as admission does) when the stored page or the incoming frontmatter has a quoted type or the stored page is below the owner's tier (an owner-tier page keeps a fence naming it only when its stored body already holds one), removing only a marker naming that slug and its own fence, so get → edit → put writes the body and a note's fence-like text is kept (`unclosed`: a fence opening the content, after blank lines at most, whose closing line the edit replaced is removed too, #8377, #8384; `closingLine` takes the first line that is exactly the read's fence outside a code block the text opens itself, so an agent's added block stays whole; every search of one text shares a budget of eight times its length, past which the rest is kept as written, so many unclosed markers stay linear). Remote `put_page` content holding a tool-call summary that a whole read of the stored conversation page never produces, or fewer of a call's summaries than the page holds (`holdsSummarizedToolCalls`), refuses `invalid_params` and stores nothing; only summaries outside the text's own tool-call blocks count, and a named summary the page never wrote is admitted while every stored call stays (#8377). A thin client paging a quoted page (`cli/page-render.ts spoolWholePage`) unquotes each window before checking size and sha256, then prints the page (and `--json` content) inside one quote fence (`transcriptFence`). Trusted local get_page/fetch/put_page, recall and delta are unchanged. `searchOutput` (`ops/search.ts`) runs `neutralizeTranscriptRows` before the snippet and evidence caps and `fenceTranscriptRows` after them, on copies, after ranking and evidence delivery; `assembleEvidenceForHits` (`evidence-delivery.ts`, so the `assemble_evidence` op and gbrain-evals) does the same around `capEvidenceToBudget`. That cap counts a conversation row as delivered, inside its fence (`deliveredQuoteText`, its `quote` flag; deliverEvidence's own cap, which recall uses, counts the text as returned), so an explicit `auto` token budget still holds, `snippet_chars` included (a rank-one row is kept even when its fence alone exceeds a very small budget); a row it cuts is shortened until the fenced text fits, and other rows are cut exactly as before. The neutralizer replaces each tool-call block with `[tool call: <name>, arguments omitted]` (`[tool calls: a, b, …]` for several): an object typed `tool_use`, `server_tool_use`, `mcp_tool_use`, `function_call`, `custom_tool_call`, `tool_call` or `toolCall` (the enclosing object, found by walking back over candidate `{` with a string-aware scan), the value of a `tool_calls` array or a `function_call` or Gemini `functionCall` object (the message object and its `content` or `parts` stay), and an XML-style `function_calls`, `invoke`, `tool_use` or `tool_call` element with its `parameter` children, namespace prefix optional (the name from `invoke name="…"`, a `<name>` child, or the root `name` of the JSON object a `tool_call` opens with; result elements are never matched, and a tag counts as markup only when it ends its line (LF or CRLF) or the text, runs into the next tag, is an `invoke` with a name, or is a `tool_call` followed by `{`; blocks separated only by whitespace merge). The XML pass runs before the JSON pass. Text between evidence omission lines is read separately; a block cut by the end of the text is replaced to the end or the next message anchor line (an open-ended block never swallows a later message), one whose `{` lies before the text from the text start (or the last message anchor) when the type is followed by `,` or `}`, and prose that only names the shape is left alone. An XML block whose close lies past the text runs to the end or the next message anchor line; a closing tag with no opener (or a `parameter` opener outside a call) starts at the text start or the last message anchor. A trailing evidence cut marker and a leading `[observed …]` date header stay outside any block. Message anchor lines may end in CRLF. Scanning is linear: anchors are indexed once, and past a per-text work budget the rest of a message is summarized (fails closed). Names outside `[A-Za-z0-9_.:/-]{1,64}` are dropped. The fence is a marker line naming the slug (`[`, `]`, `;` and line breaks shown as `?`), then a code fence of at least three backticks, one longer than the longest run in the text; the row gets `quoted: "transcript"` (kept in lean rows). `rowPreview` is the CLI human line: `[quoted transcript]` and the start of the fenced text. Stored pages, chunks, ranking and scores are unchanged; delivered `match_spans` are remapped to the returned text, and `tokens`, `tokens_delivered` and `budget_used` count the fenced text (`fenceTranscriptRows` with a recount). Tests: `test/search/transcript-quote.test.ts`, `test/search-transcript-quote.test.ts` (ChatGPT export through the importer, with a JSON and an XML call; remote MCP `search`/`query`/`assemble_evidence` and CLI human/`--json`, both engines), `test/search-transcript-quote-budget.test.ts` (budget, spans and snippet cap through the ops), `test/search-transcript-quote-coverage.test.ts` (#8042 matrix: slack, imessage, email, meeting and conversation pages plus a conversation-extracted fact against a note and a remembered fact, plus backstop facts linked to a synced slack page by a derivation edge or only by their sync session, and one derived from a note, a failed lookup withholding facts, a retried retype put, over remote search, query, saved_facts, assemble_evidence, recall, get_page body/content/window, local get_page, the get→put round trip (a note's fence-like text, a mixed-case slug), thin-client paging of a 12,000-line slack page, fetch, think's prompt, delta, hot memory, and get_page known_as_of / get_versions bodies and diff, both engines), `test/search-transcript-quote-tiers.test.ts` (GST-687: every placement and read surface by tier, both engines) and `test/search-transcript-quote-legacy-claim.test.ts` (a legacy note is quoted, raw again after claim and backfill, both engines), `test/search-transcript-quote-followups.test.ts` (#8377: the chronicle, takes and page title/frontmatter reads, hook-injected facts, and the copied-back writes, red on master, both engines) and `test/trust-keep-maintenance-reimport-8352.test.ts` (#8352: maintenance re-imports keep an owner note's tier, both engines) and `test/search-transcript-quote-8384.test.ts` (#8384: whole-markdown round-trip edges, timeline source, ontology values, the `quoted_unverified_origin` notice from `get-page-projection.ts unverifiedOriginNotice`, both engines).
+- `src/core/search/transcript-quote.ts` — quotes third-party text on every read that hands it to a model (#7600, #8042). The signal is stored metadata, in one place: `isQuotedPageType` (every concrete type in `facts/conversation-types.ts` `ALLOWED_TYPE_ALIASES` plus `transcript` and `chat`) for page rows, and for fact rows `isQuotedFactSource` (`facts.source` starting `cli:extract-conversation-facts`, the prefix in `facts/audit-sources.ts`) or `factsFromQuotedPages` (one bounded read, same source: the fact's `source_markdown_slug` page, a `derivation_inputs` page edge the backstop and extract_facts already write, or for a `sync:import` / `mcp:put_page` fact the page its `source_session` names (`sync:<slug>`, `put_page:<slug>`, covering facts saved before edges or rebuilt from git) has a quoted type; it writes nothing, and a lookup failure withholds `saved_facts` (stage `saved_facts_withheld`) and remote recall facts (`facts_degraded.reason`) and fails the delta facts arm; the facts arm carries both on `fact_row.source`/`from_quoted_page`, stripped by `factRowOutput`; marker `fact <id>`); nothing reads the text to decide, so other rows come back byte-for-byte unchanged. `quoteLabel` is the row decision. GST-687: for an untrusted (remote, `ctx.remote !== false`) reader the signal also includes the stored trust tier: `quotesTier` (below `OWNER_TIER_FLOOR`, `operator_curated`; a missing tier reads as `unknown`, so it fails closed) and `quotesStored` (page type or tier) quote agent-written, tool-data, external and unverified-origin text. `quoteLabel(row, untrusted)`, `deliveredQuoteText`, `fenceTranscriptRows` and `quoteFacts(engine, facts, untrusted)` take that flag (`quoteFacts` reads each fact's stored tier from `facts`, never from the caller's row); only third-party types get tool calls summarized. `quotePageText` and `pageTypesById` serve reads whose rows name only a page (`get_timeline`, `get_chunks`). Local reads are unchanged. Beyond search: `recall` (remote callers: neutralize + fence its results before packing, `quoteFacts` its facts), think's pages block (`think/gather.ts renderPagesBlockDetailed`: neutralize before the excerpt, fence what it renders, every run), `saved_facts` in search/query meta, remote `delta` facts and `_meta.brain_hot_memory` (`quoteFacts`, which also quotes a representative when a collapsed member qualifies), remote `get_page known_as_of` and `get_versions` bodies and diffs (`ops/known-as-of.ts intervalView`, `ops/admin.ts`), and remote `get_page`/`fetch` (`ops/get-page-projection.ts projectGetPage` `quote`, which `projectFetchText` reuses: compiled_truth, timeline and `content` fenced without the tool-call summary, so text inside stays byte-exact; windows fenced in `get-page-body.ts envelopeText`; `quoted: "transcript"`; `quotesBody(ctx, page, trust)` also quotes a page below the owner's tier, and `neutralizesBody` summarizes tool calls only on a third-party page's reading shapes, never for the thin client, with `include_content` and `view: markdown` keeping the stored bytes inside the fence). Remote `get_timeline`, `get_chunks`, `search_exact`, think's extractive fallback, `context_pack` and `list_write_requests`/`get_write_request` outcome text quote by tier too, and so (#8377) do the `chronicle_*` reads and `volunteer_chronicle`'s timeline (`ops/chronicle.ts remoteTimeline`, each row by its own page; `quoteTimelineRows` fences a row's free-text `source` with summary and detail, #8384, and an event row's `kind` is fenced by its event page's type and tier), its ontology values, `ontology_get`'s and `ontology_conflicts`' (`remoteOntology`, `quoteFacts` by `fact_id`; remote `ontology_propose` drops a fact fence), `takes_list`/`takes_search` (`ops/takes.ts quoteTakes`), a quoted page's title, frontmatter strings and tags (`quotedPageMeta`, also `get_tags`; remote `add_tag`/`remove_tag` drop a fence naming the page; `include_content` and fetch `text` fence the whole serialized markdown), a quoted search/query/assemble_evidence/recall row's title (`deliveredQuoteTitle`, which `capEvidenceToBudget` counts), a `context_pack` card below the owner's tier rendering its title under the card's trust label, the per-turn push hook's hot facts and the pushed context pack (`untrusted: true`); `context_pack` counts entity facts a failed quote lookup withholds in `suppressed`. Remote `remember` drops a fact fence (`unquoteFactText`) and `add_timeline_entry` a fence naming its page, so a copied-back entry keeps its replay key. Remote `put_page` (`ctx.remote !== false`) runs `unquoteTranscriptText` over `content` (`persistence/page-mutations.ts unquotedPutContent`, after the replay check so the request digest covers what the caller sent; slug lowercased as admission does) when the stored page or the incoming frontmatter has a quoted type or the stored page is below the owner's tier (an owner-tier page keeps a fence naming it only when its stored body already holds one), removing only a marker naming that slug and its own fence (lines may end in CRLF), so get → edit → put writes the body and a note's fence-like text is kept (`unclosed`: a fence opening the content, after blank lines at most, whose closing line the edit replaced is removed too, #8377, #8384; `closingLine` takes the first line that is exactly the read's fence outside a code block the text opens itself, so an agent's added block stays whole; every search of one text shares a budget of eight times its length, past which the rest is kept as written, so many unclosed markers stay linear). Remote `put_page` content holding a tool-call summary that a whole read of the stored conversation page never produces, or fewer of a call's summaries than the page holds (`holdsSummarizedToolCalls`), refuses `invalid_params` and stores nothing; only summaries outside the text's own tool-call blocks count, and a named summary the page never wrote is admitted while every stored call stays (#8377). A thin client paging a quoted page (`cli/page-render.ts spoolWholePage`) unquotes each window before checking size and sha256, then prints the page (and `--json` content) inside one quote fence (`transcriptFence`). Trusted local get_page/fetch/put_page, recall and delta are unchanged. `searchOutput` (`ops/search.ts`) runs `neutralizeTranscriptRows` before the snippet and evidence caps and `fenceTranscriptRows` after them, on copies, after ranking and evidence delivery; `assembleEvidenceForHits` (`evidence-delivery.ts`, so the `assemble_evidence` op and gbrain-evals) does the same around `capEvidenceToBudget`. That cap counts a conversation row as delivered, inside its fence (`deliveredQuoteText`, its `quote` flag; deliverEvidence's own cap, which recall uses, counts the text as returned), so an explicit `auto` token budget still holds, `snippet_chars` included (a rank-one row is kept even when its fence alone exceeds a very small budget); a row it cuts is shortened until the fenced text fits, and other rows are cut exactly as before. The neutralizer replaces each tool-call block with `[tool call: <name>, arguments omitted]` (`[tool calls: a, b, …]` for several): an object typed `tool_use`, `server_tool_use`, `mcp_tool_use`, `function_call`, `custom_tool_call`, `tool_call` or `toolCall` (the enclosing object, found by walking back over candidate `{` with a string-aware scan), the value of a `tool_calls` array or a `function_call` or Gemini `functionCall` object (the message object and its `content` or `parts` stay), and an XML-style `function_calls`, `invoke`, `tool_use` or `tool_call` element with its `parameter` children, namespace prefix optional (the name from `invoke name="…"`, a `<name>` child, or the root `name` of the JSON object a `tool_call` opens with; result elements are never matched, and a tag counts as markup only when it ends its line (LF or CRLF) or the text, runs into the next tag, is an `invoke` with a name, or is a `tool_call` followed by `{`; blocks separated only by whitespace merge). The XML pass runs before the JSON pass. Text between evidence omission lines is read separately; a block cut by the end of the text is replaced to the end or the next message anchor line (an open-ended block never swallows a later message), one whose `{` lies before the text from the text start (or the last message anchor) when the type is followed by `,` or `}`, and prose that only names the shape is left alone. An XML block whose close lies past the text runs to the end or the next message anchor line; a closing tag with no opener (or a `parameter` opener outside a call) starts at the text start or the last message anchor. A trailing evidence cut marker and a leading `[observed …]` date header stay outside any block. Message anchor lines may end in CRLF. Scanning is linear: anchors are indexed once, and past a per-text work budget the rest of a message is summarized (fails closed). Names outside `[A-Za-z0-9_.:/-]{1,64}` are dropped. The fence is a marker line naming the slug (`[`, `]`, `;` and line breaks shown as `?`), then a code fence of at least three backticks, one longer than the longest run in the text; the row gets `quoted: "transcript"` (kept in lean rows). `rowPreview` is the CLI human line: `[quoted transcript]` and the start of the fenced text. Stored pages, chunks, ranking and scores are unchanged; delivered `match_spans` are remapped to the returned text, and `tokens`, `tokens_delivered` and `budget_used` count the fenced text (`fenceTranscriptRows` with a recount). Tests: `test/search/transcript-quote.test.ts`, `test/search-transcript-quote.test.ts` (ChatGPT export through the importer, with a JSON and an XML call; remote MCP `search`/`query`/`assemble_evidence` and CLI human/`--json`, both engines), `test/search-transcript-quote-budget.test.ts` (budget, spans and snippet cap through the ops), `test/search-transcript-quote-coverage.test.ts` (#8042 matrix: slack, imessage, email, meeting and conversation pages plus a conversation-extracted fact against a note and a remembered fact, plus backstop facts linked to a synced slack page by a derivation edge or only by their sync session, and one derived from a note, a failed lookup withholding facts, a retried retype put, over remote search, query, saved_facts, assemble_evidence, recall, get_page body/content/window, local get_page, the get→put round trip (a note's fence-like text, a mixed-case slug), thin-client paging of a 12,000-line slack page, fetch, think's prompt, delta, hot memory, and get_page known_as_of / get_versions bodies and diff, both engines), `test/search-transcript-quote-tiers.test.ts` (GST-687: every placement and read surface by tier, both engines) and `test/search-transcript-quote-legacy-claim.test.ts` (a legacy note is quoted, raw again after claim and backfill, both engines), `test/search-transcript-quote-followups.test.ts` (#8377: the chronicle, takes and page title/frontmatter reads, hook-injected facts, and the copied-back writes, red on master, both engines) and `test/trust-keep-maintenance-reimport-8352.test.ts` (#8352: maintenance re-imports keep an owner note's tier, both engines) and `test/search-transcript-quote-8384.test.ts` (#8384: whole-markdown round-trip edges, timeline source, ontology values, the `quoted_unverified_origin` notice from `get-page-projection.ts unverifiedOriginNotice`, both engines) and `test/search-transcript-quote-8384b.test.ts` (#8384 wave 3: CRLF whole-markdown, chronicle `kind`, search row and card titles, tags, a fenced value next to a naive datetime, both engines).
- `src/core/search/facts-arm.ts` — the `query` facts arm behind `search.query_facts_arm` (default on since gates 1b and 2 passed; `false` turns it off). `matchQueryFacts` reads the candidate pool from `fact-relevance.ts` (active facts under recall's read policy) and matches them by query-embedding cosine (`FACT_COSINE_MIN` 0.6, the embedding `hybridSearch` already computed, via `HybridSearchOpts.onQueryEmbedding`) or by query-term share (half the terms, substring match) or a named entity (in that page's source), newest `valid_from` first, at most `MAX_FACT_ROWS` (3). `applyFactsArm` adds them as `fact_row` rows in spare capacity only: free slots under the caller's row count, and whole rows that fit in what the page rows leave of the token budget; a page row is never displaced `factRowOutput` strips page fields (slug, id, type, chunk_id) from fact rows on output, leaving `result_type: 'fact'`, `fact_id`, `follow_up` (`recall` by entity, or `grep` without one) and `page_slug` when the caller can read the entity page (`readableEntityPages`); and stamps `superseded_claim` on page rows whose typed `claim_metric` (plus `claim_period` when both carry it) a newer active fact covers. No model call. Tests: `test/search-facts-arm.test.ts`. Gates and verdict: `docs/eval/decisions/query-facts-arm/`. Fact reserves: `applyFactReserve` serves two policies. The temporal fact reserve (`applyTemporalFactReserve`, `search.temporal_fact_reserve`, default off): `hasTemporalCue` (the preregistered word, phrase, ISO date and month-name regex), candidates from `collectFactCandidates` (50 cosine, 50 keyword, 20 entity facts, cosine for every candidate), scored by the shared `scoreFactCandidates` and kept by its `reserve` admission rule (fail-open on any error), packed into 15% of the token budget and 30% of the row count (1-20), rendered as fact rows whose text starts with `factDateHeader` (evidence delivery adds no second header), oldest first after the pages. Tests: `test/search-temporal-fact-reserve.test.ts`. Gates: `docs/eval/decisions/temporal-fact-reserve/`. The facts block (`applyFactsBlock`, `search.query_facts_block`, GBRA-205, default on since the held-out gate passed; `false` or a config read error turns it off): the same facts for every budgeted query, up to 22% of the budget and 40 rows, oldest first ahead of the pages, adding rows. Fact source pages (`applyFactSourcePages`, `search.fact_source_pages`, GBRA-205, default off): the conversations (`facts.source_markdown_slug`, never the entity page) of the best-matching admitted facts, at most 2 not already present, read through `getChunkWindows` under the caller's read scope and placed after the top 3 rows; the row count never grows. Tests: `test/search-8k-conversion.test.ts`.
- `src/core/search/remote-page-cap.ts` — GBRA-156: the default distinct-page cap of a remote `search`/`query` that names no `limit` (and no `offset`). `remotePageCap(ctx, p)` reads `search.remote_page_cap` (default `DEFAULT_REMOTE_PAGE_CAP`, `0` = off; null for trusted local callers and `viaSubagent` host tool calls); `capVectorOnlyPages(rows, cap)` keeps every page with lexical evidence (`keyword_hit`, strict or relaxed, `alias_hit`, `exact_lookup`, `relational_pinned`) and admits vector-only pages, in rank order, only while the result holds fewer than `cap` distinct `(source_id, slug)` pages; it reports `{ cap, kept_pages, dropped_pages }` as `_meta.retrieval.page_cap` when it dropped any. `pageCapLine(retrieval, how)` renders that as the model-visible line dispatch's `retrievalNoticeBlocks` appends after the keyword count line (hosts that show only `content[]` never see `_meta`), and the CLI's `formatResult` writes on stderr with `--limit`. Applied to the hybrid output before alias fan-out (search) and to the first pass and an adopted CRAG re-run (query); keyword-only paths carry no vector-only rows and the image branch is uncapped (`test/search-remote-page-cap.test.ts`). Every vector path (the hybrid vector arm, the embed-failure fallback, the `query` image branch) reads the keyword path's source scope (`test/search-vector-scope-parity.test.ts`).
diff --git a/docs/mcp/README.md b/docs/mcp/README.md
index 2de54ed46f..2b7e0025cd 100644
--- a/docs/mcp/README.md
+++ b/docs/mcp/README.md
@@ -115,7 +115,7 @@ and `view: markdown` keep the stored text byte-exact inside the fence, so
`edit_page` `old_text` copied from inside a fence still matches, and
`put_page` given that `content` back removes exactly the fences get_page
added around this page before writing (a fence-like text in an owner-tier
-note's stored body is kept; a whole-markdown read whose closing fence the edit replaced or appended past is unfenced too,
+note's stored body is kept; a whole-markdown read whose closing fence the edit replaced or appended past, or whose line endings it converted to CRLF, is unfenced too,
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 read
is kept whole). A remote `put_page` whose content holds a
tool-call summary that a whole read of the stored page never produces, or
@@ -148,9 +148,10 @@ into `takes_add`, `takes_update` or `takes_supersede`, is stored without the fen
tracked 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); a remote `get_page` or `fetch` of such a page carries a
-`quoted_unverified_origin` notice naming those commands, once per session. 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.
+`quoted_unverified_origin` notice naming those commands, once per session. A quoted page's title is quoted on
+`get_page`, `fetch` and search and `query` rows, and its tags on `get_page`, `fetch` and `get_tags` (`add_tag` and
+`remove_tag` take a copied tag without the fence); a context card below "your notes" carries its title under the
+card's trust label, as its summary does; a chronicle entry's `kind` is quoted by its event page's tier. Local reads are unchanged.
`effective_date` is the page's own date and `effective_date_source` says
which kind: `date`, `published` or `filename` is a document date,
diff --git a/scripts/postgres-arm-weights.json b/scripts/postgres-arm-weights.json
index a9a773f07d..f19a869e87 100644
--- a/scripts/postgres-arm-weights.json
+++ b/scripts/postgres-arm-weights.json
@@ -442,6 +442,7 @@
"test/search-read-keyword-bound.test.ts": 5120,
"test/search-remote-page-cap.test.ts": 7365,
"test/search-transcript-quote-8384.test.ts": 16171,
+ "test/search-transcript-quote-8384b.test.ts": 8866,
"test/search-transcript-quote-budget.test.ts": 6435,
"test/search-transcript-quote-coverage.test.ts": 18524,
"test/search-transcript-quote-followups.test.ts": 11639,
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 75b050809b..8096efd9c8 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1396,6 +1396,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.538.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, add_timeline_entry and the takes writes 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.' },
// #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.540.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.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/chronicle/narrative.ts b/src/core/chronicle/narrative.ts
index 6b88716f61..57e72b7f19 100644
--- a/src/core/chronicle/narrative.ts
+++ b/src/core/chronicle/narrative.ts
@@ -14,9 +14,9 @@ export function renderTimelineNarrative(rows: ChronicleTimelineRow[]): string {
const lines: string[] = [];
for (const [date, rs] of byDate) {
const head = `${date} — ${rs.length} event${rs.length === 1 ? '' : 's'}:`;
- // A quoted summary (GST-687, a fenced block) keeps its fence whole: each event on its own lines, the kind above it.
- if (rs.some((r) => r.summary.includes('\n'))) {
- lines.push(head, ...rs.map((r) => (r.kind ? `(${r.kind})\n${r.summary}` : r.summary)));
+ // A quoted summary or kind (GST-687, #8384, a fenced block) keeps its fence whole: each event on its own lines, the kind above it.
+ if (rs.some((r) => r.summary.includes('\n') || r.kind?.includes('\n'))) {
+ lines.push(head, ...rs.map((r) => (r.kind ? `${r.kind.includes('\n') ? r.kind : `(${r.kind})`}\n${r.summary}` : r.summary)));
continue;
}
lines.push(`${head} ${rs.map((r) => (r.kind ? `${r.summary} (${r.kind})` : r.summary)).join('; ')}`);
diff --git a/src/core/context/turn-context.ts b/src/core/context/turn-context.ts
index 5b4bbf45f0..8451c57b1d 100644
--- a/src/core/context/turn-context.ts
+++ b/src/core/context/turn-context.ts
@@ -51,7 +51,7 @@ import { pageActivationVerdicts, pageKey, suppressionSummary, type SuppressionSu
import { renderTrustedInline, trustFields, type TrustFields } from '../eligibility/labels.ts';
import { TURN_CONTEXT_ENVELOPE } from './turn-context-envelope.ts';
import { neutralizeForPrompt } from '../think/sanitize.ts';
-import { quoteFacts, unquoteFactText } from '../search/transcript-quote.ts';
+import { quoteFacts, quotesTier, unquoteFactText } from '../search/transcript-quote.ts';
/**
* v0.45.7 ambient recall (issue #1). The per-turn assembler is extended into the
@@ -667,7 +667,7 @@ async function assemblePack(
{ excludePrivate, keepVisibility: remote ? ['world'] : ['private', 'world'], charBudget: left, eligibility: policy, includeQuarantined: opts.includeQuarantined === true });
if (!m) continue;
acc.mentions.set(keyOf(card), m);
- left -= renderNewerMentionLines({ ...card, newer_mentions: m }, sources[0]).join('\n').length + 1;
+ left -= renderNewerMentionLines({ ...card, newer_mentions: m }, sources[0], opts.untrusted === true).join('\n').length + 1;
}
})();
@@ -692,7 +692,7 @@ async function assemblePack(
const openThreads = cards
.flatMap((c) => c.open_threads ?? [])
.filter((t) => !since || (t.date !== null && isAfter(t.date, since)));
- const text = renderPack(cards, openThreads, facts, opts.checkpointLinks, sources[0], entityFacts);
+ const text = renderPack(cards, openThreads, facts, opts.checkpointLinks, sources[0], entityFacts, opts.untrusted === true);
return {
text,
pointers: [],
@@ -930,11 +930,13 @@ const labeled = (item: { trust_tier?: TrustTier; origin?: string }, text: string
item.trust_tier ? renderTrustedInline(text, labelOf(item)) : text;
const cardSummary = (c: EntityCard, text: string): string =>
c.quarantined ? renderTrustedInline(text, { trust_tier: 'external_untrusted', origin: 'quarantined' }) : labeled(c, text);
+/** #8384: for an untrusted reader a card below the owner's tier carries its title under the card's label too; otherwise as stored. */
+const cardTitle = (c: EntityCard, untrusted: boolean): string => (untrusted && c.trust_tier && quotesTier(c.trust_tier) ? cardSummary(c, c.entity.title) : c.entity.title);
/** #6723: a card from outside the pack's home source names its source, so a follow-up reads the right page. */
const sourceNote = (c: EntityCard, home?: string): string =>
home !== undefined && c.entity.source_id !== undefined && c.entity.source_id !== home ? ` (source ${c.entity.source_id})` : '';
-export const renderCardLine = (c: EntityCard, home?: string): string =>
- `- **${c.entity.title}** → \`${c.entity.slug}\`${sourceNote(c, home)}${c.summary ? ` — ${cardSummary(c, c.summary)}` : c.trust_tier ? ` — ${cardSummary(c, '')}` : ''}${c.relationship_note ? ` [${c.relationship_note}]` : ''} (use get_page/entity before relying on details)`;
+export const renderCardLine = (c: EntityCard, home?: string, untrusted = false): string =>
+ `- **${cardTitle(c, untrusted)}** → \`${c.entity.slug}\`${sourceNote(c, home)}${c.summary ? ` — ${cardSummary(c, c.summary)}` : c.trust_tier ? ` — ${cardSummary(c, '')}` : ''}${c.relationship_note ? ` [${c.relationship_note}]` : ''} (use get_page/entity before relying on details)`;
export const renderThreadLine = (t: EntityOpenThread): string =>
`- [${t.kind}] ${labeled(t, t.text)}${t.date ? ` (${t.date})` : ''}`;
/** A quoted fact's fence closes on its own line (GST-687): its label rides the marker line and the slug and confidence follow the fence. */
@@ -951,11 +953,11 @@ const factDedupeKeys = (f: TurnContextFact): string[] =>
export const renderPageLine = (p: DeltaPage): string => `- **${labeled(p, p.title)}** → \`${p.slug}\` (${p.updated_at})`;
/** One card's newer-mentions block: a line naming the entity and its page date, then one line per page. [] when there are none. */
-export const renderNewerMentionLines = (c: EntityCard, home?: string): string[] => {
+export const renderNewerMentionLines = (c: EntityCard, home?: string, untrusted = false): string[] => {
const m = c.newer_mentions;
if (!m?.rows.length) return [];
return [
- `- **${c.entity.title}** (\`${c.entity.slug}\`${sourceNote(c, home)}, page dated ${m.since.slice(0, 10)}):`,
+ `- **${cardTitle(c, untrusted)}** (\`${c.entity.slug}\`${sourceNote(c, home)}, page dated ${m.since.slice(0, 10)}):`,
...m.rows.map(renderNewerMentionRow),
...(m.more ? [` - more pages dated after ${m.since.slice(0, 10)} mention it: entity("${c.entity.slug}"${sourceNote(c, home) ? `, source_id "${c.entity.source_id}"` : ''}) lists them all`] : []),
];
@@ -984,6 +986,7 @@ export function renderPack(
checkpointLinks?: TurnContextResult['checkpointLinks'],
home?: string,
entityFacts: TurnContextFact[] = [],
+ untrusted = false,
): string {
const links = checkpointLinks ?? [];
const shown = new Set(entityFacts.map((f) => f.id));
@@ -1000,11 +1003,11 @@ export function renderPack(
're-pull with get_page. Trust these links over the compaction summary.',
);
}
- if (cards.length) lines.push('', PACK_HEADERS[0], ...cards.map((c) => renderCardLine(c, home)));
+ if (cards.length) lines.push('', PACK_HEADERS[0], ...cards.map((c) => renderCardLine(c, home, untrusted)));
if (openThreads.length) lines.push('', PACK_HEADERS[1], ...openThreads.map(renderThreadLine));
if (entityFacts.length) lines.push('', ENTITY_FACTS_HEADER, ...entityFacts.map(renderFactLine));
if (hot.length) lines.push('', PACK_HEADERS[2], ...hot.map(renderFactLine));
- const mentionLines = cards.flatMap((c) => renderNewerMentionLines(c, home));
+ const mentionLines = cards.flatMap((c) => renderNewerMentionLines(c, home, untrusted));
if (mentionLines.length) lines.push('', NEWER_MENTIONS_HEADER, ...mentionLines);
return lines.join('\n');
}
diff --git a/src/core/ops/chronicle.ts b/src/core/ops/chronicle.ts
index 583eee373e..9fe3302281 100644
--- a/src/core/ops/chronicle.ts
+++ b/src/core/ops/chronicle.ts
@@ -12,7 +12,7 @@ import type { ChronicleTimelineRow, OntologyValue } from '../types.ts';
import { readPolicyOpts, sourceScopeOpts } from './context.ts';
import { invalidParam } from './op-fix.ts';
import { quoteTimelineRows } from './timeline-quote.ts';
-import { quoteFacts, unquoteFactText } from '../search/transcript-quote.ts';
+import { quoteFacts, quotePageText, quotesStored, unquoteFactText } from '../search/transcript-quote.ts';
// ── Remote diary redaction (fail-closed) ─────────────────────────────────
// The exact mechanism the ontology siblings use (`ctx.remote !== false` →
@@ -30,9 +30,21 @@ function redactDiaryTimeline<
!(r.event_slug ?? '').startsWith(DIARY_PREFIX) &&
!(r.source ?? '').includes(DIARY_PREFIX));
}
-/** The rows a remote reader gets: diary rows redacted, then each entry below the owner's tier quoted as its own page's (GST-687). */
-function remoteTimeline(ctx: OperationContext, rows: ChronicleTimelineRow[]) {
- return quoteTimelineRows(ctx, r => r.page_slug, redactDiaryTimeline(ctx, rows));
+/**
+ * The rows a remote reader gets: diary rows redacted, then each entry below the owner's tier quoted as its own page's (GST-687),
+ * and an event projection's `kind` (its event page's frontmatter) quoted by that event page's type and tier (#8384).
+ */
+async function remoteTimeline(ctx: OperationContext, rows: ChronicleTimelineRow[]) {
+ const quoted = await quoteTimelineRows(ctx, r => r.page_slug, redactDiaryTimeline(ctx, rows));
+ const events = quoted.flatMap(r => (r.kind ? [Number(r.event_page_id)] : []));
+ if (ctx.remote === false || events.length === 0) return quoted;
+ const pages = new Map((await ctx.engine.executeRaw<{ id: number | string; type: string | null; trust_tier: string | null }>(
+ 'SELECT id, type, trust_tier FROM pages WHERE id = ANY($1::bigint[])', [[...new Set(events)]])).map(p => [Number(p.id), p]));
+ return quoted.map(r => {
+ const page = pages.get(Number(r.event_page_id));
+ return r.kind && quotesStored(page?.type, page?.trust_tier)
+ ? { ...r, kind: quotePageText(r.kind, r.event_slug ?? r.page_slug, page?.type), quoted: 'transcript' as const } : r;
+ });
}
/** #8384: ontology values a remote reader gets, each quoted by its fact's stored tier as recall quotes the fact (quoteFacts). */
async function remoteOntology<V extends Pick<OntologyValue, 'value' | 'source' | 'fact_id'>>(ctx: OperationContext, values: V[]): Promise<Array<V & { quoted?: 'transcript' }>> {
diff --git a/src/core/ops/facts.ts b/src/core/ops/facts.ts
index bc6bb3ab65..3fbc600745 100644
--- a/src/core/ops/facts.ts
+++ b/src/core/ops/facts.ts
@@ -854,7 +854,7 @@ const context_pack: Operation = {
// rendered line plus its rendered (since-filtered) thread lines.
const itemBudget = budgetTokens - packHeaderCost() - coreTokens - (pullBrief?.text ? estimateTokens(pullBrief.text) : 0);
const cardCost = (c: (typeof cards)[number]) =>
- lineCost(renderCardLine(c, walk.home)) + threadsOf(c).reduce((n, t) => n + lineCost(renderThreadLine(t)), 0);
+ lineCost(renderCardLine(c, walk.home, ctx.remote !== false)) + threadsOf(c).reduce((n, t) => n + lineCost(renderThreadLine(t)), 0);
const cardPack = itemBudget > 0 ? packToBudget(cards, cardCost, itemBudget) : dropAll(cards);
cards = cardPack.items;
// #6724: a dropped card's facts go with it; entity facts pack before hot memory, and a fact in both is priced once.
@@ -871,7 +871,7 @@ const context_pack: Operation = {
const mentionBudget = remaining - factPack.meta.used - lineCost('') - lineCost(NEWER_MENTIONS_HEADER);
const withMentions = cards.filter((c) => c.newer_mentions);
const mentionPack = mentionBudget > 0
- ? packToBudget(withMentions, (c) => renderNewerMentionLines(c, walk.home).reduce((n, l) => n + lineCost(l), 0), mentionBudget)
+ ? packToBudget(withMentions, (c) => renderNewerMentionLines(c, walk.home, ctx.remote !== false).reduce((n, l) => n + lineCost(l), 0), mentionBudget)
: dropAll(withMentions);
const keptMentions = new Set(mentionPack.items);
cards = cards.map((c) => (c.newer_mentions && !keptMentions.has(c) ? { ...c, newer_mentions: undefined } : c));
@@ -891,7 +891,7 @@ const context_pack: Operation = {
// structured arrays report — the assembler's pre-budget rendering would
// overrun the declared budget_tokens. budget_used reports that text.
const recordLines = cards.flatMap(renderRecordLines);
- const basePack = entities.length === 0 ? '' : budgetTokens !== null ? renderPack(cards, open_threads, facts, undefined, walk.home, entityFacts) : res.text;
+ const basePack = entities.length === 0 ? '' : budgetTokens !== null ? renderPack(cards, open_threads, facts, undefined, walk.home, entityFacts, ctx.remote !== false) : res.text;
const packText = recordLines.length ? [basePack, ['', RECORDS_HEADER, ...recordLines].join('\n')].filter(Boolean).join('\n') : basePack;
const text = [coreText, pullBrief?.text ?? '', packText].filter(Boolean).join('\n\n');
const budgetUsed = budgetTokens !== null ? estimateTokens(text) : undefined;
diff --git a/src/core/ops/get-page-body.ts b/src/core/ops/get-page-body.ts
index 9be64f1ad0..90201c619a 100644
--- a/src/core/ops/get-page-body.ts
+++ b/src/core/ops/get-page-body.ts
@@ -468,7 +468,7 @@ export async function readPartialBody(ctx: OperationContext, input: PartialReadI
const neutralize = input.neutralize === true && req.view !== 'markdown';
const wrap = (text: string) => envelopeText(neutralize && text ? neutralizeToolCalls(text) : text, quarantined, trust, input.quote ? page.slug : null);
const base: Record<string, unknown> = {
- slug: page.slug, source_id: page.source_id, type: page.type, revision, tags, ...quotedPageMeta({ slug: page.slug, title: page.title, frontmatter: page.frontmatter ?? {} }, input.quote === true),
+ slug: page.slug, source_id: page.source_id, type: page.type, revision, ...quotedPageMeta({ slug: page.slug, title: page.title, frontmatter: page.frontmatter ?? {} }, input.quote === true, tags),
...(page.deleted_at ? { deleted_at: page.deleted_at } : {}),
...(trust ?? {}), ...extras, ...(input.quote ? { quoted: 'transcript' } : {}),
};
@@ -607,13 +607,14 @@ export async function fetchWindowResult(ctx: OperationContext, input: PartialRea
const { page, revision, tags, quarantined, trust } = input;
const { partial, anchorStatus } = await readFetchWindow(ctx, input, anchor);
const w = partial.window ?? { text: '' };
+ const meta = quotedPageMeta(page, input.quote === true, tags);
return {
id,
- title: quotedPageMeta(page, input.quote === true).title,
+ title: meta.title,
text: w.text,
url: deepResearchPageUrl(page.source_id, page.slug),
metadata: {
- revision, type: page.type, source_id: page.source_id, updated_at: page.updated_at, tags, ...(quarantined ? { quarantined } : {}), ...(trust ?? {}),
+ revision, type: page.type, source_id: page.source_id, updated_at: page.updated_at, tags: meta.tags, ...(quarantined ? { quarantined } : {}), ...(trust ?? {}),
...(input.quote ? { quoted: 'transcript' } : {}), truncated: true, total_bytes: partial.size?.total_bytes, anchor: anchorStatus,
...(typeof w.byte_start === 'number' ? { window: { byte_start: w.byte_start, byte_end: w.byte_end, line_start: w.line_start, line_end: w.line_end } } : {}),
...(partial.next_cursor ? { next_id: encodeDeepResearchId(page.source_id, page.slug, { cursor: partial.next_cursor }) } : {}),
diff --git a/src/core/ops/get-page-projection.ts b/src/core/ops/get-page-projection.ts
index f05ce0285f..bac3478995 100644
--- a/src/core/ops/get-page-projection.ts
+++ b/src/core/ops/get-page-projection.ts
@@ -80,15 +80,15 @@ function enveloped(text: string, fields: TrustFields | undefined): string {
}
/**
- * #8377: a quoted page's title and frontmatter as an untrusted reader gets them, each string fenced as `slug`'s
- * (frontmatter keys stay); with `quote` false, as stored. The round-trip `content` is fenced whole instead.
+ * #8377: a quoted page's title and frontmatter (#8384: and its tags) as an untrusted reader gets them, each string fenced
+ * as `slug`'s (frontmatter keys stay); with `quote` false, as stored. The round-trip `content` is fenced whole instead.
*/
-export function quotedPageMeta(page: Pick<Page, 'slug' | 'title' | 'frontmatter'>, quote: boolean): Pick<Page, 'title' | 'frontmatter'> {
- if (!quote) return { title: page.title, frontmatter: page.frontmatter };
+export function quotedPageMeta(page: Pick<Page, 'slug' | 'title' | 'frontmatter'>, quote: boolean, tags: string[] = []): Pick<Page, 'title' | 'frontmatter'> & { tags: string[] } {
+ if (!quote) return { title: page.title, frontmatter: page.frontmatter, tags };
const fence = (value: unknown): unknown => typeof value === 'string' ? (value ? fenceTranscriptText(value, page.slug) : value)
: Array.isArray(value) ? value.map(fence)
: value && typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, fence(v)])) : value;
- return { title: fence(page.title) as string, frontmatter: fence(page.frontmatter ?? {}) as Page['frontmatter'] };
+ return { title: fence(page.title) as string, frontmatter: fence(page.frontmatter ?? {}) as Page['frontmatter'], tags: fence(tags) as string[] };
}
export interface GetPageProjectionOpts {
@@ -141,7 +141,8 @@ export function projectGetPage(stored: Page, o: GetPageProjectionOpts) {
const fence = (text: string) => (text ? fenceTranscriptText(text, stored.slug) : text);
const summarize = o.neutralize === true && (!o.includeContent || o.readingContent === true);
const plain = summarize ? { ...stored, compiled_truth: stored.compiled_truth && neutralizeToolCalls(stored.compiled_truth), timeline: stored.timeline && neutralizeToolCalls(stored.timeline) } : stored;
- const page = o.quote ? { ...plain, ...quotedPageMeta(stored, true), compiled_truth: fence(plain.compiled_truth), timeline: fence(plain.timeline) } : stored;
+ const { tags: shownTags, ...meta } = quotedPageMeta(stored, o.quote === true, tags);
+ const page = o.quote ? { ...plain, ...meta, compiled_truth: fence(plain.compiled_truth), timeline: fence(plain.timeline) } : stored;
const omitted = quarantined?.body_omitted === true;
const wrap = quarantined?.body_enveloped === true;
const visibleBody = omitted ? { ...page, compiled_truth: '', timeline: '' }
@@ -164,7 +165,7 @@ export function projectGetPage(stored: Page, o: GetPageProjectionOpts) {
type: visibleBody.type,
title: visibleBody.title,
revision,
- tags,
+ tags: shownTags,
...(text === undefined ? {} : { content: text }),
chars: text?.length ?? 0,
...(deletedAt ? { deleted_at: deletedAt } : {}),
@@ -175,7 +176,7 @@ export function projectGetPage(stored: Page, o: GetPageProjectionOpts) {
return {
...visibleBody,
revision,
- tags,
+ tags: shownTags,
...(text === undefined ? {} : { content: text }),
chars: (visibleBody.compiled_truth ?? '').length + (visibleBody.timeline ?? '').length + (text?.length ?? 0),
// #5575 A6: the reading shape carries the page's trust; the content_only round-trip shape stays minimal.
diff --git a/src/core/ops/pages.ts b/src/core/ops/pages.ts
index cb47658f86..367ed73f1a 100644
--- a/src/core/ops/pages.ts
+++ b/src/core/ops/pages.ts
@@ -313,9 +313,10 @@ const fetch_page: Operation = {
const pin = authorizedReadPin(ctx, page, snapshot!.bodyGeneration, p.min_trust, missing);
return fetchWindowResult(ctx, { page, visibleBody: visibleBody as Page, revision: snapshot!.revision, tags, quarantined, trust: readable.trust, extras: {}, pin, quote: quotesBody(ctx, page, readable.trust), neutralize: neutralizesBody(ctx, page) }, id, identity ? decodeDeepResearchAnchor(id) : null);
}
+ const meta = quotedPageMeta(page, quotesBody(ctx, page, readable.trust), tags);
return {
id: identity ? id : page.slug,
- title: quotedPageMeta(page, quotesBody(ctx, page, readable.trust)).title,
+ title: meta.title,
text: projectFetchText(visibleBody as Page, tags, quarantined, readable.trust, quotesBody(ctx, page, readable.trust), neutralizesBody(ctx, page)),
// Pages have no public http home; a stable brain-local URI satisfies
// the contract's citation slot without inventing a fake web URL.
@@ -325,7 +326,7 @@ const fetch_page: Operation = {
type: page.type,
source_id: page.source_id,
updated_at: page.updated_at,
- tags, ...(quarantined ? { quarantined } : {}), ...readable.trust, ...(quotesBody(ctx, page, readable.trust) ? { quoted: 'transcript' } : {}),
+ tags: meta.tags, ...(quarantined ? { quarantined } : {}), ...readable.trust, ...(quotesBody(ctx, page, readable.trust) ? { quoted: 'transcript' } : {}),
},
};
},
diff --git a/src/core/ops/tags.ts b/src/core/ops/tags.ts
index debacd7c8d..9521dad63a 100644
--- a/src/core/ops/tags.ts
+++ b/src/core/ops/tags.ts
@@ -5,13 +5,19 @@
* ../operations.ts. Never import from '../operations.ts' here (cycle).
*/
-import type { Operation } from './contract.ts';
+import type { Operation, OperationContext } from './contract.ts';
+import { fenceTranscriptText, quotesStored, unquoteTranscriptText } from '../search/transcript-quote.ts';
import { enforceClientSlugFence, readPolicyOpts } from './context.ts';
import { submitPageMutation } from '../persistence/page-mutations.ts';
import { MERGE_PRECONDITION_PARAMS, WRITE_REQUEST_PARAM } from '../persistence/params.ts';
// --- Tags ---
+/** #8384: a remote caller's tag copied out of a quoted read (get_tags, get_page, fetch) names the tag, not its fence. */
+function unquotedTag(ctx: OperationContext, p: Record<string, unknown>): Record<string, unknown> {
+ return ctx.remote === false || typeof p.tag !== 'string' || typeof p.slug !== 'string' ? p : { ...p, tag: unquoteTranscriptText(p.tag, p.slug.toLowerCase()) };
+}
+
const add_tag: Operation = {
name: 'add_tag',
idempotent: true,
@@ -29,7 +35,7 @@ const add_tag: Operation = {
enforceClientSlugFence(ctx, p.slug as string, 'add_tag');
if (ctx.dryRun) return { dry_run: true, action: 'add_tag', slug: p.slug, tag: p.tag };
// v0.31.8 (D7): thread ctx.sourceId.
- return submitPageMutation(ctx, { operation: 'add_tag', params: p });
+ return submitPageMutation(ctx, { operation: 'add_tag', params: unquotedTag(ctx, p) });
},
cliHints: { name: 'tag', positional: ['slug', 'tag'] },
};
@@ -50,7 +56,7 @@ const remove_tag: Operation = {
handler: async (ctx, p) => {
enforceClientSlugFence(ctx, p.slug as string, 'remove_tag');
if (ctx.dryRun) return { dry_run: true, action: 'remove_tag', slug: p.slug, tag: p.tag };
- return submitPageMutation(ctx, { operation: 'remove_tag', params: p });
+ return submitPageMutation(ctx, { operation: 'remove_tag', params: unquotedTag(ctx, p) });
},
cliHints: { name: 'untag', positional: ['slug', 'tag'] },
};
@@ -72,12 +78,18 @@ const get_tags: Operation = {
// Untrusted callers never learn a private or soft-deleted page's tags
// (readPolicyOpts resolves the operator's private-pages posture).
const policy = await readPolicyOpts(ctx);
- return ctx.engine.getTags(p.slug as string, {
+ const tags = await ctx.engine.getTags(p.slug as string, {
sourceId: policy.sourceId,
sourceIds: policy.sourceIds,
excludePrivate: policy.excludePrivate,
liveOnly: ctx.remote !== false,
});
+ if (ctx.remote === false || tags.length === 0) return tags;
+ // #8384: a remote reader gets a quoted page's tags quoted, as get_page and fetch return them.
+ const pages = await ctx.engine.executeRaw<{ type: string | null; trust_tier: string | null }>(
+ 'SELECT type, trust_tier FROM pages WHERE slug = $1 AND source_id = ANY($2::text[]) AND deleted_at IS NULL',
+ [p.slug, policy.sourceIds?.length ? policy.sourceIds : [policy.sourceId ?? 'default']]);
+ return pages.length && pages.every(r => !quotesStored(r.type, r.trust_tier)) ? tags : tags.map(t => fenceTranscriptText(t, p.slug as string));
},
scope: 'read',
cliHints: { name: 'tags', positional: ['slug'] },
diff --git a/src/core/persistence/page-mutations.ts b/src/core/persistence/page-mutations.ts
index a3342e9caa..b1ebc693ac 100644
--- a/src/core/persistence/page-mutations.ts
+++ b/src/core/persistence/page-mutations.ts
@@ -23,7 +23,7 @@ import { assertTimelineNotOmitted, isTimelineSection, timelineSectionOf, type Ti
import { contentOriginTier } from '../trust/tier.ts';
import { PAGE_MAX_BYTES } from '../page-size-policy.ts';
import { contentSizeHold, frontmatterBodyOffset, parseMarkdownHead } from '../markdown.ts';
-import { dataFrontmatter } from '../data-frontmatter.ts';
+import { dataFrontmatter, dumpFrontmatterYaml } 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';
@@ -273,13 +273,32 @@ 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.
*/
function unquotedFrontmatter(sent: string, content: string, slug: string): string {
const offset = frontmatterBodyOffset(content);
if (!offset || !frontmatterBodyOffset(sent) || !content.slice(0, offset).includes('```text')) return content;
const { frontmatter } = parseMarkdownHead(content);
const data = unquotedStrings(frontmatter, slug) as Record<string, unknown>;
- return JSON.stringify(data) === JSON.stringify(frontmatter) ? content : dataFrontmatter.stringify('', data) + content.slice(offset);
+ const fenced = new Set(Object.keys(data).filter(k => JSON.stringify(data[k]) !== JSON.stringify(frontmatter[k])));
+ if (!fenced.size) return content;
+ const lines = content.slice(0, offset).split('\n');
+ const open = lines.findIndex(l => l.trim() === '---');
+ const close = lines.findIndex((l, i) => i > open && l.trim() === '---');
+ const out = lines.slice(0, open + 1);
+ for (let i = open + 1; i < close;) {
+ let end = i + 1;
+ while (end < close && /^(?:[ \t]|-(?:[ \t]|\r?$)|\r?$)/.test(lines[end]!)) end++;
+ const m = /^(?:"([^"]*)"|'([^']*)'|([^\s#'"-][^:]*?))[ \t]*:(?:[ \t]|\r?$)/.exec(lines[i]!);
+ const key = m?.[1] ?? m?.[2] ?? m?.[3];
+ if (key !== undefined && fenced.delete(key)) {
+ const eol = lines[i]!.endsWith('\r') ? '\r' : '';
+ out.push(...dumpFrontmatterYaml({ [key]: data[key] }).trimEnd().split('\n').map(l => l + eol));
+ } 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);
}
async function unquotedPutContent(engine: BrainEngine, sourceId: string, slug: string, content: string): Promise<string> {
diff --git a/src/core/search/evidence-delivery.ts b/src/core/search/evidence-delivery.ts
index 8601dccc09..f803d02a2f 100644
--- a/src/core/search/evidence-delivery.ts
+++ b/src/core/search/evidence-delivery.ts
@@ -28,7 +28,7 @@ import { estimateTokens as cl100kTokens, cl100kAvailable } from '../chunkers/tok
import { estimateTokens as heuristicTokens } from './token-budget.ts';
import { redactRetrievalOutput } from './output-redaction.ts';
import { buildSnippetMarker } from './snippet-cap.ts';
-import { deliveredQuoteText, fenceTranscriptRows, neutralizeTranscriptRows } from './transcript-quote.ts';
+import { deliveredQuoteText, deliveredQuoteTitle, fenceTranscriptRows, neutralizeTranscriptRows } from './transcript-quote.ts';
import { stampPageTrust } from '../eligibility/stamp.ts';
import { pageReadFilter } from './read-policy-sql.ts';
import { chunkGenerationFilter, chunkManifestReads, currentTextProjectionFilter, safeChunksFilter, requiresSafeChunks } from './safe-chunks.ts';
@@ -1465,7 +1465,7 @@ function redactDelivered(results: DeliveredSearchResult[], tokenizer: 'cl100k' |
* and `dropped` are rewritten from the recount. Runs only when the delivery
* carries `auto_packing`; everything else is returned as is. With `quote`
* (search/query and assemble_evidence) a conversation row counts inside its
- * quote fence (#7600), and with `untrusted` (a remote reader) so does a row below the owner's tier (GST-687);
+ * quote fence (#7600), and with `untrusted` (a remote reader) so does a row below the owner's tier (GST-687), its title included (#8384);
* deliverEvidence's own cap (recall) counts the text as returned.
*/
export function capEvidenceToBudget<T extends SearchResult & { delivered?: DeliveredEvidence }>(results: T[], delivery: DeliveryMeta, quote = false, untrusted = false): T[] {
@@ -1478,7 +1478,8 @@ export function capEvidenceToBudget<T extends SearchResult & { delivered?: Deliv
const out: T[] = [];
for (const r of results) {
const asDelivered = (text: string) => (quote ? deliveredQuoteText(r, text, delivery.date_header === true, untrusted) : text);
- const titleTok = count(r.title);
+ const asTitle = (title: string) => (quote ? deliveredQuoteTitle(r, title, untrusted) : title);
+ const titleTok = count(asTitle(r.title ?? ''));
const textTok = count(asDelivered(r.chunk_text));
if (titleTok + textTok <= remaining) {
remaining -= titleTok + textTok;
@@ -1489,19 +1490,19 @@ export function capEvidenceToBudget<T extends SearchResult & { delivered?: Deliv
const quoted = asDelivered(source) !== source;
const fenceTok = quoted ? count(asDelivered(source)) - count(source) : 0;
if (out.length > 0 && remaining - titleTok - cutTok - fenceTok < CUT_BODY_MIN) { lost++; continue; }
- const titleRoom = Math.max(0, remaining - cutTok - fenceTok - CUT_BODY_MIN);
- const title = titleTok > titleRoom ? sliceToTokenCount(r.title ?? '', titleRoom, tokenizer) : r.title ?? '';
- let room = remaining - count(title) - cutTok - fenceTok;
+ const titleRoom = Math.max(0, remaining - cutTok - fenceTok - (titleTok - count(r.title)) - CUT_BODY_MIN);
+ const title = count(r.title) > titleRoom ? sliceToTokenCount(r.title ?? '', titleRoom, tokenizer) : r.title ?? '';
+ let room = remaining - count(asTitle(title)) - cutTok - fenceTok;
let body = '';
let text = '';
for (;;) {
body = sliceToTokenCount(source, Math.max(0, room), tokenizer).replace(/\s+$/, '');
text = body + EVIDENCE_CUT_MARKER;
- const over = count(title) + count(asDelivered(text)) - remaining;
+ const over = count(asTitle(title)) + count(asDelivered(text)) - remaining;
if (!quoted || over <= 0 || room <= 0) break;
room -= over;
}
- remaining -= count(title) + count(asDelivered(text));
+ remaining -= count(asTitle(title)) + count(asDelivered(text));
const row = { ...r, title, chunk_text: text } as T;
if (r.delivered) {
const spans = r.delivered.match_spans.filter(s => s.start < body.length).map(s => ({ ...s, end: Math.min(s.end, body.length) }));
diff --git a/src/core/search/transcript-quote.ts b/src/core/search/transcript-quote.ts
index 1b57911ff0..02eefeb440 100644
--- a/src/core/search/transcript-quote.ts
+++ b/src/core/search/transcript-quote.ts
@@ -76,7 +76,7 @@ const MAX_CANDIDATES = 64;
const SCAN_WORK_PER_CHAR = 8;
const SCAN_WORK_FLOOR = 65536;
-type Row = Pick<SearchResult, 'slug' | 'type' | 'chunk_text' | 'result_type' | 'quoted' | 'fact_id' | 'fact_row' | 'trust_tier'>;
+type Row = Pick<SearchResult, 'slug' | 'type' | 'chunk_text' | 'result_type' | 'quoted' | 'fact_id' | 'fact_row' | 'trust_tier'> & { title?: string };
type Span = { start: number; end: number };
type Delivered = { tokens: number; match_spans: Span[] };
interface Edit { start: number; end: number; text: string }
@@ -522,15 +522,18 @@ export async function quoteFacts<T extends { id: number; fact: string; source?:
* The text with every fence a remote get_page put around `slug`'s body (get-page-projection.ts, get-page-body.ts) removed,
* so a remote get → edit → put_page round trip writes the body, never the fence, and a thin client's paged windows join
* to the bytes the host hashed (cli/page-render.ts). Only a marker line naming this slug followed by its own fence is
- * removed; anything else is kept. Callers apply it only to a page get_page quotes (`isQuotedPageType`). With `unclosed`
+ * removed (#8384: lines ending in CRLF too, as an editor converting line endings leaves them); anything else is kept. Callers apply it only to a page get_page quotes (`isQuotedPageType`). With `unclosed`
* (put_page, whose content is a whole-markdown read an agent edited), a fence opening the text whose closing line the edit
* replaced is removed too, so the page is not stored with its read's marker and its frontmatter inside the body.
*/
export function unquoteTranscriptText(text: string, slug: string, unclosed = false): string {
- const marker = `${markerLine(slug)}\n`;
+ const marker = markerLine(slug);
return unquoteMarked(text, from => {
- const i = text.indexOf(marker, from);
- return i < 0 ? null : { i, length: marker.length };
+ for (let i = text.indexOf(marker, from); i >= 0; i = text.indexOf(marker, i + 1)) {
+ const eol = text.startsWith('\n', i + marker.length) ? 1 : text.startsWith('\r\n', i + marker.length) ? 2 : 0;
+ if (eol) return { i, length: marker.length + eol };
+ }
+ return null;
}, unclosed);
}
@@ -554,13 +557,14 @@ function unquoteMarked(text: string, find: (from: number) => { i: number; length
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));
+ const open = /^(`{3,})text(\r?)\n/.exec(text.slice(i + length));
const start = i + length + (open?.[0].length ?? 0);
const close = open ? closingLine(text, start, open[1], work) : null;
if (close === 'spent') break;
if (!close && unclosed && open && at === 0 && !text.slice(0, i).trim()) return text.slice(start);
if (!close) { out += text.slice(at, i + length); at = i + length; continue; }
- out += (unclosed && at === 0 && !text.slice(0, i).trim() ? '' : text.slice(at, i)) + text.slice(start, close.end);
+ const end = open![2] && text[close.end - 1] === '\r' ? close.end - 1 : close.end;
+ out += (unclosed && at === 0 && !text.slice(0, i).trim() ? '' : text.slice(at, i)) + text.slice(start, end);
at = close.after;
}
return out + text.slice(at);
@@ -612,12 +616,19 @@ export function deliveredQuoteText(row: Row, text: string, header = false, untru
return 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). */
+export function deliveredQuoteTitle(row: Row, title: string, untrusted: boolean): string {
+ const label = untrusted && title ? quoteLabel(row, true) : null;
+ return label === null ? title : fenceTranscriptText(title, label);
+}
+
/**
* Step 2, after the caps: transcript rows are fenced and marked
* `quoted: "transcript"`, and delivered match_spans move past the marker and
* fence lines. With `recount` (an evidence delivery), delivered.tokens is the
* fenced text's count and the delivery's tokens_delivered and budget_used move
- * by the difference. `untrusted` (a remote reader) also quotes rows below the owner's tier (quoteLabel).
+ * by the difference. `untrusted` (a remote reader) also quotes rows below the owner's tier (quoteLabel), and a quoted row's
+ * page title with it (#8384, deliveredQuoteTitle), as get_page quotes a quoted page's title; budget_used moves by its fence too.
*/
export function fenceTranscriptRows<T extends Row>(rows: T[], recount?: { count: (text: string) => number; delivery: { tokens_delivered: number; budget_used: number; date_header?: true } }, untrusted = false): T[] {
const header = recount?.delivery.date_header === true;
@@ -626,14 +637,16 @@ export function fenceTranscriptRows<T extends Row>(rows: T[], recount?: { count:
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!);
const d = (r as { delivered?: Delivered }).delivered;
- if (!d) return { ...r, chunk_text, quoted: 'transcript' } as T;
+ if (!d) return { ...r, chunk_text, ...title, quoted: 'transcript' } as T;
const headLen = headerLine(r.chunk_text, head).length;
const prefix = chunk_text.indexOf('\n', chunk_text.indexOf('\n', headLen) + 1) + 1 - headLen;
const tokens = recount ? recount.count(chunk_text) : d.tokens;
if (recount) { recount.delivery.tokens_delivered += tokens - d.tokens; recount.delivery.budget_used += tokens - d.tokens; }
const match_spans = (d.match_spans ?? []).map(s => (s.start < headLen ? s : { ...s, start: s.start + prefix, end: s.end + prefix }));
- return { ...r, chunk_text, quoted: 'transcript', delivered: { ...d, tokens, match_spans } } as T;
+ return { ...r, chunk_text, ...title, quoted: 'transcript', delivered: { ...d, tokens, match_spans } } as T;
});
}
diff --git a/test/get-page-federated-scope.test.ts b/test/get-page-federated-scope.test.ts
index d24fc381d7..b8bb17a2b6 100644
--- a/test/get-page-federated-scope.test.ts
+++ b/test/get-page-federated-scope.test.ts
@@ -30,6 +30,7 @@ import { importFromContent } from '../src/core/import-file.ts';
import { serializeMarkdown } from '../src/core/markdown.ts';
import { surfaceFileSource } from './helpers/source-surface.ts';
import { asOwner } from './helpers/owner-tier.ts';
+import { fenceTranscriptText } from '../src/core/search/transcript-quote.ts';
let engine: PGLiteEngine;
const get_page = operations.find(o => o.name === 'get_page')!;
@@ -340,7 +341,8 @@ describe('#2200 get_tags honors the federated grant', () => {
test('D3A same-slug-across-sources → union of tags', async () => {
const tags = await get_tags.handler(remoteCtx(['alpha', 'beta']), { slug: 'shared/dup' });
- expect((tags as string[]).sort()).toEqual(['alpha-only', 'beta-only']);
+ // #8384: the pages carry no trust declaration (`unknown`), so a remote reader gets their tags quoted.
+ expect((tags as string[]).sort()).toEqual(['alpha-only', 'beta-only'].map(t => fenceTranscriptText(t, 'shared/dup')));
});
});
diff --git a/test/get-tags-remote-privacy.test.ts b/test/get-tags-remote-privacy.test.ts
index 2cd7c2ab82..4229829eb4 100644
--- a/test/get-tags-remote-privacy.test.ts
+++ b/test/get-tags-remote-privacy.test.ts
@@ -8,6 +8,7 @@ import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { operations } from '../src/core/operations.ts';
import type { OperationContext } from '../src/core/operations.ts';
+import { fenceTranscriptText } from '../src/core/search/transcript-quote.ts';
let engine: PGLiteEngine;
const get_tags = operations.find(o => o.name === 'get_tags')!;
@@ -33,7 +34,8 @@ afterAll(async () => { await engine.disconnect(); });
describe('get_tags respects page visibility for remote callers', () => {
test('world page tags are visible to remote callers', async () => {
- expect(await get_tags.handler(ctxOf(true), { slug: 'notes/world' })).toEqual(['world-tag']);
+ // #8384: the page carries no trust declaration (`unknown`), so a remote reader gets its tags quoted.
+ expect(await get_tags.handler(ctxOf(true), { slug: 'notes/world' })).toEqual([fenceTranscriptText('world-tag', 'notes/world')]);
});
test('a private page returns no tags to a remote caller', async () => {
diff --git a/test/helpers/evidence-delivery-fixture.ts b/test/helpers/evidence-delivery-fixture.ts
index 88eff568c8..c676431f6b 100644
--- a/test/helpers/evidence-delivery-fixture.ts
+++ b/test/helpers/evidence-delivery-fixture.ts
@@ -120,11 +120,12 @@ function withFactsOrder(payload: Record<string, unknown>): Record<string, unknow
return Object.fromEntries(Object.entries(payload).flatMap(([k, v]) => k === 'total' ? [[k, v], ['facts_order', 'newest']] : [[k, v]]));
}
-/** GST-687's remote quote of one row: its text fenced as an excerpt of its slug and `quoted` set (recall places it before `trust_tier`). */
+/** GST-687's remote quote of one row: its text (#8384: and title) fenced as an excerpt of its slug and `quoted` set (recall places it before `trust_tier`). */
function quotedRow(row: Record<string, unknown>, field: 'chunk_text' | 'chunk'): Record<string, unknown> {
const text = row[field];
if (row.quoted !== undefined || typeof text !== 'string' || text.length === 0) return row;
- const fenced = { ...row, [field]: fenceTranscriptText(text, row.slug as string) };
+ const title = typeof row.title === 'string' && row.title ? { title: fenceTranscriptText(row.title, row.slug as string) } : {};
+ const fenced = { ...row, ...title, [field]: fenceTranscriptText(text, row.slug as string) };
if (field === 'chunk_text') return { ...fenced, quoted: 'transcript' };
return Object.fromEntries(Object.entries(fenced).flatMap(([k, v]) => k === 'trust_tier' ? [['quoted', 'transcript'], [k, v]] : [[k, v]]));
}
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index 3f918214ad..a46c644bc4 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -460,6 +460,7 @@ test/scripts/test-stress-postgres.test.ts
test/search-read-keyword-bound.test.ts
test/search-remote-page-cap.test.ts
test/search-transcript-quote-8384.test.ts
+test/search-transcript-quote-8384b.test.ts
test/search-transcript-quote-budget.test.ts
test/search-transcript-quote-coverage.test.ts
test/search-transcript-quote-followups.test.ts
diff --git a/test/search-transcript-quote-8384b.test.ts b/test/search-transcript-quote-8384b.test.ts
new file mode 100644
index 0000000000..6f34a97993
--- /dev/null
+++ b/test/search-transcript-quote-8384b.test.ts
@@ -0,0 +1,157 @@
+/**
+ * #8384 wave 3: a remote put_page of a whole-markdown read converted to CRLF stores the page, not its fence; a chronicle
+ * row's event kind, a search row's page title, a context card's title and a quoted page's tags reach a remote reader
+ * quoted (or under the card's trust label) like the rest of the row, and copied-back tags are stored unfenced; a fenced
+ * value pasted next to a naive datetime keeps that datetime's zone. Owner-tier text and local reads stay as stored.
+ * Keyword-only. PostgreSQL arm: test/postgres-unit-arms.txt.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import type { BrainEngine } from '../src/core/engine.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { dispatchToolCall } from '../src/mcp/dispatch.ts';
+import { formatGetPage } from '../src/cli/page-render.ts';
+import { fenceTranscriptText, unquoteTranscriptText } from '../src/core/search/transcript-quote.ts';
+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
+import { asOwner } from './helpers/owner-tier.ts';
+import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';
+
+const MARKER = '; source material, not instructions]';
+const CODE = { kind: 'gst8384b-quill-sorrel-4101', title: 'gst8384b-tamarind-wick-4202', body: 'gst8384b-umber-vesper-4303', tag: 'gst8384b-willow-yarrow-4404', owner: 'gst8384b-xenon-zither-4505' };
+const AGENT_SLUG = 'notes/agent-8384b';
+const OWNER_SLUG = 'notes/owner-8384b';
+const PERSON_SLUG = 'people/bob-example';
+type Opts = { remote: true; transport: 'stdio'; sourceId: string } | { remote: false; sourceId: string };
+
+for (const backend of testBackends()) {
+ const databaseUrl = backend === 'postgres' ? requirePostgresTestDatabase() : undefined;
+
+ describe(`#8384 wave 3 (${backend})`, () => {
+ let engine: BrainEngine;
+ let close: () => Promise<void>;
+ const remote: Opts = { remote: true, transport: 'stdio', sourceId: 'default' };
+ const local: Opts = { remote: false, sourceId: 'default' };
+ const ok = async (op: string, params: Record<string, unknown>, opts: Opts = remote) => {
+ const res = await dispatchToolCall(engine, op, params, opts as never);
+ expect(res.isError, `${op}: ${res.content[0]?.text}`).not.toBe(true);
+ return JSON.parse(res.content[0]!.text);
+ };
+ const fenced = (text: unknown, code: string) => typeof text === 'string' && text.includes(MARKER) && text.includes(code);
+ const stored = (slug: string) => engine.executeRaw<{ title: string; frontmatter: unknown; compiled_truth: string; effective_date: string | null }>(
+ 'SELECT title, frontmatter, compiled_truth, effective_date::text FROM pages WHERE slug = $1', [slug]).then(r => r[0]);
+
+ beforeAll(async () => {
+ if (databaseUrl) ({ engine, close } = await isolatedPersistencePostgres(databaseUrl));
+ else {
+ const pglite = new PGLiteEngine();
+ await pglite.connect({});
+ await pglite.initSchema();
+ engine = pglite;
+ close = () => pglite.disconnect();
+ }
+ await engine.setConfig('embedding_disabled', 'true');
+ await ok('put_page', { slug: AGENT_SLUG, content: `---\ntype: note\ntitle: Probe ${CODE.title}\ntags: ["${CODE.tag}"]\n---\n\nReference for the probe: ${CODE.body}.` });
+ await asOwner(engine, async tx => {
+ await tx.putPage(OWNER_SLUG, { type: 'note', title: `Owner ${CODE.owner}`, compiled_truth: `The owner wrote ${CODE.owner}.`, timeline: '', frontmatter: {} });
+ await tx.addTag(OWNER_SLUG, CODE.owner);
+ await tx.putPage('people/alice-example', { type: 'person', title: 'Alice Example', compiled_truth: 'A person.', timeline: '', frontmatter: {} });
+ for (const [slug, kind] of [['events/2026-10-04-agent', 'meeting'], ['events/2026-10-04-owner', `call ${CODE.owner}`]]) {
+ await tx.putPage(slug, { type: 'event', title: 'Event', compiled_truth: 'Met.', timeline: '', frontmatter: { event: { kind, when: '2026-10-04' } } });
+ await tx.upsertEventProjection({ depthSlug: 'people/alice-example', eventSlug: slug, date: '2026-10-04', summary: `Met at ${slug}.` });
+ }
+ });
+ const rev = (await ok('get_page', { slug: 'events/2026-10-04-agent' })).revision;
+ await ok('put_page', { slug: 'events/2026-10-04-agent', expected_revision: rev,
+ content: `---\ntype: event\ntitle: Event\nevent:\n kind: "Planted ${CODE.kind}"\n when: 2026-10-04\n---\n\nMet.` });
+ await ok('put_page', { slug: PERSON_SLUG, content: `---\ntype: person\ntitle: "Planted ${CODE.title}"\n---\n\nBob Example, a person.` });
+ }, 180_000);
+ afterAll(async () => { await close?.(); });
+
+ test('a whole-markdown read converted to CRLF is stored as the page, not its fence, closing fence kept or replaced', async () => {
+ for (const [slug, edit] of [['notes/crlf-closed', (c: string) => c], ['notes/crlf-replaced', (c: string) => c.replace(/\n[^\n]*\n?$/, '\nAppended line.\n')]] as const) {
+ await engine.putPage(slug, { type: 'note', title: 'Edge probe', compiled_truth: 'First line.\n\nSecond line.', timeline: '', frontmatter: { status: 'draft' } });
+ const read = await ok('get_page', { slug, include_content: true, content_only: true });
+ const crlf = edit(read.content).replace(/\n/g, '\r\n');
+ await ok('put_page', { slug, content: crlf, expected_revision: read.revision });
+ await ok('put_page', { slug: `${slug}-plain`, content: unquoteTranscriptText(edit(read.content), slug, true).replace(/\n/g, '\r\n') });
+ const [page, plain] = [await engine.getPage(slug), await engine.getPage(`${slug}-plain`)];
+ expect([slug, page!.title, page!.frontmatter.status, page!.compiled_truth.includes(MARKER), page!.compiled_truth.includes('```')]).toEqual([slug, 'Edge probe', 'draft', false, false]);
+ expect([slug, page!.compiled_truth]).toEqual([slug, plain!.compiled_truth]);
+ }
+ }, 120_000);
+
+ test('a chronicle row\'s event kind is quoted by its event page\'s tier on remote reads, the owner\'s kept', async () => {
+ const kinds = (rows: Array<{ event_slug: string | null; kind: string | null }>) =>
+ Object.fromEntries(rows.filter(r => r.event_slug?.startsWith('events/2026-10-04')).map(r => [r.event_slug, r.kind]));
+ const reads: Array<[string, Record<string, unknown>, (r: any) => any[]]> = [
+ ['chronicle_day', { date: '2026-10-04' }, r => r], ['chronicle_since', { date: '2026-10-01' }, r => r],
+ ['chronicle_on_this_day', { date: '2027-10-04' }, r => r], ['volunteer_chronicle', { days: 100000 }, r => r.recent_timeline],
+ ['chronicle_day', { date: '2026-10-04', narrative: true }, r => r.events],
+ ];
+ for (const [op, params, rows] of reads) {
+ const got = kinds(rows(await ok(op, params)));
+ expect([op, fenced(got['events/2026-10-04-agent'], CODE.kind), got['events/2026-10-04-owner']]).toEqual([op, true, `call ${CODE.owner}`]);
+ }
+ const { narrative } = await ok('chronicle_day', { date: '2026-10-04', narrative: true });
+ expect(narrative).toContain(fenceTranscriptText(`Planted ${CODE.kind}`, 'events/2026-10-04-agent'));
+ expect(kinds(await ok('chronicle_day', { date: '2026-10-04' }, local))['events/2026-10-04-agent']).toBe(`Planted ${CODE.kind}`);
+ }, 120_000);
+
+ test('a quoted page\'s title on search and query rows is quoted with its text, the owner\'s kept', async () => {
+ 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)!;
+ expect([op, fenced(row(await ok(op, { query: CODE.body, ...extra }), AGENT_SLUG).title, CODE.title)]).toEqual([op, true]);
+ expect([op, row(await ok(op, { query: CODE.owner, ...extra }), OWNER_SLUG).title]).toEqual([op, `Owner ${CODE.owner}`]);
+ expect([op, row(await ok(op, { query: CODE.body, ...extra }, local), AGENT_SLUG).title]).toEqual([op, `Probe ${CODE.title}`]);
+ }
+ }, 120_000);
+
+ test('a context card\'s title rides the card\'s trust label in the packed text', async () => {
+ const { text } = await ok('context_pack', { entities: `${PERSON_SLUG},people/alice-example` });
+ const line = (text as string).split('\n').find(l => l.includes(PERSON_SLUG))!;
+ expect(line.indexOf('[written by an agent')).toBeGreaterThan(-1);
+ expect(line.indexOf('[written by an agent')).toBeLessThan(line.indexOf(CODE.title));
+ expect((text as string).split('\n').find(l => l.includes('people/alice-example'))!.startsWith('- **Alice Example** →')).toBe(true);
+ const localText = (await ok('context_pack', { entities: PERSON_SLUG }, local)).text as string;
+ expect(localText.split('\n').find(l => l.includes(PERSON_SLUG))!.startsWith(`- **Planted ${CODE.title}** →`)).toBe(true);
+ }, 120_000);
+
+ test('a quoted page\'s tags are quoted on get_page, fetch and get_tags; the owner\'s kept; copied-back tags stored unfenced', async () => {
+ const tagged = (tags: string[]) => tags.some(t => fenced(t, CODE.tag));
+ expect(tagged((await ok('get_page', { slug: AGENT_SLUG })).tags)).toBe(true);
+ expect(tagged((await ok('get_page', { slug: AGENT_SLUG, include_content: true, content_only: true })).tags)).toBe(true);
+ expect(tagged((await ok('get_page', { slug: AGENT_SLUG, body: 'window', lines: { from: 1, count: 100 } })).tags)).toBe(true);
+ expect(tagged((await ok('fetch', { id: AGENT_SLUG })).metadata.tags)).toBe(true);
+ expect(tagged(await ok('get_tags', { slug: AGENT_SLUG }))).toBe(true);
+ expect((await ok('get_page', { slug: OWNER_SLUG })).tags).toEqual([CODE.owner]);
+ expect(await ok('get_tags', { slug: OWNER_SLUG })).toEqual([CODE.owner]);
+ expect(await ok('get_tags', { slug: AGENT_SLUG }, local)).toEqual([CODE.tag]);
+ const before = await stored(AGENT_SLUG);
+ const page = await ok('get_page', { slug: AGENT_SLUG });
+ 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 });
+ 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 });
+ expect(await engine.getTags(AGENT_SLUG)).toEqual([CODE.tag]);
+ }, 120_000);
+
+ test('a fenced title pasted next to a naive datetime keeps that datetime in the brain\'s zone', async () => {
+ await engine.setConfig('brain.timezone', 'America/Los_Angeles');
+ try {
+ const head = (title: string) => `---\ntype: note\ntitle: ${title}\ndate: 2026-10-03 23:30:00\n---\n\nPasted body.\n`;
+ await ok('put_page', { slug: 'notes/naive-plain', content: head('Pasted') });
+ await ok('put_page', { slug: 'notes/naive-fenced', content: '---\ntype: note\ntitle: Old\n---\n\nOld body.\n' });
+ const pasted = fenceTranscriptText('Pasted', 'notes/naive-fenced').split('\n').map(l => ` ${l}`).join('\n');
+ const { revision } = await ok('get_page', { slug: 'notes/naive-fenced' });
+ await ok('put_page', { slug: 'notes/naive-fenced', expected_revision: revision, content: head(`|-\n${pasted}`) });
+ const [plain, unfenced] = [await stored('notes/naive-plain'), await stored('notes/naive-fenced')];
+ expect(unfenced).toEqual(plain);
+ expect(plain!.effective_date?.startsWith('2026-10-04 06:30:00')).toBe(true);
+ } finally {
+ await engine.setConfig('brain.timezone', '');
+ }
+ }, 120_000);
+ });
+}