Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: keep a long closing question in a clipped run output so the run still needs review
AdityaUmalee50c1cf0eaa6
diff --git a/server/automation-reports.test.ts b/server/automation-reports.test.tsindex 8b8d8dd18c..1e765a4816 100644--- a/server/automation-reports.test.ts+++ b/server/automation-reports.test.ts@@ -44,6 +44,12 @@ describe("routineRunNeedsReview", () => {expect(routineRunNeedsReview({ status: "waiting", attention: ROUTINE_HANDOFF_WAIT })).toBe(false);expect(routineRunNeedsReview({ status: "running" })).toBe(false);expect(routineRunNeedsReview({ status: "completed", output: clipRunOutput(`${"Long report. ".repeat(300)}\nNEEDS INPUT: Send it?`, 2_000) })).toBe(true);+ // The source chat is synced from the stored output alone: a closing question over half of it, or over all of it, still counts.+ for (const words of [150, 300]) {+ const reply = `${"Long report. ".repeat(300)}\nNEEDS INPUT: ${"Which one? ".repeat(words)}\ndefault: wait`;+ expect(routineRunNeedsReview({ status: "completed", output: clipRunOutput(reply, 2_000) })).toBe(routineRunNeedsReview({ status: "completed" }, reply));+ expect(routineRunNeedsReview({ status: "completed", output: clipRunOutput(reply, 2_000) })).toBe(true);+ }expect(routineRunNeedsReview({ status: "cancelled" })).toBe(false);});});diff --git a/server/routine-lines.test.ts b/server/routine-lines.test.tsindex ba94c5151f..be402f157b 100644--- a/server/routine-lines.test.ts+++ b/server/routine-lines.test.ts@@ -70,8 +70,14 @@ describe("clipRunOutput", () => {expect(clipRunOutput(`${long}\nNEEDS INPUT: Go?\nMore text after it.`, 2_000)).toBe(`${long}\nNEEDS INPUT: Go?\nMore text after it.`.slice(0, 2_000));});- it("cuts plainly when the question alone is too long to keep", () => {- const text = `${long}\nNEEDS INPUT: ${"why ".repeat(400)}?`;- expect(clipRunOutput(text, 2_000)).toBe(text.slice(0, 2_000));+ it("keeps a long closing question that fits, and cuts one too long on its own line", () => {+ const question = `NEEDS INPUT: ${"why ".repeat(300)}?`;+ const kept = clipRunOutput(`${long}\n${question}`, 2_000);+ expect(kept.length).toBeLessThanOrEqual(2_000);+ expect(kept.endsWith(`\n…\n${question}`)).toBe(true);+ const cut = clipRunOutput(`${long}\nNEEDS INPUT: ${"why ".repeat(600)}?\ndefault: wait`, 2_000);+ expect(cut.length).toBe(2_000);+ expect(cut.startsWith("NEEDS INPUT: why")).toBe(true);+ expect(cut.endsWith("…")).toBe(true);});});diff --git a/server/routine-lines.ts b/server/routine-lines.tsindex 557298c1c3..729cf9030d 100644--- a/server/routine-lines.ts+++ b/server/routine-lines.ts@@ -91,14 +91,20 @@ export function applyCheckResult(routine: RoutineTroubleCode & { checkTrouble?:const CLOSING_QUESTION = /^\s*needs input:/i;/** A run's reply cut to max characters for its stored output. A reply that ends on a NEEDS INPUT question (with at most- * a default: line after it) keeps that question whole at the end, so a long reply still reads as waiting on the person. */+ * a default: line after it) keeps that question at the end, whole when it fits and else cut on its own line, so a long+ * reply still reads as waiting on the person. */export function clipRunOutput(text: string, max: number): string {if (text.length <= max) return text;const lines = text.split(/\r?\n/);const at = lines.findLastIndex((line) => CLOSING_QUESTION.test(line));const after = at < 0 ? [] : lines.slice(at + 1).filter((line) => line.trim());const closing = at >= 0 && (after.length === 0 || (after.length === 1 && /^default:/i.test(after[0]!.trim())));- const tail = closing ? lines.slice(at).join("\n").trim() : "";- if (!tail || tail.length > max / 2) return text.slice(0, max);- return `${text.slice(0, max - tail.length - 3).trimEnd()}\n…\n${tail}`;+ if (!closing) return text.slice(0, max);+ const tail = lines.slice(at).join("\n").trim();+ if (tail.length > max) {+ const question = lines[at]!.trim();+ return question.length <= max ? question : `${question.slice(0, max - 1)}…`;+ }+ const room = max - tail.length - 3;+ return room > 0 ? `${text.slice(0, room).trimEnd()}\n…\n${tail}` : tail;}