Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep a category keyed 'canon' distinct from the canon entry kind in the picker's type filter (review round 1)
[._.]/ Adam Eivyf5a81a667ea9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex dc5a8539a4..82598a7aec 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -72,4 +72,4 @@- **`completeAgent` had three addresses, and the four callers that most needed one address were using the wrong one.** Continuing #3450's sequencing: `agentManagement.js`, `agentLifecycle.js`, `agentFinalization.js` and `agentCliSpawning.js` all reached the completion transition through the `cosAgents.js` barrel. These four are the callers the "move the caller above the facade" recipe cannot reach — the first two DEFINE transitions `agentOrchestrator.js` re-exports, so importing the facade from either is the cycle itself, and the other two are leaves those two must call to spawn and to finalize. So the rule they follow is the other half of the same property: above the facade's closure a transition comes from the facade, inside it from the module that DECLARES it (`cosAgentLifecycle.js`), and never from a barrel. `cleanupOrphanedAgents`'s `await import('./cos.js')` went with it — it was pulling `completeAgent` and `getAgents` through the `cos.js` re-export block while the module was already a static import three lines up, so the deferral bought no cycle protection at all. The new guard in `agentImportCycles.test.js` derives the transition names from the facade's export blocks and walks re-export edges to work out which modules forward them, so a barrel added later is covered without being named; it catches a named import, a renamed one, a namespace property read, a destructure off a namespace handle, and the three deferred spellings of the same reaches — including `const { completeAgent } = await import('./cos.js')`, the exact pattern this change deleted. Each bypass-probed.-- **The "Pick from Gallery" picker could only be narrowed by typing, so finding one object in one universe meant recalling a word from its prompt.** It now carries two dropdowns beside the search box: a scope select that groups every universe and media collection under `<optgroup>`s, and a type select built from the `entryCategory`/`entryKind` tags the Universe Builder stamps onto sidecars, labelled through the same `humanizeCategory` the Builder uses. All three filters AND-combine, and both dropdowns list only universes/collections/types that actually match an image currently in the picker — a scope that can only ever produce an empty grid isn't offered, and a selection that stops matching resets itself to "All" rather than silently blanking the grid. Collection membership is matched on the stored `{ kind, ref }` pair (the same `<kind>:<ref>` string `normalizeImage` puts on `item.key`), not on a bare filename, so a collection holding video refs alongside images filters correctly. Both option fetches are best-effort: if the collections or universes call fails the picker keeps working, falling back to the universe name stamped on each sidecar (#3479).+- **The "Pick from Gallery" picker could only be narrowed by typing, so finding one object in one universe meant recalling a word from its prompt.** It now carries two dropdowns beside the search box: a scope select that groups every universe and media collection under `<optgroup>`s, and a type select built from the `entryCategory`/`entryKind` tags the Universe Builder stamps onto sidecars, labelled through the same `humanizeCategory` the Builder uses. Those two are separate vocabularies — a user-authored bucket can legitimately be keyed `canon` — so the type options are prefixed by which field they filter and grouped under Categories/Entry kinds rather than flattened into one list where the bucket and the stage would silently match each other. All three filters AND-combine, and both dropdowns list only universes/collections/types that actually match an image currently in the picker — a scope that can only ever produce an empty grid isn't offered, and a selection that stops matching resets itself to "All" rather than silently blanking the grid. Collection membership is matched on the stored `{ kind, ref }` pair (the same `<kind>:<ref>` string `normalizeImage` puts on `item.key`), not on a bare filename, so a collection holding video refs alongside images filters correctly. Both option fetches are best-effort: if the collections or universes call fails the picker keeps working, falling back to the universe name stamped on each sidecar (#3479).diff --git a/client/src/components/imageGen/GalleryImagePicker.jsx b/client/src/components/imageGen/GalleryImagePicker.jsxindex 638535b03c..09a29b161b 100644--- a/client/src/components/imageGen/GalleryImagePicker.jsx+++ b/client/src/components/imageGen/GalleryImagePicker.jsx@@ -33,6 +33,13 @@ import toast from '../ui/Toast';// Scope-select values are prefixed so one <select> can carry both option kinds.const UNI_PREFIX = 'uni:';const COL_PREFIX = 'col:';+// The type select spans two independent vocabularies — `entryCategory` is a+// user-authored bucket key, `entryKind` is the fixed canon/variation/sheet+// stage. They can collide (a category literally keyed `canon`), so options are+// prefixed by which field they filter and grouped so the two "Canon" rows are+// still distinguishable in the list.+const CAT_PREFIX = 'cat:';+const KIND_PREFIX = 'kind:';// A collection stores membership as `{ kind, ref }` (server/lib/mediaItemKey.js),// which serializes to the same `<kind>:<ref>` string `normalizeImage` puts on// `item.key` — so membership is a set lookup, not a filename comparison.@@ -117,13 +124,17 @@ export default function GalleryImagePicker({ open, onClose, onSelect, allowUploa.map((c) => ({ value: `${COL_PREFIX}${c.id}`, label: c.name || c.id })).sort(byLabel), [collections, galleryKeys]);- const typeOptions = useMemo(() => {- const seen = new Set();+ const [categoryOptions, kindOptions] = useMemo(() => {+ const categories = new Set();+ const kinds = new Set();for (const it of items) {- if (it.entryCategory) seen.add(it.entryCategory);- if (it.entryKind) seen.add(it.entryKind);+ if (it.entryCategory) categories.add(it.entryCategory);+ if (it.entryKind) kinds.add(it.entryKind);}- return [...seen].map((value) => ({ value, label: humanizeCategory(value) })).sort(byLabel);+ const toOptions = (values, prefix) => [...values]+ .map((value) => ({ value: `${prefix}${value}`, label: humanizeCategory(value) }))+ .sort(byLabel);+ return [toOptions(categories, CAT_PREFIX), toOptions(kinds, KIND_PREFIX)];}, [items]);// Membership set for the selected collection — `null` whenever no collection@@ -140,17 +151,20 @@ export default function GalleryImagePicker({ open, onClose, onSelect, allowUploaif (scope && ![...universeOptions, ...collectionOptions].some((o) => o.value === scope)) setScope('');}, [scope, universeOptions, collectionOptions]);useEffect(() => {- if (type && !typeOptions.some((o) => o.value === type)) setType('');- }, [type, typeOptions]);+ if (type && ![...categoryOptions, ...kindOptions].some((o) => o.value === type)) setType('');+ }, [type, categoryOptions, kindOptions]);const filtered = useMemo(() => {const universeId = scope.startsWith(UNI_PREFIX) ? scope.slice(UNI_PREFIX.length) : null;- if (tokens.length === 0 && !universeId && !scopedCollectionKeys && !type) return items;+ const category = type.startsWith(CAT_PREFIX) ? type.slice(CAT_PREFIX.length) : null;+ const kind = type.startsWith(KIND_PREFIX) ? type.slice(KIND_PREFIX.length) : null;+ if (tokens.length === 0 && !universeId && !scopedCollectionKeys && !category && !kind) return items;return items.filter((item, idx) => {if (tokens.length > 0 && !matchHaystack(haystacks[idx], tokens)) return false;if (universeId && item.universeId !== universeId) return false;if (scopedCollectionKeys && !scopedCollectionKeys.has(item.key)) return false;- if (type && item.entryCategory !== type && item.entryKind !== type) return false;+ if (category && item.entryCategory !== category) return false;+ if (kind && item.entryKind !== kind) return false;return true;});}, [items, haystacks, tokens, scope, scopedCollectionKeys, type]);@@ -263,7 +277,7 @@ export default function GalleryImagePicker({ open, onClose, onSelect, allowUploa</select></div>)}- {typeOptions.length > 0 && (+ {(categoryOptions.length > 0 || kindOptions.length > 0) && (<div className="sm:w-36"><label htmlFor="gallery-picker-type" className="sr-only">Filter by type</label><select@@ -273,7 +287,16 @@ export default function GalleryImagePicker({ open, onClose, onSelect, allowUploaclassName="w-full bg-port-bg border border-port-border rounded-lg px-2 py-1.5 text-xs text-white focus:outline-none focus:border-port-accent"><option value="">All types</option>- {typeOptions.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}+ {categoryOptions.length > 0 && (+ <optgroup label="Categories">+ {categoryOptions.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}+ </optgroup>+ )}+ {kindOptions.length > 0 && (+ <optgroup label="Entry kinds">+ {kindOptions.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}+ </optgroup>+ )}</select></div>)}diff --git a/client/src/components/imageGen/GalleryImagePicker.test.jsx b/client/src/components/imageGen/GalleryImagePicker.test.jsxindex db73e2ef73..2c03c3112c 100644--- a/client/src/components/imageGen/GalleryImagePicker.test.jsx+++ b/client/src/components/imageGen/GalleryImagePicker.test.jsx@@ -157,16 +157,34 @@ describe('GalleryImagePicker', () => {expect(screen.getByRole('option', { name: 'Vehicles' })).toBeTruthy();expect(screen.getByRole('option', { name: 'Canon' })).toBeTruthy();- fireEvent.change(typeSelect(), { target: { value: 'vehicles' } });+ fireEvent.change(typeSelect(), { target: { value: 'cat:vehicles' } });await waitFor(() => expect(screen.queryByAltText('a neon sunset')).toBeNull());expect(screen.getByAltText('a chrome mecha')).toBeTruthy();// entryKind is matched by the same select — 'variation' only tags forest.- fireEvent.change(typeSelect(), { target: { value: 'variation' } });+ fireEvent.change(typeSelect(), { target: { value: 'kind:variation' } });await waitFor(() => expect(screen.queryByAltText('a chrome mecha')).toBeNull());expect(screen.getByAltText('a quiet forest')).toBeTruthy();});+ it('keeps a category keyed like an entry kind distinct from that kind', async () => {+ listImageGallery.mockResolvedValue([+ // A user-authored bucket that happens to be keyed 'canon', on a variation.+ { filename: 'a.png', path: '/data/images/a.png', prompt: 'category canon', entryCategory: 'canon', entryKind: 'variation' },+ { filename: 'b.png', path: '/data/images/b.png', prompt: 'kind canon', entryCategory: 'places', entryKind: 'canon' },+ ]);+ render(<GalleryImagePicker open onClose={vi.fn()} onSelect={vi.fn()} />);+ await screen.findByAltText('category canon');++ fireEvent.change(typeSelect(), { target: { value: 'cat:canon' } });+ await waitFor(() => expect(screen.queryByAltText('kind canon')).toBeNull());+ expect(screen.getByAltText('category canon')).toBeTruthy();++ fireEvent.change(typeSelect(), { target: { value: 'kind:canon' } });+ await waitFor(() => expect(screen.queryByAltText('category canon')).toBeNull());+ expect(screen.getByAltText('kind canon')).toBeTruthy();+ });+it('AND-combines the filters with the text query', async () => {render(<GalleryImagePicker open onClose={vi.fn()} onSelect={vi.fn()} />);await screen.findByAltText('a neon sunset');@@ -190,7 +208,7 @@ describe('GalleryImagePicker', () => {await waitFor(() => expect(screen.getByRole('option', { name: 'Mood Board' })).toBeTruthy());fireEvent.change(scopeSelect(), { target: { value: 'col:col-1' } });- fireEvent.change(typeSelect(), { target: { value: 'variation' } });+ fireEvent.change(typeSelect(), { target: { value: 'kind:variation' } });await waitFor(() => expect(screen.queryByAltText('a neon sunset')).toBeNull());fireEvent.change(scopeSelect(), { target: { value: '' } });