@ai-sdk/harness-claude-code 1.0.126 → 1.0.127

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/dist/index.js CHANGED
@@ -4,7 +4,9 @@ import {
4
4
  commonTool,
5
5
  HARNESS_V1_BUILTIN_TOOLS,
6
6
  harnessV1DiagnosticFromBridgeFrame,
7
- HarnessCapabilityUnsupportedError
7
+ HarnessCapabilityUnsupportedError,
8
+ harnessStateDirectoryPath,
9
+ harnessSessionDataDirectoryPath
8
10
  } from "@ai-sdk/harness";
9
11
  import {
10
12
  applyCredentialForwarding,
@@ -18,7 +20,6 @@ import {
18
20
  forwardBridgeProcessStream,
19
21
  getRestrictedSandboxSession,
20
22
  markBridgeStarting,
21
- resolveSandboxDefaultWorkingDirectory,
22
23
  resolveSandboxHomeDir,
23
24
  SandboxChannel,
24
25
  shellQuote,
@@ -449,7 +450,7 @@ var inboundMessageSchema = z.discriminatedUnion("type", [
449
450
  ]);
450
451
 
451
452
  // src/version.ts
452
- var VERSION = true ? "1.0.126" : "0.0.0-test";
453
+ var VERSION = true ? "1.0.127" : "0.0.0-test";
453
454
 
454
455
  // src/claude-code-harness.ts
455
456
  var CLAUDE_CODE_CLIENT_APP = `ai-sdk/harness-claude-code/${VERSION}`;
@@ -1077,10 +1078,6 @@ function createClaudeCode(settings = {}) {
1077
1078
  message: "The Claude Code harness cannot use `mintBridgeToken` with a sandbox session that does not expose an id."
1078
1079
  });
1079
1080
  }
1080
- const defaultWorkingDirectory = await resolveSandboxDefaultWorkingDirectory({
1081
- sandboxSession,
1082
- abortSignal: startOpts.abortSignal
1083
- });
1084
1081
  const lifecycleState = startOpts.continueFrom ?? startOpts.resumeFrom;
1085
1082
  const isResume = lifecycleState != null;
1086
1083
  const isContinue = startOpts.continueFrom != null;
@@ -1146,17 +1143,18 @@ function createClaudeCode(settings = {}) {
1146
1143
  credentialEnvironmentVariables: CLAUDE_CODE_CREDENTIAL_ENVIRONMENT_VARIABLES
1147
1144
  });
1148
1145
  }
1149
- const bootstrapDir = posix.resolve(
1150
- defaultWorkingDirectory,
1151
- CLAUDE_CODE_BOOTSTRAP_DIR
1152
- );
1153
- const resumeSessionId = resumeData?.claudeSessionId;
1154
- const workDir = startOpts.sessionWorkDir;
1155
1146
  const sandboxHomeDir = await resolveSandboxHomeDir({
1156
1147
  sandbox: toolSafeSandboxSession,
1157
1148
  abortSignal: startOpts.abortSignal
1158
1149
  });
1159
- const sessionDataDir = `${defaultWorkingDirectory}/.agent-runs/${startOpts.sessionId}`;
1150
+ const stateDir = harnessStateDirectoryPath({ sandboxHomeDir });
1151
+ const bootstrapDir = posix.resolve(stateDir, CLAUDE_CODE_BOOTSTRAP_DIR);
1152
+ const resumeSessionId = resumeData?.claudeSessionId;
1153
+ const workDir = startOpts.sessionWorkDir;
1154
+ const sessionDataDir = harnessSessionDataDirectoryPath({
1155
+ stateDirectory: stateDir,
1156
+ sessionId: startOpts.sessionId
1157
+ });
1160
1158
  const bridgeStateDir = `${sessionDataDir}/bridge`;
1161
1159
  const timeoutMs = settings.startupTimeoutMs ?? 12e4;
1162
1160
  const report = startOpts.observability?.report;
@@ -1202,10 +1200,17 @@ function createClaudeCode(settings = {}) {
1202
1200
  onBridgeError,
1203
1201
  reconnect: settings.reconnect
1204
1202
  });
1205
- await attachChannel.open(isContinue ? { resume: true } : void 0);
1203
+ const finishListenerAttachment2 = isContinue ? attachChannel.beginListenerAttachment() : void 0;
1204
+ try {
1205
+ await attachChannel.open(isContinue ? { resume: true } : void 0);
1206
+ } catch (error) {
1207
+ finishListenerAttachment2?.();
1208
+ throw error;
1209
+ }
1206
1210
  return createSession({
1207
1211
  sessionId: startOpts.sessionId,
1208
1212
  channel: attachChannel,
1213
+ finishListenerAttachment: finishListenerAttachment2,
1209
1214
  ...resumeSessionId ? { resumeSessionId } : {},
1210
1215
  // The live bridge was spawned by another process; this one owns no
1211
1216
  // process handle. The session lifecycle method decides whether the
@@ -1320,12 +1325,19 @@ function createClaudeCode(settings = {}) {
1320
1325
  // `finish`) rather than starting empty.
1321
1326
  ...respawnStrategy === "replay" ? { initialLastSeenEventId: coords?.lastSeenEventId ?? 0 } : {}
1322
1327
  });
1323
- await channel.open(
1324
- respawnStrategy === "replay" ? { resume: true } : void 0
1325
- );
1328
+ const finishListenerAttachment = respawnStrategy === "replay" ? channel.beginListenerAttachment() : void 0;
1329
+ try {
1330
+ await channel.open(
1331
+ respawnStrategy === "replay" ? { resume: true } : void 0
1332
+ );
1333
+ } catch (error) {
1334
+ finishListenerAttachment?.();
1335
+ throw error;
1336
+ }
1326
1337
  return createSession({
1327
1338
  sessionId: startOpts.sessionId,
1328
1339
  channel,
1340
+ finishListenerAttachment,
1329
1341
  proc,
1330
1342
  maxTurns: settings.maxTurns,
1331
1343
  env: sandboxClaudeEnvironment,
@@ -1568,6 +1580,7 @@ function formatUnknownError(error) {
1568
1580
  function createSession({
1569
1581
  sessionId,
1570
1582
  channel,
1583
+ finishListenerAttachment,
1571
1584
  proc,
1572
1585
  maxTurns,
1573
1586
  env,
@@ -1642,6 +1655,7 @@ function createSession({
1642
1655
  "tool-approval-request",
1643
1656
  "tool-result",
1644
1657
  "finish-step",
1658
+ "compaction",
1645
1659
  "raw"
1646
1660
  ];
1647
1661
  for (const type of eventTypes) {
@@ -1667,6 +1681,8 @@ function createSession({
1667
1681
  settleError(msg.error);
1668
1682
  })
1669
1683
  );
1684
+ finishListenerAttachment?.();
1685
+ finishListenerAttachment = void 0;
1670
1686
  const onClose = (_code, reason) => {
1671
1687
  if (isSettled) return;
1672
1688
  if (reason === "suspended") {