@ycodium-ai/agent-dsh 0.2.3210 → 0.2.3212

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 +134 -27
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -34323,6 +34323,92 @@ function readOpenToolCalls(toolCalls, turnId) {
34323
34323
  return running;
34324
34324
  }
34325
34325
 
34326
+ // ../../packages/ycodium-acp-executor/src/protocol-log.ts
34327
+ import * as NodeFS from "node:fs";
34328
+ import * as NodeOS from "node:os";
34329
+ import * as NodePath2 from "node:path";
34330
+ var DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
34331
+ var UNSAFE_FILE_CHARS = /[^A-Za-z0-9._-]+/gu;
34332
+ function safeFileName(value) {
34333
+ return value.replaceAll(UNSAFE_FILE_CHARS, "_");
34334
+ }
34335
+ function createAcpProtocolLogFile(input2) {
34336
+ const maxBytes = input2.maxBytes ?? DEFAULT_MAX_BYTES;
34337
+ NodeFS.mkdirSync(input2.directory, { recursive: true });
34338
+ const filePath = NodePath2.join(
34339
+ input2.directory,
34340
+ `${safeFileName(input2.provider)}-${safeFileName(input2.threadId)}-${Date.now().toString(36)}.ndjson`
34341
+ );
34342
+ const stream = (input2.openStream ?? ((path) => NodeFS.createWriteStream(path, { flags: "a" })))(
34343
+ filePath
34344
+ );
34345
+ let bytes = 0;
34346
+ let stopped = false;
34347
+ const closed = Promise.withResolvers();
34348
+ let closing = false;
34349
+ stream.once("close", () => closed.resolve());
34350
+ stream.on("error", () => {
34351
+ stopped = true;
34352
+ stream.destroy();
34353
+ });
34354
+ const writeTruncated = () => {
34355
+ stopped = true;
34356
+ const marker = `${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), stage: "truncated" })}
34357
+ `;
34358
+ if (bytes + Buffer.byteLength(marker) <= maxBytes) stream.write(marker);
34359
+ stream.end();
34360
+ };
34361
+ const writeLine = (value) => {
34362
+ if (stopped) return;
34363
+ const line = `${JSON.stringify(value)}
34364
+ `;
34365
+ const lineBytes = Buffer.byteLength(line);
34366
+ if (bytes + lineBytes > maxBytes) {
34367
+ writeTruncated();
34368
+ return;
34369
+ }
34370
+ bytes += lineBytes;
34371
+ stream.write(line);
34372
+ };
34373
+ return {
34374
+ path: filePath,
34375
+ write: (event) => writeLine({
34376
+ at: (/* @__PURE__ */ new Date()).toISOString(),
34377
+ direction: event.direction,
34378
+ stage: event.stage,
34379
+ payload: event.payload
34380
+ }),
34381
+ close: async () => {
34382
+ if (closing) return closed.promise;
34383
+ closing = true;
34384
+ stopped = true;
34385
+ stream.end();
34386
+ await closed.promise;
34387
+ }
34388
+ };
34389
+ }
34390
+ function createAcpProtocolLogFromEnv(input2) {
34391
+ const flag = process.env.YCODIUM_ACP_PROTOCOL_LOG;
34392
+ if (flag !== "1" && flag?.toLowerCase() !== "true") return void 0;
34393
+ const configured = process.env.YCODIUM_ACP_PROTOCOL_LOG_DIR?.trim();
34394
+ const directory = configured && configured.length > 0 ? configured : NodePath2.join(NodeOS.tmpdir(), "ycodium-acp-protocol");
34395
+ try {
34396
+ const sink = createAcpProtocolLogFile({
34397
+ directory,
34398
+ provider: input2.provider,
34399
+ threadId: input2.threadId
34400
+ });
34401
+ input2.log?.info("acp protocol frames are being recorded", { path: sink.path });
34402
+ return sink;
34403
+ } catch (error62) {
34404
+ input2.log?.warn?.("acp protocol frame log could not be opened", {
34405
+ directory,
34406
+ error: error62 instanceof Error ? error62.message : String(error62)
34407
+ });
34408
+ return void 0;
34409
+ }
34410
+ }
34411
+
34326
34412
  // ../../packages/ycodium-acp-executor/src/executor.ts
34327
34413
  var DEFAULT_CANCEL_GRACE_MS = 5e3;
34328
34414
  function defaultNowIso() {
@@ -34431,9 +34517,16 @@ function createAcpExecutor(options) {
34431
34517
  });
34432
34518
  const { rememberSettledPromptKey, abortPendingSettlement, settleFromNotification } = createExecutorSettlement({ hooks, shared });
34433
34519
  const promptResults = createPromptResults({ options, shared });
34520
+ const protocolLogSink = options.protocolLog === void 0 ? createAcpProtocolLogFromEnv({
34521
+ provider: options.provider,
34522
+ threadId: options.threadId,
34523
+ ...options.log === void 0 ? {} : { log: options.log }
34524
+ }) : void 0;
34525
+ const protocolLog = options.protocolLog ?? protocolLogSink?.write;
34434
34526
  const connection = createAcpConnection({
34435
34527
  readable: options.readable,
34436
34528
  writable: options.writable,
34529
+ ...protocolLog === void 0 ? {} : { logger: protocolLog },
34437
34530
  onInboundFailure: (error62) => {
34438
34531
  options.log?.warn?.("acp connection closed: an inbound request could not be answered", {
34439
34532
  threadId: options.threadId,
@@ -34530,7 +34623,11 @@ function createAcpExecutor(options) {
34530
34623
  notifyPromptSettled,
34531
34624
  shared
34532
34625
  });
34533
- const { cancel, compact, dispose } = createExecutorLifecycle({
34626
+ const {
34627
+ cancel,
34628
+ compact,
34629
+ dispose: disposeLifecycle
34630
+ } = createExecutorLifecycle({
34534
34631
  promptResults,
34535
34632
  failIfDisposed,
34536
34633
  requireStarted,
@@ -34557,6 +34654,7 @@ function createAcpExecutor(options) {
34557
34654
  onInputDead,
34558
34655
  shared
34559
34656
  });
34657
+ let disposeOnce;
34560
34658
  return {
34561
34659
  get generation() {
34562
34660
  return shared.generation;
@@ -34579,7 +34677,16 @@ function createAcpExecutor(options) {
34579
34677
  setNativeMode,
34580
34678
  compact,
34581
34679
  openToolCalls: () => readOpenToolCalls(toolCalls, shared.activeTurnId),
34582
- dispose
34680
+ dispose: () => {
34681
+ disposeOnce ??= (async () => {
34682
+ try {
34683
+ await disposeLifecycle();
34684
+ } finally {
34685
+ await protocolLogSink?.close();
34686
+ }
34687
+ })();
34688
+ return disposeOnce;
34689
+ }
34583
34690
  };
34584
34691
  }
34585
34692
 
@@ -34821,9 +34928,9 @@ async function probeCliVersion(input2) {
34821
34928
 
34822
34929
  // src/dshBalance.ts
34823
34930
  import * as NodeCrypto2 from "node:crypto";
34824
- import * as NodeFS from "node:fs";
34825
- import * as NodeOS from "node:os";
34826
- import * as NodePath2 from "node:path";
34931
+ import * as NodeFS2 from "node:fs";
34932
+ import * as NodeOS2 from "node:os";
34933
+ import * as NodePath3 from "node:path";
34827
34934
  import {
34828
34935
  parseRetryAfterMs
34829
34936
  } from "@ycodium-ai/plugin-api/usage";
@@ -34842,7 +34949,7 @@ var parseJson = (raw) => {
34842
34949
  };
34843
34950
  var readFile = (path) => {
34844
34951
  try {
34845
- return NodeFS.readFileSync(path, "utf8");
34952
+ return NodeFS2.readFileSync(path, "utf8");
34846
34953
  } catch {
34847
34954
  return null;
34848
34955
  }
@@ -34912,15 +35019,15 @@ var createDshUsage = (input2) => {
34912
35019
  const now = input2.now ?? Date.now;
34913
35020
  const processEnv = input2.processEnv ?? process.env;
34914
35021
  const envValue = (name) => nonEmpty(input2.environment[name]) ?? nonEmpty(processEnv[name]);
34915
- const dshHome = () => nonEmpty(input2.environment[input2.homeEnvVar]) ?? nonEmpty(input2.homePath) ?? nonEmpty(processEnv[input2.homeEnvVar]) ?? NodePath2.join(NodeOS.homedir(), ".dsh");
35022
+ const dshHome = () => nonEmpty(input2.environment[input2.homeEnvVar]) ?? nonEmpty(input2.homePath) ?? nonEmpty(processEnv[input2.homeEnvVar]) ?? NodePath3.join(NodeOS2.homedir(), ".dsh");
34916
35023
  const resolveKey = () => {
34917
35024
  const fromEnvironment = envValue(API_KEY_NAME);
34918
35025
  if (fromEnvironment !== null) return fromEnvironment;
34919
35026
  const home = dshHome();
34920
- const yaml = readFile(NodePath2.join(home, ".credentials.yaml"));
35027
+ const yaml = readFile(NodePath3.join(home, ".credentials.yaml"));
34921
35028
  const fromYaml = yaml === null ? null : readCredentialsYamlRef(yaml, API_KEY_NAME);
34922
35029
  if (fromYaml !== null) return fromYaml;
34923
- const dotenv = readFile(NodePath2.join(home, ".env"));
35030
+ const dotenv = readFile(NodePath3.join(home, ".env"));
34924
35031
  return dotenv === null ? null : readDotenvValue(dotenv, API_KEY_NAME);
34925
35032
  };
34926
35033
  const readQuota = async (request) => {
@@ -34980,8 +35087,8 @@ var createDshUsage = (input2) => {
34980
35087
  // src/dshOverlay.ts
34981
35088
  import * as NodeCrypto3 from "node:crypto";
34982
35089
  import * as NodeFSP from "node:fs/promises";
34983
- import * as NodeOS2 from "node:os";
34984
- import * as NodePath3 from "node:path";
35090
+ import * as NodeOS3 from "node:os";
35091
+ import * as NodePath4 from "node:path";
34985
35092
  import * as NodeURL2 from "node:url";
34986
35093
  var import_yaml = __toESM(require_dist(), 1);
34987
35094
  var OVERLAY_DIR = "ycodium-dsh-patches";
@@ -34991,8 +35098,8 @@ var SKILL_FILESYSTEM_ID = "skill-filesystem";
34991
35098
  var PERMISSION_SYNC_ID = "ycodium-permission-sync";
34992
35099
  var posixPath = (path) => path.replaceAll("\\", "/");
34993
35100
  function permissionSyncModulePath() {
34994
- const here = NodePath3.dirname(NodeURL2.fileURLToPath(import.meta.url));
34995
- return NodePath3.resolve(here, "..", "assets", "permission-sync.mjs");
35101
+ const here = NodePath4.dirname(NodeURL2.fileURLToPath(import.meta.url));
35102
+ return NodePath4.resolve(here, "..", "assets", "permission-sync.mjs");
34996
35103
  }
34997
35104
  function dshOverlay(input2) {
34998
35105
  const lines = [];
@@ -35014,11 +35121,11 @@ function dshOverlay(input2) {
35014
35121
  return `${lines.join("\n")}
35015
35122
  `;
35016
35123
  }
35017
- async function ensureDshOverlay(input2, tempRoot = NodeOS2.tmpdir()) {
35124
+ async function ensureDshOverlay(input2, tempRoot = NodeOS3.tmpdir()) {
35018
35125
  const contents = dshOverlay(input2);
35019
35126
  const hash2 = NodeCrypto3.createHash("sha256").update(contents).digest("hex").slice(0, 16);
35020
- const directory = NodePath3.join(tempRoot, OVERLAY_DIR);
35021
- const file2 = NodePath3.join(directory, `${hash2}.yml`);
35127
+ const directory = NodePath4.join(tempRoot, OVERLAY_DIR);
35128
+ const file2 = NodePath4.join(directory, `${hash2}.yml`);
35022
35129
  const present = await NodeFSP.readFile(file2, "utf8").then(
35023
35130
  (existing) => existing === contents,
35024
35131
  () => false
@@ -35237,9 +35344,9 @@ function tokenizeLaunchArgs(value) {
35237
35344
  }
35238
35345
 
35239
35346
  // src/probeModels.ts
35240
- import * as NodeFS2 from "node:fs";
35241
- import * as NodeOS4 from "node:os";
35242
- import * as NodePath5 from "node:path";
35347
+ import * as NodeFS3 from "node:fs";
35348
+ import * as NodeOS5 from "node:os";
35349
+ import * as NodePath6 from "node:path";
35243
35350
  import {
35244
35351
  describeExecutorSpawnFailure,
35245
35352
  ExecutorSpawnRefusedError,
@@ -35248,8 +35355,8 @@ import {
35248
35355
  import { nodeStreamsFromHandle } from "@ycodium-ai/plugin-api/process-stdin";
35249
35356
 
35250
35357
  // src/spawnEnv.ts
35251
- import * as NodeOS3 from "node:os";
35252
- import * as NodePath4 from "node:path";
35358
+ import * as NodeOS4 from "node:os";
35359
+ import * as NodePath5 from "node:path";
35253
35360
  import { mergeLaunchEnv } from "@ycodium-ai/plugin-api/executor";
35254
35361
 
35255
35362
  // src/permission.ts
@@ -35292,20 +35399,20 @@ function dshPermissionEnv(nativeModeId) {
35292
35399
 
35293
35400
  // src/spawnEnv.ts
35294
35401
  function expandHomePath(value) {
35295
- if (value === "~") return NodeOS3.homedir();
35402
+ if (value === "~") return NodeOS4.homedir();
35296
35403
  if (value.startsWith("~/") || value.startsWith("~\\")) {
35297
- return NodePath4.join(NodeOS3.homedir(), value.slice(2));
35404
+ return NodePath5.join(NodeOS4.homedir(), value.slice(2));
35298
35405
  }
35299
35406
  return value;
35300
35407
  }
35301
35408
  function resolveHomePath(value) {
35302
35409
  const trimmed = value.trim();
35303
35410
  if (trimmed.length === 0) return "";
35304
- return NodePath4.resolve(expandHomePath(trimmed));
35411
+ return NodePath5.resolve(expandHomePath(trimmed));
35305
35412
  }
35306
35413
  function dshContinuationKey(homePath) {
35307
35414
  const resolved = resolveHomePath(homePath);
35308
- return `dsh:home:${resolved.length > 0 ? resolved : NodePath4.join(NodeOS3.homedir(), ".dsh")}`;
35415
+ return `dsh:home:${resolved.length > 0 ? resolved : NodePath5.join(NodeOS4.homedir(), ".dsh")}`;
35309
35416
  }
35310
35417
  function buildSpawnEnv(recipe, resolvedHomePath, nativeModeId) {
35311
35418
  const homeEnvVar = recipe.homeEnvVar.trim() || DSH_CARD.homeEnvVar;
@@ -35323,7 +35430,7 @@ function buildSpawnEnv(recipe, resolvedHomePath, nativeModeId) {
35323
35430
  var PROBE_REQUEST_TIMEOUT_MS = 15e3;
35324
35431
  function dshProbeSessionCwd(instanceId) {
35325
35432
  const safe = instanceId.trim().replace(/[^A-Za-z0-9._-]/g, "-") || "instance";
35326
- return NodePath5.join(NodeOS4.tmpdir(), `ycodium-dsh-probe-${safe}`);
35433
+ return NodePath6.join(NodeOS5.tmpdir(), `ycodium-dsh-probe-${safe}`);
35327
35434
  }
35328
35435
  function isRecord7(value) {
35329
35436
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -35385,7 +35492,7 @@ async function probeDshModels(input2) {
35385
35492
  const { recipe, host } = input2;
35386
35493
  const probeCwd = dshProbeSessionCwd(host.instanceId);
35387
35494
  try {
35388
- NodeFS2.mkdirSync(probeCwd, { recursive: true });
35495
+ NodeFS3.mkdirSync(probeCwd, { recursive: true });
35389
35496
  } catch (error62) {
35390
35497
  return { kind: "failed", detail: failureDetail(error62) };
35391
35498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-dsh",
3
- "version": "0.2.3210",
3
+ "version": "0.2.3212",
4
4
  "description": "DeepSeek Harness executor: dsh CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -22,8 +22,8 @@
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.3210",
26
- "ycodium-acp-executor": "0.2.3210",
25
+ "@ycodium-ai/plugin-api": "0.2.0",
26
+ "ycodium-acp-executor": "0.2.3212",
27
27
  "ycodium-executor-testing": "0.0.0"
28
28
  },
29
29
  "ycodium": {