refactor: remove role metadata from subagent artifacts
This commit is contained in:
@@ -11,11 +11,12 @@ test("createRunArtifacts writes metadata and reserves stable artifact paths", as
|
||||
const artifacts = await createRunArtifacts(cwd, {
|
||||
runId: "run-1",
|
||||
task: "inspect auth",
|
||||
systemPrompt: "You are scout",
|
||||
});
|
||||
|
||||
assert.equal(artifacts.runId, "run-1");
|
||||
assert.match(artifacts.dir, /\.pi\/subagents\/runs\/run-1$/);
|
||||
assert.equal(JSON.parse(await readFile(artifacts.metaPath, "utf8")).task, "inspect auth");
|
||||
assert.equal(await readFile(artifacts.systemPromptPath, "utf8"), "You are scout");
|
||||
const meta = JSON.parse(await readFile(artifacts.metaPath, "utf8"));
|
||||
assert.equal(meta.task, "inspect auth");
|
||||
assert.equal("systemPromptPath" in meta, false);
|
||||
await assert.rejects(readFile(join(artifacts.dir, "system-prompt.md"), "utf8"));
|
||||
});
|
||||
|
||||
@@ -12,12 +12,11 @@ export interface RunArtifacts {
|
||||
stderrPath: string;
|
||||
transcriptPath: string;
|
||||
sessionPath: string;
|
||||
systemPromptPath: string;
|
||||
}
|
||||
|
||||
export async function createRunArtifacts(
|
||||
cwd: string,
|
||||
meta: Record<string, unknown> & { runId?: string; systemPrompt?: string },
|
||||
meta: Record<string, unknown> & { runId?: string },
|
||||
): Promise<RunArtifacts> {
|
||||
const runId = meta.runId ?? randomUUID();
|
||||
const dir = resolve(cwd, ".pi", "subagents", "runs", runId);
|
||||
@@ -33,7 +32,6 @@ export async function createRunArtifacts(
|
||||
stderrPath: join(dir, "stderr.log"),
|
||||
transcriptPath: join(dir, "transcript.log"),
|
||||
sessionPath: join(dir, "child-session.jsonl"),
|
||||
systemPromptPath: join(dir, "system-prompt.md"),
|
||||
};
|
||||
|
||||
await writeFile(
|
||||
@@ -48,7 +46,6 @@ export async function createRunArtifacts(
|
||||
stdoutPath: artifacts.stdoutPath,
|
||||
stderrPath: artifacts.stderrPath,
|
||||
transcriptPath: artifacts.transcriptPath,
|
||||
systemPromptPath: artifacts.systemPromptPath,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
@@ -56,7 +53,6 @@ export async function createRunArtifacts(
|
||||
"utf8",
|
||||
);
|
||||
|
||||
await writeFile(artifacts.systemPromptPath, typeof meta.systemPrompt === "string" ? meta.systemPrompt : "", "utf8");
|
||||
await writeFile(artifacts.eventsPath, "", "utf8");
|
||||
await writeFile(artifacts.stdoutPath, "", "utf8");
|
||||
await writeFile(artifacts.stderrPath, "", "utf8");
|
||||
|
||||
@@ -30,8 +30,6 @@ test("createProcessSingleRunner launches wrapper without tmux and returns monito
|
||||
{
|
||||
runId: meta.runId,
|
||||
mode: meta.mode,
|
||||
agent: meta.agent,
|
||||
agentSource: meta.agentSource,
|
||||
task: meta.task,
|
||||
requestedModel: meta.requestedModel,
|
||||
resolvedModel: meta.resolvedModel,
|
||||
@@ -60,8 +58,6 @@ test("createProcessSingleRunner launches wrapper without tmux and returns monito
|
||||
cwd,
|
||||
meta: {
|
||||
mode: "single",
|
||||
agent: "scout",
|
||||
agentSource: "builtin",
|
||||
task: "inspect auth",
|
||||
requestedModel: "openai/gpt-5",
|
||||
resolvedModel: "openai/gpt-5",
|
||||
@@ -95,8 +91,6 @@ test("createProcessSingleRunner writes error result.json when wrapper launch fai
|
||||
cwd,
|
||||
meta: {
|
||||
mode: "single",
|
||||
agent: "scout",
|
||||
agentSource: "builtin",
|
||||
task: "inspect auth",
|
||||
requestedModel: "openai/gpt-5",
|
||||
resolvedModel: "openai/gpt-5",
|
||||
@@ -109,5 +103,6 @@ test("createProcessSingleRunner writes error result.json when wrapper launch fai
|
||||
|
||||
const saved = JSON.parse(await readFile(result.resultPath!, "utf8"));
|
||||
assert.equal(saved.exitCode, 1);
|
||||
assert.equal("agent" in saved, false);
|
||||
assert.match(saved.errorMessage ?? "", /spawn boom/);
|
||||
});
|
||||
|
||||
@@ -11,8 +11,6 @@ function makeLaunchFailureResult(artifacts: any, meta: Record<string, unknown>,
|
||||
mode: meta.mode,
|
||||
taskIndex: meta.taskIndex,
|
||||
step: meta.step,
|
||||
agent: meta.agent,
|
||||
agentSource: meta.agentSource,
|
||||
task: meta.task,
|
||||
cwd,
|
||||
requestedModel: meta.requestedModel,
|
||||
|
||||
@@ -34,8 +34,6 @@ function makeResult(meta, startedAt, input = {}) {
|
||||
mode: meta.mode,
|
||||
taskIndex: meta.taskIndex,
|
||||
step: meta.step,
|
||||
agent: meta.agent,
|
||||
agentSource: meta.agentSource,
|
||||
task: meta.task,
|
||||
cwd: meta.cwd,
|
||||
requestedModel: meta.requestedModel,
|
||||
@@ -69,8 +67,6 @@ async function runWrapper(meta, startedAt) {
|
||||
|
||||
const args = ["--mode", "json", "--session", meta.sessionPath];
|
||||
if (effectiveModel) args.push("--model", effectiveModel);
|
||||
if (Array.isArray(meta.tools) && meta.tools.length > 0) args.push("--tools", meta.tools.join(","));
|
||||
if (meta.systemPromptPath) args.push("--append-system-prompt", meta.systemPromptPath);
|
||||
args.push(meta.task);
|
||||
|
||||
let finalText = "";
|
||||
|
||||
@@ -32,8 +32,6 @@ async function runWrapperWithFakePi(requestedModel: string, resolvedModel?: stri
|
||||
const capturePath = join(dir, "capture.json");
|
||||
const piPath = join(dir, "pi");
|
||||
|
||||
// The fake `pi` is a small Node script that writes a JSON capture file
|
||||
// including relevant PI_* environment variables and the argv it received.
|
||||
const resolved = typeof resolvedModel === "string" ? resolvedModel : requestedModel;
|
||||
await writeFile(
|
||||
piPath,
|
||||
@@ -59,8 +57,6 @@ async function runWrapperWithFakePi(requestedModel: string, resolvedModel?: stri
|
||||
{
|
||||
runId: "run-1",
|
||||
mode: "single",
|
||||
agent: "scout",
|
||||
agentSource: "builtin",
|
||||
task: "inspect auth",
|
||||
cwd: dir,
|
||||
requestedModel,
|
||||
@@ -72,6 +68,7 @@ async function runWrapperWithFakePi(requestedModel: string, resolvedModel?: stri
|
||||
stdoutPath: join(dir, "stdout.log"),
|
||||
stderrPath: join(dir, "stderr.log"),
|
||||
transcriptPath: join(dir, "transcript.log"),
|
||||
tools: ["read", "grep"],
|
||||
systemPromptPath: join(dir, "system-prompt.md"),
|
||||
},
|
||||
null,
|
||||
@@ -96,7 +93,6 @@ async function runWrapperWithFakePi(requestedModel: string, resolvedModel?: stri
|
||||
return { flags: captureJson };
|
||||
}
|
||||
|
||||
// Dedicated tests: every child run must have PI_SUBAGENTS_CHILD=1
|
||||
test("wrapper marks github-copilot child run as a subagent child", async () => {
|
||||
const captured = await runWrapperWithFakePi("github-copilot/gpt-4o");
|
||||
assert.equal(captured.flags.PI_SUBAGENTS_CHILD, "1");
|
||||
@@ -107,6 +103,12 @@ test("wrapper marks anthropic child run as a subagent child", async () => {
|
||||
assert.equal(captured.flags.PI_SUBAGENTS_CHILD, "1");
|
||||
});
|
||||
|
||||
test("wrapper ignores stale tool and system prompt metadata", async () => {
|
||||
const captured = await runWrapperWithFakePi("anthropic/claude-sonnet-4-5");
|
||||
assert.equal(captured.flags.argv.includes("--tools"), false);
|
||||
assert.equal(captured.flags.argv.includes("--append-system-prompt"), false);
|
||||
});
|
||||
|
||||
test("wrapper marks github-copilot child runs as agent-initiated", async () => {
|
||||
const captured = await runWrapperWithFakePi("github-copilot/gpt-4o");
|
||||
assert.equal(captured.flags.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR, "agent");
|
||||
@@ -115,25 +117,19 @@ test("wrapper marks github-copilot child runs as agent-initiated", async () => {
|
||||
|
||||
test("wrapper leaves non-copilot child runs unchanged", async () => {
|
||||
const captured = await runWrapperWithFakePi("anthropic/claude-sonnet-4-5");
|
||||
// The wrapper should not inject the copilot initiator for non-copilot models.
|
||||
assert.equal(captured.flags.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR, "");
|
||||
assert.equal(captured.flags.PI_SUBAGENTS_CHILD, "1");
|
||||
});
|
||||
|
||||
// Regression test: ensure when requestedModel and resolvedModel differ, the
|
||||
// wrapper uses the same effective model for the child --model arg and the
|
||||
// copilot initiator env flag.
|
||||
test("wrapper uses effective model for both argv and env when requested/resolved differ", async () => {
|
||||
const requested = "anthropic/claude-sonnet-4-5";
|
||||
const resolved = "github-copilot/gpt-4o";
|
||||
|
||||
const captured = await runWrapperWithFakePi(requested, resolved);
|
||||
|
||||
// The effective model should be the resolved model in this case.
|
||||
assert.equal(captured.flags.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR, "agent");
|
||||
assert.equal(captured.flags.PI_SUBAGENTS_CHILD, "1");
|
||||
|
||||
// Verify the child argv contains the effective model after a --model flag.
|
||||
const argv = captured.flags.argv;
|
||||
const modelIndex = argv.indexOf("--model");
|
||||
assert.ok(modelIndex >= 0, "expected --model in argv");
|
||||
@@ -151,8 +147,6 @@ test("wrapper exits and writes result.json when the pi child cannot be spawned",
|
||||
{
|
||||
runId: "run-1",
|
||||
mode: "single",
|
||||
agent: "scout",
|
||||
agentSource: "builtin",
|
||||
task: "inspect auth",
|
||||
cwd: dir,
|
||||
requestedModel: "anthropic/claude-sonnet-4-5",
|
||||
@@ -186,7 +180,8 @@ test("wrapper exits and writes result.json when the pi child cannot be spawned",
|
||||
|
||||
const result = JSON.parse(await readFile(resultPath, "utf8"));
|
||||
assert.equal(result.runId, "run-1");
|
||||
assert.equal(result.agent, "scout");
|
||||
assert.equal(result.task, "inspect auth");
|
||||
assert.equal("agent" in result, false);
|
||||
assert.equal(result.exitCode, 1);
|
||||
assert.match(result.errorMessage ?? "", /ENOENT|not found|spawn pi/i);
|
||||
});
|
||||
@@ -217,8 +212,6 @@ test("wrapper does not exit early on non-terminal toolUse assistant messages", a
|
||||
{
|
||||
runId: "run-1",
|
||||
mode: "single",
|
||||
agent: "scout",
|
||||
agentSource: "builtin",
|
||||
task: "inspect auth",
|
||||
cwd: dir,
|
||||
requestedModel: "openai/gpt-5",
|
||||
@@ -280,8 +273,6 @@ test("wrapper exits and writes result.json after terminal output even if the pi
|
||||
{
|
||||
runId: "run-1",
|
||||
mode: "single",
|
||||
agent: "scout",
|
||||
agentSource: "builtin",
|
||||
task: "inspect auth",
|
||||
cwd: dir,
|
||||
requestedModel: "openai/gpt-5",
|
||||
@@ -341,8 +332,6 @@ test("wrapper still writes result.json when transcript/stdout artifact writes fa
|
||||
{
|
||||
runId: "run-1",
|
||||
mode: "single",
|
||||
agent: "scout",
|
||||
agentSource: "builtin",
|
||||
task: "inspect auth",
|
||||
cwd: dir,
|
||||
requestedModel: "openai/gpt-5",
|
||||
|
||||
@@ -5,7 +5,6 @@ function shortenCommand(command) {
|
||||
export function renderHeader(meta) {
|
||||
return [
|
||||
"=== subagent ===",
|
||||
`Agent: ${meta.agent}`,
|
||||
`Task: ${meta.task}`,
|
||||
`CWD: ${meta.cwd}`,
|
||||
`Requested model: ${meta.requestedModel ?? "(default)"}`,
|
||||
|
||||
@@ -4,7 +4,6 @@ import { renderHeader, renderEventLine } from "./render.mjs";
|
||||
|
||||
test("renderHeader prints generic subagent metadata", () => {
|
||||
const header = renderHeader({
|
||||
agent: "scout",
|
||||
task: "Inspect authentication code",
|
||||
cwd: "/repo",
|
||||
requestedModel: "anthropic/claude-sonnet-4-5",
|
||||
@@ -13,7 +12,7 @@ test("renderHeader prints generic subagent metadata", () => {
|
||||
});
|
||||
|
||||
assert.match(header, /^=== subagent ===/m);
|
||||
assert.match(header, /Agent: scout/);
|
||||
assert.doesNotMatch(header, /Agent:/);
|
||||
assert.match(header, /Task: Inspect authentication code/);
|
||||
assert.match(header, /Session: \/repo\/\.pi\/subagents\/runs\/run-1\/child-session\.jsonl/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user