feat(progress): humanize subagent updates

This commit is contained in:
pi
2026-04-12 10:17:48 +01:00
parent a4e627084d
commit 86335c2971
8 changed files with 515 additions and 25 deletions

View File

@@ -250,6 +250,66 @@ test("wrapper does not exit early on non-terminal toolUse assistant messages", a
assert.match(eventsText, /"type":"tool_call"/);
});
test("wrapper skips blank assistant transcript lines before later tool activity", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-subagents-wrapper-"));
const metaPath = join(dir, "meta.json");
const resultPath = join(dir, "result.json");
const transcriptPath = join(dir, "transcript.log");
const piPath = join(dir, "pi");
await writeFile(
piPath,
[
`#!${process.execPath}`,
"console.log(JSON.stringify({type:'message_end',message:{role:'assistant',content:[{type:'text',text:' '}],model:'openai/gpt-5',stopReason:'toolUse'}}));",
"setTimeout(() => console.log(JSON.stringify({type:'tool_execution_start',toolName:'read',args:{path:'src/auth.ts'}})), 100);",
"setTimeout(() => console.log(JSON.stringify({type:'message_end',message:{role:'assistant',content:[{type:'text',text:'done'}],model:'openai/gpt-5',stopReason:'stop'}})), 200);",
"setTimeout(() => process.exit(0), 400);",
].join("\n"),
"utf8",
);
await chmod(piPath, 0o755);
await writeFile(
metaPath,
JSON.stringify(
{
runId: "run-1",
mode: "single",
task: "inspect auth",
cwd: dir,
requestedModel: "openai/gpt-5",
resolvedModel: "openai/gpt-5",
startedAt: "2026-04-09T00:00:00.000Z",
sessionPath: join(dir, "child-session.jsonl"),
eventsPath: join(dir, "events.jsonl"),
resultPath,
stdoutPath: join(dir, "stdout.log"),
stderrPath: join(dir, "stderr.log"),
transcriptPath,
systemPromptPath: join(dir, "system-prompt.md"),
},
null,
2,
),
"utf8",
);
const wrapperPath = join(dirname(fileURLToPath(import.meta.url)), "cli.mjs");
const child = spawn(process.execPath, [wrapperPath, metaPath], {
env: { ...process.env, PATH: dir },
stdio: ["ignore", "pipe", "pipe"],
});
const exitCode = await waitForExit(child, 2500);
assert.equal(exitCode, 0);
const transcript = await readFile(transcriptPath, "utf8");
assert.doesNotMatch(transcript, /\nnull\n/);
assert.match(transcript, /Reading src\/auth.ts/);
assert.match(transcript, /done/);
});
test("wrapper exits and writes result.json after terminal output even if the pi child lingers", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-subagents-wrapper-"));
const metaPath = join(dir, "meta.json");