agentp 0.11.11 → 1.12.1

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/lib/ocmux.js CHANGED
@@ -233,13 +233,29 @@ function resurrectServer(dir, printLogs) {
233
233
  const actualName = windowNameByIndex(winIdx);
234
234
  if (actualName !== dir) {
235
235
  const found = windowByDir(dir);
236
- if (found != null) winIdx = found;
236
+ if (found == null) {
237
+ // No window exists for this directory — old server is already dead, skip kill
238
+ winIdx = null;
239
+ } else {
240
+ winIdx = found;
241
+ }
237
242
  }
238
243
  if (winIdx != null) {
239
244
  _tmux(['select-window', '-t', `${SESSION}:${winIdx}`]);
240
245
  _tmux(['send-keys', '-t', `${SESSION}:${winIdx}.0`, 'C-c']);
241
246
  sleep(0.3);
242
- _tmux(['kill-window', '-t', `${SESSION}:${winIdx}`]);
247
+ const killR = _tmux(['kill-window', '-t', `${SESSION}:${winIdx}`]);
248
+ if (killR.status !== 0) {
249
+ throw new Error(`Failed to kill old tmux window ${winIdx}: ${killR.stderr || 'unknown error'}`);
250
+ }
251
+ // Wait for window to actually disappear (up to 2s)
252
+ for (let i = 0; i < 10; i++) {
253
+ if (windowByDir(dir) == null) break;
254
+ sleep(0.2);
255
+ }
256
+ if (windowByDir(dir) != null) {
257
+ throw new Error(`Old tmux window for ${dir} still exists after kill`);
258
+ }
243
259
  }
244
260
  }
245
261
  }
@@ -260,11 +276,14 @@ function startServer(dir, printLogs) {
260
276
  ensureSession();
261
277
  const lf = logfileFor(dir);
262
278
 
263
- const rc = _tmux(['new-window', '-d', '-t', SESSION, '-n', dir, '-c', dir]);
264
- if (rc.status !== 0) throw new Error(`failed to create tmux window for ${dir}`);
265
-
266
- const winIdx = windowByDir(dir);
267
- if (winIdx == null) throw new Error('window was not created properly');
279
+ // Create a new tmux window and capture its index directly from the -P output
280
+ const newWinR = _tmux(['new-window', '-d', '-P', '-F', '#{window_index}', '-t', SESSION, '-n', dir, '-c', dir]);
281
+ if (newWinR.status !== 0) throw new Error(`failed to create tmux window for ${dir}`);
282
+ let winIdx = parseInt(newWinR.stdout.trim(), 10);
283
+ if (isNaN(winIdx)) {
284
+ winIdx = windowByDir(dir);
285
+ if (winIdx == null) throw new Error('could not determine new window index');
286
+ }
268
287
 
269
288
  pinWindowName(winIdx);
270
289
 
@@ -283,8 +302,7 @@ function startServer(dir, printLogs) {
283
302
  }
284
303
 
285
304
  if (!url) {
286
- const wi = windowByDir(dir);
287
- if (wi != null) _tmux(['kill-window', '-t', `${SESSION}:${wi}`]);
305
+ _tmux(['kill-window', '-t', `${SESSION}:${winIdx}`]);
288
306
  throw new Error('opencode server did not start within 10 seconds');
289
307
  }
290
308
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentp",
3
- "version": "0.11.11",
3
+ "version": "1.12.1",
4
4
  "description": "Pipe prompts into a running OpenCode TUI session and stream the final answer",
5
5
  "bin": {
6
6
  "agentp": "bin/agentp",