Skip to content

Commit a02860f

Browse files
committed
fix: pass remote session ID to opencode attach for correct session selection
Store the session ID created on the remote server as remoteSessionID (separate from launchSessionID which tracks the caller's session) and pass it via --session flag when mc_attach opens the TUI.
1 parent 2f0a1f2 commit a02860f

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/lib/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const JobSchema = z.object({
1919
launchSessionID: z.string().optional(),
2020
port: z.number().optional(),
2121
serverUrl: z.string().optional(),
22+
remoteSessionID: z.string().optional(),
2223
});
2324

2425
export const JobStateSchema = z.object({

src/tools/attach.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const mc_attach: ToolDefinition = tool({
2222
if (isInsideTmux()) {
2323
// Create new tmux window with opencode attach command
2424
const windowName = `mc-${job.name}`;
25-
const attachCommand = `opencode attach ${job.serverUrl} --dir ${job.worktreePath}`;
25+
const sessionFlag = job.remoteSessionID ? ` --session ${job.remoteSessionID}` : '';
26+
const attachCommand = `opencode attach ${job.serverUrl} --dir ${job.worktreePath}${sessionFlag}`;
2627
const currentSession = getCurrentSession();
2728

2829
if (!currentSession) {

src/tools/launch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export const mc_launch: ToolDefinition = tool({
209209
const useServeMode = config.useServeMode === true;
210210
let allocatedPort: number | undefined;
211211
let serverUrl: string | undefined;
212+
let remoteSessionId: string | undefined;
212213

213214
if (useServeMode) {
214215
// === SERVE MODE ===
@@ -302,7 +303,7 @@ export const mc_launch: ToolDefinition = tool({
302303
autoCommit: config.autoCommit,
303304
});
304305
const modelInfo = getCurrentModelInfo(context?.sessionID);
305-
await createSessionAndPrompt(client, fullPrompt, undefined, modelInfo);
306+
remoteSessionId = await createSessionAndPrompt(client, fullPrompt, undefined, modelInfo);
306307
} catch (error) {
307308
await releasePort(allocatedPort).catch(() => {});
308309
try {
@@ -434,6 +435,7 @@ export const mc_launch: ToolDefinition = tool({
434435
launchSessionID: context?.sessionID,
435436
port: allocatedPort,
436437
serverUrl,
438+
remoteSessionID: remoteSessionId,
437439
};
438440

439441
await addJob(job);

0 commit comments

Comments
 (0)