mycoder-agent
Version:
Agent module for mycoder - an AI-powered software development assistant
71 lines • 2.79 kB
JavaScript
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
import { ShellStatus } from './ShellTracker.js';
const parameterSchema = z.object({
status: z
.enum(['all', 'running', 'completed', 'error', 'terminated'])
.optional()
.describe('Filter shells by status (default: "all")'),
verbose: z
.boolean()
.optional()
.describe('Include detailed metadata about each shell (default: false)'),
});
const returnSchema = z.object({
shells: z.array(z.object({
id: z.string(),
status: z.string(),
startTime: z.string(),
endTime: z.string().optional(),
runtime: z.number().describe('Runtime in seconds'),
command: z.string(),
metadata: z.record(z.any()).optional(),
})),
count: z.number(),
});
export const listShellsTool = {
name: 'listShells',
description: 'Lists all shell processes and their status',
logPrefix: '🔍',
parameters: parameterSchema,
returns: returnSchema,
parametersJsonSchema: zodToJsonSchema(parameterSchema),
returnsJsonSchema: zodToJsonSchema(returnSchema),
execute: async ({ status = 'all', verbose = false }, { logger, shellTracker }) => {
logger.debug(`Listing shell processes with status: ${status}, verbose: ${verbose}`);
// Get all shells
let shells = shellTracker.getShells();
// Filter by status if specified
if (status !== 'all') {
const statusEnum = status.toUpperCase();
shells = shells.filter((shell) => shell.status === ShellStatus[statusEnum]);
}
// Format the response
const formattedShells = shells.map((shell) => {
const now = new Date();
const startTime = shell.startTime;
const endTime = shell.endTime || now;
const runtime = (endTime.getTime() - startTime.getTime()) / 1000; // in seconds
return {
id: shell.id,
status: shell.status,
startTime: startTime.toISOString(),
...(shell.endTime && { endTime: shell.endTime.toISOString() }),
runtime: parseFloat(runtime.toFixed(2)),
command: shell.metadata.command,
...(verbose && { metadata: shell.metadata }),
};
});
return {
shells: formattedShells,
count: formattedShells.length,
};
},
logParameters: ({ status = 'all', verbose = false }, { logger }) => {
logger.log(`Listing shell processes with status: ${status}, verbose: ${verbose}`);
},
logReturns: (output, { logger }) => {
logger.log(`Found ${output.count} shell processes`);
},
};
//# sourceMappingURL=listShells.js.map