@tayomi/deterministic-gates 0.6.0 → 0.7.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.
@@ -9,7 +9,7 @@
9
9
  "name": "deterministic-gates",
10
10
  "source": "./",
11
11
  "description": "Gates that run on what each turn changed and send the agent back until they pass.",
12
- "version": "0.6.0"
12
+ "version": "0.7.0"
13
13
  }
14
14
  ]
15
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.6.0",
4
+ "version": "0.7.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.6.0",
3
+ "version": "0.7.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",
@@ -3,7 +3,7 @@
3
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
4
  "gates": [
5
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.",
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. The watch is asked for a cycle through tsconfig.spec.json, and starts again when a spec is created or deleted, since ng test lists its specs once.",
7
7
  "requires": [
8
8
  {
9
9
  "tool": "@angular/cli",
@@ -27,12 +27,14 @@
27
27
  "run": ["{engine}/src/helpers/angular-watch.ts"],
28
28
  "cycleStart": "Changes detected\\. Rebuilding",
29
29
  "cycleEnd": "Test run finished with success|bundle generation failed",
30
- "failed": "^FAIL |bundle generation failed"
30
+ "failed": "^FAIL |bundle generation failed",
31
+ "sync": "tsconfig.spec.json",
32
+ "frozen": "\\.spec\\.ts$"
31
33
  }
32
34
  }
33
35
  },
34
36
  {
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.",
37
+ "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. The watch is asked for a cycle through tsconfig.app.json.",
36
38
  "requires": [
37
39
  {
38
40
  "tool": "@angular/cli",
@@ -58,7 +60,8 @@
58
60
  ],
59
61
  "cycleStart": "Changes detected\\. Rebuilding",
60
62
  "cycleEnd": "Application bundle generation (complete|failed)",
61
- "failed": "Application bundle generation failed"
63
+ "failed": "Application bundle generation failed",
64
+ "sync": "tsconfig.app.json"
62
65
  }
63
66
  }
64
67
  },
@@ -80,6 +83,27 @@
80
83
  "files": "\\.html$",
81
84
  "run": ["eslint", "--max-warnings", "0", "--no-warn-ignored", "{files}"]
82
85
  }
86
+ },
87
+ {
88
+ "description": "Fails on the strict template errors the turn added, never on the ones already there, for a project that turned strictTemplates off: it compiles the templates with strictTemplates and strictNullChecks forced on top of the project's options, through the API of the Angular compiler, so a binding that may be null is reported even when the TypeScript has strict errors of its own. The build gate checks the templates with the project's own options. An error is not new when moved, or reported with the same message in another file the turn did not change, or on a changed line as long as its file has no more errors of its code than at the turn start. It checks tsconfig.app.json: give its -p the tsconfig of the application.",
89
+ "requires": [
90
+ {
91
+ "tool": "@angular/compiler-cli",
92
+ "install": "npm install --save-dev @angular/compiler-cli"
93
+ },
94
+ {
95
+ "tool": "typescript",
96
+ "install": "npm install --save-dev typescript"
97
+ }
98
+ ],
99
+ "gate": {
100
+ "name": "no-new-strict-template-errors",
101
+ "severity": "error",
102
+ "files": "(\\.(ts|html)|(^|/)tsconfig[^/]*\\.json)$",
103
+ "run": ["{engine}/src/helpers/template-errors.ts", "-p", "tsconfig.app.json", "--strictNullChecks"],
104
+ "compare": "turn-start",
105
+ "lineKey": "^((?<file>.+?): error (?:TS|NG)\\d+) at [^\\t]*"
106
+ }
83
107
  }
84
108
  ]
85
109
  }
@@ -40,14 +40,14 @@ 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="#angular">Angular (3)</a><a href="#go">Go (6)</a><a href="#python">Python (3)</a><a href="#typescript">TypeScript (9)</a></nav>
43
+ <nav><a href="#angular">Angular (4)</a><a href="#go">Go (6)</a><a href="#python">Python (3)</a><a href="#typescript">TypeScript (9)</a></nav>
44
44
  </header>
45
45
  <section id="angular">
46
46
  <h2>Angular</h2>
47
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
48
  <article id="angular/tests">
49
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>
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. The watch is asked for a cycle through tsconfig.spec.json, and starts again when a spec is created or deleted, since ng test lists its specs once.</p>
51
51
  <dl>
52
52
  <dt>Runs</dt><dd><code>@angular/cli test --watch=false</code></dd>
53
53
  <dt>When the turn changes</dt><dd><code>\.(ts|html|css)$</code></dd>
@@ -68,13 +68,15 @@ summary { cursor: pointer; color: var(--muted); }
68
68
  ],
69
69
  &quot;cycleStart&quot;: &quot;Changes detected\\. Rebuilding&quot;,
70
70
  &quot;cycleEnd&quot;: &quot;Test run finished with success|bundle generation failed&quot;,
71
- &quot;failed&quot;: &quot;^FAIL |bundle generation failed&quot;
71
+ &quot;failed&quot;: &quot;^FAIL |bundle generation failed&quot;,
72
+ &quot;sync&quot;: &quot;tsconfig.spec.json&quot;,
73
+ &quot;frozen&quot;: &quot;\\.spec\\.ts$&quot;
72
74
  }
73
75
  }</code></pre></details>
74
76
  </article>
75
77
  <article id="angular/build">
76
78
  <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>
79
+ <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. The watch is asked for a cycle through tsconfig.app.json.</p>
78
80
  <dl>
79
81
  <dt>Runs</dt><dd><code>@angular/cli build --optimization=false --output-path=node_modules/.cache/gates/build</code></dd>
80
82
  <dt>When the turn changes</dt><dd><code>\.(ts|html|css|scss|sass|less)$</code></dd>
@@ -100,7 +102,8 @@ summary { cursor: pointer; color: var(--muted); }
100
102
  ],
101
103
  &quot;cycleStart&quot;: &quot;Changes detected\\. Rebuilding&quot;,
102
104
  &quot;cycleEnd&quot;: &quot;Application bundle generation (complete|failed)&quot;,
103
- &quot;failed&quot;: &quot;Application bundle generation failed&quot;
105
+ &quot;failed&quot;: &quot;Application bundle generation failed&quot;,
106
+ &quot;sync&quot;: &quot;tsconfig.app.json&quot;
104
107
  }
105
108
  }</code></pre></details>
106
109
  </article>
@@ -125,6 +128,28 @@ summary { cursor: pointer; color: var(--muted); }
125
128
  ]
126
129
  }</code></pre></details>
127
130
  </article>
131
+ <article id="angular/no-new-strict-template-errors">
132
+ <h3><code>angular/no-new-strict-template-errors</code></h3>
133
+ <p>Fails on the strict template errors the turn added, never on the ones already there, for a project that turned strictTemplates off: it compiles the templates with strictTemplates and strictNullChecks forced on top of the project's options, through the API of the Angular compiler, so a binding that may be null is reported even when the TypeScript has strict errors of its own. The build gate checks the templates with the project's own options. An error is not new when moved, or reported with the same message in another file the turn did not change, or on a changed line as long as its file has no more errors of its code than at the turn start. It checks tsconfig.app.json: give its -p the tsconfig of the application.</p>
134
+ <dl>
135
+ <dt>Runs</dt><dd><code>{engine}/src/helpers/template-errors.ts -p tsconfig.app.json --strictNullChecks</code></dd>
136
+ <dt>When the turn changes</dt><dd><code>(\.(ts|html)|(^|/)tsconfig[^/]*\.json)$</code></dd>
137
+ <dt>Fails on</dt><dd>only the output lines the turn added</dd><dt>Requires</dt><dd><ul><li><code>@angular/compiler-cli</code>: npm install --save-dev @angular/compiler-cli</li><li><code>typescript</code>: npm install --save-dev typescript</li></ul></dd>
138
+ </dl>
139
+ <details><summary>Definition to copy into .gates.json</summary><pre><code>{
140
+ &quot;name&quot;: &quot;no-new-strict-template-errors&quot;,
141
+ &quot;severity&quot;: &quot;error&quot;,
142
+ &quot;files&quot;: &quot;(\\.(ts|html)|(^|/)tsconfig[^/]*\\.json)$&quot;,
143
+ &quot;run&quot;: [
144
+ &quot;{engine}/src/helpers/template-errors.ts&quot;,
145
+ &quot;-p&quot;,
146
+ &quot;tsconfig.app.json&quot;,
147
+ &quot;--strictNullChecks&quot;
148
+ ],
149
+ &quot;compare&quot;: &quot;turn-start&quot;,
150
+ &quot;lineKey&quot;: &quot;^((?&lt;file&gt;.+?): error (?:TS|NG)\\d+) at [^\\t]*&quot;
151
+ }</code></pre></details>
152
+ </article>
128
153
  </section>
129
154
  <section id="go">
130
155
  <h2>Go</h2>
@@ -437,7 +462,7 @@ summary { cursor: pointer; color: var(--muted); }
437
462
  </article>
438
463
  <article id="typescript/no-new-strict-errors">
439
464
  <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 source line, since tsc prints the types of a message otherwise from one compilation to the next: one a change moves to another line is not new, nor one tsc reports in another file with the same message, nor one on a line the turn changed, as long as its file has no more errors of its code than at the turn start. The agent still reads the message. 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>
465
+ <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 source line, since tsc prints the types of a message otherwise from one compilation to the next: one a change moves to another line is not new, nor one tsc reports with the same message in another file the turn did not change, nor one on a line the turn changed, as long as its file has no more errors of its code than at the turn start. The agent still reads the message. 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. The watch is asked for a cycle through tsconfig.json: with -p, give its watch.sync the same tsconfig.</p>
441
466
  <dl>
442
467
  <dt>Runs</dt><dd><code>{engine}/src/helpers/type-errors.ts --strictNullChecks --strictPropertyInitialization</code></dd>
443
468
  <dt>When the turn changes</dt><dd><code>(\.(ts|tsx)|^tsconfig.*\.json)$</code></dd>
@@ -453,7 +478,7 @@ summary { cursor: pointer; color: var(--muted); }
453
478
  &quot;--strictPropertyInitialization&quot;
454
479
  ],
455
480
  &quot;compare&quot;: &quot;turn-start&quot;,
456
- &quot;lineKey&quot;: &quot;^(.+?: error TS\\d+) at [^\\t]*&quot;,
481
+ &quot;lineKey&quot;: &quot;^((?&lt;file&gt;.+?): error TS\\d+) at [^\\t]*&quot;,
457
482
  &quot;watch&quot;: {
458
483
  &quot;run&quot;: [
459
484
  &quot;{engine}/src/helpers/type-errors.ts&quot;,
@@ -462,7 +487,8 @@ summary { cursor: pointer; color: var(--muted); }
462
487
  &quot;--strictPropertyInitialization&quot;
463
488
  ],
464
489
  &quot;cycleStart&quot;: &quot;^Type check started$&quot;,
465
- &quot;cycleEnd&quot;: &quot;^Type check done$&quot;
490
+ &quot;cycleEnd&quot;: &quot;^Type check done$&quot;,
491
+ &quot;sync&quot;: &quot;tsconfig.json&quot;
466
492
  }
467
493
  }</code></pre></details>
468
494
  </article>
@@ -96,7 +96,7 @@
96
96
  }
97
97
  },
98
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 source line, since tsc prints the types of a message otherwise from one compilation to the next: one a change moves to another line is not new, nor one tsc reports in another file with the same message, nor one on a line the turn changed, as long as its file has no more errors of its code than at the turn start. The agent still reads the message. 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.",
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 source line, since tsc prints the types of a message otherwise from one compilation to the next: one a change moves to another line is not new, nor one tsc reports with the same message in another file the turn did not change, nor one on a line the turn changed, as long as its file has no more errors of its code than at the turn start. The agent still reads the message. 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. The watch is asked for a cycle through tsconfig.json: with -p, give its watch.sync the same tsconfig.",
100
100
  "requires": [
101
101
  {
102
102
  "tool": "typescript",
@@ -109,7 +109,7 @@
109
109
  "files": "(\\.(ts|tsx)|^tsconfig.*\\.json)$",
110
110
  "run": ["{engine}/src/helpers/type-errors.ts", "--strictNullChecks", "--strictPropertyInitialization"],
111
111
  "compare": "turn-start",
112
- "lineKey": "^(.+?: error TS\\d+) at [^\\t]*",
112
+ "lineKey": "^((?<file>.+?): error TS\\d+) at [^\\t]*",
113
113
  "watch": {
114
114
  "run": [
115
115
  "{engine}/src/helpers/type-errors.ts",
@@ -118,7 +118,8 @@
118
118
  "--strictPropertyInitialization"
119
119
  ],
120
120
  "cycleStart": "^Type check started$",
121
- "cycleEnd": "^Type check done$"
121
+ "cycleEnd": "^Type check done$",
122
+ "sync": "tsconfig.json"
122
123
  }
123
124
  }
124
125
  },
@@ -5,7 +5,7 @@ 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
+ import { judgeWatch, keepWatch, startWatch, TURN_START_MS, watchReport } from "./watch.js";
9
9
  function missingTools(root, gates) {
10
10
  return gates.flatMap((gate) => {
11
11
  const why = missingTool(root, gate);
@@ -43,13 +43,15 @@ export async function startTurn(session, root) {
43
43
  return told;
44
44
  }
45
45
  const { commit: start, tree } = snapshot(root);
46
+ // The turn starts before its reports are ready: a hook stopped for lack of time leaves it, never the turn before.
47
+ writeTurn(session, root, { start, baselines: {}, config, checked: false });
46
48
  const cached = cachedReports(root, tree);
47
49
  const baselines = await Promise.all(compared.map(async (gate) => {
48
50
  const cachedReport = cached(gate);
49
51
  if (cachedReport !== undefined)
50
52
  return { gate, ok: true, output: cachedReport };
51
53
  if (!keepsWatch(gate))
52
- return { gate, ...(await wholeProject(root, gate)) };
54
+ return { gate, ...(await wholeProject(root, gate, TURN_START_MS)) };
53
55
  const output = await watchReport(session, root, gate);
54
56
  return { gate, ok: output !== undefined, output };
55
57
  }));
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
- import { join } from "node:path";
2
+ import { isAbsolute, join } from "node:path";
3
3
  import { isRecord, isStringArray, messageOf } from "./json.js";
4
4
  import { repoRoot } from "./snapshot.js";
5
5
  const GATES_FILE = ".gates.json";
@@ -19,7 +19,7 @@ const FIELDS = new Set([
19
19
  "timeoutSeconds",
20
20
  "watch",
21
21
  ]);
22
- const WATCH_FIELDS = new Set(["run", "cycleStart", "cycleEnd", "failed"]);
22
+ const WATCH_FIELDS = new Set(["run", "cycleStart", "cycleEnd", "failed", "sync", "frozen"]);
23
23
  /** In the arguments of a gate: the changed files it looks at, and the commit of the turn start. */
24
24
  export const FILES = "{files}";
25
25
  export const TURN = "{turn}";
@@ -94,11 +94,11 @@ function isPattern(value) {
94
94
  }
95
95
  function toWatch(watch, compared) {
96
96
  if (!isRecord(watch))
97
- return refuse("watch holds run, cycleStart, cycleEnd and failed");
97
+ return refuse("watch holds run, cycleStart, cycleEnd, failed and sync");
98
98
  const unknown = Object.keys(watch).find((key) => !WATCH_FIELDS.has(key));
99
99
  if (unknown !== undefined)
100
100
  refuse(`unknown field watch.${unknown}`);
101
- const { run, cycleStart, cycleEnd, failed } = watch;
101
+ const { run, cycleStart, cycleEnd, failed, sync, frozen } = watch;
102
102
  if (!isStringArray(run) || !run.length)
103
103
  refuse("watch.run is a non-empty list of strings");
104
104
  if (run.some((argument) => argument.includes(FILES) || argument.includes(TURN)))
@@ -106,8 +106,14 @@ function toWatch(watch, compared) {
106
106
  const pattern = (field, value) => isPattern(value) ? value : refuse(`watch.${field} is a regular expression on a line of its output`);
107
107
  if (compared && failed !== undefined)
108
108
  refuse("a compared watch fails on the lines its cycle added: no watch.failed");
109
+ if (typeof sync !== "string" || !sync || isAbsolute(sync) || sync.split(/[\\/]/).includes(".."))
110
+ refuse("watch.sync is a file of the repo the watch opens a cycle for when its date changes, such as its tsconfig");
111
+ if (frozen !== undefined && !isPattern(frozen))
112
+ refuse("watch.frozen is a regular expression on the files the watch lists only as it starts");
109
113
  return {
110
114
  run,
115
+ sync,
116
+ ...(frozen === undefined ? {} : { frozen }),
111
117
  cycleStart: pattern("cycleStart", cycleStart),
112
118
  cycleEnd: pattern("cycleEnd", cycleEnd),
113
119
  ...(compared ? {} : { failed: pattern("failed", failed) }),
@@ -12,8 +12,19 @@ const ENGINE = resolve(import.meta.dirname, "..", "..");
12
12
  const manifest = readJsonFile(join(ENGINE, "package.json"));
13
13
  /** The version of this engine: what its helpers print, so what a report holds, may change from one to the next. */
14
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" };
15
+ /**
16
+ * What a tool of a repo runs with: no colour, which some tools print anyway, and the commands of its node_modules
17
+ * first on the PATH, as npx and the package managers run them, so that a tool finds the Node the repo pins.
18
+ */
19
+ export function toolEnv(root) {
20
+ const path = [join(root, "node_modules", ".bin"), ...(process.env.PATH ? [process.env.PATH] : [])];
21
+ return { ...process.env, NO_COLOR: "1", FORCE_COLOR: "0", PATH: path.join(delimiter) };
22
+ }
23
+ /** The Node a script of the repo or of its packages runs on: the one the repo pins in its node_modules, as npx finds it, or the one of the engine. */
24
+ function repoNode(root) {
25
+ const pinned = join(root, "node_modules", ".bin", "node");
26
+ return executable(pinned) ? pinned : process.execPath;
27
+ }
17
28
  const MAX_OUTPUT_MB = 16;
18
29
  const ENGINE_PREFIX = "{engine}/";
19
30
  /** A script of this engine: its .ts source, or the .js it is built to when the engine runs from its npm package. */
@@ -23,8 +34,8 @@ function engineScript(name) {
23
34
  }
24
35
  // A script of the repo runs on the interpreter of its extension.
25
36
  const INTERPRETERS = [
26
- [/\.(ts|js|mjs)$/, process.execPath],
27
- [/\.py$/, "python3"],
37
+ [/\.(ts|js|mjs)$/, repoNode],
38
+ [/\.py$/, () => "python3"],
28
39
  ];
29
40
  /** The script of a package of the repo's node_modules, or nothing when the repo does not have the package. */
30
41
  export function packageScript(root, name) {
@@ -48,7 +59,7 @@ export function commandOf(root, name) {
48
59
  if (name.startsWith(ENGINE_PREFIX)) {
49
60
  return { file: process.execPath, args: [engineScript(name.slice(ENGINE_PREFIX.length))], missing: "" };
50
61
  }
51
- const interpreter = INTERPRETERS.find(([extension]) => extension.test(name))?.[1];
62
+ const interpreter = INTERPRETERS.find(([extension]) => extension.test(name))?.[1](root);
52
63
  if (interpreter !== undefined) {
53
64
  return {
54
65
  file: interpreter,
@@ -58,7 +69,7 @@ export function commandOf(root, name) {
58
69
  }
59
70
  const script = packageScript(root, name);
60
71
  if (script !== undefined)
61
- return { file: process.execPath, args: [script], missing: "" };
72
+ return { file: repoNode(root), args: [script], missing: "" };
62
73
  if (name.includes("/"))
63
74
  return { file: resolve(root, name), args: [], missing: `${name} does not exist.` };
64
75
  return {
@@ -68,10 +79,8 @@ export function commandOf(root, name) {
68
79
  };
69
80
  }
70
81
  // A program by its path, or by its name on the PATH, that the system would execute.
71
- function executable(file) {
72
- const candidates = isAbsolute(file)
73
- ? [file]
74
- : (process.env.PATH ?? "").split(delimiter).map((dir) => join(dir, file));
82
+ function executable(file, path = process.env.PATH ?? "") {
83
+ const candidates = isAbsolute(file) ? [file] : path.split(delimiter).map((dir) => join(dir, file));
75
84
  return candidates.some((candidate) => {
76
85
  try {
77
86
  accessSync(candidate, constants.X_OK);
@@ -90,7 +99,7 @@ function missingProgram(root, name) {
90
99
  catch {
91
100
  return undefined;
92
101
  }
93
- return command.missing && !executable(command.file) ? command.missing : undefined;
102
+ return command.missing && !executable(command.file, toolEnv(root).PATH) ? command.missing : undefined;
94
103
  }
95
104
  /**
96
105
  * Why the program of a gate, or of its watch, cannot run on this machine, or nothing when they can: looked up as the
@@ -113,10 +122,11 @@ export function filesOf(gate, changed) {
113
122
  /**
114
123
  * The lines of output a turn added, less the ignored ones. With a key, a line is told by the part the key matches. A
115
124
  * line of a new key is still an old one, each line of the turn start whose key went standing for one line only: first
116
- * when it says the same as such a line, that problem reported elsewhere; then when the first group of the key, its
117
- * place, is the one of such a line, that problem changed where it is.
125
+ * when it says the same as such a line, that problem reported elsewhere, unless the group of the key named file names
126
+ * a file the turn changed, where the agent may have written it; then when the first group of the key, its place, is
127
+ * the one of such a line, that problem changed where it is.
118
128
  */
119
- export function newLines(before, after, ignore, key) {
129
+ export function newLines(before, after, ignore, key, changed = []) {
120
130
  const ignored = ignore === undefined ? undefined : new RegExp(ignore);
121
131
  const keyed = key === undefined ? undefined : new RegExp(key);
122
132
  const lines = (text) => text
@@ -125,6 +135,7 @@ export function newLines(before, after, ignore, key) {
125
135
  .filter(Boolean);
126
136
  const keyOf = (line) => keyed?.exec(line)?.[0] ?? line;
127
137
  const placeOf = (line) => keyed?.exec(line)?.[1];
138
+ const written = (line) => changed.includes(keyed?.exec(line)?.groups?.file ?? "");
128
139
  const restOf = (line) => line.replace(keyOf(line), "").trim();
129
140
  const old = lines(before);
130
141
  const now = lines(after);
@@ -139,7 +150,7 @@ export function newLines(before, after, ignore, key) {
139
150
  };
140
151
  return now
141
152
  .filter((line) => !oldKeys.has(keyOf(line)) && !ignored?.test(line))
142
- .filter((line) => !restOf(line) || !stillOld((was) => restOf(was) === restOf(line)))
153
+ .filter((line) => !restOf(line) || written(line) || !stillOld((was) => restOf(was) === restOf(line)))
143
154
  .filter((line) => placeOf(line) === undefined || !stillOld((was) => placeOf(was) === placeOf(line)));
144
155
  }
145
156
  async function execute(root, gate, args) {
@@ -158,7 +169,7 @@ async function execute(root, gate, args) {
158
169
  cwd: root,
159
170
  timeout: gate.timeoutSeconds * 1000,
160
171
  maxBuffer: MAX_OUTPUT_MB * 1024 * 1024,
161
- env: TOOL_ENV,
172
+ env: toolEnv(root),
162
173
  }, (error, stdout, stderr) => {
163
174
  resolve({
164
175
  ok: !error,
@@ -185,9 +196,14 @@ function outputOf(root, gate, command, error, printed) {
185
196
  export function cleaned(root, printed) {
186
197
  return stripVTControlCharacters(printed).split(`${root}${sep}`).join("").trim();
187
198
  }
188
- /** Runs a compared gate on the whole project, as the turn starts. */
189
- export function wholeProject(root, gate) {
190
- return execute(root, gate, gate.run.slice(1));
199
+ /**
200
+ * Runs a compared gate on the whole project, as the turn starts, in the time the gate has or less: nothing when it
201
+ * runs out of it, since its lines would all be new at the stop.
202
+ */
203
+ export async function wholeProject(root, gate, ms = gate.timeoutSeconds * 1000) {
204
+ const timeoutSeconds = Math.min(gate.timeoutSeconds, ms / 1000);
205
+ const { ok, output, timedOut } = await execute(root, { ...gate, timeoutSeconds }, gate.run.slice(1));
206
+ return timedOut ? { ok: false } : { ok, output };
191
207
  }
192
208
  /**
193
209
  * Runs a gate on the turn. A compared gate fails on the lines of output the turn added, and on any exit code but 0:
@@ -200,15 +216,15 @@ export async function check(root, gate, files, turn, baseline) {
200
216
  return { ...ran, ok, output, timedOut };
201
217
  if (!isCompared(gate) || !ok)
202
218
  return { ...ran, ok, output };
203
- return { ...ran, ...addedLines(gate, output, baseline) };
219
+ return { ...ran, ...addedLines(gate, output, baseline, files) };
204
220
  }
205
221
  /**
206
222
  * Judges the output of a compared gate that ran clean: it fails on the lines the turn added to the report of the turn
207
223
  * start. Without that report, nothing counts but the exit code.
208
224
  */
209
- export function addedLines(gate, output, baseline) {
225
+ export function addedLines(gate, output, baseline, changed) {
210
226
  if (baseline === undefined)
211
227
  return { ok: true, output: "" };
212
- const added = newLines(baseline, output, gate.ignoreLines, gate.lineKey);
228
+ const added = newLines(baseline, output, gate.ignoreLines, gate.lineKey, changed);
213
229
  return { ok: added.length === 0, output: added.join("\n") };
214
230
  }