@ycodium-ai/agent-dsh 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 +4 -4
package/dist/index.js CHANGED
@@ -32524,6 +32524,83 @@ function createAcpConnection(options) {
32524
32524
  };
32525
32525
  }
32526
32526
 
32527
+ // ../../packages/ycodium-acp-executor/src/model-selection.ts
32528
+ function normalizeModelId(value) {
32529
+ return value?.trim() || void 0;
32530
+ }
32531
+ function modelSelectionStateFromSetup(setup) {
32532
+ const sessionModels = isRecord(setup.models) ? setup.models : void 0;
32533
+ const modelConfigId = extractModelConfigId(setup);
32534
+ const strategy = sessionModels === void 0 && modelConfigId !== void 0 ? "config-option" : "session/set_model";
32535
+ const modelConfigOption = modelConfigId === void 0 ? void 0 : findSessionConfigOption(setup.configOptions, modelConfigId);
32536
+ const configModel = modelConfigOption?.currentValue;
32537
+ const currentModelId = strategy === "config-option" ? typeof configModel === "string" ? normalizeModelId(configModel) : void 0 : typeof sessionModels?.["currentModelId"] === "string" ? normalizeModelId(sessionModels["currentModelId"]) : void 0;
32538
+ return {
32539
+ strategy,
32540
+ sessionModelsAdvertised: sessionModels !== void 0,
32541
+ modelConfigId,
32542
+ currentModelId,
32543
+ advertisedModelValues: strategy === "config-option" ? modelConfigOption === void 0 ? [] : collectSessionConfigOptionValues(modelConfigOption) : collectSessionModelIds(sessionModels),
32544
+ configOptions: setup.configOptions
32545
+ };
32546
+ }
32547
+
32548
+ // ../../packages/ycodium-acp-executor/src/mutex.ts
32549
+ var Mutex = class {
32550
+ locked = false;
32551
+ waiters = [];
32552
+ get isLocked() {
32553
+ return this.locked;
32554
+ }
32555
+ acquire() {
32556
+ if (!this.locked) {
32557
+ this.locked = true;
32558
+ return Promise.resolve();
32559
+ }
32560
+ return new Promise((resolve3) => {
32561
+ this.waiters.push(resolve3);
32562
+ });
32563
+ }
32564
+ tryAcquire() {
32565
+ if (this.locked) {
32566
+ return false;
32567
+ }
32568
+ this.locked = true;
32569
+ return true;
32570
+ }
32571
+ release() {
32572
+ const next = this.waiters.shift();
32573
+ if (next) {
32574
+ next();
32575
+ return;
32576
+ }
32577
+ this.locked = false;
32578
+ }
32579
+ async runExclusive(fn) {
32580
+ await this.acquire();
32581
+ try {
32582
+ return await fn();
32583
+ } finally {
32584
+ this.release();
32585
+ }
32586
+ }
32587
+ };
32588
+
32589
+ // ../../packages/ycodium-acp-executor/src/user-input-pending.ts
32590
+ var userInputAnswerOptionId = (question, answers) => {
32591
+ const answer = answers[question.id];
32592
+ const selected = typeof answer === "string" ? answer : Array.isArray(answer) && answer.length === 1 && typeof answer[0] === "string" ? answer[0] : void 0;
32593
+ return selected !== void 0 && question.options.some((option) => option.id === selected) ? selected : void 0;
32594
+ };
32595
+
32596
+ // ../../packages/ycodium-acp-executor/src/vendor-hooks.ts
32597
+ var defaultVendorHooks = {
32598
+ completedStopReason: (response) => response.stopReason
32599
+ };
32600
+
32601
+ // ../../packages/ycodium-acp-executor/src/executor/support.ts
32602
+ var DEFAULT_RESULT_DRAIN_TIMEOUT_MS = 2e3;
32603
+
32527
32604
  // ../../packages/ycodium-acp-executor/src/executor/lifecycle.ts
32528
32605
  function createExecutorLifecycle({
32529
32606
  failIfDisposed,
@@ -32666,16 +32743,30 @@ function createExecutorLifecycle({
32666
32743
  }
32667
32744
  };
32668
32745
  let disposing;
32669
- const dispose = () => {
32746
+ const dispose = (exitCode) => {
32670
32747
  if (disposing) return disposing;
32671
32748
  shared.disposing = true;
32672
- promptResults.stop();
32673
- settleAllApprovals("cancel");
32674
- settleAllUserInputs();
32675
- abortPendingSettlement("executor disposed");
32676
- notifyPromptSettled();
32677
- shared.abortLocalPrompt?.();
32678
32749
  disposing = (async () => {
32750
+ if (exitCode !== void 0) {
32751
+ let timer;
32752
+ await Promise.race([
32753
+ connection.closed.catch(() => void 0),
32754
+ new Promise((resolve3) => {
32755
+ timer = setTimeout(
32756
+ resolve3,
32757
+ options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
32758
+ );
32759
+ })
32760
+ ]);
32761
+ clearTimeout(timer);
32762
+ await promptResults.wait(void 0, true);
32763
+ }
32764
+ promptResults.stop();
32765
+ settleAllApprovals("cancel");
32766
+ settleAllUserInputs();
32767
+ abortPendingSettlement("executor disposed");
32768
+ notifyPromptSettled();
32769
+ shared.abortLocalPrompt?.();
32679
32770
  promptResults.finishUnreceived();
32680
32771
  await promptResults.wait();
32681
32772
  emit({
@@ -32683,7 +32774,10 @@ function createExecutorLifecycle({
32683
32774
  ...stamp(),
32684
32775
  provider: options.provider,
32685
32776
  threadId: options.threadId,
32686
- payload: { reason: "disposed" }
32777
+ payload: exitCode === void 0 ? { reason: "disposed" } : {
32778
+ reason: exitCode === null ? "process exited without an exit code" : `process exited with code ${exitCode}`,
32779
+ exitKind: exitCode === 0 ? "graceful" : "error"
32780
+ }
32687
32781
  });
32688
32782
  shared.disposed = true;
32689
32783
  shared.generation += 1;
@@ -32778,11 +32872,6 @@ var acpPromptFailureCategory = (error62, input2) => {
32778
32872
  return error62 instanceof AcpConnectionClosedError ? acpTransportIfEstablished(input2.sessionEstablished, input2.disposed) : void 0;
32779
32873
  };
32780
32874
 
32781
- // ../../packages/ycodium-acp-executor/src/vendor-hooks.ts
32782
- var defaultVendorHooks = {
32783
- completedStopReason: (response) => response.stopReason
32784
- };
32785
-
32786
32875
  // ../../packages/ycodium-acp-executor/src/executor/prompt.ts
32787
32876
  function createExecutorPrompt({
32788
32877
  isLive,
@@ -32888,8 +32977,12 @@ function createExecutorPrompt({
32888
32977
  }
32889
32978
  }
32890
32979
  };
32891
- const prompt = async (input2) => {
32980
+ const failIfPromptUnavailable = () => {
32892
32981
  failIfDisposed();
32982
+ if (shared.connectionClosed) throw new AcpExecutorDisposedError();
32983
+ };
32984
+ const prompt = async (input2) => {
32985
+ failIfPromptUnavailable();
32893
32986
  const started = requireStarted();
32894
32987
  let record2;
32895
32988
  const settle2 = (rest) => settleTurn({
@@ -32901,7 +32994,7 @@ function createExecutorPrompt({
32901
32994
  let turnId;
32902
32995
  await threadMutex.acquire();
32903
32996
  try {
32904
- failIfDisposed();
32997
+ failIfPromptUnavailable();
32905
32998
  turnId = selectPromptTurnId(
32906
32999
  input2,
32907
33000
  shared.promptsInFlight > 0 ? shared.activeTurnId : void 0,
@@ -33010,7 +33103,7 @@ function createExecutorPrompt({
33010
33103
  sessionEstablished: shared.startResult !== void 0,
33011
33104
  disposed: shared.disposed
33012
33105
  });
33013
- if (written && input2.onDispatched !== void 0 && !interruptedTurnIds.has(turnId)) {
33106
+ if (!interruptedTurnIds.has(turnId)) {
33014
33107
  const errorMessage = error62 instanceof Error && error62.message.trim() || "ACP prompt failed";
33015
33108
  if (settle2({
33016
33109
  turnId,
@@ -33018,7 +33111,7 @@ function createExecutorPrompt({
33018
33111
  state: "failed",
33019
33112
  errorMessage,
33020
33113
  ...failureCategory === void 0 ? {} : { failureCategory }
33021
- }))
33114
+ }) && written && input2.onDispatched !== void 0)
33022
33115
  options.log?.warn?.("turn failed after dispatch", {
33023
33116
  threadId: options.threadId,
33024
33117
  failure: errorMessage
@@ -33119,9 +33212,9 @@ function createPromptResults({
33119
33212
  }
33120
33213
  }
33121
33214
  };
33122
- const wait = async (turnId) => {
33215
+ const wait = async (turnId, includeUnreceived = false) => {
33123
33216
  const claimed = [...prompts.values()].filter(
33124
- (record2) => !record2.finished && record2.response !== void 0 && (turnId === void 0 || record2.turnId === turnId)
33217
+ (record2) => !record2.finished && (includeUnreceived || record2.response !== void 0) && (turnId === void 0 || record2.turnId === turnId)
33125
33218
  );
33126
33219
  if (claimed.length === 0) return;
33127
33220
  let timer;
@@ -33129,7 +33222,10 @@ function createPromptResults({
33129
33222
  const drained = await Promise.race([
33130
33223
  Promise.all(claimed.map((record2) => record2.done)).then(() => true),
33131
33224
  new Promise((resolve3) => {
33132
- timer = setTimeout(() => resolve3(false), options.resultDrainTimeoutMs ?? 2e3);
33225
+ timer = setTimeout(
33226
+ () => resolve3(false),
33227
+ options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
33228
+ );
33133
33229
  })
33134
33230
  ]);
33135
33231
  if (drained) return;
@@ -33153,13 +33249,6 @@ function createPromptResults({
33153
33249
  return { add, receive, reject, stop, complete, hasInterrupted, forget, wait, finishUnreceived };
33154
33250
  }
33155
33251
 
33156
- // ../../packages/ycodium-acp-executor/src/user-input-pending.ts
33157
- var userInputAnswerOptionId = (question, answers) => {
33158
- const answer = answers[question.id];
33159
- const selected = typeof answer === "string" ? answer : Array.isArray(answer) && answer.length === 1 && typeof answer[0] === "string" ? answer[0] : void 0;
33160
- return selected !== void 0 && question.options.some((option) => option.id === selected) ? selected : void 0;
33161
- };
33162
-
33163
33252
  // ../../packages/ycodium-acp-executor/src/executor/requests.ts
33164
33253
  function createExecutorRequests({
33165
33254
  emit,
@@ -33701,27 +33790,6 @@ function acpInitializePayload(clientInfo, overrides) {
33701
33790
  };
33702
33791
  }
33703
33792
 
33704
- // ../../packages/ycodium-acp-executor/src/model-selection.ts
33705
- function normalizeModelId(value) {
33706
- return value?.trim() || void 0;
33707
- }
33708
- function modelSelectionStateFromSetup(setup) {
33709
- const sessionModels = isRecord(setup.models) ? setup.models : void 0;
33710
- const modelConfigId = extractModelConfigId(setup);
33711
- const strategy = sessionModels === void 0 && modelConfigId !== void 0 ? "config-option" : "session/set_model";
33712
- const modelConfigOption = modelConfigId === void 0 ? void 0 : findSessionConfigOption(setup.configOptions, modelConfigId);
33713
- const configModel = modelConfigOption?.currentValue;
33714
- const currentModelId = strategy === "config-option" ? typeof configModel === "string" ? normalizeModelId(configModel) : void 0 : typeof sessionModels?.["currentModelId"] === "string" ? normalizeModelId(sessionModels["currentModelId"]) : void 0;
33715
- return {
33716
- strategy,
33717
- sessionModelsAdvertised: sessionModels !== void 0,
33718
- modelConfigId,
33719
- currentModelId,
33720
- advertisedModelValues: strategy === "config-option" ? modelConfigOption === void 0 ? [] : collectSessionConfigOptionValues(modelConfigOption) : collectSessionModelIds(sessionModels),
33721
- configOptions: setup.configOptions
33722
- };
33723
- }
33724
-
33725
33793
  // ../../packages/ycodium-acp-executor/src/runtime-mode.ts
33726
33794
  function isRecord5(value) {
33727
33795
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -34265,47 +34333,6 @@ function createExecutorUpdates({
34265
34333
  return { emitCompactionState, handleSessionUpdate };
34266
34334
  }
34267
34335
 
34268
- // ../../packages/ycodium-acp-executor/src/mutex.ts
34269
- var Mutex = class {
34270
- locked = false;
34271
- waiters = [];
34272
- get isLocked() {
34273
- return this.locked;
34274
- }
34275
- acquire() {
34276
- if (!this.locked) {
34277
- this.locked = true;
34278
- return Promise.resolve();
34279
- }
34280
- return new Promise((resolve3) => {
34281
- this.waiters.push(resolve3);
34282
- });
34283
- }
34284
- tryAcquire() {
34285
- if (this.locked) {
34286
- return false;
34287
- }
34288
- this.locked = true;
34289
- return true;
34290
- }
34291
- release() {
34292
- const next = this.waiters.shift();
34293
- if (next) {
34294
- next();
34295
- return;
34296
- }
34297
- this.locked = false;
34298
- }
34299
- async runExclusive(fn) {
34300
- await this.acquire();
34301
- try {
34302
- return await fn();
34303
- } finally {
34304
- this.release();
34305
- }
34306
- }
34307
- };
34308
-
34309
34336
  // ../../packages/ycodium-acp-executor/src/openCommands.ts
34310
34337
  function readOpenToolCalls(toolCalls, turnId) {
34311
34338
  const running = [];
@@ -34677,10 +34704,10 @@ function createAcpExecutor(options) {
34677
34704
  setNativeMode,
34678
34705
  compact,
34679
34706
  openToolCalls: () => readOpenToolCalls(toolCalls, shared.activeTurnId),
34680
- dispose: () => {
34707
+ dispose: (exitCode) => {
34681
34708
  disposeOnce ??= (async () => {
34682
34709
  try {
34683
- await disposeLifecycle();
34710
+ await disposeLifecycle(exitCode);
34684
34711
  } finally {
34685
34712
  await protocolLogSink?.close();
34686
34713
  }
@@ -34691,7 +34718,8 @@ function createAcpExecutor(options) {
34691
34718
  }
34692
34719
 
34693
34720
  // ../../packages/ycodium-acp-executor/src/session-registry.ts
34694
- function createAcpSessionRegistry(threads, stopBooked2) {
34721
+ function createAcpSessionRegistry(threads, stopBooked2, log) {
34722
+ const exits = /* @__PURE__ */ new WeakMap();
34695
34723
  const requireThread = (threadId) => {
34696
34724
  const booked = threads.get(threadId);
34697
34725
  if (!booked) throw new Error(`unknown thread ${threadId}`);
@@ -34700,7 +34728,8 @@ function createAcpSessionRegistry(threads, stopBooked2) {
34700
34728
  };
34701
34729
  const stopSession = (threadId, booked = threads.get(threadId)) => {
34702
34730
  if (!booked) return Promise.resolve();
34703
- booked.closing ??= Promise.resolve().then(() => stopBooked2(booked)).then(() => {
34731
+ const close = { exitCode: exits.get(booked), hasExited: () => exits.has(booked) };
34732
+ booked.closing ??= Promise.resolve().then(() => stopBooked2(booked, close)).then(() => {
34704
34733
  if (threads.get(threadId) === booked) threads.delete(threadId);
34705
34734
  }).catch((cause) => {
34706
34735
  if (threads.get(threadId) === booked) delete booked.closing;
@@ -34711,7 +34740,16 @@ function createAcpSessionRegistry(threads, stopBooked2) {
34711
34740
  const stopAll = () => Promise.all([...threads].map(([threadId, booked]) => stopSession(threadId, booked))).then(
34712
34741
  () => void 0
34713
34742
  );
34714
- return { requireThread, stopSession, stopAll };
34743
+ const registerSession = (threadId, booked) => {
34744
+ threads.set(threadId, booked);
34745
+ void booked.handle.exited.then(async (exitCode) => {
34746
+ exits.set(booked, exitCode);
34747
+ await stopSession(threadId, booked);
34748
+ }).catch((cause) => {
34749
+ log?.warn("ACP process exit cleanup failed", { threadId, error: String(cause) });
34750
+ });
34751
+ };
34752
+ return { requireThread, registerSession, stopSession, stopAll };
34715
34753
  }
34716
34754
 
34717
34755
  // ../../packages/ycodium-acp-executor/src/session-cleanup.ts
@@ -34724,8 +34762,11 @@ async function cleanupAcpSession(input2) {
34724
34762
  failures.push(new Error(`forwarding failed: ${String(cause)}`, { cause }));
34725
34763
  });
34726
34764
  for (const [step, cleanup] of [
34727
- ["executor.dispose", () => input2.executor.dispose()],
34728
- ["stopProcess", input2.stopProcess],
34765
+ ["executor.dispose", () => input2.executor.dispose(input2.processExit?.exitCode)],
34766
+ [
34767
+ "stopProcess",
34768
+ () => input2.processExit?.hasExited() ? Promise.resolve() : input2.stopProcess()
34769
+ ],
34729
34770
  ["forwarding", () => forwarding]
34730
34771
  ]) {
34731
34772
  try {
@@ -35697,11 +35738,12 @@ function modelIdFromSelection(selection) {
35697
35738
  function nowIso() {
35698
35739
  return (/* @__PURE__ */ new Date()).toISOString();
35699
35740
  }
35700
- async function stopBooked(booked) {
35741
+ async function stopBooked(booked, processExit) {
35701
35742
  await cleanupAcpSession({
35702
35743
  executor: booked.executor,
35703
35744
  stopProcess: () => booked.handle.kill("SIGTERM"),
35704
- forwarding: booked.forwarding
35745
+ forwarding: booked.forwarding,
35746
+ processExit
35705
35747
  });
35706
35748
  }
35707
35749
  var createDshInstance = (config2, host) => {
@@ -35710,7 +35752,11 @@ var createDshInstance = (config2, host) => {
35710
35752
  const threads = /* @__PURE__ */ new Map();
35711
35753
  const overlayChecks = /* @__PURE__ */ new Map();
35712
35754
  let disposed = false;
35713
- const { requireThread, stopSession, stopAll } = createAcpSessionRegistry(threads, stopBooked);
35755
+ const { requireThread, registerSession, stopSession, stopAll } = createAcpSessionRegistry(
35756
+ threads,
35757
+ stopBooked,
35758
+ host.log
35759
+ );
35714
35760
  const disposeOnce = createRetryableClose(async () => {
35715
35761
  await stopAll();
35716
35762
  events.close();
@@ -35846,7 +35892,7 @@ var createDshInstance = (config2, host) => {
35846
35892
  ...started.modelId === void 0 ? {} : { model: started.modelId },
35847
35893
  ...input2.bindingGeneration === void 0 ? {} : { bindingGeneration: input2.bindingGeneration }
35848
35894
  };
35849
- threads.set(input2.threadId, {
35895
+ registerSession(input2.threadId, {
35850
35896
  session,
35851
35897
  turns: [],
35852
35898
  executor,
@@ -35965,7 +36011,7 @@ var executors = [
35965
36011
  ];
35966
36012
  var index_default = definePlugin({
35967
36013
  id: "agent-dsh",
35968
- apiVersion: 25,
36014
+ apiVersion: 27,
35969
36015
  executors,
35970
36016
  activate(ctx) {
35971
36017
  ctx.log.info("dsh executor ready");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-dsh",
3
- "version": "0.2.3238",
3
+ "version": "0.2.3244",
4
4
  "description": "DeepSeek Harness executor: dsh CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -22,9 +22,9 @@
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
24
  "yaml": "^2.9.0",
25
- "@ycodium-ai/plugin-api": "0.2.3238",
26
- "ycodium-acp-executor": "0.2.3238",
27
- "ycodium-executor-testing": "0.0.0"
25
+ "ycodium-acp-executor": "0.2.3244",
26
+ "ycodium-executor-testing": "0.0.0",
27
+ "@ycodium-ai/plugin-api": "0.2.3244"
28
28
  },
29
29
  "ycodium": {
30
30
  "plugin": "./dist/index.js",