@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
38 lines • 1.78 kB
JavaScript
import { formatGoalElapsedSeconds, goalStatusLabel } from "./format.js";
import { goalDisplayStatus } from "./types.js";
export const STATUS_KEY = "goal";
const OBJECTIVE_PREVIEW_MAX_LENGTH = 32;
export function truncateGoalObjective(objective, maxLength = OBJECTIVE_PREVIEW_MAX_LENGTH) {
const normalized = objective.replace(/\s+/g, " ").trim();
if (normalized.length <= maxLength)
return normalized;
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
}
export function updateGoalUi(ctx, goal, liveElapsedSeconds) {
if (!ctx.hasUI)
return;
ctx.ui.setStatus(STATUS_KEY, goal === null ? undefined : goalStatusText(goal, liveElapsedSeconds));
}
export function goalStatusText(goal, liveElapsedSeconds) {
switch (goalDisplayStatus(goal)) {
case "active": {
if (liveElapsedSeconds !== undefined) {
return `Pursuing goal (${formatGoalElapsedSeconds(liveElapsedSeconds)})`;
}
return goal.timeUsedSeconds > 0
? `Pursuing goal (${formatGoalElapsedSeconds(goal.timeUsedSeconds)})`
: "Pursuing goal";
}
case "paused":
return goal.continuationStoppedAt === undefined
? "Goal paused (/goal resume)"
: `Goal ${goalStatusLabel("paused", goal.continuationStoppedAt)}`;
case "blocked":
return goal.blockedReason ? `Goal blocked: ${goal.blockedReason}` : "Goal blocked";
case "complete": {
const elapsed = goal.timeUsedSeconds > 0 ? ` (${formatGoalElapsedSeconds(goal.timeUsedSeconds)})` : "";
return `${truncateGoalObjective(goal.objective)} \u00b7 Goal achieved${elapsed}`;
}
}
}
//# sourceMappingURL=ui.js.map