@openclaw/tokenjuice 2026.9.4 → 2026.9.6

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 (41) hide show
  1. package/assets/activity.svg +3 -0
  2. package/assets/icon.png +0 -0
  3. package/node_modules/tokenjuice/README.md +10 -1
  4. package/node_modules/tokenjuice/dist/cli/install-output.d.ts +7 -0
  5. package/node_modules/tokenjuice/dist/cli/install-output.js +19 -0
  6. package/node_modules/tokenjuice/dist/cli/main.d.ts +7 -0
  7. package/node_modules/tokenjuice/dist/cli/main.js +201 -36
  8. package/node_modules/tokenjuice/dist/core/analysis.js +3 -3
  9. package/node_modules/tokenjuice/dist/core/artifacts.d.ts +6 -1
  10. package/node_modules/tokenjuice/dist/core/artifacts.js +122 -45
  11. package/node_modules/tokenjuice/dist/core/bounded-jsonl.d.ts +26 -0
  12. package/node_modules/tokenjuice/dist/core/bounded-jsonl.js +407 -0
  13. package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +1 -1
  14. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +2 -0
  15. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +3 -2
  16. package/node_modules/tokenjuice/dist/core/reduce.js +23 -10
  17. package/node_modules/tokenjuice/dist/core/text.d.ts +4 -0
  18. package/node_modules/tokenjuice/dist/core/text.js +32 -0
  19. package/node_modules/tokenjuice/dist/core/wrap.js +1 -1
  20. package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +31 -1
  21. package/node_modules/tokenjuice/dist/hosts/codex/index.js +554 -288
  22. package/node_modules/tokenjuice/dist/hosts/droid/index.js +12 -3
  23. package/node_modules/tokenjuice/dist/hosts/grok-bot/index.d.ts +25 -0
  24. package/node_modules/tokenjuice/dist/hosts/grok-bot/index.js +644 -0
  25. package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +644 -279
  26. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +647 -282
  27. package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.d.ts +24 -0
  28. package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.js +80 -1
  29. package/node_modules/tokenjuice/dist/hosts/shared/hook-command.d.ts +19 -0
  30. package/node_modules/tokenjuice/dist/hosts/shared/hook-command.js +61 -6
  31. package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.d.ts +3 -1
  32. package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.js +2 -0
  33. package/node_modules/tokenjuice/dist/hosts/shared/host-command.d.ts +10 -1
  34. package/node_modules/tokenjuice/dist/hosts/shared/host-command.js +43 -4
  35. package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.js +9 -7
  36. package/node_modules/tokenjuice/dist/index.d.ts +3 -1
  37. package/node_modules/tokenjuice/dist/index.js +2 -1
  38. package/node_modules/tokenjuice/dist/types.d.ts +15 -0
  39. package/node_modules/tokenjuice/package.json +1 -1
  40. package/openclaw.plugin.json +1 -1
  41. package/package.json +8 -6
@@ -1,5 +1,5 @@
1
1
  // src/hosts/pi/extension/runtime.ts
2
- import { readFile as readFile3, stat } from "node:fs/promises";
2
+ import { readFile as readFile4, stat as stat2 } from "node:fs/promises";
3
3
 
4
4
  // src/core/command-identity.ts
5
5
  import { basename } from "node:path";
@@ -1283,6 +1283,315 @@ function readNoOmissionFromEnv(env = process.env) {
1283
1283
  return NO_OMISSION_TRUTHY_VALUES.has(env[NO_OMISSION_ENV] ?? "");
1284
1284
  }
1285
1285
 
1286
+ // src/core/artifacts.ts
1287
+ import { mkdir as mkdir2, readFile as readFile2, readdir, writeFile as writeFile2 } from "node:fs/promises";
1288
+ import { randomUUID as randomUUID2 } from "node:crypto";
1289
+ import { homedir } from "node:os";
1290
+ import { join as join2 } from "node:path";
1291
+
1292
+ // src/core/bounded-jsonl.ts
1293
+ import { appendFile, lstat, mkdir, open, opendir, readFile, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
1294
+ import { createHash, randomUUID } from "node:crypto";
1295
+ import { join } from "node:path";
1296
+ var DAY_MS = 24 * 60 * 60 * 1e3;
1297
+ var LOCK_RETRIES = 8;
1298
+ var LOCK_RETRY_MS = 10;
1299
+ var MAX_RETENTION_DAYS = 365;
1300
+ var MAX_SHARD_COUNT = 100;
1301
+ var MAX_STORE_FILES = 1e4;
1302
+ var MAX_SEGMENT_BYTES = 64 * 1024 * 1024;
1303
+ var DIRECTORY_ENTRY_SLACK = 256;
1304
+ var DEFAULT_RETENTION_DAYS = 14;
1305
+ var DEFAULT_SHARD_COUNT = 8;
1306
+ var DEFAULT_MAX_SEGMENT_BYTES = 1024 * 1024;
1307
+ function wait(ms) {
1308
+ return new Promise((resolvePromise) => {
1309
+ setTimeout(resolvePromise, ms);
1310
+ });
1311
+ }
1312
+ function positiveInteger(value, fallback, name, maximum) {
1313
+ const resolved = value ?? fallback;
1314
+ if (!Number.isSafeInteger(resolved) || resolved <= 0 || resolved > maximum) {
1315
+ throw new RangeError(`${name} must be a positive integer no greater than ${maximum}`);
1316
+ }
1317
+ return resolved;
1318
+ }
1319
+ function resolveStoreOptions(options) {
1320
+ const retentionDays = positiveInteger(
1321
+ options.retentionDays,
1322
+ DEFAULT_RETENTION_DAYS,
1323
+ "retentionDays",
1324
+ MAX_RETENTION_DAYS
1325
+ );
1326
+ const shardCount = positiveInteger(
1327
+ options.shardCount,
1328
+ DEFAULT_SHARD_COUNT,
1329
+ "shardCount",
1330
+ MAX_SHARD_COUNT
1331
+ );
1332
+ if (retentionDays * shardCount > MAX_STORE_FILES) {
1333
+ throw new RangeError(`retentionDays * shardCount must not exceed ${MAX_STORE_FILES}`);
1334
+ }
1335
+ return {
1336
+ retentionDays,
1337
+ shardCount,
1338
+ maxSegmentBytes: positiveInteger(
1339
+ options.maxSegmentBytes,
1340
+ DEFAULT_MAX_SEGMENT_BYTES,
1341
+ "maxSegmentBytes",
1342
+ MAX_SEGMENT_BYTES
1343
+ )
1344
+ };
1345
+ }
1346
+ function formatDay(date) {
1347
+ return date.toISOString().slice(0, 10);
1348
+ }
1349
+ function shardFor(id, shardCount) {
1350
+ const digest = createHash("sha256").update(id).digest();
1351
+ return digest[0] % shardCount;
1352
+ }
1353
+ function segmentName(prefix, day, shard) {
1354
+ return `${prefix}-${day}-${String(shard).padStart(2, "0")}.jsonl`;
1355
+ }
1356
+ function parseSegmentDay(name, prefix) {
1357
+ const escapedPrefix = prefix.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
1358
+ return new RegExp(`^${escapedPrefix}-(\\d{4}-\\d{2}-\\d{2})-\\d{2}\\.jsonl$`, "u").exec(name)?.[1];
1359
+ }
1360
+ async function tryCreateLock(lockPath) {
1361
+ try {
1362
+ await mkdir(lockPath, { mode: 448 });
1363
+ } catch (error) {
1364
+ if (error.code === "EEXIST") {
1365
+ return void 0;
1366
+ }
1367
+ throw error;
1368
+ }
1369
+ const owner = `${process.pid}:${randomUUID()}`;
1370
+ try {
1371
+ await writeFile(join(lockPath, "owner"), owner, { encoding: "utf8", flag: "wx", mode: 384 });
1372
+ return owner;
1373
+ } catch {
1374
+ return void 0;
1375
+ }
1376
+ }
1377
+ async function releaseLock(lockPath, owner) {
1378
+ try {
1379
+ const ownerPath = join(lockPath, "owner");
1380
+ if (await readFile(ownerPath, "utf8") === owner) {
1381
+ await unlink(ownerPath);
1382
+ await rmdir(lockPath);
1383
+ }
1384
+ } catch {
1385
+ }
1386
+ }
1387
+ async function acquireLock(lockPath) {
1388
+ for (let attempt = 0; attempt <= LOCK_RETRIES; attempt += 1) {
1389
+ const owner = await tryCreateLock(lockPath);
1390
+ if (owner) {
1391
+ return owner;
1392
+ }
1393
+ if (attempt < LOCK_RETRIES) {
1394
+ await wait(LOCK_RETRY_MS);
1395
+ }
1396
+ }
1397
+ return void 0;
1398
+ }
1399
+ async function pruneExpiredSegments(directory, prefix, retentionDays, maxFiles, now) {
1400
+ const oldestDay = formatDay(new Date(now.getTime() - (retentionDays - 1) * DAY_MS));
1401
+ const directoryHandle = await opendir(directory);
1402
+ let inspected = 0;
1403
+ try {
1404
+ for await (const entry of directoryHandle) {
1405
+ inspected += 1;
1406
+ if (inspected > maxFiles * 2 + DIRECTORY_ENTRY_SLACK) {
1407
+ break;
1408
+ }
1409
+ if (!entry.isFile()) {
1410
+ continue;
1411
+ }
1412
+ const day = parseSegmentDay(entry.name, prefix);
1413
+ if (day && day < oldestDay) {
1414
+ const path = join(directory, entry.name);
1415
+ const lockPath = `${path}.lock`;
1416
+ const owner = await tryCreateLock(lockPath);
1417
+ if (!owner) {
1418
+ continue;
1419
+ }
1420
+ try {
1421
+ await rm(path, { force: true });
1422
+ } finally {
1423
+ await releaseLock(lockPath, owner);
1424
+ }
1425
+ }
1426
+ }
1427
+ } finally {
1428
+ await directoryHandle.close().catch(() => {
1429
+ });
1430
+ }
1431
+ }
1432
+ async function countOwnedSegments(directory, prefix, maxFiles) {
1433
+ const directoryHandle = await opendir(directory);
1434
+ let count = 0;
1435
+ let inspected = 0;
1436
+ try {
1437
+ for await (const entry of directoryHandle) {
1438
+ inspected += 1;
1439
+ if (inspected > maxFiles * 2 + DIRECTORY_ENTRY_SLACK) {
1440
+ return { count, complete: false };
1441
+ }
1442
+ if (entry.isFile() && parseSegmentDay(entry.name, prefix)) {
1443
+ count += 1;
1444
+ if (count >= maxFiles) {
1445
+ return { count, complete: true };
1446
+ }
1447
+ }
1448
+ }
1449
+ } finally {
1450
+ await directoryHandle.close().catch(() => {
1451
+ });
1452
+ }
1453
+ return { count, complete: true };
1454
+ }
1455
+ async function appendBoundedJsonl(directory, prefix, id, value, options = {}) {
1456
+ const { retentionDays, shardCount, maxSegmentBytes } = resolveStoreOptions(options);
1457
+ const now = options.now ?? /* @__PURE__ */ new Date();
1458
+ if (!Number.isFinite(now.getTime())) {
1459
+ throw new RangeError("now must be a valid Date");
1460
+ }
1461
+ const line2 = `${JSON.stringify(value)}
1462
+ `;
1463
+ const lineBytes = Buffer.byteLength(line2, "utf8");
1464
+ if (lineBytes > maxSegmentBytes) {
1465
+ return void 0;
1466
+ }
1467
+ await mkdir(directory, { recursive: true, mode: 448 });
1468
+ const maxFiles = retentionDays * shardCount;
1469
+ const path = join(directory, segmentName(prefix, formatDay(now), shardFor(id, shardCount)));
1470
+ const lockPath = `${path}.lock`;
1471
+ const admissionLockPath = join(directory, `.${prefix}.admission.lock`);
1472
+ const admissionOwner = await acquireLock(admissionLockPath);
1473
+ if (!admissionOwner) {
1474
+ return void 0;
1475
+ }
1476
+ let owner;
1477
+ try {
1478
+ await pruneExpiredSegments(directory, prefix, retentionDays, maxFiles, now);
1479
+ let targetExists = false;
1480
+ try {
1481
+ targetExists = (await lstat(path)).isFile();
1482
+ if (!targetExists) {
1483
+ return void 0;
1484
+ }
1485
+ } catch (error) {
1486
+ if (error.code !== "ENOENT") {
1487
+ throw error;
1488
+ }
1489
+ }
1490
+ if (!targetExists) {
1491
+ const segmentCount = await countOwnedSegments(directory, prefix, maxFiles);
1492
+ if (!segmentCount.complete || segmentCount.count >= maxFiles) {
1493
+ return void 0;
1494
+ }
1495
+ }
1496
+ owner = await acquireLock(lockPath);
1497
+ if (!owner) {
1498
+ return void 0;
1499
+ }
1500
+ if (!targetExists) {
1501
+ try {
1502
+ const file = await open(path, "wx", 384);
1503
+ await file.close();
1504
+ } catch (error) {
1505
+ await releaseLock(lockPath, owner);
1506
+ owner = void 0;
1507
+ if (error.code === "EEXIST") {
1508
+ return void 0;
1509
+ }
1510
+ throw error;
1511
+ }
1512
+ }
1513
+ } catch (error) {
1514
+ if (owner) {
1515
+ await releaseLock(lockPath, owner);
1516
+ owner = void 0;
1517
+ }
1518
+ throw error;
1519
+ } finally {
1520
+ await releaseLock(admissionLockPath, admissionOwner);
1521
+ }
1522
+ if (!owner) {
1523
+ return void 0;
1524
+ }
1525
+ try {
1526
+ let currentBytes = 0;
1527
+ try {
1528
+ currentBytes = (await stat(path)).size;
1529
+ } catch (error) {
1530
+ if (error.code !== "ENOENT") {
1531
+ throw error;
1532
+ }
1533
+ }
1534
+ if (currentBytes + lineBytes > maxSegmentBytes) {
1535
+ return void 0;
1536
+ }
1537
+ await appendFile(path, line2, { encoding: "utf8", mode: 384 });
1538
+ return path;
1539
+ } finally {
1540
+ await releaseLock(lockPath, owner);
1541
+ }
1542
+ }
1543
+
1544
+ // src/core/execution-input.ts
1545
+ function normalizeExecutionInput(input) {
1546
+ const shellWrapped = unwrapShellRunner(input);
1547
+ if (shellWrapped) {
1548
+ const effectiveCommand2 = stripLeadingCdPrefix(shellWrapped);
1549
+ if (isCompoundShellCommand(effectiveCommand2)) {
1550
+ const { argv: _argv, ...restInput } = input;
1551
+ return {
1552
+ ...restInput,
1553
+ command: effectiveCommand2
1554
+ };
1555
+ }
1556
+ const argv2 = resolveEffectiveCommand({ command: effectiveCommand2 })?.argv ?? tokenizeCommand(effectiveCommand2);
1557
+ if (argv2.length === 0) {
1558
+ return {
1559
+ ...input,
1560
+ command: effectiveCommand2
1561
+ };
1562
+ }
1563
+ return {
1564
+ ...input,
1565
+ command: argv2.join(" "),
1566
+ argv: argv2
1567
+ };
1568
+ }
1569
+ const effective = resolveEffectiveCommand(input);
1570
+ if (effective?.argv.length) {
1571
+ return {
1572
+ ...input,
1573
+ ...effective.command ? { command: effective.command } : {},
1574
+ argv: effective.argv
1575
+ };
1576
+ }
1577
+ if (input.argv?.length || !input.command) {
1578
+ return input;
1579
+ }
1580
+ const effectiveCommand = stripLeadingCdPrefix(input.command);
1581
+ if (isCompoundShellCommand(effectiveCommand)) {
1582
+ return input;
1583
+ }
1584
+ const argv = tokenizeCommand(effectiveCommand);
1585
+ if (argv.length === 0) {
1586
+ return input;
1587
+ }
1588
+ return {
1589
+ ...input,
1590
+ command: argv.join(" "),
1591
+ argv
1592
+ };
1593
+ }
1594
+
1286
1595
  // src/core/compaction-metadata.ts
1287
1596
  var NO_COMPACTION_METADATA = {
1288
1597
  authoritative: false,
@@ -1312,9 +1621,6 @@ function mergeCompactionMetadata(...values) {
1312
1621
  return buildCompactionMetadata(presentValues.every((value) => value.authoritative), ...kinds);
1313
1622
  }
1314
1623
 
1315
- // src/core/reduce-utils.ts
1316
- import { createHash } from "node:crypto";
1317
-
1318
1624
  // src/core/text.ts
1319
1625
  var ANSI_CSI_PATTERN = new RegExp(String.raw`\u001B\[[0-?]*[ -/]*[@-~]`, "g");
1320
1626
  var ANSI_OSC_PATTERN = new RegExp(String.raw`\u001B\][^\u0007\u001B]*(?:\u0007|\u001B\\)`, "g");
@@ -1325,6 +1631,9 @@ var TRUNCATION_SUFFIX = "\n... truncated ...";
1325
1631
  var MIDDLE_TRUNCATION_MARKER = "\n... omitted ...\n";
1326
1632
  var COMBINING_MARK_PATTERN = new RegExp("\\p{Mark}", "u");
1327
1633
  var EMOJI_PATTERN = new RegExp("\\p{Extended_Pictographic}", "u");
1634
+ var FLAG_EMOJI_PATTERN = new RegExp("^\\p{Regional_Indicator}{2}$", "u");
1635
+ var KEYCAP_EMOJI_PATTERN = /^[#*0-9]\uFE0F?\u20E3$/u;
1636
+ var REPEATED_EMOJI_BANNER_MIN_REPETITIONS = 24;
1328
1637
  var graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : null;
1329
1638
  function graphemes(text) {
1330
1639
  if (!graphemeSegmenter) {
@@ -1378,6 +1687,28 @@ function dedupeAdjacent(lines) {
1378
1687
  }
1379
1688
  return next;
1380
1689
  }
1690
+ function formatCodePoints(text) {
1691
+ return Array.from(text, (character) => `U+${character.codePointAt(0)?.toString(16).toUpperCase().padStart(4, "0")}`).join("+");
1692
+ }
1693
+ function isEmojiGrapheme(text) {
1694
+ return EMOJI_PATTERN.test(text) || FLAG_EMOJI_PATTERN.test(text) || KEYCAP_EMOJI_PATTERN.test(text);
1695
+ }
1696
+ function collapseRepeatedEmojiBanner(lines) {
1697
+ let collapsed = false;
1698
+ const nextLines = lines.map((line2) => {
1699
+ const visibleSegments = graphemes(line2).filter((segment) => !/^\s+$/u.test(segment));
1700
+ const repeatedEmoji = visibleSegments[0];
1701
+ if (visibleSegments.length < REPEATED_EMOJI_BANNER_MIN_REPETITIONS || !repeatedEmoji || !isEmojiGrapheme(repeatedEmoji) || visibleSegments.some((segment) => segment !== repeatedEmoji)) {
1702
+ return line2;
1703
+ }
1704
+ collapsed = true;
1705
+ return `[repeated emoji banner omitted: ${formatCodePoints(repeatedEmoji)} x${visibleSegments.length}]`;
1706
+ });
1707
+ return collapsed ? {
1708
+ lines: nextLines,
1709
+ compaction: createCompactionMetadata("repeated-emoji-banner-omission")
1710
+ } : { lines: nextLines };
1711
+ }
1381
1712
  function headTail(lines, head, tail, noOmit = false) {
1382
1713
  const safeHead = Math.max(0, head);
1383
1714
  const safeTail = Math.max(0, tail);
@@ -1460,15 +1791,280 @@ function pluralize(count, noun) {
1460
1791
  if (/[^aeiou]y$/u.test(noun)) {
1461
1792
  return `${count} ${noun.slice(0, -1)}ies`;
1462
1793
  }
1463
- return `${count} ${noun}s`;
1794
+ return `${count} ${noun}s`;
1795
+ }
1796
+
1797
+ // src/core/source.ts
1798
+ var DEFAULT_CLI_ARTIFACT_SOURCE = "cli";
1799
+ function normalizeArtifactSource(value) {
1800
+ if (typeof value !== "string") {
1801
+ return null;
1802
+ }
1803
+ const source = value.trim().toLowerCase().replace(/[_\s]+/gu, "-").replace(/[^a-z0-9.-]+/gu, "-").replace(/^-+|-+$/gu, "");
1804
+ if (!source) {
1805
+ return null;
1806
+ }
1807
+ if (source.startsWith("amazon-q") || source.startsWith("amazonq") || source.startsWith("aws-q")) {
1808
+ return "amazon-q";
1809
+ }
1810
+ if (source.startsWith("claude-code") || source === "claude") {
1811
+ return "claude-code";
1812
+ }
1813
+ if (source.startsWith("cline")) {
1814
+ return "cline";
1815
+ }
1816
+ if (source.startsWith("codex")) {
1817
+ return "codex";
1818
+ }
1819
+ if (source.startsWith("command-code") || source.startsWith("commandcode")) {
1820
+ return "command-code";
1821
+ }
1822
+ if (source.startsWith("copilot-agent") || source.startsWith("github-copilot-agent")) {
1823
+ return "copilot-agent";
1824
+ }
1825
+ if (source.startsWith("copilot-cli") || source.startsWith("github-copilot-cli")) {
1826
+ return "copilot-cli";
1827
+ }
1828
+ if (source.startsWith("crush")) {
1829
+ return "crush";
1830
+ }
1831
+ if (source.startsWith("cursor")) {
1832
+ return "cursor";
1833
+ }
1834
+ if (source.startsWith("droid") || source.startsWith("factory-droid")) {
1835
+ return "droid";
1836
+ }
1837
+ if (source.startsWith("gemini")) {
1838
+ return "gemini-cli";
1839
+ }
1840
+ if (source.startsWith("grok-build") || source.startsWith("grokbuild") || source.startsWith("xai-grok-build")) {
1841
+ return "grok-build";
1842
+ }
1843
+ if (source.startsWith("grok")) {
1844
+ return "grok-cli";
1845
+ }
1846
+ if (source.startsWith("goose")) {
1847
+ return "goose";
1848
+ }
1849
+ if (source.startsWith("antigravity") || source === "google-antigravity") {
1850
+ return "antigravity";
1851
+ }
1852
+ if (source.startsWith("augment") || source.startsWith("auggie")) {
1853
+ return "augment";
1854
+ }
1855
+ if (source.startsWith("openclaw")) {
1856
+ return "openclaw";
1857
+ }
1858
+ if (source.startsWith("openhands")) {
1859
+ return "openhands";
1860
+ }
1861
+ if (source.startsWith("openinterpreter") || source.startsWith("open-interpreter")) {
1862
+ return "open-interpreter";
1863
+ }
1864
+ if (source.startsWith("openwebui") || source.startsWith("open-webui")) {
1865
+ return "openwebui";
1866
+ }
1867
+ if (source.startsWith("opencode") || source.startsWith("open-code")) {
1868
+ return "opencode";
1869
+ }
1870
+ if (source.startsWith("pi")) {
1871
+ return "pi";
1872
+ }
1873
+ if (source.startsWith("plandex")) {
1874
+ return "plandex";
1875
+ }
1876
+ if (source.startsWith("qoder")) {
1877
+ return "qoder";
1878
+ }
1879
+ if (source.startsWith("qwen")) {
1880
+ return "qwen-code";
1881
+ }
1882
+ if (source.startsWith("kimi")) {
1883
+ return "kimi";
1884
+ }
1885
+ if (source.startsWith("mux")) {
1886
+ return "mux";
1887
+ }
1888
+ if (source.startsWith("ruler")) {
1889
+ return "ruler";
1890
+ }
1891
+ if (source.startsWith("vscode-copilot") || source.startsWith("vs-code-copilot")) {
1892
+ return "vscode-copilot";
1893
+ }
1894
+ if (source === "direct" || source === "tokenjuice" || source === "wrap") {
1895
+ return DEFAULT_CLI_ARTIFACT_SOURCE;
1896
+ }
1897
+ return source;
1898
+ }
1899
+ function resolveArtifactSource(input) {
1900
+ return normalizeArtifactSource(input.metadata?.source) ?? DEFAULT_CLI_ARTIFACT_SOURCE;
1901
+ }
1902
+
1903
+ // src/core/artifacts.ts
1904
+ var ARTIFACT_ID_PATTERN = /^tj_[0-9a-f-]{12}$/iu;
1905
+ var ARTIFACT_DIR_ENV = "TOKENJUICE_ARTIFACT_DIR";
1906
+ var STATS_ENABLED_ENV = "TOKENJUICE_STATS";
1907
+ var METADATA_SEGMENT_DIRECTORY = "metadata-v1";
1908
+ var METADATA_SEGMENT_PREFIX = "events";
1909
+ var OPTIONAL_METADATA_STORAGE_ERROR_CODES = /* @__PURE__ */ new Set([
1910
+ "EACCES",
1911
+ "EDQUOT",
1912
+ "EEXIST",
1913
+ "EFBIG",
1914
+ "EIO",
1915
+ "EISDIR",
1916
+ "ELOOP",
1917
+ "EMFILE",
1918
+ "ENAMETOOLONG",
1919
+ "ENFILE",
1920
+ "ENOENT",
1921
+ "ENOSPC",
1922
+ "ENOTDIR",
1923
+ "EPERM",
1924
+ "EROFS"
1925
+ ]);
1926
+ function extractCaptureTruncatedFlag(input) {
1927
+ const value = input.metadata?.tokenjuiceCaptureTruncated;
1928
+ return typeof value === "boolean" ? value : void 0;
1929
+ }
1930
+ function getDefaultArtifactDir() {
1931
+ const artifactDir = process.env[ARTIFACT_DIR_ENV];
1932
+ if (typeof artifactDir === "string" && artifactDir.trim()) {
1933
+ return artifactDir.trim();
1934
+ }
1935
+ return join2(homedir(), ".tokenjuice", "artifacts");
1936
+ }
1937
+ function resolveArtifactBaseDir(storeDir) {
1938
+ return storeDir ?? getDefaultArtifactDir();
1939
+ }
1940
+ function isValidArtifactId(id) {
1941
+ return ARTIFACT_ID_PATTERN.test(id);
1942
+ }
1943
+ function buildArtifactPaths(id, storeDir) {
1944
+ if (!isValidArtifactId(id)) {
1945
+ throw new Error(`invalid artifact id: ${id}`);
1946
+ }
1947
+ const base = resolveArtifactBaseDir(storeDir);
1948
+ return {
1949
+ id,
1950
+ storage: "file",
1951
+ path: join2(base, `${id}.txt`),
1952
+ metadataPath: join2(base, `${id}.json`)
1953
+ };
1954
+ }
1955
+ function metadataSegmentDir(storeDir) {
1956
+ return join2(resolveArtifactBaseDir(storeDir), METADATA_SEGMENT_DIRECTORY);
1957
+ }
1958
+ var SAFE_COMMAND_FAMILY = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/u;
1959
+ function getTelemetryCommandFamily(input) {
1960
+ try {
1961
+ const family = getCommandName(getEffectiveCommandArgv(input));
1962
+ return family && SAFE_COMMAND_FAMILY.test(family) ? family : void 0;
1963
+ } catch {
1964
+ return void 0;
1965
+ }
1966
+ }
1967
+ function buildTelemetryMetadata(metadata, input) {
1968
+ const retainedMetadata = { ...metadata };
1969
+ delete retainedMetadata.command;
1970
+ const family = getTelemetryCommandFamily(input);
1971
+ return {
1972
+ ...retainedMetadata,
1973
+ ...family ? { commandFamily: family } : {}
1974
+ };
1975
+ }
1976
+ async function appendMetadataEvent(id, metadata, input, hasRaw, storeDir) {
1977
+ return await appendBoundedJsonl(
1978
+ metadataSegmentDir(storeDir),
1979
+ METADATA_SEGMENT_PREFIX,
1980
+ id,
1981
+ {
1982
+ id,
1983
+ hasRaw,
1984
+ metadata: buildTelemetryMetadata(metadata, input)
1985
+ }
1986
+ );
1987
+ }
1988
+ function shouldRecordStats(env = process.env) {
1989
+ const value = env[STATS_ENABLED_ENV]?.trim().toLowerCase();
1990
+ return value !== "0" && value !== "false" && value !== "no" && value !== "off";
1991
+ }
1992
+ async function storeArtifact(input, storeDir) {
1993
+ const id = `tj_${randomUUID2().slice(0, 12)}`;
1994
+ const ref = buildArtifactPaths(id, storeDir);
1995
+ await mkdir2(resolveArtifactBaseDir(storeDir), { recursive: true, mode: 448 });
1996
+ const captureTruncated = extractCaptureTruncatedFlag(input.input);
1997
+ const artifact = {
1998
+ id,
1999
+ rawText: input.rawText,
2000
+ metadata: {
2001
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2002
+ source: resolveArtifactSource(input.input),
2003
+ classification: input.classification,
2004
+ rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
2005
+ ...input.input.toolName ? { toolName: input.input.toolName } : {},
2006
+ ...input.input.command ? { command: input.input.command } : {},
2007
+ ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
2008
+ ...captureTruncated !== void 0 ? { captureTruncated } : {},
2009
+ ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
2010
+ }
2011
+ };
2012
+ await Promise.all([
2013
+ writeFile2(ref.path, input.rawText, { encoding: "utf8", mode: 384 }),
2014
+ writeFile2(ref.metadataPath, JSON.stringify(artifact.metadata, null, 2), { encoding: "utf8", mode: 384 })
2015
+ ]);
2016
+ if (input.recordStats ?? shouldRecordStats()) {
2017
+ await appendMetadataEvent(id, artifact.metadata, input.input, true, storeDir).catch(() => void 0);
2018
+ }
2019
+ return ref;
2020
+ }
2021
+ async function storeArtifactMetadata(input, storeDir) {
2022
+ const id = `tj_${randomUUID2().slice(0, 12)}`;
2023
+ const captureTruncated = extractCaptureTruncatedFlag(input.input);
2024
+ const metadata = {
2025
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2026
+ source: resolveArtifactSource(input.input),
2027
+ classification: input.classification,
2028
+ rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
2029
+ ...input.input.toolName ? { toolName: input.input.toolName } : {},
2030
+ ...input.input.command ? { command: input.input.command } : {},
2031
+ ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
2032
+ ...captureTruncated !== void 0 ? { captureTruncated } : {},
2033
+ ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
2034
+ };
2035
+ const telemetryMetadata = buildTelemetryMetadata(metadata, input.input);
2036
+ const metadataPath = await appendMetadataEvent(id, telemetryMetadata, input.input, false, storeDir);
2037
+ if (!metadataPath) {
2038
+ throw Object.assign(new Error("metadata segment is full or busy"), { code: "EFBIG" });
2039
+ }
2040
+ return {
2041
+ id,
2042
+ storage: "file",
2043
+ metadataPath,
2044
+ metadataFormat: "jsonl-segment",
2045
+ metadataRecordId: id,
2046
+ metadata: telemetryMetadata
2047
+ };
2048
+ }
2049
+ async function tryStoreArtifactMetadata(input, storeDir) {
2050
+ try {
2051
+ return await storeArtifactMetadata(input, storeDir);
2052
+ } catch (error) {
2053
+ const code = error.code;
2054
+ if (typeof code !== "string" || !OPTIONAL_METADATA_STORAGE_ERROR_CODES.has(code)) {
2055
+ throw error;
2056
+ }
2057
+ return void 0;
2058
+ }
1464
2059
  }
1465
2060
 
1466
2061
  // src/core/reduce-utils.ts
2062
+ import { createHash as createHash2 } from "node:crypto";
1467
2063
  function compactWhitespace(text) {
1468
2064
  return text.replace(/\s+/gu, " ").trim();
1469
2065
  }
1470
2066
  function shortHash(text) {
1471
- return createHash("sha256").update(text).digest("hex").slice(0, 12);
2067
+ return createHash2("sha256").update(text).digest("hex").slice(0, 12);
1472
2068
  }
1473
2069
  function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
1474
2070
  if (countTextChars(text) <= maxChars) {
@@ -1687,9 +2283,9 @@ function buildInspectionSummary(input, rawText, noOmit = false) {
1687
2283
  }
1688
2284
 
1689
2285
  // src/core/rules.ts
1690
- import { readdir, readFile, realpath } from "node:fs/promises";
1691
- import { homedir } from "node:os";
1692
- import { isAbsolute, join, relative, resolve } from "node:path";
2286
+ import { readdir as readdir2, readFile as readFile3, realpath } from "node:fs/promises";
2287
+ import { homedir as homedir2 } from "node:os";
2288
+ import { isAbsolute, join as join3, relative, resolve } from "node:path";
1693
2289
  import { fileURLToPath } from "node:url";
1694
2290
 
1695
2291
  // src/rules/archive/tar.json
@@ -7254,10 +7850,10 @@ async function listRuleFiles(root) {
7254
7850
  }
7255
7851
  const rootRealPath = resolvedRoot;
7256
7852
  async function walk(currentDir) {
7257
- const entries = (await readdir(currentDir, { withFileTypes: true })).sort((left, right) => left.name.localeCompare(right.name));
7853
+ const entries = (await readdir2(currentDir, { withFileTypes: true })).sort((left, right) => left.name.localeCompare(right.name));
7258
7854
  const files = await Promise.all(
7259
7855
  entries.map(async (entry) => {
7260
- const fullPath = join(currentDir, entry.name);
7856
+ const fullPath = join3(currentDir, entry.name);
7261
7857
  if (entry.isSymbolicLink()) {
7262
7858
  return [];
7263
7859
  }
@@ -7287,10 +7883,10 @@ async function listRuleFiles(root) {
7287
7883
  }
7288
7884
  }
7289
7885
  function userRulesRoot(customDir) {
7290
- return customDir ?? join(homedir(), ".config", "tokenjuice", "rules");
7886
+ return customDir ?? join3(homedir2(), ".config", "tokenjuice", "rules");
7291
7887
  }
7292
7888
  function projectRulesRoot(cwd, customDir) {
7293
- return customDir ?? join(cwd ?? process.cwd(), ".tokenjuice", "rules");
7889
+ return customDir ?? join3(cwd ?? process.cwd(), ".tokenjuice", "rules");
7294
7890
  }
7295
7891
  function sortRules(rules) {
7296
7892
  return [...rules].sort((left, right) => {
@@ -7307,7 +7903,7 @@ async function loadRuleDescriptorsFromRoot(root, source) {
7307
7903
  const files = await listRuleFiles(root);
7308
7904
  return await Promise.all(
7309
7905
  files.map(async (fullPath) => {
7310
- const parsed = JSON.parse(await readFile(fullPath, "utf8"));
7906
+ const parsed = JSON.parse(await readFile3(fullPath, "utf8"));
7311
7907
  assertValidRule(parsed);
7312
7908
  return {
7313
7909
  source,
@@ -7539,258 +8135,6 @@ function classifyExecution(input, rules, forcedRuleId) {
7539
8135
  return resolved.classification;
7540
8136
  }
7541
8137
 
7542
- // src/core/execution-input.ts
7543
- function normalizeExecutionInput(input) {
7544
- const shellWrapped = unwrapShellRunner(input);
7545
- if (shellWrapped) {
7546
- const effectiveCommand2 = stripLeadingCdPrefix(shellWrapped);
7547
- if (isCompoundShellCommand(effectiveCommand2)) {
7548
- const { argv: _argv, ...restInput } = input;
7549
- return {
7550
- ...restInput,
7551
- command: effectiveCommand2
7552
- };
7553
- }
7554
- const argv2 = resolveEffectiveCommand({ command: effectiveCommand2 })?.argv ?? tokenizeCommand(effectiveCommand2);
7555
- if (argv2.length === 0) {
7556
- return {
7557
- ...input,
7558
- command: effectiveCommand2
7559
- };
7560
- }
7561
- return {
7562
- ...input,
7563
- command: argv2.join(" "),
7564
- argv: argv2
7565
- };
7566
- }
7567
- const effective = resolveEffectiveCommand(input);
7568
- if (effective?.argv.length) {
7569
- return {
7570
- ...input,
7571
- ...effective.command ? { command: effective.command } : {},
7572
- argv: effective.argv
7573
- };
7574
- }
7575
- if (input.argv?.length || !input.command) {
7576
- return input;
7577
- }
7578
- const effectiveCommand = stripLeadingCdPrefix(input.command);
7579
- if (isCompoundShellCommand(effectiveCommand)) {
7580
- return input;
7581
- }
7582
- const argv = tokenizeCommand(effectiveCommand);
7583
- if (argv.length === 0) {
7584
- return input;
7585
- }
7586
- return {
7587
- ...input,
7588
- command: argv.join(" "),
7589
- argv
7590
- };
7591
- }
7592
-
7593
- // src/core/artifacts.ts
7594
- import { mkdir, readFile as readFile2, readdir as readdir2, writeFile } from "node:fs/promises";
7595
- import { homedir as homedir2 } from "node:os";
7596
- import { join as join2 } from "node:path";
7597
- import { randomUUID } from "node:crypto";
7598
-
7599
- // src/core/source.ts
7600
- var DEFAULT_CLI_ARTIFACT_SOURCE = "cli";
7601
- function normalizeArtifactSource(value) {
7602
- if (typeof value !== "string") {
7603
- return null;
7604
- }
7605
- const source = value.trim().toLowerCase().replace(/[_\s]+/gu, "-").replace(/[^a-z0-9.-]+/gu, "-").replace(/^-+|-+$/gu, "");
7606
- if (!source) {
7607
- return null;
7608
- }
7609
- if (source.startsWith("amazon-q") || source.startsWith("amazonq") || source.startsWith("aws-q")) {
7610
- return "amazon-q";
7611
- }
7612
- if (source.startsWith("claude-code") || source === "claude") {
7613
- return "claude-code";
7614
- }
7615
- if (source.startsWith("cline")) {
7616
- return "cline";
7617
- }
7618
- if (source.startsWith("codex")) {
7619
- return "codex";
7620
- }
7621
- if (source.startsWith("command-code") || source.startsWith("commandcode")) {
7622
- return "command-code";
7623
- }
7624
- if (source.startsWith("copilot-agent") || source.startsWith("github-copilot-agent")) {
7625
- return "copilot-agent";
7626
- }
7627
- if (source.startsWith("copilot-cli") || source.startsWith("github-copilot-cli")) {
7628
- return "copilot-cli";
7629
- }
7630
- if (source.startsWith("crush")) {
7631
- return "crush";
7632
- }
7633
- if (source.startsWith("cursor")) {
7634
- return "cursor";
7635
- }
7636
- if (source.startsWith("droid") || source.startsWith("factory-droid")) {
7637
- return "droid";
7638
- }
7639
- if (source.startsWith("gemini")) {
7640
- return "gemini-cli";
7641
- }
7642
- if (source.startsWith("grok-build") || source.startsWith("grokbuild") || source.startsWith("xai-grok-build")) {
7643
- return "grok-build";
7644
- }
7645
- if (source.startsWith("grok")) {
7646
- return "grok-cli";
7647
- }
7648
- if (source.startsWith("goose")) {
7649
- return "goose";
7650
- }
7651
- if (source.startsWith("antigravity") || source === "google-antigravity") {
7652
- return "antigravity";
7653
- }
7654
- if (source.startsWith("augment") || source.startsWith("auggie")) {
7655
- return "augment";
7656
- }
7657
- if (source.startsWith("openclaw")) {
7658
- return "openclaw";
7659
- }
7660
- if (source.startsWith("openhands")) {
7661
- return "openhands";
7662
- }
7663
- if (source.startsWith("openinterpreter") || source.startsWith("open-interpreter")) {
7664
- return "open-interpreter";
7665
- }
7666
- if (source.startsWith("openwebui") || source.startsWith("open-webui")) {
7667
- return "openwebui";
7668
- }
7669
- if (source.startsWith("opencode") || source.startsWith("open-code")) {
7670
- return "opencode";
7671
- }
7672
- if (source.startsWith("pi")) {
7673
- return "pi";
7674
- }
7675
- if (source.startsWith("plandex")) {
7676
- return "plandex";
7677
- }
7678
- if (source.startsWith("qoder")) {
7679
- return "qoder";
7680
- }
7681
- if (source.startsWith("qwen")) {
7682
- return "qwen-code";
7683
- }
7684
- if (source.startsWith("kimi")) {
7685
- return "kimi";
7686
- }
7687
- if (source.startsWith("mux")) {
7688
- return "mux";
7689
- }
7690
- if (source.startsWith("ruler")) {
7691
- return "ruler";
7692
- }
7693
- if (source.startsWith("vscode-copilot") || source.startsWith("vs-code-copilot")) {
7694
- return "vscode-copilot";
7695
- }
7696
- if (source === "direct" || source === "tokenjuice" || source === "wrap") {
7697
- return DEFAULT_CLI_ARTIFACT_SOURCE;
7698
- }
7699
- return source;
7700
- }
7701
- function resolveArtifactSource(input) {
7702
- return normalizeArtifactSource(input.metadata?.source) ?? DEFAULT_CLI_ARTIFACT_SOURCE;
7703
- }
7704
-
7705
- // src/core/artifacts.ts
7706
- var ARTIFACT_ID_PATTERN = /^tj_[0-9a-f-]{12}$/iu;
7707
- var ARTIFACT_DIR_ENV = "TOKENJUICE_ARTIFACT_DIR";
7708
- function extractCaptureTruncatedFlag(input) {
7709
- const value = input.metadata?.tokenjuiceCaptureTruncated;
7710
- return typeof value === "boolean" ? value : void 0;
7711
- }
7712
- function getDefaultArtifactDir() {
7713
- const artifactDir = process.env[ARTIFACT_DIR_ENV];
7714
- if (typeof artifactDir === "string" && artifactDir.trim()) {
7715
- return artifactDir.trim();
7716
- }
7717
- return join2(homedir2(), ".tokenjuice", "artifacts");
7718
- }
7719
- function resolveArtifactBaseDir(storeDir) {
7720
- return storeDir ?? getDefaultArtifactDir();
7721
- }
7722
- function isValidArtifactId(id) {
7723
- return ARTIFACT_ID_PATTERN.test(id);
7724
- }
7725
- function buildArtifactPaths(id, storeDir) {
7726
- if (!isValidArtifactId(id)) {
7727
- throw new Error(`invalid artifact id: ${id}`);
7728
- }
7729
- const base = resolveArtifactBaseDir(storeDir);
7730
- return {
7731
- id,
7732
- storage: "file",
7733
- path: join2(base, `${id}.txt`),
7734
- metadataPath: join2(base, `${id}.json`)
7735
- };
7736
- }
7737
- function buildMetadataOnlyPath(id, storeDir) {
7738
- if (!isValidArtifactId(id)) {
7739
- throw new Error(`invalid artifact id: ${id}`);
7740
- }
7741
- return join2(resolveArtifactBaseDir(storeDir), `${id}.meta.json`);
7742
- }
7743
- async function storeArtifact(input, storeDir) {
7744
- const id = `tj_${randomUUID().slice(0, 12)}`;
7745
- const ref = buildArtifactPaths(id, storeDir);
7746
- await mkdir(resolveArtifactBaseDir(storeDir), { recursive: true, mode: 448 });
7747
- const captureTruncated = extractCaptureTruncatedFlag(input.input);
7748
- const artifact = {
7749
- id,
7750
- rawText: input.rawText,
7751
- metadata: {
7752
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
7753
- source: resolveArtifactSource(input.input),
7754
- classification: input.classification,
7755
- rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
7756
- ...input.input.toolName ? { toolName: input.input.toolName } : {},
7757
- ...input.input.command ? { command: input.input.command } : {},
7758
- ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
7759
- ...captureTruncated !== void 0 ? { captureTruncated } : {},
7760
- ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
7761
- }
7762
- };
7763
- await Promise.all([
7764
- writeFile(ref.path, input.rawText, { encoding: "utf8", mode: 384 }),
7765
- writeFile(ref.metadataPath, JSON.stringify(artifact.metadata, null, 2), { encoding: "utf8", mode: 384 })
7766
- ]);
7767
- return ref;
7768
- }
7769
- async function storeArtifactMetadata(input, storeDir) {
7770
- const id = `tj_${randomUUID().slice(0, 12)}`;
7771
- const metadataPath = buildMetadataOnlyPath(id, storeDir);
7772
- const captureTruncated = extractCaptureTruncatedFlag(input.input);
7773
- const metadata = {
7774
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
7775
- source: resolveArtifactSource(input.input),
7776
- classification: input.classification,
7777
- rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
7778
- ...input.input.toolName ? { toolName: input.input.toolName } : {},
7779
- ...input.input.command ? { command: input.input.command } : {},
7780
- ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
7781
- ...captureTruncated !== void 0 ? { captureTruncated } : {},
7782
- ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
7783
- };
7784
- await mkdir(resolveArtifactBaseDir(storeDir), { recursive: true, mode: 448 });
7785
- await writeFile(metadataPath, JSON.stringify(metadata, null, 2), { encoding: "utf8", mode: 384 });
7786
- return {
7787
- id,
7788
- storage: "file",
7789
- metadataPath,
7790
- metadata
7791
- };
7792
- }
7793
-
7794
8138
  // src/core/github-actions-summary.ts
7795
8139
  var GITHUB_ACTIONS_EXIT_PATTERN = /^Error: Process completed with exit code (\d+)\.?$/u;
7796
8140
  var GITHUB_ACTIONS_RUN_PATTERN = /^(?:##\[group\]|::group::)?Run\s+(.+)$/u;
@@ -8463,6 +8807,7 @@ function isGithubCliCommand(command) {
8463
8807
  var TINY_OUTPUT_MAX_CHARS = 240;
8464
8808
  var SMALL_OUTPUT_PASSTHROUGH_MIN_SAVED_CHARS = 120;
8465
8809
  var SMALL_OUTPUT_PASSTHROUGH_MAX_RATIO = 0.75;
8810
+ var FAILURE_SEVERITY_FACTS = /* @__PURE__ */ new Set(["error", "warning"]);
8466
8811
  function buildRawText(input) {
8467
8812
  if (input.combinedText) {
8468
8813
  return input.combinedText;
@@ -8503,6 +8848,12 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8503
8848
  if (rule.transforms?.stripAnsi) {
8504
8849
  lines = normalizeLines(stripAnsi(lines.join("\n")));
8505
8850
  }
8851
+ let rewriteCompaction;
8852
+ if (!noOmit && rule.id === "generic/fallback") {
8853
+ const collapsed = collapseRepeatedEmojiBanner(lines);
8854
+ lines = collapsed.lines;
8855
+ rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, collapsed.compaction);
8856
+ }
8506
8857
  const outputMatchText = trimEmptyEdges(lines).join("\n");
8507
8858
  const matchedOutput = compiledRule.compiled.outputMatches.find((entry) => entry.pattern.test(outputMatchText));
8508
8859
  if (!noOmit && matchedOutput) {
@@ -8535,7 +8886,6 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8535
8886
  lines = rewriteGitStatusLines(lines);
8536
8887
  }
8537
8888
  const preRewriteLines = [...lines];
8538
- let rewriteCompaction;
8539
8889
  if (rule.id === "cloud/gh") {
8540
8890
  counterLines = rewriteGhLines(counterLines, input, noOmit).lines;
8541
8891
  const rewritten = rewriteGhLines(lines, input, noOmit);
@@ -8628,7 +8978,11 @@ function isTerseDiscoveryCommand(classification, input) {
8628
8978
  return false;
8629
8979
  }
8630
8980
  function formatInline(classification, input, summary, facts, noOmit = false) {
8631
- const factParts = Object.entries(facts).filter(([, count]) => count > 0).map(([name, count]) => pluralize(count, name));
8981
+ const neutralizeSeverityFacts = classification.matchedReducer === "generic/fallback" && input.exitCode === 0;
8982
+ const factParts = Object.entries(facts).filter(([, count]) => count > 0).map(([name, count]) => pluralize(
8983
+ count,
8984
+ neutralizeSeverityFacts && FAILURE_SEVERITY_FACTS.has(name) ? `${name} mention` : name
8985
+ ));
8632
8986
  const lines = [];
8633
8987
  if (input.exitCode && input.exitCode !== 0) {
8634
8988
  lines.push(`exit ${input.exitCode}`);
@@ -8723,6 +9077,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8723
9077
  input: normalizedInput,
8724
9078
  rawText,
8725
9079
  classification,
9080
+ ...opts.recordStats !== void 0 ? { recordStats: opts.recordStats } : {},
8726
9081
  stats: {
8727
9082
  rawChars: measuredRawChars,
8728
9083
  reducedChars: measuredRawChars,
@@ -8732,7 +9087,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8732
9087
  opts.storeDir
8733
9088
  ) : void 0;
8734
9089
  if (!opts.store && opts.recordStats) {
8735
- await storeArtifactMetadata(
9090
+ await tryStoreArtifactMetadata(
8736
9091
  {
8737
9092
  input: normalizedInput,
8738
9093
  rawText,
@@ -8779,12 +9134,13 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8779
9134
  input: normalizedInput,
8780
9135
  rawText,
8781
9136
  classification: summaryClassification,
9137
+ ...opts.recordStats !== void 0 ? { recordStats: opts.recordStats } : {},
8782
9138
  stats: stats2
8783
9139
  },
8784
9140
  opts.storeDir
8785
9141
  ) : void 0;
8786
9142
  if (!opts.store && opts.recordStats) {
8787
- await storeArtifactMetadata(
9143
+ await tryStoreArtifactMetadata(
8788
9144
  {
8789
9145
  input: normalizedInput,
8790
9146
  rawText,
@@ -8806,7 +9162,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8806
9162
  }
8807
9163
  if (classification.matchedReducer === "generic/fallback" && isFileContentInspectionCommand(normalizedInput)) {
8808
9164
  if (!opts.store && opts.recordStats) {
8809
- await storeArtifactMetadata(
9165
+ await tryStoreArtifactMetadata(
8810
9166
  {
8811
9167
  input: normalizedInput,
8812
9168
  rawText,
@@ -8850,12 +9206,13 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8850
9206
  input: normalizedInput,
8851
9207
  rawText,
8852
9208
  classification,
9209
+ ...opts.recordStats !== void 0 ? { recordStats: opts.recordStats } : {},
8853
9210
  stats: stats2
8854
9211
  },
8855
9212
  opts.storeDir
8856
9213
  ) : void 0;
8857
9214
  if (!opts.store && opts.recordStats) {
8858
- await storeArtifactMetadata(
9215
+ await tryStoreArtifactMetadata(
8859
9216
  {
8860
9217
  input: normalizedInput,
8861
9218
  rawText,
@@ -8896,12 +9253,13 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8896
9253
  input: normalizedInput,
8897
9254
  rawText,
8898
9255
  classification: jsonClassification,
9256
+ ...opts.recordStats !== void 0 ? { recordStats: opts.recordStats } : {},
8899
9257
  stats: stats2
8900
9258
  },
8901
9259
  opts.storeDir
8902
9260
  ) : void 0;
8903
9261
  if (!opts.store && opts.recordStats) {
8904
- await storeArtifactMetadata(
9262
+ await tryStoreArtifactMetadata(
8905
9263
  {
8906
9264
  input: normalizedInput,
8907
9265
  rawText,
@@ -8922,7 +9280,13 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8922
9280
  }
8923
9281
  }
8924
9282
  const { summary, facts, compaction } = applyRule(matchedRule, reducerInput, rawText, opts.noOmit);
8925
- const compactText = formatInline(classification, reducerInput, summary || "(no output)", facts, opts.noOmit);
9283
+ const compactText = formatInline(
9284
+ classification,
9285
+ reducerInput,
9286
+ summary || "(no output)",
9287
+ facts,
9288
+ opts.noOmit
9289
+ );
8926
9290
  const selectedText = selectInlineText(classification, reducerInput, rawText, compactText, maxInlineChars, compaction, opts.noOmit);
8927
9291
  const clamp = classification.family === "help" || selectedText.text.includes("\n") ? clampTextMiddleWithMetadata : clampTextWithMetadata;
8928
9292
  const inlineText = clamp(selectedText.text, maxInlineChars, opts.noOmit);
@@ -8937,12 +9301,13 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8937
9301
  input: normalizedInput,
8938
9302
  rawText,
8939
9303
  classification,
9304
+ ...opts.recordStats !== void 0 ? { recordStats: opts.recordStats } : {},
8940
9305
  stats
8941
9306
  },
8942
9307
  opts.storeDir
8943
9308
  ) : void 0;
8944
9309
  if (!opts.store && opts.recordStats) {
8945
- await storeArtifactMetadata(
9310
+ await tryStoreArtifactMetadata(
8946
9311
  {
8947
9312
  input: normalizedInput,
8948
9313
  rawText,
@@ -9048,8 +9413,8 @@ async function compactBashResult(input) {
9048
9413
  const options = {
9049
9414
  ...typeof input.cwd === "string" && input.cwd.trim() ? { cwd: input.cwd } : {},
9050
9415
  ...typeof input.maxInlineChars === "number" ? { maxInlineChars: input.maxInlineChars } : {},
9051
- ...readNoOmissionFromEnv() || input.noOmit ? { noOmit: true } : {},
9052
- recordStats: true,
9416
+ ...input.noOmit || !input.allowOmit && readNoOmissionFromEnv() ? { noOmit: true } : {},
9417
+ recordStats: input.recordStats ?? shouldRecordStats(),
9053
9418
  ...input.storeRaw ? { store: true } : {}
9054
9419
  };
9055
9420
  const result = await reduceExecution(executionInput, options);
@@ -9078,7 +9443,7 @@ function isRecord2(value) {
9078
9443
 
9079
9444
  // src/hosts/pi/extension/settings.ts
9080
9445
  import { readFileSync } from "node:fs";
9081
- import { join as join3 } from "node:path";
9446
+ import { join as join4 } from "node:path";
9082
9447
 
9083
9448
  // src/hosts/pi/extension/utils.ts
9084
9449
  function formatErrorMessage(error) {
@@ -9091,8 +9456,8 @@ function formatErrorMessage(error) {
9091
9456
  // src/hosts/pi/extension/settings.ts
9092
9457
  function getAutoCompactionEnabled(projectRoot) {
9093
9458
  const home = process.env.HOME || process.env.USERPROFILE || "";
9094
- const agentDir = process.env.PI_CODING_AGENT_DIR || join3(home, ".pi", "agent");
9095
- const settingsPaths = [join3(agentDir, "settings.json"), join3(projectRoot, ".pi", "settings.json")];
9459
+ const agentDir = process.env.PI_CODING_AGENT_DIR || join4(home, ".pi", "agent");
9460
+ const settingsPaths = [join4(agentDir, "settings.json"), join4(projectRoot, ".pi", "settings.json")];
9096
9461
  let enabled = true;
9097
9462
  for (const settingsPath of settingsPaths) {
9098
9463
  let parsed;
@@ -9331,7 +9696,7 @@ function createTokenjuicePiExtension(config) {
9331
9696
  async function loadFullOutputText(fullOutputPath) {
9332
9697
  let details;
9333
9698
  try {
9334
- details = await stat(fullOutputPath);
9699
+ details = await stat2(fullOutputPath);
9335
9700
  } catch (error) {
9336
9701
  throw new Error(`tokenjuice failed to stat bash full output file ${fullOutputPath}: ${formatErrorMessage(error)}`);
9337
9702
  }
@@ -9339,7 +9704,7 @@ function createTokenjuicePiExtension(config) {
9339
9704
  return null;
9340
9705
  }
9341
9706
  try {
9342
- return await readFile3(fullOutputPath, "utf8");
9707
+ return await readFile4(fullOutputPath, "utf8");
9343
9708
  } catch (error) {
9344
9709
  throw new Error(`tokenjuice failed to read bash full output file ${fullOutputPath}: ${formatErrorMessage(error)}`);
9345
9710
  }