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.
69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import * as path from "node:path";
|
|
import { AgentOutputManager } from "@oh-my-pi/pi-coding-agent/task/output-manager";
|
|
import { TempDir } from "@oh-my-pi/pi-utils";
|
|
|
|
// Contract: subagent output ids are the requested name, used verbatim the first
|
|
// time and suffixed (`-2`, `-3`, …) only when the same name recurs. A parent
|
|
// prefix nests ids under it. On resume the manager scans existing `.md` outputs
|
|
// so it never reuses a name that would clobber a previously written output.
|
|
|
|
describe("AgentOutputManager", () => {
|
|
it("uses the requested name verbatim and suffixes only on repeat", async () => {
|
|
const mgr = new AgentOutputManager(() => null);
|
|
|
|
expect(await mgr.allocate("Anna")).toBe("Anna");
|
|
expect(await mgr.allocate("Anna")).toBe("Anna-2");
|
|
expect(await mgr.allocate("Anna")).toBe("Anna-3");
|
|
// A distinct name is untouched — no prefix, no suffix.
|
|
expect(await mgr.allocate("Bob")).toBe("Bob");
|
|
});
|
|
|
|
it("de-duplicates repeated names while preserving order", async () => {
|
|
const mgr = new AgentOutputManager(() => null);
|
|
|
|
const ids: string[] = [];
|
|
for (const name of ["Auth", "Auth", "Api", "Auth"]) {
|
|
ids.push(await mgr.allocate(name));
|
|
}
|
|
expect(ids).toEqual(["Auth", "Auth-2", "Api", "Auth-3"]);
|
|
});
|
|
|
|
it("nests ids under a parent prefix and still suffixes repeats", async () => {
|
|
const mgr = new AgentOutputManager(() => null, { parentPrefix: "Anna" });
|
|
|
|
expect(await mgr.allocate("Bob")).toBe("Anna.Bob");
|
|
expect(await mgr.allocate("Bob")).toBe("Anna.Bob-2");
|
|
expect(await mgr.allocate("Carol")).toBe("Anna.Carol");
|
|
});
|
|
|
|
it("scans existing output files so a resume never clobbers prior outputs", async () => {
|
|
using tmp = TempDir.createSync("@omp-output-manager-");
|
|
const dir = tmp.path();
|
|
await Bun.write(path.join(dir, "Anna.md"), "prior");
|
|
await Bun.write(path.join(dir, "Anna-2.md"), "prior");
|
|
// Unrelated tool artifacts (numeric `.log` ids) must not be mistaken for names.
|
|
await Bun.write(path.join(dir, "7.bash.log"), "noise");
|
|
|
|
const mgr = new AgentOutputManager(() => dir);
|
|
|
|
expect(await mgr.allocate("Anna")).toBe("Anna-3");
|
|
// A name with no file on disk is still pristine.
|
|
expect(await mgr.allocate("Bob")).toBe("Bob");
|
|
});
|
|
|
|
it("only counts files within its own prefix scope on resume", async () => {
|
|
using tmp = TempDir.createSync("@omp-output-manager-");
|
|
const dir = tmp.path();
|
|
await Bun.write(path.join(dir, "Anna.Bob.md"), "child");
|
|
await Bun.write(path.join(dir, "Anna.Bob.Carol.md"), "grandchild");
|
|
// A different parent's child must be ignored by Anna's manager.
|
|
await Bun.write(path.join(dir, "Other.Bob.md"), "elsewhere");
|
|
|
|
const mgr = new AgentOutputManager(() => dir, { parentPrefix: "Anna" });
|
|
|
|
expect(await mgr.allocate("Bob")).toBe("Anna.Bob-2");
|
|
expect(await mgr.allocate("Dave")).toBe("Anna.Dave");
|
|
});
|
|
});
|