Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/collect/subagents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ export async function agentContext(path: string) {
// the two entries the fields below are derived from, picked as the tail
// streams past so no pass holds every parsed entry alive at once
let lastUsage: any; // newest assistant message carrying usage
let last: any; // newest entry of any kind
// newest conversation entry (user/assistant). Attachments are skipped: the
// harness appends them after a tool result (a total_tokens_reminder, say),
// so the newest entry of any kind would hide the tool_result that marks the
// agent as mid-flight.
let last: any;
const { ok } = await readTailEntries(path, (e) => {
if (e?.type === "assistant" && e.message?.usage) lastUsage = e.message;
last = e;
if (e?.type === "user" || e?.type === "assistant") last = e;
});
out.ok = ok;
// a malformed entry must not escape: this runs inside collectRows, whose
Expand Down
18 changes: 18 additions & 0 deletions test/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,24 @@ describe("transcript file scanning", () => {
expect((await __test.agentContext(finished)).running).toBe(false);
});

test("looks past trailing attachments to the last conversation entry", async () => {
const path = write(
"agent-6.jsonl",
jsonl([
assistant("claude-opus-5", { input_tokens: 8 }, [
{ type: "tool_use", name: "Write", input: { file_path: "a.ts" } },
]),
user([{ type: "tool_result", content: "ok" }]),
{
type: "attachment",
attachment: { type: "total_tokens_reminder", text: "..." },
},
]),
);
const ctx = await __test.agentContext(path);
expect(ctx.running).toBe(true); // the tool_result, not the attachment
});

// collectRows runs from a floating promise, so a throw out of here would
// take the whole TUI down over one malformed line in one agent transcript
test("survives a malformed entry instead of throwing", async () => {
Expand Down
Loading