Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

sources: list shows unset federation distinctly from explicit isolated (#3940)

testa729ca8a8c68
diff --git a/src/commands/sources.ts b/src/commands/sources.ts
index 4d286b11e2..98185acaf0 100644
--- a/src/commands/sources.ts
+++ b/src/commands/sources.ts
@@ -57,6 +57,7 @@ import {
parseSourceConfig,
normalizeSourceConfig,
isSourceFederated,
+ sourceFederationState,
type SourceRow as LoadedSourceRow,
} from '../core/sources-load.ts';
@@ -470,8 +471,14 @@ async function runList(engine: BrainEngine, args: string[]): Promise<void> {
// Human-readable table.
console.log('SOURCES');
console.log('───────');
- for (const e of entries) {
- const fedMark = e.federated ? 'federated' : (e as any).archived ? '⚠ archived' : 'isolated';
+ for (let i = 0; i < entries.length; i++) {
+ const e = entries[i];
+ // Explicit `federated: false` (`sources unfederate`) fully isolates a
+ // source's reads in both directions; an absent key ('unset') only keeps
+ // it out of OTHER anchors' reads — its own unqualified reads still widen
+ // outward (see sourceFederationState). Collapsing both to "isolated"
+ // overstates what an unset flag does.
+ const fedMark = (e as any).archived ? '⚠ archived' : sourceFederationState(rows[i].config);
const pathStr = e.local_path ?? '(no local path)';
const sync = e.last_sync_at ? `last sync ${e.last_sync_at}` : 'never synced';
console.log(` ${e.id.padEnd(20)} ${fedMark.padEnd(12)} ${String(e.page_count).padStart(6)} pages ${sync}`);
diff --git a/src/core/sources-load.ts b/src/core/sources-load.ts
index a4bd924280..661756e097 100644
--- a/src/core/sources-load.ts
+++ b/src/core/sources-load.ts
@@ -160,6 +160,28 @@ export function isSourceFederated(config: unknown): boolean {
return parsed.federated === true;
}
+/**
+ * Three-way federation state for display (CLI `sources list`, etc.).
+ *
+ * `isSourceFederated` collapses to a boolean for the inclusion check (does
+ * this source show up in OTHER anchors' unqualified reads?), which is
+ * correctly strict — 'unset' behaves like 'isolated' there. But 'unset' and
+ * 'isolated' are NOT interchangeable for display: only an explicit
+ * `federated: false` (`sources unfederate` / `--no-federated`) opts a source
+ * out of cross-source read mixing in both directions. A source that has
+ * simply never set the flag still widens its OWN unqualified reads to
+ * include the federated set (the #1434 sole-source convenience, pinned
+ * behavior — see test/local-federated-search-scope.test.ts and
+ * test/unfederate-read-scope-2928.test.ts). Labeling it "isolated" overstates
+ * what the flag actually does.
+ */
+export function sourceFederationState(config: unknown): 'federated' | 'isolated' | 'unset' {
+ const raw = parseSourceConfig(config).federated;
+ if (raw === true) return 'federated';
+ if (raw === false) return 'isolated';
+ return 'unset';
+}
+
/**
* Enumerate every source. Order: 'default' first, then alphabetical by id.
*
diff --git a/test/sources.test.ts b/test/sources.test.ts
index 73a6bfff75..0a4ccf6f44 100644
--- a/test/sources.test.ts
+++ b/test/sources.test.ts
@@ -6,7 +6,7 @@
* shape, validation, and flag parsing.
*/
-import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
+import { describe, test, expect, beforeEach, afterEach, spyOn } from 'bun:test';
import { mkdtempSync, mkdirSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
@@ -230,6 +230,37 @@ describe('sources list', () => {
const count = calls.find(c => c.sql.includes('COUNT(*)::int AS n FROM pages'));
expect(count?.sql).toContain('deleted_at IS NULL');
});
+
+ test('distinguishes explicit false / absent key / explicit true in the human-readable label', async () => {
+ const { engine } = makeStub({
+ 'SELECT id, name, local_path, last_commit, last_sync_at, config, created_at': [
+ { id: 'wiki', name: 'wiki', local_path: '/tmp/wiki', last_commit: null, last_sync_at: null, config: '{"federated":true}', created_at: new Date() },
+ { id: 'yc-media', name: 'yc-media', local_path: '/tmp/yc', last_commit: null, last_sync_at: null, config: '{"federated":false}', created_at: new Date() },
+ { id: 'gstack', name: 'gstack', local_path: '/tmp/gstack', last_commit: null, last_sync_at: null, config: '{}', created_at: new Date() },
+ ],
+ 'COUNT(*)::int AS n FROM pages': [{ n: 0 }],
+ });
+ const lines: string[] = [];
+ const logSpy = spyOn(console, 'log').mockImplementation((...a: unknown[]) => { lines.push(a.map(String).join(' ')); });
+ try {
+ await runSources(engine, ['list']);
+ } finally {
+ logSpy.mockRestore();
+ }
+ const wikiLine = lines.find(l => l.includes('wiki'))!;
+ const ycLine = lines.find(l => l.includes('yc-media'))!;
+ const gstackLine = lines.find(l => l.includes('gstack'))!;
+ // Explicit `federated: true` — unchanged.
+ expect(wikiLine).toContain('federated');
+ // Explicit `federated: false` (`sources unfederate`) — fully isolated.
+ expect(ycLine).toContain('isolated');
+ // Absent key (bare `sources add`, config={}) is NOT the same as explicit
+ // false: it doesn't appear in others' federated reads, but its own
+ // unqualified reads still widen outward (#1434/#2561/#2928). The label
+ // must say something other than "isolated", which overstates it.
+ expect(gstackLine).not.toContain('isolated');
+ expect(gstackLine).toContain('unset');
+ });
});
// ── remove ──────────────────────────────────────────────────