repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

feat(goal): show icon-prefixed widget

0810b50ed2b4454b5f64514e3a7290d1d0beab86

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (3)

extensions/goal/README.md

Modified
137 137 It gets `read`, `grep`, `find`, `ls`, and `bash`, plus the objective,
138 138 criteria, dossier tail, latest assistant text, stop reason/error message, and
139 139 last-turn tool call/result excerpts.
140 -- Judge completion writes a `goal-judge` verdict entry and updates the goal
141 - widget with the latest verdict glyph/reason.
140 +- Judge completion writes a `goal-judge` verdict entry and accumulates judge
141 + verdict glyphs/reasons in the goal widget.
142 142 - Continue verdicts stay quiet except for persistent widget/working UI.
143 143 Complete, blocked, paused, and repeated judge-failed verdicts notify.
144 144 - Done verdict marks the goal complete and clears persistent
151 151 - Incomplete verdict increments `turnsUsed`; exhausted token/time budget pauses
152 152 the goal.
153 153 There is no max-turn budget.
154 +- The elapsed timer tracks the whole active goal run, pauses on `/goal pause`,
155 + resumes on `/goal resume`, and keeps running during retryable errors.
154 156 - If still active, continuation is queued as a hidden `goal-continuation` custom
155 157 message with `deliverAs: "followUp"` and `triggerTurn: true`.
156 158 - `update_goal` is hidden until the first continue verdict increments
174 176 - UI widget key:
175 177 `goal`.
176 178 Active, queued, judging, paused, and blocked goals show a compact above-editor
177 - line by default.
179 + icon line by default.
178 180 The widget is registered once per goal display to keep ordering stable
179 181 relative to other widgets while live timer updates continue.
180 182 `/goal widget` or `alt+g` toggles expanded mode with wrapped objective,
181 - elapsed/budget info, criteria preview, and last judge verdict glyph/reason.
183 + elapsed/budget info, criteria preview, and accumulated judge verdict
184 + glyphs/reasons.
185 + Widget text wraps instead of truncating.
182 186 - Active/queued/judging goals set the streaming working message and spinner
183 187 frames as a heartbeat; terminal/passive states restore the default loader.
184 188 - Goals owned by another session show `owned by another session`; mutating

extensions/goal/__tests__/unit.test.ts

Modified
166 166 ).toBeUndefined();
169 - it("formats judge reasons as bounded one-line text", () => {
169 + it("formats judge reasons as untruncated one-line text", () => {
170 170 expect(__goalTest.judgeDisplayReason(" a\n\t b ")).toBe("a b");
171 171 expect(__goalTest.judgeDisplayReason("\u001b[31mred\u001b[0m\u0007")).toBe(
172 172 "red",
174 174 const reason = __goalTest.judgeDisplayReason("x".repeat(200));
175 - expect(reason).toHaveLength(160);
176 - expect(reason.endsWith("…")).toBe(true);
175 + expect(reason).toBe("x".repeat(200));
176 + expect(reason).not.toContain("…");
179 - it("renders compact goal widget boxes with usage-style progress", () => {
179 + it("renders icon-prefixed goal widget lines without truncation", () => {
180 180 expect(__goalTest.goalBar(goal({ turnsUsed: 2 }) as never)).toBe(
181 181 "──────────",
193 193 ).toEqual([
194 - "╭ goal active · 2c ────────────────────────────╮",
195 - "│ objective Ship the feature │",
196 - "│ criteria 1. tests pass │",
197 - "│ criteria 2. docs updated │",
198 - "│ turns 2 turns · 0s │",
199 - "│ verdict … needs tests │",
200 - "╰──────────────────────────────────────────────╯",
194 + "󰗝 active · 2 turns · 0s · 2c",
195 + " objective: Ship the feature",
196 + " criteria: 1. tests pass",
197 + " criteria: 2. docs updated",
198 + " verdict: … needs tests",
202 200 expect(__goalTest.goalWidgetLines(goal() as never, "judging", 40)).toEqual([
203 - "╭ goal judging turn 3 · 2c ────────────╮",
204 - "│ objective Ship the feature │",
205 - "│ criteria 1. tests pass │",
206 - "│ criteria 2. docs updated │",
207 - "│ turn turn 3 │",
208 - "╰──────────────────────────────────────╯",
201 + "󰗝 judging turn 3 · 2c",
202 + " objective: Ship the feature",
203 + " criteria: 1. tests pass",
204 + " criteria: 2. docs updated",
205 + " turn: turn 3",
210 - expect(__goalTest.goalWidgetLines(goal() as never, "queued", 46)[0]).toBe(
211 - "╭ goal queued continuation 3 · 2c ───────────╮",
212 - );
207 + expect(
208 + __goalTest.goalWidgetLines(goal() as never, "queued", 46).join("\n"),
209 + ).toContain("queued continuation 3 · 2 turns · 0s · 2c");
213 210 expect(
214 211 __goalTest.goalCompactWidgetLine(goal() as never, "normal", 96),
215 212 ).toContain("alt+g expand");
216 - expect(__goalTest.insetWidgetLine("╭ goal active ╮", 30)).toBe(
217 - " ╭ goal active ╮ ",
213 + expect(__goalTest.insetWidgetLine("goal active", 30)).toBe(
214 + " goal active ",
219 216 expect(__goalTest.goalJudgeMessageLine("goal judge done")).toBe(
220 - " ◇ goal judge done",
217 + " 󰗝 goal judge done",
222 219 const wrapped = __goalTest.goalWidgetLines(
223 220 goal({
650 647 ).toContain("13s");
651 648 __goalTest.syncLiveGoalTimer(undefined, "normal");
650 + it("does not reset live elapsed time on goal edits or mode changes", () => {
651 + const state = goal({ timeUsedSeconds: 10, updatedAt: 2_000 }) as never;
652 + __goalTest.syncLiveGoalTimer(state, "normal", 10_000);
654 + const edited = goal({
655 + timeUsedSeconds: 10,
656 + updatedAt: 12_000,
657 + criteria: ["tests pass", "docs updated", "new criterion"],
658 + }) as never;
659 + __goalTest.syncLiveGoalTimer(edited, "judging", 13_000);
661 + expect(__goalTest.liveDisplayState(edited, 14_000)?.timeUsedSeconds).toBe(
662 + 14,
663 + );
664 + __goalTest.syncLiveGoalTimer(undefined, "normal");
665 + });
653 666 it("shows token budget when set", () => {
654 667 const state = goal({
655 668 tokenBudget: 50_000,
1000 1013 describe("widget edge cases", () => {
1001 - it("handles minimum width of 28", () => {
1014 + it("handles minimum width", () => {
1002 1015 const lines = __goalTest.goalWidgetLines(goal() as never, "normal", 10);
1003 - expect(lines[0]).toMatch(/^╭.*╮$/);
1004 - expect(lines.at(-1)).toMatch(/^╰.*╯$/);
1016 + expect(lines[0]).toBe("󰗝 active");
1017 + expect(lines.join("\n")).not.toContain("…");
1006 1019 it("renders blocked status without turn budget", () => {
1007 1020 const lines = __goalTest.goalWidgetLines(
1028 1041 "normal",
1031 - expect(lines[0]).not.toContain("·");
1044 + expect(lines[0]).toBe("󰗝 active · 2 turns · 0s");
1032 1045 expect(lines.some((l) => l.includes("criteria"))).toBe(false);
1034 1047 it("handles many criteria", () => {
1188 1201 describe("goalWidgetLines wrapping", () => {
1202 + it("renders accumulated judge verdicts", () => {
1203 + const lines = __goalTest.goalWidgetLines(
1204 + goal({
1205 + lastReason: undefined,
1206 + verdicts: [
1207 + { turn: 1, label: "continue", reason: "needs tests" },
1208 + { turn: 2, label: "blocked", reason: "needs credentials" },
1209 + ],
1210 + }) as never,
1211 + "normal",
1212 + 80,
1213 + );
1215 + expect(lines).toContain(" verdict 1: … needs tests");
1216 + expect(lines).toContain(" verdict 2: ⊘ needs credentials");
1217 + });
1189 1218 it("wraps long objective across multiple lines", () => {
1190 1219 const lines = __goalTest.goalWidgetLines(
1197 1226 const objIdx = lines.findIndex((l) => l.includes("objective"));
1198 1227 expect(objIdx).toBeGreaterThanOrEqual(1);
1199 - expect(lines[objIdx + 1]).toMatch(/^│\s+\w/); // continuation line indented
1228 + expect(lines[objIdx + 1]).toMatch(/^\s+\w/); // continuation line indented
1201 1230 it("wraps long criteria", () => {
1202 1231 const lines = __goalTest.goalWidgetLines(
1211 1240 const critIdx = lines.findIndex((l) => l.includes("criteria"));
1212 1241 expect(critIdx).toBeGreaterThanOrEqual(1);
1213 - expect(lines[critIdx + 1]).toMatch(/^│\s+\w/); // continuation line indented
1242 + expect(lines[critIdx + 1]).toMatch(/^\s+\w/); // continuation line indented
1215 1244 it("omits turns row for complete status", () => {
1216 1245 const lines = __goalTest.goalWidgetLines(
1431 - describe("parseJudge reason truncation", () => {
1432 - it("truncates long reasons to 160 chars", () => {
1460 + describe("parseJudge reason text", () => {
1461 + it("keeps long reasons untruncated", () => {
1433 1462 const longReason = "a".repeat(200);
1434 1463 const verdict = __goalTest.parseJudge(
1435 1464 `{"done":true,"blocked":false,"reason":"${longReason}"}`,
1437 - expect(verdict.reason).toHaveLength(160);
1438 - expect(verdict.reason.endsWith("…")).toBe(true);
1466 + expect(verdict.reason).toBe(longReason);
1467 + expect(verdict.reason).not.toContain("…");
1440 1469 it("keeps short reasons intact", () => {
1441 1470 const verdict = __goalTest.parseJudge(

extensions/goal/index.ts

Modified
52 52 count: number;
55 +type GoalVerdictItem = {
56 + turn: number;
57 + label: GoalVerdictLabel;
58 + reason: string;
59 + createdAt?: number;
60 +};
55 62 type GoalState = {
56 63 schemaVersion: 2;
57 64 id: string;
61 68 turnsUsed: number;
62 69 lastReason?: string;
63 70 lastVerdict?: GoalVerdictLabel;
71 + verdicts?: GoalVerdictItem[];
64 72 blockedStreak?: BlockedStreak;
65 73 judgeFailures?: number;
66 74 errorRetries?: number;
178 186 const MAX_DOSSIER_LIST = 12;
179 187 const STATUS_KEY = "goal";
180 188 const WIDGET_KEY = "goal";
189 +const GOAL_ICON = "󰗝";
181 190 const FOOTER_SEGMENT = { id: "goal", zone: "llm", order: 30 } as const;
182 191 const JUDGE_ATTEMPTS = 2;
183 192 const JUDGE_PARSE_FAILURE_LIMIT = 3;
398 407 value.lastVerdict === "blocked" ||
399 408 value.lastVerdict === "continue" ||
400 409 value.lastVerdict === "error") &&
410 + (value.verdicts === undefined ||
411 + (Array.isArray(value.verdicts) &&
412 + value.verdicts.every(isGoalVerdictItem))) &&
401 413 (value.blockedStreak === undefined ||
402 414 (isRecord(value.blockedStreak) &&
403 415 typeof value.blockedStreak.reasonHash === "string" &&
440 452 return undefined;
455 +function isGoalVerdictItem(value: unknown): value is GoalVerdictItem {
456 + if (!isRecord(value)) return false;
457 + return (
458 + Number.isInteger(value.turn) &&
459 + (value.label === "done" ||
460 + value.label === "blocked" ||
461 + value.label === "continue" ||
462 + value.label === "error") &&
463 + typeof value.reason === "string" &&
464 + (value.createdAt === undefined || typeof value.createdAt === "number")
465 + );
443 468 function isGoalDossier(value: unknown): value is GoalDossier {
444 469 if (!isRecord(value)) return false;
445 470 return (
550 575 criteria: [],
551 576 status: "active",
552 577 turnsUsed: 0,
578 + verdicts: [],
553 579 tokenBudget: settings.tokenBudget,
554 580 tokensUsed: 0,
555 581 timeBudgetSeconds: settings.timeBudgetSeconds,
667 693 return parts.join(" · ");
696 +function cleanGoalText(text: string): string {
697 + return text
698 + .replace(ANSI_RE, "")
699 + .replace(CONTROL_RE, " ")
700 + .replace(/\s+/g, " ")
701 + .trim();
670 704 function sanitizeGoalText(text: string, max = 160): string {
671 - return shortText(
672 - text.replace(ANSI_RE, "").replace(CONTROL_RE, " ").replace(/\s+/g, " "),
673 - max,
674 - );
705 + return shortText(cleanGoalText(text), max);
677 708 function stringList(
699 730 function judgeDisplayReason(reason: string | undefined): string {
700 - return sanitizeGoalText(reason || "no reason", 160);
731 + return cleanGoalText(reason || "no reason");
703 734 function normalizeJudgeVerdict(value: unknown): JudgeVerdict {
707 738 blocked: parseLooseBoolean(verdict.blocked),
708 739 reason:
709 740 typeof verdict.reason === "string" && verdict.reason.trim()
710 - ? shortText(verdict.reason.trim(), 160)
741 + ? cleanGoalText(verdict.reason)
711 742 : "no reason",
770 801 return judgeVerdictLabel(verdict);
804 +function withJudgeVerdict(
805 + state: GoalState,
806 + verdict: JudgeVerdict,
807 + turn: number,
808 +): Pick<GoalState, "lastReason" | "lastVerdict" | "verdicts"> {
809 + const label = goalVerdictLabel(verdict);
810 + return {
811 + lastReason: verdict.reason,
812 + lastVerdict: label,
813 + verdicts: [
814 + ...(state.verdicts ?? []),
815 + { turn, label, reason: verdict.reason, createdAt: Date.now() },
816 + ],
817 + };
773 820 function appendVisibleCustomMessage(
774 821 ctx: ExtensionContext,
775 822 customType: string,
802 849 appendVisibleCustomMessage(
804 851 GOAL_EVENT_ENTRY,
805 - `goal ${event}${state?.lastReason ? ` · ${shortText(state.lastReason)}` : ""}`,
852 + `goal ${event}${state?.lastReason ? ` · ${cleanGoalText(state.lastReason)}` : ""}`,
806 853 payload,
971 1018 function goalJudgeMessageLine(content: string): string {
972 - return ` ◇ ${content}`;
1019 + return ` ${GOAL_ICON} ${content}`;
1022 +function goalIconWrap(rows: string[], width: number): string[] {
1023 + const safeWidth = Math.max(1, width);
1024 + const firstPrefix = `${GOAL_ICON} `;
1025 + const nextPrefix = " ";
1026 + const lines: string[] = [];
1027 + for (const row of rows) {
1028 + const prefix = lines.length === 0 ? firstPrefix : nextPrefix;
1029 + const textWidth = Math.max(1, safeWidth - visibleWidth(prefix));
1030 + for (const part of wrapVisibleWords(cleanGoalText(row), textWidth)) {
1031 + lines.push(`${lines.length === 0 ? firstPrefix : nextPrefix}${part}`);
1034 + return lines;
1037 +function goalWidgetRows(state: GoalState, mode: GoalUiMode): string[] {
1038 + const criteriaText =
1039 + state.criteria.length === 0 ? "" : ` · ${state.criteria.length}c`;
1040 + const rows = [
1041 + `${goalPhaseText(state, mode)}${showsTurnBudget(state) && mode !== "judging" ? ` · ${turnCountText(state.turnsUsed)} · ${budgetText(state)}` : ""}${criteriaText}`,
1042 + `objective: ${state.objective}`,
1043 + ];
1044 + for (let i = 0; i < state.criteria.length; i++)
1045 + rows.push(`criteria: ${i + 1}. ${state.criteria[i]}`);
1046 + if (mode === "judging") rows.push(`turn: ${nextTurnText(state)}`);
1047 + for (const [index, verdict] of (state.verdicts ?? []).entries())
1048 + rows.push(
1049 + `verdict ${index + 1}: ${verdictGlyph(verdict.label)} ${verdict.reason}`,
1050 + );
1051 + const latestVerdict = state.verdicts?.at(-1);
1052 + if (
1053 + state.lastReason &&
1054 + (state.lastVerdict === "error" ||
1055 + latestVerdict?.reason !== state.lastReason)
1057 + rows.push(
1058 + `${state.lastVerdict === "error" ? "error" : "verdict"}: ${verdictGlyph(state.lastVerdict)} ${state.lastReason}`,
1059 + );
1060 + return rows;
975 1063 function goalWidgetLines(
977 1065 mode: GoalUiMode,
978 1066 width = GOAL_WIDGET_DEFAULT_WIDTH,
979 1067 ): string[] {
980 - const boxWidth = Math.max(28, Math.max(0, width));
981 - const innerWidth = boxWidth - 4;
982 - const criteria =
983 - state.criteria.length === 0 ? "" : ` · ${state.criteria.length}c`;
984 - const title = truncateToWidth(
985 - ` goal ${goalPhaseText(state, mode)}${criteria} `,
986 - boxWidth - 2,
987 - "…",
988 - );
989 - const top = `╭${title}${"─".repeat(Math.max(0, boxWidth - visibleWidth(title) - 2))}╮`;
990 - const maxVal = innerWidth * 8;
991 - const lines = [
992 - top,
993 - ...goalWidgetRow(
994 - "objective",
995 - sanitizeGoalText(state.objective, maxVal),
996 - innerWidth,
997 - ),
998 - ];
999 - for (let i = 0; i < state.criteria.length; i++)
1000 - lines.push(
1001 - ...goalWidgetRow(
1002 - "criteria",
1003 - sanitizeGoalText(`${i + 1}. ${state.criteria[i]}`, maxVal),
1004 - innerWidth,
1005 - ),
1006 - );
1007 - if (mode === "judging") {
1008 - lines.push(...goalWidgetRow("turn", nextTurnText(state), innerWidth));
1009 - } else if (showsTurnBudget(state)) {
1010 - lines.push(
1011 - ...goalWidgetRow(
1012 - "turns",
1013 - `${turnCountText(state.turnsUsed)} · ${budgetText(state)}`,
1014 - innerWidth,
1015 - ),
1016 - );
1018 - if (state.lastReason)
1019 - lines.push(
1020 - ...goalWidgetRow(
1021 - state.lastVerdict === "error" ? "error" : "verdict",
1022 - `${verdictGlyph(state.lastVerdict)} ${sanitizeGoalText(state.lastReason, maxVal)}`,
1023 - innerWidth,
1024 - ),
1025 - );
1026 - lines.push(`╰${"─".repeat(boxWidth - 2)}╯`);
1027 - return lines;
1068 + return goalIconWrap(goalWidgetRows(state, mode), width);
1030 1071 function goalPhaseText(state: GoalState, mode: GoalUiMode): string {
1099 +function currentElapsedSeconds(state: GoalState): number {
1100 + return liveDisplayState(state)?.timeUsedSeconds ?? state.timeUsedSeconds ?? 0;
1058 1103 function syncLiveGoalTimer(
1059 1104 state: GoalState | undefined,
1060 1105 mode: GoalUiMode,
1067 1112 const baseSeconds = state.timeUsedSeconds ?? 0;
1069 1114 liveGoalTimer?.goalId === state.id &&
1070 - liveGoalTimer.mode === mode &&
1071 - liveGoalTimer.baseSeconds === baseSeconds &&
1072 - liveGoalTimer.stateUpdatedAt === state.updatedAt
1115 + liveGoalTimer.baseSeconds === baseSeconds
1116 + ) {
1117 + liveGoalTimer.mode = mode;
1118 + liveGoalTimer.stateUpdatedAt = state.updatedAt;
1074 1119 return;
1075 1121 liveGoalTimer = {
1076 1122 goalId: state.id,
1099 1145 mode: GoalUiMode,
1100 1146 width = GOAL_WIDGET_DEFAULT_WIDTH,
1101 1147 ): string {
1148 + return goalCompactWidgetLines(state, mode, width)[0] ?? "";
1151 +function goalCompactWidgetLines(
1152 + state: GoalState,
1153 + mode: GoalUiMode,
1154 + width = GOAL_WIDGET_DEFAULT_WIDTH,
1155 +): string[] {
1102 1156 const criteria =
1103 1157 state.criteria.length === 0 ? "" : ` · ${state.criteria.length}c`;
1104 - const reason = state.lastReason
1105 - ? ` · ${verdictGlyph(state.lastVerdict)} ${sanitizeGoalText(state.lastReason, 48)}`
1106 - : "";
1107 - return truncateToWidth(
1108 - `◇ ${footerPhaseText(state, mode)} · alt+g expand · ${budgetText(state)}${criteria} · ${sanitizeGoalText(state.objective, 160)}${reason}`,
1109 - Math.max(0, width),
1110 - "…",
1158 + const error =
1159 + state.lastVerdict === "error" && state.lastReason
1160 + ? ` · ! ${state.lastReason}`
1161 + : "";
1162 + return goalIconWrap(
1164 + `${footerPhaseText(state, mode)} · alt+g expand · ${budgetText(state)}${criteria} · ${state.objective}${error}`,
1165 + ...(state.verdicts ?? []).map(
1166 + (verdict, index) =>
1167 + `verdict ${index + 1}: ${verdictGlyph(verdict.label)} ${verdict.reason}`,
1168 + ),
1169 + ],
1170 + width,
1129 1189 const tone = goalTone(state, m);
1130 1190 const lines =
1131 1191 liveGoalWidgetMode === "compact"
1132 - ? [goalCompactWidgetLine(state, m, width)]
1192 + ? goalCompactWidgetLines(state, m, width)
1133 1193 : goalWidgetLines(state, m, width);
1134 1194 return lines.map((rawLine) => theme.fg(tone, rawLine));
2018 2078 const next = updateGoal(pi, state, {
2019 2079 status: "paused",
2020 2080 lastReason: "cancelled by user",
2081 + timeUsedSeconds: currentElapsedSeconds(state),
2022 2083 safeUpdateUI(pi, ctx, next);
2023 2084 setToolActive(pi, "update_goal", false);
2189 2250 let removeTerminalInput: (() => void) | undefined;
2190 2251 let probe: ProbeState | undefined;
2191 2252 let lastTurnEvidence: TurnEvidence | undefined;
2192 - let turnStartedAt: number | undefined;
2193 2253 let liveUiInterval: ReturnType<typeof setInterval> | undefined;
2194 2254 const stopLiveUiTicker = () => {
2195 2255 if (!liveUiInterval) return;
2331 2391 pi.on("agent_start", (_event, _ctx) => {
2332 2392 lastTurnEvidence = undefined;
2333 - turnStartedAt = Date.now();
2334 2393 if (probe?.active) appendProbe(pi, "agent-start", { mode: probe.mode });
2413 2472 errorRetries: retries,
2414 2473 lastVerdict: "error",
2415 2474 lastReason: `retry ${retries}/${MAX_ERROR_RETRIES}: ${errorMessage}`,
2475 + timeUsedSeconds: currentElapsedSeconds(state),
2417 2477 appendGoalEvent(pi, ctx, "error-retry", state, {
2418 2478 reason: errorMessage,
2436 2496 status: "paused",
2437 2497 lastVerdict: "error",
2438 2498 lastReason: errorMessage,
2499 + timeUsedSeconds: currentElapsedSeconds(state),
2440 2501 appendGoalEvent(pi, ctx, "paused", state, { reason: state.lastReason });
2441 2502 renderGoalUi(ctx, state);
2466 2527 lastJudgeReason: verdict.reason,
2468 2529 appendJudge(pi, ctx, "verdict", judged, verdict);
2530 + const verdictPatch = isJudgeFailure(verdict)
2531 + ? ({
2532 + lastReason: verdict.reason,
2533 + lastVerdict: "error" as const,
2534 + } satisfies Partial<GoalState>)
2535 + : withJudgeVerdict(judged, verdict, judged.turnsUsed + 1);
2469 2536 const commonPatch: Partial<GoalState> = {
2470 - lastReason: verdict.reason,
2471 - lastVerdict: goalVerdictLabel(verdict),
2537 + ...verdictPatch,
2472 2538 tokensUsed: (judged.tokensUsed ?? 0) + tokenDelta(evidence),
2473 - timeUsedSeconds:
2474 - (judged.timeUsedSeconds ?? 0) +
2475 - (turnStartedAt ? Math.floor((Date.now() - turnStartedAt) / 1000) : 0),
2539 + timeUsedSeconds: currentElapsedSeconds(judged),
2477 2541 if (isJudgeFailure(verdict)) {
2478 2542 const failures = (judged.judgeFailures ?? 0) + 1;
2635 2699 if (!ownedGoalOrNotify(ctx, state)) return;
2636 2700 if (state.status !== "active")
2637 2701 return ctx.ui.notify("Goal is not active.", "warning");
2638 - state = updateGoal(pi, state, { status: "paused" });
2702 + state = updateGoal(pi, state, {
2703 + status: "paused",
2704 + timeUsedSeconds: currentElapsedSeconds(state),
2705 + });
2639 2706 renderGoalUi(ctx, state);
2640 2707 syncUpdateGoalTool();
2641 2708 ctx.ui.notify("Goal paused", "info");
2648 2715 state = updateGoal(pi, state, {
2649 2716 status: "active",
2650 2717 turnsUsed: 0,
2718 + lastReason: undefined,
2651 2719 lastVerdict: undefined,
2652 2720 blockedStreak: undefined,
2653 2721 judgeFailures: 0,
2671 2739 state = updateGoal(pi, state, {
2672 2740 status: "complete",
2673 2741 lastReason: reason,
2742 + timeUsedSeconds: currentElapsedSeconds(state),
2675 2744 renderGoalUi(ctx, state);
2676 2745 syncUpdateGoalTool();
2682 2751 state = updateGoal(pi, state, {
2683 2752 status: "paused",
2684 2753 lastReason: "cleared",
2754 + timeUsedSeconds: currentElapsedSeconds(state),
2686 2756 state = undefined;
2687 2757 pi.appendEntry(GOAL_STATE_ENTRY, {