From 91385c3e632da14419e4faf42688d5a4d2e9fdb5 Mon Sep 17 00:00:00 2001 From: Dylan Hunt Date: Thu, 3 Dec 2026 14:11:53 +0800 Subject: [PATCH 1/2] chore: regenerate third-party notices in the pre-commit hook The 'Attribution is current' CI job failed on five PRs because a lockfile change was committed without bun run licenses:generate. scripts/ensure-attribution.mjs now runs from the husky pre-commit hook: when a commit stages a generator input it regenerates the notices and stages them, and it refuses the commit when cargo-about is missing or not the version ci.yml pins. Other commits exit immediately. --- .husky/pre-commit | 1 + CHANGELOG.md | 5 ++ CLAUDE.md | 2 +- CONTRIBUTING.md | 3 + scripts/ensure-attribution.mjs | 121 +++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 scripts/ensure-attribution.mjs diff --git a/.husky/pre-commit b/.husky/pre-commit index 4408be2..9224fb5 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,2 @@ +bun scripts/ensure-attribution.mjs bun run check diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c65495..e024c54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to Echophrase will be documented in this file. +## [Unreleased] + +### Developers +- Committing a dependency change (`Cargo.lock`, `bun.lock`) now regenerates the third-party notices in the same commit, so the "Attribution is current" check no longer fails afterwards. It needs `cargo-about` at the version `ci.yml` pins. + ## [v1.3.0] - 2026-12-02 diff --git a/CLAUDE.md b/CLAUDE.md index 12cc8bb..fe0ae85 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -389,7 +389,7 @@ buttons). Add an entry whenever you work around a bug you do not own. - When updating `env.yaml`, also update `env.yaml.template` - Safetensors only for Candle models (no GGUF, no PyTorch .bin) - All user-facing strings must be localized. When adding or changing any string, update all three of `src/lib/locales/en.json`, `src/lib/locales/zh-TW.json` and `src/lib/locales/zh-CN.json` (a vitest parity test fails on key drift). Use `t('key')` in templates and `translate('key')` in JS. -- **When adding a new Rust dependency** (`cargo add`), check its license against `src-tauri/about.toml`'s `accepted` allowlist (the copyleft guard - `cargo about generate` fails the build if a shipped crate's license isn't listed). If the license is already accepted (MIT, Apache-2.0, BSD, MIT-0, CC0-1.0, etc.), no action needed - attribution text itself is auto-generated from `Cargo.lock` (`bun run licenses:generate`), never hand-written. Any `Cargo.lock` change that alters a shipped crate's name, version or license (even a patch bump of a transitive crate) must commit the regenerated `ATTRIBUTION.md` / `src-tauri/licenses/THIRD-PARTY-NOTICES.txt` in the same PR, or the "Attribution is current" CI job fails. The generator also rebuilds the frontend (which rewrites the tracked `static/index.html` - restore it) and writes `licenses.generated.json` into a sibling `echophrase-www` checkout when one exists. If it's a new license not yet in the list, confirm it's permissive/notice-only (never add GPL/AGPL/LGPL) before adding it to `accepted`. New frontend (`bun add`) dependencies are covered automatically by `rollup-license-plugin` in `vite.config.js` - no manual step there either. +- **When adding a new Rust dependency** (`cargo add`), check its license against `src-tauri/about.toml`'s `accepted` allowlist (the copyleft guard - `cargo about generate` fails the build if a shipped crate's license isn't listed). If the license is already accepted (MIT, Apache-2.0, BSD, MIT-0, CC0-1.0, etc.), no action needed - attribution text itself is auto-generated from `Cargo.lock` (`bun run licenses:generate`), never hand-written. Any `Cargo.lock` change that alters a shipped crate's name, version or license (even a patch bump of a transitive crate) must commit the regenerated `ATTRIBUTION.md` / `src-tauri/licenses/THIRD-PARTY-NOTICES.txt` in the same PR, or the "Attribution is current" CI job fails. The pre-commit hook does this for you: `scripts/ensure-attribution.mjs` regenerates and stages both files whenever a commit stages `Cargo.lock`, `bun.lock`, `src-tauri/about.toml`, `src-tauri/about.hbs`, `vite.config.js` or the generator itself (about a minute; every other commit is unaffected). It needs `cargo-about` at the exact version `ci.yml` pins and refuses the commit otherwise - install it, do not skip the hook. The generator also writes `licenses.generated.json` into a sibling `echophrase-www` checkout when one exists, and when run by hand (`bun run licenses:generate`) leaves the tracked `static/index.html` rewritten by its frontend build - restore that file, never commit it. If it's a new license not yet in the list, confirm it's permissive/notice-only (never add GPL/AGPL/LGPL) before adding it to `accepted`. New frontend (`bun add`) dependencies are covered automatically by `rollup-license-plugin` in `vite.config.js` - no manual step there either. ### Backend Architecture Principles - **Traits for swappable systems**: VAD, transcription, GPU providers use trait interfaces diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97b6f2c..3cdc1ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,6 +43,9 @@ are in [CLAUDE.md](CLAUDE.md), which is written for human contributors and AI co ``` 8. **New dependencies** must be permissively licensed. Rust crates must match the `accepted` list in `src-tauri/about.toml` (no GPL/AGPL/LGPL). + A commit that changes `Cargo.lock` or `bun.lock` regenerates the third-party notices + through the pre-commit hook (`scripts/ensure-attribution.mjs`), which needs + `cargo-about` at the version pinned in `.github/workflows/ci.yml`. ## Style diff --git a/scripts/ensure-attribution.mjs b/scripts/ensure-attribution.mjs new file mode 100644 index 0000000..2b9143e --- /dev/null +++ b/scripts/ensure-attribution.mjs @@ -0,0 +1,121 @@ +#!/usr/bin/env node + +// SPDX-FileCopyrightText: 2025-2026 Imperium42 LLC +// +// SPDX-License-Identifier: MPL-2.0 + +// Pre-commit guard for the "Attribution is current" CI job. Run from repo root +// (husky does): `bun scripts/ensure-attribution.mjs`. +// +// When the commit stages a file the third-party notices are generated from, this +// regenerates them (scripts/gen-attribution.mjs) and stages the result, so a +// dependency change and its attribution always land in the same commit. Any other +// commit exits immediately. +// +// The job failed on five PRs before this existed, every time because a lockfile +// change was committed without `bun run licenses:generate`. +// +// --force regenerate even when no input is staged +// SKIP_ATTRIBUTION=1 skip (CI will still fail a stale commit) + +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); + +/** Files whose content decides what gen-attribution.mjs writes. */ +const INPUTS = [ + "Cargo.lock", + "bun.lock", + "src-tauri/about.toml", + "src-tauri/about.hbs", + "scripts/gen-attribution.mjs", + "vite.config.js", // npm license plugin config and overrides +]; + +/** The committed generator outputs that CI diffs. */ +const OUTPUTS = ["ATTRIBUTION.md", "src-tauri/licenses/THIRD-PARTY-NOTICES.txt"]; + +/** `vite build` rewrites this tracked file; it is not an attribution output. */ +const BUILD_CHURN = "static/index.html"; + +function git(args) { + return execFileSync("git", args, { cwd: repoRoot, encoding: "utf8" }); +} + +function fail(message) { + console.error(`[attribution] ${message}`); + console.error( + "[attribution] To commit anyway, set SKIP_ATTRIBUTION=1 (the CI job will fail until the notices are regenerated).", + ); + process.exit(1); +} + +/** The cargo-about version CI pins; ci.yml is the single source of truth. */ +function pinnedCargoAbout() { + const ci = readFileSync(resolve(repoRoot, ".github/workflows/ci.yml"), "utf8"); + const match = ci.match(/tool:\s*cargo-about@(\d+\.\d+\.\d+)/); + if (!match) fail("could not read the pinned cargo-about version from .github/workflows/ci.yml"); + return match[1]; +} + +function installedCargoAbout() { + try { + const out = execFileSync("cargo", ["about", "--version"], { cwd: repoRoot, encoding: "utf8" }); + return out.match(/(\d+\.\d+\.\d+)/)?.[1] ?? null; + } catch { + return null; + } +} + +function main() { + if (process.env.SKIP_ATTRIBUTION === "1") { + console.log("[attribution] SKIP_ATTRIBUTION=1 - not checking"); + return; + } + + const staged = git(["diff", "--cached", "--name-only"]).split("\n").filter(Boolean); + const touched = INPUTS.filter((file) => staged.includes(file)); + if (touched.length === 0 && !process.argv.includes("--force")) return; + + console.log( + `[attribution] ${touched.length ? `${touched.join(", ")} staged` : "--force"} - regenerating third-party notices...`, + ); + + // A different cargo-about version groups notices differently, so its output + // would fail CI just the same as a stale file. + const pinned = pinnedCargoAbout(); + const installed = installedCargoAbout(); + if (installed !== pinned) { + fail( + `cargo-about ${pinned} is required (found: ${installed ?? "none"}). ` + + `Install it with: cargo install cargo-about@${pinned} --locked --features cli`, + ); + } + + const churnWasClean = git(["status", "--porcelain", "--", BUILD_CHURN]).trim() === ""; + + let generated = true; + try { + execFileSync("bun", ["scripts/gen-attribution.mjs"], { cwd: repoRoot, stdio: "inherit" }); + } catch { + generated = false; + } + // Restore before failing: fail() exits the process, which would skip a `finally`. + if (churnWasClean) git(["checkout", "--", BUILD_CHURN]); + if (!generated) { + fail("scripts/gen-attribution.mjs failed (see the output above); nothing was staged"); + } + + const changed = git(["status", "--porcelain", "--", ...OUTPUTS]).trim(); + git(["add", "--", ...OUTPUTS]); + console.log( + changed + ? "[attribution] notices changed and were added to this commit" + : "[attribution] notices already current", + ); +} + +main(); From 52f14f9fad224d7dae17f49e3147146bf2249836 Mon Sep 17 00:00:00 2001 From: Dylan Hunt Date: Thu, 3 Dec 2026 15:35:48 +0800 Subject: [PATCH 2/2] chore: untrack static/index.html and keep the attribution hook out of the website repo static/index.html is vite build output that names hashed files under the gitignored static/_app/, so the committed copy was stale after every build and broken on a fresh clone; the app compiles without it. The pre-commit attribution guard now passes --skip-www so a dependency commit does not rewrite the sibling website checkout. --- .gitignore | 3 + CHANGELOG.md | 1 + CLAUDE.md | 2 +- scripts/ensure-attribution.mjs | 16 +--- scripts/gen-attribution.mjs | 11 ++- static/index.html | 149 --------------------------------- 6 files changed, 17 insertions(+), 165 deletions(-) delete mode 100644 static/index.html diff --git a/.gitignore b/.gitignore index c7d9e9a..c504153 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,9 @@ src-tauri/icons/Assets.xcassets/ static/oss-licenses.json # Prerendered overlay route (vite build output, regenerated every build) static/overlay.html +# SPA fallback page (vite build output). It names hashed files under static/_app/, so a +# committed copy is stale after any build and broken on a fresh clone. +static/index.html # Generated by scripts/env/load.mjs when DEV_PORT != 8420 .tauri-dev-port.json diff --git a/CHANGELOG.md b/CHANGELOG.md index e024c54..5b72415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to Echophrase will be documented in this file. ### Developers - Committing a dependency change (`Cargo.lock`, `bun.lock`) now regenerates the third-party notices in the same commit, so the "Attribution is current" check no longer fails afterwards. It needs `cargo-about` at the version `ci.yml` pins. +- `static/index.html` is no longer tracked. It is build output, so it showed up as modified after every build. ## [v1.3.0] - 2026-12-02 diff --git a/CLAUDE.md b/CLAUDE.md index fe0ae85..229af81 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -389,7 +389,7 @@ buttons). Add an entry whenever you work around a bug you do not own. - When updating `env.yaml`, also update `env.yaml.template` - Safetensors only for Candle models (no GGUF, no PyTorch .bin) - All user-facing strings must be localized. When adding or changing any string, update all three of `src/lib/locales/en.json`, `src/lib/locales/zh-TW.json` and `src/lib/locales/zh-CN.json` (a vitest parity test fails on key drift). Use `t('key')` in templates and `translate('key')` in JS. -- **When adding a new Rust dependency** (`cargo add`), check its license against `src-tauri/about.toml`'s `accepted` allowlist (the copyleft guard - `cargo about generate` fails the build if a shipped crate's license isn't listed). If the license is already accepted (MIT, Apache-2.0, BSD, MIT-0, CC0-1.0, etc.), no action needed - attribution text itself is auto-generated from `Cargo.lock` (`bun run licenses:generate`), never hand-written. Any `Cargo.lock` change that alters a shipped crate's name, version or license (even a patch bump of a transitive crate) must commit the regenerated `ATTRIBUTION.md` / `src-tauri/licenses/THIRD-PARTY-NOTICES.txt` in the same PR, or the "Attribution is current" CI job fails. The pre-commit hook does this for you: `scripts/ensure-attribution.mjs` regenerates and stages both files whenever a commit stages `Cargo.lock`, `bun.lock`, `src-tauri/about.toml`, `src-tauri/about.hbs`, `vite.config.js` or the generator itself (about a minute; every other commit is unaffected). It needs `cargo-about` at the exact version `ci.yml` pins and refuses the commit otherwise - install it, do not skip the hook. The generator also writes `licenses.generated.json` into a sibling `echophrase-www` checkout when one exists, and when run by hand (`bun run licenses:generate`) leaves the tracked `static/index.html` rewritten by its frontend build - restore that file, never commit it. If it's a new license not yet in the list, confirm it's permissive/notice-only (never add GPL/AGPL/LGPL) before adding it to `accepted`. New frontend (`bun add`) dependencies are covered automatically by `rollup-license-plugin` in `vite.config.js` - no manual step there either. +- **When adding a new Rust dependency** (`cargo add`), check its license against `src-tauri/about.toml`'s `accepted` allowlist (the copyleft guard - `cargo about generate` fails the build if a shipped crate's license isn't listed). If the license is already accepted (MIT, Apache-2.0, BSD, MIT-0, CC0-1.0, etc.), no action needed - attribution text itself is auto-generated from `Cargo.lock` (`bun run licenses:generate`), never hand-written. Any `Cargo.lock` change that alters a shipped crate's name, version or license (even a patch bump of a transitive crate) must commit the regenerated `ATTRIBUTION.md` / `src-tauri/licenses/THIRD-PARTY-NOTICES.txt` in the same PR, or the "Attribution is current" CI job fails. The pre-commit hook does this for you: `scripts/ensure-attribution.mjs` regenerates and stages both files whenever a commit stages `Cargo.lock`, `bun.lock`, `src-tauri/about.toml`, `src-tauri/about.hbs`, `vite.config.js` or the generator itself (about a minute; every other commit is unaffected). It needs `cargo-about` at the exact version `ci.yml` pins and refuses the commit otherwise - install it, do not skip the hook. Run by hand (`bun run licenses:generate`, the release flow), the generator also writes `licenses.generated.json` into a sibling `echophrase-www` checkout when one exists; the hook passes `--skip-www`, because the website lists what the last release ships. If it's a new license not yet in the list, confirm it's permissive/notice-only (never add GPL/AGPL/LGPL) before adding it to `accepted`. New frontend (`bun add`) dependencies are covered automatically by `rollup-license-plugin` in `vite.config.js` - no manual step there either. ### Backend Architecture Principles - **Traits for swappable systems**: VAD, transcription, GPU providers use trait interfaces diff --git a/scripts/ensure-attribution.mjs b/scripts/ensure-attribution.mjs index 2b9143e..90a7b53 100644 --- a/scripts/ensure-attribution.mjs +++ b/scripts/ensure-attribution.mjs @@ -38,9 +38,6 @@ const INPUTS = [ /** The committed generator outputs that CI diffs. */ const OUTPUTS = ["ATTRIBUTION.md", "src-tauri/licenses/THIRD-PARTY-NOTICES.txt"]; -/** `vite build` rewrites this tracked file; it is not an attribution output. */ -const BUILD_CHURN = "static/index.html"; - function git(args) { return execFileSync("git", args, { cwd: repoRoot, encoding: "utf8" }); } @@ -95,17 +92,12 @@ function main() { ); } - const churnWasClean = git(["status", "--porcelain", "--", BUILD_CHURN]).trim() === ""; - - let generated = true; try { - execFileSync("bun", ["scripts/gen-attribution.mjs"], { cwd: repoRoot, stdio: "inherit" }); + execFileSync("bun", ["scripts/gen-attribution.mjs", "--skip-www"], { + cwd: repoRoot, + stdio: "inherit", + }); } catch { - generated = false; - } - // Restore before failing: fail() exits the process, which would skip a `finally`. - if (churnWasClean) git(["checkout", "--", BUILD_CHURN]); - if (!generated) { fail("scripts/gen-attribution.mjs failed (see the output above); nothing was staged"); } diff --git a/scripts/gen-attribution.mjs b/scripts/gen-attribution.mjs index b6f299f..26c699f 100644 --- a/scripts/gen-attribution.mjs +++ b/scripts/gen-attribution.mjs @@ -22,9 +22,11 @@ * - ./ATTRIBUTION.md (repo-root artifact) * * Usage: - * node scripts/gen-attribution.mjs [--skip-npm-build] + * node scripts/gen-attribution.mjs [--skip-npm-build] [--skip-www] * (--skip-npm-build reuses an existing static/oss-licenses.json for fast dev - * iteration; the release path always rebuilds for freshness.) + * iteration; the release path always rebuilds for freshness. + * --skip-www leaves the website checkout alone: the pre-commit hook passes it, + * because the site should list what the last RELEASE ships, not every commit.) */ import { execFileSync } from "node:child_process"; @@ -46,6 +48,7 @@ const noticesTxt = resolve(srcTauri, "licenses/THIRD-PARTY-NOTICES.txt"); const npmManifest = resolve(clientRoot, "static/oss-licenses.json"); const skipNpmBuild = process.argv.includes("--skip-npm-build"); +const skipWww = process.argv.includes("--skip-www"); // Copyleft licenses that must never ship. The Rust side is already guarded by // about.toml's `accepted` allowlist; this is the second gate for npm packages. @@ -310,7 +313,9 @@ function main() { console.log(`[attribution] wrote ${attributionMd}`); // The website repo is a maintainer-only sibling checkout; public clones // don't have it, so only ATTRIBUTION.md is required. - if (existsSync(dirname(wwwDataFile))) { + if (skipWww) { + console.log(`[attribution] skipped ${wwwDataFile} (--skip-www)`); + } else if (existsSync(dirname(wwwDataFile))) { writeFileSync(wwwDataFile, JSON.stringify(out, null, 2) + "\n"); console.log(`[attribution] wrote ${wwwDataFile}`); } else { diff --git a/static/index.html b/static/index.html deleted file mode 100644 index 0347c77..0000000 --- a/static/index.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - - - Echophrase - - - - - - - - - - - - -
- -
- - -