@openclaw/tokenjuice 2026.11.12 → 2026.11.13
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"entries":[{"output":"index.js","source":"extensions/tokenjuice/index.ts"},{"output":"runtime-api.js","source":"extensions/tokenjuice/runtime-api.ts"},{"output":"tool-result-middleware.js","source":"extensions/tokenjuice/tool-result-middleware.ts"}],"chunks":[{"output":"index.js","sha256":"
|
|
1
|
+
{"version":3,"entries":[{"output":"index.js","source":"extensions/tokenjuice/index.ts"},{"output":"runtime-api.js","source":"extensions/tokenjuice/runtime-api.ts"},{"output":"tool-result-middleware.js","source":"extensions/tokenjuice/tool-result-middleware.ts"}],"chunks":[{"output":"index.js","sha256":"fa9334317b7fe2fffcbe2f86083d66a3bc167ef4520902e3d7ef7deb8a064945","facadeSource":"extensions/tokenjuice/index.ts","sources":["extensions/tokenjuice/index.ts"]},{"output":"runtime-api.js","sha256":"ed2b93f5080d21d766b3325f7ed6fb86f488449a4185605d59d8a37100bbcd2c","facadeSource":"extensions/tokenjuice/runtime-api.ts","sources":[]},{"output":"tool-result-middleware.js","sha256":"1648734ac59dcaca552b2ac9a827aa15c829bf43fcbdcb9e95257dac065b666c","facadeSource":"extensions/tokenjuice/tool-result-middleware.ts","sources":["extensions/tokenjuice/tool-result-middleware.ts"]}],"unrenderedSources":["extensions/tokenjuice/runtime-api.ts"]}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var tokenjuice_default = definePluginEntry({
|
|
|
6
6
|
name: "tokenjuice",
|
|
7
7
|
description: "Compacts exec and bash tool results with tokenjuice reducers.",
|
|
8
8
|
register(api) {
|
|
9
|
-
api.registerAgentToolResultMiddleware(createTokenjuiceAgentToolResultMiddleware());
|
|
9
|
+
api.registerAgentToolResultMiddleware(createTokenjuiceAgentToolResultMiddleware(api.logger));
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
export { tokenjuice_default as default };
|
|
@@ -2,10 +2,16 @@ 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
|
// extensions/tokenjuice/tool-result-middleware.ts
|
|
5
|
+
const shellToolNames = /* @__PURE__ */ new Set([
|
|
6
|
+
"exec",
|
|
7
|
+
"bash",
|
|
8
|
+
"gateway_exec",
|
|
9
|
+
"node_exec"
|
|
10
|
+
]);
|
|
5
11
|
const retainedRuleScopes = /* @__PURE__ */ new Set();
|
|
6
|
-
function normalizeDetails(event,
|
|
7
|
-
if (event.toolName !== "exec" && event.toolName !== "bash"
|
|
8
|
-
const metadata =
|
|
12
|
+
function normalizeDetails(event, details) {
|
|
13
|
+
if (event.toolName !== "exec" && event.toolName !== "bash") return details;
|
|
14
|
+
const metadata = { ...details };
|
|
9
15
|
delete metadata.aggregated;
|
|
10
16
|
if (typeof metadata.status === "string" && metadata.status.trim()) return metadata;
|
|
11
17
|
const rawExitCode = metadata.exitCode;
|
|
@@ -15,25 +21,40 @@ function normalizeDetails(event, current) {
|
|
|
15
21
|
metadata.exitCode = exitCode;
|
|
16
22
|
return metadata;
|
|
17
23
|
}
|
|
18
|
-
function createTokenjuiceAgentToolResultMiddleware() {
|
|
24
|
+
function createTokenjuiceAgentToolResultMiddleware(logger) {
|
|
19
25
|
let handler;
|
|
26
|
+
let warned = false;
|
|
20
27
|
createTokenjuiceOpenClawEmbeddedExtension()({ on(event, registeredHandler) {
|
|
21
28
|
if (event === "tool_result") handler = registeredHandler;
|
|
22
29
|
} });
|
|
23
30
|
return async (event) => {
|
|
24
|
-
const current = event
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
31
|
+
const { args, result: current, toolName } = event;
|
|
32
|
+
if (!handler || !shellToolNames.has(toolName) || "code" in args || typeof args.command !== "string" || !args.command.trim()) return;
|
|
33
|
+
const originalDetails = isRecord(current.details) ? current.details : void 0;
|
|
34
|
+
if (originalDetails?.timedOut === true || originalDetails?.noOutputTimedOut === true || typeof originalDetails?.fullOutputPath === "string") return;
|
|
35
|
+
const details = normalizeDetails(event, originalDetails);
|
|
36
|
+
if (details?.status !== "completed" && details?.status !== "failed") return;
|
|
37
|
+
const { workdir } = args;
|
|
38
|
+
const detailsCwd = details.cwd;
|
|
28
39
|
const cwd = typeof workdir === "string" && workdir.trim() ? workdir : typeof detailsCwd === "string" && detailsCwd.trim() ? detailsCwd : event.cwd?.trim() ? event.cwd : process.cwd();
|
|
29
40
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
let next;
|
|
42
|
+
try {
|
|
43
|
+
next = await handler({
|
|
44
|
+
toolName,
|
|
45
|
+
input: args,
|
|
46
|
+
content: current.content,
|
|
47
|
+
details,
|
|
48
|
+
isError: event.isError
|
|
49
|
+
}, { cwd });
|
|
50
|
+
} finally {
|
|
51
|
+
retainedRuleScopes.add(cwd);
|
|
52
|
+
if (retainedRuleScopes.size >= 128) {
|
|
53
|
+
const { clearRuleCache } = await import("tokenjuice");
|
|
54
|
+
clearRuleCache();
|
|
55
|
+
retainedRuleScopes.clear();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
37
58
|
if (!next) return;
|
|
38
59
|
const nextDetails = next.details ?? details;
|
|
39
60
|
return { result: Object.assign({}, current, {
|
|
@@ -43,13 +64,12 @@ function createTokenjuiceAgentToolResultMiddleware() {
|
|
|
43
64
|
aggregated: next.content.filter((block) => block.type === "text").map((block) => block.text).join("\n")
|
|
44
65
|
} : nextDetails
|
|
45
66
|
}) };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
clearRuleCache();
|
|
51
|
-
retainedRuleScopes.clear();
|
|
67
|
+
} catch {
|
|
68
|
+
if (!warned) {
|
|
69
|
+
warned = true;
|
|
70
|
+
logger.warn("Tokenjuice could not compact shell output; keeping the original result.");
|
|
52
71
|
}
|
|
72
|
+
return;
|
|
53
73
|
}
|
|
54
74
|
};
|
|
55
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/tokenjuice",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.13",
|
|
4
4
|
"description": "OpenClaw tokenjuice exec output compaction plugin",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"tokenjuice": "0.11.0"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"openclaw": ">=2026.11.
|
|
14
|
+
"openclaw": ">=2026.11.13"
|
|
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.
|
|
32
|
+
"pluginApi": ">=2026.11.13"
|
|
33
33
|
},
|
|
34
34
|
"build": {
|
|
35
|
-
"openclawVersion": "2026.11.
|
|
35
|
+
"openclawVersion": "2026.11.13",
|
|
36
36
|
"bundledDist": false
|
|
37
37
|
},
|
|
38
38
|
"release": {
|