Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: list slugs a slugs file cannot carry as unmatched in repair visibility --propose
garrytan9495f4db2d8a
diff --git a/src/commands/repair-propose.ts b/src/commands/repair-propose.tsindex f267981571..16a90a3c94 100644--- a/src/commands/repair-propose.ts+++ b/src/commands/repair-propose.ts@@ -37,7 +37,14 @@ export const PROPOSAL_FIELDS = ['participants', 'attendees', 'to', 'from', 'cc']export const PROPOSAL_DIR = 'visibility-proposals';export interface ProposedSet { source: string; readers: string[]; pages: number; file: string; command: string }-export interface UnmatchedPage { source: string; slug: string; addresses: string[] }+export interface UnmatchedPage {+ source: string;+ slug: string;+ /** The listed entries that name no enabled member's declared email. */+ addresses: string[];+ /** Why the page gets no proposal when its addresses are not the reason (a slug a slugs file cannot carry). */+ reason?: string;+}export interface ProposedFolder { source: string; folder: string; pages: number; command: string }export interface VisibilityProposal {/** False on a one-person brain or one pinned to access.serves one: nothing was read or written. */@@ -56,6 +63,7 @@ export interface VisibilityProposal {}const LINEAGE_COST = 'Labelling a page also hides its derived atoms, facts and chronicle events from every remote caller except the owner, unless access.members_read_lineage is on (gbrain access members-read-lineage on lets the members a page lists read them too).';+const UNCARRIED_SLUG = 'the slug starts with # or has surrounding spaces or a line break, so a slugs file cannot carry it; label it with --slug';const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`;/** The address entries a frontmatter value lists: a list or one string (comma or semicolon separated), each "Name <a@b>" read as a@b. */@@ -119,6 +127,7 @@ export async function proposeVisibility(engine: BrainEngine, opts: { source?: stconst groups = new Map<string, { source: string; readers: string[]; slugs: string[] }>();const unmatched: UnmatchedPage[] = [];const folders = new Map<string, ProposedFolder>();+ let considered = 0;const ownerFirst = owner ? `${owner},` : '';for (const row of rows) {const listed = PROPOSAL_FIELDS.flatMap(f => entries(row.fields?.[f]));@@ -134,6 +143,11 @@ export async function proposeVisibility(engine: BrainEngine, opts: { source?: stf.pages++;continue;}+ considered++;+ if (row.slug.trim() !== row.slug || row.slug.startsWith('#') || /[\r\n]/.test(row.slug)) {+ unmatched.push({ source: row.source, slug: row.slug, addresses: [], reason: UNCARRIED_SLUG });+ continue;+ }const members = new Set<string>();const missing: string[] = [];for (const entry of listed) {@@ -167,7 +181,7 @@ export async function proposeVisibility(engine: BrainEngine, opts: { source?: stconst chats = sorted.reduce((n, f) => n + f.pages, 0);return { applicable: true, owner, ...(view.inactive ? { owner_inactive: view.inactive.value } : {}), dir: sets.length ? dir : null, sets, unmatched, folders: sorted,members_read_lineage: lineage, cost: LINEAGE_COST,- message: `${plural(proposed, 'open page')} in ${plural(sets.length, 'reader set')}, ${unmatched.length} unmatched, ${plural(chats, 'DM, chat or mail page')} with no address list.` };+ message: `${proposed} of ${plural(considered, 'open page')} with an address list in ${plural(sets.length, 'reader set')}, ${unmatched.length} unmatched; ${plural(chats, 'DM, chat or mail page')} with no address list.` };}/** The human preview: the sets and their commands, the unmatched pages, the folders and what labelling costs. */@@ -179,8 +193,8 @@ export function proposalLines(p: VisibilityProposal, limit = 20): string[] {if (p.sets.length) lines.push('', `Reader sets (slugs files in ${p.dir}). Preview each, then run the --apply --expect <hash> it prints:`);for (const s of p.sets) lines.push(` ${s.source}: ${plural(s.pages, 'page')} -> ${s.readers.join(', ')}`, ` ${s.command}`);if (p.unmatched.length) {- lines.push('', `Unmatched (${p.unmatched.length}): an address names no enabled member's declared email, so nothing is proposed. Declare it on the right member (gbrain access member set <id> --email <address>) and preview again, or label these by hand:`);- for (const u of p.unmatched.slice(0, limit)) lines.push(` ${u.source}:${u.slug} (${u.addresses.join(', ')})`);+ lines.push('', `Unmatched (${p.unmatched.length}): nothing is proposed for these. Where an address names no enabled member's declared email, declare it on the right member (gbrain access member set <id> --email <address>) and preview again; otherwise label these by hand:`);+ for (const u of p.unmatched.slice(0, limit)) lines.push(u.reason ? ` ${u.source}:${JSON.stringify(u.slug)} (${u.reason})` : ` ${u.source}:${u.slug} (${u.addresses.join(', ')})`);if (p.unmatched.length > limit) lines.push(` ... and ${p.unmatched.length - limit} more (--json lists every one)`);}if (p.folders.length) {diff --git a/test/repair-visibility-propose-gst2670.test.ts b/test/repair-visibility-propose-gst2670.test.tsindex 7bc387160c..7d54ea0bd9 100644--- a/test/repair-visibility-propose-gst2670.test.ts+++ b/test/repair-visibility-propose-gst2670.test.ts@@ -255,5 +255,24 @@ for (const kind of testBackends()) {expect(readFileSync(target, 'utf8')).toBe(before);expect(readdirSync(out).filter(n => n.endsWith('.tmp'))).toEqual([]);}, 60_000);++ test('a slug a slugs file cannot carry (leading #, surrounding spaces, a line break) is unmatched with its reason, and the counts add up', async () => {+ const SRC_B = 'source-b';+ await engine.executeRaw("INSERT INTO sources (id, name) VALUES ($1, $1) ON CONFLICT (id) DO NOTHING", [SRC_B]);+ const odd = ['#meetings/h', ' meetings/x', 'meetings/a' + String.fromCharCode(10) + 'b'];+ for (const slug of ['meetings/x', ...odd]) {+ await engine.executeRaw("INSERT INTO pages (source_id, slug, title, type, frontmatter, compiled_truth) VALUES ($1, $2, 't', 'meeting', jsonb_build_object('attendees', jsonb_build_array($3::text)), '')",+ [SRC_B, slug, '[email protected]']);+ }+ const p = await propose(['--source', SRC_B]);+ expect(p.sets.map(s => [s.readers.join(','), readFileSync(s.file, 'utf8')])).toEqual([['owner-example,bob-example', 'meetings/x\n']]);+ expect(p.unmatched.map(u => u.slug).sort()).toEqual([...odd].sort());+ for (const u of p.unmatched) { expect(u.addresses).toEqual([]); expect(u.reason).toContain('label it with --slug'); }+ const [, proposed, considered, unmatched] = p.message.match(/^(\d+) of (\d+) open pages? with an address list in .*?, (\d+) unmatched;/)!.map(Number);+ expect([proposed, considered, unmatched]).toEqual([1, 4, 3]);+ expect(proposed! + unmatched!).toBe(considered!);+ const text = await repair(['visibility', '--propose', '--source', SRC_B]);+ expect(text).toContain(`source-b:${JSON.stringify('meetings/a' + String.fromCharCode(10) + 'b')} (the slug starts with #`);+ }, 60_000);});}