@bastani/atomic-acp 0.0.12 → 0.0.14

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk";
4
+ import { ndJsonStream } from "@agentclientprotocol/sdk";
5
5
 
6
6
  // src/acp/workflow-history.ts
7
7
  function record(value) {
@@ -80,6 +80,8 @@ function bashTerminalExitMeta(id, exitCode) {
80
80
 
81
81
  // src/acp/agent.ts
82
82
  import {
83
+ agent,
84
+ methods as methods3,
83
85
  RequestError as RequestError4
84
86
  } from "@agentclientprotocol/sdk";
85
87
 
@@ -122,6 +124,9 @@ function terminalAuthLaunchSpec() {
122
124
  }
123
125
 
124
126
  // src/acp/elicitation/extension-dialog.ts
127
+ import {
128
+ methods
129
+ } from "@agentclientprotocol/sdk";
125
130
  var NO_CLIENT_ELICITATION_SUPPORT = {
126
131
  form: false,
127
132
  reason: "missing_client_capability"
@@ -154,6 +159,15 @@ async function requestDialog(conn, sessionId, ev, form, onClientCannotAnswer) {
154
159
  const id = String(ev.id);
155
160
  const cancelled = { type: "extension_ui_response", id, cancelled: true };
156
161
  const method = ev.method;
162
+ if (method === "questionnaire") {
163
+ if (!form) return cancelled;
164
+ try {
165
+ return await requestQuestionnaire(conn, sessionId, id, ev.questions);
166
+ } catch {
167
+ onClientCannotAnswer?.();
168
+ return cancelled;
169
+ }
170
+ }
157
171
  const options = Array.isArray(ev.options) ? ev.options.map(String) : [];
158
172
  if (method === "select" && !options.length) return cancelled;
159
173
  const title = typeof ev.title === "string" ? ev.title : `Atomic ${method}`;
@@ -169,7 +183,7 @@ async function requestDialog(conn, sessionId, ev, form, onClientCannotAnswer) {
169
183
  ...typeof ev.placeholder === "string" ? { description: ev.placeholder } : {},
170
184
  ...typeof ev.prefill === "string" ? { default: ev.prefill } : {}
171
185
  };
172
- const response2 = await conn.unstable_createElicitation({
186
+ const response2 = await conn.request(methods.client.elicitation.create, {
173
187
  sessionId,
174
188
  mode: "form",
175
189
  message: typeof ev.message === "string" ? `${title}
@@ -190,7 +204,7 @@ ${ev.message}` : title,
190
204
  for (const key of ["title", "message", "options", "placeholder", "prefill"]) {
191
205
  if (Object.hasOwn(ev, key)) rawInput[key] = ev[key];
192
206
  }
193
- const response = await conn.requestPermission({
207
+ const response = await conn.request(methods.client.session.requestPermission, {
194
208
  sessionId,
195
209
  toolCall: { toolCallId: `atomic-ui-${id}`, title, kind: "other", status: "pending", rawInput },
196
210
  options: method === "confirm" ? [
@@ -209,9 +223,64 @@ ${ev.message}` : title,
209
223
  return cancelled;
210
224
  }
211
225
  }
226
+ function readQuestions(value) {
227
+ if (!Array.isArray(value) || value.length === 0) return void 0;
228
+ const questions = [];
229
+ for (const item of value) {
230
+ const q = item;
231
+ if (!q || typeof q.question !== "string" || !Array.isArray(q.options) || q.options.length === 0) return void 0;
232
+ const options = q.options.filter(
233
+ (option) => typeof option?.label === "string" && option.label !== ""
234
+ );
235
+ if (options.length !== q.options.length) return void 0;
236
+ questions.push({
237
+ question: q.question,
238
+ ...typeof q.header === "string" ? { header: q.header } : {},
239
+ multiSelect: q.multiSelect === true,
240
+ options
241
+ });
242
+ }
243
+ return questions;
244
+ }
245
+ async function requestQuestionnaire(conn, sessionId, id, rawQuestions) {
246
+ const cancelled = { type: "extension_ui_response", id, cancelled: true };
247
+ const questions = readQuestions(rawQuestions);
248
+ if (!questions) return cancelled;
249
+ const properties = {};
250
+ questions.forEach((q, index) => {
251
+ const labels = q.options.map((option) => option.label);
252
+ const described = q.options.filter((option) => option.description);
253
+ const description = [q.question, ...described.map((option) => `${option.label}: ${option.description}`)].join("\n");
254
+ const title = q.header || q.question;
255
+ properties[`q${index}`] = q.multiSelect ? { type: "array", title, description, minItems: 1, items: { type: "string", enum: labels } } : { type: "string", title, description, enum: labels };
256
+ });
257
+ const response = await conn.request(methods.client.elicitation.create, {
258
+ sessionId,
259
+ mode: "form",
260
+ message: questions.length === 1 ? questions[0].question : "Atomic has some questions for you.",
261
+ requestedSchema: { type: "object", properties, required: Object.keys(properties) },
262
+ _meta: { atomicAcp: { kind: "extension_ui", method: "questionnaire", atomicRequestId: id } }
263
+ });
264
+ if (response.action !== "accept") return cancelled;
265
+ const content = response.content ?? {};
266
+ const answers = [];
267
+ for (const [index, q] of questions.entries()) {
268
+ const labels = q.options.map((option) => option.label);
269
+ const value = content[`q${index}`];
270
+ if (q.multiSelect) {
271
+ if (!Array.isArray(value) || value.length === 0 || !value.every((v) => typeof v === "string" && labels.includes(v)))
272
+ return cancelled;
273
+ answers.push({ questionIndex: index, question: q.question, kind: "multi", answer: null, selected: value });
274
+ } else {
275
+ if (typeof value !== "string" || !labels.includes(value)) return cancelled;
276
+ answers.push({ questionIndex: index, question: q.question, kind: "option", answer: value });
277
+ }
278
+ }
279
+ return { type: "extension_ui_response", id, answers };
280
+ }
212
281
 
213
282
  // src/acp/session.ts
214
- import { RequestError as RequestError3 } from "@agentclientprotocol/sdk";
283
+ import { RequestError as RequestError3, methods as methods2 } from "@agentclientprotocol/sdk";
215
284
 
216
285
  // src/acp/auth-required.ts
217
286
  import { RequestError } from "@agentclientprotocol/sdk";
@@ -561,6 +630,9 @@ var AtomicRpcProcess = class _AtomicRpcProcess {
561
630
  await proc.getState();
562
631
  } catch {
563
632
  }
633
+ if (params.answersQuestionnaires && !params.headless) {
634
+ await proc.request({ type: "set_extension_ui_capabilities", questionnaire: true }).catch(() => void 0);
635
+ }
564
636
  return proc;
565
637
  }
566
638
  /** Whether the Atomic process has exited. A session whose Atomic exited needs a new process. */
@@ -1181,8 +1253,9 @@ function toAtomicMcpServers(servers) {
1181
1253
  exposure: "direct"
1182
1254
  });
1183
1255
  } else {
1184
- const type = "type" in server ? String(server.type) : "unknown";
1185
- warnings.push(`MCP server "${server.name}" skipped: Atomic does not support the ${type} transport`);
1256
+ const other = server;
1257
+ const type = "type" in other ? String(other.type) : "unknown";
1258
+ warnings.push(`MCP server "${other.name}" skipped: Atomic does not support the ${type} transport`);
1186
1259
  }
1187
1260
  }
1188
1261
  return { servers: Object.fromEntries(out), warnings };
@@ -1340,7 +1413,8 @@ var SessionManager = class {
1340
1413
  cwd: params.cwd,
1341
1414
  atomicCommand: params.atomicCommand,
1342
1415
  mcpServers: atomicMcpServersForSpawn(params.mcpServers),
1343
- headless: params.headless
1416
+ headless: params.headless,
1417
+ answersQuestionnaires: params.clientElicitationSupport?.form === true
1344
1418
  });
1345
1419
  } catch (e) {
1346
1420
  if (e instanceof AtomicRpcSpawnError) {
@@ -1348,7 +1422,7 @@ var SessionManager = class {
1348
1422
  }
1349
1423
  throw e;
1350
1424
  }
1351
- let state = null;
1425
+ let state;
1352
1426
  try {
1353
1427
  state = await proc.getState();
1354
1428
  } catch {
@@ -1572,7 +1646,7 @@ var AtomicAcpSession = class {
1572
1646
  }
1573
1647
  emit(update) {
1574
1648
  this.lastEmit = this.lastEmit.then(
1575
- () => this.conn.sessionUpdate({
1649
+ () => this.conn.notify(methods2.client.session.update, {
1576
1650
  sessionId: this.sessionId,
1577
1651
  update
1578
1652
  })
@@ -1752,7 +1826,7 @@ var AtomicAcpSession = class {
1752
1826
  });
1753
1827
  return;
1754
1828
  }
1755
- if (!["select", "confirm", "input", "editor"].includes(String(method))) return;
1829
+ if (!["select", "confirm", "input", "editor", "questionnaire"].includes(String(method))) return;
1756
1830
  if (this.pendingExtensionDialogs.has(id)) return;
1757
1831
  const question = typeof ev.title === "string" && ev.title ? ev.title : `Atomic ${method}`;
1758
1832
  const noPersonAvailable = () => this.emitAgentText(`No person is available to answer "${question}", so Atomic was told it was cancelled.`);
@@ -2592,7 +2666,8 @@ var AtomicAcpAgent = class {
2592
2666
  sessionId,
2593
2667
  atomicCommand: process.env.ATOMIC_ACP_ATOMIC_COMMAND,
2594
2668
  mcpServers: atomicMcpServersForSpawn(mcpServers),
2595
- headless: isHeadlessFromEnv()
2669
+ headless: isHeadlessFromEnv(),
2670
+ answersQuestionnaires: this.clientElicitationSupport.form
2596
2671
  });
2597
2672
  } catch (error) {
2598
2673
  if (error instanceof AtomicRpcSpawnError) throw RequestError4.internalError({ code: error.code }, error.message);
@@ -2729,7 +2804,7 @@ var AtomicAcpAgent = class {
2729
2804
  this.cleanupFailedNewSession(session.sessionId);
2730
2805
  throw maybeAuthRequiredError(err) ?? RequestError4.internalError({}, String(err));
2731
2806
  }
2732
- const { configOptions, models, modes } = configuration;
2807
+ const { configOptions, modes } = configuration;
2733
2808
  if (typeof state?.sessionId === "string") {
2734
2809
  this.store.upsert({ sessionId: session.sessionId, cwd: params.cwd });
2735
2810
  }
@@ -2740,13 +2815,11 @@ var AtomicAcpAgent = class {
2740
2815
  fileCommands,
2741
2816
  updateNotice
2742
2817
  });
2743
- if (preludeText)
2744
- session.setStartupInfo(preludeText);
2818
+ if (preludeText) session.setStartupInfo(preludeText);
2745
2819
  this.sessions.closeAllExcept?.(session.sessionId);
2746
2820
  const response = {
2747
2821
  sessionId: session.sessionId,
2748
2822
  configOptions,
2749
- models,
2750
2823
  modes,
2751
2824
  _meta: {
2752
2825
  atomicAcp: {
@@ -2764,7 +2837,7 @@ var AtomicAcpAgent = class {
2764
2837
  enableSkillCommands,
2765
2838
  includeExtensionCommands: true
2766
2839
  });
2767
- await this.conn.sessionUpdate({
2840
+ await this.conn.notify(methods3.client.session.update, {
2768
2841
  sessionId: session.sessionId,
2769
2842
  update: {
2770
2843
  sessionUpdate: "available_commands_update",
@@ -2774,7 +2847,7 @@ var AtomicAcpAgent = class {
2774
2847
  return;
2775
2848
  } catch {
2776
2849
  }
2777
- await this.conn.sessionUpdate({
2850
+ await this.conn.notify(methods3.client.session.update, {
2778
2851
  sessionId: session.sessionId,
2779
2852
  update: {
2780
2853
  sessionUpdate: "available_commands_update",
@@ -2809,7 +2882,7 @@ var AtomicAcpAgent = class {
2809
2882
  text = `Could not read workflow history: ${error instanceof Error ? error.message : String(error)}`;
2810
2883
  }
2811
2884
  }
2812
- await this.conn.sessionUpdate({
2885
+ await this.conn.notify(methods3.client.session.update, {
2813
2886
  sessionId: session.sessionId,
2814
2887
  update: {
2815
2888
  sessionUpdate: "agent_message_chunk",
@@ -2831,7 +2904,7 @@ var AtomicAcpAgent = class {
2831
2904
  const text = headerLines.join("\n") + (summary ? `
2832
2905
 
2833
2906
  ${summary}` : "");
2834
- await this.conn.sessionUpdate({
2907
+ await this.conn.notify(methods3.client.session.update, {
2835
2908
  sessionId: session.sessionId,
2836
2909
  update: {
2837
2910
  sessionUpdate: "agent_message_chunk",
@@ -2859,7 +2932,7 @@ ${summary}` : "");
2859
2932
  }
2860
2933
  const text = lines.length ? lines.join("\n") : `Session stats:
2861
2934
  ${JSON.stringify(stats, null, 2)}`;
2862
- await this.conn.sessionUpdate({
2935
+ await this.conn.notify(methods3.client.session.update, {
2863
2936
  sessionId: session.sessionId,
2864
2937
  update: {
2865
2938
  sessionUpdate: "agent_message_chunk",
@@ -2871,7 +2944,7 @@ ${JSON.stringify(stats, null, 2)}`;
2871
2944
  if (cmd === "name") {
2872
2945
  const name = args.join(" ").trim();
2873
2946
  if (!name) {
2874
- await this.conn.sessionUpdate({
2947
+ await this.conn.notify(methods3.client.session.update, {
2875
2948
  sessionId: session.sessionId,
2876
2949
  update: {
2877
2950
  sessionUpdate: "agent_message_chunk",
@@ -2885,7 +2958,7 @@ ${JSON.stringify(stats, null, 2)}`;
2885
2958
  } catch (e) {
2886
2959
  const msg = String(e?.message ?? e);
2887
2960
  const hint = /set_session_name/i.test(msg) ? " This requires a newer Atomic version that supports `set_session_name` in RPC mode." : "";
2888
- await this.conn.sessionUpdate({
2961
+ await this.conn.notify(methods3.client.session.update, {
2889
2962
  sessionId: session.sessionId,
2890
2963
  update: {
2891
2964
  sessionUpdate: "agent_message_chunk",
@@ -2894,7 +2967,7 @@ ${JSON.stringify(stats, null, 2)}`;
2894
2967
  });
2895
2968
  return { stopReason: "end_turn" };
2896
2969
  }
2897
- await this.conn.sessionUpdate({
2970
+ await this.conn.notify(methods3.client.session.update, {
2898
2971
  sessionId: session.sessionId,
2899
2972
  update: {
2900
2973
  sessionUpdate: "agent_message_chunk",
@@ -2908,7 +2981,7 @@ ${JSON.stringify(stats, null, 2)}`;
2908
2981
  const state = await session.proc.getState();
2909
2982
  const current = String(state?.steeringMode ?? "");
2910
2983
  if (!modeRaw) {
2911
- await this.conn.sessionUpdate({
2984
+ await this.conn.notify(methods3.client.session.update, {
2912
2985
  sessionId: session.sessionId,
2913
2986
  update: {
2914
2987
  sessionUpdate: "agent_message_chunk",
@@ -2921,7 +2994,7 @@ ${JSON.stringify(stats, null, 2)}`;
2921
2994
  return { stopReason: "end_turn" };
2922
2995
  }
2923
2996
  if (modeRaw !== "all" && modeRaw !== "one-at-a-time") {
2924
- await this.conn.sessionUpdate({
2997
+ await this.conn.notify(methods3.client.session.update, {
2925
2998
  sessionId: session.sessionId,
2926
2999
  update: {
2927
3000
  sessionUpdate: "agent_message_chunk",
@@ -2934,7 +3007,7 @@ ${JSON.stringify(stats, null, 2)}`;
2934
3007
  return { stopReason: "end_turn" };
2935
3008
  }
2936
3009
  await session.proc.setSteeringMode(modeRaw);
2937
- await this.conn.sessionUpdate({
3010
+ await this.conn.notify(methods3.client.session.update, {
2938
3011
  sessionId: session.sessionId,
2939
3012
  update: {
2940
3013
  sessionUpdate: "agent_message_chunk",
@@ -2948,7 +3021,7 @@ ${JSON.stringify(stats, null, 2)}`;
2948
3021
  const state = await session.proc.getState();
2949
3022
  const current = String(state?.followUpMode ?? "");
2950
3023
  if (!modeRaw) {
2951
- await this.conn.sessionUpdate({
3024
+ await this.conn.notify(methods3.client.session.update, {
2952
3025
  sessionId: session.sessionId,
2953
3026
  update: {
2954
3027
  sessionUpdate: "agent_message_chunk",
@@ -2961,7 +3034,7 @@ ${JSON.stringify(stats, null, 2)}`;
2961
3034
  return { stopReason: "end_turn" };
2962
3035
  }
2963
3036
  if (modeRaw !== "all" && modeRaw !== "one-at-a-time") {
2964
- await this.conn.sessionUpdate({
3037
+ await this.conn.notify(methods3.client.session.update, {
2965
3038
  sessionId: session.sessionId,
2966
3039
  update: {
2967
3040
  sessionUpdate: "agent_message_chunk",
@@ -2974,7 +3047,7 @@ ${JSON.stringify(stats, null, 2)}`;
2974
3047
  return { stopReason: "end_turn" };
2975
3048
  }
2976
3049
  await session.proc.setFollowUpMode(modeRaw);
2977
- await this.conn.sessionUpdate({
3050
+ await this.conn.notify(methods3.client.session.update, {
2978
3051
  sessionId: session.sessionId,
2979
3052
  update: {
2980
3053
  sessionUpdate: "agent_message_chunk",
@@ -3008,7 +3081,7 @@ ${JSON.stringify(stats, null, 2)}`;
3008
3081
  };
3009
3082
  const changelogPath = findChangelog();
3010
3083
  if (!changelogPath) {
3011
- await this.conn.sessionUpdate({
3084
+ await this.conn.notify(methods3.client.session.update, {
3012
3085
  sessionId: session.sessionId,
3013
3086
  update: {
3014
3087
  sessionUpdate: "agent_message_chunk",
@@ -3017,11 +3090,11 @@ ${JSON.stringify(stats, null, 2)}`;
3017
3090
  });
3018
3091
  return { stopReason: "end_turn" };
3019
3092
  }
3020
- let text = "";
3093
+ let text;
3021
3094
  try {
3022
3095
  text = readFileSync5(changelogPath, "utf-8");
3023
3096
  } catch (e) {
3024
- await this.conn.sessionUpdate({
3097
+ await this.conn.notify(methods3.client.session.update, {
3025
3098
  sessionId: session.sessionId,
3026
3099
  update: {
3027
3100
  sessionUpdate: "agent_message_chunk",
@@ -3032,7 +3105,7 @@ ${JSON.stringify(stats, null, 2)}`;
3032
3105
  }
3033
3106
  const maxChars = 2e4;
3034
3107
  if (text.length > maxChars) text = text.slice(0, maxChars) + "\n\n...(truncated)...";
3035
- await this.conn.sessionUpdate({
3108
+ await this.conn.notify(methods3.client.session.update, {
3036
3109
  sessionId: session.sessionId,
3037
3110
  update: {
3038
3111
  sessionUpdate: "agent_message_chunk",
@@ -3045,7 +3118,7 @@ ${JSON.stringify(stats, null, 2)}`;
3045
3118
  const state = await session.proc.getState();
3046
3119
  const messageCount = typeof state?.messageCount === "number" ? state.messageCount : 0;
3047
3120
  if (messageCount === 0) {
3048
- await this.conn.sessionUpdate({
3121
+ await this.conn.notify(methods3.client.session.update, {
3049
3122
  sessionId: session.sessionId,
3050
3123
  update: {
3051
3124
  sessionUpdate: "agent_message_chunk",
@@ -3056,12 +3129,12 @@ ${JSON.stringify(stats, null, 2)}`;
3056
3129
  }
3057
3130
  const safeSessionId = session.sessionId.replace(/[^a-zA-Z0-9_-]/g, "_");
3058
3131
  const outputPath = join5(session.cwd, `atomic-session-${safeSessionId}.html`);
3059
- let resultPath = "";
3132
+ let resultPath;
3060
3133
  try {
3061
3134
  const result = await session.proc.exportHtml(outputPath);
3062
3135
  resultPath = result.path;
3063
3136
  } catch (e) {
3064
- await this.conn.sessionUpdate({
3137
+ await this.conn.notify(methods3.client.session.update, {
3065
3138
  sessionId: session.sessionId,
3066
3139
  update: {
3067
3140
  sessionUpdate: "agent_message_chunk",
@@ -3074,7 +3147,7 @@ ${JSON.stringify(stats, null, 2)}`;
3074
3147
  return { stopReason: "end_turn" };
3075
3148
  }
3076
3149
  if (!resultPath) {
3077
- await this.conn.sessionUpdate({
3150
+ await this.conn.notify(methods3.client.session.update, {
3078
3151
  sessionId: session.sessionId,
3079
3152
  update: {
3080
3153
  sessionUpdate: "agent_message_chunk",
@@ -3087,7 +3160,7 @@ ${JSON.stringify(stats, null, 2)}`;
3087
3160
  return { stopReason: "end_turn" };
3088
3161
  }
3089
3162
  const uri = `file://${resultPath}`;
3090
- await this.conn.sessionUpdate({
3163
+ await this.conn.notify(methods3.client.session.update, {
3091
3164
  sessionId: session.sessionId,
3092
3165
  update: {
3093
3166
  sessionUpdate: "agent_message_chunk",
@@ -3097,7 +3170,7 @@ ${JSON.stringify(stats, null, 2)}`;
3097
3170
  }
3098
3171
  }
3099
3172
  });
3100
- await this.conn.sessionUpdate({
3173
+ await this.conn.notify(methods3.client.session.update, {
3101
3174
  sessionId: session.sessionId,
3102
3175
  update: {
3103
3176
  sessionUpdate: "agent_message_chunk",
@@ -3123,7 +3196,7 @@ ${JSON.stringify(stats, null, 2)}`;
3123
3196
  enabled = !current;
3124
3197
  }
3125
3198
  await session.proc.setAutoCompaction(enabled);
3126
- await this.conn.sessionUpdate({
3199
+ await this.conn.notify(methods3.client.session.update, {
3127
3200
  sessionId: session.sessionId,
3128
3201
  update: {
3129
3202
  sessionUpdate: "agent_message_chunk",
@@ -3147,9 +3220,6 @@ ${JSON.stringify(stats, null, 2)}`;
3147
3220
  async listSessions(params) {
3148
3221
  return this.listSessionsImpl(params);
3149
3222
  }
3150
- async unstable_listSessions(params) {
3151
- return this.listSessionsImpl(params);
3152
- }
3153
3223
  async listSessionsImpl(params) {
3154
3224
  const effectiveCwd = params.cwd ?? this.lastSessionCwd ?? process.cwd();
3155
3225
  if (!isAbsolute2(effectiveCwd)) throw RequestError4.invalidParams(`cwd must be an absolute path: ${effectiveCwd}`);
@@ -3186,7 +3256,7 @@ ${JSON.stringify(stats, null, 2)}`;
3186
3256
  const enableSkillCommands = getEnableSkillCommands(params.cwd);
3187
3257
  let atomicCommands = null;
3188
3258
  let atomicCommandsErr = null;
3189
- let state = null;
3259
+ let state;
3190
3260
  let configuration;
3191
3261
  try {
3192
3262
  state = await proc.getState();
@@ -3195,7 +3265,7 @@ ${JSON.stringify(stats, null, 2)}`;
3195
3265
  this.sessions.close(params.sessionId);
3196
3266
  throw err;
3197
3267
  }
3198
- const { configOptions, models, modes } = configuration;
3268
+ const { configOptions, modes } = configuration;
3199
3269
  const title = await this.readSessionTitle(proc, params.sessionId);
3200
3270
  if (title !== null) await session.publishTitle(title || null, null);
3201
3271
  try {
@@ -3212,7 +3282,7 @@ ${JSON.stringify(stats, null, 2)}`;
3212
3282
  if (role === "user") {
3213
3283
  const text = normalizeAtomicMessageText(m?.content);
3214
3284
  if (text) {
3215
- await this.conn.sessionUpdate({
3285
+ await this.conn.notify(methods3.client.session.update, {
3216
3286
  sessionId: session.sessionId,
3217
3287
  update: {
3218
3288
  sessionUpdate: "user_message_chunk",
@@ -3224,7 +3294,7 @@ ${JSON.stringify(stats, null, 2)}`;
3224
3294
  if (role === "assistant") {
3225
3295
  const text = normalizeAtomicAssistantText(m?.content);
3226
3296
  if (text) {
3227
- await this.conn.sessionUpdate({
3297
+ await this.conn.notify(methods3.client.session.update, {
3228
3298
  sessionId: session.sessionId,
3229
3299
  update: {
3230
3300
  sessionUpdate: "agent_message_chunk",
@@ -3239,7 +3309,7 @@ ${JSON.stringify(stats, null, 2)}`;
3239
3309
  const isError = Boolean(m?.isError);
3240
3310
  if (isBashTool(toolName)) {
3241
3311
  const text2 = bashResultText(m);
3242
- await this.conn.sessionUpdate({
3312
+ await this.conn.notify(methods3.client.session.update, {
3243
3313
  sessionId: session.sessionId,
3244
3314
  update: {
3245
3315
  sessionUpdate: "tool_call",
@@ -3251,7 +3321,7 @@ ${JSON.stringify(stats, null, 2)}`;
3251
3321
  _meta: bashTerminalInfoMeta(toolCallId, params.cwd)
3252
3322
  }
3253
3323
  });
3254
- await this.conn.sessionUpdate({
3324
+ await this.conn.notify(methods3.client.session.update, {
3255
3325
  sessionId: session.sessionId,
3256
3326
  update: {
3257
3327
  sessionUpdate: "tool_call_update",
@@ -3265,7 +3335,7 @@ ${JSON.stringify(stats, null, 2)}`;
3265
3335
  });
3266
3336
  continue;
3267
3337
  }
3268
- await this.conn.sessionUpdate({
3338
+ await this.conn.notify(methods3.client.session.update, {
3269
3339
  sessionId: session.sessionId,
3270
3340
  update: {
3271
3341
  sessionUpdate: "tool_call",
@@ -3278,7 +3348,7 @@ ${JSON.stringify(stats, null, 2)}`;
3278
3348
  }
3279
3349
  });
3280
3350
  const text = toolResultToText(m);
3281
- await this.conn.sessionUpdate({
3351
+ await this.conn.notify(methods3.client.session.update, {
3282
3352
  sessionId: session.sessionId,
3283
3353
  update: {
3284
3354
  sessionUpdate: "tool_call_update",
@@ -3292,7 +3362,6 @@ ${JSON.stringify(stats, null, 2)}`;
3292
3362
  }
3293
3363
  const response = {
3294
3364
  configOptions,
3295
- models,
3296
3365
  modes,
3297
3366
  _meta: {
3298
3367
  atomicAcp: {
@@ -3310,7 +3379,7 @@ ${JSON.stringify(stats, null, 2)}`;
3310
3379
  enableSkillCommands,
3311
3380
  includeExtensionCommands: true
3312
3381
  });
3313
- await this.conn.sessionUpdate({
3382
+ await this.conn.notify(methods3.client.session.update, {
3314
3383
  sessionId: session.sessionId,
3315
3384
  update: {
3316
3385
  sessionUpdate: "available_commands_update",
@@ -3320,7 +3389,7 @@ ${JSON.stringify(stats, null, 2)}`;
3320
3389
  return;
3321
3390
  } catch {
3322
3391
  }
3323
- await this.conn.sessionUpdate({
3392
+ await this.conn.notify(methods3.client.session.update, {
3324
3393
  sessionId: session.sessionId,
3325
3394
  update: {
3326
3395
  sessionUpdate: "available_commands_update",
@@ -3331,7 +3400,7 @@ ${JSON.stringify(stats, null, 2)}`;
3331
3400
  }, 0);
3332
3401
  return response;
3333
3402
  }
3334
- async unstable_deleteSession(params) {
3403
+ async deleteSession(params) {
3335
3404
  return this.withSessionOperation(params.sessionId, () => this.deleteSessionImpl(params));
3336
3405
  }
3337
3406
  async deleteSessionImpl(params) {
@@ -3343,12 +3412,6 @@ ${JSON.stringify(stats, null, 2)}`;
3343
3412
  this.store.delete(sessionId);
3344
3413
  return {};
3345
3414
  }
3346
- async unstable_setSessionModel(params) {
3347
- const session = await this.restoreSession(params.sessionId);
3348
- await setSessionModel(session.proc, params.modelId);
3349
- await emitConfigOptionsUpdate(this.conn, session.sessionId, session.proc);
3350
- await session.publishContextUsage();
3351
- }
3352
3415
  async setSessionMode(params) {
3353
3416
  const session = await this.restoreSession(params.sessionId);
3354
3417
  if (typeof params.modeId !== "string" || params.modeId.length === 0) {
@@ -3376,6 +3439,13 @@ ${JSON.stringify(stats, null, 2)}`;
3376
3439
  return { configOptions };
3377
3440
  }
3378
3441
  };
3442
+ function atomicAcpApp(onAgent) {
3443
+ let atomicAgent2;
3444
+ return agent({ name: "atomic-acp" }).onConnect((connection) => {
3445
+ atomicAgent2 = new AtomicAcpAgent(connection.client);
3446
+ onAgent?.(atomicAgent2);
3447
+ }).onRequest(methods3.agent.initialize, ({ params }) => atomicAgent2.initialize(params)).onRequest(methods3.agent.authenticate, ({ params }) => atomicAgent2.authenticate(params)).onRequest(methods3.agent.session.new, ({ params }) => atomicAgent2.newSession(params)).onRequest(methods3.agent.session.load, ({ params }) => atomicAgent2.loadSession(params)).onRequest(methods3.agent.session.list, ({ params }) => atomicAgent2.listSessions(params)).onRequest(methods3.agent.session.delete, ({ params }) => atomicAgent2.deleteSession(params)).onRequest(methods3.agent.session.setMode, ({ params }) => atomicAgent2.setSessionMode(params)).onRequest(methods3.agent.session.setConfigOption, ({ params }) => atomicAgent2.setSessionConfigOption(params)).onRequest(methods3.agent.session.prompt, ({ params }) => atomicAgent2.prompt(params)).onNotification(methods3.agent.session.cancel, ({ params }) => atomicAgent2.cancel(params));
3448
+ }
3379
3449
  function startPendingRecovery(proc) {
3380
3450
  void proc.startPendingRecovery("resume").catch(() => {
3381
3451
  });
@@ -3433,11 +3503,14 @@ async function getSessionConfiguration(proc, pre) {
3433
3503
  }
3434
3504
  async function emitConfigOptionsUpdate(conn, sessionId, proc) {
3435
3505
  const { configOptions, modes } = await getSessionConfiguration(proc);
3436
- await conn.sessionUpdate({
3506
+ await conn.notify(methods3.client.session.update, {
3437
3507
  sessionId,
3438
3508
  update: { sessionUpdate: "current_mode_update", currentModeId: modes.currentModeId }
3439
3509
  });
3440
- await conn.sessionUpdate({ sessionId, update: { sessionUpdate: "config_option_update", configOptions } });
3510
+ await conn.notify(methods3.client.session.update, {
3511
+ sessionId,
3512
+ update: { sessionUpdate: "config_option_update", configOptions }
3513
+ });
3441
3514
  return configOptions;
3442
3515
  }
3443
3516
  async function setSessionModel(proc, requestedModelId) {
@@ -3461,7 +3534,6 @@ async function setSessionModel(proc, requestedModelId) {
3461
3534
  await proc.setModel(provider, modelId);
3462
3535
  }
3463
3536
  async function getModelState(proc, pre) {
3464
- let availableModels = [];
3465
3537
  const data = pre?.availableModels ?? await (async () => {
3466
3538
  try {
3467
3539
  return await proc.getAvailableModels();
@@ -3470,7 +3542,7 @@ async function getModelState(proc, pre) {
3470
3542
  }
3471
3543
  })();
3472
3544
  const models = Array.isArray(data?.models) ? data.models : [];
3473
- availableModels = models.map((m) => {
3545
+ const availableModels = models.map((m) => {
3474
3546
  const provider = String(m?.provider ?? "").trim();
3475
3547
  const id = String(m?.id ?? "").trim();
3476
3548
  if (!provider || !id) return null;
@@ -3769,11 +3841,11 @@ var output = new ReadableStream({
3769
3841
  }
3770
3842
  });
3771
3843
  var stream = ndJsonStream(input, output);
3772
- var agent = new AgentSideConnection((conn) => new AtomicAcpAgent(conn), stream);
3844
+ var atomicAgent;
3845
+ atomicAcpApp((created) => atomicAgent = created).connect(stream);
3773
3846
  function shutdown() {
3774
3847
  try {
3775
- ;
3776
- agent?.agent?.dispose?.();
3848
+ atomicAgent?.dispose();
3777
3849
  } catch {
3778
3850
  }
3779
3851
  try {