@tayomi/deterministic-gates 0.10.0 → 0.12.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/catalog/go.json +9 -5
- package/catalog/index.html +9 -5
- package/dist/src/cli.js +2 -2
- package/dist/src/core/check.js +59 -21
- package/dist/src/core/config.js +22 -5
- package/dist/src/core/head.js +76 -22
- package/dist/src/core/projects.js +43 -0
- package/dist/src/core/report.js +41 -17
- package/dist/src/core/run.js +115 -21
- package/dist/src/core/snapshot.js +72 -15
- package/dist/src/core/turn-state.js +14 -2
- package/dist/src/helpers/new-clones.js +90 -16
- package/package.json +1 -1
- package/src/cli.ts +2 -2
- package/src/core/check.ts +67 -29
- package/src/core/config.ts +28 -4
- package/src/core/head.ts +99 -30
- package/src/core/projects.ts +54 -0
- package/src/core/report.ts +44 -16
- package/src/core/run.ts +144 -18
- package/src/core/snapshot.ts +87 -20
- package/src/core/turn-state.ts +20 -3
- package/src/helpers/new-clones.ts +105 -15
|
@@ -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.12.0",
|
|
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",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deterministic-gates",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Deterministic backpressure for coding agents: gates that run on what each turn changed and send the agent back until they pass.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Pierre Moati",
|
package/catalog/go.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "Go",
|
|
3
|
-
"description": "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.",
|
|
3
|
+
"description": "Gates for a Go module, or for a repo of several. The build, vet, test and lint gates run in each module the turn touched, from the folder of its go.mod, so a monorepo with no module at its root needs nothing more. In a module too large to read whole when the agent stops, write {dirs} in place of ./... to aim a gate at the folders the turn touched. The toolchain comes from the PATH. The first build of a cold cache is slow, which is why these gates allow 60 seconds.",
|
|
4
4
|
"gates": [
|
|
5
5
|
{
|
|
6
|
-
"description": "Builds every package of the
|
|
6
|
+
"description": "Builds every package of each module the turn touched.",
|
|
7
7
|
"requires": [
|
|
8
8
|
{
|
|
9
9
|
"tool": "go",
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
"name": "build",
|
|
15
15
|
"severity": "error",
|
|
16
16
|
"files": "(\\.go|(^|/)go\\.(mod|sum))$",
|
|
17
|
+
"each": "go.mod",
|
|
17
18
|
"run": ["go", "build", "./..."]
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
21
|
{
|
|
21
|
-
"description": "Runs go vet on every package: the suspicious constructs the compiler accepts.",
|
|
22
|
+
"description": "Runs go vet on every package of each module the turn touched: the suspicious constructs the compiler accepts.",
|
|
22
23
|
"requires": [
|
|
23
24
|
{
|
|
24
25
|
"tool": "go",
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"name": "vet",
|
|
30
31
|
"severity": "error",
|
|
31
32
|
"files": "(\\.go|(^|/)go\\.(mod|sum))$",
|
|
33
|
+
"each": "go.mod",
|
|
32
34
|
"run": ["go", "vet", "./..."]
|
|
33
35
|
}
|
|
34
36
|
},
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
}
|
|
50
52
|
},
|
|
51
53
|
{
|
|
52
|
-
"description": "Runs the tests of every package. Go caches the result of a package that did not change, so only the packages the turn touched run again.",
|
|
54
|
+
"description": "Runs the tests of every package of each module the turn touched. Go caches the result of a package that did not change, so only the packages the turn touched run again.",
|
|
53
55
|
"requires": [
|
|
54
56
|
{
|
|
55
57
|
"tool": "go",
|
|
@@ -60,11 +62,12 @@
|
|
|
60
62
|
"name": "test",
|
|
61
63
|
"severity": "error",
|
|
62
64
|
"files": "(\\.go|(^|/)go\\.(mod|sum))$",
|
|
65
|
+
"each": "go.mod",
|
|
63
66
|
"run": ["go", "test", "./..."]
|
|
64
67
|
}
|
|
65
68
|
},
|
|
66
69
|
{
|
|
67
|
-
"description": "Lints with golangci-lint, and reports only the issues created since the turn started (--new-from-rev).",
|
|
70
|
+
"description": "Lints each module the turn touched with golangci-lint, and reports only the issues created since the turn started (--new-from-rev).",
|
|
68
71
|
"requires": [
|
|
69
72
|
{
|
|
70
73
|
"tool": "golangci-lint",
|
|
@@ -75,6 +78,7 @@
|
|
|
75
78
|
"name": "lint",
|
|
76
79
|
"severity": "error",
|
|
77
80
|
"files": "\\.go$",
|
|
81
|
+
"each": "go.mod",
|
|
78
82
|
"run": ["golangci-lint", "run", "--new-from-rev", "{turn}"]
|
|
79
83
|
}
|
|
80
84
|
},
|
package/catalog/index.html
CHANGED
|
@@ -170,10 +170,10 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
170
170
|
</section>
|
|
171
171
|
<section id="go">
|
|
172
172
|
<h2>Go</h2>
|
|
173
|
-
<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>
|
|
173
|
+
<p>Gates for a Go module, or for a repo of several. The build, vet, test and lint gates run in each module the turn touched, from the folder of its go.mod, so a monorepo with no module at its root needs nothing more. In a module too large to read whole when the agent stops, write {dirs} in place of ./... to aim a gate at the folders the turn touched. The toolchain comes from the PATH. The first build of a cold cache is slow, which is why these gates allow 60 seconds.</p>
|
|
174
174
|
<article id="go/build">
|
|
175
175
|
<h3><code>go/build</code></h3>
|
|
176
|
-
<p>Builds every package of the
|
|
176
|
+
<p>Builds every package of each module the turn touched.</p>
|
|
177
177
|
<dl>
|
|
178
178
|
<dt>Runs</dt><dd><code>go build ./...</code></dd>
|
|
179
179
|
<dt>When the turn changes</dt><dd><code>(\.go|(^|/)go\.(mod|sum))$</code></dd>
|
|
@@ -183,6 +183,7 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
183
183
|
"name": "build",
|
|
184
184
|
"severity": "error",
|
|
185
185
|
"files": "(\\.go|(^|/)go\\.(mod|sum))$",
|
|
186
|
+
"each": "go.mod",
|
|
186
187
|
"run": [
|
|
187
188
|
"go",
|
|
188
189
|
"build",
|
|
@@ -192,7 +193,7 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
192
193
|
</article>
|
|
193
194
|
<article id="go/vet">
|
|
194
195
|
<h3><code>go/vet</code></h3>
|
|
195
|
-
<p>Runs go vet on every package: the suspicious constructs the compiler accepts.</p>
|
|
196
|
+
<p>Runs go vet on every package of each module the turn touched: the suspicious constructs the compiler accepts.</p>
|
|
196
197
|
<dl>
|
|
197
198
|
<dt>Runs</dt><dd><code>go vet ./...</code></dd>
|
|
198
199
|
<dt>When the turn changes</dt><dd><code>(\.go|(^|/)go\.(mod|sum))$</code></dd>
|
|
@@ -202,6 +203,7 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
202
203
|
"name": "vet",
|
|
203
204
|
"severity": "error",
|
|
204
205
|
"files": "(\\.go|(^|/)go\\.(mod|sum))$",
|
|
206
|
+
"each": "go.mod",
|
|
205
207
|
"run": [
|
|
206
208
|
"go",
|
|
207
209
|
"vet",
|
|
@@ -231,7 +233,7 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
231
233
|
</article>
|
|
232
234
|
<article id="go/test">
|
|
233
235
|
<h3><code>go/test</code></h3>
|
|
234
|
-
<p>Runs the tests of every package. Go caches the result of a package that did not change, so only the packages the turn touched run again.</p>
|
|
236
|
+
<p>Runs the tests of every package of each module the turn touched. Go caches the result of a package that did not change, so only the packages the turn touched run again.</p>
|
|
235
237
|
<dl>
|
|
236
238
|
<dt>Runs</dt><dd><code>go test ./...</code></dd>
|
|
237
239
|
<dt>When the turn changes</dt><dd><code>(\.go|(^|/)go\.(mod|sum))$</code></dd>
|
|
@@ -241,6 +243,7 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
241
243
|
"name": "test",
|
|
242
244
|
"severity": "error",
|
|
243
245
|
"files": "(\\.go|(^|/)go\\.(mod|sum))$",
|
|
246
|
+
"each": "go.mod",
|
|
244
247
|
"run": [
|
|
245
248
|
"go",
|
|
246
249
|
"test",
|
|
@@ -250,7 +253,7 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
250
253
|
</article>
|
|
251
254
|
<article id="go/lint">
|
|
252
255
|
<h3><code>go/lint</code></h3>
|
|
253
|
-
<p>Lints with golangci-lint, and reports only the issues created since the turn started (--new-from-rev).</p>
|
|
256
|
+
<p>Lints each module the turn touched with golangci-lint, and reports only the issues created since the turn started (--new-from-rev).</p>
|
|
254
257
|
<dl>
|
|
255
258
|
<dt>Runs</dt><dd><code>golangci-lint run --new-from-rev {turn}</code></dd>
|
|
256
259
|
<dt>When the turn changes</dt><dd><code>\.go$</code></dd>
|
|
@@ -260,6 +263,7 @@ summary { cursor: pointer; color: var(--muted); }
|
|
|
260
263
|
"name": "lint",
|
|
261
264
|
"severity": "error",
|
|
262
265
|
"files": "\\.go$",
|
|
266
|
+
"each": "go.mod",
|
|
263
267
|
"run": [
|
|
264
268
|
"golangci-lint",
|
|
265
269
|
"run",
|
package/dist/src/cli.js
CHANGED
|
@@ -4,7 +4,6 @@ import { checkAll } from "./core/check.js";
|
|
|
4
4
|
import { configuredRoot } from "./core/config.js";
|
|
5
5
|
import { messageOf } from "./core/json.js";
|
|
6
6
|
import { broken, reports, results, summary } from "./core/report.js";
|
|
7
|
-
import { failed } from "./core/run.js";
|
|
8
7
|
import { HOOK_EVENTS, handleHook, isHookEvent } from "./hook/hook.js";
|
|
9
8
|
function readStdin() {
|
|
10
9
|
try {
|
|
@@ -48,7 +47,8 @@ async function main([command, ...words]) {
|
|
|
48
47
|
try {
|
|
49
48
|
const all = await checkAll(root);
|
|
50
49
|
console.log(json ? JSON.stringify(results(all), null, 2) : [summary(all), ...reports(all)].join("\n\n"));
|
|
51
|
-
|
|
50
|
+
// A gate out of time judged nothing: a CI never passes on it.
|
|
51
|
+
if (!all.outcomes.every(({ ok }) => ok))
|
|
52
52
|
process.exitCode = 1;
|
|
53
53
|
}
|
|
54
54
|
catch (error) {
|
package/dist/src/core/check.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { changedGatesFiles, gatesOf, isCompared, keepsWatch, readGatesFiles, } from "./config.js";
|
|
4
|
-
import { headOf, movedSince } from "./head.js";
|
|
4
|
+
import { headOf, movedSince, observed, thereOf } from "./head.js";
|
|
5
5
|
import { cachedReports, cacheReports } from "./report-cache.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { dirsOf, projectsOf } from "./projects.js";
|
|
7
|
+
import { check, checkEach, filesOf, givenDirs, givenFiles, missingTool, namesFiles, wholeProject, } from "./run.js";
|
|
8
|
+
import { changedSince, emptyCommit, hasCommit, lastCommit, sharedDir, snapshot, workingTree } from "./snapshot.js";
|
|
9
|
+
import { readThere, readTurn, writeThere, writeTurn } from "./turn-state.js";
|
|
9
10
|
import { judgeWatch, keepWatch, startWatch, TURN_START_MS, watchReport } from "./watch.js";
|
|
10
11
|
function missingTools(root, gates) {
|
|
11
12
|
return gates.flatMap((gate) => {
|
|
@@ -39,10 +40,17 @@ export async function startTurn(session, root) {
|
|
|
39
40
|
const compared = runnable(gates, missing).filter(isCompared);
|
|
40
41
|
startWatches(session, root, runnable(gates, missing));
|
|
41
42
|
const interrupted = readTurn(session, root);
|
|
43
|
+
// The worktrees of a repo share its commits: what the session knows of them is of the repo, not of the folder.
|
|
44
|
+
const shared = sharedDir(root);
|
|
45
|
+
const there = readThere(session, shared);
|
|
42
46
|
if (interrupted?.checked === false) {
|
|
43
|
-
|
|
47
|
+
// What it committed so far stays the session's, and a commit older than this prompt is one a fetch may bring.
|
|
48
|
+
if (there)
|
|
49
|
+
writeThere(session, shared, observed(root, there, interrupted.at ?? Date.now()));
|
|
50
|
+
writeTurn(session, root, { ...interrupted, at: Date.now() });
|
|
44
51
|
return told;
|
|
45
52
|
}
|
|
53
|
+
writeThere(session, shared, thereOf(root, there));
|
|
46
54
|
const head = headOf(root);
|
|
47
55
|
const { commit: start, tree } = snapshot(root);
|
|
48
56
|
// The turn starts before its reports are ready: a hook stopped for lack of time leaves it, never the turn before.
|
|
@@ -72,20 +80,41 @@ export async function startTurn(session, root) {
|
|
|
72
80
|
/**
|
|
73
81
|
* Runs, in parallel, each gate that looks at a changed file. A deleted file counts as changed, since a gate that
|
|
74
82
|
* reads the whole project may break on it, but is never named: a gate given {files} looks at the files left, and
|
|
75
|
-
* is skipped when none is.
|
|
76
|
-
*
|
|
83
|
+
* is skipped when none is. A gate given {dirs} looks at the folders of the changed files that are left, the folder
|
|
84
|
+
* of a deleted file among them, and 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
|
|
85
|
+
* running. Elsewhere, the reports of the turn start are of code HEAD has left since. A gate that runs in each
|
|
86
|
+
* project looks at the files that have one, and is skipped when none has.
|
|
77
87
|
*/
|
|
78
88
|
function runGates(root, gates, changed, turn, baselines, session, elsewhere = false) {
|
|
79
89
|
return Promise.all(gates.map(async (gate) => {
|
|
80
90
|
const matching = filesOf(gate, changed);
|
|
91
|
+
if (gate.each !== undefined) {
|
|
92
|
+
const projects = projectsIn(root, gate, gate.each, matching);
|
|
93
|
+
if (!projects.length)
|
|
94
|
+
return { gate };
|
|
95
|
+
// At the stop, someone waits: the time of the gate is for all its projects together.
|
|
96
|
+
return { gate, outcome: await checkEach(root, gate, projects, turn, session !== undefined) };
|
|
97
|
+
}
|
|
81
98
|
const files = givenFiles(gate) ? matching.filter((file) => existsSync(join(root, file))) : matching;
|
|
82
|
-
|
|
99
|
+
const dirs = givenDirs(gate) ? dirsOf(root, matching) : undefined;
|
|
100
|
+
if (!files.length || dirs?.length === 0)
|
|
83
101
|
return { gate };
|
|
84
102
|
if (session !== undefined && keepsWatch(gate))
|
|
85
103
|
return { gate, outcome: await judgeWatch(session, root, gate, matching, baselines(gate), elsewhere) };
|
|
86
|
-
return { gate, outcome: await check(root, gate, files, turn, baselines(gate), elsewhere) };
|
|
104
|
+
return { gate, outcome: await check(root, gate, files, turn, baselines(gate), elsewhere, dirs) };
|
|
87
105
|
}));
|
|
88
106
|
}
|
|
107
|
+
// The projects a gate runs in: a gate given {files} looks at the files left, a gate given {dirs} at the folders
|
|
108
|
+
// left, and either leaves out a project with none.
|
|
109
|
+
function projectsIn(root, gate, marker, matching) {
|
|
110
|
+
return projectsOf(root, marker, matching)
|
|
111
|
+
.map(({ dir, files }) => ({
|
|
112
|
+
dir,
|
|
113
|
+
files: givenFiles(gate) ? files.filter((file) => existsSync(join(root, dir, file))) : files,
|
|
114
|
+
...(givenDirs(gate) ? { dirs: dirsOf(join(root, dir), files) } : {}),
|
|
115
|
+
}))
|
|
116
|
+
.filter(({ files, dirs }) => files.length && dirs?.length !== 0);
|
|
117
|
+
}
|
|
89
118
|
function checkedTurn(changed, results, started, notes, { gates, prompts, maxTotalReportChars, showAllPasses }) {
|
|
90
119
|
return {
|
|
91
120
|
changed,
|
|
@@ -128,8 +157,7 @@ function endReports(results, baselines, elsewhere) {
|
|
|
128
157
|
* them mid-turn changes the next turn, never its own. Without a recorded start, the turn runs from the last commit
|
|
129
158
|
* with the gates of now; with a start git no longer has, from the last commit with the gates and the reports it
|
|
130
159
|
* started with: checking too much beats leaving a hole. When HEAD moved during the turn to code it did not write, as
|
|
131
|
-
* a checkout or a pull does, the turn is only
|
|
132
|
-
* turn committed before: the rest came with that commit.
|
|
160
|
+
* a checkout or a pull does, the turn is only the files unlike the ones that code holds: the rest came with it.
|
|
133
161
|
*/
|
|
134
162
|
export async function checkTurn(session, root) {
|
|
135
163
|
const recorded = readTurn(session, root);
|
|
@@ -145,28 +173,38 @@ export async function checkTurn(session, root) {
|
|
|
145
173
|
baselines: recorded?.baselines ?? {},
|
|
146
174
|
config: recorded?.config ?? now,
|
|
147
175
|
checked: false,
|
|
148
|
-
...(kept ? { head: kept.head,
|
|
176
|
+
...(kept ? { head: kept.head, at: kept.at } : {}),
|
|
149
177
|
// What the earlier stops of the turn told the agent goes on, so its send-backs and waivers add up.
|
|
150
178
|
...(recorded?.sendBacks ? { sendBacks: recorded.sendBacks } : {}),
|
|
151
179
|
};
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const
|
|
180
|
+
const shared = sharedDir(root);
|
|
181
|
+
const there = readThere(session, shared);
|
|
182
|
+
const moved = kept && there && movedSince(root, kept, there);
|
|
155
183
|
const started = performance.now();
|
|
156
184
|
const end = workingTree(root);
|
|
157
185
|
const since = changedSince(root, turn.start, end);
|
|
158
|
-
|
|
159
|
-
const changed =
|
|
186
|
+
// A file like the one a commit under HEAD holds came with that commit: the turn did not write it.
|
|
187
|
+
const changed = (moved?.under ?? []).reduce((files, commit) => {
|
|
188
|
+
const unlike = new Set(changedSince(root, commit, end));
|
|
189
|
+
return files.filter((file) => unlike.has(file));
|
|
190
|
+
}, since);
|
|
191
|
+
// Code came with a commit, or left with one: the tree the turn started on no longer tells what the turn wrote.
|
|
192
|
+
const elsewhere = moved !== undefined && (moved.arrived || changed.length < since.length);
|
|
193
|
+
// Where a gate given the turn starts from: then, the commit that brought the code.
|
|
194
|
+
const from = (elsewhere ? moved?.to : undefined) ?? turn.start;
|
|
195
|
+
// A report of code HEAD has left serves a gate whose lines name their file, to count the ones of the turn's files.
|
|
196
|
+
const baselines = (gate) => (elsewhere && !namesFiles(gate) ? undefined : turn.baselines[gate.name]);
|
|
160
197
|
const config = gatesOf(turn.config);
|
|
161
198
|
const { gates, refused } = config;
|
|
162
199
|
const missing = missingTools(root, gates);
|
|
163
200
|
for (const gate of gates)
|
|
164
201
|
if (keepsWatch(gate))
|
|
165
202
|
keepWatch(root, gate);
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
cacheReports(root, end, endReports(results, baselines, moved !== undefined));
|
|
203
|
+
const results = await runGates(root, runnable(gates, missing), changed, from, baselines, session, elsewhere);
|
|
204
|
+
cacheReports(root, end, endReports(results, baselines, elsewhere));
|
|
169
205
|
writeTurn(session, root, { ...turn, checked: true });
|
|
206
|
+
if (there)
|
|
207
|
+
writeThere(session, shared, observed(root, there, kept?.at ?? Date.now()));
|
|
170
208
|
// A compared gate with no report from the turn start can only count its exit code, and a watch has none: a green it
|
|
171
209
|
// did not earn is said.
|
|
172
210
|
const uncompared = results
|
|
@@ -182,7 +220,7 @@ export async function checkTurn(session, root) {
|
|
|
182
220
|
.map(({ gate, why }) => `${gate.name} not run: ${why}`);
|
|
183
221
|
const notes = [
|
|
184
222
|
...(startNote ? [startNote] : []),
|
|
185
|
-
...(
|
|
223
|
+
...(elsewhere ? ["HEAD moved during the turn to code it did not write: only what the turn wrote is checked"] : []),
|
|
186
224
|
...configNote(changedGatesFiles(turn.config, now)),
|
|
187
225
|
...uncompared,
|
|
188
226
|
...refusedNotes(refused),
|
package/dist/src/core/config.js
CHANGED
|
@@ -25,11 +25,15 @@ const FIELDS = new Set([
|
|
|
25
25
|
"maxReportChars",
|
|
26
26
|
"omitLines",
|
|
27
27
|
"brokenExitCodes",
|
|
28
|
+
"each",
|
|
28
29
|
]);
|
|
29
30
|
const WATCH_FIELDS = new Set(["run", "cycleStart", "cycleEnd", "failed", "sync", "frozen"]);
|
|
30
31
|
/** In the arguments of a gate: the changed files it looks at, and the commit of the turn start. */
|
|
31
32
|
export const FILES = "{files}";
|
|
33
|
+
export const DIRS = "{dirs}";
|
|
32
34
|
export const TURN = "{turn}";
|
|
35
|
+
/** Before the first word of a command: a script of this engine, where another word names one of the repo. */
|
|
36
|
+
export const ENGINE_PREFIX = "{engine}/";
|
|
33
37
|
/**
|
|
34
38
|
* What the engine tells the agent that a repo may word again: as it sends it back, as it asks for missing tools, and
|
|
35
39
|
* with the report of a gate the turn broke.
|
|
@@ -157,8 +161,8 @@ function toWatch(watch, compared) {
|
|
|
157
161
|
const { run, cycleStart, cycleEnd, failed, sync, frozen } = watch;
|
|
158
162
|
if (!isStringArray(run) || !run.length)
|
|
159
163
|
refuse("watch.run is a non-empty list of strings");
|
|
160
|
-
if (run.some((argument) =>
|
|
161
|
-
refuse(`a watch outlives the turn: its run takes
|
|
164
|
+
if (run.some((argument) => [FILES, DIRS, TURN].some((token) => argument.includes(token))))
|
|
165
|
+
refuse(`a watch outlives the turn: its run takes none of ${FILES}, ${DIRS} and ${TURN}`);
|
|
162
166
|
const pattern = (field, value) => isPattern(value) ? value : refuse(`watch.${field} is a regular expression on a line of its output`);
|
|
163
167
|
if (compared && failed !== undefined)
|
|
164
168
|
refuse("a compared watch fails on the lines its cycle added: no watch.failed");
|
|
@@ -176,7 +180,7 @@ function toWatch(watch, compared) {
|
|
|
176
180
|
};
|
|
177
181
|
}
|
|
178
182
|
function toGate(entry, maxTimeoutSeconds, reportChars) {
|
|
179
|
-
const { name, severity, files, run, compare, ignoreLines, lineKey, watch, prompt, omitLines, brokenExitCodes, timeoutSeconds = maxTimeoutSeconds, maxReportChars = reportChars, } = entry;
|
|
183
|
+
const { name, severity, files, run, compare, ignoreLines, lineKey, watch, prompt, omitLines, brokenExitCodes, each, timeoutSeconds = maxTimeoutSeconds, maxReportChars = reportChars, } = entry;
|
|
180
184
|
const unknown = Object.keys(entry).find((key) => !FIELDS.has(key));
|
|
181
185
|
if (unknown !== undefined)
|
|
182
186
|
refuse(`unknown field ${unknown}`);
|
|
@@ -190,8 +194,9 @@ function toGate(entry, maxTimeoutSeconds, reportChars) {
|
|
|
190
194
|
refuse("run is a non-empty list of strings");
|
|
191
195
|
if (compare !== undefined && compare !== "turn-start")
|
|
192
196
|
refuse('compare is "turn-start"');
|
|
193
|
-
|
|
194
|
-
|
|
197
|
+
const narrowed = [FILES, DIRS].find((token) => run.includes(token));
|
|
198
|
+
if (compare !== undefined && narrowed !== undefined)
|
|
199
|
+
refuse(`a compared gate reads the whole project: it takes no ${narrowed}`);
|
|
195
200
|
if (ignoreLines !== undefined && !isPattern(ignoreLines))
|
|
196
201
|
refuse("ignoreLines is a regular expression");
|
|
197
202
|
if (lineKey !== undefined && !isPattern(lineKey))
|
|
@@ -206,6 +211,17 @@ function toGate(entry, maxTimeoutSeconds, reportChars) {
|
|
|
206
211
|
refuse("omitLines is a regular expression");
|
|
207
212
|
if (brokenExitCodes !== undefined && !isExitCodes(brokenExitCodes))
|
|
208
213
|
refuse("brokenExitCodes is a list of exit codes, each a whole number from 1 to 255");
|
|
214
|
+
if (each !== undefined) {
|
|
215
|
+
if (typeof each !== "string" || !each || each === "." || each === ".." || /[\\/]/.test(each))
|
|
216
|
+
refuse("each is the name of the file that marks a project, such as go.mod: a name, not a path");
|
|
217
|
+
if (compare !== undefined)
|
|
218
|
+
refuse("a compared gate reports on the whole repo as the turn starts, before its projects are known: it takes no each");
|
|
219
|
+
if (watch !== undefined)
|
|
220
|
+
refuse("a watch is kept for the whole repo, not for each project: it takes no each");
|
|
221
|
+
// Such a script takes the folder it runs in for the root of the repo: in a project, it would read nothing.
|
|
222
|
+
if (run[0]?.startsWith(ENGINE_PREFIX))
|
|
223
|
+
refuse("a script of the engine reads the repo from its root: it takes no each");
|
|
224
|
+
}
|
|
209
225
|
const told = prompt === undefined ? undefined : (toPrompt(prompt) ?? refuse(`prompt is ${PROMPT_SHAPE}`));
|
|
210
226
|
return {
|
|
211
227
|
name,
|
|
@@ -222,6 +238,7 @@ function toGate(entry, maxTimeoutSeconds, reportChars) {
|
|
|
222
238
|
...(maxReportChars === undefined ? {} : { maxReportChars }),
|
|
223
239
|
...(omitLines === undefined ? {} : { omitLines }),
|
|
224
240
|
...(brokenExitCodes === undefined ? {} : { brokenExitCodes }),
|
|
241
|
+
...(each === undefined ? {} : { each }),
|
|
225
242
|
};
|
|
226
243
|
}
|
|
227
244
|
/**
|
package/dist/src/core/head.js
CHANGED
|
@@ -1,30 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// What takes HEAD to a commit the turn did not write, as the reflog names it. Any other move is a commit of the turn,
|
|
3
|
-
// as an amend or a cherry-pick: checking too much beats leaving a hole.
|
|
4
|
-
const NOT_ITS_COMMIT = /^(checkout|pull|merge|rebase|reset)\b/;
|
|
5
|
-
// A merge the turn commits brings the code of a branch too: of its files, the turn wrote the conflicts it resolved.
|
|
6
|
-
const ELSEWHERE = new RegExp(`${NOT_ITS_COMMIT.source}|^commit \\(merge\\)`);
|
|
1
|
+
import { branchTips, commitsPast, hasCommit, isIn } from "./snapshot.js";
|
|
7
2
|
export function headOf(root) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
return { moves: moves.length, ...(head === undefined ? {} : { head }) };
|
|
3
|
+
const { head } = branchTips(root);
|
|
4
|
+
return { ...(head === undefined ? {} : { head }), at: Date.now() };
|
|
11
5
|
}
|
|
12
6
|
/**
|
|
13
|
-
*
|
|
14
|
-
* a
|
|
7
|
+
* What a session knows of a repo as a turn starts there, from what it knew: the commit HEAD is on was there, since
|
|
8
|
+
* a turn that made it has been judged on it. Before its first turn, the tips of the branches were.
|
|
15
9
|
*/
|
|
16
|
-
export function
|
|
17
|
-
|
|
10
|
+
export function thereOf(root, before) {
|
|
11
|
+
const { head, tips } = branchTips(root);
|
|
12
|
+
if (before === undefined)
|
|
13
|
+
return { known: tips, made: [] };
|
|
14
|
+
return { known: [...new Set([...before.known, ...(head === undefined ? [] : [head])])], made: before.made };
|
|
15
|
+
}
|
|
16
|
+
/** The commits the session made, among the ones past what it knew: the ones it saw as its own, and the ones of the turn. */
|
|
17
|
+
function madeOf(past, { made }, at) {
|
|
18
|
+
const seen = new Set(made);
|
|
19
|
+
const started = Math.floor(at / 1000);
|
|
20
|
+
return past.filter((commit) => seen.has(commit.hash) || commit.at >= started);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* What the session knows once a turn that started then stops: with the commits the turn made, on whatever branch, so
|
|
24
|
+
* that they stay its own in the turns after. Less the known commits git no longer has, as after a deleted branch.
|
|
25
|
+
*/
|
|
26
|
+
export function observed(root, there, at) {
|
|
27
|
+
const seen = (known) => {
|
|
28
|
+
const mine = madeOf(commitsPast(root, branchTips(root).tips, known), there, at);
|
|
29
|
+
return { known, made: [...new Set([...there.made, ...mine.map(({ hash }) => hash)])] };
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
return seen(there.known);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
const kept = there.known.filter((commit) => hasCommit(root, commit));
|
|
36
|
+
try {
|
|
37
|
+
return seen(kept);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return { known: kept, made: there.made };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** The commits that were there, nearest under a commit: itself, or the ones under the commits the session made. */
|
|
45
|
+
function under(tip, made) {
|
|
46
|
+
const there = new Set();
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
const left = [tip];
|
|
49
|
+
for (let commit = left.pop(); commit !== undefined; commit = left.pop()) {
|
|
50
|
+
if (seen.has(commit))
|
|
51
|
+
continue;
|
|
52
|
+
seen.add(commit);
|
|
53
|
+
const parents = made.get(commit);
|
|
54
|
+
if (parents === undefined)
|
|
55
|
+
there.add(commit);
|
|
56
|
+
else
|
|
57
|
+
left.push(...parents);
|
|
58
|
+
}
|
|
59
|
+
return [...there];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Whether the code under HEAD that the session did not write changed since the turn started, as after a checkout, a
|
|
63
|
+
* pull, a merge, a rebase or a reset. Nothing when it did not, as after a commit of the turn, or a branch it left and
|
|
64
|
+
* came back to; nor when nothing tells any more, where all the turn changed is checked.
|
|
65
|
+
*/
|
|
66
|
+
export function movedSince(root, { head, at }, there) {
|
|
67
|
+
const now = branchTips(root).head;
|
|
68
|
+
if (head === undefined || at === undefined || now === undefined || now === head)
|
|
18
69
|
return undefined;
|
|
19
|
-
|
|
20
|
-
|
|
70
|
+
let past;
|
|
71
|
+
try {
|
|
72
|
+
past = commitsPast(root, [now, head], there.known);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
21
75
|
return undefined;
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
if (move === undefined)
|
|
76
|
+
}
|
|
77
|
+
const made = new Map(madeOf(past, there, at).map(({ hash, parents }) => [hash, parents]));
|
|
78
|
+
const [before, after] = [under(head, made), under(now, made)];
|
|
79
|
+
if (after.length === before.length && after.every((commit) => before.includes(commit)))
|
|
27
80
|
return undefined;
|
|
28
|
-
const
|
|
29
|
-
|
|
81
|
+
const brought = after.find((commit) => !before.some((had) => isIn(root, commit, had)));
|
|
82
|
+
const to = brought ?? after.find((commit) => !before.includes(commit));
|
|
83
|
+
return { under: after, arrived: brought !== undefined, ...(to === undefined ? {} : { to }) };
|
|
30
84
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const ROOT = ".";
|
|
4
|
+
/**
|
|
5
|
+
* Groups the repo-relative files a gate looks at by project: the nearest folder above each, up to the root of the
|
|
6
|
+
* repo and never past it, that holds the marker now. A file with no marker above it is of no project, which is what
|
|
7
|
+
* leaves out the folders a gate has nothing to do in. A deleted file is looked up from the folder it was in.
|
|
8
|
+
*/
|
|
9
|
+
export function projectsOf(root, marker, files) {
|
|
10
|
+
const holds = new Map();
|
|
11
|
+
const holdsMarker = (dir) => {
|
|
12
|
+
if (!holds.has(dir))
|
|
13
|
+
holds.set(dir, existsSync(join(root, dir, marker)));
|
|
14
|
+
return holds.get(dir) === true;
|
|
15
|
+
};
|
|
16
|
+
const projects = new Map();
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const folders = file.split("/").slice(0, -1);
|
|
19
|
+
// From the folder of the file up to the root, which no folder names.
|
|
20
|
+
const above = folders.map((_, depth) => folders.slice(0, folders.length - depth).join("/"));
|
|
21
|
+
const dir = [...above, ROOT].find(holdsMarker);
|
|
22
|
+
if (dir === undefined)
|
|
23
|
+
continue;
|
|
24
|
+
const inProject = dir === ROOT ? file : file.slice(dir.length + 1);
|
|
25
|
+
projects.set(dir, [...(projects.get(dir) ?? []), inProject]);
|
|
26
|
+
}
|
|
27
|
+
return [...projects]
|
|
28
|
+
.map(([dir, inProject]) => ({ dir, files: inProject }))
|
|
29
|
+
.sort((a, b) => (a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The folders of the files, each once and sorted, as a tool that runs in `base` is to be given them: with ./ in
|
|
33
|
+
* front, which a tool such as go needs to read a folder and not an import path, and a dot for `base` itself. A
|
|
34
|
+
* deleted file counts for its folder, since what is left there may break on it, but a folder that is gone is left
|
|
35
|
+
* out. A folder inside another stands next to it: what joins the two is for the tool to know.
|
|
36
|
+
*/
|
|
37
|
+
export function dirsOf(base, files) {
|
|
38
|
+
const dirs = new Set(files.map((file) => file.split("/").slice(0, -1).join("/")));
|
|
39
|
+
return [...dirs]
|
|
40
|
+
.filter((dir) => existsSync(join(base, dir)))
|
|
41
|
+
.sort()
|
|
42
|
+
.map((dir) => (dir ? `./${dir}` : ROOT));
|
|
43
|
+
}
|