feat: 升级至 v0.3.13 — 任务管理系统重构(删除 todo_write + IPC 越权防护 + UI 自动刷新)

This commit is contained in:
2026-07-21 17:01:15 +08:00
parent 058ee2de36
commit f640c9b48a
13 changed files with 114 additions and 280 deletions
@@ -82,7 +82,22 @@ export class TaskManagerTool implements IMetonaTool {
timeoutMs: 10_000,
};
constructor(private getDB: () => Database.Database) {}
constructor(
private getDB: () => Database.Database,
// P2v0.3.13): 写入后回调,用于通知 UI 刷新(避免工具层依赖 Electron)
private onTaskChanged?: (sessionId: string) => void,
) {}
/** 写入后触发回调(仅对修改操作) */
private notifyChanged(sessionId: string): void {
if (this.onTaskChanged) {
try {
this.onTaskChanged(sessionId);
} catch {
// 回调失败不影响工具主流程
}
}
}
async execute(args: Record<string, unknown>, context: ToolExecutionContext): Promise<unknown> {
try {
@@ -139,6 +154,9 @@ export class TaskManagerTool implements IMetonaTool {
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(id, sessionId, title, description, 'pending', priority, parentId, null, order, now, now);
// P2: 通知 UI 刷新
this.notifyChanged(sessionId);
return {
success: true,
task: {
@@ -207,6 +225,9 @@ export class TaskManagerTool implements IMetonaTool {
// T3.1: UPDATE 语句加 AND session_id = ? 防止越权
db.prepare(`UPDATE tasks SET ${updates.join(', ')} WHERE id = ? AND session_id = ?`).run(...values);
// P2: 通知 UI 刷新
this.notifyChanged(context.sessionId);
const updated = db.prepare('SELECT * FROM tasks WHERE id = ? AND session_id = ?').get(taskId, context.sessionId) as Record<string, unknown>;
return { success: true, task: mapRow(updated) };
}
@@ -266,6 +287,9 @@ export class TaskManagerTool implements IMetonaTool {
return { success: false, error: `Task not found: ${taskId}` };
}
// P2: 通知 UI 刷新
this.notifyChanged(context.sessionId);
return { success: true, task_id: taskId, completed_at: now };
}
@@ -301,6 +325,9 @@ export class TaskManagerTool implements IMetonaTool {
});
deleteMany();
// P2: 通知 UI 刷新
this.notifyChanged(context.sessionId);
return { success: true, task_id: taskId, deleted: allIds.length };
}