lintobot 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -3
- package/dist/cli.js +204 -167
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# lintobot
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/lintobot)
|
|
4
|
+
|
|
3
5
|
A code linter whose rules are plain-language sentences answered by a **decision model** (Jev and similar). No AST rules to write: you state what must be true of a file, the model says how sure it is that it isn't.
|
|
4
6
|
|
|
5
7
|
```
|
|
@@ -18,7 +20,38 @@ Reads or writes files on disk
|
|
|
18
20
|
|
|
19
21
|
❌ and ⚠️ are rules that look broken, ✅ rules that hold. The plain line under a file name lists observations that are true of it.
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
## What it is for
|
|
24
|
+
|
|
25
|
+
`lintobot.yml` is where you describe what good code is for you. Its rules are **intentions**, the code you would like to see, not laws.
|
|
26
|
+
|
|
27
|
+
- **Smarter than a linter, cheaper than an agent.** It can tell whether a comment matches the code under it, whether a function belongs in its file, whether a file is about one thing. It answers in a fraction of the time and cost of a subagent reading the same file.
|
|
28
|
+
- **Signals, not problems.** A finding is advice to look, not a call to action. Hand findings to an agent or a reviewer, who reads the code and decides whether there is anything to fix.
|
|
29
|
+
- **Not deterministic.** The answer is a probability; it can move a few points between runs. Results are not strict and should not be read as proof.
|
|
30
|
+
- **Flexible.** Every rule has its own thresholds. Lower `error` on a rule you want enforced hard, raise it or switch it off on one you only want to hear about. The exit code follows what you set.
|
|
31
|
+
- **Strict rules go to the real linter.** What must hold exactly and can be read from syntax ("all methods are private except perform") is better checked by RuboCop, ESLint or Biome. The `linto-lint` skill finds such rules in `lintobot.yml`, sets them up in the linter and comments them out.
|
|
32
|
+
|
|
33
|
+
Start every code file with a few basic checks and add your own intentions on top:
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
rules:
|
|
37
|
+
- "no duplicated code"
|
|
38
|
+
- "no magic numbers"
|
|
39
|
+
- "no comments that restate the code"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
If the project has a `CLAUDE.md` or `AGENTS.md`, the intentions are already written down. The `lintobot` skill (`lintobot skill --install`) tells an agent to read them and turn every statement about how the code should look into a rule.
|
|
43
|
+
|
|
44
|
+
It pairs well with a coding agent: run it from a hook after the agent edits a file, or on a pull request over the changed files, and give the output to the agent as things to review.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
lintobot --diff # what changed since the last commit: after an agent's edits
|
|
48
|
+
lintobot --diff origin/main # what this branch changes: on a pull request
|
|
49
|
+
lintobot --staged # what is staged: in a pre-commit hook
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Only changed files that the config's patterns match are checked, deleted ones are left out, and no change means no file is checked. See [Changed files only](#changed-files-only).
|
|
53
|
+
|
|
54
|
+
> Early version. Yes/no rules, formulas, file facts, context and large-file handling work. Composition rules, checking only the changed lines of a file, and calibration are specified in [SPEC.md](SPEC.md) but not built yet.
|
|
22
55
|
|
|
23
56
|
## Install
|
|
24
57
|
|
|
@@ -204,6 +237,8 @@ lintobot [files...] files, folders or globs; everything in lintobot.yml w
|
|
|
204
237
|
-o, --output <file>
|
|
205
238
|
--files <path> relative to the project; repeatable
|
|
206
239
|
--rule <id or sentence> a rule or an info item; repeatable
|
|
240
|
+
--diff [ref] only changed files: since the branch left <ref>, or since the last commit
|
|
241
|
+
--staged only files staged for the next commit
|
|
207
242
|
--dry-run
|
|
208
243
|
--quiet problems only
|
|
209
244
|
--no-cache answers are cached in .lintobot/cache/
|
|
@@ -230,10 +265,23 @@ Naming a folder or file narrows the run to the files in it that the config's pat
|
|
|
230
265
|
|
|
231
266
|
Exit codes: `0` clean · `1` errors · `2` bad usage or config · `3` model unreachable or checks skipped.
|
|
232
267
|
|
|
268
|
+
### Changed files only
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
lintobot --diff # edited, staged and new untracked files since the last commit
|
|
272
|
+
lintobot --diff origin/main # everything since this branch left origin/main, uncommitted work included
|
|
273
|
+
lintobot --staged # what `git commit` would take
|
|
274
|
+
lintobot app/jobs --diff main # changed files inside one folder
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
The ref is a branch, tag or commit. The changed files are narrowed by the config's patterns and by any paths you name; deleted files are left out; a whole changed file is checked, not only its changed lines. When nothing changed, nothing is checked and the exit code is `0`. It works from any folder of the repository, and when the project is a subfolder of it.
|
|
278
|
+
|
|
279
|
+
`--diff <ref>` needs the commit where the branch left the ref. A shallow clone does not have it: in GitHub Actions set `fetch-depth: 0` on the checkout step.
|
|
280
|
+
|
|
233
281
|
## What to expect from the model
|
|
234
282
|
|
|
235
283
|
- It returns probabilities only: no explanation, no line. The area of a large file is the closest it gets.
|
|
236
|
-
- Answers are
|
|
284
|
+
- Answers are not deterministic: close between runs (a few points) but not identical, and not calibrated: vague rules such as "no magic numbers" fire on most files until given `criteria`. Treat thresholds as something to tune on your own code.
|
|
237
285
|
- Code is sent to the provider you chose. `--dry-run` lists exactly which files.
|
|
238
286
|
|
|
239
287
|
## Development
|
|
@@ -249,4 +297,6 @@ bunosh probe <file> # five questions about one file, raw probabilities
|
|
|
249
297
|
|
|
250
298
|
### Releasing
|
|
251
299
|
|
|
252
|
-
Publish a GitHub release with a tag such as `v0.2.0`. The `Release to npm` workflow takes the version from the tag, runs the type check, the tests and the build, and publishes to npm (a pre-release goes to the `next` tag).
|
|
300
|
+
Publish a GitHub release with a tag such as `v0.2.0`. The `Release to npm` workflow takes the version from the tag, runs the type check, the tests and the build, and publishes to npm with provenance (a pre-release goes to the `next` tag).
|
|
301
|
+
|
|
302
|
+
No npm token is stored. The workflow uses npm trusted publishing: on npmjs.com the package lists this repository and the workflow file `release.yml` as its trusted publisher.
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Command, CommanderError } from "commander";
|
|
|
7
7
|
// package.json
|
|
8
8
|
var package_default = {
|
|
9
9
|
name: "lintobot",
|
|
10
|
-
version: "0.
|
|
10
|
+
version: "0.2.0",
|
|
11
11
|
description: "AI code linter: rules are plain-language sentences answered by a decision model (Jev)",
|
|
12
12
|
keywords: [
|
|
13
13
|
"lint",
|
|
@@ -387,7 +387,7 @@ function withSchema(text) {
|
|
|
387
387
|
const document = YAML.parseDocument(text);
|
|
388
388
|
const edits = [];
|
|
389
389
|
const files = isMap2(document.contents) ? document.contents.get("files", true) : undefined;
|
|
390
|
-
const lists = (isSeq(files) ? files.items : []).flatMap((
|
|
390
|
+
const lists = (isSeq(files) ? files.items : []).flatMap((entry) => isMap2(entry) ? [entry.get("rules", true), entry.get("info", true)] : []);
|
|
391
391
|
for (const list of lists) {
|
|
392
392
|
for (const item of isSeq(list) ? list.items : []) {
|
|
393
393
|
if (isScalar(item) && typeof item.value === "string" && item.range) {
|
|
@@ -444,7 +444,7 @@ var OWN_KEYS = ["$dsl", "model", "defaults", "ignore", "files", "parts", "contex
|
|
|
444
444
|
var COMPUTED = ["error", "warning", "error!", "warning!", "show", "show!", "$if!", "$unless!"];
|
|
445
445
|
var MIN_PART_LINES = 20;
|
|
446
446
|
var isMap3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
447
|
-
var itemsOf = (
|
|
447
|
+
var itemsOf = (entry) => [...entry.rules, ...entry.info];
|
|
448
448
|
var sentences = (value) => (value ?? "").split(/[\n;]/).map((item) => item.trim()).filter(Boolean);
|
|
449
449
|
function loadConfig(file, env = process.env) {
|
|
450
450
|
const explicit = file !== undefined;
|
|
@@ -498,7 +498,7 @@ function parseConfig(text, env = {}, file = CONFIG_FILE) {
|
|
|
498
498
|
} else if (data.files !== undefined) {
|
|
499
499
|
if (!Array.isArray(data.files))
|
|
500
500
|
throw new ConfigError(`${file}: files must be a list`);
|
|
501
|
-
config.entries = data.files.map((
|
|
501
|
+
config.entries = data.files.map((entry, n) => entryOf(entry, config, `${file}: files[${n + 1}]`));
|
|
502
502
|
} else {
|
|
503
503
|
config.entries = [implicit(rulesOf(YAML2.parse(RECOMMENDED), config, "lintobot/recommended"))];
|
|
504
504
|
}
|
|
@@ -570,10 +570,10 @@ function strings(value, where) {
|
|
|
570
570
|
throw new ConfigError(`${where} must be text or a list of texts`);
|
|
571
571
|
return list;
|
|
572
572
|
}
|
|
573
|
-
function entryOf(
|
|
574
|
-
if (!isMap3(
|
|
573
|
+
function entryOf(entry, config, where) {
|
|
574
|
+
if (!isMap3(entry))
|
|
575
575
|
throw new ConfigError(`${where} must be a map with pattern and rules`);
|
|
576
|
-
const { pattern, except, rules = [], info = [], context, max_lines, ...conditions } =
|
|
576
|
+
const { pattern, except, rules = [], info = [], context, max_lines, ...conditions } = entry;
|
|
577
577
|
const patterns = strings(pattern, `${where}.pattern`);
|
|
578
578
|
if (!patterns.length)
|
|
579
579
|
throw new ConfigError(`${where} needs a pattern`);
|
|
@@ -671,9 +671,9 @@ ${YAML2.stringify(placeholders)}`;
|
|
|
671
671
|
const rule = data.files?.[n - 1]?.[list]?.[i - 1];
|
|
672
672
|
return typeof rule === "string" ? rule : isMap3(rule) ? Object.keys(rule)[0] : undefined;
|
|
673
673
|
};
|
|
674
|
-
const named = (problem) => String(problem).replace(new RegExp(`files\\[(\\d+)\\]\\.(rules|info)\\[(\\d+)\\](\\.${RULE_KEY})?`), (
|
|
675
|
-
const
|
|
676
|
-
return
|
|
674
|
+
const named = (problem) => String(problem).replace(new RegExp(`files\\[(\\d+)\\]\\.(rules|info)\\[(\\d+)\\](\\.${RULE_KEY})?`), (path, n, list, i) => {
|
|
675
|
+
const text = sentence(Number(n), list, Number(i));
|
|
676
|
+
return text === undefined ? path : `"${text}"`;
|
|
677
677
|
}).replace(/"([^"]+)" is not a field of the schema$/, 'unknown key "$1"');
|
|
678
678
|
const errors = problems.filter((problem) => problem.severity === "error" || isUnknownField(problem));
|
|
679
679
|
if (errors.length)
|
|
@@ -687,10 +687,10 @@ function documentFor(config, entries, file, confidence) {
|
|
|
687
687
|
...config.top,
|
|
688
688
|
file: literal(file),
|
|
689
689
|
env: literal(config.env),
|
|
690
|
-
files: entries.map((
|
|
691
|
-
...
|
|
690
|
+
files: entries.map((entry, n) => ({
|
|
691
|
+
...entry.conditions,
|
|
692
692
|
n,
|
|
693
|
-
rules: itemsOf(
|
|
693
|
+
rules: itemsOf(entry).map((rule, i) => ({ [`r${i}`]: { ...rule.options, confidence: confidence(rule) } }))
|
|
694
694
|
}))
|
|
695
695
|
};
|
|
696
696
|
try {
|
|
@@ -718,8 +718,8 @@ ${named.map((line) => ` ${line}`).join(`
|
|
|
718
718
|
}
|
|
719
719
|
function inspectFormulas(config) {
|
|
720
720
|
const document = documentFor(config, config.entries, PLACEHOLDER_FACTS, () => 0);
|
|
721
|
-
config.entries.forEach((
|
|
722
|
-
itemsOf(
|
|
721
|
+
config.entries.forEach((entry, n) => {
|
|
722
|
+
itemsOf(entry).forEach((rule, i) => {
|
|
723
723
|
const loaded = document.data.files[n].rules[i][`r${i}`];
|
|
724
724
|
for (const key of ["$if", "$unless"]) {
|
|
725
725
|
if (loaded[key]?.reads.includes("confidence")) {
|
|
@@ -742,9 +742,9 @@ function matchesAny(globs, file) {
|
|
|
742
742
|
matchers.set(globs, matcher(globs));
|
|
743
743
|
return matchers.get(globs)(file);
|
|
744
744
|
}
|
|
745
|
-
var matches = (
|
|
745
|
+
var matches = (entry, file) => (!entry.patterns || matchesAny(entry.patterns, file)) && !matchesAny(entry.except, file);
|
|
746
746
|
function resolveRules(config, file, confidences) {
|
|
747
|
-
const entries = config.entries.filter((
|
|
747
|
+
const entries = config.entries.filter((entry) => matches(entry, file.path));
|
|
748
748
|
if (!entries.length)
|
|
749
749
|
return [];
|
|
750
750
|
let resolved;
|
|
@@ -754,13 +754,13 @@ function resolveRules(config, file, confidences) {
|
|
|
754
754
|
throw asConfigError(error, config);
|
|
755
755
|
}
|
|
756
756
|
const applied = new Map;
|
|
757
|
-
for (const
|
|
758
|
-
|
|
757
|
+
for (const entry of resolved.files) {
|
|
758
|
+
entry.rules.forEach((item, i) => {
|
|
759
759
|
const options = item[`r${i}`];
|
|
760
|
-
const rule = itemsOf(entries[
|
|
760
|
+
const rule = itemsOf(entries[entry.n])[i];
|
|
761
761
|
if (!options || matchesAny(rule.except, file.path))
|
|
762
762
|
return;
|
|
763
|
-
applied.set(`${rule.info}:${rule.sentence}`, { rule, entry: entries[
|
|
763
|
+
applied.set(`${rule.info}:${rule.sentence}`, { rule, entry: entries[entry.n], error: options.error, warning: options.warning, show: options.show });
|
|
764
764
|
});
|
|
765
765
|
}
|
|
766
766
|
return [...applied.values()];
|
|
@@ -806,7 +806,7 @@ var lineCount = (text) => text.split(`
|
|
|
806
806
|
`).length - (text.endsWith(`
|
|
807
807
|
`) ? 1 : 0);
|
|
808
808
|
function cutPieces(text, maxBytes, maxLines = Infinity) {
|
|
809
|
-
const fits = (
|
|
809
|
+
const fits = (size, lines) => size <= maxBytes && lines <= maxLines;
|
|
810
810
|
if (fits(cost(text), lineCount(text)))
|
|
811
811
|
return [text];
|
|
812
812
|
const blocks = [];
|
|
@@ -904,21 +904,21 @@ function fileVariables(file) {
|
|
|
904
904
|
function contextFor(file, config) {
|
|
905
905
|
const variables = fileVariables(file);
|
|
906
906
|
const read = new Map;
|
|
907
|
-
const textOf = (
|
|
908
|
-
if (!read.has(
|
|
909
|
-
read.set(
|
|
910
|
-
return read.get(
|
|
907
|
+
const textOf = (entry) => {
|
|
908
|
+
if (!read.has(entry))
|
|
909
|
+
read.set(entry, attempt(() => head(load(entry, variables, config), entry.maxBytes)));
|
|
910
|
+
return read.get(entry);
|
|
911
911
|
};
|
|
912
912
|
return ({ rule, entry: group }) => {
|
|
913
913
|
const merged = { ...config.context, ...group.context, ...rule.context };
|
|
914
914
|
const result = { sections: {} };
|
|
915
|
-
for (const [name,
|
|
916
|
-
if (!
|
|
915
|
+
for (const [name, entry] of Object.entries(merged)) {
|
|
916
|
+
if (!entry)
|
|
917
917
|
continue;
|
|
918
|
-
const text = textOf(
|
|
918
|
+
const text = textOf(entry);
|
|
919
919
|
if (typeof text === "string")
|
|
920
920
|
result.sections[name] = text;
|
|
921
|
-
else if (rule.context[name] ===
|
|
921
|
+
else if (rule.context[name] === entry)
|
|
922
922
|
result.missing ??= `context "${name}": ${text.message}`;
|
|
923
923
|
}
|
|
924
924
|
return result;
|
|
@@ -931,12 +931,12 @@ function attempt(read) {
|
|
|
931
931
|
return error;
|
|
932
932
|
}
|
|
933
933
|
}
|
|
934
|
-
function load(
|
|
935
|
-
if (
|
|
936
|
-
return
|
|
934
|
+
function load(entry, variables, config) {
|
|
935
|
+
if (entry.kind === "text")
|
|
936
|
+
return entry.source;
|
|
937
937
|
const folder = path5.dirname(config.file);
|
|
938
|
-
if (
|
|
939
|
-
const name =
|
|
938
|
+
if (entry.kind === "file") {
|
|
939
|
+
const name = entry.source.replace(/\$\{?(FILE|DIR|STEM|EXT)\b\}?/g, (_, variable) => variables[variable]);
|
|
940
940
|
const target = path5.resolve(folder, name);
|
|
941
941
|
if (!fs4.statSync(target, { throwIfNoEntry: false })?.isFile())
|
|
942
942
|
throw new Error(`no file ${name}`);
|
|
@@ -944,7 +944,7 @@ function load(entry2, variables, config) {
|
|
|
944
944
|
}
|
|
945
945
|
if (!config.shell)
|
|
946
946
|
throw new Error("commands are off (--no-shell)");
|
|
947
|
-
const ran = spawnSync(
|
|
947
|
+
const ran = spawnSync(entry.source, { shell: true, cwd: folder, env: { ...process.env, ...variables }, timeout: SHELL_TIMEOUT_MS, encoding: "utf8" });
|
|
948
948
|
if (ran.error)
|
|
949
949
|
throw new Error(`the command did not finish: ${ran.error.message}`);
|
|
950
950
|
if (ran.status !== 0)
|
|
@@ -990,12 +990,12 @@ function planFile(file, text, config, only = []) {
|
|
|
990
990
|
const applied = resolveRules(config, facts).filter(({ rule }) => !only.length || only.includes(rule.sentence) || rule.id !== undefined && only.includes(rule.id));
|
|
991
991
|
if (!applied.length)
|
|
992
992
|
return null;
|
|
993
|
-
const
|
|
993
|
+
const contextOf = contextFor(file, config);
|
|
994
994
|
const taken = new Set;
|
|
995
995
|
const unasked = [];
|
|
996
996
|
const groups = new Map;
|
|
997
997
|
for (const item of applied.filter(({ rule }) => rule.asksModel)) {
|
|
998
|
-
const { sections, missing } =
|
|
998
|
+
const { sections, missing } = contextOf(item);
|
|
999
999
|
if (missing) {
|
|
1000
1000
|
unasked.push({ applied: item, reason: missing });
|
|
1001
1001
|
continue;
|
|
@@ -1087,19 +1087,19 @@ No when: ${q.criteria.false}` : q.instructions
|
|
|
1087
1087
|
}
|
|
1088
1088
|
function parseResponse(target, data, keys) {
|
|
1089
1089
|
const answers = Object.fromEntries(keys.map((key) => [key, null]));
|
|
1090
|
-
const usage = (u,
|
|
1090
|
+
const usage = (u, cost) => ({
|
|
1091
1091
|
input_tokens: u?.input_tokens ?? 0,
|
|
1092
1092
|
output_tokens: u?.output_tokens ?? 0,
|
|
1093
|
-
...(u?.cost ??
|
|
1093
|
+
...(u?.cost ?? cost) !== undefined && { cost: u?.cost ?? cost }
|
|
1094
1094
|
});
|
|
1095
1095
|
if (target.wire === "typesafe") {
|
|
1096
|
-
const
|
|
1096
|
+
const body = typesafeResponse.parse(data);
|
|
1097
1097
|
for (const key of keys) {
|
|
1098
|
-
const answer = noul.safeParse(
|
|
1098
|
+
const answer = noul.safeParse(body.answers[key]);
|
|
1099
1099
|
if (answer.success)
|
|
1100
1100
|
answers[key] = answer.data.noul;
|
|
1101
1101
|
}
|
|
1102
|
-
return { answers, usage: usage(
|
|
1102
|
+
return { answers, usage: usage(body.usage), model: body.model ?? target.model };
|
|
1103
1103
|
}
|
|
1104
1104
|
const body = openaiResponse.parse(data);
|
|
1105
1105
|
for (const item of body.answers) {
|
|
@@ -1113,7 +1113,7 @@ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
1113
1113
|
function createClient(target, options = {}) {
|
|
1114
1114
|
const { retries = 3, backoffMs = 500, timeoutMs = 60000 } = options;
|
|
1115
1115
|
const send = options.fetch ?? fetch;
|
|
1116
|
-
async function
|
|
1116
|
+
async function attempt(body, keys) {
|
|
1117
1117
|
let response;
|
|
1118
1118
|
let text;
|
|
1119
1119
|
try {
|
|
@@ -1143,7 +1143,7 @@ function createClient(target, options = {}) {
|
|
|
1143
1143
|
const started = performance.now();
|
|
1144
1144
|
for (let tries = 0;; tries++) {
|
|
1145
1145
|
try {
|
|
1146
|
-
const result = await
|
|
1146
|
+
const result = await attempt(body, keys);
|
|
1147
1147
|
return { ...result, ms: Math.round(performance.now() - started) };
|
|
1148
1148
|
} catch (error) {
|
|
1149
1149
|
const status = error.status;
|
|
@@ -1251,8 +1251,8 @@ async function lint(files, engine, reporter) {
|
|
|
1251
1251
|
}
|
|
1252
1252
|
reporter.file(result);
|
|
1253
1253
|
}
|
|
1254
|
-
const
|
|
1255
|
-
const summary = { type: "summary", ...count, ...run.stats, ...
|
|
1254
|
+
const cost = run.stats.cost === undefined ? {} : { cost: Math.round(run.stats.cost * 1e6) / 1e6 };
|
|
1255
|
+
const summary = { type: "summary", ...count, ...run.stats, ...cost, ms: Math.round(performance.now() - started) };
|
|
1256
1256
|
reporter.end(summary);
|
|
1257
1257
|
return summary;
|
|
1258
1258
|
}
|
|
@@ -1263,7 +1263,7 @@ async function lintFile(file, run) {
|
|
|
1263
1263
|
const plan = planFile(file, text, run.config, run.only);
|
|
1264
1264
|
if (!plan)
|
|
1265
1265
|
return null;
|
|
1266
|
-
const tallies = new Map(plan.unasked.map(({ applied
|
|
1266
|
+
const tallies = new Map(plan.unasked.map(({ applied, reason }) => [applied.rule, { missing: reason, parts: [] }]));
|
|
1267
1267
|
await Promise.all(plan.calls.map((call) => ask(call, run, tallies)));
|
|
1268
1268
|
let applied = plan.applied;
|
|
1269
1269
|
if (applied.some(({ rule }) => rule.formulas.error || rule.formulas.warning || rule.formulas.show)) {
|
|
@@ -1375,6 +1375,58 @@ function areaThreshold(applied, defaults) {
|
|
|
1375
1375
|
return Math.min(defaults.warning, ...thresholds);
|
|
1376
1376
|
}
|
|
1377
1377
|
|
|
1378
|
+
// src/files/diff.ts
|
|
1379
|
+
import { execFileSync } from "node:child_process";
|
|
1380
|
+
|
|
1381
|
+
class GitError extends Error {
|
|
1382
|
+
hint;
|
|
1383
|
+
constructor(message, hint) {
|
|
1384
|
+
super(message);
|
|
1385
|
+
this.hint = hint;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
var MAX_OUTPUT_BYTES = 64 * 1024 * 1024;
|
|
1389
|
+
function git(args) {
|
|
1390
|
+
return execFileSync("git", args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: MAX_OUTPUT_BYTES });
|
|
1391
|
+
}
|
|
1392
|
+
var list = (output) => output.split("\x00").filter(Boolean);
|
|
1393
|
+
function isRevision(ref) {
|
|
1394
|
+
try {
|
|
1395
|
+
git(["rev-parse", "--verify", "--quiet", "--end-of-options", `${ref}^{commit}`]);
|
|
1396
|
+
return true;
|
|
1397
|
+
} catch {
|
|
1398
|
+
return false;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
function changedFiles(scope) {
|
|
1402
|
+
try {
|
|
1403
|
+
git(["rev-parse", "--is-inside-work-tree"]);
|
|
1404
|
+
} catch {
|
|
1405
|
+
throw new GitError("--diff and --staged need a git repository", "Run inside the repository, or name the files instead");
|
|
1406
|
+
}
|
|
1407
|
+
const names = ["diff", "--name-only", "-z", "--relative", "--diff-filter=d"];
|
|
1408
|
+
if (scope.staged)
|
|
1409
|
+
return list(git([...names, "--cached", "--"]));
|
|
1410
|
+
let base = "HEAD";
|
|
1411
|
+
if (scope.ref) {
|
|
1412
|
+
if (!isRevision(scope.ref))
|
|
1413
|
+
throw new GitError(`--diff: git does not know "${scope.ref}"`, "Give a branch, tag or commit, for example --diff origin/main");
|
|
1414
|
+
try {
|
|
1415
|
+
base = git(["merge-base", scope.ref, "HEAD"]).trim();
|
|
1416
|
+
} catch {
|
|
1417
|
+
throw new GitError(`--diff: no common history with "${scope.ref}"`, "A shallow clone hides it: fetch more history (git fetch --unshallow, or fetch-depth: 0 in CI)");
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
let tracked;
|
|
1421
|
+
try {
|
|
1422
|
+
tracked = list(git([...names, base, "--"]));
|
|
1423
|
+
} catch {
|
|
1424
|
+
tracked = list(git(["ls-files", "-z"]));
|
|
1425
|
+
}
|
|
1426
|
+
const untracked = list(git(["ls-files", "-z", "--others", "--exclude-standard"]));
|
|
1427
|
+
return [...new Set([...tracked, ...untracked])].sort();
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1378
1430
|
// src/model/providers.ts
|
|
1379
1431
|
var PROVIDERS = {
|
|
1380
1432
|
openrouter: { url: () => "https://openrouter.ai/api/alpha/decisions", key: "OPENROUTER_API_KEY", wire: "typesafe" },
|
|
@@ -1406,11 +1458,11 @@ function parseModel(value, env = process.env) {
|
|
|
1406
1458
|
}
|
|
1407
1459
|
|
|
1408
1460
|
// src/report/json.ts
|
|
1409
|
-
var isProblem = (
|
|
1461
|
+
var isProblem = (record) => record.type === "info" ? record.skipped === true : record.severity !== "ok";
|
|
1410
1462
|
var shown = (records, quiet) => quiet ? records.filter(isProblem) : records;
|
|
1411
1463
|
function jsonlReporter(write, options = {}) {
|
|
1412
1464
|
return {
|
|
1413
|
-
file: (result) => shown(result.records, options.quiet).forEach((
|
|
1465
|
+
file: (result) => shown(result.records, options.quiet).forEach((record) => write(`${JSON.stringify(record)}
|
|
1414
1466
|
`)),
|
|
1415
1467
|
end: (summary) => write(`${JSON.stringify(summary)}
|
|
1416
1468
|
`)
|
|
@@ -1434,37 +1486,37 @@ var percent = (confidence) => confidence === undefined ? "" : `${Math.round(conf
|
|
|
1434
1486
|
function prettyReporter(write, options = {}) {
|
|
1435
1487
|
const color = pc.createColors(options.color ?? false);
|
|
1436
1488
|
const row = (icon, label, value, paint = (text) => text) => ` ${icon} ${paint(label)}${value && value.padStart(Math.max(value.length + 2, COLUMN - label.length))}`;
|
|
1437
|
-
const place = (
|
|
1438
|
-
const noteLabel = (
|
|
1489
|
+
const place = (record) => record.areas?.length ? ` lines ${record.areas.map((area) => `${area.start}–${area.end}`).join(", ")}` : "";
|
|
1490
|
+
const noteLabel = (record) => record.id ? `${record.statement} (${record.id})` : record.statement;
|
|
1439
1491
|
function noteLine(records) {
|
|
1440
1492
|
const text = records.map(noteLabel).join(", ");
|
|
1441
1493
|
return text ? [color.dim(text[0].toUpperCase() + text.slice(1))] : [];
|
|
1442
1494
|
}
|
|
1443
|
-
function line(
|
|
1444
|
-
const label =
|
|
1445
|
-
const where = place(
|
|
1446
|
-
switch (
|
|
1495
|
+
function line(record) {
|
|
1496
|
+
const label = record.id ? `${record.rule} (${record.id})` : record.rule;
|
|
1497
|
+
const where = place(record);
|
|
1498
|
+
switch (record.severity) {
|
|
1447
1499
|
case "error":
|
|
1448
|
-
return row("❌", label, percent(
|
|
1500
|
+
return row("❌", label, percent(record.confidence), color.red) + where;
|
|
1449
1501
|
case "warning":
|
|
1450
|
-
return row("⚠️ ", label, percent(
|
|
1502
|
+
return row("⚠️ ", label, percent(record.confidence), color.yellow) + where;
|
|
1451
1503
|
case "skipped":
|
|
1452
|
-
return `${row("⏭️ ", label, "")} ${color.dim(`skipped: ${
|
|
1504
|
+
return `${row("⏭️ ", label, "")} ${color.dim(`skipped: ${record.reason}`)}`;
|
|
1453
1505
|
default:
|
|
1454
|
-
return row("✅", label,
|
|
1506
|
+
return row("✅", label, record.min === undefined ? "" : range(record.min, record.max ?? record.min));
|
|
1455
1507
|
}
|
|
1456
1508
|
}
|
|
1457
1509
|
return {
|
|
1458
1510
|
file({ file, lines, parts, records }) {
|
|
1459
|
-
const checks = records.filter((
|
|
1460
|
-
const info = records.filter((
|
|
1461
|
-
const notes = noteLine(info.filter((
|
|
1462
|
-
const skipped = info.filter((
|
|
1463
|
-
const clean = checks.every((
|
|
1511
|
+
const checks = records.filter((record) => record.type === "check");
|
|
1512
|
+
const info = records.filter((record) => record.type === "info");
|
|
1513
|
+
const notes = noteLine(info.filter((record) => record.shown && !record.skipped && !options.quiet));
|
|
1514
|
+
const skipped = info.filter((record) => record.skipped).map((record) => `${row("⏭️ ", noteLabel(record), "")} ${color.dim(`skipped: ${record.reason}`)}`);
|
|
1515
|
+
const clean = checks.every((record) => record.severity === "ok");
|
|
1464
1516
|
const collapsed = checks.length ? [` ✅ ${plural(checks.length, "rule")}`] : [];
|
|
1465
1517
|
const rows = [
|
|
1466
1518
|
...notes,
|
|
1467
|
-
...clean && parts === 1 ? options.quiet ? [] : collapsed : checks.filter((
|
|
1519
|
+
...clean && parts === 1 ? options.quiet ? [] : collapsed : checks.filter((record) => !options.quiet || record.severity !== "ok").map(line),
|
|
1468
1520
|
...skipped
|
|
1469
1521
|
];
|
|
1470
1522
|
if (!rows.length)
|
|
@@ -1532,11 +1584,11 @@ function reportPlan(plans, format, write) {
|
|
|
1532
1584
|
rules: call.planned.map((planned) => planned.applied.rule.sentence)
|
|
1533
1585
|
}))
|
|
1534
1586
|
}));
|
|
1535
|
-
const bytes = records.reduce((sum,
|
|
1587
|
+
const bytes = records.reduce((sum, record) => sum + record.bytes, 0);
|
|
1536
1588
|
const summary = {
|
|
1537
1589
|
type: "plan-summary",
|
|
1538
1590
|
files: records.length,
|
|
1539
|
-
calls: records.reduce((sum,
|
|
1591
|
+
calls: records.reduce((sum, record) => sum + record.calls, 0),
|
|
1540
1592
|
bytes,
|
|
1541
1593
|
tokens: Math.ceil(bytes / BYTES_PER_TOKEN)
|
|
1542
1594
|
};
|
|
@@ -1544,19 +1596,19 @@ function reportPlan(plans, format, write) {
|
|
|
1544
1596
|
return write(`${JSON.stringify({ plan: records, summary }, null, 2)}
|
|
1545
1597
|
`);
|
|
1546
1598
|
if (format === "jsonl")
|
|
1547
|
-
return [...records, summary].forEach((
|
|
1599
|
+
return [...records, summary].forEach((record) => write(`${JSON.stringify(record)}
|
|
1548
1600
|
`));
|
|
1549
|
-
for (const
|
|
1550
|
-
write(`${
|
|
1551
|
-
${plural2(
|
|
1601
|
+
for (const record of records) {
|
|
1602
|
+
write(`${record.file}
|
|
1603
|
+
${plural2(record.calls, "call")} · ${record.bytes} bytes
|
|
1552
1604
|
`);
|
|
1553
|
-
for (const call of
|
|
1605
|
+
for (const call of record.sent) {
|
|
1554
1606
|
const context = Object.entries(call.context).map(([name, size]) => `${name} ${size} bytes`).join(", ");
|
|
1555
1607
|
const where = call.lines ? `lines ${call.lines.start}–${call.lines.end}` : "whole file";
|
|
1556
1608
|
write(` ${where} · ${call.bytes} bytes · ${plural2(call.rules.length, "question")}${context && ` · context: ${context}`}
|
|
1557
1609
|
`);
|
|
1558
1610
|
}
|
|
1559
|
-
for (const rule of
|
|
1611
|
+
for (const rule of record.rules) {
|
|
1560
1612
|
const detail = "skipped" in rule ? `skipped: ${rule.skipped}` : ("question" in rule) ? rule.question : `formula: ${rule.formula}`;
|
|
1561
1613
|
write(` ${"info" in rule ? `info: ${rule.info}` : rule.rule}
|
|
1562
1614
|
${detail}
|
|
@@ -1572,126 +1624,87 @@ function reportPlan(plans, format, write) {
|
|
|
1572
1624
|
// src/skill/SKILL.md
|
|
1573
1625
|
var SKILL_default = `---
|
|
1574
1626
|
name: lintobot
|
|
1575
|
-
description:
|
|
1627
|
+
description: What lintobot is, how to treat its results and how to write its rules. Use when asked to run lintobot, read or act on its report, set it up in a project, or add or change a rule in lintobot.yml.
|
|
1576
1628
|
---
|
|
1577
1629
|
|
|
1578
1630
|
# lintobot
|
|
1579
1631
|
|
|
1580
|
-
|
|
1632
|
+
A linter whose rules are plain sentences: \`lintobot.yml\` describes what good code is for this project. For each file it asks a decision model whether a sentence holds and gets back only a probability: the **confidence that the rule is broken**, never an explanation or a line.
|
|
1581
1633
|
|
|
1582
|
-
##
|
|
1634
|
+
## What it is and is not
|
|
1583
1635
|
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
lintobot src --format jsonl # one JSON record per check (default when piped)
|
|
1590
|
-
\`\`\`
|
|
1591
|
-
|
|
1592
|
-
It needs \`LINTOBOT_MODEL\` (for example \`openrouter/typesafe/jev-1.14\`) and the provider's key (\`OPENROUTER_API_KEY\`), from the environment or a \`.env\` file in the working directory.
|
|
1636
|
+
- **Rules are intentions, not laws.** They say what the team would like to see in the code. A rule that must hold exactly and can be read from syntax belongs in the real linter: \`/linto-lint\` moves it there.
|
|
1637
|
+
- **Results are signals, not problems.** A finding is advice to look, never a call to action. Pass it to an agent or a person to review: read the code, judge it against the sentence, then fix it or dismiss it. Never fix code just to silence a finding.
|
|
1638
|
+
- **Not deterministic.** The same file can score a few points differently between runs, and the scores are not calibrated. Nothing here is strict.
|
|
1639
|
+
- **Between a linter and a subagent.** It checks what a linter cannot (does a comment match the code, does a function belong in this file, is the file about one thing) and is much faster and cheaper than a subagent reading the file.
|
|
1640
|
+
- **Flexible.** Each rule has its own thresholds: lower \`error\` to enforce a rule harder, raise it or set it to \`false\` to keep the rule as a quiet hint.
|
|
1593
1641
|
|
|
1594
|
-
|
|
1642
|
+
Run it as an agent hook after edits (\`lintobot --diff\`) or on a pull request (\`lintobot --diff origin/main\`), and hand the findings to the agent as things to review.
|
|
1595
1643
|
|
|
1596
|
-
##
|
|
1644
|
+
## Run
|
|
1597
1645
|
|
|
1598
|
-
\`\`\`
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1646
|
+
\`\`\`bash
|
|
1647
|
+
lintobot # every file matched by lintobot.yml
|
|
1648
|
+
lintobot app/jobs # only this folder or file
|
|
1649
|
+
lintobot src --rule "no magic numbers"
|
|
1650
|
+
lintobot src --dry-run # shows the exact questions, sends nothing
|
|
1651
|
+
lintobot --diff # only files changed since the last commit
|
|
1652
|
+
lintobot --diff origin/main # only files this branch changes
|
|
1603
1653
|
\`\`\`
|
|
1604
1654
|
|
|
1605
|
-
|
|
1606
|
-
- A dim sentence directly under the file name lists the info items that are true of the file: observations, not problems, shown when the model is at least 90% sure. Nothing to fix; use it to know what the file does. The confidence is in the \`jsonl\` record.
|
|
1607
|
-
- For rules, the percent is how sure the model is that the rule is **broken**.
|
|
1608
|
-
- A large file is sent in parts. A failed check names the line ranges of the parts that failed: look there, the model cannot say more. A passed check shows the lowest–highest value across parts.
|
|
1609
|
-
- In \`jsonl\`, each check record has \`file\`, \`rule\`, \`severity\`, \`confidence\`, \`question\`, and for multi-part files \`min\`, \`max\`, \`areas\`, \`parts\`. An info record has \`"type":"info"\`, \`statement\`, \`confidence\` and \`shown\` (true or false) instead of a severity.
|
|
1655
|
+
Needs \`LINTOBOT_MODEL\` and the provider's key in the environment or \`.env\`. Exit codes: \`0\` clean, \`1\` errors, \`2\` bad config, \`3\` model unreachable.
|
|
1610
1656
|
|
|
1611
|
-
|
|
1657
|
+
In the report ❌ is an error, ⚠️ a warning, ✅ passed. The percent is the confidence that the rule is broken; \`lines 120–300\` is the part of a large file where it failed.
|
|
1612
1658
|
|
|
1613
1659
|
## Write rules
|
|
1614
1660
|
|
|
1615
|
-
\`lintobot.yml\` is YAML where \`key!:\` marks a formula (scripted-yaml, FEEL syntax).
|
|
1616
|
-
|
|
1617
1661
|
\`\`\`yaml
|
|
1618
|
-
model: openrouter/typesafe/jev-1.14
|
|
1619
|
-
|
|
1620
1662
|
files:
|
|
1621
|
-
- pattern: "
|
|
1663
|
+
- pattern: "app/jobs/**_job.rb"
|
|
1664
|
+
except: "app/jobs/legacy/**"
|
|
1622
1665
|
rules:
|
|
1623
|
-
- "
|
|
1624
|
-
- "no secret values exposed":
|
|
1625
|
-
error: 0.6 # stricter
|
|
1626
|
-
- "comments explain intent":
|
|
1627
|
-
$if!: file.comment_lines > 5 # only applies to such files
|
|
1666
|
+
- "all methods are private except perform"
|
|
1628
1667
|
- "no direct database access":
|
|
1668
|
+
error: 0.8
|
|
1629
1669
|
ask: Does the code open a database connection or run a query itself?
|
|
1630
|
-
criteria:
|
|
1631
|
-
yes: Calls a driver or builds SQL in this file
|
|
1632
|
-
no: Goes through a repository or service
|
|
1633
1670
|
- "file is too long":
|
|
1634
|
-
error!: file.lines > 800
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
- A sentence starting with \`no \` is asked as "does the code contain …?"; any other sentence as "is it true that …?". \`ask:\` replaces the wording but not the direction: under a \`no …\` sentence yes means broken, under any other sentence yes means fine. Prefer questions where yes means the thing is present; avoid negations.
|
|
1638
|
-
- \`error\` / \`warning\`: a number (threshold on confidence), \`false\` to switch that level off, or a formula giving true/false. Formulas read \`confidence\` and \`file\`.
|
|
1639
|
-
- \`$if!\`: whether the rule applies; may read only \`file\`.
|
|
1640
|
-
- \`except\`: a glob or a list of globs of files the rule does not apply to. On a \`files\` entry, beside \`pattern\`, it takes those files out of the entry altogether.
|
|
1641
|
-
- \`whole: true\`: a rule about the file as a whole (asked once, no area).
|
|
1642
|
-
- \`file\` facts: \`path\`, \`dir\`, \`name\`, \`ext\`, \`lines\`, \`code_lines\`, \`comment_lines\`, \`blank_lines\`, \`longest_line\`, \`max_depth\`, \`complexity\`, lists \`imports\` and \`exports\`.
|
|
1643
|
-
- FEEL reminders: equals is one \`=\`, \`not(x)\`, \`a and b\`, \`count(list)\`, \`some i in file.imports satisfies starts with(i, "../db")\`.
|
|
1644
|
-
|
|
1645
|
-
Extra material for the model, by name, at the top, on a \`files\` entry or on a rule:
|
|
1646
|
-
|
|
1647
|
-
\`\`\`yaml
|
|
1648
|
-
context:
|
|
1649
|
-
style!file: docs/conventions.md
|
|
1650
|
-
docs!file: docs/$STEM.md
|
|
1651
|
-
recent!sh: git log -5 --format=%s -- "$FILE"
|
|
1671
|
+
error!: file.lines > 800
|
|
1672
|
+
info:
|
|
1673
|
+
- "sends email"
|
|
1652
1674
|
\`\`\`
|
|
1653
1675
|
|
|
1654
|
-
|
|
1676
|
+
- A rule is a sentence that must hold for the file. One starting with \`no \` is asked as "does the code contain …?", any other as "is it true that …?". State what is present; avoid negations, "only" and "always".
|
|
1677
|
+
- \`info:\` items are observations, not rules: start them with a verb. The true ones are printed under the file name and never fail the run.
|
|
1678
|
+
- Options, all optional:
|
|
1679
|
+
- \`error\`, \`warning\`: confidence threshold (defaults 0.9 and 0.7), or \`false\` to switch the level off
|
|
1680
|
+
- \`ask\`: the question to send instead of the generated one. Under a \`no …\` sentence yes means broken, otherwise yes means fine
|
|
1681
|
+
- \`criteria\`: \`yes:\` / \`no:\` descriptions of what counts
|
|
1682
|
+
- \`except\`: globs the rule skips
|
|
1683
|
+
- \`whole: true\`: the rule is about the file as a whole
|
|
1684
|
+
- A key ending in \`!\` is a formula over \`confidence\` and \`file\` (\`lines\`, \`complexity\`, \`imports\`, \`path\`, …): \`error!: confidence > 0.8 and file.lines > 300\`. \`$if!:\` decides whether the rule applies. A formula that does not read \`confidence\` makes no model call.
|
|
1655
1685
|
|
|
1656
|
-
|
|
1686
|
+
A good start for any code file is a few basic checks, then the project's own intentions on top:
|
|
1657
1687
|
|
|
1658
1688
|
\`\`\`yaml
|
|
1659
|
-
|
|
1660
|
-
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
rules:
|
|
1664
|
-
- "no magic numbers":
|
|
1665
|
-
except: ["app/controllers/api/**", "**/*_concern.rb"]
|
|
1666
|
-
- "no direct SQL":
|
|
1667
|
-
max_lines: 150
|
|
1689
|
+
rules:
|
|
1690
|
+
- "no duplicated code"
|
|
1691
|
+
- "no magic numbers"
|
|
1692
|
+
- "no comments that restate the code"
|
|
1668
1693
|
\`\`\`
|
|
1669
1694
|
|
|
1670
|
-
|
|
1695
|
+
## Start from the agent rules
|
|
1671
1696
|
|
|
1672
|
-
|
|
1673
|
-
files:
|
|
1674
|
-
- pattern: "src/**/*.ts"
|
|
1675
|
-
rules:
|
|
1676
|
-
- "no magic numbers"
|
|
1677
|
-
info:
|
|
1678
|
-
- "has I/O interactions"
|
|
1679
|
-
- "talks to the database":
|
|
1680
|
-
show: 0.8
|
|
1681
|
-
ask: Does the code run a database query or open a connection?
|
|
1682
|
-
- "is a large module":
|
|
1683
|
-
show!: file.lines > 400
|
|
1684
|
-
\`\`\`
|
|
1697
|
+
A project that has \`CLAUDE.md\` or \`AGENTS.md\` (at the root or in subfolders) has already written down what good code is. Use them as the first source of rules:
|
|
1685
1698
|
|
|
1686
|
-
|
|
1699
|
+
1. \`lintobot init\` writes a starter \`lintobot.yml\` when there is none.
|
|
1700
|
+
2. Read the agent files and keep every statement about **how the code should look** that can be judged by reading one file: "jobs only call services", "no business logic in controllers", "comments explain why".
|
|
1701
|
+
3. Rewrite each as a rule sentence, in the \`no …\` form where it fits, under the \`pattern\` of the files it speaks about. A file in a subfolder gives rules for that folder.
|
|
1702
|
+
4. Leave out what is not about one file's code: how to run tests, commit and PR habits, tool usage, anything that needs several files. Send strict syntax rules ("all methods private except perform") to the linter with \`/linto-lint\`.
|
|
1703
|
+
5. \`lintobot --dry-run\` to read the questions, then run it on a few known good and bad files and set thresholds from what they score.
|
|
1687
1704
|
|
|
1688
|
-
|
|
1705
|
+
Show the list of rules taken from the agent files, with the line each came from, before writing them.
|
|
1689
1706
|
|
|
1690
|
-
|
|
1691
|
-
2. A rule that fires on most files, or sits near 50% everywhere, is too vague: add \`ask:\` and \`criteria:\` that say what counts.
|
|
1692
|
-
3. Set thresholds from what real good and bad files score, not from a guess.
|
|
1693
|
-
4. A finding that names a 300-line area, or a rule that misses something small in a long file: give the rule a smaller \`max_lines\`.
|
|
1694
|
-
5. Answers are cached in \`.lintobot/cache/\`; \`--no-cache\` asks again.
|
|
1707
|
+
A rule that fires on most files is too vague: add \`ask\` and \`criteria\`, check the wording with \`--dry-run\`. The README has the rest: context, part sizes, output formats.
|
|
1695
1708
|
`;
|
|
1696
1709
|
|
|
1697
1710
|
// src/skill/linto-lint/SKILL.md
|
|
@@ -1876,6 +1889,12 @@ function projectRoot(args, flags) {
|
|
|
1876
1889
|
return { cwd };
|
|
1877
1890
|
}
|
|
1878
1891
|
async function main(args, flags) {
|
|
1892
|
+
if (flags.diff && flags.staged)
|
|
1893
|
+
throw new UsageError("--diff and --staged do not go together");
|
|
1894
|
+
if (typeof flags.diff === "string" && fs6.existsSync(flags.diff) && !isRevision(flags.diff)) {
|
|
1895
|
+
args.unshift(flags.diff);
|
|
1896
|
+
flags.diff = true;
|
|
1897
|
+
}
|
|
1879
1898
|
const root = projectRoot(args, flags);
|
|
1880
1899
|
args.push(...flags.files);
|
|
1881
1900
|
for (const file of new Set([path7.resolve(".env"), path7.join(root.cwd, ".env")])) {
|
|
@@ -1895,11 +1914,13 @@ async function main(args, flags) {
|
|
|
1895
1914
|
for (const warning of config.warnings)
|
|
1896
1915
|
process.stderr.write(`warning: ${warning}
|
|
1897
1916
|
`);
|
|
1898
|
-
const fromConfig = config.entries.every((
|
|
1899
|
-
|
|
1917
|
+
const fromConfig = config.entries.every((entry) => entry.patterns);
|
|
1918
|
+
const changed = flags.diff || flags.staged ? new Set(changedFiles({ ref: typeof flags.diff === "string" ? flags.diff : undefined, staged: flags.staged })) : null;
|
|
1919
|
+
if (!fromConfig && !args.length && !changed) {
|
|
1900
1920
|
throw new UsageError("Nothing to lint: no files were given", `Name files or folders (lintobot src/), or list patterns under files: in ${config.file}`);
|
|
1901
1921
|
}
|
|
1902
|
-
const
|
|
1922
|
+
const found = findFiles(args, fromConfig ? config.entries.flatMap((entry) => entry.patterns) : null, config.ignore);
|
|
1923
|
+
const files = changed ? found.filter((file) => changed.has(file)) : found;
|
|
1903
1924
|
const chunks = [];
|
|
1904
1925
|
const write = flags.output ? (text) => void chunks.push(text) : (text) => void process.stdout.write(text);
|
|
1905
1926
|
const save = () => flags.output && fs6.writeFileSync(flags.output, chunks.join(""));
|
|
@@ -1939,7 +1960,23 @@ process.stdout.on("error", (error) => {
|
|
|
1939
1960
|
if (error.code !== "EPIPE")
|
|
1940
1961
|
throw error;
|
|
1941
1962
|
});
|
|
1942
|
-
var
|
|
1963
|
+
var ABOUT = `
|
|
1964
|
+
What to expect:
|
|
1965
|
+
Rules are intentions: lintobot.yml describes what good code is for you, in plain sentences.
|
|
1966
|
+
Results are signals, not problems: a finding is advice to look, not a call to action.
|
|
1967
|
+
Pass findings to an agent or a reviewer to judge against the code.
|
|
1968
|
+
Results are not deterministic: the model answers with a probability, which can move
|
|
1969
|
+
a few points between runs.
|
|
1970
|
+
Each rule is as strict as you make it: lower its \`error\` threshold to enforce it harder,
|
|
1971
|
+
raise it or set it to false to keep it as a hint.
|
|
1972
|
+
It checks what a linter cannot (a comment matching its code, a function belonging in its
|
|
1973
|
+
file) and costs far less than a subagent. Run it from an agent hook or on a pull request:
|
|
1974
|
+
lintobot --diff what changed since the last commit
|
|
1975
|
+
lintobot --diff origin/main what this branch changes
|
|
1976
|
+
Rules that must hold exactly belong in a real linter: the linto-lint skill moves them
|
|
1977
|
+
(lintobot skill --install).
|
|
1978
|
+
`;
|
|
1979
|
+
var program = new Command().name("lintobot").description("A code linter whose rules are plain-language sentences answered by a decision model").version(package_default.version).argument("[files...]", "files, folders or globs; all files matched by lintobot.yml when omitted. A first argument that is a config file, or a folder holding lintobot.yml, selects that project").option("--format <format>", `output format: ${FORMATS.join(", ")} (pretty on a terminal, jsonl otherwise)`).option("-o, --output <file>", "write the report to a file").option("--files <path>", "file, folder or glob relative to the project, i.e. to the config (repeatable)", (value, list) => [...list, value], []).option("--rule <id>", "run only this rule, by id or sentence (repeatable)", (value, list) => [...list, value], []).option("--diff [ref]", "only files changed since the branch left <ref> (a branch, tag or commit), uncommitted and new files included; without <ref>, since the last commit").option("--staged", "only files staged for the next commit").option("--dry-run", "show what would be sent to the model, send nothing").option("--quiet", "report problems only").option("--no-cache", "ask the model again for pieces already answered").option("--no-shell", "do not run the !sh commands of the config").option("--concurrency <n>", "model calls at a time").option("-c, --config <path>", "config file (default: lintobot.yml); its folder becomes the working directory").option("--max-warnings <n>", "exit with 1 when there are more warnings than this").addHelpText("after", ABOUT).exitOverride().action(async (args, flags) => {
|
|
1943
1980
|
process.exitCode = await main(args, flags);
|
|
1944
1981
|
});
|
|
1945
1982
|
var SKILLS = { lintobot: SKILL_default, "linto-lint": SKILL_default2 };
|
|
@@ -1976,7 +2013,7 @@ try {
|
|
|
1976
2013
|
} catch (error) {
|
|
1977
2014
|
if (error instanceof CommanderError)
|
|
1978
2015
|
process.exitCode = error.exitCode === 0 ? EXIT.clean : EXIT.usage;
|
|
1979
|
-
else if (error instanceof UsageError)
|
|
2016
|
+
else if (error instanceof UsageError || error instanceof GitError)
|
|
1980
2017
|
process.exitCode = fail(error.message, error.hint);
|
|
1981
2018
|
else if (error instanceof ConfigError)
|
|
1982
2019
|
process.exitCode = fail(error.message);
|