mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:51:36 +00:00
refactor(subagents): dedupe list line rendering
This commit is contained in:
@@ -105,6 +105,20 @@ function resolveDisplayStatus(entry: SubagentRunRecord) {
|
|||||||
return status === "error" ? "failed" : status;
|
return status === "error" ? "failed" : status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatSubagentListLine(params: {
|
||||||
|
entry: SubagentRunRecord;
|
||||||
|
index: number;
|
||||||
|
runtimeMs: number;
|
||||||
|
sessionEntry?: SessionEntry;
|
||||||
|
}) {
|
||||||
|
const usageText = formatTokenUsageDisplay(params.sessionEntry);
|
||||||
|
const label = truncateLine(formatRunLabel(params.entry, { maxLength: 48 }), 48);
|
||||||
|
const task = formatTaskPreview(params.entry.task);
|
||||||
|
const runtime = formatDurationCompact(params.runtimeMs);
|
||||||
|
const status = resolveDisplayStatus(params.entry);
|
||||||
|
return `${params.index}. ${label} (${resolveModelDisplay(params.sessionEntry, params.entry.model)}, ${runtime}${usageText ? `, ${usageText}` : ""}) ${status}${task.toLowerCase() !== label.toLowerCase() ? ` - ${task}` : ""}`;
|
||||||
|
}
|
||||||
|
|
||||||
function formatTimestamp(valueMs?: number) {
|
function formatTimestamp(valueMs?: number) {
|
||||||
if (!valueMs || !Number.isFinite(valueMs) || valueMs <= 0) {
|
if (!valueMs || !Number.isFinite(valueMs) || valueMs <= 0) {
|
||||||
return "n/a";
|
return "n/a";
|
||||||
@@ -277,42 +291,37 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
|
|||||||
const recentCutoff = now - RECENT_WINDOW_MINUTES * 60_000;
|
const recentCutoff = now - RECENT_WINDOW_MINUTES * 60_000;
|
||||||
const storeCache: SessionStoreCache = new Map();
|
const storeCache: SessionStoreCache = new Map();
|
||||||
let index = 1;
|
let index = 1;
|
||||||
const activeLines = sorted
|
const mapRuns = (
|
||||||
.filter((entry) => !entry.endedAt)
|
entries: SubagentRunRecord[],
|
||||||
.map((entry) => {
|
runtimeMs: (entry: SubagentRunRecord) => number,
|
||||||
|
) =>
|
||||||
|
entries.map((entry) => {
|
||||||
const { entry: sessionEntry } = loadSubagentSessionEntry(
|
const { entry: sessionEntry } = loadSubagentSessionEntry(
|
||||||
params,
|
params,
|
||||||
entry.childSessionKey,
|
entry.childSessionKey,
|
||||||
storeCache,
|
storeCache,
|
||||||
);
|
);
|
||||||
const usageText = formatTokenUsageDisplay(sessionEntry);
|
const line = formatSubagentListLine({
|
||||||
const label = truncateLine(formatRunLabel(entry, { maxLength: 48 }), 48);
|
entry,
|
||||||
const task = formatTaskPreview(entry.task);
|
index,
|
||||||
const runtime = formatDurationCompact(now - (entry.startedAt ?? entry.createdAt));
|
runtimeMs: runtimeMs(entry),
|
||||||
const status = resolveDisplayStatus(entry);
|
sessionEntry,
|
||||||
const line = `${index}. ${label} (${resolveModelDisplay(sessionEntry, entry.model)}, ${runtime}${usageText ? `, ${usageText}` : ""}) ${status}${task.toLowerCase() !== label.toLowerCase() ? ` - ${task}` : ""}`;
|
});
|
||||||
index += 1;
|
|
||||||
return line;
|
|
||||||
});
|
|
||||||
const recentLines = sorted
|
|
||||||
.filter((entry) => !!entry.endedAt && (entry.endedAt ?? 0) >= recentCutoff)
|
|
||||||
.map((entry) => {
|
|
||||||
const { entry: sessionEntry } = loadSubagentSessionEntry(
|
|
||||||
params,
|
|
||||||
entry.childSessionKey,
|
|
||||||
storeCache,
|
|
||||||
);
|
|
||||||
const usageText = formatTokenUsageDisplay(sessionEntry);
|
|
||||||
const label = truncateLine(formatRunLabel(entry, { maxLength: 48 }), 48);
|
|
||||||
const task = formatTaskPreview(entry.task);
|
|
||||||
const runtime = formatDurationCompact(
|
|
||||||
(entry.endedAt ?? now) - (entry.startedAt ?? entry.createdAt),
|
|
||||||
);
|
|
||||||
const status = resolveDisplayStatus(entry);
|
|
||||||
const line = `${index}. ${label} (${resolveModelDisplay(sessionEntry, entry.model)}, ${runtime}${usageText ? `, ${usageText}` : ""}) ${status}${task.toLowerCase() !== label.toLowerCase() ? ` - ${task}` : ""}`;
|
|
||||||
index += 1;
|
index += 1;
|
||||||
return line;
|
return line;
|
||||||
});
|
});
|
||||||
|
const activeEntries = sorted.filter((entry) => !entry.endedAt);
|
||||||
|
const activeLines = mapRuns(
|
||||||
|
activeEntries,
|
||||||
|
(entry) => now - (entry.startedAt ?? entry.createdAt),
|
||||||
|
);
|
||||||
|
const recentEntries = sorted.filter(
|
||||||
|
(entry) => !!entry.endedAt && (entry.endedAt ?? 0) >= recentCutoff,
|
||||||
|
);
|
||||||
|
const recentLines = mapRuns(
|
||||||
|
recentEntries,
|
||||||
|
(entry) => (entry.endedAt ?? now) - (entry.startedAt ?? entry.createdAt),
|
||||||
|
);
|
||||||
|
|
||||||
const lines = ["active subagents:", "-----"];
|
const lines = ["active subagents:", "-----"];
|
||||||
if (activeLines.length === 0) {
|
if (activeLines.length === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user