feat(server): W2-B sources, identity resolution, metadata and site workbench

- Sites / accounts / feeds: registry view (/site-definitions), site CRUD with
  enable/disable (history stays queryable, marked site_disabled), accounts and
  feed URLs stored as secrets (only secret_ref / redacted urlDisplay exposed),
  feed enable/disable/reset/fetch; one shared rate limiter + adapter per site.
- Tasks: ingestFeed (FeedFetchState/FeedCursor on feed_source, observation
  feed+guid upsert with digest-change updates, source_release site+id
  aggregation across feeds, auth failure -> account invalid + decision, no
  retry, gap -> feed.gap_suspected -> budgeted backfill snapshot),
  resolveObservation (parseRelease -> local recall via title_alias pg_trgm +
  accepted identities -> TMDB -> resolveIdentity; auto binds entity /
  provisional units / identities / aliases, otherwise identity_candidate pool
  with evidence version and bounded review backoff; manual lock respected),
  refreshMetadata (metadata_field + field_override, user locks win, paths
  untouched), snapshotSite (site_snapshot coverage records).
- Events: feed.due, feed.gap_suspected, release.observed (self-consumed),
  release.resolved, decision.created/updated; scheduler in worker start().
- Identity API: entity detail with redirects, manual mapping correction with
  identity_revision, merge with identity_redirect, pool list/assign/dismiss/
  retry, content unit numbering lock, aliases, external identities.
- Decisions: list/summary (by entity and kind)/detail/resolve; identity
  options executed directly.
- Workbench: /sites/{id}/releases (snapshot first, coalesced live search with
  backoff, origin + freshness) and /sites/{id}/releases/{rid} (volatile field
  recheck times, refresh keeps data on failure).
- Capabilities: catalog.lookup, release.search, release.inspect,
  identity.resolve.
- Migrations 0018-0020: site.adapter api, source_release.resolution_locked,
  site_snapshot, identity_candidate, resolution_attempt, identity_redirect,
  metadata_field, field_override.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-27 20:12:01 +08:00
1 parent 829ca4f7ac
commit a24bda952b
39 files changed
+6861 -15

No files matched your search

+137 -1
View File
@@ -117,6 +117,11 @@ export type ExternalIdentityVerifyStatus = "unverified" | "ok" | "not_found" | "
export type FeedSourcePurpose = "movie" | "series" | "variety" | "promotion" | "search" | "generic";
export type FeedSourceKind = "rss" | "atom" | "list" | "query";
export type FeedSourceHealthStatus = "unknown" | "healthy" | "degraded" | "failing" | "circuit_open" | "disabled";
export type FieldOverrideSource = "tmdb" | "user" | "agent" | "nfo" | "site" | "import";
export type FieldOverrideActorType = "user" | "agent" | "system" | "api_key";
export type IdentityCandidateStatus = "pending" | "resolved" | "dismissed" | "archived";
export type IdentityCandidateReason = "ambiguous" | "no_match" | "proposed" | "lookup_failed";
export type IdentityRedirectActorType = "user" | "agent" | "system" | "api_key";
export type IdentityRevisionAction =
| "created"
| "status_changed"
@@ -136,6 +141,7 @@ export type MediaEntityKind = "movie" | "series" | "variety" | "collection" | "o
export type MediaEntityStatus = "provisional" | "active" | "merged" | "archived";
export type MediaServerInstanceKind = "emby" | "jellyfin";
export type MediaServerInstanceHealthStatus = "unknown" | "healthy" | "degraded" | "offline";
export type MetadataFieldSource = "tmdb" | "user" | "agent" | "nfo" | "site" | "import";
export type ObservationStatus = "new" | "linked" | "ignored" | "error";
export type OrganizationFileResultRole = "main" | "subtitle" | "audio" | "bluray_dir" | "nfo" | "image" | "other";
export type OrganizationFileResultMode = "copy" | "move" | "rename" | "relocate" | "hardlink";
@@ -158,6 +164,15 @@ export type PreferenceTagStatus = "active" | "disabled" | "deleted";
export type ReconcileRunKind = "identity" | "metadata" | "asset" | "acquisition" | "server";
export type ReconcileRunMode = "normal" | "read_only";
export type ReconcileRunStatus = "queued" | "running" | "succeeded" | "partial" | "failed" | "cancelled";
export type ResolutionAttemptOutcome =
| "auto"
| "proposed"
| "ambiguous"
| "no_match"
| "lookup_failed"
| "manual"
| "skipped_locked";
export type ResolutionAttemptActorType = "user" | "agent" | "system" | "api_key";
export type SecretPurpose =
| "site_cookie"
| "site_passkey"
@@ -171,11 +186,13 @@ export type SecretPurpose =
| "other";
export type ServerMappingItemType = "movie" | "series" | "season" | "episode" | "other";
export type ServerMappingMatchStatus = "matched" | "ambiguous" | "unmatched" | "stale";
export type SiteAdapter = "nexusphp" | "mteam_api" | "generic_rss";
export type SiteAdapter = "nexusphp" | "mteam_api" | "api" | "generic_rss";
export type SiteHealthStatus = "unknown" | "healthy" | "degraded" | "failing" | "disabled";
export type SiteCircuitState = "closed" | "open" | "half_open";
export type SiteAccountAuthKind = "cookie" | "passkey" | "api_key" | "password";
export type SiteAccountStatus = "unknown" | "active" | "invalid" | "expired";
export type SiteSnapshotKind = "periodic" | "backfill" | "live_search" | "manual";
export type SiteSnapshotStatus = "running" | "ok" | "partial" | "failed";
export type SourceReleaseResolutionStatus = "unresolved" | "resolved" | "ambiguous" | "unidentifiable" | "rejected";
export type SourceReleaseAvailability = "active" | "site_disabled" | "expired" | "unknown";
export type SubscriptionMediaKind = "movie" | "series" | "variety";
@@ -573,6 +590,51 @@ export interface FeedSourceTable {
updated_at: GeneratedTimestamptz;
}
export interface FieldOverrideTable {
id: Generated<string>;
media_entity_id: string | null;
content_unit_id: string | null;
field: string;
value: Json | null;
locked: Generated<boolean>;
source: Generated<FieldOverrideSource>;
reason: string | null;
actor_type: FieldOverrideActorType;
actor_id: string | null;
created_at: GeneratedTimestamptz;
updated_at: GeneratedTimestamptz;
}
export interface IdentityCandidateTable {
id: Generated<string>;
source_release_id: string;
status: Generated<IdentityCandidateStatus>;
reason: IdentityCandidateReason;
query: Generated<Json>;
candidates: Generated<Json>;
evidence_version: string;
attempts: Generated<number>;
last_attempt_at: Timestamptz | null;
next_review_at: Timestamptz | null;
decision_id: string | null;
resolved_media_entity_id: string | null;
resolved_by: string | null;
resolved_at: Timestamptz | null;
created_at: GeneratedTimestamptz;
updated_at: GeneratedTimestamptz;
}
export interface IdentityRedirectTable {
id: Generated<string>;
from_entity_id: string;
to_entity_id: string;
reason: string | null;
actor_type: IdentityRedirectActorType;
actor_id: string | null;
created_at: GeneratedTimestamptz;
updated_at: GeneratedTimestamptz;
}
export interface IdentityRevisionTable {
id: Generated<string>;
external_identity_id: string;
@@ -665,6 +727,20 @@ export interface MediaServerInstanceTable {
updated_at: GeneratedTimestamptz;
}
export interface MetadataFieldTable {
id: Generated<string>;
media_entity_id: string | null;
content_unit_id: string | null;
field: string;
value: Json | null;
language: string | null;
source: MetadataFieldSource;
source_revision: string | null;
fetched_at: GeneratedTimestamptz;
created_at: GeneratedTimestamptz;
updated_at: GeneratedTimestamptz;
}
export interface ObservationTable {
id: Generated<string>;
feed_id: string;
@@ -855,6 +931,23 @@ export interface ReconcileRunTable {
updated_at: GeneratedTimestamptz;
}
export interface ResolutionAttemptTable {
id: Generated<string>;
source_release_id: string;
observation_id: string | null;
outcome: ResolutionAttemptOutcome;
reason: string | null;
evidence_version: string;
candidate_count: Generated<number>;
media_entity_id: string | null;
best: Json | null;
error: Json | null;
actor_type: Generated<ResolutionAttemptActorType>;
actor_id: string | null;
created_at: GeneratedTimestamptz;
updated_at: GeneratedTimestamptz;
}
export interface SecretTable {
id: Generated<string>;
name: string;
@@ -929,6 +1022,24 @@ export interface SiteAccountTable {
updated_at: GeneratedTimestamptz;
}
export interface SiteSnapshotTable {
id: Generated<string>;
site_id: string;
kind: SiteSnapshotKind;
query: string | null;
filters: Generated<Json>;
pages: Generated<Json>;
item_count: Generated<number>;
new_count: Generated<number>;
status: Generated<SiteSnapshotStatus>;
error: Json | null;
definition_version: string | null;
started_at: GeneratedTimestamptz;
finished_at: Timestamptz | null;
created_at: GeneratedTimestamptz;
updated_at: GeneratedTimestamptz;
}
export interface SourceReleaseTable {
id: Generated<string>;
site_id: string;
@@ -959,6 +1070,7 @@ export interface SourceReleaseTable {
raw: Generated<Json>;
created_at: GeneratedTimestamptz;
updated_at: GeneratedTimestamptz;
resolution_locked: Generated<boolean>;
}
export interface SseEventTable {
@@ -1082,12 +1194,16 @@ export interface DB {
downloader_instance: DownloaderInstanceTable;
external_identity: ExternalIdentityTable;
feed_source: FeedSourceTable;
field_override: FieldOverrideTable;
identity_candidate: IdentityCandidateTable;
identity_redirect: IdentityRedirectTable;
identity_revision: IdentityRevisionTable;
library_root: LibraryRootTable;
login_attempt: LoginAttemptTable;
media_asset: MediaAssetTable;
media_entity: MediaEntityTable;
media_server_instance: MediaServerInstanceTable;
metadata_field: MetadataFieldTable;
observation: ObservationTable;
organization_file_result: OrganizationFileResultTable;
organization_record: OrganizationRecordTable;
@@ -1098,11 +1214,13 @@ export interface DB {
preference_suppression: PreferenceSuppressionTable;
preference_tag: PreferenceTagTable;
reconcile_run: ReconcileRunTable;
resolution_attempt: ResolutionAttemptTable;
secret: SecretTable;
server_mapping: ServerMappingTable;
settings: SettingsTable;
site: SiteTable;
site_account: SiteAccountTable;
site_snapshot: SiteSnapshotTable;
source_release: SourceReleaseTable;
sse_event: SseEventTable;
subscription: SubscriptionTable;
@@ -1173,6 +1291,15 @@ export type ExternalIdentityUpdate = Updateable<ExternalIdentityTable>;
export type FeedSourceRow = Selectable<FeedSourceTable>;
export type NewFeedSource = Insertable<FeedSourceTable>;
export type FeedSourceUpdate = Updateable<FeedSourceTable>;
export type FieldOverrideRow = Selectable<FieldOverrideTable>;
export type NewFieldOverride = Insertable<FieldOverrideTable>;
export type FieldOverrideUpdate = Updateable<FieldOverrideTable>;
export type IdentityCandidateRow = Selectable<IdentityCandidateTable>;
export type NewIdentityCandidate = Insertable<IdentityCandidateTable>;
export type IdentityCandidateUpdate = Updateable<IdentityCandidateTable>;
export type IdentityRedirectRow = Selectable<IdentityRedirectTable>;
export type NewIdentityRedirect = Insertable<IdentityRedirectTable>;
export type IdentityRedirectUpdate = Updateable<IdentityRedirectTable>;
export type IdentityRevisionRow = Selectable<IdentityRevisionTable>;
export type NewIdentityRevision = Insertable<IdentityRevisionTable>;
export type IdentityRevisionUpdate = Updateable<IdentityRevisionTable>;
@@ -1191,6 +1318,9 @@ export type MediaEntityUpdate = Updateable<MediaEntityTable>;
export type MediaServerInstanceRow = Selectable<MediaServerInstanceTable>;
export type NewMediaServerInstance = Insertable<MediaServerInstanceTable>;
export type MediaServerInstanceUpdate = Updateable<MediaServerInstanceTable>;
export type MetadataFieldRow = Selectable<MetadataFieldTable>;
export type NewMetadataField = Insertable<MetadataFieldTable>;
export type MetadataFieldUpdate = Updateable<MetadataFieldTable>;
export type ObservationRow = Selectable<ObservationTable>;
export type NewObservation = Insertable<ObservationTable>;
export type ObservationUpdate = Updateable<ObservationTable>;
@@ -1221,6 +1351,9 @@ export type PreferenceTagUpdate = Updateable<PreferenceTagTable>;
export type ReconcileRunRow = Selectable<ReconcileRunTable>;
export type NewReconcileRun = Insertable<ReconcileRunTable>;
export type ReconcileRunUpdate = Updateable<ReconcileRunTable>;
export type ResolutionAttemptRow = Selectable<ResolutionAttemptTable>;
export type NewResolutionAttempt = Insertable<ResolutionAttemptTable>;
export type ResolutionAttemptUpdate = Updateable<ResolutionAttemptTable>;
export type SecretRow = Selectable<SecretTable>;
export type NewSecret = Insertable<SecretTable>;
export type SecretUpdate = Updateable<SecretTable>;
@@ -1236,6 +1369,9 @@ export type SiteUpdate = Updateable<SiteTable>;
export type SiteAccountRow = Selectable<SiteAccountTable>;
export type NewSiteAccount = Insertable<SiteAccountTable>;
export type SiteAccountUpdate = Updateable<SiteAccountTable>;
export type SiteSnapshotRow = Selectable<SiteSnapshotTable>;
export type NewSiteSnapshot = Insertable<SiteSnapshotTable>;
export type SiteSnapshotUpdate = Updateable<SiteSnapshotTable>;
export type SourceReleaseRow = Selectable<SourceReleaseTable>;
export type NewSourceRelease = Insertable<SourceReleaseTable>;
export type SourceReleaseUpdate = Updateable<SourceReleaseTable>;