Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/agent-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5178,14 +5178,20 @@ export class AgentEngine {
if (!agent) {
throw new Error(`Agent not found: ${agentId}`);
}
const resumeCommand = agent.cli_session_id
? buildResumeCommand(
let resumeCommand: string | undefined;
if (agent.cli_session_id) {
try {
resumeCommand = buildResumeCommand(
agent.cli,
agent.repo,
agent.cli_session_id,
agent.launcher_name,
)
: undefined;
);
} catch {
// Terminal I/O depends on the stable surface binding, not optional
// resume metadata. A damaged legacy repo field must not disable send.
}
}
return {
agent_id: agent.agent_id,
surface_id: agent.surface_id,
Expand Down
2 changes: 0 additions & 2 deletions src/agent-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,6 @@ export class AgentRegistry {
return null;
}
const agentId = record.agent_id;
const repo = inferRepoFromTitle(discoveredEntry.surface_title) || record.repo;
const model = discoveredEntry.model ?? record.model;
const workspaceId = discoveredEntry.workspace_id ?? null;
const surfaceUuid = discoveredEntry.surface_uuid ?? null;
Expand All @@ -1409,7 +1408,6 @@ export class AgentRegistry {
const explicitRole = this.explicitRoleFor(discoveredEntry);

const patch: Partial<AgentRecord> = {};
if (repo !== record.repo) patch.repo = repo;
if (model !== record.model) patch.model = model;
if ((record.workspace_id ?? null) !== workspaceId) {
patch.workspace_id = workspaceId;
Expand Down
31 changes: 23 additions & 8 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,29 @@ export function formatReadScreen(
return result.join("\n");
}

export function formatListAgents(agents: PublicAgent[], count: number): string {
if (count === 0) {
export function formatListAgents(
agents: PublicAgent[],
count: number,
skippedAgents: Array<{ agent_id: string; error: string }> = [],
): string {
if (count === 0 && skippedAgents.length === 0) {
return "\u250c\u2500 cmux agents\n\u2502 No agents running.\n\u2514\u2500";
}

const lines: string[] = [];
lines.push(
`\u250c\u2500 cmux agents \u2500 ${count} agent${count !== 1 ? "s" : ""}`,
);
lines.push(
`\u2502 ${pad("ID", 20)} ${pad("Repo", 16)} ${pad("State", 8)} ${pad("Model", 18)} ${pad("Session", 14)}`,
);
lines.push(
`\u251c${"─".repeat(20)}${"─".repeat(17)}${"─".repeat(9)}${"─".repeat(19)}${"─".repeat(14)}`,
);
if (count > 0) {
lines.push(
`\u2502 ${pad("ID", 20)} ${pad("Repo", 16)} ${pad("State", 8)} ${pad("Model", 18)} ${pad("Session", 14)}`,
);
lines.push(
`\u251c${"─".repeat(20)}${"─".repeat(17)}${"─".repeat(9)}${"─".repeat(19)}${"─".repeat(14)}`,
);
} else {
lines.push("\u2502 No healthy agent rows.");
}

for (const a of agents) {
const id = pad(truncate(a.agent_id, 18), 20);
Expand All @@ -184,6 +192,13 @@ export function formatListAgents(agents: PublicAgent[], count: number): string {
lines.push(`\u2502 ${id} ${repo} ${state} ${model} ${session}`);
}

if (skippedAgents.length > 0) {
const skippedIds = skippedAgents.map((agent) => agent.agent_id).join(", ");
lines.push(
`\u2502 \u26a0 skipped ${skippedAgents.length} invalid agent row${skippedAgents.length === 1 ? "" : "s"}: ${skippedIds}`,
);
}

Comment on lines +195 to +201

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize skipped agent IDs before rendering the warning.

This code inserts agent_id values directly into the text response. A malformed row with a newline, control character, or very long ID can corrupt the response. Apply the same truncation policy used for healthy IDs and remove control characters before joining the values.

Proposed fix
-    const skippedIds = skippedAgents.map((agent) => agent.agent_id).join(", ");
+    const skippedIds = skippedAgents
+      .map(({ agent_id }) =>
+        truncate(agent_id.replace(/[\u0000-\u001f\u007f]/g, " "), 18),
+      )
+      .join(", ");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (skippedAgents.length > 0) {
const skippedIds = skippedAgents.map((agent) => agent.agent_id).join(", ");
lines.push(
`\u2502 \u26a0 skipped ${skippedAgents.length} invalid agent row${skippedAgents.length === 1 ? "" : "s"}: ${skippedIds}`,
);
}
if (skippedAgents.length > 0) {
const skippedIds = skippedAgents
.map(({ agent_id }) =>
truncate(agent_id.replace(/[\u0000-\u001f\u007f]/g, " "), 18),
)
.join(", ");
lines.push(
`\u2502 \u26a0 skipped ${skippedAgents.length} invalid agent row${skippedAgents.length === 1 ? "" : "s"}: ${skippedIds}`,
);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/format.ts` around lines 195 - 201, Normalize each skipped agent ID in the
skippedAgents warning within the formatting flow before joining them: remove
control characters and apply the same truncation policy used for healthy agent
IDs, reusing the existing normalization helper or logic. Keep the warning count
and rendering behavior unchanged while ensuring malformed IDs cannot corrupt the
response.

lines.push("\u2514\u2500");
return lines.join("\n");
}
Expand Down
Loading
Loading