Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
remember: share checks the page whatever visibility is passed and again at preparation; member writeback instructions say to use share (GST-2243 review voices)
garrytana57b9d9bcca0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4d54268c13..737814a7db 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,7 +17,7 @@ identifiers and attribution are available in the pre-removal Git revision### Itemized changes- `src/core/verbs.ts`: `remember` takes a `share` boolean on every MCP surface, starter included. A non-boolean `share`, `share: true` with `visibility: "private"`, and a member's `visibility: "world"` (`member_share_required`) are refused with `invalid_params` before anything is saved, so one such item refuses a whole batch.-- `src/core/persistence/memory-mutations.ts`: a member's `share: true` saves on the entity page with world visibility; when that page's facts would be private, the call is refused (`share_target_restricted`) before anything is admitted. New and replayed replies carry `page` and `visibility`.+- `src/core/persistence/memory-mutations.ts`: a member's `share: true` saves on the entity page with world visibility; when that page's facts would be private (whatever `visibility` the call passed), the save is refused (`share_target_restricted`), and preparation refuses it again if the page turned restricted after admission. In a batch, items saved before a refused item stay saved, as with other save-time refusals. New and replayed replies carry `page` and `visibility`.- `src/core/remember-batch.ts`: `share` is accepted per item and as a shared top-level key, and each item's receipt carries `page` and `visibility`.- `test/mcp-schema-budget.test.ts`: the starter tool-list ceilings and the `remember` budget grow by what `share` costs (+144 characters, 200 headroom kept).- QM's `memory_write` and its per-person contract (`docs/contracts/qm-memory-provider/v1.json`) are unchanged.diff --git a/src/commands/serve-http-mcp.ts b/src/commands/serve-http-mcp.tsindex d4f0eeab7c..cf56ed6ba7 100644--- a/src/commands/serve-http-mcp.ts+++ b/src/commands/serve-http-mcp.ts@@ -219,6 +219,7 @@ function createMcpRequestServer(writebackOpts = ambientOptsFrom(writeback, {remember: rememberOp !== undefined && opAllowedForBoundClient(authInfo, rememberOp),extractFacts: extractFactsOp !== undefined && opAllowedForBoundClient(authInfo, extractFactsOp),+ member: !!authInfo?.member,});}const server = new Server(diff --git a/src/core/facts/writeback-config.ts b/src/core/facts/writeback-config.tsindex a7969ca53c..adc4091bd4 100644--- a/src/core/facts/writeback-config.ts+++ b/src/core/facts/writeback-config.ts@@ -155,7 +155,7 @@ const lkg = new WeakMap<BrainEngine, WritebackConfig>();*/export function ambientOptsFrom(wb: WritebackConfig,- avail: { remember: boolean; extractFacts: boolean },+ avail: { remember: boolean; extractFacts: boolean; member?: boolean },): AmbientOptsShape | null {if (!wb.enabled || wb.mode === 'off') return null;if (!avail.remember) return null;@@ -164,6 +164,7 @@ export function ambientOptsFrom(transientTtl: wb.transient_ttl,visibility: wb.visibility,extractFactsAvailable: avail.extractFacts,+ ...(avail.member ? { member: true } : {}),};}interface AmbientOptsShape {@@ -171,6 +172,7 @@ interface AmbientOptsShape {transientTtl: string;visibility: 'world' | 'private';extractFactsAvailable: boolean;+ member?: boolean;}/**diff --git a/src/core/facts/writeback-instructions.ts b/src/core/facts/writeback-instructions.tsindex 45005d0b9b..f8c42beb1e 100644--- a/src/core/facts/writeback-instructions.ts+++ b/src/core/facts/writeback-instructions.ts@@ -26,6 +26,8 @@ export interface AmbientWritebackOpts {transientTtl: string;/** Resolved write posture — see module header. */visibility: 'world' | 'private';+ /** GST-2243: the caller is one team member, whose remember is private unless it passes share: true. */+ member?: boolean;/** True only when `extract_facts` is actually callable on this transport's* allowed-op set (OV2-14) — never advertise an uncallable tool. The* engine-free harness block cannot probe the serve's surface, so it passes@@ -50,7 +52,9 @@ export function buildAmbientWritebackSection(opts: AmbientWritebackOpts): stringconst transientLine = opts.extractFactsAvailable === false? `pass ttl: "${opts.transientTtl}".`: `always save via remember with ttl: "${opts.transientTtl}" — never batch them through extract_facts (it cannot set a ttl, so they would become permanent).`;- const visibilityLine = opts.visibility === 'world'+ const visibilityLine = opts.member+ ? 'Omit visibility: your saves stay private to you. Pass share: true only for a fact about the team\'s work, never about a person; every reader of this source then recalls it, and only the brain host can withdraw it.'+ : opts.visibility === 'world'? 'Pass visibility: "world" explicitly on every save. "world" means readable by agents authorized on THIS brain — not the public internet. Never widen a private fact on your own.': 'Pass visibility: "private" explicitly on every save — this brain\'s operator keeps facts private by default (omitting visibility would silently widen: remember defaults to world). Private facts are readable by the local CLI only, not by remote sessions: you, and every other MCP or HTTP session, cannot recall or forget a fact you save as private. Never widen to world on your own.';const header = opts.origin === 'conversation'diff --git a/src/core/ops/memory-settings.ts b/src/core/ops/memory-settings.tsindex 4a00b2ed30..b0d4633795 100644--- a/src/core/ops/memory-settings.ts+++ b/src/core/ops/memory-settings.ts@@ -74,6 +74,7 @@ function ruleFor(res: AgentWritebackResolution, mode: WritebackMode, ctx: Operatvisibility: res.operator.visibility,extractFactsAvailable: callerCan(ctx, EXTRACT_FACTS_OP),origin,+ ...(ctx.remote !== false && ctx.auth?.member ? { member: true } : {}),});}diff --git a/src/core/persistence/memory-mutations.ts b/src/core/persistence/memory-mutations.tsindex 17c4f16638..3953e9b670 100644--- a/src/core/persistence/memory-mutations.ts+++ b/src/core/persistence/memory-mutations.ts@@ -206,7 +206,7 @@ export async function submitRememberMutation(ctx: OperationContext, params: Recoconst ownPage = scopePage ? null : memberFactPage(ctx);const memberPage = scopePage ? SCOPE_PAGE_SLUG : p.share === true ? null : ownPage;const call: RememberCall = memberPage ? { p: { ...p, visibility: scopePage ? 'world' : 'private', infer_entity: false }, visibilityDefaulted: false }- : { p, visibilityDefaulted: opts.visibilityDefaulted === true };+ : { p, visibilityDefaulted: opts.visibilityDefaulted === true || p.share === true };const inference = entity === null && !memberPage ? await inferRememberTarget(ctx, sourceId, source, call) : null;const linked = inference && 'target' in inference ? inference : null;const entitySlug = linked?.target.slug ?? resolved?.slug ?? null;diff --git a/src/core/persistence/memory-prepare.ts b/src/core/persistence/memory-prepare.tsindex 49107c0696..fc312fb22e 100644--- a/src/core/persistence/memory-prepare.ts+++ b/src/core/persistence/memory-prepare.ts@@ -84,6 +84,11 @@ export async function prepareMemoryMutation(engine: BrainEngine, row: WriteRequeif (p.scope_page === true && snapshot && !await scopePageIsShared(engine, { ...snapshot.page, source_id: row.source_id, slug: row.slug })) throw scopePageNotShared(row.source_id);// A defaulted visibility never lands broader than the target page as it stands at publication.if (p.visibility_defaulted === true && snapshot) input.visibility = tightenToPage(input.visibility, await withFolderRestricted(engine, snapshot.page));+ // GST-2243: a shared fact whose page turned restricted after admission is refused, never saved private under a world receipt.+ if (p.share === true && input.visibility !== 'world') {+ throw Object.assign(opError('invalid_params', `remember: share: true cannot share a fact on ${row.slug}, whose facts are now kept private; nothing was saved.`,+ 'Share it on a page every reader of this source can read, or drop share to keep the fact on your own page.'), { reason: 'share_target_restricted' });+ }if (p.expected_revision !== undefined) assertPageRevision(snapshot, engineMutationPrecondition(parseMutationPrecondition(p)));const observedRevision = snapshot?.revision ?? null;const excludePrivate = await resolveExcludePrivatePages(engine, row.authority.remote === true);diff --git a/src/mcp/http-transport.ts b/src/mcp/http-transport.tsindex 07498d9428..989224fdcb 100644--- a/src/mcp/http-transport.ts+++ b/src/mcp/http-transport.ts@@ -473,7 +473,7 @@ export async function startHttpTransport(opts: HttpTransportOptions) {capabilities: { tools: {}, resources: {} },// #4748: contract (+ opt-in writeback section) + deployment identity.instructions: resolveMcpInstructions(fileConfig, process.env, {- writeback: ambientOptsFrom(writeback, { remember: canWriteOp('remember'), extractFacts: canWriteOp('extract_facts') }),+ writeback: ambientOptsFrom(writeback, { remember: canWriteOp('remember'), extractFacts: canWriteOp('extract_facts'), member: !!auth.auth?.member }),tools: await httpInstructionTools(engine, fileConfig, { ops: surfacedOps, surface, auth: auth.auth!, allowedOps: surfaceAllowedOps }), // F1...await readInstructionContent(engine),}),diff --git a/src/mcp/instructions.ts b/src/mcp/instructions.tsindex af369e973a..cde2b73115 100644--- a/src/mcp/instructions.ts+++ b/src/mcp/instructions.ts@@ -95,7 +95,7 @@ function contractClauses(c: CallablePredicate, writeback?: AmbientWritebackOptsif (c('remember')) loop.push('`remember` what the user explicitly asks you to keep, with provenance, and preserve corrections');// #6170: capped harnesses read the first 2,048 characters; the writeback line and the error protocol live there.const capture = writeback- ? `Ambient writeback is ON (${writeback.mode}): unprompted, \`remember\` the user's preferences, corrections, decisions and commitments${writeback.visibility === 'private' ? ' with visibility "private"' : ''} (rules below).`+ ? `Ambient writeback is ON (${writeback.mode}): unprompted, \`remember\` the user's preferences, corrections, decisions and commitments${writeback.visibility === 'private' && !writeback.member ? ' with visibility "private"' : ''} (rules below).`: 'Automatic capture is opt-in.';const recallNote = c('recall') && any('search', 'query') ? ` Facts saved with remember are read back with recall${c('entity') ? ' (or entity)' : ''}, not search.` : '';out.push(`${loop.length ? `Memory loop: ${loop.join('; ')}. ` : 'Use relevant memory across conversations. '}${capture}${recallNote}`);diff --git a/test/mcp-instructions-writeback.test.ts b/test/mcp-instructions-writeback.test.tsindex d5e6300caf..b990ba7fcc 100644--- a/test/mcp-instructions-writeback.test.ts+++ b/test/mcp-instructions-writeback.test.ts@@ -29,6 +29,15 @@ const BASE_OPTS = {};describe('buildAmbientWritebackSection (F1 leaf — the single source)', () => {+ test('GST-2243: a member caller is told to omit visibility and share team facts with share: true', () => {+ for (const visibility of ['world', 'private'] as const) {+ const s = buildAmbientWritebackSection({ ...BASE_OPTS, visibility, member: true });+ expect(s).not.toContain('Pass visibility:');+ expect(s).toContain('share: true');+ expect(s).toContain('only the brain host can withdraw it');+ }+ });+test('salient mode carries the durable-only candidate policy', () => {const s = buildAmbientWritebackSection(BASE_OPTS);expect(s).toContain('mode: salient');diff --git a/test/remember-share-gst2243.test.ts b/test/remember-share-gst2243.test.tsindex 5e581ae839..78a2c5ee65 100644--- a/test/remember-share-gst2243.test.ts+++ b/test/remember-share-gst2243.test.ts@@ -22,6 +22,7 @@ import { dispatchToolCall, type ToolResult } from '../src/mcp/dispatch.ts';import { __resetPrivateVisibilityCacheForTests } from '../src/core/search/private-visibility.ts';import { __resetHotMemoryCacheForTests, getBrainHotMemoryMeta } from '../src/core/facts/meta-hook.ts';import { addMember, bindCredential } from '../src/core/access/members.ts';+import { prepareMemoryMutation } from '../src/core/persistence/memory-prepare.ts';import { linkMember } from '../src/core/access/actor.ts';import type { AuthInfo } from '../src/core/ops/contract.ts';import { testBackends } from './helpers/test-backends.ts';@@ -138,6 +139,13 @@ for (const kind of testBackends()) {expect(out.isError).toBe(true);expect(out.all).toContain('share_target_restricted');expect(await factRow('canaryrestricted')).toBeUndefined();+ const explicitWorld = await remember(U, 'Globex pilot ends in May canaryrestrictedworld', { entity: TEAM_PAGE, share: true, visibility: 'world' });+ expect(explicitWorld.isError).toBe(true);+ expect(await factRow('canaryrestrictedworld')).toBeUndefined();+ const [page] = await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE source_id = $1 AND slug = $2', [SRC, TEAM_PAGE]);+ const row = { operation: 'remember', request_id: 'gst2243-prepare-' + randomUUID().slice(0, 6), source_id: SRC, slug: TEAM_PAGE, page_id: page!.id,+ intent: { fact: 'Globex pilot ends in June canaryprepshare', kind: 'fact', visibility: 'world', visibility_defaulted: true, share: true, entity_slug: TEAM_PAGE, fence: true, valid_from: new Date().toISOString() } };+ await expect(prepareMemoryMutation(engine, row as never, {} as never)).rejects.toMatchObject({ code: 'invalid_params' });}, 120_000);test('a replayed remember and a non-member remember both name page and visibility', async () => {