| 153 | } |
| 154 | |
| 155 | async function resolveLatestSessionID(opencodeBin, project, preferredTitle) { |
| 156 | const result = await run(opencodeBin, ["session", "list", "--format", "json", "-n", "20"], project, { capture: true, timeoutMs: 15_000 }) |
| 157 | if (result.code !== 0 || result.timedOut) return undefined |
| 158 | let parsed |
| 159 | try { parsed = JSON.parse(result.stdout || "[]") } catch { return undefined } |
| 160 | const sessions = Array.isArray(parsed) ? parsed : Array.isArray(parsed?.data) ? parsed.data : [] |
| 161 | const match = preferredTitle ? sessions.find((item) => item?.title === preferredTitle) : sessions[0] |
| 162 | return typeof match?.id === "string" && match.id ? match.id : undefined |
| 163 | } |
| 164 | |
| 165 | function runSync(command, commandArgs) { |
| 166 | const options = { shell: false, stdio: "inherit", windowsHide: true } |