@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.
package/dist/sdk.js CHANGED
@@ -1884,7 +1884,8 @@ var ACPProtocolHandler = class {
1884
1884
  close: {},
1885
1885
  list: {},
1886
1886
  delete: {},
1887
- resume: {}
1887
+ resume: {},
1888
+ fork: {}
1888
1889
  },
1889
1890
  auth: {
1890
1891
  logout: {}
@@ -2096,12 +2097,44 @@ var ACPProtocolHandler = class {
2096
2097
  async handleSessionFork(id, params) {
2097
2098
  const p = params ?? {};
2098
2099
  const sourceId = typeof p.sessionId === "string" ? p.sessionId : null;
2099
- if (!sourceId || !this.sessions.has(sourceId)) {
2100
+ const source = sourceId ? this.sessions.get(sourceId) : void 0;
2101
+ if (!sourceId || !source) {
2100
2102
  await this.sendError(id, -32e3, `session not found: ${sourceId}`);
2101
2103
  return false;
2102
2104
  }
2103
- const forkParams = params;
2104
- return this.handleSessionNew(id, { ...forkParams, cwd: p.cwd ?? this.defaultCwd });
2105
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2106
+ const sessionId = `sess_${this.allocId()}`;
2107
+ const forked = {
2108
+ id: sessionId,
2109
+ cwd: typeof p.cwd === "string" ? p.cwd : source.cwd,
2110
+ abort: new AbortController(),
2111
+ modeId: source.modeId,
2112
+ createdAt: now,
2113
+ updatedAt: now,
2114
+ ...source.title !== void 0 ? { title: source.title } : {}
2115
+ };
2116
+ const history = (this.replayFor?.(sourceId) ?? []).map((update) => ({
2117
+ sessionUpdate: update.sessionUpdate,
2118
+ content: structuredClone(update.content)
2119
+ }));
2120
+ this.sessions.set(sessionId, forked);
2121
+ this.seedFor?.(sessionId, history);
2122
+ this.onSessionNew(forked);
2123
+ await this.persist(forked, history);
2124
+ await this.sendNotification({
2125
+ sessionId,
2126
+ update: { sessionUpdate: "current_mode_update", modeId: forked.modeId }
2127
+ });
2128
+ await this.transport.send(toWire({
2129
+ jsonrpc: "2.0",
2130
+ id,
2131
+ result: {
2132
+ sessionId,
2133
+ modes: this.modes,
2134
+ configOptions: this.configOptions
2135
+ }
2136
+ }));
2137
+ return false;
2105
2138
  }
2106
2139
  async handleProvidersList(id, _params) {
2107
2140
  await this.transport.send(toWire({
@@ -2302,10 +2335,10 @@ var ACPProtocolHandler = class {
2302
2335
  await this.transport.send(toWire({ jsonrpc: "2.0", method: "session/update", params }));
2303
2336
  }
2304
2337
  /** Best-effort durable persistence of a session + its recorded history. */
2305
- async persist(state) {
2338
+ async persist(state, history = void 0) {
2306
2339
  if (!this.store) return;
2307
2340
  try {
2308
- await this.store.save(state, this.replayFor?.(state.id));
2341
+ await this.store.save(state, history ?? this.replayFor?.(state.id));
2309
2342
  } catch {
2310
2343
  }
2311
2344
  }