feat(api): 项目任务状态摘要——侧栏状态点 + 需人工关注数

projectOut 此前不返 summary,前端拿到空 {} → 所有项目恒灰、无关注数。新增
store.projectSummary(projectId):running(executor+planner 在跑)/blocked/attention(待审批闸
+needs_attention)/executing/alive 计数,projectOut 带上。前端 adaptProject 用 running 判青点、
attention 进紫徽标。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-29 11:04:13 +08:00
parent 3780f1c064
commit 2460b3f46c
2 changed files with 22 additions and 7 deletions
+15
View File
@@ -218,6 +218,21 @@ export class Store {
return rows.map(rowToProject);
}
/** 项目任务状态摘要(供侧栏状态点 + 关注数徽标):running=agent 在跑、attention=需人工。 */
projectSummary(projectId: string): { executing: number; running: number; blocked: number; alive: number; attention: number } {
const rows = this.db.prepare(`SELECT status, COUNT(*) AS n FROM tasks WHERE project_id = ? GROUP BY status`).all(projectId) as Array<{ status: string; n: number }>;
const by: Record<string, number> = {};
for (const r of rows) by[r.status] = r.n;
const g = (s: string): number => by[s] || 0;
const executing = g('executing');
const running = executing + g('analyzing') + g('speccing'); // agent 在跑:executor + planner
const attention = g('plan_review') + g('spec_review') + g('exec_review') + g('needs_attention'); // 待审批闸 + 需人工
const TERMINAL = new Set(['done', 'cancelled']);
let alive = 0;
for (const [s, n] of Object.entries(by)) if (!TERMINAL.has(s)) alive += n;
return { executing, running, blocked: g('blocked'), alive, attention };
}
/** 重排项目(侧栏拖动):按给定 id 顺序写 sort_order;未列出的排在后面、相对顺序不变。 */
reorderProjects(orderedIds: string[]): Project[] {
const txn = this.db.transaction(() => {