9d99ae1af0
The task tool now takes a single { agent, assignment, description, ... } and always runs the subagent in the background — the batch tasks[] array and shared context parameter are gone. Fan-out is parallel task calls; shared background flows through a '/Users/can/.omp/agent/sessions/-Projects-.tree-pi-commit/2026-06-10T15-36-32-782Z_019eb22d-970e-7000-8964-72c98becf3e8/local' file referenced in each assignment.\n\nIntroduces a persistent subagent lifecycle: finished subagents stay live as idle, the lifecycle manager parks them to disk after task.agentIdleTtlMs (default 7 minutes; 0 keeps them live until exit), and they revive automatically when prompted from the Agent Hub, messaged on IRC, or resumed via task. New task(resume: "<id>") revives an idle or parked subagent and runs a follow-up assignment in its existing session.\n\nAdds soft request budgets (explore/quick_task 40, others 90, configurable via task.softRequestBudget, 0 disables): crossing the budget injects a one-time wrap-up steer into the child; crossing 1.5× aborts the run gracefully. Cancelled/aborted subagent salvage replaces the old (no output) with the child's last activity snippet plus request/token stats; SingleResult tracks a per-child requests counter (assistant message_end events) used to sort agent lists in runtime-ascending order in both the live progress view (finished agents above pending/running) and the finalized result view, so rows no longer reshuffle on finalize. Adds a task gallery fixture variant for the resume path (renderer key separated from fixture key).\n\nAll task tests are reshaped around the single-call contract; tests for the discarded shared-context flow are removed, and new task-guards/task-resume/task-schema tests pin the new contract surface.
128 lines
4.2 KiB
TypeScript
128 lines
4.2 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
import { resetSettingsForTest, Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { getThemeByName, setThemeInstance, type Theme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
|
|
import type { TaskParams } from "@oh-my-pi/pi-coding-agent/task";
|
|
import { taskToolRenderer } from "@oh-my-pi/pi-coding-agent/task/render";
|
|
|
|
describe("task renderer: streaming call preview", () => {
|
|
let theme: Theme;
|
|
|
|
beforeAll(async () => {
|
|
resetSettingsForTest();
|
|
await Settings.init({ inMemory: true, cwd: process.cwd() });
|
|
const resolved = await getThemeByName("dark");
|
|
expect(resolved).toBeDefined();
|
|
theme = resolved!;
|
|
setThemeInstance(theme);
|
|
});
|
|
|
|
afterAll(() => {
|
|
resetSettingsForTest();
|
|
});
|
|
|
|
function render(args: TaskParams, expanded = false): string {
|
|
const component = taskToolRenderer.renderCall(args, { expanded, isPartial: true }, theme);
|
|
return Bun.stripANSI(component.render(160).join("\n"));
|
|
}
|
|
|
|
// The preview must surface the agent id + ui description so the user can
|
|
// see what is being dispatched while args stream in.
|
|
it("shows the agent id, description, and assignment preview", () => {
|
|
const args: TaskParams = {
|
|
agent: "reviewer",
|
|
id: "ReviewAuth",
|
|
description: "Audit the auth module",
|
|
assignment: "Review packages/server/src/auth for missing 401 handling.\nReport findings.",
|
|
};
|
|
const out = render(args);
|
|
|
|
expect(out).toContain("reviewer");
|
|
expect(out).toContain("ReviewAuth");
|
|
expect(out).toContain("Audit the auth module");
|
|
expect(out).toContain("Review packages/server/src/auth for missing 401 handling.");
|
|
});
|
|
|
|
it("renders partially-streamed args without crashing", () => {
|
|
const args = {
|
|
agent: "task",
|
|
id: "First",
|
|
// description/assignment not yet arrived.
|
|
} as unknown as TaskParams;
|
|
|
|
const out = render(args);
|
|
|
|
expect(out).toContain("First");
|
|
expect(out).toContain("task");
|
|
});
|
|
|
|
it("always renders the full assignment markdown, collapsed or expanded", () => {
|
|
const assignmentLines = Array.from({ length: 6 }, (_, i) => `Step ${i + 1}: do the thing.`);
|
|
const args: TaskParams = {
|
|
agent: "task",
|
|
id: "Worker",
|
|
assignment: assignmentLines.join("\n"),
|
|
};
|
|
|
|
// The assignment is the brief handed to the subagent; it renders as
|
|
// markdown in full regardless of the expanded toggle.
|
|
const collapsed = render(args, false);
|
|
expect(collapsed).toContain("Step 1");
|
|
expect(collapsed).toContain("Step 6");
|
|
|
|
const expanded = render(args, true);
|
|
expect(expanded).toContain("Step 1");
|
|
expect(expanded).toContain("Step 6");
|
|
});
|
|
|
|
it("surfaces the isolation flag in the header bar", () => {
|
|
const args: TaskParams = {
|
|
agent: "task",
|
|
isolated: true,
|
|
id: "Only",
|
|
description: "Single task",
|
|
assignment: "...",
|
|
};
|
|
const out = render(args);
|
|
const lines = out.split("\n");
|
|
|
|
expect(out).toContain("Only");
|
|
// Isolation is surfaced as header meta in the frame's top bar (first line),
|
|
// not as a trailing child row under the task list.
|
|
expect(lines[0]).toContain("isolated");
|
|
});
|
|
|
|
it("labels resume calls with the resumed agent id", () => {
|
|
const args: TaskParams = {
|
|
resume: "AuthLoader",
|
|
assignment: "Also check the refresh-token path.",
|
|
};
|
|
const out = render(args);
|
|
const lines = out.split("\n");
|
|
|
|
expect(lines[0]).toContain("resume AuthLoader");
|
|
expect(out).toContain("Also check the refresh-token path.");
|
|
});
|
|
|
|
// Once the tool produces a result, the container suppresses the call entirely
|
|
// via `mergeCallAndResult` and `renderResult` draws the agent. As a safety
|
|
// net, `renderCall` also drops its preview when a result snapshot is present,
|
|
// so the two never stack.
|
|
it("drops the preview once a result snapshot exists", () => {
|
|
const args: TaskParams = {
|
|
agent: "reviewer",
|
|
id: "ReviewAuth",
|
|
description: "Audit the auth module",
|
|
assignment: "Review the auth module.",
|
|
};
|
|
const component = taskToolRenderer.renderCall(
|
|
args,
|
|
{ expanded: false, isPartial: true, renderContext: { hasResult: true } },
|
|
theme,
|
|
);
|
|
const out = Bun.stripANSI(component.render(160).join("\n"));
|
|
|
|
expect(out).not.toContain("Audit the auth module");
|
|
expect(out).not.toContain("Review the auth module.");
|
|
});
|
|
});
|