feat: show todo progress in Herdr sidebar

This commit is contained in:
lesetong
2026-08-24 10:10:31 +08:00
parent ff497e23b3
commit cd74f91e2a
3 changed files with 31 additions and 8 deletions
+5 -2
View File
@@ -1,10 +1,11 @@
import net from "node:net";
import type { Task } from "./types.ts";
import { orderedTreeRows } from "./ui.ts";
import { orderedTreeRows, snapshotStats } from "./ui.ts";
const SOURCE = "pi-todo-herdr";
const TASK_TOKEN = "task";
const COUNT_TOKEN = "task_count";
const PROGRESS_TOKEN = "task_progress";
let reportSeq = Date.now() * 1000;
function nextSeq(): number {
@@ -27,6 +28,7 @@ function hasDescendantWithStatus(task: Task, status: Task["status"], byId: Map<n
export function currentTaskTokens(tasks: Task[]): Record<string, string | null> {
const byId = new Map(tasks.map((task) => [task.id, task]));
const stats = snapshotStats(tasks);
const ordered = orderedTreeRows(tasks).map(({ task }) => task);
const inProgress = ordered.filter(
(task) => task.status === "in-progress" && !hasDescendantWithStatus(task, "in-progress", byId),
@@ -38,6 +40,7 @@ export function currentTaskTokens(tasks: Task[]): Record<string, string | null>
return {
[TASK_TOKEN]: candidates.length > 0 ? `#${candidates[0]!.id} ${candidates[0]!.name}` : null,
[COUNT_TOKEN]: candidates.length > 1 ? `+${candidates.length - 1}` : null,
[PROGRESS_TOKEN]: stats.total > 0 ? `${stats.done}/${stats.total}` : null,
};
}
@@ -97,5 +100,5 @@ export function reportCurrentTask(tasks: Task[]): Promise<void> {
}
export function clearCurrentTask(): Promise<void> {
return reportTokens({ [TASK_TOKEN]: null, [COUNT_TOKEN]: null });
return reportTokens({ [TASK_TOKEN]: null, [COUNT_TOKEN]: null, [PROGRESS_TOKEN]: null });
}