UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

63 lines • 2.38 kB
// Ported and adapted from oh-my-pi's todo tool (MIT License). // Copyright (c) 2025 Mario Zechner // Copyright (c) 2025-2026 Can Bölük // https://github.com/can1357/oh-my-pi export function findTaskByContent(phases, content) { for (const phase of phases) { const task = phase.tasks.find((candidate) => candidate.content === content); if (task) return { task, phase }; } return undefined; } export function findPhaseByName(phases, name) { return phases.find((phase) => phase.name === name); } export function normalizeInProgressTask(phases) { const orderedTasks = phases.flatMap((phase) => phase.tasks); if (orderedTasks.length === 0) return; const inProgressTasks = orderedTasks.filter((task) => task.status === "in_progress"); if (inProgressTasks.length > 1) { for (const task of inProgressTasks.slice(1)) task.status = "pending"; } if (inProgressTasks.length > 0) return; const firstPendingTask = orderedTasks.find((task) => task.status === "pending"); if (firstPendingTask) firstPendingTask.status = "in_progress"; } /** Return the active task, preferring an in-progress item over the first pending item. */ export function nextActionableTask(phases) { let firstPending; for (const phase of phases) { for (const task of phase.tasks) { if (task.status === "in_progress") return task; if (!firstPending && task.status === "pending") firstPending = task; } } return firstPending; } export function getCompletionTransitions(previous, updated) { const previousStatuses = new Map(); for (const phase of previous) { for (const task of phase.tasks) previousStatuses.set(`${phase.name}\u0000${task.content}`, task.status); } const transitions = []; for (const phase of updated) { for (const task of phase.tasks) { if (task.status !== "completed") continue; const previousStatus = previousStatuses.get(`${phase.name}\u0000${task.content}`); if (previousStatus && previousStatus !== "completed") { transitions.push({ phase: phase.name, content: task.content }); } } } return transitions; } //# sourceMappingURL=todo-query.js.map