@openclaw/tokenjuice 2026.9.5 → 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 +0 -0
- package/dist/index.js +1 -1
- package/node_modules/tokenjuice/README.md +4 -0
- package/node_modules/tokenjuice/dist/cli/main.d.ts +3 -0
- package/node_modules/tokenjuice/dist/cli/main.js +58 -10
- package/node_modules/tokenjuice/dist/core/analysis.js +3 -3
- package/node_modules/tokenjuice/dist/core/artifacts.d.ts +5 -1
- package/node_modules/tokenjuice/dist/core/artifacts.js +93 -45
- package/node_modules/tokenjuice/dist/core/bounded-jsonl.d.ts +26 -0
- package/node_modules/tokenjuice/dist/core/bounded-jsonl.js +407 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +1 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +2 -1
- package/node_modules/tokenjuice/dist/core/reduce.js +5 -0
- package/node_modules/tokenjuice/dist/core/wrap.js +1 -1
- package/node_modules/tokenjuice/dist/hosts/claude-code/index.js +12 -61
- package/node_modules/tokenjuice/dist/hosts/codebuddy/index.js +12 -61
- package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +6 -0
- package/node_modules/tokenjuice/dist/hosts/codex/index.js +365 -147
- package/node_modules/tokenjuice/dist/hosts/droid/index.js +21 -29
- package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +1489 -1193
- package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +1471 -1175
- package/node_modules/tokenjuice/dist/hosts/shared/settings-file.d.ts +10 -0
- package/node_modules/tokenjuice/dist/hosts/shared/settings-file.js +165 -0
- package/node_modules/tokenjuice/dist/index.d.ts +1 -1
- package/node_modules/tokenjuice/dist/index.js +1 -1
- package/node_modules/tokenjuice/dist/types.d.ts +15 -0
- package/node_modules/tokenjuice/package.json +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
|
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
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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(
|
|
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
|
|
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,9 +1,12 @@
|
|
|
1
1
|
import type { HookCommandPackageVersionMismatch, HookCommandRuntimeMismatch } from "../shared/hook-command-doctor.js";
|
|
2
|
+
declare const CODEX_HOOK_INTEGRATION_ID = "tokenjuice.post-tool-use";
|
|
2
3
|
export type InstallCodexHookResult = {
|
|
3
4
|
hooksPath: string;
|
|
4
5
|
backupPath?: string;
|
|
5
6
|
command: string;
|
|
6
7
|
featureFlag: CodexFeatureFlagStatus;
|
|
8
|
+
writer: "codex-hooks" | "standalone";
|
|
9
|
+
fragmentId: typeof CODEX_HOOK_INTEGRATION_ID;
|
|
7
10
|
};
|
|
8
11
|
export type CodexFeatureFlagStatus = {
|
|
9
12
|
/** Absolute path we looked at (`~/.codex/config.toml` by default). */
|
|
@@ -85,6 +88,8 @@ export type UninstallCodexHookResult = {
|
|
|
85
88
|
hooksPath: string;
|
|
86
89
|
backupPath?: string;
|
|
87
90
|
removed: number;
|
|
91
|
+
writer: "codex-hooks" | "standalone";
|
|
92
|
+
fragmentId: typeof CODEX_HOOK_INTEGRATION_ID;
|
|
88
93
|
};
|
|
89
94
|
/**
|
|
90
95
|
* Read-only scan of ~/.codex/config.toml for the modern `hooks = <bool>`
|
|
@@ -115,3 +120,4 @@ export declare function runCodexPostToolUseHook(rawText: string, options?: {
|
|
|
115
120
|
noOmit?: boolean;
|
|
116
121
|
allowOmit?: boolean;
|
|
117
122
|
}): Promise<number>;
|
|
123
|
+
export {};
|