GET /api/tasks/{id}/logs was fully working -- internal/logging's
decode() already captures every JSON field generically (stage,
tokens, iterations, model, everything) -- but nothing in the
dashboard ever called it. The only Logs page hit the daemon-wide
feed, which never carries this per-stage/per-agent-run detail in the
first place. An operator could never see why a task took as long as
it did or its token spend breakdown, even though the daemon already
recorded and could already serve it.
Adds a collapsible attempt-log section to each task's existing
timeline drill-down, reusing the daemon-wide page's row rendering
(extracted to ui/src/base/log-row.js as the shared second consumer).
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import "./shim.js";
|
|
import { logRow, levelKind, fmtValue, shortTime } from "../src/base/log-row.js";
|
|
|
|
test("levelKind maps known levels to their pill kind", () => {
|
|
assert.equal(levelKind("ERROR"), "danger");
|
|
assert.equal(levelKind("warn"), "warn");
|
|
assert.equal(levelKind("Debug"), "idle");
|
|
assert.equal(levelKind("info"), "info");
|
|
assert.equal(levelKind(""), "info");
|
|
});
|
|
|
|
test("fmtValue stringifies objects, passes scalars through, and blanks nullish", () => {
|
|
assert.equal(fmtValue(null), "");
|
|
assert.equal(fmtValue(undefined), "");
|
|
assert.equal(fmtValue(5), 5);
|
|
assert.equal(fmtValue({ a: 1 }), JSON.stringify({ a: 1 }));
|
|
});
|
|
|
|
test("shortTime falls back to a placeholder for an unparsable time", () => {
|
|
assert.equal(shortTime("not a date"), "--:--:--");
|
|
});
|
|
|
|
test("logRow renders every field generically, including the ones the daemon-wide feed drops", () => {
|
|
const row = logRow({
|
|
time: "2026-01-01T00:00:00Z",
|
|
level: "info",
|
|
msg: "attempt finished",
|
|
fields: {
|
|
stage: "tdd",
|
|
prompt_tokens: 100,
|
|
completion_tokens: 40,
|
|
cached_tokens: 10,
|
|
stop_reason: "end_turn",
|
|
model: "sonnet-5",
|
|
},
|
|
});
|
|
assert.match(row.className, /log-row/);
|
|
assert.match(row.textContent, /attempt finished/);
|
|
for (const key of ["stage", "prompt_tokens", "completion_tokens", "cached_tokens", "stop_reason", "model"]) {
|
|
assert.match(row.textContent, new RegExp(key), `missing field ${key}`);
|
|
}
|
|
});
|