diff --git a/src/servers/channels/send-opencode.ts b/src/servers/channels/send-opencode.ts index b36b17a3..18bb6994 100644 --- a/src/servers/channels/send-opencode.ts +++ b/src/servers/channels/send-opencode.ts @@ -32,15 +32,19 @@ function splitModel(model: string): { providerID: string; modelID: string } { return { providerID: model.slice(0, slash), modelID: model.slice(slash + 1) }; } -// OpenCode can't set a real per-session cwd (every session runs in the fixed server's dir), so we tell -// the model its working directory via an appended, non-visible system prompt. Sent on every turn. +// OpenCode can't set a real per-session cwd (every session runs in the fixed server's dir) — and its +// tools follow that server cwd, so relative paths/bare globs resolve to the wrong place. We instruct +// the model, via an appended (non-visible) system prompt sent every turn, to target the intended dir +// explicitly with absolute paths on every tool call. function officerSystemPrompt(cwd: string): string { return [ - `Session working directory: ${cwd}`, + `Working directory for this session: ${cwd}`, '', - `For this session, treat \`${cwd}\` as your current working directory — this overrides any other working directory the environment reports. Resolve relative paths, globs, and file references against it, and run shell commands from inside it (\`cd\` into it, or use absolute paths beneath it). When the user says "here", "this directory", or gives a relative path, they mean a location within \`${cwd}\`.`, + `Your tools execute with a system working directory that is NOT \`${cwd}\`, so relative paths and bare globs (\`.\`, \`*\`, \`./x\`) resolve to the wrong place. To actually operate in \`${cwd}\`, target it explicitly on EVERY tool call:`, + `- File/search tools (read, write, edit, ls, glob, grep, …): always pass an ABSOLUTE path under \`${cwd}\` — e.g. \`${cwd}/notes/todo.md\`, or glob \`${cwd}/**/*\`. Never use a relative path or a bare \`.\`/\`*\`.`, + `- Shell/bash: start every command with \`cd ${cwd}\` (or use absolute paths beneath it).`, '', - `Unless the user explicitly directs you elsewhere, keep your work focused on \`${cwd}\`, its files, and its subdirectories.`, + `Interpret "here", "this directory", "the current folder", or any relative path the user gives as a location inside \`${cwd}\`. Keep all your work within \`${cwd}\` and its subdirectories unless the user explicitly directs you elsewhere.`, ].join('\n'); }