Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Hide facts, timeline and tags of deleted pages and facts about pages the caller cannot read
garrytan27c272c76d64
diff --git a/scripts/check-engine-sql-dynamic.ts b/scripts/check-engine-sql-dynamic.tsindex 0c3a0a82d4..fc6fbfb75f 100644--- a/scripts/check-engine-sql-dynamic.ts+++ b/scripts/check-engine-sql-dynamic.ts@@ -80,6 +80,8 @@ const VETTED_BUILDERS: Record<string, string> = {privateTimelineEventFilterFragment: 'src/core/search/private-visibility.ts: constant timeline-event visibility predicate over a caller alias',privateSnapshotFilterFragment: 'src/core/search/private-visibility.ts: constant snapshot visibility predicate over a caller alias',rederiveHiddenSql: 'src/core/eligibility/sql.ts: constant needs_rederive NOT EXISTS predicate over a literal table name and caller alias; no values',+ deletedPageProjectionHiddenSql: 'src/core/eligibility/sql.ts: constant soft-deleted-page NOT EXISTS predicate over a literal table name and caller alias; no values',+ privateFactFilterForCaller: 'src/core/search/private-visibility.ts: privateProvenanceFilterFragment ANDed with privateEntityFilterForCaller (the caller page policy over a constant entity-page alias); no values',privateProvenanceFilterFragment: 'src/core/search/private-visibility.ts: constant fact-provenance visibility predicate over a caller alias',readersAllowedSql: 'src/core/search/private-visibility.ts: GBRA-218 readers predicate over a caller alias; splices only identities that pass validIdentity (member:/group: plus [a-z0-9._-]), else none',callerReadersAllowedSql: 'src/core/search/private-visibility.ts: GBRA-231 readersAllowedSql for the current caller, one conjunct per audience identity; each identity passes validIdentity',diff --git a/src/core/context/proactive-brief.ts b/src/core/context/proactive-brief.tsindex e662df3aca..3dca070c4f 100644--- a/src/core/context/proactive-brief.ts+++ b/src/core/context/proactive-brief.ts@@ -19,7 +19,7 @@ import { isConfigTruthy } from '../config.ts';import { HALFLIFE_DAYS } from '../facts/decay.ts';import { listOpenLoops, type OpenLoopRow } from '../loops/loops-store.ts';import { normalizeAlias } from '../search/alias-normalize.ts';-import { privatePagesFilterFragment, privateProvenanceFilterFragment, privateTimelineEventFilterFragment } from '../search/private-visibility.ts';+import { privatePagesFilterFragment, privateFactFilterForCaller, privateTimelineEventFilterFragment } from '../search/private-visibility.ts';import { pageEligibleSql, projectionEligibleSql } from '../eligibility/sql.ts';import type { ReadEligibility } from '../eligibility/policy.ts';import { renderTrustedInline, trustFields } from '../eligibility/labels.ts';@@ -423,7 +423,7 @@ async function loopItems(engine: BrainEngine, cp: BriefCounterparty, clock: Brieconst rows = await e.executeRaw<{ id: number | string; fact: string; trust_tier: unknown; write_origin: unknown }>(`SELECT facts.id, facts.fact, facts.trust_tier, facts.write_origin FROM factsWHERE facts.id = ANY($1::bigint[]) AND facts.expired_at IS NULL AND facts.visibility = 'world'- AND ${privateProvenanceFilterFragment('facts')}+ AND ${privateFactFilterForCaller('facts')}AND ${projectionEligibleSql('facts', 'facts', o.eligibility)}`,[factIds],);diff --git a/src/core/eligibility/sql.ts b/src/core/eligibility/sql.tsindex 9c1b7fde35..22fa2d2d16 100644--- a/src/core/eligibility/sql.ts+++ b/src/core/eligibility/sql.ts@@ -46,6 +46,20 @@ export function quarantinedProjectionHiddenSql(table: Exclude<EligibilityTable,return `NOT EXISTS (SELECT 1 FROM pages elig_qp WHERE elig_qp.id = ${alias}.page_id AND ${quarantined('elig_qp')})`;}+/**+ * A deleted page takes its projections with it: a fact held on or about a soft-deleted page (its provenance page+ * `source_markdown_slug` or its entity page `entity_slug`, in the fact's own source), and a take or timeline entry of+ * a soft-deleted page, is hidden from every reader until the page is restored. Nothing is changed, so a restore brings+ * every row back as it was.+ */+export function deletedPageProjectionHiddenSql(table: Exclude<EligibilityTable, 'pages'>, alias: string): string {+ if (table === 'facts') {+ return `NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.source_id = ${alias}.source_id+ AND elig_dp.slug = ANY(ARRAY[${alias}.source_markdown_slug, ${alias}.entity_slug]) AND elig_dp.deleted_at IS NOT NULL)`;+ }+ return `NOT EXISTS (SELECT 1 FROM pages elig_dp WHERE elig_dp.id = ${alias}.page_id AND elig_dp.deleted_at IS NOT NULL)`;+}+/*** CEO-20: true for rows a proactive surface must not inject: tier at or below* agent_written and a write-gate flag receipt in an instruction family. The@@ -71,12 +85,12 @@ export function rederiveHiddenSql(table: EligibilityTable, alias: string): strin/*** The whole row predicate for one projection table under a policy. Always- * hides quarantined-page projections and rows awaiting re-derivation.+ * hides deleted-page and quarantined-page projections and rows awaiting re-derivation.* Gate holds never reach these tables (write_gate_holds) and purged rows are* deleted, so neither needs a clause here.*/export function projectionEligibleSql(table: Exclude<EligibilityTable, 'pages'>, alias: string, policy: ReadEligibility | undefined): string {- const clauses = [quarantinedProjectionHiddenSql(table, alias), rederiveHiddenSql(table, alias)];+ const clauses = [deletedPageProjectionHiddenSql(table, alias), quarantinedProjectionHiddenSql(table, alias), rederiveHiddenSql(table, alias)];if (policy?.floor) clauses.push(trustFloorSql(alias, policy.floor));if (policy?.suppressFlagged) clauses.push(`NOT ${activationSuppressedSql(table, alias)}`);return clauses.join(' AND ');diff --git a/src/core/engine-sql/facts.ts b/src/core/engine-sql/facts.tsindex 4cbd267f80..9f5ee4c252 100644--- a/src/core/engine-sql/facts.ts+++ b/src/core/engine-sql/facts.ts@@ -27,7 +27,7 @@ import type { SqlExecutor } from './executor.ts';import type { LegacyUnscopedRead } from './brands.ts';import { sqlFragment, trustedSql } from './fragment.ts';import { compileRowNormalizer } from './normalize.ts';-import { projectionEligibleSql } from '../eligibility/sql.ts';+import { deletedPageProjectionHiddenSql, projectionEligibleSql } from '../eligibility/sql.ts';import { FACT_WITHDRAWAL_STAMP_DEFERRED_SETTING } from '../facts/insert-guard-schema.ts';import { privateProvenanceFilterUnderPolicy } from '../search/private-visibility.ts';import { factVisibilitySql, onOwnedMemoryPageSql } from '../access/member-facts.ts';@@ -53,9 +53,9 @@ async function embeddingCast(exec: SqlExecutor, probe: ResolveEmbeddingCast | un* silently misses matches outside the newest-N window on high-cardinality* entities. Parity with the pglite engine's `_listFacts`.*/-/** #5575: the read-eligibility predicate for list reads that pass a policy (eligibility/sql.ts). */-function eligibilityClause(opts: FactListOpts | undefined) {- return opts?.eligibility ? sqlFragment` AND ${trustedSql(projectionEligibleSql('facts', 'facts', opts.eligibility))}` : sqlFragment``;+/** #5575: the read-eligibility predicate for list reads that pass a policy (eligibility/sql.ts); every read hides a deleted page's facts. */+function eligibilityClause(opts: Pick<FactListOpts, 'eligibility'> | undefined) {+ return sqlFragment` AND ${trustedSql(opts?.eligibility ? projectionEligibleSql('facts', 'facts', opts.eligibility) : deletedPageProjectionHiddenSql('facts', 'facts'))}`;}/** GST-359 C2: a visibility list, widened only to the caller's own member-page private facts (access/member-facts.ts). */@@ -551,7 +551,7 @@ export async function listSupersessions(WHERE source_id = ${source_id}AND superseded_by IS NOT NULL${since ? sqlFragment`AND COALESCE(expired_at, valid_until) >= ${since}` : sqlFragment``}- ${visibilityClause(visibility)}${privacyClause(opts)}${opts?.eligibility ? sqlFragment` AND ${trustedSql(projectionEligibleSql('facts', 'facts', opts.eligibility))}` : sqlFragment``}+ ${visibilityClause(visibility)}${privacyClause(opts)}${eligibilityClause(opts)}ORDER BY COALESCE(expired_at, valid_until) DESC, id DESCLIMIT ${limit}`)).rows;diff --git a/src/core/facts/contested-claims.ts b/src/core/facts/contested-claims.tsindex 1e36f4fece..1c96791bba 100644--- a/src/core/facts/contested-claims.ts+++ b/src/core/facts/contested-claims.ts@@ -18,7 +18,7 @@ import type { BrainEngine } from '../engine.ts';import type { Contested } from '../eligibility/labels.ts';import type { ReadEligibility } from '../eligibility/policy.ts';import { projectionEligibleSql } from '../eligibility/sql.ts';-import { privateProvenanceFilterFragment } from '../search/private-visibility.ts';+import { privateFactFilterForCaller } from '../search/private-visibility.ts';export interface ContestedReadPolicy { remote: boolean; excludePrivate: boolean; eligibility?: ReadEligibility }/** Filled when the lookup failed: recall reports it as facts_degraded. */@@ -28,7 +28,7 @@ const active = (a: string) => a + '.expired_at IS NULL AND (' + a + '.valid_unticonst readable = (a: string, policy: ContestedReadPolicy) => [active(a),...(policy.remote ? [a + ".visibility = 'world'"] : []),- ...(policy.excludePrivate ? [privateProvenanceFilterFragment(a)] : []),+ ...(policy.excludePrivate ? [privateFactFilterForCaller(a)] : []),projectionEligibleSql('facts', a, policy.eligibility),].join(' AND ');diff --git a/src/core/ops/tags.ts b/src/core/ops/tags.tsindex 9521dad63a..fd104ee8fc 100644--- a/src/core/ops/tags.ts+++ b/src/core/ops/tags.ts@@ -75,14 +75,15 @@ const get_tags: Operation = {// (ctx.auth.allowedSources) reaches the engine, not just scalar ctx.sourceId.// Was `ctx.sourceId ? {sourceId} : {}` — a federated client got '{}' →// engine fell back to 'default' (functionality gap + cross-source leak).- // Untrusted callers never learn a private or soft-deleted page's tags- // (readPolicyOpts resolves the operator's private-pages posture).+ // Untrusted callers never learn a private page's tags (readPolicyOpts+ // resolves the operator's private-pages posture), and no caller reads a+ // soft-deleted page's tags: they come back with restore_page.const policy = await readPolicyOpts(ctx);const tags = await ctx.engine.getTags(p.slug as string, {sourceId: policy.sourceId,sourceIds: policy.sourceIds,excludePrivate: policy.excludePrivate,- liveOnly: ctx.remote !== false,+ liveOnly: true,});if (ctx.remote === false || tags.length === 0) return tags;// #8384: a remote reader gets a quoted page's tags quoted, as get_page and fetch return them.diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex fed0044699..e064bb6c88 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -881,6 +881,9 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wriif ((snapshot?.page.id ?? null) !== row.page_id) throw pageIdentityError(snapshot != null || row.page_id === null, 'The accepted page identity changed.');const observedRevision = snapshot?.revision ?? null;const activePack = pack?.manifest;+ // A new page written over a soft-deleted one starts clean: it takes none of the deleted page's tags, timeline rows or+ // facts (the delete recorded them in the page's history; restore_page is how the old page comes back).+ const replacesTombstone = snapshot?.page.deleted_at != null && (row.operation === 'put_page' || row.operation === 'capture');if (row.operation === 'put_page' && snapshot && !snapshot.page.deleted_at && typeof p.content === 'string'&& `${snapshot.page.compiled_truth}\n${snapshot.page.timeline ?? ''}`.trim()) {const incoming = parseMarkdown(p.content, row.slug, { activePack });@@ -900,6 +903,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wriconst privateRequest = privateRequestGuarded(row.operation, p.kind) && typeof content === 'string' ? readPrivateRequest(content, () => parseMarkdown(content as string, row.slug, { activePack }).frontmatter) : null;if (privateRequest) assertPrivateRequestAllowed(row, content as string, privateRequest.frontmatter);let versionTags: string[] | undefined = preparedIntent?.tags;+ if (replacesTombstone && typeof content === 'string') versionTags = parseMarkdown(content, row.slug, { activePack }).tags;// A replacement/restore publishes a live page. Only a recorded version may// explicitly restore a tombstone; legacy versions leave this state unchanged.let targetDeleted = false;@@ -944,8 +948,8 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wri}}const projected = !(options.unprojected || row.operation === 'remember' || row.operation.startsWith('takes_') || (row.operation === 'extract_facts' && p.kind === 'managed_facts_entity'));- const writer = (row.operation === 'put_page' || row.operation === 'edit_page') && p.kind !== 'managed_maintenance_page'- && (preparedIntent !== undefined || typeof p.expected_revision === 'string') ? 'editing' : 'preserving';+ const writer = replacesTombstone || ((row.operation === 'put_page' || row.operation === 'edit_page') && p.kind !== 'managed_maintenance_page'+ && (preparedIntent !== undefined || typeof p.expected_revision === 'string')) ? 'editing' : 'preserving';// #5969 (D3): only an ordinary put_page intent carries a timeline section; every other writer keeps the shared policy.const timelinePolicy = row.operation === 'put_page' ? timelineWritePolicy(p, row.authority.remote, writer) : undefined;enterClaimStep(clock, 'timeline_policy', undefined, 'db');@@ -953,7 +957,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wrislug: row.slug, sourceId: row.source_id, content, prior: snapshot });// #5567: database-only timeline rows are written back into the page before// the no-op check, digest, rendering and chunking see the body.- if (projected && snapshot && typeof content === 'string') {+ if (projected && snapshot && !replacesTombstone && typeof content === 'string') {const parsed = parseMarkdown(content,row.slug);enterClaimStep(clock, 'materialize_timeline', undefined, 'db');const { timeline, materialized } = await materializeTimeline(engine,parsed,row.slug,snapshot,writer,timelinePolicy);@@ -1087,6 +1091,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wrilet segmentedWrite = false;if (!noop) {const prior = snapshot ? await storedPageTier(tx, row.source_id, row.slug) : null;+ if (replacesTombstone) await retireTombstoneFacts(tx, row.source_id, row.slug);// ENG-1: a managed fence edit keeps the page's tier; CEO-12: an agent rewrite that lowers a page files a queue item.const applied = await (isFenceEditWrite(row) ? withTrustKeep(tx, ['pages'], () => ready.apply(tx, lean ? preimage : undefined)) : ready.apply(tx, lean ? preimage : undefined));projectionPending = applied?.segmented?.complete === false || applied?.projectionPending === true;@@ -1155,6 +1160,17 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wrireturn publication;}+/**+ * A put over a soft-deleted page: expire (not delete) the active facts the deleted page held, and those about it that no+ * live page holds, so the new page does not inherit them. Facts other live pages hold about the slug stay theirs.+ */+async function retireTombstoneFacts(tx: BrainEngine, sourceId: string, slug: string): Promise<void> {+ await tx.executeRaw(`UPDATE facts f SET expired_at = now(), row_num = NULL+ WHERE f.source_id = $1 AND f.expired_at IS NULL+ AND (f.source_markdown_slug = $2 OR (f.entity_slug = $2 AND NOT EXISTS (SELECT 1 FROM pages lp+ WHERE lp.source_id = f.source_id AND lp.slug = f.source_markdown_slug AND lp.slug <> $2 AND lp.deleted_at IS NULL)))`, [sourceId, slug]);+}+/** What a page's projections report back: removed timeline rows and the contested proposal refs (#5575 guarded supersession). */function projectedRows(projected: { timelineRowsRemoved?: TimelineRowsRemoved | null; contested?: string[] } | undefined): { removedTimeline: TimelineRowsRemoved | null; contested: string[] } {return { removedTimeline: projected?.timelineRowsRemoved ?? null, contested: projected?.contested ?? [] };diff --git a/src/core/pglite-engine.ts b/src/core/pglite-engine.tsindex fcb1ecf603..2ec1cd39ba 100644--- a/src/core/pglite-engine.ts+++ b/src/core/pglite-engine.ts@@ -126,7 +126,8 @@ import { resolveBoostMap, resolveHardExcludes } from './search/source-boost.ts';import { buildSourceFactorCase, buildHardExcludeClause, buildVisibilityClause, buildBestPerPagePoolCte, buildOrFallbackWebsearchQuery, boundWebsearchQuery, collapseWebsearchDashRuns, keywordPhraseFactorSql } from './search/sql-ranking.ts';import { RARE_TERM_CHUNK_CAP, rankOrFallbackByRarity, rareTermPagesSql, type RareTermPages } from './search/keyword-or-rarity.ts';import { keywordArmRows } from './search/keyword-identifier-probe.ts';-import { privatePagesFilterFragment, privateSnapshotFilterFragment, privateLinkOriginFilterFragment, privateTimelineEventFilterFragment, privateProvenanceFilterFragment, privatePagesFilterForCaller } from './search/private-visibility.ts';+import { privatePagesFilterFragment, privateSnapshotFilterFragment, privateLinkOriginFilterFragment, privateTimelineEventFilterFragment, privateFactFilterForCaller, privatePagesFilterForCaller } from './search/private-visibility.ts';+import { deletedPageProjectionHiddenSql } from './eligibility/sql.ts';import { EMBED_SKIP_FILTER_FRAGMENT } from './embed-skip.ts';import {vectorCastSuffix,@@ -2192,9 +2193,9 @@ export class PGLiteEngine implements BrainEngine {let scope: string;if (opts?.sourceIds && opts.sourceIds.length) { params.push(opts.sourceIds); scope = `AND source_id = ANY($${params.length})`; }else { params.push(opts?.sourceId ?? null); scope = `AND ($${params.length}::text IS NULL OR source_id = $${params.length})`; }- // Page-visibility gate on the provenance page, applied BEFORE DISTINCT ON- // so the untrusted caller resolves the newest value they may see.- const privacy = opts?.excludePrivate ? `AND ${privateProvenanceFilterFragment('facts')}` : '';+ // Page-visibility gate on the provenance and entity pages, applied BEFORE DISTINCT ON+ // so the untrusted caller resolves the newest value they may see; a deleted page's observations are hidden for everyone.+ const privacy = `AND ${deletedPageProjectionHiddenSql('facts', 'facts')}${opts?.excludePrivate ? ` AND ${privateFactFilterForCaller('facts')}` : ''}`;params.push(opts?.visibility ?? null);const visibility = `AND ($${params.length}::text[] IS NULL OR visibility = ANY($${params.length}::text[]))`;const r = await this.db.query(@@ -2236,9 +2237,9 @@ export class PGLiteEngine implements BrainEngine {let scope: string;if (opts?.sourceIds && opts.sourceIds.length) { params.push(opts.sourceIds); scope = `AND source_id = ANY($${params.length})`; }else { params.push(opts?.sourceId ?? null); scope = `AND ($${params.length}::text IS NULL OR source_id = $${params.length})`; }- // Same provenance-page gate as getOntology, inside the CTE so a conflict+ // Same page gates as getOntology, inside the CTE so a conflict// that only exists because of a hidden provenance is never reported.- const privacy = opts?.excludePrivate ? `AND ${privateProvenanceFilterFragment('facts')}` : '';+ const privacy = `AND ${deletedPageProjectionHiddenSql('facts', 'facts')}${opts?.excludePrivate ? ` AND ${privateFactFilterForCaller('facts')}` : ''}`;params.push(opts?.visibility ?? null);const visibility = `AND ($${params.length}::text[] IS NULL OR visibility = ANY($${params.length}::text[]))`;const r = await this.db.query(diff --git a/src/core/postgres-engine.ts b/src/core/postgres-engine.tsindex 9c9d976bd4..bc9a076ba2 100644--- a/src/core/postgres-engine.ts+++ b/src/core/postgres-engine.ts@@ -123,7 +123,8 @@ import { commonOrTokens, narrowedOrFallbackText, readOrTokenShares } from './seaimport { keywordArmRows } from './search/keyword-identifier-probe.ts';import { RARE_TERM_CHUNK_CAP, rankOrFallbackByRarity, rareTermPagesSql, type RareTermPages } from './search/keyword-or-rarity.ts';import { buildKeywordChunkMatch, KEYWORD_RANK_CANDIDATES, KEYWORD_RANKED_ROWS_CTE, KEYWORD_STATEMENT_SETTINGS } from './search/keyword-chunk-match.ts';-import { privatePagesFilterFragment, privateSnapshotFilterFragment, privateLinkOriginFilterFragment, privateTimelineEventFilterFragment, privateProvenanceFilterFragment, privatePagesFilterForCaller } from './search/private-visibility.ts';+import { privatePagesFilterFragment, privateSnapshotFilterFragment, privateLinkOriginFilterFragment, privateTimelineEventFilterFragment, privateFactFilterForCaller, privatePagesFilterForCaller } from './search/private-visibility.ts';+import { deletedPageProjectionHiddenSql } from './eligibility/sql.ts';import { DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_DIMENSIONS } from './ai/defaults.ts';import { readStoredEmbeddingIdentity } from './stored-embedding-identity.ts';import { assertEmbeddedEmbedding, embeddedSchemaEmbedding, embeddedSettingsRecord, isEmbeddedEngine, settingsConnectionOptions } from './embedded-engine.ts';@@ -2012,9 +2013,9 @@ export class PostgresEngine implements BrainEngine {const scope = opts?.sourceIds && opts.sourceIds.length? sql`AND source_id = ANY(${opts.sourceIds})`: sql`AND (${opts?.sourceId ?? null}::text IS NULL OR source_id = ${opts?.sourceId ?? null})`;- // Page-visibility gate on the provenance page, applied BEFORE DISTINCT ON- // so the untrusted caller resolves the newest value they may see.- const privacy = opts?.excludePrivate ? sql.unsafe(`AND ${privateProvenanceFilterFragment('facts')}`) : sql``;+ // Page-visibility gate on the provenance and entity pages, applied BEFORE DISTINCT ON+ // so the untrusted caller resolves the newest value they may see; a deleted page's observations are hidden for everyone.+ const privacy = sql.unsafe(`AND ${deletedPageProjectionHiddenSql('facts', 'facts')}${opts?.excludePrivate ? ` AND ${privateFactFilterForCaller('facts')}` : ''}`);const visibility = opts?.visibility ? sql`AND visibility = ANY(${opts.visibility})` : sql``;const rows = await sql<OntologyValue[]>`SELECT DISTINCT ON (dimension)@@ -2051,9 +2052,9 @@ export class PostgresEngine implements BrainEngine {const scope = opts?.sourceIds && opts.sourceIds.length? sql`AND source_id = ANY(${opts.sourceIds})`: sql`AND (${opts?.sourceId ?? null}::text IS NULL OR source_id = ${opts?.sourceId ?? null})`;- // Same provenance-page gate as getOntology, inside the CTE so a conflict+ // Same page gates as getOntology, inside the CTE so a conflict// that only exists because of a hidden provenance is never reported.- const privacy = opts?.excludePrivate ? sql.unsafe(`AND ${privateProvenanceFilterFragment('facts')}`) : sql``;+ const privacy = sql.unsafe(`AND ${deletedPageProjectionHiddenSql('facts', 'facts')}${opts?.excludePrivate ? ` AND ${privateFactFilterForCaller('facts')}` : ''}`);const visibility = opts?.visibility ? sql`AND visibility = ANY(${opts.visibility})` : sql``;const rows = await sql<{ entity_slug: string; dimension: string; values: OntologyConflict['values'] }[]>`WITH cur AS (diff --git a/src/core/search/entity-facts.ts b/src/core/search/entity-facts.tsindex 15e6357f94..5ebbf4df70 100644--- a/src/core/search/entity-facts.ts+++ b/src/core/search/entity-facts.ts@@ -19,7 +19,7 @@import type { BrainEngine } from '../engine.ts';import { AUDIT_ROW_SOURCES } from '../facts/audit-sources.ts';-import { privateProvenanceFilterFragment } from './private-visibility.ts';+import { privateFactFilterForCaller } from './private-visibility.ts';import { factEntitySlugs } from '../mentions/siblings.ts';import { resolveQueryEntities, type ResolvedEntity } from './alias-fanout.ts';import { collapseFactReads } from '../facts/capture-dedup.ts';@@ -47,7 +47,7 @@ export function stripCollapseColumns<T extends CollapseColumns & { collapsed_ids}async function newestFacts(engine: BrainEngine, sourceId: string, slugs: string[], opts: { remote: boolean; minTrust?: TrustTier }, limit: number): Promise<Array<EntityFact & CollapseColumns>> {- const visibility = opts.remote ? `AND f.visibility = 'world' AND ${privateProvenanceFilterFragment('f')}` : '';+ const visibility = opts.remote ? `AND f.visibility = 'world' AND ${privateFactFilterForCaller('f')}` : '';const rows = await engine.executeRaw<EntityFact & CollapseColumns>(`SELECT f.id, f.fact, f.entity_slug, f.kind, f.valid_from::text AS valid_from, f.source, ${SAVED_FACT_COLLAPSE_COLUMNS}FROM facts fdiff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.tsindex 65ee019c4d..6c0f3f2379 100644--- a/src/core/search/private-visibility.ts+++ b/src/core/search/private-visibility.ts@@ -676,7 +676,22 @@ export function privateProvenanceFilterUnderPolicy(factAlias: string): string {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 ${readPolicyFragment('pp', [], hide)} END`: readPolicyFragment('pp', [], hide);- 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}))`;+ 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)})`;+}++/**+ * A fact is never wider than the page it is about: hide a fact whose entity page (`entity_slug`, looked up in the fact's+ * own source) the current caller cannot read under the read policy its page reads use, so a member the page's readers+ * name keeps the fact and every other remote caller loses it. A fact with no entity page passes. Read sites only; it+ * only ever narrows.+ */+export function privateEntityFilterForCaller(factAlias: string): string {+ return `NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = ${factAlias}.source_id AND entity_pp.slug = ${factAlias}.entity_slug AND NOT ${privatePagesFilterForCaller('entity_pp')})`;+}++/** privateProvenanceFilterFragment for a remote fact read: the provenance page gate plus the caller's entity-page gate. */+export function privateFactFilterForCaller(factAlias: string): string {+ return `(${privateProvenanceFilterFragment(factAlias)} AND ${privateEntityFilterForCaller(factAlias)})`;}/** True only inside a remote caller record whose read an operator relaxed (the env hatch or the config opt-out). */diff --git a/src/core/search/saved-facts-match.ts b/src/core/search/saved-facts-match.tsindex e35dce553d..357d2dae94 100644--- a/src/core/search/saved-facts-match.ts+++ b/src/core/search/saved-facts-match.ts@@ -13,7 +13,7 @@ import { collapseFactReads } from '../facts/capture-dedup.ts';import { projectionEligibleSql } from '../eligibility/sql.ts';import { factsFtsDocument, getFtsLanguage } from '../fts-language.ts';import { hasCJK } from '../cjk.ts';-import { privateProvenanceFilterFragment, resolveExcludePrivatePages } from './private-visibility.ts';+import { privateFactFilterForCaller, resolveExcludePrivatePages } from './private-visibility.ts';import { SAVED_FACT_COLLAPSE_COLUMNS, type CollapseColumns } from './entity-facts.ts';/** Words too common to count toward a saved-fact match; also the coverage relevance stopwords in ops/search.ts. */@@ -97,7 +97,7 @@ export async function matchingSavedFacts(ctx: OperationContext, scope: { sourceIAND f.expired_at IS NULL AND (f.valid_until IS NULL OR f.valid_until > now())AND f.source != ALL($2::text[])${ctx.remote !== false ? `AND f.visibility = 'world'` : ''}`;- const eligible = `${excludePrivate ? `AND ${privateProvenanceFilterFragment('f')}` : ''}+ const eligible = `${excludePrivate ? `AND ${privateFactFilterForCaller('f')}` : ''}AND ${projectionEligibleSql('facts', 'f', { floor: scope.minTrust })}`;const lang = getFtsLanguage();const doc = factsFtsDocument('f');diff --git a/src/core/verbs/entity-card.ts b/src/core/verbs/entity-card.tsindex 20b07bf297..1a021ac6bc 100644--- a/src/core/verbs/entity-card.ts+++ b/src/core/verbs/entity-card.ts@@ -584,7 +584,7 @@ async function assembleCard(const visibility = remote ? (['world'] as ('private' | 'world')[]) : undefined;// Facts saved about this entity may sit under a sibling page or the bare subject slug (siblings.ts).const factSlugs = await factEntitySlugs(engine, sourceId, pageSlug, { excludePrivate }).catch(() => [pageSlug]);- const { privatePagesFilterForCaller, privateLinkOriginFilterForCaller, privateProvenanceFilterFragment } = await import('../search/private-visibility.ts');+ const { privatePagesFilterForCaller, privateLinkOriginFilterForCaller, privateFactFilterForCaller } = await import('../search/private-visibility.ts');const inboundPrivacy = excludePrivate? ` AND ${privatePagesFilterForCaller('f')} AND ${privateLinkOriginFilterForCaller('l')}`: '';@@ -655,7 +655,7 @@ async function assembleCard(`SELECT COUNT(*) AS nFROM factsWHERE source_id = $1 AND entity_slug = ANY($2::text[])- AND expired_at IS NULL${remote ? ` AND visibility = 'world'` : ''}${excludePrivate ? ` AND ${privateProvenanceFilterFragment('facts')}` : ''}+ AND expired_at IS NULL${remote ? ` AND visibility = 'world'` : ''}${excludePrivate ? ` AND ${privateFactFilterForCaller('facts')}` : ''}AND ${projectionEligibleSql('facts', 'facts', eligibility)}`,[sourceId, factSlugs],)diff --git a/test/fixtures/goldens/sql-text/facts.json b/test/fixtures/goldens/sql-text/facts.jsonindex 7a39eccbfb..cb7c09ec3b 100644--- a/test/fixtures/goldens/sql-text/facts.json+++ b/test/fixtures/goldens/sql-text/facts.json@@ -140,8 +140,8 @@"null","null"],- "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 ($2::text IS NULL OR source_id = $3) ) 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": "0fa36872be345c8a16b8d862ef3c94d292173b6a03a91c0094347682cd9859f2"+ "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 ($2::text IS NULL OR source_id = $3) 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) ) 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": "889bf144429d0afb1ac237d9b0bd2dcec27f8409c75377855e5289732b1277c4"}],"sourceIds+excludePrivate": [@@ -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 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 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(lower(btrim(pp.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(pp.frontmatter->>'confidentiality')) 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(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) 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))))) ) 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": "a10af4b2320b26394f426f2cb2e550adf182e264904aabd14855fbb4831cf865"+ "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 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(lower(btrim(pp.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(pp.frontmatter->>'confidentiality')) 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(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) 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 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(lower(btrim(entity_pp.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(entity_pp.frontmatter->>'confidentiality')) 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(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) 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": "c0fa29533cc6b48535f343ed84c2abfb330b7ea20e71fadc60a3a333cda49259"}]},@@ -165,8 +165,8 @@"string","number"],- "sql": "SELECT id, valid_from, valid_until, claim_metric, claim_value, claim_unit, claim_period, event_type, fact, source_session, source_markdown_slug, CASE WHEN embedding_model=(SELECT value FROM config WHERE key='embedding_model') AND embedded_text_hash=md5(fact) THEN embedding::text END AS embedding FROM facts WHERE source_id = $1 AND entity_slug = $2 AND expired_at IS NULL AND facts.visibility IN ('world') AND NOT EXISTS (SELECT 1 FROM pages elig_qp WHERE elig_qp.source_id = facts.source_id AND elig_qp.slug = facts.source_markdown_slug AND elig_qp.deleted_at IS NULL AND (COALESCE(elig_qp.frontmatter, '{}'::jsonb) ? 'quarantine')) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'facts' AND elig_nr.derived_id = facts.id::text) ORDER BY valid_from DESC, id DESC LIMIT $3",- "textSha256": "598971bc8cfe655cce331bcd51ac1b44758cb8e4d0992010fd065d4fb5ff2355"+ "sql": "SELECT id, valid_from, valid_until, claim_metric, claim_value, claim_unit, claim_period, event_type, fact, source_session, source_markdown_slug, CASE WHEN embedding_model=(SELECT value FROM config WHERE key='embedding_model') AND embedded_text_hash=md5(fact) THEN embedding::text END AS embedding FROM facts WHERE source_id = $1 AND entity_slug = $2 AND expired_at IS NULL AND facts.visibility IN ('world') 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 elig_qp WHERE elig_qp.source_id = facts.source_id AND elig_qp.slug = facts.source_markdown_slug AND elig_qp.deleted_at IS NULL AND (COALESCE(elig_qp.frontmatter, '{}'::jsonb) ? 'quarantine')) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'facts' AND elig_nr.derived_id = facts.id::text) ORDER BY valid_from DESC, id DESC LIMIT $3",+ "textSha256": "791649be50ef827e0faaf914d356654fa4d42f9d971b79f578f1bb2e48e3b00b"}],"event": [@@ -177,8 +177,8 @@"string","number"],- "sql": "SELECT id, valid_from, valid_until, claim_metric, claim_value, claim_unit, claim_period, event_type, fact, source_session, source_markdown_slug, CASE WHEN embedding_model=(SELECT value FROM config WHERE key='embedding_model') AND embedded_text_hash=md5(fact) THEN embedding::text END AS embedding FROM facts WHERE source_id = $1 AND entity_slug = $2 AND expired_at IS NULL AND facts.visibility IN ('world') AND NOT EXISTS (SELECT 1 FROM pages elig_qp WHERE elig_qp.source_id = facts.source_id AND elig_qp.slug = facts.source_markdown_slug AND elig_qp.deleted_at IS NULL AND (COALESCE(elig_qp.frontmatter, '{}'::jsonb) ? 'quarantine')) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'facts' AND elig_nr.derived_id = facts.id::text) AND event_type IS NOT NULL ORDER BY valid_from DESC, id DESC LIMIT $3",- "textSha256": "1e39ab85e99c2f8efcbad49d4727466603f3bae38c76a8a28ed5b7b9aa50c966"+ "sql": "SELECT id, valid_from, valid_until, claim_metric, claim_value, claim_unit, claim_period, event_type, fact, source_session, source_markdown_slug, CASE WHEN embedding_model=(SELECT value FROM config WHERE key='embedding_model') AND embedded_text_hash=md5(fact) THEN embedding::text END AS embedding FROM facts WHERE source_id = $1 AND entity_slug = $2 AND expired_at IS NULL AND facts.visibility IN ('world') 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 elig_qp WHERE elig_qp.source_id = facts.source_id AND elig_qp.slug = facts.source_markdown_slug AND elig_qp.deleted_at IS NULL AND (COALESCE(elig_qp.frontmatter, '{}'::jsonb) ? 'quarantine')) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'facts' AND elig_nr.derived_id = facts.id::text) AND event_type IS NOT NULL ORDER BY valid_from DESC, id DESC LIMIT $3",+ "textSha256": "f32adf826e14479184e68ab6e62034971f7cfd6d891b4381dd2421b61d5d1f02"}],"sourceIds+metric+since+until": [@@ -192,8 +192,8 @@"Date","number"],- "sql": "SELECT id, valid_from, valid_until, claim_metric, claim_value, claim_unit, claim_period, event_type, fact, source_session, source_markdown_slug, CASE WHEN embedding_model=(SELECT value FROM config WHERE key='embedding_model') AND embedded_text_hash=md5(fact) THEN embedding::text END AS embedding FROM facts WHERE source_id = ANY($1::text[]) AND entity_slug = $2 AND expired_at IS NULL AND NOT EXISTS (SELECT 1 FROM pages elig_qp WHERE elig_qp.source_id = facts.source_id AND elig_qp.slug = facts.source_markdown_slug AND elig_qp.deleted_at IS NULL AND (COALESCE(elig_qp.frontmatter, '{}'::jsonb) ? 'quarantine')) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'facts' AND elig_nr.derived_id = facts.id::text) AND claim_metric = $3 AND claim_metric IS NOT NULL AND valid_from >= $4 AND valid_from <= $5 ORDER BY valid_from DESC, id DESC LIMIT $6",- "textSha256": "a869e55cc6e4149eb86cdd875ea7bb90fedff0361a3eeefb3bf8b683a1b609e6"+ "sql": "SELECT id, valid_from, valid_until, claim_metric, claim_value, claim_unit, claim_period, event_type, fact, source_session, source_markdown_slug, CASE WHEN embedding_model=(SELECT value FROM config WHERE key='embedding_model') AND embedded_text_hash=md5(fact) THEN embedding::text END AS embedding FROM facts WHERE source_id = ANY($1::text[]) AND entity_slug = $2 AND expired_at IS NULL 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 elig_qp WHERE elig_qp.source_id = facts.source_id AND elig_qp.slug = facts.source_markdown_slug AND elig_qp.deleted_at IS NULL AND (COALESCE(elig_qp.frontmatter, '{}'::jsonb) ? 'quarantine')) AND NOT EXISTS (SELECT 1 FROM needs_rederive elig_nr WHERE elig_nr.derived_table = 'facts' AND elig_nr.derived_id = facts.id::text) AND claim_metric = $3 AND claim_metric IS NOT NULL AND valid_from >= $4 AND valid_from <= $5 ORDER BY valid_from DESC, id DESC LIMIT $6",+ "textSha256": "0d334769c5861820bac7ddd0c4334037cff4bfb7b5832c4e4fb973c7fcb83969"}]},@@ -230,8 +230,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 ($2::text IS NULL OR source_id = $3) AND COALESCE(valid_from, '-infinity'::timestamptz) <= COALESCE($4::timestamptz, now()) AND COALESCE(valid_until, 'infinity'::timestamptz) > COALESCE($5::timestamptz, now()) AND confidence >= $6 AND ($7::boolean OR dim_status IS NULL OR dim_status = 'active') ORDER BY dimension, valid_from DESC NULLS LAST, confidence DESC, id DESC",- "textSha256": "34084e478b807600e07f3aa6927ca19ac466e57d70fee3c09eef553b86c6b73d"+ "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 ($2::text IS NULL OR source_id = $3) 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 COALESCE(valid_from, '-infinity'::timestamptz) <= COALESCE($4::timestamptz, now()) AND COALESCE(valid_until, 'infinity'::timestamptz) > COALESCE($5::timestamptz, now()) AND confidence >= $6 AND ($7::boolean OR dim_status IS NULL OR dim_status = 'active') ORDER BY dimension, valid_from DESC NULLS LAST, confidence DESC, id DESC",+ "textSha256": "4d2f1416764d3f7165807fb59bee872e35d1db67192aeaebc6e8fc35a70d9a56"}],"sourceIds+excludePrivate": [@@ -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 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 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(lower(btrim(pp.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(pp.frontmatter->>'confidentiality')) 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(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) 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 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": "8c762c00c5f7b35b5d6d9e4e78f808aef170e1ea18f73a6d00363b5f3c35487e"+ "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 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(lower(btrim(pp.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(pp.frontmatter->>'confidentiality')) 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(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) 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 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(lower(btrim(entity_pp.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(entity_pp.frontmatter->>'confidentiality')) 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(lower(btrim(chronicle_origin.frontmatter->>'access')) IN ('private','restricted','confidential'), false) OR COALESCE(lower(btrim(chronicle_origin.frontmatter->>'confidentiality')) 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": "6bdf1b3da66666f069f26439750b85d18acce9ee0fe71a9530645d59c2596f7b"}]},@@ -520,8 +520,8 @@"number","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND entity_slug = $2 AND consolidated_at IS NULL AND kind = ANY($3::text[]) AND facts.visibility IN ('world') AND source != ALL($4::text[]) AND fact ILIKE $5 ESCAPE '\\' ORDER BY valid_from DESC, id DESC LIMIT $6 OFFSET $7",- "textSha256": "58c970e9c7c1ca7b38e5dc67dd6d0507ac9c63a37a4c45f52a775a1517fb51eb"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND entity_slug = $2 AND consolidated_at IS NULL AND kind = ANY($3::text[]) AND facts.visibility IN ('world') AND source != ALL($4::text[]) AND fact ILIKE $5 ESCAPE '\\' 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) ORDER BY valid_from DESC, id DESC LIMIT $6 OFFSET $7",+ "textSha256": "382772a89cb86b97fb1565f507dee897f9af3d8f6a4dadf014285ebfd98f0070"}],"default": [@@ -533,8 +533,8 @@"number","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND entity_slug = $2 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) ORDER BY valid_from DESC, id DESC LIMIT $3 OFFSET $4",- "textSha256": "f480c85f5b2b56d825347ae4812946eb71fcb8730bb4eb23655c538dab8e0b2e"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND entity_slug = $2 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) 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) ORDER BY valid_from DESC, id DESC LIMIT $3 OFFSET $4",+ "textSha256": "027398b406f284b7be64589ef4f64333d5a1badad86f1ca2958dbbef5e45b618"}]},@@ -551,8 +551,8 @@"number","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND source_session = $2 AND consolidated_at IS NULL AND kind = ANY($3::text[]) AND facts.visibility IN ('world') AND source != ALL($4::text[]) AND fact ILIKE $5 ESCAPE '\\' ORDER BY created_at DESC, id DESC LIMIT $6 OFFSET $7",- "textSha256": "4303ab045786dbf0844e317c08c07529b3ee46488b3330077d46c0f4e5ec6f28"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND source_session = $2 AND consolidated_at IS NULL AND kind = ANY($3::text[]) AND facts.visibility IN ('world') AND source != ALL($4::text[]) AND fact ILIKE $5 ESCAPE '\\' 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) ORDER BY created_at DESC, id DESC LIMIT $6 OFFSET $7",+ "textSha256": "f444afcaf1f782a97a26a5f2f8b287c392387372cc8536e87432a4ed30baa74d"}],"default": [@@ -564,8 +564,8 @@"number","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND source_session = $2 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) ORDER BY created_at DESC, id DESC LIMIT $3 OFFSET $4",- "textSha256": "16af231e53b7564dc3e84fe282ab684b8aa5ab3135ac6b602943d26f00fd96ba"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND source_session = $2 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) 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) ORDER BY created_at DESC, id DESC LIMIT $3 OFFSET $4",+ "textSha256": "71b913dc3e3424c8783fda4dabcc9dc0395316ef3fd0709e95b7a1f864de1443"}]},@@ -577,8 +577,8 @@"string","number"],- "sql": "SELECT *, to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS created_at_iso FROM facts WHERE source_id = $1 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) ORDER BY created_at ASC, id ASC LIMIT $2",- "textSha256": "0a40122b0f45781fe163473acc69c889aeb6c63e2fd366f2f15731229025b466"+ "sql": "SELECT *, to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS created_at_iso FROM facts WHERE source_id = $1 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) 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) ORDER BY created_at ASC, id ASC LIMIT $2",+ "textSha256": "0e5f910e4420459feeb01b79da58e46ba6797609021d40dc1e399ea268e2eab2"}],"keyset": [@@ -591,8 +591,8 @@"number","number"],- "sql": "SELECT *, gbrain_fact_fingerprint(fact) AS fact_fingerprint, to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS created_at_iso FROM facts WHERE source_id = $1 AND (created_at > $2::text::timestamptz OR (created_at = $3::text::timestamptz AND id > $4)) ORDER BY created_at ASC, id ASC LIMIT $5",- "textSha256": "48e52d1c6898cb66b520371fe6e65624ccfca9643f2e6e4dcf8f30186bbbdd0f"+ "sql": "SELECT *, gbrain_fact_fingerprint(fact) AS fact_fingerprint, to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS created_at_iso FROM facts WHERE source_id = $1 AND (created_at > $2::text::timestamptz OR (created_at = $3::text::timestamptz AND id > $4)) 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) ORDER BY created_at ASC, id ASC LIMIT $5",+ "textSha256": "496a582f02aed3d2fd5bfae3c1004d663b02a1af6274a3e7f98019705dfe37cf"}],"strictTime": [@@ -603,8 +603,8 @@"string","number"],- "sql": "SELECT *, to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS created_at_iso FROM facts WHERE source_id = $1 AND created_at > $2::text::timestamptz AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) AND facts.visibility IN ('world') ORDER BY created_at ASC, id ASC LIMIT $3",- "textSha256": "5224220754538ac8d17fd002c25dcd00c4ad3ad5634f77b111c0ffebd2ed7b31"+ "sql": "SELECT *, to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS created_at_iso FROM facts WHERE source_id = $1 AND created_at > $2::text::timestamptz AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) AND facts.visibility IN ('world') 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) ORDER BY created_at ASC, id ASC LIMIT $3",+ "textSha256": "6f676646f4e21a9fcff1282839ac9a86ba0b0056e83003bfc4394c0d05bc9674"}]},@@ -623,8 +623,8 @@"number","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND COALESCE(valid_from, created_at) >= $2 AND entity_slug = $3 AND source_session = $4 AND source != ALL($5::text[]) AND fact ILIKE $6 ESCAPE '\\' AND consolidated_at IS NULL AND kind = ANY($7::text[]) AND facts.visibility IN ('world') ORDER BY COALESCE(valid_from, created_at) DESC, id DESC LIMIT $8 OFFSET $9",- "textSha256": "08ec05ff5a0d3ab9d0e87cc53c862b889f562e2af8c6959238905f2e48a80cbe"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND COALESCE(valid_from, created_at) >= $2 AND entity_slug = $3 AND source_session = $4 AND source != ALL($5::text[]) AND fact ILIKE $6 ESCAPE '\\' AND consolidated_at IS NULL AND kind = ANY($7::text[]) AND facts.visibility IN ('world') 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) ORDER BY COALESCE(valid_from, created_at) DESC, id DESC LIMIT $8 OFFSET $9",+ "textSha256": "db68556ba4c2d5393c3b9b5846176aca8447dd5047e5ee6d43571d3ef74500a6"}],"default": [@@ -636,8 +636,8 @@"number","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND created_at >= $2 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) ORDER BY created_at DESC, id DESC LIMIT $3 OFFSET $4",- "textSha256": "b91c27c57a63ae4eeed4b01a43c5b9c43bc16d06e7960e87a68898d91577d0ac"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND created_at >= $2 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now()) 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) ORDER BY created_at DESC, id DESC LIMIT $3 OFFSET $4",+ "textSha256": "4470d6ad169dd3ef6e6f027e56ec8af4a50455d6442442a8828bc49c39a11749"}]},@@ -649,8 +649,8 @@"string","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND superseded_by IS NOT NULL ORDER BY COALESCE(expired_at, valid_until) DESC, id DESC LIMIT $2",- "textSha256": "c9884eab330821c3b6b9a84fd1ae17e215ce8911ba3945e954b6918172b22d9c"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND superseded_by IS NOT NULL 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) ORDER BY COALESCE(expired_at, valid_until) DESC, id DESC LIMIT $2",+ "textSha256": "e63dfda8b03f7257ea2f9228a75edd5825322630989d7c2da14128b7502ce074"}],"since+visibility": [@@ -661,8 +661,8 @@"Date","number"],- "sql": "SELECT * FROM facts WHERE source_id = $1 AND superseded_by IS NOT NULL AND COALESCE(expired_at, valid_until) >= $2 AND facts.visibility IN ('world') ORDER BY COALESCE(expired_at, valid_until) DESC, id DESC LIMIT $3",- "textSha256": "8b156f6248ef869384a1f72a2f97a3578dca517f9ad8da801f01252d26f43b9e"+ "sql": "SELECT * FROM facts WHERE source_id = $1 AND superseded_by IS NOT NULL AND COALESCE(expired_at, valid_until) >= $2 AND facts.visibility IN ('world') 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) ORDER BY COALESCE(expired_at, valid_until) DESC, id DESC LIMIT $3",+ "textSha256": "f44deac7f42061a9ee4c865f7fbda707420075f6d4d91b02b22ddd7b8a89e45a"}]},