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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/node_modules/tokenjuice/README.md +133 -6
  2. package/node_modules/tokenjuice/dist/cli/main.d.ts +1 -2
  3. package/node_modules/tokenjuice/dist/cli/main.js +3 -18
  4. package/node_modules/tokenjuice/dist/core/analysis.js +7 -10
  5. package/node_modules/tokenjuice/dist/core/artifacts.d.ts +1 -1
  6. package/node_modules/tokenjuice/dist/core/artifacts.js +4 -3
  7. package/node_modules/tokenjuice/dist/core/command-identity.js +7 -6
  8. package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +3 -2
  9. package/node_modules/tokenjuice/dist/core/compaction-metadata.js +2 -1
  10. package/node_modules/tokenjuice/dist/core/failure-summary.d.ts +7 -0
  11. package/node_modules/tokenjuice/dist/core/failure-summary.js +76 -0
  12. package/node_modules/tokenjuice/dist/core/inventory-safety.js +14 -6
  13. package/node_modules/tokenjuice/dist/core/reduce-utils.js +9 -7
  14. package/node_modules/tokenjuice/dist/core/reduce.js +32 -21
  15. package/node_modules/tokenjuice/dist/core/streamed-text-counter.d.ts +8 -0
  16. package/node_modules/tokenjuice/dist/core/streamed-text-counter.js +56 -0
  17. package/node_modules/tokenjuice/dist/core/text.d.ts +1 -0
  18. package/node_modules/tokenjuice/dist/core/text.js +22 -11
  19. package/node_modules/tokenjuice/dist/core/wrap-format.d.ts +3 -0
  20. package/node_modules/tokenjuice/dist/core/wrap-format.js +34 -0
  21. package/node_modules/tokenjuice/dist/core/wrap.js +55 -6
  22. package/node_modules/tokenjuice/dist/hosts/codex/index.js +37 -10
  23. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/index.js +221 -79
  24. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/package.json +1 -1
  25. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/plugin.yaml +1 -1
  26. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/README.md +4 -2
  27. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/bridge.py +62 -5
  28. package/node_modules/tokenjuice/dist/hosts/openclaw/extension.js +7 -2
  29. package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +221 -79
  30. package/node_modules/tokenjuice/dist/hosts/opencode/v2/bundle/index.js +221 -79
  31. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +221 -79
  32. package/node_modules/tokenjuice/dist/python/README.md +1 -1
  33. package/node_modules/tokenjuice/dist/python/pyproject.toml +1 -1
  34. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/README.md +4 -2
  35. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/bridge.py +62 -5
  36. package/node_modules/tokenjuice/dist/rules/build/tsc.json +8 -3
  37. package/node_modules/tokenjuice/dist/rules/fixtures/build/tsc.fixture.json +6 -2
  38. package/node_modules/tokenjuice/dist/rules/install/bun-install.json +12 -4
  39. package/node_modules/tokenjuice/dist/rules/install/npm-ci.json +12 -4
  40. package/node_modules/tokenjuice/dist/rules/install/npm-install.json +12 -4
  41. package/node_modules/tokenjuice/dist/rules/install/pnpm-install.json +12 -4
  42. package/node_modules/tokenjuice/dist/rules/install/yarn-install.json +12 -4
  43. package/node_modules/tokenjuice/dist/rules/tests/pytest.json +8 -3
  44. package/node_modules/tokenjuice/dist/types.d.ts +3 -0
  45. package/node_modules/tokenjuice/package.json +5 -15
  46. package/package.json +5 -5
@@ -1,10 +1,56 @@
1
1
  """Pass captured output to tokenjuice; never execute the command in the payload."""
2
2
  import asyncio
3
3
  import json
4
+ import logging
4
5
  import os
5
6
  import subprocess
6
7
 
7
8
  MAX_INPUT_BYTES = 2_000_000
9
+ DEFAULT_PATHEXT = ".COM;.EXE;.BAT;.CMD"
10
+
11
+ logger = logging.getLogger("tokenjuice")
12
+ _reported = set()
13
+
14
+
15
+ def _find_on_path(name, path, separator):
16
+ # Absolute PATH entries only: never pick up a launcher from the working directory.
17
+ for directory in (path or "").split(separator):
18
+ directory = directory.strip().strip('"')
19
+ if not directory or not os.path.isabs(directory):
20
+ continue
21
+ candidate = os.path.join(directory, name)
22
+ if os.path.isfile(candidate):
23
+ return candidate
24
+ return None
25
+
26
+
27
+ def resolve_launcher(env=None, *, windows=None):
28
+ """Return the tokenjuice CLI argv prefix.
29
+
30
+ TOKENJUICE_BIN wins. On Windows, npm installs `tokenjuice.cmd` and no `.exe`, and
31
+ CreateProcess does not apply PATHEXT to a bare name, so resolve the shim explicitly.
32
+ """
33
+ env = os.environ if env is None else env
34
+ explicit = env.get("TOKENJUICE_BIN")
35
+ if explicit:
36
+ return [explicit]
37
+ windows = os.name == "nt" if windows is None else windows
38
+ if windows:
39
+ for ext in (env.get("PATHEXT") or DEFAULT_PATHEXT).split(";"):
40
+ ext = ext.strip()
41
+ if ext.startswith("."):
42
+ found = _find_on_path(f"tokenjuice{ext.lower()}", env.get("PATH"), ";")
43
+ if found:
44
+ return [found]
45
+ return ["tokenjuice"]
46
+
47
+
48
+ def _report(kind, message):
49
+ # Failures preserve the original output; say why once per process and kind.
50
+ if kind in _reported:
51
+ return
52
+ _reported.add(kind)
53
+ logger.warning("tokenjuice: %s; output left uncompacted", message)
8
54
 
9
55
 
10
56
  def compact_result(source, result, *, launcher=None, timeout=5):
@@ -12,17 +58,23 @@ def compact_result(source, result, *, launcher=None, timeout=5):
12
58
  return None
13
59
  if not isinstance(result.get("output"), str) or not isinstance(result.get("command"), str):
14
60
  return None
61
+ command = None
15
62
  try:
16
63
  payload = json.dumps({"source": source, "result": result}).encode("utf-8")
17
64
  if len(payload) > MAX_INPUT_BYTES:
18
65
  return None
19
- command = list(launcher) if launcher is not None else [os.environ.get("TOKENJUICE_BIN", "tokenjuice")]
66
+ command = list(launcher) if launcher is not None else resolve_launcher()
20
67
  completed = subprocess.run(
21
68
  [*command, "compact-shell-result"], input=payload,
22
- stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, timeout=timeout,
69
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout,
23
70
  check=False, env={**os.environ, "TOKENJUICE_STATS": "off"},
24
71
  )
25
- if completed.returncode != 0 or len(completed.stdout) > MAX_INPUT_BYTES:
72
+ if completed.returncode != 0:
73
+ detail = (completed.stderr or b"").decode("utf-8", "replace").strip().splitlines()
74
+ _report("exit", f"{command[0]} exited with status {completed.returncode}"
75
+ + (f": {detail[-1][:200]}" if detail else ""))
76
+ return None
77
+ if len(completed.stdout) > MAX_INPUT_BYTES:
26
78
  return None
27
79
  response = json.loads(completed.stdout)
28
80
  if not isinstance(response, dict):
@@ -30,8 +82,13 @@ def compact_result(source, result, *, launcher=None, timeout=5):
30
82
  text = response.get("text")
31
83
  if response.get("action") == "rewrite" and isinstance(text, str) and 0 < len(text) < len(result["output"]):
32
84
  return text
33
- except (OSError, ValueError, TypeError, subprocess.TimeoutExpired):
34
- pass
85
+ except OSError as error:
86
+ name = command[0] if command else "tokenjuice"
87
+ _report("spawn", f"could not start {name} ({error}); install the CLI or set TOKENJUICE_BIN")
88
+ except subprocess.TimeoutExpired:
89
+ _report("timeout", f"compact-shell-result timed out after {timeout}s")
90
+ except (ValueError, TypeError) as error:
91
+ _report("response", f"invalid compact-shell-result response ({error})")
35
92
  return None
36
93
 
37
94
 
@@ -87,14 +87,19 @@ export function createTokenjuiceOpenClawEmbeddedExtension() {
87
87
  if (outcome.action === "keep") {
88
88
  return undefined;
89
89
  }
90
+ const deliveredText = `${outcome.result.inlineText}\n\n[${buildCompactionNotice(outcome.result)}]`;
90
91
  return {
91
92
  content: [
92
93
  {
93
94
  type: "text",
94
- text: `${outcome.result.inlineText}\n\n[${buildCompactionNotice(outcome.result)}]`,
95
+ text: deliveredText,
95
96
  },
96
97
  ],
97
- details: mergeDetails(event.details, buildTokenjuiceDetails(outcome.result)),
98
+ details: {
99
+ ...mergeDetails(event.details, buildTokenjuiceDetails(outcome.result)),
100
+ // Structured consumers use aggregated instead of the content projection.
101
+ ...(typeof event.details.aggregated === "string" ? { aggregated: deliveredText } : {}),
102
+ },
98
103
  };
99
104
  }
100
105
  catch (error) {