Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Guest marks reach only callers who can read the note (GBRA-504)
garrytane895ce767f43
diff --git a/docs/guides/guest-notes.md b/docs/guides/guest-notes.mdindex 57c3fb25fe..d6e26dbb68 100644--- a/docs/guides/guest-notes.md+++ b/docs/guides/guest-notes.md@@ -69,6 +69,10 @@ every page in a guest source would then read as a guest's words. Deleted pagesthat haven't been purged yet count too, because restoring one would bring it backinto the guest source.+Before a brain that uses a scoped row-level-security write role turns guests on,+the guest guard and admission must check maintainer policies on guest_sources;+until then a scoped write role sees no guest rows and the checks fail open.+## Change who may write```bash@@ -142,6 +146,12 @@ the local CLI alike. JSON results give the row `origin: "guest"`, trust tier"saved_at": "2026-11-13", "promoted": false, "writer": "legacy_token:<id>" }```+A reader sees a mark only on a note they could read with `get_page`: the same+source grant, `readable_by`, folder and privacy rules decide, for deleted notes+too. Anywhere else the note is named, such as a slug inside a raw-data payload,+it gets no mark at all. Marks pass the same secret redaction as page text, so a+key-shaped sender label reads as `<REDACTED:…>` over MCP.+`writer` is shown to the owner only. Text answers put a warning line before thenote, then wrap it in `<external-data trust="external_untrusted" origin="guest">`:diff --git a/src/core/guests/stamp-readable.ts b/src/core/guests/stamp-readable.tsnew file mode 100644index 0000000000..0fe2a2828d--- /dev/null+++ b/src/core/guests/stamp-readable.ts@@ -0,0 +1,44 @@+/**+ * Guest notes, slice 4 (GBRA-504): which guest pages a caller may see marked. A guest mark names the note's sender,+ * group, audience and date, so it rides only on a page the caller's own read policy admits, the decision get_page+ * makes for that caller (ops/pages.ts): the source scope federatedSearchScope grants (an explicit source checked+ * against the grant and the explicit-read set), then member access and privacy (privatePagesFilterForCaller in SQL and+ * isPrivatePageForCaller after it) whenever resolveExcludePrivatePages applies them. A soft-deleted page is decided by+ * the same rules, as get_page include_deleted reads it. A reference the caller cannot read gets no stamp at all, so a+ * stored object that names a guest note (a raw-data payload, a frontmatter value, a page id) reads back nothing.+ */+import type { OperationContext } from '../ops/contract.ts';+import { federatedSearchScope } from '../ops/context.ts';+import { currentCallerAccess, isPrivatePageForCaller, privatePagesFilterForCaller, resolveExcludePrivatePages } from '../search/private-visibility.ts';+import { refKey, type PageRef } from '../access/page-items.ts';++function sourceAdmitted(ctx: OperationContext, source: string): boolean {+ try {+ const scope = federatedSearchScope(ctx, source);+ return scope.sourceIds ? scope.sourceIds.includes(source) : scope.sourceId === source;+ } catch {+ return false;+ }+}++/**+ * The refKeys (access/page-items.ts) among `refs` the caller may read, from one batched query. The trusted local CLI+ * reads every page, except under an --as preview, which applies the member's policy like a remote read.+ */+export async function readableGuestRefs(ctx: OperationContext, refs: readonly PageRef[]): Promise<Set<string>> {+ if (ctx.remote === false && !currentCallerAccess().applyRemoteReadPolicy) return new Set(refs.map(refKey));+ const excludePrivate = await resolveExcludePrivatePages(ctx.engine, ctx.remote);+ const ids = refs.flatMap(r => (r.kind === 'page_id' ? [r.id] : []));+ const named = refs.flatMap(r => (r.kind === 'page' ? [r] : []));+ const rows = await ctx.engine.executeRaw<{ id: number; source_id: string; slug: string; type: string | null; frontmatter: unknown }>(+ `SELECT p.id, p.source_id, p.slug, p.type, p.frontmatter FROM pages p+ WHERE (p.id = ANY($1::int[]) OR (p.source_id, p.slug) IN (SELECT u.s, u.g FROM unnest($2::text[], $3::text[]) AS u(s, g)))${excludePrivate ? ` AND ${privatePagesFilterForCaller('p')}` : ''}`,+ [ids, named.map(r => r.source_id), named.map(r => r.slug)]);+ const readable = new Set<string>();+ for (const row of rows) {+ if (!sourceAdmitted(ctx, row.source_id) || (excludePrivate && isPrivatePageForCaller(row))) continue;+ readable.add(refKey({ kind: 'page', source_id: row.source_id, slug: row.slug }));+ readable.add(refKey({ kind: 'page_id', id: Number(row.id) }));+ }+ return readable;+}diff --git a/src/core/guests/stamp.ts b/src/core/guests/stamp.tsindex 45da5cf96a..892ac444fa 100644--- a/src/core/guests/stamp.ts+++ b/src/core/guests/stamp.ts@@ -4,15 +4,19 @@* dispatch, the local CLI and in-process callers all get it. The shared page-item walker (access/page-items.ts) finds* every page-bearing item; the batched trust load (eligibility/stamp.ts loadPageTrust) decides per row whether its* source is a guest source and reads the marks; each guest item gains `trust_tier: external_untrusted`,- * `origin: "guest"` and its `guest` object, and a remote quote fence around its text names the guest. The stamp is- * on the handler's result, so dispatch's response-cap fallback, which drops room marks, never drops it.+ * `origin: "guest"` and its `guest` object, and a remote quote fence around its text names the guest. Only a page the+ * caller's own read policy admits is stamped (guests/stamp-readable.ts); output redaction runs after the stamp+ * (operation-load.ts). The stamp is on the handler's result, so dispatch's response-cap fallback, which drops room+ * marks, never drops it.*/import type { OperationContext } from '../ops/contract.ts';import { currentCallerAccess } from '../search/private-visibility.ts';-import { collectPageItems, type Ref } from '../access/page-items.ts';+import { exemptGuestWriter } from '../search/output-redaction.ts';+import { collectPageItems, refKey, type PageRef, type Ref } from '../access/page-items.ts';import { loadPageTrust } from '../eligibility/stamp.ts';import { relabelGuestQuote } from '../search/transcript-quote.ts';import { brainHasGuestSource, GUEST_ORIGIN, guestQuoteLabel } from './marker.ts';+import { readableGuestRefs } from './stamp-readable.ts';/** An owner caller sees the guest note's writer: the trusted local CLI, or a credential bound to the owner speaking for no one else. */export function guestViewerIsOwner(ctx: Pick<OperationContext, 'remote'>): boolean {@@ -34,18 +38,22 @@ const refSlug = (r: Ref) => (r.kind === 'page' ? r.slug : undefined);/*** `result` with every guest item stamped, on a detached copy (handlers may return cached objects), or `result` itself- * when nothing in it is a guest row. The trust load is skipped only when no source is a guest source (marker.ts- * brainHasGuestSource, which answers yes when it cannot tell); a failed trust load fails the read rather than return a- * guest note unmarked.+ * when nothing in it is a guest row the caller may read. The trust load is skipped only when no source is a guest source+ * (marker.ts brainHasGuestSource, which answers yes when it cannot tell); a failed trust or readability load fails the+ * read rather than return a guest note unmarked.*/-export async function stampGuestNotes(ctx: Pick<OperationContext, 'engine' | 'remote' | 'sourceId'>, result: unknown): Promise<unknown> {+export async function stampGuestNotes(ctx: OperationContext, result: unknown): Promise<unknown> {if (!result || typeof result !== 'object') return result;const found = collectPageItems(result, ctx.sourceId ?? 'default').filter(s => s.ref !== null && s.ref.kind !== 'fact');if (!found.length || !(await brainHasGuestSource(ctx.engine))) return result;const refs = found.map(s => s.ref!).map(r => r.kind === 'page' ? { source_id: r.source_id, slug: r.slug } : { page_id: (r as { id: number }).id, slug: '' });const trust = await loadPageTrust(ctx.engine, refs, { guestWriter: guestViewerIsOwner(ctx), includeDeleted: true });- const guestOf = (r: Ref) => (r.kind === 'page' ? trust.byKey.get(`${r.source_id}\u0000${r.slug}`) : r.kind === 'page_id' ? trust.byId.get(r.id) : undefined)?.guest;- if (!found.some(s => guestOf(s.ref!))) return result;+ const markOf = (r: Ref) => (r.kind === 'page' ? trust.byKey.get(`${r.source_id}\u0000${r.slug}`) : r.kind === 'page_id' ? trust.byId.get(r.id) : undefined)?.guest;+ const marked = found.map(s => s.ref as PageRef).filter(r => markOf(r));+ if (!marked.length) return result;+ const readable = await readableGuestRefs(ctx, marked);+ const guestOf = (r: Ref) => (readable.has(refKey(r)) ? markOf(r) : undefined);+ if (!marked.some(guestOf)) return result;const copy = detachedCopy(result);for (const slot of collectPageItems(copy, ctx.sourceId ?? 'default')) {const guest = slot.ref ? guestOf(slot.ref) : undefined;@@ -53,7 +61,7 @@ export async function stampGuestNotes(ctx: Pick<OperationContext, 'engine' | 'reconst h = slot.holder;h.trust_tier = 'external_untrusted';h.origin = GUEST_ORIGIN;- h.guest = guest;+ h.guest = exemptGuestWriter(guest);const slug = refSlug(slot.ref!) ?? (typeof h.slug === 'string' ? h.slug : undefined);if (!slug) continue;for (const [k, v] of Object.entries(h)) if (typeof v === 'string') h[k] = relabelGuestQuote(v, slug, guestQuoteLabel(guest));diff --git a/src/core/operation-load.ts b/src/core/operation-load.tsindex e0825e767a..437616c64c 100644--- a/src/core/operation-load.ts+++ b/src/core/operation-load.ts@@ -128,7 +128,8 @@ export function finalizeOperation(op: Operation): void {op.area = OP_AREAS[op.name];}// The handler runs in its engine's scope, so an embedded engine's AI calls use that engine's gateway (engine-scope.ts).- const handler = withGuestMarks(op, withOutputRedaction(op));+ // Redaction runs after the guest stamp, so a key-like sender label in a guest mark is redacted like stored text.+ const handler = withOutputRedaction({ handler: withGuestMarks(op, op.handler), outputRedaction: op.outputRedaction });op.handler = (ctx, params) => withEngineScope(ctx.engine, () => handler(ctx, params));}diff --git a/src/core/search/output-redaction.ts b/src/core/search/output-redaction.tsindex 648d61ca9f..ecc0ee91a5 100644--- a/src/core/search/output-redaction.ts+++ b/src/core/search/output-redaction.ts@@ -15,6 +15,18 @@ const MAX_DEPTH = 24;const MAX_TEXT_FIELDS = 8192;const DEGRADED_STAGE_CODES = new Set<string>(DEGRADED_STAGES);const DEGRADED_REASON_CODES = new Set<string>(DEGRADED_REASONS);+const GUEST_STAMP = Symbol('gbrain.guest_stamp');++/**+ * Registers a guest mark built by the guest stamp (guests/stamp.ts), so its `writer`, a principal id read from+ * guest_marks, passes redaction while the mark's other fields are scanned like stored text. Only a registered object+ * qualifies, by a symbol key that stored data cannot carry: a stored look-alike `guest.writer`, and a `writer` anywhere+ * else, is still redacted.+ */+export function exemptGuestWriter<T extends object>(guest: T): T {+ (guest as Record<symbol, unknown>)[GUEST_STAMP] = true;+ return guest;+}export interface RetrievalRedactionOpts {/**@@ -45,6 +57,8 @@ export function redactRetrievalOutput<T, M>(results: T[], meta: M, opts: Retrievlet next: unknown;if (path.length === 2 && path[0] === 'results' && verbatim.has(String(key))) {next = item;+ } else if (key === 'writer' && typeof item === 'string' && (value as Record<symbol, unknown>)[GUEST_STAMP] === true) {+ next = item;} else if (IDENTITY_FIELDS.has(String(key)) && (typeof item !== 'object' || item === null ||(Array.isArray(item) && item.every(part => typeof part === 'string')))) {next = Array.isArray(item) ? [...item] : item;diff --git a/test/guest-notes-stamp-access.test.ts b/test/guest-notes-stamp-access.test.tsnew file mode 100644index 0000000000..5fe4213373--- /dev/null+++ b/test/guest-notes-stamp-access.test.ts@@ -0,0 +1,201 @@+/**+ * Guest notes, slice 4 (GBRA-504): a guest mark reaches only a caller whose own read policy admits the note.+ *+ * Protects: the stamp (guests/stamp.ts) decides per referenced page what get_page decides for that caller (source+ * grant, readable_by and folder rules, privacy labels; a soft-deleted note under the same rules). A reference the+ * caller cannot read gets no stamp at all, not even the unattributed form, so a stored object naming a guest note by+ * source_id and slug (a raw-data payload, a frontmatter value) or by page_id cannot read back its sender, group,+ * audience or date. The local CLI and an owner-bound credential still see every mark with its writer. Output+ * redaction runs after the stamp, so a key-like sender label is redacted for remote readers; only the writer of a mark+ * the stamp built passes it, never a `writer` field elsewhere or a stored look-alike.+ *+ * Real seams: legacy tokens bound by the member functions, MCP dispatch on a repo-less PGLite brain.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { GBrainOAuthProvider } from '../src/core/oauth-provider.ts';+import { sqlQueryForEngine } from '../src/core/sql-query.ts';+import { mintLegacyToken } from '../src/core/token-mint.ts';+import { dispatchToolCall } from '../src/mcp/dispatch.ts';+import { addGroup, addMember, bindCredential, memberIdentity } from '../src/core/access/members.ts';+import { setOwner } from '../src/core/access/owner.ts';+import { changeGuestWriters, initGuestSource } from '../src/core/guests/sources.ts';+import { importFromContent } from '../src/core/import-file.ts';+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';+import { withCallerAccess } from '../src/core/search/private-visibility.ts';+import { exemptGuestWriter, withOutputRedaction } from '../src/core/search/output-redaction.ts';+import type { AuthInfo } from '../src/core/ops/contract.ts';+import { readsUnscopedOnPurpose } from './helpers/reads-unscoped.ts';++const SRC = 'guests';+const PLAIN = 'source-a';+const OWNER = 'alice-example';+const HOST = 'notes/owner-plan';+const GUEST = 'notes/guest-live';+const GONE = 'notes/guest-gone';+const KEYED = 'notes/guest-keyed';+const SENDER = 'Bob Example';+/** A key-shaped sender label admission accepts (built here so no scanner reads a literal key in this file). */+const KEY = 'sk-ant-' + 'supersecret-123456';++let engine: PGLiteEngine;+const tokens: Record<string, { id: string; token: string }> = {};+const ids: Record<string, number> = {};+let writer = '';+const provider = () => new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });+const verify = async (who: string) => await provider().verifyAccessToken(tokens[who]!.token) as unknown as AuthInfo;++type Who = 'local' | 'owner' | 'bob' | 'carol' | 'dave';+async function call(who: Who, op: string, args: Record<string, unknown>, sourceId = PLAIN) {+ const opts = who === 'local'+ ? { remote: false, sourceId }+ : { remote: true, transport: 'http', auth: await verify(who), sourceId, takesHoldersAllowList: ['world'] };+ const out = await dispatchToolCall(engine, op, args, opts as never);+ return { isError: out.isError === true, text: out.content.map(c => c.text).join('\n') };+}+/** A trusted local read previewing a member's view (the CLI's --as): local output carries no quote fences. */+async function preview(member: string, op: string, args: Record<string, unknown>) {+ const { identity } = await memberIdentity(engine, member);+ const out = await withCallerAccess({ identity, applyRemoteReadPolicy: true, hidePrivate: true, privateReadableSources: [] },+ () => dispatchToolCall(engine, op, args, { remote: false, sourceId: PLAIN }));+ return { isError: out.isError === true, text: out.content.map(c => c.text).join('\n') };+}++const isObj = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);+/** Every guest object stamped anywhere in a JSON answer, with the slug or page_id of the item it sits on. */+function stamps(text: string): Array<{ at: string; guest: Record<string, unknown> }> {+ const out: Array<{ at: string; guest: Record<string, unknown> }> = [];+ const walk = (v: unknown) => {+ if (Array.isArray(v)) { v.forEach(walk); return; }+ if (!isObj(v)) return;+ if (v.origin === 'guest' && isObj(v.guest)) out.push({ at: String(v.slug ?? v.page_id), guest: v.guest });+ for (const x of Object.values(v)) walk(x);+ };+ try { walk(JSON.parse(text)); } catch { /* not JSON */ }+ return out;+}++async function guestPut(slug: string, label: string) {+ const content = ['---', 'type: note', 'title: Guest ' + slug, 'readable_by: [' + OWNER + ', bob-example]', 'guest_group: team-a',+ 'guest_sender: ' + JSON.stringify(label), 'saved_at: 2026-11-13T10:00:00Z', '---', '# Guest ' + slug, '', 'Bob says the offsite moved to Friday.'].join('\n');+ const put = await dispatchToolCall(engine, 'put_page', { slug, content }, { remote: true, transport: 'http', auth: await verify('broker'), sourceId: SRC,+ takesHoldersAllowList: ['world'], onBehalfOf: { header: 'bob-example' }, guest: { requestMeta: { guest: { sender_label: label, group: 'team-a' } } } });+ expect(put.isError).not.toBe(true);+ const [row] = await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE source_id = $1 AND slug = $2', [SRC, slug]);+ ids[slug] = Number(row!.id);+}++beforeAll(async () => {+ engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+ for (const id of [OWNER, 'bob-example', 'carol-example', 'dave-example']) await addMember(engine, id);+ await addGroup(engine, 'team-a', ['bob-example']);+ await addGroup(engine, 'team-b', ['dave-example']);+ await setOwner(engine, OWNER);+ await engine.executeRaw('INSERT INTO sources (id, name) VALUES ($1, $1) ON CONFLICT (id) DO NOTHING', [PLAIN]);+ await importFromContent(engine, HOST, '---\ntype: note\ntitle: Owner plan\nref:\n source_id: ' + SRC + '\n slug: ' + GUEST + '\n---\n# Owner plan\n\nThe owner plans the harbor review.\n', { sourceId: PLAIN });+ await initGuestSource(engine, SRC, []);+ const mint = async (name: string, grant: string[], binding: { member?: string; mayActFor?: string[] }) => {+ const minted = await mintLegacyToken(engine, { name, scopes: ['read', 'write'], takesHolders: ['world'], sourceGrant: grant });+ tokens[name] = { id: minted.id, token: minted.token };+ await bindCredential(engine, { kind: 'token', id: minted.id }, binding);+ if (!binding.member) await readsUnscopedOnPurpose(engine, minted.id);+ };+ await mint('broker', [SRC], { mayActFor: ['member:bob-example'] });+ await mint('owner', [SRC, PLAIN], { member: OWNER });+ await mint('bob', [SRC], { member: 'bob-example' });+ await mint('carol', [PLAIN], { member: 'carol-example' });+ await mint('dave', [SRC, PLAIN], { member: 'dave-example' });+ await changeGuestWriters(engine, SRC, { add: ['legacy_token:' + tokens.broker!.id] });+ await guestPut(GUEST, SENDER);+ await guestPut(GONE, SENDER);+ await guestPut(KEYED, KEY);+ const [m] = await engine.executeRaw<{ writer_kind: string; writer_id: string }>('SELECT writer_kind, writer_id FROM guest_marks WHERE page_id = $1', [ids[GUEST]]);+ writer = m!.writer_kind + ':' + m!.writer_id;+ // A soft-deleted guest note. Guest pages refuse ordinary edits, so the fixture sets the tombstone with triggers off.+ await engine.transaction(async tx => {+ await tx.executeRaw('SET LOCAL session_replication_role = replica');+ await tx.executeRaw('UPDATE pages SET deleted_at = now() WHERE id = $1', [ids[GONE]]);+ });+ // A source-a-only credential stores an object naming the guest notes by source_id and slug and by page_id. The owner+ // plan's frontmatter names one too.+ const payload = { live: { source_id: SRC, slug: GUEST }, gone: { source_id: SRC, slug: GONE }, by_id: { page_id: ids[GUEST] } };+ expect((await call('carol', 'put_raw_data', { slug: HOST, source: 'probe', data: payload })).isError).toBe(false);+}, 240_000);+afterAll(async () => { await disposePersistenceConsumer(engine); await engine.disconnect(); }, 60_000);++describe('guest marks reach only callers who can read the note', () => {+ test('(a) a credential without the guest source reads no mark through a stored raw-data payload', async () => {+ expect((await call('carol', 'get_page', { slug: GUEST, source_id: SRC })).isError).toBe(true);+ const raw = await call('carol', 'get_raw_data', { slug: HOST });+ expect(raw.text).toContain(GUEST);+ expect(stamps(raw.text)).toEqual([]);+ for (const leak of ['"origin":"guest"', '"guest":', SENDER, 'team-a', 'external_untrusted']) expect(raw.text).not.toContain(leak);+ });++ test('(b) a member of another group with the guest source in its grant, outside readable_by, reads no mark', async () => {+ expect((await call('dave', 'get_page', { slug: GUEST, source_id: SRC })).isError).toBe(true);+ const raw = await call('dave', 'get_raw_data', { slug: HOST });+ expect(raw.text).toContain(GUEST);+ expect(stamps(raw.text)).toEqual([]);+ for (const leak of ['"origin":"guest"', '"guest":', SENDER, 'team-a']) expect(raw.text).not.toContain(leak);+ // A frontmatter value naming the note, through a read that prints it unfenced: a local preview of that member's view.+ expect((await preview('dave-example', 'get_page', { slug: GUEST, source_id: SRC })).isError).toBe(true);+ const page = await preview('dave-example', 'get_page', { slug: HOST });+ expect(page.isError).toBe(false);+ expect(page.text).toContain(GUEST);+ expect(stamps(page.text)).toEqual([]);+ for (const leak of ['"origin":"guest"', SENDER, 'team-a']) expect(page.text).not.toContain(leak);+ });++ test('(c) a soft-deleted guest note is marked only for a caller whose read policy admits it', async () => {+ expect((await call('carol', 'get_page', { slug: GONE, source_id: SRC, include_deleted: true })).isError).toBe(true);+ expect((await call('dave', 'get_page', { slug: GONE, source_id: SRC, include_deleted: true })).isError).toBe(true);+ for (const who of ['carol', 'dave'] as const) {+ const raw = await call(who, 'get_raw_data', { slug: HOST });+ expect(raw.text).toContain(GONE);+ expect(stamps(raw.text).filter(s => s.at === GONE)).toEqual([]);+ }+ const owner = await call('owner', 'get_raw_data', { slug: HOST });+ expect(stamps(owner.text).filter(s => s.at === GONE).map(s => s.guest.sender)).toEqual([SENDER]);+ });++ test('(d) the local CLI and an owner-bound credential still see every mark with its writer', async () => {+ for (const who of ['local', 'owner'] as const) {+ const raw = await call(who, 'get_raw_data', { slug: HOST });+ const found = stamps(raw.text);+ expect(found.map(s => s.at).sort()).toEqual([GONE, GUEST, String(ids[GUEST])].sort());+ for (const s of found) expect(s.guest).toMatchObject({ sender: SENDER, group: 'team-a', audience_member: 'member:bob-example', writer });+ }+ expect(stamps((await call('local', 'get_page', { slug: HOST })).text).map(s => s.guest.writer)).toEqual([writer]);+ expect(stamps((await preview('bob-example', 'get_raw_data', { slug: HOST })).text).map(s => s.at).sort()).toEqual([GONE, GUEST, String(ids[GUEST])].sort());+ });++ test('(e) output redaction runs after the stamp, so a key-like sender label is redacted for a remote reader', async () => {+ const listed = await call('bob', 'list_pages', {}, SRC);+ const keyed = stamps(listed.text).filter(s => s.at === KEYED);+ expect(keyed.length).toBe(1);+ expect(listed.text).not.toContain(KEY);+ expect(String(keyed[0]!.guest.sender)).toContain('<REDACTED:');+ const plain = stamps(listed.text).filter(s => s.at === GUEST);+ expect(plain.map(s => s.guest.sender)).toEqual([SENDER]);+ });++ test('(f) only the stamp-built guest.writer passes redaction; another writer field that looks like a secret does not', async () => {+ const owner = await call('owner', 'list_pages', {}, SRC);+ expect(stamps(owner.text).filter(s => s.at === GUEST).map(s => s.guest.writer)).toEqual([writer]);+ const handler = withOutputRedaction({ outputRedaction: 'retrieval', handler: async () => ({+ writer: KEY,+ owner_style: { writer },+ forged: { slug: 'notes/look-alike', origin: 'guest', guest: { sender: SENDER, writer: KEY } },+ stamped: { slug: GUEST, origin: 'guest', guest: exemptGuestWriter({ sender: KEY, writer }) },+ }) });+ const out = await handler({ engine, remote: true, sourceId: SRC } as never, {}) as Record<string, Record<string, Record<string, unknown>>>;+ expect(String(out.writer)).toContain('<REDACTED:');+ expect(String(out.owner_style!.writer)).toContain('<REDACTED:');+ expect(String(out.forged!.guest!.writer)).toContain('<REDACTED:');+ expect(out.stamped!.guest!.writer).toBe(writer);+ expect(String(out.stamped!.guest!.sender)).toContain('<REDACTED:');+ });+});