@sideboard-ai/core 0.1.292 → 0.1.294

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 (57) hide show
  1. package/dist/{abletime-VFKYNSJT.js → abletime-APP3DZ4P.js} +4 -4
  2. package/dist/{abletime-4WJUVE64.js → abletime-RYDAQ3FE.js} +4 -4
  3. package/dist/{abletime-oauth-ICMB2XV2.js → abletime-oauth-KTERKARA.js} +3 -3
  4. package/dist/{abletime-oauth-FW24YHYX.js → abletime-oauth-ZURGXSY6.js} +3 -3
  5. package/dist/{abletime-rest-OGWC7BC6.js → abletime-rest-4TVIWLZK.js} +3 -3
  6. package/dist/{abletime-rest-HFMRTUDT.js → abletime-rest-EUB6RW7K.js} +3 -3
  7. package/dist/agents/cursor-runner.cjs +329 -36
  8. package/dist/agents/cursor-runner.js +318 -17
  9. package/dist/{agents-XAKSP653.js → agents-2PDBDZPS.js} +5 -5
  10. package/dist/{agents-4BBCKITL.js → agents-73JXQXF2.js} +5 -5
  11. package/dist/{app-settings-EHMXHNG5.js → app-settings-2IH42VA5.js} +3 -1
  12. package/dist/{app-settings-MR2U6AXN.js → app-settings-3OQWRKOK.js} +3 -1
  13. package/dist/{chunk-3E4NOIXN.js → chunk-3D3GGL6X.js} +3 -3
  14. package/dist/{chunk-5HPMKLJ7.js → chunk-6SGYGYH7.js} +38 -14
  15. package/dist/{chunk-NXXQFLNQ.js → chunk-B42H6GJR.js} +2 -2
  16. package/dist/{chunk-G74TSBJ3.js → chunk-BJUHZSZQ.js} +4 -4
  17. package/dist/{chunk-MVZO7QZ2.js → chunk-BU6HH5VA.js} +4 -0
  18. package/dist/{chunk-QOUTSISS.js → chunk-BYAFYLLZ.js} +19 -19
  19. package/dist/{chunk-4VXWLY3L.js → chunk-CECZUHA5.js} +18 -18
  20. package/dist/{chunk-O4324MXE.js → chunk-E7G7RY6T.js} +3 -3
  21. package/dist/{chunk-NFPWLDCH.js → chunk-FAXOEKQR.js} +5 -5
  22. package/dist/{chunk-GU6DT6NO.js → chunk-HSF2RQSQ.js} +5 -5
  23. package/dist/{chunk-OH4EN323.js → chunk-ISEYRGMP.js} +2 -2
  24. package/dist/{chunk-VNCPRMIK.js → chunk-JEYJGQ33.js} +17 -11
  25. package/dist/{chunk-MYJYINTS.js → chunk-LZVWKJXY.js} +3 -3
  26. package/dist/{chunk-Y67TBJD5.js → chunk-MOP5L5QZ.js} +3 -3
  27. package/dist/{chunk-AF2DMY3K.js → chunk-QDDTVIWE.js} +13 -4
  28. package/dist/{chunk-B3BPLPKQ.js → chunk-R3R3ZDFC.js} +2 -2
  29. package/dist/{chunk-36J3IZBS.js → chunk-RSATPXU4.js} +4 -0
  30. package/dist/{chunk-AHH5USEA.js → chunk-SSETL5EX.js} +2 -2
  31. package/dist/{chunk-LUQ7MIVD.js → chunk-SVQTKVXH.js} +16 -11
  32. package/dist/{chunk-W2KZTDET.js → chunk-WZCPZVUC.js} +2 -2
  33. package/dist/{chunk-4BXRRHDC.js → chunk-XCXUVX7I.js} +12 -3
  34. package/dist/{chunk-V3BSO2O6.js → chunk-YEIPPZ5W.js} +3 -3
  35. package/dist/{chunk-GBAACE3C.js → chunk-YKO6HG74.js} +4 -4
  36. package/dist/{chunk-2IXKTAIT.js → chunk-ZEP6JIRF.js} +38 -14
  37. package/dist/{conductor-5MNGC25D.js → conductor-7DEMFEIO.js} +4 -4
  38. package/dist/{conductor-UFJXJPTF.js → conductor-ZQZTYXSX.js} +4 -4
  39. package/dist/{coordinator-prompt-5Q66Y5KW.js → coordinator-prompt-AROMFCP2.js} +3 -3
  40. package/dist/{coordinator-prompt-BYPEW6DE.js → coordinator-prompt-K6XHUG3N.js} +3 -3
  41. package/dist/{global-workspace-YKOYXSB2.js → global-workspace-4WAU4PAL.js} +3 -3
  42. package/dist/{global-workspace-BTH2YGDZ.js → global-workspace-PX4GUVLW.js} +3 -3
  43. package/dist/index.cjs +80 -24
  44. package/dist/index.d.cts +19 -5
  45. package/dist/index.d.ts +19 -5
  46. package/dist/index.js +32 -17
  47. package/dist/mcp/run-stdio.cjs +66 -24
  48. package/dist/mcp/run-stdio.js +15 -13
  49. package/dist/{optional-cli-FRUZSZ3U.js → optional-cli-JQVNSMSU.js} +3 -3
  50. package/dist/{optional-cli-6SW4OOX3.js → optional-cli-PZXDOVJJ.js} +4 -4
  51. package/dist/{orchestrator-EQSK2RMI.js → orchestrator-LIEGSQ6M.js} +8 -8
  52. package/dist/{orchestrator-GSOW3RPA.js → orchestrator-YNEEEP6O.js} +8 -8
  53. package/dist/{workspaces-ELO2YVTU.js → workspaces-MFU3IGAP.js} +3 -3
  54. package/dist/{workspaces-RFD6I4FM.js → workspaces-U7SSD27C.js} +3 -3
  55. package/dist/{worktree-ADVQ6X6C.js → worktree-2VSHRI72.js} +2 -2
  56. package/dist/{worktree-TN7DZDJZ.js → worktree-TQKASYPZ.js} +2 -2
  57. package/package.json +1 -1
@@ -35,9 +35,291 @@ import {
35
35
  import "../chunk-EHT2DRT4.js";
36
36
 
37
37
  // src/agents/cursor-runner.ts
38
- import { mkdirSync } from "fs";
38
+ import { mkdirSync as mkdirSync2 } from "fs";
39
39
  import { createInterface } from "readline";
40
40
 
41
+ // src/agents/cursor-catalog.ts
42
+ import {
43
+ existsSync,
44
+ mkdirSync,
45
+ readdirSync,
46
+ readFileSync,
47
+ renameSync,
48
+ unlinkSync,
49
+ writeFileSync
50
+ } from "fs";
51
+ import { basename, dirname, join } from "path";
52
+ import lockfile from "proper-lockfile";
53
+ var CATALOG_FILES = ["agents.ndjson", "runs.ndjson", "run_events.ndjson", "checkpoints.ndjson"];
54
+ var INTERRUPTED_TMP = /^\.(agents|runs|run_events|checkpoints)\.ndjson\.[0-9a-f]{16}\.tmp$/;
55
+ async function acquireCursorCatalogLock(storeDir) {
56
+ mkdirSync(storeDir, { recursive: true });
57
+ const lockPath = join(storeDir, ".catalog.lock");
58
+ writeFileSync(lockPath, "", { flag: "a" });
59
+ try {
60
+ return await lockfile.lock(lockPath, {
61
+ retries: { retries: 40, minTimeout: 50, maxTimeout: 500 },
62
+ stale: 5e3,
63
+ update: 2e3
64
+ });
65
+ } catch {
66
+ return async () => {
67
+ };
68
+ }
69
+ }
70
+ var heldCatalogRelease;
71
+ function publishRepair(repair, note) {
72
+ for (const line of repair.notes) note(line);
73
+ }
74
+ async function openCursorCatalogTurn(storeDir, note) {
75
+ mkdirSync(storeDir, { recursive: true });
76
+ heldCatalogRelease = await acquireCursorCatalogLock(storeDir);
77
+ publishRepair(repairCursorLocalCatalog(storeDir), note);
78
+ }
79
+ function repairCursorCatalogForResume(storeDir, note) {
80
+ const repair = repairCursorLocalCatalog(storeDir);
81
+ publishRepair(repair, note);
82
+ return repair.repaired;
83
+ }
84
+ async function closeCursorCatalogTurn() {
85
+ const release = heldCatalogRelease;
86
+ heldCatalogRelease = void 0;
87
+ if (release) await release().catch(() => void 0);
88
+ }
89
+ function repairCursorLocalCatalog(storeDir) {
90
+ if (!existsSync(storeDir)) return { repaired: false, notes: [] };
91
+ const notes = [];
92
+ let repaired = false;
93
+ const loaded = /* @__PURE__ */ new Map();
94
+ for (const file of CATALOG_FILES) {
95
+ loaded.set(file, loadCatalogFile(storeDir, file));
96
+ }
97
+ const checkpoints = mergeByKey(
98
+ loaded.get("checkpoints.ndjson").main,
99
+ loaded.get("checkpoints.ndjson").tmpRows,
100
+ (row) => checkpointKey(row),
101
+ (main2) => main2
102
+ );
103
+ const blobs = checkpointBlobs(checkpoints.rows);
104
+ const agents = mergeByKey(
105
+ loaded.get("agents.ndjson").main,
106
+ loaded.get("agents.ndjson").tmpRows,
107
+ (row) => typeof row.agentId === "string" ? row.agentId : null,
108
+ (main2, extra) => preferAgent(main2, extra, blobs)
109
+ );
110
+ const runs = mergeByKey(
111
+ loaded.get("runs.ndjson").main,
112
+ loaded.get("runs.ndjson").tmpRows,
113
+ (row) => runKey(row),
114
+ (main2, extra) => num(extra.updatedAt) >= num(main2.updatedAt) ? extra : main2
115
+ );
116
+ const events = mergeByKey(
117
+ loaded.get("run_events.ndjson").main,
118
+ loaded.get("run_events.ndjson").tmpRows,
119
+ (row) => eventKey(row),
120
+ (main2) => main2
121
+ );
122
+ const merged = {
123
+ "checkpoints.ndjson": checkpoints.rows,
124
+ "agents.ndjson": agents.rows,
125
+ "runs.ndjson": runs.rows,
126
+ "run_events.ndjson": events.rows
127
+ };
128
+ for (const agent of merged["agents.ndjson"]) {
129
+ if (restoreAgentCheckpoint(agent, merged["runs.ndjson"], blobs, notes)) repaired = true;
130
+ if (clearMissingActiveRun(agent, merged["runs.ndjson"], notes)) repaired = true;
131
+ }
132
+ for (const file of CATALOG_FILES) {
133
+ const prior = loaded.get(file);
134
+ const next = merged[file];
135
+ const recovered = countNewKeys(prior.main, next, keyFor(file));
136
+ if (recovered > 0) {
137
+ notes.push(`Cursor catalog recovered ${recovered} ${file} row(s) from an interrupted write`);
138
+ repaired = true;
139
+ }
140
+ if (!sameRows(prior.main, next)) {
141
+ writeCatalogFile(join(storeDir, file), next);
142
+ repaired = true;
143
+ }
144
+ for (const tmp of prior.tmps) {
145
+ try {
146
+ unlinkSync(tmp);
147
+ } catch {
148
+ }
149
+ }
150
+ }
151
+ return { repaired, notes };
152
+ }
153
+ function loadCatalogFile(storeDir, file) {
154
+ const tmps = interruptedTmps(storeDir, file);
155
+ return {
156
+ main: readRows(join(storeDir, file)),
157
+ tmps,
158
+ tmpRows: tmps.flatMap((tmp) => readRows(tmp))
159
+ };
160
+ }
161
+ function keyFor(file) {
162
+ if (file === "checkpoints.ndjson") return checkpointKey;
163
+ if (file === "agents.ndjson") return (row) => typeof row.agentId === "string" ? row.agentId : null;
164
+ if (file === "runs.ndjson") return runKey;
165
+ return eventKey;
166
+ }
167
+ function countNewKeys(main2, next, keyOf) {
168
+ const had = new Set(main2.map(keyOf).filter((key) => Boolean(key)));
169
+ let n = 0;
170
+ for (const row of next) {
171
+ const key = keyOf(row);
172
+ if (key && !had.has(key)) n += 1;
173
+ }
174
+ return n;
175
+ }
176
+ function interruptedTmps(storeDir, file) {
177
+ let names = [];
178
+ try {
179
+ names = readdirSync(storeDir);
180
+ } catch {
181
+ return [];
182
+ }
183
+ const prefix = `.${file}.`;
184
+ return names.filter((name) => name.startsWith(prefix) && INTERRUPTED_TMP.test(name)).map((name) => join(storeDir, name));
185
+ }
186
+ function readRows(file) {
187
+ if (!existsSync(file)) return [];
188
+ let raw = "";
189
+ try {
190
+ raw = readFileSync(file, "utf8");
191
+ } catch {
192
+ return [];
193
+ }
194
+ const rows = [];
195
+ for (const line of raw.split("\n")) {
196
+ const trimmed = line.trim();
197
+ if (!trimmed) continue;
198
+ try {
199
+ const parsed = JSON.parse(trimmed);
200
+ if (isRow(parsed)) rows.push(parsed);
201
+ } catch {
202
+ }
203
+ }
204
+ return rows;
205
+ }
206
+ function writeCatalogFile(file, rows) {
207
+ if (rows.length === 0 && !existsSync(file)) return;
208
+ const body = rows.map((row) => JSON.stringify(row)).join("\n");
209
+ const dir = dirname(file);
210
+ mkdirSync(dir, { recursive: true });
211
+ const tmp = join(dir, `.${basename(file)}.repair.tmp`);
212
+ writeFileSync(tmp, body);
213
+ renameSync(tmp, file);
214
+ }
215
+ function mergeByKey(main2, extra, keyOf, prefer) {
216
+ const out = [];
217
+ const index = /* @__PURE__ */ new Map();
218
+ for (const row of main2) {
219
+ const key = keyOf(row);
220
+ if (!key || index.has(key)) continue;
221
+ index.set(key, out.length);
222
+ out.push(structuredClone(row));
223
+ }
224
+ for (const row of extra) {
225
+ const key = keyOf(row);
226
+ if (!key) continue;
227
+ const at = index.get(key);
228
+ if (at == null) {
229
+ index.set(key, out.length);
230
+ out.push(structuredClone(row));
231
+ continue;
232
+ }
233
+ out[at] = structuredClone(prefer(out[at], row));
234
+ }
235
+ return { rows: out };
236
+ }
237
+ function restoreAgentCheckpoint(agent, runs, blobs, notes) {
238
+ const agentId = typeof agent.agentId === "string" ? agent.agentId : "";
239
+ const current = rootBlobId(agent.latestCheckpoint);
240
+ if (!agentId || !current || blobs.has(`${agentId}\0${current}`)) return false;
241
+ const fallback = fallbackCheckpoint(runs, agentId, blobs);
242
+ const fallbackId = rootBlobId(fallback);
243
+ if (!fallback || !fallbackId) return false;
244
+ agent.latestCheckpoint = fallback;
245
+ agent.updatedAt = Date.now();
246
+ notes.push(
247
+ `Cursor catalog restored agent ${agentId} to checkpoint ${fallbackId} (root blob ${current} was missing)`
248
+ );
249
+ return true;
250
+ }
251
+ function clearMissingActiveRun(agent, runs, notes) {
252
+ const agentId = typeof agent.agentId === "string" ? agent.agentId : "";
253
+ const active = typeof agent.activeRunId === "string" ? agent.activeRunId : "";
254
+ if (!agentId || !active) return false;
255
+ const live = runs.some((run) => run.agentId === agentId && run.runId === active);
256
+ if (live) return false;
257
+ agent.activeRunId = null;
258
+ if (agent.status === "running") agent.status = "idle";
259
+ notes.push(`Cursor catalog cleared missing run ${active} on agent ${agentId}`);
260
+ return true;
261
+ }
262
+ function fallbackCheckpoint(runs, agentId, blobs) {
263
+ const mine = runs.filter((run) => run.agentId === agentId).slice().sort((a, b) => num(b.updatedAt) - num(a.updatedAt));
264
+ for (const run of mine) {
265
+ for (const field of ["latestCheckpointRef", "startCheckpointRef"]) {
266
+ const ref = run[field];
267
+ const id = rootBlobId(ref);
268
+ if (id && blobs.has(`${agentId}\0${id}`) && isRow(ref)) return ref;
269
+ }
270
+ }
271
+ return null;
272
+ }
273
+ function preferAgent(main2, extra, blobs) {
274
+ const mainOk = checkpointPresent(main2, blobs);
275
+ const extraOk = checkpointPresent(extra, blobs);
276
+ if (mainOk && !extraOk) return main2;
277
+ if (extraOk && !mainOk) return extra;
278
+ return num(extra.updatedAt) >= num(main2.updatedAt) ? extra : main2;
279
+ }
280
+ function checkpointPresent(agent, blobs) {
281
+ const agentId = typeof agent.agentId === "string" ? agent.agentId : "";
282
+ const id = rootBlobId(agent.latestCheckpoint);
283
+ if (!id) return true;
284
+ return blobs.has(`${agentId}\0${id}`);
285
+ }
286
+ function checkpointBlobs(rows) {
287
+ const ids = /* @__PURE__ */ new Set();
288
+ for (const row of rows) {
289
+ if (typeof row.agentId !== "string" || typeof row.blobId !== "string") continue;
290
+ if (typeof row.dataBase64 !== "string" || !row.dataBase64) continue;
291
+ ids.add(`${row.agentId}\0${row.blobId}`);
292
+ }
293
+ return ids;
294
+ }
295
+ function checkpointKey(row) {
296
+ if (typeof row.agentId !== "string" || typeof row.blobId !== "string") return null;
297
+ return `${row.agentId}\0${row.blobId}`;
298
+ }
299
+ function runKey(row) {
300
+ if (typeof row.agentId !== "string" || typeof row.runId !== "string") return null;
301
+ return `${row.agentId}\0${row.runId}`;
302
+ }
303
+ function eventKey(row) {
304
+ if (typeof row.runId !== "string") return null;
305
+ if (typeof row.seq === "number") return `${row.runId}\0${row.seq}`;
306
+ if (typeof row.offset === "string") return `${row.runId}\0${row.offset}`;
307
+ return null;
308
+ }
309
+ function rootBlobId(ref) {
310
+ if (!isRow(ref) || typeof ref.rootBlobId !== "string" || !ref.rootBlobId) return null;
311
+ return ref.rootBlobId;
312
+ }
313
+ function num(value) {
314
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
315
+ }
316
+ function sameRows(a, b) {
317
+ return JSON.stringify(a) === JSON.stringify(b);
318
+ }
319
+ function isRow(value) {
320
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
321
+ }
322
+
41
323
  // src/agents/cursor-session.ts
42
324
  function cursorErrorMessage(err) {
43
325
  if (err instanceof Error) return err.message.trim();
@@ -146,7 +428,7 @@ async function* iterateUntilIdle(iterable, idleMs, onIdle, activity) {
146
428
  }
147
429
 
148
430
  // src/agents/sliced-file-read.ts
149
- import { readFileSync, realpathSync, statSync } from "fs";
431
+ import { readFileSync as readFileSync2, realpathSync, statSync } from "fs";
150
432
  import { isAbsolute, relative, resolve, sep } from "path";
151
433
  var SLICED_READ_DEFAULT_LIMIT = 200;
152
434
  var SLICED_READ_MAX_LINE_CHARS = 2e3;
@@ -221,7 +503,7 @@ function executeSlicedFileRead(cwd, args) {
221
503
  try {
222
504
  const st = statSync(abs);
223
505
  if (!st.isFile()) return `Error: not a file: ${rawPath}`;
224
- buf = readFileSync(abs);
506
+ buf = readFileSync2(abs);
225
507
  } catch (err) {
226
508
  return `Error: ${err instanceof Error ? err.message : String(err)}`;
227
509
  }
@@ -306,7 +588,7 @@ function emit(event) {
306
588
  }
307
589
  function localAgentStore(Store, threadId) {
308
590
  const root = cursorSdkStoreDir(threadId);
309
- mkdirSync(root, { recursive: true });
591
+ mkdirSync2(root, { recursive: true });
310
592
  return new Store(root);
311
593
  }
312
594
  async function cancelStaleRuns(Agent, agentId, opts) {
@@ -396,6 +678,9 @@ async function main() {
396
678
  fast: Boolean(req.fast)
397
679
  });
398
680
  const mode = req.planMode ? "plan" : "agent";
681
+ const storeRoot = cursorSdkStoreDir(req.threadId);
682
+ const note = (line) => emit({ type: "stderr", data: line });
683
+ await openCursorCatalogTurn(storeRoot, note);
399
684
  const store = localAgentStore(JsonlLocalAgentStore, req.threadId);
400
685
  const isolateSources = [];
401
686
  let onRpcProgress = () => {
@@ -444,20 +729,22 @@ async function main() {
444
729
  async function createAgent() {
445
730
  return retryTransport(() => Agent.create(createOpts));
446
731
  }
732
+ function resumeAgent(agentId) {
733
+ const { name: _name, ...opts } = createOpts;
734
+ return retryTransport(() => Agent.resume(agentId, opts));
735
+ }
447
736
  async function openAgent() {
448
737
  try {
449
- return req.agentId ? await retryTransport(
450
- () => Agent.resume(req.agentId, {
451
- apiKey,
452
- model,
453
- mode,
454
- local,
455
- disallowedTools: ["read"],
456
- ...mcpServers ? { mcpServers } : {}
457
- })
458
- ) : await createAgent();
738
+ return req.agentId ? await resumeAgent(req.agentId) : await createAgent();
459
739
  } catch (err) {
460
740
  if (!isUnresumableCursorSession(err)) throw err;
741
+ if (repairCursorCatalogForResume(storeRoot, note) && req.agentId) {
742
+ try {
743
+ return await resumeAgent(req.agentId);
744
+ } catch (err2) {
745
+ if (!isUnresumableCursorSession(err2)) throw err2;
746
+ }
747
+ }
461
748
  emit({
462
749
  type: "stderr",
463
750
  data: cursorSessionRecoveryMessage(err, req.agentId)
@@ -511,7 +798,9 @@ async function main() {
511
798
  new Promise((resolve2) => {
512
799
  setTimeout(resolve2, 2e3);
513
800
  })
514
- ]).finally(() => process.exit(1));
801
+ ]).finally(() => {
802
+ void closeCursorCatalogTurn().finally(() => process.exit(1));
803
+ });
515
804
  };
516
805
  process.once("SIGTERM", onSignal);
517
806
  process.once("SIGINT", onSignal);
@@ -609,11 +898,21 @@ async function main() {
609
898
  return await runTurn(agent);
610
899
  }
611
900
  if (!isUnresumableCursorSession(err)) throw err;
901
+ const agentId = agent.agentId;
902
+ await agent[Symbol.asyncDispose]().catch(() => void 0);
903
+ const repaired = repairCursorCatalogForResume(storeRoot, note);
904
+ if (repaired) {
905
+ try {
906
+ agent = await resumeAgent(agentId);
907
+ return await runTurn(agent);
908
+ } catch (err2) {
909
+ if (!isUnresumableCursorSession(err2)) throw err2;
910
+ }
911
+ }
612
912
  emit({
613
913
  type: "stderr",
614
- data: cursorSessionRecoveryMessage(err, agent.agentId)
914
+ data: cursorSessionRecoveryMessage(err, agentId)
615
915
  });
616
- await agent[Symbol.asyncDispose]().catch(() => void 0);
617
916
  agent = await createAgent();
618
917
  return await runTurn(agent);
619
918
  }
@@ -631,6 +930,8 @@ async function main() {
631
930
  const message = err instanceof Error ? err.message : String(err);
632
931
  emit({ type: "stderr", data: message });
633
932
  return 1;
933
+ } finally {
934
+ await closeCursorCatalogTurn();
634
935
  }
635
936
  }
636
937
  main().then(
@@ -46,7 +46,7 @@ import {
46
46
  resolveCursorSdkRoot,
47
47
  resolveQuotaFallbackAgent,
48
48
  turnCostUsdFromCursorUsage
49
- } from "./chunk-LUQ7MIVD.js";
49
+ } from "./chunk-SVQTKVXH.js";
50
50
  import {
51
51
  getAgentSetupInfo,
52
52
  installAgent,
@@ -58,13 +58,13 @@ import {
58
58
  prepareTerminalCommand,
59
59
  resolveLoginCommand,
60
60
  whichOnPath
61
- } from "./chunk-W2KZTDET.js";
61
+ } from "./chunk-WZCPZVUC.js";
62
62
  import "./chunk-7IAMHN2N.js";
63
63
  import "./chunk-PXMLMBMI.js";
64
64
  import "./chunk-2GPQZZLY.js";
65
65
  import "./chunk-AFLNFGGB.js";
66
- import "./chunk-O4324MXE.js";
67
- import "./chunk-5HPMKLJ7.js";
66
+ import "./chunk-E7G7RY6T.js";
67
+ import "./chunk-6SGYGYH7.js";
68
68
  import "./chunk-N2WW62LF.js";
69
69
  import "./chunk-DD67JWTN.js";
70
70
  import {
@@ -83,7 +83,7 @@ import {
83
83
  assertOrchestratorCapableAgent,
84
84
  coerceOrchestratorAgent,
85
85
  isOrchestratorCapableAgent
86
- } from "./chunk-MVZO7QZ2.js";
86
+ } from "./chunk-BU6HH5VA.js";
87
87
  import "./chunk-NSTQ6QKD.js";
88
88
  import "./chunk-WWUABK6B.js";
89
89
  import "./chunk-FJZWM2ON.js";
@@ -37,7 +37,7 @@ import {
37
37
  planModeTurnInstruction,
38
38
  resolveCursorModelId,
39
39
  resolveQuotaFallbackAgent
40
- } from "./chunk-VNCPRMIK.js";
40
+ } from "./chunk-JEYJGQ33.js";
41
41
  import "./chunk-VGNLMGBK.js";
42
42
  import "./chunk-YSLCWCMJ.js";
43
43
  import {
@@ -51,9 +51,9 @@ import {
51
51
  prepareTerminalCommand,
52
52
  resolveLoginCommand,
53
53
  whichOnPath
54
- } from "./chunk-NXXQFLNQ.js";
55
- import "./chunk-V3BSO2O6.js";
56
- import "./chunk-2IXKTAIT.js";
54
+ } from "./chunk-B42H6GJR.js";
55
+ import "./chunk-YEIPPZ5W.js";
56
+ import "./chunk-ZEP6JIRF.js";
57
57
  import "./chunk-QB5MDOHL.js";
58
58
  import "./chunk-2P4XKWV2.js";
59
59
  import "./chunk-33KDPEK4.js";
@@ -87,7 +87,7 @@ import {
87
87
  assertOrchestratorCapableAgent,
88
88
  coerceOrchestratorAgent,
89
89
  isOrchestratorCapableAgent
90
- } from "./chunk-36J3IZBS.js";
90
+ } from "./chunk-RSATPXU4.js";
91
91
  import "./chunk-77WWLBCI.js";
92
92
  import "./chunk-4TR3HZFT.js";
93
93
  import "./chunk-WDRMZKVB.js";
@@ -64,6 +64,7 @@ import {
64
64
  isChatTextScale,
65
65
  isIssueSourceConnected,
66
66
  isLinearConnected,
67
+ isPosthogConnected,
67
68
  isUsageOnLimit,
68
69
  issueSourceLabel,
69
70
  loadAppSettings,
@@ -107,7 +108,7 @@ import {
107
108
  updateProjectProfileSettings,
108
109
  usageOnLimit,
109
110
  writeViewerContext
110
- } from "./chunk-MVZO7QZ2.js";
111
+ } from "./chunk-BU6HH5VA.js";
111
112
  import "./chunk-NSTQ6QKD.js";
112
113
  import "./chunk-WWUABK6B.js";
113
114
  import "./chunk-FJZWM2ON.js";
@@ -178,6 +179,7 @@ export {
178
179
  isChatTextScale,
179
180
  isIssueSourceConnected,
180
181
  isLinearConnected,
182
+ isPosthogConnected,
181
183
  isUsageOnLimit,
182
184
  issueSourceLabel,
183
185
  loadAppSettings,
@@ -62,6 +62,7 @@ import {
62
62
  isChatTextScale,
63
63
  isIssueSourceConnected,
64
64
  isLinearConnected,
65
+ isPosthogConnected,
65
66
  isUsageOnLimit,
66
67
  issueSourceLabel,
67
68
  loadAppSettings,
@@ -105,7 +106,7 @@ import {
105
106
  updateProjectProfileSettings,
106
107
  usageOnLimit,
107
108
  writeViewerContext
108
- } from "./chunk-36J3IZBS.js";
109
+ } from "./chunk-RSATPXU4.js";
109
110
  import "./chunk-77WWLBCI.js";
110
111
  import "./chunk-4TR3HZFT.js";
111
112
  import "./chunk-WDRMZKVB.js";
@@ -176,6 +177,7 @@ export {
176
177
  isChatTextScale,
177
178
  isIssueSourceConnected,
178
179
  isLinearConnected,
180
+ isPosthogConnected,
179
181
  isUsageOnLimit,
180
182
  issueSourceLabel,
181
183
  loadAppSettings,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DEFAULT_ABLETIME_HOST,
3
3
  normalizeAbleTimeHost
4
- } from "./chunk-NFPWLDCH.js";
4
+ } from "./chunk-FAXOEKQR.js";
5
5
  import {
6
6
  httpFetch
7
7
  } from "./chunk-JAT3JFOS.js";
@@ -10,7 +10,7 @@ import {
10
10
  getAbleTimeHost,
11
11
  loadAppSettings,
12
12
  saveAbleTimeConnection
13
- } from "./chunk-36J3IZBS.js";
13
+ } from "./chunk-RSATPXU4.js";
14
14
 
15
15
  // src/integrations/abletime-oauth.ts
16
16
  import { createHash, randomBytes } from "crypto";
@@ -280,7 +280,7 @@ async function startAbleTimeOAuth(opts) {
280
280
  persistAbleTimeTokens(data, { host });
281
281
  const token = data.access_token.trim();
282
282
  try {
283
- const { getAbleTimeOrientation } = await import("./abletime-4WJUVE64.js");
283
+ const { getAbleTimeOrientation } = await import("./abletime-RYDAQ3FE.js");
284
284
  const orientation = await getAbleTimeOrientation({ token, host });
285
285
  return saveAbleTimeConnection({
286
286
  accessToken: token,
@@ -19,7 +19,7 @@ import {
19
19
  import {
20
20
  getGithubGitAuthMode,
21
21
  getGithubPat
22
- } from "./chunk-MVZO7QZ2.js";
22
+ } from "./chunk-BU6HH5VA.js";
23
23
  import {
24
24
  allocateTeamName,
25
25
  listThreads,
@@ -1984,15 +1984,8 @@ async function fetchOriginForWorktree(repoPath, sourceRef, opts) {
1984
1984
  async function fastForwardMainCheckoutIfSafe(repoPath, opts) {
1985
1985
  try {
1986
1986
  const branch = opts?.branch?.trim() || await resolveDefaultBranch(repoPath, { network: false });
1987
- const head = await git(["rev-parse", "--abbrev-ref", "HEAD"], repoPath, {
1988
- reject: false
1989
- });
1990
- const current = head.stdout.trim();
1991
- if (head.exitCode !== 0 || !current || current === "HEAD" || current !== branch) {
1992
- return { updated: false, reason: "not-on-default" };
1993
- }
1994
- if (await isDirty(repoPath)) {
1995
- return { updated: false, reason: "dirty" };
1987
+ if (!branch || branch === "HEAD" || branch.includes("..")) {
1988
+ return { updated: false, reason: "ff-failed" };
1996
1989
  }
1997
1990
  const remote = `origin/${branch}`;
1998
1991
  const remoteOk = await git(["rev-parse", "--verify", remote], repoPath, {
@@ -2001,8 +1994,27 @@ async function fastForwardMainCheckoutIfSafe(repoPath, opts) {
2001
1994
  if (remoteOk.exitCode !== 0) {
2002
1995
  return { updated: false, reason: "no-origin-tip" };
2003
1996
  }
1997
+ const worktrees = await listWorktrees(repoPath);
1998
+ if (worktrees.length === 0) {
1999
+ return { updated: false, reason: "ff-failed" };
2000
+ }
2001
+ const checkout = worktrees.find((entry) => entry.branch === branch) ?? null;
2002
+ const localRef = `refs/heads/${branch}`;
2003
+ const localOk = await git(["rev-parse", "--verify", localRef], repoPath, {
2004
+ reject: false
2005
+ });
2006
+ if (localOk.exitCode !== 0) {
2007
+ if (checkout) return { updated: false, reason: "ff-failed" };
2008
+ const created = await git(["branch", "--track", branch, remote], repoPath, {
2009
+ reject: false
2010
+ });
2011
+ if (created.exitCode !== 0) {
2012
+ return { updated: false, reason: "ff-failed" };
2013
+ }
2014
+ return { updated: true, reason: "updated" };
2015
+ }
2004
2016
  const ancestor = await git(
2005
- ["merge-base", "--is-ancestor", "HEAD", remote],
2017
+ ["merge-base", "--is-ancestor", localRef, remote],
2006
2018
  repoPath,
2007
2019
  { reject: false }
2008
2020
  );
@@ -2010,7 +2022,7 @@ async function fastForwardMainCheckoutIfSafe(repoPath, opts) {
2010
2022
  return { updated: false, reason: "diverged" };
2011
2023
  }
2012
2024
  const behind = await git(
2013
- ["rev-list", "--count", `HEAD..${remote}`],
2025
+ ["rev-list", "--count", `${localRef}..${remote}`],
2014
2026
  repoPath,
2015
2027
  { reject: false }
2016
2028
  );
@@ -2018,10 +2030,22 @@ async function fastForwardMainCheckoutIfSafe(repoPath, opts) {
2018
2030
  if (behind.exitCode !== 0 || !Number.isFinite(n) || n <= 0) {
2019
2031
  return { updated: false, reason: "already-current" };
2020
2032
  }
2021
- const ff = await git(["merge", "--ff-only", remote], repoPath, {
2033
+ if (checkout) {
2034
+ if (await isDirty(checkout.path)) {
2035
+ return { updated: false, reason: "dirty" };
2036
+ }
2037
+ const ff = await git(["merge", "--ff-only", remote], checkout.path, {
2038
+ reject: false
2039
+ });
2040
+ if (ff.exitCode !== 0) {
2041
+ return { updated: false, reason: "ff-failed" };
2042
+ }
2043
+ return { updated: true, reason: "updated" };
2044
+ }
2045
+ const moved = await git(["branch", "-f", branch, remote], repoPath, {
2022
2046
  reject: false
2023
2047
  });
2024
- if (ff.exitCode !== 0) {
2048
+ if (moved.exitCode !== 0) {
2025
2049
  return { updated: false, reason: "ff-failed" };
2026
2050
  }
2027
2051
  return { updated: true, reason: "updated" };
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-QVN2WOKJ.js";
8
8
  import {
9
9
  resolveAgentExecutable
10
- } from "./chunk-36J3IZBS.js";
10
+ } from "./chunk-RSATPXU4.js";
11
11
 
12
12
  // src/agents/install.ts
13
13
  import { existsSync } from "fs";
@@ -265,7 +265,7 @@ async function loginAgent(agent) {
265
265
  };
266
266
  }
267
267
  async function loginManagedAccount(accountId) {
268
- const { loadAppSettings } = await import("./app-settings-MR2U6AXN.js");
268
+ const { loadAppSettings } = await import("./app-settings-3OQWRKOK.js");
269
269
  const { loginEnvPrefix } = await import("./managed-accounts-2AK5RIAF.js");
270
270
  const account = loadAppSettings().accounts.accounts.find((a) => a.id === accountId);
271
271
  if (!account) {
@@ -11,11 +11,11 @@ import {
11
11
  isGlobalThread,
12
12
  isOrchestratorThread,
13
13
  isSlackCoordinatorThread
14
- } from "./chunk-O4324MXE.js";
14
+ } from "./chunk-E7G7RY6T.js";
15
15
  import {
16
16
  mergeAgentGitAuthEnv,
17
17
  resolveAgentGitAuthEnv
18
- } from "./chunk-5HPMKLJ7.js";
18
+ } from "./chunk-6SGYGYH7.js";
19
19
  import {
20
20
  ATTACHMENTS_DIR,
21
21
  DETACHED_JOBS_DIR,
@@ -32,7 +32,7 @@ import {
32
32
  import {
33
33
  assertOrchestratorCapableAgent,
34
34
  contextTokens
35
- } from "./chunk-MVZO7QZ2.js";
35
+ } from "./chunk-BU6HH5VA.js";
36
36
  import {
37
37
  stripNestedElectronEnv
38
38
  } from "./chunk-WWUABK6B.js";
@@ -1674,7 +1674,7 @@ var PORT_RANGE_SIZE = 10;
1674
1674
  var RECLAIM_RETRY_DELAY_MS = 40;
1675
1675
  var RECLAIM_TRIES = 8;
1676
1676
  async function killReclaimable(ports, worktreePath, signal) {
1677
- const { killListenersOnPorts: killListenersOnPorts2, killStaleWorktreeListeners: killStaleWorktreeListeners2 } = await import("./conductor-5MNGC25D.js");
1677
+ const { killListenersOnPorts: killListenersOnPorts2, killStaleWorktreeListeners: killStaleWorktreeListeners2 } = await import("./conductor-7DEMFEIO.js");
1678
1678
  if (worktreePath) killStaleWorktreeListeners2(ports, worktreePath, signal);
1679
1679
  else killListenersOnPorts2(ports);
1680
1680
  }