agent-inspect 4.0.0 → 4.1.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 +11 -0
- package/docs/CLI.md +20 -0
- package/package.json +2 -2
- package/packages/cli/dist/chunk-MT5G7JFO.mjs +3234 -0
- package/packages/cli/dist/chunk-MT5G7JFO.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +2406 -683
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +384 -3414
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/src-DUGEOAZ7.mjs +1157 -0
- package/packages/cli/dist/src-DUGEOAZ7.mjs.map +1 -0
|
@@ -1,39 +1,69 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var fs = require('fs');
|
|
5
|
-
var path14 = require('path');
|
|
6
|
-
var url = require('url');
|
|
7
|
-
var commander = require('commander');
|
|
8
|
-
var async_hooks = require('async_hooks');
|
|
9
4
|
var crypto = require('crypto');
|
|
10
5
|
var promises = require('fs/promises');
|
|
11
6
|
var os = require('os');
|
|
7
|
+
var path14 = require('path');
|
|
8
|
+
var async_hooks = require('async_hooks');
|
|
12
9
|
var process3 = require('process');
|
|
13
10
|
var tty = require('tty');
|
|
11
|
+
var fs = require('fs');
|
|
14
12
|
var readline = require('readline');
|
|
13
|
+
var url = require('url');
|
|
14
|
+
var commander = require('commander');
|
|
15
15
|
var http = require('http');
|
|
16
16
|
var module$1 = require('module');
|
|
17
17
|
|
|
18
18
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
19
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
20
|
|
|
21
|
-
var path14__default = /*#__PURE__*/_interopDefault(path14);
|
|
22
21
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
23
22
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
23
|
+
var path14__default = /*#__PURE__*/_interopDefault(path14);
|
|
24
24
|
var process3__default = /*#__PURE__*/_interopDefault(process3);
|
|
25
25
|
var tty__default = /*#__PURE__*/_interopDefault(tty);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
var
|
|
27
|
+
var __create = Object.create;
|
|
28
|
+
var __defProp = Object.defineProperty;
|
|
29
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
30
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
31
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
32
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
33
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
34
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
35
|
+
}) : x)(function(x) {
|
|
36
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
37
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
38
|
+
});
|
|
39
|
+
var __esm = (fn, res) => function __init() {
|
|
40
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
41
|
+
};
|
|
42
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
43
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
44
|
+
};
|
|
45
|
+
var __export = (target, all) => {
|
|
46
|
+
for (var name in all)
|
|
47
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
48
|
+
};
|
|
49
|
+
var __copyProps = (to, from, except, desc) => {
|
|
50
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
51
|
+
for (let key of __getOwnPropNames(from))
|
|
52
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
53
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
54
|
+
}
|
|
55
|
+
return to;
|
|
56
|
+
};
|
|
57
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
58
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
59
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
60
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
61
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
62
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
63
|
+
mod
|
|
64
|
+
));
|
|
29
65
|
|
|
30
66
|
// packages/core/src/correlation-metadata.ts
|
|
31
|
-
var TRACE_CORRELATION_KEYS = [
|
|
32
|
-
"correlationId",
|
|
33
|
-
"requestId",
|
|
34
|
-
"decisionId",
|
|
35
|
-
"groupId"
|
|
36
|
-
];
|
|
37
67
|
function isNonEmptyString(value) {
|
|
38
68
|
return typeof value === "string" && value.length > 0;
|
|
39
69
|
}
|
|
@@ -52,15 +82,17 @@ function extractCorrelationMetadata(record) {
|
|
|
52
82
|
}
|
|
53
83
|
return found ? out : void 0;
|
|
54
84
|
}
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
];
|
|
85
|
+
var TRACE_CORRELATION_KEYS;
|
|
86
|
+
var init_correlation_metadata = __esm({
|
|
87
|
+
"packages/core/src/correlation-metadata.ts"() {
|
|
88
|
+
TRACE_CORRELATION_KEYS = [
|
|
89
|
+
"correlationId",
|
|
90
|
+
"requestId",
|
|
91
|
+
"decisionId",
|
|
92
|
+
"groupId"
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
64
96
|
function isRecord(v) {
|
|
65
97
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
66
98
|
}
|
|
@@ -99,94 +131,67 @@ function compileRules(rules, extraKeys) {
|
|
|
99
131
|
}
|
|
100
132
|
return [...out.values()];
|
|
101
133
|
}
|
|
102
|
-
var Redactor
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return asString.length <= keep ? `${asString}\u2026` : `${asString.slice(0, keep)}\u2026`;
|
|
119
|
-
}
|
|
120
|
-
if (rule.strategy === "hash") {
|
|
121
|
-
if (asString === void 0) return "[HASH:unknown]";
|
|
122
|
-
return `[HASH:${stableHash(asString)}]`;
|
|
123
|
-
}
|
|
124
|
-
return this.#redactNested(value);
|
|
125
|
-
}
|
|
126
|
-
redactRecord(record) {
|
|
127
|
-
const out = {};
|
|
128
|
-
for (const [k, v] of Object.entries(record)) {
|
|
129
|
-
out[k] = this.redactValue(k, v);
|
|
130
|
-
}
|
|
131
|
-
return out;
|
|
132
|
-
}
|
|
133
|
-
#redactNested(value) {
|
|
134
|
-
if (Array.isArray(value)) {
|
|
135
|
-
return value.map((v) => this.#redactNested(v));
|
|
136
|
-
}
|
|
137
|
-
if (isRecord(value)) {
|
|
138
|
-
const out = {};
|
|
139
|
-
for (const [k, v] of Object.entries(value)) {
|
|
140
|
-
out[k] = this.redactValue(k, v);
|
|
134
|
+
var DEFAULT_REDACT_KEYS, Redactor;
|
|
135
|
+
var init_redactor = __esm({
|
|
136
|
+
"packages/core/src/logs/redactor.ts"() {
|
|
137
|
+
DEFAULT_REDACT_KEYS = [
|
|
138
|
+
"authorization",
|
|
139
|
+
"cookie",
|
|
140
|
+
"token",
|
|
141
|
+
"apiKey",
|
|
142
|
+
"password",
|
|
143
|
+
"secret",
|
|
144
|
+
"email"
|
|
145
|
+
];
|
|
146
|
+
Redactor = class {
|
|
147
|
+
#rules;
|
|
148
|
+
constructor(options) {
|
|
149
|
+
this.#rules = compileRules(options?.rules, options?.extraKeys);
|
|
141
150
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
151
|
+
redactValue(key, value) {
|
|
152
|
+
const k = toKey(key);
|
|
153
|
+
const rule = this.#rules.find((r) => r.key === k);
|
|
154
|
+
if (!rule) {
|
|
155
|
+
return this.#redactNested(value);
|
|
156
|
+
}
|
|
157
|
+
if (rule.strategy === "full") return "[REDACTED]";
|
|
158
|
+
const asString = typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" ? String(value) : void 0;
|
|
159
|
+
if (rule.strategy === "prefix") {
|
|
160
|
+
if (asString === void 0) return "[REDACTED]";
|
|
161
|
+
const keep = Math.max(0, Math.floor(rule.keep));
|
|
162
|
+
return asString.length <= keep ? `${asString}\u2026` : `${asString.slice(0, keep)}\u2026`;
|
|
163
|
+
}
|
|
164
|
+
if (rule.strategy === "hash") {
|
|
165
|
+
if (asString === void 0) return "[HASH:unknown]";
|
|
166
|
+
return `[HASH:${stableHash(asString)}]`;
|
|
167
|
+
}
|
|
168
|
+
return this.#redactNested(value);
|
|
169
|
+
}
|
|
170
|
+
redactRecord(record) {
|
|
171
|
+
const out = {};
|
|
172
|
+
for (const [k, v] of Object.entries(record)) {
|
|
173
|
+
out[k] = this.redactValue(k, v);
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
#redactNested(value) {
|
|
178
|
+
if (Array.isArray(value)) {
|
|
179
|
+
return value.map((v) => this.#redactNested(v));
|
|
180
|
+
}
|
|
181
|
+
if (isRecord(value)) {
|
|
182
|
+
const out = {};
|
|
183
|
+
for (const [k, v] of Object.entries(value)) {
|
|
184
|
+
out[k] = this.redactValue(k, v);
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
145
191
|
}
|
|
146
|
-
};
|
|
192
|
+
});
|
|
147
193
|
|
|
148
194
|
// packages/core/src/redaction-profiles.ts
|
|
149
|
-
var SHARE_PROFILE_EXTRA_KEYS = [
|
|
150
|
-
"userEmail",
|
|
151
|
-
"customerEmail",
|
|
152
|
-
"phone",
|
|
153
|
-
"phoneNumber",
|
|
154
|
-
"address",
|
|
155
|
-
"ip",
|
|
156
|
-
"ipAddress",
|
|
157
|
-
"sessionId",
|
|
158
|
-
"requestId",
|
|
159
|
-
"correlationId",
|
|
160
|
-
"decisionId",
|
|
161
|
-
"groupId",
|
|
162
|
-
"customerId",
|
|
163
|
-
"userId",
|
|
164
|
-
"accountId",
|
|
165
|
-
"tenantId",
|
|
166
|
-
"orgId",
|
|
167
|
-
"organizationId",
|
|
168
|
-
"traceId",
|
|
169
|
-
"spanId",
|
|
170
|
-
"parentSpanId"
|
|
171
|
-
];
|
|
172
|
-
var STRICT_PROFILE_EXTRA_KEYS = [
|
|
173
|
-
"prompt",
|
|
174
|
-
"completion",
|
|
175
|
-
"input",
|
|
176
|
-
"output",
|
|
177
|
-
"inputPreview",
|
|
178
|
-
"outputPreview",
|
|
179
|
-
"message",
|
|
180
|
-
"messages",
|
|
181
|
-
"transcript",
|
|
182
|
-
"context",
|
|
183
|
-
"document",
|
|
184
|
-
"documents",
|
|
185
|
-
"chunk",
|
|
186
|
-
"chunks",
|
|
187
|
-
"retrieval",
|
|
188
|
-
"query"
|
|
189
|
-
];
|
|
190
195
|
function resolveRedactionProfile(profile = "local") {
|
|
191
196
|
switch (profile) {
|
|
192
197
|
case "local":
|
|
@@ -213,15 +218,15 @@ function isPreviewKey(key) {
|
|
|
213
218
|
return key.toLowerCase().includes("preview");
|
|
214
219
|
}
|
|
215
220
|
function applyProfileMetadataCaps(maxMetadataValueLength, maxPreviewLength, resolved) {
|
|
216
|
-
let
|
|
221
|
+
let meta2 = maxMetadataValueLength;
|
|
217
222
|
let preview = maxPreviewLength;
|
|
218
223
|
if (resolved.maxMetadataValueLengthCap !== void 0) {
|
|
219
|
-
|
|
224
|
+
meta2 = Math.min(meta2, resolved.maxMetadataValueLengthCap);
|
|
220
225
|
}
|
|
221
226
|
if (resolved.maxPreviewLengthCap !== void 0) {
|
|
222
227
|
preview = Math.min(preview, resolved.maxPreviewLengthCap);
|
|
223
228
|
}
|
|
224
|
-
return { maxMetadataValueLength:
|
|
229
|
+
return { maxMetadataValueLength: meta2, maxPreviewLength: preview };
|
|
225
230
|
}
|
|
226
231
|
function truncateStringForProfile(value, key, maxMetadataValueLength, maxPreviewLength) {
|
|
227
232
|
const max = isPreviewKey(key) ? maxPreviewLength : maxMetadataValueLength;
|
|
@@ -229,17 +234,54 @@ function truncateStringForProfile(value, key, maxMetadataValueLength, maxPreview
|
|
|
229
234
|
if (value.length <= max) return value;
|
|
230
235
|
return `${value.slice(0, max)}\u2026`;
|
|
231
236
|
}
|
|
237
|
+
var SHARE_PROFILE_EXTRA_KEYS, STRICT_PROFILE_EXTRA_KEYS;
|
|
238
|
+
var init_redaction_profiles = __esm({
|
|
239
|
+
"packages/core/src/redaction-profiles.ts"() {
|
|
240
|
+
SHARE_PROFILE_EXTRA_KEYS = [
|
|
241
|
+
"userEmail",
|
|
242
|
+
"customerEmail",
|
|
243
|
+
"phone",
|
|
244
|
+
"phoneNumber",
|
|
245
|
+
"address",
|
|
246
|
+
"ip",
|
|
247
|
+
"ipAddress",
|
|
248
|
+
"sessionId",
|
|
249
|
+
"requestId",
|
|
250
|
+
"correlationId",
|
|
251
|
+
"decisionId",
|
|
252
|
+
"groupId",
|
|
253
|
+
"customerId",
|
|
254
|
+
"userId",
|
|
255
|
+
"accountId",
|
|
256
|
+
"tenantId",
|
|
257
|
+
"orgId",
|
|
258
|
+
"organizationId",
|
|
259
|
+
"traceId",
|
|
260
|
+
"spanId",
|
|
261
|
+
"parentSpanId"
|
|
262
|
+
];
|
|
263
|
+
STRICT_PROFILE_EXTRA_KEYS = [
|
|
264
|
+
"prompt",
|
|
265
|
+
"completion",
|
|
266
|
+
"input",
|
|
267
|
+
"output",
|
|
268
|
+
"inputPreview",
|
|
269
|
+
"outputPreview",
|
|
270
|
+
"message",
|
|
271
|
+
"messages",
|
|
272
|
+
"transcript",
|
|
273
|
+
"context",
|
|
274
|
+
"document",
|
|
275
|
+
"documents",
|
|
276
|
+
"chunk",
|
|
277
|
+
"chunks",
|
|
278
|
+
"retrieval",
|
|
279
|
+
"query"
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
232
283
|
|
|
233
284
|
// packages/core/src/types.ts
|
|
234
|
-
var STEP_TYPES = [
|
|
235
|
-
"run",
|
|
236
|
-
"llm",
|
|
237
|
-
"tool",
|
|
238
|
-
"decision",
|
|
239
|
-
"logic",
|
|
240
|
-
"state",
|
|
241
|
-
"custom"
|
|
242
|
-
];
|
|
243
285
|
function isRecord2(value) {
|
|
244
286
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
245
287
|
}
|
|
@@ -268,41 +310,22 @@ function isTraceEvent(value) {
|
|
|
268
310
|
return false;
|
|
269
311
|
}
|
|
270
312
|
}
|
|
313
|
+
var STEP_TYPES;
|
|
314
|
+
var init_types = __esm({
|
|
315
|
+
"packages/core/src/types.ts"() {
|
|
316
|
+
STEP_TYPES = [
|
|
317
|
+
"run",
|
|
318
|
+
"llm",
|
|
319
|
+
"tool",
|
|
320
|
+
"decision",
|
|
321
|
+
"logic",
|
|
322
|
+
"state",
|
|
323
|
+
"custom"
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
271
327
|
|
|
272
328
|
// packages/core/src/types/persisted-inspect-event.ts
|
|
273
|
-
var INSPECT_KINDS = [
|
|
274
|
-
"RUN",
|
|
275
|
-
"AGENT",
|
|
276
|
-
"LLM",
|
|
277
|
-
"TOOL",
|
|
278
|
-
"CHAIN",
|
|
279
|
-
"RETRIEVER",
|
|
280
|
-
"DECISION",
|
|
281
|
-
"RESULT",
|
|
282
|
-
"ERROR",
|
|
283
|
-
"LOGIC",
|
|
284
|
-
"LOG"
|
|
285
|
-
];
|
|
286
|
-
var ATTRIBUTION_CONFIDENCES = [
|
|
287
|
-
"explicit",
|
|
288
|
-
"correlated",
|
|
289
|
-
"heuristic",
|
|
290
|
-
"unknown"
|
|
291
|
-
];
|
|
292
|
-
var PERSISTED_EVENT_SOURCE_TYPES = [
|
|
293
|
-
"manual",
|
|
294
|
-
"json-log",
|
|
295
|
-
"log4js",
|
|
296
|
-
"adapter",
|
|
297
|
-
"ai-sdk",
|
|
298
|
-
"otel"
|
|
299
|
-
];
|
|
300
|
-
var PERSISTED_EVENT_STATUSES = [
|
|
301
|
-
"running",
|
|
302
|
-
"ok",
|
|
303
|
-
"error",
|
|
304
|
-
"unknown"
|
|
305
|
-
];
|
|
306
329
|
function isRecord3(value) {
|
|
307
330
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
308
331
|
}
|
|
@@ -399,6 +422,44 @@ function isPersistedInspectEvent(value) {
|
|
|
399
422
|
}
|
|
400
423
|
return true;
|
|
401
424
|
}
|
|
425
|
+
var INSPECT_KINDS, ATTRIBUTION_CONFIDENCES, PERSISTED_EVENT_SOURCE_TYPES, PERSISTED_EVENT_STATUSES;
|
|
426
|
+
var init_persisted_inspect_event = __esm({
|
|
427
|
+
"packages/core/src/types/persisted-inspect-event.ts"() {
|
|
428
|
+
INSPECT_KINDS = [
|
|
429
|
+
"RUN",
|
|
430
|
+
"AGENT",
|
|
431
|
+
"LLM",
|
|
432
|
+
"TOOL",
|
|
433
|
+
"CHAIN",
|
|
434
|
+
"RETRIEVER",
|
|
435
|
+
"DECISION",
|
|
436
|
+
"RESULT",
|
|
437
|
+
"ERROR",
|
|
438
|
+
"LOGIC",
|
|
439
|
+
"LOG"
|
|
440
|
+
];
|
|
441
|
+
ATTRIBUTION_CONFIDENCES = [
|
|
442
|
+
"explicit",
|
|
443
|
+
"correlated",
|
|
444
|
+
"heuristic",
|
|
445
|
+
"unknown"
|
|
446
|
+
];
|
|
447
|
+
PERSISTED_EVENT_SOURCE_TYPES = [
|
|
448
|
+
"manual",
|
|
449
|
+
"json-log",
|
|
450
|
+
"log4js",
|
|
451
|
+
"adapter",
|
|
452
|
+
"ai-sdk",
|
|
453
|
+
"otel"
|
|
454
|
+
];
|
|
455
|
+
PERSISTED_EVENT_STATUSES = [
|
|
456
|
+
"running",
|
|
457
|
+
"ok",
|
|
458
|
+
"error",
|
|
459
|
+
"unknown"
|
|
460
|
+
];
|
|
461
|
+
}
|
|
462
|
+
});
|
|
402
463
|
|
|
403
464
|
// packages/core/src/persisted/to-trace-event.ts
|
|
404
465
|
function parseIsoToMs(iso) {
|
|
@@ -674,14 +735,19 @@ function persistedInspectEventsToTraceEvents(events, options) {
|
|
|
674
735
|
});
|
|
675
736
|
return out;
|
|
676
737
|
}
|
|
738
|
+
var init_to_trace_event = __esm({
|
|
739
|
+
"packages/core/src/persisted/to-trace-event.ts"() {
|
|
740
|
+
init_persisted_inspect_event();
|
|
741
|
+
}
|
|
742
|
+
});
|
|
677
743
|
|
|
678
744
|
// node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/url-alphabet/index.js
|
|
679
|
-
var urlAlphabet
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
745
|
+
var urlAlphabet;
|
|
746
|
+
var init_url_alphabet = __esm({
|
|
747
|
+
"node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/url-alphabet/index.js"() {
|
|
748
|
+
urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
749
|
+
}
|
|
750
|
+
});
|
|
685
751
|
function fillPool(bytes) {
|
|
686
752
|
if (bytes < 0 || bytes > 1024) throw new RangeError("Wrong ID size");
|
|
687
753
|
if (!pool || pool.length < bytes) {
|
|
@@ -702,6 +768,13 @@ function nanoid(size = 21) {
|
|
|
702
768
|
}
|
|
703
769
|
return id;
|
|
704
770
|
}
|
|
771
|
+
var POOL_SIZE_MULTIPLIER, pool, poolOffset;
|
|
772
|
+
var init_nanoid = __esm({
|
|
773
|
+
"node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/index.js"() {
|
|
774
|
+
init_url_alphabet();
|
|
775
|
+
POOL_SIZE_MULTIPLIER = 128;
|
|
776
|
+
}
|
|
777
|
+
});
|
|
705
778
|
|
|
706
779
|
// packages/core/src/utils/duration.ts
|
|
707
780
|
function parseDuration(duration) {
|
|
@@ -753,16 +826,10 @@ function formatDuration(ms) {
|
|
|
753
826
|
}
|
|
754
827
|
return `${(ms / 36e5).toFixed(1)}h`;
|
|
755
828
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
var FALLBACK_TRACE_DIR = path14__default.default.join(
|
|
761
|
-
os__default.default.tmpdir(),
|
|
762
|
-
"agent-inspect",
|
|
763
|
-
RUNS_DIR_NAME
|
|
764
|
-
);
|
|
765
|
-
var MAX_NAME_LENGTH = 100;
|
|
829
|
+
var init_duration = __esm({
|
|
830
|
+
"packages/core/src/utils/duration.ts"() {
|
|
831
|
+
}
|
|
832
|
+
});
|
|
766
833
|
function formatDuration2(ms) {
|
|
767
834
|
return formatDuration(ms);
|
|
768
835
|
}
|
|
@@ -855,6 +922,20 @@ function warn(message, error) {
|
|
|
855
922
|
}
|
|
856
923
|
console.warn(`${base}: ${formatError(error).message}`);
|
|
857
924
|
}
|
|
925
|
+
var DEFAULT_TRACE_DIR_NAME, RUNS_DIR_NAME, FALLBACK_TRACE_DIR, MAX_NAME_LENGTH;
|
|
926
|
+
var init_utils = __esm({
|
|
927
|
+
"packages/core/src/utils.ts"() {
|
|
928
|
+
init_duration();
|
|
929
|
+
DEFAULT_TRACE_DIR_NAME = ".agent-inspect";
|
|
930
|
+
RUNS_DIR_NAME = "runs";
|
|
931
|
+
FALLBACK_TRACE_DIR = path14__default.default.join(
|
|
932
|
+
os__default.default.tmpdir(),
|
|
933
|
+
"agent-inspect",
|
|
934
|
+
RUNS_DIR_NAME
|
|
935
|
+
);
|
|
936
|
+
MAX_NAME_LENGTH = 100;
|
|
937
|
+
}
|
|
938
|
+
});
|
|
858
939
|
|
|
859
940
|
// packages/core/src/read-trace.ts
|
|
860
941
|
function isRecord4(value) {
|
|
@@ -931,8 +1012,14 @@ function parseTraceJsonl(raw, options = {}) {
|
|
|
931
1012
|
else if (saw10) format = "1.0";
|
|
932
1013
|
return { format, sourceEventCount, events: traceEvents, persisted, rows };
|
|
933
1014
|
}
|
|
934
|
-
|
|
935
|
-
|
|
1015
|
+
var init_read_trace = __esm({
|
|
1016
|
+
"packages/core/src/read-trace.ts"() {
|
|
1017
|
+
init_to_trace_event();
|
|
1018
|
+
init_persisted_inspect_event();
|
|
1019
|
+
init_types();
|
|
1020
|
+
init_utils();
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
936
1023
|
function isRecord5(value) {
|
|
937
1024
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
938
1025
|
}
|
|
@@ -1000,79 +1087,48 @@ async function readTraceEventsFromFile(filePath) {
|
|
|
1000
1087
|
return [];
|
|
1001
1088
|
}
|
|
1002
1089
|
}
|
|
1090
|
+
var init_storage = __esm({
|
|
1091
|
+
"packages/core/src/storage.ts"() {
|
|
1092
|
+
init_types();
|
|
1093
|
+
init_trace_event_safety();
|
|
1094
|
+
init_read_trace();
|
|
1095
|
+
init_utils();
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1003
1098
|
|
|
1004
|
-
// packages/core/src/
|
|
1005
|
-
|
|
1099
|
+
// packages/core/src/trace-event-safety.ts
|
|
1100
|
+
var init_trace_event_safety = __esm({
|
|
1101
|
+
"packages/core/src/trace-event-safety.ts"() {
|
|
1102
|
+
init_redactor();
|
|
1103
|
+
init_redaction_profiles();
|
|
1104
|
+
init_storage();
|
|
1105
|
+
init_persisted_inspect_event();
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
var init_context = __esm({
|
|
1109
|
+
"packages/core/src/context.ts"() {
|
|
1110
|
+
init_correlation_metadata();
|
|
1111
|
+
init_trace_event_safety();
|
|
1112
|
+
new async_hooks.AsyncLocalStorage();
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
var init_inspector_runtime = __esm({
|
|
1116
|
+
"packages/core/src/inspector-runtime.ts"() {
|
|
1117
|
+
init_correlation_metadata();
|
|
1118
|
+
init_trace_event_safety();
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1006
1121
|
|
|
1007
|
-
//
|
|
1008
|
-
var
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
modifier: {
|
|
1014
|
-
reset: [0, 0],
|
|
1015
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
1016
|
-
bold: [1, 22],
|
|
1017
|
-
dim: [2, 22],
|
|
1018
|
-
italic: [3, 23],
|
|
1019
|
-
underline: [4, 24],
|
|
1020
|
-
overline: [53, 55],
|
|
1021
|
-
inverse: [7, 27],
|
|
1022
|
-
hidden: [8, 28],
|
|
1023
|
-
strikethrough: [9, 29]
|
|
1024
|
-
},
|
|
1025
|
-
color: {
|
|
1026
|
-
black: [30, 39],
|
|
1027
|
-
red: [31, 39],
|
|
1028
|
-
green: [32, 39],
|
|
1029
|
-
yellow: [33, 39],
|
|
1030
|
-
blue: [34, 39],
|
|
1031
|
-
magenta: [35, 39],
|
|
1032
|
-
cyan: [36, 39],
|
|
1033
|
-
white: [37, 39],
|
|
1034
|
-
// Bright color
|
|
1035
|
-
blackBright: [90, 39],
|
|
1036
|
-
gray: [90, 39],
|
|
1037
|
-
// Alias of `blackBright`
|
|
1038
|
-
grey: [90, 39],
|
|
1039
|
-
// Alias of `blackBright`
|
|
1040
|
-
redBright: [91, 39],
|
|
1041
|
-
greenBright: [92, 39],
|
|
1042
|
-
yellowBright: [93, 39],
|
|
1043
|
-
blueBright: [94, 39],
|
|
1044
|
-
magentaBright: [95, 39],
|
|
1045
|
-
cyanBright: [96, 39],
|
|
1046
|
-
whiteBright: [97, 39]
|
|
1047
|
-
},
|
|
1048
|
-
bgColor: {
|
|
1049
|
-
bgBlack: [40, 49],
|
|
1050
|
-
bgRed: [41, 49],
|
|
1051
|
-
bgGreen: [42, 49],
|
|
1052
|
-
bgYellow: [43, 49],
|
|
1053
|
-
bgBlue: [44, 49],
|
|
1054
|
-
bgMagenta: [45, 49],
|
|
1055
|
-
bgCyan: [46, 49],
|
|
1056
|
-
bgWhite: [47, 49],
|
|
1057
|
-
// Bright color
|
|
1058
|
-
bgBlackBright: [100, 49],
|
|
1059
|
-
bgGray: [100, 49],
|
|
1060
|
-
// Alias of `bgBlackBright`
|
|
1061
|
-
bgGrey: [100, 49],
|
|
1062
|
-
// Alias of `bgBlackBright`
|
|
1063
|
-
bgRedBright: [101, 49],
|
|
1064
|
-
bgGreenBright: [102, 49],
|
|
1065
|
-
bgYellowBright: [103, 49],
|
|
1066
|
-
bgBlueBright: [104, 49],
|
|
1067
|
-
bgMagentaBright: [105, 49],
|
|
1068
|
-
bgCyanBright: [106, 49],
|
|
1069
|
-
bgWhiteBright: [107, 49]
|
|
1122
|
+
// packages/core/src/inspector.ts
|
|
1123
|
+
var init_inspector = __esm({
|
|
1124
|
+
"packages/core/src/inspector.ts"() {
|
|
1125
|
+
init_inspector_runtime();
|
|
1126
|
+
init_trace_event_safety();
|
|
1127
|
+
init_utils();
|
|
1070
1128
|
}
|
|
1071
|
-
};
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
1075
|
-
[...foregroundColorNames, ...backgroundColorNames];
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
1076
1132
|
function assembleStyles() {
|
|
1077
1133
|
const codes = /* @__PURE__ */ new Map();
|
|
1078
1134
|
for (const [groupName, group] of Object.entries(styles)) {
|
|
@@ -1187,21 +1243,87 @@ function assembleStyles() {
|
|
|
1187
1243
|
});
|
|
1188
1244
|
return styles;
|
|
1189
1245
|
}
|
|
1190
|
-
var ansiStyles
|
|
1191
|
-
var
|
|
1246
|
+
var ANSI_BACKGROUND_OFFSET, wrapAnsi16, wrapAnsi256, wrapAnsi16m, styles, foregroundColorNames, backgroundColorNames, ansiStyles, ansi_styles_default;
|
|
1247
|
+
var init_ansi_styles = __esm({
|
|
1248
|
+
"node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js"() {
|
|
1249
|
+
ANSI_BACKGROUND_OFFSET = 10;
|
|
1250
|
+
wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
1251
|
+
wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
1252
|
+
wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
1253
|
+
styles = {
|
|
1254
|
+
modifier: {
|
|
1255
|
+
reset: [0, 0],
|
|
1256
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
1257
|
+
bold: [1, 22],
|
|
1258
|
+
dim: [2, 22],
|
|
1259
|
+
italic: [3, 23],
|
|
1260
|
+
underline: [4, 24],
|
|
1261
|
+
overline: [53, 55],
|
|
1262
|
+
inverse: [7, 27],
|
|
1263
|
+
hidden: [8, 28],
|
|
1264
|
+
strikethrough: [9, 29]
|
|
1265
|
+
},
|
|
1266
|
+
color: {
|
|
1267
|
+
black: [30, 39],
|
|
1268
|
+
red: [31, 39],
|
|
1269
|
+
green: [32, 39],
|
|
1270
|
+
yellow: [33, 39],
|
|
1271
|
+
blue: [34, 39],
|
|
1272
|
+
magenta: [35, 39],
|
|
1273
|
+
cyan: [36, 39],
|
|
1274
|
+
white: [37, 39],
|
|
1275
|
+
// Bright color
|
|
1276
|
+
blackBright: [90, 39],
|
|
1277
|
+
gray: [90, 39],
|
|
1278
|
+
// Alias of `blackBright`
|
|
1279
|
+
grey: [90, 39],
|
|
1280
|
+
// Alias of `blackBright`
|
|
1281
|
+
redBright: [91, 39],
|
|
1282
|
+
greenBright: [92, 39],
|
|
1283
|
+
yellowBright: [93, 39],
|
|
1284
|
+
blueBright: [94, 39],
|
|
1285
|
+
magentaBright: [95, 39],
|
|
1286
|
+
cyanBright: [96, 39],
|
|
1287
|
+
whiteBright: [97, 39]
|
|
1288
|
+
},
|
|
1289
|
+
bgColor: {
|
|
1290
|
+
bgBlack: [40, 49],
|
|
1291
|
+
bgRed: [41, 49],
|
|
1292
|
+
bgGreen: [42, 49],
|
|
1293
|
+
bgYellow: [43, 49],
|
|
1294
|
+
bgBlue: [44, 49],
|
|
1295
|
+
bgMagenta: [45, 49],
|
|
1296
|
+
bgCyan: [46, 49],
|
|
1297
|
+
bgWhite: [47, 49],
|
|
1298
|
+
// Bright color
|
|
1299
|
+
bgBlackBright: [100, 49],
|
|
1300
|
+
bgGray: [100, 49],
|
|
1301
|
+
// Alias of `bgBlackBright`
|
|
1302
|
+
bgGrey: [100, 49],
|
|
1303
|
+
// Alias of `bgBlackBright`
|
|
1304
|
+
bgRedBright: [101, 49],
|
|
1305
|
+
bgGreenBright: [102, 49],
|
|
1306
|
+
bgYellowBright: [103, 49],
|
|
1307
|
+
bgBlueBright: [104, 49],
|
|
1308
|
+
bgMagentaBright: [105, 49],
|
|
1309
|
+
bgCyanBright: [106, 49],
|
|
1310
|
+
bgWhiteBright: [107, 49]
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
Object.keys(styles.modifier);
|
|
1314
|
+
foregroundColorNames = Object.keys(styles.color);
|
|
1315
|
+
backgroundColorNames = Object.keys(styles.bgColor);
|
|
1316
|
+
[...foregroundColorNames, ...backgroundColorNames];
|
|
1317
|
+
ansiStyles = assembleStyles();
|
|
1318
|
+
ansi_styles_default = ansiStyles;
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1192
1321
|
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process3__default.default.argv) {
|
|
1193
1322
|
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
1194
1323
|
const position = argv.indexOf(prefix + flag);
|
|
1195
1324
|
const terminatorPosition = argv.indexOf("--");
|
|
1196
1325
|
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1197
1326
|
}
|
|
1198
|
-
var { env } = process3__default.default;
|
|
1199
|
-
var flagForceColor;
|
|
1200
|
-
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
1201
|
-
flagForceColor = 0;
|
|
1202
|
-
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
1203
|
-
flagForceColor = 1;
|
|
1204
|
-
}
|
|
1205
1327
|
function envForceColor() {
|
|
1206
1328
|
if ("FORCE_COLOR" in env) {
|
|
1207
1329
|
if (env.FORCE_COLOR === "true") {
|
|
@@ -1311,11 +1433,22 @@ function createSupportsColor(stream, options = {}) {
|
|
|
1311
1433
|
});
|
|
1312
1434
|
return translateLevel(level);
|
|
1313
1435
|
}
|
|
1314
|
-
var supportsColor
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1436
|
+
var env, flagForceColor, supportsColor, supports_color_default;
|
|
1437
|
+
var init_supports_color = __esm({
|
|
1438
|
+
"node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js"() {
|
|
1439
|
+
({ env } = process3__default.default);
|
|
1440
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
1441
|
+
flagForceColor = 0;
|
|
1442
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
1443
|
+
flagForceColor = 1;
|
|
1444
|
+
}
|
|
1445
|
+
supportsColor = {
|
|
1446
|
+
stdout: createSupportsColor({ isTTY: tty__default.default.isatty(1) }),
|
|
1447
|
+
stderr: createSupportsColor({ isTTY: tty__default.default.isatty(2) })
|
|
1448
|
+
};
|
|
1449
|
+
supports_color_default = supportsColor;
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1319
1452
|
|
|
1320
1453
|
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
|
|
1321
1454
|
function stringReplaceAll(string, substring, replacer) {
|
|
@@ -1346,158 +1479,167 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
|
1346
1479
|
returnValue += string.slice(endIndex);
|
|
1347
1480
|
return returnValue;
|
|
1348
1481
|
}
|
|
1482
|
+
var init_utilities = __esm({
|
|
1483
|
+
"node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js"() {
|
|
1484
|
+
}
|
|
1485
|
+
});
|
|
1349
1486
|
|
|
1350
1487
|
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
1351
|
-
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
1352
|
-
var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
|
|
1353
|
-
var STYLER = /* @__PURE__ */ Symbol("STYLER");
|
|
1354
|
-
var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
|
|
1355
|
-
var levelMapping = [
|
|
1356
|
-
"ansi",
|
|
1357
|
-
"ansi",
|
|
1358
|
-
"ansi256",
|
|
1359
|
-
"ansi16m"
|
|
1360
|
-
];
|
|
1361
|
-
var styles2 = /* @__PURE__ */ Object.create(null);
|
|
1362
|
-
var applyOptions = (object, options = {}) => {
|
|
1363
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1364
|
-
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
1365
|
-
}
|
|
1366
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1367
|
-
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
1368
|
-
};
|
|
1369
|
-
var chalkFactory = (options) => {
|
|
1370
|
-
const chalk2 = (...strings) => strings.join(" ");
|
|
1371
|
-
applyOptions(chalk2, options);
|
|
1372
|
-
Object.setPrototypeOf(chalk2, createChalk.prototype);
|
|
1373
|
-
return chalk2;
|
|
1374
|
-
};
|
|
1375
1488
|
function createChalk(options) {
|
|
1376
1489
|
return chalkFactory(options);
|
|
1377
1490
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
1417
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
1491
|
+
var stdoutColor, stderrColor, GENERATOR, STYLER, IS_EMPTY, levelMapping, styles2, applyOptions, chalkFactory, getModelAnsi, usedModels, proto, createStyler, createBuilder, applyStyle, chalk, source_default;
|
|
1492
|
+
var init_source = __esm({
|
|
1493
|
+
"node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js"() {
|
|
1494
|
+
init_ansi_styles();
|
|
1495
|
+
init_supports_color();
|
|
1496
|
+
init_utilities();
|
|
1497
|
+
({ stdout: stdoutColor, stderr: stderrColor } = supports_color_default);
|
|
1498
|
+
GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
|
|
1499
|
+
STYLER = /* @__PURE__ */ Symbol("STYLER");
|
|
1500
|
+
IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
|
|
1501
|
+
levelMapping = [
|
|
1502
|
+
"ansi",
|
|
1503
|
+
"ansi",
|
|
1504
|
+
"ansi256",
|
|
1505
|
+
"ansi16m"
|
|
1506
|
+
];
|
|
1507
|
+
styles2 = /* @__PURE__ */ Object.create(null);
|
|
1508
|
+
applyOptions = (object, options = {}) => {
|
|
1509
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1510
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
1511
|
+
}
|
|
1512
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1513
|
+
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
1514
|
+
};
|
|
1515
|
+
chalkFactory = (options) => {
|
|
1516
|
+
const chalk2 = (...strings) => strings.join(" ");
|
|
1517
|
+
applyOptions(chalk2, options);
|
|
1518
|
+
Object.setPrototypeOf(chalk2, createChalk.prototype);
|
|
1519
|
+
return chalk2;
|
|
1520
|
+
};
|
|
1521
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
1522
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
1523
|
+
styles2[styleName] = {
|
|
1524
|
+
get() {
|
|
1525
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
1526
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
1527
|
+
return builder;
|
|
1528
|
+
}
|
|
1418
1529
|
};
|
|
1419
1530
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1531
|
+
styles2.visible = {
|
|
1532
|
+
get() {
|
|
1533
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
1534
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
1535
|
+
return builder;
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
getModelAnsi = (model, level, type, ...arguments_) => {
|
|
1539
|
+
if (model === "rgb") {
|
|
1540
|
+
if (level === "ansi16m") {
|
|
1541
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
1542
|
+
}
|
|
1543
|
+
if (level === "ansi256") {
|
|
1544
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
1545
|
+
}
|
|
1546
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
1547
|
+
}
|
|
1548
|
+
if (model === "hex") {
|
|
1549
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
1550
|
+
}
|
|
1551
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
1552
|
+
};
|
|
1553
|
+
usedModels = ["rgb", "hex", "ansi256"];
|
|
1554
|
+
for (const model of usedModels) {
|
|
1555
|
+
styles2[model] = {
|
|
1556
|
+
get() {
|
|
1557
|
+
const { level } = this;
|
|
1558
|
+
return function(...arguments_) {
|
|
1559
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
1560
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
1565
|
+
styles2[bgModel] = {
|
|
1566
|
+
get() {
|
|
1567
|
+
const { level } = this;
|
|
1568
|
+
return function(...arguments_) {
|
|
1569
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
1570
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1428
1573
|
};
|
|
1429
1574
|
}
|
|
1430
|
-
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
}
|
|
1575
|
+
proto = Object.defineProperties(() => {
|
|
1576
|
+
}, {
|
|
1577
|
+
...styles2,
|
|
1578
|
+
level: {
|
|
1579
|
+
enumerable: true,
|
|
1580
|
+
get() {
|
|
1581
|
+
return this[GENERATOR].level;
|
|
1582
|
+
},
|
|
1583
|
+
set(level) {
|
|
1584
|
+
this[GENERATOR].level = level;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
createStyler = (open3, close, parent) => {
|
|
1589
|
+
let openAll;
|
|
1590
|
+
let closeAll;
|
|
1591
|
+
if (parent === void 0) {
|
|
1592
|
+
openAll = open3;
|
|
1593
|
+
closeAll = close;
|
|
1594
|
+
} else {
|
|
1595
|
+
openAll = parent.openAll + open3;
|
|
1596
|
+
closeAll = close + parent.closeAll;
|
|
1597
|
+
}
|
|
1598
|
+
return {
|
|
1599
|
+
open: open3,
|
|
1600
|
+
close,
|
|
1601
|
+
openAll,
|
|
1602
|
+
closeAll,
|
|
1603
|
+
parent
|
|
1604
|
+
};
|
|
1605
|
+
};
|
|
1606
|
+
createBuilder = (self, _styler, _isEmpty) => {
|
|
1607
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
1608
|
+
Object.setPrototypeOf(builder, proto);
|
|
1609
|
+
builder[GENERATOR] = self;
|
|
1610
|
+
builder[STYLER] = _styler;
|
|
1611
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
1612
|
+
return builder;
|
|
1613
|
+
};
|
|
1614
|
+
applyStyle = (self, string) => {
|
|
1615
|
+
if (self.level <= 0 || !string) {
|
|
1616
|
+
return self[IS_EMPTY] ? "" : string;
|
|
1617
|
+
}
|
|
1618
|
+
let styler = self[STYLER];
|
|
1619
|
+
if (styler === void 0) {
|
|
1620
|
+
return string;
|
|
1621
|
+
}
|
|
1622
|
+
const { openAll, closeAll } = styler;
|
|
1623
|
+
if (string.includes("\x1B")) {
|
|
1624
|
+
while (styler !== void 0) {
|
|
1625
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
1626
|
+
styler = styler.parent;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
const lfIndex = string.indexOf("\n");
|
|
1630
|
+
if (lfIndex !== -1) {
|
|
1631
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
1632
|
+
}
|
|
1633
|
+
return openAll + string + closeAll;
|
|
1634
|
+
};
|
|
1635
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
1636
|
+
chalk = createChalk();
|
|
1637
|
+
createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
1638
|
+
source_default = chalk;
|
|
1443
1639
|
}
|
|
1444
1640
|
});
|
|
1445
|
-
var createStyler = (open3, close, parent) => {
|
|
1446
|
-
let openAll;
|
|
1447
|
-
let closeAll;
|
|
1448
|
-
if (parent === void 0) {
|
|
1449
|
-
openAll = open3;
|
|
1450
|
-
closeAll = close;
|
|
1451
|
-
} else {
|
|
1452
|
-
openAll = parent.openAll + open3;
|
|
1453
|
-
closeAll = close + parent.closeAll;
|
|
1454
|
-
}
|
|
1455
|
-
return {
|
|
1456
|
-
open: open3,
|
|
1457
|
-
close,
|
|
1458
|
-
openAll,
|
|
1459
|
-
closeAll,
|
|
1460
|
-
parent
|
|
1461
|
-
};
|
|
1462
|
-
};
|
|
1463
|
-
var createBuilder = (self, _styler, _isEmpty) => {
|
|
1464
|
-
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
1465
|
-
Object.setPrototypeOf(builder, proto);
|
|
1466
|
-
builder[GENERATOR] = self;
|
|
1467
|
-
builder[STYLER] = _styler;
|
|
1468
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
1469
|
-
return builder;
|
|
1470
|
-
};
|
|
1471
|
-
var applyStyle = (self, string) => {
|
|
1472
|
-
if (self.level <= 0 || !string) {
|
|
1473
|
-
return self[IS_EMPTY] ? "" : string;
|
|
1474
|
-
}
|
|
1475
|
-
let styler = self[STYLER];
|
|
1476
|
-
if (styler === void 0) {
|
|
1477
|
-
return string;
|
|
1478
|
-
}
|
|
1479
|
-
const { openAll, closeAll } = styler;
|
|
1480
|
-
if (string.includes("\x1B")) {
|
|
1481
|
-
while (styler !== void 0) {
|
|
1482
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
1483
|
-
styler = styler.parent;
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
const lfIndex = string.indexOf("\n");
|
|
1487
|
-
if (lfIndex !== -1) {
|
|
1488
|
-
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
1489
|
-
}
|
|
1490
|
-
return openAll + string + closeAll;
|
|
1491
|
-
};
|
|
1492
|
-
Object.defineProperties(createChalk.prototype, styles2);
|
|
1493
|
-
var chalk = createChalk();
|
|
1494
|
-
createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
1495
|
-
var source_default = chalk;
|
|
1496
1641
|
|
|
1497
1642
|
// packages/core/src/terminal.ts
|
|
1498
|
-
var TERMINAL_INDENT = " ";
|
|
1499
|
-
var MAX_TERMINAL_NAME_LENGTH = 80;
|
|
1500
|
-
var MAX_TERMINAL_DEPTH = 10;
|
|
1501
1643
|
function normalizeDepth(depth) {
|
|
1502
1644
|
if (!Number.isFinite(depth) || depth < 0) {
|
|
1503
1645
|
return 0;
|
|
@@ -1550,6 +1692,17 @@ function renderErrorLine(error, depth) {
|
|
|
1550
1692
|
return "";
|
|
1551
1693
|
}
|
|
1552
1694
|
}
|
|
1695
|
+
var TERMINAL_INDENT, MAX_TERMINAL_NAME_LENGTH, MAX_TERMINAL_DEPTH;
|
|
1696
|
+
var init_terminal = __esm({
|
|
1697
|
+
"packages/core/src/terminal.ts"() {
|
|
1698
|
+
init_source();
|
|
1699
|
+
init_context();
|
|
1700
|
+
init_utils();
|
|
1701
|
+
TERMINAL_INDENT = " ";
|
|
1702
|
+
MAX_TERMINAL_NAME_LENGTH = 80;
|
|
1703
|
+
MAX_TERMINAL_DEPTH = 10;
|
|
1704
|
+
}
|
|
1705
|
+
});
|
|
1553
1706
|
function resolveTraceDir(options = {}) {
|
|
1554
1707
|
if (typeof options.dir === "string" && options.dir.trim() !== "") {
|
|
1555
1708
|
return options.dir.trim();
|
|
@@ -1560,32 +1713,38 @@ function resolveTraceDir(options = {}) {
|
|
|
1560
1713
|
}
|
|
1561
1714
|
return getDefaultTraceDir();
|
|
1562
1715
|
}
|
|
1563
|
-
var TraceDirectory
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
async list() {
|
|
1572
|
-
try {
|
|
1573
|
-
const files = await promises.readdir(this.#dir);
|
|
1574
|
-
return files.filter((f) => f.endsWith(".jsonl"));
|
|
1575
|
-
} catch (e) {
|
|
1576
|
-
if (e && typeof e === "object" && "code" in e && e.code === "ENOENT") {
|
|
1577
|
-
return [];
|
|
1716
|
+
var TraceDirectory;
|
|
1717
|
+
var init_trace_directory = __esm({
|
|
1718
|
+
"packages/core/src/trace-directory.ts"() {
|
|
1719
|
+
init_utils();
|
|
1720
|
+
TraceDirectory = class {
|
|
1721
|
+
#dir;
|
|
1722
|
+
constructor(options = {}) {
|
|
1723
|
+
this.#dir = resolveTraceDir(options);
|
|
1578
1724
|
}
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1725
|
+
getPath(filename) {
|
|
1726
|
+
return filename ? path14__default.default.join(this.#dir, filename) : this.#dir;
|
|
1727
|
+
}
|
|
1728
|
+
async list() {
|
|
1729
|
+
try {
|
|
1730
|
+
const files = await promises.readdir(this.#dir);
|
|
1731
|
+
return files.filter((f) => f.endsWith(".jsonl"));
|
|
1732
|
+
} catch (e) {
|
|
1733
|
+
if (e && typeof e === "object" && "code" in e && e.code === "ENOENT") {
|
|
1734
|
+
return [];
|
|
1735
|
+
}
|
|
1736
|
+
throw e;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
async getFileStats(filename) {
|
|
1740
|
+
return await promises.stat(this.getPath(filename));
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
function isFiniteNumber(v) {
|
|
1746
|
+
return typeof v === "number" && Number.isFinite(v);
|
|
1747
|
+
}
|
|
1589
1748
|
function parseIsoToMs2(value) {
|
|
1590
1749
|
if (value === void 0) return void 0;
|
|
1591
1750
|
const parsed = Date.parse(value);
|
|
@@ -1816,6 +1975,11 @@ function buildRunSummary(events) {
|
|
|
1816
1975
|
};
|
|
1817
1976
|
return summary;
|
|
1818
1977
|
}
|
|
1978
|
+
var init_trace_metadata = __esm({
|
|
1979
|
+
"packages/core/src/trace-metadata.ts"() {
|
|
1980
|
+
init_read_trace();
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1819
1983
|
|
|
1820
1984
|
// packages/core/src/trace-filter.ts
|
|
1821
1985
|
function toLower(s) {
|
|
@@ -1850,6 +2014,11 @@ function filterTraces(traces, options) {
|
|
|
1850
2014
|
}
|
|
1851
2015
|
return out;
|
|
1852
2016
|
}
|
|
2017
|
+
var init_trace_filter = __esm({
|
|
2018
|
+
"packages/core/src/trace-filter.ts"() {
|
|
2019
|
+
init_duration();
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
1853
2022
|
|
|
1854
2023
|
// packages/core/src/timeline.ts
|
|
1855
2024
|
function finite(n) {
|
|
@@ -2019,6 +2188,11 @@ function renderTimeline(timeline, options = {}) {
|
|
|
2019
2188
|
}
|
|
2020
2189
|
return lines.join("\n");
|
|
2021
2190
|
}
|
|
2191
|
+
var init_timeline = __esm({
|
|
2192
|
+
"packages/core/src/timeline.ts"() {
|
|
2193
|
+
init_utils();
|
|
2194
|
+
}
|
|
2195
|
+
});
|
|
2022
2196
|
|
|
2023
2197
|
// packages/core/src/what.ts
|
|
2024
2198
|
function pickCorrelation2(metadata) {
|
|
@@ -2158,6 +2332,12 @@ function renderRunWhat(summary, options = {}) {
|
|
|
2158
2332
|
}
|
|
2159
2333
|
return lines.join("\n");
|
|
2160
2334
|
}
|
|
2335
|
+
var init_what = __esm({
|
|
2336
|
+
"packages/core/src/what.ts"() {
|
|
2337
|
+
init_trace_metadata();
|
|
2338
|
+
init_utils();
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2161
2341
|
|
|
2162
2342
|
// packages/core/src/explain.ts
|
|
2163
2343
|
function flatten(nodes, out = []) {
|
|
@@ -2303,6 +2483,12 @@ function buildLocalExplanation(run, options = {}) {
|
|
|
2303
2483
|
]
|
|
2304
2484
|
};
|
|
2305
2485
|
}
|
|
2486
|
+
var init_explain = __esm({
|
|
2487
|
+
"packages/core/src/explain.ts"() {
|
|
2488
|
+
init_redactor();
|
|
2489
|
+
init_redaction_profiles();
|
|
2490
|
+
}
|
|
2491
|
+
});
|
|
2306
2492
|
|
|
2307
2493
|
// packages/core/src/stats.ts
|
|
2308
2494
|
function percentile(sorted, p) {
|
|
@@ -2442,11 +2628,11 @@ function collectCompletedSteps(events, runId) {
|
|
|
2442
2628
|
if (typeof c.durationMs !== "number" || !Number.isFinite(c.durationMs)) {
|
|
2443
2629
|
continue;
|
|
2444
2630
|
}
|
|
2445
|
-
const
|
|
2631
|
+
const meta2 = started.get(c.stepId);
|
|
2446
2632
|
out.push({
|
|
2447
2633
|
runId,
|
|
2448
|
-
stepName:
|
|
2449
|
-
stepType:
|
|
2634
|
+
stepName: meta2?.name ?? c.stepId,
|
|
2635
|
+
stepType: meta2?.type ?? "logic",
|
|
2450
2636
|
durationMs: c.durationMs
|
|
2451
2637
|
});
|
|
2452
2638
|
}
|
|
@@ -2496,6 +2682,14 @@ function renderTraceStats(stats) {
|
|
|
2496
2682
|
}
|
|
2497
2683
|
return lines.join("\n");
|
|
2498
2684
|
}
|
|
2685
|
+
var init_stats = __esm({
|
|
2686
|
+
"packages/core/src/stats.ts"() {
|
|
2687
|
+
init_trace_metadata();
|
|
2688
|
+
init_trace_filter();
|
|
2689
|
+
init_storage();
|
|
2690
|
+
init_utils();
|
|
2691
|
+
}
|
|
2692
|
+
});
|
|
2499
2693
|
|
|
2500
2694
|
// packages/core/src/search.ts
|
|
2501
2695
|
function parseDurationFilter(expr) {
|
|
@@ -2691,13 +2885,21 @@ async function loadTraceMetadataList(_traceDir, fileNames, getPath) {
|
|
|
2691
2885
|
for (const fileName of fileNames) {
|
|
2692
2886
|
try {
|
|
2693
2887
|
const filePath = getPath(fileName);
|
|
2694
|
-
const
|
|
2695
|
-
metas.push(
|
|
2888
|
+
const meta2 = await extractMetadata(filePath);
|
|
2889
|
+
metas.push(meta2);
|
|
2696
2890
|
} catch {
|
|
2697
2891
|
}
|
|
2698
2892
|
}
|
|
2699
2893
|
return metas;
|
|
2700
2894
|
}
|
|
2895
|
+
var init_search = __esm({
|
|
2896
|
+
"packages/core/src/search.ts"() {
|
|
2897
|
+
init_trace_metadata();
|
|
2898
|
+
init_trace_filter();
|
|
2899
|
+
init_storage();
|
|
2900
|
+
init_duration();
|
|
2901
|
+
}
|
|
2902
|
+
});
|
|
2701
2903
|
|
|
2702
2904
|
// packages/core/src/sessions/metadata.ts
|
|
2703
2905
|
function isNonEmptyString3(value) {
|
|
@@ -2746,19 +2948,29 @@ function extractSessionWorkflowMetadata(record) {
|
|
|
2746
2948
|
}
|
|
2747
2949
|
return found ? out : void 0;
|
|
2748
2950
|
}
|
|
2749
|
-
function sessionKeyForRun(
|
|
2750
|
-
if (
|
|
2751
|
-
if (options?.correlateByGroupId &&
|
|
2752
|
-
return `group:${
|
|
2951
|
+
function sessionKeyForRun(meta2, options) {
|
|
2952
|
+
if (meta2?.sessionId) return meta2.sessionId;
|
|
2953
|
+
if (options?.correlateByGroupId && meta2?.groupId) {
|
|
2954
|
+
return `group:${meta2.groupId}`;
|
|
2753
2955
|
}
|
|
2754
2956
|
return void 0;
|
|
2755
2957
|
}
|
|
2958
|
+
var init_metadata = __esm({
|
|
2959
|
+
"packages/core/src/sessions/metadata.ts"() {
|
|
2960
|
+
}
|
|
2961
|
+
});
|
|
2962
|
+
|
|
2963
|
+
// packages/core/src/sessions/types.ts
|
|
2964
|
+
var init_types2 = __esm({
|
|
2965
|
+
"packages/core/src/sessions/types.ts"() {
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2756
2968
|
|
|
2757
2969
|
// packages/core/src/sessions/load.ts
|
|
2758
|
-
async function enrichSessionRunRecord(
|
|
2970
|
+
async function enrichSessionRunRecord(meta2) {
|
|
2759
2971
|
let metadata;
|
|
2760
2972
|
try {
|
|
2761
|
-
const events = await readTraceEventsFromFile(
|
|
2973
|
+
const events = await readTraceEventsFromFile(meta2.filePath);
|
|
2762
2974
|
for (const event of events) {
|
|
2763
2975
|
if (event.event !== "run_started") continue;
|
|
2764
2976
|
if (event.metadata && typeof event.metadata === "object") {
|
|
@@ -2769,23 +2981,28 @@ async function enrichSessionRunRecord(meta) {
|
|
|
2769
2981
|
} catch {
|
|
2770
2982
|
}
|
|
2771
2983
|
return {
|
|
2772
|
-
runId:
|
|
2773
|
-
name:
|
|
2774
|
-
status:
|
|
2775
|
-
startedAt:
|
|
2776
|
-
endedAt:
|
|
2777
|
-
durationMs:
|
|
2778
|
-
filePath:
|
|
2984
|
+
runId: meta2.runId,
|
|
2985
|
+
name: meta2.name,
|
|
2986
|
+
status: meta2.status,
|
|
2987
|
+
startedAt: meta2.startedAt,
|
|
2988
|
+
endedAt: meta2.endedAt,
|
|
2989
|
+
durationMs: meta2.durationMs,
|
|
2990
|
+
filePath: meta2.filePath,
|
|
2779
2991
|
metadata
|
|
2780
2992
|
};
|
|
2781
2993
|
}
|
|
2782
2994
|
async function loadSessionRunRecords(metas) {
|
|
2783
2995
|
const out = [];
|
|
2784
|
-
for (const
|
|
2785
|
-
out.push(await enrichSessionRunRecord(
|
|
2996
|
+
for (const meta2 of metas) {
|
|
2997
|
+
out.push(await enrichSessionRunRecord(meta2));
|
|
2786
2998
|
}
|
|
2787
2999
|
return out;
|
|
2788
3000
|
}
|
|
3001
|
+
var init_load = __esm({
|
|
3002
|
+
"packages/core/src/sessions/load.ts"() {
|
|
3003
|
+
init_storage();
|
|
3004
|
+
}
|
|
3005
|
+
});
|
|
2789
3006
|
|
|
2790
3007
|
// packages/core/src/sessions/scope.ts
|
|
2791
3008
|
function filterMetasBySessionScope(metas, records, options) {
|
|
@@ -2809,7 +3026,7 @@ function filterMetasBySessionScope(metas, records, options) {
|
|
|
2809
3026
|
};
|
|
2810
3027
|
}
|
|
2811
3028
|
const runIdSet = new Set(session.runIds);
|
|
2812
|
-
const filtered = metas.filter((
|
|
3029
|
+
const filtered = metas.filter((meta2) => runIdSet.has(meta2.runId));
|
|
2813
3030
|
return {
|
|
2814
3031
|
metas: filtered,
|
|
2815
3032
|
scopeLabel: sessionId,
|
|
@@ -2833,7 +3050,7 @@ function filterMetasBySessionScope(metas, records, options) {
|
|
|
2833
3050
|
}
|
|
2834
3051
|
const runIdSet = new Set(runIds);
|
|
2835
3052
|
return {
|
|
2836
|
-
metas: metas.filter((
|
|
3053
|
+
metas: metas.filter((meta2) => runIdSet.has(meta2.runId)),
|
|
2837
3054
|
scopeLabel: groupId,
|
|
2838
3055
|
scopeKind: "group",
|
|
2839
3056
|
runIds,
|
|
@@ -2850,6 +3067,20 @@ function filterMetasBySessionScope(metas, records, options) {
|
|
|
2850
3067
|
notFound: false
|
|
2851
3068
|
};
|
|
2852
3069
|
}
|
|
3070
|
+
var init_scope = __esm({
|
|
3071
|
+
"packages/core/src/sessions/scope.ts"() {
|
|
3072
|
+
init_sessions();
|
|
3073
|
+
init_metadata();
|
|
3074
|
+
}
|
|
3075
|
+
});
|
|
3076
|
+
|
|
3077
|
+
// packages/core/src/sessions/cohort.ts
|
|
3078
|
+
var init_cohort = __esm({
|
|
3079
|
+
"packages/core/src/sessions/cohort.ts"() {
|
|
3080
|
+
init_sessions();
|
|
3081
|
+
init_metadata();
|
|
3082
|
+
}
|
|
3083
|
+
});
|
|
2853
3084
|
|
|
2854
3085
|
// packages/core/src/sessions/checks.ts
|
|
2855
3086
|
function emptySummary() {
|
|
@@ -2943,6 +3174,10 @@ function aggregateSessionCheckResults(perRun, scope) {
|
|
|
2943
3174
|
...scope.sessionWarnings?.length ? { sessionWarnings: [...scope.sessionWarnings] } : {}
|
|
2944
3175
|
};
|
|
2945
3176
|
}
|
|
3177
|
+
var init_checks = __esm({
|
|
3178
|
+
"packages/core/src/sessions/checks.ts"() {
|
|
3179
|
+
}
|
|
3180
|
+
});
|
|
2946
3181
|
|
|
2947
3182
|
// packages/core/src/sessions/index.ts
|
|
2948
3183
|
function compareRuns(a, b) {
|
|
@@ -2982,37 +3217,37 @@ function buildHandoffs(runIds, metaByRunId, warnings, sessionId) {
|
|
|
2982
3217
|
edges.push(edge);
|
|
2983
3218
|
};
|
|
2984
3219
|
for (const runId of runIds) {
|
|
2985
|
-
const
|
|
2986
|
-
if (!
|
|
2987
|
-
if (
|
|
3220
|
+
const meta2 = metaByRunId.get(runId);
|
|
3221
|
+
if (!meta2) continue;
|
|
3222
|
+
if (meta2.handoffFrom && meta2.handoffTo) {
|
|
2988
3223
|
pushEdge({
|
|
2989
|
-
from:
|
|
2990
|
-
to:
|
|
3224
|
+
from: meta2.handoffFrom,
|
|
3225
|
+
to: meta2.handoffTo,
|
|
2991
3226
|
source: "manual",
|
|
2992
3227
|
confidence: "explicit"
|
|
2993
3228
|
});
|
|
2994
3229
|
continue;
|
|
2995
3230
|
}
|
|
2996
|
-
if (
|
|
3231
|
+
if (meta2.handoffFrom) {
|
|
2997
3232
|
pushEdge({
|
|
2998
|
-
from:
|
|
3233
|
+
from: meta2.handoffFrom,
|
|
2999
3234
|
to: runId,
|
|
3000
3235
|
source: "manual",
|
|
3001
3236
|
confidence: "explicit"
|
|
3002
3237
|
});
|
|
3003
3238
|
}
|
|
3004
|
-
if (
|
|
3239
|
+
if (meta2.handoffTo) {
|
|
3005
3240
|
pushEdge({
|
|
3006
3241
|
from: runId,
|
|
3007
|
-
to:
|
|
3242
|
+
to: meta2.handoffTo,
|
|
3008
3243
|
source: "manual",
|
|
3009
3244
|
confidence: "explicit"
|
|
3010
3245
|
});
|
|
3011
3246
|
}
|
|
3012
|
-
if (
|
|
3247
|
+
if (meta2.subAgentId && meta2.parentGroupId && !meta2.handoffFrom && !meta2.handoffTo) {
|
|
3013
3248
|
pushEdge({
|
|
3014
|
-
from:
|
|
3015
|
-
to:
|
|
3249
|
+
from: meta2.parentGroupId,
|
|
3250
|
+
to: meta2.subAgentId,
|
|
3016
3251
|
source: "inferred",
|
|
3017
3252
|
confidence: "correlated"
|
|
3018
3253
|
});
|
|
@@ -3033,22 +3268,22 @@ function buildHandoffs(runIds, metaByRunId, warnings, sessionId) {
|
|
|
3033
3268
|
function buildRetries(runIds, metaByRunId, warnings, sessionId) {
|
|
3034
3269
|
const retries = [];
|
|
3035
3270
|
for (const runId of runIds) {
|
|
3036
|
-
const
|
|
3037
|
-
if (!
|
|
3038
|
-
if (
|
|
3271
|
+
const meta2 = metaByRunId.get(runId);
|
|
3272
|
+
if (!meta2) continue;
|
|
3273
|
+
if (meta2.retryOf) {
|
|
3039
3274
|
retries.push({
|
|
3040
3275
|
runId,
|
|
3041
|
-
retryOf:
|
|
3042
|
-
attempt:
|
|
3276
|
+
retryOf: meta2.retryOf,
|
|
3277
|
+
attempt: meta2.attempt,
|
|
3043
3278
|
source: "manual",
|
|
3044
3279
|
confidence: "explicit"
|
|
3045
3280
|
});
|
|
3046
3281
|
continue;
|
|
3047
3282
|
}
|
|
3048
|
-
if (
|
|
3283
|
+
if (meta2.attempt !== void 0 && meta2.attempt > 1) {
|
|
3049
3284
|
retries.push({
|
|
3050
3285
|
runId,
|
|
3051
|
-
attempt:
|
|
3286
|
+
attempt: meta2.attempt,
|
|
3052
3287
|
source: "inferred",
|
|
3053
3288
|
confidence: "correlated"
|
|
3054
3289
|
});
|
|
@@ -3071,12 +3306,12 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
3071
3306
|
handoffs.filter((edge) => edge.confidence === "explicit").map((edge) => edge.from)
|
|
3072
3307
|
);
|
|
3073
3308
|
const ordered = [...runs].sort(compareRuns);
|
|
3074
|
-
const
|
|
3309
|
+
const path22 = [];
|
|
3075
3310
|
const visited = /* @__PURE__ */ new Set();
|
|
3076
3311
|
const pushRun = (run, confidence, source) => {
|
|
3077
3312
|
if (visited.has(run.runId)) return;
|
|
3078
3313
|
visited.add(run.runId);
|
|
3079
|
-
|
|
3314
|
+
path22.push({
|
|
3080
3315
|
runId: run.runId,
|
|
3081
3316
|
name: run.name,
|
|
3082
3317
|
startedAt: run.startedAt,
|
|
@@ -3101,118 +3336,1377 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
3101
3336
|
const confidence = explicitTargets.has(run.runId) || explicitSources.has(run.runId) ? "explicit" : "correlated";
|
|
3102
3337
|
pushRun(run, confidence, confidence === "explicit" ? "manual" : "inferred");
|
|
3103
3338
|
}
|
|
3104
|
-
return
|
|
3339
|
+
return path22;
|
|
3340
|
+
}
|
|
3341
|
+
function metaRunIdMatches(run, token, runById) {
|
|
3342
|
+
const meta2 = extractSessionWorkflowMetadata(run.metadata);
|
|
3343
|
+
return meta2?.subAgentId === token || meta2?.groupId === token || runById.has(token);
|
|
3344
|
+
}
|
|
3345
|
+
function buildSessionIndex(inputRuns, options = {}) {
|
|
3346
|
+
const warnings = [];
|
|
3347
|
+
const runs = [...inputRuns].sort(compareRuns);
|
|
3348
|
+
const metaByRunId = /* @__PURE__ */ new Map();
|
|
3349
|
+
for (const run of runs) {
|
|
3350
|
+
metaByRunId.set(run.runId, extractSessionWorkflowMetadata(run.metadata));
|
|
3351
|
+
}
|
|
3352
|
+
const sessionsByKey = /* @__PURE__ */ new Map();
|
|
3353
|
+
const unscopedRunIds = [];
|
|
3354
|
+
for (const run of runs) {
|
|
3355
|
+
const meta2 = metaByRunId.get(run.runId);
|
|
3356
|
+
const key = sessionKeyForRun(meta2, {
|
|
3357
|
+
correlateByGroupId: options.correlateByGroupId === true
|
|
3358
|
+
});
|
|
3359
|
+
if (!key) {
|
|
3360
|
+
unscopedRunIds.push(run.runId);
|
|
3361
|
+
continue;
|
|
3362
|
+
}
|
|
3363
|
+
const bucket = sessionsByKey.get(key) ?? [];
|
|
3364
|
+
bucket.push(run);
|
|
3365
|
+
sessionsByKey.set(key, bucket);
|
|
3366
|
+
}
|
|
3367
|
+
const sessions = [...sessionsByKey.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([sessionId, sessionRuns]) => {
|
|
3368
|
+
const runIds = sessionRuns.map((run) => run.runId).sort();
|
|
3369
|
+
const handoffs = buildHandoffs(runIds, metaByRunId, warnings, sessionId);
|
|
3370
|
+
const retries = buildRetries(runIds, metaByRunId, warnings, sessionId);
|
|
3371
|
+
const groups = buildGroups(runIds, metaByRunId);
|
|
3372
|
+
const criticalPath = buildCriticalPath(sessionRuns, handoffs);
|
|
3373
|
+
const confidences = new Set(handoffs.map((edge) => edge.confidence));
|
|
3374
|
+
if (confidences.has("explicit") && confidences.has("correlated")) {
|
|
3375
|
+
warnings.push({
|
|
3376
|
+
code: "mixed-confidence-group",
|
|
3377
|
+
message: "Session aggregates explicit and correlated handoff edges.",
|
|
3378
|
+
sessionId
|
|
3379
|
+
});
|
|
3380
|
+
}
|
|
3381
|
+
return {
|
|
3382
|
+
sessionId,
|
|
3383
|
+
runIds,
|
|
3384
|
+
groups,
|
|
3385
|
+
handoffs,
|
|
3386
|
+
retries,
|
|
3387
|
+
criticalPath
|
|
3388
|
+
};
|
|
3389
|
+
});
|
|
3390
|
+
if (sessions.length === 0 && runs.length > 0) {
|
|
3391
|
+
warnings.push({
|
|
3392
|
+
code: "missing-session-id",
|
|
3393
|
+
message: "No sessionId (or correlated groupId) found on input runs."
|
|
3394
|
+
});
|
|
3395
|
+
}
|
|
3396
|
+
warnings.sort((a, b) => {
|
|
3397
|
+
const code = a.code.localeCompare(b.code);
|
|
3398
|
+
if (code !== 0) return code;
|
|
3399
|
+
return (a.runId ?? "").localeCompare(b.runId ?? "");
|
|
3400
|
+
});
|
|
3401
|
+
return {
|
|
3402
|
+
runs,
|
|
3403
|
+
sessions,
|
|
3404
|
+
unscopedRunIds: unscopedRunIds.sort(),
|
|
3405
|
+
warnings
|
|
3406
|
+
};
|
|
3407
|
+
}
|
|
3408
|
+
var init_sessions = __esm({
|
|
3409
|
+
"packages/core/src/sessions/index.ts"() {
|
|
3410
|
+
init_metadata();
|
|
3411
|
+
init_metadata();
|
|
3412
|
+
init_types2();
|
|
3413
|
+
init_load();
|
|
3414
|
+
init_scope();
|
|
3415
|
+
init_cohort();
|
|
3416
|
+
init_checks();
|
|
3417
|
+
}
|
|
3418
|
+
});
|
|
3419
|
+
function isRecord6(value) {
|
|
3420
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3421
|
+
}
|
|
3422
|
+
function safeParse(line) {
|
|
3423
|
+
try {
|
|
3424
|
+
return JSON.parse(line);
|
|
3425
|
+
} catch {
|
|
3426
|
+
return void 0;
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
async function isAgentInspectTrace(filePath) {
|
|
3430
|
+
try {
|
|
3431
|
+
const rl = readline.createInterface({
|
|
3432
|
+
input: fs.createReadStream(filePath, { encoding: "utf8" }),
|
|
3433
|
+
crlfDelay: Infinity
|
|
3434
|
+
});
|
|
3435
|
+
let checked = 0;
|
|
3436
|
+
for await (const line of rl) {
|
|
3437
|
+
const trimmed = line.trim();
|
|
3438
|
+
if (trimmed === "") continue;
|
|
3439
|
+
const parsed = safeParse(trimmed);
|
|
3440
|
+
if (!parsed) continue;
|
|
3441
|
+
if (!isRecord6(parsed)) continue;
|
|
3442
|
+
checked += 1;
|
|
3443
|
+
if (isTraceEvent(parsed)) return true;
|
|
3444
|
+
const ev = parsed.event;
|
|
3445
|
+
const runId = parsed.runId;
|
|
3446
|
+
if (typeof ev === "string" && KNOWN_EVENTS.has(ev) && typeof runId === "string") {
|
|
3447
|
+
return true;
|
|
3448
|
+
}
|
|
3449
|
+
if (checked >= 20) break;
|
|
3450
|
+
}
|
|
3451
|
+
return false;
|
|
3452
|
+
} catch {
|
|
3453
|
+
return false;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
var KNOWN_EVENTS;
|
|
3457
|
+
var init_trace_verification = __esm({
|
|
3458
|
+
"packages/core/src/trace-verification.ts"() {
|
|
3459
|
+
init_types();
|
|
3460
|
+
KNOWN_EVENTS = /* @__PURE__ */ new Set([
|
|
3461
|
+
"run_started",
|
|
3462
|
+
"run_completed",
|
|
3463
|
+
"step_started",
|
|
3464
|
+
"step_completed"
|
|
3465
|
+
]);
|
|
3466
|
+
}
|
|
3467
|
+
});
|
|
3468
|
+
|
|
3469
|
+
// packages/core/src/inspect-run.ts
|
|
3470
|
+
var init_inspect_run = __esm({
|
|
3471
|
+
"packages/core/src/inspect-run.ts"() {
|
|
3472
|
+
init_correlation_metadata();
|
|
3473
|
+
init_context();
|
|
3474
|
+
init_storage();
|
|
3475
|
+
init_terminal();
|
|
3476
|
+
init_trace_directory();
|
|
3477
|
+
init_trace_event_safety();
|
|
3478
|
+
init_utils();
|
|
3479
|
+
}
|
|
3480
|
+
});
|
|
3481
|
+
|
|
3482
|
+
// packages/core/src/maybe-inspect-run.ts
|
|
3483
|
+
var init_maybe_inspect_run = __esm({
|
|
3484
|
+
"packages/core/src/maybe-inspect-run.ts"() {
|
|
3485
|
+
init_inspect_run();
|
|
3486
|
+
}
|
|
3487
|
+
});
|
|
3488
|
+
|
|
3489
|
+
// packages/core/src/entries/advanced.ts
|
|
3490
|
+
var init_advanced = __esm({
|
|
3491
|
+
"packages/core/src/entries/advanced.ts"() {
|
|
3492
|
+
init_context();
|
|
3493
|
+
init_inspector();
|
|
3494
|
+
init_inspector_runtime();
|
|
3495
|
+
init_trace_event_safety();
|
|
3496
|
+
init_terminal();
|
|
3497
|
+
init_utils();
|
|
3498
|
+
init_types();
|
|
3499
|
+
init_storage();
|
|
3500
|
+
init_read_trace();
|
|
3501
|
+
init_trace_directory();
|
|
3502
|
+
init_trace_metadata();
|
|
3503
|
+
init_trace_filter();
|
|
3504
|
+
init_timeline();
|
|
3505
|
+
init_what();
|
|
3506
|
+
init_explain();
|
|
3507
|
+
init_stats();
|
|
3508
|
+
init_search();
|
|
3509
|
+
init_sessions();
|
|
3510
|
+
init_trace_verification();
|
|
3511
|
+
init_duration();
|
|
3512
|
+
init_maybe_inspect_run();
|
|
3513
|
+
}
|
|
3514
|
+
});
|
|
3515
|
+
|
|
3516
|
+
// packages/index-sqlite/src/types.ts
|
|
3517
|
+
var INDEX_SCHEMA_VERSION, INDEX_DB_FILENAME;
|
|
3518
|
+
var init_types3 = __esm({
|
|
3519
|
+
"packages/index-sqlite/src/types.ts"() {
|
|
3520
|
+
INDEX_SCHEMA_VERSION = "1";
|
|
3521
|
+
INDEX_DB_FILENAME = "trace-index.sqlite";
|
|
3522
|
+
}
|
|
3523
|
+
});
|
|
3524
|
+
|
|
3525
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/util.js
|
|
3526
|
+
var require_util = __commonJS({
|
|
3527
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/util.js"(exports$1) {
|
|
3528
|
+
exports$1.getBooleanOption = (options, key) => {
|
|
3529
|
+
let value = false;
|
|
3530
|
+
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
3531
|
+
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
3532
|
+
}
|
|
3533
|
+
return value;
|
|
3534
|
+
};
|
|
3535
|
+
exports$1.cppdb = /* @__PURE__ */ Symbol();
|
|
3536
|
+
exports$1.inspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
3537
|
+
}
|
|
3538
|
+
});
|
|
3539
|
+
|
|
3540
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/sqlite-error.js
|
|
3541
|
+
var require_sqlite_error = __commonJS({
|
|
3542
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/sqlite-error.js"(exports$1, module) {
|
|
3543
|
+
var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
3544
|
+
function SqliteError(message, code) {
|
|
3545
|
+
if (new.target !== SqliteError) {
|
|
3546
|
+
return new SqliteError(message, code);
|
|
3547
|
+
}
|
|
3548
|
+
if (typeof code !== "string") {
|
|
3549
|
+
throw new TypeError("Expected second argument to be a string");
|
|
3550
|
+
}
|
|
3551
|
+
Error.call(this, message);
|
|
3552
|
+
descriptor.value = "" + message;
|
|
3553
|
+
Object.defineProperty(this, "message", descriptor);
|
|
3554
|
+
Error.captureStackTrace(this, SqliteError);
|
|
3555
|
+
this.code = code;
|
|
3556
|
+
}
|
|
3557
|
+
Object.setPrototypeOf(SqliteError, Error);
|
|
3558
|
+
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
3559
|
+
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
3560
|
+
module.exports = SqliteError;
|
|
3561
|
+
}
|
|
3562
|
+
});
|
|
3563
|
+
|
|
3564
|
+
// node_modules/.pnpm/file-uri-to-path@1.0.0/node_modules/file-uri-to-path/index.js
|
|
3565
|
+
var require_file_uri_to_path = __commonJS({
|
|
3566
|
+
"node_modules/.pnpm/file-uri-to-path@1.0.0/node_modules/file-uri-to-path/index.js"(exports$1, module) {
|
|
3567
|
+
var sep = __require("path").sep || "/";
|
|
3568
|
+
module.exports = fileUriToPath;
|
|
3569
|
+
function fileUriToPath(uri) {
|
|
3570
|
+
if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
|
|
3571
|
+
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
3572
|
+
}
|
|
3573
|
+
var rest = decodeURI(uri.substring(7));
|
|
3574
|
+
var firstSlash = rest.indexOf("/");
|
|
3575
|
+
var host = rest.substring(0, firstSlash);
|
|
3576
|
+
var path22 = rest.substring(firstSlash + 1);
|
|
3577
|
+
if ("localhost" == host) host = "";
|
|
3578
|
+
if (host) {
|
|
3579
|
+
host = sep + sep + host;
|
|
3580
|
+
}
|
|
3581
|
+
path22 = path22.replace(/^(.+)\|/, "$1:");
|
|
3582
|
+
if (sep == "\\") {
|
|
3583
|
+
path22 = path22.replace(/\//g, "\\");
|
|
3584
|
+
}
|
|
3585
|
+
if (/^.+\:/.test(path22)) ; else {
|
|
3586
|
+
path22 = sep + path22;
|
|
3587
|
+
}
|
|
3588
|
+
return host + path22;
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
});
|
|
3592
|
+
|
|
3593
|
+
// node_modules/.pnpm/bindings@1.5.0/node_modules/bindings/bindings.js
|
|
3594
|
+
var require_bindings = __commonJS({
|
|
3595
|
+
"node_modules/.pnpm/bindings@1.5.0/node_modules/bindings/bindings.js"(exports$1, module) {
|
|
3596
|
+
var fs = __require("fs");
|
|
3597
|
+
var path22 = __require("path");
|
|
3598
|
+
var fileURLToPath2 = require_file_uri_to_path();
|
|
3599
|
+
var join = path22.join;
|
|
3600
|
+
var dirname = path22.dirname;
|
|
3601
|
+
var exists = fs.accessSync && function(path23) {
|
|
3602
|
+
try {
|
|
3603
|
+
fs.accessSync(path23);
|
|
3604
|
+
} catch (e) {
|
|
3605
|
+
return false;
|
|
3606
|
+
}
|
|
3607
|
+
return true;
|
|
3608
|
+
} || fs.existsSync || path22.existsSync;
|
|
3609
|
+
var defaults = {
|
|
3610
|
+
arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
|
|
3611
|
+
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
3612
|
+
platform: process.platform,
|
|
3613
|
+
arch: process.arch,
|
|
3614
|
+
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
3615
|
+
version: process.versions.node,
|
|
3616
|
+
bindings: "bindings.node",
|
|
3617
|
+
try: [
|
|
3618
|
+
// node-gyp's linked version in the "build" dir
|
|
3619
|
+
["module_root", "build", "bindings"],
|
|
3620
|
+
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
3621
|
+
["module_root", "build", "Debug", "bindings"],
|
|
3622
|
+
["module_root", "build", "Release", "bindings"],
|
|
3623
|
+
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
3624
|
+
["module_root", "out", "Debug", "bindings"],
|
|
3625
|
+
["module_root", "Debug", "bindings"],
|
|
3626
|
+
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
3627
|
+
["module_root", "out", "Release", "bindings"],
|
|
3628
|
+
["module_root", "Release", "bindings"],
|
|
3629
|
+
// Legacy from node-waf, node <= 0.4.x
|
|
3630
|
+
["module_root", "build", "default", "bindings"],
|
|
3631
|
+
// Production "Release" buildtype binary (meh...)
|
|
3632
|
+
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
3633
|
+
// node-qbs builds
|
|
3634
|
+
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
3635
|
+
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
3636
|
+
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
3637
|
+
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
3638
|
+
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
3639
|
+
]
|
|
3640
|
+
};
|
|
3641
|
+
function bindings(opts) {
|
|
3642
|
+
if (typeof opts == "string") {
|
|
3643
|
+
opts = { bindings: opts };
|
|
3644
|
+
} else if (!opts) {
|
|
3645
|
+
opts = {};
|
|
3646
|
+
}
|
|
3647
|
+
Object.keys(defaults).map(function(i2) {
|
|
3648
|
+
if (!(i2 in opts)) opts[i2] = defaults[i2];
|
|
3649
|
+
});
|
|
3650
|
+
if (!opts.module_root) {
|
|
3651
|
+
opts.module_root = exports$1.getRoot(exports$1.getFileName());
|
|
3652
|
+
}
|
|
3653
|
+
if (path22.extname(opts.bindings) != ".node") {
|
|
3654
|
+
opts.bindings += ".node";
|
|
3655
|
+
}
|
|
3656
|
+
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
3657
|
+
var tries = [], i = 0, l = opts.try.length, n, b, err;
|
|
3658
|
+
for (; i < l; i++) {
|
|
3659
|
+
n = join.apply(
|
|
3660
|
+
null,
|
|
3661
|
+
opts.try[i].map(function(p) {
|
|
3662
|
+
return opts[p] || p;
|
|
3663
|
+
})
|
|
3664
|
+
);
|
|
3665
|
+
tries.push(n);
|
|
3666
|
+
try {
|
|
3667
|
+
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
3668
|
+
if (!opts.path) {
|
|
3669
|
+
b.path = n;
|
|
3670
|
+
}
|
|
3671
|
+
return b;
|
|
3672
|
+
} catch (e) {
|
|
3673
|
+
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
|
|
3674
|
+
throw e;
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
err = new Error(
|
|
3679
|
+
"Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
|
|
3680
|
+
return opts.arrow + a;
|
|
3681
|
+
}).join("\n")
|
|
3682
|
+
);
|
|
3683
|
+
err.tries = tries;
|
|
3684
|
+
throw err;
|
|
3685
|
+
}
|
|
3686
|
+
module.exports = exports$1 = bindings;
|
|
3687
|
+
exports$1.getFileName = function getFileName(calling_file) {
|
|
3688
|
+
var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
|
|
3689
|
+
Error.stackTraceLimit = 10;
|
|
3690
|
+
Error.prepareStackTrace = function(e, st) {
|
|
3691
|
+
for (var i = 0, l = st.length; i < l; i++) {
|
|
3692
|
+
fileName = st[i].getFileName();
|
|
3693
|
+
if (fileName !== __filename) {
|
|
3694
|
+
if (calling_file) {
|
|
3695
|
+
if (fileName !== calling_file) {
|
|
3696
|
+
return;
|
|
3697
|
+
}
|
|
3698
|
+
} else {
|
|
3699
|
+
return;
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3704
|
+
Error.captureStackTrace(dummy);
|
|
3705
|
+
dummy.stack;
|
|
3706
|
+
Error.prepareStackTrace = origPST;
|
|
3707
|
+
Error.stackTraceLimit = origSTL;
|
|
3708
|
+
var fileSchema = "file://";
|
|
3709
|
+
if (fileName.indexOf(fileSchema) === 0) {
|
|
3710
|
+
fileName = fileURLToPath2(fileName);
|
|
3711
|
+
}
|
|
3712
|
+
return fileName;
|
|
3713
|
+
};
|
|
3714
|
+
exports$1.getRoot = function getRoot(file) {
|
|
3715
|
+
var dir = dirname(file), prev;
|
|
3716
|
+
while (true) {
|
|
3717
|
+
if (dir === ".") {
|
|
3718
|
+
dir = process.cwd();
|
|
3719
|
+
}
|
|
3720
|
+
if (exists(join(dir, "package.json")) || exists(join(dir, "node_modules"))) {
|
|
3721
|
+
return dir;
|
|
3722
|
+
}
|
|
3723
|
+
if (prev === dir) {
|
|
3724
|
+
throw new Error(
|
|
3725
|
+
'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
|
|
3726
|
+
);
|
|
3727
|
+
}
|
|
3728
|
+
prev = dir;
|
|
3729
|
+
dir = join(dir, "..");
|
|
3730
|
+
}
|
|
3731
|
+
};
|
|
3732
|
+
}
|
|
3733
|
+
});
|
|
3734
|
+
|
|
3735
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/wrappers.js
|
|
3736
|
+
var require_wrappers = __commonJS({
|
|
3737
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/wrappers.js"(exports$1) {
|
|
3738
|
+
var { cppdb } = require_util();
|
|
3739
|
+
exports$1.prepare = function prepare(sql) {
|
|
3740
|
+
return this[cppdb].prepare(sql, this, false);
|
|
3741
|
+
};
|
|
3742
|
+
exports$1.exec = function exec(sql) {
|
|
3743
|
+
this[cppdb].exec(sql);
|
|
3744
|
+
return this;
|
|
3745
|
+
};
|
|
3746
|
+
exports$1.close = function close() {
|
|
3747
|
+
this[cppdb].close();
|
|
3748
|
+
return this;
|
|
3749
|
+
};
|
|
3750
|
+
exports$1.loadExtension = function loadExtension(...args) {
|
|
3751
|
+
this[cppdb].loadExtension(...args);
|
|
3752
|
+
return this;
|
|
3753
|
+
};
|
|
3754
|
+
exports$1.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
3755
|
+
this[cppdb].defaultSafeIntegers(...args);
|
|
3756
|
+
return this;
|
|
3757
|
+
};
|
|
3758
|
+
exports$1.unsafeMode = function unsafeMode(...args) {
|
|
3759
|
+
this[cppdb].unsafeMode(...args);
|
|
3760
|
+
return this;
|
|
3761
|
+
};
|
|
3762
|
+
exports$1.getters = {
|
|
3763
|
+
name: {
|
|
3764
|
+
get: function name() {
|
|
3765
|
+
return this[cppdb].name;
|
|
3766
|
+
},
|
|
3767
|
+
enumerable: true
|
|
3768
|
+
},
|
|
3769
|
+
open: {
|
|
3770
|
+
get: function open3() {
|
|
3771
|
+
return this[cppdb].open;
|
|
3772
|
+
},
|
|
3773
|
+
enumerable: true
|
|
3774
|
+
},
|
|
3775
|
+
inTransaction: {
|
|
3776
|
+
get: function inTransaction() {
|
|
3777
|
+
return this[cppdb].inTransaction;
|
|
3778
|
+
},
|
|
3779
|
+
enumerable: true
|
|
3780
|
+
},
|
|
3781
|
+
readonly: {
|
|
3782
|
+
get: function readonly() {
|
|
3783
|
+
return this[cppdb].readonly;
|
|
3784
|
+
},
|
|
3785
|
+
enumerable: true
|
|
3786
|
+
},
|
|
3787
|
+
memory: {
|
|
3788
|
+
get: function memory() {
|
|
3789
|
+
return this[cppdb].memory;
|
|
3790
|
+
},
|
|
3791
|
+
enumerable: true
|
|
3792
|
+
}
|
|
3793
|
+
};
|
|
3794
|
+
}
|
|
3795
|
+
});
|
|
3796
|
+
|
|
3797
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/transaction.js
|
|
3798
|
+
var require_transaction = __commonJS({
|
|
3799
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/transaction.js"(exports$1, module) {
|
|
3800
|
+
var { cppdb } = require_util();
|
|
3801
|
+
var controllers = /* @__PURE__ */ new WeakMap();
|
|
3802
|
+
module.exports = function transaction(fn) {
|
|
3803
|
+
if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
|
|
3804
|
+
const db = this[cppdb];
|
|
3805
|
+
const controller = getController(db, this);
|
|
3806
|
+
const { apply } = Function.prototype;
|
|
3807
|
+
const properties = {
|
|
3808
|
+
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
3809
|
+
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
3810
|
+
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
3811
|
+
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
3812
|
+
database: { value: this, enumerable: true }
|
|
3813
|
+
};
|
|
3814
|
+
Object.defineProperties(properties.default.value, properties);
|
|
3815
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
3816
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
3817
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
3818
|
+
return properties.default.value;
|
|
3819
|
+
};
|
|
3820
|
+
var getController = (db, self) => {
|
|
3821
|
+
let controller = controllers.get(db);
|
|
3822
|
+
if (!controller) {
|
|
3823
|
+
const shared = {
|
|
3824
|
+
commit: db.prepare("COMMIT", self, false),
|
|
3825
|
+
rollback: db.prepare("ROLLBACK", self, false),
|
|
3826
|
+
savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
|
|
3827
|
+
release: db.prepare("RELEASE ` _bs3. `", self, false),
|
|
3828
|
+
rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
|
|
3829
|
+
};
|
|
3830
|
+
controllers.set(db, controller = {
|
|
3831
|
+
default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
|
|
3832
|
+
deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
|
|
3833
|
+
immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
|
|
3834
|
+
exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
|
|
3835
|
+
});
|
|
3836
|
+
}
|
|
3837
|
+
return controller;
|
|
3838
|
+
};
|
|
3839
|
+
var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
3840
|
+
let before, after, undo;
|
|
3841
|
+
if (db.inTransaction) {
|
|
3842
|
+
before = savepoint;
|
|
3843
|
+
after = release;
|
|
3844
|
+
undo = rollbackTo;
|
|
3845
|
+
} else {
|
|
3846
|
+
before = begin;
|
|
3847
|
+
after = commit;
|
|
3848
|
+
undo = rollback;
|
|
3849
|
+
}
|
|
3850
|
+
before.run();
|
|
3851
|
+
try {
|
|
3852
|
+
const result = apply.call(fn, this, arguments);
|
|
3853
|
+
if (result && typeof result.then === "function") {
|
|
3854
|
+
throw new TypeError("Transaction function cannot return a promise");
|
|
3855
|
+
}
|
|
3856
|
+
after.run();
|
|
3857
|
+
return result;
|
|
3858
|
+
} catch (ex) {
|
|
3859
|
+
if (db.inTransaction) {
|
|
3860
|
+
undo.run();
|
|
3861
|
+
if (undo !== rollback) after.run();
|
|
3862
|
+
}
|
|
3863
|
+
throw ex;
|
|
3864
|
+
}
|
|
3865
|
+
};
|
|
3866
|
+
}
|
|
3867
|
+
});
|
|
3868
|
+
|
|
3869
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/pragma.js
|
|
3870
|
+
var require_pragma = __commonJS({
|
|
3871
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/pragma.js"(exports$1, module) {
|
|
3872
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
3873
|
+
module.exports = function pragma(source, options) {
|
|
3874
|
+
if (options == null) options = {};
|
|
3875
|
+
if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
|
|
3876
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
3877
|
+
const simple = getBooleanOption(options, "simple");
|
|
3878
|
+
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
3879
|
+
return simple ? stmt.pluck().get() : stmt.all();
|
|
3880
|
+
};
|
|
3881
|
+
}
|
|
3882
|
+
});
|
|
3883
|
+
|
|
3884
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/backup.js
|
|
3885
|
+
var require_backup = __commonJS({
|
|
3886
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/backup.js"(exports$1, module) {
|
|
3887
|
+
var fs = __require("fs");
|
|
3888
|
+
var path22 = __require("path");
|
|
3889
|
+
var { promisify } = __require("util");
|
|
3890
|
+
var { cppdb } = require_util();
|
|
3891
|
+
var fsAccess = promisify(fs.access);
|
|
3892
|
+
module.exports = async function backup(filename, options) {
|
|
3893
|
+
if (options == null) options = {};
|
|
3894
|
+
if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
|
|
3895
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
3896
|
+
filename = filename.trim();
|
|
3897
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
3898
|
+
const handler = "progress" in options ? options.progress : null;
|
|
3899
|
+
if (!filename) throw new TypeError("Backup filename cannot be an empty string");
|
|
3900
|
+
if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
|
|
3901
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
3902
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
3903
|
+
if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
|
|
3904
|
+
await fsAccess(path22.dirname(filename)).catch(() => {
|
|
3905
|
+
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
3906
|
+
});
|
|
3907
|
+
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
3908
|
+
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
3909
|
+
};
|
|
3910
|
+
var runBackup = (backup, handler) => {
|
|
3911
|
+
let rate = 0;
|
|
3912
|
+
let useDefault = true;
|
|
3913
|
+
return new Promise((resolve, reject) => {
|
|
3914
|
+
setImmediate(function step() {
|
|
3915
|
+
try {
|
|
3916
|
+
const progress = backup.transfer(rate);
|
|
3917
|
+
if (!progress.remainingPages) {
|
|
3918
|
+
backup.close();
|
|
3919
|
+
resolve(progress);
|
|
3920
|
+
return;
|
|
3921
|
+
}
|
|
3922
|
+
if (useDefault) {
|
|
3923
|
+
useDefault = false;
|
|
3924
|
+
rate = 100;
|
|
3925
|
+
}
|
|
3926
|
+
if (handler) {
|
|
3927
|
+
const ret = handler(progress);
|
|
3928
|
+
if (ret !== void 0) {
|
|
3929
|
+
if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
3930
|
+
else throw new TypeError("Expected progress callback to return a number or undefined");
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
setImmediate(step);
|
|
3934
|
+
} catch (err) {
|
|
3935
|
+
backup.close();
|
|
3936
|
+
reject(err);
|
|
3937
|
+
}
|
|
3938
|
+
});
|
|
3939
|
+
});
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
});
|
|
3943
|
+
|
|
3944
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/serialize.js
|
|
3945
|
+
var require_serialize = __commonJS({
|
|
3946
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/serialize.js"(exports$1, module) {
|
|
3947
|
+
var { cppdb } = require_util();
|
|
3948
|
+
module.exports = function serialize(options) {
|
|
3949
|
+
if (options == null) options = {};
|
|
3950
|
+
if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
|
|
3951
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
3952
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
3953
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
3954
|
+
return this[cppdb].serialize(attachedName);
|
|
3955
|
+
};
|
|
3956
|
+
}
|
|
3957
|
+
});
|
|
3958
|
+
|
|
3959
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/function.js
|
|
3960
|
+
var require_function = __commonJS({
|
|
3961
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/function.js"(exports$1, module) {
|
|
3962
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
3963
|
+
module.exports = function defineFunction(name, options, fn) {
|
|
3964
|
+
if (options == null) options = {};
|
|
3965
|
+
if (typeof options === "function") {
|
|
3966
|
+
fn = options;
|
|
3967
|
+
options = {};
|
|
3968
|
+
}
|
|
3969
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
3970
|
+
if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
|
|
3971
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
3972
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
3973
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
3974
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
3975
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
3976
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
3977
|
+
let argCount = -1;
|
|
3978
|
+
if (!varargs) {
|
|
3979
|
+
argCount = fn.length;
|
|
3980
|
+
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
|
|
3981
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
3982
|
+
}
|
|
3983
|
+
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
3984
|
+
return this;
|
|
3985
|
+
};
|
|
3986
|
+
}
|
|
3987
|
+
});
|
|
3988
|
+
|
|
3989
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/aggregate.js
|
|
3990
|
+
var require_aggregate = __commonJS({
|
|
3991
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/aggregate.js"(exports$1, module) {
|
|
3992
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
3993
|
+
module.exports = function defineAggregate(name, options) {
|
|
3994
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
3995
|
+
if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
|
|
3996
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
3997
|
+
const start = "start" in options ? options.start : null;
|
|
3998
|
+
const step = getFunctionOption(options, "step", true);
|
|
3999
|
+
const inverse = getFunctionOption(options, "inverse", false);
|
|
4000
|
+
const result = getFunctionOption(options, "result", false);
|
|
4001
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
4002
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
4003
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
4004
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
4005
|
+
let argCount = -1;
|
|
4006
|
+
if (!varargs) {
|
|
4007
|
+
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
4008
|
+
if (argCount > 0) argCount -= 1;
|
|
4009
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
4010
|
+
}
|
|
4011
|
+
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
4012
|
+
return this;
|
|
4013
|
+
};
|
|
4014
|
+
var getFunctionOption = (options, key, required) => {
|
|
4015
|
+
const value = key in options ? options[key] : null;
|
|
4016
|
+
if (typeof value === "function") return value;
|
|
4017
|
+
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
4018
|
+
if (required) throw new TypeError(`Missing required option "${key}"`);
|
|
4019
|
+
return null;
|
|
4020
|
+
};
|
|
4021
|
+
var getLength = ({ length }) => {
|
|
4022
|
+
if (Number.isInteger(length) && length >= 0) return length;
|
|
4023
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
4024
|
+
};
|
|
4025
|
+
}
|
|
4026
|
+
});
|
|
4027
|
+
|
|
4028
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/table.js
|
|
4029
|
+
var require_table = __commonJS({
|
|
4030
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/table.js"(exports$1, module) {
|
|
4031
|
+
var { cppdb } = require_util();
|
|
4032
|
+
module.exports = function defineTable(name, factory) {
|
|
4033
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
4034
|
+
if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
|
|
4035
|
+
let eponymous = false;
|
|
4036
|
+
if (typeof factory === "object" && factory !== null) {
|
|
4037
|
+
eponymous = true;
|
|
4038
|
+
factory = defer(parseTableDefinition(factory, "used", name));
|
|
4039
|
+
} else {
|
|
4040
|
+
if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
4041
|
+
factory = wrapFactory(factory);
|
|
4042
|
+
}
|
|
4043
|
+
this[cppdb].table(factory, name, eponymous);
|
|
4044
|
+
return this;
|
|
4045
|
+
};
|
|
4046
|
+
function wrapFactory(factory) {
|
|
4047
|
+
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
4048
|
+
const thisObject = {
|
|
4049
|
+
module: moduleName,
|
|
4050
|
+
database: databaseName,
|
|
4051
|
+
table: tableName
|
|
4052
|
+
};
|
|
4053
|
+
const def = apply.call(factory, thisObject, args);
|
|
4054
|
+
if (typeof def !== "object" || def === null) {
|
|
4055
|
+
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
4056
|
+
}
|
|
4057
|
+
return parseTableDefinition(def, "returned", moduleName);
|
|
4058
|
+
};
|
|
4059
|
+
}
|
|
4060
|
+
function parseTableDefinition(def, verb, moduleName) {
|
|
4061
|
+
if (!hasOwnProperty.call(def, "rows")) {
|
|
4062
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
4063
|
+
}
|
|
4064
|
+
if (!hasOwnProperty.call(def, "columns")) {
|
|
4065
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
4066
|
+
}
|
|
4067
|
+
const rows = def.rows;
|
|
4068
|
+
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
4069
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
4070
|
+
}
|
|
4071
|
+
let columns = def.columns;
|
|
4072
|
+
if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
|
|
4073
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
4074
|
+
}
|
|
4075
|
+
if (columns.length !== new Set(columns).size) {
|
|
4076
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
4077
|
+
}
|
|
4078
|
+
if (!columns.length) {
|
|
4079
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
4080
|
+
}
|
|
4081
|
+
let parameters;
|
|
4082
|
+
if (hasOwnProperty.call(def, "parameters")) {
|
|
4083
|
+
parameters = def.parameters;
|
|
4084
|
+
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
|
|
4085
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
4086
|
+
}
|
|
4087
|
+
} else {
|
|
4088
|
+
parameters = inferParameters(rows);
|
|
4089
|
+
}
|
|
4090
|
+
if (parameters.length !== new Set(parameters).size) {
|
|
4091
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
4092
|
+
}
|
|
4093
|
+
if (parameters.length > 32) {
|
|
4094
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
4095
|
+
}
|
|
4096
|
+
for (const parameter of parameters) {
|
|
4097
|
+
if (columns.includes(parameter)) {
|
|
4098
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
4101
|
+
let safeIntegers = 2;
|
|
4102
|
+
if (hasOwnProperty.call(def, "safeIntegers")) {
|
|
4103
|
+
const bool = def.safeIntegers;
|
|
4104
|
+
if (typeof bool !== "boolean") {
|
|
4105
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
4106
|
+
}
|
|
4107
|
+
safeIntegers = +bool;
|
|
4108
|
+
}
|
|
4109
|
+
let directOnly = false;
|
|
4110
|
+
if (hasOwnProperty.call(def, "directOnly")) {
|
|
4111
|
+
directOnly = def.directOnly;
|
|
4112
|
+
if (typeof directOnly !== "boolean") {
|
|
4113
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4116
|
+
const columnDefinitions = [
|
|
4117
|
+
...parameters.map(identifier).map((str2) => `${str2} HIDDEN`),
|
|
4118
|
+
...columns.map(identifier)
|
|
4119
|
+
];
|
|
4120
|
+
return [
|
|
4121
|
+
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
4122
|
+
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
4123
|
+
parameters,
|
|
4124
|
+
safeIntegers,
|
|
4125
|
+
directOnly
|
|
4126
|
+
];
|
|
4127
|
+
}
|
|
4128
|
+
function wrapGenerator(generator, columnMap, moduleName) {
|
|
4129
|
+
return function* virtualTable(...args) {
|
|
4130
|
+
const output2 = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
4131
|
+
for (let i = 0; i < columnMap.size; ++i) {
|
|
4132
|
+
output2.push(null);
|
|
4133
|
+
}
|
|
4134
|
+
for (const row of generator(...args)) {
|
|
4135
|
+
if (Array.isArray(row)) {
|
|
4136
|
+
extractRowArray(row, output2, columnMap.size, moduleName);
|
|
4137
|
+
yield output2;
|
|
4138
|
+
} else if (typeof row === "object" && row !== null) {
|
|
4139
|
+
extractRowObject(row, output2, columnMap, moduleName);
|
|
4140
|
+
yield output2;
|
|
4141
|
+
} else {
|
|
4142
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
};
|
|
4146
|
+
}
|
|
4147
|
+
function extractRowArray(row, output2, columnCount, moduleName) {
|
|
4148
|
+
if (row.length !== columnCount) {
|
|
4149
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
4150
|
+
}
|
|
4151
|
+
const offset = output2.length - columnCount;
|
|
4152
|
+
for (let i = 0; i < columnCount; ++i) {
|
|
4153
|
+
output2[i + offset] = row[i];
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
function extractRowObject(row, output2, columnMap, moduleName) {
|
|
4157
|
+
let count = 0;
|
|
4158
|
+
for (const key of Object.keys(row)) {
|
|
4159
|
+
const index = columnMap.get(key);
|
|
4160
|
+
if (index === void 0) {
|
|
4161
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
4162
|
+
}
|
|
4163
|
+
output2[index] = row[key];
|
|
4164
|
+
count += 1;
|
|
4165
|
+
}
|
|
4166
|
+
if (count !== columnMap.size) {
|
|
4167
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
function inferParameters({ length }) {
|
|
4171
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
4172
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
4173
|
+
}
|
|
4174
|
+
const params = [];
|
|
4175
|
+
for (let i = 0; i < length; ++i) {
|
|
4176
|
+
params.push(`$${i + 1}`);
|
|
4177
|
+
}
|
|
4178
|
+
return params;
|
|
4179
|
+
}
|
|
4180
|
+
var { hasOwnProperty } = Object.prototype;
|
|
4181
|
+
var { apply } = Function.prototype;
|
|
4182
|
+
var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
|
|
4183
|
+
});
|
|
4184
|
+
var identifier = (str2) => `"${str2.replace(/"/g, '""')}"`;
|
|
4185
|
+
var defer = (x) => () => x;
|
|
4186
|
+
}
|
|
4187
|
+
});
|
|
4188
|
+
|
|
4189
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/inspect.js
|
|
4190
|
+
var require_inspect = __commonJS({
|
|
4191
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/methods/inspect.js"(exports$1, module) {
|
|
4192
|
+
var DatabaseInspection = function Database3() {
|
|
4193
|
+
};
|
|
4194
|
+
module.exports = function inspect(depth, opts) {
|
|
4195
|
+
return Object.assign(new DatabaseInspection(), this);
|
|
4196
|
+
};
|
|
4197
|
+
}
|
|
4198
|
+
});
|
|
4199
|
+
|
|
4200
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/database.js
|
|
4201
|
+
var require_database = __commonJS({
|
|
4202
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/database.js"(exports$1, module) {
|
|
4203
|
+
var fs = __require("fs");
|
|
4204
|
+
var path22 = __require("path");
|
|
4205
|
+
var util = require_util();
|
|
4206
|
+
var SqliteError = require_sqlite_error();
|
|
4207
|
+
var DEFAULT_ADDON;
|
|
4208
|
+
function Database3(filenameGiven, options) {
|
|
4209
|
+
if (new.target == null) {
|
|
4210
|
+
return new Database3(filenameGiven, options);
|
|
4211
|
+
}
|
|
4212
|
+
let buffer;
|
|
4213
|
+
if (Buffer.isBuffer(filenameGiven)) {
|
|
4214
|
+
buffer = filenameGiven;
|
|
4215
|
+
filenameGiven = ":memory:";
|
|
4216
|
+
}
|
|
4217
|
+
if (filenameGiven == null) filenameGiven = "";
|
|
4218
|
+
if (options == null) options = {};
|
|
4219
|
+
if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
|
|
4220
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
4221
|
+
if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
4222
|
+
if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
4223
|
+
const filename = filenameGiven.trim();
|
|
4224
|
+
const anonymous = filename === "" || filename === ":memory:";
|
|
4225
|
+
const readonly = util.getBooleanOption(options, "readonly");
|
|
4226
|
+
const fileMustExist = util.getBooleanOption(options, "fileMustExist");
|
|
4227
|
+
const timeout = "timeout" in options ? options.timeout : 5e3;
|
|
4228
|
+
const verbose = "verbose" in options ? options.verbose : null;
|
|
4229
|
+
const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
|
|
4230
|
+
if (readonly && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
4231
|
+
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
4232
|
+
if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
4233
|
+
if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
|
|
4234
|
+
if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
4235
|
+
let addon;
|
|
4236
|
+
if (nativeBinding == null) {
|
|
4237
|
+
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
|
|
4238
|
+
} else if (typeof nativeBinding === "string") {
|
|
4239
|
+
const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
4240
|
+
addon = requireFunc(path22.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
|
|
4241
|
+
} else {
|
|
4242
|
+
addon = nativeBinding;
|
|
4243
|
+
}
|
|
4244
|
+
if (!addon.isInitialized) {
|
|
4245
|
+
addon.setErrorConstructor(SqliteError);
|
|
4246
|
+
addon.isInitialized = true;
|
|
4247
|
+
}
|
|
4248
|
+
if (!anonymous && !fs.existsSync(path22.dirname(filename))) {
|
|
4249
|
+
throw new TypeError("Cannot open database because the directory does not exist");
|
|
4250
|
+
}
|
|
4251
|
+
Object.defineProperties(this, {
|
|
4252
|
+
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
4253
|
+
...wrappers.getters
|
|
4254
|
+
});
|
|
4255
|
+
}
|
|
4256
|
+
var wrappers = require_wrappers();
|
|
4257
|
+
Database3.prototype.prepare = wrappers.prepare;
|
|
4258
|
+
Database3.prototype.transaction = require_transaction();
|
|
4259
|
+
Database3.prototype.pragma = require_pragma();
|
|
4260
|
+
Database3.prototype.backup = require_backup();
|
|
4261
|
+
Database3.prototype.serialize = require_serialize();
|
|
4262
|
+
Database3.prototype.function = require_function();
|
|
4263
|
+
Database3.prototype.aggregate = require_aggregate();
|
|
4264
|
+
Database3.prototype.table = require_table();
|
|
4265
|
+
Database3.prototype.loadExtension = wrappers.loadExtension;
|
|
4266
|
+
Database3.prototype.exec = wrappers.exec;
|
|
4267
|
+
Database3.prototype.close = wrappers.close;
|
|
4268
|
+
Database3.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
4269
|
+
Database3.prototype.unsafeMode = wrappers.unsafeMode;
|
|
4270
|
+
Database3.prototype[util.inspect] = require_inspect();
|
|
4271
|
+
module.exports = Database3;
|
|
4272
|
+
}
|
|
4273
|
+
});
|
|
4274
|
+
|
|
4275
|
+
// node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/index.js
|
|
4276
|
+
var require_lib = __commonJS({
|
|
4277
|
+
"node_modules/.pnpm/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/index.js"(exports$1, module) {
|
|
4278
|
+
module.exports = require_database();
|
|
4279
|
+
module.exports.SqliteError = require_sqlite_error();
|
|
4280
|
+
}
|
|
4281
|
+
});
|
|
4282
|
+
|
|
4283
|
+
// packages/index-sqlite/src/schema.ts
|
|
4284
|
+
function metaDefaults(sourceDir, fileCount) {
|
|
4285
|
+
return {
|
|
4286
|
+
[META_KEYS.schemaVersion]: INDEX_SCHEMA_VERSION,
|
|
4287
|
+
[META_KEYS.builtAt]: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4288
|
+
[META_KEYS.sourceDir]: sourceDir,
|
|
4289
|
+
[META_KEYS.fileCount]: String(fileCount),
|
|
4290
|
+
[META_KEYS.driver]: "better-sqlite3"
|
|
4291
|
+
};
|
|
4292
|
+
}
|
|
4293
|
+
var INDEX_SCHEMA_SQL, DERIVE_SESSIONS_SQL, META_KEYS;
|
|
4294
|
+
var init_schema = __esm({
|
|
4295
|
+
"packages/index-sqlite/src/schema.ts"() {
|
|
4296
|
+
init_types3();
|
|
4297
|
+
INDEX_SCHEMA_SQL = `
|
|
4298
|
+
DROP TABLE IF EXISTS meta;
|
|
4299
|
+
DROP TABLE IF EXISTS errors;
|
|
4300
|
+
DROP TABLE IF EXISTS steps;
|
|
4301
|
+
DROP TABLE IF EXISTS sessions;
|
|
4302
|
+
DROP TABLE IF EXISTS runs;
|
|
4303
|
+
|
|
4304
|
+
CREATE TABLE meta (
|
|
4305
|
+
key TEXT PRIMARY KEY,
|
|
4306
|
+
value TEXT
|
|
4307
|
+
);
|
|
4308
|
+
|
|
4309
|
+
CREATE TABLE runs (
|
|
4310
|
+
run_id TEXT PRIMARY KEY,
|
|
4311
|
+
file TEXT NOT NULL,
|
|
4312
|
+
mtime_ms REAL NOT NULL,
|
|
4313
|
+
name TEXT,
|
|
4314
|
+
status TEXT,
|
|
4315
|
+
started_at REAL,
|
|
4316
|
+
ended_at REAL,
|
|
4317
|
+
duration_ms REAL,
|
|
4318
|
+
session_id TEXT,
|
|
4319
|
+
group_id TEXT,
|
|
4320
|
+
correlation_id TEXT
|
|
4321
|
+
);
|
|
4322
|
+
|
|
4323
|
+
CREATE TABLE steps (
|
|
4324
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4325
|
+
run_id TEXT NOT NULL,
|
|
4326
|
+
step_id TEXT NOT NULL,
|
|
4327
|
+
kind TEXT,
|
|
4328
|
+
name TEXT,
|
|
4329
|
+
status TEXT,
|
|
4330
|
+
duration_ms REAL,
|
|
4331
|
+
tool_name TEXT,
|
|
4332
|
+
model TEXT,
|
|
4333
|
+
parent_id TEXT
|
|
4334
|
+
);
|
|
4335
|
+
|
|
4336
|
+
CREATE TABLE errors (
|
|
4337
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4338
|
+
run_id TEXT NOT NULL,
|
|
4339
|
+
step_id TEXT,
|
|
4340
|
+
message TEXT,
|
|
4341
|
+
code TEXT
|
|
4342
|
+
);
|
|
4343
|
+
|
|
4344
|
+
CREATE TABLE sessions (
|
|
4345
|
+
session_id TEXT PRIMARY KEY,
|
|
4346
|
+
run_count INTEGER NOT NULL,
|
|
4347
|
+
first_started_at REAL,
|
|
4348
|
+
last_ended_at REAL
|
|
4349
|
+
);
|
|
4350
|
+
|
|
4351
|
+
CREATE INDEX idx_runs_status ON runs(status);
|
|
4352
|
+
CREATE INDEX idx_runs_session ON runs(session_id);
|
|
4353
|
+
CREATE INDEX idx_runs_started ON runs(started_at);
|
|
4354
|
+
CREATE INDEX idx_steps_run ON steps(run_id);
|
|
4355
|
+
CREATE INDEX idx_steps_kind ON steps(kind);
|
|
4356
|
+
CREATE INDEX idx_steps_tool ON steps(tool_name);
|
|
4357
|
+
`;
|
|
4358
|
+
DERIVE_SESSIONS_SQL = `
|
|
4359
|
+
INSERT INTO sessions (session_id, run_count, first_started_at, last_ended_at)
|
|
4360
|
+
SELECT session_id, COUNT(*), MIN(started_at), MAX(ended_at)
|
|
4361
|
+
FROM runs
|
|
4362
|
+
WHERE session_id IS NOT NULL
|
|
4363
|
+
GROUP BY session_id;
|
|
4364
|
+
`;
|
|
4365
|
+
META_KEYS = {
|
|
4366
|
+
schemaVersion: "schemaVersion",
|
|
4367
|
+
builtAt: "builtAt",
|
|
4368
|
+
sourceDir: "sourceDir",
|
|
4369
|
+
fileCount: "fileCount",
|
|
4370
|
+
driver: "driver"
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4373
|
+
});
|
|
4374
|
+
function resolveIndexDbPath(traceDir, dbPath) {
|
|
4375
|
+
if (dbPath && dbPath.trim() !== "") return path14__default.default.resolve(dbPath);
|
|
4376
|
+
return path14__default.default.join(path14__default.default.resolve(traceDir), INDEX_DB_FILENAME);
|
|
3105
4377
|
}
|
|
3106
|
-
function
|
|
3107
|
-
|
|
3108
|
-
return meta?.subAgentId === token || meta?.groupId === token || runById.has(token);
|
|
4378
|
+
function str(value) {
|
|
4379
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
3109
4380
|
}
|
|
3110
|
-
function
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
const
|
|
3118
|
-
const
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
4381
|
+
function num(value) {
|
|
4382
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
4383
|
+
}
|
|
4384
|
+
function deriveRun(file, mtimeMs, events) {
|
|
4385
|
+
const started = events.find((e) => e.event === "run_started");
|
|
4386
|
+
if (!started || started.event !== "run_started") return null;
|
|
4387
|
+
const completed = events.find((e) => e.event === "run_completed");
|
|
4388
|
+
const metadata = started.metadata ?? {};
|
|
4389
|
+
const run = {
|
|
4390
|
+
runId: started.runId,
|
|
4391
|
+
file,
|
|
4392
|
+
mtimeMs,
|
|
4393
|
+
name: str(started.name),
|
|
4394
|
+
status: completed && completed.event === "run_completed" ? completed.status : null,
|
|
4395
|
+
startedAt: num(started.startTime),
|
|
4396
|
+
endedAt: completed && completed.event === "run_completed" ? num(completed.endTime) : null,
|
|
4397
|
+
durationMs: completed && completed.event === "run_completed" ? num(completed.durationMs) : null,
|
|
4398
|
+
sessionId: str(metadata.sessionId),
|
|
4399
|
+
groupId: str(metadata.groupId),
|
|
4400
|
+
correlationId: str(metadata.correlationId)
|
|
4401
|
+
};
|
|
4402
|
+
const stepStarts = /* @__PURE__ */ new Map();
|
|
4403
|
+
const steps = [];
|
|
4404
|
+
const errors = [];
|
|
4405
|
+
if (completed && completed.event === "run_completed" && completed.error) {
|
|
4406
|
+
errors.push({
|
|
4407
|
+
stepId: null,
|
|
4408
|
+
message: str(completed.error.message),
|
|
4409
|
+
code: str(completed.error.code)
|
|
3123
4410
|
});
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
4411
|
+
}
|
|
4412
|
+
for (const event of events) {
|
|
4413
|
+
if (event.event === "step_started") {
|
|
4414
|
+
stepStarts.set(event.stepId, event);
|
|
3127
4415
|
}
|
|
3128
|
-
const bucket = sessionsByKey.get(key) ?? [];
|
|
3129
|
-
bucket.push(run);
|
|
3130
|
-
sessionsByKey.set(key, bucket);
|
|
3131
4416
|
}
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
const
|
|
3135
|
-
const
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
4417
|
+
for (const event of events) {
|
|
4418
|
+
if (event.event !== "step_completed") continue;
|
|
4419
|
+
const start = stepStarts.get(event.stepId);
|
|
4420
|
+
const meta2 = start?.metadata ?? {};
|
|
4421
|
+
steps.push({
|
|
4422
|
+
runId: run.runId,
|
|
4423
|
+
stepId: event.stepId,
|
|
4424
|
+
kind: start ? str(start.type) : null,
|
|
4425
|
+
name: start ? str(start.name) : null,
|
|
4426
|
+
status: event.status,
|
|
4427
|
+
durationMs: num(event.durationMs),
|
|
4428
|
+
toolName: str(meta2.toolName),
|
|
4429
|
+
model: str(meta2.model),
|
|
4430
|
+
parentId: start ? str(start.parentId) : null
|
|
4431
|
+
});
|
|
4432
|
+
if (event.error) {
|
|
4433
|
+
errors.push({
|
|
4434
|
+
stepId: event.stepId,
|
|
4435
|
+
message: str(event.error.message),
|
|
4436
|
+
code: str(event.error.code)
|
|
3144
4437
|
});
|
|
3145
4438
|
}
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
});
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
4439
|
+
}
|
|
4440
|
+
return { run, steps, errors };
|
|
4441
|
+
}
|
|
4442
|
+
async function buildIndex(options = {}) {
|
|
4443
|
+
const traceDir = resolveTraceDir({ dir: options.traceDir });
|
|
4444
|
+
const dbPath = resolveIndexDbPath(traceDir, options.dbPath);
|
|
4445
|
+
const maxRuns = options.maxRuns ?? DEFAULT_MAX_RUNS;
|
|
4446
|
+
const warnings = [];
|
|
4447
|
+
const td = new TraceDirectory({ dir: traceDir });
|
|
4448
|
+
const files = await td.list();
|
|
4449
|
+
if (files.length > maxRuns) {
|
|
4450
|
+
warnings.push(
|
|
4451
|
+
`index.truncated: ${files.length} trace files present; indexing first ${maxRuns}`
|
|
4452
|
+
);
|
|
4453
|
+
}
|
|
4454
|
+
const slice = files.slice(0, maxRuns);
|
|
4455
|
+
const derived = [];
|
|
4456
|
+
for (const file of slice) {
|
|
4457
|
+
try {
|
|
4458
|
+
const raw = await promises.readFile(td.getPath(file), "utf-8");
|
|
4459
|
+
const parsed = parseTraceJsonl(raw, { validate: validateEvent });
|
|
4460
|
+
const stats = await td.getFileStats(file);
|
|
4461
|
+
const one = deriveRun(file, stats.mtimeMs, parsed.events);
|
|
4462
|
+
if (one) derived.push(one);
|
|
4463
|
+
else warnings.push(`index.skipped: ${file} has no run_started event`);
|
|
4464
|
+
} catch {
|
|
4465
|
+
warnings.push(`index.unreadable: ${file}`);
|
|
4466
|
+
}
|
|
4467
|
+
}
|
|
4468
|
+
await promises.mkdir(path14__default.default.dirname(dbPath), { recursive: true });
|
|
4469
|
+
await promises.rm(dbPath, { force: true });
|
|
4470
|
+
const db = new import_better_sqlite3.default(dbPath);
|
|
4471
|
+
let runCount = 0;
|
|
4472
|
+
let stepCount = 0;
|
|
4473
|
+
let errorCount = 0;
|
|
4474
|
+
try {
|
|
4475
|
+
db.pragma("journal_mode = WAL");
|
|
4476
|
+
db.exec(INDEX_SCHEMA_SQL);
|
|
4477
|
+
const insertRun = db.prepare(
|
|
4478
|
+
`INSERT INTO runs (run_id, file, mtime_ms, name, status, started_at, ended_at, duration_ms, session_id, group_id, correlation_id)
|
|
4479
|
+
VALUES (@runId, @file, @mtimeMs, @name, @status, @startedAt, @endedAt, @durationMs, @sessionId, @groupId, @correlationId)`
|
|
4480
|
+
);
|
|
4481
|
+
const insertStep = db.prepare(
|
|
4482
|
+
`INSERT INTO steps (run_id, step_id, kind, name, status, duration_ms, tool_name, model, parent_id)
|
|
4483
|
+
VALUES (@runId, @stepId, @kind, @name, @status, @durationMs, @toolName, @model, @parentId)`
|
|
4484
|
+
);
|
|
4485
|
+
const insertError = db.prepare(
|
|
4486
|
+
`INSERT INTO errors (run_id, step_id, message, code) VALUES (@runId, @stepId, @message, @code)`
|
|
4487
|
+
);
|
|
4488
|
+
const insertMeta = db.prepare(`INSERT INTO meta (key, value) VALUES (?, ?)`);
|
|
4489
|
+
const write = db.transaction((items) => {
|
|
4490
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4491
|
+
for (const item of items) {
|
|
4492
|
+
if (seen.has(item.run.runId)) continue;
|
|
4493
|
+
seen.add(item.run.runId);
|
|
4494
|
+
insertRun.run(item.run);
|
|
4495
|
+
runCount += 1;
|
|
4496
|
+
for (const step of item.steps) {
|
|
4497
|
+
insertStep.run(step);
|
|
4498
|
+
stepCount += 1;
|
|
4499
|
+
}
|
|
4500
|
+
for (const err of item.errors) {
|
|
4501
|
+
insertError.run({ runId: item.run.runId, ...err });
|
|
4502
|
+
errorCount += 1;
|
|
4503
|
+
}
|
|
4504
|
+
}
|
|
4505
|
+
db.exec(DERIVE_SESSIONS_SQL);
|
|
4506
|
+
for (const [key, value] of Object.entries(metaDefaults(traceDir, slice.length))) {
|
|
4507
|
+
insertMeta.run(key, value);
|
|
4508
|
+
}
|
|
3159
4509
|
});
|
|
4510
|
+
write(derived);
|
|
4511
|
+
} finally {
|
|
4512
|
+
db.close();
|
|
3160
4513
|
}
|
|
3161
|
-
|
|
3162
|
-
const code = a.code.localeCompare(b.code);
|
|
3163
|
-
if (code !== 0) return code;
|
|
3164
|
-
return (a.runId ?? "").localeCompare(b.runId ?? "");
|
|
3165
|
-
});
|
|
4514
|
+
const builtAtRow = readMetaValue(dbPath, META_KEYS.builtAt);
|
|
3166
4515
|
return {
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
4516
|
+
dbPath,
|
|
4517
|
+
traceDir,
|
|
4518
|
+
runs: runCount,
|
|
4519
|
+
steps: stepCount,
|
|
4520
|
+
errors: errorCount,
|
|
4521
|
+
builtAt: builtAtRow ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
3170
4522
|
warnings
|
|
3171
4523
|
};
|
|
3172
4524
|
}
|
|
3173
|
-
|
|
3174
|
-
"run_started",
|
|
3175
|
-
"run_completed",
|
|
3176
|
-
"step_started",
|
|
3177
|
-
"step_completed"
|
|
3178
|
-
]);
|
|
3179
|
-
function isRecord6(value) {
|
|
3180
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3181
|
-
}
|
|
3182
|
-
function safeParse(line) {
|
|
4525
|
+
function readMetaValue(dbPath, key) {
|
|
3183
4526
|
try {
|
|
3184
|
-
|
|
4527
|
+
const db = new import_better_sqlite3.default(dbPath, { readonly: true, fileMustExist: true });
|
|
4528
|
+
try {
|
|
4529
|
+
const row = db.prepare(`SELECT value FROM meta WHERE key = ?`).get(key);
|
|
4530
|
+
return row?.value ?? null;
|
|
4531
|
+
} finally {
|
|
4532
|
+
db.close();
|
|
4533
|
+
}
|
|
3185
4534
|
} catch {
|
|
3186
|
-
return
|
|
4535
|
+
return null;
|
|
3187
4536
|
}
|
|
3188
4537
|
}
|
|
3189
|
-
async function
|
|
4538
|
+
async function cleanIndex(dbPath) {
|
|
4539
|
+
await promises.rm(dbPath, { force: true });
|
|
4540
|
+
await promises.rm(`${dbPath}-wal`, { force: true });
|
|
4541
|
+
await promises.rm(`${dbPath}-shm`, { force: true });
|
|
4542
|
+
}
|
|
4543
|
+
var import_better_sqlite3, DEFAULT_MAX_RUNS, rebuildIndex;
|
|
4544
|
+
var init_builder = __esm({
|
|
4545
|
+
"packages/index-sqlite/src/builder.ts"() {
|
|
4546
|
+
import_better_sqlite3 = __toESM(require_lib());
|
|
4547
|
+
init_advanced();
|
|
4548
|
+
init_schema();
|
|
4549
|
+
init_types3();
|
|
4550
|
+
DEFAULT_MAX_RUNS = 1e4;
|
|
4551
|
+
rebuildIndex = buildIndex;
|
|
4552
|
+
}
|
|
4553
|
+
});
|
|
4554
|
+
function openHealthy(dbPath) {
|
|
4555
|
+
if (!fs.existsSync(dbPath)) return null;
|
|
3190
4556
|
try {
|
|
3191
|
-
const
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
const trimmed = line.trim();
|
|
3198
|
-
if (trimmed === "") continue;
|
|
3199
|
-
const parsed = safeParse(trimmed);
|
|
3200
|
-
if (!parsed) continue;
|
|
3201
|
-
if (!isRecord6(parsed)) continue;
|
|
3202
|
-
checked += 1;
|
|
3203
|
-
if (isTraceEvent(parsed)) return true;
|
|
3204
|
-
const ev = parsed.event;
|
|
3205
|
-
const runId = parsed.runId;
|
|
3206
|
-
if (typeof ev === "string" && KNOWN_EVENTS.has(ev) && typeof runId === "string") {
|
|
3207
|
-
return true;
|
|
4557
|
+
const db = new import_better_sqlite32.default(dbPath, { readonly: true, fileMustExist: true });
|
|
4558
|
+
try {
|
|
4559
|
+
const result = db.pragma("integrity_check", { simple: true });
|
|
4560
|
+
if (result !== "ok") {
|
|
4561
|
+
db.close();
|
|
4562
|
+
return null;
|
|
3208
4563
|
}
|
|
3209
|
-
|
|
4564
|
+
db.prepare(`SELECT 1 FROM meta LIMIT 1`).get();
|
|
4565
|
+
db.prepare(`SELECT 1 FROM runs LIMIT 1`).get();
|
|
4566
|
+
return { db, healthy: true };
|
|
4567
|
+
} catch {
|
|
4568
|
+
db.close();
|
|
4569
|
+
return null;
|
|
3210
4570
|
}
|
|
3211
|
-
return false;
|
|
3212
4571
|
} catch {
|
|
3213
|
-
return
|
|
4572
|
+
return null;
|
|
4573
|
+
}
|
|
4574
|
+
}
|
|
4575
|
+
function meta(db, key) {
|
|
4576
|
+
const row = db.prepare(`SELECT value FROM meta WHERE key = ?`).get(key);
|
|
4577
|
+
return row?.value ?? null;
|
|
4578
|
+
}
|
|
4579
|
+
function indexStatus(dbPath) {
|
|
4580
|
+
const opened = openHealthy(dbPath);
|
|
4581
|
+
if (!opened) {
|
|
4582
|
+
return {
|
|
4583
|
+
dbPath,
|
|
4584
|
+
exists: fs.existsSync(dbPath),
|
|
4585
|
+
healthy: false,
|
|
4586
|
+
builtAt: null,
|
|
4587
|
+
sourceDir: null,
|
|
4588
|
+
schemaVersion: null,
|
|
4589
|
+
runs: 0,
|
|
4590
|
+
steps: 0
|
|
4591
|
+
};
|
|
4592
|
+
}
|
|
4593
|
+
const { db } = opened;
|
|
4594
|
+
try {
|
|
4595
|
+
const runs = db.prepare(`SELECT COUNT(*) AS c FROM runs`).get().c;
|
|
4596
|
+
const steps = db.prepare(`SELECT COUNT(*) AS c FROM steps`).get().c;
|
|
4597
|
+
return {
|
|
4598
|
+
dbPath,
|
|
4599
|
+
exists: true,
|
|
4600
|
+
healthy: true,
|
|
4601
|
+
builtAt: meta(db, META_KEYS.builtAt),
|
|
4602
|
+
sourceDir: meta(db, META_KEYS.sourceDir),
|
|
4603
|
+
schemaVersion: meta(db, META_KEYS.schemaVersion),
|
|
4604
|
+
runs,
|
|
4605
|
+
steps
|
|
4606
|
+
};
|
|
4607
|
+
} finally {
|
|
4608
|
+
db.close();
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
function isIndexStale(dbPath, newestTraceMtimeMs2) {
|
|
4612
|
+
const opened = openHealthy(dbPath);
|
|
4613
|
+
if (!opened) return true;
|
|
4614
|
+
try {
|
|
4615
|
+
const builtAt = meta(opened.db, META_KEYS.builtAt);
|
|
4616
|
+
if (!builtAt) return true;
|
|
4617
|
+
const builtMs = Date.parse(builtAt);
|
|
4618
|
+
if (Number.isNaN(builtMs)) return true;
|
|
4619
|
+
return newestTraceMtimeMs2 > builtMs;
|
|
4620
|
+
} finally {
|
|
4621
|
+
opened.db.close();
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
function mapRow(row) {
|
|
4625
|
+
return {
|
|
4626
|
+
runId: row.run_id,
|
|
4627
|
+
file: row.file,
|
|
4628
|
+
mtimeMs: row.mtime_ms,
|
|
4629
|
+
name: row.name ?? null,
|
|
4630
|
+
status: row.status ?? null,
|
|
4631
|
+
startedAt: row.started_at ?? null,
|
|
4632
|
+
endedAt: row.ended_at ?? null,
|
|
4633
|
+
durationMs: row.duration_ms ?? null,
|
|
4634
|
+
sessionId: row.session_id ?? null,
|
|
4635
|
+
groupId: row.group_id ?? null,
|
|
4636
|
+
correlationId: row.correlation_id ?? null
|
|
4637
|
+
};
|
|
4638
|
+
}
|
|
4639
|
+
function queryRuns(dbPath, query = {}) {
|
|
4640
|
+
const opened = openHealthy(dbPath);
|
|
4641
|
+
if (!opened) return [];
|
|
4642
|
+
const { db } = opened;
|
|
4643
|
+
try {
|
|
4644
|
+
const where = [];
|
|
4645
|
+
const params = {};
|
|
4646
|
+
if (query.status) {
|
|
4647
|
+
where.push(`r.status = @status`);
|
|
4648
|
+
params.status = query.status;
|
|
4649
|
+
}
|
|
4650
|
+
if (query.sessionId) {
|
|
4651
|
+
where.push(`r.session_id = @sessionId`);
|
|
4652
|
+
params.sessionId = query.sessionId;
|
|
4653
|
+
}
|
|
4654
|
+
if (query.name) {
|
|
4655
|
+
where.push(`LOWER(r.name) LIKE @name`);
|
|
4656
|
+
params.name = `%${query.name.toLowerCase()}%`;
|
|
4657
|
+
}
|
|
4658
|
+
if (query.kind) {
|
|
4659
|
+
where.push(`EXISTS (SELECT 1 FROM steps s WHERE s.run_id = r.run_id AND s.kind = @kind)`);
|
|
4660
|
+
params.kind = query.kind;
|
|
4661
|
+
}
|
|
4662
|
+
if (query.tool) {
|
|
4663
|
+
where.push(
|
|
4664
|
+
`EXISTS (SELECT 1 FROM steps s WHERE s.run_id = r.run_id AND LOWER(s.tool_name) LIKE @tool)`
|
|
4665
|
+
);
|
|
4666
|
+
params.tool = `%${query.tool.toLowerCase()}%`;
|
|
4667
|
+
}
|
|
4668
|
+
const limit = Number.isInteger(query.limit) && query.limit > 0 ? query.limit : 100;
|
|
4669
|
+
const sql = `SELECT r.* FROM runs r ${where.length ? `WHERE ${where.join(" AND ")}` : ""} ORDER BY r.started_at DESC LIMIT ${limit}`;
|
|
4670
|
+
const rows = db.prepare(sql).all(params);
|
|
4671
|
+
return rows.map(mapRow);
|
|
4672
|
+
} finally {
|
|
4673
|
+
db.close();
|
|
3214
4674
|
}
|
|
3215
4675
|
}
|
|
4676
|
+
var import_better_sqlite32;
|
|
4677
|
+
var init_query = __esm({
|
|
4678
|
+
"packages/index-sqlite/src/query.ts"() {
|
|
4679
|
+
import_better_sqlite32 = __toESM(require_lib());
|
|
4680
|
+
init_schema();
|
|
4681
|
+
}
|
|
4682
|
+
});
|
|
4683
|
+
|
|
4684
|
+
// packages/index-sqlite/src/index.ts
|
|
4685
|
+
var src_exports = {};
|
|
4686
|
+
__export(src_exports, {
|
|
4687
|
+
INDEX_DB_FILENAME: () => INDEX_DB_FILENAME,
|
|
4688
|
+
INDEX_SCHEMA_VERSION: () => INDEX_SCHEMA_VERSION,
|
|
4689
|
+
buildIndex: () => buildIndex,
|
|
4690
|
+
cleanIndex: () => cleanIndex,
|
|
4691
|
+
indexStatus: () => indexStatus,
|
|
4692
|
+
isIndexStale: () => isIndexStale,
|
|
4693
|
+
queryRuns: () => queryRuns,
|
|
4694
|
+
rebuildIndex: () => rebuildIndex,
|
|
4695
|
+
resolveIndexDbPath: () => resolveIndexDbPath
|
|
4696
|
+
});
|
|
4697
|
+
var init_src = __esm({
|
|
4698
|
+
"packages/index-sqlite/src/index.ts"() {
|
|
4699
|
+
init_types3();
|
|
4700
|
+
init_builder();
|
|
4701
|
+
init_query();
|
|
4702
|
+
}
|
|
4703
|
+
});
|
|
4704
|
+
|
|
4705
|
+
// package.json
|
|
4706
|
+
var version = "4.1.0";
|
|
4707
|
+
|
|
4708
|
+
// packages/cli/src/list.ts
|
|
4709
|
+
init_advanced();
|
|
3216
4710
|
|
|
3217
4711
|
// packages/cli/src/trace-dir-scale.ts
|
|
3218
4712
|
var TRACE_COUNT_WARN = 1e3;
|
|
@@ -3319,8 +4813,8 @@ async function list(options = {}) {
|
|
|
3319
4813
|
for (const fileName of files) {
|
|
3320
4814
|
try {
|
|
3321
4815
|
const filePath = td.getPath(fileName);
|
|
3322
|
-
const
|
|
3323
|
-
metas.push(
|
|
4816
|
+
const meta2 = await extractMetadata(filePath);
|
|
4817
|
+
metas.push(meta2);
|
|
3324
4818
|
} catch {
|
|
3325
4819
|
}
|
|
3326
4820
|
}
|
|
@@ -3361,6 +4855,9 @@ async function list(options = {}) {
|
|
|
3361
4855
|
process.exitCode = 1;
|
|
3362
4856
|
}
|
|
3363
4857
|
}
|
|
4858
|
+
|
|
4859
|
+
// packages/cli/src/clean.ts
|
|
4860
|
+
init_advanced();
|
|
3364
4861
|
function parseKeep(raw) {
|
|
3365
4862
|
const trimmed = typeof raw === "string" ? raw.trim() : "";
|
|
3366
4863
|
if (trimmed === "") {
|
|
@@ -3372,9 +4869,9 @@ function parseKeep(raw) {
|
|
|
3372
4869
|
}
|
|
3373
4870
|
return n;
|
|
3374
4871
|
}
|
|
3375
|
-
function basisTimeMs(
|
|
3376
|
-
const started = typeof
|
|
3377
|
-
const t = started ??
|
|
4872
|
+
function basisTimeMs(meta2) {
|
|
4873
|
+
const started = typeof meta2.startedAt === "number" ? meta2.startedAt : void 0;
|
|
4874
|
+
const t = started ?? meta2.createdAt.getTime();
|
|
3378
4875
|
return Number.isFinite(t) ? t : 0;
|
|
3379
4876
|
}
|
|
3380
4877
|
function stableSortNewestFirst(a, b) {
|
|
@@ -3516,6 +5013,18 @@ async function clean(options = {}) {
|
|
|
3516
5013
|
}
|
|
3517
5014
|
}
|
|
3518
5015
|
|
|
5016
|
+
// packages/cli/src/view.ts
|
|
5017
|
+
init_advanced();
|
|
5018
|
+
|
|
5019
|
+
// packages/cli/src/read-run.ts
|
|
5020
|
+
init_advanced();
|
|
5021
|
+
|
|
5022
|
+
// packages/core/src/entries/persisted.ts
|
|
5023
|
+
init_persisted_inspect_event();
|
|
5024
|
+
|
|
5025
|
+
// packages/core/src/persisted/from-trace-event.ts
|
|
5026
|
+
init_correlation_metadata();
|
|
5027
|
+
|
|
3519
5028
|
// packages/core/src/persisted/token-usage.ts
|
|
3520
5029
|
function isRecord7(value) {
|
|
3521
5030
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -3750,6 +5259,7 @@ function traceEventsToPersistedInspectEvents(events, options) {
|
|
|
3750
5259
|
}
|
|
3751
5260
|
|
|
3752
5261
|
// packages/core/src/persisted/to-inspect-event.ts
|
|
5262
|
+
init_persisted_inspect_event();
|
|
3753
5263
|
function compactAttributes2(entries) {
|
|
3754
5264
|
const out = {};
|
|
3755
5265
|
for (const [key, value] of Object.entries(entries)) {
|
|
@@ -3887,6 +5397,9 @@ function persistedInspectEventsToInspectEvents(events, options) {
|
|
|
3887
5397
|
return out;
|
|
3888
5398
|
}
|
|
3889
5399
|
|
|
5400
|
+
// packages/core/src/entries/persisted.ts
|
|
5401
|
+
init_to_trace_event();
|
|
5402
|
+
|
|
3890
5403
|
// packages/core/src/logs/tree-builder.ts
|
|
3891
5404
|
function inc(map, key) {
|
|
3892
5405
|
map[key] = (map[key] ?? 0) + 1;
|
|
@@ -3974,6 +5487,9 @@ function persistedInspectEventsToRunTrees(events, options) {
|
|
|
3974
5487
|
});
|
|
3975
5488
|
return new TreeBuilder().build(inspectEvents);
|
|
3976
5489
|
}
|
|
5490
|
+
|
|
5491
|
+
// packages/core/src/readers/index.ts
|
|
5492
|
+
init_read_trace();
|
|
3977
5493
|
var DEFAULT_MAX_TRACE_INPUT_BYTES = 10 * 1024 * 1024;
|
|
3978
5494
|
var MIN_DETECTION_CONFIDENCE = 0.5;
|
|
3979
5495
|
var AMBIGUOUS_CONFIDENCE_DELTA = 0.05;
|
|
@@ -5686,24 +7202,24 @@ function printSummary(summary) {
|
|
|
5686
7202
|
);
|
|
5687
7203
|
}
|
|
5688
7204
|
}
|
|
5689
|
-
function printMetadata(
|
|
7205
|
+
function printMetadata(meta2) {
|
|
5690
7206
|
console.log("Trace Metadata");
|
|
5691
|
-
console.log(`ID: ${
|
|
5692
|
-
console.log(`Name: ${
|
|
5693
|
-
console.log(`Status: ${
|
|
7207
|
+
console.log(`ID: ${meta2.runId}`);
|
|
7208
|
+
console.log(`Name: ${meta2.name ?? "unnamed"}`);
|
|
7209
|
+
console.log(`Status: ${meta2.status}`);
|
|
5694
7210
|
console.log(
|
|
5695
|
-
`Started: ${
|
|
7211
|
+
`Started: ${meta2.startedAt !== void 0 ? formatTimestamp(meta2.startedAt) : "-"}`
|
|
5696
7212
|
);
|
|
5697
7213
|
console.log(
|
|
5698
|
-
`Ended: ${
|
|
7214
|
+
`Ended: ${meta2.endedAt !== void 0 ? formatTimestamp(meta2.endedAt) : "-"}`
|
|
5699
7215
|
);
|
|
5700
7216
|
console.log(
|
|
5701
|
-
`Duration: ${
|
|
7217
|
+
`Duration: ${meta2.durationMs !== void 0 ? formatDuration2(meta2.durationMs) : "-"}`
|
|
5702
7218
|
);
|
|
5703
|
-
console.log(`Event count: ${
|
|
5704
|
-
console.log(`File path: ${
|
|
5705
|
-
console.log(`File size: ${
|
|
5706
|
-
console.log(`Created at: ${
|
|
7219
|
+
console.log(`Event count: ${meta2.eventCount}`);
|
|
7220
|
+
console.log(`File path: ${meta2.filePath}`);
|
|
7221
|
+
console.log(`File size: ${meta2.fileSize}`);
|
|
7222
|
+
console.log(`Created at: ${meta2.createdAt.toISOString()}`);
|
|
5707
7223
|
}
|
|
5708
7224
|
function filterErrorEvents(events) {
|
|
5709
7225
|
return events.filter((e) => {
|
|
@@ -5772,11 +7288,11 @@ async function view(runId, options = {}) {
|
|
|
5772
7288
|
return;
|
|
5773
7289
|
}
|
|
5774
7290
|
if (mode === "metadata") {
|
|
5775
|
-
const
|
|
7291
|
+
const meta2 = await extractMetadata(filePath);
|
|
5776
7292
|
if (options.json) {
|
|
5777
|
-
console.log(JSON.stringify(
|
|
7293
|
+
console.log(JSON.stringify(meta2, null, 2));
|
|
5778
7294
|
} else {
|
|
5779
|
-
printMetadata(
|
|
7295
|
+
printMetadata(meta2);
|
|
5780
7296
|
}
|
|
5781
7297
|
return;
|
|
5782
7298
|
}
|
|
@@ -6153,7 +7669,11 @@ function matchMapping(eventName, mappings) {
|
|
|
6153
7669
|
return bestKey ? mappings[bestKey] : void 0;
|
|
6154
7670
|
}
|
|
6155
7671
|
|
|
7672
|
+
// packages/core/src/entries/logs.ts
|
|
7673
|
+
init_redactor();
|
|
7674
|
+
|
|
6156
7675
|
// packages/core/src/logs/normalizer.ts
|
|
7676
|
+
init_nanoid();
|
|
6157
7677
|
function isFiniteNumber2(v) {
|
|
6158
7678
|
return typeof v === "number" && Number.isFinite(v);
|
|
6159
7679
|
}
|
|
@@ -6446,6 +7966,7 @@ function renderRunTree(tree, options) {
|
|
|
6446
7966
|
function renderRunTrees(trees, options) {
|
|
6447
7967
|
return trees.map((t) => renderRunTree(t, options)).join("\n\n");
|
|
6448
7968
|
}
|
|
7969
|
+
init_redactor();
|
|
6449
7970
|
|
|
6450
7971
|
// packages/core/src/logs/line-parser.ts
|
|
6451
7972
|
function shiftLineNumbers(res, options) {
|
|
@@ -6483,6 +8004,7 @@ function parseLogLine(line, options = {}) {
|
|
|
6483
8004
|
}
|
|
6484
8005
|
|
|
6485
8006
|
// packages/core/src/logs/live-tree.ts
|
|
8007
|
+
init_redactor();
|
|
6486
8008
|
var LiveLogAccumulator = class {
|
|
6487
8009
|
#config;
|
|
6488
8010
|
#format;
|
|
@@ -6936,10 +8458,15 @@ async function tail(options = {}) {
|
|
|
6936
8458
|
}
|
|
6937
8459
|
}
|
|
6938
8460
|
|
|
8461
|
+
// packages/cli/src/export.ts
|
|
8462
|
+
init_advanced();
|
|
8463
|
+
|
|
6939
8464
|
// packages/core/src/exporters/types.ts
|
|
6940
8465
|
var EXPORT_PAYLOAD_VERSION = "0.1.2";
|
|
6941
8466
|
|
|
6942
8467
|
// packages/core/src/exporters/redact-export.ts
|
|
8468
|
+
init_redactor();
|
|
8469
|
+
init_redaction_profiles();
|
|
6943
8470
|
function isRecord12(value) {
|
|
6944
8471
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6945
8472
|
}
|
|
@@ -7586,19 +9113,19 @@ function exportOpenInference(tree, options) {
|
|
|
7586
9113
|
if (ev.durationMs !== void 0) {
|
|
7587
9114
|
attrs["agent_inspect.duration_ms"] = ev.durationMs;
|
|
7588
9115
|
}
|
|
7589
|
-
const
|
|
7590
|
-
if (
|
|
7591
|
-
attrs["llm.model_name"] =
|
|
9116
|
+
const meta2 = ev.attributes;
|
|
9117
|
+
if (meta2?.model !== void 0 && typeof meta2.model === "string") {
|
|
9118
|
+
attrs["llm.model_name"] = meta2.model;
|
|
7592
9119
|
}
|
|
7593
|
-
const tokens =
|
|
9120
|
+
const tokens = meta2?.tokens;
|
|
7594
9121
|
if (tokens && typeof tokens === "object" && tokens !== null) {
|
|
7595
9122
|
const inp = tokens.input;
|
|
7596
9123
|
const outp = tokens.output;
|
|
7597
9124
|
if (typeof inp === "number") attrs["llm.token_count.prompt"] = inp;
|
|
7598
9125
|
if (typeof outp === "number") attrs["llm.token_count.completion"] = outp;
|
|
7599
9126
|
}
|
|
7600
|
-
if (includeAttributes &&
|
|
7601
|
-
for (const [k, v] of Object.entries(
|
|
9127
|
+
if (includeAttributes && meta2 && typeof meta2 === "object") {
|
|
9128
|
+
for (const [k, v] of Object.entries(meta2)) {
|
|
7602
9129
|
if (k === "tokens" || k === "model") continue;
|
|
7603
9130
|
if (v !== void 0 && v !== null && typeof v !== "object") {
|
|
7604
9131
|
attrs[`agent_inspect.preview.${k}`] = typeof v === "string" ? v.slice(0, maxLen) : v;
|
|
@@ -7607,7 +9134,7 @@ function exportOpenInference(tree, options) {
|
|
|
7607
9134
|
}
|
|
7608
9135
|
let status;
|
|
7609
9136
|
if (ev.status === "error") {
|
|
7610
|
-
const msg =
|
|
9137
|
+
const msg = meta2 && typeof meta2.error === "object" && meta2.error !== null ? String(meta2.error.message ?? "error") : "error";
|
|
7611
9138
|
status = { code: "ERROR", message: msg.slice(0, maxLen) };
|
|
7612
9139
|
} else if (ev.status === "ok") {
|
|
7613
9140
|
status = { code: "OK" };
|
|
@@ -7697,19 +9224,19 @@ function exportOtlpJson(tree, options) {
|
|
|
7697
9224
|
if (op !== void 0) {
|
|
7698
9225
|
attrs.push(stringAttr("gen_ai.operation.name", op));
|
|
7699
9226
|
}
|
|
7700
|
-
const
|
|
7701
|
-
if (
|
|
7702
|
-
attrs.push(stringAttr("gen_ai.request.model",
|
|
9227
|
+
const meta2 = ev.attributes;
|
|
9228
|
+
if (meta2?.model !== void 0 && typeof meta2.model === "string") {
|
|
9229
|
+
attrs.push(stringAttr("gen_ai.request.model", meta2.model.slice(0, maxLen)));
|
|
7703
9230
|
}
|
|
7704
|
-
const tokens =
|
|
9231
|
+
const tokens = meta2?.tokens;
|
|
7705
9232
|
if (tokens && typeof tokens === "object" && tokens !== null) {
|
|
7706
9233
|
const inp = tokens.input;
|
|
7707
9234
|
const outp = tokens.output;
|
|
7708
9235
|
if (typeof inp === "number") attrs.push(intAttr("gen_ai.usage.input_tokens", inp));
|
|
7709
9236
|
if (typeof outp === "number") attrs.push(intAttr("gen_ai.usage.output_tokens", outp));
|
|
7710
9237
|
}
|
|
7711
|
-
if (includeAttributes &&
|
|
7712
|
-
for (const [k, v] of Object.entries(
|
|
9238
|
+
if (includeAttributes && meta2 && typeof meta2 === "object") {
|
|
9239
|
+
for (const [k, v] of Object.entries(meta2)) {
|
|
7713
9240
|
if (k === "tokens" || k === "model") continue;
|
|
7714
9241
|
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
7715
9242
|
attrs.push(
|
|
@@ -7725,7 +9252,7 @@ function exportOtlpJson(tree, options) {
|
|
|
7725
9252
|
let statusMessage;
|
|
7726
9253
|
if (ev.status === "error") {
|
|
7727
9254
|
statusCode = "STATUS_CODE_ERROR";
|
|
7728
|
-
statusMessage =
|
|
9255
|
+
statusMessage = meta2 && typeof meta2.error === "object" && meta2.error !== null ? String(meta2.error.message ?? "error").slice(0, maxLen) : "error";
|
|
7729
9256
|
} else if (ev.status === "ok") {
|
|
7730
9257
|
statusCode = "STATUS_CODE_OK";
|
|
7731
9258
|
}
|
|
@@ -8024,6 +9551,8 @@ function validateExport(result) {
|
|
|
8024
9551
|
}
|
|
8025
9552
|
|
|
8026
9553
|
// packages/core/src/report.ts
|
|
9554
|
+
init_timeline();
|
|
9555
|
+
init_what();
|
|
8027
9556
|
function resolveTree(events, profile) {
|
|
8028
9557
|
const tree = manualTraceEventsToRunTree(events);
|
|
8029
9558
|
return profile === "local" ? tree : redactRunTreeForExport(tree, { redactionProfile: profile });
|
|
@@ -8265,11 +9794,14 @@ Trace directory: ${traceDir}`);
|
|
|
8265
9794
|
}
|
|
8266
9795
|
}
|
|
8267
9796
|
|
|
9797
|
+
// packages/cli/src/diff.ts
|
|
9798
|
+
init_advanced();
|
|
9799
|
+
|
|
8268
9800
|
// packages/core/src/diff/comparable.ts
|
|
8269
|
-
function extractOutputPreview(
|
|
8270
|
-
if (
|
|
8271
|
-
if ("outputPreview" in
|
|
8272
|
-
if ("resultPreview" in
|
|
9801
|
+
function extractOutputPreview(meta2) {
|
|
9802
|
+
if (meta2 === void 0) return void 0;
|
|
9803
|
+
if ("outputPreview" in meta2) return meta2.outputPreview;
|
|
9804
|
+
if ("resultPreview" in meta2) return meta2.resultPreview;
|
|
8273
9805
|
return void 0;
|
|
8274
9806
|
}
|
|
8275
9807
|
function mapStepStatus2(s) {
|
|
@@ -8294,7 +9826,7 @@ function manualTraceEventsToComparableRun(events) {
|
|
|
8294
9826
|
for (const e of events) {
|
|
8295
9827
|
if (e.event !== "step_started") continue;
|
|
8296
9828
|
const s = e;
|
|
8297
|
-
const
|
|
9829
|
+
const meta2 = s.metadata ? { ...s.metadata } : void 0;
|
|
8298
9830
|
steps.set(s.stepId, {
|
|
8299
9831
|
id: s.stepId,
|
|
8300
9832
|
parentId: s.parentId,
|
|
@@ -8302,7 +9834,7 @@ function manualTraceEventsToComparableRun(events) {
|
|
|
8302
9834
|
type: s.type,
|
|
8303
9835
|
order: order++,
|
|
8304
9836
|
timestamp: s.timestamp,
|
|
8305
|
-
metadata:
|
|
9837
|
+
metadata: meta2
|
|
8306
9838
|
});
|
|
8307
9839
|
}
|
|
8308
9840
|
for (const e of events) {
|
|
@@ -8319,11 +9851,11 @@ function manualTraceEventsToComparableRun(events) {
|
|
|
8319
9851
|
}
|
|
8320
9852
|
const nodes = /* @__PURE__ */ new Map();
|
|
8321
9853
|
for (const acc of steps.values()) {
|
|
8322
|
-
let
|
|
9854
|
+
let meta2 = acc.metadata ? { ...acc.metadata } : void 0;
|
|
8323
9855
|
if (acc.parentId !== void 0 && !steps.has(acc.parentId)) {
|
|
8324
|
-
|
|
9856
|
+
meta2 = { ...meta2 ?? {}, agent_inspect_diff_parent_missing: true };
|
|
8325
9857
|
}
|
|
8326
|
-
const outputPreview = extractOutputPreview(
|
|
9858
|
+
const outputPreview = extractOutputPreview(meta2);
|
|
8327
9859
|
const sc = {
|
|
8328
9860
|
id: acc.id,
|
|
8329
9861
|
name: acc.name,
|
|
@@ -8331,7 +9863,7 @@ function manualTraceEventsToComparableRun(events) {
|
|
|
8331
9863
|
status: mapStepStatus2(acc.status),
|
|
8332
9864
|
durationMs: acc.durationMs,
|
|
8333
9865
|
error: acc.errorMsg,
|
|
8334
|
-
metadata:
|
|
9866
|
+
metadata: meta2 && Object.keys(meta2).length > 0 ? meta2 : void 0,
|
|
8335
9867
|
outputPreview,
|
|
8336
9868
|
children: []
|
|
8337
9869
|
};
|
|
@@ -8404,13 +9936,13 @@ function pairSteps(left, right) {
|
|
|
8404
9936
|
return pairs;
|
|
8405
9937
|
}
|
|
8406
9938
|
function compareLeafSteps(L, R, segments, opts, out) {
|
|
8407
|
-
const
|
|
9939
|
+
const path22 = buildPath(segments);
|
|
8408
9940
|
if (L.name !== R.name) {
|
|
8409
9941
|
out.push({
|
|
8410
9942
|
kind: "structure",
|
|
8411
9943
|
severity: "warning",
|
|
8412
9944
|
message: "Step name differs",
|
|
8413
|
-
path:
|
|
9945
|
+
path: path22,
|
|
8414
9946
|
left: L.name,
|
|
8415
9947
|
right: R.name
|
|
8416
9948
|
});
|
|
@@ -8420,7 +9952,7 @@ function compareLeafSteps(L, R, segments, opts, out) {
|
|
|
8420
9952
|
kind: "step-type",
|
|
8421
9953
|
severity: "warning",
|
|
8422
9954
|
message: "Step type differs",
|
|
8423
|
-
path:
|
|
9955
|
+
path: path22,
|
|
8424
9956
|
left: L.type,
|
|
8425
9957
|
right: R.type
|
|
8426
9958
|
});
|
|
@@ -8430,7 +9962,7 @@ function compareLeafSteps(L, R, segments, opts, out) {
|
|
|
8430
9962
|
kind: "step-status",
|
|
8431
9963
|
severity: "warning",
|
|
8432
9964
|
message: "Step status differs",
|
|
8433
|
-
path:
|
|
9965
|
+
path: path22,
|
|
8434
9966
|
left: L.status,
|
|
8435
9967
|
right: R.status
|
|
8436
9968
|
});
|
|
@@ -8442,7 +9974,7 @@ function compareLeafSteps(L, R, segments, opts, out) {
|
|
|
8442
9974
|
kind: "error",
|
|
8443
9975
|
severity: "error",
|
|
8444
9976
|
message: "Step error message differs",
|
|
8445
|
-
path:
|
|
9977
|
+
path: path22,
|
|
8446
9978
|
left: le || void 0,
|
|
8447
9979
|
right: re || void 0
|
|
8448
9980
|
});
|
|
@@ -8460,20 +9992,20 @@ function compareLeafSteps(L, R, segments, opts, out) {
|
|
|
8460
9992
|
kind: "duration",
|
|
8461
9993
|
severity: "info",
|
|
8462
9994
|
message: "Step duration differs",
|
|
8463
|
-
path:
|
|
9995
|
+
path: path22,
|
|
8464
9996
|
left: ld,
|
|
8465
9997
|
right: rd
|
|
8466
9998
|
});
|
|
8467
9999
|
}
|
|
8468
10000
|
}
|
|
8469
10001
|
const lm = stableJson(L.metadata ?? {});
|
|
8470
|
-
const
|
|
8471
|
-
if (lm !==
|
|
10002
|
+
const rm4 = stableJson(R.metadata ?? {});
|
|
10003
|
+
if (lm !== rm4) {
|
|
8472
10004
|
out.push({
|
|
8473
10005
|
kind: "metadata",
|
|
8474
10006
|
severity: "info",
|
|
8475
10007
|
message: "Step metadata differs",
|
|
8476
|
-
path:
|
|
10008
|
+
path: path22,
|
|
8477
10009
|
left: L.metadata,
|
|
8478
10010
|
right: R.metadata
|
|
8479
10011
|
});
|
|
@@ -8485,7 +10017,7 @@ function compareLeafSteps(L, R, segments, opts, out) {
|
|
|
8485
10017
|
kind: "output",
|
|
8486
10018
|
severity: "info",
|
|
8487
10019
|
message: "Output preview differs",
|
|
8488
|
-
path:
|
|
10020
|
+
path: path22,
|
|
8489
10021
|
left: L.outputPreview,
|
|
8490
10022
|
right: R.outputPreview
|
|
8491
10023
|
});
|
|
@@ -8645,11 +10177,12 @@ function diffRuns(left, right, options) {
|
|
|
8645
10177
|
}
|
|
8646
10178
|
|
|
8647
10179
|
// packages/core/src/diff/renderer.ts
|
|
8648
|
-
|
|
8649
|
-
|
|
10180
|
+
init_source();
|
|
10181
|
+
function formatPath(path22) {
|
|
10182
|
+
if (path22 === void 0 || path22.path.length === 0) {
|
|
8650
10183
|
return "(run)";
|
|
8651
10184
|
}
|
|
8652
|
-
return
|
|
10185
|
+
return path22.path.map((s) => s.name).join(" > ");
|
|
8653
10186
|
}
|
|
8654
10187
|
function formatValue(v, verbose) {
|
|
8655
10188
|
if (v === void 0) return "(undefined)";
|
|
@@ -8831,6 +10364,7 @@ Trace directory: ${traceDir}`
|
|
|
8831
10364
|
}
|
|
8832
10365
|
|
|
8833
10366
|
// packages/cli/src/timeline.ts
|
|
10367
|
+
init_advanced();
|
|
8834
10368
|
async function timelineCommand(runId, options = {}) {
|
|
8835
10369
|
const id = typeof runId === "string" && runId.trim() !== "" ? runId.trim() : "";
|
|
8836
10370
|
if (id === "") {
|
|
@@ -8867,6 +10401,7 @@ async function timelineCommand(runId, options = {}) {
|
|
|
8867
10401
|
}
|
|
8868
10402
|
|
|
8869
10403
|
// packages/cli/src/stats.ts
|
|
10404
|
+
init_advanced();
|
|
8870
10405
|
async function statsCommand(options = {}) {
|
|
8871
10406
|
try {
|
|
8872
10407
|
const traceDir = resolveTraceDir({ dir: options.dir });
|
|
@@ -8930,6 +10465,7 @@ async function statsCommand(options = {}) {
|
|
|
8930
10465
|
}
|
|
8931
10466
|
|
|
8932
10467
|
// packages/cli/src/search.ts
|
|
10468
|
+
init_advanced();
|
|
8933
10469
|
function parseLimit2(raw) {
|
|
8934
10470
|
if (raw === void 0 || raw.trim() === "") return 50;
|
|
8935
10471
|
const n = Number.parseInt(raw, 10);
|
|
@@ -9013,6 +10549,7 @@ async function searchCommand(options = {}) {
|
|
|
9013
10549
|
}
|
|
9014
10550
|
|
|
9015
10551
|
// packages/cli/src/sessions.ts
|
|
10552
|
+
init_advanced();
|
|
9016
10553
|
async function loadSessionIndex(traceDir, correlateGroup) {
|
|
9017
10554
|
const td = new TraceDirectory({ dir: traceDir });
|
|
9018
10555
|
const files = await td.list();
|
|
@@ -9191,6 +10728,7 @@ async function sessionCommand(sessionId, options = {}) {
|
|
|
9191
10728
|
}
|
|
9192
10729
|
|
|
9193
10730
|
// packages/cli/src/what.ts
|
|
10731
|
+
init_advanced();
|
|
9194
10732
|
async function whatCommand(runId, options = {}) {
|
|
9195
10733
|
const id = typeof runId === "string" && runId.trim() !== "" ? runId.trim() : "";
|
|
9196
10734
|
if (id === "") {
|
|
@@ -9222,6 +10760,9 @@ async function whatCommand(runId, options = {}) {
|
|
|
9222
10760
|
}
|
|
9223
10761
|
console.log(renderRunWhat(summary, { correlation: !options.noCorrelation }));
|
|
9224
10762
|
}
|
|
10763
|
+
|
|
10764
|
+
// packages/cli/src/report.ts
|
|
10765
|
+
init_advanced();
|
|
9225
10766
|
function parseReportFormat(s) {
|
|
9226
10767
|
const v = (s ?? "markdown").trim().toLowerCase();
|
|
9227
10768
|
if (v === "markdown" || v === "html") {
|
|
@@ -9304,6 +10845,9 @@ async function reportCommand(runId, options = {}) {
|
|
|
9304
10845
|
console.log(result.content);
|
|
9305
10846
|
}
|
|
9306
10847
|
}
|
|
10848
|
+
|
|
10849
|
+
// packages/cli/src/redact.ts
|
|
10850
|
+
init_advanced();
|
|
9307
10851
|
var DEFAULT_REDACT_KEYS2 = [
|
|
9308
10852
|
"authorization",
|
|
9309
10853
|
"cookie",
|
|
@@ -9531,17 +11075,17 @@ function applyRule(rule, value, replacement) {
|
|
|
9531
11075
|
}
|
|
9532
11076
|
return value;
|
|
9533
11077
|
}
|
|
9534
|
-
function childPath(
|
|
11078
|
+
function childPath(path22, key) {
|
|
9535
11079
|
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key)) {
|
|
9536
|
-
return
|
|
11080
|
+
return path22 ? `${path22}.${key}` : key;
|
|
9537
11081
|
}
|
|
9538
|
-
return `${
|
|
11082
|
+
return `${path22 || "$"}[${JSON.stringify(key)}]`;
|
|
9539
11083
|
}
|
|
9540
|
-
function indexPath(
|
|
9541
|
-
return `${
|
|
11084
|
+
function indexPath(path22, index) {
|
|
11085
|
+
return `${path22 || "$"}[${index}]`;
|
|
9542
11086
|
}
|
|
9543
|
-
function makeFinding(
|
|
9544
|
-
return preview === void 0 ? { path:
|
|
11087
|
+
function makeFinding(path22, detector, action, matchKind, severity = "warning", preview) {
|
|
11088
|
+
return preview === void 0 ? { path: path22, detector, action, severity, matchKind } : { path: path22, detector, action, severity, matchKind, preview };
|
|
9545
11089
|
}
|
|
9546
11090
|
function createRedactionProfile(profile = "local") {
|
|
9547
11091
|
switch (profile) {
|
|
@@ -9610,11 +11154,11 @@ var Redactor2 = class {
|
|
|
9610
11154
|
#recordFinding(state, finding) {
|
|
9611
11155
|
if (this.#collectFindings) state.findings.push(finding);
|
|
9612
11156
|
}
|
|
9613
|
-
#redactValue(value, key,
|
|
11157
|
+
#redactValue(value, key, path22, depth, state) {
|
|
9614
11158
|
if (depth > this.#maxDepth) {
|
|
9615
11159
|
this.#recordFinding(
|
|
9616
11160
|
state,
|
|
9617
|
-
makeFinding(
|
|
11161
|
+
makeFinding(path22, "structure.maxDepth", "truncate", "value", "warning")
|
|
9618
11162
|
);
|
|
9619
11163
|
return "[Truncated]";
|
|
9620
11164
|
}
|
|
@@ -9623,19 +11167,19 @@ var Redactor2 = class {
|
|
|
9623
11167
|
if (rule) {
|
|
9624
11168
|
this.#recordFinding(
|
|
9625
11169
|
state,
|
|
9626
|
-
makeFinding(
|
|
11170
|
+
makeFinding(path22, `key.${rule.key}`, actionForRule(rule), "key", "warning")
|
|
9627
11171
|
);
|
|
9628
11172
|
return applyRule(rule, value, this.#replacement);
|
|
9629
11173
|
}
|
|
9630
11174
|
}
|
|
9631
11175
|
for (const detector of this.#detectors) {
|
|
9632
|
-
const detections = detector.detect({ path:
|
|
11176
|
+
const detections = detector.detect({ path: path22, key, value });
|
|
9633
11177
|
for (const detection of detections) {
|
|
9634
11178
|
const action = detection.action ?? "replace";
|
|
9635
11179
|
this.#recordFinding(
|
|
9636
11180
|
state,
|
|
9637
11181
|
makeFinding(
|
|
9638
|
-
|
|
11182
|
+
path22,
|
|
9639
11183
|
detector.id,
|
|
9640
11184
|
action,
|
|
9641
11185
|
detection.matchKind ?? detector.matchKind ?? "custom",
|
|
@@ -9653,7 +11197,7 @@ var Redactor2 = class {
|
|
|
9653
11197
|
const out = [];
|
|
9654
11198
|
state.seen.set(value, out);
|
|
9655
11199
|
value.forEach((item, index) => {
|
|
9656
|
-
out[index] = this.#redactValue(item, void 0, indexPath(
|
|
11200
|
+
out[index] = this.#redactValue(item, void 0, indexPath(path22, index), depth + 1, state);
|
|
9657
11201
|
});
|
|
9658
11202
|
return out;
|
|
9659
11203
|
}
|
|
@@ -9665,7 +11209,7 @@ var Redactor2 = class {
|
|
|
9665
11209
|
out[entryKey] = this.#redactValue(
|
|
9666
11210
|
entryValue,
|
|
9667
11211
|
entryKey,
|
|
9668
|
-
childPath(
|
|
11212
|
+
childPath(path22 === "$" ? "" : path22, entryKey),
|
|
9669
11213
|
depth + 1,
|
|
9670
11214
|
state
|
|
9671
11215
|
);
|
|
@@ -9681,6 +11225,9 @@ function createRedactor(options) {
|
|
|
9681
11225
|
function redact(value, options) {
|
|
9682
11226
|
return createRedactor(options).redact(value);
|
|
9683
11227
|
}
|
|
11228
|
+
|
|
11229
|
+
// packages/cli/src/trace-input.ts
|
|
11230
|
+
init_advanced();
|
|
9684
11231
|
async function readStdin(stdin) {
|
|
9685
11232
|
stdin.setEncoding("utf8");
|
|
9686
11233
|
let content = "";
|
|
@@ -9821,6 +11368,7 @@ async function redactCommand(target, options = {}, stdin = process.stdin) {
|
|
|
9821
11368
|
}
|
|
9822
11369
|
|
|
9823
11370
|
// packages/cli/src/explain.ts
|
|
11371
|
+
init_advanced();
|
|
9824
11372
|
function parseRedactionProfile4(value) {
|
|
9825
11373
|
const profile = (value ?? "local").trim().toLowerCase();
|
|
9826
11374
|
if (profile === "local" || profile === "share" || profile === "strict") {
|
|
@@ -9947,6 +11495,9 @@ async function explainCommand(target, options = {}, stdin = process.stdin) {
|
|
|
9947
11495
|
console.error(message);
|
|
9948
11496
|
}
|
|
9949
11497
|
}
|
|
11498
|
+
|
|
11499
|
+
// packages/cli/src/open.ts
|
|
11500
|
+
init_advanced();
|
|
9950
11501
|
async function readStdin2(stdin) {
|
|
9951
11502
|
stdin.setEncoding("utf8");
|
|
9952
11503
|
let content = "";
|
|
@@ -10090,6 +11641,9 @@ async function openCommand(input3, options = {}, stdin = process.stdin) {
|
|
|
10090
11641
|
}
|
|
10091
11642
|
}
|
|
10092
11643
|
}
|
|
11644
|
+
|
|
11645
|
+
// packages/cli/src/migrate.ts
|
|
11646
|
+
init_advanced();
|
|
10093
11647
|
function isRecord14(value) {
|
|
10094
11648
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10095
11649
|
}
|
|
@@ -10269,6 +11823,7 @@ async function migrateCommand(input3, options = {}) {
|
|
|
10269
11823
|
process.exitCode = 1;
|
|
10270
11824
|
}
|
|
10271
11825
|
}
|
|
11826
|
+
init_advanced();
|
|
10272
11827
|
|
|
10273
11828
|
// packages/core/src/checks/index.ts
|
|
10274
11829
|
var SEVERITY_RANK = {
|
|
@@ -10537,7 +12092,7 @@ function stripPrefix(name, prefixes) {
|
|
|
10537
12092
|
}
|
|
10538
12093
|
return name;
|
|
10539
12094
|
}
|
|
10540
|
-
function eventEvidence(event,
|
|
12095
|
+
function eventEvidence(event, path22) {
|
|
10541
12096
|
return {
|
|
10542
12097
|
runId: event.runId,
|
|
10543
12098
|
eventId: event.eventId,
|
|
@@ -10547,7 +12102,7 @@ function eventEvidence(event, path20) {
|
|
|
10547
12102
|
kind: event.kind,
|
|
10548
12103
|
name: event.name,
|
|
10549
12104
|
status: event.status,
|
|
10550
|
-
...
|
|
12105
|
+
...path22 ? { path: path22 } : {}
|
|
10551
12106
|
};
|
|
10552
12107
|
}
|
|
10553
12108
|
function runEvidence(run) {
|
|
@@ -10610,9 +12165,9 @@ function eventEndMs(event) {
|
|
|
10610
12165
|
function normalizedKey(value) {
|
|
10611
12166
|
return value.toLowerCase().replace(/[^a-z0-9_]/g, "");
|
|
10612
12167
|
}
|
|
10613
|
-
function lastPathSegment(
|
|
10614
|
-
const parts =
|
|
10615
|
-
return parts[parts.length - 1] ??
|
|
12168
|
+
function lastPathSegment(path22) {
|
|
12169
|
+
const parts = path22.split(".");
|
|
12170
|
+
return parts[parts.length - 1] ?? path22;
|
|
10616
12171
|
}
|
|
10617
12172
|
function valueType(value) {
|
|
10618
12173
|
if (Array.isArray(value)) return "array";
|
|
@@ -10626,12 +12181,12 @@ function serializedByteLength(value) {
|
|
|
10626
12181
|
return void 0;
|
|
10627
12182
|
}
|
|
10628
12183
|
}
|
|
10629
|
-
function pushValueEntries(entries, event, value,
|
|
10630
|
-
entries.push({ event, path:
|
|
12184
|
+
function pushValueEntries(entries, event, value, path22, key, depth = 0) {
|
|
12185
|
+
entries.push({ event, path: path22, key, value });
|
|
10631
12186
|
if (depth >= 8) return;
|
|
10632
12187
|
if (Array.isArray(value)) {
|
|
10633
12188
|
for (const [index, item] of value.entries()) {
|
|
10634
|
-
pushValueEntries(entries, event, item, `${
|
|
12189
|
+
pushValueEntries(entries, event, item, `${path22}.${index}`, String(index), depth + 1);
|
|
10635
12190
|
}
|
|
10636
12191
|
return;
|
|
10637
12192
|
}
|
|
@@ -10641,7 +12196,7 @@ function pushValueEntries(entries, event, value, path20, key, depth = 0) {
|
|
|
10641
12196
|
entries,
|
|
10642
12197
|
event,
|
|
10643
12198
|
value[nestedKey],
|
|
10644
|
-
`${
|
|
12199
|
+
`${path22}.${nestedKey}`,
|
|
10645
12200
|
nestedKey,
|
|
10646
12201
|
depth + 1
|
|
10647
12202
|
);
|
|
@@ -10722,9 +12277,9 @@ function eventDurationMs(event) {
|
|
|
10722
12277
|
}
|
|
10723
12278
|
function treeShape(nodes) {
|
|
10724
12279
|
const lines = [];
|
|
10725
|
-
const visit = (node,
|
|
10726
|
-
lines.push(`${
|
|
10727
|
-
node.children.forEach((child, index) => visit(child, `${
|
|
12280
|
+
const visit = (node, path22) => {
|
|
12281
|
+
lines.push(`${path22}:${node.event.kind}:${node.event.name}:${node.event.status ?? "unknown"}`);
|
|
12282
|
+
node.children.forEach((child, index) => visit(child, `${path22}.${index}`));
|
|
10728
12283
|
};
|
|
10729
12284
|
nodes.forEach((node, index) => visit(node, String(index)));
|
|
10730
12285
|
return lines;
|
|
@@ -10773,9 +12328,9 @@ function retrievalShape(context) {
|
|
|
10773
12328
|
function guardrailShape(context) {
|
|
10774
12329
|
return guardrailEvents(context).map((event) => signalName(event, ["guardrailName", "guardrail", "guardrailId"], ["guardrail:"])).sort((a, b) => a.localeCompare(b));
|
|
10775
12330
|
}
|
|
10776
|
-
function firstEvidenceForKind(context, kind,
|
|
12331
|
+
function firstEvidenceForKind(context, kind, path22) {
|
|
10777
12332
|
const event = context.events.find((candidate) => candidate.kind === kind);
|
|
10778
|
-
return event ? [eventEvidence(event,
|
|
12333
|
+
return event ? [eventEvidence(event, path22)] : runEvidence(context.selectedRun);
|
|
10779
12334
|
}
|
|
10780
12335
|
function baselineDiffFinding(message, evidence, expected, actual) {
|
|
10781
12336
|
return failFinding("baseline.regression", message, evidence, expected, actual);
|
|
@@ -11125,13 +12680,13 @@ function createStructureCycleRule() {
|
|
|
11125
12680
|
const seenCycles = /* @__PURE__ */ new Set();
|
|
11126
12681
|
const findings = [];
|
|
11127
12682
|
for (const event of [...context.events].sort((a, b) => a.eventId.localeCompare(b.eventId))) {
|
|
11128
|
-
const
|
|
12683
|
+
const path22 = [];
|
|
11129
12684
|
const seenAt = /* @__PURE__ */ new Map();
|
|
11130
12685
|
let current = event;
|
|
11131
12686
|
while (current) {
|
|
11132
12687
|
const existing = seenAt.get(current.eventId);
|
|
11133
12688
|
if (existing !== void 0) {
|
|
11134
|
-
const cycle =
|
|
12689
|
+
const cycle = path22.slice(existing);
|
|
11135
12690
|
const key = cycle.map((item) => item.eventId).sort().join("\0");
|
|
11136
12691
|
if (!seenCycles.has(key)) {
|
|
11137
12692
|
seenCycles.add(key);
|
|
@@ -11147,8 +12702,8 @@ function createStructureCycleRule() {
|
|
|
11147
12702
|
}
|
|
11148
12703
|
break;
|
|
11149
12704
|
}
|
|
11150
|
-
seenAt.set(current.eventId,
|
|
11151
|
-
|
|
12705
|
+
seenAt.set(current.eventId, path22.length);
|
|
12706
|
+
path22.push(current);
|
|
11152
12707
|
current = current.parentId ? byId.get(current.parentId) : void 0;
|
|
11153
12708
|
}
|
|
11154
12709
|
}
|
|
@@ -11945,23 +13500,23 @@ function evaluatePromptInjection(text, options = {}) {
|
|
|
11945
13500
|
}
|
|
11946
13501
|
return fail(ruleId, `Matched ${evidence.length} injection pattern(s).`, evidence, "warning");
|
|
11947
13502
|
}
|
|
11948
|
-
function validateSchemaField(value, field,
|
|
13503
|
+
function validateSchemaField(value, field, path22, evidence) {
|
|
11949
13504
|
const ruleId = "guardrail.structured-output";
|
|
11950
13505
|
if (field.type) {
|
|
11951
13506
|
const actual = value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
|
|
11952
13507
|
if (actual !== field.type) {
|
|
11953
|
-
evidence.push({ ruleId, path:
|
|
13508
|
+
evidence.push({ ruleId, path: path22, preview: `expected ${field.type}, got ${actual}` });
|
|
11954
13509
|
return;
|
|
11955
13510
|
}
|
|
11956
13511
|
}
|
|
11957
13512
|
if (field.enum && !field.enum.some((item) => Object.is(item, value))) {
|
|
11958
|
-
evidence.push({ ruleId, path:
|
|
13513
|
+
evidence.push({ ruleId, path: path22, preview: "value not in enum" });
|
|
11959
13514
|
}
|
|
11960
13515
|
if (field.type === "object" && field.required && value && typeof value === "object" && !Array.isArray(value)) {
|
|
11961
13516
|
const record = value;
|
|
11962
13517
|
for (const key of field.required) {
|
|
11963
13518
|
if (!(key in record)) {
|
|
11964
|
-
evidence.push({ ruleId, path: `${
|
|
13519
|
+
evidence.push({ ruleId, path: `${path22}.${key}`, preview: "missing required key" });
|
|
11965
13520
|
}
|
|
11966
13521
|
}
|
|
11967
13522
|
}
|
|
@@ -12446,10 +14001,10 @@ function printHuman(result) {
|
|
|
12446
14001
|
console.log(`- ${diagnostic4.code}: ${diagnostic4.message}`);
|
|
12447
14002
|
}
|
|
12448
14003
|
for (const finding of result.findings) {
|
|
12449
|
-
const
|
|
14004
|
+
const path22 = finding.evidence[0]?.path;
|
|
12450
14005
|
const run = finding.evidence[0]?.runId;
|
|
12451
14006
|
const runPrefix = run ? `[${run}] ` : "";
|
|
12452
|
-
console.log(`- ${runPrefix}${finding.ruleId}: ${finding.message}${
|
|
14007
|
+
console.log(`- ${runPrefix}${finding.ruleId}: ${finding.message}${path22 ? ` (${path22})` : ""}`);
|
|
12453
14008
|
}
|
|
12454
14009
|
}
|
|
12455
14010
|
function readErrorResult(error) {
|
|
@@ -12491,9 +14046,9 @@ async function checkCommand(target, options = {}, stdin = process.stdin) {
|
|
|
12491
14046
|
correlateByGroupId: options.correlateGroup === true
|
|
12492
14047
|
});
|
|
12493
14048
|
const perRun = [];
|
|
12494
|
-
for (const
|
|
14049
|
+
for (const meta2 of scoped.metas) {
|
|
12495
14050
|
const read = await openTrace(
|
|
12496
|
-
{ type: "file", path:
|
|
14051
|
+
{ type: "file", path: meta2.filePath },
|
|
12497
14052
|
{
|
|
12498
14053
|
...options.format !== void 0 ? { format: options.format } : {}
|
|
12499
14054
|
}
|
|
@@ -12505,7 +14060,7 @@ async function checkCommand(target, options = {}, stdin = process.stdin) {
|
|
|
12505
14060
|
{
|
|
12506
14061
|
rules: built.rules,
|
|
12507
14062
|
select: built.select,
|
|
12508
|
-
runId:
|
|
14063
|
+
runId: meta2.runId
|
|
12509
14064
|
}
|
|
12510
14065
|
),
|
|
12511
14066
|
read,
|
|
@@ -12563,6 +14118,9 @@ async function checkCommand(target, options = {}, stdin = process.stdin) {
|
|
|
12563
14118
|
else printHuman(result);
|
|
12564
14119
|
}
|
|
12565
14120
|
|
|
14121
|
+
// packages/viewer/src/server.ts
|
|
14122
|
+
init_advanced();
|
|
14123
|
+
|
|
12566
14124
|
// packages/viewer/src/html.ts
|
|
12567
14125
|
var viewerIndexHtml = `<!DOCTYPE html>
|
|
12568
14126
|
<html lang="en">
|
|
@@ -12663,13 +14221,13 @@ function createViewerServer(options = {}) {
|
|
|
12663
14221
|
return sendJson(
|
|
12664
14222
|
res,
|
|
12665
14223
|
200,
|
|
12666
|
-
metas.map((
|
|
12667
|
-
runId:
|
|
12668
|
-
name:
|
|
12669
|
-
status:
|
|
12670
|
-
file: path14__default.default.basename(
|
|
12671
|
-
startedAt:
|
|
12672
|
-
durationMs:
|
|
14224
|
+
metas.map((meta2) => ({
|
|
14225
|
+
runId: meta2.runId,
|
|
14226
|
+
name: meta2.name,
|
|
14227
|
+
status: meta2.status,
|
|
14228
|
+
file: path14__default.default.basename(meta2.filePath),
|
|
14229
|
+
startedAt: meta2.startedAt,
|
|
14230
|
+
durationMs: meta2.durationMs
|
|
12673
14231
|
}))
|
|
12674
14232
|
);
|
|
12675
14233
|
}
|
|
@@ -12712,9 +14270,9 @@ function createViewerServer(options = {}) {
|
|
|
12712
14270
|
files,
|
|
12713
14271
|
(fileName) => td.getPath(fileName)
|
|
12714
14272
|
);
|
|
12715
|
-
const
|
|
12716
|
-
if (!
|
|
12717
|
-
const read = await openTrace({ type: "file", path:
|
|
14273
|
+
const meta2 = metas.find((item) => item.runId === runId);
|
|
14274
|
+
if (!meta2) return notFound(res, `Run not found: ${runId}`);
|
|
14275
|
+
const read = await openTrace({ type: "file", path: meta2.filePath });
|
|
12718
14276
|
const run = read.runs.find((item) => item.runId === runId) ?? read.runs[0];
|
|
12719
14277
|
return sendJson(res, 200, {
|
|
12720
14278
|
runId,
|
|
@@ -12734,9 +14292,9 @@ function createViewerServer(options = {}) {
|
|
|
12734
14292
|
files,
|
|
12735
14293
|
(fileName) => td.getPath(fileName)
|
|
12736
14294
|
);
|
|
12737
|
-
const
|
|
12738
|
-
if (!
|
|
12739
|
-
const read = await openTrace({ type: "file", path:
|
|
14295
|
+
const meta2 = metas.find((item) => item.runId === runId);
|
|
14296
|
+
if (!meta2) return notFound(res, `Run not found: ${runId}`);
|
|
14297
|
+
const read = await openTrace({ type: "file", path: meta2.filePath });
|
|
12740
14298
|
const legacyEvents = persistedInspectEventsToTraceEvents(
|
|
12741
14299
|
boundedEvents(read.events, maxEvents)
|
|
12742
14300
|
);
|
|
@@ -12752,9 +14310,9 @@ function createViewerServer(options = {}) {
|
|
|
12752
14310
|
files,
|
|
12753
14311
|
(fileName) => td.getPath(fileName)
|
|
12754
14312
|
);
|
|
12755
|
-
const
|
|
12756
|
-
if (!
|
|
12757
|
-
const read = await openTrace({ type: "file", path:
|
|
14313
|
+
const meta2 = metas.find((item) => item.runId === runId);
|
|
14314
|
+
if (!meta2) return notFound(res, `Run not found: ${runId}`);
|
|
14315
|
+
const read = await openTrace({ type: "file", path: meta2.filePath });
|
|
12758
14316
|
const result = runTraceChecks(
|
|
12759
14317
|
{ read },
|
|
12760
14318
|
{ rules: [createRunStatusRule()], select: ["run.status"], runId }
|
|
@@ -12987,10 +14545,10 @@ async function evalRun(input3, options = {}) {
|
|
|
12987
14545
|
diagnostics: []
|
|
12988
14546
|
};
|
|
12989
14547
|
}
|
|
12990
|
-
function evidenceForRun(run,
|
|
12991
|
-
return [{ runId: run.runId, ...
|
|
14548
|
+
function evidenceForRun(run, path22) {
|
|
14549
|
+
return [{ runId: run.runId, ...path22 !== void 0 ? { path: path22 } : {} }];
|
|
12992
14550
|
}
|
|
12993
|
-
function evidenceForEvent(event,
|
|
14551
|
+
function evidenceForEvent(event, path22) {
|
|
12994
14552
|
return [
|
|
12995
14553
|
{
|
|
12996
14554
|
runId: event.runId,
|
|
@@ -12998,7 +14556,7 @@ function evidenceForEvent(event, path20) {
|
|
|
12998
14556
|
...event.parentId !== void 0 ? { parentId: event.parentId } : {},
|
|
12999
14557
|
kind: event.kind,
|
|
13000
14558
|
name: event.name,
|
|
13001
|
-
...
|
|
14559
|
+
...path22 !== void 0 ? { path: path22 } : {}
|
|
13002
14560
|
}
|
|
13003
14561
|
];
|
|
13004
14562
|
}
|
|
@@ -13156,9 +14714,9 @@ function collectTextFields(nodes, keys, preferredKinds = []) {
|
|
|
13156
14714
|
function tokenize(text) {
|
|
13157
14715
|
return [...text.toLowerCase().matchAll(/[a-z0-9][a-z0-9'-]{2,}/g)].map((match) => match[0].replace(/^['-]+|['-]+$/g, "")).filter((token) => token.length > 2 && !STOP_WORDS.has(token));
|
|
13158
14716
|
}
|
|
13159
|
-
function firstEvidence(fields, run,
|
|
14717
|
+
function firstEvidence(fields, run, path22) {
|
|
13160
14718
|
const first = fields[0];
|
|
13161
|
-
return first === void 0 ? evidenceForRun(run,
|
|
14719
|
+
return first === void 0 ? evidenceForRun(run, path22) : evidenceForEvent(first.node.event, first.path);
|
|
13162
14720
|
}
|
|
13163
14721
|
function collectSourceIds(nodes, keys) {
|
|
13164
14722
|
const wanted = keySet(keys);
|
|
@@ -13535,8 +15093,8 @@ function renderEvalMarkdown(result) {
|
|
|
13535
15093
|
if (result.findings.length > 0) {
|
|
13536
15094
|
lines.push("", "## Findings");
|
|
13537
15095
|
for (const finding of result.findings) {
|
|
13538
|
-
const
|
|
13539
|
-
lines.push(`- ${finding.ruleId}: ${finding.message}${
|
|
15096
|
+
const path22 = finding.evidence[0]?.path;
|
|
15097
|
+
lines.push(`- ${finding.ruleId}: ${finding.message}${path22 ? ` (${path22})` : ""}`);
|
|
13540
15098
|
}
|
|
13541
15099
|
}
|
|
13542
15100
|
return `${lines.join("\n")}
|
|
@@ -13729,8 +15287,8 @@ function printHuman2(result) {
|
|
|
13729
15287
|
console.log(`- ${diagnostic4.code}: ${diagnostic4.message}`);
|
|
13730
15288
|
}
|
|
13731
15289
|
for (const finding of result.findings) {
|
|
13732
|
-
const
|
|
13733
|
-
console.log(`- ${finding.ruleId}: ${finding.message}${
|
|
15290
|
+
const path22 = finding.evidence[0]?.path;
|
|
15291
|
+
console.log(`- ${finding.ruleId}: ${finding.message}${path22 ? ` (${path22})` : ""}`);
|
|
13734
15292
|
}
|
|
13735
15293
|
}
|
|
13736
15294
|
function readErrorResult2(error) {
|
|
@@ -13968,8 +15526,8 @@ function printHuman3(result) {
|
|
|
13968
15526
|
console.log(`- ${diagnostic4.code}: ${diagnostic4.message}`);
|
|
13969
15527
|
}
|
|
13970
15528
|
for (const finding of result.findings) {
|
|
13971
|
-
const
|
|
13972
|
-
console.log(`- ${finding.ruleId}: ${finding.message}${
|
|
15529
|
+
const path22 = finding.evidence[0]?.path;
|
|
15530
|
+
console.log(`- ${finding.ruleId}: ${finding.message}${path22 ? ` (${path22})` : ""}`);
|
|
13973
15531
|
}
|
|
13974
15532
|
console.log(`Note: ${result.note}`);
|
|
13975
15533
|
}
|
|
@@ -14088,8 +15646,8 @@ function renderCheckSection(result) {
|
|
|
14088
15646
|
`Diagnostics: ${result.diagnostics.length}`
|
|
14089
15647
|
];
|
|
14090
15648
|
for (const finding of result.findings.slice(0, 10)) {
|
|
14091
|
-
const
|
|
14092
|
-
lines.push(`- ${finding.ruleId}: ${finding.message} (${
|
|
15649
|
+
const path22 = finding.evidence[0]?.path ?? "(run)";
|
|
15650
|
+
lines.push(`- ${finding.ruleId}: ${finding.message} (${path22})`);
|
|
14093
15651
|
}
|
|
14094
15652
|
for (const diagnostic4 of result.diagnostics.slice(0, 10)) {
|
|
14095
15653
|
lines.push(`- ${diagnostic4.code}: ${diagnostic4.message}`);
|
|
@@ -15092,6 +16650,7 @@ Summary: ${failed} failed, ${warned} warnings`);
|
|
|
15092
16650
|
}
|
|
15093
16651
|
|
|
15094
16652
|
// packages/adapter-sdk/src/indexer.ts
|
|
16653
|
+
init_advanced();
|
|
15095
16654
|
function defineIndexer(indexer) {
|
|
15096
16655
|
if (!indexer.id.trim()) throw new Error("indexer id is required");
|
|
15097
16656
|
return indexer;
|
|
@@ -15126,12 +16685,12 @@ function createTraceDirectoryIndexer() {
|
|
|
15126
16685
|
slice,
|
|
15127
16686
|
(fileName) => td.getPath(fileName)
|
|
15128
16687
|
);
|
|
15129
|
-
const entries = metas.map((
|
|
15130
|
-
runId:
|
|
15131
|
-
path:
|
|
15132
|
-
name:
|
|
15133
|
-
startedAt:
|
|
15134
|
-
status:
|
|
16688
|
+
const entries = metas.map((meta2) => ({
|
|
16689
|
+
runId: meta2.runId,
|
|
16690
|
+
path: meta2.filePath,
|
|
16691
|
+
name: meta2.name,
|
|
16692
|
+
startedAt: meta2.startedAt,
|
|
16693
|
+
status: meta2.status
|
|
15135
16694
|
})).sort((a, b) => a.runId.localeCompare(b.runId));
|
|
15136
16695
|
if (entries.length < slice.length) {
|
|
15137
16696
|
warnings.push(
|
|
@@ -15149,6 +16708,7 @@ function createTraceDirectoryIndexer() {
|
|
|
15149
16708
|
}
|
|
15150
16709
|
|
|
15151
16710
|
// packages/cli/src/index-cmd.ts
|
|
16711
|
+
init_advanced();
|
|
15152
16712
|
var INDEX_FILENAME = ".agent-inspect-index.json";
|
|
15153
16713
|
function traceIndexPath(traceDir) {
|
|
15154
16714
|
return path14__default.default.join(traceDir, INDEX_FILENAME);
|
|
@@ -15259,6 +16819,144 @@ async function indexCleanCommand(options = {}) {
|
|
|
15259
16819
|
}
|
|
15260
16820
|
}
|
|
15261
16821
|
|
|
16822
|
+
// packages/cli/src/index-sqlite-cmd.ts
|
|
16823
|
+
init_advanced();
|
|
16824
|
+
var PACKAGE = "@agent-inspect/index-sqlite";
|
|
16825
|
+
function isModuleNotFound2(e) {
|
|
16826
|
+
return e !== null && typeof e === "object" && "code" in e && (e.code === "ERR_MODULE_NOT_FOUND" || e.code === "MODULE_NOT_FOUND");
|
|
16827
|
+
}
|
|
16828
|
+
async function loadIndexSqlite() {
|
|
16829
|
+
try {
|
|
16830
|
+
return await Promise.resolve().then(() => (init_src(), src_exports));
|
|
16831
|
+
} catch (e) {
|
|
16832
|
+
if (isModuleNotFound2(e)) {
|
|
16833
|
+
console.error(
|
|
16834
|
+
`The optional SQLite index is not installed. Run: npm install ${PACKAGE}`
|
|
16835
|
+
);
|
|
16836
|
+
process.exitCode = 1;
|
|
16837
|
+
return null;
|
|
16838
|
+
}
|
|
16839
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
16840
|
+
console.error(`[AgentInspect] failed to load ${PACKAGE}: ${msg}`);
|
|
16841
|
+
process.exitCode = 1;
|
|
16842
|
+
return null;
|
|
16843
|
+
}
|
|
16844
|
+
}
|
|
16845
|
+
function parsePositiveInt(raw, flag) {
|
|
16846
|
+
if (raw === void 0 || raw.trim() === "") return void 0;
|
|
16847
|
+
const parsed = Number.parseInt(raw, 10);
|
|
16848
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
16849
|
+
throw new Error(`${flag} must be a positive integer.`);
|
|
16850
|
+
}
|
|
16851
|
+
return parsed;
|
|
16852
|
+
}
|
|
16853
|
+
async function newestTraceMtimeMs(traceDir) {
|
|
16854
|
+
let newest = 0;
|
|
16855
|
+
try {
|
|
16856
|
+
const files = await promises.readdir(traceDir);
|
|
16857
|
+
for (const file of files) {
|
|
16858
|
+
if (!file.endsWith(".jsonl")) continue;
|
|
16859
|
+
try {
|
|
16860
|
+
const s = await promises.stat(path14__default.default.join(traceDir, file));
|
|
16861
|
+
if (s.mtimeMs > newest) newest = s.mtimeMs;
|
|
16862
|
+
} catch {
|
|
16863
|
+
}
|
|
16864
|
+
}
|
|
16865
|
+
} catch {
|
|
16866
|
+
}
|
|
16867
|
+
return newest;
|
|
16868
|
+
}
|
|
16869
|
+
async function indexSqliteBuildCommand(options = {}) {
|
|
16870
|
+
const mod = await loadIndexSqlite();
|
|
16871
|
+
if (!mod) return;
|
|
16872
|
+
const result = await mod.buildIndex({
|
|
16873
|
+
traceDir: options.dir,
|
|
16874
|
+
maxRuns: parsePositiveInt(options.maxRuns, "--max-runs")
|
|
16875
|
+
});
|
|
16876
|
+
if (options.json) {
|
|
16877
|
+
console.log(JSON.stringify({ ok: true, ...result }, null, 2));
|
|
16878
|
+
return;
|
|
16879
|
+
}
|
|
16880
|
+
console.log(`Built SQLite index: ${result.dbPath}`);
|
|
16881
|
+
console.log(`Runs: ${result.runs} Steps: ${result.steps} Errors: ${result.errors}`);
|
|
16882
|
+
for (const warning of result.warnings) console.log(`warning: ${warning}`);
|
|
16883
|
+
}
|
|
16884
|
+
async function indexSqliteStatusCommand(options = {}) {
|
|
16885
|
+
const mod = await loadIndexSqlite();
|
|
16886
|
+
if (!mod) return;
|
|
16887
|
+
const traceDir = resolveTraceDir({ dir: options.dir });
|
|
16888
|
+
const dbPath = mod.resolveIndexDbPath(traceDir);
|
|
16889
|
+
const status = mod.indexStatus(dbPath);
|
|
16890
|
+
const stale = mod.isIndexStale(dbPath, await newestTraceMtimeMs(traceDir));
|
|
16891
|
+
if (options.json) {
|
|
16892
|
+
console.log(JSON.stringify({ ok: true, traceDir, stale, ...status }, null, 2));
|
|
16893
|
+
return;
|
|
16894
|
+
}
|
|
16895
|
+
if (!status.exists) {
|
|
16896
|
+
console.log(`No SQLite index at ${dbPath}`);
|
|
16897
|
+
console.log("Run: agent-inspect index sqlite build");
|
|
16898
|
+
return;
|
|
16899
|
+
}
|
|
16900
|
+
console.log(`Index: ${status.dbPath}`);
|
|
16901
|
+
console.log(`Healthy: ${status.healthy ? "yes" : "no"}`);
|
|
16902
|
+
console.log(`Built: ${status.builtAt ?? "unknown"}`);
|
|
16903
|
+
console.log(`Runs: ${status.runs} Steps: ${status.steps}`);
|
|
16904
|
+
console.log(`Stale: ${stale ? "yes" : "no"}`);
|
|
16905
|
+
}
|
|
16906
|
+
async function indexSqliteQueryCommand(options = {}) {
|
|
16907
|
+
const mod = await loadIndexSqlite();
|
|
16908
|
+
if (!mod) return;
|
|
16909
|
+
const traceDir = resolveTraceDir({ dir: options.dir });
|
|
16910
|
+
const dbPath = mod.resolveIndexDbPath(traceDir);
|
|
16911
|
+
const status = mod.indexStatus(dbPath);
|
|
16912
|
+
if (!status.exists || !status.healthy) {
|
|
16913
|
+
if (options.json) {
|
|
16914
|
+
console.log(JSON.stringify({ ok: false, reason: "index-missing", dbPath }, null, 2));
|
|
16915
|
+
} else {
|
|
16916
|
+
console.log("No usable SQLite index. Run: agent-inspect index sqlite build");
|
|
16917
|
+
}
|
|
16918
|
+
process.exitCode = 1;
|
|
16919
|
+
return;
|
|
16920
|
+
}
|
|
16921
|
+
const rows = mod.queryRuns(dbPath, {
|
|
16922
|
+
status: options.status,
|
|
16923
|
+
sessionId: options.session,
|
|
16924
|
+
name: options.name,
|
|
16925
|
+
kind: options.kind,
|
|
16926
|
+
tool: options.tool,
|
|
16927
|
+
limit: parsePositiveInt(options.limit, "--limit")
|
|
16928
|
+
});
|
|
16929
|
+
if (options.json) {
|
|
16930
|
+
console.log(JSON.stringify({ ok: true, count: rows.length, runs: rows }, null, 2));
|
|
16931
|
+
return;
|
|
16932
|
+
}
|
|
16933
|
+
if (rows.length === 0) {
|
|
16934
|
+
console.log("No matching runs.");
|
|
16935
|
+
return;
|
|
16936
|
+
}
|
|
16937
|
+
for (const run of rows) {
|
|
16938
|
+
const parts = [
|
|
16939
|
+
run.runId,
|
|
16940
|
+
run.status ?? "unknown",
|
|
16941
|
+
run.name ?? "",
|
|
16942
|
+
run.durationMs != null ? `${run.durationMs}ms` : ""
|
|
16943
|
+
].filter((p) => p !== "");
|
|
16944
|
+
console.log(parts.join(" "));
|
|
16945
|
+
}
|
|
16946
|
+
}
|
|
16947
|
+
async function indexSqliteCleanCommand(options = {}) {
|
|
16948
|
+
const mod = await loadIndexSqlite();
|
|
16949
|
+
if (!mod) return;
|
|
16950
|
+
const traceDir = resolveTraceDir({ dir: options.dir });
|
|
16951
|
+
const dbPath = mod.resolveIndexDbPath(traceDir);
|
|
16952
|
+
await mod.cleanIndex(dbPath);
|
|
16953
|
+
if (options.json) {
|
|
16954
|
+
console.log(JSON.stringify({ ok: true, removed: dbPath }, null, 2));
|
|
16955
|
+
return;
|
|
16956
|
+
}
|
|
16957
|
+
console.log(`Removed SQLite index: ${dbPath}`);
|
|
16958
|
+
}
|
|
16959
|
+
|
|
15262
16960
|
// packages/core/src/workspace/types.ts
|
|
15263
16961
|
var WORKSPACE_SCHEMA_VERSION = "1.0";
|
|
15264
16962
|
var WORKSPACE_DIR_NAME = ".agent-inspect";
|
|
@@ -16192,6 +17890,31 @@ function createCliProgram() {
|
|
|
16192
17890
|
indexCmd.command("clean").description("Remove the local index file").option("--dir <path>", "trace directory").option("--json", "print JSON result").action((opts) => {
|
|
16193
17891
|
runCommand(() => indexCleanCommand(opts));
|
|
16194
17892
|
});
|
|
17893
|
+
const sqliteCmd = indexCmd.command("sqlite").description(
|
|
17894
|
+
"Optional SQLite-backed trace index (requires @agent-inspect/index-sqlite)"
|
|
17895
|
+
);
|
|
17896
|
+
sqliteCmd.command("build").description("Build or rebuild the local SQLite index").option("--dir <path>", "trace directory").option("--max-runs <n>", "cap indexed trace files (default 10000)").option("--json", "print JSON result").action((opts) => {
|
|
17897
|
+
runCommand(() => indexSqliteBuildCommand(opts));
|
|
17898
|
+
});
|
|
17899
|
+
sqliteCmd.command("rebuild").description("Alias for build (full, idempotent rebuild)").option("--dir <path>", "trace directory").option("--max-runs <n>", "cap indexed trace files (default 10000)").option("--json", "print JSON result").action((opts) => {
|
|
17900
|
+
runCommand(() => indexSqliteBuildCommand(opts));
|
|
17901
|
+
});
|
|
17902
|
+
sqliteCmd.command("status").description("Show SQLite index health, counts, and staleness").option("--dir <path>", "trace directory").option("--json", "print JSON result").action((opts) => {
|
|
17903
|
+
runCommand(() => indexSqliteStatusCommand(opts));
|
|
17904
|
+
});
|
|
17905
|
+
sqliteCmd.command("query").description("Query indexed runs (fast; falls back with a hint if absent)").option("--dir <path>", "trace directory").addOption(
|
|
17906
|
+
new commander.Option("--status <status>", "filter by run status").choices([
|
|
17907
|
+
"success",
|
|
17908
|
+
"error",
|
|
17909
|
+
"running",
|
|
17910
|
+
"unknown"
|
|
17911
|
+
])
|
|
17912
|
+
).option("--session <id>", "filter by session id").option("--name <query>", "substring match on run name").option("--kind <kind>", "match runs containing a step of this kind").option("--tool <query>", "match runs containing a tool step (substring)").option("--limit <n>", "max results (default 100)").option("--json", "print JSON result").action((opts) => {
|
|
17913
|
+
runCommand(() => indexSqliteQueryCommand(opts));
|
|
17914
|
+
});
|
|
17915
|
+
sqliteCmd.command("clean").description("Remove the SQLite index (traces are never touched)").option("--dir <path>", "trace directory").option("--json", "print JSON result").action((opts) => {
|
|
17916
|
+
runCommand(() => indexSqliteCleanCommand(opts));
|
|
17917
|
+
});
|
|
16195
17918
|
const workspaceCmd = program.command("workspace").description("Manage a project-local AgentInspect workspace (.agent-inspect)");
|
|
16196
17919
|
workspaceCmd.command("init").description("Create or adopt a local workspace (never deletes traces)").option("--project <name>", "project name (default: directory name)").addOption(
|
|
16197
17920
|
new commander.Option("--redaction-profile <profile>", "default redaction posture").choices([
|