chat: keep OpenCode session cwd consistent across turns + strengthen the override
msg.cwd only rides the first message, but OpenCode's system prompt is rebuilt every turn — so turn 2+ reverted to general_chat_sessions and the model fell back to the server's real cwd. Fix: the cwd is bound at creation (metadata.officer.cwd), so for an existing/resumed session read it back (new client.getSession) and reuse it for the system prompt every turn. Also make the prompt explicit that it overrides any other working directory the environment reports. Verified: a session created with a cwd reads the same cwd back on a later turn. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -146,6 +146,12 @@ class ServerConnection {
|
||||
return (await res.json()) as OpenCodeSessionInfo[];
|
||||
}
|
||||
|
||||
async getSession(sessionId: string): Promise<OpenCodeSessionInfo | null> {
|
||||
const res = await fetch(`${this.baseUrl}/session/${sessionId}`);
|
||||
if (!res.ok) return null;
|
||||
return (await res.json()) as OpenCodeSessionInfo;
|
||||
}
|
||||
|
||||
async getMessages(sessionId: string): Promise<OpenCodeStoredMessage[]> {
|
||||
const res = await fetch(`${this.baseUrl}/session/${sessionId}/message`);
|
||||
if (!res.ok) throw new Error(`opencode GET /session/${sessionId}/message → ${res.status}`);
|
||||
|
||||
Reference in New Issue
Block a user