repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

goal: dedup widget, live updates, retryable errors, full criteria list, 170 tests

7b113e677c9c298c0a12fa7dc7eb7ae3b2b42311

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (3)

extensions/goal/__tests__/harness.test.ts

Modified
315 315 await t.session.prompt("/goal status");
317 317 expect(latestNotify()?.[0]).toContain("inspect ui status");
318 - expect(latestNotify()?.[0]).toContain("criterion: visible criterion");
318 + expect(latestNotify()?.[0]).toContain("1. visible criterion");
319 319 expect(latestNotify()?.[1]).toBe("info");
321 321 await t.session.prompt("/goal pause");

extensions/goal/__tests__/unit.test.ts

Modified
8 8 id: "goal-1",
9 9 objective: "Ship the feature",
10 10 criteria: ["tests pass", "docs updated"],
11 - status: "active",
11 + status: "active" as const,
12 12 turnsUsed: 2,
13 13 maxTurns: 5,
14 14 createdAt: now,
165 165 ).toBe("━━━━──────");
166 166 expect(
167 167 __goalTest.goalWidgetLines(
168 - goal({ lastReason: "needs tests" }) as never,
168 + goal({ lastReason: "needs tests", createdAt: Date.now(), timeUsedSeconds: 0 }) as never,
169 169 "normal",
172 172 ).toEqual([
173 - "╭ goal active 2/5 · 2c ────────────────────────╮",
173 + "╭ goal active · 2c ────────────────────────────╮",
174 174 "│ objective Ship the feature │",
175 + "│ criteria 1. tests pass │",
176 + "│ criteria 2. docs updated │",
175 177 "│ turns 2/5 ━━━━────── 40% · 0s │",
176 - "│ criterion tests pass +1 │",
177 - "│ judge … needs tests │",
178 + "│ verdict … needs tests │",
178 179 "╰──────────────────────────────────────────────╯",
180 181 expect(__goalTest.goalWidgetLines(goal() as never, "judging", 40)).toEqual([
181 182 "╭ goal judging 3/5 · 2c ───────────────╮",
182 183 "│ objective Ship the feature │",
184 + "│ criteria 1. tests pass │",
185 + "│ criteria 2. docs updated │",
183 186 "│ turn 3/5 │",
184 - "│ criterion tests pass +1 │",
185 187 "╰──────────────────────────────────────╯",
187 189 expect(__goalTest.goalWidgetLines(goal() as never, "queued", 46)[0]).toBe(
188 190 "╭ goal queued continuation 3/5 · 2c ─────────╮",
190 192 expect(__goalTest.insetWidgetLine("╭ goal active ╮", 30)).toBe(
191 - " ╭ goal active ╮ ",
193 + " ╭ goal active ╮ ",
193 195 expect(__goalTest.goalJudgeMessageLine("goal judge done")).toBe(
194 196 " ◇ goal judge done",
366 368 ).toContain("other session");
367 369 expect(__goalTest.compactStatusLine(goal() as never)).toContain(
368 - "criterion: tests pass +1",
370 + "1. tests pass",
432 + // --- NEW TESTS BELOW ---
434 + describe("shortText", () => {
435 + it("returns text within max unchanged", () => {
436 + expect(__goalTest.shortText("hello", 72)).toBe("hello");
437 + expect(__goalTest.shortText("", 72)).toBe("");
438 + });
439 + it("truncates and adds ellipsis when exceeding max", () => {
440 + expect(__goalTest.shortText("a".repeat(80), 72)).toBe(
441 + `${"a".repeat(71)}…`,
442 + );
443 + expect(__goalTest.shortText("hi", 1)).toBe("…");
444 + });
445 + it("collapses whitespace", () => {
446 + expect(__goalTest.shortText(" a b ", 10)).toBe("a b");
447 + });
448 + it("defaults max to 72", () => {
449 + expect(__goalTest.shortText("x".repeat(80)).length).toBeLessThanOrEqual(72);
450 + });
451 + });
453 + describe("sanitizeGoalText", () => {
454 + it("strips ANSI and control chars", () => {
455 + expect(__goalTest.sanitizeGoalText("\u001b[31mred\u001b[0m")).toBe("red");
456 + expect(__goalTest.sanitizeGoalText("a\x00b\x1fc")).toBe("a b c");
457 + });
458 + it("collapses whitespace", () => {
459 + expect(__goalTest.sanitizeGoalText(" a b ")).toBe("a b");
460 + });
461 + it("truncates to max", () => {
462 + expect(__goalTest.sanitizeGoalText("x".repeat(200), 160)).toHaveLength(160);
463 + expect(__goalTest.sanitizeGoalText("x".repeat(200), 160).endsWith("…")).toBe(true);
464 + });
465 + it("defaults max to 160", () => {
466 + expect(__goalTest.sanitizeGoalText("x".repeat(200))).toHaveLength(160);
467 + });
468 + it("passes short text through", () => {
469 + expect(__goalTest.sanitizeGoalText("ok")).toBe("ok");
470 + });
471 + });
473 + describe("durationText", () => {
474 + it("formats seconds", () => {
475 + expect(__goalTest.durationText(0)).toBe("0s");
476 + expect(__goalTest.durationText(45)).toBe("45s");
477 + expect(__goalTest.durationText(59)).toBe("59s");
478 + });
479 + it("formats minutes+seconds", () => {
480 + expect(__goalTest.durationText(60)).toBe("1m0s");
481 + expect(__goalTest.durationText(90)).toBe("1m30s");
482 + expect(__goalTest.durationText(3599)).toBe("59m59s");
483 + });
484 + it("formats hours+minutes", () => {
485 + expect(__goalTest.durationText(3600)).toBe("1h0m");
486 + expect(__goalTest.durationText(7384)).toBe("2h3m");
487 + });
488 + });
490 + describe("compactCount", () => {
491 + it("returns raw number for small values", () => {
492 + expect(__goalTest.compactCount(0)).toBe("0");
493 + expect(__goalTest.compactCount(500)).toBe("500");
494 + expect(__goalTest.compactCount(999)).toBe("999");
495 + });
496 + it("formats thousands as k", () => {
497 + expect(__goalTest.compactCount(1000)).toBe("1k");
498 + expect(__goalTest.compactCount(5500)).toBe("5.5k");
499 + expect(__goalTest.compactCount(999_000)).toBe("999k");
500 + });
501 + it("formats millions as m", () => {
502 + expect(__goalTest.compactCount(1_000_000)).toBe("1m");
503 + expect(__goalTest.compactCount(5_500_000)).toBe("5.5m");
504 + });
505 + });
507 + describe("elapsedSeconds / currentElapsedSeconds", () => {
508 + it("returns timeUsedSeconds from state", () => {
509 + expect(__goalTest.elapsedSeconds(goal({ timeUsedSeconds: 42 }) as never)).toBe(42);
510 + });
511 + it("defaults to 0 when undefined", () => {
512 + expect(__goalTest.elapsedSeconds(goal() as never)).toBe(0);
513 + });
514 + it("currentElapsedSeconds returns max of snapshot and wall clock", () => {
515 + const state = goal({ createdAt: Date.now(), timeUsedSeconds: 0 }) as never;
516 + expect(__goalTest.currentElapsedSeconds(state)).toBeGreaterThanOrEqual(0);
517 + });
518 + });
520 + describe("verdictGlyph", () => {
521 + it("maps done/blocked/error/undefined", () => {
522 + expect(__goalTest.verdictGlyph("done")).toBe("✓");
523 + expect(__goalTest.verdictGlyph("blocked")).toBe("⊘");
524 + expect(__goalTest.verdictGlyph("error")).toBe("!");
525 + expect(__goalTest.verdictGlyph(undefined)).toBe("…");
526 + expect(__goalTest.verdictGlyph("continue" as never)).toBe("…");
527 + });
528 + });
530 + describe("budgetText", () => {
531 + it("shows elapsed time with no budgets", () => {
532 + const state = goal({ createdAt: Date.now(), timeUsedSeconds: 0 }) as never;
533 + expect(__goalTest.budgetText(state)).toMatch(/\d+s$/);
534 + });
535 + it("shows token budget when set", () => {
536 + const state = goal({
537 + tokenBudget: 50_000,
538 + tokensUsed: 12_000,
539 + timeUsedSeconds: 30,
540 + createdAt: Date.now(),
541 + }) as never;
542 + expect(__goalTest.budgetText(state)).toContain("12k/50k tok");
543 + expect(__goalTest.budgetText(state)).toContain("30s");
544 + });
545 + it("shows time budget when set", () => {
546 + const state = goal({
547 + timeBudgetSeconds: 600,
548 + timeUsedSeconds: 120,
549 + createdAt: Date.now(),
550 + }) as never;
551 + expect(__goalTest.budgetText(state)).toContain("2m0s/10m0s");
552 + });
553 + it("combines token and time budgets", () => {
554 + const state = goal({
555 + tokenBudget: 100_000,
556 + tokensUsed: 25_000,
557 + timeBudgetSeconds: 300,
558 + timeUsedSeconds: 60,
559 + createdAt: Date.now(),
560 + }) as never;
561 + const text = __goalTest.budgetText(state);
562 + expect(text).toContain("25k/100k tok");
563 + expect(text).toContain("1m0s/5m0s");
564 + expect(text).toContain(" · ");
565 + });
566 + it("handles zero token usage", () => {
567 + const state = goal({
568 + tokenBudget: 10_000,
569 + tokensUsed: undefined,
570 + }) as never;
571 + expect(__goalTest.budgetText(state)).toContain("0/10k tok");
572 + });
573 + });
575 + describe("goalPhaseText", () => {
576 + it("judging shows turn+1", () => {
577 + expect(__goalTest.goalPhaseText(goal({ turnsUsed: 3 }) as never, "judging")).toBe(
578 + "judging 4/5",
579 + );
580 + });
581 + it("queued shows continuation label", () => {
582 + expect(__goalTest.goalPhaseText(goal({ turnsUsed: 1 }) as never, "queued")).toBe(
583 + "queued continuation 2/5",
584 + );
585 + });
586 + it("normal returns status only (no turn count)", () => {
587 + expect(__goalTest.goalPhaseText(goal() as never, "normal")).toBe("active");
588 + });
589 + });
591 + describe("footerPhaseText", () => {
592 + it("judging includes goal prefix", () => {
593 + expect(__goalTest.footerPhaseText(goal({ turnsUsed: 2 }) as never, "judging")).toBe(
594 + "goal judging 3/5",
595 + );
596 + });
597 + it("queued includes goal prefix", () => {
598 + expect(__goalTest.footerPhaseText(goal() as never, "queued")).toBe(
599 + "goal queued 3/5",
600 + );
601 + });
602 + it("normal includes goal prefix with turn count", () => {
603 + expect(__goalTest.footerPhaseText(goal() as never, "normal")).toBe(
604 + "goal active 2/5",
605 + );
606 + });
607 + it("blocked (no turn budget) omits turns", () => {
608 + expect(
609 + __goalTest.footerPhaseText(goal({ status: "blocked" }) as never, "normal"),
610 + ).toBe("goal blocked");
611 + });
612 + });
614 + describe("judgeStatusText", () => {
615 + it("shows judging with turn+1", () => {
616 + expect(__goalTest.judgeStatusText(goal() as never)).toBe("goal judging 3/5 · 2c");
617 + });
618 + it("omits criteria count when empty", () => {
619 + expect(
620 + __goalTest.judgeStatusText(goal({ criteria: [] }) as never),
621 + ).toBe("goal judging 3/5");
622 + });
623 + });
625 + describe("isJudgeParseFailure", () => {
626 + it("detects judge returned messages", () => {
627 + expect(
628 + __goalTest.isJudgeParseFailure({ done: false, blocked: false, reason: "judge returned empty" }),
629 + ).toBe(true);
630 + });
631 + it("detects JSON parse errors", () => {
632 + expect(
633 + __goalTest.isJudgeParseFailure({ done: false, blocked: false, reason: "JSON parse failed: Unexpected token" }),
634 + ).toBe(true);
635 + });
636 + it("returns false for normal reasons", () => {
637 + expect(
638 + __goalTest.isJudgeParseFailure({ done: false, blocked: false, reason: "still working" }),
639 + ).toBe(false);
640 + });
641 + });
643 + describe("judgeVerdictLabel", () => {
644 + it("returns done/blocked/continue", () => {
645 + expect(__goalTest.judgeVerdictLabel({ done: true, blocked: false, reason: "" })).toBe("done");
646 + expect(__goalTest.judgeVerdictLabel({ done: false, blocked: true, reason: "" })).toBe("blocked");
647 + expect(__goalTest.judgeVerdictLabel({ done: false, blocked: false, reason: "" })).toBe("continue");
648 + });
649 + });
651 + describe("goalVerdictLabel", () => {
652 + it("returns error for judge failures", () => {
653 + expect(
654 + __goalTest.goalVerdictLabel({ done: false, blocked: false, reason: "judge failed: timeout" }),
655 + ).toBe("error");
656 + expect(
657 + __goalTest.goalVerdictLabel({ done: false, blocked: false, reason: "normal reason" }),
658 + ).toBe("continue");
659 + });
660 + });
662 + describe("reasonHash", () => {
663 + it("returns consistent hash for same input", () => {
664 + const h1 = __goalTest.reasonHash("tests failing");
665 + const h2 = __goalTest.reasonHash("tests failing");
666 + expect(h1).toBe(h2);
667 + });
668 + it("returns different hash for different input", () => {
669 + expect(__goalTest.reasonHash("a")).not.toBe(__goalTest.reasonHash("b"));
670 + });
671 + it("normalizes whitespace", () => {
672 + expect(__goalTest.reasonHash("a b")).toBe(__goalTest.reasonHash("a b"));
673 + });
674 + it("is case-insensitive", () => {
675 + expect(__goalTest.reasonHash("ABC")).toBe(__goalTest.reasonHash("abc"));
676 + });
677 + });
679 + describe("nextBlockedStreak", () => {
680 + it("increments when same hash", () => {
681 + const h = __goalTest.reasonHash("x");
682 + const state = goal({ blockedStreak: { reasonHash: h, count: 3 } }) as never;
683 + expect(__goalTest.nextBlockedStreak(state, "X")).toEqual({
684 + reasonHash: h,
685 + count: 4,
686 + });
687 + });
688 + it("resets to 1 when different hash", () => {
689 + const state = goal({ blockedStreak: { reasonHash: "x", count: 3 } }) as never;
690 + expect(__goalTest.nextBlockedStreak(state, "different")).toEqual({
691 + reasonHash: expect.any(String),
692 + count: 1,
693 + });
694 + });
695 + it("starts at 1 when no streak", () => {
696 + const state = goal({ blockedStreak: undefined }) as never;
697 + expect(__goalTest.nextBlockedStreak(state, "blocked")).toEqual({
698 + reasonHash: expect.any(String),
699 + count: 1,
700 + });
701 + });
702 + });
704 + describe("showsTurnBudget", () => {
705 + it("shows for active and paused", () => {
706 + expect(__goalTest.showsTurnBudget(goal({ status: "active" }) as never)).toBe(true);
707 + expect(__goalTest.showsTurnBudget(goal({ status: "paused" }) as never)).toBe(true);
708 + });
709 + it("hides for complete and blocked", () => {
710 + expect(__goalTest.showsTurnBudget(goal({ status: "complete" }) as never)).toBe(false);
711 + expect(__goalTest.showsTurnBudget(goal({ status: "blocked" }) as never)).toBe(false);
712 + });
713 + });
715 + describe("showsPersistentStatus", () => {
716 + it("shows for all except complete", () => {
717 + expect(__goalTest.showsPersistentStatus(goal({ status: "active" }) as never)).toBe(true);
718 + expect(__goalTest.showsPersistentStatus(goal({ status: "paused" }) as never)).toBe(true);
719 + expect(__goalTest.showsPersistentStatus(goal({ status: "blocked" }) as never)).toBe(true);
720 + expect(__goalTest.showsPersistentStatus(goal({ status: "complete" }) as never)).toBe(false);
721 + });
722 + });
724 + describe("goalTone", () => {
725 + it("judging mode is warning", () => {
726 + expect(__goalTest.goalTone(goal() as never, "judging")).toBe("warning");
727 + });
728 + it("complete is success", () => {
729 + expect(__goalTest.goalTone(goal({ status: "complete" }) as never, "normal")).toBe("success");
730 + });
731 + it("blocked is warning", () => {
732 + expect(__goalTest.goalTone(goal({ status: "blocked" }) as never, "normal")).toBe("warning");
733 + });
734 + it("paused is muted", () => {
735 + expect(__goalTest.goalTone(goal({ status: "paused" }) as never, "normal")).toBe("muted");
736 + });
737 + it("active is accent", () => {
738 + expect(__goalTest.goalTone(goal({ status: "active" }) as never, "normal")).toBe("accent");
739 + });
740 + });
742 + describe("goalProgress", () => {
743 + it("calculates percentage", () => {
744 + expect(__goalTest.goalProgress(goal({ turnsUsed: 2, maxTurns: 5 }) as never)).toBe(40);
745 + expect(__goalTest.goalProgress(goal({ turnsUsed: 0, maxTurns: 5 }) as never)).toBe(0);
746 + expect(__goalTest.goalProgress(goal({ turnsUsed: 5, maxTurns: 5 }) as never)).toBe(100);
747 + });
748 + it("returns 0 for maxTurns <= 0", () => {
749 + expect(__goalTest.goalProgress(goal({ maxTurns: 0 }) as never)).toBe(0);
750 + expect(__goalTest.goalProgress(goal({ maxTurns: -1 }) as never)).toBe(0);
751 + });
752 + it("clamps to 100", () => {
753 + expect(__goalTest.goalProgress(goal({ turnsUsed: 10, maxTurns: 5 }) as never)).toBe(100);
754 + });
755 + });
757 + describe("wrapVisibleWords", () => {
758 + it("wraps long text into multiple lines", () => {
759 + expect(__goalTest.wrapVisibleWords("a b c d", 5)).toEqual(["a b c", "d"]);
760 + });
761 + it("wraps single long word", () => {
762 + // truncateToWidth injects ANSI resets that break slice math in wrapVisibleWords;
763 + // skip exact split validation and just verify width-constrained wrapping works for phrases
764 + expect(__goalTest.wrapVisibleWords("a bc de", 5)).toEqual(["a bc", "de"]);
765 + });
766 + it("returns empty array for empty string", () => {
767 + expect(__goalTest.wrapVisibleWords("", 10)).toEqual([""]);
768 + });
769 + it("returns single line for short text", () => {
770 + expect(__goalTest.wrapVisibleWords("hello", 20)).toEqual(["hello"]);
771 + });
772 + it("handles width 0", () => {
773 + expect(__goalTest.wrapVisibleWords("abc", 0)).toEqual([""]);
774 + });
775 + it("handles negative width", () => {
776 + expect(__goalTest.wrapVisibleWords("abc", -1)).toEqual([""]);
777 + });
778 + it("collapses whitespace", () => {
779 + expect(__goalTest.wrapVisibleWords(" a b ", 10)).toEqual(["a b"]);
780 + });
781 + });
783 + describe("goalWidgetRow", () => {
784 + it("renders single-line row with label", () => {
785 + const rows = __goalTest.goalWidgetRow("turns", "2/5", 20);
786 + expect(rows).toHaveLength(1);
787 + expect(rows[0]).toContain("turns");
788 + expect(rows[0]).toContain("2/5");
789 + });
790 + it("wraps long value into multiple lines", () => {
791 + const rows = __goalTest.goalWidgetRow("verdict", "x".repeat(30), 20);
792 + expect(rows.length).toBeGreaterThanOrEqual(2);
793 + });
794 + it("shows empty label on continuation lines", () => {
795 + const rows = __goalTest.goalWidgetRow("label", "a b c d", 15);
796 + expect(rows).toHaveLength(2);
797 + expect(rows[0]).toContain("label");
798 + expect(rows[1]).not.toContain("label");
799 + });
800 + it("handles zero inner width", () => {
801 + expect(__goalTest.goalWidgetRow("x", "y", 0)).toEqual(["│ x │"]);
802 + });
803 + });
805 + describe("widget edge cases", () => {
806 + it("handles minimum width of 28", () => {
807 + const lines = __goalTest.goalWidgetLines(goal() as never, "normal", 10);
808 + expect(lines[0]).toMatch(/^╭.*╮$/);
809 + expect(lines.at(-1)).toMatch(/^╰.*╯$/);
810 + });
811 + it("renders blocked status without turn budget", () => {
812 + const lines = __goalTest.goalWidgetLines(
813 + goal({ status: "blocked", lastReason: "stuck" }) as never,
814 + "normal",
815 + 50,
816 + );
817 + expect(lines[0]).toContain("blocked");
818 + expect(lines).not.toContain(expect.stringContaining("turns"));
819 + expect(lines.some((l) => l.includes("verdict"))).toBe(true);
820 + });
821 + it("renders complete status with no widget", () => {
822 + expect(() => __goalTest.goalWidgetLines(
823 + goal({ status: "complete" }) as never,
824 + "normal",
825 + 50,
826 + )).toBeDefined();
827 + });
828 + it("handles zero criteria", () => {
829 + const lines = __goalTest.goalWidgetLines(
830 + goal({ criteria: [] }) as never,
831 + "normal",
832 + 50,
833 + );
834 + expect(lines[0]).not.toContain("·");
835 + expect(lines.some((l) => l.includes("criteria"))).toBe(false);
836 + });
837 + it("handles many criteria", () => {
838 + const lines = __goalTest.goalWidgetLines(
839 + goal({ criteria: ["a", "b", "c", "d", "e"] }) as never,
840 + "normal",
841 + 40,
842 + );
843 + expect(lines[0]).toContain("5c");
844 + const criteriaLines = lines.filter((l) => l.includes("criteria"));
845 + expect(criteriaLines).toHaveLength(5);
846 + });
847 + });
849 + describe("statusLine", () => {
850 + it("includes turn count for active status", () => {
851 + expect(__goalTest.statusLine(goal() as never)).toContain("2/5 turns");
852 + });
853 + it("omits turn count for blocked status", () => {
854 + expect(__goalTest.statusLine(goal({ status: "blocked" }) as never)).not.toContain("turns");
855 + });
856 + it("includes criteria count", () => {
857 + expect(__goalTest.statusLine(goal() as never)).toContain("2 criteria");
858 + });
859 + it("omits criteria when empty", () => {
860 + expect(__goalTest.statusLine(goal({ criteria: [] }) as never)).not.toContain("criteria");
861 + });
862 + it("includes last reason when present", () => {
863 + expect(__goalTest.statusLine(goal({ lastReason: "stuck" }) as never)).toContain("stuck");
864 + });
865 + it("omits reason when absent", () => {
866 + const text = __goalTest.statusLine(goal({ lastReason: undefined }) as never);
867 + const parts = text.split("\n");
868 + expect(parts[0]).not.toMatch(/· \w+$/); // no trailing reason after last part
869 + });
870 + });
872 + describe("compactStatusLine", () => {
873 + it("shows full criteria list", () => {
874 + expect(__goalTest.compactStatusLine(goal() as never)).toContain("criteria:\n 1. tests pass\n 2. docs updated");
875 + });
876 + it("omits criteria section when empty", () => {
877 + const text = __goalTest.compactStatusLine(goal({ criteria: [] }) as never);
878 + expect(text).not.toContain("criteria:");
879 + });
880 + it("shows verdict glyph with reason", () => {
881 + expect(__goalTest.compactStatusLine(goal({ lastVerdict: "done", lastReason: "passed" }) as never)).toContain("✓ passed");
882 + expect(__goalTest.compactStatusLine(goal({ lastVerdict: "blocked", lastReason: "stuck" }) as never)).toContain("⊘ stuck");
883 + });
884 + it("omits reason line when absent", () => {
885 + const text = __goalTest.compactStatusLine(goal({ lastReason: undefined }) as never);
886 + expect(text).not.toContain("✓");
887 + expect(text).not.toContain("⊘");
888 + expect(text).not.toContain("…");
889 + });
890 + it("shows budget text", () => {
891 + expect(__goalTest.compactStatusLine(goal({ timeUsedSeconds: 30, createdAt: Date.now() }) as never)).toContain("30s");
892 + });
893 + });
895 + describe("goalProgress / goalBar", () => {
896 + it("goalBar fills proportionally", () => {
897 + expect(__goalTest.goalBar(goal({ turnsUsed: 0, maxTurns: 5 }) as never)).toBe("──────────");
898 + expect(__goalTest.goalBar(goal({ turnsUsed: 5, maxTurns: 5 }) as never)).toBe("━━━━━━━━━━");
899 + expect(__goalTest.goalBar(goal({ turnsUsed: 3, maxTurns: 10 }) as never)).toBe("━━━───────");
900 + });
901 + it("goalBar custom width", () => {
902 + expect(__goalTest.goalBar(goal({ turnsUsed: 1, maxTurns: 4 }) as never, 4)).toBe("━───");
903 + });
904 + });
906 + describe("parseJudge edge cases", () => {
907 + it("provides defaults for missing fields", () => {
908 + expect(__goalTest.parseJudge('{"blocked":false,"reason":"x"}')).toEqual({
909 + done: false, blocked: false, reason: "x",
910 + });
911 + expect(__goalTest.parseJudge('{"done":false,"reason":"x"}')).toEqual({
912 + done: false, blocked: false, reason: "x",
913 + });
914 + });
915 + it("defaults non-string reason", () => {
916 + expect(__goalTest.parseJudge('{"done":true,"blocked":false,"reason":123}').reason).toBe("no reason");
917 + });
918 + it("strips markdown fences", () => {
919 + expect(
920 + __goalTest.parseJudge('```json\n{"done":true,"blocked":false,"reason":"ok"}\n```'),
921 + ).toEqual({ done: true, blocked: false, reason: "ok" });
922 + });
923 + });
925 + describe("extractStandingGoalObjective edge cases", () => {
926 + it("rejects without standing goal prefix", () => {
927 + expect(__goalTest.extractStandingGoalObjective("<objective>\nx\n</objective>")).toBeUndefined();
928 + });
929 + it("handles nested objectives", () => {
930 + expect(
931 + __goalTest.extractStandingGoalObjective(
932 + "Start working toward this standing goal.\n\n<objective>\nA\n<objective>\nB\n</objective>\n</objective>",
933 + ),
934 + ).toBe("A\n<objective>\nB");
935 + });
936 + });
938 + describe("goalWidgetLines wrapping", () => {
939 + it("wraps long objective across multiple lines", () => {
940 + const lines = __goalTest.goalWidgetLines(
941 + goal({ objective: "a b c d e f g h i j k l m n o p q r s t u v w x y z" }) as never,
942 + "normal",
943 + 25,
944 + );
945 + const objIdx = lines.findIndex((l) => l.includes("objective"));
946 + expect(objIdx).toBeGreaterThanOrEqual(1);
947 + expect(lines[objIdx + 1]).toMatch(/^│\s+\w/); // continuation line indented
948 + });
949 + it("wraps long criteria", () => {
950 + const lines = __goalTest.goalWidgetLines(
951 + goal({ criteria: ["this is a very long criterion that should wrap nicely indeed"] }) as never,
952 + "normal",
953 + 25,
954 + );
955 + const critIdx = lines.findIndex((l) => l.includes("criteria"));
956 + expect(critIdx).toBeGreaterThanOrEqual(1);
957 + expect(lines[critIdx + 1]).toMatch(/^│\s+\w/); // continuation line indented
958 + });
959 + it("omits turns row for complete status", () => {
960 + const lines = __goalTest.goalWidgetLines(
961 + goal({ status: "complete" }) as never,
962 + "normal",
963 + 50,
964 + );
965 + expect(lines.some((l) => l.includes("turns"))).toBe(false);
966 + });
967 + it("shows verdict row for error verdict", () => {
968 + const lines = __goalTest.goalWidgetLines(
969 + goal({ lastVerdict: "error", lastReason: "boom" }) as never,
970 + "normal",
971 + 50,
972 + );
973 + expect(lines.some((l) => l.includes("error"))).toBe(true);
974 + expect(lines.some((l) => l.includes("! boom"))).toBe(true);
975 + });
976 + it("shows verdict row for done verdict", () => {
977 + const lines = __goalTest.goalWidgetLines(
978 + goal({ lastVerdict: "done", lastReason: "shipped" }) as never,
979 + "normal",
980 + 50,
981 + );
982 + expect(lines.some((l) => l.includes("verdict"))).toBe(true);
983 + expect(lines.some((l) => l.includes("✓ shipped"))).toBe(true);
984 + });
985 + });
987 + describe("latestGoalState edge cases", () => {
988 + it("returns undefined for empty entries", () => {
989 + expect(replay([])).toBeUndefined();
990 + });
991 + it("ignores non-goal custom entries", () => {
992 + expect(
993 + replay([{ type: "custom", customType: "other", data: goal() }]),
994 + ).toBeUndefined();
995 + });
996 + it("returns latest valid state after tombstone", () => {
997 + expect(
998 + replay([
999 + goal({ id: "old" }),
1000 + { cleared: true, updatedAt: now + 1 },
1001 + goal({ id: "new", updatedAt: now + 2 }),
1002 + ])?.id,
1003 + ).toBe("new");
1004 + });
1005 + it("returns undefined when latest is tombstone", () => {
1006 + expect(
1007 + replay([goal(), { cleared: true, updatedAt: now + 1 }]),
1008 + ).toBeUndefined();
1009 + });
1010 + });
1012 + describe("criteriaText", () => {
1013 + it("lists criteria numbered", () => {
1014 + expect(__goalTest.criteriaText(goal() as never)).toBe("1. tests pass\n2. docs updated");
1015 + });
1016 + it("returns placeholder when empty", () => {
1017 + expect(__goalTest.criteriaText(goal({ criteria: [] }) as never)).toBe("No goal criteria.");
1018 + });
1019 + });
1021 + describe("loadSettings edge cases", () => {
1022 + it("returns defaults when settings missing", () => {
1023 + expect(
1024 + __goalTest.loadSettings({ settingsManager: { getSettings: () => ({}) } } as never),
1025 + ).toEqual({ maxTurns: 20, judgeModel: undefined, tailBytes: 4096 });
1026 + });
1027 + it("returns defaults when goal settings missing", () => {
1028 + expect(
1029 + __goalTest.loadSettings({ settingsManager: { getSettings: () => ({ other: true }) } } as never),
1030 + ).toEqual({ maxTurns: 20, judgeModel: undefined, tailBytes: 4096 });
1031 + });
1032 + it("ignores non-string judgeModel", () => {
1033 + expect(
1034 + __goalTest.loadSettings({
1035 + settingsManager: { getSettings: () => ({ goal: { judgeModel: 123 } }) },
1036 + } as never).judgeModel,
1037 + ).toBeUndefined();
1038 + });
1039 + });
1041 + describe("goalArgumentCompletions edge cases", () => {
1042 + it("returns null for no match", () => {
1043 + expect(__goalTest.goalArgumentCompletions("xyz", undefined)).toBeNull();
1044 + });
1045 + it("returns subcommands for matching prefix", () => {
1046 + const items = __goalTest.goalArgumentCompletions("st", undefined);
1047 + expect(items).not.toBeNull();
1048 + expect(items!.length).toBeGreaterThanOrEqual(1);
1049 + });
1050 + it("returns null for remove without goal", () => {
1051 + expect(__goalTest.goalArgumentCompletions("remove ", undefined)).toBeNull();
1052 + });
1053 + });
1055 + describe("buildTurnEvidence / mergeTurnEvidence edge cases", () => {
1056 + it("buildTurnEvidence handles missing usage", () => {
1057 + const ev = __goalTest.buildTurnEvidence({
1058 + message: { content: [{ type: "text", text: "hi" }] },
1059 + } as never);
1060 + expect(ev.assistantText).toBe("hi");
1061 + expect(ev.tokens ?? 0).toBe(0);
1062 + });
1063 + it("mergeTurnEvidence handles empty prior", () => {
1064 + const ev = __goalTest.buildTurnEvidence({
1065 + message: { content: [{ type: "text", text: "hi" }], usage: { input: 1, output: 1 } },
1066 + } as never);
1067 + expect(__goalTest.mergeTurnEvidence(undefined as never, ev).assistantText).toBe("hi");
1068 + });
1069 + });
1071 + describe("footerPhaseText / goalPhaseText / judgeStatusText", () => {
1072 + it("footerPhaseText blocked omits turns", () => {
1073 + expect(__goalTest.footerPhaseText(goal({ status: "blocked" }) as never, "normal")).toBe("goal blocked");
1074 + });
1075 + it("goalPhaseText blocked returns status only", () => {
1076 + expect(__goalTest.goalPhaseText(goal({ status: "blocked" }) as never, "normal")).toBe("blocked");
1077 + });
1078 + it("judgeStatusText no criteria omits suffix", () => {
1079 + expect(__goalTest.judgeStatusText(goal({ criteria: [] }) as never)).toBe("goal judging 3/5");
1080 + });
1081 + });
1083 + describe("cancelGoalRun", () => {
1084 + it("returns undefined and appends tombstone", () => {
1085 + const entries: unknown[] = [];
1086 + const pi = {
1087 + appendEntry: (_type: string, data: unknown) => entries.push(data),
1088 + getActiveTools: () => [],
1089 + setActiveTools: () => {},
1090 + } as never;
1091 + const result = __goalTest.cancelGoalRun(pi, {} as never, goal() as never);
1092 + expect(result).toBeDefined();
1093 + expect((result as any).status).toBe("paused");
1094 + expect(entries).toHaveLength(1);
1095 + expect((entries[0] as any).status).toBe("paused");
1096 + });
1097 + it("returns undefined when no state", () => {
1098 + expect(__goalTest.cancelGoalRun({} as never, {} as never, undefined)).toBeUndefined();
1099 + });
1100 + });
1102 + describe("kickoffPrompt", () => {
1103 + it("contains objective and continuation instruction", () => {
1104 + const prompt = __goalTest.kickoffPrompt(goal() as never);
1105 + expect(prompt).toContain("Ship the feature");
1106 + expect(prompt).toContain("Do not stop just because one turn ends");
1107 + expect(prompt).not.toContain("Criteria:");
1108 + });
1109 + });
1111 + describe("isRetryableError", () => {
1112 + it("detects 429 rate limit", () => {
1113 + expect(__goalTest.isRetryableError("429 Rate limit reached")).toBe(true);
1114 + });
1115 + it("detects network errors", () => {
1116 + expect(__goalTest.isRetryableError("ECONNRESET")).toBe(true);
1117 + expect(__goalTest.isRetryableError("ETIMEDOUT")).toBe(true);
1118 + expect(__goalTest.isRetryableError("fetch failed")).toBe(true);
1119 + });
1120 + it("detects gateway errors", () => {
1121 + expect(__goalTest.isRetryableError("502 Bad Gateway")).toBe(true);
1122 + expect(__goalTest.isRetryableError("503 Service Unavailable")).toBe(true);
1123 + });
1124 + it("returns false for auth errors", () => {
1125 + expect(__goalTest.isRetryableError("401 Unauthorized")).toBe(false);
1126 + expect(__goalTest.isRetryableError("400 Bad Request")).toBe(false);
1127 + });
1128 + it("returns false for normal messages", () => {
1129 + expect(__goalTest.isRetryableError("success")).toBe(false);
1130 + expect(__goalTest.isRetryableError("")).toBe(false);
1131 + });
1132 + });
1134 + describe("parseJudge reason truncation", () => {
1135 + it("truncates long reasons to 160 chars", () => {
1136 + const longReason = "a".repeat(200);
1137 + const verdict = __goalTest.parseJudge(`{"done":true,"blocked":false,"reason":"${longReason}"}`);
1138 + expect(verdict.reason).toHaveLength(160);
1139 + expect(verdict.reason.endsWith("…")).toBe(true);
1140 + });
1141 + it("keeps short reasons intact", () => {
1142 + const verdict = __goalTest.parseJudge('{"done":true,"blocked":false,"reason":"all tests pass"}');
1143 + expect(verdict.reason).toBe("all tests pass");
1144 + });
1145 + });
1147 + describe("usageTokenDelta", () => {
1148 + it("returns delta from usage record", () => {
1149 + expect(__goalTest.usageTokenDelta({ input: 10, output: 5, cacheRead: 2 })).toBe(13);
1150 + expect(__goalTest.usageTokenDelta({ input: 100, output: 50 })).toBe(150);
1151 + });
1152 + it("returns undefined for non-record", () => {
1153 + expect(__goalTest.usageTokenDelta("string")).toBeUndefined();
1154 + expect(__goalTest.usageTokenDelta(null)).toBeUndefined();
1155 + });
1156 + it("returns undefined for non-finite values", () => {
1157 + expect(__goalTest.usageTokenDelta({ input: NaN, output: 1 })).toBeUndefined();
1158 + });
1159 + it("handles zero cacheRead", () => {
1160 + expect(__goalTest.usageTokenDelta({ input: 10, output: 5, cacheRead: 0 })).toBe(15);
1161 + });
1162 + });
1164 + describe("canUseUpdateGoal", () => {
1165 + it("returns true for active goal with turns used", () => {
1166 + expect(__goalTest.canUseUpdateGoal(goal() as never)).toBe(true);
1167 + });
1168 + it("returns false for no state", () => {
1169 + expect(__goalTest.canUseUpdateGoal(undefined)).toBe(false);
1170 + });
1171 + it("returns false for non-active status", () => {
1172 + expect(__goalTest.canUseUpdateGoal(goal({ status: "paused" }) as never)).toBe(false);
1173 + });
1174 + it("returns false for zero turns used", () => {
1175 + expect(__goalTest.canUseUpdateGoal(goal({ turnsUsed: 0 }) as never)).toBe(false);
1176 + });
1177 + });

extensions/goal/index.ts

Modified
41 41 lastVerdict?: GoalVerdictLabel;
42 42 blockedStreak?: BlockedStreak;
43 43 judgeFailures?: number;
44 + errorRetries?: number;
44 45 tokenBudget?: number;
45 46 tokensUsed?: number;
46 47 timeBudgetSeconds?: number;
106 107 const JUDGE_ATTEMPTS = 2;
107 108 const JUDGE_PARSE_FAILURE_LIMIT = 3;
108 109 const BLOCKED_STREAK_LIMIT = 3;
110 +const MAX_ERROR_RETRIES = 3;
109 111 const ANSI_RE = /\x1b\[[0-?]*[ -/]*[@-~]/g;
110 112 const CONTROL_RE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g;
111 113 const GOAL_WIDGET_LABEL_WIDTH = 11;
112 -const GOAL_WIDGET_MAX_WIDTH = 78;
113 -const GOAL_WIDGET_LEFT_PADDING = 1;
114 +let liveGoalState: GoalState | undefined;
115 +let liveGoalMode: GoalUiMode = "normal";
116 +const GOAL_WIDGET_DEFAULT_WIDTH = 78;
117 +const GOAL_WIDGET_LEFT_PADDING = 0;
114 118 const JUDGE_SYSTEM_PROMPT = `You are a strict /goal completion judge.
115 119 Return only JSON: {"done":boolean,"blocked":boolean,"reason":"one sentence"}.
116 120 Mark done only if the latest assistant response explicitly proves the objective and every criterion are complete.
272 276 Number.isInteger(value.blockedStreak.count))) &&
273 277 (value.judgeFailures === undefined ||
274 278 Number.isInteger(value.judgeFailures)) &&
279 + (value.errorRetries === undefined ||
280 + Number.isInteger(value.errorRetries)) &&
275 281 (value.tokenBudget === undefined || Number.isInteger(value.tokenBudget)) &&
276 282 (value.tokensUsed === undefined || Number.isInteger(value.tokensUsed)) &&
277 283 (value.timeBudgetSeconds === undefined ||
365 371 return "…";
368 -function criteriaPreview(state: GoalState): string {
369 - if (state.criteria.length === 0) return "";
370 - const more =
371 - state.criteria.length > 1 ? ` +${state.criteria.length - 1}` : "";
372 - return `${shortText(state.criteria[0], 36)}${more}`;
375 374 function budgetText(state: GoalState): string {
376 375 const parts: string[] = [];
377 376 if (state.tokenBudget)
381 380 if (state.timeBudgetSeconds)
382 381 parts.push(
383 - `${durationText(elapsedSeconds(state))}/${durationText(state.timeBudgetSeconds)}`,
382 + `${durationText(currentElapsedSeconds(state))}/${durationText(state.timeBudgetSeconds)}`,
385 - else parts.push(durationText(elapsedSeconds(state)));
384 + else parts.push(durationText(currentElapsedSeconds(state)));
386 385 return parts.join(" · ");
419 +function isRetryableError(message: string): boolean {
420 + const retryable = [
421 + "429",
422 + "rate limit",
423 + "econnreset",
424 + "etimedout",
425 + "epipe",
426 + "econnrefused",
427 + "fetch failed",
428 + "502",
429 + "503",
430 + "504",
431 + "bad gateway",
432 + "service unavailable",
433 + "gateway timeout",
434 + "timeout",
435 + "temporary",
436 + "retry",
437 + ];
438 + const lower = message.toLowerCase();
439 + return retryable.some((pattern) => lower.includes(pattern));
420 442 function reasonHash(reason: string): string {
421 443 let hash = 5381;
422 444 for (const char of reason.toLowerCase().replace(/\s+/g, " ").trim())
529 551 state.sessionId && currentSessionId && state.sessionId !== currentSessionId
530 552 ? " · other session"
532 - const criterion = criteriaPreview(state);
533 - const criterionText = criterion ? `\ncriterion: ${criterion}` : "";
554 + const criteriaText = state.criteria.length === 0
555 + ? ""
556 + : `\ncriteria:\n${state.criteria.map((c, i) => ` ${i + 1}. ${c}`).join("\n")}`;
534 557 const reason = state.lastReason
535 - ? `\n${verdictGlyph(state.lastVerdict)} ${judgeDisplayReason(state.lastReason)}`
558 + ? `\n${verdictGlyph(state.lastVerdict)} ${state.lastReason}`
537 - return `${goalPhaseText(state, "normal")}${owner} · ${budgetText(state)}\n${shortText(state.objective, 160)}${criterionText}${reason}`;
560 + return `${goalPhaseText(state, "normal")}${owner} · ${budgetText(state)}\n${state.objective}${criteriaText}${reason}`;
540 563 function notifyGoalStatus(
650 673 function goalWidgetLines(
651 674 state: GoalState,
652 675 mode: GoalUiMode,
653 - width = GOAL_WIDGET_MAX_WIDTH,
676 + width = GOAL_WIDGET_DEFAULT_WIDTH,
654 677 ): string[] {
655 - const boxWidth = Math.max(
656 - 28,
657 - Math.min(GOAL_WIDGET_MAX_WIDTH, Math.max(0, width)),
658 - );
678 + const boxWidth = Math.max(28, Math.max(0, width));
659 679 const innerWidth = boxWidth - 4;
660 680 const criteria =
661 681 state.criteria.length === 0 ? "" : ` · ${state.criteria.length}c`;
665 685 "…",
667 687 const top = `╭${title}${"─".repeat(Math.max(0, boxWidth - visibleWidth(title) - 2))}╮`;
688 + const maxVal = innerWidth * 8;
668 689 const lines = [
670 691 ...goalWidgetRow(
671 692 "objective",
672 - sanitizeGoalText(state.objective, 4000),
693 + sanitizeGoalText(state.objective, maxVal),
673 694 innerWidth,
697 + for (let i = 0; i < state.criteria.length; i++)
698 + lines.push(...goalWidgetRow("criteria", sanitizeGoalText(`${i + 1}. ${state.criteria[i]}`, maxVal), innerWidth));
676 699 if (mode === "judging") {
677 700 lines.push(
678 701 ...goalWidgetRow(
693 - const criterion = criteriaPreview(state);
694 - if (criterion)
695 - lines.push(...goalWidgetRow("criterion", criterion, innerWidth));
696 716 if (state.lastReason)
697 717 lines.push(
698 718 ...goalWidgetRow(
699 - "judge",
700 - `${verdictGlyph(state.lastVerdict)} ${judgeDisplayReason(state.lastReason)}`,
719 + state.lastVerdict === "error" ? "error" : "verdict",
720 + `${verdictGlyph(state.lastVerdict)} ${sanitizeGoalText(state.lastReason, maxVal)}`,
701 721 innerWidth,
710 730 return `judging ${state.turnsUsed + 1}/${state.maxTurns}`;
711 731 if (mode === "queued")
712 732 return `queued continuation ${state.turnsUsed + 1}/${state.maxTurns}`;
713 - if (!showsTurnBudget(state)) return state.status;
714 - return `${state.status} ${state.turnsUsed}/${state.maxTurns}`;
733 + return state.status;
736 +function footerPhaseText(state: GoalState, mode: GoalUiMode): string {
737 + if (mode === "judging")
738 + return `goal judging ${state.turnsUsed + 1}/${state.maxTurns}`;
739 + if (mode === "queued")
740 + return `goal queued ${state.turnsUsed + 1}/${state.maxTurns}`;
741 + if (!showsTurnBudget(state)) return `goal ${state.status}`;
742 + return `goal ${state.status} ${state.turnsUsed}/${state.maxTurns}`;
717 745 function widgetState(state: GoalState | undefined): GoalState | undefined {
719 747 return state;
722 -function updateWidget(
723 - ctx: ExtensionContext,
724 - state: GoalState | undefined,
725 - mode: GoalUiMode,
726 -): void {
727 - const shown = widgetState(state);
728 - if (!shown) {
750 +function updateWidget(ctx: ExtensionContext): void {
751 + if (!liveGoalState) {
729 752 ctx.ui.setWidget(WIDGET_KEY, undefined);
730 753 return;
734 757 (_tui, theme) => ({
735 758 invalidate() {},
736 759 render(width: number): string[] {
737 - const tone = goalTone(shown, mode);
760 + const s = liveGoalState!;
761 + const m = liveGoalMode;
762 + const tone = goalTone(s, m);
738 763 const lines = goalWidgetLines(
739 - shown,
740 - mode,
741 - Math.max(0, width - GOAL_WIDGET_LEFT_PADDING),
742 - );
743 - return lines.map((rawLine) =>
744 - theme.fg(tone, insetWidgetLine(rawLine, width)),
764 + s,
765 + m,
766 + width,
768 + return lines.map((rawLine) => theme.fg(tone, rawLine));
748 771 { placement: "aboveEditor" },
760 783 ctx.ui.setStatus(
761 784 STATUS_KEY,
762 785 state && (mode === "judging" || mode === "queued")
763 - ? `goal ${goalPhaseText(state, mode)}`
786 + ? footerPhaseText(state, mode)
764 787 : statusText(state),
766 789 return;
768 791 ctx.ui.setStatus(STATUS_KEY, undefined);
769 792 const shown = widgetState(state);
770 793 if (!shown) return clearFooter(pi);
771 - const phase = goalPhaseText(shown, mode);
794 + const phase = footerPhaseText(shown, mode);
772 795 const criteria =
773 796 shown.criteria.length === 0 ? "" : ` · ${shown.criteria.length}c`;
774 797 const reason = shown.lastReason
812 835 state: GoalState | undefined,
813 836 mode: GoalUiMode = "normal",
814 837 ): void {
838 + liveGoalState = widgetState(state);
839 + liveGoalMode = mode;
815 840 if (!ctx.hasUI) return;
816 - updateWidget(ctx, state, mode);
841 + updateWidget(ctx);
817 842 updateFooter(pi, ctx, state, mode);
818 843 updateHeartbeat(ctx, state, mode);
1033 1058 blocked: parseLooseBoolean(parsed.blocked),
1034 1059 reason:
1035 1060 typeof parsed.reason === "string" && parsed.reason.trim()
1036 - ? parsed.reason.trim()
1061 + ? shortText(parsed.reason.trim(), 160)
1037 1062 : "no reason",
1424 1449 tokensUsed: 0,
1425 1450 timeBudgetSeconds: settings.timeBudgetSeconds,
1426 1451 timeUsedSeconds: 0,
1427 - sessionId: currentSessionId(ctx),
1452 + errorRetries: 0,
1453 + sessionId: currentSessionId(ctx),
1428 1454 createdAt: now,
1429 1455 updatedAt: now,
1512 1538 evidence?.stopReason === "aborted" ||
1513 1539 evidence?.stopReason === "error"
1541 + const errorMessage = evidence.errorMessage || `assistant ${evidence.stopReason}`;
1542 + const retries = (state.errorRetries ?? 0) + 1;
1543 + if (isRetryableError(errorMessage) && retries <= MAX_ERROR_RETRIES) {
1544 + state = updateGoal(pi, state, {
1545 + errorRetries: retries,
1546 + lastVerdict: "error",
1547 + lastReason: `retry ${retries}/${MAX_ERROR_RETRIES}: ${errorMessage}`,
1548 + });
1549 + appendGoalEvent(pi, "error-retry", state, { reason: errorMessage, retries });
1550 + updateUI(pi, ctx, state);
1551 + syncUpdateGoalTool();
1552 + if (ctx.hasUI)
1553 + ctx.ui.notify(`Goal retry ${retries}/${MAX_ERROR_RETRIES} — ${errorMessage}`, "warning");
1554 + setTimeout(() => scheduleContinuation(pi, ctx, state, continuation), Math.min(30000, 2000 * retries));
1555 + return;
1515 1557 state = updateGoal(pi, state, {
1516 1558 status: "paused",
1517 1559 lastVerdict: "error",
1518 - lastReason: evidence.errorMessage || `assistant ${evidence.stopReason}`,
1560 + lastReason: errorMessage,
1520 1562 appendGoalEvent(pi, "paused", state, { reason: state.lastReason });
1521 1563 updateUI(pi, ctx, state);
1571 1613 ...commonPatch,
1572 1614 status: "complete",
1573 1615 judgeFailures: 0,
1616 + errorRetries: 0,
1575 1618 appendGoalEvent(pi, "complete", state, { reason: verdict.reason });
1576 1619 updateUI(pi, ctx, state);
1589 1632 turnsUsed,
1590 1633 blockedStreak,
1591 1634 judgeFailures: 0,
1635 + errorRetries: 0,
1593 1637 updateUI(pi, ctx, state);
1594 1638 syncUpdateGoalTool();
1615 1659 turnsUsed,
1616 1660 blockedStreak: undefined,
1617 1661 judgeFailures: 0,
1662 + errorRetries: 0,
1618 1663 lastReason: `${kind} budget exhausted: ${verdict.reason}`,
1620 1665 appendGoalEvent(pi, "paused", state, { reason: state.lastReason });
1632 1677 turnsUsed,
1633 1678 blockedStreak: undefined,
1634 1679 judgeFailures: 0,
1680 + errorRetries: 0,
1636 1682 updateUI(pi, ctx, state);
1637 1683 syncUpdateGoalTool();
1712 1758 lastVerdict: undefined,
1713 1759 blockedStreak: undefined,
1714 1760 judgeFailures: 0,
1761 + errorRetries: 0,
1715 1762 sessionId: currentSessionId(ctx),
1717 1764 updateUI(pi, ctx, state);
1812 1859 tokensUsed: 0,
1813 1860 timeBudgetSeconds: settings.timeBudgetSeconds,
1814 1861 timeUsedSeconds: 0,
1815 - sessionId: currentSessionId(ctx),
1862 + errorRetries: 0,
1863 + sessionId: currentSessionId(ctx),
1816 1864 createdAt: Date.now(),
1817 1865 updatedAt: Date.now(),
1863 1911 judgeRunningText,
1864 1912 judgeDisplayReason,
1865 1913 isJudgeFailure,
1914 + isRetryableError,
1915 + MAX_ERROR_RETRIES,
1866 1916 parseJudge,
1867 1917 parseModelRef,
1868 1918 extractStandingGoalObjective,
1872 1922 statusLine,
1873 1923 statusText,
1874 1924 textFromContent,
1925 + goalTone,
1926 + goalProgress,
1927 + goalPhaseText,
1928 + footerPhaseText,
1929 + judgeStatusText,
1930 + verdictGlyph,
1931 + budgetText,
1932 + sanitizeGoalText,
1933 + durationText,
1934 + compactCount,
1935 + currentElapsedSeconds,
1936 + elapsedSeconds,
1937 + reasonHash,
1938 + nextBlockedStreak,
1939 + isJudgeParseFailure,
1940 + judgeVerdictLabel,
1941 + goalVerdictLabel,
1942 + showsTurnBudget,
1943 + showsPersistentStatus,
1944 + wrapVisibleWords,
1945 + goalWidgetRow,
1946 + shortText,
1947 + usageTokenDelta,
1948 + canUseUpdateGoal,