@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
57 lines • 3.02 kB
JavaScript
import { getLatestPhasesFromBranchEntries, isIncompleteTodo, isTodoPhaseArray } from "../todotools/state.js";
import { isRecord } from "./types.js";
const MAX_LISTED_TASKS = 5;
/**
* Contents of every non-terminal (pending / in_progress) task in the thread's
* latest todo list. The goal builtin refuses to mark a goal complete while any
* of these remain: an open todo task is remaining work by definition.
*/
export function openTodoTaskContents(entries) {
return getLatestPhasesFromBranchEntries(entries)
.flatMap((phase) => phase.tasks)
.filter(isIncompleteTodo)
.map((task) => task.content);
}
export function openTodoCompletionError(openTasks) {
const listed = openTasks
.slice(0, MAX_LISTED_TASKS)
.map((task) => `"${task}"`)
.join(", ");
const suffix = openTasks.length > MAX_LISTED_TASKS ? ` and ${openTasks.length - MAX_LISTED_TASKS} more` : "";
return (`cannot mark the goal complete: ${openTasks.length} open todo task(s) remain: ${listed}${suffix}. ` +
"Do the remaining work, or drop the tasks that are genuinely no longer needed - closing an unfinished task " +
"to clear this gate reports a completion that did not happen. Then run the completion audit again and retry update_goal.");
}
/**
* True when a successful todo tool result came from an add operation (init /
* append) that left at least one open (pending / in_progress) task behind.
*/
export function todoResultAddsOpenTasks(details) {
if (!isRecord(details))
return false;
const op = details.op;
if (op !== "init" && op !== "append")
return false;
const phases = details.phases;
if (!isTodoPhaseArray(phases))
return false;
return phases.some((phase) => phase.tasks.some(isIncompleteTodo));
}
/**
* System reminder injected into a todo tool result when new open tasks were
* added while the thread has no goal, or only a stale (already complete) one.
* The mirror of the completion gate above: newly tracked work should be
* anchored to a live goal when it serves a durable objective.
*/
export function staleGoalTodoReminder(goal) {
if (goal !== null && goal.status !== "complete")
return undefined;
const staleLine = goal === null
? "New todo tasks were added, but this thread has no goal registered."
: "New todo tasks were added, but the registered goal is already complete (stale), so the new work is untracked.";
const fixLine = goal === null
? "Register one with create_goal only when the work must outlive this turn - it waits on external state or needs more than one verify-and-fix round."
: "Register one with create_goal only when the work must outlive this turn - it waits on external state or needs more than one verify-and-fix round; a new goal archives the completed one.";
return ["<system-reminder>", staleLine, fixLine, "Otherwise continue without a goal.", "</system-reminder>"].join("\n");
}
//# sourceMappingURL=todo-gate.js.map