From 8800d4d114fd02062b02b486dc8ddaa3e270305d Mon Sep 17 00:00:00 2001 From: arpan Date: Thu, 20 Aug 2026 16:57:26 +0530 Subject: [PATCH] fix(shared): preserve paragraph breaks in the Bot system prompt SYSTEM_PROMPT was an array of lines with "" entries marking paragraph breaks, joined with .join(" "). That turns every break into a double space instead of a real paragraph gap, collapsing the whole multi-section prompt into one run-on string before it reaches the model. Split the array into paragraphs (lines joined with a space) and join paragraphs with a blank line instead. --- shared/bot-prompt.test.ts | 25 +++++++++++++++++++++++++ shared/bot-prompt.ts | 22 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 shared/bot-prompt.test.ts diff --git a/shared/bot-prompt.test.ts b/shared/bot-prompt.test.ts new file mode 100644 index 0000000..2120821 --- /dev/null +++ b/shared/bot-prompt.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, test } from "bun:test"; +import { SYSTEM_PROMPT } from "./bot-prompt"; + +describe("SYSTEM_PROMPT", () => { + test("keeps paragraph breaks as blank lines instead of collapsing them into spaces", () => { + expect(SYSTEM_PROMPT).toContain("\n\n"); + expect(SYSTEM_PROMPT).not.toContain(" "); + }); + + test("keeps each paragraph as one unbroken line of prose", () => { + for (const paragraph of SYSTEM_PROMPT.split("\n\n")) { + expect(paragraph).not.toContain("\n"); + expect(paragraph.length).toBeGreaterThan(0); + } + }); + + test("still contains the full instruction text, unchanged in wording", () => { + expect(SYSTEM_PROMPT).toContain( + "You are a Bot with your own computer, a real web browser the person can watch you use.", + ); + expect(SYSTEM_PROMPT).toContain( + "Say what you found or did in plain language, briefly.", + ); + }); +}); diff --git a/shared/bot-prompt.ts b/shared/bot-prompt.ts index 8e92490..2b1ec52 100644 --- a/shared/bot-prompt.ts +++ b/shared/bot-prompt.ts @@ -10,7 +10,7 @@ * The prompt requires snapshot-first computer use. Element refs are opaque and valid only with the * snapshotId that produced them, so the Bot must read refs from the page before acting. */ -export const SYSTEM_PROMPT = [ +const SYSTEM_PROMPT_LINES = [ "You are a Bot with your own computer, a real web browser the person can watch you use.", "When you are asked to look at, open, visit, check or read a web page, call computer_navigate.", "Never claim you cannot browse: opening a page is something you can actually do.", @@ -53,4 +53,22 @@ export const SYSTEM_PROMPT = [ "something to retry: say plainly what was blocked and why, and stop. Do not try another route to", "the same thing.", "Say what you found or did in plain language, briefly.", -].join(" "); +]; + +/** + * `SYSTEM_PROMPT_LINES` uses `""` as a paragraph break. Joining the whole array with `" "` would + * collapse those breaks into a double space instead of a real paragraph gap, turning the prompt into + * one run-on block. Join each paragraph's lines with a space, then join paragraphs with a blank line. + */ +export const SYSTEM_PROMPT = SYSTEM_PROMPT_LINES.reduce( + (paragraphs, line) => { + if (line === "") { + paragraphs.push(""); + return paragraphs; + } + const last = paragraphs.length - 1; + paragraphs[last] = paragraphs[last] ? `${paragraphs[last]} ${line}` : line; + return paragraphs; + }, + [""], +).join("\n\n");