diff options
| -rw-r--r-- | src/index.ts | 3 | ||||
| -rw-r--r-- | src/prompt.ts | 21 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/index.ts b/src/index.ts index 152c94d..e4d23f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -261,8 +261,9 @@ export default function browserHarnessExtension(pi: ExtensionAPI): void { }); pi.on("before_agent_start", async (event) => { + const target = resolveCdpTarget(process.env, await readTarget()); return { - systemPrompt: event.systemPrompt + getBrowserSystemPrompt(client?.status().alive ?? false), + systemPrompt: event.systemPrompt + getBrowserSystemPrompt(client?.status().alive ?? false, target), }; }); } diff --git a/src/prompt.ts b/src/prompt.ts index 4fb78a7..db0e6a4 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -1,11 +1,28 @@ -export function getBrowserSystemPrompt(connected = true): string { +import { type CdpTarget, DEFAULT_REMOTE_CDP } from "./cdp/endpoint"; + +/** + * FORK: which Chrome browser_* drives. Upstream always means "the user's own + * Chrome"; here the default is castle's shared one, signed out of everything, + * and pi-chrome's chrome_* tools drive a signed-in Brave - so the model has to + * be told which is which to route between them. + */ +const describeChrome = (target?: CdpTarget): string => { + if (!target || target.kind === "invalid") return "a real Chrome (not headless)"; + if (target.kind === "local") return "a real Chrome (the user's own, on this machine)"; + if (`${target.host}:${target.port}` === DEFAULT_REMOTE_CDP) { + return "a real Chrome (castle's shared browser on the wire network, signed out of every account — not the user's own browser)"; + } + return `a real Chrome (the one at ${target.host}:${target.port})`; +}; + +export function getBrowserSystemPrompt(connected = true, target?: CdpTarget): string { const connectionNotice = connected ? "" : "Browser is not connected. Run browser_setup or /browser-setup to connect.\n\n"; return ` ## Browser Control -${connectionNotice}You control the user's running Chrome through \`browser_*\` tools alongside the +${connectionNotice}You control ${describeChrome(target)} through \`browser_*\` tools alongside the standard pi tools. Per-tool usage lives in tool descriptions, parameter schemas, and tool-specific guidelines. |
