Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(trust): connector pages and ingest captures pass the external gate; add_timeline_entry gates its row and keeps the page tier (#5575 A3, CEO-27)
garrytan11cccdb9327f
diff --git a/src/core/minions/handlers/ingest-capture.ts b/src/core/minions/handlers/ingest-capture.tsindex 89bd35c66c..5345308676 100644--- a/src/core/minions/handlers/ingest-capture.ts+++ b/src/core/minions/handlers/ingest-capture.ts@@ -234,6 +234,8 @@ export function makeIngestCaptureHandler(engine: BrainEngine) {// and `content_flag.detail` injects text into the agent-trusted warning// channel. Trusted daemon emitters leave it false and keep their markers.remote: untrustedPayload,+ // #5575 A3: webhook and ingestion-daemon captures are external content: stored external_untrusted and gated.+ writeGate: { tier: 'external_untrusted' as const, origin: { channel: `ingest:${event.source_kind}`, source_uri: event.source_uri ?? null, source_kind: event.source_kind }, requestId: null },};let result;diff --git a/src/core/persistence/connector-sync.ts b/src/core/persistence/connector-sync.tsindex e98481cc92..c92ce3591f 100644--- a/src/core/persistence/connector-sync.ts+++ b/src/core/persistence/connector-sync.ts@@ -1039,6 +1039,8 @@ export async function prepareConnectorMutation(engine: BrainEngine, row: WriteRelet prepared: PreparedContentImport | undefined;const result = await importFromContent(engine, row.slug, content, { sourceId: row.source_id, sourcePath: p.sourcePath,filename: basename(p.sourcePath).replace(/\.mdx?$/i, ''), noEmbed: true, allowEmptyOverwrite: true, activePack,+ // #5575 A3: connector free text (mail bodies, invite descriptions, issue text) is external and gated.+ writeGate: { tier: 'external_untrusted', origin: { channel: `connector:${p.connector}`, connector: String(p.connector), source_uri: p.sourcePath }, requestId: row.id },prepareFrontmatter: page => {if (snapshot?.page.frontmatter.visibility === 'private') page.frontmatter.visibility = 'private';},diff --git a/src/core/persistence/semantic-pages.ts b/src/core/persistence/semantic-pages.tsindex 5a45198ae5..015742c1a0 100644--- a/src/core/persistence/semantic-pages.ts+++ b/src/core/persistence/semantic-pages.ts@@ -1,3 +1,7 @@+import { requestChannelTrust } from '../trust/channel.ts';+import { gateField, gateInput, loadWriteGateConfig } from '../trust/gate-outcomes.ts';+import { recordWriteGateReceipt } from '../write-gate-store.ts';+import { assessTimelineForGate, writeGateRejectedError } from '../write-gate.ts';import type { BrainEngine } from '../engine.ts';import type { GBrainConfig } from '../config.ts';import { serializePageToMarkdown } from '../markdown.ts';@@ -74,6 +78,9 @@ export async function prepareSemanticPageMutation(engine: BrainEngine, row: Writif (!exact && tuples.some(tuple => tuple.date === rendered.canonical.date && tuple.source === rendered.canonical.source && tuple.summary === rendered.canonical.summary)) {throw new OperationError('invalid_params', 'This timeline identity already exists with different detail.', 'Read and conditionally edit the existing page to change that entry.');}+ // #5575 CEO-27: the timeline row is gated at the request's tier; it keeps its own tier, the page keeps its own.+ const gate = assessTimelineForGate(entry, gateInput(requestChannelTrust(row) ?? { tier: 'unknown', origin: null }, row.id), await loadWriteGateConfig(engine));+ if (gate.verdict === 'reject' || gate.verdict === 'quarantine') throw writeGateRejectedError(gate);const page = { ...snapshot.page, timeline: exact ? snapshot.page.timeline : spliceTimelineBlock(snapshot.page.timeline, entry.date, block) };const prepared = await preparePageMutation(engine, row, config, {expectedRevision: snapshot.revision, content: serializePageToMarkdown(page, snapshot.tags),@@ -81,6 +88,9 @@ export async function prepareSemanticPageMutation(engine: BrainEngine, row: Writreturn { ...prepared, apply: async tx => {const outcome = await prepared.apply(tx);const inserted = await tx.addTimelineEntry(row.slug, { ...rendered.canonical, detail: rendered.detail }, { sourceId: row.source_id });- return { ...outcome, status: exact && !inserted ? 'skipped' : 'ok', ...(exact && !inserted ? { reason: 'duplicate' } : {}), entry: rendered.canonical };+ const [stored] = gate.verdict === 'flag' ? await tx.executeRaw<{ id: number }>(`SELECT t.id FROM timeline_entries t JOIN pages p ON p.id = t.page_id+ WHERE p.source_id = $1 AND p.slug = $2 AND t.date = $3::date AND t.summary = $4 ORDER BY t.id DESC LIMIT 1`, [row.source_id, row.slug, rendered.canonical.date, rendered.canonical.summary]) : [];+ const flagged = stored ? gateField(gate, `p:${row.source_id}/${row.slug}`, await recordWriteGateReceipt(tx, { targetTable: 'timeline_entries', targetId: Number(stored.id), sourceId: row.source_id, assessment: gate, requestId: row.id })) : undefined;+ return { ...outcome, status: exact && !inserted ? 'skipped' : 'ok', ...(exact && !inserted ? { reason: 'duplicate' } : {}), entry: rendered.canonical, ...(flagged ? { gate: flagged } : {}) };} };}diff --git a/src/core/trust/page-write.ts b/src/core/trust/page-write.tsindex 3a49f1bfb2..0b79c52dd4 100644--- a/src/core/trust/page-write.ts+++ b/src/core/trust/page-write.ts@@ -9,9 +9,10 @@* lower of the write's tier and the page's stored tier, so the tier survives* the git round trip (sync honors it; an owner restamp needs the marker gone).* - ENG-1: gbrain-managed fence edits (remember / takes fence appends, proposal- * accept strikes, loop and relink maintenance) rewrite the page body without- * authoring it, so the page keeps its stored tier (withTrustKeep); the fence- * row carries the writer's tier.+ * accept strikes, loop and relink maintenance) and add_timeline_entry rewrite+ * the page body without authoring it, so the page keeps its stored tier+ * (withTrustKeep); the fence or timeline row carries the writer's tier and+ * is gated per row (CEO-27).* - CEO-12: an agent write that replaces the body of a higher-tier page lowers* the page and files one `lower_page` trust proposal per page (later edits* fold into it) with the prior owner version to revert to.@@ -24,7 +25,7 @@ import { OWNER_TIER_FLOOR, compareTrust, effectiveWriteTrust, minTrust, storedTr/** Page writes that only edit a gbrain-managed fence (or strike a row) and keep the page's tier. */const FENCE_EDIT_OPERATIONS = ['remember', 'takes_add', 'takes_update', 'takes_supersede', 'takes_resolve', 'takes_remove',- 'decide_proposal', 'loops_close', 'relink_facts'];+ 'decide_proposal', 'loops_close', 'relink_facts', 'add_timeline_entry'];/** Page writes whose caller supplies the page content: they stamp the marker and can lower the page (CEO-12). */const CONTENT_OPERATIONS = ['put_page', 'capture', 'edit_page', 'revert_version', 'restore_page'];