@openclaw/tokenjuice 2026.11.5 → 2026.11.10-beta.1
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 +1 -1
- package/dist/.source-module-urls/e1cd11006f37307698d3ccaa0b9377541a8f8fcd96acf7a0d93ee391c8c5abfa.json +1 -1
- package/dist/index.js +1 -2
- package/dist/tool-result-middleware.js +33 -19
- package/node_modules/tokenjuice/README.md +71 -272
- package/node_modules/tokenjuice/dist/cli/command-types.d.ts +36 -0
- package/node_modules/tokenjuice/dist/cli/command-types.js +1 -0
- package/node_modules/tokenjuice/dist/cli/doctor-commands.d.ts +2 -0
- package/node_modules/tokenjuice/dist/cli/doctor-commands.js +674 -0
- package/node_modules/tokenjuice/dist/cli/doctor-output.d.ts +2 -1
- package/node_modules/tokenjuice/dist/cli/doctor-output.js +9 -0
- package/node_modules/tokenjuice/dist/cli/host-command.d.ts +4 -0
- package/node_modules/tokenjuice/dist/cli/host-command.js +19 -0
- package/node_modules/tokenjuice/dist/cli/install-commands.d.ts +2 -0
- package/node_modules/tokenjuice/dist/cli/install-commands.js +1263 -0
- package/node_modules/tokenjuice/dist/cli/main.d.ts +2 -33
- package/node_modules/tokenjuice/dist/cli/main.js +255 -5950
- package/node_modules/tokenjuice/dist/cli/uninstall-commands.d.ts +2 -0
- package/node_modules/tokenjuice/dist/cli/uninstall-commands.js +554 -0
- package/node_modules/tokenjuice/dist/core/bounded-jsonl.js +15 -3
- package/node_modules/tokenjuice/dist/core/bounded-text-file.d.ts +3 -0
- package/node_modules/tokenjuice/dist/core/bounded-text-file.js +32 -0
- package/node_modules/tokenjuice/dist/core/classify.d.ts +0 -5
- package/node_modules/tokenjuice/dist/core/classify.js +1 -1
- package/node_modules/tokenjuice/dist/core/command-identity.d.ts +0 -2
- package/node_modules/tokenjuice/dist/core/command-identity.js +2 -2
- package/node_modules/tokenjuice/dist/core/command-match.d.ts +0 -3
- package/node_modules/tokenjuice/dist/core/command-match.js +88 -8
- package/node_modules/tokenjuice/dist/core/command.d.ts +0 -1
- package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +1 -1
- package/node_modules/tokenjuice/dist/core/env.d.ts +1 -0
- package/node_modules/tokenjuice/dist/core/env.js +8 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +7 -3
- package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +190 -10
- package/node_modules/tokenjuice/dist/core/integrations/compact-copilot-result.d.ts +6 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-copilot-result.js +50 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-deepseek-result.d.ts +7 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-deepseek-result.js +46 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-framework-result.d.ts +11 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-framework-result.js +19 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-opencode-v2-result.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-opencode-v2-result.js +39 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-qoder-result.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/integrations/compact-qoder-result.js +34 -0
- package/node_modules/tokenjuice/dist/core/integrations/openclaw-command.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/integrations/openclaw-command.js +13 -0
- package/node_modules/tokenjuice/dist/core/integrations/rewrite-cline-input.d.ts +4 -0
- package/node_modules/tokenjuice/dist/core/integrations/rewrite-cline-input.js +18 -0
- package/node_modules/tokenjuice/dist/core/inventory-safety.d.ts +0 -1
- package/node_modules/tokenjuice/dist/core/inventory-safety.js +1 -1
- package/node_modules/tokenjuice/dist/core/record-fields.d.ts +1 -0
- package/node_modules/tokenjuice/dist/core/record-fields.js +9 -0
- package/node_modules/tokenjuice/dist/core/reduce-inspection-summary.d.ts +2 -1
- package/node_modules/tokenjuice/dist/core/reduce-inspection-summary.js +7 -94
- package/node_modules/tokenjuice/dist/core/simple-yaml-frontmatter.d.ts +9 -0
- package/node_modules/tokenjuice/dist/core/simple-yaml-frontmatter.js +125 -0
- package/node_modules/tokenjuice/dist/core/source.d.ts +0 -1
- package/node_modules/tokenjuice/dist/core/source.js +14 -4
- package/node_modules/tokenjuice/dist/core/structural-markers.d.ts +11 -0
- package/node_modules/tokenjuice/dist/core/structural-markers.js +49 -0
- package/node_modules/tokenjuice/dist/core/text.d.ts +0 -1
- package/node_modules/tokenjuice/dist/core/text.js +0 -3
- package/node_modules/tokenjuice/dist/core/toml-structure.d.ts +2 -0
- package/node_modules/tokenjuice/dist/core/toml-structure.js +83 -0
- package/node_modules/tokenjuice/dist/core/validate-rules.d.ts +2 -2
- package/node_modules/tokenjuice/dist/core/wrap.js +1 -1
- package/node_modules/tokenjuice/dist/hosts/adal/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/adal/index.js +15 -125
- package/node_modules/tokenjuice/dist/hosts/aether/index.d.ts +2 -7
- package/node_modules/tokenjuice/dist/hosts/aether/index.js +17 -155
- package/node_modules/tokenjuice/dist/hosts/agent-layer/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/agent-layer/index.js +10 -64
- package/node_modules/tokenjuice/dist/hosts/agentinit/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/agentinit/index.js +15 -111
- package/node_modules/tokenjuice/dist/hosts/agentlink/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/agentlink/index.js +14 -97
- package/node_modules/tokenjuice/dist/hosts/agentloom/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/agentloom/index.js +11 -52
- package/node_modules/tokenjuice/dist/hosts/agents-cli/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/agents-cli/index.js +10 -41
- package/node_modules/tokenjuice/dist/hosts/agents-md/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/agents-md/index.js +16 -128
- package/node_modules/tokenjuice/dist/hosts/agentsge/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/agentsge/index.js +11 -52
- package/node_modules/tokenjuice/dist/hosts/agentsmesh/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/agentsmesh/index.js +10 -53
- package/node_modules/tokenjuice/dist/hosts/ai-memory-protocol/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/ai-memory-protocol/index.js +13 -42
- package/node_modules/tokenjuice/dist/hosts/aictl/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/aictl/index.js +17 -128
- package/node_modules/tokenjuice/dist/hosts/aider/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/aider/index.js +6 -18
- package/node_modules/tokenjuice/dist/hosts/amazon-q/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/amazon-q/index.js +31 -105
- package/node_modules/tokenjuice/dist/hosts/amp/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/amp/index.js +11 -72
- package/node_modules/tokenjuice/dist/hosts/ante/index.d.ts +11 -0
- package/node_modules/tokenjuice/dist/hosts/ante/index.js +76 -0
- package/node_modules/tokenjuice/dist/hosts/antigravity/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/antigravity/index.js +29 -117
- package/node_modules/tokenjuice/dist/hosts/anywhere-agents/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/anywhere-agents/index.js +14 -97
- package/node_modules/tokenjuice/dist/hosts/augment/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/augment/index.js +29 -117
- package/node_modules/tokenjuice/dist/hosts/avante/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/avante/index.js +5 -27
- package/node_modules/tokenjuice/dist/hosts/baz/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/baz/index.js +17 -132
- package/node_modules/tokenjuice/dist/hosts/bito/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/bito/index.js +11 -108
- package/node_modules/tokenjuice/dist/hosts/blackbox/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/blackbox/index.js +16 -157
- package/node_modules/tokenjuice/dist/hosts/blocks/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/blocks/index.js +16 -157
- package/node_modules/tokenjuice/dist/hosts/bob/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/bob/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/builder/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/builder/index.js +34 -131
- package/node_modules/tokenjuice/dist/hosts/charlie/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/charlie/index.js +16 -140
- package/node_modules/tokenjuice/dist/hosts/claude-code/index.js +12 -49
- package/node_modules/tokenjuice/dist/hosts/clawdbot/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/clawdbot/index.js +48 -235
- package/node_modules/tokenjuice/dist/hosts/cline/index.d.ts +6 -13
- package/node_modules/tokenjuice/dist/hosts/cline/index.js +134 -135
- package/node_modules/tokenjuice/dist/hosts/codeant/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/codeant/index.js +12 -123
- package/node_modules/tokenjuice/dist/hosts/codebuddy/index.js +14 -58
- package/node_modules/tokenjuice/dist/hosts/codebuff/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/codebuff/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/codegen/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/codegen/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/coder-agents/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/coder-agents/index.js +25 -193
- package/node_modules/tokenjuice/dist/hosts/coderabbit/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/coderabbit/index.js +16 -173
- package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +3 -4
- package/node_modules/tokenjuice/dist/hosts/codex/index.js +26 -58
- package/node_modules/tokenjuice/dist/hosts/command-code/index.d.ts +6 -13
- package/node_modules/tokenjuice/dist/hosts/command-code/index.js +87 -331
- package/node_modules/tokenjuice/dist/hosts/continue/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/continue/index.js +6 -18
- package/node_modules/tokenjuice/dist/hosts/copilot-agent/index.d.ts +2 -11
- package/node_modules/tokenjuice/dist/hosts/copilot-agent/index.js +15 -166
- package/node_modules/tokenjuice/dist/hosts/copilot-cli/index.d.ts +2 -11
- package/node_modules/tokenjuice/dist/hosts/copilot-cli/index.js +24 -196
- package/node_modules/tokenjuice/dist/hosts/copilot-sdk/index.d.ts +12 -0
- package/node_modules/tokenjuice/dist/hosts/copilot-sdk/index.js +15 -0
- package/node_modules/tokenjuice/dist/hosts/crush/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/crush/index.js +6 -18
- package/node_modules/tokenjuice/dist/hosts/cursor/index.js +7 -8
- package/node_modules/tokenjuice/dist/hosts/deepagents/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/deepagents/index.js +15 -125
- package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/cordis.patch.yml +3 -0
- package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/index.js +9656 -0
- package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/package.json +18 -0
- package/node_modules/tokenjuice/dist/hosts/deepseek-harness/runtime.d.ts +7 -0
- package/node_modules/tokenjuice/dist/hosts/deepseek-harness/runtime.js +23 -0
- package/node_modules/tokenjuice/dist/hosts/devin/index.d.ts +2 -11
- package/node_modules/tokenjuice/dist/hosts/devin/index.js +7 -9
- package/node_modules/tokenjuice/dist/hosts/docker-agent/index.d.ts +2 -7
- package/node_modules/tokenjuice/dist/hosts/docker-agent/index.js +19 -99
- package/node_modules/tokenjuice/dist/hosts/dot-agents/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/dot-agents/index.js +12 -41
- package/node_modules/tokenjuice/dist/hosts/droid/index.d.ts +5 -12
- package/node_modules/tokenjuice/dist/hosts/droid/index.js +106 -211
- package/node_modules/tokenjuice/dist/hosts/eca/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/eca/index.js +26 -190
- package/node_modules/tokenjuice/dist/hosts/elyra/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/elyra/index.js +26 -190
- package/node_modules/tokenjuice/dist/hosts/firebase-studio/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/firebase-studio/index.js +16 -123
- package/node_modules/tokenjuice/dist/hosts/forgecode/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/forgecode/index.js +20 -161
- package/node_modules/tokenjuice/dist/hosts/gemini-cli/index.d.ts +5 -12
- package/node_modules/tokenjuice/dist/hosts/gemini-cli/index.js +87 -94
- package/node_modules/tokenjuice/dist/hosts/gitlab-duo/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/gitlab-duo/index.js +17 -123
- package/node_modules/tokenjuice/dist/hosts/goose/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/goose/index.js +34 -77
- package/node_modules/tokenjuice/dist/hosts/gptme/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/gptme/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/greptile/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/greptile/index.js +18 -156
- package/node_modules/tokenjuice/dist/hosts/grok-bot/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/grok-bot/index.js +14 -110
- package/node_modules/tokenjuice/dist/hosts/grok-build/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/grok-build/index.js +13 -113
- package/node_modules/tokenjuice/dist/hosts/grok-cli/index.d.ts +7 -14
- package/node_modules/tokenjuice/dist/hosts/grok-cli/index.js +32 -188
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/__init__.py +1 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/plugin.yaml +7 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/README.md +29 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/__init__.py +3 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/bridge.py +39 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/fastmcp.py +24 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/hermes.py +13 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/langchain.py +38 -0
- package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/plugin.yaml +7 -0
- package/node_modules/tokenjuice/dist/hosts/jean2/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/jean2/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/jetbrains-ai/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/jetbrains-ai/index.js +33 -133
- package/node_modules/tokenjuice/dist/hosts/jules/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/jules/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/junie/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/junie/index.js +5 -27
- package/node_modules/tokenjuice/dist/hosts/kilo/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/kilo/index.js +6 -18
- package/node_modules/tokenjuice/dist/hosts/kimi/index.d.ts +7 -13
- package/node_modules/tokenjuice/dist/hosts/kimi/index.js +38 -156
- package/node_modules/tokenjuice/dist/hosts/kiro/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/kiro/index.js +6 -18
- package/node_modules/tokenjuice/dist/hosts/knowns/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/knowns/index.js +35 -203
- package/node_modules/tokenjuice/dist/hosts/leanctl/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/leanctl/index.js +15 -156
- package/node_modules/tokenjuice/dist/hosts/localcode/index.d.ts +2 -7
- package/node_modules/tokenjuice/dist/hosts/localcode/index.js +10 -68
- package/node_modules/tokenjuice/dist/hosts/mastra/index.d.ts +28 -0
- package/node_modules/tokenjuice/dist/hosts/mastra/index.js +26 -0
- package/node_modules/tokenjuice/dist/hosts/mcp-agent/index.d.ts +2 -7
- package/node_modules/tokenjuice/dist/hosts/mcp-agent/index.js +15 -109
- package/node_modules/tokenjuice/dist/hosts/mini-swe-agent/index.d.ts +2 -7
- package/node_modules/tokenjuice/dist/hosts/mini-swe-agent/index.js +21 -110
- package/node_modules/tokenjuice/dist/hosts/mistral-vibe/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/mistral-vibe/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/mux/index.d.ts +6 -13
- package/node_modules/tokenjuice/dist/hosts/mux/index.js +54 -349
- package/node_modules/tokenjuice/dist/hosts/novakit/index.d.ts +5 -16
- package/node_modules/tokenjuice/dist/hosts/novakit/index.js +35 -203
- package/node_modules/tokenjuice/dist/hosts/ona/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/ona/index.js +19 -283
- package/node_modules/tokenjuice/dist/hosts/open-interpreter/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/open-interpreter/index.js +11 -66
- package/node_modules/tokenjuice/dist/hosts/openclaw/extension.js +6 -5
- package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +540 -363
- package/node_modules/tokenjuice/dist/hosts/opencode/index.js +8 -54
- package/node_modules/tokenjuice/dist/hosts/opencode/v2/bundle/index.js +9648 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/v2/index.d.ts +37 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/v2/index.js +97 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/v2/runtime.d.ts +13 -0
- package/node_modules/tokenjuice/dist/hosts/opencode/v2/runtime.js +23 -0
- package/node_modules/tokenjuice/dist/hosts/openhands/index.d.ts +7 -14
- package/node_modules/tokenjuice/dist/hosts/openhands/index.js +111 -186
- package/node_modules/tokenjuice/dist/hosts/openwebui/index.d.ts +2 -7
- package/node_modules/tokenjuice/dist/hosts/openwebui/index.js +2 -24
- package/node_modules/tokenjuice/dist/hosts/pi/extension/pi-types.d.ts +3 -2
- package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.d.ts +2 -1
- package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +545 -359
- package/node_modules/tokenjuice/dist/hosts/pi/extension/status-panel.d.ts +1 -1
- package/node_modules/tokenjuice/dist/hosts/pi/extension/status.d.ts +1 -1
- package/node_modules/tokenjuice/dist/hosts/pi/extension/tool-result.d.ts +1 -1
- package/node_modules/tokenjuice/dist/hosts/pi/index.d.ts +1 -0
- package/node_modules/tokenjuice/dist/hosts/pi/index.js +5 -53
- package/node_modules/tokenjuice/dist/hosts/pi-go/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/pi-go/index.js +26 -190
- package/node_modules/tokenjuice/dist/hosts/plandex/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/plandex/index.js +10 -41
- package/node_modules/tokenjuice/dist/hosts/qoder/hook-install.d.ts +22 -0
- package/node_modules/tokenjuice/dist/hosts/qoder/hook-install.js +105 -0
- package/node_modules/tokenjuice/dist/hosts/qoder/hook.d.ts +1 -0
- package/node_modules/tokenjuice/dist/hosts/qoder/hook.js +22 -0
- package/node_modules/tokenjuice/dist/hosts/qoder/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/qoder/index.js +13 -113
- package/node_modules/tokenjuice/dist/hosts/qoderwork/index.d.ts +36 -0
- package/node_modules/tokenjuice/dist/hosts/qoderwork/index.js +20 -0
- package/node_modules/tokenjuice/dist/hosts/qodo/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/qodo/index.js +20 -290
- package/node_modules/tokenjuice/dist/hosts/qwen-code/index.d.ts +6 -13
- package/node_modules/tokenjuice/dist/hosts/qwen-code/index.js +60 -165
- package/node_modules/tokenjuice/dist/hosts/qwenwork/index.d.ts +36 -0
- package/node_modules/tokenjuice/dist/hosts/qwenwork/index.js +20 -0
- package/node_modules/tokenjuice/dist/hosts/replit/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/replit/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/roo/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/roo/index.js +5 -31
- package/node_modules/tokenjuice/dist/hosts/rovo/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/rovo/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/ruler/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/ruler/index.js +10 -64
- package/node_modules/tokenjuice/dist/hosts/shared/bundle-runtime.d.ts +2 -0
- package/node_modules/tokenjuice/dist/hosts/shared/bundle-runtime.js +56 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.d.ts +3 -8
- package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.js +3 -3
- package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.d.ts +112 -101
- package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.js +10 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hook-output.d.ts +0 -1
- package/node_modules/tokenjuice/dist/hosts/shared/hook-output.js +1 -1
- package/node_modules/tokenjuice/dist/hosts/shared/hooks-json-file.d.ts +15 -0
- package/node_modules/tokenjuice/dist/hosts/shared/hooks-json-file.js +93 -0
- package/node_modules/tokenjuice/dist/hosts/shared/host-command.d.ts +1 -1
- package/node_modules/tokenjuice/dist/hosts/shared/host-command.js +4 -4
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-doctor.d.ts +4 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-file.d.ts +26 -6
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-file.js +125 -5
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-guidance.d.ts +7 -0
- package/node_modules/tokenjuice/dist/hosts/shared/instruction-guidance.js +24 -0
- package/node_modules/tokenjuice/dist/hosts/shared/managed-skill.d.ts +42 -0
- package/node_modules/tokenjuice/dist/hosts/shared/managed-skill.js +87 -0
- package/node_modules/tokenjuice/dist/hosts/shared/marker-instruction-doctor.d.ts +29 -0
- package/node_modules/tokenjuice/dist/hosts/shared/marker-instruction-doctor.js +72 -0
- package/node_modules/tokenjuice/dist/hosts/shared/marker-instructions.d.ts +12 -0
- package/node_modules/tokenjuice/dist/hosts/shared/marker-instructions.js +43 -0
- package/node_modules/tokenjuice/dist/hosts/shared/owned-instruction-doctor.d.ts +9 -0
- package/node_modules/tokenjuice/dist/hosts/shared/owned-instruction-doctor.js +17 -0
- package/node_modules/tokenjuice/dist/hosts/shared/path-ancestors.d.ts +14 -0
- package/node_modules/tokenjuice/dist/hosts/shared/path-ancestors.js +117 -0
- package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.d.ts +7 -7
- package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.js +13 -48
- package/node_modules/tokenjuice/dist/hosts/shared/private-config-file.d.ts +2 -0
- package/node_modules/tokenjuice/dist/hosts/shared/private-config-file.js +36 -0
- package/node_modules/tokenjuice/dist/hosts/shared/project-root.d.ts +5 -0
- package/node_modules/tokenjuice/dist/hosts/shared/project-root.js +33 -0
- package/node_modules/tokenjuice/dist/hosts/shared/project-skill-doctor.d.ts +14 -0
- package/node_modules/tokenjuice/dist/hosts/shared/project-skill-doctor.js +62 -0
- package/node_modules/tokenjuice/dist/hosts/shared/restorable-rule.d.ts +15 -0
- package/node_modules/tokenjuice/dist/hosts/shared/restorable-rule.js +64 -0
- package/node_modules/tokenjuice/dist/hosts/shared/restorable-skill.d.ts +15 -0
- package/node_modules/tokenjuice/dist/hosts/shared/restorable-skill.js +48 -0
- package/node_modules/tokenjuice/dist/hosts/shared/settings-file.d.ts +5 -1
- package/node_modules/tokenjuice/dist/hosts/shared/settings-file.js +33 -5
- package/node_modules/tokenjuice/dist/hosts/shared/skill-frontmatter.d.ts +5 -0
- package/node_modules/tokenjuice/dist/hosts/shared/skill-frontmatter.js +18 -0
- package/node_modules/tokenjuice/dist/hosts/stagewise/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/stagewise/index.js +50 -377
- package/node_modules/tokenjuice/dist/hosts/swe-agent/index.d.ts +2 -7
- package/node_modules/tokenjuice/dist/hosts/swe-agent/index.js +20 -88
- package/node_modules/tokenjuice/dist/hosts/tabby/index.d.ts +2 -8
- package/node_modules/tokenjuice/dist/hosts/tabby/index.js +13 -190
- package/node_modules/tokenjuice/dist/hosts/tabnine/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/tabnine/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/trae/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/trae/index.js +17 -123
- package/node_modules/tokenjuice/dist/hosts/uipath/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/uipath/index.js +13 -123
- package/node_modules/tokenjuice/dist/hosts/vscode-copilot/index.d.ts +2 -11
- package/node_modules/tokenjuice/dist/hosts/vscode-copilot/index.js +15 -101
- package/node_modules/tokenjuice/dist/hosts/warp/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/warp/index.js +14 -116
- package/node_modules/tokenjuice/dist/hosts/windsurf/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/windsurf/index.js +6 -18
- package/node_modules/tokenjuice/dist/hosts/zed/index.d.ts +5 -17
- package/node_modules/tokenjuice/dist/hosts/zed/index.js +5 -27
- package/node_modules/tokenjuice/dist/hosts/zencoder/index.d.ts +2 -9
- package/node_modules/tokenjuice/dist/hosts/zencoder/index.js +42 -139
- package/node_modules/tokenjuice/dist/index.d.ts +20 -4
- package/node_modules/tokenjuice/dist/index.js +14 -4
- package/node_modules/tokenjuice/dist/python/LICENSE +21 -0
- package/node_modules/tokenjuice/dist/python/README.md +38 -0
- package/node_modules/tokenjuice/dist/python/pyproject.toml +30 -0
- package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/README.md +29 -0
- package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/__init__.py +3 -0
- package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/bridge.py +39 -0
- package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/fastmcp.py +24 -0
- package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/hermes.py +13 -0
- package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/langchain.py +38 -0
- package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/plugin.yaml +7 -0
- package/node_modules/tokenjuice/dist/types.d.ts +9 -8
- package/node_modules/tokenjuice/package.json +32 -11
- package/package.json +5 -5
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
export async function realpathExistingAncestor(path) {
|
|
4
|
+
let current = path;
|
|
5
|
+
while (true) {
|
|
6
|
+
try {
|
|
7
|
+
return await realpath(current);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error.code !== "ENOENT") {
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
const parent = dirname(current);
|
|
14
|
+
if (parent === current) {
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
current = parent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export async function findExistingAncestor(path) {
|
|
22
|
+
let current = path;
|
|
23
|
+
while (true) {
|
|
24
|
+
try {
|
|
25
|
+
return { path: current, realPath: await realpath(current) };
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error.code !== "ENOENT") {
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
const parent = dirname(current);
|
|
32
|
+
if (parent === current) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
current = parent;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function isInsideOrEqual(parentDir, childPath) {
|
|
40
|
+
const relativePath = relative(parentDir, childPath);
|
|
41
|
+
return relativePath === "" || (!relativePath.startsWith("..") && !isAbsolute(relativePath));
|
|
42
|
+
}
|
|
43
|
+
export async function rejectSymlinkPathComponents(filePath, projectDir, errorMessage) {
|
|
44
|
+
const relativePath = relative(projectDir, filePath);
|
|
45
|
+
const segments = relativePath.split(sep).filter(Boolean);
|
|
46
|
+
let currentPath = projectDir;
|
|
47
|
+
for (const segment of segments.slice(0, -1)) {
|
|
48
|
+
currentPath = join(currentPath, segment);
|
|
49
|
+
try {
|
|
50
|
+
const stats = await lstat(currentPath);
|
|
51
|
+
if (stats.isSymbolicLink()) {
|
|
52
|
+
throw new Error(errorMessage);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === "ENOENT") {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function createSymlinkGuard(errorMessage) {
|
|
64
|
+
return async (filePath, ...args) => {
|
|
65
|
+
try {
|
|
66
|
+
const stats = await lstat(filePath);
|
|
67
|
+
if (stats.isSymbolicLink()) {
|
|
68
|
+
throw new Error(errorMessage(filePath, ...args));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error.code === "ENOENT") {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function createProjectInstructionPathResolver(label, rejectSymlink) {
|
|
80
|
+
return async (filePath, projectDir, realProjectDir = projectDir) => {
|
|
81
|
+
const resolvedPath = resolve(filePath);
|
|
82
|
+
if (projectDir !== realProjectDir) {
|
|
83
|
+
throw new Error(`cannot use ${label} ${resolvedPath}; tokenjuice will not read or write through instruction symlinks`);
|
|
84
|
+
}
|
|
85
|
+
const realParentDir = await realpathExistingAncestor(dirname(resolvedPath));
|
|
86
|
+
if (!isInsideOrEqual(realProjectDir, realParentDir)) {
|
|
87
|
+
throw new Error(`cannot use ${label} ${resolvedPath}; tokenjuice will not write through instruction directories outside ${realProjectDir}`);
|
|
88
|
+
}
|
|
89
|
+
await rejectSymlink(projectDir);
|
|
90
|
+
await rejectSymlinkPathComponents(resolvedPath, projectDir, `cannot use ${label} ${resolvedPath}; tokenjuice will not read or write through instruction symlinks`);
|
|
91
|
+
await rejectSymlink(resolvedPath);
|
|
92
|
+
return resolvedPath;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Checks symlink components before canonical ancestor containment. */
|
|
96
|
+
export function createCanonicalProjectSkillPaths(label, relativeSkillPath, rejectSymlink) {
|
|
97
|
+
const skillPathSegments = relativeSkillPath.split("/");
|
|
98
|
+
function getExpectedSkillPath(projectDir) {
|
|
99
|
+
return join(projectDir, ...skillPathSegments);
|
|
100
|
+
}
|
|
101
|
+
async function resolveSafeProjectSkillPath(filePath, projectDir, realProjectDir = projectDir) {
|
|
102
|
+
const resolvedPath = resolve(filePath);
|
|
103
|
+
await rejectSymlink(projectDir);
|
|
104
|
+
await rejectSymlinkPathComponents(resolvedPath, projectDir, `cannot use ${label} ${resolvedPath}; tokenjuice will not read or write through instruction symlinks`);
|
|
105
|
+
const realParentDir = await realpathExistingAncestor(dirname(resolvedPath));
|
|
106
|
+
if (!isInsideOrEqual(realProjectDir, realParentDir)) {
|
|
107
|
+
throw new Error(`cannot use ${label} ${resolvedPath}; tokenjuice will not write through instruction directories outside ${realProjectDir}`);
|
|
108
|
+
}
|
|
109
|
+
await rejectSymlink(resolvedPath);
|
|
110
|
+
const expectedSkillPath = getExpectedSkillPath(projectDir);
|
|
111
|
+
if (resolvedPath !== expectedSkillPath) {
|
|
112
|
+
throw new Error(`cannot use ${label} ${resolvedPath}; tokenjuice only installs the project-local ${relativeSkillPath} file`);
|
|
113
|
+
}
|
|
114
|
+
return resolvedPath;
|
|
115
|
+
}
|
|
116
|
+
return { getExpectedSkillPath, resolveSafeProjectSkillPath };
|
|
117
|
+
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* wrapped command, detecting already-wrapped commands — is host-agnostic and
|
|
13
13
|
* lives here.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
type WrapLauncherOptions = {
|
|
16
16
|
/** When true, bypass the `PATH` lookup for an installed tokenjuice binary and route through the caller's build. */
|
|
17
17
|
local?: boolean;
|
|
18
18
|
/** Override the binary/entrypoint path. Defaults to `process.argv[1]`. */
|
|
@@ -27,8 +27,7 @@ export type BuildWrapLauncherHookCommandOptions = WrapLauncherOptions & {
|
|
|
27
27
|
hostName: string;
|
|
28
28
|
};
|
|
29
29
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
30
|
-
export
|
|
31
|
-
export declare function pathExists(path: string): Promise<boolean>;
|
|
30
|
+
export { isExecutableFile, pathExists } from "./host-command.js";
|
|
32
31
|
/**
|
|
33
32
|
* Walk `PATH` and return the first executable `tokenjuice` (or Windows
|
|
34
33
|
* variant) found. Empty segments and missing entries are skipped.
|
|
@@ -64,10 +63,11 @@ export declare function buildWrapLauncherHookCommand(options: BuildWrapLauncherH
|
|
|
64
63
|
* Build the command the host should ask the agent to run — the original
|
|
65
64
|
* command routed through `tokenjuice wrap` and the selected host shell:
|
|
66
65
|
*
|
|
67
|
-
* <launcher-command> wrap -- <shell-path> -lc '<original>'
|
|
66
|
+
* <launcher-command> wrap --keep-failures -- <shell-path> -lc '<original>'
|
|
68
67
|
*
|
|
69
68
|
* `wrapLauncher` comes from the PreToolUse hook's `--wrap-launcher` argv so
|
|
70
|
-
* the dispatched binary matches the one the host installed.
|
|
69
|
+
* the dispatched binary matches the one the host installed. Automatic wrappers
|
|
70
|
+
* preserve failed stdout/stderr; only successful output is eligible for reduction.
|
|
71
71
|
*/
|
|
72
72
|
export declare function buildWrappedCommand(params: {
|
|
73
73
|
wrapLauncher: string;
|
|
@@ -83,9 +83,9 @@ export declare function buildWrappedCommand(params: {
|
|
|
83
83
|
* `tokenjuice wrap ...` — bare executable on PATH
|
|
84
84
|
* `/abs/path/to/tokenjuice wrap ...` — absolute launcher (pnpm link,
|
|
85
85
|
* homebrew, etc.)
|
|
86
|
-
* `node /some/dist/cli/main.js
|
|
86
|
+
* `node /some/dist/cli/main.js wrap ...` — node-dispatched local build
|
|
87
87
|
*
|
|
88
88
|
* Avoids double-wrapping when a tool call is already routed through tokenjuice
|
|
89
89
|
* (e.g. the user invoked `tokenjuice wrap --raw -- <cmd>` explicitly).
|
|
90
90
|
*/
|
|
91
|
-
export declare function commandAlreadyWrapped(command: string): boolean;
|
|
91
|
+
export declare function commandAlreadyWrapped(command: string, platform?: NodeJS.Platform): boolean;
|
|
@@ -12,56 +12,20 @@
|
|
|
12
12
|
* wrapped command, detecting already-wrapped commands — is host-agnostic and
|
|
13
13
|
* lives here.
|
|
14
14
|
*/
|
|
15
|
-
import { constants as fsConstants } from "node:fs";
|
|
16
|
-
import { access } from "node:fs/promises";
|
|
17
15
|
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
18
16
|
import { stripLeadingCdPrefix } from "../../core/command.js";
|
|
17
|
+
import { resolveCommandFromPath, isExecutableFile } from "./host-command.js";
|
|
19
18
|
import { isNodeExecutablePath, isTokenjuiceExecutablePath, parseShellWords, posixShellQuote, shellQuote, } from "./hook-command.js";
|
|
20
19
|
export function isRecord(value) {
|
|
21
20
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
21
|
}
|
|
23
|
-
export
|
|
24
|
-
try {
|
|
25
|
-
await access(path, fsConstants.X_OK);
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export async function pathExists(path) {
|
|
33
|
-
try {
|
|
34
|
-
await access(path);
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
22
|
+
export { isExecutableFile, pathExists } from "./host-command.js";
|
|
41
23
|
/**
|
|
42
24
|
* Walk `PATH` and return the first executable `tokenjuice` (or Windows
|
|
43
25
|
* variant) found. Empty segments and missing entries are skipped.
|
|
44
26
|
*/
|
|
45
27
|
export async function resolveInstalledTokenjuicePath() {
|
|
46
|
-
|
|
47
|
-
if (!pathValue) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
const candidateNames = process.platform === "win32"
|
|
51
|
-
? ["tokenjuice.exe", "tokenjuice.cmd", "tokenjuice.bat", "tokenjuice"]
|
|
52
|
-
: ["tokenjuice"];
|
|
53
|
-
for (const segment of pathValue.split(delimiter)) {
|
|
54
|
-
if (!segment) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
for (const candidateName of candidateNames) {
|
|
58
|
-
const candidatePath = join(segment, candidateName);
|
|
59
|
-
if (await isExecutableFile(candidatePath)) {
|
|
60
|
-
return candidatePath;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return undefined;
|
|
28
|
+
return resolveCommandFromPath("tokenjuice");
|
|
65
29
|
}
|
|
66
30
|
/**
|
|
67
31
|
* Resolve a single shell candidate string to an executable path. Accepts
|
|
@@ -140,10 +104,11 @@ export async function buildWrapLauncherHookCommand(options) {
|
|
|
140
104
|
* Build the command the host should ask the agent to run — the original
|
|
141
105
|
* command routed through `tokenjuice wrap` and the selected host shell:
|
|
142
106
|
*
|
|
143
|
-
* <launcher-command> wrap -- <shell-path> -lc '<original>'
|
|
107
|
+
* <launcher-command> wrap --keep-failures -- <shell-path> -lc '<original>'
|
|
144
108
|
*
|
|
145
109
|
* `wrapLauncher` comes from the PreToolUse hook's `--wrap-launcher` argv so
|
|
146
|
-
* the dispatched binary matches the one the host installed.
|
|
110
|
+
* the dispatched binary matches the one the host installed. Automatic wrappers
|
|
111
|
+
* preserve failed stdout/stderr; only successful output is eligible for reduction.
|
|
147
112
|
*/
|
|
148
113
|
export function buildWrappedCommand(params) {
|
|
149
114
|
const nodePath = params.nodePath ?? process.execPath;
|
|
@@ -151,7 +116,7 @@ export function buildWrappedCommand(params) {
|
|
|
151
116
|
? `${posixShellQuote(nodePath)} ${posixShellQuote(params.wrapLauncher)}`
|
|
152
117
|
: posixShellQuote(params.wrapLauncher);
|
|
153
118
|
const sourceArgs = params.source ? ` --source ${posixShellQuote(params.source)}` : "";
|
|
154
|
-
return `${launcherCommand} wrap${sourceArgs} -- ${posixShellQuote(params.shellPath)} -lc ${posixShellQuote(params.command)}`;
|
|
119
|
+
return `${launcherCommand} wrap --keep-failures${sourceArgs} -- ${posixShellQuote(params.shellPath)} -lc ${posixShellQuote(params.command)}`;
|
|
155
120
|
}
|
|
156
121
|
/**
|
|
157
122
|
* Detect whether a command has already been wrapped by tokenjuice. Matches
|
|
@@ -160,15 +125,15 @@ export function buildWrappedCommand(params) {
|
|
|
160
125
|
* `tokenjuice wrap ...` — bare executable on PATH
|
|
161
126
|
* `/abs/path/to/tokenjuice wrap ...` — absolute launcher (pnpm link,
|
|
162
127
|
* homebrew, etc.)
|
|
163
|
-
* `node /some/dist/cli/main.js
|
|
128
|
+
* `node /some/dist/cli/main.js wrap ...` — node-dispatched local build
|
|
164
129
|
*
|
|
165
130
|
* Avoids double-wrapping when a tool call is already routed through tokenjuice
|
|
166
131
|
* (e.g. the user invoked `tokenjuice wrap --raw -- <cmd>` explicitly).
|
|
167
132
|
*/
|
|
168
|
-
export function commandAlreadyWrapped(command) {
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
const argv = parseShellWords(stripLeadingCdPrefix(command),
|
|
133
|
+
export function commandAlreadyWrapped(command, platform = "linux") {
|
|
134
|
+
// Most adapters use POSIX shells even on Windows; native PowerShell callers
|
|
135
|
+
// select Windows parsing to preserve backslashes in executable paths.
|
|
136
|
+
const argv = parseShellWords(stripLeadingCdPrefix(command), platform);
|
|
172
137
|
if (argv.length < 2) {
|
|
173
138
|
return false;
|
|
174
139
|
}
|
|
@@ -181,7 +146,7 @@ export function commandAlreadyWrapped(command) {
|
|
|
181
146
|
&& isNodeExecutablePath(first)
|
|
182
147
|
&& typeof second === "string"
|
|
183
148
|
&& second.endsWith(".js")
|
|
184
|
-
&& argv
|
|
149
|
+
&& argv[2] === "wrap") {
|
|
185
150
|
return true;
|
|
186
151
|
}
|
|
187
152
|
return false;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { InstructionFileSnapshot, WriteInstructionFileResult } from "./instruction-file.js";
|
|
2
|
+
export declare function writePrivateConfigFile(filePath: string, text: string, existing: InstructionFileSnapshot, chooseBackupPath: (filePath: string) => Promise<string>): Promise<WriteInstructionFileResult<"configPath">>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { chmod, lstat, mkdir, mkdtemp, rename, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
async function getExistingFileMode(filePath, existing) {
|
|
4
|
+
if (!existing.exists) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return (await lstat(filePath)).mode & 0o777;
|
|
8
|
+
}
|
|
9
|
+
async function writePrivateConfigAtomically(filePath, text, mode) {
|
|
10
|
+
const fileMode = mode ?? 0o600;
|
|
11
|
+
await mkdir(dirname(filePath), { recursive: true, mode: 0o700 });
|
|
12
|
+
const tempDir = await mkdtemp(join(dirname(filePath), ".tokenjuice-"));
|
|
13
|
+
const tempPath = join(tempDir, "write");
|
|
14
|
+
try {
|
|
15
|
+
await writeFile(tempPath, text, { encoding: "utf8", flag: "wx", mode: fileMode });
|
|
16
|
+
await chmod(tempPath, fileMode);
|
|
17
|
+
await rename(tempPath, filePath);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function writePrivateConfigFile(filePath, text, existing, chooseBackupPath) {
|
|
24
|
+
const mode = await getExistingFileMode(filePath, existing);
|
|
25
|
+
let backupPath;
|
|
26
|
+
if (existing.exists) {
|
|
27
|
+
backupPath = await chooseBackupPath(filePath);
|
|
28
|
+
await writeFile(backupPath, existing.text, { encoding: "utf8", flag: "wx", mode: mode ?? 0o600 });
|
|
29
|
+
await chmod(backupPath, mode ?? 0o600);
|
|
30
|
+
}
|
|
31
|
+
await writePrivateConfigAtomically(filePath, text, mode);
|
|
32
|
+
return {
|
|
33
|
+
configPath: filePath,
|
|
34
|
+
...(backupPath ? { backupPath } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function hasGitMetadata(dir: string): Promise<boolean>;
|
|
2
|
+
export declare function findGitRoot(startDir: string): Promise<string | undefined>;
|
|
3
|
+
export declare function createProjectDirResolver(environmentKey: string): (options?: {
|
|
4
|
+
projectDir?: string;
|
|
5
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
export async function hasGitMetadata(dir) {
|
|
4
|
+
try {
|
|
5
|
+
await stat(join(dir, ".git"));
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function findGitRoot(startDir) {
|
|
13
|
+
let current = resolve(startDir);
|
|
14
|
+
while (true) {
|
|
15
|
+
if (await hasGitMetadata(current)) {
|
|
16
|
+
return current;
|
|
17
|
+
}
|
|
18
|
+
const parent = dirname(current);
|
|
19
|
+
if (parent === current) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
current = parent;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function createProjectDirResolver(environmentKey) {
|
|
26
|
+
return async (options = {}) => {
|
|
27
|
+
const explicitProjectDir = options.projectDir || process.env[environmentKey];
|
|
28
|
+
if (explicitProjectDir) {
|
|
29
|
+
return resolve(explicitProjectDir);
|
|
30
|
+
}
|
|
31
|
+
return (await findGitRoot(process.cwd())) ?? process.cwd();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PathDoctorReport } from "./instruction-doctor.js";
|
|
2
|
+
export declare function doctorProjectSkill(explicitSkillPath: string | undefined, config: {
|
|
3
|
+
resolvePath: () => Promise<string>;
|
|
4
|
+
getAliasPath: () => Promise<string>;
|
|
5
|
+
missingIssue: string;
|
|
6
|
+
ownershipMarker: string;
|
|
7
|
+
advisory: string;
|
|
8
|
+
fixCommand: string;
|
|
9
|
+
pathFixCommand: (message: string) => string;
|
|
10
|
+
collectIssues: (text: string) => string[];
|
|
11
|
+
}): Promise<PathDoctorReport<"skillPath"> & {
|
|
12
|
+
hasTokenjuiceMarker: boolean;
|
|
13
|
+
hasUnsafePathIssue: boolean;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { pathEntryExists, readInstructionFile } from "./instruction-file.js";
|
|
2
|
+
import { buildInstructionDoctorReportFields, instructionDoctorStatusFromIssues } from "./instruction-doctor.js";
|
|
3
|
+
export async function doctorProjectSkill(explicitSkillPath, config) {
|
|
4
|
+
let resolvedSkillPath;
|
|
5
|
+
try {
|
|
6
|
+
resolvedSkillPath = await config.resolvePath();
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
const aliasPath = explicitSkillPath ?? (await config.getAliasPath());
|
|
10
|
+
if (!explicitSkillPath && !(await pathEntryExists(aliasPath))) {
|
|
11
|
+
return {
|
|
12
|
+
skillPath: aliasPath,
|
|
13
|
+
hasTokenjuiceMarker: false,
|
|
14
|
+
hasUnsafePathIssue: false,
|
|
15
|
+
...buildInstructionDoctorReportFields({
|
|
16
|
+
status: "disabled",
|
|
17
|
+
issues: [config.missingIssue],
|
|
18
|
+
advisory: config.advisory,
|
|
19
|
+
fixCommand: config.fixCommand,
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
skillPath: aliasPath,
|
|
25
|
+
hasTokenjuiceMarker: false,
|
|
26
|
+
hasUnsafePathIssue: true,
|
|
27
|
+
...buildInstructionDoctorReportFields({
|
|
28
|
+
status: "broken",
|
|
29
|
+
issues: [error.message],
|
|
30
|
+
advisory: config.advisory,
|
|
31
|
+
fixCommand: config.pathFixCommand(error.message),
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const existing = await readInstructionFile(resolvedSkillPath);
|
|
36
|
+
if (!existing.exists) {
|
|
37
|
+
return {
|
|
38
|
+
skillPath: resolvedSkillPath,
|
|
39
|
+
hasTokenjuiceMarker: false,
|
|
40
|
+
hasUnsafePathIssue: false,
|
|
41
|
+
...buildInstructionDoctorReportFields({
|
|
42
|
+
status: "disabled",
|
|
43
|
+
issues: [config.missingIssue],
|
|
44
|
+
advisory: config.advisory,
|
|
45
|
+
fixCommand: config.fixCommand,
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const hasTokenjuiceMarker = existing.text.includes(config.ownershipMarker);
|
|
50
|
+
const issues = config.collectIssues(existing.text);
|
|
51
|
+
return {
|
|
52
|
+
skillPath: resolvedSkillPath,
|
|
53
|
+
hasTokenjuiceMarker,
|
|
54
|
+
hasUnsafePathIssue: false,
|
|
55
|
+
...buildInstructionDoctorReportFields({
|
|
56
|
+
status: instructionDoctorStatusFromIssues(issues),
|
|
57
|
+
issues,
|
|
58
|
+
advisory: config.advisory,
|
|
59
|
+
fixCommand: config.fixCommand,
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RemoveInstructionFileResult, WriteInstructionFileResult } from "./instruction-file.js";
|
|
2
|
+
export declare function createRestorableRuleCommands(config: {
|
|
3
|
+
buildText: (options?: {
|
|
4
|
+
restoreBackupSuffix?: string | undefined;
|
|
5
|
+
}) => string;
|
|
6
|
+
isManagedText: (text: string) => boolean;
|
|
7
|
+
readRestoreBackupSuffix: (text: string) => string | undefined;
|
|
8
|
+
writeWithoutBackup: (filePath: string, options?: {
|
|
9
|
+
restoreBackupSuffix?: string | undefined;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
refusalMessage: (filePath: string) => string;
|
|
12
|
+
}): {
|
|
13
|
+
install: (filePath: string) => Promise<WriteInstructionFileResult>;
|
|
14
|
+
uninstall: (filePath: string) => Promise<RemoveInstructionFileResult>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { rename, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { readInstructionFile, removeInstructionFile } from "./instruction-file.js";
|
|
3
|
+
async function chooseBackupSuffix(filePath) {
|
|
4
|
+
const primaryBackup = await readInstructionFile(`${filePath}.bak`);
|
|
5
|
+
if (!primaryBackup.exists) {
|
|
6
|
+
return ".bak";
|
|
7
|
+
}
|
|
8
|
+
const secondaryBackup = await readInstructionFile(`${filePath}.tokenjuice.bak`);
|
|
9
|
+
if (!secondaryBackup.exists) {
|
|
10
|
+
return ".tokenjuice.bak";
|
|
11
|
+
}
|
|
12
|
+
for (let index = 1;; index += 1) {
|
|
13
|
+
const suffix = `.tokenjuice-${index}.bak`;
|
|
14
|
+
const candidate = await readInstructionFile(`${filePath}${suffix}`);
|
|
15
|
+
if (!candidate.exists) {
|
|
16
|
+
return suffix;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function createRestorableRuleCommands(config) {
|
|
21
|
+
async function install(filePath) {
|
|
22
|
+
const existing = await readInstructionFile(filePath);
|
|
23
|
+
if (existing.exists && config.isManagedText(existing.text)) {
|
|
24
|
+
const restoreBackupSuffix = config.readRestoreBackupSuffix(existing.text);
|
|
25
|
+
const expectedRule = config.buildText({ restoreBackupSuffix });
|
|
26
|
+
if (existing.text === expectedRule) {
|
|
27
|
+
return { filePath };
|
|
28
|
+
}
|
|
29
|
+
const backupPath = `${filePath}${await chooseBackupSuffix(filePath)}`;
|
|
30
|
+
await writeFile(backupPath, existing.text, "utf8");
|
|
31
|
+
await config.writeWithoutBackup(filePath, { restoreBackupSuffix });
|
|
32
|
+
return { filePath, backupPath };
|
|
33
|
+
}
|
|
34
|
+
if (existing.exists) {
|
|
35
|
+
const backupSuffix = await chooseBackupSuffix(filePath);
|
|
36
|
+
const backupPath = `${filePath}${backupSuffix}`;
|
|
37
|
+
await writeFile(backupPath, existing.text, "utf8");
|
|
38
|
+
await config.writeWithoutBackup(filePath, { restoreBackupSuffix: backupSuffix });
|
|
39
|
+
return { filePath, backupPath };
|
|
40
|
+
}
|
|
41
|
+
await config.writeWithoutBackup(filePath);
|
|
42
|
+
return { filePath };
|
|
43
|
+
}
|
|
44
|
+
async function uninstall(filePath) {
|
|
45
|
+
const existing = await readInstructionFile(filePath);
|
|
46
|
+
if (existing.exists && !config.isManagedText(existing.text)) {
|
|
47
|
+
throw new Error(config.refusalMessage(filePath));
|
|
48
|
+
}
|
|
49
|
+
const restoreBackupSuffix = config.readRestoreBackupSuffix(existing.text);
|
|
50
|
+
const backupPath = restoreBackupSuffix ? `${filePath}${restoreBackupSuffix}` : "";
|
|
51
|
+
const backup = restoreBackupSuffix ? await readInstructionFile(backupPath) : { exists: false, text: "" };
|
|
52
|
+
if (existing.exists
|
|
53
|
+
&& restoreBackupSuffix
|
|
54
|
+
&& backup.exists
|
|
55
|
+
&& !config.isManagedText(backup.text)) {
|
|
56
|
+
await rm(filePath, { force: true });
|
|
57
|
+
await rename(backupPath, filePath);
|
|
58
|
+
return { filePath, removed: true };
|
|
59
|
+
}
|
|
60
|
+
const result = await removeInstructionFile(filePath);
|
|
61
|
+
return { filePath: result.filePath, removed: result.removed };
|
|
62
|
+
}
|
|
63
|
+
return { install, uninstall };
|
|
64
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type RemoveInstructionFileResult, type WriteInstructionFileResult } from "./instruction-file.js";
|
|
2
|
+
type RestorableSkillConfig = {
|
|
3
|
+
buildSkill: (options?: {
|
|
4
|
+
restoreBackupSuffix?: string | undefined;
|
|
5
|
+
}) => string;
|
|
6
|
+
isManagedText: (text: string) => boolean;
|
|
7
|
+
readRestoreBackupSuffix: (text: string) => string | undefined;
|
|
8
|
+
rejectSkillSymlink: (path: string) => Promise<void>;
|
|
9
|
+
rejectInstallSidecarSymlinks: (path: string) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
export declare function createRestorableSkillCommands(config: RestorableSkillConfig): {
|
|
12
|
+
install(skillPath: string): Promise<WriteInstructionFileResult<"skillPath">>;
|
|
13
|
+
uninstall(skillPath: string): Promise<RemoveInstructionFileResult<"skillPath">>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { rename, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { findAvailableBackupPath, readInstructionFile, removeInstructionFile, writeInstructionFile, writeTextFileWithoutBackup, } from "./instruction-file.js";
|
|
3
|
+
export function createRestorableSkillCommands(config) {
|
|
4
|
+
return {
|
|
5
|
+
async install(skillPath) {
|
|
6
|
+
await config.rejectInstallSidecarSymlinks(skillPath);
|
|
7
|
+
const existing = await readInstructionFile(skillPath);
|
|
8
|
+
if (existing.exists && config.isManagedText(existing.text)) {
|
|
9
|
+
const nextSkill = config.buildSkill({ restoreBackupSuffix: config.readRestoreBackupSuffix(existing.text) });
|
|
10
|
+
if (existing.text === nextSkill) {
|
|
11
|
+
return { skillPath };
|
|
12
|
+
}
|
|
13
|
+
const result = await writeInstructionFile(skillPath, nextSkill);
|
|
14
|
+
return {
|
|
15
|
+
skillPath: result.filePath,
|
|
16
|
+
...(result.backupPath ? { backupPath: result.backupPath } : {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (existing.exists) {
|
|
20
|
+
const backupPath = await findAvailableBackupPath(skillPath);
|
|
21
|
+
await writeFile(backupPath, existing.text, { encoding: "utf8", flag: "wx" });
|
|
22
|
+
await writeTextFileWithoutBackup(skillPath, config.buildSkill({ restoreBackupSuffix: backupPath.slice(skillPath.length) }));
|
|
23
|
+
return { skillPath, backupPath };
|
|
24
|
+
}
|
|
25
|
+
await writeTextFileWithoutBackup(skillPath, config.buildSkill());
|
|
26
|
+
return { skillPath };
|
|
27
|
+
},
|
|
28
|
+
async uninstall(skillPath) {
|
|
29
|
+
const existing = await readInstructionFile(skillPath);
|
|
30
|
+
if (!existing.exists || !config.isManagedText(existing.text)) {
|
|
31
|
+
return { skillPath, removed: false };
|
|
32
|
+
}
|
|
33
|
+
const restoreBackupSuffix = config.readRestoreBackupSuffix(existing.text);
|
|
34
|
+
if (restoreBackupSuffix) {
|
|
35
|
+
const backupPath = `${skillPath}${restoreBackupSuffix}`;
|
|
36
|
+
await config.rejectSkillSymlink(backupPath);
|
|
37
|
+
const backup = await readInstructionFile(backupPath);
|
|
38
|
+
if (backup.exists && !config.isManagedText(backup.text)) {
|
|
39
|
+
await rm(skillPath, { force: true });
|
|
40
|
+
await rename(backupPath, skillPath);
|
|
41
|
+
return { skillPath, removed: true };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const result = await removeInstructionFile(skillPath);
|
|
45
|
+
return { skillPath: result.filePath, removed: result.removed };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -7,4 +7,8 @@ export type SettingsFile = {
|
|
|
7
7
|
metadata?: Stats;
|
|
8
8
|
};
|
|
9
9
|
export declare function readSettingsFile(path: string): Promise<SettingsFile>;
|
|
10
|
-
export declare function writeSettingsFile(original: SettingsFile, text: string, backup?: "replace" | "preserve"
|
|
10
|
+
export declare function writeSettingsFile(original: SettingsFile, text: string, backup?: "replace" | "preserve", options?: {
|
|
11
|
+
mode?: number;
|
|
12
|
+
}): Promise<string | undefined>;
|
|
13
|
+
export declare function writeSettingsBackup(file: SettingsFile, path: string, mode?: number): Promise<void>;
|
|
14
|
+
export declare function removeSettingsFile(file: SettingsFile): Promise<boolean>;
|
|
@@ -5,7 +5,7 @@ function changed(file) {
|
|
|
5
5
|
return new Error(`settings changed while updating ${file.path}; retry after other settings edits finish`);
|
|
6
6
|
}
|
|
7
7
|
async function readTarget(targetPath) {
|
|
8
|
-
const handle = await open(targetPath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
8
|
+
const handle = await open(targetPath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
9
9
|
try {
|
|
10
10
|
const metadata = await handle.stat();
|
|
11
11
|
if (!metadata.isFile()) {
|
|
@@ -74,7 +74,7 @@ export async function readSettingsFile(path) {
|
|
|
74
74
|
await assertUnchanged(file);
|
|
75
75
|
return file;
|
|
76
76
|
}
|
|
77
|
-
async function stageFile(parent, data, metadata) {
|
|
77
|
+
async function stageFile(parent, data, metadata, mode) {
|
|
78
78
|
const directory = await mkdtemp(join(parent, ".tokenjuice-settings-"));
|
|
79
79
|
const path = join(directory, "write");
|
|
80
80
|
try {
|
|
@@ -86,7 +86,9 @@ async function stageFile(parent, data, metadata) {
|
|
|
86
86
|
if (staged.uid !== metadata.uid || staged.gid !== metadata.gid) {
|
|
87
87
|
await handle.chown(metadata.uid, metadata.gid);
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
}
|
|
90
|
+
if (mode !== undefined || metadata) {
|
|
91
|
+
await handle.chmod(mode ?? (metadata.mode & 0o7777));
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
finally {
|
|
@@ -99,14 +101,14 @@ async function stageFile(parent, data, metadata) {
|
|
|
99
101
|
throw error;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
|
-
export async function writeSettingsFile(original, text, backup) {
|
|
104
|
+
export async function writeSettingsFile(original, text, backup, options = {}) {
|
|
103
105
|
let file = original;
|
|
104
106
|
if (!file.metadata) {
|
|
105
107
|
await mkdir(dirname(file.logicalPath), { recursive: true, mode: 0o700 });
|
|
106
108
|
file = { ...file, targetPath: join(await realpath(dirname(file.logicalPath)), basename(file.logicalPath)) };
|
|
107
109
|
}
|
|
108
110
|
await assertUnchanged(file);
|
|
109
|
-
const staged = await stageFile(dirname(file.targetPath), Buffer.from(text), file.metadata);
|
|
111
|
+
const staged = await stageFile(dirname(file.targetPath), Buffer.from(text), file.metadata, options.mode);
|
|
110
112
|
let stagedBackup;
|
|
111
113
|
try {
|
|
112
114
|
let backupPath;
|
|
@@ -163,3 +165,29 @@ export async function writeSettingsFile(original, text, backup) {
|
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
167
|
}
|
|
168
|
+
export async function writeSettingsBackup(file, path, mode) {
|
|
169
|
+
if (!file.data) {
|
|
170
|
+
throw new Error(`cannot back up absent settings: ${file.path}`);
|
|
171
|
+
}
|
|
172
|
+
await assertUnchanged(file);
|
|
173
|
+
const parent = await realpath(dirname(path));
|
|
174
|
+
const staged = await stageFile(parent, file.data, file.metadata, mode);
|
|
175
|
+
try {
|
|
176
|
+
await assertUnchanged(file);
|
|
177
|
+
if (await realpath(dirname(path)) !== parent) {
|
|
178
|
+
throw changed(file);
|
|
179
|
+
}
|
|
180
|
+
await link(staged.path, join(parent, basename(path)));
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
await rm(staged.directory, { recursive: true, force: true });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
export async function removeSettingsFile(file) {
|
|
187
|
+
if (!file.metadata) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
await assertUnchanged(file);
|
|
191
|
+
await rm(file.targetPath);
|
|
192
|
+
return true;
|
|
193
|
+
}
|