@cnwenf/occ 2.1.299 → 2.1.301

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 +343 -36
  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.299","BINARY_NAME":"occ","BUILD_TIME":"2026-08-12T20:49:17.819Z","FEEDBACK_CHANNEL":"","ISSUES_EXPLAINER":"","NATIVE_PACKAGE_URL":"","PACKAGE_URL":"@cnwenf/occ","VERSION_CHANGELOG":""};
2
+ globalThis.MACRO={"VERSION":"2.1.301","BINARY_NAME":"occ","BUILD_TIME":"2026-08-14T18:51:25.355Z","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;
@@ -53615,12 +53615,13 @@ __export(exports_git, {
53615
53615
  getChangedFiles: () => getChangedFiles,
53616
53616
  getBranch: () => getBranch,
53617
53617
  findRemoteBase: () => findRemoteBase,
53618
+ findGitRootUncached: () => findGitRootUncached,
53618
53619
  findGitRoot: () => findGitRoot,
53619
53620
  findCanonicalGitRoot: () => findCanonicalGitRoot,
53620
53621
  dirIsInGitRepo: () => dirIsInGitRepo
53621
53622
  });
53622
53623
  import { createHash } from "crypto";
53623
- import { readFileSync as readFileSync5, realpathSync as realpathSync3, statSync as statSync4 } from "fs";
53624
+ import { lstatSync as lstatSync2, readFileSync as readFileSync5, realpathSync as realpathSync3, statSync as statSync4 } from "fs";
53624
53625
  import { open as open2, readFile as readFile5, realpath as realpath3, stat as stat4 } from "fs/promises";
53625
53626
  import { basename as basename3, dirname as dirname8, join as join14, resolve as resolve6, sep as sep3 } from "path";
53626
53627
  function createFindGitRoot() {
@@ -53631,6 +53632,35 @@ function createFindGitRoot() {
53631
53632
  wrapper.cache = findGitRootImpl.cache;
53632
53633
  return wrapper;
53633
53634
  }
53635
+ function findGitRootUncached(startPath) {
53636
+ let current = resolve6(startPath);
53637
+ const root2 = current.substring(0, current.indexOf(sep3) + 1) || sep3;
53638
+ while (current !== root2) {
53639
+ if (isGitRootForTrust(current)) {
53640
+ return current.normalize("NFC");
53641
+ }
53642
+ const parent = dirname8(current);
53643
+ if (parent === current) {
53644
+ break;
53645
+ }
53646
+ current = parent;
53647
+ }
53648
+ if (isGitRootForTrust(root2)) {
53649
+ return root2.normalize("NFC");
53650
+ }
53651
+ return null;
53652
+ }
53653
+ function isGitRootForTrust(dir) {
53654
+ try {
53655
+ const s = lstatSync2(join14(dir, ".git"));
53656
+ if (s.isSymbolicLink()) {
53657
+ return false;
53658
+ }
53659
+ return s.isDirectory() || s.isFile();
53660
+ } catch {
53661
+ return false;
53662
+ }
53663
+ }
53634
53664
  function createFindCanonicalGitRoot() {
53635
53665
  function wrapper(startPath) {
53636
53666
  const root2 = findGitRoot(startPath);
@@ -152932,31 +152962,44 @@ function computeTrustDialogAccepted() {
152932
152962
  if (projectConfig?.hasTrustDialogAccepted) {
152933
152963
  return true;
152934
152964
  }
152935
- let currentPath = normalizePathForConfigKey(getCwd());
152965
+ const resolvedCwd = resolve9(getCwd());
152966
+ const repoRoot = findGitRootUncached(resolvedCwd);
152967
+ const boundary = repoRoot !== null ? normalizePathForConfigKey(resolve9(repoRoot)) : null;
152968
+ return walkAncestorsForTrust(config4, resolvedCwd, boundary);
152969
+ }
152970
+ function walkAncestorsForTrust(config4, startPath, boundary) {
152971
+ let currentPath = normalizePathForConfigKey(startPath);
152936
152972
  while (true) {
152937
- const pathConfig = config4.projects?.[currentPath];
152938
- if (pathConfig?.hasTrustDialogAccepted) {
152973
+ if (!(boundary === null || currentPath === boundary || currentPath.startsWith(boundary.endsWith("/") ? boundary : `${boundary}/`))) {
152974
+ return false;
152975
+ }
152976
+ if (config4.projects?.[currentPath]?.hasTrustDialogAccepted) {
152939
152977
  return true;
152940
152978
  }
152979
+ if (currentPath === boundary) {
152980
+ return false;
152981
+ }
152941
152982
  const parentPath = normalizePathForConfigKey(resolve9(currentPath, ".."));
152942
152983
  if (parentPath === currentPath) {
152943
- break;
152984
+ return false;
152944
152985
  }
152945
152986
  currentPath = parentPath;
152946
152987
  }
152947
- return false;
152948
152988
  }
152949
- function isPathTrusted(dir) {
152989
+ function isPathTrusted(dir, opts = {}) {
152950
152990
  const config4 = getGlobalConfig();
152951
- let currentPath = normalizePathForConfigKey(resolve9(dir));
152952
- while (true) {
152953
- if (config4.projects?.[currentPath]?.hasTrustDialogAccepted)
152954
- return true;
152955
- const parentPath = normalizePathForConfigKey(resolve9(currentPath, ".."));
152956
- if (parentPath === currentPath)
152957
- return false;
152958
- currentPath = parentPath;
152991
+ if (opts.advisoryNoFsProbe) {
152992
+ return walkAncestorsForTrust(config4, resolve9(dir), null);
152959
152993
  }
152994
+ const canonicalRoot = findCanonicalGitRoot(dir);
152995
+ const persistKey = normalizePathForConfigKey(canonicalRoot !== null ? resolve9(canonicalRoot) : resolve9(dir));
152996
+ if (config4.projects?.[persistKey]?.hasTrustDialogAccepted === true) {
152997
+ return true;
152998
+ }
152999
+ const resolved = resolve9(dir);
153000
+ const repoRoot = findGitRootUncached(resolved);
153001
+ const boundary = repoRoot !== null ? normalizePathForConfigKey(resolve9(repoRoot)) : null;
153002
+ return walkAncestorsForTrust(config4, resolved, boundary);
152960
153003
  }
152961
153004
  function isProjectConfigKey(key) {
152962
153005
  return PROJECT_CONFIG_KEYS.includes(key);
@@ -189468,14 +189511,23 @@ function getCLISyspromptPrefix(options) {
189468
189511
  }
189469
189512
  return DEFAULT_PREFIX;
189470
189513
  }
189471
- function isAttributionHeaderEnabled() {
189472
- if (isEnvDefinedFalsy(process.env.CLAUDE_CODE_ATTRIBUTION_HEADER)) {
189514
+ function isPlainAnthropicApiBaseUrl() {
189515
+ const baseUrl = process.env.ANTHROPIC_BASE_URL;
189516
+ if (!baseUrl) {
189517
+ return true;
189518
+ }
189519
+ try {
189520
+ return ["api.anthropic.com"].includes(new URL(baseUrl).host);
189521
+ } catch {
189473
189522
  return false;
189474
189523
  }
189475
- return getFeatureValue_CACHED_MAY_BE_STALE("tengu_attribution_header", true);
189476
189524
  }
189477
- function getAttributionHeader(fingerprint) {
189478
- if (!isAttributionHeaderEnabled()) {
189525
+ function getAttributionHeader(fingerprint, opts) {
189526
+ const envOptOutBypassed = opts?.ignoreEnvOptOut === true && getAPIProvider() === "firstParty" && isPlainAnthropicApiBaseUrl() && !process.env.ANTHROPIC_UNIX_SOCKET;
189527
+ if (!envOptOutBypassed && isEnvDefinedFalsy(process.env.CLAUDE_CODE_ATTRIBUTION_HEADER)) {
189528
+ return "";
189529
+ }
189530
+ if (!getFeatureValue_CACHED_MAY_BE_STALE("tengu_attribution_header", true)) {
189479
189531
  return "";
189480
189532
  }
189481
189533
  const version5 = `${MACRO.VERSION}.${fingerprint}`;
@@ -201253,7 +201305,7 @@ __export(exports_sandbox_adapter, {
201253
201305
  SandboxRuntimeConfigSchema: () => SandboxRuntimeConfigSchema,
201254
201306
  SandboxManager: () => SandboxManager2
201255
201307
  });
201256
- import { lstatSync as lstatSync3, readdirSync as readdirSync4, realpathSync as realpathSync6, rmSync as rmSync4, statSync as statSync8 } from "fs";
201308
+ import { lstatSync as lstatSync4, readdirSync as readdirSync4, realpathSync as realpathSync6, rmSync as rmSync4, statSync as statSync8 } from "fs";
201257
201309
  import { readFile as readFile15 } from "fs/promises";
201258
201310
  import { join as join39, resolve as resolve17, sep as sep9 } from "path";
201259
201311
  function permissionRuleValueFromString2(ruleString) {
@@ -201416,7 +201468,7 @@ function convertToSandboxRuntimeConfig(settings) {
201416
201468
  }
201417
201469
  }
201418
201470
  const { rgPath, rgArgs, argv0 } = ripgrepCommand();
201419
- const ripgrepConfig = settings.sandbox?.ripgrep ?? {
201471
+ const ripgrepConfig = ["policySettings", "flagSettings", "userSettings"].map((source) => getSettingsForSource(source)?.sandbox?.ripgrep).find((config5) => config5 !== undefined) ?? {
201420
201472
  command: rgPath,
201421
201473
  args: rgArgs,
201422
201474
  argv0
@@ -201456,7 +201508,7 @@ function reconcileClaudeSymlinks(dirs) {
201456
201508
  for (const name3 of entries) {
201457
201509
  const entryPath = join39(claudeDir, name3);
201458
201510
  try {
201459
- if (!lstatSync3(entryPath).isSymbolicLink()) {
201511
+ if (!lstatSync4(entryPath).isSymbolicLink()) {
201460
201512
  continue;
201461
201513
  }
201462
201514
  } catch {
@@ -372201,7 +372253,9 @@ function ruleIdToLabel(ruleId) {
372201
372253
  digitalocean: "DigitalOcean",
372202
372254
  huggingface: "HuggingFace",
372203
372255
  hashicorp: "HashiCorp",
372204
- sendgrid: "SendGrid"
372256
+ sendgrid: "SendGrid",
372257
+ ci: "CI",
372258
+ scim: "SCIM"
372205
372259
  };
372206
372260
  return ruleId.split("-").map((part) => specialCase[part] ?? capitalize(part)).join(" ");
372207
372261
  }
@@ -372232,7 +372286,7 @@ function redactSecrets(content) {
372232
372286
  }
372233
372287
  return content;
372234
372288
  }
372235
- var ANT_KEY_PFX, SECRET_RULES, compiledRules = null, redactRules = null;
372289
+ var ANT_KEY_PFX, GITLAB_TOKEN_BODY = "[\\w=-]{20,}(?:\\.[0-9a-z]{9})?", SECRET_RULES, compiledRules = null, redactRules = null;
372236
372290
  var init_secretScanner = __esm(() => {
372237
372291
  init_stringUtils();
372238
372292
  ANT_KEY_PFX = ["sk", "ant", "api"].join("-");
@@ -372295,11 +372349,47 @@ var init_secretScanner = __esm(() => {
372295
372349
  },
372296
372350
  {
372297
372351
  id: "gitlab-pat",
372298
- source: "glpat-[\\w-]{20}"
372352
+ source: `glpat-${GITLAB_TOKEN_BODY}`
372299
372353
  },
372300
372354
  {
372301
372355
  id: "gitlab-deploy-token",
372302
- source: "gldt-[0-9a-zA-Z_\\-]{20}"
372356
+ source: `gldt-${GITLAB_TOKEN_BODY}`
372357
+ },
372358
+ {
372359
+ id: "gitlab-runner-authentication-token",
372360
+ source: `glrt-${GITLAB_TOKEN_BODY}`
372361
+ },
372362
+ {
372363
+ id: "gitlab-oauth-app-secret",
372364
+ source: `gloas-${GITLAB_TOKEN_BODY}`
372365
+ },
372366
+ {
372367
+ id: "gitlab-pipeline-trigger-token",
372368
+ source: `glptt-${GITLAB_TOKEN_BODY}`
372369
+ },
372370
+ {
372371
+ id: "gitlab-kubernetes-agent-token",
372372
+ source: `glagent-${GITLAB_TOKEN_BODY}`
372373
+ },
372374
+ {
372375
+ id: "gitlab-incoming-mail-token",
372376
+ source: `glimt-${GITLAB_TOKEN_BODY}`
372377
+ },
372378
+ {
372379
+ id: "gitlab-scim-oauth-token",
372380
+ source: `glsoat-${GITLAB_TOKEN_BODY}`
372381
+ },
372382
+ {
372383
+ id: "gitlab-ci-build-token",
372384
+ source: `glcbt-${GITLAB_TOKEN_BODY}`
372385
+ },
372386
+ {
372387
+ id: "gitlab-feed-token",
372388
+ source: `glft-${GITLAB_TOKEN_BODY}`
372389
+ },
372390
+ {
372391
+ id: "gitlab-feature-flag-client-token",
372392
+ source: `glffct-${GITLAB_TOKEN_BODY}`
372303
372393
  },
372304
372394
  {
372305
372395
  id: "slack-bot-token",
@@ -379578,6 +379668,33 @@ function validateOutputRedirections(redirections, cwd2, toolPermissionContext, c
379578
379668
  message: "No unsafe redirections found"
379579
379669
  };
379580
379670
  }
379671
+ function validateInputRedirections(astRedirects, cwd2, toolPermissionContext) {
379672
+ for (const r4 of astRedirects) {
379673
+ if (r4.op !== "<" || r4.target === "/dev/null") {
379674
+ continue;
379675
+ }
379676
+ const { allowed, resolvedPath, decisionReason } = validatePath(r4.target, cwd2, toolPermissionContext, "read");
379677
+ if (allowed) {
379678
+ continue;
379679
+ }
379680
+ const message = decisionReason?.type === "other" || decisionReason?.type === "safetyCheck" ? decisionReason.reason : decisionReason?.type === "rule" ? `Input redirection from '${resolvedPath}' was blocked by a deny rule.` : `Input redirection from '${resolvedPath}' was blocked. For security, Claude Code may only read files in the allowed working directories for this session.`;
379681
+ if (decisionReason?.type === "rule") {
379682
+ return { behavior: "deny", message, decisionReason };
379683
+ }
379684
+ const suggestion = decisionReason === undefined ? createReadRuleSuggestion(getDirectoryForPath(resolvedPath), "session") : undefined;
379685
+ return {
379686
+ behavior: "ask",
379687
+ message,
379688
+ blockedPath: resolvedPath,
379689
+ decisionReason,
379690
+ ...suggestion !== undefined && { suggestions: [suggestion] }
379691
+ };
379692
+ }
379693
+ return {
379694
+ behavior: "passthrough",
379695
+ message: "No unsafe input redirections found"
379696
+ };
379697
+ }
379581
379698
  function checkPathConstraints(input, cwd2, toolPermissionContext, compoundCommandHasCd, astRedirects, astCommands) {
379582
379699
  if (!astCommands && />>\s*>\s*\(|>\s*>\s*\(|<\s*\(/.test(input.command)) {
379583
379700
  return {
@@ -379604,6 +379721,12 @@ function checkPathConstraints(input, cwd2, toolPermissionContext, compoundComman
379604
379721
  if (redirectionResult.behavior !== "passthrough") {
379605
379722
  return redirectionResult;
379606
379723
  }
379724
+ if (astRedirects) {
379725
+ const inputRedirectResult = validateInputRedirections(astRedirects, cwd2, toolPermissionContext);
379726
+ if (inputRedirectResult.behavior !== "passthrough") {
379727
+ return inputRedirectResult;
379728
+ }
379729
+ }
379607
379730
  if (astCommands) {
379608
379731
  for (const cmd of astCommands) {
379609
379732
  const result = validateSinglePathCommandArgv(cmd, cwd2, toolPermissionContext, compoundCommandHasCd);
@@ -389452,7 +389575,7 @@ async function sideQuery(opts) {
389452
389575
  }
389453
389576
  const messageText = extractFirstUserMessageText(messages);
389454
389577
  const fingerprint = computeFingerprint(messageText, MACRO.VERSION);
389455
- const attributionHeader = getAttributionHeader(fingerprint);
389578
+ const attributionHeader = getAttributionHeader(fingerprint, opts.forceAttributionHeader ? { ignoreEnvOptOut: true } : undefined);
389456
389579
  const systemBlocks = [
389457
389580
  attributionHeader ? { type: "text", text: attributionHeader } : null,
389458
389581
  ...skipSystemPromptPrefix ? [] : [
@@ -390318,6 +390441,7 @@ async function classifyYoloActionXml(prefixMessages, systemPrompt, userPrompt, u
390318
390441
  max_tokens: (mode === "fast" ? 256 : 64) + thinkingPadding,
390319
390442
  system: systemBlocks,
390320
390443
  skipSystemPromptPrefix: true,
390444
+ forceAttributionHeader: true,
390321
390445
  temperature: 0,
390322
390446
  thinking: disableThinking,
390323
390447
  messages: [
@@ -390398,6 +390522,7 @@ async function classifyYoloActionXml(prefixMessages, systemPrompt, userPrompt, u
390398
390522
  max_tokens: 4096 + thinkingPadding,
390399
390523
  system: systemBlocks,
390400
390524
  skipSystemPromptPrefix: true,
390525
+ forceAttributionHeader: true,
390401
390526
  temperature: 0,
390402
390527
  thinking: disableThinking,
390403
390528
  messages: [
@@ -390594,6 +390719,7 @@ async function classifyYoloAction(messages, action2, tools, context4, signal) {
390594
390719
  }
390595
390720
  ],
390596
390721
  skipSystemPromptPrefix: true,
390722
+ forceAttributionHeader: true,
390597
390723
  temperature: 0,
390598
390724
  thinking: disableThinking,
390599
390725
  messages: [
@@ -459890,11 +460016,27 @@ var init_bypassPermissionsKillswitch = __esm(() => {
459890
460016
  // src/commands/login/login.tsx
459891
460017
  var exports_login = {};
459892
460018
  __export(exports_login, {
460019
+ getLoginStartingMessage: () => getLoginStartingMessage,
459893
460020
  call: () => call2,
460021
+ buildLoginDoneMessage: () => buildLoginDoneMessage,
459894
460022
  Login: () => Login
459895
460023
  });
460024
+ function getLoginStartingMessage() {
460025
+ return process.env.CLAUDE_CODE_OAUTH_TOKEN ? `Warning: CLAUDE_CODE_OAUTH_TOKEN is set in your environment. This session will switch to your new credentials after logging in, ${ENV_TOKEN_OVERRIDE_WARNING_TAIL}` : undefined;
460026
+ }
460027
+ function buildLoginDoneMessage(success2, opts) {
460028
+ if (!success2)
460029
+ return "Login interrupted";
460030
+ const base2 = opts.bridgeDisconnected ? `Login successful. ${REMOTE_CONTROL_DISCONNECTED_NOTE}` : "Login successful";
460031
+ return opts.envTokenWasSet && !opts.gatewayActive ? `${base2}
460032
+
460033
+ ${ENV_TOKEN_OVERRIDE_DONE_NOTE}` : base2;
460034
+ }
459896
460035
  async function call2(onDone, context6) {
460036
+ const startingMessage = getLoginStartingMessage();
460037
+ const envTokenWasSet = startingMessage !== undefined;
459897
460038
  return /* @__PURE__ */ jsx_runtime84.jsx(Login, {
460039
+ startingMessage,
459898
460040
  onDone: async (success2) => {
459899
460041
  context6.onChangeAPIKey();
459900
460042
  context6.setMessages(stripSignatureBlocks);
@@ -459918,7 +460060,11 @@ async function call2(onDone, context6) {
459918
460060
  authVersion: prev.authVersion + 1
459919
460061
  }));
459920
460062
  }
459921
- onDone(success2 ? "Login successful" : "Login interrupted");
460063
+ onDone(buildLoginDoneMessage(success2, {
460064
+ bridgeDisconnected: false,
460065
+ envTokenWasSet,
460066
+ gatewayActive: getAPIProvider() === "gateway"
460067
+ }));
459922
460068
  }
459923
460069
  });
459924
460070
  }
@@ -459986,7 +460132,7 @@ function _temp14(exitState) {
459986
460132
  description: "cancel"
459987
460133
  });
459988
460134
  }
459989
- var import_compiler_runtime71, jsx_runtime84;
460135
+ var import_compiler_runtime71, jsx_runtime84, ENV_TOKEN_OVERRIDE_WARNING_TAIL = "but if that variable is set in your shell profile or a Claude Code settings file, new `claude` sessions will keep using the old token until you remove it there.", ENV_TOKEN_OVERRIDE_DONE_NOTE, REMOTE_CONTROL_DISCONNECTED_NOTE = "Remote Control disconnected.";
459990
460136
  var init_login = __esm(() => {
459991
460137
  init_featureFlags();
459992
460138
  init_state();
@@ -460000,10 +460146,12 @@ var init_login = __esm(() => {
460000
460146
  init_policyLimits();
460001
460147
  init_remoteManagedSettings();
460002
460148
  init_messages3();
460149
+ init_providers();
460003
460150
  init_bypassPermissionsKillswitch();
460004
460151
  init_user();
460005
460152
  import_compiler_runtime71 = __toESM(require_compiler_runtime(), 1);
460006
460153
  jsx_runtime84 = __toESM(require_jsx_runtime(), 1);
460154
+ ENV_TOKEN_OVERRIDE_DONE_NOTE = `Note: CLAUDE_CODE_OAUTH_TOKEN was set in your environment when /login started. This session will use your new credentials, ${ENV_TOKEN_OVERRIDE_WARNING_TAIL}`;
460007
460155
  });
460008
460156
 
460009
460157
  // src/utils/teleport/api.ts
@@ -584100,6 +584248,142 @@ var init_errors11 = __esm(() => {
584100
584248
  };
584101
584249
  });
584102
584250
 
584251
+ // src/tools/WorkflowTool/prefixStagger.ts
584252
+ function createWarmingEntry() {
584253
+ let release;
584254
+ const ready = new Promise((resolve44) => {
584255
+ release = resolve44;
584256
+ });
584257
+ return { state: "warming", ready, release: () => release?.() };
584258
+ }
584259
+ function sleepWithAbort(ms, signal) {
584260
+ return new Promise((resolve44) => {
584261
+ if (signal?.aborted) {
584262
+ resolve44();
584263
+ return;
584264
+ }
584265
+ const onAbort = () => {
584266
+ clearTimeout(timer2);
584267
+ resolve44();
584268
+ };
584269
+ const timer2 = setTimeout(() => {
584270
+ signal?.removeEventListener("abort", onAbort);
584271
+ resolve44();
584272
+ }, ms);
584273
+ signal?.addEventListener("abort", onAbort, { once: true });
584274
+ });
584275
+ }
584276
+ function raceReadyWithTimeout(ready, timeoutMs, signal) {
584277
+ if (signal?.aborted)
584278
+ return Promise.resolve();
584279
+ const controller = new AbortController;
584280
+ const onAbort = () => controller.abort();
584281
+ signal?.addEventListener("abort", onAbort, { once: true });
584282
+ return Promise.race([ready, sleepWithAbort(timeoutMs, controller.signal)]).finally(() => {
584283
+ controller.abort();
584284
+ signal?.removeEventListener("abort", onAbort);
584285
+ });
584286
+ }
584287
+
584288
+ class WorkflowPrefixStaggerGate {
584289
+ now;
584290
+ entries = new Map;
584291
+ constructor(now2 = Date.now) {
584292
+ this.now = now2;
584293
+ }
584294
+ async enter(key3, opts) {
584295
+ const now2 = this.now();
584296
+ for (const [k5, entry] of this.entries) {
584297
+ if (entry.state === "warm" && entry.until <= now2) {
584298
+ this.entries.delete(k5);
584299
+ }
584300
+ }
584301
+ const existing = this.entries.get(key3);
584302
+ let warming;
584303
+ let waitedMs = 0;
584304
+ if (existing === undefined) {
584305
+ warming = createWarmingEntry();
584306
+ this.entries.set(key3, warming);
584307
+ } else if (existing.state === "warming" && opts.capMs > 0) {
584308
+ const start = this.now();
584309
+ await raceReadyWithTimeout(existing.ready, opts.capMs, opts.signal);
584310
+ waitedMs = Math.max(0, this.now() - start);
584311
+ }
584312
+ let respondedFired = false;
584313
+ return {
584314
+ leader: warming !== undefined,
584315
+ waitedMs,
584316
+ responded: () => {
584317
+ respondedFired = true;
584318
+ this.markWarm(key3);
584319
+ },
584320
+ done: () => {
584321
+ if (respondedFired || warming === undefined)
584322
+ return;
584323
+ if (this.entries.get(key3) === warming && warming.state === "warming") {
584324
+ this.entries.delete(key3);
584325
+ warming.release();
584326
+ }
584327
+ }
584328
+ };
584329
+ }
584330
+ stateOf(key3) {
584331
+ const entry = this.entries.get(key3);
584332
+ if (entry === undefined)
584333
+ return "cold";
584334
+ if (entry.state === "warm") {
584335
+ return entry.until > this.now() ? "warm" : "cold";
584336
+ }
584337
+ return "warming";
584338
+ }
584339
+ clear() {
584340
+ for (const entry of this.entries.values()) {
584341
+ if (entry.state === "warming")
584342
+ entry.release();
584343
+ }
584344
+ this.entries.clear();
584345
+ }
584346
+ markWarm(key3) {
584347
+ const existing = this.entries.get(key3);
584348
+ this.entries.set(key3, {
584349
+ state: "warm",
584350
+ until: this.now() + WORKFLOW_PREFIX_WARM_TTL_MS
584351
+ });
584352
+ if (existing?.state === "warming")
584353
+ existing.release();
584354
+ }
584355
+ }
584356
+ function getWorkflowPrefixStaggerGate() {
584357
+ return singleton ??= new WorkflowPrefixStaggerGate;
584358
+ }
584359
+ function getWorkflowPrefixStaggerCapMs(env7 = process.env) {
584360
+ if (isEnvTruthy(env7.DISABLE_PROMPT_CACHING)) {
584361
+ return 0;
584362
+ }
584363
+ const raw = env7.CLAUDE_CODE_WORKFLOW_PREFIX_STAGGER_MS;
584364
+ if (raw !== undefined && raw !== "") {
584365
+ const parsed = Number.parseInt(raw, 10);
584366
+ if (Number.isFinite(parsed) && parsed >= 0)
584367
+ return parsed;
584368
+ }
584369
+ return WORKFLOW_PREFIX_STAGGER_DEFAULT_MS;
584370
+ }
584371
+ function buildWorkflowPrefixKey(parts) {
584372
+ return [
584373
+ parts.model ?? "",
584374
+ String(parts.effort ?? ""),
584375
+ parts.agentType,
584376
+ parts.toolNames,
584377
+ parts.schemaJson,
584378
+ parts.cwd
584379
+ ].join(`
584380
+ `);
584381
+ }
584382
+ var WORKFLOW_PREFIX_WARM_TTL_MS = 270000, WORKFLOW_PREFIX_STAGGER_DEFAULT_MS = 5000, singleton;
584383
+ var init_prefixStagger = __esm(() => {
584384
+ init_envUtils();
584385
+ });
584386
+
584103
584387
  // src/tools/WorkflowTool/primitives.ts
584104
584388
  function workflowAgentTelemetryAttributes(runId, workflowName) {
584105
584389
  return {
@@ -584291,10 +584575,29 @@ You MUST call the ${SYNTHETIC_OUTPUT_TOOL_NAME} tool exactly once at the end of
584291
584575
  })
584292
584576
  ];
584293
584577
  let agentTokens = 0;
584294
- const onQueryProgress = () => {};
584295
584578
  const agentId = createAgentId("wf");
584296
584579
  const agentShortId = agentId.slice(0, 16);
584297
584580
  const agentLabel = opts.label ?? prompt.slice(0, 80);
584581
+ const agentStartTime = Date.now();
584582
+ const agentModel = opts.model ?? getMainLoopModel();
584583
+ const prefixKey = buildWorkflowPrefixKey({
584584
+ model: agentModel,
584585
+ effort: opts.effort,
584586
+ agentType: agentDef.agentType,
584587
+ toolNames: ctx.availableTools.map((t4) => t4.name).join(","),
584588
+ schemaJson: opts.schema ? JSON.stringify(opts.schema) : "",
584589
+ cwd: worktreePath ?? getCwd()
584590
+ });
584591
+ const staggerHandle = await getWorkflowPrefixStaggerGate().enter(prefixKey, {
584592
+ capMs: getWorkflowPrefixStaggerCapMs(),
584593
+ signal: ctx.abortController.signal
584594
+ });
584595
+ if (staggerHandle.waitedMs > 0) {
584596
+ logForDebugging(`workflow agent [${agentLabel}] held ${staggerHandle.waitedMs}ms for a same-prefix sibling's first response (prompt-cache warm-up)`);
584597
+ }
584598
+ const onQueryProgress = () => {
584599
+ staggerHandle.responded();
584600
+ };
584298
584601
  const gen = runAgent({
584299
584602
  agentDefinition: agentDef,
584300
584603
  promptMessages,
@@ -584313,8 +584616,6 @@ You MUST call the ${SYNTHETIC_OUTPUT_TOOL_NAME} tool exactly once at the end of
584313
584616
  onQueryProgress,
584314
584617
  override: { agentId }
584315
584618
  });
584316
- const agentStartTime = Date.now();
584317
- const agentModel = opts.model ?? getMainLoopModel();
584318
584619
  logEvent2("tengu_workflow_agent_started", {
584319
584620
  ...workflowAgentTelemetryAttributes(ctx.runId, ctx.workflowName),
584320
584621
  agent_id: agentShortId,
@@ -584361,6 +584662,8 @@ You MUST call the ${SYNTHETIC_OUTPUT_TOOL_NAME} tool exactly once at the end of
584361
584662
  elapsedMs: Math.max(0, Date.now() - agentStartTime)
584362
584663
  });
584363
584664
  throw e4;
584665
+ } finally {
584666
+ staggerHandle.done();
584364
584667
  }
584365
584668
  agentTokens = extractTokenUsage(messages);
584366
584669
  ctx.counters.spentTokens += agentTokens;
@@ -584617,7 +584920,10 @@ var init_primitives = __esm(() => {
584617
584920
  init_SyntheticOutputTool();
584618
584921
  init_errors11();
584619
584922
  init_journal();
584923
+ init_prefixStagger();
584620
584924
  init_model();
584925
+ init_cwd2();
584926
+ init_debug();
584621
584927
  });
584622
584928
 
584623
584929
  // src/utils/effort/workflowDiscovery.ts
@@ -616820,7 +617126,7 @@ function getMcpAutoBackgroundMs(tool, {
616820
617126
  function isPipeNonInteractiveModeDefault() {
616821
617127
  return isPipeNonInteractiveMode();
616822
617128
  }
616823
- function sleepWithAbort(ms, signal) {
617129
+ function sleepWithAbort2(ms, signal) {
616824
617130
  return new Promise((resolve53) => {
616825
617131
  if (signal.aborted) {
616826
617132
  resolve53("timeout");
@@ -616862,7 +617168,7 @@ async function callMcpToolWithAutoBackground({
616862
617168
  while (true) {
616863
617169
  const winner = await Promise.race([
616864
617170
  settledPromise,
616865
- sleepWithAbort(autoBackgroundMs, raceController.signal)
617171
+ sleepWithAbort2(autoBackgroundMs, raceController.signal)
616866
617172
  ]);
616867
617173
  if (winner === "settled" || parentAbortController.signal.aborted) {
616868
617174
  raceController.abort();
@@ -823248,6 +823554,7 @@ async function autoModeCritiqueHandler(options) {
823248
823554
  model,
823249
823555
  system: CRITIQUE_SYSTEM_PROMPT,
823250
823556
  skipSystemPromptPrefix: true,
823557
+ forceAttributionHeader: true,
823251
823558
  max_tokens: 4096,
823252
823559
  messages: [
823253
823560
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnwenf/occ",
3
- "version": "2.1.299",
3
+ "version": "2.1.301",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {