polyergon 0.1.0 → 0.1.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.
Files changed (82) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-build-manifest.json +4 -4
  3. package/.next/app-path-routes-manifest.json +1 -1
  4. package/.next/build-manifest.json +4 -4
  5. package/.next/next-minimal-server.js.nft.json +1 -1
  6. package/.next/next-server.js.nft.json +1 -1
  7. package/.next/prerender-manifest.json +1 -1
  8. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  9. package/.next/server/app/_not-found.html +1 -1
  10. package/.next/server/app/_not-found.rsc +1 -1
  11. package/.next/server/app/api/automations/existing/route.js +1 -1
  12. package/.next/server/app/api/backends/route.js +1 -1
  13. package/.next/server/app/api/diff/route.js +1 -0
  14. package/.next/server/app/api/diff/route.js.nft.json +1 -0
  15. package/.next/server/app/api/limits/route.js +1 -1
  16. package/.next/server/app/api/models/route.js +1 -1
  17. package/.next/server/app/api/orgs/[id]/route.js +1 -1
  18. package/.next/server/app/api/orgs/route.js +1 -1
  19. package/.next/server/app/api/prs/inbox/route.js +1 -1
  20. package/.next/server/app/api/prs/inbox/route.js.nft.json +1 -1
  21. package/.next/server/app/api/prs/refresh/route.js +1 -1
  22. package/.next/server/app/api/prs/refresh/route.js.nft.json +1 -1
  23. package/.next/server/app/api/prs/route.js +1 -1
  24. package/.next/server/app/api/prs/route.js.nft.json +1 -1
  25. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  26. package/.next/server/app/api/sessions/route.js +1 -1
  27. package/.next/server/app/api/settings/auth/route.js +1 -1
  28. package/.next/server/app/api/skills/[name]/route.js +1 -1
  29. package/.next/server/app/api/skills/marketplace/route.js +1 -1
  30. package/.next/server/app/api/skills/route.js +1 -1
  31. package/.next/server/app/api/skills/view/route.js +1 -1
  32. package/.next/server/app/api/slack/channels/route.js +1 -1
  33. package/.next/server/app/api/slack/configured/route.js +1 -1
  34. package/.next/server/app/api/slack/inbox/route.js +1 -1
  35. package/.next/server/app/api/tasks/route.js +1 -0
  36. package/.next/server/app/api/tasks/route.js.nft.json +1 -0
  37. package/.next/server/app/api/usage/route.js +1 -1
  38. package/.next/server/app/demo/page_client-reference-manifest.js +1 -1
  39. package/.next/server/app/demo.html +1 -1
  40. package/.next/server/app/demo.rsc +2 -2
  41. package/.next/server/app/favicon.ico/route.js +1 -1
  42. package/.next/server/app/index.html +1 -1
  43. package/.next/server/app/index.rsc +2 -2
  44. package/.next/server/app/page.js +10 -1
  45. package/.next/server/app/page_client-reference-manifest.js +1 -1
  46. package/.next/server/app-paths-manifest.json +18 -16
  47. package/.next/server/chunks/36.js +1 -0
  48. package/.next/server/chunks/590.js +1 -1
  49. package/.next/server/chunks/621.js +1 -1
  50. package/.next/server/chunks/904.js +1 -1
  51. package/.next/server/chunks/972.js +2 -2
  52. package/.next/server/functions-config-manifest.json +1 -1
  53. package/.next/server/middleware-build-manifest.js +1 -1
  54. package/.next/server/pages/404.html +1 -1
  55. package/.next/server/pages/500.html +1 -1
  56. package/.next/server/server-reference-manifest.json +1 -1
  57. package/.next/static/chunks/171-d325f9625379d70a.js +1 -0
  58. package/.next/static/chunks/app/page-fedaef1e63f186c2.js +1 -0
  59. package/.next/static/chunks/{main-960df1c7509a5a8b.js → main-e88dbd51c3bdafca.js} +1 -1
  60. package/.next/static/css/6e83ef44d507c857.css +3 -0
  61. package/.next/trace +23 -22
  62. package/.next/types/app/api/diff/route.ts +343 -0
  63. package/.next/types/app/api/tasks/route.ts +343 -0
  64. package/.server-dist/server.js +73 -27
  65. package/.server-dist/src/lib/backends.js +99 -1
  66. package/.server-dist/src/lib/diffReview.js +116 -0
  67. package/.server-dist/src/lib/liveSessionStore.js +1 -1
  68. package/.server-dist/src/lib/modelCatalog.js +10 -3
  69. package/.server-dist/src/lib/pipelines.js +34 -8
  70. package/.server-dist/src/lib/ptyManager.js +15 -6
  71. package/.server-dist/src/lib/statusDetector.js +4 -0
  72. package/.server-dist/src/lib/taskStore.js +42 -0
  73. package/.server-dist/src/lib/worktrees.js +42 -0
  74. package/.server-dist/tsconfig.server.tsbuildinfo +1 -1
  75. package/README.md +16 -4
  76. package/package.json +1 -1
  77. package/.next/server/chunks/348.js +0 -1
  78. package/.next/static/chunks/171-f72ed164561ba218.js +0 -1
  79. package/.next/static/chunks/app/page-cebeba7d6d08548a.js +0 -1
  80. package/.next/static/css/a537d3e86c0f36d2.css +0 -3
  81. /package/.next/static/{q-HMeHYZY36qljBJhsyS6 → 2gHioRND6aAzT4OB5OHDV}/_buildManifest.js +0 -0
  82. /package/.next/static/{q-HMeHYZY36qljBJhsyS6 → 2gHioRND6aAzT4OB5OHDV}/_ssgManifest.js +0 -0
@@ -53,6 +53,14 @@ const backends_1 = require("./src/lib/backends");
53
53
  const meetingManager_1 = require("./src/lib/meetingManager");
54
54
  const pipelines_1 = require("./src/lib/pipelines");
55
55
  const keepAwake_1 = require("./src/lib/keepAwake");
56
+ const worktrees_1 = require("./src/lib/worktrees");
57
+ const taskStore_1 = require("./src/lib/taskStore");
58
+ // What the browser sees of a live session
59
+ const sessionView = (s) => {
60
+ var _a, _b, _c;
61
+ return ({ id: s.id, cwd: s.cwd, gitRoot: (_a = s.gitRoot) !== null && _a !== void 0 ? _a : (0, gitUtils_1.getGitRoot)(s.cwd), // restored sessions may lack it (cached lookup)
62
+ status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_b = s.rcUrl) !== null && _b !== void 0 ? _b : null, rc: !!s.rc, orgId: s.orgId, backend: (_c = s.backend) !== null && _c !== void 0 ? _c : 'claude', worktree: s.worktree ? { branch: s.worktree.branch, repo: s.worktree.repo } : null });
63
+ };
56
64
  const slackWatchers_1 = require("./src/lib/slackWatchers");
57
65
  const meetingStore_1 = require("./src/lib/meetingStore");
58
66
  const sessionNameStore_1 = require("./src/lib/sessionNameStore");
@@ -225,16 +233,16 @@ app.prepare().then(async () => {
225
233
  cleanupStatus = (0, ptyManager_1.onStatusChange)(sessionId, (status) => send({ type: 'status', status }));
226
234
  }
227
235
  ws.on('message', (raw) => {
228
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
236
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
229
237
  let msg;
230
238
  try {
231
239
  msg = JSON.parse(raw.toString());
232
240
  }
233
- catch (_z) {
241
+ catch (_2) {
234
242
  return;
235
243
  }
236
244
  if (msg.type === 'list') {
237
- send({ type: 'sessions', sessions: liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); }) });
245
+ send({ type: 'sessions', sessions: liveSessionStore_1.liveSessionStore.list().map(sessionView) });
238
246
  }
239
247
  else if (msg.type === 'create') {
240
248
  let cwd = msg.cwd || process.env.HOME;
@@ -246,6 +254,18 @@ app.prepare().then(async () => {
246
254
  send({ type: 'error', message: `Directory not found: ${cwd}` });
247
255
  return;
248
256
  }
257
+ // Isolated copy: new branch + worktree folder for this session
258
+ let worktree;
259
+ if (msg.worktree === true) {
260
+ try {
261
+ worktree = (0, worktrees_1.createWorktree)(cwd, msg.name || path_1.default.basename(cwd));
262
+ cwd = worktree.path;
263
+ }
264
+ catch (e) {
265
+ send({ type: 'error', message: /not a git repository/i.test(String((_a = e.stderr) !== null && _a !== void 0 ? _a : e)) ? 'That folder is not a git repository, so it can\'t get its own worktree.' : `Could not create a worktree: ${e.message}` });
266
+ return;
267
+ }
268
+ }
249
269
  const orgId = msg.orgId || orgRegistry_1.DEFAULT_ORG_ID;
250
270
  const org = orgRegistry_1.orgRegistry.get(orgId);
251
271
  const id = (0, uuid_1.v4)();
@@ -258,8 +278,16 @@ app.prepare().then(async () => {
258
278
  const backend = msg.backend || backends_1.DEFAULT_BACKEND;
259
279
  const model = msg.model || (org === null || org === void 0 ? void 0 : org.model) || null;
260
280
  const rc = !!msg.rc;
261
- liveSessionStore_1.liveSessionStore.add({ id, cwd, gitRoot, claudeSessionId: null, status: 'thinking', createdAt: Date.now(), prUrl: null, orgId, backend, model, rc });
262
- (0, ptyManager_1.spawnSession)(id, cwd, undefined, (_a = org === null || org === void 0 ? void 0 : org.configDir) !== null && _a !== void 0 ? _a : null, model, rcName, backend, rc);
281
+ liveSessionStore_1.liveSessionStore.add({ id, cwd, gitRoot, claudeSessionId: null, status: 'thinking', createdAt: Date.now(), prUrl: null, orgId, backend, model, rc, worktree });
282
+ (0, ptyManager_1.spawnSession)(id, cwd, undefined, (_b = org === null || org === void 0 ? void 0 : org.configDir) !== null && _b !== void 0 ? _b : null, model, rcName, backend, rc);
283
+ if (typeof msg.taskId === 'string') {
284
+ // Board: link the session; a repo task with "ship" gets a Ship it pipeline right away.
285
+ // Opening the PR waits for you ("Your review" column); fixes run on their own; merge asks.
286
+ const task = (0, taskStore_1.updateTask)(msg.taskId, { liveId: id });
287
+ if ((task === null || task === void 0 ? void 0 : task.ship) && gitRoot && backend === 'claude') {
288
+ pipelines_1.pipelineEngine.create(id, { slackChannel: (_c = task.slackChannel) !== null && _c !== void 0 ? _c : null, maxRounds: 3, auto: { openPr: false, review: true, ci: true, merge: false } });
289
+ }
290
+ }
263
291
  send({ type: 'created', id, cwd, gitRoot, orgId });
264
292
  attachToSession(id);
265
293
  // First prompt (e.g. "cr <url>", "/mcp"): sent only once Claude is at its input prompt
@@ -285,7 +313,7 @@ app.prepare().then(async () => {
285
313
  (0, ptyManager_1.killSession)(existing.id);
286
314
  liveSessionStore_1.liveSessionStore.setStatus(existing.id, 'idle');
287
315
  }
288
- if (((_b = liveSessionStore_1.liveSessionStore.get(existing.id)) === null || _b === void 0 ? void 0 : _b.status) === 'idle') {
316
+ if (((_d = liveSessionStore_1.liveSessionStore.get(existing.id)) === null || _d === void 0 ? void 0 : _d.status) === 'idle') {
289
317
  // PTY exited — re-spawn it on the same store entry. Always uses the
290
318
  // session's OWN stored org, never whatever orgId the client sent —
291
319
  // a resume must never silently move a session to a different org.
@@ -300,7 +328,7 @@ app.prepare().then(async () => {
300
328
  existing.model = model;
301
329
  liveSessionStore_1.liveSessionStore.add(existing);
302
330
  }
303
- (0, ptyManager_1.spawnSession)(existing.id, existing.cwd, rawSessionId, (_c = org === null || org === void 0 ? void 0 : org.configDir) !== null && _c !== void 0 ? _c : null, model, rcNameFor(existing, msg.name), existing.backend, existing.rc);
331
+ (0, ptyManager_1.spawnSession)(existing.id, existing.cwd, rawSessionId, (_e = org === null || org === void 0 ? void 0 : org.configDir) !== null && _e !== void 0 ? _e : null, model, rcNameFor(existing, msg.name), existing.backend, existing.rc);
304
332
  }
305
333
  send({ type: 'attached', id: existing.id, cwd: existing.cwd });
306
334
  attachToSession(existing.id);
@@ -314,7 +342,7 @@ app.prepare().then(async () => {
314
342
  const backend = msg.backend || backends_1.DEFAULT_BACKEND;
315
343
  const model = msg.model || (org === null || org === void 0 ? void 0 : org.model) || null;
316
344
  liveSessionStore_1.liveSessionStore.add({ id, cwd, gitRoot, claudeSessionId: rawSessionId, status: 'thinking', createdAt: Date.now(), prUrl: null, orgId, backend, model, rc: !!msg.rc });
317
- (0, ptyManager_1.spawnSession)(id, cwd, rawSessionId, (_d = org === null || org === void 0 ? void 0 : org.configDir) !== null && _d !== void 0 ? _d : null, model, rcNameFor({ id, cwd, claudeSessionId: rawSessionId, orgId }, msg.name), backend, !!msg.rc);
345
+ (0, ptyManager_1.spawnSession)(id, cwd, rawSessionId, (_f = org === null || org === void 0 ? void 0 : org.configDir) !== null && _f !== void 0 ? _f : null, model, rcNameFor({ id, cwd, claudeSessionId: rawSessionId, orgId }, msg.name), backend, !!msg.rc);
318
346
  send({ type: 'created', id, cwd, gitRoot, claudeSessionId: rawSessionId, orgId });
319
347
  attachToSession(id);
320
348
  }
@@ -333,7 +361,7 @@ app.prepare().then(async () => {
333
361
  (0, ptyManager_1.spawnSession)(s.id, s.cwd, s.claudeSessionId, (_b = org === null || org === void 0 ? void 0 : org.configDir) !== null && _b !== void 0 ? _b : null, (_c = s.model) !== null && _c !== void 0 ? _c : org === null || org === void 0 ? void 0 : org.model, rcNameFor(s), s.backend, s.rc);
334
362
  await new Promise(r => setTimeout(r, 300));
335
363
  }
336
- const updated = liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); });
364
+ const updated = liveSessionStore_1.liveSessionStore.list().map(sessionView);
337
365
  wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
338
366
  c.send(JSON.stringify({ type: 'sessions', sessions: updated })); });
339
367
  })();
@@ -351,7 +379,7 @@ app.prepare().then(async () => {
351
379
  (0, ptyManager_1.killSession)(target.id);
352
380
  const org = orgRegistry_1.orgRegistry.get(target.orgId);
353
381
  liveSessionStore_1.liveSessionStore.setStatus(target.id, 'thinking');
354
- (0, ptyManager_1.spawnSession)(target.id, target.cwd, target.claudeSessionId, (_e = org === null || org === void 0 ? void 0 : org.configDir) !== null && _e !== void 0 ? _e : null, (_f = target.model) !== null && _f !== void 0 ? _f : org === null || org === void 0 ? void 0 : org.model, rcNameFor(target), target.backend, target.rc);
382
+ (0, ptyManager_1.spawnSession)(target.id, target.cwd, target.claudeSessionId, (_g = org === null || org === void 0 ? void 0 : org.configDir) !== null && _g !== void 0 ? _g : null, (_h = target.model) !== null && _h !== void 0 ? _h : org === null || org === void 0 ? void 0 : org.model, rcNameFor(target), target.backend, target.rc);
355
383
  }
356
384
  }
357
385
  else if (msg.type === 'set-rc') {
@@ -365,9 +393,9 @@ app.prepare().then(async () => {
365
393
  (0, ptyManager_1.killSession)(target.id);
366
394
  const org = orgRegistry_1.orgRegistry.get(target.orgId);
367
395
  liveSessionStore_1.liveSessionStore.setStatus(target.id, 'thinking');
368
- (0, ptyManager_1.spawnSession)(target.id, target.cwd, target.claudeSessionId, (_g = org === null || org === void 0 ? void 0 : org.configDir) !== null && _g !== void 0 ? _g : null, (_h = target.model) !== null && _h !== void 0 ? _h : org === null || org === void 0 ? void 0 : org.model, rcNameFor(target), target.backend, target.rc);
396
+ (0, ptyManager_1.spawnSession)(target.id, target.cwd, target.claudeSessionId, (_j = org === null || org === void 0 ? void 0 : org.configDir) !== null && _j !== void 0 ? _j : null, (_k = target.model) !== null && _k !== void 0 ? _k : org === null || org === void 0 ? void 0 : org.model, rcNameFor(target), target.backend, target.rc);
369
397
  }
370
- const updated = liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); });
398
+ const updated = liveSessionStore_1.liveSessionStore.list().map(sessionView);
371
399
  wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
372
400
  c.send(JSON.stringify({ type: 'sessions', sessions: updated })); });
373
401
  }
@@ -390,7 +418,25 @@ app.prepare().then(async () => {
390
418
  const targetId = msg.sessionId;
391
419
  (0, ptyManager_1.killSession)(targetId);
392
420
  liveSessionStore_1.liveSessionStore.remove(targetId);
393
- const updated = liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); });
421
+ const updated = liveSessionStore_1.liveSessionStore.list().map(sessionView);
422
+ wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
423
+ c.send(JSON.stringify({ type: 'sessions', sessions: updated })); });
424
+ }
425
+ else if (msg.type === 'worktree-remove') {
426
+ // Stops the session, deletes its worktree folder (branch kept). Conversation stays in History.
427
+ const target = liveSessionStore_1.liveSessionStore.get(msg.sessionId);
428
+ if (!(target === null || target === void 0 ? void 0 : target.worktree))
429
+ return;
430
+ (0, ptyManager_1.killSession)(target.id);
431
+ try {
432
+ (0, worktrees_1.removeWorktree)(target.worktree);
433
+ }
434
+ catch (e) {
435
+ send({ type: 'error', message: e.message });
436
+ return;
437
+ }
438
+ liveSessionStore_1.liveSessionStore.remove(target.id);
439
+ const updated = liveSessionStore_1.liveSessionStore.list().map(sessionView);
394
440
  wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
395
441
  c.send(JSON.stringify({ type: 'sessions', sessions: updated })); });
396
442
  }
@@ -406,7 +452,7 @@ app.prepare().then(async () => {
406
452
  send({ type: 'image-pasted', path: tmpPath });
407
453
  }
408
454
  else if (msg.type === 'meeting-start') {
409
- const result = meetingManager_1.meetingManager.start((_j = msg.title) !== null && _j !== void 0 ? _j : '', (_k = msg.orgId) !== null && _k !== void 0 ? _k : orgRegistry_1.DEFAULT_ORG_ID);
455
+ const result = meetingManager_1.meetingManager.start((_l = msg.title) !== null && _l !== void 0 ? _l : '', (_m = msg.orgId) !== null && _m !== void 0 ? _m : orgRegistry_1.DEFAULT_ORG_ID);
410
456
  if ('error' in result)
411
457
  send({ type: 'meeting-error', meetingId: null, message: result.error });
412
458
  else
@@ -415,30 +461,30 @@ app.prepare().then(async () => {
415
461
  else if (msg.type === 'rename-live') {
416
462
  // Rename the running Claude conversation too, so Remote Control and
417
463
  // claude.ai show the title. Sent now if the prompt is idle, else on next idle.
418
- const name = String((_l = msg.name) !== null && _l !== void 0 ? _l : '').replace(/[\x00-\x1f\x7f]/g, ' ').trim().slice(0, 80);
464
+ const name = String((_o = msg.name) !== null && _o !== void 0 ? _o : '').replace(/[\x00-\x1f\x7f]/g, ' ').trim().slice(0, 80);
419
465
  const target = liveSessionStore_1.liveSessionStore.get(msg.id);
420
- if (name && target && target.backend !== 'copilot') {
466
+ if (name && target && ((_p = target.backend) !== null && _p !== void 0 ? _p : 'claude') === 'claude') { // /rename is Claude-only
421
467
  pendingRenames.set(target.id, name);
422
468
  if (target.status === 'waiting')
423
469
  flushRename(target.id);
424
470
  }
425
471
  }
426
472
  else if (msg.type === 'pipeline-start') {
427
- const cfg = ((_m = msg.config) !== null && _m !== void 0 ? _m : {});
428
- const ch = ((_o = cfg.slackChannel) === null || _o === void 0 ? void 0 : _o.name) ? { id: String((_p = cfg.slackChannel.id) !== null && _p !== void 0 ? _p : '').replace(/[^A-Z0-9]/gi, ''), name: cfg.slackChannel.name.replace(/^#/, '').slice(0, 80) } : null;
429
- const result = pipelines_1.pipelineEngine.create(msg.liveId, { slackChannel: ch, maxRounds: Number(cfg.maxRounds) || 3 });
473
+ const cfg = ((_q = msg.config) !== null && _q !== void 0 ? _q : {});
474
+ const ch = ((_r = cfg.slackChannel) === null || _r === void 0 ? void 0 : _r.name) ? { id: String((_s = cfg.slackChannel.id) !== null && _s !== void 0 ? _s : '').replace(/[^A-Z0-9]/gi, ''), name: cfg.slackChannel.name.replace(/^#/, '').slice(0, 80) } : null;
475
+ const result = pipelines_1.pipelineEngine.create(msg.liveId, { slackChannel: ch, maxRounds: Number(cfg.maxRounds) || 3, auto: cfg.auto });
430
476
  if ('error' in result)
431
477
  send({ type: 'pipeline-error', liveId: msg.liveId, message: result.error });
432
478
  }
433
479
  else if (msg.type === 'pipeline-add-pr') {
434
- const err = pipelines_1.pipelineEngine.addPr(msg.id, String((_q = msg.url) !== null && _q !== void 0 ? _q : '').trim());
480
+ const err = pipelines_1.pipelineEngine.addPr(msg.id, String((_t = msg.url) !== null && _t !== void 0 ? _t : '').trim());
435
481
  if (err)
436
482
  send({ type: 'pipeline-error', liveId: msg.liveId, message: err.error });
437
483
  }
438
484
  else if (msg.type === 'watcher-create') {
439
- const c = ((_r = msg.channel) !== null && _r !== void 0 ? _r : {});
485
+ const c = ((_u = msg.channel) !== null && _u !== void 0 ? _u : {});
440
486
  const result = slackWatchers_1.slackWatchers.create({
441
- channel: { id: String((_s = c.id) !== null && _s !== void 0 ? _s : '').replace(/[^A-Z0-9]/gi, ''), name: String((_t = c.name) !== null && _t !== void 0 ? _t : '').replace(/^#/, '').slice(0, 80) },
487
+ channel: { id: String((_v = c.id) !== null && _v !== void 0 ? _v : '').replace(/[^A-Z0-9]/gi, ''), name: String((_w = c.name) !== null && _w !== void 0 ? _w : '').replace(/^#/, '').slice(0, 80) },
442
488
  liveId: msg.liveId || null, mode: msg.mode === 'auto' ? 'auto' : 'approve', intervalMin: Number(msg.intervalMin) || 5,
443
489
  orgId: typeof msg.orgId === 'string' && orgRegistry_1.orgRegistry.get(msg.orgId) ? msg.orgId : orgRegistry_1.DEFAULT_ORG_ID,
444
490
  knowledge: typeof msg.knowledge === 'string' ? msg.knowledge : '', instructions: typeof msg.instructions === 'string' ? msg.instructions : '',
@@ -452,7 +498,7 @@ app.prepare().then(async () => {
452
498
  slackWatchers_1.slackWatchers.stop(msg.id);
453
499
  }
454
500
  else if (msg.type === 'watcher-update') {
455
- const err = slackWatchers_1.slackWatchers.update(msg.id, ((_u = msg.patch) !== null && _u !== void 0 ? _u : {}));
501
+ const err = slackWatchers_1.slackWatchers.update(msg.id, ((_x = msg.patch) !== null && _x !== void 0 ? _x : {}));
456
502
  if (err)
457
503
  send({ type: 'watcher-error', message: err.error });
458
504
  }
@@ -463,7 +509,7 @@ app.prepare().then(async () => {
463
509
  slackWatchers_1.slackWatchers.run(msg.id);
464
510
  }
465
511
  else if (msg.type === 'watcher-send') {
466
- slackWatchers_1.slackWatchers.send(msg.id, msg.permalink, String((_v = msg.text) !== null && _v !== void 0 ? _v : '')).then(err => { if (err)
512
+ slackWatchers_1.slackWatchers.send(msg.id, msg.permalink, String((_y = msg.text) !== null && _y !== void 0 ? _y : '')).then(err => { if (err)
467
513
  send({ type: 'watcher-error', message: err.error }); });
468
514
  }
469
515
  else if (msg.type === 'watcher-dismiss') {
@@ -479,7 +525,7 @@ app.prepare().then(async () => {
479
525
  send({ type: 'pipeline-error', liveId: msg.liveId, message: err.error });
480
526
  }
481
527
  else if (msg.type === 'pipeline-auto') {
482
- pipelines_1.pipelineEngine.setAuto(msg.id, ((_w = msg.auto) !== null && _w !== void 0 ? _w : {}));
528
+ pipelines_1.pipelineEngine.setAuto(msg.id, ((_z = msg.auto) !== null && _z !== void 0 ? _z : {}));
483
529
  }
484
530
  else if (msg.type === 'pipeline-dismiss') {
485
531
  pipelines_1.pipelineEngine.dismiss(msg.id, msg.prUrl || null);
@@ -490,7 +536,7 @@ app.prepare().then(async () => {
490
536
  else if (msg.type === 'meeting-resume') {
491
537
  const result = meetingManager_1.meetingManager.resume(msg.meetingId);
492
538
  if ('error' in result)
493
- send({ type: 'meeting-error', meetingId: (_x = msg.meetingId) !== null && _x !== void 0 ? _x : null, message: result.error });
539
+ send({ type: 'meeting-error', meetingId: (_0 = msg.meetingId) !== null && _0 !== void 0 ? _0 : null, message: result.error });
494
540
  else
495
541
  send({ type: 'meeting-started', meeting: result });
496
542
  }
@@ -516,7 +562,7 @@ app.prepare().then(async () => {
516
562
  }
517
563
  else if (msg.type === 'send-to-live') {
518
564
  // User clicked "Ask session" on a Slack card: queue the text for when the session is idle
519
- const text = String((_y = msg.text) !== null && _y !== void 0 ? _y : '').replace(/[\x00-\x08\x0b-\x1f\x7f]/g, ' ').trim().slice(0, 20000);
565
+ const text = String((_1 = msg.text) !== null && _1 !== void 0 ? _1 : '').replace(/[\x00-\x08\x0b-\x1f\x7f]/g, ' ').trim().slice(0, 20000);
520
566
  if (text && liveSessionStore_1.liveSessionStore.get(msg.id))
521
567
  (0, ptyManager_1.sendWhenReady)(msg.id, text);
522
568
  }
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_BACKEND = exports.BACKENDS = void 0;
3
+ exports.DEFAULT_BACKEND = exports.BACKENDS = exports.DEFAULT_MODEL_ID = void 0;
4
4
  exports.getBackend = getBackend;
5
5
  exports.availableBackends = availableBackends;
6
6
  const child_process_1 = require("child_process");
7
7
  const path_1 = require("path");
8
+ const fs_1 = require("fs");
9
+ // 'default' = let the CLI use its own configured model (no --model flag)
10
+ exports.DEFAULT_MODEL_ID = 'default';
11
+ const modelArgs = (flag, model) => (model && model !== exports.DEFAULT_MODEL_ID ? [flag, model] : []);
8
12
  const CLAUDE = {
9
13
  id: 'claude',
10
14
  label: 'Claude',
@@ -77,9 +81,103 @@ const COPILOT = {
77
81
  ],
78
82
  env: () => ({}),
79
83
  };
84
+ const realpath = (p) => { try {
85
+ return (0, child_process_1.execFileSync)('/usr/bin/readlink', ['-f', p], { timeout: 2000 }).toString().trim() || p;
86
+ }
87
+ catch (_a) {
88
+ return p;
89
+ } };
90
+ // OpenCode (sst/opencode). TUI; sessions live in ~/.local/share/opencode/opencode.db.
91
+ // Footer shows "esc interrupt" while working. --auto = approve permissions.
92
+ const OPENCODE = {
93
+ id: 'opencode',
94
+ label: 'OpenCode',
95
+ bin: 'opencode',
96
+ spawnArgs: ({ model, cwd, resumeId, skipPermissions }) => [
97
+ cwd,
98
+ ...modelArgs('-m', model),
99
+ ...(skipPermissions ? ['--auto'] : []),
100
+ ...(resumeId ? ['-s', resumeId] : []),
101
+ ],
102
+ env: () => ({}),
103
+ detectSessionId: (cwd, sinceMs) => {
104
+ const db = (0, path_1.join)(process.env.HOME, '.local', 'share', 'opencode', 'opencode.db');
105
+ const q = (s) => `'${s.replace(/'/g, "''")}'`;
106
+ try {
107
+ const out = (0, child_process_1.execFileSync)('sqlite3', [db, `SELECT id FROM session WHERE parent_id IS NULL AND directory IN (${q(cwd)},${q(realpath(cwd))}) AND time_created >= ${sinceMs - 1000} ORDER BY time_created DESC LIMIT 1;`], { timeout: 3000 }).toString().trim();
108
+ return out || null;
109
+ }
110
+ catch (_a) {
111
+ return null;
112
+ }
113
+ },
114
+ };
115
+ // OpenAI Codex CLI. Resume is a subcommand; sessions are JSONL files under
116
+ // ~/.codex/sessions/YYYY/MM/DD whose first line holds {payload: {id, cwd}}.
117
+ function findCodexSessionIdSince(cwd, sinceMs) {
118
+ var _a, _b;
119
+ const root = (0, path_1.join)(process.env.HOME, '.codex', 'sessions');
120
+ const real = realpath(cwd);
121
+ const d = new Date(sinceMs);
122
+ const dirs = [0, 1].map(off => { const x = new Date(d.getTime() + off * 86400000); return (0, path_1.join)(root, String(x.getFullYear()), String(x.getMonth() + 1).padStart(2, '0'), String(x.getDate()).padStart(2, '0')); });
123
+ let best = null;
124
+ for (const dir of dirs) {
125
+ let files = [];
126
+ try {
127
+ files = (0, fs_1.readdirSync)(dir).filter(f => f.endsWith('.jsonl'));
128
+ }
129
+ catch (_c) {
130
+ continue;
131
+ }
132
+ for (const f of files) {
133
+ const p = (0, path_1.join)(dir, f);
134
+ try {
135
+ const t = (0, fs_1.statSync)(p).birthtimeMs;
136
+ if (t < sinceMs - 1000 || (best && t < best.t))
137
+ continue;
138
+ const fd = (0, fs_1.openSync)(p, 'r');
139
+ const buf = Buffer.alloc(8192);
140
+ const n = (0, fs_1.readSync)(fd, buf, 0, buf.length, 0);
141
+ (0, fs_1.closeSync)(fd);
142
+ const meta = JSON.parse(buf.toString('utf-8', 0, n).split('\n')[0]);
143
+ const pl = (_a = meta.payload) !== null && _a !== void 0 ? _a : meta;
144
+ if (pl.id && (pl.cwd === cwd || pl.cwd === real))
145
+ best = { id: pl.id, t };
146
+ }
147
+ catch ( /* partial file */_d) { /* partial file */ }
148
+ }
149
+ }
150
+ return (_b = best === null || best === void 0 ? void 0 : best.id) !== null && _b !== void 0 ? _b : null;
151
+ }
152
+ const CODEX = {
153
+ id: 'codex',
154
+ label: 'Codex',
155
+ bin: 'codex',
156
+ spawnArgs: ({ model, resumeId, skipPermissions }) => [
157
+ ...(resumeId ? ['resume', resumeId] : []),
158
+ ...modelArgs('-m', model),
159
+ ...(skipPermissions ? ['--dangerously-bypass-approvals-and-sandbox'] : []),
160
+ ],
161
+ env: () => ({}),
162
+ detectSessionId: findCodexSessionIdSince,
163
+ };
164
+ // Google Gemini CLI. --yolo = approve all tool calls. No resume support here yet.
165
+ const GEMINI = {
166
+ id: 'gemini',
167
+ label: 'Gemini',
168
+ bin: 'gemini',
169
+ spawnArgs: ({ model, skipPermissions }) => [
170
+ ...modelArgs('-m', model),
171
+ ...(skipPermissions ? ['--yolo'] : []),
172
+ ],
173
+ env: () => ({}),
174
+ };
80
175
  exports.BACKENDS = {
81
176
  claude: CLAUDE,
82
177
  copilot: COPILOT,
178
+ opencode: OPENCODE,
179
+ codex: CODEX,
180
+ gemini: GEMINI,
83
181
  };
84
182
  exports.DEFAULT_BACKEND = 'claude';
85
183
  function getBackend(id) {
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseUnifiedDiff = parseUnifiedDiff;
4
+ exports.prDiff = prDiff;
5
+ exports.sessionDiff = sessionDiff;
6
+ const child_process_1 = require("child_process");
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const MAX_BYTES = 1500000;
10
+ const git = (cwd, args) => (0, child_process_1.execFileSync)('git', ['-C', cwd, ...args], { stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 20000000, timeout: 20000 }).toString();
11
+ // Parses `git diff` output into files and numbered lines.
12
+ function parseUnifiedDiff(text) {
13
+ const files = [];
14
+ let f = null, oldNo = 0, newNo = 0;
15
+ for (const line of text.split('\n')) {
16
+ if (line.startsWith('diff --git ')) {
17
+ const m = line.match(/^diff --git a\/(.+) b\/(.+)$/);
18
+ f = { path: m ? m[2] : line.slice(11), status: 'modified', additions: 0, deletions: 0, lines: [] };
19
+ files.push(f);
20
+ }
21
+ else if (!f)
22
+ continue;
23
+ else if (line.startsWith('new file'))
24
+ f.status = 'added';
25
+ else if (line.startsWith('deleted file'))
26
+ f.status = 'deleted';
27
+ else if (line.startsWith('rename to ')) {
28
+ f.status = 'renamed';
29
+ f.path = line.slice(10);
30
+ }
31
+ else if (line.startsWith('Binary files'))
32
+ f.binary = true;
33
+ else if (line.startsWith('@@')) {
34
+ const m = line.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/);
35
+ if (m) {
36
+ oldNo = Number(m[1]);
37
+ newNo = Number(m[2]);
38
+ }
39
+ f.lines.push({ kind: 'hunk', text: line, oldNo: null, newNo: null });
40
+ }
41
+ else if (line.startsWith('+++') || line.startsWith('---') || line.startsWith('index ') || line.startsWith('similarity') || line.startsWith('rename from') || line.startsWith('old mode') || line.startsWith('new mode'))
42
+ continue;
43
+ else if (line.startsWith('+')) {
44
+ f.lines.push({ kind: 'add', text: line.slice(1), oldNo: null, newNo: newNo++ });
45
+ f.additions++;
46
+ }
47
+ else if (line.startsWith('-')) {
48
+ f.lines.push({ kind: 'del', text: line.slice(1), oldNo: oldNo++, newNo: null });
49
+ f.deletions++;
50
+ }
51
+ else if (line.startsWith(' '))
52
+ f.lines.push({ kind: 'ctx', text: line.slice(1), oldNo: oldNo++, newNo: newNo++ });
53
+ }
54
+ return files;
55
+ }
56
+ // Base = where this branch split from the main branch; on the main branch itself, HEAD (so: uncommitted work).
57
+ function findBase(cwd) {
58
+ const head = git(cwd, ['rev-parse', 'HEAD']).trim();
59
+ for (const ref of ['origin/HEAD', 'origin/main', 'origin/master', 'main', 'master']) {
60
+ try {
61
+ const mb = git(cwd, ['merge-base', 'HEAD', ref]).trim();
62
+ if (mb && mb !== head)
63
+ return { base: mb, label: ref.replace(/^origin\//, '') === 'HEAD' ? 'main branch' : ref.replace(/^origin\//, '') };
64
+ if (mb === head)
65
+ break;
66
+ }
67
+ catch ( /* ref missing */_a) { /* ref missing */ }
68
+ }
69
+ return { base: head, label: 'last commit' };
70
+ }
71
+ // A pull request's diff from GitHub (needs gh). For sessions that worked outside their own folder.
72
+ function prDiff(url) {
73
+ const env = Object.assign({}, process.env);
74
+ delete env.GITHUB_TOKEN;
75
+ delete env.GH_TOKEN;
76
+ const run = (args) => (0, child_process_1.execFileSync)('gh', args, { stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 20000000, timeout: 30000, env }).toString();
77
+ let text = run(['pr', 'diff', url]);
78
+ let truncated = false;
79
+ if (text.length > MAX_BYTES) {
80
+ text = text.slice(0, MAX_BYTES);
81
+ truncated = true;
82
+ }
83
+ const meta = JSON.parse(run(['pr', 'view', url, '--json', 'headRefName,baseRefName']));
84
+ return { base: meta.baseRefName, baseLabel: meta.baseRefName, branch: meta.headRefName, files: parseUnifiedDiff(text), truncated };
85
+ }
86
+ function sessionDiff(cwd) {
87
+ const { base, label } = findBase(cwd);
88
+ const branch = git(cwd, ['branch', '--show-current']).trim() || 'detached';
89
+ let text = git(cwd, ['diff', '--no-color', '--find-renames', base]);
90
+ let truncated = false;
91
+ if (text.length > MAX_BYTES) {
92
+ text = text.slice(0, MAX_BYTES);
93
+ truncated = true;
94
+ }
95
+ const files = parseUnifiedDiff(text);
96
+ // New files git doesn't track yet
97
+ for (const p of git(cwd, ['ls-files', '--others', '--exclude-standard']).split('\n').filter(Boolean).slice(0, 200)) {
98
+ try {
99
+ if ((0, fs_1.statSync)((0, path_1.join)(cwd, p)).size > 200000) {
100
+ files.push({ path: p, status: 'added', additions: 0, deletions: 0, lines: [], binary: true });
101
+ continue;
102
+ }
103
+ const body = (0, fs_1.readFileSync)((0, path_1.join)(cwd, p), 'utf-8');
104
+ if (body.includes('\u0000')) {
105
+ files.push({ path: p, status: 'added', additions: 0, deletions: 0, lines: [], binary: true });
106
+ continue;
107
+ }
108
+ const rows = body.split('\n');
109
+ if (rows.at(-1) === '')
110
+ rows.pop();
111
+ files.push({ path: p, status: 'added', additions: rows.length, deletions: 0, lines: rows.map((t, i) => ({ kind: 'add', text: t, oldNo: null, newNo: i + 1 })) });
112
+ }
113
+ catch ( /* vanished */_a) { /* vanished */ }
114
+ }
115
+ return { base, baseLabel: label, branch, files, truncated };
116
+ }
@@ -58,7 +58,7 @@ class LiveSessionStore {
58
58
  if (!(0, fs_1.existsSync)(this.persistDir))
59
59
  (0, fs_1.mkdirSync)(this.persistDir, { recursive: true });
60
60
  const saved = Array.from(this.sessions.values()).map(s => ({
61
- id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, orgId: s.orgId, backend: s.backend, model: s.model, rc: s.rc,
61
+ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, orgId: s.orgId, backend: s.backend, model: s.model, rc: s.rc, worktree: s.worktree,
62
62
  }));
63
63
  (0, fs_1.writeFileSync)(this.persistFile, JSON.stringify(saved));
64
64
  }
@@ -62,6 +62,12 @@ async function fetchCopilotModels() {
62
62
  .filter(m => (seen.has(m.id) ? false : (seen.add(m.id), true)))
63
63
  .map(m => { var _a; return ({ id: m.id, displayName: (_a = m.name) !== null && _a !== void 0 ? _a : m.id }); });
64
64
  }
65
+ // `opencode models` prints provider/model ids, one per line
66
+ async function fetchOpencodeModels() {
67
+ const { stdout } = await execFileAsync('opencode', ['models'], { timeout: 20000 });
68
+ const ids = stdout.split('\n').map(l => l.trim()).filter(l => /^[\w.-]+\/\S+$/.test(l));
69
+ return [{ id: 'default', displayName: 'Default (from its config)' }, ...ids.map(id => ({ id, displayName: id }))];
70
+ }
65
71
  async function fetchClaudeModels(configDir) {
66
72
  var _a;
67
73
  const token = await readToken(configDir);
@@ -92,9 +98,10 @@ async function getModels(backend, orgId, force = false) {
92
98
  return hit.models;
93
99
  try {
94
100
  const org = orgRegistry_1.orgRegistry.get(orgId);
95
- const models = backend === 'copilot'
96
- ? await fetchCopilotModels()
97
- : await fetchClaudeModels((_a = org === null || org === void 0 ? void 0 : org.configDir) !== null && _a !== void 0 ? _a : null);
101
+ const models = backend === 'copilot' ? await fetchCopilotModels()
102
+ : backend === 'opencode' ? await fetchOpencodeModels()
103
+ : backend === 'claude' ? await fetchClaudeModels((_a = org === null || org === void 0 ? void 0 : org.configDir) !== null && _a !== void 0 ? _a : null)
104
+ : [{ id: 'default', displayName: 'Default (from its config)' }]; // codex, gemini: their own default
98
105
  cache.set(key, { at: Date.now(), models });
99
106
  return models;
100
107
  }
@@ -51,9 +51,26 @@ const PROMPTS = {
51
51
  openPr: 'Your work looks finished. Commit it, push the branch, and open a pull request with a clear title and description. Print the PR URL when done.',
52
52
  review: (url) => `There is new review feedback on ${url}. Read it with gh (reviews and comments), address each point, push the fixes, and reply on the PR to say what changed.`,
53
53
  ci: (url) => `CI is failing on ${url}. Find the failing checks with gh, fix the cause, and push.`,
54
+ unresolved: (url, n) => `${url} has ${n} unresolved review thread${n > 1 ? 's' : ''}. Read them with gh (review comments), fix what's needed, push, reply in each thread, and resolve the ones you addressed.`,
54
55
  merge: (url) => `${url} is approved and CI is green. Merge it with gh pr merge, using the merge method this repo uses, and delete the branch. Print the result.`,
55
56
  };
56
57
  const pipelineView_3 = require("./pipelineView");
58
+ // Open review threads on a PR (GraphQL; `gh pr view` doesn't expose them). -1 = unknown.
59
+ async function unresolvedThreads(url, env) {
60
+ const m = url.match(/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)/);
61
+ if (!m)
62
+ return -1;
63
+ try {
64
+ const { stdout } = await execFileAsync('gh', ['api', 'graphql',
65
+ '-f', 'query=query($o:String!,$r:String!,$n:Int!){repository(owner:$o,name:$r){pullRequest(number:$n){reviewThreads(first:100){nodes{isResolved}}}}}',
66
+ '-F', `o=${m[1]}`, '-F', `r=${m[2]}`, '-F', `n=${m[3]}`], { timeout: 15000, env });
67
+ const nodes = JSON.parse(stdout).data.repository.pullRequest.reviewThreads.nodes;
68
+ return nodes.filter(n => !n.isResolved).length;
69
+ }
70
+ catch (_a) {
71
+ return -1;
72
+ }
73
+ }
57
74
  async function prSnapshot(url) {
58
75
  var _a, _b, _c, _d, _e, _f, _g, _h;
59
76
  try {
@@ -70,8 +87,9 @@ async function prSnapshot(url) {
70
87
  .map((r) => { var _a; return ({ login: r.author.login, state: r.state, at: (_a = r.submittedAt) !== null && _a !== void 0 ? _a : null }); });
71
88
  const reviewed = new Set(reviews.map((r) => r.login));
72
89
  const requested = ((_d = j.reviewRequests) !== null && _d !== void 0 ? _d : []).map((r) => { var _a, _b, _c; return (_c = (_b = (_a = r.login) !== null && _a !== void 0 ? _a : r.name) !== null && _b !== void 0 ? _b : r.slug) !== null && _c !== void 0 ? _c : ''; }).filter((x) => x && !reviewed.has(x));
73
- const view = { number: j.number, title: (_e = j.title) !== null && _e !== void 0 ? _e : '', state: j.state, isDraft: !!j.isDraft, reviewDecision: (_f = j.reviewDecision) !== null && _f !== void 0 ? _f : null, checks, requested, reviews, fetchedAt: Date.now() };
74
- return { state: j.state, reviewDecision: (_g = j.reviewDecision) !== null && _g !== void 0 ? _g : null, checks, feedback: others(j.reviews) + others(j.comments), title: (_h = j.title) !== null && _h !== void 0 ? _h : '', view };
90
+ const unresolved = await unresolvedThreads(url, env);
91
+ const view = { number: j.number, title: (_e = j.title) !== null && _e !== void 0 ? _e : '', state: j.state, isDraft: !!j.isDraft, reviewDecision: (_f = j.reviewDecision) !== null && _f !== void 0 ? _f : null, checks, requested, reviews, fetchedAt: Date.now(), unresolved: Math.max(0, unresolved) };
92
+ return { state: j.state, reviewDecision: (_g = j.reviewDecision) !== null && _g !== void 0 ? _g : null, checks, feedback: others(j.reviews) + others(j.comments), title: (_h = j.title) !== null && _h !== void 0 ? _h : '', view, unresolved, isDraft: !!j.isDraft };
75
93
  }
76
94
  catch (_j) {
77
95
  return null;
@@ -136,10 +154,11 @@ class PipelineEngine {
136
154
  this.update(p, {}, logText, notify);
137
155
  }
138
156
  create(liveId, config) {
157
+ var _a;
139
158
  const s = liveSessionStore_1.liveSessionStore.get(liveId);
140
159
  if (!s)
141
160
  return { error: 'Session not found' };
142
- if (s.backend === 'copilot')
161
+ if (((_a = s.backend) !== null && _a !== void 0 ? _a : 'claude') !== 'claude')
143
162
  return { error: 'Automations support Claude sessions only for now' };
144
163
  if (this.items.some(p => p.liveId === liveId && pipelineView_2.ACTIVE_PHASES.includes(p.phase)))
145
164
  return { error: 'This session already has a running automation' };
@@ -277,7 +296,7 @@ class PipelineEngine {
277
296
  }
278
297
  }
279
298
  async advance(id, poll) {
280
- var _a, _b, _c;
299
+ var _a, _b, _c, _d, _e;
281
300
  const p = this.items.find(x => x.id === id);
282
301
  if (!p || !pipelineView_2.ACTIVE_PHASES.includes(p.phase))
283
302
  return;
@@ -356,11 +375,18 @@ class PipelineEngine {
356
375
  suggest(t, 'ci', PROMPTS.ci(t.url), `CI failing on ${(0, pipelineView_3.shortPr)(t.url)}`, 'CI failing', `${pr.title}: click Send to ask the session to fix it`);
357
376
  continue;
358
377
  }
359
- if (pr.reviewDecision === 'APPROVED' && pr.checks !== 'pending' && t.state !== 'ready') {
360
- this.patchTrack(p, t, { state: 'ready', suggestion: { kind: 'merge', text: PROMPTS.merge(t.url), at: Date.now() } }, `${(0, pipelineView_3.shortPr)(t.url)} approved and CI is green. Ready to merge`, { title: 'Ready to merge', body: `${pr.title}: click Merge in the automation` });
378
+ // Open review threads: ask the session to handle them (once per new count), never call it mergeable
379
+ if (pr.unresolved > 0 && pr.unresolved > ((_d = t.seenUnresolved) !== null && _d !== void 0 ? _d : 0) && !t.suggestion && t.state !== 'working') {
380
+ this.patchTrack(p, t, { seenUnresolved: pr.unresolved });
381
+ suggest(t, 'review', PROMPTS.unresolved(t.url, pr.unresolved), `${pr.unresolved} unresolved review thread${pr.unresolved > 1 ? 's' : ''} on ${(0, pipelineView_3.shortPr)(t.url)}`, 'Unresolved review comments', `${pr.title}: ${pr.unresolved} open thread(s)`);
382
+ }
383
+ // Mergeable only when approved, CI done, not a draft and no open threads (unknown thread count = not ready)
384
+ const blockers = [pr.isDraft && 'still a draft', pr.unresolved !== 0 && (pr.unresolved < 0 ? 'review threads unknown' : `${pr.unresolved} unresolved review thread${pr.unresolved > 1 ? 's' : ''}`), pr.reviewDecision !== 'APPROVED' && 'not approved', pr.checks === 'pending' && 'CI running'].filter(Boolean);
385
+ if (!blockers.length && t.state !== 'ready') {
386
+ this.patchTrack(p, t, { state: 'ready', suggestion: { kind: 'merge', text: PROMPTS.merge(t.url), at: Date.now() } }, `${(0, pipelineView_3.shortPr)(t.url)} approved, CI green, no open threads. Ready to merge`, { title: 'Ready to merge', body: `${pr.title}: click Merge in the automation` });
361
387
  }
362
- else if (t.state === 'ready' && pr.reviewDecision !== 'APPROVED') {
363
- this.patchTrack(p, t, { state: 'in-review' }, `${(0, pipelineView_3.shortPr)(t.url)} is no longer approved`);
388
+ else if (blockers.length && t.state === 'ready') {
389
+ this.patchTrack(p, t, Object.assign({ state: 'in-review' }, (((_e = t.suggestion) === null || _e === void 0 ? void 0 : _e.kind) === 'merge' ? { suggestion: null } : {})), `${(0, pipelineView_3.shortPr)(t.url)} is not ready to merge: ${blockers.join(', ')}`);
364
390
  }
365
391
  }
366
392
  this.autoSend(p, quiet);