Skip to content
Open
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: 13 additions & 1 deletion extensions/cli/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,19 @@
// Update metadata after successful agent turn
try {
const history = services.chatHistory?.getHistory();
await updateAgentMetadata(history);

// Check if the agent should be marked as complete
// The agent is complete if the last message is from the assistant and has no tool calls
let isComplete = false;
if (history && history.length > 0) {
const lastItem = history[history.length - 1];
if (lastItem?.message?.role === "assistant") {

Check failure on line 538 in extensions/cli/src/commands/serve.ts

View workflow job for this annotation

GitHub Actions / lint

Blocks are nested too deeply (5). Maximum allowed is 4
const toolCalls = (lastItem.message as any).tool_calls;
isComplete = !toolCalls || toolCalls.length === 0;
}
}

await updateAgentMetadata({ history, isComplete });
} catch (metadataErr) {
// Non-critical: log but don't fail the agent execution
logger.debug(
Expand Down Expand Up @@ -634,7 +646,7 @@
await updateAgentMetadata({ history, isComplete: true });
} catch (err) {
logger.debug("Failed to update metadata (non-critical)", err as any);
}

Check failure on line 649 in extensions/cli/src/commands/serve.ts

View workflow job for this annotation

GitHub Actions / lint

File has too many lines (508). Maximum allowed is 500

gracefulExit(0).catch((err) => {
logger.error(`Graceful exit failed: ${formatError(err)}`);
Expand Down
18 changes: 17 additions & 1 deletion extensions/cli/src/tools/exit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { logger } from "../util/logger.js";

import { Tool } from "./types.js";

export const exitTool: Tool = {
Expand All @@ -12,7 +14,21 @@ export const exitTool: Tool = {
readonly: false,
isBuiltIn: true,
run: async (): Promise<string> => {
const { gracefulExit } = await import("../util/exit.js");
const { gracefulExit, updateAgentMetadata } = await import(
"../util/exit.js"
);

// Mark agent as complete before exiting
try {
await updateAgentMetadata({ isComplete: true });
} catch (err) {
// Non-critical: log but don't block exit
logger.debug(
"Failed to update completion metadata (non-critical)",
err as any,
);
}

await gracefulExit(1);
return "";
},
Expand Down
13 changes: 13 additions & 0 deletions extensions/cli/src/tools/reportFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AuthenticationRequiredError,
post,
} from "../util/apiClient.js";
import { updateAgentMetadata } from "../util/exit.js";
import { logger } from "../util/logger.js";

import { Tool } from "./types.js";
Expand Down Expand Up @@ -74,6 +75,18 @@ export const reportFailureTool: Tool = {
errorMessage: trimmedMessage,
});

// Mark agent as complete since it failed
try {
await updateAgentMetadata({ isComplete: true });
logger.debug("Marked agent as complete due to failure");
} catch (metadataErr) {
// Non-critical: log but don't fail the failure report
logger.debug(
"Failed to update completion metadata (non-critical)",
metadataErr as any,
);
}

logger.info(`Failure reported: ${trimmedMessage}`);
return "Failure reported to user.";
} catch (error) {
Expand Down
19 changes: 19 additions & 0 deletions extensions/cli/src/tools/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AuthenticationRequiredError,
post,
} from "../util/apiClient.js";
import { updateAgentMetadata } from "../util/exit.js";
import { logger } from "../util/logger.js";

import { Tool } from "./types.js";
Expand Down Expand Up @@ -62,6 +63,24 @@ You should use this tool to notify the user whenever the state of your work chan
await post(`agents/${agentId}/status`, { status: args.status });

logger.info(`Status: ${args.status}`);

// If status is DONE or FAILED, mark agent as complete
const normalizedStatus = args.status.toUpperCase();
if (normalizedStatus === "DONE" || normalizedStatus === "FAILED") {
try {
await updateAgentMetadata({ isComplete: true });
logger.debug(
`Marked agent as complete due to status: ${args.status}`,
);
} catch (metadataErr) {
// Non-critical: log but don't fail the status update
logger.debug(
"Failed to update completion metadata (non-critical)",
metadataErr as any,
);
}
}

return `Status set: ${args.status}`;
} catch (error) {
if (error instanceof ContinueError) {
Expand Down
Loading