@tayomi/deterministic-gates 0.4.2 → 0.5.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/catalog/angular.json +85 -0
- package/catalog/index.html +119 -4
- package/catalog/typescript.json +29 -2
- package/dist/src/cli.js +3 -3
- package/dist/src/core/check.js +35 -12
- package/dist/src/core/config.js +28 -2
- package/dist/src/core/report-cache.js +7 -2
- package/dist/src/core/run.js +29 -11
- package/dist/src/core/watch.js +283 -0
- package/dist/src/helpers/angular-watch.js +47 -0
- package/dist/src/helpers/tsc.js +57 -0
- package/dist/src/helpers/type-errors.js +144 -0
- package/dist/src/helpers/vitest-state-reporter.js +26 -0
- package/dist/src/hook/hook.js +25 -1
- package/hooks/hooks.json +11 -0
- package/package.json +1 -1
- package/src/cli.ts +3 -3
- package/src/core/check.ts +36 -12
- package/src/core/config.ts +43 -2
- package/src/core/report-cache.ts +12 -3
- package/src/core/run.ts +32 -11
- package/src/core/watch.ts +313 -0
- package/src/helpers/angular-watch.ts +50 -0
- package/src/helpers/tsc.ts +60 -0
- package/src/helpers/type-errors.ts +142 -0
- package/src/helpers/vitest-state-reporter.ts +48 -0
- package/src/hook/hook.ts +27 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
|
|
3
3
|
"name": "deterministic-gates",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"description": "Deterministic backpressure for coding agents: gates that run on what each turn changed and send the agent back until they pass.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Pierre Moati",
|
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ codex plugin marketplace add mopi1402/tayomi-deterministic-gates
|
|
|
37
37
|
codex plugin add deterministic-gates@tayomi-deterministic-gates
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
Codex runs no hook you have not reviewed: in a session, open `/hooks` and trust the
|
|
40
|
+
Codex runs no hook you have not reviewed: in a session, open `/hooks` and trust the four hooks of the plugin. A plugin update that changes a script asks for a new review.
|
|
41
41
|
|
|
42
42
|
## Configure the gates
|
|
43
43
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Angular",
|
|
3
|
+
"description": "Gates for an Angular project tested with Vitest through the Angular builder, ng test. Each tool comes from the repo's node_modules, so its version is the one the lockfile pins.",
|
|
4
|
+
"gates": [
|
|
5
|
+
{
|
|
6
|
+
"description": "Runs the unit tests in a watch kept warm between turns, since ng test builds the whole application before a single test runs. At the stop, it waits for the watch to finish with the turn's changes, then fails on a build that does not compile, and on every red spec, the ones the change did not rerun included. The whole check runs ng test once, without a watch.",
|
|
7
|
+
"requires": [
|
|
8
|
+
{
|
|
9
|
+
"tool": "@angular/cli",
|
|
10
|
+
"install": "npm install --save-dev @angular/cli"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"tool": "@angular/build",
|
|
14
|
+
"install": "npm install --save-dev @angular/build"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"tool": "vitest",
|
|
18
|
+
"install": "npm install --save-dev vitest"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"gate": {
|
|
22
|
+
"name": "tests",
|
|
23
|
+
"severity": "error",
|
|
24
|
+
"files": "\\.(ts|html|css)$",
|
|
25
|
+
"run": ["@angular/cli", "test", "--watch=false"],
|
|
26
|
+
"watch": {
|
|
27
|
+
"run": ["{engine}/src/helpers/angular-watch.ts"],
|
|
28
|
+
"cycleStart": "Changes detected\\. Rebuilding",
|
|
29
|
+
"cycleEnd": "Test run finished with success|bundle generation failed",
|
|
30
|
+
"failed": "^FAIL |bundle generation failed"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"description": "Builds the application in a watch kept warm between turns, which type-checks every template, the ones of a component no spec reaches included: tsc alone never reads a template. At the stop, it fails on a build that does not compile, with the file and line of each error. Built without optimization into node_modules/.cache, so the dist of the project stays as it is. The whole check builds once, without a watch.",
|
|
36
|
+
"requires": [
|
|
37
|
+
{
|
|
38
|
+
"tool": "@angular/cli",
|
|
39
|
+
"install": "npm install --save-dev @angular/cli"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"tool": "@angular/build",
|
|
43
|
+
"install": "npm install --save-dev @angular/build"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"gate": {
|
|
47
|
+
"name": "build",
|
|
48
|
+
"severity": "error",
|
|
49
|
+
"files": "\\.(ts|html|css|scss|sass|less)$",
|
|
50
|
+
"run": ["@angular/cli", "build", "--optimization=false", "--output-path=node_modules/.cache/gates/build"],
|
|
51
|
+
"watch": {
|
|
52
|
+
"run": [
|
|
53
|
+
"@angular/cli",
|
|
54
|
+
"build",
|
|
55
|
+
"--watch",
|
|
56
|
+
"--optimization=false",
|
|
57
|
+
"--output-path=node_modules/.cache/gates/build"
|
|
58
|
+
],
|
|
59
|
+
"cycleStart": "Changes detected\\. Rebuilding",
|
|
60
|
+
"cycleEnd": "Application bundle generation (complete|failed)",
|
|
61
|
+
"failed": "Application bundle generation failed"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"description": "Lints the changed templates with angular-eslint, warnings included: the lint of the TypeScript catalog reads no .html file. It needs an ESLint config that gives .html files to angular-eslint, such as its templateRecommended and templateAccessibility configs.",
|
|
67
|
+
"requires": [
|
|
68
|
+
{
|
|
69
|
+
"tool": "eslint",
|
|
70
|
+
"install": "npm install --save-dev eslint"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"tool": "angular-eslint",
|
|
74
|
+
"install": "npm install --save-dev angular-eslint"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"gate": {
|
|
78
|
+
"name": "template-lint",
|
|
79
|
+
"severity": "error",
|
|
80
|
+
"files": "\\.html$",
|
|
81
|
+
"run": ["eslint", "--max-warnings", "0", "--no-warn-ignored", "{files}"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
package/catalog/index.html
CHANGED
|
@@ -40,8 +40,92 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
40
40
|
<h1>Gate catalog</h1>
|
|
41
41
|
<p>The gates worth copying into a repo. Nothing here runs by itself: the engine reads only the repo's <code>.gates.json</code>. Copy the definition of a gate there, install what it requires, and adapt its <code>files</code> to the layout of the repo.</p>
|
|
42
42
|
<p>Generated from <code>catalog/*.json</code> by <code>pnpm catalog</code>: edit those files, never this page.</p>
|
|
43
|
-
<nav><a href="#go">Go (6)</a><a href="#python">Python (3)</a><a href="#typescript">TypeScript (
|
|
43
|
+
<nav><a href="#angular">Angular (3)</a><a href="#go">Go (6)</a><a href="#python">Python (3)</a><a href="#typescript">TypeScript (9)</a></nav>
|
|
44
44
|
</header>
|
|
45
|
+
<section id="angular">
|
|
46
|
+
<h2>Angular</h2>
|
|
47
|
+
<p>Gates for an Angular project tested with Vitest through the Angular builder, ng test. Each tool comes from the repo's node_modules, so its version is the one the lockfile pins.</p>
|
|
48
|
+
<article id="angular/tests">
|
|
49
|
+
<h3><code>angular/tests</code></h3>
|
|
50
|
+
<p>Runs the unit tests in a watch kept warm between turns, since ng test builds the whole application before a single test runs. At the stop, it waits for the watch to finish with the turn's changes, then fails on a build that does not compile, and on every red spec, the ones the change did not rerun included. The whole check runs ng test once, without a watch.</p>
|
|
51
|
+
<dl>
|
|
52
|
+
<dt>Runs</dt><dd><code>@angular/cli test --watch=false</code></dd>
|
|
53
|
+
<dt>When the turn changes</dt><dd><code>\.(ts|html|css)$</code></dd>
|
|
54
|
+
<dt>Requires</dt><dd><ul><li><code>@angular/cli</code>: npm install --save-dev @angular/cli</li><li><code>@angular/build</code>: npm install --save-dev @angular/build</li><li><code>vitest</code>: npm install --save-dev vitest</li></ul></dd>
|
|
55
|
+
</dl>
|
|
56
|
+
<details><summary>Definition to copy into .gates.json</summary><pre><code>{
|
|
57
|
+
"name": "tests",
|
|
58
|
+
"severity": "error",
|
|
59
|
+
"files": "\\.(ts|html|css)$",
|
|
60
|
+
"run": [
|
|
61
|
+
"@angular/cli",
|
|
62
|
+
"test",
|
|
63
|
+
"--watch=false"
|
|
64
|
+
],
|
|
65
|
+
"watch": {
|
|
66
|
+
"run": [
|
|
67
|
+
"{engine}/src/helpers/angular-watch.ts"
|
|
68
|
+
],
|
|
69
|
+
"cycleStart": "Changes detected\\. Rebuilding",
|
|
70
|
+
"cycleEnd": "Test run finished with success|bundle generation failed",
|
|
71
|
+
"failed": "^FAIL |bundle generation failed"
|
|
72
|
+
}
|
|
73
|
+
}</code></pre></details>
|
|
74
|
+
</article>
|
|
75
|
+
<article id="angular/build">
|
|
76
|
+
<h3><code>angular/build</code></h3>
|
|
77
|
+
<p>Builds the application in a watch kept warm between turns, which type-checks every template, the ones of a component no spec reaches included: tsc alone never reads a template. At the stop, it fails on a build that does not compile, with the file and line of each error. Built without optimization into node_modules/.cache, so the dist of the project stays as it is. The whole check builds once, without a watch.</p>
|
|
78
|
+
<dl>
|
|
79
|
+
<dt>Runs</dt><dd><code>@angular/cli build --optimization=false --output-path=node_modules/.cache/gates/build</code></dd>
|
|
80
|
+
<dt>When the turn changes</dt><dd><code>\.(ts|html|css|scss|sass|less)$</code></dd>
|
|
81
|
+
<dt>Requires</dt><dd><ul><li><code>@angular/cli</code>: npm install --save-dev @angular/cli</li><li><code>@angular/build</code>: npm install --save-dev @angular/build</li></ul></dd>
|
|
82
|
+
</dl>
|
|
83
|
+
<details><summary>Definition to copy into .gates.json</summary><pre><code>{
|
|
84
|
+
"name": "build",
|
|
85
|
+
"severity": "error",
|
|
86
|
+
"files": "\\.(ts|html|css|scss|sass|less)$",
|
|
87
|
+
"run": [
|
|
88
|
+
"@angular/cli",
|
|
89
|
+
"build",
|
|
90
|
+
"--optimization=false",
|
|
91
|
+
"--output-path=node_modules/.cache/gates/build"
|
|
92
|
+
],
|
|
93
|
+
"watch": {
|
|
94
|
+
"run": [
|
|
95
|
+
"@angular/cli",
|
|
96
|
+
"build",
|
|
97
|
+
"--watch",
|
|
98
|
+
"--optimization=false",
|
|
99
|
+
"--output-path=node_modules/.cache/gates/build"
|
|
100
|
+
],
|
|
101
|
+
"cycleStart": "Changes detected\\. Rebuilding",
|
|
102
|
+
"cycleEnd": "Application bundle generation (complete|failed)",
|
|
103
|
+
"failed": "Application bundle generation failed"
|
|
104
|
+
}
|
|
105
|
+
}</code></pre></details>
|
|
106
|
+
</article>
|
|
107
|
+
<article id="angular/template-lint">
|
|
108
|
+
<h3><code>angular/template-lint</code></h3>
|
|
109
|
+
<p>Lints the changed templates with angular-eslint, warnings included: the lint of the TypeScript catalog reads no .html file. It needs an ESLint config that gives .html files to angular-eslint, such as its templateRecommended and templateAccessibility configs.</p>
|
|
110
|
+
<dl>
|
|
111
|
+
<dt>Runs</dt><dd><code>eslint --max-warnings 0 --no-warn-ignored {files}</code></dd>
|
|
112
|
+
<dt>When the turn changes</dt><dd><code>\.html$</code></dd>
|
|
113
|
+
<dt>Requires</dt><dd><ul><li><code>eslint</code>: npm install --save-dev eslint</li><li><code>angular-eslint</code>: npm install --save-dev angular-eslint</li></ul></dd>
|
|
114
|
+
</dl>
|
|
115
|
+
<details><summary>Definition to copy into .gates.json</summary><pre><code>{
|
|
116
|
+
"name": "template-lint",
|
|
117
|
+
"severity": "error",
|
|
118
|
+
"files": "\\.html$",
|
|
119
|
+
"run": [
|
|
120
|
+
"eslint",
|
|
121
|
+
"--max-warnings",
|
|
122
|
+
"0",
|
|
123
|
+
"--no-warn-ignored",
|
|
124
|
+
"{files}"
|
|
125
|
+
]
|
|
126
|
+
}</code></pre></details>
|
|
127
|
+
</article>
|
|
128
|
+
</section>
|
|
45
129
|
<section id="go">
|
|
46
130
|
<h2>Go</h2>
|
|
47
131
|
<p>Gates for a Go module. The toolchain comes from the PATH. The first build of a cold cache is slow, which is why these gates allow 60 seconds.</p>
|
|
@@ -250,9 +334,9 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
250
334
|
</article>
|
|
251
335
|
<article id="typescript/typecheck">
|
|
252
336
|
<h3><code>typescript/typecheck</code></h3>
|
|
253
|
-
<p>Type-checks the project with tsc, since a change in one file can break the types of another. Incremental: tsc keeps what it learnt under node_modules/.cache and re-checks only what the changed files reach.</p>
|
|
337
|
+
<p>Type-checks the project with tsc, since a change in one file can break the types of another, and writes no JavaScript. Incremental: tsc keeps what it learnt under node_modules/.cache and re-checks only what the changed files reach. Refused when tsconfig.json only references others, as in an Angular project, since tsc would check no file: give it -p and a tsconfig.</p>
|
|
254
338
|
<dl>
|
|
255
|
-
<dt>Runs</dt><dd><code>
|
|
339
|
+
<dt>Runs</dt><dd><code>{engine}/src/helpers/tsc.ts --pretty false --noEmit --incremental --tsBuildInfoFile node_modules/.cache/gates/tsbuildinfo</code></dd>
|
|
256
340
|
<dt>When the turn changes</dt><dd><code>(\.(ts|tsx)|^tsconfig\.json)$</code></dd>
|
|
257
341
|
<dt>Requires</dt><dd><ul><li><code>typescript</code>: npm install --save-dev typescript</li></ul></dd>
|
|
258
342
|
</dl>
|
|
@@ -261,9 +345,10 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
261
345
|
"severity": "error",
|
|
262
346
|
"files": "(\\.(ts|tsx)|^tsconfig\\.json)$",
|
|
263
347
|
"run": [
|
|
264
|
-
"
|
|
348
|
+
"{engine}/src/helpers/tsc.ts",
|
|
265
349
|
"--pretty",
|
|
266
350
|
"false",
|
|
351
|
+
"--noEmit",
|
|
267
352
|
"--incremental",
|
|
268
353
|
"--tsBuildInfoFile",
|
|
269
354
|
"node_modules/.cache/gates/tsbuildinfo"
|
|
@@ -350,6 +435,36 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
350
435
|
]
|
|
351
436
|
}</code></pre></details>
|
|
352
437
|
</article>
|
|
438
|
+
<article id="typescript/no-new-strict-errors">
|
|
439
|
+
<h3><code>typescript/no-new-strict-errors</code></h3>
|
|
440
|
+
<p>Type-checks the project with strictNullChecks and strictPropertyInitialization on, and fails only on the errors the turn added: a project that turned them off, with more errors than it can fix at once, stops growing new ones. An error is told by its file, code and message, so one a change moves to another line is not new. tsc keeps watching between turns; without the watch, it runs at each prompt and stop instead. Refused when tsconfig.json only references others, as in an Angular project, since tsc would check no file: give it -p and a tsconfig. The whole check counts every error.</p>
|
|
441
|
+
<dl>
|
|
442
|
+
<dt>Runs</dt><dd><code>{engine}/src/helpers/type-errors.ts --strictNullChecks --strictPropertyInitialization</code></dd>
|
|
443
|
+
<dt>When the turn changes</dt><dd><code>(\.(ts|tsx)|^tsconfig.*\.json)$</code></dd>
|
|
444
|
+
<dt>Fails on</dt><dd>only the output lines the turn added</dd><dt>Requires</dt><dd><ul><li><code>typescript</code>: npm install --save-dev typescript</li></ul></dd>
|
|
445
|
+
</dl>
|
|
446
|
+
<details><summary>Definition to copy into .gates.json</summary><pre><code>{
|
|
447
|
+
"name": "no-new-strict-errors",
|
|
448
|
+
"severity": "error",
|
|
449
|
+
"files": "(\\.(ts|tsx)|^tsconfig.*\\.json)$",
|
|
450
|
+
"run": [
|
|
451
|
+
"{engine}/src/helpers/type-errors.ts",
|
|
452
|
+
"--strictNullChecks",
|
|
453
|
+
"--strictPropertyInitialization"
|
|
454
|
+
],
|
|
455
|
+
"compare": "turn-start",
|
|
456
|
+
"watch": {
|
|
457
|
+
"run": [
|
|
458
|
+
"{engine}/src/helpers/type-errors.ts",
|
|
459
|
+
"--watch",
|
|
460
|
+
"--strictNullChecks",
|
|
461
|
+
"--strictPropertyInitialization"
|
|
462
|
+
],
|
|
463
|
+
"cycleStart": "^Type check started$",
|
|
464
|
+
"cycleEnd": "^Type check done$"
|
|
465
|
+
}
|
|
466
|
+
}</code></pre></details>
|
|
467
|
+
</article>
|
|
353
468
|
<article id="typescript/no-new-dead-code">
|
|
354
469
|
<h3><code>typescript/no-new-dead-code</code></h3>
|
|
355
470
|
<p>Fails on the unused files, exports and dependencies the turn added, never on the ones already there, so it works on a repo that already has some.</p>
|
package/catalog/typescript.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
"description": "Type-checks the project with tsc, since a change in one file can break the types of another. Incremental: tsc keeps what it learnt under node_modules/.cache and re-checks only what the changed files reach.",
|
|
21
|
+
"description": "Type-checks the project with tsc, since a change in one file can break the types of another, and writes no JavaScript. Incremental: tsc keeps what it learnt under node_modules/.cache and re-checks only what the changed files reach. Refused when tsconfig.json only references others, as in an Angular project, since tsc would check no file: give it -p and a tsconfig.",
|
|
22
22
|
"requires": [
|
|
23
23
|
{
|
|
24
24
|
"tool": "typescript",
|
|
@@ -30,9 +30,10 @@
|
|
|
30
30
|
"severity": "error",
|
|
31
31
|
"files": "(\\.(ts|tsx)|^tsconfig\\.json)$",
|
|
32
32
|
"run": [
|
|
33
|
-
"
|
|
33
|
+
"{engine}/src/helpers/tsc.ts",
|
|
34
34
|
"--pretty",
|
|
35
35
|
"false",
|
|
36
|
+
"--noEmit",
|
|
36
37
|
"--incremental",
|
|
37
38
|
"--tsBuildInfoFile",
|
|
38
39
|
"node_modules/.cache/gates/tsbuildinfo"
|
|
@@ -94,6 +95,32 @@
|
|
|
94
95
|
"run": ["{engine}/src/helpers/new-clones.ts", "{turn}"]
|
|
95
96
|
}
|
|
96
97
|
},
|
|
98
|
+
{
|
|
99
|
+
"description": "Type-checks the project with strictNullChecks and strictPropertyInitialization on, and fails only on the errors the turn added: a project that turned them off, with more errors than it can fix at once, stops growing new ones. An error is told by its file, code and message, so one a change moves to another line is not new. tsc keeps watching between turns; without the watch, it runs at each prompt and stop instead. Refused when tsconfig.json only references others, as in an Angular project, since tsc would check no file: give it -p and a tsconfig. The whole check counts every error.",
|
|
100
|
+
"requires": [
|
|
101
|
+
{
|
|
102
|
+
"tool": "typescript",
|
|
103
|
+
"install": "npm install --save-dev typescript"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"gate": {
|
|
107
|
+
"name": "no-new-strict-errors",
|
|
108
|
+
"severity": "error",
|
|
109
|
+
"files": "(\\.(ts|tsx)|^tsconfig.*\\.json)$",
|
|
110
|
+
"run": ["{engine}/src/helpers/type-errors.ts", "--strictNullChecks", "--strictPropertyInitialization"],
|
|
111
|
+
"compare": "turn-start",
|
|
112
|
+
"watch": {
|
|
113
|
+
"run": [
|
|
114
|
+
"{engine}/src/helpers/type-errors.ts",
|
|
115
|
+
"--watch",
|
|
116
|
+
"--strictNullChecks",
|
|
117
|
+
"--strictPropertyInitialization"
|
|
118
|
+
],
|
|
119
|
+
"cycleStart": "^Type check started$",
|
|
120
|
+
"cycleEnd": "^Type check done$"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
97
124
|
{
|
|
98
125
|
"description": "Fails on the unused files, exports and dependencies the turn added, never on the ones already there, so it works on a repo that already has some.",
|
|
99
126
|
"requires": [
|
package/dist/src/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { configuredRoot } from "./core/config.js";
|
|
|
5
5
|
import { messageOf } from "./core/json.js";
|
|
6
6
|
import { broken, reports, summary } from "./core/report.js";
|
|
7
7
|
import { failed } from "./core/run.js";
|
|
8
|
-
import { handleHook } from "./hook/hook.js";
|
|
8
|
+
import { HOOK_EVENTS, handleHook, isHookEvent } from "./hook/hook.js";
|
|
9
9
|
function readStdin() {
|
|
10
10
|
try {
|
|
11
11
|
return readFileSync(0, "utf8");
|
|
@@ -15,7 +15,7 @@ function readStdin() {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
/** What the command prints when it is called with words it does not know, named by the bin of the npm package. */
|
|
18
|
-
export const USAGE =
|
|
18
|
+
export const USAGE = `Usage: deterministic-gates check, or deterministic-gates hook <${HOOK_EVENTS.join("|")}>`;
|
|
19
19
|
// The helpers of the engine run only on import.meta.main, which came with Node 24.2: below, they are a silent green.
|
|
20
20
|
const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
|
|
21
21
|
const oldNode = major < 24 || (major === 24 && minor < 2)
|
|
@@ -30,7 +30,7 @@ async function main([command, event]) {
|
|
|
30
30
|
process.exitCode = 2;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
else if (command === "hook" && (event
|
|
33
|
+
else if (command === "hook" && isHookEvent(event)) {
|
|
34
34
|
const output = await handleHook(event, readStdin());
|
|
35
35
|
if (output)
|
|
36
36
|
console.log(JSON.stringify(output));
|
package/dist/src/core/check.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { changedGatesFiles, gatesOf, isCompared, readGatesFiles } from "./config.js";
|
|
3
|
+
import { changedGatesFiles, gatesOf, isCompared, keepsWatch, readGatesFiles } from "./config.js";
|
|
4
4
|
import { cachedReports, cacheReports } from "./report-cache.js";
|
|
5
5
|
import { check, filesOf, givenFiles, missingTool, wholeProject } from "./run.js";
|
|
6
6
|
import { changedSince, emptyCommit, hasCommit, lastCommit, snapshot, workingTree } from "./snapshot.js";
|
|
7
7
|
import { readTurn, writeTurn } from "./turn-state.js";
|
|
8
|
+
import { judgeWatch, keepWatch, startWatch, watchReport } from "./watch.js";
|
|
8
9
|
function missingTools(root, gates) {
|
|
9
10
|
return gates.flatMap((gate) => {
|
|
10
11
|
const why = missingTool(root, gate);
|
|
@@ -14,6 +15,16 @@ function missingTools(root, gates) {
|
|
|
14
15
|
function runnable(gates, missing) {
|
|
15
16
|
return gates.filter((gate) => !missing.some((tool) => tool.gate === gate));
|
|
16
17
|
}
|
|
18
|
+
function startWatches(session, root, gates) {
|
|
19
|
+
for (const gate of gates)
|
|
20
|
+
if (keepsWatch(gate))
|
|
21
|
+
startWatch(session, root, gate);
|
|
22
|
+
}
|
|
23
|
+
/** Starts the watches of the gates of a repo that are not running yet, so their first build runs before a turn. */
|
|
24
|
+
export function startSession(session, root) {
|
|
25
|
+
const { gates } = gatesOf(readGatesFiles(root));
|
|
26
|
+
startWatches(session, root, runnable(gates, missingTools(root, gates)));
|
|
27
|
+
}
|
|
17
28
|
/**
|
|
18
29
|
* Records the commit a turn starts from, and the reports its compared gates will compare with. After an interrupted
|
|
19
30
|
* turn, the next one of the repo starts where it did, so its check also covers what the interrupted one changed.
|
|
@@ -25,6 +36,7 @@ export async function startTurn(session, root) {
|
|
|
25
36
|
const missing = missingTools(root, gates);
|
|
26
37
|
const told = missing.map(({ gate, why }) => `${gate.name}: ${why}`);
|
|
27
38
|
const compared = runnable(gates, missing).filter(isCompared);
|
|
39
|
+
startWatches(session, root, runnable(gates, missing));
|
|
28
40
|
const interrupted = readTurn(session, root);
|
|
29
41
|
if (interrupted?.checked === false) {
|
|
30
42
|
writeTurn(session, root, interrupted);
|
|
@@ -34,17 +46,19 @@ export async function startTurn(session, root) {
|
|
|
34
46
|
const cached = cachedReports(root, tree);
|
|
35
47
|
const baselines = await Promise.all(compared.map(async (gate) => {
|
|
36
48
|
const cachedReport = cached(gate);
|
|
37
|
-
|
|
38
|
-
gate,
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
if (cachedReport !== undefined)
|
|
50
|
+
return { gate, ok: true, output: cachedReport };
|
|
51
|
+
if (!keepsWatch(gate))
|
|
52
|
+
return { gate, ...(await wholeProject(root, gate)) };
|
|
53
|
+
const output = await watchReport(session, root, gate);
|
|
54
|
+
return { gate, ok: output !== undefined, output };
|
|
41
55
|
}));
|
|
42
56
|
// A report from a command that broke still serves this turn, since checking too much beats leaving a hole, but it
|
|
43
57
|
// is never kept for the next one.
|
|
44
|
-
cacheReports(root, tree, baselines.
|
|
58
|
+
cacheReports(root, tree, baselines.flatMap(({ gate, ok, output }) => (ok && output !== undefined ? [[gate, output]] : [])));
|
|
45
59
|
writeTurn(session, root, {
|
|
46
60
|
start,
|
|
47
|
-
baselines: Object.fromEntries(baselines.
|
|
61
|
+
baselines: Object.fromEntries(baselines.flatMap(({ gate, output }) => (output === undefined ? [] : [[gate.name, output]]))),
|
|
48
62
|
config,
|
|
49
63
|
checked: false,
|
|
50
64
|
});
|
|
@@ -53,14 +67,17 @@ export async function startTurn(session, root) {
|
|
|
53
67
|
/**
|
|
54
68
|
* Runs, in parallel, each gate that looks at a changed file. A deleted file counts as changed, since a gate that
|
|
55
69
|
* reads the whole project may break on it, but is never named: a gate given {files} looks at the files left, and
|
|
56
|
-
* is skipped when none is.
|
|
70
|
+
* is skipped when none is. At the end of a turn of a session, a gate that keeps a watch is judged on it instead of
|
|
71
|
+
* running.
|
|
57
72
|
*/
|
|
58
|
-
function runGates(root, gates, changed, turn, baselines) {
|
|
73
|
+
function runGates(root, gates, changed, turn, baselines, session) {
|
|
59
74
|
return Promise.all(gates.map(async (gate) => {
|
|
60
75
|
const matching = filesOf(gate, changed);
|
|
61
76
|
const files = givenFiles(gate) ? matching.filter((file) => existsSync(join(root, file))) : matching;
|
|
62
77
|
if (!files.length)
|
|
63
78
|
return { gate };
|
|
79
|
+
if (session !== undefined && keepsWatch(gate))
|
|
80
|
+
return { gate, outcome: await judgeWatch(session, root, gate, matching, baselines(gate)) };
|
|
64
81
|
return { gate, outcome: await check(root, gate, files, turn, baselines(gate)) };
|
|
65
82
|
}));
|
|
66
83
|
}
|
|
@@ -127,13 +144,19 @@ export async function checkTurn(session, root) {
|
|
|
127
144
|
const changed = changedSince(root, turn.start, end);
|
|
128
145
|
const { gates, refused, showAllPasses } = gatesOf(turn.config);
|
|
129
146
|
const missing = missingTools(root, gates);
|
|
130
|
-
const
|
|
147
|
+
for (const gate of gates)
|
|
148
|
+
if (keepsWatch(gate))
|
|
149
|
+
keepWatch(root, gate);
|
|
150
|
+
const results = await runGates(root, runnable(gates, missing), changed, turn.start, baselines, session);
|
|
131
151
|
cacheReports(root, end, endReports(results, baselines));
|
|
132
152
|
writeTurn(session, root, { ...turn, checked: true });
|
|
133
|
-
// A compared gate with no report from the turn start can only count its exit code
|
|
153
|
+
// A compared gate with no report from the turn start can only count its exit code, and a watch has none: a green it
|
|
154
|
+
// did not earn is said.
|
|
134
155
|
const uncompared = results
|
|
135
156
|
.filter(({ gate, outcome }) => outcome && isCompared(gate) && baselines(gate) === undefined)
|
|
136
|
-
.map(({ gate }) =>
|
|
157
|
+
.map(({ gate }) => keepsWatch(gate)
|
|
158
|
+
? `${gate.name} not judged: no report from the turn start to compare its cycle with`
|
|
159
|
+
: `${gate.name} not compared: no report from the turn start, only its exit code counted`);
|
|
137
160
|
// Only a gate the turn concerned is named: one that would not have run anyway costs nothing to miss.
|
|
138
161
|
const notRun = missing
|
|
139
162
|
.filter(({ gate }) => filesOf(gate, changed).length)
|
package/dist/src/core/config.js
CHANGED
|
@@ -8,10 +8,14 @@ const LOCAL_GATES_FILE = ".gates.local.json";
|
|
|
8
8
|
const DEFAULT_MAX_TIMEOUT_SECONDS = 45;
|
|
9
9
|
// The times a turn sends the agent back: enough for a fix that breaks another gate, never a loop.
|
|
10
10
|
const DEFAULT_MAX_SEND_BACKS = 5;
|
|
11
|
-
const FIELDS = new Set(["name", "severity", "files", "run", "compare", "ignoreLines", "timeoutSeconds"]);
|
|
11
|
+
const FIELDS = new Set(["name", "severity", "files", "run", "compare", "ignoreLines", "timeoutSeconds", "watch"]);
|
|
12
|
+
const WATCH_FIELDS = new Set(["run", "cycleStart", "cycleEnd", "failed"]);
|
|
12
13
|
/** In the arguments of a gate: the changed files it looks at, and the commit of the turn start. */
|
|
13
14
|
export const FILES = "{files}";
|
|
14
15
|
export const TURN = "{turn}";
|
|
16
|
+
export function keepsWatch(gate) {
|
|
17
|
+
return gate.watch !== undefined;
|
|
18
|
+
}
|
|
15
19
|
/** A gate that fails on the lines of output the turn added, with the report of the turn start to compare with. */
|
|
16
20
|
export function isCompared(gate) {
|
|
17
21
|
return gate.compare === "turn-start";
|
|
@@ -78,8 +82,29 @@ function isPattern(value) {
|
|
|
78
82
|
return false;
|
|
79
83
|
}
|
|
80
84
|
}
|
|
85
|
+
function toWatch(watch, compared) {
|
|
86
|
+
if (!isRecord(watch))
|
|
87
|
+
return refuse("watch holds run, cycleStart, cycleEnd and failed");
|
|
88
|
+
const unknown = Object.keys(watch).find((key) => !WATCH_FIELDS.has(key));
|
|
89
|
+
if (unknown !== undefined)
|
|
90
|
+
refuse(`unknown field watch.${unknown}`);
|
|
91
|
+
const { run, cycleStart, cycleEnd, failed } = watch;
|
|
92
|
+
if (!isStringArray(run) || !run.length)
|
|
93
|
+
refuse("watch.run is a non-empty list of strings");
|
|
94
|
+
if (run.some((argument) => argument.includes(FILES) || argument.includes(TURN)))
|
|
95
|
+
refuse(`a watch outlives the turn: its run takes neither ${FILES} nor ${TURN}`);
|
|
96
|
+
const pattern = (field, value) => isPattern(value) ? value : refuse(`watch.${field} is a regular expression on a line of its output`);
|
|
97
|
+
if (compared && failed !== undefined)
|
|
98
|
+
refuse("a compared watch fails on the lines its cycle added: no watch.failed");
|
|
99
|
+
return {
|
|
100
|
+
run,
|
|
101
|
+
cycleStart: pattern("cycleStart", cycleStart),
|
|
102
|
+
cycleEnd: pattern("cycleEnd", cycleEnd),
|
|
103
|
+
...(compared ? {} : { failed: pattern("failed", failed) }),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
81
106
|
function toGate(entry, maxTimeoutSeconds) {
|
|
82
|
-
const { name, severity, files, run, compare, ignoreLines, timeoutSeconds = maxTimeoutSeconds } = entry;
|
|
107
|
+
const { name, severity, files, run, compare, ignoreLines, watch, timeoutSeconds = maxTimeoutSeconds } = entry;
|
|
83
108
|
const unknown = Object.keys(entry).find((key) => !FIELDS.has(key));
|
|
84
109
|
if (unknown !== undefined)
|
|
85
110
|
refuse(`unknown field ${unknown}`);
|
|
@@ -108,6 +133,7 @@ function toGate(entry, maxTimeoutSeconds) {
|
|
|
108
133
|
timeoutSeconds: Math.min(timeoutSeconds, maxTimeoutSeconds),
|
|
109
134
|
...(compare === undefined ? {} : { compare }),
|
|
110
135
|
...(ignoreLines === undefined ? {} : { ignoreLines }),
|
|
136
|
+
...(watch === undefined ? {} : { watch: toWatch(watch, compare !== undefined) }),
|
|
111
137
|
};
|
|
112
138
|
}
|
|
113
139
|
/**
|
|
@@ -3,8 +3,12 @@ import { writeFileSync } from "node:fs";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { isRecord, isStringRecord, readJsonFile } from "./json.js";
|
|
6
|
+
import { ENGINE_VERSION } from "./run.js";
|
|
6
7
|
function isCache(value) {
|
|
7
|
-
return isRecord(value) &&
|
|
8
|
+
return (isRecord(value) &&
|
|
9
|
+
typeof value.engine === "string" &&
|
|
10
|
+
typeof value.tree === "string" &&
|
|
11
|
+
isStringRecord(value.reports));
|
|
8
12
|
}
|
|
9
13
|
function cacheFile(root) {
|
|
10
14
|
const repo = createHash("sha256").update(root).digest("hex").slice(0, 16);
|
|
@@ -15,7 +19,7 @@ function commandOf(gate) {
|
|
|
15
19
|
}
|
|
16
20
|
function readCache(root) {
|
|
17
21
|
const cache = readJsonFile(cacheFile(root));
|
|
18
|
-
return isCache(cache) ? cache : undefined;
|
|
22
|
+
return isCache(cache) && cache.engine === ENGINE_VERSION ? cache : undefined;
|
|
19
23
|
}
|
|
20
24
|
export function cachedReports(root, tree) {
|
|
21
25
|
const cache = readCache(root);
|
|
@@ -25,6 +29,7 @@ export function cachedReports(root, tree) {
|
|
|
25
29
|
export function cacheReports(root, tree, reports) {
|
|
26
30
|
const kept = readCache(root);
|
|
27
31
|
const cache = {
|
|
32
|
+
engine: ENGINE_VERSION,
|
|
28
33
|
tree,
|
|
29
34
|
reports: {
|
|
30
35
|
...(kept?.tree === tree ? kept.reports : {}),
|
package/dist/src/core/run.js
CHANGED
|
@@ -9,6 +9,11 @@ export function failed(outcome) {
|
|
|
9
9
|
return !outcome.ok && !outcome.timedOut;
|
|
10
10
|
}
|
|
11
11
|
const ENGINE = resolve(import.meta.dirname, "..", "..");
|
|
12
|
+
const manifest = readJsonFile(join(ENGINE, "package.json"));
|
|
13
|
+
/** The version of this engine: what its helpers print, so what a report holds, may change from one to the next. */
|
|
14
|
+
export const ENGINE_VERSION = isRecord(manifest) ? String(manifest.version) : "";
|
|
15
|
+
/** What a tool runs with: no colour, which some tools print anyway. */
|
|
16
|
+
export const TOOL_ENV = { ...process.env, NO_COLOR: "1", FORCE_COLOR: "0" };
|
|
12
17
|
const MAX_OUTPUT_MB = 16;
|
|
13
18
|
const ENGINE_PREFIX = "{engine}/";
|
|
14
19
|
/** A script of this engine: its .ts source, or the .js it is built to when the engine runs from its npm package. */
|
|
@@ -77,20 +82,23 @@ function executable(file) {
|
|
|
77
82
|
}
|
|
78
83
|
});
|
|
79
84
|
}
|
|
80
|
-
|
|
81
|
-
* Why the program of a gate cannot run on this machine, or nothing when it can: looked up as the gate would start it,
|
|
82
|
-
* without starting it. A command the engine cannot resolve is left to the run, which reports it.
|
|
83
|
-
*/
|
|
84
|
-
export function missingTool(root, gate) {
|
|
85
|
+
function missingProgram(root, name) {
|
|
85
86
|
let command;
|
|
86
87
|
try {
|
|
87
|
-
command = commandOf(root,
|
|
88
|
+
command = commandOf(root, name);
|
|
88
89
|
}
|
|
89
90
|
catch {
|
|
90
91
|
return undefined;
|
|
91
92
|
}
|
|
92
93
|
return command.missing && !executable(command.file) ? command.missing : undefined;
|
|
93
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Why the program of a gate, or of its watch, cannot run on this machine, or nothing when they can: looked up as the
|
|
97
|
+
* gate would start it, without starting it. A command the engine cannot resolve is left to the run, which reports it.
|
|
98
|
+
*/
|
|
99
|
+
export function missingTool(root, gate) {
|
|
100
|
+
return missingProgram(root, gate.run[0] ?? "") ?? (gate.watch && missingProgram(root, gate.watch.run[0] ?? ""));
|
|
101
|
+
}
|
|
94
102
|
export function argumentsOf(gate, files, turn) {
|
|
95
103
|
return gate.run.slice(1).flatMap((argument) => (argument === FILES ? files : [argument.replaceAll(TURN, turn)]));
|
|
96
104
|
}
|
|
@@ -126,7 +134,7 @@ async function execute(root, gate, args) {
|
|
|
126
134
|
cwd: root,
|
|
127
135
|
timeout: gate.timeoutSeconds * 1000,
|
|
128
136
|
maxBuffer: MAX_OUTPUT_MB * 1024 * 1024,
|
|
129
|
-
env:
|
|
137
|
+
env: TOOL_ENV,
|
|
130
138
|
}, (error, stdout, stderr) => {
|
|
131
139
|
resolve({
|
|
132
140
|
ok: !error,
|
|
@@ -144,12 +152,15 @@ function outputOf(root, gate, command, error, printed) {
|
|
|
144
152
|
return `Out of time after ${gate.timeoutSeconds} s, so not judged. Make it faster, or move it to CI.`;
|
|
145
153
|
if (error?.code === "ENOENT")
|
|
146
154
|
return command.missing;
|
|
147
|
-
|
|
148
|
-
const said = stripVTControlCharacters(printed).split(`${root}${sep}`).join("").trim();
|
|
155
|
+
const said = cleaned(root, printed);
|
|
149
156
|
if (said || !error)
|
|
150
157
|
return said;
|
|
151
158
|
return `exit code ${String(error.code)}, no output`;
|
|
152
159
|
}
|
|
160
|
+
/** What a tool printed, for the agent: some tools colour despite NO_COLOR, and absolute paths only cost it tokens. */
|
|
161
|
+
export function cleaned(root, printed) {
|
|
162
|
+
return stripVTControlCharacters(printed).split(`${root}${sep}`).join("").trim();
|
|
163
|
+
}
|
|
153
164
|
/** Runs a compared gate on the whole project, as the turn starts. */
|
|
154
165
|
export function wholeProject(root, gate) {
|
|
155
166
|
return execute(root, gate, gate.run.slice(1));
|
|
@@ -165,8 +176,15 @@ export async function check(root, gate, files, turn, baseline) {
|
|
|
165
176
|
return { ...ran, ok, output, timedOut };
|
|
166
177
|
if (!isCompared(gate) || !ok)
|
|
167
178
|
return { ...ran, ok, output };
|
|
179
|
+
return { ...ran, ...addedLines(gate, output, baseline) };
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Judges the output of a compared gate that ran clean: it fails on the lines the turn added to the report of the turn
|
|
183
|
+
* start. Without that report, nothing counts but the exit code.
|
|
184
|
+
*/
|
|
185
|
+
export function addedLines(gate, output, baseline) {
|
|
168
186
|
if (baseline === undefined)
|
|
169
|
-
return {
|
|
187
|
+
return { ok: true, output: "" };
|
|
170
188
|
const added = newLines(baseline, output, gate.ignoreLines);
|
|
171
|
-
return {
|
|
189
|
+
return { ok: added.length === 0, output: added.join("\n") };
|
|
172
190
|
}
|