@openclaw/tokenjuice 2026.7.2-beta.5 → 2026.7.33

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.
@@ -2,18 +2,53 @@ import { createTokenjuiceOpenClawEmbeddedExtension } from "./runtime-api.js";
2
2
  import process from "node:process";
3
3
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  //#region extensions/tokenjuice/tool-result-middleware.ts
5
+ function readCwd(event) {
6
+ if (event.cwd?.trim()) return event.cwd;
7
+ const workdir = event.args.workdir;
8
+ if (typeof workdir === "string" && workdir.trim()) return workdir;
9
+ return process.cwd();
10
+ }
11
+ function readTextContent(content) {
12
+ if (typeof content === "string") return content;
13
+ if (!Array.isArray(content)) return "";
14
+ return content.map((item) => {
15
+ if (typeof item === "string") return item;
16
+ if (item && typeof item === "object" && "text" in item && typeof item.text === "string") return item.text;
17
+ return "";
18
+ }).filter(Boolean).join("\n");
19
+ }
20
+ function readCommand(args) {
21
+ const command = args.command;
22
+ return typeof command === "string" ? command : "";
23
+ }
24
+ function hasStatus(details) {
25
+ const status = details.status;
26
+ return typeof status === "string" && status.trim() !== "";
27
+ }
28
+ function hasFailureState(event, details) {
29
+ const exitCode = details?.exitCode;
30
+ return event.isError === true || details?.ok === false || details?.success === false || details?.timedOut === true || Boolean(details?.error) || typeof exitCode === "number" && Number.isFinite(exitCode) && exitCode !== 0;
31
+ }
5
32
  function normalizeDetails(event, current) {
6
- if (event.toolName !== "exec" && event.toolName !== "bash" || typeof event.args.command !== "string" || !event.args.command) return current.details;
7
- const metadata = isRecord(current.details) ? { ...current.details } : {};
8
- delete metadata.aggregated;
9
- if (typeof metadata.status === "string" && metadata.status.trim()) return metadata;
10
- const rawExitCode = metadata.exitCode;
11
- const failed = event.isError === true || metadata.ok === false || metadata.success === false || metadata.timedOut === true || Boolean(metadata.error) || typeof rawExitCode === "number" && Number.isFinite(rawExitCode) && rawExitCode !== 0;
12
- const exitCode = typeof rawExitCode === "number" && Number.isFinite(rawExitCode) ? rawExitCode : failed ? 1 : 0;
13
- return {
14
- ...metadata,
33
+ const isExecLike = event.toolName === "exec" || event.toolName === "bash";
34
+ const details = isRecord(current.details) ? current.details : void 0;
35
+ if (!isExecLike || !readCommand(event.args)) return current.details;
36
+ if (details && hasStatus(details)) return current.details;
37
+ const aggregated = readTextContent(current.content);
38
+ if (!aggregated.trim()) return current.details;
39
+ const failed = hasFailureState(event, details);
40
+ const existingExitCode = details?.exitCode;
41
+ const synthesized = {
15
42
  status: failed ? "failed" : "completed",
16
- exitCode
43
+ aggregated,
44
+ exitCode: typeof existingExitCode === "number" && Number.isFinite(existingExitCode) ? existingExitCode : failed ? 1 : 0
45
+ };
46
+ if (!details) return synthesized;
47
+ return {
48
+ ...synthesized,
49
+ ...details,
50
+ status: synthesized.status,
51
+ exitCode: synthesized.exitCode
17
52
  };
18
53
  }
19
54
  function createTokenjuiceAgentToolResultMiddleware() {
@@ -23,8 +58,6 @@ function createTokenjuiceAgentToolResultMiddleware() {
23
58
  } });
24
59
  return async (event) => {
25
60
  let current = event.result;
26
- const workdir = event.args.workdir;
27
- const cwd = event.cwd?.trim() ? event.cwd : typeof workdir === "string" && workdir.trim() ? workdir : process.cwd();
28
61
  for (const handler of handlers) {
29
62
  const next = await handler({
30
63
  toolName: event.toolName,
@@ -32,7 +65,7 @@ function createTokenjuiceAgentToolResultMiddleware() {
32
65
  content: current.content,
33
66
  details: normalizeDetails(event, current),
34
67
  isError: event.isError
35
- }, { cwd });
68
+ }, { cwd: readCwd(event) });
36
69
  if (next) current = Object.assign({}, current, {
37
70
  content: next.content ?? current.content,
38
71
  details: next.details ?? current.details
@@ -5,7 +5,6 @@
5
5
  },
6
6
  "name": "tokenjuice",
7
7
  "description": "Compacts exec and bash tool results with tokenjuice reducers.",
8
- "catalog": { "featured": true, "order": 60 },
9
8
  "contracts": {
10
9
  "agentToolResultMiddleware": ["openclaw", "codex"]
11
10
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/tokenjuice",
3
- "version": "2026.7.2-beta.5",
3
+ "version": "2026.7.33",
4
4
  "description": "OpenClaw tokenjuice exec output compaction plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,7 @@
11
11
  "tokenjuice": "0.8.1"
12
12
  },
13
13
  "peerDependencies": {
14
- "openclaw": ">=2026.7.2-beta.5"
14
+ "openclaw": ">=2026.7.33"
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.7.2-beta.5"
32
+ "pluginApi": ">=2026.7.33"
33
33
  },
34
34
  "build": {
35
- "openclawVersion": "2026.7.2-beta.5",
35
+ "openclawVersion": "2026.7.33",
36
36
  "bundledDist": false
37
37
  },
38
38
  "release": {