Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
wip: owner opt-in, whoami, doctor
garrytan65395bc18766
diff --git a/src/cli/as-preview.ts b/src/cli/as-preview.tsindex ddafc30bda..775f2c1275 100644--- a/src/cli/as-preview.ts+++ b/src/cli/as-preview.ts@@ -48,7 +48,7 @@ export async function openAsPreview(engine: BrainEngine, member: string | undefi}const { withCallerAccess } = await import('../core/search/private-visibility.ts');const folder = await (await import('../core/access/caller.ts')).folderAccessFor(engine, identity);- const access = { identity, ...folder, applyRemoteReadPolicy: true, hidePrivate: !owner, owner, ownerReadsRestricted, privateReadableSources: [] };+ const access = { identity, ...folder, applyRemoteReadPolicy: true, hidePrivate: !owner, owner, ownerLineage: owner, ownerReadsRestricted, privateReadableSources: [] };return {run: fn => withCallerAccess(access, fn),context: ctx => ({ ...ctx, accessIdentity: identity, applyRemoteReadPolicy: true }),diff --git a/src/commands/access.ts b/src/commands/access.tsindex 8d18ecddc7..f01044c583 100644--- a/src/commands/access.ts+++ b/src/commands/access.ts@@ -24,7 +24,7 @@ import { readClientGrant } from '../core/grants/service.ts';import { resolveTokenGrant } from '../core/grants/legacy-token.ts';import { accessAllowedSql, isPrivacyPrivatePage, withCallerAccess } from '../core/search/private-visibility.ts';import { folderAccessFor } from '../core/access/caller.ts';-import { identityFor, normalizePrincipal, normalizeReaders } from '../core/access/principals.ts';+import { identityFor, MEMBER_PAGE_PREFIX, normalizePrincipal, normalizeReaders } from '../core/access/principals.ts';import { mayActForCovers, singleMemberAudience, type AudiencePrincipal } from '../core/access/audience.ts';import { linkMember, linkMemberByEmail, listMemberLinks, unlinkMember } from '../core/access/actor.ts';import { bindMemberSource, listMemberSources, unbindMemberSource } from '../core/access/member-sources.ts';@@ -229,7 +229,7 @@ export async function accessCheck(engine: BrainEngine, target: { token?: string;: `Reads as member "${member!.id}"${member!.groups.length ? ` (groups: ${member!.groups.join(', ')})` : ''}: pages naming readers are visible when they list the member or one of its groups, within the grant below.`+ (owner ? ' It is the brain owner: it also reads visibility: private pages, privacy-alias pages, derived and pinned-question pages and private facts in every source the grant reads.' : '')+ (ownerReadsRestricted ? (owner- ? ' access.owner_reads_restricted is on: in reads it also reads pages that readers lists and folder or page rules keep to other members, and their derived pages and facts, except another member's own member page.'+ ? ' access.owner_reads_restricted is on: in reads it also reads pages that readers lists and folder or page rules keep to other members, and their derived pages and facts, except another member\'s own member page.': ` access.owner_reads_restricted is on: the brain owner (${ownerId}) also reads the pages this credential's readers lists and rules keep to it, except its own member page.`) : '');const result: AccessCheckResult = {credential,@@ -372,7 +372,7 @@ function ownerLines(v: OwnerView): string[] {return [`Owner: ${v.owner}`,` Credentials that read as the owner (${v.bound_credentials.length}): ${v.bound_credentials.map(c => `${c.kind} ${c.name}`).join(', ') || 'none'}`,v.reads_restricted- ? ' Owner reads member-restricted pages: on (access.owner_reads_restricted). Its credentials read pages that readers lists and folder or page rules keep to other members, and their derived pages and facts; never another member's own member page. Turn off: gbrain access owner reads-restricted off'+ ? ' Owner reads member-restricted pages: on (access.owner_reads_restricted). Its credentials read pages that readers lists and folder or page rules keep to other members, and their derived pages and facts; never another member\'s own member page. Turn off: gbrain access owner reads-restricted off': ' Owner reads member-restricted pages: off. It reads a page that names readers or sits under a rule only when listed. Turn on: gbrain access owner reads-restricted on',` Bind one: gbrain auth rescope --token <name> --member ${v.owner} (a stdio server: gbrain config set mcp.stdio_member ${v.owner})`];}diff --git a/src/commands/doctor/checks/owner-reads-restricted.ts b/src/commands/doctor/checks/owner-reads-restricted.tsnew file mode 100644index 0000000000..44999540f3--- /dev/null+++ b/src/commands/doctor/checks/owner-reads-restricted.ts@@ -0,0 +1,47 @@+/**+ * GST-2490 owner opt-in doctor check.+ *+ * - access_owner_reads_restricted: config access.owner_reads_restricted is on, so credentials bound to the brain owner+ * read pages that readers lists and folder or page rules keep to other members (and their derived pages and facts),+ * except another member's own member page. Reported so nobody on a shared brain reads under it unknowingly; a warn+ * when it is on but names no enabled owner (no credential reads under it).+ *+ * Off, the check is not applicable.+ */+import type { Check } from '../../doctor.ts';+import { agentFix, checkError, infoCheck } from '../check-fix.ts';+import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';+import { ownerReadsRestrictedOn, ownerView } from '../../../core/access/owner.ts';++const name = 'access_owner_reads_restricted';++async function verdict(ctx: DoctorContext): Promise<Check> {+ const engine = connectedEngine(ctx);+ try {+ if (!(await ownerReadsRestrictedOn(engine))) {+ return infoCheck(name, 'Not applicable: the owner opt-in (access.owner_reads_restricted) is off; the owner reads a page that names readers or sits under a rule only when listed.', 'not_applicable');+ }+ const view = await ownerView(engine);+ const details = { owner: view.owner, bound_credentials: view.bound_credentials.length };+ if (!view.owner) {+ return { name, status: 'warn', details,+ message: 'access.owner_reads_restricted is on, but no enabled member is named as the owner, so no credential reads under it. Name the owner or turn the opt-in off.',+ fix: agentFix(['gbrain', 'access', 'owner', '--json'], 'Read-only: shows the configured owner and why it is not in effect.', name, { ask_user: true }) };+ }+ return { name, status: 'ok', details,+ message: `The owner opt-in is on: the ${view.bound_credentials.length} credential(s) bound to owner ${view.owner} read pages that readers lists and folder or page rules keep to other members, and their derived pages and facts, except another member's own member page. Every member's whoami reports it. Turn it off with gbrain access owner reads-restricted off.` };+ } catch (error) {+ return checkError(name, `run ${name}`, error);+ }+}++async function runOwnerReadsRestricted(ctx: DoctorContext): Promise<Check[]> {+ const { name: _name, ...check } = await verdict(ctx);+ return [{ name, ...check }];+}++export const ownerReadsRestrictedEntry: DoctorEntry = {+ name,+ emits: [name],+ run: runOwnerReadsRestricted,+};diff --git a/src/commands/doctor/registry.ts b/src/commands/doctor/registry.tsindex a9c740a4b3..5f96d2073c 100644--- a/src/commands/doctor/registry.ts+++ b/src/commands/doctor/registry.ts@@ -143,6 +143,7 @@ import { memberAccessEntry } from './checks/member-access.ts';import { folderAccessEntry } from './checks/folder-access.ts';import { unlabeledPeopleFoldersEntry } from './checks/unlabeled-people-folders.ts';import { sharedAgentAccessEntry } from './checks/shared-agent-access.ts';+import { ownerReadsRestrictedEntry } from './checks/owner-reads-restricted.ts';import { attestReadAccessEntry } from './checks/attest-read-access.ts';import { originTwinsEntry } from './checks/origin-twins.ts';import { slugPathMismatchEntry } from './checks/slug-path-mismatch.ts';@@ -229,6 +230,7 @@ export const DOCTOR_CHECK_REGISTRY: readonly DoctorEntry[] = [folderAccessEntry,unlabeledPeopleFoldersEntry,sharedAgentAccessEntry,+ ownerReadsRestrictedEntry,attestReadAccessEntry,rlsEntry,postgresTlsEntry,diff --git a/src/core/access/caller.ts b/src/core/access/caller.tsindex 2cb7388572..6a8fe9087a 100644--- a/src/core/access/caller.ts+++ b/src/core/access/caller.ts@@ -205,8 +205,9 @@ export async function resolveAudienceIdentities(engine: Pick<BrainEngine, 'execu* GST-2059: a caller bound to the brain owner (config access.owner_member) reads with its privacy relaxed in every* source its grant reads (owner), with no audience or an audience of the owner alone; member access stays.* GST-363: `stdioMember` is the member an unauthenticated stdio server was started with (serve --stdio-member).- * GST-2490: `readOnly` (a non-mutating operation) lets an owner read under access.owner_reads_restricted; a write's- * checks keep the owner's ordinary member access, so its pre-check and its publication agree.+ * GST-2490: `readOnly` (a non-mutating operation) gives an owner read the owner's lineage (a derivative of origins it+ * reads) and, under access.owner_reads_restricted, the opt-in; a write's checks keep the every-caller rule, so its+ * pre-check and its publication agree.*/export async function remoteCallerAccess(engine: BrainEngine, auth: AuthInfo | undefined, privateSources: readonly string[] | undefined, transport?: string, audience?: readonly AudiencePrincipal[] | null, stdioMember?: string, readOnly = false): Promise<Partial<CallerAccess>> {const [relaxed, remotePolicy] = await Promise.all([remotePrivacyRelaxed(engine), requestRemotePolicy(engine)]);@@ -224,6 +225,7 @@ export async function remoteCallerAccess(engine: BrainEngine, auth: AuthInfo | uprivateReadableSources: single ? privateSources ?? [] : [],hidePrivate: single ? !relaxed && !owner : true,owner,+ ownerLineage: owner && readOnly,ownerReadsRestricted: owner && readOnly && remotePolicy.ownerReadsRestricted === true,applyRemoteReadPolicy: false,restricted,@@ -240,6 +242,7 @@ export async function remoteCallerAccess(engine: BrainEngine, auth: AuthInfo | uprivateReadableSources: privateSources ?? [],hidePrivate: !relaxed && !owner,owner,+ ownerLineage: owner && readOnly,ownerReadsRestricted: owner && readOnly && remotePolicy.ownerReadsRestricted === true,applyRemoteReadPolicy: false,restricted,diff --git a/src/core/access/member-facts.ts b/src/core/access/member-facts.tsindex 10ddc11141..3738c0d799 100644--- a/src/core/access/member-facts.ts+++ b/src/core/access/member-facts.ts@@ -195,7 +195,7 @@ export function callerIdentityKey(): string {const access = currentCallerAccess();if (!access.actor && !access.identity.length && !access.audienceIdentities.length && !access.audience) return '';const parts = { actor: access.actor ? [access.actor.system, access.actor.member] : null, identity: access.identity, audience: access.audienceIdentities, entries: access.audience,- ...(access.ownerReadsRestricted ? { owner_reads_restricted: true } : {}) };+ ...(access.ownerLineage ? { owner_reads: access.ownerReadsRestricted ? 'restricted' : 'lineage' } : {}) };return createHash('sha256').update(JSON.stringify(parts)).digest('hex').slice(0, 16);}diff --git a/src/core/access/owner.ts b/src/core/access/owner.tsindex 944bbeafe3..485b9d83fc 100644--- a/src/core/access/owner.ts+++ b/src/core/access/owner.ts@@ -59,6 +59,15 @@ export async function ownerReadsRestrictedOn(engine: Pick<BrainEngine, 'getConfi}}+/**+ * GST-2490: what whoami adds for every remote caller while the owner opt-in is on and names a live owner, so a member's+ * agent can find out that the owner reads the pages kept to it. Empty otherwise.+ */+export async function ownerReadsRestrictedNotice(engine: BrainEngine): Promise<{ owner_reads_restricted?: true; owner_reads_restricted_note?: string }> {+ if (!(await ownerReadsRestrictedOn(engine)) || !(await ownerView(engine)).owner) return {};+ return { owner_reads_restricted: true, owner_reads_restricted_note: "The brain owner's credentials read every page on this brain that readers lists or folder or page rules keep to members, including pages kept to this connection, and their derived pages and facts; never a member's own member page. The brain operator set this (config access.owner_reads_restricted)." };+}+/*** GST-2490: turns the owner opt-in on or off. Only the trusted local operator may: a remote caller (anything whose* `remote` is not strictly false) is refused before anything is written.@@ -68,7 +77,7 @@ export async function setOwnerReadsRestricted(engine: BrainEngine, on: boolean,throw hostOnlyError({ remote: true, transport: 'http' }, 'permission_denied','Only the brain operator on the brain host turns the owner opt-in on or off, so nothing was changed.',['gbrain', 'access', 'owner', 'reads-restricted', on ? 'on' : 'off'],- 'Lets the owner's credentials read pages that readers lists and folder or page rules keep to other members. Whether the owner reads them is the brain operator's decision, never an agent's.');+ 'Lets the owner\'s credentials read pages that readers lists and folder or page rules keep to other members. Whether the owner reads them is the brain operator\'s decision, never an agent\'s.');}if (on) await engine.setConfig(OWNER_READS_RESTRICTED_KEY, '1');else await engine.unsetConfig(OWNER_READS_RESTRICTED_KEY);diff --git a/src/core/doctor-categories.ts b/src/core/doctor-categories.tsindex dac0490091..e24b1fa8f6 100644--- a/src/core/doctor-categories.ts+++ b/src/core/doctor-categories.ts@@ -104,6 +104,8 @@ export const BRAIN_CHECK_NAMES: ReadonlySet<string> = new Set(['unlabeled_people_folders',// GBRA-231: shared agents (doctor/checks/shared-agent-access.ts).'access_may_act_for_wildcard',+ // GST-2490: the owner opt-in (doctor/checks/owner-reads-restricted.ts).+ 'access_owner_reads_restricted',// GST-1158 F3: attest credentials that read a shared-scope source as the person (doctor/checks/attest-read-access.ts).'attest_read_shared_scope','extractor_facts_expired',diff --git a/src/core/function-search-path.ts b/src/core/function-search-path.tsindex 56501f219c..ad4ba6bab8 100644--- a/src/core/function-search-path.ts+++ b/src/core/function-search-path.ts@@ -24,7 +24,7 @@ export const LEGACY_SEARCH_PATH_SETTINGS = ['search_path=pg_catalog, public', 'sexport const PINNED_FUNCTION_NAMES = ['auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol','gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers',- 'gbrain_access_origin_closed_to_owner', 'gbrain_access_origin_hidden_from_owner', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules',+ 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules','gbrain_access_state_unreadable','gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation','gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals',diff --git a/src/core/ops/sources.ts b/src/core/ops/sources.tsindex c652815cad..5948a8f891 100644--- a/src/core/ops/sources.ts+++ b/src/core/ops/sources.ts@@ -51,7 +51,9 @@ const whoami: Operation = {const { accessView, appliedAccessSummary, credentialAccessView, stdioAccessView } = await import('../access/caller.ts');// GBRA-231: the view this call is answered under (the shared-agent audience when the harness asserted one), so a// model can check it when its harness does not forward _meta.access.- const withApplied = async <T extends object>(view: T) => ({ ...view, applied: await appliedAccessSummary(ctx.engine, ctx.auth, [ctx.sourceId, ...(ctx.localFederatedSourceIds ?? [])]) });+ // GST-2490: and, while the owner opt-in is on, that the owner reads the pages kept to this caller.+ const withApplied = async <T extends object>(view: T) => ({ ...view, applied: await appliedAccessSummary(ctx.engine, ctx.auth, [ctx.sourceId, ...(ctx.localFederatedSourceIds ?? [])]),+ ...await (await import('../access/owner.ts')).ownerReadsRestrictedNotice(ctx.engine) });if (ctx.remote === false) {// GBRA-218: a local --as <member> preview reports the member it reads as; the plain local CLI reads every page.const access = ctx.applyRemoteReadPolicy && ctx.accessIdentity?.length ? accessView(ctx.accessIdentity, 'as')diff --git a/src/core/pglite-schema.generated.ts b/src/core/pglite-schema.generated.tsindex 9ebcea6b20..274744a9b2 100644--- a/src/core/pglite-schema.generated.ts+++ b/src/core/pglite-schema.generated.ts@@ -2962,7 +2962,7 @@ BEGINFOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS pathFROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')AND pg_has_role(current_user, p.proowner, 'USAGE')ORDER BY 1LOOPdiff --git a/src/core/schema-embedded.generated.ts b/src/core/schema-embedded.generated.tsindex 285205d0e9..012e13326c 100644--- a/src/core/schema-embedded.generated.ts+++ b/src/core/schema-embedded.generated.ts@@ -3748,7 +3748,7 @@ BEGINFOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS pathFROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')AND pg_has_role(current_user, p.proowner, 'USAGE')ORDER BY 1LOOPdiff --git a/src/core/schema-migrations/latest.generated.ts b/src/core/schema-migrations/latest.generated.tsindex 22f670b0a8..06933be159 100644--- a/src/core/schema-migrations/latest.generated.ts+++ b/src/core/schema-migrations/latest.generated.ts@@ -4,4 +4,4 @@// The highest schema migration version (migrate.ts LATEST_VERSION), importable without// loading the migrations themselves.-export const LATEST_SCHEMA_VERSION = 303;+export const LATEST_SCHEMA_VERSION = 304;diff --git a/src/core/schema-migrations/registry.generated.ts b/src/core/schema-migrations/registry.generated.tsindex 14f3f13bc7..eb09b0133a 100644--- a/src/core/schema-migrations/registry.generated.ts+++ b/src/core/schema-migrations/registry.generated.ts@@ -304,6 +304,7 @@ import { v300 } from './v300-memory-proposals.ts';import { v301 } from './v301-member-email.ts';import { v302 } from './v302-link-transitions-source.ts';import { v303 } from './v303-access-page-rules.ts';+import { v304 } from './v304-access-owner-origin.ts';// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the// runner sorts by version before applying.@@ -606,4 +607,5 @@ export const MIGRATIONS: Migration[] = [v301,v302,v303,+ v304,];diff --git a/src/core/schema-migrations/v304-access-owner-origin.ts b/src/core/schema-migrations/v304-access-owner-origin.tsindex bdf565d31a..38d83df046 100644--- a/src/core/schema-migrations/v304-access-owner-origin.ts+++ b/src/core/schema-migrations/v304-access-owner-origin.ts@@ -3,54 +3,61 @@ import type { Migration } from './types.ts';// Applied by src/core/migrate.ts on the next initSchema(); see docs/ENGINES.md// ("Canonical schema sources") for when schema.sql or a TS fragment also changes.//-// GST-2490 (G6 of GST-2476): the owner opt-in (config access.owner_reads_restricted). Derived pages (an atom, a-// synthesized concept or question, a Life Chronicle event, a derived_from page) of an origin that names readers or sits-// under a folder or page rule are hidden from every remote caller by gbrain_access_origin_restricted (v282, v283, v285),-// the brain owner included, even when the readers or the rule name the owner. With the opt-in on, an owner read uses-// gbrain_access_origin_hidden_from_owner instead: the same arms, but an origin hides its derivatives only when it is-// another member's own member page (memory/members/<id>, the owner's own excluded) or reads as nobody (pending-// coverage). The per-origin test is one function, gbrain_access_origin_closed_to_owner, so a later rule (say, "a caller-// reads a derivative when it reads every origin") swaps that test and keeps the arms. Nothing is rewritten and-// gbrain_access_origin_restricted is untouched, so every other caller reads exactly as before. No schema.sql mirror:-// like v282, v283 and v285, these exist only through migrations. Provisional number: renumbered at the merge slot.+// GST-2490 (G6 of GST-2476): the brain owner's lineage. A derived page (an atom, a synthesized concept or question, a+// Life Chronicle event, a derived_from page) of an origin that names readers or sits under a folder or page rule is+// hidden from every remote caller by gbrain_access_origin_restricted (v282, v283, v285), the owner included, even when+// the readers or the rule name the owner, so a labelled page's derivatives disappeared from the owner's own keys.+// gbrain_access_origin_hidden_for has the same arms but asks, per origin, whether a caller with p_identity (and the+// folder rules it satisfies, p_satisfied) reads that origin (gbrain_access_origin_closed_for): an owner read passes a+// derivative when it reads every origin. p_open is the owner opt-in (config access.owner_reads_restricted): every+// origin passes except another member's own member page (memory/members/<id>, p_own_page excluded) and pending+// coverage. Only owner reads call these; gbrain_access_origin_restricted is untouched, so every other caller reads+// exactly as before, and letting listed members read derivatives later is a call-site change. Nothing is rewritten.+// No schema.sql mirror: like v282, v283 and v285, these exist only through migrations. Provisional number: renumbered+// at the merge slot.export const v304: Migration = {version: 304,name: 'access_owner_origin',idempotent: true,sql: `-CREATE OR REPLACE FUNCTION gbrain_access_origin_closed_to_owner(o_source TEXT, o_slug TEXT, p_owner_page TEXT) RETURNS boolean+CREATE OR REPLACE FUNCTION gbrain_access_origin_closed_for(o_source TEXT, o_slug TEXT, o_frontmatter JSONB, o_readers TEXT[], o_rules TEXT[],+ p_identity TEXT[], p_satisfied TEXT[], p_open BOOLEAN, p_own_page TEXT) RETURNS booleanLANGUAGE sql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$- SELECT (starts_with(o_slug, 'memory/members/') AND o_slug IS DISTINCT FROM p_owner_page) OR gbrain_access_pending_covers(o_source, o_slug)+ SELECT gbrain_access_pending_covers(o_source, o_slug)+ OR (starts_with(o_slug, 'memory/members/') AND o_slug IS DISTINCT FROM p_own_page AND NOT COALESCE(o_readers && p_identity, false))+ OR (NOT p_open AND NOT (((o_readers IS NULL AND NOT (o_frontmatter ? 'readable_by')) OR COALESCE(o_readers && p_identity, false))+ AND (o_rules IS NULL OR o_rules <@ p_satisfied)))$fn$;-CREATE OR REPLACE FUNCTION gbrain_access_origin_hidden_from_owner(p_id INTEGER, p_source_id TEXT, p_type TEXT, fm JSONB, p_owner_page TEXT) RETURNS boolean+CREATE OR REPLACE FUNCTION gbrain_access_origin_hidden_for(p_id INTEGER, p_source_id TEXT, p_type TEXT, fm JSONB,+ p_identity TEXT[], p_satisfied TEXT[], p_open BOOLEAN, p_own_page TEXT) RETURNS booleanLANGUAGE plpgsql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$BEGINIF p_type = 'atom' THENIF EXISTS (SELECT 1 FROM pages o WHERE o.source_id = p_source_id AND o.slug IN (SELECT fm->>'source_slug' UNION SELECT a.canonical_slug FROM slug_aliases a WHERE a.source_id = p_source_id AND a.alias_slug = fm->>'source_slug'UNION SELECT h.new_slug FROM slug_rename_history h WHERE h.source_id = p_source_id AND h.old_slug = fm->>'source_slug')- AND gbrain_access_origin_closed_to_owner(o.source_id, o.slug, p_owner_page)) THEN+ AND gbrain_access_origin_closed_for(o.source_id, o.slug, o.frontmatter, o.page_readers, o.folder_rule_ids, p_identity, p_satisfied, p_open, p_own_page)) THENRETURN true;END IF;ELSIF p_type = 'question' OR (p_type = 'concept' AND fm->>'synthesized_by' IS NOT NULL) THENIF EXISTS (SELECT 1 FROM links l JOIN pages i ON i.id = l.to_page_idWHERE l.from_page_id = p_id AND l.link_source = 'concept-provenance' AND l.link_type = 'synthesized_from'- AND (gbrain_access_origin_closed_to_owner(i.source_id, i.slug, p_owner_page)+ AND (gbrain_access_origin_closed_for(i.source_id, i.slug, i.frontmatter, i.page_readers, i.folder_rule_ids, p_identity, p_satisfied, p_open, p_own_page)OR EXISTS (SELECT 1 FROM pages io WHERE io.source_id = i.source_idAND io.slug IN (SELECT i.frontmatter->>'source_slug' UNION SELECT a.canonical_slug FROM slug_aliases a WHERE a.source_id = i.source_id AND a.alias_slug = i.frontmatter->>'source_slug'UNION SELECT h.new_slug FROM slug_rename_history h WHERE h.source_id = i.source_id AND h.old_slug = i.frontmatter->>'source_slug')- AND gbrain_access_origin_closed_to_owner(io.source_id, io.slug, p_owner_page)))) THEN+ AND gbrain_access_origin_closed_for(io.source_id, io.slug, io.frontmatter, io.page_readers, io.folder_rule_ids, p_identity, p_satisfied, p_open, p_own_page)))) THENRETURN true;END IF;ELSIF p_type = 'event' AND fm->>'captured_via' LIKE 'life-chronicle:%' THENIF EXISTS (SELECT 1 FROM pages c WHERE c.source_id = p_source_id AND c.slug IN (SELECT fm->'event'->>'depth' UNION SELECT a.canonical_slug FROM slug_aliases a WHERE a.source_id = p_source_id AND a.alias_slug = fm->'event'->>'depth'UNION SELECT h.new_slug FROM slug_rename_history h WHERE h.source_id = p_source_id AND h.old_slug = fm->'event'->>'depth')- AND gbrain_access_origin_closed_to_owner(c.source_id, c.slug, p_owner_page)) THEN+ AND gbrain_access_origin_closed_for(c.source_id, c.slug, c.frontmatter, c.page_readers, c.folder_rule_ids, p_identity, p_satisfied, p_open, p_own_page)) THENRETURN true;END IF;END IF;IF jsonb_typeof(fm->'derived_from') IN ('array', 'string') THENRETURN EXISTS (SELECT 1 FROM pages d WHERE d.source_id = p_source_id- AND gbrain_access_origin_closed_to_owner(d.source_id, d.slug, p_owner_page)+ AND gbrain_access_origin_closed_for(d.source_id, d.slug, d.frontmatter, d.page_readers, d.folder_rule_ids, p_identity, p_satisfied, p_open, p_own_page)AND d.slug = ANY(ARRAY(WITH declared(slug) AS (SELECT regexp_replace(x, '\\.md$', '') FROM jsonb_array_elements_text(CASE WHEN jsonb_typeof(fm->'derived_from') = 'array' THEN fm->'derived_from' ELSE jsonb_build_array(fm->'derived_from') END) AS x)SELECT slug FROM declared UNION SELECT a.canonical_slug FROM slug_aliases a JOIN declared ON a.alias_slug = declared.slug WHERE a.source_id = p_source_iddiff --git a/src/core/search/mode.ts b/src/core/search/mode.tsindex d66c711125..2a61a50ae5 100644--- a/src/core/search/mode.ts+++ b/src/core/search/mode.ts@@ -1322,7 +1322,7 @@ export function knobsHash(if (access.identity.length) parts.push(`xid=${createHash('sha256').update(access.identity.join(',')).digest('hex').slice(0, 16)}`);if (access.audienceIdentities.length) parts.push(`xau=${createHash('sha256').update(JSON.stringify(access.audienceIdentities)).digest('hex').slice(0, 16)}`);if (!access.hidePrivate) parts.push('xhp=0');- if (access.ownerReadsRestricted) parts.push('xor=1');+ if (access.ownerLineage) parts.push(access.ownerReadsRestricted ? 'xol=2' : 'xol=1');}const h = createHash('sha256');h.update(parts.join('|'));diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.tsindex f4ae8b3154..a61c2a2390 100644--- a/src/core/search/private-visibility.ts+++ b/src/core/search/private-visibility.ts@@ -178,40 +178,52 @@ function originAllowedSql(p: string): string {OR NOT gbrain_access_origin_restricted(${p}.id, ${p}.source_id, ${p}.type, ${p}.frontmatter))`;}-/** GST-2490: the owner's own member page, when the current record is an owner read under the opt-in (else null). */-function ownerOptInPage(access: CallerAccess): string | null {- if (!access.ownerReadsRestricted) return null;+/** GST-2490: the owner's own member page for an owner read (CallerAccess.ownerLineage), else null. */+function ownerReadPage(access: CallerAccess): string | null {+ if (!access.ownerLineage) return null;const member = access.identity.find(p => p.startsWith('member:'))?.slice('member:'.length);return member && ACCESS_ID_RE.test(member) ? `${MEMBER_PAGE_PREFIX}${member}` : null;}+/** GST-2490: the owner's own member page for an owner read under the opt-in (access.owner_reads_restricted), else null. */+function ownerOptInPage(access: CallerAccess): string | null {+ return access.ownerReadsRestricted ? ownerReadPage(access) : null;+}+/** GST-2490: `alias` is not another member's own member page (the owner's own one passes). */function notOtherMemberPageSql(alias: string, ownPage: string): string {return `(NOT starts_with(${alias}.slug, '${MEMBER_PAGE_PREFIX}') OR ${alias}.slug = '${ownPage}')`;}+const textArraySql = (values: readonly string[]): string => values.length ? `ARRAY[${values.map(v => `'${v}'`).join(', ')}]::text[]` : 'ARRAY[]::text[]';+/**- * GST-2490: originAllowedSql for an owner read under the opt-in. A derived page is hidden only when an origin is another- * member's own member page or reads as nobody (pending coverage), through gbrain_access_origin_hidden_from_owner, the- * owner twin of gbrain_access_origin_restricted with the same arms.+ * GST-2490: originAllowedSql for an owner read. A derived page passes when the owner reads every origin of it+ * (gbrain_access_origin_hidden_for with the owner's identity and satisfied rules, v304), so a page whose readers or rule+ * name the owner keeps its derivatives for the owner; under the opt-in every origin passes except another member's own+ * member page and pending coverage. The identity and rule ids are validated on the record, so they embed as literals.*/-function ownerOriginAllowedSql(p: string, ownPage: string): string {+function ownerOriginAllowedSql(p: string, access: CallerAccess, ownPage: string): string {+ const identity = validIdentity(access.identity) ? access.identity : [];+ const satisfied = access.satisfiedRuleIds.every(validQualifiedRuleId) ? access.satisfiedRuleIds : [];return `((${p}.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (${p}.frontmatter ? 'derived_from'))- OR NOT gbrain_access_origin_hidden_from_owner(${p}.id, ${p}.source_id, ${p}.type, ${p}.frontmatter, '${ownPage}'))`;+ OR NOT gbrain_access_origin_hidden_for(${p}.id, ${p}.source_id, ${p}.type, ${p}.frontmatter, ${textArraySql(identity)}, ${textArraySql(satisfied)}, ${access.ownerReadsRestricted}, '${ownPage}'))`;}/**- * GST-2490: the member-access part for an owner read under the opt-in: what the owner's own identity reads, or any page- * that is not another member's own member page, outside a prefix that reads as nobody, whose origins pass- * ownerOriginAllowedSql. Readers lists, folder rules and page rules no longer close a page to the owner.+ * GST-2490: the member-access part for an owner read: the owner's readers and folder rules as for any member, with the+ * owner's lineage (ownerOriginAllowedSql) instead of the every-caller one. Under the opt-in, a page that is not another+ * member's own member page passes too, outside a prefix that reads as nobody.*/-function ownerAccessSql(pageAlias: string, access: CallerAccess): string {- const ownPage = ownerOptInPage(access);- const own = accessAllowedSql(pageAlias, access.identity);- if (!ownPage) return own;+function ownerAccessSql(pageAlias: string, access: CallerAccess, ownPage: string): string {const notOther = notOtherMemberPageSql(pageAlias, ownPage);- if (!access.restricted) return `(${own} OR ${notOther})`;- return `(${own} OR (${notOther}${coverageSql(pageAlias)} AND ${ownerOriginAllowedSql(pageAlias, ownPage)}))`;+ if (!access.restricted) {+ const unrestricted = `(${pageAlias}.page_readers IS NULL AND ${pageAlias}.folder_rule_ids IS NULL)`;+ return access.ownerReadsRestricted ? `(${unrestricted} OR ${notOther})` : unrestricted;+ }+ const listed = `(${readersAllowedSql(pageAlias, access.identity)} AND ${folderRulesAllowedSql(pageAlias, access.satisfiedRuleIds)})`;+ const page = access.ownerReadsRestricted ? `(${listed} OR (${notOther}${coverageSql(pageAlias)}))` : listed;+ return `(${page} AND ${ownerOriginAllowedSql(pageAlias, access, ownPage)})`;}/**@@ -286,6 +298,11 @@ export interface CallerAccess {privateReadableSources: readonly string[];hidePrivate: boolean;owner: boolean;+ /**+ * GST-2490: an owner read (owner true, a non-mutating operation): derived pages and facts pass when the owner reads+ * every origin (ownerOriginAllowedSql) instead of being hidden from every remote caller.+ */+ ownerLineage: boolean;/*** GST-2490: an owner read (owner true, a non-mutating operation) on a brain whose operator turned on* access.owner_reads_restricted: readers lists, folder rules and page rules stop closing pages, their derivatives and@@ -302,7 +319,7 @@ const callerAccessStore = new AsyncLocalStorage<CallerAccess>();/** The current read's caller-access record (see CallerAccess). */export function currentCallerAccess(): CallerAccess {- return callerAccessStore.getStore() ?? { identity: [], audience: null, audienceIdentities: [], actor: null, satisfiedRuleIds: [], folderCoverage: [], privateReadableSources: [], hidePrivate: !processPrivacyRelaxed(), owner: false, ownerReadsRestricted: false, applyRemoteReadPolicy: false, restricted: true, remotePolicy: null };+ return callerAccessStore.getStore() ?? { identity: [], audience: null, audienceIdentities: [], actor: null, satisfiedRuleIds: [], folderCoverage: [], privateReadableSources: [], hidePrivate: !processPrivacyRelaxed(), owner: false, ownerLineage: false, ownerReadsRestricted: false, applyRemoteReadPolicy: false, restricted: true, remotePolicy: null };}/** Runs `fn` under `access` merged over the current record; an invalid identity or source id empties that set (fail closed). */@@ -328,14 +345,20 @@ export function withCallerAccess<T>(access: Partial<CallerAccess>, fn: () => T):privateReadableSources: sources.length && sources.every(isValidSourceId) ? Object.freeze([...new Set(sources)]) : Object.freeze([]),hidePrivate: access.hidePrivate ?? (fresh ? true : base.hidePrivate),owner: access.owner ?? (fresh ? false : base.owner),- ownerReadsRestricted: (access.owner ?? (fresh ? false : base.owner)) && audienceIdentities.length <= 1- && (access.ownerReadsRestricted ?? (fresh ? false : base.ownerReadsRestricted)),+ ...ownerReads(access.owner ?? (fresh ? false : base.owner), audienceIdentities.length <= 1,+ access.ownerLineage ?? (fresh ? false : base.ownerLineage), access.ownerReadsRestricted ?? (fresh ? false : base.ownerReadsRestricted)),applyRemoteReadPolicy: access.applyRemoteReadPolicy ?? base.applyRemoteReadPolicy,restricted: access.restricted ?? base.restricted,remotePolicy: access.remotePolicy ?? base.remotePolicy,}), fn);}+/** GST-2490: the owner-read flags of a record; both need the owner speaking for itself, and the opt-in needs an owner read. */+function ownerReads(owner: boolean, single: boolean, lineage: boolean, readsRestricted: boolean): Pick<CallerAccess, 'ownerLineage' | 'ownerReadsRestricted'> {+ const ownerLineage = owner && single && lineage;+ return { ownerLineage, ownerReadsRestricted: ownerLineage && readsRestricted };+}+/** Runs `fn` outside any caller's record, for work a request spawns that must not inherit its view. */export function withoutCallerAccess<T>(fn: () => T): T {return callerAccessStore.exit(fn);@@ -397,7 +420,8 @@ function validAudienceEntry(entry: string): boolean {function callerAccessSql(pageAlias: string): string {const access = currentCallerAccess();- if (access.ownerReadsRestricted) return ownerAccessSql(pageAlias, access);+ const ownPage = ownerReadPage(access);+ if (ownPage) return ownerAccessSql(pageAlias, access, ownPage);return access.audienceIdentities.length ? accessAllowedForAllSql(pageAlias, access.audienceIdentities, access.satisfiedRuleIds): accessAllowedSql(pageAlias, access.identity);}@@ -743,9 +767,9 @@ export function privateProvenanceFilterUnderPolicy(factAlias: string): string {const access = currentCallerAccess();const hide = !callerRelaxesPrivacy();const member = access.actor?.member ?? (access.audienceIdentities.length ? null : access.identity.find(p => p.startsWith('member:'))?.slice('member:'.length));- const ownPage = ownerOptInPage(access);+ const ownPage = ownerReadPage(access);const otherwise = ownPage- ? `CASE WHEN starts_with(pp.slug, '${MEMBER_PAGE_PREFIX}') THEN ${readPolicyFragment('pp', [], hide)} ELSE (TRUE${coverageSql('pp')} AND ${ownerOriginAllowedSql('pp', ownPage)} AND ${hide ? privacyPartSql('pp') : 'TRUE'}) END`+ ? `CASE WHEN starts_with(pp.slug, '${MEMBER_PAGE_PREFIX}') THEN ${readPolicyFragment('pp', [], hide)} ELSE (${ownerAccessSql('pp', access, ownPage)} AND ${hide ? privacyPartSql('pp') : 'TRUE'}) END`: readPolicyFragment('pp', [], hide);const policy = member && ACCESS_ID_RE.test(member)? `CASE WHEN pp.slug = '${MEMBER_PAGE_PREFIX}${member}' THEN ${readPolicyFragment('pp', access.identity, hide, access.satisfiedRuleIds)} ELSE ${otherwise} END`diff --git a/src/schema.sql b/src/schema.sqlindex 4970912bf2..51817337e2 100644--- a/src/schema.sql+++ b/src/schema.sql@@ -3744,7 +3744,7 @@ BEGINFOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS pathFROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')AND pg_has_role(current_user, p.proowner, 'USAGE')ORDER BY 1LOOP