refactor: remove role metadata from subagent artifacts

This commit is contained in:
pi
2026-04-12 06:57:18 +01:00
parent 4a0f78f9fb
commit c8859b626b
8 changed files with 16 additions and 43 deletions

View File

@@ -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",