@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,6 @@
1
1
  import { getInspectionCommandSkipReason, getSafeRepositoryInventorySourceArgv } from "../inventory-safety.js";
2
2
  import { readNoOmissionFromEnv } from "../env.js";
3
+ import { shouldRecordStats } from "../artifacts.js";
3
4
  import { buildInspectionSummary } from "../reduce-inspection-summary.js";
4
5
  import { reduceExecution } from "../reduce.js";
5
6
  import { getCompactionSkipReason } from "./rewrite-policy.js";
@@ -61,8 +62,8 @@ export async function compactBashResult(input) {
61
62
  const options = {
62
63
  ...(typeof input.cwd === "string" && input.cwd.trim() ? { cwd: input.cwd } : {}),
63
64
  ...(typeof input.maxInlineChars === "number" ? { maxInlineChars: input.maxInlineChars } : {}),
64
- ...(readNoOmissionFromEnv() || input.noOmit ? { noOmit: true } : {}),
65
- recordStats: true,
65
+ ...(input.noOmit || (!input.allowOmit && readNoOmissionFromEnv()) ? { noOmit: true } : {}),
66
+ recordStats: input.recordStats ?? shouldRecordStats(),
66
67
  ...(input.storeRaw ? { store: true } : {}),
67
68
  };
68
69
  const result = await reduceExecution(executionInput, options);
@@ -3,8 +3,8 @@ import { hasMultipleSubstantiveShellCommands } from "./command-match.js";
3
3
  import { classifyExecution, resolveRuleMatch } from "./classify.js";
4
4
  import { isFileContentInspectionCommand, isVerbatimConfigInspectionCommand } from "./command-identity.js";
5
5
  import { normalizeExecutionInput } from "./execution-input.js";
6
- import { clampTextMiddleWithMetadata, clampTextWithMetadata, countTextChars, dedupeAdjacent, headTail, normalizeLines, pluralize, stripAnsi, trimEmptyEdges } from "./text.js";
7
- import { storeArtifact, storeArtifactMetadata } from "./artifacts.js";
6
+ import { clampTextMiddleWithMetadata, clampTextWithMetadata, collapseRepeatedEmojiBanner, countTextChars, dedupeAdjacent, headTail, normalizeLines, pluralize, stripAnsi, trimEmptyEdges } from "./text.js";
7
+ import { storeArtifact, tryStoreArtifactMetadata } from "./artifacts.js";
8
8
  import { NO_COMPACTION_METADATA, mergeCompactionMetadata } from "./compaction-metadata.js";
9
9
  import { buildGithubActionsFailureSummary } from "./github-actions-summary.js";
10
10
  import { rewriteGhLines, rewriteGitDiffLines, rewriteGitStatusLines, rewriteSearchLines } from "./reduce-formatters.js";
@@ -13,6 +13,7 @@ import { compactWholeJsonText } from "./reduce-utils.js";
13
13
  const TINY_OUTPUT_MAX_CHARS = 240;
14
14
  const SMALL_OUTPUT_PASSTHROUGH_MIN_SAVED_CHARS = 120;
15
15
  const SMALL_OUTPUT_PASSTHROUGH_MAX_RATIO = 0.75;
16
+ const FAILURE_SEVERITY_FACTS = new Set(["error", "warning"]);
16
17
  function buildRawText(input) {
17
18
  if (input.combinedText) {
18
19
  return input.combinedText;
@@ -53,6 +54,12 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
53
54
  if (rule.transforms?.stripAnsi) {
54
55
  lines = normalizeLines(stripAnsi(lines.join("\n")));
55
56
  }
57
+ let rewriteCompaction;
58
+ if (!noOmit && rule.id === "generic/fallback") {
59
+ const collapsed = collapseRepeatedEmojiBanner(lines);
60
+ lines = collapsed.lines;
61
+ rewriteCompaction = mergeCompactionMetadata(rewriteCompaction, collapsed.compaction);
62
+ }
56
63
  const outputMatchText = trimEmptyEdges(lines).join("\n");
57
64
  const matchedOutput = compiledRule.compiled.outputMatches.find((entry) => entry.pattern.test(outputMatchText));
58
65
  if (!noOmit && matchedOutput) {
@@ -85,7 +92,6 @@ function applyRule(compiledRule, input, rawText, noOmit = false) {
85
92
  lines = rewriteGitStatusLines(lines);
86
93
  }
87
94
  const preRewriteLines = [...lines];
88
- let rewriteCompaction;
89
95
  if (rule.id === "cloud/gh") {
90
96
  counterLines = rewriteGhLines(counterLines, input, noOmit).lines;
91
97
  const rewritten = rewriteGhLines(lines, input, noOmit);
@@ -179,9 +185,11 @@ function isTerseDiscoveryCommand(classification, input) {
179
185
  return false;
180
186
  }
181
187
  function formatInline(classification, input, summary, facts, noOmit = false) {
188
+ const neutralizeSeverityFacts = classification.matchedReducer === "generic/fallback"
189
+ && input.exitCode === 0;
182
190
  const factParts = Object.entries(facts)
183
191
  .filter(([, count]) => count > 0)
184
- .map(([name, count]) => pluralize(count, name));
192
+ .map(([name, count]) => pluralize(count, neutralizeSeverityFacts && FAILURE_SEVERITY_FACTS.has(name) ? `${name} mention` : name));
185
193
  const lines = [];
186
194
  if (input.exitCode && input.exitCode !== 0) {
187
195
  lines.push(`exit ${input.exitCode}`);
@@ -294,6 +302,7 @@ export async function reduceExecutionWithRules(input, rules, opts = {}) {
294
302
  input: normalizedInput,
295
303
  rawText,
296
304
  classification,
305
+ ...(opts.recordStats !== undefined ? { recordStats: opts.recordStats } : {}),
297
306
  stats: {
298
307
  rawChars: measuredRawChars,
299
308
  reducedChars: measuredRawChars,
@@ -302,7 +311,7 @@ export async function reduceExecutionWithRules(input, rules, opts = {}) {
302
311
  }, opts.storeDir)
303
312
  : undefined;
304
313
  if (!opts.store && opts.recordStats) {
305
- await storeArtifactMetadata({
314
+ await tryStoreArtifactMetadata({
306
315
  input: normalizedInput,
307
316
  rawText,
308
317
  classification,
@@ -348,11 +357,12 @@ export async function reduceExecutionWithRules(input, rules, opts = {}) {
348
357
  input: normalizedInput,
349
358
  rawText,
350
359
  classification: summaryClassification,
360
+ ...(opts.recordStats !== undefined ? { recordStats: opts.recordStats } : {}),
351
361
  stats,
352
362
  }, opts.storeDir)
353
363
  : undefined;
354
364
  if (!opts.store && opts.recordStats) {
355
- await storeArtifactMetadata({
365
+ await tryStoreArtifactMetadata({
356
366
  input: normalizedInput,
357
367
  rawText,
358
368
  classification: summaryClassification,
@@ -371,7 +381,7 @@ export async function reduceExecutionWithRules(input, rules, opts = {}) {
371
381
  }
372
382
  if (classification.matchedReducer === "generic/fallback" && isFileContentInspectionCommand(normalizedInput)) {
373
383
  if (!opts.store && opts.recordStats) {
374
- await storeArtifactMetadata({
384
+ await tryStoreArtifactMetadata({
375
385
  input: normalizedInput,
376
386
  rawText,
377
387
  classification,
@@ -415,11 +425,12 @@ export async function reduceExecutionWithRules(input, rules, opts = {}) {
415
425
  input: normalizedInput,
416
426
  rawText,
417
427
  classification,
428
+ ...(opts.recordStats !== undefined ? { recordStats: opts.recordStats } : {}),
418
429
  stats,
419
430
  }, opts.storeDir)
420
431
  : undefined;
421
432
  if (!opts.store && opts.recordStats) {
422
- await storeArtifactMetadata({
433
+ await tryStoreArtifactMetadata({
423
434
  input: normalizedInput,
424
435
  rawText,
425
436
  classification,
@@ -456,11 +467,12 @@ export async function reduceExecutionWithRules(input, rules, opts = {}) {
456
467
  input: normalizedInput,
457
468
  rawText,
458
469
  classification: jsonClassification,
470
+ ...(opts.recordStats !== undefined ? { recordStats: opts.recordStats } : {}),
459
471
  stats,
460
472
  }, opts.storeDir)
461
473
  : undefined;
462
474
  if (!opts.store && opts.recordStats) {
463
- await storeArtifactMetadata({
475
+ await tryStoreArtifactMetadata({
464
476
  input: normalizedInput,
465
477
  rawText,
466
478
  classification: jsonClassification,
@@ -493,11 +505,12 @@ export async function reduceExecutionWithRules(input, rules, opts = {}) {
493
505
  input: normalizedInput,
494
506
  rawText,
495
507
  classification,
508
+ ...(opts.recordStats !== undefined ? { recordStats: opts.recordStats } : {}),
496
509
  stats,
497
510
  }, opts.storeDir)
498
511
  : undefined;
499
512
  if (!opts.store && opts.recordStats) {
500
- await storeArtifactMetadata({
513
+ await tryStoreArtifactMetadata({
501
514
  input: normalizedInput,
502
515
  rawText,
503
516
  classification,
@@ -6,6 +6,10 @@ export declare function countTerminalCells(text: string): number;
6
6
  export declare function normalizeLines(text: string): string[];
7
7
  export declare function trimEmptyEdges(lines: string[]): string[];
8
8
  export declare function dedupeAdjacent(lines: string[]): string[];
9
+ export declare function collapseRepeatedEmojiBanner(lines: string[]): {
10
+ lines: string[];
11
+ compaction?: CompactionMetadata;
12
+ };
9
13
  export declare function headTail(lines: string[], head: number, tail: number, noOmit?: boolean): {
10
14
  lines: string[];
11
15
  compaction?: CompactionMetadata;
@@ -8,6 +8,9 @@ const TRUNCATION_SUFFIX = "\n... truncated ...";
8
8
  const MIDDLE_TRUNCATION_MARKER = "\n... omitted ...\n";
9
9
  const COMBINING_MARK_PATTERN = /\p{Mark}/u;
10
10
  const EMOJI_PATTERN = /\p{Extended_Pictographic}/u;
11
+ const FLAG_EMOJI_PATTERN = /^\p{Regional_Indicator}{2}$/u;
12
+ const KEYCAP_EMOJI_PATTERN = /^[#*0-9]\uFE0F?\u20E3$/u;
13
+ const REPEATED_EMOJI_BANNER_MIN_REPETITIONS = 24;
11
14
  const graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl
12
15
  ? new Intl.Segmenter(undefined, { granularity: "grapheme" })
13
16
  : null;
@@ -115,6 +118,35 @@ export function dedupeAdjacent(lines) {
115
118
  }
116
119
  return next;
117
120
  }
121
+ function formatCodePoints(text) {
122
+ return Array.from(text, (character) => `U+${character.codePointAt(0)?.toString(16).toUpperCase().padStart(4, "0")}`).join("+");
123
+ }
124
+ function isEmojiGrapheme(text) {
125
+ return EMOJI_PATTERN.test(text)
126
+ || FLAG_EMOJI_PATTERN.test(text)
127
+ || KEYCAP_EMOJI_PATTERN.test(text);
128
+ }
129
+ export function collapseRepeatedEmojiBanner(lines) {
130
+ let collapsed = false;
131
+ const nextLines = lines.map((line) => {
132
+ const visibleSegments = graphemes(line).filter((segment) => !/^\s+$/u.test(segment));
133
+ const repeatedEmoji = visibleSegments[0];
134
+ if (visibleSegments.length < REPEATED_EMOJI_BANNER_MIN_REPETITIONS
135
+ || !repeatedEmoji
136
+ || !isEmojiGrapheme(repeatedEmoji)
137
+ || visibleSegments.some((segment) => segment !== repeatedEmoji)) {
138
+ return line;
139
+ }
140
+ collapsed = true;
141
+ return `[repeated emoji banner omitted: ${formatCodePoints(repeatedEmoji)} x${visibleSegments.length}]`;
142
+ });
143
+ return collapsed
144
+ ? {
145
+ lines: nextLines,
146
+ compaction: createCompactionMetadata("repeated-emoji-banner-omission"),
147
+ }
148
+ : { lines: nextLines };
149
+ }
118
150
  export function headTail(lines, head, tail, noOmit = false) {
119
151
  const safeHead = Math.max(0, head);
120
152
  const safeTail = Math.max(0, tail);
@@ -84,7 +84,7 @@ export async function runWrappedCommand(argv, opts = {}) {
84
84
  raw: opts.raw ?? false,
85
85
  noOmit: opts.noOmit ?? false,
86
86
  trace: opts.trace ?? false,
87
- recordStats: opts.recordStats ?? false,
87
+ ...(opts.recordStats !== undefined ? { recordStats: opts.recordStats } : {}),
88
88
  store: opts.store ?? false,
89
89
  ...(opts.storeDir ? { storeDir: opts.storeDir } : {}),
90
90
  ...(typeof opts.maxInlineChars === "number" ? { maxInlineChars: opts.maxInlineChars } : {}),
@@ -1,8 +1,12 @@
1
+ import type { HookCommandPackageVersionMismatch, HookCommandRuntimeMismatch } from "../shared/hook-command-doctor.js";
2
+ declare const CODEX_HOOK_INTEGRATION_ID = "tokenjuice.post-tool-use";
1
3
  export type InstallCodexHookResult = {
2
4
  hooksPath: string;
3
5
  backupPath?: string;
4
6
  command: string;
5
7
  featureFlag: CodexFeatureFlagStatus;
8
+ writer: "codex-hooks" | "standalone";
9
+ fragmentId: typeof CODEX_HOOK_INTEGRATION_ID;
6
10
  };
7
11
  export type CodexFeatureFlagStatus = {
8
12
  /** Absolute path we looked at (`~/.codex/config.toml` by default). */
@@ -40,6 +44,7 @@ export type CodexHookCommandOptions = {
40
44
  local?: boolean;
41
45
  binaryPath?: string;
42
46
  nodePath?: string;
47
+ noOmit?: boolean;
43
48
  /**
44
49
  * Override for the config.toml consulted when reporting the
45
50
  * `codex_hooks` feature-flag state. Defaults to `~/.codex/config.toml`.
@@ -48,6 +53,16 @@ export type CodexHookCommandOptions = {
48
53
  */
49
54
  featureFlagConfigPath?: string;
50
55
  };
56
+ export type CodexHookCommandDiagnostic = {
57
+ location: string;
58
+ command: string;
59
+ checkedPaths: string[];
60
+ missingPaths: string[];
61
+ nonExecutablePaths: string[];
62
+ runtimePath?: string;
63
+ runtimeMismatch?: HookCommandRuntimeMismatch;
64
+ packageVersionMismatch?: HookCommandPackageVersionMismatch;
65
+ };
51
66
  export type CodexDoctorReport = {
52
67
  hooksPath: string;
53
68
  status: "ok" | "warn" | "broken" | "disabled";
@@ -55,8 +70,17 @@ export type CodexDoctorReport = {
55
70
  fixCommand: string;
56
71
  expectedCommand: string;
57
72
  detectedCommand?: string;
73
+ detectedCommands: CodexHookCommandDiagnostic[];
74
+ duplicateHookCount: number;
58
75
  checkedPaths: string[];
59
76
  missingPaths: string[];
77
+ nonExecutablePaths: string[];
78
+ runtimeMismatches: Array<HookCommandRuntimeMismatch & {
79
+ location: string;
80
+ }>;
81
+ packageVersionMismatches: Array<HookCommandPackageVersionMismatch & {
82
+ location: string;
83
+ }>;
60
84
  featureFlag: CodexFeatureFlagStatus;
61
85
  runtimeConfig: CodexRuntimeConfigStatus;
62
86
  };
@@ -64,6 +88,8 @@ export type UninstallCodexHookResult = {
64
88
  hooksPath: string;
65
89
  backupPath?: string;
66
90
  removed: number;
91
+ writer: "codex-hooks" | "standalone";
92
+ fragmentId: typeof CODEX_HOOK_INTEGRATION_ID;
67
93
  };
68
94
  /**
69
95
  * Read-only scan of ~/.codex/config.toml for the modern `hooks = <bool>`
@@ -90,4 +116,8 @@ export declare function inspectCodexRuntimeConfig(configPath?: string): Promise<
90
116
  export declare function installCodexHook(hooksPath?: string, options?: CodexHookCommandOptions): Promise<InstallCodexHookResult>;
91
117
  export declare function uninstallCodexHook(hooksPath?: string): Promise<UninstallCodexHookResult>;
92
118
  export declare function doctorCodexHook(hooksPath?: string, options?: CodexHookCommandOptions): Promise<CodexDoctorReport>;
93
- export declare function runCodexPostToolUseHook(rawText: string): Promise<number>;
119
+ export declare function runCodexPostToolUseHook(rawText: string, options?: {
120
+ noOmit?: boolean;
121
+ allowOmit?: boolean;
122
+ }): Promise<number>;
123
+ export {};