@ycodium-ai/agent-grok 0.2.3238 → 0.2.3244

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 (2) hide show
  1. package/dist/index.js +147 -101
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -25201,6 +25201,83 @@ function createAcpConnection(options) {
25201
25201
  };
25202
25202
  }
25203
25203
 
25204
+ // ../../packages/ycodium-acp-executor/src/model-selection.ts
25205
+ function normalizeModelId(value) {
25206
+ return value?.trim() || void 0;
25207
+ }
25208
+ function modelSelectionStateFromSetup(setup) {
25209
+ const sessionModels = isRecord(setup.models) ? setup.models : void 0;
25210
+ const modelConfigId = extractModelConfigId(setup);
25211
+ const strategy = sessionModels === void 0 && modelConfigId !== void 0 ? "config-option" : "session/set_model";
25212
+ const modelConfigOption = modelConfigId === void 0 ? void 0 : findSessionConfigOption(setup.configOptions, modelConfigId);
25213
+ const configModel = modelConfigOption?.currentValue;
25214
+ const currentModelId = strategy === "config-option" ? typeof configModel === "string" ? normalizeModelId(configModel) : void 0 : typeof sessionModels?.["currentModelId"] === "string" ? normalizeModelId(sessionModels["currentModelId"]) : void 0;
25215
+ return {
25216
+ strategy,
25217
+ sessionModelsAdvertised: sessionModels !== void 0,
25218
+ modelConfigId,
25219
+ currentModelId,
25220
+ advertisedModelValues: strategy === "config-option" ? modelConfigOption === void 0 ? [] : collectSessionConfigOptionValues(modelConfigOption) : collectSessionModelIds(sessionModels),
25221
+ configOptions: setup.configOptions
25222
+ };
25223
+ }
25224
+
25225
+ // ../../packages/ycodium-acp-executor/src/mutex.ts
25226
+ var Mutex = class {
25227
+ locked = false;
25228
+ waiters = [];
25229
+ get isLocked() {
25230
+ return this.locked;
25231
+ }
25232
+ acquire() {
25233
+ if (!this.locked) {
25234
+ this.locked = true;
25235
+ return Promise.resolve();
25236
+ }
25237
+ return new Promise((resolve2) => {
25238
+ this.waiters.push(resolve2);
25239
+ });
25240
+ }
25241
+ tryAcquire() {
25242
+ if (this.locked) {
25243
+ return false;
25244
+ }
25245
+ this.locked = true;
25246
+ return true;
25247
+ }
25248
+ release() {
25249
+ const next = this.waiters.shift();
25250
+ if (next) {
25251
+ next();
25252
+ return;
25253
+ }
25254
+ this.locked = false;
25255
+ }
25256
+ async runExclusive(fn) {
25257
+ await this.acquire();
25258
+ try {
25259
+ return await fn();
25260
+ } finally {
25261
+ this.release();
25262
+ }
25263
+ }
25264
+ };
25265
+
25266
+ // ../../packages/ycodium-acp-executor/src/user-input-pending.ts
25267
+ var userInputAnswerOptionId = (question, answers) => {
25268
+ const answer = answers[question.id];
25269
+ const selected = typeof answer === "string" ? answer : Array.isArray(answer) && answer.length === 1 && typeof answer[0] === "string" ? answer[0] : void 0;
25270
+ return selected !== void 0 && question.options.some((option) => option.id === selected) ? selected : void 0;
25271
+ };
25272
+
25273
+ // ../../packages/ycodium-acp-executor/src/vendor-hooks.ts
25274
+ var defaultVendorHooks = {
25275
+ completedStopReason: (response) => response.stopReason
25276
+ };
25277
+
25278
+ // ../../packages/ycodium-acp-executor/src/executor/support.ts
25279
+ var DEFAULT_RESULT_DRAIN_TIMEOUT_MS = 2e3;
25280
+
25204
25281
  // ../../packages/ycodium-acp-executor/src/executor/lifecycle.ts
25205
25282
  function createExecutorLifecycle({
25206
25283
  failIfDisposed,
@@ -25343,16 +25420,30 @@ function createExecutorLifecycle({
25343
25420
  }
25344
25421
  };
25345
25422
  let disposing;
25346
- const dispose = () => {
25423
+ const dispose = (exitCode) => {
25347
25424
  if (disposing) return disposing;
25348
25425
  shared.disposing = true;
25349
- promptResults.stop();
25350
- settleAllApprovals("cancel");
25351
- settleAllUserInputs();
25352
- abortPendingSettlement("executor disposed");
25353
- notifyPromptSettled();
25354
- shared.abortLocalPrompt?.();
25355
25426
  disposing = (async () => {
25427
+ if (exitCode !== void 0) {
25428
+ let timer;
25429
+ await Promise.race([
25430
+ connection.closed.catch(() => void 0),
25431
+ new Promise((resolve2) => {
25432
+ timer = setTimeout(
25433
+ resolve2,
25434
+ options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
25435
+ );
25436
+ })
25437
+ ]);
25438
+ clearTimeout(timer);
25439
+ await promptResults.wait(void 0, true);
25440
+ }
25441
+ promptResults.stop();
25442
+ settleAllApprovals("cancel");
25443
+ settleAllUserInputs();
25444
+ abortPendingSettlement("executor disposed");
25445
+ notifyPromptSettled();
25446
+ shared.abortLocalPrompt?.();
25356
25447
  promptResults.finishUnreceived();
25357
25448
  await promptResults.wait();
25358
25449
  emit({
@@ -25360,7 +25451,10 @@ function createExecutorLifecycle({
25360
25451
  ...stamp(),
25361
25452
  provider: options.provider,
25362
25453
  threadId: options.threadId,
25363
- payload: { reason: "disposed" }
25454
+ payload: exitCode === void 0 ? { reason: "disposed" } : {
25455
+ reason: exitCode === null ? "process exited without an exit code" : `process exited with code ${exitCode}`,
25456
+ exitKind: exitCode === 0 ? "graceful" : "error"
25457
+ }
25364
25458
  });
25365
25459
  shared.disposed = true;
25366
25460
  shared.generation += 1;
@@ -25455,11 +25549,6 @@ var acpPromptFailureCategory = (error62, input2) => {
25455
25549
  return error62 instanceof AcpConnectionClosedError ? acpTransportIfEstablished(input2.sessionEstablished, input2.disposed) : void 0;
25456
25550
  };
25457
25551
 
25458
- // ../../packages/ycodium-acp-executor/src/vendor-hooks.ts
25459
- var defaultVendorHooks = {
25460
- completedStopReason: (response) => response.stopReason
25461
- };
25462
-
25463
25552
  // ../../packages/ycodium-acp-executor/src/executor/prompt.ts
25464
25553
  function createExecutorPrompt({
25465
25554
  isLive,
@@ -25565,8 +25654,12 @@ function createExecutorPrompt({
25565
25654
  }
25566
25655
  }
25567
25656
  };
25568
- const prompt = async (input2) => {
25657
+ const failIfPromptUnavailable = () => {
25569
25658
  failIfDisposed();
25659
+ if (shared.connectionClosed) throw new AcpExecutorDisposedError();
25660
+ };
25661
+ const prompt = async (input2) => {
25662
+ failIfPromptUnavailable();
25570
25663
  const started = requireStarted();
25571
25664
  let record3;
25572
25665
  const settle2 = (rest) => settleTurn({
@@ -25578,7 +25671,7 @@ function createExecutorPrompt({
25578
25671
  let turnId;
25579
25672
  await threadMutex.acquire();
25580
25673
  try {
25581
- failIfDisposed();
25674
+ failIfPromptUnavailable();
25582
25675
  turnId = selectPromptTurnId(
25583
25676
  input2,
25584
25677
  shared.promptsInFlight > 0 ? shared.activeTurnId : void 0,
@@ -25687,7 +25780,7 @@ function createExecutorPrompt({
25687
25780
  sessionEstablished: shared.startResult !== void 0,
25688
25781
  disposed: shared.disposed
25689
25782
  });
25690
- if (written && input2.onDispatched !== void 0 && !interruptedTurnIds.has(turnId)) {
25783
+ if (!interruptedTurnIds.has(turnId)) {
25691
25784
  const errorMessage = error62 instanceof Error && error62.message.trim() || "ACP prompt failed";
25692
25785
  if (settle2({
25693
25786
  turnId,
@@ -25695,7 +25788,7 @@ function createExecutorPrompt({
25695
25788
  state: "failed",
25696
25789
  errorMessage,
25697
25790
  ...failureCategory === void 0 ? {} : { failureCategory }
25698
- }))
25791
+ }) && written && input2.onDispatched !== void 0)
25699
25792
  options.log?.warn?.("turn failed after dispatch", {
25700
25793
  threadId: options.threadId,
25701
25794
  failure: errorMessage
@@ -25796,9 +25889,9 @@ function createPromptResults({
25796
25889
  }
25797
25890
  }
25798
25891
  };
25799
- const wait = async (turnId) => {
25892
+ const wait = async (turnId, includeUnreceived = false) => {
25800
25893
  const claimed = [...prompts.values()].filter(
25801
- (record3) => !record3.finished && record3.response !== void 0 && (turnId === void 0 || record3.turnId === turnId)
25894
+ (record3) => !record3.finished && (includeUnreceived || record3.response !== void 0) && (turnId === void 0 || record3.turnId === turnId)
25802
25895
  );
25803
25896
  if (claimed.length === 0) return;
25804
25897
  let timer;
@@ -25806,7 +25899,10 @@ function createPromptResults({
25806
25899
  const drained = await Promise.race([
25807
25900
  Promise.all(claimed.map((record3) => record3.done)).then(() => true),
25808
25901
  new Promise((resolve2) => {
25809
- timer = setTimeout(() => resolve2(false), options.resultDrainTimeoutMs ?? 2e3);
25902
+ timer = setTimeout(
25903
+ () => resolve2(false),
25904
+ options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
25905
+ );
25810
25906
  })
25811
25907
  ]);
25812
25908
  if (drained) return;
@@ -25830,13 +25926,6 @@ function createPromptResults({
25830
25926
  return { add, receive, reject, stop, complete, hasInterrupted, forget, wait, finishUnreceived };
25831
25927
  }
25832
25928
 
25833
- // ../../packages/ycodium-acp-executor/src/user-input-pending.ts
25834
- var userInputAnswerOptionId = (question, answers) => {
25835
- const answer = answers[question.id];
25836
- const selected = typeof answer === "string" ? answer : Array.isArray(answer) && answer.length === 1 && typeof answer[0] === "string" ? answer[0] : void 0;
25837
- return selected !== void 0 && question.options.some((option) => option.id === selected) ? selected : void 0;
25838
- };
25839
-
25840
25929
  // ../../packages/ycodium-acp-executor/src/executor/requests.ts
25841
25930
  function createExecutorRequests({
25842
25931
  emit,
@@ -26368,27 +26457,6 @@ function acpInitializePayload(clientInfo, overrides) {
26368
26457
  };
26369
26458
  }
26370
26459
 
26371
- // ../../packages/ycodium-acp-executor/src/model-selection.ts
26372
- function normalizeModelId(value) {
26373
- return value?.trim() || void 0;
26374
- }
26375
- function modelSelectionStateFromSetup(setup) {
26376
- const sessionModels = isRecord(setup.models) ? setup.models : void 0;
26377
- const modelConfigId = extractModelConfigId(setup);
26378
- const strategy = sessionModels === void 0 && modelConfigId !== void 0 ? "config-option" : "session/set_model";
26379
- const modelConfigOption = modelConfigId === void 0 ? void 0 : findSessionConfigOption(setup.configOptions, modelConfigId);
26380
- const configModel = modelConfigOption?.currentValue;
26381
- const currentModelId = strategy === "config-option" ? typeof configModel === "string" ? normalizeModelId(configModel) : void 0 : typeof sessionModels?.["currentModelId"] === "string" ? normalizeModelId(sessionModels["currentModelId"]) : void 0;
26382
- return {
26383
- strategy,
26384
- sessionModelsAdvertised: sessionModels !== void 0,
26385
- modelConfigId,
26386
- currentModelId,
26387
- advertisedModelValues: strategy === "config-option" ? modelConfigOption === void 0 ? [] : collectSessionConfigOptionValues(modelConfigOption) : collectSessionModelIds(sessionModels),
26388
- configOptions: setup.configOptions
26389
- };
26390
- }
26391
-
26392
26460
  // ../../packages/ycodium-acp-executor/src/runtime-mode.ts
26393
26461
  function isRecord5(value) {
26394
26462
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -26932,47 +27000,6 @@ function createExecutorUpdates({
26932
27000
  return { emitCompactionState, handleSessionUpdate };
26933
27001
  }
26934
27002
 
26935
- // ../../packages/ycodium-acp-executor/src/mutex.ts
26936
- var Mutex = class {
26937
- locked = false;
26938
- waiters = [];
26939
- get isLocked() {
26940
- return this.locked;
26941
- }
26942
- acquire() {
26943
- if (!this.locked) {
26944
- this.locked = true;
26945
- return Promise.resolve();
26946
- }
26947
- return new Promise((resolve2) => {
26948
- this.waiters.push(resolve2);
26949
- });
26950
- }
26951
- tryAcquire() {
26952
- if (this.locked) {
26953
- return false;
26954
- }
26955
- this.locked = true;
26956
- return true;
26957
- }
26958
- release() {
26959
- const next = this.waiters.shift();
26960
- if (next) {
26961
- next();
26962
- return;
26963
- }
26964
- this.locked = false;
26965
- }
26966
- async runExclusive(fn) {
26967
- await this.acquire();
26968
- try {
26969
- return await fn();
26970
- } finally {
26971
- this.release();
26972
- }
26973
- }
26974
- };
26975
-
26976
27003
  // ../../packages/ycodium-acp-executor/src/openCommands.ts
26977
27004
  function readOpenToolCalls(toolCalls, turnId) {
26978
27005
  const running = [];
@@ -27344,10 +27371,10 @@ function createAcpExecutor(options) {
27344
27371
  setNativeMode,
27345
27372
  compact,
27346
27373
  openToolCalls: () => readOpenToolCalls(toolCalls, shared.activeTurnId),
27347
- dispose: () => {
27374
+ dispose: (exitCode) => {
27348
27375
  disposeOnce ??= (async () => {
27349
27376
  try {
27350
- await disposeLifecycle();
27377
+ await disposeLifecycle(exitCode);
27351
27378
  } finally {
27352
27379
  await protocolLogSink?.close();
27353
27380
  }
@@ -27358,7 +27385,8 @@ function createAcpExecutor(options) {
27358
27385
  }
27359
27386
 
27360
27387
  // ../../packages/ycodium-acp-executor/src/session-registry.ts
27361
- function createAcpSessionRegistry(threads, stopBooked2) {
27388
+ function createAcpSessionRegistry(threads, stopBooked2, log) {
27389
+ const exits = /* @__PURE__ */ new WeakMap();
27362
27390
  const requireThread = (threadId) => {
27363
27391
  const booked = threads.get(threadId);
27364
27392
  if (!booked) throw new Error(`unknown thread ${threadId}`);
@@ -27367,7 +27395,8 @@ function createAcpSessionRegistry(threads, stopBooked2) {
27367
27395
  };
27368
27396
  const stopSession = (threadId, booked = threads.get(threadId)) => {
27369
27397
  if (!booked) return Promise.resolve();
27370
- booked.closing ??= Promise.resolve().then(() => stopBooked2(booked)).then(() => {
27398
+ const close = { exitCode: exits.get(booked), hasExited: () => exits.has(booked) };
27399
+ booked.closing ??= Promise.resolve().then(() => stopBooked2(booked, close)).then(() => {
27371
27400
  if (threads.get(threadId) === booked) threads.delete(threadId);
27372
27401
  }).catch((cause) => {
27373
27402
  if (threads.get(threadId) === booked) delete booked.closing;
@@ -27378,7 +27407,16 @@ function createAcpSessionRegistry(threads, stopBooked2) {
27378
27407
  const stopAll = () => Promise.all([...threads].map(([threadId, booked]) => stopSession(threadId, booked))).then(
27379
27408
  () => void 0
27380
27409
  );
27381
- return { requireThread, stopSession, stopAll };
27410
+ const registerSession = (threadId, booked) => {
27411
+ threads.set(threadId, booked);
27412
+ void booked.handle.exited.then(async (exitCode) => {
27413
+ exits.set(booked, exitCode);
27414
+ await stopSession(threadId, booked);
27415
+ }).catch((cause) => {
27416
+ log?.warn("ACP process exit cleanup failed", { threadId, error: String(cause) });
27417
+ });
27418
+ };
27419
+ return { requireThread, registerSession, stopSession, stopAll };
27382
27420
  }
27383
27421
 
27384
27422
  // ../../packages/ycodium-acp-executor/src/session-cleanup.ts
@@ -27391,8 +27429,11 @@ async function cleanupAcpSession(input2) {
27391
27429
  failures.push(new Error(`forwarding failed: ${String(cause)}`, { cause }));
27392
27430
  });
27393
27431
  for (const [step, cleanup] of [
27394
- ["executor.dispose", () => input2.executor.dispose()],
27395
- ["stopProcess", input2.stopProcess],
27432
+ ["executor.dispose", () => input2.executor.dispose(input2.processExit?.exitCode)],
27433
+ [
27434
+ "stopProcess",
27435
+ () => input2.processExit?.hasExited() ? Promise.resolve() : input2.stopProcess()
27436
+ ],
27396
27437
  ["forwarding", () => forwarding]
27397
27438
  ]) {
27398
27439
  try {
@@ -28917,11 +28958,12 @@ var EventBus = class {
28917
28958
  function nowIso() {
28918
28959
  return (/* @__PURE__ */ new Date()).toISOString();
28919
28960
  }
28920
- async function stopBooked(booked) {
28961
+ async function stopBooked(booked, processExit) {
28921
28962
  await cleanupAcpSession({
28922
28963
  executor: booked.executor,
28923
28964
  stopProcess: () => booked.handle.kill("SIGTERM"),
28924
- forwarding: booked.forwarding
28965
+ forwarding: booked.forwarding,
28966
+ processExit
28925
28967
  });
28926
28968
  }
28927
28969
  function modelIdFromSelection(selection) {
@@ -28937,7 +28979,11 @@ var createGrokInstance = (config2, host) => {
28937
28979
  const threads = /* @__PURE__ */ new Map();
28938
28980
  const signInOperations = /* @__PURE__ */ new Map();
28939
28981
  let disposed = false;
28940
- const { requireThread, stopSession, stopAll } = createAcpSessionRegistry(threads, stopBooked);
28982
+ const { requireThread, registerSession, stopSession, stopAll } = createAcpSessionRegistry(
28983
+ threads,
28984
+ stopBooked,
28985
+ host.log
28986
+ );
28941
28987
  const disposeOnce = createRetryableClose(async () => {
28942
28988
  const operations = [...signInOperations.values()];
28943
28989
  signInOperations.clear();
@@ -29176,7 +29222,7 @@ var createGrokInstance = (config2, host) => {
29176
29222
  ...started.modelId === void 0 ? {} : { model: started.modelId },
29177
29223
  ...input2.bindingGeneration === void 0 ? {} : { bindingGeneration: input2.bindingGeneration }
29178
29224
  };
29179
- threads.set(input2.threadId, {
29225
+ registerSession(input2.threadId, {
29180
29226
  session,
29181
29227
  turns: [],
29182
29228
  executor,
@@ -29355,7 +29401,7 @@ var executors = [
29355
29401
  ];
29356
29402
  var index_default = definePlugin({
29357
29403
  id: "agent-grok",
29358
- apiVersion: 25,
29404
+ apiVersion: 27,
29359
29405
  executors,
29360
29406
  activate(ctx) {
29361
29407
  ctx.log.info("grok executor ready");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-grok",
3
- "version": "0.2.3238",
3
+ "version": "0.2.3244",
4
4
  "description": "Grok executor: grok CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -21,8 +21,8 @@
21
21
  "@types/node": "24.12.4",
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
- "ycodium-acp-executor": "0.2.3238",
25
- "@ycodium-ai/plugin-api": "0.2.3238",
24
+ "@ycodium-ai/plugin-api": "0.2.3244",
25
+ "ycodium-acp-executor": "0.2.3244",
26
26
  "ycodium-executor-testing": "0.0.0"
27
27
  },
28
28
  "ycodium": {