@ai-sdk/harness-claude-code 1.0.178 → 1.0.179

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @ai-sdk/harness-claude-code
2
2
 
3
+ ## 1.0.179
4
+
5
+ ### Patch Changes
6
+
7
+ - ae4e236: add an additionalDirectories setting and trust those directories like the working directory in file approvals
8
+ - a54f0fd: fix(harness): abort a running turn when its host disconnects for good
9
+ - Updated dependencies [8e8033a]
10
+ - Updated dependencies [a54f0fd]
11
+ - @ai-sdk/harness@1.0.175
12
+
3
13
  ## 1.0.178
4
14
 
5
15
  ### Patch Changes
@@ -201,6 +201,12 @@ const WS_OPEN = 1;
201
201
  async function runBridge(options) {
202
202
  const { bridgeType, bridgeStateDir, onStart, onStop, onDestroy } = options;
203
203
  const teardownGraceMs = options.turnTeardownGraceMs ?? 1e4;
204
+ const hostDisconnectTimeoutMs = options.hostDisconnectTimeoutMs != null && Number.isFinite(options.hostDisconnectTimeoutMs) && options.hostDisconnectTimeoutMs > 0 ? Math.min(options.hostDisconnectTimeoutMs, 2147483647) : void 0;
205
+ let hostDisconnectTimer;
206
+ const clearHostDisconnectTimer = () => {
207
+ clearTimeout(hostDisconnectTimer);
208
+ hostDisconnectTimer = void 0;
209
+ };
204
210
  const expectedToken = options.token ?? env.BRIDGE_CHANNEL_TOKEN ?? "";
205
211
  const bridgeWsPort = options.port ?? parseInt(env.BRIDGE_WS_PORT ?? "0", 10);
206
212
  const bridgeMetaPath = `${bridgeStateDir}/bridge-meta.json`;
@@ -388,6 +394,7 @@ async function runBridge(options) {
388
394
  const thisTurn = new Promise((resolve) => turnFinished = resolve);
389
395
  activeTurn = thisTurn;
390
396
  activeSocket = ws;
397
+ clearHostDisconnectTimer();
391
398
  const firstTurn = isFirstTurn;
392
399
  isFirstTurn = false;
393
400
  eventLog = [];
@@ -454,6 +461,7 @@ async function runBridge(options) {
454
461
  activeTurn = void 0;
455
462
  currentTurnState = "waiting";
456
463
  writeBridgeMeta("waiting");
464
+ clearHostDisconnectTimer();
457
465
  }
458
466
  turnFinished();
459
467
  }
@@ -520,6 +528,7 @@ async function runBridge(options) {
520
528
  return;
521
529
  case "resume":
522
530
  activeSocket = ws;
531
+ clearHostDisconnectTimer();
523
532
  replay(ws, msg.lastSeenEventId);
524
533
  return;
525
534
  case "destroy":
@@ -607,8 +616,18 @@ async function runBridge(options) {
607
616
  }
608
617
  handleInbound(parsed, ws);
609
618
  });
610
- ws.on("close", () => {
611
- if (activeSocket === ws) activeSocket = void 0;
619
+ ws.on("close", (_code, reason) => {
620
+ if (activeSocket === ws) {
621
+ activeSocket = void 0;
622
+ if (hostDisconnectTimeoutMs != null && activeTurn != null && reason.toString() !== "suspended") {
623
+ clearHostDisconnectTimer();
624
+ hostDisconnectTimer = setTimeout(() => {
625
+ hostDisconnectTimer = void 0;
626
+ if (activeSocket == null) turnAbort?.abort();
627
+ }, hostDisconnectTimeoutMs);
628
+ hostDisconnectTimer.unref?.();
629
+ }
630
+ }
612
631
  });
613
632
  ws.on("error", () => {});
614
633
  });
@@ -1330,7 +1349,8 @@ async function areFileToolPathsTrusted(options) {
1330
1349
  if (options.paths.length === 0) return false;
1331
1350
  try {
1332
1351
  const roots = [await realpath(options.workDir)];
1333
- if (options.access === "read") for (const root of options.readableSkillRoots) try {
1352
+ const trustedRoots = [...(options.additionalDirectories ?? []).filter((root) => path.posix.isAbsolute(root)), ...options.access === "read" ? options.readableSkillRoots : []];
1353
+ for (const root of trustedRoots) try {
1334
1354
  roots.push(await realpath(root));
1335
1355
  } catch {
1336
1356
  continue;
@@ -1538,6 +1558,7 @@ let lastClaudeSessionId;
1538
1558
  await runBridge({
1539
1559
  bridgeType: "claude-code",
1540
1560
  bridgeStateDir,
1561
+ ...args.hostDisconnectTimeoutMs !== void 0 ? { hostDisconnectTimeoutMs: args.hostDisconnectTimeoutMs } : {},
1541
1562
  onStart: async (start, turn) => {
1542
1563
  const emit = (event) => {
1543
1564
  if (turn.abortSignal.aborted) return;
@@ -1599,6 +1620,7 @@ function createPermissionOptions(input) {
1599
1620
  inactiveNativeTools,
1600
1621
  cwd: input.toolCwds.get(options.toolUseID) ?? "",
1601
1622
  readableSkillRoots: input.start.readableSkillRoots ?? [],
1623
+ additionalDirectories: input.start.additionalDirectories ?? [],
1602
1624
  blockedPath: options.blockedPath
1603
1625
  })) return {
1604
1626
  behavior: "allow",
@@ -1765,7 +1787,8 @@ async function needsHostApproval(input) {
1765
1787
  cwd: input.cwd,
1766
1788
  paths,
1767
1789
  access,
1768
- readableSkillRoots: input.readableSkillRoots
1790
+ readableSkillRoots: input.readableSkillRoots,
1791
+ additionalDirectories: input.additionalDirectories
1769
1792
  });
1770
1793
  }
1771
1794
  function createApprovalPreToolUseHook(input) {
@@ -1791,6 +1814,7 @@ function createApprovalPreToolUseHook(input) {
1791
1814
  toolInput: hookInput.tool_input,
1792
1815
  cwd: hookInput.cwd,
1793
1816
  readableSkillRoots: input.readableSkillRoots,
1817
+ additionalDirectories: input.additionalDirectories,
1794
1818
  permissionMode: input.permissionMode,
1795
1819
  inactiveNativeTools: input.inactiveNativeTools
1796
1820
  })) return {};
@@ -1953,6 +1977,7 @@ async function runTurn(start, turn) {
1953
1977
  const approvalPreToolUseHook = createApprovalPreToolUseHook({
1954
1978
  toolCwds,
1955
1979
  readableSkillRoots: start.readableSkillRoots ?? [],
1980
+ additionalDirectories: start.additionalDirectories ?? [],
1956
1981
  permissionMode,
1957
1982
  inactiveNativeTools: new Set(inactiveNativeTools),
1958
1983
  decisions: approvalDecisions,
@@ -1984,6 +2009,7 @@ async function runTurn(start, turn) {
1984
2009
  ...start.model ? { model: start.model } : {},
1985
2010
  ...start.maxTurns !== void 0 ? { maxTurns: start.maxTurns } : {},
1986
2011
  ...start.maxBudgetUsd !== void 0 ? { maxBudgetUsd: start.maxBudgetUsd } : {},
2012
+ ...start.additionalDirectories !== void 0 ? { additionalDirectories: start.additionalDirectories } : {},
1987
2013
  ...start.strictMcpConfig !== void 0 ? { strictMcpConfig: start.strictMcpConfig } : {},
1988
2014
  ...start.agentProgressSummaries !== void 0 ? { agentProgressSummaries: start.agentProgressSummaries } : {},
1989
2015
  ...start.forwardSubagentText !== void 0 ? { forwardSubagentText: start.forwardSubagentText } : {},
@@ -2383,6 +2409,7 @@ function parseArgs(args) {
2383
2409
  const out = {};
2384
2410
  for (let i = 0; i < args.length; i++) if (args[i] === "--workdir" && i + 1 < args.length) out.workdir = args[++i];
2385
2411
  else if (args[i] === "--bridge-state-dir" && i + 1 < args.length) out.bridgeStateDir = args[++i];
2412
+ else if (args[i] === "--host-disconnect-timeout-ms" && i + 1 < args.length) out.hostDisconnectTimeoutMs = Number(args[++i]);
2386
2413
  return out;
2387
2414
  }
2388
2415
  function emitFatal(message) {