Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
context_pack's person read narrows to the named source too; name the one-source rule in its refusal
garrytan79acf8044704
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f88af9d380..c721759fe0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,7 +16,7 @@ identifiers and attribution are available in the pre-removal Git revision**context_pack reads a room as its audience.** A QM client that reads named sources as the scope used to be refused when it asked `context_pack` for a room's source, so QM had no session brief in shared conversations. Now a call that names `source_id` reads only that source: its entities and `entity_refs`, the core block, the counterparty brief and hot facts. Nothing from the person's own member page or from pages kept to named readers comes back, and privacy is never relaxed.- A scope call is refused with `invalid_params` before anything is read when it sends `entity_refs` without `source_id`, names an `entity_refs` entry in another source, or sends `session_id` (a session's thread rows are the person's).-- A client set `--attest-read person` keeps reading as the person.+- A client set `--attest-read person` keeps reading as the person, and its pack is narrowed to the named source the same way.- Contract `docs/contracts/qm-memory-provider/v5.json` marks `context_pack` `scope_read: true`. v1 to v4 stay byte for byte as published, and v4's markings are frozen in the builder.**`gbrain mcp admin attest <client> --attest-read person|scope|none`** sets the same `attest_read` that `gbrain auth rescope --attest-read` sets, over the owner session (`attestRead` on `/admin/api/access/attest`). It refuses what the local command refuses, previews with `--dry-run`, and logs `attest_read` in the `access_admin` row.diff --git a/docs/contracts/qm-memory-provider/v5.json b/docs/contracts/qm-memory-provider/v5.jsonindex 7fde8f263b..12264cfd0c 100644--- a/docs/contracts/qm-memory-provider/v5.json+++ b/docs/contracts/qm-memory-provider/v5.json@@ -257,7 +257,7 @@"marked": "scope_read: true: a call that names sources (source_id, source_ids or all_sources, where the tool's input_schema declares them) reads those sources as their audience, never as the person, as memory_recall's scope_read does: no member-page fact, no page restricted to named readers, and privacy is never relaxed","every_source": "under a scope read, source_id '__all__', '__all__' in source_ids and all_sources: true are refused with invalid_params; nothing is read","unmarked": "scope_read: false: the tool reads as the person whatever the call names",- "context_pack": "a context_pack scope read names one source in source_id and reads only it: entities, cards, core memory, the counterparty brief and hot facts; entity_refs also name sources, and each must carry that same source_id; a call with entity_refs and no source_id, an entity_refs entry in another source, or session_id is refused with invalid_params, and nothing is read",+ "context_pack": "a context_pack scope read names one source in source_id and reads only it: entities, cards, core memory, the counterparty brief and hot facts; entity_refs also name sources, and each must carry that same source_id; a call with entity_refs and no source_id (source_ids alone names none), an entity_refs entry in another source, or session_id is refused with invalid_params, and nothing is read; with --attest-read person the pack reads as the person, narrowed to source_id the same way","as_person": "a credential the brain operator binds with --attest-read person reads named sources as the person instead, narrowed to those sources","without_sources": "the person read (read_as above)"},diff --git a/scripts/build-qm-memory-contract.ts b/scripts/build-qm-memory-contract.tsindex bcfdbd4fc1..5b11535d5c 100644--- a/scripts/build-qm-memory-contract.ts+++ b/scripts/build-qm-memory-contract.ts@@ -215,7 +215,7 @@ export function buildQmMemoryContract(version: QmContractVersion): Record<stringevery_source: "under a scope read, source_id '__all__', '__all__' in source_ids and all_sources: true are refused with invalid_params; nothing is read",unmarked: v5 ? 'scope_read: false: the tool reads as the person whatever the call names': 'scope_read: false: the tool reads as the person whatever the call names; context_pack refuses a call that names sources or entity_refs with invalid_params (nothing is read) unless the credential reads named sources as the person',- ...(v5 ? { context_pack: 'a context_pack scope read names one source in source_id and reads only it: entities, cards, core memory, the counterparty brief and hot facts; entity_refs also name sources, and each must carry that same source_id; a call with entity_refs and no source_id, an entity_refs entry in another source, or session_id is refused with invalid_params, and nothing is read' } : {}),+ ...(v5 ? { context_pack: 'a context_pack scope read names one source in source_id and reads only it: entities, cards, core memory, the counterparty brief and hot facts; entity_refs also name sources, and each must carry that same source_id; a call with entity_refs and no source_id (source_ids alone names none), an entity_refs entry in another source, or session_id is refused with invalid_params, and nothing is read; with --attest-read person the pack reads as the person, narrowed to source_id the same way' } : {}),as_person: 'a credential the brain operator binds with --attest-read person reads named sources as the person instead, narrowed to those sources',without_sources: 'the person read (read_as above)',} } : {}),diff --git a/src/core/access/scope-read.ts b/src/core/access/scope-read.tsindex 997a5b5624..b5493a06eb 100644--- a/src/core/access/scope-read.ts+++ b/src/core/access/scope-read.ts@@ -64,7 +64,7 @@ function assertPackConfined(params: Record<string, unknown>): void {const source = params.source_id;const refused = (problem: string, fix: string) => opError('invalid_params', `context_pack: ${problem}, and this credential reads named sources as their audience, so it is refused. Nothing was read.`, fix,{ why: 'A scope read must name exactly the one source it reads, so the pack never reads past the scope the turn serves.' });- if (typeof source !== 'string' || !source) throw refused('a call with entity_refs names no source_id', 'Pass source_id with the source the entity_refs name, or leave entity_refs out to read as the person.');+ if (typeof source !== 'string' || !source) throw refused('a scope read of the pack names exactly one source in source_id, and this call names none', 'Pass source_id with the one source to read (the source every entity_refs entry names), or leave source_ids and entity_refs out to read as the person.');if ((params.entity_refs as unknown[] | undefined)?.some(ref => (ref as { source_id?: unknown } | null)?.source_id !== source)) {throw refused(`an entity_refs entry names a source other than source_id '${source}'`, 'Name only entities in the source_id the call reads, each with that source_id.');}diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 21202f5a93..7d564727bc 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1563,7 +1563,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.693.0', id: 'member_save_withdrawn_scope_gst2346', text: 'A remote `remember` onto a member\'s own page (`memory/members/<id>`) is refused `fact_withdrawn` only when that member could read what was withdrawn: a fact on its own page, its own copy withdrawn by the brain host, or for the brain owner a fact it reads. A claim withdrawn by the brain host or the owner that the member never read no longer refuses its save: the fact saves as the member\'s own active row with the same reply as a new claim. A schema migration makes the database insert guards mark a row on a member page only by that page\'s own withdrawals; a withdrawal still expires matching rows on member pages when it is made, and strikes them in the page\'s file, so an import of a member page\'s file no longer marks a row withdrawn by a withdrawal of another subject. The same holds for each item of a `remember` batch (`items`), a replay with the same `request_id`, a `replaces` and the write receipt (`get_write_request`). Trusted local saves keep the check they had.' },{ since: '0.60.694.0', id: 'owner_labels_guarded_gst2521', text: 'Labels the owner sets with `gbrain repair visibility` (or its `--readers` setter, or `gbrain repair private-labels`) now raise the page\'s label guard to operator_curated, so a later local agent write at the page\'s own tier that drops or widens them is held like a write over an owner page, with a `lower_page` item. A local write below operator_curated whose `readable_by` would leave the brain owner out of a page the owner reads now publishes with the owner kept in the readers (the rest of the narrowing applies), and its item records the requested readers. Accepting such an item (`gbrain trust confirm tp<id>`) on a page whose own tier is an agent\'s writes only the labels and keeps the agent\'s tier; on an owner page it still endorses the edit at the owner\'s tier. The guard is stored in the database (`page_label_guards`) and set only by label repairs run after the upgrade, so labels set earlier, and a managed Git brain rebuilt from a clone, start unguarded; re-running `gbrain repair visibility --slug` or `--readers` on a page that already has those labels raises the guard without changing them. The owner\'s own label writes, synced owner edits, agent narrowing that keeps the owner, and brains with `access.owner_reads_restricted` on are unchanged.' },{ since: '0.60.694.0', id: 'page_label_widening_held_gst2518', text: 'A local agent write (`put_page`, `capture`, `edit_page`, `append_page`, `revert_version`, `restore_page`) less trusted than a page that drops or widens its `visibility`, `access`, `confidentiality` or `readable_by` now publishes with the page\'s earlier labels kept, in the database and in the committed file, and its receipt lists them under `privacy_labels_kept`; so does a maintenance job\'s derived page publication, and a page whose tier is still `unknown` counts as the owner\'s. A soft delete no longer lowers the page\'s tier. Before, the page became readable to remote callers and other members at once, and only a `lower_page` item waited for the owner. That item now records the requested labels: `gbrain trust confirm tp<id>` applies them if the page has not changed since, `gbrain trust drop tp<id>` keeps the earlier ones, and undoing a confirm restores them while the page is unchanged since. Narrowing writes, label-neutral writes, writers at or above the page\'s tier, synced owner edits and `gbrain repair visibility` are unchanged.' },- { since: 'TBD', id: 'qm_context_pack_scope_read_gst2407', text: 'An attested `context_pack` that names `source_id` now reads that one source as its audience instead of being refused on a client that reads named sources as the scope: its entities and `entity_refs`, the core block, the counterparty brief and hot facts come from that source only, with no member-page fact, no page restricted to named readers and privacy never relaxed. A call that sends `entity_refs` without `source_id`, an `entity_refs` entry in another source, or `session_id` is refused with `invalid_params` before anything is read. A client set `--attest-read person` reads as the person, as before. Contract `docs/contracts/qm-memory-provider/v5.json` marks `context_pack` `scope_read: true`; v1 to v4 are unchanged.' },+ { since: 'TBD', id: 'qm_context_pack_scope_read_gst2407', text: 'An attested `context_pack` that names `source_id` now reads that one source as its audience instead of being refused on a client that reads named sources as the scope: its entities and `entity_refs`, the core block, the counterparty brief and hot facts come from that source only, with no member-page fact, no page restricted to named readers and privacy never relaxed. A call that sends `entity_refs` without `source_id`, an `entity_refs` entry in another source, or `session_id` is refused with `invalid_params` before anything is read. A client set `--attest-read person` reads as the person, narrowed to that source the same way. Contract `docs/contracts/qm-memory-provider/v5.json` marks `context_pack` `scope_read: true`; v1 to v4 are unchanged.' },{ since: 'TBD', id: 'qm_admin_attest_read_gst2407', text: 'The owner can now set how a client reads named sources from another machine: `gbrain mcp admin attest <client> --attest-read person|scope|none`, backed by `attestRead` on `/admin/api/access/attest`. It refuses what `gbrain auth rescope --attest-read` refuses (no attest right, or a client with scope sources set to person), previews with `--dry-run` and logs `attest_read` in the `access_admin` row.' },];diff --git a/src/core/ops/facts.ts b/src/core/ops/facts.tsindex da9cf0b60e..b6f9cdca8b 100644--- a/src/core/ops/facts.ts+++ b/src/core/ops/facts.ts@@ -756,8 +756,8 @@ const context_pack: Operation = {// #6723: names resolve across the readable sources (home first) unless source_id pins one; entity_refs name their source.const { ambientMissNotice, entityRefs, entitySources } = await import('../verbs/entity-source.ts');const walk = await entitySources(ctx, p, 'context_pack');- const scoped = (await import('../access/scope-read.ts')).currentReadMode() === 'scope';- const sourceId = scoped ? walk.home : ctx.sourceId ?? 'default';+ const named = (await import('../access/scope-read.ts')).currentReadMode() !== undefined;+ const sourceId = named ? walk.home : ctx.sourceId ?? 'default';const refs = (await entityRefs(ctx, p.entity_refs, PACK_DEFAULT_MAX_ENTITIES)).slice(0, PACK_DEFAULT_MAX_ENTITIES - names.length);const entities = [...names, ...refs.map((r) => r.name)];// Fail-closed: private only when EXPLICITLY requested AND the caller is@@ -794,7 +794,7 @@ const context_pack: Operation = {// Always-loaded core tier (core-memory.ts): owner-designated pages of// `default` plus this source, inside the caller's grant; it packs first.const { loadCoreBlock } = await import('../core-memory.ts');- const allowed = scoped ? [sourceId] : ctx.auth?.allowedSources?.length ? ctx.auth.allowedSources : null;+ const allowed = named ? [sourceId] : ctx.auth?.allowedSources?.length ? ctx.auth.allowedSources : null;const core = await loadCoreBlock(ctx.engine, { sessionSourceId: sourceId, allowedSources: allowed, excludePrivate: !includePrivate, forCaller: true, eligibility }).catch(() => null);const coreText = core?.text ?? '';diff --git a/test/qm-scope-read.test.ts b/test/qm-scope-read.test.tsindex a217916133..49940bd7e5 100644--- a/test/qm-scope-read.test.ts+++ b/test/qm-scope-read.test.ts@@ -257,6 +257,11 @@ for (const kind of testBackends()) {expect((await call('ctx', 'context_pack', { counterparty: 'Zephyr Restricted Example' })).isError).toBe(false);const person = await call('ctxp', 'context_pack', { entities: 'Acme Example', source_id: SRC, session_id: 'session-a' });expect(person.isError).toBe(false);+ const personRoom = await call('ctxp', 'context_pack', { entities: 'Room Example', counterparty: 'Acme Example', source_id: ROOM });+ expect(personRoom.all).toContain('canarycoreroom');+ for (const leak of ['canarycoresrc', 'acme-example']) expect(personRoom.all).not.toContain(leak);+ const ids = await refused(call('ctx', 'context_pack', { entities: 'Acme Example', source_ids: [SRC] }), 'invalid_params');+ expect(ids.all).toContain('names exactly one source in source_id');} finally {await engine.setConfig('memory.core.enabled', 'false');}