@cesarus777/opencode-cgp 0.2.5 → 0.3.1
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 +19 -0
- package/README.md +56 -5
- package/dist/cli.js +3498 -1029
- package/dist/core.js +311 -102
- package/dist/index.js +873 -836
- package/dist/rpc.js +275 -246
- package/dist/tui.js +679 -627
- package/dist/types/clihelp.d.ts +2 -0
- package/dist/types/core.d.ts +1 -0
- package/dist/types/dashboard/command.d.ts +5 -0
- package/dist/types/dashboard/connection.d.ts +36 -0
- package/dist/types/dashboard/controller.d.ts +57 -0
- package/dist/types/dashboard/inventory.d.ts +17 -0
- package/dist/types/dashboard/port.d.ts +41 -0
- package/dist/types/dashboard/terminal.d.ts +36 -0
- package/dist/types/dashboard/terminalview.d.ts +15 -0
- package/dist/types/dashboard/view.d.ts +83 -0
- package/dist/types/modelanalytics.d.ts +60 -0
- package/dist/types/modelcli.d.ts +1 -0
- package/dist/types/tui/contextchart.d.ts +2 -1
- package/package.json +6 -7
package/dist/core.js
CHANGED
|
@@ -1,4 +1,314 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, {
|
|
21
|
+
get: all[name],
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
set: (newValue) => all[name] = () => newValue
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
28
|
+
|
|
29
|
+
// src/family.ts
|
|
30
|
+
function metric(snapshot, now, staleMs) {
|
|
31
|
+
const m = snapshot?.measurement;
|
|
32
|
+
const freshness = !m ? "missing" : m.model !== snapshot?.model || m.at > now ? "invalid" : now - m.at > staleMs ? "stale" : "fresh";
|
|
33
|
+
const t = snapshot?.policy.triggerTokens;
|
|
34
|
+
const valid = freshness === "fresh" && m !== undefined;
|
|
35
|
+
const displayable = valid || freshness === "stale" && m !== undefined;
|
|
36
|
+
const pressureRatio = valid && t !== undefined && t > 0 ? m.tokens / t : undefined;
|
|
37
|
+
const crossed = valid && t !== undefined && t > 0 && (snapshot?.policy.comparison === ">" ? m.tokens > t : m.tokens >= t);
|
|
38
|
+
return {
|
|
39
|
+
freshness,
|
|
40
|
+
pressure: pressureRatio === undefined ? "unknown" : crossed ? "crossed" : pressureRatio >= 0.9 ? "near" : "normal",
|
|
41
|
+
...pressureRatio === undefined ? {} : { pressureRatio },
|
|
42
|
+
...displayable && snapshot?.capacityTokens && snapshot.capacityTokens > 0 ? { utilizationPercent: m.tokens / snapshot.capacityTokens * 100 } : {},
|
|
43
|
+
...valid && t !== undefined ? { triggerDeltaTokens: t - m.tokens } : {}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function familyRows(nodes, snapshots, current, now, staleMs, expanded = new Set, limit = 1024, timing, stableOrder = []) {
|
|
47
|
+
const byId = new Map(nodes.map((n) => [n.sessionId, n]));
|
|
48
|
+
const children = new Map;
|
|
49
|
+
for (const n of byId.values()) {
|
|
50
|
+
const parent = n.parentId && byId.has(n.parentId) ? n.parentId : "";
|
|
51
|
+
const list = children.get(parent) ?? [];
|
|
52
|
+
list.push(n);
|
|
53
|
+
children.set(parent, list);
|
|
54
|
+
}
|
|
55
|
+
const metrics = new Map([...byId.keys()].map((id) => [
|
|
56
|
+
id,
|
|
57
|
+
metric(snapshots.get(id), timing?.(id).now ?? now, timing?.(id).staleMs ?? staleMs)
|
|
58
|
+
]));
|
|
59
|
+
const protectedIds = new Set;
|
|
60
|
+
let ancestor = byId.get(current);
|
|
61
|
+
while (ancestor && !protectedIds.has(ancestor.sessionId)) {
|
|
62
|
+
protectedIds.add(ancestor.sessionId);
|
|
63
|
+
ancestor = ancestor.parentId ? byId.get(ancestor.parentId) : undefined;
|
|
64
|
+
}
|
|
65
|
+
const scores = new Map, sensitive = new Map, sizes = new Map;
|
|
66
|
+
const calculate = (n, seen) => {
|
|
67
|
+
if (seen.has(n.sessionId))
|
|
68
|
+
return -1;
|
|
69
|
+
if (scores.has(n.sessionId))
|
|
70
|
+
return scores.get(n.sessionId) ?? -1;
|
|
71
|
+
const path = new Set(seen).add(n.sessionId), m = metrics.get(n.sessionId);
|
|
72
|
+
let score = m?.pressureRatio ?? -1, size = 1;
|
|
73
|
+
let keep = protectedIds.has(n.sessionId) || n.status === "running" || m?.pressure === "crossed" || ["blocked", "uncertain"].includes(snapshots.get(n.sessionId)?.compaction.phase ?? "");
|
|
74
|
+
for (const child of children.get(n.sessionId) ?? []) {
|
|
75
|
+
score = Math.max(score, calculate(child, path));
|
|
76
|
+
size += sizes.get(child.sessionId) ?? 0;
|
|
77
|
+
keep ||= sensitive.get(child.sessionId) ?? false;
|
|
78
|
+
}
|
|
79
|
+
scores.set(n.sessionId, score);
|
|
80
|
+
sizes.set(n.sessionId, size);
|
|
81
|
+
sensitive.set(n.sessionId, keep);
|
|
82
|
+
return score;
|
|
83
|
+
};
|
|
84
|
+
for (const n of byId.values())
|
|
85
|
+
calculate(n, new Set);
|
|
86
|
+
const visited = new Set, rows = [];
|
|
87
|
+
const visit = (n, depth) => {
|
|
88
|
+
if (visited.has(n.sessionId) || rows.length >= limit || depth > 64)
|
|
89
|
+
return;
|
|
90
|
+
visited.add(n.sessionId);
|
|
91
|
+
const snapshot = snapshots.get(n.sessionId), m = metrics.get(n.sessionId) ?? metric(undefined, now, staleMs);
|
|
92
|
+
const collapsed = n.status === "completed" && !sensitive.get(n.sessionId) && !expanded.has(n.sessionId);
|
|
93
|
+
rows.push({
|
|
94
|
+
node: n,
|
|
95
|
+
...snapshot ? { snapshot } : {},
|
|
96
|
+
depth,
|
|
97
|
+
current: n.sessionId === current,
|
|
98
|
+
...m,
|
|
99
|
+
hidden: collapsed ? (sizes.get(n.sessionId) ?? 1) - 1 : 0
|
|
100
|
+
});
|
|
101
|
+
if (collapsed) {
|
|
102
|
+
const pending = [...children.get(n.sessionId) ?? []];
|
|
103
|
+
while (pending.length) {
|
|
104
|
+
const child = pending.pop();
|
|
105
|
+
if (!child || visited.has(child.sessionId))
|
|
106
|
+
continue;
|
|
107
|
+
visited.add(child.sessionId);
|
|
108
|
+
pending.push(...children.get(child.sessionId) ?? []);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!collapsed)
|
|
112
|
+
for (const child of sorted(children.get(n.sessionId) ?? []))
|
|
113
|
+
visit(child, depth + 1);
|
|
114
|
+
};
|
|
115
|
+
const ranks = new Map(stableOrder.map((id, i) => [id, i]));
|
|
116
|
+
const sorted = (items) => [...items].sort((a, b) => (stableOrder.length ? (ranks.get(a.sessionId) ?? Infinity) - (ranks.get(b.sessionId) ?? Infinity) : 0) || (scores.get(b.sessionId) ?? -1) - (scores.get(a.sessionId) ?? -1) || a.sessionId.localeCompare(b.sessionId));
|
|
117
|
+
for (const n of sorted(children.get("") ?? []))
|
|
118
|
+
visit(n, 0);
|
|
119
|
+
for (const n of byId.values())
|
|
120
|
+
if (!visited.has(n.sessionId) && rows.length < limit)
|
|
121
|
+
visit(n, 0);
|
|
122
|
+
return rows;
|
|
123
|
+
}
|
|
124
|
+
function executionStatus(known, nativeRunning, evidence) {
|
|
125
|
+
if (nativeRunning || evidence.startedAt !== undefined && evidence.startedAt > (evidence.terminalAt ?? -1))
|
|
126
|
+
return "running";
|
|
127
|
+
if (evidence.outcome && (evidence.terminalAt ?? -1) >= (evidence.startedAt ?? -1))
|
|
128
|
+
return evidence.outcome === "succeeded" ? "completed" : evidence.outcome === "failed" ? "failed" : "unknown";
|
|
129
|
+
return known ? "idle" : "unknown";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/modelanalytics.ts
|
|
133
|
+
function requestFact(record) {
|
|
134
|
+
const p = record.performance;
|
|
135
|
+
if (!p?.requestId || !record.sessionId || !nonnegative(p.requestStartedAt))
|
|
136
|
+
return;
|
|
137
|
+
const model = p.requestModel || record.model;
|
|
138
|
+
const agent = p.requestAgent || record.agent;
|
|
139
|
+
const ttft = p.ttftMs ?? (p.firstOutputAt === undefined ? undefined : p.firstOutputAt - p.requestStartedAt);
|
|
140
|
+
return {
|
|
141
|
+
location: "",
|
|
142
|
+
sessionId: record.sessionId,
|
|
143
|
+
requestId: p.requestId,
|
|
144
|
+
startedAt: p.requestStartedAt,
|
|
145
|
+
...p.streamEndedAt === undefined ? {} : { completedAt: p.streamEndedAt },
|
|
146
|
+
...model ? { model } : {},
|
|
147
|
+
...agent ? { agent } : {},
|
|
148
|
+
attribution: p.requestModel ? "request" : model ? "legacy-record" : "unknown",
|
|
149
|
+
partial: p.partial,
|
|
150
|
+
...p.tokenSource === "reported" && nonnegative(p.requestOutputTokens) ? { outputTokens: p.requestOutputTokens } : {},
|
|
151
|
+
...ttft === undefined ? {} : { ttftMs: ttft }
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function reconcile(a, b) {
|
|
155
|
+
for (const field of [
|
|
156
|
+
"completedAt",
|
|
157
|
+
"outputTokens",
|
|
158
|
+
"ttftMs",
|
|
159
|
+
"agent"
|
|
160
|
+
])
|
|
161
|
+
if (a[field] !== undefined && b[field] !== undefined && a[field] !== b[field])
|
|
162
|
+
return;
|
|
163
|
+
if (a.model && b.model && a.model !== b.model)
|
|
164
|
+
return;
|
|
165
|
+
const rank = { unknown: 0, "legacy-record": 1, request: 2 };
|
|
166
|
+
const preferred = rank[b.attribution] > rank[a.attribution] ? b : a;
|
|
167
|
+
return {
|
|
168
|
+
...a,
|
|
169
|
+
...b,
|
|
170
|
+
...preferred.model ? { model: preferred.model } : {},
|
|
171
|
+
attribution: preferred.attribution,
|
|
172
|
+
partial: a.partial || b.partial
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function aggregateModels(records, options) {
|
|
176
|
+
const maxRequests = options.maxRequests ?? 1e5;
|
|
177
|
+
if (!Number.isSafeInteger(maxRequests) || maxRequests < 1 || maxRequests > 1e6)
|
|
178
|
+
throw new Error("maxRequests must be an integer from 1 to 1000000");
|
|
179
|
+
if (!options.location)
|
|
180
|
+
throw new Error("Analytics requires a location identity");
|
|
181
|
+
for (const value of [options.from, options.to])
|
|
182
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))
|
|
183
|
+
throw new Error("Invalid analytics timestamp");
|
|
184
|
+
if (options.from !== undefined && options.to !== undefined && options.from > options.to)
|
|
185
|
+
throw new Error("--from must precede --to");
|
|
186
|
+
const coverage = {
|
|
187
|
+
source: "retained-request-records",
|
|
188
|
+
scannedRecords: 0,
|
|
189
|
+
unscannedRecords: 0,
|
|
190
|
+
duplicateRecords: 0,
|
|
191
|
+
conflictingRequests: 0,
|
|
192
|
+
missingIdentityRecords: 0,
|
|
193
|
+
incompleteRequests: 0,
|
|
194
|
+
invalidTimingRequests: 0,
|
|
195
|
+
gapRecords: 0,
|
|
196
|
+
maxRequests,
|
|
197
|
+
partial: false
|
|
198
|
+
};
|
|
199
|
+
const requests = new Map;
|
|
200
|
+
for (const record of records) {
|
|
201
|
+
coverage.scannedRecords++;
|
|
202
|
+
if (record.type === "gap") {
|
|
203
|
+
coverage.gapRecords++;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (record.type !== "request")
|
|
207
|
+
continue;
|
|
208
|
+
const fact = requestFact(record);
|
|
209
|
+
if (!fact) {
|
|
210
|
+
coverage.missingIdentityRecords++;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
fact.location = options.location;
|
|
214
|
+
const key = JSON.stringify([
|
|
215
|
+
fact.sessionId,
|
|
216
|
+
fact.requestId,
|
|
217
|
+
fact.startedAt
|
|
218
|
+
]);
|
|
219
|
+
const previous = requests.get(key);
|
|
220
|
+
if (previous) {
|
|
221
|
+
coverage.duplicateRecords++;
|
|
222
|
+
const merged = reconcile(previous.fact, fact);
|
|
223
|
+
if (!merged)
|
|
224
|
+
previous.conflict = true;
|
|
225
|
+
else
|
|
226
|
+
previous.fact = merged;
|
|
227
|
+
} else {
|
|
228
|
+
if (requests.size === maxRequests) {
|
|
229
|
+
coverage.scannedRecords--;
|
|
230
|
+
coverage.unscannedRecords = records.length - coverage.scannedRecords;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
requests.set(key, { fact, conflict: false });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const groups = new Map;
|
|
237
|
+
for (const { fact: r, conflict } of requests.values()) {
|
|
238
|
+
if (conflict) {
|
|
239
|
+
coverage.conflictingRequests++;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (r.completedAt === undefined) {
|
|
243
|
+
coverage.incompleteRequests++;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const duration = r.completedAt - r.startedAt;
|
|
247
|
+
if (!nonnegative(r.completedAt) || !Number.isFinite(duration) || duration <= 0) {
|
|
248
|
+
coverage.invalidTimingRequests++;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (options.from !== undefined && r.completedAt < options.from || options.to !== undefined && r.completedAt >= options.to || options.model !== undefined && r.model !== options.model || options.agent !== undefined && r.agent !== options.agent)
|
|
252
|
+
continue;
|
|
253
|
+
let group = groups.get(r.model);
|
|
254
|
+
if (!group) {
|
|
255
|
+
group = {
|
|
256
|
+
summary: {
|
|
257
|
+
...r.model ? { model: r.model } : {},
|
|
258
|
+
sessions: 0,
|
|
259
|
+
completedRequests: 0,
|
|
260
|
+
partialRequests: 0,
|
|
261
|
+
legacyAttributionRequests: 0,
|
|
262
|
+
tpsRequests: 0,
|
|
263
|
+
ttftRequests: 0,
|
|
264
|
+
excludedTpsRequests: 0,
|
|
265
|
+
excludedTtftRequests: 0,
|
|
266
|
+
outputTokens: 0,
|
|
267
|
+
durationMs: 0
|
|
268
|
+
},
|
|
269
|
+
sessions: new Set,
|
|
270
|
+
ttfts: []
|
|
271
|
+
};
|
|
272
|
+
groups.set(r.model, group);
|
|
273
|
+
}
|
|
274
|
+
const s = group.summary;
|
|
275
|
+
group.sessions.add(r.sessionId);
|
|
276
|
+
s.completedRequests++;
|
|
277
|
+
if (r.partial)
|
|
278
|
+
s.partialRequests++;
|
|
279
|
+
if (r.attribution === "legacy-record")
|
|
280
|
+
s.legacyAttributionRequests++;
|
|
281
|
+
if (r.outputTokens !== undefined) {
|
|
282
|
+
s.tpsRequests++;
|
|
283
|
+
s.outputTokens += r.outputTokens;
|
|
284
|
+
s.durationMs += duration;
|
|
285
|
+
} else
|
|
286
|
+
s.excludedTpsRequests++;
|
|
287
|
+
if (nonnegative(r.ttftMs) && r.ttftMs <= duration)
|
|
288
|
+
group.ttfts.push(r.ttftMs);
|
|
289
|
+
else
|
|
290
|
+
s.excludedTtftRequests++;
|
|
291
|
+
}
|
|
292
|
+
const models = [...groups.values()].map(({ summary: s, sessions, ttfts }) => {
|
|
293
|
+
s.sessions = sessions.size;
|
|
294
|
+
s.ttftRequests = ttfts.length;
|
|
295
|
+
if (s.tpsRequests)
|
|
296
|
+
s.averageTps = s.outputTokens * 1000 / s.durationMs;
|
|
297
|
+
ttfts.sort((a, b) => a - b);
|
|
298
|
+
if (ttfts.length) {
|
|
299
|
+
s.meanTtftMs = ttfts.reduce((sum, n) => sum + n, 0) / ttfts.length;
|
|
300
|
+
s.medianTtftMs = ((ttfts[Math.floor((ttfts.length - 1) / 2)] ?? 0) + (ttfts[Math.floor(ttfts.length / 2)] ?? 0)) / 2;
|
|
301
|
+
const p95 = ttfts[Math.ceil(ttfts.length * 0.95) - 1];
|
|
302
|
+
if (p95 !== undefined)
|
|
303
|
+
s.p95TtftMs = p95;
|
|
304
|
+
}
|
|
305
|
+
return s;
|
|
306
|
+
}).sort((a, b) => (a.model ?? "").localeCompare(b.model ?? ""));
|
|
307
|
+
coverage.partial = coverage.unscannedRecords > 0 || coverage.conflictingRequests > 0 || coverage.missingIdentityRecords > 0 || coverage.incompleteRequests > 0 || coverage.invalidTimingRequests > 0 || coverage.gapRecords > 0 || models.some((s) => s.partialRequests > 0 || s.legacyAttributionRequests > 0 || s.excludedTpsRequests > 0 || s.excludedTtftRequests > 0 || !s.model);
|
|
308
|
+
return { schemaVersion: 1, location: options.location, models, coverage };
|
|
309
|
+
}
|
|
310
|
+
var nonnegative = (n) => n !== undefined && Number.isFinite(n) && n >= 0;
|
|
311
|
+
|
|
2
312
|
// src/types.ts
|
|
3
313
|
class NoopBudgetController {
|
|
4
314
|
evaluate(_input) {
|
|
@@ -742,108 +1052,6 @@ function freezeSnapshot(row) {
|
|
|
742
1052
|
}
|
|
743
1053
|
return Object.freeze(row);
|
|
744
1054
|
}
|
|
745
|
-
// src/family.ts
|
|
746
|
-
function metric(snapshot, now, staleMs) {
|
|
747
|
-
const m = snapshot?.measurement;
|
|
748
|
-
const freshness = !m ? "missing" : m.model !== snapshot?.model || m.at > now ? "invalid" : now - m.at > staleMs ? "stale" : "fresh";
|
|
749
|
-
const t = snapshot?.policy.triggerTokens;
|
|
750
|
-
const valid = freshness === "fresh" && m !== undefined;
|
|
751
|
-
const displayable = valid || freshness === "stale" && m !== undefined;
|
|
752
|
-
const pressureRatio = valid && t !== undefined && t > 0 ? m.tokens / t : undefined;
|
|
753
|
-
const crossed = valid && t !== undefined && t > 0 && (snapshot?.policy.comparison === ">" ? m.tokens > t : m.tokens >= t);
|
|
754
|
-
return {
|
|
755
|
-
freshness,
|
|
756
|
-
pressure: pressureRatio === undefined ? "unknown" : crossed ? "crossed" : pressureRatio >= 0.9 ? "near" : "normal",
|
|
757
|
-
...pressureRatio === undefined ? {} : { pressureRatio },
|
|
758
|
-
...displayable && snapshot?.capacityTokens && snapshot.capacityTokens > 0 ? { utilizationPercent: m.tokens / snapshot.capacityTokens * 100 } : {},
|
|
759
|
-
...valid && t !== undefined ? { triggerDeltaTokens: t - m.tokens } : {}
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
function familyRows(nodes, snapshots, current, now, staleMs, expanded = new Set, limit = 1024, timing, stableOrder = []) {
|
|
763
|
-
const byId = new Map(nodes.map((n) => [n.sessionId, n]));
|
|
764
|
-
const children = new Map;
|
|
765
|
-
for (const n of byId.values()) {
|
|
766
|
-
const parent = n.parentId && byId.has(n.parentId) ? n.parentId : "";
|
|
767
|
-
const list = children.get(parent) ?? [];
|
|
768
|
-
list.push(n);
|
|
769
|
-
children.set(parent, list);
|
|
770
|
-
}
|
|
771
|
-
const metrics = new Map([...byId.keys()].map((id) => [
|
|
772
|
-
id,
|
|
773
|
-
metric(snapshots.get(id), timing?.(id).now ?? now, timing?.(id).staleMs ?? staleMs)
|
|
774
|
-
]));
|
|
775
|
-
const protectedIds = new Set;
|
|
776
|
-
let ancestor = byId.get(current);
|
|
777
|
-
while (ancestor && !protectedIds.has(ancestor.sessionId)) {
|
|
778
|
-
protectedIds.add(ancestor.sessionId);
|
|
779
|
-
ancestor = ancestor.parentId ? byId.get(ancestor.parentId) : undefined;
|
|
780
|
-
}
|
|
781
|
-
const scores = new Map, sensitive = new Map, sizes = new Map;
|
|
782
|
-
const calculate = (n, seen) => {
|
|
783
|
-
if (seen.has(n.sessionId))
|
|
784
|
-
return -1;
|
|
785
|
-
if (scores.has(n.sessionId))
|
|
786
|
-
return scores.get(n.sessionId) ?? -1;
|
|
787
|
-
const path = new Set(seen).add(n.sessionId), m = metrics.get(n.sessionId);
|
|
788
|
-
let score = m?.pressureRatio ?? -1, size = 1;
|
|
789
|
-
let keep = protectedIds.has(n.sessionId) || n.status === "running" || m?.pressure === "crossed" || ["blocked", "uncertain"].includes(snapshots.get(n.sessionId)?.compaction.phase ?? "");
|
|
790
|
-
for (const child of children.get(n.sessionId) ?? []) {
|
|
791
|
-
score = Math.max(score, calculate(child, path));
|
|
792
|
-
size += sizes.get(child.sessionId) ?? 0;
|
|
793
|
-
keep ||= sensitive.get(child.sessionId) ?? false;
|
|
794
|
-
}
|
|
795
|
-
scores.set(n.sessionId, score);
|
|
796
|
-
sizes.set(n.sessionId, size);
|
|
797
|
-
sensitive.set(n.sessionId, keep);
|
|
798
|
-
return score;
|
|
799
|
-
};
|
|
800
|
-
for (const n of byId.values())
|
|
801
|
-
calculate(n, new Set);
|
|
802
|
-
const visited = new Set, rows = [];
|
|
803
|
-
const visit = (n, depth) => {
|
|
804
|
-
if (visited.has(n.sessionId) || rows.length >= limit || depth > 64)
|
|
805
|
-
return;
|
|
806
|
-
visited.add(n.sessionId);
|
|
807
|
-
const snapshot = snapshots.get(n.sessionId), m = metrics.get(n.sessionId) ?? metric(undefined, now, staleMs);
|
|
808
|
-
const collapsed = n.status === "completed" && !sensitive.get(n.sessionId) && !expanded.has(n.sessionId);
|
|
809
|
-
rows.push({
|
|
810
|
-
node: n,
|
|
811
|
-
...snapshot ? { snapshot } : {},
|
|
812
|
-
depth,
|
|
813
|
-
current: n.sessionId === current,
|
|
814
|
-
...m,
|
|
815
|
-
hidden: collapsed ? (sizes.get(n.sessionId) ?? 1) - 1 : 0
|
|
816
|
-
});
|
|
817
|
-
if (collapsed) {
|
|
818
|
-
const pending = [...children.get(n.sessionId) ?? []];
|
|
819
|
-
while (pending.length) {
|
|
820
|
-
const child = pending.pop();
|
|
821
|
-
if (!child || visited.has(child.sessionId))
|
|
822
|
-
continue;
|
|
823
|
-
visited.add(child.sessionId);
|
|
824
|
-
pending.push(...children.get(child.sessionId) ?? []);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
if (!collapsed)
|
|
828
|
-
for (const child of sorted(children.get(n.sessionId) ?? []))
|
|
829
|
-
visit(child, depth + 1);
|
|
830
|
-
};
|
|
831
|
-
const ranks = new Map(stableOrder.map((id, i) => [id, i]));
|
|
832
|
-
const sorted = (items) => [...items].sort((a, b) => (stableOrder.length ? (ranks.get(a.sessionId) ?? Infinity) - (ranks.get(b.sessionId) ?? Infinity) : 0) || (scores.get(b.sessionId) ?? -1) - (scores.get(a.sessionId) ?? -1) || a.sessionId.localeCompare(b.sessionId));
|
|
833
|
-
for (const n of sorted(children.get("") ?? []))
|
|
834
|
-
visit(n, 0);
|
|
835
|
-
for (const n of byId.values())
|
|
836
|
-
if (!visited.has(n.sessionId) && rows.length < limit)
|
|
837
|
-
visit(n, 0);
|
|
838
|
-
return rows;
|
|
839
|
-
}
|
|
840
|
-
function executionStatus(known, nativeRunning, evidence) {
|
|
841
|
-
if (nativeRunning || evidence.startedAt !== undefined && evidence.startedAt > (evidence.terminalAt ?? -1))
|
|
842
|
-
return "running";
|
|
843
|
-
if (evidence.outcome && (evidence.terminalAt ?? -1) >= (evidence.startedAt ?? -1))
|
|
844
|
-
return evidence.outcome === "succeeded" ? "completed" : evidence.outcome === "failed" ? "failed" : "unknown";
|
|
845
|
-
return known ? "idle" : "unknown";
|
|
846
|
-
}
|
|
847
1055
|
// src/performance.ts
|
|
848
1056
|
var valid = (n) => Number.isFinite(n) && n >= 0;
|
|
849
1057
|
var rate = (tokens, ms) => valid(tokens) && ms > 0 ? tokens * 1000 / ms : undefined;
|
|
@@ -1239,6 +1447,7 @@ export {
|
|
|
1239
1447
|
estimate,
|
|
1240
1448
|
downsamplePoints,
|
|
1241
1449
|
buildChartData,
|
|
1450
|
+
aggregateModels,
|
|
1242
1451
|
SnapshotStore,
|
|
1243
1452
|
PolicyResolver,
|
|
1244
1453
|
PerformanceTracker,
|