Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Access: raw-only folder rules, audience members, and member lineage reads

garrytan732e3fdce861
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8176f068ec..28fdb01deb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,23 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**Three opt-in ways to share what is derived from member-restricted pages: raw-only folder rules, audience members the owner reads, and member lineage reads.** A folder rule kept the summaries, atoms, chronicle events and facts made from its pages as tightly as the pages themselves, so a transcript folder kept to one member hid every summary of those calls from everyone else; a group chat's own memory page was closed to the brain owner; and only the owner could read the derived pages and facts of pages it already reads. Each now has an operator setting, off by default, and nothing changes on upgrade: `gbrain access rule add --raw-only` keeps a folder's pages to its readers but lets whoever reads a derived page read it (use it for transcripts, never for a folder whose content is itself the secret); `gbrain access member kind <id> audience` lets the owner read that member's own member page, versions, derived pages and facts; and `gbrain access members-read-lineage on` lets every member read the derived pages and facts of pages it reads, as the owner does. All three work the same on a repo-less brain and with rules in `access.yml`, only the operator on the brain host sets them, and no write widens.
+
+### Itemized changes
+
+#### Access lineage designs (GBRA-108 designs 2, 3 and 4)
+
+- Migration v305 (`src/core/schema-migrations/v305-access-lineage-designs.ts`): `access_rules.covers_derived` (default true), `access_members.kind` (`person` | `audience`, default `person`), the SQL function `gbrain_access_lineage_rules()`, and new versions of `gbrain_access_origin_restricted()`, `gbrain_access_origin_closed_for()` (10 arguments) and `gbrain_access_origin_hidden_for()` (9 arguments); the v304 signatures stay as wrappers. Nothing is rewritten, and every existing rule keeps its digest.
+- Raw-only rules: `src/core/access/folder-rules.ts` (`covers_derived: false` in `access.yml`, the held widening `derived_released` and the narrowing `derived_covered`), `src/core/access/policy.ts` (stored, compared and previewed with `lineage` in `gbrain access apply`), `src/commands/access-rules.ts` (`rule add --raw-only`).
+- Audience members: `src/core/access/members.ts` (`setMemberKind`, `member add --kind`, refused for remote callers with `permission_denied`), `src/core/search/private-visibility.ts` (the owner's read of an audience member page, its versions, derived pages and facts), `gbrain access member kind <id> person|audience`; `member list` shows the kind.
+- Member lineage: config `access.members_read_lineage` (`src/core/access/lineage.ts`, `gbrain access members-read-lineage [on|off]`, refused for remote callers); `src/core/access/caller.ts` and `src/cli/as-preview.ts` give it to a member speaking for itself, never to an audience of several, an unbound credential or a `granted_sources` grant; `whoami` adds `members_read_lineage` while it is on.
+- The semantic cache key (`src/core/search/mode.ts`) and the per-caller key (`src/core/access/member-facts.ts`) carry the member lineage and the owner's audience members.
+- `gbrain access check` and `who-can-read` explain all three; doctor `access_raw_only_rules`, `access_audience_members` and `access_members_read_lineage` (`src/commands/doctor/checks/access-lineage.ts`).
+- Docs: `docs/guides/access-designations.md` (raw-only rules, audience members, members read lineage), key-files entry.
+- Tests: `test/access-raw-only-rules.test.ts`, `test/access-audience-members.test.ts`, `test/access-members-read-lineage.test.ts` (every read path for every caller, off and on, the held widening, remote refusals, cache keys and the write gate; PGLite and Postgres, rules in the database and in `access.yml`); shared fixture `test/helpers/access-lineage-fixture.ts`; migration, catalog and doctor goldens.
+
## [0.60.682.0] - 2026-11-11
**The brain owner reads the derived pages and facts of pages it can already read, and the operator can let the owner read pages kept to other members.** An atom, a synthesized concept, a Life Chronicle event, a page with `derived_from` or a fact made from a page under a folder rule, or from a page that names readers, was hidden from every remote caller, the owner included, even when the rule or the readers named the owner. Credentials bound to the owner now read them whenever they read every origin, with no setting. A new opt-in, `gbrain access owner reads-restricted on`, off by default and settable only by the operator on the brain host, lets the owner also read pages that readers lists, folder rules and page rules keep to other members, with their derived pages and facts, but never another member's own member page. Nothing changes for any other caller or for writes, and nothing changes on upgrade.
diff --git a/docs/architecture/key-files/access.md b/docs/architecture/key-files/access.md
index 58a7e9a960..b055222efb 100644
--- a/docs/architecture/key-files/access.md
+++ b/docs/architecture/key-files/access.md
@@ -3,7 +3,7 @@
[Subsystem index](../KEY_FILES.md). Read only the entries relevant to your change.
Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.
-- `src/core/access/` (GBRA-218) — per-member read access inside one source. `principals.ts` normalizes frontmatter `readable_by` (bare id = `member:<id>`, `group:<g>`, ASCII case fold, space trim; anything malformed is `['!nobody']`); it is the row twin of the SQL `gbrain_access_readers()` (`test/access-principals.test.ts` holds them equal). A BEFORE trigger keeps `pages.page_readers` equal to that function (direct writes to the column are recomputed), and predicates test the array, never the function, which costs ~0.2 ms per row. A page that names readers with no derived value yet (written before the migration) reads as nobody until `gbrain repair access` (`repair/access.ts`). `members.ts` (members, groups, tombstoned ids never reused, bindings), `token-binding.ts` (the verifiers' join; a credential bound to a disabled, tombstoned or missing member is refused with `access_member_disabled`) and `caller.ts` (`remoteCallerAccess`: the identity dispatch puts on the caller-access record; stdio binds through `serve --stdio-member`, else `mcp.stdio_member`; publication re-resolves from the stored principal). In `search/private-visibility.ts` every page fragment is `accessAllowedSql` AND the privacy part: plain fragments use the empty identity (over-hide, never leak), `*ForCaller` fragments the caller's, and `GBRAIN_REMOTE_PRIVATE_PAGES`, `search.remote_private_pages` and `granted_sources` relax only the privacy part (`privacyForCaller`). GST-2490: an owner read (`CallerAccess.ownerLineage`, read-only ops only) uses `ownerAccessSql`: the owner's readers and folder rules as for any member, with `gbrain_access_origin_hidden_for()` (v304; per origin `gbrain_access_origin_closed_for()`) in place of the every-caller lineage, so a derivative or fact passes when the owner reads every origin; `ownerReadsRestricted` (config `access.owner_reads_restricted`, `owner.ts` `setOwnerReadsRestricted`, local only) also passes pages kept to other members except another member's own member page and pending coverage. `access check`, `who-can-read`, `whoami` (`ownerReadsRestrictedNotice`) and doctor `access_owner_reads_restricted` report it; test `test/owner-reads-restricted.test.ts` (both engines, database and access.yml rules). A derivative of a page that names readers is otherwise hidden from every remote caller (`originAllowedSql`, which calls the SQL function `gbrain_access_origin_restricted()` only for atom, question, concept, event or `derived_from` rows, so each read plans one call instead of four subplans). Both parts lead with column tests (`page_readers IS NULL`, `type`) so row estimates follow column statistics; an expression test such as `->'readable_by' IS NULL` estimates almost no rows and sent restricted vector searches into nested-loop sequential scans. The index walk's page probe (`INDEX_WALK_PAGE_COLUMNS`) projects `page_readers`. Config `access.restrictions_present` (set by a trigger, sticky) keeps every pre-A1 path on a brain with no restriction. `check:remote-privacy-reads` keeps the two relaxations read only in `private-visibility.ts`. Tests: `test/member-read-access.test.ts` (remote matrix, both engines), `test/access-*.test.ts`. Folder rules (A2) keep whole folders of a source to named members. `folder-rules.ts` is the grammar (`.gbrain/access.yml`: `rules:` of `id`, `prefix`, `readable_by`), `classifyRulebook` (each change is narrowing or widening; the target installs only the narrowing part) and `matchingRuleIds`. `policy.ts` owns the one applied rulebook for both stores: `access_rules` (source-qualified ids), the append-only `access_policy_revisions` log, `access_pending_coverage` (prefixes that read as nobody while a narrowing restamps, or while a committed file is invalid) and `sources.config.access_store`, persisted at the first rule and changed only by `policy-migrate.ts` (journaled in `access_policy_migrations`). `proposeRevision` installs narrowing at once under a per-source row lock and holds widening for `applyApproved` (`plan_hash`, `preview_changed`); `restampSource` rewrites `pages.folder_rule_ids` in id windows, then clears pending coverage under the lock; re-proposing the same rulebook finishes an interrupted restamp. A trigger stamps `folder_rule_ids` from the SQL function `gbrain_access_folder_rules()` on insert and on slug or source change, never from git on the serve path. `policy-git.ts` is the git store (files committed through the commit door, applied by `syncAccessPolicyAt` from sync preflight and before and after every managed pass (`performManagedSync`: sync, drain, `sources refresh`, git conversion), read with `git show` at the synced commit (GST-2331: every read under `HARDENED_GIT_ARGS` and `NO_LAZY_FETCH_ENV`, so a partial clone fetches nothing; a policy file the commit names that the clone lacks, or a history the replay cannot read, makes the source read as nobody until the objects are fetched: the problem names the exact `git cat-file -p` or `git log --first-parent -p` that fetches them, and the next sync applies the rules and clears the mark); a database with no revision yet replays each committed `access.yml` since the `access.approved` baseline, so a rebuild holds a removal a plain commit made); `policy-transfer.ts` carries the applied rulebook through `gbrain export` and installs it before any page in `gbrain import`; `policy-notice.ts` is the `access_policy_pending` degraded notice. In `private-visibility.ts`, `folderRulesAllowedSql` sits inside `accessAllowedSql` (`folder_rule_ids IS NULL OR folder_rule_ids <@ <satisfied ids>` plus coverage conjuncts), so no hatch, grant or `--as` relaxes it, and the unrestricted short form tests `folder_rule_ids IS NULL` next to `page_readers IS NULL` (v283 triggers set `access.restrictions_present` on the first rule or pending prefix); `caller.ts`'s `folderAccessFor` fails closed to whole-source coverage. CLI: `src/commands/access-rules.ts`; doctor: `src/commands/doctor/checks/folder-access.ts`. Tests: `test/access-folder-rules.test.ts` (database store, both engines), `test/access-folder-rules-git.test.ts`, `test/access-folder-transfer.test.ts`, `test/access-folder-doctor.test.ts`. Shared agents (B, GBRA-231): `audience.ts` parses the audience a harness asserts (`X-Gbrain-On-Behalf-Of` or request-level `_meta.on_behalf_of`, 1-50 principals, `guest` = the empty identity; the same key inside tool arguments is refused) and appends each assertion to `access-audience-YYYY-Www.jsonl`. Dispatch resolves it on every remote call through `caller.ts` (`resolveAudienceIdentities`: every entry must be in the credential's live `may_act_for`, then name an enabled member or existing group); the caller-access record then carries `audienceIdentities`, and `accessAllowedForAllSql` needs one readers conjunct per identity, folder rules the intersection of each entry's satisfied set (`folderAccessForAll`). Privacy relaxes only for a one-member audience. Writes carry the audience as `WriteAuthority.actingFor` (re-resolved at publication) and agent jobs as `grant.actingFor`. Every remote response carries `_meta.access` (`appliedAccessSummary`), which `whoami` returns as `access.applied`; doctor `access_may_act_for_wildcard` (`checks/shared-agent-access.ts`) warns on `*`. Tests: `test/access-on-behalf-of.test.ts` (both engines), `test/e2e/serve-http-on-behalf-of.test.ts`. Attested actor (C1, GST-359): `actor-model.ts` (dependency-free: `x-qm-actor`, `acting_user`, `EXTERNAL_ID_RE` = 1-256 visible ASCII, `attestRightFrom`: the right counts only for a member-less credential whose token is legacy or `client_credentials`, read from `oauth_tokens.grant_type`) and `actor.ts`. `resolveAttestedActor` runs in dispatch before any work: an invalid id refuses `actor_not_attested` (`invalid_actor_id`) before any lookup, then the right, the op list (`attest_ops`, default `get_write_request,memory_recall,memory_write`), `acting_user` = header (stripped), and `actorCoverage` (the one coverage test: live right plus a live link in `access_member_links` to an enabled member, compared exactly) or `actor_unlinked`. GST-1158: `scope-read.ts` holds `SCOPE_READ_ACCESS` (no identity, actor or audience; privacy never relaxed) and `SCOPE_READ_OPS`; dispatch runs an attested call to one of those ops that names `source_id`/`source_ids` under that record (`attestedReadMode`, which refuses `__all__`/`all_sources`), or as the person when the right's `attest_read` (v298, `--attest-read`) is `person`, and handlers read the mode with `currentReadMode`. `attest_read = 'scope'` refuses a call that names no actor (`actor_required`). Tests: `test/qm-scope-read.test.ts` (both engines), `test/doctor-attest-read-shared-scope.test.ts`. GBRA-284: `member-sources.ts` binds a source to its member (`access_member_sources`, v299; `gbrain access member source add|remove|list`); `attestedReadScope`, called in dispatch for every attested call and in `minions/tools/brain-allowlist.ts` for an attested job's tool calls, replaces the call's read grant with the grant minus personal sources bound to another member (every personal source under a scope read), so every resolver refuses or skips them like out-of-grant sources and nothing is added. Test: `test/qm-personal-sources.test.ts` (both engines). `ACTOR_DEFERRED_OPS` (`capture`, `extract_facts`, take writes, `list_write_conflicts`, and since GST-2249 W1 every page write; `test/qm-attest-write-boundary.test.ts` classifies every attestable mutating operation) are never attestable: refused by `parseAttestOps`, `bindCredential`, every call and the stored re-check, which also re-checks `attest_ops` for a queued write's operation and each job tool call. Under the header serve-http lists only attested tools and refuses `resources/read`. `attestedCallerAccess` is a one-member audience with privacy never relaxed (no granted sources, no hatch), never B's `may_act_for` path. Writes store `WriteAuthority.actingFor = {system, external_id, member}` and jobs `grant.actor`; `storedActorIdentity` re-resolves both through `actorCoverage` and refuses when the member changed. `linkMember` / `unlinkMember` / `listMemberLinks` back `gbrain access member link|unlink|links`; `linkMemberByEmail` (GST-1158) finds the member by its declared email (`members.ts` `memberByEmail`: `access_members.email`, migration v301, case-folded, unique, cleared on removal; `not_found` when none, `email_ambiguous` when several) and then links exactly as `linkMember`, from the local CLI and the owner-session routes in `src/commands/serve-http-access.ts` only; `--attest-actor` / `--attest-ops` on `auth rescope` (`members.ts`) only for a member-less legacy token or confidential client-credentials client. Migration v286. Tests: `test/access-qm-actor.test.ts` (both engines), `test/e2e/serve-http-qm-actor.test.ts`. Member facts (C2, GST-359): `member-facts.ts`. A remote `remember` from an attested actor or a lone-member credential (`callerMember`, never an audience of several) writes to `memory/members/<member>` (`memberFactPage`; `persistence/memory-prepare.ts` creates the page with `readable_by: [member:<id>]`), `visibility: private`, `infer_entity` off, the entity kept as `entity_slug`, unless the call passes `share: true` (GST-2243), which takes the ordinary world route to the subject's page; a member's explicit `visibility: "world"` is refused in `remember`'s validation (`member_share_required`), so a batch with one such item saves nothing. A member id whose page slug `slugifyPath` would change (`a--b`, `zed-`) is refused (`invalid_params`). The page must name that member alone (`memberPageIsOwn`, checked at submission and again in preparation, `memberPageNotOwned`), and remote writes under `memory/members/` go only to the caller's own page (`assertMemberPageWriter`, called from `ops/context.ts` `enforceClientSlugFence`, so every remote page write passes it; trusted local callers are unaffected). Reads widen a world-only fact list only by `memberFactAdmitSql` (a private fact on the caller's own live member page whose readers and folder rules admit the caller; `factVisibilitySql` in `engine-sql/facts.ts` and `search/fact-relevance.ts`), and `privateProvenanceFilterUnderPolicy` judges a member-page fact's source page as the caller (every other fact keeps the empty identity, so a fact from a page that names readers stays hidden from every remote caller). Writers never cross pages: `facts/single-prepare.ts` (`SingleFactIntent.page_slug`) and `trust/supersede-handlers.ts` dedup, supersede and contest only within the member page, and no other write matches a fact there (`onMemberPageSql`); consolidation skips facts whose page names readers (`readersSourcedFactSql`). Per-person keys: `callerIdentityKey` joins the hot-memory cache key (`facts/meta-hook.ts`, `::xid=`), `callerSessionKey` the `delta` cursor (`ops/facts.ts`), `sameAttestedActor` gates receipts (`persistence/authority.ts` `ownRequestAccessible`) and replays (`persistence/journal.ts`) on the stored actor, else the stored audience, and `get_agent_job` and the owner-fenced `get_job`, `wait_job`, `get_job_progress`, `list_jobs` and `cancel_job` match the job's `grant.actor` (system, external id, member) and `grant.actingFor` (the same distinct audience entries; `jobActorSql` in `minions/types.ts`), so a job or receipt with an actor or audience reads as missing to the bare client and to other actors and audiences, and one with neither to every actor and audience. Tests: `test/access-member-facts.test.ts` (both engines), `test/access-member-sweep.test.ts` (every attestable op as Bob, the bare client and an unbound credential; `test/helpers/member-sweep.ts`), `test/e2e/serve-http-member-sweep.test.ts` (two members over a real `serve --http` on a keyless repo-less brain).
+- `src/core/access/` (GBRA-218) — per-member read access inside one source. `principals.ts` normalizes frontmatter `readable_by` (bare id = `member:<id>`, `group:<g>`, ASCII case fold, space trim; anything malformed is `['!nobody']`); it is the row twin of the SQL `gbrain_access_readers()` (`test/access-principals.test.ts` holds them equal). A BEFORE trigger keeps `pages.page_readers` equal to that function (direct writes to the column are recomputed), and predicates test the array, never the function, which costs ~0.2 ms per row. A page that names readers with no derived value yet (written before the migration) reads as nobody until `gbrain repair access` (`repair/access.ts`). `members.ts` (members, groups, tombstoned ids never reused, bindings), `token-binding.ts` (the verifiers' join; a credential bound to a disabled, tombstoned or missing member is refused with `access_member_disabled`) and `caller.ts` (`remoteCallerAccess`: the identity dispatch puts on the caller-access record; stdio binds through `serve --stdio-member`, else `mcp.stdio_member`; publication re-resolves from the stored principal). In `search/private-visibility.ts` every page fragment is `accessAllowedSql` AND the privacy part: plain fragments use the empty identity (over-hide, never leak), `*ForCaller` fragments the caller's, and `GBRAIN_REMOTE_PRIVATE_PAGES`, `search.remote_private_pages` and `granted_sources` relax only the privacy part (`privacyForCaller`). GST-2490: an owner read (`CallerAccess.lineage` with `owner`, read-only ops only) uses `lineageAccessSql`: the owner's readers and folder rules as for any member, with `gbrain_access_origin_hidden_for()` (v304; per origin `gbrain_access_origin_closed_for()`) in place of the every-caller lineage, so a derivative or fact passes when the owner reads every origin; `ownerReadsRestricted` (config `access.owner_reads_restricted`, `owner.ts` `setOwnerReadsRestricted`, local only) also passes pages kept to other members except another member's own member page and pending coverage. `access check`, `who-can-read`, `whoami` (`ownerReadsRestrictedNotice`) and doctor `access_owner_reads_restricted` report it; test `test/owner-reads-restricted.test.ts` (both engines, database and access.yml rules). GBRA-108 (migration v305, `v305-access-lineage-designs.ts`): `access_rules.covers_derived` (default true) — a raw-only rule (`folder-rules.ts` `covers_derived: false`, `rule add --raw-only`; digest unchanged for covering rules; true→false is the held widening `derived_released`, false→true the narrowing `derived_covered`) is dropped from an origin's rule set by the SQL function `gbrain_access_lineage_rules()` inside `gbrain_access_origin_restricted()` and the 10-argument `gbrain_access_origin_closed_for()`, so it keeps its pages but not their lineage (a page's own readers still close it; fact provenance filters judge with `derived = true`). `access_members.kind` (`person` | `audience`, `members.ts` `setMemberKind`, local only): an owner read carries `CallerAccess.audienceKindMembers`, whose member pages pass the readers test and the member-page exemptions (`audiencePages`, `notOtherMemberPageSql`, the `p_audience_pages` argument of the 9-argument `gbrain_access_origin_hidden_for()`). Config `access.members_read_lineage` (`lineage.ts`, local only) sets `CallerAccess.lineage` for any member read speaking for itself (`caller.ts`; never an audience of several or an unbound credential; `withCallerAccess` drops it for several identities and keeps the owner opt-in and audience members owner-only). Cache keys: `knobsHash` `xol=3` and `xak=`, `callerIdentityKey` `owner_reads`/`audience_kind`. Doctor `access_lineage` (`checks/access-lineage.ts`). Tests: `test/access-raw-only-rules.test.ts`, `test/access-audience-members.test.ts`, `test/access-members-read-lineage.test.ts` (both engines, both stores; fixture `test/helpers/access-lineage-fixture.ts`). A derivative of a page that names readers is otherwise hidden from every remote caller (`originAllowedSql`, which calls the SQL function `gbrain_access_origin_restricted()` only for atom, question, concept, event or `derived_from` rows, so each read plans one call instead of four subplans). Both parts lead with column tests (`page_readers IS NULL`, `type`) so row estimates follow column statistics; an expression test such as `->'readable_by' IS NULL` estimates almost no rows and sent restricted vector searches into nested-loop sequential scans. The index walk's page probe (`INDEX_WALK_PAGE_COLUMNS`) projects `page_readers`. Config `access.restrictions_present` (set by a trigger, sticky) keeps every pre-A1 path on a brain with no restriction. `check:remote-privacy-reads` keeps the two relaxations read only in `private-visibility.ts`. Tests: `test/member-read-access.test.ts` (remote matrix, both engines), `test/access-*.test.ts`. Folder rules (A2) keep whole folders of a source to named members. `folder-rules.ts` is the grammar (`.gbrain/access.yml`: `rules:` of `id`, `prefix`, `readable_by`), `classifyRulebook` (each change is narrowing or widening; the target installs only the narrowing part) and `matchingRuleIds`. `policy.ts` owns the one applied rulebook for both stores: `access_rules` (source-qualified ids), the append-only `access_policy_revisions` log, `access_pending_coverage` (prefixes that read as nobody while a narrowing restamps, or while a committed file is invalid) and `sources.config.access_store`, persisted at the first rule and changed only by `policy-migrate.ts` (journaled in `access_policy_migrations`). `proposeRevision` installs narrowing at once under a per-source row lock and holds widening for `applyApproved` (`plan_hash`, `preview_changed`); `restampSource` rewrites `pages.folder_rule_ids` in id windows, then clears pending coverage under the lock; re-proposing the same rulebook finishes an interrupted restamp. A trigger stamps `folder_rule_ids` from the SQL function `gbrain_access_folder_rules()` on insert and on slug or source change, never from git on the serve path. `policy-git.ts` is the git store (files committed through the commit door, applied by `syncAccessPolicyAt` from sync preflight and before and after every managed pass (`performManagedSync`: sync, drain, `sources refresh`, git conversion), read with `git show` at the synced commit (GST-2331: every read under `HARDENED_GIT_ARGS` and `NO_LAZY_FETCH_ENV`, so a partial clone fetches nothing; a policy file the commit names that the clone lacks, or a history the replay cannot read, makes the source read as nobody until the objects are fetched: the problem names the exact `git cat-file -p` or `git log --first-parent -p` that fetches them, and the next sync applies the rules and clears the mark); a database with no revision yet replays each committed `access.yml` since the `access.approved` baseline, so a rebuild holds a removal a plain commit made); `policy-transfer.ts` carries the applied rulebook through `gbrain export` and installs it before any page in `gbrain import`; `policy-notice.ts` is the `access_policy_pending` degraded notice. In `private-visibility.ts`, `folderRulesAllowedSql` sits inside `accessAllowedSql` (`folder_rule_ids IS NULL OR folder_rule_ids <@ <satisfied ids>` plus coverage conjuncts), so no hatch, grant or `--as` relaxes it, and the unrestricted short form tests `folder_rule_ids IS NULL` next to `page_readers IS NULL` (v283 triggers set `access.restrictions_present` on the first rule or pending prefix); `caller.ts`'s `folderAccessFor` fails closed to whole-source coverage. CLI: `src/commands/access-rules.ts`; doctor: `src/commands/doctor/checks/folder-access.ts`. Tests: `test/access-folder-rules.test.ts` (database store, both engines), `test/access-folder-rules-git.test.ts`, `test/access-folder-transfer.test.ts`, `test/access-folder-doctor.test.ts`. Shared agents (B, GBRA-231): `audience.ts` parses the audience a harness asserts (`X-Gbrain-On-Behalf-Of` or request-level `_meta.on_behalf_of`, 1-50 principals, `guest` = the empty identity; the same key inside tool arguments is refused) and appends each assertion to `access-audience-YYYY-Www.jsonl`. Dispatch resolves it on every remote call through `caller.ts` (`resolveAudienceIdentities`: every entry must be in the credential's live `may_act_for`, then name an enabled member or existing group); the caller-access record then carries `audienceIdentities`, and `accessAllowedForAllSql` needs one readers conjunct per identity, folder rules the intersection of each entry's satisfied set (`folderAccessForAll`). Privacy relaxes only for a one-member audience. Writes carry the audience as `WriteAuthority.actingFor` (re-resolved at publication) and agent jobs as `grant.actingFor`. Every remote response carries `_meta.access` (`appliedAccessSummary`), which `whoami` returns as `access.applied`; doctor `access_may_act_for_wildcard` (`checks/shared-agent-access.ts`) warns on `*`. Tests: `test/access-on-behalf-of.test.ts` (both engines), `test/e2e/serve-http-on-behalf-of.test.ts`. Attested actor (C1, GST-359): `actor-model.ts` (dependency-free: `x-qm-actor`, `acting_user`, `EXTERNAL_ID_RE` = 1-256 visible ASCII, `attestRightFrom`: the right counts only for a member-less credential whose token is legacy or `client_credentials`, read from `oauth_tokens.grant_type`) and `actor.ts`. `resolveAttestedActor` runs in dispatch before any work: an invalid id refuses `actor_not_attested` (`invalid_actor_id`) before any lookup, then the right, the op list (`attest_ops`, default `get_write_request,memory_recall,memory_write`), `acting_user` = header (stripped), and `actorCoverage` (the one coverage test: live right plus a live link in `access_member_links` to an enabled member, compared exactly) or `actor_unlinked`. GST-1158: `scope-read.ts` holds `SCOPE_READ_ACCESS` (no identity, actor or audience; privacy never relaxed) and `SCOPE_READ_OPS`; dispatch runs an attested call to one of those ops that names `source_id`/`source_ids` under that record (`attestedReadMode`, which refuses `__all__`/`all_sources`), or as the person when the right's `attest_read` (v298, `--attest-read`) is `person`, and handlers read the mode with `currentReadMode`. `attest_read = 'scope'` refuses a call that names no actor (`actor_required`). Tests: `test/qm-scope-read.test.ts` (both engines), `test/doctor-attest-read-shared-scope.test.ts`. GBRA-284: `member-sources.ts` binds a source to its member (`access_member_sources`, v299; `gbrain access member source add|remove|list`); `attestedReadScope`, called in dispatch for every attested call and in `minions/tools/brain-allowlist.ts` for an attested job's tool calls, replaces the call's read grant with the grant minus personal sources bound to another member (every personal source under a scope read), so every resolver refuses or skips them like out-of-grant sources and nothing is added. Test: `test/qm-personal-sources.test.ts` (both engines). `ACTOR_DEFERRED_OPS` (`capture`, `extract_facts`, take writes, `list_write_conflicts`, and since GST-2249 W1 every page write; `test/qm-attest-write-boundary.test.ts` classifies every attestable mutating operation) are never attestable: refused by `parseAttestOps`, `bindCredential`, every call and the stored re-check, which also re-checks `attest_ops` for a queued write's operation and each job tool call. Under the header serve-http lists only attested tools and refuses `resources/read`. `attestedCallerAccess` is a one-member audience with privacy never relaxed (no granted sources, no hatch), never B's `may_act_for` path. Writes store `WriteAuthority.actingFor = {system, external_id, member}` and jobs `grant.actor`; `storedActorIdentity` re-resolves both through `actorCoverage` and refuses when the member changed. `linkMember` / `unlinkMember` / `listMemberLinks` back `gbrain access member link|unlink|links`; `linkMemberByEmail` (GST-1158) finds the member by its declared email (`members.ts` `memberByEmail`: `access_members.email`, migration v301, case-folded, unique, cleared on removal; `not_found` when none, `email_ambiguous` when several) and then links exactly as `linkMember`, from the local CLI and the owner-session routes in `src/commands/serve-http-access.ts` only; `--attest-actor` / `--attest-ops` on `auth rescope` (`members.ts`) only for a member-less legacy token or confidential client-credentials client. Migration v286. Tests: `test/access-qm-actor.test.ts` (both engines), `test/e2e/serve-http-qm-actor.test.ts`. Member facts (C2, GST-359): `member-facts.ts`. A remote `remember` from an attested actor or a lone-member credential (`callerMember`, never an audience of several) writes to `memory/members/<member>` (`memberFactPage`; `persistence/memory-prepare.ts` creates the page with `readable_by: [member:<id>]`), `visibility: private`, `infer_entity` off, the entity kept as `entity_slug`, unless the call passes `share: true` (GST-2243), which takes the ordinary world route to the subject's page; a member's explicit `visibility: "world"` is refused in `remember`'s validation (`member_share_required`), so a batch with one such item saves nothing. A member id whose page slug `slugifyPath` would change (`a--b`, `zed-`) is refused (`invalid_params`). The page must name that member alone (`memberPageIsOwn`, checked at submission and again in preparation, `memberPageNotOwned`), and remote writes under `memory/members/` go only to the caller's own page (`assertMemberPageWriter`, called from `ops/context.ts` `enforceClientSlugFence`, so every remote page write passes it; trusted local callers are unaffected). Reads widen a world-only fact list only by `memberFactAdmitSql` (a private fact on the caller's own live member page whose readers and folder rules admit the caller; `factVisibilitySql` in `engine-sql/facts.ts` and `search/fact-relevance.ts`), and `privateProvenanceFilterUnderPolicy` judges a member-page fact's source page as the caller (every other fact keeps the empty identity, so a fact from a page that names readers stays hidden from every remote caller). Writers never cross pages: `facts/single-prepare.ts` (`SingleFactIntent.page_slug`) and `trust/supersede-handlers.ts` dedup, supersede and contest only within the member page, and no other write matches a fact there (`onMemberPageSql`); consolidation skips facts whose page names readers (`readersSourcedFactSql`). Per-person keys: `callerIdentityKey` joins the hot-memory cache key (`facts/meta-hook.ts`, `::xid=`), `callerSessionKey` the `delta` cursor (`ops/facts.ts`), `sameAttestedActor` gates receipts (`persistence/authority.ts` `ownRequestAccessible`) and replays (`persistence/journal.ts`) on the stored actor, else the stored audience, and `get_agent_job` and the owner-fenced `get_job`, `wait_job`, `get_job_progress`, `list_jobs` and `cancel_job` match the job's `grant.actor` (system, external id, member) and `grant.actingFor` (the same distinct audience entries; `jobActorSql` in `minions/types.ts`), so a job or receipt with an actor or audience reads as missing to the bare client and to other actors and audiences, and one with neither to every actor and audience. Tests: `test/access-member-facts.test.ts` (both engines), `test/access-member-sweep.test.ts` (every attestable op as Bob, the bare client and an unbound credential; `test/helpers/member-sweep.ts`), `test/e2e/serve-http-member-sweep.test.ts` (two members over a real `serve --http` on a keyless repo-less brain).
- `src/core/access/federation-exposure.ts` (#8982) — `remotePagesFederationExposes(engine, source)`: the live pages of a source that name no readers and no folder rule, that the read paths' privacy rules (`privacyPartSql`) do not hide from a no-grant connection (#9068; skipped when `remotePrivacyRelaxed` says an operator opted out), and whose live revision (`pages.revision_principal_*`) or any version (`page_versions.write_principal_*`) a token or OAuth client wrote (revoked or deleted included; no record keeps a credential's member at write time, so an unbound, rebound or deleted one counts and each example names its member now; a tag change moves the revision attribution without a version, hiding the earlier author): count, the first five slugs, and shell-quoted `who-can-read` / `access rule add` commands. `remotePagesFederationExposesOrWarn` runs it, after the change commits, only for a change that added the source to the no-grant floor (federate reads the prior state under the source row lock), and turns a failed read into a stderr warning, so the caller's federation never changes. Read by `sources federate`, the unmanaged `sources restore` (stderr; `--json` as `pages_exposed`) and the managed `source_lifecycle` restore result. Pinned by `test/sources-federate-member-pages.test.ts` and `test/federation-exposure-private-9068.test.ts`.
- `src/core/access/serves.ts` + `src/commands/access-serves.ts` (GST-363 PR 1) — whether a brain serves several people (`brainServes`: config `access.serves` `one`|`several` wins, else 2+ enabled members) and `gbrain access serves [several --members a,b [--yes]]`: preview, then config, members (kept when present), one folder rule `people/<member>/` per member through `addFolderRules` (`access-rules.ts`, the `rule add` preview-then-write path; a git store commits `.gbrain/access.yml` through the commit door), and one read-write token `member-<id>` per member through `auth-mint.ts` (the `auth create` mint) written to `<configDir>/member-keys/<id>.key` (0600, dir 0700, refused inside a git work tree: `access_serves_key_dir_in_git`). Idempotent on the member id; a token whose file is gone is reported, never re-minted. `GBRAIN_SETUP_ABORT_AFTER=serves-members|serves-rules|serves-key` is the crash seam. Doctor: `checks/unlabeled-people-folders.ts` fails a `people/<x>/` folder with pages no rule covers on a several-person brain. Tests: `test/setup-serves-several.test.ts` (both engines).
- `gbrain serve --stdio-member <id>` (GST-363 PR 3) — `parseStdioMemberFlag`, `registeredStdioMember` and `withStdioMember` live in `src/core/stdio-member-flag.ts` (kept out of `mcp-registration.ts` so serve and doctor pick up no registration flags); serve passes the value to `startMcpServer`, dispatch sets `OperationContext.stdioMember` only for an unauthenticated stdio call, and `caller.ts` resolves it live ahead of config `mcp.stdio_member` (a disabled or unknown member reads as nobody, no fallback). Stored writes stamp it on `WriteAuthority.stdioMember` (jsonb, no migration); a stdio watch uses principal id `registration` so the wake drain re-checks that member. Setup writes it into one claude-code or codex entry (`ClaudeSetupPlan`/`CodexSetupPlan.stdioMember`); inspection reports an owned entry's member so setup re-runs and `refreshHookLaunchers` carry it, and `setupRerunArgv` never names it.
diff --git a/docs/guides/access-designations.md b/docs/guides/access-designations.md
index ef5490ccd9..9cd98fb303 100644
--- a/docs/guides/access-designations.md
+++ b/docs/guides/access-designations.md
@@ -117,7 +117,10 @@ These rules follow the origin, so nobody writes them by hand:
and any page whose `derived_from` names a private page are private whatever their own field says;
- anything derived from a page that names `readable_by` or sits under a folder or page rule is hidden from every
remote caller, except a credential bound to the owner: the owner reads a derived page or a fact when it reads every
- origin of it (a folder rule kept to the owner, or readers that list the owner).
+ origin of it (a folder rule kept to the owner, or readers that list the owner). Three operator settings change this,
+ all off by default: a raw-only rule does not hide what is derived from its pages, an audience member's own member
+ page reads to the owner as if it named the owner, and `access.members_read_lineage` gives every member the owner's
+ rule (all below).
`gbrain repair visibility` stamps the explicit value on derived pages (tighten-only). The owner reads them all.
@@ -138,6 +141,18 @@ member with `default` or a federated source as its write source gets it on the p
except the owner's, whose new pages stay shared (`POST /ingest` still refuses both). See
[company brain, Model C](../tutorials/company-brain.md#two-scoping-models-pick-the-one-that-matches-your-shape).
+**Raw-only rules.** `gbrain access rule add --prefix transcripts/ --readers alice-example --raw-only` (in
+`access.yml`, `covers_derived: false` on the rule) keeps the pages under `transcripts/` to their readers, but not the
+pages and facts derived from them: an atom, a summary, a synthesized concept, a chronicle event or a fact made from a
+raw-only page is read by whoever reads that derived page. Use it for raw material such as call transcripts, whose
+summaries are meant to be shared. Never use it for a folder whose content is itself the secret: a summary of a
+raw-only page carries what the page says. A page's own `readable_by` still hides what is derived from it, and a page
+that another covering rule also matches stays covered. Every rule written before this existed covers derived pages and
+keeps its digest. Making a rule raw-only widens access, so it waits for `gbrain access apply` (preview, then
+`--expect <plan_hash>`); making it covering again (the same command without `--raw-only`) applies at once. Doctor's
+`access_raw_only_rules` lists every raw-only rule, and `who-can-read` says when a page's lineage is open. Works the same
+for rules in the database (a repo-less brain) and in `access.yml`.
+
### Fact visibility (`private` | `world`)
Each fact row has its own visibility. `remember` defaults to `world`, except into a private page or under an
@@ -171,6 +186,30 @@ owner agent can copy private content into a shared page. A prompt planted in a p
Bind only agents you trust with the whole brain as the owner; give every other agent its own member, whose new pages
stay kept to it.
+### Audience members (`gbrain access member kind`)
+
+A member can stand for a group chat or a shared assistant rather than a person. `gbrain access member kind <id>
+audience` (or `gbrain access member add <id> --kind audience`) marks it; `gbrain access member kind <id> person` is the
+undo. The owner then reads that member's own member page (`memory/members/<id>`), its older versions, its derived
+pages and its facts as if the page named the owner, with or without the owner opt-in; folder rules still apply unless
+the opt-in is on. Only that page: a page that lists the audience in `readable_by` stays under the usual rules (the
+owner opt-in opens it), and a person member's member page stays closed to the owner. Nothing changes for any other
+caller, and no write widens. Only the brain operator on the brain host sets a kind; a remote caller is refused
+(`permission_denied`). `gbrain access member list` shows each member's kind, `who-can-read` lists the owner on such a
+page, and doctor's `access_audience_members` lists the audience members.
+
+### Members read lineage (`gbrain access members-read-lineage`)
+
+`gbrain access members-read-lineage on` (config `access.members_read_lineage`, off by default and unchanged on
+upgrade) gives every member's credential the owner's lineage rule: a member speaking for itself (no audience, or an
+audience of that one member) reads a derived page or a fact when it reads every origin of it, on every read path and
+in `--as <member>`. Summaries of a page then reach everyone that page lists, so turn it on only when that is what the
+members expect. It never applies to an audience of several members, a group or a guest, an attested call, an unbound
+credential or a `granted_sources` grant, never widens a write, and leaves the owner opt-in to the owner. Only the brain
+operator on the brain host sets it; a remote caller is refused. While it is on, every remote caller's `whoami` says so
+(`members_read_lineage`), `gbrain access check` reports it, `who-can-read` names it on pages it opens, and doctor
+reports `access_members_read_lineage`. `gbrain access members-read-lineage off` is the undo.
+
## Related
- [Multi-source brains](multi-source-brains.md): sources and grants.
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsv
index f1cd64de0e..3ad8264749 100644
--- a/scripts/module-size-limits.tsv
+++ b/scripts/module-size-limits.tsv
@@ -43,7 +43,7 @@ src/core/persistence/worktree-refresh.ts 1554 ratchet new row: crossed the 1500
src/core/bootstrap/harness.ts 2630 ratchet +29 live-PGLite-serve lane: LIVE_SERVE refusal ahead of source resolution + unpinned --token hooks (CI e2e fix); +46 wave review: resolveHookSource dep (serve-parity resolver + federated grant), --source shape validation, loud SOURCE_UNRESOLVED instead of a silent 'default'; +10: #4574 parseCodexBlockBearer http_headers shape + legacy bearer_token fallback; +4 at megawave/wave-k merge; +codex hooks lane: step-7 codex hooks.json + config.toml trust pair, removeHarness arm; +234 ambient-writeback WP3: kind:'instructions' targets (plan/apply/converge-off/remove/status probes, OV-A4 override pre-check) — splice/render mechanics live in instructions-block.ts; +59 adversarial fix wave: registrar-mode block suppression, converge-failure receipt tracking, MCP-confirmed guard before block install; +26 round-3 fixes: codex-lane MCP-confirmed guard + smoke-rollback block strip; master: | merged v0.48.1.0 true-up; +41 #4897 resolveImplicitSource dep + defaultResolveImplicitSource: hooks/token/receipt bind to the serve's implicit default source when --source is omitted; +23 #4586 statusHarness live claude-code mcp verdict (URL mismatch or same-scope non-HTTP registration reads failed, receipt untouched); shared-skills integration on company-ingestion base; +18 #5671: logAmbientPostureNotes helper (registrar note moved out of applyHarness + pre-consent warning when an explicit private facts default meets the HTTP harness; text shared with doctor in facts/writeback-config.ts); +24 #5893: rotation grant carry wiring and its rotationCarry/withheldOperationsNote helpers (carry rules live in token-mint.ts carryLegacyGrant); +6 #5878: --refresh-skills flag and status epoch line (refresh logic lives in harness-skills.ts); +7 #4618 seat: HarnessFlags.seat field, --seat/--no-seat parse via hooks.ts parseSeatFlags, GBRAIN_SEAT in the hook env; -119 #6082: plugin-lane detectors moved to plugin-lanes.ts (re-exported); +18 #6092/#6171: hook ownership identity on write/remove/converge, permission ownership carry, --remove --dry-run and the --status hook census (logic in hooks.ts + harness-hooks.ts); +5 D8 Codex slice: the Codex SessionEnd capture hook obeys the recorded consent (wireCodexCapture: hooks on, capture accepted, never registrar mode) and is disclosed in the consent block; -31 #6743: cleanup gate moved to harness-cleanup.ts; +8 #6798: supersededEnrollments dep (interface field + default) and the --status epoch hint printed only for a superseded enrollment (the brain read lives in harness-skills.ts brainSupersededEnrollments); +13 brain-first block lane: --no-instructions flag field + parse, opencodeAgentsPath dep (field + default) and the step-10b / remove call sites (logic lives in harness-brain-first.ts); +7 GBRA-243 per-turn rule hook: consent-block interface field, step-10c call site, turn_hooks JSON field, exit code and the remove arm (writer, host list and consent text live in harness-brain-first.ts); +2 #8428: the harness lane Claude Code and Codex SessionEnd hooks start gbrain through the hook launcher; +16 GBRA-194 skills index lane: --skill-loading flag field + parse, step-10b and remove call sites, skills_index JSON field and exit-code wiring (logic lives in harness-skills-index.ts and setup/skills-block.ts)
src/core/oauth-provider.ts 1237 ratchet new row: crossed the 1500 unlisted cap absorbing #3819 (DCR 400 invalid_client_metadata + scope filtering + custom-scheme redirect_uris + pseudo-scheme guard); merged v0.49: transactional grant enforcement shared with hosted grant policies; +1 #5222 resourceUrl option; +1 GST-1113 transactional token mint
src/core/ops/pages.ts 744 ratchet crossed the unlisted 1500 cap in the fix wave: pack-vocabulary enforcement on capture (#4721) + get_page alias follow (#4275) landed together; next growth should peel a pages-ops submodule; +3: alias hop reads the canonical in the owning source (ship-review); +5: explicit source_id liveness check in get_page/list_pages (#4620); +3: #4857 total-order slug sort + list_pages source_id parse; +5: #4620 explicit removed-source id fails loudly; master integration: +4: authenticated delegated private-write boundary and auto-link suppression; #5105: canonical page mutations peeled into persistence modules; +2 v0.50.5.0 purge parameter and shared preflight call; preparation composes through the persistence modules; +7: source-qualified deep-research fetch authorization and ambiguity refusal (codec lives in deep-research-id.ts); +1 #5567: remote get_page keeps materialized markers; +1 #5622: trusted local capture file parameter; +5 #5709: get_page include_timeline_entries (rows via get_timeline's read policy); +8 GBRA-36 security wave: required outputRedaction policy on each pages op; +1 #5154: list_pages passes listColumnsOnly; +17 #5641: list_pages exposes the updated_after_slug keyset cursor and updated_at_iso; +8 agent operator wave A2: every op declares mutating + idempotent (tags only); +7 F3b (#5954): list_pages pagination meta + listing_truncated notice for MCP callers (logic in ops/list-pages-pagination.ts); +4 #5988: get_page file_held (one indexed hold lookup; logic in persistence/held-reads.ts); +6 #6103: list_pages maps an unreadable updated_after (SQLSTATE 22007/22008) to invalid_params; wave 10 collector: #6103 (+6) and #4807 (+2) compose; +1 wave 11 W4.3 (#5969 D3): put_page drop_timeline param; +1 wave 11 security review: purge_deleted_pages yes param + trusted-CLI guard (consent logic in persistence/purge-deleted.ts); +1 Q2 parser gaps: get_page grammar_diagnostics param (report logic in core/line-grammar-report.ts); master v0.60.136.0 merge into #5575 memory trust (both sides kept); +21 large pages (Wave A): get_page body-mode dispatch, fetch window branch, put_page large-page admission and allow_shrink param, description text (logic in ops/get-page-body.ts and persistence/large-page-guard.ts); +1 D8 funnel: committed put_page records a save when the opt-in funnel is on; +1 #6609: restore_page detach param (logic in persistence/detached-pages.ts); +1 Wave B gem A: post-batch auto-link reads a segmented page materialized (helpers in persistence/segmented-apply.ts); merge v0.60.249.0: composes at 707; +4 Wave B PR 2: get_page refuses a segmented page whole and fetch windows one (logic in ops/get-page-body.ts and page-window/segmented.ts); +2 Wave B PR 2 lane F: get_page and fetch pin segmented reads to the authorized snapshot (pin logic in ops/get-page-body.ts authorizedReadPin); +3 W2 page-at-time: get_page known_as_of param and dispatch (logic in ops/known-as-of.ts and belief/page-at-time.ts); GBRA-151 retrieval P0 x operability wave merge: both sides grew the file, re-summed (721 measured); GBRA-151 #7147 follow-up re-summed at the v0.60.334.0 merge (727 measured); +1 #7305: capture dry run applies the hyphen-run slug admission (logic in persistence/suffixed-slug.ts); +1 GST-687: get_page include_timeline_entries quotes rows for remote readers (import only; logic in ops/timeline-quote.ts); +2 #8384: the quoted_unverified_origin notice call in get_page and fetch (logic lives in get-page-projection.ts); +1 GBRA-218: put_page checks a remote readable_by before admission (logic in persistence/page-visibility.ts assertSubmittedReaders) (re-summed at the train M merge of master v0.60.539.0: 732 measured); re-summed at the memory train #8481 merge with v0.60.576.0 (739 measured); +4 GBRA-449: an empty list_pages names the page types present when no visible page has the requested type (logic in ops/list-pages-pagination.ts unusedTypeNotice); +1 GST-2462: a static import of the put_page ignored-label notice (a dynamic one yielded on the first put_page, so a queued embedding ran inside it; mode-receipt.serial.test.ts)
-src/core/search/mode.ts 1731 ratchet +12 #7175 (train R): search.keyword_phrase bundle field, config parse and knobsHash part; +53 W3 confidence-gated reranking: reranker_gate / reranker_gate_min_gap bundle fields, overrides, config parse and KNOB_CONFIG_KEY rows, knobsHash v=31 rrg=/rrgg=/ecf= parts (parse contracts in crag.ts); +10 System One v1: decide.* snapshot subset in loadSearchModeConfig, append-only dec= knobsHash part; +5 #3617 follow-up: v27 same-knobs behavioral-change note (relaxed-row fusion demotion rides the bump); new row: crossed the 1500 unlisted cap in the 2026-08 eval fix wave — KNOBS_HASH v=27 adaptive-return fold (ar/arem/arom/armk/ari parts + KnobsHashContext.adaptiveReturn field + contamination rationale comments) | merged v0.48.1.0 (+#4787) true-up; +master v0.48 merge true-up (reranker succession: no_key preflight, reranker_skipped stage, readiness); ranker wave v0.48.4.0: four knobs (expansion_variant_budget, relational_rerank_pin, keyword_arm_confidence_floor, metadata_boost_gate) + v29 hash parts + doc receipts (+218); #4781 loadSearchModeConfig reads the config table once via loadConfigSnapshot (+6); +4 #4359: update loadSearchModeConfig docstring — the cached path now reads config once (threaded snapshot), not twice; retired provider integration removed; +12 fw3-search: search.source_boosts + search.alias_token_hop read in the mode snapshot; +10 #5691: KnobsHashContext.queryPrefix and its append-only qp= part; P7 relational_planner / relational_orient_onehop knobs (interface docs, bundles, overrides, config parse, hash parts); +18 P7 relational_chain_slots knob (interface doc, bundles, override, config parse, rcs= hash part); +22 GBRA-60 S1 diverse_pool_depth knob (interface doc, bundles, overrides, pick, config parse, append-only dpd= hash part); +35 GBRA-154: collapse and rank_priors knobs (interface docs, bundles, overrides, pick, config parse, append-only col=/rpr= hash parts); GBRA-151 retrieval P0 x operability wave merge: both sides grew the file, re-summed (1704 measured); +5 GBRA-156 #7593: private-pages grant part in the cache key; +7 GBRA-218 A1: append-only xid=/xhp= knobsHash parts (member identity, operator privacy relaxation); +1 GBRA-231: append-only xau= knobsHash part (shared-agent audience identities) (re-summed at the train M .538 merge: 1717 measured); +1 GBRA-283 B2: import of the embedded engine reranker model (engine-gateway.ts); re-summed at the train R merge with v0.60.574.0: 1721 + 9; +1 GST-2490: append-only xol= knobsHash part (owner lineage and the owner opt-in)
+src/core/search/mode.ts 1732 ratchet +12 #7175 (train R): search.keyword_phrase bundle field, config parse and knobsHash part; +53 W3 confidence-gated reranking: reranker_gate / reranker_gate_min_gap bundle fields, overrides, config parse and KNOB_CONFIG_KEY rows, knobsHash v=31 rrg=/rrgg=/ecf= parts (parse contracts in crag.ts); +10 System One v1: decide.* snapshot subset in loadSearchModeConfig, append-only dec= knobsHash part; +5 #3617 follow-up: v27 same-knobs behavioral-change note (relaxed-row fusion demotion rides the bump); new row: crossed the 1500 unlisted cap in the 2026-08 eval fix wave — KNOBS_HASH v=27 adaptive-return fold (ar/arem/arom/armk/ari parts + KnobsHashContext.adaptiveReturn field + contamination rationale comments) | merged v0.48.1.0 (+#4787) true-up; +master v0.48 merge true-up (reranker succession: no_key preflight, reranker_skipped stage, readiness); ranker wave v0.48.4.0: four knobs (expansion_variant_budget, relational_rerank_pin, keyword_arm_confidence_floor, metadata_boost_gate) + v29 hash parts + doc receipts (+218); #4781 loadSearchModeConfig reads the config table once via loadConfigSnapshot (+6); +4 #4359: update loadSearchModeConfig docstring — the cached path now reads config once (threaded snapshot), not twice; retired provider integration removed; +12 fw3-search: search.source_boosts + search.alias_token_hop read in the mode snapshot; +10 #5691: KnobsHashContext.queryPrefix and its append-only qp= part; P7 relational_planner / relational_orient_onehop knobs (interface docs, bundles, overrides, config parse, hash parts); +18 P7 relational_chain_slots knob (interface doc, bundles, override, config parse, rcs= hash part); +22 GBRA-60 S1 diverse_pool_depth knob (interface doc, bundles, overrides, pick, config parse, append-only dpd= hash part); +35 GBRA-154: collapse and rank_priors knobs (interface docs, bundles, overrides, pick, config parse, append-only col=/rpr= hash parts); GBRA-151 retrieval P0 x operability wave merge: both sides grew the file, re-summed (1704 measured); +5 GBRA-156 #7593: private-pages grant part in the cache key; +7 GBRA-218 A1: append-only xid=/xhp= knobsHash parts (member identity, operator privacy relaxation); +1 GBRA-231: append-only xau= knobsHash part (shared-agent audience identities) (re-summed at the train M .538 merge: 1717 measured); +1 GBRA-283 B2: import of the embedded engine reranker model (engine-gateway.ts); re-summed at the train R merge with v0.60.574.0: 1721 + 9; +1 GST-2490: append-only xol= knobsHash part (owner lineage and the owner opt-in); +1 GBRA-108: append-only xak= knobsHash part (the owner's audience members; member lineage reuses the xol= line as xol=3)
src/commands/eval-longmemeval.ts 1545 ratchet new row: crossed the 1500 unlisted cap in fw3-search (#5092 benchmark-brain recycling: configureBrain split + recycler wiring + test seams; the recycler itself lives in src/eval/longmemeval/harness.ts); +1 P6: tokenmax synopsis-tier wiring (logic in eval/longmemeval/synopsis-tier.ts); +13 GBRA-81 lane A: --via-operation query|search (flags, per-call expansion pin, the run's expectExpansion, the op branch in runOneQuestion, row field, via_operation_summary and its FAIL line; logic in eval/longmemeval/via-operation.ts); +12 --call-plan FILE / --call-plan-gate CMD: two LME_FLAGS entries (CLI help lines), two ParsedArgs fields, the parseArgs pairing check and the header invariant (planner lives in eval/longmemeval/call-plan.ts; runEvalLongMemEval is one line shorter); +1 #7619: parseArgs refuses a value on a switch (--judge=false turned the paid judge on)
src/commands/doctor/checks/extraction-sync.ts 1500 ratchet +7 GBRA-130 A-1: links_extraction_lag held bucket and its retry fix (logic in core/extraction-lag.ts heldExtractionReport); +1 undeclared_db_only_pages computes the source Git scope once per source (logic in core/markdown.ts sourceGitScope); new row: crossed the 1500 unlisted cap at the fix wave 9 merge: +7 lane W #5028 (extract_atoms freshness judged by the phase itself) and +3 lane F #5863 (extract_health dates a high halt rate by its last halt), each under the cap alone; +7 #5019: content_hash_duplicates fix pins the pairs' source (GBRAIN_SOURCE) and names a delete that runs; +1 fix wave 10 lane L1 #5556: links_extraction_lag denominator excludes quarantined pages (quarantineFilterFragment import); +11 fix wave 15 P2.8 (#5495): extract_health reads the 7-day halt reasons per kind (halt_reasons, top_halt_reason in details and the top reason in the warn line); the read, the unknown bucket and the ranking live in core/extract/rollup-writer.ts; +20 wave 18b lane 1: links_extraction_lag names the columns its pre-migration degrade reads (#6599 strict predicate), sync_freshness separates sync outcome from freshness for a source with no successful sync (#4960; verdict text, fixes and the attempt read live in doctor/sync-outcome.ts and core/sync-attempt.ts) and exempts read-only skill-pack catalogs (#6076; core/shared-skills/adopted-packs.ts); -51 #6803 (D1): links_extraction_lag reads its counts and verdict from core/extraction-lag.ts (shared with the sync nudge); +1 #7145: content_hash_duplicates reads one group past its list to report a floor ("at least 50")
src/core/search/evidence-delivery.ts 1759 ratchet +5 W5: EvidencePlan.rankCut resolved with the plan (logic in search/page-rank-cut.ts); +20 W5 whole_pages: wholeCost prices a block as delivery would emit it whole (needs the private Block/enrichBlock internals) and the cut is wired before allocate (cutWholePages lives in search/page-rank-cut.ts); new row: crossed the 1500 unlisted cap at the #6367 merge (master 1479, its explicit-budget cap) by the C1 date header threaded through every block path, cap included; pagePlanHits (search/page-plan-hits.ts) and the header loader (evidence-date.ts blockDateHeaders) were peeled first; peel candidate: allocateCapped; +8 at the #6396 merge: page evidence text cut through the fence-chunk trust overlay and the caller minTrust floor (re-summed: our 1504 + master +8); +119 Cat 40 next wave F2: the search.long_page_unit policy (withLongPagePolicy, selectLongPages size preflight with page/byte/deadline limits) and the long-page fetch and fallback in deliverEvidence, kept in the shared seam the plan names (gbrain-evals docs/plans/2026-10-11-cat40-next-wave, F2); +17 F2 rework to the frozen-comparison policy: search.long_page_min_chars (rendered-body characters, default 20,000) read in withLongPagePolicy, a character count in the preflight, the rendered-body confirmation in deliverEvidence, and the long-page row exemption in capDeliveredSnippets (re-summed at the 0.60.225.0 merge: master 1537 + F2 136); +39 Wave B PR 2 lane 2b: planSegmentedBlock joins the windows search/segmented-evidence.ts reads around a segmented page's hits into one run-marked document (needs the private Doc/Piece/buildDoc/locateAnchor internals), planBlock's unit cut split into blockFromDoc for both, sections bounded by their run, selectionCost counts a gap between runs, and the fetch skips the whole-body fence overlay for a segmented page; +4 segmented pages read at once before planning (segmentedReads; the read is search/segmented-evidence.ts, the statements page-body/read-range.ts); +17 GBRA-156: tail trim plan flag, DeliverOptions.query, DeliveryMeta.tail_trim, the trim call and the frozen-hit score/query library fields (logic in search/evidence-tail-trim.ts; interface fields cannot move); +7 GBRA-205: EvidencePlan.titleHeader and DeliveryMeta.title_header (interface fields cannot move) and the titles option on the header loader (logic in search/evidence-date.ts; the query budget key lives in search/evidence-packing.ts); +11 #7600: assemble_evidence quotes conversation rows and capEvidenceToBudget counts the quote fence (logic in search/transcript-quote.ts); +2 GBRA-156 /ship review: the cut-path admission and title room count the quote fence; +2 GBRA-156 /ship review pass 2: capEvidenceToBudget counts the fence only for the paths that fence (quote flag; recall counts the text as returned); +4 GST-687: page evidence and the extractive fallback quote below-owner-tier text for untrusted readers (untrusted flag; logic in search/transcript-quote.ts)
diff --git a/scripts/stress/iteration-weights.json b/scripts/stress/iteration-weights.json
index 62f2cf0600..b325e71790 100644
--- a/scripts/stress/iteration-weights.json
+++ b/scripts/stress/iteration-weights.json
@@ -1,5 +1,8 @@
{
+ "test/access-audience-members.test.ts": 60000,
+ "test/access-members-read-lineage.test.ts": 60000,
"test/access-page-rule-fileless.test.ts": 59000,
+ "test/access-raw-only-rules.test.ts": 60000,
"test/activation-unbound-rooted-6449.test.ts": 8600,
"test/agent-journey-upgrade.serial.test.ts": 56550,
"test/alias-source-cascade-5094.test.ts": 7700,
diff --git a/src/cli/as-preview.ts b/src/cli/as-preview.ts
index f5eeac1ab1..68b0fc4d39 100644
--- a/src/cli/as-preview.ts
+++ b/src/cli/as-preview.ts
@@ -2,7 +2,8 @@
* GBRA-218 local `--as <member>`: an operation's reads previewed as one member.
* The handler runs under that member's identity with the remote read policy
* (readers and privacy; GST-2059: the brain owner reads with privacy relaxed, and GST-2490: with access.owner_reads_restricted
- * on, past readers lists and rules too), while ctx.remote stays false, so upload confinement
+ * on, past readers lists and rules too; GBRA-108: a read previews the lineage the member's own credential gets, owner
+ * or access.members_read_lineage, and the owner's audience members), while ctx.remote stays false, so upload confinement
* and write trust are unchanged. An unknown or ill-formed member is refused
* before any work.
*/
@@ -36,19 +37,24 @@ export async function openAsPreview(engine: BrainEngine, member: string | undefi
let identity: string[];
let owner: boolean;
let ownerReadsRestricted: boolean;
+ let lineage: boolean;
+ let audienceKindMembers: string[];
try {
- const resolved = await (await import('../core/access/members.ts')).memberIdentity(engine, member);
+ const membersModule = await import('../core/access/members.ts');
+ const resolved = await membersModule.memberIdentity(engine, member);
identity = resolved.identity;
const ownerModule = await import('../core/access/owner.ts');
owner = resolved.member === await ownerModule.ownerMemberId(engine);
ownerReadsRestricted = owner && await ownerModule.ownerReadsRestrictedOn(engine);
+ lineage = readOnly && (owner || await (await import('../core/access/lineage.ts')).membersReadLineageOn(engine));
+ audienceKindMembers = owner && lineage ? await membersModule.audienceMemberIds(engine) : [];
} catch (e: unknown) {
await finishCliTeardown({ engine });
exitCliError(e, command);
}
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, ownerLineage: owner && readOnly, ownerReadsRestricted: ownerReadsRestricted && readOnly, privateReadableSources: [] };
+ const access = { identity, ...folder, applyRemoteReadPolicy: true, hidePrivate: !owner, owner, lineage, ownerReadsRestricted: ownerReadsRestricted && lineage, audienceKindMembers, privateReadableSources: [] };
return {
run: fn => withCallerAccess(access, fn),
context: ctx => ({ ...ctx, accessIdentity: identity, applyRemoteReadPolicy: true }),
diff --git a/src/commands/access-rules.ts b/src/commands/access-rules.ts
index 50975f883c..f7f484471d 100644
--- a/src/commands/access-rules.ts
+++ b/src/commands/access-rules.ts
@@ -1,7 +1,7 @@
/**
* GBRA-218 (PR A2): `gbrain access rule|apply|resume`, the operator surface for folder rules.
*
- * gbrain access rule add --prefix <folder/> | --slug <page> --readers a,group:b [--id <rule>] [--source <id>] [--yes] [--expect <rev>] [--operation <id>]
+ * gbrain access rule add --prefix <folder/> | --slug <page> --readers a,group:b [--raw-only] [--id <rule>] [--source <id>] [--yes] [--expect <rev>] [--operation <id>]
* gbrain access rule rm <rule> [--source <id>] [--yes] [--expect <rev>] [--operation <id>]
* gbrain access rule list|status|history [--source <id>] [--operation <id>] [--limit <n>]
* gbrain access rule revert --to <revision> [--source <id>] [--yes]
@@ -21,7 +21,7 @@ import { readFileSync } from 'node:fs';
import type { BrainEngine } from '../core/engine.ts';
import { usageError } from '../cli/cli-error.ts';
import { opError } from '../core/ops/contract.ts';
-import { classifyRulebook, folderRulesAllow, normalizeRule, ruleCoversSql, parsePolicyYaml, serializePolicyYaml, sortRules, type FolderRule, type RuleChange } from '../core/access/folder-rules.ts';
+import { classifyRulebook, coversDerived, folderRulesAllow, normalizeRule, ruleCoversSql, parsePolicyYaml, serializePolicyYaml, sortRules, type FolderRule, type RuleChange } from '../core/access/folder-rules.ts';
import { identityFor } from '../core/access/principals.ts';
import { boundCredentials, listGroups, listMembers } from '../core/access/members.ts';
import {
@@ -73,10 +73,11 @@ function progressLogger(json: boolean): (p: RestampProgress) => void {
}
const reader = (p: string) => (p.startsWith('member:') ? p.slice(7) : p);
-const ruleLine = (r: FolderRule) => ` ${r.id} ${r.prefix} readable by ${r.readable_by.map(reader).join(', ') || 'nobody'}`;
+const ruleLine = (r: FolderRule) => ` ${r.id} ${r.prefix} readable by ${r.readable_by.map(reader).join(', ') || 'nobody'}${coversDerived(r) ? '' : ' (raw only: its derived pages and facts are not kept to these readers)'}`;
function changeLine(c: RuleChange): string {
const what = c.kind === 'added' ? 'add rule' : c.kind === 'removed' ? 'remove rule' : c.kind === 'prefix_moved' ? `move rule to ${c.prefix}` : c.kind === 'prefix_released' ? 'release the old prefix of moved rule'
+ : c.kind === 'derived_released' ? 'stop keeping derived pages and facts to the readers of (raw only)' : c.kind === 'derived_covered' ? 'keep derived pages and facts to the readers of'
: c.kind === 'readers_removed' ? `remove readers ${(c.readers ?? []).map(reader).join(', ')} from` : `add readers ${(c.readers ?? []).map(reader).join(', ')} to`;
return ` ${what} ${c.rule} (${c.prefix}): ${c.narrowing ? 'narrowing, applies at once' : 'widening, held until gbrain access apply'}`;
}
@@ -243,7 +244,7 @@ async function ruleCmd(engine: BrainEngine, sub: string | undefined, args: strin
if (sub === 'add') {
const readers = flag(args, '--readers');
const slug = flag(args, '--slug');
- const r = normalizeRule({ ...(slug === undefined ? { prefix: flag(args, '--prefix') } : { slug, ...(flag(args, '--prefix') === undefined ? {} : { prefix: flag(args, '--prefix') }) }), readable_by: readers === undefined ? undefined : readers.split(',').map(s => s.trim()).filter(Boolean), ...(flag(args, '--id') ? { id: flag(args, '--id') } : {}) });
+ const r = normalizeRule({ ...(slug === undefined ? { prefix: flag(args, '--prefix') } : { slug, ...(flag(args, '--prefix') === undefined ? {} : { prefix: flag(args, '--prefix') }) }), readable_by: readers === undefined ? undefined : readers.split(',').map(s => s.trim()).filter(Boolean), ...(flag(args, '--id') ? { id: flag(args, '--id') } : {}), ...(args.includes('--raw-only') ? { covers_derived: false } : {}) });
if ('problem' in r) {
throw opError('access_rule_invalid', `The rule is invalid: ${r.problem}.`, 'Nothing was written. Example: gbrain access rule add --prefix partners/alice-example/ --readers alice-example,group:team-a');
}
@@ -252,7 +253,7 @@ async function ruleCmd(engine: BrainEngine, sub: string | undefined, args: strin
const clash = base.find(b => b.prefix === r.rule.prefix && b.id !== r.rule.id);
if (clash) throw opError('access_rule_invalid', `Rule "${clash.id}" already covers ${r.rule.prefix}.`, `Nothing was written. Change that rule's readers instead: gbrain access rule add --id ${clash.id} ${r.rule.prefix.endsWith('/') ? '--prefix' : '--slug'} ${r.rule.prefix} --readers <list>.`);
desired = sortRules([...base.filter(b => b.id !== r.rule.id), r.rule]);
- message = `access: rule ${r.rule.id} on ${r.rule.prefix} readable by ${r.rule.readable_by.map(reader).join(', ')}`;
+ message = `access: rule ${r.rule.id} on ${r.rule.prefix} readable by ${r.rule.readable_by.map(reader).join(', ')}${coversDerived(r.rule) ? '' : ' (raw only)'}`;
} else if (sub === 'rm') {
const id = positionals(args)[0];
if (!id) throw usageError('rule rm needs a rule id.', 'gbrain access rule rm <rule> --source <id> (gbrain access rule list shows the ids)');
@@ -348,8 +349,10 @@ async function applyCmd(engine: BrainEngine, args: string[], json: boolean): Pro
`Source ${sourceId}: ${p.desired ? `desired revision ${p.desired.revision} (${p.desired.origin}, by ${p.desired.proposed_by ?? '?'}, ${p.desired.created_at})` : 'no folder-rule revision'}`,
...(p.proposals.length ? [` Proposals not yet approved: ${p.proposals.map(x => `${x.revision} (${x.change_kind})`).join(', ')}`] : []),
...(p.widening.length ? p.widening.flatMap(w => [changeLine(w.change),
- ` ${w.pages} page(s) gain readers${w.sample.length ? `: ${w.sample.slice(0, 5).join(', ')}${w.pages > 5 ? ', ...' : ''}` : ''}`,
- ` Gaining access: ${w.gains === 'every_source_reader' ? 'every caller entitled to the source, unbound credentials included' : w.gains.join(', ') || 'no enabled member'}`])
+ w.lineage ? ` ${w.pages} page(s) under it stay kept to its readers, but their derived pages and facts stop being kept to them${w.sample.length ? `: ${w.sample.slice(0, 5).join(', ')}${w.pages > 5 ? ', ...' : ''}` : ''}`
+ : ` ${w.pages} page(s) gain readers${w.sample.length ? `: ${w.sample.slice(0, 5).join(', ')}${w.pages > 5 ? ', ...' : ''}` : ''}`,
+ w.lineage ? ' Gaining access to those derived pages and facts: whoever reads them (a summary of a raw-only page reads like any other page)'
+ : ` Gaining access: ${w.gains === 'every_source_reader' ? 'every caller entitled to the source, unbound credentials included' : w.gains.join(', ') || 'no enabled member'}`])
: [' Nothing is held: the applied rules already match.']),
...(p.plan_hash ? [`Nothing written; approve with gbrain access apply --source ${sourceId}${revision ? ` --revision ${revision}` : ''} --yes --expect ${p.plan_hash}`] : []),
]);
diff --git a/src/commands/access.ts b/src/commands/access.ts
index f01044c583..036c4911bb 100644
--- a/src/commands/access.ts
+++ b/src/commands/access.ts
@@ -22,7 +22,8 @@ import { sqlQueryForEngine } from '../core/sql-query.ts';
import { grantFromClient, type PrincipalGrant } from '../core/grants/model.ts';
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 { accessAllowedSql, folderRulesAllowedSql, isPrivacyPrivatePage, withCallerAccess } from '../core/search/private-visibility.ts';
+import { membersReadLineageOn, setMembersReadLineage } from '../core/access/lineage.ts';
import { folderAccessFor } from '../core/access/caller.ts';
import { identityFor, MEMBER_PAGE_PREFIX, normalizePrincipal, normalizeReaders } from '../core/access/principals.ts';
import { mayActForCovers, singleMemberAudience, type AudiencePrincipal } from '../core/access/audience.ts';
@@ -31,13 +32,16 @@ import { bindMemberSource, listMemberSources, unbindMemberSource } from '../core
import { clearOwner, ownerMemberId, ownerReadsRestrictedOn, ownerView, setOwner, setOwnerReadsRestricted, type OwnerView } from '../core/access/owner.ts';
import {
addGroup, addMember, assertAccessId, disableMember, enableMember, getMember, legacyTokenByName, listGroups, listMembers,
- parseIdList, previewRemoveGroup, previewRemoveMember, removeGroup, removeGroupMembers, removeMember, setMemberEmail, type MemberRecord,
+ parseIdList, previewRemoveGroup, previewRemoveMember, removeGroup, removeGroupMembers, removeMember, setMemberEmail, setMemberKind, type MemberRecord,
} from '../core/access/members.ts';
export const ACCESS_USAGE = `gbrain access: per-member read access inside one brain
Members and groups:
- gbrain access member add <id> [--name <display name>] [--email <addr>] [--groups a,b] [--bind-token <token name>]
+ gbrain access member add <id> [--name <display name>] [--email <addr>] [--groups a,b] [--bind-token <token name>] [--kind person|audience]
+ gbrain access member kind <id> person|audience
+ audience: a group chat or shared assistant; the owner reads its own
+ member page, older versions, derived pages and facts (person: default)
gbrain access member set <id> --email <addr>|none
Declare or clear the email an operator finds the member by
(case-folded, unique per brain)
@@ -72,6 +76,10 @@ Owner (one member who owns this brain; credentials bound to it read every page,
Off by default. On: the owner's credentials also read pages that
readers lists and folder or page rules keep to other members, and
their derived pages and facts (never another member's member page)
+ gbrain access members-read-lineage [on|off]
+ Off by default. On: a member's credential (speaking for itself) reads
+ derived pages and facts whose origins it reads, so summaries of a page
+ reach everyone that page lists
Serves several people (GST-363):
gbrain access serves One or several, and why (config access.serves, else 2+ enabled members)
@@ -81,8 +89,10 @@ Serves several people (GST-363):
bound to each member in a 0600 file under <config>/member-keys/
Folder rules (one rulebook per source; the database store on a repo-less source, .gbrain/access.yml on a git one):
- gbrain access rule add --prefix <folder/> | --slug <page> --readers a,group:b [--id <rule>] [--source <id>] [--yes]
- Preview first; narrowing applies at once
+ gbrain access rule add --prefix <folder/> | --slug <page> --readers a,group:b [--raw-only] [--id <rule>] [--source <id>] [--yes]
+ Preview first; narrowing applies at once. --raw-only: the rule keeps
+ its pages, not their derived pages and facts (transcripts; a widening
+ held for gbrain access apply when it changes an existing rule)
gbrain access rule rm <rule> [--source <id>] [--yes]
A widening: recorded and held until gbrain access apply
gbrain access rule list|status|history [--source <id>] [--operation <id>]
@@ -113,7 +123,7 @@ function flagValue(args: string[], name: string): string | undefined {
return v;
}
-const VALUE_FLAGS = new Set(['--name', '--groups', '--bind-token', '--members', '--members-file', '--source', '--token', '--client', '--as', '--qm', '--member', '--email']);
+const VALUE_FLAGS = new Set(['--name', '--groups', '--bind-token', '--members', '--members-file', '--source', '--token', '--client', '--as', '--qm', '--member', '--email', '--kind']);
function positionals(args: string[]): string[] {
const out: string[] = [];
@@ -125,7 +135,7 @@ function positionals(args: string[]): string[] {
}
function memberLine(m: MemberRecord): string {
- return ` ${m.id}${m.display_name ? ` (${m.display_name})` : ''} ${m.status}${m.email ? ` email: ${m.email}` : ''}${m.groups.length ? ` groups: ${m.groups.join(', ')}` : ''}`;
+ return ` ${m.id}${m.display_name ? ` (${m.display_name})` : ''} ${m.status} ${m.kind}${m.email ? ` email: ${m.email}` : ''}${m.groups.length ? ` groups: ${m.groups.join(', ')}` : ''}`;
}
export interface WhoCanReadEntry {
@@ -145,8 +155,12 @@ export async function whoCanRead(engine: BrainEngine, slug: string, sourceId?: s
if (!rows.length) {
throw opError('not_found', `No page "${slug}"${sourceId ? ` in source ${sourceId}` : ''}.`, 'Check the slug with gbrain list or gbrain search.');
}
- const optIn = await ownerReadsRestrictedOn(engine) ? await ownerMemberId(engine) : null;
- const members = await Promise.all((await listMembers(engine)).filter(m => m.status === 'enabled').map(async m => {
+ const ownerId = await ownerMemberId(engine);
+ const optIn = await ownerReadsRestrictedOn(engine) ? ownerId : null;
+ const memberLineage = await membersReadLineageOn(engine);
+ const enabled = (await listMembers(engine)).filter(m => m.status === 'enabled');
+ const audienceIds = enabled.filter(m => m.kind === 'audience').map(m => m.id);
+ const members = await Promise.all(enabled.map(async m => {
const identity = identityFor(m.id, m.groups);
return { id: m.id, identity, folder: await folderAccessFor(engine, identity) };
}));
@@ -164,17 +178,30 @@ export async function whoCanRead(engine: BrainEngine, slug: string, sourceId?: s
if (admitted.length) allowed.push(id);
}
}
+ const audiencePage = row.slug.startsWith(MEMBER_PAGE_PREFIX) && audienceIds.includes(row.slug.slice(MEMBER_PAGE_PREFIX.length));
const ownerOpened = !!optIn && (readers !== null || ruled) && !allowed.includes(optIn) && members.some(m => m.id === optIn)
- && (!row.slug.startsWith(MEMBER_PAGE_PREFIX) || row.slug === `${MEMBER_PAGE_PREFIX}${optIn}`);
+ && (!row.slug.startsWith(MEMBER_PAGE_PREFIX) || row.slug === `${MEMBER_PAGE_PREFIX}${optIn}` || audiencePage);
if (ownerOpened) allowed.push(optIn!);
+ const ownerRecord = members.find(m => m.id === ownerId);
+ const audienceOpened = audiencePage && !!ownerRecord && !allowed.includes(ownerRecord.id) && (readers !== null || ruled)
+ && (await withCallerAccess({ identity: ownerRecord.identity, ...ownerRecord.folder, restricted: true }, () => engine.executeRaw(
+ `SELECT 1 FROM pages p WHERE p.source_id = $1 AND p.slug = $2 AND ${folderRulesAllowedSql('p', ownerRecord.folder.satisfiedRuleIds)}`, [row.source_id, row.slug]))).length > 0;
+ if (audienceOpened) allowed.push(ownerRecord!.id);
+ const lineageRules = ruled ? await engine.executeRaw<{ n: number }>(
+ `SELECT count(*)::int AS n FROM unnest($1::text[]) AS x WHERE NOT EXISTS (SELECT 1 FROM access_rules r WHERE r.source_id = $2 AND x = $2 || ':' || r.rule_id AND NOT r.covers_derived)`,
+ [row.folder_rule_ids, row.source_id]) : [{ n: 0 }];
+ const closesLineage = readers !== null || Number(lineageRules[0]?.n ?? 0) > 0;
const notes = [
readers === null ? (ruled ? 'No readable_by, but folder rules cover it: only members who meet every rule read it remotely.' : 'No readable_by: every caller entitled to the source reads it.')
: readers.includes('!nobody') ? 'readable_by is malformed, so no remote caller reads it; fix the frontmatter.'
: 'Only credentials bound to these members (directly or through a group) read it remotely; unbound credentials and stdio do not.',
...(readers !== null && ruled ? ['Folder rules cover it too: a member must meet readable_by and every rule.'] : []),
...(priv ? ['visibility: private also applies: a member still needs private_pages: granted_sources on this source.'] : []),
- 'Derived pages (atoms, facts, chronicle events) of a page that names readers are hidden from every remote caller.',
+ !closesLineage && ruled ? 'Every rule covering it is raw only (covers_derived: false): its derived pages and facts are not kept to its readers; whoever reads a derived page reads it.'
+ : memberLineage && closesLineage ? 'Derived pages (atoms, facts, chronicle events) of it are read by the members listed here that read every origin (access.members_read_lineage is on, gbrain access members-read-lineage off turns it off) and by the owner when listed; every other remote caller gets not_found.'
+ : 'Derived pages (atoms, facts, chronicle events) of a page that names readers are hidden from every remote caller.',
...(ownerOpened ? [`The owner (${optIn}) reads it too, and its derived pages and facts: access.owner_reads_restricted is on (gbrain access owner reads-restricted off turns it off).`] : []),
+ ...(audienceOpened || (audiencePage && ownerOpened) ? [`It is the member page of an audience member (gbrain access member kind), so the owner (${ownerId}) reads it, its older versions, its derived pages and its facts as if it named the owner.`] : []),
];
entries.push({ slug: row.slug, source_id: row.source_id, readers, private: priv, members: readers === null && !ruled ? 'every_source_reader' : allowed, note: notes.join(' ') });
}
@@ -184,7 +211,7 @@ export async function whoCanRead(engine: BrainEngine, slug: string, sourceId?: s
export interface AccessCheckResult {
credential: { kind: 'token' | 'client'; id: string; name: string };
grant: { scopes: string[]; sources: PrincipalGrant['sources']; takes_holders: string[] | null; private_pages: PrincipalGrant['privatePages']; operations: string[] | 'unrestricted'; revision: number };
- member: { id: string; status: MemberRecord['status'] | 'missing'; groups: string[] } | null;
+ member: { id: string; status: MemberRecord['status'] | 'missing'; groups: string[]; kind?: MemberRecord['kind'] } | null;
identity: string[];
may_act_for: string[] | null;
verdict: 'reads_as_member' | 'unbound' | 'refused';
@@ -192,6 +219,8 @@ export interface AccessCheckResult {
owner: boolean;
/** GST-2490: access.owner_reads_restricted is on, so the owner's credentials read past readers lists and rules. */
owner_reads_restricted: boolean;
+ /** GBRA-108 design 3: access.members_read_lineage is on, so a member's reads pass derived pages and facts whose origins it reads. */
+ members_read_lineage: boolean;
explanation: string;
audience?: Array<{ principal: string; covered_by_may_act_for: boolean }>;
}
@@ -216,7 +245,7 @@ export async function accessCheck(engine: BrainEngine, target: { token?: string;
}
const boundId = typeof row.member_id === 'string' ? row.member_id : null;
const rec = boundId ? await getMember(engine, boundId) : null;
- const member = boundId ? { id: boundId, status: rec?.status ?? 'missing' as const, groups: rec?.groups ?? [] } : null;
+ const member = boundId ? { id: boundId, status: rec?.status ?? 'missing' as const, groups: rec?.groups ?? [], ...(rec ? { kind: rec.kind } : {}) } : null;
const live = member?.status === 'enabled';
const identity = live ? identityFor(member!.id, member!.groups) : [];
const mayActFor = Array.isArray(row.may_act_for) ? (row.may_act_for as string[]) : null;
@@ -224,18 +253,22 @@ export async function accessCheck(engine: BrainEngine, target: { token?: string;
const ownerId = await ownerMemberId(engine);
const owner = live && member!.id === ownerId;
const ownerReadsRestricted = !!ownerId && await ownerReadsRestrictedOn(engine);
+ const memberLineage = await membersReadLineageOn(engine);
const explanation = verdict === 'unbound' ? 'Bound to no member: reads every page its grant allows except pages that name readers (readable_by).'
: verdict === 'refused' ? `Bound to member "${member!.id}", which is ${member!.status}: the credential is refused at verification (access_member_disabled).`
: `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: the brain owner (${ownerId}) also reads the pages this credential's readers lists and rules keep to it, except its 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.`) : '')
+ + (owner ? ' In reads it also reads derived pages and facts whose origins it reads.'
+ : memberLineage ? ' access.members_read_lineage is on: in reads, speaking for itself, it also reads derived pages and facts whose origins it reads.' : '')
+ + (rec?.kind === 'audience' ? ` It is an audience member (a group chat or shared assistant)${ownerId && !owner ? `: the brain owner (${ownerId}) reads its own member page, older versions, derived pages and facts as if they named the owner` : ''}.` : '');
const result: AccessCheckResult = {
credential,
grant: { scopes: grant.scopes, sources: grant.sources, takes_holders: grant.takesHolders, private_pages: grant.privatePages,
operations: grant.allowedOperations ?? 'unrestricted', revision: grant.revision },
- member, identity, may_act_for: mayActFor, verdict, owner, owner_reads_restricted: ownerReadsRestricted, explanation,
+ member, identity, may_act_for: mayActFor, verdict, owner, owner_reads_restricted: ownerReadsRestricted, members_read_lineage: memberLineage, explanation,
};
if (target.as !== undefined) {
const audience: NonNullable<AccessCheckResult['audience']> = [];
@@ -267,12 +300,20 @@ async function memberCmd(engine: BrainEngine, sub: string | undefined, args: str
const id = positionals(args)[0];
switch (sub) {
case 'add': {
- const r = await addMember(engine, id, { name: flagValue(args, '--name'), email: flagValue(args, '--email'), groups: parseIdList(flagValue(args, '--groups'), 'group'), bindToken: flagValue(args, '--bind-token') });
+ const r = await addMember(engine, id, { name: flagValue(args, '--name'), email: flagValue(args, '--email'), groups: parseIdList(flagValue(args, '--groups'), 'group'), bindToken: flagValue(args, '--bind-token'), kind: flagValue(args, '--kind'), remote: false });
return print(json, r, () => [`Member added: ${r.member.id}`, memberLine(r.member),
...(r.groups_created.length ? [` Groups created: ${r.groups_created.join(', ')}`] : []),
...(r.bound ? [` Bound token: ${r.bound.name} (${r.bound.id})`] : [' Bind a credential: gbrain auth rescope --token <name> --member ' + r.member.id]),
`Preview what it reads: gbrain search "<query>" --as ${r.member.id}`]);
}
+ case 'kind': {
+ const kind = positionals(args)[1];
+ if (kind !== 'person' && kind !== 'audience') throw usageError('access member kind needs a member id and person or audience.', 'gbrain access member kind <id> person|audience');
+ const r = await setMemberKind(engine, id, kind, { remote: false });
+ return print(json, r, () => [`${r.changed ? 'Member updated' : 'Unchanged'}: ${r.member.id}`, memberLine(r.member),
+ r.member.kind === 'audience' ? 'The brain owner reads its own member page, older versions, derived pages and facts as if they named the owner. gbrain access member kind ' + r.member.id + ' person undoes this.'
+ : 'A person: the owner reads its member page only when listed.']);
+ }
case 'disable':
case 'enable': {
const m = await (sub === 'disable' ? disableMember : enableMember)(engine, id);
@@ -306,7 +347,7 @@ async function memberCmd(engine: BrainEngine, sub: string | undefined, args: str
case 'source':
return memberSourceCmd(engine, args, json);
default:
- throw usageError(`Unknown access member subcommand: ${sub ?? '(none)'}.`, 'Use add, set, disable, enable, rm, list, link, unlink, links or source (gbrain access --help).');
+ throw usageError(`Unknown access member subcommand: ${sub ?? '(none)'}.`, 'Use add, set, kind, disable, enable, rm, list, link, unlink, links or source (gbrain access --help).');
}
}
@@ -444,6 +485,14 @@ export async function runAccess(engine: BrainEngine, args: string[]): Promise<vo
switch (cmd) {
case 'member': return await memberCmd(engine, rest[0], rest.slice(1), json);
case 'owner': return await ownerCmd(engine, rest[0], rest.slice(1), json);
+ case 'members-read-lineage': {
+ const value = positionals(rest)[0];
+ if (value !== undefined && value !== 'on' && value !== 'off') throw usageError('access members-read-lineage takes on or off.', 'gbrain access members-read-lineage [on|off]');
+ const v = value === undefined ? { members_read_lineage: await membersReadLineageOn(engine) } : await setMembersReadLineage(engine, value === 'on', { remote: false });
+ return print(json, v, () => [v.members_read_lineage
+ ? 'Members read lineage: on (access.members_read_lineage). A member\'s credential speaking for itself reads derived pages and facts whose origins it reads, so summaries of a page reach everyone that page lists. Turn off: gbrain access members-read-lineage off'
+ : 'Members read lineage: off. Derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner. Turn on: gbrain access members-read-lineage on']);
+ }
case 'serves': return await runAccessServes(engine, positionals(rest)[0], rest, json, flagValue);
case 'group': return await groupCmd(engine, rest[0], rest.slice(1), json);
case 'who-can-read': {
@@ -470,7 +519,7 @@ export async function runAccess(engine: BrainEngine, args: string[]): Promise<vo
` ${r.explanation}`]);
}
default:
- throw usageError(`Unknown access subcommand: ${cmd}.`, 'Use member, owner, serves, group, rule, apply, resume, who-can-read or check (gbrain access --help).', { code: 'unknown_command' });
+ throw usageError(`Unknown access subcommand: ${cmd}.`, 'Use member, owner, members-read-lineage, serves, group, rule, apply, resume, who-can-read or check (gbrain access --help).', { code: 'unknown_command' });
}
} catch (e) {
exitCliError(e, 'access');
diff --git a/src/commands/doctor/checks/access-lineage.ts b/src/commands/doctor/checks/access-lineage.ts
new file mode 100644
index 0000000000..cbe3714a2c
--- /dev/null
+++ b/src/commands/doctor/checks/access-lineage.ts
@@ -0,0 +1,72 @@
+/**
+ * GBRA-108 access designs doctor checks (all operator settings, off by default):
+ *
+ * - access_raw_only_rules: every folder or page rule stored with covers_derived false. Such a rule keeps the pages it
+ * covers to its readers, but the pages and facts derived from them are read by whoever reads those derivatives, so a
+ * summary of a raw-only transcript is not kept to the transcript's readers. Listed so a raw-only rule over a folder
+ * whose content is itself the secret is caught.
+ * - access_audience_members: every enabled member of kind audience (a group chat, a shared assistant). The brain owner
+ * reads each one's own member page, older versions, derived pages and facts as if they named the owner.
+ * - access_members_read_lineage: config access.members_read_lineage is on, so a member's credential reads derived pages
+ * and facts whose origins it reads (summaries of a page reach everyone that page lists).
+ *
+ * Each is informational: not applicable when its setting is unused, and an ok with the list when it is in use.
+ */
+import type { Check } from '../../doctor.ts';
+import { checkError, infoCheck } from '../check-fix.ts';
+import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';
+import { membersReadLineageOn } from '../../../core/access/lineage.ts';
+
+async function rawOnlyRules(ctx: DoctorContext): Promise<Omit<Check, 'name'>> {
+ const name = 'access_raw_only_rules';
+ try {
+ const rows = await connectedEngine(ctx).executeRaw<{ source_id: string; rule_id: string; prefix: string }>(
+ 'SELECT source_id, rule_id, prefix FROM access_rules WHERE NOT covers_derived ORDER BY source_id, rule_id');
+ if (!rows.length) return infoCheck(name, 'Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).', 'not_applicable');
+ const rules = rows.map(r => `${r.source_id}:${r.rule_id} (${r.prefix})`);
+ return infoCheck(name, `${rows.length} raw-only rule(s) keep their pages to their readers, but not the pages and facts derived from them: whoever reads a summary of such a page reads it. Use raw-only rules for transcripts and similar raw material, never for a folder whose content is itself the secret: ${rules.slice(0, 10).join(', ')}${rows.length > 10 ? ', ...' : ''}. Turn one back: gbrain access rule add --id <rule> --prefix <folder/> --readers <list> (without --raw-only).`, 'ok', undefined, { rules: rows });
+ } catch (error) {
+ return checkError(name, `run ${name}`, error);
+ }
+}
+
+async function audienceMembers(ctx: DoctorContext): Promise<Omit<Check, 'name'>> {
+ const name = 'access_audience_members';
+ try {
+ const ids = (await connectedEngine(ctx).executeRaw<{ id: string }>(
+ "SELECT id FROM access_members WHERE kind = 'audience' AND disabled_at IS NULL AND tombstoned_at IS NULL ORDER BY id")).map(r => r.id);
+ if (!ids.length) return infoCheck(name, 'Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).', 'not_applicable');
+ return infoCheck(name, `${ids.length} audience member(s) (a group chat or shared assistant): the brain owner reads each one's own member page, older versions, derived pages and facts as if they named the owner: ${ids.join(', ')}. Undo with gbrain access member kind <id> person.`, 'ok', undefined, { members: ids });
+ } catch (error) {
+ return checkError(name, `run ${name}`, error);
+ }
+}
+
+async function membersReadLineage(ctx: DoctorContext): Promise<Omit<Check, 'name'>> {
+ const name = 'access_members_read_lineage';
+ try {
+ if (!(await membersReadLineageOn(connectedEngine(ctx)))) {
+ return infoCheck(name, 'Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.', 'not_applicable');
+ }
+ return infoCheck(name, 'access.members_read_lineage is on: a member\'s credential speaking for itself reads derived pages and facts whose origins it reads, so summaries of a page reach everyone that page lists. Every remote caller\'s whoami reports it. Turn it off with gbrain access members-read-lineage off.', 'ok');
+ } catch (error) {
+ return checkError(name, `run ${name}`, error);
+ }
+}
+
+async function runAccessLineage(ctx: DoctorContext): Promise<Check[]> {
+ const checks: Check[] = [];
+ const { name: _raw, ...raw } = await rawOnlyRules(ctx) as Check;
+ checks.push({ name: 'access_raw_only_rules', ...raw });
+ const { name: _audience, ...audience } = await audienceMembers(ctx) as Check;
+ checks.push({ name: 'access_audience_members', ...audience });
+ const { name: _lineage, ...lineage } = await membersReadLineage(ctx) as Check;
+ checks.push({ name: 'access_members_read_lineage', ...lineage });
+ return checks;
+}
+
+export const accessLineageEntry: DoctorEntry = {
+ name: 'access_raw_only_rules',
+ emits: ['access_raw_only_rules', 'access_audience_members', 'access_members_read_lineage'],
+ run: runAccessLineage,
+};
diff --git a/src/commands/doctor/registry.ts b/src/commands/doctor/registry.ts
index 5f96d2073c..7164278b1d 100644
--- a/src/commands/doctor/registry.ts
+++ b/src/commands/doctor/registry.ts
@@ -144,6 +144,7 @@ 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 { accessLineageEntry } from './checks/access-lineage.ts';
import { attestReadAccessEntry } from './checks/attest-read-access.ts';
import { originTwinsEntry } from './checks/origin-twins.ts';
import { slugPathMismatchEntry } from './checks/slug-path-mismatch.ts';
@@ -231,6 +232,7 @@ export const DOCTOR_CHECK_REGISTRY: readonly DoctorEntry[] = [
unlabeledPeopleFoldersEntry,
sharedAgentAccessEntry,
ownerReadsRestrictedEntry,
+ accessLineageEntry,
attestReadAccessEntry,
rlsEntry,
postgresTlsEntry,
diff --git a/src/core/access/caller.ts b/src/core/access/caller.ts
index 6a8fe9087a..2034fde5ab 100644
--- a/src/core/access/caller.ts
+++ b/src/core/access/caller.ts
@@ -22,7 +22,7 @@ import { hostOnlyError } from '../ops/op-fix.ts';
import { currentCallerAccess } from '../search/private-visibility.ts';
import { edgeTrimSql } from '../edge-whitespace.ts';
import { GUEST, STDIO_MAY_ACT_FOR_KEY, mayActForCovers, singleMemberAudience, type AudiencePrincipal } from './audience.ts';
-import { parseMayActFor } from './members.ts';
+import { audienceMemberIds, parseMayActFor } from './members.ts';
/** Config key binding a local stdio MCP server to one member. */
export const STDIO_MEMBER_KEY = 'mcp.stdio_member';
@@ -208,6 +208,9 @@ export async function resolveAudienceIdentities(engine: Pick<BrainEngine, 'execu
* 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.
+ * GBRA-108: under access.members_read_lineage a read by any other member speaking for itself (no audience, or an
+ * audience of that one member) gets the same lineage (design 3), and an owner read carries the audience members
+ * (design 2). Never an audience of several, a group or a guest, and never an unbound credential (no member identity).
*/
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)]);
@@ -217,6 +220,7 @@ export async function remoteCallerAccess(engine: BrainEngine, auth: AuthInfo | u
const single = singleMemberAudience(audience);
const owner = single && audience[0] === `member:${remotePolicy.ownerMember}`
&& isOwner(await boundIdentity(engine, auth, transport, stdioMember), remotePolicy);
+ const lineage = readOnly && single && identities.length === 1 && (owner || remotePolicy.membersReadLineage === true);
return {
identity: identities.length === 1 ? identities[0]! : [],
audience: [...audience],
@@ -225,8 +229,9 @@ export async function remoteCallerAccess(engine: BrainEngine, auth: AuthInfo | u
privateReadableSources: single ? privateSources ?? [] : [],
hidePrivate: single ? !relaxed && !owner : true,
owner,
- ownerLineage: owner && readOnly,
- ownerReadsRestricted: owner && readOnly && remotePolicy.ownerReadsRestricted === true,
+ lineage,
+ ownerReadsRestricted: owner && lineage && remotePolicy.ownerReadsRestricted === true,
+ audienceKindMembers: owner && lineage ? await audienceMemberIds(engine) : [],
applyRemoteReadPolicy: false,
restricted,
remotePolicy,
@@ -234,6 +239,7 @@ export async function remoteCallerAccess(engine: BrainEngine, auth: AuthInfo | u
}
const identity = restricted || remotePolicy.ownerMember ? await boundIdentity(engine, auth, transport, stdioMember) : [];
const owner = isOwner(identity, remotePolicy);
+ const lineage = readOnly && identity.some(p => p.startsWith('member:')) && (owner || remotePolicy.membersReadLineage === true);
return {
identity,
audience: null,
@@ -242,8 +248,9 @@ export async function remoteCallerAccess(engine: BrainEngine, auth: AuthInfo | u
privateReadableSources: privateSources ?? [],
hidePrivate: !relaxed && !owner,
owner,
- ownerLineage: owner && readOnly,
- ownerReadsRestricted: owner && readOnly && remotePolicy.ownerReadsRestricted === true,
+ lineage,
+ ownerReadsRestricted: owner && lineage && remotePolicy.ownerReadsRestricted === true,
+ audienceKindMembers: owner && lineage ? await audienceMemberIds(engine) : [],
applyRemoteReadPolicy: false,
restricted,
remotePolicy,
diff --git a/src/core/access/folder-rules.ts b/src/core/access/folder-rules.ts
index ef6317169e..c1773940a9 100644
--- a/src/core/access/folder-rules.ts
+++ b/src/core/access/folder-rules.ts
@@ -11,6 +11,9 @@
* readable_by: [alice-example, group:team-a]
* - slug: projects # a page rule: exactly this one slug (GST-2462)
* readable_by: [alice-example]
+ * - prefix: transcripts/ # a raw-only rule: keeps these pages to its readers, but not
+ * readable_by: [alice-example] # the pages and facts derived from them (covers_derived, default true)
+ * covers_derived: false
*
* A prefix is matched literally against the source's slugs (never LIKE): it is
* lower case, built of segments that start with a letter or digit, ends in
@@ -25,7 +28,8 @@
* classifyRulebook() compares the applied rulebook with a desired one rule by
* rule: an added rule and removed readers narrow and apply at once; a removed
* rule and added readers widen and wait for an operator's
- * `gbrain access apply --yes`. A moved prefix is both: the rule applies at its
+ * `gbrain access apply --yes`. Turning covers_derived off (a rule stops closing its pages' lineage) widens; turning it
+ * back on narrows. A moved prefix is both: the rule applies at its
* new prefix at once, and its old prefix keeps the old readers under a held
* rule (heldRuleId) whose release waits for apply. Its target (what is applied
* now) is never wider than the applied rulebook: a rule whose readers both lose
@@ -41,6 +45,11 @@ export interface FolderRule {
prefix: string;
/** Sorted, distinct normalized principals; empty means readable by nobody (an applied intersection only). */
readable_by: string[];
+ /**
+ * Raw-only rules: false when the rule keeps its pages to its readers but no longer closes the lineage of the pages
+ * and facts derived from them. Absent means true (every rule written before it existed); only false is carried.
+ */
+ covers_derived?: false;
}
export interface PolicyProblem {
@@ -58,7 +67,7 @@ export const MAX_RULES = 256;
const MAX_READERS = 256;
const PREFIX_RE = /^(?:[a-z0-9][a-z0-9._-]*\/)+$/;
const SLUG_RE = /^(?:[a-z0-9][a-z0-9._-]*\/)*[a-z0-9][a-z0-9._-]*$/;
-const RULE_KEYS = new Set(['id', 'prefix', 'slug', 'readable_by']);
+const RULE_KEYS = new Set(['id', 'prefix', 'slug', 'readable_by', 'covers_derived']);
/** A stored rule prefix the grammar accepts: a folder (ends in '/') or one page's exact slug. Also safe to embed as an SQL literal: no quote or backslash. */
export function validPrefix(prefix: string): boolean {
@@ -131,13 +140,14 @@ export function normalizeRule(raw: unknown): { rule: FolderRule } | { problem: s
if (entry.slug !== undefined && entry.prefix !== undefined) return { problem: 'a rule has prefix (a folder) or slug (one page), not both' };
const prefixError = entry.slug !== undefined ? slugProblem(entry.slug) : prefixProblem(entry.prefix);
const prefix = prefixError ? undefined : (entry.slug ?? entry.prefix) as string;
- if (unknown.length) return { problem: `unknown key ${unknown.map(k => JSON.stringify(k)).join(', ')}; a rule has id, prefix or slug, and readable_by`, prefix };
+ if (unknown.length) return { problem: `unknown key ${unknown.map(k => JSON.stringify(k)).join(', ')}; a rule has id, prefix or slug, readable_by and an optional covers_derived`, prefix };
if (prefixError) return { problem: prefixError };
const readers = readersOf(entry.readable_by);
if ('problem' in readers) return { problem: readers.problem, prefix };
const id = entry.id === undefined ? ruleIdForPrefix(prefix!) : entry.id;
if (typeof id !== 'string' || !ACCESS_ID_RE.test(id)) return { problem: `id ${JSON.stringify(id)} is not a rule id (lower-case letters, digits, '.', '_' and '-', 1-64 characters)`, prefix };
- return { rule: { id, prefix: prefix!, readable_by: readers.readers } };
+ if (entry.covers_derived !== undefined && typeof entry.covers_derived !== 'boolean') return { problem: `covers_derived must be true or false (found ${JSON.stringify(entry.covers_derived)})`, prefix };
+ return { rule: { id, prefix: prefix!, readable_by: readers.readers, ...(entry.covers_derived === false ? { covers_derived: false as const } : {}) } };
}
/** Rules sorted by id with duplicate ids or prefixes reported. */
@@ -208,7 +218,13 @@ export function parsePolicyYaml(text: string): ParsedPolicy {
}
export function sortRules(rules: readonly FolderRule[]): FolderRule[] {
- return [...rules].map(r => ({ id: r.id, prefix: r.prefix, readable_by: [...new Set(r.readable_by)].sort() })).sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
+ return [...rules].map(r => ({ id: r.id, prefix: r.prefix, readable_by: [...new Set(r.readable_by)].sort(), ...(r.covers_derived === false ? { covers_derived: false as const } : {}) }))
+ .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
+}
+
+/** Whether a rule closes the lineage of the pages and facts derived from the pages it covers (covers_derived, default true). */
+export function coversDerived(rule: Pick<FolderRule, 'covers_derived'>): boolean {
+ return rule.covers_derived !== false;
}
/** The file text for a rulebook: the same grammar parsePolicyYaml reads, members written bare. */
@@ -221,13 +237,14 @@ export function serializePolicyYaml(rules: readonly FolderRule[], comment?: stri
lines.push('rules:');
for (const r of sorted) {
lines.push(` - id: ${plain(r.id)}`, r.prefix.endsWith('/') ? ` prefix: ${plain(r.prefix)}` : ` slug: ${plain(r.prefix)}`, ` readable_by: [${r.readable_by.map(reader).join(', ')}]`);
+ if (!coversDerived(r)) lines.push(' covers_derived: false');
}
return [...lines, ''].join('\n');
}
-/** A content digest of a rulebook (sha256 over its canonical JSON); equal rulebooks have equal digests. */
+/** A content digest of a rulebook (sha256 over its canonical JSON); equal rulebooks have equal digests. A rule that covers derived pages hashes as it did before covers_derived existed. */
export function rulebookDigest(rules: readonly FolderRule[]): string {
- return createHash('sha256').update(JSON.stringify(sortRules(rules).map(r => [r.id, r.prefix, r.readable_by]))).digest('hex');
+ return createHash('sha256').update(JSON.stringify(sortRules(rules).map(r => coversDerived(r) ? [r.id, r.prefix, r.readable_by] : [r.id, r.prefix, r.readable_by, false]))).digest('hex');
}
/** Rules read back from a stored JSON value (revisions, exports); anything malformed is refused, never repaired. */
@@ -237,14 +254,15 @@ export function rulesFromJson(value: unknown): FolderRule[] {
return sortRules(raw.map(r => {
const rule = r as FolderRule;
if (!rule || typeof rule.id !== 'string' || !ACCESS_ID_RE.test(rule.id) || typeof rule.prefix !== 'string' || !validPrefix(rule.prefix)
- || !Array.isArray(rule.readable_by) || !rule.readable_by.every(p => typeof p === 'string' && normalizePrincipal(p) === p)) {
+ || !Array.isArray(rule.readable_by) || !rule.readable_by.every(p => typeof p === 'string' && normalizePrincipal(p) === p)
+ || (rule.covers_derived !== undefined && typeof rule.covers_derived !== 'boolean')) {
throw new Error('stored rulebook holds a malformed rule');
}
return rule;
}));
}
-export type ChangeKind = 'added' | 'removed' | 'readers_removed' | 'readers_added' | 'prefix_moved' | 'prefix_released';
+export type ChangeKind = 'added' | 'removed' | 'readers_removed' | 'readers_added' | 'prefix_moved' | 'prefix_released' | 'derived_released' | 'derived_covered';
const HELD_RULE_RE = /\.held-[0-9a-f]{8}$/;
@@ -281,7 +299,7 @@ export function classifyRulebook(applied: readonly FolderRule[], desired: readon
const b = before.get(id);
if (!b) { target.push(a); changes.push({ rule: id, kind: 'added', narrowing: true, prefix: a.prefix }); continue; }
if (b.prefix !== a.prefix) {
- const held = { id: heldRuleId(id, b.prefix), prefix: b.prefix, readable_by: b.readable_by };
+ const held = { id: heldRuleId(id, b.prefix), prefix: b.prefix, readable_by: b.readable_by, ...(coversDerived(b) ? {} : { covers_derived: false as const }) };
if (before.has(held.id) || after.has(held.id)) { target.push(b); changes.push({ rule: id, kind: 'prefix_moved', narrowing: false, prefix: a.prefix }); continue; }
target.push(a, held);
changes.push({ rule: id, kind: 'prefix_moved', narrowing: true, prefix: a.prefix }, { rule: held.id, kind: 'prefix_released', narrowing: false, prefix: b.prefix });
@@ -289,9 +307,12 @@ export function classifyRulebook(applied: readonly FolderRule[], desired: readon
}
const removed = b.readable_by.filter(p => !a.readable_by.includes(p));
const added = a.readable_by.filter(p => !b.readable_by.includes(p));
- target.push({ id, prefix: b.prefix, readable_by: b.readable_by.filter(p => a.readable_by.includes(p)) });
+ const rawOnly = !coversDerived(b) && !coversDerived(a);
+ target.push({ id, prefix: b.prefix, readable_by: b.readable_by.filter(p => a.readable_by.includes(p)), ...(rawOnly ? { covers_derived: false as const } : {}) });
if (removed.length) changes.push({ rule: id, kind: 'readers_removed', narrowing: true, prefix: b.prefix, readers: removed });
if (added.length) changes.push({ rule: id, kind: 'readers_added', narrowing: false, prefix: b.prefix, readers: added });
+ if (coversDerived(b) && !coversDerived(a)) changes.push({ rule: id, kind: 'derived_released', narrowing: false, prefix: b.prefix });
+ if (!coversDerived(b) && coversDerived(a)) changes.push({ rule: id, kind: 'derived_covered', narrowing: true, prefix: b.prefix });
}
for (const [id, b] of before) {
if (after.has(id)) continue;
diff --git a/src/core/access/lineage.ts b/src/core/access/lineage.ts
new file mode 100644
index 0000000000..77de335e22
--- /dev/null
+++ b/src/core/access/lineage.ts
@@ -0,0 +1,44 @@
+/**
+ * GBRA-108 design 3: listed members read lineage. With config access.members_read_lineage on ('1'; off by default and
+ * unchanged on upgrade), a read by a credential bound to one member speaking for itself (or for an audience of exactly
+ * that member) passes a derived page (an atom, a synthesized concept or question, a Life Chronicle event, a
+ * derived_from page) or a fact when that member reads every origin of it, as an owner read does (CallerAccess.lineage,
+ * search/private-visibility.ts). Never an audience of several, an unbound credential or an attested call, and never a
+ * write. The owner opt-in (access.owner_reads_restricted) stays the owner's alone. Everything lives in the database, so
+ * a repo-less brain gets it unchanged. Only the trusted local operator sets it.
+ */
+import type { BrainEngine } from '../engine.ts';
+import { MEMBERS_READ_LINEAGE_KEY } from '../search/private-visibility.ts';
+import { hostOnlyError } from '../ops/op-fix.ts';
+
+export const MEMBERS_READ_LINEAGE_NOTE = 'Members read derived pages and facts of the pages listed to them: access.members_read_lineage is on, so a summary, atom, chronicle event or fact made from a page reaches every member that page lists. The brain operator set this.';
+
+/** Is access.members_read_lineage on? Unset, anything but '1', or unreadable is off (nothing widens). */
+export async function membersReadLineageOn(engine: Pick<BrainEngine, 'getConfig'>): Promise<boolean> {
+ try {
+ return (await engine.getConfig(MEMBERS_READ_LINEAGE_KEY))?.trim() === '1';
+ } catch {
+ return false;
+ }
+}
+
+/** What whoami adds for every remote caller while the setting is on; empty otherwise. */
+export async function membersReadLineageNotice(engine: Pick<BrainEngine, 'getConfig'>): Promise<{ members_read_lineage?: true; members_read_lineage_note?: string }> {
+ return await membersReadLineageOn(engine) ? { members_read_lineage: true, members_read_lineage_note: MEMBERS_READ_LINEAGE_NOTE } : {};
+}
+
+/**
+ * Turns the setting 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.
+ */
+export async function setMembersReadLineage(engine: BrainEngine, on: boolean, ctx: { remote?: boolean }): Promise<{ members_read_lineage: boolean }> {
+ if (ctx.remote !== false) {
+ throw hostOnlyError({ remote: true, transport: 'http' }, 'permission_denied',
+ 'Only the brain operator on the brain host turns members-read-lineage on or off, so nothing was changed.',
+ ['gbrain', 'access', 'members-read-lineage', on ? 'on' : 'off'],
+ 'Lets every member read the derived pages and facts of the pages listed to it. Whether summaries of a page reach everyone that page lists is the brain operator\'s decision, never an agent\'s.');
+ }
+ if (on) await engine.setConfig(MEMBERS_READ_LINEAGE_KEY, '1');
+ else await engine.unsetConfig(MEMBERS_READ_LINEAGE_KEY);
+ return { members_read_lineage: await membersReadLineageOn(engine) };
+}
diff --git a/src/core/access/member-facts.ts b/src/core/access/member-facts.ts
index 3738c0d799..8cf196ddc8 100644
--- a/src/core/access/member-facts.ts
+++ b/src/core/access/member-facts.ts
@@ -195,7 +195,8 @@ 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.ownerLineage ? { owner_reads: access.ownerReadsRestricted ? 'restricted' : 'lineage' } : {}) };
+ ...(access.lineage ? { owner_reads: access.owner ? (access.ownerReadsRestricted ? 'restricted' : 'lineage') : 'member_lineage' } : {}),
+ ...(access.audienceKindMembers.length ? { audience_kind: access.audienceKindMembers } : {}) };
return createHash('sha256').update(JSON.stringify(parts)).digest('hex').slice(0, 16);
}
diff --git a/src/core/access/members.ts b/src/core/access/members.ts
index 543336ed93..1c87d2277b 100644
--- a/src/core/access/members.ts
+++ b/src/core/access/members.ts
@@ -14,10 +14,16 @@
* GST-1158: a member may carry one operator-declared email (case-folded,
* unique per brain), only so the operator can find the member when linking a
* trusted system's id (`memberByEmail`). It never creates a member or a link.
+ *
+ * Audience members (GBRA-108 design 2): a member's kind is `person` (the default) or `audience` (a group chat, a
+ * shared assistant). An owner read treats an audience member's own member page, its older versions, its derived pages
+ * and its facts as if its readers named the owner (search/private-visibility.ts). Only the trusted local operator
+ * sets it (`gbrain access member kind`, `member add --kind`); a remote caller is refused.
*/
import type { BrainEngine } from '../engine.ts';
import type { SqlQuery } from '../sql-query.ts';
import { opError, type OperationError } from '../ops/contract.ts';
+import { hostOnlyError } from '../ops/op-fix.ts';
import type { Action } from '../agent-output.ts';
import { ACCESS_ID_RE, identityFor, normalizePrincipal } from './principals.ts';
import { ACTOR_DEFERRED_OPS, DEFAULT_ATTEST_OPS } from './actor-model.ts';
@@ -28,10 +34,15 @@ export interface MemberRecord {
display_name: string | null;
email: string | null;
status: 'enabled' | 'disabled' | 'removed';
+ /** GBRA-108 design 2: person (the default) or audience (a group chat, a shared assistant; the owner reads its member page). */
+ kind: MemberKind;
groups: string[];
created_at: string | null;
}
+export type MemberKind = 'person' | 'audience';
+export const MEMBER_KINDS: readonly MemberKind[] = ['person', 'audience'];
+
export interface CredentialRef { kind: 'token' | 'client'; id: string; name: string }
export interface PageRef { slug: string; source_id: string }
@@ -95,12 +106,13 @@ function toRecord(row: Record<string, unknown>): MemberRecord {
display_name: (row.display_name as string | null) ?? null,
email: (row.email as string | null) ?? null,
status: row.tombstoned_at != null ? 'removed' : row.disabled_at != null ? 'disabled' : 'enabled',
+ kind: row.kind === 'audience' ? 'audience' : 'person',
groups: Array.isArray(row.groups) ? (row.groups as string[]) : [],
created_at: iso(row.created_at),
};
}
-const MEMBER_SELECT = `SELECT m.id, m.display_name, m.email, m.disabled_at, m.tombstoned_at, m.created_at,
+const MEMBER_SELECT = `SELECT m.id, m.display_name, m.email, m.kind, m.disabled_at, m.tombstoned_at, m.created_at,
COALESCE(array_agg(g.group_id ORDER BY g.group_id) FILTER (WHERE g.group_id IS NOT NULL), '{}') AS groups
FROM access_members m LEFT JOIN access_group_members g ON g.member_id = m.id`;
@@ -190,8 +202,10 @@ export async function legacyTokenByName(engine: BrainEngine, name: string): Prom
export interface AddMemberResult { member: MemberRecord; groups_created: string[]; bound: CredentialRef | null }
-export async function addMember(engine: BrainEngine, rawId: unknown, opts: { name?: string; email?: unknown; groups?: readonly string[]; bindToken?: string } = {}): Promise<AddMemberResult> {
+export async function addMember(engine: BrainEngine, rawId: unknown, opts: { name?: string; email?: unknown; groups?: readonly string[]; bindToken?: string; kind?: unknown; remote?: boolean } = {}): Promise<AddMemberResult> {
const id = assertAccessId(rawId);
+ const kind = opts.kind === undefined ? 'person' : assertMemberKind(opts.kind);
+ if (kind !== 'person') assertLocalKindChange(opts, id, kind);
const groups = (opts.groups ?? []).map(g => assertAccessId(g, 'group'));
const email = opts.email === undefined ? null : assertMemberEmail(opts.email);
const existing = await getMember(engine, id);
@@ -208,7 +222,7 @@ export async function addMember(engine: BrainEngine, rawId: unknown, opts: { nam
const bindTarget = opts.bindToken ? await legacyTokenByName(engine, opts.bindToken) : null;
let created: string[] = [];
await engine.transaction(async tx => {
- await tx.executeRaw('INSERT INTO access_members (id, display_name, email) VALUES ($1, $2, $3)', [id, opts.name ?? null, email]);
+ await tx.executeRaw('INSERT INTO access_members (id, display_name, email, kind) VALUES ($1, $2, $3, $4)', [id, opts.name ?? null, email, kind]);
created = await ensureGroups(tx, groups);
for (const g of groups) await tx.executeRaw('INSERT INTO access_group_members (group_id, member_id) VALUES ($1, $2) ON CONFLICT DO NOTHING', [g, id]);
if (bindTarget) await tx.executeRaw('UPDATE access_tokens SET member_id = $2 WHERE id::text = $1', [bindTarget.id, id]);
@@ -238,6 +252,48 @@ export async function setMemberEmail(engine: BrainEngine, rawId: unknown, rawEma
return { member: (await getMember(engine, member.id))!, changed: true };
}
+/** A member kind (person or audience), validated; throws access_member_invalid otherwise. */
+export function assertMemberKind(raw: unknown): MemberKind {
+ if (raw === 'person' || raw === 'audience') return raw;
+ throw memberInvalid(`"${String(raw ?? '')}" is not a member kind.`, 'ill_formed', 'Use person or audience.',
+ 'An audience member (a group chat, a shared assistant) is read by the owner as its own; every other member is a person.');
+}
+
+/** Refuses a kind change from anything but the trusted local operator (remote strictly false), before anything is written. */
+function assertLocalKindChange(ctx: { remote?: boolean }, id: string, kind: MemberKind): void {
+ if (ctx.remote === false) return;
+ throw hostOnlyError({ remote: true, transport: 'http' }, 'permission_denied',
+ 'Only the brain operator on the brain host marks a member as an audience or a person, so nothing was changed.',
+ ['gbrain', 'access', 'member', 'kind', id, kind],
+ 'An audience member\'s own member page, derived pages and facts are read by the brain owner. Whether the owner reads them is the brain operator\'s decision, never an agent\'s.');
+}
+
+/**
+ * GBRA-108 design 2: marks a member as an audience (a group chat, a shared assistant) or a person. Only the trusted
+ * local operator may (setOwnerReadsRestricted's rule): a remote caller is refused before anything is written.
+ */
+export async function setMemberKind(engine: BrainEngine, rawId: unknown, rawKind: unknown, ctx: { remote?: boolean }): Promise<{ member: MemberRecord; changed: boolean }> {
+ const id = assertAccessId(rawId);
+ const kind = assertMemberKind(rawKind);
+ assertLocalKindChange(ctx, id, kind);
+ const member = await existingMember(engine, id, 'changed');
+ if (member.status === 'removed') throw retired(member.id, 'Add a new member id instead.', 'A removed member stays removed.');
+ if (member.kind === kind) return { member, changed: false };
+ await engine.executeRaw('UPDATE access_members SET kind = $2, updated_at = now() WHERE id = $1 AND tombstoned_at IS NULL', [member.id, kind]);
+ return { member: (await getMember(engine, member.id))!, changed: true };
+}
+
+/** GBRA-108 design 2: the enabled audience members, sorted; empty when none or unreadable (nothing widens). */
+export async function audienceMemberIds(engine: Pick<BrainEngine, 'executeRaw'>): Promise<string[]> {
+ try {
+ const rows = await engine.executeRaw<{ id: string }>(
+ "SELECT id FROM access_members WHERE kind = 'audience' AND disabled_at IS NULL AND tombstoned_at IS NULL ORDER BY id");
+ return rows.map(r => r.id).filter(id => ACCESS_ID_RE.test(id));
+ } catch {
+ return [];
+ }
+}
+
/** Credentials whose stored binding names `id` (active tokens, clients not deleted). */
export async function boundCredentials(engine: BrainEngine, id: string): Promise<CredentialRef[]> {
const tokens = await engine.executeRaw<{ id: string; name: string }>(
diff --git a/src/core/access/policy.ts b/src/core/access/policy.ts
index 7a59effdaf..ee07e2a75d 100644
--- a/src/core/access/policy.ts
+++ b/src/core/access/policy.ts
@@ -25,7 +25,7 @@ import { createHash, randomUUID } from 'node:crypto';
import { userInfo } from 'node:os';
import type { BrainEngine } from '../engine.ts';
import { opError } from '../ops/contract.ts';
-import { classifyRulebook, folderRulesAllow, rulebookDigest, rulesFromJson, sortRules, type Classification, type FolderRule, type RuleChange } from './folder-rules.ts';
+import { classifyRulebook, coversDerived, folderRulesAllow, ruleCovers, rulebookDigest, rulesFromJson, sortRules, type Classification, type FolderRule, type RuleChange } from './folder-rules.ts';
import { identityFor } from './principals.ts';
import { listMembers } from './members.ts';
@@ -114,9 +114,9 @@ export async function lockSource(tx: Exec, sourceId: string): Promise<void> {
}
export async function appliedRules(engine: Exec, sourceId: string): Promise<FolderRule[]> {
- const rows = await engine.executeRaw<{ rule_id: string; prefix: string; readable_by: string[] }>(
- 'SELECT rule_id, prefix, readable_by FROM access_rules WHERE source_id = $1 ORDER BY rule_id', [sourceId]);
- return sortRules(rows.map(r => ({ id: r.rule_id, prefix: r.prefix, readable_by: [...(r.readable_by ?? [])] })));
+ const rows = await engine.executeRaw<{ rule_id: string; prefix: string; readable_by: string[]; covers_derived: boolean }>(
+ 'SELECT rule_id, prefix, readable_by, covers_derived FROM access_rules WHERE source_id = $1 ORDER BY rule_id', [sourceId]);
+ return sortRules(rows.map(r => ({ id: r.rule_id, prefix: r.prefix, readable_by: [...(r.readable_by ?? [])], ...(r.covers_derived === false ? { covers_derived: false as const } : {}) })));
}
export async function listRevisions(engine: Exec, sourceId: string, limit = 50): Promise<RevisionRow[]> {
@@ -140,6 +140,7 @@ export async function coverageRows(engine: Exec, sourceId: string): Promise<Cove
}
const key = (r: FolderRule) => `${r.id}\u0000${r.prefix}`;
+const sameRule = (a: FolderRule, b: FolderRule) => a.prefix === b.prefix && a.readable_by.join('\u0000') === b.readable_by.join('\u0000') && coversDerived(a) === coversDerived(b);
/**
* Makes `target` the applied rulebook inside the caller's locked transaction. Rules whose (id, prefix) pair is new get
@@ -163,15 +164,15 @@ async function installRulebook(tx: Exec, sourceId: string, target: readonly Fold
const targetKeys = new Set(target.map(key));
for (const r of current) {
const next = after.get(r.id);
- if (!next || next.prefix !== r.prefix || next.readable_by.join('\u0000') !== r.readable_by.join('\u0000')) {
+ if (!next || !sameRule(next, r)) {
await tx.executeRaw('DELETE FROM access_rules WHERE source_id = $1 AND rule_id = $2', [sourceId, r.id]);
}
}
for (const r of target) {
const prior = before.get(r.id);
- if (prior && prior.prefix === r.prefix && prior.readable_by.join('\u0000') === r.readable_by.join('\u0000')) continue;
- await tx.executeRaw('INSERT INTO access_rules (source_id, rule_id, prefix, readable_by, revision, created_by) VALUES ($1, $2, $3, $4::text[], $5, $6)',
- [sourceId, r.id, r.prefix, r.readable_by, revision, actor]);
+ if (prior && sameRule(prior, r)) continue;
+ await tx.executeRaw('INSERT INTO access_rules (source_id, rule_id, prefix, readable_by, revision, created_by, covers_derived) VALUES ($1, $2, $3, $4::text[], $5, $6, $7)',
+ [sourceId, r.id, r.prefix, r.readable_by, revision, actor, coversDerived(r)]);
}
const added = target.filter(r => !currentKeys.has(key(r)));
for (const r of added) {
@@ -304,6 +305,11 @@ export interface WideningImpact {
sample: string[];
/** Members who read at least one page after the change that they cannot read now; 'every_source_reader' when unbound callers gain too. */
gains: string[] | 'every_source_reader';
+ /**
+ * Raw-only rules (derived_released): no page gains readers; `pages` and `sample` are the pages the rule covers, whose
+ * derived pages and facts stop being hidden by it from whoever reads those derivatives.
+ */
+ lineage?: true;
}
export interface ApplyPreview {
@@ -338,6 +344,12 @@ export async function previewApply(engine: BrainEngine, sourceId: string, revisi
const widening: WideningImpact[] = [];
for (const change of cls.held) {
const old = current.find(r => r.id === change.rule);
+ if (change.kind === 'derived_released') {
+ const covered = (await engine.executeRaw<{ slug: string }>(
+ 'SELECT slug FROM pages WHERE source_id = $1 AND deleted_at IS NULL AND starts_with(slug, $2) ORDER BY slug', [sourceId, change.prefix])).map(r => r.slug).filter(s => ruleCovers(s, change.prefix));
+ widening.push({ change, pages: covered.length, sample: covered.slice(0, 20), gains: 'every_source_reader', lineage: true });
+ continue;
+ }
const prefixes = [...new Set([old?.prefix, change.prefix].filter((p): p is string => !!p))];
const slugs = (await engine.executeRaw<{ slug: string }>(
'SELECT slug FROM pages WHERE source_id = $1 AND deleted_at IS NULL AND EXISTS (SELECT 1 FROM unnest($2::text[]) AS pfx WHERE starts_with(slug, pfx)) ORDER BY slug',
diff --git a/src/core/cli-flag-registry.generated.ts b/src/core/cli-flag-registry.generated.ts
index f8dbb14f1c..5cb4b6b6c8 100644
--- a/src/core/cli-flag-registry.generated.ts
+++ b/src/core/cli-flag-registry.generated.ts
@@ -14,7 +14,7 @@
// (help-text mentions count): accepting an ignored flag is the pre-#2185
// status quo; missing a real one breaks working invocations.
export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {
- 'access': ['--add', '--adopt-columns', '--adopt-permissions', '--all', '--all-new', '--approved', '--as', '--attest-actor', '--attest-ops', '--attest-read', '--attest-sources', '--bind-token', '--brain', '--client', '--dry-run', '--email', '--expect', '--file', '--grant-types', '--groups', '--help', '--http', '--id', '--if-version', '--json', '--limit', '--may-act-for', '--member', '--members', '--members-file', '--migrate-legacy', '--name', '--operation', '--operations', '--prefix', '--private-pages', '--qm', '--readers', '--refresh-operations', '--reset-default', '--revision', '--scopes', '--slug', '--source', '--sources', '--stdio-member', '--takes-holders', '--to', '--token', '--tools-json', '--yes'],
+ 'access': ['--add', '--adopt-columns', '--adopt-permissions', '--all', '--all-new', '--approved', '--as', '--attest-actor', '--attest-ops', '--attest-read', '--attest-sources', '--bind-token', '--brain', '--client', '--dry-run', '--email', '--expect', '--file', '--grant-types', '--groups', '--help', '--http', '--id', '--if-version', '--json', '--kind', '--limit', '--may-act-for', '--member', '--members', '--members-file', '--migrate-legacy', '--name', '--operation', '--operations', '--prefix', '--private-pages', '--qm', '--raw-only', '--readers', '--refresh-operations', '--reset-default', '--revision', '--scopes', '--slug', '--source', '--sources', '--stdio-member', '--takes-holders', '--to', '--token', '--tools-json', '--yes'],
'advisor': ['--apply', '--brain', '--help', '--json', '--skills-dir', '--source', '--workspace', '--yes'],
'agent': ['--allow-old-serve', '--brain', '--detach', '--fanout-manifest', '--federated-read', '--flags', '--follow', '--harness', '--help', '--http', '--json', '--max-turns', '--mcp-only', '--model', '--no-follow', '--port', '--preset', '--reissue', '--scopes', '--show-token', '--since', '--source', '--subagent-def', '--surface', '--timeout-ms', '--token-ttl', '--tools', '--url', '--word', '--yes'],
'anomalies': ['--all', '--brain', '--help', '--json', '--lookback-days', '--mcp-only', '--request-id', '--sigma', '--since', '--source'],
@@ -52,7 +52,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {
'db-repair': ['--accept-pending', '--apply', '--apply-rewrites', '--as', '--background', '--brain', '--break-lock', '--db-url', '--dry-run', '--explain', '--filter', '--follow', '--force', '--force-retry', '--format', '--help', '--http', '--json', '--legacy-lock', '--locks', '--name', '--no-accept-pending', '--path', '--prefer-postgres', '--probe', '--progress-interval', '--progress-json', '--quiet', '--remediate', '--restart', '--skip-verify', '--source', '--statement-timeout', '--supabase', '--timeout', '--timings', '--undo-last-rewrite', '--url', '--version', '--wait', '--yes'],
'decide': ['--accept-all', '--all', '--all-from', '--apply', '--brain', '--call-site', '--claims', '--dataset', '--dry-run', '--egress', '--embedding-dimensions', '--embedding-model', '--expect', '--from', '--help', '--include-withdrawals', '--input', '--items-out', '--json', '--kind', '--limit', '--max-cost', '--max-usd', '--min', '--non-interactive', '--out', '--provenance', '--provider', '--query', '--rate', '--reason', '--reason-family', '--recommended', '--remove', '--shadow', '--since', '--slot', '--source', '--status', '--suite', '--target', '--threshold', '--trust', '--undo', '--uri-prefix', '--version', '--what-if-threshold', '--yes'],
'diag': ['--access', '--add', '--all', '--allowed-operations', '--apply', '--as', '--asof', '--body', '--bound-slug-prefixes', '--brain', '--budget-ms', '--client', '--count', '--cursor', '--date', '--dated-since', '--days', '--detach', '--entities', '--expect', '--expected-revision', '--federated-read', '--filter', '--follow', '--format', '--from-index', '--full', '--fuzzy', '--group-by', '--held', '--help', '--http', '--id', '--include', '--include-ambiguous', '--include-deleted', '--json', '--kind', '--limit', '--max-usd', '--model', '--multimodal', '--no-autopilot-install', '--no-pull', '--no-walk', '--of', '--only', '--page', '--params', '--path', '--phase', '--prefer', '--preview', '--purge', '--query', '--recent', '--refresh-operations', '--replace', '--restart-only', '--reverse', '--row', '--scopes', '--session', '--side', '--since', '--slug', '--slugs', '--source', '--source-id', '--sources', '--stale', '--state', '--surface', '--to', '--updated-after', '--url', '--yes'],
- 'doctor': ['--abandon', '--abbrev-ref', '--abort', '--absolute-git-dir', '--accept-all', '--accept-capabilities', '--accept-pending', '--access', '--access-policy', '--account', '--acknowledge-managed', '--add', '--admin-intent', '--adopt', '--adopt-columns', '--adopt-permissions', '--advertise', '--after', '--agent', '--aggressive', '--aliases', '--all', '--all-drifted', '--all-from', '--allow-old-serve', '--allow-outside-source-root', '--allow-shell-jobs', '--allow-unverified-remote', '--allowed-operations', '--anchor', '--applied', '--apply', '--apply-rewrites', '--approval-out', '--approved', '--as', '--assign-corpus', '--assume-unchanged', '--attest-actor', '--attest-ops', '--attest-read', '--attest-sources', '--audit', '--auto', '--auto-additive', '--auto-fix', '--autostash', '--background', '--base', '--batch', '--batch-check', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-ms', '--budget-policy', '--budget-tokens', '--budget-usd', '--bundled', '--by-mention', '--cached', '--cacheinfo', '--call-site', '--catalog', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--cherry-mark', '--claims', '--class', '--claude-plugins', '--clear', '--clear-never-installed', '--cli-socket', '--client', '--close', '--code', '--concurrency', '--confidence', '--config', '--confirm', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--content-root', '--continue', '--conversation', '--count', '--credentials-file', '--cursor', '--cwd', '--dataset', '--day', '--db-url', '--deadline', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--delete-brain', '--dest', '--detach', '--detail', '--diff-filter', '--dim', '--dimensions', '--dir', '--disable', '--drain', '--drain-timeout', '--dry-run', '--egress', '--email', '--embedding-dimensions', '--embedding-model', '--enable', '--enable-dcr', '--end-of-options', '--entity', '--env', '--env-file', '--error-unmatch', '--exclude', '--exclude-standard', '--exit-code', '--expand', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--filter', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-rechunk', '--force-remove', '--force-retry', '--force-schema', '--force-with-lease', '--format', '--fresh', '--fresh-token', '--from', '--from-json', '--from-meetings', '--from-pages', '--full', '--full-tree', '--fuzzy', '--gbrain-bin', '--generation', '--get', '--get-all', '--get-regexp', '--get-url', '--git-common-dir', '--git-dir', '--git-path', '--grammar', '--group', '--group-by', '--hard', '--hard-deadline', '--harness', '--heads', '--held', '--help', '--hold-state', '--holds', '--home', '--http', '--id', '--if-version', '--ignore-env-override', '--ignore-missing', '--images', '--import', '--include-ambiguous', '--include-covered', '--include-cross-entity', '--include-deleted', '--include-failures', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-pseudo', '--include-repairs', '--include-withdrawals', '--index-audit', '--index-info', '--infer-dates', '--init', '--input', '--input-type', '--install', '--instructions', '--instructions-only', '--is-ancestor', '--is-bare-repository', '--is-inside-work-tree', '--is-shallow-repository', '--items-out', '--job-isolation', '--jq', '--json', '--keep', '--keep-checkout', '--key', '--kind', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link', '--link-source', '--link-type', '--list', '--list-out', '--literal-pathspecs', '--local', '--local-env-vars', '--locks', '--log-noop', '--manifest', '--markdown', '--max-cost', '--max-cost-usd', '--max-count', '--max-facts', '--max-jobs', '--max-requests', '--max-rss', '--max-runtime', '--max-usd', '--max-waiting', '--may-act-for', '--mcp-only', '--member', '--members', '--members-file', '--merge-base', '--migrate-legacy', '--migrate-only', '--migration', '--min', '--min-n', '--mode', '--model', '--multimodal', '--name', '--name-only', '--name-status', '--nice', '--no-accept-pending', '--no-assume-unchanged', '--no-autopilot-install', '--no-autostash', '--no-capture', '--no-commit-id', '--no-confirm', '--no-cron', '--no-delegate', '--no-edit', '--no-embed', '--no-embed-cache', '--no-embedding', '--no-expand', '--no-extract', '--no-federated', '--no-filters', '--no-gpg-sign', '--no-hooks', '--no-instructions', '--no-lanes', '--no-llm', '--no-merges', '--no-migrate', '--no-optional-locks', '--no-probe', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-seat', '--no-skip-worktree', '--no-stdio-member', '--no-tags', '--no-verify', '--no-walk', '--no-write-fetch-head', '--non-interactive', '--not', '--now', '--of', '--older-than', '--once', '--only', '--operation', '--operations', '--others', '--out', '--output', '--oversized', '--overwrite', '--page', '--parallel', '--params', '--parents', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--port', '--prefer', '--prefer-postgres', '--prefix', '--preload', '--preset', '--preview', '--principal', '--private-pages', '--probe', '--probe-pglite', '--profile', '--progress-interval', '--progress-json', '--project', '--provenance', '--provider', '--providers', '--prune-orphans', '--public-url', '--pull', '--pure', '--purge', '--push', '--push-only', '--qm', '--query', '--question', '--queue', '--quiet', '--rate', '--reader-mode', '--readers', '--reason', '--reauth', '--rebase', '--rebuild', '--recommended', '--redact-paths', '--reference-date', '--refresh', '--refresh-operations', '--refresh-skills', '--regenerate', '--reissue', '--relative', '--relower', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--repair', '--repair-unknown-markers', '--replace', '--repo', '--request', '--request-id', '--require', '--require-clean', '--reranker', '--reset', '--reset-checkpoint', '--reset-default', '--reset-session', '--resolve', '--restart-only', '--restore-only', '--resume', '--retire', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--reverse', '--review-lower', '--revision', '--right-only', '--rollback-to-source', '--root', '--routing', '--rules', '--run', '--runtime', '--safe', '--sample', '--save', '--scan-secrets', '--scope', '--scopes', '--search-mode', '--seat', '--section', '--segmented', '--select', '--self-transfer', '--semantic', '--serves', '--session', '--session-id', '--set', '--set-upstream-to', '--shadow', '--shared-skills', '--short', '--show-current', '--show-object-format', '--show-prefix', '--show-token', '--show-toplevel', '--side', '--since', '--since-last-run', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip', '--skip-bare-tweet', '--skip-failed', '--skip-urls', '--skip-verify', '--skip-worktree', '--slot', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--slug', '--slugs', '--source', '--source-id', '--source-ids', '--sources', '--squash', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--statement-timeout', '--status', '--stdin', '--stdio-member', '--stop-mcp', '--strategy', '--strict', '--suite', '--supabase', '--surface', '--swap-only', '--symbol-kind', '--symbolic-full-name', '--tags', '--take', '--takes-holders', '--target', '--target-score', '--threshold', '--tier', '--timeout', '--timings', '--to', '--token', '--token-ttl', '--top-k', '--topo-order', '--trust', '--tsconfig-override', '--type', '--types', '--unindexed', '--uninstall', '--unsafe-bypass-dream-guard', '--unset', '--unset-all', '--unsettle', '--unshallow', '--untracked-files', '--url', '--url-env', '--user', '--vacuum', '--vectors', '--verbose', '--verify', '--version', '--wait', '--wait-drain', '--warn-only', '--watch', '--what-if-threshold', '--where', '--window', '--workers', '--working-tree', '--workspace', '--worktree', '--write-tree', '--yes'],
+ 'doctor': ['--abandon', '--abbrev-ref', '--abort', '--absolute-git-dir', '--accept-all', '--accept-capabilities', '--accept-pending', '--access', '--access-policy', '--account', '--acknowledge-managed', '--add', '--admin-intent', '--adopt', '--adopt-columns', '--adopt-permissions', '--advertise', '--after', '--agent', '--aggressive', '--aliases', '--all', '--all-drifted', '--all-from', '--allow-old-serve', '--allow-outside-source-root', '--allow-shell-jobs', '--allow-unverified-remote', '--allowed-operations', '--anchor', '--applied', '--apply', '--apply-rewrites', '--approval-out', '--approved', '--as', '--assign-corpus', '--assume-unchanged', '--attest-actor', '--attest-ops', '--attest-read', '--attest-sources', '--audit', '--auto', '--auto-additive', '--auto-fix', '--autostash', '--background', '--base', '--batch', '--batch-check', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--branch', '--break-lock', '--budget-ms', '--budget-policy', '--budget-tokens', '--budget-usd', '--bundled', '--by-mention', '--cached', '--cacheinfo', '--call-site', '--catalog', '--catch-up', '--channel', '--check', '--check-downgrade', '--check-only', '--cherry-mark', '--claims', '--class', '--claude-plugins', '--clear', '--clear-never-installed', '--cli-socket', '--client', '--close', '--code', '--concurrency', '--confidence', '--config', '--confirm', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--content-root', '--continue', '--conversation', '--count', '--credentials-file', '--cursor', '--cwd', '--dataset', '--day', '--db-url', '--deadline', '--decisions', '--delegated-namespace', '--delegated-slug-prefixes', '--delete-brain', '--dest', '--detach', '--detail', '--diff-filter', '--dim', '--dimensions', '--dir', '--disable', '--drain', '--drain-timeout', '--dry-run', '--egress', '--email', '--embedding-dimensions', '--embedding-model', '--enable', '--enable-dcr', '--end-of-options', '--entity', '--env', '--env-file', '--error-unmatch', '--exclude', '--exclude-standard', '--exit-code', '--expand', '--expect', '--expect-local', '--expect-remote', '--expect-upstream', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--federated', '--federated-read', '--fetch-timeout-ms', '--ff-only', '--file', '--filter', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-rechunk', '--force-remove', '--force-retry', '--force-schema', '--force-with-lease', '--format', '--fresh', '--fresh-token', '--from', '--from-json', '--from-meetings', '--from-pages', '--full', '--full-tree', '--fuzzy', '--gbrain-bin', '--generation', '--get', '--get-all', '--get-regexp', '--get-url', '--git-common-dir', '--git-dir', '--git-path', '--grammar', '--group', '--group-by', '--hard', '--hard-deadline', '--harness', '--heads', '--held', '--help', '--hold-state', '--holds', '--home', '--http', '--id', '--if-version', '--ignore-env-override', '--ignore-missing', '--images', '--import', '--include-ambiguous', '--include-covered', '--include-cross-entity', '--include-deleted', '--include-failures', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-pseudo', '--include-repairs', '--include-withdrawals', '--index-audit', '--index-info', '--infer-dates', '--init', '--input', '--input-type', '--install', '--instructions', '--instructions-only', '--is-ancestor', '--is-bare-repository', '--is-inside-work-tree', '--is-shallow-repository', '--items-out', '--job-isolation', '--jq', '--json', '--keep', '--keep-checkout', '--key', '--kind', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link', '--link-source', '--link-type', '--list', '--list-out', '--literal-pathspecs', '--local', '--local-env-vars', '--locks', '--log-noop', '--manifest', '--markdown', '--max-cost', '--max-cost-usd', '--max-count', '--max-facts', '--max-jobs', '--max-requests', '--max-rss', '--max-runtime', '--max-usd', '--max-waiting', '--may-act-for', '--mcp-only', '--member', '--members', '--members-file', '--merge-base', '--migrate-legacy', '--migrate-only', '--migration', '--min', '--min-n', '--mode', '--model', '--multimodal', '--name', '--name-only', '--name-status', '--nice', '--no-accept-pending', '--no-assume-unchanged', '--no-autopilot-install', '--no-autostash', '--no-capture', '--no-commit-id', '--no-confirm', '--no-cron', '--no-delegate', '--no-edit', '--no-embed', '--no-embed-cache', '--no-embedding', '--no-expand', '--no-extract', '--no-federated', '--no-filters', '--no-gpg-sign', '--no-hooks', '--no-instructions', '--no-lanes', '--no-llm', '--no-merges', '--no-migrate', '--no-optional-locks', '--no-probe', '--no-pull', '--no-renames', '--no-repair', '--no-restart', '--no-schema-pack', '--no-seat', '--no-skip-worktree', '--no-stdio-member', '--no-tags', '--no-verify', '--no-walk', '--no-write-fetch-head', '--non-interactive', '--not', '--now', '--of', '--older-than', '--once', '--only', '--operation', '--operations', '--others', '--out', '--output', '--oversized', '--overwrite', '--page', '--parallel', '--params', '--parents', '--parked-code', '--parked-pushes', '--pat-file', '--path', '--path-format', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--port', '--prefer', '--prefer-postgres', '--prefix', '--preload', '--preset', '--preview', '--principal', '--private-pages', '--probe', '--probe-pglite', '--profile', '--progress-interval', '--progress-json', '--project', '--provenance', '--provider', '--providers', '--prune-orphans', '--public-url', '--pull', '--pure', '--purge', '--push', '--push-only', '--qm', '--query', '--question', '--queue', '--quiet', '--rate', '--raw-only', '--reader-mode', '--readers', '--reason', '--reauth', '--rebase', '--rebuild', '--recommended', '--redact-paths', '--reference-date', '--refresh', '--refresh-operations', '--refresh-skills', '--regenerate', '--reissue', '--relative', '--relower', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--repair', '--repair-unknown-markers', '--replace', '--repo', '--request', '--request-id', '--require', '--require-clean', '--reranker', '--reset', '--reset-checkpoint', '--reset-default', '--reset-session', '--resolve', '--restart-only', '--restore-only', '--resume', '--retire', '--retry-failed', '--retry-global', '--retry-held', '--retry-parked', '--reverse', '--review-lower', '--revision', '--right-only', '--rollback-to-source', '--root', '--routing', '--rules', '--run', '--runtime', '--safe', '--sample', '--save', '--scan-secrets', '--scope', '--scopes', '--search-mode', '--seat', '--section', '--segmented', '--select', '--self-transfer', '--semantic', '--serves', '--session', '--session-id', '--set', '--set-upstream-to', '--shadow', '--shared-skills', '--short', '--show-current', '--show-object-format', '--show-prefix', '--show-token', '--show-toplevel', '--side', '--since', '--since-last-run', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip', '--skip-bare-tweet', '--skip-failed', '--skip-urls', '--skip-verify', '--skip-worktree', '--slot', '--slot-a-model', '--slot-b-model', '--slot-c-model', '--slug', '--slugs', '--source', '--source-id', '--source-ids', '--sources', '--squash', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--statement-timeout', '--status', '--stdin', '--stdio-member', '--stop-mcp', '--strategy', '--strict', '--suite', '--supabase', '--surface', '--swap-only', '--symbol-kind', '--symbolic-full-name', '--tags', '--take', '--takes-holders', '--target', '--target-score', '--threshold', '--tier', '--timeout', '--timings', '--to', '--token', '--token-ttl', '--top-k', '--topo-order', '--trust', '--tsconfig-override', '--type', '--types', '--unindexed', '--uninstall', '--unsafe-bypass-dream-guard', '--unset', '--unset-all', '--unsettle', '--unshallow', '--untracked-files', '--url', '--url-env', '--user', '--vacuum', '--vectors', '--verbose', '--verify', '--version', '--wait', '--wait-drain', '--warn-only', '--watch', '--what-if-threshold', '--where', '--window', '--workers', '--working-tree', '--workspace', '--worktree', '--write-tree', '--yes'],
'dream': ['--audit-rejects', '--brain', '--cancel-unmatched', '--date', '--dir', '--drain', '--dry-run', '--eval-run', '--force', '--from', '--help', '--input', '--install', '--json', '--limit', '--list', '--max-usd', '--once', '--phase', '--probe', '--pull', '--reconcile-queue', '--since', '--source', '--source-id', '--threshold', '--to', '--unsafe-bypass-dream-guard', '--window', '--yes'],
'edge-proposals': ['--access', '--add', '--all', '--all-applied', '--all-held', '--allowed-operations', '--as', '--asof', '--body', '--bound-slug-prefixes', '--brain', '--client', '--cursor', '--date', '--dated-since', '--days', '--entities', '--federated-read', '--follow', '--from-index', '--full', '--fuzzy', '--group-by', '--help', '--http', '--id', '--include', '--include-deleted', '--json', '--kind', '--limit', '--max-usd', '--model', '--multimodal', '--no-autopilot-install', '--of', '--only', '--page', '--params', '--path', '--phase', '--prefer', '--purge', '--recent', '--refresh-operations', '--row', '--scopes', '--session', '--since', '--slugs', '--source', '--sources', '--stale', '--status', '--surface', '--to', '--updated-after', '--url', '--yes'],
'edges-backfill': ['--all-sources', '--brain', '--concurrency', '--help', '--json', '--max-chunks', '--source', '--workers'],
@@ -85,7 +85,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {
'lint': ['--abbrev-ref', '--accept-pending', '--add', '--admin-intent', '--adopt-slug-path', '--as', '--audit', '--autostash', '--background', '--brain', '--branch', '--cached', '--client', '--confirm-relocated-root', '--conflicts', '--dry-run', '--enable', '--error-unmatch', '--exclude', '--expect-remote', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--ff-only', '--file', '--fix', '--follow', '--force', '--get', '--get-all', '--git-dir', '--git-path', '--grammar-diagnostics', '--hard', '--help', '--id', '--infer-entity', '--is-inside-work-tree', '--json', '--keep', '--keep-checkout', '--local', '--local-env-vars', '--manifest', '--max-cost-usd', '--no-accept-pending', '--no-assume-unchanged', '--no-autostash', '--no-cron', '--no-pull', '--no-renames', '--no-skip-worktree', '--no-tags', '--no-verify', '--older-than', '--only', '--pat-file', '--path', '--porcelain', '--prefer', '--preview', '--probe', '--progress-interval', '--progress-json', '--provenance', '--pull', '--purge', '--push-only', '--quiet', '--readers', '--rebase', '--require-clean', '--resolve', '--scopes', '--self-transfer', '--short', '--show-toplevel', '--slug', '--slugs', '--source', '--source-id', '--stdin', '--timeout', '--timings', '--unset-all', '--untracked-files', '--verify', '--wait', '--yes'],
'loops': ['--all', '--as-of', '--brain', '--dry-run', '--fail-fast', '--help', '--json', '--note', '--source', '--stale-ok', '--status', '--tools-json', '--top', '--type'],
'lsd': ['--brain', '--force-resume', '--help', '--json', '--judge-model', '--limit', '--list-runs', '--max-cost', '--max-far-set', '--max-ideas-per-judge-call', '--max-usd', '--no-save', '--resume', '--save', '--source', '--strict-budget', '--yes'],
- 'maintain': ['--absolute-git-dir', '--account', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--after', '--all', '--allow-outside-source-root', '--apply', '--assign-corpus', '--attest-read', '--audit', '--background', '--brain', '--break-lock', '--budget-ms', '--by-mention', '--cached', '--catch-up', '--check-only', '--class', '--clear', '--client', '--concurrency', '--conflicts', '--contacts-dir', '--content-audit', '--continue', '--conversation', '--count', '--cwd', '--detach', '--detail', '--dim', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--enable', '--entity', '--expect', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--fix', '--follow', '--force', '--force-retry', '--force-schema', '--format', '--from-meetings', '--full', '--grammar', '--group-by', '--hard-deadline', '--harness', '--held', '--help', '--http', '--id', '--ignore-missing', '--images', '--include-ambiguous', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-repairs', '--index-audit', '--infer-dates', '--input', '--install', '--instructions-only', '--json', '--keep-checkout', '--kind', '--lang', '--left-right', '--limit', '--link-source', '--link-type', '--list', '--local', '--locks', '--markdown', '--max-cost', '--max-cost-usd', '--max-jobs', '--max-rss', '--max-usd', '--may-act-for', '--migrate-legacy', '--migrate-only', '--multimodal', '--name', '--name-only', '--ner', '--no-autopilot-install', '--no-capture', '--no-delegate', '--no-embed', '--no-instructions', '--no-pull', '--no-renames', '--no-walk', '--once', '--only', '--operations', '--output', '--oversized', '--pack', '--page', '--parallel', '--params', '--path', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--prefer', '--prefix', '--preview', '--probe', '--probe-pglite', '--project', '--providers', '--prune-orphans', '--pull', '--purge', '--push-only', '--query', '--question', '--queue', '--quiet', '--rate', '--reader-mode', '--readers', '--reauth', '--rebase', '--rebuild', '--regenerate', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--request-id', '--reset', '--reset-default', '--restart-only', '--resume', '--retry-failed', '--retry-held', '--retry-parked', '--reverse', '--safe', '--scan-secrets', '--scope', '--scopes', '--serves', '--session', '--show-current', '--show-toplevel', '--since', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip-failed', '--slot', '--slug', '--slugs', '--source', '--source-id', '--sources', '--staged', '--stale', '--stat', '--state', '--status', '--stdin', '--supabase', '--surface', '--symbol-kind', '--takes-holders', '--target', '--target-score', '--tier', '--to', '--token', '--top-k', '--type', '--unindexed', '--untracked-files', '--url-env', '--verbose', '--verify', '--version', '--where', '--window', '--workers', '--workspace', '--yes'],
+ 'maintain': ['--absolute-git-dir', '--account', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--after', '--all', '--allow-outside-source-root', '--apply', '--assign-corpus', '--attest-read', '--audit', '--background', '--brain', '--break-lock', '--budget-ms', '--by-mention', '--cached', '--catch-up', '--check-only', '--class', '--clear', '--client', '--concurrency', '--conflicts', '--contacts-dir', '--content-audit', '--continue', '--conversation', '--count', '--cwd', '--detach', '--detail', '--dim', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--enable', '--entity', '--expect', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--fix', '--follow', '--force', '--force-retry', '--force-schema', '--format', '--from-meetings', '--full', '--grammar', '--group-by', '--hard-deadline', '--harness', '--held', '--help', '--http', '--id', '--ignore-missing', '--images', '--include-ambiguous', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-repairs', '--index-audit', '--infer-dates', '--input', '--install', '--instructions-only', '--json', '--keep-checkout', '--kind', '--lang', '--left-right', '--limit', '--link-source', '--link-type', '--list', '--local', '--locks', '--markdown', '--max-cost', '--max-cost-usd', '--max-jobs', '--max-rss', '--max-usd', '--may-act-for', '--migrate-legacy', '--migrate-only', '--multimodal', '--name', '--name-only', '--ner', '--no-autopilot-install', '--no-capture', '--no-delegate', '--no-embed', '--no-instructions', '--no-pull', '--no-renames', '--no-walk', '--once', '--only', '--operations', '--output', '--oversized', '--pack', '--page', '--parallel', '--params', '--path', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--prefer', '--prefix', '--preview', '--probe', '--probe-pglite', '--project', '--providers', '--prune-orphans', '--pull', '--purge', '--push-only', '--query', '--question', '--queue', '--quiet', '--rate', '--raw-only', '--reader-mode', '--readers', '--reauth', '--rebase', '--rebuild', '--regenerate', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--request-id', '--reset', '--reset-default', '--restart-only', '--resume', '--retry-failed', '--retry-held', '--retry-parked', '--reverse', '--safe', '--scan-secrets', '--scope', '--scopes', '--serves', '--session', '--show-current', '--show-toplevel', '--since', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip-failed', '--slot', '--slug', '--slugs', '--source', '--source-id', '--sources', '--staged', '--stale', '--stat', '--state', '--status', '--stdin', '--supabase', '--surface', '--symbol-kind', '--takes-holders', '--target', '--target-score', '--tier', '--to', '--token', '--top-k', '--type', '--unindexed', '--untracked-files', '--url-env', '--verbose', '--verify', '--version', '--where', '--window', '--workers', '--workspace', '--yes'],
'mcp': ['--admin-token-file', '--advertise', '--agent', '--all', '--arg', '--attest-actor', '--attest-ops', '--bearer-token-env-var', '--bound-brain', '--bound-max-concurrent', '--bound-slug-prefixes', '--bound-source', '--bound-tools', '--brain', '--budget-usd-per-day', '--client', '--credentials-file', '--credentials-out', '--cursor', '--delegate', '--delegated-namespace', '--delegated-slug-prefixes', '--dry-run', '--email', '--enable-dcr', '--federated-read', '--flow', '--force', '--funnel', '--groups', '--harness', '--header', '--help', '--if-version', '--install', '--issuer-url', '--json', '--limit', '--mcp-only', '--mcp-url', '--member', '--name', '--no-install', '--no-service', '--no-tailscale', '--oauth-client-id', '--oauth-client-secret', '--oauth-request', '--port', '--profile', '--qm', '--queue', '--reason', '--redirect-uri', '--remove', '--resume', '--root', '--scope', '--scopes', '--skills', '--source', '--status', '--surface', '--timeout-ms', '--token', '--token-endpoint-auth-method', '--token-ttl', '--url', '--yes'],
'memory-proposals': ['--all', '--brain', '--dry-run', '--help', '--json', '--limit', '--reason', '--replace', '--source'],
'migrate': ['--accept-pending', '--admin-intent', '--all', '--apply', '--as', '--background', '--batch-size', '--brain', '--catch-up', '--dim', '--drain-timeout', '--dry-run', '--embedding-dimensions', '--embedding-model', '--expect', '--expected-epoch', '--expected-state', '--explain', '--facts', '--follow', '--force', '--force-retry', '--harness', '--held', '--help', '--ignore-env-override', '--images', '--include-null-signature', '--json', '--locks', '--manifest', '--max-cost', '--max-cost-usd', '--max-usd', '--no-accept-pending', '--no-embed', '--no-embedding', '--no-migrate', '--non-interactive', '--only', '--oversized', '--pace', '--pace-max-concurrency', '--path', '--pglite', '--plan', '--priority', '--probe', '--progress-interval', '--progress-json', '--quiet', '--replace', '--reranker', '--resume', '--retarget', '--rollback-to-source', '--scope', '--skip-verify', '--slugs', '--source', '--stale', '--statement-timeout', '--status', '--timeout', '--timings', '--to', '--trigger-bypass', '--trust', '--url', '--url-env', '--wait', '--yes'],
@@ -135,7 +135,7 @@ export const CLI_FLAG_REGISTRY: Record<string, readonly string[]> = {
'status': ['--abbrev-ref', '--acknowledge-managed', '--all', '--allow-empty', '--apply', '--brain', '--break-lock', '--cached', '--check', '--code', '--concurrency', '--confirm-destructive', '--count', '--cursor', '--deadline-ms', '--delete', '--detail', '--diff-filter', '--empty', '--enable', '--exclude', '--exclude-standard', '--fast', '--filters', '--fix', '--force-break-lock', '--format', '--full', '--full-history', '--funnel', '--hard-deadline', '--help', '--hold-state', '--include-gitignored', '--include-hidden', '--install', '--interval', '--is-ancestor', '--is-shallow-repository', '--json', '--lanes', '--limit', '--max-age', '--max-sources', '--mcp-only', '--missing-path', '--name-only', '--no-auto-embed', '--no-bulk', '--no-delegate', '--no-embed', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-verify', '--no-walk', '--others', '--parallel', '--path', '--prefer', '--preview', '--priority', '--quiet', '--reason', '--redact-paths', '--repo', '--request-id', '--reset-checkpoint', '--retry-failed', '--retry-held', '--reverse', '--section', '--serial', '--show-toplevel', '--skip-failed', '--slug', '--slugs', '--source', '--source-id', '--src-subpath', '--stale', '--status', '--strategy', '--timeout', '--url', '--verify', '--watch', '--workers', '--working-tree', '--yes'],
'storage': ['--brain', '--help', '--json', '--plan', '--repo', '--restore-only', '--source', '--to'],
'sweep': ['--accept-pending', '--apply', '--as', '--assign-corpus', '--background', '--batch-limit', '--brain', '--budget-ms', '--delete-brain', '--explain', '--follow', '--help', '--home', '--json', '--no-accept-pending', '--no-delegate', '--once', '--only', '--progress-interval', '--progress-json', '--quiet', '--retry-failed', '--session', '--source', '--source-id', '--stale', '--timeout', '--timings', '--wait'],
- 'sync': ['--abbrev-ref', '--absolute-git-dir', '--accept-pending', '--access-policy', '--account', '--acknowledge-managed', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--after', '--all', '--allow-empty', '--allow-outside-source-root', '--apply', '--apply-rewrites', '--as', '--assign-corpus', '--attest-read', '--audit', '--auto', '--background', '--batch', '--batch-check', '--batch-size', '--brain', '--branch', '--break-lock', '--budget-ms', '--by-mention', '--cached', '--catch-up', '--check', '--check-only', '--class', '--clear', '--client', '--close', '--code', '--concurrency', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--continue', '--conversation', '--count', '--cursor', '--cwd', '--db-url', '--delete-brain', '--depth', '--detach', '--detail', '--diff-filter', '--dim', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--empty', '--enable', '--end-of-options', '--entity', '--exclude', '--exclude-standard', '--expect', '--expect-local', '--expect-upstream', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--ff-only', '--filter', '--filters', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-rechunk', '--force-retry', '--force-schema', '--format', '--fresh', '--from', '--from-meetings', '--full', '--full-history', '--get-regexp', '--git-dir', '--git-path', '--grammar', '--group-by', '--hard-deadline', '--harness', '--held', '--help', '--hold-state', '--home', '--http', '--id', '--ignore-missing', '--images', '--include-ambiguous', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--include-repairs', '--index-audit', '--infer-dates', '--input', '--install', '--instructions-only', '--interval', '--is-ancestor', '--is-bare-repository', '--is-inside-work-tree', '--is-shallow-repository', '--json', '--keep-checkout', '--kind', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link-source', '--link-type', '--list', '--literal-pathspecs', '--local', '--locks', '--log-noop', '--manifest', '--markdown', '--max-age', '--max-cost', '--max-cost-usd', '--max-jobs', '--max-rss', '--max-sources', '--max-usd', '--may-act-for', '--migrate-legacy', '--migrate-only', '--missing-path', '--multimodal', '--name', '--name-only', '--name-status', '--ner', '--no-accept-pending', '--no-auto-embed', '--no-autopilot-install', '--no-bulk', '--no-capture', '--no-delegate', '--no-embed', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-instructions', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-verify', '--no-walk', '--once', '--only', '--operations', '--others', '--output', '--oversized', '--overwrite', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--path', '--path-format', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--prefer', '--prefer-postgres', '--prefix', '--preview', '--priority', '--probe', '--probe-pglite', '--progress-interval', '--progress-json', '--project', '--providers', '--prune-orphans', '--pull', '--purge', '--push-only', '--query', '--question', '--queue', '--quiet', '--raw', '--reader-mode', '--readers', '--reauth', '--rebase', '--rebuild', '--redact-paths', '--refresh', '--regenerate', '--relative', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--replace', '--repo', '--request-id', '--reset', '--reset-checkpoint', '--reset-default', '--restart-only', '--restore-only', '--resume', '--retry-failed', '--retry-held', '--retry-parked', '--reverse', '--scan-secrets', '--scope', '--scopes', '--self-transfer', '--serial', '--serves', '--session', '--short', '--show-current', '--show-toplevel', '--side', '--since', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip', '--skip-failed', '--slot', '--slug', '--slugs', '--source', '--source-id', '--sources', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--status', '--stdin', '--strategy', '--supabase', '--surface', '--symbol-kind', '--symbolic-full-name', '--takes-holders', '--target', '--target-score', '--tier', '--timeout', '--timings', '--to', '--token', '--token-env', '--top-k', '--type', '--unindexed', '--unshallow', '--untracked-files', '--url', '--url-env', '--verbose', '--verify', '--version', '--wait', '--watch', '--where', '--window', '--workers', '--working-tree', '--workspace', '--yes'],
+ 'sync': ['--abbrev-ref', '--absolute-git-dir', '--accept-pending', '--access-policy', '--account', '--acknowledge-managed', '--admin-intent', '--adopt-columns', '--adopt-permissions', '--after', '--all', '--allow-empty', '--allow-outside-source-root', '--apply', '--apply-rewrites', '--as', '--assign-corpus', '--attest-read', '--audit', '--auto', '--background', '--batch', '--batch-check', '--batch-size', '--brain', '--branch', '--break-lock', '--budget-ms', '--by-mention', '--cached', '--catch-up', '--check', '--check-only', '--class', '--clear', '--client', '--close', '--code', '--concurrency', '--config', '--confirm-destructive', '--confirm-quiesced', '--confirm-relocated-root', '--conflicts', '--contacts-dir', '--content-audit', '--continue', '--conversation', '--count', '--cursor', '--cwd', '--db-url', '--delete-brain', '--depth', '--detach', '--detail', '--diff-filter', '--dim', '--dir', '--drain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--empty', '--enable', '--end-of-options', '--entity', '--exclude', '--exclude-standard', '--expect', '--expect-local', '--expect-upstream', '--expected-epoch', '--expected-revision', '--expected-state', '--explain', '--facts', '--fast', '--ff-only', '--filter', '--filters', '--first-parent', '--fix', '--follow', '--force', '--force-break-lock', '--force-rechunk', '--force-retry', '--force-schema', '--format', '--fresh', '--from', '--from-meetings', '--full', '--full-history', '--get-regexp', '--git-dir', '--git-path', '--grammar', '--group-by', '--hard-deadline', '--harness', '--held', '--help', '--hold-state', '--home', '--http', '--id', '--ignore-missing', '--images', '--include-ambiguous', '--include-flagged', '--include-frontmatter', '--include-gitignored', '--include-hidden', '--include-null-signature', '--include-repairs', '--index-audit', '--infer-dates', '--input', '--install', '--instructions-only', '--interval', '--is-ancestor', '--is-bare-repository', '--is-inside-work-tree', '--is-shallow-repository', '--json', '--keep-checkout', '--kind', '--lanes', '--lang', '--left-right', '--legacy-lock', '--limit', '--link-source', '--link-type', '--list', '--literal-pathspecs', '--local', '--locks', '--log-noop', '--manifest', '--markdown', '--max-age', '--max-cost', '--max-cost-usd', '--max-jobs', '--max-rss', '--max-sources', '--max-usd', '--may-act-for', '--migrate-legacy', '--migrate-only', '--missing-path', '--multimodal', '--name', '--name-only', '--name-status', '--ner', '--no-accept-pending', '--no-auto-embed', '--no-autopilot-install', '--no-bulk', '--no-capture', '--no-delegate', '--no-embed', '--no-extract', '--no-gpg-sign', '--no-hard-deadline', '--no-instructions', '--no-lanes', '--no-llm', '--no-pull', '--no-renames', '--no-repair', '--no-schema-pack', '--no-verify', '--no-walk', '--once', '--only', '--operations', '--others', '--output', '--oversized', '--overwrite', '--pace', '--pace-max-concurrency', '--pack', '--page', '--parallel', '--params', '--path', '--path-format', '--pending', '--pglite', '--phase', '--pid-file', '--plan', '--porcelain', '--prefer', '--prefer-postgres', '--prefix', '--preview', '--priority', '--probe', '--probe-pglite', '--progress-interval', '--progress-json', '--project', '--providers', '--prune-orphans', '--pull', '--purge', '--push-only', '--query', '--question', '--queue', '--quiet', '--raw', '--raw-only', '--reader-mode', '--readers', '--reauth', '--rebase', '--rebuild', '--redact-paths', '--refresh', '--regenerate', '--relative', '--remediate', '--remediation-plan', '--remote', '--remove', '--remove-core', '--replace', '--repo', '--request-id', '--reset', '--reset-checkpoint', '--reset-default', '--restart-only', '--restore-only', '--resume', '--retry-failed', '--retry-held', '--retry-parked', '--reverse', '--scan-secrets', '--scope', '--scopes', '--self-transfer', '--serial', '--serves', '--session', '--short', '--show-current', '--show-toplevel', '--side', '--since', '--skill-loading', '--skills-dir', '--skills-index-only', '--skip', '--skip-failed', '--slot', '--slug', '--slugs', '--source', '--source-id', '--sources', '--src-subpath', '--staged', '--stale', '--stat', '--state', '--status', '--stdin', '--strategy', '--supabase', '--surface', '--symbol-kind', '--symbolic-full-name', '--takes-holders', '--target', '--target-score', '--tier', '--timeout', '--timings', '--to', '--token', '--token-env', '--top-k', '--type', '--unindexed', '--unshallow', '--untracked-files', '--url', '--url-env', '--verbose', '--verify', '--version', '--wait', '--watch', '--where', '--window', '--workers', '--working-tree', '--workspace', '--yes'],
'takes': ['--about', '--accept', '--applied', '--apply', '--batch-size', '--before', '--brain', '--bucket-size', '--by', '--claim', '--date', '--dim', '--dir', '--domain', '--dry-run', '--embedding-dimensions', '--embedding-model', '--evidence', '--expected-revision', '--expired', '--failed', '--force', '--from-pages', '--group-by', '--help', '--holder', '--include-covered', '--json', '--kind', '--limit', '--max-pages', '--min-confidence', '--min-n', '--no-embed', '--no-embedding', '--offset', '--outcome', '--path', '--quality', '--reject', '--request-id', '--retry-failed', '--row', '--semantic', '--since', '--slug', '--sort', '--source', '--source-id', '--stale', '--state', '--status', '--supabase', '--to', '--unapplied', '--unit', '--until', '--value', '--verdict', '--weight', '--who', '--yes'],
'think': ['--anchor', '--brain', '--calibration-holder', '--help', '--images', '--json', '--mcp-only', '--model', '--only', '--reference-date', '--request-id', '--rounds', '--save', '--since', '--source', '--source-id', '--stale', '--take', '--until', '--with-calibration'],
'transcripts': ['--accept-pending', '--all', '--all-discovery', '--apply', '--as', '--background', '--brain', '--days', '--dry-run', '--embed', '--explain', '--facts', '--follow', '--format', '--full', '--help', '--include-self', '--json', '--limit', '--max-bytes', '--max-cost-usd', '--no-accept-pending', '--only', '--progress-interval', '--progress-json', '--purge', '--quiet', '--since', '--source', '--source-id', '--timeout', '--timings', '--wait'],
diff --git a/src/core/config-runtime-keys.ts b/src/core/config-runtime-keys.ts
index 024d89bd2f..e30d890f5e 100644
--- a/src/core/config-runtime-keys.ts
+++ b/src/core/config-runtime-keys.ts
@@ -26,6 +26,7 @@ export const RUNTIME_READER_CONFIG_KEYS: readonly string[] = [
'persistence.adopt_quiet_ms', // persistence/local-edit-adoption.ts (GST-1601): how long a local edit must be quiet before it is adopted, default 5000
'access.owner_member', // access/owner.ts (GST-2059): the member who owns this brain; credentials bound to it read private pages (gbrain access owner set)
'access.owner_reads_restricted', // access/owner.ts (GST-2490): '1' lets owner-bound credentials read past readers lists and rules (gbrain access owner reads-restricted on)
+ 'access.members_read_lineage', // access/lineage.ts (GBRA-108 design 3): '1' lets a member read derived pages and facts of origins it reads (gbrain access members-read-lineage on)
'access.serves', // access/serves.ts (GST-363): one or several; explicit wins over the enabled-member count (gbrain setup --serves several writes it)
'mcp.stdio_may_act_for', // access/audience.ts (GBRA-231): whom a local stdio server may act for (_meta.on_behalf_of); unset, stdio refuses every audience
'proposals.ttl_hours', 'proposals.max_pending_per_actor', 'proposals.max_pending_per_credential', // persistence/memory-proposals.ts: held QM proposal TTL (168 h) and pending caps (10 per person, 50 per credential)
diff --git a/src/core/deletion-inventory.ts b/src/core/deletion-inventory.ts
index 7c55024e80..e234c0d0ce 100644
--- a/src/core/deletion-inventory.ts
+++ b/src/core/deletion-inventory.ts
@@ -39,7 +39,7 @@ const ROWS: readonly Row[] = [
['access_groups', 'out_of_scope', 'no_memory_text', 'id'],
['access_member_links', 'out_of_scope', 'no_memory_text', 'system external_id member_id'],
['access_member_sources', 'out_of_scope', 'no_memory_text', 'member_id source_id'],
- ['access_members', 'out_of_scope', 'no_memory_text', 'id display_name email'],
+ ['access_members', 'out_of_scope', 'no_memory_text', 'id display_name email kind'],
['access_pending_coverage', 'out_of_scope', 'no_memory_text', 'source_id prefix reason detail'],
['access_policy_migrations', 'out_of_scope', 'no_memory_text', 'id source_id direction phase receipts'],
['access_policy_revisions', 'out_of_scope', 'no_memory_text', 'source_id rules digest origin proposed_by approved_by change_kind operation_id'],
diff --git a/src/core/doctor-categories.ts b/src/core/doctor-categories.ts
index e24b1fa8f6..f61136ae37 100644
--- a/src/core/doctor-categories.ts
+++ b/src/core/doctor-categories.ts
@@ -106,6 +106,10 @@ export const BRAIN_CHECK_NAMES: ReadonlySet<string> = new Set([
'access_may_act_for_wildcard',
// GST-2490: the owner opt-in (doctor/checks/owner-reads-restricted.ts).
'access_owner_reads_restricted',
+ // GBRA-108: raw-only rules, audience members and members-read-lineage (doctor/checks/access-lineage.ts).
+ 'access_raw_only_rules',
+ 'access_audience_members',
+ 'access_members_read_lineage',
// 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.ts
index ad4ba6bab8..b7a0b1a605 100644
--- a/src/core/function-search-path.ts
+++ b/src/core/function-search-path.ts
@@ -23,7 +23,7 @@ export const LEGACY_SEARCH_PATH_SETTINGS = ['search_path=pg_catalog, public', 's
*/
export 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_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_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',
diff --git a/src/core/ops/sources.ts b/src/core/ops/sources.ts
index 5948a8f891..5ab5ac4135 100644
--- a/src/core/ops/sources.ts
+++ b/src/core/ops/sources.ts
@@ -51,9 +51,11 @@ 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.
- // GST-2490: and, while the owner opt-in is on, that the owner reads the pages kept to this caller.
+ // GST-2490: and, while the owner opt-in is on, that the owner reads the pages kept to this caller; GBRA-108: and,
+ // while access.members_read_lineage is on, that members read the derived pages of pages listed to them.
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) });
+ ...await (await import('../access/owner.ts')).ownerReadsRestrictedNotice(ctx.engine),
+ ...await (await import('../access/lineage.ts')).membersReadLineageNotice(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.ts
index 274744a9b2..2f8fc824f5 100644
--- a/src/core/pglite-schema.generated.ts
+++ b/src/core/pglite-schema.generated.ts
@@ -2962,7 +2962,7 @@ BEGIN
FOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS path
FROM 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_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 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_lineage_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 1
LOOP
diff --git a/src/core/schema-embedded.generated.ts b/src/core/schema-embedded.generated.ts
index 012e13326c..0fd5ea0ff6 100644
--- a/src/core/schema-embedded.generated.ts
+++ b/src/core/schema-embedded.generated.ts
@@ -3748,7 +3748,7 @@ BEGIN
FOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS path
FROM 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_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 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_lineage_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 1
LOOP
diff --git a/src/core/schema-migrations/latest.generated.ts b/src/core/schema-migrations/latest.generated.ts
index 06933be159..e228ee6a8c 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 = 304;
+export const LATEST_SCHEMA_VERSION = 305;
diff --git a/src/core/schema-migrations/registry.generated.ts b/src/core/schema-migrations/registry.generated.ts
index eb09b0133a..ee670ca2bb 100644
--- a/src/core/schema-migrations/registry.generated.ts
+++ b/src/core/schema-migrations/registry.generated.ts
@@ -305,6 +305,7 @@ 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';
+import { v305 } from './v305-access-lineage-designs.ts';
// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the
// runner sorts by version before applying.
@@ -608,4 +609,5 @@ export const MIGRATIONS: Migration[] = [
v302,
v303,
v304,
+ v305,
];
diff --git a/src/core/schema-migrations/v305-access-lineage-designs.ts b/src/core/schema-migrations/v305-access-lineage-designs.ts
new file mode 100644
index 0000000000..15e007d882
--- /dev/null
+++ b/src/core/schema-migrations/v305-access-lineage-designs.ts
@@ -0,0 +1,136 @@
+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.
+//
+// Three operator-set access designs (GBRA-108), all off on upgrade:
+//
+// Raw-only rules. access_rules.covers_derived (default true) is false for a folder or page rule whose pages are raw
+// material (transcripts): the rule still keeps the pages it covers to its readers, but no longer closes the lineage of
+// the pages and facts derived from them. gbrain_access_lineage_rules(source, rule ids) is the part of an origin's
+// folder_rule_ids that closes lineage: every id except one naming a rule stored with covers_derived false, so a stamped
+// id whose rule is gone keeps counting (fail closed); NULL when none is left. gbrain_access_origin_restricted (every
+// caller; v285's arms and escaping) and gbrain_access_origin_closed_for (owner and member lineage; v304's) count only
+// those ids. An origin's own readable_by and pending coverage close lineage as before.
+//
+// Audience members. access_members.kind ('person' by default, or 'audience': a group chat, a shared assistant). An
+// owner read treats an audience member's own member page (memory/members/<id>) as if its readers named the owner, and
+// the opt-in's member-page arm passes it, so gbrain_access_origin_closed_for and gbrain_access_origin_hidden_for take
+// p_audience_pages (those page slugs; empty for every other caller). The v304 signatures stay as wrappers that pass
+// none, so an older binary sharing the database keeps reading as before.
+//
+// Nothing is rewritten: every rule keeps covers_derived true and every member kind person, so every read is
+// unchanged. No schema.sql mirror: like v283, v285 and v304, these exist only through migrations. Provisional number:
+// renumbered at the merge slot.
+const CLOSED = (o: string) => `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, p_audience_pages)`;
+const RESTRICTED = (o: string) => `(${o}.frontmatter ? 'readable_by' OR gbrain_access_lineage_rules(${o}.source_id, ${o}.folder_rule_ids) IS NOT NULL OR gbrain_access_pending_covers(${o}.source_id, ${o}.slug))`;
+
+export const v305: Migration = {
+ version: 305,
+ name: 'access_lineage_designs',
+ idempotent: true,
+ sql: `
+ALTER TABLE access_rules ADD COLUMN IF NOT EXISTS covers_derived BOOLEAN NOT NULL DEFAULT true;
+ALTER TABLE access_members ADD COLUMN IF NOT EXISTS kind TEXT NOT NULL DEFAULT 'person';
+ALTER TABLE access_members DROP CONSTRAINT IF EXISTS access_members_kind_check;
+ALTER TABLE access_members ADD CONSTRAINT access_members_kind_check CHECK (kind IN ('person', 'audience'));
+CREATE OR REPLACE FUNCTION gbrain_access_lineage_rules(p_source TEXT, p_rules TEXT[]) RETURNS TEXT[]
+ LANGUAGE sql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
+ SELECT CASE WHEN p_rules IS NULL THEN NULL ELSE (SELECT array_agg(x ORDER BY x COLLATE "C") FROM unnest(p_rules) AS x
+ WHERE NOT EXISTS (SELECT 1 FROM access_rules r WHERE r.source_id = p_source AND x = p_source || ':' || r.rule_id AND NOT r.covers_derived)) END
+$fn$;
+CREATE OR REPLACE FUNCTION gbrain_access_origin_restricted(p_id INTEGER, p_source_id TEXT, p_type TEXT, fm JSONB) RETURNS boolean
+ LANGUAGE plpgsql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
+BEGIN
+ IF p_type = 'atom' THEN
+ IF 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 ${RESTRICTED('o')}) THEN
+ RETURN true;
+ END IF;
+ ELSIF p_type = 'question' OR (p_type = 'concept' AND fm->>'synthesized_by' IS NOT NULL) THEN
+ IF EXISTS (SELECT 1 FROM links l JOIN pages i ON i.id = l.to_page_id
+ WHERE l.from_page_id = p_id AND l.link_source = 'concept-provenance' AND l.link_type = 'synthesized_from'
+ AND (${RESTRICTED('i')}
+ OR EXISTS (SELECT 1 FROM pages io WHERE io.source_id = i.source_id
+ AND 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 ${RESTRICTED('io')}))) THEN
+ RETURN true;
+ END IF;
+ ELSIF p_type = 'event' AND fm->>'captured_via' LIKE 'life-chronicle:%' THEN
+ IF 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 ${RESTRICTED('c')}) THEN
+ RETURN true;
+ END IF;
+ END IF;
+ IF jsonb_typeof(fm->'derived_from') IN ('array', 'string') THEN
+ RETURN EXISTS (SELECT 1 FROM pages d WHERE d.source_id = p_source_id
+ AND ${RESTRICTED('d')}
+ 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_id
+ UNION SELECT h.new_slug FROM slug_rename_history h JOIN declared ON h.old_slug = declared.slug WHERE h.source_id = p_source_id)));
+ END IF;
+ RETURN false;
+END
+$fn$;
+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, p_audience_pages TEXT[]) RETURNS boolean
+ LANGUAGE sql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
+ SELECT gbrain_access_pending_covers(o_source, o_slug)
+ OR ((NOT p_open OR (starts_with(o_slug, 'memory/members/') AND o_slug IS DISTINCT FROM p_own_page AND NOT COALESCE(o_slug = ANY(p_audience_pages), false)))
+ AND NOT (((o_readers IS NULL AND NOT (o_frontmatter ? 'readable_by')) OR COALESCE(o_readers && p_identity, false) OR COALESCE(o_slug = ANY(p_audience_pages), false))
+ AND (o_rules IS NULL OR o_rules <@ p_satisfied OR COALESCE(gbrain_access_lineage_rules(o_source, o_rules) <@ p_satisfied, true))))
+$fn$;
+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, p_audience_pages TEXT[]) RETURNS boolean
+ LANGUAGE plpgsql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
+BEGIN
+ IF p_type = 'atom' THEN
+ IF 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 ${CLOSED('o')}) THEN
+ RETURN true;
+ END IF;
+ ELSIF p_type = 'question' OR (p_type = 'concept' AND fm->>'synthesized_by' IS NOT NULL) THEN
+ IF EXISTS (SELECT 1 FROM links l JOIN pages i ON i.id = l.to_page_id
+ WHERE l.from_page_id = p_id AND l.link_source = 'concept-provenance' AND l.link_type = 'synthesized_from'
+ AND (${CLOSED('i')}
+ OR EXISTS (SELECT 1 FROM pages io WHERE io.source_id = i.source_id
+ AND 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 ${CLOSED('io')}))) THEN
+ RETURN true;
+ END IF;
+ ELSIF p_type = 'event' AND fm->>'captured_via' LIKE 'life-chronicle:%' THEN
+ IF 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 ${CLOSED('c')}) THEN
+ RETURN true;
+ END IF;
+ END IF;
+ IF jsonb_typeof(fm->'derived_from') IN ('array', 'string') THEN
+ RETURN EXISTS (SELECT 1 FROM pages d WHERE d.source_id = p_source_id
+ AND ${CLOSED('d')}
+ 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_id
+ UNION SELECT h.new_slug FROM slug_rename_history h JOIN declared ON h.old_slug = declared.slug WHERE h.source_id = p_source_id)));
+ END IF;
+ RETURN false;
+END
+$fn$;
+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 boolean
+ LANGUAGE sql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
+ SELECT gbrain_access_origin_closed_for(o_source, o_slug, o_frontmatter, o_readers, o_rules, p_identity, p_satisfied, p_open, p_own_page, ARRAY[]::text[])
+$fn$;
+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 boolean
+ LANGUAGE sql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
+ SELECT gbrain_access_origin_hidden_for(p_id, p_source_id, p_type, fm, p_identity, p_satisfied, p_open, p_own_page, ARRAY[]::text[])
+$fn$;
+`,
+};
diff --git a/src/core/search/mode.ts b/src/core/search/mode.ts
index 2a61a50ae5..4a70312455 100644
--- a/src/core/search/mode.ts
+++ b/src/core/search/mode.ts
@@ -1322,7 +1322,8 @@ 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.ownerLineage) parts.push(access.ownerReadsRestricted ? 'xol=2' : 'xol=1');
+ if (access.lineage) parts.push(!access.owner ? 'xol=3' : access.ownerReadsRestricted ? 'xol=2' : 'xol=1');
+ if (access.audienceKindMembers.length) parts.push(`xak=${createHash('sha256').update(access.audienceKindMembers.join(',')).digest('hex').slice(0, 16)}`);
}
const h = createHash('sha256');
h.update(parts.join('|'));
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.ts
index 5e24c21b39..2c1990167b 100644
--- a/src/core/search/private-visibility.ts
+++ b/src/core/search/private-visibility.ts
@@ -46,6 +46,15 @@ export const OWNER_MEMBER_KEY = 'access.owner_member';
*/
export const OWNER_READS_RESTRICTED_KEY = 'access.owner_reads_restricted';
+/**
+ * GBRA-108 design 3: listed members read lineage. Set to '1' only by the trusted local operator (`gbrain access
+ * members-read-lineage on`, access/lineage.ts); with it on, a read by a credential bound to one member speaking for itself (or for an audience of that
+ * one member) passes a derived page or fact when that member reads every origin of it, as an owner read does
+ * (CallerAccess.lineage). Never an audience of several, an unbound credential or an attested call. Off or unset
+ * changes nothing.
+ */
+export const MEMBERS_READ_LINEAGE_KEY = 'access.members_read_lineage';
+
/**
* #5525 — extracted atoms and synthesized concept pages are derived from
* other pages or from private transcripts, so a missing `visibility` field on
@@ -65,8 +74,8 @@ function derivedPageSql(pageAlias: string): string {
* relational-arm hydrate, and get_page's fuzzy-candidate filter. `pageAlias`
* is a code-provided literal, never user input.
*/
-export function privatePagesFilterFragment(pageAlias: string): string {
- return `(${accessAllowedSql(pageAlias, [])} AND ${privacyPartSql(pageAlias)})`;
+export function privatePagesFilterFragment(pageAlias: string, derived = false): string {
+ return `(${accessAllowedSql(pageAlias, [], [], derived)} AND ${privacyPartSql(pageAlias)})`;
}
/** The privacy rules alone (visibility, aliases, pinned questions, lineage): what the escape hatches and granted_sources may relax. */
@@ -87,19 +96,20 @@ export function privacyPartSql(pageAlias: string): string {
* `identity` must pass validIdentity (its alphabet has no quote), so it is
* embedded as literals; anything else empties it (fail closed).
*/
-export function accessAllowedSql(pageAlias: string, identity: readonly string[], satisfied: readonly string[] = satisfiedFor(identity)): string {
- return accessAllowedForAllSql(pageAlias, [identity], satisfied);
+export function accessAllowedSql(pageAlias: string, identity: readonly string[], satisfied: readonly string[] = satisfiedFor(identity), derived = false): string {
+ return accessAllowedForAllSql(pageAlias, [identity], satisfied, derived);
}
/**
* GBRA-231 (shared agents): accessAllowedSql for an audience. A page passes only when every identity in
* `identities` meets its readers (one conjunct each; a guest's empty identity meets no readers), and its folder rules
- * are all in `satisfied` (for an audience, the intersection of every entry's satisfied set).
+ * are all in `satisfied` (for an audience, the intersection of every entry's satisfied set). `derived` tests a page as
+ * the origin of what was derived from it (a fact's provenance page): raw-only rules (covers_derived false) do not count.
*/
-export function accessAllowedForAllSql(pageAlias: string, identities: readonly (readonly string[])[], satisfied: readonly string[]): string {
+export function accessAllowedForAllSql(pageAlias: string, identities: readonly (readonly string[])[], satisfied: readonly string[], derived = false): string {
if (!currentCallerAccess().restricted) return `(${pageAlias}.page_readers IS NULL AND ${pageAlias}.folder_rule_ids IS NULL)`;
const readers = (identities.length ? identities : [[]]).map(identity => readersAllowedSql(pageAlias, identity)).join(' AND ');
- return `(${readers} AND ${folderRulesAllowedSql(pageAlias, satisfied)} AND ${originAllowedSql(pageAlias)})`;
+ return `(${readers} AND ${folderRulesAllowedSql(pageAlias, satisfied, derived)} AND ${originAllowedSql(pageAlias)})`;
}
/**
@@ -109,12 +119,16 @@ export function accessAllowedForAllSql(pageAlias: string, identities: readonly (
* and group rules both have to pass. `satisfied` is the caller's satisfied set (CallerAccess.satisfiedRuleIds); an
* entry that is not a valid qualified id empties it (fail closed). Prefixes under a narrowing still being stamped,
* or touched by a policy file that does not validate, read as nobody (CallerAccess.folderCoverage). Column tests
- * lead, so a page under no rule costs one NULL test.
+ * lead, so a page under no rule costs one NULL test. With `derived` (a fact judged by its provenance page), only the
+ * rules that cover derived pages count (gbrain_access_lineage_rules, v305): a raw-only rule keeps its pages, not what
+ * was derived from them.
*/
-export function folderRulesAllowedSql(alias: string, satisfied: readonly string[]): string {
+export function folderRulesAllowedSql(alias: string, satisfied: readonly string[], derived = false): string {
const ids = satisfied.length && satisfied.every(validQualifiedRuleId) ? [...new Set(satisfied)].sort() : [];
- const listed = ids.length ? ` OR ${alias}.folder_rule_ids <@ ARRAY[${ids.map(id => `'${id}'`).join(', ')}]::text[]` : '';
- return `(${alias}.folder_rule_ids IS NULL${listed})${coverageSql(alias)}`;
+ const array = ids.length ? `ARRAY[${ids.map(id => `'${id}'`).join(', ')}]::text[]` : 'ARRAY[]::text[]';
+ const listed = ids.length ? ` OR ${alias}.folder_rule_ids <@ ${array}` : '';
+ const lineage = derived ? ` OR COALESCE(gbrain_access_lineage_rules(${alias}.source_id, ${alias}.folder_rule_ids) <@ ${array}, true)` : '';
+ return `(${alias}.folder_rule_ids IS NULL${listed}${lineage})${coverageSql(alias)}`;
}
/**
@@ -178,52 +192,70 @@ 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 for an owner read (CallerAccess.ownerLineage), else null. */
-function ownerReadPage(access: CallerAccess): string | null {
- if (!access.ownerLineage) return null;
+/**
+ * GST-2490 / GBRA-108 design 3: the reader's own member page for a lineage read (CallerAccess.lineage: an owner read,
+ * or a listed member's read under access.members_read_lineage), else null.
+ */
+function lineageReadPage(access: CallerAccess): string | null {
+ if (!access.lineage) 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;
+ return access.ownerReadsRestricted ? lineageReadPage(access) : null;
+}
+
+/** GBRA-108 design 2: the member pages of the audience members an owner read treats as naming the owner; none for any other read. */
+function audiencePages(access: CallerAccess): string[] {
+ return access.owner && access.lineage ? access.audienceKindMembers.filter(id => ACCESS_ID_RE.test(id)).map(id => `${MEMBER_PAGE_PREFIX}${id}`) : [];
+}
+
+/** GBRA-108 design 2: `alias` is an audience member's own member page (FALSE when there is none). */
+function audiencePageSql(alias: string, pages: readonly string[]): string {
+ return pages.length ? `${alias}.slug IN (${pages.map(p => `'${p}'`).join(', ')})` : 'FALSE';
}
-/** 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}')`;
+/** GST-2490: `alias` is not another member's own member page (the reader's own one, and GBRA-108 an audience member's for the owner, pass). */
+function notOtherMemberPageSql(alias: string, ownPage: string, audience: readonly string[] = []): string {
+ return `(NOT starts_with(${alias}.slug, '${MEMBER_PAGE_PREFIX}') OR ${alias}.slug = '${ownPage}'${audience.length ? ` OR ${audiencePageSql(alias, audience)}` : ''})`;
}
const textArraySql = (values: readonly string[]): string => values.length ? `ARRAY[${values.map(v => `'${v}'`).join(', ')}]::text[]` : 'ARRAY[]::text[]';
/**
- * 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.
+ * GST-2490: originAllowedSql for a lineage read. A derived page passes when the reader reads every origin of it
+ * (gbrain_access_origin_hidden_for with the reader's identity and satisfied rules, v304/v305), so a page whose readers or
+ * rule name the reader keeps its derivatives for it; under the owner opt-in every origin passes except another member's
+ * own member page and pending coverage. GBRA-108: an owner read passes audience members' pages as origins naming the
+ * owner. The identity, rule ids and member ids are validated on the record, so they embed as literals.
*/
-function ownerOriginAllowedSql(p: string, access: CallerAccess, ownPage: string): string {
+function lineageOriginAllowedSql(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_for(${p}.id, ${p}.source_id, ${p}.type, ${p}.frontmatter, ${textArraySql(identity)}, ${textArraySql(satisfied)}, ${access.ownerReadsRestricted}, '${ownPage}'))`;
+ OR NOT gbrain_access_origin_hidden_for(${p}.id, ${p}.source_id, ${p}.type, ${p}.frontmatter, ${textArraySql(identity)}, ${textArraySql(satisfied)}, ${access.ownerReadsRestricted}, '${ownPage}', ${textArraySql(audiencePages(access))}))`;
}
/**
- * 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.
+ * GST-2490: the member-access part for a lineage read: the reader's readers and folder rules as for any member, with
+ * its lineage (lineageOriginAllowedSql) instead of the every-caller one. Under the owner opt-in, a page that is not
+ * another member's own member page passes too, outside a prefix that reads as nobody. GBRA-108 design 2: for an owner
+ * read an audience member's own member page reads as if its readers named the owner. `derived` judges the page as an
+ * origin (a fact's provenance page; raw-only rules do not count).
*/
-function ownerAccessSql(pageAlias: string, access: CallerAccess, ownPage: string): string {
- const notOther = notOtherMemberPageSql(pageAlias, ownPage);
+function lineageAccessSql(pageAlias: string, access: CallerAccess, ownPage: string, derived = false): string {
+ const audience = audiencePages(access);
+ const notOther = notOtherMemberPageSql(pageAlias, ownPage, audience);
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 readers = audience.length ? `(${readersAllowedSql(pageAlias, access.identity)} OR ${audiencePageSql(pageAlias, audience)})` : readersAllowedSql(pageAlias, access.identity);
+ const listed = `(${readers} AND ${folderRulesAllowedSql(pageAlias, access.satisfiedRuleIds, derived)})`;
const page = access.ownerReadsRestricted ? `(${listed} OR (${notOther}${coverageSql(pageAlias)}))` : listed;
- return `(${page} AND ${ownerOriginAllowedSql(pageAlias, access, ownPage)})`;
+ return `(${page} AND ${lineageOriginAllowedSql(pageAlias, access, ownPage)})`;
}
/**
@@ -299,16 +331,24 @@ export interface CallerAccess {
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.
+ * GST-2490 / GBRA-108 design 3: a lineage read, one member speaking for itself in a non-mutating operation: the owner
+ * always, any other member only under access.members_read_lineage. Derived pages and facts pass when that member reads
+ * every origin (lineageOriginAllowedSql) instead of being hidden from every remote caller. Never an audience of
+ * several, an unbound credential or an attested call.
*/
- ownerLineage: boolean;
+ lineage: 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
- * their facts to the owner, except another member's own member page and what derives from it (ownerAccessSql).
+ * GST-2490: an owner read (owner and lineage) on a brain whose operator turned on access.owner_reads_restricted:
+ * readers lists, folder rules and page rules stop closing pages, their derivatives and their facts to the owner,
+ * except another member's own member page and what derives from it (lineageAccessSql).
*/
ownerReadsRestricted: boolean;
+ /**
+ * GBRA-108 design 2: the enabled members of kind audience (a group chat, a shared assistant), kept only on an owner
+ * read (owner and lineage): the owner reads each one's own member page, its older versions, its derived pages and its
+ * facts as if its readers named the owner. Ids pass ACCESS_ID_RE, so they embed as literals; empty otherwise.
+ */
+ audienceKindMembers: readonly string[];
applyRemoteReadPolicy: boolean;
restricted: boolean;
/** The fresh remote policy (readRemotePolicyNow) a remote request read when it started; null outside one. */
@@ -319,7 +359,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, ownerLineage: 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, lineage: false, ownerReadsRestricted: false, audienceKindMembers: [], 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). */
@@ -345,18 +385,24 @@ 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),
- ...ownerReads(access.owner ?? (fresh ? false : base.owner), audienceIdentities.length <= 1,
- access.ownerLineage ?? (fresh ? false : base.ownerLineage), access.ownerReadsRestricted ?? (fresh ? false : base.ownerReadsRestricted)),
+ ...lineageReads(access.owner ?? (fresh ? false : base.owner), audienceIdentities.length <= 1,
+ access.lineage ?? (fresh ? false : base.lineage), access.ownerReadsRestricted ?? (fresh ? false : base.ownerReadsRestricted),
+ access.audienceKindMembers ?? (fresh ? [] : base.audienceKindMembers)),
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 };
+/**
+ * GST-2490 / GBRA-108: the lineage flags of a record. Lineage needs one identity (never an audience of several); the owner
+ * opt-in and the audience members need an owner read.
+ */
+function lineageReads(owner: boolean, single: boolean, lineage: boolean, readsRestricted: boolean, audienceKind: readonly string[]): Pick<CallerAccess, 'lineage' | 'ownerReadsRestricted' | 'audienceKindMembers'> {
+ const read = single && lineage;
+ const ownerRead = owner && read;
+ return { lineage: read, ownerReadsRestricted: ownerRead && readsRestricted,
+ audienceKindMembers: Object.freeze(ownerRead && audienceKind.every(id => ACCESS_ID_RE.test(id)) ? [...new Set(audienceKind)].sort() : []) };
}
/** Runs `fn` outside any caller's record, for work a request spawns that must not inherit its view. */
@@ -401,18 +447,21 @@ export function callerIdentities(): readonly (readonly string[])[] {
/** GBRA-231: readersAllow for the current caller (every audience entry must be a reader). */
export function callerReadersAllow(frontmatter: unknown, slug?: string): boolean {
- const ownPage = ownerOptInPage(currentCallerAccess());
+ const access = currentCallerAccess();
+ const ownPage = ownerOptInPage(access);
+ if (typeof slug === 'string' && audiencePages(access).includes(slug)) return true;
if (ownPage && typeof slug === 'string' && (!slug.startsWith(MEMBER_PAGE_PREFIX) || slug === ownPage)) return true;
return callerIdentities().every(identity => readersAllow(frontmatter, identity));
}
/** GBRA-231: readersAllowedSql for the current caller, one conjunct per audience entry. */
export function callerReadersAllowedSql(alias: string, row: 'page' | 'snapshot' = 'page'): string {
- const ownPage = ownerOptInPage(currentCallerAccess());
- if (ownPage) {
- const notOther = row === 'snapshot' ? `EXISTS (SELECT 1 FROM pages sp WHERE sp.id = ${alias}.page_id AND ${notOtherMemberPageSql('sp', ownPage)})` : notOtherMemberPageSql(alias, ownPage);
- return `(${readersAllowedSql(alias, currentCallerAccess().identity, row)} OR ${notOther})`;
- }
+ const access = currentCallerAccess();
+ const ownPage = ownerOptInPage(access);
+ const audience = audiencePages(access);
+ const onPage = (test: (pageAlias: string) => string) => row === 'snapshot' ? `EXISTS (SELECT 1 FROM pages sp WHERE sp.id = ${alias}.page_id AND ${test('sp')})` : test(alias);
+ if (ownPage) return `(${readersAllowedSql(alias, access.identity, row)} OR ${onPage(a => notOtherMemberPageSql(a, ownPage, audience))})`;
+ if (audience.length) return `(${readersAllowedSql(alias, access.identity, row)} OR ${onPage(a => audiencePageSql(a, audience))})`;
return callerIdentities().map(identity => readersAllowedSql(alias, identity, row)).join(' AND ');
}
@@ -423,8 +472,8 @@ function validAudienceEntry(entry: string): boolean {
function callerAccessSql(pageAlias: string): string {
const access = currentCallerAccess();
- const ownPage = ownerReadPage(access);
- if (ownPage) return ownerAccessSql(pageAlias, access, ownPage);
+ const ownPage = lineageReadPage(access);
+ if (ownPage) return lineageAccessSql(pageAlias, access, ownPage);
return access.audienceIdentities.length ? accessAllowedForAllSql(pageAlias, access.audienceIdentities, access.satisfiedRuleIds)
: accessAllowedSql(pageAlias, access.identity);
}
@@ -473,8 +522,8 @@ export function callerAccessAllowedSql(pageAlias: string): string {
* part, then the privacy part unless `hidePrivate` is false. With an empty
* identity and `hidePrivate` it equals privatePagesFilterFragment.
*/
-export function readPolicyFragment(pageAlias: string, identity: readonly string[] | { all: readonly (readonly string[])[] }, hidePrivate: boolean, satisfied?: readonly string[]): string {
- const access = 'all' in identity ? accessAllowedForAllSql(pageAlias, identity.all, satisfied ?? []) : accessAllowedSql(pageAlias, identity, satisfied);
+export function readPolicyFragment(pageAlias: string, identity: readonly string[] | { all: readonly (readonly string[])[] }, hidePrivate: boolean, satisfied?: readonly string[], derived = false): string {
+ const access = 'all' in identity ? accessAllowedForAllSql(pageAlias, identity.all, satisfied ?? [], derived) : accessAllowedSql(pageAlias, identity, satisfied ?? satisfiedFor(identity), derived);
return `(${access} AND ${hidePrivate ? privacyPartSql(pageAlias) : 'TRUE'})`;
}
@@ -764,18 +813,22 @@ export function privateTimelineEventFilterForCaller(timelineAlias: string): stri
* read, which is what the hatches did to these reads before member access (`excludePrivate` was false then).
* Outside a remote record nothing relaxes it. GST-359 C2: a fact on the caller's own member page
* (`memory/members/<member>`, one attested or bound member) alone is judged as the caller, so its member reads it back;
- * every other page, other members' pages included, keeps the empty identity.
+ * every other page, other members' pages included, keeps the empty identity. GST-2490 / GBRA-108: a lineage read judges
+ * every other page that is not a member page as the reader, and an owner read an audience member's page too. The
+ * provenance page is judged as an origin: a raw-only rule (covers_derived false) does not hide the facts from its pages.
*/
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 = ownerReadPage(access);
+ const ownPage = lineageReadPage(access);
+ const audience = audiencePages(access);
+ const memberPage = audience.length ? `(starts_with(pp.slug, '${MEMBER_PAGE_PREFIX}') AND NOT ${audiencePageSql('pp', audience)})` : `starts_with(pp.slug, '${MEMBER_PAGE_PREFIX}')`;
const otherwise = ownPage
- ? `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);
+ ? `CASE WHEN ${memberPage} THEN ${readPolicyFragment('pp', [], hide, [], true)} ELSE (${lineageAccessSql('pp', access, ownPage, true)} AND ${hide ? privacyPartSql('pp') : 'TRUE'}) END`
+ : readPolicyFragment('pp', [], hide, [], true);
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`
+ ? `CASE WHEN pp.slug = '${MEMBER_PAGE_PREFIX}${member}' THEN ${readPolicyFragment('pp', access.identity, hide, access.satisfiedRuleIds, true)} ELSE ${otherwise} END`
: otherwise;
return `(NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${policy})) AND ${privateEntityFilterForCaller(factAlias)})`;
}
@@ -806,7 +859,7 @@ export function callerRelaxesPrivacy(): boolean {
export function privateProvenanceFilterFragment(factAlias: string): string {
return `NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id ` +
- `AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${privatePagesFilterFragment('pp')}))`;
+ `AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${privatePagesFilterFragment('pp', true)}))`;
}
/**
@@ -934,7 +987,7 @@ export async function remotePrivacyRelaxed(engine: BrainEngine): Promise<boolean
return expose;
}
-export interface RemotePolicy { privacyRelaxed: boolean; restricted: boolean; ownerMember?: string | null; ownerReadsRestricted?: boolean }
+export interface RemotePolicy { privacyRelaxed: boolean; restricted: boolean; ownerMember?: string | null; ownerReadsRestricted?: boolean; membersReadLineage?: boolean }
/**
* The remote read policy read fresh, for publication: whether an operator
@@ -945,10 +998,10 @@ export interface RemotePolicy { privacyRelaxed: boolean; restricted: boolean; ow
*/
export async function readRemotePolicyNow(engine: Pick<BrainEngine, 'executeRaw'>): Promise<RemotePolicy> {
try {
- const rows = await engine.executeRaw<{ key: string; value: string }>('SELECT key, value FROM config WHERE key = ANY($1::text[])', [[REMOTE_PRIVATE_PAGES_KEY, ACCESS_RESTRICTIONS_KEY, OWNER_MEMBER_KEY, OWNER_READS_RESTRICTED_KEY]]);
+ const rows = await engine.executeRaw<{ key: string; value: string }>('SELECT key, value FROM config WHERE key = ANY($1::text[])', [[REMOTE_PRIVATE_PAGES_KEY, ACCESS_RESTRICTIONS_KEY, OWNER_MEMBER_KEY, OWNER_READS_RESTRICTED_KEY, MEMBERS_READ_LINEAGE_KEY]]);
return remotePolicyFrom(Object.fromEntries(rows.map(r => [r.key, r.value])));
} catch {
- return { privacyRelaxed: process.env.GBRAIN_REMOTE_PRIVATE_PAGES === '1', restricted: true, ownerMember: null, ownerReadsRestricted: false };
+ return { privacyRelaxed: process.env.GBRAIN_REMOTE_PRIVATE_PAGES === '1', restricted: true, ownerMember: null, ownerReadsRestricted: false, membersReadLineage: false };
}
}
@@ -966,7 +1019,8 @@ function remotePolicyFrom(config: Record<string, string>): RemotePolicy {
const hatch = process.env.GBRAIN_REMOTE_PRIVATE_PAGES === '1';
const owner = config[OWNER_MEMBER_KEY]?.trim();
return { privacyRelaxed: hatch || ['visible', 'true', '1'].includes(config[REMOTE_PRIVATE_PAGES_KEY] ?? ''), restricted: config[ACCESS_RESTRICTIONS_KEY] === '1',
- ownerMember: owner && ACCESS_ID_RE.test(owner) ? owner : null, ownerReadsRestricted: config[OWNER_READS_RESTRICTED_KEY]?.trim() === '1' };
+ ownerMember: owner && ACCESS_ID_RE.test(owner) ? owner : null, ownerReadsRestricted: config[OWNER_READS_RESTRICTED_KEY]?.trim() === '1',
+ membersReadLineage: config[MEMBERS_READ_LINEAGE_KEY]?.trim() === '1' };
}
/** GBRA-218: does this brain hold member-access restrictions? Read live (the request snapshot answers it inside a read); unreadable counts as yes. */
diff --git a/src/schema.sql b/src/schema.sql
index 51817337e2..8c17094d96 100644
--- a/src/schema.sql
+++ b/src/schema.sql
@@ -3744,7 +3744,7 @@ BEGIN
FOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS path
FROM 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_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 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_lineage_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 1
LOOP
diff --git a/test/access-audience-members.test.ts b/test/access-audience-members.test.ts
new file mode 100644
index 0000000000..8104a21488
--- /dev/null
+++ b/test/access-audience-members.test.ts
@@ -0,0 +1,155 @@
+import { afterAll, beforeAll, describe, expect, spyOn, test } from 'bun:test';
+import type { DoctorContext } from '../src/commands/doctor/context.ts';
+import { accessLineageEntry } from '../src/commands/doctor/checks/access-lineage.ts';
+import { runAccess, whoCanRead } from '../src/commands/access.ts';
+import { addMember, getMember, setMemberKind } from '../src/core/access/members.ts';
+import { setOwnerReadsRestricted } from '../src/core/access/owner.ts';
+import { callerIdentityKey } from '../src/core/access/member-facts.ts';
+import { knobsHash, resolveSearchMode } from '../src/core/search/mode.ts';
+import { __resetPrivateVisibilityCacheForTests, withCallerAccess } from '../src/core/search/private-visibility.ts';
+import { authorizePageVisibility } from '../src/core/persistence/page-visibility.ts';
+import type { WriteAuthority } from '../src/core/persistence/model.ts';
+import { buildLineageBrain, derivedOf, factsOf, type LineageBrain, type Seen } from './helpers/access-lineage-fixture.ts';
+import { testBackends } from './helpers/test-backends.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+
+/**
+ * GBRA-108 Design 2: audience members (access_members.kind = 'audience': a group chat, a shared assistant).
+ * 1. Protects: the brain owner reads an audience member's own member page (memory/members/<id>), its older versions,
+ * its derived pages and its facts as if that page named the owner, with the owner opt-in off or on. Only that page:
+ * a page that merely lists the audience stays under the usual rules (the owner opt-in opens it), and a person
+ * member's member page stays closed to the owner. Only the operator on the brain host sets a kind; reads of every
+ * other caller, and every write, are identical whatever the kind.
+ * 2. Fails when: the owner misses the audience member page or a derivative, fact or version of it; the owner reads it
+ * while the member is a person; the owner reads a person member's page, with or without the opt-in; any other
+ * caller's view changes with the kind; the publication gate lets the owner write the audience page; a remote caller
+ * sets a kind; the --as owner preview disagrees; or the cache keys do not change with the audience list.
+ * 3. Real seams: tokens minted by the token service and verified by the serve --http verifier, dispatched through MCP
+ * dispatch (remote: true); the access CLI; a folder rule in the database (repo-less) and in a committed access.yml
+ * (git); PGLite, and Postgres with DATABASE_URL; embeddings stubbed.
+ */
+
+const OWNER = 'owner-example';
+const GC = 'groupchat-example';
+const ORIGINS = {
+ gc: { slug: 'memory/members/' + GC, fm: ['readable_by: [' + GC + ']'], derive: true },
+ gcnote: { slug: 'notes/gc-note', fm: ['readable_by: [' + GC + ']'], derive: false },
+ dm: { slug: 'memory/members/alice-example', fm: ['readable_by: [alice-example]'], derive: true },
+ open: { slug: 'notes/open-example', fm: [] as string[], derive: false },
+};
+const OTHERS = ['alice', 'gc', 'unbound', 'granted'] as const;
+
+describe('audience member kind: who may set it', () => {
+ let engine: PGLiteEngine;
+ beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({ engine: 'pglite' } as never); await engine.initSchema(); }, 120_000);
+ afterAll(async () => { await engine?.disconnect(); });
+
+ test('a remote caller cannot set or add an audience kind; ids and kinds are validated', async () => {
+ await addMember(engine, GC);
+ expect((await getMember(engine, GC))?.kind).toBe('person');
+ await expect(setMemberKind(engine, GC, 'audience', { remote: true })).rejects.toMatchObject({ code: 'permission_denied' });
+ await expect(setMemberKind(engine, GC, 'audience', {})).rejects.toMatchObject({ code: 'permission_denied' });
+ await expect(addMember(engine, 'chat-two-example', { kind: 'audience', remote: true })).rejects.toMatchObject({ code: 'permission_denied' });
+ expect(await getMember(engine, 'chat-two-example')).toBeNull();
+ await expect(setMemberKind(engine, GC, 'robot', { remote: false })).rejects.toThrow();
+ await expect(setMemberKind(engine, 'Not An Id', 'audience', { remote: false })).rejects.toThrow();
+ expect((await getMember(engine, GC))?.kind).toBe('person');
+ expect((await setMemberKind(engine, GC, 'audience', { remote: false })).changed).toBe(true);
+ expect((await addMember(engine, 'chat-two-example', { kind: 'audience', remote: false })).member.kind).toBe('audience');
+ }, 120_000);
+
+ test('the semantic cache and the caller key change with the owner\'s audience members', () => {
+ const knobs = resolveSearchMode({ mode: 'balanced' });
+ const base = { identity: ['member:' + OWNER], owner: true, lineage: true, applyRemoteReadPolicy: true, hidePrivate: true, privateReadableSources: [] as string[] };
+ const keys = (audienceKindMembers: string[]) => withCallerAccess({ ...base, audienceKindMembers }, () => [knobsHash(knobs, { excludePrivate: true }), callerIdentityKey()]);
+ const none = keys([]);
+ const one = keys([GC]);
+ const two = keys([GC, 'chat-two-example']);
+ for (const i of [0, 1]) expect(new Set([none[i], one[i], two[i]]).size).toBe(3);
+ });
+});
+
+for (const kind of testBackends()) {
+ for (const store of ['database', 'git'] as const) {
+ describe(`audience members (${kind}, rules in ${store === 'git' ? 'access.yml' : 'the database, repo-less'})`, () => {
+ let b: LineageBrain;
+ const SRC = 'aud-src';
+ async function cli(args: string[]): Promise<any> {
+ const lines: string[] = [];
+ const spy = spyOn(console, 'log').mockImplementation((...a: unknown[]) => { lines.push(a.map(String).join(' ')); });
+ try { await runAccess(b.engine, [...args, '--json']); } finally { spy.mockRestore(); }
+ return JSON.parse(lines.join('\n'));
+ }
+ const withOptIn = async <T>(fn: () => Promise<T>): Promise<T> => {
+ await setOwnerReadsRestricted(b.engine, true, { remote: false });
+ __resetPrivateVisibilityCacheForTests();
+ try { return await fn(); } finally { await setOwnerReadsRestricted(b.engine, false, { remote: false }); __resetPrivateVisibilityCacheForTests(); }
+ };
+ const doctor = async () => Object.fromEntries((await accessLineageEntry.run({ engine: b.engine } as unknown as DoctorContext) as Array<{ name: string; status: string; message: string }>).map(c => [c.name, c]));
+ const writable = async () => {
+ const authority = { version: 1, principal: { kind: 'legacy_token', id: b.tokenIds.owner }, remote: true, excludePrivate: true, sourceId: SRC,
+ sourceIncarnation: 'unused', scopes: ['read', 'write'], operations: null, slugPrefixes: null } as WriteAuthority;
+ const out: string[] = [];
+ for (const [o, s] of Object.entries(ORIGINS)) if (await authorizePageVisibility(b.engine, authority, s.slug).then(() => true, () => false)) out.push(o);
+ return out;
+ };
+ const person: Record<string, Seen> = {};
+
+ beforeAll(async () => {
+ b = await buildLineageBrain({
+ kind, store, src: SRC, tag: 'aud', origins: ORIGINS,
+ rules: [{ id: 'vault', prefix: 'vault/', readable_by: ['member:alice-example'] }],
+ members: [OWNER, 'alice-example', GC], owner: OWNER,
+ callers: [{ name: 'owner', member: OWNER }, { name: 'as-owner', as: OWNER }, { name: 'alice', member: 'alice-example' }, { name: 'gc', member: GC },
+ { name: 'unbound' }, { name: 'granted', grantedSources: true }],
+ });
+ }, 300_000);
+ afterAll(async () => { await b?.close(); }, 60_000);
+
+ test('while the member is a person, the owner reads no member page but its own, opt-in off or on', async () => {
+ expect(await b.seenBy('owner')).toEqual(b.expected(['open'], []));
+ expect(await withOptIn(() => b.seenBy('owner'))).toEqual(b.expected(['gcnote', 'open'], []));
+ expect(await b.seenBy('as-owner')).toEqual(await b.seenBy('owner'));
+ for (const who of OTHERS) person[who] = await b.seenBy(who);
+ // The audience reads its own pages, and the facts recorded on its own member page (v0.60.682.0 behaviour).
+ expect(person.gc.get_page).toEqual(['gc', 'gcnote', 'open']);
+ expect(person.gc['recall since']).toEqual(['gc.fact']);
+ expect(person.alice).toEqual(b.expected(['dm', 'open'], ['dm.fact']));
+ expect(person.unbound).toEqual(b.expected(['open'], []));
+ expect(person.granted).toEqual(person.unbound);
+ expect((await whoCanRead(b.engine, ORIGINS.gc.slug, SRC))[0]?.members).toEqual([GC]);
+ expect((await doctor()).access_audience_members.message).toStartWith('Not applicable');
+ }, 600_000);
+
+ test('as an audience, the owner reads its member page, versions, derived pages and facts with the opt-in off', async () => {
+ const set = await cli(['access', 'member', 'kind', GC, 'audience'].slice(1));
+ expect(set).toMatchObject({ changed: true, member: { id: GC, kind: 'audience' } });
+ __resetPrivateVisibilityCacheForTests();
+ const audience = b.expected(['gc', ...derivedOf(b.keys, ['gc']), 'open'], factsOf(b.keys, ['gc']));
+ expect(await b.seenBy('owner')).toEqual(audience);
+ expect(await b.seenBy('as-owner')).toEqual(audience);
+ const listed = await cli(['member', 'list']);
+ expect(listed.members.find((m: { id: string }) => m.id === GC)?.kind).toBe('audience');
+ const who = (await whoCanRead(b.engine, ORIGINS.gc.slug, SRC))[0]!;
+ expect(who.members).toEqual([GC, OWNER]);
+ expect(who.note).toContain('member page of an audience member');
+ const checks = await doctor();
+ expect(checks.access_audience_members.message).toContain(GC);
+ }, 600_000);
+
+ test('with the opt-in on, the owner also reads pages that list the audience, and never a person member\'s page', async () => {
+ expect(await withOptIn(() => b.seenBy('owner'))).toEqual(b.expected(['gc', ...derivedOf(b.keys, ['gc']), 'gcnote', 'open'], factsOf(b.keys, ['gc'])));
+ expect(await withOptIn(() => b.seenBy('as-owner'))).toEqual(await withOptIn(() => b.seenBy('owner')));
+ }, 600_000);
+
+ test('every other caller reads exactly the same whatever the kind, and no write widens', async () => {
+ for (const who of OTHERS) expect({ who, seen: await b.seenBy(who) }).toEqual({ who, seen: person[who]! });
+ expect(await writable()).toEqual(['open']);
+ await setMemberKind(b.engine, GC, 'person', { remote: false });
+ expect(await writable()).toEqual(['open']);
+ __resetPrivateVisibilityCacheForTests();
+ expect(await b.seenBy('owner')).toEqual(b.expected(['open'], []));
+ }, 600_000);
+ });
+ }
+}
diff --git a/test/access-members-read-lineage.test.ts b/test/access-members-read-lineage.test.ts
new file mode 100644
index 0000000000..84fe2388c6
--- /dev/null
+++ b/test/access-members-read-lineage.test.ts
@@ -0,0 +1,166 @@
+import { afterAll, beforeAll, describe, expect, spyOn, test } from 'bun:test';
+import type { DoctorContext } from '../src/commands/doctor/context.ts';
+import { accessLineageEntry } from '../src/commands/doctor/checks/access-lineage.ts';
+import { accessCheck, runAccess, whoCanRead } from '../src/commands/access.ts';
+import { membersReadLineageOn, setMembersReadLineage } from '../src/core/access/lineage.ts';
+import { setOwnerReadsRestricted } from '../src/core/access/owner.ts';
+import { callerIdentityKey } from '../src/core/access/member-facts.ts';
+import { knobsHash, resolveSearchMode } from '../src/core/search/mode.ts';
+import { __resetPrivateVisibilityCacheForTests, currentCallerAccess, withCallerAccess } from '../src/core/search/private-visibility.ts';
+import { authorizePageVisibility } from '../src/core/persistence/page-visibility.ts';
+import type { WriteAuthority } from '../src/core/persistence/model.ts';
+import { buildLineageBrain, derivedOf, factsOf, type LineageBrain, type Seen } from './helpers/access-lineage-fixture.ts';
+import { testBackends } from './helpers/test-backends.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+
+/**
+ * GBRA-108 Design 3: config access.members_read_lineage (off by default; set only by the operator on the brain host).
+ * 1. Protects: with it on, a member's credential speaking for itself (no audience, or an audience of exactly that one
+ * member) reads the atoms, derived_from pages, synthesized concepts, Life Chronicle events and facts whose origins it
+ * reads, on every read path, as the owner already does. Off, nothing changes. An unbound credential, a
+ * granted_sources credential, an audience of several members, and the owner (whose own lineage and opt-in are
+ * separate) read exactly the same off and on, and no write widens.
+ * 2. Fails when: a member misses a derivative or fact of an origin it reads, or reads one of an origin it does not; any
+ * non-target caller's view changes; the --as preview disagrees with the key; whoami, access check, who-can-read or
+ * doctor do not report the setting; a remote caller turns it on; or the cache keys do not change with it.
+ * 3. Real seams: tokens minted by the token service and verified by the serve --http verifier, dispatched through MCP
+ * dispatch (remote: true), with and without an on-behalf-of audience; the access CLI; a folder rule in the database
+ * (repo-less) and in a committed access.yml (git); PGLite, and Postgres with DATABASE_URL; embeddings stubbed.
+ */
+
+const OWNER = 'owner-example';
+const ORIGINS = {
+ al: { slug: 'notes/al-example', fm: ['readable_by: [alice-example]'], derive: true },
+ team: { slug: 'team/origin-example', fm: [] as string[], derive: true },
+ both: { slug: 'notes/both-example', fm: ['readable_by: [alice-example, bob-example]'], derive: true },
+ open: { slug: 'notes/open-example', fm: [] as string[], derive: false },
+};
+const UNCHANGED = ['owner', 'carol', 'pair', 'unbound', 'granted'] as const;
+
+describe('members read lineage: who may set it, and the cache keys', () => {
+ let engine: PGLiteEngine;
+ beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({ engine: 'pglite' } as never); await engine.initSchema(); }, 120_000);
+ afterAll(async () => { await engine?.disconnect(); });
+
+ test('a remote caller cannot turn it on', async () => {
+ expect(await membersReadLineageOn(engine)).toBe(false);
+ await expect(setMembersReadLineage(engine, true, { remote: true })).rejects.toMatchObject({ code: 'permission_denied' });
+ await expect(setMembersReadLineage(engine, true, {})).rejects.toMatchObject({ code: 'permission_denied' });
+ expect(await membersReadLineageOn(engine)).toBe(false);
+ expect(await setMembersReadLineage(engine, true, { remote: false })).toMatchObject({ members_read_lineage: true });
+ expect(await membersReadLineageOn(engine)).toBe(true);
+ }, 120_000);
+
+ test('the semantic cache and the caller key differ for a member read with lineage', () => {
+ const knobs = resolveSearchMode({ mode: 'balanced' });
+ const base = { identity: ['member:alice-example'], applyRemoteReadPolicy: true, hidePrivate: true, privateReadableSources: [] as string[] };
+ const keys = (lineage: boolean, owner = false) => withCallerAccess({ ...base, lineage, owner }, () => [knobsHash(knobs, { excludePrivate: true }), callerIdentityKey()]);
+ const [off, on, ownerOn] = [keys(false), keys(true), keys(true, true)];
+ for (const i of [0, 1]) expect(new Set([off[i], on[i], ownerOn[i]]).size).toBe(3);
+ const pair = withCallerAccess({ identity: [], audience: ['member:alice-example', 'member:bob-example'], audienceIdentities: [['member:alice-example'], ['member:bob-example']], lineage: true },
+ () => currentLineage());
+ expect(pair).toBe(false);
+ });
+});
+
+function currentLineage(): boolean {
+ return currentCallerAccess().lineage;
+}
+
+for (const kind of testBackends()) {
+ for (const store of ['database', 'git'] as const) {
+ describe(`members read lineage (${kind}, rules in ${store === 'git' ? 'access.yml' : 'the database, repo-less'})`, () => {
+ let b: LineageBrain;
+ const SRC = 'mrl-src';
+ const off: Record<string, Seen> = {};
+ async function cli(args: string[]): Promise<any> {
+ const lines: string[] = [];
+ const spy = spyOn(console, 'log').mockImplementation((...a: unknown[]) => { lines.push(a.map(String).join(' ')); });
+ try { await runAccess(b.engine, [...args, '--json']); } finally { spy.mockRestore(); }
+ return JSON.parse(lines.join('\n'));
+ }
+ const doctor = async () => Object.fromEntries((await accessLineageEntry.run({ engine: b.engine } as unknown as DoctorContext) as Array<{ name: string; status: string; message: string }>).map(c => [c.name, c]));
+ const whoami = async (who: string) => JSON.parse(await b.call(who, 'whoami', {}));
+ const writable = async (who: string) => {
+ const authority = { version: 1, principal: { kind: 'legacy_token', id: b.tokenIds[who] }, remote: true, excludePrivate: true, sourceId: SRC,
+ sourceIncarnation: 'unused', scopes: ['read', 'write'], operations: null, slugPrefixes: null } as WriteAuthority;
+ const out: string[] = [];
+ for (const [o, s] of Object.entries(ORIGINS)) if (await authorizePageVisibility(b.engine, authority, s.slug).then(() => true, () => false)) out.push(o);
+ return out;
+ };
+ const ALL = ['alice', 'bob', 'solo', 'as-alice', ...UNCHANGED];
+
+ beforeAll(async () => {
+ b = await buildLineageBrain({
+ kind, store, src: SRC, tag: 'mrl', origins: ORIGINS,
+ rules: [{ id: 'team', prefix: 'team/', readable_by: ['group:team-a'] }],
+ members: [OWNER, 'alice-example', 'bob-example', 'carol-example'], groups: { 'team-a': ['bob-example'] }, owner: OWNER,
+ callers: [{ name: 'owner', member: OWNER }, { name: 'alice', member: 'alice-example' }, { name: 'bob', member: 'bob-example' }, { name: 'carol', member: 'carol-example' },
+ { name: 'as-alice', as: 'alice-example' },
+ { name: 'solo', mayActFor: ['member:alice-example', 'member:bob-example'], audience: ['alice-example'] },
+ { name: 'pair', mayActFor: ['member:alice-example', 'member:bob-example'], audience: ['alice-example', 'bob-example'] },
+ { name: 'unbound' }, { name: 'granted', grantedSources: true }],
+ });
+ }, 300_000);
+ afterAll(async () => { await b?.close(); }, 60_000);
+
+ test('off (the default): no member but the owner reads a derived page or fact of a page kept to readers', async () => {
+ for (const who of ALL) off[who] = await b.seenBy(who);
+ expect(off.alice).toEqual(b.expected(['al', 'both', 'open'], []));
+ expect(off.bob).toEqual(b.expected(['team', 'both', 'open'], []));
+ expect(off.solo).toEqual(off.alice);
+ expect(off['as-alice']).toEqual(off.alice);
+ expect(off.pair).toEqual(b.expected(['both', 'open'], []));
+ for (const who of ['owner', 'carol', 'unbound', 'granted']) expect({ who, seen: off[who] }).toEqual({ who, seen: b.expected(['open'], []) });
+ expect((await whoami('alice')).access.members_read_lineage).toBeUndefined();
+ expect((await doctor()).access_members_read_lineage.message).toStartWith('Not applicable');
+ expect((await accessCheck(b.engine, { token: 'alice' })).members_read_lineage).toBe(false);
+ }, 600_000);
+
+ test('on: a member speaking for itself reads the derived pages and facts of every origin it reads, on every path', async () => {
+ expect(await cli(['members-read-lineage', 'on'])).toMatchObject({ members_read_lineage: true });
+ __resetPrivateVisibilityCacheForTests();
+ const alice = b.expected(['al', 'both', 'open', ...derivedOf(b.keys, ['al', 'both'])], factsOf(b.keys, ['al', 'both']));
+ expect(await b.seenBy('alice')).toEqual(alice);
+ expect(await b.seenBy('solo')).toEqual(alice);
+ expect(await b.seenBy('as-alice')).toEqual(alice);
+ expect(await b.seenBy('bob')).toEqual(b.expected(['team', 'both', 'open', ...derivedOf(b.keys, ['team', 'both'])], factsOf(b.keys, ['team', 'both'])));
+ }, 600_000);
+
+ test('on: the owner, another member, an audience of several, an unbound and a granted_sources credential read the same', async () => {
+ for (const who of UNCHANGED) expect({ who, seen: await b.seenBy(who) }).toEqual({ who, seen: off[who]! });
+ }, 600_000);
+
+ test('on: whoami, access check, who-can-read and doctor report it; no write widens', async () => {
+ const me = await whoami('alice');
+ expect(me.access.members_read_lineage).toBe(true);
+ expect(me.access.members_read_lineage_note).toContain('reaches every member that page lists');
+ const check = await accessCheck(b.engine, { token: 'alice' });
+ expect(check.members_read_lineage).toBe(true);
+ expect(check.explanation).toContain('access.members_read_lineage is on');
+ expect((await whoCanRead(b.engine, ORIGINS.al.slug, SRC))[0]!.note).toContain('access.members_read_lineage is on');
+ expect((await doctor()).access_members_read_lineage.status).toBe('ok');
+ expect((await doctor()).access_members_read_lineage.message).toContain('summaries of a page reach everyone that page lists');
+ for (const who of ['alice', 'bob', 'carol', 'unbound']) {
+ await setMembersReadLineage(b.engine, false, { remote: false });
+ const before = await writable(who);
+ await setMembersReadLineage(b.engine, true, { remote: false });
+ expect({ who, w: await writable(who) }).toEqual({ who, w: before });
+ }
+ }, 600_000);
+
+ test('the owner opt-in stays the owner\'s: it changes nothing for a member reading with lineage', async () => {
+ await setOwnerReadsRestricted(b.engine, true, { remote: false });
+ __resetPrivateVisibilityCacheForTests();
+ try {
+ expect(await b.seenBy('alice')).toEqual(b.expected(['al', 'both', 'open', ...derivedOf(b.keys, ['al', 'both'])], factsOf(b.keys, ['al', 'both'])));
+ } finally {
+ await setOwnerReadsRestricted(b.engine, false, { remote: false });
+ }
+ expect(await cli(['members-read-lineage', 'off'])).toMatchObject({ members_read_lineage: false });
+ __resetPrivateVisibilityCacheForTests();
+ for (const who of ['alice', 'bob', 'solo']) expect({ who, seen: await b.seenBy(who) }).toEqual({ who, seen: off[who]! });
+ }, 600_000);
+ });
+ }
+}
diff --git a/test/access-raw-only-rules.test.ts b/test/access-raw-only-rules.test.ts
new file mode 100644
index 0000000000..88e8a42ab4
--- /dev/null
+++ b/test/access-raw-only-rules.test.ts
@@ -0,0 +1,156 @@
+import { afterAll, beforeAll, describe, expect, spyOn, test } from 'bun:test';
+import type { DoctorContext } from '../src/commands/doctor/context.ts';
+import { accessLineageEntry } from '../src/commands/doctor/checks/access-lineage.ts';
+import { runAccessRules } from '../src/commands/access-rules.ts';
+import { classifyRulebook, parsePolicyYaml, rulebookDigest, rulesFromJson, serializePolicyYaml, type FolderRule } from '../src/core/access/folder-rules.ts';
+import { appliedRules, policyStatus, previewApply } from '../src/core/access/policy.ts';
+import { buildLineageBrain, derivedOf, factsOf, type LineageBrain, type Seen } from './helpers/access-lineage-fixture.ts';
+import { testBackends } from './helpers/test-backends.ts';
+
+/**
+ * GBRA-108 Design 4: raw-only folder and page rules (covers_derived: false).
+ * 1. Protects: a rule keeps the pages it covers to its readers and, by default, also closes the lineage of the pages and
+ * facts derived from them (unchanged on upgrade, same digest). A raw-only rule keeps only its own pages: the atoms,
+ * derived_from pages, synthesized concepts, Life Chronicle events and facts derived from them are read by whoever
+ * reads those derivatives. Turning a rule raw-only is a widening held for gbrain access apply; turning it back applies
+ * at once. The origin's own readers list still closes its lineage.
+ * 2. Fails when: a default rule's digest or reads change; a raw-only proposal widens anything before apply; apply widens
+ * anything beyond the raw-only rule's derived pages and facts, or opens the raw page itself; a derivative of a page
+ * whose readers list names a member opens; the narrowing back is held; or doctor does not list the raw-only rule.
+ * 3. Real seams: tokens minted by the token service and verified by the serve --http verifier, dispatched through MCP
+ * dispatch (remote: true); the access rule CLI; rules in the database (repo-less) and in a committed access.yml
+ * (git); PGLite, and Postgres with DATABASE_URL; embeddings stubbed.
+ */
+
+const ALICE = 'member:alice-example';
+const COVERING: FolderRule[] = [
+ { id: 'transcripts', prefix: 'transcripts/', readable_by: [ALICE] },
+ { id: 'vault', prefix: 'vault/', readable_by: [ALICE, 'group:team-a'] },
+];
+const RAW_ONLY: FolderRule[] = [{ ...COVERING[0]!, covers_derived: false }, COVERING[1]!];
+
+describe('raw-only rule grammar, digest and classification', () => {
+ test('covers_derived: false parses, serializes and round-trips; true is the default and is not carried', () => {
+ const yml = serializePolicyYaml(RAW_ONLY);
+ expect(yml).toContain('covers_derived: false');
+ const parsed = parsePolicyYaml(yml);
+ expect(parsed.ok).toBe(true);
+ if (!parsed.ok) return;
+ expect(parsed.rules.find(r => r.id === 'transcripts')?.covers_derived).toBe(false);
+ expect('covers_derived' in parsed.rules.find(r => r.id === 'vault')!).toBe(false);
+ const explicitTrue = parsePolicyYaml(yml.replace('covers_derived: false', 'covers_derived: true'));
+ expect(explicitTrue.ok && explicitTrue.rules.every(r => !('covers_derived' in r))).toBe(true);
+ expect(serializePolicyYaml(COVERING)).not.toContain('covers_derived');
+ expect(parsePolicyYaml(yml.replace('covers_derived: false', 'covers_derived: maybe')).ok).toBe(false);
+ expect(rulesFromJson(JSON.stringify(RAW_ONLY))).toEqual(rulesFromJson(JSON.stringify(RAW_ONLY)).map(r => r.id === 'transcripts' ? { ...r, covers_derived: false } : r));
+ });
+
+ test('a covering rulebook keeps the digest it had before raw-only rules existed; a raw-only rule changes it', () => {
+ // The digest v0.60.682.0 computed for COVERING, before covers_derived existed.
+
+ expect(rulebookDigest(COVERING)).toBe('7921ac7ce30f5bfc93ebcf0abe88bd4262337ff0a2c6fb003f0f9251281dfd04');
+ expect(rulebookDigest(RAW_ONLY)).not.toBe(rulebookDigest(COVERING));
+ });
+
+ test('covering to raw-only is a held widening; raw-only to covering is a narrowing', () => {
+ const widen = classifyRulebook(COVERING, RAW_ONLY);
+ expect(widen.kind).toBe('widening');
+ expect(widen.held.map(c => [c.rule, c.kind])).toEqual([['transcripts', 'derived_released']]);
+ expect(rulebookDigest(widen.target)).toBe(rulebookDigest(COVERING));
+ const narrow = classifyRulebook(RAW_ONLY, COVERING);
+ expect(narrow.kind).toBe('narrowing');
+ expect(narrow.changes.map(c => [c.rule, c.kind, c.narrowing])).toEqual([['transcripts', 'derived_covered', true]]);
+ expect(narrow.held).toEqual([]);
+ expect(rulebookDigest(narrow.target)).toBe(rulebookDigest(COVERING));
+ });
+});
+
+const ORIGINS = {
+ raw: { slug: 'transcripts/raw-example', fm: [] as string[], derive: true },
+ rdr: { slug: 'transcripts/rdr-example', fm: ['readable_by: [alice-example]'], derive: true },
+ cov: { slug: 'vault/cov-example', fm: [] as string[], derive: true },
+ open: { slug: 'notes/open-example', fm: [] as string[], derive: true },
+};
+const CALLERS = ['alice', 'bob', 'unbound', 'granted'] as const;
+
+for (const kind of testBackends()) {
+ for (const store of ['database', 'git'] as const) {
+ describe(`raw-only rules (${kind}, rules in ${store === 'git' ? 'access.yml' : 'the database, repo-less'})`, () => {
+ let b: LineageBrain;
+ const SRC = 'raw-src';
+ const off: Record<string, Seen> = {};
+
+ async function cli(args: string[]): Promise<any> {
+ const lines: string[] = [];
+ const spy = spyOn(console, 'log').mockImplementation((...a: unknown[]) => { lines.push(a.map(String).join(' ')); });
+ try { await runAccessRules(b.engine, args[0]!, args.slice(1), args.includes('--json')); } finally { spy.mockRestore(); }
+ return JSON.parse(lines.join('\n'));
+ }
+ const doctor = async () => Object.fromEntries((await accessLineageEntry.run({ engine: b.engine } as unknown as DoctorContext) as Array<{ name: string; status: string; message: string; details?: any }>).map(c => [c.name, c]));
+ const views = async () => Object.fromEntries(await Promise.all(CALLERS.map(async c => [c, await b.seenBy(c)] as const))) as Record<string, Seen>;
+
+ beforeAll(async () => {
+ b = await buildLineageBrain({
+ kind, store, src: SRC, tag: 'raw', origins: ORIGINS, rules: COVERING,
+ members: ['alice-example', 'bob-example'], groups: { 'team-a': ['bob-example'] },
+ callers: [{ name: 'alice', member: 'alice-example' }, { name: 'bob', member: 'bob-example' }, { name: 'unbound' }, { name: 'granted', grantedSources: true }],
+ });
+ }, 300_000);
+ afterAll(async () => { await b?.close(); }, 60_000);
+
+ test('by default a rule also keeps the pages and facts derived from its pages to its readers', async () => {
+ Object.assign(off, await views());
+ expect(off.alice).toEqual(b.expected(['raw', 'rdr', 'cov', 'open', ...derivedOf(b.keys, ['open'])], factsOf(b.keys, ['open'])));
+ expect(off.bob).toEqual(b.expected(['cov', 'open', ...derivedOf(b.keys, ['open'])], factsOf(b.keys, ['open'])));
+ expect(off.unbound).toEqual(b.expected(['open', ...derivedOf(b.keys, ['open'])], factsOf(b.keys, ['open'])));
+ expect(off.granted).toEqual(off.unbound);
+ expect((await doctor()).access_raw_only_rules.status).toBe('ok');
+ expect((await doctor()).access_raw_only_rules.message).toStartWith('Not applicable');
+ }, 120_000);
+
+ test('rule add --raw-only is a widening held for access apply: nothing changes until it is approved', async () => {
+ const result = await cli(['rule', 'add', '--id', 'transcripts', '--prefix', 'transcripts/', '--readers', 'alice-example', '--raw-only', '--source', SRC, '--yes', '--json']);
+ expect(JSON.stringify(result)).toContain('derived_released');
+ const status = await policyStatus(b.engine, SRC);
+ expect(status.held.map(c => [c.rule, c.kind])).toEqual([['transcripts', 'derived_released']]);
+ expect(rulebookDigest(status.rules)).toBe(rulebookDigest(COVERING));
+ expect(status.desired?.rules.find(r => r.id === 'transcripts')?.covers_derived).toBe(false);
+ const preview = await previewApply(b.engine, SRC);
+ const widening = preview.widening.find(w => w.change.rule === 'transcripts');
+ expect(widening?.lineage).toBe(true);
+ expect(widening?.gains).toBe('every_source_reader');
+ expect(widening?.sample.sort()).toEqual([ORIGINS.raw.slug, ORIGINS.rdr.slug]);
+ expect(await views()).toEqual(off);
+ }, 120_000);
+
+ test('after apply the only change for any caller is the derived pages and facts of the raw-only rule\'s own pages', async () => {
+ await b.approve();
+ expect((await appliedRules(b.engine, SRC)).find(r => r.id === 'transcripts')?.covers_derived).toBe(false);
+ const on = await views();
+ const raw = derivedOf(b.keys, ['raw']);
+ expect(on.alice).toEqual(b.expected(['raw', 'rdr', 'cov', 'open', ...derivedOf(b.keys, ['open', 'raw'])], factsOf(b.keys, ['open', 'raw'])));
+ expect(on.bob).toEqual(b.expected(['cov', 'open', ...derivedOf(b.keys, ['open', 'raw'])], factsOf(b.keys, ['open', 'raw'])));
+ for (const who of ['unbound', 'granted']) expect(on[who]).toEqual(b.expected(['open', ...derivedOf(b.keys, ['open', 'raw'])], factsOf(b.keys, ['open', 'raw'])));
+ for (const who of CALLERS) {
+ for (const label of Object.keys(on[who]!)) {
+ const gained = on[who]![label]!.filter(k => !off[who]![label]!.includes(k));
+ expect(gained.every(k => raw.includes(k) || k === 'raw.fact')).toBe(true);
+ expect(off[who]![label]!.every(k => on[who]![label]!.includes(k))).toBe(true);
+ }
+ }
+ const checks = await doctor();
+ expect(checks.access_raw_only_rules.message).toContain(`${SRC}:transcripts (transcripts/)`);
+ expect(checks.access_raw_only_rules.message).toContain('never for a folder whose content is itself the secret');
+ }, 120_000);
+
+ test('turning the rule back to covering is a narrowing that applies at once', async () => {
+ const result = await cli(['rule', 'add', '--id', 'transcripts', '--prefix', 'transcripts/', '--readers', 'alice-example', '--source', SRC, '--yes', '--json']);
+ expect(JSON.stringify(result)).toContain('derived_covered');
+ expect(rulebookDigest(await appliedRules(b.engine, SRC))).toBe(rulebookDigest(COVERING));
+ expect((await policyStatus(b.engine, SRC)).held).toEqual([]);
+ expect(await views()).toEqual(off);
+ expect((await doctor()).access_raw_only_rules.message).toStartWith('Not applicable');
+ }, 120_000);
+ });
+ }
+}
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
index 365b1cc774..c3a0d10736 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
@@ -14,6 +14,7 @@
"access_member_sources.access_member_sources_pkey": "p PRIMARY KEY (member_id, source_id)",
"access_members.access_members_email_check": "c CHECK (((email IS NULL) OR ((length(email) <= 254) AND (email ~ '^[^@[:space:]]+@[^@[:space:]]+$'::text))))",
"access_members.access_members_id_check": "c CHECK ((id ~ '^[a-z0-9][a-z0-9._-]{0,63}$'::text))",
+ "access_members.access_members_kind_check": "c CHECK ((kind = ANY (ARRAY['person'::text, 'audience'::text])))",
"access_members.access_members_pkey": "p PRIMARY KEY (id)",
"access_pending_coverage.access_pending_coverage_pkey": "p PRIMARY KEY (source_id, prefix, reason)",
"access_pending_coverage.access_pending_coverage_prefix_check": "c CHECK (((prefix = ''::text) OR ((length(prefix) <= 512) AND (prefix ~ '^(([a-z0-9][a-z0-9._-]*/)+|([a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*)$'::text) AND (POSITION(('..'::text) IN (prefix)) = 0))))",
@@ -595,11 +596,14 @@
"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784",
"gbrain_access_derive_page_readers()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=55923fb552adcdc8e5e3c820a0b4ba11f74748b4478f52de2e1b7506e969ac4d",
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
+ "gbrain_access_lineage_rules(p_source text, p_rules text[])": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d2373deb5c27c3ba3794e223754c116a6ded14a54cb296882fff69464d74f0e5",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
- "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 boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
- "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=72cab846e7394f7dc707d5ba4398aca28282577ef0ddfd7344e1d331c14d9736",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=141ca5767c490e897b509cee46d2e7b54ce8ff12176c4c45ec36fb7b048cd660",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=3eac3806fcfc6e54e07a28f06ce153b4ac415709cd53c50d3b24e4423646be3c",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=74057c9cd464b1993aa10970e8d21cc5fb2f66c7c7fe91dc271680901f927188",
+ "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=506a29c639348746278d0c472b43a013bf2e39a8e83de4cd3641424116160c6d",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
"gbrain_access_readers(fm jsonb)": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=18348cb56089106aaec6470076ee652d7ed3bfbcb20e950a24abd52a21e7a380",
"gbrain_access_stamp_folder_rules()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7fb49ce62f4f6153ef0c844a1816f5f5bb7d765b8610ff66fec137283469fc09",
@@ -1809,7 +1813,8 @@
"4 tombstoned_at timestamp with time zone/timestamptz NULL",
"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 email text/text NULL"
+ "7 email text/text NULL",
+ "8 kind text/text NOT NULL DEFAULT 'person'::text"
],
"flags": "relkind=r rls=true force_rls=false"
},
@@ -1868,7 +1873,8 @@
"4 readable_by ARRAY/_text NOT NULL",
"5 revision bigint/int8 NOT NULL",
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 created_by text/text NULL"
+ "7 created_by text/text NULL",
+ "8 covers_derived boolean/bool NOT NULL DEFAULT true"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
index f5f37f52ab..c382197414 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
@@ -14,6 +14,7 @@
"access_member_sources.access_member_sources_pkey": "p PRIMARY KEY (member_id, source_id)",
"access_members.access_members_email_check": "c CHECK (((email IS NULL) OR ((length(email) <= 254) AND (email ~ '^[^@[:space:]]+@[^@[:space:]]+$'::text))))",
"access_members.access_members_id_check": "c CHECK ((id ~ '^[a-z0-9][a-z0-9._-]{0,63}$'::text))",
+ "access_members.access_members_kind_check": "c CHECK ((kind = ANY (ARRAY['person'::text, 'audience'::text])))",
"access_members.access_members_pkey": "p PRIMARY KEY (id)",
"access_pending_coverage.access_pending_coverage_pkey": "p PRIMARY KEY (source_id, prefix, reason)",
"access_pending_coverage.access_pending_coverage_prefix_check": "c CHECK (((prefix = ''::text) OR ((length(prefix) <= 512) AND (prefix ~ '^(([a-z0-9][a-z0-9._-]*/)+|([a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*)$'::text) AND (POSITION(('..'::text) IN (prefix)) = 0))))",
@@ -595,11 +596,14 @@
"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784",
"gbrain_access_derive_page_readers()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=55923fb552adcdc8e5e3c820a0b4ba11f74748b4478f52de2e1b7506e969ac4d",
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
+ "gbrain_access_lineage_rules(p_source text, p_rules text[])": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d2373deb5c27c3ba3794e223754c116a6ded14a54cb296882fff69464d74f0e5",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
- "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 boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
- "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=72cab846e7394f7dc707d5ba4398aca28282577ef0ddfd7344e1d331c14d9736",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=141ca5767c490e897b509cee46d2e7b54ce8ff12176c4c45ec36fb7b048cd660",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=3eac3806fcfc6e54e07a28f06ce153b4ac415709cd53c50d3b24e4423646be3c",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=74057c9cd464b1993aa10970e8d21cc5fb2f66c7c7fe91dc271680901f927188",
+ "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=506a29c639348746278d0c472b43a013bf2e39a8e83de4cd3641424116160c6d",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
"gbrain_access_readers(fm jsonb)": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=18348cb56089106aaec6470076ee652d7ed3bfbcb20e950a24abd52a21e7a380",
"gbrain_access_stamp_folder_rules()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7fb49ce62f4f6153ef0c844a1816f5f5bb7d765b8610ff66fec137283469fc09",
@@ -1809,7 +1813,8 @@
"4 tombstoned_at timestamp with time zone/timestamptz NULL",
"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 email text/text NULL"
+ "7 email text/text NULL",
+ "8 kind text/text NOT NULL DEFAULT 'person'::text"
],
"flags": "relkind=r rls=true force_rls=false"
},
@@ -1868,7 +1873,8 @@
"4 readable_by ARRAY/_text NOT NULL",
"5 revision bigint/int8 NOT NULL",
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 created_by text/text NULL"
+ "7 created_by text/text NULL",
+ "8 covers_derived boolean/bool NOT NULL DEFAULT true"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
index 717dd57ead..c2c3aa0861 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
@@ -14,6 +14,7 @@
"access_member_sources.access_member_sources_pkey": "p PRIMARY KEY (member_id, source_id)",
"access_members.access_members_email_check": "c CHECK (((email IS NULL) OR ((length(email) <= 254) AND (email ~ '^[^@[:space:]]+@[^@[:space:]]+$'::text))))",
"access_members.access_members_id_check": "c CHECK ((id ~ '^[a-z0-9][a-z0-9._-]{0,63}$'::text))",
+ "access_members.access_members_kind_check": "c CHECK ((kind = ANY (ARRAY['person'::text, 'audience'::text])))",
"access_members.access_members_pkey": "p PRIMARY KEY (id)",
"access_pending_coverage.access_pending_coverage_pkey": "p PRIMARY KEY (source_id, prefix, reason)",
"access_pending_coverage.access_pending_coverage_prefix_check": "c CHECK (((prefix = ''::text) OR ((length(prefix) <= 512) AND (prefix ~ '^(([a-z0-9][a-z0-9._-]*/)+|([a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*)$'::text) AND (POSITION(('..'::text) IN (prefix)) = 0))))",
@@ -595,11 +596,14 @@
"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784",
"gbrain_access_derive_page_readers()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=55923fb552adcdc8e5e3c820a0b4ba11f74748b4478f52de2e1b7506e969ac4d",
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
+ "gbrain_access_lineage_rules(p_source text, p_rules text[])": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d2373deb5c27c3ba3794e223754c116a6ded14a54cb296882fff69464d74f0e5",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
- "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 boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
- "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=72cab846e7394f7dc707d5ba4398aca28282577ef0ddfd7344e1d331c14d9736",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=141ca5767c490e897b509cee46d2e7b54ce8ff12176c4c45ec36fb7b048cd660",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=3eac3806fcfc6e54e07a28f06ce153b4ac415709cd53c50d3b24e4423646be3c",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=74057c9cd464b1993aa10970e8d21cc5fb2f66c7c7fe91dc271680901f927188",
+ "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=506a29c639348746278d0c472b43a013bf2e39a8e83de4cd3641424116160c6d",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
"gbrain_access_readers(fm jsonb)": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=18348cb56089106aaec6470076ee652d7ed3bfbcb20e950a24abd52a21e7a380",
"gbrain_access_stamp_folder_rules()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7fb49ce62f4f6153ef0c844a1816f5f5bb7d765b8610ff66fec137283469fc09",
@@ -1805,7 +1809,8 @@
"4 tombstoned_at timestamp with time zone/timestamptz NULL",
"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 email text/text NULL"
+ "7 email text/text NULL",
+ "8 kind text/text NOT NULL DEFAULT 'person'::text"
],
"flags": "relkind=r rls=true force_rls=false"
},
@@ -1864,7 +1869,8 @@
"4 readable_by ARRAY/_text NOT NULL",
"5 revision bigint/int8 NOT NULL",
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 created_by text/text NULL"
+ "7 created_by text/text NULL",
+ "8 covers_derived boolean/bool NOT NULL DEFAULT true"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
index 15cdeb704a..7d94b8bbc8 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
@@ -14,6 +14,7 @@
"access_member_sources.access_member_sources_pkey": "p PRIMARY KEY (member_id, source_id)",
"access_members.access_members_email_check": "c CHECK (((email IS NULL) OR ((length(email) <= 254) AND (email ~ '^[^@[:space:]]+@[^@[:space:]]+$'::text))))",
"access_members.access_members_id_check": "c CHECK ((id ~ '^[a-z0-9][a-z0-9._-]{0,63}$'::text))",
+ "access_members.access_members_kind_check": "c CHECK ((kind = ANY (ARRAY['person'::text, 'audience'::text])))",
"access_members.access_members_pkey": "p PRIMARY KEY (id)",
"access_pending_coverage.access_pending_coverage_pkey": "p PRIMARY KEY (source_id, prefix, reason)",
"access_pending_coverage.access_pending_coverage_prefix_check": "c CHECK (((prefix = ''::text) OR ((length(prefix) <= 512) AND (prefix ~ '^(([a-z0-9][a-z0-9._-]*/)+|([a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*)$'::text) AND (POSITION(('..'::text) IN (prefix)) = 0))))",
@@ -599,11 +600,14 @@
"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784",
"gbrain_access_derive_page_readers()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=55923fb552adcdc8e5e3c820a0b4ba11f74748b4478f52de2e1b7506e969ac4d",
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
+ "gbrain_access_lineage_rules(p_source text, p_rules text[])": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d2373deb5c27c3ba3794e223754c116a6ded14a54cb296882fff69464d74f0e5",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
- "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 boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
- "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=72cab846e7394f7dc707d5ba4398aca28282577ef0ddfd7344e1d331c14d9736",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=141ca5767c490e897b509cee46d2e7b54ce8ff12176c4c45ec36fb7b048cd660",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=3eac3806fcfc6e54e07a28f06ce153b4ac415709cd53c50d3b24e4423646be3c",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=74057c9cd464b1993aa10970e8d21cc5fb2f66c7c7fe91dc271680901f927188",
+ "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=506a29c639348746278d0c472b43a013bf2e39a8e83de4cd3641424116160c6d",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
"gbrain_access_readers(fm jsonb)": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=18348cb56089106aaec6470076ee652d7ed3bfbcb20e950a24abd52a21e7a380",
"gbrain_access_stamp_folder_rules()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7fb49ce62f4f6153ef0c844a1816f5f5bb7d765b8610ff66fec137283469fc09",
@@ -1810,7 +1814,8 @@
"4 tombstoned_at timestamp with time zone/timestamptz NULL",
"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 email text/text NULL"
+ "7 email text/text NULL",
+ "8 kind text/text NOT NULL DEFAULT 'person'::text"
],
"flags": "relkind=r rls=true force_rls=false"
},
@@ -1869,7 +1874,8 @@
"4 readable_by ARRAY/_text NOT NULL",
"5 revision bigint/int8 NOT NULL",
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 created_by text/text NULL"
+ "7 created_by text/text NULL",
+ "8 covers_derived boolean/bool NOT NULL DEFAULT true"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
index 9a39a88413..129cd03abf 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
@@ -14,6 +14,7 @@
"access_member_sources.access_member_sources_pkey": "p PRIMARY KEY (member_id, source_id)",
"access_members.access_members_email_check": "c CHECK (((email IS NULL) OR ((length(email) <= 254) AND (email ~ '^[^@[:space:]]+@[^@[:space:]]+$'::text))))",
"access_members.access_members_id_check": "c CHECK ((id ~ '^[a-z0-9][a-z0-9._-]{0,63}$'::text))",
+ "access_members.access_members_kind_check": "c CHECK ((kind = ANY (ARRAY['person'::text, 'audience'::text])))",
"access_members.access_members_pkey": "p PRIMARY KEY (id)",
"access_pending_coverage.access_pending_coverage_pkey": "p PRIMARY KEY (source_id, prefix, reason)",
"access_pending_coverage.access_pending_coverage_prefix_check": "c CHECK (((prefix = ''::text) OR ((length(prefix) <= 512) AND (prefix ~ '^(([a-z0-9][a-z0-9._-]*/)+|([a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*)$'::text) AND (POSITION(('..'::text) IN (prefix)) = 0))))",
@@ -599,11 +600,14 @@
"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784",
"gbrain_access_derive_page_readers()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=55923fb552adcdc8e5e3c820a0b4ba11f74748b4478f52de2e1b7506e969ac4d",
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
+ "gbrain_access_lineage_rules(p_source text, p_rules text[])": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d2373deb5c27c3ba3794e223754c116a6ded14a54cb296882fff69464d74f0e5",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
- "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 boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
- "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=72cab846e7394f7dc707d5ba4398aca28282577ef0ddfd7344e1d331c14d9736",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=141ca5767c490e897b509cee46d2e7b54ce8ff12176c4c45ec36fb7b048cd660",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=3eac3806fcfc6e54e07a28f06ce153b4ac415709cd53c50d3b24e4423646be3c",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=74057c9cd464b1993aa10970e8d21cc5fb2f66c7c7fe91dc271680901f927188",
+ "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=506a29c639348746278d0c472b43a013bf2e39a8e83de4cd3641424116160c6d",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
"gbrain_access_readers(fm jsonb)": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=18348cb56089106aaec6470076ee652d7ed3bfbcb20e950a24abd52a21e7a380",
"gbrain_access_stamp_folder_rules()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7fb49ce62f4f6153ef0c844a1816f5f5bb7d765b8610ff66fec137283469fc09",
@@ -1810,7 +1814,8 @@
"4 tombstoned_at timestamp with time zone/timestamptz NULL",
"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 email text/text NULL"
+ "7 email text/text NULL",
+ "8 kind text/text NOT NULL DEFAULT 'person'::text"
],
"flags": "relkind=r rls=true force_rls=false"
},
@@ -1869,7 +1874,8 @@
"4 readable_by ARRAY/_text NOT NULL",
"5 revision bigint/int8 NOT NULL",
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 created_by text/text NULL"
+ "7 created_by text/text NULL",
+ "8 covers_derived boolean/bool NOT NULL DEFAULT true"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
index 2eff9fb9a0..fa8bebae32 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
@@ -14,6 +14,7 @@
"access_member_sources.access_member_sources_pkey": "p PRIMARY KEY (member_id, source_id)",
"access_members.access_members_email_check": "c CHECK (((email IS NULL) OR ((length(email) <= 254) AND (email ~ '^[^@[:space:]]+@[^@[:space:]]+$'::text))))",
"access_members.access_members_id_check": "c CHECK ((id ~ '^[a-z0-9][a-z0-9._-]{0,63}$'::text))",
+ "access_members.access_members_kind_check": "c CHECK ((kind = ANY (ARRAY['person'::text, 'audience'::text])))",
"access_members.access_members_pkey": "p PRIMARY KEY (id)",
"access_pending_coverage.access_pending_coverage_pkey": "p PRIMARY KEY (source_id, prefix, reason)",
"access_pending_coverage.access_pending_coverage_prefix_check": "c CHECK (((prefix = ''::text) OR ((length(prefix) <= 512) AND (prefix ~ '^(([a-z0-9][a-z0-9._-]*/)+|([a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*)$'::text) AND (POSITION(('..'::text) IN (prefix)) = 0))))",
@@ -599,11 +600,14 @@
"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784",
"gbrain_access_derive_page_readers()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=55923fb552adcdc8e5e3c820a0b4ba11f74748b4478f52de2e1b7506e969ac4d",
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
+ "gbrain_access_lineage_rules(p_source text, p_rules text[])": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d2373deb5c27c3ba3794e223754c116a6ded14a54cb296882fff69464d74f0e5",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
- "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 boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
- "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=72cab846e7394f7dc707d5ba4398aca28282577ef0ddfd7344e1d331c14d9736",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=141ca5767c490e897b509cee46d2e7b54ce8ff12176c4c45ec36fb7b048cd660",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=3eac3806fcfc6e54e07a28f06ce153b4ac415709cd53c50d3b24e4423646be3c",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=74057c9cd464b1993aa10970e8d21cc5fb2f66c7c7fe91dc271680901f927188",
+ "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=506a29c639348746278d0c472b43a013bf2e39a8e83de4cd3641424116160c6d",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
"gbrain_access_readers(fm jsonb)": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=18348cb56089106aaec6470076ee652d7ed3bfbcb20e950a24abd52a21e7a380",
"gbrain_access_stamp_folder_rules()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7fb49ce62f4f6153ef0c844a1816f5f5bb7d765b8610ff66fec137283469fc09",
@@ -1806,7 +1810,8 @@
"4 tombstoned_at timestamp with time zone/timestamptz NULL",
"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 email text/text NULL"
+ "7 email text/text NULL",
+ "8 kind text/text NOT NULL DEFAULT 'person'::text"
],
"flags": "relkind=r rls=true force_rls=false"
},
@@ -1865,7 +1870,8 @@
"4 readable_by ARRAY/_text NOT NULL",
"5 revision bigint/int8 NOT NULL",
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 created_by text/text NULL"
+ "7 created_by text/text NULL",
+ "8 covers_derived boolean/bool NOT NULL DEFAULT true"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/doctor/content-pglite-human.json b/test/fixtures/goldens/doctor/content-pglite-human.json
index 76b3907b88..36b966db61 100644
--- a/test/fixtures/goldens/doctor/content-pglite-human.json
+++ b/test/fixtures/goldens/doctor/content-pglite-human.json
@@ -89,6 +89,9 @@
" [INFO] unlabeled_people_folders: Not applicable: this brain serves one person (fewer than two enabled members and no access.serves = several).",
" [INFO] access_may_act_for_wildcard: Not applicable: no page names readers and no member exists.",
" [INFO] access_owner_reads_restricted: 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.",
+ " [INFO] access_raw_only_rules: Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ " [INFO] access_audience_members: Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ " [INFO] access_members_read_lineage: Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
" [INFO] attest_read_shared_scope: Not applicable: no attest credential reads named sources as the person (--attest-read person).",
" [OK] rls: Skipped (PGLite — no PostgREST exposure, RLS not applicable)",
" [OK] function_search_path: Every gbrain function that pins a search_path ends it with pg_temp",
@@ -267,7 +270,7 @@
" [OK] fence_integrity: No malformed facts or takes fence is held, stored or waiting in a checkout (2 source(s) scanned).",
" [OK] search_mode: Mode: conservative (no per-key overrides — mode bundle is canonical).",
" [OK] hidden_by_search_policy: No pages hidden by search-exclude policy.",
- " [OK] eval_drift: No retrieval-affecting files changed in working tree.",
+ " [OK] eval_drift: 2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
" [OK] reranker_health: Reranker disabled — no failures expected",
" [OK] batch_retry_health: No exhausted batch retries in last 24h.",
" [OK] wedged_queue: PGLite — no queue to check",
diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.json
index 5e45c60366..48543995dd 100644
--- a/test/fixtures/goldens/doctor/content-pglite-json.json
+++ b/test/fixtures/goldens/doctor/content-pglite-json.json
@@ -1075,6 +1075,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -4044,7 +4071,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
index d4d813d016..d082f6d0e9 100644
--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
@@ -1146,6 +1146,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -4476,7 +4503,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
@@ -6231,6 +6258,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -9573,7 +9627,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
index 5fca8c7d7a..c4805e2923 100644
--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
@@ -1142,6 +1142,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -4486,7 +4513,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
@@ -6235,6 +6262,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -9591,7 +9645,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.json
index 55ff7f067b..dbe46d3f9f 100644
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@ -988,6 +988,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -3622,7 +3649,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.json
index aca0f06173..c18c9a28ea 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@ -1035,6 +1035,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -3667,7 +3694,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.json
index d891421a04..957a0a32cf 100644
--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json
+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json
@@ -1031,6 +1031,33 @@
"severity": "info",
"status": "ok"
},
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: every folder and page rule also keeps the pages and facts derived from its pages to its readers (no rule has covers_derived: false).",
+ "name": "access_raw_only_rules",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: no member is marked as an audience (gbrain access member kind <id> audience).",
+ "name": "access_audience_members",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
+ {
+ "category": "brain",
+ "elapsed_ms": "<volatile>",
+ "message": "Not applicable: access.members_read_lineage is off; derived pages and facts of a page that names readers or sits under a rule are hidden from every member but the owner.",
+ "name": "access_members_read_lineage",
+ "readiness_state": "not_applicable",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "brain",
"elapsed_ms": "<volatile>",
@@ -3677,7 +3704,7 @@
{
"category": "brain",
"elapsed_ms": "<volatile>",
- "message": "No retrieval-affecting files changed in working tree.",
+ "message": "2 retrieval-affecting file(s) changed since HEAD: src/core/search/mode.ts, src/core/search/private-visibility.ts. Re-run `gbrain eval run-all` after committing these changes.",
"name": "eval_drift",
"status": "ok"
},
diff --git a/test/fixtures/goldens/doctor/registry-build-checks.json b/test/fixtures/goldens/doctor/registry-build-checks.json
index 634471d611..e0e4487ddb 100644
--- a/test/fixtures/goldens/doctor/registry-build-checks.json
+++ b/test/fixtures/goldens/doctor/registry-build-checks.json
@@ -401,6 +401,18 @@
"category": "brain",
"name": "access_owner_reads_restricted"
},
+ {
+ "category": "brain",
+ "name": "access_raw_only_rules"
+ },
+ {
+ "category": "brain",
+ "name": "access_audience_members"
+ },
+ {
+ "category": "brain",
+ "name": "access_members_read_lineage"
+ },
{
"category": "brain",
"name": "attest_read_shared_scope"
diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.json
index 22feb54248..930d34535f 100644
--- a/test/fixtures/goldens/migrations/records.json
+++ b/test/fixtures/goldens/migrations/records.json
@@ -1,6 +1,6 @@
{
"golden": {
- "count": 299,
+ "count": 300,
"gaps": [
17,
18,
@@ -52,7 +52,7 @@
"PERSISTENCE_REQUEST_SLUG_SEQUENCE_INDEX": "4759eaf319a6ad8d99aae7648acb6556745ed7cba051175273e2f46927c77d52",
"PERSISTENCE_SYNC_RUN_INDEXES": "e1b12613c5fd2facb850e6857b0bddcf49b2478ec258fa226fe15e71e55df9c1",
"PERSISTENCE_SYNC_WATERMARK_INDEX": "93523954a30e8483717f07ec97a3e0cd062b15d8a60cc759281054b06c23bb40",
- "PINNED_FUNCTION_NAMES": "f940551717a5d974effd67e25cd93c287af7394f16e458af0e318619d1f01901",
+ "PINNED_FUNCTION_NAMES": "e1fae0df5d24dc4721ffc1939c661ed377c3da6f8f8eea1913a497893a2a5090",
"PLANNER_REPAIR_TABLES": "008725595e099adba279d4292661eb4a59930b777c35db43c340220f7f12e093",
"POSTGRES_15_GATE": "09c990d8c0bd6e4ebeb3b897477748609035b0e695b5b2c6a9bf7539f7352193",
"TABLES": "3fc77a0fccb525f9b791098f9eae27b19adaa3f5dadbabcff2a719137cbc3ef8",
@@ -103,7 +103,7 @@
"widenIdentityIndex": "86a6176bd7637d964dbc1d3cd3b1bdfa3ca0161e1ee248c37d7380a1471282e6",
"withSchemaLockTimeout": "95605bd3004955e11e936c7a4aa6889319b401098abf9db18ef3e48da2c3fc59"
},
- "latest": 304,
+ "latest": 305,
"records": [
{
"handler": {
@@ -4963,6 +4963,19 @@
"transaction": "absent",
"verify": "absent",
"version": 304
+ },
+ {
+ "handler": "absent",
+ "idempotent": true,
+ "name": "access_lineage_designs",
+ "sql": {
+ "length": 9778,
+ "sha256": "f893b1ba189ad260c2503b589fe097af29938504419ae56a6865ad95a80e1332"
+ },
+ "sqlFor": "absent",
+ "transaction": "absent",
+ "verify": "absent",
+ "version": 305
}
],
"versions": [
@@ -5264,7 +5277,8 @@
301,
302,
303,
- 304
+ 304,
+ 305
]
},
"normalizer": "migrations-record-v1"
diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
index 0b2ada8737..e640cb7cb9 100644
--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
@@ -14,6 +14,7 @@
"access_member_sources.access_member_sources_pkey": "p PRIMARY KEY (member_id, source_id)",
"access_members.access_members_email_check": "c CHECK (((email IS NULL) OR ((length(email) <= 254) AND (email ~ '^[^@[:space:]]+@[^@[:space:]]+$'::text))))",
"access_members.access_members_id_check": "c CHECK ((id ~ '^[a-z0-9][a-z0-9._-]{0,63}$'::text))",
+ "access_members.access_members_kind_check": "c CHECK ((kind = ANY (ARRAY['person'::text, 'audience'::text])))",
"access_members.access_members_pkey": "p PRIMARY KEY (id)",
"access_pending_coverage.access_pending_coverage_pkey": "p PRIMARY KEY (source_id, prefix, reason)",
"access_pending_coverage.access_pending_coverage_prefix_check": "c CHECK (((prefix = ''::text) OR ((length(prefix) <= 512) AND (prefix ~ '^(([a-z0-9][a-z0-9._-]*/)+|([a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*)$'::text) AND (POSITION(('..'::text) IN (prefix)) = 0))))",
@@ -595,11 +596,14 @@
"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784",
"gbrain_access_derive_page_readers()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=55923fb552adcdc8e5e3c820a0b4ba11f74748b4478f52de2e1b7506e969ac4d",
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
+ "gbrain_access_lineage_rules(p_source text, p_rules text[])": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d2373deb5c27c3ba3794e223754c116a6ded14a54cb296882fff69464d74f0e5",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
- "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 boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
- "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=72cab846e7394f7dc707d5ba4398aca28282577ef0ddfd7344e1d331c14d9736",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=141ca5767c490e897b509cee46d2e7b54ce8ff12176c4c45ec36fb7b048cd660",
+ "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 boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=3eac3806fcfc6e54e07a28f06ce153b4ac415709cd53c50d3b24e4423646be3c",
+ "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, p_audience_pages text[])": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=74057c9cd464b1993aa10970e8d21cc5fb2f66c7c7fe91dc271680901f927188",
+ "gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=506a29c639348746278d0c472b43a013bf2e39a8e83de4cd3641424116160c6d",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
"gbrain_access_readers(fm jsonb)": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=18348cb56089106aaec6470076ee652d7ed3bfbcb20e950a24abd52a21e7a380",
"gbrain_access_stamp_folder_rules()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7fb49ce62f4f6153ef0c844a1816f5f5bb7d765b8610ff66fec137283469fc09",
@@ -1809,7 +1813,8 @@
"4 tombstoned_at timestamp with time zone/timestamptz NULL",
"5 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
"6 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 email text/text NULL"
+ "7 email text/text NULL",
+ "8 kind text/text NOT NULL DEFAULT 'person'::text"
],
"flags": "relkind=r rls=true force_rls=false"
},
@@ -1868,7 +1873,8 @@
"4 readable_by ARRAY/_text NOT NULL",
"5 revision bigint/int8 NOT NULL",
"6 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",
- "7 created_by text/text NULL"
+ "7 created_by text/text NULL",
+ "8 covers_derived boolean/bool NOT NULL DEFAULT true"
],
"flags": "relkind=r rls=true force_rls=false"
},
diff --git a/test/fixtures/goldens/sql-text/facts.json b/test/fixtures/goldens/sql-text/facts.json
index 59ac885b2d..bb0cbce395 100644
--- a/test/fixtures/goldens/sql-text/facts.json
+++ b/test/fixtures/goldens/sql-text/facts.json
@@ -151,8 +151,8 @@
"number",
"array<string>"
],
- "sql": "WITH cur AS ( SELECT entity_slug, dimension, value, source_markdown_slug AS source, confidence, id AS fact_id FROM facts WHERE dimension IS NOT NULL AND expired_at IS NULL AND valid_until IS NULL AND (dim_status IS NULL OR dim_status = 'active') AND confidence >= $1 AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND (NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug = facts.entity_slug AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = entity_pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) ) SELECT entity_slug, dimension, json_agg(json_build_object('value', value, 'source', source, 'confidence', confidence, 'fact_id', fact_id)) AS values FROM cur GROUP BY entity_slug, dimension HAVING count(DISTINCT value) >= 2 AND count(DISTINCT source) >= 2 ORDER BY entity_slug, dimension",
- "textSha256": "f923ffce72f0302bc497d30743a14be8d4ed630186a813fddb92d079de08baaa"
+ "sql": "WITH cur AS ( SELECT entity_slug, dimension, value, source_markdown_slug AS source, confidence, id AS fact_id FROM facts WHERE dimension IS NOT NULL AND expired_at IS NULL AND valid_until IS NULL AND (dim_status IS NULL OR dim_status = 'active') AND confidence >= $1 AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND (NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL OR COALESCE(gbrain_access_lineage_rules(pp.source_id, pp.folder_rule_ids) <@ ARRAY[]::text[], true)) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug = facts.entity_slug AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = entity_pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) ) SELECT entity_slug, dimension, json_agg(json_build_object('value', value, 'source', source, 'confidence', confidence, 'fact_id', fact_id)) AS values FROM cur GROUP BY entity_slug, dimension HAVING count(DISTINCT value) >= 2 AND count(DISTINCT source) >= 2 ORDER BY entity_slug, dimension",
+ "textSha256": "d7541bc618e375f4dfe29011fb137d8b97adbe095e6cf365e6a04a7cdc842e85"
}
]
},
@@ -245,8 +245,8 @@
"number",
"boolean"
],
- "sql": "SELECT DISTINCT ON (dimension) dimension, value, confidence, source_markdown_slug AS source, valid_from, valid_until AS valid_to, COALESCE(dim_status, 'active') AS status, id AS fact_id FROM facts WHERE entity_slug = $1 AND dimension IS NOT NULL AND expired_at IS NULL AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND (NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug = facts.entity_slug AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = entity_pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND COALESCE(valid_from, '-infinity'::timestamptz) <= COALESCE($3::timestamptz, now()) AND COALESCE(valid_until, 'infinity'::timestamptz) > COALESCE($4::timestamptz, now()) AND confidence >= $5 AND ($6::boolean OR dim_status IS NULL OR dim_status = 'active') ORDER BY dimension, valid_from DESC NULLS LAST, confidence DESC, id DESC",
- "textSha256": "1e66e4467d3dab30d96d575be6b2765ff217929458e3a074c0a325de81ae77f3"
+ "sql": "SELECT DISTINCT ON (dimension) dimension, value, confidence, source_markdown_slug AS source, valid_from, valid_until AS valid_to, COALESCE(dim_status, 'active') AS status, id AS fact_id FROM facts WHERE entity_slug = $1 AND dimension IS NOT NULL AND expired_at IS NULL AND source_id = ANY($2) AND NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = facts.source_id AND elig_dp.slug = ANY(ARRAY[facts.source_markdown_slug, facts.entity_slug]) AND elig_dp.deleted_at IS NOT NULL) AND (NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = facts.source_id AND pp.slug = facts.source_markdown_slug AND NOT (((((pp.page_readers IS NULL AND NOT (pp.frontmatter ? 'readable_by'))) AND (pp.folder_rule_ids IS NULL OR COALESCE(gbrain_access_lineage_rules(pp.source_id, pp.folder_rule_ids) <@ ARRAY[]::text[], true)) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = pp.source_id AND (starts_with(pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(pp.id, pp.source_id, pp.type, pp.frontmatter))) AND ((COALESCE(pp.frontmatter->>'visibility', CASE WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(pp.frontmatter ? 'pinned_question', false) AND NOT (pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = pp.source_id AND derived_origin.slug = pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (pp.type IN ('atom', 'question') OR (pp.type = 'concept' AND pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN pp.type = 'event' AND pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = pp.source_id AND chronicle_origin.slug = pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(pp.frontmatter->'derived_from') = 'array' THEN pp.frontmatter->'derived_from' ELSE jsonb_build_array(pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = facts.source_id AND entity_pp.slug = facts.entity_slug AND NOT ((((entity_pp.page_readers IS NULL AND NOT (entity_pp.frontmatter ? 'readable_by'))) AND (entity_pp.folder_rule_ids IS NULL) AND NOT EXISTS (SELECT 1 FROM access_pending_coverage pc WHERE pc.source_id = entity_pp.source_id AND (starts_with(entity_pp.slug, pc.prefix) AND (pc.prefix = '' OR right(pc.prefix, 1) = '/' OR entity_pp.slug = pc.prefix))) AND NOT (SELECT gbrain_access_state_unreadable()) AND ((entity_pp.type NOT IN ('atom', 'question', 'concept', 'event') AND NOT (entity_pp.frontmatter ? 'derived_from')) OR NOT gbrain_access_origin_restricted(entity_pp.id, entity_pp.source_id, entity_pp.type, entity_pp.frontmatter))) AND ((COALESCE(entity_pp.frontmatter->>'visibility', CASE WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(entity_pp.frontmatter ? 'pinned_question', false) AND NOT (entity_pp.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(entity_pp.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(entity_pp.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN entity_pp.type = 'atom' THEN EXISTS (SELECT 1 FROM pages derived_origin WHERE derived_origin.source_id = entity_pp.source_id AND derived_origin.slug = entity_pp.frontmatter->>'source_slug' AND derived_origin.frontmatter->>'visibility' = 'private') WHEN (entity_pp.type IN ('atom', 'question') OR (entity_pp.type = 'concept' AND entity_pp.frontmatter->>'synthesized_by' IS NOT NULL)) THEN EXISTS (SELECT 1 FROM links derived_input_link JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id WHERE derived_input_link.from_page_id = entity_pp.id AND derived_input_link.link_source = 'concept-provenance' AND derived_input_link.link_type = 'synthesized_from' AND (COALESCE(derived_input.frontmatter->>'visibility', CASE WHEN derived_input.type = 'atom' THEN 'private' ELSE 'world' END) = 'private' OR EXISTS (SELECT 1 FROM pages derived_input_origin WHERE derived_input_origin.source_id = derived_input.source_id AND derived_input_origin.slug = derived_input.frontmatter->>'source_slug' AND derived_input_origin.frontmatter->>'visibility' = 'private'))) WHEN entity_pp.type = 'event' AND entity_pp.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN NOT EXISTS (SELECT 1 FROM pages chronicle_origin WHERE chronicle_origin.source_id = entity_pp.source_id AND chronicle_origin.slug = entity_pp.frontmatter->'event'->>'depth' AND (COALESCE(chronicle_origin.frontmatter->>'visibility', CASE WHEN (chronicle_origin.type IN ('atom', 'question') OR (chronicle_origin.type = 'concept' AND chronicle_origin.frontmatter->>'synthesized_by' IS NOT NULL)) THEN 'private' ELSE 'world' END) <> 'private' AND NOT COALESCE(chronicle_origin.frontmatter ? 'pinned_question', false) AND NOT (chronicle_origin.frontmatter->>'visibility' IS NULL AND (COALESCE(translate(btrim(chronicle_origin.frontmatter->>'access', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('private','restricted','confidential'), false) OR COALESCE(translate(btrim(chronicle_origin.frontmatter->>'confidentiality', (E'\\u0020\\u0009\\u000a\\u000b\\u000c\\u000d' || CASE WHEN current_setting('server_encoding') = 'UTF8' THEN convert_from(decode('c2a0e19a80e28080e28081e28082e28083e28084e28085e28086e28087e28088e28089e2808ae280a8e280a9e280afe2819fe38080efbbbf', 'hex'), 'UTF8') ELSE '' END)), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') IN ('confidential','secret','private','restricted'), false)))) AND NOT (CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = chronicle_origin.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(chronicle_origin.frontmatter->'derived_from') = 'array' THEN chronicle_origin.frontmatter->'derived_from' ELSE jsonb_build_array(chronicle_origin.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END)) ELSE false END) AND NOT (CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') IN ('array', 'string') THEN EXISTS ( SELECT 1 FROM pages declared_origin WHERE declared_origin.source_id = entity_pp.source_id AND declared_origin.frontmatter->>'visibility' = 'private' AND declared_origin.slug = ANY(ARRAY( SELECT regexp_replace(declared.slug, '\\.md$', '') FROM jsonb_array_elements_text( CASE WHEN jsonb_typeof(entity_pp.frontmatter->'derived_from') = 'array' THEN entity_pp.frontmatter->'derived_from' ELSE jsonb_build_array(entity_pp.frontmatter->'derived_from') END) AS declared(slug)))) ELSE false END))))) AND COALESCE(valid_from, '-infinity'::timestamptz) <= COALESCE($3::timestamptz, now()) AND COALESCE(valid_until, 'infinity'::timestamptz) > COALESCE($4::timestamptz, now()) AND confidence >= $5 AND ($6::boolean OR dim_status IS NULL OR dim_status = 'active') ORDER BY dimension, valid_from DESC NULLS LAST, confidence DESC, id DESC",
+ "textSha256": "c4cd121ae13f2d8cf3d07846b51b90968623bfc04bc5ab919afa5cdc3c2f51ab"
}
]
},
diff --git a/test/helpers/access-lineage-fixture.ts b/test/helpers/access-lineage-fixture.ts
new file mode 100644
index 0000000000..5d09a8d441
--- /dev/null
+++ b/test/helpers/access-lineage-fixture.ts
@@ -0,0 +1,273 @@
+/**
+ * Shared fixture for the GBRA-108 access-design tests (raw-only rules, audience members, members-read-lineage): one
+ * brain with origins, their derived pages (an atom, a derived_from page, a synthesized concept, a Life Chronicle event)
+ * and a world fact per origin (on an open entity page, provenance on the origin), read through MCP dispatch with real
+ * tokens over every read path. Rules live in the database (repo-less) or in a committed .gbrain/access.yml (git).
+ * Every origin and derived page has an older version, and links to an open hub page.
+ */
+import { execFileSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import type { BrainEngine } from '../../src/core/engine.ts';
+import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
+import { importFromContent } from '../../src/core/import-file.ts';
+import { configureGateway, resetGateway, __setEmbedTransportForTests } from '../../src/core/ai/gateway.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 { parseRescopeTokenArgs, rescopeLegacyToken } from '../../src/core/grants/legacy-token.ts';
+import { noGrantFederatedScope } from '../../src/core/source-resolver.ts';
+import { dispatchToolCall } from '../../src/mcp/dispatch.ts';
+import { __resetPrivateVisibilityCacheForTests } from '../../src/core/search/private-visibility.ts';
+import { setOwner } from '../../src/core/access/owner.ts';
+import { bindCredential } from '../../src/core/access/members.ts';
+import { applyApproved, getRevision, previewApply, proposeRevision, type ProposalResult } from '../../src/core/access/policy.ts';
+import { POLICY_FILE, syncGitPolicy, writeApprovedFile, writeGitRules } from '../../src/core/access/policy-git.ts';
+import { serializePolicyYaml, type FolderRule } from '../../src/core/access/folder-rules.ts';
+import { performSync } from '../../src/commands/sync.ts';
+import { openAsPreview } from '../../src/cli/as-preview.ts';
+import type { AuthInfo } from '../../src/core/ops/contract.ts';
+import { isolatedPersistencePostgres } from './persistence-postgres.ts';
+
+const DIMS = 1536;
+function vectorFor(text: string): number[] {
+ const v = new Array<number>(DIMS).fill(0);
+ for (const w of text.toLowerCase().match(/[a-z]+/g) ?? []) {
+ let h = 0;
+ for (const ch of w) h = (h * 31 + ch.charCodeAt(0)) >>> 0;
+ v[h % DIMS] += 1;
+ }
+ const n = Math.hypot(...v) || 1;
+ return v.map(x => x / n);
+}
+
+export const DERIVED = ['atom', 'df', 'concept', 'event'] as const;
+export const ENTITY = 'people/entity-example';
+export const HUB = 'notes/hub-example';
+
+export interface OriginSpec { slug: string; fm: string[]; derive: boolean }
+export interface CallerSpec { name: string; member?: string; grantedSources?: boolean; mayActFor?: string[]; audience?: string[]; as?: string }
+export interface LineageSpec {
+ kind: 'pglite' | 'postgres';
+ store: 'database' | 'git';
+ src: string;
+ tag: string;
+ origins: Record<string, OriginSpec>;
+ rules: FolderRule[];
+ members: string[];
+ groups?: Record<string, string[]>;
+ owner?: string;
+ callers: CallerSpec[];
+}
+
+export type Seen = Record<string, string[]>;
+
+export interface LineageBrain {
+ engine: BrainEngine;
+ keys: string[];
+ pageSlug(key: string): string | null;
+ canary(key: string): string;
+ call(who: string, op: string, params: Record<string, unknown>): Promise<string>;
+ seenBy(who: string): Promise<Seen>;
+ expected(pages: string[], facts: string[]): Seen;
+ setRules(rules: FolderRule[]): Promise<ProposalResult>;
+ approve(): Promise<string>;
+ tokenIds: Record<string, string>;
+ close(): Promise<void>;
+}
+
+const git = (dir: string, ...args: string[]) => execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
+
+/** Every read path: [label, op, params, per-page]. */
+const READS: Array<[string, string, (slug: string) => Record<string, unknown>, 'page' | 'list' | 'versions' | 'backlinks']> = [
+ ['get_page', 'get_page', slug => ({ slug }), 'page'],
+ ['get_versions', 'get_versions', slug => ({ slug, include_body: true, limit: 10 }), 'versions'],
+ ['list_pages', 'list_pages', () => ({ limit: 100 }), 'list'],
+ ['backlinks', 'get_backlinks', () => ({ slug: HUB }), 'backlinks'],
+ ['search', 'search', () => ({ query: 'harbor ledger planning notes', autocut: false, fields: 'full', limit: 100 }), 'list'],
+ ['search keyword', 'search', () => ({ query: 'planning notes', match: 'keyword', autocut: false, fields: 'full', limit: 100 }), 'list'],
+ ['query', 'query', () => ({ query: 'harbor ledger planning notes', expand: false, autocut: false, fields: 'full', limit: 100 }), 'list'],
+ ['recall since', 'recall', () => ({ since: '2000-01-01', limit: 100 }), 'list'],
+ ['recall question', 'recall', () => ({ question: 'harbor fact planning' }), 'list'],
+ ['recall entity', 'recall', () => ({ entity: ENTITY }), 'list'],
+];
+
+export async function buildLineageBrain(spec: LineageSpec): Promise<LineageBrain> {
+ const { kind, store, src, tag } = spec;
+ configureGateway({ embedding_model: 'openai:text-embedding-3-small', embedding_dimensions: DIMS, env: { OPENAI_API_KEY: 'test' } });
+ __setEmbedTransportForTests((async ({ values }: { values: string[] }) => ({ embeddings: values.map(vectorFor) })) as never);
+ let engine: BrainEngine;
+ let closeEngine: () => Promise<void>;
+ if (kind === 'postgres') ({ engine, close: closeEngine } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));
+ else { engine = new PGLiteEngine(); await engine.connect({ engine: 'pglite' } as never); await engine.initSchema(); closeEngine = () => engine.disconnect(); }
+ __resetPrivateVisibilityCacheForTests();
+ const canary = (key: string) => 'canary' + tag + key.replace(/[^a-z]/g, '') + 'x';
+ const oldCanary = (key: string) => 'canaryold' + tag + key.replace(/[^a-z]/g, '') + 'x';
+ const slugOf = (o: string, d: string) => ({ atom: `atoms/${o}-atom`, df: `notes/${o}-derived`, concept: `concepts/${o}-concept`, event: `events/${o}-event` })[d]!;
+ const keys: string[] = [];
+ for (const [o, s] of Object.entries(spec.origins)) {
+ keys.push(o);
+ if (s.derive) { for (const d of DERIVED) keys.push(o + '.' + d); keys.push(o + '.fact'); }
+ }
+ const pageSlug = (key: string): string | null => {
+ const [o, d] = key.split('.') as [string, string | undefined];
+ return d === undefined ? spec.origins[o]!.slug : d === 'fact' ? null : slugOf(o, d);
+ };
+ const doc = (title: string, key: string, fm: readonly string[], type = 'note', old = false) =>
+ ['---', 'type: ' + type, 'title: ' + title, ...fm, '---', '# ' + title, '', 'Harbor ledger planning notes ' + (old ? oldCanary(key) : canary(key)) + ' here.'].join('\n');
+
+ for (const id of spec.members) await engine.executeRaw('INSERT INTO access_members (id) VALUES ($1)', [id]);
+ for (const [g, ms] of Object.entries(spec.groups ?? {})) {
+ await engine.executeRaw('INSERT INTO access_groups (id) VALUES ($1)', [g]);
+ for (const m of ms) await engine.executeRaw('INSERT INTO access_group_members (group_id, member_id) VALUES ($1, $2)', [g, m]);
+ }
+ let root = '';
+ if (store === 'git') {
+ root = mkdtempSync(join(tmpdir(), 'gbrain-lineage-'));
+ git(root, 'init', '-q', '-b', 'main');
+ git(root, 'config', 'user.email', '[email protected]');
+ git(root, 'config', 'user.name', 't');
+ await engine.executeRaw("INSERT INTO sources (id, name, local_path, config) VALUES ($1, $1, $2, '{}')", [src, root]);
+ for (const old of [true, false]) {
+ for (const [o, s] of Object.entries(spec.origins)) {
+ mkdirSync(join(root, s.slug, '..'), { recursive: true });
+ writeFileSync(join(root, s.slug + '.md'), doc(o + ' origin', o, s.fm, 'note', old) + '\n');
+ }
+ mkdirSync(join(root, '.gbrain'), { recursive: true });
+ writeFileSync(join(root, POLICY_FILE), serializePolicyYaml(spec.rules));
+ git(root, 'add', '-A');
+ git(root, 'commit', '-q', '-m', old ? 'pages and policy' : 'pages again');
+ await performSync(engine, { sourceId: src, repoPath: root, noPull: true, noEmbed: true, full: true, concurrency: 1 });
+ }
+ } else {
+ await engine.executeRaw('INSERT INTO sources (id, name) VALUES ($1, $1) ON CONFLICT (id) DO NOTHING', [src]);
+ await proposeRevision(engine, src, spec.rules, { origin: 'cli', store: 'database' });
+ for (const old of [true, false]) {
+ for (const [o, s] of Object.entries(spec.origins)) await importFromContent(engine, s.slug, doc(o + ' origin', o, s.fm, 'note', old), { sourceId: src });
+ }
+ }
+ // The entity and hub pages carry their own types, so search's type-diversity cap (60% per type) never trims the pages under test.
+ await importFromContent(engine, ENTITY, doc('entity', 'entity', [], 'person').replace('Harbor ledger planning notes', 'Anchor page'), { sourceId: src });
+ await importFromContent(engine, HUB, doc('hub', 'hub', [], 'project').replace('Harbor ledger planning notes', 'Anchor page'), { sourceId: src });
+ for (const [o, s] of Object.entries(spec.origins)) {
+ await engine.addLink(s.slug, HUB, 'hub', 'mentions', 'fixture', undefined, undefined, { fromSourceId: src, toSourceId: src });
+ if (!s.derive) continue;
+ for (const old of [true, false]) {
+ await importFromContent(engine, slugOf(o, 'atom'), doc(o + ' atom', o + '.atom', ['visibility: world', 'source_slug: ' + s.slug], 'atom', old), { sourceId: src });
+ await importFromContent(engine, slugOf(o, 'df'), doc(o + ' derived', o + '.df', ['derived_from: [' + s.slug + ']'], 'note', old), { sourceId: src });
+ await importFromContent(engine, slugOf(o, 'concept'), doc(o + ' concept', o + '.concept', ['visibility: world', 'synthesized_by: fixture'], 'concept', old), { sourceId: src });
+ await importFromContent(engine, slugOf(o, 'event'), doc(o + ' event', o + '.event', ['captured_via: life-chronicle:fixture', 'event:', ' depth: ' + s.slug], 'event', old), { sourceId: src });
+ }
+ await engine.addLink(slugOf(o, 'concept'), slugOf(o, 'atom'), 'input', 'synthesized_from', 'concept-provenance', undefined, undefined, { fromSourceId: src, toSourceId: src });
+ for (const d of DERIVED) await engine.addLink(slugOf(o, d), HUB, 'hub', 'mentions', 'fixture', undefined, undefined, { fromSourceId: src, toSourceId: src });
+ await engine.executeRaw("INSERT INTO facts (source_id, entity_slug, fact, kind, visibility, source, source_markdown_slug, valid_from) VALUES ($1, $2, $3, 'fact', 'world', 'fixture', $4, now())",
+ [src, ENTITY, 'Harbor fact planning ' + canary(o + '.fact'), s.slug]);
+ }
+ const tokens: Record<string, string> = {};
+ const tokenIds: Record<string, string> = {};
+ const callers = new Map(spec.callers.map(c => [c.name, c]));
+ for (const c of spec.callers) {
+ if (c.as) continue;
+ const minted = await mintLegacyToken(engine, { name: c.name, scopes: ['read'], takesHolders: ['world'], sourceGrant: [src] });
+ tokens[c.name] = minted.token;
+ tokenIds[c.name] = minted.id;
+ if (c.member || c.mayActFor) await bindCredential(engine, { kind: 'token', id: minted.id }, { ...(c.member ? { member: c.member } : {}), ...(c.mayActFor ? { mayActFor: c.mayActFor } : {}) });
+ if (c.grantedSources) await rescopeLegacyToken(engine, parseRescopeTokenArgs([c.name, '--private-pages', 'granted-sources']));
+ }
+ if (spec.owner) await setOwner(engine, spec.owner);
+ const provider = () => new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });
+
+ async function call(who: string, op: string, params: Record<string, unknown>): Promise<string> {
+ const c = callers.get(who);
+ if (!c) throw new Error('unknown caller ' + who);
+ if (c.as) {
+ const preview = await openAsPreview(engine, c.as, op, true);
+ const out = await preview.run(() => dispatchToolCall(engine, op, { ...params }, preview.context({ remote: false, sourceId: src }) as never));
+ return out.content.map(x => x.text).join('\n');
+ }
+ const auth = await provider().verifyAccessToken(tokens[who]!) as unknown as AuthInfo;
+ const sourceId = auth.sourceId ?? 'default';
+ const localFederated = await noGrantFederatedScope(engine, auth.hasSourceGrant, sourceId);
+ const out = await dispatchToolCall(engine, op, { ...params }, {
+ remote: true, transport: 'http', auth, sourceId, takesHoldersAllowList: auth.takesHoldersAllowList ?? ['world'],
+ ...(localFederated ? { localFederatedSourceIds: localFederated } : {}),
+ ...(c.audience ? { onBehalfOf: { header: c.audience.join(','), requestMeta: undefined } } : {}),
+ });
+ return out.content.map(x => x.text).join('\n');
+ }
+
+ async function seenBy(who: string): Promise<Seen> {
+ __resetPrivateVisibilityCacheForTests();
+ const out: Seen = {};
+ for (const [label, op, params, mode] of READS) {
+ const seen = new Set<string>();
+ if (mode === 'page' || mode === 'versions') {
+ for (const key of keys) {
+ const slug = pageSlug(key);
+ if (!slug) continue;
+ const text = await call(who, op, params(slug));
+ if (text.includes(mode === 'versions' ? oldCanary(key) : canary(key))) seen.add(key);
+ }
+ } else {
+ const text = await call(who, op, params(''));
+ for (const key of keys) {
+ const slug = pageSlug(key);
+ if (mode === 'backlinks' || label === 'list_pages' ? (slug !== null && text.includes('"' + slug + '"')) : text.includes(canary(key))) seen.add(key);
+ }
+ }
+ out[label] = keys.filter(k => seen.has(k));
+ }
+ return out;
+ }
+
+ /** What a caller reading exactly these page keys and fact keys sees on every path. */
+ const expected = (pages: string[], facts: string[]): Seen => {
+ const out: Seen = {};
+ for (const [label, op] of READS) {
+ out[label] = op === 'recall' ? keys.filter(k => facts.includes(k))
+ : op === 'query' ? keys.filter(k => pages.includes(k) || facts.includes(k))
+ : keys.filter(k => pages.includes(k));
+ }
+ return out;
+ };
+
+ async function setRules(rules: FolderRule[]): Promise<ProposalResult> {
+ if (store === 'database') return proposeRevision(engine, src, rules, { origin: 'cli', store: 'database' });
+ const { sync } = await writeGitRules(engine, src, root, rules, 'access: fixture rules');
+ if (!sync.proposal) throw new Error('git rules produced no proposal: ' + JSON.stringify(sync));
+ return sync.proposal;
+ }
+
+ async function approve(): Promise<string> {
+ const preview = await previewApply(engine, src);
+ if (!preview.plan_hash) throw new Error('nothing to approve');
+ const r = await applyApproved(engine, src, { expect: preview.plan_hash });
+ if (store === 'git') {
+ const approved = (await getRevision(engine, src, r.revision ?? undefined))?.rules ?? [];
+ await writeApprovedFile(root, approved, 'access: approve fixture rules');
+ await syncGitPolicy(engine, src, root);
+ }
+ return preview.plan_hash;
+ }
+
+ return {
+ engine, keys, pageSlug, canary, call, seenBy, expected, setRules, approve, tokenIds,
+ close: async () => {
+ __setEmbedTransportForTests(null);
+ resetGateway();
+ await closeEngine();
+ if (root) rmSync(root, { recursive: true, force: true });
+ },
+ };
+}
+
+/** Every key of \`keys\` that starts with one of \`origins\` and is a derived page (not the origin, not the fact). */
+export function derivedOf(keys: readonly string[], origins: readonly string[]): string[] {
+ return keys.filter(k => { const [o, d] = k.split('.'); return d !== undefined && d !== 'fact' && origins.includes(o!); });
+}
+
+/** The fact keys of \`origins\`. */
+export function factsOf(keys: readonly string[], origins: readonly string[]): string[] {
+ return keys.filter(k => { const [o, d] = k.split('.'); return d === 'fact' && origins.includes(o!); });
+}
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index 08dcf2bd9f..a3e905465c 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -12,6 +12,7 @@
# other Postgres lane runs. The unit, serial and slow lanes unset
# themselves from scripts/postgres-arm-weights.json.
test/access-as.test.ts
+test/access-audience-members.test.ts
test/access-binding.test.ts
test/access-federated-member-writes.test.ts
test/access-folder-lock-order.test.ts
@@ -21,6 +22,7 @@ test/access-folder-scoped-role.test.ts
test/access-hidden-page-writes.test.ts
test/access-member-facts.test.ts
test/access-member-sweep.test.ts
+test/access-members-read-lineage.test.ts
test/access-members.test.ts
test/access-on-behalf-of.test.ts
test/access-owner-default-writes.test.ts
@@ -28,6 +30,7 @@ test/access-owner-reads.test.ts
test/access-page-indexes-online.test.ts
test/access-page-rule-fileless.test.ts
test/access-qm-actor.test.ts
+test/access-raw-only-rules.test.ts
test/access-token-grant-columns.test.ts
test/access-ungranted-member-writes.test.ts
test/access-writes.test.ts