Peach: Local-first video metadata scraper and media manager.
docs: 安装节以首次运行问答为主线,登记 peach scan 与问答复用点
longmeidaoc3d051aeac0d
diff --git a/README.en.md b/README.en.mdindex 54ad58832..e58b929b5 100644--- a/README.en.md+++ b/README.en.md@@ -100,18 +100,34 @@ Three steps, with no directories or configuration files to prepare in advance. R& .\.venv\Scripts\peach.exe init # macOS: ./.venv/bin/peach init```-`peach init` creates the data root, migrates the ledger to the latest schema, generates the local CA-and writes `<data root>/config.toml`. The default data root is `peach-data/` next to the repository;-`--data-root` changes it, and the `PEACH_DATA_ROOT` environment variable overrides it. After that,-`peach serve` starts the service; the listen address, port, media drive-letter mappings and-replication switches are all edited in that settings file, explained item by item in+Run without arguments, `peach init` asks five questions in the terminal; pressing Enter accepts the default shown in brackets:++| Question | Default |+| --- | --- |+| Data root (ledger, caches and the settings file live here) | `peach-data/` next to the repository |+| Local media directory (source `local`, must already exist) | `~\Videos` (`~/Movies` on macOS); required when that folder is missing |+| Listen scope: 1 = this machine only (127.0.0.1), 2 = LAN (0.0.0.0) | `1` |+| Service port | `8900` |+| LAN name (`<name>.local`, published only when listening on the LAN) | `peach` |++It then creates the data root, migrates the ledger to the latest schema, generates the local CA, writes+`<data root>/config.toml`, asks "scan <directory> now?" (default yes) to register that directory's files+in the ledger, and prints the next steps. The settings file declares only the one source you named; after+that `peach serve` starts the service and `peach scan local` rescans at any time. The listen address, port,+sources and replication switches are all edited in that settings file, explained item by item in[`docs/OPERATIONS.md`](docs/OPERATIONS.md). The tray is started with `peach-tray`, without arguments.+To skip the questions, pass arguments: `peach init --no-input` (or any single option such as `--data-root`,+`--port` or `--mount local=/mnt/media`) generates the file from the built-in defaults plus your arguments;+the same path is taken when stdin is not a terminal. A file written this way carries three example sources,+`local = R:\media`, `115 = B:/` and `pikpak = A:/`, which must be changed to your own paths under+`[media.locations]` and `[media.mounts]`; leaving them means every source is offline, not an error.+Four facts:- `-e` is a hard requirement: the wheel contains only the packages under `src/`, and the repository-root `migrations/` and `web/` are not in it, so under a non-editable install `peach init` fails outright because it cannot find the migrations directory.-- When `--data-root` points somewhere else, `peach serve` looks for the data root only via `PEACH_DATA_ROOT` and the `peach-data/` directories a few levels above the repository, so set `PEACH_DATA_ROOT` as well; the default data root needs no such step.-- The declared roots of the three sources in the settings file default to `local = R:\media`, `115 = B:/` and `pikpak = A:/`. These are example drive letters and must be changed to your own paths under `[media.locations]` and `[media.mounts]`; leaving them means every source is offline, not an error. CloudDrive is not required — any cloud drive that mounts as a local path works; 115 and PikPak are recommendations, not requirements.+- When the data root is not next to the repository, `peach serve` looks for it only via `PEACH_DATA_ROOT` and the `peach-data/` directories a few levels above the repository, so set `PEACH_DATA_ROOT` as well; the default data root needs no such step.+- Ledger paths are always in the Windows shape. On Windows the media directory goes straight into `[media.locations]`; on macOS the declared root is `R:\media` and the directory goes into `[media.mounts]`, where the local mount point does the translation. CloudDrive is not required — any cloud drive that mounts as a local path works; 115 and PikPak are recommendations, not requirements.- The interface is currently available in Chinese only.The service also starts without a settings file: `/healthz` reports `configured=false`, and the pages prompt you to run `peach init` first.diff --git a/README.md b/README.mdindex b9200d9c4..5e03d61aa 100644--- a/README.md+++ b/README.md@@ -96,16 +96,32 @@ peach-app/& .\.venv\Scripts\peach.exe init # macOS: ./.venv/bin/peach init```-`peach init` 建数据根、把账本迁到最新 schema、生成本机 CA,并写出 `<数据根>/config.toml`。-默认数据根是仓库同级的 `peach-data/`,`--data-root` 可改,环境变量 `PEACH_DATA_ROOT` 覆盖它。-之后 `peach serve` 就能起服务;监听地址、端口、媒体盘符映射和复制开关都在那个设置文件里改,-逐项说明见 [`docs/OPERATIONS.md`](docs/OPERATIONS.md)。托盘由 `peach-tray` 启动,不带参数。+不带参数的 `peach init` 在终端里问五个问题,每一题回车即接受方括号里的默认值:++| 问题 | 默认值 |+| --- | --- |+| 数据根(账本、缓存与设置文件都放这里) | 仓库同级的 `peach-data/` |+| 本地媒体目录(来源 `local`,必须已存在) | `~\Videos`(macOS 为 `~/Movies`),不存在则必填 |+| 监听范围:1 = 仅本机(127.0.0.1),2 = 局域网(0.0.0.0) | `1` |+| 服务端口 | `8900` |+| 局域网名字(`<名字>.local`,只在监听局域网时发布) | `peach` |++回答完它建数据根、把账本迁到最新 schema、生成本机 CA、写出 `<数据根>/config.toml`,然后问+「现在扫描 <目录>?」(默认是)把那个目录的文件登记进账本,最后打印下一步。设置文件里只有你+声明过的那一个来源;之后 `peach serve` 就能起服务,`peach scan local` 可以随时重扫。监听地址、+端口、来源与复制开关都在那个设置文件里改,逐项说明见 [`docs/OPERATIONS.md`](docs/OPERATIONS.md)。+托盘由 `peach-tray` 启动,不带参数。++不想问答就给参数:`peach init --no-input`(或任何一个参数,例如 `--data-root`、`--port`、+`--mount local=/mnt/media`)按内建默认与参数直接生成;stdin 不是终端时也走这条路。这条路写出的+设置文件带三个示例来源 `local = R:\media`、`115 = B:/`、`pikpak = A:/`,必须在 `[media.locations]`+与 `[media.mounts]` 里改成自己的路径,不改的结果是全部来源脱盘,而不是报错。四个事实:- `-e` 是硬性要求:wheel 只含 `src/` 下的包,仓库根的 `migrations/` 与 `web/` 不在里面,非可编辑安装下 `peach init` 找不到迁移目录会直接报错。-- `--data-root` 指到别处时,`peach serve` 只按 `PEACH_DATA_ROOT` 和仓库上方几层的 `peach-data/` 找数据根,所以要同时设 `PEACH_DATA_ROOT`;用默认数据根没有这一步。-- 设置文件里三个来源的声明根默认是 `local = R:\media`、`115 = B:/`、`pikpak = A:/`,这只是示例盘符,必须在 `[media.locations]` 与 `[media.mounts]` 里改成自己的路径;不改的结果是全部来源脱盘,而不是报错。CloudDrive 不是必需,任何能挂成本地路径的网盘都行;115 与 PikPak 是推荐项,不是要求。+- 数据根不在仓库同级时,`peach serve` 只按 `PEACH_DATA_ROOT` 和仓库上方几层的 `peach-data/` 找数据根,所以要同时设 `PEACH_DATA_ROOT`;用默认数据根没有这一步。+- 账本里的路径一律是 Windows 形态。Windows 上媒体目录直接写进 `[media.locations]`;macOS 上声明根写 `R:\media`、目录写进 `[media.mounts]`,由本机挂载点负责翻译。CloudDrive 不是必需,任何能挂成本地路径的网盘都行;115 与 PikPak 是推荐项,不是要求。- 界面目前只有中文。没有设置文件也能启动:`/healthz` 报 `configured=false`,页面提示先跑 `peach init`。diff --git a/docs/HANDOFF.md b/docs/HANDOFF.mdindex 6408a3757..706911f54 100644--- a/docs/HANDOFF.md+++ b/docs/HANDOFF.md@@ -133,7 +133,7 @@ React 渲染的规格页、用户截图这类给不出可重抓字节的实测- 「同步开发进度」(GitHub)和「同步 Ledger」(SMB 共享)是两条独立通道,任一方不可达都不该拖住另一方;服务只观察角色不自动复制。- 两台机器可以同时跑服务,但同时写入会很快冲突转只读;「接管 Ledger 写入」的短路与拒绝条件见 OPERATIONS。- `src/peach/__init__.py::__version__` 是版本唯一来源;自动更新只做 `merge --ff-only`,不 stash、不 rebase、不 `--force`,工作区脏或两边分叉就原样报出来交给人——并行工作树和主检出共用同一个对象库。-- 本机坐标在 `<数据根>/config.toml`(环境变量 > 它 > 内建默认),`src/peach/` 不写死本机字面量或家庭 IP;现有部署各跑一次 `peach init --from-existing`。`[media.mounts]` 按 `asset.location` 给本机落点,Windows 上整表为空;`replication.enabled` 默认关,关掉即整条复制链路不装配,`/healthz` 报 `disabled`。+- 本机坐标在 `<数据根>/config.toml`(环境变量 > 它 > 内建默认),`src/peach/` 不写死本机字面量或家庭 IP。`[media.mounts]` 按 `asset.location` 给本机落点,Windows 上整表为空;`replication.enabled` 默认关,关掉即整条复制链路不装配。首次运行问答与扫描是 `peach.onboarding`/`peach.scan` 的纯逻辑,CLI 与托盘设置页共用。- `.local` 用本机 CA 而不是 Let's Encrypt,证书与私钥留在本机 `peach-data/secrets` 且按设计不跨机共享;FastAPI 是唯一 Web server,探测本机服务必须绕过系统代理,否则代理会替服务回 503。- 网盘目录整理后必须经「管理 → 资源同步」显式对账,不做后台静默删除;源文件缺失的 asset 和垃圾文件候选都只能先进回收站,清空回收站才永久删除账本行。- 长任务只停止自己拥有且命令行匹配的 Python/FFmpeg 进程树,禁止全机终止 FFmpeg;转码只写缓存,永不改写原媒体。diff --git a/docs/OPERATIONS.md b/docs/OPERATIONS.mdindex a42743f8a..6feece80c 100644--- a/docs/OPERATIONS.md+++ b/docs/OPERATIONS.md@@ -9,10 +9,24 @@- 设置文件固定是 `<数据根>/config.toml`。数据根按三步找:环境变量 `PEACH_DATA_ROOT`、项目根同级(含上溯四层,覆盖主检出、`peach-worktrees/<任务>` 和打包后的 `dist/Peach/_internal`)的 `peach-data/`、都没有就是「未配置」。优先级是环境变量 > 设置文件 > 内建默认。-- 全新机器只跑 `peach init`:建齐 `database`/`generated`/`sources`/`state`/`secrets`/- `logs`/`tools`/`review` 八个目录、把账本迁到最新 schema、生成本机 CA、写出设置文件,- 最后打印下一步。可用 `--data-root`/`--host`/`--port`/`--mdns-name`/- `--mount local=/mnt/media` 预置值;已有账本不会被重建,它会提示改用 `--from-existing`。+- 全新机器只跑 `peach init`。不带参数且 stdin 是终端时进问答(题目、默认值与落盘逻辑在+ `src/peach/onboarding.py`,托盘设置页复用同一组函数):问数据根、一个已存在的本地媒体+ 目录、监听范围(仅本机/局域网)、端口、局域网名字,每题回车取默认,连续三次无效即退出且+ 不写任何文件。然后建齐 `database`/`generated`/`sources`/`state`/`secrets`/`logs`/+ `tools`/`review` 八个目录、把账本迁到最新 schema、生成本机 CA、写出设置文件,问一句+ 「现在扫描 <目录>?」(默认是)调 `peach.scan.scan_location` 登记文件,最后打印下一步与+ 扫描摘要。写出的 `[media.locations]` 只有 `local`:Windows 上直接是那个目录、+ `[media.mounts]` 为空;macOS 上声明根是 `R:\media`、目录写进 `[media.mounts] local`。+ 复制、writer 镜像、SMB 一律不问,保持关闭或留空。+- 给了任何参数、加了 `--no-input`、或 stdin 不是终端,`peach init` 走非交互路径:按内建默认+ 与 `--data-root`/`--host`/`--port`/`--mdns-name`/`--mount local=/mnt/media` 直接生成,+ 写出的文件带 `local`/`115`/`pikpak` 三个示例声明根。已有账本不会被重建,它会提示改用+ `--from-existing`。+- `peach scan <来源ID> [根目录]` 把一个目录的文件元数据 upsert 进账本,只新增行与刷新+ `size`/`mtime`/`last_seen`,不改真相字段、不删行。根目录省略时取该来源在+ `[media.locations]` 的声明根,本机目录按 `[media.mounts]` 取;给了目录则必须落在声明根+ (macOS 上是挂载点)之内,否则拒绝——写进去的行否则翻译不回本机路径。+ `scripts/ledger.py scan` 是同一实现的薄委托。- 已经在跑的机器用 `peach init --from-existing`:只写设置文件,不建库、不动 `peach-data/`下任何现有文件。它把当前实际生效的配置原样落盘,猜不出来的坐标(局域网 writer 地址、SMB 主机与账号)留空并逐条打印出来,用 `--writer-origin`/`--smb-host`/`--smb-user`diff --git a/docs/PRODUCT_BACKLOG.md b/docs/PRODUCT_BACKLOG.mdindex cc15eb07f..a92ac17d1 100644--- a/docs/PRODUCT_BACKLOG.md+++ b/docs/PRODUCT_BACKLOG.md@@ -23,7 +23,7 @@8. 开源通用化的发布准备(ADR-0023 第 4 阶段):清扫 `docs/` 与 `.claude/skills/` 里的局域网地址、主机名、账号名、备份文件名与个人目录,把只对一台机器成立的运行态移出仓库,并把 `tests/test_repo_hygiene.py` 的个人字面量门槛从 `src/peach/` 扩到文档与技能。许可证、贡献与安全说明、issue/PR 模板在仓库里;设置层、来源挂载点 ID 与可整体关闭的复制链路在 Windows 生效,macOS 待跑 `peach init --from-existing --mount local=<落点>`。9. 女优高清头像的写入侧:`scripts/audit_performer_portraits.py` 已能出候选与实测证据,仍缺按复核结果复制头像文件那一步,以及实体合并后孤立头像的 relink(如 `8022 <- 8168`:只有旧 ID 的 provenance 名唯一命中当前实体、当前目标又不存在时才算候选,不覆盖、不删除旧文件)。10. 文件名与网盘目录整理的落地:`scripts/clean_names.py` 与目录计划只出 dry-run CSV。真正改名要独立维护窗口——停同类任务、确认本机是 writer、SQLite backup、逐条同目录 rename 并同步账本 path/name、失败时文件名回滚,最后跑完整性、外键与路径存在性检查;不跨盘移动,也不按文件夹名猜创作者。-11. 来源与默认值通用化(ADR-0023 第 5 阶段候选):`DEFAULT_LOCATION_ROOTS` 写死的 `R:\media`、`B:/`、`A:/` 是维护者自己的盘符,陌生用户不改设置文件就是全部来源脱盘。要做三件事:`peach init` 按本机实际路径生成 `[media.locations]` 声明根;来源用「本地 / 远端挂载」类型字段代替代码里按 `local`/`115`/`pikpak` 名字点名(`web_resource_sync.py` 的 SQL、`media.py` 的 HLS 规则);复制链路支持 win↔win、mac↔mac 与任意一台当写者,目前只验证过 Windows 写者 + macOS 读者。+11. 来源与默认值通用化(ADR-0023 第 5 阶段候选):`peach init` 的问答已按本机路径只声明 `local`,非交互路径写出的 `DEFAULT_LOCATION_ROOTS`(`R:\media`、`B:/`、`A:/`)仍是维护者的示例盘符。剩两件事:来源用「本地 / 远端挂载」类型字段代替代码里按 `local`/`115`/`pikpak` 名字点名(`web_resource_sync.py` 的 SQL、`media.py` 的 HLS 规则);复制链路支持 win↔win、mac↔mac 与任意一台当写者,目前只验证过 Windows 写者 + macOS 读者。12. `pip install .`(非 editable)可用:wheel 只含 `src/` 下的包,`migrations/` 与 `web/` 留在仓库根,非可编辑安装下 `migrations.discover()` 抛 `FileNotFoundError`。把这两个目录做成 package data,并让 `PROJECT_ROOT` 的解析在 site-packages 里也成立。13. `/healthz` 的 `db` 判据改为「`schema_migration` 有行」:目前只看文件存在,空账本也报 available。14. 界面国际化:界面目前只有中文,先补英文。diff --git a/docs/adr/0023-generic-distribution-roadmap.md b/docs/adr/0023-generic-distribution-roadmap.mdindex 852a6cf09..8b120ed8b 100644--- a/docs/adr/0023-generic-distribution-roadmap.md+++ b/docs/adr/0023-generic-distribution-roadmap.md@@ -22,6 +22,7 @@ Peach 要发布到 GitHub 供所有人维护与使用。使用形态不变:每1. **配置层与首次运行**- 新增 `peach-data/config.toml`(或同等设置文件)承载数据根、媒体根、监听地址、代理、复制开关;环境变量继续作为覆盖,`config.py` 只保留读取与校验逻辑,不再含个人路径与主机名。- 新增 `peach init` 子命令:创建数据目录、跑迁移、生成设置文件与自签 CA,并输出下一步。+ - 不带参数的 `peach init` 在终端里问答(数据根、一个本地媒体目录、监听范围、端口、局域网名字),写出只声明 `local` 的设置文件并可选地首次扫描;问答逻辑在 `peach.onboarding`,托盘设置页复用(2026-09-04 落地)。- 「未配置」是明确状态:服务能启动并在页面提示去设置,而不是因缺目录崩掉。2. **来源挂载点取代盘符**