|
|
|
|
@ -11,6 +11,10 @@ import {
|
|
|
|
|
isSubagentSessionKey,
|
|
|
|
|
parseAgentSessionKey,
|
|
|
|
|
} from "../session-key.ts";
|
|
|
|
|
import {
|
|
|
|
|
normalizeLowercaseStringOrEmpty,
|
|
|
|
|
normalizeOptionalLowercaseString,
|
|
|
|
|
} from "../string-coerce.ts";
|
|
|
|
|
import {
|
|
|
|
|
formatThinkingLevels,
|
|
|
|
|
normalizeThinkLevel,
|
|
|
|
|
@ -60,7 +64,7 @@ function normalizeVerboseLevel(raw?: string | null): "off" | "on" | "full" | und
|
|
|
|
|
if (!raw) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
const key = raw.toLowerCase();
|
|
|
|
|
const key = normalizeLowercaseStringOrEmpty(raw);
|
|
|
|
|
if (["off", "false", "no", "0"].includes(key)) {
|
|
|
|
|
return "off";
|
|
|
|
|
}
|
|
|
|
|
@ -313,7 +317,7 @@ async function executeFast(
|
|
|
|
|
sessionKey: string,
|
|
|
|
|
args: string,
|
|
|
|
|
): Promise<SlashCommandResult> {
|
|
|
|
|
const rawMode = args.trim().toLowerCase();
|
|
|
|
|
const rawMode = normalizeLowercaseStringOrEmpty(args);
|
|
|
|
|
|
|
|
|
|
if (!rawMode || rawMode === "status") {
|
|
|
|
|
try {
|
|
|
|
|
@ -406,6 +410,7 @@ async function executeKill(
|
|
|
|
|
args: string,
|
|
|
|
|
): Promise<SlashCommandResult> {
|
|
|
|
|
const target = args.trim();
|
|
|
|
|
const normalizedTarget = normalizeLowercaseStringOrEmpty(target);
|
|
|
|
|
if (!target) {
|
|
|
|
|
return { content: "Usage: `/kill <id|all>`" };
|
|
|
|
|
}
|
|
|
|
|
@ -415,7 +420,7 @@ async function executeKill(
|
|
|
|
|
if (matched.length === 0) {
|
|
|
|
|
return {
|
|
|
|
|
content:
|
|
|
|
|
target.toLowerCase() === "all"
|
|
|
|
|
normalizedTarget === "all"
|
|
|
|
|
? "No active sub-agent sessions found."
|
|
|
|
|
: `No matching sub-agent sessions found for \`${target}\`.`,
|
|
|
|
|
};
|
|
|
|
|
@ -435,7 +440,7 @@ async function executeKill(
|
|
|
|
|
if (rejected.length === 0) {
|
|
|
|
|
return {
|
|
|
|
|
content:
|
|
|
|
|
target.toLowerCase() === "all"
|
|
|
|
|
normalizedTarget === "all"
|
|
|
|
|
? "No active sub-agent runs to abort."
|
|
|
|
|
: `No active runs matched \`${target}\`.`,
|
|
|
|
|
};
|
|
|
|
|
@ -443,7 +448,7 @@ async function executeKill(
|
|
|
|
|
throw rejected[0]?.reason ?? new Error("abort failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (target.toLowerCase() === "all") {
|
|
|
|
|
if (normalizedTarget === "all") {
|
|
|
|
|
return {
|
|
|
|
|
content:
|
|
|
|
|
successCount === matched.length
|
|
|
|
|
@ -468,13 +473,13 @@ function resolveKillTargets(
|
|
|
|
|
currentSessionKey: string,
|
|
|
|
|
target: string,
|
|
|
|
|
): string[] {
|
|
|
|
|
const normalizedTarget = target.trim().toLowerCase();
|
|
|
|
|
const normalizedTarget = normalizeLowercaseStringOrEmpty(target);
|
|
|
|
|
if (!normalizedTarget) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const keys = new Set<string>();
|
|
|
|
|
const normalizedCurrentSessionKey = currentSessionKey.trim().toLowerCase();
|
|
|
|
|
const normalizedCurrentSessionKey = normalizeLowercaseStringOrEmpty(currentSessionKey);
|
|
|
|
|
const currentParsed = parseAgentSessionKey(normalizedCurrentSessionKey);
|
|
|
|
|
const currentAgentId =
|
|
|
|
|
currentParsed?.agentId ??
|
|
|
|
|
@ -485,7 +490,7 @@ function resolveKillTargets(
|
|
|
|
|
if (!key || !isSubagentSessionKey(key)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const normalizedKey = key.toLowerCase();
|
|
|
|
|
const normalizedKey = normalizeLowercaseStringOrEmpty(key);
|
|
|
|
|
const parsed = parseAgentSessionKey(normalizedKey);
|
|
|
|
|
const belongsToCurrentSession = isWithinCurrentSessionSubtree(
|
|
|
|
|
normalizedKey,
|
|
|
|
|
@ -550,8 +555,7 @@ function buildSessionIndex(sessions: GatewaySessionRow[]): Map<string, GatewaySe
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function normalizeSessionKey(key?: string | null): string | undefined {
|
|
|
|
|
const normalized = key?.trim().toLowerCase();
|
|
|
|
|
return normalized || undefined;
|
|
|
|
|
return normalizeOptionalLowercaseString(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resolveEquivalentSessionKeys(
|
|
|
|
|
@ -658,11 +662,11 @@ function resolveSteerSubagent(
|
|
|
|
|
currentSessionKey: string,
|
|
|
|
|
target: string,
|
|
|
|
|
): string[] {
|
|
|
|
|
const normalizedTarget = target.trim().toLowerCase();
|
|
|
|
|
const normalizedTarget = normalizeLowercaseStringOrEmpty(target);
|
|
|
|
|
if (!normalizedTarget) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
const normalizedCurrentSessionKey = currentSessionKey.trim().toLowerCase();
|
|
|
|
|
const normalizedCurrentSessionKey = normalizeLowercaseStringOrEmpty(currentSessionKey);
|
|
|
|
|
const currentParsed = parseAgentSessionKey(normalizedCurrentSessionKey);
|
|
|
|
|
const currentAgentId =
|
|
|
|
|
currentParsed?.agentId ??
|
|
|
|
|
@ -675,7 +679,7 @@ function resolveSteerSubagent(
|
|
|
|
|
if (!key || !isSubagentSessionKey(key)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const normalizedKey = key.toLowerCase();
|
|
|
|
|
const normalizedKey = normalizeLowercaseStringOrEmpty(key);
|
|
|
|
|
const parsed = parseAgentSessionKey(normalizedKey);
|
|
|
|
|
const belongsToCurrentSession = isWithinCurrentSessionSubtree(
|
|
|
|
|
normalizedKey,
|
|
|
|
|
@ -692,7 +696,7 @@ function resolveSteerSubagent(
|
|
|
|
|
normalizedKey === normalizedTarget ||
|
|
|
|
|
normalizedKey.endsWith(`:subagent:${normalizedTarget}`) ||
|
|
|
|
|
normalizedKey === `subagent:${normalizedTarget}` ||
|
|
|
|
|
(session.label ?? "").toLowerCase() === normalizedTarget;
|
|
|
|
|
normalizeLowercaseStringOrEmpty(session.label) === normalizedTarget;
|
|
|
|
|
if (isMatch) {
|
|
|
|
|
keys.add(key);
|
|
|
|
|
}
|
|
|
|
|
@ -728,7 +732,7 @@ async function resolveSteerTarget(
|
|
|
|
|
const rest = trimmed.slice(spaceIdx + 1).trim();
|
|
|
|
|
// Skip "all" — resolveKillTargets treats it as a wildcard, but steer/redirect
|
|
|
|
|
// target a single session, so "all good now" should not match subagents.
|
|
|
|
|
if (rest && maybeTarget.toLowerCase() !== "all") {
|
|
|
|
|
if (rest && normalizeLowercaseStringOrEmpty(maybeTarget) !== "all") {
|
|
|
|
|
const sessions =
|
|
|
|
|
context.sessionsResult ?? (await client.request<SessionsListResult>("sessions.list", {}));
|
|
|
|
|
const matched = resolveSteerSubagent(sessions?.sessions ?? [], sessionKey, maybeTarget);
|
|
|
|
|
|