Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(repair): keep private labels on pages with declared lineage; fresh caller identity hides private by default (R51 B1)

garrytan96f988ce0b5a
diff --git a/src/core/repair/private-labels.ts b/src/core/repair/private-labels.ts
index 2fd3b594fb..f41573266f 100644
--- a/src/core/repair/private-labels.ts
+++ b/src/core/repair/private-labels.ts
@@ -5,7 +5,8 @@
*
* KEEP (counted, never changed)
* pinned_question pinned_question in frontmatter, or type question
- * derived an atom, a synthesized concept or a life-chronicle event;
+ * derived an atom, a page with derived_from or source_slug, a synthesized
+ * concept or a life-chronicle event;
* its privacy follows its origin (gbrain repair visibility owns it)
* strong_alias access restricted or confidential, or a private confidentiality value
* explicit_visibility visibility: private with no access: private (a deliberate writer or connector)
@@ -79,7 +80,7 @@ export function classifyPrivateLabel(row: Pick<LabelRow, 'type' | 'frontmatter'
const aliased = Object.entries(PRIVACY_ALIASES).some(([key, values]) => values.includes(value(key) ?? ''));
if (!(fm.visibility === 'private' || (fm.visibility == null && aliased))) return null;
if (Object.hasOwn(fm, 'pinned_question') || row.type === 'question') return { keep: 'pinned_question' };
- if (row.type === 'atom' || (row.type === 'concept' && fm.synthesized_by != null)
+ if (row.type === 'atom' || Object.hasOwn(fm, 'derived_from') || Object.hasOwn(fm, 'source_slug') || (row.type === 'concept' && fm.synthesized_by != null)
|| (row.type === 'event' && typeof fm.captured_via === 'string' && fm.captured_via.startsWith('life-chronicle:'))) return { keep: 'derived' };
const access = value('access');
if (access === 'restricted' || access === 'confidential' || PRIVACY_ALIASES.confidentiality!.includes(value('confidentiality') ?? '')) return { keep: 'strong_alias' };
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.ts
index 4343ba74dd..65ee019c4d 100644
--- a/src/core/search/private-visibility.ts
+++ b/src/core/search/private-visibility.ts
@@ -274,7 +274,7 @@ export function withCallerAccess<T>(access: Partial<CallerAccess>, fn: () => T):
satisfiedRuleIds: satisfied.length && satisfied.every(validQualifiedRuleId) ? Object.freeze([...new Set(satisfied)].sort()) : Object.freeze([]),
folderCoverage: Object.freeze([...(access.folderCoverage ?? base.folderCoverage)].map(c => Object.freeze({ source_id: c.source_id, prefix: c.prefix }))),
privateReadableSources: sources.length && sources.every(isValidSourceId) ? Object.freeze([...new Set(sources)]) : Object.freeze([]),
- hidePrivate: access.hidePrivate ?? base.hidePrivate,
+ hidePrivate: access.hidePrivate ?? (fresh ? true : base.hidePrivate),
owner: access.owner ?? (fresh ? false : base.owner),
applyRemoteReadPolicy: access.applyRemoteReadPolicy ?? base.applyRemoteReadPolicy,
restricted: access.restricted ?? base.restricted,
diff --git a/test/access-owner-reads.test.ts b/test/access-owner-reads.test.ts
index 103ec5c42e..1228fee4e7 100644
--- a/test/access-owner-reads.test.ts
+++ b/test/access-owner-reads.test.ts
@@ -21,7 +21,7 @@ import { sqlQueryForEngine } from '../src/core/sql-query.ts';
import { mintLegacyToken } from '../src/core/token-mint.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 { __resetPrivateVisibilityCacheForTests, currentCallerAccess, withCallerAccess } from '../src/core/search/private-visibility.ts';
import { clearOwner, ownerView, setOwner } from '../src/core/access/owner.ts';
import { bindCredential } from '../src/core/access/members.ts';
import { accessCheck } from '../src/commands/access.ts';
@@ -205,3 +205,10 @@ for (const kind of testBackends()) {
});
});
}
+
+test('a fresh identity nested under the owner hides private pages unless it says otherwise', () => {
+ const nested = withCallerAccess({ identity: ['member:owner-example'], hidePrivate: false, owner: true }, () =>
+ withCallerAccess({ identity: ['member:bob-example'] }, () => currentCallerAccess()));
+ expect(nested.owner).toBe(false);
+ expect(nested.hidePrivate).toBe(true);
+});
diff --git a/test/repair-private-labels.test.ts b/test/repair-private-labels.test.ts
index 5057e5bf60..d60e6fbc3b 100644
--- a/test/repair-private-labels.test.ts
+++ b/test/repair-private-labels.test.ts
@@ -27,6 +27,7 @@ import { runRepairCommand } from '../src/commands/repair.ts';
import { _resetCliExitVerdictForTests } from '../src/core/cli-force-exit.ts';
import { EXPLICIT_REPAIR_REGISTRY, PREVIEW_BOUND_REPAIR_REGISTRY, repairRunner, repairSpec } from '../src/core/repair/registry.ts';
import { resolveRepairScope } from '../src/core/repair/core.ts';
+import { classifyPrivateLabel } from '../src/core/repair/private-labels.ts';
import { withEnv } from './helpers/with-env.ts';
import { withCoordinatedWrite, withTrustBackfill } from '../src/core/persistence/context.ts';
import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';
@@ -315,3 +316,14 @@ describe('repair private-labels keeps the trust tier', () => {
}
});
});
+
+test('a page with declared lineage keeps its label whatever its type, so its origin decides who reads it', () => {
+ const lineage: Array<Record<string, unknown>> = [
+ { access: 'private', derived_from: 'notes/origin' },
+ { access: 'private', derived_from: ['notes/origin.md', 'notes/other'] },
+ { access: 'private', visibility: 'private', derived_from: 'notes/origin' },
+ { access: 'private', source_slug: 'notes/origin' },
+ ];
+ for (const frontmatter of lineage) expect(classifyPrivateLabel({ type: 'note', frontmatter, git: false })).toEqual({ keep: 'derived' });
+ expect(classifyPrivateLabel({ type: 'note', frontmatter: { access: 'private' }, git: false })).toEqual({ clear: 'alias', removed: { access: 'private' } });
+});