Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

ci(repository): run only the checks a change needs

shoudi zhengf8528ce0ad01
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d8122156..6c2df6fd 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -6,7 +6,8 @@ name: CI
# which GitHub reports as success for its required check; a failed path
# filter makes every app check fail instead of skipping. A merge-queue build
# checks the paths its whole group changes, on top of the latest main. Pushes
-# to main run every check. CI runs the
+# to main run every check. scripts/check-plan.mjs maps paths to checks, here
+# and in `make check`. CI runs the
# computer daemon's Go unit tests; the rest of check-computer (TS and process
# tests) and the heavier suites (node-services, voice-runtime, integration,
# containers and E2E) stay local: run `make check BASE=<target-ref>` and the
@@ -58,23 +59,9 @@ jobs:
else
changed=ALL
fi
- # Files every Node check depends on.
- node='^(package\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|\.npmrc|\.node-version|patches/|eslint\.config\.mjs|tsconfig\.base\.json|vitest\.config\.ts|Makefile|\.github/)'
- match() {
- if [ "$changed" = ALL ] || grep -Eq "$1" <<<"$changed"; then
- echo "$2=true" >>"$GITHUB_OUTPUT"
- else
- echo "$2=false" >>"$GITHUB_OUTPUT"
- fi
- }
- match "$node|^(apps/web/|packages/|contracts/generated/typescript/)" web
- match "$node|^(packages/|contracts/generated/typescript/|contracts/fixtures/)" packages
- match "$node|^(apps/teamhub-cli/|packages/|contracts/)" teamhub-cli
- match "$node|^(apps/linger-installer/|packages/|contracts/generated/typescript/)" installer
- match "$node|^(apps/desktop/|apps/computer/local-daemon/|apps/computer/package\.json|packages/|contracts/generated/typescript/)" desktop
- match "$node|^contracts/" contracts
- match '^(apps/teamhub/|skills/|contracts/generated/go/|contracts/fixtures/|\.golangci\.yml|Makefile|\.github/)' teamhub
- match '^(apps/computer/local-daemon/|apps/computer/run-test\.sh|contracts/generated/go/runnergateway/|contracts/runner-gateway/fixtures/|scripts/managed-tools-|scripts/local-computer-node-distributions\.mjs|scripts/test-fixtures/managed-tools-fixture\.mjs|Makefile|\.github/)' computer-go
+ # scripts/check-plan.mjs maps paths to checks for CI and `make
+ # check`; it uses only Node builtins, so the runner's Node runs it.
+ printf '%s\n' "$changed" | node scripts/check-plan.mjs --files-from - --format github >>"$GITHUB_OUTPUT"
repository-gate:
runs-on: ubuntu-latest
diff --git a/AGENTS.md b/AGENTS.md
index f00e1f6f..def4a520 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -20,7 +20,10 @@ Memory, and Voice services.
Node Services test, including the Agent Service's under `tests/agent/`.
- `make -C apps/teamhub test`: run TeamHub unit tests.
- `pnpm contracts:generate && pnpm contracts:verify`: regenerate and verify OpenAPI consumers.
-- `make check BASE=<target-ref>`: run every app's fast check in parallel.
+- `make check BASE=<target-ref>`: run in parallel the fast checks that the
+ changes since the merge base (committed, uncommitted, and untracked)
+ select; it prints the plan first, and `ALL=1` runs every fast check.
+ `scripts/check-plan.mjs` holds the path-to-check map that CI also uses.
Fast checks are local and need no Postgres, containers, or full suite.
`BASE` is required because the built-in Skill immutability check compares
against it; the repository assumes no default branch.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index bf7d223f..bec72e43 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -51,7 +51,7 @@ you touched. None of these need a database or containers.
| Change | Command |
| ---------------- | ----------------------------------------------------------------------------------------------------- |
-| Anything | `make check BASE=origin/<target-branch>` runs every app's fast check in parallel |
+| Anything | `make check BASE=origin/<target-branch>` runs the fast checks your changes select (`ALL=1` for all) |
| Web | `make check-web` |
| TeamHub | `make -C apps/teamhub fmt-check` and `cd apps/teamhub && go test ./tests/integration/layout -count=1` |
| Other apps | the matching `make check-<app>` |
diff --git a/Makefile b/Makefile
index 6209d4ac..7511614a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
.PHONY: contracts-generate contracts-verify computer-release-local source-archive source-dependencies
.PHONY: check-teamhub-cli check-installer check-desktop
-.PHONY: check check-heavy-lane check-web check-web-static check-web-tests
+.PHONY: check check-planned check-heavy-lane check-web check-web-static check-web-tests
.PHONY: check-computer check-computer-go check-computer-release check-node-services check-voice-runtime
.PHONY: check-teamhub check-teamhub-tooling check-teamhub-integration
.PHONY: check-teamhub-integration-process check-teamhub-integration-migrations
@@ -41,29 +41,45 @@ SCRIPT_FAST_SPAWN_TESTS = $(if $(SCRIPT_FAST_PARALLEL_TESTS),$(shell grep -l chi
SCRIPT_FAST_PURE_TESTS = $(filter-out $(SCRIPT_FAST_SPAWN_TESTS),$(SCRIPT_FAST_PARALLEL_TESTS))
# Every fast check. Integration, build, container, E2E and the heavy script
-# tests stay separate targets. The light checks run CHECK_JOBS at a time beside
-# one lane that runs the heavy test suites one after another: their timed tests
-# fail when they share the CPU. BASE reaches the built-in Skill immutability
-# check inside check-teamhub.
+# tests stay separate targets. `make check` runs only the checks that
+# scripts/check-plan.mjs selects for the changes since merge-base(BASE, HEAD),
+# including uncommitted and untracked files; ALL=1 runs every check. CI's
+# changes job reads the same plan. The light checks run CHECK_JOBS at a time
+# beside one lane that runs the heavy test suites one after another: their
+# timed tests fail when they share the CPU. BASE reaches the built-in Skill
+# immutability check inside check-teamhub.
FAST_CHECKS := check-repository check-docs check-contracts check-packages \
check-voice-runtime check-teamhub-cli check-installer check-desktop \
check-teamhub check-teamhub-tooling check-scripts-fast
HEAVY_CHECKS := check-web check-node-services check-computer
CHECK_JOBS ?= 4
+# The planned targets; `make check` sets them for its sub-make.
+CHECK_TARGETS ?= $(FAST_CHECKS) $(HEAVY_CHECKS)
+CHECK_PLAN = node scripts/check-plan.mjs $(if $(ALL),--all,--base '$(BASE)')
# GNU Make 3.81 (macOS) has no --output-sync.
OUTPUT_SYNC := $(if $(filter 3.%,$(MAKE_VERSION)),,--output-sync=target)
check:
- @test -n "$(strip $(BASE))" || { echo "Usage: make check BASE=<target-ref>" >&2; exit 2; }
- $(MAKE) -j$(CHECK_JOBS) $(OUTPUT_SYNC) $(FAST_CHECKS) check-heavy-lane
+ @test -n "$(strip $(BASE))" || { echo "Usage: make check BASE=<target-ref> [ALL=1]" >&2; exit 2; }
+ @$(CHECK_PLAN)
+ @targets="$$($(CHECK_PLAN) --format make)" && test -n "$$targets" || { echo "check-plan selected no checks" >&2; exit 1; }; \
+ $(MAKE) -j$(CHECK_JOBS) $(OUTPUT_SYNC) CHECK_TARGETS="$$targets" check-planned
+
+check-planned: $(filter $(CHECK_TARGETS),$(FAST_CHECKS)) check-heavy-lane
check-heavy-lane:
- $(MAKE) -j1 $(HEAVY_CHECKS)
+ $(if $(filter $(CHECK_TARGETS),$(HEAVY_CHECKS)),$(MAKE) -j1 $(filter $(CHECK_TARGETS),$(HEAVY_CHECKS)))
+# With a BASE, formats and lints only the changed files unless ALL=1 or the
+# plan selects every check; without one, the whole repository.
check-repository:
- pnpm format:check
- pnpm lint
pnpm env:inventory:check
+ @if [ -z "$(strip $(BASE))" ] || [ "$$($(CHECK_PLAN) --format scope)" = all ]; then \
+ echo "pnpm format:check && pnpm lint"; pnpm format:check && pnpm lint; \
+ else \
+ echo "scripts/ci/check-changed-files.sh (changes since $(BASE))"; \
+ bash scripts/ci/check-changed-files.sh "$$(git merge-base '$(BASE)^{commit}' HEAD)" --worktree; \
+ fi
# React Doctor compares against BASE. Without one it scans the whole repository,
# which exceeds its lint budget on CI runners and fails. A push that creates a
@@ -110,10 +126,11 @@ check-teamhub-cli:
pnpm --filter @linger/teamhub-cli test
pnpm --filter @linger/teamhub-cli build
+# check-packages covers @linger/local-installation.
check-installer:
- pnpm --filter @linger/local-installation --filter @linger/linger-installer typecheck
- pnpm --filter @linger/local-installation --filter @linger/linger-installer lint
- pnpm --workspace-concurrency=1 --filter @linger/local-installation --filter @linger/linger-installer test
+ pnpm --filter @linger/linger-installer typecheck
+ pnpm --filter @linger/linger-installer lint
+ pnpm --filter @linger/linger-installer test
check-desktop:
pnpm --filter @linger/desktop typecheck
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.md
index 22e68a6e..28f695b0 100644
--- a/packages/local-installation/AGENTS.md
+++ b/packages/local-installation/AGENTS.md
@@ -142,6 +142,6 @@ to absolute paths runs a local `localmodels` checkout instead of fetching the
published kit, and `LOCALMODELS_DEBUG` (`simulate` or `tiny`, or
`~/.config/localmodels/debug.json`) passes straight through to `localmodels`.
-Run `pnpm --filter @linger/local-installation check`; `make check-installer`
-also runs its consumer, the installer, and applies to changes that affect its
-public behavior.
+Run `pnpm --filter @linger/local-installation check` (`make check-packages`
+runs it too); `make check-installer` runs its consumer, the installer, and
+applies to changes that affect its public behavior.
diff --git a/scripts/AGENTS.md b/scripts/AGENTS.md
index b363f182..3a82ad16 100644
--- a/scripts/AGENTS.md
+++ b/scripts/AGENTS.md
@@ -28,8 +28,8 @@ Scripts support existing build, generation, and verification entrypoints.
`make check-scripts-fast`. Changes to the Local Computer installer,
uninstaller, installer fixtures, bundle or manifest generation, signatures,
or release images must also run `make check-scripts-heavy` locally.
-- Before delivery, run `make check BASE=<target-branch>`, which runs every
- app's fast check. Do not replace installer security failures,
+- Before delivery, run `make check BASE=<target-branch>`, which runs the
+ fast checks the change selects through `scripts/check-plan.mjs`. Do not replace installer security failures,
the complete install path, signature or rollback checks, or release
integrity with pure unit coverage unless equivalent end-to-end coverage is
identified and documented.
diff --git a/scripts/check-plan.mjs b/scripts/check-plan.mjs
new file mode 100644
index 00000000..8a3eef49
--- /dev/null
+++ b/scripts/check-plan.mjs
@@ -0,0 +1,443 @@
+// Selects the fast checks a change set needs. `make check` and the CI
+// `changes` job both read this table, so local and CI agree on which paths
+// select which check. Any error selects every check; it never selects nothing.
+import { execFileSync } from "node:child_process";
+import { readFileSync, readdirSync } from "node:fs";
+import path from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
+
+const repositoryRoot = fileURLToPath(new URL("..", import.meta.url));
+
+// A change to any of these selects every check. Paths are prefixes from the
+// repository root, so `.github/` covers the directory and `package.json` only
+// the root file.
+export const EVERYTHING_PATHS = [
+ "Makefile",
+ "scripts/check-plan.mjs",
+ ".github/",
+ "package.json",
+ "pnpm-lock.yaml",
+ "pnpm-workspace.yaml",
+ ".npmrc",
+ ".node-version",
+ "patches/",
+ "eslint.config.mjs",
+ "tsconfig.base.json",
+ "vitest.config.ts",
+ ".golangci.yml",
+];
+
+const COMPUTER_GO_PATHS = [
+ "apps/computer/local-daemon/",
+ "apps/computer/run-test.sh",
+ "contracts/generated/go/runnergateway/",
+ "contracts/runner-gateway/fixtures/",
+ "scripts/managed-tools-",
+ "scripts/local-computer-node-distributions.mjs",
+ "scripts/test-fixtures/managed-tools-fixture.mjs",
+];
+
+// Make targets in the order `make check` runs them. `packages` are workspace
+// package directories; the plan adds every transitive `workspace:*`
+// dependency's directory. `paths` are extra prefixes the target reads.
+// `ci` is the CI `changes` output key; `local: false` keeps a CI-only target
+// out of `make check`; `always` targets run on every local plan.
+export const TARGETS = [
+ { target: "check-repository", lane: "fast", always: true },
+ { target: "check-docs", lane: "fast", always: true },
+ {
+ target: "check-contracts",
+ lane: "fast",
+ ci: "contracts",
+ paths: ["contracts/"],
+ },
+ {
+ target: "check-packages",
+ lane: "fast",
+ ci: "packages",
+ paths: [
+ "packages/",
+ "contracts/generated/typescript/",
+ "contracts/fixtures/",
+ ],
+ },
+ {
+ target: "check-voice-runtime",
+ lane: "fast",
+ packages: ["apps/voice-runtime"],
+ },
+ {
+ target: "check-teamhub-cli",
+ lane: "fast",
+ ci: "teamhub-cli",
+ paths: ["apps/teamhub-cli/", "packages/", "contracts/"],
+ },
+ {
+ target: "check-installer",
+ lane: "fast",
+ ci: "installer",
+ paths: [
+ "apps/linger-installer/",
+ "packages/",
+ "contracts/generated/typescript/",
+ ],
+ },
+ {
+ target: "check-desktop",
+ lane: "fast",
+ ci: "desktop",
+ paths: [
+ "apps/desktop/",
+ "apps/computer/local-daemon/",
+ "apps/computer/package.json",
+ "packages/",
+ "contracts/generated/typescript/",
+ ],
+ },
+ {
+ target: "check-teamhub",
+ lane: "fast",
+ ci: "teamhub",
+ paths: [
+ "apps/teamhub/",
+ "skills/",
+ "contracts/generated/go/",
+ "contracts/fixtures/",
+ ],
+ },
+ {
+ // apps/teamhub test-scripts: its fixtures build their own repositories.
+ target: "check-teamhub-tooling",
+ lane: "fast",
+ paths: [
+ "apps/teamhub/scripts/",
+ "apps/teamhub/Makefile",
+ "apps/teamhub/deployments/compose/",
+ ],
+ },
+ {
+ // Script tests also read these repository files and contracts.
+ target: "check-scripts-fast",
+ lane: "fast",
+ paths: [
+ "scripts/",
+ "contracts/",
+ ".dockerignore",
+ ".env.example",
+ ".husky/",
+ "docker-compose.yml",
+ "apps/web/Dockerfile",
+ "apps/web/package.json",
+ "apps/node-services/Dockerfile",
+ "apps/node-services/package.json",
+ "apps/node-services/release-lockfiles/",
+ "apps/computer/package.json",
+ "apps/teamhub/Dockerfile",
+ "apps/teamhub/Makefile",
+ "apps/teamhub/deployments/compose/",
+ "apps/desktop/src/main/",
+ "apps/linger-installer/src/server/",
+ "packages/local-installation/src/",
+ ],
+ },
+ {
+ target: "check-web",
+ lane: "heavy",
+ ci: "web",
+ paths: ["apps/web/", "packages/", "contracts/generated/typescript/"],
+ },
+ {
+ // Tests read daemon sources, run daemon Go tests, and read these
+ // TeamHub sources and shared fixtures.
+ target: "check-node-services",
+ lane: "heavy",
+ packages: ["apps/node-services"],
+ paths: [
+ "apps/computer/local-daemon/",
+ "apps/teamhub/internal/permissionreview/",
+ "apps/teamhub/internal/typedcard/",
+ "contracts/runner-gateway/",
+ "scripts/test-fixtures/",
+ ],
+ },
+ {
+ // Runs check-computer-go, the @linger/computer suite (which bundles the
+ // TeamHub CLI and Computer tools) and the Daemon to Node Services process
+ // test, which runs nowhere else; the Gateway it starts imports across
+ // Node Services, so any change there or in its dependencies selects it.
+ target: "check-computer",
+ lane: "heavy",
+ packages: ["apps/computer", "apps/node-services", "apps/teamhub-cli"],
+ paths: [
+ ...COMPUTER_GO_PATHS,
+ "scripts/computer-tool-bundle.mjs",
+ "scripts/prepare-local-computer-release.mjs",
+ "scripts/test-fixtures/",
+ ],
+ },
+ {
+ target: "check-computer-go",
+ lane: "fast",
+ ci: "computer-go",
+ local: false,
+ paths: COMPUTER_GO_PATHS,
+ },
+];
+
+export const CI_KEYS = TARGETS.filter((entry) => entry.ci).map(
+ (entry) => entry.ci,
+);
+
+function readJSON(file) {
+ return JSON.parse(readFileSync(file, "utf8"));
+}
+
+// Reads the workspace package directories and their `workspace:*`
+// dependencies from pnpm-workspace.yaml globs of the form `dir` or `dir/*`.
+export function readWorkspace(root = repositoryRoot) {
+ const manifest = readFileSync(path.join(root, "pnpm-workspace.yaml"), "utf8");
+ const globs = [];
+ let inPackages = false;
+ for (const line of manifest.split("\n")) {
+ if (/^packages:\s*$/.test(line)) {
+ inPackages = true;
+ continue;
+ }
+ if (!inPackages) continue;
+ const item = /^\s+-\s+["']?([^"']+)["']?\s*$/.exec(line);
+ if (item) globs.push(item[1]);
+ else if (/^\S/.test(line)) break;
+ }
+ if (globs.length === 0)
+ throw new Error("pnpm-workspace.yaml lists no packages");
+ const directories = [];
+ for (const glob of globs) {
+ if (glob.endsWith("/*")) {
+ const parent = glob.slice(0, -2);
+ for (const entry of readdirSync(path.join(root, parent), {
+ withFileTypes: true,
+ })) {
+ if (entry.isDirectory()) directories.push(`${parent}/${entry.name}`);
+ }
+ } else {
+ directories.push(glob);
+ }
+ }
+ const packages = {};
+ for (const directory of directories) {
+ let manifestJSON;
+ try {
+ manifestJSON = readJSON(path.join(root, directory, "package.json"));
+ } catch (error) {
+ if (error?.code === "ENOENT") continue;
+ throw error;
+ }
+ const dependencies = Object.entries({
+ ...manifestJSON.dependencies,
+ ...manifestJSON.devDependencies,
+ })
+ .filter(([, version]) => String(version).startsWith("workspace:"))
+ .map(([name]) => name);
+ packages[manifestJSON.name] = { directory, dependencies };
+ }
+ return packages;
+}
+
+// Directories of the given package directories and all their transitive
+// workspace dependencies.
+export function workspaceClosure(directories, workspace) {
+ const byDirectory = new Map(
+ Object.entries(workspace).map(([name, entry]) => [entry.directory, name]),
+ );
+ const seen = new Set();
+ const pending = directories.map((directory) => {
+ const name = byDirectory.get(directory);
+ if (!name) throw new Error(`${directory} is not a workspace package`);
+ return name;
+ });
+ while (pending.length > 0) {
+ const name = pending.pop();
+ if (seen.has(name)) continue;
+ const entry = workspace[name];
+ if (!entry) throw new Error(`unknown workspace package ${name}`);
+ seen.add(name);
+ pending.push(...entry.dependencies);
+ }
+ return [...seen].map((name) => workspace[name].directory).sort();
+}
+
+function targetPrefixes(entry, workspace) {
+ const packageDirectories = entry.packages
+ ? workspaceClosure(entry.packages, workspace)
+ : [];
+ return [
+ ...packageDirectories.map((directory) => `${directory}/`),
+ ...(entry.paths ?? []),
+ ];
+}
+
+// Returns { all, reason, selected: [{ target, ci, lane, match }], skipped }.
+// `changed` is a list of repository-relative paths or the string "ALL".
+export function planChecks(changed, workspace) {
+ const everything = (reason) => ({
+ all: true,
+ reason,
+ selected: TARGETS.map((entry) => ({ ...entry, match: reason })),
+ skipped: [],
+ });
+ if (changed === "ALL") return everything("all checks requested");
+ const files = changed.filter((file) => file !== "");
+ const global = files.find((file) =>
+ EVERYTHING_PATHS.some((prefix) => file.startsWith(prefix)),
+ );
+ if (global) return everything(global);
+ const selected = [];
+ const skipped = [];
+ for (const entry of TARGETS) {
+ if (entry.always) {
+ selected.push({ ...entry, match: "always" });
+ continue;
+ }
+ const prefixes = targetPrefixes(entry, workspace);
+ const match = files.find((file) =>
+ prefixes.some((prefix) => file.startsWith(prefix)),
+ );
+ if (match) selected.push({ ...entry, match });
+ else skipped.push(entry);
+ }
+ return { all: false, reason: undefined, selected, skipped };
+}
+
+// Every path changed since the merge base of BASE and HEAD: commits, staged
+// and unstaged edits, deletions, and untracked files that are not ignored.
+export function changedSinceBase(base, git) {
+ const mergeBase = git(["merge-base", `${base}^{commit}`, "HEAD"]).trim();
+ if (!mergeBase) throw new Error(`no merge base for ${base}`);
+ const diff = git(["diff", "-z", "--name-only", "--no-renames", mergeBase]);
+ const untracked = git(["ls-files", "-z", "--others", "--exclude-standard"]);
+ return [...diff.split("\0"), ...untracked.split("\0")].filter(Boolean);
+}
+
+// Plans from git; any git or workspace error selects every check.
+export function planFromBase(base, { git, workspace }) {
+ try {
+ return planChecks(changedSinceBase(base, git), workspace());
+ } catch (error) {
+ return {
+ ...planChecks("ALL", {}),
+ reason: `could not compute changes (${String(error.message).trim()})`,
+ };
+ }
+}
+
+export function planFromList(text, workspace) {
+ const lines = text.split("\n").map((line) => line.trim());
+ if (lines.includes("ALL")) return planChecks("ALL", {});
+ try {
+ return planChecks(lines, workspace());
+ } catch (error) {
+ return {
+ ...planChecks("ALL", {}),
+ reason: `could not compute changes (${String(error.message).trim()})`,
+ };
+ }
+}
+
+export function formatPlan(plan, format) {
+ const local = (entries) => entries.filter((entry) => entry.local !== false);
+ switch (format) {
+ case "make":
+ return local(plan.selected)
+ .map((entry) => entry.target)
+ .join(" ");
+ case "scope":
+ return plan.all ? "all" : "changed";
+ case "github": {
+ const selected = new Set(plan.selected.map((entry) => entry.ci));
+ return CI_KEYS.map((key) => `${key}=${selected.has(key)}`).join("\n");
+ }
+ case "human": {
+ const lines = [];
+ if (plan.all) {
+ lines.push(`Check plan: every check (${plan.reason})`);
+ for (const entry of local(plan.selected)) {
+ lines.push(` run ${entry.target}`);
+ }
+ return lines.join("\n");
+ }
+ lines.push("Check plan:");
+ for (const entry of local(plan.selected)) {
+ lines.push(` run ${entry.target.padEnd(24)} ${entry.match}`);
+ }
+ for (const entry of local(plan.skipped)) {
+ lines.push(` skip ${entry.target}`);
+ }
+ lines.push("Run every check with ALL=1.");
+ return lines.join("\n");
+ }
+ default:
+ throw new Error(`unknown format ${format}`);
+ }
+}
+
+function parseArguments(argv) {
+ const options = { format: "human" };
+ for (let index = 0; index < argv.length; index += 1) {
+ const argument = argv[index];
+ const value = () => {
+ index += 1;
+ if (index >= argv.length) throw new Error(`${argument} needs a value`);
+ return argv[index];
+ };
+ if (argument === "--base") options.base = value();
+ else if (argument === "--files-from") options.filesFrom = value();
+ else if (argument === "--format") options.format = value();
+ else if (argument === "--all") options.all = true;
+ else throw new Error(`unknown argument ${argument}`);
+ }
+ if (options.filesFrom !== undefined && options.filesFrom !== "-") {
+ throw new Error("--files-from supports only - (stdin)");
+ }
+ if (
+ !options.all &&
+ (options.base === undefined) === (options.filesFrom === undefined)
+ ) {
+ throw new Error(
+ "pass exactly one of --base <ref>, --files-from - or --all",
+ );
+ }
+ return options;
+}
+
+function main() {
+ let options;
+ try {
+ options = parseArguments(process.argv.slice(2));
+ } catch (error) {
+ console.error(
+ `${error.message}\nUsage: node scripts/check-plan.mjs (--base <ref> | --files-from - | --all) [--format human|make|github|scope]`,
+ );
+ process.exit(2);
+ }
+ const git = (args) =>
+ execFileSync("git", args, {
+ cwd: repositoryRoot,
+ encoding: "utf8",
+ stdio: ["ignore", "pipe", "pipe"],
+ maxBuffer: 64 * 1024 * 1024,
+ });
+ const workspace = () => readWorkspace(repositoryRoot);
+ let plan;
+ if (options.all) plan = planChecks("ALL", {});
+ else if (options.base !== undefined) {
+ plan = planFromBase(options.base, { git, workspace });
+ } else {
+ plan = planFromList(readFileSync(0, "utf8"), workspace);
+ }
+ if (plan.all && plan.reason?.startsWith("could not")) {
+ console.error(`check-plan: ${plan.reason}; selecting every check`);
+ }
+ console.log(formatPlan(plan, options.format));
+}
+
+if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) main();
diff --git a/scripts/check-plan.test.ts b/scripts/check-plan.test.ts
new file mode 100644
index 00000000..768e53e0
--- /dev/null
+++ b/scripts/check-plan.test.ts
@@ -0,0 +1,288 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ CI_KEYS,
+ EVERYTHING_PATHS,
+ formatPlan,
+ planChecks,
+ planFromBase,
+ planFromList,
+ readWorkspace,
+} from "./check-plan.mjs";
+
+const workspace = readWorkspace();
+const local = (changed: string[] | "ALL") =>
+ formatPlan(planChecks(changed, workspace), "make").split(" ");
+const ci = (changed: string[]) =>
+ Object.fromEntries(
+ formatPlan(planChecks(changed, workspace), "github")
+ .split("\n")
+ .map((line) => line.split("=")),
+ );
+const allLocal = formatPlan(planChecks("ALL", {}), "make").split(" ");
+
+describe("CI outputs", () => {
+ // One path per alternative of the regexes the CI changes job used before
+ // it read this plan; each must still select its key.
+ const previousRegexExamples: Record<string, string[]> = {
+ web: [
+ "apps/web/src/main.tsx",
+ "packages/service-kit/src/index.ts",
+ "contracts/generated/typescript/src/index.ts",
+ ],
+ packages: [
+ "packages/document-model/src/index.ts",
+ "contracts/generated/typescript/src/index.ts",
+ "contracts/fixtures/example.json",
+ ],
+ "teamhub-cli": [
+ "apps/teamhub-cli/src/main.ts",
+ "packages/service-kit/src/index.ts",
+ "contracts/openapi/teamhub-agent-api/openapi.yaml",
+ ],
+ installer: [
+ "apps/linger-installer/src/main.ts",
+ "packages/local-installation/src/index.ts",
+ "contracts/generated/typescript/src/index.ts",
+ ],
+ desktop: [
+ "apps/desktop/src/main/index.ts",
+ "apps/computer/local-daemon/go.mod",
+ "apps/computer/package.json",
+ "packages/local-installation/src/index.ts",
+ "contracts/generated/typescript/src/index.ts",
+ ],
+ contracts: ["contracts/openapi/components/example.yaml"],
+ teamhub: [
+ "apps/teamhub/internal/app/app.go",
+ "skills/builtin/catalog.yaml",
+ "contracts/generated/go/teamhub/types.go",
+ "contracts/fixtures/example.json",
+ ".golangci.yml",
+ "Makefile",
+ ".github/workflows/ci.yml",
+ ],
+ "computer-go": [
+ "apps/computer/local-daemon/internal/daemon/daemon.go",
+ "apps/computer/run-test.sh",
+ "contracts/generated/go/runnergateway/types.go",
+ "contracts/runner-gateway/fixtures/example.json",
+ "scripts/managed-tools-install.mjs",
+ "scripts/local-computer-node-distributions.mjs",
+ "scripts/test-fixtures/managed-tools-fixture.mjs",
+ "Makefile",
+ ".github/workflows/ci.yml",
+ ],
+ };
+ const nodeEverything = [
+ "package.json",
+ "pnpm-lock.yaml",
+ "pnpm-workspace.yaml",
+ ".npmrc",
+ ".node-version",
+ "patches/example.patch",
+ "eslint.config.mjs",
+ "tsconfig.base.json",
+ "vitest.config.ts",
+ "Makefile",
+ ".github/actions/setup/action.yml",
+ ];
+ const nodeKeys = [
+ "web",
+ "packages",
+ "teamhub-cli",
+ "installer",
+ "desktop",
+ "contracts",
+ ];
+
+ it("lists the CI output keys", () => {
+ expect([...CI_KEYS].sort()).toEqual(
+ [...nodeKeys, "teamhub", "computer-go"].sort(),
+ );
+ });
+
+ for (const [key, paths] of Object.entries(previousRegexExamples)) {
+ for (const file of paths) {
+ it(`${file} selects ${key}`, () => {
+ expect(ci([file])[key]).toBe("true");
+ });
+ }
+ }
+
+ for (const file of nodeEverything) {
+ it(`${file} selects every Node key`, () => {
+ const outputs = ci([file]);
+ for (const key of nodeKeys) expect(outputs[key]).toBe("true");
+ });
+ }
+
+ it("selects nothing for an unrelated path", () => {
+ expect(Object.values(ci(["README.md"]))).toEqual(
+ CI_KEYS.map(() => "false"),
+ );
+ });
+
+ it("keeps a nested package.json out of the everything set", () => {
+ const outputs = ci(["apps/teamhub/package.json"]);
+ expect(outputs.teamhub).toBe("true");
+ expect(outputs.web).toBe("false");
+ });
+});
+
+describe("local plan", () => {
+ it("runs only TeamHub for a TeamHub change", () => {
+ expect(local(["apps/teamhub/internal/app/app.go"])).toEqual([
+ "check-repository",
+ "check-docs",
+ "check-teamhub",
+ ]);
+ });
+
+ it("follows workspace dependencies from packages/service-kit", () => {
+ expect(local(["packages/service-kit/src/index.ts"])).toEqual([
+ "check-repository",
+ "check-docs",
+ "check-packages",
+ "check-voice-runtime",
+ "check-teamhub-cli",
+ "check-installer",
+ "check-desktop",
+ "check-web",
+ "check-node-services",
+ "check-computer",
+ ]);
+ });
+
+ it("runs the Daemon process test for any Node Services change", () => {
+ expect(
+ local(["apps/node-services/src/agent/agent-features/compose.ts"]),
+ ).toEqual([
+ "check-repository",
+ "check-docs",
+ "check-node-services",
+ "check-computer",
+ ]);
+ });
+
+ it("runs check-packages and its dependents for packages/local-installation", () => {
+ expect(local(["packages/local-installation/src/index.ts"])).toEqual([
+ "check-repository",
+ "check-docs",
+ "check-packages",
+ "check-teamhub-cli",
+ "check-installer",
+ "check-desktop",
+ "check-scripts-fast",
+ "check-web",
+ ]);
+ });
+
+ it("includes the TeamHub CLI that Node Services depends on", () => {
+ expect(local(["apps/teamhub-cli/src/main.ts"])).toContain(
+ "check-node-services",
+ );
+ });
+
+ it("runs every check for each everything-set path", () => {
+ for (const prefix of EVERYTHING_PATHS) {
+ const file = prefix.endsWith("/") ? `${prefix}x` : prefix;
+ expect(local([file])).toEqual(allLocal);
+ expect(planChecks([file], workspace).all).toBe(true);
+ }
+ });
+
+ it("never runs the CI-only computer Go target locally", () => {
+ expect(allLocal).not.toContain("check-computer-go");
+ expect(local(["apps/computer/local-daemon/go.mod"])).toContain(
+ "check-computer",
+ );
+ });
+
+ it("plans a mixed change set", () => {
+ expect(
+ local([
+ "apps/web/src/x.ts",
+ "apps/node-services/src/agent/runner-gateway/y.ts",
+ "apps/computer/local-daemon/internal/daemon/z.go",
+ "apps/desktop/src/main/a.ts",
+ "packages/local-installation/src/b.ts",
+ ]),
+ ).toEqual([
+ "check-repository",
+ "check-docs",
+ "check-packages",
+ "check-teamhub-cli",
+ "check-installer",
+ "check-desktop",
+ "check-scripts-fast",
+ "check-web",
+ "check-node-services",
+ "check-computer",
+ ]);
+ });
+
+ it("runs only the always-on checks for a docs change", () => {
+ expect(local(["docs/index.md"])).toEqual([
+ "check-repository",
+ "check-docs",
+ ]);
+ });
+});
+
+describe("failures select every check", () => {
+ const failingGit = () => {
+ throw new Error("fatal: Not a valid object name nope");
+ };
+
+ it("on a git failure or unresolvable base", () => {
+ const plan = planFromBase("nope", {
+ git: failingGit,
+ workspace: () => workspace,
+ });
+ expect(plan.all).toBe(true);
+ expect(formatPlan(plan, "make").split(" ")).toEqual(allLocal);
+ expect(formatPlan(plan, "scope")).toBe("all");
+ });
+
+ it("on an empty merge base", () => {
+ const plan = planFromBase("main", {
+ git: () => "",
+ workspace: () => workspace,
+ });
+ expect(plan.all).toBe(true);
+ });
+
+ it("on an unreadable workspace", () => {
+ const plan = planFromList("apps/web/x.ts\n", () => {
+ throw new Error("ENOENT");
+ });
+ expect(plan.all).toBe(true);
+ });
+
+ it("for the literal ALL", () => {
+ expect(planFromList("ALL\n", () => workspace).all).toBe(true);
+ });
+
+ it("reads committed, uncommitted, deleted and untracked paths", () => {
+ const calls: string[][] = [];
+ const git = (args: string[]) => {
+ calls.push(args);
+ if (args[0] === "merge-base") return "abc\n";
+ if (args[0] === "diff")
+ return "apps/teamhub/a.go\0apps/teamhub/gone.go\0";
+ return "skills/new.md\0";
+ };
+ const plan = planFromBase("main", { git, workspace: () => workspace });
+ expect(calls[1]).toEqual([
+ "diff",
+ "-z",
+ "--name-only",
+ "--no-renames",
+ "abc",
+ ]);
+ expect(formatPlan(plan, "make")).toBe(
+ "check-repository check-docs check-teamhub",
+ );
+ });
+});
diff --git a/scripts/ci/check-changed-files.sh b/scripts/ci/check-changed-files.sh
new file mode 100755
index 00000000..509385bb
--- /dev/null
+++ b/scripts/ci/check-changed-files.sh
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# Formats, lints and checks the English-only rule on the files a change adds
+# or modifies. Published built-in Skill versions are immutable and never
+# reformatted.
+#
+# Usage: check-changed-files.sh <base> <head> diff two commits (the gate)
+# check-changed-files.sh <base> --worktree
+# diff the working tree, plus untracked files (local make check)
+
+if (($# != 2)); then
+ echo "Usage: $0 <base> (<head> | --worktree)" >&2
+ exit 2
+fi
+base=$1
+if [[ "$2" == --worktree ]]; then
+ list_changed() {
+ git -c core.quotePath=false diff -z --name-only --no-renames --diff-filter=ACMRT "$base"
+ git -c core.quotePath=false ls-files -z --others --exclude-standard
+ }
+else
+ head=$2
+ list_changed() {
+ git -c core.quotePath=false diff -z --name-only --no-renames --diff-filter=ACMRT "$base" "$head"
+ }
+fi
+
+prettier_files=()
+eslint_files=()
+changed_files=()
+while IFS= read -r -d '' file; do
+ [[ "$file" =~ ^skills/builtin/[^/]+/[^/]+/ ]] && continue
+ [[ -f "$file" ]] || continue
+ case "$file" in
+ *.cjs | *.css | *.html | *.js | *.json | *.jsonc | *.jsx | *.md | *.mdx | *.mjs | *.mts | *.scss | *.ts | *.tsx | *.yaml | *.yml)
+ prettier_files+=("$file")
+ ;;
+ esac
+ case "$file" in
+ *.cjs | *.cts | *.js | *.jsx | *.mjs | *.mts | *.ts | *.tsx) eslint_files+=("$file") ;;
+ esac
+ changed_files+=("$file")
+done < <(list_changed)
+if ((${#prettier_files[@]} > 0)); then
+ pnpm exec prettier --check "${prettier_files[@]}"
+fi
+if ((${#eslint_files[@]} > 0)); then
+ pnpm exec eslint "${eslint_files[@]}"
+fi
+
+# The repository is English-only. Only CJK ideographs are rejected, so tests
+# may still use kana, Hangul, and full-width punctuation as unspaced scripts.
+# git grep exits 1 when nothing matches; any other non-zero status is an error
+# (for example a git without PCRE), which must fail the check rather than pass
+# it. --untracked lets the local run see files not yet added.
+if ((${#changed_files[@]} > 0)); then
+ cjk_status=0
+ LC_ALL=C git grep --untracked -nIP '(*UTF)[\x{3400}-\x{4DBF}\x{4E00}-\x{9FFF}\x{F900}-\x{FAFF}]' -- "${changed_files[@]}" || cjk_status=$?
+ if ((cjk_status == 0)); then
+ echo "Changed files contain Chinese characters; the repository is English-only (see AGENTS.md)." >&2
+ exit 1
+ elif ((cjk_status != 1)); then
+ echo "The English-only check could not run (git grep exited $cjk_status)." >&2
+ exit 1
+ fi
+fi
diff --git a/scripts/ci/check-repository-gate.sh b/scripts/ci/check-repository-gate.sh
index 5b999881..29b7e697 100755
--- a/scripts/ci/check-repository-gate.sh
+++ b/scripts/ci/check-repository-gate.sh
@@ -36,45 +36,8 @@ fi
# Every variable runtime code reads is documented in .env.example or the inventory.
pnpm env:inventory:check
-# Format and lint the files this branch adds or changes. Published built-in
-# Skill versions are immutable and never reformatted.
-prettier_files=()
-eslint_files=()
-changed_files=()
-while IFS= read -r -d '' file; do
- [[ "$file" =~ ^skills/builtin/[^/]+/[^/]+/ ]] && continue
- [[ -f "$file" ]] || continue
- case "$file" in
- *.cjs | *.css | *.html | *.js | *.json | *.jsonc | *.jsx | *.md | *.mdx | *.mjs | *.mts | *.scss | *.ts | *.tsx | *.yaml | *.yml)
- prettier_files+=("$file")
- ;;
- esac
- case "$file" in
- *.cjs | *.cts | *.js | *.jsx | *.mjs | *.mts | *.ts | *.tsx) eslint_files+=("$file") ;;
- esac
- changed_files+=("$file")
-done < <(git -c core.quotePath=false diff -z --name-only --no-renames --diff-filter=ACMRT "$base" "$head_sha")
-if ((${#prettier_files[@]} > 0)); then
- pnpm exec prettier --check "${prettier_files[@]}"
-fi
-if ((${#eslint_files[@]} > 0)); then
- pnpm exec eslint "${eslint_files[@]}"
-fi
-
-# The repository is English-only. Only CJK ideographs are rejected, so tests
-# may still use kana, Hangul, and full-width punctuation as unspaced scripts.
-# git grep exits 1 when nothing matches; any other non-zero status is an error
-# (for example a git without PCRE), which must fail the gate rather than pass it.
-if ((${#changed_files[@]} > 0)); then
- cjk_status=0
- LC_ALL=C git grep -nIP '(*UTF)[\x{3400}-\x{4DBF}\x{4E00}-\x{9FFF}\x{F900}-\x{FAFF}]' -- "${changed_files[@]}" || cjk_status=$?
- if ((cjk_status == 0)); then
- echo "Changed files contain Chinese characters; the repository is English-only (see AGENTS.md)." >&2
- exit 1
- elif ((cjk_status != 1)); then
- echo "The English-only check could not run (git grep exited $cjk_status)." >&2
- exit 1
- fi
-fi
+# Format, lint and check the English-only rule on the files this branch adds
+# or changes.
+bash "$script_root/check-changed-files.sh" "$base" "$head_sha"
make check-scripts-fast check-docs