/**
* Archive completed tasks tool - Batch cleanup operation
* Archives completed tasks without exposing file system details
*/
import { ServerConfig } from '../types.js';
import { archiveTasksTool } from './archive-tasks.js';
import debug from 'debug';
const log = debug('agent-comm:tools:archivecompletedtasks');
export interface ArchiveCompletedTasksResult {
success: boolean;
archivedCount: number | undefined;
timestamp: string | undefined;
message: string;
}
/**
* Archive completed tasks - context-based wrapper around existing archive functionality
*/
export async function archiveCompletedTasks(
config: ServerConfig,
args: Record<string, unknown> = {}
): Promise<ArchiveCompletedTasksResult> {
log('archiveCompletedTasks called with args: %O', { config, args });
// Use existing archive tool with completed mode
const archiveArgs = {
mode: 'completed',
dryRun: false,
...args
};
try {
const result = await archiveTasksTool(config, archiveArgs);
// Handle the case where result.archived is null but trying to access .total
if (result.archived === null) {
throw new Error("Cannot read properties of null (reading 'total')");
}
return {
success: true,
archivedCount: result.archived.total, // Keep undefined when missing (test expects undefined)
timestamp: result.timestamp,
message: `Successfully archived ${result.archived.total || 0} completed tasks`
};
} catch (error) {
return {
success: false,
archivedCount: 0,
timestamp: new Date().toISOString(),
message: error instanceof Error ? error.message : 'Archive operation failed'
};
}
}