@rob-c/pi-managed-tools 0.16.0 → 0.23.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/BUSYBOX-CONTRACT.md +440 -0
- package/CHANGELOG.md +441 -0
- package/README.md +464 -35
- package/package.json +7 -4
- package/skills/busybox-applets/SKILL.md +142 -15
- package/skills/managed-tools/SKILL.md +201 -25
- package/skills/managed-tools-reference/SKILL.md +206 -38
- package/src/agentops.ts +813 -0
- package/src/agenttools.ts +391 -0
- package/src/bashtool.ts +103 -0
- package/src/build.ts +142 -0
- package/src/context.ts +157 -0
- package/src/display.ts +79 -0
- package/src/extension.ts +817 -28
- package/src/guard.ts +437 -0
- package/src/jobs.ts +1052 -0
- package/src/timing.ts +364 -0
- package/src/tools.ts +525 -42
- package/src/userstdin.ts +524 -0
- package/src/wrap.ts +683 -0
package/src/timing.ts
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* pi-managed-tools — keep a set of developer binaries at their latest upstream release.
|
|
3
|
+
* Copyright (C) 2026 Robert Currie
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or modify it under
|
|
6
|
+
* the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
* Foundation; version 2 of the License only.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
10
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
11
|
+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the GNU General Public License along with this
|
|
14
|
+
* program; if not, see <https://www.gnu.org/licenses/gpl-2.0.html>.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* One line that says what the offsets mean.
|
|
18
|
+
*
|
|
19
|
+
* A timeline answers "in what order", but the useful question about a slow command is
|
|
20
|
+
* usually "where did the time go": three seconds after the last line? A stall between
|
|
21
|
+
* two phases? Eight minutes of silence before the failure? A model reading 300 timestamped
|
|
22
|
+
* lines can work that out, and pays attention for it every time; a summary costs one line.
|
|
23
|
+
*
|
|
24
|
+
* Only the shape is summarised — total, where output started, the longest silence — so a
|
|
25
|
+
* caller can still read the offsets when the summary is not the question.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export interface TimelineSample {
|
|
29
|
+
/** Microseconds from process start, as the timeline prints them. */
|
|
30
|
+
us: number;
|
|
31
|
+
stream: "out" | "err";
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A timeline line, in every shape a build has printed it:
|
|
37
|
+
*
|
|
38
|
+
* [ 0.011354 out] ok 1 padded, six digits (to 0.5.x)
|
|
39
|
+
* [00000.005868042 out] ok 1 zero-padded, nine with -n (0.6.0)
|
|
40
|
+
* [0.005868042 out] ok 1 unpadded, always nine with -n (0.6.1 on)
|
|
41
|
+
* [1.225 out], [10.23 out] fewer as the offset grows (0.6.1 on, no -n)
|
|
42
|
+
* [= out] ok 2 the offset of the line above (compactStamps)
|
|
43
|
+
*
|
|
44
|
+
* So the fraction is one to nine digits and is read as a decimal fraction, never as a
|
|
45
|
+
* count of a fixed unit. The `s` flag matters: a line from a CRLF file ends in a carriage
|
|
46
|
+
* return, which `.` does not match without it, and such a line would drop out of the
|
|
47
|
+
* digest.
|
|
48
|
+
*/
|
|
49
|
+
const TIMELINE_LINE = /^\[(?:\s*(\d+)\.(\d{1,9})|(=)) (out|err)\] (.*)$/s;
|
|
50
|
+
|
|
51
|
+
/** The wrapper's own summary line: `run=R12 exit_code=0 … duration_ms=328`. */
|
|
52
|
+
const RUN_HEADER = /^run=R\d+ .*duration_ms=(\d+)/;
|
|
53
|
+
|
|
54
|
+
/** Parse the text-mode timeline the bash wrapper produces. */
|
|
55
|
+
export function parseTimeline(text: string): TimelineSample[] {
|
|
56
|
+
const samples: TimelineSample[] = [];
|
|
57
|
+
let previous = 0;
|
|
58
|
+
for (const line of text.split("\n")) {
|
|
59
|
+
const match = TIMELINE_LINE.exec(line);
|
|
60
|
+
if (!match) continue;
|
|
61
|
+
// Every width lands in microseconds, so durations stay one unit everywhere. Padded
|
|
62
|
+
// to nine first: a shortened `.225` is 225 000 us, not 225.
|
|
63
|
+
const us = match[3] === "=" ? previous : Number(match[1]) * 1_000_000 + Number((match[2] as string).padEnd(9, "0")) / 1000;
|
|
64
|
+
previous = us;
|
|
65
|
+
samples.push({ us, stream: match[4] as "out" | "err", text: match[5] as string });
|
|
66
|
+
}
|
|
67
|
+
return samples;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A full stamp at the start of a line, and the offset inside it. */
|
|
71
|
+
const FULL_STAMP = /^\[(\s*\d+\.\d{1,9}) (out|err)\] /;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Print an offset once per burst: a line that arrived at the same offset as the line
|
|
75
|
+
* above it carries `[= out]` instead of the digits again.
|
|
76
|
+
*
|
|
77
|
+
* Stamps were measured at a quarter of all bash-result bytes, and most output arrives in
|
|
78
|
+
* bursts — a listing, a file, a test summary flushed at once — where every line repeats
|
|
79
|
+
* the same eighteen characters. The stream tag stays on every line; only the repeated
|
|
80
|
+
* number goes. Lossless: `parseTimeline` reads `=` back as the offset above.
|
|
81
|
+
*
|
|
82
|
+
* Only inside the timeline section of a wrapped result; the header, the truncation
|
|
83
|
+
* marker and anything appended after the timeline are left as they are.
|
|
84
|
+
*/
|
|
85
|
+
export function compactStamps(text: string): string {
|
|
86
|
+
let last: string | undefined;
|
|
87
|
+
return text
|
|
88
|
+
.split("\n")
|
|
89
|
+
.map((line) => {
|
|
90
|
+
const match = FULL_STAMP.exec(line);
|
|
91
|
+
if (!match) {
|
|
92
|
+
// Anything that is not a timeline line ends the burst: the truncation
|
|
93
|
+
// marker, the digest, a note.
|
|
94
|
+
last = undefined;
|
|
95
|
+
return line;
|
|
96
|
+
}
|
|
97
|
+
const offset = (match[1] as string).trim();
|
|
98
|
+
if (offset === last) return `[= ${match[2]}] ${line.slice(match[0].length)}`;
|
|
99
|
+
last = offset;
|
|
100
|
+
return line;
|
|
101
|
+
})
|
|
102
|
+
.join("\n");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** What the run's own two header lines say, field by field. */
|
|
106
|
+
export interface RunHeader {
|
|
107
|
+
runId: string;
|
|
108
|
+
exitCode?: number;
|
|
109
|
+
timedOut: boolean;
|
|
110
|
+
cancelled: boolean;
|
|
111
|
+
idle: boolean;
|
|
112
|
+
durationMs?: number;
|
|
113
|
+
/** Lines the command printed in all, and how many of them the view shows. */
|
|
114
|
+
linesTotal?: number;
|
|
115
|
+
linesShown?: number;
|
|
116
|
+
truncated: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Read the header of a wrapped result, or undefined when the text is not one.
|
|
121
|
+
*
|
|
122
|
+
* Field by field off the header line and nowhere else: the header gains fields between
|
|
123
|
+
* builds (`idle=` arrived in 0.6.0), and a command that prints `timed_out=true` in its
|
|
124
|
+
* own output has not timed out.
|
|
125
|
+
*/
|
|
126
|
+
export function parseHeader(text: string): RunHeader | undefined {
|
|
127
|
+
const header = /^run=(R\d+) .*$/m.exec(text);
|
|
128
|
+
if (!header) return undefined;
|
|
129
|
+
const field = (name: string) => new RegExp(` ${name}=(\\S+)`).exec(header[0])?.[1];
|
|
130
|
+
const number = (value: string | undefined) => (value !== undefined && /^-?\d+$/.test(value) ? Number(value) : undefined);
|
|
131
|
+
const counts = /^timeline_lines=(\d+) shown=(\d+) truncated=(true|false)/m.exec(text);
|
|
132
|
+
return {
|
|
133
|
+
runId: header[1] as string,
|
|
134
|
+
exitCode: number(field("exit_code")),
|
|
135
|
+
timedOut: field("timed_out") === "true",
|
|
136
|
+
cancelled: field("cancelled") === "true",
|
|
137
|
+
idle: field("idle") === "true",
|
|
138
|
+
durationMs: number(field("duration_ms")),
|
|
139
|
+
linesTotal: counts ? Number(counts[1]) : undefined,
|
|
140
|
+
linesShown: counts ? Number(counts[2]) : undefined,
|
|
141
|
+
truncated: counts ? counts[3] === "true" : /^(?:captured_bytes=.*view_truncated=true)/m.test(text),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Total wall time the wrapper reported, in milliseconds. */
|
|
146
|
+
export function parseDurationMs(text: string): number | undefined {
|
|
147
|
+
for (const line of text.split("\n")) {
|
|
148
|
+
const match = RUN_HEADER.exec(line);
|
|
149
|
+
if (match) return Number(match[1]);
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function seconds(us: number): string {
|
|
155
|
+
return `${(us / 1_000_000).toFixed(2)}s`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The one-line shape of a run: `timing: 8.42s total, 412 lines, output from 0.02s,
|
|
160
|
+
* silent 6.10s (2.32s → 8.42s)`, or undefined when there is nothing worth saying.
|
|
161
|
+
*
|
|
162
|
+
* "Nothing worth saying" is deliberate: a command that finished in 40 ms with five lines
|
|
163
|
+
* gets no line, because a summary on every call is noise the model pays for.
|
|
164
|
+
*/
|
|
165
|
+
export function summarizeTiming(
|
|
166
|
+
samples: TimelineSample[],
|
|
167
|
+
durationMs?: number,
|
|
168
|
+
options: { minDurationMs?: number; minGapUs?: number } = {},
|
|
169
|
+
): string | undefined {
|
|
170
|
+
if (samples.length < 2) return undefined;
|
|
171
|
+
const minDurationMs = options.minDurationMs ?? 1_000;
|
|
172
|
+
const minGapUs = options.minGapUs ?? 1_000_000;
|
|
173
|
+
|
|
174
|
+
const first = samples[0] as TimelineSample;
|
|
175
|
+
const last = samples[samples.length - 1] as TimelineSample;
|
|
176
|
+
const totalUs = (durationMs ?? 0) * 1_000 > last.us ? (durationMs as number) * 1_000 : last.us;
|
|
177
|
+
|
|
178
|
+
let gapUs = 0;
|
|
179
|
+
let gapFrom = 0;
|
|
180
|
+
let gaps = 0;
|
|
181
|
+
for (let i = 1; i < samples.length; i++) {
|
|
182
|
+
const previous = samples[i - 1] as TimelineSample;
|
|
183
|
+
const current = samples[i] as TimelineSample;
|
|
184
|
+
const delta = current.us - previous.us;
|
|
185
|
+
if (delta > gapUs) {
|
|
186
|
+
gapUs = delta;
|
|
187
|
+
gapFrom = previous.us;
|
|
188
|
+
}
|
|
189
|
+
if (delta >= minGapUs) gaps++;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (totalUs < minDurationMs * 1_000) return undefined;
|
|
193
|
+
|
|
194
|
+
const parts = [
|
|
195
|
+
`${seconds(totalUs)} total`,
|
|
196
|
+
`${samples.length} lines`,
|
|
197
|
+
`output from ${seconds(first.us)}`,
|
|
198
|
+
];
|
|
199
|
+
if (samples.some((sample) => sample.stream === "err")) {
|
|
200
|
+
const firstErr = samples.find((sample) => sample.stream === "err") as TimelineSample;
|
|
201
|
+
parts.push(`stderr from ${seconds(firstErr.us)}`);
|
|
202
|
+
}
|
|
203
|
+
if (gapUs >= minGapUs) {
|
|
204
|
+
const endsWithGap = totalUs - last.us >= minGapUs;
|
|
205
|
+
parts.push(
|
|
206
|
+
endsWithGap
|
|
207
|
+
? `silent ${seconds(totalUs - last.us)} after the last line (${seconds(last.us)} → ${seconds(totalUs)})`
|
|
208
|
+
: `longest pause ${seconds(gapUs)} (${seconds(gapFrom)} → ${seconds(gapFrom + gapUs)})`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
if (gaps > 1) parts.push(`${gaps} pauses over ${seconds(minGapUs)}`);
|
|
212
|
+
return `timing: ${parts.join(", ")}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** `run=R12 …`, or undefined when the text is not a wrapped run. */
|
|
216
|
+
export function parseRunId(text: string): string | undefined {
|
|
217
|
+
return text.match(/^run=(R\d+)\b/m)?.[1];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The pointer a truncated wrapper view needs.
|
|
222
|
+
*
|
|
223
|
+
* pi truncates at ~50 KB and keeps a temp file, but the wrapper's own budget is smaller
|
|
224
|
+
* (48 KB), so pi never sees a truncation and never offers the file — the model is left
|
|
225
|
+
* with `truncated=true` and no way to say "get me the middle". The capture is complete on
|
|
226
|
+
* disk, so name the command that reads it.
|
|
227
|
+
*/
|
|
228
|
+
export function truncationHint(text: string, options: { stderrTotal?: number } = {}): string | undefined {
|
|
229
|
+
if (!/^timeline_lines=\d+ shown=\d+ truncated=true/m.test(text) && !/truncated=true/.test(text)) return undefined;
|
|
230
|
+
const runId = parseRunId(text);
|
|
231
|
+
const shown = text.match(/timeline_lines=(\d+) shown=(\d+)/);
|
|
232
|
+
const total = shown ? Number(shown[1]) : 0;
|
|
233
|
+
const count = shown ? Number(shown[2]) : 0;
|
|
234
|
+
const scale = shown ? `${count} of ${total} lines shown` : "the view was truncated";
|
|
235
|
+
if (!runId) return `truncated: ${scale} — the full capture is on disk (busybox log needs a run id, which this view did not carry)`;
|
|
236
|
+
|
|
237
|
+
// Since 0.6.0 the view keeps the head AND the tail and marks the cut in between. What
|
|
238
|
+
// the model lacks is then the middle, and the lines it should be sent to are exactly
|
|
239
|
+
// those — not the last forty, which it already has.
|
|
240
|
+
const lines = text.split("\n");
|
|
241
|
+
const cut = lines.findIndex((line) => OMISSION_MARKER.test(line));
|
|
242
|
+
if (cut >= 0) {
|
|
243
|
+
let head = 0;
|
|
244
|
+
let errShown = 0;
|
|
245
|
+
for (const [index, line] of lines.entries()) {
|
|
246
|
+
const match = TIMELINE_LINE.exec(line);
|
|
247
|
+
if (!match) continue;
|
|
248
|
+
if (index < cut) head++;
|
|
249
|
+
if (match[4] === "err") errShown++;
|
|
250
|
+
}
|
|
251
|
+
const omitted = Number(OMISSION_MARKER.exec(lines[cut] as string)?.[1] ?? total - count);
|
|
252
|
+
const from = head + 1;
|
|
253
|
+
const to = head + omitted;
|
|
254
|
+
// The dangerous silence: a view with no [err] line reads as "no errors" when the
|
|
255
|
+
// errors are in the part that was cut. Say how many there are, when it is known.
|
|
256
|
+
const hidden = options.stderrTotal !== undefined ? Math.max(0, options.stderrTotal - errShown) : undefined;
|
|
257
|
+
const errors =
|
|
258
|
+
hidden === undefined
|
|
259
|
+
? "it may hold stderr lines this view does not show"
|
|
260
|
+
: hidden === 0
|
|
261
|
+
? "none of them on stderr"
|
|
262
|
+
: `${hidden} of them on stderr (\`busybox log ${runId} --stream stderr\` shows those alone)`;
|
|
263
|
+
return `truncated: ${scale} — the first ${head} and the last ${count - head}. Lines ${from}-${to} are omitted, ${errors}. The capture is complete: read part of the gap with busybox log ${runId} --stream timeline --lines ${from}:${Math.min(to, from + 39)}, or find a literal anywhere in it with busybox log ${runId} --match STR.`;
|
|
264
|
+
}
|
|
265
|
+
// An older build's view keeps the head only, so the useful thing to name is the tail:
|
|
266
|
+
// that is where a test suite's verdict lives.
|
|
267
|
+
const from = Math.max(1, total - 40);
|
|
268
|
+
return `truncated: ${scale}, head only — the capture is complete; read the end with busybox log ${runId} --lines ${from}:${total}, a pattern with --match STR, or the interleaved view with busybox_run run_id=${runId}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** `... [timeline truncated: 183 of 6000 lines shown (5817 omitted); …] ...`, as `run` prints it. */
|
|
272
|
+
const OMISSION_MARKER = /^\.\.\. \[timeline truncated: \d+ of \d+ lines shown \((\d+) omitted\)/;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The sentence a timeout needs, and never a euphemism.
|
|
276
|
+
*
|
|
277
|
+
* The wrapper exits 3 and prints `exit_code=-1 timed_out=true`; pi then appends
|
|
278
|
+
* "Command exited with code 3". Read together those look like the *command* failed, which
|
|
279
|
+
* sends a model down a debugging path when the right move is to retry with more time or
|
|
280
|
+
* narrow the command. So the result says plainly what happened, what the statuses mean, and
|
|
281
|
+
* what to do next — including that the kill was deliberate.
|
|
282
|
+
*/
|
|
283
|
+
export function describeTimeout(options: { seconds?: number; runId?: string } = {}): string {
|
|
284
|
+
const budget = options.seconds ? `the ${options.seconds}s deadline` : "its deadline";
|
|
285
|
+
const lines = [
|
|
286
|
+
`TIMEOUT — not a failure of the command: it was still running when ${budget} fired, so it was killed.`,
|
|
287
|
+
'`exit_code=-1` above and pi\'s "Command exited with code 3" are the kill status, not the command\'s own exit code.',
|
|
288
|
+
];
|
|
289
|
+
if (options.runId) {
|
|
290
|
+
lines.push(
|
|
291
|
+
`Everything it printed before the kill is above and the capture is complete: busybox log ${options.runId} --lines 1:40 reads it again.`,
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
lines.push(
|
|
295
|
+
"Recovery: raise `timeout` on this call (seconds) if the work is genuinely long, narrow the command, or run it in the background and poll with `waitfor`.",
|
|
296
|
+
);
|
|
297
|
+
return lines.join("\n");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** The sentence for an idle kill: a hang, not slow work, and not a timeout either. */
|
|
301
|
+
export function describeIdle(options: { seconds?: number; runId?: string } = {}): string {
|
|
302
|
+
const budget = options.seconds ? `the ${options.seconds}s silence watchdog` : "the silence watchdog";
|
|
303
|
+
const lines = [
|
|
304
|
+
`IDLE — not a failure of the command and not a timeout: ${budget} killed it for producing no output at all. This was a hang, not slow work.`,
|
|
305
|
+
"It was not waiting on stdin: stdin is empty here and a read returns end-of-file at once. Check what else it waited on: a socket, a lock, a child process that never exits.",
|
|
306
|
+
];
|
|
307
|
+
if (options.runId) lines.push(`The partial capture is complete: busybox log ${options.runId} reads it again.`);
|
|
308
|
+
return lines.join("\n");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** The sentence for a cancelled run, which is a different situation from a timeout. */
|
|
312
|
+
export function describeCancellation(runId?: string): string {
|
|
313
|
+
const lines = [
|
|
314
|
+
"CANCELLED — the command was stopped on request (interrupt or abort), not because it failed.",
|
|
315
|
+
"The capture so far is complete" + (runId ? `: busybox log ${runId} reads it again.` : "."),
|
|
316
|
+
];
|
|
317
|
+
return lines.join("\n");
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Which notice a wrapper result needs, if any: a deadline, a silence, a cancellation or a
|
|
322
|
+
* signal.
|
|
323
|
+
*
|
|
324
|
+
* Read off the run's own header line and nowhere else — a command that prints
|
|
325
|
+
* `timed_out=true` in its output has not timed out.
|
|
326
|
+
*/
|
|
327
|
+
export function outcomeNotice(text: string, seconds?: number, idleSeconds?: number): string | undefined {
|
|
328
|
+
const header = parseHeader(text);
|
|
329
|
+
if (!header) return undefined;
|
|
330
|
+
if (header.timedOut) {
|
|
331
|
+
// Cite a budget only when the run's own duration says that budget is the one that
|
|
332
|
+
// fired. A caller-supplied timeout beats the default, and a notice naming "the 120s
|
|
333
|
+
// deadline" on a 599s kill would be a lie the model might act on.
|
|
334
|
+
const budget = parseBudgetFromDuration(text, seconds);
|
|
335
|
+
return describeTimeout({ seconds: budget, runId: header.runId });
|
|
336
|
+
}
|
|
337
|
+
if (header.idle) {
|
|
338
|
+
// The hang signature: no output at all until the silence watchdog fired. Same
|
|
339
|
+
// budget honesty as the deadline notice, against the idle number.
|
|
340
|
+
const budget = parseBudgetFromDuration(text, idleSeconds);
|
|
341
|
+
return describeIdle({ seconds: budget, runId: header.runId });
|
|
342
|
+
}
|
|
343
|
+
if (header.cancelled) return describeCancellation(header.runId);
|
|
344
|
+
// No deadline, no silence, no request — and still no status: the shell was ended by a
|
|
345
|
+
// signal. Without this the result reads as an ordinary failure with pi's "code 1".
|
|
346
|
+
if (header.exitCode === -1) return describeSignal();
|
|
347
|
+
return undefined;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** The sentence for a command whose own shell was ended by a signal. */
|
|
351
|
+
export function describeSignal(): string {
|
|
352
|
+
return [
|
|
353
|
+
"KILLED — the command's shell was ended by a signal; it did not exit on its own.",
|
|
354
|
+
'`exit_code=-1` above and pi\'s "Command exited with code 1" are placeholders, not a status the command returned.',
|
|
355
|
+
].join("\n");
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** True when the run died within ~2s of the claimed budget — i.e. that budget killed it. */
|
|
359
|
+
function parseBudgetFromDuration(text: string, seconds?: number): number | undefined {
|
|
360
|
+
if (!seconds) return undefined;
|
|
361
|
+
const duration = Number(/duration_ms=(\d+)/.exec(text)?.[1]);
|
|
362
|
+
if (!Number.isFinite(duration)) return seconds;
|
|
363
|
+
return Math.abs(duration / 1000 - seconds) <= 2 ? seconds : undefined;
|
|
364
|
+
}
|