@openclaw/tokenjuice 2026.9.4 → 2026.9.6
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/activity.svg +3 -0
- package/assets/icon.png +0 -0
- package/node_modules/tokenjuice/README.md +10 -1
- package/node_modules/tokenjuice/dist/cli/install-output.d.ts +7 -0
- package/node_modules/tokenjuice/dist/cli/install-output.js +19 -0
- package/node_modules/tokenjuice/dist/cli/main.d.ts +7 -0
- package/node_modules/tokenjuice/dist/cli/main.js +201 -36
- package/node_modules/tokenjuice/dist/core/analysis.js +3 -3
- package/node_modules/tokenjuice/dist/core/artifacts.d.ts +6 -1
- package/node_modules/tokenjuice/dist/core/artifacts.js +122 -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/compaction-metadata.d.ts +1 -1
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +3 -2
- package/node_modules/tokenjuice/dist/core/reduce.js +23 -10
- package/node_modules/tokenjuice/dist/core/text.d.ts +4 -0
- package/node_modules/tokenjuice/dist/core/text.js +32 -0
- package/node_modules/tokenjuice/dist/core/wrap.js +1 -1
- package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +31 -1
- package/node_modules/tokenjuice/dist/hosts/codex/index.js +554 -288
- package/node_modules/tokenjuice/dist/hosts/droid/index.js +12 -3
- package/node_modules/tokenjuice/dist/hosts/grok-bot/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/grok-bot/index.js +644 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +644 -279
- package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +647 -282
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.js +80 -1
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command.d.ts +19 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command.js +61 -6
- package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.d.ts +3 -1
- package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.js +2 -0
- package/node_modules/tokenjuice/dist/hosts/shared/host-command.d.ts +10 -1
- package/node_modules/tokenjuice/dist/hosts/shared/host-command.js +43 -4
- package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.js +9 -7
- package/node_modules/tokenjuice/dist/index.d.ts +3 -1
- package/node_modules/tokenjuice/dist/index.js +2 -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 +8 -6
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
export type HookCommandRuntimeMismatch = {
|
|
2
|
+
configuredPath: string;
|
|
3
|
+
expectedPath: string;
|
|
4
|
+
};
|
|
5
|
+
export type HookCommandPackageVersionMismatch = {
|
|
6
|
+
launcherPath: string;
|
|
7
|
+
resolvedPath: string;
|
|
8
|
+
resolvedVersion: string;
|
|
9
|
+
expectedVersion: string;
|
|
10
|
+
};
|
|
11
|
+
export type HookCommandInspection = {
|
|
12
|
+
checkedPaths: string[];
|
|
13
|
+
missingPaths: string[];
|
|
14
|
+
nonExecutablePaths: string[];
|
|
15
|
+
runtimePath?: string;
|
|
16
|
+
runtimeMismatch?: HookCommandRuntimeMismatch;
|
|
17
|
+
packageVersionMismatch?: HookCommandPackageVersionMismatch;
|
|
18
|
+
};
|
|
1
19
|
export type HookCommandDoctorStatus = "ok" | "broken" | "disabled";
|
|
2
20
|
export type HookCommandDoctorFields = {
|
|
3
21
|
status: HookCommandDoctorStatus;
|
|
@@ -9,6 +27,12 @@ export type HookCommandDoctorFields = {
|
|
|
9
27
|
checkedPaths: string[];
|
|
10
28
|
missingPaths: string[];
|
|
11
29
|
};
|
|
30
|
+
export declare function inspectTokenjuiceHookCommand(options: {
|
|
31
|
+
command: string;
|
|
32
|
+
expectedNodePath?: string;
|
|
33
|
+
expectedPackageVersion?: string;
|
|
34
|
+
platform?: NodeJS.Platform;
|
|
35
|
+
}): Promise<HookCommandInspection>;
|
|
12
36
|
export declare function buildHookCommandDoctorFields(options: {
|
|
13
37
|
expectedCommand: string;
|
|
14
38
|
detectedCommand: string | undefined;
|
|
@@ -1,4 +1,83 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
import { findMissingHookCommandPaths, isExecutableFile, parseTokenjuiceHookCommand, pathExists, } from "./host-command.js";
|
|
4
|
+
function extractHomebrewCellarVersion(path) {
|
|
5
|
+
const normalized = path.replace(/\\/gu, "/");
|
|
6
|
+
return normalized.match(/\/Cellar\/tokenjuice\/([^/]+)\//u)?.[1];
|
|
7
|
+
}
|
|
8
|
+
async function pathsResolveToSameFile(left, right) {
|
|
9
|
+
if (left === right) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return await realpath(left) === await realpath(right);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function isNodeInvokedJavaScriptLauncher(path, runtimePath, launcherPath) {
|
|
20
|
+
if (!runtimePath || path !== launcherPath) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
return (await realpath(path)).endsWith(".js");
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function inspectTokenjuiceHookCommand(options) {
|
|
31
|
+
const parsed = parseTokenjuiceHookCommand(options.command, options.platform);
|
|
32
|
+
const missingPaths = await findMissingHookCommandPaths(options.command, options.platform);
|
|
33
|
+
const nonExecutablePaths = [];
|
|
34
|
+
for (const path of parsed.checkedPaths) {
|
|
35
|
+
if (missingPaths.includes(path)
|
|
36
|
+
|| path.endsWith(".js")
|
|
37
|
+
|| await isNodeInvokedJavaScriptLauncher(path, parsed.runtimePath, parsed.launcherPath)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!(await isExecutableFile(path))) {
|
|
41
|
+
nonExecutablePaths.push(path);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let runtimeMismatch;
|
|
45
|
+
if (parsed.runtimePath
|
|
46
|
+
&& options.expectedNodePath
|
|
47
|
+
&& isAbsolute(parsed.runtimePath)
|
|
48
|
+
&& !(await pathsResolveToSameFile(parsed.runtimePath, options.expectedNodePath))) {
|
|
49
|
+
runtimeMismatch = {
|
|
50
|
+
configuredPath: parsed.runtimePath,
|
|
51
|
+
expectedPath: options.expectedNodePath,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
let packageVersionMismatch;
|
|
55
|
+
if (parsed.launcherPath && options.expectedPackageVersion && await pathExists(parsed.launcherPath)) {
|
|
56
|
+
try {
|
|
57
|
+
const resolvedPath = await realpath(parsed.launcherPath);
|
|
58
|
+
const resolvedVersion = extractHomebrewCellarVersion(resolvedPath);
|
|
59
|
+
if (resolvedVersion && resolvedVersion !== options.expectedPackageVersion) {
|
|
60
|
+
packageVersionMismatch = {
|
|
61
|
+
launcherPath: parsed.launcherPath,
|
|
62
|
+
resolvedPath,
|
|
63
|
+
resolvedVersion,
|
|
64
|
+
expectedVersion: options.expectedPackageVersion,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Missing and unreadable paths are reported separately.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
checkedPaths: parsed.checkedPaths,
|
|
74
|
+
missingPaths,
|
|
75
|
+
nonExecutablePaths,
|
|
76
|
+
...(parsed.runtimePath ? { runtimePath: parsed.runtimePath } : {}),
|
|
77
|
+
...(runtimeMismatch ? { runtimeMismatch } : {}),
|
|
78
|
+
...(packageVersionMismatch ? { packageVersionMismatch } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
2
81
|
export async function buildHookCommandDoctorFields(options) {
|
|
3
82
|
if (!options.detectedCommand) {
|
|
4
83
|
return {
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
export declare function isTokenjuiceExecutablePath(value: string): boolean;
|
|
2
2
|
export declare function shellQuote(value: string, platform?: NodeJS.Platform): string;
|
|
3
|
+
/**
|
|
4
|
+
* Quote a value for a POSIX shell, regardless of the host platform.
|
|
5
|
+
*
|
|
6
|
+
* `shellQuote` picks its quoting style from `process.platform`, which is the
|
|
7
|
+
* right question for a *path* going into a host config file: on win32 it wraps
|
|
8
|
+
* in double quotes without escaping, and that is safe because a Windows path
|
|
9
|
+
* cannot contain `"` in the first place.
|
|
10
|
+
*
|
|
11
|
+
* It is the wrong question for a *command* that we are about to hand to a
|
|
12
|
+
* POSIX shell via `-lc`. There the parser is the shell we resolved, not the
|
|
13
|
+
* platform we happen to be running on, and user commands routinely contain
|
|
14
|
+
* quotes. Wrapping `git commit -m "fix: thing"` in bare double quotes on
|
|
15
|
+
* Windows yields `-lc "git commit -m "fix: thing""`, which bash re-splits into
|
|
16
|
+
* `git commit -m fix: thing` -- a different command, silently.
|
|
17
|
+
*
|
|
18
|
+
* Callers building a command line that a POSIX shell will parse must use this
|
|
19
|
+
* for every argv item, including Windows paths and the `-lc` payload.
|
|
20
|
+
*/
|
|
21
|
+
export declare function posixShellQuote(value: string): string;
|
|
3
22
|
export declare function parseShellWords(command: string, platform?: NodeJS.Platform): string[];
|
|
4
23
|
export declare function isNodeExecutablePath(value: string): boolean;
|
|
5
24
|
export declare function extractHookCommandPaths(command: string, platform?: NodeJS.Platform): string[];
|
|
@@ -26,6 +26,30 @@ export function shellQuote(value, platform = process.platform) {
|
|
|
26
26
|
if (platform === "win32") {
|
|
27
27
|
return `"${value}"`;
|
|
28
28
|
}
|
|
29
|
+
return posixShellQuote(value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Quote a value for a POSIX shell, regardless of the host platform.
|
|
33
|
+
*
|
|
34
|
+
* `shellQuote` picks its quoting style from `process.platform`, which is the
|
|
35
|
+
* right question for a *path* going into a host config file: on win32 it wraps
|
|
36
|
+
* in double quotes without escaping, and that is safe because a Windows path
|
|
37
|
+
* cannot contain `"` in the first place.
|
|
38
|
+
*
|
|
39
|
+
* It is the wrong question for a *command* that we are about to hand to a
|
|
40
|
+
* POSIX shell via `-lc`. There the parser is the shell we resolved, not the
|
|
41
|
+
* platform we happen to be running on, and user commands routinely contain
|
|
42
|
+
* quotes. Wrapping `git commit -m "fix: thing"` in bare double quotes on
|
|
43
|
+
* Windows yields `-lc "git commit -m "fix: thing""`, which bash re-splits into
|
|
44
|
+
* `git commit -m fix: thing` -- a different command, silently.
|
|
45
|
+
*
|
|
46
|
+
* Callers building a command line that a POSIX shell will parse must use this
|
|
47
|
+
* for every argv item, including Windows paths and the `-lc` payload.
|
|
48
|
+
*/
|
|
49
|
+
export function posixShellQuote(value) {
|
|
50
|
+
if (POSIX_SAFE_SHELL_WORD.test(value)) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
29
53
|
return `'${value.replace(/'/gu, `'\\''`)}'`;
|
|
30
54
|
}
|
|
31
55
|
export function parseShellWords(command, platform = process.platform) {
|
|
@@ -33,18 +57,46 @@ export function parseShellWords(command, platform = process.platform) {
|
|
|
33
57
|
let current = "";
|
|
34
58
|
let quote = null;
|
|
35
59
|
let escaping = false;
|
|
36
|
-
|
|
60
|
+
const chars = [...command];
|
|
61
|
+
for (let index = 0; index < chars.length; index += 1) {
|
|
62
|
+
const char = chars[index];
|
|
63
|
+
if (quote === "'") {
|
|
64
|
+
if (char === "'") {
|
|
65
|
+
quote = null;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
current += char;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
37
72
|
if (escaping) {
|
|
38
73
|
current += char;
|
|
39
74
|
escaping = false;
|
|
40
75
|
continue;
|
|
41
76
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
77
|
+
if (char === "\\") {
|
|
78
|
+
if (platform === "win32") {
|
|
79
|
+
current += char;
|
|
80
|
+
}
|
|
81
|
+
else if (chars[index + 1] === "\n") {
|
|
82
|
+
index += 1;
|
|
83
|
+
}
|
|
84
|
+
else if (quote === "\"") {
|
|
85
|
+
const next = chars[index + 1];
|
|
86
|
+
if (next === "$" || next === "`" || next === "\"" || next === "\\") {
|
|
87
|
+
escaping = true;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
current += char;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
escaping = true;
|
|
95
|
+
}
|
|
44
96
|
continue;
|
|
45
97
|
}
|
|
46
|
-
if (quote) {
|
|
47
|
-
if (char ===
|
|
98
|
+
if (quote === "\"") {
|
|
99
|
+
if (char === "\"") {
|
|
48
100
|
quote = null;
|
|
49
101
|
}
|
|
50
102
|
else {
|
|
@@ -87,7 +139,10 @@ export function extractHookCommandPaths(command, platform = process.platform) {
|
|
|
87
139
|
paths.add(first);
|
|
88
140
|
}
|
|
89
141
|
const second = argv[1];
|
|
90
|
-
if (first
|
|
142
|
+
if (first
|
|
143
|
+
&& second
|
|
144
|
+
&& isNodeExecutablePath(first)
|
|
145
|
+
&& (second.endsWith(".js") || isTokenjuiceExecutablePath(second))) {
|
|
91
146
|
paths.add(second);
|
|
92
147
|
}
|
|
93
148
|
return [...paths];
|
|
@@ -54,6 +54,7 @@ import type { GitLabDuoDoctorReport, GitLabDuoRuleOptions } from "../gitlab-duo/
|
|
|
54
54
|
import type { GooseDoctorReport, GooseHintsOptions } from "../goose/index.js";
|
|
55
55
|
import type { GreptileDoctorReport, GreptileRuleOptions } from "../greptile/index.js";
|
|
56
56
|
import type { GrokBuildDoctorReport, GrokBuildInstructionsOptions } from "../grok-build/index.js";
|
|
57
|
+
import type { GrokBotDoctorReport, GrokBotRuleOptions } from "../grok-bot/index.js";
|
|
57
58
|
import type { GrokCliDoctorReport, GrokCliHookCommandOptions } from "../grok-cli/index.js";
|
|
58
59
|
import type { GptmeDoctorReport, GptmeInstructionsOptions } from "../gptme/index.js";
|
|
59
60
|
import type { Jean2DoctorReport, Jean2InstructionsOptions } from "../jean2/index.js";
|
|
@@ -153,6 +154,7 @@ export type HookIntegrationDoctorReport = {
|
|
|
153
154
|
goose: GooseDoctorReport;
|
|
154
155
|
greptile: GreptileDoctorReport;
|
|
155
156
|
"grok-build": GrokBuildDoctorReport;
|
|
157
|
+
"grok-bot": GrokBotDoctorReport;
|
|
156
158
|
"grok-cli": GrokCliDoctorReport;
|
|
157
159
|
gptme: GptmeDoctorReport;
|
|
158
160
|
jean2: Jean2DoctorReport;
|
|
@@ -201,7 +203,7 @@ export type HookDoctorReport = {
|
|
|
201
203
|
status: HookHealthStatus;
|
|
202
204
|
integrations: HookIntegrationDoctorReport;
|
|
203
205
|
};
|
|
204
|
-
export type HookDoctorCommandOptions = AdalInstructionsOptions & AetherPromptOptions & AictlInstructionsOptions & AiMemoryProtocolOptions & AgentLayerInstructionsOptions & AgentInitInstructionsOptions & AgentlinkInstructionsOptions & AgentloomRuleOptions & AgentsCliMemoryOptions & AgentsMdInstructionsOptions & AgentsGeRuleOptions & AgentsMeshRuleOptions & AmazonQRuleOptions & AmpInstructionsOptions & AntigravityRuleOptions & AnywhereAgentsInstructionsOptions & AugmentRuleOptions & BazSkillOptions & BitoGuidelinesOptions & BlackboxSkillOptions & BlocksSkillOptions & ClawdbotSkillOptions & BobInstructionsOptions & BuilderRuleOptions & CharlieInstructionsOptions & CodeAntInstructionsOptions & CodebuffInstructionsOptions & CodegenInstructionsOptions & CommandCodeHookCommandOptions & CoderAgentsSkillOptions & CodeRabbitConfigOptions & DeepAgentsInstructionsOptions & DockerAgentPromptOptions & DotAgentsRuleOptions & EcaSkillOptions & ElyraSkillOptions & LocalCodePluginOptions & MiniSweAgentConfigOptions & SweAgentConfigOptions & StagewiseSkillOptions & PiGoSkillOptions & CodexHookCommandOptions & ClaudeCodeHookCommandOptions & CodeBuddyHookCommandOptions & CopilotAgentHookCommandOptions & CrushSkillOptions & DevinHookCommandOptions & DroidHookCommandOptions & FirebaseStudioRuleOptions & ForgeCodeInstructionsOptions & GitLabDuoRuleOptions & GooseHintsOptions & GreptileRuleOptions & GrokBuildInstructionsOptions & GrokCliHookCommandOptions & GptmeInstructionsOptions & Jean2InstructionsOptions & JetBrainsAiRuleOptions & JulesInstructionsOptions & KimiHookCommandOptions & KnownsInstructionsOptions & LeanCtlInstructionsOptions & McpAgentDefinitionOptions & MistralVibeInstructionsOptions & MuxHookCommandOptions & NovaKitInstructionsOptions & OnaSkillOptions & OpenInterpreterInstructionsOptions & OpenWebUIToolOptions & PlandexConventionOptions & QodoReviewConfigOptions & QoderInstructionsOptions & QwenCodeHookCommandOptions & ReplitInstructionsOptions & RovoInstructionsOptions & RulerRuleOptions & TabbySystemPromptOptions & TabnineInstructionsOptions & TraeRuleOptions & UiPathInstructionsOptions & WarpInstructionsOptions & ZencoderRuleOptions;
|
|
206
|
+
export type HookDoctorCommandOptions = AdalInstructionsOptions & AetherPromptOptions & AictlInstructionsOptions & AiMemoryProtocolOptions & AgentLayerInstructionsOptions & AgentInitInstructionsOptions & AgentlinkInstructionsOptions & AgentloomRuleOptions & AgentsCliMemoryOptions & AgentsMdInstructionsOptions & AgentsGeRuleOptions & AgentsMeshRuleOptions & AmazonQRuleOptions & AmpInstructionsOptions & AntigravityRuleOptions & AnywhereAgentsInstructionsOptions & AugmentRuleOptions & BazSkillOptions & BitoGuidelinesOptions & BlackboxSkillOptions & BlocksSkillOptions & ClawdbotSkillOptions & BobInstructionsOptions & BuilderRuleOptions & CharlieInstructionsOptions & CodeAntInstructionsOptions & CodebuffInstructionsOptions & CodegenInstructionsOptions & CommandCodeHookCommandOptions & CoderAgentsSkillOptions & CodeRabbitConfigOptions & DeepAgentsInstructionsOptions & DockerAgentPromptOptions & DotAgentsRuleOptions & EcaSkillOptions & ElyraSkillOptions & LocalCodePluginOptions & MiniSweAgentConfigOptions & SweAgentConfigOptions & StagewiseSkillOptions & PiGoSkillOptions & CodexHookCommandOptions & ClaudeCodeHookCommandOptions & CodeBuddyHookCommandOptions & CopilotAgentHookCommandOptions & CrushSkillOptions & DevinHookCommandOptions & DroidHookCommandOptions & FirebaseStudioRuleOptions & ForgeCodeInstructionsOptions & GitLabDuoRuleOptions & GooseHintsOptions & GreptileRuleOptions & GrokBuildInstructionsOptions & GrokBotRuleOptions & GrokCliHookCommandOptions & GptmeInstructionsOptions & Jean2InstructionsOptions & JetBrainsAiRuleOptions & JulesInstructionsOptions & KimiHookCommandOptions & KnownsInstructionsOptions & LeanCtlInstructionsOptions & McpAgentDefinitionOptions & MistralVibeInstructionsOptions & MuxHookCommandOptions & NovaKitInstructionsOptions & OnaSkillOptions & OpenInterpreterInstructionsOptions & OpenWebUIToolOptions & PlandexConventionOptions & QodoReviewConfigOptions & QoderInstructionsOptions & QwenCodeHookCommandOptions & ReplitInstructionsOptions & RovoInstructionsOptions & RulerRuleOptions & TabbySystemPromptOptions & TabnineInstructionsOptions & TraeRuleOptions & UiPathInstructionsOptions & WarpInstructionsOptions & ZencoderRuleOptions;
|
|
205
207
|
export type HookIntegrationDoctorEntry = [
|
|
206
208
|
keyof HookIntegrationDoctorReport,
|
|
207
209
|
HookIntegrationDoctorReport[keyof HookIntegrationDoctorReport]
|
|
@@ -54,6 +54,7 @@ import { doctorGitLabDuoRule } from "../gitlab-duo/index.js";
|
|
|
54
54
|
import { doctorGooseHints } from "../goose/index.js";
|
|
55
55
|
import { doctorGreptileRule } from "../greptile/index.js";
|
|
56
56
|
import { doctorGrokBuildInstructions } from "../grok-build/index.js";
|
|
57
|
+
import { doctorGrokBotRule } from "../grok-bot/index.js";
|
|
57
58
|
import { doctorGrokCliHook } from "../grok-cli/index.js";
|
|
58
59
|
import { doctorGptmeInstructions } from "../gptme/index.js";
|
|
59
60
|
import { doctorJean2Instructions } from "../jean2/index.js";
|
|
@@ -152,6 +153,7 @@ const hookDoctorIntegrationDoctors = {
|
|
|
152
153
|
goose: (options) => doctorGooseHints(undefined, { ...getHookCommandOptions(options), scanProjectTree: false }),
|
|
153
154
|
greptile: (options) => doctorGreptileRule(undefined, getHookCommandOptions(options)),
|
|
154
155
|
"grok-build": (options) => doctorGrokBuildInstructions(undefined, getHookCommandOptions(options)),
|
|
156
|
+
"grok-bot": (options) => doctorGrokBotRule(undefined, getHookCommandOptions(options)),
|
|
155
157
|
"grok-cli": (options) => doctorGrokCliHook(undefined, getHookCommandOptions(options)),
|
|
156
158
|
gptme: (options) => doctorGptmeInstructions(undefined, getHookCommandOptions(options)),
|
|
157
159
|
jean2: (options) => doctorJean2Instructions(undefined, getHookCommandOptions(options)),
|
|
@@ -2,9 +2,18 @@ export type TokenjuiceHookCommandOptions = {
|
|
|
2
2
|
local?: boolean;
|
|
3
3
|
binaryPath?: string;
|
|
4
4
|
nodePath?: string;
|
|
5
|
+
pinNodeForJavaScriptLauncher?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ParsedTokenjuiceHookCommand = {
|
|
8
|
+
argv: string[];
|
|
9
|
+
checkedPaths: string[];
|
|
10
|
+
runtimePath?: string;
|
|
11
|
+
launcherPath?: string;
|
|
12
|
+
subcommand?: string;
|
|
5
13
|
};
|
|
6
14
|
export declare function isExecutableFile(path: string): Promise<boolean>;
|
|
7
15
|
export declare function pathExists(path: string): Promise<boolean>;
|
|
8
16
|
export declare function resolveInstalledTokenjuicePath(): Promise<string | undefined>;
|
|
9
17
|
export declare function buildTokenjuiceHookCommand(subcommand: string, hostLabel: string, options?: TokenjuiceHookCommandOptions): Promise<string>;
|
|
10
|
-
export declare function
|
|
18
|
+
export declare function parseTokenjuiceHookCommand(command: string, platform?: NodeJS.Platform): ParsedTokenjuiceHookCommand;
|
|
19
|
+
export declare function findMissingHookCommandPaths(command: string, platform?: NodeJS.Platform): Promise<string[]>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { constants as fsConstants } from "node:fs";
|
|
2
|
-
import { access } from "node:fs/promises";
|
|
2
|
+
import { access, realpath, stat } from "node:fs/promises";
|
|
3
3
|
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
4
|
-
import { extractHookCommandPaths, shellQuote } from "./hook-command.js";
|
|
4
|
+
import { extractHookCommandPaths, isNodeExecutablePath, isTokenjuiceExecutablePath, parseShellWords, shellQuote, } from "./hook-command.js";
|
|
5
5
|
export async function isExecutableFile(path) {
|
|
6
6
|
try {
|
|
7
|
+
if (!(await stat(path)).isFile()) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
7
10
|
await access(path, fsConstants.X_OK);
|
|
8
11
|
return true;
|
|
9
12
|
}
|
|
@@ -53,13 +56,49 @@ export async function buildTokenjuiceHookCommand(subcommand, hostLabel, options
|
|
|
53
56
|
const installedBinaryPath = await resolveInstalledTokenjuicePath();
|
|
54
57
|
launcher = installedBinaryPath ?? binaryPath;
|
|
55
58
|
}
|
|
59
|
+
if (!options.local && options.pinNodeForJavaScriptLauncher) {
|
|
60
|
+
try {
|
|
61
|
+
if ((await realpath(launcher)).endsWith(".js")) {
|
|
62
|
+
return `${shellQuote(nodePath)} ${shellQuote(launcher)} ${subcommand}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Preserve package-manager launchers when their final target cannot be inspected.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
56
69
|
if (launcher.endsWith(".js")) {
|
|
57
70
|
return `${shellQuote(nodePath)} ${shellQuote(launcher)} ${subcommand}`;
|
|
58
71
|
}
|
|
59
72
|
return `${shellQuote(launcher)} ${subcommand}`;
|
|
60
73
|
}
|
|
61
|
-
export
|
|
62
|
-
const
|
|
74
|
+
export function parseTokenjuiceHookCommand(command, platform = process.platform) {
|
|
75
|
+
const argv = parseShellWords(command, platform);
|
|
76
|
+
const first = argv[0];
|
|
77
|
+
const second = argv[1];
|
|
78
|
+
if (first && isNodeExecutablePath(first) && second) {
|
|
79
|
+
return {
|
|
80
|
+
argv,
|
|
81
|
+
checkedPaths: extractHookCommandPaths(command, platform),
|
|
82
|
+
runtimePath: first,
|
|
83
|
+
launcherPath: second,
|
|
84
|
+
...(argv[2] ? { subcommand: argv[2] } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (first && isTokenjuiceExecutablePath(first)) {
|
|
88
|
+
return {
|
|
89
|
+
argv,
|
|
90
|
+
checkedPaths: extractHookCommandPaths(command, platform),
|
|
91
|
+
launcherPath: first,
|
|
92
|
+
...(second ? { subcommand: second } : {}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
argv,
|
|
97
|
+
checkedPaths: extractHookCommandPaths(command, platform),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export async function findMissingHookCommandPaths(command, platform = process.platform) {
|
|
101
|
+
const paths = extractHookCommandPaths(command, platform);
|
|
63
102
|
const missing = [];
|
|
64
103
|
for (const path of paths) {
|
|
65
104
|
if (!(await pathExists(path))) {
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
import { constants as fsConstants } from "node:fs";
|
|
16
16
|
import { access } from "node:fs/promises";
|
|
17
17
|
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
18
|
-
import { stripLeadingCdPrefix
|
|
19
|
-
import { isNodeExecutablePath, isTokenjuiceExecutablePath, shellQuote } from "./hook-command.js";
|
|
18
|
+
import { stripLeadingCdPrefix } from "../../core/command.js";
|
|
19
|
+
import { isNodeExecutablePath, isTokenjuiceExecutablePath, parseShellWords, posixShellQuote, shellQuote, } from "./hook-command.js";
|
|
20
20
|
export function isRecord(value) {
|
|
21
21
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
22
|
}
|
|
@@ -148,10 +148,10 @@ export async function buildWrapLauncherHookCommand(options) {
|
|
|
148
148
|
export function buildWrappedCommand(params) {
|
|
149
149
|
const nodePath = params.nodePath ?? process.execPath;
|
|
150
150
|
const launcherCommand = params.wrapLauncher.endsWith(".js")
|
|
151
|
-
? `${
|
|
152
|
-
:
|
|
153
|
-
const sourceArgs = params.source ? ` --source ${
|
|
154
|
-
return `${launcherCommand} wrap${sourceArgs} -- ${
|
|
151
|
+
? `${posixShellQuote(nodePath)} ${posixShellQuote(params.wrapLauncher)}`
|
|
152
|
+
: posixShellQuote(params.wrapLauncher);
|
|
153
|
+
const sourceArgs = params.source ? ` --source ${posixShellQuote(params.source)}` : "";
|
|
154
|
+
return `${launcherCommand} wrap${sourceArgs} -- ${posixShellQuote(params.shellPath)} -lc ${posixShellQuote(params.command)}`;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* Detect whether a command has already been wrapped by tokenjuice. Matches
|
|
@@ -166,7 +166,9 @@ export function buildWrappedCommand(params) {
|
|
|
166
166
|
* (e.g. the user invoked `tokenjuice wrap --raw -- <cmd>` explicitly).
|
|
167
167
|
*/
|
|
168
168
|
export function commandAlreadyWrapped(command) {
|
|
169
|
-
|
|
169
|
+
// PreToolUse hosts execute this command through a POSIX shell, including
|
|
170
|
+
// Bash-compatible shells on Windows.
|
|
171
|
+
const argv = parseShellWords(stripLeadingCdPrefix(command), "linux");
|
|
170
172
|
if (argv.length < 2) {
|
|
171
173
|
return false;
|
|
172
174
|
}
|
|
@@ -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";
|
|
@@ -59,6 +59,7 @@ export { doctorGitLabDuoRule, installGitLabDuoRule, uninstallGitLabDuoRule } fro
|
|
|
59
59
|
export { doctorGooseHints, installGooseHints, uninstallGooseHints } from "./hosts/goose/index.js";
|
|
60
60
|
export { doctorGreptileRule, installGreptileRule, uninstallGreptileRule } from "./hosts/greptile/index.js";
|
|
61
61
|
export { doctorGrokBuildInstructions, installGrokBuildInstructions, uninstallGrokBuildInstructions } from "./hosts/grok-build/index.js";
|
|
62
|
+
export { doctorGrokBotRule, installGrokBotRule, uninstallGrokBotRule } from "./hosts/grok-bot/index.js";
|
|
62
63
|
export { doctorGrokCliHook, installGrokCliHook, runGrokCliPostToolUseHook, uninstallGrokCliHook } from "./hosts/grok-cli/index.js";
|
|
63
64
|
export { doctorGptmeInstructions, installGptmeInstructions, uninstallGptmeInstructions } from "./hosts/gptme/index.js";
|
|
64
65
|
export { doctorJean2Instructions, installJean2Instructions, uninstallJean2Instructions } from "./hosts/jean2/index.js";
|
|
@@ -167,6 +168,7 @@ export type { GitLabDuoDoctorReport, GitLabDuoRuleOptions, InstallGitLabDuoRuleR
|
|
|
167
168
|
export type { GreptileDoctorReport, GreptileRuleOptions, InstallGreptileRuleResult, UninstallGreptileRuleResult, } from "./hosts/greptile/index.js";
|
|
168
169
|
export type { GooseDoctorReport, GooseHintsOptions, InstallGooseHintsResult, UninstallGooseHintsResult, } from "./hosts/goose/index.js";
|
|
169
170
|
export type { GrokBuildDoctorReport, GrokBuildInstructionsOptions, InstallGrokBuildInstructionsResult, UninstallGrokBuildInstructionsResult, } from "./hosts/grok-build/index.js";
|
|
171
|
+
export type { GrokBotDoctorReport, GrokBotRuleOptions, InstallGrokBotRuleResult, UninstallGrokBotRuleResult, } from "./hosts/grok-bot/index.js";
|
|
170
172
|
export type { GrokCliDoctorReport, GrokCliHookCommandOptions, InstallGrokCliHookResult, UninstallGrokCliHookResult, } from "./hosts/grok-cli/index.js";
|
|
171
173
|
export type { GptmeDoctorReport, GptmeInstructionsOptions, InstallGptmeInstructionsResult, UninstallGptmeInstructionsResult, } from "./hosts/gptme/index.js";
|
|
172
174
|
export type { InstallJean2InstructionsResult, Jean2DoctorReport, Jean2InstructionsOptions, UninstallJean2InstructionsResult, } from "./hosts/jean2/index.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";
|
|
@@ -58,6 +58,7 @@ export { doctorGitLabDuoRule, installGitLabDuoRule, uninstallGitLabDuoRule } fro
|
|
|
58
58
|
export { doctorGooseHints, installGooseHints, uninstallGooseHints } from "./hosts/goose/index.js";
|
|
59
59
|
export { doctorGreptileRule, installGreptileRule, uninstallGreptileRule } from "./hosts/greptile/index.js";
|
|
60
60
|
export { doctorGrokBuildInstructions, installGrokBuildInstructions, uninstallGrokBuildInstructions } from "./hosts/grok-build/index.js";
|
|
61
|
+
export { doctorGrokBotRule, installGrokBotRule, uninstallGrokBotRule } from "./hosts/grok-bot/index.js";
|
|
61
62
|
export { doctorGrokCliHook, installGrokCliHook, runGrokCliPostToolUseHook, uninstallGrokCliHook } from "./hosts/grok-cli/index.js";
|
|
62
63
|
export { doctorGptmeInstructions, installGptmeInstructions, uninstallGptmeInstructions } from "./hosts/gptme/index.js";
|
|
63
64
|
export { doctorJean2Instructions, installJean2Instructions, uninstallJean2Instructions } from "./hosts/jean2/index.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;
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/tokenjuice",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.6",
|
|
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.
|
|
11
|
+
"tokenjuice": "0.8.4"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"openclaw": ">=2026.9.
|
|
14
|
+
"openclaw": ">=2026.9.6"
|
|
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.
|
|
32
|
+
"pluginApi": ">=2026.9.6"
|
|
33
33
|
},
|
|
34
34
|
"build": {
|
|
35
|
-
"openclawVersion": "2026.9.
|
|
35
|
+
"openclawVersion": "2026.9.6",
|
|
36
36
|
"bundledDist": false
|
|
37
37
|
},
|
|
38
38
|
"release": {
|
|
@@ -46,7 +46,9 @@
|
|
|
46
46
|
"files": [
|
|
47
47
|
"dist/**",
|
|
48
48
|
"openclaw.plugin.json",
|
|
49
|
-
"README.md"
|
|
49
|
+
"README.md",
|
|
50
|
+
"assets/icon.png",
|
|
51
|
+
"assets/activity.svg"
|
|
50
52
|
],
|
|
51
53
|
"bundledDependencies": [
|
|
52
54
|
"tokenjuice"
|