Revert "chat: root the OpenCode server at the chat cwd (email chat now runs in the account dir)"

This reverts commit d60c73b3a3.
This commit is contained in:
2026-07-25 10:08:48 +00:00
parent 9b9938aaa9
commit bab0d1b7f8
3 changed files with 18 additions and 124 deletions
+3 -7
View File
@@ -4,7 +4,6 @@ import { ensureServer } from '@@/api/chat/opencode/server-manager';
import { getConnection } from '@@/api/chat/opencode/client';
import { createEventMapper } from '@@/api/chat/opencode/event-mapper';
import { getOpenCodeSession, setOpenCodeSession } from '@@/api/chat/opencode/state';
import { getHomeDirForRole } from '../data-path';
// The OpenCode analog of send-claude-code.ts's streaming path. Drives a turn against a warm
// `opencode serve` over HTTP + SSE, mapping events to the shared ChatEvent contract.
@@ -34,11 +33,9 @@ function splitModel(model: string): { providerID: string; modelID: string } {
}
export async function sendOpenCodeStreaming(params: OpenCodeStreamingParams): Promise<OpenCodeStreamingHandle> {
logger.info('OpenCode streaming exec', { sessionKey: params.sessionKey, model: params.model, cwd: params.cwd });
logger.info('OpenCode streaming exec', { sessionKey: params.sessionKey, model: params.model });
// params.cwd set (email/project) → a server rooted there; unset (/chat) → the fixed pm2 server.
const home = getHomeDirForRole(params.email, params.role ?? '');
const { baseUrl } = await ensureServer(params.cwd, home);
const { baseUrl } = await ensureServer();
const conn = getConnection(baseUrl);
// Resolve the OpenCode session: a known mapping, or — when resuming from history — the sessionKey is
@@ -48,8 +45,7 @@ export async function sendOpenCodeStreaming(params: OpenCodeStreamingParams): Pr
(params.sessionKey.startsWith('ses_') ? params.sessionKey : undefined) ??
params.resumeSessionId;
if (!opencodeSessionId) {
// The working dir comes from the server (rooted at cwd above), not a per-session param.
opencodeSessionId = await conn.createSession();
opencodeSessionId = await conn.createSession(params.cwd);
}
setOpenCodeSession(params.sessionKey, opencodeSessionId);
const sessionId = opencodeSessionId;