@devries-cameron20 / t3code-1 / commits / 74541bab17
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(scripts): one command checks what the branch changed (#22767)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 02:23 UTC 74541bab17270c35f4418d4e543d85628632ed8f
6 files changed +156 -4
.github/scripts/ci-changes.cjs
+5 -1
@@ -5,6 +5,8 @@
5 // node ci-changes.cjs --paths <file> --full run every Linux job, gate only the macOS lint
6 // node ci-changes.cjs changed paths unknown: run everything
7 //
8 +// scripts/check-changed.ts requires the same decisions so local runs match CI.
9 +//
10 // Every changed path maps to workspace packages, which then pull in their
11 // dependents from package.json. A path this file does not recognize runs
12 // everything, so a new root file or directory can only cost minutes.
@@ -201,4 +203,6 @@ function main() {
203 for (const [key, value] of Object.entries(outputs)) console.log(`${key}=${value}`);
204 }
205
204 -main();
206 +module.exports = { readWorkspace, decide };
207 +
208 +if (require.main === module) main();
.github/scripts/ci-changes.d.cts new
+27
@@ -0,0 +1,27 @@
1 +interface WorkspacePackage {
2 + readonly name: string;
3 + readonly dir: string;
4 + readonly hasTest: boolean;
5 + readonly deps: ReadonlyArray<string>;
6 +}
7 +
8 +export function readWorkspace(): Array<WorkspacePackage>;
9 +
10 +export function decide(
11 + files: ReadonlyArray<string> | null,
12 + packages: ReadonlyArray<WorkspacePackage>,
13 + full: boolean,
14 +): {
15 + affected: Array<string>;
16 + outputs: {
17 + typecheck: boolean;
18 + build: boolean;
19 + test: boolean;
20 + test_packages: string;
21 + test_web: boolean;
22 + test_server: boolean;
23 + rust: boolean;
24 + release_smoke: boolean;
25 + mobile_native: boolean;
26 + };
27 +};
AGENTS.md
+3 -2
@@ -98,8 +98,9 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
98
99 ## Verifying
100
101 -- Smallest proof that the change works. `vp test run <files>` for the tests you touched (`-t "<name>"` in big files), `vp lint <files>`, and `vp run typecheck` in the package you changed. Not `npx tsc`; it is 3x slower than tsc-rs.
102 -- Run `vp run knip:check` (about 35 s) when you add, remove, or rename exports, files, or dependencies.
101 +- Before you push, run `vp run check:changed`. It runs CI checks for changed files: format, lint, tests beside changes, typecheck of affected packages and dependents, plus knip when files, exports, or dependencies change.
102 +- While you iterate, run `vp test run <files>`. For big files, add `-t "<name>"`.
103 +- Do not use `npx tsc`. Use `vp run typecheck`; it uses tsc-rs, which is 3x faster.
104 - Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.
105 - Test meaningful logic or observable behavior. Do not render components to static markup to assert props or attributes, or add tests that merely assert callback wiring or mirror the implementation.
106 - **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.
docs/operations/development.md
+8 -1
@@ -102,7 +102,14 @@ for the security model.
102
103 ## Checks
104
105 -Run checks for the files and packages you changed:
105 +`vp run check:changed` runs what CI runs for your branch's changes: format and lint of the
106 +changed files, `knip:check` when files, exports, or dependencies change, typecheck of the affected
107 +packages and their dependents, and the test files beside the changed files. It maps files to
108 +packages with [ci-changes.cjs](../../.github/scripts/ci-changes.cjs), as CI does. It compares
109 +against the merge base with `origin/main`, or a ref you pass. Tests that reach a changed file only
110 +through imports run in CI.
111 +
112 +While you iterate, run single checks:
113
114 ```sh
115 vp test run <files>
package.json
+1
@@ -26,6 +26,7 @@
26 "build:resource-monitor": "cargo build --locked --release --manifest-path native/resource-monitor/Cargo.toml",
27 "typecheck": "vp run -r --cache --concurrency-limit 4 typecheck",
28 "tc": "vp run -r --cache --concurrency-limit 4 typecheck",
29 + "check:changed": "node scripts/check-changed.ts",
30 "lint": "vp lint --report-unused-disable-directives",
31 "knip": "knip --preprocessor ./scripts/knip-schemas.ts",
32 "knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-grok --workspace packages/source-control-core --workspace packages/source-control-azure-devops --workspace packages/source-control-bitbucket --workspace packages/source-control-forgejo --workspace packages/source-control-gitcafe --workspace packages/source-control-github --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
scripts/check-changed.ts new
+112
@@ -0,0 +1,112 @@
1 +// @effect-diagnostics nodeBuiltinImport:off globalConsole:off
2 +// Runs locally what CI runs for this branch's changes: format and lint of the
3 +// changed files, knip, typecheck of the affected packages and their dependents,
4 +// and the test files beside the changed files.
5 +//
6 +// vp run check:changed compare against the merge base with origin/main
7 +// vp run check:changed <ref> compare against <ref>
8 +//
9 +// Uncommitted and untracked files count. The package mapping comes from
10 +// .github/scripts/ci-changes.cjs, so this typechecks what CI would typecheck.
11 +import * as NodeChildProcess from "node:child_process";
12 +import * as NodeFS from "node:fs";
13 +import * as NodePath from "node:path";
14 +import { decide, readWorkspace } from "../.github/scripts/ci-changes.cjs";
15 +
16 +const root = NodePath.resolve(import.meta.dirname, "..");
17 +const CODE = /\.[cm]?[jt]sx?$/;
18 +
19 +const git = (...args: Array<string>) =>
20 + NodeChildProcess.execFileSync("git", args, { cwd: root, encoding: "utf8" })
21 + .split("\n")
22 + .filter(Boolean);
23 +
24 +const base = process.argv[2] ?? git("merge-base", "HEAD", "origin/main")[0] ?? "origin/main";
25 +// --no-renames lists a rename as its old and new path, as CI does.
26 +const untracked = git("ls-files", "--others", "--exclude-standard");
27 +const files = [
28 + ...new Set([...git("diff", "--name-only", "--no-renames", base, "--"), ...untracked]),
29 +].sort();
30 +
31 +if (files.length === 0) {
32 + console.log(`check:changed: no changes since ${base.slice(0, 12)}.`);
33 + process.exit(0);
34 +}
35 +
36 +const present = files.filter((file) => NodeFS.existsSync(NodePath.join(root, file)));
37 +const code = present.filter((file) => CODE.test(file));
38 +const packages = readWorkspace();
39 +const { affected, outputs } = decide(files, packages, false);
40 +
41 +// Changed test files, and the test files beside a changed source file
42 +// (foo.ts -> foo.test.ts, foo.browser.test.tsx). Vitest's import-graph
43 +// `related` reaches most of a package: one leaf server file pulled in 252 of
44 +// 406 server test files and took 7 minutes. CI runs the rest.
45 +const TEST = /\.test\.[cm]?[jt]sx?$/;
46 +const tests = new Set(code.filter((file) => TEST.test(file)));
47 +for (const file of code) {
48 + const dir = NodePath.dirname(file);
49 + const prefix = `${NodePath.basename(file).replace(CODE, "")}.`;
50 + for (const entry of NodeFS.readdirSync(NodePath.join(root, dir))) {
51 + if (entry.startsWith(prefix) && TEST.test(entry)) tests.add(NodePath.join(dir, entry));
52 + }
53 +}
54 +
55 +// knip:check takes about 35 s and cannot be scoped to a package, so it runs
56 +// only when the change can leave a file, export, or dependency unused.
57 +const addedOrDeleted = new Set([
58 + ...git("diff", "--name-only", "--no-renames", "--diff-filter=AD", base, "--"),
59 + ...untracked,
60 +]);
61 +const changedExport =
62 + code.length > 0 &&
63 + git("diff", "--unified=0", base, "--", ...code).some((line) =>
64 + /^[+-](?!\+\+ |-- ).*\bexport\b/.test(line),
65 + );
66 +const runKnip =
67 + changedExport ||
68 + files.some(
69 + (file) =>
70 + (CODE.test(file) && addedOrDeleted.has(file)) ||
71 + NodePath.basename(file) === "package.json" ||
72 + file === "knip.jsonc",
73 + );
74 +
75 +const filters = (names: ReadonlyArray<string>) => names.flatMap((name) => ["--filter", name]);
76 +const steps = [
77 + present.length > 0 && {
78 + name: "format",
79 + args: ["fmt", "--check", "--no-error-on-unmatched-pattern", ...present],
80 + },
81 + code.length > 0 && { name: "lint", args: ["lint", ...code] },
82 + runKnip && { name: "knip", args: ["run", "knip:check"] },
83 + affected.length > 0 && {
84 + name: `typecheck (${affected.length} packages)`,
85 + args: ["run", "--cache", "--concurrency-limit", "4", ...filters(affected), "typecheck"],
86 + },
87 + // From the repo root, the root vite.config.ts hands each file to its package's config.
88 + tests.size > 0 && {
89 + name: `test (${tests.size} files)`,
90 + args: ["test", "run", "--passWithNoTests", ...tests],
91 + },
92 +].filter((step) => step !== false);
93 +
94 +console.log(`check:changed: ${files.length} files since ${base.slice(0, 12)}`);
95 +const results = steps.map((step) => {
96 + console.log(`\n> vp ${step.name}`);
97 + const started = performance.now();
98 + const { status } = NodeChildProcess.spawnSync("vp", step.args, { cwd: root, stdio: "inherit" });
99 + const seconds = ((performance.now() - started) / 1000).toFixed(1);
100 + return { name: step.name, ok: status === 0, seconds };
101 +});
102 +
103 +console.log("\ncheck:changed summary");
104 +for (const result of results) {
105 + console.log(` ${result.ok ? "pass" : "FAIL"} ${result.name} ${result.seconds}s`);
106 +}
107 +const ciOnly = (["build", "rust", "mobile_native", "release_smoke"] as const).filter(
108 + (job) => outputs[job],
109 +);
110 +if (ciOnly.length > 0) console.log(` CI also runs: ${ciOnly.join(", ")}`);
111 +if (!runKnip) console.log(" knip skipped: no files, exports, or dependencies changed");
112 +if (results.some((result) => !result.ok)) process.exit(1);