FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(plugin): handle opencode -c (continue) flag for session adoption · fetep/opencode-pulse@ff03f9a · GitHub

Commit ff03f9a

Browse files
committed
feat(plugin): handle opencode -c (continue) flag for session adoption
1 parent 8ce92c9 commit ff03f9a

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

‎plugin/src/index.ts‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ function debugLog(msg: string) {
1616
} catch {}
1717
}
1818

19-
function getSessionFromCmdline(): string | null {
19+
interface CmdlineFlags {
20+
sessionId: string | null; // from -s <id>
21+
continueMode: boolean; // from -c / --continue
22+
}
23+
24+
function parseCmdlineFlags(): CmdlineFlags {
2025
try {
2126
const args = readFileSync("/proc/self/cmdline", "utf-8").split("\0");
22-
const idx = args.indexOf("-s");
23-
if (idx !== -1 && idx + 1 < args.length && args[idx + 1]) {
24-
return args[idx + 1];
25-
}
26-
return null;
27+
const sIdx = args.indexOf("-s");
28+
const sessionId = (sIdx !== -1 && sIdx + 1 < args.length && args[sIdx + 1]) ? args[sIdx + 1] : null;
29+
const continueMode = args.includes("-c") || args.includes("--continue");
30+
return { sessionId, continueMode };
2731
} catch {
28-
return null;
32+
return { sessionId: null, continueMode: false };
2933
}
3034
}
3135

@@ -115,8 +119,8 @@ const plugin: Plugin = async (input: PluginInput): Promise<Hooks> => {
115119
const pendingPermissions = new Set<string>();
116120
const pendingQuestions = new Set<string>();
117121
let sessionFromEvent = false;
118-
const cmdlineSessionId = getSessionFromCmdline();
119-
debugLog(`startup: tmuxPane=${tmuxPane} dir=${project.worktree} cmdlineSession=${cmdlineSessionId}`);
122+
const { sessionId: cmdlineSessionId, continueMode } = parseCmdlineFlags();
123+
debugLog(`startup: tmuxPane=${tmuxPane} dir=${project.worktree} cmdlineSession=${cmdlineSessionId} continue=${continueMode}`);
120124

121125
const upsertProcess = (updates: Partial<Omit<SessionRow, "pid">>) => {
122126
const now = Date.now();
@@ -213,7 +217,6 @@ const plugin: Plugin = async (input: PluginInput): Promise<Hooks> => {
213217
return;
214218
}
215219

216-
// Direct path: cmdline told us exactly which session
217220
if (cmdlineSessionId) {
218221
const { data: session } = await input.client.session.get({
219222
path: { id: cmdlineSessionId },
@@ -232,7 +235,26 @@ const plugin: Plugin = async (input: PluginInput): Promise<Hooks> => {
232235
debugLog(`adopt: cmdline session ${cmdlineSessionId} not found, falling back`);
233236
}
234237

235-
// Fallback: discover active session by directory
238+
if (continueMode) {
239+
const { data: sessions } = await input.client.session.list({
240+
query: { directory: project.worktree },
241+
});
242+
if (sessions && sessions.length > 0) {
243+
const session = sessions[0];
244+
upsertProcess({
245+
session_id: session.id,
246+
project_id: session.projectID,
247+
directory: session.directory,
248+
title: session.title,
249+
opencode_version: session.version,
250+
});
251+
debugLog(`adopt: continue session id=${session.id} title="${session.title}"`);
252+
} else {
253+
debugLog("adopt: continue mode but no sessions found");
254+
}
255+
return;
256+
}
257+
236258
const { data: statuses } = await input.client.session.status({
237259
query: { directory: project.worktree },
238260
});

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL