fix: scope /kill <id> to current session subtree and preserve usage.cost in chat.history

- Restrict /kill <id> matching to only subagents belonging to the current
  session's agent subtree (P1 review feedback)
- Preserve nested usage.cost in chat.history sanitization so cost badges
  remain available (P2 review feedback)
This commit is contained in:
Val Alexander
2026-03-09 18:56:28 -05:00
parent 5aa5ca6027
commit 6bdeb712f4
3 changed files with 13 additions and 4 deletions

1
.gitignore vendored
View File

@@ -121,3 +121,4 @@ dist/protocol.schema.json
# Synthing
**/.stfolder/
openclaw

View File

@@ -352,6 +352,14 @@ function sanitizeUsage(raw: unknown): Record<string, number> | undefined {
}
}
// Preserve nested usage.cost when present
if ("cost" in u && u.cost != null && typeof u.cost === "object") {
const sanitizedCost = sanitizeCost(u.cost);
if (sanitizedCost) {
(out as Record<string, unknown>).cost = sanitizedCost;
}
}
return Object.keys(out).length > 0 ? out : undefined;
}

View File

@@ -354,10 +354,10 @@ function resolveKillTargets(
const isMatch =
(normalizedTarget === "all" && belongsToCurrentSession) ||
normalizedKey === normalizedTarget ||
(parsed?.agentId ?? "") === normalizedTarget ||
normalizedKey.endsWith(`:subagent:${normalizedTarget}`) ||
normalizedKey === `subagent:${normalizedTarget}` ||
(belongsToCurrentSession && normalizedKey.endsWith(`:subagent:${normalizedTarget}`));
(belongsToCurrentSession &&
((parsed?.agentId ?? "") === normalizedTarget ||
normalizedKey.endsWith(`:subagent:${normalizedTarget}`) ||
normalizedKey === `subagent:${normalizedTarget}`));
if (isMatch) {
keys.add(key);
}