refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -33,6 +33,39 @@ function writeStore(agentId: string, store: Record<string, unknown>) {
fs.writeFileSync(storePath, JSON.stringify(store, null, 2), "utf-8");
}
function setSubagentLimits(subagents: Record<string, unknown>) {
configOverride = {
session: {
mainKey: "main",
scope: "per-sender",
store: storeTemplatePath,
},
agents: {
defaults: {
subagents,
},
},
};
}
function seedDepthTwoAncestryStore(params?: { sessionIds?: boolean }) {
const depth1 = "agent:main:subagent:depth-1";
const callerKey = "agent:main:subagent:depth-2";
writeStore("main", {
[depth1]: {
sessionId: params?.sessionIds ? "depth-1-session" : "depth-1",
updatedAt: Date.now(),
spawnedBy: "agent:main:main",
},
[callerKey]: {
sessionId: params?.sessionIds ? "depth-2-session" : "depth-2",
updatedAt: Date.now(),
spawnedBy: depth1,
},
});
return { depth1, callerKey };
}
describe("sessions_spawn depth + child limits", () => {
beforeEach(() => {
resetSubagentRegistryForTests();
@@ -72,20 +105,7 @@ describe("sessions_spawn depth + child limits", () => {
});
it("allows depth-1 callers when maxSpawnDepth is 2", async () => {
configOverride = {
session: {
mainKey: "main",
scope: "per-sender",
store: storeTemplatePath,
},
agents: {
defaults: {
subagents: {
maxSpawnDepth: 2,
},
},
},
};
setSubagentLimits({ maxSpawnDepth: 2 });
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:subagent:parent" });
const result = await tool.execute("call-depth-allow", { task: "hello" });
@@ -109,20 +129,7 @@ describe("sessions_spawn depth + child limits", () => {
});
it("rejects depth-2 callers when maxSpawnDepth is 2 (using stored spawnDepth on flat keys)", async () => {
configOverride = {
session: {
mainKey: "main",
scope: "per-sender",
store: storeTemplatePath,
},
agents: {
defaults: {
subagents: {
maxSpawnDepth: 2,
},
},
},
};
setSubagentLimits({ maxSpawnDepth: 2 });
const callerKey = "agent:main:subagent:flat-depth-2";
writeStore("main", {
@@ -143,35 +150,8 @@ describe("sessions_spawn depth + child limits", () => {
});
it("rejects depth-2 callers when spawnDepth is missing but spawnedBy ancestry implies depth 2", async () => {
configOverride = {
session: {
mainKey: "main",
scope: "per-sender",
store: storeTemplatePath,
},
agents: {
defaults: {
subagents: {
maxSpawnDepth: 2,
},
},
},
};
const depth1 = "agent:main:subagent:depth-1";
const callerKey = "agent:main:subagent:depth-2";
writeStore("main", {
[depth1]: {
sessionId: "depth-1",
updatedAt: Date.now(),
spawnedBy: "agent:main:main",
},
[callerKey]: {
sessionId: "depth-2",
updatedAt: Date.now(),
spawnedBy: depth1,
},
});
setSubagentLimits({ maxSpawnDepth: 2 });
const { callerKey } = seedDepthTwoAncestryStore();
const tool = createSessionsSpawnTool({ agentSessionKey: callerKey });
const result = await tool.execute("call-depth-ancestry-reject", { task: "hello" });
@@ -183,35 +163,8 @@ describe("sessions_spawn depth + child limits", () => {
});
it("rejects depth-2 callers when the requester key is a sessionId", async () => {
configOverride = {
session: {
mainKey: "main",
scope: "per-sender",
store: storeTemplatePath,
},
agents: {
defaults: {
subagents: {
maxSpawnDepth: 2,
},
},
},
};
const depth1 = "agent:main:subagent:depth-1";
const callerKey = "agent:main:subagent:depth-2";
writeStore("main", {
[depth1]: {
sessionId: "depth-1-session",
updatedAt: Date.now(),
spawnedBy: "agent:main:main",
},
[callerKey]: {
sessionId: "depth-2-session",
updatedAt: Date.now(),
spawnedBy: depth1,
},
});
setSubagentLimits({ maxSpawnDepth: 2 });
seedDepthTwoAncestryStore({ sessionIds: true });
const tool = createSessionsSpawnTool({ agentSessionKey: "depth-2-session" });
const result = await tool.execute("call-depth-sessionid-reject", { task: "hello" });