Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Keep the private-labels preview counting concepts a cleared origin exposes
garrytane1a61592ccb3
diff --git a/src/core/repair/private-labels.ts b/src/core/repair/private-labels.tsindex d66ccae113..82e662ba8a 100644--- a/src/core/repair/private-labels.ts+++ b/src/core/repair/private-labels.ts@@ -258,7 +258,7 @@ export function dependentsSql(): string {CASE WHEN c.id IS NULL THEN pg.frontmatter ELSE pg.frontmatter - string_to_array(c.keys, ',') END AS frontmatterFROM pages pg LEFT JOIN cleared c ON c.id = pg.id)SELECT after_clear.id FROM (SELECT a.id, a.source_id, a.slug, a.type, a.frontmatter FROM (SELECT DISTINCT id FROM candidates) k- JOIN pages a ON a.id = k.id OFFSET 0) after_clear WHERE ${privacyPartSql('after_clear')})+ JOIN pages a ON a.id = k.id OFFSET 0) after_clear WHERE ${privacyPartSql('after_clear', true)})SELECT cand.id, cand.cleared_id, CASE WHEN p.type = 'event' AND p.frontmatter->>'captured_via' LIKE 'life-chronicle:%' THEN 'life_chronicle'WHEN p.type = 'atom' THEN 'atom' WHEN p.type = 'concept' AND p.frontmatter->>'synthesized_by' IS NOT NULL THEN 'concept' ELSE 'derived_from' END AS categoryFROM candidates cand JOIN pages p ON p.id = cand.iddiff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.tsindex 656150db09..9b9b66e2af 100644--- a/src/core/search/private-visibility.ts+++ b/src/core/search/private-visibility.ts@@ -81,10 +81,14 @@ export function privatePagesFilterFragment(pageAlias: string, derived = false):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. */-export function privacyPartSql(pageAlias: string): string {+/**+ * The privacy rules alone (visibility, aliases, pinned questions, lineage): what the escape hatches and granted_sources may relax.+ * `shadowedPages`: the statement shadows `pages` with a CTE (a postimage, repair/private-labels.ts), which a SQL+ * function body never reads, so the concept-input test runs inline over the shadow.+ */+export function privacyPartSql(pageAlias: string, shadowedPages = false): string {return `(${privateSnapshotFilterFragment(pageAlias)}- AND NOT ${derivedOriginPrivateSql(pageAlias)}+ AND NOT ${derivedOriginPrivateSql(pageAlias, shadowedPages)}AND NOT ${declaredLineagePrivateSql(pageAlias)})`;}@@ -697,15 +701,15 @@ export function privateSnapshotFilterFragment(alias: string): string {* move whose alias a later rename onto the old slug dropped (#8920). A concept's* inputs are judged the same way, moved origins included (GST-2687), by the SQL* function gbrain_concept_inputs_private (migration v311), one planned call per- * page instead of the subplans. Inside a remote request on a brain whose schema- * predates v311 the same test runs inline, as gbrain_access_origin_restricted is+ * page instead of the subplans. Over a shadowed `pages` (privacyPartSql), and+ * inside a remote request on a brain whose schema predates v311, the same test runs inline, as gbrain_access_origin_restricted is* skipped inside a request on a brain that never set access.restrictions_present.*/-function derivedOriginPrivateSql(p: string): string {+function derivedOriginPrivateSql(p: string, shadowedPages: boolean): string {const privateOrigin = (atom: string, alias: string) => `EXISTS (SELECT 1 FROM pages ${alias} WHERE ${alias}.source_id = ${atom}.source_idAND ${alias}.slug = ANY(${atomOriginSlugsSql(atom)}) AND ${alias}.frontmatter->>'visibility' = 'private')`;const schema = currentCallerAccess().remotePolicy?.schemaVersion;- const conceptInputsPrivate = schema === undefined || schema >= v311.version ? `gbrain_concept_inputs_private(${p}.id)`+ const conceptInputsPrivate = !shadowedPages && (schema === undefined || schema >= v311.version) ? `gbrain_concept_inputs_private(${p}.id)`: `EXISTS (SELECT 1 FROM links derived_input_linkJOIN pages derived_input ON derived_input.id = derived_input_link.to_page_idWHERE derived_input_link.from_page_id = ${p}.id AND derived_input_link.link_source = 'concept-provenance'diff --git a/test/helpers/private-labels-dependents-fixture.ts b/test/helpers/private-labels-dependents-fixture.tsindex 049071cb2c..1f3f6fb9eb 100644--- a/test/helpers/private-labels-dependents-fixture.ts+++ b/test/helpers/private-labels-dependents-fixture.ts@@ -37,7 +37,7 @@ export function preChangeDependentsSql(): string {WITH pages AS NOT MATERIALIZED (SELECT pg.id, pg.source_id, pg.slug, pg.type, pg.deleted_at,CASE WHEN c.id IS NULL THEN pg.frontmatter ELSE pg.frontmatter - string_to_array(c.keys, ',') END AS frontmatterFROM pages pg LEFT JOIN cleared c ON c.id = pg.id)- SELECT after_clear.id FROM pages after_clear WHERE after_clear.id IN (SELECT id FROM candidates) AND ${privacyPartSql('after_clear')})+ SELECT after_clear.id FROM pages after_clear WHERE after_clear.id IN (SELECT id FROM candidates) AND ${privacyPartSql('after_clear', true)})ORDER BY cand.id`;}