Implements 10 MCP tools for task management: - CRUD: task_add, task_list, task_show, task_close, task_update - Search: task_similar (pgvector), task_context - Relations: task_link, task_checklist_add, task_checklist_toggle Uses PostgreSQL with pgvector for semantic search via LiteLLM embeddings. Connects via SSH tunnel to docker-host:5435. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
82 lines
1.8 KiB
TypeScript
82 lines
1.8 KiB
TypeScript
// Task relations: dependencies and checklists
|
|
|
|
import { query, queryOne, execute } from '../db.js';
|
|
|
|
interface TaskLinkArgs {
|
|
from_id: string;
|
|
to_id: string;
|
|
link_type: string;
|
|
}
|
|
|
|
interface ChecklistAddArgs {
|
|
task_id: string;
|
|
item: string;
|
|
}
|
|
|
|
interface ChecklistToggleArgs {
|
|
item_id: number;
|
|
checked: boolean;
|
|
}
|
|
|
|
/**
|
|
* Create a dependency between tasks
|
|
*/
|
|
export async function taskLink(args: TaskLinkArgs): Promise<string> {
|
|
const { from_id, to_id, link_type } = args;
|
|
|
|
try {
|
|
await execute(
|
|
`INSERT INTO task_links (from_task_id, to_task_id, link_type)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT (from_task_id, to_task_id, link_type) DO NOTHING`,
|
|
[from_id, to_id, link_type]
|
|
);
|
|
|
|
return `Linked: ${from_id} ${link_type} ${to_id}`;
|
|
} catch (error) {
|
|
return `Error creating link: ${error}`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add a checklist item to a task
|
|
*/
|
|
export async function checklistAdd(args: ChecklistAddArgs): Promise<string> {
|
|
const { task_id, item } = args;
|
|
|
|
// Get next position
|
|
const result = await queryOne<{ max: number }>(
|
|
`SELECT COALESCE(MAX(position), 0) + 1 as max
|
|
FROM task_checklist WHERE task_id = $1`,
|
|
[task_id]
|
|
);
|
|
|
|
const position = result?.max || 1;
|
|
|
|
await execute(
|
|
`INSERT INTO task_checklist (task_id, item, position)
|
|
VALUES ($1, $2, $3)`,
|
|
[task_id, item, position]
|
|
);
|
|
|
|
return `Added to ${task_id}: ${item}`;
|
|
}
|
|
|
|
/**
|
|
* Toggle a checklist item
|
|
*/
|
|
export async function checklistToggle(args: ChecklistToggleArgs): Promise<string> {
|
|
const { item_id, checked } = args;
|
|
|
|
const result = await execute(
|
|
`UPDATE task_checklist SET checked = $1 WHERE id = $2`,
|
|
[checked, item_id]
|
|
);
|
|
|
|
if (result === 0) {
|
|
return `Checklist item not found: ${item_id}`;
|
|
}
|
|
|
|
return `${checked ? 'Checked' : 'Unchecked'}: item #${item_id}`;
|
|
}
|