Files
oh-my-pi/packages/coding-agent/test/task/spawn-advisory.test.ts
T
metaphorics a6cce473ac feat(task): nudge generic spawns toward specialization
When a spawner with remaining depth capacity spawns generic role-less
workers (a task/quick_task spawn without a `role`, or the same agent
cloned >=2x all without roles), TaskTool.execute appends a non-blocking
advisory steering it toward tailored specialists. Gated on DepthCapacity
so a leaf at max recursion is never nudged; the task-tool depth gate is
extracted into a shared `canSpawnAtDepth` helper reused by both the tool
gate and the advisory.

Refs #2469

Op: extend
2026-06-14 08:47:01 +09:00

39 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { buildSpecializationAdvisory } from "@oh-my-pi/pi-coding-agent/task";
import type { TaskItem } from "@oh-my-pi/pi-coding-agent/task/types";
// Contract: the task tool appends an advisory (never a rejection) steering the
// spawner toward tailored specialists when it spawns generic role-less workers
// and still holds spawn capacity (DepthCapacity). It is gated on depth so a
// leaf at max recursion is never nagged.
const item = (role?: string): TaskItem => ({ assignment: "do the thing", role });
describe("buildSpecializationAdvisory", () => {
it("nudges a generic role-less spawn when depth capacity remains", () => {
const advice = buildSpecializationAdvisory("task", [item()], true);
expect(advice).toBeDefined();
expect(advice).toContain("`role`");
});
it("stays silent at max depth even for a generic role-less spawn", () => {
expect(buildSpecializationAdvisory("task", [item()], false)).toBeUndefined();
});
it("stays silent when the spawn already carries a role", () => {
expect(buildSpecializationAdvisory("task", [item("Rust async-runtime specialist")], true)).toBeUndefined();
});
it("treats a whitespace-only role as absent and nudges", () => {
expect(buildSpecializationAdvisory("quick_task", [item(" ")], true)).toBeDefined();
});
it("nudges when one call clones the same agent twice without roles", () => {
expect(buildSpecializationAdvisory("reviewer", [item(), item()], true)).toBeDefined();
});
it("stays silent for a single non-generic role-less spawn", () => {
expect(buildSpecializationAdvisory("reviewer", [item()], true)).toBeUndefined();
});
});