@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
 
@@ -3,8 +3,12 @@
3
3
  "family": "build-typescript",
4
4
  "description": "Compact TypeScript compiler output while preserving real diagnostics.",
5
5
  "match": {
6
- "toolNames": ["exec"],
7
- "commandIncludes": ["tsc"]
6
+ "toolNames": [
7
+ "exec"
8
+ ],
9
+ "commandIncludes": [
10
+ "tsc"
11
+ ]
8
12
  },
9
13
  "transforms": {
10
14
  "stripAnsi": true,
@@ -48,7 +52,8 @@
48
52
  "^.+\\(\\d+,\\d+\\):\\s+error TS\\d+: .+",
49
53
  "^.+\\(\\d+,\\d+\\):\\s+warning TS\\d+: .+",
50
54
  "^Found \\d+ errors?.+",
51
- "^error TS\\d+: .+"
55
+ "^error TS\\d+: .+",
56
+ "^\\s{2,}\\S"
52
57
  ]
53
58
  },
54
59
  "summarize": {
@@ -4,12 +4,16 @@
4
4
  "input": {
5
5
  "toolName": "exec",
6
6
  "command": "pnpm tsc --noEmit",
7
- "combinedText": "src/index.ts(1,1): error TS2322: Type 'string' is not assignable to type 'number'.\nFound 1 error.\n",
7
+ "combinedText": "src/index.ts(1,1): error TS2322: Type 'string' is not assignable to type 'number'.\n Property requiredField is missing in type Source but required in type Target.\nFound 1 error.\n",
8
8
  "exitCode": 2
9
9
  },
10
10
  "expect": {
11
11
  "matchedReducer": "build/tsc",
12
12
  "family": "build-typescript",
13
- "contains": ["exit 2", "TS2322"]
13
+ "contains": [
14
+ "exit 2",
15
+ "TS2322",
16
+ "Property requiredField is missing"
17
+ ]
14
18
  }
15
19
  }
@@ -4,15 +4,23 @@
4
4
  "description": "Compact bun install output while preserving warnings and package counts.",
5
5
  "matchOutput": [
6
6
  {
7
- "pattern": "Checked \\d+ installs? across \\d+ packages? \\(no changes\\)",
7
+ "pattern": "^(?:bun install v[^\\r\\n]+\\n)?Checked \\d+ installs? across \\d+ packages? \\(no changes\\)$",
8
8
  "message": "bun install: up to date",
9
9
  "flags": "i"
10
10
  }
11
11
  ],
12
12
  "match": {
13
- "toolNames": ["exec"],
14
- "argv0": ["bun"],
15
- "argvIncludes": [["install"]]
13
+ "toolNames": [
14
+ "exec"
15
+ ],
16
+ "argv0": [
17
+ "bun"
18
+ ],
19
+ "argvIncludes": [
20
+ [
21
+ "install"
22
+ ]
23
+ ]
16
24
  },
17
25
  "transforms": {
18
26
  "stripAnsi": true,
@@ -5,15 +5,23 @@
5
5
  "onEmpty": "npm ci: ok",
6
6
  "matchOutput": [
7
7
  {
8
- "pattern": "up to date, audited \\d+ package",
8
+ "pattern": "^up to date, audited \\d+ packages? in [^\\r\\n]+(?:\\n+found 0 vulnerabilities)?$",
9
9
  "message": "npm ci: up to date",
10
10
  "flags": "i"
11
11
  }
12
12
  ],
13
13
  "match": {
14
- "toolNames": ["exec"],
15
- "argv0": ["npm"],
16
- "argvIncludes": [["ci"]]
14
+ "toolNames": [
15
+ "exec"
16
+ ],
17
+ "argv0": [
18
+ "npm"
19
+ ],
20
+ "argvIncludes": [
21
+ [
22
+ "ci"
23
+ ]
24
+ ]
17
25
  },
18
26
  "transforms": {
19
27
  "stripAnsi": true,
@@ -5,15 +5,23 @@
5
5
  "onEmpty": "npm install: ok",
6
6
  "matchOutput": [
7
7
  {
8
- "pattern": "up to date, audited \\d+ package",
8
+ "pattern": "^up to date, audited \\d+ packages? in [^\\r\\n]+(?:\\n+found 0 vulnerabilities)?$",
9
9
  "message": "npm install: up to date",
10
10
  "flags": "i"
11
11
  }
12
12
  ],
13
13
  "match": {
14
- "toolNames": ["exec"],
15
- "argv0": ["npm"],
16
- "argvIncludes": [["install"]]
14
+ "toolNames": [
15
+ "exec"
16
+ ],
17
+ "argv0": [
18
+ "npm"
19
+ ],
20
+ "argvIncludes": [
21
+ [
22
+ "install"
23
+ ]
24
+ ]
17
25
  },
18
26
  "transforms": {
19
27
  "stripAnsi": true,
@@ -4,15 +4,23 @@
4
4
  "description": "Compact pnpm install output while preserving warnings and summary lines.",
5
5
  "matchOutput": [
6
6
  {
7
- "pattern": "Already up to date",
7
+ "pattern": "^(?:Lockfile is up to date, resolution step is skipped\\n)?Already up to date(?:\\nDone in [^\\r\\n]+)?$",
8
8
  "message": "pnpm install: up to date",
9
9
  "flags": "i"
10
10
  }
11
11
  ],
12
12
  "match": {
13
- "toolNames": ["exec"],
14
- "argv0": ["pnpm"],
15
- "argvIncludes": [["install"]]
13
+ "toolNames": [
14
+ "exec"
15
+ ],
16
+ "argv0": [
17
+ "pnpm"
18
+ ],
19
+ "argvIncludes": [
20
+ [
21
+ "install"
22
+ ]
23
+ ]
16
24
  },
17
25
  "transforms": {
18
26
  "stripAnsi": true,
@@ -4,14 +4,22 @@
4
4
  "description": "Compact yarn install output while preserving warnings and summary lines.",
5
5
  "matchOutput": [
6
6
  {
7
- "pattern": "Already up-to-date\\.",
7
+ "pattern": "^(?:\\[\\d+/\\d+\\] Resolving packages\\.\\.\\.\\n)?(?:success )?Already up-to-date\\.(?:\\nDone in [^\\r\\n]+)?$",
8
8
  "message": "yarn install: up to date"
9
9
  }
10
10
  ],
11
11
  "match": {
12
- "toolNames": ["exec"],
13
- "argv0": ["yarn"],
14
- "argvIncludes": [["install"]]
12
+ "toolNames": [
13
+ "exec"
14
+ ],
15
+ "argv0": [
16
+ "yarn"
17
+ ],
18
+ "argvIncludes": [
19
+ [
20
+ "install"
21
+ ]
22
+ ]
15
23
  },
16
24
  "transforms": {
17
25
  "stripAnsi": true,
@@ -4,8 +4,12 @@
4
4
  "description": "Compact pytest output while preserving failures and final summary.",
5
5
  "counterSource": "preKeep",
6
6
  "match": {
7
- "toolNames": ["exec"],
8
- "commandIncludes": ["pytest"]
7
+ "toolNames": [
8
+ "exec"
9
+ ],
10
+ "commandIncludes": [
11
+ "pytest"
12
+ ]
9
13
  },
10
14
  "transforms": {
11
15
  "stripAnsi": true,
@@ -27,7 +31,8 @@
27
31
  "^E\\s+.+",
28
32
  "AssertionError",
29
33
  "^.+::.+ (FAILED|ERROR)$",
30
- "^>\\s+.+"
34
+ "^>\\s+.+",
35
+ "^\\S.*\\.py:\\d+:\\s+\\S"
31
36
  ]
32
37
  },
33
38
  "summarize": {
@@ -136,6 +136,7 @@ export type ArtifactMetadataPageOptions = {
136
136
  };
137
137
  export type CompactResult = {
138
138
  inlineText: string;
139
+ captureTruncated?: boolean;
139
140
  previewText?: string;
140
141
  facts?: Record<string, number>;
141
142
  compaction?: import("./core/compaction-metadata.js").CompactionMetadata;
@@ -206,6 +207,8 @@ export type RuleFixture = {
206
207
  };
207
208
  };
208
209
  export type WrapOptions = {
210
+ /** Return the complete text-mode payload, including notices and its line ending. */
211
+ includeCompactionNotice?: boolean;
209
212
  keepFailures?: boolean;
210
213
  cwd?: string;
211
214
  source?: string;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenjuice",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "Lean output compaction for terminal-heavy agent workflows.",
5
5
  "keywords": [
6
6
  "cli",
@@ -74,7 +74,8 @@
74
74
  "test": "pnpm generate:builtin-rules && vitest run",
75
75
  "typecheck": "pnpm generate:builtin-rules && tsc -p tsconfig.json --noEmit",
76
76
  "verify": "pnpm lint && pnpm lint:circular && pnpm typecheck && pnpm test",
77
- "verify:package": "pnpm build && pnpm contracts && pnpm release:artifacts && pnpm release:checksums && pnpm release:formula"
77
+ "verify:package": "pnpm build && pnpm contracts && pnpm release:artifacts && pnpm release:checksums && pnpm release:formula",
78
+ "bench:quality": "node scripts/bench-quality.mjs"
78
79
  },
79
80
  "devDependencies": {
80
81
  "@types/node": "^22.20.5",
@@ -84,18 +85,7 @@
84
85
  "publint": "^0.3.25",
85
86
  "typescript": "^7.0.2",
86
87
  "vitest": "5.0.5",
87
- "vite": "8.3.5"
88
- },
89
- "pnpm": {
90
- "overrides": {
91
- "vite": "8.3.5",
92
- "source-map-js": "1.2.2",
93
- "nanoid@3": "3.3.20",
94
- "postcss": "8.5.23",
95
- "brace-expansion": "5.0.12",
96
- "esbuild": "0.28.2",
97
- "@vitest/mocker": "5.0.5",
98
- "minimatch@10": "11.0.1"
99
- }
88
+ "vite": "8.3.5",
89
+ "gpt-tokenizer": "4.1.2"
100
90
  }
101
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/tokenjuice",
3
- "version": "2026.11.10-beta.3",
3
+ "version": "2026.12.1-beta.1",
4
4
  "description": "OpenClaw tokenjuice exec output compaction plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "type": "module",
10
10
  "dependencies": {
11
- "tokenjuice": "0.11.0"
11
+ "tokenjuice": "0.11.2"
12
12
  },
13
13
  "peerDependencies": {
14
- "openclaw": ">=2026.11.10-beta.3"
14
+ "openclaw": ">=2026.12.1-beta.1"
15
15
  },
16
16
  "peerDependenciesMeta": {
17
17
  "openclaw": {
@@ -29,10 +29,10 @@
29
29
  "minHostVersion": ">=2026.5.28"
30
30
  },
31
31
  "compat": {
32
- "pluginApi": ">=2026.11.10-beta.3"
32
+ "pluginApi": ">=2026.12.1-beta.1"
33
33
  },
34
34
  "build": {
35
- "openclawVersion": "2026.11.10-beta.3",
35
+ "openclawVersion": "2026.12.1-beta.1",
36
36
  "bundledDist": false
37
37
  },
38
38
  "release": {