@ycodium-ai/agent-dsh 0.2.3254 → 0.2.3265

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 +232 -51
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -7481,7 +7481,7 @@ var DSH_CARD = {
7481
7481
  };
7482
7482
 
7483
7483
  // src/dshInstance.ts
7484
- import { modelSelectionStringOption } from "@ycodium-ai/plugin-api/executor";
7484
+ import { modelSelectionStringOption, raceAbort as raceAbort2 } from "@ycodium-ai/plugin-api/executor";
7485
7485
  import { nodeStreamsFromHandle as nodeStreamsFromHandle2 } from "@ycodium-ai/plugin-api/process-stdin";
7486
7486
 
7487
7487
  // ../../packages/ycodium-acp-executor/src/executor.ts
@@ -32514,11 +32514,15 @@ function createAcpConnection(options) {
32514
32514
  });
32515
32515
  };
32516
32516
  const close = (error62) => shutdown(error62 ?? new AcpConnectionClosedError());
32517
+ const abandonPending = (error62) => {
32518
+ rejectPending(error62);
32519
+ };
32517
32520
  return {
32518
32521
  request,
32519
32522
  begin,
32520
32523
  notify,
32521
32524
  awaitInboundIdle,
32525
+ abandonPending,
32522
32526
  close,
32523
32527
  closed
32524
32528
  };
@@ -32984,10 +32988,11 @@ function createExecutorPrompt({
32984
32988
  const prompt = async (input2) => {
32985
32989
  failIfPromptUnavailable();
32986
32990
  const started = requireStarted();
32991
+ let sessionId = started.sessionId;
32987
32992
  let record2;
32988
32993
  const settle2 = (rest) => settleTurn({
32989
32994
  expectedGeneration: started.generation,
32990
- expectedSessionId: started.sessionId,
32995
+ expectedSessionId: sessionId,
32991
32996
  record: record2,
32992
32997
  ...rest
32993
32998
  });
@@ -33071,12 +33076,32 @@ function createExecutorPrompt({
33071
33076
  const queuedTurnId = turnId;
33072
33077
  const isStale = () => interruptedTurnIds.has(queuedTurnId) || input2.expectedActiveTurnId !== void 0 && shared.activeTurnId !== queuedTurnId;
33073
33078
  if (!isStale()) {
33074
- shared.modelSelectionState = await applyRequestedModel({
33075
- state: shared.modelSelectionState,
33076
- acpSessionId: started.sessionId,
33077
- requestedModelId: input2.requestedModelId,
33078
- expectedGeneration: started.generation
33079
- });
33079
+ try {
33080
+ const applied = await applyRequestedModel({
33081
+ state: shared.modelSelectionState,
33082
+ acpSessionId: sessionId,
33083
+ setup: shared.startResult?.sessionSetupResult ?? {},
33084
+ requestedModelId: input2.requestedModelId,
33085
+ expectedGeneration: started.generation
33086
+ });
33087
+ shared.modelSelectionState = applied.state;
33088
+ sessionId = applied.sessionId;
33089
+ record2.sessionId = applied.sessionId;
33090
+ } catch (error62) {
33091
+ const failureCategory = readAcpFailureCategory(error62);
33092
+ if (failureCategory === "model-unavailable") {
33093
+ const errorMessage = error62 instanceof Error && error62.message.trim().length > 0 ? error62.message : "Requested model is not in this agent's catalog. This turn was not sent.";
33094
+ settle2({
33095
+ turnId,
33096
+ stopReason: "error",
33097
+ state: "failed",
33098
+ errorMessage,
33099
+ failureCategory
33100
+ });
33101
+ throw error62 instanceof Error ? withFailureCategory(error62, failureCategory) : error62;
33102
+ }
33103
+ throw error62;
33104
+ }
33080
33105
  }
33081
33106
  failIfDisposed();
33082
33107
  if (isStale()) {
@@ -33087,7 +33112,7 @@ function createExecutorPrompt({
33087
33112
  let written = false;
33088
33113
  try {
33089
33114
  response = await sendPromptRpc(
33090
- started.sessionId,
33115
+ sessionId,
33091
33116
  promptParts,
33092
33117
  () => {
33093
33118
  written = true;
@@ -33137,7 +33162,7 @@ function createExecutorPrompt({
33137
33162
  if (hooks.readContextWindow !== void 0) {
33138
33163
  try {
33139
33164
  contextWindow = await hooks.readContextWindow({
33140
- sessionId: started.sessionId,
33165
+ sessionId,
33141
33166
  promptResponse: response
33142
33167
  }) ?? void 0;
33143
33168
  } catch {
@@ -33790,6 +33815,56 @@ function acpInitializePayload(clientInfo, overrides) {
33790
33815
  };
33791
33816
  }
33792
33817
 
33818
+ // ../../packages/ycodium-acp-executor/src/refreshDeadline.ts
33819
+ var MODEL_CATALOG_REFRESH_TIMEOUT_MS = 9e4;
33820
+
33821
+ // ../../packages/ycodium-acp-executor/src/model-send.ts
33822
+ function judgeRequestedModel(input2) {
33823
+ const requested = normalizeModelId(input2.requestedModelId);
33824
+ const current = input2.state.currentModelId;
33825
+ if (requested === void 0 || requested === current) return { kind: "keep" };
33826
+ const hasCatalog = input2.state.advertisedModelValues.length > 0;
33827
+ const hasCurrent = current !== void 0;
33828
+ if (!hasCatalog && !hasCurrent) return { kind: "keep" };
33829
+ const canSwitch = input2.state.strategy === "session/set_model" && input2.state.sessionModelsAdvertised || input2.state.strategy === "config-option" && input2.state.modelConfigId !== void 0;
33830
+ const value = hasCatalog ? matchAdvertisedModelValue(requested, input2.state.advertisedModelValues) : void 0;
33831
+ if (value !== void 0 && value === current) return { kind: "keep" };
33832
+ if (value !== void 0 && canSwitch) return { kind: "switch", value };
33833
+ return input2.refreshed ? { kind: "unavailable" } : { kind: "refresh" };
33834
+ }
33835
+ function modelUnavailableError(requestedModelId, currentModelId) {
33836
+ const current = currentModelId ?? "its own model";
33837
+ return withFailureCategory(
33838
+ new Error(
33839
+ `Requested model "${requestedModelId}" is not in this agent's catalog; it is on "${current}". This turn was not sent. Refresh the model list in this agent's settings and try again.`
33840
+ ),
33841
+ "model-unavailable"
33842
+ );
33843
+ }
33844
+ var ModelCatalogRefreshTimeoutError = class extends Error {
33845
+ constructor() {
33846
+ super("model catalog refresh timed out");
33847
+ this.name = "ModelCatalogRefreshTimeoutError";
33848
+ }
33849
+ };
33850
+ function modelRefreshTimedOutError(requestedModelId) {
33851
+ return withFailureCategory(
33852
+ new Error(
33853
+ `Refreshing this agent's model list timed out, so this turn was not sent. Requested model "${requestedModelId}".`
33854
+ ),
33855
+ "model-unavailable"
33856
+ );
33857
+ }
33858
+ function modelRefreshFailedError(requestedModelId, error62) {
33859
+ const detail = error62 instanceof Error && error62.message.trim().length > 0 ? error62.message : "the model list could not be read";
33860
+ return withFailureCategory(
33861
+ new Error(
33862
+ `Refreshing this agent's model list failed (${detail}), so this turn was not sent. Requested model "${requestedModelId}".`
33863
+ ),
33864
+ "model-unavailable"
33865
+ );
33866
+ }
33867
+
33793
33868
  // ../../packages/ycodium-acp-executor/src/runtime-mode.ts
33794
33869
  function isRecord5(value) {
33795
33870
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -33820,43 +33895,131 @@ function createExecutorSession({
33820
33895
  failIfDisposed,
33821
33896
  shared
33822
33897
  }) {
33823
- const applyRequestedModel = async (input2) => {
33824
- const requestedModelId = normalizeModelId(input2.requestedModelId);
33825
- if (requestedModelId === void 0 || requestedModelId === input2.state.currentModelId || input2.state.strategy === "session/set_model" && !input2.state.sessionModelsAdvertised || input2.state.strategy === "config-option" && input2.state.modelConfigId === void 0) {
33826
- return input2.state;
33827
- }
33828
- const value = matchAdvertisedModelValue(requestedModelId, input2.state.advertisedModelValues);
33829
- if (value === void 0) {
33830
- if (requestedModelId !== shared.lastUnmatchedModelId) {
33831
- shared.lastUnmatchedModelId = requestedModelId;
33832
- options.log?.info("requested model is not in the agent catalog; keeping its own model", {
33833
- requestedModelId,
33834
- currentModelId: input2.state.currentModelId,
33835
- advertisedModelValues: input2.state.advertisedModelValues
33836
- });
33837
- }
33838
- return input2.state;
33898
+ const openFreshSession = async (expectedGeneration) => {
33899
+ const initialized = shared.initializeResult;
33900
+ if (initialized === void 0) {
33901
+ throw new Error("no handshake");
33902
+ }
33903
+ const mcpServers = filterMcpServersByAgentCapabilities(
33904
+ options.mcpServers ?? [],
33905
+ initialized.agentCapabilities
33906
+ );
33907
+ const additionalDirectories = options.additionalDirectories !== void 0 && options.additionalDirectories.length > 0 ? { additionalDirectories: options.additionalDirectories } : {};
33908
+ const created = await connection.request("session/new", {
33909
+ cwd: options.cwd,
33910
+ mcpServers,
33911
+ ...additionalDirectories
33912
+ });
33913
+ if (!isLive(expectedGeneration)) {
33914
+ throw new AcpExecutorDisposedError();
33839
33915
  }
33840
- if (value === input2.state.currentModelId) {
33841
- return input2.state;
33916
+ if (created.sessionId === void 0 || created.sessionId.length === 0) {
33917
+ throw new Error("session/new did not return a session id");
33842
33918
  }
33919
+ return { sessionId: created.sessionId, setup: created };
33920
+ };
33921
+ const switchModel = async (input2) => {
33843
33922
  let configOptions = input2.state.configOptions;
33844
33923
  if (input2.state.strategy === "config-option") {
33845
33924
  const switched = await connection.request(
33846
33925
  "session/set_config_option",
33847
- { sessionId: input2.acpSessionId, configId: input2.state.modelConfigId, value }
33926
+ { sessionId: input2.sessionId, configId: input2.state.modelConfigId, value: input2.value }
33848
33927
  );
33849
33928
  configOptions = switched?.configOptions ?? configOptions;
33850
33929
  } else {
33851
33930
  await connection.request("session/set_model", {
33852
- sessionId: input2.acpSessionId,
33853
- modelId: value
33931
+ sessionId: input2.sessionId,
33932
+ modelId: input2.value
33854
33933
  });
33855
33934
  }
33856
33935
  if (!isLive(input2.expectedGeneration)) {
33857
33936
  throw new AcpExecutorDisposedError();
33858
33937
  }
33859
- return { ...input2.state, currentModelId: value, configOptions };
33938
+ return { ...input2.state, currentModelId: input2.value, configOptions };
33939
+ };
33940
+ const adoptReopenedSession = (applied) => {
33941
+ if (shared.sessionId === void 0 && shared.startResult === void 0) return;
33942
+ const setup = applied.setup;
33943
+ shared.sessionId = applied.sessionId;
33944
+ shared.modelSelectionState = applied.state;
33945
+ shared.modeState = parseSessionModeState(setup);
33946
+ if (shared.startResult !== void 0) {
33947
+ shared.startResult = {
33948
+ ...shared.startResult,
33949
+ sessionId: applied.sessionId,
33950
+ sessionSetupResult: setup,
33951
+ modelConfigId: extractModelConfigId(setup),
33952
+ modelId: applied.state.currentModelId
33953
+ };
33954
+ }
33955
+ };
33956
+ const applyRequestedModel = async (input2) => {
33957
+ async function applyOnce(state, sessionId, setup, refreshed) {
33958
+ const requestedModelId = normalizeModelId(input2.requestedModelId) ?? "";
33959
+ const judgment = judgeRequestedModel({
33960
+ state,
33961
+ requestedModelId: input2.requestedModelId,
33962
+ refreshed
33963
+ });
33964
+ if (judgment.kind === "keep") return { state, sessionId, setup };
33965
+ if (judgment.kind === "unavailable") {
33966
+ throw modelUnavailableError(requestedModelId, state.currentModelId);
33967
+ }
33968
+ if (judgment.kind === "switch") {
33969
+ return {
33970
+ state: await switchModel({
33971
+ state,
33972
+ sessionId,
33973
+ value: judgment.value,
33974
+ expectedGeneration: input2.expectedGeneration
33975
+ }),
33976
+ sessionId,
33977
+ setup
33978
+ };
33979
+ }
33980
+ return refreshAndRejudge(requestedModelId);
33981
+ }
33982
+ async function refreshAndRejudge(requestedModelId) {
33983
+ const timeoutMs = options.modelCatalogRefreshTimeoutMs ?? MODEL_CATALOG_REFRESH_TIMEOUT_MS;
33984
+ let timedOut = false;
33985
+ const timeoutError = new ModelCatalogRefreshTimeoutError();
33986
+ let timer;
33987
+ const work = (async () => {
33988
+ await options.refreshCatalogForSend?.();
33989
+ if (timedOut) throw timeoutError;
33990
+ const reopened = await openFreshSession(input2.expectedGeneration);
33991
+ if (timedOut) throw timeoutError;
33992
+ const next = modelSelectionStateFromSetup(reopened.setup);
33993
+ const applied = await applyOnce(next, reopened.sessionId, reopened.setup, true);
33994
+ if (timedOut) throw timeoutError;
33995
+ adoptReopenedSession(applied);
33996
+ return applied;
33997
+ })();
33998
+ void work.then(
33999
+ () => void 0,
34000
+ () => void 0
34001
+ );
34002
+ const deadline = new Promise((_resolve, reject) => {
34003
+ timer = setTimeout(() => {
34004
+ timedOut = true;
34005
+ connection.abandonPending(timeoutError);
34006
+ reject(timeoutError);
34007
+ }, timeoutMs);
34008
+ });
34009
+ try {
34010
+ return await Promise.race([work, deadline]);
34011
+ } catch (error62) {
34012
+ if (error62 instanceof AcpExecutorDisposedError) throw error62;
34013
+ if (timedOut || error62 instanceof ModelCatalogRefreshTimeoutError) {
34014
+ throw modelRefreshTimedOutError(requestedModelId);
34015
+ }
34016
+ if (readAcpFailureCategory(error62) === "model-unavailable") throw error62;
34017
+ throw modelRefreshFailedError(requestedModelId, error62);
34018
+ } finally {
34019
+ if (timer !== void 0) clearTimeout(timer);
34020
+ }
34021
+ }
34022
+ return applyOnce(input2.state, input2.acpSessionId, input2.setup, false);
33860
34023
  };
33861
34024
  const startOnce = async (expectedGeneration) => {
33862
34025
  const initializePayload = acpInitializePayload(options.clientInfo, options.clientCapabilities);
@@ -33925,12 +34088,17 @@ function createExecutorSession({
33925
34088
  categories: unhandledCategories
33926
34089
  });
33927
34090
  }
33928
- const nextModelSelectionState = await applyRequestedModel({
33929
- state: modelSelectionStateFromSetup(setup),
34091
+ const openedSetup = setup;
34092
+ const appliedModel = await applyRequestedModel({
34093
+ state: modelSelectionStateFromSetup(openedSetup),
33930
34094
  acpSessionId: nextSessionId,
34095
+ setup: openedSetup,
33931
34096
  requestedModelId: options.requestedModelId,
33932
34097
  expectedGeneration
33933
34098
  });
34099
+ nextSessionId = appliedModel.sessionId;
34100
+ setup = appliedModel.setup;
34101
+ const nextModelSelectionState = appliedModel.state;
33934
34102
  await applyRequestedEffort({
33935
34103
  connection,
33936
34104
  log: options.log,
@@ -34465,7 +34633,6 @@ function createAcpExecutor(options) {
34465
34633
  currentModelId: void 0,
34466
34634
  advertisedModelValues: []
34467
34635
  },
34468
- lastUnmatchedModelId: void 0,
34469
34636
  initializeResult: void 0,
34470
34637
  startResult: void 0,
34471
34638
  startInFlight: void 0,
@@ -35390,7 +35557,9 @@ import * as NodeOS5 from "node:os";
35390
35557
  import * as NodePath6 from "node:path";
35391
35558
  import {
35392
35559
  describeExecutorSpawnFailure,
35560
+ ExecutorSpawnAbortedError,
35393
35561
  ExecutorSpawnRefusedError,
35562
+ raceAbort,
35394
35563
  REASONING_OPTION_LABEL
35395
35564
  } from "@ycodium-ai/plugin-api/executor";
35396
35565
  import { nodeStreamsFromHandle } from "@ycodium-ai/plugin-api/process-stdin";
@@ -35545,21 +35714,27 @@ async function probeDshModels(input2) {
35545
35714
  args: tokenizeLaunchArgs(recipe.launchArgs),
35546
35715
  cwd: probeCwd,
35547
35716
  owner: { bindingId: host.bindingId },
35548
- ...Object.keys(env).length > 0 ? { env } : {}
35717
+ ...Object.keys(env).length > 0 ? { env } : {},
35718
+ ...input2.signal === void 0 ? {} : { signal: input2.signal }
35549
35719
  });
35550
35720
  } catch (error62) {
35551
- if (error62 instanceof ExecutorSpawnRefusedError) throw error62;
35721
+ if (error62 instanceof ExecutorSpawnRefusedError || error62 instanceof ExecutorSpawnAbortedError) {
35722
+ throw error62;
35723
+ }
35552
35724
  return { kind: "not-started", ...describeExecutorSpawnFailure(error62) };
35553
35725
  }
35554
35726
  let handshake;
35555
35727
  try {
35556
35728
  const { readable: readable2, writable } = nodeStreamsFromHandle(handle);
35557
- handshake = await openAcpProbeHandshake({
35558
- readable: readable2,
35559
- writable,
35560
- clientInfo: DSH_CLIENT_INFO,
35561
- requestTimeoutMs: PROBE_REQUEST_TIMEOUT_MS
35562
- });
35729
+ handshake = await raceAbort(
35730
+ openAcpProbeHandshake({
35731
+ readable: readable2,
35732
+ writable,
35733
+ clientInfo: DSH_CLIENT_INFO,
35734
+ requestTimeoutMs: PROBE_REQUEST_TIMEOUT_MS
35735
+ }),
35736
+ input2.signal
35737
+ );
35563
35738
  return {
35564
35739
  kind: "answered",
35565
35740
  models: dshProbeModels(await probeSessionSetup(handshake, probeCwd))
@@ -35572,14 +35747,15 @@ async function probeDshModels(input2) {
35572
35747
  }
35573
35748
  }
35574
35749
  async function probeDshVersion(input2) {
35575
- const { recipe, host } = input2;
35750
+ const { recipe, host, signal } = input2;
35576
35751
  const env = buildSpawnEnv(recipe, resolveHomePath(recipe.homePath));
35577
35752
  return probeCliVersion({
35578
35753
  spawn: () => host.process.spawn({
35579
35754
  program: recipe.binaryPath,
35580
35755
  args: ["--version"],
35581
35756
  owner: { bindingId: host.bindingId },
35582
- ...Object.keys(env).length > 0 ? { env } : {}
35757
+ ...Object.keys(env).length > 0 ? { env } : {},
35758
+ ...signal === void 0 ? {} : { signal }
35583
35759
  }),
35584
35760
  timeoutMs: PROBE_REQUEST_TIMEOUT_MS
35585
35761
  });
@@ -35762,7 +35938,7 @@ var createDshInstance = (config2, host) => {
35762
35938
  events.close();
35763
35939
  });
35764
35940
  const instance = {
35765
- probe: async () => {
35941
+ probe: async (signal) => {
35766
35942
  if (recipe.binaryPath.length === 0) {
35767
35943
  return {
35768
35944
  installed: false,
@@ -35772,10 +35948,14 @@ var createDshInstance = (config2, host) => {
35772
35948
  detail: "DeepSeek Harness program path is not configured"
35773
35949
  };
35774
35950
  }
35775
- const [outcome, version2] = await Promise.all([
35776
- probeDshModels({ recipe, host }),
35777
- probeDshVersion({ recipe, host })
35778
- ]);
35951
+ if (signal?.aborted) throw new Error("aborted");
35952
+ const [outcome, version2] = await raceAbort2(
35953
+ Promise.all([
35954
+ probeDshModels({ recipe, host, ...signal === void 0 ? {} : { signal } }),
35955
+ probeDshVersion({ recipe, host, ...signal === void 0 ? {} : { signal } })
35956
+ ]),
35957
+ signal
35958
+ );
35779
35959
  if (outcome.kind !== "answered") {
35780
35960
  return {
35781
35961
  installed: outcome.kind === "failed",
@@ -35798,6 +35978,7 @@ var createDshInstance = (config2, host) => {
35798
35978
  ...dshNativeModeReport(recipe.environment)
35799
35979
  };
35800
35980
  },
35981
+ readCliVersion: () => recipe.binaryPath.length === 0 ? Promise.resolve(null) : probeDshVersion({ recipe, host }),
35801
35982
  // 暂不处理 input.readOnlyDirectories(有意为之):dsh 经共享的 ycodium-acp-executor 起会话,
35802
35983
  // 还没用真机确认这家 CLI 对 cwd 之外的读怎么处理、要不要放行。确认之后再接这一栏。
35803
35984
  startSession: async (input2, signal) => {
@@ -36011,7 +36192,7 @@ var executors = [
36011
36192
  ];
36012
36193
  var index_default = definePlugin({
36013
36194
  id: "agent-dsh",
36014
- apiVersion: 30,
36195
+ apiVersion: 31,
36015
36196
  executors,
36016
36197
  activate(ctx) {
36017
36198
  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.3254",
3
+ "version": "0.2.3265",
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-acp-executor": "0.2.3254",
26
- "ycodium-executor-testing": "0.0.0",
27
- "@ycodium-ai/plugin-api": "0.2.3254"
25
+ "@ycodium-ai/plugin-api": "0.2.3265",
26
+ "ycodium-acp-executor": "0.2.3265",
27
+ "ycodium-executor-testing": "0.0.0"
28
28
  },
29
29
  "ycodium": {
30
30
  "plugin": "./dist/index.js",