@openclaw/tokenjuice 2026.11.10-beta.3 → 2026.12.1-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.
Files changed (46) hide show
  1. package/node_modules/tokenjuice/README.md +133 -6
  2. package/node_modules/tokenjuice/dist/cli/main.d.ts +1 -2
  3. package/node_modules/tokenjuice/dist/cli/main.js +3 -18
  4. package/node_modules/tokenjuice/dist/core/analysis.js +7 -10
  5. package/node_modules/tokenjuice/dist/core/artifacts.d.ts +1 -1
  6. package/node_modules/tokenjuice/dist/core/artifacts.js +4 -3
  7. package/node_modules/tokenjuice/dist/core/command-identity.js +7 -6
  8. package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +3 -2
  9. package/node_modules/tokenjuice/dist/core/compaction-metadata.js +2 -1
  10. package/node_modules/tokenjuice/dist/core/failure-summary.d.ts +7 -0
  11. package/node_modules/tokenjuice/dist/core/failure-summary.js +76 -0
  12. package/node_modules/tokenjuice/dist/core/inventory-safety.js +14 -6
  13. package/node_modules/tokenjuice/dist/core/reduce-utils.js +9 -7
  14. package/node_modules/tokenjuice/dist/core/reduce.js +32 -21
  15. package/node_modules/tokenjuice/dist/core/streamed-text-counter.d.ts +8 -0
  16. package/node_modules/tokenjuice/dist/core/streamed-text-counter.js +56 -0
  17. package/node_modules/tokenjuice/dist/core/text.d.ts +1 -0
  18. package/node_modules/tokenjuice/dist/core/text.js +22 -11
  19. package/node_modules/tokenjuice/dist/core/wrap-format.d.ts +3 -0
  20. package/node_modules/tokenjuice/dist/core/wrap-format.js +34 -0
  21. package/node_modules/tokenjuice/dist/core/wrap.js +55 -6
  22. package/node_modules/tokenjuice/dist/hosts/codex/index.js +37 -10
  23. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/index.js +221 -79
  24. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/package.json +1 -1
  25. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/plugin.yaml +1 -1
  26. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/README.md +4 -2
  27. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/bridge.py +62 -5
  28. package/node_modules/tokenjuice/dist/hosts/openclaw/extension.js +7 -2
  29. package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +221 -79
  30. package/node_modules/tokenjuice/dist/hosts/opencode/v2/bundle/index.js +221 -79
  31. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +221 -79
  32. package/node_modules/tokenjuice/dist/python/README.md +1 -1
  33. package/node_modules/tokenjuice/dist/python/pyproject.toml +1 -1
  34. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/README.md +4 -2
  35. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/bridge.py +62 -5
  36. package/node_modules/tokenjuice/dist/rules/build/tsc.json +8 -3
  37. package/node_modules/tokenjuice/dist/rules/fixtures/build/tsc.fixture.json +6 -2
  38. package/node_modules/tokenjuice/dist/rules/install/bun-install.json +12 -4
  39. package/node_modules/tokenjuice/dist/rules/install/npm-ci.json +12 -4
  40. package/node_modules/tokenjuice/dist/rules/install/npm-install.json +12 -4
  41. package/node_modules/tokenjuice/dist/rules/install/pnpm-install.json +12 -4
  42. package/node_modules/tokenjuice/dist/rules/install/yarn-install.json +12 -4
  43. package/node_modules/tokenjuice/dist/rules/tests/pytest.json +8 -3
  44. package/node_modules/tokenjuice/dist/types.d.ts +3 -0
  45. package/node_modules/tokenjuice/package.json +5 -15
  46. package/package.json +5 -5
@@ -36,11 +36,138 @@ See [distribution](docs/distribution.md) for release artifacts and Linux package
36
36
 
37
37
  ## host integrations
38
38
 
39
- Choose an integration from the [client catalog](docs/integrations.md).
40
-
41
- Building an agent? Use the native [Hermes, Copilot SDK, LangChain, Mastra, and FastMCP adapters](docs/framework-integrations.md).
42
- Check its guide before installing: automatic replacement, command wrapping, and skill guidance have different contracts.
43
- The [support matrix](docs/adapter-support-matrix.md) records native test versions and remaining acceptance work.
39
+ The catalog below covers CLI and editor harnesses, desktop clients, instruction formats, and framework adapters.
40
+ Each name links to its setup guide. **Pre-tool wrapping** rewrites commands before execution; **result replacement** compacts captured output; **guidance** asks the agent to call `tokenjuice wrap` and is not automatic.
41
+ Manual imports, retired hooks, and experimental routes are marked separately.
42
+
43
+ Support varies by host and version. The [support matrix](docs/adapter-support-matrix.md) records native acceptance and remaining gaps; the [verification inventory](docs/verification-inventory.md) covers every installer target and alias.
44
+ A passing doctor check confirms managed configuration, not host loading or model-visible output.
45
+
46
+ ### harness and framework catalog
47
+
48
+ | Logo | Harness / client / framework | Integration | Setup | Configuration / limits |
49
+ | --- | --- | --- | --- | --- |
50
+ | <img width="48" height="48" src="docs/logos/adal.png" alt="AdaL CLI" /> | [AdaL CLI](docs/adal-integration.md) | Guidance | `tokenjuice install adal` | `AGENTS.md` |
51
+ | <img width="48" height="48" src="docs/logos/aether.png" alt="Aether" /> | [Aether](docs/aether-integration.md) | Guidance | `tokenjuice install aether` | `.aether/tokenjuice.md` / `.aether/settings.json` |
52
+ | <img width="48" height="48" src="docs/logos/agent-layer.png" alt="Agent Layer" /> | [Agent Layer](docs/agent-layer-integration.md) | Guidance | `tokenjuice install agent-layer` | `.agent-layer/instructions/tokenjuice.md`; run `al sync` after install or uninstall |
53
+ | — | [AgentInit](docs/agentinit-integration.md) | Guidance | `tokenjuice install agentinit` | `AGENTS.md`; run `agentinit sync` after install or uninstall |
54
+ | <img width="48" height="48" src="docs/logos/agentlink.png" alt="Agentlink" /> | [Agentlink](docs/agentlink-integration.md) | Guidance | `tokenjuice install agentlink` | `AGENTS.md`; run `agentlink sync` after install or uninstall |
55
+ | <img width="48" height="48" src="docs/logos/agentloom.png" alt="Agentloom" /> | [Agentloom](docs/agentloom-integration.md) | Guidance | `tokenjuice install agentloom` | `.agents/rules/tokenjuice-agentloom.md`; run `agentloom sync` after install or uninstall |
56
+ | <img width="48" height="48" src="docs/logos/agents-cli.png" alt="agents-cli" /> | [agents-cli](docs/agents-cli-integration.md) | Guidance | `tokenjuice install agents-cli` | `~/.agents/memory/AGENTS.md`; run `agents sync` after install or uninstall |
57
+ | <img width="48" height="48" src="docs/logos/agentsge.png" alt="agents.ge" /> | [agents.ge](docs/agentsge-integration.md) | Guidance | `tokenjuice install agentsge` | `.agents/rules/tokenjuice-agentsge.md` |
58
+ | <img width="48" height="48" src="docs/logos/agents-md.png" alt="AGENTS.md" /> | [AGENTS.md](docs/agents-md-integration.md) | Guidance | `tokenjuice install agents-md` | `AGENTS.md` |
59
+ | <img width="48" height="48" src="docs/logos/agentsmesh.png" alt="AgentsMesh" /> | [AgentsMesh](docs/agentsmesh-integration.md) | Guidance | `tokenjuice install agentsmesh` | `.agentsmesh/rules/tokenjuice.md`; run `agentsmesh generate` after install or uninstall |
60
+ | — | [AI Memory Protocol](docs/ai-memory-protocol-integration.md) | Guidance | `tokenjuice install ai-memory-protocol` | `.memories/memory/preferences.rst` |
61
+ | <img width="48" height="48" src="docs/logos/aictl.png" alt="aictl" /> | [aictl](docs/aictl-integration.md) | Guidance | `tokenjuice install aictl` | `AICTL.md` |
62
+ | <img width="48" height="48" src="docs/logos/aider.png" alt="Aider" /> | [Aider](docs/aider-integration.md) | Guidance | `tokenjuice install aider` | `CONVENTIONS.tokenjuice.md` |
63
+ | <img width="48" height="48" src="docs/logos/amazon-q.png" alt="Amazon Q Developer CLI / Kiro compatibility" /> | [Amazon Q Developer CLI / Kiro compatibility](docs/amazon-q-integration.md) | Guidance | `tokenjuice install amazon-q` | `.amazonq/rules/tokenjuice.md` |
64
+ | <img width="48" height="48" src="docs/logos/amp.png" alt="Amp" /> | [Amp](docs/amp-integration.md) | Guidance | `tokenjuice install amp` | `AGENTS.md` / `AGENT.md` / `CLAUDE.md` |
65
+ | <img width="48" height="48" src="docs/logos/ante.png" alt="Antigma Ante" /> | [Antigma Ante](docs/ante-integration.md) | Guidance | `tokenjuice install ante` | project `AGENTS.md` or `CLAUDE.md` |
66
+ | <img width="48" height="48" src="docs/logos/anywhere-agents.png" alt="anywhere-agents" /> | [anywhere-agents](docs/anywhere-agents-integration.md) | Guidance | `tokenjuice install anywhere-agents` | `AGENTS.local.md`; run `anywhere-agents` after install or uninstall |
67
+ | <img width="48" height="48" src="docs/logos/augment.png" alt="Augment" /> | [Augment](docs/augment-integration.md) | Guidance | `tokenjuice install augment` | `.augment/rules/tokenjuice.md` |
68
+ | <img width="48" height="48" src="docs/logos/autoclaw.png" alt="AutoClaw" /> | [AutoClaw](docs/autoclaw-integration.md) | Manual skill setup | Create a custom skill using the [workflow](packaging/skills/autoclaw/tokenjuice-instructions.md) | Select the skill in a fresh conversation; execution unqualified |
69
+ | <img width="48" height="48" src="docs/logos/avante.png" alt="Avante.nvim" /> | [Avante.nvim](docs/avante-integration.md) | Guidance | `tokenjuice install avante` | `avante.md` |
70
+ | <img width="48" height="48" src="docs/logos/baz.png" alt="Baz" /> | [Baz](docs/baz-integration.md) | Guidance | `tokenjuice install baz` | `.baz/skills/tokenjuice/SKILL.md` |
71
+ | <img width="48" height="48" src="docs/logos/bito.png" alt="Bito" /> | [Bito](docs/bito-integration.md) | Guidance | `tokenjuice install bito` | `.bito.yaml` / `.bito/tokenjuice.md` |
72
+ | <img width="48" height="48" src="docs/logos/blackbox.png" alt="Blackbox CLI" /> | [Blackbox CLI](docs/blackbox-integration.md) | Guidance | `tokenjuice install blackbox` | `.blackbox/skills/tokenjuice/SKILL.md` |
73
+ | <img width="48" height="48" src="docs/logos/blocks.png" alt="Blocks" /> | [Blocks](docs/blocks-integration.md) | Guidance | `tokenjuice install blocks` | `.agents/skills/tokenjuice-blocks/SKILL.md` |
74
+ | <img width="48" height="48" src="docs/logos/builder.png" alt="Builder" /> | [Builder](docs/builder-integration.md) | Guidance | `tokenjuice install builder` | `.builder/rules/tokenjuice.mdc` |
75
+ | <img width="48" height="48" src="docs/logos/charlie.png" alt="Charlie" /> | [Charlie](docs/charlie-integration.md) | Guidance | `tokenjuice install charlie` | `AGENTS.md` |
76
+ | <img width="48" height="48" src="docs/logos/claude-code.png" alt="Claude Code" /> | [Claude Code](docs/spec.md#install-doctor-and-uninstall) | Pre-tool wrapping | `tokenjuice install claude-code` | `~/.claude/settings.json` |
77
+ | <img width="48" height="48" src="docs/logos/clawdbot.png" alt="Clawdbot" /> | [Clawdbot](docs/clawdbot-integration.md) | Guidance | `tokenjuice install clawdbot` | `skills/tokenjuice/SKILL.md` |
78
+ | <img width="48" height="48" src="docs/logos/cline.png" alt="Cline" /> | [Cline](docs/cline-integration.md) | Pre-tool wrapping | `tokenjuice install cline` | `~/.cline/hooks/PreToolUse`; native CLI 3.0.74 input wrapping |
79
+ | <img width="48" height="48" src="docs/logos/codeant.png" alt="CodeAnt" /> | [CodeAnt](docs/codeant-integration.md) | Guidance | `tokenjuice install codeant` | `.codeant/instructions.json` |
80
+ | <img width="48" height="48" src="docs/logos/codebuddy.png" alt="CodeBuddy" /> | [CodeBuddy](docs/codebuddy-integration.md) | Pre-tool wrapping | `tokenjuice install codebuddy` | `~/.codebuddy/settings.json` |
81
+ | <img width="48" height="48" src="docs/logos/codebuff.png" alt="Codebuff" /> | [Codebuff](docs/codebuff-integration.md) | Guidance | `tokenjuice install codebuff` | `AGENTS.md` |
82
+ | <img width="48" height="48" src="docs/logos/codegen.png" alt="Codegen" /> | [Codegen](docs/codegen-integration.md) | Guidance | `tokenjuice install codegen` | `AGENTS.md` |
83
+ | <img width="48" height="48" src="docs/logos/coder-agents.png" alt="Coder Agents" /> | [Coder Agents](docs/coder-agents-integration.md) | Guidance | `tokenjuice install coder-agents` | `.agents/skills/tokenjuice/SKILL.md` |
84
+ | <img width="48" height="48" src="docs/logos/coderabbit.png" alt="CodeRabbit" /> | [CodeRabbit](docs/coderabbit-integration.md) | Guidance | `tokenjuice install coderabbit` | `.coderabbit.yaml` |
85
+ | <img width="48" height="48" src="docs/logos/codex-cli.png" alt="Codex CLI" /> | [Codex CLI](docs/codex-integration.md) | Explicit wrapping | `tokenjuice wrap -- <command>` | Native 0.166.0 hooks lack exit status; automatic compaction stays off |
86
+ | <img width="48" height="48" src="docs/logos/command-code.png" alt="Command Code" /> | [Command Code](docs/command-code-integration.md) | Explicit wrapping | `tokenjuice wrap -- <command>` | Additive hook retired; scoped legacy cleanup remains available |
87
+ | — | [Community Grok CLI](docs/grok-cli-integration.md) | Explicit wrapping | `tokenjuice wrap -- <command>` | [Automatic hook retired](docs/grok-cli-integration.md) |
88
+ | <img width="48" height="48" src="docs/logos/continue.png" alt="Continue" /> | [Continue](docs/continue-integration.md) | Guidance | `tokenjuice install continue` | `.continue/rules/tokenjuice.md` |
89
+ | <img width="48" height="48" src="docs/logos/crush.png" alt="Crush" /> | [Crush](docs/crush-integration.md) | Guidance | `tokenjuice install crush` | `.crush/skills/tokenjuice/SKILL.md` |
90
+ | <img width="48" height="48" src="docs/logos/cursor.png" alt="Cursor" /> | [Cursor](docs/cursor-integration.md) | Pre-tool wrapping | `tokenjuice install cursor` | `~/.cursor/hooks.json` |
91
+ | <img width="48" height="48" src="docs/logos/deepagents.png" alt="Deep Agents Code" /> | [Deep Agents Code](docs/deepagents-integration.md) | Guidance | `tokenjuice install deepagents` | `.deepagents/AGENTS.md` |
92
+ | <img width="48" height="48" src="docs/logos/deepseek-harness.png" alt="DeepSeek Harness" /> | [DeepSeek Harness](docs/deepseek-harness-integration.md) | Native plugin | `dsh plugin --profile PROFILE add <bundle>` | Use the packaged `dist/hosts/deepseek-harness/bundle`; PTC requires explicit wrapping |
93
+ | <img width="48" height="48" src="docs/logos/devin.png" alt="Devin for Terminal" /> | [Devin for Terminal](docs/devin-integration.md) | Pre-tool wrapping | `tokenjuice install devin` | `.devin/hooks.v1.json` |
94
+ | <img width="48" height="48" src="docs/logos/docker-agent.png" alt="Docker Agent" /> | [Docker Agent](docs/docker-agent-integration.md) | Guidance | `tokenjuice install docker-agent` | `.docker-agent/tokenjuice.md` |
95
+ | <img width="48" height="48" src="docs/logos/dot-agents.png" alt="dot-agents" /> | [dot-agents](docs/dot-agents-integration.md) | Guidance | `tokenjuice install dot-agents` | `~/.agents/rules/global/rules.mdc`; run `dot-agents sync` after install or uninstall |
96
+ | <img width="48" height="48" src="docs/logos/doubao-work.png" alt="Doubao Work" /> | [Doubao Work](docs/doubao-work-integration.md) | Manual skill import | Import the packaged [Doubao Work skill](packaging/skills/doubao-work/tokenjuice/SKILL.md) | Personal file/folder import; native execution unqualified |
97
+ | <img width="48" height="48" src="docs/logos/droid.png" alt="Droid (Factory CLI)" /> | [Droid (Factory CLI)](docs/droid-integration.md) | Pre-tool wrapping | `tokenjuice install droid` | `~/.factory/hooks.json` or legacy settings |
98
+ | <img width="48" height="48" src="docs/logos/eca.png" alt="ECA" /> | [ECA](docs/eca-integration.md) | Guidance | `tokenjuice install eca` | `.eca/skills/tokenjuice/SKILL.md` |
99
+ | <img width="48" height="48" src="docs/logos/elyra.png" alt="Elyra" /> | [Elyra](docs/elyra-integration.md) | Guidance | `tokenjuice install elyra` | `.elyra/skills/tokenjuice/SKILL.md` |
100
+ | <img width="48" height="48" src="docs/logos/fastmcp.png" alt="FastMCP" /> | [FastMCP](docs/framework-integrations.md#fastmcp) | Python middleware | `pip install 'tokenjuice-integrations[fastmcp]'` | Add `TokenjuiceMiddleware` to the server or proxy; routed MCP traffic only |
101
+ | <img width="48" height="48" src="docs/logos/firebase-studio.png" alt="Firebase Studio" /> | [Firebase Studio](docs/firebase-studio-integration.md) | Guidance | `tokenjuice install firebase-studio` | `.idx/airules.md` |
102
+ | <img width="48" height="48" src="docs/logos/forgecode.png" alt="ForgeCode" /> | [ForgeCode](docs/forgecode-integration.md) | Guidance | `tokenjuice install forgecode` | `AGENTS.md` |
103
+ | <img width="48" height="48" src="docs/logos/gemini-cli.png" alt="Gemini CLI" /> | [Gemini CLI](docs/gemini-cli-integration.md) | Pre-tool wrapping | `tokenjuice install gemini-cli` | `~/.gemini/settings.json`; `BeforeTool` command wrapping |
104
+ | <img width="48" height="48" src="docs/logos/copilot-cli.png" alt="GitHub Copilot CLI" /> | [GitHub Copilot CLI](docs/copilot-cli-integration.md) | Result replacement | `tokenjuice install copilot-cli` | native Bash replacement; [1.0.105 acceptance](docs/copilot-cli-integration.md) |
105
+ | <img width="48" height="48" src="docs/logos/copilot-cli.png" alt="GitHub Copilot coding agent" /> | [GitHub Copilot coding agent](docs/copilot-agent-integration.md) | Result replacement | `tokenjuice install copilot-agent` | `.github/hooks/tokenjuice-agent.json` |
106
+ | <img width="48" height="48" src="docs/logos/copilot-cli.png" alt="GitHub Copilot SDK" /> | [GitHub Copilot SDK](docs/framework-integrations.md#github-copilot-sdk) | SDK result hook | `createCopilotSdkHooks()` from `tokenjuice/copilot-sdk` | Compose with application `onPostToolUse` hooks; successful Bash results only |
107
+ | <img width="48" height="48" src="docs/logos/gitlab-duo.png" alt="GitLab Duo Agent Platform" /> | [GitLab Duo Agent Platform](docs/gitlab-duo-integration.md) | Guidance | `tokenjuice install gitlab-duo` | `.gitlab/duo/chat-rules.md` |
108
+ | <img width="48" height="48" src="docs/logos/antigravity.png" alt="Google Antigravity" /> | [Google Antigravity](docs/antigravity-integration.md) | Guidance | `tokenjuice install antigravity` | `.agents/rules/tokenjuice.md` |
109
+ | <img width="48" height="48" src="docs/logos/goose.png" alt="Goose" /> | [Goose](docs/goose-integration.md) | Guidance | `tokenjuice install goose` | `.goosehints` |
110
+ | <img width="48" height="48" src="docs/logos/gptme.png" alt="gptme" /> | [gptme](docs/gptme-integration.md) | Guidance | `tokenjuice install gptme` | `AGENTS.md` |
111
+ | <img width="48" height="48" src="docs/logos/greptile.png" alt="Greptile" /> | [Greptile](docs/greptile-integration.md) | Guidance | `tokenjuice install greptile` | `.greptile/rules.md` |
112
+ | <img width="48" height="48" src="docs/logos/grok-bot.png" alt="Grok Bot" /> | [Grok Bot](docs/grok-bot-integration.md) | Experimental guidance | `tokenjuice install grok-bot` | experimental local rule; [cloud skill workflow](docs/grok-bot-integration.md) |
113
+ | <img width="48" height="48" src="docs/logos/grok-bot.png" alt="Grok Build" /> | [Grok Build](docs/grok-build-integration.md) | Guidance | `tokenjuice install grok-build` | `AGENTS.md` |
114
+ | <img width="48" height="48" src="docs/logos/hermes.png" alt="Hermes" /> | [Hermes](docs/framework-integrations.md#hermes) | Native plugin | Copy the packaged bundle, then `hermes plugins enable tokenjuice` | Native user-plugin directory; `transform_terminal_output` |
115
+ | <img width="48" height="48" src="docs/logos/bob.png" alt="IBM Bob Shell" /> | [IBM Bob Shell](docs/bob-integration.md) | Guidance | `tokenjuice install bob` | `AGENTS.md` |
116
+ | <img width="48" height="48" src="docs/logos/jean2.png" alt="Jean2" /> | [Jean2](docs/jean2-integration.md) | Guidance | `tokenjuice install jean2` | `AGENTS.md` |
117
+ | <img width="48" height="48" src="docs/logos/jetbrains-ai.png" alt="JetBrains AI Assistant" /> | [JetBrains AI Assistant](docs/jetbrains-ai-integration.md) | Guidance | `tokenjuice install jetbrains-ai` | `.aiassistant/rules/tokenjuice.md` |
118
+ | <img width="48" height="48" src="docs/logos/jules.png" alt="Jules" /> | [Jules](docs/jules-integration.md) | Guidance | `tokenjuice install jules` | `AGENTS.md` |
119
+ | <img width="48" height="48" src="docs/logos/junie.png" alt="Junie" /> | [Junie](docs/junie-integration.md) | Guidance | `tokenjuice install junie` | `.junie/AGENTS.md` |
120
+ | <img width="48" height="48" src="docs/logos/kilo.png" alt="Kilo Code" /> | [Kilo Code](docs/kilo-integration.md) | Guidance | `tokenjuice install kilo` | `kilo.jsonc` or `.kilo/kilo.jsonc` + `.kilo/rules/tokenjuice.md` |
121
+ | <img width="48" height="48" src="docs/logos/kimi-code-cli.png" alt="Kimi Code CLI" /> | [Kimi Code CLI](docs/kimi-integration.md) | Explicit wrapping | `tokenjuice wrap -- <command>` | [Automatic hook retired](docs/kimi-integration.md) |
122
+ | <img width="48" height="48" src="docs/logos/kiro.png" alt="Kiro" /> | [Kiro](docs/kiro-integration.md) | Guidance | `tokenjuice install kiro` | `.kiro/steering/tokenjuice.md` |
123
+ | <img width="48" height="48" src="docs/logos/knowns.png" alt="Knowns" /> | [Knowns](docs/knowns-integration.md) | Guidance | `tokenjuice install knowns` | `KNOWNS.md` |
124
+ | <img width="48" height="48" src="docs/logos/deepagents.png" alt="LangChain" /> | [LangChain](docs/framework-integrations.md#langchain) | Python middleware | `pip install 'tokenjuice-integrations[langchain]'` | Add `TokenjuiceMiddleware` with an explicit shell-result decoder |
125
+ | — | [LeanCTL](docs/leanctl-integration.md) | Guidance | `tokenjuice install leanctl` | `.leanctl/instructions.md` |
126
+ | <img width="48" height="48" src="docs/logos/localcode.png" alt="LocalCode" /> | [LocalCode](docs/localcode-integration.md) | On-demand tool (beta) | `tokenjuice install localcode` | `~/.localcode/plugins/tokenjuice/` |
127
+ | <img width="48" height="48" src="docs/logos/mastra.png" alt="Mastra" /> | [Mastra](docs/framework-integrations.md#mastra) | Output processor | `createMastraProcessor()` from `tokenjuice/mastra` | Add to `outputProcessors` with application decoder/replacement callbacks |
128
+ | <img width="48" height="48" src="docs/logos/mcp-agent.png" alt="mcp-agent" /> | [mcp-agent](docs/mcp-agent-integration.md) | Guidance | `tokenjuice install mcp-agent` | `.mcp-agent/agents/tokenjuice.md` |
129
+ | <img width="48" height="48" src="docs/logos/mini-swe-agent.png" alt="mini-SWE-agent" /> | [mini-SWE-agent](docs/mini-swe-agent-integration.md) | Guidance | `tokenjuice install mini-swe-agent` | `.mini-swe-agent/tokenjuice.yaml` |
130
+ | <img width="48" height="48" src="docs/logos/mistral-vibe.png" alt="Mistral Vibe" /> | [Mistral Vibe](docs/mistral-vibe-integration.md) | Guidance | `tokenjuice install mistral-vibe` | `AGENTS.md` |
131
+ | <img width="48" height="48" src="docs/logos/mux-xum.png" alt="Mux / Xum" /> | [Mux / Xum](docs/mux-integration.md) | Explicit wrapping | `tokenjuice wrap -- <command>` | [Automatic hook retired](docs/mux-integration.md) |
132
+ | — | [NovaKit CLI](docs/novakit-integration.md) | Guidance | `tokenjuice install novakit` | `NOVAKIT.md` |
133
+ | <img width="48" height="48" src="docs/logos/ona.png" alt="Ona Agent" /> | [Ona Agent](docs/ona-integration.md) | Guidance | `tokenjuice install ona` | `.ona/skills/tokenjuice/SKILL.md` |
134
+ | <img width="48" height="48" src="docs/logos/open-interpreter.png" alt="Open Interpreter" /> | [Open Interpreter](docs/open-interpreter-integration.md) | Guidance | `tokenjuice install open-interpreter` | `AGENTS.md` |
135
+ | <img width="48" height="48" src="docs/logos/openwebui.png" alt="Open WebUI" /> | [Open WebUI](docs/openwebui-integration.md) | Manual tool import (beta) | `tokenjuice install openwebui` | `.openwebui/tools/tokenjuice_compact.py`; then import in Workspace Tools |
136
+ | <img width="48" height="48" src="docs/logos/clawdbot.png" alt="OpenClaw" /> | [OpenClaw](https://docs.openclaw.ai/tools/tokenjuice) | External plugin | `openclaw plugins install @openclaw/tokenjuice` | `~/.openclaw/openclaw.json`; enable plugin and restart Gateway (see below) |
137
+ | <img width="48" height="48" src="docs/logos/opencode.png" alt="OpenCode V1" /> | [OpenCode V1](docs/spec.md#install-doctor-and-uninstall) | Result replacement | `tokenjuice install opencode` | `~/.config/opencode/plugins/tokenjuice.js` |
138
+ | <img width="48" height="48" src="docs/logos/opencode.png" alt="OpenCode V2" /> | [OpenCode V2](docs/opencode-v2-integration.md) | Result replacement | `tokenjuice install opencode-v2` | foreground `shell` result replacement; native v2.0.18 acceptance |
139
+ | <img width="48" height="48" src="docs/logos/openhands.png" alt="OpenHands" /> | [OpenHands](docs/openhands-integration.md) | Explicit wrapping | `tokenjuice wrap -- <command>` | Manual wrapping; [legacy hook cleanup](docs/openhands-integration.md) |
140
+ | <img width="48" height="48" src="docs/logos/pi.png" alt="pi" /> | [pi](docs/spec.md#install-doctor-and-uninstall) | Result replacement | `tokenjuice install pi` | `~/.pi/agent/extensions/tokenjuice.js` |
141
+ | — | [pi-go](docs/pi-go-integration.md) | Guidance | `tokenjuice install pi-go` | `.pi/skills/tokenjuice/SKILL.md` |
142
+ | <img width="48" height="48" src="docs/logos/plandex.png" alt="Plandex" /> | [Plandex](docs/plandex-integration.md) | Guidance | `tokenjuice install plandex` | `PLANDEX.tokenjuice.md` |
143
+ | <img width="48" height="48" src="docs/logos/qclaw.png" alt="QClaw" /> | [QClaw](docs/qclaw-migration.md) | Migration only | Follow the WorkBuddy migration guide | No QClaw hook installer; qualify WorkBuddy separately |
144
+ | <img width="48" height="48" src="docs/logos/qoder.png" alt="Qoder (guidance)" /> | [Qoder (guidance)](docs/qoder-integration.md) | Guidance | `tokenjuice install qoder` | `AGENTS.md`; use `qoder-cli` for the replacement hook |
145
+ | <img width="48" height="48" src="docs/logos/qoder.png" alt="Qoder CLI" /> | [Qoder CLI](docs/qoder-integration.md) | Result replacement | `tokenjuice install qoder-cli` | Native `PostToolUse`; separate from Qoder guidance below |
146
+ | <img width="48" height="48" src="docs/logos/qoder.png" alt="QoderWork skills" /> | [QoderWork skills](docs/qoderwork-integration.md) | Guidance | `tokenjuice install qoderwork` | guidance skill at `~/.qoderwork/skills/tokenjuice/SKILL.md` |
147
+ | <img width="48" height="48" src="docs/logos/qodo.png" alt="Qodo Code Review" /> | [Qodo Code Review](docs/qodo-integration.md) | Guidance | `tokenjuice install qodo` | `.pr_agent.toml` |
148
+ | <img width="48" height="48" src="docs/logos/qwen-code.png" alt="Qwen Code" /> | [Qwen Code](docs/qwen-code-integration.md) | Pre-tool wrapping | `tokenjuice install qwen-code` | `.qwen/settings.json` |
149
+ | <img width="48" height="48" src="docs/logos/qwenwork.png" alt="QwenWork" /> | [QwenWork](docs/qwenwork-integration.md) | Guidance | `tokenjuice install qwenwork` | guidance skill at `~/.qwenwork/skills/tokenjuice/SKILL.md` |
150
+ | <img width="48" height="48" src="docs/logos/replit.png" alt="Replit Agent" /> | [Replit Agent](docs/replit-integration.md) | Guidance | `tokenjuice install replit` | `replit.md` |
151
+ | <img width="48" height="48" src="docs/logos/roo.png" alt="Roo Code" /> | [Roo Code](docs/roo-integration.md) | Guidance | `tokenjuice install roo` | `.roo/rules/tokenjuice.md` |
152
+ | <img width="48" height="48" src="docs/logos/rovo.png" alt="Rovo Dev CLI" /> | [Rovo Dev CLI](docs/rovo-integration.md) | Guidance | `tokenjuice install rovo` | `AGENTS.md` |
153
+ | — | [Ruler](docs/ruler-integration.md) | Guidance | `tokenjuice install ruler` | `.ruler/tokenjuice.md` |
154
+ | <img width="48" height="48" src="docs/logos/stagewise.png" alt="Stagewise" /> | [Stagewise](docs/stagewise-integration.md) | Guidance | `tokenjuice install stagewise` | `.stagewise/skills/tokenjuice/SKILL.md` |
155
+ | <img width="48" height="48" src="docs/logos/swe-agent.png" alt="SWE-agent" /> | [SWE-agent](docs/swe-agent-integration.md) | Guidance | `tokenjuice install swe-agent` | `.swe-agent/tokenjuice.yaml` |
156
+ | <img width="48" height="48" src="docs/logos/t3-code.png" alt="T3 Code" /> | [T3 Code](docs/t3-code-integration.md) | Provider integration | Configure the selected Codex, Claude Code or OpenCode provider | Install on the machine executing tools; no separate T3 installer |
157
+ | <img width="48" height="48" src="docs/logos/tabby.png" alt="Tabby" /> | [Tabby](docs/tabby-integration.md) | Guidance | `tokenjuice install tabby` | `~/.tabby/config.toml` |
158
+ | <img width="48" height="48" src="docs/logos/tabnine.png" alt="Tabnine CLI" /> | [Tabnine CLI](docs/tabnine-integration.md) | Guidance | `tokenjuice install tabnine` | `TABNINE.md` |
159
+ | <img width="48" height="48" src="docs/logos/trae.png" alt="Trae" /> | [Trae](docs/trae-integration.md) | Guidance | `tokenjuice install trae` | `.trae/rules/project_rules.md` |
160
+ | <img width="48" height="48" src="docs/logos/uipath.png" alt="UiPath for Coding Agents" /> | [UiPath for Coding Agents](docs/uipath-integration.md) | Guidance | `tokenjuice install uipath` | `AGENTS.md` |
161
+ | <img width="48" height="48" src="docs/logos/copilot-cli.png" alt="VS Code Copilot Chat (Local)" /> | [VS Code Copilot Chat (Local)](docs/vscode-copilot-integration.md) | Pre-tool wrapping | `tokenjuice install vscode-copilot` | `~/.copilot/hooks/tokenjuice-vscode.json` |
162
+ | <img width="48" height="48" src="docs/logos/warp.png" alt="Warp" /> | [Warp](docs/warp-integration.md) | Guidance | `tokenjuice install warp` | `AGENTS.md` / `WARP.md` |
163
+ | <img width="48" height="48" src="docs/logos/windsurf.png" alt="Windsurf" /> | [Windsurf](docs/windsurf-integration.md) | Guidance | `tokenjuice install windsurf` | `.windsurf/rules/tokenjuice.md` |
164
+ | <img width="48" height="48" src="docs/logos/workbuddy.png" alt="WorkBuddy" /> | [WorkBuddy](docs/workbuddy-integration.md) | Manual skill import | Import the packaged [WorkBuddy skill](packaging/skills/workbuddy/tokenjuice/SKILL.md) | Desktop import and execution unqualified; separate from CodeBuddy CLI |
165
+ | <img width="48" height="48" src="docs/logos/zed.png" alt="Zed" /> | [Zed](docs/zed-integration.md) | Guidance | `tokenjuice install zed` | `.rules` |
166
+ | <img width="48" height="48" src="docs/logos/zencoder.png" alt="Zencoder" /> | [Zencoder](docs/zencoder-integration.md) | Guidance | `tokenjuice install zencoder` | `.zencoder/rules/tokenjuice.md` |
167
+
168
+ Logos use locally stored, padded tiles for light and dark themes. A dash means no verified project mark is available; see [logo sources and standards](docs/logos/README.md).
169
+
170
+ ### installation notes
44
171
 
45
172
  For example, Claude Code uses pre-tool command wrapping:
46
173
 
@@ -110,7 +237,7 @@ Later layers override earlier rules by ID. See [rule authoring](docs/rules.md).
110
237
  ## docs
111
238
 
112
239
  - [documentation index](docs/README.md) — all integration guides and reference pages
113
- - [client catalog](docs/integrations.md) — setup routes and configuration locations
240
+ - [harness and framework catalog](#harness-and-framework-catalog) — setup routes and configuration locations
114
241
  - [support and verification](docs/adapter-support-matrix.md) — evidence and acceptance limits
115
242
  - [spec](docs/spec.md) — CLI, adapter protocol, compaction, and storage
116
243
  - [contributing](CONTRIBUTING.md) — development and validation
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { type StatsSourceReport } from "../core/analysis.js";
3
- import type { WrapResult } from "../types.js";
3
+ export { decorateWrapInlineText } from "../core/wrap-format.js";
4
4
  import type { ParsedArgs } from "./command-types.js";
5
5
  export declare function parseArgs(argv: string[]): ParsedArgs;
6
6
  export declare function resolveNoOmit(noOmitFlag: boolean, env?: NodeJS.ProcessEnv): boolean;
7
- export declare function decorateWrapInlineText(result: WrapResult["result"], raw: boolean): string;
8
7
  export declare function formatStatsSources(sources: StatsSourceReport[]): string;
9
8
  export declare function main(argv?: string[]): Promise<number>;
10
9
  export declare function isDirectModuleEntrypoint(moduleUrl: string | URL, argv?: string[]): Promise<boolean>;
@@ -11,11 +11,11 @@ import { buildAnalysisEntry, discoverCandidates, doctorArtifacts, statsArtifacts
11
11
  import { verifyBuiltinFixtures } from "../core/fixtures.js";
12
12
  import { readNoOmissionFromEnv } from "../core/env.js";
13
13
  import { parseReduceJsonRequest } from "../core/json-protocol.js";
14
- import { WRAP_AUTHORITATIVE_FOOTER } from "../core/compaction-metadata.js";
15
14
  import { reduceExecution } from "../core/reduce.js";
16
15
  import { verifyRules } from "../core/rules.js";
17
16
  import { UNKNOWN_ARTIFACT_SOURCE } from "../core/source.js";
18
17
  import { runWrappedCommand } from "../core/wrap.js";
18
+ export { decorateWrapInlineText } from "../core/wrap-format.js";
19
19
  import { runClaudeCodePostToolUseHook, runClaudeCodePreToolUseHook } from "../hosts/claude-code/index.js";
20
20
  import { runClinePreToolUseHook, runClinePostToolUseHook } from "../hosts/cline/index.js";
21
21
  import { runCodeBuddyPreToolUseHook } from "../hosts/codebuddy/index.js";
@@ -620,6 +620,7 @@ async function runReduceJson(args) {
620
620
  async function runWrap(args) {
621
621
  const noOmit = resolveNoOmit(args.noOmit);
622
622
  const wrapped = await runWrappedCommand(args.passthrough, {
623
+ includeCompactionNotice: args.format === "text",
623
624
  tee: args.tee,
624
625
  ...(args.keepFailures ? { keepFailures: true } : {}),
625
626
  ...(args.raw ? { raw: true } : {}),
@@ -640,28 +641,12 @@ async function runWrap(args) {
640
641
  }
641
642
  return wrapped.exitCode;
642
643
  }
643
- const inlineText = decorateWrapInlineText(wrapped.result, args.raw || failedPassthrough);
644
- // Passthrough output already has the command's exact line endings.
645
- const exactText = args.raw || (wrapped.stderr.length === 0 && inlineText === wrapped.stdout);
646
- emit(args.format, wrapped, inlineText, exactText);
644
+ emit(args.format, wrapped, wrapped.result.inlineText, true);
647
645
  return wrapped.exitCode;
648
646
  }
649
647
  export function resolveNoOmit(noOmitFlag, env = process.env) {
650
648
  return noOmitFlag || readNoOmissionFromEnv(env);
651
649
  }
652
- export function decorateWrapInlineText(result, raw) {
653
- const { rawChars, reducedChars } = result.stats;
654
- if (raw || !result.compaction?.authoritative || reducedChars === 0 || reducedChars >= rawChars) {
655
- return result.inlineText;
656
- }
657
- const footer = [
658
- "",
659
- "---",
660
- WRAP_AUTHORITATIVE_FOOTER,
661
- ...(result.rawRef?.id ? [`Raw output is available locally: tokenjuice cat ${result.rawRef.id}`] : []),
662
- ].join("\n");
663
- return `${result.inlineText}${footer}`;
664
- }
665
650
  async function runInstall(args) {
666
651
  const target = args.positionals[0];
667
652
  if (target !== undefined) {
@@ -5,18 +5,15 @@ const GENERIC_REDUCERS = new Set(["generic/fallback", undefined]);
5
5
  const WEAK_RATIO_THRESHOLD = 0.65;
6
6
  const MISSING_RAW_CHARS_THRESHOLD = 200;
7
7
  const WEAK_RAW_CHARS_THRESHOLD = 500;
8
- function clampRatio(value) {
9
- return Math.min(Math.max(value, 0), 1);
10
- }
11
8
  function effectiveReducedChars(metadata) {
12
9
  const reduced = metadata.reducedChars ?? metadata.rawChars;
13
- return Math.min(Math.max(reduced, 0), metadata.rawChars);
10
+ return Math.max(reduced, 0);
14
11
  }
15
12
  function effectiveRatio(metadata) {
16
13
  if (metadata.rawChars === 0) {
17
14
  return 1;
18
15
  }
19
- return clampRatio(effectiveReducedChars(metadata) / metadata.rawChars);
16
+ return effectiveReducedChars(metadata) / metadata.rawChars;
20
17
  }
21
18
  export function buildAnalysisEntry(input, result) {
22
19
  const captureTruncated = input.metadata?.tokenjuiceCaptureTruncated;
@@ -210,10 +207,10 @@ function buildStatsReport(entries, options, source) {
210
207
  commands.set(signature, addToStatsGroup(commands.get(signature), entry.metadata.rawChars, reduced, ratio));
211
208
  daily.set(day, addToStatsGroup(daily.get(day), entry.metadata.rawChars, reduced, ratio));
212
209
  }
213
- const totalSavedChars = Math.max(rawChars - reducedChars, 0);
210
+ const totalSavedChars = rawChars - reducedChars;
214
211
  const avgRatio = ratioCount > 0 ? ratioSum / ratioCount : null;
215
212
  const savingsPercent = rawChars > 0 ? totalSavedChars / rawChars : null;
216
- const observedSavedChars = Math.max(observedRawChars - observedReducedChars, 0);
213
+ const observedSavedChars = observedRawChars - observedReducedChars;
217
214
  const observedAvgRatio = observedRatioCount > 0 ? observedRatioSum / observedRatioCount : null;
218
215
  const observedSavingsPercent = observedRawChars > 0 ? observedSavedChars / observedRawChars : null;
219
216
  return {
@@ -239,7 +236,7 @@ function buildStatsReport(entries, options, source) {
239
236
  count: group.count,
240
237
  rawChars: group.rawChars,
241
238
  reducedChars: group.reducedChars,
242
- savedChars: Math.max(group.rawChars - group.reducedChars, 0),
239
+ savedChars: group.rawChars - group.reducedChars,
243
240
  avgRatio: avgRatioFromGroup(group),
244
241
  }))
245
242
  .sort((left, right) => right.savedChars - left.savedChars || right.count - left.count)
@@ -250,7 +247,7 @@ function buildStatsReport(entries, options, source) {
250
247
  count: group.count,
251
248
  rawChars: group.rawChars,
252
249
  reducedChars: group.reducedChars,
253
- savedChars: Math.max(group.rawChars - group.reducedChars, 0),
250
+ savedChars: group.rawChars - group.reducedChars,
254
251
  avgRatio: avgRatioFromGroup(group),
255
252
  }))
256
253
  .sort((left, right) => right.savedChars - left.savedChars || right.count - left.count)
@@ -261,7 +258,7 @@ function buildStatsReport(entries, options, source) {
261
258
  count: group.count,
262
259
  rawChars: group.rawChars,
263
260
  reducedChars: group.reducedChars,
264
- savedChars: Math.max(group.rawChars - group.reducedChars, 0),
261
+ savedChars: group.rawChars - group.reducedChars,
265
262
  }))
266
263
  .sort((left, right) => left.day.localeCompare(right.day)),
267
264
  };
@@ -5,7 +5,7 @@ export declare function resolveArtifactBaseDir(storeDir?: string): string;
5
5
  export declare function isValidArtifactId(id: string): boolean;
6
6
  export declare function getTelemetryCommandFamily(input: Pick<ToolExecutionInput, "argv" | "command">): string | undefined;
7
7
  export declare function shouldRecordStats(env?: NodeJS.ProcessEnv): boolean;
8
- export declare function storeArtifact(input: StoredArtifactInput, storeDir?: string): Promise<StoredArtifactRef>;
8
+ export declare function storeArtifact(input: StoredArtifactInput, storeDir?: string, statsForRef?: (ref: StoredArtifactRef) => StoredArtifactInput["stats"]): Promise<StoredArtifactRef>;
9
9
  export declare function storeArtifactMetadata(input: StoredArtifactInput, storeDir?: string): Promise<ArtifactMetadataRef>;
10
10
  export declare function tryStoreArtifactMetadata(input: StoredArtifactInput, storeDir?: string): Promise<ArtifactMetadataRef | undefined>;
11
11
  export declare function getArtifact(id: string, storeDir?: string): Promise<StoredArtifact | null>;
@@ -140,9 +140,10 @@ export function shouldRecordStats(env = process.env) {
140
140
  const value = env[STATS_ENABLED_ENV]?.trim().toLowerCase();
141
141
  return value !== "0" && value !== "false" && value !== "no" && value !== "off";
142
142
  }
143
- export async function storeArtifact(input, storeDir) {
143
+ export async function storeArtifact(input, storeDir, statsForRef) {
144
144
  const id = `tj_${randomUUID().slice(0, 12)}`;
145
145
  const ref = buildArtifactPaths(id, storeDir);
146
+ const stats = statsForRef ? statsForRef(ref) : input.stats;
146
147
  await mkdir(resolveArtifactBaseDir(storeDir), { recursive: true, mode: 0o700 });
147
148
  const captureTruncated = extractCaptureTruncatedFlag(input.input);
148
149
  const artifact = {
@@ -152,12 +153,12 @@ export async function storeArtifact(input, storeDir) {
152
153
  createdAt: new Date().toISOString(),
153
154
  source: resolveArtifactSource(input.input),
154
155
  classification: input.classification,
155
- rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
156
+ rawChars: stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
156
157
  ...(input.input.toolName ? { toolName: input.input.toolName } : {}),
157
158
  ...(input.input.command ? { command: input.input.command } : {}),
158
159
  ...(typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {}),
159
160
  ...(captureTruncated !== undefined ? { captureTruncated } : {}),
160
- ...(input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}),
161
+ ...(stats ? { reducedChars: stats.reducedChars, ratio: stats.ratio } : {}),
161
162
  },
162
163
  };
163
164
  await Promise.all([
@@ -189,8 +189,8 @@ function isRepositoryInspectionArgv(argv) {
189
189
  }
190
190
  return false;
191
191
  }
192
- function getMostDerivedCandidate(input) {
193
- return deriveCommandMatchCandidates(input).reduce((best, candidate) => (getSourcePriority(candidate.source) >= getSourcePriority(best.source) ? candidate : best));
192
+ function getMostDerivedCandidate(input, candidates = deriveCommandMatchCandidates(input)) {
193
+ return candidates.reduce((best, candidate) => (getSourcePriority(candidate.source) >= getSourcePriority(best.source) ? candidate : best));
194
194
  }
195
195
  function extractPipelineSourceCommand(command) {
196
196
  let current = "";
@@ -227,8 +227,8 @@ function extractPipelineSourceCommand(command) {
227
227
  }
228
228
  return current.trim();
229
229
  }
230
- function getInspectionArgv(input) {
231
- const candidate = getMostDerivedCandidate(input);
230
+ function getInspectionArgv(input, candidates = deriveCommandMatchCandidates(input)) {
231
+ const candidate = getMostDerivedCandidate(input, candidates);
232
232
  if (candidate.argv.length > 0) {
233
233
  return candidate.argv;
234
234
  }
@@ -239,8 +239,9 @@ function getInspectionArgv(input) {
239
239
  return sourceCommand ? tokenizeCommand(sourceCommand) : [];
240
240
  }
241
241
  export function isFileContentInspectionCommand(input) {
242
- return isFileContentInspectionArgv(getInspectionArgv(input))
243
- || deriveCommandMatchCandidates(input).some((candidate) => isGhApiContentsDecodeCommand(candidate.command));
242
+ const candidates = deriveCommandMatchCandidates(input);
243
+ return isFileContentInspectionArgv(getInspectionArgv(input, candidates))
244
+ || candidates.some((candidate) => isGhApiContentsDecodeCommand(candidate.command));
244
245
  }
245
246
  function isVerbatimRemoteInspectionCommand(command) {
246
247
  const effectiveCommand = unwrapShellRunner({ command }) ?? command;
@@ -1,10 +1,11 @@
1
- export type CompactionKind = "head-tail-omission" | "middle-truncation" | "tail-truncation" | "hashed-middle-clip" | "git-diff-hunk-clip" | "inspection-package-lock-summary" | "repeated-emoji-banner-omission" | "github-actions-command-list-omission" | "github-actions-log-signal-filter" | "github-status-check-rollup-omission" | "no-omit-head-tail-passthrough" | "no-omit-char-clip-passthrough" | "no-omit-domain-passthrough";
1
+ export type CompactionKind = "failure-signal-filter" | "head-tail-omission" | "middle-truncation" | "tail-truncation" | "hashed-middle-clip" | "git-diff-hunk-clip" | "inspection-package-lock-summary" | "repeated-emoji-banner-omission" | "github-actions-command-list-omission" | "github-actions-log-signal-filter" | "github-status-check-rollup-omission" | "no-omit-head-tail-passthrough" | "no-omit-char-clip-passthrough" | "no-omit-domain-passthrough" | "rule-line-filter" | "rule-output-replacement";
2
2
  export type CompactionMetadata = {
3
3
  authoritative: boolean;
4
4
  kinds: CompactionKind[];
5
5
  };
6
6
  export declare const NO_COMPACTION_METADATA: CompactionMetadata;
7
- export declare const WRAP_AUTHORITATIVE_FOOTER = "[tokenjuice] This is the complete, authoritative output for this command. It was deterministically compacted to remove low-signal noise. Do not re-run the command, vary flags, or switch tools to try to recover omitted content; use a raw-artifact recovery command below when one is provided. Proceed with the task using this output.";
7
+ export declare const WRAP_AUTHORITATIVE_FOOTER = "[tokenjuice] Compacted output; some content was omitted.";
8
+ export declare const WRAP_RECOVERY_HINT = "Use the stored-output command below to inspect the captured original.";
8
9
  export declare function createCompactionMetadata(...kinds: CompactionKind[]): CompactionMetadata;
9
10
  export declare function createPassthroughCompactionMetadata(...kinds: CompactionKind[]): CompactionMetadata;
10
11
  export declare function mergeCompactionMetadata(...values: Array<CompactionMetadata | undefined>): CompactionMetadata;
@@ -2,7 +2,8 @@ export const NO_COMPACTION_METADATA = {
2
2
  authoritative: false,
3
3
  kinds: [],
4
4
  };
5
- export const WRAP_AUTHORITATIVE_FOOTER = "[tokenjuice] This is the complete, authoritative output for this command. It was deterministically compacted to remove low-signal noise. Do not re-run the command, vary flags, or switch tools to try to recover omitted content; use a raw-artifact recovery command below when one is provided. Proceed with the task using this output.";
5
+ export const WRAP_AUTHORITATIVE_FOOTER = "[tokenjuice] Compacted output; some content was omitted.";
6
+ export const WRAP_RECOVERY_HINT = "Use the stored-output command below to inspect the captured original.";
6
7
  function buildCompactionMetadata(authoritative, ...kinds) {
7
8
  if (kinds.length === 0) {
8
9
  return NO_COMPACTION_METADATA;
@@ -0,0 +1,7 @@
1
+ import { type CompactionMetadata } from "./compaction-metadata.js";
2
+ import type { ToolExecutionInput } from "../types.js";
3
+ /** Prioritize diagnostic lines before spending the remaining budget on context. */
4
+ export declare function buildFailureSummary(input: ToolExecutionInput, rawText: string, maxChars: number, noOmit?: boolean): {
5
+ text: string;
6
+ compaction: CompactionMetadata;
7
+ } | null;
@@ -0,0 +1,76 @@
1
+ import { createCompactionMetadata, NO_COMPACTION_METADATA } from "./compaction-metadata.js";
2
+ import { clampTextWithMetadata, countTextChars, normalizeLines, stripAnsi } from "./text.js";
3
+ const FAILURE_LINE = /(?:^|\s)(?:fatal(?:\s+error)?|error|panic|exception|caused by|traceback)(?:[:\s]|$)|\b[A-Z][A-Za-z]*(?:Error|Exception):/iu;
4
+ /** Prioritize diagnostic lines before spending the remaining budget on context. */
5
+ export function buildFailureSummary(input, rawText, maxChars, noOmit = false) {
6
+ if (noOmit || typeof input.exitCode !== "number" || input.exitCode === 0)
7
+ return null;
8
+ const text = stripAnsi(rawText);
9
+ const lines = normalizeLines(text);
10
+ if (lines.length <= 32)
11
+ return null;
12
+ const signals = lines.flatMap((line, index) => FAILURE_LINE.test(line) ? [index] : []);
13
+ if (signals.length === 0)
14
+ return null;
15
+ const fullText = `[exit ${input.exitCode}]\n${text}`;
16
+ if (countTextChars(fullText) <= maxChars)
17
+ return { text: fullText, compaction: NO_COMPACTION_METADATA };
18
+ const header = `[exit ${input.exitCode}] selected failure details (original line numbers):\n`;
19
+ const footer = "\n[other output omitted]";
20
+ let remaining = maxChars - countTextChars(header + footer);
21
+ if (remaining < 32)
22
+ return null;
23
+ const diagnosticRows = signals.map((index) => {
24
+ const row = `${index + 1}: ${lines[index]}`;
25
+ const cost = countTextChars(row) + 1;
26
+ return { index, row, cost, minimum: Math.min(cost, 64) };
27
+ });
28
+ let candidates = diagnosticRows;
29
+ if (diagnosticRows.reduce((sum, row) => sum + row.minimum, 0) > remaining) {
30
+ // When even short excerpts cannot all fit, retain both ends of the failure.
31
+ candidates = [];
32
+ let reserved = 0;
33
+ for (let offset = 0; offset < diagnosticRows.length; offset++) {
34
+ const index = offset % 2 === 0 ? offset / 2 : diagnosticRows.length - 1 - Math.floor(offset / 2);
35
+ const row = diagnosticRows[index];
36
+ if (reserved + row.minimum <= remaining) {
37
+ candidates.push(row);
38
+ reserved += row.minimum;
39
+ }
40
+ }
41
+ candidates.sort((left, right) => left.index - right.index);
42
+ }
43
+ const selected = new Map();
44
+ let reserved = candidates.reduce((sum, row) => sum + row.minimum, 0);
45
+ for (const { index, row, cost, minimum } of candidates) {
46
+ reserved -= minimum;
47
+ const allowance = remaining - reserved;
48
+ if (cost <= allowance) {
49
+ selected.set(index, row);
50
+ remaining -= cost;
51
+ }
52
+ else {
53
+ const clipped = clampTextWithMetadata(row, allowance - 1).text;
54
+ selected.set(index, clipped);
55
+ remaining -= countTextChars(clipped) + 1;
56
+ }
57
+ }
58
+ for (const index of signals) {
59
+ if (!selected.has(index))
60
+ continue;
61
+ for (const neighbor of [index - 1, index + 1]) {
62
+ if (neighbor < 0 || neighbor >= lines.length || selected.has(neighbor))
63
+ continue;
64
+ const row = `${neighbor + 1}: ${lines[neighbor]}`;
65
+ const cost = countTextChars(row) + 1;
66
+ if (cost <= remaining) {
67
+ selected.set(neighbor, row);
68
+ remaining -= cost;
69
+ }
70
+ }
71
+ }
72
+ return {
73
+ text: header + [...selected].sort(([left], [right]) => left - right).map(([, row]) => row).join("\n") + footer,
74
+ compaction: createCompactionMetadata("failure-signal-filter"),
75
+ };
76
+ }
@@ -252,6 +252,9 @@ function isSafeRepositoryInventorySource(argv) {
252
252
  }
253
253
  export function isRepositoryInventoryCommand(input) {
254
254
  const argv = input.argv?.length ? getEffectiveCommandArgv(input) : getRepositoryInventorySourceArgv(input.command ?? "");
255
+ return isRepositoryInventoryArgv(argv);
256
+ }
257
+ function isRepositoryInventoryArgv(argv) {
255
258
  const argv0 = getCommandName(argv);
256
259
  if (!argv0) {
257
260
  return false;
@@ -295,11 +298,15 @@ export function isSafeRepositoryInventoryPipeline(command) {
295
298
  }
296
299
  export function isRepositoryInspectionCommand(input) {
297
300
  const argv = input.argv?.length ? getEffectiveCommandArgv(input) : getRepositoryInventorySourceArgv(input.command ?? "");
301
+ return isPreparedRepositoryInspection({ argv, fileContent: isFileContentInspectionCommand(input) });
302
+ }
303
+ function isPreparedRepositoryInspection(analysis) {
304
+ const { argv, fileContent } = analysis;
298
305
  const argv0 = getCommandName(argv);
299
- if (isFileContentInspectionCommand(input)) {
306
+ if (fileContent) {
300
307
  return true;
301
308
  }
302
- if (isRepositoryInventoryCommand(input)) {
309
+ if (isRepositoryInventoryArgv(argv)) {
303
310
  return true;
304
311
  }
305
312
  if (argv0 && REPO_INSPECTION_ONLY_COMMANDS.has(argv0)) {
@@ -323,15 +330,16 @@ export function getInspectionCommandSkipReason(command, policy) {
323
330
  if (policy === "skip-all") {
324
331
  return isRepositoryInspectionCommand({ command }) ? "inspection-command" : null;
325
332
  }
326
- if (isFileContentInspectionCommand({ command }) && !hasCommandOnlyFileContentSummary(command)) {
333
+ const fileContent = isFileContentInspectionCommand({ command });
334
+ if (fileContent && !hasCommandOnlyFileContentSummary(command)) {
327
335
  return "file-content-inspection-command";
328
336
  }
329
337
  if (policy === "skip-file-content") {
330
338
  return null;
331
339
  }
332
- if (isRepositoryInspectionCommand({ command })) {
333
- const sourceArgv = getRepositoryInventorySourceArgv(command);
334
- const argv0 = getCommandName(sourceArgv);
340
+ const analysis = { argv: getRepositoryInventorySourceArgv(command), fileContent };
341
+ if (isPreparedRepositoryInspection(analysis)) {
342
+ const argv0 = getCommandName(analysis.argv);
335
343
  if (argv0 && REPO_INSPECTION_ONLY_COMMANDS.has(argv0)) {
336
344
  return "inspection-command";
337
345
  }
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { createCompactionMetadata, createPassthroughCompactionMetadata } from "./compaction-metadata.js";
3
- import { countTextChars, sliceTextChars } from "./text.js";
3
+ import { countTextChars, segmentTextChars, sliceTextChars } from "./text.js";
4
4
  export function compactWhitespace(text) {
5
5
  return text.replace(/\s+/gu, " ").trim();
6
6
  }
@@ -8,7 +8,8 @@ function shortHash(text) {
8
8
  return createHash("sha256").update(text).digest("hex").slice(0, 12);
9
9
  }
10
10
  function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
11
- if (countTextChars(text) <= maxChars) {
11
+ const segments = segmentTextChars(text);
12
+ if (segments.length <= maxChars) {
12
13
  return { text };
13
14
  }
14
15
  if (noOmit) {
@@ -17,7 +18,7 @@ function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
17
18
  compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough"),
18
19
  };
19
20
  }
20
- const omitted = countTextChars(text) - maxChars;
21
+ const omitted = segments.length - maxChars;
21
22
  const marker = `...[${omitted} chars omitted, sha256:${shortHash(text)}]...`;
22
23
  const markerChars = countTextChars(marker);
23
24
  if (maxChars <= markerChars) {
@@ -30,7 +31,7 @@ function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
30
31
  const headChars = Math.ceil(bodyChars * 0.7);
31
32
  const tailChars = Math.max(0, bodyChars - headChars);
32
33
  return {
33
- text: `${sliceTextChars(text, 0, headChars)}${marker}${tailChars > 0 ? sliceTextChars(text, -tailChars) : ""}`,
34
+ text: `${segments.slice(0, headChars).join("")}${marker}${tailChars > 0 ? segments.slice(-tailChars).join("") : ""}`,
34
35
  compaction: createCompactionMetadata("hashed-middle-clip"),
35
36
  };
36
37
  }
@@ -66,7 +67,8 @@ function minifyJsonLexically(rawText) {
66
67
  return output;
67
68
  }
68
69
  export function clipMiddleWithHash(text, maxChars, noOmit = false) {
69
- if (countTextChars(text) <= maxChars) {
70
+ const segments = segmentTextChars(text);
71
+ if (segments.length <= maxChars) {
70
72
  return { text };
71
73
  }
72
74
  if (noOmit) {
@@ -75,11 +77,11 @@ export function clipMiddleWithHash(text, maxChars, noOmit = false) {
75
77
  compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough"),
76
78
  };
77
79
  }
78
- const omitted = countTextChars(text) - maxChars;
80
+ const omitted = segments.length - maxChars;
79
81
  const headChars = Math.max(20, Math.floor(maxChars * 0.55));
80
82
  const tailChars = Math.max(20, maxChars - headChars);
81
83
  return {
82
- text: `${sliceTextChars(text, 0, headChars)} ...[${omitted} chars omitted, sha256:${shortHash(text)}]... ${sliceTextChars(text, -tailChars)}`,
84
+ text: `${segments.slice(0, headChars).join("")} ...[${omitted} chars omitted, sha256:${shortHash(text)}]... ${segments.slice(-tailChars).join("")}`,
83
85
  compaction: createCompactionMetadata("hashed-middle-clip"),
84
86
  };
85
87
  }