@openclaw/tokenjuice 2026.9.4 → 2026.9.5

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 (35) hide show
  1. package/assets/activity.svg +3 -0
  2. package/assets/icon.png +0 -0
  3. package/node_modules/tokenjuice/README.md +6 -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 +4 -0
  7. package/node_modules/tokenjuice/dist/cli/main.js +143 -26
  8. package/node_modules/tokenjuice/dist/core/artifacts.d.ts +1 -0
  9. package/node_modules/tokenjuice/dist/core/artifacts.js +29 -0
  10. package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +1 -1
  11. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +1 -0
  12. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +1 -1
  13. package/node_modules/tokenjuice/dist/core/reduce.js +18 -10
  14. package/node_modules/tokenjuice/dist/core/text.d.ts +4 -0
  15. package/node_modules/tokenjuice/dist/core/text.js +32 -0
  16. package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +25 -1
  17. package/node_modules/tokenjuice/dist/hosts/codex/index.js +211 -163
  18. package/node_modules/tokenjuice/dist/hosts/grok-bot/index.d.ts +25 -0
  19. package/node_modules/tokenjuice/dist/hosts/grok-bot/index.js +644 -0
  20. package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +79 -10
  21. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +79 -10
  22. package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.d.ts +24 -0
  23. package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.js +80 -1
  24. package/node_modules/tokenjuice/dist/hosts/shared/hook-command.d.ts +19 -0
  25. package/node_modules/tokenjuice/dist/hosts/shared/hook-command.js +61 -6
  26. package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.d.ts +3 -1
  27. package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.js +2 -0
  28. package/node_modules/tokenjuice/dist/hosts/shared/host-command.d.ts +10 -1
  29. package/node_modules/tokenjuice/dist/hosts/shared/host-command.js +43 -4
  30. package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.js +9 -7
  31. package/node_modules/tokenjuice/dist/index.d.ts +2 -0
  32. package/node_modules/tokenjuice/dist/index.js +1 -0
  33. package/node_modules/tokenjuice/package.json +1 -1
  34. package/openclaw.plugin.json +1 -1
  35. package/package.json +8 -6
@@ -1325,6 +1325,9 @@ var TRUNCATION_SUFFIX = "\n... truncated ...";
1325
1325
  var MIDDLE_TRUNCATION_MARKER = "\n... omitted ...\n";
1326
1326
  var COMBINING_MARK_PATTERN = new RegExp("\\p{Mark}", "u");
1327
1327
  var EMOJI_PATTERN = new RegExp("\\p{Extended_Pictographic}", "u");
1328
+ var FLAG_EMOJI_PATTERN = new RegExp("^\\p{Regional_Indicator}{2}$", "u");
1329
+ var KEYCAP_EMOJI_PATTERN = /^[#*0-9]\uFE0F?\u20E3$/u;
1330
+ var REPEATED_EMOJI_BANNER_MIN_REPETITIONS = 24;
1328
1331
  var graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : null;
1329
1332
  function graphemes(text) {
1330
1333
  if (!graphemeSegmenter) {
@@ -1378,6 +1381,28 @@ function dedupeAdjacent(lines) {
1378
1381
  }
1379
1382
  return next;
1380
1383
  }
1384
+ function formatCodePoints(text) {
1385
+ return Array.from(text, (character) => `U+${character.codePointAt(0)?.toString(16).toUpperCase().padStart(4, "0")}`).join("+");
1386
+ }
1387
+ function isEmojiGrapheme(text) {
1388
+ return EMOJI_PATTERN.test(text) || FLAG_EMOJI_PATTERN.test(text) || KEYCAP_EMOJI_PATTERN.test(text);
1389
+ }
1390
+ function collapseRepeatedEmojiBanner(lines) {
1391
+ let collapsed = false;
1392
+ const nextLines = lines.map((line) => {
1393
+ const visibleSegments = graphemes(line).filter((segment) => !/^\s+$/u.test(segment));
1394
+ const repeatedEmoji = visibleSegments[0];
1395
+ if (visibleSegments.length < REPEATED_EMOJI_BANNER_MIN_REPETITIONS || !repeatedEmoji || !isEmojiGrapheme(repeatedEmoji) || visibleSegments.some((segment) => segment !== repeatedEmoji)) {
1396
+ return line;
1397
+ }
1398
+ collapsed = true;
1399
+ return `[repeated emoji banner omitted: ${formatCodePoints(repeatedEmoji)} x${visibleSegments.length}]`;
1400
+ });
1401
+ return collapsed ? {
1402
+ lines: nextLines,
1403
+ compaction: createCompactionMetadata("repeated-emoji-banner-omission")
1404
+ } : { lines: nextLines };
1405
+ }
1381
1406
  function headTail(lines, head, tail, noOmit = false) {
1382
1407
  const safeHead = Math.max(0, head);
1383
1408
  const safeTail = Math.max(0, tail);
@@ -7705,6 +7730,23 @@ function resolveArtifactSource(input) {
7705
7730
  // src/core/artifacts.ts
7706
7731
  var ARTIFACT_ID_PATTERN = /^tj_[0-9a-f-]{12}$/iu;
7707
7732
  var ARTIFACT_DIR_ENV = "TOKENJUICE_ARTIFACT_DIR";
7733
+ var OPTIONAL_METADATA_STORAGE_ERROR_CODES = /* @__PURE__ */ new Set([
7734
+ "EACCES",
7735
+ "EDQUOT",
7736
+ "EEXIST",
7737
+ "EFBIG",
7738
+ "EIO",
7739
+ "EISDIR",
7740
+ "ELOOP",
7741
+ "EMFILE",
7742
+ "ENAMETOOLONG",
7743
+ "ENFILE",
7744
+ "ENOENT",
7745
+ "ENOSPC",
7746
+ "ENOTDIR",
7747
+ "EPERM",
7748
+ "EROFS"
7749
+ ]);
7708
7750
  function extractCaptureTruncatedFlag(input) {
7709
7751
  const value = input.metadata?.tokenjuiceCaptureTruncated;
7710
7752
  return typeof value === "boolean" ? value : void 0;
@@ -7790,6 +7832,17 @@ async function storeArtifactMetadata(input, storeDir) {
7790
7832
  metadata
7791
7833
  };
7792
7834
  }
7835
+ async function tryStoreArtifactMetadata(input, storeDir) {
7836
+ try {
7837
+ return await storeArtifactMetadata(input, storeDir);
7838
+ } catch (error) {
7839
+ const code = error.code;
7840
+ if (typeof code !== "string" || !OPTIONAL_METADATA_STORAGE_ERROR_CODES.has(code)) {
7841
+ throw error;
7842
+ }
7843
+ return void 0;
7844
+ }
7845
+ }
7793
7846
 
7794
7847
  // src/core/github-actions-summary.ts
7795
7848
  var GITHUB_ACTIONS_EXIT_PATTERN = /^Error: Process completed with exit code (\d+)\.?$/u;
@@ -8463,6 +8516,7 @@ function isGithubCliCommand(command) {
8463
8516
  var TINY_OUTPUT_MAX_CHARS = 240;
8464
8517
  var SMALL_OUTPUT_PASSTHROUGH_MIN_SAVED_CHARS = 120;
8465
8518
  var SMALL_OUTPUT_PASSTHROUGH_MAX_RATIO = 0.75;
8519
+ var FAILURE_SEVERITY_FACTS = /* @__PURE__ */ new Set(["error", "warning"]);
8466
8520
  function buildRawText(input) {
8467
8521
  if (input.combinedText) {
8468
8522
  return input.combinedText;
@@ -8503,6 +8557,12 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8503
8557
  if (rule.transforms?.stripAnsi) {
8504
8558
  lines = normalizeLines(stripAnsi(lines.join("\n")));
8505
8559
  }
8560
+ let rewriteCompaction;
8561
+ if (!noOmit && rule.id === "generic/fallback") {
8562
+ const collapsed = collapseRepeatedEmojiBanner(lines);
8563
+ lines = collapsed.lines;
8564
+ rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, collapsed.compaction);
8565
+ }
8506
8566
  const outputMatchText = trimEmptyEdges(lines).join("\n");
8507
8567
  const matchedOutput = compiledRule.compiled.outputMatches.find((entry) => entry.pattern.test(outputMatchText));
8508
8568
  if (!noOmit && matchedOutput) {
@@ -8535,7 +8595,6 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8535
8595
  lines = rewriteGitStatusLines(lines);
8536
8596
  }
8537
8597
  const preRewriteLines = [...lines];
8538
- let rewriteCompaction;
8539
8598
  if (rule.id === "cloud/gh") {
8540
8599
  counterLines = rewriteGhLines(counterLines, input, noOmit).lines;
8541
8600
  const rewritten = rewriteGhLines(lines, input, noOmit);
@@ -8628,7 +8687,11 @@ function isTerseDiscoveryCommand(classification, input) {
8628
8687
  return false;
8629
8688
  }
8630
8689
  function formatInline(classification, input, summary, facts, noOmit = false) {
8631
- const factParts = Object.entries(facts).filter(([, count]) => count > 0).map(([name, count]) => pluralize(count, name));
8690
+ const neutralizeSeverityFacts = classification.matchedReducer === "generic/fallback" && input.exitCode === 0;
8691
+ const factParts = Object.entries(facts).filter(([, count]) => count > 0).map(([name, count]) => pluralize(
8692
+ count,
8693
+ neutralizeSeverityFacts && FAILURE_SEVERITY_FACTS.has(name) ? `${name} mention` : name
8694
+ ));
8632
8695
  const lines = [];
8633
8696
  if (input.exitCode && input.exitCode !== 0) {
8634
8697
  lines.push(`exit ${input.exitCode}`);
@@ -8732,7 +8795,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8732
8795
  opts.storeDir
8733
8796
  ) : void 0;
8734
8797
  if (!opts.store && opts.recordStats) {
8735
- await storeArtifactMetadata(
8798
+ await tryStoreArtifactMetadata(
8736
8799
  {
8737
8800
  input: normalizedInput,
8738
8801
  rawText,
@@ -8784,7 +8847,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8784
8847
  opts.storeDir
8785
8848
  ) : void 0;
8786
8849
  if (!opts.store && opts.recordStats) {
8787
- await storeArtifactMetadata(
8850
+ await tryStoreArtifactMetadata(
8788
8851
  {
8789
8852
  input: normalizedInput,
8790
8853
  rawText,
@@ -8806,7 +8869,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8806
8869
  }
8807
8870
  if (classification.matchedReducer === "generic/fallback" && isFileContentInspectionCommand(normalizedInput)) {
8808
8871
  if (!opts.store && opts.recordStats) {
8809
- await storeArtifactMetadata(
8872
+ await tryStoreArtifactMetadata(
8810
8873
  {
8811
8874
  input: normalizedInput,
8812
8875
  rawText,
@@ -8855,7 +8918,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8855
8918
  opts.storeDir
8856
8919
  ) : void 0;
8857
8920
  if (!opts.store && opts.recordStats) {
8858
- await storeArtifactMetadata(
8921
+ await tryStoreArtifactMetadata(
8859
8922
  {
8860
8923
  input: normalizedInput,
8861
8924
  rawText,
@@ -8901,7 +8964,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8901
8964
  opts.storeDir
8902
8965
  ) : void 0;
8903
8966
  if (!opts.store && opts.recordStats) {
8904
- await storeArtifactMetadata(
8967
+ await tryStoreArtifactMetadata(
8905
8968
  {
8906
8969
  input: normalizedInput,
8907
8970
  rawText,
@@ -8922,7 +8985,13 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8922
8985
  }
8923
8986
  }
8924
8987
  const { summary, facts, compaction } = applyRule(matchedRule, reducerInput, rawText, opts.noOmit);
8925
- const compactText = formatInline(classification, reducerInput, summary || "(no output)", facts, opts.noOmit);
8988
+ const compactText = formatInline(
8989
+ classification,
8990
+ reducerInput,
8991
+ summary || "(no output)",
8992
+ facts,
8993
+ opts.noOmit
8994
+ );
8926
8995
  const selectedText = selectInlineText(classification, reducerInput, rawText, compactText, maxInlineChars, compaction, opts.noOmit);
8927
8996
  const clamp = classification.family === "help" || selectedText.text.includes("\n") ? clampTextMiddleWithMetadata : clampTextWithMetadata;
8928
8997
  const inlineText = clamp(selectedText.text, maxInlineChars, opts.noOmit);
@@ -8942,7 +9011,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8942
9011
  opts.storeDir
8943
9012
  ) : void 0;
8944
9013
  if (!opts.store && opts.recordStats) {
8945
- await storeArtifactMetadata(
9014
+ await tryStoreArtifactMetadata(
8946
9015
  {
8947
9016
  input: normalizedInput,
8948
9017
  rawText,
@@ -9048,7 +9117,7 @@ async function compactBashResult(input) {
9048
9117
  const options = {
9049
9118
  ...typeof input.cwd === "string" && input.cwd.trim() ? { cwd: input.cwd } : {},
9050
9119
  ...typeof input.maxInlineChars === "number" ? { maxInlineChars: input.maxInlineChars } : {},
9051
- ...readNoOmissionFromEnv() || input.noOmit ? { noOmit: true } : {},
9120
+ ...input.noOmit || !input.allowOmit && readNoOmissionFromEnv() ? { noOmit: true } : {},
9052
9121
  recordStats: true,
9053
9122
  ...input.storeRaw ? { store: true } : {}
9054
9123
  };
@@ -1325,6 +1325,9 @@ var TRUNCATION_SUFFIX = "\n... truncated ...";
1325
1325
  var MIDDLE_TRUNCATION_MARKER = "\n... omitted ...\n";
1326
1326
  var COMBINING_MARK_PATTERN = new RegExp("\\p{Mark}", "u");
1327
1327
  var EMOJI_PATTERN = new RegExp("\\p{Extended_Pictographic}", "u");
1328
+ var FLAG_EMOJI_PATTERN = new RegExp("^\\p{Regional_Indicator}{2}$", "u");
1329
+ var KEYCAP_EMOJI_PATTERN = /^[#*0-9]\uFE0F?\u20E3$/u;
1330
+ var REPEATED_EMOJI_BANNER_MIN_REPETITIONS = 24;
1328
1331
  var graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : null;
1329
1332
  function graphemes(text) {
1330
1333
  if (!graphemeSegmenter) {
@@ -1378,6 +1381,28 @@ function dedupeAdjacent(lines) {
1378
1381
  }
1379
1382
  return next;
1380
1383
  }
1384
+ function formatCodePoints(text) {
1385
+ return Array.from(text, (character) => `U+${character.codePointAt(0)?.toString(16).toUpperCase().padStart(4, "0")}`).join("+");
1386
+ }
1387
+ function isEmojiGrapheme(text) {
1388
+ return EMOJI_PATTERN.test(text) || FLAG_EMOJI_PATTERN.test(text) || KEYCAP_EMOJI_PATTERN.test(text);
1389
+ }
1390
+ function collapseRepeatedEmojiBanner(lines) {
1391
+ let collapsed = false;
1392
+ const nextLines = lines.map((line2) => {
1393
+ const visibleSegments = graphemes(line2).filter((segment) => !/^\s+$/u.test(segment));
1394
+ const repeatedEmoji = visibleSegments[0];
1395
+ if (visibleSegments.length < REPEATED_EMOJI_BANNER_MIN_REPETITIONS || !repeatedEmoji || !isEmojiGrapheme(repeatedEmoji) || visibleSegments.some((segment) => segment !== repeatedEmoji)) {
1396
+ return line2;
1397
+ }
1398
+ collapsed = true;
1399
+ return `[repeated emoji banner omitted: ${formatCodePoints(repeatedEmoji)} x${visibleSegments.length}]`;
1400
+ });
1401
+ return collapsed ? {
1402
+ lines: nextLines,
1403
+ compaction: createCompactionMetadata("repeated-emoji-banner-omission")
1404
+ } : { lines: nextLines };
1405
+ }
1381
1406
  function headTail(lines, head, tail, noOmit = false) {
1382
1407
  const safeHead = Math.max(0, head);
1383
1408
  const safeTail = Math.max(0, tail);
@@ -7705,6 +7730,23 @@ function resolveArtifactSource(input) {
7705
7730
  // src/core/artifacts.ts
7706
7731
  var ARTIFACT_ID_PATTERN = /^tj_[0-9a-f-]{12}$/iu;
7707
7732
  var ARTIFACT_DIR_ENV = "TOKENJUICE_ARTIFACT_DIR";
7733
+ var OPTIONAL_METADATA_STORAGE_ERROR_CODES = /* @__PURE__ */ new Set([
7734
+ "EACCES",
7735
+ "EDQUOT",
7736
+ "EEXIST",
7737
+ "EFBIG",
7738
+ "EIO",
7739
+ "EISDIR",
7740
+ "ELOOP",
7741
+ "EMFILE",
7742
+ "ENAMETOOLONG",
7743
+ "ENFILE",
7744
+ "ENOENT",
7745
+ "ENOSPC",
7746
+ "ENOTDIR",
7747
+ "EPERM",
7748
+ "EROFS"
7749
+ ]);
7708
7750
  function extractCaptureTruncatedFlag(input) {
7709
7751
  const value = input.metadata?.tokenjuiceCaptureTruncated;
7710
7752
  return typeof value === "boolean" ? value : void 0;
@@ -7790,6 +7832,17 @@ async function storeArtifactMetadata(input, storeDir) {
7790
7832
  metadata
7791
7833
  };
7792
7834
  }
7835
+ async function tryStoreArtifactMetadata(input, storeDir) {
7836
+ try {
7837
+ return await storeArtifactMetadata(input, storeDir);
7838
+ } catch (error) {
7839
+ const code = error.code;
7840
+ if (typeof code !== "string" || !OPTIONAL_METADATA_STORAGE_ERROR_CODES.has(code)) {
7841
+ throw error;
7842
+ }
7843
+ return void 0;
7844
+ }
7845
+ }
7793
7846
 
7794
7847
  // src/core/github-actions-summary.ts
7795
7848
  var GITHUB_ACTIONS_EXIT_PATTERN = /^Error: Process completed with exit code (\d+)\.?$/u;
@@ -8463,6 +8516,7 @@ function isGithubCliCommand(command) {
8463
8516
  var TINY_OUTPUT_MAX_CHARS = 240;
8464
8517
  var SMALL_OUTPUT_PASSTHROUGH_MIN_SAVED_CHARS = 120;
8465
8518
  var SMALL_OUTPUT_PASSTHROUGH_MAX_RATIO = 0.75;
8519
+ var FAILURE_SEVERITY_FACTS = /* @__PURE__ */ new Set(["error", "warning"]);
8466
8520
  function buildRawText(input) {
8467
8521
  if (input.combinedText) {
8468
8522
  return input.combinedText;
@@ -8503,6 +8557,12 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8503
8557
  if (rule.transforms?.stripAnsi) {
8504
8558
  lines = normalizeLines(stripAnsi(lines.join("\n")));
8505
8559
  }
8560
+ let rewriteCompaction;
8561
+ if (!noOmit && rule.id === "generic/fallback") {
8562
+ const collapsed = collapseRepeatedEmojiBanner(lines);
8563
+ lines = collapsed.lines;
8564
+ rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, collapsed.compaction);
8565
+ }
8506
8566
  const outputMatchText = trimEmptyEdges(lines).join("\n");
8507
8567
  const matchedOutput = compiledRule.compiled.outputMatches.find((entry) => entry.pattern.test(outputMatchText));
8508
8568
  if (!noOmit && matchedOutput) {
@@ -8535,7 +8595,6 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
8535
8595
  lines = rewriteGitStatusLines(lines);
8536
8596
  }
8537
8597
  const preRewriteLines = [...lines];
8538
- let rewriteCompaction;
8539
8598
  if (rule.id === "cloud/gh") {
8540
8599
  counterLines = rewriteGhLines(counterLines, input, noOmit).lines;
8541
8600
  const rewritten = rewriteGhLines(lines, input, noOmit);
@@ -8628,7 +8687,11 @@ function isTerseDiscoveryCommand(classification, input) {
8628
8687
  return false;
8629
8688
  }
8630
8689
  function formatInline(classification, input, summary, facts, noOmit = false) {
8631
- const factParts = Object.entries(facts).filter(([, count]) => count > 0).map(([name, count]) => pluralize(count, name));
8690
+ const neutralizeSeverityFacts = classification.matchedReducer === "generic/fallback" && input.exitCode === 0;
8691
+ const factParts = Object.entries(facts).filter(([, count]) => count > 0).map(([name, count]) => pluralize(
8692
+ count,
8693
+ neutralizeSeverityFacts && FAILURE_SEVERITY_FACTS.has(name) ? `${name} mention` : name
8694
+ ));
8632
8695
  const lines = [];
8633
8696
  if (input.exitCode && input.exitCode !== 0) {
8634
8697
  lines.push(`exit ${input.exitCode}`);
@@ -8732,7 +8795,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8732
8795
  opts.storeDir
8733
8796
  ) : void 0;
8734
8797
  if (!opts.store && opts.recordStats) {
8735
- await storeArtifactMetadata(
8798
+ await tryStoreArtifactMetadata(
8736
8799
  {
8737
8800
  input: normalizedInput,
8738
8801
  rawText,
@@ -8784,7 +8847,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8784
8847
  opts.storeDir
8785
8848
  ) : void 0;
8786
8849
  if (!opts.store && opts.recordStats) {
8787
- await storeArtifactMetadata(
8850
+ await tryStoreArtifactMetadata(
8788
8851
  {
8789
8852
  input: normalizedInput,
8790
8853
  rawText,
@@ -8806,7 +8869,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8806
8869
  }
8807
8870
  if (classification.matchedReducer === "generic/fallback" && isFileContentInspectionCommand(normalizedInput)) {
8808
8871
  if (!opts.store && opts.recordStats) {
8809
- await storeArtifactMetadata(
8872
+ await tryStoreArtifactMetadata(
8810
8873
  {
8811
8874
  input: normalizedInput,
8812
8875
  rawText,
@@ -8855,7 +8918,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8855
8918
  opts.storeDir
8856
8919
  ) : void 0;
8857
8920
  if (!opts.store && opts.recordStats) {
8858
- await storeArtifactMetadata(
8921
+ await tryStoreArtifactMetadata(
8859
8922
  {
8860
8923
  input: normalizedInput,
8861
8924
  rawText,
@@ -8901,7 +8964,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8901
8964
  opts.storeDir
8902
8965
  ) : void 0;
8903
8966
  if (!opts.store && opts.recordStats) {
8904
- await storeArtifactMetadata(
8967
+ await tryStoreArtifactMetadata(
8905
8968
  {
8906
8969
  input: normalizedInput,
8907
8970
  rawText,
@@ -8922,7 +8985,13 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8922
8985
  }
8923
8986
  }
8924
8987
  const { summary, facts, compaction } = applyRule(matchedRule, reducerInput, rawText, opts.noOmit);
8925
- const compactText = formatInline(classification, reducerInput, summary || "(no output)", facts, opts.noOmit);
8988
+ const compactText = formatInline(
8989
+ classification,
8990
+ reducerInput,
8991
+ summary || "(no output)",
8992
+ facts,
8993
+ opts.noOmit
8994
+ );
8926
8995
  const selectedText = selectInlineText(classification, reducerInput, rawText, compactText, maxInlineChars, compaction, opts.noOmit);
8927
8996
  const clamp = classification.family === "help" || selectedText.text.includes("\n") ? clampTextMiddleWithMetadata : clampTextWithMetadata;
8928
8997
  const inlineText = clamp(selectedText.text, maxInlineChars, opts.noOmit);
@@ -8942,7 +9011,7 @@ async function reduceExecutionWithRules(input, rules, opts = {}) {
8942
9011
  opts.storeDir
8943
9012
  ) : void 0;
8944
9013
  if (!opts.store && opts.recordStats) {
8945
- await storeArtifactMetadata(
9014
+ await tryStoreArtifactMetadata(
8946
9015
  {
8947
9016
  input: normalizedInput,
8948
9017
  rawText,
@@ -9048,7 +9117,7 @@ async function compactBashResult(input) {
9048
9117
  const options = {
9049
9118
  ...typeof input.cwd === "string" && input.cwd.trim() ? { cwd: input.cwd } : {},
9050
9119
  ...typeof input.maxInlineChars === "number" ? { maxInlineChars: input.maxInlineChars } : {},
9051
- ...readNoOmissionFromEnv() || input.noOmit ? { noOmit: true } : {},
9120
+ ...input.noOmit || !input.allowOmit && readNoOmissionFromEnv() ? { noOmit: true } : {},
9052
9121
  recordStats: true,
9053
9122
  ...input.storeRaw ? { store: true } : {}
9054
9123
  };
@@ -1,3 +1,21 @@
1
+ export type HookCommandRuntimeMismatch = {
2
+ configuredPath: string;
3
+ expectedPath: string;
4
+ };
5
+ export type HookCommandPackageVersionMismatch = {
6
+ launcherPath: string;
7
+ resolvedPath: string;
8
+ resolvedVersion: string;
9
+ expectedVersion: string;
10
+ };
11
+ export type HookCommandInspection = {
12
+ checkedPaths: string[];
13
+ missingPaths: string[];
14
+ nonExecutablePaths: string[];
15
+ runtimePath?: string;
16
+ runtimeMismatch?: HookCommandRuntimeMismatch;
17
+ packageVersionMismatch?: HookCommandPackageVersionMismatch;
18
+ };
1
19
  export type HookCommandDoctorStatus = "ok" | "broken" | "disabled";
2
20
  export type HookCommandDoctorFields = {
3
21
  status: HookCommandDoctorStatus;
@@ -9,6 +27,12 @@ export type HookCommandDoctorFields = {
9
27
  checkedPaths: string[];
10
28
  missingPaths: string[];
11
29
  };
30
+ export declare function inspectTokenjuiceHookCommand(options: {
31
+ command: string;
32
+ expectedNodePath?: string;
33
+ expectedPackageVersion?: string;
34
+ platform?: NodeJS.Platform;
35
+ }): Promise<HookCommandInspection>;
12
36
  export declare function buildHookCommandDoctorFields(options: {
13
37
  expectedCommand: string;
14
38
  detectedCommand: string | undefined;
@@ -1,4 +1,83 @@
1
- import { findMissingHookCommandPaths } from "./host-command.js";
1
+ import { realpath } from "node:fs/promises";
2
+ import { isAbsolute } from "node:path";
3
+ import { findMissingHookCommandPaths, isExecutableFile, parseTokenjuiceHookCommand, pathExists, } from "./host-command.js";
4
+ function extractHomebrewCellarVersion(path) {
5
+ const normalized = path.replace(/\\/gu, "/");
6
+ return normalized.match(/\/Cellar\/tokenjuice\/([^/]+)\//u)?.[1];
7
+ }
8
+ async function pathsResolveToSameFile(left, right) {
9
+ if (left === right) {
10
+ return true;
11
+ }
12
+ try {
13
+ return await realpath(left) === await realpath(right);
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ async function isNodeInvokedJavaScriptLauncher(path, runtimePath, launcherPath) {
20
+ if (!runtimePath || path !== launcherPath) {
21
+ return false;
22
+ }
23
+ try {
24
+ return (await realpath(path)).endsWith(".js");
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ }
30
+ export async function inspectTokenjuiceHookCommand(options) {
31
+ const parsed = parseTokenjuiceHookCommand(options.command, options.platform);
32
+ const missingPaths = await findMissingHookCommandPaths(options.command, options.platform);
33
+ const nonExecutablePaths = [];
34
+ for (const path of parsed.checkedPaths) {
35
+ if (missingPaths.includes(path)
36
+ || path.endsWith(".js")
37
+ || await isNodeInvokedJavaScriptLauncher(path, parsed.runtimePath, parsed.launcherPath)) {
38
+ continue;
39
+ }
40
+ if (!(await isExecutableFile(path))) {
41
+ nonExecutablePaths.push(path);
42
+ }
43
+ }
44
+ let runtimeMismatch;
45
+ if (parsed.runtimePath
46
+ && options.expectedNodePath
47
+ && isAbsolute(parsed.runtimePath)
48
+ && !(await pathsResolveToSameFile(parsed.runtimePath, options.expectedNodePath))) {
49
+ runtimeMismatch = {
50
+ configuredPath: parsed.runtimePath,
51
+ expectedPath: options.expectedNodePath,
52
+ };
53
+ }
54
+ let packageVersionMismatch;
55
+ if (parsed.launcherPath && options.expectedPackageVersion && await pathExists(parsed.launcherPath)) {
56
+ try {
57
+ const resolvedPath = await realpath(parsed.launcherPath);
58
+ const resolvedVersion = extractHomebrewCellarVersion(resolvedPath);
59
+ if (resolvedVersion && resolvedVersion !== options.expectedPackageVersion) {
60
+ packageVersionMismatch = {
61
+ launcherPath: parsed.launcherPath,
62
+ resolvedPath,
63
+ resolvedVersion,
64
+ expectedVersion: options.expectedPackageVersion,
65
+ };
66
+ }
67
+ }
68
+ catch {
69
+ // Missing and unreadable paths are reported separately.
70
+ }
71
+ }
72
+ return {
73
+ checkedPaths: parsed.checkedPaths,
74
+ missingPaths,
75
+ nonExecutablePaths,
76
+ ...(parsed.runtimePath ? { runtimePath: parsed.runtimePath } : {}),
77
+ ...(runtimeMismatch ? { runtimeMismatch } : {}),
78
+ ...(packageVersionMismatch ? { packageVersionMismatch } : {}),
79
+ };
80
+ }
2
81
  export async function buildHookCommandDoctorFields(options) {
3
82
  if (!options.detectedCommand) {
4
83
  return {
@@ -1,5 +1,24 @@
1
1
  export declare function isTokenjuiceExecutablePath(value: string): boolean;
2
2
  export declare function shellQuote(value: string, platform?: NodeJS.Platform): string;
3
+ /**
4
+ * Quote a value for a POSIX shell, regardless of the host platform.
5
+ *
6
+ * `shellQuote` picks its quoting style from `process.platform`, which is the
7
+ * right question for a *path* going into a host config file: on win32 it wraps
8
+ * in double quotes without escaping, and that is safe because a Windows path
9
+ * cannot contain `"` in the first place.
10
+ *
11
+ * It is the wrong question for a *command* that we are about to hand to a
12
+ * POSIX shell via `-lc`. There the parser is the shell we resolved, not the
13
+ * platform we happen to be running on, and user commands routinely contain
14
+ * quotes. Wrapping `git commit -m "fix: thing"` in bare double quotes on
15
+ * Windows yields `-lc "git commit -m "fix: thing""`, which bash re-splits into
16
+ * `git commit -m fix: thing` -- a different command, silently.
17
+ *
18
+ * Callers building a command line that a POSIX shell will parse must use this
19
+ * for every argv item, including Windows paths and the `-lc` payload.
20
+ */
21
+ export declare function posixShellQuote(value: string): string;
3
22
  export declare function parseShellWords(command: string, platform?: NodeJS.Platform): string[];
4
23
  export declare function isNodeExecutablePath(value: string): boolean;
5
24
  export declare function extractHookCommandPaths(command: string, platform?: NodeJS.Platform): string[];
@@ -26,6 +26,30 @@ export function shellQuote(value, platform = process.platform) {
26
26
  if (platform === "win32") {
27
27
  return `"${value}"`;
28
28
  }
29
+ return posixShellQuote(value);
30
+ }
31
+ /**
32
+ * Quote a value for a POSIX shell, regardless of the host platform.
33
+ *
34
+ * `shellQuote` picks its quoting style from `process.platform`, which is the
35
+ * right question for a *path* going into a host config file: on win32 it wraps
36
+ * in double quotes without escaping, and that is safe because a Windows path
37
+ * cannot contain `"` in the first place.
38
+ *
39
+ * It is the wrong question for a *command* that we are about to hand to a
40
+ * POSIX shell via `-lc`. There the parser is the shell we resolved, not the
41
+ * platform we happen to be running on, and user commands routinely contain
42
+ * quotes. Wrapping `git commit -m "fix: thing"` in bare double quotes on
43
+ * Windows yields `-lc "git commit -m "fix: thing""`, which bash re-splits into
44
+ * `git commit -m fix: thing` -- a different command, silently.
45
+ *
46
+ * Callers building a command line that a POSIX shell will parse must use this
47
+ * for every argv item, including Windows paths and the `-lc` payload.
48
+ */
49
+ export function posixShellQuote(value) {
50
+ if (POSIX_SAFE_SHELL_WORD.test(value)) {
51
+ return value;
52
+ }
29
53
  return `'${value.replace(/'/gu, `'\\''`)}'`;
30
54
  }
31
55
  export function parseShellWords(command, platform = process.platform) {
@@ -33,18 +57,46 @@ export function parseShellWords(command, platform = process.platform) {
33
57
  let current = "";
34
58
  let quote = null;
35
59
  let escaping = false;
36
- for (const char of command) {
60
+ const chars = [...command];
61
+ for (let index = 0; index < chars.length; index += 1) {
62
+ const char = chars[index];
63
+ if (quote === "'") {
64
+ if (char === "'") {
65
+ quote = null;
66
+ }
67
+ else {
68
+ current += char;
69
+ }
70
+ continue;
71
+ }
37
72
  if (escaping) {
38
73
  current += char;
39
74
  escaping = false;
40
75
  continue;
41
76
  }
42
- if (platform !== "win32" && char === "\\") {
43
- escaping = true;
77
+ if (char === "\\") {
78
+ if (platform === "win32") {
79
+ current += char;
80
+ }
81
+ else if (chars[index + 1] === "\n") {
82
+ index += 1;
83
+ }
84
+ else if (quote === "\"") {
85
+ const next = chars[index + 1];
86
+ if (next === "$" || next === "`" || next === "\"" || next === "\\") {
87
+ escaping = true;
88
+ }
89
+ else {
90
+ current += char;
91
+ }
92
+ }
93
+ else {
94
+ escaping = true;
95
+ }
44
96
  continue;
45
97
  }
46
- if (quote) {
47
- if (char === quote) {
98
+ if (quote === "\"") {
99
+ if (char === "\"") {
48
100
  quote = null;
49
101
  }
50
102
  else {
@@ -87,7 +139,10 @@ export function extractHookCommandPaths(command, platform = process.platform) {
87
139
  paths.add(first);
88
140
  }
89
141
  const second = argv[1];
90
- if (first && second && isNodeExecutablePath(first) && second.endsWith(".js")) {
142
+ if (first
143
+ && second
144
+ && isNodeExecutablePath(first)
145
+ && (second.endsWith(".js") || isTokenjuiceExecutablePath(second))) {
91
146
  paths.add(second);
92
147
  }
93
148
  return [...paths];
@@ -54,6 +54,7 @@ import type { GitLabDuoDoctorReport, GitLabDuoRuleOptions } from "../gitlab-duo/
54
54
  import type { GooseDoctorReport, GooseHintsOptions } from "../goose/index.js";
55
55
  import type { GreptileDoctorReport, GreptileRuleOptions } from "../greptile/index.js";
56
56
  import type { GrokBuildDoctorReport, GrokBuildInstructionsOptions } from "../grok-build/index.js";
57
+ import type { GrokBotDoctorReport, GrokBotRuleOptions } from "../grok-bot/index.js";
57
58
  import type { GrokCliDoctorReport, GrokCliHookCommandOptions } from "../grok-cli/index.js";
58
59
  import type { GptmeDoctorReport, GptmeInstructionsOptions } from "../gptme/index.js";
59
60
  import type { Jean2DoctorReport, Jean2InstructionsOptions } from "../jean2/index.js";
@@ -153,6 +154,7 @@ export type HookIntegrationDoctorReport = {
153
154
  goose: GooseDoctorReport;
154
155
  greptile: GreptileDoctorReport;
155
156
  "grok-build": GrokBuildDoctorReport;
157
+ "grok-bot": GrokBotDoctorReport;
156
158
  "grok-cli": GrokCliDoctorReport;
157
159
  gptme: GptmeDoctorReport;
158
160
  jean2: Jean2DoctorReport;
@@ -201,7 +203,7 @@ export type HookDoctorReport = {
201
203
  status: HookHealthStatus;
202
204
  integrations: HookIntegrationDoctorReport;
203
205
  };
204
- export type HookDoctorCommandOptions = AdalInstructionsOptions & AetherPromptOptions & AictlInstructionsOptions & AiMemoryProtocolOptions & AgentLayerInstructionsOptions & AgentInitInstructionsOptions & AgentlinkInstructionsOptions & AgentloomRuleOptions & AgentsCliMemoryOptions & AgentsMdInstructionsOptions & AgentsGeRuleOptions & AgentsMeshRuleOptions & AmazonQRuleOptions & AmpInstructionsOptions & AntigravityRuleOptions & AnywhereAgentsInstructionsOptions & AugmentRuleOptions & BazSkillOptions & BitoGuidelinesOptions & BlackboxSkillOptions & BlocksSkillOptions & ClawdbotSkillOptions & BobInstructionsOptions & BuilderRuleOptions & CharlieInstructionsOptions & CodeAntInstructionsOptions & CodebuffInstructionsOptions & CodegenInstructionsOptions & CommandCodeHookCommandOptions & CoderAgentsSkillOptions & CodeRabbitConfigOptions & DeepAgentsInstructionsOptions & DockerAgentPromptOptions & DotAgentsRuleOptions & EcaSkillOptions & ElyraSkillOptions & LocalCodePluginOptions & MiniSweAgentConfigOptions & SweAgentConfigOptions & StagewiseSkillOptions & PiGoSkillOptions & CodexHookCommandOptions & ClaudeCodeHookCommandOptions & CodeBuddyHookCommandOptions & CopilotAgentHookCommandOptions & CrushSkillOptions & DevinHookCommandOptions & DroidHookCommandOptions & FirebaseStudioRuleOptions & ForgeCodeInstructionsOptions & GitLabDuoRuleOptions & GooseHintsOptions & GreptileRuleOptions & GrokBuildInstructionsOptions & GrokCliHookCommandOptions & GptmeInstructionsOptions & Jean2InstructionsOptions & JetBrainsAiRuleOptions & JulesInstructionsOptions & KimiHookCommandOptions & KnownsInstructionsOptions & LeanCtlInstructionsOptions & McpAgentDefinitionOptions & MistralVibeInstructionsOptions & MuxHookCommandOptions & NovaKitInstructionsOptions & OnaSkillOptions & OpenInterpreterInstructionsOptions & OpenWebUIToolOptions & PlandexConventionOptions & QodoReviewConfigOptions & QoderInstructionsOptions & QwenCodeHookCommandOptions & ReplitInstructionsOptions & RovoInstructionsOptions & RulerRuleOptions & TabbySystemPromptOptions & TabnineInstructionsOptions & TraeRuleOptions & UiPathInstructionsOptions & WarpInstructionsOptions & ZencoderRuleOptions;
206
+ export type HookDoctorCommandOptions = AdalInstructionsOptions & AetherPromptOptions & AictlInstructionsOptions & AiMemoryProtocolOptions & AgentLayerInstructionsOptions & AgentInitInstructionsOptions & AgentlinkInstructionsOptions & AgentloomRuleOptions & AgentsCliMemoryOptions & AgentsMdInstructionsOptions & AgentsGeRuleOptions & AgentsMeshRuleOptions & AmazonQRuleOptions & AmpInstructionsOptions & AntigravityRuleOptions & AnywhereAgentsInstructionsOptions & AugmentRuleOptions & BazSkillOptions & BitoGuidelinesOptions & BlackboxSkillOptions & BlocksSkillOptions & ClawdbotSkillOptions & BobInstructionsOptions & BuilderRuleOptions & CharlieInstructionsOptions & CodeAntInstructionsOptions & CodebuffInstructionsOptions & CodegenInstructionsOptions & CommandCodeHookCommandOptions & CoderAgentsSkillOptions & CodeRabbitConfigOptions & DeepAgentsInstructionsOptions & DockerAgentPromptOptions & DotAgentsRuleOptions & EcaSkillOptions & ElyraSkillOptions & LocalCodePluginOptions & MiniSweAgentConfigOptions & SweAgentConfigOptions & StagewiseSkillOptions & PiGoSkillOptions & CodexHookCommandOptions & ClaudeCodeHookCommandOptions & CodeBuddyHookCommandOptions & CopilotAgentHookCommandOptions & CrushSkillOptions & DevinHookCommandOptions & DroidHookCommandOptions & FirebaseStudioRuleOptions & ForgeCodeInstructionsOptions & GitLabDuoRuleOptions & GooseHintsOptions & GreptileRuleOptions & GrokBuildInstructionsOptions & GrokBotRuleOptions & GrokCliHookCommandOptions & GptmeInstructionsOptions & Jean2InstructionsOptions & JetBrainsAiRuleOptions & JulesInstructionsOptions & KimiHookCommandOptions & KnownsInstructionsOptions & LeanCtlInstructionsOptions & McpAgentDefinitionOptions & MistralVibeInstructionsOptions & MuxHookCommandOptions & NovaKitInstructionsOptions & OnaSkillOptions & OpenInterpreterInstructionsOptions & OpenWebUIToolOptions & PlandexConventionOptions & QodoReviewConfigOptions & QoderInstructionsOptions & QwenCodeHookCommandOptions & ReplitInstructionsOptions & RovoInstructionsOptions & RulerRuleOptions & TabbySystemPromptOptions & TabnineInstructionsOptions & TraeRuleOptions & UiPathInstructionsOptions & WarpInstructionsOptions & ZencoderRuleOptions;
205
207
  export type HookIntegrationDoctorEntry = [
206
208
  keyof HookIntegrationDoctorReport,
207
209
  HookIntegrationDoctorReport[keyof HookIntegrationDoctorReport]