@ycodium-ai/agent-dsh 0.2.3484 → 0.2.3506

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 +69 -40
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -35038,19 +35038,28 @@ function toAcpMcpServers(entries) {
35038
35038
  }
35039
35039
 
35040
35040
  // ../../packages/ycodium-acp-executor/src/probe.ts
35041
- function withProbeTimeout(promise2, timeoutMs, what) {
35041
+ function withProbeTimeout(promise2, timeoutMs, what, signal) {
35042
+ signal?.throwIfAborted();
35042
35043
  return new Promise((resolve3, reject) => {
35044
+ const onAbort = () => {
35045
+ clearTimeout(timer);
35046
+ reject(signal?.reason ?? new Error("aborted"));
35047
+ };
35043
35048
  const timer = setTimeout(() => {
35049
+ signal?.removeEventListener("abort", onAbort);
35044
35050
  reject(new Error(`${what} timed out after ${timeoutMs}ms`));
35045
35051
  }, timeoutMs);
35046
35052
  timer.unref?.();
35053
+ signal?.addEventListener("abort", onAbort, { once: true });
35047
35054
  promise2.then(
35048
35055
  (value) => {
35049
35056
  clearTimeout(timer);
35057
+ signal?.removeEventListener("abort", onAbort);
35050
35058
  resolve3(value);
35051
35059
  },
35052
35060
  (error62) => {
35053
35061
  clearTimeout(timer);
35062
+ signal?.removeEventListener("abort", onAbort);
35054
35063
  reject(error62 instanceof Error ? error62 : new Error(String(error62)));
35055
35064
  }
35056
35065
  );
@@ -35066,14 +35075,16 @@ async function openAcpProbeHandshake(input2) {
35066
35075
  const initializeResult = await withProbeTimeout(
35067
35076
  connection.request("initialize", acpInitializePayload(input2.clientInfo)),
35068
35077
  input2.requestTimeoutMs,
35069
- "ACP probe request 'initialize'"
35078
+ "ACP probe request 'initialize'",
35079
+ input2.signal
35070
35080
  );
35071
35081
  return {
35072
35082
  initializeResult,
35073
35083
  request: (method, params) => withProbeTimeout(
35074
35084
  connection.request(method, params),
35075
35085
  input2.requestTimeoutMs,
35076
- `ACP probe request '${method}'`
35086
+ `ACP probe request '${method}'`,
35087
+ input2.signal
35077
35088
  ),
35078
35089
  close: () => connection.close()
35079
35090
  };
@@ -35097,42 +35108,50 @@ async function collectCappedText(stream, maxBytes) {
35097
35108
  return { text: text + decoder.decode(), overflowed: total > maxBytes };
35098
35109
  }
35099
35110
  async function collectProbeProcess(child, input2) {
35111
+ const stdinClosed = Promise.resolve().then(() => child.closeStdin());
35112
+ const stdout = collectCappedText(child.stdout, input2.maxOutputBytes);
35113
+ const stderr = collectCappedText(child.stderr, input2.maxOutputBytes);
35114
+ const tasks = [stdinClosed, stdout, stderr, child.exited];
35115
+ let result;
35116
+ let bodyFailed = false;
35117
+ let bodyError;
35100
35118
  try {
35101
- await child.closeStdin().catch(() => void 0);
35102
- const [stdout, stderr, exitCode] = await withProbeTimeout(
35103
- Promise.all([
35104
- collectCappedText(child.stdout, input2.maxOutputBytes),
35105
- collectCappedText(child.stderr, input2.maxOutputBytes),
35106
- child.exited
35107
- ]),
35119
+ const [, out, err, exitCode] = await withProbeTimeout(
35120
+ Promise.all(tasks),
35108
35121
  input2.timeoutMs,
35109
- input2.what
35122
+ input2.what,
35123
+ input2.signal
35110
35124
  );
35111
- return { stdout: stdout.overflowed ? void 0 : stdout.text, stderr: stderr.text, exitCode };
35112
- } finally {
35113
- await child.kill("SIGTERM").catch(() => void 0);
35114
- }
35115
- }
35116
- var MAX_VERSION_OUTPUT_BYTES = 64 * 1024;
35117
- async function probeCliVersion(input2) {
35118
- let child;
35119
- try {
35120
- child = await input2.spawn();
35121
- } catch {
35122
- return null;
35125
+ result = { stdout: out.overflowed ? void 0 : out.text, stderr: err.text, exitCode };
35126
+ } catch (error62) {
35127
+ bodyFailed = true;
35128
+ bodyError = error62;
35123
35129
  }
35130
+ const term = Promise.resolve().then(() => child.kill("SIGTERM"));
35131
+ void term.catch(() => void 0);
35132
+ const cleanup = (async () => {
35133
+ try {
35134
+ await withProbeTimeout(child.exited, 250, `${input2.what} termination grace`);
35135
+ } catch {
35136
+ await child.kill("SIGKILL");
35137
+ }
35138
+ const settled = await Promise.allSettled([term, ...tasks]);
35139
+ const termination = settled[0];
35140
+ if (termination?.status === "rejected") throw termination.reason;
35141
+ })();
35124
35142
  try {
35125
- const run = await collectProbeProcess(child, {
35126
- timeoutMs: input2.timeoutMs,
35127
- maxOutputBytes: MAX_VERSION_OUTPUT_BYTES,
35128
- what: "--version"
35129
- });
35130
- if (run.exitCode !== 0) return null;
35131
- return parseCliVersion(run.stdout ?? "") ?? parseCliVersion(run.stderr);
35132
- } catch {
35133
- return null;
35143
+ await withProbeTimeout(cleanup, input2.cleanupTimeoutMs ?? 5e3, `${input2.what} cleanup`);
35144
+ } catch (cleanupError) {
35145
+ throw new AggregateError(
35146
+ bodyFailed ? [bodyError, cleanupError] : [cleanupError],
35147
+ `${input2.what} cleanup failed`,
35148
+ { cause: cleanupError }
35149
+ );
35134
35150
  }
35151
+ if (bodyFailed) throw bodyError;
35152
+ return result;
35135
35153
  }
35154
+ var MAX_VERSION_OUTPUT_BYTES = 64 * 1024;
35136
35155
 
35137
35156
  // src/dshBalance.ts
35138
35157
  import * as NodeCrypto2 from "node:crypto";
@@ -35552,6 +35571,10 @@ function tokenizeLaunchArgs(value) {
35552
35571
  }
35553
35572
 
35554
35573
  // src/probeModels.ts
35574
+ import {
35575
+ runProcessOperation,
35576
+ OperationCleanupError
35577
+ } from "@ycodium-ai/plugin-api/process-operation";
35555
35578
  import * as NodeFS3 from "node:fs";
35556
35579
  import * as NodeOS5 from "node:os";
35557
35580
  import * as NodePath6 from "node:path";
@@ -35749,16 +35772,22 @@ async function probeDshModels(input2) {
35749
35772
  async function probeDshVersion(input2) {
35750
35773
  const { recipe, host, signal } = input2;
35751
35774
  const env = buildSpawnEnv(recipe, resolveHomePath(recipe.homePath));
35752
- return probeCliVersion({
35753
- spawn: () => host.process.spawn({
35775
+ try {
35776
+ const run = await runProcessOperation(host, {
35754
35777
  program: recipe.binaryPath,
35755
35778
  args: ["--version"],
35756
35779
  owner: { bindingId: host.bindingId },
35757
35780
  ...Object.keys(env).length > 0 ? { env } : {},
35758
- ...signal === void 0 ? {} : { signal }
35759
- }),
35760
- timeoutMs: PROBE_REQUEST_TIMEOUT_MS
35761
- });
35781
+ signal,
35782
+ timeoutMs: PROBE_REQUEST_TIMEOUT_MS,
35783
+ maxOutputBytes: 64 * 1024
35784
+ });
35785
+ if (run.exitCode !== 0) return null;
35786
+ return parseCliVersion(run.stdout) ?? parseCliVersion(run.stderr);
35787
+ } catch (error62) {
35788
+ if (error62 instanceof OperationCleanupError || signal?.aborted) throw error62;
35789
+ return null;
35790
+ }
35762
35791
  }
35763
35792
 
35764
35793
  // src/openCommands.ts
@@ -35978,7 +36007,7 @@ var createDshInstance = (config2, host) => {
35978
36007
  ...dshNativeModeReport(recipe.environment)
35979
36008
  };
35980
36009
  },
35981
- readCliVersion: () => recipe.binaryPath.length === 0 ? Promise.resolve(null) : probeDshVersion({ recipe, host }),
36010
+ readCliVersion: (signal) => recipe.binaryPath.length === 0 ? Promise.resolve(null) : probeDshVersion({ recipe, host, ...signal === void 0 ? {} : { signal } }),
35982
36011
  // 暂不处理 input.readOnlyDirectories(有意为之):dsh 经共享的 ycodium-acp-executor 起会话,
35983
36012
  // 还没用真机确认这家 CLI 对 cwd 之外的读怎么处理、要不要放行。确认之后再接这一栏。
35984
36013
  startSession: async (input2, signal) => {
@@ -36192,7 +36221,7 @@ var executors = [
36192
36221
  ];
36193
36222
  var index_default = definePlugin({
36194
36223
  id: "agent-dsh",
36195
- apiVersion: 39,
36224
+ apiVersion: 42,
36196
36225
  executors,
36197
36226
  activate(ctx) {
36198
36227
  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.3484",
3
+ "version": "0.2.3506",
4
4
  "description": "DeepSeek Harness executor: dsh CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -23,8 +23,8 @@
23
23
  "vite-plus": "0.2.2",
24
24
  "yaml": "^2.9.0",
25
25
  "ycodium-executor-testing": "0.0.0",
26
- "@ycodium-ai/plugin-api": "0.2.3484",
27
- "ycodium-acp-executor": "0.2.3484"
26
+ "@ycodium-ai/plugin-api": "0.2.3506",
27
+ "ycodium-acp-executor": "0.2.0"
28
28
  },
29
29
  "ycodium": {
30
30
  "plugin": "./dist/index.js",