| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,16 +16,20 @@ function debugLog(msg: string) { | |||
| 16 | 16 | } catch {} | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 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 { | ||
| 20 | 25 | try { | |
| 21 | 26 | 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 }; | ||
| 27 | 31 | } catch { | |
| 28 | - return null; | ||
| 32 | + return { sessionId: null, continueMode: false }; | ||
| 29 | 33 | } | |
| 30 | 34 | } | |
| 31 | 35 | ||
@@ -115,8 +119,8 @@ const plugin: Plugin = async (input: PluginInput): Promise<Hooks> => { | |||
| 115 | 119 | const pendingPermissions = new Set<string>(); | |
| 116 | 120 | const pendingQuestions = new Set<string>(); | |
| 117 | 121 | 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}`); | ||
| 120 | 124 | ||
| 121 | 125 | const upsertProcess = (updates: Partial<Omit<SessionRow, "pid">>) => { | |
| 122 | 126 | const now = Date.now(); | |
@@ -213,7 +217,6 @@ const plugin: Plugin = async (input: PluginInput): Promise<Hooks> => { | |||
| 213 | 217 | return; | |
| 214 | 218 | } | |
| 215 | 219 | ||
| 216 | - // Direct path: cmdline told us exactly which session | ||
| 217 | 220 | if (cmdlineSessionId) { | |
| 218 | 221 | const { data: session } = await input.client.session.get({ | |
| 219 | 222 | path: { id: cmdlineSessionId }, | |
@@ -232,7 +235,26 @@ const plugin: Plugin = async (input: PluginInput): Promise<Hooks> => { | |||
| 232 | 235 | debugLog(`adopt: cmdline session ${cmdlineSessionId} not found, falling back`); | |
| 233 | 236 | } | |
| 234 | 237 | ||
| 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 | + | ||
| 236 | 258 | const { data: statuses } = await input.client.session.status({ | |
| 237 | 259 | query: { directory: project.worktree }, | |
| 238 | 260 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments