@cnwenf/occ 2.1.330 → 2.1.331

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/cli.js +141 -48
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bun
2
- globalThis.MACRO={"VERSION":"2.1.330","BINARY_NAME":"occ","BUILD_TIME":"2026-09-12T00:55:03.697Z","FEEDBACK_CHANNEL":"","ISSUES_EXPLAINER":"","NATIVE_PACKAGE_URL":"","PACKAGE_URL":"@cnwenf/occ","VERSION_CHANGELOG":""};
2
+ globalThis.MACRO={"VERSION":"2.1.331","BINARY_NAME":"occ","BUILD_TIME":"2026-09-12T07:54:49.967Z","FEEDBACK_CHANNEL":"","ISSUES_EXPLAINER":"","NATIVE_PACKAGE_URL":"","PACKAGE_URL":"@cnwenf/occ","VERSION_CHANGELOG":""};
3
3
  // @bun
4
4
  var __create = Object.create;
5
5
  var __getProtoOf = Object.getPrototypeOf;
@@ -395528,14 +395528,19 @@ async function gracefulShutdown(exitCode = 0, reason = "other", options) {
395528
395528
  return;
395529
395529
  }
395530
395530
  shutdownInProgress = true;
395531
- const { executeSessionEndHooks, getSessionEndHookTimeoutMs } = await Promise.resolve().then(() => (init_hooks5(), exports_hooks2));
395531
+ const {
395532
+ executeSessionEndHooks,
395533
+ getSessionEndHookTimeoutMs,
395534
+ getSessionEndHooksBudgetMs
395535
+ } = await Promise.resolve().then(() => (init_hooks5(), exports_hooks2));
395532
395536
  const sessionEndTimeoutMs = getSessionEndHookTimeoutMs();
395537
+ const sessionEndBudgetMs = getSessionEndHooksBudgetMs();
395533
395538
  failsafeTimer = setTimeout(async (code) => {
395534
395539
  cleanupTerminalModes();
395535
395540
  printResumeHint();
395536
395541
  await drainStdoutBeforeExit(500);
395537
395542
  forceExit(code);
395538
- }, Math.max(5000, sessionEndTimeoutMs + 3500), exitCode);
395543
+ }, Math.max(5000, sessionEndBudgetMs + 3500), exitCode);
395539
395544
  failsafeTimer.unref();
395540
395545
  process.exitCode = exitCode;
395541
395546
  cleanupTerminalModes();
@@ -395560,7 +395565,7 @@ async function gracefulShutdown(exitCode = 0, reason = "other", options) {
395560
395565
  try {
395561
395566
  await executeSessionEndHooks(reason, {
395562
395567
  ...options,
395563
- signal: AbortSignal.timeout(sessionEndTimeoutMs),
395568
+ signal: AbortSignal.timeout(sessionEndBudgetMs),
395564
395569
  timeoutMs: sessionEndTimeoutMs
395565
395570
  });
395566
395571
  } catch {}
@@ -481765,6 +481770,38 @@ var init_UI10 = __esm(() => {
481765
481770
  jsx_runtime137 = __toESM(require_jsx_runtime(), 1);
481766
481771
  });
481767
481772
 
481773
+ // src/utils/combinedAbortSignal.ts
481774
+ function createCombinedAbortSignal(signal, opts) {
481775
+ const { signalB, timeoutMs } = opts ?? {};
481776
+ const combined = createAbortController();
481777
+ if (signal?.aborted || signalB?.aborted) {
481778
+ combined.abort();
481779
+ return { signal: combined.signal, cleanup: () => {} };
481780
+ }
481781
+ let timer;
481782
+ const abortCombined = () => {
481783
+ if (timer !== undefined)
481784
+ clearTimeout(timer);
481785
+ combined.abort();
481786
+ };
481787
+ if (timeoutMs !== undefined) {
481788
+ timer = setTimeout(abortCombined, timeoutMs);
481789
+ timer.unref?.();
481790
+ }
481791
+ signal?.addEventListener("abort", abortCombined);
481792
+ signalB?.addEventListener("abort", abortCombined);
481793
+ const cleanup = () => {
481794
+ if (timer !== undefined)
481795
+ clearTimeout(timer);
481796
+ signal?.removeEventListener("abort", abortCombined);
481797
+ signalB?.removeEventListener("abort", abortCombined);
481798
+ };
481799
+ return { signal: combined.signal, cleanup };
481800
+ }
481801
+ var init_combinedAbortSignal = __esm(() => {
481802
+ init_abortController();
481803
+ });
481804
+
481768
481805
  // src/utils/mcpOutputStorage.ts
481769
481806
  import { writeFile as writeFile27 } from "fs/promises";
481770
481807
  import { join as join100 } from "path";
@@ -498499,11 +498536,13 @@ __export(exports_utils2, {
498499
498536
  isPermittedRedirect: () => isPermittedRedirect,
498500
498537
  invalidUrlErrorMessage: () => invalidUrlErrorMessage,
498501
498538
  getWithPermittedRedirects: () => getWithPermittedRedirects,
498539
+ getWebFetchDeadlineMs: () => getWebFetchDeadlineMs,
498502
498540
  getURLMarkdownContent: () => getURLMarkdownContent,
498503
498541
  getTurndownService: () => getTurndownService,
498504
498542
  clearWebFetchCache: () => clearWebFetchCache,
498505
498543
  checkDomainBlocklist: () => checkDomainBlocklist,
498506
498544
  applyPromptToMarkdown: () => applyPromptToMarkdown,
498545
+ WebFetchTransportError: () => WebFetchTransportError,
498507
498546
  MAX_MARKDOWN_LENGTH: () => MAX_MARKDOWN_LENGTH
498508
498547
  });
498509
498548
  function clearWebFetchCache() {
@@ -498523,6 +498562,13 @@ function getTurndownService() {
498523
498562
  return service;
498524
498563
  });
498525
498564
  }
498565
+ function getWebFetchDeadlineMs() {
498566
+ const fromEnv5 = parseEnvInt(process.env.CLAUDE_CODE_WEBFETCH_DEADLINE_MS);
498567
+ if (fromEnv5 !== undefined) {
498568
+ return Math.min(fromEnv5, MAX_DEADLINE_MS);
498569
+ }
498570
+ return WEBFETCH_DEADLINE_MS_DEFAULT;
498571
+ }
498526
498572
  function isPreapprovedUrl(url3) {
498527
498573
  try {
498528
498574
  const parsedUrl = new URL(url3);
@@ -498606,13 +498652,30 @@ function isPermittedRedirect(originalUrl, redirectUrl) {
498606
498652
  return false;
498607
498653
  }
498608
498654
  }
498609
- async function getWithPermittedRedirects(url3, signal, redirectChecker, depth = 0) {
498655
+ async function getWithPermittedRedirects(url3, signal, redirectChecker, depth = 0, deadlineSignal) {
498656
+ if (deadlineSignal !== undefined) {
498657
+ return fetchWithRedirectChain(url3, signal, redirectChecker, depth, deadlineSignal);
498658
+ }
498659
+ const deadlineMs = getWebFetchDeadlineMs();
498660
+ if (deadlineMs === 0) {
498661
+ return fetchWithRedirectChain(url3, signal, redirectChecker, depth, new AbortController().signal);
498662
+ }
498663
+ const deadline = createCombinedAbortSignal(undefined, {
498664
+ timeoutMs: deadlineMs
498665
+ });
498666
+ try {
498667
+ return await fetchWithRedirectChain(url3, signal, redirectChecker, depth, deadline.signal);
498668
+ } finally {
498669
+ deadline.cleanup();
498670
+ }
498671
+ }
498672
+ async function fetchWithRedirectChain(url3, signal, redirectChecker, depth, deadlineSignal) {
498610
498673
  if (depth > MAX_REDIRECTS) {
498611
498674
  throw new Error(`Too many redirects (exceeded ${MAX_REDIRECTS})`);
498612
498675
  }
498613
498676
  try {
498614
498677
  return await axios_default.get(url3, {
498615
- signal,
498678
+ signal: AbortSignal.any([signal, deadlineSignal]),
498616
498679
  timeout: FETCH_TIMEOUT_MS3,
498617
498680
  maxRedirects: 0,
498618
498681
  responseType: "arraybuffer",
@@ -498623,14 +498686,17 @@ async function getWithPermittedRedirects(url3, signal, redirectChecker, depth =
498623
498686
  }
498624
498687
  });
498625
498688
  } catch (error52) {
498626
- if (axios_default.isAxiosError(error52) && error52.response && [301, 302, 307, 308].includes(error52.response.status)) {
498689
+ if (axios_default.isCancel(error52) && deadlineSignal.aborted && !signal.aborted) {
498690
+ throw new WebFetchTransportError(`Fetch did not complete within the ${getWebFetchDeadlineMs() / 1000}s deadline`, "EDEADLINE");
498691
+ }
498692
+ if (axios_default.isAxiosError(error52) && error52.response && REDIRECT_STATUS_CODES.has(error52.response.status)) {
498627
498693
  const redirectLocation = error52.response.headers.location;
498628
498694
  if (!redirectLocation) {
498629
498695
  throw new Error("Redirect missing Location header");
498630
498696
  }
498631
498697
  const redirectUrl = new URL(redirectLocation, url3).toString();
498632
498698
  if (redirectChecker(url3, redirectUrl)) {
498633
- return getWithPermittedRedirects(redirectUrl, signal, redirectChecker, depth + 1);
498699
+ return fetchWithRedirectChain(redirectUrl, signal, redirectChecker, depth + 1, deadlineSignal);
498634
498700
  } else {
498635
498701
  return {
498636
498702
  type: "redirect",
@@ -498684,7 +498750,7 @@ async function getURLMarkdownContent(url3, abortController) {
498684
498750
  case "blocked":
498685
498751
  throw new DomainBlockedError(hostname4);
498686
498752
  case "check_failed":
498687
- throw new DomainCheckFailedError(hostname4);
498753
+ throw new DomainCheckFailedError(hostname4, axios_default.isCancel(checkResult.error) ? "EDEADLINE_PREFLIGHT" : undefined);
498688
498754
  }
498689
498755
  }
498690
498756
  if (process.env.USER_TYPE === "ant") {
@@ -498768,12 +498834,14 @@ async function applyPromptToMarkdown(prompt, markdownContent, signal, isNonInter
498768
498834
  }
498769
498835
  return "No response from model";
498770
498836
  }
498771
- var DomainBlockedError, DomainCheckFailedError, EgressBlockedError, MAX_CACHE_SIZE_BYTES, URL_CACHE, DOMAIN_CHECK_CACHE, turndownServicePromise, MAX_URL_LENGTH = 2000, MAX_HTTP_CONTENT_LENGTH = 10485760, FETCH_TIMEOUT_MS3 = 60000, DOMAIN_CHECK_TIMEOUT_MS = 1e4, MAX_REDIRECTS = 10, MAX_MARKDOWN_LENGTH = 1e5;
498837
+ var DomainBlockedError, DomainCheckFailedError, WebFetchTransportError, EgressBlockedError, MAX_CACHE_SIZE_BYTES, URL_CACHE, DOMAIN_CHECK_CACHE, turndownServicePromise, MAX_URL_LENGTH = 2000, MAX_HTTP_CONTENT_LENGTH = 10485760, FETCH_TIMEOUT_MS3 = 60000, DOMAIN_CHECK_TIMEOUT_MS = 1e4, MAX_REDIRECTS = 10, REDIRECT_STATUS_CODES, WEBFETCH_DEADLINE_MS_DEFAULT = 300000, MAX_DEADLINE_MS = 2147483647, MAX_MARKDOWN_LENGTH = 1e5;
498772
498838
  var init_utils12 = __esm(() => {
498773
498839
  init_axios2();
498774
498840
  init_index_min();
498775
498841
  init_analytics();
498776
498842
  init_claude();
498843
+ init_combinedAbortSignal();
498844
+ init_envValidation();
498777
498845
  init_errors();
498778
498846
  init_http4();
498779
498847
  init_log3();
@@ -498789,9 +498857,19 @@ var init_utils12 = __esm(() => {
498789
498857
  }
498790
498858
  };
498791
498859
  DomainCheckFailedError = class DomainCheckFailedError extends Error {
498792
- constructor(domain2) {
498860
+ code;
498861
+ constructor(domain2, code) {
498793
498862
  super(`Unable to verify if domain ${domain2} is safe to fetch. This may be due to network restrictions or enterprise security policies blocking claude.ai.`);
498794
498863
  this.name = "DomainCheckFailedError";
498864
+ this.code = code;
498865
+ }
498866
+ };
498867
+ WebFetchTransportError = class WebFetchTransportError extends Error {
498868
+ code;
498869
+ constructor(message, code) {
498870
+ super(message);
498871
+ this.name = "WebFetchTransportError";
498872
+ this.code = code;
498795
498873
  }
498796
498874
  };
498797
498875
  EgressBlockedError = class EgressBlockedError extends Error {
@@ -498815,6 +498893,13 @@ var init_utils12 = __esm(() => {
498815
498893
  max: 128,
498816
498894
  ttl: 5 * 60 * 1000
498817
498895
  });
498896
+ REDIRECT_STATUS_CODES = new Set([
498897
+ 301,
498898
+ 302,
498899
+ 303,
498900
+ 307,
498901
+ 308
498902
+ ]);
498818
498903
  });
498819
498904
 
498820
498905
  // src/tools/WebFetchTool/WebFetchTool.ts
@@ -625728,9 +625813,28 @@ async function findAvailablePort() {
625728
625813
  });
625729
625814
  return REDIRECT_PORT_FALLBACK;
625730
625815
  } catch {
625816
+ const ephemeralPort = await tryAssignEphemeralPort();
625817
+ if (ephemeralPort !== undefined) {
625818
+ return ephemeralPort;
625819
+ }
625731
625820
  throw new Error(`No available ports for OAuth redirect`);
625732
625821
  }
625733
625822
  }
625823
+ async function tryAssignEphemeralPort() {
625824
+ try {
625825
+ return await new Promise((resolve53) => {
625826
+ const testServer = createServer4();
625827
+ testServer.once("error", () => resolve53(undefined));
625828
+ testServer.listen(0, "127.0.0.1", () => {
625829
+ const address = testServer.address();
625830
+ const port2 = typeof address === "object" && address !== null ? address.port : undefined;
625831
+ testServer.close(() => resolve53(port2));
625832
+ });
625833
+ });
625834
+ } catch {
625835
+ return;
625836
+ }
625837
+ }
625734
625838
  var REDIRECT_PORT_RANGE, REDIRECT_PORT_FALLBACK = 3118;
625735
625839
  var init_oauthPort = __esm(() => {
625736
625840
  init_platform2();
@@ -647111,10 +647215,11 @@ async function clearConversation({
647111
647215
  setConversationId
647112
647216
  }) {
647113
647217
  const sessionEndTimeoutMs = getSessionEndHookTimeoutMs();
647218
+ const sessionEndBudgetMs = getSessionEndHooksBudgetMs();
647114
647219
  await executeSessionEndHooks("clear", {
647115
647220
  getAppState,
647116
647221
  setAppState,
647117
- signal: AbortSignal.timeout(sessionEndTimeoutMs),
647222
+ signal: AbortSignal.timeout(sessionEndBudgetMs),
647118
647223
  timeoutMs: sessionEndTimeoutMs
647119
647224
  });
647120
647225
  const lastRequestId = getLastMainRequestId();
@@ -729176,38 +729281,6 @@ var init_hooks4 = __esm(() => {
729176
729281
  });
729177
729282
  });
729178
729283
 
729179
- // src/utils/combinedAbortSignal.ts
729180
- function createCombinedAbortSignal(signal, opts) {
729181
- const { signalB, timeoutMs } = opts ?? {};
729182
- const combined = createAbortController();
729183
- if (signal?.aborted || signalB?.aborted) {
729184
- combined.abort();
729185
- return { signal: combined.signal, cleanup: () => {} };
729186
- }
729187
- let timer2;
729188
- const abortCombined = () => {
729189
- if (timer2 !== undefined)
729190
- clearTimeout(timer2);
729191
- combined.abort();
729192
- };
729193
- if (timeoutMs !== undefined) {
729194
- timer2 = setTimeout(abortCombined, timeoutMs);
729195
- timer2.unref?.();
729196
- }
729197
- signal?.addEventListener("abort", abortCombined);
729198
- signalB?.addEventListener("abort", abortCombined);
729199
- const cleanup2 = () => {
729200
- if (timer2 !== undefined)
729201
- clearTimeout(timer2);
729202
- signal?.removeEventListener("abort", abortCombined);
729203
- signalB?.removeEventListener("abort", abortCombined);
729204
- };
729205
- return { signal: combined.signal, cleanup: cleanup2 };
729206
- }
729207
- var init_combinedAbortSignal = __esm(() => {
729208
- init_abortController();
729209
- });
729210
-
729211
729284
  // src/utils/hooks/hookHelpers.ts
729212
729285
  function addArgumentsToPrompt(prompt, jsonInput) {
729213
729286
  return substituteArguments(prompt, jsonInput);
@@ -730043,6 +730116,7 @@ __export(exports_hooks2, {
730043
730116
  getTaskCreatedHookMessage: () => getTaskCreatedHookMessage,
730044
730117
  getTaskCompletedHookMessage: () => getTaskCompletedHookMessage,
730045
730118
  getStopHookMessage: () => getStopHookMessage,
730119
+ getSessionEndHooksBudgetMs: () => getSessionEndHooksBudgetMs,
730046
730120
  getSessionEndHookTimeoutMs: () => getSessionEndHookTimeoutMs,
730047
730121
  getPreToolHookBlockingMessage: () => getPreToolHookBlockingMessage,
730048
730122
  getMatchingHooks: () => getMatchingHooks,
@@ -730093,9 +730167,28 @@ function hookCallbackTimeoutMessage(hookName, timeoutMs) {
730093
730167
  return `${hookName} hook callback timed out after ${timeoutMs}ms`;
730094
730168
  }
730095
730169
  function getSessionEndHookTimeoutMs() {
730096
- const raw = process.env.CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS;
730097
- const parsed = raw ? parseEnvInt(raw) : NaN;
730098
- return Number.isFinite(parsed) && parsed > 0 ? parsed : SESSION_END_HOOK_TIMEOUT_MS_DEFAULT;
730170
+ const parsed = parseEnvInt(process.env.CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS);
730171
+ return parsed ?? SESSION_END_HOOK_TIMEOUT_MS_DEFAULT;
730172
+ }
730173
+ function getSessionEndHooksBudgetMs() {
730174
+ const fromEnv5 = parseEnvInt(process.env.CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS);
730175
+ if (fromEnv5 !== undefined) {
730176
+ return fromEnv5;
730177
+ }
730178
+ let maxHookTimeoutMs = 0;
730179
+ try {
730180
+ for (const matcher of getHooksConfigFromSnapshot()?.SessionEnd ?? []) {
730181
+ for (const hook of matcher.hooks ?? []) {
730182
+ const timeoutSec = hook.timeout;
730183
+ if (timeoutSec && timeoutSec * 1000 > maxHookTimeoutMs) {
730184
+ maxHookTimeoutMs = timeoutSec * 1000;
730185
+ }
730186
+ }
730187
+ }
730188
+ } catch (e4) {
730189
+ logError2(e4);
730190
+ }
730191
+ return Math.max(SESSION_END_HOOK_TIMEOUT_MS_DEFAULT, Math.min(maxHookTimeoutMs, SESSION_END_HOOKS_BUDGET_MS_MAX));
730099
730192
  }
730100
730193
  function executeInBackground({
730101
730194
  processId,
@@ -733427,7 +733520,7 @@ async function* executeMessageDisplayHooks(display, getAppState, agentId, signal
733427
733520
  timeoutMs
733428
733521
  });
733429
733522
  }
733430
- var TOOL_HOOK_EXECUTION_TIMEOUT_MS, PRE_TOOL_USE_HOOK_TIMEOUT_MESSAGE = "PreToolUse hook did not respond before its timeout (host client may be unreachable). The tool call was not executed; other configured hooks may not have completed.", SESSION_END_HOOK_TIMEOUT_MS_DEFAULT = 1500, BACKGROUND_TASK_TYPE_LABELS, HOOK_STRING_CAP = 1000, HOOK_JSON_VALIDATION_ERROR_PREFIX = "Hook JSON output validation failed \u2014 ", HOOK_JSON_DISCRIMINATOR_KEYS, MISSING_SCRIPT_HOOK_EVENTS, MATCHER_COMMA_HYPHEN_EVENTS;
733523
+ var TOOL_HOOK_EXECUTION_TIMEOUT_MS, PRE_TOOL_USE_HOOK_TIMEOUT_MESSAGE = "PreToolUse hook did not respond before its timeout (host client may be unreachable). The tool call was not executed; other configured hooks may not have completed.", SESSION_END_HOOK_TIMEOUT_MS_DEFAULT = 1500, SESSION_END_HOOKS_BUDGET_MS_MAX = 60000, BACKGROUND_TASK_TYPE_LABELS, HOOK_STRING_CAP = 1000, HOOK_JSON_VALIDATION_ERROR_PREFIX = "Hook JSON output validation failed \u2014 ", HOOK_JSON_DISCRIMINATOR_KEYS, MISSING_SCRIPT_HOOK_EVENTS, MATCHER_COMMA_HYPHEN_EVENTS;
733431
733524
  var init_hooks5 = __esm(() => {
733432
733525
  init_file();
733433
733526
  init_envValidation();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnwenf/occ",
3
- "version": "2.1.330",
3
+ "version": "2.1.331",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {