@openclaw/tokenjuice 2026.11.7 → 2026.11.10-beta.2

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 (361) hide show
  1. package/README.md +1 -1
  2. package/dist/.source-module-urls/e1cd11006f37307698d3ccaa0b9377541a8f8fcd96acf7a0d93ee391c8c5abfa.json +1 -1
  3. package/dist/index.js +1 -2
  4. package/dist/tool-result-middleware.js +33 -19
  5. package/node_modules/tokenjuice/README.md +71 -272
  6. package/node_modules/tokenjuice/dist/cli/command-types.d.ts +36 -0
  7. package/node_modules/tokenjuice/dist/cli/command-types.js +1 -0
  8. package/node_modules/tokenjuice/dist/cli/doctor-commands.d.ts +2 -0
  9. package/node_modules/tokenjuice/dist/cli/doctor-commands.js +674 -0
  10. package/node_modules/tokenjuice/dist/cli/doctor-output.d.ts +2 -1
  11. package/node_modules/tokenjuice/dist/cli/doctor-output.js +9 -0
  12. package/node_modules/tokenjuice/dist/cli/host-command.d.ts +4 -0
  13. package/node_modules/tokenjuice/dist/cli/host-command.js +19 -0
  14. package/node_modules/tokenjuice/dist/cli/install-commands.d.ts +2 -0
  15. package/node_modules/tokenjuice/dist/cli/install-commands.js +1263 -0
  16. package/node_modules/tokenjuice/dist/cli/main.d.ts +2 -33
  17. package/node_modules/tokenjuice/dist/cli/main.js +255 -5950
  18. package/node_modules/tokenjuice/dist/cli/uninstall-commands.d.ts +2 -0
  19. package/node_modules/tokenjuice/dist/cli/uninstall-commands.js +554 -0
  20. package/node_modules/tokenjuice/dist/core/bounded-jsonl.js +15 -3
  21. package/node_modules/tokenjuice/dist/core/bounded-text-file.d.ts +3 -0
  22. package/node_modules/tokenjuice/dist/core/bounded-text-file.js +32 -0
  23. package/node_modules/tokenjuice/dist/core/classify.d.ts +0 -5
  24. package/node_modules/tokenjuice/dist/core/classify.js +1 -1
  25. package/node_modules/tokenjuice/dist/core/command-identity.d.ts +0 -2
  26. package/node_modules/tokenjuice/dist/core/command-identity.js +2 -2
  27. package/node_modules/tokenjuice/dist/core/command-match.d.ts +0 -3
  28. package/node_modules/tokenjuice/dist/core/command-match.js +88 -8
  29. package/node_modules/tokenjuice/dist/core/command.d.ts +0 -1
  30. package/node_modules/tokenjuice/dist/core/compaction-metadata.d.ts +1 -1
  31. package/node_modules/tokenjuice/dist/core/env.d.ts +1 -0
  32. package/node_modules/tokenjuice/dist/core/env.js +8 -0
  33. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.d.ts +7 -3
  34. package/node_modules/tokenjuice/dist/core/integrations/compact-bash-result.js +190 -10
  35. package/node_modules/tokenjuice/dist/core/integrations/compact-copilot-result.d.ts +6 -0
  36. package/node_modules/tokenjuice/dist/core/integrations/compact-copilot-result.js +50 -0
  37. package/node_modules/tokenjuice/dist/core/integrations/compact-deepseek-result.d.ts +7 -0
  38. package/node_modules/tokenjuice/dist/core/integrations/compact-deepseek-result.js +46 -0
  39. package/node_modules/tokenjuice/dist/core/integrations/compact-framework-result.d.ts +11 -0
  40. package/node_modules/tokenjuice/dist/core/integrations/compact-framework-result.js +19 -0
  41. package/node_modules/tokenjuice/dist/core/integrations/compact-opencode-v2-result.d.ts +2 -0
  42. package/node_modules/tokenjuice/dist/core/integrations/compact-opencode-v2-result.js +39 -0
  43. package/node_modules/tokenjuice/dist/core/integrations/compact-qoder-result.d.ts +2 -0
  44. package/node_modules/tokenjuice/dist/core/integrations/compact-qoder-result.js +34 -0
  45. package/node_modules/tokenjuice/dist/core/integrations/openclaw-command.d.ts +2 -0
  46. package/node_modules/tokenjuice/dist/core/integrations/openclaw-command.js +13 -0
  47. package/node_modules/tokenjuice/dist/core/integrations/rewrite-cline-input.d.ts +4 -0
  48. package/node_modules/tokenjuice/dist/core/integrations/rewrite-cline-input.js +18 -0
  49. package/node_modules/tokenjuice/dist/core/inventory-safety.d.ts +0 -1
  50. package/node_modules/tokenjuice/dist/core/inventory-safety.js +1 -1
  51. package/node_modules/tokenjuice/dist/core/record-fields.d.ts +1 -0
  52. package/node_modules/tokenjuice/dist/core/record-fields.js +9 -0
  53. package/node_modules/tokenjuice/dist/core/reduce-inspection-summary.d.ts +2 -1
  54. package/node_modules/tokenjuice/dist/core/reduce-inspection-summary.js +7 -94
  55. package/node_modules/tokenjuice/dist/core/simple-yaml-frontmatter.d.ts +9 -0
  56. package/node_modules/tokenjuice/dist/core/simple-yaml-frontmatter.js +125 -0
  57. package/node_modules/tokenjuice/dist/core/source.d.ts +0 -1
  58. package/node_modules/tokenjuice/dist/core/source.js +14 -4
  59. package/node_modules/tokenjuice/dist/core/structural-markers.d.ts +11 -0
  60. package/node_modules/tokenjuice/dist/core/structural-markers.js +49 -0
  61. package/node_modules/tokenjuice/dist/core/text.d.ts +0 -1
  62. package/node_modules/tokenjuice/dist/core/text.js +0 -3
  63. package/node_modules/tokenjuice/dist/core/toml-structure.d.ts +2 -0
  64. package/node_modules/tokenjuice/dist/core/toml-structure.js +83 -0
  65. package/node_modules/tokenjuice/dist/core/validate-rules.d.ts +2 -2
  66. package/node_modules/tokenjuice/dist/core/wrap.js +1 -1
  67. package/node_modules/tokenjuice/dist/hosts/adal/index.d.ts +5 -17
  68. package/node_modules/tokenjuice/dist/hosts/adal/index.js +15 -125
  69. package/node_modules/tokenjuice/dist/hosts/aether/index.d.ts +2 -7
  70. package/node_modules/tokenjuice/dist/hosts/aether/index.js +17 -155
  71. package/node_modules/tokenjuice/dist/hosts/agent-layer/index.d.ts +2 -9
  72. package/node_modules/tokenjuice/dist/hosts/agent-layer/index.js +10 -64
  73. package/node_modules/tokenjuice/dist/hosts/agentinit/index.d.ts +2 -8
  74. package/node_modules/tokenjuice/dist/hosts/agentinit/index.js +15 -111
  75. package/node_modules/tokenjuice/dist/hosts/agentlink/index.d.ts +2 -8
  76. package/node_modules/tokenjuice/dist/hosts/agentlink/index.js +14 -97
  77. package/node_modules/tokenjuice/dist/hosts/agentloom/index.d.ts +2 -9
  78. package/node_modules/tokenjuice/dist/hosts/agentloom/index.js +11 -52
  79. package/node_modules/tokenjuice/dist/hosts/agents-cli/index.d.ts +2 -8
  80. package/node_modules/tokenjuice/dist/hosts/agents-cli/index.js +10 -41
  81. package/node_modules/tokenjuice/dist/hosts/agents-md/index.d.ts +5 -16
  82. package/node_modules/tokenjuice/dist/hosts/agents-md/index.js +16 -128
  83. package/node_modules/tokenjuice/dist/hosts/agentsge/index.d.ts +2 -9
  84. package/node_modules/tokenjuice/dist/hosts/agentsge/index.js +11 -52
  85. package/node_modules/tokenjuice/dist/hosts/agentsmesh/index.d.ts +2 -8
  86. package/node_modules/tokenjuice/dist/hosts/agentsmesh/index.js +10 -53
  87. package/node_modules/tokenjuice/dist/hosts/ai-memory-protocol/index.d.ts +2 -8
  88. package/node_modules/tokenjuice/dist/hosts/ai-memory-protocol/index.js +13 -42
  89. package/node_modules/tokenjuice/dist/hosts/aictl/index.d.ts +5 -16
  90. package/node_modules/tokenjuice/dist/hosts/aictl/index.js +17 -128
  91. package/node_modules/tokenjuice/dist/hosts/aider/index.d.ts +2 -9
  92. package/node_modules/tokenjuice/dist/hosts/aider/index.js +6 -18
  93. package/node_modules/tokenjuice/dist/hosts/amazon-q/index.d.ts +2 -9
  94. package/node_modules/tokenjuice/dist/hosts/amazon-q/index.js +31 -105
  95. package/node_modules/tokenjuice/dist/hosts/amp/index.d.ts +2 -9
  96. package/node_modules/tokenjuice/dist/hosts/amp/index.js +11 -72
  97. package/node_modules/tokenjuice/dist/hosts/ante/index.d.ts +11 -0
  98. package/node_modules/tokenjuice/dist/hosts/ante/index.js +76 -0
  99. package/node_modules/tokenjuice/dist/hosts/antigravity/index.d.ts +2 -9
  100. package/node_modules/tokenjuice/dist/hosts/antigravity/index.js +29 -117
  101. package/node_modules/tokenjuice/dist/hosts/anywhere-agents/index.d.ts +2 -8
  102. package/node_modules/tokenjuice/dist/hosts/anywhere-agents/index.js +14 -97
  103. package/node_modules/tokenjuice/dist/hosts/augment/index.d.ts +2 -9
  104. package/node_modules/tokenjuice/dist/hosts/augment/index.js +29 -117
  105. package/node_modules/tokenjuice/dist/hosts/avante/index.d.ts +5 -17
  106. package/node_modules/tokenjuice/dist/hosts/avante/index.js +5 -27
  107. package/node_modules/tokenjuice/dist/hosts/baz/index.d.ts +2 -8
  108. package/node_modules/tokenjuice/dist/hosts/baz/index.js +17 -132
  109. package/node_modules/tokenjuice/dist/hosts/bito/index.d.ts +2 -8
  110. package/node_modules/tokenjuice/dist/hosts/bito/index.js +11 -108
  111. package/node_modules/tokenjuice/dist/hosts/blackbox/index.d.ts +2 -8
  112. package/node_modules/tokenjuice/dist/hosts/blackbox/index.js +16 -157
  113. package/node_modules/tokenjuice/dist/hosts/blocks/index.d.ts +2 -8
  114. package/node_modules/tokenjuice/dist/hosts/blocks/index.js +16 -157
  115. package/node_modules/tokenjuice/dist/hosts/bob/index.d.ts +5 -17
  116. package/node_modules/tokenjuice/dist/hosts/bob/index.js +13 -123
  117. package/node_modules/tokenjuice/dist/hosts/builder/index.d.ts +2 -9
  118. package/node_modules/tokenjuice/dist/hosts/builder/index.js +34 -131
  119. package/node_modules/tokenjuice/dist/hosts/charlie/index.d.ts +5 -16
  120. package/node_modules/tokenjuice/dist/hosts/charlie/index.js +16 -140
  121. package/node_modules/tokenjuice/dist/hosts/claude-code/index.js +12 -49
  122. package/node_modules/tokenjuice/dist/hosts/clawdbot/index.d.ts +2 -8
  123. package/node_modules/tokenjuice/dist/hosts/clawdbot/index.js +48 -235
  124. package/node_modules/tokenjuice/dist/hosts/cline/index.d.ts +6 -13
  125. package/node_modules/tokenjuice/dist/hosts/cline/index.js +134 -135
  126. package/node_modules/tokenjuice/dist/hosts/codeant/index.d.ts +5 -16
  127. package/node_modules/tokenjuice/dist/hosts/codeant/index.js +12 -123
  128. package/node_modules/tokenjuice/dist/hosts/codebuddy/index.js +14 -58
  129. package/node_modules/tokenjuice/dist/hosts/codebuff/index.d.ts +5 -17
  130. package/node_modules/tokenjuice/dist/hosts/codebuff/index.js +13 -123
  131. package/node_modules/tokenjuice/dist/hosts/codegen/index.d.ts +5 -17
  132. package/node_modules/tokenjuice/dist/hosts/codegen/index.js +13 -123
  133. package/node_modules/tokenjuice/dist/hosts/coder-agents/index.d.ts +2 -8
  134. package/node_modules/tokenjuice/dist/hosts/coder-agents/index.js +25 -193
  135. package/node_modules/tokenjuice/dist/hosts/coderabbit/index.d.ts +2 -8
  136. package/node_modules/tokenjuice/dist/hosts/coderabbit/index.js +16 -173
  137. package/node_modules/tokenjuice/dist/hosts/codex/index.d.ts +3 -4
  138. package/node_modules/tokenjuice/dist/hosts/codex/index.js +26 -58
  139. package/node_modules/tokenjuice/dist/hosts/command-code/index.d.ts +6 -13
  140. package/node_modules/tokenjuice/dist/hosts/command-code/index.js +87 -331
  141. package/node_modules/tokenjuice/dist/hosts/continue/index.d.ts +2 -9
  142. package/node_modules/tokenjuice/dist/hosts/continue/index.js +6 -18
  143. package/node_modules/tokenjuice/dist/hosts/copilot-agent/index.d.ts +2 -11
  144. package/node_modules/tokenjuice/dist/hosts/copilot-agent/index.js +15 -166
  145. package/node_modules/tokenjuice/dist/hosts/copilot-cli/index.d.ts +2 -11
  146. package/node_modules/tokenjuice/dist/hosts/copilot-cli/index.js +24 -196
  147. package/node_modules/tokenjuice/dist/hosts/copilot-sdk/index.d.ts +12 -0
  148. package/node_modules/tokenjuice/dist/hosts/copilot-sdk/index.js +15 -0
  149. package/node_modules/tokenjuice/dist/hosts/crush/index.d.ts +2 -9
  150. package/node_modules/tokenjuice/dist/hosts/crush/index.js +6 -18
  151. package/node_modules/tokenjuice/dist/hosts/cursor/index.js +7 -8
  152. package/node_modules/tokenjuice/dist/hosts/deepagents/index.d.ts +5 -17
  153. package/node_modules/tokenjuice/dist/hosts/deepagents/index.js +15 -125
  154. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/cordis.patch.yml +3 -0
  155. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/index.js +9656 -0
  156. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/bundle/package.json +18 -0
  157. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/runtime.d.ts +7 -0
  158. package/node_modules/tokenjuice/dist/hosts/deepseek-harness/runtime.js +23 -0
  159. package/node_modules/tokenjuice/dist/hosts/devin/index.d.ts +2 -11
  160. package/node_modules/tokenjuice/dist/hosts/devin/index.js +7 -9
  161. package/node_modules/tokenjuice/dist/hosts/docker-agent/index.d.ts +2 -7
  162. package/node_modules/tokenjuice/dist/hosts/docker-agent/index.js +19 -99
  163. package/node_modules/tokenjuice/dist/hosts/dot-agents/index.d.ts +2 -8
  164. package/node_modules/tokenjuice/dist/hosts/dot-agents/index.js +12 -41
  165. package/node_modules/tokenjuice/dist/hosts/droid/index.d.ts +5 -12
  166. package/node_modules/tokenjuice/dist/hosts/droid/index.js +106 -211
  167. package/node_modules/tokenjuice/dist/hosts/eca/index.d.ts +2 -8
  168. package/node_modules/tokenjuice/dist/hosts/eca/index.js +26 -190
  169. package/node_modules/tokenjuice/dist/hosts/elyra/index.d.ts +2 -8
  170. package/node_modules/tokenjuice/dist/hosts/elyra/index.js +26 -190
  171. package/node_modules/tokenjuice/dist/hosts/firebase-studio/index.d.ts +2 -9
  172. package/node_modules/tokenjuice/dist/hosts/firebase-studio/index.js +16 -123
  173. package/node_modules/tokenjuice/dist/hosts/forgecode/index.d.ts +5 -16
  174. package/node_modules/tokenjuice/dist/hosts/forgecode/index.js +20 -161
  175. package/node_modules/tokenjuice/dist/hosts/gemini-cli/index.d.ts +5 -12
  176. package/node_modules/tokenjuice/dist/hosts/gemini-cli/index.js +87 -94
  177. package/node_modules/tokenjuice/dist/hosts/gitlab-duo/index.d.ts +2 -9
  178. package/node_modules/tokenjuice/dist/hosts/gitlab-duo/index.js +17 -123
  179. package/node_modules/tokenjuice/dist/hosts/goose/index.d.ts +2 -9
  180. package/node_modules/tokenjuice/dist/hosts/goose/index.js +34 -77
  181. package/node_modules/tokenjuice/dist/hosts/gptme/index.d.ts +5 -17
  182. package/node_modules/tokenjuice/dist/hosts/gptme/index.js +13 -123
  183. package/node_modules/tokenjuice/dist/hosts/greptile/index.d.ts +2 -8
  184. package/node_modules/tokenjuice/dist/hosts/greptile/index.js +18 -156
  185. package/node_modules/tokenjuice/dist/hosts/grok-bot/index.d.ts +2 -8
  186. package/node_modules/tokenjuice/dist/hosts/grok-bot/index.js +14 -110
  187. package/node_modules/tokenjuice/dist/hosts/grok-build/index.d.ts +5 -17
  188. package/node_modules/tokenjuice/dist/hosts/grok-build/index.js +13 -113
  189. package/node_modules/tokenjuice/dist/hosts/grok-cli/index.d.ts +7 -14
  190. package/node_modules/tokenjuice/dist/hosts/grok-cli/index.js +32 -188
  191. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/__init__.py +1 -0
  192. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/plugin.yaml +7 -0
  193. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/README.md +29 -0
  194. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/__init__.py +3 -0
  195. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/bridge.py +39 -0
  196. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/fastmcp.py +24 -0
  197. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/hermes.py +13 -0
  198. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/langchain.py +38 -0
  199. package/node_modules/tokenjuice/dist/hosts/hermes/bundle/tokenjuice_integrations/plugin.yaml +7 -0
  200. package/node_modules/tokenjuice/dist/hosts/jean2/index.d.ts +5 -17
  201. package/node_modules/tokenjuice/dist/hosts/jean2/index.js +13 -123
  202. package/node_modules/tokenjuice/dist/hosts/jetbrains-ai/index.d.ts +2 -9
  203. package/node_modules/tokenjuice/dist/hosts/jetbrains-ai/index.js +33 -133
  204. package/node_modules/tokenjuice/dist/hosts/jules/index.d.ts +5 -17
  205. package/node_modules/tokenjuice/dist/hosts/jules/index.js +13 -123
  206. package/node_modules/tokenjuice/dist/hosts/junie/index.d.ts +5 -17
  207. package/node_modules/tokenjuice/dist/hosts/junie/index.js +5 -27
  208. package/node_modules/tokenjuice/dist/hosts/kilo/index.d.ts +2 -8
  209. package/node_modules/tokenjuice/dist/hosts/kilo/index.js +6 -18
  210. package/node_modules/tokenjuice/dist/hosts/kimi/index.d.ts +7 -13
  211. package/node_modules/tokenjuice/dist/hosts/kimi/index.js +38 -156
  212. package/node_modules/tokenjuice/dist/hosts/kiro/index.d.ts +2 -9
  213. package/node_modules/tokenjuice/dist/hosts/kiro/index.js +6 -18
  214. package/node_modules/tokenjuice/dist/hosts/knowns/index.d.ts +5 -16
  215. package/node_modules/tokenjuice/dist/hosts/knowns/index.js +35 -203
  216. package/node_modules/tokenjuice/dist/hosts/leanctl/index.d.ts +5 -16
  217. package/node_modules/tokenjuice/dist/hosts/leanctl/index.js +15 -156
  218. package/node_modules/tokenjuice/dist/hosts/localcode/index.d.ts +2 -7
  219. package/node_modules/tokenjuice/dist/hosts/localcode/index.js +10 -68
  220. package/node_modules/tokenjuice/dist/hosts/mastra/index.d.ts +28 -0
  221. package/node_modules/tokenjuice/dist/hosts/mastra/index.js +26 -0
  222. package/node_modules/tokenjuice/dist/hosts/mcp-agent/index.d.ts +2 -7
  223. package/node_modules/tokenjuice/dist/hosts/mcp-agent/index.js +15 -109
  224. package/node_modules/tokenjuice/dist/hosts/mini-swe-agent/index.d.ts +2 -7
  225. package/node_modules/tokenjuice/dist/hosts/mini-swe-agent/index.js +21 -110
  226. package/node_modules/tokenjuice/dist/hosts/mistral-vibe/index.d.ts +5 -17
  227. package/node_modules/tokenjuice/dist/hosts/mistral-vibe/index.js +13 -123
  228. package/node_modules/tokenjuice/dist/hosts/mux/index.d.ts +6 -13
  229. package/node_modules/tokenjuice/dist/hosts/mux/index.js +54 -349
  230. package/node_modules/tokenjuice/dist/hosts/novakit/index.d.ts +5 -16
  231. package/node_modules/tokenjuice/dist/hosts/novakit/index.js +35 -203
  232. package/node_modules/tokenjuice/dist/hosts/ona/index.d.ts +2 -8
  233. package/node_modules/tokenjuice/dist/hosts/ona/index.js +19 -283
  234. package/node_modules/tokenjuice/dist/hosts/open-interpreter/index.d.ts +2 -9
  235. package/node_modules/tokenjuice/dist/hosts/open-interpreter/index.js +11 -66
  236. package/node_modules/tokenjuice/dist/hosts/openclaw/extension.js +6 -5
  237. package/node_modules/tokenjuice/dist/hosts/opencode/extension/runtime.js +540 -363
  238. package/node_modules/tokenjuice/dist/hosts/opencode/index.js +8 -54
  239. package/node_modules/tokenjuice/dist/hosts/opencode/v2/bundle/index.js +9648 -0
  240. package/node_modules/tokenjuice/dist/hosts/opencode/v2/index.d.ts +37 -0
  241. package/node_modules/tokenjuice/dist/hosts/opencode/v2/index.js +97 -0
  242. package/node_modules/tokenjuice/dist/hosts/opencode/v2/runtime.d.ts +13 -0
  243. package/node_modules/tokenjuice/dist/hosts/opencode/v2/runtime.js +23 -0
  244. package/node_modules/tokenjuice/dist/hosts/openhands/index.d.ts +7 -14
  245. package/node_modules/tokenjuice/dist/hosts/openhands/index.js +111 -186
  246. package/node_modules/tokenjuice/dist/hosts/openwebui/index.d.ts +2 -7
  247. package/node_modules/tokenjuice/dist/hosts/openwebui/index.js +2 -24
  248. package/node_modules/tokenjuice/dist/hosts/pi/extension/pi-types.d.ts +3 -2
  249. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.d.ts +2 -1
  250. package/node_modules/tokenjuice/dist/hosts/pi/extension/runtime.js +545 -359
  251. package/node_modules/tokenjuice/dist/hosts/pi/extension/status-panel.d.ts +1 -1
  252. package/node_modules/tokenjuice/dist/hosts/pi/extension/status.d.ts +1 -1
  253. package/node_modules/tokenjuice/dist/hosts/pi/extension/tool-result.d.ts +1 -1
  254. package/node_modules/tokenjuice/dist/hosts/pi/index.d.ts +1 -0
  255. package/node_modules/tokenjuice/dist/hosts/pi/index.js +5 -53
  256. package/node_modules/tokenjuice/dist/hosts/pi-go/index.d.ts +2 -8
  257. package/node_modules/tokenjuice/dist/hosts/pi-go/index.js +26 -190
  258. package/node_modules/tokenjuice/dist/hosts/plandex/index.d.ts +2 -9
  259. package/node_modules/tokenjuice/dist/hosts/plandex/index.js +10 -41
  260. package/node_modules/tokenjuice/dist/hosts/qoder/hook-install.d.ts +22 -0
  261. package/node_modules/tokenjuice/dist/hosts/qoder/hook-install.js +105 -0
  262. package/node_modules/tokenjuice/dist/hosts/qoder/hook.d.ts +1 -0
  263. package/node_modules/tokenjuice/dist/hosts/qoder/hook.js +22 -0
  264. package/node_modules/tokenjuice/dist/hosts/qoder/index.d.ts +5 -17
  265. package/node_modules/tokenjuice/dist/hosts/qoder/index.js +13 -113
  266. package/node_modules/tokenjuice/dist/hosts/qoderwork/index.d.ts +36 -0
  267. package/node_modules/tokenjuice/dist/hosts/qoderwork/index.js +20 -0
  268. package/node_modules/tokenjuice/dist/hosts/qodo/index.d.ts +2 -8
  269. package/node_modules/tokenjuice/dist/hosts/qodo/index.js +20 -290
  270. package/node_modules/tokenjuice/dist/hosts/qwen-code/index.d.ts +6 -13
  271. package/node_modules/tokenjuice/dist/hosts/qwen-code/index.js +60 -165
  272. package/node_modules/tokenjuice/dist/hosts/qwenwork/index.d.ts +36 -0
  273. package/node_modules/tokenjuice/dist/hosts/qwenwork/index.js +20 -0
  274. package/node_modules/tokenjuice/dist/hosts/replit/index.d.ts +5 -17
  275. package/node_modules/tokenjuice/dist/hosts/replit/index.js +13 -123
  276. package/node_modules/tokenjuice/dist/hosts/roo/index.d.ts +5 -17
  277. package/node_modules/tokenjuice/dist/hosts/roo/index.js +5 -31
  278. package/node_modules/tokenjuice/dist/hosts/rovo/index.d.ts +5 -17
  279. package/node_modules/tokenjuice/dist/hosts/rovo/index.js +13 -123
  280. package/node_modules/tokenjuice/dist/hosts/ruler/index.d.ts +2 -9
  281. package/node_modules/tokenjuice/dist/hosts/ruler/index.js +10 -64
  282. package/node_modules/tokenjuice/dist/hosts/shared/bundle-runtime.d.ts +2 -0
  283. package/node_modules/tokenjuice/dist/hosts/shared/bundle-runtime.js +56 -0
  284. package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.d.ts +3 -8
  285. package/node_modules/tokenjuice/dist/hosts/shared/hook-command-doctor.js +3 -3
  286. package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.d.ts +112 -101
  287. package/node_modules/tokenjuice/dist/hosts/shared/hook-doctor.js +10 -0
  288. package/node_modules/tokenjuice/dist/hosts/shared/hook-output.d.ts +0 -1
  289. package/node_modules/tokenjuice/dist/hosts/shared/hook-output.js +1 -1
  290. package/node_modules/tokenjuice/dist/hosts/shared/hooks-json-file.d.ts +15 -0
  291. package/node_modules/tokenjuice/dist/hosts/shared/hooks-json-file.js +93 -0
  292. package/node_modules/tokenjuice/dist/hosts/shared/host-command.d.ts +1 -1
  293. package/node_modules/tokenjuice/dist/hosts/shared/host-command.js +4 -4
  294. package/node_modules/tokenjuice/dist/hosts/shared/instruction-doctor.d.ts +4 -0
  295. package/node_modules/tokenjuice/dist/hosts/shared/instruction-file.d.ts +26 -6
  296. package/node_modules/tokenjuice/dist/hosts/shared/instruction-file.js +125 -5
  297. package/node_modules/tokenjuice/dist/hosts/shared/instruction-guidance.d.ts +7 -0
  298. package/node_modules/tokenjuice/dist/hosts/shared/instruction-guidance.js +24 -0
  299. package/node_modules/tokenjuice/dist/hosts/shared/managed-skill.d.ts +42 -0
  300. package/node_modules/tokenjuice/dist/hosts/shared/managed-skill.js +87 -0
  301. package/node_modules/tokenjuice/dist/hosts/shared/marker-instruction-doctor.d.ts +29 -0
  302. package/node_modules/tokenjuice/dist/hosts/shared/marker-instruction-doctor.js +72 -0
  303. package/node_modules/tokenjuice/dist/hosts/shared/marker-instructions.d.ts +12 -0
  304. package/node_modules/tokenjuice/dist/hosts/shared/marker-instructions.js +43 -0
  305. package/node_modules/tokenjuice/dist/hosts/shared/owned-instruction-doctor.d.ts +9 -0
  306. package/node_modules/tokenjuice/dist/hosts/shared/owned-instruction-doctor.js +17 -0
  307. package/node_modules/tokenjuice/dist/hosts/shared/path-ancestors.d.ts +14 -0
  308. package/node_modules/tokenjuice/dist/hosts/shared/path-ancestors.js +117 -0
  309. package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.d.ts +7 -7
  310. package/node_modules/tokenjuice/dist/hosts/shared/pre-tool-wrap.js +13 -48
  311. package/node_modules/tokenjuice/dist/hosts/shared/private-config-file.d.ts +2 -0
  312. package/node_modules/tokenjuice/dist/hosts/shared/private-config-file.js +36 -0
  313. package/node_modules/tokenjuice/dist/hosts/shared/project-root.d.ts +5 -0
  314. package/node_modules/tokenjuice/dist/hosts/shared/project-root.js +33 -0
  315. package/node_modules/tokenjuice/dist/hosts/shared/project-skill-doctor.d.ts +14 -0
  316. package/node_modules/tokenjuice/dist/hosts/shared/project-skill-doctor.js +62 -0
  317. package/node_modules/tokenjuice/dist/hosts/shared/restorable-rule.d.ts +15 -0
  318. package/node_modules/tokenjuice/dist/hosts/shared/restorable-rule.js +64 -0
  319. package/node_modules/tokenjuice/dist/hosts/shared/restorable-skill.d.ts +15 -0
  320. package/node_modules/tokenjuice/dist/hosts/shared/restorable-skill.js +48 -0
  321. package/node_modules/tokenjuice/dist/hosts/shared/settings-file.d.ts +5 -1
  322. package/node_modules/tokenjuice/dist/hosts/shared/settings-file.js +33 -5
  323. package/node_modules/tokenjuice/dist/hosts/shared/skill-frontmatter.d.ts +5 -0
  324. package/node_modules/tokenjuice/dist/hosts/shared/skill-frontmatter.js +18 -0
  325. package/node_modules/tokenjuice/dist/hosts/stagewise/index.d.ts +2 -8
  326. package/node_modules/tokenjuice/dist/hosts/stagewise/index.js +50 -377
  327. package/node_modules/tokenjuice/dist/hosts/swe-agent/index.d.ts +2 -7
  328. package/node_modules/tokenjuice/dist/hosts/swe-agent/index.js +20 -88
  329. package/node_modules/tokenjuice/dist/hosts/tabby/index.d.ts +2 -8
  330. package/node_modules/tokenjuice/dist/hosts/tabby/index.js +13 -190
  331. package/node_modules/tokenjuice/dist/hosts/tabnine/index.d.ts +5 -17
  332. package/node_modules/tokenjuice/dist/hosts/tabnine/index.js +13 -123
  333. package/node_modules/tokenjuice/dist/hosts/trae/index.d.ts +2 -9
  334. package/node_modules/tokenjuice/dist/hosts/trae/index.js +17 -123
  335. package/node_modules/tokenjuice/dist/hosts/uipath/index.d.ts +5 -17
  336. package/node_modules/tokenjuice/dist/hosts/uipath/index.js +13 -123
  337. package/node_modules/tokenjuice/dist/hosts/vscode-copilot/index.d.ts +2 -11
  338. package/node_modules/tokenjuice/dist/hosts/vscode-copilot/index.js +15 -101
  339. package/node_modules/tokenjuice/dist/hosts/warp/index.d.ts +5 -17
  340. package/node_modules/tokenjuice/dist/hosts/warp/index.js +14 -116
  341. package/node_modules/tokenjuice/dist/hosts/windsurf/index.d.ts +2 -9
  342. package/node_modules/tokenjuice/dist/hosts/windsurf/index.js +6 -18
  343. package/node_modules/tokenjuice/dist/hosts/zed/index.d.ts +5 -17
  344. package/node_modules/tokenjuice/dist/hosts/zed/index.js +5 -27
  345. package/node_modules/tokenjuice/dist/hosts/zencoder/index.d.ts +2 -9
  346. package/node_modules/tokenjuice/dist/hosts/zencoder/index.js +42 -139
  347. package/node_modules/tokenjuice/dist/index.d.ts +20 -4
  348. package/node_modules/tokenjuice/dist/index.js +14 -4
  349. package/node_modules/tokenjuice/dist/python/LICENSE +21 -0
  350. package/node_modules/tokenjuice/dist/python/README.md +38 -0
  351. package/node_modules/tokenjuice/dist/python/pyproject.toml +30 -0
  352. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/README.md +29 -0
  353. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/__init__.py +3 -0
  354. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/bridge.py +39 -0
  355. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/fastmcp.py +24 -0
  356. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/hermes.py +13 -0
  357. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/langchain.py +38 -0
  358. package/node_modules/tokenjuice/dist/python/tokenjuice_integrations/plugin.yaml +7 -0
  359. package/node_modules/tokenjuice/dist/types.d.ts +9 -8
  360. package/node_modules/tokenjuice/package.json +32 -11
  361. package/package.json +5 -5
@@ -1,8 +1,34 @@
1
- // src/hosts/pi/extension/runtime.ts
2
- import { readFile as readFile4, stat as stat2 } from "node:fs/promises";
3
-
4
- // src/core/command-identity.ts
5
- import { basename } from "node:path";
1
+ // src/core/bounded-text-file.ts
2
+ import { constants } from "node:fs";
3
+ import { open } from "node:fs/promises";
4
+ async function readBoundedTextFile(path, maxBytes, options = {}) {
5
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) {
6
+ throw new RangeError("maxBytes must be a non-negative safe integer");
7
+ }
8
+ const file = await open(path, options.regularFileOnly ? constants.O_RDONLY | constants.O_NONBLOCK : "r");
9
+ try {
10
+ const details = await file.stat();
11
+ if (options.regularFileOnly && !details.isFile() || details.size > maxBytes) {
12
+ return null;
13
+ }
14
+ const chunks = [];
15
+ let totalBytes = 0;
16
+ for (; ; ) {
17
+ const buffer = Buffer.allocUnsafe(Math.min(64 * 1024, maxBytes - totalBytes + 1));
18
+ const { bytesRead } = await file.read(buffer, 0, buffer.length, null);
19
+ if (bytesRead === 0) {
20
+ return Buffer.concat(chunks, totalBytes).toString("utf8");
21
+ }
22
+ totalBytes += bytesRead;
23
+ if (totalBytes > maxBytes) {
24
+ return null;
25
+ }
26
+ chunks.push(buffer.subarray(0, bytesRead));
27
+ }
28
+ } finally {
29
+ await file.close();
30
+ }
31
+ }
6
32
 
7
33
  // src/core/command-shell.ts
8
34
  var COMPOUND_SHELL_OPERATORS = /* @__PURE__ */ new Set([";", "\n", "|", "&&", "||"]);
@@ -404,7 +430,7 @@ function getNormalizedArgv(input) {
404
430
  return tokenizeCommand(input.command);
405
431
  }
406
432
  function isShellCommandStringOption(token) {
407
- return /^-[A-Za-z]*c[A-Za-z]*$/u.test(token);
433
+ return token.includes("c") && /^-[A-Za-z]+$/u.test(token);
408
434
  }
409
435
  function getSourcePriority(source) {
410
436
  switch (source) {
@@ -585,18 +611,81 @@ function isSetupConditionCommand(command) {
585
611
  return segments.length > 0 && segments.every((segment) => isSetupConditionSegment(tokenizeCommand(segment), segment));
586
612
  }
587
613
  function stripLeadingSetupIfBlock(command) {
588
- const match = /^if\s+([\s\S]+?)(?:;|\n)\s*then\s+([\s\S]+?)(?:(?:;|\n)\s*else\s+([\s\S]+?))?(?:;|\n)\s*fi\s*(?:;|&&|\n)\s*(.+)$/u.exec(command.trim());
589
- if (!match) {
614
+ const text = command.trim();
615
+ if (!/^if\s/u.test(text)) {
590
616
  return null;
591
617
  }
592
- const [, condition, thenCommand, elseCommand, tail] = match;
618
+ let quote = null;
619
+ let escaping = false;
620
+ let depth = 0;
621
+ let phase = "condition";
622
+ let start = 2;
623
+ let condition = "";
624
+ let thenCommand = "";
625
+ let elseCommand;
626
+ let tail = "";
627
+ for (let index = start; index < text.length; index += 1) {
628
+ const char = text[index];
629
+ if (escaping) {
630
+ escaping = false;
631
+ continue;
632
+ }
633
+ if (char === "\\" && quote !== "'") {
634
+ escaping = true;
635
+ continue;
636
+ }
637
+ if (quote) {
638
+ if (char === quote) quote = null;
639
+ continue;
640
+ }
641
+ if (char === "'" || char === '"') {
642
+ quote = char;
643
+ continue;
644
+ }
645
+ if (char === "(") {
646
+ depth += 1;
647
+ continue;
648
+ }
649
+ if (char === ")") {
650
+ if (--depth < 0) return null;
651
+ continue;
652
+ }
653
+ if (depth > 0 || char !== ";" && char !== "\n") continue;
654
+ let wordStart = index + 1;
655
+ while (/[ \t\r]/u.test(text[wordStart] ?? "")) wordStart += 1;
656
+ const keyword = ["then", "else", "fi", "if", "elif"].find((word) => text.startsWith(word, wordStart) && /[\s;&]/u.test(text[wordStart + word.length] ?? ""));
657
+ if (!keyword) continue;
658
+ const part = text.slice(start, index).trim();
659
+ const next = wordStart + keyword.length;
660
+ if (keyword === "then" && phase === "condition" && /\s/u.test(text[next] ?? "")) {
661
+ condition = part;
662
+ phase = "then";
663
+ } else if (keyword === "else" && phase === "then" && /\s/u.test(text[next] ?? "")) {
664
+ thenCommand = part;
665
+ phase = "else";
666
+ } else if (keyword === "fi" && phase !== "condition") {
667
+ if (phase === "then") thenCommand = part;
668
+ else elseCommand = part;
669
+ let end = next;
670
+ while (/[ \t\r]/u.test(text[end] ?? "")) end += 1;
671
+ if (text[end] === ";" || text[end] === "\n") end += 1;
672
+ else if (text.startsWith("&&", end)) end += 2;
673
+ else return null;
674
+ tail = text.slice(end).trim();
675
+ break;
676
+ } else {
677
+ return null;
678
+ }
679
+ start = next;
680
+ index = next - 1;
681
+ }
593
682
  if (!condition || !thenCommand || !tail) {
594
683
  return null;
595
684
  }
596
685
  if (!isSetupConditionCommand(condition) || !isSetupWrapperCommand(thenCommand)) {
597
686
  return null;
598
687
  }
599
- if (elseCommand && !isSetupWrapperCommand(elseCommand)) {
688
+ if (elseCommand !== void 0 && !isSetupWrapperCommand(elseCommand)) {
600
689
  return null;
601
690
  }
602
691
  return tail.trim() || null;
@@ -722,6 +811,7 @@ function deriveCommandMatchCandidates(input) {
722
811
  }
723
812
 
724
813
  // src/core/command-identity.ts
814
+ import { basename } from "node:path";
725
815
  var FILE_CONTENT_INSPECTION_COMMANDS = /* @__PURE__ */ new Set(["cat", "sed", "head", "tail", "nl", "bat", "batcat", "jq", "yq"]);
726
816
  var SSH_OPTIONS_WITH_VALUES = /* @__PURE__ */ new Set([
727
817
  "-B",
@@ -937,6 +1027,57 @@ function isVerbatimConfigInspectionCommand(input) {
937
1027
  });
938
1028
  }
939
1029
 
1030
+ // src/core/execution-input.ts
1031
+ function normalizeExecutionInput(input) {
1032
+ const shellWrapped = unwrapShellRunner(input);
1033
+ if (shellWrapped) {
1034
+ const effectiveCommand2 = stripLeadingCdPrefix(shellWrapped);
1035
+ if (isCompoundShellCommand(effectiveCommand2)) {
1036
+ const { argv: _argv, ...restInput } = input;
1037
+ return {
1038
+ ...restInput,
1039
+ command: effectiveCommand2
1040
+ };
1041
+ }
1042
+ const argv2 = resolveEffectiveCommand({ command: effectiveCommand2 })?.argv ?? tokenizeCommand(effectiveCommand2);
1043
+ if (argv2.length === 0) {
1044
+ return {
1045
+ ...input,
1046
+ command: effectiveCommand2
1047
+ };
1048
+ }
1049
+ return {
1050
+ ...input,
1051
+ command: argv2.join(" "),
1052
+ argv: argv2
1053
+ };
1054
+ }
1055
+ const effective = resolveEffectiveCommand(input);
1056
+ if (effective?.argv.length) {
1057
+ return {
1058
+ ...input,
1059
+ ...effective.command ? { command: effective.command } : {},
1060
+ argv: effective.argv
1061
+ };
1062
+ }
1063
+ if (input.argv?.length || !input.command) {
1064
+ return input;
1065
+ }
1066
+ const effectiveCommand = stripLeadingCdPrefix(input.command);
1067
+ if (isCompoundShellCommand(effectiveCommand)) {
1068
+ return input;
1069
+ }
1070
+ const argv = tokenizeCommand(effectiveCommand);
1071
+ if (argv.length === 0) {
1072
+ return input;
1073
+ }
1074
+ return {
1075
+ ...input,
1076
+ command: argv.join(" "),
1077
+ argv
1078
+ };
1079
+ }
1080
+
940
1081
  // src/core/inventory-safety.ts
941
1082
  var REPO_INVENTORY_COMMANDS = /* @__PURE__ */ new Set(["find", "fd", "fdfind", "ls"]);
942
1083
  var REPO_INSPECTION_ONLY_COMMANDS = /* @__PURE__ */ new Set(["tree"]);
@@ -1225,7 +1366,7 @@ function getRepositoryInventorySafety(command) {
1225
1366
  });
1226
1367
  return safePipeline ? "safe" : "unsafe-pipeline";
1227
1368
  }
1228
- function isRepositoryInspectionCommand(input) {
1369
+ function isRepositoryInspectionCommand2(input) {
1229
1370
  const argv = input.argv?.length ? getEffectiveCommandArgv(input) : getRepositoryInventorySourceArgv(input.command ?? "");
1230
1371
  const argv0 = getCommandName(argv);
1231
1372
  if (isFileContentInspectionCommand(input)) {
@@ -1251,7 +1392,7 @@ function getInspectionCommandSkipReason(command, policy) {
1251
1392
  return null;
1252
1393
  }
1253
1394
  if (policy === "skip-all") {
1254
- return isRepositoryInspectionCommand({ command }) ? "inspection-command" : null;
1395
+ return isRepositoryInspectionCommand2({ command }) ? "inspection-command" : null;
1255
1396
  }
1256
1397
  if (isFileContentInspectionCommand({ command }) && !hasCommandOnlyFileContentSummary(command)) {
1257
1398
  return "file-content-inspection-command";
@@ -1259,7 +1400,7 @@ function getInspectionCommandSkipReason(command, policy) {
1259
1400
  if (policy === "skip-file-content") {
1260
1401
  return null;
1261
1402
  }
1262
- if (isRepositoryInspectionCommand({ command })) {
1403
+ if (isRepositoryInspectionCommand2({ command })) {
1263
1404
  const sourceArgv = getRepositoryInventorySourceArgv(command);
1264
1405
  const argv0 = getCommandName(sourceArgv);
1265
1406
  if (argv0 && REPO_INSPECTION_ONLY_COMMANDS.has(argv0)) {
@@ -1290,7 +1431,7 @@ import { homedir } from "node:os";
1290
1431
  import { join as join2 } from "node:path";
1291
1432
 
1292
1433
  // src/core/bounded-jsonl.ts
1293
- import { appendFile, lstat, mkdir, open, opendir, readFile, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
1434
+ import { appendFile, lstat, mkdir, open as open2, opendir, readFile, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
1294
1435
  import { createHash, randomUUID } from "node:crypto";
1295
1436
  import { join } from "node:path";
1296
1437
  var DAY_MS = 24 * 60 * 60 * 1e3;
@@ -1301,6 +1442,16 @@ var MAX_SHARD_COUNT = 100;
1301
1442
  var MAX_STORE_FILES = 1e4;
1302
1443
  var MAX_SEGMENT_BYTES = 64 * 1024 * 1024;
1303
1444
  var DIRECTORY_ENTRY_SLACK = 256;
1445
+ async function closeDirectoryHandle(directoryHandle) {
1446
+ const close = directoryHandle.close;
1447
+ if (typeof close !== "function") {
1448
+ return;
1449
+ }
1450
+ try {
1451
+ await close.call(directoryHandle);
1452
+ } catch {
1453
+ }
1454
+ }
1304
1455
  var DEFAULT_RETENTION_DAYS = 14;
1305
1456
  var DEFAULT_SHARD_COUNT = 8;
1306
1457
  var DEFAULT_MAX_SEGMENT_BYTES = 1024 * 1024;
@@ -1425,8 +1576,7 @@ async function pruneExpiredSegments(directory, prefix, retentionDays, maxFiles,
1425
1576
  }
1426
1577
  }
1427
1578
  } finally {
1428
- await directoryHandle.close().catch(() => {
1429
- });
1579
+ await closeDirectoryHandle(directoryHandle);
1430
1580
  }
1431
1581
  }
1432
1582
  async function countOwnedSegments(directory, prefix, maxFiles) {
@@ -1447,8 +1597,7 @@ async function countOwnedSegments(directory, prefix, maxFiles) {
1447
1597
  }
1448
1598
  }
1449
1599
  } finally {
1450
- await directoryHandle.close().catch(() => {
1451
- });
1600
+ await closeDirectoryHandle(directoryHandle);
1452
1601
  }
1453
1602
  return { count, complete: true };
1454
1603
  }
@@ -1499,7 +1648,7 @@ async function appendBoundedJsonl(directory, prefix, id, value, options = {}) {
1499
1648
  }
1500
1649
  if (!targetExists) {
1501
1650
  try {
1502
- const file = await open(path, "wx", 384);
1651
+ const file = await open2(path, "wx", 384);
1503
1652
  await file.close();
1504
1653
  } catch (error) {
1505
1654
  await releaseLock(lockPath, owner);
@@ -1541,57 +1690,6 @@ async function appendBoundedJsonl(directory, prefix, id, value, options = {}) {
1541
1690
  }
1542
1691
  }
1543
1692
 
1544
- // src/core/execution-input.ts
1545
- function normalizeExecutionInput(input) {
1546
- const shellWrapped = unwrapShellRunner(input);
1547
- if (shellWrapped) {
1548
- const effectiveCommand2 = stripLeadingCdPrefix(shellWrapped);
1549
- if (isCompoundShellCommand(effectiveCommand2)) {
1550
- const { argv: _argv, ...restInput } = input;
1551
- return {
1552
- ...restInput,
1553
- command: effectiveCommand2
1554
- };
1555
- }
1556
- const argv2 = resolveEffectiveCommand({ command: effectiveCommand2 })?.argv ?? tokenizeCommand(effectiveCommand2);
1557
- if (argv2.length === 0) {
1558
- return {
1559
- ...input,
1560
- command: effectiveCommand2
1561
- };
1562
- }
1563
- return {
1564
- ...input,
1565
- command: argv2.join(" "),
1566
- argv: argv2
1567
- };
1568
- }
1569
- const effective = resolveEffectiveCommand(input);
1570
- if (effective?.argv.length) {
1571
- return {
1572
- ...input,
1573
- ...effective.command ? { command: effective.command } : {},
1574
- argv: effective.argv
1575
- };
1576
- }
1577
- if (input.argv?.length || !input.command) {
1578
- return input;
1579
- }
1580
- const effectiveCommand = stripLeadingCdPrefix(input.command);
1581
- if (isCompoundShellCommand(effectiveCommand)) {
1582
- return input;
1583
- }
1584
- const argv = tokenizeCommand(effectiveCommand);
1585
- if (argv.length === 0) {
1586
- return input;
1587
- }
1588
- return {
1589
- ...input,
1590
- command: argv.join(" "),
1591
- argv
1592
- };
1593
- }
1594
-
1595
1693
  // src/core/compaction-metadata.ts
1596
1694
  var NO_COMPACTION_METADATA = {
1597
1695
  authoritative: false,
@@ -1796,11 +1894,24 @@ function pluralize(count, noun) {
1796
1894
 
1797
1895
  // src/core/source.ts
1798
1896
  var DEFAULT_CLI_ARTIFACT_SOURCE = "cli";
1897
+ function trimHyphens(value) {
1898
+ let start = 0;
1899
+ let end = value.length;
1900
+ while (value[start] === "-") {
1901
+ start += 1;
1902
+ }
1903
+ while (end > start && value[end - 1] === "-") {
1904
+ end -= 1;
1905
+ }
1906
+ return value.slice(start, end);
1907
+ }
1799
1908
  function normalizeArtifactSource(value) {
1800
1909
  if (typeof value !== "string") {
1801
1910
  return null;
1802
1911
  }
1803
- const source = value.trim().toLowerCase().replace(/[_\s]+/gu, "-").replace(/[^a-z0-9.-]+/gu, "-").replace(/^-+|-+$/gu, "");
1912
+ const source = trimHyphens(
1913
+ value.trim().toLowerCase().replace(/[_\s]+/gu, "-").replace(/[^a-z0-9.-]+/gu, "-")
1914
+ );
1804
1915
  if (!source) {
1805
1916
  return null;
1806
1917
  }
@@ -2004,283 +2115,59 @@ async function storeArtifact(input, storeDir) {
2004
2115
  rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
2005
2116
  ...input.input.toolName ? { toolName: input.input.toolName } : {},
2006
2117
  ...input.input.command ? { command: input.input.command } : {},
2007
- ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
2008
- ...captureTruncated !== void 0 ? { captureTruncated } : {},
2009
- ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
2010
- }
2011
- };
2012
- await Promise.all([
2013
- writeFile2(ref.path, input.rawText, { encoding: "utf8", mode: 384 }),
2014
- writeFile2(ref.metadataPath, JSON.stringify(artifact.metadata, null, 2), { encoding: "utf8", mode: 384 })
2015
- ]);
2016
- if (input.recordStats ?? shouldRecordStats()) {
2017
- await appendMetadataEvent(id, artifact.metadata, input.input, true, storeDir).catch(() => void 0);
2018
- }
2019
- return ref;
2020
- }
2021
- async function storeArtifactMetadata(input, storeDir) {
2022
- const id = `tj_${randomUUID2().slice(0, 12)}`;
2023
- const captureTruncated = extractCaptureTruncatedFlag(input.input);
2024
- const metadata = {
2025
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2026
- source: resolveArtifactSource(input.input),
2027
- classification: input.classification,
2028
- rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
2029
- ...input.input.toolName ? { toolName: input.input.toolName } : {},
2030
- ...input.input.command ? { command: input.input.command } : {},
2031
- ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
2032
- ...captureTruncated !== void 0 ? { captureTruncated } : {},
2033
- ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
2034
- };
2035
- const telemetryMetadata = buildTelemetryMetadata(metadata, input.input);
2036
- const metadataPath = await appendMetadataEvent(id, telemetryMetadata, input.input, false, storeDir);
2037
- if (!metadataPath) {
2038
- throw Object.assign(new Error("metadata segment is full or busy"), { code: "EFBIG" });
2039
- }
2040
- return {
2041
- id,
2042
- storage: "file",
2043
- metadataPath,
2044
- metadataFormat: "jsonl-segment",
2045
- metadataRecordId: id,
2046
- metadata: telemetryMetadata
2047
- };
2048
- }
2049
- async function tryStoreArtifactMetadata(input, storeDir) {
2050
- try {
2051
- return await storeArtifactMetadata(input, storeDir);
2052
- } catch (error) {
2053
- const code = error.code;
2054
- if (typeof code !== "string" || !OPTIONAL_METADATA_STORAGE_ERROR_CODES.has(code)) {
2055
- throw error;
2056
- }
2057
- return void 0;
2058
- }
2059
- }
2060
-
2061
- // src/core/reduce-utils.ts
2062
- import { createHash as createHash2 } from "node:crypto";
2063
- function compactWhitespace(text) {
2064
- return text.replace(/\s+/gu, " ").trim();
2065
- }
2066
- function shortHash(text) {
2067
- return createHash2("sha256").update(text).digest("hex").slice(0, 12);
2068
- }
2069
- function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
2070
- if (countTextChars(text) <= maxChars) {
2071
- return { text };
2072
- }
2073
- if (noOmit) {
2074
- return {
2075
- text,
2076
- compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough")
2077
- };
2078
- }
2079
- const omitted = countTextChars(text) - maxChars;
2080
- const marker = `...[${omitted} chars omitted, sha256:${shortHash(text)}]...`;
2081
- const markerChars = countTextChars(marker);
2082
- if (maxChars <= markerChars) {
2083
- return {
2084
- text: sliceTextChars(marker, 0, maxChars),
2085
- compaction: createCompactionMetadata("hashed-middle-clip")
2086
- };
2087
- }
2088
- const bodyChars = maxChars - markerChars;
2089
- const headChars = Math.ceil(bodyChars * 0.7);
2090
- const tailChars = Math.max(0, bodyChars - headChars);
2091
- return {
2092
- text: `${sliceTextChars(text, 0, headChars)}${marker}${tailChars > 0 ? sliceTextChars(text, -tailChars) : ""}`,
2093
- compaction: createCompactionMetadata("hashed-middle-clip")
2094
- };
2095
- }
2096
- function minifyJsonLexically(rawText) {
2097
- const text = rawText.trim();
2098
- let output = "";
2099
- let inString = false;
2100
- let escaped = false;
2101
- for (const char of text) {
2102
- if (inString) {
2103
- output += char;
2104
- if (escaped) {
2105
- escaped = false;
2106
- } else if (char === "\\") {
2107
- escaped = true;
2108
- } else if (char === '"') {
2109
- inString = false;
2110
- }
2111
- continue;
2112
- }
2113
- if (char === '"') {
2114
- inString = true;
2115
- output += char;
2116
- continue;
2117
- }
2118
- if (/\s/u.test(char)) {
2119
- continue;
2120
- }
2121
- output += char;
2122
- }
2123
- return output;
2124
- }
2125
- function clipMiddleWithHash(text, maxChars, noOmit = false) {
2126
- if (countTextChars(text) <= maxChars) {
2127
- return { text };
2128
- }
2129
- if (noOmit) {
2130
- return {
2131
- text,
2132
- compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough")
2133
- };
2134
- }
2135
- const omitted = countTextChars(text) - maxChars;
2136
- const headChars = Math.max(20, Math.floor(maxChars * 0.55));
2137
- const tailChars = Math.max(20, maxChars - headChars);
2138
- return {
2139
- text: `${sliceTextChars(text, 0, headChars)} ...[${omitted} chars omitted, sha256:${shortHash(text)}]... ${sliceTextChars(text, -tailChars)}`,
2140
- compaction: createCompactionMetadata("hashed-middle-clip")
2141
- };
2142
- }
2143
- function compactWholeJsonText(rawText, maxChars, noOmit = false) {
2144
- return parseJsonValue(rawText) === null ? null : clipMiddleWithHashStrict(minifyJsonLexically(rawText), maxChars, noOmit);
2145
- }
2146
- function parseJsonObjectLine(line2) {
2147
- const trimmed = line2.trim();
2148
- if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
2149
- return null;
2150
- }
2151
- try {
2152
- const parsed = JSON.parse(trimmed);
2153
- return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : null;
2154
- } catch {
2155
- return null;
2156
- }
2157
- }
2158
- function parseJsonValue(text) {
2159
- const trimmed = text.trim();
2160
- if (!(trimmed.startsWith("{") || trimmed.startsWith("["))) {
2161
- return null;
2162
- }
2163
- try {
2164
- return JSON.parse(trimmed);
2165
- } catch {
2166
- return null;
2167
- }
2168
- }
2169
-
2170
- // src/core/reduce-inspection-summary.ts
2171
- var LARGE_INSPECTION_MIN_CHARS = 4e3;
2172
- var LARGE_INSPECTION_MIN_LINES = 40;
2173
- var PACKAGE_LOCK_RE = /\bpackage-lock\.json\b/u;
2174
- function buildPackageLockSummary(value, noOmit = false) {
2175
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
2176
- return [];
2177
- }
2178
- const record = value;
2179
- const packages = typeof record.packages === "object" && record.packages !== null && !Array.isArray(record.packages) ? Object.keys(record.packages) : [];
2180
- const dependencies = typeof record.dependencies === "object" && record.dependencies !== null && !Array.isArray(record.dependencies) ? Object.keys(record.dependencies) : [];
2181
- const lines = [
2182
- "package-lock summary",
2183
- typeof record.name === "string" ? `name: ${record.name}` : null,
2184
- typeof record.version === "string" ? `version: ${record.version}` : null,
2185
- typeof record.lockfileVersion === "number" ? `lockfileVersion: ${record.lockfileVersion}` : null,
2186
- `packages: ${packages.length}`,
2187
- `dependencies: ${dependencies.length}`
2188
- ].filter((line2) => line2 !== null);
2189
- const packageSamples = noOmit ? packages.filter(Boolean) : packages.filter(Boolean).slice(0, 12);
2190
- if (packageSamples.length > 0) {
2191
- lines.push(`sample packages: ${packageSamples.join(", ")}`);
2192
- }
2193
- return lines;
2194
- }
2195
- function buildLargeDocumentSummary(lines, rawText, noOmit = false) {
2196
- const headings = lines.map((line2) => line2.trim()).filter((line2) => /^#{1,6}\s+\S/u.test(line2)).slice(0, 24);
2197
- const excerpt = headTail(lines, 6, 6, noOmit);
2198
- const clippedHeadingCompactions = [];
2199
- const clippedHeadings = headings.map((line2) => {
2200
- const clipped = clipMiddleWithHash(line2, 180, noOmit);
2201
- if (clipped.compaction) {
2202
- clippedHeadingCompactions.push(clipped.compaction);
2203
- }
2204
- return `- ${clipped.text}`;
2205
- });
2206
- const clippedExcerptCompactions = [];
2207
- const excerptLines = excerpt.lines.map((line2) => {
2208
- const clipped = clipMiddleWithHash(line2, 180, noOmit);
2209
- if (clipped.compaction) {
2210
- clippedExcerptCompactions.push(clipped.compaction);
2211
- }
2212
- return clipped.text;
2213
- });
2214
- return {
2215
- lines: [
2216
- `large document summary: ${lines.length} lines, ${countTextChars(rawText)} chars`,
2217
- ...clippedHeadings.length > 0 ? ["headings:", ...clippedHeadings] : [],
2218
- "excerpt:",
2219
- ...excerptLines
2220
- ],
2221
- compaction: mergeCompactionMetadata(
2222
- createCompactionMetadata("inspection-large-document-summary"),
2223
- excerpt.compaction,
2224
- ...clippedHeadingCompactions,
2225
- ...clippedExcerptCompactions
2226
- )
2227
- };
2228
- }
2229
- function isLikelyDocumentLine(line2) {
2230
- const trimmed = line2.trim();
2231
- if (trimmed.length < 50) {
2232
- return false;
2233
- }
2234
- if (/^(?:import|export|const|let|var|function|class|interface|type|return|if|for|while|switch|case|try|catch)\b/u.test(trimmed)) {
2235
- return false;
2236
- }
2237
- if (/^[{}()[\].,;:]/u.test(trimmed) || /[{};]$/u.test(trimmed)) {
2238
- return false;
2239
- }
2240
- return /\s/u.test(trimmed);
2241
- }
2242
- function isLikelyCodeLine(line2) {
2243
- const trimmed = line2.trim();
2244
- if (!trimmed) {
2245
- return false;
2246
- }
2247
- return /^(?:import|export|const|let|var|function|class|interface|type|return|if|for|while|switch|case|try|catch|\}|\{|\)|\])/u.test(trimmed) || /[{};]$/u.test(trimmed);
2248
- }
2249
- function isLargeDocumentOutput(lines, rawChars) {
2250
- if (rawChars < LARGE_INSPECTION_MIN_CHARS) {
2251
- return false;
2252
- }
2253
- if (lines.length < LARGE_INSPECTION_MIN_LINES) {
2254
- return false;
2255
- }
2256
- const nonEmptyLines = lines.filter((line2) => line2.trim() !== "");
2257
- const headingCount = nonEmptyLines.filter((line2) => /^#{1,6}\s+\S/u.test(line2.trim())).length;
2258
- const hasFrontmatter = nonEmptyLines[0]?.trim() === "---" && nonEmptyLines.slice(1, 20).some((line2) => line2.trim() === "---");
2259
- if (headingCount >= 2 || hasFrontmatter && headingCount >= 1) {
2260
- return true;
2118
+ ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
2119
+ ...captureTruncated !== void 0 ? { captureTruncated } : {},
2120
+ ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
2121
+ }
2122
+ };
2123
+ await Promise.all([
2124
+ writeFile2(ref.path, input.rawText, { encoding: "utf8", mode: 384 }),
2125
+ writeFile2(ref.metadataPath, JSON.stringify(artifact.metadata, null, 2), { encoding: "utf8", mode: 384 })
2126
+ ]);
2127
+ if (input.recordStats ?? shouldRecordStats()) {
2128
+ await appendMetadataEvent(id, artifact.metadata, input.input, true, storeDir).catch(() => void 0);
2261
2129
  }
2262
- const documentLines = nonEmptyLines.filter(isLikelyDocumentLine).length;
2263
- const codeLines = nonEmptyLines.filter(isLikelyCodeLine).length;
2264
- return documentLines >= 20 && documentLines / nonEmptyLines.length >= 0.5 && codeLines / nonEmptyLines.length < 0.25;
2130
+ return ref;
2265
2131
  }
2266
- function buildInspectionSummary(input, rawText, noOmit = false) {
2267
- const command = input.command ?? "";
2268
- if (PACKAGE_LOCK_RE.test(command)) {
2269
- const lines2 = buildPackageLockSummary(parseJsonValue(rawText), noOmit);
2270
- return lines2.length > 0 ? { lines: lines2, matchedReducer: "generic/package-lock-summary", compaction: createCompactionMetadata("inspection-package-lock-summary") } : null;
2271
- }
2272
- const rawChars = countTextChars(rawText);
2273
- const lines = trimEmptyEdges(normalizeLines(stripAnsi(rawText)));
2274
- if (!isFileContentInspectionCommand(input) || !isLargeDocumentOutput(lines, rawChars)) {
2275
- return null;
2132
+ async function storeArtifactMetadata(input, storeDir) {
2133
+ const id = `tj_${randomUUID2().slice(0, 12)}`;
2134
+ const captureTruncated = extractCaptureTruncatedFlag(input.input);
2135
+ const metadata = {
2136
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2137
+ source: resolveArtifactSource(input.input),
2138
+ classification: input.classification,
2139
+ rawChars: input.stats?.rawChars ?? countTextChars(stripAnsi(input.rawText)),
2140
+ ...input.input.toolName ? { toolName: input.input.toolName } : {},
2141
+ ...input.input.command ? { command: input.input.command } : {},
2142
+ ...typeof input.input.exitCode === "number" ? { exitCode: input.input.exitCode } : {},
2143
+ ...captureTruncated !== void 0 ? { captureTruncated } : {},
2144
+ ...input.stats ? { reducedChars: input.stats.reducedChars, ratio: input.stats.ratio } : {}
2145
+ };
2146
+ const telemetryMetadata = buildTelemetryMetadata(metadata, input.input);
2147
+ const metadataPath = await appendMetadataEvent(id, telemetryMetadata, input.input, false, storeDir);
2148
+ if (!metadataPath) {
2149
+ throw Object.assign(new Error("metadata segment is full or busy"), { code: "EFBIG" });
2276
2150
  }
2277
- const summary = buildLargeDocumentSummary(lines, rawText, noOmit);
2278
2151
  return {
2279
- lines: summary.lines,
2280
- matchedReducer: "generic/large-document-summary",
2281
- compaction: summary.compaction
2152
+ id,
2153
+ storage: "file",
2154
+ metadataPath,
2155
+ metadataFormat: "jsonl-segment",
2156
+ metadataRecordId: id,
2157
+ metadata: telemetryMetadata
2282
2158
  };
2283
2159
  }
2160
+ async function tryStoreArtifactMetadata(input, storeDir) {
2161
+ try {
2162
+ return await storeArtifactMetadata(input, storeDir);
2163
+ } catch (error) {
2164
+ const code = error.code;
2165
+ if (typeof code !== "string" || !OPTIONAL_METADATA_STORAGE_ERROR_CODES.has(code)) {
2166
+ throw error;
2167
+ }
2168
+ return void 0;
2169
+ }
2170
+ }
2284
2171
 
2285
2172
  // src/core/rules.ts
2286
2173
  import { readdir as readdir2, readFile as readFile3, realpath } from "node:fs/promises";
@@ -8230,6 +8117,115 @@ function buildGithubActionsFailureSummary(input, rawText, noOmit = false) {
8230
8117
  };
8231
8118
  }
8232
8119
 
8120
+ // src/core/reduce-utils.ts
8121
+ import { createHash as createHash2 } from "node:crypto";
8122
+ function compactWhitespace(text) {
8123
+ return text.replace(/\s+/gu, " ").trim();
8124
+ }
8125
+ function shortHash(text) {
8126
+ return createHash2("sha256").update(text).digest("hex").slice(0, 12);
8127
+ }
8128
+ function clipMiddleWithHashStrict(text, maxChars, noOmit = false) {
8129
+ if (countTextChars(text) <= maxChars) {
8130
+ return { text };
8131
+ }
8132
+ if (noOmit) {
8133
+ return {
8134
+ text,
8135
+ compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough")
8136
+ };
8137
+ }
8138
+ const omitted = countTextChars(text) - maxChars;
8139
+ const marker = `...[${omitted} chars omitted, sha256:${shortHash(text)}]...`;
8140
+ const markerChars = countTextChars(marker);
8141
+ if (maxChars <= markerChars) {
8142
+ return {
8143
+ text: sliceTextChars(marker, 0, maxChars),
8144
+ compaction: createCompactionMetadata("hashed-middle-clip")
8145
+ };
8146
+ }
8147
+ const bodyChars = maxChars - markerChars;
8148
+ const headChars = Math.ceil(bodyChars * 0.7);
8149
+ const tailChars = Math.max(0, bodyChars - headChars);
8150
+ return {
8151
+ text: `${sliceTextChars(text, 0, headChars)}${marker}${tailChars > 0 ? sliceTextChars(text, -tailChars) : ""}`,
8152
+ compaction: createCompactionMetadata("hashed-middle-clip")
8153
+ };
8154
+ }
8155
+ function minifyJsonLexically(rawText) {
8156
+ const text = rawText.trim();
8157
+ let output = "";
8158
+ let inString = false;
8159
+ let escaped = false;
8160
+ for (const char of text) {
8161
+ if (inString) {
8162
+ output += char;
8163
+ if (escaped) {
8164
+ escaped = false;
8165
+ } else if (char === "\\") {
8166
+ escaped = true;
8167
+ } else if (char === '"') {
8168
+ inString = false;
8169
+ }
8170
+ continue;
8171
+ }
8172
+ if (char === '"') {
8173
+ inString = true;
8174
+ output += char;
8175
+ continue;
8176
+ }
8177
+ if (/\s/u.test(char)) {
8178
+ continue;
8179
+ }
8180
+ output += char;
8181
+ }
8182
+ return output;
8183
+ }
8184
+ function clipMiddleWithHash(text, maxChars, noOmit = false) {
8185
+ if (countTextChars(text) <= maxChars) {
8186
+ return { text };
8187
+ }
8188
+ if (noOmit) {
8189
+ return {
8190
+ text,
8191
+ compaction: createPassthroughCompactionMetadata("no-omit-char-clip-passthrough")
8192
+ };
8193
+ }
8194
+ const omitted = countTextChars(text) - maxChars;
8195
+ const headChars = Math.max(20, Math.floor(maxChars * 0.55));
8196
+ const tailChars = Math.max(20, maxChars - headChars);
8197
+ return {
8198
+ text: `${sliceTextChars(text, 0, headChars)} ...[${omitted} chars omitted, sha256:${shortHash(text)}]... ${sliceTextChars(text, -tailChars)}`,
8199
+ compaction: createCompactionMetadata("hashed-middle-clip")
8200
+ };
8201
+ }
8202
+ function compactWholeJsonText(rawText, maxChars, noOmit = false) {
8203
+ return parseJsonValue(rawText) === null ? null : clipMiddleWithHashStrict(minifyJsonLexically(rawText), maxChars, noOmit);
8204
+ }
8205
+ function parseJsonObjectLine(line2) {
8206
+ const trimmed = line2.trim();
8207
+ if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
8208
+ return null;
8209
+ }
8210
+ try {
8211
+ const parsed = JSON.parse(trimmed);
8212
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : null;
8213
+ } catch {
8214
+ return null;
8215
+ }
8216
+ }
8217
+ function parseJsonValue(text) {
8218
+ const trimmed = text.trim();
8219
+ if (!(trimmed.startsWith("{") || trimmed.startsWith("["))) {
8220
+ return null;
8221
+ }
8222
+ try {
8223
+ return JSON.parse(trimmed);
8224
+ } catch {
8225
+ return null;
8226
+ }
8227
+ }
8228
+
8233
8229
  // src/core/reduce-formatters.ts
8234
8230
  var LONG_SEARCH_LINE_MAX_CHARS = 420;
8235
8231
  var LONG_CHANGED_LINE_MAX_CHARS = 260;
@@ -8803,6 +8799,38 @@ function isGithubCliCommand(command) {
8803
8799
  return command === "gh" || command === "ghx";
8804
8800
  }
8805
8801
 
8802
+ // src/core/reduce-inspection-summary.ts
8803
+ var PACKAGE_LOCK_RE = /\bpackage-lock\.json\b/u;
8804
+ function buildPackageLockSummary(value, noOmit = false) {
8805
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
8806
+ return [];
8807
+ }
8808
+ const record = value;
8809
+ const packages = typeof record.packages === "object" && record.packages !== null && !Array.isArray(record.packages) ? Object.keys(record.packages) : [];
8810
+ const dependencies = typeof record.dependencies === "object" && record.dependencies !== null && !Array.isArray(record.dependencies) ? Object.keys(record.dependencies) : [];
8811
+ const lines = [
8812
+ "package-lock summary",
8813
+ typeof record.name === "string" ? `name: ${record.name}` : null,
8814
+ typeof record.version === "string" ? `version: ${record.version}` : null,
8815
+ typeof record.lockfileVersion === "number" ? `lockfileVersion: ${record.lockfileVersion}` : null,
8816
+ `packages: ${packages.length}`,
8817
+ `dependencies: ${dependencies.length}`
8818
+ ].filter((line2) => line2 !== null);
8819
+ const packageSamples = noOmit ? packages.filter(Boolean) : packages.filter(Boolean).slice(0, 12);
8820
+ if (packageSamples.length > 0) {
8821
+ lines.push(`sample packages: ${packageSamples.join(", ")}`);
8822
+ }
8823
+ return lines;
8824
+ }
8825
+ function buildInspectionSummary(input, rawText, noOmit = false) {
8826
+ const command = input.command ?? "";
8827
+ if (!PACKAGE_LOCK_RE.test(command)) {
8828
+ return null;
8829
+ }
8830
+ const lines = buildPackageLockSummary(parseJsonValue(rawText), noOmit);
8831
+ return lines.length > 0 ? { lines, matchedReducer: "generic/package-lock-summary", compaction: createCompactionMetadata("inspection-package-lock-summary") } : null;
8832
+ }
8833
+
8806
8834
  // src/core/reduce.ts
8807
8835
  var TINY_OUTPUT_MAX_CHARS = 240;
8808
8836
  var SMALL_OUTPUT_PASSTHROUGH_MIN_SAVED_CHARS = 120;
@@ -9364,12 +9392,133 @@ function resolveInspectionPolicy(input) {
9364
9392
  }
9365
9393
  function getOutputAwareInspectionSkipReason(policy, executionInput) {
9366
9394
  const command = executionInput.command ?? "";
9367
- const rawText = executionInput.combinedText ?? "";
9368
- const inspectionSkipReason = getInspectionCommandSkipReason(command, policy);
9369
- if (inspectionSkipReason === "file-content-inspection-command" && buildInspectionSummary(executionInput, rawText)) {
9395
+ return getInspectionCommandSkipReason(command, policy);
9396
+ }
9397
+ var SIMPLE_COMMAND_WRAPPERS = /* @__PURE__ */ new Set(["nohup", "builtin", "exec", "noglob", "nocorrect"]);
9398
+ function getWrappedCommandArgv(argv) {
9399
+ const wrapper = getCommandName(argv);
9400
+ if (wrapper && SIMPLE_COMMAND_WRAPPERS.has(wrapper)) {
9401
+ return argv.slice(1);
9402
+ }
9403
+ if (wrapper === "uv" && argv[1] === "run") {
9404
+ return argv.slice(2);
9405
+ }
9406
+ if (wrapper === "command") {
9407
+ let commandIndex = 1;
9408
+ while (commandIndex < argv.length) {
9409
+ const arg = argv[commandIndex];
9410
+ if (arg === "-v" || arg === "-V") {
9411
+ return null;
9412
+ }
9413
+ if (arg === "-p") {
9414
+ commandIndex += 1;
9415
+ continue;
9416
+ }
9417
+ if (arg === "--") {
9418
+ commandIndex += 1;
9419
+ }
9420
+ break;
9421
+ }
9422
+ return argv.slice(commandIndex);
9423
+ }
9424
+ let index = 1;
9425
+ if (wrapper === "timeout") {
9426
+ while (index < argv.length) {
9427
+ const arg = argv[index] ?? "";
9428
+ if (["-s", "-k", "--signal", "--kill-after"].includes(arg)) {
9429
+ index += 2;
9430
+ } else if (["--preserve-status", "--foreground", "-v", "--verbose"].includes(arg) || arg.length > 2 && (arg.startsWith("-s") || arg.startsWith("-k")) || arg.startsWith("--signal=") || arg.startsWith("--kill-after=")) {
9431
+ index += 1;
9432
+ } else if (arg === "--") {
9433
+ return index + 1 < argv.length ? argv.slice(index + 2) : null;
9434
+ } else {
9435
+ return argv.slice(index + 1);
9436
+ }
9437
+ }
9370
9438
  return null;
9371
9439
  }
9372
- return inspectionSkipReason;
9440
+ if (wrapper === "nice" || wrapper === "time") {
9441
+ const valueOptions = wrapper === "nice" ? ["-n", "--adjustment"] : ["-f", "-o", "--format", "--output"];
9442
+ const flagOptions = wrapper === "nice" ? [] : ["-p", "-a", "-v", "--append", "--verbose", "--portability", "--quiet"];
9443
+ while (index < argv.length) {
9444
+ const arg = argv[index] ?? "";
9445
+ if (valueOptions.includes(arg)) {
9446
+ index += 2;
9447
+ } else if (flagOptions.includes(arg) || wrapper === "nice" && (/^-\d+$/u.test(arg) || arg.startsWith("-n") && arg.length > 2 || arg.startsWith("--adjustment=")) || wrapper === "time" && ((arg.startsWith("-f") || arg.startsWith("-o")) && arg.length > 2 || arg.startsWith("--format=") || arg.startsWith("--output="))) {
9448
+ index += 1;
9449
+ } else if (arg === "--") {
9450
+ return argv.slice(index + 1);
9451
+ } else {
9452
+ return argv.slice(index);
9453
+ }
9454
+ }
9455
+ }
9456
+ return null;
9457
+ }
9458
+ var WINDOWS_EXECUTABLE_SUFFIXES = [".exe", ".cmd", ".bat", ".com"];
9459
+ function normalizeSkipCommandName(name) {
9460
+ let normalized = name.trim().toLowerCase();
9461
+ for (const suffix of WINDOWS_EXECUTABLE_SUFFIXES) {
9462
+ if (normalized.endsWith(suffix)) {
9463
+ normalized = normalized.slice(0, -suffix.length);
9464
+ break;
9465
+ }
9466
+ }
9467
+ return normalized;
9468
+ }
9469
+ function shouldSkipCommand(command, skipCommandNames) {
9470
+ if (!skipCommandNames?.length) {
9471
+ return false;
9472
+ }
9473
+ let candidate = command;
9474
+ let argv = [];
9475
+ for (let iteration = 0; iteration < 10; iteration += 1) {
9476
+ if (candidate) {
9477
+ candidate = stripLeadingCdPrefix(candidate);
9478
+ const effectiveArgv = getEffectiveCommandArgv({ command: candidate });
9479
+ argv = effectiveArgv.length > 0 ? effectiveArgv : stripLeadingEnvAssignments(tokenizeCommand(candidate));
9480
+ candidate = "";
9481
+ }
9482
+ const shellBody = unwrapShellRunner({ argv });
9483
+ if (shellBody) {
9484
+ candidate = shellBody;
9485
+ continue;
9486
+ }
9487
+ const commandName = getCommandName(argv);
9488
+ if (commandName && skipCommandNames.some(
9489
+ (skipName) => normalizeSkipCommandName(skipName) === normalizeSkipCommandName(commandName)
9490
+ )) {
9491
+ return true;
9492
+ }
9493
+ const wrappedArgv = getWrappedCommandArgv(argv);
9494
+ if (!wrappedArgv?.length) {
9495
+ return false;
9496
+ }
9497
+ argv = wrappedArgv;
9498
+ }
9499
+ return false;
9500
+ }
9501
+ function commandRequestsRawBypass(command) {
9502
+ let argv = getEffectiveCommandArgv({ command: stripLeadingCdPrefix(command) });
9503
+ for (let depth = 0; depth < 16; depth++) {
9504
+ const shellBody = unwrapShellRunner({ argv });
9505
+ if (shellBody) {
9506
+ argv = getEffectiveCommandArgv({ command: shellBody });
9507
+ continue;
9508
+ }
9509
+ const name = getCommandName(argv)?.toLowerCase();
9510
+ const wrapIndex = name && /^tokenjuice(?:\.(?:exe|cmd|bat))?$/u.test(name) ? 1 : name && /^node(?:\.exe)?$/u.test(name) && argv[1]?.endsWith(".js") && argv[1].includes("tokenjuice") ? 2 : -1;
9511
+ if (wrapIndex !== -1 && argv[wrapIndex] === "wrap") {
9512
+ const end = argv.indexOf("--", wrapIndex + 1);
9513
+ if (end === -1) return false;
9514
+ const options = argv.slice(wrapIndex + 1, end);
9515
+ return options.includes("--raw") || options.includes("--full");
9516
+ }
9517
+ const wrapped = getWrappedCommandArgv(argv);
9518
+ if (!wrapped?.length) return false;
9519
+ argv = wrapped;
9520
+ }
9521
+ return false;
9373
9522
  }
9374
9523
  async function compactBashResult(input) {
9375
9524
  const command = input.command.trim();
@@ -9391,6 +9540,9 @@ async function compactBashResult(input) {
9391
9540
  usedTrustedFullText
9392
9541
  };
9393
9542
  }
9543
+ if (commandRequestsRawBypass(command)) {
9544
+ return { action: "keep", reason: "raw-bypass", rawText, usedTrustedFullText };
9545
+ }
9394
9546
  const safeInventoryArgv = getSafeRepositoryInventorySourceArgv(command);
9395
9547
  const executionInput = {
9396
9548
  toolName: "exec",
@@ -9401,6 +9553,14 @@ async function compactBashResult(input) {
9401
9553
  ...typeof input.exitCode === "number" ? { exitCode: input.exitCode } : {},
9402
9554
  ...input.metadata ? { metadata: input.metadata } : {}
9403
9555
  };
9556
+ if (shouldSkipCommand(command, input.skipCommandNames)) {
9557
+ return {
9558
+ action: "keep",
9559
+ reason: "configured-command",
9560
+ rawText,
9561
+ usedTrustedFullText
9562
+ };
9563
+ }
9404
9564
  const inspectionSkipReason = getOutputAwareInspectionSkipReason(resolveInspectionPolicy(input), executionInput);
9405
9565
  if (inspectionSkipReason) {
9406
9566
  return {
@@ -9410,12 +9570,19 @@ async function compactBashResult(input) {
9410
9570
  usedTrustedFullText
9411
9571
  };
9412
9572
  }
9573
+ const storeDir = typeof input.storeDir === "string" && input.storeDir.trim() ? input.storeDir.trim() : void 0;
9574
+ const recordStats = input.recordStats ?? shouldRecordStats();
9413
9575
  const options = {
9414
9576
  ...typeof input.cwd === "string" && input.cwd.trim() ? { cwd: input.cwd } : {},
9415
9577
  ...typeof input.maxInlineChars === "number" ? { maxInlineChars: input.maxInlineChars } : {},
9416
9578
  ...input.noOmit || !input.allowOmit && readNoOmissionFromEnv() ? { noOmit: true } : {},
9417
- recordStats: input.recordStats ?? shouldRecordStats(),
9418
- ...input.storeRaw ? { store: true } : {}
9579
+ // store:true inside reduceExecution writes before this function can keep the output, so a
9580
+ // storeRaw caller stores below, only after the rewrite decision. A keep from a storeRaw
9581
+ // caller then leaves no raw file and no stats entry: recordStats stays off for that call
9582
+ // as well. Callers without storeRaw keep the stats policy unchanged: an explicit
9583
+ // input.recordStats wins, otherwise stats are on unless TOKENJUICE_STATS disables them.
9584
+ recordStats: input.storeRaw ? false : recordStats,
9585
+ ...storeDir ? { storeDir } : {}
9419
9586
  };
9420
9587
  const result = await reduceExecution(executionInput, options);
9421
9588
  const skipReason = getCompactionSkipReason(command, rawText, result, input);
@@ -9428,11 +9595,32 @@ async function compactBashResult(input) {
9428
9595
  result
9429
9596
  };
9430
9597
  }
9598
+ if (!input.storeRaw) {
9599
+ return {
9600
+ action: "rewrite",
9601
+ rawText,
9602
+ usedTrustedFullText,
9603
+ result
9604
+ };
9605
+ }
9606
+ const rawRef = await storeArtifact(
9607
+ {
9608
+ input: executionInput,
9609
+ rawText,
9610
+ classification: result.classification,
9611
+ stats: result.stats,
9612
+ recordStats
9613
+ },
9614
+ storeDir
9615
+ );
9431
9616
  return {
9432
9617
  action: "rewrite",
9433
9618
  rawText,
9434
9619
  usedTrustedFullText,
9435
- result
9620
+ result: {
9621
+ ...result,
9622
+ rawRef
9623
+ }
9436
9624
  };
9437
9625
  }
9438
9626
 
@@ -9694,17 +9882,8 @@ function createTokenjuicePiExtension(config) {
9694
9882
  return ctx.sessionManager.getHeader?.()?.cwd || ctx.sessionManager.getCwd?.() || ctx.cwd;
9695
9883
  }
9696
9884
  async function loadFullOutputText(fullOutputPath) {
9697
- let details;
9698
- try {
9699
- details = await stat2(fullOutputPath);
9700
- } catch (error) {
9701
- throw new Error(`tokenjuice failed to stat bash full output file ${fullOutputPath}: ${formatErrorMessage(error)}`);
9702
- }
9703
- if (details.size > MAX_TRUSTED_FULL_OUTPUT_BYTES) {
9704
- return null;
9705
- }
9706
9885
  try {
9707
- return await readFile4(fullOutputPath, "utf8");
9886
+ return await readBoundedTextFile(fullOutputPath, MAX_TRUSTED_FULL_OUTPUT_BYTES);
9708
9887
  } catch (error) {
9709
9888
  throw new Error(`tokenjuice failed to read bash full output file ${fullOutputPath}: ${formatErrorMessage(error)}`);
9710
9889
  }
@@ -9788,6 +9967,9 @@ function createTokenjuicePiExtension(config) {
9788
9967
  if (!enabled || !autoCompactEnabled || !command) {
9789
9968
  return void 0;
9790
9969
  }
9970
+ if (shouldSkipCommand(command, config.skipCommandNames)) {
9971
+ return void 0;
9972
+ }
9791
9973
  const outputText = extractTextContent(event.content);
9792
9974
  if (!outputText.trim()) {
9793
9975
  return void 0;
@@ -9816,6 +9998,7 @@ function createTokenjuicePiExtension(config) {
9816
9998
  if (fullOutputPath && trustedFullOutputText === null) {
9817
9999
  return void 0;
9818
10000
  }
10001
+ const artifactDir = process.env.TOKENJUICE_ARTIFACT_DIR?.trim();
9819
10002
  let outcome;
9820
10003
  try {
9821
10004
  outcome = await compactBashResult({
@@ -9831,6 +10014,9 @@ function createTokenjuicePiExtension(config) {
9831
10014
  genericFallbackMinSavedChars: GENERIC_FALLBACK_MIN_SAVED_CHARS,
9832
10015
  genericFallbackMaxRatio: GENERIC_FALLBACK_MAX_RATIO,
9833
10016
  skipGenericFallbackForCompoundCommands: true,
10017
+ storeRaw: true,
10018
+ ...artifactDir ? { storeDir: artifactDir } : {},
10019
+ ...config.skipCommandNames ? { skipCommandNames: config.skipCommandNames } : {},
9834
10020
  metadata: {
9835
10021
  source: "pi-tool-result"
9836
10022
  }