Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Local reflex pointers and briefs keep the plain privacy rule; only the remote pull brief reads with the caller's policy

garrytan565aef85b5c4
diff --git a/src/core/context/pack-brief.ts b/src/core/context/pack-brief.ts
index a152665f9f..6a2b68975b 100644
--- a/src/core/context/pack-brief.ts
+++ b/src/core/context/pack-brief.ts
@@ -35,7 +35,7 @@ export async function contextPackBrief(
...(local ? {} : { withheld_arms: ['loops'] }),
};
const cp = await resolvePullCounterparty(ctx.engine, opts.sourceId, p.counterparty.slice(0, 200), {
- excludePrivate: !opts.includePrivate, eligibility: opts.eligibility,
+ excludePrivate: !opts.includePrivate, forCaller: !local, eligibility: opts.eligibility,
});
if (!cp) return { text: '', view: { ...label, counterparty: null, items: [], reason: 'counterparty_unresolved' } };
const now = Date.now();
diff --git a/src/core/context/proactive-brief.ts b/src/core/context/proactive-brief.ts
index fc4e5e5e02..8740522e4d 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 { privatePagesFilterForCaller, privatePagesFilterFragment, privateProvenanceFilterFragment, privateTimelineEventFilterForCaller } from '../search/private-visibility.ts';
+import { privatePagesFilterForCaller, privatePagesFilterFragment, privateProvenanceFilterFragment, privateTimelineEventFilterForCaller, 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';
@@ -165,7 +165,7 @@ export async function resolveBriefCounterparties(
engine: BrainEngine,
sourceId: string,
text: string,
- opts: { excludePrivate: boolean; eligibility?: ReadEligibility },
+ opts: { excludePrivate: boolean; forCaller?: boolean; eligibility?: ReadEligibility },
): Promise<BriefCounterparty[]> {
const candidates = extractCandidatesFromWindow([{ role: 'user', text }])
.filter((c) => !c.weak && !isCommonWordSurface(c.query));
@@ -174,6 +174,7 @@ export async function resolveBriefCounterparties(
suppression: 'slug-only',
maxPointers: candidates.length,
excludePrivate: opts.excludePrivate,
+ forCaller: opts.forCaller,
eligibility: opts.eligibility,
});
const order = new Map(candidates.map((c, i) => [normalizeAlias(c.query), i]));
@@ -196,13 +197,13 @@ async function entityPages(
engine: BrainEngine,
sourceId: string,
slugs: string[],
- opts: { excludePrivate: boolean; eligibility?: ReadEligibility },
+ opts: { excludePrivate: boolean; forCaller?: boolean; eligibility?: ReadEligibility },
): Promise<Map<string, string>> {
if (!slugs.length) return new Map();
const rows = await engine.executeRaw<{ slug: string; title: string | null; type: string | null }>(
`SELECT p.slug, p.title, p.type FROM pages p
WHERE p.source_id = $1 AND p.slug = ANY($2::text[]) AND p.deleted_at IS NULL
- ${opts.excludePrivate ? `AND ${privatePagesFilterForCaller('p')}` : ''}
+ ${opts.excludePrivate ? `AND ${opts.forCaller ? privatePagesFilterForCaller('p') : privatePagesFilterFragment('p')}` : ''}
AND ${pageEligibleSql('p', opts.eligibility)}`,
[sourceId, slugs],
);
@@ -219,7 +220,7 @@ export async function resolvePullCounterparty(
engine: BrainEngine,
sourceId: string,
name: string,
- opts: { excludePrivate: boolean; eligibility?: ReadEligibility },
+ opts: { excludePrivate: boolean; forCaller?: boolean; eligibility?: ReadEligibility },
): Promise<BriefCounterparty | null> {
const raw = name.trim().replace(/\.md$/i, '');
if (!raw) return null;
@@ -367,7 +368,7 @@ export async function meetingCounterparties(
// ── Item arms ─────────────────────────────────────────────────────────────
-interface ArmOpts { includePrivate: boolean; eligibility?: ReadEligibility }
+interface ArmOpts { includePrivate: boolean; forCaller: boolean; eligibility?: ReadEligibility }
const ymd = (v: string | Date | null | undefined): string | null => {
if (!v) return null;
@@ -483,7 +484,7 @@ async function editItem(engine: BrainEngine, cp: BriefCounterparty, clock: Brief
p.timeline, p.trust_tier, p.write_origin
FROM pages p
WHERE p.source_id = $1 AND p.slug = $2 AND p.deleted_at IS NULL
- AND ${opts.includePrivate ? 'TRUE' : privatePagesFilterForCaller('p')}
+ AND ${opts.includePrivate ? 'TRUE' : opts.forCaller ? privatePagesFilterForCaller('p') : privatePagesFilterFragment('p')}
AND ${pageEligibleSql('p', opts.eligibility)}`,
[cp.source_id, cp.slug, EDIT_MAX_PAGE_BYTES],
);
@@ -493,7 +494,7 @@ async function editItem(engine: BrainEngine, cp: BriefCounterparty, clock: Brief
engine.executeRaw<{ id: number; date: string; summary: string; detail: string; created_at: string | Date }>(
`SELECT te.id, te.date::text AS date, te.summary, te.detail, te.created_at FROM timeline_entries te
WHERE te.page_id = $1 AND te.created_at >= $2::timestamptz AND te.date >= $2::timestamptz::date
- AND ${opts.includePrivate ? 'TRUE' : privateTimelineEventFilterForCaller('te')}
+ AND ${opts.includePrivate ? 'TRUE' : opts.forCaller ? privateTimelineEventFilterForCaller('te') : privateTimelineEventFilterFragment('te')}
AND ${projectionEligibleSql('timeline_entries', 'te', opts.eligibility)}
ORDER BY te.created_at DESC, te.date DESC, te.id DESC LIMIT 1`,
[pg.id, since],
@@ -605,7 +606,7 @@ export interface AssembleBriefOpts {
* Stops issuing queries once the clock passes. Null when nothing survives.
*/
export async function assembleBrief(engine: BrainEngine, opts: AssembleBriefOpts): Promise<Brief | null> {
- const arm: ArmOpts = { includePrivate: opts.local && opts.includePrivate === true, eligibility: opts.eligibility };
+ const arm: ArmOpts = { includePrivate: opts.local && opts.includePrivate === true, forCaller: !opts.local, eligibility: opts.eligibility };
const seen = (id: string) => opts.suppressIds?.has(id) === true || (opts.priorContextText?.includes(`[${id}]`) ?? false);
const items: BriefItem[] = [];
for (const cp of opts.counterparties) {
diff --git a/src/core/context/retrieval-reflex.ts b/src/core/context/retrieval-reflex.ts
index 815a6fbe21..45c024533f 100644
--- a/src/core/context/retrieval-reflex.ts
+++ b/src/core/context/retrieval-reflex.ts
@@ -39,7 +39,7 @@ import { slugify } from '../entities/resolve.ts';
import { stripTakesFence } from '../takes-fence.ts';
import { stripFactsFence } from '../facts-fence.ts';
import { redactFindings } from '../secret-scan.ts';
-import { privatePagesFilterForCaller } from '../search/private-visibility.ts';
+import { privatePagesFilterForCaller, privatePagesFilterFragment } from '../search/private-visibility.ts';
import type { EntityCandidate } from './entity-salience.ts';
import { reflexPointerRationale } from './reflex-rationale.ts';
import { preferEntityTitleMatches } from './title-matches.ts';
@@ -200,6 +200,8 @@ export interface ResolvePointersOpts {
* via resolveExcludePrivatePages) passes false.
*/
excludePrivate?: boolean;
+ /** A remote read: `excludePrivate` applies the caller's policy instead of the plain privacy fragment. */
+ forCaller?: boolean;
/**
* #5575 (CEO-20, ENG-8): the proactive eligibility the enclosing surface
* resolved (read floor plus activation control). Absent: the resolver
@@ -237,7 +239,7 @@ export async function resolveEntitiesToPointers(
// v0.46.15: weak-alias + surname arms share one kill switch (default ON).
const lexicalArms = opts.lexicalArms !== false;
- const privacySql = opts.excludePrivate === false ? '' : `AND ${privatePagesFilterForCaller('p')}`;
+ const privacySql = opts.excludePrivate === false ? '' : `AND ${opts.forCaller ? privatePagesFilterForCaller('p') : privatePagesFilterFragment('p')}`;
// display lookup keyed by normalized query, so resolved slugs can recover a
// human surface form for the pointer label.
diff --git a/test/caller-aux-page-reads.test.ts b/test/caller-aux-page-reads.test.ts
index b9713303d6..ebd1d841bf 100644
--- a/test/caller-aux-page-reads.test.ts
+++ b/test/caller-aux-page-reads.test.ts
@@ -105,12 +105,25 @@ describe('#8395 auxiliary page reads follow the caller', () => {
test('retrieval pointers, pull counterparties and brief edits', async () => {
for (const who of ['alice', 'bob'] as const) {
await as(who, true, async () => {
- const block = await resolveEntitiesToPointers(engine, SRC, [{ query: 'Alice Example', display: 'Alice Example' }] as never, { excludePrivate: true });
+ const block = await resolveEntitiesToPointers(engine, SRC, [{ query: 'Alice Example', display: 'Alice Example' }] as never, { excludePrivate: true, forCaller: true });
expect(block?.pointers.some(p => p.slug === ALICE) ?? false).toBe(who === 'alice');
- expect((await resolvePullCounterparty(engine, SRC, ALICE, { excludePrivate: true }))?.slug ?? null).toBe(who === 'alice' ? ALICE : null);
+ expect((await resolvePullCounterparty(engine, SRC, ALICE, { excludePrivate: true, forCaller: true }))?.slug ?? null).toBe(who === 'alice' ? ALICE : null);
const brief = await assembleBrief(engine, { trigger: 'pull', local: false, counterparties: [{ slug: ALICE, source_id: SRC, display: 'Alice Example', confidence: 1 }], clock: { now: Date.now(), stopAt: Date.now() + 30_000 } });
expect(brief?.text.includes('Timeline note for Alice Example') ?? false).toBe(who === 'alice');
});
}
}, 30_000);
+
+ test('local retrieval pointers, pull counterparties and briefs keep the plain privacy fragment, even with the read hatch open', async () => {
+ await withEnv({ GBRAIN_REMOTE_PRIVATE_PAGES: '1' }, async () => {
+ __resetPrivateVisibilityCacheForTests();
+ const block = await resolveEntitiesToPointers(engine, SRC, [{ query: 'Carol Example', display: 'Carol Example' }] as never, { excludePrivate: true });
+ expect(block?.pointers.some(p => p.slug === SECRET) ?? false).toBe(false);
+ expect((await resolvePullCounterparty(engine, SRC, SECRET, { excludePrivate: true }))?.slug ?? null).toBe(null);
+ const brief = await assembleBrief(engine, { trigger: 'pull', local: true, counterparties: [{ slug: SECRET, source_id: SRC, display: 'Carol Example', confidence: 1 }], clock: { now: Date.now(), stopAt: Date.now() + 30_000 } });
+ expect(brief?.text.includes('Timeline note for Carol Example') ?? false).toBe(false);
+ expect((await resolvePullCounterparty(engine, SRC, SECRET, { excludePrivate: true, forCaller: true }))?.slug ?? null).toBe(SECRET);
+ });
+ __resetPrivateVisibilityCacheForTests();
+ }, 30_000);
});