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-rule-recipe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@taskless/cli": patch
---

The `check` agent recipe (topic v12) now documents `--rule <id>`, which has existed since 0.11.3: it runs only the named rule, repeats (`--rule a --rule b`), and works with `--json` and `--summary`. For a large repository the recipe gives the order to use: `check --json --summary` to see which rules fired and how often, then `check --json --rule <id>` for one rule's findings, so an agent never has to read or filter every finding to see where one rule fired.
40 changes: 21 additions & 19 deletions packages/cli/src/agent/check.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Topic: check (CLI v%(CLI_VERSION)s / topic v11)
# Topic: check (CLI v%(CLI_VERSION)s / topic v12)

%(ONE_COMMAND_PER_CALL)s

Expand All @@ -22,6 +22,8 @@ in CI (diff-only scan), or after rule create/improve to validate.
- `--summary`: per-rule counts instead of every finding. With `--json`
it omits `results` and keeps `summary`, so the output stays small on
any repository. Use it when the question is "how many", not "where".
- `--rule <id>`: run only the named rule (its directory name);

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 flag entry documents the happy path for --rule <id> but not the refusal: per openspec/specs/cli-check/spec.md ("Requirement: Check restricts the run to named rules with --rule"), an id that names no rule directory under any engine is refused — check exits 1 and, under --json, reports the standardized error envelope with code RULE_NOT_FOUND naming the id (confirmed in packages/cli/src/rules/rule-filter.ts and wired through packages/cli/src/commands/check.ts).

That refusal isn't reflected anywhere else in this file either — the ## Errors table (lines 155-158) only lists SCAN_FAILED and INVALID_INPUT, and the ## Exit codes section's list of reasons for exit 1 (line 146) doesn't mention an unresolved --rule id. Every sibling recipe that can raise RULE_NOT_FOUND (delete-rule.md, improve-rule.md, recover-rule.md) lists it in its own Errors table, so this is the one place introducing --rule to the check recipe without the matching error row.

Given the 8 KiB default-output budget this file is already close to, a one-row addition to the Errors table (RULE_NOT_FOUND | unknown `--rule` id | re-check the directory name) would likely fit and bring this recipe in line with the others. Not blocking since the error message itself is self-explanatory, but worth considering before this ships as the only place --rule is documented.

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.

Added in 02bb444: a RULE_NOT_FOUND row in the Errors table, and an unknown --rule id in the exit-1 list. To stay under the 8 KiB default-output budget I tightened two Step 2 sentences without changing what they say. A test pins the new row.

repeatable. Works with `--json` and `--summary`.
- `--anonymous`: run only static rules; skip runtime rules.
- `--dangerously-run-scripts`: run runtime `check.ts` unverified.
- `--timeout <seconds>`: per-runtime-check wall-clock bound (default 10).
Expand Down Expand Up @@ -55,17 +57,15 @@ in CI (diff-only scan), or after rule create/improve to validate.
%(TASKLESS_CLI)s check --json src/foo.ts src/deleted.ts
```
Paths that don't exist on disk are skipped, so you can pass every
path `git diff` printed without pre-filtering. The skipped paths
are named in a notice (`notices` under `--json`), so a mistyped
path is visible rather than reading as clean.
path `git diff` printed without pre-filtering. Skipped paths are
named in `notices`, so a mistyped path does not read as clean.

Paths must be inside the project (the working directory, or
`--dir`). A path outside it, existing or not, is refused with
`INVALID_INPUT` and exit 1, and nothing is scanned. Run `check`
from the project that holds the files instead.
A path outside the project (the working directory, or `--dir`),
existing or not, is refused with `INVALID_INPUT` and nothing is
scanned.

When runtime rules were present but not run (e.g. logged out), the
JSON also carries `"skipped": [{ "rule": "<name>", "reason": "…" }]`
JSON carries `"skipped": [{ "rule": "<name>", "reason": "…" }]`
alongside `success`/`results`. Surface it so CI can tell that runtime
rules did not execute. It never affects the exit code on its own; an
accompanying `entitlement` with a non-empty `withheld` does (see
Expand Down Expand Up @@ -111,11 +111,11 @@ in CI (diff-only scan), or after rule create/improve to validate.
only rules that fired, most findings first, keyed by `engine` and
`ruleId` as `verify` keys `rules[]`.

**To measure a whole repository, add `--summary`.** `results` can run
to hundreds of kilobytes; `check --json --summary` returns only
`summary`, one entry per rule that fired. Do not count `results`
yourself, and do not read an absent `results` as clean: read
`summary.total`.
**On a large repository, run `check --json --summary` first** to see
which rules fired, then `check --json --rule <id>` for one rule's
findings, since `results` can run to hundreds of kilobytes. Do not
count `results` yourself, and do not read an absent `results` as
clean: read `summary.total`.

4. **Report findings to the user.** Group by `file`. Show `severity`,
`message`, and `ruleId` for each finding; the `range.start` is the
Expand Down Expand Up @@ -144,16 +144,18 @@ in CI (diff-only scan), or after rule create/improve to validate.
- `1`: Errors detected, scan failed, runtime rules withheld because
the plan does not include them, an issued ast-grep or Vale rule was
edited or copied under a new id, a rule was unaccounted for, two
engines share a rule id, or a supplied path is outside the project
engines share a rule id, a supplied path is outside the project, or a
`--rule` id names no rule

## Errors

When `--json` is set, failures emit `{ ok: false, code, message }`:

| code | meaning | fix |
|-----------------|-------------------------------|-------------------------------------------|
| `SCAN_FAILED` | ast-grep scan errored | Report; check rule YAML validity |
| `INVALID_INPUT` | a path is outside the project | Run from the project that holds the files |
| code | meaning | fix |
|------------------|-------------------------------|-------------------------------------------|
| `SCAN_FAILED` | ast-grep scan errored | Report; check rule YAML validity |
| `INVALID_INPUT` | a path is outside the project | Run from the project that holds the files |
| `RULE_NOT_FOUND` | a `--rule` id names no rule | Use the rule's directory name |

<!-- on-demand -->
## What runs
Expand Down
35 changes: 35 additions & 0 deletions packages/cli/test/check-recipe.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";

import { getRecipe } from "../src/prompts/recipes";

const check = getRecipe("check");
if (check === undefined) throw new Error("no recipe for check");

describe("the check recipe", () => {
it("is topic v12", () => {
expect(check).toMatch(/^# Topic: check {5}\(CLI v.+ \/ topic v12\)/m);
});

it("lists --rule among its flags", () => {
const flags = check.slice(
check.indexOf("## Flags"),
check.indexOf("## Steps")
);
expect(flags).toContain("- `--rule <id>`:");
expect(flags).toContain("repeatable");
});

it("orders a large repository as summary first, then one rule", () => {
const summary = check.indexOf("run `check --json --summary` first");
const rule = check.indexOf("`check --json --rule <id>`");
expect(summary).toBeGreaterThan(-1);
expect(rule).toBeGreaterThan(summary);
});

it("lists RULE_NOT_FOUND for an unknown --rule id", () => {
const errors = check.slice(check.indexOf("## Errors"));
expect(errors).toContain(
"| `RULE_NOT_FOUND` | a `--rule` id names no rule"
);
});
});