@xiangyixie/dsh-superagent 0.9.3 → 0.11.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 +210 -0
- package/LICENSE +21 -21
- package/README.md +422 -42
- package/bin/archive.js +185 -0
- package/bin/doctor.js +84 -0
- package/bin/report.js +79 -79
- package/bin/watch.js +57 -57
- package/cordis.patch.yml +9 -9
- package/lib/control.js +495 -494
- package/lib/cost.js +267 -0
- package/lib/doctor.js +876 -0
- package/lib/errors.js +205 -199
- package/lib/index.js +767 -42
- package/lib/ledger.js +270 -0
- package/lib/lock.js +107 -0
- package/lib/memory.js +736 -0
- package/lib/notify.js +257 -0
- package/lib/orchestrator.js +1975 -127
- package/lib/report.js +350 -15
- package/lib/store.js +503 -15
- package/lib/templates.js +690 -0
- package/lib/usage.js +152 -152
- package/lib/watch.js +422 -70
- package/lib/workspace.js +433 -0
- package/package.json +16 -3
package/lib/report.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module dsh-superagent/report
|
|
14
14
|
*/
|
|
15
|
+
import { formatMoney, moneyOfMicros } from './cost.js'
|
|
15
16
|
import { ACTIVE_STATUSES } from './store.js'
|
|
16
17
|
import { callsOf, formatCount, formatDuration } from './watch.js'
|
|
17
18
|
|
|
@@ -56,13 +57,11 @@ function timeOf(value) {
|
|
|
56
57
|
return Number.isFinite(parsed) ? parsed : null
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
/**
|
|
60
|
-
function money(value) {
|
|
61
|
-
if (
|
|
62
|
-
if (value ===
|
|
63
|
-
|
|
64
|
-
if (value < 1) return `$${value.toFixed(4)}`
|
|
65
|
-
return `$${value.toFixed(2)}`
|
|
60
|
+
/** `¥0.0225`, `$1.24`, `<¥0.0001`, or `—`. */
|
|
61
|
+
function money(value, currency) {
|
|
62
|
+
if (typeof value === 'number' && !Number.isFinite(value)) return '—'
|
|
63
|
+
if (value === null || value === undefined) return '—'
|
|
64
|
+
return formatMoney(value, currency)
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
/** `2026-11-14 07:52:05` in UTC, matching the axis. */
|
|
@@ -170,6 +169,100 @@ export function assignLanes(items) {
|
|
|
170
169
|
return laneEnds.length
|
|
171
170
|
}
|
|
172
171
|
|
|
172
|
+
/** Worker colours, by subtask order; cycled when a run has more workers. */
|
|
173
|
+
const WORKER_COLORS = ['#0f766e', '#0284c7', '#7c3aed', '#b45309', '#be185d', '#15803d', '#475569', '#a16207']
|
|
174
|
+
|
|
175
|
+
/** `40%`, or `0.4%` for a sliver rather than a misleading `0%`. */
|
|
176
|
+
function percent(share) {
|
|
177
|
+
if (!Number.isFinite(share) || share <= 0) return '0%'
|
|
178
|
+
const value = share * 100
|
|
179
|
+
if (value < 1) return `${value.toFixed(1)}%`
|
|
180
|
+
return `${value.toFixed(0)}%`
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Attempts recorded for one worker.
|
|
185
|
+
*
|
|
186
|
+
* A subtask that never started records zero; a worker that is about to run has
|
|
187
|
+
* not spent an attempt yet, so the value is clamped to at least one only when
|
|
188
|
+
* the caller is describing work that did happen.
|
|
189
|
+
*
|
|
190
|
+
* @param {object} subtask - worker record.
|
|
191
|
+
*/
|
|
192
|
+
export function attemptsOf(subtask) {
|
|
193
|
+
return Math.max(0, Number(subtask?.attempts) || 0)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The causal chain for the workers that needed more than one attempt, or that
|
|
198
|
+
* ended in failure.
|
|
199
|
+
*
|
|
200
|
+
* The run file keeps one error per worker, not one per attempt, so a chain can
|
|
201
|
+
* say how many attempts were spent and what the last error was, but not what
|
|
202
|
+
* each earlier attempt said. The section states that limitation instead of
|
|
203
|
+
* inventing per-attempt text. A self-heal round resets the worker's counter, so
|
|
204
|
+
* its recorded attempts describe the latest round; the round itself is
|
|
205
|
+
* reported from `run.selfHeal`.
|
|
206
|
+
*
|
|
207
|
+
* @param {object} run - run record.
|
|
208
|
+
* @returns {Array<object>} one entry per retried or failed worker.
|
|
209
|
+
*/
|
|
210
|
+
export function retryChainsOf(run) {
|
|
211
|
+
const subtasks = Array.isArray(run?.subtasks) ? run.subtasks : []
|
|
212
|
+
const cap = Math.max(1, Number(run?.limits?.attempts) || 1)
|
|
213
|
+
const chains = []
|
|
214
|
+
for (const subtask of subtasks) {
|
|
215
|
+
const attempts = attemptsOf(subtask)
|
|
216
|
+
const failed = subtask?.status === 'failed'
|
|
217
|
+
if (attempts < 2 && !(failed && attempts >= 1)) continue
|
|
218
|
+
chains.push({
|
|
219
|
+
index: Number(subtask.index) || chains.length + 1,
|
|
220
|
+
title: String(subtask.title ?? ''),
|
|
221
|
+
attempts: Math.max(1, attempts),
|
|
222
|
+
cap,
|
|
223
|
+
status: String(subtask.status ?? 'pending'),
|
|
224
|
+
error: String(subtask.error ?? ''),
|
|
225
|
+
stopReason: String(subtask.stopReason ?? ''),
|
|
226
|
+
recovered: subtask?.status === 'completed' && attempts > 1,
|
|
227
|
+
startedAt: timeOf(subtask.startedAt),
|
|
228
|
+
finishedAt: timeOf(subtask.finishedAt),
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
return chains
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Wall-time share of every worker in a run.
|
|
236
|
+
*
|
|
237
|
+
* `share` is the worker's own span over the run's wall clock, so shares of
|
|
238
|
+
* parallel workers can add up to more than 100%; `parallelism` is that sum and
|
|
239
|
+
* is the run's effective worker concurrency. A worker still running counts to
|
|
240
|
+
* `now`.
|
|
241
|
+
*
|
|
242
|
+
* @param {{ duration: number, subtasks: object[] }} item - prepared run.
|
|
243
|
+
* @param {number} [now] - wall clock.
|
|
244
|
+
*/
|
|
245
|
+
export function workerShares(item, now = Date.now()) {
|
|
246
|
+
const wall = Math.max(0, Number(item?.duration) || 0)
|
|
247
|
+
const workers = []
|
|
248
|
+
for (const subtask of item?.subtasks ?? []) {
|
|
249
|
+
const start = timeOf(subtask.startedAt)
|
|
250
|
+
if (start === null) continue
|
|
251
|
+
const end = timeOf(subtask.finishedAt) ?? (subtask.status === 'running' ? now : null)
|
|
252
|
+
const span = end === null ? 0 : Math.max(0, end - start)
|
|
253
|
+
workers.push({
|
|
254
|
+
index: Number(subtask.index) || workers.length + 1,
|
|
255
|
+
title: String(subtask.title ?? ''),
|
|
256
|
+
status: String(subtask.status ?? 'pending'),
|
|
257
|
+
attempts: attemptsOf(subtask),
|
|
258
|
+
span,
|
|
259
|
+
share: wall > 0 ? span / wall : 0,
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
const busy = workers.reduce((sum, worker) => sum + worker.span, 0)
|
|
263
|
+
return { wall, workers, busy, parallelism: wall > 0 ? busy / wall : 0 }
|
|
264
|
+
}
|
|
265
|
+
|
|
173
266
|
/**
|
|
174
267
|
* Normalise run files into what the page needs, in chronological order.
|
|
175
268
|
* @param {object[]} runs - run records from the store.
|
|
@@ -184,7 +277,11 @@ export function prepare(runs, now) {
|
|
|
184
277
|
const live = ACTIVE_STATUSES.has(run.status)
|
|
185
278
|
const phases = phasesOf(run, now)
|
|
186
279
|
const calls = callsOf(run)
|
|
187
|
-
const
|
|
280
|
+
const priced = run.cost && run.cost.complete !== false
|
|
281
|
+
const cost = priced && Number.isFinite(run.cost?.total) ? run.cost.total : null
|
|
282
|
+
const costMicros = priced
|
|
283
|
+
? (Number.isFinite(run.cost?.totalMicros) ? run.cost.totalMicros : Math.round((run.cost.total ?? 0) * 1e6))
|
|
284
|
+
: null
|
|
188
285
|
items.push({
|
|
189
286
|
run,
|
|
190
287
|
id: String(run.id),
|
|
@@ -195,6 +292,8 @@ export function prepare(runs, now) {
|
|
|
195
292
|
phases,
|
|
196
293
|
calls,
|
|
197
294
|
cost,
|
|
295
|
+
costMicros,
|
|
296
|
+
currency: run.cost?.currency ?? 'USD',
|
|
198
297
|
tokens: run.usage?.totalTokens ?? 0,
|
|
199
298
|
duration: Math.max(0, end - start),
|
|
200
299
|
parent: String(run.parentSessionId ?? ''),
|
|
@@ -212,23 +311,40 @@ function summarize(items) {
|
|
|
212
311
|
const byStatus = {}
|
|
213
312
|
let calls = 0
|
|
214
313
|
let tokens = 0
|
|
215
|
-
|
|
314
|
+
// Integer micro-units: a long list of runs must not drift the cent total.
|
|
315
|
+
let costMicros = 0
|
|
216
316
|
let priced = 0
|
|
217
317
|
let unpriced = 0
|
|
318
|
+
const currencies = new Set()
|
|
218
319
|
for (const item of items) {
|
|
219
320
|
byStatus[item.status] = (byStatus[item.status] ?? 0) + 1
|
|
220
321
|
calls += item.calls
|
|
221
322
|
tokens += item.tokens
|
|
222
|
-
if (item.
|
|
223
|
-
|
|
323
|
+
if (item.costMicros !== null) {
|
|
324
|
+
costMicros += item.costMicros
|
|
224
325
|
priced += 1
|
|
326
|
+
currencies.add(item.currency)
|
|
225
327
|
} else if (item.calls > 0) {
|
|
226
328
|
unpriced += 1
|
|
227
329
|
}
|
|
228
330
|
}
|
|
229
331
|
const start = items.length > 0 ? Math.min(...items.map(item => item.start)) : 0
|
|
230
332
|
const end = items.length > 0 ? Math.max(...items.map(item => item.end)) : 0
|
|
231
|
-
|
|
333
|
+
const currency = currencies.size === 1 ? [...currencies][0] : (currencies.size === 0 ? 'USD' : null)
|
|
334
|
+
return {
|
|
335
|
+
byStatus,
|
|
336
|
+
calls,
|
|
337
|
+
tokens,
|
|
338
|
+
cost: costMicros / 1e6,
|
|
339
|
+
costMicros,
|
|
340
|
+
currency,
|
|
341
|
+
mixedCurrency: currencies.size > 1,
|
|
342
|
+
priced,
|
|
343
|
+
unpriced,
|
|
344
|
+
start,
|
|
345
|
+
end,
|
|
346
|
+
span: Math.max(0, end - start),
|
|
347
|
+
}
|
|
232
348
|
}
|
|
233
349
|
|
|
234
350
|
/**
|
|
@@ -457,6 +573,135 @@ function curveSvg(events, options) {
|
|
|
457
573
|
return parts.join('')
|
|
458
574
|
}
|
|
459
575
|
|
|
576
|
+
/** Outcome word and symbol for the last recorded attempt of a worker. */
|
|
577
|
+
function outcomeOf(chain) {
|
|
578
|
+
if (chain.status === 'completed') return { symbol: '✓', tone: 'ok', text: chain.recovered ? `recovered on attempt ${chain.attempts}` : 'completed' }
|
|
579
|
+
if (chain.status === 'failed') return { symbol: '✕', tone: 'bad', text: `failed after ${chain.attempts} attempt${chain.attempts === 1 ? '' : 's'}` }
|
|
580
|
+
if (chain.status === 'running') return { symbol: '▶', tone: 'live', text: `running · attempt ${chain.attempts}` }
|
|
581
|
+
return { symbol: '…', tone: 'idle', text: `still open · ${chain.attempts} attempt${chain.attempts === 1 ? '' : 's'} spent` }
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Failure and retry chains: which worker failed, how many attempts it burned,
|
|
586
|
+
* and what it ended as. Only runs that actually retried or failed are listed,
|
|
587
|
+
* so a healthy window says so in one line instead of drawing empty boxes.
|
|
588
|
+
*/
|
|
589
|
+
function retriesSection(items) {
|
|
590
|
+
const blocks = []
|
|
591
|
+
for (const item of [...items].sort((a, b) => b.end - a.end)) {
|
|
592
|
+
const chains = retryChainsOf(item.run)
|
|
593
|
+
const heal = item.run?.selfHeal
|
|
594
|
+
if (chains.length === 0 && !heal) continue
|
|
595
|
+
const attempts = chains.reduce((sum, chain) => sum + chain.attempts, 0)
|
|
596
|
+
const color = STATUS_HEX[item.status] ?? '#64748b'
|
|
597
|
+
blocks.push([
|
|
598
|
+
'<article class="retry">',
|
|
599
|
+
'<div class="retry-head">',
|
|
600
|
+
`<span class="chip" style="background:${color}">${escapeHtml(item.status.toUpperCase())}</span>`,
|
|
601
|
+
`<span class="rid">${escapeHtml(item.id)}</span>`,
|
|
602
|
+
`<span class="when">${escapeHtml(stampUtc(item.start))} UTC · ${escapeHtml(formatDuration(item.duration))}</span>`,
|
|
603
|
+
`<span class="tally">${chains.length} worker${chains.length === 1 ? '' : 's'} · ${attempts} attempt${attempts === 1 ? '' : 's'}</span>`,
|
|
604
|
+
'</div>',
|
|
605
|
+
heal
|
|
606
|
+
? `<div class="selfheal">self-heal round ${escapeHtml(String(heal.rounds ?? 1))} · retried ${escapeHtml(String(heal.retried ?? 0))} · recovered ${escapeHtml(String(heal.recovered ?? 0))}${heal.model ? ` · on <code>${escapeHtml(heal.model)}</code>` : ''}</div>`
|
|
607
|
+
: '',
|
|
608
|
+
item.run?.recovery?.previousStatus
|
|
609
|
+
? `<div class="selfheal">resumed after an earlier <code>${escapeHtml(String(item.run.recovery.previousStatus))}</code> attempt</div>`
|
|
610
|
+
: '',
|
|
611
|
+
...chains.map(chain => {
|
|
612
|
+
const outcome = outcomeOf(chain)
|
|
613
|
+
const steps = []
|
|
614
|
+
for (let attempt = 1; attempt <= chain.attempts; attempt++) {
|
|
615
|
+
const last = attempt === chain.attempts
|
|
616
|
+
const tone = last ? outcome.tone : 'bad'
|
|
617
|
+
steps.push(`<span class="step ${tone}">${attempt} ${last ? outcome.symbol : '✕'}</span>`)
|
|
618
|
+
}
|
|
619
|
+
return [
|
|
620
|
+
'<div class="retry-worker">',
|
|
621
|
+
`<div class="worker-head"><span class="widx">#${escapeHtml(String(chain.index))}</span> ${escapeHtml(chain.title)}`,
|
|
622
|
+
`<span class="outcome ${outcome.tone}">${escapeHtml(outcome.text)}</span></div>`,
|
|
623
|
+
`<div class="chain">${steps.join('<span class="arrow">→</span>')}</div>`,
|
|
624
|
+
chain.error
|
|
625
|
+
? `<div class="worker-error"><code>${escapeHtml(chain.error)}</code></div>`
|
|
626
|
+
: chain.stopReason
|
|
627
|
+
? `<div class="worker-error">child stopped with reason <code>${escapeHtml(chain.stopReason)}</code></div>`
|
|
628
|
+
: '',
|
|
629
|
+
'</div>',
|
|
630
|
+
].join('')
|
|
631
|
+
}),
|
|
632
|
+
'</article>',
|
|
633
|
+
].join(''))
|
|
634
|
+
if (blocks.length === 12) break
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (blocks.length === 0) {
|
|
638
|
+
return '<p class="hint">No retries and no failed workers in this window: every started worker finished on its first attempt.</p>'
|
|
639
|
+
}
|
|
640
|
+
const note = blocks.length > 0 && items.length > blocks.length
|
|
641
|
+
? `<p class="hint">Showing the ${blocks.length} most recent runs with retries or failures.</p>`
|
|
642
|
+
: ''
|
|
643
|
+
return `<div class="retries">${blocks.join('')}</div>${note}`
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Worker time share: how the run's wall clock was distributed across its
|
|
648
|
+
* workers. Shares are per worker against the run's wall clock, so parallel
|
|
649
|
+
* workers add up past 100%; the parallelism factor is that sum.
|
|
650
|
+
*/
|
|
651
|
+
function workersSection(items, now) {
|
|
652
|
+
const rows = []
|
|
653
|
+
for (const item of [...items].sort((a, b) => b.duration - a.duration)) {
|
|
654
|
+
const shares = workerShares(item, now)
|
|
655
|
+
if (shares.workers.length === 0) continue
|
|
656
|
+
const color = STATUS_HEX[item.status] ?? '#64748b'
|
|
657
|
+
const segments = []
|
|
658
|
+
let cursor = 0
|
|
659
|
+
shares.workers.forEach((worker, index) => {
|
|
660
|
+
const wx = shares.busy > 0 ? (worker.span / shares.busy) * 1080 : 0
|
|
661
|
+
const fill = WORKER_COLORS[index % WORKER_COLORS.length]
|
|
662
|
+
if (wx > 0) {
|
|
663
|
+
segments.push(`<rect x="${cursor.toFixed(1)}" y="4" width="${Math.max(1, wx).toFixed(1)}" height="18" rx="3" fill="${fill}"><title>${escapeHtml(`${worker.title} · ${formatDuration(worker.span)} · ${percent(worker.share)} of the run's wall clock`)}</title></rect>`)
|
|
664
|
+
}
|
|
665
|
+
cursor += wx
|
|
666
|
+
})
|
|
667
|
+
const listed = shares.workers.slice(0, 6)
|
|
668
|
+
const rest = shares.workers.length - listed.length
|
|
669
|
+
rows.push([
|
|
670
|
+
'<div class="workers-run">',
|
|
671
|
+
'<div class="workers-head">',
|
|
672
|
+
`<span class="chip" style="background:${color}">${escapeHtml(item.status)}</span>`,
|
|
673
|
+
`<span class="rid">${escapeHtml(item.id)}</span>`,
|
|
674
|
+
`<span class="when">wall ${escapeHtml(formatDuration(shares.wall))} · workers busy ${escapeHtml(formatDuration(shares.busy))} · ${shares.parallelism.toFixed(2)}× parallel</span>`,
|
|
675
|
+
'</div>',
|
|
676
|
+
`<svg viewBox="0 0 1080 26" role="img" aria-label="${escapeHtml(`${shares.workers.length} workers of ${item.id} by share of total worker time`)}">`,
|
|
677
|
+
'<rect x="0" y="4" width="1080" height="18" rx="6" fill="#f1f5f9"/>',
|
|
678
|
+
segments.join(''),
|
|
679
|
+
'</svg>',
|
|
680
|
+
'<ul class="worker-list">',
|
|
681
|
+
...listed.map((worker, index) => {
|
|
682
|
+
const fill = WORKER_COLORS[index % WORKER_COLORS.length]
|
|
683
|
+
const outcome = worker.status === 'completed' ? 'done' : worker.status === 'failed' ? 'failed' : worker.status
|
|
684
|
+
return [
|
|
685
|
+
'<li>',
|
|
686
|
+
`<i class="swatch" style="background:${fill}"></i>`,
|
|
687
|
+
`<span class="wtitle">#${escapeHtml(String(worker.index))} ${escapeHtml(worker.title)}</span>`,
|
|
688
|
+
`<span class="wmeta">${escapeHtml(outcome)}${worker.attempts > 1 ? ` · ${escapeHtml(String(worker.attempts))} attempts` : ''} · ${escapeHtml(formatDuration(worker.span))} · ${escapeHtml(percent(worker.share))}</span>`,
|
|
689
|
+
'</li>',
|
|
690
|
+
].join('')
|
|
691
|
+
}),
|
|
692
|
+
rest > 0 ? `<li class="more">+${rest} more worker${rest === 1 ? '' : 's'} in the bar above</li>` : '',
|
|
693
|
+
'</ul>',
|
|
694
|
+
'</div>',
|
|
695
|
+
].join(''))
|
|
696
|
+
if (rows.length === 10) break
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if (rows.length === 0) {
|
|
700
|
+
return '<p class="hint">No worker timings recorded: these runs never started a subtask, or their subtasks carry no <code>startedAt</code>.</p>'
|
|
701
|
+
}
|
|
702
|
+
return `<div class="workers">${rows.join('')}</div>`
|
|
703
|
+
}
|
|
704
|
+
|
|
460
705
|
/** One stat card. */
|
|
461
706
|
function card(label, value, note, accent) {
|
|
462
707
|
return [
|
|
@@ -532,6 +777,40 @@ svg .empty { font-size: 12px; fill: #94a3b8; }
|
|
|
532
777
|
.failure-body { margin-top: 6px; font-size: 12.5px; color: #475569; }
|
|
533
778
|
.failure-body code { font-family: ${MONO_FONT}; font-size: 11.5px; background: #f4f6fa; padding: 1px 5px; border-radius: 4px; }
|
|
534
779
|
.failure .when { color: #8b98a9; font-weight: 400; }
|
|
780
|
+
.retries { display: grid; gap: 12px; }
|
|
781
|
+
.retry { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fff; }
|
|
782
|
+
.retry-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font: 600 11.5px/1.4 ${MONO_FONT}; }
|
|
783
|
+
.retry-head .when, .retry-head .tally { color: #8b98a9; font-weight: 400; }
|
|
784
|
+
.selfheal { margin-top: 9px; font-size: 12px; color: #475569; border-left: 3px solid #b45309; padding: 2px 0 2px 9px; }
|
|
785
|
+
.selfheal code { font-family: ${MONO_FONT}; font-size: 11.5px; background: #f4f6fa; padding: 1px 5px; border-radius: 4px; }
|
|
786
|
+
.retry-worker { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #eef1f5; }
|
|
787
|
+
.worker-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #1e293b; flex-wrap: wrap; }
|
|
788
|
+
.worker-head .widx { font: 600 10.5px ${MONO_FONT}; color: #8b98a9; }
|
|
789
|
+
.worker-head .outcome { font: 600 10px ${MONO_FONT}; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; }
|
|
790
|
+
.outcome.ok { color: #15803d; background: #dcfce7; }
|
|
791
|
+
.outcome.bad { color: #b91c1c; background: #fee2e2; }
|
|
792
|
+
.outcome.live { color: #0284c7; background: #e0f2fe; }
|
|
793
|
+
.outcome.idle { color: #b45309; background: #fef3c7; }
|
|
794
|
+
.chain { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
|
|
795
|
+
.step { font: 600 11px ${MONO_FONT}; padding: 3px 9px; border-radius: 6px; border: 1px solid transparent; }
|
|
796
|
+
.step.ok { color: #15803d; background: #f0fdf4; border-color: #bbf7d0; }
|
|
797
|
+
.step.bad { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
|
|
798
|
+
.step.live { color: #0284c7; background: #f0f9ff; border-color: #bae6fd; }
|
|
799
|
+
.step.idle { color: #b45309; background: #fffbeb; border-color: #fde68a; }
|
|
800
|
+
.arrow { color: #cbd5e1; font-size: 12px; }
|
|
801
|
+
.worker-error { margin-top: 7px; font-size: 12px; color: #475569; }
|
|
802
|
+
.worker-error code { font-family: ${MONO_FONT}; font-size: 11.5px; background: #fef2f2; color: #991b1b; padding: 1px 5px; border-radius: 4px; }
|
|
803
|
+
.workers { display: grid; gap: 16px; }
|
|
804
|
+
.workers-run { border-top: 1px solid #f1f4f8; padding-top: 12px; }
|
|
805
|
+
.workers-run:first-child { border-top: 0; padding-top: 0; }
|
|
806
|
+
.workers-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font: 600 11.5px/1.4 ${MONO_FONT}; margin-bottom: 8px; }
|
|
807
|
+
.workers-head .when { color: #8b98a9; font-weight: 400; }
|
|
808
|
+
.workers svg { min-width: 0; }
|
|
809
|
+
.worker-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 5px 20px; }
|
|
810
|
+
.worker-list li { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #334155; min-width: 0; }
|
|
811
|
+
.worker-list .wtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
812
|
+
.worker-list .wmeta { margin-left: auto; color: #8b98a9; font: 11px ${MONO_FONT}; white-space: nowrap; }
|
|
813
|
+
.worker-list .more { color: #8b98a9; font-size: 11.5px; }
|
|
535
814
|
.table-wrap { overflow-x: auto; }
|
|
536
815
|
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
|
|
537
816
|
th { text-align: left; font: 600 10px/1 ${MONO_FONT}; letter-spacing: .1em; text-transform: uppercase; color: #8b98a9; padding: 0 10px 9px; border-bottom: 1px solid var(--line); }
|
|
@@ -601,7 +880,16 @@ export function buildReport(runs, options = {}) {
|
|
|
601
880
|
card('Failed', String(summary.byStatus.failed ?? 0), `${summary.byStatus.cancelled ?? 0} cancelled · ${summary.byStatus.interrupted ?? 0} interrupted`, '#b91c1c'),
|
|
602
881
|
card('Model calls', formatCount(summary.calls), 'measured from child sessions'),
|
|
603
882
|
card('Tokens', formatCount(summary.tokens), 'input + cache + output'),
|
|
604
|
-
card(
|
|
883
|
+
card(
|
|
884
|
+
'Cost',
|
|
885
|
+
summary.priced === 0
|
|
886
|
+
? 'unpriced'
|
|
887
|
+
: `${moneyOfMicros(summary.costMicros, summary.currency ?? 'USD')}${summary.unpriced > 0 ? '+' : ''}`,
|
|
888
|
+
summary.priced === 0
|
|
889
|
+
? 'no configured price — not shown as zero'
|
|
890
|
+
: `${summary.priced}/${items.length} runs priced${summary.mixedCurrency ? ' · mixed currencies' : ''}`,
|
|
891
|
+
'#0f766e',
|
|
892
|
+
),
|
|
605
893
|
].join('')
|
|
606
894
|
|
|
607
895
|
const cards = [
|
|
@@ -656,13 +944,40 @@ export function buildReport(runs, options = {}) {
|
|
|
656
944
|
`<td><span class="chip" style="background:${color}">${escapeHtml(item.status)}</span><span class="goal" title="${escapeHtml(item.goal)}">${escapeHtml(item.goal)}</span></td>`,
|
|
657
945
|
`<td class="num">${escapeHtml(item.calls ? String(item.calls) : '—')}</td>`,
|
|
658
946
|
`<td class="num">${escapeHtml(item.tokens ? formatCount(item.tokens) : '—')}</td>`,
|
|
659
|
-
`<td class="num">${escapeHtml(
|
|
947
|
+
`<td class="num">${escapeHtml(item.costMicros === null ? 'unpriced' : moneyOfMicros(item.costMicros, item.currency))}</td>`,
|
|
660
948
|
`<td class="num">${escapeHtml(formatDuration(item.duration))}</td>`,
|
|
661
949
|
`<td class="id">${escapeHtml(item.parent.replace(/^session-/, '').slice(0, 8) || '—')}</td>`,
|
|
662
950
|
'</tr>',
|
|
663
951
|
].join('')
|
|
664
952
|
})
|
|
665
953
|
|
|
954
|
+
// Subtask-level spend: only worker children own a subtask, so the planner and
|
|
955
|
+
// the merge step appear in the run total but not here. Rows are emitted only
|
|
956
|
+
// for subtasks that actually recorded a model call.
|
|
957
|
+
const subtaskRows = items.flatMap(item => (item.subtasks ?? [])
|
|
958
|
+
.filter(subtask => subtask?.usage?.modelCalls)
|
|
959
|
+
.map(subtask => {
|
|
960
|
+
const usage = subtask.usage
|
|
961
|
+
const tokens = (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.outputTokens ?? 0)
|
|
962
|
+
const cost = subtask.cost && Object.keys(subtask.cost.byModel ?? {}).length > 0 ? subtask.cost : null
|
|
963
|
+
const costText = cost
|
|
964
|
+
? `${moneyOfMicros(
|
|
965
|
+
Number.isFinite(cost.totalMicros) ? cost.totalMicros : Math.round((cost.total ?? 0) * 1e6),
|
|
966
|
+
cost.currency ?? item.currency,
|
|
967
|
+
)}${cost.complete ? '' : '+'}`
|
|
968
|
+
: 'unpriced'
|
|
969
|
+
return [
|
|
970
|
+
'<tr>',
|
|
971
|
+
`<td class="id">${escapeHtml(item.id)}</td>`,
|
|
972
|
+
`<td class="num">${escapeHtml(String(subtask.index ?? '—'))}</td>`,
|
|
973
|
+
`<td><span class="goal" title="${escapeHtml(subtask.title ?? '')}">${escapeHtml(subtask.title ?? '')}</span></td>`,
|
|
974
|
+
`<td class="num">${escapeHtml(String(usage.modelCalls))}</td>`,
|
|
975
|
+
`<td class="num">${escapeHtml(formatCount(tokens))}</td>`,
|
|
976
|
+
`<td class="num">${escapeHtml(costText)}</td>`,
|
|
977
|
+
'</tr>',
|
|
978
|
+
].join('')
|
|
979
|
+
}))
|
|
980
|
+
|
|
666
981
|
const pricedNote = items.length === 0
|
|
667
982
|
? 'No runs matched this window.'
|
|
668
983
|
: summary.unpriced > 0
|
|
@@ -695,6 +1010,11 @@ export function buildReport(runs, options = {}) {
|
|
|
695
1010
|
<div class="panel-head"><h2>Concurrency</h2><span class="hint">${laneCount} lane${laneCount === 1 ? '' : 's'} · overlapping runs never share a lane</span></div>
|
|
696
1011
|
<figure>${lanesSvg(items, { start, end, ticks, lanes: laneCount })}</figure>
|
|
697
1012
|
</section>
|
|
1013
|
+
<section class="panel" id="retries">
|
|
1014
|
+
<div class="panel-head"><h2>Failure & retry chains</h2><span class="hint">which worker failed · attempts spent · what it ended as</span></div>
|
|
1015
|
+
${retriesSection(items)}
|
|
1016
|
+
<p class="hint">A run file keeps the latest error per worker, so earlier attempts are counted but cannot quote their own message. A self-heal round resets a worker's attempt counter, which is why its steps describe the latest round.</p>
|
|
1017
|
+
</section>
|
|
698
1018
|
<div class="charts">
|
|
699
1019
|
<section class="panel" id="calls">
|
|
700
1020
|
<div class="panel-head"><h2>Model calls</h2><span class="hint">cumulative at each run's end</span></div>
|
|
@@ -703,10 +1023,14 @@ export function buildReport(runs, options = {}) {
|
|
|
703
1023
|
</section>
|
|
704
1024
|
<section class="panel" id="cost">
|
|
705
1025
|
<div class="panel-head"><h2>Cost</h2><span class="hint">cumulative at each run's end</span></div>
|
|
706
|
-
<figure>${curveSvg(costEvents, { start, end, ticks, color: '#0f766e', title: 'Cumulative cost', formatter: value => money(value), empty: 'no priced runs' })}</figure>
|
|
1026
|
+
<figure>${curveSvg(costEvents, { start, end, ticks, color: '#0f766e', title: 'Cumulative cost', formatter: value => money(value, summary.currency ?? 'USD'), empty: 'no priced runs' })}</figure>
|
|
707
1027
|
<p class="hint">${escapeHtml(pricedNote)}</p>
|
|
708
1028
|
</section>
|
|
709
1029
|
</div>
|
|
1030
|
+
<section class="panel" id="workers">
|
|
1031
|
+
<div class="panel-head"><h2>Worker time share</h2><span class="hint">each worker's span against the run's wall clock · bar = share of total worker time</span></div>
|
|
1032
|
+
${workersSection(items, now)}
|
|
1033
|
+
</section>
|
|
710
1034
|
<section class="panel" id="failures">
|
|
711
1035
|
<div class="panel-head"><h2>Failures & cancellations</h2><span class="hint">every run that did not complete normally</span></div>
|
|
712
1036
|
${failures}
|
|
@@ -720,6 +1044,17 @@ export function buildReport(runs, options = {}) {
|
|
|
720
1044
|
</table>
|
|
721
1045
|
</div>
|
|
722
1046
|
</section>
|
|
1047
|
+
<section class="panel" id="subtasks">
|
|
1048
|
+
<div class="panel-head"><h2>Subtask cost</h2><span class="hint">worker children only · planner and merge calls appear in the run total · a “+” marks an incomplete figure</span></div>
|
|
1049
|
+
${subtaskRows.length === 0
|
|
1050
|
+
? '<p class="hint">No subtask recorded a model call in this window.</p>'
|
|
1051
|
+
: `<div class="table-wrap">
|
|
1052
|
+
<table>
|
|
1053
|
+
<thead><tr><th>Run</th><th style="text-align:right">#</th><th>Subtask</th><th style="text-align:right">Calls</th><th style="text-align:right">Tokens</th><th style="text-align:right">Cost</th></tr></thead>
|
|
1054
|
+
<tbody>${subtaskRows.join('')}</tbody>
|
|
1055
|
+
</table>
|
|
1056
|
+
</div>`}
|
|
1057
|
+
</section>
|
|
723
1058
|
<footer>
|
|
724
1059
|
Self-contained report: inline CSS and inline SVG, no scripts, no external fonts or images, no network access.
|
|
725
1060
|
Phases are inferred from <code>startedAt</code>/<code>finishedAt</code> of the run and its subtasks; a run file does not record phase boundaries directly.
|