@wrongstack/acp 0.283.0 → 0.284.0

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.
@@ -209,7 +209,8 @@ var ACPProtocolHandler = class {
209
209
  close: {},
210
210
  list: {},
211
211
  delete: {},
212
- resume: {}
212
+ resume: {},
213
+ fork: {}
213
214
  },
214
215
  auth: {
215
216
  logout: {}
@@ -421,12 +422,44 @@ var ACPProtocolHandler = class {
421
422
  async handleSessionFork(id, params) {
422
423
  const p = params ?? {};
423
424
  const sourceId = typeof p.sessionId === "string" ? p.sessionId : null;
424
- if (!sourceId || !this.sessions.has(sourceId)) {
425
+ const source = sourceId ? this.sessions.get(sourceId) : void 0;
426
+ if (!sourceId || !source) {
425
427
  await this.sendError(id, -32e3, `session not found: ${sourceId}`);
426
428
  return false;
427
429
  }
428
- const forkParams = params;
429
- return this.handleSessionNew(id, { ...forkParams, cwd: p.cwd ?? this.defaultCwd });
430
+ const now = (/* @__PURE__ */ new Date()).toISOString();
431
+ const sessionId = `sess_${this.allocId()}`;
432
+ const forked = {
433
+ id: sessionId,
434
+ cwd: typeof p.cwd === "string" ? p.cwd : source.cwd,
435
+ abort: new AbortController(),
436
+ modeId: source.modeId,
437
+ createdAt: now,
438
+ updatedAt: now,
439
+ ...source.title !== void 0 ? { title: source.title } : {}
440
+ };
441
+ const history = (this.replayFor?.(sourceId) ?? []).map((update) => ({
442
+ sessionUpdate: update.sessionUpdate,
443
+ content: structuredClone(update.content)
444
+ }));
445
+ this.sessions.set(sessionId, forked);
446
+ this.seedFor?.(sessionId, history);
447
+ this.onSessionNew(forked);
448
+ await this.persist(forked, history);
449
+ await this.sendNotification({
450
+ sessionId,
451
+ update: { sessionUpdate: "current_mode_update", modeId: forked.modeId }
452
+ });
453
+ await this.transport.send(toWire({
454
+ jsonrpc: "2.0",
455
+ id,
456
+ result: {
457
+ sessionId,
458
+ modes: this.modes,
459
+ configOptions: this.configOptions
460
+ }
461
+ }));
462
+ return false;
430
463
  }
431
464
  async handleProvidersList(id, _params) {
432
465
  await this.transport.send(toWire({
@@ -627,10 +660,10 @@ var ACPProtocolHandler = class {
627
660
  await this.transport.send(toWire({ jsonrpc: "2.0", method: "session/update", params }));
628
661
  }
629
662
  /** Best-effort durable persistence of a session + its recorded history. */
630
- async persist(state) {
663
+ async persist(state, history = void 0) {
631
664
  if (!this.store) return;
632
665
  try {
633
- await this.store.save(state, this.replayFor?.(state.id));
666
+ await this.store.save(state, history ?? this.replayFor?.(state.id));
634
667
  } catch {
635
668
  }
636
669
  }