From 28c712868661d3f9aec7bb2ccc6a844fe1856cd3 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 03:12:23 +0800 Subject: [PATCH 01/14] Lighter install, a short last screen, and a word before the local voice's first download Measured on a clean Mac: 71 of the install's 90 s and 305 MB were the reference repos, which a first film does not use; the install ended with a 60-line doctor report that said ready even when uv or a render browser was missing (Linux); the local voice's first use downloaded about 2.5 GB without a word. - install.sh fetches the reference repos only with --refs; references/fetch.sh says what it fetches and how big first (a size table in the script, checked by CI), and an unknown name exits 2. - bin/vh doctor --first: ready for a first film or not, what is missing and how to get it, how a voice comes here; the installer ends with it, the skills step says one line, the example sentence is the README's silent one. - bin/vh tts: before the local voice's first download, one line with the size, the time it may take and the way around it (--provider edge); uv's download lines shown, the model's progress every 10 s. The default provider is set in tts.py alone (DEFAULT_PROVIDER). - README, homepage: the sizes measured. --- README.md | 8 ++--- README.zh-CN.md | 8 ++--- bin/vh | 11 +++++-- changes/first-run.md | 7 +++++ docs/site/index.html | 2 +- install.sh | 61 ++++++++++++++++++++----------------- references/fetch.sh | 30 ++++++++++++++++--- tools/audio/tts.py | 71 ++++++++++++++++++++++++++++++++++++++++---- tools/ci.sh | 38 ++++++++++++++++++++++++ tools/commands.json | 8 +++-- tools/doctor.py | 63 ++++++++++++++++++++++++++++++++++----- 11 files changed, 246 insertions(+), 61 deletions(-) create mode 100644 changes/first-run.md diff --git a/README.md b/README.md index 9035a877..187520f3 100644 --- a/README.md +++ b/README.md @@ -410,20 +410,20 @@ For finer control, name what you want to decide yourself: the hook, the look, th ## Install options and updates -By default the installer registers the skills for both agents and fetches 37 read-only reference repos. It uses about 650 MB on disk, or 380 MB with `--no-refs`. The Studio app uses about 380 MB more, including its cached installer. +By default the installer registers the skills for both agents and uses about 400 MB on disk. The 37 read-only reference repos agents can read are not fetched then: an agent fetches the one a doc points to when it first needs it, saying its size first; `--refs` fetches them all now (about 300 MB more). The Studio app uses about 380 MB more, including its cached installer. ```bash bash install.sh --dir ~/code/OpenVideoHarness # install somewhere else -bash install.sh --no-refs # skip the reference repos for now (references/fetch.sh later) +bash install.sh --refs # fetch all 37 reference repos now (about 300 MB) bash install.sh --no-skill # don't register the global skill bash install.sh --no-icon # leave OVH Studio out of your applications (bin/vh studio --install-icon adds it later) ``` -- Nothing asks a question. On macOS and on a Linux desktop the installer puts OVH Studio, Studio's own window, in your applications (Electron: about 130 MB downloaded once, 260 MB on disk); when a step fails it says what to do next in one sentence. It ends with the two ways to start: click OVH Studio, or open Claude Code or Codex in the folder and say what film you want. +- Nothing asks a question. On macOS and on a Linux desktop the installer puts OVH Studio, Studio's own window, in your applications (Electron: about 130 MB downloaded once, 260 MB on disk); when a step fails it says what to do next in one sentence. It ends with a few lines: ready for a first film or not, what it still needs and how to get it, how a voice comes on this machine, and the two ways to start: click OVH Studio, or open Claude Code or Codex in the folder and say what film you want (`bin/vh doctor` has the full report). - The installer fetches only the newest commit: the repo itself is about 95 MB to download and 200 MB on disk, before its packages and the reference repos. To contribute or browse the history, `git clone` normally and run `bin/vh setup`. - To update, run the installer again with the same options (or `git pull`); `LOCAL.md` and `projects/` are left alone, and it stops before overwriting files you changed. The installed skills are short stubs that read `skills/` in the clone, so they follow the update; `bin/vh doctor` says in the rare case one needs `bin/vh install-skill` again. - The showcase videos aren't in git; to rebuild a showcase locally, `tools/fetch_media.sh` downloads them from the release to where its scripts expect them. -- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, Python packages up to about 1.5 GB, and the default local voice's model about 2 GB (measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). If npm, PyPI, Hugging Face or Google Fonts are blocked or slow where you are, [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) has the mirror settings. +- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, Python packages up to about 1.5 GB, and the default local voice about 2.5 GB, its model and packages, which `bin/vh tts` says before it starts, showing the progress (`--provider edge` downloads nothing; measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). If npm, PyPI, Hugging Face or Google Fonts are blocked or slow where you are, [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) has the mirror settings. Skill only: `npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`. It's a pointer: on first use it asks before installing the full workbench. That copy stays as it was when the repo changes; once the workbench is installed, `bin/vh install-skill` replaces it with a stub that follows the clone. diff --git a/README.zh-CN.md b/README.zh-CN.md index d417878d..dbb778d2 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -410,20 +410,20 @@ AI 听不见,所以声音尽量做成能计算、能测量的。 ## 安装、更新和国内网络 -默认给两个 agent 注册 skill,并拉取 37 个只读参考仓库。合计约占 650 MB,用 `--no-refs` 安装约占 380 MB。Studio 应用另占约 380 MB,含缓存的安装包。 +默认给两个 agent 注册 skill,约占 400 MB。37 个只读参考仓库安装时不拉:agent 用到文档指的那一个时再拉,拉之前先说多大;`--refs` 在安装时一次拉全(再约 300 MB)。Studio 应用另占约 380 MB,含缓存的安装包。 ```bash bash install.sh --dir ~/code/OpenVideoHarness # 装到别的位置 -bash install.sh --no-refs # 先不拉参考仓库(之后用 references/fetch.sh 拉) +bash install.sh --refs # 安装时就把 37 个参考仓库拉全(约 300 MB) bash install.sh --no-skill # 不注册全局 skill bash install.sh --no-icon # 不把 OVH Studio 放进应用程序(以后 bin/vh studio --install-icon 再放) ``` -- 安装时什么都不问。macOS 和 Linux 桌面上,它会把 OVH Studio(Studio 自己的窗口)放进应用程序(Electron:第一次下载约 130 MB,占约 260 MB 磁盘);哪一步没成,它用一句话说接下来做什么。最后告诉你两种开始的办法:点 OVH Studio,或者在这个文件夹里打开 Claude Code 或 Codex,说你想做什么片子。 +- 安装时什么都不问。macOS 和 Linux 桌面上,它会把 OVH Studio(Studio 自己的窗口)放进应用程序(Electron:第一次下载约 130 MB,占约 260 MB 磁盘);哪一步没成,它用一句话说接下来做什么。最后几行说清这台机器能不能做第一支片、还缺什么、怎么补,配音在这台机器上怎么来,以及两种开始的办法:点 OVH Studio,或者在这个文件夹里打开 Claude Code 或 Codex,说你想做什么片子(完整的报告在 `bin/vh doctor`)。 - 安装脚本只拉最新的一个提交,仓库本身下载约 95 MB、占约 200 MB 磁盘,依赖和参考仓库另算;想参与贡献或翻历史,就正常 `git clone`,再运行 `bin/vh setup`。 - 更新:用同样的参数再运行一次安装命令(或者 `git pull`);`LOCAL.md` 和 `projects/` 不动,要覆盖你改过的文件时会先停下来。装出去的 skill 是指回克隆里 `skills/` 的短桩,跟着一起更新;少数要重装的时候(`bin/vh install-skill`),`bin/vh doctor` 会说。 - 样片的视频不在 git 里,要在本地复现样片时运行 `tools/fetch_media.sh`,它从 Release 下载到脚本要的位置。 -- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,Python 依赖最多约 1.5 GB,默认的本地配音模型约 2 GB(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络连不上 npm、PyPI、Hugging Face 或 Google Fonts 时,镜像设置见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 +- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,Python 依赖最多约 1.5 GB,默认的本地配音约 2.5 GB(模型加它的依赖;`bin/vh tts` 开始前会先说,并显示进度;`--provider edge` 什么都不下)(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络连不上 npm、PyPI、Hugging Face 或 Google Fonts 时,镜像设置见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 只装 skill:`npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`。它只是一个指针,第一次用时会征得你同意,再把完整的工作台装好。这样装的是整份副本,仓库更新了它不变;工作台装好以后跑一次 `bin/vh install-skill`,换成跟随克隆的短桩。 diff --git a/bin/vh b/bin/vh index 9728dea0..a9321046 100755 --- a/bin/vh +++ b/bin/vh @@ -61,7 +61,7 @@ cmd_doctor() { local a skip="" live="" rec="" for a in "$@"; do # a usage error is said at once (by doctor.py), before the probe below if [ -n "$skip" ]; then skip=""; continue; fi - case "$a" in -h|--help) exec python3 "$ROOT/tools/doctor.py" -h ;; --json|--fill-local|--only=*) ;; --only) skip=1 ;; --probe) live=1 ;; --offline=*) rec=1 ;; --offline) rec=1 skip=1 ;; + case "$a" in -h|--help) exec python3 "$ROOT/tools/doctor.py" -h ;; --json|--fill-local|--first|--only=*) ;; --only) skip=1 ;; --probe) live=1 ;; --offline=*) rec=1 ;; --offline) rec=1 skip=1 ;; *) exec python3 "$ROOT/tools/doctor.py" "$@" ;; esac done [ -z "$rec" ] || [ -n "$live" ] || exec python3 "$ROOT/tools/doctor.py" "$@" @@ -1299,7 +1299,8 @@ cmd_tts() { [ -d "$proj" ] || { echo "$c_no bin/vh tts: no such project: $proj" >&2; exit 2; } # before uv builds an environment; tts.py would make the folder shift while [ $# -gt 0 ] && [ ${#pos[@]} -lt 4 ] && [[ "$1" != --* ]]; do pos+=("$1"); shift; done # positionals stop at the first --flag - local prov=${pos[0]:-qwen} voice=${pos[1]:-} lang=${pos[2]:-} instruct=${pos[3]:-} a prev="" np="" + local prov=${pos[0]:-} voice=${pos[1]:-} lang=${pos[2]:-} instruct=${pos[3]:-} a prev="" np="" quiet=-q fresh="" + [ -n "$prov" ] || prov=$(python3 "$ROOT/tools/audio/tts.py" --default-provider) # tts.py's DEFAULT_PROVIDER, the one place it is set for a in "$@"; do # tts.py's own --provider X / --provider=X picks the dependencies too; the last one wins, as in argparse [ "$prev" = --provider ] && prov=$a case "$a" in --provider=*) prov=${a#--provider=} ;; --candidates|--candidates=*) np="--with numpy" ;; --align=local) np="$np --with mlx-whisper" ;; esac # the takes are measured with numpy @@ -1311,7 +1312,11 @@ cmd_tts() { case "$prov" in qwen) deps="--with mlx-audio" ;; edge) deps="--with edge-tts" ;; dashscope) [ -z "${DASHSCOPE_API_KEY:-}" ] || deps="--with dashscope" ;; esac # no key: tts.py says so, with no package fetched first deps="$deps${np:+ $np}" - on_ctrl_c uv run -q --no-project $deps python "$ROOT/tools/audio/tts.py" "$proj" --provider "$prov" ${lang:+--lang "$lang"} ${voice:+--voice "$voice"} ${instruct:+--instruct "$instruct"} "$@" + # the local voice's first use downloads gigabytes: said first in one line (how much, how long, the way around it), and + # uv's own download lines shown instead of quieted (tts.py adds the model's progress) + if [ "$prov" = qwen ] && command -v uv >/dev/null 2>&1 && ! uv run -q --no-project --offline $deps python -c "" >/dev/null 2>&1; then quiet=""; fresh=--packages-missing; fi + [ "$prov" != qwen ] || python3 "$ROOT/tools/audio/tts.py" --first-use qwen $fresh + on_ctrl_c uv run $quiet --no-project $deps python "$ROOT/tools/audio/tts.py" "$proj" --provider "$prov" ${lang:+--lang "$lang"} ${voice:+--voice "$voice"} ${instruct:+--instruct "$instruct"} "$@" } cmd_voices() { # audition measures the takes (numpy) and synthesizes with the provider's own packages, through uv [ $# -gt 0 ] || set -- list diff --git a/changes/first-run.md b/changes/first-run.md new file mode 100644 index 00000000..e22c5b0b --- /dev/null +++ b/changes/first-run.md @@ -0,0 +1,7 @@ +**安装更轻,最后一屏只说第一支片要知道的事;本地配音第一次下载前先说** +- Why: 在干净的机器上量过,安装 90 秒里有 71 秒、305 MB 在拉参考仓库,而第一支片用不到它们;安装最后一屏是 60 多行 doctor,十几行黄色提示大多和第一支片无关,Linux 上真挡路的缺项淹在里面,最后照样说"ready";本地配音第一次用要静默下载约 2.5 GB。 +- 37 个参考仓库安装时不再拉:agent 用到文档指的那一个时再拉,`references/fetch.sh <目录>` 拉之前用一行说清拉什么、从哪、多大(大小表在脚本里,CI 查每一个都有);名字写错时说清并退出 2。`install.sh --refs` 一次拉全;`--no-refs` 照旧认,现在就是默认。之前拉过的留着不动。 +- 安装最后几行换成 `bin/vh doctor --first`:能不能做第一支片,缺什么、一句怎么补(Node、FFmpeg、Python、uv、能渲染的浏览器、一个 agent),Linux 上缺中文字体也说,配音在这台机器上怎么来;有缺的就不说 ready。完整报告照旧是 `bin/vh doctor`。skill 注册只说一行。示例句换成 README 那条无声 15 秒。 +- `bin/vh tts` 用本地配音、第一次要下载时,先说一行:约多大、大概多久、显示进度,以及不用下载的办法(`--provider edge`,免费,在线:稿子会发到微软的配音服务);Python 包的下载逐个显示,模型下载每 10 秒说一次下了多少。默认配音只在 `tools/audio/tts.py` 的 `DEFAULT_PROVIDER` 一处设,`bin/vh tts` 问它。 +- doctor 找本地配音模型时也看 `XDG_CACHE_HOME`(Hugging Face 自己就这样找)。 +- README 中英文和官网的安装大小按实测更新:安装约 400 MB,`--refs` 再约 300 MB,本地配音约 2.5 GB。 diff --git a/docs/site/index.html b/docs/site/index.html index 13f1f8af..5898ddea 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -866,7 +866,7 @@

Compare the revision同一段改完
Quick draft: make a silent 15-second vertical explainer showing why doubling a square’s side length quadruples its area. Use a grid and on-screen text.快速出一版 15 秒的竖屏无声科普,用方格和画面文字讲清楚为什么正方形边长翻倍,面积变成四倍。
-

Needs Git, Node.js 22+, Chrome, FFmpeg, Python 3 with uv, and Claude Code or Codex. About 650 MB on disk including 37 read-only reference repos. Step-by-step guide · China network需要 Git、Node.js ≥ 22、Chrome、FFmpeg、Python 3 和 uv,以及 Claude Code 或 Codex。连同 37 个只读参考仓库,约占 650 MB。分步教程 · 国内网络

+

Needs Git, Node.js 22+, Chrome, FFmpeg, Python 3 with uv, and Claude Code or Codex. About 400 MB on disk; the 37 read-only reference repos come when an agent first needs one. Step-by-step guide · China network需要 Git、Node.js ≥ 22、Chrome、FFmpeg、Python 3 和 uv,以及 Claude Code 或 Codex。约占 400 MB;37 个只读参考仓库等 agent 用到时再拉。分步教程 · 国内网络

Review stops for standard and studio标准档和精品档怎么审

diff --git a/install.sh b/install.sh index 6598d988..8a32c32f 100755 --- a/install.sh +++ b/install.sh @@ -1,19 +1,21 @@ #!/usr/bin/env bash # OpenVideoHarness one-line installer. # curl -fsSL https://raw.githubusercontent.com/ZLHad/OpenVideoHarness/main/install.sh | bash -# bash install.sh [--dir ~/OpenVideoHarness] [--no-refs] [--no-skill] [--skill claude|codex|all] [--obscura] [--icon | --no-icon] +# bash install.sh [--dir ~/OpenVideoHarness] [--refs] [--no-skill] [--skill claude|codex|all] [--obscura] [--icon | --no-icon] # What it does, and where it puts things: # 1. clone the repo into --dir, newest commit only (about 200 MB on disk; a re-run moves it to the newest commit, keeping LOCAL.md and projects/) -# 2. npm install in engines/ClaudeAnimationBase and npm ci in styles/_swatch (HyperFrames 0.8.202), both inside --dir (about 210 MB of -# node_modules; npm also writes its own cache, ~/.npm); unless --no-refs, fetch the read-only reference repos references/fetch.sh lists -# into references/repos/ (about 250 MB, git-ignored; references/fetch.sh fetches one later) +# 2. npm install in engines/ClaudeAnimationBase and npm ci in styles/_swatch (HyperFrames 0.8.202), both inside --dir (about 180 MB of +# node_modules; npm also writes its own cache, ~/.npm). The read-only reference repos references/fetch.sh lists are not fetched: +# an agent fetches the one a doc points to when it first needs it (bash references/fetch.sh , which says its size first); +# --refs fetches them all now into references/repos/ (about 300 MB, git-ignored; --no-refs, the old way to skip them, is the default) # 3. copy LOCAL.example.md to LOCAL.md (git-ignored) if there is no LOCAL.md # 4. unless --no-skill, write the skills (skills/*: open-video-harness, open-video-harness-web) to ~/.claude/skills and # ~/.agents/skills (--skill claude|codex: only one): short stubs that read skills/ in --dir, so a re-run or git pull updates them # 4b. with --obscura, bin/vh web install: the pinned Obscura release (a headless browser, about 70 MB from its GitHub releases) # into ~/.local/share/ovh/obscura, linked from ~/.local/bin; bin/vh web checks facts against web pages with it -# 5. run bin/vh doctor --fill-local as a final check: it also writes LOCAL.md's machine lines (硬件, 已装工具, 已装引擎) -# where they still hold the template, never a line you wrote +# 5. run bin/vh doctor --fill-local --first as the last lines: ready for a first film or not, what it still needs and how to get it, +# how a voice comes on this machine (the full report: bin/vh doctor); it also writes LOCAL.md's machine lines (硬件, 已装工具, +# 已装引擎) where they still hold the template, never a line you wrote # 6. put OVH Studio, Studio's own window, in your applications (macOS: ~/Applications/OVH Studio.app; a Linux desktop: a # desktop entry in ~/.local/share/applications): Electron, about 130 MB downloaded once and 260 MB on disk (without npm or # a network, a small launcher that opens a browser's window instead). No question. A run again leaves it alone when it is @@ -25,16 +27,16 @@ # - the first hyperframes render: HyperFrames' own chrome-headless-shell (about 200 MB, ~/.cache/hyperframes) # - the first bin/vh beats, music, sfx, qa or sheet: their Python packages, through uv (about 700 MB, ~/.cache/uv) # - the first bin/vh tts with the default qwen provider (skipped with another one): its Python packages (about 750 MB, ~/.cache/uv) -# and the Qwen3-TTS model (about 2 GB, ~/.cache/huggingface) +# and the Qwen3-TTS model (1.8 GB, ~/.cache/huggingface); bin/vh tts says so before it starts and shows the progress # - every bin/vh new short, promo, data or meme: about 140 MB of node_modules in that project # The wiki's Getting Started ("What gets downloaded") has the same list. set -euo pipefail REPO="${OVH_REPO:-https://github.com/ZLHad/OpenVideoHarness.git}" -DIR="${OVH_DIR:-$HOME/OpenVideoHarness}"; REFS=1; SKILL=all; OBSCURA=0; ICON=default +DIR="${OVH_DIR:-$HOME/OpenVideoHarness}"; REFS=0; SKILL=all; OBSCURA=0; ICON=default while [ $# -gt 0 ]; do case "$1" in - --dir) DIR="$2"; shift 2 ;; --no-refs) REFS=0; shift ;; --no-skill) SKILL=none; shift ;; --skill) SKILL="${2:?--skill needs claude|codex|all|none}"; shift 2 ;; --obscura) OBSCURA=1; shift ;; + --dir) DIR="$2"; shift 2 ;; --refs) REFS=1; shift ;; --no-refs) REFS=0; shift ;; --no-skill) SKILL=none; shift ;; --skill) SKILL="${2:?--skill needs claude|codex|all|none}"; shift 2 ;; --obscura) OBSCURA=1; shift ;; --icon) ICON=yes; shift ;; --no-icon) ICON=no; shift ;; - -h|--help) sed -n '2,30p' "$0"; exit 0 ;; *) echo "unknown option: $1"; exit 1 ;; esac; done + -h|--help) sed -n '2,32p' "$0"; exit 0 ;; *) echo "unknown option: $1"; exit 1 ;; esac; done case "$SKILL" in claude|codex|all|none) ;; *) echo "unknown --skill '$SKILL' (claude|codex|all|none)"; exit 1 ;; esac say() { printf '\033[1m→ %s\033[0m\n' "$*"; } NOAPP="${XDG_DATA_HOME:-$HOME/.local/share}/ovh-studio/no-app" # --no-icon once: kept here, so an update leaves OVH Studio out too (--icon clears it) @@ -98,30 +100,33 @@ else say "cloning into $DIR (newest commit only)" cd "$DIR" say "installing the bundled engine (ClaudeAnimationBase)" (cd engines/ClaudeAnimationBase && npm install --silent) || echo "! the hand-drawn engine's packages did not install; running this installer again finishes them" -if [ "$REFS" = 1 ]; then n=$(grep -cE '^(full|sparse|textonly) ' references/fetch.sh || true) # counted from the list, so it cannot go stale - say "fetching $n reference repos (about 250 MB, read-only, git-ignored; --no-refs skips them)" - references/fetch.sh || echo "! some reference repos were not fetched; bash references/fetch.sh fetches them later"; fi +n=$(grep -cE '^(full|sparse|textonly) ' references/fetch.sh || true) # counted from the list, so it cannot go stale +if [ "$REFS" = 1 ]; then + say "fetching $n reference repos (about 300 MB, read-only, git-ignored)" + references/fetch.sh || echo "! some reference repos were not fetched; bash references/fetch.sh fetches them later" +else had=$(find references/repos -mindepth 2 -maxdepth 2 -name .git 2>/dev/null | wc -l | tr -d ' ') + if [ "${had:-0}" -gt 0 ]; then echo " the $had reference repos fetched before stay as they are (--refs updates them and fetches the rest)"; fi +fi say "installing the renderer for style samples (HyperFrames, for bin/vh style)" (cd styles/_swatch && npm ci --silent) || echo "! the renderer for style samples did not install; it is tried again the first time a style sample is made" [ -f LOCAL.md ] || cp LOCAL.example.md LOCAL.md -[ "$SKILL" = none ] || { say "telling Claude Code and Codex where this workbench is (skills)"; bin/vh install-skill "$SKILL" || echo "! the skills were not registered; bin/vh install-skill $SKILL registers them"; } +if [ "$SKILL" != none ]; then # one line for the stubs it wrote (each says where it went when run by hand: bin/vh install-skill) + say "telling Claude Code and Codex where this workbench is (skills)" + if out=$(bin/vh install-skill "$SKILL" 2>&1); then + echo " $(printf '%s\n' "$out" | grep -c 'skill →') skill stubs written; restart Claude Code or Codex if it is open, so it sees them" + else printf '%s\n' "$out"; echo "! the skills were not registered; bin/vh install-skill $SKILL registers them"; fi +fi [ "$OBSCURA" = 0 ] || { say "installing Obscura (an optional page reader that bin/vh web can use to keep web pages for fact checks)"; bin/vh web install || echo "! Obscura not installed; bin/vh web install retries it"; } -say "final check (and this machine's lines in LOCAL.md)"; bin/vh doctor --fill-local || true ICON_LATER=""; ICON_DONE=""; ICON_HEADLESS=""; put_icon -arm="" # Linux arm64: HyperFrames has no Chrome of its own there (engines/README.md, its notes), so a missing browser is said again below -if [ "$(uname -s)" = Linux ]; then case "$(uname -m)" in aarch64|arm64) - bin/vh doctor --json 2>/dev/null | python3 -c 'import json, sys; sys.exit(0 if any(c["name"] == "browser" and c["state"] == "ok" for c in json.load(sys.stdin)["checks"]) else 1)' 2>/dev/null || arm=1 ;; esac; fi -cat </, bash references/fetch.sh fetches that one" -[ -z "$arm" ] || echo " ! Linux arm64: no browser yet, and HyperFrames has none of its own here; set one up before the first render (engines/README.md, \"Linux:渲染前要先备好的三样\")" echo -echo "✓ OpenVideoHarness is ready at $DIR. Two ways to start:" +# the last lines: ready for a first film or not, what it still needs, how a voice comes here (the full report: bin/vh doctor) +READY=""; bin/vh doctor --fill-local --first && READY=1 +echo +if [ -n "$READY" ]; then echo "✓ OpenVideoHarness is ready at $DIR. Two ways to start:" +else echo "✗ OpenVideoHarness is installed at $DIR; a first film still needs what is listed above. Then, two ways to start:"; fi if [ -n "$ICON_DONE" ]; then echo " 1. Click OVH Studio in your applications: your films, their stops and the agent, in one window." elif [ -n "$ICON_HEADLESS" ]; then echo " 1. Studio, in a browser on another computer: cd \"$DIR\" && bin/vh studio --print-address (this machine has no desktop)" else echo " 1. Studio, your films in one window: cd \"$DIR\" && bin/vh studio$([ -z "$ICON_LATER" ] || printf ' (bin/vh studio --install-icon puts it in your applications)')"; fi -echo " 2. Open Claude Code or Codex in that folder (cd \"$DIR\" && claude) and say what film you want, e.g. \"做一个 30 秒的竖屏科普:为什么低轨卫星的信号会变调\"" +echo " 2. Open Claude Code or Codex in that folder (cd \"$DIR\" && claude) and say what film you want, e.g." +echo " \"快速出一版 15 秒的竖屏无声科普,用方格和画面文字讲清楚为什么正方形边长翻倍,面积变成四倍。\"" +echo " The full report of this machine: bin/vh doctor" diff --git a/references/fetch.sh b/references/fetch.sh index bc0578f8..b069541a 100755 --- a/references/fetch.sh +++ b/references/fetch.sh @@ -10,11 +10,31 @@ # 用法:bash references/fetch.sh 拉取或更新全部 # bash references/fetch.sh 只处理一个(dir 是下表第二列,例如 lemo-opuscar) # bash references/fetch.sh --neutralize 不联网,只对已拉取的仓库重新做一遍中和 +# +# 安装时默认不拉(install.sh --refs 才一次拉全):文档指到哪一个,agent 第一次用时再拉那一个,拉之前用一行说清拉什么、多大。 set -euo pipefail unset CDPATH # an exported one could send these relative cds elsewhere (as in bin/vh) cd "$(dirname "$0")" && mkdir -p repos && cd repos ARG=${1:-} +# 各仓库第一次拉下来占的磁盘(MB,含浅克隆的 .git;2026-11-22 在 macOS 上量的,合计约 300 MB)。拉之前那一行用它说大小; +# 加一个仓库时在这里补一项(tools/ci.sh 查每一行都有) +SIZES=" + 3brown1blue 1 Battle-of-Austerlitz-Film 2 Code2Video <1 MathLens <1 OpenMontage 27 PDoomVideo 8 Paper-Cut <1 + anatomy-reveal <1 anatomy 14 awesome-claude-video-skills <1 awesome-opus5-5-videos 5 blender-skills 2 + claude-animation-skill 6 data-animation-skills <1 faceless-shorts-creator 2 functional-emotions-video 18 + gbro-collage-info 5 guizang-product-video 3 hand-drawn-explainer <1 huashu-art-motion 7 huashu-design 4 + hyperframes-launches 12 hyperframes 11 lemo-opuscar 42 openfilm-examples 8 openfilm 59 opus55-catalog-zhuyansen 4 + opus55-guide-athemeroy 7 procedural-film 13 product-film-skill <1 remotion-guofeng-starter <1 remotion-skills 2 + story-to-handdrawn-video 3 video-shotcraft 11 video-talkcraft 18 viral-video-decomposer 4 vox-director <1 +" +size_of() { printf '%s\n' $SIZES | awk -v d="$1" 'p { print; exit } $0 == d { p = 1 }'; } +announce() { # announce :第一次拉一个之前,一行说清拉什么、从哪、多大 + local mb; mb=$(size_of "$2") + echo "fetching $2 from github.com/$1 (${mb:+about $mb MB, }read-only, for agents to read)" +} +MATCHED="" + AGENT_FILES=(.claude .agents CLAUDE.md CLAUDE.local.md AGENTS.md .mcp.json) agent_paths() { # 列出 $1 下所有层级的 agent 文件(跳过 .git),深的在前,保证先改子项再改父目录 local d=$1 f args=() @@ -34,7 +54,8 @@ neutralize() { # 更新后:改名为同目录下的 _upstream_*(git status skip() { # 按参数决定是否跳过这一行;--neutralize 模式只中和、不联网 local d=$1 if [ "$ARG" = "--neutralize" ]; then [ -d "$d" ] && neutralize "$d" && echo "ok $d (neutralized)"; return 0; fi - [ -n "$ARG" ] && [ "$ARG" != "$d" ] + [ -n "$ARG" ] && [ "$ARG" != "$d" ] && return 0 + MATCHED=1; return 1 } SKIPPED="" failed() { # failed <原因>:一个上游拉不下来只跳过这一行,不中断其余仓库和调用本脚本的安装流程 @@ -49,14 +70,14 @@ full() { # full :整仓浅克隆 skip "$2" && return 0 restore "$2" if [ -d "$2/.git" ]; then git -C "$2" pull --ff-only -q || true - else clone "$1" "$2" || return 0; fi + else announce "$1" "$2"; clone "$1" "$2" || return 0; fi neutralize "$2"; echo "ok $2" } sparse() { # sparse :只检出指定目录(大仓库用) local r=$1 d=$2; shift 2 skip "$d" && return 0 restore "$d" - if [ ! -d "$d/.git" ]; then clone "$r" "$d" --filter=blob:none --sparse || return 0; fi + if [ ! -d "$d/.git" ]; then announce "$r" "$d"; clone "$r" "$d" --filter=blob:none --sparse || return 0; fi git -C "$d" sparse-checkout set "$@" && git -C "$d" pull --ff-only -q || true neutralize "$d"; echo "ok $d ($*)" } @@ -64,7 +85,7 @@ textonly() { # textonly :只检出代码和文档,跳过 local r=$1 d=$2 fresh= skip "$d" && return 0 restore "$d" - if [ ! -d "$d/.git" ]; then clone "$r" "$d" --filter=blob:none --no-checkout || return 0; fresh=1; fi + if [ ! -d "$d/.git" ]; then announce "$r" "$d"; clone "$r" "$d" --filter=blob:none --no-checkout || return 0; fresh=1; fi git -C "$d" sparse-checkout set --no-cone '/*' '!*.mp4' '!*.mov' '!*.webm' '!*.mkv' '!*.gif' '!*.mp3' '!*.wav' '!*.m4a' '!*.aac' '!*.flac' \ '!*.png' '!*.jpg' '!*.jpeg' '!*.webp' '!*.psd' '!*.ttf' '!*.otf' '!*.woff' '!*.woff2' '!*.zip' '!*.pdf' '!*.onnx' '!*.bin' # 新克隆只需检出;已有克隆要 pull(空参数的 checkout 总是成功,放在 || 前面会让 pull 永远跑不到) @@ -124,5 +145,6 @@ textonly annnguyentt/anatomy-reveal-skill anatomy-reveal # 用 # Blender 只做资产(见 engines/blender.md"只做资产") textonly EL4CTEO/blender-skills blender-skills # Blender 5.2 的建模、UV、PBR、烘焙、绑骨、导出和资产质检 skill,`blender -b` 就能跑;bin/vh model3d check --blender 借它 asset-qa 的检查(MIT) +[ -z "$ARG" ] || [ "$ARG" = --neutralize ] || [ -n "$MATCHED" ] || { echo "no reference repo named $ARG: the names are the second column of references/fetch.sh" >&2; exit 2; } [ -z "$SKIPPED" ] || echo "skipped (re-run later, e.g. bash references/fetch.sh ):$SKIPPED" exit 0 diff --git a/tools/audio/tts.py b/tools/audio/tts.py index 0e3663be..54613cb8 100644 --- a/tools/audio/tts.py +++ b/tools/audio/tts.py @@ -269,6 +269,54 @@ def hf_cached(model_id): return True return os.path.isdir(os.path.join(constants.HF_HUB_CACHE, "models--" + model_id.replace("/", "--"), "snapshots")) +# The provider bin/vh tts uses when none is named: the one place to change it (bin/vh asks: tts.py --default-provider). +DEFAULT_PROVIDER = "qwen" +QWEN_MODEL = "mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-8bit" +QWEN_SIZES = {"packages": 0.75, "model": 1.8} # GB on disk the first time: mlx-audio and its packages (uv), the model (Hugging Face) + +def hub_dir(): + """Where the Hugging Face Hub keeps models, worked out as huggingface_hub does (stdlib, before it is installed).""" + if os.environ.get("HF_HUB_CACHE"): + return Path(os.environ["HF_HUB_CACHE"]) + home = os.environ.get("HF_HOME") or os.path.join(os.environ.get("XDG_CACHE_HOME") or os.path.expanduser("~/.cache"), "huggingface") + return Path(home) / "hub" + +def model_dir(model_id): + return hub_dir() / ("models--" + model_id.replace("/", "--")) + +def first_use_line(provider, packages_missing=False): + """The one line bin/vh tts says before a provider's first run downloads gigabytes (or None: nothing that big to fetch): + how much, roughly how long, that the progress shows, and the way around it.""" + if provider != "qwen" or not (sys.platform == "darwin" and platform.machine() == "arm64"): + return None + model_id = os.environ.get("QWEN_TTS_MODEL", QWEN_MODEL) + model = model_id == QWEN_MODEL and not os.path.isdir(os.path.expanduser(model_id)) and not list(model_dir(model_id).glob("snapshots/*/*.safetensors")) + parts = (["its Python packages"] if packages_missing else []) + (["the voice model"] if model else []) + if not parts: + return None + gb = (QWEN_SIZES["packages"] if packages_missing else 0) + (QWEN_SIZES["model"] if model else 0) + return (f" first use of the local voice: about {gb:.1f} GB to download once ({' and '.join(parts)}); a few minutes on a fast line," + f" half an hour or more on a slow one; the progress shows below. To skip it: --provider edge (free, online: the script" + f" goes to Microsoft's voice service)") + +def show_progress(folder, total_gb, every=10.0): + """A line every `every` seconds with how much a download has added to `folder` (the Hub's whole cache: its xet transfer + stages the parts outside the model's own folder), for output nobody watches live, where a progress bar is turned + off. → the thread's stop event.""" + import threading + stop = threading.Event() + def size(): + return sum(f.stat().st_size for f in Path(folder).rglob("*") if f.is_file() and not f.is_symlink()) if Path(folder).is_dir() else 0 + base = size() + def run(): + last = None + while not stop.wait(every): + got = round((size() - base) / 1e9, 1) + if got != last: + print(f" voice model: {got:.1f} of about {total_gb} GB", flush=True); last = got + threading.Thread(target=run, daemon=True).start() + return stop + _QWEN = {} def p_qwen(text, voice, out: Path, tmp: Path, lang, instruct=None): # Set before the libraries are imported, which is when they read them; one set outside wins (TRANSFORMERS_VERBOSITY=info). @@ -281,18 +329,22 @@ def p_qwen(text, voice, out: Path, tmp: Path, lang, instruct=None): import contextlib, io import numpy as np from mlx_audio.tts.utils import load_model # provided by `uv run --with mlx-audio` - default = "mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-8bit" - model_id = os.environ.get("QWEN_TTS_MODEL", default) + model_id = os.environ.get("QWEN_TTS_MODEL", QWEN_MODEL) if model_id not in _QWEN: - print(f" loading {model_id}" + ("" if hf_cached(model_id) else " (not downloaded yet: " + ("about 2 GB " if model_id == default else "") - + "into the Hugging Face cache, once)") + " …", flush=True) + fresh = not hf_cached(model_id) + print(f" loading {model_id}" + (" (not downloaded yet: " + (f"{QWEN_SIZES['model']} GB " if model_id == QWEN_MODEL else "") + + "into the Hugging Face cache, once)" if fresh else "") + " …", flush=True) said = io.StringIO() # mlx-audio prints what it loads; shown only when loading fails + stop = show_progress(hub_dir(), QWEN_SIZES["model"] if model_id == QWEN_MODEL else "?") if fresh and not sys.stderr.isatty() else None try: with contextlib.redirect_stdout(said): _QWEN[model_id] = load_model(model_id) except BaseException: sys.stdout.write(said.getvalue()) raise + finally: + if stop: + stop.set() model = _QWEN[model_id] zh = lang.startswith("zh") kw = dict(text=text, speaker=voice or ("Serena" if zh else "Aiden"), language="Chinese" if zh else "English") @@ -1151,8 +1203,15 @@ def usage_error(msg): # a mistake in the command line: one line, exit 2 (a run def main(): if sys.argv[1:2] == ["voices"] and (len(sys.argv) == 2 or sys.argv[2] in ("list", "design", "delete", "audition", "-h", "--help")): return voices_main(sys.argv[2:]) + if sys.argv[1:] == ["--default-provider"]: # for bin/vh tts, which picks the provider's packages before this runs + print(DEFAULT_PROVIDER); return + if sys.argv[1:2] == ["--first-use"] and len(sys.argv) in (3, 4): # bin/vh tts: the line before a big first download + line = first_use_line(sys.argv[2], sys.argv[3:] == ["--packages-missing"]) + if line: + print(line, flush=True) + return ap = argparse.ArgumentParser() - ap.add_argument("project"); ap.add_argument("--provider", choices=PROVIDERS, help="default qwen (with --resume: the run's provider)") + ap.add_argument("project"); ap.add_argument("--provider", choices=PROVIDERS, help=f"default {DEFAULT_PROVIDER} (with --resume: the run's provider)") ap.add_argument("--voice"); ap.add_argument("--lang", choices=["zh", "en"], help="spoken side (default zh; en for an English-only script)") ap.add_argument("--gap", type=float, default=0.25); ap.add_argument("--instruct") ap.add_argument("--keep-edges", action="store_true", help="keep the silence the provider puts before/after each line") @@ -1207,7 +1266,7 @@ def main(): sys.exit(f"--resume: GEMINI_TTS_STYLE was {man.get('style_env')!r} for the run, now {os.environ.get('GEMINI_TTS_STYLE')!r};" f" set it back, or drop --resume to start over") a.provider, a.voice, a.instruct, a.keep_edges = man["provider"], man["voice"], man.get("instruct"), man["keep_edges"] - a.provider = a.provider or "qwen" + a.provider = a.provider or DEFAULT_PROVIDER gemini = a.provider.startswith("gemini") timed = a.provider in WORD_TIMED # word timing from the provider itself penv = {k: os.environ.get(k) for k in MINIMAX_ENV} if a.provider == "minimax" else {} diff --git a/tools/ci.sh b/tools/ci.sh index 9da0f4f5..70f7aad3 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1565,6 +1565,44 @@ print(d.references_note(0, 37, 0, d.install_says())); print(d.references_note(31 case "$a" in "0/37 repos fetched → bash references/fetch.sh (all 37: about $b;"*"31/37 repos fetched → bash references/fetch.sh (all 37: about 255 MB, at the size of the 31 here;"*) ok "doctor: the reference repos' size from the ones fetched (31 of 37 at 214 MB: about 255 MB), else as install.sh says it ($b)" ;; *) bad "doctor's line for the reference repos: $a (install.sh says: ${b:-nothing found})" ;; esac + # the reference repos are fetched on first use: references/fetch.sh knows each one's size, and says it in one line before + # a first fetch; a name it does not have is said, exit 2 (it used to do nothing) + a=$(bash -c 'cd references && sed -n "/^SIZES=\"/,/^\"/p" fetch.sh | tr " " "\n" | grep -v "^SIZES\|^\"\|^$" | paste - - | cut -f1 | sort' 2>&1) + b=$(grep -E '^(full|sparse|textonly) ' references/fetch.sh | awk '{print $3}' | sort) + c=$(bash references/fetch.sh no-such-repo 2>&1); rc=$? + if [ -n "$b" ] && [ "$a" = "$b" ] && [ "$rc" = 2 ] && case "$c" in "no reference repo named no-such-repo"*) true ;; *) false ;; esac \ + && grep -q '^ else announce "$1" "$2"; clone' references/fetch.sh && grep -q 'REFS=0;' install.sh && grep -q -- '--refs) REFS=1' install.sh + then ok "references/fetch.sh: a size for each of the $(printf '%s\n' "$b" | wc -l | tr -d ' ') reference repos, said before a first fetch; an unknown name exits 2; install.sh fetches them only with --refs" + else bad "references/fetch.sh's sizes or names (exit $rc): $(diff <(printf '%s\n' "$a") <(printf '%s\n' "$b") | head -5 | tr '\n' ' ') | $c"; fi + # doctor --first, the installer's last lines: ready only when a first film has what it needs; what is missing, with how + # to get it; a voice line for this platform; a Chinese font missing is said (Linux) + a=$(python3 - <<'PY' 2>&1 +import sys; sys.path.insert(0, "tools"); import doctor as d +ok = lambda n, **k: dict({"name": n, "state": "ok", "install": f"get {n}"}, **k) +mods = [ok("node"), ok("ffmpeg"), ok("python3"), ok("uv"), ok("chrome"), ok("chrome-headless-shell", state="missing"), ok("claude-code"), ok("codex", state="missing"), + ok("qwen3-tts", state="missing"), ok("mlx-audio")] +checks = [{"name": "browser", "state": "missing"}] +l1, r1 = d.first_film(mods, checks, "darwin-arm64") # no browser yet, but the first render brings its own: ready +mods2 = [dict(m, state="missing") if m["name"] in ("uv", "claude-code") else m for m in mods] +l2, r2 = d.first_film(mods2, checks + [{"name": "fonts", "state": "missing"}], "linux-arm64") # no uv, no browser, no agent, no font +print(r1, r2, len(l1), len(l2)); print("\n".join(l1 + ["--"] + l2)) +PY +) + case "$a" in "True False 3 6"*"✓ Ready for a first film: Node, FFmpeg, uv, a browser to render with, Claude Code"*"downloads its own Chrome once"*"- Voice: the first bin/vh tts downloads the local voice once (about 2.5 GB"*"--provider edge"*"--"*"✗ Not ready for a first film yet"*" uv → get uv"*" a browser to render with → get chrome"*" Claude Code or Codex →"*"! Chinese text"*"- Voice: bin/vh tts --provider edge"*) + ok "doctor --first: ready only with Node, FFmpeg, Python, uv, a browser (or a platform whose first render brings one) and an agent; each missing one with how to get it; the voice for the platform; a missing Chinese font said" ;; + *) bad "doctor --first: $(printf '%s' "$a" | head -c 600)" ;; esac + # bin/vh tts: the default provider is said in one place (tts.py), and the local voice's first use is said before it + # downloads, with the size, the time it may take and the way around it; nothing for another provider or a cached model + a=$(python3 tools/audio/tts.py --default-provider 2>&1) + b=$(HF_HOME="$(mktemp -d)" python3 tools/audio/tts.py --first-use qwen --packages-missing 2>&1) + c=$(python3 tools/audio/tts.py --first-use edge --packages-missing 2>&1) + want="first use of the local voice: about 2.5 GB to download once (its Python packages and the voice model)" + case "$(uname -s)-$(uname -m)" in Darwin-arm64) ;; *) want="" ;; esac # elsewhere the local voice does not run, so nothing is said + if [ "$a" = qwen ] && case "$b" in *"$want"*) [ -n "$want" ] || [ -z "$b" ] ;; *) false ;; esac && [ -z "$c" ] \ + && { [ -z "$want" ] || case "$b" in *"--provider edge (free, online"*) true ;; *) false ;; esac; } \ + && grep -q 'prov=$(python3 "$ROOT/tools/audio/tts.py" --default-provider)' bin/vh + then ok "bin/vh tts: the default provider comes from tts.py alone; the local voice's first use is said before its 2.5 GB download (Apple Silicon), with the way around it; nothing for edge" + else bad "bin/vh tts's default and first-use line: $a | $b | $c"; fi # recipes sample: bad usage exits 2 before any render (an unknown id, a sequence, an unknown style); list --json names # the sheet a recipe carries (recipes check, above, holds every sketch to its sheet) vh recipes sample no-such-recipe >/dev/null 2>&1; rc=$?; vh recipes sample launch-15s >/dev/null 2>&1; rc2=$? diff --git a/tools/commands.json b/tools/commands.json index 305e3c75..c9373420 100644 --- a/tools/commands.json +++ b/tools/commands.json @@ -70,7 +70,7 @@ "writes": ["LOCAL.md (--fill-local: its machine lines that still hold the template; LOCAL.example.md copied first when there is none)"], "usage": [ { - "synopsis": "doctor [--json] [--fill-local] [--probe [--only a,b] [--offline DIR]]", + "synopsis": "doctor [--json] [--first] [--fill-local] [--probe [--only a,b] [--offline DIR]]", "text": [ "what this machine can use, from tools/modules.json (tools/doctor.py): each outside module's program and version (under the", "minimum, not the pin, or older than its max_age_days: outdated), the parts it needs, packages in uv's cache, a model in", @@ -79,7 +79,9 @@ "--probe: also call each service with a key, and each public one that takes none, once, at an endpoint that costs", "nothing (--only a,b: these modules alone; --offline DIR: answered from responses recorded the way", "tools/assets/fetch.py records them); --fill-local: also write LOCAL.md's machine lines (硬件, 已装工具, 已装引擎)", - "where they still hold the template, never a line a person wrote (the installer runs it). Exit 0: it is a report" + "where they still hold the template, never a line a person wrote (the installer runs it). --first: only the few lines", + "a first film needs (the installer ends with them): ready or not, what is missing and how to get it, how a voice", + "comes here (exit 1 when not ready). Exit 0: it is a report" ] }, { @@ -1629,7 +1631,7 @@ "--candidates N: N takes a block, the one nearest the narration's median voice kept (N × the synthesis);", "warns of a line far off the take's seconds per character, and (with --align) of a phrase heard twice;", "--resume: continue the last run after a failed synthesis or transcription, same script and command)", - "providers: qwen (default, local open-source Qwen3-TTS) | say | edge | dashscope | elevenlabs | gemini | gemini-lite | minimax" + "providers: qwen (default, local open-source Qwen3-TTS; its first use downloads about 2.5 GB, said first, with the progress) | say | edge | dashscope | elevenlabs | gemini | gemini-lite | minimax" ] } ] diff --git a/tools/doctor.py b/tools/doctor.py index 89282010..8976b6b8 100644 --- a/tools/doctor.py +++ b/tools/doctor.py @@ -1,8 +1,10 @@ """bin/vh doctor: what this machine can use, from the table of outside modules (tools/modules.json). Stdlib only. -usage: bin/vh doctor [--json] [--fill-local] [--probe [--only a,b] [--offline DIR]] +usage: bin/vh doctor [--json] [--first] [--fill-local] [--probe [--only a,b] [--offline DIR]] (bin/vh passes what its own finders found: --chrome, --hf-chrome, --hf-pin, --webgl) --json the same as JSON (below), the lines a person reads not printed + --first only the few lines a first film needs (the installer ends with them): ready or not, what is missing + for a first silent film and how to get it, how a voice comes here. Exit 1 when it is not ready --fill-local also write LOCAL.md's machine lines (硬件, 已装工具, 已装引擎) from this check, where they still hold the template's {…}; with no LOCAL.md, LOCAL.example.md is copied first. A line a person wrote stays; the other lines' {…} are their defaults (the installer runs this) @@ -28,7 +30,7 @@ a whole copy stays as it was when the repo moves on); studio-icon, the launcher bin/vh studio --install-icon makes (installed or not, which clone it runs, made by an earlier launcher or picture); caches, whether the folders a first run downloads into (uv's, npm's, Hugging Face's, HyperFrames', bin/vh's own) can be written, tried with a file made and removed. -Exit 0: it is a report (2 on a usage error or an unreadable table). +Exit 0: it is a report (2 on a usage error or an unreadable table; with --first, 1 when a first film still lacks something). --json, "version": 1 (these fields stay; new ones may be added): {"version", "tool", "platform", "modules": [{"name", "kind", "status" ("planned" when nothing calls it yet, else "used"), "required", "state", "found", "version", "keys": @@ -117,6 +119,45 @@ def references_note(have, want, fetched, said): " the one a doc points to, references/repos//…: bash references/fetch.sh )") +OWN_CHROME = ("darwin-arm64", "darwin-x86_64", "linux-x86_64") # where HyperFrames downloads its own chrome-headless-shell +LOCAL_VOICE = "about 2.5 GB" # the local voice's first use: mlx-audio and its packages (about 0.75 GB) and the model (1.8 GB on disk) + + +def first_film(mods, checks, plat): + """--first, the few lines install.sh ends with: is this machine ready for a first (silent) film, what it lacks for + one, and how a voice comes. → (lines, ready). Ready only with nothing missing that the first film needs: Node, FFmpeg, + Python 3, uv, a browser to render with (or a platform where the first render downloads its own), and an agent.""" + m, c = {x["name"]: x for x in mods}, {x["name"]: x for x in checks} + lack = [] + for name, what in (("node", "Node 22 or newer"), ("ffmpeg", "FFmpeg"), ("python3", "Python 3"), ("uv", "uv")): + r = m.get(name) + if r and r["state"] != "ok": + lack.append(f"{what} → {r.get('install') or 'install it'}") + own = plat in OWN_CHROME + if (c.get("browser") or {}).get("state") != "ok" and not own: + lack.append(f"a browser to render with → {(m.get('chrome') or {}).get('install') or 'set CHROME_PATH'}") + agents = [w for n, w in (("claude-code", "Claude Code"), ("codex", "Codex")) if (m.get(n) or {}).get("state") == "ok"] + if not agents: + lack.append("Claude Code or Codex → claude.com/claude-code, or npm install -g @openai/codex") + if lack: + lines = ["✗ Not ready for a first film yet. It still needs:"] + [f" {x}" for x in lack] + else: + lines = [f"✓ Ready for a first film: Node, FFmpeg, uv, a browser to render with, {' and '.join(agents)}"] + if (m.get("chrome-headless-shell") or {}).get("state") != "ok" and own: + lines.append(" The first render downloads its own Chrome once (about 0.2 GB).") + if (c.get("fonts") or {}).get("state") == "missing": + lines.append("! Chinese text: no Chinese font here, so it would draw as boxes → sudo apt install fonts-noto-cjk") + if plat == "darwin-arm64": + if (m.get("qwen3-tts") or {}).get("state") == "ok" and (m.get("mlx-audio") or {}).get("state") == "ok": + lines.append("✓ Voice: the local voice is downloaded.") + else: + lines.append(f"- Voice: the first bin/vh tts downloads the local voice once ({LOCAL_VOICE}; it says so first and shows the progress)." + " With --provider edge it downloads nothing (free, online).") + else: + lines.append("- Voice: bin/vh tts --provider edge (free, online), or a cloud voice with a key; the local voice needs Apple Silicon.") + return lines, not lack + + def this_platform(): m = platform.machine().lower() return f"{sys.platform}-{'arm64' if m in ('arm64', 'aarch64') else m}" @@ -137,7 +178,7 @@ def uv_has(pkgs): def hf_snapshot(model): """The Hugging Face snapshot folder of a model with weights in it, or None.""" - hub = os.environ.get("HF_HUB_CACHE") or os.path.join(os.environ.get("HF_HOME") or str(home("~/.cache/huggingface")), "hub") + hub = os.environ.get("HF_HUB_CACHE") or os.path.join(os.environ.get("HF_HOME") or os.path.join(os.environ.get("XDG_CACHE_HOME") or str(home("~/.cache")), "huggingface"), "hub") for snap in sorted(glob.glob(os.path.join(hub, "models--" + model.replace("/", "--"), "snapshots", "*", ""))): if glob.glob(os.path.join(snap, "*.safetensors")): return snap @@ -805,7 +846,7 @@ def print_module(m, r): def main(argv): - a = {"json": False, "probe": False, "fill-local": False, "offline": None, "only": None, "chrome": "", "hf-chrome": "", "hf-pin": "", "webgl": ""} + a = {"json": False, "probe": False, "fill-local": False, "first": False, "offline": None, "only": None, "chrome": "", "hf-chrome": "", "hf-pin": "", "webgl": ""} i = 0 while i < len(argv): x = argv[i] @@ -820,7 +861,7 @@ def main(argv): print(f"tools/modules.json: {len(t['modules'])} modules") return 1 if bad else 0 k, eq, v = x[2:].partition("=") - if x in ("--json", "--probe", "--fill-local"): + if x in ("--json", "--probe", "--fill-local", "--first"): a[x[2:]] = True elif k in ("offline", "only", "chrome", "hf-chrome", "hf-pin", "webgl") and x.startswith("--"): if not eq: @@ -829,7 +870,7 @@ def main(argv): i += 1; v = argv[i] a[k] = v else: - print(f"bin/vh doctor: unknown option {x} (usage: bin/vh doctor [--json] [--fill-local] [--probe [--only a,b] [--offline DIR]], or bin/vh doctor )", file=sys.stderr) + print(f"bin/vh doctor: unknown option {x} (usage: bin/vh doctor [--json] [--first] [--fill-local] [--probe [--only a,b] [--offline DIR]], or bin/vh doctor )", file=sys.stderr) return 2 i += 1 if (a["offline"] or a["only"] is not None) and not a["probe"]: @@ -855,9 +896,15 @@ def main(argv): pr = probe(m, a["offline"], recs) if a["probe"] and (only is None or m["name"] in only) else None mods[i] = {"name": m["name"], "kind": m["kind"], "status": m.get("status", "used"), "required": m["required"], **r, "install": (m.get("install") or {}).get("macos" if sys.platform == "darwin" else "linux"), "probe": pr} - if a["fill-local"]: # before the checks, so the LOCAL.md line says what is there now - print(fill_local(mods), file=sys.stderr if a["json"] else sys.stdout) + if a["fill-local"]: # before the checks, so the LOCAL.md line says what is there now (--first: written, not said) + said = fill_local(mods) + if not a["first"]: + print(said, file=sys.stderr if a["json"] else sys.stdout) checks = repo_checks(a["webgl"], found_by) + if a["first"] and not a["json"]: + lines, ready = first_film(mods, checks, this_platform()) + print("\n".join(lines)) + return 0 if ready else 1 first = [m.get("first_run") for m, r in zip(t["modules"], mods) if m.get("first_run") and r["state"] == "missing"] counts = {} for x in mods + checks: From 8ec76976b14dd71860dfa152802ccfc6d7bdfe85 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 03:12:46 +0800 Subject: [PATCH 02/14] install.sh: no references/repos yet is the usual first install (pipefail stopped the script there) --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 8a32c32f..d9c64abc 100755 --- a/install.sh +++ b/install.sh @@ -104,7 +104,7 @@ n=$(grep -cE '^(full|sparse|textonly) ' references/fetch.sh || true) # counted if [ "$REFS" = 1 ]; then say "fetching $n reference repos (about 300 MB, read-only, git-ignored)" references/fetch.sh || echo "! some reference repos were not fetched; bash references/fetch.sh fetches them later" -else had=$(find references/repos -mindepth 2 -maxdepth 2 -name .git 2>/dev/null | wc -l | tr -d ' ') +else had=0; [ ! -d references/repos ] || had=$(find references/repos -mindepth 2 -maxdepth 2 -name .git | wc -l | tr -d ' ') if [ "${had:-0}" -gt 0 ]; then echo " the $had reference repos fetched before stay as they are (--refs updates them and fetches the rest)"; fi fi say "installing the renderer for style samples (HyperFrames, for bin/vh style)" From 6d6de958a888ae9c1504983f997ef93cb976db3a Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 03:33:42 +0800 Subject: [PATCH 03/14] bin/vh tts: a Ctrl-C during the local voice's package probe ends bin/vh too (it went on to uv run) --- bin/vh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/vh b/bin/vh index a9321046..33a2f683 100755 --- a/bin/vh +++ b/bin/vh @@ -1314,7 +1314,7 @@ cmd_tts() { deps="$deps${np:+ $np}" # the local voice's first use downloads gigabytes: said first in one line (how much, how long, the way around it), and # uv's own download lines shown instead of quieted (tts.py adds the model's progress) - if [ "$prov" = qwen ] && command -v uv >/dev/null 2>&1 && ! uv run -q --no-project --offline $deps python -c "" >/dev/null 2>&1; then quiet=""; fresh=--packages-missing; fi + if [ "$prov" = qwen ] && command -v uv >/dev/null 2>&1 && ! on_ctrl_c uv run -q --no-project --offline $deps python -c "" >/dev/null 2>&1; then quiet=""; fresh=--packages-missing; fi # (a Ctrl-C here ends bin/vh too) [ "$prov" != qwen ] || python3 "$ROOT/tools/audio/tts.py" --first-use qwen $fresh on_ctrl_c uv run $quiet --no-project $deps python "$ROOT/tools/audio/tts.py" "$proj" --provider "$prov" ${lang:+--lang "$lang"} ${voice:+--voice "$voice"} ${instruct:+--instruct "$instruct"} "$@" } From 3c73c044a144d96aead216cec2c3d0ccd8ae9452 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 04:14:32 +0800 Subject: [PATCH 04/14] Review of #228: python3 asked for, every big first download said, the checks run the behaviour - install.sh asks for python3 up front; bin/vh doctor --first with no python3 is not ready (exit 1). - doctor --first: a Chinese locale with no Chinese font is not ready; on Linux the render browser's missing system libraries are not ready, and libraries it cannot ask about are 'not checked' (exit 3, the installer then does not say ready); an outdated agent is told to update; Python 3 in the ready line; uv says what it is for. - tools/audio/firstuse.py: the local voice's and the local Whisper's first downloads in one table (sizes measured: 0.8 + 1.8 GB, 2.0 + 1.6 GB), the line before them, the model's progress written to the real stdout so a redirect_stdout around the loader cannot swallow it. bin/vh's first_use helper is used by tts, voices audition and pace; tts checks its script first. doctor and tts read the sizes from there; edge 'needs only a small package'. - references: one repo by name that does not come exits 1; a full fetch with no network is one line; 'under 1 MB'; doctor's references line is fine by default; setup says its size; four docs say the one-name fetch. - The example sentence follows the locale; the skill says to read the installer's last lines. - README sizes: no double count. CI: fetch.sh through a stand-in git, doctor --first's states, the bare doctor, the first-download lines through a stand-in uv, the progress inside a redirect. --- README.md | 2 +- README.zh-CN.md | 2 +- bin/vh | 50 +++++++---- cases/remotion-production.md | 2 +- changes/first-run.md | 13 +-- engines/README.md | 4 +- install.sh | 18 ++-- playbook/04-audio.md | 2 +- references/fetch.sh | 16 ++-- references/open-source.md | 2 +- skills/open-video-harness/SKILL.md | 4 + tools/audio/firstuse.py | 135 +++++++++++++++++++++++++++++ tools/audio/pace.py | 12 ++- tools/audio/tts.py | 72 ++++----------- tools/ci.sh | 117 ++++++++++++++++++------- tools/commands.json | 2 +- tools/doctor.py | 103 ++++++++++++++++------ tools/modules.json | 8 +- 18 files changed, 399 insertions(+), 165 deletions(-) create mode 100644 tools/audio/firstuse.py diff --git a/README.md b/README.md index 187520f3..d4ca7edb 100644 --- a/README.md +++ b/README.md @@ -423,7 +423,7 @@ bash install.sh --no-icon # leave OVH Studio out of your - The installer fetches only the newest commit: the repo itself is about 95 MB to download and 200 MB on disk, before its packages and the reference repos. To contribute or browse the history, `git clone` normally and run `bin/vh setup`. - To update, run the installer again with the same options (or `git pull`); `LOCAL.md` and `projects/` are left alone, and it stops before overwriting files you changed. The installed skills are short stubs that read `skills/` in the clone, so they follow the update; `bin/vh doctor` says in the rare case one needs `bin/vh install-skill` again. - The showcase videos aren't in git; to rebuild a showcase locally, `tools/fetch_media.sh` downloads them from the release to where its scripts expect them. -- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, Python packages up to about 1.5 GB, and the default local voice about 2.5 GB, its model and packages, which `bin/vh tts` says before it starts, showing the progress (`--provider edge` downloads nothing; measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). If npm, PyPI, Hugging Face or Google Fonts are blocked or slow where you are, [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) has the mirror settings. +- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, the sound tools' Python packages about 0.7 GB, and the default local voice about 2.6 GB (its packages 0.8 GB, its model 1.8 GB), which `bin/vh tts` says before it starts and shows the progress of (`--provider edge` needs only a small package). The local Whisper behind `--align local` is about 3.6 GB more, said the same way (measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). If npm, PyPI, Hugging Face or Google Fonts are blocked or slow where you are, [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) has the mirror settings. Skill only: `npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`. It's a pointer: on first use it asks before installing the full workbench. That copy stays as it was when the repo changes; once the workbench is installed, `bin/vh install-skill` replaces it with a stub that follows the clone. diff --git a/README.zh-CN.md b/README.zh-CN.md index dbb778d2..72f71d3b 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -423,7 +423,7 @@ bash install.sh --no-icon # 不把 OVH Studio 放进应 - 安装脚本只拉最新的一个提交,仓库本身下载约 95 MB、占约 200 MB 磁盘,依赖和参考仓库另算;想参与贡献或翻历史,就正常 `git clone`,再运行 `bin/vh setup`。 - 更新:用同样的参数再运行一次安装命令(或者 `git pull`);`LOCAL.md` 和 `projects/` 不动,要覆盖你改过的文件时会先停下来。装出去的 skill 是指回克隆里 `skills/` 的短桩,跟着一起更新;少数要重装的时候(`bin/vh install-skill`),`bin/vh doctor` 会说。 - 样片的视频不在 git 里,要在本地复现样片时运行 `tools/fetch_media.sh`,它从 Release 下载到脚本要的位置。 -- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,Python 依赖最多约 1.5 GB,默认的本地配音约 2.5 GB(模型加它的依赖;`bin/vh tts` 开始前会先说,并显示进度;`--provider edge` 什么都不下)(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络连不上 npm、PyPI、Hugging Face 或 Google Fonts 时,镜像设置见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 +- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,声音工具的 Python 依赖约 0.7 GB,默认的本地配音约 2.6 GB(依赖 0.8 GB、模型 1.8 GB;`bin/vh tts` 开始前会先说,并显示进度;`--provider edge` 只要一个小包);`--align local` 用的本地 Whisper 另需约 3.6 GB,同样先说(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络连不上 npm、PyPI、Hugging Face 或 Google Fonts 时,镜像设置见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 只装 skill:`npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`。它只是一个指针,第一次用时会征得你同意,再把完整的工作台装好。这样装的是整份副本,仓库更新了它不变;工作台装好以后跑一次 `bin/vh install-skill`,换成跟随克隆的短桩。 diff --git a/bin/vh b/bin/vh index 33a2f683..21660ee4 100755 --- a/bin/vh +++ b/bin/vh @@ -57,7 +57,7 @@ cmd_doctor() { case "${1:-}" in ""|-*) ;; *) python3 "$ROOT/tools/engine_copy.py" "$@"; return ;; esac # this machine: tools/doctor.py reads tools/modules.json and reports; bin/vh hands it what its own finders find (the # browser the page tools take, the chrome-headless-shell HyperFrames pins) and the WebGL probe, which runs only here - command -v python3 >/dev/null 2>&1 || { doctor_bare "$@"; return 0; } + command -v python3 >/dev/null 2>&1 || { doctor_bare "$@"; case " $* " in *" --first "*) return 1 ;; esac; return 0; } # --first: not ready local a skip="" live="" rec="" for a in "$@"; do # a usage error is said at once (by doctor.py), before the probe below if [ -n "$skip" ]; then skip=""; continue; fi @@ -182,7 +182,7 @@ cmd_sync_agents() { # CLAUDE.md's 命令行 line from tools/commands.json first, cmd_setup() { echo "→ installing ClaudeAnimationBase deps"; (cd "$ROOT/engines/ClaudeAnimationBase" && npm install --silent) - echo "→ fetching reference repos"; "$ROOT/references/fetch.sh" + echo "→ fetching all $(grep -cE '^(full|sparse|textonly) ' "$ROOT/references/fetch.sh") reference repos (about 300 MB; an install fetches each on first use instead)"; "$ROOT/references/fetch.sh" echo "→ installing the style swatch renderer"; (cd "$ROOT/styles/_swatch" && npm ci --silent) [ -f "$ROOT/LOCAL.md" ] || cp "$ROOT/LOCAL.example.md" "$ROOT/LOCAL.md" echo "→ smoke test" @@ -1299,12 +1299,12 @@ cmd_tts() { [ -d "$proj" ] || { echo "$c_no bin/vh tts: no such project: $proj" >&2; exit 2; } # before uv builds an environment; tts.py would make the folder shift while [ $# -gt 0 ] && [ ${#pos[@]} -lt 4 ] && [[ "$1" != --* ]]; do pos+=("$1"); shift; done # positionals stop at the first --flag - local prov=${pos[0]:-} voice=${pos[1]:-} lang=${pos[2]:-} instruct=${pos[3]:-} a prev="" np="" quiet=-q fresh="" + local prov=${pos[0]:-} voice=${pos[1]:-} lang=${pos[2]:-} instruct=${pos[3]:-} a prev="" np="" kinds=() [ -n "$prov" ] || prov=$(python3 "$ROOT/tools/audio/tts.py" --default-provider) # tts.py's DEFAULT_PROVIDER, the one place it is set for a in "$@"; do # tts.py's own --provider X / --provider=X picks the dependencies too; the last one wins, as in argparse [ "$prev" = --provider ] && prov=$a - case "$a" in --provider=*) prov=${a#--provider=} ;; --candidates|--candidates=*) np="--with numpy" ;; --align=local) np="$np --with mlx-whisper" ;; esac # the takes are measured with numpy - [ "$prev|$a" = "--align|local" ] && np="$np --with mlx-whisper" # a local Whisper for the word times + case "$a" in --provider=*) prov=${a#--provider=} ;; --candidates|--candidates=*) np="--with numpy" ;; --align=local) np="$np --with mlx-whisper"; kinds+=(whisper) ;; esac # the takes are measured with numpy + [ "$prev|$a" = "--align|local" ] && { np="$np --with mlx-whisper"; kinds+=(whisper); } # a local Whisper for the word times prev=$a done # everything from the first --flag on goes straight to tts.py (--beats, --snap, --lead, --gap, --min-gap, --align, --join, --candidates, --min-sim, --vocab, --resume) @@ -1312,24 +1312,40 @@ cmd_tts() { case "$prov" in qwen) deps="--with mlx-audio" ;; edge) deps="--with edge-tts" ;; dashscope) [ -z "${DASHSCOPE_API_KEY:-}" ] || deps="--with dashscope" ;; esac # no key: tts.py says so, with no package fetched first deps="$deps${np:+ $np}" - # the local voice's first use downloads gigabytes: said first in one line (how much, how long, the way around it), and - # uv's own download lines shown instead of quieted (tts.py adds the model's progress) - if [ "$prov" = qwen ] && command -v uv >/dev/null 2>&1 && ! on_ctrl_c uv run -q --no-project --offline $deps python -c "" >/dev/null 2>&1; then quiet=""; fresh=--packages-missing; fi # (a Ctrl-C here ends bin/vh too) - [ "$prov" != qwen ] || python3 "$ROOT/tools/audio/tts.py" --first-use qwen $fresh - on_ctrl_c uv run $quiet --no-project $deps python "$ROOT/tools/audio/tts.py" "$proj" --provider "$prov" ${lang:+--lang "$lang"} ${voice:+--voice "$voice"} ${instruct:+--instruct "$instruct"} "$@" + # no script yet: tts.py writes a sample and stops, with no package fetched for it (it needs none for that) + [ -f "$proj/audio/script.txt" ] || exec python3 "$ROOT/tools/audio/tts.py" "$proj" --provider "$prov" + [ "$prov" != qwen ] || kinds+=(qwen) + first_use ${kinds[@]+"${kinds[@]}"} + on_ctrl_c uv run $uvq --no-project $deps python "$ROOT/tools/audio/tts.py" "$proj" --provider "$prov" ${lang:+--lang "$lang"} ${voice:+--voice "$voice"} ${instruct:+--instruct "$instruct"} "$@" +} +first_use() { # first_use [kind…]: before a command that can start one of the big first downloads (qwen: the local voice; whisper: + # the local Whisper), say it in one line (tools/audio/firstuse.py: how much, how long, the way around it, its sizes in one + # place) and set uvq to show uv's own download lines instead of quieting them; the model's progress comes from the tool. + # Apple Silicon only: elsewhere these do not run, and the command says so itself + local k pk miss="" + uvq=-q + [ $# -gt 0 ] && [ "$(uname -s) $(uname -m)" = "Darwin arm64" ] && command -v uv >/dev/null 2>&1 || return 0 + for k in "$@"; do + pk=$(python3 "$ROOT/tools/audio/firstuse.py" --package "$k") || continue + on_ctrl_c uv run -q --no-project --offline --with "$pk" python -c "" >/dev/null 2>&1 || miss="$miss${miss:+,}$k" # (a Ctrl-C here ends bin/vh too) + done + [ -z "$miss" ] || uvq="" + python3 "$ROOT/tools/audio/firstuse.py" "$(IFS=,; echo "$*")" ${miss:+--packages-missing "$miss"} } cmd_voices() { # audition measures the takes (numpy) and synthesizes with the provider's own packages, through uv [ $# -gt 0 ] || set -- list [ "$1" = audition ] || { python3 "$ROOT/tools/audio/tts.py" voices "$@"; return; } - local a prev="" prov=gemini deps="--with numpy" - for a in "$@"; do [ "$prev" = --provider ] && prov=$a; [ "$prev|$a" = "--align|local" ] && deps="$deps --with mlx-whisper"; case "$a" in --provider=*) prov=${a#--provider=} ;; --align=local) deps="$deps --with mlx-whisper" ;; esac; prev=$a; done - case "$prov" in qwen) deps="$deps --with mlx-audio" ;; edge) deps="$deps --with edge-tts" ;; dashscope) deps="$deps --with dashscope" ;; esac - on_ctrl_c uv run -q --no-project $deps python "$ROOT/tools/audio/tts.py" voices "$@" + local a prev="" prov=gemini deps="--with numpy" kinds=() + for a in "$@"; do [ "$prev" = --provider ] && prov=$a; [ "$prev|$a" = "--align|local" ] && { deps="$deps --with mlx-whisper"; kinds+=(whisper); }; case "$a" in --provider=*) prov=${a#--provider=} ;; --align=local) deps="$deps --with mlx-whisper"; kinds+=(whisper) ;; esac; prev=$a; done + case "$prov" in qwen) deps="$deps --with mlx-audio"; kinds+=(qwen) ;; edge) deps="$deps --with edge-tts" ;; dashscope) deps="$deps --with dashscope" ;; esac + first_use ${kinds[@]+"${kinds[@]}"} + on_ctrl_c uv run $uvq --no-project $deps python "$ROOT/tools/audio/tts.py" voices "$@" } cmd_pace() { # numpy for the waveform; mlx-whisper only with --align whisper (Apple Silicon) - local a prev="" deps="--with numpy" - for a in "$@"; do case "$prev:$a" in --align:whisper|*:--align=whisper|--align:local|*:--align=local) deps="$deps --with mlx-whisper" ;; esac; prev=$a; done - on_ctrl_c uv run -q --no-project $deps python "$ROOT/tools/audio/pace.py" "$@" + local a prev="" deps="--with numpy" kinds=() + for a in "$@"; do case "$prev:$a" in --align:whisper|*:--align=whisper|--align:local|*:--align=local) deps="$deps --with mlx-whisper"; kinds=(whisper) ;; esac; prev=$a; done + first_use ${kinds[@]+"${kinds[@]}"} + on_ctrl_c uv run $uvq --no-project $deps python "$ROOT/tools/audio/pace.py" "$@" } cmd_captions() { # --media-end S: where a caption too short for its minimum may be lengthened to (default: the picture's length) local u="usage: bin/vh captions [zh|en] [zh-max] [--en-max 42] [--cards] [--cps 9] [--media-end S] [--skip-lint]" x diff --git a/cases/remotion-production.md b/cases/remotion-production.md index 9d9a8b7c..85ff8f22 100644 --- a/cases/remotion-production.md +++ b/cases/remotion-production.md @@ -31,4 +31,4 @@ - 动画必须用 `useCurrentFrame()` 加 `interpolate()` 驱动。CSS transition、CSS animation 和 Tailwind 的动画类在渲染时都不会正确生效。 - 字幕:`@remotion/install-whisper-cpp` 的 `transcribe()`,再加 `toCaptions`。 - 配音:用 ElevenLabs 为每个场景生成一个 mp3,在 `calculateMetadata` 里读取音频时长,设置 `durationInFrames`。 -- 官方 skills 已拉到本地:`references/repos/remotion-skills/skills/`。 +- 官方 skills 在 `references/repos/remotion-skills/skills/`(没有就先 `bash references/fetch.sh remotion-skills`,约 2 MB)。 diff --git a/changes/first-run.md b/changes/first-run.md index e22c5b0b..af9c136d 100644 --- a/changes/first-run.md +++ b/changes/first-run.md @@ -1,7 +1,8 @@ -**安装更轻,最后一屏只说第一支片要知道的事;本地配音第一次下载前先说** -- Why: 在干净的机器上量过,安装 90 秒里有 71 秒、305 MB 在拉参考仓库,而第一支片用不到它们;安装最后一屏是 60 多行 doctor,十几行黄色提示大多和第一支片无关,Linux 上真挡路的缺项淹在里面,最后照样说"ready";本地配音第一次用要静默下载约 2.5 GB。 -- 37 个参考仓库安装时不再拉:agent 用到文档指的那一个时再拉,`references/fetch.sh <目录>` 拉之前用一行说清拉什么、从哪、多大(大小表在脚本里,CI 查每一个都有);名字写错时说清并退出 2。`install.sh --refs` 一次拉全;`--no-refs` 照旧认,现在就是默认。之前拉过的留着不动。 -- 安装最后几行换成 `bin/vh doctor --first`:能不能做第一支片,缺什么、一句怎么补(Node、FFmpeg、Python、uv、能渲染的浏览器、一个 agent),Linux 上缺中文字体也说,配音在这台机器上怎么来;有缺的就不说 ready。完整报告照旧是 `bin/vh doctor`。skill 注册只说一行。示例句换成 README 那条无声 15 秒。 -- `bin/vh tts` 用本地配音、第一次要下载时,先说一行:约多大、大概多久、显示进度,以及不用下载的办法(`--provider edge`,免费,在线:稿子会发到微软的配音服务);Python 包的下载逐个显示,模型下载每 10 秒说一次下了多少。默认配音只在 `tools/audio/tts.py` 的 `DEFAULT_PROVIDER` 一处设,`bin/vh tts` 问它。 +**安装更轻,最后一屏只说第一支片要知道的事;几个 GB 的第一次下载都先说一声** +- Why: 在干净的机器上量过,安装 90 秒里有 71 秒、305 MB 在拉参考仓库,而第一支片用不到它们;安装最后一屏是 60 多行 doctor,十几行黄色提示大多和第一支片无关,Linux 上真挡路的缺项淹在里面,最后照样说"ready";本地配音第一次用要静默下载约 2.6 GB。 +- 37 个参考仓库安装时不再拉:agent 用到文档指的那一个时再拉,`references/fetch.sh <目录>` 拉之前用一行说清拉什么、从哪、多大(大小表在脚本里,CI 查每一个都有);指名的那一个没拉下来就退出 1,名字写错退出 2;拉全部时断网只说一行。`install.sh --refs` 一次拉全;`--no-refs` 照旧认,现在就是默认。之前拉过的留着不动。`bin/vh doctor` 不再把没拉的参考仓库当成缺项。`bin/vh setup` 仍然拉全部,先说约 300 MB。 +- 安装最后几行换成 `bin/vh doctor --first`:能不能做第一支片,缺什么、一句怎么补(Node、FFmpeg、Python 3、uv、能渲染的浏览器和它要的系统库、一个 agent;中文环境下还有中文字体),配音在这台机器上怎么来;有缺的就不说 ready,没法检查的(Linux 上问不到浏览器的系统库)说"没检查",也不说 ready。完整报告照旧是 `bin/vh doctor`。安装前就要 python3。skill 注册只说一行。示例句跟着你的语言:中文环境是 README 那条无声 15 秒,其他是它的英文版。skill 里写明:安装看最后几行,不看退出码。 +- 几个 GB 的第一次下载,开始前都先说一行:约多大、大概多久、显示进度,以及不用下载的办法。本地配音(`bin/vh tts`、`voices audition`)约 2.6 GB,`--provider edge` 只要一个小包(免费,在线:稿子会发到微软的配音服务);本地 Whisper(`tts`、`voices audition --align local`、`pace --align whisper`)约 3.6 GB,`--align gemini` 不用下载。Python 包的下载逐个显示,模型下载每 10 秒说一次下了多少(输出给 agent 看、或者外面关了进度条时)。大小只记在 `tools/audio/firstuse.py` 一处,doctor 也从那里读。`bin/vh tts` 先查稿子:没有稿子时写一份示例就停,一个包都不下。 +- 默认配音只在 `tools/audio/tts.py` 的 `DEFAULT_PROVIDER` 一处设,`bin/vh tts` 问它。 - doctor 找本地配音模型时也看 `XDG_CACHE_HOME`(Hugging Face 自己就这样找)。 -- README 中英文和官网的安装大小按实测更新:安装约 400 MB,`--refs` 再约 300 MB,本地配音约 2.5 GB。 +- README 中英文和官网的安装大小按实测更新:安装约 400 MB,`--refs` 再约 300 MB,本地配音约 2.6 GB,本地 Whisper 约 3.6 GB。 diff --git a/engines/README.md b/engines/README.md index 89d01817..d31167ba 100644 --- a/engines/README.md +++ b/engines/README.md @@ -109,7 +109,7 @@ HYPERFRAMES_RENDER_DETACHED=1 nohup caffeinate -i npx hyperframes render --quali - **`font-weight: 800` 在 macOS 自带的 PingFang SC 上等于 600。** 现象:字幕规格写了字重 800,渲出来却不够粗,也没有报错。原因:PingFang SC 只有 6 个字重,从 Ultralight 到 Semibold(CSS 的 100–600),没有 Bold 和 Heavy;请求 700、800、900 都落到 600,实测渲出的字和 600 逐像素相同,浏览器也不会再合成粗体。解决:用 PingFang SC 就写 600,并在 STYLE.md 里记下;真要 800,自己带一个有这个字重的字体(Noto Sans SC 等,不联网的取法见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)),或者换一个有更粗字重的系统字体(比如 Songti SC 有 900,`styles/_swatch/README.md` 的字体表列了各字体实测可用的字重)。 - **`--format png-sequence` 写出的是 RGBA,而且不画 `html`、`body` 的背景。** 那些地方 alpha = 0,元素自己的底色会留下。0.8.82 连合成根元素(带 `data-composition-id` 的那个)上的 `background` 也不画;0.8.202 画它,根元素有不透明的底色时整帧不透明,PNG 就成了不带 alpha 的 RGB(2026-10-26 用 html、body、根元素三种写法各测一遍)。做确定性检查时要留意,细节和比对办法见 `playbook/02-verification.md` 的"确定性"一节。 - **现成的块和组件**(字幕样式、lower-third、转场、图表等,0.8.202 的 registry 有 448 个):`bin/vh hf catalog <词>` 查,`bin/vh hf add <项目> <名字>` 装。它把项目的 `hyperframes.json` 钉到这个版本的 tag(HyperFrames 默认取 GitHub `main` 上最新的那份),装进来的文件记进素材台账,并提示里面用了 CSS 动画、`Math.random` 或联网加载的地方。 -- **不要运行 `npx hyperframes skills update`**。skill 文档已经拉到本地,直接读:`references/repos/hyperframes/skills/`(工作流和参考资料)、`references/repos/hyperframes/_upstream_claude/skills/`(motion-doctrine 等内部规范,写动画前先读 motion-doctrine)。 +- **不要运行 `npx hyperframes skills update`**。skill 文档在参考仓库里(没有就先 `bash references/fetch.sh hyperframes`,约 11 MB),直接读:`references/repos/hyperframes/skills/`(工作流和参考资料)、`references/repos/hyperframes/_upstream_claude/skills/`(motion-doctrine 等内部规范,写动画前先读 motion-doctrine)。 - 想让所有项目都能用 `/hyperframes`、`/faceless-explainer` 等命令,可以装成 Claude Code 的用户级插件(`claude plugin marketplace add heygen-com/hyperframes && claude plugin install hyperframes@hyperframes`)。这会修改全局配置,**必须先征得用户同意**。 - **没有 `@font-face` 的字体,渲染时会去 Google Fonts 取。** `render`、`snapshot`、`check` 每次运行都请求,连不上就挂住(render 停在 5% 的 "Compiling composition")。lint 拦不住其中两种:它别名表里的名字(Arial、Helvetica Neue、Menlo 等)没有声明也算通过,渲染时被换成 Inter、JetBrains Mono 去取;以 `sans-serif` 这类通用族名开头的栈,前面会被补上 Inter。所以本机字体也写 `@font-face`、`src` 用 `local()`,栈里排第一的写声明过的字体,照 `bin/vh hf-init` 搭的脚手架做。渲染日志里出现 `[Compiler] Injected deterministic @font-face rules`,就是还有字体没声明。国内网络下的做法见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 - **字体里缺的字**:字体在、字不在时,浏览器换一个字体画这个字,哪个字体都没有就画成空的缺字字形(苹方的是空白),lint 和渲染都不报。`bin/vh fonts check <项目>` 用 HyperFrames 自己的运行时抽帧,查每个 clip 的 DOM 字和 canvas 字实际由哪个字体画(2026-10-12 在一台 Mac 上:showcase 00 的 "LF Mono" 里有三个汉字落到了苹方,showcase 02 的"Δ"落到了 Arial)。HyperFrames 渲染时把 Google 字体换成它缓存的一份,这个检查看的是页面声明的字体,所以 `local()` 和项目里的字体文件最准。 @@ -251,7 +251,7 @@ npx remotion studio # 预览 ``` - 许可:个人和 3 人以内的公司免费,超过这个规模需要购买授权。 -- 官方 skills 已拉到本地:`references/repos/remotion-skills/skills/`。 +- 官方 skills 在 `references/repos/remotion-skills/skills/`(没有就先 `bash references/fetch.sh remotion-skills`,约 2 MB)。 ## Manim CE(Python),装进每个项目 diff --git a/install.sh b/install.sh index d9c64abc..ccd5174c 100755 --- a/install.sh +++ b/install.sh @@ -26,8 +26,9 @@ # your home directory, without asking: # - the first hyperframes render: HyperFrames' own chrome-headless-shell (about 200 MB, ~/.cache/hyperframes) # - the first bin/vh beats, music, sfx, qa or sheet: their Python packages, through uv (about 700 MB, ~/.cache/uv) -# - the first bin/vh tts with the default qwen provider (skipped with another one): its Python packages (about 750 MB, ~/.cache/uv) -# and the Qwen3-TTS model (1.8 GB, ~/.cache/huggingface); bin/vh tts says so before it starts and shows the progress +# - the first bin/vh tts with the default qwen provider (skipped with another one): its Python packages (about 0.8 GB, ~/.cache/uv) +# and the Qwen3-TTS model (1.8 GB, ~/.cache/huggingface); --align local adds the local Whisper (about 3.6 GB); bin/vh tts says +# so before it starts and shows the progress (the sizes: tools/audio/firstuse.py) # - every bin/vh new short, promo, data or meme: about 140 MB of node_modules in that project # The wiki's Getting Started ("What gets downloaded") has the same list. set -euo pipefail @@ -65,7 +66,7 @@ if [ "$(uname -s)" = Darwin ] && [ "$(command -v git)" = /usr/bin/git ] && ! xco echo "✗ First this Mac needs Apple's command line tools (git comes with them): run xcode-select --install, then run this installer again."; exit 1 fi missing="" -for t in git node ffmpeg; do command -v "$t" >/dev/null 2>&1 || missing="$missing $t"; done +for t in git node ffmpeg python3; do command -v "$t" >/dev/null 2>&1 || missing="$missing $t"; done # (bin/vh's commands run on python3) if [ -n "$missing" ]; then if [ "$(uname -s)" = Darwin ] && command -v brew >/dev/null 2>&1; then how="brew install${missing}" elif [ "$(uname -s)" = Darwin ]; then how="get Homebrew (https://brew.sh), then brew install${missing}" @@ -120,13 +121,16 @@ fi ICON_LATER=""; ICON_DONE=""; ICON_HEADLESS=""; put_icon echo # the last lines: ready for a first film or not, what it still needs, how a voice comes here (the full report: bin/vh doctor) -READY=""; bin/vh doctor --fill-local --first && READY=1 +st=0; bin/vh doctor --fill-local --first || st=$? # 0 ready, 3 one thing not checked, else not ready echo -if [ -n "$READY" ]; then echo "✓ OpenVideoHarness is ready at $DIR. Two ways to start:" -else echo "✗ OpenVideoHarness is installed at $DIR; a first film still needs what is listed above. Then, two ways to start:"; fi +case $st in 0) echo "✓ OpenVideoHarness is ready at $DIR. Two ways to start:" ;; + 3) echo "OpenVideoHarness is installed at $DIR; one thing above could not be checked here. Two ways to start:" ;; + *) echo "✗ OpenVideoHarness is installed at $DIR; a first film still needs what is listed above. Then, two ways to start:" ;; esac if [ -n "$ICON_DONE" ]; then echo " 1. Click OVH Studio in your applications: your films, their stops and the agent, in one window." elif [ -n "$ICON_HEADLESS" ]; then echo " 1. Studio, in a browser on another computer: cd \"$DIR\" && bin/vh studio --print-address (this machine has no desktop)" else echo " 1. Studio, your films in one window: cd \"$DIR\" && bin/vh studio$([ -z "$ICON_LATER" ] || printf ' (bin/vh studio --install-icon puts it in your applications)')"; fi echo " 2. Open Claude Code or Codex in that folder (cd \"$DIR\" && claude) and say what film you want, e.g." -echo " \"快速出一版 15 秒的竖屏无声科普,用方格和画面文字讲清楚为什么正方形边长翻倍,面积变成四倍。\"" +case "${LC_ALL:-${LC_MESSAGES:-${LANG:-}}}" in # the example in the person's language (the README's silent first film) + zh*|ZH*) echo " \"快速出一版 15 秒的竖屏无声科普,用方格和画面文字讲清楚为什么正方形边长翻倍,面积变成四倍。\"" ;; + *) echo " \"Quick draft: make a silent 15-second vertical explainer showing why doubling a square's side length quadruples its area. Use a grid and on-screen text.\"" ;; esac echo " The full report of this machine: bin/vh doctor" diff --git a/playbook/04-audio.md b/playbook/04-audio.md index 3adc8df8..57b73c84 100644 --- a/playbook/04-audio.md +++ b/playbook/04-audio.md @@ -62,7 +62,7 @@ bin/vh beats <任意音乐文件> # 外来音乐的节 | provider | 什么时候用 | |---|---| -| `qwen`(默认) | 本地开源 Qwen3-TTS,免费、离线,首次下载约 2 GB;0.6B 模型念英文短句偶尔停不下来,每条都要查 | +| `qwen`(默认) | 本地开源 Qwen3-TTS,免费、离线,首次下载约 2.6 GB(`bin/vh tts` 开始前先说,并显示进度);0.6B 模型念英文短句偶尔停不下来,每条都要查 | | `gemini` | 云端,表演力最好,能用一句话导演语气,适合讲解旁白和双人对话;要 `GEMINI_API_KEY` | | `minimax` | 云端 MiniMax(`speech-2.8-hd`),中文音色多(`Chinese (Mandarin)_*`)。`--join all` 整份稿一个请求,从头到尾一个声音;自带逐字时间,不用转写;支持停顿标记 `<#0.4#>` 和发音词典 `@pronounce`。语气只认一个情绪词。要 `MINIMAX_TOKEN_PLAN_KEY` 或 `MINIMAX_API_KEY`,细节见 `tools/audio/README.md` 的"MiniMax" | | `say` / `edge` | 打草稿;只能念,不能演 | diff --git a/references/fetch.sh b/references/fetch.sh index b069541a..ea22afbf 100755 --- a/references/fetch.sh +++ b/references/fetch.sh @@ -29,9 +29,11 @@ SIZES=" story-to-handdrawn-video 3 video-shotcraft 11 video-talkcraft 18 viral-video-decomposer 4 vox-director <1 " size_of() { printf '%s\n' $SIZES | awk -v d="$1" 'p { print; exit } $0 == d { p = 1 }'; } -announce() { # announce :第一次拉一个之前,一行说清拉什么、从哪、多大 +announce() { # announce :只拉一个时,第一次拉之前一行说清拉什么、从哪、多大(拉全部时调用方已说过总共多大) + [ -n "$ARG" ] || return 0 local mb; mb=$(size_of "$2") - echo "fetching $2 from github.com/$1 (${mb:+about $mb MB, }read-only, for agents to read)" + case "$mb" in "<1") mb="under 1 MB, " ;; "") ;; *) mb="about $mb MB, " ;; esac + echo "fetching $2 from github.com/$1 (${mb}read-only, for agents to read)" } MATCHED="" @@ -58,12 +60,13 @@ skip() { # 按参数决定是否跳过这一行;--neutralize 模式只 MATCHED=1; return 1 } SKIPPED="" -failed() { # failed <原因>:一个上游拉不下来只跳过这一行,不中断其余仓库和调用本脚本的安装流程 - echo "skip $1 ($2)"; SKIPPED="$SKIPPED $1" +failed() { # failed <原因>:一个上游拉不下来只跳过这一行,不中断其余仓库和调用本脚本的安装流程(拉全部时最后一行一起说) + [ -z "$ARG" ] || echo "skip $1 ($2)"; SKIPPED="$SKIPPED $1" } clone() { # clone [git clone 参数...] local r=$1 d=$2; shift 2 - git clone -q --depth 1 "$@" "https://github.com/$r.git" "$d" || { failed "$d" "clone failed"; return 1; } + git clone -q --depth 1 "$@" "https://github.com/$r.git" "$d" 2>"${TMPDIR:-/tmp}/fetch-$d.err" || { failed "$d" "clone failed: $(tail -1 "${TMPDIR:-/tmp}/fetch-$d.err")"; rm -f "${TMPDIR:-/tmp}/fetch-$d.err"; return 1; } + rm -f "${TMPDIR:-/tmp}/fetch-$d.err" } full() { # full :整仓浅克隆 @@ -146,5 +149,6 @@ textonly annnguyentt/anatomy-reveal-skill anatomy-reveal # 用 textonly EL4CTEO/blender-skills blender-skills # Blender 5.2 的建模、UV、PBR、烘焙、绑骨、导出和资产质检 skill,`blender -b` 就能跑;bin/vh model3d check --blender 借它 asset-qa 的检查(MIT) [ -z "$ARG" ] || [ "$ARG" = --neutralize ] || [ -n "$MATCHED" ] || { echo "no reference repo named $ARG: the names are the second column of references/fetch.sh" >&2; exit 2; } -[ -z "$SKIPPED" ] || echo "skipped (re-run later, e.g. bash references/fetch.sh ):$SKIPPED" +[ -z "$SKIPPED" ] || echo "skipped $(echo $SKIPPED | wc -w | tr -d ' ') (no network? re-run later, e.g. bash references/fetch.sh ):$SKIPPED" +[ -z "$ARG" ] || [ -z "$SKIPPED" ] || exit 1 # the one asked for did not come: say so in the exit status too exit 0 diff --git a/references/open-source.md b/references/open-source.md index 3b2ec18b..f15ad86a 100644 --- a/references/open-source.md +++ b/references/open-source.md @@ -2,7 +2,7 @@ 所有项目都通过 GitHub API 核实过存在性;⭐ 是约数,日期是最近一次 push。 -已拉到本地的仓库都在 `references/repos/`(运行 `references/fetch.sh` 更新),包括: +下面这些仓库由 `references/fetch.sh` 拉进 `references/repos/`:安装时默认不拉,用到哪一个再拉哪一个(`bash references/fetch.sh <目录>`,拉之前说多大),`bash references/fetch.sh` 一次拉全(约 300 MB)。其中有: - PDoomVideo、functional-emotions-video、hyperframes-launches、remotion-skills; - HyperFrames 的 skills(部分检出)、Code2Video 的 prompts 和 src(部分检出)、3brown1blue 的 skill(部分检出); - 2026-09-29 补:Battle-of-Austerlitz-Film、claude-animation-skill、product-film-skill、procedural-film,以及两份 Opus 5.5 作品目录(athemeroy、zhuyansen)。社区 skill 和目录的完整清单见 `community-skills.md`。 diff --git a/skills/open-video-harness/SKILL.md b/skills/open-video-harness/SKILL.md index a0ea0fc6..b848fde5 100644 --- a/skills/open-video-harness/SKILL.md +++ b/skills/open-video-harness/SKILL.md @@ -25,6 +25,10 @@ If none exists, ask the user for permission, then install it: curl -fsSL https://raw.githubusercontent.com/ZLHad/OpenVideoHarness/main/install.sh | bash ``` +Read the installer's last lines, not its exit status: it exits 0 whenever the install itself worked, and its last lines +say whether a first film can be made here ("✗ Not ready for a first film yet" lists what is missing, each with how to +get it). Tell the user what is missing before starting a film. + ## 2. Follow the harness, not this file Read `/CLAUDE.md` (Codex: `/AGENTS.md`, which is identical) and follow it: diff --git a/tools/audio/firstuse.py b/tools/audio/firstuse.py new file mode 100644 index 00000000..cfe32ec4 --- /dev/null +++ b/tools/audio/firstuse.py @@ -0,0 +1,135 @@ +"""The big first downloads the sound commands can start, said before they start. Stdlib only. + +usage: python3 tools/audio/firstuse.py [--packages-missing kind[,kind]] the one line (nothing when nothing big + is to come); bin/vh's first_use helper + python3 tools/audio/firstuse.py --package the Python package bin/vh probes for it + +Kinds: qwen, the local voice (bin/vh tts and voices audition with the default provider); whisper, the local Whisper (tts and +voices audition --align local, pace --align whisper). Each is Python packages fetched by uv on first use and a model fetched +from Hugging Face on first load, on Apple Silicon only (mlx). Their sizes live here and only here: bin/vh doctor --first and +the line bin/vh says read them. Measured 2026-11-22 on macOS (Apple Silicon), each in an empty cache: mlx-audio and its +packages 0.8 GB, mlx-whisper and its packages 2.0 GB (torch among them; the two together 2.6 GB), the Qwen3-TTS model +1.8 GB, whisper-large-v3-turbo 1.6 GB. +""" +import os, platform, sys, threading +from pathlib import Path + +KINDS = { + "qwen": {"what": "the local voice", "package": "mlx-audio", "packages_gb": 0.8, "env": "QWEN_TTS_MODEL", + "model": "mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-8bit", "model_gb": 1.8, + "around": "--provider edge needs only a small package (free, online: the script goes to Microsoft's voice service)"}, + "whisper": {"what": "the local Whisper", "package": "mlx-whisper", "packages_gb": 2.0, "env": "WHISPER_MODEL", + "model": "mlx-community/whisper-large-v3-turbo", "model_gb": 1.6, + "around": "--align gemini needs a Gemini key and no download"}, +} + + +def gb(x): + return f"{x:.1f} GB" + + +def total(kinds=("qwen",)): + """The whole first download of these kinds, packages and models (what doctor --first says).""" + return sum(KINDS[k]["packages_gb"] + KINDS[k]["model_gb"] for k in kinds) + + +def here(): + """These downloads run on Apple Silicon only (mlx); elsewhere the commands say so themselves.""" + return sys.platform == "darwin" and platform.machine() == "arm64" + + +def hub_dir(): + """Where the Hugging Face Hub keeps models, worked out as huggingface_hub does (stdlib, before it is installed).""" + if os.environ.get("HF_HUB_CACHE"): + return Path(os.environ["HF_HUB_CACHE"]) + home = os.environ.get("HF_HOME") or os.path.join(os.environ.get("XDG_CACHE_HOME") or os.path.expanduser("~/.cache"), "huggingface") + return Path(home) / "hub" + + +def model_id(kind): + return os.environ.get(KINDS[kind]["env"], KINDS[kind]["model"]) + + +def model_cached(kind): + """The model is here: a local folder, or a snapshot with weights in the Hub's cache. Another model than ours (the env + variable) counts as here when it is a folder; else as we cannot size it, it is said without a size.""" + m = model_id(kind) + if os.path.isdir(os.path.expanduser(m)): + return True + d = hub_dir() / ("models--" + m.replace("/", "--")) / "snapshots" + return any(d.glob("*/*.safetensors")) or any(d.glob("*/*.npz")) + + +def line(kinds, packages_missing=()): + """The one line before a first download of these kinds (or None: nothing big to fetch, or not this platform): how much, + roughly how long, that the progress shows, and the way around each.""" + if not here(): + return None + parts, size, around, whats = [], 0.0, [], [] + for k in kinds: + K = KINDS[k]; mine = model_id(k) == K["model"] + pk, md = k in packages_missing, not model_cached(k) + if not (pk or md): + continue + whats.append(K["what"]) + size += (K["packages_gb"] if pk else 0) + (K["model_gb"] if md and mine else 0) + model = "model" if mine else f"model {model_id(k)}" + parts.append(f"{K['what']}'s " + ("Python packages and " + model if pk and md else "Python packages" if pk else model)) + around.append(K["around"]) + if not parts: + return None + return (f" first use of {' and '.join(whats)}: about {gb(size)} to download once ({', '.join(parts)}); a few minutes on a fast" + f" line, half an hour or more on a slow one; the progress shows below. Without it: {'; '.join(around)}") + + +def show_progress(total_gb, every=10.0, folder=None): + """A line every `every` seconds with how much a download has added to `folder` (default: the Hub's whole cache, as its + xet transfer stages the parts outside the model's own folder). Written to the process's real stdout (sys.__stdout__), + so a caller that has swapped sys.stdout (contextlib.redirect_stdout, around a library that prints as it loads) does not + swallow it. → the thread's stop event.""" + folder = Path(folder) if folder else hub_dir() + stop = threading.Event() + + def size(): + return sum(f.stat().st_size for f in folder.rglob("*") if f.is_file() and not f.is_symlink()) if folder.is_dir() else 0 + base = size() + + def run(): + last = None + while not stop.wait(every): + got = round((size() - base) / 1e9, 1) + if got != last: + out = sys.__stdout__ or sys.stderr + out.write(f" model: {got:.1f} of about {total_gb} GB\n"); out.flush(); last = got + threading.Thread(target=run, daemon=True).start() + return stop + + +def progress(kind): + """show_progress for this kind's model when it is not here yet and no progress bar will show (output nobody watches + live, or the Hub's bars turned off from outside): the stop event, or None.""" + if model_cached(kind): + return None + if sys.stderr.isatty() and not os.environ.get("HF_HUB_DISABLE_PROGRESS_BARS"): + return None + mine = model_id(kind) == KINDS[kind]["model"] + return show_progress(KINDS[kind]["model_gb"] if mine else "?") + + +def main(argv): + if argv[:1] in (["-h"], ["--help"]) or not argv: + print(__doc__.strip()); return 0 + if argv[0] == "--package" and len(argv) == 2 and argv[1] in KINDS: + print(KINDS[argv[1]]["package"]); return 0 + kinds = [k for k in argv[0].split(",") if k] + miss = argv[2].split(",") if argv[1:2] == ["--packages-missing"] and len(argv) == 3 else [] + if any(k not in KINDS for k in kinds + miss) or len(argv) not in (1, 3): + print(f"firstuse: kinds are {', '.join(KINDS)} (python3 tools/audio/firstuse.py -h)", file=sys.stderr); return 2 + said = line(kinds, miss) + if said: + print(said, flush=True) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/tools/audio/pace.py b/tools/audio/pace.py index d386e96c..d3261896 100644 --- a/tools/audio/pace.py +++ b/tools/audio/pace.py @@ -69,6 +69,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent)) import tts # noqa: E402 parse_script, align_lines, transcribe, asr_record: one alignment for the whole harness +import firstuse # noqa: E402 the local Whisper's model: its first download's progress try: import numpy as np except ImportError: # -h on a plain python3; bin/vh pace runs it with numpy @@ -215,9 +216,14 @@ def asr_words(wav, engine, lang, texts, cuts, tmp): import mlx_whisper except ImportError: sys.exit("--align whisper needs mlx-whisper (Apple Silicon; bin/vh pace adds it with --align whisper)") - r = mlx_whisper.transcribe(str(wav), path_or_hf_repo=os.environ.get("WHISPER_MODEL", "mlx-community/whisper-large-v3-turbo"), - word_timestamps=True, language=lang, condition_on_previous_text=False, - initial_prompt="".join(texts)[:120] if lang == "zh" else None) # simplified characters, the terms + stop = firstuse.progress("whisper") # its model's first download (1.6 GB), where no progress bar shows + try: + r = mlx_whisper.transcribe(str(wav), path_or_hf_repo=firstuse.model_id("whisper"), + word_timestamps=True, language=lang, condition_on_previous_text=False, + initial_prompt="".join(texts)[:120] if lang == "zh" else None) # simplified characters, the terms + finally: + if stop: + stop.set() return [{"w": w["word"].strip(), "start": float(w["start"]), "end": float(w["end"])} for sg in r.get("segments", []) for w in sg.get("words", []) if w["word"].strip()] dur, pieces, t0, prev = probe_len(wav), [], 0.0, None diff --git a/tools/audio/tts.py b/tools/audio/tts.py index 54613cb8..b463c922 100644 --- a/tools/audio/tts.py +++ b/tools/audio/tts.py @@ -145,6 +145,8 @@ import urllib.error, urllib.parse, urllib.request, wave from concurrent.futures import Future, ThreadPoolExecutor from pathlib import Path +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import firstuse # noqa: E402 the big first downloads: their sizes, the line before them, their progress RESUME = None # what a stop keeps for a resume, once a line is on disk @@ -253,7 +255,7 @@ def gemini_call(path, body=None, method=None, query=None, timeout=180, tries=3): def no_key(provider): """Exit (1) on a provider with no key: the key it needs, and what works with none on this machine.""" if sys.platform == "darwin" and platform.machine() == "arm64": - free = "the local default needs no key: leave the provider out, bin/vh tts (qwen, free, about 2 GB on first use)" + free = "the local default needs no key: leave the provider out, bin/vh tts (qwen, free, about " + firstuse.gb(firstuse.total(["qwen"])) + " on first use)" else: free = "the local default (qwen) needs no key but only runs on Apple Silicon; here --provider edge needs none (free, online)" sys.exit(f"set {KEY_OF[provider]} for {provider}; {free}") @@ -271,51 +273,7 @@ def hf_cached(model_id): # The provider bin/vh tts uses when none is named: the one place to change it (bin/vh asks: tts.py --default-provider). DEFAULT_PROVIDER = "qwen" -QWEN_MODEL = "mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-8bit" -QWEN_SIZES = {"packages": 0.75, "model": 1.8} # GB on disk the first time: mlx-audio and its packages (uv), the model (Hugging Face) - -def hub_dir(): - """Where the Hugging Face Hub keeps models, worked out as huggingface_hub does (stdlib, before it is installed).""" - if os.environ.get("HF_HUB_CACHE"): - return Path(os.environ["HF_HUB_CACHE"]) - home = os.environ.get("HF_HOME") or os.path.join(os.environ.get("XDG_CACHE_HOME") or os.path.expanduser("~/.cache"), "huggingface") - return Path(home) / "hub" - -def model_dir(model_id): - return hub_dir() / ("models--" + model_id.replace("/", "--")) - -def first_use_line(provider, packages_missing=False): - """The one line bin/vh tts says before a provider's first run downloads gigabytes (or None: nothing that big to fetch): - how much, roughly how long, that the progress shows, and the way around it.""" - if provider != "qwen" or not (sys.platform == "darwin" and platform.machine() == "arm64"): - return None - model_id = os.environ.get("QWEN_TTS_MODEL", QWEN_MODEL) - model = model_id == QWEN_MODEL and not os.path.isdir(os.path.expanduser(model_id)) and not list(model_dir(model_id).glob("snapshots/*/*.safetensors")) - parts = (["its Python packages"] if packages_missing else []) + (["the voice model"] if model else []) - if not parts: - return None - gb = (QWEN_SIZES["packages"] if packages_missing else 0) + (QWEN_SIZES["model"] if model else 0) - return (f" first use of the local voice: about {gb:.1f} GB to download once ({' and '.join(parts)}); a few minutes on a fast line," - f" half an hour or more on a slow one; the progress shows below. To skip it: --provider edge (free, online: the script" - f" goes to Microsoft's voice service)") - -def show_progress(folder, total_gb, every=10.0): - """A line every `every` seconds with how much a download has added to `folder` (the Hub's whole cache: its xet transfer - stages the parts outside the model's own folder), for output nobody watches live, where a progress bar is turned - off. → the thread's stop event.""" - import threading - stop = threading.Event() - def size(): - return sum(f.stat().st_size for f in Path(folder).rglob("*") if f.is_file() and not f.is_symlink()) if Path(folder).is_dir() else 0 - base = size() - def run(): - last = None - while not stop.wait(every): - got = round((size() - base) / 1e9, 1) - if got != last: - print(f" voice model: {got:.1f} of about {total_gb} GB", flush=True); last = got - threading.Thread(target=run, daemon=True).start() - return stop +QWEN_MODEL = firstuse.KINDS["qwen"]["model"] # its size, and the line said before a first download: tools/audio/firstuse.py _QWEN = {} def p_qwen(text, voice, out: Path, tmp: Path, lang, instruct=None): @@ -324,6 +282,7 @@ def p_qwen(text, voice, out: Path, tmp: Path, lang, instruct=None): # progress bar redrawn with \r is noise in output nobody watches live (an agent's). os.environ.setdefault("TRANSFORMERS_VERBOSITY", "error") os.environ.setdefault("HF_HUB_VERBOSITY", "error") + stop = firstuse.progress("qwen") # before the bars are turned off below: it reads whether they will show if not sys.stderr.isatty(): os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1") import contextlib, io @@ -332,10 +291,9 @@ def p_qwen(text, voice, out: Path, tmp: Path, lang, instruct=None): model_id = os.environ.get("QWEN_TTS_MODEL", QWEN_MODEL) if model_id not in _QWEN: fresh = not hf_cached(model_id) - print(f" loading {model_id}" + (" (not downloaded yet: " + (f"{QWEN_SIZES['model']} GB " if model_id == QWEN_MODEL else "") + print(f" loading {model_id}" + (" (not downloaded yet: " + (f"{firstuse.KINDS['qwen']['model_gb']} GB " if model_id == QWEN_MODEL else "") + "into the Hugging Face cache, once)" if fresh else "") + " …", flush=True) - said = io.StringIO() # mlx-audio prints what it loads; shown only when loading fails - stop = show_progress(hub_dir(), QWEN_SIZES["model"] if model_id == QWEN_MODEL else "?") if fresh and not sys.stderr.isatty() else None + said = io.StringIO() # mlx-audio prints what it loads; shown only when loading fails (the progress goes to the real stdout) try: with contextlib.redirect_stdout(said): _QWEN[model_id] = load_model(model_id) @@ -861,9 +819,14 @@ def transcribe_local(wav: Path, lang, vocab=None): the terms go into Whisper's initial prompt (it has no custom vocabulary).""" import mlx_whisper # bin/vh tts adds it with --align local prompt = (",".join(vocab) if vocab else None) or None - r = mlx_whisper.transcribe(str(wav), path_or_hf_repo=os.environ.get("WHISPER_MODEL", "mlx-community/whisper-large-v3-turbo"), - word_timestamps=True, language=lang if lang in ("zh", "en", "ja", "ko") else None, condition_on_previous_text=False, - initial_prompt=prompt) + stop = firstuse.progress("whisper") # its model's first download (1.6 GB), where no progress bar shows + try: + r = mlx_whisper.transcribe(str(wav), path_or_hf_repo=firstuse.model_id("whisper"), + word_timestamps=True, language=lang if lang in ("zh", "en", "ja", "ko") else None, condition_on_previous_text=False, + initial_prompt=prompt) + finally: + if stop: + stop.set() words = [{"w": w["word"].strip(), "start": float(w["start"]), "end": float(w["end"])} for sg in r.get("segments", []) for w in sg.get("words", []) if str(w.get("word", "")).strip()] return str(r.get("text", "")).strip(), words @@ -1205,11 +1168,6 @@ def main(): return voices_main(sys.argv[2:]) if sys.argv[1:] == ["--default-provider"]: # for bin/vh tts, which picks the provider's packages before this runs print(DEFAULT_PROVIDER); return - if sys.argv[1:2] == ["--first-use"] and len(sys.argv) in (3, 4): # bin/vh tts: the line before a big first download - line = first_use_line(sys.argv[2], sys.argv[3:] == ["--packages-missing"]) - if line: - print(line, flush=True) - return ap = argparse.ArgumentParser() ap.add_argument("project"); ap.add_argument("--provider", choices=PROVIDERS, help=f"default {DEFAULT_PROVIDER} (with --resume: the run's provider)") ap.add_argument("--voice"); ap.add_argument("--lang", choices=["zh", "en"], help="spoken side (default zh; en for an English-only script)") diff --git a/tools/ci.sh b/tools/ci.sh index 70f7aad3..17a05833 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1562,47 +1562,102 @@ print(sum("hold-confirm" in x for x in rows(row)))' 2>&1 | tr '\n' ' ') a=$(python3 -c 'import sys; sys.path.insert(0, "tools"); import doctor as d print(d.references_note(0, 37, 0, d.install_says())); print(d.references_note(31, 37, 214e6, None))' 2>&1) b=$(grep -o 'reference repos (about [0-9.]* [MG]B' install.sh | grep -o '[0-9.]* [MG]B') - case "$a" in "0/37 repos fetched → bash references/fetch.sh (all 37: about $b;"*"31/37 repos fetched → bash references/fetch.sh (all 37: about 255 MB, at the size of the 31 here;"*) + case "$a" in "0/37 repos fetched; an agent fetches the one a doc points to when it first needs it"*"all 37 now: bash references/fetch.sh (about $b)"*"31/37 repos fetched;"*"(about 255 MB, at the size of the 31 here)"*) ok "doctor: the reference repos' size from the ones fetched (31 of 37 at 214 MB: about 255 MB), else as install.sh says it ($b)" ;; *) bad "doctor's line for the reference repos: $a (install.sh says: ${b:-nothing found})" ;; esac - # the reference repos are fetched on first use: references/fetch.sh knows each one's size, and says it in one line before - # a first fetch; a name it does not have is said, exit 2 (it used to do nothing) - a=$(bash -c 'cd references && sed -n "/^SIZES=\"/,/^\"/p" fetch.sh | tr " " "\n" | grep -v "^SIZES\|^\"\|^$" | paste - - | cut -f1 | sort' 2>&1) - b=$(grep -E '^(full|sparse|textonly) ' references/fetch.sh | awk '{print $3}' | sort) - c=$(bash references/fetch.sh no-such-repo 2>&1); rc=$? - if [ -n "$b" ] && [ "$a" = "$b" ] && [ "$rc" = 2 ] && case "$c" in "no reference repo named no-such-repo"*) true ;; *) false ;; esac \ - && grep -q '^ else announce "$1" "$2"; clone' references/fetch.sh && grep -q 'REFS=0;' install.sh && grep -q -- '--refs) REFS=1' install.sh - then ok "references/fetch.sh: a size for each of the $(printf '%s\n' "$b" | wc -l | tr -d ' ') reference repos, said before a first fetch; an unknown name exits 2; install.sh fetches them only with --refs" - else bad "references/fetch.sh's sizes or names (exit $rc): $(diff <(printf '%s\n' "$a") <(printf '%s\n' "$b") | head -5 | tr '\n' ' ') | $c"; fi - # doctor --first, the installer's last lines: ready only when a first film has what it needs; what is missing, with how - # to get it; a voice line for this platform; a Chinese font missing is said (Linux) + # the reference repos come on first use: references/fetch.sh says what, from where and how big before it fetches one, + # for each kind of fetch (full, sparse, text only), through a stand-in git; one asked for by name that does not come exits 1; + # every repo has a size; an unknown name exits 2; a full fetch with no network is one line and exit 0; install.sh fetches + # them all only with --refs + ft=$(mktemp -d "${TMPDIR:-/tmp}/vh-fetch.XXXXXX"); mkdir -p "$ft/references" "$ft/bin"; cp references/fetch.sh "$ft/references/" + printf '#!/bin/sh\ncase "$1" in clone) [ -n "$FAIL" ] && { echo "fatal: could not resolve host" >&2; exit 128; }; for a; do d=$a; done; mkdir -p "$d/.git" ;; esac\nexit 0\n' > "$ft/bin/git"; chmod +x "$ft/bin/git" + fe() { env PATH="$ft/bin:$PATH" "$@" bash "$ft/references/fetch.sh" ${FA[@]+"${FA[@]}"} 2>&1; } + FA=(PDoomVideo); a=$(fe); FA=(hyperframes); b=$(fe); FA=(vox-director); c=$(fe) # full, sparse, text only + FA=(Paper-Cut); d=$(fe FAIL=1); rd=$?; FA=(no-such-repo); e=$(fe); re=$?; rm -rf "$ft/references/repos"; FA=(); f=$(fe FAIL=1); rf=$? + sz=$(sed -n '/^SIZES="/,/^"/p' references/fetch.sh | tr " " "\n" | grep -v '^SIZES\|^"\|^$' | paste - - | cut -f1 | sort) + names=$(grep -E '^(full|sparse|textonly) ' references/fetch.sh | awk '{print $3}' | sort) + if case "$a" in "fetching PDoomVideo from github.com/JohnHeibel/PDoomVideo (about "*" MB, read-only"*) true ;; *) false ;; esac \ + && case "$b" in "fetching hyperframes from github.com/heygen-com/hyperframes (about "*) true ;; *) false ;; esac \ + && case "$c" in "fetching vox-director from github.com/Alisa0808/vox-director (under 1 MB, read-only"*) true ;; *) false ;; esac \ + && [ $rd = 1 ] && case "$d" in *"skip Paper-Cut (clone failed: fatal: could not resolve host)"*) true ;; *) false ;; esac \ + && [ $re = 2 ] && case "$e" in "no reference repo named no-such-repo"*) true ;; *) false ;; esac \ + && [ $rf = 0 ] && [ "$(printf '%s\n' "$f" | wc -l | tr -d ' ')" = 1 ] && case "$f" in "skipped $(printf '%s\n' "$names" | wc -l | tr -d ' ') (no network?"*) true ;; *) false ;; esac \ + && [ -n "$names" ] && [ "$sz" = "$names" ] && grep -q 'REFS=0;' install.sh && grep -q -- '--refs) REFS=1' install.sh + then ok "references/fetch.sh: one repo by name says what, where from and how big first (full, sparse and text only), exits 1 when it did not come, 2 for an unknown name; every repo has a size; all of them with no network: one line, exit 0; install.sh only with --refs" + else bad "references/fetch.sh ($rd/$re/$rf): $a | $b | $c | $d | $e | $(printf '%s' "$f" | head -c 200)"; fi + rm -rf "$ft" + # doctor --first, the installer's last lines: ready only when a first film has what it needs; each missing one with how to + # get it; in a Chinese locale a missing Chinese font is not ready; on Linux the render browser's missing libraries are not + # ready, and libraries it could not ask about are "not checked" (exit 3), not ready; an outdated agent is told to update; + # with no python3 at all (bin/vh's bare doctor) it is not ready either (exit 1) a=$(python3 - <<'PY' 2>&1 import sys; sys.path.insert(0, "tools"); import doctor as d ok = lambda n, **k: dict({"name": n, "state": "ok", "install": f"get {n}"}, **k) mods = [ok("node"), ok("ffmpeg"), ok("python3"), ok("uv"), ok("chrome"), ok("chrome-headless-shell", state="missing"), ok("claude-code"), ok("codex", state="missing"), ok("qwen3-tts", state="missing"), ok("mlx-audio")] -checks = [{"name": "browser", "state": "missing"}] -l1, r1 = d.first_film(mods, checks, "darwin-arm64") # no browser yet, but the first render brings its own: ready +nob = [{"name": "browser", "state": "missing"}]; nofont = nob + [{"name": "fonts", "state": "missing"}] +r = [] +r.append(d.first_film(mods, nob, "darwin-arm64")) # the first render brings its own Chrome mods2 = [dict(m, state="missing") if m["name"] in ("uv", "claude-code") else m for m in mods] -l2, r2 = d.first_film(mods2, checks + [{"name": "fonts", "state": "missing"}], "linux-arm64") # no uv, no browser, no agent, no font -print(r1, r2, len(l1), len(l2)); print("\n".join(l1 + ["--"] + l2)) +r.append(d.first_film(mods2, nofont, "linux-arm64", libs=([], True))) # no uv, no browser, no agent +r.append(d.first_film(mods, nofont, "linux-x86_64", env={"LANG": "zh_CN.UTF-8"}, libs=([], True))) # zh, no Chinese font +r.append(d.first_film(mods, nofont, "linux-x86_64", env={"LANG": "en_US.UTF-8"}, libs=([], True))) # en: said, still ready +r.append(d.first_film(mods, nob, "linux-x86_64", env={}, libs=(["libnss3.so", "libnspr4.so"], True))) +r.append(d.first_film(mods, nob, "linux-x86_64", env={}, libs=([], False))) +mods3 = [dict(m, state="outdated", version="1.0") if m["name"] == "claude-code" else m for m in mods] +r.append(d.first_film(mods3, nob, "darwin-arm64")) +print(" ".join(st for _, st in r)) +for lines, _ in r: print("\n".join(lines)); print("--") PY ) - case "$a" in "True False 3 6"*"✓ Ready for a first film: Node, FFmpeg, uv, a browser to render with, Claude Code"*"downloads its own Chrome once"*"- Voice: the first bin/vh tts downloads the local voice once (about 2.5 GB"*"--provider edge"*"--"*"✗ Not ready for a first film yet"*" uv → get uv"*" a browser to render with → get chrome"*" Claude Code or Codex →"*"! Chinese text"*"- Voice: bin/vh tts --provider edge"*) - ok "doctor --first: ready only with Node, FFmpeg, Python, uv, a browser (or a platform whose first render brings one) and an agent; each missing one with how to get it; the voice for the platform; a missing Chinese font said" ;; - *) bad "doctor --first: $(printf '%s' "$a" | head -c 600)" ;; esac - # bin/vh tts: the default provider is said in one place (tts.py), and the local voice's first use is said before it - # downloads, with the size, the time it may take and the way around it; nothing for another provider or a cached model - a=$(python3 tools/audio/tts.py --default-provider 2>&1) - b=$(HF_HOME="$(mktemp -d)" python3 tools/audio/tts.py --first-use qwen --packages-missing 2>&1) - c=$(python3 tools/audio/tts.py --first-use edge --packages-missing 2>&1) - want="first use of the local voice: about 2.5 GB to download once (its Python packages and the voice model)" - case "$(uname -s)-$(uname -m)" in Darwin-arm64) ;; *) want="" ;; esac # elsewhere the local voice does not run, so nothing is said - if [ "$a" = qwen ] && case "$b" in *"$want"*) [ -n "$want" ] || [ -z "$b" ] ;; *) false ;; esac && [ -z "$c" ] \ - && { [ -z "$want" ] || case "$b" in *"--provider edge (free, online"*) true ;; *) false ;; esac; } \ - && grep -q 'prov=$(python3 "$ROOT/tools/audio/tts.py" --default-provider)' bin/vh - then ok "bin/vh tts: the default provider comes from tts.py alone; the local voice's first use is said before its 2.5 GB download (Apple Silicon), with the way around it; nothing for edge" - else bad "bin/vh tts's default and first-use line: $a | $b | $c"; fi + ft=$(mktemp -d "${TMPDIR:-/tmp}/vh-nopy.XXXXXX"); mkdir -p "$ft/bin" + for f in /usr/bin/* /bin/*; do n=$(basename "$f"); case "$n" in python*|pydoc*) continue ;; esac; [ -e "$ft/bin/$n" ] || ln -s "$f" "$ft/bin/$n"; done + for n in node ffmpeg git; do command -v "$n" >/dev/null && ln -sf "$(command -v "$n")" "$ft/bin/$n"; done + b=$(PATH="$ft/bin" "$VH_BASH" "$ROOT/bin/vh" doctor --first 2>&1); rb=$?; rm -rf "$ft" + if case "$a" in "ready not not ready not unchecked not"*) true ;; *) false ;; esac \ + && case "$a" in *"✓ Ready for a first film: Node, FFmpeg, Python 3, uv, a browser to render with, Claude Code"*"downloads its own Chrome once"*"- Voice: the first bin/vh tts downloads the local voice once (about 2.6 GB"*"--provider edge needs only a small package"*) true ;; *) false ;; esac \ + && case "$a" in *" uv (it runs the Python tools"*" a browser to render with → get chrome"*" Claude Code or Codex →"*"- Voice: bin/vh tts --provider edge (free, online; only a small package)"*) true ;; *) false ;; esac \ + && case "$a" in *" a Chinese font (Chinese text would draw as boxes) → sudo apt install fonts-noto-cjk"*"! Chinese text: no Chinese font here"*) true ;; *) false ;; esac \ + && case "$a" in *"the render browser's system libraries (libnspr4.so, libnss3.so) → sudo apt install libnspr4 libnss3"*"? Nearly ready"*"not checked:"*"Claude Code is out of date (1.0) → update it"*) true ;; *) false ;; esac \ + && [ $rb = 1 ] && case "$b" in *"python3 not found"*) true ;; *) false ;; esac + then ok "doctor --first: ready only with Node, FFmpeg, Python 3, uv, a browser (or a platform whose first render brings one) and its libraries, an agent, a Chinese font in a Chinese locale; each missing one with how to get it; libraries not asked about are not checked (3); an old agent is told to update; no python3: not ready (1)" + else bad "doctor --first (no python3: exit $rb): $(printf '%s' "$a" | head -c 900) | $(printf '%s' "$b" | head -3)"; fi + # the big first downloads (tools/audio/firstuse.py) are said by bin/vh before they start: tts with the local voice and with + # --align local, voices audition with the local voice, pace --align whisper (uv and the Hub stood in for: uv says the + # packages are not cached); uv then runs without -q, so its download lines show; a project with no script gets the sample + # and no package at all; the model's progress reaches the terminal even inside the redirect a loader runs in. Apple Silicon: + # the lines; elsewhere these do not run, and nothing is said + ft=$(mktemp -d "${TMPDIR:-/tmp}/vh-firstuse.XXXXXX"); mkdir -p "$ft/bin" "$ft/p/audio" "$ft/q"; echo "一句话" > "$ft/p/audio/script.txt"; : > "$ft/t.txt" + printf '#!/bin/sh\necho "uv $*" >> "%s/calls"\ncase "$*" in *--offline*) exit 1 ;; esac\nexit 0\n' "$ft" > "$ft/bin/uv"; chmod +x "$ft/bin/uv" + fu() { env PATH="$ft/bin:$PATH" HF_HOME="$ft/hf" "$VH_BASH" "$ROOT/bin/vh" "$@" 2>&1; } + a=$(fu tts "$ft/p"); b=$(fu tts "$ft/p" --align local); c=$(fu voices audition --provider qwen --voices x --text "$ft/t.txt"); d=$(fu pace "$ft/p" --align whisper) + calls=$(cat "$ft/calls" 2>/dev/null); : > "$ft/calls"; e=$(fu tts "$ft/q"); re=$?; qcalls=$(cat "$ft/calls" 2>/dev/null) + g=$(python3 - "$ft/hf" <<'PY' +import contextlib, io, os, subprocess, sys, time +code = ("import contextlib, io, sys, time, os; sys.path.insert(0, 'tools/audio'); import firstuse; d = sys.argv[1]; os.makedirs(d, exist_ok=True)\n" + "with contextlib.redirect_stdout(io.StringIO()):\n" + " st = firstuse.show_progress(1.8, every=0.2, folder=d)\n" + " for i in range(3): open(os.path.join(d, f'x{i}'), 'wb').write(b'0' * 100_000_000); time.sleep(0.35)\n" + " st.set()\n") +r = subprocess.run([sys.executable, "-c", code, sys.argv[1]], capture_output=True, text=True) +print(r.stdout.count("model:")) +PY +) + case "$(uname -s) $(uname -m)" in + "Darwin arm64") + if case "$a" in *"first use of the local voice: about 2.6 GB to download once"*"--provider edge needs only a small package"*) true ;; *) false ;; esac \ + && case "$b" in *"first use of the local Whisper and the local voice: about 6.2 GB"*) true ;; *) false ;; esac \ + && case "$c" in *"first use of the local voice"*) true ;; *) false ;; esac && case "$d" in *"first use of the local Whisper: about 3.6 GB"*"--align gemini"*) true ;; *) false ;; esac \ + && printf '%s\n' "$calls" | grep -q '^uv run --no-project --with mlx-audio' && ! printf '%s\n' "$calls" | grep -q '^uv run -q --no-project --with mlx-audio' \ + && [ $re = 1 ] && [ -z "$qcalls" ] && [ -s "$ft/q/audio/script.txt" ] && [ "${g:-0}" -ge 2 ] + then ok "first downloads: tts, tts --align local, voices audition and pace --align whisper say theirs first (size, the way around), uv shows its lines; no script: the sample and no package; the model's progress gets past a redirect" + else bad "first downloads: $a | $b | $c | $d | calls: $(printf '%s' "$calls" | head -c 300) | no script ($re): $qcalls | progress lines: $g"; fi ;; + *) + if ! printf '%s' "$a$b$c$d" | grep -q "first use of" && [ $re = 1 ] && [ -z "$qcalls" ] && [ "${g:-0}" -ge 2 ] + then ok "first downloads: not on this platform (the local voice and Whisper are Apple Silicon only), so nothing said; no script: the sample and no package; the model's progress gets past a redirect" + else bad "first downloads here: $a | $b | no script ($re): $qcalls | progress lines: $g"; fi ;; + esac + rm -rf "$ft" # recipes sample: bad usage exits 2 before any render (an unknown id, a sequence, an unknown style); list --json names # the sheet a recipe carries (recipes check, above, holds every sketch to its sheet) vh recipes sample no-such-recipe >/dev/null 2>&1; rc=$?; vh recipes sample launch-15s >/dev/null 2>&1; rc2=$? diff --git a/tools/commands.json b/tools/commands.json index c9373420..228499bc 100644 --- a/tools/commands.json +++ b/tools/commands.json @@ -1631,7 +1631,7 @@ "--candidates N: N takes a block, the one nearest the narration's median voice kept (N × the synthesis);", "warns of a line far off the take's seconds per character, and (with --align) of a phrase heard twice;", "--resume: continue the last run after a failed synthesis or transcription, same script and command)", - "providers: qwen (default, local open-source Qwen3-TTS; its first use downloads about 2.5 GB, said first, with the progress) | say | edge | dashscope | elevenlabs | gemini | gemini-lite | minimax" + "providers: qwen (default, local open-source Qwen3-TTS; its first use downloads about 2.6 GB, said first, with the progress) | say | edge | dashscope | elevenlabs | gemini | gemini-lite | minimax" ] } ] diff --git a/tools/doctor.py b/tools/doctor.py index 8976b6b8..1c18ac55 100644 --- a/tools/doctor.py +++ b/tools/doctor.py @@ -4,7 +4,8 @@ (bin/vh passes what its own finders found: --chrome, --hf-chrome, --hf-pin, --webgl) --json the same as JSON (below), the lines a person reads not printed --first only the few lines a first film needs (the installer ends with them): ready or not, what is missing - for a first silent film and how to get it, how a voice comes here. Exit 1 when it is not ready + for a first silent film and how to get it, how a voice comes here. Exit 1 when it is not ready, 3 when + nothing is missing but something could not be checked (the render browser's libraries on Linux) --fill-local also write LOCAL.md's machine lines (硬件, 已装工具, 已装引擎) from this check, where they still hold the template's {…}; with no LOCAL.md, LOCAL.example.md is copied first. A line a person wrote stays; the other lines' {…} are their defaults (the installer runs this) @@ -30,7 +31,8 @@ a whole copy stays as it was when the repo moves on); studio-icon, the launcher bin/vh studio --install-icon makes (installed or not, which clone it runs, made by an earlier launcher or picture); caches, whether the folders a first run downloads into (uv's, npm's, Hugging Face's, HyperFrames', bin/vh's own) can be written, tried with a file made and removed. -Exit 0: it is a report (2 on a usage error or an unreadable table; with --first, 1 when a first film still lacks something). +Exit 0: it is a report (2 on a usage error or an unreadable table; with --first, 1 when a first film still lacks something, 3 +when nothing is missing but something could not be checked). --json, "version": 1 (these fields stay; new ones may be added): {"version", "tool", "platform", "modules": [{"name", "kind", "status" ("planned" when nothing calls it yet, else "used"), "required", "state", "found", "version", "keys": @@ -112,50 +114,99 @@ def install_says(): def references_note(have, want, fetched, said): - """doctor's line for references/repos when some are not fetched: the whole set's size worked out from the ones that - are (fetched: their bytes), else what install.sh says (said), else none.""" + """doctor's line for references/repos when not all are fetched, which is the default (they come on first use): the + whole set's size worked out from the ones that are (fetched: their bytes), else what install.sh says (said), else none.""" size = f"about {mb_text(fetched * want / have)}, at the size of the {have} here" if have and fetched else f"about {said}" if said else None - return (f"{have}/{want} repos fetched → bash references/fetch.sh (all {want}{': ' + size if size else ''}; agents read them for the case studies;" - " the one a doc points to, references/repos//…: bash references/fetch.sh )") + return (f"{have}/{want} repos fetched; an agent fetches the one a doc points to when it first needs it (bash references/fetch.sh ," + f" which says its size first); all {want} now: bash references/fetch.sh{' (' + size + ')' if size else ''}") OWN_CHROME = ("darwin-arm64", "darwin-x86_64", "linux-x86_64") # where HyperFrames downloads its own chrome-headless-shell -LOCAL_VOICE = "about 2.5 GB" # the local voice's first use: mlx-audio and its packages (about 0.75 GB) and the model (1.8 GB on disk) +BROWSER_LIBS = {"libnss3.so": "libnss3", "libnspr4.so": "libnspr4"} # what a fresh Ubuntu with ffmpeg still lacked for it (engines/README.md) -def first_film(mods, checks, plat): - """--first, the few lines install.sh ends with: is this machine ready for a first (silent) film, what it lacks for - one, and how a voice comes. → (lines, ready). Ready only with nothing missing that the first film needs: Node, FFmpeg, - Python 3, uv, a browser to render with (or a platform where the first render downloads its own), and an agent.""" +def zh_locale(env=os.environ): + """The person's language is Chinese: the first of LC_ALL, LC_MESSAGES, LANG that is set starts with zh.""" + v = next((env[k] for k in ("LC_ALL", "LC_MESSAGES", "LANG") if env.get(k)), "") + return v.lower().startswith("zh") + + +def browser_libs(plat, path=None, run=subprocess.run): + """Linux: the system libraries the render browser needs that are missing → (missing .so names, checked). With a browser + found, what ldd says is "not found" in it; with none yet on a platform where the first render downloads one, whether the + linker knows libnss3 and libnspr4 (ldconfig -p). Not Linux: nothing to check ([], True). No ldd or ldconfig: ([], False).""" + if not plat.startswith("linux"): + return [], True + try: + if path and os.path.isfile(path): + out = run(["ldd", path], capture_output=True, text=True, timeout=20).stdout + return sorted({ln.split()[0] for ln in out.splitlines() if "not found" in ln}), True + ldc = shutil.which("ldconfig") or ("/sbin/ldconfig" if os.path.exists("/sbin/ldconfig") else None) + if not ldc: + return [], False + out = run([ldc, "-p"], capture_output=True, text=True, timeout=20).stdout + return [so for so in BROWSER_LIBS if so not in out], True + except (OSError, subprocess.SubprocessError): + return [], False + + +def first_film(mods, checks, plat, found_by=None, env=os.environ, libs=None): + """--first, the few lines install.sh ends with: is this machine ready for a first (silent) film, what it lacks for one, + and how a voice comes. → (lines, "ready" | "not" | "unchecked"). Ready only with nothing missing a first film needs: + Node, FFmpeg, Python 3, uv, a browser to render with (or a platform where the first render downloads its own) and the + system libraries it needs (Linux), an agent, and in a Chinese locale a Chinese font. "unchecked": nothing missing, but + the browser's libraries could not be checked. libs: browser_libs's answer, given by the tests.""" + sys.path.insert(0, str(ROOT / "tools" / "audio")) + import firstuse m, c = {x["name"]: x for x in mods}, {x["name"]: x for x in checks} - lack = [] - for name, what in (("node", "Node 22 or newer"), ("ffmpeg", "FFmpeg"), ("python3", "Python 3"), ("uv", "uv")): + lack, unsure = [], [] + for name, what in (("node", "Node 22 or newer"), ("ffmpeg", "FFmpeg"), ("python3", "Python 3"), + ("uv", "uv (it runs the Python tools: contact sheets, sound checks, the voice)")): r = m.get(name) if r and r["state"] != "ok": lack.append(f"{what} → {r.get('install') or 'install it'}") own = plat in OWN_CHROME if (c.get("browser") or {}).get("state") != "ok" and not own: lack.append(f"a browser to render with → {(m.get('chrome') or {}).get('install') or 'set CHROME_PATH'}") + elif plat.startswith("linux"): + found_by = found_by or {} + missing, checked = libs if libs is not None else browser_libs(plat, found_by.get("hf-chrome") or found_by.get("chrome")) + missing = sorted(missing) + if missing: + pkgs = [BROWSER_LIBS[so] for so in missing if so in BROWSER_LIBS] + lack.append(f"the render browser's system libraries ({', '.join(missing)}) → " + + (f"sudo apt install {' '.join(pkgs)}" if len(pkgs) == len(missing) else "install the packages that give them")) + elif not checked: + unsure.append("the render browser's system libraries: no ldd or ldconfig here to ask; the first render names any it misses" + " (engines/README.md, Linux:渲染前要先备好的三样)") agents = [w for n, w in (("claude-code", "Claude Code"), ("codex", "Codex")) if (m.get(n) or {}).get("state") == "ok"] + old = [(w, m[n]) for n, w in (("claude-code", "Claude Code"), ("codex", "Codex")) if (m.get(n) or {}).get("state") == "outdated"] if not agents: - lack.append("Claude Code or Codex → claude.com/claude-code, or npm install -g @openai/codex") + lack += ([f"{w} is out of date ({r.get('version') or r.get('note') or 'too old'}) → update it" for w, r in old] if old else + ["Claude Code or Codex → claude.com/claude-code, or npm install -g @openai/codex"]) + font = (c.get("fonts") or {}).get("state") == "missing" + if font and zh_locale(env): + lack.append("a Chinese font (Chinese text would draw as boxes) → sudo apt install fonts-noto-cjk") if lack: lines = ["✗ Not ready for a first film yet. It still needs:"] + [f" {x}" for x in lack] + elif unsure: + lines = [f"? Nearly ready for a first film: Node, FFmpeg, Python 3, uv and {' and '.join(agents)} are here; not checked:"] + [f" {x}" for x in unsure] else: - lines = [f"✓ Ready for a first film: Node, FFmpeg, uv, a browser to render with, {' and '.join(agents)}"] - if (m.get("chrome-headless-shell") or {}).get("state") != "ok" and own: - lines.append(" The first render downloads its own Chrome once (about 0.2 GB).") - if (c.get("fonts") or {}).get("state") == "missing": + lines = [f"✓ Ready for a first film: Node, FFmpeg, Python 3, uv, a browser to render with, {' and '.join(agents)}"] + if not lack and (m.get("chrome-headless-shell") or {}).get("state") != "ok" and own: + lines.append(" The first render downloads its own Chrome once (about 0.2 GB).") + if font and not zh_locale(env): lines.append("! Chinese text: no Chinese font here, so it would draw as boxes → sudo apt install fonts-noto-cjk") if plat == "darwin-arm64": if (m.get("qwen3-tts") or {}).get("state") == "ok" and (m.get("mlx-audio") or {}).get("state") == "ok": lines.append("✓ Voice: the local voice is downloaded.") else: - lines.append(f"- Voice: the first bin/vh tts downloads the local voice once ({LOCAL_VOICE}; it says so first and shows the progress)." - " With --provider edge it downloads nothing (free, online).") + lines.append(f"- Voice: the first bin/vh tts downloads the local voice once (about {firstuse.gb(firstuse.total(['qwen']))};" + " it says so first and shows the progress). --provider edge needs only a small package (free, online).") else: - lines.append("- Voice: bin/vh tts --provider edge (free, online), or a cloud voice with a key; the local voice needs Apple Silicon.") - return lines, not lack + lines.append("- Voice: bin/vh tts --provider edge (free, online; only a small package), or a cloud voice with a key;" + " the local voice needs Apple Silicon.") + return lines, "not" if lack else "unchecked" if unsure else "ready" def this_platform(): @@ -571,7 +622,7 @@ def cache_homes(has_chrome=False): return [ ("uv", uv or str(home("~/.cache/uv")), "the Python packages of beats, music, qa, tts and the other uv tools", "UV_CACHE_DIR="), ("npm", env("npm_config_cache") or env("NPM_CONFIG_CACHE") or str(home("~/.npm")), "bin/vh new's npm install and every npx hyperframes", "NPM_CONFIG_CACHE="), - ("Hugging Face", env("HF_HOME") or str(home("~/.cache/huggingface")), "the local voice's model, about 2 GB", "HF_HOME="), + ("Hugging Face", env("HF_HOME") or str(home("~/.cache/huggingface")), "the local voice's model, 1.8 GB", "HF_HOME="), ("HyperFrames", env("HYPERFRAMES_FONT_CACHE_DIR") or str(home("~/.cache/hyperframes/fonts")), "the fonts a film asks for; its Chrome is already there", "HYPERFRAMES_FONT_CACHE_DIR=") if has_chrome else ("HyperFrames", str(home("~/.cache/hyperframes")), "its Chrome on a first snapshot or render, about 200 MB, and its fonts", @@ -627,7 +678,7 @@ def repo_checks(webgl, found_by): if have >= want: out.append({"name": "references", "state": "ok", "note": f"{have}/{want} repos fetched, {size_of(ROOT / 'references' / 'repos')}"}) else: - out.append({"name": "references", "state": "missing", "note": references_note(have, want, bytes_of(ROOT / "references" / "repos") if have else 0, install_says())}) + out.append({"name": "references", "state": "ok", "note": references_note(have, want, bytes_of(ROOT / "references" / "repos") if have else 0, install_says())}) local = ROOT / "LOCAL.md" if not local.exists(): out.append({"name": "local_md", "state": "missing", "note": "no LOCAL.md → bin/vh doctor --fill-local (copies LOCAL.example.md, writes this machine's lines)"}) @@ -902,9 +953,9 @@ def main(argv): print(said, file=sys.stderr if a["json"] else sys.stdout) checks = repo_checks(a["webgl"], found_by) if a["first"] and not a["json"]: - lines, ready = first_film(mods, checks, this_platform()) + lines, state = first_film(mods, checks, this_platform(), found_by) print("\n".join(lines)) - return 0 if ready else 1 + return {"ready": 0, "not": 1, "unchecked": 3}[state] first = [m.get("first_run") for m, r in zip(t["modules"], mods) if m.get("first_run") and r["state"] == "missing"] counts = {} for x in mods + checks: diff --git a/tools/modules.json b/tools/modules.json index 82e0a1e4..a48cba20 100644 --- a/tools/modules.json +++ b/tools/modules.json @@ -242,8 +242,8 @@ "commands": ["tts", "voices"], "required": false, "check": {"hf_model": {"env": "QWEN_TTS_MODEL", "default": "mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-8bit"}}, - "first_run": "Qwen3-TTS model 2 GB", - "install": {"macos": "the first bin/vh tts with the default provider fetches it (about 2 GB) from Hugging Face"} + "first_run": "Qwen3-TTS model 1.8 GB", + "install": {"macos": "the first bin/vh tts with the default provider fetches it (1.8 GB) from Hugging Face, said first"} }, { "name": "mlx-audio", @@ -257,8 +257,8 @@ "commands": ["tts", "voices"], "required": false, "check": {"uv": ["mlx-audio"]}, - "first_run": "mlx-audio 0.75 GB", - "install": {"macos": "the first bin/vh tts with the default provider fetches it and its packages (about 750 MB)"} + "first_run": "mlx-audio 0.8 GB", + "install": {"macos": "the first bin/vh tts with the default provider fetches it and its packages (about 0.8 GB), said first"} }, { "name": "mlx-whisper", From 3284d197209a1bf9d4808b928d9fc52f54400860 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 04:17:58 +0800 Subject: [PATCH 05/14] ci: the tts --provider check gives its project a script (with none, tts now writes the sample and fetches nothing) --- tools/ci.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/ci.sh b/tools/ci.sh index 17a05833..30f83e58 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1182,8 +1182,9 @@ PY [ $rc = 2 ] && [ $a = 2 ] && [ -z "$(ls -d "$t"/*-cf2 "$t"/*-cf3 2>/dev/null)" ] && ok "bin/vh new refuses a vertical canvas-film and an unknown --engine" \ || bad "bin/vh new --engine: --aspect 9:16 exited $rc, an unknown engine $a" rm -rf "$t" - # tts picks the uv dependencies from --provider too (a fake uv prints the command instead of running it) - t=$(mktemp -d "${TMPDIR:-/tmp}/vh-ci.XXXXXX"); printf '#!/bin/sh\necho "$*"\n' > "$t/uv"; chmod +x "$t/uv" + # tts picks the uv dependencies from --provider too (a fake uv prints the command instead of running it; a script is there, + # as with none tts writes the sample and fetches nothing) + t=$(mktemp -d "${TMPDIR:-/tmp}/vh-ci.XXXXXX"); printf '#!/bin/sh\necho "$*"\n' > "$t/uv"; chmod +x "$t/uv"; mkdir -p "$t/audio"; echo "A line." > "$t/audio/script.txt" a=$(PATH="$t:$PATH" vh tts "$t" --provider edge --lang en; PATH="$t:$PATH" DASHSCOPE_API_KEY=ci vh tts "$t" --provider=dashscope) case "$a" in *"--with edge-tts "*"--provider edge"*"--with dashscope "*) ok "tts --provider picks the provider's dependencies" ;; *) bad "tts --provider: uv got '$a'" ;; esac From 66a97815d862166d93e41f62abac8bf9d28e6f12 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 03:41:44 +0800 Subject: [PATCH 06/14] Mirrors in one step: the installer falls back to them when the official npm registry does not answer, and every later download follows - tools/mirrors.txt: each kind of download, its variable, the official source, the mainland-China mirror, who runs it. - This machine's settings in $XDG_CONFIG_HOME/ovh/settings.json (tools/settings.py, bin/vh settings): mirror cn|off|auto. - bin/vh exports the mirror variables for everything it runs when the mirror is cn (a variable already set wins); HyperFrames' Chrome is fetched from the mirror by bin/vh new, install.sh and settings chrome, as HyperFrames has no setting for it. - install.sh tries registry.npmjs.org for 5 s; only when it does not answer and the mirror does, it keeps cn and says so; --mirror cn|off forces it either way. doctor says which sources are in use. - README: the China network line; homepage and overview: 74 commands. --- AGENTS.md | 2 +- CLAUDE.md | 2 +- README.md | 5 +- README.zh-CN.md | 5 +- bin/vh | 37 +++++- changes/first-run-mirrors.md | 7 ++ docs/assets/overview.en.svg | 2 +- docs/assets/overview.zh.svg | 2 +- docs/site/index.html | 4 +- install.sh | 20 ++- tools/ci.sh | 21 ++++ tools/commands.json | 19 +++ tools/doctor.py | 11 ++ tools/mirrors.txt | 19 +++ tools/schemas/output/settings.schema.json | 30 +++++ tools/settings.py | 145 ++++++++++++++++++++++ tools/test_contract.py | 6 +- 17 files changed, 320 insertions(+), 17 deletions(-) create mode 100644 changes/first-run-mirrors.md create mode 100644 tools/mirrors.txt create mode 100644 tools/schemas/output/settings.schema.json create mode 100644 tools/settings.py diff --git a/AGENTS.md b/AGENTS.md index f6067dc5..a0adeae2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -138,7 +138,7 @@ OpenVideoHarness/ ├── CLAUDE.md / AGENTS.md 入口(本文件;AGENTS.md 由 bin/vh sync-agents 生成,内容相同) ├── README.md / README.zh-CN.md 给人看的说明;CONTRIBUTING.md 是改本仓库时的规则;install.sh 一键安装 ├── LOCAL.md 本机环境(不入库;模板是 LOCAL.example.md) -├── bin/vh 命令行:doctor · setup · install-skill · sync-agents · sound · commands · status · projects · cancel · history · activity · know · artifacts · studio · types · effort · new · footage · assets · scout · ref · web · review · gate · desk · concept · breakdown · cast · style · recipes · storyboard · rhythm · words · edit · bgm · tts · pace · voices · captions · timeline · remap · timemap · beats · music · sfx · hf-init · determinism · image · model3d · hdri · hf · components · frames · cues · readcheck · textcheck · fonts · sheet · proxy · thumbs · peaks · render · patch · versions · check · mix · qa · mux · deliver · looks · clean · gif · cover-preview +├── bin/vh 命令行:doctor · setup · settings · install-skill · sync-agents · sound · commands · status · projects · cancel · history · activity · know · artifacts · studio · types · effort · new · footage · assets · scout · ref · web · review · gate · desk · concept · breakdown · cast · style · recipes · storyboard · rhythm · words · edit · bgm · tts · pace · voices · captions · timeline · remap · timemap · beats · music · sfx · hf-init · determinism · image · model3d · hdri · hf · components · frames · cues · readcheck · textcheck · fonts · sheet · proxy · thumbs · peaks · render · patch · versions · check · mix · qa · mux · deliver · looks · clean · gif · cover-preview ├── tools/ bin/vh 背后的脚本;commands.json 是命令表(`bin/vh commands` 按阶段列出),modules.json 是外接模块表(`bin/vh doctor` 报这台机器能用哪些),audio/README.md 是声音命令的参数手册,desk/README.md 是审阅台的读取约定;ci.sh 是仓库自检 ├── skills/ 轻量 skill(`bin/vh install-skill` 装上的是指回这里的短桩,`git pull` 后不用重装):open-video-harness 在任何目录把做视频的请求引到本仓库;open-video-harness-web 用已装浏览器查网页事实、存参考页 ├── video-types/ 11 类视频(09、11 实验中):工作流、审美、禁止项、Prompt 增量块、自查重点、案例 diff --git a/CLAUDE.md b/CLAUDE.md index 489e7213..25540d68 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -135,7 +135,7 @@ OpenVideoHarness/ ├── CLAUDE.md / AGENTS.md 入口(本文件;AGENTS.md 由 bin/vh sync-agents 生成,内容相同) ├── README.md / README.zh-CN.md 给人看的说明;CONTRIBUTING.md 是改本仓库时的规则;install.sh 一键安装 ├── LOCAL.md 本机环境(不入库;模板是 LOCAL.example.md) -├── bin/vh 命令行:doctor · setup · install-skill · sync-agents · sound · commands · status · projects · cancel · history · activity · know · artifacts · studio · types · effort · new · footage · assets · scout · ref · web · review · gate · desk · concept · breakdown · cast · style · recipes · storyboard · rhythm · words · edit · bgm · tts · pace · voices · captions · timeline · remap · timemap · beats · music · sfx · hf-init · determinism · image · model3d · hdri · hf · components · frames · cues · readcheck · textcheck · fonts · sheet · proxy · thumbs · peaks · render · patch · versions · check · mix · qa · mux · deliver · looks · clean · gif · cover-preview +├── bin/vh 命令行:doctor · setup · settings · install-skill · sync-agents · sound · commands · status · projects · cancel · history · activity · know · artifacts · studio · types · effort · new · footage · assets · scout · ref · web · review · gate · desk · concept · breakdown · cast · style · recipes · storyboard · rhythm · words · edit · bgm · tts · pace · voices · captions · timeline · remap · timemap · beats · music · sfx · hf-init · determinism · image · model3d · hdri · hf · components · frames · cues · readcheck · textcheck · fonts · sheet · proxy · thumbs · peaks · render · patch · versions · check · mix · qa · mux · deliver · looks · clean · gif · cover-preview ├── tools/ bin/vh 背后的脚本;commands.json 是命令表(`bin/vh commands` 按阶段列出),modules.json 是外接模块表(`bin/vh doctor` 报这台机器能用哪些),audio/README.md 是声音命令的参数手册,desk/README.md 是审阅台的读取约定;ci.sh 是仓库自检 ├── skills/ 轻量 skill(`bin/vh install-skill` 装上的是指回这里的短桩,`git pull` 后不用重装):open-video-harness 在任何目录把做视频的请求引到本仓库;open-video-harness-web 用已装浏览器查网页事实、存参考页 ├── video-types/ 11 类视频(09、11 实验中):工作流、审美、禁止项、Prompt 增量块、自查重点、案例 diff --git a/README.md b/README.md index d4ca7edb..fd69ccc3 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ Say what the film is about, who it's for and where it will be shown; a long brie ## What's in the box -The tools follow the work: think, gather, make, check and deliver. Each name below is a `bin/vh` command; `bin/vh commands` lists all 73 commands by pipeline stage, and any command takes `-h`. +The tools follow the work: think, gather, make, check and deliver. Each name below is a `bin/vh` command; `bin/vh commands` lists all 74 commands by pipeline stage, and any command takes `-h`. | | Command | What it does | |---|---|---| @@ -415,6 +415,7 @@ By default the installer registers the skills for both agents and uses about 400 ```bash bash install.sh --dir ~/code/OpenVideoHarness # install somewhere else bash install.sh --refs # fetch all 37 reference repos now (about 300 MB) +bash install.sh --mirror cn # use the mainland-China mirrors (--mirror off: never; without it the official sources come first) bash install.sh --no-skill # don't register the global skill bash install.sh --no-icon # leave OVH Studio out of your applications (bin/vh studio --install-icon adds it later) ``` @@ -423,7 +424,7 @@ bash install.sh --no-icon # leave OVH Studio out of your - The installer fetches only the newest commit: the repo itself is about 95 MB to download and 200 MB on disk, before its packages and the reference repos. To contribute or browse the history, `git clone` normally and run `bin/vh setup`. - To update, run the installer again with the same options (or `git pull`); `LOCAL.md` and `projects/` are left alone, and it stops before overwriting files you changed. The installed skills are short stubs that read `skills/` in the clone, so they follow the update; `bin/vh doctor` says in the rare case one needs `bin/vh install-skill` again. - The showcase videos aren't in git; to rebuild a showcase locally, `tools/fetch_media.sh` downloads them from the release to where its scripts expect them. -- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, the sound tools' Python packages about 0.7 GB, and the default local voice about 2.6 GB (its packages 0.8 GB, its model 1.8 GB), which `bin/vh tts` says before it starts and shows the progress of (`--provider edge` needs only a small package). The local Whisper behind `--align local` is about 3.6 GB more, said the same way (measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). If npm, PyPI, Hugging Face or Google Fonts are blocked or slow where you are, [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) has the mirror settings. +- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, the sound tools' Python packages about 0.7 GB, and the default local voice about 2.6 GB (its packages 0.8 GB, its model 1.8 GB), which `bin/vh tts` says before it starts and shows the progress of (`--provider edge` needs only a small package). The local Whisper behind `--align local` is about 3.6 GB more, said the same way (measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). Where the official sources are blocked: the installer tries the official npm registry first, and when it does not answer in 5 s and the mainland-China mirror does, it switches to the mirrors (npmmirror, Tsinghua's TUNA, hf-mirror, listed in `tools/mirrors.txt`), says so, and every later `bin/vh` download follows (npm, Python packages, the local voice's model, Electron, the Chrome renders use); `bin/vh settings mirror off` turns that off. GitHub itself has no mirror: cloning the repo still needs GitHub. More on the wiki's [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) page. Skill only: `npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`. It's a pointer: on first use it asks before installing the full workbench. That copy stays as it was when the repo changes; once the workbench is installed, `bin/vh install-skill` replaces it with a stub that follows the clone. diff --git a/README.zh-CN.md b/README.zh-CN.md index 72f71d3b..0fca0b0a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -265,7 +265,7 @@ curl -fsSL https://raw.githubusercontent.com/ZLHad/OpenVideoHarness/main/install ## 工具一览 -工具跟着做片子的顺序走:想、找料、做、查和交付。下表每个名字都是一条 `bin/vh` 命令;`bin/vh commands` 按流程阶段列出全部 73 条命令,每条命令加 `-h` 看用法。 +工具跟着做片子的顺序走:想、找料、做、查和交付。下表每个名字都是一条 `bin/vh` 命令;`bin/vh commands` 按流程阶段列出全部 74 条命令,每条命令加 `-h` 看用法。 | | 命令 | 做什么 | |---|---|---| @@ -415,6 +415,7 @@ AI 听不见,所以声音尽量做成能计算、能测量的。 ```bash bash install.sh --dir ~/code/OpenVideoHarness # 装到别的位置 bash install.sh --refs # 安装时就把 37 个参考仓库拉全(约 300 MB) +bash install.sh --mirror cn # 直接用国内镜像(--mirror off:不用;不写时先试官方源) bash install.sh --no-skill # 不注册全局 skill bash install.sh --no-icon # 不把 OVH Studio 放进应用程序(以后 bin/vh studio --install-icon 再放) ``` @@ -423,7 +424,7 @@ bash install.sh --no-icon # 不把 OVH Studio 放进应 - 安装脚本只拉最新的一个提交,仓库本身下载约 95 MB、占约 200 MB 磁盘,依赖和参考仓库另算;想参与贡献或翻历史,就正常 `git clone`,再运行 `bin/vh setup`。 - 更新:用同样的参数再运行一次安装命令(或者 `git pull`);`LOCAL.md` 和 `projects/` 不动,要覆盖你改过的文件时会先停下来。装出去的 skill 是指回克隆里 `skills/` 的短桩,跟着一起更新;少数要重装的时候(`bin/vh install-skill`),`bin/vh doctor` 会说。 - 样片的视频不在 git 里,要在本地复现样片时运行 `tools/fetch_media.sh`,它从 Release 下载到脚本要的位置。 -- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,声音工具的 Python 依赖约 0.7 GB,默认的本地配音约 2.6 GB(依赖 0.8 GB、模型 1.8 GB;`bin/vh tts` 开始前会先说,并显示进度;`--provider edge` 只要一个小包);`--align local` 用的本地 Whisper 另需约 3.6 GB,同样先说(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络连不上 npm、PyPI、Hugging Face 或 Google Fonts 时,镜像设置见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 +- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,声音工具的 Python 依赖约 0.7 GB,默认的本地配音约 2.6 GB(依赖 0.8 GB、模型 1.8 GB;`bin/vh tts` 开始前会先说,并显示进度;`--provider edge` 只要一个小包);`--align local` 用的本地 Whisper 另需约 3.6 GB,同样先说(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络:安装时先试官方的 npm 源,5 秒内没有应答、国内镜像有,就改用国内镜像(npmmirror、清华 TUNA、hf-mirror,列在 `tools/mirrors.txt`)并说一声,之后 `bin/vh` 的下载(npm、Python 包、本地配音模型、Electron、渲染用的 Chrome)都跟着走;`bin/vh settings mirror off` 关掉。GitHub 本身没有镜像:克隆仓库还是要连得上 GitHub。其余细节见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 只装 skill:`npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`。它只是一个指针,第一次用时会征得你同意,再把完整的工作台装好。这样装的是整份副本,仓库更新了它不变;工作台装好以后跑一次 `bin/vh install-skill`,换成跟随克隆的短桩。 diff --git a/bin/vh b/bin/vh index 21660ee4..1b082d88 100755 --- a/bin/vh +++ b/bin/vh @@ -8,6 +8,15 @@ set -euo pipefail unset CDPATH # an exported CDPATH would send a relative cd (this one: bin/vh run as bin/vh) to another folder, and print it ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" c_ok=$'\033[32m✓\033[0m'; c_no=$'\033[31m✗\033[0m'; c_wa=$'\033[33m!\033[0m' +# this machine's settings (tools/settings.py): with "mirror": "cn", every download a command starts goes to the mirrors in +# tools/mirrors.txt (npm, uv, Hugging Face, Electron; a variable already set wins); read with grep, so no python3 per run +if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/ovh/settings.json" ] && grep -q '"mirror"[[:space:]]*:[[:space:]]*"cn"' "${XDG_CONFIG_HOME:-$HOME/.config}/ovh/settings.json" 2>/dev/null; then + while read -r _k _v _o _m _w; do + case "$_k" in ""|\#*) continue ;; esac + if [ "$_v" != - ] && [ -z "${!_v:-}" ]; then export "$_v=$_m"; fi + done < "$ROOT/tools/mirrors.txt" + export OVH_MIRROR=cn +fi declare -a TYPES=( "math:01-math-science-explainer:数学/科学原理讲解(Manim)" @@ -126,6 +135,18 @@ hf_pin() { # hf_pin : the Chrome version pinned by the HyperFrames in the n [ ${#files[@]} -gt 0 ] || return 1 awk -F'"' -v k="var $k = " '$1 == k && $2 ~ /^[0-9][0-9.]*$/ { print $2; f = 1; exit } END { exit !f }' "${files[@]}" 2>/dev/null } +hf_chrome_mirror() { # hf_chrome_mirror : with the mirror on (cn) and no chrome-headless-shell yet at the version the HyperFrames + # installed for dir pins, fetch it from the mirror into the folder HyperFrames looks in: HyperFrames has no setting for where it + # downloads its Chrome, so without this the first render would go to storage.googleapis.com anyway (no hash is pinned for it) + [ "${OVH_MIRROR:-}" = cn ] || return 0 + local d=$1 pin base + pin=$(hf_pin "$d") || return 0 + [ -n "$(shell_folder "$HOME/.cache/hyperframes/chrome/chrome-headless-shell" "$pin" 2>/dev/null)" ] && return 0 + base=$(awk '$1 == "chrome" { print $4 }' "$ROOT/tools/mirrors.txt") + echo "→ HyperFrames' Chrome $pin from the mirror ($base, about 93 MB), into ~/.cache/hyperframes/chrome, where its first render looks" + (cd "$d" && npx --yes @puppeteer/browsers install "chrome-headless-shell@$pin" --path "$HOME/.cache/hyperframes/chrome" --base-url "$base" >/dev/null 2>&1) \ + || echo "$c_wa HyperFrames' Chrome did not come from the mirror; the first render tries its own download" +} old_mac() { [ "$(uname)" = Darwin ] && [ "$(uname -r | cut -d. -f1)" -lt 22 ]; } # macOS 12 or older: HyperFrames stops Chrome at 150 shell_folder() { # shell_folder [version]: the folder of that chrome-headless-shell version, else (no version given) the newest; # only a folder with the browser in it counts (an interrupted download leaves an empty one). Folders are - @@ -170,6 +191,17 @@ cmd_install_skill() { # writes a stub for each skill in skills/: its frontmatter echo " restart Claude Code / Codex so it picks up the skill; then ask for a video from any folder." echo " a git pull here updates the skill; run this again only when bin/vh doctor's skills line says so (a renamed skill, a new one, a changed description)." } +cmd_settings() { # this machine's settings (tools/settings.py, -h); the mirror turned on also fetches HyperFrames' Chrome from it now, + # since HyperFrames cannot be pointed at a mirror itself + if [ "${1:-}" = chrome ]; then # settings chrome: HyperFrames' Chrome from the mirror now, when the mirror is on and it is not here + [ $# = 1 ] || { echo "usage: bin/vh settings chrome" >&2; return 2; } + [ "${OVH_MIRROR:-}" = cn ] || { echo "the mirrors are not on (bin/vh settings mirror cn): HyperFrames downloads its own Chrome at the first render"; return 0; } + [ -d "$ROOT/styles/_swatch/node_modules/hyperframes" ] || { echo "$c_wa no HyperFrames in styles/_swatch yet (cd styles/_swatch && npm ci): nothing to fetch Chrome for" >&2; return 1; } + hf_chrome_mirror "$ROOT/styles/_swatch"; return 0 + fi + python3 "$ROOT/tools/settings.py" "$@" || return $? + if [ "${1:-}" = mirror ] && [ "${2:-}" = cn ] && [ -d "$ROOT/styles/_swatch/node_modules/hyperframes" ]; then OVH_MIRROR=cn; hf_chrome_mirror "$ROOT/styles/_swatch"; fi +} cmd_sync_agents() { # CLAUDE.md's 命令行 line from tools/commands.json first, then AGENTS.md from CLAUDE.md local m; m=$(python3 "$ROOT/tools/commands.py" claude-line --write "$ROOT/CLAUDE.md") || exit 1 echo "$c_ok $m" @@ -1051,6 +1083,7 @@ PY done shopt -u dotglob; rm -rf "$tmp" (cd "$dir" && npm i -D --save-exact --silent --no-fund --no-audit "hyperframes@${HYPERFRAMES_VERSION:-0.8.202}" >/dev/null 2>&1) || echo "$c_wa could not pin hyperframes locally (offline?)" + hf_chrome_mirror "$dir" # with the mirror on: its Chrome now, from the mirror, not at the first render from Google's # the scaffold loads GSAP from a CDN; an offline render then hangs silently, so vend it locally (same pinned version) local gv; gv=$(grep -o 'cdn.jsdelivr.net/npm/gsap@[0-9.]*' "$dir"/*.html 2>/dev/null | head -1 | sed 's/.*gsap@//') || true if [ -n "$gv" ] && (cd "$dir" && npm i -D --save-exact --silent --no-fund --no-audit "gsap@$gv" >/dev/null 2>&1); then @@ -1450,11 +1483,12 @@ case "${2:-}" in -h|--help) # `bin/vh -h` prints its usage instead o pace) cmd_usage pace; echo; exec python3 "$ROOT/tools/audio/pace.py" -h ;; words) cmd_usage words; echo; exec python3 "$ROOT/tools/words.py" -h ;; # + what it reads, the checks and the --json fields doctor) cmd_usage doctor; echo; exec python3 "$ROOT/tools/doctor.py" -h ;; # + the --json fields + settings) cmd_usage settings; echo; exec python3 "$ROOT/tools/settings.py" -h ;; # + the file's shape frames|render|determinism|cues|patch) cmd_usage "$1"; echo; exec node "$ROOT/tools/film/$1.mjs" -h ;; # + every flag *) cmd_usage "$1" && exit 0 ;; esac ;; esac case "${1:-}" in # the activity log: every command that works on a project (act_start finds it) but the read-only views - ""|help|-h|--help|setup|install-skill|sync-agents|types|effort|recipes|doctor|commands|status|activity|know|artifacts|projects|new|words|studio) ;; # (new: once the project is made; words only reads; studio opens a page, and the desk it starts logs its own run) + ""|help|-h|--help|setup|install-skill|settings|sync-agents|types|effort|recipes|doctor|commands|status|activity|know|artifacts|projects|new|words|studio) ;; # (new: once the project is made; words only reads; studio opens a page, and the desk it starts logs its own run) components) [ "${2:-}" != add ] || act_start "$@" || true ;; # list, check and sample touch no project desk) case "${2:-}" in data|agents) ;; *) act_start "$@" || true ;; esac ;; # agents: no project (it installs into a cache) versions) case "${2:-}" in compare|use) act_start "$@" || true ;; esac ;; # the list is a read-only view @@ -1481,6 +1515,7 @@ case "${1:-help}" in doctor) shift; cmd_doctor "$@" ;; setup) cmd_setup ;; types) cmd_types ;; tts) shift; cmd_tts "$@" ;; pace) shift; cmd_pace "$@" ;; voices) shift; cmd_voices "$@" ;; captions) shift; cmd_captions "$@" ;; timeline) shift; cmd_timeline "$@" ;; remap) shift; cmd_remap "$@" ;; timemap) shift; cmd_timemap "$@" ;; music) shift; cmd_music "$@" ;; sfx) shift; cmd_sfx "$@" ;; beats) shift; cmd_beats "$@" ;; mix) shift; cmd_mix "$@" ;; qa) shift; cmd_qa "$@" ;; mux) shift; cmd_mux "$@" ;; install-skill) shift; cmd_install_skill "$@" ;; + settings) shift; cmd_settings "$@" ;; recipes) shift; python3 "$ROOT/tools/recipes.py" "$@" ;; bgm) shift; cmd_bgm "$@" ;; sound) shift; cmd_sound "$@" ;; diff --git a/changes/first-run-mirrors.md b/changes/first-run-mirrors.md new file mode 100644 index 00000000..d11bde11 --- /dev/null +++ b/changes/first-run-mirrors.md @@ -0,0 +1,7 @@ +**连不上官方源时,安装自动改用国内镜像,之后的下载都跟着走** +- Why: 在国内网络下,第一次安装和第一次做片要连 npm、PyPI、Hugging Face、GitHub Releases 和 Google 的存储;原来要照 wiki 手动设三四个变量、另跑两条命令装 Chrome,Studio 应用的 Electron 下载没有写怎么办。 +- 安装时先试官方的 npm 源(5 秒);没有应答、国内镜像有,就改用国内镜像,用一句话说明,并记在这台机器自己的设置里(`~/.config/ovh/settings.json`)。不按语言或时区猜。`--mirror cn` 直接用,`--mirror off` 不用,也记下来。 +- 镜像的地址集中在 `tools/mirrors.txt` 一个文件里,每一行写明是谁在运营(npmmirror.com、清华 TUNA、hf-mirror.com)。镜像打开时,`bin/vh` 给它运行的每条命令设好 npm、uv(Python 包和 Python 本身)、Hugging Face 和 Electron 的镜像变量;你自己设过的变量不动。HyperFrames 下载 Chrome 时没有可设的地址,所以由 `bin/vh new` 和安装先从镜像把它装进 HyperFrames 找的目录。 +- 新命令 `bin/vh settings`:看这台机器的设置,`bin/vh settings mirror cn|off|auto` 改镜像,`--json` 给 Studio 的设置面板读。`bin/vh doctor` 多一行说现在走哪里、怎么关。 +- 已有的校验不变,也不信任镜像:npm ci 按 lockfile 里的哈希核对每个包;Electron 按它自己的包里带的 checksums.json 核对。uv 的包、Hugging Face 的模型、Python 和 Chrome 没有钉住的哈希,和从官方源下一样照收。 +- 切到镜像以后,uv 会按新的源重新下载之前缓存过的 Python 包(它的缓存按源区分)。 diff --git a/docs/assets/overview.en.svg b/docs/assets/overview.en.svg index 18c77caa..bac3cec4 100644 --- a/docs/assets/overview.en.svg +++ b/docs/assets/overview.en.svg @@ -37,7 +37,7 @@ rect{stroke-width:0.8} Knowledge11 video types · 13 playbook docs43 styles · 75 shot recipes6 motion components · 15 cases37 reference repos, read-only -Tools and enginesbin/vh: 73 commandsHyperFrames · canvas + Three.jsp5.brush · Manim · Blendervoice · score · SFX · mix · QA +Tools and enginesbin/vh: 74 commandsHyperFrames · canvas + Three.jsp5.brush · Manim · Blendervoice · score · SFX · mix · QA Records and lessonsREVIEW.md logs every noteLESSONS flow into the playbookthe next film starts better diff --git a/docs/assets/overview.zh.svg b/docs/assets/overview.zh.svg index 590e82ee..ce213a8b 100644 --- a/docs/assets/overview.zh.svg +++ b/docs/assets/overview.zh.svg @@ -37,7 +37,7 @@ rect{stroke-width:0.8} 知识库11 类视频 · 13 篇 playbook43 种风格 · 75 张镜头配方6 个动效组件 · 15 个案例37 个只读参考仓库 -工具与引擎bin/vh:73 条命令HyperFrames · canvas + Three.jsp5.brush · Manim · Blender配音 · 作曲 · 音效 · 混音 · QA +工具与引擎bin/vh:74 条命令HyperFrames · canvas + Three.jsp5.brush · Manim · Blender配音 · 作曲 · 音效 · 混音 · QA 记录与回流REVIEW.md 记下每条意见LESSONS 回流进 playbook下一支片子直接受益 diff --git a/docs/site/index.html b/docs/site/index.html index 5898ddea..02696c6e 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -976,7 +976,7 @@

Reads读

-

Runs跑 one CLI, 73 commands, 5 engines一个命令行,73 条命令,5 个引擎

+

Runs跑 one CLI, 74 commands, 5 engines一个命令行,74 条命令,5 个引擎

bin/vhnew · edit · render · check · gate · studio · footage · image · tts · music
HyperFramescanvas + Three.jsp5.brushManimBlender
@@ -1006,7 +1006,7 @@

Runs跑

06Capability map能力地图

From idea to delivery, a tool at every step.从立意到交付,每一步都有工具。

-

One CLI, bin/vh, with 73 commands. Each name below is one; any command takes -h, and bin/vh commands lists them by stage.一个命令行 bin/vh,73 条命令。下面每个名字都是其中一条;每条加 -h 看用法,bin/vh commands 按阶段列出全部。

+

One CLI, bin/vh, with 74 commands. Each name below is one; any command takes -h, and bin/vh commands lists them by stage.一个命令行 bin/vh,74 条命令。下面每个名字都是其中一条;每条加 -h 看用法,bin/vh commands 按阶段列出全部。

diff --git a/install.sh b/install.sh index ccd5174c..b824a488 100755 --- a/install.sh +++ b/install.sh @@ -1,9 +1,13 @@ #!/usr/bin/env bash # OpenVideoHarness one-line installer. # curl -fsSL https://raw.githubusercontent.com/ZLHad/OpenVideoHarness/main/install.sh | bash -# bash install.sh [--dir ~/OpenVideoHarness] [--refs] [--no-skill] [--skill claude|codex|all] [--obscura] [--icon | --no-icon] +# bash install.sh [--dir ~/OpenVideoHarness] [--refs] [--no-skill] [--skill claude|codex|all] [--mirror cn|off] [--obscura] [--icon | --no-icon] # What it does, and where it puts things: # 1. clone the repo into --dir, newest commit only (about 200 MB on disk; a re-run moves it to the newest commit, keeping LOCAL.md and projects/) +# 1b. the download mirrors (tools/mirrors.txt): with neither --mirror nor a choice made before (bin/vh settings), try the official +# npm registry for 5 s; when it does not answer and the mainland-China mirror does, use the mirrors from here on, say so in one +# line, and keep the choice in ~/.config/ovh/settings.json, so later bin/vh downloads use them too (bin/vh settings mirror off +# turns that off). --mirror cn uses them without trying, --mirror off never. Never guessed from the language or time zone # 2. npm install in engines/ClaudeAnimationBase and npm ci in styles/_swatch (HyperFrames 0.8.202), both inside --dir (about 180 MB of # node_modules; npm also writes its own cache, ~/.npm). The read-only reference repos references/fetch.sh lists are not fetched: # an agent fetches the one a doc points to when it first needs it (bash references/fetch.sh , which says its size first); @@ -33,12 +37,13 @@ # The wiki's Getting Started ("What gets downloaded") has the same list. set -euo pipefail REPO="${OVH_REPO:-https://github.com/ZLHad/OpenVideoHarness.git}" -DIR="${OVH_DIR:-$HOME/OpenVideoHarness}"; REFS=0; SKILL=all; OBSCURA=0; ICON=default +DIR="${OVH_DIR:-$HOME/OpenVideoHarness}"; REFS=0; SKILL=all; OBSCURA=0; ICON=default; MIRROR="" while [ $# -gt 0 ]; do case "$1" in - --dir) DIR="$2"; shift 2 ;; --refs) REFS=1; shift ;; --no-refs) REFS=0; shift ;; --no-skill) SKILL=none; shift ;; --skill) SKILL="${2:?--skill needs claude|codex|all|none}"; shift 2 ;; --obscura) OBSCURA=1; shift ;; + --dir) DIR="$2"; shift 2 ;; --refs) REFS=1; shift ;; --no-refs) REFS=0; shift ;; --no-skill) SKILL=none; shift ;; --skill) SKILL="${2:?--skill needs claude|codex|all|none}"; shift 2 ;; --obscura) OBSCURA=1; shift ;; --mirror) MIRROR="${2:?--mirror needs cn or off}"; shift 2 ;; --icon) ICON=yes; shift ;; --no-icon) ICON=no; shift ;; -h|--help) sed -n '2,32p' "$0"; exit 0 ;; *) echo "unknown option: $1"; exit 1 ;; esac; done case "$SKILL" in claude|codex|all|none) ;; *) echo "unknown --skill '$SKILL' (claude|codex|all|none)"; exit 1 ;; esac +case "$MIRROR" in ""|cn|off) ;; *) echo "unknown --mirror '$MIRROR' (cn|off)"; exit 1 ;; esac say() { printf '\033[1m→ %s\033[0m\n' "$*"; } NOAPP="${XDG_DATA_HOME:-$HOME/.local/share}/ovh-studio/no-app" # --no-icon once: kept here, so an update leaves OVH Studio out too (--icon clears it) put_icon() { # OVH Studio in the applications, unasked (macOS, a Linux desktop): left alone when it is there and current, never @@ -99,6 +104,14 @@ if [ -d "$DIR/.git" ]; then say "updating $DIR" else say "cloning into $DIR (newest commit only)" git clone -q --depth 1 --single-branch "$REPO" "$DIR" || { echo "✗ Could not download OpenVideoHarness: check the network (or your proxy) and run this installer again."; exit 1; }; fi cd "$DIR" +answers() { command -v curl >/dev/null 2>&1 && curl -fsS -m 5 -o /dev/null "$1" 2>/dev/null; } +if [ -n "$MIRROR" ]; then bin/vh settings mirror "$MIRROR" --why "install.sh --mirror $MIRROR, $(date +%F)" | sed 's/^/ /' +elif [ "$(bin/vh settings mirror --get 2>/dev/null)" = auto ] && ! answers https://registry.npmjs.org/ && answers https://registry.npmmirror.com/; then + bin/vh settings mirror cn --why "install.sh, $(date +%F): registry.npmjs.org did not answer in 5 s, registry.npmmirror.com did" >/dev/null + echo " npm's registry did not answer in 5 s, so downloads come from the mainland-China mirrors from now on (npmmirror.com, TUNA, hf-mirror.com;" + echo " tools/mirrors.txt). bin/vh settings mirror off turns that off." +fi +eval "$(python3 tools/settings.py env)" # the mirrors, when they are on, for this script's own downloads too say "installing the bundled engine (ClaudeAnimationBase)" (cd engines/ClaudeAnimationBase && npm install --silent) || echo "! the hand-drawn engine's packages did not install; running this installer again finishes them" n=$(grep -cE '^(full|sparse|textonly) ' references/fetch.sh || true) # counted from the list, so it cannot go stale @@ -110,6 +123,7 @@ else had=0; [ ! -d references/repos ] || had=$(find references/repos -mindepth 2 fi say "installing the renderer for style samples (HyperFrames, for bin/vh style)" (cd styles/_swatch && npm ci --silent) || echo "! the renderer for style samples did not install; it is tried again the first time a style sample is made" +[ "${OVH_MIRROR:-}" != cn ] || bin/vh settings chrome # with the mirrors on: HyperFrames' Chrome from the mirror now [ -f LOCAL.md ] || cp LOCAL.example.md LOCAL.md if [ "$SKILL" != none ]; then # one line for the stubs it wrote (each says where it went when run by hand: bin/vh install-skill) say "telling Claude Code and Codex where this workbench is (skills)" diff --git a/tools/ci.sh b/tools/ci.sh index 30f83e58..b650e41c 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1659,6 +1659,27 @@ PY else bad "first downloads here: $a | $b | no script ($re): $qcalls | progress lines: $g"; fi ;; esac rm -rf "$ft" + # the download mirrors: this machine's settings (tools/settings.py) in a file of their own; with "mirror": "cn" bin/vh exports + # the variables of tools/mirrors.txt for what it runs (one the person set stays theirs); install.sh tries the official npm + # registry first and keeps cn only when it does not answer and the mirror does; --mirror off is kept, and stops the trying + t=$(mktemp -d "${TMPDIR:-/tmp}/vh-mirror.XXXXXX") + a=$(XDG_CONFIG_HOME="$t/c" vh settings mirror --get; XDG_CONFIG_HOME="$t/c" vh settings mirror cn --why "a test" >/dev/null + (unset npm_config_registry HF_ENDPOINT UV_DEFAULT_INDEX ELECTRON_MIRROR; XDG_CONFIG_HOME="$t/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); e = d["environment"] +print(d["mirror"], d["settings"].get("mirror_why"), e["npm_config_registry"], e["HF_ENDPOINT"], e["UV_DEFAULT_INDEX"], e["ELECTRON_MIRROR"])' + XDG_CONFIG_HOME="$t/c" npm_config_registry=https://mine.example vh settings --json | python3 -c 'import json, sys; print(json.load(sys.stdin)["environment"]["npm_config_registry"])' + XDG_CONFIG_HOME="$t/c" vh settings mirror off >/dev/null; (unset npm_config_registry; XDG_CONFIG_HOME="$t/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); print(d["mirror"], d["environment"]["npm_config_registry"])' + XDG_CONFIG_HOME="$t/c" vh settings mirror nope 2>/dev/null; echo "exit $?") + b=$(awk '!/^#/ && NF { if ($4 !~ /^https:\/\//) print "not https: " $1 }' tools/mirrors.txt) + mkdir -p "$t/bin"; printf '#!/bin/sh\ncase "$*" in *registry.npmjs.org*) [ -n "$OFFICIAL" ] && exit 0; exit 28 ;; *) exit 0 ;; esac\n' > "$t/bin/curl"; chmod +x "$t/bin/curl" + sed -n '/^answers() {/,/^eval "\$(python3 tools\/settings.py env)"/p' install.sh > "$t/probe.sh" + probe() { (env PATH="$t/bin:$PATH" XDG_CONFIG_HOME="$t/$1" "${@:2}" bash -c '. "$1"; vh_get() { bin/vh settings mirror --get; }; echo "now $(vh_get) ${npm_config_registry:-official}"' _ "$t/probe.sh" 2>&1 | tail -1); } + c=$(MIRROR="" probe p1 env -u npm_config_registry); d=$(probe p2 env -u npm_config_registry OFFICIAL=1); e=$(probe p3 env -u npm_config_registry MIRROR=off); f=$(probe p3 env -u npm_config_registry MIRROR=) + if case "$a" in "auto"*"cn a test https://registry.npmmirror.com https://hf-mirror.com https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple https://npmmirror.com/mirrors/electron/"*"https://mine.example"*"off None"*"exit 2") true ;; *) false ;; esac \ + && [ -z "$b" ] && [ -s "$t/probe.sh" ] && [ "$c" = "now cn https://registry.npmmirror.com" ] && [ "$d" = "now auto official" ] && [ "$e" = "now off official" ] && [ "$f" = "now off official" ] \ + && grep -q '"mirror_why": "install.sh, ' "$t/p1/ovh/settings.json" + then ok "mirrors: kept in this machine's settings; bin/vh exports tools/mirrors.txt's variables with cn (a variable the person set stays); install.sh keeps cn only when the official npm registry does not answer and the mirror does; off is kept and stops the trying" + else bad "mirrors: $a | $b | probe: $c / $d / $e / $f"; fi + rm -rf "$t" # recipes sample: bad usage exits 2 before any render (an unknown id, a sequence, an unknown style); list --json names # the sheet a recipe carries (recipes check, above, holds every sketch to its sheet) vh recipes sample no-such-recipe >/dev/null 2>&1; rc=$?; vh recipes sample launch-15s >/dev/null 2>&1; rc2=$? diff --git a/tools/commands.json b/tools/commands.json index 228499bc..f83dcf7c 100644 --- a/tools/commands.json +++ b/tools/commands.json @@ -119,6 +119,25 @@ } ] }, + { + "name": "settings", + "summary": "This machine's own settings, the ones that are not secret, kept once for every clone and for Studio: for now the download mirrors (tools/mirrors.txt), cn, off or auto.", + "when": "when downloads are blocked or slow where you are (install.sh switches to the mirrors by itself when the official npm registry does not answer), or to turn the mirrors off again", + "stages": ["env"], + "reads": ["$XDG_CONFIG_HOME/ovh/settings.json (~/.config/ovh/settings.json)", "tools/mirrors.txt"], + "writes": ["$XDG_CONFIG_HOME/ovh/settings.json (~/.config/ovh/settings.json)", "~/.cache/hyperframes/chrome (mirror cn: HyperFrames' Chrome from the mirror)"], + "usage": [ + { + "synopsis": "settings [--json] | settings mirror cn|off|auto [--why TEXT] | settings mirror --get | settings chrome", + "text": [ + "what this machine's settings are and where they are kept; mirror cn: every later download a command starts comes from the", + "mainland-China mirrors in tools/mirrors.txt (npm, uv, Hugging Face, Electron; HyperFrames' Chrome fetched from the mirror", + "now, as HyperFrames cannot be pointed at one; settings chrome does only that), off: never, auto: the official sources", + "(install.sh tries them first)" + ] + } + ] + }, { "name": "install-skill", "summary": "Register the skills in skills/ for Claude Code, Codex or both: short stubs that read skills//SKILL.md in this clone, so a git pull updates them.", diff --git a/tools/doctor.py b/tools/doctor.py index 1c18ac55..64711724 100644 --- a/tools/doctor.py +++ b/tools/doctor.py @@ -197,6 +197,8 @@ def first_film(mods, checks, plat, found_by=None, env=os.environ, libs=None): lines.append(" The first render downloads its own Chrome once (about 0.2 GB).") if font and not zh_locale(env): lines.append("! Chinese text: no Chinese font here, so it would draw as boxes → sudo apt install fonts-noto-cjk") + if ((c.get("mirror") or {}).get("note") or "").startswith("cn:"): + lines.append(" Downloads come from the mainland-China mirrors (bin/vh settings mirror off turns that off).") if plat == "darwin-arm64": if (m.get("qwen3-tts") or {}).get("state") == "ok" and (m.get("mlx-audio") or {}).get("state") == "ok": lines.append("✓ Voice: the local voice is downloaded.") @@ -679,6 +681,15 @@ def repo_checks(webgl, found_by): out.append({"name": "references", "state": "ok", "note": f"{have}/{want} repos fetched, {size_of(ROOT / 'references' / 'repos')}"}) else: out.append({"name": "references", "state": "ok", "note": references_note(have, want, bytes_of(ROOT / "references" / "repos") if have else 0, install_says())}) + try: # the download mirrors this machine's settings say (tools/settings.py, tools/mirrors.txt) + import settings as S + d = S.load(); m = S.mirror(d); why = f" ({d['mirror_why']})" if d.get("mirror_why") else "" + out.append({"name": "mirror", "state": "ok", "note": { + "cn": f"cn: downloads come from the mainland-China mirrors ({S.operators()}; tools/mirrors.txt){why} → bin/vh settings mirror off turns that off", + "off": f"off: the official sources, and install.sh does not try the mirrors{why} → bin/vh settings mirror auto or cn changes it", + "auto": "auto: the official sources (install.sh tries the mainland-China mirrors when the official npm registry does not answer) → bin/vh settings mirror cn uses them now"}[m]}) + except (OSError, ValueError, ImportError) as e: + out.append({"name": "mirror", "state": "unchecked", "note": f"tools/mirrors.txt or this machine's settings not readable: {e}"}) local = ROOT / "LOCAL.md" if not local.exists(): out.append({"name": "local_md", "state": "missing", "note": "no LOCAL.md → bin/vh doctor --fill-local (copies LOCAL.example.md, writes this machine's lines)"}) diff --git a/tools/mirrors.txt b/tools/mirrors.txt new file mode 100644 index 00000000..3c2a8785 --- /dev/null +++ b/tools/mirrors.txt @@ -0,0 +1,19 @@ +# Download mirrors for a network where the official sources do not answer (mainland China), in one place. +# install.sh tries the official npm registry first (5 s); only when it does not answer and the mirror does, this machine's +# settings get "mirror": "cn" ($XDG_CONFIG_HOME/ovh/settings.json, tools/settings.py), and from then on bin/vh exports the +# variables below with the mirror column, so every later download goes there: npm (project packages, Studio's app and its +# agent adapters), uv (Python packages, a Python build), Hugging Face (the local voice), Electron, and HyperFrames' Chrome, +# which bin/vh fetches from the mirror itself because HyperFrames has no setting for it. A variable you set yourself wins. +# install.sh --mirror cn uses them without trying, --mirror off never; bin/vh settings mirror cn|off|auto changes it later. +# The checks the tools already make stay as they are, and do not trust the mirror: npm ci checks each package against the +# lockfile's hash; Electron's download is checked against the checksums.json its npm package ships (itself under that +# hash). uv's packages, the Hugging Face model, a Python build and Chrome have no hash pinned here: they are taken as the +# mirror serves them over https, as they are taken from the official source. +# +# kind variable official (tried first) mirror (cn) who runs the mirror +npm npm_config_registry https://registry.npmjs.org https://registry.npmmirror.com npmmirror.com, run by the cnpm project +pypi UV_DEFAULT_INDEX https://pypi.org/simple https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple TUNA, Tsinghua University's open-source mirror +python UV_PYTHON_INSTALL_MIRROR https://github.com/astral-sh/python-build-standalone/releases/download https://registry.npmmirror.com/-/binary/python-build-standalone npmmirror.com +huggingface HF_ENDPOINT https://huggingface.co https://hf-mirror.com hf-mirror.com, a non-profit community project, not Hugging Face's own +electron ELECTRON_MIRROR https://github.com/electron/electron/releases/download/ https://npmmirror.com/mirrors/electron/ npmmirror.com +chrome - https://storage.googleapis.com/chrome-for-testing-public https://cdn.npmmirror.com/binaries/chrome-for-testing npmmirror.com diff --git a/tools/schemas/output/settings.schema.json b/tools/schemas/output/settings.schema.json new file mode 100644 index 00000000..ad29f391 --- /dev/null +++ b/tools/schemas/output/settings.schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/ZLHad/OpenVideoHarness/tools/schemas/output/settings.schema.json", + "title": "bin/vh settings --json", + "description": "This machine's own settings (tools/settings.py: $XDG_CONFIG_HOME/ovh/settings.json), the mirror in effect, the mirror table (tools/mirrors.txt) and the mirror variables as bin/vh exported them.", + "type": "object", + "required": ["version", "tool", "file", "settings", "mirror", "mirrors", "environment"], + "properties": { + "version": {"enum": [1]}, + "tool": {"type": "string"}, + "file": {"type": "string"}, + "settings": {"type": "object"}, + "mirror": {"enum": ["cn", "off", "auto"]}, + "mirrors": { + "type": "array", + "items": { + "type": "object", + "required": ["kind", "variable", "official", "mirror", "who"], + "properties": { + "kind": {"type": "string"}, + "variable": {"type": ["string", "null"]}, + "official": {"type": "string"}, + "mirror": {"type": "string"}, + "who": {"type": "string"} + } + } + }, + "environment": {"type": "object"} + } +} diff --git a/tools/settings.py b/tools/settings.py new file mode 100644 index 00000000..58d97aa7 --- /dev/null +++ b/tools/settings.py @@ -0,0 +1,145 @@ +"""bin/vh settings: this machine's own settings, the ones that are not secret, for every clone on it and for Studio. Stdlib only. + +usage: bin/vh settings [--json] what they are now, and where they are kept + bin/vh settings mirror cn|off|auto [--why TEXT] the download mirrors (tools/mirrors.txt): + cn every later download comes from the mainland-China mirrors (bin/vh exports their variables) + off never: the official sources, and install.sh does not try the mirrors either + auto the official sources; install.sh tries the official npm registry once and switches to cn when it + does not answer and the mirror does (the default: no "mirror" key) + bin/vh settings mirror --get cn, off or auto, alone on a line + bin/vh settings chrome with the mirrors on, HyperFrames' Chrome from the mirror now when it + is not here (HyperFrames has no setting for where it downloads it; + bin/vh new and settings mirror cn do this by themselves) + python3 tools/settings.py env the lines bin/vh and install.sh run to use the mirrors + (export NAME=value; none when the mirror is not cn, or for a + variable already set) + +Kept in $XDG_CONFIG_HOME/ovh/settings.json (~/.config/ovh/settings.json): one file per machine, outside every clone, so a +git pull, a second clone or Studio's settings panel see the same values. Never a key or a token: those stay in the +environment (LOCAL.md names them, never their values). Shape, "version": 1 (keys only added, never renamed; a key +this file does not know is kept as it is when another is written): + {"version": 1, + "mirror": "cn" | "off", absent: auto + "mirror_why": "…", who set it and why, in a sentence (install.sh's probe says what did not answer) + "mirror_at": "YYYY-MM-DD"} +Written whole to a temporary file beside it and moved into place, so a reader never sees half a file. +""" +import datetime, json, os, sys, tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +MODES = ("cn", "off", "auto") + + +def path(): + return Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config") / "ovh" / "settings.json" + + +def load(): + """The settings as kept, or {"version": 1} (none yet, or a file that is not a JSON object: said on stderr).""" + p = path() + try: + d = json.loads(p.read_text(encoding="utf-8")) + except FileNotFoundError: + return {"version": 1} + except (OSError, ValueError) as e: + print(f"bin/vh settings: {p} is not readable JSON ({e}); taken as empty", file=sys.stderr) + return {"version": 1} + return d if isinstance(d, dict) else {"version": 1} + + +def save(d): + p = path() + p.parent.mkdir(parents=True, exist_ok=True) + fd, tmp = tempfile.mkstemp(prefix=".settings.", suffix=".tmp", dir=p.parent) + try: + with os.fdopen(fd, "w", encoding="utf-8") as f: + f.write(json.dumps(dict(d, version=1), ensure_ascii=False, indent=2) + "\n") + os.replace(tmp, p) + finally: + if os.path.exists(tmp): + os.unlink(tmp) + + +def mirror(d=None): + m = (d if d is not None else load()).get("mirror") + return m if m in ("cn", "off") else "auto" + + +def mirrors(): + """tools/mirrors.txt → [{kind, variable, official, mirror, who}].""" + rows = [] + for line in (ROOT / "tools" / "mirrors.txt").read_text(encoding="utf-8").splitlines(): + if not line.strip() or line.startswith("#"): + continue + kind, var, official, mir, who = line.split(None, 4) + rows.append({"kind": kind, "variable": None if var == "-" else var, "official": official, "mirror": mir, "who": who}) + return rows + + +def env_lines(environ=os.environ): + """export lines for the mirror variables, when the mirror is cn; a variable already set (by the person) is left.""" + if mirror() != "cn": + return [] + out = [f"export {r['variable']}={r['mirror']}" for r in mirrors() if r["variable"] and not environ.get(r["variable"])] + return out + ["export OVH_MIRROR=cn"] + + +def in_effect(environ=os.environ): + """The mirror variables as this process has them (bin/vh exports them before it runs a tool): {name: value or None}.""" + return {r["variable"]: environ.get(r["variable"]) for r in mirrors() if r["variable"]} + + +def operators(): + """The mirrors' operators by name, each once: "npmmirror.com, TUNA and hf-mirror.com".""" + names = list(dict.fromkeys(r["who"].split(",")[0] for r in mirrors())) + return ", ".join(names[:-1]) + " and " + names[-1] if len(names) > 1 else names[0] + + +def show(d, as_json=False): + m = mirror(d) + if as_json: + print(json.dumps({"version": 1, "tool": "bin/vh settings", "file": str(path()), "settings": d, "mirror": m, + "mirrors": mirrors(), "environment": in_effect()}, ensure_ascii=False, indent=1)) + return + print(f"this machine's settings: {path()}" + ("" if path().exists() else " (not written yet: the defaults)")) + said = {"cn": "the mainland-China mirrors, for every download (tools/mirrors.txt)", + "off": "the official sources; install.sh does not try the mirrors", + "auto": "the official sources; install.sh switches to the mirrors when the official npm registry does not answer"}[m] + print(f" mirror {m}: {said}" + (f" · {d['mirror_why']}" if d.get("mirror_why") else "") + + (f" ({d['mirror_at']})" if d.get("mirror_at") else "")) + print(" bin/vh settings mirror cn|off|auto changes it") + + +def main(argv): + if argv[:1] in (["-h"], ["--help"]): + print(__doc__.strip()); return 0 + if argv == ["env"]: + print("\n".join(env_lines())); return 0 + if not argv or argv == ["--json"]: + show(load(), bool(argv)); return 0 + if argv[0] == "mirror": + if argv[1:] == ["--get"]: + print(mirror()); return 0 + if len(argv) < 2 or argv[1] not in MODES or (len(argv) > 2 and (argv[2] != "--why" or len(argv) != 4)): + print("usage: bin/vh settings mirror cn|off|auto [--why TEXT] (or --get)", file=sys.stderr); return 2 + d = load() + for k in ("mirror", "mirror_why", "mirror_at"): + d.pop(k, None) + if argv[1] != "auto": + d.update(mirror=argv[1], mirror_at=datetime.date.today().isoformat()) + if len(argv) == 4: + d["mirror_why"] = argv[3] + save(d) + if argv[1] == "cn": + print(f"✓ downloads now come from the mainland-China mirrors ({operators()}; tools/mirrors.txt), kept in {path()};" + " bin/vh settings mirror off turns that off") + else: + print(f"✓ downloads come from the official sources{'' if argv[1] == 'auto' else ', and install.sh does not try the mirrors'} (kept in {path()})") + return 0 + print(f"bin/vh settings: unknown {' '.join(argv)} (bin/vh settings -h)", file=sys.stderr) + return 2 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/tools/test_contract.py b/tools/test_contract.py index d17d0c58..a7759b5c 100644 --- a/tools/test_contract.py +++ b/tools/test_contract.py @@ -22,7 +22,7 @@ SCHEMAS = HERE / "schemas" / "output" ALL = ("status", "activity", "versions", "check", "commands", "desk-data", "edit-list", "edit-build", "assets-list", "artifacts-list", "projects", "error", "cancel", "peaks", "timeline", "history", - "history-save", "history-diff", "history-restore", "gate", "new", "proxy", "thumbs", "words") + "history-save", "history-diff", "history-restore", "gate", "new", "proxy", "thumbs", "words", "settings") class VH: @@ -47,7 +47,7 @@ def fixture(t, sh): """The projects: p (bin/vh new, a film, its render, check, version and delivery records, a ledger, a cast and research folder, a log with each kind of line), z (the desk's fixture with a page and a submission), e (an edit list), and bad things for the failures. → (vh, p, z, e, whether there is a film).""" - vh = VH(sh, {"OVH_PROJECTS": f"{t}/projects"}) + vh = VH(sh, {"OVH_PROJECTS": f"{t}/projects", "XDG_CONFIG_HOME": f"{t}/config"}) # (settings: this run's own) r = vh("new", "math", "ci-contract") if r.returncode: raise SystemExit(f"bin/vh new: exit {r.returncode}: {r.stderr[-400:]}") @@ -113,7 +113,7 @@ def outputs(vh, p, z, e, has_film): ("edit-list", ["edit", "list", e]), ("edit-build", ["edit", "build", e]), ("assets-list", ["assets", "list", p]), ("artifacts-list", ["artifacts", "list", p]), ("artifacts-list", ["artifacts", "list", z]), ("projects", ["projects"]), ("cancel", ["cancel", p]), ("timeline", ["timeline", p, "--resolved"]), ("timeline", ["timeline", z, "--resolved"]), ("timeline", ["timeline", e, "--resolved"]), ("history", ["history", "list", p]), ("history-save", ["history", "save", p]), ("history-diff", ["history", "diff", p]), ("history-restore", ["history", "restore", p, "NOTES.md", "--at", "s1"]), ("gate", ["gate", z, "1", "--page"]), ("new", ["new", "math", "ci-contract-too"]), - ("words", ["words", z]), ("words", ["words", f"{z}/SCRIPT.md", "--all"])] + ("words", ["words", z]), ("words", ["words", f"{z}/SCRIPT.md", "--all"]), ("settings", ["settings"])] if has_film: runs.insert(0, ("check", ["check", f"{p}/out/final.mp4"])) # first: status and the others have its record runs.append(("peaks", ["peaks", f"{p}/out/final.mp4", "--bins", "8"])) From f1a64af6816790baab95adbebb173a559748cd32 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 04:02:07 +0800 Subject: [PATCH 07/14] ci: the mirrors check keeps its temp folder to itself (it took smoke_checks' $t) --- tools/ci.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/ci.sh b/tools/ci.sh index b650e41c..ce9f2361 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1662,24 +1662,24 @@ PY # the download mirrors: this machine's settings (tools/settings.py) in a file of their own; with "mirror": "cn" bin/vh exports # the variables of tools/mirrors.txt for what it runs (one the person set stays theirs); install.sh tries the official npm # registry first and keeps cn only when it does not answer and the mirror does; --mirror off is kept, and stops the trying - t=$(mktemp -d "${TMPDIR:-/tmp}/vh-mirror.XXXXXX") - a=$(XDG_CONFIG_HOME="$t/c" vh settings mirror --get; XDG_CONFIG_HOME="$t/c" vh settings mirror cn --why "a test" >/dev/null - (unset npm_config_registry HF_ENDPOINT UV_DEFAULT_INDEX ELECTRON_MIRROR; XDG_CONFIG_HOME="$t/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); e = d["environment"] + mt=$(mktemp -d "${TMPDIR:-/tmp}/vh-mirror.XXXXXX") + a=$(XDG_CONFIG_HOME="$mt/c" vh settings mirror --get; XDG_CONFIG_HOME="$mt/c" vh settings mirror cn --why "a test" >/dev/null + (unset npm_config_registry HF_ENDPOINT UV_DEFAULT_INDEX ELECTRON_MIRROR; XDG_CONFIG_HOME="$mt/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); e = d["environment"] print(d["mirror"], d["settings"].get("mirror_why"), e["npm_config_registry"], e["HF_ENDPOINT"], e["UV_DEFAULT_INDEX"], e["ELECTRON_MIRROR"])' - XDG_CONFIG_HOME="$t/c" npm_config_registry=https://mine.example vh settings --json | python3 -c 'import json, sys; print(json.load(sys.stdin)["environment"]["npm_config_registry"])' - XDG_CONFIG_HOME="$t/c" vh settings mirror off >/dev/null; (unset npm_config_registry; XDG_CONFIG_HOME="$t/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); print(d["mirror"], d["environment"]["npm_config_registry"])' - XDG_CONFIG_HOME="$t/c" vh settings mirror nope 2>/dev/null; echo "exit $?") + XDG_CONFIG_HOME="$mt/c" npm_config_registry=https://mine.example vh settings --json | python3 -c 'import json, sys; print(json.load(sys.stdin)["environment"]["npm_config_registry"])' + XDG_CONFIG_HOME="$mt/c" vh settings mirror off >/dev/null; (unset npm_config_registry; XDG_CONFIG_HOME="$mt/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); print(d["mirror"], d["environment"]["npm_config_registry"])' + XDG_CONFIG_HOME="$mt/c" vh settings mirror nope 2>/dev/null; echo "exit $?") b=$(awk '!/^#/ && NF { if ($4 !~ /^https:\/\//) print "not https: " $1 }' tools/mirrors.txt) - mkdir -p "$t/bin"; printf '#!/bin/sh\ncase "$*" in *registry.npmjs.org*) [ -n "$OFFICIAL" ] && exit 0; exit 28 ;; *) exit 0 ;; esac\n' > "$t/bin/curl"; chmod +x "$t/bin/curl" - sed -n '/^answers() {/,/^eval "\$(python3 tools\/settings.py env)"/p' install.sh > "$t/probe.sh" - probe() { (env PATH="$t/bin:$PATH" XDG_CONFIG_HOME="$t/$1" "${@:2}" bash -c '. "$1"; vh_get() { bin/vh settings mirror --get; }; echo "now $(vh_get) ${npm_config_registry:-official}"' _ "$t/probe.sh" 2>&1 | tail -1); } + mkdir -p "$mt/bin"; printf '#!/bin/sh\ncase "$*" in *registry.npmjs.org*) [ -n "$OFFICIAL" ] && exit 0; exit 28 ;; *) exit 0 ;; esac\n' > "$mt/bin/curl"; chmod +x "$mt/bin/curl" + sed -n '/^answers() {/,/^eval "\$(python3 tools\/settings.py env)"/p' install.sh > "$mt/probe.sh" + probe() { (env PATH="$mt/bin:$PATH" XDG_CONFIG_HOME="$mt/$1" "${@:2}" bash -c '. "$1"; vh_get() { bin/vh settings mirror --get; }; echo "now $(vh_get) ${npm_config_registry:-official}"' _ "$mt/probe.sh" 2>&1 | tail -1); } c=$(MIRROR="" probe p1 env -u npm_config_registry); d=$(probe p2 env -u npm_config_registry OFFICIAL=1); e=$(probe p3 env -u npm_config_registry MIRROR=off); f=$(probe p3 env -u npm_config_registry MIRROR=) if case "$a" in "auto"*"cn a test https://registry.npmmirror.com https://hf-mirror.com https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple https://npmmirror.com/mirrors/electron/"*"https://mine.example"*"off None"*"exit 2") true ;; *) false ;; esac \ - && [ -z "$b" ] && [ -s "$t/probe.sh" ] && [ "$c" = "now cn https://registry.npmmirror.com" ] && [ "$d" = "now auto official" ] && [ "$e" = "now off official" ] && [ "$f" = "now off official" ] \ - && grep -q '"mirror_why": "install.sh, ' "$t/p1/ovh/settings.json" + && [ -z "$b" ] && [ -s "$mt/probe.sh" ] && [ "$c" = "now cn https://registry.npmmirror.com" ] && [ "$d" = "now auto official" ] && [ "$e" = "now off official" ] && [ "$f" = "now off official" ] \ + && grep -q '"mirror_why": "install.sh, ' "$mt/p1/ovh/settings.json" then ok "mirrors: kept in this machine's settings; bin/vh exports tools/mirrors.txt's variables with cn (a variable the person set stays); install.sh keeps cn only when the official npm registry does not answer and the mirror does; off is kept and stops the trying" else bad "mirrors: $a | $b | probe: $c / $d / $e / $f"; fi - rm -rf "$t" + rm -rf "$mt" # recipes sample: bad usage exits 2 before any render (an unknown id, a sequence, an unknown style); list --json names # the sheet a recipe carries (recipes check, above, holds every sketch to its sheet) vh recipes sample no-such-recipe >/dev/null 2>&1; rc=$?; vh recipes sample launch-15s >/dev/null 2>&1; rc2=$? From f23d43ccc3e3201218a75f5b15cc7ca533805e67 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 04:16:30 +0800 Subject: [PATCH 08/14] install.sh: --mirror checked without an empty case (the wording check reads it); ci: bin/vh exec's into settings.py, known --- install.sh | 2 +- tools/ci.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index b824a488..1781e744 100755 --- a/install.sh +++ b/install.sh @@ -43,7 +43,7 @@ while [ $# -gt 0 ]; do case "$1" in --icon) ICON=yes; shift ;; --no-icon) ICON=no; shift ;; -h|--help) sed -n '2,32p' "$0"; exit 0 ;; *) echo "unknown option: $1"; exit 1 ;; esac; done case "$SKILL" in claude|codex|all|none) ;; *) echo "unknown --skill '$SKILL' (claude|codex|all|none)"; exit 1 ;; esac -case "$MIRROR" in ""|cn|off) ;; *) echo "unknown --mirror '$MIRROR' (cn|off)"; exit 1 ;; esac +[ -z "$MIRROR" ] || case "$MIRROR" in cn|off) ;; *) echo "unknown --mirror '$MIRROR' (cn|off)"; exit 1 ;; esac say() { printf '\033[1m→ %s\033[0m\n' "$*"; } NOAPP="${XDG_DATA_HOME:-$HOME/.local/share}/ovh-studio/no-app" # --no-icon once: kept here, so an update leaves OVH Studio out too (--icon clears it) put_icon() { # OVH Studio in the applications, unasked (macOS, a Linux desktop): left alone when it is there and current, never diff --git a/tools/ci.sh b/tools/ci.sh index ce9f2361..62fa23b4 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -9220,7 +9220,7 @@ for cmd, cl in (("render", "node /r/tools/film/render.mjs --browser b p"), ("fra for cmd, cl in (("render", "bash /r/bin/vh qa /p/render/x"), ("qa", "sleep 30"), ("", "bash /r/bin/vh qa"), ("music", "python3 /r/tools/audio/music.py p"), ("style", "bash /r/bin/vh qa x"), ("render", "node /elsewhere/render.mjs")): if C.is_ours(cmd, cl): bad.append(f"is_ours, not: {cmd}, {cl}") -known = {"doctor.py", "textcheck.mjs", "$tool.mjs", "activity.py", "know.py", "status.py", "projects.py", "gate.py", "desk.py", "studio.py", "render.sh", "resolved.py", "lyria.py", "tts.py", "pace.py", "$1.mjs", "commands.py", "artifacts.py", "words.py"} +known = {"doctor.py", "settings.py", "textcheck.mjs", "$tool.mjs", "activity.py", "know.py", "status.py", "projects.py", "gate.py", "desk.py", "studio.py", "render.sh", "resolved.py", "lyria.py", "tts.py", "pace.py", "$1.mjs", "commands.py", "artifacts.py", "words.py"} for m in re.finditer(r'\bexec\s+(?:python3|node)?\s*"?\$(?:ROOT|sw)/([^"\s]+)', open(f"{root}/bin/vh", encoding="utf-8").read()): if m.group(1).rsplit("/", 1)[-1] not in known: bad.append(f"bin/vh exec's into {m.group(1)}: say in tools/cancel.py's EXEC what its pid's command line is (a command not named after its tool), and add it here") From e5865caa45616cf6f94b4a77bf5ad882bbaba6d5 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 04:21:12 +0800 Subject: [PATCH 09/14] settings: a locked update(patch) is the one way to write (re-read, merge, keep the other keys, replace whole); save() goes through it Studio's settings panel and a terminal writing at once both land: the CI check runs two writers of 60 updates each (all 120 land; without the lock, 64 did). --- tools/ci.sh | 15 +++++++++++++ tools/settings.py | 55 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/tools/ci.sh b/tools/ci.sh index 62fa23b4..d7646abe 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1679,6 +1679,21 @@ print(d["mirror"], d["settings"].get("mirror_why"), e["npm_config_registry"], e[ && grep -q '"mirror_why": "install.sh, ' "$mt/p1/ovh/settings.json" then ok "mirrors: kept in this machine's settings; bin/vh exports tools/mirrors.txt's variables with cn (a variable the person set stays); install.sh keeps cn only when the official npm registry does not answer and the mirror does; off is kept and stops the trying" else bad "mirrors: $a | $b | probe: $c / $d / $e / $f"; fi + # two writers at once (Studio's settings panel and a terminal) both land: settings.update holds a lock, re-reads, merges, + # keeps the keys it was not given + a=$(XDG_CONFIG_HOME="$mt/w" python3 - <<'PY' 2>&1 +import json, os, subprocess, sys +code = "import sys; sys.path.insert(0, 'tools'); import settings\nfor i in range(60): settings.update({f'{sys.argv[1]}{i}': i})\n" +ps = [subprocess.Popen([sys.executable, "-c", code, w]) for w in ("a", "b")] +for q in ps: q.wait() +sys.path.insert(0, "tools"); import settings +settings.update({"mirror": "cn"}); settings.update({"mirror": None, "studio_theme": "dark"}) +d = json.load(open(settings.path())) +print(sum(k[0] in "ab" and k[1:].isdigit() for k in d), d.get("mirror"), d.get("studio_theme"), d.get("version")) +PY +) + if [ "$a" = "120 None dark 1" ]; then ok "settings: two writers at once both land (a lock, a fresh read, a merge); a key given as None goes, the others stay" + else bad "settings with two writers: $a"; fi rm -rf "$mt" # recipes sample: bad usage exits 2 before any render (an unknown id, a sequence, an unknown style); list --json names # the sheet a recipe carries (recipes check, above, holds every sketch to its sheet) diff --git a/tools/settings.py b/tools/settings.py index 58d97aa7..3839c49a 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -22,9 +22,11 @@ "mirror": "cn" | "off", absent: auto "mirror_why": "…", who set it and why, in a sentence (install.sh's probe says what did not answer) "mirror_at": "YYYY-MM-DD"} -Written whole to a temporary file beside it and moved into place, so a reader never sees half a file. +Every write goes through update(patch): under a lock (settings.json.lock), it reads the file as it is now, sets the keys +it was given (None takes one out), keeps all the others, and writes the whole file to a temporary file moved into place, +so two writers at once (Studio and a terminal) both land and a reader never sees half a file. """ -import datetime, json, os, sys, tempfile +import contextlib, datetime, fcntl, json, os, sys, tempfile from pathlib import Path ROOT = Path(__file__).resolve().parent.parent @@ -48,9 +50,21 @@ def load(): return d if isinstance(d, dict) else {"version": 1} -def save(d): +@contextlib.contextmanager +def locked(): + """The settings file's lock (settings.json.lock beside it, never removed: another process may hold the old one): held + by every write, so Studio and a terminal writing at once both land.""" + p = path(); p.parent.mkdir(parents=True, exist_ok=True) + with open(str(p) + ".lock", "a+") as f: + fcntl.flock(f, fcntl.LOCK_EX) + try: + yield + finally: + fcntl.flock(f, fcntl.LOCK_UN) + + +def _write(d): p = path() - p.parent.mkdir(parents=True, exist_ok=True) fd, tmp = tempfile.mkstemp(prefix=".settings.", suffix=".tmp", dir=p.parent) try: with os.fdopen(fd, "w", encoding="utf-8") as f: @@ -61,6 +75,28 @@ def save(d): os.unlink(tmp) +def update(patch): + """The one way to write: under the lock, read the file as it is now, set each key of patch (None takes a key out), keep + every other key (another writer's, or one this code does not know), and write the whole file to a temp file moved into + place. → the settings as written. Studio's settings panel and bin/vh settings both go through it.""" + with locked(): + d = load() + for k, v in patch.items(): + if k == "version": + continue + if v is None: + d.pop(k, None) + else: + d[k] = v + _write(d) + return d + + +def save(d): + """Write these keys (as update: under the lock, onto what is there now, nothing else taken out).""" + return update(d) + + def mirror(d=None): m = (d if d is not None else load()).get("mirror") return m if m in ("cn", "off") else "auto" @@ -123,14 +159,9 @@ def main(argv): print(mirror()); return 0 if len(argv) < 2 or argv[1] not in MODES or (len(argv) > 2 and (argv[2] != "--why" or len(argv) != 4)): print("usage: bin/vh settings mirror cn|off|auto [--why TEXT] (or --get)", file=sys.stderr); return 2 - d = load() - for k in ("mirror", "mirror_why", "mirror_at"): - d.pop(k, None) - if argv[1] != "auto": - d.update(mirror=argv[1], mirror_at=datetime.date.today().isoformat()) - if len(argv) == 4: - d["mirror_why"] = argv[3] - save(d) + on = argv[1] != "auto" + update({"mirror": argv[1] if on else None, "mirror_at": datetime.date.today().isoformat() if on else None, + "mirror_why": argv[3] if on and len(argv) == 4 else None}) if argv[1] == "cn": print(f"✓ downloads now come from the mainland-China mirrors ({operators()}; tools/mirrors.txt), kept in {path()};" " bin/vh settings mirror off turns that off") From 40f348b57d80b06879686ce4f1d5ffab833e4030 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 04:22:24 +0800 Subject: [PATCH 10/14] settings: set_mirror(mode, why=None) -> dict, what bin/vh settings mirror writes, without the saying (Studio calls it in-process) --- tools/ci.sh | 12 +++++++++++- tools/settings.py | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/ci.sh b/tools/ci.sh index d7646abe..134f306a 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1690,9 +1690,19 @@ sys.path.insert(0, "tools"); import settings settings.update({"mirror": "cn"}); settings.update({"mirror": None, "studio_theme": "dark"}) d = json.load(open(settings.path())) print(sum(k[0] in "ab" and k[1:].isdigit() for k in d), d.get("mirror"), d.get("studio_theme"), d.get("version")) +# set_mirror writes what the command writes, and leaves a key it does not know where it was +mine = settings.set_mirror("cn", "a test"); subprocess.run([sys.executable, "tools/settings.py", "mirror", "off"], capture_output=True) +cmd_off = {k: v for k, v in json.load(open(settings.path())).items() if k.startswith("mirror")} +settings.set_mirror("off"); fn_off = {k: v for k, v in json.load(open(settings.path())).items() if k.startswith("mirror")} +subprocess.run([sys.executable, "tools/settings.py", "mirror", "cn", "--why", "a test"], capture_output=True) +cmd_cn = {k: v for k, v in json.load(open(settings.path())).items() if k.startswith("mirror")} +last = settings.set_mirror("auto") +print(mine.get("mirror"), mine.get("mirror_why"), cmd_off == fn_off, cmd_cn == {k: v for k, v in mine.items() if k.startswith("mirror")}, + "mirror" in last, last.get("studio_theme"), last.get("a0")) PY ) - if [ "$a" = "120 None dark 1" ]; then ok "settings: two writers at once both land (a lock, a fresh read, a merge); a key given as None goes, the others stay" + if [ "$a" = "120 None dark 1 +cn a test True True False dark 0" ]; then ok "settings: two writers at once both land (a lock, a fresh read, a merge); a key given as None goes, the others stay; set_mirror writes what bin/vh settings mirror writes, other keys untouched" else bad "settings with two writers: $a"; fi rm -rf "$mt" # recipes sample: bad usage exits 2 before any render (an unknown id, a sequence, an unknown style); list --json names diff --git a/tools/settings.py b/tools/settings.py index 3839c49a..3fb2f6a0 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -22,6 +22,7 @@ "mirror": "cn" | "off", absent: auto "mirror_why": "…", who set it and why, in a sentence (install.sh's probe says what did not answer) "mirror_at": "YYYY-MM-DD"} +In-process (Studio): update(patch: dict) -> dict and set_mirror(mode, why=None) -> dict; load() reads, path() says where. Every write goes through update(patch): under a lock (settings.json.lock), it reads the file as it is now, sets the keys it was given (None takes one out), keeps all the others, and writes the whole file to a temporary file moved into place, so two writers at once (Studio and a terminal) both land and a reader never sees half a file. @@ -92,6 +93,18 @@ def update(patch): return d +def set_mirror(mode, why=None): + """The mirror setting, as bin/vh settings mirror [--why TEXT] writes it, through update(), saying nothing (Studio's + settings panel calls it in-process; main() calls it and does the saying). mode: cn, off or auto (auto takes the keys + out). → the settings as written. It does not fetch HyperFrames' Chrome from the mirror: bin/vh settings mirror cn and + bin/vh new do that (bin/vh settings chrome alone).""" + if mode not in MODES: + raise ValueError(f"mirror: {mode!r} is not one of {', '.join(MODES)}") + on = mode != "auto" + return update({"mirror": mode if on else None, "mirror_at": datetime.date.today().isoformat() if on else None, + "mirror_why": why if on and why else None}) + + def save(d): """Write these keys (as update: under the lock, onto what is there now, nothing else taken out).""" return update(d) @@ -159,9 +172,7 @@ def main(argv): print(mirror()); return 0 if len(argv) < 2 or argv[1] not in MODES or (len(argv) > 2 and (argv[2] != "--why" or len(argv) != 4)): print("usage: bin/vh settings mirror cn|off|auto [--why TEXT] (or --get)", file=sys.stderr); return 2 - on = argv[1] != "auto" - update({"mirror": argv[1] if on else None, "mirror_at": datetime.date.today().isoformat() if on else None, - "mirror_why": argv[3] if on and len(argv) == 4 else None}) + set_mirror(argv[1], argv[3] if len(argv) == 4 else None) if argv[1] == "cn": print(f"✓ downloads now come from the mainland-China mirrors ({operators()}; tools/mirrors.txt), kept in {path()};" " bin/vh settings mirror off turns that off") From 2106efc3c94bdf3689212e7eb01484c768970387 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 05:40:20 +0800 Subject: [PATCH 11/14] Mirrors, review of #231: read on every run (off takes out what an earlier bin/vh exported), a source of the person's own stays, every Chrome fetch through the mirror, the probe tries the right hosts twice settings.py: env_changes() is the one reader (bin/vh asks it when the file names a mirror or one was inherited), an inherited OVH_MIRROR with the setting not cn takes out exactly the values bin/vh exported; npm's registry in an .npmrc and uv's index or Python mirror in a uv.toml or pyproject.toml are left alone and said; a broken file kept as settings.json.bad, a newer version never written over, a relative XDG_CONFIG_HOME ignored, an unwritable folder one line. install.sh: npmjs through npm ping, Hugging Face and Google's storage through curl, all at once, twice each; the reason says what happened; the Chrome step cannot stop the install; -h prints the whole header. bin/vh: render, frames, textcheck and hf fetch HyperFrames' Chrome through the mirror with cn, with the @puppeteer/browsers HyperFrames' node_modules holds; settings chrome [project]; the hints name it. mirrors.txt says what is checked and what is trusted to the mirror, and what is not covered; README and the change note too. --- README.md | 2 +- README.zh-CN.md | 2 +- bin/vh | 72 ++++--- changes/first-run-mirrors.md | 6 +- install.sh | 66 ++++-- tools/ci.sh | 132 ++++++++---- tools/commands.json | 8 +- tools/doctor.py | 7 +- tools/mirrors.txt | 29 ++- tools/readcheck.py | 6 +- tools/schemas/output/settings.schema.json | 10 +- tools/settings.py | 252 ++++++++++++++++++---- tools/status.py | 6 +- 13 files changed, 453 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index fd69ccc3..68337849 100644 --- a/README.md +++ b/README.md @@ -424,7 +424,7 @@ bash install.sh --no-icon # leave OVH Studio out of your - The installer fetches only the newest commit: the repo itself is about 95 MB to download and 200 MB on disk, before its packages and the reference repos. To contribute or browse the history, `git clone` normally and run `bin/vh setup`. - To update, run the installer again with the same options (or `git pull`); `LOCAL.md` and `projects/` are left alone, and it stops before overwriting files you changed. The installed skills are short stubs that read `skills/` in the clone, so they follow the update; `bin/vh doctor` says in the rare case one needs `bin/vh install-skill` again. - The showcase videos aren't in git; to rebuild a showcase locally, `tools/fetch_media.sh` downloads them from the release to where its scripts expect them. -- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, the sound tools' Python packages about 0.7 GB, and the default local voice about 2.6 GB (its packages 0.8 GB, its model 1.8 GB), which `bin/vh tts` says before it starts and shows the progress of (`--provider edge` needs only a small package). The local Whisper behind `--align local` is about 3.6 GB more, said the same way (measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). Where the official sources are blocked: the installer tries the official npm registry first, and when it does not answer in 5 s and the mainland-China mirror does, it switches to the mirrors (npmmirror, Tsinghua's TUNA, hf-mirror, listed in `tools/mirrors.txt`), says so, and every later `bin/vh` download follows (npm, Python packages, the local voice's model, Electron, the Chrome renders use); `bin/vh settings mirror off` turns that off. GitHub itself has no mirror: cloning the repo still needs GitHub. More on the wiki's [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) page. +- The first render and the first use of the sound tools download more into `~/.cache`: Chrome about 200 MB, the sound tools' Python packages about 0.7 GB, and the default local voice about 2.6 GB (its packages 0.8 GB, its model 1.8 GB), which `bin/vh tts` says before it starts and shows the progress of (`--provider edge` needs only a small package). The local Whisper behind `--align local` is about 3.6 GB more, said the same way (measured 2026-11; where each goes is on the wiki's [Getting Started](https://github.com/ZLHad/OpenVideoHarness/wiki/Getting-Started)). Where the official sources are blocked: the installer tries the official npm registry, Hugging Face and Google's storage first (twice each), and when one does not answer and its mainland-China mirror does, it switches to the mirrors (npmmirror, Tsinghua's TUNA, hf-mirror, listed in `tools/mirrors.txt`) and says which and why. From then on the downloads `bin/vh` starts follow: npm, Python packages, the local voice's model, Electron, the Chrome renders use, and an agent's own `npm` or `uv` in a session Studio started. A registry you set yourself (an `.npmrc`, a `uv.toml`, the variable) stays yours. `bin/vh settings mirror off` turns it off; installed before this, `bin/vh settings mirror cn` turns it on. Not covered: GitHub (the clone itself, `references/fetch.sh`, `--obscura`), `bin/vh hf add`, `bin/vh hdri` (Poly Haven) and the Google Fonts the hand-drawn engine's studio page loads. More on the wiki's [China network](https://github.com/ZLHad/OpenVideoHarness/wiki/China-Network) page. Skill only: `npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`. It's a pointer: on first use it asks before installing the full workbench. That copy stays as it was when the repo changes; once the workbench is installed, `bin/vh install-skill` replaces it with a stub that follows the clone. diff --git a/README.zh-CN.md b/README.zh-CN.md index 0fca0b0a..1a5b677b 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -424,7 +424,7 @@ bash install.sh --no-icon # 不把 OVH Studio 放进应 - 安装脚本只拉最新的一个提交,仓库本身下载约 95 MB、占约 200 MB 磁盘,依赖和参考仓库另算;想参与贡献或翻历史,就正常 `git clone`,再运行 `bin/vh setup`。 - 更新:用同样的参数再运行一次安装命令(或者 `git pull`);`LOCAL.md` 和 `projects/` 不动,要覆盖你改过的文件时会先停下来。装出去的 skill 是指回克隆里 `skills/` 的短桩,跟着一起更新;少数要重装的时候(`bin/vh install-skill`),`bin/vh doctor` 会说。 - 样片的视频不在 git 里,要在本地复现样片时运行 `tools/fetch_media.sh`,它从 Release 下载到脚本要的位置。 -- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,声音工具的 Python 依赖约 0.7 GB,默认的本地配音约 2.6 GB(依赖 0.8 GB、模型 1.8 GB;`bin/vh tts` 开始前会先说,并显示进度;`--provider edge` 只要一个小包);`--align local` 用的本地 Whisper 另需约 3.6 GB,同样先说(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络:安装时先试官方的 npm 源,5 秒内没有应答、国内镜像有,就改用国内镜像(npmmirror、清华 TUNA、hf-mirror,列在 `tools/mirrors.txt`)并说一声,之后 `bin/vh` 的下载(npm、Python 包、本地配音模型、Electron、渲染用的 Chrome)都跟着走;`bin/vh settings mirror off` 关掉。GitHub 本身没有镜像:克隆仓库还是要连得上 GitHub。其余细节见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 +- 第一次渲染、第一次用声音工具时还会往 `~/.cache` 下载:Chrome 约 200 MB,声音工具的 Python 依赖约 0.7 GB,默认的本地配音约 2.6 GB(依赖 0.8 GB、模型 1.8 GB;`bin/vh tts` 开始前会先说,并显示进度;`--provider edge` 只要一个小包);`--align local` 用的本地 Whisper 另需约 3.6 GB,同样先说(2026-11 实测;各放在哪里见 wiki 的[快速开始](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B))。国内网络:安装时先试官方的 npm 源、Hugging Face 和 Google 的存储(各试两次),哪个连不上、它的国内镜像连得上,就改用国内镜像(npmmirror、清华 TUNA、hf-mirror,列在 `tools/mirrors.txt`),并说明是哪个、为什么。之后 `bin/vh` 起的下载都跟着走:npm、Python 包、本地配音模型、Electron、渲染用的 Chrome,还有 Studio 起的 agent 自己跑的 `npm`、`uv`。你自己设过的源(`.npmrc`、`uv.toml` 或那个变量)不动。`bin/vh settings mirror off` 关掉;这之前装的,`bin/vh settings mirror cn` 打开。不走镜像的:GitHub(克隆本身、`references/fetch.sh`、`--obscura`)、`bin/vh hf add`、`bin/vh hdri`(Poly Haven),以及手绘引擎的 studio 页面加载的 Google Fonts。其余细节见 wiki 的[国内网络](https://github.com/ZLHad/OpenVideoHarness/wiki/%E5%9B%BD%E5%86%85%E7%BD%91%E7%BB%9C)。 只装 skill:`npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness`。它只是一个指针,第一次用时会征得你同意,再把完整的工作台装好。这样装的是整份副本,仓库更新了它不变;工作台装好以后跑一次 `bin/vh install-skill`,换成跟随克隆的短桩。 diff --git a/bin/vh b/bin/vh index 1b082d88..9cce523f 100755 --- a/bin/vh +++ b/bin/vh @@ -8,15 +8,16 @@ set -euo pipefail unset CDPATH # an exported CDPATH would send a relative cd (this one: bin/vh run as bin/vh) to another folder, and print it ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" c_ok=$'\033[32m✓\033[0m'; c_no=$'\033[31m✗\033[0m'; c_wa=$'\033[33m!\033[0m' -# this machine's settings (tools/settings.py): with "mirror": "cn", every download a command starts goes to the mirrors in -# tools/mirrors.txt (npm, uv, Hugging Face, Electron; a variable already set wins); read with grep, so no python3 per run -if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/ovh/settings.json" ] && grep -q '"mirror"[[:space:]]*:[[:space:]]*"cn"' "${XDG_CONFIG_HOME:-$HOME/.config}/ovh/settings.json" 2>/dev/null; then - while read -r _k _v _o _m _w; do - case "$_k" in ""|\#*) continue ;; esac - if [ "$_v" != - ] && [ -z "${!_v:-}" ]; then export "$_v=$_m"; fi - done < "$ROOT/tools/mirrors.txt" - export OVH_MIRROR=cn +# this machine's settings (tools/settings.py) are read on every run, so a change reaches every process at its next bin/vh: +# with "mirror": "cn" bin/vh exports the mirror variables of tools/mirrors.txt for what it runs, the agents Studio starts +# included (one the person set stays theirs: in the environment, or npm's or uv's own configuration); otherwise it takes out +# again the ones a bin/vh before it exported (inherited OVH_MIRROR=cn). One reader, settings.py; python3 runs only when the +# file names a mirror or a mirror was inherited (an XDG_CONFIG_HOME that is not absolute is ignored, as settings.py does) +_cf=${XDG_CONFIG_HOME:-}; case "$_cf" in /*) ;; *) _cf=$HOME/.config ;; esac +if [ -n "${OVH_MIRROR:-}" ] || { [ -f "$_cf/ovh/settings.json" ] && grep -q '"mirror"' "$_cf/ovh/settings.json" 2>/dev/null; }; then + if _env=$(python3 "$ROOT/tools/settings.py" env 2>/dev/null); then eval "$_env"; fi fi +unset _cf _env declare -a TYPES=( "math:01-math-science-explainer:数学/科学原理讲解(Manim)" @@ -135,17 +136,37 @@ hf_pin() { # hf_pin : the Chrome version pinned by the HyperFrames in the n [ ${#files[@]} -gt 0 ] || return 1 awk -F'"' -v k="var $k = " '$1 == k && $2 ~ /^[0-9][0-9.]*$/ { print $2; f = 1; exit } END { exit !f }' "${files[@]}" 2>/dev/null } +hf_mods() { # hf_mods : the folder at or above dir whose node_modules holds HyperFrames (as hf_pin looks), else fails + local d + [ -n "${1:-}" ] && d=$(cd "$1" 2>/dev/null && pwd) || return 1 + while [ ! -d "$d/node_modules/hyperframes" ]; do [ "$d" = / ] && return 1; d=$(dirname "$d"); done + echo "$d" +} hf_chrome_mirror() { # hf_chrome_mirror : with the mirror on (cn) and no chrome-headless-shell yet at the version the HyperFrames - # installed for dir pins, fetch it from the mirror into the folder HyperFrames looks in: HyperFrames has no setting for where it - # downloads its Chrome, so without this the first render would go to storage.googleapis.com anyway (no hash is pinned for it) + # installed for dir pins (dir has none: styles/_swatch's), fetch it from the mirror into the folder HyperFrames looks in: + # HyperFrames has no setting for where it downloads its Chrome, so without this the first render would go to + # storage.googleapis.com anyway. With the @puppeteer/browsers HyperFrames' own node_modules holds (under its lockfile's + # hash where there is one), else the one pinned here; no hash is pinned for the Chrome itself. Its lines go to stderr [ "${OVH_MIRROR:-}" = cn ] || return 0 - local d=$1 pin base - pin=$(hf_pin "$d") || return 0 + local d m pin base cli + m=$(hf_mods "${1:-.}") || m=$(hf_mods "$ROOT/styles/_swatch") || return 0 + pin=$(hf_pin "$m") || return 0 [ -n "$(shell_folder "$HOME/.cache/hyperframes/chrome/chrome-headless-shell" "$pin" 2>/dev/null)" ] && return 0 base=$(awk '$1 == "chrome" { print $4 }' "$ROOT/tools/mirrors.txt") - echo "→ HyperFrames' Chrome $pin from the mirror ($base, about 93 MB), into ~/.cache/hyperframes/chrome, where its first render looks" - (cd "$d" && npx --yes @puppeteer/browsers install "chrome-headless-shell@$pin" --path "$HOME/.cache/hyperframes/chrome" --base-url "$base" >/dev/null 2>&1) \ - || echo "$c_wa HyperFrames' Chrome did not come from the mirror; the first render tries its own download" + if [ -x "$m/node_modules/.bin/browsers" ]; then cli=("$m/node_modules/.bin/browsers"); else cli=(npx --yes "@puppeteer/browsers@$PUPPETEER_BROWSERS"); fi + echo "→ HyperFrames' Chrome $pin from the mirror ($base, about 93 MB), into ~/.cache/hyperframes/chrome, where its first render looks" >&2 + (cd "$m" && "${cli[@]}" install "chrome-headless-shell@$pin" --path "$HOME/.cache/hyperframes/chrome" --base-url "$base" >/dev/null 2>&1) \ + || { echo "$c_wa HyperFrames' Chrome did not come from the mirror; the first render tries its own download (bin/vh settings chrome tries again)" >&2; return 1; } +} +PUPPETEER_BROWSERS=3.2.3 # the @puppeteer/browsers HyperFrames 0.8.202 brings, for a folder without node_modules +chrome_hint() { # chrome_hint : how to get the chrome-headless-shell HyperFrames renders with, in words for a message + if [ "${OVH_MIRROR:-}" = cn ]; then echo "bin/vh settings chrome ${1:-} (from the mirror)"; else echo "npx hyperframes browser ensure (in a HyperFrames project)"; fi +} +hf_shell_any() { # hf_shell_any : hf_shell, and with the mirror on and none here yet, after fetching it from the mirror + hf_shell "${1:-}" && return 0 + [ "${OVH_MIRROR:-}" = cn ] || return 1 + hf_chrome_mirror "${1:-.}" >/dev/null || return 1 + hf_shell "${1:-}" } old_mac() { [ "$(uname)" = Darwin ] && [ "$(uname -r | cut -d. -f1)" -lt 22 ]; } # macOS 12 or older: HyperFrames stops Chrome at 150 shell_folder() { # shell_folder [version]: the folder of that chrome-headless-shell version, else (no version given) the newest; @@ -193,14 +214,15 @@ cmd_install_skill() { # writes a stub for each skill in skills/: its frontmatter } cmd_settings() { # this machine's settings (tools/settings.py, -h); the mirror turned on also fetches HyperFrames' Chrome from it now, # since HyperFrames cannot be pointed at a mirror itself - if [ "${1:-}" = chrome ]; then # settings chrome: HyperFrames' Chrome from the mirror now, when the mirror is on and it is not here - [ $# = 1 ] || { echo "usage: bin/vh settings chrome" >&2; return 2; } + if [ "${1:-}" = chrome ]; then # settings chrome [project]: HyperFrames' Chrome from the mirror now, when the mirror is on and it is not here + [ $# -le 2 ] || { echo "usage: bin/vh settings chrome [project]" >&2; return 2; } [ "${OVH_MIRROR:-}" = cn ] || { echo "the mirrors are not on (bin/vh settings mirror cn): HyperFrames downloads its own Chrome at the first render"; return 0; } - [ -d "$ROOT/styles/_swatch/node_modules/hyperframes" ] || { echo "$c_wa no HyperFrames in styles/_swatch yet (cd styles/_swatch && npm ci): nothing to fetch Chrome for" >&2; return 1; } - hf_chrome_mirror "$ROOT/styles/_swatch"; return 0 + local w=${2:-$ROOT/styles/_swatch} + hf_mods "$w" >/dev/null || { echo "$c_wa no HyperFrames installed for ${2:-styles/_swatch} yet (${2:+bin/vh hf-init it, or }cd ${2:-styles/_swatch} && npm ci): nothing to fetch Chrome for" >&2; return 1; } + hf_chrome_mirror "$w"; return $? fi python3 "$ROOT/tools/settings.py" "$@" || return $? - if [ "${1:-}" = mirror ] && [ "${2:-}" = cn ] && [ -d "$ROOT/styles/_swatch/node_modules/hyperframes" ]; then OVH_MIRROR=cn; hf_chrome_mirror "$ROOT/styles/_swatch"; fi + if [ "${1:-}" = mirror ] && [ "${2:-}" = cn ] && [ -d "$ROOT/styles/_swatch/node_modules/hyperframes" ]; then OVH_MIRROR=cn; hf_chrome_mirror "$ROOT/styles/_swatch" || true; fi } cmd_sync_agents() { # CLAUDE.md's 命令行 line from tools/commands.json first, then AGENTS.md from CLAUDE.md local m; m=$(python3 "$ROOT/tools/commands.py" claude-line --write "$ROOT/CLAUDE.md") || exit 1 @@ -887,8 +909,8 @@ cmd_textcheck() { # canvas text covered or too faint (tools/textcheck/textcheck. local b=${CHROME_PATH:-} d if [ -z "$b" ] || [ ! -x "$b" ]; then d=$(arg_dir "$@") - b=$(hf_shell "$d") || b=$(chrome_path) || { echo "$c_no bin/vh textcheck needs a headless Chrome: npx hyperframes browser ensure (in a HyperFrames project), install Chrome or Chromium, or set CHROME_PATH" >&2; exit 2; } - hf_chrome "$d" >/dev/null || echo "$c_wa not the chrome-headless-shell hyperframes render uses for this project, so text can lay out a little differently in the film (npx hyperframes browser ensure there fetches it)" >&2 + b=$(hf_shell_any "$d") || b=$(chrome_path) || { echo "$c_no bin/vh textcheck needs a headless Chrome: $(chrome_hint "$d"), install Chrome or Chromium, or set CHROME_PATH" >&2; exit 2; } + hf_chrome "$d" >/dev/null || echo "$c_wa not the chrome-headless-shell hyperframes render uses for this project, so text can lay out a little differently in the film ($(chrome_hint "$d") fetches it)" >&2 fi exec node "$ROOT/tools/textcheck/textcheck.mjs" --browser "$b" "$@" } @@ -920,7 +942,7 @@ film_browser() { # film_browser [dir]: the browser the page-contract t # render uses for dir, else the newest in ~/.cache/puppeteer, else Chrome or Chromium); the command is for the message local b=${CHROME_PATH:-} if [ -z "$b" ] || [ ! -x "$b" ]; then - b=$(hf_shell "${2:-}") || b=$(chrome_path) || { echo "$c_no bin/vh $1 needs a headless Chrome: npx hyperframes browser ensure (in a HyperFrames project), install Chrome or Chromium, or set CHROME_PATH" >&2; return 1; } + b=$(hf_shell_any "${2:-}") || b=$(chrome_path) || { echo "$c_no bin/vh $1 needs a headless Chrome: $(chrome_hint "${2:-}"), install Chrome or Chromium, or set CHROME_PATH" >&2; return 1; } fi echo "$b" } @@ -1454,7 +1476,9 @@ cmd_web() { # stdlib + the existing Chrome CDP transport; Obscura is an explicit case "$1" in fetch|shot) b=$(film_browser web "${2:-}" 2>/dev/null) || b="" ;; esac CHROME_PATH="${b:-${CHROME_PATH:-}}" python3 "$ROOT/tools/web/web.py" "$@" } -cmd_hf() { [ $# -gt 0 ] || { cmd_usage hf >&2; exit 2; }; python3 "$ROOT/tools/hf.py" "$@"; } # stdlib; add runs HyperFrames' own add +cmd_hf() { [ $# -gt 0 ] || { cmd_usage hf >&2; exit 2; } # stdlib; add runs HyperFrames' own add + case "${1:-}" in -h|--help) ;; *) hf_chrome_mirror "$(arg_dir "${@:2}")" || true ;; esac # with the mirror on: its Chrome first, from there + python3 "$ROOT/tools/hf.py" "$@"; } cmd_components() { python3 "$ROOT/tools/components.py" "$@"; } # stdlib; check reads component.js through node, sample runs the swatch renderer cmd_deliver() { [ $# -gt 0 ] || { cmd_usage deliver >&2; exit 2; }; python3 "$ROOT/tools/deliver.py" "$@"; } # ffmpeg only cmd_looks() { [ $# -gt 0 ] || { cmd_usage looks >&2; exit 2; }; python3 "$ROOT/tools/looks.py" "$@"; } # ffmpeg; the ledger outside the repo diff --git a/changes/first-run-mirrors.md b/changes/first-run-mirrors.md index d11bde11..ea671aeb 100644 --- a/changes/first-run-mirrors.md +++ b/changes/first-run-mirrors.md @@ -1,7 +1,7 @@ **连不上官方源时,安装自动改用国内镜像,之后的下载都跟着走** - Why: 在国内网络下,第一次安装和第一次做片要连 npm、PyPI、Hugging Face、GitHub Releases 和 Google 的存储;原来要照 wiki 手动设三四个变量、另跑两条命令装 Chrome,Studio 应用的 Electron 下载没有写怎么办。 -- 安装时先试官方的 npm 源(5 秒);没有应答、国内镜像有,就改用国内镜像,用一句话说明,并记在这台机器自己的设置里(`~/.config/ovh/settings.json`)。不按语言或时区猜。`--mirror cn` 直接用,`--mirror off` 不用,也记下来。 -- 镜像的地址集中在 `tools/mirrors.txt` 一个文件里,每一行写明是谁在运营(npmmirror.com、清华 TUNA、hf-mirror.com)。镜像打开时,`bin/vh` 给它运行的每条命令设好 npm、uv(Python 包和 Python 本身)、Hugging Face 和 Electron 的镜像变量;你自己设过的变量不动。HyperFrames 下载 Chrome 时没有可设的地址,所以由 `bin/vh new` 和安装先从镜像把它装进 HyperFrames 找的目录。 +- 安装时先试官方的 npm 源(经 npm 试,它自己的代理设置算数)、Hugging Face 和 Google 的存储(Chrome),各试两次、每次 5 秒;哪个连不上、它的国内镜像连得上,就改用国内镜像,用一句话说明是哪个、怎么连不上,并记在这台机器自己的设置里(`~/.config/ovh/settings.json`)。不按语言或时区猜。`--mirror cn` 直接用,`--mirror off` 不用,也记下来。这之前装的,`bin/vh settings mirror cn` 打开。 +- 镜像的地址集中在 `tools/mirrors.txt` 一个文件里,每一行写明是谁在运营(npmmirror.com、清华 TUNA、hf-mirror.com)。设置每次都从文件读:镜像打开时,`bin/vh` 给它运行的每条命令设好 npm、uv(Python 包和 Python 本身)、Hugging Face 和 Electron 的镜像变量,Studio 起的 agent 也一样;关掉以后,之前继承下来的这些变量下一次运行就拿掉。你自己设的源不动:环境变量,`.npmrc` 里 npm 的源,`uv.toml` 里 uv 的源。HyperFrames 下载 Chrome 没有可设的地方,`bin/vh new`、`render`、`hf`、`frames` 和 `bin/vh settings chrome [项目]` 从镜像替它下好。不走镜像的:GitHub(克隆、`references/fetch.sh`、`--obscura`)、`bin/vh hf add`、`bin/vh hdri`、手绘引擎 studio 页面的 Google Fonts。 - 新命令 `bin/vh settings`:看这台机器的设置,`bin/vh settings mirror cn|off|auto` 改镜像,`--json` 给 Studio 的设置面板读。`bin/vh doctor` 多一行说现在走哪里、怎么关。 -- 已有的校验不变,也不信任镜像:npm ci 按 lockfile 里的哈希核对每个包;Electron 按它自己的包里带的 checksums.json 核对。uv 的包、Hugging Face 的模型、Python 和 Chrome 没有钉住的哈希,和从官方源下一样照收。 +- 校验:有 lockfile 的地方(`styles/_swatch`、Studio 的 Electron 壳、agent 适配器、ClaudeAnimationBase),npm ci 按 lockfile 里的哈希核对每个包;Electron 按它自己的包里带的 checksums.json 核对;uv 按它自带的 sha256 核对 Python 的构建(试过:从镜像目录换进去的包会被拒)。没有 lockfile 的就完全信任镜像,和今天信任 npmjs.org 一样:`bin/vh new` 装的 hyperframes 和 gsap、`npx hyperframes@<版本>`、没有 node_modules 时用的 @puppeteer/browsers(钉了版本,没钉哈希),包和核对它的哈希都来自镜像;uv 的包、Hugging Face 的模型、HyperFrames 的 Chrome 也是照收。 - 切到镜像以后,uv 会按新的源重新下载之前缓存过的 Python 包(它的缓存按源区分)。 diff --git a/install.sh b/install.sh index 1781e744..ac47dd99 100755 --- a/install.sh +++ b/install.sh @@ -5,9 +5,10 @@ # What it does, and where it puts things: # 1. clone the repo into --dir, newest commit only (about 200 MB on disk; a re-run moves it to the newest commit, keeping LOCAL.md and projects/) # 1b. the download mirrors (tools/mirrors.txt): with neither --mirror nor a choice made before (bin/vh settings), try the official -# npm registry for 5 s; when it does not answer and the mainland-China mirror does, use the mirrors from here on, say so in one -# line, and keep the choice in ~/.config/ovh/settings.json, so later bin/vh downloads use them too (bin/vh settings mirror off -# turns that off). --mirror cn uses them without trying, --mirror off never. Never guessed from the language or time zone +# npm registry (through npm, so its own proxy setting counts), Hugging Face and Google's storage (Chrome), twice each, 5 s a try; +# when one does not answer and its mainland-China mirror does, use the mirrors from here on, say which and why in one line, +# and keep the choice in ~/.config/ovh/settings.json, so later bin/vh downloads use them too (bin/vh settings mirror off turns +# that off). --mirror cn uses them without trying, --mirror off never. Never guessed from the language or time zone # 2. npm install in engines/ClaudeAnimationBase and npm ci in styles/_swatch (HyperFrames 0.8.202), both inside --dir (about 180 MB of # node_modules; npm also writes its own cache, ~/.npm). The read-only reference repos references/fetch.sh lists are not fetched: # an agent fetches the one a doc points to when it first needs it (bash references/fetch.sh , which says its size first); @@ -41,7 +42,7 @@ DIR="${OVH_DIR:-$HOME/OpenVideoHarness}"; REFS=0; SKILL=all; OBSCURA=0; ICON=def while [ $# -gt 0 ]; do case "$1" in --dir) DIR="$2"; shift 2 ;; --refs) REFS=1; shift ;; --no-refs) REFS=0; shift ;; --no-skill) SKILL=none; shift ;; --skill) SKILL="${2:?--skill needs claude|codex|all|none}"; shift 2 ;; --obscura) OBSCURA=1; shift ;; --mirror) MIRROR="${2:?--mirror needs cn or off}"; shift 2 ;; --icon) ICON=yes; shift ;; --no-icon) ICON=no; shift ;; - -h|--help) sed -n '2,32p' "$0"; exit 0 ;; *) echo "unknown option: $1"; exit 1 ;; esac; done + -h|--help) awk 'NR == 1 { next } /^#/ { sub(/^# ?/, ""); print; next } { exit }' "$0"; exit 0 ;; *) echo "unknown option: $1"; exit 1 ;; esac; done case "$SKILL" in claude|codex|all|none) ;; *) echo "unknown --skill '$SKILL' (claude|codex|all|none)"; exit 1 ;; esac [ -z "$MIRROR" ] || case "$MIRROR" in cn|off) ;; *) echo "unknown --mirror '$MIRROR' (cn|off)"; exit 1 ;; esac say() { printf '\033[1m→ %s\033[0m\n' "$*"; } @@ -104,14 +105,55 @@ if [ -d "$DIR/.git" ]; then say "updating $DIR" else say "cloning into $DIR (newest commit only)" git clone -q --depth 1 --single-branch "$REPO" "$DIR" || { echo "✗ Could not download OpenVideoHarness: check the network (or your proxy) and run this installer again."; exit 1; }; fi cd "$DIR" -answers() { command -v curl >/dev/null 2>&1 && curl -fsS -m 5 -o /dev/null "$1" 2>/dev/null; } -if [ -n "$MIRROR" ]; then bin/vh settings mirror "$MIRROR" --why "install.sh --mirror $MIRROR, $(date +%F)" | sed 's/^/ /' -elif [ "$(bin/vh settings mirror --get 2>/dev/null)" = auto ] && ! answers https://registry.npmjs.org/ && answers https://registry.npmmirror.com/; then - bin/vh settings mirror cn --why "install.sh, $(date +%F): registry.npmjs.org did not answer in 5 s, registry.npmmirror.com did" >/dev/null - echo " npm's registry did not answer in 5 s, so downloads come from the mainland-China mirrors from now on (npmmirror.com, TUNA, hf-mirror.com;" - echo " tools/mirrors.txt). bin/vh settings mirror off turns that off." +reach() { # reach [npm]: does it answer at all (any HTTP reply counts), in 5 s, at the first or the second try? → 0; else 1, + # and what happened on stdout. With npm: npm ping, so a proxy that lives only in npm's own configuration is used as npm would + local rc out="" + for _ in 1 2; do + if [ "${2:-}" = npm ] && command -v npm >/dev/null 2>&1; then + out=$(npm ping --registry "$1" --fetch-timeout=5000 --fetch-retries=0 2>&1) && return 0 + case "$out" in *ENOTFOUND*|*EAI_AGAIN*) out="its name did not resolve" ;; *ETIMEDOUT*|*imeout*) out="it did not answer in 5 s" ;; + *ECONNREFUSED*) out="it refused the connection" ;; *ECONNRESET*) out="the connection was reset" ;; *) out="npm could not reach it" ;; esac + elif command -v curl >/dev/null 2>&1; then + rc=0; curl -sS -o /dev/null -m 5 "$1" 2>/dev/null || rc=$? + [ "$rc" = 0 ] && return 0 + case $rc in 5) out="the proxy's name did not resolve" ;; 6) out="its name did not resolve" ;; 7) out="it refused the connection" ;; + 28) out="it did not answer in 5 s" ;; 35|60) out="the secure connection failed" ;; 52|56) out="the connection was reset" ;; *) out="curl error $rc" ;; esac + else echo "nothing here to try it with (no curl)"; return 1 + fi + done + echo "$out, twice"; return 1 +} +PROBES='registry.npmjs.org https://registry.npmjs.org/ https://registry.npmmirror.com/ npm +huggingface.co https://huggingface.co/ https://hf-mirror.com/ curl +storage.googleapis.com https://storage.googleapis.com/chrome-for-testing-public/ https://cdn.npmmirror.com/binaries/chrome-for-testing/ curl' # each official source: what to try, its mirror, how (npm: through npm itself) +probe_mirrors() { # with no choice made: each official source, all three at once; cn when one fails and its mirror answers. → the why + local pt name url mir how n=0 why="" + pt=$(mktemp -d "${TMPDIR:-/tmp}/ovh-probe.XXXXXX") + while read -r name url mir how; do + n=$((n + 1)); ( if r=$(reach "$url" "$how"); then : > "$pt/$n.ok"; else printf '%s' "$r" > "$pt/$n.no"; fi ) & + done <<<"$PROBES" + wait + n=0 + while read -r name url mir how; do + n=$((n + 1)); [ -f "$pt/$n.no" ] || continue + mir=${mir#https://} + if reach "https://$mir" >/dev/null; then why="${why:+$why; }$name: $(cat "$pt/$n.no"), and ${mir%%/*} answered"; fi + done <<<"$PROBES" + rm -rf "$pt" + printf '%s' "$why" +} +NOW="" # the mirror for this run when it could not be kept (an unwritable ~/.config) +if [ -n "$MIRROR" ]; then + bin/vh settings mirror "$MIRROR" --why "install.sh --mirror $MIRROR, $(date +%F)" | sed 's/^/ /' || NOW=$MIRROR +elif [ "$(bin/vh settings mirror --get 2>/dev/null)" = auto ]; then + why=$(probe_mirrors) + if [ -n "$why" ]; then + bin/vh settings mirror cn --why "install.sh, $(date +%F): $why" >/dev/null || NOW=cn + echo " $why: so downloads come from the mainland-China mirrors from now on (npmmirror.com, TUNA, hf-mirror.com;" + echo " tools/mirrors.txt). bin/vh settings mirror off turns that off." + fi fi -eval "$(python3 tools/settings.py env)" # the mirrors, when they are on, for this script's own downloads too +eval "$(python3 tools/settings.py env ${NOW:+--mode "$NOW"})" # the mirrors, when they are on, for this script's own downloads too say "installing the bundled engine (ClaudeAnimationBase)" (cd engines/ClaudeAnimationBase && npm install --silent) || echo "! the hand-drawn engine's packages did not install; running this installer again finishes them" n=$(grep -cE '^(full|sparse|textonly) ' references/fetch.sh || true) # counted from the list, so it cannot go stale @@ -123,7 +165,7 @@ else had=0; [ ! -d references/repos ] || had=$(find references/repos -mindepth 2 fi say "installing the renderer for style samples (HyperFrames, for bin/vh style)" (cd styles/_swatch && npm ci --silent) || echo "! the renderer for style samples did not install; it is tried again the first time a style sample is made" -[ "${OVH_MIRROR:-}" != cn ] || bin/vh settings chrome # with the mirrors on: HyperFrames' Chrome from the mirror now +[ "${OVH_MIRROR:-}" != cn ] || bin/vh settings chrome || true # with the mirrors on: its Chrome from the mirror now (a miss says so, in a line) [ -f LOCAL.md ] || cp LOCAL.example.md LOCAL.md if [ "$SKILL" != none ]; then # one line for the stubs it wrote (each says where it went when run by hand: bin/vh install-skill) say "telling Claude Code and Codex where this workbench is (skills)" diff --git a/tools/ci.sh b/tools/ci.sh index 134f306a..8d7ea792 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -1659,51 +1659,105 @@ PY else bad "first downloads here: $a | $b | no script ($re): $qcalls | progress lines: $g"; fi ;; esac rm -rf "$ft" - # the download mirrors: this machine's settings (tools/settings.py) in a file of their own; with "mirror": "cn" bin/vh exports - # the variables of tools/mirrors.txt for what it runs (one the person set stays theirs); install.sh tries the official npm - # registry first and keeps cn only when it does not answer and the mirror does; --mirror off is kept, and stops the trying - mt=$(mktemp -d "${TMPDIR:-/tmp}/vh-mirror.XXXXXX") - a=$(XDG_CONFIG_HOME="$mt/c" vh settings mirror --get; XDG_CONFIG_HOME="$mt/c" vh settings mirror cn --why "a test" >/dev/null - (unset npm_config_registry HF_ENDPOINT UV_DEFAULT_INDEX ELECTRON_MIRROR; XDG_CONFIG_HOME="$mt/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); e = d["environment"] -print(d["mirror"], d["settings"].get("mirror_why"), e["npm_config_registry"], e["HF_ENDPOINT"], e["UV_DEFAULT_INDEX"], e["ELECTRON_MIRROR"])' - XDG_CONFIG_HOME="$mt/c" npm_config_registry=https://mine.example vh settings --json | python3 -c 'import json, sys; print(json.load(sys.stdin)["environment"]["npm_config_registry"])' - XDG_CONFIG_HOME="$mt/c" vh settings mirror off >/dev/null; (unset npm_config_registry; XDG_CONFIG_HOME="$mt/c" vh settings --json) | python3 -c 'import json, sys; d = json.load(sys.stdin); print(d["mirror"], d["environment"]["npm_config_registry"])' - XDG_CONFIG_HOME="$mt/c" vh settings mirror nope 2>/dev/null; echo "exit $?") - b=$(awk '!/^#/ && NF { if ($4 !~ /^https:\/\//) print "not https: " $1 }' tools/mirrors.txt) - mkdir -p "$mt/bin"; printf '#!/bin/sh\ncase "$*" in *registry.npmjs.org*) [ -n "$OFFICIAL" ] && exit 0; exit 28 ;; *) exit 0 ;; esac\n' > "$mt/bin/curl"; chmod +x "$mt/bin/curl" - sed -n '/^answers() {/,/^eval "\$(python3 tools\/settings.py env)"/p' install.sh > "$mt/probe.sh" - probe() { (env PATH="$mt/bin:$PATH" XDG_CONFIG_HOME="$mt/$1" "${@:2}" bash -c '. "$1"; vh_get() { bin/vh settings mirror --get; }; echo "now $(vh_get) ${npm_config_registry:-official}"' _ "$mt/probe.sh" 2>&1 | tail -1); } - c=$(MIRROR="" probe p1 env -u npm_config_registry); d=$(probe p2 env -u npm_config_registry OFFICIAL=1); e=$(probe p3 env -u npm_config_registry MIRROR=off); f=$(probe p3 env -u npm_config_registry MIRROR=) - if case "$a" in "auto"*"cn a test https://registry.npmmirror.com https://hf-mirror.com https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple https://npmmirror.com/mirrors/electron/"*"https://mine.example"*"off None"*"exit 2") true ;; *) false ;; esac \ - && [ -z "$b" ] && [ -s "$mt/probe.sh" ] && [ "$c" = "now cn https://registry.npmmirror.com" ] && [ "$d" = "now auto official" ] && [ "$e" = "now off official" ] && [ "$f" = "now off official" ] \ - && grep -q '"mirror_why": "install.sh, ' "$mt/p1/ovh/settings.json" - then ok "mirrors: kept in this machine's settings; bin/vh exports tools/mirrors.txt's variables with cn (a variable the person set stays); install.sh keeps cn only when the official npm registry does not answer and the mirror does; off is kept and stops the trying" - else bad "mirrors: $a | $b | probe: $c / $d / $e / $f"; fi - # two writers at once (Studio's settings panel and a terminal) both land: settings.update holds a lock, re-reads, merges, - # keeps the keys it was not given - a=$(XDG_CONFIG_HOME="$mt/w" python3 - <<'PY' 2>&1 -import json, os, subprocess, sys -code = "import sys; sys.path.insert(0, 'tools'); import settings\nfor i in range(60): settings.update({f'{sys.argv[1]}{i}': i})\n" -ps = [subprocess.Popen([sys.executable, "-c", code, w]) for w in ("a", "b")] -for q in ps: q.wait() + # the download mirrors: this machine's settings (tools/settings.py) in a file of their own, read on every bin/vh run. With + # "mirror": "cn" bin/vh exports the variables of tools/mirrors.txt for what it runs; a source the person set stays theirs (the + # variable, npm's registry in an .npmrc, uv's index in a uv.toml); once it is not cn, the ones a bin/vh before exported + # (inherited, as Studio's agents have them) are taken out again, and a value of the person's own is left + mt=$(mktemp -d "${TMPDIR:-/tmp}/vh-mirror.XXXXXX"); mh="$mt/home"; mkdir -p "$mh" + mv_() { env -u npm_config_registry -u HF_ENDPOINT -u UV_DEFAULT_INDEX -u UV_INDEX_URL -u ELECTRON_MIRROR -u UV_PYTHON_INSTALL_MIRROR -u OVH_MIRROR -u NPM_CONFIG_USERCONFIG HOME="$mh" XDG_CONFIG_HOME="$mt/c" "$@"; } + envj() { python3 -c 'import json, sys; d = json.load(sys.stdin); e = d["environment"]; print(d["mirror"], " ".join(f"{k}={e[k]}" for k in sorted(e)), [k["kind"] for k in d.get("kept_own", [])])'; } + a=$(mv_ bin/vh settings mirror --get; mv_ bin/vh settings mirror cn --why "a test" >/dev/null; mv_ bin/vh settings --json | envj + mv_ npm_config_registry=https://mine.example bin/vh settings --json | envj + mv_ bin/vh settings mirror off >/dev/null + mv_ OVH_MIRROR=cn npm_config_registry=https://registry.npmmirror.com HF_ENDPOINT=https://hf-mirror.com UV_DEFAULT_INDEX=https://mine.example/simple bin/vh settings --json | envj + mv_ bin/vh settings mirror nope 2>/dev/null; echo "exit $?") + want="auto +cn ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ HF_ENDPOINT=https://hf-mirror.com UV_DEFAULT_INDEX=https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple UV_PYTHON_INSTALL_MIRROR=https://registry.npmmirror.com/-/binary/python-build-standalone npm_config_registry=https://registry.npmmirror.com [] +cn ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ HF_ENDPOINT=https://hf-mirror.com UV_DEFAULT_INDEX=https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple UV_PYTHON_INSTALL_MIRROR=https://registry.npmmirror.com/-/binary/python-build-standalone npm_config_registry=https://mine.example ['npm'] +off ELECTRON_MIRROR=None HF_ENDPOINT=None UV_DEFAULT_INDEX=https://mine.example/simple UV_PYTHON_INSTALL_MIRROR=None npm_config_registry=None [] +exit 2" + # a registry of the person's own in their .npmrc and a uv.toml: not exported over, and said + mv_ bin/vh settings mirror cn >/dev/null; printf 'registry=https://corp.example/npm/\n' > "$mh/.npmrc"; mkdir -p "$mt/c/uv"; printf 'index-url = "https://corp.example/pypi/simple"\n' > "$mt/c/uv/uv.toml" + b=$(mv_ bin/vh settings --json | envj; mv_ bin/vh settings | grep -c 'your own source stays'); rm -f "$mh/.npmrc" "$mt/c/uv/uv.toml" + wantb="cn ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ HF_ENDPOINT=https://hf-mirror.com UV_DEFAULT_INDEX=None UV_PYTHON_INSTALL_MIRROR=https://registry.npmmirror.com/-/binary/python-build-standalone npm_config_registry=None ['npm', 'pypi'] +2" + c=$(awk '!/^#/ && NF { if ($4 !~ /^https:\/\//) print "not https: " $1 }' tools/mirrors.txt) + # HyperFrames' Chrome: only through the mirror helper with cn, and not for an inherited OVH_MIRROR once the setting is off; a + # folder with no HyperFrames is one line and exit 1 (the installer goes on past it) + hp="$mt/hfp"; mkdir -p "$hp/node_modules/hyperframes/dist" "$hp/node_modules/.bin"; printf 'var CHROME_VERSION = "152.0.1.2";\n' > "$hp/node_modules/hyperframes/dist/a.js" + printf '#!/bin/sh\necho "$*" >> "%s/browsers.log"\n' "$mt" > "$hp/node_modules/.bin/browsers"; chmod +x "$hp/node_modules/.bin/browsers" + d=$(mv_ bin/vh settings chrome "$hp" 2>&1 >/dev/null; mv_ bin/vh settings mirror off >/dev/null; mv_ OVH_MIRROR=cn bin/vh settings chrome "$hp" + mkdir -p "$mt/empty"; mv_ bin/vh settings mirror cn >/dev/null; mv_ bin/vh settings chrome "$mt/empty" 2>&1; echo "exit $?"; mv_ bin/vh settings mirror auto >/dev/null) + chr=$(sed -n '/settings chrome || true/p' install.sh | sed 's/ *#.*$//'); mkdir -p "$mt/inst/bin"; printf '#!/bin/sh\necho "! no HyperFrames yet" >&2; exit 1\n' > "$mt/inst/bin/vh"; chmod +x "$mt/inst/bin/vh" + e=$(cd "$mt/inst" && OVH_MIRROR=cn bash -euo pipefail -c "$chr; echo went on" 2>&1) + if [ "$a" = "$want" ] && [ "$b" = "$wantb" ] && [ -z "$c" ] && [ "$(cat "$mt/browsers.log" 2>/dev/null)" = "install chrome-headless-shell@152.0.1.2 --path $mh/.cache/hyperframes/chrome --base-url https://cdn.npmmirror.com/binaries/chrome-for-testing" ] \ + && case "$d" in *"HyperFrames' Chrome 152.0.1.2 from the mirror"*"the mirrors are not on"*"no HyperFrames installed for $mt/empty yet"*"exit 1") true ;; *) false ;; esac \ + && [ "$(printf '%s\n' "$e" | tail -1)" = "went on" ] + then ok "mirrors: read on every run; cn exports tools/mirrors.txt's variables (one the person set stays, and npm's or uv's own registry is not exported over, and said); off takes out what an earlier bin/vh exported, not the person's own; HyperFrames' Chrome through the mirror only with cn, a folder with no HyperFrames one line and the installer goes on" + else bad "mirrors: $a | own: $b | $c | chrome: $(cat "$mt/browsers.log" 2>/dev/null) / $d | installer: $e"; fi + # install.sh's probe: npmjs through npm (its own proxy counts), Hugging Face and Google's storage through curl, twice each; + # cn when one fails twice and its mirror answers, the reason saying what happened; one failed try is not a failure; off is + # kept and stops the trying; a choice that cannot be kept still uses the mirrors for this run + mkdir -p "$mt/bin" + printf '#!/bin/sh\n[ -n "$NPM_DOWN" ] && { echo "npm error code ENOTFOUND" >&2; exit 1; }; exit 0\n' > "$mt/bin/npm" + printf '#!/bin/sh\nfor a; do u=$a; done\ncase "$u" in *huggingface.co*) [ -n "$HF_DOWN" ] && exit 28; if [ -n "$HF_FLAKY" ] && [ ! -e "$HF_FLAKY" ]; then : > "$HF_FLAKY"; exit 6; fi ;; *registry.npmjs.org*) [ -n "$CURL_NPM_DOWN" ] && exit 7 ;; esac\nexit 0\n' > "$mt/bin/curl" + chmod +x "$mt/bin/npm" "$mt/bin/curl" + sed -n '/^reach() {/,/^eval "\$(python3 tools\/settings.py env/p' install.sh > "$mt/probe.sh" + probe() { (env -u npm_config_registry -u HF_ENDPOINT -u OVH_MIRROR PATH="$mt/bin:$PATH" HOME="$mh" XDG_CONFIG_HOME="$mt/$1" "${@:2}" bash -euo pipefail -c 'MIRROR=${MIRROR:-}; . "$1"; echo "now $(bin/vh settings mirror --get) ${HF_ENDPOINT:-official}"' _ "$mt/probe.sh" 2>&1 | tail -1); } + f1=$(probe p1 HF_DOWN=1); f2=$(probe p2); f3=$(probe p3 MIRROR=off HF_DOWN=1); f4=$(probe p4 HF_FLAKY="$mt/flaky"); f5=$(probe p5 CURL_NPM_DOWN=1); f6=$(probe p6 NPM_DOWN=1) + mkdir -p "$mt/ro"; chmod 555 "$mt/ro"; f7=$(probe ro HF_DOWN=1); chmod 755 "$mt/ro" + why=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["mirror_why"])' "$mt/p1/ovh/settings.json" 2>&1) + why6=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["mirror_why"])' "$mt/p6/ovh/settings.json" 2>&1) + if [ -s "$mt/probe.sh" ] && [ "$f1" = "now cn https://hf-mirror.com" ] && [ "$f2" = "now auto official" ] && [ "$f3" = "now off official" ] \ + && [ "$f4" = "now auto official" ] && [ "$f5" = "now auto official" ] && [ "$f6" = "now cn https://hf-mirror.com" ] && [ "$f7" = "now auto https://hf-mirror.com" ] \ + && case "$why" in "install.sh, "*": huggingface.co: it did not answer in 5 s, twice, and hf-mirror.com answered") true ;; *) false ;; esac \ + && case "$why6" in *"registry.npmjs.org: its name did not resolve, twice, and registry.npmmirror.com answered") true ;; *) false ;; esac + then ok "install.sh's probe: npmjs through npm, Hugging Face and Google's storage twice each; cn when one fails and its mirror answers, with what happened; one failed try is not a failure; off is kept; a choice it cannot keep still uses the mirrors for this run" + else bad "install.sh's probe: $f1 / $f2 / $f3 / $f4 / $f5 / $f6 / $f7 | $why | $why6"; fi + # this machine's settings file: two writers both land (deterministically: the second writes while the first holds the lock + # between its read and its write); a key given as None goes, an unknown one stays; set_mirror writes what the command writes; + # a file that is not a JSON object is kept as settings.json.bad; one of a newer version is not written over; an XDG_CONFIG_HOME + # that is not absolute is ignored; a key nested in another is not the mirror; an unwritable folder is one line, no traceback + a=$(cd "$ROOT" && XDG_CONFIG_HOME="$mt/w" HOME="$mh" python3 - <<'PY' 2>&1 +import json, os, subprocess, sys, time sys.path.insert(0, "tools"); import settings -settings.update({"mirror": "cn"}); settings.update({"mirror": None, "studio_theme": "dark"}) -d = json.load(open(settings.path())) -print(sum(k[0] in "ab" and k[1:].isdigit() for k in d), d.get("mirror"), d.get("studio_theme"), d.get("version")) -# set_mirror writes what the command writes, and leaves a key it does not know where it was +first = ("import sys, time; sys.path.insert(0, 'tools'); import settings\n" + "with settings.locked():\n d = settings.load(); open(sys.argv[1], 'w').close(); time.sleep(1.0); d['a'] = 1; settings._write(d)\n") +flag = os.path.join(os.environ["XDG_CONFIG_HOME"], "held"); os.makedirs(os.environ["XDG_CONFIG_HOME"], exist_ok=True) +pa = subprocess.Popen([sys.executable, "-c", first, flag]) +while not os.path.exists(flag): time.sleep(0.01) +settings.update({"b": 1}); pa.wait() +d = json.load(open(settings.path())); out = [d.get("a"), d.get("b")] +settings.update({"mirror": "cn"}); settings.update({"mirror": None, "studio_theme": "dark"}); d = json.load(open(settings.path())) +out += [d.get("mirror"), d.get("studio_theme"), d.get("version")] mine = settings.set_mirror("cn", "a test"); subprocess.run([sys.executable, "tools/settings.py", "mirror", "off"], capture_output=True) cmd_off = {k: v for k, v in json.load(open(settings.path())).items() if k.startswith("mirror")} settings.set_mirror("off"); fn_off = {k: v for k, v in json.load(open(settings.path())).items() if k.startswith("mirror")} -subprocess.run([sys.executable, "tools/settings.py", "mirror", "cn", "--why", "a test"], capture_output=True) -cmd_cn = {k: v for k, v in json.load(open(settings.path())).items() if k.startswith("mirror")} -last = settings.set_mirror("auto") -print(mine.get("mirror"), mine.get("mirror_why"), cmd_off == fn_off, cmd_cn == {k: v for k, v in mine.items() if k.startswith("mirror")}, - "mirror" in last, last.get("studio_theme"), last.get("a0")) +out += [mine.get("mirror"), cmd_off == fn_off] +p = settings.path(); p.write_text('{"mirror": "cn", "studio_theme": "da'); r = subprocess.run([sys.executable, "tools/settings.py", "mirror", "auto"], capture_output=True, text=True) +out += [p.with_name("settings.json.bad").read_text().startswith('{"mirror": "cn"'), "kept as settings.json.bad" in r.stderr, settings.mirror()] +p.write_text('{"version": 2, "mirror": "off"}'); r = subprocess.run([sys.executable, "tools/settings.py", "mirror", "cn"], capture_output=True, text=True) +out += [r.returncode, json.loads(p.read_text())["version"], "newer" in r.stderr] +p.write_text('{"version": 1, "x": {"mirror": "cn"}}'); out += [subprocess.run(["bash", "bin/vh", "settings", "mirror", "--get"], capture_output=True, text=True).stdout.strip()] +clean = {k: v for k, v in os.environ.items() if k not in ("OVH_MIRROR", *(r["variable"] for r in settings.mirrors() if r["variable"]))} +out += [all(v is None for v in json.loads(subprocess.run(["bash", "bin/vh", "settings", "--json"], capture_output=True, text=True, env=clean).stdout)["environment"].values())] +out += [str(settings.path()).startswith(os.environ["XDG_CONFIG_HOME"]), + subprocess.run([sys.executable, "-c", "import sys; sys.path.insert(0, 'tools'); import settings; print(settings.path())"], + capture_output=True, text=True, env=dict(os.environ, XDG_CONFIG_HOME="rel")).stdout.strip() == os.path.join(os.environ["HOME"], ".config/ovh/settings.json")] +ro = os.path.join(os.environ["XDG_CONFIG_HOME"], "..", "ro2"); os.makedirs(ro); os.chmod(ro, 0o555) +r = subprocess.run([sys.executable, "tools/settings.py", "mirror", "cn"], capture_output=True, text=True, env=dict(os.environ, XDG_CONFIG_HOME=os.path.abspath(ro))) +os.chmod(ro, 0o755); out += [r.returncode, "Traceback" in r.stderr, "could not be kept" in r.stderr] +print(*out) PY ) - if [ "$a" = "120 None dark 1 -cn a test True True False dark 0" ]; then ok "settings: two writers at once both land (a lock, a fresh read, a merge); a key given as None goes, the others stay; set_mirror writes what bin/vh settings mirror writes, other keys untouched" - else bad "settings with two writers: $a"; fi + if [ "$a" = "1 1 None dark 1 cn True True True auto 1 2 True auto True True True 1 False True" ] + then ok "settings: two writers both land (the second waits for the first's lock); None takes a key out, an unknown one stays; set_mirror writes what the command writes; a broken file kept as .bad; a newer version not written over; one reader (a nested key is not the mirror); a relative XDG_CONFIG_HOME ignored; an unwritable folder one line" + else bad "settings: $a"; fi + # the help prints the whole header; a project made under cn records the mirror in its own lockfile, so no committed one may + x=$(bash install.sh -h); lk=$(git ls-files '*package-lock.json' | xargs grep -l 'npmmirror\|tuna.tsinghua\|hf-mirror' 2>/dev/null) + if case "$x" in *"--mirror cn|off"*"the first bin/vh tts with the default qwen provider"*"every bin/vh new short, promo, data or meme"*"Getting Started"*) true ;; *) false ;; esac && [ -z "$lk" ] + then ok "install.sh -h prints its whole header; no committed lockfile names a mirror" + else bad "install.sh -h or a lockfile with a mirror in it: $(printf '%s' "$x" | tail -2) | $lk"; fi rm -rf "$mt" # recipes sample: bad usage exits 2 before any render (an unknown id, a sequence, an unknown style); list --json names # the sheet a recipe carries (recipes check, above, holds every sketch to its sheet) diff --git a/tools/commands.json b/tools/commands.json index f83dcf7c..ca69832f 100644 --- a/tools/commands.json +++ b/tools/commands.json @@ -128,12 +128,12 @@ "writes": ["$XDG_CONFIG_HOME/ovh/settings.json (~/.config/ovh/settings.json)", "~/.cache/hyperframes/chrome (mirror cn: HyperFrames' Chrome from the mirror)"], "usage": [ { - "synopsis": "settings [--json] | settings mirror cn|off|auto [--why TEXT] | settings mirror --get | settings chrome", + "synopsis": "settings [--json] | settings mirror cn|off|auto [--why TEXT] | settings mirror --get | settings chrome [project]", "text": [ - "what this machine's settings are and where they are kept; mirror cn: every later download a command starts comes from the", + "what this machine's settings are and where they are kept; mirror cn: the downloads a command starts come from the", "mainland-China mirrors in tools/mirrors.txt (npm, uv, Hugging Face, Electron; HyperFrames' Chrome fetched from the mirror", - "now, as HyperFrames cannot be pointed at one; settings chrome does only that), off: never, auto: the official sources", - "(install.sh tries them first)" + "now, as HyperFrames cannot be pointed at one; settings chrome [project] does only that), a source of your own stays;", + "off: never, auto: the official sources (install.sh tries them first)" ] } ] diff --git a/tools/doctor.py b/tools/doctor.py index 64711724..3dcc1d78 100644 --- a/tools/doctor.py +++ b/tools/doctor.py @@ -628,7 +628,7 @@ def cache_homes(has_chrome=False): ("HyperFrames", env("HYPERFRAMES_FONT_CACHE_DIR") or str(home("~/.cache/hyperframes/fonts")), "the fonts a film asks for; its Chrome is already there", "HYPERFRAMES_FONT_CACHE_DIR=") if has_chrome else ("HyperFrames", str(home("~/.cache/hyperframes")), "its Chrome on a first snapshot or render, about 200 MB, and its fonts", - "no setting moves it: let the sandbox write it, or fetch the Chrome once outside the sandbox (npx hyperframes browser ensure) " + "no setting moves it: let the sandbox write it, or fetch the Chrome once outside the sandbox (" + ("bin/vh settings chrome" if os.environ.get("OVH_MIRROR") == "cn" else "npx hyperframes browser ensure") + ") " "and give the fonts HYPERFRAMES_FONT_CACHE_DIR="), ("bin/vh", os.path.join(xdg, "ovh"), "the font index of fonts and textcheck, HyperFrames' registry list", "XDG_CACHE_HOME="), ] @@ -994,7 +994,10 @@ def main(argv): print_module(m, r) print("- every bin/vh new short|promo|data|meme installs its own pinned HyperFrames into the project (about 140 MB of node_modules)") if first: - print(f" still to come on first use: {', '.join(first)} (wiki: Getting Started; mirrors behind a slow or blocked network: wiki China-Network / 国内网络)") + mirrored = os.environ.get("OVH_MIRROR") == "cn" + print(f" still to come on first use: {', '.join(first)} (wiki: Getting Started; " + + ("from the mainland-China mirrors, as this machine's settings say: bin/vh settings)" if mirrored else + "mirrors behind a slow or blocked network: bin/vh settings mirror cn, wiki China-Network / 国内网络)")) if not a["probe"]: print(" bin/vh doctor --probe: also call each service with a key once, at an endpoint that costs nothing") return 0 diff --git a/tools/mirrors.txt b/tools/mirrors.txt index 3c2a8785..32508f34 100644 --- a/tools/mirrors.txt +++ b/tools/mirrors.txt @@ -1,14 +1,25 @@ # Download mirrors for a network where the official sources do not answer (mainland China), in one place. -# install.sh tries the official npm registry first (5 s); only when it does not answer and the mirror does, this machine's -# settings get "mirror": "cn" ($XDG_CONFIG_HOME/ovh/settings.json, tools/settings.py), and from then on bin/vh exports the -# variables below with the mirror column, so every later download goes there: npm (project packages, Studio's app and its -# agent adapters), uv (Python packages, a Python build), Hugging Face (the local voice), Electron, and HyperFrames' Chrome, -# which bin/vh fetches from the mirror itself because HyperFrames has no setting for it. A variable you set yourself wins. +# install.sh tries the official npm registry (through npm), Hugging Face and Google's storage first (twice each, 5 s a try); +# only when one does not answer and its mirror does, this machine's settings get "mirror": "cn" ($XDG_CONFIG_HOME/ovh/ +# settings.json, tools/settings.py), and from then on bin/vh exports the variables below with the mirror column for +# everything it runs (the agents Studio starts too, so their own npm or uv goes there as well): npm (project packages, +# Studio's app and its agent adapters), uv (Python packages, a Python build), Hugging Face (the local voice), Electron, and +# HyperFrames' Chrome, which bin/vh fetches from the mirror itself because HyperFrames has no setting for it. A source you set +# yourself stays yours: the variable in your environment, npm's registry in an .npmrc, uv's index in a uv.toml. # install.sh --mirror cn uses them without trying, --mirror off never; bin/vh settings mirror cn|off|auto changes it later. -# The checks the tools already make stay as they are, and do not trust the mirror: npm ci checks each package against the -# lockfile's hash; Electron's download is checked against the checksums.json its npm package ships (itself under that -# hash). uv's packages, the Hugging Face model, a Python build and Chrome have no hash pinned here: they are taken as the -# mirror serves them over https, as they are taken from the official source. +# Not covered (they still go to the official place): the git clone itself and references/fetch.sh (GitHub), install.sh +# --obscura (GitHub releases), bin/vh hf add (HyperFrames' registry), bin/vh hdri (Poly Haven), and the Google Fonts that +# ClaudeAnimationBase's studio.html loads. +# What still checks a download, mirror or not, and what the mirror is trusted with: +# - checked: npm ci where a lockfile is (styles/_swatch, Studio's Electron shell, the agent adapters, ClaudeAnimationBase) +# checks each package against the lockfile's hash; Electron's zip is checked against the checksums.json its npm package +# ships (itself under that hash); uv checks a Python build against the sha256 built into uv (a substituted archive from a +# mirror folder is refused, tried 2026-11-22). +# - trusted to the mirror, wholly, as it is to npmjs.org today: what has no lockfile. bin/vh new's npm i -D hyperframes@ +# and gsap with what they bring, npx --yes hyperframes@ (bin/vh hf), the @puppeteer/browsers a folder without +# HyperFrames' node_modules runs (pinned to a version, not a hash): their packages and the hashes they are checked +# against both come from the mirror. So do uv's packages (uv run --with …, not pinned), the Hugging Face model, and +# HyperFrames' Chrome (no hash is pinned for it anywhere): over https, as from the official source. # # kind variable official (tried first) mirror (cn) who runs the mirror npm npm_config_registry https://registry.npmjs.org https://registry.npmmirror.com npmmirror.com, run by the cnpm project diff --git a/tools/readcheck.py b/tools/readcheck.py index 70d2a7c6..8af37198 100644 --- a/tools/readcheck.py +++ b/tools/readcheck.py @@ -525,8 +525,10 @@ def check_hint(a, out): def canvas_texts(html, out, browser, force=False): """Export the live registry; texts.mjs owns exclusive creation so two writers cannot silently replace each other.""" if not browser: # "": bin/vh looked and found none; None: run without bin/vh - raise ValueError("canvas-film needs a headless Chrome: " + ("npx hyperframes browser ensure (in a HyperFrames project), " - "install Chrome or Chromium, or set CHROME_PATH" if browser == "" else "run it as bin/vh readcheck, or pass --browser ")) + get = ("bin/vh settings chrome (from the mirror)" if os.environ.get("OVH_MIRROR") == "cn" + else "npx hyperframes browser ensure (in a HyperFrames project)") + raise ValueError("canvas-film needs a headless Chrome: " + (f"{get}, install Chrome or Chromium, or set CHROME_PATH" if browser == "" + else "run it as bin/vh readcheck, or pass --browser ")) cmd = ["node", str(Path(__file__).resolve().parent / "film" / "texts.mjs"), str(html), "--browser", browser, "--out", str(out)] + (["--force"] if force else []) proc = subprocess.Popen(cmd) diff --git a/tools/schemas/output/settings.schema.json b/tools/schemas/output/settings.schema.json index ad29f391..f1f25022 100644 --- a/tools/schemas/output/settings.schema.json +++ b/tools/schemas/output/settings.schema.json @@ -2,9 +2,9 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/ZLHad/OpenVideoHarness/tools/schemas/output/settings.schema.json", "title": "bin/vh settings --json", - "description": "This machine's own settings (tools/settings.py: $XDG_CONFIG_HOME/ovh/settings.json), the mirror in effect, the mirror table (tools/mirrors.txt) and the mirror variables as bin/vh exported them.", + "description": "This machine's own settings (tools/settings.py: $XDG_CONFIG_HOME/ovh/settings.json), the mirror in effect, the mirror table (tools/mirrors.txt), the mirror variables as bin/vh exported them, and the sources of the person's own that bin/vh leaves alone with cn.", "type": "object", - "required": ["version", "tool", "file", "settings", "mirror", "mirrors", "environment"], + "required": ["version", "tool", "file", "settings", "mirror", "mirrors", "environment", "kept_own"], "properties": { "version": {"enum": [1]}, "tool": {"type": "string"}, @@ -25,6 +25,10 @@ } } }, - "environment": {"type": "object"} + "environment": {"type": "object"}, + "kept_own": { + "type": "array", + "items": {"type": "object", "required": ["kind", "why"], "properties": {"kind": {"type": "string"}, "why": {"type": "string"}}} + } } } diff --git a/tools/settings.py b/tools/settings.py index 3fb2f6a0..51375c80 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -2,53 +2,78 @@ usage: bin/vh settings [--json] what they are now, and where they are kept bin/vh settings mirror cn|off|auto [--why TEXT] the download mirrors (tools/mirrors.txt): - cn every later download comes from the mainland-China mirrors (bin/vh exports their variables) + cn later downloads come from the mainland-China mirrors (bin/vh exports their variables for everything + it runs, the agents Studio starts included) off never: the official sources, and install.sh does not try the mirrors either - auto the official sources; install.sh tries the official npm registry once and switches to cn when it - does not answer and the mirror does (the default: no "mirror" key) + auto the official sources; install.sh tries the official npm registry, Hugging Face and Google's storage + (Chrome) and switches to cn when one does not answer twice and its mirror does (the default: no + "mirror" key) bin/vh settings mirror --get cn, off or auto, alone on a line - bin/vh settings chrome with the mirrors on, HyperFrames' Chrome from the mirror now when it + bin/vh settings chrome [project] with the mirrors on, HyperFrames' Chrome from the mirror now when it is not here (HyperFrames has no setting for where it downloads it; - bin/vh new and settings mirror cn do this by themselves) - python3 tools/settings.py env the lines bin/vh and install.sh run to use the mirrors - (export NAME=value; none when the mirror is not cn, or for a - variable already set) - -Kept in $XDG_CONFIG_HOME/ovh/settings.json (~/.config/ovh/settings.json): one file per machine, outside every clone, so a -git pull, a second clone or Studio's settings panel see the same values. Never a key or a token: those stay in the -environment (LOCAL.md names them, never their values). Shape, "version": 1 (keys only added, never renamed; a key -this file does not know is kept as it is when another is written): + bin/vh new, render, hf, frames and settings mirror cn do this by + themselves); project: that project's HyperFrames, else styles/_swatch's + python3 tools/settings.py env [--mode cn] the lines bin/vh and install.sh run (export NAME=value, unset NAME): + with cn, the mirror variables; otherwise none, and the ones bin/vh + exported before (inherited: OVH_MIRROR=cn) taken out again + +Kept in $XDG_CONFIG_HOME/ovh/settings.json (~/.config/ovh/settings.json; an XDG_CONFIG_HOME that is not an absolute path +is ignored, as the XDG spec says): one file per machine, outside every clone, so a git pull, a second clone or Studio's +settings panel see the same values. Never a key or a token: those stay in the environment (LOCAL.md names them, never their +values). Shape, "version": 1 (keys only added, never renamed; a key this file does not know is kept as it is when another +is written): {"version": 1, "mirror": "cn" | "off", absent: auto - "mirror_why": "…", who set it and why, in a sentence (install.sh's probe says what did not answer) + "mirror_why": "…", who set it and why, in a sentence (install.sh's probe says what did not answer, and how) "mirror_at": "YYYY-MM-DD"} -In-process (Studio): update(patch: dict) -> dict and set_mirror(mode, why=None) -> dict; load() reads, path() says where. +In-process (Studio): update(patch: dict) -> dict and set_mirror(mode, why=None) -> dict; load() reads, path() says where; +env_changes(environ) -> {NAME: value, or None to take it out}: what a long-lived process (Studio's server) applies to its own +environment after a change, so the agents it starts next follow it (bin/vh itself works it out again on every run). Every write goes through update(patch): under a lock (settings.json.lock), it reads the file as it is now, sets the keys it was given (None takes one out), keeps all the others, and writes the whole file to a temporary file moved into place, -so two writers at once (Studio and a terminal) both land and a reader never sees half a file. +so two writers at once (Studio and a terminal) both land and a reader never sees half a file. A file that is not a JSON +object (cut short, edited by hand) is kept beside it as settings.json.bad, said, and a fresh one written; a file of a newer +"version" is never written over (Newer). A folder it cannot write to raises OSError; the commands say so in one line. +A variable the person set stays theirs: one set in the environment (an empty one counts as not set), and npm's registry +set in an .npmrc (the person's, the project's, the global one) or uv's default index or Python mirror set in a uv.toml or +pyproject.toml, when it names a source other than the official one and the mirror: bin/vh then does not export that +one, and bin/vh settings says so. """ -import contextlib, datetime, fcntl, json, os, sys, tempfile +import contextlib, datetime, fcntl, json, os, re, shlex, shutil, sys, tempfile from pathlib import Path ROOT = Path(__file__).resolve().parent.parent MODES = ("cn", "off", "auto") +VERSION = 1 + + +class Newer(Exception): + """The file was written by a newer OpenVideoHarness ("version" above VERSION): not written over.""" def path(): - return Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config") / "ovh" / "settings.json" + x = os.environ.get("XDG_CONFIG_HOME") or "" + return Path(x if os.path.isabs(x) else Path.home() / ".config") / "ovh" / "settings.json" -def load(): - """The settings as kept, or {"version": 1} (none yet, or a file that is not a JSON object: said on stderr).""" +def _read(): + """→ (the settings as kept, or None when there is no file, or "bad" when it is not a JSON object, with why).""" p = path() try: d = json.loads(p.read_text(encoding="utf-8")) except FileNotFoundError: - return {"version": 1} + return None, None except (OSError, ValueError) as e: - print(f"bin/vh settings: {p} is not readable JSON ({e}); taken as empty", file=sys.stderr) - return {"version": 1} - return d if isinstance(d, dict) else {"version": 1} + return "bad", str(e) + return (d, None) if isinstance(d, dict) else ("bad", f"a JSON {type(d).__name__}, not an object") + + +def load(): + """The settings as kept, or {"version": 1} (none yet, or a file that is not a JSON object: said on stderr).""" + d, why = _read() + if d == "bad": + print(f"bin/vh settings: {path()} is not readable ({why}); taken as empty", file=sys.stderr) + return d if isinstance(d, dict) else {"version": VERSION} @contextlib.contextmanager @@ -69,7 +94,7 @@ def _write(d): fd, tmp = tempfile.mkstemp(prefix=".settings.", suffix=".tmp", dir=p.parent) try: with os.fdopen(fd, "w", encoding="utf-8") as f: - f.write(json.dumps(dict(d, version=1), ensure_ascii=False, indent=2) + "\n") + f.write(json.dumps(dict(d, version=VERSION), ensure_ascii=False, indent=2) + "\n") os.replace(tmp, p) finally: if os.path.exists(tmp): @@ -79,9 +104,20 @@ def _write(d): def update(patch): """The one way to write: under the lock, read the file as it is now, set each key of patch (None takes a key out), keep every other key (another writer's, or one this code does not know), and write the whole file to a temp file moved into - place. → the settings as written. Studio's settings panel and bin/vh settings both go through it.""" + place. → the settings as written. A file that is not a JSON object is kept as settings.json.bad first (said on stderr); + one of a newer version raises Newer and stays as it is. Studio's settings panel and bin/vh settings both go through it.""" with locked(): - d = load() + d, why = _read() + if d == "bad": + bad = path().with_name("settings.json.bad") + shutil.copyfile(path(), bad) + print(f"bin/vh settings: {path()} was not readable ({why}); kept as {bad.name} beside it, and a new one written", + file=sys.stderr) + d = {} + d = d or {} + if isinstance(d.get("version"), int) and d["version"] > VERSION: + raise Newer(f"{path()} was written by a newer OpenVideoHarness (version {d['version']}): it is left as it is; " + "update this clone (git pull) to change it") for k, v in patch.items(): if k == "version": continue @@ -90,14 +126,14 @@ def update(patch): else: d[k] = v _write(d) - return d + return dict(d, version=VERSION) def set_mirror(mode, why=None): """The mirror setting, as bin/vh settings mirror [--why TEXT] writes it, through update(), saying nothing (Studio's - settings panel calls it in-process; main() calls it and does the saying). mode: cn, off or auto (auto takes the keys - out). → the settings as written. It does not fetch HyperFrames' Chrome from the mirror: bin/vh settings mirror cn and - bin/vh new do that (bin/vh settings chrome alone).""" + settings panel calls it in-process, then applies env_changes() to its own environment; main() calls it and does the + saying). mode: cn, off or auto (auto takes the keys out). → the settings as written. It does not fetch HyperFrames' + Chrome from the mirror: bin/vh settings mirror cn and bin/vh new do that (bin/vh settings chrome alone).""" if mode not in MODES: raise ValueError(f"mirror: {mode!r} is not one of {', '.join(MODES)}") on = mode != "auto" @@ -126,16 +162,130 @@ def mirrors(): return rows -def env_lines(environ=os.environ): - """export lines for the mirror variables, when the mirror is cn; a variable already set (by the person) is left.""" - if mirror() != "cn": - return [] - out = [f"export {r['variable']}={r['mirror']}" for r in mirrors() if r["variable"] and not environ.get(r["variable"])] - return out + ["export OVH_MIRROR=cn"] +def _same(a, b): + return a.rstrip("/").lower() == b.rstrip("/").lower() + + +def _upward(cwd, names): + """The files of these names in cwd and every folder above it, nearest first.""" + d, out = Path(cwd).resolve(), [] + while True: + out += [d / n for n in names if (d / n).is_file()] + if d.parent == d: + return out + d = d.parent + + +def _ini(p, key): # the value of key=… in an .npmrc (the last one counts, as npm reads it) + v = None + try: + for line in p.read_text(encoding="utf-8", errors="replace").splitlines(): + m = re.match(r"\s*" + re.escape(key) + r"\s*=\s*(\S+)", line) + if m: + v = m.group(1).strip("'\"") + except OSError: + pass + return v + + +def _toml_url(p, keys): # a uv setting in a uv.toml or pyproject.toml ([tool.uv]): index-url, default-index, a default [[index]] + try: + text = p.read_text(encoding="utf-8", errors="replace") + except OSError: + return None + if p.name == "pyproject.toml" and "[tool.uv" not in text: + return None + for k in keys: + m = re.search(r'(?m)^\s*' + re.escape(k) + r'\s*=\s*["\']([^"\']+)["\']', text) + if m: + return m.group(1) + if "default-index" in keys: + for block in re.split(r"(?m)^\s*\[\[(?:tool\.uv\.)?index\]\]\s*$", text)[1:]: + block = re.split(r"(?m)^\s*\[", block)[0] + if re.search(r"(?m)^\s*default\s*=\s*true", block): + m = re.search(r'(?m)^\s*url\s*=\s*["\']([^"\']+)["\']', block) + if m: + return m.group(1) + return None + + +def own_config(row, environ=os.environ, cwd=None): + """Where the person's own tool configuration names a source of its own for this kind of download (not the official + one, not the mirror): → "a sentence: the value, from which file", or None.""" + cwd = cwd or os.getcwd(); home = Path(environ.get("HOME") or Path.home()) + def other(v): + return v and not _same(v, row["official"]) and not _same(v, row["mirror"]) + if row["kind"] in ("npm", "electron"): + key = "registry" if row["kind"] == "npm" else "electron_mirror" + node = shutil.which("node", path=environ.get("PATH")) + files = _upward(cwd, [".npmrc"]) + [Path(environ.get("NPM_CONFIG_USERCONFIG") or home / ".npmrc")] + files += [Path(environ["NPM_CONFIG_GLOBALCONFIG"])] if environ.get("NPM_CONFIG_GLOBALCONFIG") else \ + ([Path(node).resolve().parent.parent / "etc" / "npmrc"] if node else []) + for f in files: + v = _ini(f, key) if f.is_file() else None + if v is not None: # the nearest one npm reads wins + return f"{v} (npm's {key}, from {f})" if other(v) else None + if row["kind"] in ("pypi", "python"): + keys = ("index-url", "default-index") if row["kind"] == "pypi" else ("python-install-mirror",) + xdg = environ.get("XDG_CONFIG_HOME") or "" + user = Path(xdg if os.path.isabs(xdg) else home / ".config") / "uv" / "uv.toml" + for f in _upward(cwd, ["uv.toml", "pyproject.toml"]) + [user, Path("/etc/uv/uv.toml")]: + v = _toml_url(f, keys) if f.is_file() else None + if v: + return f"{v} (uv's {keys[0]}, from {f})" if other(v) else None + if row["kind"] == "pypi" and environ.get("UV_INDEX_URL"): # uv's older name for the same setting + return f"{environ['UV_INDEX_URL']} (UV_INDEX_URL)" + return None + + +def env_changes(environ=os.environ, mode=None, cwd=None): + """What bin/vh (and install.sh, and Studio's server) does to its environment for the mirror setting: {NAME: value to + export, or None to take out}. With cn: each mirror variable not set by the person (unset or empty, or already the + mirror's value) and not named by their own npm or uv configuration, and OVH_MIRROR=cn. Otherwise, only when the + environment came from a bin/vh run under cn (OVH_MIRROR=cn inherited): OVH_MIRROR, and each mirror variable that + still holds exactly the mirror's value, taken out; nothing else is touched.""" + mode = mode or mirror() + out = {} + if mode == "cn": + for r in mirrors(): + v = r["variable"] + if v and (not environ.get(v) or environ.get(v) == r["mirror"]) and not own_config(r, environ, cwd): + if environ.get(v) != r["mirror"]: + out[v] = r["mirror"] + if environ.get("OVH_MIRROR") != "cn": + out["OVH_MIRROR"] = "cn" + return out + if environ.get("OVH_MIRROR"): + out["OVH_MIRROR"] = None + for r in mirrors(): + if r["variable"] and environ.get(r["variable"]) == r["mirror"]: + out[r["variable"]] = None + return out + + +def env_lines(environ=os.environ, mode=None): + """env_changes() as shell lines: export NAME=value, unset NAME.""" + return [f"export {k}={shlex.quote(v)}" if v is not None else f"unset {k}" for k, v in env_changes(environ, mode).items()] + + +def kept_own(environ=os.environ): + """With cn, the mirror variables bin/vh leaves alone because the person set them: [(kind, why)].""" + out = [] + for r in mirrors(): + if not r["variable"]: + continue + mine = environ.get(r["variable"]) + if mine and mine != r["mirror"]: + out.append((r["kind"], f"{mine} ({r['variable']}, set in the environment)")) + else: + o = own_config(r, environ) + if o: + out.append((r["kind"], o)) + return out def in_effect(environ=os.environ): - """The mirror variables as this process has them (bin/vh exports them before it runs a tool): {name: value or None}.""" + """The mirror variables as this process has them (bin/vh works them out before it runs a tool): {name: value or None}.""" return {r["variable"]: environ.get(r["variable"]) for r in mirrors() if r["variable"]} @@ -147,24 +297,31 @@ def operators(): def show(d, as_json=False): m = mirror(d) + own = kept_own() if m == "cn" else [] if as_json: print(json.dumps({"version": 1, "tool": "bin/vh settings", "file": str(path()), "settings": d, "mirror": m, - "mirrors": mirrors(), "environment": in_effect()}, ensure_ascii=False, indent=1)) + "mirrors": mirrors(), "environment": in_effect(), "kept_own": [{"kind": k, "why": w} for k, w in own]}, + ensure_ascii=False, indent=1)) return print(f"this machine's settings: {path()}" + ("" if path().exists() else " (not written yet: the defaults)")) - said = {"cn": "the mainland-China mirrors, for every download (tools/mirrors.txt)", + said = {"cn": "the mainland-China mirrors, for the downloads tools/mirrors.txt lists", "off": "the official sources; install.sh does not try the mirrors", - "auto": "the official sources; install.sh switches to the mirrors when the official npm registry does not answer"}[m] + "auto": "the official sources; install.sh switches to the mirrors when an official source does not answer and its mirror does"}[m] print(f" mirror {m}: {said}" + (f" · {d['mirror_why']}" if d.get("mirror_why") else "") + (f" ({d['mirror_at']})" if d.get("mirror_at") else "")) + for k, w in own: + print(f" {k}: your own source stays, {w}") print(" bin/vh settings mirror cn|off|auto changes it") def main(argv): if argv[:1] in (["-h"], ["--help"]): print(__doc__.strip()); return 0 - if argv == ["env"]: - print("\n".join(env_lines())); return 0 + if argv[:1] == ["env"]: + mode = argv[2] if argv[1:2] == ["--mode"] and len(argv) == 3 and argv[2] in MODES else None + if len(argv) > 1 and mode is None: + print("usage: python3 tools/settings.py env [--mode cn|off|auto]", file=sys.stderr); return 2 + print("\n".join(env_lines(mode=mode))); return 0 if not argv or argv == ["--json"]: show(load(), bool(argv)); return 0 if argv[0] == "mirror": @@ -172,10 +329,17 @@ def main(argv): print(mirror()); return 0 if len(argv) < 2 or argv[1] not in MODES or (len(argv) > 2 and (argv[2] != "--why" or len(argv) != 4)): print("usage: bin/vh settings mirror cn|off|auto [--why TEXT] (or --get)", file=sys.stderr); return 2 - set_mirror(argv[1], argv[3] if len(argv) == 4 else None) + try: + set_mirror(argv[1], argv[3] if len(argv) == 4 else None) + except Newer as e: + print(f"✗ {e}", file=sys.stderr); return 1 + except OSError as e: + print(f"✗ the choice could not be kept in {path()} ({e.strerror or e}): nothing changed", file=sys.stderr); return 1 if argv[1] == "cn": print(f"✓ downloads now come from the mainland-China mirrors ({operators()}; tools/mirrors.txt), kept in {path()};" " bin/vh settings mirror off turns that off") + for k, w in kept_own(): + print(f" {k}: your own source stays, {w}") else: print(f"✓ downloads come from the official sources{'' if argv[1] == 'auto' else ', and install.sh does not try the mirrors'} (kept in {path()})") return 0 diff --git a/tools/status.py b/tools/status.py index 18aadc45..93288462 100644 --- a/tools/status.py +++ b/tools/status.py @@ -534,6 +534,10 @@ def hf_pin(project): return None +def chrome_fetch(project): # how to fetch HyperFrames' Chrome beforehand: from the mirror when it is on (bin/vh exports OVH_MIRROR) + return f"bin/vh settings chrome {shown(project)}" if os.environ.get("OVH_MIRROR") == "cn" else f"(cd {shown(project)} && npx hyperframes browser ensure)" + + def hf_chrome_note(project, proj): """HyperFrames' first snapshot or render downloads its own Chrome (chrome-headless-shell, about 200 MB, into ~/.cache/hyperframes, which it finds from the home folder) and shows nothing while it does: the words that say so, or "" once @@ -559,7 +563,7 @@ def wanted(folder): # bin/vh's shell_folder: the pinned version (any when ther except OSError: pass return (f" (HyperFrames' first snapshot or render downloads its Chrome first, about 200 MB into ~/.cache/hyperframes, with nothing" - f" shown; (cd {shown(project)} && npx hyperframes browser ensure) fetches it beforehand and shows the download)") + f" shown; {chrome_fetch(project)} fetches it beforehand and shows the download)") def engine_docs(project, proj): From f5cbf1823b08063b86c7c898ad8109432df2a98b Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 05:53:25 +0800 Subject: [PATCH 12/14] settings.py says the installer, not its file name: bin/vh runs it on every start, so a file it names reaches every CI group --- tools/settings.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/settings.py b/tools/settings.py index 51375c80..c0dfd70c 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -4,8 +4,8 @@ bin/vh settings mirror cn|off|auto [--why TEXT] the download mirrors (tools/mirrors.txt): cn later downloads come from the mainland-China mirrors (bin/vh exports their variables for everything it runs, the agents Studio starts included) - off never: the official sources, and install.sh does not try the mirrors either - auto the official sources; install.sh tries the official npm registry, Hugging Face and Google's storage + off never: the official sources, and the installer does not try the mirrors either + auto the official sources; the installer tries the official npm registry, Hugging Face and Google's storage (Chrome) and switches to cn when one does not answer twice and its mirror does (the default: no "mirror" key) bin/vh settings mirror --get cn, off or auto, alone on a line @@ -13,7 +13,7 @@ is not here (HyperFrames has no setting for where it downloads it; bin/vh new, render, hf, frames and settings mirror cn do this by themselves); project: that project's HyperFrames, else styles/_swatch's - python3 tools/settings.py env [--mode cn] the lines bin/vh and install.sh run (export NAME=value, unset NAME): + python3 tools/settings.py env [--mode cn] the lines bin/vh and the installer run (export NAME=value, unset NAME): with cn, the mirror variables; otherwise none, and the ones bin/vh exported before (inherited: OVH_MIRROR=cn) taken out again @@ -24,7 +24,7 @@ is written): {"version": 1, "mirror": "cn" | "off", absent: auto - "mirror_why": "…", who set it and why, in a sentence (install.sh's probe says what did not answer, and how) + "mirror_why": "…", who set it and why, in a sentence (the installer's probe says what did not answer, and how) "mirror_at": "YYYY-MM-DD"} In-process (Studio): update(patch: dict) -> dict and set_mirror(mode, why=None) -> dict; load() reads, path() says where; env_changes(environ) -> {NAME: value, or None to take it out}: what a long-lived process (Studio's server) applies to its own @@ -239,7 +239,7 @@ def other(v): def env_changes(environ=os.environ, mode=None, cwd=None): - """What bin/vh (and install.sh, and Studio's server) does to its environment for the mirror setting: {NAME: value to + """What bin/vh (and the installer, and Studio's server) does to its environment for the mirror setting: {NAME: value to export, or None to take out}. With cn: each mirror variable not set by the person (unset or empty, or already the mirror's value) and not named by their own npm or uv configuration, and OVH_MIRROR=cn. Otherwise, only when the environment came from a bin/vh run under cn (OVH_MIRROR=cn inherited): OVH_MIRROR, and each mirror variable that @@ -305,8 +305,8 @@ def show(d, as_json=False): return print(f"this machine's settings: {path()}" + ("" if path().exists() else " (not written yet: the defaults)")) said = {"cn": "the mainland-China mirrors, for the downloads tools/mirrors.txt lists", - "off": "the official sources; install.sh does not try the mirrors", - "auto": "the official sources; install.sh switches to the mirrors when an official source does not answer and its mirror does"}[m] + "off": "the official sources; the installer does not try the mirrors", + "auto": "the official sources; the installer switches to the mirrors when an official source does not answer and its mirror does"}[m] print(f" mirror {m}: {said}" + (f" · {d['mirror_why']}" if d.get("mirror_why") else "") + (f" ({d['mirror_at']})" if d.get("mirror_at") else "")) for k, w in own: @@ -341,7 +341,7 @@ def main(argv): for k, w in kept_own(): print(f" {k}: your own source stays, {w}") else: - print(f"✓ downloads come from the official sources{'' if argv[1] == 'auto' else ', and install.sh does not try the mirrors'} (kept in {path()})") + print(f"✓ downloads come from the official sources{'' if argv[1] == 'auto' else ', and the installer does not try the mirrors'} (kept in {path()})") return 0 print(f"bin/vh settings: unknown {' '.join(argv)} (bin/vh settings -h)", file=sys.stderr) return 2 From ceb6616e5bac074354b27c1b5c060b6d1c75cb02 Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 03:52:50 +0800 Subject: [PATCH 13/14] Homepage: a sentence to make one like this on each film and style; Get started lists the four ways in - Showcase: a film card the pointer is over (the keyboard is in; always on a touch screen) offers a sentence that asks for a quick film made the way that one was, on a new subject; copied, the page says what it copied. - Styles: a style's lightbox has a copyable sentence for a 20-second quick short in that style, pictures and on-screen text without narration, vertical where the style comes vertical (STYLE_VERTICAL, held to tokens.json by readme.py). - Get started, step 2: Studio, the terminal, the agents' desktop apps, any folder (the skill or the plugin). --- changes/site-sample-wall.md | 5 +++ docs/site/index.html | 86 +++++++++++++++++++++++++++++-------- tools/readme.py | 8 ++++ 3 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 changes/site-sample-wall.md diff --git a/changes/site-sample-wall.md b/changes/site-sample-wall.md new file mode 100644 index 00000000..7ee110fe --- /dev/null +++ b/changes/site-sample-wall.md @@ -0,0 +1,5 @@ +**官网:每支样片、每种风格都带一句"照这个做一支";快速开始列出四个入口** +- Why: 新来的人第一步卡在"该说什么"。官网上的样片和风格只能看,不能直接拿来开片。 +- 作品区:鼠标移到一支片子上,出现"照这个做一支 · 复制这句话",复制的是一句照这支的做法、换一个新题目的快出需求,页面底部说一声复制了什么;触屏上一直显示。 +- 风格墙:点开一种风格,样片下面是一句可复制的话:用这种风格快出一版 20 秒的短片,只用画面和文字、不配旁白(避开第一次的配音下载),横屏或竖屏按这种风格支持的画幅;`bin/vh new … --style` 那行命令留在下面。`tools/readme.py check` 核对哪些风格算竖屏。 +- 快速开始第二步改成四个入口:Studio、终端、Claude Code 或 Codex 的桌面 App、别的文件夹(装好的 skill,或在 agent 里一条命令装插件)。 diff --git a/docs/site/index.html b/docs/site/index.html index 02696c6e..438bd77e 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -438,6 +438,16 @@ .film figcaption b { display: block; font-size: clamp(15px, 1.15vw, 18px); font-weight: 600; } .film figcaption q { display: block; font-family: var(--display); font-weight: 500; font-size: clamp(15px, 1.2vw, 19px); line-height: 1.25; color: var(--text-2); margin-top: 2px; letter-spacing: -.01em; } .film figcaption small { display: block; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 4px; } +.say-mini { pointer-events: auto; max-height: 0; opacity: 0; overflow: hidden; transition: max-height .25s, opacity .25s, margin .25s; } +.film:hover .say-mini, .film:focus-within .say-mini { max-height: 40px; opacity: 1; margin-top: 7px; } +@media (hover: none) { .say-mini { max-height: none; opacity: 1; margin-top: 7px; } } +.say-mini [data-copy-text] { display: none; } +.say-mini .copy.say-btn { position: static; transform: none; font-size: 12px; padding: 4px 10px; border-radius: 999px; color: var(--cyan); background: rgba(8,10,20,.6); } +.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px); max-width: min(720px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px; background: rgba(12,14,26,.95); border: 1px solid var(--line); color: var(--text); font-size: 14px; line-height: 1.45; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 60; } +.toast.show { opacity: 1; transform: translate(-50%, 0); } +.films.sees .say-mini { display: none; } +.lb-say { flex-basis: 100%; margin-top: 2px; font-size: clamp(15px, 1.15vw, 18px); } +.lb-cap code.lb-code { display: block; margin-top: 8px; font-size: 12.5px; color: var(--muted); } .film .pbtn { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border-radius: 50%; z-index: 1; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.35); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); @@ -521,6 +531,12 @@ .cmd code { font: inherit; } .cmd.say { white-space: normal; font-family: var(--display); font-weight: 500; font-size: clamp(17px, 1.35vw, 22px); line-height: 1.35; letter-spacing: -.01em; background: var(--glass); } .start-cli { margin-top: 8px; } +.ways { list-style: none; display: grid; gap: 6px; margin: 0 0 10px; font-size: 14.5px; line-height: 1.45; color: var(--text-2); } +.steps .ways li { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 10px; } +.steps .ways li::before { content: none; } +.ways b { color: var(--text); font-weight: 600; } +.ways code { font-family: var(--mono); font-size: .92em; color: var(--cyan); } +@media (max-width: 640px) { .steps .ways li { grid-template-columns: minmax(0, 1fr); gap: 0; } } .start-cli summary { color: var(--cyan); cursor: pointer; font-size: 14px; } .start-cli .cmd { margin-top: 6px; } .steps h3 + .fine, .steps .fine + .cmd { margin-bottom: 6px; } @@ -853,13 +869,20 @@

Compare the revision同一段改完
  1. Install on macOS or Linux在 macOS 或 Linux 安装

    curl -fsSL https://raw.githubusercontent.com/ZLHad/OpenVideoHarness/main/install.sh | bash
  2. -
  3. Open OVH Studio打开 OVH Studio

    -

    Open the app, choose your signed-in Claude Code or Codex in the agent column, and click Set it up if prompted. You can also launch Studio from the default install folder.打开应用,在右栏选择已登录的 Claude Code 或 Codex。看到适配器提示时点装上。也可以从默认安装目录启动 Studio。

    -
    cd ~/OpenVideoHarness && bin/vh studio
    +
  4. Pick a way in选一个入口

    +
      +
    • StudioStudioOpen OVH Studio from your applications, choose your signed-in Claude Code or Codex in the agent column, and click Set it up if prompted.从应用程序打开 OVH Studio,在右栏选已登录的 Claude Code 或 Codex,看到适配器提示时点装上。
    • +
    • Terminal终端Open Claude Code or Codex in the install folder.在安装目录里打开 Claude Code 或 Codex。
    • +
    • Desktop app桌面 AppIn the Claude Code or Codex app, open the install folder (~/OpenVideoHarness) as the project.在 Claude Code 或 Codex 的桌面 App 里,把安装目录(~/OpenVideoHarness)当作项目打开。
    • +
    • Any folder别的文件夹The installer registers a skill for both agents, so “make a video …” finds the workbench from any project. Only the skill, from inside the agent: the commands below.安装时给两个 agent 都注册了 skill,在任何项目里说“做一支视频……”都能找到工作台。只装 skill、在 agent 里一条命令:见下面。
    • +
    +
    cd ~/OpenVideoHarness && claude
    - Use the terminal用终端开片 + More commands: Studio, Codex, only the skill更多命令:Studio、Codex、只装 skill +
    cd ~/OpenVideoHarness && bin/vh studio
    cd ~/OpenVideoHarness && codex
    -
    cd ~/OpenVideoHarness && claude
    +
    /plugin install open-video-harness --marketplace ZLHad/OpenVideoHarness
    +
    codex plugin marketplace add ZLHad/OpenVideoHarness && codex plugin add open-video-harness@open-video-harness
  5. Send a first request发送第一条需求

    @@ -1104,7 +1127,7 @@

    04Check & deliver查与交 Contact sheet of the science short contact sheet联系表 -
    Vertical science short竖屏科普Why does a low-orbit satellite's signal change pitch?为什么低轨卫星的信号会"变调"?HyperFrames · 24.8 s · 1080×1920 · Chinese voice, two-language subtitlesHyperFrames · 24.8 秒 · 1080×1920 · 中文配音,双语字幕
    +
    Vertical science short竖屏科普Why does a low-orbit satellite's signal change pitch?为什么低轨卫星的信号会"变调"?HyperFrames · 24.8 s · 1080×1920 · Chinese voice, two-language subtitlesHyperFrames · 24.8 秒 · 1080×1920 · 中文配音,双语字幕
    Quick draft, the way showcase/02 was made: a 25-second vertical science short on why the sky is blue.照 showcase/02 的做法,快速出一版 25 秒的竖屏科普,讲为什么天空是蓝的。
    Every film ships with its paper trail每支片子都附带完整的制作记录 @@ -1364,6 +1387,14 @@

    Star it on GitHub在 GitHub 上点 St ['walk-in-world', 'Walk-in World', '走进去的世界'], ['watercolor-pastoral', 'Watercolor Pastoral', '水彩田园'], ['whiteboard', 'Whiteboard Sketch', '白板速写'], ['y2k-chrome', 'Y2K Chrome', 'Y2K 铬面'], ]; +// the styles that also come vertical (tokens.json tags.aspect "both"): their "make one like this" sentence asks for a vertical +// short, the others' for a landscape one (tools/readme.py check holds this list to the styles) +const STYLE_VERTICAL = new Set(["bouncy-flat-2d", "brutalist-meme", "chalkboard", "deep-space-explainer", "editorial-data", "era-media-relay", "gold-line-dark", "guochao-festive", "halftone-comic", "isotype", "map-explainer", "paper-desk-dossier", "pastel-ui", "product-keynote", "risograph", "swiss-grid-type", "visual-investigation", "whiteboard", "y2k-chrome"]); +const styleSay = (slug, en, zh) => STYLE_VERTICAL.has(slug) + ? { en: `Quick draft: a 20-second vertical short in the ${en} style (styles/${slug}), pictures and on-screen text, no narration, about why the sky is blue.`, + zh: `快速出一版 20 秒的竖屏短片,用「${zh}」风格(styles/${slug}),只用画面和文字、不配旁白,讲为什么天空是蓝的。` } + : { en: `Quick draft: a 20-second landscape short in the ${en} style (styles/${slug}), pictures and on-screen text, no narration, about why the sky is blue.`, + zh: `快速出一版 20 秒的横屏短片,用「${zh}」风格(styles/${slug}),只用画面和文字、不配旁白,讲为什么天空是蓝的。` }; const stylePath = (slug, f) => `../../styles/${slug}/media/${f}`; // the 5 s sample (swatch.mp4) of a spec-1 style // A spec-2 style (tokens.json "swatch": {"spec": 2}) keeps only its 2 s preview.mp4 in git; its full sample is a release // asset (tools/media.txt, release styles-media), named here. Its tile plays the preview; the lightbox plays the release @@ -1763,7 +1794,7 @@

    Star it on GitHub在 GitHub 上点 St const t = { b, v, slug, en, zh }; v.addEventListener('ended', () => b.classList.remove('on')); b.addEventListener('mouseenter', () => playTile(t)); - b.addEventListener('click', () => { stopWall(); openLightbox({ video: fullClip(slug), cap: lang === 'zh' ? zh : en, code: `bin/vh new promo my-film --style ${slug}` }); }); + b.addEventListener('click', () => { stopWall(); openLightbox({ video: fullClip(slug), cap: lang === 'zh' ? zh : en, say: styleSay(slug, en, zh), code: `bin/vh new promo my-film --style ${slug}` }); }); return t; }); const yours = document.createElement('div'); yours.className = 'sw info'; @@ -1812,7 +1843,7 @@

    Star it on GitHub在 GitHub 上点 St /* ---------- lightbox ---------- */ const lb = $('#lightbox'), lbMedia = $('#lbMedia'), lbCap = $('#lbCap'); -function openLightbox({ video, img, cap, code }) { +function openLightbox({ video, img, cap, code, say }) { pauseAll(); lbMedia.innerHTML = ''; if (video) { // a path, or { src, type, loop }: a release file goes through (WebKit refuses it as a bare src) @@ -1825,7 +1856,13 @@

    Star it on GitHub在 GitHub 上点 St if (img) { const i = new Image(); i.src = img; i.alt = cap; lbMedia.appendChild(i); } lbCap.innerHTML = ''; const c = document.createElement('span'); c.textContent = cap; lbCap.appendChild(c); - if (code) { const k = document.createElement('code'); k.textContent = code; lbCap.appendChild(k); } + if (say) { // a sentence to paste into Studio or an agent: "make one like this" + const d = document.createElement('div'); d.className = 'cmd say lb-say'; + for (const l of ['en', 'zh']) { const t = document.createElement('span'); t.lang = l; t.dataset.copyText = ''; t.textContent = say[l]; d.appendChild(t); } + const b = document.createElement('button'); b.type = 'button'; b.className = 'copy'; b.textContent = tr().copy; bindCopy(b); d.appendChild(b); + lbCap.appendChild(d); + } + if (code) { const k = document.createElement('code'); k.textContent = code; if (say) k.className = 'lb-code'; lbCap.appendChild(k); } lb.classList.add('show'); } function closeLightbox() { lb.classList.remove('show'); lbMedia.innerHTML = ''; if (sections[current].id === 'styles') startWall(); } @@ -1834,17 +1871,30 @@

    Star it on GitHub在 GitHub 上点 St document.addEventListener('keydown', e => { if (e.key === 'Escape' && lb.classList.contains('show')) closeLightbox(); }); /* ---------- copy buttons ---------- */ -$$('.copy').forEach(b => b.addEventListener('click', async () => { +function bindCopy(b) { b.addEventListener('click', async e => { + e.stopPropagation(); // a film card plays on a click: the copy button inside it must not const value = $(`[data-copy-text]:not([lang]), [data-copy-text][lang="${lang}"]`, b.parentElement); - try { await navigator.clipboard.writeText(value.textContent); b.textContent = tr().copied; } - catch { + const label = b.innerHTML; // a button with its own words (a film card's) gets them back, the others their "Copy" + try { + await navigator.clipboard.writeText(value.textContent); + if (b.hasAttribute('data-toast')) toast(`${tr().copied}: ${value.textContent}`); else b.textContent = tr().copied; + } + catch { // no clipboard (a page over http, a refusal): the sentence is shown to copy by hand + if (b.hasAttribute('data-toast')) { toast(value.textContent); return; } const selection = window.getSelection(), range = document.createRange(); range.selectNodeContents(value); selection.removeAllRanges(); selection.addRange(range); b.textContent = tr().select; } - setTimeout(() => { b.textContent = tr().copy; }, 1600); -})); + setTimeout(() => { if (b.hasAttribute('data-toast')) b.innerHTML = label; else b.textContent = tr().copy; }, 1600); +}); } +let toastTimer = null; +function toast(text) { + let t = $('#toast'); + if (!t) { t = document.createElement('div'); t.id = 'toast'; t.className = 'toast'; t.setAttribute('role', 'status'); document.body.appendChild(t); } + t.textContent = text; t.classList.add('show'); clearTimeout(toastTimer); toastTimer = setTimeout(() => t.classList.remove('show'), 3200); +} +$$('.copy').forEach(bindCopy); /* ---------- buttons lean toward the cursor ---------- */ if (fine && !reduced) $$('.btn, .gh').forEach(b => { @@ -1860,7 +1910,7 @@

    Star it on GitHub在 GitHub 上点 St document.title = tr().title; railLabels(); $$('[data-aria-en]').forEach(el => el.setAttribute('aria-label', el.dataset[l === 'zh' ? 'ariaZh' : 'ariaEn'])); - $$('.copy').forEach(b => { b.textContent = tr().copy; }); + $$('.copy:not([data-toast])').forEach(b => { b.textContent = tr().copy; }); // a card's button keeps its two-language words tiles.forEach(t => t.b.setAttribute('aria-label', tr().tile(l === 'zh' ? t.zh : t.en))); yours.innerHTML = tr().yours; ftSetPlaying(ft.playing); ftDraw(); ftShowCheck(); diff --git a/tools/readme.py b/tools/readme.py index aeff8db3..b279f476 100644 --- a/tools/readme.py +++ b/tools/readme.py @@ -368,6 +368,14 @@ def site_problems(have): for f in (base / "img" / "styles" / f"{slug}.jpg", ROOT / "styles" / slug / "media" / "swatch.mp4"): if not f.is_file() and str(f.relative_to(ROOT)) not in fetched: bad.append(f"{SITE}: the style {slug} has no {f.relative_to(ROOT)}") + # the "make one like this" sentence asks for a vertical short in the styles that come vertical too (tags.aspect "both") + vert = re.search(r"const STYLE_VERTICAL = new Set\((\[.*?\])\);", html, re.S) + want_v = sorted(q.parent.name for q in (ROOT / "styles").glob("*/tokens.json") + if (json.loads(q.read_text(encoding="utf-8")).get("tags") or {}).get("aspect") == "both") + if not vert: + bad.append(f"{SITE}: no STYLE_VERTICAL list (the styles whose tokens.json says aspect both)") + elif sorted(json.loads(vert.group(1))) != want_v: + bad.append(f"{SITE}: STYLE_VERTICAL is not the styles whose tokens.json says aspect both: {want_v}") # a spec-2 style's tile plays its preview.mp4 (in git) and its lightbox the release asset: RELEASE_SAMPLES names them rel = re.search(r"const RELEASE_SAMPLES = \{(.*?)\};", html, re.S) named = dict(re.findall(r"'([a-z0-9-]+)': '([^']+)'", rel.group(1))) if rel else {} From f04d1bbcbc298a45aa5b47d2f415eb4e72635dec Mon Sep 17 00:00:00 2001 From: zhanglinghao Date: Sun, 22 Nov 2026 06:03:57 +0800 Subject: [PATCH 14/14] Homepage, review of #232: each way in with its own commands, as the READMEs give them (no plugin lines until #230); the pill at the card's top-left; sentences by kind of film; the toast cleared by a lightbox readme.py check: every command the page offers to copy is one a README gives on the same commit. The film's pill sits over the card's top-left, opposite the play button: on hover or keyboard focus (not clickable while hidden), always on a phone; the caption keeps its height. Reduced motion: no fade for the pill and the toast. The launch short's sentence leaves a blank. --- changes/site-sample-wall.md | 4 ++-- docs/site/index.html | 36 ++++++++++++++++-------------------- tools/readme.py | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/changes/site-sample-wall.md b/changes/site-sample-wall.md index 7ee110fe..bbb2d6e7 100644 --- a/changes/site-sample-wall.md +++ b/changes/site-sample-wall.md @@ -1,5 +1,5 @@ **官网:每支样片、每种风格都带一句"照这个做一支";快速开始列出四个入口** - Why: 新来的人第一步卡在"该说什么"。官网上的样片和风格只能看,不能直接拿来开片。 -- 作品区:鼠标移到一支片子上,出现"照这个做一支 · 复制这句话",复制的是一句照这支的做法、换一个新题目的快出需求,页面底部说一声复制了什么;触屏上一直显示。 +- 作品区:每张片子的左上角(播放键对面)有一个"照这个做一支 · 复制这句话":鼠标移上去或用键盘 Tab 到它时出现,触屏上一直显示。复制的是一句同类片子、换一个新题目的快出需求;发布短片那句留了一个要你填的空([在这里贴上它的链接])。页面底部说一声复制了什么,点开风格大图时这行字自己收起。点它不会播片。 - 风格墙:点开一种风格,样片下面是一句可复制的话:用这种风格快出一版 20 秒的短片,只用画面和文字、不配旁白(避开第一次的配音下载),横屏或竖屏按这种风格支持的画幅;`bin/vh new … --style` 那行命令留在下面。`tools/readme.py check` 核对哪些风格算竖屏。 -- 快速开始第二步改成四个入口:Studio、终端、Claude Code 或 Codex 的桌面 App、别的文件夹(装好的 skill,或在 agent 里一条命令装插件)。 +- 快速开始第二步改成四个入口,每个入口带自己的命令,和 README 一样的顺序:Studio(`bin/vh studio`)、终端(`codex`、`claude`)、Claude Code 或 Codex 的桌面 App、别的文件夹(只装 skill:`npx skills add …`)。`tools/readme.py check` 新查一条:页面上每一条可复制的命令,同一个提交的 README 里都要有,页面就不会先于仓库给出还没有的命令。 diff --git a/docs/site/index.html b/docs/site/index.html index 438bd77e..1c0eb0d2 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -438,11 +438,11 @@ .film figcaption b { display: block; font-size: clamp(15px, 1.15vw, 18px); font-weight: 600; } .film figcaption q { display: block; font-family: var(--display); font-weight: 500; font-size: clamp(15px, 1.2vw, 19px); line-height: 1.25; color: var(--text-2); margin-top: 2px; letter-spacing: -.01em; } .film figcaption small { display: block; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 4px; } -.say-mini { pointer-events: auto; max-height: 0; opacity: 0; overflow: hidden; transition: max-height .25s, opacity .25s, margin .25s; } -.film:hover .say-mini, .film:focus-within .say-mini { max-height: 40px; opacity: 1; margin-top: 7px; } -@media (hover: none) { .say-mini { max-height: none; opacity: 1; margin-top: 7px; } } +.say-mini { position: absolute; top: 12px; left: 12px; right: 62px; z-index: 2; opacity: 0; pointer-events: none; transition: opacity .25s; } +.film:hover .say-mini, .film:focus-within .say-mini { opacity: 1; pointer-events: auto; } +@media (hover: none) { .say-mini { opacity: 1; pointer-events: auto; } } /* a phone: always there, over the film's top-left, opposite its play button */ .say-mini [data-copy-text] { display: none; } -.say-mini .copy.say-btn { position: static; transform: none; font-size: 12px; padding: 4px 10px; border-radius: 999px; color: var(--cyan); background: rgba(8,10,20,.6); } +.say-mini .copy.say-btn { position: static; transform: none; white-space: nowrap; font-size: 12px; padding: 4px 10px; border-radius: 999px; color: var(--cyan); background: rgba(8,10,20,.6); } .toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px); max-width: min(720px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px; background: rgba(12,14,26,.95); border: 1px solid var(--line); color: var(--text); font-size: 14px; line-height: 1.45; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 60; } .toast.show { opacity: 1; transform: translate(-50%, 0); } .films.sees .say-mini { display: none; } @@ -536,7 +536,9 @@ .steps .ways li::before { content: none; } .ways b { color: var(--text); font-weight: 600; } .ways code { font-family: var(--mono); font-size: .92em; color: var(--cyan); } -@media (max-width: 640px) { .steps .ways li { grid-template-columns: minmax(0, 1fr); gap: 0; } } +.ways .cmd code { color: var(--text); font-size: 1em; } +.ways-cmds { grid-column: 2; display: grid; gap: 6px; margin-top: 2px; } +@media (max-width: 640px) { .steps .ways li { grid-template-columns: minmax(0, 1fr); gap: 0; } .ways-cmds { grid-column: 1; margin-top: 6px; } } .start-cli summary { color: var(--cyan); cursor: pointer; font-size: 14px; } .start-cli .cmd { margin-top: 6px; } .steps h3 + .fine, .steps .fine + .cmd { margin-bottom: 6px; } @@ -760,6 +762,7 @@ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } .js [data-r], .js .split .w > span, .js .hero h1, .js .wall, .js .sw { opacity: 1 !important; transform: none !important; filter: none !important; transition: none !important; } + .say-mini, .toast { transition: none; } } @@ -871,19 +874,11 @@

    Compare the revision同一段改完
  6. Install on macOS or Linux在 macOS 或 Linux 安装

    curl -fsSL https://raw.githubusercontent.com/ZLHad/OpenVideoHarness/main/install.sh | bash
  7. Pick a way in选一个入口

      -
    • StudioStudioOpen OVH Studio from your applications, choose your signed-in Claude Code or Codex in the agent column, and click Set it up if prompted.从应用程序打开 OVH Studio,在右栏选已登录的 Claude Code 或 Codex,看到适配器提示时点装上。
    • -
    • Terminal终端Open Claude Code or Codex in the install folder.在安装目录里打开 Claude Code 或 Codex。
    • +
    • StudioStudioOpen OVH Studio from your applications (or run bin/vh studio in the install folder), choose your signed-in Claude Code or Codex in the agent column, and click Set it up if prompted.从应用程序打开 OVH Studio(或在安装目录运行 bin/vh studio),在右栏选已登录的 Claude Code 或 Codex,看到适配器提示时点装上。
      cd ~/OpenVideoHarness && bin/vh studio
    • +
    • Terminal终端In the install folder, start Codex or Claude Code, then send your request.在安装目录里启动 Codex 或 Claude Code,再发送需求。
      cd ~/OpenVideoHarness && codex
      cd ~/OpenVideoHarness && claude
    • Desktop app桌面 AppIn the Claude Code or Codex app, open the install folder (~/OpenVideoHarness) as the project.在 Claude Code 或 Codex 的桌面 App 里,把安装目录(~/OpenVideoHarness)当作项目打开。
    • -
    • Any folder别的文件夹The installer registers a skill for both agents, so “make a video …” finds the workbench from any project. Only the skill, from inside the agent: the commands below.安装时给两个 agent 都注册了 skill,在任何项目里说“做一支视频……”都能找到工作台。只装 skill、在 agent 里一条命令:见下面。
    • +
    • Any folder别的文件夹The installer registers a skill for both agents, so “make a video …” finds the workbench from any project. Only the skill:安装时给两个 agent 都注册了 skill,在任何项目里说“做一支视频……”都能找到工作台。只装 skill:
      npx skills add https://github.com/ZLHad/OpenVideoHarness --skill open-video-harness
    -
    cd ~/OpenVideoHarness && claude
    -
    - More commands: Studio, Codex, only the skill更多命令:Studio、Codex、只装 skill -
    cd ~/OpenVideoHarness && bin/vh studio
    -
    cd ~/OpenVideoHarness && codex
    -
    /plugin install open-video-harness --marketplace ZLHad/OpenVideoHarness
    -
    codex plugin marketplace add ZLHad/OpenVideoHarness && codex plugin add open-video-harness@open-video-harness
    -
  8. Send a first request发送第一条需求

    Quick draft: make a silent 15-second vertical explainer showing why doubling a square’s side length quadruples its area. Use a grid and on-screen text.快速出一版 15 秒的竖屏无声科普,用方格和画面文字讲清楚为什么正方形边长翻倍,面积变成四倍。
    @@ -1127,7 +1122,7 @@

    04Check & deliver查与交 Contact sheet of the science short contact sheet联系表 -
    Vertical science short竖屏科普Why does a low-orbit satellite's signal change pitch?为什么低轨卫星的信号会"变调"?HyperFrames · 24.8 s · 1080×1920 · Chinese voice, two-language subtitlesHyperFrames · 24.8 秒 · 1080×1920 · 中文配音,双语字幕
    Quick draft, the way showcase/02 was made: a 25-second vertical science short on why the sky is blue.照 showcase/02 的做法,快速出一版 25 秒的竖屏科普,讲为什么天空是蓝的。
    +
    Vertical science short竖屏科普Why does a low-orbit satellite's signal change pitch?为什么低轨卫星的信号会"变调"?HyperFrames · 24.8 s · 1080×1920 · Chinese voice, two-language subtitlesHyperFrames · 24.8 秒 · 1080×1920 · 中文配音,双语字幕
    Quick draft: a 25-second vertical science short on why the sky is blue.快速出一版 25 秒的竖屏科普,讲为什么天空是蓝的。
    Every film ships with its paper trail每支片子都附带完整的制作记录 @@ -1845,6 +1840,7 @@

    Star it on GitHub在 GitHub 上点 St const lb = $('#lightbox'), lbMedia = $('#lbMedia'), lbCap = $('#lbCap'); function openLightbox({ video, img, cap, code, say }) { pauseAll(); + const tt = $('#toast'); if (tt) { clearTimeout(toastTimer); tt.classList.remove('show'); } // a copy's line would sit over the lightbox's own lbMedia.innerHTML = ''; if (video) { // a path, or { src, type, loop }: a release file goes through (WebKit refuses it as a bare src) const c = typeof video === 'string' ? { src: video } : video; diff --git a/tools/readme.py b/tools/readme.py index b279f476..b84ff43e 100644 --- a/tools/readme.py +++ b/tools/readme.py @@ -26,6 +26,7 @@ application/octet-stream, which WebKit (Safari) refuses unless the says the type. Links to the web are not fetched (CI runs offline). Exit status: 0 all good, 1 a problem (each said), 2 usage. """ +import html as html_lib import ast, json, os, re, sys, unicodedata from pathlib import Path @@ -398,6 +399,20 @@ def site_problems(have): bad.append(f"{SITE}: RELEASE_SAMPLES gives {slug} {named.get(slug)!r}, tools/media.txt {assets.get(slug)!r}: write '{slug}': '{assets.get(slug)}'") elif slug in named: bad.append(f"{SITE}: RELEASE_SAMPLES names {slug}, a spec-1 style whose sample is in git") + # every command the page gives to copy is one a README gives on the same commit (whole, or after "cd ~/OpenVideoHarness + # && "), so the page cannot offer a command the repo does not have yet + readmes = "\n".join((ROOT / f).read_text(encoding="utf-8") for f in ("README.md", "README.zh-CN.md")) + for c in re.findall(r"(.*?)", html, re.S): + c = html_lib.unescape(re.sub(r"<[^>]+>", "", c)).strip() + if not any(f"`{x}`" in readmes or f"\n{x}\n" in readmes for x in (c, c.removeprefix("cd ~/OpenVideoHarness && "))): + bad.append(f"{SITE}: offers the command {c!r}, which no README gives (write it there first)") + # every command the page gives to copy is one a README gives on the same commit (whole, or after "cd ~/OpenVideoHarness + # && "), so the page cannot offer a command the repo does not have yet + readmes = "\n".join((ROOT / f).read_text(encoding="utf-8") for f in ("README.md", "README.zh-CN.md")) + for c in re.findall(r"(.*?)", html, re.S): + c = html_lib.unescape(re.sub(r"<[^>]+>", "", c)).strip() + if not any(f"`{x}`" in readmes or f"\n{x}\n" in readmes for x in (c, c.removeprefix("cd ~/OpenVideoHarness && "))): + bad.append(f"{SITE}: offers the command {c!r}, which no README gives (write it there first)") body = html[html.find("]*\blang=\"(en|zh)\"", body) en, zh = (sum(1 for tag, lang in tags if lang == want and tag != "small") for want in ("en", "zh"))