Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/check-diff-scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@taskless/cli": patch
---

`check --diff` scopes a check to the files a unified diff changes. Pipe one in (`git diff --staged | taskless check --diff`), or name a file with `--diff=<file>`; the value only ever follows `=`, so `check --diff src/a.ts` reads `src/a.ts` as a path and refuses the pair. Every file the diff adds or modifies is checked whole, including lines it did not change. Deleted files are skipped, and files under `.taskless/` or `.git/` are never checked from a diff, so a change that only adds a rule no longer fails on the rule's own `tests/fail` fixtures. An empty diff exits 0 having checked nothing; input that is not a unified diff, a terminal on stdin, and a diff combined with paths are refused with `INVALID_INPUT`. The CLI runs no git: the `ci` and `hooks` recipes give the command that produces the diff (`git diff --no-ext-diff --no-color --relative ...`), replacing the `$(git diff --name-only ...)` expansion they used before.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-12-05
40 changes: 40 additions & 0 deletions openspec/changes/archive/2026-12-05-check-diff-scope/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Context

`check` takes positional paths (`classifyPaths` in `commands/check.ts`): missing paths are skipped with a notice, paths outside the project are refused, and the surviving list goes to all three engines through `scanProject`. ast-grep and Vale apply the `.taskless/**` and `.git/**` exclusions only on a whole-project walk (`isWholeProjectWalk`), on the principle that a path the caller named is a request. The runtime engine narrows with ast-grep over the same list. Engines read the working tree; the run snapshot holds only `.taskless/rules/`.

## Goals / Non-Goals

**Goals:**

- A diff in, the set of files it changes checked whole, with one exit code meaning the same as any other `check`.
- No git invocation, configuration, or repository assumption inside the CLI.
- Every way the input can fail to describe a change is an error or a named notice, never a silent clean run.

**Non-Goals:**

- Filtering findings to changed lines. Decided against: it would report a file clean that is not.
- Checking staged content when it differs from the working tree. The engines read the working tree; see Risks.
- Prefix styles other than one leading path component (`a/`, `b/`, `i/`, `w/`, `c/`). Producing a conforming diff is the integration's job, and the recipes give the canonical command.

## Decisions

**Read a diff, never run git.** The alternative, `--staged` and `--diff <ref>` flags that shell out to git, bakes one VCS's commands, configuration (`diff.external`, `color.ui`, `diff.noprefix`) and repository-shape assumptions (merge bases on shallow clones) into the deterministic side. A diff on stdin is the same text whatever produced it, and the parser is testable with fixture files and no repository. The Taskless service already holds each PR's diff, so the upkeep path needs no checkout to compute one.

**Parse file headers only.** With whole-file scope the hunks carry nothing `check` uses, so the parser reads only the per-file headers: `diff --git a/X b/Y`, `---`/`+++` lines, `rename to`, `new file mode`, `deleted file mode`, and `Binary files ... differ`. The changed path is the `+++` path with its first component stripped, falling back to the `diff --git` new-side path when there is no `+++` (binary, mode-only, pure rename). `+++ /dev/null` is a deletion and contributes no path. C-quoted paths (`"a/caf\303\251.md"`) are unquoted. A hand-written parser over a few line shapes, rather than a dependency: the existing parsers on npm parse hunks we would discard, and this repository's guidance is not to add a dependency for one call site.

**Unrecognized input is an error.** Input that is non-empty after trimming but contains no file header is refused with `INVALID_INPUT`. This is the case where a user's `diff.external` (difftastic, say) or forced color produced something that is not a unified diff; reading it as "no files changed" would be a green run that checked nothing, the defect #475 fixed for paths. Empty input is legitimate (nothing staged) and exits 0 with a notice.

**Diff paths go through the existing path pipeline, then the exclusions.** Parsed paths are classified exactly like positional paths (missing skipped and named, outside refused), then paths under `.taskless/` or `.git/` at any depth are dropped and named in one notice. The exclusion reuses the directory list ast-grep and Vale already use for a whole-project walk, so the three definitions of "not the user's code" cannot drift. Applying it here and not to positional paths keeps the existing rule intact: the caller did not name these paths, the diff did. If nothing survives, the run exits 0 like an all-missing path list does today, with the notices saying why.

**One flag whose value comes only from `=`.** `--diff` reads stdin; `--diff=<file>` reads a file. A flag with an optional value that could also take the next token would make `check --diff src/a.ts` ambiguous between a diff file and a positional path, since positional paths are how lint-staged, lefthook, pre-commit and existing CI pass files and cannot move behind a flag. Taking the value only from `=` is git's convention for optional values (`--color[=<when>]`, `--abbrev[=<n>]`) and removes the ambiguity: `--diff src/a.ts` is stdin plus a path, which is refused, so a caller who meant a file gets an error rather than a misreading. The shared argv scanner gains an optional-value class for this: it records `--diff=<file>` as a value and never consumes the token after a bare `--diff`. The alternative, two flags (`--diff` and `--diff-file <path>`), also works but spends a second name on one input. Required-value flags (`--rule`, `--timeout`, `--dir`) keep accepting both `--flag value` and `--flag=value`: they are never ambiguous, because they always take a value.

**Refuse a terminal stdin.** `--diff` with `process.stdin.isTTY` set is refused with `INVALID_INPUT` naming the piped form, instead of blocking on a read nobody will satisfy.

**Refuse `--diff` with positional paths.** Their intersection is a plausible feature, but nobody has asked for it, and silently preferring one source would check something other than what one of the two arguments said.

## Risks / Trade-offs

- [A partially staged file is checked as it is in the working tree] → The diff decides which files, the working tree decides their content, as with positional paths today. A commit can pass on an unstaged fix, or fail on an unstaged mistake. The `hooks` recipe keeps lint-staged (which hides unstaged changes) as the preferred route and states this for the piped form.
- [A monorepo diff is repo-root-relative while `check` runs in a package] → Without `--relative`, every path resolves under the package and is skipped as missing, giving exit 0 with a notice listing them. The recipes use `git diff --relative` from the package directory. The notice names every skipped path, so it is visible, but it does not fail the run, because an all-deletions diff produces the same input legitimately.
- [The upkeep PR's new rule is never exercised by its own diff check] → Intended: the PR changes no source file. The rule meets pre-existing code on the first full scan after merge, which is a policy question for upkeep itself (fix in the same PR, ship as a warning, or accept it), outside this change. The exclusion notice names the rule files, and `verify` remains the test of the rule.
- [Whole-file scope surfaces old findings in a touched file] → Intended, by decision: a changed file must be clean.
38 changes: 38 additions & 0 deletions openspec/changes/archive/2026-12-05-check-diff-scope/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Why

`check` can already scan a list of files, but a caller has to build that list with `$(git diff --name-only ...)`, which splits filenames on whitespace, turns an empty list into a full scan unless guarded, and passes every path as an explicit request. Explicit paths skip the whole-project exclusions, so a diff that touches `.taskless/` scans the rules' own `tests/fail/` fixtures. Measured on this repository: the files of `sg/no-eval` and `vale/no-em-dashes`, passed the way the CI recipe passes a diff, report 6 errors and exit 1, every one from a fixture written to fail. That is exactly the diff a Taskless upkeep PR produces (it adds a rule and nothing else), so the repository's own diff-scoped check goes red on the rule being added.

Three callers need "check what this change touches": a pre-commit hook over staged files, CI that judges incoming code, and the upkeep PRs. All three already hold a unified diff, or can produce one with a single command, so `check` should read one.

## What Changes

- `check --diff` reads a unified diff from stdin and checks every file the diff adds or modifies, **whole file**. Findings anywhere in a changed file are reported, including ones on lines the diff did not touch: a changed file must be clean to pass. There is no changed-lines mode, by decision: a narrowed result would report a file as clean when it is not.
- `check --diff=<file>` reads the diff from a file instead. The value is taken only from the `=` form, the way git spells its optional-value flags (`--color[=<when>]`), so `check --diff src/a.ts` is never read as a diff file.
- The CLI never runs git. The diff is plain text the caller supplies, so any tool that emits a unified diff with `a/`/`b/` prefixes works (git, jj, Mercurial, `gh pr diff`, a diff the Taskless service fetched from GitHub).
- Paths from a diff are chosen by the CLI rather than named by the caller, so the whole-project exclusions apply: paths under `.taskless/` and `.git/` are not checked, and are named in a notice.
- An empty diff exits 0 with a notice and checks nothing. Non-empty input that names no file is refused with `INVALID_INPUT` rather than reported clean. `--diff` with stdin attached to a terminal is refused rather than waiting for input. `--diff` combined with positional paths is refused.
- The `ci` and `hooks` recipes pipe a canonical diff command into `check --diff` (`git diff --no-ext-diff --no-color --relative ...`) instead of expanding a file list into the command line.
- Positional paths are unchanged: a path the caller names is still checked as named.

## Capabilities

### New Capabilities

(none)

### Modified Capabilities

- `cli-check`: adds diff-scoped checking (`--diff[=<file>]`), its input errors, and the exclusions a diff-derived file list is subject to.
- `cli-agent`: the `ci` recipe's diff scan becomes a piped `check --diff`; the `hooks` recipe gains the piped form for hook tools that do not supply a file list themselves.

## Delivery shape

**Single PR.** The parser, the flags, the recipes, and their tests are one reviewable diff, well under the stacking threshold, and none of it is correct without the rest: the recipes name a flag that only exists with the CLI change.

## Impact

- `packages/cli/src/commands/check.ts`: one new flag; the diff-derived path list feeds the existing path classification and scan.
- A new unified-diff file-list parser under `packages/cli/src/util/` (no new dependency).
- `packages/cli/src/agent/ci.md`, `packages/cli/src/agent/hooks.md`: recipe text and examples; topic versions bump.
- Tests for the parser, the command's input handling, and the fixture-exclusion case above.
- A `patch` changeset (the package is `0.y.z`; this adds surface and changes nothing a consumer must react to).
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## MODIFIED Requirements

### Requirement: The ci recipe runs the launcher with Node supplied by the job

The `ci` recipe SHALL generate CI configuration that runs `node .taskless/bin/cli.mjs check`, for a full scan, and, for a diff scan, pipes the pull request's diff into `node .taskless/bin/cli.mjs check --diff`, from the repository root. The diff command SHALL be `git diff --no-ext-diff --no-color --relative <base>...HEAD`, and the recipe SHALL NOT expand a file list into the `check` command line. It SHALL NOT generate a `npx`, `pnpm dlx`, `yarn dlx`, or `bunx` call to the CLI, and SHALL NOT ask the reader to choose a package manager launcher. It SHALL use `node <path>` rather than `./<path>`, since a CI checkout can lose the executable bit and a Windows runner does not honour a shebang.

The recipe SHALL require that the generated job make Node available itself, through the CI system's Node setup step or a Node container image, and SHALL say that the job does not need the project's own language toolchain or a `package.json`. It SHALL name the launcher's version source, `.taskless/taskless.json`, as what decides which CLI version CI runs, so an upgrade reaches CI through the same commit that updates `.taskless/`.

The recipe SHALL have the generated job cache `.taskless/.cache` between runs where the CI system supports a cache, with a key that includes the runner's operating system and a hash of `.taskless/bin/cli.lock.json`, so a restored cache never crosses platforms and an upgrade starts a fresh one.

#### Scenario: GitHub Actions template

- **WHEN** the `ci` recipe is rendered
- **THEN** its GitHub Actions template SHALL contain `node .taskless/bin/cli.mjs check`
- **AND** SHALL contain a Node setup step
- **AND** SHALL NOT contain `%(PACKAGE_MANAGER_DLX)s`

#### Scenario: A repository without package.json

- **WHEN** the `ci` recipe is followed in a repository with no `package.json`
- **THEN** the recipe SHALL direct the job to supply Node itself, and SHALL NOT tell the reader to add a `package.json`

#### Scenario: The launcher cache is restored between runs

- **WHEN** the `ci` recipe is rendered
- **THEN** its GitHub Actions template SHALL cache the path `.taskless/.cache`
- **AND** the cache key SHALL include `runner.os` and `hashFiles('.taskless/bin/cli.lock.json')`

#### Scenario: The diff scan pipes a diff

- **WHEN** the `ci` recipe is rendered
- **THEN** its diff scan SHALL pipe `git diff --no-ext-diff --no-color --relative` into `node .taskless/bin/cli.mjs check --diff`
- **AND** SHALL NOT contain `$(git diff` inside a `check` command line

## ADDED Requirements

### Requirement: The hooks recipe pipes the staged diff where the tool supplies no file list

For hook tools that do not pass staged filenames themselves (husky or simple-git-hooks without lint-staged), the `hooks` recipe SHALL generate `git diff --staged --no-ext-diff --no-color --relative | node .taskless/bin/cli.mjs check --diff`, and SHALL NOT build a file list in a shell variable. It SHALL state that `check` reads the working tree, so a file with unstaged edits is checked as it is on disk rather than as staged, and SHALL keep lint-staged as the recommended route where that matters.

#### Scenario: husky example

- **WHEN** the `hooks` recipe is rendered
- **THEN** its husky example SHALL pipe `git diff --staged` into `node .taskless/bin/cli.mjs check --diff`
- **AND** SHALL NOT contain `FILES=$(`
Loading