Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

remember: a stdio server bound to a member gets the member writeback rule too (GST-2243 fix-check)

garrytan512071bcc141
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14cb8fb6b2..f64a04ae92 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,7 +18,7 @@ identifiers and attribution are available in the pre-removal Git revision
- `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 (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/facts/writeback-instructions.ts`, `writeback-config.ts`, `src/mcp/instructions.ts` and the HTTP serves: with ambient writeback on, a member credential is told to omit `visibility` and to pass `share: true` only for facts about the team's work, instead of the brain-wide "pass visibility: world" line its saves would now be refused for.
+- `src/core/facts/writeback-instructions.ts`, `writeback-config.ts`, `src/mcp/instructions.ts`, the HTTP serves, the stdio serve bound through `mcp.stdio_member` and `memory_conversation_mode`: with ambient writeback on, a member caller is told to omit `visibility` and to pass `share: true` only for facts about the team's work, instead of the brain-wide "pass visibility: world" line its saves would now be refused for.
- `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/core/ops/memory-settings.ts b/src/core/ops/memory-settings.ts
index b0d4633795..c18198e6e2 100644
--- a/src/core/ops/memory-settings.ts
+++ b/src/core/ops/memory-settings.ts
@@ -15,6 +15,7 @@ import { opError, OperationError } from './contract.ts';
import { hostFix } from './op-fix.ts';
import { opAllowedForBoundClient } from './context.ts';
import { hasScope } from '../scope.ts';
+import { callerMember } from '../access/member-facts.ts';
import { buildAmbientWritebackSection } from '../facts/writeback-instructions.ts';
import { CAPTURE_GATE_LANES, CAPTURE_LANE_LABELS, captureGateDecision, resolveWritebackConfig, type WritebackMode } from '../facts/writeback-config.ts';
import {
@@ -74,7 +75,7 @@ function ruleFor(res: AgentWritebackResolution, mode: WritebackMode, ctx: Operat
visibility: res.operator.visibility,
extractFactsAvailable: callerCan(ctx, EXTRACT_FACTS_OP),
origin,
- ...(ctx.remote !== false && ctx.auth?.member ? { member: true } : {}),
+ ...(ctx.remote !== false && callerMember() ? { member: true } : {}),
});
}
diff --git a/src/mcp/server.ts b/src/mcp/server.ts
index aa0221010b..ce0adccb10 100644
--- a/src/mcp/server.ts
+++ b/src/mcp/server.ts
@@ -30,6 +30,7 @@ import { isEngineDegraded, onEngineRecovered } from '../core/degraded-marker.ts'
import { assertStdioSourceBindable } from './source-preflight.ts';
import { readOnlyServeSkipsResidentDuties } from '../core/direct-pool-profile.ts';
import { hookSessionCwd } from '../core/session-cwd.ts';
+import { stdioMemberIdentity } from '../core/access/caller.ts';
/**
* Largest JSON-RPC message the stdio server reads (the SDK default is 10 MiB,
@@ -368,6 +369,7 @@ export async function startMcpServer(engine: BrainEngine, opts: { surface?: McpS
const writebackOpts = writeback ? ambientOptsFrom(writeback, {
remember: session.allowedOps ? session.allowedOps.has('remember') : true,
extractFacts: session.allowedOps ? session.allowedOps.has('extract_facts') : true,
+ member: (await stdioMemberIdentity(engine)).some(p => p.startsWith('member:')),
}) : null;
server = new Server(
{ name: 'gbrain', version: VERSION, description: MCP_SERVER_DESCRIPTION },
diff --git a/test/memory-settings.test.ts b/test/memory-settings.test.ts
index e77524ab7d..0cab8afa92 100644
--- a/test/memory-settings.test.ts
+++ b/test/memory-settings.test.ts
@@ -16,6 +16,7 @@ import { buildAmbientWritebackSection } from '../src/core/facts/writeback-instru
import { ambientOptsFrom, captureLaneStates, resolveWritebackConfig } from '../src/core/facts/writeback-config.ts';
import { resolveAgentWriteback } from '../src/core/facts/writeback-settings.ts';
import type { AuthInfo } from '../src/core/ops/contract.ts';
+import { addMember } from '../src/core/access/members.ts';
import type { GBrainConfig } from '../src/core/config.ts';
const CONFIG = { engine: 'pglite' } as GBrainConfig;
@@ -243,6 +244,16 @@ describe('get_memory_settings', () => {
});
describe('memory_conversation_mode', () => {
+ test('GST-2243: a stdio server bound to a member (mcp.stdio_member) gets the member rule, never "pass visibility: world"', async () => {
+ await addMember(engine, 'alice-example');
+ await engine.setConfig('mcp.stdio_member', 'alice-example');
+ const res = await dispatchToolCall(engine, 'memory_conversation_mode', { mode: 'all' }, { remote: true, transport: 'stdio', config: CONFIG, sourceId: 'default' });
+ const body = JSON.parse(res.content[0].text) as Record<string, any>;
+ expect(res.isError === true).toBe(false);
+ expect(body.rule_text).toContain('share: true');
+ expect(body.rule_text).not.toContain('Pass visibility:');
+ });
+
test('all returns a conversation rule with the brain\'s private posture, even when the operator set off; nothing is stored', async () => {
await engine.setConfig('memory.auto_writeback', 'off');
await engine.setConfig('facts.default_visibility', 'private');