Peach: Local-first video metadata scraper and media manager.
fix: backfill canonical tag relations
Peach local maintenance969c83b99144
diff --git a/docs/HANDOFF.md b/docs/HANDOFF.mdindex 9867e1b44..797ab614b 100644--- a/docs/HANDOFF.md+++ b/docs/HANDOFF.md@@ -20,6 +20,7 @@ This is durable operating knowledge, not a per-session transcript.- Worker results return to the coordinating agent for vocabulary/provenance checks, deduplication, isolated tests and approval. The user does not relay reports between agents.- `scripts/scrape_codes.py` and `scripts/creator_tags.py` are the standard review boundaries. Creator-board work exports `generated/creator-tags-review.csv`; workers may change `pending` to `candidate` or `skip`, while `approved` and the required backup remain coordinator actions.- Claude Code 2.1.232 refused explicit sexual-act classification from board images. Do not assign that visual-content category to Claude again unless its supported-use boundary is reverified; use human review or a separately approved vision provider. Claude remains suitable for code, public metadata adapters, deduplication and non-visual CSV validation.+- An older Claude Desktop conversation did perform board inspection, but conversation text is not proof of persistence: its reported `ruth_lee` mapping differs from the current ledger. Read the transcript only as candidate evidence and reconcile it into the review CSV; database counts and canonical relations are the completion gate.## Reuse before restore@@ -33,7 +34,7 @@ This is durable operating knowledge, not a per-session transcript.- Real ledger: `R:\peach-data\database\ledger.db`; WAL mode; normal browsing legitimately changes play/activity fields.- Tests must create temporary SQLite databases and temporary media files.- Before real migration: SQLite backup, asset/tag counts, `PRAGMA integrity_check`, migration version check, then service smoke test.-- Formal migrations `0000`–`0004` were applied to the real ledger on 2026-08-14. `0003` adds the local default profile, profile-scoped watch queue, typed entity links and entity search terms. `0004` adds synchronized SQLite FTS5 trigram search over asset names/codes, canonical entities, aliases and private search terms. Its backup is `R:\peach-data\database\ledger.pre-migrate-20260814-213920.db`; retain it with the 20:17 recovery points until a later verified migration.+- Formal migrations `0000`–`0005` were applied to the real ledger on 2026-08-14. `0003` adds the local default profile, profile-scoped watch queue, typed entity links and entity search terms. `0004` adds synchronized SQLite FTS5 trigram search over asset names/codes, canonical entities, aliases and private search terms. `0005` backfills compatibility tags written after `0002` into canonical relations and rebuilds affected FTS rows in one batch. Its backup is `R:\peach-data\database\ledger.pre-migrate-20260814-225437.db`; retain it with the earlier recovery points until a later verified migration.- Media and runtime data remain under `R:\media` and `R:\peach-data`; they are not repository assets.## Operationsdiff --git a/docs/STATUS.md b/docs/STATUS.mdindex 9d91c4d42..3c050390c 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -52,6 +52,8 @@ Runtime PIDs are observations, not configuration; always re-check them.- The creator-board sampler completed before its implementation was changed; it left 86 boards and 598 cached frames. No `creator_boards.py` process was active at the final observation. The command now uses the shared source-access policy, disk guard, PID lock and Peach-managed FFmpeg resolver while preserving its prior arguments and output layout.- Creator tagging is now review-first: `scripts/creator_tags.py --export-review` produced `R:\peach-data\generated\creator-tags-review.csv` with 86 boards, 30 prior decisions and 56 pending rows. A parallel worker may write only `candidate`/`skip`; applying accepts only coordinator-reviewed `approved` rows, requires a SQLite backup, and dual-writes compatibility plus canonical tag relations.- A Claude Code 2.1.232 batch was asked to inspect those 56 boards but refused explicit sexual-act visual classification after 24 seconds; it made no CSV changes. The queue remains 27 applied, 3 skipped and 56 pending. Claude should be used for non-visual scraping/code/data reconciliation, not this visual category.+- The earlier Claude Desktop session did visually inspect boards and reported intermediate creator mappings (including `ruth_lee` and `luckydog22`), but its transcript and current ledger disagree: the reported `ruth_lee` foot/hand tags are absent from the persisted `vision_creator` rows. Treat chat text as evidence input, never as an applied result; only the review CSV plus database postcondition is authoritative.+- Migration `0005_backfill_legacy_tags.sql` is applied to the real ledger. It repaired all 27,295 late `vision_creator` compatibility rows missing from `asset_entity`, temporarily suspended the per-row FTS trigger and rebuilt affected search rows once. The real apply took about 7 seconds; 81,873 assets and 88,672 compatibility tag rows were preserved, canonical relations reached 159,172, missing legacy relations are zero, integrity is `ok` and foreign-key violations are zero. Backup: `R:\peach-data\database\ledger.pre-migrate-20260814-225437.db`.- The visible terminal mistaken for a slow batch was the permanent `RM-TrafficWatch` heartbeat. Its scheduled action was changed from `python.exe` to `pythonw.exe` at 22:36, the task restarted successfully, and the new hidden process continued writing `trafficwatch-20260814-223642.log` every 30 seconds. It stops only matching Peach task trees and no longer terminates machine-wide FFmpeg/ffprobe processes.- `scripts/scrape_codes.py` — code scraping via r18 → avsox → javbus cascade, resumable from@@ -115,7 +117,8 @@ Runtime PIDs are observations, not configuration; always re-check them.## Next work-1. Add a Media Engine stream-plan endpoint and integrate hls.js or Shaka Player before enabling Stash HLS/DASH fallback in the browser.-2. Configure/evaluate Stash CommunityScrapers and metadata providers before writing another source adapter.-3. Add explicit feed configuration and reviewed import; only then use APScheduler. Add reviewed inference requests afterward, with AI output remaining candidates.-4. Move remaining legacy status/suggest/ledger application logic behind repository/application ports, then delete obsolete CLI surfaces.+1. Reconcile Claude Desktop transcript candidates through `creator-tags-review.csv` rather than direct writes.+2. Add a Media Engine stream-plan endpoint and integrate hls.js or Shaka Player before enabling Stash HLS/DASH fallback in the browser.+3. Configure/evaluate Stash CommunityScrapers and metadata providers before writing another source adapter.+4. Add explicit feed configuration and reviewed import; only then use APScheduler. Add reviewed inference requests afterward, with AI output remaining candidates.+5. Move remaining legacy status/suggest/ledger application logic behind repository/application ports, then delete obsolete CLI surfaces.diff --git a/migrations/0005_backfill_legacy_tags.sql b/migrations/0005_backfill_legacy_tags.sqlnew file mode 100644index 000000000..a2363d1dc--- /dev/null+++ b/migrations/0005_backfill_legacy_tags.sql@@ -0,0 +1,41 @@+-- 0002 只迁移了当时已有的 asset_tag;其后旧脚本继续写入的标签需要补入规范实体层。+-- 先暂停逐行 FTS 刷新,批量回填后按受影响资源重建一次,避免 O(关系数 x 聚合成本)。+DROP TRIGGER IF EXISTS asset_search_relation_insert;++INSERT OR IGNORE INTO entity(kind,canonical_name,normalized_name,created_at,updated_at)+SELECT CASE WHEN tag LIKE '演员:%' THEN 'performer' ELSE 'tag' END,+ CASE WHEN tag LIKE '演员:%' THEN trim(substr(tag,4)) ELSE trim(tag) END,+ lower(CASE WHEN tag LIKE '演员:%' THEN trim(substr(tag,4)) ELSE trim(tag) END),+ strftime('%Y-%m-%dT%H:%M:%fZ','now'),+ strftime('%Y-%m-%dT%H:%M:%fZ','now')+FROM asset_tag+WHERE trim(CASE WHEN tag LIKE '演员:%' THEN substr(tag,4) ELSE tag END)<>'';++INSERT OR IGNORE INTO asset_entity(asset_id,entity_id,role,source,confidence,+ metadata_json,first_seen_at,last_seen_at)+SELECT t.asset_id,e.id,+ CASE WHEN t.tag LIKE '演员:%' THEN 'performer' ELSE 'tag' END,+ COALESCE(t.source,'legacy:asset_tag'),COALESCE(t.confidence,1.0),+ '{"migration":"0005_backfill_legacy_tags"}',+ strftime('%Y-%m-%dT%H:%M:%fZ','now'),+ strftime('%Y-%m-%dT%H:%M:%fZ','now')+FROM asset_tag t+JOIN entity e ON e.kind=CASE WHEN t.tag LIKE '演员:%' THEN 'performer' ELSE 'tag' END+ AND e.normalized_name=lower(CASE WHEN t.tag LIKE '演员:%'+ THEN trim(substr(t.tag,4)) ELSE trim(t.tag) END)+WHERE trim(CASE WHEN t.tag LIKE '演员:%' THEN substr(t.tag,4) ELSE t.tag END)<>'';++DELETE FROM asset_search+WHERE asset_id IN (SELECT DISTINCT asset_id FROM asset_tag);++INSERT INTO asset_search(asset_id,name,code,entities,search_terms)+SELECT asset_id,name,code,entities,search_terms+FROM asset_search_source+WHERE asset_id IN (SELECT DISTINCT asset_id FROM asset_tag);++CREATE TRIGGER asset_search_relation_insert AFTER INSERT ON asset_entity BEGIN+ DELETE FROM asset_search WHERE asset_id=NEW.asset_id;+ INSERT INTO asset_search(asset_id,name,code,entities,search_terms)+ SELECT asset_id,name,code,entities,search_terms+ FROM asset_search_source WHERE asset_id=NEW.asset_id;+END;diff --git a/tests/test_migrations.py b/tests/test_migrations.pyindex a9add835c..cae778a40 100644--- a/tests/test_migrations.py+++ b/tests/test_migrations.py@@ -23,7 +23,8 @@ class MigrationTests(unittest.TestCase):sqlite3.connect(self.db).close()backup = self.root / "before.db"done = upgrade(self.db, MIGRATIONS, backup)- self.assertEqual([m.version for m in done], ["0000", "0001", "0002", "0003", "0004"])+ self.assertEqual([m.version for m in done],+ ["0000", "0001", "0002", "0003", "0004", "0005"])self.assertTrue(backup.exists())con = sqlite3.connect(self.db)tables = {row[0] for row in con.execute(@@ -38,7 +39,7 @@ class MigrationTests(unittest.TestCase):"entity_external_ref", "asset_entity", "entity_link","entity_search_term", "watch_queue", "asset_search","schema_migration"} <= tables)- self.assertEqual(versions, ["0000", "0001", "0002", "0003", "0004"])+ self.assertEqual(versions, ["0000", "0001", "0002", "0003", "0004", "0005"])self.assertEqual(upgrade(self.db, MIGRATIONS), [])self.assertEqual(plan(self.db, MIGRATIONS)[1], [])@@ -109,6 +110,43 @@ class MigrationTests(unittest.TestCase):('creator','creator','legacy:asset'),('series','series','legacy:asset')} <= relations)+ def test_late_legacy_tags_are_backfilled_by_0005(self):+ base_migrations = self.root / "base-migrations"+ base_migrations.mkdir()+ for name in (+ "0000_legacy_schema.sql", "0001_core_boundaries.sql",+ "0002_canonical_entities.sql", "0003_entity_pages_and_watch_queue.sql",+ "0004_asset_search_fts.sql",+ ):+ shutil.copyfile(MIGRATIONS / name, base_migrations / name)+ sqlite3.connect(self.db).close()+ upgrade(self.db, base_migrations)+ con = sqlite3.connect(self.db)+ con.executescript("""+ INSERT INTO asset(id,location,path,name,medium)+ VALUES(1,'local','late.mp4','late.mp4','video');+ INSERT INTO asset_tag(asset_id,tag,confidence,source)+ VALUES(1,'足交',0.6,'vision_creator'),+ (1,'演员:Late Performer',1.0,'stash:performer');+ """)+ con.close()+ upgrade(self.db, MIGRATIONS)+ con = sqlite3.connect(self.db)+ relations = set(con.execute(+ "SELECT e.kind,e.canonical_name,ae.role,ae.source,ae.confidence "+ "FROM asset_entity ae JOIN entity e ON e.id=ae.entity_id "+ "WHERE ae.asset_id=1"+ ))+ search_entities = con.execute(+ "SELECT entities FROM asset_search WHERE asset_id=1"+ ).fetchone()[0]+ con.close()+ self.assertIn(('tag', '足交', 'tag', 'vision_creator', 0.6), relations)+ self.assertIn(('performer', 'Late Performer', 'performer',+ 'stash:performer', 1.0), relations)+ self.assertIn('足交', search_entities)+ self.assertIn('Late Performer', search_entities)+def test_fts_tracks_asset_entity_alias_and_search_term_changes(self):sqlite3.connect(self.db).close()upgrade(self.db, MIGRATIONS)