@cortexkit/aft 0.51.1 → 0.51.2

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 +58 -18
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -764,7 +764,7 @@ function coerceConfigureDroppedKeys(value) {
764
764
  function isBridgeTransportTimeout(err) {
765
765
  return err instanceof Error && err.code === "transport_timeout";
766
766
  }
767
- var DEFAULT_BRIDGE_TIMEOUT_MS = 30000, BRIDGE_HANG_TIMEOUT_THRESHOLD = 2, MAX_STDOUT_BUFFER, STDOUT_BUFFER_COMPACT_THRESHOLD, HASHLINE_REGISTRATION_LOG_INTERVAL_MS = 60000, HASHLINE_REGISTRATION_LOG_STATE_LIMIT = 256, TERMINAL_BASH_STATUSES, binaryFingerprintReader, BENIGN_CPUINFO_PROC_CPUINFO_PARSE_FAILURE = "failed to parse processor information from /proc/cpuinfo", BridgeReplacedDuringVersionCheck, BridgeTransportTimeoutError, BridgeTransportUnavailableError, BinaryBridge;
767
+ var DEFAULT_BRIDGE_TIMEOUT_MS = 30000, BRIDGE_HANG_TIMEOUT_THRESHOLD = 2, MAX_STDOUT_BUFFER, STDOUT_BUFFER_COMPACT_THRESHOLD, HASHLINE_REGISTRATION_LOG_INTERVAL_MS = 60000, HASHLINE_REGISTRATION_LOG_STATE_LIMIT = 256, TERMINAL_BASH_STATUSES, binaryFingerprintReader, BENIGN_CPUINFO_PROC_CPUINFO_PARSE_FAILURE = "failed to parse processor information from /proc/cpuinfo", BridgeReplacedDuringVersionCheck, BridgeTransportTimeoutError, BridgeTransportUnavailableError, BridgeTransportUnknownOutcomeError, BinaryBridge;
768
768
  var init_bridge = __esm(() => {
769
769
  init_active_logger();
770
770
  init_command_timeouts();
@@ -805,6 +805,12 @@ var init_bridge = __esm(() => {
805
805
  this.name = "BridgeTransportUnavailableError";
806
806
  }
807
807
  };
808
+ BridgeTransportUnknownOutcomeError = class BridgeTransportUnknownOutcomeError extends BridgeTransportUnavailableError {
809
+ constructor(message, options) {
810
+ super(message, options);
811
+ this.name = "BridgeTransportUnknownOutcomeError";
812
+ }
813
+ };
808
814
  BinaryBridge = class BinaryBridge {
809
815
  static RESTART_RESET_MS = 5 * 60 * 1000;
810
816
  static STDERR_TAIL_MAX = 20;
@@ -954,7 +960,7 @@ var init_bridge = __esm(() => {
954
960
  this.clearRestartResetTimer();
955
961
  this.configured = false;
956
962
  this.outstandingBackgroundTaskIds.clear();
957
- this.rejectAllPending(error2);
963
+ this.rejectAllPending(error2 instanceof BridgeTransportUnknownOutcomeError ? error2 : new BridgeTransportUnknownOutcomeError(error2.message, { cause: error2 }));
958
964
  }
959
965
  hasPendingRequests() {
960
966
  return this.pending.size > 0;
@@ -1077,6 +1083,12 @@ var init_bridge = __esm(() => {
1077
1083
  if (!this.configured) {
1078
1084
  if (command !== "configure" && command !== "version") {
1079
1085
  if (!this._configurePromise) {
1086
+ const configuringChild = this.process;
1087
+ const requireConfiguringChild = () => {
1088
+ if (this.process !== configuringChild) {
1089
+ throw new BridgeTransportUnavailableError(`${this.errorPrefix} Bridge process changed during configure; retry on replacement`);
1090
+ }
1091
+ };
1080
1092
  const sessionIdForConfigure = typeof params.session_id === "string" ? params.session_id : undefined;
1081
1093
  this._configurePromise = (async () => {
1082
1094
  try {
@@ -1085,11 +1097,14 @@ var init_bridge = __esm(() => {
1085
1097
  ...this.configOverrides,
1086
1098
  ...sessionIdForConfigure ? { session_id: sessionIdForConfigure } : {}
1087
1099
  }, implicitTransportOptions);
1100
+ requireConfiguringChild();
1088
1101
  if (configResult.success === false) {
1089
1102
  throw new Error(`${this.errorPrefix} Configure failed: ${configResult.message ?? "unknown error"}`);
1090
1103
  }
1091
1104
  await this.deliverConfigureWarnings(configResult, params, options);
1105
+ requireConfiguringChild();
1092
1106
  await this.checkVersion(implicitTransportOptions);
1107
+ requireConfiguringChild();
1093
1108
  if (!this.isAlive()) {
1094
1109
  throw new BridgeTransportUnavailableError(`${this.errorPrefix} Bridge died during version check. Check logs: ${this.getLogFilePathVia()}`);
1095
1110
  }
@@ -1168,19 +1183,26 @@ var init_bridge = __esm(() => {
1168
1183
  return;
1169
1184
  }
1170
1185
  requestSentAt = Date.now();
1171
- child.stdin.write(line, (err) => {
1172
- if (err) {
1173
- const error2 = new BridgeTransportUnavailableError(`${this.errorPrefix} Failed to write to stdin: ${err.message}`, { cause: err });
1174
- const entry = this.pending.get(id);
1175
- if (entry) {
1176
- this.pending.delete(id);
1177
- clearTimeout(entry.timer);
1178
- entry.reject(error2);
1179
- }
1180
- if (this.process === child)
1181
- this.invalidateTransportProcess(error2);
1186
+ const handleWriteFailure = (cause) => {
1187
+ const writeError = cause instanceof Error ? cause : new Error(String(cause));
1188
+ const error2 = new BridgeTransportUnknownOutcomeError(`${this.errorPrefix} Failed to write to stdin: ${writeError.message}`, { cause: writeError });
1189
+ const entry = this.pending.get(id);
1190
+ if (entry) {
1191
+ this.pending.delete(id);
1192
+ clearTimeout(entry.timer);
1193
+ entry.reject(error2);
1182
1194
  }
1183
- });
1195
+ if (this.process === child)
1196
+ this.invalidateTransportProcess(error2);
1197
+ };
1198
+ try {
1199
+ child.stdin.write(line, (err) => {
1200
+ if (err)
1201
+ handleWriteFailure(err);
1202
+ });
1203
+ } catch (err) {
1204
+ handleWriteFailure(err);
1205
+ }
1184
1206
  });
1185
1207
  if (command === "configure" && response.success === true && options?.markConfiguredOnSuccess !== false) {
1186
1208
  this.configured = true;
@@ -1395,9 +1417,13 @@ var init_bridge = __esm(() => {
1395
1417
  const currentChild = child;
1396
1418
  const stdoutDecoder = new StringDecoder("utf8");
1397
1419
  child.stdout?.on("data", (chunk) => {
1420
+ if (this.process !== currentChild)
1421
+ return;
1398
1422
  this.onStdoutData(stdoutDecoder.write(chunk));
1399
1423
  });
1400
1424
  child.stdout?.on("end", () => {
1425
+ if (this.process !== currentChild)
1426
+ return;
1401
1427
  const remaining = stdoutDecoder.end();
1402
1428
  if (remaining)
1403
1429
  this.onStdoutData(remaining);
@@ -1405,9 +1431,13 @@ var init_bridge = __esm(() => {
1405
1431
  });
1406
1432
  const stderrDecoder = new StringDecoder("utf8");
1407
1433
  child.stderr?.on("data", (chunk) => {
1434
+ if (this.process !== currentChild)
1435
+ return;
1408
1436
  this.onStderrData(stderrDecoder.write(chunk));
1409
1437
  });
1410
1438
  child.stderr?.on("end", () => {
1439
+ if (this.process !== currentChild)
1440
+ return;
1411
1441
  const remaining = stderrDecoder.end();
1412
1442
  if (remaining)
1413
1443
  this.onStderrData(remaining);
@@ -1430,7 +1460,7 @@ var init_bridge = __esm(() => {
1430
1460
  this.process = null;
1431
1461
  this.configured = false;
1432
1462
  this.clearRestartResetTimer();
1433
- this.rejectAllPending(new BridgeTransportUnavailableError(`${this.errorPrefix} Binary killed by ${signal}`));
1463
+ this.rejectAllPending(new BridgeTransportUnknownOutcomeError(`${this.errorPrefix} Binary killed by ${signal}`));
1434
1464
  return;
1435
1465
  }
1436
1466
  this.handleCrash();
@@ -1608,7 +1638,7 @@ var init_bridge = __esm(() => {
1608
1638
  handleTimeout(triggeringSessionId) {
1609
1639
  this.consecutiveRequestTimeouts = 0;
1610
1640
  this.spawnedBinaryFingerprint = null;
1611
- this.rejectAllPending(new Error(`${this.errorPrefix} bridge killed during sibling timeout — request aborted`));
1641
+ this.rejectAllPending(new BridgeTransportUnknownOutcomeError(`${this.errorPrefix} bridge killed during sibling timeout — request aborted`));
1612
1642
  this.outstandingBackgroundTaskIds.clear();
1613
1643
  if (this.process) {
1614
1644
  this.process.kill("SIGKILL");
@@ -1645,7 +1675,7 @@ var init_bridge = __esm(() => {
1645
1675
  if (tail) {
1646
1676
  this.errorVia(`Binary crashed (restarts: ${this._restartCount})${cause ? `: ${cause.message}` : ""}.${tail}`);
1647
1677
  }
1648
- this.rejectAllPending(new BridgeTransportUnavailableError(`${this.errorPrefix} Binary crashed (restarts: ${this._restartCount})${cause ? `: ${cause.message}` : ""} (see ${this.getLogFilePathVia()})`, { cause }));
1678
+ this.rejectAllPending(new BridgeTransportUnknownOutcomeError(`${this.errorPrefix} Binary crashed (restarts: ${this._restartCount})${cause ? `: ${cause.message}` : ""} (see ${this.getLogFilePathVia()})`, { cause }));
1649
1679
  if (this._retiringDueToBinaryChange) {
1650
1680
  this.logVia("Binary exited while retiring after an on-disk update; skipping auto-restart");
1651
1681
  return;
@@ -6593,6 +6623,8 @@ function isBashTransportDeadError(error2) {
6593
6623
  if (!(error2 instanceof Error) || hasEngineResponse(error2) || isRouteGoodbyeError(error2)) {
6594
6624
  return false;
6595
6625
  }
6626
+ if (error2 instanceof BridgeTransportUnknownOutcomeError)
6627
+ return false;
6596
6628
  return error2 instanceof BridgeTransportUnavailableError || error2 instanceof SubcTransportShuttingDownError || isConsumerReconnectTransient(error2) || error2 instanceof StaleRouteHandleError || error2 instanceof SubcRootGenerationExpiredError || error2 instanceof SubcRootReapedError;
6597
6629
  }
6598
6630
  function isTransportClassError(error2) {
@@ -6601,6 +6633,12 @@ function isTransportClassError(error2) {
6601
6633
  function adaptToolError(command, error2) {
6602
6634
  if (!(error2 instanceof Error))
6603
6635
  return error2;
6636
+ if (error2 instanceof BridgeTransportUnknownOutcomeError) {
6637
+ if (error2.message.includes(BRIDGE_TRANSPORT_UNKNOWN_OUTCOME_DISPOSITION))
6638
+ return error2;
6639
+ error2.message = error2.message ? `${error2.message} ${BRIDGE_TRANSPORT_UNKNOWN_OUTCOME_DISPOSITION}` : BRIDGE_TRANSPORT_UNKNOWN_OUTCOME_DISPOSITION;
6640
+ return error2;
6641
+ }
6604
6642
  if (isRouteGoodbyeError(error2)) {
6605
6643
  if (error2.message.includes(SUBC_MODULE_RESTART_DISPOSITION))
6606
6644
  return error2;
@@ -6614,7 +6652,7 @@ function adaptToolError(command, error2) {
6614
6652
  error2.message = error2.message ? `${error2.message} ${BASH_TRANSPORT_DISPOSITION}` : BASH_TRANSPORT_DISPOSITION;
6615
6653
  return error2;
6616
6654
  }
6617
- var AftToolError, BASH_TRANSPORT_DISPOSITION = "The transport to the AFT daemon was interrupted; no background task was created for this command and no task ID exists. Re-run the command. Do not poll bash_status for it.", SUBC_MODULE_RESTART_DISPOSITION = "The AFT daemon module restarted while this call was in flight, so its outcome is UNKNOWN: it may or may not have executed. Verify actual state before re-running, and never blind-retry a mutation.";
6655
+ var AftToolError, BASH_TRANSPORT_DISPOSITION = "The transport to the AFT daemon was interrupted; no background task was created for this command and no task ID exists. Re-run the command. Do not poll bash_status for it.", SUBC_MODULE_RESTART_DISPOSITION = "The AFT daemon module restarted while this call was in flight, so its outcome is UNKNOWN: it may or may not have executed. Verify actual state before re-running, and never blind-retry a mutation.", BRIDGE_TRANSPORT_UNKNOWN_OUTCOME_DISPOSITION = "The standalone AFT transport failed after this call may have been sent, so its outcome is UNKNOWN: it may or may not have executed. Verify actual state before re-running, and never blind-retry a mutation.";
6618
6656
  var init_error_contract = __esm(() => {
6619
6657
  init_dist();
6620
6658
  init_bridge();
@@ -9745,10 +9783,12 @@ __export(exports_dist, {
9745
9783
  HomeProjectRootError: () => HomeProjectRootError,
9746
9784
  DEFAULT_LOG_GENERATIONS: () => DEFAULT_LOG_GENERATIONS,
9747
9785
  DEFAULT_LOG_BYTES: () => DEFAULT_LOG_BYTES,
9786
+ BridgeTransportUnknownOutcomeError: () => BridgeTransportUnknownOutcomeError,
9748
9787
  BridgeTransportUnavailableError: () => BridgeTransportUnavailableError,
9749
9788
  BridgeTransportTimeoutError: () => BridgeTransportTimeoutError,
9750
9789
  BridgePool: () => BridgePool,
9751
9790
  BinaryBridge: () => BinaryBridge,
9791
+ BRIDGE_TRANSPORT_UNKNOWN_OUTCOME_DISPOSITION: () => BRIDGE_TRANSPORT_UNKNOWN_OUTCOME_DISPOSITION,
9752
9792
  BASH_TRANSPORT_DISPOSITION: () => BASH_TRANSPORT_DISPOSITION,
9753
9793
  BASH_HOST_FALLBACK_REFUSAL: () => BASH_HOST_FALLBACK_REFUSAL,
9754
9794
  BASH_HOST_FALLBACK_MAX_TIMEOUT_MS: () => BASH_HOST_FALLBACK_MAX_TIMEOUT_MS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/aft",
3
- "version": "0.51.1",
3
+ "version": "0.51.2",
4
4
  "type": "module",
5
5
  "description": "Unified CLI for Agent File Tools (AFT) — setup, doctor, and diagnostics across supported agent harnesses (OpenCode, Pi)",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@clack/prompts": "^1.6.0",
27
- "@cortexkit/aft-bridge": "0.51.1",
27
+ "@cortexkit/aft-bridge": "0.51.2",
28
28
  "comment-json": "^4.6.2"
29
29
  },
30
30
  "devDependencies": {