@openclaw/tokenjuice 2026.5.28
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/README.md +35 -0
- package/dist/index.js +13 -0
- package/dist/runtime-api.js +2 -0
- package/dist/tool-result-middleware.js +34 -0
- package/node_modules/tokenjuice/LICENSE +21 -0
- package/node_modules/tokenjuice/README.md +311 -0
- package/node_modules/tokenjuice/SECURITY.md +50 -0
- package/node_modules/tokenjuice/dist/cli/doctor-output.d.ts +2 -0
- package/node_modules/tokenjuice/dist/cli/doctor-output.js +92 -0
- package/node_modules/tokenjuice/dist/cli/install-output.d.ts +5 -0
- package/node_modules/tokenjuice/dist/cli/install-output.js +11 -0
- package/node_modules/tokenjuice/dist/cli/main.d.ts +34 -0
- package/node_modules/tokenjuice/dist/cli/main.js +6614 -0
- package/node_modules/tokenjuice/dist/core/analysis.d.ts +88 -0
- package/node_modules/tokenjuice/dist/core/analysis.js +313 -0
- package/node_modules/tokenjuice/dist/core/artifacts.d.ts +9 -0
- package/node_modules/tokenjuice/dist/core/artifacts.js +210 -0
- package/node_modules/tokenjuice/dist/core/builtin-rules.generated.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/builtin-rules.generated.js +262 -0
- package/node_modules/tokenjuice/dist/core/classify.d.ts +18 -0
- package/node_modules/tokenjuice/dist/core/classify.js +181 -0
- package/node_modules/tokenjuice/dist/core/cli-client.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/cli-client.js +127 -0
- package/node_modules/tokenjuice/dist/core/command-identity.d.ts +9 -0
- package/node_modules/tokenjuice/dist/core/command-identity.js +201 -0
- package/node_modules/tokenjuice/dist/core/command-match.d.ts +16 -0
- package/node_modules/tokenjuice/dist/core/command-match.js +443 -0
- package/node_modules/tokenjuice/dist/core/command-shell.d.ts +18 -0
- package/node_modules/tokenjuice/dist/core/command-shell.js +291 -0
- package/node_modules/tokenjuice/dist/core/command.d.ts +5 -0
- package/node_modules/tokenjuice/dist/core/command.js +4 -0
- package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +10 -0
- package/node_modules/tokenjuice/dist/core/compaction-metadata.js +28 -0
- package/node_modules/tokenjuice/dist/core/env.d.ts +1 -0
- package/node_modules/tokenjuice/dist/core/env.js +5 -0
- package/node_modules/tokenjuice/dist/core/execution-input.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/execution-input.js +51 -0
- package/node_modules/tokenjuice/dist/core/fixtures.d.ts +14 -0
- package/node_modules/tokenjuice/dist/core/fixtures.js +190 -0
- package/node_modules/tokenjuice/dist/core/github-actions-summary.d.ts +6 -0
- package/node_modules/tokenjuice/dist/core/github-actions-summary.js +105 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +33 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +85 -0
- package/node_modules/tokenjuice/dist/core/integrations/rewrite-policy.d.ts +8 -0
- package/node_modules/tokenjuice/dist/core/integrations/rewrite-policy.js +25 -0
- package/node_modules/tokenjuice/dist/core/inventory-safety.d.ts +11 -0
- package/node_modules/tokenjuice/dist/core/inventory-safety.js +347 -0
- package/node_modules/tokenjuice/dist/core/json-protocol.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/json-protocol.js +131 -0
- package/node_modules/tokenjuice/dist/core/reduce-formatters.d.ts +15 -0
- package/node_modules/tokenjuice/dist/core/reduce-formatters.js +611 -0
- package/node_modules/tokenjuice/dist/core/reduce-inspection-summary.d.ts +9 -0
- package/node_modules/tokenjuice/dist/core/reduce-inspection-summary.js +125 -0
- package/node_modules/tokenjuice/dist/core/reduce-utils.d.ts +12 -0
- package/node_modules/tokenjuice/dist/core/reduce-utils.js +117 -0
- package/node_modules/tokenjuice/dist/core/reduce.d.ts +5 -0
- package/node_modules/tokenjuice/dist/core/reduce.js +511 -0
- package/node_modules/tokenjuice/dist/core/rules.d.ts +22 -0
- package/node_modules/tokenjuice/dist/core/rules.js +265 -0
- package/node_modules/tokenjuice/dist/core/source.d.ts +6 -0
- package/node_modules/tokenjuice/dist/core/source.js +113 -0
- package/node_modules/tokenjuice/dist/core/text.d.ts +23 -0
- package/node_modules/tokenjuice/dist/core/text.js +204 -0
- package/node_modules/tokenjuice/dist/core/time.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/time.js +82 -0
- package/node_modules/tokenjuice/dist/core/validate-rules.d.ts +10 -0
- package/node_modules/tokenjuice/dist/core/validate-rules.js +198 -0
- package/node_modules/tokenjuice/dist/core/wrap.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/wrap.js +104 -0
- package/node_modules/tokenjuice/dist/hosts/adal/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/adal/index.js +157 -0
- package/node_modules/tokenjuice/dist/hosts/aether/index.d.ts +30 -0
- package/node_modules/tokenjuice/dist/hosts/aether/index.js +671 -0
- package/node_modules/tokenjuice/dist/hosts/agent-layer/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/agent-layer/index.js +173 -0
- package/node_modules/tokenjuice/dist/hosts/agentinit/index.d.ts +27 -0
- package/node_modules/tokenjuice/dist/hosts/agentinit/index.js +252 -0
- package/node_modules/tokenjuice/dist/hosts/agentlink/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/agentlink/index.js +310 -0
- package/node_modules/tokenjuice/dist/hosts/agentloom/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/agentloom/index.js +161 -0
- package/node_modules/tokenjuice/dist/hosts/agents-cli/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/agents-cli/index.js +136 -0
- package/node_modules/tokenjuice/dist/hosts/agents-md/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/agents-md/index.js +240 -0
- package/node_modules/tokenjuice/dist/hosts/agentsge/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/agentsge/index.js +119 -0
- package/node_modules/tokenjuice/dist/hosts/agentsmesh/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/agentsmesh/index.js +337 -0
- package/node_modules/tokenjuice/dist/hosts/ai-memory-protocol/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/ai-memory-protocol/index.js +392 -0
- package/node_modules/tokenjuice/dist/hosts/aictl/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/aictl/index.js +271 -0
- package/node_modules/tokenjuice/dist/hosts/aider/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/aider/index.js +79 -0
- package/node_modules/tokenjuice/dist/hosts/amazon-q/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/amazon-q/index.js +169 -0
- package/node_modules/tokenjuice/dist/hosts/amp/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/amp/index.js +306 -0
- package/node_modules/tokenjuice/dist/hosts/antigravity/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/antigravity/index.js +172 -0
- package/node_modules/tokenjuice/dist/hosts/anywhere-agents/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/anywhere-agents/index.js +260 -0
- package/node_modules/tokenjuice/dist/hosts/augment/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/augment/index.js +171 -0
- package/node_modules/tokenjuice/dist/hosts/avante/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/avante/index.js +68 -0
- package/node_modules/tokenjuice/dist/hosts/baz/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/baz/index.js +286 -0
- package/node_modules/tokenjuice/dist/hosts/bito/index.d.ts +28 -0
- package/node_modules/tokenjuice/dist/hosts/bito/index.js +363 -0
- package/node_modules/tokenjuice/dist/hosts/blackbox/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/blackbox/index.js +305 -0
- package/node_modules/tokenjuice/dist/hosts/blocks/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/blocks/index.js +317 -0
- package/node_modules/tokenjuice/dist/hosts/bob/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/bob/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/builder/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/builder/index.js +177 -0
- package/node_modules/tokenjuice/dist/hosts/charlie/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/charlie/index.js +275 -0
- package/node_modules/tokenjuice/dist/hosts/claude-code/index.d.ts +30 -0
- package/node_modules/tokenjuice/dist/hosts/claude-code/index.js +364 -0
- package/node_modules/tokenjuice/dist/hosts/clawdbot/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/clawdbot/index.js +320 -0
- package/node_modules/tokenjuice/dist/hosts/cline/index.d.ts +27 -0
- package/node_modules/tokenjuice/dist/hosts/cline/index.js +156 -0
- package/node_modules/tokenjuice/dist/hosts/codeant/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/codeant/index.js +370 -0
- package/node_modules/tokenjuice/dist/hosts/codebuddy/index.d.ts +29 -0
- package/node_modules/tokenjuice/dist/hosts/codebuddy/index.js +379 -0
- package/node_modules/tokenjuice/dist/hosts/codebuff/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/codebuff/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/codegen/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/codegen/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/coder-agents/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/coder-agents/index.js +339 -0
- package/node_modules/tokenjuice/dist/hosts/coderabbit/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/coderabbit/index.js +599 -0
- package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +93 -0
- package/node_modules/tokenjuice/dist/hosts/codex/index.js +945 -0
- package/node_modules/tokenjuice/dist/hosts/command-code/index.d.ts +29 -0
- package/node_modules/tokenjuice/dist/hosts/command-code/index.js +366 -0
- package/node_modules/tokenjuice/dist/hosts/continue/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/continue/index.js +81 -0
- package/node_modules/tokenjuice/dist/hosts/copilot-agent/index.d.ts +29 -0
- package/node_modules/tokenjuice/dist/hosts/copilot-agent/index.js +497 -0
- package/node_modules/tokenjuice/dist/hosts/copilot-cli/index.d.ts +31 -0
- package/node_modules/tokenjuice/dist/hosts/copilot-cli/index.js +428 -0
- package/node_modules/tokenjuice/dist/hosts/crush/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/crush/index.js +135 -0
- package/node_modules/tokenjuice/dist/hosts/cursor/index.d.ts +30 -0
- package/node_modules/tokenjuice/dist/hosts/cursor/index.js +293 -0
- package/node_modules/tokenjuice/dist/hosts/deepagents/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/deepagents/index.js +157 -0
- package/node_modules/tokenjuice/dist/hosts/devin/index.d.ts +31 -0
- package/node_modules/tokenjuice/dist/hosts/devin/index.js +283 -0
- package/node_modules/tokenjuice/dist/hosts/docker-agent/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/docker-agent/index.js +206 -0
- package/node_modules/tokenjuice/dist/hosts/dot-agents/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/dot-agents/index.js +171 -0
- package/node_modules/tokenjuice/dist/hosts/droid/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/droid/index.js +313 -0
- package/node_modules/tokenjuice/dist/hosts/eca/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/eca/index.js +347 -0
- package/node_modules/tokenjuice/dist/hosts/elyra/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/elyra/index.js +382 -0
- package/node_modules/tokenjuice/dist/hosts/firebase-studio/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/firebase-studio/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/forgecode/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/forgecode/index.js +273 -0
- package/node_modules/tokenjuice/dist/hosts/gemini-cli/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/gemini-cli/index.js +234 -0
- package/node_modules/tokenjuice/dist/hosts/gitlab-duo/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/gitlab-duo/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/goose/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/goose/index.js +288 -0
- package/node_modules/tokenjuice/dist/hosts/gptme/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/gptme/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/greptile/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/greptile/index.js +299 -0
- package/node_modules/tokenjuice/dist/hosts/grok-build/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/grok-build/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/grok-cli/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/grok-cli/index.js +262 -0
- package/node_modules/tokenjuice/dist/hosts/jean2/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/jean2/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/jetbrains-ai/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/jetbrains-ai/index.js +202 -0
- package/node_modules/tokenjuice/dist/hosts/jules/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/jules/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/junie/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/junie/index.js +68 -0
- package/node_modules/tokenjuice/dist/hosts/kilo/index.d.ts +30 -0
- package/node_modules/tokenjuice/dist/hosts/kilo/index.js +497 -0
- package/node_modules/tokenjuice/dist/hosts/kimi/index.d.ts +29 -0
- package/node_modules/tokenjuice/dist/hosts/kimi/index.js +255 -0
- package/node_modules/tokenjuice/dist/hosts/kiro/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/kiro/index.js +116 -0
- package/node_modules/tokenjuice/dist/hosts/knowns/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/knowns/index.js +273 -0
- package/node_modules/tokenjuice/dist/hosts/leanctl/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/leanctl/index.js +317 -0
- package/node_modules/tokenjuice/dist/hosts/localcode/index.d.ts +31 -0
- package/node_modules/tokenjuice/dist/hosts/localcode/index.js +539 -0
- package/node_modules/tokenjuice/dist/hosts/mcp-agent/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/mcp-agent/index.js +302 -0
- package/node_modules/tokenjuice/dist/hosts/mini-swe-agent/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/mini-swe-agent/index.js +226 -0
- package/node_modules/tokenjuice/dist/hosts/mistral-vibe/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/mistral-vibe/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/mux/index.d.ts +28 -0
- package/node_modules/tokenjuice/dist/hosts/mux/index.js +411 -0
- package/node_modules/tokenjuice/dist/hosts/novakit/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/novakit/index.js +273 -0
- package/node_modules/tokenjuice/dist/hosts/ona/index.d.ts +41 -0
- package/node_modules/tokenjuice/dist/hosts/ona/index.js +596 -0
- package/node_modules/tokenjuice/dist/hosts/open-interpreter/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/open-interpreter/index.js +348 -0
- package/node_modules/tokenjuice/dist/hosts/openclaw/extension.d.ts +8 -0
- package/node_modules/tokenjuice/dist/hosts/openclaw/extension.js +104 -0
- package/node_modules/tokenjuice/dist/hosts/openclaw/index.d.ts +1 -0
- package/node_modules/tokenjuice/dist/hosts/openclaw/index.js +1 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.d.ts +17 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +9094 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/index.d.ts +21 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/index.js +163 -0
- package/node_modules/tokenjuice/dist/hosts/openhands/index.d.ts +28 -0
- package/node_modules/tokenjuice/dist/hosts/openhands/index.js +211 -0
- package/node_modules/tokenjuice/dist/hosts/openwebui/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/openwebui/index.js +245 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/pi-types.d.ts +79 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/pi-types.js +3 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.d.ts +5 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +9372 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/settings.d.ts +1 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/settings.js +26 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/status-panel.d.ts +3 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/status-panel.js +72 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/status.d.ts +20 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/status.js +58 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/tool-result.d.ts +4 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/tool-result.js +24 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/utils.d.ts +1 -0
- package/node_modules/tokenjuice/dist/hosts/pi/extension/utils.js +6 -0
- package/node_modules/tokenjuice/dist/hosts/pi/index.d.ts +26 -0
- package/node_modules/tokenjuice/dist/hosts/pi/index.js +228 -0
- package/node_modules/tokenjuice/dist/hosts/pi-go/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/pi-go/index.js +352 -0
- package/node_modules/tokenjuice/dist/hosts/plandex/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/plandex/index.js +164 -0
- package/node_modules/tokenjuice/dist/hosts/qoder/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/qoder/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/qodo/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/qodo/index.js +584 -0
- package/node_modules/tokenjuice/dist/hosts/qwen-code/index.d.ts +28 -0
- package/node_modules/tokenjuice/dist/hosts/qwen-code/index.js +276 -0
- package/node_modules/tokenjuice/dist/hosts/replit/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/replit/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/roo/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/roo/index.js +101 -0
- package/node_modules/tokenjuice/dist/hosts/rovo/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/rovo/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/ruler/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/ruler/index.js +157 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.d.ts +19 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.js +32 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command.d.ts +5 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command.js +94 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.d.ts +212 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.js +270 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-output.d.ts +4 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-output.js +15 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hooks-json-file.d.ts +18 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hooks-json-file.js +108 -0
- package/node_modules/tokenjuice/dist/hosts/shared/host-command.d.ts +10 -0
- package/node_modules/tokenjuice/dist/hosts/shared/host-command.js +70 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-doctor.d.ts +16 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-doctor.js +13 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-file.d.ts +29 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-file.js +121 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-guidance.d.ts +7 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-guidance.js +12 -0
- package/node_modules/tokenjuice/dist/hosts/shared/marker-instructions.d.ts +32 -0
- package/node_modules/tokenjuice/dist/hosts/shared/marker-instructions.js +100 -0
- package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.d.ts +91 -0
- package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.js +186 -0
- package/node_modules/tokenjuice/dist/hosts/shared/tool-result.d.ts +15 -0
- package/node_modules/tokenjuice/dist/hosts/shared/tool-result.js +52 -0
- package/node_modules/tokenjuice/dist/hosts/stagewise/index.d.ts +25 -0
- package/node_modules/tokenjuice/dist/hosts/stagewise/index.js +468 -0
- package/node_modules/tokenjuice/dist/hosts/swe-agent/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/swe-agent/index.js +223 -0
- package/node_modules/tokenjuice/dist/hosts/tabby/index.d.ts +24 -0
- package/node_modules/tokenjuice/dist/hosts/tabby/index.js +469 -0
- package/node_modules/tokenjuice/dist/hosts/tabnine/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/tabnine/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/trae/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/trae/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/uipath/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/uipath/index.js +155 -0
- package/node_modules/tokenjuice/dist/hosts/vscode-copilot/index.d.ts +32 -0
- package/node_modules/tokenjuice/dist/hosts/vscode-copilot/index.js +416 -0
- package/node_modules/tokenjuice/dist/hosts/warp/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/warp/index.js +181 -0
- package/node_modules/tokenjuice/dist/hosts/windsurf/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/windsurf/index.js +99 -0
- package/node_modules/tokenjuice/dist/hosts/zed/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/zed/index.js +68 -0
- package/node_modules/tokenjuice/dist/hosts/zencoder/index.d.ts +23 -0
- package/node_modules/tokenjuice/dist/hosts/zencoder/index.js +227 -0
- package/node_modules/tokenjuice/dist/index.d.ts +214 -0
- package/node_modules/tokenjuice/dist/index.js +113 -0
- package/node_modules/tokenjuice/dist/rules/archive/tar.json +30 -0
- package/node_modules/tokenjuice/dist/rules/archive/unzip.json +30 -0
- package/node_modules/tokenjuice/dist/rules/archive/zip.json +30 -0
- package/node_modules/tokenjuice/dist/rules/build/cmake.json +35 -0
- package/node_modules/tokenjuice/dist/rules/build/dotnet.json +36 -0
- package/node_modules/tokenjuice/dist/rules/build/esbuild.json +35 -0
- package/node_modules/tokenjuice/dist/rules/build/go-build.json +31 -0
- package/node_modules/tokenjuice/dist/rules/build/gradle.json +35 -0
- package/node_modules/tokenjuice/dist/rules/build/maven.json +35 -0
- package/node_modules/tokenjuice/dist/rules/build/msbuild.json +35 -0
- package/node_modules/tokenjuice/dist/rules/build/pnpm-build.json +44 -0
- package/node_modules/tokenjuice/dist/rules/build/swift-build.json +56 -0
- package/node_modules/tokenjuice/dist/rules/build/tsc.json +74 -0
- package/node_modules/tokenjuice/dist/rules/build/tsdown.json +35 -0
- package/node_modules/tokenjuice/dist/rules/build/vite.json +42 -0
- package/node_modules/tokenjuice/dist/rules/build/webpack.json +51 -0
- package/node_modules/tokenjuice/dist/rules/build/xcodebuild.json +80 -0
- package/node_modules/tokenjuice/dist/rules/cloud/aws.json +30 -0
- package/node_modules/tokenjuice/dist/rules/cloud/az.json +30 -0
- package/node_modules/tokenjuice/dist/rules/cloud/flyctl.json +30 -0
- package/node_modules/tokenjuice/dist/rules/cloud/gcloud.json +30 -0
- package/node_modules/tokenjuice/dist/rules/cloud/gh.json +30 -0
- package/node_modules/tokenjuice/dist/rules/cloud/vercel.json +30 -0
- package/node_modules/tokenjuice/dist/rules/database/mongosh.json +30 -0
- package/node_modules/tokenjuice/dist/rules/database/mysql.json +30 -0
- package/node_modules/tokenjuice/dist/rules/database/psql.json +30 -0
- package/node_modules/tokenjuice/dist/rules/database/redis-cli.json +30 -0
- package/node_modules/tokenjuice/dist/rules/database/sqlite3.json +30 -0
- package/node_modules/tokenjuice/dist/rules/devops/docker-build.json +53 -0
- package/node_modules/tokenjuice/dist/rules/devops/docker-compose.json +44 -0
- package/node_modules/tokenjuice/dist/rules/devops/docker-images.json +30 -0
- package/node_modules/tokenjuice/dist/rules/devops/docker-logs.json +43 -0
- package/node_modules/tokenjuice/dist/rules/devops/docker-ps.json +30 -0
- package/node_modules/tokenjuice/dist/rules/devops/helm.json +35 -0
- package/node_modules/tokenjuice/dist/rules/devops/kubectl-describe.json +45 -0
- package/node_modules/tokenjuice/dist/rules/devops/kubectl-get.json +35 -0
- package/node_modules/tokenjuice/dist/rules/devops/kubectl-logs.json +43 -0
- package/node_modules/tokenjuice/dist/rules/devops/pulumi.json +35 -0
- package/node_modules/tokenjuice/dist/rules/devops/terraform.json +35 -0
- package/node_modules/tokenjuice/dist/rules/devops/terragrunt.json +35 -0
- package/node_modules/tokenjuice/dist/rules/filesystem/fd.json +33 -0
- package/node_modules/tokenjuice/dist/rules/filesystem/find.json +42 -0
- package/node_modules/tokenjuice/dist/rules/filesystem/git-ls-files.json +35 -0
- package/node_modules/tokenjuice/dist/rules/filesystem/ls.json +29 -0
- package/node_modules/tokenjuice/dist/rules/filesystem/rg-files.json +34 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/archive/tar.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/archive/unzip.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/archive/zip.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/cmake.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/dotnet.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/esbuild.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/go-build.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/gradle.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/maven.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/msbuild.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/pnpm-build-failure.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/pnpm-build.fixture.json +18 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/swift-build.fixture.json +29 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/tsc.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/tsdown.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/vite.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/webpack.fixture.json +20 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/build/xcodebuild.fixture.json +27 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/cloud/aws.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/cloud/az.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/cloud/flyctl.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/cloud/gcloud.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/cloud/gh.fixture.json +17 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/cloud/vercel.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/database/mongosh.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/database/mysql.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/database/psql.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/database/redis-cli.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/database/sqlite3.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/docker-build.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/docker-compose.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/docker-images.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/docker-logs.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/docker-ps.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/helm.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/kubectl-describe.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/kubectl-get.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/kubectl-logs.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/pulumi.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/terraform.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/devops/terragrunt.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/filesystem/fd.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/filesystem/find.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/filesystem/git-ls-files.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/filesystem/ls.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/filesystem/rg-files.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/generic/fallback.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/generic/help.fixture.json +17 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/branch.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/diff-name-only.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/diff-stat.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/diff.fixture.json +26 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/log-oneline.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/remote-v.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/show.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/stash-list.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/status.fixture.json +17 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/git/worktree-list.fixture.json +17 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/bun-install-up-to-date.fixture.json +19 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/bun-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/npm-ci-up-to-date.fixture.json +19 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/npm-ci.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/npm-install-up-to-date.fixture.json +19 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/npm-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/pnpm-install-up-to-date.fixture.json +19 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/pnpm-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/yarn-install-up-to-date.fixture.json +19 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/install/yarn-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/lint/biome.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/lint/eslint.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/lint/oxlint.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/lint/prettier-check.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/media/ffmpeg.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/media/mediainfo.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/network/curl.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/network/dig.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/network/nslookup.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/network/ping.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/network/ssh.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/network/traceroute.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/network/wget.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/observability/free.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/observability/htop.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/observability/iostat.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/observability/top.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/observability/vmstat.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/openclaw/sessions-history.fixture.json +33 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/apt-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/apt-upgrade.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/brew-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/brew-upgrade.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/composer.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/dnf-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/fnm.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/npm-ls.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/package/yum-install.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/search/git-grep.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/search/grep.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/search/rg.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/journalctl.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/launchctl.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/lsof.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/netstat.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/pm2.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/service.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/ss.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/service/systemctl-status.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/system/df.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/system/du.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/system/file.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/system/ps.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/env.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/just.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/make.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/mise.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/node.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/php.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/python.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/ruby.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/task/uv.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/bun-test.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/cargo-test.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/go-test.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/jest.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/mocha.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/npm-test.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/playwright.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/pnpm-test.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/pytest.fixture.json +19 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/rspec.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/swift-test.fixture.json +30 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/vitest.fixture.json +15 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/tests/yarn-test.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/text/wc.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/transfer/rsync.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/fixtures/transfer/scp.fixture.json +16 -0
- package/node_modules/tokenjuice/dist/rules/generic/fallback.json +32 -0
- package/node_modules/tokenjuice/dist/rules/generic/help.json +25 -0
- package/node_modules/tokenjuice/dist/rules/git/branch.json +29 -0
- package/node_modules/tokenjuice/dist/rules/git/diff-name-only.json +29 -0
- package/node_modules/tokenjuice/dist/rules/git/diff-stat.json +37 -0
- package/node_modules/tokenjuice/dist/rules/git/diff.json +65 -0
- package/node_modules/tokenjuice/dist/rules/git/log-oneline.json +30 -0
- package/node_modules/tokenjuice/dist/rules/git/remote-v.json +29 -0
- package/node_modules/tokenjuice/dist/rules/git/show.json +50 -0
- package/node_modules/tokenjuice/dist/rules/git/stash-list.json +30 -0
- package/node_modules/tokenjuice/dist/rules/git/status.json +54 -0
- package/node_modules/tokenjuice/dist/rules/git/worktree-list.json +31 -0
- package/node_modules/tokenjuice/dist/rules/install/bun-install.json +43 -0
- package/node_modules/tokenjuice/dist/rules/install/npm-ci.json +49 -0
- package/node_modules/tokenjuice/dist/rules/install/npm-install.json +49 -0
- package/node_modules/tokenjuice/dist/rules/install/pnpm-install.json +43 -0
- package/node_modules/tokenjuice/dist/rules/install/yarn-install.json +42 -0
- package/node_modules/tokenjuice/dist/rules/lint/biome.json +35 -0
- package/node_modules/tokenjuice/dist/rules/lint/eslint.json +45 -0
- package/node_modules/tokenjuice/dist/rules/lint/oxlint.json +35 -0
- package/node_modules/tokenjuice/dist/rules/lint/prettier-check.json +34 -0
- package/node_modules/tokenjuice/dist/rules/media/ffmpeg.json +30 -0
- package/node_modules/tokenjuice/dist/rules/media/mediainfo.json +30 -0
- package/node_modules/tokenjuice/dist/rules/network/curl.json +30 -0
- package/node_modules/tokenjuice/dist/rules/network/dig.json +30 -0
- package/node_modules/tokenjuice/dist/rules/network/nslookup.json +30 -0
- package/node_modules/tokenjuice/dist/rules/network/ping.json +35 -0
- package/node_modules/tokenjuice/dist/rules/network/ssh.json +30 -0
- package/node_modules/tokenjuice/dist/rules/network/traceroute.json +30 -0
- package/node_modules/tokenjuice/dist/rules/network/wget.json +30 -0
- package/node_modules/tokenjuice/dist/rules/observability/free.json +30 -0
- package/node_modules/tokenjuice/dist/rules/observability/htop.json +30 -0
- package/node_modules/tokenjuice/dist/rules/observability/iostat.json +30 -0
- package/node_modules/tokenjuice/dist/rules/observability/top.json +30 -0
- package/node_modules/tokenjuice/dist/rules/observability/vmstat.json +30 -0
- package/node_modules/tokenjuice/dist/rules/openclaw/sessions-history.json +59 -0
- package/node_modules/tokenjuice/dist/rules/package/apt-install.json +36 -0
- package/node_modules/tokenjuice/dist/rules/package/apt-upgrade.json +36 -0
- package/node_modules/tokenjuice/dist/rules/package/brew-install.json +31 -0
- package/node_modules/tokenjuice/dist/rules/package/brew-upgrade.json +31 -0
- package/node_modules/tokenjuice/dist/rules/package/composer.json +35 -0
- package/node_modules/tokenjuice/dist/rules/package/dnf-install.json +31 -0
- package/node_modules/tokenjuice/dist/rules/package/fnm.json +35 -0
- package/node_modules/tokenjuice/dist/rules/package/npm-ls.json +31 -0
- package/node_modules/tokenjuice/dist/rules/package/yum-install.json +31 -0
- package/node_modules/tokenjuice/dist/rules/search/git-grep.json +30 -0
- package/node_modules/tokenjuice/dist/rules/search/grep.json +38 -0
- package/node_modules/tokenjuice/dist/rules/search/rg.json +38 -0
- package/node_modules/tokenjuice/dist/rules/service/journalctl.json +42 -0
- package/node_modules/tokenjuice/dist/rules/service/launchctl.json +41 -0
- package/node_modules/tokenjuice/dist/rules/service/lsof.json +29 -0
- package/node_modules/tokenjuice/dist/rules/service/netstat.json +29 -0
- package/node_modules/tokenjuice/dist/rules/service/pm2.json +35 -0
- package/node_modules/tokenjuice/dist/rules/service/service.json +46 -0
- package/node_modules/tokenjuice/dist/rules/service/ss.json +29 -0
- package/node_modules/tokenjuice/dist/rules/service/systemctl-status.json +45 -0
- package/node_modules/tokenjuice/dist/rules/system/df.json +29 -0
- package/node_modules/tokenjuice/dist/rules/system/du.json +29 -0
- package/node_modules/tokenjuice/dist/rules/system/file.json +30 -0
- package/node_modules/tokenjuice/dist/rules/system/ps.json +29 -0
- package/node_modules/tokenjuice/dist/rules/task/env.json +31 -0
- package/node_modules/tokenjuice/dist/rules/task/just.json +30 -0
- package/node_modules/tokenjuice/dist/rules/task/make.json +30 -0
- package/node_modules/tokenjuice/dist/rules/task/mise.json +35 -0
- package/node_modules/tokenjuice/dist/rules/task/node.json +30 -0
- package/node_modules/tokenjuice/dist/rules/task/php.json +30 -0
- package/node_modules/tokenjuice/dist/rules/task/python.json +30 -0
- package/node_modules/tokenjuice/dist/rules/task/ruby.json +30 -0
- package/node_modules/tokenjuice/dist/rules/task/uv.json +35 -0
- package/node_modules/tokenjuice/dist/rules/tests/bun-test.json +56 -0
- package/node_modules/tokenjuice/dist/rules/tests/cargo-test.json +41 -0
- package/node_modules/tokenjuice/dist/rules/tests/go-test.json +49 -0
- package/node_modules/tokenjuice/dist/rules/tests/jest.json +41 -0
- package/node_modules/tokenjuice/dist/rules/tests/mocha.json +35 -0
- package/node_modules/tokenjuice/dist/rules/tests/npm-test.json +56 -0
- package/node_modules/tokenjuice/dist/rules/tests/playwright.json +37 -0
- package/node_modules/tokenjuice/dist/rules/tests/pnpm-test.json +56 -0
- package/node_modules/tokenjuice/dist/rules/tests/pytest.json +54 -0
- package/node_modules/tokenjuice/dist/rules/tests/rspec.json +31 -0
- package/node_modules/tokenjuice/dist/rules/tests/swift-test.json +66 -0
- package/node_modules/tokenjuice/dist/rules/tests/vitest.json +56 -0
- package/node_modules/tokenjuice/dist/rules/tests/yarn-test.json +56 -0
- package/node_modules/tokenjuice/dist/rules/text/wc.json +35 -0
- package/node_modules/tokenjuice/dist/rules/tokenjuice-rule.schema.json +155 -0
- package/node_modules/tokenjuice/dist/rules/transfer/rsync.json +30 -0
- package/node_modules/tokenjuice/dist/rules/transfer/scp.json +30 -0
- package/node_modules/tokenjuice/dist/types.d.ts +212 -0
- package/node_modules/tokenjuice/dist/types.js +1 -0
- package/node_modules/tokenjuice/package.json +80 -0
- package/npm-shrinkwrap.json +39 -0
- package/openclaw.plugin.json +16 -0
- package/package.json +55 -0
|
@@ -0,0 +1,945 @@
|
|
|
1
|
+
import { constants as fsConstants } from "node:fs";
|
|
2
|
+
import { access, appendFile, mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import packageJson from "../../../package.json" with { type: "json" };
|
|
6
|
+
import { stripLeadingCdPrefix } from "../../core/command.js";
|
|
7
|
+
import { storeArtifactMetadata } from "../../core/artifacts.js";
|
|
8
|
+
import { compactBashResult, getOutputAwareInspectionSkipReason } from "../../core/integrations/compact-bash-result.js";
|
|
9
|
+
import { classifyOnly } from "../../core/reduce.js";
|
|
10
|
+
import { countTextChars, stripAnsi } from "../../core/text.js";
|
|
11
|
+
import { extractHookCommandPaths, isNodeExecutablePath, parseShellWords, shellQuote } from "../shared/hook-command.js";
|
|
12
|
+
import { buildCompactionHint } from "../shared/hook-output.js";
|
|
13
|
+
const GENERIC_FALLBACK_MIN_SAVED_CHARS = 120;
|
|
14
|
+
const GENERIC_FALLBACK_MAX_RATIO = 0.75;
|
|
15
|
+
const HOOK_REWRITE_MIN_SAVED_CHARS = 8;
|
|
16
|
+
const CODEX_HOOK_LAST_LOG = "tokenjuice-hook.last.json";
|
|
17
|
+
const CODEX_HOOK_HISTORY_LOG = "tokenjuice-hook.history.jsonl";
|
|
18
|
+
const CODEX_HOOK_HISTORY_LIMIT = 200;
|
|
19
|
+
const CODEX_HOOK_HISTORY_LOCK_STALE_MS = 30_000;
|
|
20
|
+
const CODEX_HOOK_HISTORY_LOCK_RETRY_MS = 25;
|
|
21
|
+
const CODEX_HOOK_HISTORY_LOCK_RETRIES = 8;
|
|
22
|
+
const LOW_NON_TOKENJUICE_TIMEOUT_SECONDS = 2;
|
|
23
|
+
const RECOMMENDED_NON_TOKENJUICE_TIMEOUT_SECONDS = 6;
|
|
24
|
+
const TOKENJUICE_CODEX_HOOK_TIMEOUT_SECONDS = 10;
|
|
25
|
+
const TOKENJUICE_CODEX_STATUS = "compacting bash output with tokenjuice";
|
|
26
|
+
const TOKENJUICE_CODEX_FIX_COMMAND = "tokenjuice install codex";
|
|
27
|
+
function getCodexHome() {
|
|
28
|
+
return process.env.CODEX_HOME || join(homedir(), ".codex");
|
|
29
|
+
}
|
|
30
|
+
function getDefaultHooksPath() {
|
|
31
|
+
return join(getCodexHome(), "hooks.json");
|
|
32
|
+
}
|
|
33
|
+
function getDefaultCodexConfigPath() {
|
|
34
|
+
return join(getCodexHome(), "config.toml");
|
|
35
|
+
}
|
|
36
|
+
const FEATURE_FLAG_NAMES = ["hooks", "codex_hooks"];
|
|
37
|
+
const FEATURE_FLAG_FIX_HINT = "Codex hooks are disabled. Enable per-invocation with `codex exec --enable hooks ...`, " +
|
|
38
|
+
"or persistently by adding a `[features]` section with `hooks = true` to ~/.codex/config.toml.";
|
|
39
|
+
function buildCodexFeatureFlagStatus(configPath, configExists) {
|
|
40
|
+
return {
|
|
41
|
+
configPath,
|
|
42
|
+
configExists,
|
|
43
|
+
keyPresent: false,
|
|
44
|
+
defaultEnabled: true,
|
|
45
|
+
value: null,
|
|
46
|
+
enabled: true,
|
|
47
|
+
fixHint: "",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Read-only scan of ~/.codex/config.toml for the modern `hooks = <bool>`
|
|
52
|
+
* feature flag or its legacy `codex_hooks = <bool>` alias under a `[features]`
|
|
53
|
+
* section (top-level or dotted form). Does NOT edit the file — tokenjuice
|
|
54
|
+
* prefers to surface the state and let the user decide.
|
|
55
|
+
*
|
|
56
|
+
* Latest Codex enables hooks by default. Returns `enabled: true` when no key is
|
|
57
|
+
* declared, and `enabled: false` only when the user explicitly disables hooks.
|
|
58
|
+
*/
|
|
59
|
+
export async function inspectCodexHooksFeatureFlag(configPath = getDefaultCodexConfigPath()) {
|
|
60
|
+
let source;
|
|
61
|
+
try {
|
|
62
|
+
source = await readFile(configPath, "utf8");
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const code = error.code;
|
|
66
|
+
if (code === "ENOENT") {
|
|
67
|
+
return buildCodexFeatureFlagStatus(configPath, false);
|
|
68
|
+
}
|
|
69
|
+
if (code === "EACCES" || code === "EPERM" || code === "EISDIR") {
|
|
70
|
+
return buildCodexFeatureFlagStatus(configPath, true);
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
const parsed = parseCodexFeatureFlag(source, FEATURE_FLAG_NAMES);
|
|
75
|
+
const enabled = parsed.keyPresent ? parsed.value === true : true;
|
|
76
|
+
return {
|
|
77
|
+
configPath,
|
|
78
|
+
configExists: true,
|
|
79
|
+
keyPresent: parsed.keyPresent,
|
|
80
|
+
...(parsed.key ? { key: parsed.key } : {}),
|
|
81
|
+
defaultEnabled: true,
|
|
82
|
+
value: parsed.keyPresent ? parsed.value : null,
|
|
83
|
+
enabled,
|
|
84
|
+
fixHint: enabled ? "" : FEATURE_FLAG_FIX_HINT,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Minimal TOML-ish scanner. Looks for feature flags either under a `[features]`
|
|
89
|
+
* header or as a dotted `features.<key> = <bool>` assignment at any indent.
|
|
90
|
+
* Ignores comments and in-line comments.
|
|
91
|
+
* Not a full TOML parser; only the shapes Codex itself documents.
|
|
92
|
+
*/
|
|
93
|
+
export function parseCodexFeatureFlag(source, keys) {
|
|
94
|
+
const lines = source.split(/\r?\n/u);
|
|
95
|
+
let currentTablePath = [];
|
|
96
|
+
const keyList = typeof keys === "string" ? [keys] : keys;
|
|
97
|
+
const escapedKeys = keyList.join("|");
|
|
98
|
+
const dottedRe = new RegExp(`^\\s*features\\.(${escapedKeys})\\s*=\\s*(true|false)\\b`, "u");
|
|
99
|
+
const scopedRe = new RegExp(`^\\s*(${escapedKeys})\\s*=\\s*(true|false)\\b`, "u");
|
|
100
|
+
for (const rawLine of lines) {
|
|
101
|
+
const line = rawLine.replace(/#.*$/u, "");
|
|
102
|
+
const header = /^\s*\[([^\]]+)\]/u.exec(line);
|
|
103
|
+
if (header) {
|
|
104
|
+
currentTablePath = header[1]
|
|
105
|
+
.trim()
|
|
106
|
+
.split(".")
|
|
107
|
+
.map((segment) => segment.trim())
|
|
108
|
+
.filter(Boolean);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const dotted = currentTablePath.length === 0 ? dottedRe.exec(line) : null;
|
|
112
|
+
if (dotted) {
|
|
113
|
+
return { keyPresent: true, key: dotted[1], value: dotted[2] === "true" };
|
|
114
|
+
}
|
|
115
|
+
if (currentTablePath.length === 1 && currentTablePath[0] === "features") {
|
|
116
|
+
const scoped = scopedRe.exec(line);
|
|
117
|
+
if (scoped) {
|
|
118
|
+
return { keyPresent: true, key: scoped[1], value: scoped[2] === "true" };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { keyPresent: false, value: null };
|
|
123
|
+
}
|
|
124
|
+
export async function inspectCodexRuntimeConfig(configPath = getDefaultCodexConfigPath()) {
|
|
125
|
+
let source;
|
|
126
|
+
try {
|
|
127
|
+
source = await readFile(configPath, "utf8");
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
const code = error.code;
|
|
131
|
+
if (code === "ENOENT") {
|
|
132
|
+
return {
|
|
133
|
+
configPath,
|
|
134
|
+
configExists: false,
|
|
135
|
+
approvalPolicy: null,
|
|
136
|
+
sandboxMode: null,
|
|
137
|
+
approvalsReviewer: null,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (code === "EACCES" || code === "EPERM" || code === "EISDIR") {
|
|
141
|
+
return {
|
|
142
|
+
configPath,
|
|
143
|
+
configExists: true,
|
|
144
|
+
approvalPolicy: null,
|
|
145
|
+
sandboxMode: null,
|
|
146
|
+
approvalsReviewer: null,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
const values = parseCodexRuntimeConfig(source);
|
|
152
|
+
return {
|
|
153
|
+
configPath,
|
|
154
|
+
configExists: true,
|
|
155
|
+
approvalPolicy: values.approvalPolicy,
|
|
156
|
+
sandboxMode: values.sandboxMode,
|
|
157
|
+
approvalsReviewer: values.approvalsReviewer,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function parseCodexRuntimeConfig(source) {
|
|
161
|
+
const values = {
|
|
162
|
+
approvalPolicy: null,
|
|
163
|
+
sandboxMode: null,
|
|
164
|
+
approvalsReviewer: null,
|
|
165
|
+
};
|
|
166
|
+
let currentTablePath = [];
|
|
167
|
+
for (const rawLine of source.split(/\r?\n/u)) {
|
|
168
|
+
const line = rawLine.replace(/#.*$/u, "");
|
|
169
|
+
const header = /^\s*\[([^\]]+)\]/u.exec(line);
|
|
170
|
+
if (header) {
|
|
171
|
+
currentTablePath = header[1]
|
|
172
|
+
.trim()
|
|
173
|
+
.split(".")
|
|
174
|
+
.map((segment) => segment.trim())
|
|
175
|
+
.filter(Boolean);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (currentTablePath.length > 0) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const assignment = /^\s*(approval_policy|sandbox_mode|approvals_reviewer)\s*=\s*("[^"]+"|'[^']+'|\{.*|[A-Za-z0-9_-]+)/u.exec(line);
|
|
182
|
+
if (!assignment) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const rawValue = assignment[2].trim();
|
|
186
|
+
const value = rawValue.startsWith("{") ? "granular" : rawValue.replace(/^["']|["']$/gu, "");
|
|
187
|
+
if (assignment[1] === "approval_policy") {
|
|
188
|
+
values.approvalPolicy = value;
|
|
189
|
+
}
|
|
190
|
+
else if (assignment[1] === "sandbox_mode") {
|
|
191
|
+
values.sandboxMode = value;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
values.approvalsReviewer = value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return values;
|
|
198
|
+
}
|
|
199
|
+
async function isExecutableFile(path) {
|
|
200
|
+
try {
|
|
201
|
+
await access(path, fsConstants.X_OK);
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function resolveInstalledTokenjuicePath() {
|
|
209
|
+
const pathValue = process.env.PATH;
|
|
210
|
+
if (!pathValue) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
const candidateNames = process.platform === "win32"
|
|
214
|
+
? ["tokenjuice.exe", "tokenjuice.cmd", "tokenjuice.bat", "tokenjuice"]
|
|
215
|
+
: ["tokenjuice"];
|
|
216
|
+
for (const segment of pathValue.split(delimiter)) {
|
|
217
|
+
if (!segment) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
for (const candidateName of candidateNames) {
|
|
221
|
+
const candidatePath = join(segment, candidateName);
|
|
222
|
+
if (await isExecutableFile(candidatePath)) {
|
|
223
|
+
return candidatePath;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
async function buildCodexHookCommand(options = {}) {
|
|
230
|
+
const rawBinaryPath = options.binaryPath ?? process.argv[1];
|
|
231
|
+
const binaryPath = rawBinaryPath && !isAbsolute(rawBinaryPath) ? resolve(rawBinaryPath) : rawBinaryPath;
|
|
232
|
+
const nodePath = options.nodePath ?? process.execPath;
|
|
233
|
+
if (!binaryPath) {
|
|
234
|
+
throw new Error("unable to resolve tokenjuice binary path for codex install");
|
|
235
|
+
}
|
|
236
|
+
if (!options.local) {
|
|
237
|
+
const installedBinaryPath = await resolveInstalledTokenjuicePath();
|
|
238
|
+
if (installedBinaryPath) {
|
|
239
|
+
return `${shellQuote(installedBinaryPath)} codex-post-tool-use`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (binaryPath.endsWith(".js")) {
|
|
243
|
+
return `${shellQuote(nodePath)} ${shellQuote(binaryPath)} codex-post-tool-use`;
|
|
244
|
+
}
|
|
245
|
+
return `${shellQuote(binaryPath)} codex-post-tool-use`;
|
|
246
|
+
}
|
|
247
|
+
function getCodexFixCommand(local = false) {
|
|
248
|
+
return local ? "tokenjuice install codex --local" : TOKENJUICE_CODEX_FIX_COMMAND;
|
|
249
|
+
}
|
|
250
|
+
async function pathExists(path) {
|
|
251
|
+
try {
|
|
252
|
+
await access(path);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async function newestMtimeMs(path) {
|
|
260
|
+
try {
|
|
261
|
+
const details = await stat(path);
|
|
262
|
+
let newest = details.mtimeMs;
|
|
263
|
+
if (details.isDirectory()) {
|
|
264
|
+
for (const entry of await readdir(path)) {
|
|
265
|
+
const childNewest = await newestMtimeMs(join(path, entry));
|
|
266
|
+
if (typeof childNewest === "number" && childNewest > newest) {
|
|
267
|
+
newest = childNewest;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return newest;
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async function detectStaleLocalBuild(commandPaths) {
|
|
278
|
+
const distPath = commandPaths.find((path) => path.endsWith("/dist/cli/main.js") || path.endsWith("\\dist\\cli\\main.js"));
|
|
279
|
+
if (!distPath) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
let distMtimeMs;
|
|
283
|
+
try {
|
|
284
|
+
distMtimeMs = (await stat(distPath)).mtimeMs;
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
const projectRoot = dirname(dirname(dirname(distPath)));
|
|
290
|
+
const latestSourceMtimeMs = Math.max(await newestMtimeMs(join(projectRoot, "src")) ?? 0, await newestMtimeMs(join(projectRoot, "package.json")) ?? 0, await newestMtimeMs(join(projectRoot, "tsconfig.json")) ?? 0);
|
|
291
|
+
return latestSourceMtimeMs > distMtimeMs;
|
|
292
|
+
}
|
|
293
|
+
function isRecord(value) {
|
|
294
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
295
|
+
}
|
|
296
|
+
function stringifyToolResponse(value) {
|
|
297
|
+
if (value === null || value === undefined) {
|
|
298
|
+
return "";
|
|
299
|
+
}
|
|
300
|
+
if (typeof value === "string") {
|
|
301
|
+
return value;
|
|
302
|
+
}
|
|
303
|
+
if (Array.isArray(value)) {
|
|
304
|
+
return value
|
|
305
|
+
.map((entry) => stringifyToolResponse(entry))
|
|
306
|
+
.filter(Boolean)
|
|
307
|
+
.join("\n");
|
|
308
|
+
}
|
|
309
|
+
if (isRecord(value)) {
|
|
310
|
+
for (const key of ["output", "text", "stdout", "stderr", "combinedText"]) {
|
|
311
|
+
const text = value[key];
|
|
312
|
+
if (typeof text === "string" && text) {
|
|
313
|
+
return text;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return JSON.stringify(value);
|
|
317
|
+
}
|
|
318
|
+
return String(value);
|
|
319
|
+
}
|
|
320
|
+
function createTokenjuiceCodexHook(command) {
|
|
321
|
+
return {
|
|
322
|
+
matcher: "^Bash$",
|
|
323
|
+
hooks: [
|
|
324
|
+
{
|
|
325
|
+
type: "command",
|
|
326
|
+
command,
|
|
327
|
+
statusMessage: TOKENJUICE_CODEX_STATUS,
|
|
328
|
+
timeout: TOKENJUICE_CODEX_HOOK_TIMEOUT_SECONDS,
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function isTokenjuiceCodexHook(group) {
|
|
334
|
+
return group.hooks.some((hook) => {
|
|
335
|
+
const command = typeof hook.command === "string" ? hook.command : "";
|
|
336
|
+
return hook.statusMessage === TOKENJUICE_CODEX_STATUS
|
|
337
|
+
|| command.includes("codex-post-tool-use")
|
|
338
|
+
|| command.includes("post_tool_use_tokenjuice.py");
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function findTokenjuiceCodexHookCommand(config) {
|
|
342
|
+
return findTokenjuiceCodexHook(config)?.command;
|
|
343
|
+
}
|
|
344
|
+
function findTokenjuiceCodexHook(config) {
|
|
345
|
+
for (const group of config.hooks.PostToolUse ?? []) {
|
|
346
|
+
if (!isTokenjuiceCodexHook(group)) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const hook = group.hooks.find((hook) => {
|
|
350
|
+
const hookCommand = typeof hook.command === "string" ? hook.command : "";
|
|
351
|
+
return hook.statusMessage === TOKENJUICE_CODEX_STATUS
|
|
352
|
+
|| hookCommand.includes("codex-post-tool-use")
|
|
353
|
+
|| hookCommand.includes("post_tool_use_tokenjuice.py");
|
|
354
|
+
});
|
|
355
|
+
if (hook) {
|
|
356
|
+
return hook;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
function truncateHookCommand(command, maxLength = 80) {
|
|
362
|
+
const trimmed = command.trim();
|
|
363
|
+
if (trimmed.length <= maxLength) {
|
|
364
|
+
return trimmed;
|
|
365
|
+
}
|
|
366
|
+
return `${trimmed.slice(0, maxLength - 3)}...`;
|
|
367
|
+
}
|
|
368
|
+
function extractHomebrewCellarVersion(path) {
|
|
369
|
+
const normalized = path.replace(/\\/gu, "/");
|
|
370
|
+
const match = normalized.match(/\/Cellar\/tokenjuice\/([^/]+)\//u);
|
|
371
|
+
return match?.[1];
|
|
372
|
+
}
|
|
373
|
+
async function detectResolvedHomebrewVersionMismatch(commandPaths) {
|
|
374
|
+
for (const path of commandPaths) {
|
|
375
|
+
if (!path.endsWith("/tokenjuice") && !path.endsWith("\\tokenjuice") && !path.endsWith("\\tokenjuice.exe")) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
let resolvedPath;
|
|
379
|
+
try {
|
|
380
|
+
resolvedPath = await realpath(path);
|
|
381
|
+
}
|
|
382
|
+
catch {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const resolvedVersion = extractHomebrewCellarVersion(resolvedPath);
|
|
386
|
+
if (!resolvedVersion || resolvedVersion === packageJson.version) {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
launcherPath: path,
|
|
391
|
+
resolvedPath,
|
|
392
|
+
resolvedVersion,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
return undefined;
|
|
396
|
+
}
|
|
397
|
+
function collectLowTimeoutWarnings(config) {
|
|
398
|
+
const issues = [];
|
|
399
|
+
for (const [eventName, groups] of Object.entries(config.hooks)) {
|
|
400
|
+
groups.forEach((group, groupIndex) => {
|
|
401
|
+
const tokenjuiceGroup = eventName === "PostToolUse" && isTokenjuiceCodexHook(group);
|
|
402
|
+
if (tokenjuiceGroup) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
group.hooks.forEach((hook, hookIndex) => {
|
|
406
|
+
if (typeof hook.command !== "string") {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (typeof hook.timeout !== "number"
|
|
410
|
+
|| !Number.isFinite(hook.timeout)
|
|
411
|
+
|| hook.timeout > LOW_NON_TOKENJUICE_TIMEOUT_SECONDS) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const location = `${eventName}[${groupIndex}].hooks[${hookIndex}]`;
|
|
415
|
+
const command = truncateHookCommand(hook.command);
|
|
416
|
+
issues.push(`non-tokenjuice Codex hook ${location} uses a low ${hook.timeout}s timeout for "${command}" — consider ${RECOMMENDED_NON_TOKENJUICE_TIMEOUT_SECONDS}s or higher`);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return issues;
|
|
421
|
+
}
|
|
422
|
+
function collectTokenjuiceHookTimeoutWarnings(config, fixCommand) {
|
|
423
|
+
const hook = findTokenjuiceCodexHook(config);
|
|
424
|
+
if (!hook) {
|
|
425
|
+
return [];
|
|
426
|
+
}
|
|
427
|
+
if (hook.timeout !== TOKENJUICE_CODEX_HOOK_TIMEOUT_SECONDS) {
|
|
428
|
+
return [
|
|
429
|
+
`configured Codex tokenjuice hook timeout is missing or stale; run ${fixCommand} to add the ${TOKENJUICE_CODEX_HOOK_TIMEOUT_SECONDS}s safety cap`,
|
|
430
|
+
];
|
|
431
|
+
}
|
|
432
|
+
return [];
|
|
433
|
+
}
|
|
434
|
+
function sanitizeHooksConfig(raw) {
|
|
435
|
+
if (!isRecord(raw) || !isRecord(raw.hooks)) {
|
|
436
|
+
return { hooks: {} };
|
|
437
|
+
}
|
|
438
|
+
const hooks = {};
|
|
439
|
+
for (const [eventName, groups] of Object.entries(raw.hooks)) {
|
|
440
|
+
if (!Array.isArray(groups)) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
const normalizedGroups = groups.flatMap((group) => {
|
|
444
|
+
if (!isRecord(group) || !Array.isArray(group.hooks)) {
|
|
445
|
+
return [];
|
|
446
|
+
}
|
|
447
|
+
const commands = group.hooks.flatMap((hook) => {
|
|
448
|
+
if (!isRecord(hook)) {
|
|
449
|
+
return [];
|
|
450
|
+
}
|
|
451
|
+
return [{ ...hook }];
|
|
452
|
+
});
|
|
453
|
+
if (commands.length === 0) {
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
const normalizedGroup = {
|
|
457
|
+
...group,
|
|
458
|
+
hooks: commands,
|
|
459
|
+
};
|
|
460
|
+
if (typeof group.matcher === "string" && group.matcher) {
|
|
461
|
+
normalizedGroup.matcher = group.matcher;
|
|
462
|
+
}
|
|
463
|
+
return [normalizedGroup];
|
|
464
|
+
});
|
|
465
|
+
if (normalizedGroups.length > 0) {
|
|
466
|
+
hooks[eventName] = normalizedGroups;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return { hooks };
|
|
470
|
+
}
|
|
471
|
+
async function loadHooksConfig(hooksPath) {
|
|
472
|
+
try {
|
|
473
|
+
const rawText = await readFile(hooksPath, "utf8");
|
|
474
|
+
const parsed = JSON.parse(rawText);
|
|
475
|
+
const config = sanitizeHooksConfig(parsed);
|
|
476
|
+
const backupPath = `${hooksPath}.bak`;
|
|
477
|
+
await writeFile(backupPath, rawText, "utf8");
|
|
478
|
+
return { config, backupPath };
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
if (error.code === "ENOENT") {
|
|
482
|
+
return { config: { hooks: {} } };
|
|
483
|
+
}
|
|
484
|
+
throw new Error(`failed to load codex hooks from ${hooksPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
async function readHooksConfig(hooksPath) {
|
|
488
|
+
try {
|
|
489
|
+
const rawText = await readFile(hooksPath, "utf8");
|
|
490
|
+
const parsed = JSON.parse(rawText);
|
|
491
|
+
return {
|
|
492
|
+
config: sanitizeHooksConfig(parsed),
|
|
493
|
+
exists: true,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
if (error.code === "ENOENT") {
|
|
498
|
+
return {
|
|
499
|
+
config: { hooks: {} },
|
|
500
|
+
exists: false,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
throw new Error(`failed to read codex hooks from ${hooksPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function isTokenjuiceExecutableArg(value) {
|
|
507
|
+
if (!value) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
const normalized = value.replace(/\\/gu, "/");
|
|
511
|
+
return normalized === "tokenjuice"
|
|
512
|
+
|| normalized.endsWith("/tokenjuice")
|
|
513
|
+
|| normalized.endsWith("/tokenjuice.exe")
|
|
514
|
+
|| normalized.endsWith("/tokenjuice.cmd")
|
|
515
|
+
|| normalized.endsWith("/tokenjuice.bat");
|
|
516
|
+
}
|
|
517
|
+
function commandRequestsTokenjuiceRawBypass(command) {
|
|
518
|
+
const argv = parseShellWords(stripLeadingCdPrefix(command));
|
|
519
|
+
if (argv.length < 3) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
const first = argv[0];
|
|
523
|
+
const second = argv[1];
|
|
524
|
+
let wrapIndex = -1;
|
|
525
|
+
if (isTokenjuiceExecutableArg(first)) {
|
|
526
|
+
wrapIndex = 1;
|
|
527
|
+
}
|
|
528
|
+
else if (typeof first === "string"
|
|
529
|
+
&& isNodeExecutablePath(first)
|
|
530
|
+
&& typeof second === "string"
|
|
531
|
+
&& second.endsWith(".js")
|
|
532
|
+
&& argv.slice(1).some((part) => part.includes("tokenjuice"))) {
|
|
533
|
+
wrapIndex = 2;
|
|
534
|
+
}
|
|
535
|
+
if (wrapIndex === -1 || argv[wrapIndex] !== "wrap") {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
const optionEndIndex = argv.indexOf("--", wrapIndex + 1);
|
|
539
|
+
const optionArgs = argv.slice(wrapIndex + 1, optionEndIndex === -1 ? undefined : optionEndIndex);
|
|
540
|
+
return optionArgs.includes("--raw") || optionArgs.includes("--full");
|
|
541
|
+
}
|
|
542
|
+
function buildCodexFeedback(inlineText, rawRefId) {
|
|
543
|
+
return `${inlineText}\n\n${buildCompactionHint(rawRefId)}`;
|
|
544
|
+
}
|
|
545
|
+
function buildCodexReplacementOutput(inlineText, rawRefId) {
|
|
546
|
+
const feedback = buildCodexFeedback(inlineText, rawRefId);
|
|
547
|
+
return {
|
|
548
|
+
hookSpecificOutput: {
|
|
549
|
+
hookEventName: "PostToolUse",
|
|
550
|
+
additionalContext: feedback,
|
|
551
|
+
},
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function parseExitCodeValue(value) {
|
|
555
|
+
if (typeof value === "number" && Number.isInteger(value)) {
|
|
556
|
+
return value;
|
|
557
|
+
}
|
|
558
|
+
if (typeof value === "string" && /^-?\d+$/u.test(value.trim())) {
|
|
559
|
+
return Number(value);
|
|
560
|
+
}
|
|
561
|
+
return undefined;
|
|
562
|
+
}
|
|
563
|
+
function extractCodexExitCode(payload) {
|
|
564
|
+
for (const candidate of [payload.exitCode, payload.exit_code]) {
|
|
565
|
+
const parsed = parseExitCodeValue(candidate);
|
|
566
|
+
if (typeof parsed === "number") {
|
|
567
|
+
return parsed;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (isRecord(payload.tool_response)) {
|
|
571
|
+
for (const key of ["exitCode", "exit_code"]) {
|
|
572
|
+
const parsed = parseExitCodeValue(payload.tool_response[key]);
|
|
573
|
+
if (typeof parsed === "number") {
|
|
574
|
+
return parsed;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
580
|
+
export async function installCodexHook(hooksPath = getDefaultHooksPath(), options = {}) {
|
|
581
|
+
const { config, backupPath } = await loadHooksConfig(hooksPath);
|
|
582
|
+
const command = await buildCodexHookCommand(options);
|
|
583
|
+
const postToolUse = config.hooks.PostToolUse ?? [];
|
|
584
|
+
const retained = postToolUse.filter((group) => !isTokenjuiceCodexHook(group));
|
|
585
|
+
retained.push(createTokenjuiceCodexHook(command));
|
|
586
|
+
config.hooks.PostToolUse = retained;
|
|
587
|
+
await mkdir(dirname(hooksPath), { recursive: true });
|
|
588
|
+
const tempPath = `${hooksPath}.tmp`;
|
|
589
|
+
await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
590
|
+
await rename(tempPath, hooksPath);
|
|
591
|
+
const featureFlag = await inspectCodexHooksFeatureFlag(options.featureFlagConfigPath);
|
|
592
|
+
return {
|
|
593
|
+
hooksPath,
|
|
594
|
+
...(backupPath ? { backupPath } : {}),
|
|
595
|
+
command,
|
|
596
|
+
featureFlag,
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
export async function uninstallCodexHook(hooksPath = getDefaultHooksPath()) {
|
|
600
|
+
const { config, backupPath } = await loadHooksConfig(hooksPath);
|
|
601
|
+
const postToolUse = config.hooks.PostToolUse ?? [];
|
|
602
|
+
const retained = postToolUse.filter((group) => !isTokenjuiceCodexHook(group));
|
|
603
|
+
const removed = postToolUse.length - retained.length;
|
|
604
|
+
if (retained.length > 0) {
|
|
605
|
+
config.hooks.PostToolUse = retained;
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
delete config.hooks.PostToolUse;
|
|
609
|
+
}
|
|
610
|
+
await mkdir(dirname(hooksPath), { recursive: true });
|
|
611
|
+
const tempPath = `${hooksPath}.tmp`;
|
|
612
|
+
await writeFile(tempPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
613
|
+
await rename(tempPath, hooksPath);
|
|
614
|
+
return {
|
|
615
|
+
hooksPath,
|
|
616
|
+
...(backupPath ? { backupPath } : {}),
|
|
617
|
+
removed,
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
export async function doctorCodexHook(hooksPath = getDefaultHooksPath(), options = {}) {
|
|
621
|
+
const expectedCommand = await buildCodexHookCommand(options);
|
|
622
|
+
const installFixCommand = getCodexFixCommand(options.local);
|
|
623
|
+
let fixCommand = installFixCommand;
|
|
624
|
+
const { config, exists } = await readHooksConfig(hooksPath);
|
|
625
|
+
const detectedCommand = findTokenjuiceCodexHookCommand(config);
|
|
626
|
+
const featureFlag = await inspectCodexHooksFeatureFlag(options.featureFlagConfigPath);
|
|
627
|
+
const runtimeConfig = await inspectCodexRuntimeConfig(options.featureFlagConfigPath);
|
|
628
|
+
if (!exists) {
|
|
629
|
+
return {
|
|
630
|
+
hooksPath,
|
|
631
|
+
status: "disabled",
|
|
632
|
+
issues: [],
|
|
633
|
+
fixCommand,
|
|
634
|
+
expectedCommand,
|
|
635
|
+
checkedPaths: [],
|
|
636
|
+
missingPaths: [],
|
|
637
|
+
featureFlag,
|
|
638
|
+
runtimeConfig,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
if (!detectedCommand) {
|
|
642
|
+
return {
|
|
643
|
+
hooksPath,
|
|
644
|
+
status: "disabled",
|
|
645
|
+
issues: [],
|
|
646
|
+
fixCommand,
|
|
647
|
+
expectedCommand,
|
|
648
|
+
checkedPaths: [],
|
|
649
|
+
missingPaths: [],
|
|
650
|
+
featureFlag,
|
|
651
|
+
runtimeConfig,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
const checkedPaths = extractHookCommandPaths(detectedCommand);
|
|
655
|
+
const missingPaths = [];
|
|
656
|
+
for (const path of checkedPaths) {
|
|
657
|
+
if (!(await isExecutableFile(path)) && !(path.endsWith(".js") && await pathExists(path))) {
|
|
658
|
+
missingPaths.push(path);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
const issues = [];
|
|
662
|
+
if (detectedCommand !== expectedCommand) {
|
|
663
|
+
if (detectedCommand.includes("/Cellar/")) {
|
|
664
|
+
issues.push("configured Codex hook is pinned to a versioned Homebrew Cellar path");
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
issues.push("configured Codex hook command does not match the current recommended command");
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
if (missingPaths.length > 0) {
|
|
671
|
+
issues.push(`configured Codex hook points at missing path${missingPaths.length === 1 ? "" : "s"}`);
|
|
672
|
+
}
|
|
673
|
+
const resolvedVersionMismatch = await detectResolvedHomebrewVersionMismatch(checkedPaths);
|
|
674
|
+
if (resolvedVersionMismatch) {
|
|
675
|
+
issues.push(`configured Codex hook launcher resolves to Homebrew tokenjuice ${resolvedVersionMismatch.resolvedVersion}, but this tokenjuice is ${packageJson.version}`);
|
|
676
|
+
fixCommand = "brew upgrade tokenjuice";
|
|
677
|
+
}
|
|
678
|
+
if (options.local && await detectStaleLocalBuild(checkedPaths)) {
|
|
679
|
+
issues.push("local Codex hook target is older than the source tree");
|
|
680
|
+
fixCommand = "pnpm build && tokenjuice install codex --local";
|
|
681
|
+
}
|
|
682
|
+
if (!featureFlag.enabled) {
|
|
683
|
+
issues.push("Codex feature flag `hooks` is disabled — the configured hook will not fire");
|
|
684
|
+
}
|
|
685
|
+
issues.push(...collectTokenjuiceHookTimeoutWarnings(config, installFixCommand));
|
|
686
|
+
issues.push(...collectLowTimeoutWarnings(config));
|
|
687
|
+
return {
|
|
688
|
+
hooksPath,
|
|
689
|
+
status: missingPaths.length > 0 ? "broken" : issues.length > 0 ? "warn" : "ok",
|
|
690
|
+
issues,
|
|
691
|
+
fixCommand,
|
|
692
|
+
expectedCommand,
|
|
693
|
+
detectedCommand,
|
|
694
|
+
checkedPaths,
|
|
695
|
+
missingPaths,
|
|
696
|
+
featureFlag,
|
|
697
|
+
runtimeConfig,
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
function readPositiveIntegerEnv(name) {
|
|
701
|
+
const value = process.env[name];
|
|
702
|
+
if (!value) {
|
|
703
|
+
return undefined;
|
|
704
|
+
}
|
|
705
|
+
const parsed = Number(value);
|
|
706
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
707
|
+
}
|
|
708
|
+
function shouldStoreFromEnv() {
|
|
709
|
+
const value = process.env.TOKENJUICE_CODEX_STORE;
|
|
710
|
+
return value === "1" || value === "true" || value === "TRUE" || value === "yes" || value === "YES";
|
|
711
|
+
}
|
|
712
|
+
async function writeHookDebug(record) {
|
|
713
|
+
const codexHome = getCodexHome();
|
|
714
|
+
const debugPath = join(codexHome, CODEX_HOOK_LAST_LOG);
|
|
715
|
+
const historyPath = join(codexHome, CODEX_HOOK_HISTORY_LOG);
|
|
716
|
+
const enrichedRecord = {
|
|
717
|
+
timestamp: new Date().toISOString(),
|
|
718
|
+
tokenjuiceVersion: packageJson.version,
|
|
719
|
+
hookCommandPath: process.argv[1],
|
|
720
|
+
...record,
|
|
721
|
+
};
|
|
722
|
+
await mkdir(dirname(debugPath), { recursive: true });
|
|
723
|
+
await writeFile(debugPath, `${JSON.stringify(enrichedRecord, null, 2)}\n`, "utf8");
|
|
724
|
+
await writeHookHistoryEntry(historyPath, JSON.stringify(enrichedRecord));
|
|
725
|
+
}
|
|
726
|
+
function sanitizeHookHistoryLines(text) {
|
|
727
|
+
return text
|
|
728
|
+
.split("\n")
|
|
729
|
+
.map((line) => line.trim())
|
|
730
|
+
.filter(Boolean)
|
|
731
|
+
.filter((line) => {
|
|
732
|
+
try {
|
|
733
|
+
JSON.parse(line);
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
function wait(ms) {
|
|
742
|
+
return new Promise((resolvePromise) => {
|
|
743
|
+
setTimeout(resolvePromise, ms);
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
async function acquireHistoryLock(lockPath) {
|
|
747
|
+
for (let attempt = 0; attempt <= CODEX_HOOK_HISTORY_LOCK_RETRIES; attempt += 1) {
|
|
748
|
+
try {
|
|
749
|
+
await mkdir(lockPath);
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
const code = error.code;
|
|
754
|
+
if (code !== "EEXIST") {
|
|
755
|
+
throw error;
|
|
756
|
+
}
|
|
757
|
+
try {
|
|
758
|
+
const details = await stat(lockPath);
|
|
759
|
+
if (Date.now() - details.mtimeMs > CODEX_HOOK_HISTORY_LOCK_STALE_MS) {
|
|
760
|
+
await rm(lockPath, { recursive: true, force: true });
|
|
761
|
+
continue;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
catch (statError) {
|
|
765
|
+
const statCode = statError.code;
|
|
766
|
+
if (statCode !== "ENOENT") {
|
|
767
|
+
throw statError;
|
|
768
|
+
}
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
if (attempt < CODEX_HOOK_HISTORY_LOCK_RETRIES) {
|
|
772
|
+
await wait(CODEX_HOOK_HISTORY_LOCK_RETRY_MS);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
async function writeHookHistoryEntry(historyPath, line) {
|
|
779
|
+
const lockPath = `${historyPath}.lock`;
|
|
780
|
+
const tempPath = `${historyPath}.${process.pid}.tmp`;
|
|
781
|
+
const hasLock = await acquireHistoryLock(lockPath);
|
|
782
|
+
if (!hasLock) {
|
|
783
|
+
await appendFile(historyPath, `${line}\n`, "utf8");
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
try {
|
|
787
|
+
let historyLines = [];
|
|
788
|
+
try {
|
|
789
|
+
historyLines = sanitizeHookHistoryLines(await readFile(historyPath, "utf8"));
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
const code = error.code;
|
|
793
|
+
if (code !== "ENOENT") {
|
|
794
|
+
throw error;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
historyLines.push(line);
|
|
798
|
+
if (historyLines.length > CODEX_HOOK_HISTORY_LIMIT) {
|
|
799
|
+
historyLines = historyLines.slice(-CODEX_HOOK_HISTORY_LIMIT);
|
|
800
|
+
}
|
|
801
|
+
await writeFile(tempPath, `${historyLines.join("\n")}\n`, "utf8");
|
|
802
|
+
await rename(tempPath, historyPath);
|
|
803
|
+
}
|
|
804
|
+
finally {
|
|
805
|
+
await rm(tempPath, { force: true }).catch(() => { });
|
|
806
|
+
await rm(lockPath, { recursive: true, force: true }).catch(() => { });
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
function buildImmediateSkipStats(text) {
|
|
810
|
+
const rawChars = countTextChars(stripAnsi(text));
|
|
811
|
+
return {
|
|
812
|
+
rawChars,
|
|
813
|
+
reducedChars: rawChars,
|
|
814
|
+
savedChars: 0,
|
|
815
|
+
ratio: 1,
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
async function recordImmediateHookStats(input, rawText, storeRaw) {
|
|
819
|
+
if (storeRaw) {
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
const stats = buildImmediateSkipStats(rawText);
|
|
823
|
+
const classification = await classifyOnly(input);
|
|
824
|
+
await storeArtifactMetadata({
|
|
825
|
+
input,
|
|
826
|
+
rawText,
|
|
827
|
+
classification,
|
|
828
|
+
stats: {
|
|
829
|
+
rawChars: stats.rawChars,
|
|
830
|
+
reducedChars: stats.reducedChars,
|
|
831
|
+
ratio: stats.ratio,
|
|
832
|
+
},
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
export async function runCodexPostToolUseHook(rawText) {
|
|
836
|
+
let payload;
|
|
837
|
+
try {
|
|
838
|
+
payload = JSON.parse(rawText);
|
|
839
|
+
}
|
|
840
|
+
catch {
|
|
841
|
+
return 0;
|
|
842
|
+
}
|
|
843
|
+
const command = payload.tool_input?.command;
|
|
844
|
+
const debug = {
|
|
845
|
+
hookEvent: payload.hook_event_name,
|
|
846
|
+
toolName: payload.tool_name,
|
|
847
|
+
command,
|
|
848
|
+
rewrote: false,
|
|
849
|
+
};
|
|
850
|
+
if (payload.hook_event_name !== "PostToolUse") {
|
|
851
|
+
await writeHookDebug({ ...debug, skipped: "non-post-tool-use" });
|
|
852
|
+
return 0;
|
|
853
|
+
}
|
|
854
|
+
if (payload.tool_name !== "Bash") {
|
|
855
|
+
await writeHookDebug({ ...debug, skipped: "non-bash" });
|
|
856
|
+
return 0;
|
|
857
|
+
}
|
|
858
|
+
if (typeof command !== "string" || !command.trim()) {
|
|
859
|
+
await writeHookDebug({ ...debug, skipped: "missing-command" });
|
|
860
|
+
return 0;
|
|
861
|
+
}
|
|
862
|
+
const combinedText = stringifyToolResponse(payload.tool_response);
|
|
863
|
+
if (!combinedText.trim()) {
|
|
864
|
+
await writeHookDebug({ ...debug, skipped: "empty-tool-response" });
|
|
865
|
+
return 0;
|
|
866
|
+
}
|
|
867
|
+
const exitCode = extractCodexExitCode(payload);
|
|
868
|
+
const executionInput = {
|
|
869
|
+
toolName: "exec",
|
|
870
|
+
command,
|
|
871
|
+
combinedText,
|
|
872
|
+
...(typeof payload.cwd === "string" && payload.cwd.trim() ? { cwd: payload.cwd } : {}),
|
|
873
|
+
...(typeof exitCode === "number" ? { exitCode } : {}),
|
|
874
|
+
metadata: {
|
|
875
|
+
source: "codex-post-tool-use",
|
|
876
|
+
},
|
|
877
|
+
};
|
|
878
|
+
const storeRaw = shouldStoreFromEnv();
|
|
879
|
+
if (commandRequestsTokenjuiceRawBypass(command)) {
|
|
880
|
+
await recordImmediateHookStats(executionInput, combinedText, storeRaw);
|
|
881
|
+
const stats = buildImmediateSkipStats(combinedText);
|
|
882
|
+
await writeHookDebug({
|
|
883
|
+
...debug,
|
|
884
|
+
...stats,
|
|
885
|
+
skipped: "explicit-raw-bypass",
|
|
886
|
+
});
|
|
887
|
+
return 0;
|
|
888
|
+
}
|
|
889
|
+
const inspectionSkipReason = getOutputAwareInspectionSkipReason("allow-safe-inventory", executionInput);
|
|
890
|
+
if (inspectionSkipReason) {
|
|
891
|
+
await recordImmediateHookStats(executionInput, combinedText, storeRaw);
|
|
892
|
+
const stats = buildImmediateSkipStats(combinedText);
|
|
893
|
+
await writeHookDebug({
|
|
894
|
+
...debug,
|
|
895
|
+
...stats,
|
|
896
|
+
skipped: inspectionSkipReason,
|
|
897
|
+
});
|
|
898
|
+
return 0;
|
|
899
|
+
}
|
|
900
|
+
const maxInlineChars = readPositiveIntegerEnv("TOKENJUICE_CODEX_MAX_INLINE_CHARS");
|
|
901
|
+
try {
|
|
902
|
+
const outcome = await compactBashResult({
|
|
903
|
+
source: "codex",
|
|
904
|
+
command,
|
|
905
|
+
visibleText: combinedText,
|
|
906
|
+
...(typeof payload.cwd === "string" && payload.cwd.trim() ? { cwd: payload.cwd } : {}),
|
|
907
|
+
...(typeof exitCode === "number" ? { exitCode } : {}),
|
|
908
|
+
...(typeof maxInlineChars === "number" ? { maxInlineChars } : {}),
|
|
909
|
+
storeRaw,
|
|
910
|
+
metadata: {
|
|
911
|
+
source: "codex-post-tool-use",
|
|
912
|
+
},
|
|
913
|
+
minSavedCharsAny: HOOK_REWRITE_MIN_SAVED_CHARS,
|
|
914
|
+
genericFallbackMinSavedChars: GENERIC_FALLBACK_MIN_SAVED_CHARS,
|
|
915
|
+
genericFallbackMaxRatio: GENERIC_FALLBACK_MAX_RATIO,
|
|
916
|
+
skipGenericFallbackForCompoundCommands: true,
|
|
917
|
+
});
|
|
918
|
+
const result = outcome.action === "rewrite" ? outcome.result : outcome.result;
|
|
919
|
+
if (result) {
|
|
920
|
+
const rawChars = result.stats.rawChars;
|
|
921
|
+
const reducedChars = result.stats.reducedChars;
|
|
922
|
+
const savedChars = rawChars - reducedChars;
|
|
923
|
+
debug.rawChars = rawChars;
|
|
924
|
+
debug.reducedChars = reducedChars;
|
|
925
|
+
debug.savedChars = savedChars;
|
|
926
|
+
debug.ratio = result.stats.ratio;
|
|
927
|
+
debug.matchedReducer = result.classification.matchedReducer;
|
|
928
|
+
}
|
|
929
|
+
if (outcome.action === "keep") {
|
|
930
|
+
await writeHookDebug({ ...debug, skipped: outcome.reason });
|
|
931
|
+
return 0;
|
|
932
|
+
}
|
|
933
|
+
process.stdout.write(`${JSON.stringify(buildCodexReplacementOutput(outcome.result.inlineText, outcome.result.rawRef?.id))}\n`);
|
|
934
|
+
await writeHookDebug({ ...debug, rewrote: true });
|
|
935
|
+
return 0;
|
|
936
|
+
}
|
|
937
|
+
catch (error) {
|
|
938
|
+
await writeHookDebug({
|
|
939
|
+
...debug,
|
|
940
|
+
skipped: "hook-error",
|
|
941
|
+
error: error instanceof Error ? error.message : String(error),
|
|
942
|
+
});
|
|
943
|
+
return 0;
|
|
944
|
+
}
|
|
945
|
+
}
|