opencode-agent-tmux 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/opencode-tmux.js +8 -55
- package/package.json +1 -1
|
@@ -172,53 +172,19 @@ function isForegroundProcess(pid) {
|
|
|
172
172
|
if (!stat) return false;
|
|
173
173
|
return stat.includes("+");
|
|
174
174
|
}
|
|
175
|
-
async function getOpencodeSessionCount(port) {
|
|
176
|
-
const controller = new AbortController();
|
|
177
|
-
const timeout = setTimeout(() => controller.abort(), HEALTH_TIMEOUT_MS);
|
|
178
|
-
const statusUrl = `http://127.0.0.1:${port}/session/status`;
|
|
179
|
-
try {
|
|
180
|
-
const response = await fetch(statusUrl, { signal: controller.signal }).catch(
|
|
181
|
-
() => null
|
|
182
|
-
);
|
|
183
|
-
if (!response?.ok) return null;
|
|
184
|
-
const payload = await response.json().catch(() => null);
|
|
185
|
-
if (!payload || typeof payload !== "object") return null;
|
|
186
|
-
const maybeData = payload.data;
|
|
187
|
-
if (maybeData && typeof maybeData === "object" && !Array.isArray(maybeData)) {
|
|
188
|
-
return Object.keys(maybeData).length;
|
|
189
|
-
}
|
|
190
|
-
if (!Array.isArray(payload)) {
|
|
191
|
-
return Object.keys(payload).length;
|
|
192
|
-
}
|
|
193
|
-
return payload.length;
|
|
194
|
-
} catch {
|
|
195
|
-
return null;
|
|
196
|
-
} finally {
|
|
197
|
-
clearTimeout(timeout);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
175
|
async function tryReclaimPort(port, tmuxPanePids) {
|
|
201
176
|
if (platform === "win32") return false;
|
|
202
177
|
const healthy = await isOpencodeHealthy(port);
|
|
178
|
+
if (healthy) return false;
|
|
203
179
|
const pids = getListeningPids(port);
|
|
204
|
-
const sessionCount = healthy ? await getOpencodeSessionCount(port) : null;
|
|
205
|
-
const idleServer = healthy && sessionCount === 0;
|
|
206
180
|
log(
|
|
207
181
|
"Port scan:",
|
|
208
182
|
port.toString(),
|
|
209
183
|
"healthy",
|
|
210
184
|
String(healthy),
|
|
211
|
-
"sessions",
|
|
212
|
-
sessionCount === null ? "unknown" : sessionCount.toString(),
|
|
213
|
-
"idle",
|
|
214
|
-
String(idleServer),
|
|
215
185
|
"pids",
|
|
216
186
|
pids.length > 0 ? pids.join(",") : "none"
|
|
217
187
|
);
|
|
218
|
-
if (healthy && sessionCount !== null && sessionCount > 0) {
|
|
219
|
-
log("Port in use by active server:", port.toString());
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
188
|
if (pids.length === 0) {
|
|
223
189
|
return false;
|
|
224
190
|
}
|
|
@@ -228,10 +194,6 @@ async function tryReclaimPort(port, tmuxPanePids) {
|
|
|
228
194
|
const tty = getProcessTty(pid);
|
|
229
195
|
const stat = getProcessStat(pid);
|
|
230
196
|
const hasTtyPeers = hasOtherTtyProcesses(tty, pid);
|
|
231
|
-
if (!command || !command.includes("opencode")) {
|
|
232
|
-
log("Port owned by non-opencode process, skipping:", port.toString());
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
197
|
const inTmux = tmuxPanePids.size > 0 && isDescendantOf(pid, tmuxPanePids);
|
|
236
198
|
log(
|
|
237
199
|
"Port process:",
|
|
@@ -246,12 +208,10 @@ async function tryReclaimPort(port, tmuxPanePids) {
|
|
|
246
208
|
String(inTmux),
|
|
247
209
|
"ttyPeers",
|
|
248
210
|
String(hasTtyPeers),
|
|
249
|
-
"idle",
|
|
250
|
-
String(idleServer),
|
|
251
211
|
"command",
|
|
252
|
-
command
|
|
212
|
+
command ?? "unknown"
|
|
253
213
|
);
|
|
254
|
-
if (
|
|
214
|
+
if (command && command.includes("opencode")) {
|
|
255
215
|
if (inTmux) {
|
|
256
216
|
log("Port owned by tmux process, skipping:", port.toString(), pid.toString());
|
|
257
217
|
continue;
|
|
@@ -260,20 +220,12 @@ async function tryReclaimPort(port, tmuxPanePids) {
|
|
|
260
220
|
log("Port owned by active tty process, skipping:", port.toString(), pid.toString());
|
|
261
221
|
continue;
|
|
262
222
|
}
|
|
263
|
-
if (
|
|
264
|
-
log("
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
if (healthy && sessionCount !== null && sessionCount > 0) {
|
|
268
|
-
log("Port has active sessions, skipping:", port.toString(), pid.toString());
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
if (!healthy && !isForegroundProcess(pid)) {
|
|
272
|
-
log("Port owned by background opencode process, skipping:", port.toString(), pid.toString());
|
|
223
|
+
if (isForegroundProcess(pid)) {
|
|
224
|
+
log("Port owned by potentially busy foreground process, skipping:", port.toString(), pid.toString());
|
|
273
225
|
continue;
|
|
274
226
|
}
|
|
275
227
|
}
|
|
276
|
-
log("Attempting to stop stale opencode process:", port.toString(), pid.toString());
|
|
228
|
+
log("Attempting to stop stale or non-opencode process:", port.toString(), pid.toString());
|
|
277
229
|
attemptedKill = true;
|
|
278
230
|
try {
|
|
279
231
|
process.kill(pid, "SIGTERM");
|
|
@@ -326,7 +278,8 @@ async function main() {
|
|
|
326
278
|
exit(1);
|
|
327
279
|
}
|
|
328
280
|
const bypassArgs = [...args];
|
|
329
|
-
|
|
281
|
+
const hasPrintLogs = args.includes("--print-logs");
|
|
282
|
+
if (!hasPrintLogs && !args.some((arg) => arg.startsWith("--log-level"))) {
|
|
330
283
|
bypassArgs.push("--log-level", "ERROR");
|
|
331
284
|
}
|
|
332
285
|
const child = spawn(opencodeBin2, bypassArgs, {
|