@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
@@ -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,4 +1,4 @@
1
- export { ARTIFACT_DIR_ENV, getArtifact, isValidArtifactId, listArtifactMetadata, listArtifacts, resolveArtifactBaseDir, storeArtifact, storeArtifactMetadata } from "./core/artifacts.js";
1
+ export { ARTIFACT_DIR_ENV, STATS_ENABLED_ENV, getArtifact, isValidArtifactId, listArtifactMetadata, listArtifactMetadataPage, listArtifacts, resolveArtifactBaseDir, shouldRecordStats, storeArtifact, storeArtifactMetadata } from "./core/artifacts.js";
2
2
  export { buildAnalysisEntry, discoverCandidates, doctorArtifacts, statsArtifacts } from "./core/analysis.js";
3
3
  export { classifyExecution } from "./core/classify.js";
4
4
  export { normalizeCommandSignature, normalizeEffectiveCommandSignature, normalizeExecutionInput, tokenizeCommand } from "./core/command.js";
@@ -1,4 +1,4 @@
1
- export { ARTIFACT_DIR_ENV, getArtifact, isValidArtifactId, listArtifactMetadata, listArtifacts, resolveArtifactBaseDir, storeArtifact, storeArtifactMetadata } from "./core/artifacts.js";
1
+ export { ARTIFACT_DIR_ENV, STATS_ENABLED_ENV, getArtifact, isValidArtifactId, listArtifactMetadata, listArtifactMetadataPage, listArtifacts, resolveArtifactBaseDir, shouldRecordStats, storeArtifact, storeArtifactMetadata } from "./core/artifacts.js";
2
2
  export { buildAnalysisEntry, discoverCandidates, doctorArtifacts, statsArtifacts } from "./core/analysis.js";
3
3
  export { classifyExecution } from "./core/classify.js";
4
4
  export { normalizeCommandSignature, normalizeEffectiveCommandSignature, normalizeExecutionInput, tokenizeCommand } from "./core/command.js";
@@ -106,6 +106,8 @@ export type StoredArtifactMetadata = {
106
106
  source?: string;
107
107
  toolName?: string;
108
108
  command?: string;
109
+ commandFamily?: string;
110
+ commandDigest?: string;
109
111
  exitCode?: number;
110
112
  captureTruncated?: boolean;
111
113
  classification: ClassificationResult;
@@ -118,8 +120,20 @@ export type ArtifactMetadataRef = {
118
120
  storage: "file";
119
121
  path?: string;
120
122
  metadataPath: string;
123
+ metadataFormat?: "json" | "jsonl-segment";
124
+ metadataRecordId?: string;
121
125
  metadata: StoredArtifactMetadata;
122
126
  };
127
+ export type ArtifactMetadataPage = {
128
+ entries: ArtifactMetadataRef[];
129
+ nextCursor?: string;
130
+ partial: boolean;
131
+ legacySidecarsIncluded: false;
132
+ };
133
+ export type ArtifactMetadataPageOptions = {
134
+ cursor?: string;
135
+ limit?: number;
136
+ };
123
137
  export type CompactResult = {
124
138
  inlineText: string;
125
139
  previewText?: string;
@@ -143,6 +157,7 @@ export type StoredArtifactInput = {
143
157
  input: ToolExecutionInput;
144
158
  rawText: string;
145
159
  classification: ClassificationResult;
160
+ recordStats?: boolean;
146
161
  stats?: {
147
162
  rawChars?: number;
148
163
  reducedChars: number;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenjuice",
3
- "version": "0.8.3",
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.5",
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.3"
11
+ "tokenjuice": "0.8.5"
12
12
  },
13
13
  "peerDependencies": {
14
- "openclaw": ">=2026.9.5"
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.5"
32
+ "pluginApi": ">=2026.9.7"
33
33
  },
34
34
  "build": {
35
- "openclawVersion": "2026.9.5",
35
+ "openclawVersion": "2026.9.7",
36
36
  "bundledDist": false
37
37
  },
38
38
  "release": {