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
Merge pull request #299 from atomantic/claim/sharing-v2-per-sender-subscription-filenames
[._.]/ Adam Eivy64ba1c3297d0
diff --cc DONE.mdindex 5f04b2ce99,c7e777addf..795be72a44--- a/DONE.md+++ b/DONE.md@@@ -8,12 -8,9 +8,13 @@@ For active roadmap see [PLAN.md](./PLAN## 2026-05+### 2026-05-18++- **[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.+### 2026-05-17+ - **[sharing-v2-per-sender-subscription-filenames] Per-sender subscription filenames.** `subscriptionFilename()` now keys on the `senderInstanceId` segment (`sub-<kind>-<recordId>-<senderInstanceId>.json`) so two peers subscribed to the same record write to distinct bucket files instead of clobbering each other. Touched `server/services/sharing/manifest.js` (signature + new `legacySubscriptionFilename` export + `manifestFilename` plumbs `manifest.senderInstanceId` through to the helper + extracted `SUBSCRIPTION_FILE_PREFIX` constant shared with the prune filter), `subscriptions.js` (`unsubscribe` now reads `getInstanceId()` for the new name AND best-effort cleans up the pre-v2 legacy file only when its `senderInstanceId` matches this instance — so a still-subscribed peer's pre-upgrade file isn't stomped), `importer.js` (inbox dedup now keys on `(recordKind, recordId, senderInstanceId)` so peerB's update no longer wipes peerA's inbox row), and the `exporter.js` doc comment. Coverage: 3 new tests in `subscriptions.test.js` (filename-with-sender, legacy cleanup gated on own instance, legacy preserved for other peer's instance), 2 new in `manifest.test.js` (per-sender determinism + two-peer-distinct + `legacySubscriptionFilename` shape), and integration test updated to assert the new naming. All 5,315 server tests pass. Follow-up captured in PLAN.md as `[sharing-inbox-orphans-on-peer-instance-id-rotation]` — per-sender dedup means a peer that rotates its instanceId leaves their old inbox row as an orphan (pre-v2 dedup wiped it implicitly).- **[extract-upsertbyidprepend-helper-universe-builder] Extract `upsertByIdPrepend(list, item)` helper.** New `client/src/lib/upsertByIdPrepend.js` collapses the "filter-by-id then prepend" worlds-list upsert into one helper. The PLAN line called out 3 sites; the actual count was 7 — all collapsed to `setWorlds((prev) => upsertByIdPrepend(prev, entity))`: 1 in `client/src/hooks/useUniverseAction.js` (LLM-action result merge) + 6 in `client/src/pages/UniverseBuilder.jsx` (`handleCreate`, `handleSave`, expand auto-save, refine auto-save, `handleMoveCategoryToTrunk`, `handleGenerateInCategory`). 4 new vitest cases in `upsertByIdPrepend.test.js` (new-id prepend, id replacement, empty-list, no input mutation).- **[universe-builder-redesign-trunks-sub-buckets] Universe Builder redesign — trunks + sub-buckets layout (Phases A–D + Phase C follow-ups).** Multi-phase rewrite landing across 2026-05-15 → 2026-05-17. Phase A added a `kind: 'characters'|'settings'|'objects'|'other'` field to every category bucket + a migration to backfill the built-in defaults; Phase B taught `buildExpansionPrompt()` + `isExpansionShape()` to emit and accept rich canon arrays alongside categories, with client-side `handleExpand` merging canon entries into `universe.{characters,settings,objects}` (dedupe by name, respect locks); Phase C rewrote the page as a tabbed-trunk layout (Bible / Cast / Places / Objects / Other / Composites / Render) with URL state, a unified `EntryCard` rendering both canon entries and category variations, and per-trunk / per-bucket / all-canon batch-render targeting; Phase D shipped `POST /:id/promote-variation` to LLM-expand a variation into a full canon entry (atomic canon append + variation removal in one `updateUniverse` patch, duplicate-name 409 before the LLM call, trunk picker for `kind: 'other'` buckets). Phase C follow-ups closed today: (1) `updateUniverse(id, mutator)` now accepts an async `mutator(latest) => patch` callback that runs INSIDE `queueUniverseWrite` — `autoSortOtherBuckets` and `promoteVariationToCanon` route their read-modify-write through this so a slow LLM call can't admit a concurrent edit between read and persist; promote's variation removal also re-locates by label inside the queue rather than relying on the stale pre-LLM index, and the duplicate-name 409 is re-checked against the latest canon (returns `UNIVERSE_PROMOTE_CATEGORY_GONE` / `UNIVERSE_PROMOTE_VARIATION_GONE` when the bucket/variation disappears mid-flight); (2) `handleAutoSort` / `handlePromoteVariation` / `handleGenerateInCategory` now flush a dirty draft via `handleSave()` before kicking off — `UniverseBuilder.jsx` tracks a `savedDraftSnapshotRef` baseline (compared via `draftSnapshotForDirty`) that updates on universe-load, manual save, expand auto-save, refine auto-save, generate auto-save, and after each LLM mutator's `onFreshResult` merge. `useUniverseAction` gained a `preflight` option that runs AFTER the ref/savedId guard so double-clicks short-circuit before flushing. 5 new server tests (`updateUniverse` mutator overload — happy path, null-skip, throw-propagation, non-object validation, queue-ordering against a parallel literal-patch write) + 4 new client tests (`useUniverseAction` preflight — returns-false abort, throw-as-false, returns-true continue, post-ref-guard ordering).- **[canoncard-from-series-name-full-provenance-label] CanonCard "from series: <name>" full provenance label.** The provenance chip now reads `seriesNameMap?.[entry.sourceSeriesId]` to render `from <Series Name>` with `Introduced by series "<name>" (<id>)` in the tooltip; missing-name fallback preserves the existing `from series` label + id-only tooltip. Chip rendering extracted into a `SourceSeriesChip` helper alongside `ChipPicker` / `ReadonlyChip` in `client/src/components/pipeline/CanonCard.jsx`. Map plumbed from both parents: `UniverseCanonSection.jsx` passes `usage?.seriesNameMap` (no new fetch — reuses the canon-usage call it already makes), and `NounsStage.jsx` fetches `getUniverseCanonUsage(series.universeId)` once on universe load. Server-side `getUniverseCanonUsage` (`server/services/canonUsage.js`) gains a top-level `seriesNameMap: { [seriesId]: name }` field built from every `linkedSeries` (not just ones with prose-match rows) so an entry whose `sourceSeriesId` points at a series with no matching prose still resolves to a name. Coverage: 4 new vitest cases in `CanonCard.test.jsx` (chip omitted with no `sourceSeriesId`; generic fallback when map missing; resolved name + dual-tooltip when present; fallback when id not in map) and 2 new `canonUsage.test.js` cases (linked-with-no-prose-match included; empty map when no series link). NounsStage's per-render fetch is acknowledged as quadratic-cost relative to need; deferred to `[nounsstage-cheaper-seriesnamemap-fetch]` for a thin-endpoint follow-up.