Skip to content

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

feat([importer-review-ui-extract-canoncard-once-universe]): share EntryCard shell in Importer review

[._.]/ Adam Eivy6052f95b2bd4
diff --git a/DONE.md b/DONE.md
index 17d229bed5..d69cf68f93 100644
--- a/DONE.md
+++ b/DONE.md
@@ -13,6 +13,7 @@ For active roadmap see [PLAN.md](./PLAN.md). For project goals see [GOALS.md](./
- **[tabpills-pipelineissue-status-dot-trailing-slot] Extend `<TabPills>` with a `trailing` slot to migrate `PipelineIssue.jsx`.** Added an optional `t.trailing` ReactNode to the tab shape, rendered after the count in both `underline` and `pills` variants of `client/src/components/ui/TabPills.jsx`. Migrated `client/src/pages/PipelineIssue.jsx`'s previously-inlined stage tab row (the 11th outlier — its per-tab `STATUS_DOT[status]` indicator didn't fit the prior contract) onto `<TabPills>`, with the status dot supplied via `trailing`. Net 22-line bespoke `<button>` block collapsed onto the shared primitive; the row also picks up the standard mobile touch-target (`min-h-[44px]`) and icon size (16 vs 14) used elsewhere. +1 vitest case in `TabPills.test.jsx` pins the DOM-order contract (`trailing` follows `count`) in both variants; all 78 client tests pass.
- **[sharing-inbox-live-subscription-badge] "🔄 live" badge on inbox subscription rows.** Subscription rows in the Sharing → Inbox tab now show a small green "live" pill (spinning RefreshCw icon + label) when `item.subscription` is truthy AND `item.receivedAt` is within the last 5 minutes. Re-exports fire on every record edit with a 3s server-side debounce and propagate via chokidar in <1s, so a row received that recently is a real-time signal that the sender is actively editing. Pure `isLiveSubscription(item, now=Date.now())` helper exported from `client/src/pages/Sharing.jsx` (handles null/undefined inputs + unparseable `receivedAt` + one-shot shares without throwing); 5 new vitest cases in `Sharing.test.jsx` cover all four exit paths. Badge placement is inline in the row's metadata strip alongside source/kind/timestamp; freshness is computed on render so the badge naturally decays when the page re-renders (via socket updates) past the 5-min mark. All 82 client tests pass.
- **[nounsstage-cheaper-seriesnamemap-fetch] NounsStage seriesNameMap — avoid the heavy canon-usage fetch.** `NounsStage.jsx` was calling `GET /api/universe-builder/:id/canon-usage` purely to extract `seriesNameMap` for the CanonCard "from <series>" chip, which makes the server iterate every linked series × every issue × 3 prose matchers — O(series × issues × matchers) work for what should be O(series). Picked option (a) from the PLAN: new `GET /api/universe-builder/:id/series-names` endpoint returns `[{id,name}]` for linked series only, with no per-issue prose scan and no matchers. Backed by `listLinkedSeriesNames` in `server/services/canonUsage.js` (validates the universe via `getUniverse` so 404s mirror the heavier endpoint, then `listSeries().filter(s.universeId === id).map(s ⇒ ({id, name}))`). Client helper `getUniverseSeriesNames` in `apiUniverseBuilder.js`; `NounsStage` builds the map locally with `Object.fromEntries(list.map(...))`. `UniverseCanonSection` continues to use `canon-usage` because it actually needs the per-entry usage counts. +3 vitest cases in `canonUsage.test.js` (linked-series filter + ignores issues; empty result for no-linked universe; 404 for missing universe).
+- **[importer-review-ui-extract-canoncard-once-universe] Importer review UI shares the canon-card shell.** `Importer.jsx#CanonReviewSection` no longer hand-rolls its own checkbox card — it renders through the shared `EntryCard` primitive (the post-Phase-2 shell that `CanonCard` and `VariationCard` already render through). The full `CanonCard` contract (id-bearing entries, image refs, lock/refine/wardrobes, intExt/timeOfDay chips) doesn't fit the importer's pre-commit LLM output, so the cleanest "extract" was to lift the visual primitive instead. `EntryCard.jsx` gains a new `selectable={{ selected, onToggle, label? }}` slot: when provided, the card wraps its row in a `<label>`, renders an aria-labelled checkbox column, and swaps the `locked` accent for select-on (`border-port-accent bg-port-accent/5`) vs. select-off (`border-port-border opacity-60`) styling — matching the inline card's prior look pixel-for-pixel so importer users see no visual diff. 6 vitest cases in new `client/src/components/universe/EntryCard.test.jsx` cover: checkbox omitted when `selectable` is null, `selected`-bound state, `onToggle` fires on click, selected vs. unselected accent class application, and the generic-label fallback when `selectable.label` is omitted. All 83 client tests pass; client build succeeds.
- **[sharing-inbox-orphans-on-peer-instance-id-rotation] Cull rotation-orphan inbox rows.** Closes the regression introduced by `[sharing-v2-per-sender-subscription-filenames]`: a peer that rotates its `senderInstanceId` (factory reset / new device) would otherwise leave its old identity's inbox row stranded forever, because the per-sender dedup keys on the new id. `applyInbox` in `server/services/sharing/importer.js` now culls cross-sender orphans on every subscription-manifest arrival when (a) same `(recordKind, recordId, source)`, (b) DIFFERENT `senderInstanceId`, and (c) existing row's `createdAt` older than the 30-day `ROTATION_CULL_MS` window. The window is conservative — two legitimately distinct peers sharing the same display name (e.g. both devices named "MacBook") would only be culled after a month of one going silent. 4 new integration tests in `integration.test.js` (cull at 60 days, preserve at 2 days, preserve different-source-old, and a freshness-gate early-return regression that asserts the cull still persists when the `inbox-has-newer` short-circuit fires). 79 sharing tests pass.
- **[content-addressed-asset-dedup-today-asset-copies] Content-addressed asset dedup.** Share-bucket asset blobs are now stored content-addressed at `<bucket>/assets/blobs/<sha256>` (sidecar metadata at `<sha256>.metadata.json`) instead of filename-addressed at `assets/{images,videos}/<filename>`. Two manifests referencing identical bytes under different filenames now share one on-disk blob — every additional reference is a no-op file-existence check on the same hash. New shared helper `sha256File` in `server/lib/fileUtils.js` (one-shot < 512 KB / streaming ≥ 512 KB); `server/services/backup.js#generateManifest` migrated to the same helper (its inline reimplementation deleted). Path/sidecar helpers (`bucketBlobsDir`, `bucketBlobPath`, `bucketBlobSidecarPath`, `imageSidecarName`, `IMAGE_EXT_RE`) live in `server/services/sharing/buckets.js` so storage-layout changes touch one file. `exporter.js#copyAssetIfPresent` computes the hash and returns `{ kind, ref, hash }` per asset; `importer.js#copyAssetsLocally` resolves bucket paths via a `resolveBucketAssetPaths` helper that prefers `assets/blobs/<hash>` when present and falls back to legacy `assets/{kind}/<filename>` for v1 manifests still in-bucket. `SHARING_SCHEMA_VERSION` bumped 1 → 2; bucket layout adds `assets/blobs/` in `ensureBucketLayout`. `annotationsSync.js#listBucketAssetKeys` now derives the user-facing filename set by scanning manifests' `assetRefs` (with the legacy dir scan retained as a fall-through for v1 buckets). Coverage: 4 new unit tests in `fileUtils.test.js` (small/large split, cross-path identical-bytes equality, distinct-bytes inequality) + 2 new integration tests in `integration.test.js` (two manifests with different filenames + identical bytes share one blob and import cleanly; v1 manifest without `hash` field still imports via legacy path) + updated existing integration assertions to expect `assets/blobs/<hash>` paths. All 249 server test files / 5452 tests pass. Two performance follow-ups captured in PLAN.md: per-source hash caching on the exporter, and per-bucket manifest-scan caching on the annotation flush path.
diff --git a/PLAN.md b/PLAN.md
index 8d5139a8b4..955b1a666b 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -17,8 +17,8 @@ _Nothing currently parked — pick the next item from the Backlog._
### Importer (deferred research)
+- [ ] [importer-canonprompt-preview-fragments-helper] **Share a per-kind preview-fragments helper between Importer and `canonPrompt.js`.** Importer's `CanonReviewSection` callsite (`client/src/pages/Importer.jsx:467-495`) inlines `renderSubtitle` + `renderBody` for each of characters/places/objects. Existing `client/src/lib/canonPrompt.js` already centralizes short/rich descriptor fragments for the render-prompt scope but doesn't fit pre-commit preview: (a) Importer wants ALL visible fields (`personality`, `background`, `role`, `slugline`) for the user to judge before committing — wider than `shortCanonDescriptorFragments`; (b) `normalizeKind` accepts `'setting'` but not `'places'` (the importer's canonSelections key), so a drop-in call would silently return `[]`. Add a `previewCanonFragments(kind, entry, { includeAll: true })` variant and teach `normalizeKind` to alias `'places' → 'settings'`. Then collapse the Importer's three inline `renderBody`/`renderSubtitle` callbacks onto the helper. Deferred from `[importer-review-ui-extract-canoncard-once-universe]`.
- [ ] [chunked-extraction-for-source-200k-chars-today-s] **Chunked extraction for source > 200K chars.** Today's `IMPORTER_SOURCE_CHAR_LIMIT` hard-rejects. Once a real import hits the cap, route through per-chunk canon extraction + rolling synopsis. **Investigate chunk-overlap / merge strategy first — research-required, not a drop-in feature.** Plan sketch: pick a chunk size that fits all three importer prompts (canon/arc/issue-proposal) under the smallest provider's context window after overhead; per-chunk canon-extract feeds back into `existingCanon` for the next chunk so dedup is rolling; rolling synopsis is generated after each chunk and prepended as `priorSynopsis` to the next; arc-extract runs against the final concatenated synopsis, not the raw source; issue-proposal honors chunk boundaries only when a chapter/issue marker straddles them. Open questions: (a) is overlap needed at all, or are chapter markers reliable enough to clean-cut at? (b) how to merge per-chunk arcs when chunks disagree on theme/protagonist? (c) progress UI — single bar or per-chunk? Defer until a real import actually hits the 200K cap; the hard-reject + "trim source" guidance is acceptable for now.
-- [ ] [importer-review-ui-extract-canoncard-once-universe] **Importer review UI: extract `<CanonCard>` once Universe-as-Canon Phase 2 lands.** Today renders an inline minimal card in `Importer.jsx#CanonReviewSection`. Blocked on Phase 2 — revisit when that section's first item ships.
### Universe-as-Canon — Phase 2 + extensions
diff --git a/client/src/components/universe/EntryCard.jsx b/client/src/components/universe/EntryCard.jsx
index e4849d93c3..644368709f 100644
--- a/client/src/components/universe/EntryCard.jsx
+++ b/client/src/components/universe/EntryCard.jsx
@@ -10,8 +10,11 @@
* (NOT a ReactNode). Spread into the internal `EntryCardThumbnail` renderer
* so the 12x12 frame, primary-star badge, and zoom-in button styling stay
* consistent across consumers. Pass `null`/omit to skip the thumbnail column.
+ * - `selectable` — descriptor `{ selected, onToggle, label? }`. Turns the row
+ * into a checkbox-driven selection card (used by the Importer review for
+ * pre-commit canon picks). Selected accent matches `locked`'s family;
+ * unselected dims with `opacity-60` so picked vs. dropped reads at a glance.
*/
-
import { Star } from 'lucide-react';
export default function EntryCard({
@@ -21,18 +24,38 @@ export default function EntryCard({
body = null,
actions = null,
footer = null,
+ selectable = null,
}) {
- const borderClass = locked ? 'border-port-accent/40' : 'border-port-border';
+ const isSelected = selectable ? selectable.selected : false;
+ const borderClass = selectable
+ ? (isSelected ? 'border-port-accent bg-port-accent/5' : 'border-port-border opacity-60')
+ : (locked ? 'border-port-accent/40' : 'border-port-border');
+
+ const row = (
+ <div className="flex items-start gap-3">
+ {selectable ? (
+ <input
+ type="checkbox"
+ checked={isSelected}
+ onChange={selectable.onToggle}
+ aria-label={selectable.label || 'Select entry'}
+ className="mt-1 accent-port-accent shrink-0"
+ />
+ ) : null}
+ {thumbnail ? <EntryCardThumbnail {...thumbnail} /> : null}
+ <div className="flex-1 min-w-0">
+ {title}
+ {body}
+ </div>
+ {actions ? <div className="shrink-0">{actions}</div> : null}
+ </div>
+ );
+
return (
<li className={`rounded border bg-port-bg/60 p-2 ${borderClass}`}>
- <div className="flex items-start gap-3">
- {thumbnail ? <EntryCardThumbnail {...thumbnail} /> : null}
- <div className="flex-1 min-w-0">
- {title}
- {body}
- </div>
- {actions ? <div className="shrink-0">{actions}</div> : null}
- </div>
+ {selectable ? (
+ <label className="cursor-pointer block">{row}</label>
+ ) : row}
{footer}
</li>
);
diff --git a/client/src/components/universe/EntryCard.test.jsx b/client/src/components/universe/EntryCard.test.jsx
new file mode 100644
index 0000000000..23c53a55c0
--- /dev/null
+++ b/client/src/components/universe/EntryCard.test.jsx
@@ -0,0 +1,72 @@
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen, fireEvent } from '@testing-library/react';
+import EntryCard from './EntryCard';
+
+const wrapInList = (node) => <ul>{node}</ul>;
+
+describe('EntryCard — selectable mode', () => {
+ it('omits the checkbox entirely when selectable is null', () => {
+ render(wrapInList(
+ <EntryCard title={<div>Lyra</div>} body={<p>desc</p>} />,
+ ));
+ expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
+ });
+
+ it('renders a checkbox bound to selectable.selected', () => {
+ render(wrapInList(
+ <EntryCard
+ title={<div>Lyra</div>}
+ selectable={{ selected: true, onToggle: () => {}, label: 'Include Lyra' }}
+ />,
+ ));
+ const cb = screen.getByRole('checkbox', { name: 'Include Lyra' });
+ expect(cb).toBeChecked();
+ });
+
+ it('fires onToggle when the checkbox is clicked', () => {
+ const onToggle = vi.fn();
+ render(wrapInList(
+ <EntryCard
+ title={<div>Lyra</div>}
+ selectable={{ selected: false, onToggle, label: 'Include Lyra' }}
+ />,
+ ));
+ fireEvent.click(screen.getByRole('checkbox', { name: 'Include Lyra' }));
+ expect(onToggle).toHaveBeenCalledTimes(1);
+ });
+
+ it('applies the selected accent classes when selected', () => {
+ const { container } = render(wrapInList(
+ <EntryCard
+ title={<div>Lyra</div>}
+ selectable={{ selected: true, onToggle: () => {}, label: 'Include Lyra' }}
+ />,
+ ));
+ const li = container.querySelector('li');
+ expect(li.className).toMatch(/border-port-accent/);
+ expect(li.className).toMatch(/bg-port-accent\/5/);
+ expect(li.className).not.toMatch(/opacity-60/);
+ });
+
+ it('applies the unselected dim classes when not selected', () => {
+ const { container } = render(wrapInList(
+ <EntryCard
+ title={<div>Lyra</div>}
+ selectable={{ selected: false, onToggle: () => {}, label: 'Include Lyra' }}
+ />,
+ ));
+ const li = container.querySelector('li');
+ expect(li.className).toMatch(/opacity-60/);
+ expect(li.className).toMatch(/border-port-border/);
+ });
+
+ it('falls back to a generic checkbox label when selectable.label is omitted', () => {
+ render(wrapInList(
+ <EntryCard
+ title={<div>Lyra</div>}
+ selectable={{ selected: false, onToggle: () => {} }}
+ />,
+ ));
+ expect(screen.getByRole('checkbox', { name: 'Select entry' })).toBeInTheDocument();
+ });
+});
diff --git a/client/src/pages/Importer.jsx b/client/src/pages/Importer.jsx
index 4b1edaa4a4..d87c338163 100644
--- a/client/src/pages/Importer.jsx
+++ b/client/src/pages/Importer.jsx
@@ -4,6 +4,7 @@ import { FileInput, Loader2, ArrowLeft, CheckCircle2, AlertTriangle, ChevronDown
import toast from '../components/ui/Toast';
import { useAsyncAction } from '../hooks/useAsyncAction';
import { STORY_SHAPES } from '../components/pipeline/StoryShapes';
+import EntryCard from '../components/universe/EntryCard';
import {
analyzeImport,
classifyImport,
@@ -544,32 +545,30 @@ function CanonReviewSection({ title, kind, entries, selectedIdxs, onToggle, rend
{title} <span className="text-sm font-normal text-port-text-muted">({selectedCount} / {entries.length} selected)</span>
</h2>
</div>
- <div className="grid grid-cols-1 md:grid-cols-2 gap-2">
- {entries.map((entry, idx) => (
- <label
- key={`${kind}-${idx}`}
- className={`flex items-start gap-3 border rounded p-3 cursor-pointer text-sm ${
- selectedIdxs.has(idx) ? 'border-port-accent bg-port-accent/5' : 'border-port-border opacity-60'
- }`}
- >
- <input
- type="checkbox"
- checked={selectedIdxs.has(idx)}
- onChange={() => onToggle(idx)}
- className="mt-1 accent-port-accent"
- />
- <div className="flex-1 min-w-0">
- <div className="font-medium truncate">{entry.name || '(unnamed)'}</div>
- {renderSubtitle(entry) && (
- <div className="text-xs text-port-text-muted truncate">{renderSubtitle(entry)}</div>
+ <ul className="grid grid-cols-1 md:grid-cols-2 gap-2">
+ {entries.map((entry, idx) => {
+ const subtitle = renderSubtitle(entry);
+ const bodyText = renderBody(entry);
+ const name = entry.name || '(unnamed)';
+ return (
+ <EntryCard
+ key={`${kind}-${idx}`}
+ selectable={{
+ selected: selectedIdxs.has(idx),
+ onToggle: () => onToggle(idx),
+ label: `Include ${name}`,
+ }}
+ title={<div className="font-medium truncate text-sm">{name}</div>}
+ body={(
+ <>
+ {subtitle ? <div className="text-xs text-port-text-muted truncate">{subtitle}</div> : null}
+ {bodyText ? <div className="text-xs text-port-text-muted mt-1 line-clamp-3">{bodyText}</div> : null}
+ </>
)}
- {renderBody(entry) && (
- <div className="text-xs text-port-text-muted mt-1 line-clamp-3">{renderBody(entry)}</div>
- )}
- </div>
- </label>
- ))}
- </div>
+ />
+ );
+ })}
+ </ul>
</section>
);
}