@ycodium-ai/agent-antigravity 0.2.3608 → 0.2.3635

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1704,6 +1704,40 @@ var AcpExecutorTurnEndedError = class extends AcpExecutorError {
1704
1704
  this.name = "AcpExecutorTurnEndedError";
1705
1705
  }
1706
1706
  };
1707
+ var AcpExecutorOptionRejectedError = class extends AcpExecutorError {
1708
+ constructor(option, value, cause) {
1709
+ const detail = acpErrorDetail(cause);
1710
+ super(
1711
+ "provider-rejected",
1712
+ `The agent rejected the ${option}${value === void 0 ? "" : ` "${value}"`}${detail === void 0 ? "" : ` (${detail})`}. This turn was not sent.`
1713
+ );
1714
+ this.name = "AcpExecutorOptionRejectedError";
1715
+ }
1716
+ };
1717
+ var AcpExecutorOptionTimeoutError = class extends AcpExecutorError {
1718
+ constructor(option, value) {
1719
+ super(
1720
+ "provider-rejected",
1721
+ `The agent did not answer the ${option} "${value}" change in time. This turn was not sent.`
1722
+ );
1723
+ this.name = "AcpExecutorOptionTimeoutError";
1724
+ }
1725
+ };
1726
+ var AcpOptionWriteStoppedError = class extends Error {
1727
+ constructor() {
1728
+ super("option write stopped");
1729
+ this.name = "AcpOptionWriteStoppedError";
1730
+ }
1731
+ };
1732
+ function acpErrorDetail(cause) {
1733
+ if (typeof cause !== "object" || cause === null) return void 0;
1734
+ const message = cause.message;
1735
+ const data = cause.data;
1736
+ const parts = [message, data].filter(
1737
+ (part) => typeof part === "string" && part.trim().length > 0
1738
+ );
1739
+ return parts.length === 0 ? void 0 : parts.join(": ");
1740
+ }
1707
1741
  var AcpExecutorNotStartedError = class extends AcpExecutorError {
1708
1742
  constructor(message = "ACP session has not been started") {
1709
1743
  super("not-started", message);
@@ -1817,10 +1851,120 @@ var UnboundedEventStream = class {
1817
1851
  }
1818
1852
  };
1819
1853
 
1820
- // ../../packages/ycodium-acp-executor/src/util.ts
1854
+ // ../../packages/ycodium-acp-executor/src/config-options.ts
1821
1855
  function isRecord(value) {
1822
1856
  return typeof value === "object" && value !== null && !Array.isArray(value);
1823
1857
  }
1858
+ function asString(value) {
1859
+ return typeof value === "string" ? value : void 0;
1860
+ }
1861
+ function normalizedField(option, key) {
1862
+ return asString(option[key])?.trim().toLowerCase() ?? "";
1863
+ }
1864
+ function looksLikeEffortOption(option) {
1865
+ const id = normalizedField(option, "id");
1866
+ const name = normalizedField(option, "name");
1867
+ return id === "effort" || id === "reasoning" || name === "effort" || name === "reasoning" || name.includes("effort") || name.includes("reasoning") || normalizedField(option, "category") === "thought_level";
1868
+ }
1869
+ function flattenChoices(rawOptions, currentValue) {
1870
+ if (!Array.isArray(rawOptions)) return [];
1871
+ const out = [];
1872
+ const seen = /* @__PURE__ */ new Set();
1873
+ const push = (entry) => {
1874
+ if (!isRecord(entry)) return;
1875
+ const value = asString(entry["value"]);
1876
+ if (value === void 0 || seen.has(value)) return;
1877
+ seen.add(value);
1878
+ const description = asString(entry["description"])?.trim();
1879
+ const name = asString(entry["name"])?.trim();
1880
+ out.push({
1881
+ value,
1882
+ ...name ? { name } : {},
1883
+ label: name || value,
1884
+ ...description ? { description } : {},
1885
+ ...currentValue !== void 0 && currentValue === value ? { isDefault: true } : {}
1886
+ });
1887
+ };
1888
+ for (const entry of rawOptions) {
1889
+ if (isRecord(entry) && Array.isArray(entry["options"])) {
1890
+ for (const nested of entry["options"]) push(nested);
1891
+ continue;
1892
+ }
1893
+ push(entry);
1894
+ }
1895
+ return out;
1896
+ }
1897
+ function isConfigOption(entry, configId) {
1898
+ return isRecord(entry) && asString(entry["id"])?.trim() === configId.trim();
1899
+ }
1900
+ function findConfigOptionEntry(configOptions, configId) {
1901
+ return Array.isArray(configOptions) && configId.trim() !== "" ? configOptions.find(
1902
+ (entry) => isConfigOption(entry, configId)
1903
+ ) : void 0;
1904
+ }
1905
+ function withConfigOptionValue(configOptions, configId, value) {
1906
+ if (!Array.isArray(configOptions)) return configOptions;
1907
+ return configOptions.map(
1908
+ (option) => isConfigOption(option, configId) ? { ...option, currentValue: value } : option
1909
+ );
1910
+ }
1911
+ function pickEffortOption(configOptions) {
1912
+ if (!Array.isArray(configOptions)) return void 0;
1913
+ const candidates = configOptions.filter(isRecord).filter((option) => normalizedField(option, "type") === "select").filter(looksLikeEffortOption);
1914
+ return candidates.find((option) => normalizedField(option, "category") === "model_option") ?? candidates.find((option) => normalizedField(option, "id") === "effort") ?? candidates.find((option) => normalizedField(option, "category") === "thought_level") ?? candidates[0];
1915
+ }
1916
+ function findAcpEffortConfig(configOptions) {
1917
+ const picked = pickEffortOption(configOptions);
1918
+ if (picked === void 0) return void 0;
1919
+ const configId = asString(picked["id"])?.trim();
1920
+ if (!configId) return void 0;
1921
+ const currentValue = asString(picked["currentValue"])?.trim() || void 0;
1922
+ const choices = flattenChoices(picked["options"], currentValue);
1923
+ if (choices.length === 0) return void 0;
1924
+ return {
1925
+ configId,
1926
+ label: asString(picked["name"])?.trim() ?? "",
1927
+ choices,
1928
+ ...currentValue === void 0 ? {} : { currentValue }
1929
+ };
1930
+ }
1931
+ function acpModelChoicesFromConfigOptions(configOptions) {
1932
+ if (!Array.isArray(configOptions)) return void 0;
1933
+ const records = configOptions.filter(isRecord);
1934
+ const modelOption = records.find((option) => normalizedField(option, "category") === "model") ?? records.find(
1935
+ (option) => normalizedField(option, "id") === "model" && normalizedField(option, "type") === "select"
1936
+ );
1937
+ if (modelOption === void 0) return void 0;
1938
+ if (!asString(modelOption["id"])?.trim()) return void 0;
1939
+ return flattenChoices(modelOption["options"], asString(modelOption["currentValue"])?.trim());
1940
+ }
1941
+ function acpModelChoicesFromSessionModels(models) {
1942
+ if (!isRecord(models) || !Array.isArray(models["availableModels"])) return void 0;
1943
+ const currentModelId = asString(models["currentModelId"])?.trim();
1944
+ const out = [];
1945
+ const seen = /* @__PURE__ */ new Set();
1946
+ for (const entry of models["availableModels"]) {
1947
+ if (!isRecord(entry)) continue;
1948
+ const value = asString(entry["modelId"])?.trim();
1949
+ if (!value || seen.has(value)) continue;
1950
+ seen.add(value);
1951
+ const name = asString(entry["name"])?.trim();
1952
+ const description = asString(entry["description"])?.trim();
1953
+ out.push({
1954
+ value,
1955
+ ...name ? { name } : {},
1956
+ label: name || value,
1957
+ ...description ? { description } : {},
1958
+ ...currentModelId !== void 0 && currentModelId === value ? { isDefault: true } : {}
1959
+ });
1960
+ }
1961
+ return out;
1962
+ }
1963
+
1964
+ // ../../packages/ycodium-acp-executor/src/util.ts
1965
+ function isRecord2(value) {
1966
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1967
+ }
1824
1968
  function asTrimmedString(value) {
1825
1969
  if (typeof value !== "string") {
1826
1970
  return void 0;
@@ -1873,11 +2017,11 @@ function extractCommandFromTitle(title) {
1873
2017
  return backtickMatch?.[1]?.trim() || void 0;
1874
2018
  }
1875
2019
  function extractToolCommand(data, title) {
1876
- const item = isRecord(data?.["item"]) ? data["item"] : void 0;
1877
- const itemInput = item && isRecord(item["input"]) ? item["input"] : void 0;
1878
- const itemResult = item && isRecord(item["result"]) ? item["result"] : void 0;
1879
- const rawInput = isRecord(data?.["rawInput"]) ? data["rawInput"] : void 0;
1880
- const dataInput = isRecord(data?.["input"]) ? data["input"] : void 0;
2020
+ const item = isRecord2(data?.["item"]) ? data["item"] : void 0;
2021
+ const itemInput = item && isRecord2(item["input"]) ? item["input"] : void 0;
2022
+ const itemResult = item && isRecord2(item["result"]) ? item["result"] : void 0;
2023
+ const rawInput = isRecord2(data?.["rawInput"]) ? data["rawInput"] : void 0;
2024
+ const dataInput = isRecord2(data?.["input"]) ? data["input"] : void 0;
1881
2025
  const candidates = [
1882
2026
  normalizeCommandValue(item?.["command"]),
1883
2027
  normalizeCommandValue(itemInput?.["command"]),
@@ -1922,7 +2066,7 @@ function collectPaths(value, paths, seen, depth) {
1922
2066
  }
1923
2067
  return;
1924
2068
  }
1925
- if (!isRecord(value)) {
2069
+ if (!isRecord2(value)) {
1926
2070
  return;
1927
2071
  }
1928
2072
  for (const key of ["path", "filePath", "relativePath", "filename", "newPath", "oldPath"]) {
@@ -2000,7 +2144,7 @@ function deriveToolActivityPresentation(input2) {
2000
2144
  const title = asTrimmedString(input2.title);
2001
2145
  const detail = stripTrailingExitCode(asTrimmedString(input2.detail));
2002
2146
  const fallbackSummary = asTrimmedString(input2.fallbackSummary) ?? "Tool";
2003
- const data = isRecord(input2.data) ? input2.data : void 0;
2147
+ const data = isRecord2(input2.data) ? input2.data : void 0;
2004
2148
  const command = extractToolCommand(data, title);
2005
2149
  const primaryPath = extractPrimaryPath(data);
2006
2150
  const action = classifyToolAction({
@@ -2032,7 +2176,7 @@ function deriveToolActivityPresentation(input2) {
2032
2176
  };
2033
2177
  }
2034
2178
  if (action === "search") {
2035
- const rawInput = isRecord(data?.["rawInput"]) ? data["rawInput"] : void 0;
2179
+ const rawInput = isRecord2(data?.["rawInput"]) ? data["rawInput"] : void 0;
2036
2180
  const query = asTrimmedString(rawInput?.["query"]) ?? asTrimmedString(rawInput?.["pattern"]) ?? asTrimmedString(rawInput?.["searchTerm"]);
2037
2181
  return {
2038
2182
  summary: "Searched files",
@@ -2092,7 +2236,7 @@ function extractCommandFromTitle2(title) {
2092
2236
  return match?.[1]?.trim() || void 0;
2093
2237
  }
2094
2238
  function extractToolCallCommand(rawInput, title) {
2095
- if (isRecord(rawInput)) {
2239
+ if (isRecord2(rawInput)) {
2096
2240
  const directCommand = normalizeCommandValue2(rawInput["command"]);
2097
2241
  if (directCommand) {
2098
2242
  return directCommand;
@@ -2120,7 +2264,7 @@ function boundTailText(text, limit = TOOL_CALL_CONTENT_MAX_CHARS) {
2120
2264
  var boundToolCallOutputText = (text) => boundTailText(text);
2121
2265
  var RAW_OUTPUT_TEXT_FIELDS = ["content", "stdout", "stderr", "output"];
2122
2266
  function boundToolCallRawOutput(rawOutput) {
2123
- if (!isRecord(rawOutput)) {
2267
+ if (!isRecord2(rawOutput)) {
2124
2268
  return rawOutput;
2125
2269
  }
2126
2270
  let changed = false;
@@ -2301,14 +2445,7 @@ function extractModelConfigId(sessionResponse) {
2301
2445
  return configOptions.find((opt) => opt.id.trim() === "model" && opt.type === "select") ? "model" : void 0;
2302
2446
  }
2303
2447
  function findSessionConfigOption(configOptions, configId) {
2304
- if (!configOptions) {
2305
- return void 0;
2306
- }
2307
- const normalizedConfigId = configId.trim();
2308
- if (!normalizedConfigId) {
2309
- return void 0;
2310
- }
2311
- return configOptions.find((option) => option.id.trim() === normalizedConfigId);
2448
+ return findConfigOptionEntry(configOptions, configId);
2312
2449
  }
2313
2450
  function collectSessionConfigOptionValues(configOption) {
2314
2451
  if (configOption.type !== "select" || !configOption.options) {
@@ -2319,11 +2456,11 @@ function collectSessionConfigOptionValues(configOption) {
2319
2456
  );
2320
2457
  }
2321
2458
  function collectSessionModelIds(models) {
2322
- if (!isRecord(models) || !Array.isArray(models["availableModels"])) {
2459
+ if (!isRecord2(models) || !Array.isArray(models["availableModels"])) {
2323
2460
  return [];
2324
2461
  }
2325
2462
  return models["availableModels"].flatMap(
2326
- (model) => isRecord(model) && typeof model["modelId"] === "string" ? [model["modelId"]] : []
2463
+ (model) => isRecord2(model) && typeof model["modelId"] === "string" ? [model["modelId"]] : []
2327
2464
  );
2328
2465
  }
2329
2466
  function catalogModelLastSegment(value) {
@@ -2395,7 +2532,7 @@ function parseAvailableCommandsUpdate(params) {
2395
2532
  }
2396
2533
  const commands = [];
2397
2534
  for (const command of availableCommands) {
2398
- if (!isRecord(command)) {
2535
+ if (!isRecord2(command)) {
2399
2536
  continue;
2400
2537
  }
2401
2538
  const name = typeof command["name"] === "string" ? command["name"].trim() : "";
@@ -2403,7 +2540,7 @@ function parseAvailableCommandsUpdate(params) {
2403
2540
  continue;
2404
2541
  }
2405
2542
  const description = typeof command["description"] === "string" ? command["description"].trim() || void 0 : void 0;
2406
- const input2 = isRecord(command["input"]) ? command["input"] : void 0;
2543
+ const input2 = isRecord2(command["input"]) ? command["input"] : void 0;
2407
2544
  const inputHint = typeof input2?.["hint"] === "string" ? input2["hint"].trim() || void 0 : void 0;
2408
2545
  commands.push({
2409
2546
  name,
@@ -2457,7 +2594,7 @@ function boundToolCallRawPayload(params, update, toolCall) {
2457
2594
  }
2458
2595
  function textFromContentBlocks(blocks) {
2459
2596
  const parts = blocks.flatMap(
2460
- (block) => isRecord(block) && block["type"] === "text" && typeof block["text"] === "string" ? [block["text"]] : []
2597
+ (block) => isRecord2(block) && block["type"] === "text" && typeof block["text"] === "string" ? [block["text"]] : []
2461
2598
  );
2462
2599
  const joined = parts.join("");
2463
2600
  return joined.trim().length > 0 ? joined : void 0;
@@ -2482,7 +2619,7 @@ function parseSessionUpdateEvent(params) {
2482
2619
  const entries = Array.isArray(upd["entries"]) ? upd["entries"] : [];
2483
2620
  const plan = entries.map((entry, index) => ({
2484
2621
  step: readAcpText(entry, "content") ?? `Step ${index + 1}`,
2485
- status: normalizePlanStepStatus(isRecord(entry) ? entry["status"] : void 0)
2622
+ status: normalizePlanStepStatus(isRecord2(entry) ? entry["status"] : void 0)
2486
2623
  }));
2487
2624
  if (plan.length > 0) {
2488
2625
  events.push({
@@ -2522,7 +2659,7 @@ function parseSessionUpdateEvent(params) {
2522
2659
  }
2523
2660
  case "agent_message_chunk":
2524
2661
  case "agent_thought_chunk": {
2525
- const content = isRecord(upd["content"]) ? upd["content"] : void 0;
2662
+ const content = isRecord2(upd["content"]) ? upd["content"] : void 0;
2526
2663
  const contentType = content?.["type"];
2527
2664
  const streamKind = kind === "agent_thought_chunk" ? "reasoning_text" : "assistant_text";
2528
2665
  if (contentType === "text") {
@@ -2562,7 +2699,7 @@ function parseSessionUpdateEvent(params) {
2562
2699
  }
2563
2700
  case "compaction_summary_chunk": {
2564
2701
  const compactionId = readAcpText(upd, "compactionId");
2565
- const content = isRecord(upd["content"]) ? upd["content"] : void 0;
2702
+ const content = isRecord2(upd["content"]) ? upd["content"] : void 0;
2566
2703
  const text = content?.["type"] === "text" ? content["text"] : void 0;
2567
2704
  if (compactionId === void 0 || typeof text !== "string" || text.length === 0) break;
2568
2705
  events.push({ _tag: "CompactionSummaryChunk", compactionId, text });
@@ -24256,17 +24393,17 @@ function isResponseMessage(value) {
24256
24393
  function isNotificationMessage(value) {
24257
24394
  return isJsonRpcEnvelope(value) && !("id" in value) && typeof value["method"] === "string";
24258
24395
  }
24259
- function isRecord2(value) {
24396
+ function isRecord3(value) {
24260
24397
  return typeof value === "object" && value !== null;
24261
24398
  }
24262
24399
  function isJsonRpcEnvelope(value) {
24263
- return isRecord2(value) && value["jsonrpc"] === "2.0";
24400
+ return isRecord3(value) && value["jsonrpc"] === "2.0";
24264
24401
  }
24265
24402
  function isJsonRpcId(value) {
24266
24403
  return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
24267
24404
  }
24268
24405
  function isResponseShapedMessage(value) {
24269
- return isRecord2(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
24406
+ return isRecord3(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
24270
24407
  }
24271
24408
  function isResponseBatch(batch) {
24272
24409
  let hasValidCall = false;
@@ -24276,7 +24413,7 @@ function isResponseBatch(batch) {
24276
24413
  for (const entry of batch) {
24277
24414
  hasValidCall ||= isRequestMessage(entry) || isNotificationMessage(entry);
24278
24415
  hasValidResponse ||= isResponseMessage(entry);
24279
- if (!isRecord2(entry)) {
24416
+ if (!isRecord3(entry)) {
24280
24417
  continue;
24281
24418
  }
24282
24419
  hasCallShape ||= "method" in entry;
@@ -24291,13 +24428,13 @@ function isResponseBatch(batch) {
24291
24428
  return hasResponseShape && !hasCallShape;
24292
24429
  }
24293
24430
  function cancelRequestId(params) {
24294
- if (!isRecord2(params) || !isJsonRpcId(params["requestId"])) {
24431
+ if (!isRecord3(params) || !isJsonRpcId(params["requestId"])) {
24295
24432
  return void 0;
24296
24433
  }
24297
24434
  return params["requestId"];
24298
24435
  }
24299
24436
  function isErrorResponse(value) {
24300
- return isRecord2(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
24437
+ return isRecord3(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
24301
24438
  }
24302
24439
  var Handled = {
24303
24440
  /**
@@ -24842,7 +24979,7 @@ var Connection = class {
24842
24979
  if (this.abortController.signal.aborted) {
24843
24980
  return Promise.resolve();
24844
24981
  }
24845
- if (!isRecord2(message)) {
24982
+ if (!isRecord3(message)) {
24846
24983
  console.error("Invalid message", { message });
24847
24984
  return Promise.resolve();
24848
24985
  }
@@ -25245,7 +25382,7 @@ function ndJsonStream(output2, input2) {
25245
25382
  await writeJson(protocolErrorResponse(RequestError.parseError()));
25246
25383
  return;
25247
25384
  }
25248
- if (isRecord2(message) || Array.isArray(message)) {
25385
+ if (isRecord3(message) || Array.isArray(message)) {
25249
25386
  controller.enqueue(message);
25250
25387
  } else {
25251
25388
  await writeJson(protocolErrorResponse(RequestError.invalidRequest(message)));
@@ -26232,14 +26369,14 @@ var legacyClientNotificationMethods = /* @__PURE__ */ new Set([
26232
26369
  import * as NodeStream from "node:stream";
26233
26370
 
26234
26371
  // ../../packages/ycodium-acp-executor/src/jsonrpc.ts
26235
- function isRecord3(value) {
26372
+ function isRecord4(value) {
26236
26373
  return typeof value === "object" && value !== null;
26237
26374
  }
26238
26375
  function isJsonRpcId2(value) {
26239
26376
  return typeof value === "string" || typeof value === "number" && Number.isFinite(value);
26240
26377
  }
26241
26378
  function isJsonRpcEnvelope2(value) {
26242
- return isRecord3(value) && value["jsonrpc"] === "2.0";
26379
+ return isRecord4(value) && value["jsonrpc"] === "2.0";
26243
26380
  }
26244
26381
  function isRequestMessage2(value) {
26245
26382
  return isJsonRpcEnvelope2(value) && "id" in value && typeof value["method"] === "string" && isJsonRpcId2(value["id"]);
@@ -26259,7 +26396,7 @@ function isNotificationMessage2(value) {
26259
26396
  return isJsonRpcEnvelope2(value) && !("id" in value) && typeof value["method"] === "string";
26260
26397
  }
26261
26398
  function readJsonRpcError(value) {
26262
- if (!isRecord3(value) || typeof value["code"] !== "number" || typeof value["message"] !== "string") {
26399
+ if (!isRecord4(value) || typeof value["code"] !== "number" || typeof value["message"] !== "string") {
26263
26400
  return void 0;
26264
26401
  }
26265
26402
  return {
@@ -26332,11 +26469,11 @@ var KNOWN_SESSION_UPDATES = /* @__PURE__ */ new Set([
26332
26469
  "compaction_summary_chunk"
26333
26470
  ]);
26334
26471
  function isSessionUpdateEnvelope(payload) {
26335
- if (!isRecord3(payload) || typeof payload["sessionId"] !== "string") {
26472
+ if (!isRecord4(payload) || typeof payload["sessionId"] !== "string") {
26336
26473
  return false;
26337
26474
  }
26338
26475
  const update = payload["update"];
26339
- return isRecord3(update) && typeof update["sessionUpdate"] === "string";
26476
+ return isRecord4(update) && typeof update["sessionUpdate"] === "string";
26340
26477
  }
26341
26478
  function hasKnownVariantShape(update) {
26342
26479
  const kind = update["sessionUpdate"];
@@ -26344,7 +26481,7 @@ function hasKnownVariantShape(update) {
26344
26481
  return false;
26345
26482
  }
26346
26483
  if (kind === "user_message_chunk" || kind === "agent_message_chunk" || kind === "agent_thought_chunk") {
26347
- return isRecord3(update["content"]);
26484
+ return isRecord4(update["content"]);
26348
26485
  }
26349
26486
  return true;
26350
26487
  }
@@ -26533,6 +26670,10 @@ function createAcpConnection(options2) {
26533
26670
  );
26534
26671
  } catch {
26535
26672
  }
26673
+ try {
26674
+ waiter.onArrival?.();
26675
+ } catch {
26676
+ }
26536
26677
  if (Object.hasOwn(message, "error")) {
26537
26678
  const rpcError = readJsonRpcError(message["error"]);
26538
26679
  waiter.reject(
@@ -26663,7 +26804,7 @@ function createAcpConnection(options2) {
26663
26804
  options2.readable.on("end", onEnd);
26664
26805
  options2.readable.on("error", onError);
26665
26806
  options2.writable.once("error", onWritableError);
26666
- const begin = (method, params, promptId) => {
26807
+ const begin = (method, params, promptId, onArrival) => {
26667
26808
  failIfClosed();
26668
26809
  const id = nextRequestId;
26669
26810
  nextRequestId += 1;
@@ -26671,6 +26812,7 @@ function createAcpConnection(options2) {
26671
26812
  pending.set(String(id), {
26672
26813
  method,
26673
26814
  ...promptId === void 0 ? {} : { promptId },
26815
+ ...onArrival === void 0 ? {} : { onArrival },
26674
26816
  resolve: resolve6,
26675
26817
  reject
26676
26818
  });
@@ -26726,10 +26868,31 @@ function createAcpConnection(options2) {
26726
26868
  function normalizeModelId(value) {
26727
26869
  return value?.trim() || void 0;
26728
26870
  }
26871
+ function adoptReportedConfigOptions(state, configOptions) {
26872
+ const option = state.modelConfigId === void 0 ? void 0 : findConfigOptionEntry(configOptions, state.modelConfigId);
26873
+ const value = option?.["currentValue"];
26874
+ const reported = typeof value === "string" ? normalizeModelId(value) : void 0;
26875
+ if (reported === void 0) return { ...state, configOptions };
26876
+ const { modelUnconfirmed: _confirmed, ...known } = state;
26877
+ return { ...known, configOptions, currentModelId: reported };
26878
+ }
26879
+ function forgetConfigOptionValue(state, configId) {
26880
+ const forgetsModel = configId === void 0 || configId === state.modelConfigId;
26881
+ const configOptions = configId !== void 0 && Array.isArray(state.configOptions) ? state.configOptions.map((option) => {
26882
+ if (!isRecord2(option) || option["id"] !== configId) return option;
26883
+ const { currentValue: _forgotten, ...rest } = option;
26884
+ return rest;
26885
+ }) : state.configOptions;
26886
+ return {
26887
+ ...state,
26888
+ configOptions,
26889
+ ...forgetsModel ? { currentModelId: void 0, modelUnconfirmed: true } : {}
26890
+ };
26891
+ }
26729
26892
  function modelSelectionStateFromSetup(setup) {
26730
- const sessionModels = isRecord(setup.models) ? setup.models : void 0;
26893
+ const sessionModels = isRecord2(setup.models) ? setup.models : void 0;
26731
26894
  const modelConfigId = extractModelConfigId(setup);
26732
- const strategy = sessionModels === void 0 && modelConfigId !== void 0 ? "config-option" : "session/set_model";
26895
+ const strategy = modelConfigId !== void 0 ? "config-option" : "session/set_model";
26733
26896
  const modelConfigOption = modelConfigId === void 0 ? void 0 : findSessionConfigOption(setup.configOptions, modelConfigId);
26734
26897
  const configModel = modelConfigOption?.currentValue;
26735
26898
  const currentModelId = strategy === "config-option" ? typeof configModel === "string" ? normalizeModelId(configModel) : void 0 : typeof sessionModels?.["currentModelId"] === "string" ? normalizeModelId(sessionModels["currentModelId"]) : void 0;
@@ -26739,7 +26902,8 @@ function modelSelectionStateFromSetup(setup) {
26739
26902
  modelConfigId,
26740
26903
  currentModelId,
26741
26904
  advertisedModelValues: strategy === "config-option" ? modelConfigOption === void 0 ? [] : collectSessionConfigOptionValues(modelConfigOption) : collectSessionModelIds(sessionModels),
26742
- configOptions: setup.configOptions
26905
+ configOptions: setup.configOptions,
26906
+ catalogSetup: setup
26743
26907
  };
26744
26908
  }
26745
26909
 
@@ -26837,6 +27001,10 @@ function createExecutorLifecycle({
26837
27001
  if (targetTurnId !== void 0) {
26838
27002
  interruptedTurnIds.add(targetTurnId);
26839
27003
  }
27004
+ const optionWrites = shared.optionWriteStop;
27005
+ if (optionWrites !== void 0 && (targetTurnId === void 0 || optionWrites.turnId === targetTurnId)) {
27006
+ optionWrites.stop();
27007
+ }
26840
27008
  settleAllApprovals("cancel");
26841
27009
  settleAllUserInputs();
26842
27010
  abortPendingSettlement("turn cancelled");
@@ -27049,6 +27217,41 @@ function isAcpRequestPermissionParams(value) {
27049
27217
  return Array.isArray(record2["options"]);
27050
27218
  }
27051
27219
 
27220
+ // ../../packages/ycodium-acp-executor/src/apply-effort.ts
27221
+ var alignRequestedEffort = async (input2) => {
27222
+ const unchanged = { configOptions: input2.configOptions };
27223
+ const effort = findAcpEffortConfig(input2.configOptions);
27224
+ if (effort === void 0) return unchanged;
27225
+ const values = new Set(effort.choices.map((choice) => choice.value));
27226
+ const current = effort.currentValue;
27227
+ const requested = input2.requestedEffort?.trim() || void 0;
27228
+ const unsupportedEffort = requested !== void 0 && !values.has(requested) ? requested : void 0;
27229
+ const staleCurrent = current !== void 0 && !values.has(current);
27230
+ const fallback = input2.modelDefaultEffort !== void 0 && values.has(input2.modelDefaultEffort) ? input2.modelDefaultEffort : void 0;
27231
+ const target = requested !== void 0 && unsupportedEffort === void 0 ? requested : unsupportedEffort !== void 0 || staleCurrent ? fallback : void 0;
27232
+ const written = target === void 0 || target === current ? void 0 : await input2.write(effort.configId, target);
27233
+ const configOptions = written === void 0 ? input2.configOptions : written.configOptions;
27234
+ if (unsupportedEffort === void 0) return { configOptions };
27235
+ const confirmed = fallback !== void 0 && written?.reported === true && findAcpEffortConfig(written.configOptions)?.currentValue === fallback;
27236
+ return { configOptions, unsupportedEffort, ...confirmed ? { appliedEffort: fallback } : {} };
27237
+ };
27238
+
27239
+ // ../../packages/ycodium-acp-executor/src/reasoning-level-fallback.ts
27240
+ var REASONING_LEVEL_FALLBACK_CODE = "reasoning-level-fallback";
27241
+ function reasoningLevelFallbackWarning(input2) {
27242
+ const model = input2.model ?? "This model";
27243
+ const outcome = input2.appliedEffort === void 0 ? "so the agent picks this turn's level" : `so this turn uses its default, "${input2.appliedEffort}"`;
27244
+ return {
27245
+ message: `${model} does not offer the "${input2.requestedEffort}" reasoning effort, ${outcome}. Your saved choice is unchanged.`,
27246
+ detail: {
27247
+ code: REASONING_LEVEL_FALLBACK_CODE,
27248
+ ...input2.model === void 0 ? {} : { model: input2.model },
27249
+ requestedEffort: input2.requestedEffort,
27250
+ ...input2.appliedEffort === void 0 ? {} : { appliedEffort: input2.appliedEffort }
27251
+ }
27252
+ };
27253
+ }
27254
+
27052
27255
  // ../../packages/ycodium-acp-executor/src/failureCategory.ts
27053
27256
  var ACP_FAILURE_CATEGORIES = [
27054
27257
  "quota",
@@ -27389,6 +27592,8 @@ function createExecutorPrompt({
27389
27592
  threadMutex,
27390
27593
  promptMutex,
27391
27594
  applyRequestedModel,
27595
+ modelDefaultEffort,
27596
+ writeConfigOptionReported,
27392
27597
  notifyPromptSettled,
27393
27598
  shared,
27394
27599
  promptResults,
@@ -27482,6 +27687,57 @@ function createExecutorPrompt({
27482
27687
  }
27483
27688
  }
27484
27689
  };
27690
+ const alignTurnOptions = async (input2, sessionId, generation, isStale, signal) => {
27691
+ const applied = await applyRequestedModel({
27692
+ state: shared.modelSelectionState,
27693
+ acpSessionId: sessionId,
27694
+ requestedModelId: input2.requestedModelId,
27695
+ expectedGeneration: generation,
27696
+ signal
27697
+ });
27698
+ shared.modelSelectionState = applied;
27699
+ if (isStale()) return;
27700
+ const switched = applied.configOptions;
27701
+ let aligned;
27702
+ try {
27703
+ aligned = await alignRequestedEffort({
27704
+ configOptions: switched,
27705
+ write: (configId, value) => writeConfigOptionReported(sessionId, switched, configId, value, {
27706
+ option: "reasoning level",
27707
+ signal
27708
+ }),
27709
+ requestedEffort: input2.requestedEffort,
27710
+ modelDefaultEffort: modelDefaultEffort(applied)
27711
+ });
27712
+ } catch (error62) {
27713
+ throw error62 instanceof RequestError ? new AcpExecutorOptionRejectedError(
27714
+ "reasoning level",
27715
+ input2.requestedEffort?.trim(),
27716
+ error62
27717
+ ) : error62;
27718
+ }
27719
+ if (!isLive(generation)) throw new AcpExecutorDisposedError();
27720
+ if (aligned.configOptions !== switched) {
27721
+ shared.modelSelectionState = adoptReportedConfigOptions(
27722
+ shared.modelSelectionState,
27723
+ aligned.configOptions
27724
+ );
27725
+ }
27726
+ if (aligned.unsupportedEffort !== void 0) {
27727
+ emit({
27728
+ type: "runtime.warning",
27729
+ ...stamp(),
27730
+ provider: options2.provider,
27731
+ threadId: options2.threadId,
27732
+ ...shared.activeTurnId === void 0 ? {} : { turnId: shared.activeTurnId },
27733
+ payload: reasoningLevelFallbackWarning({
27734
+ model: applied.currentModelId,
27735
+ requestedEffort: aligned.unsupportedEffort,
27736
+ appliedEffort: aligned.appliedEffort
27737
+ })
27738
+ });
27739
+ }
27740
+ };
27485
27741
  const failIfPromptUnavailable = () => {
27486
27742
  failIfDisposed();
27487
27743
  if (shared.connectionClosed) throw new AcpExecutorDisposedError();
@@ -27489,7 +27745,7 @@ function createExecutorPrompt({
27489
27745
  const prompt = async (input2) => {
27490
27746
  failIfPromptUnavailable();
27491
27747
  const started = requireStarted();
27492
- let sessionId = started.sessionId;
27748
+ const sessionId = started.sessionId;
27493
27749
  let record2;
27494
27750
  const settle2 = (rest) => settleTurn({
27495
27751
  expectedGeneration: started.generation,
@@ -27576,32 +27832,34 @@ function createExecutorPrompt({
27576
27832
  failIfDisposed();
27577
27833
  const queuedTurnId = turnId;
27578
27834
  const isStale = () => interruptedTurnIds.has(queuedTurnId) || input2.expectedActiveTurnId !== void 0 && shared.activeTurnId !== queuedTurnId;
27579
- if (!isStale()) {
27835
+ if (!isStale() && input2.expectedActiveTurnId === void 0) {
27836
+ const optionWrites = new AbortController();
27837
+ shared.optionWriteStop = { turnId, stop: () => optionWrites.abort() };
27580
27838
  try {
27581
- const applied = await applyRequestedModel({
27582
- state: shared.modelSelectionState,
27583
- acpSessionId: sessionId,
27584
- setup: shared.startResult?.sessionSetupResult ?? {},
27585
- requestedModelId: input2.requestedModelId,
27586
- expectedGeneration: started.generation
27587
- });
27588
- shared.modelSelectionState = applied.state;
27589
- sessionId = applied.sessionId;
27590
- record2.sessionId = applied.sessionId;
27839
+ await alignTurnOptions(
27840
+ input2,
27841
+ sessionId,
27842
+ started.generation,
27843
+ isStale,
27844
+ optionWrites.signal
27845
+ );
27591
27846
  } catch (error62) {
27592
- const failureCategory = readAcpFailureCategory(error62);
27593
- if (failureCategory === "model-unavailable") {
27594
- const errorMessage2 = error62 instanceof Error && error62.message.trim().length > 0 ? error62.message : "Requested model is not in this agent's catalog. This turn was not sent.";
27595
- settle2({
27596
- turnId,
27597
- stopReason: "error",
27598
- state: "failed",
27599
- errorMessage: errorMessage2,
27600
- failureCategory
27601
- });
27602
- throw error62 instanceof Error ? withFailureCategory(error62, failureCategory) : error62;
27847
+ if (error62 instanceof AcpExecutorDisposedError) throw error62;
27848
+ if (isStale()) {
27849
+ settle2({ turnId, stopReason: "cancelled", state: "cancelled" });
27850
+ return { threadId: options2.threadId, turnId, stopReason: "cancelled" };
27603
27851
  }
27604
- throw error62;
27852
+ const failureCategory = readAcpFailureCategory(error62);
27853
+ settle2({
27854
+ turnId,
27855
+ stopReason: "error",
27856
+ state: "failed",
27857
+ errorMessage: error62 instanceof Error && error62.message.trim() || "Switching the model or reasoning level failed. This turn was not sent.",
27858
+ ...failureCategory === void 0 ? {} : { failureCategory }
27859
+ });
27860
+ throw error62 instanceof Error ? withFailureCategory(error62, failureCategory) : error62;
27861
+ } finally {
27862
+ shared.optionWriteStop = void 0;
27605
27863
  }
27606
27864
  }
27607
27865
  failIfDisposed();
@@ -27984,7 +28242,7 @@ function createExecutorRequests({
27984
28242
  pendingUserInputs.delete(requestId);
27985
28243
  pending.resolve({
27986
28244
  kind: "answered",
27987
- answers: isRecord(answers) ? answers : {}
28245
+ answers: isRecord2(answers) ? answers : {}
27988
28246
  });
27989
28247
  };
27990
28248
  return {
@@ -28159,129 +28417,6 @@ function createExecutorRuntime({
28159
28417
  };
28160
28418
  }
28161
28419
 
28162
- // ../../packages/ycodium-acp-executor/src/config-options.ts
28163
- function isRecord4(value) {
28164
- return typeof value === "object" && value !== null && !Array.isArray(value);
28165
- }
28166
- function asString(value) {
28167
- return typeof value === "string" ? value : void 0;
28168
- }
28169
- function normalizedField(option, key) {
28170
- return asString(option[key])?.trim().toLowerCase() ?? "";
28171
- }
28172
- function looksLikeEffortOption(option) {
28173
- const id = normalizedField(option, "id");
28174
- const name = normalizedField(option, "name");
28175
- return id === "effort" || id === "reasoning" || name === "effort" || name === "reasoning" || name.includes("effort") || name.includes("reasoning") || normalizedField(option, "category") === "thought_level";
28176
- }
28177
- function flattenChoices(rawOptions, currentValue) {
28178
- if (!Array.isArray(rawOptions)) return [];
28179
- const out = [];
28180
- const seen = /* @__PURE__ */ new Set();
28181
- const push = (entry) => {
28182
- if (!isRecord4(entry)) return;
28183
- const value = asString(entry["value"]);
28184
- if (value === void 0 || seen.has(value)) return;
28185
- seen.add(value);
28186
- const description = asString(entry["description"])?.trim();
28187
- const name = asString(entry["name"])?.trim();
28188
- out.push({
28189
- value,
28190
- ...name ? { name } : {},
28191
- label: name || value,
28192
- ...description ? { description } : {},
28193
- ...currentValue !== void 0 && currentValue === value ? { isDefault: true } : {}
28194
- });
28195
- };
28196
- for (const entry of rawOptions) {
28197
- if (isRecord4(entry) && Array.isArray(entry["options"])) {
28198
- for (const nested of entry["options"]) push(nested);
28199
- continue;
28200
- }
28201
- push(entry);
28202
- }
28203
- return out;
28204
- }
28205
- function findAcpEffortConfig(configOptions) {
28206
- if (!Array.isArray(configOptions)) return void 0;
28207
- const candidates = configOptions.filter(isRecord4).filter((option) => normalizedField(option, "type") === "select").filter(looksLikeEffortOption);
28208
- if (candidates.length === 0) return void 0;
28209
- const picked = candidates.find((option) => normalizedField(option, "category") === "model_option") ?? candidates.find((option) => normalizedField(option, "id") === "effort") ?? candidates.find((option) => normalizedField(option, "category") === "thought_level") ?? candidates[0];
28210
- if (picked === void 0) return void 0;
28211
- const configId = asString(picked["id"])?.trim();
28212
- if (!configId) return void 0;
28213
- const choices = flattenChoices(picked["options"], asString(picked["currentValue"])?.trim());
28214
- if (choices.length === 0) return void 0;
28215
- return {
28216
- configId,
28217
- label: asString(picked["name"])?.trim() ?? "",
28218
- choices
28219
- };
28220
- }
28221
- function acpModelChoicesFromConfigOptions(configOptions) {
28222
- if (!Array.isArray(configOptions)) return void 0;
28223
- const records = configOptions.filter(isRecord4);
28224
- const modelOption = records.find((option) => normalizedField(option, "category") === "model") ?? records.find(
28225
- (option) => normalizedField(option, "id") === "model" && normalizedField(option, "type") === "select"
28226
- );
28227
- if (modelOption === void 0) return void 0;
28228
- if (!asString(modelOption["id"])?.trim()) return void 0;
28229
- return flattenChoices(modelOption["options"], asString(modelOption["currentValue"])?.trim());
28230
- }
28231
- function acpModelChoicesFromSessionModels(models) {
28232
- if (!isRecord4(models) || !Array.isArray(models["availableModels"])) return void 0;
28233
- const currentModelId = asString(models["currentModelId"])?.trim();
28234
- const out = [];
28235
- const seen = /* @__PURE__ */ new Set();
28236
- for (const entry of models["availableModels"]) {
28237
- if (!isRecord4(entry)) continue;
28238
- const value = asString(entry["modelId"])?.trim();
28239
- if (!value || seen.has(value)) continue;
28240
- seen.add(value);
28241
- const name = asString(entry["name"])?.trim();
28242
- const description = asString(entry["description"])?.trim();
28243
- out.push({
28244
- value,
28245
- ...name ? { name } : {},
28246
- label: name || value,
28247
- ...description ? { description } : {},
28248
- ...currentModelId !== void 0 && currentModelId === value ? { isDefault: true } : {}
28249
- });
28250
- }
28251
- return out;
28252
- }
28253
-
28254
- // ../../packages/ycodium-acp-executor/src/apply-effort.ts
28255
- var applyRequestedEffort = async (input2) => {
28256
- const requested = input2.requestedEffort?.trim();
28257
- if (!requested) return;
28258
- const effort = findAcpEffortConfig(input2.configOptions);
28259
- if (effort === void 0) return;
28260
- const matched = effort.choices.find((choice) => choice.value === requested);
28261
- if (matched === void 0) {
28262
- input2.log?.info("requested effort is not in the agent catalog; keeping its own", {
28263
- requestedEffort: requested,
28264
- advertised: effort.choices.map((choice) => choice.value)
28265
- });
28266
- return;
28267
- }
28268
- if (matched.isDefault === true) return;
28269
- if (!input2.isLive(input2.expectedGeneration)) return;
28270
- try {
28271
- await input2.connection.request("session/set_config_option", {
28272
- sessionId: input2.acpSessionId,
28273
- configId: effort.configId,
28274
- value: requested
28275
- });
28276
- } catch (error62) {
28277
- input2.log?.info("setting the effort level failed; the session keeps its own", {
28278
- requestedEffort: requested,
28279
- configId: effort.configId,
28280
- error: error62 instanceof Error ? error62.message : String(error62)
28281
- });
28282
- }
28283
- };
28284
-
28285
28420
  // ../../packages/ycodium-acp-executor/src/config-option-wiring.ts
28286
28421
  var VENDOR_CATEGORY_PREFIX = "_";
28287
28422
  var ACP_CONFIG_CATEGORY_HANDLING = {
@@ -28295,7 +28430,7 @@ var ACP_CONFIG_CATEGORY_HANDLING = {
28295
28430
  },
28296
28431
  thought_level: {
28297
28432
  consumed: true,
28298
- via: "config-options.ts:findAcpEffortConfig \u2192 apply-effort.ts:applyRequestedEffort"
28433
+ via: "config-options.ts:findAcpEffortConfig \u2192 apply-effort.ts:alignRequestedEffort"
28299
28434
  },
28300
28435
  model_option: {
28301
28436
  consumed: true,
@@ -28364,13 +28499,14 @@ function judgeRequestedModel(input2) {
28364
28499
  if (requested === void 0 || requested === current) return { kind: "keep" };
28365
28500
  const hasCatalog = input2.state.advertisedModelValues.length > 0;
28366
28501
  const hasCurrent = current !== void 0;
28367
- if (!hasCatalog && !hasCurrent) return { kind: "keep" };
28368
- const canSwitch = input2.state.strategy === "session/set_model" && input2.state.sessionModelsAdvertised || input2.state.strategy === "config-option" && input2.state.modelConfigId !== void 0;
28502
+ if (!hasCatalog && !hasCurrent && input2.state.modelUnconfirmed !== true) return { kind: "keep" };
28503
+ const canSwitch = canSwitchModel(input2.state);
28369
28504
  const value = hasCatalog ? matchAdvertisedModelValue(requested, input2.state.advertisedModelValues) : void 0;
28370
28505
  if (value !== void 0 && value === current) return { kind: "keep" };
28371
28506
  if (value !== void 0 && canSwitch) return { kind: "switch", value };
28372
- return input2.refreshed ? { kind: "unavailable" } : { kind: "refresh" };
28507
+ return { kind: "refresh" };
28373
28508
  }
28509
+ var canSwitchModel = (state) => state.strategy === "session/set_model" && state.sessionModelsAdvertised || state.strategy === "config-option" && state.modelConfigId !== void 0;
28374
28510
  function modelUnavailableError(requestedModelId, currentModelId) {
28375
28511
  const current = currentModelId ?? "its own model";
28376
28512
  return withFailureCategory(
@@ -28480,6 +28616,7 @@ function acpCurrentModeId(setup) {
28480
28616
  // ../../packages/ycodium-acp-executor/src/executor/session.ts
28481
28617
  function createExecutorSession({
28482
28618
  options: options2,
28619
+ hooks,
28483
28620
  connection,
28484
28621
  isLive,
28485
28622
  emit,
@@ -28501,131 +28638,140 @@ function createExecutorSession({
28501
28638
  shared.sessionOpensInFlight -= 1;
28502
28639
  }
28503
28640
  };
28504
- const openFreshSession = async (expectedGeneration) => {
28505
- const initialized = shared.initializeResult;
28506
- if (initialized === void 0) {
28507
- throw new Error("no handshake");
28641
+ const optionDeadlineMs = () => options2.modelCatalogRefreshTimeoutMs ?? MODEL_CATALOG_REFRESH_TIMEOUT_MS;
28642
+ const within = async (work, signal, onTimeout) => {
28643
+ void work.catch(() => void 0);
28644
+ let timer;
28645
+ let onStop;
28646
+ const bound = new Promise((_resolve, reject) => {
28647
+ timer = setTimeout(() => reject(onTimeout()), optionDeadlineMs());
28648
+ onStop = () => reject(new AcpOptionWriteStoppedError());
28649
+ if (signal?.aborted === true) onStop();
28650
+ else signal?.addEventListener("abort", onStop, { once: true });
28651
+ });
28652
+ try {
28653
+ return await Promise.race([work, bound]);
28654
+ } finally {
28655
+ clearTimeout(timer);
28656
+ if (onStop !== void 0) signal?.removeEventListener("abort", onStop);
28508
28657
  }
28509
- const mcpServers = filterMcpServersByAgentCapabilities(
28510
- options2.mcpServers ?? [],
28511
- initialized.agentCapabilities
28658
+ };
28659
+ const awaitOptionReply = async (pending, configId, write) => {
28660
+ void pending.response.catch(() => void 0);
28661
+ try {
28662
+ return await within(
28663
+ pending.written.then(() => pending.response),
28664
+ write.signal,
28665
+ () => new AcpExecutorOptionTimeoutError(write.option, write.value)
28666
+ );
28667
+ } catch (error62) {
28668
+ if (error62 instanceof AcpExecutorOptionTimeoutError || error62 instanceof AcpOptionWriteStoppedError) {
28669
+ shared.modelSelectionState = forgetConfigOptionValue(shared.modelSelectionState, configId);
28670
+ }
28671
+ throw error62;
28672
+ }
28673
+ };
28674
+ const writeConfigOptionReported = async (sessionId, configOptions, configId, value, write) => {
28675
+ const issuedAt = shared.configUpdateSeq;
28676
+ let arrivedAt = Number.POSITIVE_INFINITY;
28677
+ const pending = connection.begin(
28678
+ "session/set_config_option",
28679
+ { sessionId, configId, value },
28680
+ void 0,
28681
+ () => {
28682
+ arrivedAt = shared.configUpdateSeq;
28683
+ }
28512
28684
  );
28513
- const additionalDirectories = options2.additionalDirectories !== void 0 && options2.additionalDirectories.length > 0 ? { additionalDirectories: options2.additionalDirectories } : {};
28514
- const created = await requestSession("session/new", {
28515
- cwd: options2.cwd,
28516
- mcpServers,
28517
- ...additionalDirectories
28518
- });
28519
- if (!isLive(expectedGeneration)) {
28520
- throw new AcpExecutorDisposedError();
28685
+ const reply = await awaitOptionReply(pending, configId, { ...write, value });
28686
+ await connection.awaitInboundIdle();
28687
+ const ours = shared.configOptionUpdates.get(sessionId);
28688
+ if (ours !== void 0 && ours.seq > arrivedAt) {
28689
+ return { configOptions: ours.configOptions, reported: true };
28521
28690
  }
28522
- if (created.sessionId === void 0 || created.sessionId.length === 0) {
28523
- throw new Error("session/new did not return a session id");
28691
+ if (reply?.configOptions !== void 0) {
28692
+ return { configOptions: reply.configOptions, reported: true };
28524
28693
  }
28525
- return { sessionId: created.sessionId, setup: created };
28694
+ const base = ours !== void 0 && ours.seq > issuedAt ? ours.configOptions : configOptions;
28695
+ return { configOptions: withConfigOptionValue(base, configId, value), reported: false };
28526
28696
  };
28697
+ const writeConfigOption = async (...args) => (await writeConfigOptionReported(...args)).configOptions;
28527
28698
  const switchModel = async (input2) => {
28528
28699
  let configOptions = input2.state.configOptions;
28529
- if (input2.state.strategy === "config-option") {
28530
- const switched = await connection.request(
28531
- "session/set_config_option",
28532
- { sessionId: input2.sessionId, configId: input2.state.modelConfigId, value: input2.value }
28700
+ const write = { option: "model", signal: input2.signal };
28701
+ if (input2.state.strategy === "config-option" && input2.state.modelConfigId !== void 0) {
28702
+ configOptions = await writeConfigOption(
28703
+ input2.sessionId,
28704
+ configOptions,
28705
+ input2.state.modelConfigId,
28706
+ input2.value,
28707
+ write
28533
28708
  );
28534
- configOptions = switched?.configOptions ?? configOptions;
28535
28709
  } else {
28536
- await connection.request("session/set_model", {
28710
+ const before = shared.configOptionUpdates.get(input2.sessionId);
28711
+ const pending = connection.begin("session/set_model", {
28537
28712
  sessionId: input2.sessionId,
28538
28713
  modelId: input2.value
28539
28714
  });
28715
+ await awaitOptionReply(pending, void 0, { ...write, value: input2.value });
28716
+ await connection.awaitInboundIdle();
28717
+ const reported = shared.configOptionUpdates.get(input2.sessionId);
28718
+ if (reported !== void 0 && reported !== before) {
28719
+ configOptions = reported.configOptions;
28720
+ }
28540
28721
  }
28541
28722
  if (!isLive(input2.expectedGeneration)) {
28542
28723
  throw new AcpExecutorDisposedError();
28543
28724
  }
28544
- return { ...input2.state, currentModelId: input2.value, configOptions };
28545
- };
28546
- const adoptReopenedSession = (applied) => {
28547
- if (shared.sessionId === void 0 && shared.startResult === void 0) return;
28548
- const setup = applied.setup;
28549
- shared.sessionId = applied.sessionId;
28550
- shared.modelSelectionState = applied.state;
28551
- shared.modeState = parseSessionModeState(setup);
28552
- if (shared.startResult !== void 0) {
28553
- shared.startResult = {
28554
- ...shared.startResult,
28555
- sessionId: applied.sessionId,
28556
- sessionSetupResult: setup,
28557
- modelConfigId: extractModelConfigId(setup),
28558
- modelId: applied.state.currentModelId
28559
- };
28560
- }
28725
+ const { modelUnconfirmed: _confirmed, ...known } = input2.state;
28726
+ return adoptReportedConfigOptions({ ...known, currentModelId: input2.value }, configOptions);
28561
28727
  };
28562
28728
  const applyRequestedModel = async (input2) => {
28563
- async function applyOnce(state, sessionId, setup, refreshed) {
28564
- const requestedModelId = normalizeModelId(input2.requestedModelId) ?? "";
28729
+ const requestedModelId = normalizeModelId(input2.requestedModelId) ?? "";
28730
+ const switchTo = (value) => switchModel({
28731
+ state: input2.state,
28732
+ sessionId: input2.acpSessionId,
28733
+ value,
28734
+ expectedGeneration: input2.expectedGeneration,
28735
+ signal: input2.signal
28736
+ });
28737
+ try {
28565
28738
  const judgment = judgeRequestedModel({
28566
- state,
28567
- requestedModelId: input2.requestedModelId,
28568
- refreshed
28739
+ state: input2.state,
28740
+ requestedModelId: input2.requestedModelId
28569
28741
  });
28570
- if (judgment.kind === "keep") return { state, sessionId, setup };
28571
- if (judgment.kind === "unavailable") {
28572
- throw modelUnavailableError(requestedModelId, state.currentModelId);
28573
- }
28574
- if (judgment.kind === "switch") {
28575
- return {
28576
- state: await switchModel({
28577
- state,
28578
- sessionId,
28579
- value: judgment.value,
28580
- expectedGeneration: input2.expectedGeneration
28581
- }),
28582
- sessionId,
28583
- setup
28584
- };
28585
- }
28586
- return refreshAndRejudge(requestedModelId);
28587
- }
28588
- async function refreshAndRejudge(requestedModelId) {
28589
- const timeoutMs = options2.modelCatalogRefreshTimeoutMs ?? MODEL_CATALOG_REFRESH_TIMEOUT_MS;
28590
- let timedOut = false;
28591
- const timeoutError = new ModelCatalogRefreshTimeoutError();
28592
- let timer;
28593
- const work = (async () => {
28594
- await options2.refreshCatalogForSend?.();
28595
- if (timedOut) throw timeoutError;
28596
- const reopened = await openFreshSession(input2.expectedGeneration);
28597
- if (timedOut) throw timeoutError;
28598
- const next = modelSelectionStateFromSetup(reopened.setup);
28599
- const applied = await applyOnce(next, reopened.sessionId, reopened.setup, true);
28600
- if (timedOut) throw timeoutError;
28601
- adoptReopenedSession(applied);
28602
- return applied;
28603
- })();
28604
- void work.then(
28605
- () => void 0,
28606
- () => void 0
28742
+ if (judgment.kind === "keep") return input2.state;
28743
+ if (judgment.kind === "switch") return await switchTo(judgment.value);
28744
+ await refreshCatalog(requestedModelId, input2.signal);
28745
+ if (!isLive(input2.expectedGeneration)) throw new AcpExecutorDisposedError();
28746
+ if (!canSwitchModel(input2.state)) {
28747
+ throw modelUnavailableError(requestedModelId, input2.state.currentModelId);
28748
+ }
28749
+ const switched = await switchTo(requestedModelId);
28750
+ return switched.advertisedModelValues.includes(requestedModelId) ? switched : {
28751
+ ...switched,
28752
+ advertisedModelValues: [...switched.advertisedModelValues, requestedModelId]
28753
+ };
28754
+ } catch (error62) {
28755
+ throw error62 instanceof RequestError ? withFailureCategory(
28756
+ new AcpExecutorOptionRejectedError("model", requestedModelId, error62),
28757
+ "model-unavailable"
28758
+ ) : error62;
28759
+ }
28760
+ };
28761
+ const refreshCatalog = async (requestedModelId, signal) => {
28762
+ try {
28763
+ await within(
28764
+ Promise.resolve(options2.refreshCatalogForSend?.()),
28765
+ signal,
28766
+ () => new ModelCatalogRefreshTimeoutError()
28607
28767
  );
28608
- const deadline = new Promise((_resolve, reject) => {
28609
- timer = setTimeout(() => {
28610
- timedOut = true;
28611
- connection.abandonPending(timeoutError);
28612
- reject(timeoutError);
28613
- }, timeoutMs);
28614
- });
28615
- try {
28616
- return await Promise.race([work, deadline]);
28617
- } catch (error62) {
28618
- if (error62 instanceof AcpExecutorDisposedError) throw error62;
28619
- if (timedOut || error62 instanceof ModelCatalogRefreshTimeoutError) {
28620
- throw modelRefreshTimedOutError(requestedModelId);
28621
- }
28622
- if (readAcpFailureCategory(error62) === "model-unavailable") throw error62;
28623
- throw modelRefreshFailedError(requestedModelId, error62);
28624
- } finally {
28625
- if (timer !== void 0) clearTimeout(timer);
28768
+ } catch (error62) {
28769
+ if (error62 instanceof AcpOptionWriteStoppedError) throw error62;
28770
+ if (error62 instanceof ModelCatalogRefreshTimeoutError) {
28771
+ throw modelRefreshTimedOutError(requestedModelId);
28626
28772
  }
28773
+ throw modelRefreshFailedError(requestedModelId, error62);
28627
28774
  }
28628
- return applyOnce(input2.state, input2.acpSessionId, input2.setup, false);
28629
28775
  };
28630
28776
  const startOnce = async (expectedGeneration) => {
28631
28777
  const initializePayload = acpInitializePayload(
@@ -28700,26 +28846,45 @@ function createExecutorSession({
28700
28846
  categories: unhandledCategories
28701
28847
  });
28702
28848
  }
28703
- const openedSetup = setup;
28704
- const appliedModel = await applyRequestedModel({
28705
- state: modelSelectionStateFromSetup(openedSetup),
28849
+ let nextModelSelectionState = await applyRequestedModel({
28850
+ state: modelSelectionStateFromSetup(setup),
28706
28851
  acpSessionId: nextSessionId,
28707
- setup: openedSetup,
28708
28852
  requestedModelId: options2.requestedModelId,
28709
28853
  expectedGeneration
28710
28854
  });
28711
- nextSessionId = appliedModel.sessionId;
28712
- setup = appliedModel.setup;
28713
- const nextModelSelectionState = appliedModel.state;
28714
- await applyRequestedEffort({
28715
- connection,
28716
- log: options2.log,
28717
- isLive,
28718
- configOptions: nextModelSelectionState.configOptions,
28719
- acpSessionId: nextSessionId,
28720
- requestedEffort: options2.requestedEffort,
28721
- expectedGeneration
28722
- });
28855
+ if (!isLive(expectedGeneration)) {
28856
+ throw new AcpExecutorDisposedError();
28857
+ }
28858
+ try {
28859
+ const opened = nextModelSelectionState.configOptions;
28860
+ const aligned = await alignRequestedEffort({
28861
+ configOptions: opened,
28862
+ write: (configId, value) => writeConfigOptionReported(nextSessionId, opened, configId, value, {
28863
+ option: "reasoning level"
28864
+ }),
28865
+ requestedEffort: options2.requestedEffort,
28866
+ modelDefaultEffort: modelDefaultEffort(nextModelSelectionState)
28867
+ });
28868
+ nextModelSelectionState = adoptReportedConfigOptions(
28869
+ nextModelSelectionState,
28870
+ aligned.configOptions
28871
+ );
28872
+ if (aligned.unsupportedEffort !== void 0) {
28873
+ options2.log?.info("requested effort is not offered by this model; using its default", {
28874
+ requestedEffort: aligned.unsupportedEffort,
28875
+ modelId: nextModelSelectionState.currentModelId
28876
+ });
28877
+ }
28878
+ } catch (error62) {
28879
+ const effortConfigId = findAcpEffortConfig(nextModelSelectionState.configOptions)?.configId;
28880
+ if (error62 instanceof AcpExecutorOptionTimeoutError && effortConfigId !== void 0) {
28881
+ nextModelSelectionState = forgetConfigOptionValue(nextModelSelectionState, effortConfigId);
28882
+ }
28883
+ options2.log?.info("setting the effort level failed; the session keeps its own", {
28884
+ requestedEffort: options2.requestedEffort,
28885
+ error: error62 instanceof Error ? error62.message : String(error62)
28886
+ });
28887
+ }
28723
28888
  if (options2.beforeApplyResult) {
28724
28889
  await options2.beforeApplyResult();
28725
28890
  }
@@ -28779,6 +28944,7 @@ function createExecutorSession({
28779
28944
  );
28780
28945
  return shared.startInFlight;
28781
28946
  };
28947
+ const modelDefaultEffort = (state) => state.currentModelId === void 0 ? void 0 : hooks.modelDefaultEffort?.({ setup: state.catalogSetup, modelId: state.currentModelId });
28782
28948
  const requireStarted = () => {
28783
28949
  failIfDisposed();
28784
28950
  if (!shared.sessionId || !shared.startResult) {
@@ -28806,7 +28972,14 @@ function createExecutorSession({
28806
28972
  modeId
28807
28973
  });
28808
28974
  };
28809
- return { applyRequestedModel, start, requireStarted, setNativeMode };
28975
+ return {
28976
+ applyRequestedModel,
28977
+ modelDefaultEffort,
28978
+ writeConfigOptionReported,
28979
+ start,
28980
+ requireStarted,
28981
+ setNativeMode
28982
+ };
28810
28983
  }
28811
28984
 
28812
28985
  // ../../packages/ycodium-acp-executor/src/executor/settlement.ts
@@ -28870,14 +29043,14 @@ function createExecutorSettlement({
28870
29043
 
28871
29044
  // ../../packages/ycodium-acp-executor/src/executor/subagent-sessions.ts
28872
29045
  function parseState(raw) {
28873
- if (!isRecord(raw)) return { status: void 0, error: void 0 };
29046
+ if (!isRecord2(raw)) return { status: void 0, error: void 0 };
28874
29047
  const state = raw["state"];
28875
29048
  if (state === "running") return { status: "running", error: void 0 };
28876
29049
  if (state === "requires_action") return { status: "waiting", error: void 0 };
28877
29050
  if (state !== "idle") return { status: void 0, error: void 0 };
28878
29051
  const stopReason = raw["stopReason"];
28879
- const error62 = isRecord(raw["error"]) ? asTrimmedString(raw["error"]["message"]) : void 0;
28880
- if (stopReason === "error" || isRecord(raw["error"])) return { status: "failed", error: error62 };
29052
+ const error62 = isRecord2(raw["error"]) ? asTrimmedString(raw["error"]["message"]) : void 0;
29053
+ if (stopReason === "error" || isRecord2(raw["error"])) return { status: "failed", error: error62 };
28881
29054
  if (stopReason === "cancelled") return { status: "cancelled", error: void 0 };
28882
29055
  return { status: "idle", error: void 0 };
28883
29056
  }
@@ -28893,7 +29066,7 @@ function childLinkage(childId, record2) {
28893
29066
  function createSubagentSessionTracker(registry2) {
28894
29067
  const observe = (notification, ctx) => {
28895
29068
  const update = notification.update;
28896
- if (!isRecord(update) || update["sessionUpdate"] !== "subagent_update") return [];
29069
+ if (!isRecord2(update) || update["sessionUpdate"] !== "subagent_update") return [];
28897
29070
  const childId = asTrimmedString(update["sessionId"]);
28898
29071
  if (childId === void 0 || ctx.ownSessionIds.has(childId)) return [];
28899
29072
  const outerId = notification.sessionId;
@@ -29119,6 +29292,21 @@ function createExecutorUpdates({
29119
29292
  markChildSession
29120
29293
  });
29121
29294
  const handleSessionUpdate = (params) => {
29295
+ const update = params.update;
29296
+ const reportedOptions = update["configOptions"];
29297
+ if (update["sessionUpdate"] === "config_option_update" && Array.isArray(reportedOptions)) {
29298
+ shared.configUpdateSeq += 1;
29299
+ shared.configOptionUpdates.set(params.sessionId, {
29300
+ configOptions: reportedOptions,
29301
+ seq: shared.configUpdateSeq
29302
+ });
29303
+ if (params.sessionId === shared.sessionId) {
29304
+ shared.modelSelectionState = adoptReportedConfigOptions(
29305
+ shared.modelSelectionState,
29306
+ reportedOptions
29307
+ );
29308
+ }
29309
+ }
29122
29310
  const parsed = parseSessionUpdateEvent(params);
29123
29311
  if (parsed.modeId && shared.modeState) {
29124
29312
  shared.modeState = {
@@ -29434,7 +29622,10 @@ function createAcpExecutor(options2) {
29434
29622
  droppedReplayUpdates: 0,
29435
29623
  ownSessionIds: /* @__PURE__ */ new Set(),
29436
29624
  childSessions: createChildSessionRegistry(),
29437
- sessionOpensInFlight: 0
29625
+ sessionOpensInFlight: 0,
29626
+ configOptionUpdates: /* @__PURE__ */ new Map(),
29627
+ optionWriteStop: void 0,
29628
+ configUpdateSeq: 0
29438
29629
  };
29439
29630
  const interruptedTurnIds = /* @__PURE__ */ new Set();
29440
29631
  const approvals = createApprovalGate({
@@ -29583,8 +29774,16 @@ function createAcpExecutor(options2) {
29583
29774
  };
29584
29775
  options2.readable.once("end", onInputDead);
29585
29776
  options2.readable.once("error", onInputDead);
29586
- const { applyRequestedModel, start, requireStarted, setNativeMode } = createExecutorSession({
29777
+ const {
29778
+ applyRequestedModel,
29779
+ modelDefaultEffort,
29780
+ writeConfigOptionReported,
29781
+ start,
29782
+ requireStarted,
29783
+ setNativeMode
29784
+ } = createExecutorSession({
29587
29785
  options: options2,
29786
+ hooks,
29588
29787
  connection,
29589
29788
  isLive,
29590
29789
  emit,
@@ -29610,6 +29809,8 @@ function createAcpExecutor(options2) {
29610
29809
  threadMutex,
29611
29810
  promptMutex,
29612
29811
  applyRequestedModel,
29812
+ modelDefaultEffort,
29813
+ writeConfigOptionReported,
29613
29814
  notifyPromptSettled,
29614
29815
  shared
29615
29816
  });
@@ -29877,9 +30078,9 @@ async function openAcpProbeHandshake(input2) {
29877
30078
  }
29878
30079
  }
29879
30080
  function acpAgentVersion(initializeResult) {
29880
- if (!isRecord(initializeResult)) return null;
30081
+ if (!isRecord2(initializeResult)) return null;
29881
30082
  const agentInfo = initializeResult["agentInfo"];
29882
- return isRecord(agentInfo) ? asTrimmedString(agentInfo["version"]) ?? null : null;
30083
+ return isRecord2(agentInfo) ? asTrimmedString(agentInfo["version"]) ?? null : null;
29883
30084
  }
29884
30085
  var MAX_VERSION_OUTPUT_BYTES = 64 * 1024;
29885
30086
 
@@ -34586,7 +34787,7 @@ var executors = [
34586
34787
  ];
34587
34788
  var index_default = definePlugin({
34588
34789
  id: "agent-antigravity",
34589
- apiVersion: 49,
34790
+ apiVersion: 50,
34590
34791
  executors,
34591
34792
  activate(ctx) {
34592
34793
  const runtime = createRuntimeManager({