@openclaw/tokenjuice 2026.7.1 → 2026.7.2-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.
@@ -2,53 +2,18 @@ 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
- }
32
5
  function normalizeDetails(event, current) {
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 = {
42
- status: failed ? "failed" : "completed",
43
- aggregated,
44
- exitCode: typeof existingExitCode === "number" && Number.isFinite(existingExitCode) ? existingExitCode : failed ? 1 : 0
45
- };
46
- if (!details) return synthesized;
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;
47
13
  return {
48
- ...synthesized,
49
- ...details,
50
- status: synthesized.status,
51
- exitCode: synthesized.exitCode
14
+ ...metadata,
15
+ status: failed ? "failed" : "completed",
16
+ exitCode
52
17
  };
53
18
  }
54
19
  function createTokenjuiceAgentToolResultMiddleware() {
@@ -58,6 +23,8 @@ function createTokenjuiceAgentToolResultMiddleware() {
58
23
  } });
59
24
  return async (event) => {
60
25
  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();
61
28
  for (const handler of handlers) {
62
29
  const next = await handler({
63
30
  toolName: event.toolName,
@@ -65,7 +32,7 @@ function createTokenjuiceAgentToolResultMiddleware() {
65
32
  content: current.content,
66
33
  details: normalizeDetails(event, current),
67
34
  isError: event.isError
68
- }, { cwd: readCwd(event) });
35
+ }, { cwd });
69
36
  if (next) current = Object.assign({}, current, {
70
37
  content: next.content ?? current.content,
71
38
  details: next.details ?? current.details
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@openclaw/tokenjuice",
3
- "version": "2026.7.1",
3
+ "version": "2026.7.2-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@openclaw/tokenjuice",
9
- "version": "2026.7.1",
9
+ "version": "2026.7.2-beta.1",
10
10
  "dependencies": {
11
11
  "tokenjuice": "0.8.1"
12
12
  },
13
13
  "peerDependencies": {
14
- "openclaw": ">=2026.7.1"
14
+ "openclaw": ">=2026.7.2-beta.1"
15
15
  },
16
16
  "peerDependenciesMeta": {
17
17
  "openclaw": {
@@ -5,6 +5,7 @@
5
5
  },
6
6
  "name": "tokenjuice",
7
7
  "description": "Compacts exec and bash tool results with tokenjuice reducers.",
8
+ "catalog": { "featured": true, "order": 60 },
8
9
  "contracts": {
9
10
  "agentToolResultMiddleware": ["openclaw", "codex"]
10
11
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/tokenjuice",
3
- "version": "2026.7.1",
3
+ "version": "2026.7.2-beta.1",
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.1"
14
+ "openclaw": ">=2026.7.2-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.7.1"
32
+ "pluginApi": ">=2026.7.2-beta.1"
33
33
  },
34
34
  "build": {
35
- "openclawVersion": "2026.7.1",
35
+ "openclawVersion": "2026.7.2-beta.1",
36
36
  "bundledDist": false
37
37
  },
38
38
  "release": {