@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.
Files changed (29) hide show
  1. package/assets/icon.png +0 -0
  2. package/dist/index.js +1 -1
  3. package/node_modules/tokenjuice/README.md +4 -0
  4. package/node_modules/tokenjuice/dist/cli/main.d.ts +3 -0
  5. package/node_modules/tokenjuice/dist/cli/main.js +58 -10
  6. package/node_modules/tokenjuice/dist/core/analysis.js +3 -3
  7. package/node_modules/tokenjuice/dist/core/artifacts.d.ts +5 -1
  8. package/node_modules/tokenjuice/dist/core/artifacts.js +93 -45
  9. package/node_modules/tokenjuice/dist/core/bounded-jsonl.d.ts +26 -0
  10. package/node_modules/tokenjuice/dist/core/bounded-jsonl.js +407 -0
  11. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +1 -0
  12. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +2 -1
  13. package/node_modules/tokenjuice/dist/core/reduce.js +5 -0
  14. package/node_modules/tokenjuice/dist/core/wrap.js +1 -1
  15. package/node_modules/tokenjuice/dist/hosts/claude-code/index.js +12 -61
  16. package/node_modules/tokenjuice/dist/hosts/codebuddy/index.js +12 -61
  17. package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +6 -0
  18. package/node_modules/tokenjuice/dist/hosts/codex/index.js +365 -147
  19. package/node_modules/tokenjuice/dist/hosts/droid/index.js +21 -29
  20. package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +1489 -1193
  21. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +1471 -1175
  22. package/node_modules/tokenjuice/dist/hosts/shared/settings-file.d.ts +10 -0
  23. package/node_modules/tokenjuice/dist/hosts/shared/settings-file.js +165 -0
  24. package/node_modules/tokenjuice/dist/index.d.ts +1 -1
  25. package/node_modules/tokenjuice/dist/index.js +1 -1
  26. package/node_modules/tokenjuice/dist/types.d.ts +15 -0
  27. package/node_modules/tokenjuice/package.json +1 -1
  28. package/openclaw.plugin.json +1 -1
  29. package/package.json +5 -5
@@ -1,6 +1,7 @@
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
+ import { shouldRecordStats } from "../../core/artifacts.js";
4
5
  import { stripLeadingCdPrefix } from "../../core/command.js";
5
6
  import { compactBashResult } from "../../core/integrations/compact-bash-result.js";
6
7
  import { buildTokenjuiceHookCommand, } from "../shared/host-command.js";
@@ -8,6 +9,7 @@ import { buildHookCommandDoctorFields } from "../shared/hook-command-doctor.js";
8
9
  import { isTokenjuiceExecutablePath, parseShellWords } from "../shared/hook-command.js";
9
10
  import { buildCompactedOutputContext, writeEmptyHookJsonLine, writeHookJsonLine } from "../shared/hook-output.js";
10
11
  import { isRecord } from "../shared/hooks-json-file.js";
12
+ import { readSettingsFile, writeSettingsFile } from "../shared/settings-file.js";
11
13
  const TOKENJUICE_DROID_SUBCOMMAND = "droid-post-tool-use";
12
14
  const TOKENJUICE_DROID_FIX_COMMAND = "tokenjuice install droid";
13
15
  const TOKENJUICE_DROID_ADVISORY = "Droid PostToolUse hook compacts Execute shell output before it returns to the agent.";
@@ -39,26 +41,6 @@ async function readFactorySettings(settingsPath) {
39
41
  throw error;
40
42
  }
41
43
  }
42
- async function loadFactorySettingsWithBackup(settingsPath) {
43
- try {
44
- const rawText = await readFile(settingsPath, "utf8");
45
- const backupPath = `${settingsPath}.bak`;
46
- await writeFile(backupPath, rawText, "utf8");
47
- return { config: sanitizeFactorySettings(JSON.parse(rawText)), backupPath };
48
- }
49
- catch (error) {
50
- if (error.code === "ENOENT") {
51
- return { config: { hooks: {} } };
52
- }
53
- throw error;
54
- }
55
- }
56
- async function writeFactorySettings(settingsPath, config) {
57
- await mkdir(dirname(settingsPath), { recursive: true });
58
- const tempPath = `${settingsPath}.tmp`;
59
- await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
60
- await rename(tempPath, settingsPath);
61
- }
62
44
  function isTokenjuiceDroidHook(entry) {
63
45
  return isRecord(entry)
64
46
  && typeof entry.command === "string"
@@ -121,12 +103,13 @@ function createDroidPostToolUseHook(command) {
121
103
  };
122
104
  }
123
105
  export async function installDroidHook(settingsPath = getDefaultSettingsPath(), options = {}) {
124
- 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);
125
108
  const command = await buildTokenjuiceHookCommand(TOKENJUICE_DROID_SUBCOMMAND, "droid", options);
126
109
  removeTokenjuiceDroidHooks(config);
127
110
  const postToolUse = getPostToolUseGroups(config);
128
111
  config.hooks.PostToolUse = [...postToolUse, createDroidPostToolUseHook(command)];
129
- await writeFactorySettings(settingsPath, config);
112
+ const backupPath = await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`, "replace");
130
113
  return {
131
114
  settingsPath,
132
115
  ...(backupPath ? { backupPath } : {}),
@@ -134,13 +117,14 @@ export async function installDroidHook(settingsPath = getDefaultSettingsPath(),
134
117
  };
135
118
  }
136
119
  export async function uninstallDroidHook(settingsPath = getDefaultSettingsPath()) {
137
- const { config, exists } = await readFactorySettings(settingsPath);
138
- if (!exists) {
120
+ const settings = await readSettingsFile(settingsPath);
121
+ if (!settings.data) {
139
122
  return { settingsPath, removed: 0 };
140
123
  }
124
+ const config = sanitizeFactorySettings(JSON.parse(settings.data.toString("utf8")));
141
125
  const removed = removeTokenjuiceDroidHooks(config);
142
126
  if (removed > 0) {
143
- await writeFactorySettings(settingsPath, config);
127
+ await writeSettingsFile(settings, `${JSON.stringify(config, null, 2)}\n`);
144
128
  }
145
129
  return { settingsPath, removed };
146
130
  }
@@ -220,9 +204,17 @@ function stringifyToolResponse(value) {
220
204
  return String(value);
221
205
  }
222
206
  async function writeHookDebug(record) {
223
- const debugPath = join(getFactoryHome(), "tokenjuice-hook.last.json");
224
- await mkdir(dirname(debugPath), { recursive: true });
225
- await writeFile(debugPath, `${JSON.stringify(record, null, 2)}\n`, "utf8");
207
+ if (!shouldRecordStats()) {
208
+ return;
209
+ }
210
+ try {
211
+ const debugPath = join(getFactoryHome(), "tokenjuice-hook.last.json");
212
+ await mkdir(dirname(debugPath), { recursive: true });
213
+ await writeFile(debugPath, `${JSON.stringify(record, null, 2)}\n`, "utf8");
214
+ }
215
+ catch {
216
+ // Optional diagnostics must not fail a hook or duplicate an already-written response.
217
+ }
226
218
  }
227
219
  export async function runDroidPostToolUseHook(rawText) {
228
220
  let payload;