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
docs: archive sharing-merge-hardening bundle to DONE.md
[._.]/ Adam Eivy179a9010910f
diff --git a/DONE.md b/DONE.mdindex 9c4d960a5a..8b75af581f 100644--- a/DONE.md+++ b/DONE.md@@ -10,6 +10,7 @@ For active roadmap see [PLAN.md](./PLAN.md). For project goals see [GOALS.md](./### 2026-05-19+- **[med-sharing-server-services-sharing] [med-sharing-server-services-mediaannotations-js-38] [low-sharing-server-services-mediaannotations-js] [low-sharing-server-services-mediaannotations-js-2] [low-sharing-server-services-sharing] Sharing/annotation-merge hardening bundle.** Five v2.1.0 pre-release residue items shipped together because they all touch the same annotation-sync + LWW-merge surface. (1) `annotationsSync.flushAll` no longer resolves one `sourceName` for all buckets — `exportAnnotationsToBucket` now resolves its own per-bucket name, so per-bucket `displayNameOverride` is honored in outgoing annotation manifest envelopes the same way it already was for series/universe/media manifests. The bucket-effective resolver lives in `sharing/annotationIdentity.js` as a new `resolveBucketSourceName(bucket)` export consumed by both the exporter and the annotation flush (the exporter's local copy in `sharing/exporter.js` was deleted in favor of the shared helper). (2) `mediaAnnotations.mergePeerAnnotations` now pre-rejects peer payloads with missing/invalid `updatedAt` before they reach `sanitizeAuthorEntry`'s `now`-fallback — previously a malformed peer record would always win LWW. The pre-check disambiguates "empty tombstone" (still applies as a delete) from "malformed payload" (now ignored entirely, instead of silently deleting the prior peer entry through the tombstone branch). (3) `sanitizeAuthorEntry` gained an opt-in `clampUpdatedAtTo` option used by the merge path so a peer whose clock is years ahead can't ratchet every subsequent LWW round on the same key — its `updatedAt` is clamped to local-now on import without disturbing reasonable timestamps. (4) `mergePeerAnnotations` rejects `peerInstanceId === 'unknown'` (and empty/non-string) on import — the outgoing path already guarded but a hand-crafted manifest or inconsistent peer could otherwise alias every record into the same "unknown" bucket and clobber each other on every merge. (5) `exportAnnotationsToBucket` now has a cheap early-out before `listBucketAssetKeys`: if local has zero annotations AND no prior record exists on disk for this `(bucket, instance)`, skip the manifest+asset-dir scan entirely (the common fresh-install fan-out case). A late-stage skip (both filtered AND prior empty) still covers the case where the bucket has assets but none overlap local. Coverage: 11 new vitest cases across `mediaAnnotations.test.js` (refuses `'unknown'` / empty peer id, drops missing+invalid updatedAt without nuking prior, clamps future-skewed peer ts) and new sibling `sharing/annotationsSync.test.js` (per-bucket displayNameOverride honored in record, cheap early-out skips `listManifestFilenames`, late skip when no local matches + no prior, asset-less bucket short-circuit, inbox-mode short-circuit, tombstone synthesis preserved for prior keys still in bucket). `/simplify` follow-up deferred to `[promote-unknown-instance-id-constant]` — promote the existing `UNKNOWN_INSTANCE_ID` constant from `importer.js` to a shared module + replace the bare `'unknown'` literal at the four remaining sites. All 5775 server tests pass.- **[voice-picker-on-character-cards-voiceid-binding] Voice picker on character cards + per-line override.** New reusable `client/src/components/voice/VoicePicker.jsx` — engine-grouped dropdown over the merged `/api/pipeline/tts/voices` flat namespaced list (Kokoro + Piper today; future engines slot in upstream) with an audition button that POSTs to `/api/pipeline/tts/preview` and pipes the resulting WAV through `voiceClient.playWav` so it composes with voice-mode echo gating. Module-local cache shared between mounts so the universe character editor opening N picker instances fires exactly one `listPipelineTtsVoices` request. Wired into two consumers: (1) `CharacterDetailEditor`'s Identity section binds `entry.voiceId` (canon-level default for every line spoken by that character — server-side `resolveVoiceForLine` already preferred `character.voiceId` after a per-line override); (2) `AudioStage`'s per-line row gets a `compact + hideWhenEmpty` picker driving `voiceIdOverride` through the existing per-line PATCH path (`saveLineText` generalized to `saveLinePatch` so both text edits and voice-override changes share the in-flight-promise gate that `handleRender` already awaits — preventing a synth fired before the override PATCH settles from rendering against the prior voice). New client API helpers `listPipelineTtsVoices` + `previewPipelineTtsVoice` in `apiPipeline.js` (preview uses raw fetch since the shared `request()` helper auto-parses JSON). Unavailable saved voiceIds (engine uninstalled, voice renamed) are preserved as an `(unavailable)` option so the user sees what was bound instead of silently dropping to the placeholder. Empty voices catalog hides the AudioStage row picker (`hideWhenEmpty`) so a broken TTS install doesn't print an empty picker on every line. Coverage: 9 new vitest cases in `VoicePicker.test.jsx` cover catalog fetch + engine-group rendering, namespaced onChange + null-on-clear, unavailable-voice retention, audition→preview→playWav pipe, audition disabled with no selection, load-error inline display, hideWhenEmpty no-op, and the module-cache single-fetch invariant across mounts. Server-side voiceId + voiceIdOverride support was already complete (storyBible.js sanitizer, audio.js#resolveVoiceForLine, lineEditSchema in routes/pipeline.js, audio.test.js for both resolution priorities). All 5755 server tests + 130 client tests pass.- **[high-tests-create-test-files-for-server-services] Create test files for `server/services/clinvar.js` and `server/services/telegramBridge.js`.** Both services had no sibling test file — clinvar covers the genome-scan path PortOS uses to flag actionable variants from a 23andMe upload, and telegramBridge is the outbound HTTP bridge that mirrors notifications to a Telegram chat. New `clinvar.test.js` (12 cases) pins `getClinvarStatus`, `scanClinvar` (severity sort + star tiebreak + corrupt-JSON + unknown-severity fallback), `invalidateClinvarCache`, and `deleteClinvar` (success + ENOENT-swallowed). New `telegramBridge.test.js` (14 cases) pins `init` (4 branches: no token, no allowFrom, getMe rejection, happy path + multi-line .env), `sendMessage` (pre-init, success body shape, ok:false surfaced, rate-limit drain at 30), `reload` (no-op when inactive, chat-id swap when active), `cleanup` (state reset + listener unsubscribe), and notification forwarding through the real `notificationEvents` EventEmitter (HTML-escape + emoji formatting + cachedForwardTypes whitelist filter). Module-level token-bucket reset between tests uses `vi.useFakeTimers({ toFake: ['Date'] })` + `setSystemTime` advancing 5 minutes per test so `refillTokens()` fires on the next consumeToken call. All 5781 server tests pass.- **[wardroberow-migrate-to-userowdraft] Migrate `WardrobeRow` to consume `useRowDraft`.** `client/src/components/pipeline/CanonCard.jsx` no longer runs two `useFieldDraft` calls per outfit row — a single `useRowDraft(wardrobe, onCommit)` call covers both columns, so wardrobe entries pick up the same sibling-draft ride-along race protection that landed for `ListRow` in `[characterdetaileditor-listrow-row-draft-hook]`. `WardrobeSection.commit` reshapes from `(idx, field, value)` to `(idx, nextRow)`; the pending-row promotion trigger moves from "per-field `name` commit with non-empty value" to "any commit where `nextRow.name.trim()` is non-empty" — same end state, and the rewrite fires earlier for the ride-along case (description blur with a pending name draft now promotes the row instead of stranding it in `pendingNew`). The deferred concern from PLAN ("promotion semantics need their own design pass") resolved by following the existing `CharacterDetailEditor.updateRow` pattern, which already runs the same required-column check against `nextRow`. Removed the now-unused `useFieldDraft` import from `CanonCard.jsx`. +1 ride-along regression test in `CanonCard.test.jsx` (description blurs first with a pending name draft → row promotes with both fields intact). All 121 client tests pass.diff --git a/PLAN.md b/PLAN.mdindex 5f78c53dec..0782e5c10b 100644--- a/PLAN.md+++ b/PLAN.md@@ -82,8 +82,6 @@ _Nothing currently parked — pick the next item from the Backlog._### v2.1.0 pre-release review residue (deferred from main→release multi-agent review, 2026-05-16)-- [ ] [med-sharing-server-services-sharing] **[MED][SHARING]** `server/services/sharing/annotationsSync.js:86-103` — `flushAll()` uses one `sourceName` for ALL buckets instead of honoring per-bucket `displayNameOverride`. Annotation manifest envelopes get the global name; series/universe/media manifests honor the override. Call `resolveSourceName(bucket)` per-bucket inside `exportAnnotationsToBucket`.-- [ ] [med-sharing-server-services-mediaannotations-js-38] **[MED][SHARING]** `server/services/mediaAnnotations.js:38-49` — `sanitizeAuthorEntry` stamps `new Date().toISOString()` when `updatedAt` is missing/invalid on the merge path, making malformed peer records always win LWW. Reject entries without a valid `updatedAt` on merge.- [ ] [med-universe-builder-server-routes-universebuilder] **[MED][UNIVERSE-BUILDER]** `server/routes/universeBuilder.js:407-435` — `registerUniverseBuilderRun(...)` is called AFTER `await svc.recordRun(...)`; worker can pick up the first job and emit `completed` before registration, losing coalescing. Move `registerUniverseBuilderRun` before the enqueue loop.- [ ] [med-migration-scripts-migrations-014-attribute] **[MED][MIGRATION]** `scripts/migrations/014-attribute-existing-annotations.js:43` — if migrations run before first server boot, `instances?.self?.instanceId || 'unknown'` writes the literal `'unknown'` as a phantom peer forever. Defer the migration to first server boot via `ensureSelf()`, or reconcile `unknown`→real id on read.- [ ] [med-pipeline-server-services-pipeline-arcplanner] **[MED][PIPELINE]** `server/services/pipeline/arcPlanner.js:863-866` — `sanitizeSeasonList` dedupes by id (LWW); two LLM-emitted seasons with the same id silently drop one before persist while child issues stay attached to the still-present id. Add a duplicate-id detector that fails loud or warns.@@ -107,10 +105,8 @@ _Nothing currently parked — pick the next item from the Backlog._- [ ] [low-canon-server-services-pipeline-textstages-js] **[LOW][CANON]** `server/services/pipeline/textStages.js:156` — dead-code fallback `|| series.characters` (always `undefined` post-B.4). Drop the middle clause.- [ ] [low-canon-server-services-pipeline] **[LOW][CANON]** `server/services/pipeline/migrateSeriesCanon.js:61` — `updateSeries({ universeId })` writes mid-loop with the universe still empty. Crash between line 61 and the universe patch leaves series stripped + universe empty. Build the universe patch first, then write both.- [ ] [low-importer-server-services-importer-js-444-446] **[LOW][IMPORTER]** `server/services/importer.js:444-446` — `arcSummary = arcContent.summary || arcContent.logline || \`${name} — ${type}\``silently swallows a successful arc-extract that returned empty fields. Log a warning or surface`arcExtractFallback: true`.-- [ ] [low-sharing-server-services-mediaannotations-js] **[LOW][SHARING]** `server/services/mediaAnnotations.js:154` — peer `updatedAt` not clamped to `Math.min(now, sane.updatedAt)`; a peer with future-skewed clock dominates all merges.-- [ ] [low-sharing-server-services-mediaannotations-js-2] **[LOW][SHARING]** `server/services/mediaAnnotations.js:132-167` — `mergePeerAnnotations` accepts `peerInstanceId === 'unknown'`; the outgoing path guards but the import side doesn't. Add `if (!peerInstanceId || peerInstanceId === 'unknown') return ...`.-- [ ] [low-sharing-server-services-sharing] **[LOW][SHARING]** `server/services/sharing/annotationsSync.js:38-68` — empty-payload writes fan to every auto-merge bucket per local edit. Skip when both prior and current filtered payloads are empty.- [ ] [low-ai-dispatch-server-lib-ansistrip-js-14-pattern] **[LOW][AI-DISPATCH]** `server/lib/ansiStrip.js:14` — pattern doesn't strip lone `\x1B` bytes; chunk `\x1B\x1B[31m` leaks a raw escape. Add `.replace(/\x1B(?![@-_\[\]])/g, '')` second pass.+- [ ] [promote-unknown-instance-id-constant] **[LOW][SHARING]** Promote `UNKNOWN_INSTANCE_ID` from `server/services/sharing/importer.js:41` to a shared module (likely `server/services/instances.js`) and replace the bare string `'unknown'` literal at the four other sites that compare against it: `server/services/sharing/manifest.js` (multiple), `server/services/sharing/annotationsSync.js` (`flushAll` early-return), `server/services/mediaAnnotations.js` (`mergePeerAnnotations` peer-id guard), and `server/services/sharing/importer.js` (additional `manifest.producedByVersion || 'unknown'` etc.). Surfaced by /simplify during the sharing-merge-hardening bundle; deferred to keep that PR scoped to behavior fixes.### Better-audit residue