@openclaw/tokenjuice 2026.9.6 → 2026.9.7

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.
package/assets/icon.png CHANGED
Binary file
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(), { runtimes: ["openclaw", "codex"] });
9
+ api.registerAgentToolResultMiddleware(createTokenjuiceAgentToolResultMiddleware());
10
10
  }
11
11
  });
12
12
  //#endregion
@@ -1,7 +1,8 @@
1
- import { access, mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
- import { dirname, join } from "node:path";
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
3
  import { homedir } from "node:os";
4
4
  import { extractHookCommandPaths } from "../shared/hook-command.js";
5
+ import { readSettingsFile, writeSettingsFile } from "../shared/settings-file.js";
5
6
  import { buildWrapLauncherHookCommand, buildWrappedCommand, commandAlreadyWrapped, isExecutableFile, isRecord, pathExists, resolveHostShell, } from "../shared/pre-tool-wrap.js";
6
7
  const TOKENJUICE_CLAUDE_CODE_STATUS = "wrapping bash through tokenjuice for compaction";
7
8
  const TOKENJUICE_CLAUDE_CODE_LEGACY_STATUS = "compacting bash output with tokenjuice";
@@ -97,22 +98,6 @@ function sanitizeClaudeCodeSettings(raw) {
97
98
  hooks: sanitizeHooksSubtree(raw.hooks),
98
99
  };
99
100
  }
100
- async function loadClaudeCodeSettings(settingsPath) {
101
- try {
102
- const rawText = await readFile(settingsPath, "utf8");
103
- const parsed = JSON.parse(rawText);
104
- const config = sanitizeClaudeCodeSettings(parsed);
105
- const backupPath = `${settingsPath}.bak`;
106
- await writeFile(backupPath, rawText, "utf8");
107
- return { config, backupPath };
108
- }
109
- catch (error) {
110
- if (error.code === "ENOENT") {
111
- return { config: { hooks: {} } };
112
- }
113
- throw new Error(`failed to load claude code settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
114
- }
115
- }
116
101
  async function readClaudeCodeSettings(settingsPath) {
117
102
  try {
118
103
  const rawText = await readFile(settingsPath, "utf8");
@@ -132,20 +117,6 @@ async function readClaudeCodeSettings(settingsPath) {
132
117
  throw new Error(`failed to read claude code settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
133
118
  }
134
119
  }
135
- async function chooseBackupPath(filePath) {
136
- for (let index = 0;; index += 1) {
137
- const candidate = index === 0 ? `${filePath}.bak` : `${filePath}.bak.${index}`;
138
- try {
139
- await access(candidate);
140
- }
141
- catch (error) {
142
- if (error.code === "ENOENT") {
143
- return candidate;
144
- }
145
- throw error;
146
- }
147
- }
148
- }
149
120
  function pruneTokenjuiceHookEntries(groups) {
150
121
  const pruned = [];
151
122
  for (const group of groups) {
@@ -193,7 +164,8 @@ async function resolveClaudeCodeHostShell(toolInput) {
193
164
  ]);
194
165
  }
195
166
  export async function installClaudeCodeHook(settingsPath = getDefaultSettingsPath(), options = {}) {
196
- const { config, backupPath } = await loadClaudeCodeSettings(settingsPath);
167
+ const settings = await readSettingsFile(settingsPath);
168
+ const config = sanitizeClaudeCodeSettings(settings.data ? JSON.parse(settings.data.toString("utf8")) : undefined);
197
169
  const command = await buildClaudeCodeHookCommand(options);
198
170
  if (Array.isArray(config.hooks.PostToolUse)) {
199
171
  const prunedPost = pruneTokenjuiceHookEntries(config.hooks.PostToolUse);
@@ -208,10 +180,7 @@ export async function installClaudeCodeHook(settingsPath = getDefaultSettingsPat
208
180
  const retained = pruneTokenjuiceHookEntries(preToolUse);
209
181
  retained.push(createTokenjuiceClaudeCodeHook(command));
210
182
  config.hooks.PreToolUse = retained;
211
- await mkdir(dirname(settingsPath), { recursive: true });
212
- const tempPath = `${settingsPath}.tmp`;
213
- await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
214
- await rename(tempPath, settingsPath);
183
+ const backupPath = await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`, "replace");
215
184
  return {
216
185
  settingsPath,
217
186
  ...(backupPath ? { backupPath } : {}),
@@ -219,39 +188,21 @@ export async function installClaudeCodeHook(settingsPath = getDefaultSettingsPat
219
188
  };
220
189
  }
221
190
  export async function uninstallClaudeCodeHook(settingsPath = getDefaultSettingsPath()) {
222
- let rawText;
223
- try {
224
- rawText = await readFile(settingsPath, "utf8");
225
- }
226
- catch (error) {
227
- if (error.code === "ENOENT") {
228
- return { settingsPath, removed: false };
229
- }
230
- throw new Error(`failed to read claude code settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
231
- }
232
- let parsed;
233
- try {
234
- parsed = JSON.parse(rawText);
235
- }
236
- catch (error) {
237
- throw new Error(`failed to read claude code settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
191
+ const settings = await readSettingsFile(settingsPath);
192
+ if (!settings.data) {
193
+ return { settingsPath, removed: false };
238
194
  }
239
- const config = sanitizeClaudeCodeSettings(parsed);
195
+ const config = sanitizeClaudeCodeSettings(JSON.parse(settings.data.toString("utf8")));
240
196
  const removedPreToolUse = removeTokenjuiceHookEvent(config, "PreToolUse");
241
197
  const removedPostToolUse = removeTokenjuiceHookEvent(config, "PostToolUse");
242
198
  const removed = removedPreToolUse || removedPostToolUse;
243
199
  if (!removed) {
244
200
  return { settingsPath, removed: false };
245
201
  }
246
- const backupPath = await chooseBackupPath(settingsPath);
247
- await writeFile(backupPath, rawText, "utf8");
248
- await mkdir(dirname(settingsPath), { recursive: true });
249
- const tempPath = `${settingsPath}.tmp`;
250
- await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
251
- await rename(tempPath, settingsPath);
202
+ const backupPath = await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`, "preserve");
252
203
  return {
253
204
  settingsPath,
254
- backupPath,
205
+ ...(backupPath ? { backupPath } : {}),
255
206
  removed: true,
256
207
  };
257
208
  }
@@ -1,7 +1,8 @@
1
- import { access, mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
- import { dirname, join } from "node:path";
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
3
  import { homedir } from "node:os";
4
4
  import { extractHookCommandPaths } from "../shared/hook-command.js";
5
+ import { readSettingsFile, writeSettingsFile } from "../shared/settings-file.js";
5
6
  import { buildWrapLauncherHookCommand, buildWrappedCommand, commandAlreadyWrapped, isExecutableFile, isRecord, pathExists, resolveHostShell, } from "../shared/pre-tool-wrap.js";
6
7
  const TOKENJUICE_CODEBUDDY_STATUS = "wrapping bash through tokenjuice for compaction";
7
8
  const TOKENJUICE_CODEBUDDY_FIX_COMMAND = "tokenjuice install codebuddy";
@@ -93,22 +94,6 @@ function sanitizeCodeBuddySettings(raw) {
93
94
  hooks: sanitizeHooksSubtree(raw.hooks),
94
95
  };
95
96
  }
96
- async function loadCodeBuddySettings(settingsPath) {
97
- try {
98
- const rawText = await readFile(settingsPath, "utf8");
99
- const parsed = JSON.parse(rawText);
100
- const config = sanitizeCodeBuddySettings(parsed);
101
- const backupPath = `${settingsPath}.bak`;
102
- await writeFile(backupPath, rawText, "utf8");
103
- return { config, backupPath };
104
- }
105
- catch (error) {
106
- if (error.code === "ENOENT") {
107
- return { config: { hooks: {} } };
108
- }
109
- throw new Error(`failed to load codebuddy settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
110
- }
111
- }
112
97
  async function readCodeBuddySettings(settingsPath) {
113
98
  try {
114
99
  const rawText = await readFile(settingsPath, "utf8");
@@ -128,20 +113,6 @@ async function readCodeBuddySettings(settingsPath) {
128
113
  throw new Error(`failed to read codebuddy settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
129
114
  }
130
115
  }
131
- async function chooseBackupPath(filePath) {
132
- for (let index = 0;; index += 1) {
133
- const candidate = index === 0 ? `${filePath}.bak` : `${filePath}.bak.${index}`;
134
- try {
135
- await access(candidate);
136
- }
137
- catch (error) {
138
- if (error.code === "ENOENT") {
139
- return candidate;
140
- }
141
- throw error;
142
- }
143
- }
144
- }
145
116
  async function resolveCodeBuddyHostShell(toolInput) {
146
117
  return resolveHostShell([
147
118
  typeof toolInput.shell === "string" ? toolInput.shell : undefined,
@@ -201,7 +172,8 @@ export async function installCodeBuddyHook(settingsPath = getDefaultSettingsPath
201
172
  if (isNativeWindowsCodeBuddyUnsupported()) {
202
173
  throw new Error(TOKENJUICE_CODEBUDDY_WINDOWS_ISSUE);
203
174
  }
204
- const { config, backupPath } = await loadCodeBuddySettings(settingsPath);
175
+ const settings = await readSettingsFile(settingsPath);
176
+ const config = sanitizeCodeBuddySettings(settings.data ? JSON.parse(settings.data.toString("utf8")) : undefined);
205
177
  const command = await buildCodeBuddyHookCommand(options);
206
178
  // Drop any legacy PostToolUse tokenjuice entries left behind by a prior
207
179
  // version of this host, but preserve unrelated hooks that happen to live in
@@ -219,10 +191,7 @@ export async function installCodeBuddyHook(settingsPath = getDefaultSettingsPath
219
191
  const retained = pruneTokenjuiceHookEntries(preToolUse);
220
192
  retained.push(createTokenjuiceCodeBuddyHook(command));
221
193
  config.hooks.PreToolUse = retained;
222
- await mkdir(dirname(settingsPath), { recursive: true });
223
- const tempPath = `${settingsPath}.tmp`;
224
- await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
225
- await rename(tempPath, settingsPath);
194
+ const backupPath = await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`, "replace");
226
195
  return {
227
196
  settingsPath,
228
197
  ...(backupPath ? { backupPath } : {}),
@@ -230,39 +199,21 @@ export async function installCodeBuddyHook(settingsPath = getDefaultSettingsPath
230
199
  };
231
200
  }
232
201
  export async function uninstallCodeBuddyHook(settingsPath = getDefaultSettingsPath()) {
233
- let rawText;
234
- try {
235
- rawText = await readFile(settingsPath, "utf8");
236
- }
237
- catch (error) {
238
- if (error.code === "ENOENT") {
239
- return { settingsPath, removed: false };
240
- }
241
- throw new Error(`failed to read codebuddy settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
242
- }
243
- let parsed;
244
- try {
245
- parsed = JSON.parse(rawText);
246
- }
247
- catch (error) {
248
- throw new Error(`failed to read codebuddy settings from ${settingsPath}: ${error instanceof Error ? error.message : String(error)}`);
202
+ const settings = await readSettingsFile(settingsPath);
203
+ if (!settings.data) {
204
+ return { settingsPath, removed: false };
249
205
  }
250
- const config = sanitizeCodeBuddySettings(parsed);
206
+ const config = sanitizeCodeBuddySettings(JSON.parse(settings.data.toString("utf8")));
251
207
  const removedPreToolUse = removeTokenjuiceHookEvent(config, "PreToolUse");
252
208
  const removedPostToolUse = removeTokenjuiceHookEvent(config, "PostToolUse");
253
209
  const removed = removedPreToolUse || removedPostToolUse;
254
210
  if (!removed) {
255
211
  return { settingsPath, removed: false };
256
212
  }
257
- const backupPath = await chooseBackupPath(settingsPath);
258
- await writeFile(backupPath, rawText, "utf8");
259
- await mkdir(dirname(settingsPath), { recursive: true });
260
- const tempPath = `${settingsPath}.tmp`;
261
- await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
262
- await rename(tempPath, settingsPath);
213
+ const backupPath = await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`, "preserve");
263
214
  return {
264
215
  settingsPath,
265
- backupPath,
216
+ ...(backupPath ? { backupPath } : {}),
266
217
  removed: true,
267
218
  };
268
219
  }
@@ -1,4 +1,4 @@
1
- import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
2
  import { dirname, join } from "node:path";
3
3
  import { homedir } from "node:os";
4
4
  import { shouldRecordStats } from "../../core/artifacts.js";
@@ -9,6 +9,7 @@ import { buildHookCommandDoctorFields } from "../shared/hook-command-doctor.js";
9
9
  import { isTokenjuiceExecutablePath, parseShellWords } from "../shared/hook-command.js";
10
10
  import { buildCompactedOutputContext, writeEmptyHookJsonLine, writeHookJsonLine } from "../shared/hook-output.js";
11
11
  import { isRecord } from "../shared/hooks-json-file.js";
12
+ import { readSettingsFile, writeSettingsFile } from "../shared/settings-file.js";
12
13
  const TOKENJUICE_DROID_SUBCOMMAND = "droid-post-tool-use";
13
14
  const TOKENJUICE_DROID_FIX_COMMAND = "tokenjuice install droid";
14
15
  const TOKENJUICE_DROID_ADVISORY = "Droid PostToolUse hook compacts Execute shell output before it returns to the agent.";
@@ -40,26 +41,6 @@ async function readFactorySettings(settingsPath) {
40
41
  throw error;
41
42
  }
42
43
  }
43
- async function loadFactorySettingsWithBackup(settingsPath) {
44
- try {
45
- const rawText = await readFile(settingsPath, "utf8");
46
- const backupPath = `${settingsPath}.bak`;
47
- await writeFile(backupPath, rawText, "utf8");
48
- return { config: sanitizeFactorySettings(JSON.parse(rawText)), backupPath };
49
- }
50
- catch (error) {
51
- if (error.code === "ENOENT") {
52
- return { config: { hooks: {} } };
53
- }
54
- throw error;
55
- }
56
- }
57
- async function writeFactorySettings(settingsPath, config) {
58
- await mkdir(dirname(settingsPath), { recursive: true });
59
- const tempPath = `${settingsPath}.tmp`;
60
- await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
61
- await rename(tempPath, settingsPath);
62
- }
63
44
  function isTokenjuiceDroidHook(entry) {
64
45
  return isRecord(entry)
65
46
  && typeof entry.command === "string"
@@ -122,12 +103,13 @@ function createDroidPostToolUseHook(command) {
122
103
  };
123
104
  }
124
105
  export async function installDroidHook(settingsPath = getDefaultSettingsPath(), options = {}) {
125
- const { config, backupPath } = await loadFactorySettingsWithBackup(settingsPath);
106
+ const settings = await readSettingsFile(settingsPath);
107
+ const config = sanitizeFactorySettings(settings.data ? JSON.parse(settings.data.toString("utf8")) : undefined);
126
108
  const command = await buildTokenjuiceHookCommand(TOKENJUICE_DROID_SUBCOMMAND, "droid", options);
127
109
  removeTokenjuiceDroidHooks(config);
128
110
  const postToolUse = getPostToolUseGroups(config);
129
111
  config.hooks.PostToolUse = [...postToolUse, createDroidPostToolUseHook(command)];
130
- await writeFactorySettings(settingsPath, config);
112
+ const backupPath = await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`, "replace");
131
113
  return {
132
114
  settingsPath,
133
115
  ...(backupPath ? { backupPath } : {}),
@@ -135,13 +117,14 @@ export async function installDroidHook(settingsPath = getDefaultSettingsPath(),
135
117
  };
136
118
  }
137
119
  export async function uninstallDroidHook(settingsPath = getDefaultSettingsPath()) {
138
- const { config, exists } = await readFactorySettings(settingsPath);
139
- if (!exists) {
120
+ const settings = await readSettingsFile(settingsPath);
121
+ if (!settings.data) {
140
122
  return { settingsPath, removed: 0 };
141
123
  }
124
+ const config = sanitizeFactorySettings(JSON.parse(settings.data.toString("utf8")));
142
125
  const removed = removeTokenjuiceDroidHooks(config);
143
126
  if (removed > 0) {
144
- await writeFactorySettings(settingsPath, config);
127
+ await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`);
145
128
  }
146
129
  return { settingsPath, removed };
147
130
  }
@@ -0,0 +1,10 @@
1
+ import { type Stats } from "node:fs";
2
+ export type SettingsFile = {
3
+ path: string;
4
+ logicalPath: string;
5
+ targetPath: string;
6
+ data?: Buffer;
7
+ metadata?: Stats;
8
+ };
9
+ export declare function readSettingsFile(path: string): Promise<SettingsFile>;
10
+ export declare function writeSettingsFile(original: SettingsFile, text: string, backup?: "replace" | "preserve"): Promise<string | undefined>;
@@ -0,0 +1,165 @@
1
+ import { constants } from "node:fs";
2
+ import { link, lstat, mkdir, mkdtemp, open, realpath, rename, rm } from "node:fs/promises";
3
+ import { basename, dirname, join, resolve } from "node:path";
4
+ function changed(file) {
5
+ return new Error(`settings changed while updating ${file.path}; retry after other settings edits finish`);
6
+ }
7
+ async function readTarget(targetPath) {
8
+ const handle = await open(targetPath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
9
+ try {
10
+ const metadata = await handle.stat();
11
+ if (!metadata.isFile()) {
12
+ throw new Error(`settings path is not a regular file: ${targetPath}`);
13
+ }
14
+ return { data: await handle.readFile(), metadata };
15
+ }
16
+ finally {
17
+ await handle.close();
18
+ }
19
+ }
20
+ function sameMetadata(left, right) {
21
+ return left.dev === right.dev && left.ino === right.ino && left.mode === right.mode
22
+ && left.uid === right.uid && left.gid === right.gid && left.size === right.size
23
+ && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
24
+ }
25
+ async function assertUnchanged(file) {
26
+ try {
27
+ if (!file.metadata) {
28
+ try {
29
+ await lstat(file.logicalPath);
30
+ }
31
+ catch (error) {
32
+ if (error.code === "ENOENT"
33
+ && await realpath(dirname(file.logicalPath)) === dirname(file.targetPath)) {
34
+ return;
35
+ }
36
+ throw error;
37
+ }
38
+ throw changed(file);
39
+ }
40
+ if (await realpath(file.logicalPath) !== file.targetPath) {
41
+ throw changed(file);
42
+ }
43
+ const current = await readTarget(file.targetPath);
44
+ if (!sameMetadata(file.metadata, current.metadata) || !file.data?.equals(current.data)) {
45
+ throw changed(file);
46
+ }
47
+ }
48
+ catch {
49
+ throw changed(file);
50
+ }
51
+ }
52
+ export async function readSettingsFile(path) {
53
+ const logicalPath = resolve(path);
54
+ let targetPath;
55
+ try {
56
+ targetPath = await realpath(logicalPath);
57
+ }
58
+ catch (error) {
59
+ if (error.code === "ENOENT") {
60
+ // A dangling settings link is not an absent configuration. Keep it intact.
61
+ try {
62
+ await lstat(logicalPath);
63
+ }
64
+ catch (missing) {
65
+ if (missing.code === "ENOENT") {
66
+ return { path, logicalPath, targetPath: logicalPath };
67
+ }
68
+ throw missing;
69
+ }
70
+ }
71
+ throw error;
72
+ }
73
+ const file = { path, logicalPath, targetPath, ...await readTarget(targetPath) };
74
+ await assertUnchanged(file);
75
+ return file;
76
+ }
77
+ async function stageFile(parent, data, metadata) {
78
+ const directory = await mkdtemp(join(parent, ".tokenjuice-settings-"));
79
+ const path = join(directory, "write");
80
+ try {
81
+ const handle = await open(path, "wx", 0o600);
82
+ try {
83
+ await handle.writeFile(data);
84
+ if (metadata) {
85
+ const staged = await handle.stat();
86
+ if (staged.uid !== metadata.uid || staged.gid !== metadata.gid) {
87
+ await handle.chown(metadata.uid, metadata.gid);
88
+ }
89
+ await handle.chmod(metadata.mode & 0o7777);
90
+ }
91
+ }
92
+ finally {
93
+ await handle.close();
94
+ }
95
+ return { directory, path };
96
+ }
97
+ catch (error) {
98
+ await rm(directory, { recursive: true, force: true });
99
+ throw error;
100
+ }
101
+ }
102
+ export async function writeSettingsFile(original, text, backup) {
103
+ let file = original;
104
+ if (!file.metadata) {
105
+ await mkdir(dirname(file.logicalPath), { recursive: true, mode: 0o700 });
106
+ file = { ...file, targetPath: join(await realpath(dirname(file.logicalPath)), basename(file.logicalPath)) };
107
+ }
108
+ await assertUnchanged(file);
109
+ const staged = await stageFile(dirname(file.targetPath), Buffer.from(text), file.metadata);
110
+ let stagedBackup;
111
+ try {
112
+ let backupPath;
113
+ if (backup && file.data) {
114
+ const backupParent = await realpath(dirname(file.logicalPath));
115
+ stagedBackup = await stageFile(backupParent, file.data, file.metadata);
116
+ await assertUnchanged(file);
117
+ if (await realpath(dirname(file.logicalPath)) !== backupParent) {
118
+ throw changed(file);
119
+ }
120
+ for (let index = 0;; index += 1) {
121
+ const suffix = index === 0 ? ".bak" : `.bak.${index}`;
122
+ const target = join(backupParent, `${basename(file.logicalPath)}${suffix}`);
123
+ if (backup === "replace" && index === 0) {
124
+ // A managed settings link may itself point through the usual backup.
125
+ // Keep that chain intact and reserve a numbered backup instead.
126
+ try {
127
+ if (await realpath(target) === file.targetPath) {
128
+ continue;
129
+ }
130
+ }
131
+ catch (error) {
132
+ if (error.code !== "ENOENT") {
133
+ throw error;
134
+ }
135
+ }
136
+ await rename(stagedBackup.path, target);
137
+ }
138
+ else {
139
+ try {
140
+ await link(stagedBackup.path, target);
141
+ }
142
+ catch (error) {
143
+ if (error.code === "EEXIST") {
144
+ continue;
145
+ }
146
+ throw error;
147
+ }
148
+ }
149
+ backupPath = `${file.path}${suffix}`;
150
+ break;
151
+ }
152
+ }
153
+ // Pin the resolved target instead of replacing the logical symlink. Recheck
154
+ // edits and retargeting after staging; portable rename is not a cross-process CAS.
155
+ await assertUnchanged(file);
156
+ await rename(staged.path, file.targetPath);
157
+ return backupPath;
158
+ }
159
+ finally {
160
+ await rm(staged.directory, { recursive: true, force: true });
161
+ if (stagedBackup) {
162
+ await rm(stagedBackup.directory, { recursive: true, force: true });
163
+ }
164
+ }
165
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenjuice",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "Lean output compaction for terminal-heavy agent workflows.",
5
5
  "keywords": [
6
6
  "cli",
@@ -8,7 +8,7 @@
8
8
  "description": "Compacts exec and bash tool results with tokenjuice reducers.",
9
9
  "catalog": { "featured": true, "order": 60 },
10
10
  "contracts": {
11
- "agentToolResultMiddleware": ["openclaw", "codex"]
11
+ "agentToolResultMiddleware": ["openclaw", "codex", "agentsapi"]
12
12
  },
13
13
  "configSchema": {
14
14
  "type": "object",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/tokenjuice",
3
- "version": "2026.9.6",
3
+ "version": "2026.9.7",
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.8.4"
11
+ "tokenjuice": "0.8.5"
12
12
  },
13
13
  "peerDependencies": {
14
- "openclaw": ">=2026.9.6"
14
+ "openclaw": ">=2026.9.7"
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.9.6"
32
+ "pluginApi": ">=2026.9.7"
33
33
  },
34
34
  "build": {
35
- "openclawVersion": "2026.9.6",
35
+ "openclawVersion": "2026.9.7",
36
36
  "bundledDist": false
37
37
  },
38
38
  "release": {