@moxt-ai/mobius 0.0.318 → 0.0.320

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 (76) hide show
  1. package/dist/acp/adapter/agent-initialization.d.ts.map +1 -1
  2. package/dist/acp/adapter/agent-initialization.js +7 -12
  3. package/dist/acp/adapter/agent-initialization.js.map +1 -1
  4. package/dist/acp/adapter/claude/agent-connection.d.ts +6 -0
  5. package/dist/acp/adapter/claude/agent-connection.d.ts.map +1 -0
  6. package/dist/acp/adapter/claude/agent-connection.js +15 -0
  7. package/dist/acp/adapter/claude/agent-connection.js.map +1 -0
  8. package/dist/acp/adapter/codex/agent-connection.d.ts +6 -0
  9. package/dist/acp/adapter/codex/agent-connection.d.ts.map +1 -0
  10. package/dist/acp/adapter/codex/agent-connection.js +15 -0
  11. package/dist/acp/adapter/codex/agent-connection.js.map +1 -0
  12. package/dist/acp/adapter/pi/agent-connection.d.ts +6 -0
  13. package/dist/acp/adapter/pi/agent-connection.d.ts.map +1 -0
  14. package/dist/acp/adapter/pi/agent-connection.js +15 -0
  15. package/dist/acp/adapter/pi/agent-connection.js.map +1 -0
  16. package/dist/acp/adapter/session-events.d.ts +1 -1
  17. package/dist/acp/adapter/session-events.d.ts.map +1 -1
  18. package/dist/acp/adapter/session-events.js +12 -11
  19. package/dist/acp/adapter/session-events.js.map +1 -1
  20. package/dist/acp/agent/agent-definition.d.ts +9 -21
  21. package/dist/acp/agent/agent-definition.d.ts.map +1 -1
  22. package/dist/acp/agent/agent-definition.js +11 -31
  23. package/dist/acp/agent/agent-definition.js.map +1 -1
  24. package/dist/acp/connection/agent-connection.d.ts +18 -10
  25. package/dist/acp/connection/agent-connection.d.ts.map +1 -1
  26. package/dist/acp/connection/agent-connection.js +1 -231
  27. package/dist/acp/connection/agent-connection.js.map +1 -1
  28. package/dist/acp/connection/agent-operation.d.ts +4 -0
  29. package/dist/acp/connection/agent-operation.d.ts.map +1 -0
  30. package/dist/acp/connection/agent-operation.js +57 -0
  31. package/dist/acp/connection/agent-operation.js.map +1 -0
  32. package/dist/acp/connection/endpoint-agent-connection.d.ts +28 -0
  33. package/dist/acp/connection/endpoint-agent-connection.d.ts.map +1 -0
  34. package/dist/acp/connection/endpoint-agent-connection.js +31 -0
  35. package/dist/acp/connection/endpoint-agent-connection.js.map +1 -0
  36. package/dist/agent/discovery/acp-readiness-probe.d.ts +1 -0
  37. package/dist/agent/discovery/acp-readiness-probe.d.ts.map +1 -1
  38. package/dist/agent/discovery/acp-readiness-probe.js +29 -188
  39. package/dist/agent/discovery/acp-readiness-probe.js.map +1 -1
  40. package/dist/agent/discovery/discover-agent.d.ts.map +1 -1
  41. package/dist/agent/discovery/discover-agent.js +4 -6
  42. package/dist/agent/discovery/discover-agent.js.map +1 -1
  43. package/dist/agent/discovery/executable-discovery.d.ts +1 -1
  44. package/dist/agent/discovery/executable-discovery.d.ts.map +1 -1
  45. package/dist/agent/discovery/executable-discovery.js +1 -6
  46. package/dist/agent/discovery/executable-discovery.js.map +1 -1
  47. package/dist/agent/specification/agent-specification.d.ts +3 -9
  48. package/dist/agent/specification/agent-specification.d.ts.map +1 -1
  49. package/dist/agent/specification/agent-specification.js +1 -12
  50. package/dist/agent/specification/agent-specification.js.map +1 -1
  51. package/dist/agent/specification/vendors/claude-code-agent.d.ts +2 -2
  52. package/dist/agent/specification/vendors/claude-code-agent.d.ts.map +1 -1
  53. package/dist/agent/specification/vendors/claude-code-agent.js +2 -2
  54. package/dist/agent/specification/vendors/claude-code-agent.js.map +1 -1
  55. package/dist/agent/specification/vendors/codex-agent.d.ts +2 -2
  56. package/dist/agent/specification/vendors/codex-agent.d.ts.map +1 -1
  57. package/dist/agent/specification/vendors/codex-agent.js +2 -2
  58. package/dist/agent/specification/vendors/codex-agent.js.map +1 -1
  59. package/dist/agent/specification/vendors/pi-agent.d.ts +2 -2
  60. package/dist/agent/specification/vendors/pi-agent.d.ts.map +1 -1
  61. package/dist/agent/specification/vendors/pi-agent.js +2 -2
  62. package/dist/agent/specification/vendors/pi-agent.js.map +1 -1
  63. package/dist/cli/handler/agents/logic/agent-diagnostics.d.ts.map +1 -1
  64. package/dist/cli/handler/agents/logic/agent-diagnostics.js +1 -4
  65. package/dist/cli/handler/agents/logic/agent-diagnostics.js.map +1 -1
  66. package/dist/cli.js +579 -860
  67. package/dist/cli.js.map +4 -4
  68. package/dist/runtime/catalog/resolve-catalog-agent.js +6 -3
  69. package/dist/runtime/catalog/resolve-catalog-agent.js.map +1 -1
  70. package/dist/runtime.d.ts +3 -2
  71. package/dist/runtime.d.ts.map +1 -1
  72. package/dist/runtime.js +303 -609
  73. package/dist/runtime.js.map +4 -4
  74. package/dist/session/settings/discover-agent-settings.js +1 -1
  75. package/dist/session/settings/discover-agent-settings.js.map +1 -1
  76. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -2086,7 +2086,7 @@ var init_package = __esm({
2086
2086
  "package.json"() {
2087
2087
  package_default = {
2088
2088
  name: "@moxt-ai/mobius",
2089
- version: "0.0.318",
2089
+ version: "0.0.320",
2090
2090
  description: "Mobius CLI for pairing and running local AI agent services.",
2091
2091
  type: "module",
2092
2092
  bin: {
@@ -5781,6 +5781,224 @@ var init_state_root = __esm({
5781
5781
  }
5782
5782
  });
5783
5783
 
5784
+ // src/util/value-utils.ts
5785
+ function truncate(value, maximumLength) {
5786
+ return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
5787
+ }
5788
+ function isRecord(value) {
5789
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5790
+ }
5791
+ function readString(value, fallback = "") {
5792
+ return typeof value === "string" ? value : fallback;
5793
+ }
5794
+ function arraysEqual(left, right) {
5795
+ return left.length === right.length && left.every((value, index2) => value === right[index2]);
5796
+ }
5797
+ function recordsEqual(left, right) {
5798
+ const leftEntries = Object.entries(left);
5799
+ const rightEntries = Object.entries(right);
5800
+ return leftEntries.length === rightEntries.length && leftEntries.every(([name2, value]) => right[name2] === value);
5801
+ }
5802
+ var init_value_utils = __esm({
5803
+ "src/util/value-utils.ts"() {
5804
+ "use strict";
5805
+ }
5806
+ });
5807
+
5808
+ // src/infra/operation-error.ts
5809
+ function operationErrorCode(error62) {
5810
+ return error62 instanceof OperationError ? error62.code : "session_operation_failed";
5811
+ }
5812
+ function operationErrorMessage(error62) {
5813
+ return error62 instanceof OperationError ? error62.message : "The local agent operation could not be completed";
5814
+ }
5815
+ var OperationError;
5816
+ var init_operation_error = __esm({
5817
+ "src/infra/operation-error.ts"() {
5818
+ "use strict";
5819
+ OperationError = class extends Error {
5820
+ code;
5821
+ constructor(code, message, options = {}) {
5822
+ super(message, options);
5823
+ this.code = code;
5824
+ }
5825
+ };
5826
+ }
5827
+ });
5828
+
5829
+ // src/acp/acp-error.ts
5830
+ var AcpExecutionError, AcpConfigurationValueUnavailableError;
5831
+ var init_acp_error = __esm({
5832
+ "src/acp/acp-error.ts"() {
5833
+ "use strict";
5834
+ init_operation_error();
5835
+ AcpExecutionError = class extends OperationError {
5836
+ constructor(message, options = {}, code = "acp_execution_failed") {
5837
+ super(code, message, options);
5838
+ this.name = "AcpExecutionError";
5839
+ }
5840
+ };
5841
+ AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
5842
+ configId;
5843
+ offeredValueCount;
5844
+ offeredValues;
5845
+ requestedValue;
5846
+ constructor(configId, requestedValue, offeredValues) {
5847
+ super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
5848
+ this.name = "AcpConfigurationValueUnavailableError";
5849
+ this.configId = configId.slice(0, 128);
5850
+ this.requestedValue = requestedValue.slice(0, 128);
5851
+ this.offeredValueCount = offeredValues.length;
5852
+ this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
5853
+ }
5854
+ };
5855
+ }
5856
+ });
5857
+
5858
+ // src/acp/agent/in-process-endpoint.ts
5859
+ function acpEndpointTerminationError(termination) {
5860
+ switch (termination.kind) {
5861
+ case "failed":
5862
+ return termination.error;
5863
+ case "closed":
5864
+ return new AcpExecutionError("The ACP endpoint is closed", {}, "acp_endpoint_closed");
5865
+ default: {
5866
+ const unreachable3 = termination;
5867
+ return unreachable3;
5868
+ }
5869
+ }
5870
+ }
5871
+ var init_in_process_endpoint = __esm({
5872
+ "src/acp/agent/in-process-endpoint.ts"() {
5873
+ "use strict";
5874
+ init_acp_error();
5875
+ }
5876
+ });
5877
+
5878
+ // src/acp/connection/agent-operation.ts
5879
+ import { RequestError } from "@agentclientprotocol/sdk";
5880
+ function requestErrorMessage(error62) {
5881
+ const fallback = truncate(error62.message, 500);
5882
+ if (error62.message !== "Internal error" || !isRecord(error62.data)) {
5883
+ return fallback;
5884
+ }
5885
+ const agentError = error62.data["error"];
5886
+ if (isRecord(agentError)) {
5887
+ const message = agentError["message"];
5888
+ if (typeof message === "string" && message.length > 0) {
5889
+ return truncate(message, 500);
5890
+ }
5891
+ }
5892
+ const details = error62.data["details"];
5893
+ return typeof details === "string" && details.length > 0 ? truncate(details, 500) : fallback;
5894
+ }
5895
+ async function raceAgentOperation(operation, termination, exitMessage, signal) {
5896
+ let removeAbortListener = () => {
5897
+ };
5898
+ const aborted2 = new Promise((_resolve, reject2) => {
5899
+ const rejectAbort = () => {
5900
+ reject2(signal.reason ?? new Error("ACP request was cancelled"));
5901
+ };
5902
+ signal.addEventListener("abort", rejectAbort, { once: true });
5903
+ removeAbortListener = () => signal.removeEventListener("abort", rejectAbort);
5904
+ if (signal.aborted) {
5905
+ rejectAbort();
5906
+ }
5907
+ });
5908
+ try {
5909
+ return await Promise.race([
5910
+ aborted2,
5911
+ operation,
5912
+ termination.then((result) => {
5913
+ const cause = acpEndpointTerminationError(result);
5914
+ throw new AcpExecutionError(exitMessage, { cause }, cause.code);
5915
+ })
5916
+ ]);
5917
+ } catch (error62) {
5918
+ signal.throwIfAborted();
5919
+ if (error62 instanceof RequestError && error62.code === -32e3) {
5920
+ throw new AcpExecutionError(
5921
+ "Agent authentication is required",
5922
+ { cause: error62 },
5923
+ "authentication_required"
5924
+ );
5925
+ }
5926
+ if (error62 instanceof RequestError) {
5927
+ throw new AcpExecutionError(requestErrorMessage(error62), { cause: error62 }, "acp_agent_error");
5928
+ }
5929
+ throw error62;
5930
+ } finally {
5931
+ removeAbortListener();
5932
+ }
5933
+ }
5934
+ var init_agent_operation = __esm({
5935
+ "src/acp/connection/agent-operation.ts"() {
5936
+ "use strict";
5937
+ init_value_utils();
5938
+ init_acp_error();
5939
+ init_in_process_endpoint();
5940
+ }
5941
+ });
5942
+
5943
+ // src/acp/connection/create-client.ts
5944
+ import {
5945
+ client,
5946
+ methods
5947
+ } from "@agentclientprotocol/sdk";
5948
+ var createAcpClient;
5949
+ var init_create_client = __esm({
5950
+ "src/acp/connection/create-client.ts"() {
5951
+ "use strict";
5952
+ createAcpClient = (handler) => client({ name: "mobius" }).onRequest(
5953
+ methods.client.session.requestPermission,
5954
+ async (context) => await handler.onPermission(context.params, context.signal)
5955
+ ).onRequest(
5956
+ methods.client.elicitation.create,
5957
+ async (context) => await handler.onElicitation(context.params, context.signal)
5958
+ ).onNotification(methods.client.session.update, async (context) => {
5959
+ await handler.onUpdate(context.params);
5960
+ }).onNotification(methods.client.elicitation.complete, async (context) => {
5961
+ await handler.onElicitationComplete(context.params);
5962
+ });
5963
+ }
5964
+ });
5965
+
5966
+ // src/acp/connection/endpoint-agent-connection.ts
5967
+ var EndpointAgentConnection;
5968
+ var init_endpoint_agent_connection = __esm({
5969
+ "src/acp/connection/endpoint-agent-connection.ts"() {
5970
+ "use strict";
5971
+ init_agent_operation();
5972
+ init_create_client();
5973
+ EndpointAgentConnection = class {
5974
+ #endpoint;
5975
+ connection;
5976
+ termination;
5977
+ #closePromise = null;
5978
+ constructor(endpoint, client2) {
5979
+ this.#endpoint = endpoint;
5980
+ this.termination = endpoint.terminated;
5981
+ this.connection = createAcpClient(client2).connect(endpoint.app());
5982
+ }
5983
+ initialize = async (signal) => {
5984
+ await this.#endpoint.initialize(signal);
5985
+ };
5986
+ agentSettingsModelEffort = () => this.#endpoint.agentSettingsModelEffort?.() ?? null;
5987
+ closeProcess = () => {
5988
+ this.#closePromise ??= (async () => {
5989
+ try {
5990
+ await this.#endpoint.close();
5991
+ } finally {
5992
+ this.connection.close();
5993
+ }
5994
+ })();
5995
+ return this.#closePromise;
5996
+ };
5997
+ race = (operation, exitMessage, signal) => raceAgentOperation(operation, this.termination, exitMessage, signal);
5998
+ };
5999
+ }
6000
+ });
6001
+
5784
6002
  // src/acp/harness/claude/parent-lifeline.ts
5785
6003
  import { spawn } from "node:child_process";
5786
6004
  import { Duplex } from "node:stream";
@@ -42527,7 +42745,7 @@ ${plan}` }]
42527
42745
  });
42528
42746
 
42529
42747
  // src/acp/harness/claude/upstream/dist/goal-extension.js
42530
- import { RequestError } from "@agentclientprotocol/sdk";
42748
+ import { RequestError as RequestError2 } from "@agentclientprotocol/sdk";
42531
42749
  function goalUpdateFromPrompt(prompt) {
42532
42750
  const match = /^\/goal(?:\s+([\s\S]*))?$/.exec(prompt);
42533
42751
  const argument = match?.[1]?.trim();
@@ -42545,17 +42763,17 @@ function goalUpdateFromPrompt(prompt) {
42545
42763
  }
42546
42764
  function parseGoalRequest(params) {
42547
42765
  if (!params || typeof params !== "object") {
42548
- throw RequestError.invalidParams(void 0, "goal params must be an object");
42766
+ throw RequestError2.invalidParams(void 0, "goal params must be an object");
42549
42767
  }
42550
42768
  const { sessionId, action, objective } = params;
42551
42769
  if (typeof sessionId !== "string" || sessionId.length === 0) {
42552
- throw RequestError.invalidParams(void 0, "goal params require a non-empty sessionId");
42770
+ throw RequestError2.invalidParams(void 0, "goal params require a non-empty sessionId");
42553
42771
  }
42554
42772
  if (!GOAL_ACTIONS.includes(action)) {
42555
- throw RequestError.invalidParams(void 0, 'goal action must be "set" or "clear"');
42773
+ throw RequestError2.invalidParams(void 0, 'goal action must be "set" or "clear"');
42556
42774
  }
42557
42775
  if (action === "set" && (typeof objective !== "string" || objective.trim().length === 0)) {
42558
- throw RequestError.invalidParams(void 0, 'goal action "set" requires a non-empty objective');
42776
+ throw RequestError2.invalidParams(void 0, 'goal action "set" requires a non-empty objective');
42559
42777
  }
42560
42778
  return action === "set" ? { sessionId, action, objective: objective.trim() } : { sessionId, action: "clear" };
42561
42779
  }
@@ -42631,7 +42849,7 @@ var init_modes = __esm({
42631
42849
  });
42632
42850
 
42633
42851
  // src/acp/harness/claude/upstream/dist/permissions/normalization.js
42634
- function isRecord(value) {
42852
+ function isRecord2(value) {
42635
42853
  return !!value && typeof value === "object" && !Array.isArray(value);
42636
42854
  }
42637
42855
  function isDestination(value) {
@@ -42648,13 +42866,13 @@ function safePlainString(value, maxLength) {
42648
42866
  });
42649
42867
  }
42650
42868
  function isRule(value) {
42651
- if (!isRecord(value) || !safePlainString(value.toolName, MAX_TOOL_NAME_LENGTH)) {
42869
+ if (!isRecord2(value) || !safePlainString(value.toolName, MAX_TOOL_NAME_LENGTH)) {
42652
42870
  return false;
42653
42871
  }
42654
42872
  return value.ruleContent === void 0 || safePlainString(value.ruleContent, MAX_RULE_CONTENT_LENGTH);
42655
42873
  }
42656
42874
  function isKnownUpdate(value) {
42657
- if (!isRecord(value) || !isDestination(value.destination) || typeof value.type !== "string") {
42875
+ if (!isRecord2(value) || !isDestination(value.destination) || typeof value.type !== "string") {
42658
42876
  return false;
42659
42877
  }
42660
42878
  switch (value.type) {
@@ -65115,7 +65333,7 @@ var init_settings = __esm({
65115
65333
  });
65116
65334
 
65117
65335
  // src/acp/harness/claude/upstream/dist/session-mode.js
65118
- import { RequestError as RequestError2 } from "@agentclientprotocol/sdk";
65336
+ import { RequestError as RequestError3 } from "@agentclientprotocol/sdk";
65119
65337
  var MODE_CONFIG_ID, AUTO_MODE_FALLBACK, AUTO_MODE_FALLBACK_NOTICE, SessionModeManager;
65120
65338
  var init_session_mode = __esm({
65121
65339
  "src/acp/harness/claude/upstream/dist/session-mode.js"() {
@@ -65265,7 +65483,7 @@ var init_session_mode = __esm({
65265
65483
  throw new Error("Session not found");
65266
65484
  }
65267
65485
  if (session.queryClosed) {
65268
- throw RequestError2.internalError(void 0, this.options.sessionEndedMessage);
65486
+ throw RequestError3.internalError(void 0, this.options.sessionEndedMessage);
65269
65487
  }
65270
65488
  return session;
65271
65489
  }
@@ -65345,7 +65563,7 @@ import * as fs4 from "node:fs/promises";
65345
65563
  import * as os3 from "node:os";
65346
65564
  import * as path6 from "node:path";
65347
65565
  import { promisify } from "node:util";
65348
- import { agent as acpAgent, CreateElicitationResponse as CreateElicitationResponse2, methods, ndJsonStream, RequestError as RequestError3 } from "@agentclientprotocol/sdk";
65566
+ import { agent as acpAgent, CreateElicitationResponse as CreateElicitationResponse2, methods as methods2, ndJsonStream, RequestError as RequestError4 } from "@agentclientprotocol/sdk";
65349
65567
  function supportsMcpOAuth(query) {
65350
65568
  return typeof query.mcpAuthenticate === "function";
65351
65569
  }
@@ -65367,19 +65585,19 @@ function waitUnlessAborted(milliseconds, signal) {
65367
65585
  }
65368
65586
  function parseSteerRequest(params) {
65369
65587
  if (!params || typeof params !== "object") {
65370
- throw RequestError3.invalidParams(void 0, "steer params must be an object");
65588
+ throw RequestError4.invalidParams(void 0, "steer params must be an object");
65371
65589
  }
65372
65590
  const { sessionId, prompt, _meta } = params;
65373
65591
  if (typeof sessionId !== "string" || sessionId.length === 0) {
65374
- throw RequestError3.invalidParams(void 0, "steer params require a non-empty sessionId");
65592
+ throw RequestError4.invalidParams(void 0, "steer params require a non-empty sessionId");
65375
65593
  }
65376
65594
  if (!Array.isArray(prompt) || prompt.length === 0) {
65377
- throw RequestError3.invalidParams(void 0, "steer params require a non-empty prompt array");
65595
+ throw RequestError4.invalidParams(void 0, "steer params require a non-empty prompt array");
65378
65596
  }
65379
65597
  const steering = _meta && typeof _meta === "object" ? _meta.steering : void 0;
65380
65598
  const idleBehavior = steering && typeof steering === "object" ? steering.idleBehavior : void 0;
65381
65599
  if (idleBehavior !== void 0 && idleBehavior !== "promptRequired") {
65382
- throw RequestError3.invalidParams(void 0, "unsupported steering idleBehavior");
65600
+ throw RequestError4.invalidParams(void 0, "unsupported steering idleBehavior");
65383
65601
  }
65384
65602
  return {
65385
65603
  sessionId,
@@ -65389,14 +65607,14 @@ function parseSteerRequest(params) {
65389
65607
  }
65390
65608
  function parseRenameRequest(params) {
65391
65609
  if (!params || typeof params !== "object") {
65392
- throw RequestError3.invalidParams(void 0, "rename params must be an object");
65610
+ throw RequestError4.invalidParams(void 0, "rename params must be an object");
65393
65611
  }
65394
65612
  const { sessionId, title: title2 } = params;
65395
65613
  if (typeof sessionId !== "string" || sessionId.length === 0) {
65396
- throw RequestError3.invalidParams(void 0, "rename params require a non-empty sessionId");
65614
+ throw RequestError4.invalidParams(void 0, "rename params require a non-empty sessionId");
65397
65615
  }
65398
65616
  if (typeof title2 !== "string" || title2.trim().length === 0) {
65399
- throw RequestError3.invalidParams(void 0, "rename params require a non-empty title");
65617
+ throw RequestError4.invalidParams(void 0, "rename params require a non-empty title");
65400
65618
  }
65401
65619
  return { sessionId, title: title2 };
65402
65620
  }
@@ -66860,7 +67078,7 @@ function createClaudeAcpApp(options = {}) {
66860
67078
  const app = acpAgent({ name: "claude-code-acp" }).onConnect((connection) => {
66861
67079
  agent = new ClaudeAcpAgent(new ClientConnection(connection.client, options.onSessionUpdate), options.logger, options.environment, options.spawnClaudeCodeProcess, options.onBackgroundActivity);
66862
67080
  options.onConnect?.(connection);
66863
- }).onRequest(methods.agent.initialize, (ctx) => requiredAgent(agent).initialize(ctx.params)).onRequest(methods.agent.session.new, (ctx) => requiredAgent(agent).newSession(ctx.params)).onRequest(methods.agent.session.load, (ctx) => requiredAgent(agent).loadSession(ctx.params, ctx.signal)).onRequest(methods.agent.session.fork, (ctx) => requiredAgent(agent).unstable_forkSession(ctx.params, ctx.signal)).onRequest(methods.agent.session.list, (ctx) => requiredAgent(agent).listSessions(ctx.params, ctx.signal)).onRequest(methods.agent.session.delete, (ctx) => requiredAgent(agent).deleteSession(ctx.params)).onRequest(methods.agent.session.resume, (ctx) => requiredAgent(agent).resumeSession(ctx.params)).onRequest(methods.agent.session.close, (ctx) => requiredAgent(agent).closeSession(ctx.params)).onRequest(methods.agent.session.setMode, (ctx) => requiredAgent(agent).setSessionMode(ctx.params)).onRequest(methods.agent.session.setConfigOption, (ctx) => requiredAgent(agent).setSessionConfigOption(ctx.params)).onRequest(methods.agent.authenticate, (ctx) => requiredAgent(agent).authenticate(ctx.params)).onRequest(methods.agent.providers.list, (ctx) => requiredAgent(agent).unstable_listProviders(ctx.params)).onRequest(methods.agent.providers.set, (ctx) => requiredAgent(agent).unstable_setProvider(ctx.params)).onRequest(methods.agent.providers.disable, (ctx) => requiredAgent(agent).unstable_disableProvider(ctx.params)).onRequest(methods.agent.logout, (ctx) => requiredAgent(agent).logout(ctx.params)).onRequest(methods.agent.session.prompt, (ctx) => runPromptWithCancellation(requiredAgent(agent), ctx.params, ctx.signal)).onNotification(methods.agent.session.cancel, (ctx) => requiredAgent(agent).cancel(ctx.params)).onRequest(STEER_METHOD, { parse: parseSteerRequest }, (ctx) => requiredAgent(agent).steer(ctx.params)).onRequest(RENAME_METHOD, { parse: parseRenameRequest }, (ctx) => requiredAgent(agent).renameSession(ctx.params)).onRequest(GOAL_CONTROL_METHOD, { parse: parseGoalRequest }, (ctx) => requiredAgent(agent).goal(ctx.params));
67081
+ }).onRequest(methods2.agent.initialize, (ctx) => requiredAgent(agent).initialize(ctx.params)).onRequest(methods2.agent.session.new, (ctx) => requiredAgent(agent).newSession(ctx.params)).onRequest(methods2.agent.session.load, (ctx) => requiredAgent(agent).loadSession(ctx.params, ctx.signal)).onRequest(methods2.agent.session.fork, (ctx) => requiredAgent(agent).unstable_forkSession(ctx.params, ctx.signal)).onRequest(methods2.agent.session.list, (ctx) => requiredAgent(agent).listSessions(ctx.params, ctx.signal)).onRequest(methods2.agent.session.delete, (ctx) => requiredAgent(agent).deleteSession(ctx.params)).onRequest(methods2.agent.session.resume, (ctx) => requiredAgent(agent).resumeSession(ctx.params)).onRequest(methods2.agent.session.close, (ctx) => requiredAgent(agent).closeSession(ctx.params)).onRequest(methods2.agent.session.setMode, (ctx) => requiredAgent(agent).setSessionMode(ctx.params)).onRequest(methods2.agent.session.setConfigOption, (ctx) => requiredAgent(agent).setSessionConfigOption(ctx.params)).onRequest(methods2.agent.authenticate, (ctx) => requiredAgent(agent).authenticate(ctx.params)).onRequest(methods2.agent.providers.list, (ctx) => requiredAgent(agent).unstable_listProviders(ctx.params)).onRequest(methods2.agent.providers.set, (ctx) => requiredAgent(agent).unstable_setProvider(ctx.params)).onRequest(methods2.agent.providers.disable, (ctx) => requiredAgent(agent).unstable_disableProvider(ctx.params)).onRequest(methods2.agent.logout, (ctx) => requiredAgent(agent).logout(ctx.params)).onRequest(methods2.agent.session.prompt, (ctx) => runPromptWithCancellation(requiredAgent(agent), ctx.params, ctx.signal)).onNotification(methods2.agent.session.cancel, (ctx) => requiredAgent(agent).cancel(ctx.params)).onRequest(STEER_METHOD, { parse: parseSteerRequest }, (ctx) => requiredAgent(agent).steer(ctx.params)).onRequest(RENAME_METHOD, { parse: parseRenameRequest }, (ctx) => requiredAgent(agent).renameSession(ctx.params)).onRequest(GOAL_CONTROL_METHOD, { parse: parseGoalRequest }, (ctx) => requiredAgent(agent).goal(ctx.params));
66864
67082
  return { agent: () => agent, app };
66865
67083
  }
66866
67084
  function requiredAgent(agent) {
@@ -67028,26 +67246,26 @@ var init_acp_agent = __esm({
67028
67246
  if (this.onSessionUpdate !== void 0) {
67029
67247
  return this.onSessionUpdate(params);
67030
67248
  }
67031
- return this.ctx.notify(methods.client.session.update, params);
67249
+ return this.ctx.notify(methods2.client.session.update, params);
67032
67250
  }
67033
67251
  requestPermission(params, signal) {
67034
- return this.ctx.request(methods.client.session.requestPermission, params, {
67252
+ return this.ctx.request(methods2.client.session.requestPermission, params, {
67035
67253
  cancellationSignal: signal
67036
67254
  });
67037
67255
  }
67038
67256
  readTextFile(params) {
67039
- return this.ctx.request(methods.client.fs.readTextFile, params);
67257
+ return this.ctx.request(methods2.client.fs.readTextFile, params);
67040
67258
  }
67041
67259
  writeTextFile(params) {
67042
- return this.ctx.request(methods.client.fs.writeTextFile, params);
67260
+ return this.ctx.request(methods2.client.fs.writeTextFile, params);
67043
67261
  }
67044
67262
  createElicitation(params, signal) {
67045
- return this.ctx.request(methods.client.elicitation.create, params, {
67263
+ return this.ctx.request(methods2.client.elicitation.create, params, {
67046
67264
  cancellationSignal: signal
67047
67265
  });
67048
67266
  }
67049
67267
  completeElicitation(params) {
67050
- return this.ctx.notify(methods.client.elicitation.complete, params);
67268
+ return this.ctx.notify(methods2.client.elicitation.complete, params);
67051
67269
  }
67052
67270
  extNotification(method, params) {
67053
67271
  return this.ctx.notify(method, params);
@@ -67377,13 +67595,13 @@ var init_acp_agent = __esm({
67377
67595
  */
67378
67596
  async unstable_setProvider(params) {
67379
67597
  if (params.providerId !== PROVIDER_ID) {
67380
- throw RequestError3.invalidParams({ providerId: params.providerId }, `Unknown provider ID "${params.providerId}"; expected "${PROVIDER_ID}".`);
67598
+ throw RequestError4.invalidParams({ providerId: params.providerId }, `Unknown provider ID "${params.providerId}"; expected "${PROVIDER_ID}".`);
67381
67599
  }
67382
67600
  if (!SUPPORTED_PROTOCOLS.includes(params.apiType)) {
67383
- throw RequestError3.invalidParams({ apiType: params.apiType, supported: SUPPORTED_PROTOCOLS }, `Unsupported apiType "${params.apiType}" for provider "${PROVIDER_ID}".`);
67601
+ throw RequestError4.invalidParams({ apiType: params.apiType, supported: SUPPORTED_PROTOCOLS }, `Unsupported apiType "${params.apiType}" for provider "${PROVIDER_ID}".`);
67384
67602
  }
67385
67603
  if (!isValidBaseUrl(params.baseUrl)) {
67386
- throw RequestError3.invalidParams({ baseUrl: params.baseUrl }, "baseUrl must be a non-empty absolute http(s) URL.");
67604
+ throw RequestError4.invalidParams({ baseUrl: params.baseUrl }, "baseUrl must be a non-empty absolute http(s) URL.");
67387
67605
  }
67388
67606
  const config2 = {
67389
67607
  apiType: params.apiType,
@@ -67393,7 +67611,7 @@ var init_acp_agent = __esm({
67393
67611
  if (params.apiType === "vertex") {
67394
67612
  const vertex = params._meta?.claudeCode?.vertex;
67395
67613
  if (!vertex || typeof vertex.projectId !== "string" || vertex.projectId.trim() === "" || typeof vertex.region !== "string" || vertex.region.trim() === "") {
67396
- throw RequestError3.invalidParams(void 0, "vertex apiType requires non-empty `_meta.claudeCode.vertex.projectId` and `_meta.claudeCode.vertex.region`.");
67614
+ throw RequestError4.invalidParams(void 0, "vertex apiType requires non-empty `_meta.claudeCode.vertex.projectId` and `_meta.claudeCode.vertex.region`.");
67397
67615
  }
67398
67616
  config2.vertex = { projectId: vertex.projectId, region: vertex.region };
67399
67617
  }
@@ -67449,7 +67667,7 @@ var init_acp_agent = __esm({
67449
67667
  await execFileAsync(cliPath, ["auth", "logout"]);
67450
67668
  } catch (error62) {
67451
67669
  const stderr = typeof error62 === "object" && error62 && "stderr" in error62 ? String(error62.stderr).trim() : void 0;
67452
- throw RequestError3.internalError({ stderr: stderr || void 0 }, `claude auth logout failed: ${error62 instanceof Error ? error62.message : String(error62)}`);
67670
+ throw RequestError4.internalError({ stderr: stderr || void 0 }, `claude auth logout failed: ${error62 instanceof Error ? error62.message : String(error62)}`);
67453
67671
  }
67454
67672
  }
67455
67673
  async prompt(params) {
@@ -67461,7 +67679,7 @@ var init_acp_agent = __esm({
67461
67679
  throw new Error("Session not found");
67462
67680
  }
67463
67681
  if (session.queryClosed) {
67464
- throw RequestError3.internalError(void 0, SESSION_ENDED_MESSAGE);
67682
+ throw RequestError4.internalError(void 0, SESSION_ENDED_MESSAGE);
67465
67683
  }
67466
67684
  if (session.autoModeFallbackWarningPending) {
67467
67685
  await this.sessionModes.publishFallbackWarning(params.sessionId, session);
@@ -67601,7 +67819,7 @@ var init_acp_agent = __esm({
67601
67819
  throw new Error("Session not found");
67602
67820
  }
67603
67821
  if (session.queryClosed) {
67604
- throw RequestError3.internalError(void 0, SESSION_ENDED_MESSAGE);
67822
+ throw RequestError4.internalError(void 0, SESSION_ENDED_MESSAGE);
67605
67823
  }
67606
67824
  const turnInFlight = (session.turnQueue ?? []).find((turn) => !turn.settled);
67607
67825
  if (!turnInFlight) {
@@ -67932,7 +68150,7 @@ var init_acp_agent = __esm({
67932
68150
  for (const queued of [...session.turnQueue ?? []]) {
67933
68151
  if (!queued.settled) {
67934
68152
  queued.settled = true;
67935
- queued.reject(RequestError3.internalError(void 0, SESSION_ENDED_MESSAGE));
68153
+ queued.reject(RequestError4.internalError(void 0, SESSION_ENDED_MESSAGE));
67936
68154
  }
67937
68155
  }
67938
68156
  session.turnQueue = [];
@@ -68081,16 +68299,15 @@ var init_acp_agent = __esm({
68081
68299
  session.lastSessionState = message.state;
68082
68300
  if (message.state === "idle") {
68083
68301
  disarmResultWatchdog();
68302
+ const boundary = session.idleBoundary;
68303
+ const hadEarlierResult = boundary.kind === "accounted" && boundary.turn !== session.activeTurn;
68304
+ session.idleBoundary = { kind: "unaccounted" };
68084
68305
  if (session.cancelled && session.activeTurn && !session.activeTurn.settled) {
68085
68306
  settleActive(turnOutcome(session, "cancelled"));
68086
68307
  session.emittedAssistantText = false;
68087
68308
  } else if (isHeldOpen(session.activeTurn)) {
68088
- if (session.owedTrailingIdles > 0) {
68089
- session.owedTrailingIdles--;
68090
- }
68091
68309
  settleDeferredIfDrained();
68092
- } else if (session.owedTrailingIdles > 0) {
68093
- session.owedTrailingIdles--;
68310
+ } else if (hadEarlierResult) {
68094
68311
  } else if (isSteering(session.activeTurn)) {
68095
68312
  const steered = session.activeTurn;
68096
68313
  if (steered.steeredEchoes?.size === 0 && steered.steeredSettle !== void 0) {
@@ -68099,9 +68316,9 @@ var init_acp_agent = __esm({
68099
68316
  steered.steeredSettle = void 0;
68100
68317
  settleDeferredIfDrained();
68101
68318
  }
68102
- } else if (!session.cancelled && session.activeTurn && !session.activeTurn.settled) {
68319
+ } else if (boundary.kind === "unaccounted" && !session.cancelled && session.activeTurn && !session.activeTurn.settled) {
68103
68320
  this.logger.error(`Session ${params.sessionId}: SDK went idle without emitting a result for the active turn; failing the in-flight prompt (issue #825)`);
68104
- failActive(RequestError3.internalError(errorKindData("no_result"), TURN_NO_RESULT_MESSAGE));
68321
+ failActive(RequestError4.internalError(errorKindData("no_result"), TURN_NO_RESULT_MESSAGE));
68105
68322
  }
68106
68323
  await session.titles.onTurnEnd(session);
68107
68324
  }
@@ -68360,9 +68577,8 @@ ${message.api_refusal_explanation}` : "";
68360
68577
  }
68361
68578
  }
68362
68579
  const deliveredAssistantText = session.emittedAssistantText;
68363
- const owesTrailingIdle = isAutonomousResult || !isSteering(session.activeTurn);
68364
- if (owesTrailingIdle && (isAutonomousResult || !session.cancelled || !session.activeTurn)) {
68365
- session.owedTrailingIdles++;
68580
+ if (isAutonomousResult || !session.cancelled || !session.activeTurn) {
68581
+ session.idleBoundary = { kind: "accounted", turn: session.activeTurn ?? null };
68366
68582
  }
68367
68583
  if (!isAutonomousResult) {
68368
68584
  session.accumulatedUsage.inputTokens += message.usage.input_tokens;
@@ -68457,7 +68673,7 @@ ${message.api_refusal_explanation}` : "";
68457
68673
  break;
68458
68674
  }
68459
68675
  if (message.is_error) {
68460
- failActive(RequestError3.internalError(errorKindData(lastAssistantError), message.result));
68676
+ failActive(RequestError4.internalError(errorKindData(lastAssistantError), message.result));
68461
68677
  break;
68462
68678
  }
68463
68679
  if (session.activeTurn?.isLocalOnlyCommand || !deliveredAssistantText && (message.usage.output_tokens ?? 0) === 0) {
@@ -68473,7 +68689,7 @@ ${message.api_refusal_explanation}` : "";
68473
68689
  break;
68474
68690
  }
68475
68691
  if (message.is_error) {
68476
- failActive(RequestError3.internalError(errorKindData(lastAssistantError), message.errors.join(", ") || message.subtype));
68692
+ failActive(RequestError4.internalError(errorKindData(lastAssistantError), message.errors.join(", ") || message.subtype));
68477
68693
  break;
68478
68694
  }
68479
68695
  stopReason = "end_turn";
@@ -68483,7 +68699,7 @@ ${message.api_refusal_explanation}` : "";
68483
68699
  case "error_max_turns":
68484
68700
  case "error_max_structured_output_retries":
68485
68701
  if (message.is_error) {
68486
- failActive(RequestError3.internalError(errorKindData(lastAssistantError), message.errors.join(", ") || message.subtype));
68702
+ failActive(RequestError4.internalError(errorKindData(lastAssistantError), message.errors.join(", ") || message.subtype));
68487
68703
  break;
68488
68704
  }
68489
68705
  stopReason = "max_turn_requests";
@@ -68624,12 +68840,18 @@ ${message.api_refusal_explanation}` : "";
68624
68840
  if (session.activeTurn !== queued) {
68625
68841
  if (session.activeTurn) {
68626
68842
  if (session.cancelled) {
68627
- session.owedTrailingIdles++;
68843
+ session.idleBoundary = {
68844
+ kind: "accounted",
68845
+ turn: session.activeTurn ?? null
68846
+ };
68628
68847
  settleActive(turnOutcome(session, "cancelled"));
68629
68848
  } else if (isHeldOpen(session.activeTurn)) {
68630
68849
  settleActive(session.activeTurn.deferredSettle);
68631
68850
  } else if (isSteering(session.activeTurn) && session.activeTurn.steeredSettle !== void 0) {
68632
- session.owedTrailingIdles++;
68851
+ session.idleBoundary = {
68852
+ kind: "accounted",
68853
+ turn: session.activeTurn ?? null
68854
+ };
68633
68855
  settleActive(session.activeTurn.steeredSettle);
68634
68856
  } else {
68635
68857
  settleActive(turnOutcome(session, "end_turn"));
@@ -68640,8 +68862,8 @@ ${message.api_refusal_explanation}` : "";
68640
68862
  break;
68641
68863
  }
68642
68864
  if ("isReplay" in message && message.isReplay) {
68643
- if (isSteering(session.activeTurn)) {
68644
- session.activeTurn.steeredEchoes.delete(message.uuid);
68865
+ if (isSteering(session.activeTurn) && session.activeTurn.steeredEchoes.delete(message.uuid)) {
68866
+ session.activeTurn.steeredSettle = void 0;
68645
68867
  }
68646
68868
  break;
68647
68869
  }
@@ -68695,7 +68917,7 @@ ${message.api_refusal_explanation}` : "";
68695
68917
  break;
68696
68918
  }
68697
68919
  if (message.type === "assistant" && message.error === "authentication_failed") {
68698
- failActive(RequestError3.authRequired(errorKindData(message.error)));
68920
+ failActive(RequestError4.authRequired(errorKindData(message.error)));
68699
68921
  break;
68700
68922
  }
68701
68923
  let content;
@@ -68820,7 +69042,7 @@ ${message.api_refusal_explanation}` : "";
68820
69042
  const processDied = error62 instanceof Error && (message.includes("ProcessTransport") || message.includes("terminated process") || message.includes("process exited with") || message.includes("process terminated by signal") || message.includes("Failed to write to process stdin"));
68821
69043
  if (processDied) {
68822
69044
  this.logger.error(`Session ${params.sessionId}: Claude Agent process died: ${message}`);
68823
- failAllTurns(RequestError3.internalError(void 0, "The Claude Agent process exited unexpectedly. Please start a new session."));
69045
+ failAllTurns(RequestError4.internalError(void 0, "The Claude Agent process exited unexpectedly. Please start a new session."));
68824
69046
  this.closeQueryStream(session);
68825
69047
  delete this.sessions[params.sessionId];
68826
69048
  } else {
@@ -68906,7 +69128,7 @@ ${message.api_refusal_explanation}` : "";
68906
69128
  session.activeTurn = null;
68907
69129
  session.emittedAssistantText = false;
68908
69130
  if (session.lastSessionState !== "idle") {
68909
- session.owedTrailingIdles++;
69131
+ session.idleBoundary = { kind: "accounted", turn: active };
68910
69132
  }
68911
69133
  active.resolve({
68912
69134
  stopReason: "cancelled",
@@ -68916,7 +69138,7 @@ ${message.api_refusal_explanation}` : "";
68916
69138
  }
68917
69139
  }
68918
69140
  if (isSteering(session.activeTurn) && session.activeTurn.steeredSettle !== void 0) {
68919
- session.owedTrailingIdles++;
69141
+ session.idleBoundary = { kind: "accounted", turn: session.activeTurn ?? null };
68920
69142
  }
68921
69143
  if (session.activeTurn && session.cancelController && !session.cancelController.signal.aborted && !session.forceCancelTimer) {
68922
69144
  const cancelController = session.cancelController;
@@ -69025,7 +69247,7 @@ ${message.api_refusal_explanation}` : "";
69025
69247
  throw new Error("Session not found");
69026
69248
  }
69027
69249
  if (session.queryClosed) {
69028
- throw RequestError3.internalError(void 0, SESSION_ENDED_MESSAGE);
69250
+ throw RequestError4.internalError(void 0, SESSION_ENDED_MESSAGE);
69029
69251
  }
69030
69252
  const option = session.configOptions.find((o) => o.id === params.configId);
69031
69253
  if (!option) {
@@ -69621,16 +69843,16 @@ ${message.api_refusal_explanation}` : "";
69621
69843
  */
69622
69844
  async validateCwd(cwd) {
69623
69845
  if (!path6.isAbsolute(cwd)) {
69624
- throw RequestError3.invalidParams({ cwd }, `\`cwd\` must be an absolute path, but received: ${cwd}`);
69846
+ throw RequestError4.invalidParams({ cwd }, `\`cwd\` must be an absolute path, but received: ${cwd}`);
69625
69847
  }
69626
69848
  let stats;
69627
69849
  try {
69628
69850
  stats = await fs4.stat(cwd);
69629
69851
  } catch {
69630
- throw RequestError3.invalidParams({ cwd }, `\`cwd\` does not exist on the machine running the agent: ${cwd}`);
69852
+ throw RequestError4.invalidParams({ cwd }, `\`cwd\` does not exist on the machine running the agent: ${cwd}`);
69631
69853
  }
69632
69854
  if (!stats.isDirectory()) {
69633
- throw RequestError3.invalidParams({ cwd }, `\`cwd\` is not a directory: ${cwd}`);
69855
+ throw RequestError4.invalidParams({ cwd }, `\`cwd\` is not a directory: ${cwd}`);
69634
69856
  }
69635
69857
  }
69636
69858
  async createSession(params, creationOpts = {}) {
@@ -69853,12 +70075,12 @@ ${message.api_refusal_explanation}` : "";
69853
70075
  initializationResult = await q2.initializationResult();
69854
70076
  } catch (error62) {
69855
70077
  if (creationOpts.resume && error62 instanceof Error && (error62.message === "Query closed before response received" || error62.message.includes("No conversation found with session ID"))) {
69856
- throw RequestError3.resourceNotFound(sessionId);
70078
+ throw RequestError4.resourceNotFound(sessionId);
69857
70079
  }
69858
70080
  throw error62;
69859
70081
  }
69860
70082
  if (shouldHideClaudeAuth() && initializationResult.account.subscriptionType && !this.gatewayAuthRequest) {
69861
- throw RequestError3.authRequired(void 0, "This integration does not support using claude.ai subscriptions.");
70083
+ throw RequestError4.authRequired(void 0, "This integration does not support using claude.ai subscriptions.");
69862
70084
  }
69863
70085
  const settingsAvailableModels = settingsManager.getSettings().availableModels;
69864
70086
  const settingsModelOverrides = settingsManager.getSettings().modelOverrides;
@@ -69934,7 +70156,7 @@ ${message.api_refusal_explanation}` : "";
69934
70156
  emittedToolCalls: /* @__PURE__ */ new Set(),
69935
70157
  liveBackgroundTasks: /* @__PURE__ */ new Map(),
69936
70158
  emittedAssistantText: false,
69937
- owedTrailingIdles: 0,
70159
+ idleBoundary: { kind: "unaccounted" },
69938
70160
  messageIdToUuid: /* @__PURE__ */ new Map()
69939
70161
  };
69940
70162
  return {
@@ -70081,6 +70303,28 @@ var init_endpoint = __esm({
70081
70303
  }
70082
70304
  });
70083
70305
 
70306
+ // src/acp/adapter/claude/agent-connection.ts
70307
+ var ClaudeAgentConnection;
70308
+ var init_agent_connection = __esm({
70309
+ "src/acp/adapter/claude/agent-connection.ts"() {
70310
+ "use strict";
70311
+ init_endpoint_agent_connection();
70312
+ init_endpoint();
70313
+ ClaudeAgentConnection = class extends EndpointAgentConnection {
70314
+ constructor(options) {
70315
+ const endpoint = new ClaudeAcpEndpoint({
70316
+ command: options.command,
70317
+ cwd: options.cwd,
70318
+ environment: options.environment,
70319
+ onSessionUpdate: options.client.onUpdate,
70320
+ onBackgroundActivity: (active) => options.onBackgroundActivity?.(active)
70321
+ });
70322
+ super(endpoint, options.client);
70323
+ }
70324
+ };
70325
+ }
70326
+ });
70327
+
70084
70328
  // src/util/filesystem/path-error.ts
70085
70329
  var LocalPathError;
70086
70330
  var init_path_error = __esm({
@@ -71025,7 +71269,7 @@ var init_version_output = __esm({
71025
71269
  });
71026
71270
 
71027
71271
  // src/agent/specification/agent-specification.ts
71028
- var VERSION_PROBE_TIMEOUT_MILLISECONDS, ACP_PROBE_TIMEOUT_MILLISECONDS, LocalAgentSpecification, DirectAcpAgentSpecification, InProcessAcpAgentSpecification;
71272
+ var VERSION_PROBE_TIMEOUT_MILLISECONDS, ACP_PROBE_TIMEOUT_MILLISECONDS, LocalAgentSpecification, InProcessAcpAgentSpecification;
71029
71273
  var init_agent_specification = __esm({
71030
71274
  "src/agent/specification/agent-specification.ts"() {
71031
71275
  "use strict";
@@ -71047,17 +71291,6 @@ var init_agent_specification = __esm({
71047
71291
  resolveInstalledAgentExecutables = (_context) => Promise.resolve([]);
71048
71292
  verifyAcp = (_connection, _initialized, _defaultWorkspace, _signal) => Promise.resolve();
71049
71293
  };
71050
- DirectAcpAgentSpecification = class extends LocalAgentSpecification {
71051
- adapterOverrideVariable;
71052
- agentOverrideVariable;
71053
- launchArguments;
71054
- constructor(executableOverrideVariable, launchArguments) {
71055
- super();
71056
- this.adapterOverrideVariable = executableOverrideVariable;
71057
- this.agentOverrideVariable = executableOverrideVariable;
71058
- this.launchArguments = Object.freeze([...launchArguments]);
71059
- }
71060
- };
71061
71294
  InProcessAcpAgentSpecification = class extends LocalAgentSpecification {
71062
71295
  launchArguments = Object.freeze([]);
71063
71296
  adapterOverrideVariable;
@@ -71077,13 +71310,13 @@ var ClaudeCodeAgentSpecification;
71077
71310
  var init_claude_code_agent = __esm({
71078
71311
  "src/agent/specification/vendors/claude-code-agent.ts"() {
71079
71312
  "use strict";
71080
- init_endpoint();
71313
+ init_agent_connection();
71081
71314
  init_platform();
71082
71315
  init_executable();
71083
71316
  init_agent_specification();
71084
71317
  ClaudeCodeAgentSpecification = class extends InProcessAcpAgentSpecification {
71085
71318
  agentExecutable = "claude";
71086
- createEndpoint = (options) => new ClaudeAcpEndpoint(options);
71319
+ createConnection = (options) => new ClaudeAgentConnection(options);
71087
71320
  id = "claude";
71088
71321
  label = "Claude Code";
71089
71322
  minimumSupportedAgentVersion = "2.1.273";
@@ -71109,76 +71342,6 @@ var init_claude_code_agent = __esm({
71109
71342
  }
71110
71343
  });
71111
71344
 
71112
- // src/infra/operation-error.ts
71113
- function operationErrorCode(error62) {
71114
- return error62 instanceof OperationError ? error62.code : "session_operation_failed";
71115
- }
71116
- function operationErrorMessage(error62) {
71117
- return error62 instanceof OperationError ? error62.message : "The local agent operation could not be completed";
71118
- }
71119
- var OperationError;
71120
- var init_operation_error = __esm({
71121
- "src/infra/operation-error.ts"() {
71122
- "use strict";
71123
- OperationError = class extends Error {
71124
- code;
71125
- constructor(code, message, options = {}) {
71126
- super(message, options);
71127
- this.code = code;
71128
- }
71129
- };
71130
- }
71131
- });
71132
-
71133
- // src/acp/acp-error.ts
71134
- var AcpExecutionError, AcpConfigurationValueUnavailableError;
71135
- var init_acp_error = __esm({
71136
- "src/acp/acp-error.ts"() {
71137
- "use strict";
71138
- init_operation_error();
71139
- AcpExecutionError = class extends OperationError {
71140
- constructor(message, options = {}, code = "acp_execution_failed") {
71141
- super(code, message, options);
71142
- this.name = "AcpExecutionError";
71143
- }
71144
- };
71145
- AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
71146
- configId;
71147
- offeredValueCount;
71148
- offeredValues;
71149
- requestedValue;
71150
- constructor(configId, requestedValue, offeredValues) {
71151
- super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
71152
- this.name = "AcpConfigurationValueUnavailableError";
71153
- this.configId = configId.slice(0, 128);
71154
- this.requestedValue = requestedValue.slice(0, 128);
71155
- this.offeredValueCount = offeredValues.length;
71156
- this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
71157
- }
71158
- };
71159
- }
71160
- });
71161
-
71162
- // src/acp/agent/in-process-endpoint.ts
71163
- function acpEndpointTerminationError(termination) {
71164
- switch (termination.kind) {
71165
- case "failed":
71166
- return termination.error;
71167
- case "closed":
71168
- return new AcpExecutionError("The ACP endpoint is closed", {}, "acp_endpoint_closed");
71169
- default: {
71170
- const unreachable3 = termination;
71171
- return unreachable3;
71172
- }
71173
- }
71174
- }
71175
- var init_in_process_endpoint = __esm({
71176
- "src/acp/agent/in-process-endpoint.ts"() {
71177
- "use strict";
71178
- init_acp_error();
71179
- }
71180
- });
71181
-
71182
71345
  // src/acp/harness/codex/app-server-protocol.ts
71183
71346
  import { isAbsolute as isAbsolute8 } from "node:path";
71184
71347
  function decodeAppServerMessage(value) {
@@ -71741,7 +71904,7 @@ var init_app_server_client = __esm({
71741
71904
 
71742
71905
  // src/acp/harness/codex/items.ts
71743
71906
  import { pathToFileURL } from "node:url";
71744
- function truncate(value, limit) {
71907
+ function truncate2(value, limit) {
71745
71908
  return value.length <= limit ? value : value.slice(0, limit);
71746
71909
  }
71747
71910
  function boundedParagraphs(values, limit) {
@@ -71757,7 +71920,7 @@ function boundedParagraphs(values, limit) {
71757
71920
  return text2;
71758
71921
  }
71759
71922
  function textContent(text2) {
71760
- const block = { text: truncate(text2, TOOL_OUTPUT_CHARACTER_LIMIT), type: "text" };
71923
+ const block = { text: truncate2(text2, TOOL_OUTPUT_CHARACTER_LIMIT), type: "text" };
71761
71924
  return { content: block, type: "content" };
71762
71925
  }
71763
71926
  function structuredToolText(value) {
@@ -71846,16 +72009,16 @@ function presentToolItem(item) {
71846
72009
  rawInput: { command: item.command, cwd: item.cwd },
71847
72010
  rawOutput: {
71848
72011
  ...item.exitCode == null ? {} : { exitCode: item.exitCode },
71849
- output: truncate(output2, TOOL_OUTPUT_CHARACTER_LIMIT)
72012
+ output: truncate2(output2, TOOL_OUTPUT_CHARACTER_LIMIT)
71850
72013
  },
71851
72014
  status: commandStatus(item.status),
71852
- title: truncate(firstLine(item.command), TITLE_CHARACTER_LIMIT)
72015
+ title: truncate2(firstLine(item.command), TITLE_CHARACTER_LIMIT)
71853
72016
  };
71854
72017
  }
71855
72018
  if (item.type === "fileChange") {
71856
72019
  const paths = item.changes.map((change) => change.path);
71857
72020
  const content = item.changes.map((change) => ({
71858
- newText: truncate(change.diff, TOOL_OUTPUT_CHARACTER_LIMIT),
72021
+ newText: truncate2(change.diff, TOOL_OUTPUT_CHARACTER_LIMIT),
71859
72022
  path: change.path,
71860
72023
  type: "diff"
71861
72024
  }));
@@ -71866,7 +72029,7 @@ function presentToolItem(item) {
71866
72029
  rawInput: { changes: item.changes.map((change) => change.path) },
71867
72030
  rawOutput: null,
71868
72031
  status: patchStatus(item.status),
71869
- title: truncate(paths.join(", "), TITLE_CHARACTER_LIMIT)
72032
+ title: truncate2(paths.join(", "), TITLE_CHARACTER_LIMIT)
71870
72033
  };
71871
72034
  }
71872
72035
  if (item.type === "mcpToolCall") {
@@ -71879,7 +72042,7 @@ function presentToolItem(item) {
71879
72042
  rawInput: item.arguments ?? null,
71880
72043
  rawOutput: item.error ?? item.result ?? null,
71881
72044
  status: mcpStatus(item.status),
71882
- title: truncate(label, TITLE_CHARACTER_LIMIT)
72045
+ title: truncate2(label, TITLE_CHARACTER_LIMIT)
71883
72046
  };
71884
72047
  }
71885
72048
  if (item.type === "dynamicToolCall") {
@@ -71892,16 +72055,16 @@ function presentToolItem(item) {
71892
72055
  rawInput: item.arguments ?? null,
71893
72056
  rawOutput: item.contentItems ?? null,
71894
72057
  status: mcpStatus(item.status),
71895
- title: truncate(label, TITLE_CHARACTER_LIMIT)
72058
+ title: truncate2(label, TITLE_CHARACTER_LIMIT)
71896
72059
  };
71897
72060
  }
71898
72061
  if (item.type === "collabAgentToolCall") {
71899
- const spawn10 = item.tool === "spawnAgent";
72062
+ const spawn8 = item.tool === "spawnAgent";
71900
72063
  return {
71901
72064
  content: [],
71902
72065
  kind: "other",
71903
72066
  locations: [],
71904
- rawInput: spawn10 ? {
72067
+ rawInput: spawn8 ? {
71905
72068
  model: item.model,
71906
72069
  prompt: item.prompt,
71907
72070
  reasoningEffort: item.reasoningEffort,
@@ -71909,10 +72072,10 @@ function presentToolItem(item) {
71909
72072
  } : { receiverThreadIds: item.receiverThreadIds, senderThreadId: item.senderThreadId },
71910
72073
  rawOutput: {
71911
72074
  agentsStates: item.agentsStates,
71912
- ...spawn10 ? { receiverThreadIds: item.receiverThreadIds } : {}
72075
+ ...spawn8 ? { receiverThreadIds: item.receiverThreadIds } : {}
71913
72076
  },
71914
72077
  status: collaborationStatus(item.status),
71915
- title: spawn10 ? "Dispatch subagent" : "Wait for subagent"
72078
+ title: spawn8 ? "Dispatch subagent" : "Wait for subagent"
71916
72079
  };
71917
72080
  }
71918
72081
  if (item.type === "subAgentActivity" && item.kind === "started") {
@@ -71923,7 +72086,7 @@ function presentToolItem(item) {
71923
72086
  rawInput: { agentPath: item.agentPath },
71924
72087
  rawOutput: { agentThreadId: item.agentThreadId },
71925
72088
  status: "in_progress",
71926
- title: truncate(`Dispatch subagent ${item.agentPath}`, TITLE_CHARACTER_LIMIT)
72089
+ title: truncate2(`Dispatch subagent ${item.agentPath}`, TITLE_CHARACTER_LIMIT)
71927
72090
  };
71928
72091
  }
71929
72092
  return null;
@@ -72533,7 +72696,7 @@ var init_history_images = __esm({
72533
72696
  // src/acp/harness/codex/owned-agent.ts
72534
72697
  import { randomUUID as randomUUID6 } from "node:crypto";
72535
72698
  import { setTimeout as delay } from "node:timers/promises";
72536
- import { methods as methods2 } from "@agentclientprotocol/sdk";
72699
+ import { methods as methods3 } from "@agentclientprotocol/sdk";
72537
72700
  function permissionDecision(optionId) {
72538
72701
  if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
72539
72702
  return optionId;
@@ -72787,7 +72950,7 @@ var init_owned_agent = __esm({
72787
72950
  if (connection === null || this.#context.threadId().length === 0) {
72788
72951
  return;
72789
72952
  }
72790
- await connection.client.notify(methods2.client.session.update, {
72953
+ await connection.client.notify(methods3.client.session.update, {
72791
72954
  sessionId: this.#context.threadId(),
72792
72955
  update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
72793
72956
  });
@@ -73012,7 +73175,7 @@ var init_owned_agent = __esm({
73012
73175
  return "cancel";
73013
73176
  }
73014
73177
  const response = await connection.client.request(
73015
- methods2.client.session.requestPermission,
73178
+ methods3.client.session.requestPermission,
73016
73179
  {
73017
73180
  options: [...APPROVAL_OPTIONS],
73018
73181
  sessionId: this.#context.threadId(),
@@ -73049,7 +73212,7 @@ var init_owned_agent = __esm({
73049
73212
  }
73050
73213
  const questions = decoded.data.questions;
73051
73214
  const response = await connection.client.request(
73052
- methods2.client.elicitation.create,
73215
+ methods3.client.elicitation.create,
73053
73216
  {
73054
73217
  message: questions.map((question) => question.question).join("\n\n").slice(0, 2e3),
73055
73218
  mode: "form",
@@ -73078,7 +73241,7 @@ var init_owned_agent = __esm({
73078
73241
  const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS);
73079
73242
  if (params.mode === "url" && params.url !== void 0) {
73080
73243
  const response2 = await connection.client.request(
73081
- methods2.client.elicitation.create,
73244
+ methods3.client.elicitation.create,
73082
73245
  {
73083
73246
  elicitationId: `${this.#context.threadId()}-${String(request.id)}`,
73084
73247
  message: params.message,
@@ -73092,7 +73255,7 @@ var init_owned_agent = __esm({
73092
73255
  return;
73093
73256
  }
73094
73257
  const response = await connection.client.request(
73095
- methods2.client.elicitation.create,
73258
+ methods3.client.elicitation.create,
73096
73259
  {
73097
73260
  message: params.message,
73098
73261
  mode: "form",
@@ -73447,7 +73610,7 @@ var init_directory = __esm({
73447
73610
  });
73448
73611
 
73449
73612
  // ../mobius-sdk/src/protocol/shared/message-codec.ts
73450
- function isRecord2(value) {
73613
+ function isRecord3(value) {
73451
73614
  return typeof value === "object" && value !== null && !Array.isArray(value);
73452
73615
  }
73453
73616
  function parseJson(encoded) {
@@ -73459,12 +73622,12 @@ function parseJson(encoded) {
73459
73622
  cause: error62
73460
73623
  });
73461
73624
  }
73462
- if (!isRecord2(value)) {
73625
+ if (!isRecord3(value)) {
73463
73626
  throw new ProtocolMessageError("Message must be a JSON object");
73464
73627
  }
73465
73628
  return value;
73466
73629
  }
73467
- function readString(value, key, maximumLength) {
73630
+ function readString2(value, key, maximumLength) {
73468
73631
  const field = value[key];
73469
73632
  if (typeof field !== "string" || field.length === 0 || field.length > maximumLength) {
73470
73633
  throw new ProtocolMessageError(`Invalid string field: ${key}`);
@@ -73502,7 +73665,7 @@ function readIdentifier(value, key) {
73502
73665
  }
73503
73666
  }
73504
73667
  function readDirectoryIdentifier(value, key) {
73505
- const field = readString(value, key, MAX_DIRECTORY_IDENTIFIER_LENGTH);
73668
+ const field = readString2(value, key, MAX_DIRECTORY_IDENTIFIER_LENGTH);
73506
73669
  if (!isDirectoryIdentifier(field)) {
73507
73670
  throw new ProtocolMessageError(`Invalid directory identifier field: ${key}`);
73508
73671
  }
@@ -73514,7 +73677,7 @@ function assertKind(value, expectedKind) {
73514
73677
  }
73515
73678
  }
73516
73679
  function decodeMessageKind(encoded) {
73517
- return readString(parseJson(encoded), "kind", 64);
73680
+ return readString2(parseJson(encoded), "kind", 64);
73518
73681
  }
73519
73682
  function decodeZodMessage(encoded, schema) {
73520
73683
  const result = schema.safeParse(parseJson(encoded));
@@ -76393,7 +76556,7 @@ var init_settings3 = __esm({
76393
76556
  // src/acp/harness/codex/agent.ts
76394
76557
  import {
76395
76558
  agent as createAgentApp,
76396
- methods as methods3,
76559
+ methods as methods4,
76397
76560
  PROTOCOL_VERSION
76398
76561
  } from "@agentclientprotocol/sdk";
76399
76562
  function promptInput(prompt) {
@@ -76492,7 +76655,7 @@ var init_agent = __esm({
76492
76655
  });
76493
76656
  this.#app = createAgentApp({ name: "mobius-codex" }).onConnect((connection) => {
76494
76657
  this.#connection = connection;
76495
- }).onRequest(methods3.agent.initialize, async () => ({
76658
+ }).onRequest(methods4.agent.initialize, async () => ({
76496
76659
  _meta: { steering: { supported: true } },
76497
76660
  agentCapabilities: {
76498
76661
  loadSession: true,
@@ -76502,7 +76665,7 @@ var init_agent = __esm({
76502
76665
  agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
76503
76666
  authMethods: [],
76504
76667
  protocolVersion: PROTOCOL_VERSION
76505
- })).onRequest(methods3.agent.session.new, async (context) => {
76668
+ })).onRequest(methods4.agent.session.new, async (context) => {
76506
76669
  const created = threadStartResponseSchema.parse(
76507
76670
  await this.#appServer.request(
76508
76671
  "thread/start",
@@ -76515,13 +76678,13 @@ var init_agent = __esm({
76515
76678
  await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
76516
76679
  this.#advertiseCompactCommand();
76517
76680
  return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
76518
- }).onRequest(methods3.agent.session.setConfigOption, async (context) => {
76681
+ }).onRequest(methods4.agent.session.setConfigOption, async (context) => {
76519
76682
  this.#settings.applySelection(context.params.configId, context.params.value);
76520
76683
  return { configOptions: this.#settings.configOptions() };
76521
- }).onRequest(methods3.agent.session.setMode, async (context) => {
76684
+ }).onRequest(methods4.agent.session.setMode, async (context) => {
76522
76685
  this.#settings.applySelection("mode", context.params.modeId);
76523
76686
  return {};
76524
- }).onRequest(methods3.agent.session.load, async (context) => {
76687
+ }).onRequest(methods4.agent.session.load, async (context) => {
76525
76688
  await this.#resume(context.params.sessionId, context.params.cwd, context.signal);
76526
76689
  await this.#replaySavedHistory(context.signal);
76527
76690
  this.#advertiseCompactCommand();
@@ -76529,7 +76692,7 @@ var init_agent = __esm({
76529
76692
  _meta: { steering: { supported: this.#sessionAgent.steeringSupported } },
76530
76693
  configOptions: this.#settings.configOptions()
76531
76694
  };
76532
- }).onRequest(methods3.agent.session.fork, async (context) => {
76695
+ }).onRequest(methods4.agent.session.fork, async (context) => {
76533
76696
  const forked = threadForkResponseSchema.parse(
76534
76697
  await this.#appServer.request(
76535
76698
  "thread/fork",
@@ -76548,14 +76711,14 @@ var init_agent = __esm({
76548
76711
  await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
76549
76712
  this.#advertiseCompactCommand();
76550
76713
  return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
76551
- }).onRequest(methods3.agent.session.resume, async (context) => {
76714
+ }).onRequest(methods4.agent.session.resume, async (context) => {
76552
76715
  await this.#resume(context.params.sessionId, context.params.cwd, context.signal);
76553
76716
  this.#advertiseCompactCommand();
76554
76717
  return {
76555
76718
  _meta: { steering: { supported: this.#sessionAgent.steeringSupported } },
76556
76719
  configOptions: this.#settings.configOptions()
76557
76720
  };
76558
- }).onRequest(methods3.agent.session.prompt, async (context) => {
76721
+ }).onRequest(methods4.agent.session.prompt, async (context) => {
76559
76722
  if (isCompactCommand(context.params.prompt)) {
76560
76723
  return await this.#sessionAgent.compact(context.signal);
76561
76724
  }
@@ -76564,7 +76727,7 @@ var init_agent = __esm({
76564
76727
  "_session/steering",
76565
76728
  (params) => params,
76566
76729
  async (context) => await this.#sessionAgent.steer(context.params, context.signal)
76567
- ).onRequest(methods3.agent.session.list, async (context) => {
76730
+ ).onRequest(methods4.agent.session.list, async (context) => {
76568
76731
  const decoded = threadListResponseSchema.parse(
76569
76732
  await this.#appServer.request(
76570
76733
  "thread/list",
@@ -76586,9 +76749,9 @@ var init_agent = __esm({
76586
76749
  updatedAt: new Date(thread.updatedAt * 1e3).toISOString()
76587
76750
  }))
76588
76751
  };
76589
- }).onRequest(methods3.agent.session.close, async () => {
76752
+ }).onRequest(methods4.agent.session.close, async () => {
76590
76753
  await this.#sessionAgent.cancel();
76591
- }).onNotification(methods3.agent.session.cancel, async () => {
76754
+ }).onNotification(methods4.agent.session.cancel, async () => {
76592
76755
  await this.#sessionAgent.cancel();
76593
76756
  });
76594
76757
  }
@@ -76707,17 +76870,39 @@ var init_agent = __esm({
76707
76870
  }
76708
76871
  });
76709
76872
 
76873
+ // src/acp/adapter/codex/agent-connection.ts
76874
+ var CodexAgentConnection;
76875
+ var init_agent_connection2 = __esm({
76876
+ "src/acp/adapter/codex/agent-connection.ts"() {
76877
+ "use strict";
76878
+ init_endpoint_agent_connection();
76879
+ init_agent();
76880
+ CodexAgentConnection = class extends EndpointAgentConnection {
76881
+ constructor(options) {
76882
+ const endpoint = new CodexAcpAgent({
76883
+ command: options.command,
76884
+ cwd: options.cwd,
76885
+ environment: options.environment,
76886
+ onSessionUpdate: options.client.onUpdate,
76887
+ onBackgroundActivity: (active) => options.onBackgroundActivity?.(active)
76888
+ });
76889
+ super(endpoint, options.client);
76890
+ }
76891
+ };
76892
+ }
76893
+ });
76894
+
76710
76895
  // src/agent/specification/vendors/codex-agent.ts
76711
76896
  var CodexAgentSpecification;
76712
76897
  var init_codex_agent = __esm({
76713
76898
  "src/agent/specification/vendors/codex-agent.ts"() {
76714
76899
  "use strict";
76715
- init_agent();
76900
+ init_agent_connection2();
76716
76901
  init_agent_specification();
76717
76902
  CodexAgentSpecification = class extends InProcessAcpAgentSpecification {
76718
76903
  versionProbeTimeoutMilliseconds = 1e4;
76719
76904
  agentExecutable = "codex";
76720
- createEndpoint = (options) => new CodexAcpAgent(options);
76905
+ createConnection = (options) => new CodexAgentConnection(options);
76721
76906
  id = "codex";
76722
76907
  label = "Codex";
76723
76908
  minimumSupportedAgentVersion = "0.153.0";
@@ -77173,7 +77358,7 @@ var init_auth = __esm({
77173
77358
  });
77174
77359
 
77175
77360
  // src/acp/harness/pi/upstream/dist/acp/auth-required.js
77176
- import { RequestError as RequestError4 } from "@agentclientprotocol/sdk";
77361
+ import { RequestError as RequestError5 } from "@agentclientprotocol/sdk";
77177
77362
  function maybeAuthRequiredError(err) {
77178
77363
  const msg = String(err?.message ?? err ?? "");
77179
77364
  const s = msg.toLowerCase();
@@ -77194,7 +77379,7 @@ function maybeAuthRequiredError(err) {
77194
77379
  if (!hit) {
77195
77380
  return null;
77196
77381
  }
77197
- return RequestError4.authRequired({
77382
+ return RequestError5.authRequired({
77198
77383
  authMethods: getAuthMethods()
77199
77384
  }, "Configure an API key or log in with an OAuth provider.");
77200
77385
  }
@@ -77682,7 +77867,7 @@ var init_pi_settings = __esm({
77682
77867
  });
77683
77868
 
77684
77869
  // src/acp/harness/pi/upstream/dist/acp/extension-questions.js
77685
- import { RequestError as RequestError5 } from "@agentclientprotocol/sdk";
77870
+ import { RequestError as RequestError6 } from "@agentclientprotocol/sdk";
77686
77871
  function questionField(question) {
77687
77872
  const title2 = question.title || "Answer";
77688
77873
  switch (question.method) {
@@ -77730,7 +77915,7 @@ var init_extension_questions = __esm({
77730
77915
  external_exports.object({ ...questionBase, method: external_exports.literal("editor"), prefill: external_exports.string().max(1e4).optional() })
77731
77916
  ]).readonly();
77732
77917
  QUESTION_TIMEOUT_MS = 36e5;
77733
- PiQuestionError = class extends RequestError5 {
77918
+ PiQuestionError = class extends RequestError6 {
77734
77919
  constructor(kind, cause) {
77735
77920
  const messages = {
77736
77921
  request_failed: "Pi could not request an answer.",
@@ -77842,7 +78027,7 @@ var init_extension_questions = __esm({
77842
78027
  throw new PiQuestionError("invalid_response");
77843
78028
  }
77844
78029
  } catch (cause) {
77845
- if (!signal.aborted && !(cause instanceof RequestError5 && cause.code === -32800)) {
78030
+ if (!signal.aborted && !(cause instanceof RequestError6 && cause.code === -32800)) {
77846
78031
  turn.controller.abort(cause instanceof PiQuestionError ? cause : new PiQuestionError("request_failed", cause));
77847
78032
  }
77848
78033
  } finally {
@@ -78150,7 +78335,7 @@ var init_pi_tools = __esm({
78150
78335
  import { randomUUID as randomUUID7 } from "node:crypto";
78151
78336
  import { readFileSync as readFileSync7 } from "node:fs";
78152
78337
  import { isAbsolute as isAbsolute11, resolve as resolvePath } from "node:path";
78153
- import { RequestError as RequestError6 } from "@agentclientprotocol/sdk";
78338
+ import { RequestError as RequestError7 } from "@agentclientprotocol/sdk";
78154
78339
  function toUsageUpdate(stats) {
78155
78340
  const used = stats?.contextUsage?.tokens;
78156
78341
  const size = stats?.contextUsage?.contextWindow;
@@ -78324,7 +78509,7 @@ var init_session = __esm({
78324
78509
  });
78325
78510
  } catch (e) {
78326
78511
  if (e instanceof PiRpcSpawnError) {
78327
- throw RequestError6.internalError({ code: e.code }, e.message);
78512
+ throw RequestError7.internalError({ code: e.code }, e.message);
78328
78513
  }
78329
78514
  throw e;
78330
78515
  }
@@ -78353,7 +78538,7 @@ var init_session = __esm({
78353
78538
  get(sessionId) {
78354
78539
  const s = this.sessions.get(sessionId);
78355
78540
  if (!s) {
78356
- throw RequestError6.invalidParams(`Unknown sessionId: ${sessionId}`);
78541
+ throw RequestError7.invalidParams(`Unknown sessionId: ${sessionId}`);
78357
78542
  }
78358
78543
  return s;
78359
78544
  }
@@ -78450,8 +78635,8 @@ var init_session = __esm({
78450
78635
  if (cause instanceof PiRpcProcessError) {
78451
78636
  const pending = this.pendingTurn;
78452
78637
  const reason = pending?.questionSignal.reason;
78453
- const error62 = reason instanceof RequestError6 ? reason : RequestError6.internalError({ code: cause.code, details: cause.message });
78454
- if (!(reason instanceof RequestError6)) {
78638
+ const error62 = reason instanceof RequestError7 ? reason : RequestError7.internalError({ code: cause.code, details: cause.message });
78639
+ if (!(reason instanceof RequestError7)) {
78455
78640
  error62.cause = cause;
78456
78641
  }
78457
78642
  this.extensionQuestions.endTurn(error62);
@@ -78519,12 +78704,12 @@ var init_session = __esm({
78519
78704
  const signal = this.extensionQuestions.startTurn();
78520
78705
  try {
78521
78706
  const result = await this.proc.compact(customInstructions, { signal, timeoutMs });
78522
- if (signal.aborted && signal.reason instanceof RequestError6) {
78707
+ if (signal.aborted && signal.reason instanceof RequestError7) {
78523
78708
  throw signal.reason;
78524
78709
  }
78525
78710
  return result;
78526
78711
  } catch (cause) {
78527
- if (signal.aborted && signal.reason instanceof RequestError6) {
78712
+ if (signal.aborted && signal.reason instanceof RequestError7) {
78528
78713
  try {
78529
78714
  await this.proc.abort({ signal: this.proc.signal, timeoutMs });
78530
78715
  } catch (abortCause) {
@@ -78617,14 +78802,14 @@ var init_session = __esm({
78617
78802
  await this.publishContextUsage();
78618
78803
  const retryFailure = this.turnRetryFailure;
78619
78804
  this.turnRetryFailure = null;
78620
- if (questionSignal?.aborted && questionSignal.reason instanceof RequestError6 && !this.cancelRequested) {
78805
+ if (questionSignal?.aborted && questionSignal.reason instanceof RequestError7 && !this.cancelRequested) {
78621
78806
  this.pendingTurn?.reject(questionSignal.reason);
78622
78807
  } else if (retryFailure !== null && !this.cancelRequested) {
78623
78808
  this.pendingTurn?.reject(
78624
78809
  // The message rides in `data.details` so clients that unwrap the
78625
78810
  // JSON-RPC internal-error envelope (like Mobius) surface the real
78626
78811
  // model error; `code` keeps the failure machine-readable.
78627
- RequestError6.internalError({
78812
+ RequestError7.internalError({
78628
78813
  code: "pi_retries_exhausted",
78629
78814
  details: `Pi retries exhausted: ${retryFailure}`
78630
78815
  })
@@ -79076,7 +79261,7 @@ import { spawnSync } from "node:child_process";
79076
79261
  import { randomUUID as randomUUID8 } from "node:crypto";
79077
79262
  import { existsSync as existsSync7, readdirSync as readdirSync6, readFileSync as readFileSync8, realpathSync as realpathSync3, statSync as statSync3, unlinkSync as unlinkSync2 } from "node:fs";
79078
79263
  import { basename as basename6, dirname as dirname9, isAbsolute as isAbsolute12, join as join20 } from "node:path";
79079
- import { RequestError as RequestError7 } from "@agentclientprotocol/sdk";
79264
+ import { RequestError as RequestError8 } from "@agentclientprotocol/sdk";
79080
79265
  function thinkingLevelName(id) {
79081
79266
  return id.split(/[_-]/u).map((part) => part.length === 0 ? part : `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
79082
79267
  }
@@ -79280,7 +79465,7 @@ async function setSessionModel(proc, requestedModelId) {
79280
79465
  }
79281
79466
  }
79282
79467
  if (!provider || !modelId) {
79283
- throw RequestError7.invalidParams(`Unknown modelId: ${requestedModelId}`);
79468
+ throw RequestError8.invalidParams(`Unknown modelId: ${requestedModelId}`);
79284
79469
  }
79285
79470
  await proc.setModel(provider, modelId);
79286
79471
  }
@@ -79561,7 +79746,7 @@ var init_agent2 = __esm({
79561
79746
  const restorePromise = (async () => {
79562
79747
  const stored = this.findStoredSession(sessionId);
79563
79748
  if (!stored) {
79564
- throw RequestError7.invalidParams(`Unknown sessionId: ${sessionId}`);
79749
+ throw RequestError8.invalidParams(`Unknown sessionId: ${sessionId}`);
79565
79750
  }
79566
79751
  const cwd = opts?.cwd ?? stored.cwd;
79567
79752
  let proc;
@@ -79574,7 +79759,7 @@ var init_agent2 = __esm({
79574
79759
  });
79575
79760
  } catch (e) {
79576
79761
  if (e?.name === "PiRpcSpawnError") {
79577
- throw RequestError7.internalError({ code: e?.code }, String(e?.message ?? e));
79762
+ throw RequestError8.internalError({ code: e?.code }, String(e?.message ?? e));
79578
79763
  }
79579
79764
  throw e;
79580
79765
  }
@@ -79634,7 +79819,7 @@ var init_agent2 = __esm({
79634
79819
  }
79635
79820
  async newSession(params) {
79636
79821
  if (!isAbsolute12(params.cwd)) {
79637
- throw RequestError7.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
79822
+ throw RequestError8.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
79638
79823
  }
79639
79824
  this.lastSessionCwd = params.cwd;
79640
79825
  const fileCommands = loadSlashCommands(params.cwd, this.environment);
@@ -79673,16 +79858,16 @@ var init_agent2 = __esm({
79673
79858
  }
79674
79859
  if (availableModelsErr) {
79675
79860
  this.cleanupFailedNewSession(session.sessionId, state);
79676
- throw RequestError7.internalError({}, String(availableModelsErr?.message ?? availableModelsErr));
79861
+ throw RequestError8.internalError({}, String(availableModelsErr?.message ?? availableModelsErr));
79677
79862
  }
79678
79863
  const rawModelsCount = Array.isArray(availableModels?.models) ? availableModels.models.length : 0;
79679
79864
  if (rawModelsCount === 0) {
79680
79865
  this.cleanupFailedNewSession(session.sessionId, state);
79681
- throw RequestError7.authRequired({ authMethods: getAuthMethods() }, "Configure an API key or log in with an OAuth provider.");
79866
+ throw RequestError8.authRequired({ authMethods: getAuthMethods() }, "Configure an API key or log in with an OAuth provider.");
79682
79867
  }
79683
79868
  if (stateErr && maybeAuthRequiredError(stateErr)) {
79684
79869
  this.cleanupFailedNewSession(session.sessionId, state);
79685
- throw RequestError7.authRequired({ authMethods: getAuthMethods() }, "Configure an API key or log in with an OAuth provider.");
79870
+ throw RequestError8.authRequired({ authMethods: getAuthMethods() }, "Configure an API key or log in with an OAuth provider.");
79686
79871
  }
79687
79872
  let configuration;
79688
79873
  try {
@@ -79692,7 +79877,7 @@ var init_agent2 = __esm({
79692
79877
  configuration = await getSessionConfiguration(session.proc, { state, availableModels });
79693
79878
  } catch (err) {
79694
79879
  this.cleanupFailedNewSession(session.sessionId, state);
79695
- throw maybeAuthRequiredError(err) ?? RequestError7.internalError({}, String(err?.message ?? err));
79880
+ throw maybeAuthRequiredError(err) ?? RequestError8.internalError({}, String(err?.message ?? err));
79696
79881
  }
79697
79882
  const { configOptions, models, modes } = configuration;
79698
79883
  const quietStartup = getQuietStartup(params.cwd, this.environment);
@@ -80190,7 +80375,7 @@ ${JSON.stringify(stats, null, 2)}`;
80190
80375
  signal.throwIfAborted();
80191
80376
  const parsed = steerRequestSchema.safeParse(params);
80192
80377
  if (!parsed.success) {
80193
- throw RequestError7.invalidParams("Invalid steering request");
80378
+ throw RequestError8.invalidParams("Invalid steering request");
80194
80379
  }
80195
80380
  const session = this.sessions.maybeGet(parsed.data.sessionId);
80196
80381
  if (session === void 0) {
@@ -80231,11 +80416,11 @@ ${JSON.stringify(stats, null, 2)}`;
80231
80416
  }
80232
80417
  async forkSession(params) {
80233
80418
  if (!isAbsolute12(params.cwd)) {
80234
- throw RequestError7.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
80419
+ throw RequestError8.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
80235
80420
  }
80236
80421
  const source = this.findStoredSession(params.sessionId);
80237
80422
  if (!source) {
80238
- throw RequestError7.invalidParams(`Unknown sessionId: ${params.sessionId}`);
80423
+ throw RequestError8.invalidParams(`Unknown sessionId: ${params.sessionId}`);
80239
80424
  }
80240
80425
  this.lastSessionCwd = params.cwd;
80241
80426
  const fileCommands = loadSlashCommands(params.cwd, this.environment);
@@ -80297,13 +80482,13 @@ ${JSON.stringify(stats, null, 2)}`;
80297
80482
  }
80298
80483
  async resumeSession(params) {
80299
80484
  if (!isAbsolute12(params.cwd)) {
80300
- throw RequestError7.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
80485
+ throw RequestError8.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
80301
80486
  }
80302
80487
  this.sessions.close(params.sessionId);
80303
80488
  this.lastSessionCwd = params.cwd;
80304
80489
  const stored = this.findStoredSession(params.sessionId);
80305
80490
  if (!stored) {
80306
- throw RequestError7.invalidParams(`Unknown sessionId: ${params.sessionId}`);
80491
+ throw RequestError8.invalidParams(`Unknown sessionId: ${params.sessionId}`);
80307
80492
  }
80308
80493
  const session = await this.restoreSession(params.sessionId, {
80309
80494
  cwd: params.cwd,
@@ -80368,13 +80553,13 @@ ${JSON.stringify(stats, null, 2)}`;
80368
80553
  }
80369
80554
  async loadSession(params) {
80370
80555
  if (!isAbsolute12(params.cwd)) {
80371
- throw RequestError7.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
80556
+ throw RequestError8.invalidParams(`cwd must be an absolute path: ${params.cwd}`);
80372
80557
  }
80373
80558
  this.sessions.close(params.sessionId);
80374
80559
  this.lastSessionCwd = params.cwd;
80375
80560
  const stored = this.findStoredSession(params.sessionId);
80376
80561
  if (!stored) {
80377
- throw RequestError7.invalidParams(`Unknown sessionId: ${params.sessionId}`);
80562
+ throw RequestError8.invalidParams(`Unknown sessionId: ${params.sessionId}`);
80378
80563
  }
80379
80564
  const enableSkillCommands = getEnableSkillCommands(params.cwd, this.environment);
80380
80565
  const session = await this.restoreSession(params.sessionId, {
@@ -80549,7 +80734,7 @@ ${JSON.stringify(stats, null, 2)}`;
80549
80734
  const session = await this.restoreSession(params.sessionId);
80550
80735
  const mode = params.modeId;
80551
80736
  if (typeof mode !== "string" || mode.length === 0) {
80552
- throw RequestError7.invalidParams("Expected nonempty string modeId");
80737
+ throw RequestError8.invalidParams("Expected nonempty string modeId");
80553
80738
  }
80554
80739
  await session.proc.setThinkingLevel(mode);
80555
80740
  await emitConfigOptionsUpdate(this.conn, session.sessionId, session.proc);
@@ -80560,18 +80745,18 @@ ${JSON.stringify(stats, null, 2)}`;
80560
80745
  const configId = String(params.configId);
80561
80746
  let modelChanged = false;
80562
80747
  if (typeof params.value !== "string") {
80563
- throw RequestError7.invalidParams(`Expected string value for config option: ${configId}`);
80748
+ throw RequestError8.invalidParams(`Expected string value for config option: ${configId}`);
80564
80749
  }
80565
80750
  if (configId === MODEL_CONFIG_ID2) {
80566
80751
  await setSessionModel(session.proc, params.value);
80567
80752
  modelChanged = true;
80568
80753
  } else if (configId === THOUGHT_LEVEL_CONFIG_ID) {
80569
80754
  if (params.value.length === 0) {
80570
- throw RequestError7.invalidParams("Expected nonempty thinking level");
80755
+ throw RequestError8.invalidParams("Expected nonempty thinking level");
80571
80756
  }
80572
80757
  await session.proc.setThinkingLevel(params.value);
80573
80758
  } else {
80574
- throw RequestError7.invalidParams(`Unknown config option: ${configId}`);
80759
+ throw RequestError8.invalidParams(`Unknown config option: ${configId}`);
80575
80760
  }
80576
80761
  const configOptions = await emitConfigOptionsUpdate(this.conn, session.sessionId, session.proc);
80577
80762
  if (modelChanged) {
@@ -80584,11 +80769,11 @@ ${JSON.stringify(stats, null, 2)}`;
80584
80769
  });
80585
80770
 
80586
80771
  // src/acp/harness/pi/upstream/dist/acp/client.js
80587
- import { methods as methods4 } from "@agentclientprotocol/sdk";
80772
+ import { methods as methods5 } from "@agentclientprotocol/sdk";
80588
80773
  function createPiAcpClient(connection, onSessionUpdate) {
80589
80774
  return {
80590
- requestElicitation: async (request, signal) => await connection.client.request(methods4.client.elicitation.create, request, { cancellationSignal: signal }),
80591
- requestPermission: async (request) => await connection.client.request(methods4.client.session.requestPermission, request),
80775
+ requestElicitation: async (request, signal) => await connection.client.request(methods5.client.elicitation.create, request, { cancellationSignal: signal }),
80776
+ requestPermission: async (request) => await connection.client.request(methods5.client.session.requestPermission, request),
80592
80777
  sessionUpdate: onSessionUpdate
80593
80778
  };
80594
80779
  }
@@ -80599,7 +80784,7 @@ var init_client = __esm({
80599
80784
  });
80600
80785
 
80601
80786
  // src/acp/harness/pi/endpoint.ts
80602
- import { agent as createAgentApp2, methods as methods5 } from "@agentclientprotocol/sdk";
80787
+ import { agent as createAgentApp2, methods as methods6 } from "@agentclientprotocol/sdk";
80603
80788
  function piAgentOrThrow(agent) {
80604
80789
  if (agent === null) {
80605
80790
  throw new Error("The Pi ACP client is not connected");
@@ -80634,36 +80819,36 @@ var init_endpoint2 = __esm({
80634
80819
  piAgent = new PiAcpAgent(createPiAcpClient(connection, options.onSessionUpdate), { environment });
80635
80820
  this.#agent = piAgent;
80636
80821
  }).onRequest(
80637
- methods5.agent.initialize,
80822
+ methods6.agent.initialize,
80638
80823
  async (context) => await piAgentOrThrow(piAgent).initialize(context.params)
80639
80824
  ).onRequest(
80640
- methods5.agent.authenticate,
80825
+ methods6.agent.authenticate,
80641
80826
  async (context) => await piAgentOrThrow(piAgent).authenticate(context.params)
80642
80827
  ).onRequest(
80643
- methods5.agent.session.new,
80828
+ methods6.agent.session.new,
80644
80829
  async (context) => await piAgentOrThrow(piAgent).newSession(context.params)
80645
80830
  ).onRequest(
80646
- methods5.agent.session.load,
80831
+ methods6.agent.session.load,
80647
80832
  async (context) => await piAgentOrThrow(piAgent).loadSession(context.params)
80648
80833
  ).onRequest(
80649
- methods5.agent.session.resume,
80834
+ methods6.agent.session.resume,
80650
80835
  async (context) => await piAgentOrThrow(piAgent).resumeSession(context.params)
80651
80836
  ).onRequest(
80652
- methods5.agent.session.list,
80837
+ methods6.agent.session.list,
80653
80838
  async (context) => await piAgentOrThrow(piAgent).listSessions(context.params)
80654
80839
  ).onRequest(
80655
- methods5.agent.session.delete,
80840
+ methods6.agent.session.delete,
80656
80841
  async (context) => await piAgentOrThrow(piAgent).deleteSession(context.params)
80657
80842
  ).onRequest(
80658
- methods5.agent.session.fork,
80843
+ methods6.agent.session.fork,
80659
80844
  async (context) => await piAgentOrThrow(piAgent).forkSession(context.params)
80660
80845
  ).onRequest(
80661
- methods5.agent.session.setMode,
80846
+ methods6.agent.session.setMode,
80662
80847
  async (context) => await piAgentOrThrow(piAgent).setSessionMode(context.params)
80663
80848
  ).onRequest(
80664
- methods5.agent.session.setConfigOption,
80849
+ methods6.agent.session.setConfigOption,
80665
80850
  async (context) => await piAgentOrThrow(piAgent).setSessionConfigOption(context.params)
80666
- ).onRequest(methods5.agent.session.prompt, async (context) => {
80851
+ ).onRequest(methods6.agent.session.prompt, async (context) => {
80667
80852
  const agent = piAgentOrThrow(piAgent);
80668
80853
  const cancel = () => {
80669
80854
  void agent.cancel({ sessionId: context.params.sessionId });
@@ -80678,7 +80863,7 @@ var init_endpoint2 = __esm({
80678
80863
  "_session/steering",
80679
80864
  (params) => params,
80680
80865
  async (context) => await piAgentOrThrow(piAgent).steer(context.params, context.signal)
80681
- ).onNotification(methods5.agent.session.cancel, async (context) => {
80866
+ ).onNotification(methods6.agent.session.cancel, async (context) => {
80682
80867
  await piAgentOrThrow(piAgent).cancel(context.params);
80683
80868
  });
80684
80869
  }
@@ -80703,6 +80888,28 @@ var init_endpoint2 = __esm({
80703
80888
  }
80704
80889
  });
80705
80890
 
80891
+ // src/acp/adapter/pi/agent-connection.ts
80892
+ var PiAgentConnection;
80893
+ var init_agent_connection3 = __esm({
80894
+ "src/acp/adapter/pi/agent-connection.ts"() {
80895
+ "use strict";
80896
+ init_endpoint_agent_connection();
80897
+ init_endpoint2();
80898
+ PiAgentConnection = class extends EndpointAgentConnection {
80899
+ constructor(options) {
80900
+ const endpoint = new PiAcpEndpoint({
80901
+ command: options.command,
80902
+ cwd: options.cwd,
80903
+ environment: options.environment,
80904
+ onSessionUpdate: options.client.onUpdate,
80905
+ onBackgroundActivity: (active) => options.onBackgroundActivity?.(active)
80906
+ });
80907
+ super(endpoint, options.client);
80908
+ }
80909
+ };
80910
+ }
80911
+ });
80912
+
80706
80913
  // src/agent/discovery/agent-probe-error.ts
80707
80914
  var AgentProbeError;
80708
80915
  var init_agent_probe_error = __esm({
@@ -80723,20 +80930,20 @@ var init_agent_probe_error = __esm({
80723
80930
  import { createHash as createHash3 } from "node:crypto";
80724
80931
  import { join as join21 } from "node:path";
80725
80932
  import {
80726
- methods as methods6
80933
+ methods as methods7
80727
80934
  } from "@agentclientprotocol/sdk";
80728
80935
  var ACP_PROBE_TIMEOUT_MILLISECONDS2, PiAgentSpecification;
80729
80936
  var init_pi_agent = __esm({
80730
80937
  "src/agent/specification/vendors/pi-agent.ts"() {
80731
80938
  "use strict";
80732
- init_endpoint2();
80939
+ init_agent_connection3();
80733
80940
  init_agent_probe_error();
80734
80941
  init_agent_specification();
80735
80942
  ACP_PROBE_TIMEOUT_MILLISECONDS2 = 3e4;
80736
80943
  PiAgentSpecification = class extends InProcessAcpAgentSpecification {
80737
80944
  acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS2;
80738
80945
  agentExecutable = "pi";
80739
- createEndpoint = (options) => new PiAcpEndpoint(options);
80946
+ createConnection = (options) => new PiAgentConnection(options);
80740
80947
  // The Pi ACP fork inlines embedded prompt resources into the turn message, so Mobius
80741
80948
  // keeps the adapter's opt-in capability flag enabled for every launch it owns.
80742
80949
  createLaunchEnvironment = async (_agent, context) => {
@@ -80761,7 +80968,7 @@ var init_pi_agent = __esm({
80761
80968
  throw new AgentProbeError("acp_incompatible", "Pi ACP adapter does not support session recovery");
80762
80969
  }
80763
80970
  const session = await connection.agent.request(
80764
- methods6.agent.session.new,
80971
+ methods7.agent.session.new,
80765
80972
  {
80766
80973
  additionalDirectories: [],
80767
80974
  cwd: defaultWorkspace,
@@ -80773,7 +80980,7 @@ var init_pi_agent = __esm({
80773
80980
  throw new AgentProbeError("acp_incompatible", "Pi ACP adapter returned an invalid session");
80774
80981
  }
80775
80982
  const prompt = await connection.agent.request(
80776
- methods6.agent.session.prompt,
80983
+ methods7.agent.session.prompt,
80777
80984
  {
80778
80985
  prompt: [{ text: "/session", type: "text" }],
80779
80986
  sessionId: session.sessionId
@@ -80969,37 +81176,13 @@ var init_local_executable = __esm({
80969
81176
  }
80970
81177
  });
80971
81178
 
80972
- // src/util/value-utils.ts
80973
- function truncate2(value, maximumLength) {
80974
- return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
80975
- }
80976
- function isRecord3(value) {
80977
- return typeof value === "object" && value !== null && !Array.isArray(value);
80978
- }
80979
- function readString2(value, fallback = "") {
80980
- return typeof value === "string" ? value : fallback;
80981
- }
80982
- function arraysEqual(left, right) {
80983
- return left.length === right.length && left.every((value, index2) => value === right[index2]);
80984
- }
80985
- function recordsEqual(left, right) {
80986
- const leftEntries = Object.entries(left);
80987
- const rightEntries = Object.entries(right);
80988
- return leftEntries.length === rightEntries.length && leftEntries.every(([name2, value]) => right[name2] === value);
80989
- }
80990
- var init_value_utils = __esm({
80991
- "src/util/value-utils.ts"() {
80992
- "use strict";
80993
- }
80994
- });
80995
-
80996
81179
  // src/acp/protocol/session-capabilities.ts
80997
81180
  function hasTrueChildField(value, childKey, fieldKey) {
80998
- if (!isRecord3(value)) {
81181
+ if (!isRecord(value)) {
80999
81182
  return false;
81000
81183
  }
81001
81184
  const child = Reflect.get(value, childKey);
81002
- return isRecord3(child) && Reflect.get(child, fieldKey) === true;
81185
+ return isRecord(child) && Reflect.get(child, fieldKey) === true;
81003
81186
  }
81004
81187
  function unsupportedSessionCapabilities() {
81005
81188
  return Object.freeze({
@@ -81039,11 +81222,11 @@ function normalizeAcpCapabilities(initialized) {
81039
81222
  });
81040
81223
  }
81041
81224
  function restrictAcpSessionCapabilities(capabilities, response) {
81042
- if (!isRecord3(response) || !isRecord3(response["_meta"])) {
81225
+ if (!isRecord(response) || !isRecord(response["_meta"])) {
81043
81226
  return capabilities;
81044
81227
  }
81045
81228
  const steering = response["_meta"]["steering"];
81046
- if (!isRecord3(steering) || steering["supported"] !== false) {
81229
+ if (!isRecord(steering) || steering["supported"] !== false) {
81047
81230
  return capabilities;
81048
81231
  }
81049
81232
  return Object.freeze({ ...capabilities, steering: false });
@@ -81056,178 +81239,89 @@ var init_session_capabilities = __esm({
81056
81239
  });
81057
81240
 
81058
81241
  // src/acp/agent/agent-definition.ts
81059
- var AgentDefinition, LocalAgentDefinition, InProcessAcpAgentDefinition;
81242
+ var AcpAgentDefinition;
81060
81243
  var init_agent_definition = __esm({
81061
81244
  "src/acp/agent/agent-definition.ts"() {
81062
81245
  "use strict";
81063
81246
  init_local_executable();
81064
81247
  init_session_capabilities();
81065
- AgentDefinition = class {
81248
+ AcpAgentDefinition = class _AcpAgentDefinition {
81066
81249
  agentIdentity;
81067
81250
  agentVersion;
81251
+ adapterVersion;
81068
81252
  capabilities;
81069
81253
  command;
81070
81254
  environment;
81071
81255
  id;
81072
81256
  label;
81073
- constructor(id, label, _command, environment, agentVersion, agentIdentity, capabilities) {
81257
+ runtimeExecutables;
81258
+ #connectionFactory;
81259
+ constructor(id, label, command, createConnection2, environment = {}, agentVersion = "", agentIdentity = readExecutableIdentity(command), capabilities = unsupportedSessionCapabilities(), adapterVersion = agentVersion, runtimeExecutables = [agentIdentity]) {
81074
81260
  this.agentIdentity = agentIdentity;
81075
81261
  this.agentVersion = agentVersion;
81262
+ this.adapterVersion = adapterVersion;
81076
81263
  this.capabilities = Object.freeze({ ...capabilities });
81077
81264
  this.command = agentIdentity.realPath;
81078
81265
  this.environment = Object.freeze({ ...environment });
81079
81266
  this.id = id;
81080
81267
  this.label = label;
81268
+ this.runtimeExecutables = Object.freeze([.../* @__PURE__ */ new Set([agentIdentity, ...runtimeExecutables])]);
81269
+ this.#connectionFactory = createConnection2;
81081
81270
  }
81082
- };
81083
- LocalAgentDefinition = class _LocalAgentDefinition extends AgentDefinition {
81084
- kind = "acp-adapter-process";
81085
- adapterIdentity;
81086
- adapterPath;
81087
- adapterVersion;
81088
- arguments;
81089
- constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readExecutableIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities()) {
81090
- super(id, label, command, environment, agentVersion, agentIdentity, capabilities);
81091
- this.adapterIdentity = adapterIdentity;
81092
- this.adapterPath = adapterIdentity.realPath;
81093
- this.adapterVersion = adapterVersion;
81094
- this.arguments = Object.freeze([...arguments_]);
81095
- }
81096
- withEnvironment = (environment) => new _LocalAgentDefinition(
81097
- this.id,
81098
- this.label,
81099
- this.command,
81100
- this.arguments,
81101
- environment,
81102
- this.adapterVersion,
81103
- this.agentVersion,
81104
- this.adapterIdentity,
81105
- this.agentIdentity,
81106
- this.capabilities
81107
- );
81108
- };
81109
- InProcessAcpAgentDefinition = class _InProcessAcpAgentDefinition extends AgentDefinition {
81110
- kind = "in-process-acp";
81111
- createEndpoint;
81112
- constructor(id, label, command, createEndpoint, environment = {}, agentVersion = "", agentIdentity = readExecutableIdentity(command), capabilities = unsupportedSessionCapabilities()) {
81113
- super(id, label, command, environment, agentVersion, agentIdentity, capabilities);
81114
- this.createEndpoint = createEndpoint;
81115
- }
81116
- withEnvironment = (environment) => new _InProcessAcpAgentDefinition(
81271
+ createConnection = (options) => this.#connectionFactory({ ...options, command: this.command, environment: this.environment });
81272
+ withEnvironment = (environment) => new _AcpAgentDefinition(
81117
81273
  this.id,
81118
81274
  this.label,
81119
81275
  this.command,
81120
- this.createEndpoint,
81276
+ this.#connectionFactory,
81121
81277
  environment,
81122
81278
  this.agentVersion,
81123
81279
  this.agentIdentity,
81124
- this.capabilities
81280
+ this.capabilities,
81281
+ this.adapterVersion,
81282
+ this.runtimeExecutables
81125
81283
  );
81126
81284
  };
81127
81285
  }
81128
81286
  });
81129
81287
 
81130
- // src/acp/connection/create-client.ts
81131
- import {
81132
- client,
81133
- methods as methods7
81134
- } from "@agentclientprotocol/sdk";
81135
- var createAcpClient;
81136
- var init_create_client = __esm({
81137
- "src/acp/connection/create-client.ts"() {
81138
- "use strict";
81139
- createAcpClient = (handler) => client({ name: "mobius" }).onRequest(
81140
- methods7.client.session.requestPermission,
81141
- async (context) => await handler.onPermission(context.params, context.signal)
81142
- ).onRequest(
81143
- methods7.client.elicitation.create,
81144
- async (context) => await handler.onElicitation(context.params, context.signal)
81145
- ).onNotification(methods7.client.session.update, async (context) => {
81146
- await handler.onUpdate(context.params);
81147
- }).onNotification(methods7.client.elicitation.complete, async (context) => {
81148
- await handler.onElicitationComplete(context.params);
81149
- });
81150
- }
81151
- });
81152
-
81153
81288
  // src/agent/discovery/acp-readiness-probe.ts
81154
- import { spawn as spawn6 } from "node:child_process";
81155
81289
  import {
81156
81290
  methods as methods8,
81157
- ndJsonStream as ndJsonStream2,
81158
- PROTOCOL_VERSION as PROTOCOL_VERSION2,
81159
- RequestError as RequestError8
81291
+ PROTOCOL_VERSION as PROTOCOL_VERSION2
81160
81292
  } from "@agentclientprotocol/sdk";
81161
- function readableAcpStream(input2) {
81162
- let byteLength = 0;
81163
- let open7 = true;
81164
- return new ReadableStream({
81165
- start(controller) {
81166
- input2.on("data", (chunk) => {
81167
- if (!open7) {
81168
- return;
81169
- }
81170
- if (!(chunk instanceof Uint8Array)) {
81171
- open7 = false;
81172
- controller.error(new Error("ACP adapter produced invalid output"));
81173
- return;
81174
- }
81175
- byteLength += chunk.byteLength;
81176
- if (byteLength > ACP_OUTPUT_LIMIT_BYTES) {
81177
- open7 = false;
81178
- controller.error(new Error("ACP adapter output limit exceeded"));
81179
- return;
81180
- }
81181
- controller.enqueue(new Uint8Array(chunk));
81182
- });
81183
- input2.once("end", () => {
81184
- if (open7) {
81185
- open7 = false;
81186
- controller.close();
81187
- }
81188
- });
81189
- input2.once("error", (error62) => {
81190
- if (open7) {
81191
- open7 = false;
81192
- controller.error(error62);
81193
- }
81194
- });
81195
- },
81196
- cancel() {
81197
- open7 = false;
81198
- }
81199
- });
81200
- }
81201
- function writableAcpStream(output2) {
81202
- return new WritableStream({
81203
- write(chunk) {
81204
- return new Promise((resolveWrite, rejectWrite) => {
81205
- output2.write(chunk, (error62) => {
81206
- if (error62) {
81207
- rejectWrite(error62);
81208
- return;
81209
- }
81210
- resolveWrite();
81211
- });
81212
- });
81293
+ function filterEnvironment(environment) {
81294
+ const filtered = {};
81295
+ for (const [name2, value] of Object.entries(environment)) {
81296
+ if (typeof value === "string") {
81297
+ filtered[name2] = value;
81213
81298
  }
81214
- });
81299
+ }
81300
+ return filtered;
81215
81301
  }
81216
- async function probeInProcessReadiness(specification, agent, environment, defaultWorkspace, controller) {
81217
- const handler = new DiscoveryAcpHandler();
81218
- const inProcess = agent.createEndpoint({
81219
- command: agent.command,
81220
- cwd: defaultWorkspace,
81221
- environment: { ...filterEnvironment(environment), ...agent.environment },
81222
- onSessionUpdate: handler.onUpdate
81223
- });
81302
+ async function probeAcpReadiness(specification, agent, environment, defaultWorkspace, signal) {
81303
+ signal.throwIfAborted();
81304
+ const controller = new AbortController();
81305
+ let timedOut = false;
81306
+ const timeout = setTimeout(() => {
81307
+ timedOut = true;
81308
+ controller.abort(new Error("ACP probe timed out"));
81309
+ }, specification.acpProbeTimeoutMilliseconds);
81310
+ const abort = () => controller.abort(signal.reason);
81311
+ signal.addEventListener("abort", abort, { once: true });
81312
+ if (signal.aborted) {
81313
+ abort();
81314
+ }
81224
81315
  try {
81225
- const connection = createAcpClient(handler).connect(inProcess.app());
81316
+ const runtime = agent.withEnvironment({ ...filterEnvironment(environment), ...agent.environment }).createConnection({
81317
+ cwd: defaultWorkspace,
81318
+ client: new DiscoveryAcpHandler()
81319
+ });
81226
81320
  try {
81227
- return await Promise.race([
81321
+ return await runtime.race(
81228
81322
  (async () => {
81229
- await inProcess.initialize(controller.signal);
81230
- const initialized = await connection.agent.request(
81323
+ await runtime.initialize(controller.signal);
81324
+ const initialized = await runtime.connection.agent.request(
81231
81325
  methods8.agent.initialize,
81232
81326
  {
81233
81327
  clientCapabilities: {},
@@ -81242,161 +81336,43 @@ async function probeInProcessReadiness(specification, agent, environment, defaul
81242
81336
  "ACP agent selected an unsupported protocol version"
81243
81337
  );
81244
81338
  }
81245
- await specification.verifyAcp(connection, initialized, defaultWorkspace, controller.signal);
81339
+ await specification.verifyAcp(runtime.connection, initialized, defaultWorkspace, controller.signal);
81246
81340
  return new VerifiedAcpReadiness(
81247
81341
  normalizeVersionOutput(initialized.agentInfo?.version ?? ""),
81248
81342
  normalizeAcpCapabilities(initialized)
81249
81343
  );
81250
81344
  })(),
81251
- inProcess.terminated.then((termination) => {
81252
- throw new AgentProbeError("acp_incompatible", "The ACP endpoint stopped during initialization", {
81253
- cause: acpEndpointTerminationError(termination)
81254
- });
81255
- })
81256
- ]);
81257
- } finally {
81258
- connection.close();
81259
- }
81260
- } finally {
81261
- await inProcess.close();
81262
- }
81263
- }
81264
- function filterEnvironment(environment) {
81265
- const filtered = {};
81266
- for (const [name2, value] of Object.entries(environment)) {
81267
- if (typeof value === "string") {
81268
- filtered[name2] = value;
81269
- }
81270
- }
81271
- return filtered;
81272
- }
81273
- async function probeAcpReadiness(specification, agent, environment, defaultWorkspace, signal) {
81274
- signal.throwIfAborted();
81275
- const controller = new AbortController();
81276
- let timedOut = false;
81277
- const timeout = setTimeout(() => {
81278
- timedOut = true;
81279
- controller.abort(new Error("ACP probe timed out"));
81280
- }, specification.acpProbeTimeoutMilliseconds);
81281
- const abort = () => controller.abort(signal.reason);
81282
- signal.addEventListener("abort", abort, { once: true });
81283
- if (signal.aborted) {
81284
- abort();
81285
- }
81286
- if (agent.kind === "in-process-acp") {
81287
- try {
81288
- return await probeInProcessReadiness(specification, agent, environment, defaultWorkspace, controller);
81289
- } catch (error62) {
81290
- if (signal.aborted) {
81291
- signal.throwIfAborted();
81292
- }
81293
- if (timedOut) {
81294
- throw new AgentProbeError("adapter_probe_timeout", "ACP agent probe timed out", { cause: error62 });
81295
- }
81296
- if (error62 instanceof AgentProbeError) {
81297
- throw error62;
81298
- }
81299
- if (error62 instanceof RequestError8 && error62.code === -32e3 && specification.authenticationCommand().length > 0) {
81300
- throw new AgentProbeError("authentication_required", "Agent authentication is required", {
81301
- cause: error62
81302
- });
81303
- }
81304
- throw new AgentProbeError("acp_incompatible", "ACP agent initialization failed", { cause: error62 });
81345
+ "The ACP endpoint stopped during initialization",
81346
+ controller.signal
81347
+ );
81305
81348
  } finally {
81306
- clearTimeout(timeout);
81307
- signal.removeEventListener("abort", abort);
81308
- }
81309
- }
81310
- const launch = executableLaunch2(agent.adapterPath, agent.arguments);
81311
- const child = spawn6(launch.command, [...launch.arguments], {
81312
- cwd: defaultWorkspace,
81313
- ...platformSpawnOptions,
81314
- env: { ...environment, ...agent.environment },
81315
- shell: false,
81316
- stdio: ["pipe", "pipe", "pipe"]
81317
- });
81318
- const processExit = new Promise((_resolve, reject2) => {
81319
- const rejectExit = () => reject2(new Error("ACP adapter exited during initialization"));
81320
- child.once("error", reject2);
81321
- child.once("exit", rejectExit);
81322
- if (child.exitCode !== null || child.signalCode !== null) {
81323
- rejectExit();
81324
- }
81325
- });
81326
- const stdin = child.stdin;
81327
- const stdout = child.stdout;
81328
- const stderr = child.stderr;
81329
- if (stdin === null || stdout === null || stderr === null) {
81330
- await stopProcessTree(child);
81331
- throw new AgentProbeError("acp_incompatible", "ACP adapter streams are unavailable");
81332
- }
81333
- let stderrBytes = 0;
81334
- const consumeStderr = (chunk) => {
81335
- stderrBytes += chunk.byteLength;
81336
- if (stderrBytes > ACP_OUTPUT_LIMIT_BYTES) {
81337
- controller.abort(new Error("ACP adapter output limit exceeded"));
81338
- }
81339
- };
81340
- stderr.on("data", consumeStderr);
81341
- const connection = createAcpClient(new DiscoveryAcpHandler()).connect(
81342
- ndJsonStream2(writableAcpStream(stdin), readableAcpStream(stdout))
81343
- );
81344
- try {
81345
- const initialized = await Promise.race([
81346
- connection.agent.request(
81347
- methods8.agent.initialize,
81348
- {
81349
- clientCapabilities: {},
81350
- clientInfo: { name: "mobius", version: "0.0.3" },
81351
- protocolVersion: PROTOCOL_VERSION2
81352
- },
81353
- { cancellationSignal: controller.signal }
81354
- ),
81355
- processExit
81356
- ]);
81357
- if (initialized.protocolVersion !== PROTOCOL_VERSION2) {
81358
- throw new AgentProbeError("acp_incompatible", "ACP adapter selected an unsupported protocol version");
81349
+ await runtime.closeProcess();
81359
81350
  }
81360
- await specification.verifyAcp(connection, initialized, defaultWorkspace, controller.signal);
81361
- return new VerifiedAcpReadiness(
81362
- normalizeVersionOutput(initialized.agentInfo?.version ?? ""),
81363
- normalizeAcpCapabilities(initialized)
81364
- );
81365
81351
  } catch (error62) {
81366
- if (signal.aborted) {
81367
- signal.throwIfAborted();
81368
- }
81352
+ signal.throwIfAborted();
81369
81353
  if (timedOut) {
81370
- throw new AgentProbeError("adapter_probe_timeout", "ACP adapter probe timed out", { cause: error62 });
81354
+ throw new AgentProbeError("adapter_probe_timeout", "ACP agent probe timed out", { cause: error62 });
81371
81355
  }
81372
81356
  if (error62 instanceof AgentProbeError) {
81373
81357
  throw error62;
81374
81358
  }
81375
- if (error62 instanceof RequestError8 && error62.code === -32e3 && specification.authenticationCommand().length > 0) {
81359
+ if (error62 instanceof AcpExecutionError && error62.code === "authentication_required" && specification.authenticationCommand().length > 0) {
81376
81360
  throw new AgentProbeError("authentication_required", "Agent authentication is required", { cause: error62 });
81377
81361
  }
81378
- throw new AgentProbeError("acp_incompatible", "ACP adapter initialization failed", { cause: error62 });
81362
+ throw new AgentProbeError("acp_incompatible", "ACP agent initialization failed", { cause: error62 });
81379
81363
  } finally {
81380
81364
  clearTimeout(timeout);
81381
81365
  signal.removeEventListener("abort", abort);
81382
- const capturedProcesses = await captureProcessTree(child);
81383
- connection.close();
81384
- stdin.end();
81385
- stderr.removeListener("data", consumeStderr);
81386
- await stopProcessTree(child, capturedProcesses);
81387
81366
  }
81388
81367
  }
81389
- var ACP_OUTPUT_LIMIT_BYTES, VerifiedAcpReadiness, DiscoveryAcpHandler;
81368
+ var VerifiedAcpReadiness, DiscoveryAcpHandler;
81390
81369
  var init_acp_readiness_probe = __esm({
81391
81370
  "src/agent/discovery/acp-readiness-probe.ts"() {
81392
81371
  "use strict";
81393
- init_in_process_endpoint();
81394
- init_create_client();
81372
+ init_acp_error();
81395
81373
  init_session_capabilities();
81396
- init_executable();
81397
81374
  init_agent_probe_error();
81398
81375
  init_version_output();
81399
- ACP_OUTPUT_LIMIT_BYTES = 1024 * 1024;
81400
81376
  VerifiedAcpReadiness = class {
81401
81377
  adapterVersion;
81402
81378
  capabilities;
@@ -81510,10 +81486,7 @@ async function resolveAgentExecutables(specification, context) {
81510
81486
  );
81511
81487
  }
81512
81488
  async function resolveAdapterExecutables(specification, context) {
81513
- if (specification instanceof DirectAcpAgentSpecification || specification instanceof InProcessAcpAgentSpecification) {
81514
- return await resolveAgentExecutables(specification, context);
81515
- }
81516
- throw new Error("Unsupported local Agent execution topology");
81489
+ return await resolveAgentExecutables(specification, context);
81517
81490
  }
81518
81491
  async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds, normalize4 = normalizeVersionOutput) {
81519
81492
  const result = await runBoundedProcess({
@@ -81534,7 +81507,6 @@ var init_executable_discovery = __esm({
81534
81507
  "src/agent/discovery/executable-discovery.ts"() {
81535
81508
  "use strict";
81536
81509
  init_executable();
81537
- init_agent_specification();
81538
81510
  init_version_output();
81539
81511
  }
81540
81512
  });
@@ -81635,7 +81607,7 @@ async function discoverAgent(specification, context) {
81635
81607
  return new MissingAdapter(specification);
81636
81608
  }
81637
81609
  for (const adapter of adapters) {
81638
- if (specification instanceof DirectAcpAgentSpecification && adapter.path !== agent.path) {
81610
+ if (adapter.path !== agent.path) {
81639
81611
  continue;
81640
81612
  }
81641
81613
  let adapterVersion = "";
@@ -81666,26 +81638,16 @@ async function discoverAgent(specification, context) {
81666
81638
  lastFailure = integrationProbeFailure(specification, error62);
81667
81639
  continue;
81668
81640
  }
81669
- const buildDefinition = (verifiedAdapterVersion, capabilities) => specification instanceof InProcessAcpAgentSpecification ? new InProcessAcpAgentDefinition(
81641
+ const buildDefinition = (verifiedAdapterVersion, capabilities) => new AcpAgentDefinition(
81670
81642
  specification.id,
81671
81643
  specification.label,
81672
81644
  agent.path,
81673
- specification.createEndpoint,
81645
+ specification.createConnection,
81674
81646
  launchEnvironment,
81675
81647
  agentVersion.length > 0 ? agentVersion : verifiedAdapterVersion,
81676
81648
  agent.identity,
81677
- capabilities
81678
- ) : new LocalAgentDefinition(
81679
- specification.id,
81680
- specification.label,
81681
- adapter.path,
81682
- specification.launchArguments,
81683
- launchEnvironment,
81684
- verifiedAdapterVersion,
81685
- agentVersion,
81686
- adapter.identity,
81687
- agent.identity,
81688
- capabilities
81649
+ capabilities,
81650
+ specification instanceof InProcessAcpAgentSpecification ? agentVersion : verifiedAdapterVersion
81689
81651
  );
81690
81652
  try {
81691
81653
  const readiness = await probeWithRetry(
@@ -82109,244 +82071,6 @@ var init_session_config_protocol = __esm({
82109
82071
  }
82110
82072
  });
82111
82073
 
82112
- // src/acp/connection/agent-connection.ts
82113
- import { spawn as spawn7 } from "node:child_process";
82114
- import { ndJsonStream as ndJsonStream3, RequestError as RequestError9 } from "@agentclientprotocol/sdk";
82115
- function requestErrorMessage(error62) {
82116
- const fallback = truncate2(error62.message, 500);
82117
- if (error62.message !== "Internal error" || !isRecord3(error62.data)) {
82118
- return fallback;
82119
- }
82120
- const agentError = error62.data["error"];
82121
- if (isRecord3(agentError)) {
82122
- const message = agentError["message"];
82123
- if (typeof message === "string" && message.length > 0) {
82124
- return truncate2(message, 500);
82125
- }
82126
- }
82127
- const details = error62.data["details"];
82128
- return typeof details === "string" && details.length > 0 ? truncate2(details, 500) : fallback;
82129
- }
82130
- function readableWebStream(input2) {
82131
- let streamOpen = true;
82132
- return new ReadableStream({
82133
- start(controller) {
82134
- input2.on("data", (chunk) => {
82135
- if (!streamOpen) {
82136
- return;
82137
- }
82138
- if (chunk instanceof Uint8Array) {
82139
- controller.enqueue(new Uint8Array(chunk));
82140
- return;
82141
- }
82142
- streamOpen = false;
82143
- controller.error(new Error("ACP process produced a non-binary chunk"));
82144
- });
82145
- input2.once("end", () => {
82146
- if (!streamOpen) {
82147
- return;
82148
- }
82149
- streamOpen = false;
82150
- controller.close();
82151
- });
82152
- input2.once("error", (error62) => {
82153
- if (!streamOpen) {
82154
- return;
82155
- }
82156
- streamOpen = false;
82157
- controller.error(error62);
82158
- });
82159
- },
82160
- cancel() {
82161
- streamOpen = false;
82162
- }
82163
- });
82164
- }
82165
- function createWritableAcpStream(output2) {
82166
- let outputFailure;
82167
- const pendingWriteFailures = /* @__PURE__ */ new Set();
82168
- const fail = (error62) => {
82169
- outputFailure = error62;
82170
- for (const reject2 of pendingWriteFailures) {
82171
- reject2(error62);
82172
- }
82173
- pendingWriteFailures.clear();
82174
- };
82175
- output2.on("error", fail);
82176
- output2.once("close", () => {
82177
- if (outputFailure === void 0) {
82178
- fail(new Error("ACP process input closed"));
82179
- }
82180
- });
82181
- return new WritableStream({
82182
- write(chunk) {
82183
- if (outputFailure !== void 0) {
82184
- return Promise.reject(outputFailure);
82185
- }
82186
- return new Promise((resolve21, reject2) => {
82187
- pendingWriteFailures.add(reject2);
82188
- output2.write(chunk, (error62) => {
82189
- pendingWriteFailures.delete(reject2);
82190
- if (error62) {
82191
- outputFailure = error62;
82192
- reject2(error62);
82193
- return;
82194
- }
82195
- if (outputFailure !== void 0) {
82196
- reject2(outputFailure);
82197
- return;
82198
- }
82199
- resolve21();
82200
- });
82201
- });
82202
- }
82203
- });
82204
- }
82205
- var AgentConnection;
82206
- var init_agent_connection = __esm({
82207
- "src/acp/connection/agent-connection.ts"() {
82208
- "use strict";
82209
- init_executable();
82210
- init_value_utils();
82211
- init_acp_error();
82212
- init_in_process_endpoint();
82213
- init_create_client();
82214
- AgentConnection = class {
82215
- connection;
82216
- termination;
82217
- #process;
82218
- constructor(agent, cwd, client2, onBackgroundActivity = () => {
82219
- }) {
82220
- if (agent.kind === "in-process-acp") {
82221
- const inProcess = agent.createEndpoint({
82222
- command: agent.command,
82223
- cwd,
82224
- environment: agent.environment,
82225
- onSessionUpdate: client2.onUpdate,
82226
- onBackgroundActivity
82227
- });
82228
- this.#process = { kind: "in-process", endpoint: inProcess };
82229
- this.termination = inProcess.terminated;
82230
- this.connection = createAcpClient(client2).connect(inProcess.app());
82231
- return;
82232
- }
82233
- const launch = executableLaunch2(agent.adapterPath, agent.arguments);
82234
- const child = spawn7(launch.command, [...launch.arguments], {
82235
- cwd,
82236
- ...platformSpawnOptions,
82237
- env: { ...process.env, ...agent.environment },
82238
- shell: false,
82239
- stdio: ["pipe", "pipe", "pipe"]
82240
- });
82241
- this.#process = { kind: "child", child };
82242
- const stdin = child.stdin;
82243
- const stdout = child.stdout;
82244
- const stderr = child.stderr;
82245
- if (stdin === null || stdout === null || stderr === null) {
82246
- child.kill("SIGKILL");
82247
- throw new AcpExecutionError("ACP process streams are unavailable");
82248
- }
82249
- stderr.setEncoding("utf8");
82250
- stderr.on("data", (chunk) => {
82251
- process.stderr.write(`[${agent.id}-acp] ${chunk}`);
82252
- });
82253
- this.termination = new Promise((resolve21) => {
82254
- child.once("error", (cause) => {
82255
- resolve21({ kind: "failed", error: new AcpExecutionError("The ACP process could not run", { cause }) });
82256
- });
82257
- child.once("exit", (code, signal) => {
82258
- resolve21({
82259
- kind: "failed",
82260
- error: new AcpExecutionError("The ACP process stopped", { cause: { code, signal } })
82261
- });
82262
- });
82263
- });
82264
- const stream = ndJsonStream3(createWritableAcpStream(stdin), readableWebStream(stdout));
82265
- let pendingUpdates = 0;
82266
- this.connection = createAcpClient({
82267
- onElicitation: client2.onElicitation,
82268
- onElicitationComplete: client2.onElicitationComplete,
82269
- onPermission: client2.onPermission,
82270
- // ACP notifications acknowledge transport writes, not their consumption.
82271
- // Stop reading the child while updates from the current chunk drain;
82272
- // the OS pipe then backpressures history replay instead of filling our queue.
82273
- onUpdate: async (notification) => {
82274
- pendingUpdates += 1;
82275
- stdout.pause();
82276
- try {
82277
- await client2.onUpdate(notification);
82278
- } finally {
82279
- pendingUpdates -= 1;
82280
- if (pendingUpdates === 0) {
82281
- stdout.resume();
82282
- }
82283
- }
82284
- }
82285
- }).connect(stream);
82286
- }
82287
- get inProcessAgent() {
82288
- return this.#process.kind === "in-process" ? this.#process.endpoint : null;
82289
- }
82290
- closeProcess = async () => {
82291
- try {
82292
- if (this.#process.kind === "in-process") {
82293
- await this.#process.endpoint.close();
82294
- return;
82295
- }
82296
- await stopProcessTree(this.#process.child);
82297
- } finally {
82298
- this.connection.close();
82299
- }
82300
- };
82301
- race = async (operation, exitMessage, signal) => {
82302
- let removeAbortListener = () => {
82303
- };
82304
- const aborted2 = new Promise((_resolve, reject2) => {
82305
- const rejectAbort = () => {
82306
- reject2(signal.reason ?? new Error("ACP request was cancelled"));
82307
- };
82308
- signal.addEventListener("abort", rejectAbort, { once: true });
82309
- removeAbortListener = () => {
82310
- signal.removeEventListener("abort", rejectAbort);
82311
- };
82312
- if (signal.aborted) {
82313
- rejectAbort();
82314
- }
82315
- });
82316
- try {
82317
- try {
82318
- return await Promise.race([
82319
- // The caller has already started operation. Even when cancellation
82320
- // won before entry, observe its later rejection during endpoint cleanup.
82321
- aborted2,
82322
- operation,
82323
- this.termination.then((termination) => {
82324
- const cause = acpEndpointTerminationError(termination);
82325
- throw new AcpExecutionError(exitMessage, { cause }, cause.code);
82326
- })
82327
- ]);
82328
- } catch (error62) {
82329
- signal.throwIfAborted();
82330
- if (error62 instanceof RequestError9 && error62.code === -32e3) {
82331
- throw new AcpExecutionError(
82332
- "Agent authentication is required",
82333
- { cause: error62 },
82334
- "authentication_required"
82335
- );
82336
- }
82337
- if (error62 instanceof RequestError9) {
82338
- throw new AcpExecutionError(requestErrorMessage(error62), { cause: error62 }, "acp_agent_error");
82339
- }
82340
- throw error62;
82341
- }
82342
- } finally {
82343
- removeAbortListener();
82344
- }
82345
- };
82346
- };
82347
- }
82348
- });
82349
-
82350
82074
  // src/acp/connection/agent-update-stream.ts
82351
82075
  import { setImmediate as yieldToRuntime } from "node:timers/promises";
82352
82076
  var MAX_PENDING_UPDATES, MAX_PENDING_BYTES, MAX_SELECTED_UPDATES, MAX_SELECTED_BYTES, MAX_RUNTIME_QUEUED_BYTES, UPDATES_PER_YIELD, runtimeQueuedBytes, updatesSinceYield, AgentUpdateStream;
@@ -82483,7 +82207,6 @@ var init_session_events = __esm({
82483
82207
  init_protocol();
82484
82208
  init_value_utils();
82485
82209
  init_acp_error();
82486
- init_agent_connection();
82487
82210
  init_agent_update_stream();
82488
82211
  init_session_config_protocol();
82489
82212
  MAXIMUM_REASONING_UPDATE_CHARACTERS = 1e6;
@@ -82527,9 +82250,9 @@ var init_session_events = __esm({
82527
82250
  kind: "commands",
82528
82251
  payload,
82529
82252
  commands: update.availableCommands.slice(0, 500).map((command) => ({
82530
- description: truncate2(command.description, 500),
82531
- inputHint: truncate2(command.input?.hint ?? "", 255),
82532
- name: truncate2(command.name, 128)
82253
+ description: truncate(command.description, 500),
82254
+ inputHint: truncate(command.input?.hint ?? "", 255),
82255
+ name: truncate(command.name, 128)
82533
82256
  })).filter((command) => command.name.length > 0)
82534
82257
  };
82535
82258
  break;
@@ -82546,10 +82269,10 @@ var init_session_events = __esm({
82546
82269
  case "session_info_update": {
82547
82270
  const changes = [];
82548
82271
  if (Object.hasOwn(update, "title")) {
82549
- changes.push({ kind: "title", value: truncate2(update.title ?? "", 500) });
82272
+ changes.push({ kind: "title", value: truncate(update.title ?? "", 500) });
82550
82273
  }
82551
82274
  if (Object.hasOwn(update, "updatedAt")) {
82552
- changes.push({ kind: "updated-at", value: truncate2(update.updatedAt ?? "", 128) });
82275
+ changes.push({ kind: "updated-at", value: truncate(update.updatedAt ?? "", 128) });
82553
82276
  }
82554
82277
  event = { kind: "info", payload, changes };
82555
82278
  break;
@@ -82594,21 +82317,23 @@ var init_session_events = __esm({
82594
82317
  onElicitation: options.interactions.onElicitation,
82595
82318
  onElicitationComplete: options.interactions.onElicitationComplete
82596
82319
  };
82597
- this.#connection = new AgentConnection(options.agent, options.cwd, client2, (active) => {
82598
- if (this.#lifetime.signal.aborted) {
82599
- return;
82320
+ this.#connection = options.agent.createConnection({
82321
+ cwd: options.cwd,
82322
+ client: client2,
82323
+ onBackgroundActivity: (active) => {
82324
+ if (this.#lifetime.signal.aborted) {
82325
+ return;
82326
+ }
82327
+ this.#backgroundActivity = active;
82328
+ this.#onBackgroundActivity(active);
82600
82329
  }
82601
- this.#backgroundActivity = active;
82602
- this.#onBackgroundActivity(active);
82603
82330
  });
82604
82331
  }
82605
82332
  get connection() {
82606
82333
  return this.#connection.connection;
82607
82334
  }
82608
- get inProcessAgent() {
82609
- return this.#connection.inProcessAgent;
82610
- }
82611
- agentSettingsModelEffort = () => this.#connection.inProcessAgent?.agentSettingsModelEffort?.() ?? null;
82335
+ initialize = (signal) => this.#connection.initialize(signal);
82336
+ agentSettingsModelEffort = () => this.#connection.agentSettingsModelEffort();
82612
82337
  race = (operation, exitMessage, signal) => this.#connection.race(operation, exitMessage, signal);
82613
82338
  closeProcess = async () => {
82614
82339
  this.#lifetime.abort(new DOMException("The adapter event subscription closed", "AbortError"));
@@ -82809,7 +82534,7 @@ var init_live_sessions = __esm({
82809
82534
  "ACP agent exited during steering",
82810
82535
  signal
82811
82536
  );
82812
- if (isRecord3(response)) {
82537
+ if (isRecord(response)) {
82813
82538
  const outcome = response["outcome"];
82814
82539
  if (outcome === "injected" || outcome === "startedNewTurn") {
82815
82540
  return outcome;
@@ -82834,7 +82559,7 @@ var init_live_sessions = __esm({
82834
82559
  renameSession = async (target, title2, signal) => {
82835
82560
  signal.throwIfAborted();
82836
82561
  const { connection, scope } = this.#resolve(target);
82837
- const normalized = truncate2(title2, 500);
82562
+ const normalized = truncate(title2, 500);
82838
82563
  if (normalized.length === 0) {
82839
82564
  throw new AcpExecutionError("The Session title cannot be empty", {}, "invalid_session_title");
82840
82565
  }
@@ -83714,10 +83439,7 @@ var init_retained_agent_processes = __esm({
83714
83439
  import { methods as methods11, PROTOCOL_VERSION as PROTOCOL_VERSION3 } from "@agentclientprotocol/sdk";
83715
83440
  async function validateAgentRuntime(agent, signal) {
83716
83441
  signal.throwIfAborted();
83717
- const unchanged = await Promise.all([
83718
- agent.kind === "acp-adapter-process" ? revalidateExecutable(agent.adapterIdentity) : Promise.resolve(true),
83719
- revalidateExecutable(agent.agentIdentity)
83720
- ]);
83442
+ const unchanged = await Promise.all(agent.runtimeExecutables.map((identity2) => revalidateExecutable(identity2)));
83721
83443
  signal.throwIfAborted();
83722
83444
  if (unchanged.some((result) => !result)) {
83723
83445
  throw new AcpExecutionError(
@@ -83728,16 +83450,10 @@ async function validateAgentRuntime(agent, signal) {
83728
83450
  }
83729
83451
  }
83730
83452
  async function initializeAgentConnection(connection, agentId, verifiedVersion, signal) {
83731
- if (connection.inProcessAgent !== null) {
83732
- await connection.race(
83733
- connection.inProcessAgent.initialize(signal),
83734
- "The Codex app-server exited during initialization",
83735
- signal
83736
- ).catch((cause) => {
83737
- signal.throwIfAborted();
83738
- throw new RetryableAcpInitializationError(cause);
83739
- });
83740
- }
83453
+ await connection.race(connection.initialize(signal), "The Agent runtime exited during initialization", signal).catch((cause) => {
83454
+ signal.throwIfAborted();
83455
+ throw new RetryableAcpInitializationError(cause);
83456
+ });
83741
83457
  const initialized = await connection.race(
83742
83458
  connection.connection.agent.request(
83743
83459
  methods11.agent.initialize,
@@ -83767,8 +83483,8 @@ async function initializeAgentConnection(connection, agentId, verifiedVersion, s
83767
83483
  }
83768
83484
  return {
83769
83485
  capabilities: normalizeAcpCapabilities(initialized),
83770
- agentName: truncate2(initialized.agentInfo?.title ?? initialized.agentInfo?.name ?? agentId, 255),
83771
- agentVersion: truncate2(
83486
+ agentName: truncate(initialized.agentInfo?.title ?? initialized.agentInfo?.name ?? agentId, 255),
83487
+ agentVersion: truncate(
83772
83488
  verifiedVersion.length > 0 ? verifiedVersion : initialized.agentInfo?.version ?? "",
83773
83489
  128
83774
83490
  )
@@ -90806,11 +90522,14 @@ function createCatalogAgentResolver(discover, readConfig, publish) {
90806
90522
  };
90807
90523
  }
90808
90524
  async function unchangedIdentity(agent, signal) {
90809
- if (!await revalidateExecutable(agent.agentIdentity)) {
90810
- return false;
90525
+ for (const identity2 of agent.runtimeExecutables) {
90526
+ signal.throwIfAborted();
90527
+ if (!await revalidateExecutable(identity2)) {
90528
+ return false;
90529
+ }
90811
90530
  }
90812
90531
  signal.throwIfAborted();
90813
- return agent.kind !== "acp-adapter-process" || await revalidateExecutable(agent.adapterIdentity);
90532
+ return true;
90814
90533
  }
90815
90534
  var init_resolve_catalog_agent = __esm({
90816
90535
  "src/runtime/catalog/resolve-catalog-agent.ts"() {
@@ -91778,9 +91497,9 @@ async function readJsonResponse(response) {
91778
91497
  }
91779
91498
  }
91780
91499
  function readRelayError(value) {
91781
- if (isRecord3(value)) {
91500
+ if (isRecord(value)) {
91782
91501
  const error62 = value["error"];
91783
- if (isRecord3(error62)) {
91502
+ if (isRecord(error62)) {
91784
91503
  const code = error62["code"];
91785
91504
  const message = error62["message"];
91786
91505
  if (typeof code === "string" && typeof message === "string") {
@@ -91791,7 +91510,7 @@ function readRelayError(value) {
91791
91510
  return new PairingClientError("pairing_failed", "The relay could not pair this machine");
91792
91511
  }
91793
91512
  function decodePairingResponse(value, credentialField, expectedKeys) {
91794
- if (!isRecord3(value) || !hasExactKeys2(value, expectedKeys)) {
91513
+ if (!isRecord(value) || !hasExactKeys2(value, expectedKeys)) {
91795
91514
  throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
91796
91515
  }
91797
91516
  const appId = value["appId"];
@@ -92110,7 +91829,7 @@ var init_agent_diagnostics = __esm({
92110
91829
  label;
92111
91830
  status = "ready";
92112
91831
  constructor(discovery) {
92113
- this.adapterVersion = discovery.agent.kind === "acp-adapter-process" ? discovery.agent.adapterVersion : discovery.agent.agentVersion;
91832
+ this.adapterVersion = discovery.agent.adapterVersion;
92114
91833
  this.agentVersion = discovery.agent.agentVersion;
92115
91834
  this.id = discovery.specification.id;
92116
91835
  this.label = discovery.specification.label;
@@ -92645,7 +92364,7 @@ var init_worker_lifecycle_log = __esm({
92645
92364
  });
92646
92365
 
92647
92366
  // src/daemon/lifecycle/worker-process.ts
92648
- import { spawn as spawn8 } from "node:child_process";
92367
+ import { spawn as spawn6 } from "node:child_process";
92649
92368
  import { isAbsolute as isAbsolute15 } from "node:path";
92650
92369
  async function decodeWorkerLaunch(value) {
92651
92370
  const { entry, executable, version: version2 } = workerLaunch.parse(value);
@@ -92694,7 +92413,7 @@ var init_worker_process = __esm({
92694
92413
  constructor(launch, signal, environment) {
92695
92414
  signal.throwIfAborted();
92696
92415
  this.launch = launch;
92697
- this.#child = spawn8(launch.executable, [launch.entry, "__worker"], {
92416
+ this.#child = spawn6(launch.executable, [launch.entry, "__worker"], {
92698
92417
  env: environment,
92699
92418
  windowsHide: true,
92700
92419
  stdio: ["ignore", "pipe", "pipe", "ipc"]
@@ -92711,7 +92430,7 @@ var init_worker_process = __esm({
92711
92430
  this.#drained.resolve();
92712
92431
  });
92713
92432
  this.#child.on("message", (value) => {
92714
- if (isRecord3(value) && value["kind"] === "worker-ready") {
92433
+ if (isRecord(value) && value["kind"] === "worker-ready") {
92715
92434
  if (value["version"] !== launch.version) {
92716
92435
  this.#started.reject(
92717
92436
  new WorkerStartupError(
@@ -93213,9 +92932,9 @@ var init_package2 = __esm({
93213
92932
  });
93214
92933
 
93215
92934
  // src/daemon/lifecycle/manager-client.ts
93216
- import { spawn as spawn9 } from "node:child_process";
92935
+ import { spawn as spawn7 } from "node:child_process";
93217
92936
  async function spawnManager(launch) {
93218
- const child = spawn9(launch.executable, [launch.entry, "__manager"], {
92937
+ const child = spawn7(launch.executable, [launch.entry, "__manager"], {
93219
92938
  detached: true,
93220
92939
  windowsHide: true,
93221
92940
  env: process.env,
@@ -93763,11 +93482,11 @@ function normalizeElicitationOptions(schema) {
93763
93482
  const oneOf = schema["oneOf"];
93764
93483
  if (Array.isArray(oneOf)) {
93765
93484
  for (const option of oneOf) {
93766
- if (isRecord3(option) && typeof option["const"] === "string") {
93485
+ if (isRecord(option) && typeof option["const"] === "string") {
93767
93486
  normalized.push({
93768
- description: truncate2(readString2(option["description"]), 500),
93769
- label: truncate2(readString2(option["title"], option["const"]), 255),
93770
- value: truncate2(option["const"], 500)
93487
+ description: truncate(readString(option["description"]), 500),
93488
+ label: truncate(readString(option["title"], option["const"]), 255),
93489
+ value: truncate(option["const"], 500)
93771
93490
  });
93772
93491
  }
93773
93492
  }
@@ -93783,7 +93502,7 @@ function normalizeElicitationOptions(schema) {
93783
93502
  return normalized.slice(0, 200);
93784
93503
  }
93785
93504
  const items = schema["items"];
93786
- if (!isRecord3(items)) {
93505
+ if (!isRecord(items)) {
93787
93506
  return normalized;
93788
93507
  }
93789
93508
  const anyOf = items["anyOf"];
@@ -93796,7 +93515,7 @@ function numericString(value) {
93796
93515
  return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
93797
93516
  }
93798
93517
  function normalizeElicitationFields(requestedSchema) {
93799
- if (!isRecord3(requestedSchema) || !isRecord3(requestedSchema["properties"])) {
93518
+ if (!isRecord(requestedSchema) || !isRecord(requestedSchema["properties"])) {
93800
93519
  return [];
93801
93520
  }
93802
93521
  const properties = requestedSchema["properties"];
@@ -93806,7 +93525,7 @@ function normalizeElicitationFields(requestedSchema) {
93806
93525
  );
93807
93526
  const normalized = [];
93808
93527
  for (const [name2, property] of Object.entries(properties)) {
93809
- if (!isRecord3(property)) {
93528
+ if (!isRecord(property)) {
93810
93529
  continue;
93811
93530
  }
93812
93531
  const type = elicitationFieldType(property["type"]);
@@ -93817,20 +93536,20 @@ function normalizeElicitationFields(requestedSchema) {
93817
93536
  normalized.push({
93818
93537
  defaultBooleanValue: typeof defaultValue === "boolean" ? defaultValue : false,
93819
93538
  defaultNumberValue: typeof defaultValue === "number" && Number.isFinite(defaultValue) ? defaultValue : 0,
93820
- defaultStringValue: typeof defaultValue === "string" ? truncate2(defaultValue, 1e4) : Array.isArray(defaultValue) ? truncate2(JSON.stringify(defaultValue), 1e4) : "",
93821
- description: truncate2(readString2(property["description"]), 500),
93822
- format: truncate2(readString2(property["format"]), 64),
93539
+ defaultStringValue: typeof defaultValue === "string" ? truncate(defaultValue, 1e4) : Array.isArray(defaultValue) ? truncate(JSON.stringify(defaultValue), 1e4) : "",
93540
+ description: truncate(readString(property["description"]), 500),
93541
+ format: truncate(readString(property["format"]), 64),
93823
93542
  hasDefaultValue: defaultValue !== void 0 && defaultValue !== null,
93824
93543
  maximum: numericString(property["maximum"]),
93825
93544
  maximumLength: numericString(property["maxLength"] ?? property["maxItems"]),
93826
93545
  minimum: numericString(property["minimum"]),
93827
93546
  minimumLength: numericString(property["minLength"] ?? property["minItems"]),
93828
- ...normalizedType === "string" && isRecord3(metadata) && metadata["io.mobius/multiline"] === true ? { multiline: true } : {},
93829
- name: truncate2(name2, 128),
93547
+ ...normalizedType === "string" && isRecord(metadata) && metadata["io.mobius/multiline"] === true ? { multiline: true } : {},
93548
+ name: truncate(name2, 128),
93830
93549
  options,
93831
- pattern: truncate2(readString2(property["pattern"]), 500),
93550
+ pattern: truncate(readString(property["pattern"]), 500),
93832
93551
  required: required2.has(name2),
93833
- title: truncate2(readString2(property["title"], name2), 255),
93552
+ title: truncate(readString(property["title"], name2), 255),
93834
93553
  type: normalizedType
93835
93554
  });
93836
93555
  }
@@ -93899,7 +93618,7 @@ function validateElicitationContent(encoded, requestedSchema) {
93899
93618
  "invalid_elicitation_response"
93900
93619
  );
93901
93620
  }
93902
- if (!isRecord3(decoded) || !isRecord3(requestedSchema) || !isRecord3(requestedSchema["properties"])) {
93621
+ if (!isRecord(decoded) || !isRecord(requestedSchema) || !isRecord(requestedSchema["properties"])) {
93903
93622
  throw new AcpExecutionError(
93904
93623
  "Elicitation response does not match the requested form",
93905
93624
  {},
@@ -93919,7 +93638,7 @@ function validateElicitationContent(encoded, requestedSchema) {
93919
93638
  const validated = {};
93920
93639
  for (const [name2, value] of Object.entries(decoded)) {
93921
93640
  const property = properties[name2];
93922
- if (!isRecord3(property)) {
93641
+ if (!isRecord(property)) {
93923
93642
  throw new AcpExecutionError(
93924
93643
  `Elicitation field ${name2} was not requested`,
93925
93644
  {},
@@ -94173,8 +93892,8 @@ var init_session_interactions = __esm({
94173
93892
  const interactionId = `permission-${crypto.randomUUID()}`;
94174
93893
  const options = request.options.slice(0, 20).map((option) => ({
94175
93894
  kind: option.kind,
94176
- name: truncate2(option.name, 255),
94177
- optionId: truncate2(option.optionId, 255)
93895
+ name: truncate(option.name, 255),
93896
+ optionId: truncate(option.optionId, 255)
94178
93897
  }));
94179
93898
  if (options.length === 0) {
94180
93899
  throw new AcpExecutionError(
@@ -94206,9 +93925,9 @@ var init_session_interactions = __esm({
94206
93925
  kind: SESSION_PERMISSION_REQUESTED_KIND,
94207
93926
  options,
94208
93927
  sessionId: this.#context.sessionId(),
94209
- title: truncate2(title2 ?? "Permission required", 500),
94210
- toolCallId: truncate2(request.toolCall.toolCallId, 255),
94211
- toolKind: truncate2(kind ?? "other", 64)
93928
+ title: truncate(title2 ?? "Permission required", 500),
93929
+ toolCallId: truncate(request.toolCall.toolCallId, 255),
93930
+ toolKind: truncate(kind ?? "other", 64)
94212
93931
  });
94213
93932
  return await pending.completion.promise;
94214
93933
  } finally {
@@ -94237,7 +93956,7 @@ var init_session_interactions = __esm({
94237
93956
  const schemaValue = Reflect.get(request, "requestedSchema");
94238
93957
  const requestedSchema = request.mode === "form" ? schemaValue : {};
94239
93958
  const elicitationIdValue = Reflect.get(request, "elicitationId");
94240
- const elicitationId = request.mode === "url" && typeof elicitationIdValue === "string" ? truncate2(elicitationIdValue, 255) : "";
93959
+ const elicitationId = request.mode === "url" && typeof elicitationIdValue === "string" ? truncate(elicitationIdValue, 255) : "";
94241
93960
  const pending = new PendingElicitation(interactionId, elicitationId, requestedSchema);
94242
93961
  this.#pendingElicitations.set(interactionId, pending);
94243
93962
  const abort = () => {
@@ -94252,10 +93971,10 @@ var init_session_interactions = __esm({
94252
93971
  fields: normalizeElicitationFields(requestedSchema),
94253
93972
  interactionId,
94254
93973
  kind: SESSION_ELICITATION_REQUESTED_KIND,
94255
- message: truncate2(request.message, 2e3),
93974
+ message: truncate(request.message, 2e3),
94256
93975
  mode: request.mode,
94257
93976
  sessionId: this.#context.sessionId(),
94258
- url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ? truncate2(readString2(Reflect.get(request, "url")), 4096) : ""
93977
+ url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ? truncate(readString(Reflect.get(request, "url")), 4096) : ""
94259
93978
  });
94260
93979
  return await pending.completion.promise;
94261
93980
  } finally {
@@ -94947,7 +94666,7 @@ var init_agent_session = __esm({
94947
94666
  * directory observes the same title transition.
94948
94667
  */
94949
94668
  renameSession = async (title2, signal) => {
94950
- const normalized = truncate2(title2, 500);
94669
+ const normalized = truncate(title2, 500);
94951
94670
  if (normalized.length === 0) {
94952
94671
  throw new AcpExecutionError("The Session title cannot be empty", {}, "invalid_session_title");
94953
94672
  }
@@ -95156,7 +94875,7 @@ var init_agent_session = __esm({
95156
94875
  }
95157
94876
  validatePromptContent(options, this.#capabilities);
95158
94877
  if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
95159
- this.#sessionTitle = truncate2(options.prompt, 500);
94878
+ this.#sessionTitle = truncate(options.prompt, 500);
95160
94879
  }
95161
94880
  this.#prompted = true;
95162
94881
  this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
@@ -95204,7 +94923,7 @@ var init_agent_session = __esm({
95204
94923
  code: failure2.code,
95205
94924
  commandId: options.commandId,
95206
94925
  kind: "prompt.failed",
95207
- message: truncate2(failure2.message, 500)
94926
+ message: truncate(failure2.message, 500)
95208
94927
  },
95209
94928
  type: "lifecycle-metadata"
95210
94929
  });
@@ -95270,7 +94989,7 @@ var init_agent_session = __esm({
95270
94989
  code: failure2.code,
95271
94990
  commandId: options.commandId,
95272
94991
  kind: "prompt.failed",
95273
- message: truncate2(failure2.message, 500)
94992
+ message: truncate(failure2.message, 500)
95274
94993
  },
95275
94994
  type: "lifecycle-metadata"
95276
94995
  });
@@ -99066,7 +98785,7 @@ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
99066
98785
  };
99067
98786
  return createHash9("sha256").update(
99068
98787
  JSON.stringify({
99069
- adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
98788
+ adapterVersion: agent.adapterVersion,
99070
98789
  agentId: agent.id,
99071
98790
  agentVersion: agent.agentVersion,
99072
98791
  modelEffort: revisionModelEffort,