lawcheck 0.0.0-stage → 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +36 -2
- package/dist/args.js +168 -0
- package/dist/bin.cjs +20 -0
- package/dist/check.js +472 -0
- package/dist/cli.js +182 -0
- package/dist/config.js +278 -0
- package/dist/docs.js +41 -0
- package/dist/doctor.js +273 -0
- package/dist/environment.js +73 -0
- package/dist/explain.js +446 -0
- package/dist/files.js +388 -0
- package/dist/glob.js +268 -0
- package/dist/grammars/LICENSES.txt +353 -0
- package/dist/grammars/tree-sitter-c.wasm +0 -0
- package/dist/grammars/tree-sitter-c_sharp.wasm +0 -0
- package/dist/grammars/tree-sitter-cpp.wasm +0 -0
- package/dist/grammars/tree-sitter-go.wasm +0 -0
- package/dist/grammars/tree-sitter-java.wasm +0 -0
- package/dist/grammars/tree-sitter-javascript.wasm +0 -0
- package/dist/grammars/tree-sitter-kotlin.wasm +0 -0
- package/dist/grammars/tree-sitter-php.wasm +0 -0
- package/dist/grammars/tree-sitter-python.wasm +0 -0
- package/dist/grammars/tree-sitter-ruby.wasm +0 -0
- package/dist/grammars/tree-sitter-rust.wasm +0 -0
- package/dist/grammars/tree-sitter-tsx.wasm +0 -0
- package/dist/grammars/tree-sitter-typescript.wasm +0 -0
- package/dist/guard.js +179 -0
- package/dist/init.js +131 -0
- package/dist/keys.js +55 -0
- package/dist/law.js +416 -0
- package/dist/lawchange.js +208 -0
- package/dist/limits.js +207 -0
- package/dist/main.js +77 -0
- package/dist/names.js +117 -0
- package/dist/output.js +325 -0
- package/dist/prime.js +211 -0
- package/dist/programs.js +177 -0
- package/dist/progress.js +42 -0
- package/dist/prompt.js +317 -0
- package/dist/providers/anthropic.js +33 -0
- package/dist/providers/claude-code.js +41 -0
- package/dist/providers/codex.js +75 -0
- package/dist/providers/copilot-cli.js +56 -0
- package/dist/providers/gemini-cli.js +30 -0
- package/dist/providers/google.js +31 -0
- package/dist/providers/http.js +138 -0
- package/dist/providers/index.js +96 -0
- package/dist/providers/ollama.js +39 -0
- package/dist/providers/openai-compatible.js +41 -0
- package/dist/providers/openai.js +17 -0
- package/dist/providers/program.js +282 -0
- package/dist/readers.js +286 -0
- package/dist/review.js +116 -0
- package/dist/rules.js +418 -0
- package/dist/runner.js +177 -0
- package/dist/setup.js +388 -0
- package/dist/try.js +346 -0
- package/dist/types.js +99 -0
- package/dist/uses.js +78 -0
- package/dist/verdicts.js +337 -0
- package/dist/waivers.js +70 -0
- package/dist/work.js +21 -0
- package/docs/change.md +62 -0
- package/docs/ci.md +133 -0
- package/docs/codes.md +60 -0
- package/docs/config.md +117 -0
- package/docs/first-law.md +189 -0
- package/docs/json.md +72 -0
- package/docs/languages.md +87 -0
- package/docs/law.md +95 -0
- package/docs/providers.md +105 -0
- package/docs/reviewer-rules.md +96 -0
- package/docs/script-rules.md +90 -0
- package/docs/waivers.md +56 -0
- package/package.json +66 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Krzysztof Dudek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lawcheck
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
You write your repository's architecture and rules. Lawcheck checks the code against them and tells your coding agent which line breaks which rule.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
This is an alpha for early testing.
|
|
8
|
+
|
|
9
|
+
Lawcheck needs Node 24 or later and git 2.34 or later. It installs with npm, pnpm, Yarn 1, Yarn 4 with `nodeLinker: node-modules` or `nodeLinker: pnpm`, and Bun beside Node. Yarn Plug'n'Play is not supported, and neither is Bun without Node.
|
|
10
|
+
|
|
11
|
+
npm install --global lawcheck@alpha
|
|
12
|
+
|
|
13
|
+
Then, at the root of a git repository:
|
|
14
|
+
|
|
15
|
+
lawcheck init
|
|
16
|
+
lawcheck docs first-law
|
|
17
|
+
|
|
18
|
+
To keep Lawcheck in a project instead, run `npm install --save-dev lawcheck@alpha`, set `runner` in `.lawcheck/config.yaml` (`lawcheck docs config`), and start it with `npx lawcheck`.
|
|
19
|
+
|
|
20
|
+
## Coding agents
|
|
21
|
+
|
|
22
|
+
In Claude Code, the Lawcheck plugin gives the agent the law at the start of every session, checks each file it edits, and sends it back, up to three times, while the files that changed in its turn break the law:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
claude plugin marketplace add krzysztofdudek/Lawcheck
|
|
26
|
+
claude plugin install lawcheck@lawcheck-marketplace
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The hooks run Lawcheck and the repository's rule scripts after edits and before the agent finishes, so use the plugin where you would run the repository's tests. With a `runner` other than `global`, the package manager also reads the repository's own files, such as `yarnPath` in `.yarnrc.yml` or a committed `node_modules/.bin/lawcheck`, and starts the program they name. The two checks, the one after an edit and the one before the agent finishes, can both be switched off with `/plugin configure lawcheck@lawcheck-marketplace`.
|
|
30
|
+
|
|
31
|
+
With any other agent, paste this sentence into its instructions file:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Run `lawcheck prime` at the start of every session and follow it.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
That agent then checks only when it follows the primer: nothing checks a file after an edit or holds the turn while the law is broken. A project that starts Lawcheck through its package manager names it as `runner` in `.lawcheck/config.yaml` (`lawcheck docs config`), and the sentence then uses that command, such as `pnpm exec lawcheck prime`.
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { renderErrors } from './output.js';
|
|
3
|
+
export function version() {
|
|
4
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
5
|
+
return manifest.version;
|
|
6
|
+
}
|
|
7
|
+
export function usageError(problem, json, command) {
|
|
8
|
+
return errorResult([{ code: 'usage', file: null, line: null, message: problem }], json, command);
|
|
9
|
+
}
|
|
10
|
+
export function errorResult(errors, json, command) {
|
|
11
|
+
return { code: 2, stdout: renderErrors(errors, json, command) };
|
|
12
|
+
}
|
|
13
|
+
export function documentOf(value) {
|
|
14
|
+
return JSON.stringify(value, null, 2) + '\n';
|
|
15
|
+
}
|
|
16
|
+
export const COMMANDS = ['init', 'prime', 'check', 'explain', 'try', 'docs', 'doctor'];
|
|
17
|
+
const FLAGS = {
|
|
18
|
+
init: { '--json': 'switch' },
|
|
19
|
+
prime: { '--json': 'switch' },
|
|
20
|
+
check: { '--full': 'switch', '--base': 'ref', '--review': 'switch', '--again': 'switch', '--max-calls': 'digits', '--json': 'switch' },
|
|
21
|
+
explain: { '--type': 'id', '--rule': 'id', '--json': 'switch' },
|
|
22
|
+
try: { '--times': 'digits', '--dry-run': 'switch', '--max-calls': 'digits', '--json': 'switch' },
|
|
23
|
+
docs: { '--json': 'switch' },
|
|
24
|
+
doctor: { '--base': 'ref', '--reviewer': 'switch', '--json': 'switch' },
|
|
25
|
+
};
|
|
26
|
+
export const PROGRAM_USAGE = [
|
|
27
|
+
'usage: lawcheck <command> [<arguments>] [--json]',
|
|
28
|
+
' init starts a law in the current directory',
|
|
29
|
+
' prime prints what a coding agent reads at the start of a session',
|
|
30
|
+
' check checks the files of this change, or the files named, against the law',
|
|
31
|
+
' explain says why a file, a type or a rule has the law it has',
|
|
32
|
+
' try runs one rule on chosen files and records nothing',
|
|
33
|
+
' docs prints the reference, one topic at a time',
|
|
34
|
+
' doctor says what is wrong with this setup',
|
|
35
|
+
'',
|
|
36
|
+
].join('\n');
|
|
37
|
+
export const USAGE = {
|
|
38
|
+
init: [
|
|
39
|
+
'usage: lawcheck init [--json]',
|
|
40
|
+
'',
|
|
41
|
+
'Starts a law in the current directory: writes .lawcheck/law.yaml and .lawcheck/.gitignore when they are absent.',
|
|
42
|
+
'',
|
|
43
|
+
' --json print one JSON document',
|
|
44
|
+
'',
|
|
45
|
+
].join('\n'),
|
|
46
|
+
prime: [
|
|
47
|
+
'usage: lawcheck prime [--json]',
|
|
48
|
+
'',
|
|
49
|
+
"Prints how to work with Lawcheck here, then this repository's law in short.",
|
|
50
|
+
'',
|
|
51
|
+
' --json print one JSON document',
|
|
52
|
+
'',
|
|
53
|
+
].join('\n'),
|
|
54
|
+
check: [
|
|
55
|
+
'usage: lawcheck check [--full] [--base <ref>] [--review [--again] [--max-calls <n>]] [--json]',
|
|
56
|
+
' lawcheck check <path or pattern>... [--json]',
|
|
57
|
+
'',
|
|
58
|
+
'Checks the files of this change, or the files named, against .lawcheck/law.yaml.',
|
|
59
|
+
'',
|
|
60
|
+
' <path or pattern> judge these files, changed or not, and no others',
|
|
61
|
+
' --full also judge the files outside the change, as debt',
|
|
62
|
+
' --base <ref> the base of the change; else LAWCHECK_BASE, else origin/HEAD',
|
|
63
|
+
' --review ask the reviewer for the reviews that have no verdict',
|
|
64
|
+
' --again with --review, ask again where a failure is cached',
|
|
65
|
+
' --max-calls <n> with --review, the most requests this run sends',
|
|
66
|
+
' --json print one JSON document',
|
|
67
|
+
'',
|
|
68
|
+
'Exit 0: no error. Exit 1: the code breaks the law. Exit 2: no conclusion.',
|
|
69
|
+
'',
|
|
70
|
+
].join('\n'),
|
|
71
|
+
explain: [
|
|
72
|
+
'usage: lawcheck explain (<path> | --type <id> | --rule <id>) [--json]',
|
|
73
|
+
'',
|
|
74
|
+
'Says why a file has the law it has, or explains a type or a rule. Runs no rule and writes nothing.',
|
|
75
|
+
'',
|
|
76
|
+
' <path> a file, a file that does not exist yet, or a directory',
|
|
77
|
+
' --type <id> a type of the law, with its files',
|
|
78
|
+
' --rule <id> a rule of the law, with the files it binds',
|
|
79
|
+
' --json print one JSON document',
|
|
80
|
+
'',
|
|
81
|
+
].join('\n'),
|
|
82
|
+
try: [
|
|
83
|
+
'usage: lawcheck try <rule> [<path or pattern>...] [--times <n>] [--dry-run] [--max-calls <n>] [--json]',
|
|
84
|
+
'',
|
|
85
|
+
'Runs one rule on chosen files, without a base, and writes nothing in the repository.',
|
|
86
|
+
'',
|
|
87
|
+
' <path or pattern> a file, a directory or a pattern; a script rule without one takes the files it binds',
|
|
88
|
+
' --times <n> with a reviewer rule, ask about each file n times',
|
|
89
|
+
' --dry-run with a reviewer rule, print the calls and make none',
|
|
90
|
+
' --max-calls <n> with a reviewer rule, the most requests this run sends',
|
|
91
|
+
' --json print one JSON document',
|
|
92
|
+
'',
|
|
93
|
+
'Exit 0: no finding. Exit 1: a finding. Exit 2: the run could not be made.',
|
|
94
|
+
'',
|
|
95
|
+
].join('\n'),
|
|
96
|
+
docs: [
|
|
97
|
+
'usage: lawcheck docs [<topic>] [--json]',
|
|
98
|
+
'',
|
|
99
|
+
"Prints the tool's reference. Without a topic, lists the topics.",
|
|
100
|
+
'',
|
|
101
|
+
' --json print one JSON document',
|
|
102
|
+
'',
|
|
103
|
+
].join('\n'),
|
|
104
|
+
doctor: [
|
|
105
|
+
'usage: lawcheck doctor [--base <ref>] [--reviewer] [--json]',
|
|
106
|
+
'',
|
|
107
|
+
'Says what is wrong with this setup, with one next step for each problem. Writes nothing.',
|
|
108
|
+
'',
|
|
109
|
+
' --base <ref> the base of the change; else LAWCHECK_BASE, else origin/HEAD',
|
|
110
|
+
' --reviewer send the reviewer one small test request',
|
|
111
|
+
' --json print one JSON document',
|
|
112
|
+
'',
|
|
113
|
+
].join('\n'),
|
|
114
|
+
};
|
|
115
|
+
const LIST = COMMANDS.join(', ');
|
|
116
|
+
function what(kind) {
|
|
117
|
+
return kind === 'ref' ? 'a ref' : kind === 'digits' ? 'a number' : 'an id';
|
|
118
|
+
}
|
|
119
|
+
export function readArguments(argv) {
|
|
120
|
+
if (argv.length === 0)
|
|
121
|
+
return { problem: `no command; the commands are ${LIST}`, command: null };
|
|
122
|
+
const name = argv[0];
|
|
123
|
+
if (!COMMANDS.includes(name))
|
|
124
|
+
return { problem: `unknown command '${name}'; the commands are ${LIST}`, command: null };
|
|
125
|
+
const command = name;
|
|
126
|
+
const known = FLAGS[command];
|
|
127
|
+
const flags = new Map();
|
|
128
|
+
const words = [];
|
|
129
|
+
const fail = (problem) => ({ problem, command });
|
|
130
|
+
for (let i = 1; i < argv.length; i++) {
|
|
131
|
+
const word = argv[i];
|
|
132
|
+
if (!word.startsWith('-')) {
|
|
133
|
+
words.push(word);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const kind = known[word];
|
|
137
|
+
if (kind === undefined)
|
|
138
|
+
return fail(`unknown flag '${word}'`);
|
|
139
|
+
if (flags.has(word))
|
|
140
|
+
return fail(`the flag ${word} is given twice`);
|
|
141
|
+
if (kind === 'switch') {
|
|
142
|
+
flags.set(word, true);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const value = argv[i + 1];
|
|
146
|
+
if (value === undefined || value.startsWith('-'))
|
|
147
|
+
return fail(`the flag ${word} takes ${what(kind)}`);
|
|
148
|
+
if (kind === 'digits' && !/^[0-9]+$/.test(value))
|
|
149
|
+
return fail(`the flag ${word} takes a number of digits, not '${value}'`);
|
|
150
|
+
if (kind === 'digits' && !Number.isSafeInteger(Number(value)))
|
|
151
|
+
return fail(`the flag ${word} takes a number up to ${Number.MAX_SAFE_INTEGER}, not '${value}'`);
|
|
152
|
+
flags.set(word, value);
|
|
153
|
+
i++;
|
|
154
|
+
}
|
|
155
|
+
return { arguments: { command, flags, words } };
|
|
156
|
+
}
|
|
157
|
+
export function number(args, flag) {
|
|
158
|
+
const value = args.flags.get(flag);
|
|
159
|
+
return typeof value === 'string' ? Number(value) : null;
|
|
160
|
+
}
|
|
161
|
+
export function text(args, flag) {
|
|
162
|
+
const value = args.flags.get(flag);
|
|
163
|
+
return typeof value === 'string' ? value : null;
|
|
164
|
+
}
|
|
165
|
+
export function noWords(args) {
|
|
166
|
+
const word = args.words[0];
|
|
167
|
+
return word === undefined ? null : `unexpected argument '${word}'; ${args.command} takes no arguments`;
|
|
168
|
+
}
|
package/dist/bin.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// Node's permission model, turned on by --permission in NODE_OPTIONS, lets the entry file load and refuses every module it imports, so this file imports none of Lawcheck's own modules before it looks. It is CommonJS whatever package.json says: Node 24.2 to 24.6 under that model cannot read package.json, and would parse an ES module entry as CommonJS.
|
|
5
|
+
const COMMANDS = ['init', 'prime', 'check', 'explain', 'try', 'docs', 'doctor'];
|
|
6
|
+
function refuse() {
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const command = COMMANDS.includes(args[0] ?? '') ? args[0] : 'check';
|
|
9
|
+
const message = "Node runs with --permission, set in NODE_OPTIONS, and under it Lawcheck cannot read its own files";
|
|
10
|
+
const why = 'Lawcheck answers only where its rules and readers are known to run';
|
|
11
|
+
const next = `start Lawcheck with NODE_OPTIONS free of --permission, then run lawcheck ${command === 'check' ? 'check' : `${command} again`}`;
|
|
12
|
+
const text = args.includes('--json')
|
|
13
|
+
? JSON.stringify({ schema: 'lawcheck-error/1', errors: [{ code: 'unsupported-environment', file: null, line: null, message, why }], next: { command: null, text: next } }, null, 2) + '\n'
|
|
14
|
+
: [`lawcheck: ERROR ${message}`, '', `error[unsupported-environment] ${message}`, ` why: ${why}`, '', `next: ${next}`, ''].join('\n');
|
|
15
|
+
process.stdout.write(text, () => process.exit(2));
|
|
16
|
+
}
|
|
17
|
+
if (process.permission !== undefined)
|
|
18
|
+
refuse();
|
|
19
|
+
else
|
|
20
|
+
void import('./cli.js').then((cli) => cli.start());
|