@openclaw/tokenjuice 2026.11.10-beta.3 → 2026.12.1-beta.1

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 (46) hide show
  1. package/node_modules/tokenjuice/README.md +133 -6
  2. package/node_modules/tokenjuice/dist/cli/main.d.ts +1 -2
  3. package/node_modules/tokenjuice/dist/cli/main.js +3 -18
  4. package/node_modules/tokenjuice/dist/core/analysis.js +7 -10
  5. package/node_modules/tokenjuice/dist/core/artifacts.d.ts +1 -1
  6. package/node_modules/tokenjuice/dist/core/artifacts.js +4 -3
  7. package/node_modules/tokenjuice/dist/core/command-identity.js +7 -6
  8. package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +3 -2
  9. package/node_modules/tokenjuice/dist/core/compaction-metadata.js +2 -1
  10. package/node_modules/tokenjuice/dist/core/failure-summary.d.ts +7 -0
  11. package/node_modules/tokenjuice/dist/core/failure-summary.js +76 -0
  12. package/node_modules/tokenjuice/dist/core/inventory-safety.js +14 -6
  13. package/node_modules/tokenjuice/dist/core/reduce-utils.js +9 -7
  14. package/node_modules/tokenjuice/dist/core/reduce.js +32 -21
  15. package/node_modules/tokenjuice/dist/core/streamed-text-counter.d.ts +8 -0
  16. package/node_modules/tokenjuice/dist/core/streamed-text-counter.js +56 -0
  17. package/node_modules/tokenjuice/dist/core/text.d.ts +1 -0
  18. package/node_modules/tokenjuice/dist/core/text.js +22 -11
  19. package/node_modules/tokenjuice/dist/core/wrap-format.d.ts +3 -0
  20. package/node_modules/tokenjuice/dist/core/wrap-format.js +34 -0
  21. package/node_modules/tokenjuice/dist/core/wrap.js +55 -6
  22. package/node_modules/tokenjuice/dist/hosts/codex/index.js +37 -10
  23. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/index.js +221 -79
  24. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/package.json +1 -1
  25. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/plugin.yaml +1 -1
  26. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/README.md +4 -2
  27. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/bridge.py +62 -5
  28. package/node_modules/tokenjuice/dist/hosts/openclaw/extension.js +7 -2
  29. package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +221 -79
  30. package/node_modules/tokenjuice/dist/hosts/opencode/v2/bundle/index.js +221 -79
  31. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +221 -79
  32. package/node_modules/tokenjuice/dist/python/README.md +1 -1
  33. package/node_modules/tokenjuice/dist/python/pyproject.toml +1 -1
  34. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/README.md +4 -2
  35. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/bridge.py +62 -5
  36. package/node_modules/tokenjuice/dist/rules/build/tsc.json +8 -3
  37. package/node_modules/tokenjuice/dist/rules/fixtures/build/tsc.fixture.json +6 -2
  38. package/node_modules/tokenjuice/dist/rules/install/bun-install.json +12 -4
  39. package/node_modules/tokenjuice/dist/rules/install/npm-ci.json +12 -4
  40. package/node_modules/tokenjuice/dist/rules/install/npm-install.json +12 -4
  41. package/node_modules/tokenjuice/dist/rules/install/pnpm-install.json +12 -4
  42. package/node_modules/tokenjuice/dist/rules/install/yarn-install.json +12 -4
  43. package/node_modules/tokenjuice/dist/rules/tests/pytest.json +8 -3
  44. package/node_modules/tokenjuice/dist/types.d.ts +3 -0
  45. package/node_modules/tokenjuice/package.json +5 -15
  46. package/package.json +5 -5
@@ -952,8 +952,8 @@ function isGhApiContentsDecodeCommand(command) {
952
952
  }
953
953
  return /\bgh\s+api\b/u.test(command) && /\/contents\//u.test(command) && /--jq(?:=|\s+)['"]?\.content['"]?/u.test(command) && /\|\s*base64\s+(?:-[dD]\b|--decode\b)/u.test(command);
954
954
  }
955
- function getMostDerivedCandidate(input) {
956
- return deriveCommandMatchCandidates(input).reduce((best, candidate) => getSourcePriority(candidate.source) >= getSourcePriority(best.source) ? candidate : best);
955
+ function getMostDerivedCandidate(input, candidates = deriveCommandMatchCandidates(input)) {
956
+ return candidates.reduce((best, candidate) => getSourcePriority(candidate.source) >= getSourcePriority(best.source) ? candidate : best);
957
957
  }
958
958
  function extractPipelineSourceCommand(command) {
959
959
  let current = "";
@@ -990,8 +990,8 @@ function extractPipelineSourceCommand(command) {
990
990
  }
991
991
  return current.trim();
992
992
  }
993
- function getInspectionArgv(input) {
994
- const candidate = getMostDerivedCandidate(input);
993
+ function getInspectionArgv(input, candidates = deriveCommandMatchCandidates(input)) {
994
+ const candidate = getMostDerivedCandidate(input, candidates);
995
995
  if (candidate.argv.length > 0) {
996
996
  return candidate.argv;
997
997
  }
@@ -1002,7 +1002,8 @@ function getInspectionArgv(input) {
1002
1002
  return sourceCommand ? tokenizeCommand(sourceCommand) : [];
1003
1003
  }
1004
1004
  function isFileContentInspectionCommand(input) {
1005
- return isFileContentInspectionArgv(getInspectionArgv(input)) || deriveCommandMatchCandidates(input).some((candidate) => isGhApiContentsDecodeCommand(candidate.command));
1005
+ const candidates = deriveCommandMatchCandidates(input);
1006
+ return isFileContentInspectionArgv(getInspectionArgv(input, candidates)) || candidates.some((candidate) => isGhApiContentsDecodeCommand(candidate.command));
1006
1007
  }
1007
1008
  function isVerbatimRemoteInspectionCommand(command) {
1008
1009
  const effectiveCommand = unwrapShellRunner({ command }) ?? command;
@@ -1328,6 +1329,9 @@ function isSafeRepositoryInventorySource(argv) {
1328
1329
  }
1329
1330
  function isRepositoryInventoryCommand(input) {
1330
1331
  const argv = input.argv?.length ? getEffectiveCommandArgv(input) : getRepositoryInventorySourceArgv(input.command ?? "");
1332
+ return isRepositoryInventoryArgv(argv);
1333
+ }
1334
+ function isRepositoryInventoryArgv(argv) {
1331
1335
  const argv0 = getCommandName(argv);
1332
1336
  if (!argv0) {
1333
1337
  return false;
@@ -1368,11 +1372,15 @@ function getRepositoryInventorySafety(command) {
1368
1372
  }
1369
1373
  function isRepositoryInspectionCommand2(input) {
1370
1374
  const argv = input.argv?.length ? getEffectiveCommandArgv(input) : getRepositoryInventorySourceArgv(input.command ?? "");
1375
+ return isPreparedRepositoryInspection({ argv, fileContent: isFileContentInspectionCommand(input) });
1376
+ }
1377
+ function isPreparedRepositoryInspection(analysis) {
1378
+ const { argv, fileContent } = analysis;
1371
1379
  const argv0 = getCommandName(argv);
1372
- if (isFileContentInspectionCommand(input)) {
1380
+ if (fileContent) {
1373
1381
  return true;
1374
1382
  }
1375
- if (isRepositoryInventoryCommand(input)) {
1383
+ if (isRepositoryInventoryArgv(argv)) {
1376
1384
  return true;
1377
1385
  }
1378
1386
  if (argv0 && REPO_INSPECTION_ONLY_COMMANDS.has(argv0)) {
@@ -1394,15 +1402,16 @@ function getInspectionCommandSkipReason(command, policy) {
1394
1402
  if (policy === "skip-all") {
1395
1403
  return isRepositoryInspectionCommand2({ command }) ? "inspection-command" : null;
1396
1404
  }
1397
- if (isFileContentInspectionCommand({ command }) && !hasCommandOnlyFileContentSummary(command)) {
1405
+ const fileContent = isFileContentInspectionCommand({ command });
1406
+ if (fileContent && !hasCommandOnlyFileContentSummary(command)) {
1398
1407
  return "file-content-inspection-command";
1399
1408
  }
1400
1409
  if (policy === "skip-file-content") {
1401
1410
  return null;
1402
1411
  }
1403
- if (isRepositoryInspectionCommand2({ command })) {
1404
- const sourceArgv = getRepositoryInventorySourceArgv(command);
1405
- const argv0 = getCommandName(sourceArgv);
1412
+ const analysis = { argv: getRepositoryInventorySourceArgv(command), fileContent };
1413
+ if (isPreparedRepositoryInspection(analysis)) {
1414
+ const argv0 = getCommandName(analysis.argv);
1406
1415
  if (argv0 && REPO_INSPECTION_ONLY_COMMANDS.has(argv0)) {
1407
1416
  return "inspection-command";
1408
1417
  }
@@ -1733,7 +1742,7 @@ var FLAG_EMOJI_PATTERN = new RegExp("^\\p{Regional_Indicator}{2}$", "u");
1733
1742
  var KEYCAP_EMOJI_PATTERN = /^[#*0-9]\uFE0F?\u20E3$/u;
1734
1743
  var REPEATED_EMOJI_BANNER_MIN_REPETITIONS = 24;
1735
1744
  var graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : null;
1736
- function graphemes(text) {
1745
+ function segmentTextChars(text) {
1737
1746
  if (!graphemeSegmenter) {
1738
1747
  return Array.from(text);
1739
1748
  }
@@ -1757,10 +1766,13 @@ function stripAnsi(text) {
1757
1766
  return text.replaceAll(ANSI_OSC_PATTERN, "").replaceAll(ANSI_CSI_PATTERN, "").replaceAll(ANSI_OSC_INCOMPLETE_PATTERN, "").replaceAll(ANSI_CSI_INCOMPLETE_PATTERN, "").replaceAll(ANSI_SINGLE_PATTERN, "").replaceAll("\x1B", "");
1758
1767
  }
1759
1768
  function countTextChars(text) {
1760
- return graphemes(text).length;
1769
+ const iterator = graphemeSegmenter ? graphemeSegmenter.segment(text)[Symbol.iterator]() : text[Symbol.iterator]();
1770
+ let count = 0;
1771
+ while (!iterator.next().done) count += 1;
1772
+ return count;
1761
1773
  }
1762
1774
  function sliceTextChars(text, start, end) {
1763
- return graphemes(text).slice(start, end).join("");
1775
+ return segmentTextChars(text).slice(start, end).join("");
1764
1776
  }
1765
1777
  function normalizeLines(text) {
1766
1778
  return text.replaceAll("\r\n", "\n").split("\n").map((line) => line.replace(/\s+$/u, ""));
@@ -1794,7 +1806,7 @@ function isEmojiGrapheme(text) {
1794
1806
  function collapseRepeatedEmojiBanner(lines) {
1795
1807
  let collapsed = false;
1796
1808
  const nextLines = lines.map((line) => {
1797
- const visibleSegments = graphemes(line).filter((segment) => !/^\s+$/u.test(segment));
1809
+ const visibleSegments = segmentTextChars(line).filter((segment) => !/^\s+$/u.test(segment));
1798
1810
  const repeatedEmoji = visibleSegments[0];
1799
1811
  if (visibleSegments.length < REPEATED_EMOJI_BANNER_MIN_REPETITIONS || !repeatedEmoji || !isEmojiGrapheme(repeatedEmoji) || visibleSegments.some((segment) => segment !== repeatedEmoji)) {
1800
1812
  return line;
@@ -1831,16 +1843,14 @@ function headTail(lines, head, tail, noOmit = false) {
1831
1843
  compaction: createCompactionMetadata("head-tail-omission")
1832
1844
  };
1833
1845
  }
1834
- function clampText(text, maxChars) {
1835
- if (countTextChars(text) <= maxChars) {
1836
- return text;
1837
- }
1846
+ function clampSegments(segments, maxChars) {
1838
1847
  const bodyChars = Math.max(0, maxChars - countTextChars(TRUNCATION_SUFFIX));
1839
- const head = trimHeadToLineBoundary(graphemes(text).slice(0, bodyChars).join(""));
1848
+ const head = trimHeadToLineBoundary(segments.slice(0, bodyChars).join(""));
1840
1849
  return `${head}${TRUNCATION_SUFFIX}`;
1841
1850
  }
1842
1851
  function clampTextWithMetadata(text, maxChars, noOmit = false) {
1843
- if (countTextChars(text) <= maxChars) {
1852
+ const segments = segmentTextChars(text);
1853
+ if (segments.length <= maxChars) {
1844
1854
  return { text };
1845
1855
  }
1846
1856
  if (noOmit) {
@@ -1850,12 +1860,13 @@ function clampTextWithMetadata(text, maxChars, noOmit = false) {
1850
1860
  };
1851
1861
  }
1852
1862
  return {
1853
- text: clampText(text, maxChars),
1863
+ text: clampSegments(segments, maxChars),
1854
1864
  compaction: createCompactionMetadata("tail-truncation")
1855
1865
  };
1856
1866
  }
1857
1867
  function clampTextMiddleWithMetadata(text, maxChars, noOmit = false) {
1858
- if (countTextChars(text) <= maxChars) {
1868
+ const segments = segmentTextChars(text);
1869
+ if (segments.length <= maxChars) {
1859
1870
  return { text };
1860
1871
  }
1861
1872
  if (noOmit) {
@@ -1868,7 +1879,6 @@ function clampTextMiddleWithMetadata(text, maxChars, noOmit = false) {
1868
1879
  const bodyChars = Math.max(0, maxChars - markerChars);
1869
1880
  const headChars = Math.ceil(bodyChars * 0.7);
1870
1881
  const tailChars = Math.max(0, bodyChars - headChars);
1871
- const segments = graphemes(text);
1872
1882
  const head = trimHeadToLineBoundary(segments.slice(0, headChars).join(""));
1873
1883
  const tail = trimTailToLineBoundary(segments.slice(-tailChars).join(""));
1874
1884
  return {
@@ -2100,9 +2110,10 @@ function shouldRecordStats(env = process.env) {
2100
2110
  const value = env[STATS_ENABLED_ENV]?.trim().toLowerCase();
2101
2111
  return value !== "0" && value !== "false" && value !== "no" && value !== "off";
2102
2112
  }
2103
- async function storeArtifact(input, storeDir) {
2113
+ async function storeArtifact(input, storeDir, statsForRef) {
2104
2114
  const id = `tj_${randomUUID2().slice(0, 12)}`;
2105
2115
  const ref = buildArtifactPaths(id, storeDir);
2116
+ const stats = statsForRef ? statsForRef(ref) : input.stats;
2106
2117
  await mkdir2(resolveArtifactBaseDir(storeDir), { recursive: true, mode: 448 });
2107
2118
  const captureTruncated = extractCaptureTruncatedFlag(input.input);
2108
2119
  const artifact = {
@@ -2112,12 +2123,12 @@ async function storeArtifact(input, storeDir) {
2112
2123
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2113
2124
  source: resolveArtifactSource(input.input),
2114
2125
  classification: input.classification,
2115
- rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
2126
+ rawChars: stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
2116
2127
  ...input.input.toolName ? { toolName: input.input.toolName } : {},
2117
2128
  ...input.input.command ? { command: input.input.command } : {},
2118
2129
  ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
2119
2130
  ...captureTruncated !== void 0 ? { captureTruncated } : {},
2120
- ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
2131
+ ...stats ? { reducedChars: stats.reducedChars, ratio: stats.ratio } : {}
2121
2132
  }
2122
2133
  };
2123
2134
  await Promise.all([
@@ -2637,8 +2648,12 @@ var tsc_default = {
2637
2648
  family: "build-typescript",
2638
2649
  description: "Compact TypeScript compiler output while preserving real diagnostics.",
2639
2650
  match: {
2640
- toolNames: ["exec"],
2641
- commandIncludes: ["tsc"]
2651
+ toolNames: [
2652
+ "exec"
2653
+ ],
2654
+ commandIncludes: [
2655
+ "tsc"
2656
+ ]
2642
2657
  },
2643
2658
  transforms: {
2644
2659
  stripAnsi: true,
@@ -2682,7 +2697,8 @@ var tsc_default = {
2682
2697
  "^.+\\(\\d+,\\d+\\):\\s+error TS\\d+: .+",
2683
2698
  "^.+\\(\\d+,\\d+\\):\\s+warning TS\\d+: .+",
2684
2699
  "^Found \\d+ errors?.+",
2685
- "^error TS\\d+: .+"
2700
+ "^error TS\\d+: .+",
2701
+ "^\\s{2,}\\S"
2686
2702
  ]
2687
2703
  },
2688
2704
  summarize: {
@@ -4417,15 +4433,23 @@ var bun_install_default = {
4417
4433
  description: "Compact bun install output while preserving warnings and package counts.",
4418
4434
  matchOutput: [
4419
4435
  {
4420
- pattern: "Checked \\d+ installs? across \\d+ packages? \\(no changes\\)",
4436
+ pattern: "^(?:bun install v[^\\r\\n]+\\n)?Checked \\d+ installs? across \\d+ packages? \\(no changes\\)$",
4421
4437
  message: "bun install: up to date",
4422
4438
  flags: "i"
4423
4439
  }
4424
4440
  ],
4425
4441
  match: {
4426
- toolNames: ["exec"],
4427
- argv0: ["bun"],
4428
- argvIncludes: [["install"]]
4442
+ toolNames: [
4443
+ "exec"
4444
+ ],
4445
+ argv0: [
4446
+ "bun"
4447
+ ],
4448
+ argvIncludes: [
4449
+ [
4450
+ "install"
4451
+ ]
4452
+ ]
4429
4453
  },
4430
4454
  transforms: {
4431
4455
  stripAnsi: true,
@@ -4463,15 +4487,23 @@ var npm_ci_default = {
4463
4487
  onEmpty: "npm ci: ok",
4464
4488
  matchOutput: [
4465
4489
  {
4466
- pattern: "up to date, audited \\d+ package",
4490
+ pattern: "^up to date, audited \\d+ packages? in [^\\r\\n]+(?:\\n+found 0 vulnerabilities)?$",
4467
4491
  message: "npm ci: up to date",
4468
4492
  flags: "i"
4469
4493
  }
4470
4494
  ],
4471
4495
  match: {
4472
- toolNames: ["exec"],
4473
- argv0: ["npm"],
4474
- argvIncludes: [["ci"]]
4496
+ toolNames: [
4497
+ "exec"
4498
+ ],
4499
+ argv0: [
4500
+ "npm"
4501
+ ],
4502
+ argvIncludes: [
4503
+ [
4504
+ "ci"
4505
+ ]
4506
+ ]
4475
4507
  },
4476
4508
  transforms: {
4477
4509
  stripAnsi: true,
@@ -4514,15 +4546,23 @@ var npm_install_default = {
4514
4546
  onEmpty: "npm install: ok",
4515
4547
  matchOutput: [
4516
4548
  {
4517
- pattern: "up to date, audited \\d+ package",
4549
+ pattern: "^up to date, audited \\d+ packages? in [^\\r\\n]+(?:\\n+found 0 vulnerabilities)?$",
4518
4550
  message: "npm install: up to date",
4519
4551
  flags: "i"
4520
4552
  }
4521
4553
  ],
4522
4554
  match: {
4523
- toolNames: ["exec"],
4524
- argv0: ["npm"],
4525
- argvIncludes: [["install"]]
4555
+ toolNames: [
4556
+ "exec"
4557
+ ],
4558
+ argv0: [
4559
+ "npm"
4560
+ ],
4561
+ argvIncludes: [
4562
+ [
4563
+ "install"
4564
+ ]
4565
+ ]
4526
4566
  },
4527
4567
  transforms: {
4528
4568
  stripAnsi: true,
@@ -4564,15 +4604,23 @@ var pnpm_install_default = {
4564
4604
  description: "Compact pnpm install output while preserving warnings and summary lines.",
4565
4605
  matchOutput: [
4566
4606
  {
4567
- pattern: "Already up to date",
4607
+ pattern: "^(?:Lockfile is up to date, resolution step is skipped\\n)?Already up to date(?:\\nDone in [^\\r\\n]+)?$",
4568
4608
  message: "pnpm install: up to date",
4569
4609
  flags: "i"
4570
4610
  }
4571
4611
  ],
4572
4612
  match: {
4573
- toolNames: ["exec"],
4574
- argv0: ["pnpm"],
4575
- argvIncludes: [["install"]]
4613
+ toolNames: [
4614
+ "exec"
4615
+ ],
4616
+ argv0: [
4617
+ "pnpm"
4618
+ ],
4619
+ argvIncludes: [
4620
+ [
4621
+ "install"
4622
+ ]
4623
+ ]
4576
4624
  },
4577
4625
  transforms: {
4578
4626
  stripAnsi: true,
@@ -4609,14 +4657,22 @@ var yarn_install_default = {
4609
4657
  description: "Compact yarn install output while preserving warnings and summary lines.",
4610
4658
  matchOutput: [
4611
4659
  {
4612
- pattern: "Already up-to-date\\.",
4660
+ pattern: "^(?:\\[\\d+/\\d+\\] Resolving packages\\.\\.\\.\\n)?(?:success )?Already up-to-date\\.(?:\\nDone in [^\\r\\n]+)?$",
4613
4661
  message: "yarn install: up to date"
4614
4662
  }
4615
4663
  ],
4616
4664
  match: {
4617
- toolNames: ["exec"],
4618
- argv0: ["yarn"],
4619
- argvIncludes: [["install"]]
4665
+ toolNames: [
4666
+ "exec"
4667
+ ],
4668
+ argv0: [
4669
+ "yarn"
4670
+ ],
4671
+ argvIncludes: [
4672
+ [
4673
+ "install"
4674
+ ]
4675
+ ]
4620
4676
  },
4621
4677
  transforms: {
4622
4678
  stripAnsi: true,
@@ -6874,8 +6930,12 @@ var pytest_default = {
6874
6930
  description: "Compact pytest output while preserving failures and final summary.",
6875
6931
  counterSource: "preKeep",
6876
6932
  match: {
6877
- toolNames: ["exec"],
6878
- commandIncludes: ["pytest"]
6933
+ toolNames: [
6934
+ "exec"
6935
+ ],
6936
+ commandIncludes: [
6937
+ "pytest"
6938
+ ]
6879
6939
  },
6880
6940
  transforms: {
6881
6941
  stripAnsi: true,
@@ -6897,7 +6957,8 @@ var pytest_default = {
6897
6957
  "^E\\s+.+",
6898
6958
  "AssertionError",
6899
6959
  "^.+::.+ (FAILED|ERROR)$",
6900
- "^>\\s+.+"
6960
+ "^>\\s+.+",
6961
+ "^\\S.*\\.py:\\d+:\\s+\\S"
6901
6962
  ]
6902
6963
  },
6903
6964
  summarize: {
@@ -8022,6 +8083,74 @@ function classifyExecution(input, rules, forcedRuleId) {
8022
8083
  return resolved.classification;
8023
8084
  }
8024
8085
 
8086
+ // src/core/failure-summary.ts
8087
+ var FAILURE_LINE = /(?:^|\s)(?:fatal(?:\s+error)?|error|panic|exception|caused by|traceback)(?:[:\s]|$)|\b[A-Z][A-Za-z]*(?:Error|Exception):/iu;
8088
+ function buildFailureSummary(input, rawText, maxChars, noOmit = false) {
8089
+ if (noOmit || typeof input.exitCode !== "number" || input.exitCode === 0) return null;
8090
+ const text = stripAnsi(rawText);
8091
+ const lines = normalizeLines(text);
8092
+ if (lines.length <= 32) return null;
8093
+ const signals = lines.flatMap((line, index) => FAILURE_LINE.test(line) ? [index] : []);
8094
+ if (signals.length === 0) return null;
8095
+ const fullText = `[exit ${input.exitCode}]
8096
+ ${text}`;
8097
+ if (countTextChars(fullText) <= maxChars) return { text: fullText, compaction: NO_COMPACTION_METADATA };
8098
+ const header = `[exit ${input.exitCode}] selected failure details (original line numbers):
8099
+ `;
8100
+ const footer = "\n[other output omitted]";
8101
+ let remaining = maxChars - countTextChars(header + footer);
8102
+ if (remaining < 32) return null;
8103
+ const diagnosticRows = signals.map((index) => {
8104
+ const row = `${index + 1}: ${lines[index]}`;
8105
+ const cost = countTextChars(row) + 1;
8106
+ return { index, row, cost, minimum: Math.min(cost, 64) };
8107
+ });
8108
+ let candidates = diagnosticRows;
8109
+ if (diagnosticRows.reduce((sum, row) => sum + row.minimum, 0) > remaining) {
8110
+ candidates = [];
8111
+ let reserved2 = 0;
8112
+ for (let offset = 0; offset < diagnosticRows.length; offset++) {
8113
+ const index = offset % 2 === 0 ? offset / 2 : diagnosticRows.length - 1 - Math.floor(offset / 2);
8114
+ const row = diagnosticRows[index];
8115
+ if (reserved2 + row.minimum <= remaining) {
8116
+ candidates.push(row);
8117
+ reserved2 += row.minimum;
8118
+ }
8119
+ }
8120
+ candidates.sort((left, right) => left.index - right.index);
8121
+ }
8122
+ const selected = /* @__PURE__ */ new Map();
8123
+ let reserved = candidates.reduce((sum, row) => sum + row.minimum, 0);
8124
+ for (const { index, row, cost, minimum } of candidates) {
8125
+ reserved -= minimum;
8126
+ const allowance = remaining - reserved;
8127
+ if (cost <= allowance) {
8128
+ selected.set(index, row);
8129
+ remaining -= cost;
8130
+ } else {
8131
+ const clipped = clampTextWithMetadata(row, allowance - 1).text;
8132
+ selected.set(index, clipped);
8133
+ remaining -= countTextChars(clipped) + 1;
8134
+ }
8135
+ }
8136
+ for (const index of signals) {
8137
+ if (!selected.has(index)) continue;
8138
+ for (const neighbor of [index - 1, index + 1]) {
8139
+ if (neighbor < 0 || neighbor >= lines.length || selected.has(neighbor)) continue;
8140
+ const row = `${neighbor + 1}: ${lines[neighbor]}`;
8141
+ const cost = countTextChars(row) + 1;
8142
+ if (cost <= remaining) {
8143
+ selected.set(neighbor, row);
8144
+ remaining -= cost;
8145
+ }
8146
+ }
8147
+ }
8148
+ return {
8149
+ text: header + [...selected].sort(([left], [right]) => left - right).map(([, row]) => row).join("\n") + footer,
8150
+ compaction: createCompactionMetadata("failure-signal-filter")
8151
+ };
8152
+ }
8153
+
8025
8154
  // src/core/github-actions-summary.ts
8026
8155
  var GITHUB_ACTIONS_EXIT_PATTERN = /^Error: Process completed with exit code (\d+)\.?$/u;
8027
8156
  var GITHUB_ACTIONS_RUN_PATTERN = /^(?:##\[group\]|::group::)?Run\s+(.+)$/u;
@@ -8126,7 +8255,8 @@ function shortHash(text) {
8126
8255
  return createHash2("sha256").update(text).digest("hex").slice(0, 12);
8127
8256
  }
8128
8257
  function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
8129
- if (countTextChars(text) <= maxChars) {
8258
+ const segments = segmentTextChars(text);
8259
+ if (segments.length <= maxChars) {
8130
8260
  return { text };
8131
8261
  }
8132
8262
  if (noOmit) {
@@ -8135,7 +8265,7 @@ function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
8135
8265
  compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough")
8136
8266
  };
8137
8267
  }
8138
- const omitted = countTextChars(text) - maxChars;
8268
+ const omitted = segments.length - maxChars;
8139
8269
  const marker = `...[${omitted} chars omitted, sha256:${shortHash(text)}]...`;
8140
8270
  const markerChars = countTextChars(marker);
8141
8271
  if (maxChars <= markerChars) {
@@ -8148,7 +8278,7 @@ function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
8148
8278
  const headChars = Math.ceil(bodyChars * 0.7);
8149
8279
  const tailChars = Math.max(0, bodyChars - headChars);
8150
8280
  return {
8151
- text: `${sliceTextChars(text, 0, headChars)}${marker}${tailChars > 0 ? sliceTextChars(text, -tailChars) : ""}`,
8281
+ text: `${segments.slice(0, headChars).join("")}${marker}${tailChars > 0 ? segments.slice(-tailChars).join("") : ""}`,
8152
8282
  compaction: createCompactionMetadata("hashed-middle-clip")
8153
8283
  };
8154
8284
  }
@@ -8182,7 +8312,8 @@ function minifyJsonLexically(rawText) {
8182
8312
  return output;
8183
8313
  }
8184
8314
  function clipMiddleWithHash(text, maxChars, noOmit = false) {
8185
- if (countTextChars(text) <= maxChars) {
8315
+ const segments = segmentTextChars(text);
8316
+ if (segments.length <= maxChars) {
8186
8317
  return { text };
8187
8318
  }
8188
8319
  if (noOmit) {
@@ -8191,11 +8322,11 @@ function clipMiddleWithHash(text, maxChars, noOmit = false) {
8191
8322
  compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough")
8192
8323
  };
8193
8324
  }
8194
- const omitted = countTextChars(text) - maxChars;
8325
+ const omitted = segments.length - maxChars;
8195
8326
  const headChars = Math.max(20, Math.floor(maxChars * 0.55));
8196
8327
  const tailChars = Math.max(20, maxChars - headChars);
8197
8328
  return {
8198
- text: `${sliceTextChars(text, 0, headChars)} ...[${omitted} chars omitted, sha256:${shortHash(text)}]... ${sliceTextChars(text, -tailChars)}`,
8329
+ text: `${segments.slice(0, headChars).join("")} ...[${omitted} chars omitted, sha256:${shortHash(text)}]... ${segments.slice(-tailChars).join("")}`,
8199
8330
  compaction: createCompactionMetadata("hashed-middle-clip")
8200
8331
  };
8201
8332
  }
@@ -8866,7 +8997,7 @@ function prettyPrintJsonIfPossible(text) {
8866
8997
  }
8867
8998
  return text;
8868
8999
  }
8869
- function applyRule(compiledRule, input, rawText, noOmit = false) {
9000
+ function applyRule(compiledRule, input, rawText, noOmit = false, maxInlineChars = 1200) {
8870
9001
  const rule = compiledRule.rule;
8871
9002
  if (rule.transforms?.prettyPrintJson) {
8872
9003
  rawText = prettyPrintJsonIfPossible(rawText);
@@ -8884,13 +9015,14 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8884
9015
  }
8885
9016
  const outputMatchText = trimEmptyEdges(lines).join("\n");
8886
9017
  const matchedOutput = compiledRule.compiled.outputMatches.find((entry) => entry.pattern.test(outputMatchText));
8887
- if (!noOmit && matchedOutput) {
9018
+ if (!noOmit && input.exitCode === 0 && matchedOutput) {
8888
9019
  return {
8889
9020
  summary: matchedOutput.message,
8890
9021
  facts,
8891
- compaction: NO_COMPACTION_METADATA
9022
+ compaction: matchedOutput.message === outputMatchText ? NO_COMPACTION_METADATA : createCompactionMetadata("rule-output-replacement")
8892
9023
  };
8893
9024
  }
9025
+ const unfilteredLineCount = lines.length;
8894
9026
  if (!noOmit && rule.filters?.skipPatterns?.length) {
8895
9027
  lines = lines.filter((line) => !compiledRule.compiled.skipPatterns.some((pattern) => pattern.test(line)));
8896
9028
  }
@@ -8901,6 +9033,9 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8901
9033
  lines = kept;
8902
9034
  }
8903
9035
  }
9036
+ if (lines.length < unfilteredLineCount) {
9037
+ rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, createCompactionMetadata("rule-line-filter"));
9038
+ }
8904
9039
  if (rule.transforms?.trimEmptyEdges) {
8905
9040
  counterLines = trimEmptyEdges(counterLines);
8906
9041
  lines = trimEmptyEdges(lines);
@@ -8920,11 +9055,6 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8920
9055
  lines = rewritten.lines;
8921
9056
  rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, rewritten.compaction);
8922
9057
  }
8923
- if (rule.id === "search/rg") {
8924
- const rewritten = rewriteSearchLines(lines, noOmit);
8925
- lines = rewritten.lines;
8926
- rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, rewritten.compaction);
8927
- }
8928
9058
  if (rule.id === "git/diff") {
8929
9059
  const rewritten = rewriteGitDiffLines(lines, noOmit);
8930
9060
  lines = rewritten.lines;
@@ -8938,6 +9068,18 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8938
9068
  }
8939
9069
  facts[counter.name] = factLines.filter((line) => pattern.test(line)).length;
8940
9070
  }
9071
+ const searchFits = rule.family === "search" && countTextChars(formatInline(
9072
+ { family: rule.family, matchedReducer: rule.id },
9073
+ input,
9074
+ lines.join("\n"),
9075
+ facts,
9076
+ noOmit
9077
+ )) <= maxInlineChars;
9078
+ if (rule.id === "search/rg" && !searchFits) {
9079
+ const rewritten = rewriteSearchLines(lines, noOmit);
9080
+ lines = rewritten.lines;
9081
+ rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, rewritten.compaction);
9082
+ }
8941
9083
  if (lines.length === 0 && rule.onEmpty) {
8942
9084
  return {
8943
9085
  summary: rule.onEmpty,
@@ -8952,7 +9094,7 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8952
9094
  head: rule.summarize?.head ?? 6,
8953
9095
  tail: rule.summarize?.tail ?? 6
8954
9096
  };
8955
- const compacted = headTail(lines, summarize.head, summarize.tail, noOmit);
9097
+ const compacted = searchFits ? { lines, compaction: NO_COMPACTION_METADATA } : headTail(lines, summarize.head, summarize.tail, noOmit);
8956
9098
  return {
8957
9099
  summary: compacted.lines.join("\n").trim(),
8958
9100
  facts,
@@ -9022,9 +9164,8 @@ function formatInline(classification, input, summary, facts, noOmit = false) {
9022
9164
  lines.push(summary);
9023
9165
  return lines.join("\n").trim();
9024
9166
  }
9025
- function selectInlineText(classification, input, rawText, compactText, maxInlineChars, compactCompaction, noOmit = false) {
9167
+ function selectInlineText(classification, input, rawText, rawChars, compactText, maxInlineChars, compactCompaction, noOmit = false) {
9026
9168
  const passthroughText = buildPassthroughText(input, rawText);
9027
- const rawChars = countTextChars(stripAnsi(rawText));
9028
9169
  const compactChars = countTextChars(compactText);
9029
9170
  if (noOmit) {
9030
9171
  return {
@@ -9051,13 +9192,14 @@ function selectInlineText(classification, input, rawText, compactText, maxInline
9051
9192
  };
9052
9193
  }
9053
9194
  const passthroughLimit = classification.family === "help" ? maxInlineChars : TINY_OUTPUT_MAX_CHARS;
9054
- if (countTextChars(passthroughText) > passthroughLimit) {
9195
+ const passthroughChars = countTextChars(passthroughText);
9196
+ if (passthroughChars > passthroughLimit) {
9055
9197
  return {
9056
9198
  text: compactText,
9057
9199
  compaction: compactCompaction
9058
9200
  };
9059
9201
  }
9060
- if (countTextChars(passthroughText) <= countTextChars(compactText)) {
9202
+ if (passthroughChars <= compactChars) {
9061
9203
  return {
9062
9204
  text: passthroughText,
9063
9205
  compaction: NO_COMPACTION_METADATA
@@ -9220,9 +9362,9 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
9220
9362
  if (!matchedRule) {
9221
9363
  throw new Error("missing generic fallback rule");
9222
9364
  }
9223
- const githubActionsFailureSummary = classification.matchedReducer === "generic/fallback" ? buildGithubActionsFailureSummary(reducerInput, rawText, opts.noOmit) : null;
9224
- if (githubActionsFailureSummary) {
9225
- const inlineText2 = clampTextMiddleWithMetadata(githubActionsFailureSummary.text, maxInlineChars, opts.noOmit);
9365
+ const failureSummary = classification.matchedReducer === "generic/fallback" ? buildGithubActionsFailureSummary(reducerInput, rawText, opts.noOmit) ?? buildFailureSummary(reducerInput, rawText, maxInlineChars, opts.noOmit) : null;
9366
+ if (failureSummary) {
9367
+ const inlineText2 = clampTextMiddleWithMetadata(failureSummary.text, maxInlineChars, opts.noOmit);
9226
9368
  const reducedChars2 = countTextChars(inlineText2.text);
9227
9369
  const stats2 = {
9228
9370
  rawChars: measuredRawChars,
@@ -9252,8 +9394,8 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
9252
9394
  }
9253
9395
  return {
9254
9396
  inlineText: inlineText2.text,
9255
- previewText: githubActionsFailureSummary.text,
9256
- compaction: mergeCompactionMetadata(githubActionsFailureSummary.compaction, inlineText2.compaction),
9397
+ previewText: failureSummary.text,
9398
+ compaction: mergeCompactionMetadata(failureSummary.compaction, inlineText2.compaction),
9257
9399
  ...trace ? { trace } : {},
9258
9400
  ...rawRef2 ? { rawRef: rawRef2 } : {},
9259
9401
  stats: stats2,
@@ -9307,7 +9449,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
9307
9449
  };
9308
9450
  }
9309
9451
  }
9310
- const { summary, facts, compaction } = applyRule(matchedRule, reducerInput, rawText, opts.noOmit);
9452
+ const { summary, facts, compaction } = applyRule(matchedRule, reducerInput, rawText, opts.noOmit, maxInlineChars);
9311
9453
  const compactText = formatInline(
9312
9454
  classification,
9313
9455
  reducerInput,
@@ -9315,7 +9457,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
9315
9457
  facts,
9316
9458
  opts.noOmit
9317
9459
  );
9318
- const selectedText = selectInlineText(classification, reducerInput, rawText, compactText, maxInlineChars, compaction, opts.noOmit);
9460
+ const selectedText = selectInlineText(classification, reducerInput, rawText, measuredRawChars, compactText, maxInlineChars, compaction, opts.noOmit);
9319
9461
  const clamp = classification.family === "help" || selectedText.text.includes("\n") ? clampTextMiddleWithMetadata : clampTextWithMetadata;
9320
9462
  const inlineText = clamp(selectedText.text, maxInlineChars, opts.noOmit);
9321
9463
  const reducedChars = countTextChars(inlineText.text);