Skip to content

feat(check): scope a check to the files a unified diff changes with --diff[=<file>] - #741

Merged
aibex-agent[bot] merged 8 commits into
mainfrom
aibex/t_XcbmECzOScSutEMqfU9u79t9
Dec 6, 2026
Merged

aibex-agent[bot] merged 8 commits into
mainfrom
aibex/t_XcbmECzOScSutEMqfU9u79t9

Conversation

@aibex-agent

@aibex-agent aibex-agent Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

taskless check --diff reads a unified diff (stdin, or a file through --diff=<file>) and checks every file it adds or modifies, whole. The CLI never runs git.

Why: the old diff recipe expanded $(git diff --name-only ...) into the command line, and positional paths skip the .taskless/ exclusion. Measured here: the files of sg/no-eval and vale/no-em-dashes, passed that way, reported 6 errors and exit 1, all from the rules' own tests/fail fixtures. An upkeep PR that adds a rule produces exactly that diff, so it would have turned its own diff check red.

What landed:

  • src/util/unified-diff.ts: a header-only parser. Hunks are consumed by their line counts, so an added line reading +++ b/x is never a header. Handles a//b/ and mnemonic i//w/ prefixes, renames, binaries, deletions, C-quoted paths, and the tab git appends to a path with a space. Tested against fixtures git diff --staged wrote.
  • check --diff[=<file>]: the value comes only from = (a new optional-value class in the shared argv scanner), so check --diff src/a.ts reads the path as a path and refuses the pair. Diff paths go through the existing path classification, then skip .taskless/ and .git/, named in a notice. An empty diff exits 0. Refused with INVALID_INPUT: input with no file headers, a terminal on stdin, a diff with paths, an unreadable file.
  • Whole-file scope only, no changed-lines mode: a finding on an untouched line of a changed file is reported and fails the run.
  • Recipes: ci and hooks pipe git diff --no-ext-diff --no-color --relative ... into check --diff; check documents it in an on-demand section (the topic was at its 8 KiB budget). README updated.
  • Changeset patch: this adds surface and breaks no existing call. The =-only syntax for every value flag, the breaking part, is a separate change.

Verified: pnpm typecheck, pnpm lint, full suite (3501 passed), plus a real git diff --staged piped end to end, and the terminal-stdin refusal under a pseudo-terminal. Archived; the pre-archive scenario count shows no scenario dropped (cli-check 118 → 132, cli-agent 99 → 101).

@aibex-agent

aibex-agent Bot commented Dec 6, 2026

Copy link
Copy Markdown
Author

@claude /review

@github-actions github-actions Bot added the Open OpenSpec Contains unresolved OpenSpec changes. All openspec changes must eventually reach an archive state. label Dec 6, 2026
@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @aibex-agent[bot]'s task in 1m 15s —— View job


Review complete

  • Read .prior-review.json (no prior threads/reviews/comments found — this is the first review)
  • Fetch PR diff and metadata
  • Read changed files in full
  • Review for correctness, security, performance, test adequacy, clarity
  • Post inline comments for findings
  • Post final summary

Review mode: incremental — read 0 prior review thread(s) before reviewing. This is the first review of this PR; there is nothing previously raised to classify as addressed or still open.

Summary

This is a docs-only OpenSpec proposal (check-diff-scope): design, proposal, and two delta specs for a new check --diff[=<file>] flag, plus tasks. No implementation code is touched, so there's nothing to assess for runtime correctness/security/performance — the review here is of the spec's internal consistency and completeness as a basis for the implementation that follows.

The proposal and design are well-reasoned and consistent with each other: whole-file scope (no changed-lines mode), reading a diff rather than invoking git, the =-only optional-value flag convention, and the .taskless//.git/ exclusion applied only to diff-derived paths (not positional ones) all track through design.md → specs/cli-check/spec.md → specs/cli-agent/spec.md → tasks.md without contradiction. The parsing rules (new-side path from +++, fallback to diff --git header for binary/mode-only/pure-rename, /dev/null deletions dropped, C-quoted paths unquoted) are reflected consistently in both the design rationale and the spec requirements/scenarios.

[New] One concrete defect found: in openspec/changes/check-diff-scope/specs/cli-check/spec.md, the scenario "The token after a bare --diff is a path, not a diff file" is duplicated verbatim at lines 94-99 and again at lines 111-115 — the second copy is missing the **AND** SHALL NOT report the run as clean bullet that the first has. This looks like a copy-paste leftover from editing the "Check refuses diff input that cannot describe a change" requirement's scenario list. Flagged inline at lines 111-115.

No other inconsistencies, gaps, or ambiguities found in the delta specs, design doc, or tasks breakdown. Per the PR description, this draft intentionally carries only the proposal — implementation, changeset, and archive are meant to land before it leaves draft — so the above is the only item to clean up before that happens.

Review status: complete

Comment on lines +111 to +115
#### Scenario: The token after a bare --diff is a path, not a diff file

- **WHEN** a user runs `taskless check --diff change.patch` with a diff piped on stdin
- **THEN** `change.patch` SHALL be read as a positional path, not as the diff
- **AND** the CLI SHALL exit 1 with `INVALID_INPUT` because a diff and positional paths were given together

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[New] This "Scenario: The token after a bare --diff is a path, not a diff file" block duplicates the one at lines 94-99 verbatim (same WHEN/THEN), except it drops the final **AND** SHALL NOT report the run as clean bullet that the first copy has. Looks like a copy-paste leftover from editing — one of the two should be removed, and if the dropped bullet was an intentional edit, the surviving copy should keep it rather than silently losing it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e933a41. My edit had replaced a line that occurs twice, so the scenario was inserted twice and the first copy took the "SHALL NOT report the run as clean" clause from the scenario above it. The duplicate is gone and that clause is back on "Output that is not a unified diff".

@aibex-agent aibex-agent Bot changed the title docs(openspec): propose check --diff[=<file>] feat(check): scope a check to the files a unified diff changes with --diff[=<file>] Dec 6, 2026
@aibex-agent
aibex-agent Bot marked this pull request as ready for review December 6, 2026 00:41
@aibex-agent

aibex-agent Bot commented Dec 6, 2026

Copy link
Copy Markdown
Author

@claude /review

@github-actions github-actions Bot removed the Open OpenSpec Contains unresolved OpenSpec changes. All openspec changes must eventually reach an archive state. label Dec 6, 2026
@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @aibex-agent[bot]'s task in 5m 11s —— View job


Review complete

  • Read .prior-review.json
  • Fetch PR diff and metadata
  • Read changed files in full
  • Review for correctness, security, performance, test adequacy, clarity
  • Post inline comments for findings
  • Post final summary

Review mode: incremental — read 1 prior review thread(s) before reviewing. The one prior thread (duplicated "token after a bare --diff" scenario in specs/cli-check/spec.md) is neither marked isResolved nor carries the *— AI Coding Agent* marker, but the author's reply names the fixing commit (e933a41), and I verified directly against the current diff: the duplicate scenario and its missing **AND** SHALL NOT report the run as clean bullet are both gone from the final file (one occurrence of the scenario in each of the archived and main cli-check/spec.md, and the clause is back on "Output that is not a unified diff"). Treating it as addressed rather than re-raising it.

Summary

This PR implements check --diff[=<file>] end-to-end: a header-only unified-diff parser (util/unified-diff.ts), an optional-value-flag convention in the shared argv scanner (util/argv.ts), the flag itself in commands/check.ts, updated ci/hooks/check recipes, README, specs, changeset, and tests. The parser logic, hunk-counting (so an added line that happens to read +++ b/x is never mistaken for a header), C-quoted path decoding, prefix stripping, and the .taskless//.git/ exclusion applied only to diff-derived paths all check out against the fixtures and the stated design — I traced the parser by hand against git-default.diff/git-mnemonic.diff (renames, binaries, deletions, quoted/space-containing paths, the embedded fake +++ line) and it's correct.

Two concrete issues found, both [New]:

  1. packages/cli/src/commands/check.ts:458 — --diff=<file> resolves its path against process.cwd() instead of against the command's own cwd (resolve(args.dir ?? process.cwd())), unlike every positional path, which classifyPaths resolves against cwd. Combined with --dir, a relative --diff=<file> path resolves from the wrong base and the run is refused with INVALID_INPUT for a file that exists where the user meant it. Untested because check-diff.test.ts only exercises an absolute --diff=<file> path.

  2. packages/cli/src/agent/check.md:328 (new "Diff scope" section) — step 2's existing diff-scan example (lines 50-61, not touched by this PR) still tells the agent to run git diff --name-only and pass the resulting paths positionally — the exact pattern whose .taskless/-exclusion gap this PR was written to fix, per the PR's own "Why." tasks.md task 3.3 says to keep "the existing one-command-per-call path-list guidance," but the surviving text is the diff-specific example, which now contradicts the new --diff guidance a few sections below it in the same file.

No other correctness, security, or test-adequacy issues found. The argv-scanning changes (optional-value flags), the exclusion/notice plumbing, and the refusal ordering in check.ts all match the spec scenarios and are exercised by check-diff.test.ts and unified-diff.test.ts, including the real git diff --staged end-to-end case.

Review status: complete

Comment thread packages/cli/src/commands/check.ts Outdated
text =
diffSource.kind === "stdin"
? await readStdin()
: await readFile(resolve(diffSource.path), "utf8");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[New] resolve(diffSource.path) resolves against process.cwd(), not against the command's own cwd (resolve(args.dir ?? process.cwd()), line 365). Every other path this command reads — the positionals handled by classifyPaths — is resolved against that cwd (see classifyPaths(cwd, positionalPaths) → resolve(resolvedCwd, rawPath) at lines 116-129). --diff=<file> is the one path argument that skips it.

Concretely: taskless check --dir ../other-project --diff=patch.diff where patch.diff lives inside ../other-project resolves the file against the invoking shell's cwd instead of ../other-project, so it won't be found and the run is refused with INVALID_INPUT ("Could not read the diff from …") even though the file exists at the path the user reasonably meant. This isn't covered by check-diff.test.ts, which only exercises an already-absolute --diff=<file> path, so the mismatch doesn't surface there.

If relative-to-shell-cwd is the intended behavior (plausible, since the diff is often piped/redirected from the invoking shell rather than the project under --dir), it'd be worth a one-line comment saying so and a test pinning it; otherwise this should resolve against cwd like everything else.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 957578b. It now resolves against the project directory (--dir), the same way --from does in feedback and report, with a test that passes a relative --diff=change.patch together with --dir from another working directory.

`entitlement` with an empty `withheld` does not fail the run.

<!-- on-demand -->
## Diff scope

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[New] This new "Diff scope" section tells the agent to pipe a diff into check --diff, but step 2 above (lines 50-61, unedited by this PR) still says: "or, against a git diff: run git diff --name-only main...HEAD as its own call, then pass the paths it printed" into check --json src/foo.ts src/deleted.ts as positional arguments.

That's exactly the pattern this whole PR exists to move away from: per the PR description, positional paths from git diff --name-only don't get the .taskless/ exclusion this feature adds, so an upkeep PR that adds a rule (and lands its own tests/fail fixture) would turn its own diff check red if an agent follows the still-present step-2 guidance instead of the new --diff flag documented here. tasks.md (2026-12-05-check-diff-scope) task 3.3 explicitly calls for "keeping the existing one-command-per-call path-list guidance for agents" in this file, but the surviving text is the specific git diff --name-only-for-diff-scoping example, not just the general "pass a list of paths positionally" pattern — those are different things, and the recipe now recommends both for the same "check a diff" use case.

Worth updating step 2's diff bullet to point at --diff instead (or at least note that --diff is now the preferred way to scope to a diff, and that positional paths from a diff don't get the .taskless//.git/ exclusion).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 957578b. Step 2's diff bullet now has the agent run git diff --no-ext-diff --no-color main...HEAD as its own call, save the output to .taskless/.tmp-diff.patch (gitignored, like the other .tmp-* scratch files), and run check --json --diff=.taskless/.tmp-diff.patch, and it notes that --diff skips .taskless/ while a path list does not. Piping isn't an option for an agent under the one-command-per-call rule. The standing cli-agent scenario that required the --name-only path list is updated to match.

@aibex-agent
aibex-agent Bot merged commit 119fde7 into main Dec 6, 2026
8 checks passed
@aibex-agent
aibex-agent Bot deleted the aibex/t_XcbmECzOScSutEMqfU9u79t9 branch December 6, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant