fix(ui): support legacy slash kill scopes

This commit is contained in:
Val Alexander
2026-03-10 20:56:31 -05:00
parent da7e8733eb
commit 4075703730
2 changed files with 45 additions and 2 deletions

View File

@@ -141,4 +141,39 @@ describe("executeSlashCommand /kill", () => {
sessionKey: "agent:main:subagent:two",
});
});
it("treats the legacy main session key as the default agent scope", async () => {
const request = vi.fn(async (method: string, _payload?: unknown) => {
if (method === "sessions.list") {
return {
sessions: [
row("main"),
row("agent:main:subagent:one"),
row("agent:main:subagent:two"),
row("agent:other:subagent:three"),
],
};
}
if (method === "chat.abort") {
return { ok: true, aborted: true };
}
throw new Error(`unexpected method: ${method}`);
});
const result = await executeSlashCommand(
{ request } as unknown as GatewayBrowserClient,
"main",
"kill",
"all",
);
expect(result.content).toBe("Aborted 2 sub-agent sessions.");
expect(request).toHaveBeenNthCalledWith(1, "sessions.list", {});
expect(request).toHaveBeenNthCalledWith(2, "chat.abort", {
sessionKey: "agent:main:subagent:one",
});
expect(request).toHaveBeenNthCalledWith(3, "chat.abort", {
sessionKey: "agent:main:subagent:two",
});
});
});

View File

@@ -3,7 +3,12 @@
* Calls gateway RPC methods and returns formatted results.
*/
import { isSubagentSessionKey, parseAgentSessionKey } from "../../../../src/routing/session-key.js";
import {
DEFAULT_AGENT_ID,
DEFAULT_MAIN_KEY,
isSubagentSessionKey,
parseAgentSessionKey,
} from "../../../../src/routing/session-key.js";
import type { GatewayBrowserClient } from "../gateway.ts";
import type {
AgentsListResult,
@@ -350,6 +355,9 @@ function resolveKillTargets(
const keys = new Set<string>();
const normalizedCurrentSessionKey = currentSessionKey.trim().toLowerCase();
const currentParsed = parseAgentSessionKey(normalizedCurrentSessionKey);
const currentAgentId =
currentParsed?.agentId ??
(normalizedCurrentSessionKey === DEFAULT_MAIN_KEY ? DEFAULT_AGENT_ID : undefined);
for (const session of sessions) {
const key = session?.key?.trim();
if (!key || !isSubagentSessionKey(key)) {
@@ -360,7 +368,7 @@ function resolveKillTargets(
const belongsToCurrentSession = isWithinCurrentSessionSubtree(
normalizedKey,
normalizedCurrentSessionKey,
currentParsed?.agentId,
currentAgentId,
parsed?.agentId,
);
const isMatch =