hoi4-agent-tools 4.6.5 → 4.8.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/CHANGELOG.md +40 -5
- package/README.md +32 -13
- package/dist/hoi4_agent_tools/core/engine-client.js +342 -0
- package/dist/hoi4_agent_tools/core/operation-result.js +33 -5
- package/dist/hoi4_agent_tools/core/resident-engine.js +273 -0
- package/dist/hoi4_agent_tools/core/temporary-directories.js +3 -2
- package/dist/hoi4_agent_tools/decision/service.js +7 -0
- package/dist/hoi4_agent_tools/event/service.js +18 -6
- package/dist/hoi4_agent_tools/event/summary.js +9 -0
- package/dist/hoi4_agent_tools/focus/compact.js +197 -18
- package/dist/hoi4_agent_tools/focus/engine-layout.js +201 -0
- package/dist/hoi4_agent_tools/focus/game-render.js +72 -0
- package/dist/hoi4_agent_tools/focus/game-view-output.js +160 -0
- package/dist/hoi4_agent_tools/focus/job-operations.js +3 -1
- package/dist/hoi4_agent_tools/focus/layout.js +3 -2
- package/dist/hoi4_agent_tools/focus/native-effects.js +4 -4
- package/dist/hoi4_agent_tools/focus/quality/branches.js +32 -0
- package/dist/hoi4_agent_tools/focus/quality/calibration.js +364 -0
- package/dist/hoi4_agent_tools/focus/quality/delta.js +85 -0
- package/dist/hoi4_agent_tools/focus/quality/focus-quality-calibration.json +2265 -0
- package/dist/hoi4_agent_tools/focus/quality/graph.js +170 -0
- package/dist/hoi4_agent_tools/focus/quality/index.js +24 -0
- package/dist/hoi4_agent_tools/focus/quality/inline-images.js +132 -0
- package/dist/hoi4_agent_tools/focus/quality/metrics.js +424 -0
- package/dist/hoi4_agent_tools/focus/quality/orthogonal.js +213 -0
- package/dist/hoi4_agent_tools/focus/quality/positions.js +41 -0
- package/dist/hoi4_agent_tools/focus/quality/schematic.js +243 -0
- package/dist/hoi4_agent_tools/focus/quality/scorecard.js +549 -0
- package/dist/hoi4_agent_tools/focus/quality/stored-calibration.js +7 -0
- package/dist/hoi4_agent_tools/focus/quality/tool-output.js +113 -0
- package/dist/hoi4_agent_tools/focus/quality/types.js +5 -0
- package/dist/hoi4_agent_tools/focus/render.js +21 -9
- package/dist/hoi4_agent_tools/focus/tool-operations.js +364 -25
- package/dist/hoi4_agent_tools/focus/tool-support.js +1 -1
- package/dist/hoi4_agent_tools/gui/assets.js +18 -0
- package/dist/hoi4_agent_tools/gui/dds.js +38 -5
- package/dist/hoi4_agent_tools/gui/engine-textures.js +48 -0
- package/dist/hoi4_agent_tools/gui/source-graph.js +7 -0
- package/dist/hoi4_agent_tools/gui/tool-operations.js +23 -4
- package/dist/hoi4_agent_tools/gui/validators.js +31 -2
- package/dist/hoi4_agent_tools/ideas/inspect.js +43 -0
- package/dist/hoi4_agent_tools/localisation/inspect.js +34 -0
- package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +2 -0
- package/dist/hoi4_agent_tools/mcp/server/instructions.js +1 -1
- package/dist/hoi4_agent_tools/mcp/tools/event.js +2 -0
- package/dist/hoi4_agent_tools/mcp/tools/focus.js +76 -4
- package/dist/hoi4_agent_tools/mcp/tools/reference.js +18 -0
- package/dist/hoi4_agent_tools/probability/operations.js +27 -1
- package/dist/hoi4_agent_tools/probability/service.js +91 -11
- package/dist/hoi4_agent_tools/probability/source-analysis.js +2 -2
- package/dist/hoi4_agent_tools/probability/sweep.js +20 -6
- package/dist/hoi4_agent_tools/reference/command-phrases.json +11065 -0
- package/dist/hoi4_agent_tools/reference/error-log.js +24 -0
- package/dist/hoi4_agent_tools/reference/game-text.js +109 -0
- package/dist/hoi4_agent_tools/reference/known-mistakes.js +8 -5
- package/dist/hoi4_agent_tools/reference/known-mistakes.json +4 -4
- package/dist/hoi4_agent_tools/reference/operations.js +68 -2
- package/dist/hoi4_agent_tools/reference/ranking.js +92 -2
- package/dist/hoi4_agent_tools/reference/script-validation.js +46 -6
- package/dist/hoi4_agent_tools/reference/service.js +125 -21
- package/dist/hoi4_agent_tools/reference/source-lookup.js +8 -0
- package/dist/hoi4_agent_tools/schemas/focus-requests.js +68 -7
- package/dist/hoi4_agent_tools/schemas/focus.js +121 -6
- package/dist/hoi4_agent_tools/schemas/ideas.js +142 -0
- package/dist/hoi4_agent_tools/schemas/localisation.js +94 -0
- package/dist/hoi4_agent_tools/schemas/mod-tools.js +11 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/configuration.md +17 -17
- package/docs/focus.md +104 -4
- package/docs/reference.md +1 -1
- package/docs/research/reference-benchmark.md +152 -1
- package/docs/setup.md +1 -1
- package/docs/tools.md +48 -44
- package/docs/troubleshooting.md +13 -12
- package/engine/README.md +284 -0
- package/engine/bin/darwin-arm64/hoi4-engine +0 -0
- package/engine/bin/linux-arm64/hoi4-engine +0 -0
- package/engine/bin/linux-x64/hoi4-engine +0 -0
- package/engine/bin/manifest.json +26 -0
- package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +5 -1
- package/schemas/configuration.schema.json +1 -1
- package/schemas/continuous-focus-palette.schema.json +1 -1
- package/schemas/custom-weighted-pool.schema.json +1 -1
- package/schemas/decision-inspect-input.schema.json +1 -1
- package/schemas/error-log-input.schema.json +1 -1
- package/schemas/event-feature-manifest.schema.json +1 -1
- package/schemas/focus-plan.schema.json +146 -120
- package/schemas/focus-planning-sidecar.schema.json +15 -7
- package/schemas/geography-model.schema.json +1 -1
- package/schemas/gui-animation-source.schema.json +1 -1
- package/schemas/gui-helper.schema.json +1 -1
- package/schemas/gui-scenario.schema.json +1 -1
- package/schemas/helper-expansion-request.schema.json +1 -1
- package/schemas/helper-expansion-summary.schema.json +1 -1
- package/schemas/impact-inspect-input.schema.json +1 -1
- package/schemas/map-operation.schema.json +1 -1
- package/schemas/mechanic-test-input.schema.json +1 -1
- package/schemas/mod-index-input.schema.json +1 -1
- package/schemas/operation-result.schema.json +1 -1
- package/schemas/package-check-input.schema.json +1 -1
- package/schemas/package-manifest.schema.json +1 -1
- package/schemas/probability-analysis-result.schema.json +1 -1
- package/schemas/probability-compare-input.schema.json +1 -1
- package/schemas/probability-evaluate-input.schema.json +1 -1
- package/schemas/probability-inspect-input.schema.json +1 -1
- package/schemas/probability-render-input.schema.json +1 -1
- package/schemas/probability-scenario-set.schema.json +1 -1
- package/schemas/probability-sequence-input.schema.json +1 -1
- package/schemas/probability-simulate-input.schema.json +1 -1
- package/schemas/probability-sweep-input.schema.json +1 -1
- package/schemas/reference-context-input.schema.json +1 -1
- package/schemas/reference-read-input.schema.json +1 -1
- package/schemas/reference-search-input.schema.json +1 -1
- package/schemas/reference-sheets.schema.json +1 -1
- package/schemas/scenario-suite.schema.json +1 -1
- package/schemas/scenario-test-input.schema.json +1 -1
- package/schemas/script-validate-input.schema.json +1 -1
- package/schemas/shared-scenario.schema.json +1 -1
- package/schemas/source-lookup-input.schema.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { locateEngineBinary, } from './engine-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* The resident engine (`hoi4-engine serve`, ADR 0074): one long-lived engine process per server
|
|
5
|
+
* that keeps its caches between calls. Requests and responses are frames: a JSON line, then the
|
|
6
|
+
* raw bytes its `payload` field counts. Requests run in parallel inside the engine and are matched
|
|
7
|
+
* to responses by id.
|
|
8
|
+
*
|
|
9
|
+
* The process is started on first use and kept until the server exits, with no idle eviction. A
|
|
10
|
+
* crash fails the requests in flight and the next request starts a fresh process; after
|
|
11
|
+
* `RESIDENT_ENGINE_MAX_RESTARTS` crashes in a row the engine is reported unavailable.
|
|
12
|
+
*/
|
|
13
|
+
export const RESIDENT_ENGINE_PROTOCOL = 1;
|
|
14
|
+
export const RESIDENT_ENGINE_TIMEOUT_MS = 120_000;
|
|
15
|
+
export const RESIDENT_ENGINE_MAX_RESTARTS = 3;
|
|
16
|
+
/** The largest response header line; payloads are bounded by `maxPayloadBytes`. */
|
|
17
|
+
const RESIDENT_ENGINE_MAX_HEADER_BYTES = 1024 * 1024;
|
|
18
|
+
const RESIDENT_ENGINE_MAX_PAYLOAD_BYTES = 512 * 1024 * 1024;
|
|
19
|
+
const STDERR_TAIL_BYTES = 4096;
|
|
20
|
+
export class ResidentEngine {
|
|
21
|
+
options;
|
|
22
|
+
child;
|
|
23
|
+
binary;
|
|
24
|
+
pending = new Map();
|
|
25
|
+
nextId = 1;
|
|
26
|
+
buffered = [];
|
|
27
|
+
bufferedBytes = 0;
|
|
28
|
+
header;
|
|
29
|
+
stderrTail = '';
|
|
30
|
+
crashes = 0;
|
|
31
|
+
closed = false;
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
this.options = options;
|
|
34
|
+
}
|
|
35
|
+
/** The binary in use, once a request has started the process. */
|
|
36
|
+
get location() {
|
|
37
|
+
return this.binary;
|
|
38
|
+
}
|
|
39
|
+
/** Whether a binary can be found, without starting it. */
|
|
40
|
+
available() {
|
|
41
|
+
return 'path' in locateEngineBinary(this.options);
|
|
42
|
+
}
|
|
43
|
+
async request(op, body = {}, payload, options = {}) {
|
|
44
|
+
options.signal?.throwIfAborted();
|
|
45
|
+
if (this.closed)
|
|
46
|
+
return { ok: false, kind: 'unavailable', reason: 'spawn_failed', message: 'closed' };
|
|
47
|
+
const started = this.ensureStarted();
|
|
48
|
+
if (started !== undefined)
|
|
49
|
+
return started;
|
|
50
|
+
const child = this.child;
|
|
51
|
+
const id = this.nextId++;
|
|
52
|
+
const timeoutMs = options.timeoutMs ?? RESIDENT_ENGINE_TIMEOUT_MS;
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const entry = {
|
|
55
|
+
resolve,
|
|
56
|
+
timer: setTimeout(() => {
|
|
57
|
+
this.settle(id, {
|
|
58
|
+
ok: false,
|
|
59
|
+
kind: 'unavailable',
|
|
60
|
+
reason: 'timeout',
|
|
61
|
+
message: `hoi4-engine ${op} did not answer within ${timeoutMs} ms`,
|
|
62
|
+
});
|
|
63
|
+
}, timeoutMs),
|
|
64
|
+
};
|
|
65
|
+
if (options.signal !== undefined) {
|
|
66
|
+
const signal = options.signal;
|
|
67
|
+
entry.signal = signal;
|
|
68
|
+
entry.onAbort = () => {
|
|
69
|
+
const current = this.pending.get(id);
|
|
70
|
+
if (current === undefined)
|
|
71
|
+
return;
|
|
72
|
+
clearTimeout(current.timer);
|
|
73
|
+
this.pending.delete(id);
|
|
74
|
+
this.updateRef();
|
|
75
|
+
const reason = signal.reason;
|
|
76
|
+
reject(reason instanceof Error ? reason : new Error('The engine request was cancelled'));
|
|
77
|
+
};
|
|
78
|
+
signal.addEventListener('abort', entry.onAbort, { once: true });
|
|
79
|
+
}
|
|
80
|
+
this.pending.set(id, entry);
|
|
81
|
+
this.updateRef();
|
|
82
|
+
const line = `${JSON.stringify({ ...body, id, op, payload: payload?.length ?? 0 })}\n`;
|
|
83
|
+
child.stdin.write(line);
|
|
84
|
+
if (payload !== undefined && payload.length > 0)
|
|
85
|
+
child.stdin.write(payload);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Stops the process; requests in flight fail as unavailable. */
|
|
89
|
+
close() {
|
|
90
|
+
this.closed = true;
|
|
91
|
+
this.stop('the resident engine was closed');
|
|
92
|
+
}
|
|
93
|
+
ensureStarted() {
|
|
94
|
+
if (this.child !== undefined)
|
|
95
|
+
return undefined;
|
|
96
|
+
if (this.crashes >= RESIDENT_ENGINE_MAX_RESTARTS)
|
|
97
|
+
return {
|
|
98
|
+
ok: false,
|
|
99
|
+
kind: 'unavailable',
|
|
100
|
+
reason: 'exit_status',
|
|
101
|
+
message: `hoi4-engine serve stopped ${this.crashes} times in a row: ${this.stderrTail.trim().slice(-300)}`,
|
|
102
|
+
};
|
|
103
|
+
const located = locateEngineBinary(this.options);
|
|
104
|
+
if (!('path' in located))
|
|
105
|
+
return { ok: false, kind: 'unavailable', reason: located.reason, message: located.message };
|
|
106
|
+
this.binary = located;
|
|
107
|
+
// A JavaScript engine (a development wrapper or a test double) runs under this Node.
|
|
108
|
+
const script = /\.(?:c|m)?js$/iu.test(located.path);
|
|
109
|
+
let child;
|
|
110
|
+
try {
|
|
111
|
+
child = spawn(script ? process.execPath : located.path, script ? [located.path, 'serve'] : ['serve'], {
|
|
112
|
+
shell: false,
|
|
113
|
+
windowsHide: true,
|
|
114
|
+
env: this.options.env ?? process.env,
|
|
115
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
kind: 'unavailable',
|
|
122
|
+
reason: 'spawn_failed',
|
|
123
|
+
message: error instanceof Error ? error.message : String(error),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
this.child = child;
|
|
127
|
+
this.buffered = [];
|
|
128
|
+
this.bufferedBytes = 0;
|
|
129
|
+
this.header = undefined;
|
|
130
|
+
child.stdout.on('data', (chunk) => this.onData(child, chunk));
|
|
131
|
+
child.stderr.on('data', (chunk) => {
|
|
132
|
+
this.stderrTail = `${this.stderrTail}${chunk.toString('utf8')}`.slice(-STDERR_TAIL_BYTES);
|
|
133
|
+
});
|
|
134
|
+
child.stdin.on('error', () => undefined);
|
|
135
|
+
child.on('error', (error) => this.onExit(child, `hoi4-engine serve failed: ${error.message}`));
|
|
136
|
+
child.on('close', (code, signal) => this.onExit(child, `hoi4-engine serve exited with ${code === null ? `signal ${signal ?? 'unknown'}` : `code ${code}`}`));
|
|
137
|
+
this.updateRef();
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
/** Keeps Node alive only while a request waits, so an idle engine never holds the server open. */
|
|
141
|
+
updateRef() {
|
|
142
|
+
const child = this.child;
|
|
143
|
+
if (child === undefined)
|
|
144
|
+
return;
|
|
145
|
+
const waiting = this.pending.size > 0;
|
|
146
|
+
if (waiting)
|
|
147
|
+
child.ref();
|
|
148
|
+
else
|
|
149
|
+
child.unref();
|
|
150
|
+
// The pipes are sockets at run time, which Node's stream types do not say.
|
|
151
|
+
for (const stream of [child.stdout, child.stderr, child.stdin]) {
|
|
152
|
+
const socket = stream;
|
|
153
|
+
if (waiting)
|
|
154
|
+
socket.ref?.();
|
|
155
|
+
else
|
|
156
|
+
socket.unref?.();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
take(bytes) {
|
|
160
|
+
const all = this.buffered.length === 1 ? this.buffered[0] : Buffer.concat(this.buffered);
|
|
161
|
+
const head = all.subarray(0, bytes);
|
|
162
|
+
const rest = all.subarray(bytes);
|
|
163
|
+
this.buffered = rest.length === 0 ? [] : [rest];
|
|
164
|
+
this.bufferedBytes = rest.length;
|
|
165
|
+
return head;
|
|
166
|
+
}
|
|
167
|
+
onData(child, chunk) {
|
|
168
|
+
if (child !== this.child)
|
|
169
|
+
return;
|
|
170
|
+
this.buffered.push(chunk);
|
|
171
|
+
this.bufferedBytes += chunk.length;
|
|
172
|
+
for (;;) {
|
|
173
|
+
if (this.header === undefined) {
|
|
174
|
+
const all = this.buffered.length === 1 ? this.buffered[0] : Buffer.concat(this.buffered);
|
|
175
|
+
this.buffered = all.length === 0 ? [] : [all];
|
|
176
|
+
const newline = all.indexOf(0x0a);
|
|
177
|
+
if (newline < 0) {
|
|
178
|
+
if (all.length > RESIDENT_ENGINE_MAX_HEADER_BYTES)
|
|
179
|
+
this.stop('hoi4-engine serve printed an oversized response header');
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const line = this.take(newline + 1).toString('utf8');
|
|
183
|
+
let body;
|
|
184
|
+
try {
|
|
185
|
+
body = JSON.parse(line);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
this.stop('hoi4-engine serve printed a response that is not JSON');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const id = typeof body.id === 'number' ? body.id : -1;
|
|
192
|
+
const payload = body.ok === true && typeof body.payload === 'number' ? body.payload : 0;
|
|
193
|
+
if (!Number.isSafeInteger(payload) ||
|
|
194
|
+
payload < 0 ||
|
|
195
|
+
payload > RESIDENT_ENGINE_MAX_PAYLOAD_BYTES) {
|
|
196
|
+
this.stop('hoi4-engine serve announced an invalid payload size');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.header = { id, body, payload };
|
|
200
|
+
}
|
|
201
|
+
const header = this.header;
|
|
202
|
+
if (this.bufferedBytes < header.payload)
|
|
203
|
+
return;
|
|
204
|
+
const payload = header.payload === 0 ? Buffer.alloc(0) : Buffer.from(this.take(header.payload));
|
|
205
|
+
this.header = undefined;
|
|
206
|
+
this.crashes = 0;
|
|
207
|
+
const body = header.body;
|
|
208
|
+
if (body.ok === true) {
|
|
209
|
+
const result = typeof body.result === 'object' && body.result !== null
|
|
210
|
+
? body.result
|
|
211
|
+
: {};
|
|
212
|
+
this.settle(header.id, { ok: true, response: { result, payload } });
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const error = typeof body.error === 'object' && body.error !== null
|
|
216
|
+
? body.error
|
|
217
|
+
: {};
|
|
218
|
+
const { code, message, ...details } = error;
|
|
219
|
+
this.settle(header.id, {
|
|
220
|
+
ok: false,
|
|
221
|
+
kind: 'error',
|
|
222
|
+
code: typeof code === 'string' ? code : 'error',
|
|
223
|
+
message: typeof message === 'string' ? message : 'the engine reported an error',
|
|
224
|
+
details,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
settle(id, outcome) {
|
|
230
|
+
const entry = this.pending.get(id);
|
|
231
|
+
if (entry === undefined)
|
|
232
|
+
return;
|
|
233
|
+
clearTimeout(entry.timer);
|
|
234
|
+
if (entry.onAbort !== undefined)
|
|
235
|
+
entry.signal?.removeEventListener('abort', entry.onAbort);
|
|
236
|
+
this.pending.delete(id);
|
|
237
|
+
this.updateRef();
|
|
238
|
+
entry.resolve(outcome);
|
|
239
|
+
}
|
|
240
|
+
onExit(child, message) {
|
|
241
|
+
if (child !== this.child)
|
|
242
|
+
return;
|
|
243
|
+
this.child = undefined;
|
|
244
|
+
if (!this.closed)
|
|
245
|
+
this.crashes += 1;
|
|
246
|
+
this.failAll(`${message}${this.stderrTail.trim() === '' ? '' : `: ${this.stderrTail.trim().slice(-300)}`}`);
|
|
247
|
+
}
|
|
248
|
+
stop(message) {
|
|
249
|
+
const child = this.child;
|
|
250
|
+
this.child = undefined;
|
|
251
|
+
if (child !== undefined) {
|
|
252
|
+
if (!this.closed)
|
|
253
|
+
this.crashes += 1;
|
|
254
|
+
child.kill();
|
|
255
|
+
}
|
|
256
|
+
this.failAll(message);
|
|
257
|
+
}
|
|
258
|
+
failAll(message) {
|
|
259
|
+
for (const id of [...this.pending.keys()])
|
|
260
|
+
this.settle(id, { ok: false, kind: 'unavailable', reason: 'exit_status', message });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
let shared;
|
|
264
|
+
/** The server-wide resident engine (one process per server). */
|
|
265
|
+
export function sharedResidentEngine() {
|
|
266
|
+
shared ??= new ResidentEngine();
|
|
267
|
+
return shared;
|
|
268
|
+
}
|
|
269
|
+
/** Test hook: replaces the shared engine and closes the old one. */
|
|
270
|
+
export function replaceSharedResidentEngine(engine) {
|
|
271
|
+
shared?.close();
|
|
272
|
+
shared = engine;
|
|
273
|
+
}
|
|
@@ -167,7 +167,7 @@ export async function sweepTemporaryDirectories(parent, options = {}) {
|
|
|
167
167
|
continue;
|
|
168
168
|
await lock.close();
|
|
169
169
|
lock = undefined;
|
|
170
|
-
await rm(entry.directory, { recursive: true, force: true });
|
|
170
|
+
await rm(entry.directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
|
|
171
171
|
retainedBytes -= entry.bytes;
|
|
172
172
|
removed += 1;
|
|
173
173
|
}
|
|
@@ -265,7 +265,8 @@ export class TemporaryDirectoryLifetime {
|
|
|
265
265
|
}
|
|
266
266
|
if ((await lstat(directory)).isSymbolicLink() || (await realpath(directory)) !== directory)
|
|
267
267
|
throw new Error('Temporary directory changed before cleanup');
|
|
268
|
-
|
|
268
|
+
// Windows can hold a file a closed process wrote for a moment (ENOTEMPTY, EBUSY).
|
|
269
|
+
await rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
|
|
269
270
|
this.#owned.delete(directory);
|
|
270
271
|
this.#forgetFiles(directory);
|
|
271
272
|
}
|
|
@@ -4,6 +4,7 @@ import { canonicalJson, hashCanonical } from '../core/canonical.js';
|
|
|
4
4
|
import { setInlineFilesScanned } from '../core/operation-result.js';
|
|
5
5
|
import { emptyServiceResult, ServiceError } from '../core/result.js';
|
|
6
6
|
import { buildProposedSourceOverlay } from '../core/source-overlay.js';
|
|
7
|
+
import { nearestNames } from '../reference/suggestions.js';
|
|
7
8
|
import { PACKAGE_VERSION } from '../version.js';
|
|
8
9
|
import { inspectDecisionAi } from './ai.js';
|
|
9
10
|
import { compareDecisionScenarios, inspectDecisionScenario } from './comparison.js';
|
|
@@ -33,6 +34,12 @@ export class DecisionAnalyzer {
|
|
|
33
34
|
if (input.mode !== 'compare' && input.proposedSources !== undefined)
|
|
34
35
|
throw new ServiceError('DECISION_PROPOSAL_MODE', 'Proposed sources require compare mode');
|
|
35
36
|
const inventory = decisionSourceInventory(before);
|
|
37
|
+
if (input.mode === 'inspect' &&
|
|
38
|
+
input.id !== undefined &&
|
|
39
|
+
!inventory.decisions.some((source) => source.id === input.id)) {
|
|
40
|
+
const suggestions = nearestNames(input.id, new Set(inventory.decisions.map((source) => source.id)));
|
|
41
|
+
throw new ServiceError('DECISION_NOT_FOUND', `No decision ${input.id.slice(0, 256)} is defined${before.complete ? '' : ' in the scanned files (the scan is incomplete)'}${suggestions.length === 0 ? '' : `; did you mean ${suggestions.join(', ')}?`}`, { id: input.id.slice(0, 256), suggestions, scanComplete: before.complete });
|
|
42
|
+
}
|
|
36
43
|
const overlay = input.proposedSources === undefined
|
|
37
44
|
? undefined
|
|
38
45
|
: buildProposedSourceOverlay(before, workspace, input.proposedSources);
|
|
@@ -6,6 +6,7 @@ import { canonicalJson, canonicalJsonByteLength, compareCodeUnits, hashCanonical
|
|
|
6
6
|
import { installedEffectCommands } from '../core/game-documentation.js';
|
|
7
7
|
import { boundedSourceHashEvidence, publicArtifactLink, } from '../core/artifacts.js';
|
|
8
8
|
import { ServiceError } from '../core/result.js';
|
|
9
|
+
import { nearestNames } from '../reference/suggestions.js';
|
|
9
10
|
import { RenderBudget } from '../core/render-budget.js';
|
|
10
11
|
import { SOURCE_MAX_BYTES } from '../core/source/index.js';
|
|
11
12
|
import { isPortablePathSegment } from '../core/workspace.js';
|
|
@@ -13,7 +14,7 @@ import { PACKAGE_VERSION } from '../version.js';
|
|
|
13
14
|
import { buildEventGraph, buildEventGraphAsync } from './graph.js';
|
|
14
15
|
import { summarizeEventImpact, summarizeEventIssues, summarizeEventPath, summarizeEventRoots, summarizeEventTrace, } from './summary.js';
|
|
15
16
|
import { EVENT_FRAGMENT_CACHE_MAX_ENTRIES, EVENT_FRAGMENT_CACHE_MAX_SOURCE_BYTES, EVENT_GRAPH_SNAPSHOT_MAX_BYTES, EVENT_PROPOSED_SOURCE_MAX_BYTES, EVENT_PROPOSED_SOURCE_MAX_FILES, } from './limits.js';
|
|
16
|
-
import { analyzeEventImpact, discoverEventRoots, explainEventPath, inspectEventStateFlow, lintEventGraph, traceSelectedEvents, } from './queries.js';
|
|
17
|
+
import { analyzeEventImpact, discoverEventRoots, explainEventPath, inspectEventStateFlow, lintEventGraph, selectEventNodes, traceSelectedEvents, } from './queries.js';
|
|
17
18
|
import { compareEventGraphs, eventGraphHash } from './compare.js';
|
|
18
19
|
import { selectEventComparison } from './comparison-selection.js';
|
|
19
20
|
import { eventFlowEdges } from './algorithms.js';
|
|
@@ -161,9 +162,15 @@ function engineGeneration(engine, workspaceId) {
|
|
|
161
162
|
function eventScanPatterns(workspace, focused = false) {
|
|
162
163
|
const roots = workspace.registration.roots;
|
|
163
164
|
const under = (values, glob) => values.map((root) => `${root.replaceAll('\\', '/').replace(/\/$/u, '')}/${glob}`);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
// A focused route still resolves scripted-effect helpers and follows callers back through
|
|
166
|
+
// them, so it scans every folder that can define or call one. Only localisation, which
|
|
167
|
+
// feeds the skipped lint passes, is left out.
|
|
168
|
+
const localisation = focused
|
|
169
|
+
? []
|
|
170
|
+
: [
|
|
171
|
+
...under(roots.localisation, 'english/**/*.{yml,yaml}'),
|
|
172
|
+
...under(roots.localisation, '*.{yml,yaml}'),
|
|
173
|
+
];
|
|
167
174
|
return [
|
|
168
175
|
'events/**/*.txt',
|
|
169
176
|
'history/countries/**/*.txt',
|
|
@@ -182,8 +189,7 @@ function eventScanPatterns(workspace, focused = false) {
|
|
|
182
189
|
'common/scripted_effects/**/*.txt',
|
|
183
190
|
...under(roots.focus, '**/*.txt'),
|
|
184
191
|
...under(roots.scriptedGui, '**/*.txt'),
|
|
185
|
-
...
|
|
186
|
-
...under(roots.localisation, '*.{yml,yaml}'),
|
|
192
|
+
...localisation,
|
|
187
193
|
].sort(compareCodeUnits);
|
|
188
194
|
}
|
|
189
195
|
async function scanEventSources(engine, workspaceId, workspace, focused = false, signal) {
|
|
@@ -854,6 +860,12 @@ export class EventChainViewer {
|
|
|
854
860
|
case 'trace':
|
|
855
861
|
if (input.selector === undefined)
|
|
856
862
|
throw new ServiceError('EVENT_SELECTOR_REQUIRED', 'Trace requires a selector');
|
|
863
|
+
if (input.selector.kind === 'event' &&
|
|
864
|
+
selectEventNodes(graph, input.selector).length === 0) {
|
|
865
|
+
// An event no file defines or fires is not-found, never an empty trace.
|
|
866
|
+
const suggestions = nearestNames(input.selector.eventId, new Set(graph.nodes.flatMap(({ eventId }) => (eventId === undefined ? [] : [eventId]))));
|
|
867
|
+
throw new ServiceError('EVENT_NOT_FOUND', `No scanned file defines or fires event ${input.selector.eventId.slice(0, 256)}${suggestions.length === 0 ? '' : `; did you mean ${suggestions.join(', ')}?`}`, { eventId: input.selector.eventId.slice(0, 256), suggestions });
|
|
868
|
+
}
|
|
857
869
|
{
|
|
858
870
|
const trace = traceSelectedEvents(graph, input.selector, {
|
|
859
871
|
maxDepth,
|
|
@@ -3,6 +3,7 @@ import { compareCodeUnits } from '../core/canonical.js';
|
|
|
3
3
|
export const EVENT_INLINE_FINDINGS = 10;
|
|
4
4
|
const EVENT_INLINE_CODES = 10;
|
|
5
5
|
const EVENT_INLINE_EVENT_IDS = 20;
|
|
6
|
+
const EVENT_INLINE_TRACE_NAMES = 20;
|
|
6
7
|
const EVENT_INLINE_MESSAGE_LENGTH = 300;
|
|
7
8
|
const CLASSIFICATION_ORDER = {
|
|
8
9
|
confirmed_error: 0,
|
|
@@ -72,11 +73,19 @@ export function summarizeEventTrace(trace) {
|
|
|
72
73
|
const events = trace.nodes
|
|
73
74
|
.flatMap(({ kind, eventId }) => (kind === 'event' && eventId !== undefined ? [eventId] : []))
|
|
74
75
|
.sort(compareCodeUnits);
|
|
76
|
+
// Callers that reach an event through scripted effects, decisions or focuses are not events,
|
|
77
|
+
// so name them here as well. Otherwise an upstream trace looks callerless without its report.
|
|
78
|
+
const entries = [
|
|
79
|
+
...new Set(trace.nodes.flatMap(({ kind, label }) => (kind === 'entry' ? [label] : []))),
|
|
80
|
+
].sort(compareCodeUnits);
|
|
81
|
+
const helpers = [...new Set(trace.edges.flatMap(({ helperStack }) => helperStack))].sort(compareCodeUnits);
|
|
75
82
|
return {
|
|
76
83
|
nodes: trace.nodes.length,
|
|
77
84
|
edges: trace.edges.length,
|
|
78
85
|
events: events.length,
|
|
79
86
|
eventIds: events.slice(0, EVENT_INLINE_EVENT_IDS),
|
|
87
|
+
entryPoints: entries.slice(0, EVENT_INLINE_TRACE_NAMES),
|
|
88
|
+
helpers: helpers.slice(0, EVENT_INLINE_TRACE_NAMES),
|
|
80
89
|
boundaryNodes: trace.boundaryNodeIds.length,
|
|
81
90
|
truncated: trace.truncated,
|
|
82
91
|
};
|