Files
silo-server/docs/superpowers/specs/2026-05-26-abs-implementation-fix-design.md
eb6024573e feat(audiobooks): make audiobook libraries first-class catalog items (#73)
* docs(audiobooks): design spec for plugin absorption

Plan to absorb silo-plugin-audiobooks into silo-server as a first-party
feature. Audiobooks land in silo's existing SPA; ABS clients connect
directly. Hard constraints: reuse existing tables (media_items,
media_files, user_watch_progress, user_playback_sessions, people,
item_people, library_collections); only two new tables (abs_sessions,
podcast_feeds) and at most one column add (media_libraries.kind);
silo's main :8080 listener handles ABS Socket.io natively. Out of
scope: audiobook requests flow, smart collections, share links,
external recommender, custom metadata providers, separate audiobook
SPA.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(audiobooks): implementation plan sub-plan 1 (discovery + schema)

First of six sub-plans for the absorption. Six tasks: a discovery
audit that resolves the spec's Risk questions, four idempotent SQL
migrations (abs_sessions, podcast_feeds, media_libraries.kind,
audiobooks.enabled feature flag), and an empty-but-compiling
internal/audiobooks package scaffolded into cmd/silo. Lands as a
strict no-op for users (feature flag defaults to false).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(audiobooks): discovery findings for absorption sub-plan 1

Locks schema/code decisions for migrations 139-142 and downstream
sub-plans. Resolves open Risk questions from the absorption design spec.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): migration 139 add abs_sessions table

Parallel of jellycompat_sessions for Audiobookshelf-compatible clients.
Lets ABS mobile/desktop apps maintain a device-bound session that
silo's audiobooks/abs handlers will validate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* style(audiobooks): match codebase conventions in migration 139

Lowercases type keywords in the abs_sessions CREATE TABLE body to
match neighboring migrations, fixes the client_version column
alignment, and replaces the misleading "parallel to
jellycompat_sessions" header comment with a more accurate
description of the table's role.

Cosmetic only — the running schema is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): migration 140 add podcast_feeds table

Side table on media_items for RSS-subscribed podcasts. Holds feed URL,
ETag/Last-Modified for conditional fetches, last-refresh timestamp, and
the per-feed refresh interval consumed by the upcoming
podcastfeed.Refresher scheduled task.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* style(audiobooks): uppercase PRIMARY KEY in migration 140

Aligns with the codebase convention (type keywords lowercase,
constraint keywords uppercase) established in migration 139's
post-style-fix form. Cosmetic only — running schema is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(audiobooks): migration 141 no-op for media_folders.type

Sub-plan 1 originally reserved migration 141 to add a 'kind' column to
media_libraries discriminating audiobook/podcast libraries. Discovery
audit (sub-plan 1 Task 1) found that the actual table is media_folders
and it already has a type text NOT NULL column with no CHECK constraint
or enum, so 'audiobooks' and 'podcasts' can be added as future values
without DDL.

Landing this migration as a documented no-op preserves the version
numbering audit trail and pins the decision in git history. The
matching down migration is also a no-op.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): migration 142 add audiobooks.enabled flag

Server-settings row that gates the absorbed audiobooks feature.
Defaults to 'false' so sub-plan 1 lands as a strict no-op; subsequent
sub-plans branch on this flag and operators flip it to 'true' at
cutover.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): scaffold internal/audiobooks package

Empty-but-compiling Service that reads the audiobooks.enabled feature
flag from server_settings. Wired into cmd/silo so the package is
referenced from the binary; no routes mounted, no scheduled tasks
registered, no DB writes. Subsequent sub-plans hang scanner branches,
ABS handlers, Socket.io, podcast refresher, and SPA pages off this
Service.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* style(audiobooks): cosmetic cleanups in scaffolded package

Two pre-emptive cleanups flagged by code review before sub-plan 2
copies the patterns:

  1. Sort the internal/audiobooks import after internal/adminjob in
     cmd/silo/main.go (alphabetical).
  2. Drop the redundant "audiobooks: " prefix from the Enabled() error
     wrap; matches how every other top-level service package
     (watchstate, scanqueue, metadata, etc.) formats errors.

No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(audiobooks): implementation plan sub-plan 2 (scanner)

Second of six sub-plans. 10 tasks: PersonKind constants for Author and
Narrator, audio-extension recognizer, library-type helpers, a
walkLogicalTree refactor (movieLibrary bool -> typed walkMode), chapter
extraction via ffprobe, single-file and multi-file audiobook parsers,
scanner write path producing media_items.type='audiobook', and a
filesystem podcast parser (RSS deferred to sub-plan 5).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): add Author and Narrator PersonKind constants

Discovery audit confirmed item_people.kind is unconstrained smallint
with values 1-6 in use. Reserve 7 = Author, 8 = Narrator for audiobook
people-links written by the upcoming scanner branches.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): add audio-extension recognizer for scanner

Mirrors the existing videoExtensions/SupportsVideoFile pair. Used by
upcoming audiobook and podcast scanner branches to filter directory
walks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): library-type recognizers for scanner dispatch

isAudiobookLibraryType and isPodcastLibraryType match singular and
plural forms case-insensitively, mirroring isMovieLibraryType. Used by
upcoming scanner walk branches (Task 4) that filter audio files into
audiobook and podcast libraries.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(scanner): replace movieLibrary bool with typed walkMode

Lets walkLogicalTree dispatch on multiple library shapes (video, movie,
audiobook, podcast) without proliferating boolean flags. Behavior for
existing video and movie libraries is unchanged; audiobook and podcast
modes will be consumed by the upcoming audiobook.go and podcast.go
parsers in later tasks of this sub-plan.

walkModeFor() derives the mode from a media_folders.type string;
unknown types default to walkModeVideo to preserve prior behavior for
any caller still passing a raw type.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): expose ffprobe format tags on ProbeData

The audiobook scanner needs format-level tags (title, artist, album,
date) for media_items metadata; ffprobe already parses them in
ffprobeFormat.Tags but ProbeData previously discarded them. Add
FormatTags map[string]string to ProbeData, populate it in
convertProbeData via a new normalizeFormatTags helper that lowercases
keys and trims values.

Adds a fixture audiobook .m4b with embedded chapters (Intro/Outro) and
format tags, and a test that verifies ProbeFile() returns both
correctly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): parser for single-file audiobook folders

parseAudiobookFolder reads tags + chapters via the existing ProbeFile
(now that Task 5 exposes FormatTags on ProbeData) and produces a
parsedAudiobook struct. Title falls back from "title" tag to "album";
author from "artist" -> "album_artist" -> "composer"; series from
"album" -> "series" -> "mvnm" (Movement Name, used by some MP4 tools).
Year parsed from "date" or "year" tags, tolerating ISO dates and
parenthesized forms.

Single-file case only; multi-file folders (one audio file per chapter)
return a placeholder error and arrive in Task 7.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): multi-file audiobook folder support

Folders containing N audio files (one per chapter/part) get one
parsedAudiobookFile per file; each file's chapter list is synthesized
as a single chapter with title = filename stem. Title/author/series/
year come from the first file's tags.

Also drops the duplicate pickFirstNonEmpty helper added in Task 6 in
favor of the existing firstNonEmpty already in probe.go.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): scanner write path produces audiobook media_items

ScanAudiobookFolder walks an audiobooks-typed media folder and treats
each immediate subdirectory as one audiobook. For each parsed audiobook
it upserts:
  - one media_items row with type='audiobook'
  - one media_files row per audio file (with chapters JSONB)
  - author/narrator links in item_people (kind=7, kind=8)

Adds itemRepo and personRepo to the Scanner struct, wired from
fileRepo.Pool() in NewScanner — no constructor signature change needed.

ScanFolder dispatches to this path when folder.Type='audiobooks',
bypassing the per-file movie/TV pipeline because audiobooks are
folder-scoped entities.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): filesystem podcast scanner

ScanPodcastFolder walks a podcasts-typed media folder, treating each
subdirectory as a podcast show and each audio file inside as an
episode. Writes media_items.type='podcast' + episodes rows + media_files
rows. RSS-subscribed feeds (podcast_feeds table) arrive in sub-plan 5;
this task covers filesystem-only ingestion.

ScanFolder dispatches to this path when folder.Type='podcasts'.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(audiobooks): implementation plan sub-plan 5 (podcasts)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): expose audiobooks/podcasts library types in admin UI

Adds 'Audiobooks' and 'Podcasts' options to the library-type dropdown
in the admin libraries page so operators can flag a folder as an
audiobook or podcast library. Extends contentLevelsForType() so the
admin UI's downstream filtering treats those types correctly
(audiobook -> ['audiobook'], podcasts -> ['podcast',
'podcast_episode']).

Backend scanner branches for these types were already wired in
sub-plan 2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(migrations): renumber 139_abs_sessions to 147 for origin/main merge

origin/main adds 139_media_requests at the same number our local
audiobook branch had used for abs_sessions. Renumber ours to 147 to
free up 139 for the upstream migration. The schema_versions row is
updated in lockstep on the running database so the migrator sees the
abs_sessions migration as already applied at its new version.

Migrations 140-146 (podcast feeds, media_folders kind noop, audiobook
feature flag, abs playback sessions, podcast episode guid, audiobook
series, audiobook title cleanup) stay where they are — they don't
collide with anything on origin/main.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(migrations): renumber 140_podcast_feeds to 157 for origin/main merge

origin/main added 140_user_permissions at the same version this branch
had used for podcast_feeds. Renumber ours to 157 (next free above the
collections-unify migration at 156) so 140 is free for the upstream
migration. schema_versions on the running database is updated in lockstep
so the migrator sees podcast_feeds as already applied at its new version.

Same pattern as d59c1cb (renumber 139_abs_sessions to 147 for the prior
main merge). Pending migrations after this rename: 132 (downloaded
subtitles admin index, main), 140 (user_permissions, main), and 156
(unify_user_collections, this branch).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(migrations): renumber 141_media_folders_kind_noop to 159 for origin/main merge

Same shape as eb8f67d (the 140→157 renumber from the previous main
merge). origin/main added 141_episode_title_sort_index at the same
version this branch had used for media_folders_kind_noop. Renumber
ours to 159 (next free above the audiobook_series truncate at 158) so
141 is open for the upstream migration. schema_versions on the
running database is updated in lockstep so the migrator sees
media_folders_kind_noop as already applied at its new version.

Pending migrations on silo-prod after this rename: 141
(episode_title_sort_index, main) and any other newer ones from main
that the branch hasn't picked up yet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(migrations): renumber 142_audiobooks_feature_flag to 160 for origin/main merge

Companion to 3c6f062's 141 renumber — origin/main also added
142_episode_catalog_entries (alongside 141_episode_title_sort_index)
at a version this branch had used for the audiobooks feature flag.
Renumber ours to 160 so 142 is open for the upstream migration;
schema_versions on silo-prod is updated in lockstep so the migrator
sees audiobooks_feature_flag as already applied at its new version.

This was the only remaining collision (verified by checking for
duplicate version prefixes across migrations/).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(audiobooks): address foundation review comments

* fix(audiobooks): tighten scanner identity handling

* fix(audiobooks): propagate scanner cancellation

* chore(audiobooks): adopt goose migration layout

* docs(audiobooks): implementation plan sub-plan 3 (API + frontend MVP)

Third of six sub-plans. 9 tasks: three REST endpoints (list/detail/
progress), TanStack Query hooks + types, three React pages
(Library/Detail/Player), and navigation integration. Scoped to MVP —
author/series indices, smart collections, share links, and other
nice-to-haves from the spec are deferred. Streaming reuses silo's
existing /api/v1/stream/{session_id}; no new transcode code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): list endpoint at GET /api/v1/audiobooks

Paginated list of media_items with type='audiobook' scoped to the
caller's accessible libraries via the existing access filter.
Mirrors silo's existing list-style handlers for movies and series.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): detail endpoint at GET /api/v1/audiobooks/{id}

Returns the media_items row, its media_files (with chapters JSONB),
author/narrator extracted from item_people (kinds 7/8), and the
caller's per-profile listening progress from user_watch_progress.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): progress endpoint at POST /api/v1/audiobooks/{id}/progress

UPSERTs user_watch_progress for the caller's (user_id, profile_id,
content_id). Body carries position_seconds; clients are expected to
post every 5-10s during playback plus on pause/seek (matching silo's
existing video progress cadence).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): frontend types and TanStack Query hooks

TypeScript types match the JSON shapes from the new
/api/v1/audiobooks endpoints (list, detail, progress). Three hooks:
useAudiobookLibrary (list), useAudiobook (detail), and
useReportAudiobookProgress (mutation that invalidates the detail
query on success so progress updates reflect immediately).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): library grid page at /audiobooks

Renders a paginated grid of audiobook cards using the
useAudiobookLibrary hook. Each card links to /audiobooks/book/{id}.
Cards show poster, title, and year; falls back to a "No cover"
placeholder when the audiobook has no poster_url. Empty state hints
to operators that they need to set a library's type to 'audiobooks'.

Routes themselves are wired in Task 8 (navigation integration).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): detail page with chapter list

Renders cover, title, author, narrator, year, and overview alongside a
chapter list. Clicking a chapter opens an inline sticky
AudiobookPlayer at that chapter's start. A "Resume" button restarts
playback at the saved progress position if present.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): HTML5 audio player with chapter navigation

Single-file audiobook playback for MVP. Multi-file queuing arrives in
a follow-up. Streams via the existing /api/v1/direct-download GET
endpoint. Position is reported to /api/v1/audiobooks/{id}/progress
every 10s while playing plus on pause/seek/end. Skip-30s, playback
rate select, chapter list panel.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(audiobooks): wire navigation and routes

Adds an Audiobooks entry to the sidebar and registers the two new
routes (/audiobooks for the library grid, /audiobooks/book/:id for
detail). The player renders inline inside the detail page; no
dedicated player route is required for MVP.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(audiobooks): address native API review comments

* feat(audiobooks): add ABS compatibility and polish

* fix(audiobooks): stabilize ABS playback progress reporting

* fix(audiobooks): clean up ABS branch review fixes

* chore(audiobooks): adopt goose layout for ABS migrations

* fix(audiobooks): align player seek bar props

* feat(audiobooks): make libraries first-class catalog items

* feat(admin): add server restart endpoint

* fix(audiobooks): address review comment findings

---------

Co-authored-by: RXWatcher <14085001+RXWatcher@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-07 15:57:05 -04:00

23 KiB

ABS Implementation Fix — Design

Status: Approved (brainstorming complete, awaiting writing-plans handoff) Date: 2026-05-26 Scope: Bring silo-server's Audiobookshelf-compatible API to full parity with the canonical continuum-plugin-audiobooks implementation so that official ABS iOS, Android, and 3rd-party (Plappa, AudioBookShelfFully) clients work end-to-end against silo. Out of scope: silo's native audiobook surface (/api/v1/audiobooks/*), silo-android/silo-apple/silo-plugin-sdk repos, Continuum's plugin-host RPC layer, the "standalone listener" port (silo has no separate process), cover transcoding pipelines, transcribed-audio search.

Commands assume the repository root is the cwd.


1. Problem

silo's ABS-compat layer at internal/audiobooks/abs/ exposes ~20% of the surface that the canonical Continuum plugin implements (continuum-plugin-audiobooks reference). Real ABS mobile clients cannot complete the basic flow today — login is reported broken, and even when it succeeds many subsequent calls (filterdata, resume position, author/series IDs) return data shapes that break the client. Bookmarks, collections, playlists, smart collections, RSS feeds, author/series detail, and listening stats are entirely absent. Socket.io publishes only 3 of the ~30 events real clients subscribe to.

The user's directive: every feature of ABS clients must function. Source of truth for behavior is the Continuum plugin; the booklore-ng reference docs (BOOKLORE_ABS_IMPLEMENTATION_ISSUES.md, src/lib/socket/events.ts) document specific response-shape bugs and the canonical socket event list.

2. Goals & Non-goals

Goals

  • Official ABS iOS app, ABS Android app, and 3rd-party clients (Plappa, AudioBookShelfFully) work end-to-end: add server → login → browse libraries → play → progress sync → bookmark → collection → playlist.
  • Token lifecycle is complete: login, refresh, logout, revocation, multi-device tracking.
  • Socket.io publishes the full event surface real clients subscribe to.
  • New data lives in ABS-scoped tables that don't entangle silo's existing collection system.

Non-goals

  • silo's native audiobook UI changes.
  • silo-android / silo-apple client changes.
  • Importing real audiobook content via ABS-protocol requests (silo has its own internal/requests/ system that is not being bridged here).
  • Watch-together, podcast download queues, server-side backup event streams.

3. Architecture & Strategy

Source of truth: continuum-plugin-audiobooks (canonical). Port file-by-file, adapt to silo's data model (catalog repos, auth.Service, profile model).

Topology: silo is monolithic; the ABS layer reads/writes the local DB directly. The Continuum plugin's HostClient → backend plugin RPC layer has no analog and is dropped.

Package layout: keep silo's existing internal/audiobooks/{abs,abssocket,podcastfeed} — it already mirrors the Continuum plugin's structure.

Listener: continue using the dedicated :13378 ABS-compat HTTP server (configured in internal/config/db_loader.go as audiobookshelf_compat.listen). Routes mounted on a fresh chi router; no SPA fallback collisions.

Data isolation: new ABS surface uses dedicated tables (abs_bookmarks, abs_user_collections, abs_collection_items, abs_playlists, abs_playlist_items, abs_smart_collections, abs_rss_feeds). silo's existing library_collections / user_personal_collections / user_smart_collections / collection groups are untouched. Future bridging is possible but out of scope here.

4. Phasing

Four phases, each independently mergeable and independently verifiable against a real mobile client.

Phase 0 — Login + critical bug fixes

Goal: iOS/Android app can add server → login → browse library → tap book → play end-to-end. No bookmarks/collections/etc. yet.

Concrete changes:

File:line Change
internal/audiobooks/abs/login.go:195-234 Add to login envelope: user.itemTagsAccessible: [], user.itemTagsSelected: [], user.lastSeen: <epoch ms>, user.createdAt: <epoch ms>. Enrich serverSettings with coverAspectRatio, dateFormat, timeFormat, storeCoverWithItem, scannerDisableWatcher, metadataFileFormat, chromecastEnabled. Mirror Continuum's completeLogin (continuum-plugin-audiobooks/internal/abs/handler.go:591-697) verbatim.
internal/audiobooks/abs/login.go:274-315 (handleABSAuthorize) Return the identical envelope as /login, including accessToken and refreshToken. Currently omits them, which breaks resume-on-launch.
internal/audiobooks/abs/handler.go:353-391 (bearerAuth) Audit JTI lookup against abs_session_store.go:GetTokenByJTI to confirm the freshly-minted JTI is found. Add slog.Debug lines at each rejection branch so the next 401 is traceable. Confirm ?token= query-param fallback parses correctly (iOS AVPlayer requirement).
internal/audiobooks/abs/libraries_handler.go:499-549 (siloItemToMetadata) Include id on every authors[] entry (use item_people.id UUID). Include id on every series[] entry (slugified name until a series table lands). Populate genres and tags from real catalog data instead of empty arrays. Cross-reference booklore-ng/BOOKLORE_ABS_IMPLEMENTATION_ISSUES.md lines 9-100.
internal/audiobooks/abs/play_response.go:119 Replace hardcoded currentTime: 0 with ProgressStore.GetItemProgress(userID, profileID, libraryItemID) lookup; emit the persisted currentTime and progress fields.
internal/audiobooks/abs/libraries_handler.go:56-66 When ?include=filterdata, hydrate authors, series, narrators, genres, languages, tags aggregations so iOS filter UI populates.
internal/audiobooks/abs/login.go (new handler) Add POST /auth/refresh. Validate refresh token type, check JTI not revoked, mint new access+refresh pair, persist new JTIs. Port from continuum-plugin-audiobooks/internal/abs/handler.go:handleRefresh.
internal/audiobooks/abs/login.go (new handler) Add POST /logout. Marks caller's JTIs revoked in abs_sessions. Port from Continuum's handleLogout.
internal/audiobooks/abs/handler.go:225 (mountRoutes) Mount the new /auth/refresh and /logout routes (the latter inside bearerAuth).

Deliverable: silo build where official ABS iOS app smoke test passes the core flow.

Size: ~600-800 lines across ~6 files + 2 new endpoints.

Phase 1 — Feature surface completion

Goal: Bookmarks, manual collections, playlists, smart collections, RSS feeds, author/series detail, and listening stats functional in mobile clients.

Endpoints to add (all under bearerAuth unless noted; mounted at both /abs/api/* and /api/*):

Bookmarks (port continuum-plugin-audiobooks/internal/abs/bookmarks_handler.go)

  • POST /api/me/item/{itemId}/bookmark — body {title, time} → array of all bookmarks for the item. Fires socket user_updated (reason: "bookmark_created").
  • PATCH /api/me/item/{itemId}/bookmark — upsert at time position. Fires user_updated (reason: "bookmark_updated").
  • DELETE /api/me/item/{itemId}/bookmark/{time} — fires user_updated (reason: "bookmark_deleted").

Manual Collections (port collections_handler.go)

  • GET /api/collections — list with embedded libraryItems[].
  • POST /api/collections — {name, description} → single collection.
  • GET/PATCH/DELETE /api/collections/{id}.
  • POST /api/collections/{id}/book/{bookId} — add item.
  • DELETE /api/collections/{id}/book/{bookId} — remove item.

Playlists (port playlists_handler.go)

  • GET /api/playlists → {playlists: [...]}.
  • POST /api/playlists — {name, description, cover_item, is_public}.
  • GET/PATCH/DELETE /api/playlists/{id}.
  • POST /api/playlists/{id}/item — {libraryItemId, episodeId?}.
  • POST /api/playlists/{id}/batch/add — {items: [...]}.
  • POST /api/playlists/{id}/batch/remove.
  • DELETE /api/playlists/{id}/item/{libraryItemId}[/{episodeId}].

Smart Collections (port smart_collection_handler.go + the entire internal/smartcoll/ DSL package; adapt SQL to silo's media_items schema)

  • GET /api/me/smart-collections → {items: [...]}.
  • POST /api/me/smart-collections — {name, description, color, is_public, is_pinned, query_def}.
  • GET /api/me/smart-collections/{id}.
  • GET /api/me/smart-collections/{id}/items — evaluates query_def against the catalog.
  • PATCH/DELETE /api/me/smart-collections/{id}.

Author detail

  • GET /api/authors/{id} — single author with books[].
  • GET /api/authors/{id}/image — wire to item_people.poster_path via DetailService.PresignURL (currently 404s).

Series detail

  • GET /api/series/{id} — single series with books[] sorted by series_sequence.

RSS Feeds (port rss_feed_handler.go + internal/podcastfeed/)

  • POST /api/feeds — {itemId, slug, minified} → {success, feed: {id, slug, url, ...}}.
  • GET /api/feeds — caller's feeds.
  • DELETE /api/feeds/{id}.
  • GET /abs/public/feed/{slug} — public RSS XML (no auth, slug is capability token).
  • GET /abs/public/feed/{slug}/cover.
  • GET /abs/public/feed/{slug}/item/{itemId}/{fileIdx}.

Listening stats (port internal/abs/handler.go:handleListeningStats + handleListeningSessions)

  • GET /api/me/listening-stats → {totalTime, items, days, dayOfWeek, monthly} from abs_playback_sessions aggregation.
  • GET /api/me/listening-sessions?limit=... — paginated session history.
  • GET /api/me/listening-sessions/{sid} — single session detail.

Continue-listening toggles (port continue_listening.go)

  • GET /api/me/progress/{itemId}/remove-from-continue-listening.
  • GET /api/me/progress/{itemId}/readd-to-continue-listening.
  • Adds hide_from_continue boolean column to user_watch_progress (the table the ABS layer writes via abs_progress_store.go).

Migrations (numbered after silo's current max, paired up/down per CLAUDE.md):

  • 148_abs_bookmarks — (id ULID PK, user_id, profile_id, library_item_id, time_seconds, title, created_at, updated_at) + unique (user_id, profile_id, library_item_id, time_seconds).
  • 149_abs_user_collections + 150_abs_collection_items.
  • 151_abs_playlists + 152_abs_playlist_items.
  • 153_abs_smart_collections — includes query_def jsonb.
  • 154_abs_rss_feeds — slug is unique capability token.
  • 155_abs_progress_hide_from_continue — adds hide_from_continue boolean default false.

Deliverable: ABS iOS/Android Library, Collections, Playlists, Bookmarks, RSS, Stats tabs all functional.

Size: ~3000-4000 lines across ~15 new files + 7 migration pairs. Splittable into 4 sub-commits (bookmarks, collections+playlists, smart collections, RSS+stats).

Phase 2 — Socket.io full event parity

Goal: A logged-in mobile client sees real-time updates when another device on the same account changes progress, when a server scan adds items, when collections/playlists are mutated remotely, and when an admin posts notifications.

Event surface (union of Continuum + booklore-ng — what real ABS iOS source subscribes to):

Server → Client (~30 events):

  • Lifecycle: init, auth_failed, user_online, user_offline, listener_count.
  • Progress/session: user_item_progress_updated, user_session_open, user_session_updated, user_session_closed, user_stream_update, user_stream_end.
  • User-scoped: user_updated (bookmark reasons).
  • Library: library_added, library_updated, library_removed.
  • Items: item_added, item_updated, item_removed, items_added.
  • People/series: author_added, author_updated, author_removed, series_added, series_updated, series_removed.
  • Collections/playlists: collection_added/updated/removed, playlist_added/updated/removed.
  • RSS: rss_feed_open, rss_feed_closed.
  • Tasks: scan_start, scan_progress, scan_complete, task_started, task_progress, task_finished.
  • Misc: notification.

Client → Server (10 events):

  • auth (exists), ping, join_library, leave_library, playback_start, playback_sync, playback_end, stream_open, stream_close, sync_progress.

Architecture changes to internal/audiobooks/abssocket/:

  • Add room types: existing user:<userID>, new lib:<libraryID> (joined via join_library), new admin:*.
  • New file abssocket/publisher.go exposing Publisher interface (PublishUser, PublishLibrary, Broadcast). Replaces ad-hoc h.publish/h.broadcast helpers on the Handler struct (currently silent no-ops when SocketIO == nil). Tests pass a recording Publisher.

Cross-package event-source hooks (via a new audiobooks.EventBroadcaster interface in api.Dependencies so the consumer packages don't import abssocket directly):

  • internal/scanner/ — emit scan_*, item_*, items_added on audiobook-library scan operations.
  • internal/taskmanager/ — emit task_* for audiobook-scoped tasks.
  • internal/api/handlers/libraries.go (or wherever library CRUD lives) — emit library_*.

Auth/lifecycle improvements:

  • Richer init payload: {userId, connectedAt, libraries[], itemTagsAccessible[]}.
  • Heartbeat: respond to ping with pong.
  • On disconnect, decrement listener count and broadcast user_offline if this was the user's last device.
  • Reconnect replay (last 30s of user-scoped events) is out of scope for v1; leave a hook.

Migrations: none — sockets are stateless except for in-memory connection registry.

Size: ~1500-2000 lines: ~600 in abssocket/, ~400 publisher wiring across audiobook handlers, ~500 cross-package hooks.

Phase 3 — Hardening

Media token signing layer (port continuum-plugin-audiobooks/internal/mediatoken/):

  • Separate HS256 secret (audiobooks.abs.media_signing_secret), 15-min TTL, claims bound to (user_id, profile_id, book_id, file_idx).
  • file_handler.go mints when building stream URLs; validates on file request.
  • Defense-in-depth: a leaked stream URL grants access to ONE file for 15 minutes instead of full account.
  • Secret stored in server_settings, auto-generated on first read.

Device tracking (currently abs_sessions.device_id = JTI, useless for UI):

  • Parse User-Agent on /login → derive device_name, client_name, client_version, store on abs_sessions insert.
  • GET /api/me/sessions — list user's sessions (so they see "iPhone 15 Pro — Sep 1").
  • DELETE /api/me/sessions/{jti} — selective revocation.

Audit log:

  • New table abs_audit_log: (id, user_id, action, ip, user_agent, metadata jsonb, created_at).
  • Logged events: login success/failure, logout, token refresh, session revoke, smart-collection-rule changes.
  • Optional GET /api/admin/audit-log for ops visibility.

Rate limiting beyond login:

  • Per-user limit on POST /me/progress (1/sec — clients sometimes spam this).
  • Per-user limit on POST /auth/refresh (5/hour — prevent JTI accumulation).

Size: ~800-1200 lines + 2 migration pairs.

5. Data Model

New tables (all in Phase 1 unless noted)

abs_bookmarks (
  id              text PRIMARY KEY,         -- ULID
  user_id         integer NOT NULL,
  profile_id      uuid,                     -- nullable: primary profile
  library_item_id text NOT NULL,
  time_seconds    double precision NOT NULL,
  title           text,
  created_at      timestamptz DEFAULT now(),
  updated_at      timestamptz DEFAULT now(),
  UNIQUE (user_id, profile_id, library_item_id, time_seconds)
)

abs_user_collections (
  id          text PRIMARY KEY,            -- ULID
  user_id     integer NOT NULL,
  profile_id  uuid,
  name        text NOT NULL,
  description text,
  is_public   boolean DEFAULT false,
  created_at  timestamptz DEFAULT now(),
  updated_at  timestamptz DEFAULT now()
)

abs_collection_items (
  collection_id text NOT NULL REFERENCES abs_user_collections(id) ON DELETE CASCADE,
  library_item_id text NOT NULL,
  added_at      timestamptz DEFAULT now(),
  PRIMARY KEY (collection_id, library_item_id)
)

abs_playlists (
  id            text PRIMARY KEY,
  user_id       integer NOT NULL,
  profile_id    uuid,
  name          text NOT NULL,
  description   text,
  cover_item    text,                       -- library_item_id for cover
  is_public     boolean DEFAULT false,
  created_at    timestamptz DEFAULT now(),
  updated_at    timestamptz DEFAULT now()
)

abs_playlist_items (
  playlist_id     text NOT NULL REFERENCES abs_playlists(id) ON DELETE CASCADE,
  position        integer NOT NULL,
  library_item_id text NOT NULL,
  episode_id      text,                     -- nullable: book item vs podcast episode
  added_at        timestamptz DEFAULT now(),
  PRIMARY KEY (playlist_id, position)
)

abs_smart_collections (
  id          text PRIMARY KEY,
  user_id     integer NOT NULL,
  profile_id  uuid,
  name        text NOT NULL,
  description text,
  color       text,
  is_public   boolean DEFAULT false,
  is_pinned   boolean DEFAULT false,
  query_def   jsonb NOT NULL,
  created_at  timestamptz DEFAULT now(),
  updated_at  timestamptz DEFAULT now()
)

abs_rss_feeds (
  id           text PRIMARY KEY,
  user_id      integer NOT NULL,
  slug         text UNIQUE NOT NULL,        -- capability token in URL
  item_id      text NOT NULL,
  minified     boolean DEFAULT false,
  created_at   timestamptz DEFAULT now()
)

-- Phase 3
abs_audit_log (
  id          bigserial PRIMARY KEY,
  user_id     integer,
  action      text NOT NULL,
  ip          inet,
  user_agent  text,
  metadata    jsonb,
  created_at  timestamptz DEFAULT now()
)

Modifications to existing tables

-- Phase 1: hide-from-continue toggle
ALTER TABLE user_watch_progress ADD COLUMN hide_from_continue boolean DEFAULT false;

-- Phase 3: real device tracking
ALTER TABLE abs_sessions
  ALTER COLUMN device_id DROP DEFAULT,
  ADD COLUMN parsed_user_agent text;

6. Testing Strategy

Unit tests (Go, in-package):

  • Table-driven per handler in internal/audiobooks/abs/: happy path, missing field, wrong field type, IDOR (other user's session/bookmark/collection).
  • abssocket/ Publisher recording mock — verify events fire on the right operations with the right payload shape.
  • Smart collection DSL evaluator — port Continuum's smartcoll_test.go.

Integration tests (against real Postgres + Redis via silo's internal/audiobooks/testutil harness):

  • Full login → browse → play → progress → close-session flow.
  • Token refresh — old token rejected, new token accepted.
  • Bookmark CRUD round-trip with socket event capture.
  • Smart collection rule evaluation against seeded catalog.

End-to-end (manual):

  • iOS official ABS app: add server → login → browse → play offline downloads → progress sync across devices.
  • Plappa: same flow. Strictest client for response shape; if Plappa works, everything works.
  • Android official: same.

Migration safety:

  • Each migration includes .down.sql.
  • New helper scripts/test-abs-migrations.sh runs up → down → up against a fresh DB.

7. Rollout

Single-shot per phase, no human review gate. Each phase gets its own implementation plan (separate writing-plans cycle) since a combined plan would be unwieldy at this size. Start with Phase 0; subsequent phases planned only after the prior phase merges and verifies.

Phase PR Verify
Phase 0 One PR make build → restart silo → curl /ping → iOS app smoke test
Phase 1 One PR (or 4 sub-PRs if reviewable size matters) iOS app: Bookmarks, Collections, Playlists, Stats tabs functional
Phase 2 One PR Two devices on same account: progress sync visible in real time
Phase 3 One PR /api/me/sessions shows real device names; leaked stream URL expires

Cross-repo coordination: silo-android and silo-apple are NOT touched. The ABS-compat surface targets OFFICIAL ABS clients; silo's own clients use silo's native API.

Rollback: every migration has a working .down.sql. New tables don't break existing functionality; silo's native audiobook API (/api/v1/audiobooks/*) is untouched.

8. Open Follow-ups (Explicitly Out of Scope)

  • ABS server-side import requests (/api/me/request) — Continuum had this; silo has its own internal/requests/ system. Bridging is a future decision.
  • Podcast episode-download queue events (episode_download_*) — only relevant if silo gains podcast download capability beyond RSS refresh.
  • Backup events — silo's backup story is separate.
  • Watch-Together over the ABS socket — silo has internal/watchtogether/, deferred.
  • Reconnect replay buffer for socket events — Phase 2 leaves a hook but does not implement.

9. References

  • Source-of-truth implementation: continuum-plugin-audiobooks (sibling worktree). Key files: internal/abs/handler.go, bookmarks_handler.go, collections_handler.go, playlists_handler.go, smart_collection_handler.go, rss_feed_handler.go, continue_listening.go, abssocket/server.go, mediatoken/.
  • Bug catalog for response shape: booklore-ng/BOOKLORE_ABS_IMPLEMENTATION_ISSUES.md.
  • Canonical socket event list: booklore-ng/src/lib/socket/events.ts.
  • ABS API documentation: booklore-ng/AUDIOBOOKSHELF_API_DOCUMENTATION.md.

10. Phase 0 — Status

Implemented: 2026-05-26. Plan: docs/superpowers/plans/2026-05-26-abs-phase-0-login-and-critical-fixes.md. All 11 plan tasks committed on feat/audiobooks and deployed to the production silo container. Endpoint smoke tests confirm correct mount + status codes for /ping, /login, /auth/refresh, /logout, /me, /authorize at both root and /api//abs/api prefixes. End-to-end iOS/Plappa app validation pending operator hand-off.

Phase 0 commits (13 total — implementation + review-feedback fixes):

# SHA Subject
1 6c9c721 feat(audiobooks): diagnostic logging to ABS bearer auth and login
1+ d5edb24 chore(audiobooks): normalize slog "err" key + add path to secret-fetch log
2 877120f fix(audiobooks): enrich ABS login envelope
2+ 47c04f1 chore(audiobooks): reuse existing now var in login envelope
3 045984c fix(audiobooks): /authorize returns identical envelope to /login
3+ 0306cfe docs(audiobooks): restore x-return-tokens and displayName fallback comments
4 e163858 fix(audiobooks): emit IDs on authors/series and stable genres/tags arrays
4+ 470a483 fix(audiobooks): proper pagination total + tags key in play session
5 7f600b2 fix(audiobooks): hydrate filterdata authors and series in library detail
5+ 2e2b411 chore(audiobooks): rename const cap to fetchCap in buildFilterData
6 7e956f1 fix(audiobooks): seed currentTime from ProgressStore so resume works
7 93e321f feat(audiobooks): POST /auth/refresh for ABS token rotation
8 278f815 feat(audiobooks): POST /logout for ABS sign-out

Tests added: 15 (6 metadata + 4 resume + 5 refresh + 4 logout — note 4 logout overlaps with refresh's memTokenStore). go test ./internal/audiobooks/... -count=1 all pass.

Next: Phase 1 (bookmarks, collections, playlists, smart collections, RSS, author/series detail, listening stats) will start with its own brainstorming → writing-plans cycle after operator confirms Phase 0 works against real clients.