@nanocollective/nanocoder
Version:
A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter
101 lines • 3.79 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { TaskListDisplay } from '../../components/task-list-display.js';
import { jsonSchema, tool } from '../../types/core.js';
import { clearAllTasks, loadTasks, saveTasks } from './storage.js';
const executeDeleteTask = async (args) => {
if (args.clear_all) {
const tasks = await loadTasks();
const count = tasks.length;
await clearAllTasks();
return `Cleared all ${count} task(s)\n\nNo tasks remaining.`;
}
if (!args.ids || args.ids.length === 0) {
throw new Error('Either ids or clear_all must be provided');
}
const tasks = await loadTasks();
const results = [];
const idsToDelete = new Set(args.ids);
const remainingTasks = tasks.filter(t => {
if (idsToDelete.has(t.id)) {
results.push(` ✗ [${t.id}] ${t.title}`);
return false;
}
return true;
});
// Check for IDs that weren't found
const foundIds = new Set(tasks.map(t => t.id));
for (const id of args.ids) {
if (!foundIds.has(id)) {
results.push(` ? Task not found: ${id}`);
}
}
await saveTasks(remainingTasks);
const counts = {
pending: remainingTasks.filter(t => t.status === 'pending').length,
in_progress: remainingTasks.filter(t => t.status === 'in_progress').length,
completed: remainingTasks.filter(t => t.status === 'completed').length,
};
if (remainingTasks.length === 0) {
return `Deleted ${args.ids.length} task(s):\n${results.join('\n')}\n\nNo tasks remaining.`;
}
const allTasksList = remainingTasks
.map(t => {
const icon = t.status === 'completed' ? '✓' : t.status === 'in_progress' ? '◐' : '○';
return ` ${icon} [${t.id}] ${t.title}`;
})
.join('\n');
return `Deleted ${args.ids.length} task(s):\n${results.join('\n')}\n\nRemaining Tasks (${counts.pending} pending, ${counts.in_progress} in progress, ${counts.completed} completed):\n${allTasksList}`;
};
const deleteTaskCoreTool = tool({
description: 'Delete one or more tasks by ID, or clear all tasks. Pass an array of ids, or use clear_all to reset.',
inputSchema: jsonSchema({
type: 'object',
properties: {
ids: {
type: 'array',
description: 'Array of task IDs to delete',
items: {
type: 'string',
},
},
clear_all: {
type: 'boolean',
description: 'Set to true to delete all tasks and reset the list',
},
},
required: [],
}),
needsApproval: false,
execute: async (args, _options) => {
return await executeDeleteTask(args);
},
});
const deleteTaskFormatter = async (args, _result) => {
const allTasks = await loadTasks();
const title = args.clear_all ? 'Tasks Cleared' : 'Tasks';
return _jsx(TaskListDisplay, { tasks: allTasks, title: title });
};
const deleteTaskValidator = (args) => {
const hasIds = args.ids && args.ids.length > 0;
const hasClearAll = args.clear_all === true;
if (!hasIds && !hasClearAll) {
return Promise.resolve({
valid: false,
error: '⚒ Either ids (array) or clear_all must be provided',
});
}
if (hasIds && hasClearAll) {
return Promise.resolve({
valid: false,
error: '⚒ Cannot specify both ids and clear_all',
});
}
return Promise.resolve({ valid: true });
};
export const deleteTaskTool = {
name: 'delete_task',
tool: deleteTaskCoreTool,
formatter: deleteTaskFormatter,
validator: deleteTaskValidator,
};
//# sourceMappingURL=delete-task.js.map