@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,119 +1,22 @@
1
- import { lstat, realpath, stat } from "node:fs/promises";
2
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
- import { collectMarkerDelimitedBlockIssues, inspectMarkerDelimitedBlock, installMarkerDelimitedBlock, uninstallMarkerDelimitedBlock, } from "../shared/marker-instructions.js";
4
- import { buildTokenjuiceGuidanceBullets, TOKENJUICE_FULL_COMMAND, TOKENJUICE_RAW_COMMAND, TOKENJUICE_WRAP_COMMAND, } from "../shared/instruction-guidance.js";
5
- import { buildInstructionDoctorReportFields, instructionDoctorStatusFromIssues, } from "../shared/instruction-doctor.js";
6
- import { collectGuidanceIssues, readInstructionFile } from "../shared/instruction-file.js";
1
+ import { realpath } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { inspectMarkerInstructionDoctor } from "../shared/marker-instruction-doctor.js";
4
+ import { createProjectInstructionPathResolver, createSymlinkGuard } from "../shared/path-ancestors.js";
5
+ import { createProjectDirResolver } from "../shared/project-root.js";
6
+ import { createMarkerInstructionCommands, } from "../shared/marker-instructions.js";
7
+ import { buildTokenjuiceGuidanceBullets } from "../shared/instruction-guidance.js";
8
+ import { buildInstructionDoctorReportFields, } from "../shared/instruction-doctor.js";
7
9
  const TOKENJUICE_KNOWNS_FIX_COMMAND = "tokenjuice install knowns";
8
10
  const TOKENJUICE_KNOWNS_BEGIN = "<!-- tokenjuice:knowns begin -->";
9
11
  const TOKENJUICE_KNOWNS_END = "<!-- tokenjuice:knowns end -->";
10
12
  const TOKENJUICE_KNOWNS_ADVISORY = "Knowns support is beta and instruction-based; Knowns generates KNOWNS.md guidance and exposes memory, tasks, docs, and code intelligence through MCP, but tokenjuice does not intercept tool output.";
11
- function getExplicitProjectDir(options = {}) {
12
- return options.projectDir || process.env.KNOWNS_PROJECT_DIR;
13
- }
14
- async function hasGitMetadata(dir) {
15
- try {
16
- await stat(join(dir, ".git"));
17
- return true;
18
- }
19
- catch {
20
- return false;
21
- }
22
- }
23
- async function findGitRoot(startDir) {
24
- let current = resolve(startDir);
25
- while (true) {
26
- if (await hasGitMetadata(current)) {
27
- return current;
28
- }
29
- const parent = dirname(current);
30
- if (parent === current) {
31
- return undefined;
32
- }
33
- current = parent;
34
- }
35
- }
36
- async function resolveProjectDir(options = {}) {
37
- const explicitProjectDir = getExplicitProjectDir(options);
38
- if (explicitProjectDir) {
39
- return resolve(explicitProjectDir);
40
- }
41
- return (await findGitRoot(process.cwd())) ?? process.cwd();
42
- }
43
- function isInsideOrEqual(parentDir, childPath) {
44
- const relativePath = relative(parentDir, childPath);
45
- return relativePath === "" || (!relativePath.startsWith("..") && !isAbsolute(relativePath));
46
- }
47
- async function realpathExistingAncestor(path) {
48
- let current = path;
49
- while (true) {
50
- try {
51
- return await realpath(current);
52
- }
53
- catch (error) {
54
- if (error.code !== "ENOENT") {
55
- throw error;
56
- }
57
- const parent = dirname(current);
58
- if (parent === current) {
59
- throw error;
60
- }
61
- current = parent;
62
- }
63
- }
64
- }
65
- async function rejectInstructionSymlink(filePath) {
66
- try {
67
- const stats = await lstat(filePath);
68
- if (stats.isSymbolicLink()) {
69
- throw new Error(`cannot use Knowns instructions ${filePath}; tokenjuice will not read or write through instruction symlinks`);
70
- }
71
- }
72
- catch (error) {
73
- if (error.code === "ENOENT") {
74
- return;
75
- }
76
- throw error;
77
- }
78
- }
13
+ const resolveProjectDir = createProjectDirResolver("KNOWNS_PROJECT_DIR");
14
+ const rejectInstructionSymlink = createSymlinkGuard((filePath) => `cannot use Knowns instructions ${filePath}; tokenjuice will not read or write through instruction symlinks`);
79
15
  async function rejectInstallSidecarSymlinks(filePath) {
80
16
  await rejectInstructionSymlink(`${filePath}.bak`);
81
17
  await rejectInstructionSymlink(`${filePath}.tmp`);
82
18
  }
83
- async function rejectSymlinkPathComponents(filePath, projectDir) {
84
- const relativePath = relative(projectDir, filePath);
85
- const segments = relativePath.split(sep).filter(Boolean);
86
- let currentPath = projectDir;
87
- for (const segment of segments.slice(0, -1)) {
88
- currentPath = join(currentPath, segment);
89
- try {
90
- const stats = await lstat(currentPath);
91
- if (stats.isSymbolicLink()) {
92
- throw new Error(`cannot use Knowns instructions ${filePath}; tokenjuice will not read or write through instruction symlinks`);
93
- }
94
- }
95
- catch (error) {
96
- if (error.code === "ENOENT") {
97
- return;
98
- }
99
- throw error;
100
- }
101
- }
102
- }
103
- async function resolveSafeProjectInstructionsPath(filePath, projectDir, realProjectDir = projectDir) {
104
- const resolvedPath = resolve(filePath);
105
- if (projectDir !== realProjectDir) {
106
- throw new Error(`cannot use Knowns instructions ${resolvedPath}; tokenjuice will not read or write through instruction symlinks`);
107
- }
108
- const realParentDir = await realpathExistingAncestor(dirname(resolvedPath));
109
- if (!isInsideOrEqual(realProjectDir, realParentDir)) {
110
- throw new Error(`cannot use Knowns instructions ${resolvedPath}; tokenjuice will not write through instruction directories outside ${realProjectDir}`);
111
- }
112
- await rejectInstructionSymlink(projectDir);
113
- await rejectSymlinkPathComponents(resolvedPath, projectDir);
114
- await rejectInstructionSymlink(resolvedPath);
115
- return resolvedPath;
116
- }
19
+ const resolveSafeProjectInstructionsPath = createProjectInstructionPathResolver("Knowns instructions", rejectInstructionSymlink);
117
20
  async function getDefaultInstructionsPath(options = {}) {
118
21
  const projectDir = await resolveProjectDir(options);
119
22
  const realProjectDir = await realpath(projectDir).catch(() => projectDir);
@@ -146,48 +49,15 @@ const TOKENJUICE_KNOWNS_BLOCK_CONFIG = {
146
49
  block: TOKENJUICE_KNOWNS_BLOCK,
147
50
  preserveSurroundingText: true,
148
51
  };
149
- function getTokenjuiceBlockText(text) {
150
- const beginIndex = text.indexOf(TOKENJUICE_KNOWNS_BEGIN);
151
- if (beginIndex === -1) {
152
- return "";
153
- }
154
- const endIndex = text.indexOf(TOKENJUICE_KNOWNS_END, beginIndex + TOKENJUICE_KNOWNS_BEGIN.length);
155
- if (endIndex === -1) {
156
- return text.slice(beginIndex);
157
- }
158
- return text.slice(beginIndex, endIndex + TOKENJUICE_KNOWNS_END.length);
159
- }
160
- function countMarker(text, marker) {
161
- return text.split(marker).length - 1;
162
- }
163
- function hasMalformedMarkerStructure(text, completeBlockCount) {
164
- const beginCount = countMarker(text, TOKENJUICE_KNOWNS_BEGIN);
165
- const endCount = countMarker(text, TOKENJUICE_KNOWNS_END);
166
- return beginCount !== endCount || beginCount !== completeBlockCount || endCount !== completeBlockCount;
167
- }
52
+ const markerInstructions = createMarkerInstructionCommands("knowns", TOKENJUICE_KNOWNS_BLOCK_CONFIG);
168
53
  export async function installKnownsInstructions(instructionsPath, options = {}) {
169
54
  const resolvedInstructionsPath = await resolveInstructionsPath(instructionsPath, options);
170
55
  await rejectInstallSidecarSymlinks(resolvedInstructionsPath);
171
- const existing = await readInstructionFile(resolvedInstructionsPath);
172
- const markerState = inspectMarkerDelimitedBlock(existing.text, TOKENJUICE_KNOWNS_BLOCK_CONFIG);
173
- if (existing.exists && hasMalformedMarkerStructure(existing.text, markerState.completeBlockCount)) {
174
- throw new Error(`cannot safely repair malformed tokenjuice markers in ${resolvedInstructionsPath}; remove the dangling marker manually, then rerun tokenjuice install knowns`);
175
- }
176
- const result = await installMarkerDelimitedBlock(resolvedInstructionsPath, TOKENJUICE_KNOWNS_BLOCK_CONFIG);
177
- return {
178
- instructionsPath: result.filePath,
179
- ...(result.backupPath ? { backupPath: result.backupPath } : {}),
180
- };
56
+ return markerInstructions.install(resolvedInstructionsPath);
181
57
  }
182
58
  export async function uninstallKnownsInstructions(instructionsPath, options = {}) {
183
59
  const resolvedInstructionsPath = await resolveInstructionsPath(instructionsPath, options);
184
- const existing = await readInstructionFile(resolvedInstructionsPath);
185
- const markerState = inspectMarkerDelimitedBlock(existing.text, TOKENJUICE_KNOWNS_BLOCK_CONFIG);
186
- if (existing.exists && hasMalformedMarkerStructure(existing.text, markerState.completeBlockCount)) {
187
- throw new Error(`cannot safely uninstall malformed tokenjuice markers in ${resolvedInstructionsPath}; remove the dangling marker manually, then rerun tokenjuice uninstall knowns`);
188
- }
189
- const result = await uninstallMarkerDelimitedBlock(resolvedInstructionsPath, TOKENJUICE_KNOWNS_BLOCK_CONFIG);
190
- return { instructionsPath: result.filePath, removed: result.removed };
60
+ return markerInstructions.uninstall(resolvedInstructionsPath);
191
61
  }
192
62
  export async function doctorKnownsInstructions(instructionsPath, options = {}) {
193
63
  let resolvedInstructionsPath;
@@ -209,65 +79,27 @@ export async function doctorKnownsInstructions(instructionsPath, options = {}) {
209
79
  }),
210
80
  };
211
81
  }
212
- const existing = await readInstructionFile(resolvedInstructionsPath);
213
- const markerState = inspectMarkerDelimitedBlock(existing.text, TOKENJUICE_KNOWNS_BLOCK_CONFIG);
214
- const hasTokenjuiceMarker = markerState.hasBegin || markerState.hasEnd;
215
- if (!existing.exists || (!markerState.hasBegin && !markerState.hasEnd)) {
216
- return {
217
- instructionsPath: resolvedInstructionsPath,
218
- hasTokenjuiceMarker,
219
- ...buildInstructionDoctorReportFields({
220
- status: "disabled",
221
- issues: ["tokenjuice Knowns instructions are not installed"],
222
- advisory: TOKENJUICE_KNOWNS_ADVISORY,
223
- fixCommand: TOKENJUICE_KNOWNS_FIX_COMMAND,
224
- }),
225
- };
226
- }
227
- const markerIssues = collectMarkerDelimitedBlockIssues(markerState, {
82
+ const { report, hasTokenjuiceMarker } = await inspectMarkerInstructionDoctor(resolvedInstructionsPath, TOKENJUICE_KNOWNS_BLOCK_CONFIG, {
228
83
  configuredLabel: "Knowns instructions",
229
- repairCommand: TOKENJUICE_KNOWNS_FIX_COMMAND,
230
- });
231
- const structureIssues = hasMalformedMarkerStructure(existing.text, markerState.completeBlockCount)
232
- ? ["configured Knowns instructions have unmatched tokenjuice markers"]
233
- : [];
234
- const guidanceIssues = collectGuidanceIssues(getTokenjuiceBlockText(existing.text), {
235
- required: [
236
- {
237
- requiredText: "tokenjuice terminal output compaction",
238
- missingIssue: "configured Knowns instructions do not look like the tokenjuice instructions",
239
- },
240
- {
241
- requiredText: TOKENJUICE_WRAP_COMMAND,
242
- missingIssue: "configured Knowns instructions are missing tokenjuice wrap guidance",
243
- },
244
- {
245
- requiredText: TOKENJUICE_RAW_COMMAND,
246
- missingIssue: "configured Knowns instructions are missing the raw escape hatch",
247
- },
248
- {
249
- requiredText: "Knowns uses this KNOWNS.md guidance",
250
- missingIssue: "configured Knowns instructions are missing KNOWNS.md guidance context",
251
- },
252
- ],
253
- forbidden: [
254
- {
255
- forbiddenText: TOKENJUICE_FULL_COMMAND,
256
- presentIssue: "configured Knowns instructions still suggest the full escape hatch",
257
- },
258
- ],
84
+ advisory: TOKENJUICE_KNOWNS_ADVISORY,
85
+ fixCommand: TOKENJUICE_KNOWNS_FIX_COMMAND,
86
+ malformedFixCommand: "remove unmatched tokenjuice markers from KNOWNS.md, then run tokenjuice install knowns",
87
+ malformedMarkerIssue: "configured Knowns instructions have unmatched tokenjuice markers",
88
+ repairOnMarkerIssues: true,
89
+ guidanceOptions: {
90
+ additionalRequired: [
91
+ {
92
+ requiredText: "tokenjuice terminal output compaction",
93
+ missingIssue: "configured Knowns instructions do not look like the tokenjuice instructions",
94
+ },
95
+ ],
96
+ additionalRequiredAfter: [
97
+ {
98
+ requiredText: "Knowns uses this KNOWNS.md guidance",
99
+ missingIssue: "configured Knowns instructions are missing KNOWNS.md guidance context",
100
+ },
101
+ ],
102
+ },
259
103
  });
260
- const issues = [...markerIssues, ...structureIssues, ...guidanceIssues];
261
- return {
262
- instructionsPath: resolvedInstructionsPath,
263
- hasTokenjuiceMarker,
264
- ...buildInstructionDoctorReportFields({
265
- status: instructionDoctorStatusFromIssues(issues),
266
- issues,
267
- advisory: TOKENJUICE_KNOWNS_ADVISORY,
268
- fixCommand: [...markerIssues, ...structureIssues].length > 0
269
- ? "remove unmatched tokenjuice markers from KNOWNS.md, then run tokenjuice install knowns"
270
- : TOKENJUICE_KNOWNS_FIX_COMMAND,
271
- }),
272
- };
104
+ return { instructionsPath: resolvedInstructionsPath, hasTokenjuiceMarker, ...report };
273
105
  }
@@ -1,23 +1,12 @@
1
+ import { type RemoveInstructionFileResult, type WriteInstructionFileResult } from "../shared/instruction-file.js";
2
+ import { type InstructionsDoctorReport } from "../shared/instruction-doctor.js";
1
3
  export type LeanCtlInstructionsOptions = {
2
4
  projectDir?: string;
3
5
  };
4
- export type InstallLeanCtlInstructionsResult = {
5
- instructionsPath: string;
6
- backupPath?: string;
7
- };
8
- export type UninstallLeanCtlInstructionsResult = {
9
- instructionsPath: string;
10
- removed: boolean;
11
- };
12
- export type LeanCtlDoctorReport = {
13
- instructionsPath: string;
6
+ export type InstallLeanCtlInstructionsResult = WriteInstructionFileResult<"instructionsPath">;
7
+ export type UninstallLeanCtlInstructionsResult = RemoveInstructionFileResult<"instructionsPath">;
8
+ export type LeanCtlDoctorReport = InstructionsDoctorReport & {
14
9
  hasTokenjuiceMarker: boolean;
15
- status: "ok" | "warn" | "broken" | "disabled";
16
- issues: string[];
17
- advisories: string[];
18
- fixCommand: string;
19
- checkedPaths: string[];
20
- missingPaths: string[];
21
10
  };
22
11
  export declare function installLeanCtlInstructions(instructionsPath?: string, options?: LeanCtlInstructionsOptions): Promise<InstallLeanCtlInstructionsResult>;
23
12
  export declare function uninstallLeanCtlInstructions(instructionsPath?: string, options?: LeanCtlInstructionsOptions): Promise<UninstallLeanCtlInstructionsResult>;
@@ -1,8 +1,9 @@
1
- import { randomUUID } from "node:crypto";
2
- import { lstat, mkdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
3
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
- import { buildTokenjuiceGuidanceBullets, TOKENJUICE_FULL_COMMAND, TOKENJUICE_RAW_COMMAND, TOKENJUICE_WRAP_COMMAND } from "../shared/instruction-guidance.js";
5
- import { collectGuidanceIssues, readInstructionFile, removeInstructionFile, writeInstructionFile } from "../shared/instruction-file.js";
1
+ import { realpath, rename, rm, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { findAvailableBackupPath, writeTextFileWithoutBackup, readInstructionFile, removeInstructionFile, writeInstructionFile, } from "../shared/instruction-file.js";
4
+ import { createProjectInstructionPathResolver, createSymlinkGuard } from "../shared/path-ancestors.js";
5
+ import { createProjectDirResolver } from "../shared/project-root.js";
6
+ import { collectTokenjuiceGuidanceIssues, buildTokenjuiceGuidanceBullets } from "../shared/instruction-guidance.js";
6
7
  import { buildInstructionDoctorReportFields, instructionDoctorStatusFromIssues, } from "../shared/instruction-doctor.js";
7
8
  const TOKENJUICE_LEANCTL_FIX_COMMAND = "tokenjuice install leanctl";
8
9
  const TOKENJUICE_LEANCTL_OWNERSHIP_MARKER = "<!-- tokenjuice:leanctl-instructions -->";
@@ -16,144 +17,13 @@ function readRestoreBackupSuffix(text) {
16
17
  const match = text.match(/^<!-- tokenjuice:leanctl-restore-backup=(\.bak(?:\.\d+)?) -->$/mu);
17
18
  return match?.[1];
18
19
  }
19
- function getExplicitProjectDir(options = {}) {
20
- return options.projectDir || process.env.LEANCTL_PROJECT_DIR;
21
- }
22
- async function hasGitMetadata(dir) {
23
- try {
24
- await stat(join(dir, ".git"));
25
- return true;
26
- }
27
- catch {
28
- return false;
29
- }
30
- }
31
- async function findGitRoot(startDir) {
32
- let current = resolve(startDir);
33
- while (true) {
34
- if (await hasGitMetadata(current)) {
35
- return current;
36
- }
37
- const parent = dirname(current);
38
- if (parent === current) {
39
- return undefined;
40
- }
41
- current = parent;
42
- }
43
- }
44
- async function resolveProjectDir(options = {}) {
45
- const explicitProjectDir = getExplicitProjectDir(options);
46
- if (explicitProjectDir) {
47
- return resolve(explicitProjectDir);
48
- }
49
- return (await findGitRoot(process.cwd())) ?? process.cwd();
50
- }
51
- function isInsideOrEqual(parentDir, childPath) {
52
- const relativePath = relative(parentDir, childPath);
53
- return relativePath === "" || (!relativePath.startsWith("..") && !isAbsolute(relativePath));
54
- }
55
- async function realpathExistingAncestor(path) {
56
- let current = path;
57
- while (true) {
58
- try {
59
- return await realpath(current);
60
- }
61
- catch (error) {
62
- if (error.code !== "ENOENT") {
63
- throw error;
64
- }
65
- const parent = dirname(current);
66
- if (parent === current) {
67
- throw error;
68
- }
69
- current = parent;
70
- }
71
- }
72
- }
73
- async function rejectInstructionSymlink(filePath) {
74
- try {
75
- const stats = await lstat(filePath);
76
- if (stats.isSymbolicLink()) {
77
- throw new Error(`cannot use LeanCTL instructions ${filePath}; tokenjuice will not read or write through instruction symlinks`);
78
- }
79
- }
80
- catch (error) {
81
- if (error.code === "ENOENT") {
82
- return;
83
- }
84
- throw error;
85
- }
86
- }
20
+ const resolveProjectDir = createProjectDirResolver("LEANCTL_PROJECT_DIR");
21
+ const rejectInstructionSymlink = createSymlinkGuard((filePath) => `cannot use LeanCTL instructions ${filePath}; tokenjuice will not read or write through instruction symlinks`);
87
22
  async function rejectInstallSidecarSymlinks(filePath) {
88
23
  await rejectInstructionSymlink(`${filePath}.bak`);
89
24
  await rejectInstructionSymlink(`${filePath}.tmp`);
90
25
  }
91
- async function backupPathExists(backupPath) {
92
- try {
93
- await lstat(backupPath);
94
- return true;
95
- }
96
- catch (error) {
97
- if (error.code === "ENOENT") {
98
- return false;
99
- }
100
- throw error;
101
- }
102
- }
103
- async function chooseLeanCtlBackupPath(instructionsPath) {
104
- for (let index = 0;; index += 1) {
105
- const candidate = index === 0 ? `${instructionsPath}.bak` : `${instructionsPath}.bak.${index}`;
106
- if (!(await backupPathExists(candidate))) {
107
- return candidate;
108
- }
109
- }
110
- }
111
- async function writeTextFileWithoutBackup(filePath, text) {
112
- await mkdir(dirname(filePath), { recursive: true });
113
- const tempPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
114
- await writeFile(tempPath, text, { encoding: "utf8", flag: "wx" });
115
- try {
116
- await rename(tempPath, filePath);
117
- }
118
- catch (error) {
119
- await rm(tempPath, { force: true });
120
- throw error;
121
- }
122
- }
123
- async function rejectSymlinkPathComponents(filePath, projectDir) {
124
- const relativePath = relative(projectDir, filePath);
125
- const segments = relativePath.split(sep).filter(Boolean);
126
- let currentPath = projectDir;
127
- for (const segment of segments.slice(0, -1)) {
128
- currentPath = join(currentPath, segment);
129
- try {
130
- const stats = await lstat(currentPath);
131
- if (stats.isSymbolicLink()) {
132
- throw new Error(`cannot use LeanCTL instructions ${filePath}; tokenjuice will not read or write through instruction symlinks`);
133
- }
134
- }
135
- catch (error) {
136
- if (error.code === "ENOENT") {
137
- return;
138
- }
139
- throw error;
140
- }
141
- }
142
- }
143
- async function resolveSafeProjectInstructionsPath(filePath, projectDir, realProjectDir = projectDir) {
144
- const resolvedPath = resolve(filePath);
145
- if (projectDir !== realProjectDir) {
146
- throw new Error(`cannot use LeanCTL instructions ${resolvedPath}; tokenjuice will not read or write through instruction symlinks`);
147
- }
148
- const realParentDir = await realpathExistingAncestor(dirname(resolvedPath));
149
- if (!isInsideOrEqual(realProjectDir, realParentDir)) {
150
- throw new Error(`cannot use LeanCTL instructions ${resolvedPath}; tokenjuice will not write through instruction directories outside ${realProjectDir}`);
151
- }
152
- await rejectInstructionSymlink(projectDir);
153
- await rejectSymlinkPathComponents(resolvedPath, projectDir);
154
- await rejectInstructionSymlink(resolvedPath);
155
- return resolvedPath;
156
- }
26
+ const resolveSafeProjectInstructionsPath = createProjectInstructionPathResolver("LeanCTL instructions", rejectInstructionSymlink);
157
27
  async function getDefaultInstructionsPath(options = {}) {
158
28
  const projectDir = await resolveProjectDir(options);
159
29
  const realProjectDir = await realpath(projectDir).catch(() => projectDir);
@@ -200,7 +70,7 @@ export async function installLeanCtlInstructions(instructionsPath, options = {})
200
70
  };
201
71
  }
202
72
  if (existing.exists) {
203
- const backupPath = await chooseLeanCtlBackupPath(resolvedInstructionsPath);
73
+ const backupPath = await findAvailableBackupPath(resolvedInstructionsPath);
204
74
  await writeFile(backupPath, existing.text, { encoding: "utf8", flag: "wx" });
205
75
  await writeTextFileWithoutBackup(resolvedInstructionsPath, buildLeanCtlInstructions({ restoreBackupSuffix: backupPath.slice(resolvedInstructionsPath.length) }));
206
76
  return { instructionsPath: resolvedInstructionsPath, backupPath };
@@ -274,8 +144,9 @@ export async function doctorLeanCtlInstructions(instructionsPath, options = {})
274
144
  }),
275
145
  };
276
146
  }
277
- const issues = collectGuidanceIssues(existing.text, {
278
- required: [
147
+ const issues = collectTokenjuiceGuidanceIssues(existing.text, {
148
+ configuredLabel: "LeanCTL instructions",
149
+ additionalRequired: [
279
150
  {
280
151
  requiredText: TOKENJUICE_LEANCTL_OWNERSHIP_MARKER,
281
152
  missingIssue: "configured LeanCTL instructions are missing the tokenjuice ownership marker",
@@ -284,25 +155,13 @@ export async function doctorLeanCtlInstructions(instructionsPath, options = {})
284
155
  requiredText: TOKENJUICE_LEANCTL_INSTRUCTIONS_MARKER,
285
156
  missingIssue: "configured LeanCTL instructions do not look like the tokenjuice instructions",
286
157
  },
287
- {
288
- requiredText: TOKENJUICE_WRAP_COMMAND,
289
- missingIssue: "configured LeanCTL instructions are missing tokenjuice wrap guidance",
290
- },
291
- {
292
- requiredText: TOKENJUICE_RAW_COMMAND,
293
- missingIssue: "configured LeanCTL instructions are missing the raw escape hatch",
294
- },
158
+ ],
159
+ additionalRequiredAfter: [
295
160
  {
296
161
  requiredText: ".leanctl/instructions.md",
297
162
  missingIssue: "configured LeanCTL instructions are missing project instruction path guidance",
298
163
  },
299
164
  ],
300
- forbidden: [
301
- {
302
- forbiddenText: TOKENJUICE_FULL_COMMAND,
303
- presentIssue: "configured LeanCTL instructions still suggest the full escape hatch",
304
- },
305
- ],
306
165
  });
307
166
  return {
308
167
  instructionsPath: resolvedInstructionsPath,
@@ -1,3 +1,4 @@
1
+ import { type InstructionDoctorReportFields } from "../shared/instruction-doctor.js";
1
2
  export type LocalCodePluginOptions = {
2
3
  homeDir?: string;
3
4
  };
@@ -14,17 +15,11 @@ export type UninstallLocalCodePluginResult = {
14
15
  indexPath: string;
15
16
  removed: boolean;
16
17
  };
17
- export type LocalCodeDoctorReport = {
18
+ export type LocalCodeDoctorReport = InstructionDoctorReportFields & {
18
19
  pluginDir: string;
19
20
  manifestPath: string;
20
21
  indexPath: string;
21
22
  hasTokenjuiceMarker: boolean;
22
- status: "ok" | "broken" | "disabled";
23
- issues: string[];
24
- advisories: string[];
25
- fixCommand: string;
26
- checkedPaths: string[];
27
- missingPaths: string[];
28
23
  };
29
24
  export declare function installLocalCodePlugin(options?: LocalCodePluginOptions): Promise<InstallLocalCodePluginResult>;
30
25
  export declare function uninstallLocalCodePlugin(options?: LocalCodePluginOptions): Promise<UninstallLocalCodePluginResult>;
@@ -1,8 +1,8 @@
1
- import { randomUUID } from "node:crypto";
2
- import { lstat, mkdir, rename, rm, rmdir, writeFile } from "node:fs/promises";
1
+ import { rename, rm, rmdir, writeFile } from "node:fs/promises";
3
2
  import { homedir } from "node:os";
4
- import { dirname, join } from "node:path";
5
- import { collectGuidanceIssues, readInstructionFile, removeInstructionFile, writeInstructionFile } from "../shared/instruction-file.js";
3
+ import { join } from "node:path";
4
+ import { createSymlinkGuard } from "../shared/path-ancestors.js";
5
+ import { findAvailableBackupPath, writeTextFileWithoutBackup, collectGuidanceIssues, readInstructionFile, removeInstructionFile, writeInstructionFile } from "../shared/instruction-file.js";
6
6
  import { buildInstructionDoctorReportFields, instructionDoctorStatusFromIssues, } from "../shared/instruction-doctor.js";
7
7
  import { isRecord } from "../shared/hooks-json-file.js";
8
8
  const TOKENJUICE_LOCALCODE_FIX_COMMAND = "tokenjuice install localcode";
@@ -25,75 +25,17 @@ function getManifestPath(options = {}) {
25
25
  function getIndexPath(options = {}) {
26
26
  return join(getPluginDir(options), "index.js");
27
27
  }
28
- async function rejectPluginDirectorySymlink(pluginDir) {
29
- try {
30
- const stats = await lstat(pluginDir);
31
- if (stats.isSymbolicLink()) {
32
- throw new Error(`cannot use LocalCode plugin directory ${pluginDir}; tokenjuice will not write through plugin directory symlinks`);
33
- }
34
- }
35
- catch (error) {
36
- if (error.code === "ENOENT") {
37
- return;
38
- }
39
- throw error;
40
- }
41
- }
28
+ const rejectPluginDirectorySymlink = createSymlinkGuard((pluginDir) => `cannot use LocalCode plugin directory ${pluginDir}; tokenjuice will not write through plugin directory symlinks`);
42
29
  async function rejectPluginDirectorySymlinks(options = {}) {
43
30
  const localCodeHome = getLocalCodeHome(options);
44
31
  for (const directory of [localCodeHome, join(localCodeHome, "plugins"), getPluginDir(options)]) {
45
32
  await rejectPluginDirectorySymlink(directory);
46
33
  }
47
34
  }
48
- async function rejectPluginFileSymlink(filePath) {
49
- try {
50
- const stats = await lstat(filePath);
51
- if (stats.isSymbolicLink()) {
52
- throw new Error(`cannot use LocalCode plugin file ${filePath}; tokenjuice will not read or write through plugin file symlinks`);
53
- }
54
- }
55
- catch (error) {
56
- if (error.code === "ENOENT") {
57
- return;
58
- }
59
- throw error;
60
- }
61
- }
35
+ const rejectPluginFileSymlink = createSymlinkGuard((filePath) => `cannot use LocalCode plugin file ${filePath}; tokenjuice will not read or write through plugin file symlinks`);
62
36
  async function rejectPluginFileSidecarSymlinks(filePath) {
63
37
  await rejectPluginFileSymlink(`${filePath}.bak`);
64
38
  }
65
- async function backupPathExists(backupPath) {
66
- try {
67
- await lstat(backupPath);
68
- return true;
69
- }
70
- catch (error) {
71
- if (error.code === "ENOENT") {
72
- return false;
73
- }
74
- throw error;
75
- }
76
- }
77
- async function chooseLocalCodeBackupPath(filePath) {
78
- for (let index = 0;; index += 1) {
79
- const candidate = index === 0 ? `${filePath}.bak` : `${filePath}.bak.${index}`;
80
- if (!(await backupPathExists(candidate))) {
81
- return candidate;
82
- }
83
- }
84
- }
85
- async function writeTextFileWithoutBackup(filePath, text) {
86
- await mkdir(dirname(filePath), { recursive: true });
87
- const tempPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
88
- await writeFile(tempPath, text, { encoding: "utf8", flag: "wx" });
89
- try {
90
- await rename(tempPath, filePath);
91
- }
92
- catch (error) {
93
- await rm(tempPath, { force: true });
94
- throw error;
95
- }
96
- }
97
39
  async function readLocalCodePluginFiles(options = {}) {
98
40
  return {
99
41
  manifest: await readInstructionFile(getManifestPath(options)),
@@ -283,10 +225,10 @@ export async function installLocalCodePlugin(options = {}) {
283
225
  if (hasTokenjuiceMarker(existingManifest.text, existingIndex.text)) {
284
226
  const restoreBackups = readRestoreBackups(existingIndex.text);
285
227
  const manifestBackupPath = existingManifest.exists && !existingManifest.text.includes(TOKENJUICE_LOCALCODE_OWNERSHIP_MARKER)
286
- ? await chooseLocalCodeBackupPath(manifestPath)
228
+ ? await findAvailableBackupPath(manifestPath)
287
229
  : undefined;
288
230
  const indexBackupPath = existingIndex.exists && !existingIndex.text.includes(TOKENJUICE_LOCALCODE_OWNERSHIP_MARKER)
289
- ? await chooseLocalCodeBackupPath(indexPath)
231
+ ? await findAvailableBackupPath(indexPath)
290
232
  : undefined;
291
233
  if (manifestBackupPath) {
292
234
  await writeFile(manifestBackupPath, existingManifest.text, { encoding: "utf8", flag: "wx" });
@@ -332,8 +274,8 @@ export async function installLocalCodePlugin(options = {}) {
332
274
  ...(indexBackupPath ? { indexBackupPath } : index.backupPath ? { indexBackupPath: index.backupPath } : {}),
333
275
  };
334
276
  }
335
- const manifestBackupPath = existingManifest.exists ? await chooseLocalCodeBackupPath(manifestPath) : undefined;
336
- const indexBackupPath = existingIndex.exists ? await chooseLocalCodeBackupPath(indexPath) : undefined;
277
+ const manifestBackupPath = existingManifest.exists ? await findAvailableBackupPath(manifestPath) : undefined;
278
+ const indexBackupPath = existingIndex.exists ? await findAvailableBackupPath(indexPath) : undefined;
337
279
  if (manifestBackupPath) {
338
280
  await writeFile(manifestBackupPath, existingManifest.text, { encoding: "utf8", flag: "wx" });
339
281
  }