@tayomi/deterministic-gates 0.8.1 → 0.8.2

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.8.1"
12
+ "version": "0.8.2"
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.8.1",
4
+ "version": "0.8.2",
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.8.1",
3
+ "version": "0.8.2",
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",
@@ -87,6 +87,16 @@ export async function compilerOf(root, args) {
87
87
  const sources = new Map();
88
88
  const resources = new Map();
89
89
  let last;
90
+ // No file the check before this one read has another date: it would say the same.
91
+ const unchanged = () => {
92
+ for (const [file, { at }] of sources)
93
+ if (changedAt(file) !== at)
94
+ return false;
95
+ for (const [file, at] of resources)
96
+ if (changedAt(file) !== at)
97
+ return false;
98
+ return true;
99
+ };
90
100
  return {
91
101
  compiler: {
92
102
  async diagnostics() {
@@ -98,10 +108,19 @@ export async function compilerOf(root, args) {
98
108
  sources.clear();
99
109
  resources.clear();
100
110
  }
111
+ // The check before this one stands when nothing it read has changed, which saves checking every file again.
112
+ // Never the first check of a compiler: TypeScript reports some errors once per type, in the first file it
113
+ // checks, and that order is another in a program that reuses one, so a first check served again would be
114
+ // compared with the checks after it, and an error would look new for having moved.
115
+ const roots = JSON.stringify(config.rootNames);
116
+ if (last?.reused && last.roots === roots && unchanged())
117
+ return [...config.errors, ...last.checked];
101
118
  const base = ng.createCompilerHost({ options });
119
+ const asked = new Set();
102
120
  const host = {
103
121
  ...base,
104
122
  getSourceFile(file, ...rest) {
123
+ asked.add(file);
105
124
  const at = changedAt(file);
106
125
  const kept = sources.get(file);
107
126
  if (kept?.at === at)
@@ -131,15 +150,21 @@ export async function compilerOf(root, args) {
131
150
  return modified;
132
151
  },
133
152
  };
153
+ const reused = last !== undefined;
134
154
  const program = new ng.NgtscProgram(config.rootNames, options, host, last?.program);
135
155
  await program.loadNgStructureAsync();
136
- last = { program, options: JSON.stringify(options) };
137
- return [
138
- ...config.errors,
156
+ const checked = [
139
157
  ...program.getTsSyntacticDiagnostics(),
140
158
  ...program.getTsSemanticDiagnostics(),
141
159
  ...program.getNgSemanticDiagnostics(),
142
160
  ];
161
+ // A file the program no longer reads is forgotten once it changes: kept with its old date, it would make
162
+ // every check to come a whole one.
163
+ for (const [file, { at }] of sources)
164
+ if (!asked.has(file) && changedAt(file) !== at)
165
+ sources.delete(file);
166
+ last = { program, options: JSON.stringify(options), roots, reused, checked };
167
+ return [...config.errors, ...checked];
143
168
  },
144
169
  },
145
170
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tayomi/deterministic-gates",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
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
  "type": "module",
6
6
  "license": "MIT",
@@ -15,7 +15,8 @@ import { strictErrorLines } from "./type-errors.ts";
15
15
  //
16
16
  // With --watch, it stays, and checks again each time the date of its tsconfig changes, which is how the engine asks
17
17
  // a watch for a cycle. It follows no other file: a check reads the files as they are when it starts, the ones whose
18
- // date changed since the check before it, so it never misses a change, and it reuses the program of that check.
18
+ // date changed since the check before it, so it never misses a change, and it reuses the program of that check. When
19
+ // no file that check read has changed, it says what that check said, without checking again.
19
20
 
20
21
  /** A diagnostic of the Angular compiler, as its API gives it. */
21
22
  export interface Diagnostic {
@@ -110,7 +111,14 @@ export async function compilerOf(root: string, args: string[]): Promise<{ compil
110
111
  // is how the compiler knows it need not check it again.
111
112
  const sources = new Map<string, { at: number; source: unknown }>();
112
113
  const resources = new Map<string, number>();
113
- let last: { program: unknown; options: string } | undefined;
114
+ let last:
115
+ { program: unknown; options: string; roots: string; reused: boolean; checked: readonly Diagnostic[] } | undefined;
116
+ // No file the check before this one read has another date: it would say the same.
117
+ const unchanged = () => {
118
+ for (const [file, { at }] of sources) if (changedAt(file) !== at) return false;
119
+ for (const [file, at] of resources) if (changedAt(file) !== at) return false;
120
+ return true;
121
+ };
114
122
  return {
115
123
  compiler: {
116
124
  async diagnostics() {
@@ -122,10 +130,18 @@ export async function compilerOf(root: string, args: string[]): Promise<{ compil
122
130
  sources.clear();
123
131
  resources.clear();
124
132
  }
133
+ // The check before this one stands when nothing it read has changed, which saves checking every file again.
134
+ // Never the first check of a compiler: TypeScript reports some errors once per type, in the first file it
135
+ // checks, and that order is another in a program that reuses one, so a first check served again would be
136
+ // compared with the checks after it, and an error would look new for having moved.
137
+ const roots = JSON.stringify(config.rootNames);
138
+ if (last?.reused && last.roots === roots && unchanged()) return [...config.errors, ...last.checked];
125
139
  const base = ng.createCompilerHost({ options });
140
+ const asked = new Set<string>();
126
141
  const host = {
127
142
  ...base,
128
143
  getSourceFile(file: string, ...rest: unknown[]) {
144
+ asked.add(file);
129
145
  const at = changedAt(file);
130
146
  const kept = sources.get(file);
131
147
  if (kept?.at === at) return kept.source;
@@ -150,15 +166,19 @@ export async function compilerOf(root: string, args: string[]): Promise<{ compil
150
166
  return modified;
151
167
  },
152
168
  };
169
+ const reused = last !== undefined;
153
170
  const program = new ng.NgtscProgram(config.rootNames, options, host, last?.program);
154
171
  await program.loadNgStructureAsync();
155
- last = { program, options: JSON.stringify(options) };
156
- return [
157
- ...config.errors,
172
+ const checked: readonly Diagnostic[] = [
158
173
  ...program.getTsSyntacticDiagnostics(),
159
174
  ...program.getTsSemanticDiagnostics(),
160
175
  ...program.getNgSemanticDiagnostics(),
161
176
  ];
177
+ // A file the program no longer reads is forgotten once it changes: kept with its old date, it would make
178
+ // every check to come a whole one.
179
+ for (const [file, { at }] of sources) if (!asked.has(file) && changedAt(file) !== at) sources.delete(file);
180
+ last = { program, options: JSON.stringify(options), roots, reused, checked };
181
+ return [...config.errors, ...checked];
162
182
  },
163
183
  },
164
184
  };