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
simplify([extract-useuniverseaction-hook]): trim hook header + test cleanup
[._.]/ Adam Eivyc52a4c5f1400
diff --git a/PLAN.md b/PLAN.mdindex 410c861ef7..b258202ffd 100644--- a/PLAN.md+++ b/PLAN.md@@ -86,6 +86,7 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]### Code quality / dedup (from `/simplify` passes)+- [ ] [extract-upsertbyidprepend-helper-universe-builder] **Extract `upsertByIdPrepend(list, item)` helper.** The "filter out by id then prepend" upsert pattern is duplicated in three places: `client/src/pages/UniverseBuilder.jsx#handleMoveCategoryToTrunk` (~line 1393), `client/src/pages/UniverseBuilder.jsx#handleGenerateInCategory` (~line 1479), and `client/src/hooks/useUniverseAction.js` (~line 72). A two-line helper in `client/src/lib/` would dedupe all three. Surfaced by `/simplify` during the `useUniverseAction` extraction; deferred so that PR stays focused on the hook itself.- [ ] [tabpills-pipelineissue-status-dot-trailing-slot] **Extend `<TabPills>` with a `trailing` slot to migrate `PipelineIssue.jsx`.** That page's tab row renders a per-tab status dot (`<span className="w-1.5 h-1.5 rounded-full ${STATUS_DOT[status]}" />`) after the label (see `client/src/pages/PipelineIssue.jsx:298-319`). Add an optional `t.trailing` ReactNode to the tab shape (rendered after the count), then migrate the call site. Defer until the next time a tab-bar variant lands so the API surface grows in response to a concrete second user, not in anticipation.- [ ] [more-resolveproviderandmodel-migration-candidates] **More `resolveProviderAndModel` migration candidates.** When the helper landed in `server/lib/promptRunner.js` (universe-builder PR), three additional pure two-step provider-resolution chains were left alone to keep scope tight: `server/services/agentContentGenerator.js#runAIGeneration` (line ~80–90), `server/services/agentPersonalityGenerator.js` (line ~68–79), `server/services/loops.js` (line ~64–77). All three are textbook fits (no `enabled` gate, no typed-error throw mid-chain). Migration is one-import + 5-line collapse per file.- [ ] [extract-assertprovider-provider-errormessage-code] **Extract `assertProvider(provider, { errorMessage, code, status })` helper.** After the `resolveProviderAndModel` migration there are now 4 `if (!provider) throw …` sites with varying error shapes (`Error` vs `ServerError`, `status: 400/503`, codes `NO_PROVIDER`/`UNIVERSE_PROMOTE_NO_PROVIDER`/etc.). One helper that takes the error-shape args would consolidate without forcing each caller to share the same error type.diff --git a/client/src/hooks/useUniverseAction.js b/client/src/hooks/useUniverseAction.jsindex 68badb809d..6c1fce47da 100644--- a/client/src/hooks/useUniverseAction.js+++ b/client/src/hooks/useUniverseAction.js@@ -3,32 +3,17 @@ import toast from '../components/ui/Toast';// Scaffolding for LLM-driven universe mutations that follow the// "guarded API call → setWorlds → stale-write-checked setDraft" pattern.-//// Used by handlePromoteVariation + handleAutoSort in UniverseBuilder.jsx.-// Both: (1) require the universe to be saved, (2) need a page-level-// re-entrancy guard, (3) show a loading toast that flips to success/error,-// (4) always update the cached worlds list when the server returns a new-// universe (even across navigation), and (5) only mutate the local draft-// when the user is still on the same universe (stale-write guard).//// handleGenerateInCategory is intentionally NOT a consumer — it does an// eager local merge first and then a best-effort save, so the guard /-// loading-toast / required-savedId shape doesn't fit. Extracting just its-// setWorlds line through this hook would be more abstraction than savings.-//-// Contract for `action`:-// - Receives `capturedId` (the selectedId at call time).-// - Pass `{ silent: true }` to the underlying API helper so toasts only-// fire from this hook (per CLAUDE.md "Custom catch ⇒ silent: true").-// - Resolve with `{ universe, ... }`; reject with an Error whose message-// is user-displayable.+// loading-toast / required-savedId shape doesn't fit. Forcing it through+// would warp it for almost no shared scaffolding.//-// Contract for `onFreshResult`:-// - Called only when the user is still on the same universe at result time.-// - Caller does its own selective `setDraft` here (different actions touch-// different fields — promote rewrites canon arrays + one category, autoSort-// rewrites only reclassified buckets).-// - Return a string to use as the success toast, or null/void to suppress it.+// `action(capturedId)` must pass `{ silent: true }` to its API helper so+// toasts only fire from this hook (per CLAUDE.md "Custom catch ⇒ silent").+// `onFreshResult(result, { capturedId })` runs only when the user is still+// on the same universe; return a string to use as the success toast.export default function useUniverseAction({ selectedId, mountedRef, setWorlds }) {return useCallback(async function runUniverseAction({ref,diff --git a/client/src/hooks/useUniverseAction.test.jsx b/client/src/hooks/useUniverseAction.test.jsxindex e86f7b58c6..3f9d953585 100644--- a/client/src/hooks/useUniverseAction.test.jsx+++ b/client/src/hooks/useUniverseAction.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { renderHook, act } from '@testing-library/react';+import { renderHook } from '@testing-library/react';const toastMock = {success: vi.fn(),@@ -62,7 +62,6 @@ describe('useUniverseAction', () => {expect(ref.current).toBe(false);expect(toastMock.loading).toHaveBeenCalledWith('Working…');expect(setWorlds).toHaveBeenCalled();- // setWorlds reducer puts the updated universe first and dedupes by idconst updated = setWorlds.mock.results[0].value;expect(updated[0]).toEqual({ id: 'u1', name: 'new' });expect(onFreshResult).toHaveBeenCalledWith(out, { capturedId: 'u1' });@@ -153,9 +152,8 @@ describe('useUniverseAction', () => {await run({ ref, setBusy, action });// CLAUDE.md "Deferred work must respect both staleness and unmount" —// hook intentionally skips ref/busy reset when unmounted to avoid- // post-unmount setState. Async caller closure handles it on remount.+ // post-unmount setState.expect(ref.current).toBe(true);- // setBusy(true) was called on entry but the cleanup setBusy(false) is gated.expect(setBusy).toHaveBeenCalledTimes(1);expect(setBusy).toHaveBeenCalledWith(true);expect(setWorlds).toHaveBeenCalled();