@mxalbert/context-mode 2.0.0

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 (365) hide show
  1. package/.claude-plugin/marketplace.json +33 -0
  2. package/.claude-plugin/plugin.json +31 -0
  3. package/.codex-plugin/hooks.json +65 -0
  4. package/.codex-plugin/mcp.json +13 -0
  5. package/.codex-plugin/plugin.json +31 -0
  6. package/.openclaw-plugin/index.ts +12 -0
  7. package/.openclaw-plugin/openclaw.plugin.json +38 -0
  8. package/.openclaw-plugin/package.json +28 -0
  9. package/LICENSE +94 -0
  10. package/README.md +1619 -0
  11. package/bin/statusline.mjs +378 -0
  12. package/build/adapters/antigravity/index.d.ts +51 -0
  13. package/build/adapters/antigravity/index.js +169 -0
  14. package/build/adapters/antigravity-cli/index.d.ts +51 -0
  15. package/build/adapters/antigravity-cli/index.js +342 -0
  16. package/build/adapters/base.d.ts +92 -0
  17. package/build/adapters/base.js +135 -0
  18. package/build/adapters/claude-code/config.d.ts +8 -0
  19. package/build/adapters/claude-code/config.js +8 -0
  20. package/build/adapters/claude-code/hooks.d.ts +106 -0
  21. package/build/adapters/claude-code/hooks.js +183 -0
  22. package/build/adapters/claude-code/index.d.ts +80 -0
  23. package/build/adapters/claude-code/index.js +569 -0
  24. package/build/adapters/claude-code-base.d.ts +49 -0
  25. package/build/adapters/claude-code-base.js +113 -0
  26. package/build/adapters/client-map.d.ts +10 -0
  27. package/build/adapters/client-map.js +42 -0
  28. package/build/adapters/codex/config.d.ts +8 -0
  29. package/build/adapters/codex/config.js +8 -0
  30. package/build/adapters/codex/hooks.d.ts +55 -0
  31. package/build/adapters/codex/hooks.js +64 -0
  32. package/build/adapters/codex/index.d.ts +87 -0
  33. package/build/adapters/codex/index.js +995 -0
  34. package/build/adapters/codex/paths.d.ts +1 -0
  35. package/build/adapters/codex/paths.js +12 -0
  36. package/build/adapters/codex/usage.d.ts +107 -0
  37. package/build/adapters/codex/usage.js +227 -0
  38. package/build/adapters/copilot-base.d.ts +94 -0
  39. package/build/adapters/copilot-base.js +297 -0
  40. package/build/adapters/copilot-cli/hooks.d.ts +33 -0
  41. package/build/adapters/copilot-cli/hooks.js +64 -0
  42. package/build/adapters/copilot-cli/index.d.ts +48 -0
  43. package/build/adapters/copilot-cli/index.js +341 -0
  44. package/build/adapters/cursor/config.d.ts +4 -0
  45. package/build/adapters/cursor/config.js +4 -0
  46. package/build/adapters/cursor/hooks.d.ts +55 -0
  47. package/build/adapters/cursor/hooks.js +82 -0
  48. package/build/adapters/cursor/index.d.ts +64 -0
  49. package/build/adapters/cursor/index.js +517 -0
  50. package/build/adapters/detect.d.ts +136 -0
  51. package/build/adapters/detect.js +623 -0
  52. package/build/adapters/gemini-cli/config.d.ts +8 -0
  53. package/build/adapters/gemini-cli/config.js +8 -0
  54. package/build/adapters/gemini-cli/hooks.d.ts +83 -0
  55. package/build/adapters/gemini-cli/hooks.js +115 -0
  56. package/build/adapters/gemini-cli/index.d.ts +80 -0
  57. package/build/adapters/gemini-cli/index.js +483 -0
  58. package/build/adapters/jetbrains-copilot/config.d.ts +8 -0
  59. package/build/adapters/jetbrains-copilot/config.js +8 -0
  60. package/build/adapters/jetbrains-copilot/hooks.d.ts +59 -0
  61. package/build/adapters/jetbrains-copilot/hooks.js +87 -0
  62. package/build/adapters/jetbrains-copilot/index.d.ts +31 -0
  63. package/build/adapters/jetbrains-copilot/index.js +131 -0
  64. package/build/adapters/kimi/config.d.ts +8 -0
  65. package/build/adapters/kimi/config.js +8 -0
  66. package/build/adapters/kimi/hooks.d.ts +28 -0
  67. package/build/adapters/kimi/hooks.js +34 -0
  68. package/build/adapters/kimi/index.d.ts +66 -0
  69. package/build/adapters/kimi/index.js +537 -0
  70. package/build/adapters/kimi/paths.d.ts +21 -0
  71. package/build/adapters/kimi/paths.js +52 -0
  72. package/build/adapters/kimi/usage.d.ts +82 -0
  73. package/build/adapters/kimi/usage.js +217 -0
  74. package/build/adapters/kiro/hooks.d.ts +61 -0
  75. package/build/adapters/kiro/hooks.js +94 -0
  76. package/build/adapters/kiro/index.d.ts +61 -0
  77. package/build/adapters/kiro/index.js +301 -0
  78. package/build/adapters/omp/index.d.ts +65 -0
  79. package/build/adapters/omp/index.js +182 -0
  80. package/build/adapters/omp/plugin.d.ts +81 -0
  81. package/build/adapters/omp/plugin.js +331 -0
  82. package/build/adapters/omp/usage.d.ts +49 -0
  83. package/build/adapters/omp/usage.js +110 -0
  84. package/build/adapters/openclaw/config.d.ts +8 -0
  85. package/build/adapters/openclaw/config.js +8 -0
  86. package/build/adapters/openclaw/hooks.d.ts +50 -0
  87. package/build/adapters/openclaw/hooks.js +61 -0
  88. package/build/adapters/openclaw/index.d.ts +74 -0
  89. package/build/adapters/openclaw/index.js +439 -0
  90. package/build/adapters/openclaw/mcp-tools.d.ts +54 -0
  91. package/build/adapters/openclaw/mcp-tools.js +207 -0
  92. package/build/adapters/openclaw/plugin.d.ts +141 -0
  93. package/build/adapters/openclaw/plugin.js +818 -0
  94. package/build/adapters/openclaw/session-db.d.ts +55 -0
  95. package/build/adapters/openclaw/session-db.js +88 -0
  96. package/build/adapters/openclaw/usage.d.ts +34 -0
  97. package/build/adapters/openclaw/usage.js +52 -0
  98. package/build/adapters/openclaw/workspace-router.d.ts +29 -0
  99. package/build/adapters/openclaw/workspace-router.js +64 -0
  100. package/build/adapters/opencode/config.d.ts +8 -0
  101. package/build/adapters/opencode/config.js +8 -0
  102. package/build/adapters/opencode/hooks.d.ts +38 -0
  103. package/build/adapters/opencode/hooks.js +50 -0
  104. package/build/adapters/opencode/index.d.ts +144 -0
  105. package/build/adapters/opencode/index.js +638 -0
  106. package/build/adapters/opencode/plugin.d.ts +249 -0
  107. package/build/adapters/opencode/plugin.js +1536 -0
  108. package/build/adapters/opencode/v2.d.ts +117 -0
  109. package/build/adapters/opencode/v2.js +224 -0
  110. package/build/adapters/opencode/zod3tov4.d.ts +1 -0
  111. package/build/adapters/opencode/zod3tov4.js +132 -0
  112. package/build/adapters/pi/extension.d.ts +81 -0
  113. package/build/adapters/pi/extension.js +861 -0
  114. package/build/adapters/pi/index.d.ts +57 -0
  115. package/build/adapters/pi/index.js +173 -0
  116. package/build/adapters/pi/mcp-bridge.d.ts +268 -0
  117. package/build/adapters/pi/mcp-bridge.js +894 -0
  118. package/build/adapters/qwen-code/hooks.d.ts +26 -0
  119. package/build/adapters/qwen-code/hooks.js +29 -0
  120. package/build/adapters/qwen-code/index.d.ts +40 -0
  121. package/build/adapters/qwen-code/index.js +361 -0
  122. package/build/adapters/qwen-code/usage.d.ts +90 -0
  123. package/build/adapters/qwen-code/usage.js +222 -0
  124. package/build/adapters/types.d.ts +360 -0
  125. package/build/adapters/types.js +118 -0
  126. package/build/adapters/vscode-copilot/config.d.ts +8 -0
  127. package/build/adapters/vscode-copilot/config.js +8 -0
  128. package/build/adapters/vscode-copilot/hooks.d.ts +71 -0
  129. package/build/adapters/vscode-copilot/hooks.js +98 -0
  130. package/build/adapters/vscode-copilot/index.d.ts +32 -0
  131. package/build/adapters/vscode-copilot/index.js +222 -0
  132. package/build/adapters/zed/index.d.ts +40 -0
  133. package/build/adapters/zed/index.js +163 -0
  134. package/build/cli.d.ts +34 -0
  135. package/build/cli.js +1828 -0
  136. package/build/db-base.d.ts +250 -0
  137. package/build/db-base.js +756 -0
  138. package/build/executor.d.ts +72 -0
  139. package/build/executor.js +678 -0
  140. package/build/exit-classify.d.ts +19 -0
  141. package/build/exit-classify.js +12 -0
  142. package/build/fetch/blocks.d.ts +145 -0
  143. package/build/fetch/blocks.js +244 -0
  144. package/build/fetch/extract.d.ts +68 -0
  145. package/build/fetch/extract.js +123 -0
  146. package/build/fetch/page-store.d.ts +66 -0
  147. package/build/fetch/page-store.js +174 -0
  148. package/build/fetch-cache.d.ts +13 -0
  149. package/build/fetch-cache.js +15 -0
  150. package/build/lifecycle.d.ts +124 -0
  151. package/build/lifecycle.js +278 -0
  152. package/build/package-identity.d.ts +26 -0
  153. package/build/package-identity.js +28 -0
  154. package/build/runPool.d.ts +36 -0
  155. package/build/runPool.js +51 -0
  156. package/build/runtime.d.ts +71 -0
  157. package/build/runtime.js +659 -0
  158. package/build/search/auto-memory.d.ts +47 -0
  159. package/build/search/auto-memory.js +170 -0
  160. package/build/search/ctx-search-schema.d.ts +90 -0
  161. package/build/search/ctx-search-schema.js +135 -0
  162. package/build/search/flood-guard.d.ts +57 -0
  163. package/build/search/flood-guard.js +80 -0
  164. package/build/search/unified.d.ts +56 -0
  165. package/build/search/unified.js +104 -0
  166. package/build/security.d.ts +206 -0
  167. package/build/security.js +780 -0
  168. package/build/server.d.ts +240 -0
  169. package/build/server.js +5034 -0
  170. package/build/session/analytics.d.ts +773 -0
  171. package/build/session/analytics.js +2420 -0
  172. package/build/session/db.d.ts +468 -0
  173. package/build/session/db.js +1330 -0
  174. package/build/session/error-classifier.d.ts +87 -0
  175. package/build/session/error-classifier.js +303 -0
  176. package/build/session/event-emit.d.ts +48 -0
  177. package/build/session/event-emit.js +101 -0
  178. package/build/session/extract.d.ts +333 -0
  179. package/build/session/extract.js +2688 -0
  180. package/build/session/model-prices.json +429 -0
  181. package/build/session/persist-tool-calls.d.ts +54 -0
  182. package/build/session/persist-tool-calls.js +105 -0
  183. package/build/session/pricing.d.ts +64 -0
  184. package/build/session/pricing.js +151 -0
  185. package/build/session/project-attribution.d.ts +73 -0
  186. package/build/session/project-attribution.js +245 -0
  187. package/build/session/purge.d.ts +138 -0
  188. package/build/session/purge.js +240 -0
  189. package/build/session/retrieval-marker.d.ts +39 -0
  190. package/build/session/retrieval-marker.js +65 -0
  191. package/build/session/snapshot.d.ts +46 -0
  192. package/build/session/snapshot.js +532 -0
  193. package/build/store-directory.d.ts +56 -0
  194. package/build/store-directory.js +254 -0
  195. package/build/store.d.ts +147 -0
  196. package/build/store.js +1714 -0
  197. package/build/truncate.d.ts +57 -0
  198. package/build/truncate.js +142 -0
  199. package/build/types.d.ts +117 -0
  200. package/build/types.js +20 -0
  201. package/build/util/claude-config.d.ts +32 -0
  202. package/build/util/claude-config.js +84 -0
  203. package/build/util/hook-config.d.ts +27 -0
  204. package/build/util/hook-config.js +76 -0
  205. package/build/util/jsonc.d.ts +14 -0
  206. package/build/util/jsonc.js +104 -0
  207. package/build/util/plugin-cache-integrity.d.ts +51 -0
  208. package/build/util/plugin-cache-integrity.js +146 -0
  209. package/build/util/project-dir.d.ts +149 -0
  210. package/build/util/project-dir.js +340 -0
  211. package/build/util/sibling-mcp.d.ts +79 -0
  212. package/build/util/sibling-mcp.js +181 -0
  213. package/cli.bundle.mjs +1495 -0
  214. package/configs/antigravity/GEMINI.md +68 -0
  215. package/configs/antigravity/mcp_config.json +7 -0
  216. package/configs/antigravity-cli/hooks/hooks.json +37 -0
  217. package/configs/antigravity-cli/hooks.json +37 -0
  218. package/configs/antigravity-cli/mcp_config.json +10 -0
  219. package/configs/antigravity-cli/plugin.json +14 -0
  220. package/configs/antigravity-cli/rules/context-mode.md +77 -0
  221. package/configs/antigravity-cli/skills/context-mode/SKILL.md +77 -0
  222. package/configs/claude-code/CLAUDE.md +91 -0
  223. package/configs/codex/AGENTS.md +99 -0
  224. package/configs/codex/config.toml +8 -0
  225. package/configs/codex/hooks.json +47 -0
  226. package/configs/copilot-cli/.github/plugin/plugin.json +23 -0
  227. package/configs/copilot-cli/.mcp.json +12 -0
  228. package/configs/copilot-cli/README.md +47 -0
  229. package/configs/copilot-cli/hooks.json +41 -0
  230. package/configs/copilot-cli/skills/context-mode/SKILL.md +38 -0
  231. package/configs/cursor/context-mode.mdc +76 -0
  232. package/configs/cursor/hooks.json +21 -0
  233. package/configs/cursor/mcp.json +7 -0
  234. package/configs/gemini-cli/GEMINI.md +88 -0
  235. package/configs/gemini-cli/mcp.json +7 -0
  236. package/configs/gemini-cli/settings.json +60 -0
  237. package/configs/jetbrains-copilot/copilot-instructions.md +80 -0
  238. package/configs/jetbrains-copilot/hooks.json +16 -0
  239. package/configs/jetbrains-copilot/mcp.json +7 -0
  240. package/configs/kilo/AGENTS.md +84 -0
  241. package/configs/kilo/kilo.json +6 -0
  242. package/configs/kimi/hooks.json +54 -0
  243. package/configs/kiro/KIRO.md +84 -0
  244. package/configs/kiro/agent.json +18 -0
  245. package/configs/kiro/mcp.json +7 -0
  246. package/configs/omp/SYSTEM.md +85 -0
  247. package/configs/omp/mcp.json +7 -0
  248. package/configs/openclaw/AGENTS.md +87 -0
  249. package/configs/openclaw/openclaw.json +13 -0
  250. package/configs/opencode/AGENTS.md +84 -0
  251. package/configs/opencode/opencode.json +6 -0
  252. package/configs/pi/AGENTS.md +3 -0
  253. package/configs/qwen-code/QWEN.md +91 -0
  254. package/configs/vscode-copilot/copilot-instructions.md +80 -0
  255. package/configs/vscode-copilot/hooks.json +16 -0
  256. package/configs/vscode-copilot/mcp.json +7 -0
  257. package/configs/zed/AGENTS.md +68 -0
  258. package/hooks/antigravity-cli/payload.mjs +98 -0
  259. package/hooks/antigravity-cli/posttooluse.mjs +138 -0
  260. package/hooks/antigravity-cli/pretooluse.mjs +78 -0
  261. package/hooks/antigravity-cli/stop.mjs +58 -0
  262. package/hooks/auto-injection.mjs +102 -0
  263. package/hooks/cache-heal-utils.mjs +379 -0
  264. package/hooks/codex/platform.mjs +1 -0
  265. package/hooks/codex/posttooluse.mjs +66 -0
  266. package/hooks/codex/precompact.mjs +70 -0
  267. package/hooks/codex/pretooluse.mjs +42 -0
  268. package/hooks/codex/sessionstart.mjs +121 -0
  269. package/hooks/codex/stop.mjs +138 -0
  270. package/hooks/codex/userpromptsubmit.mjs +75 -0
  271. package/hooks/copilot-cli/posttooluse.mjs +79 -0
  272. package/hooks/copilot-cli/precompact.mjs +66 -0
  273. package/hooks/copilot-cli/pretooluse.mjs +41 -0
  274. package/hooks/copilot-cli/sessionstart.mjs +121 -0
  275. package/hooks/copilot-cli/stop.mjs +59 -0
  276. package/hooks/copilot-cli/userpromptsubmit.mjs +77 -0
  277. package/hooks/core/codex-caps.mjs +112 -0
  278. package/hooks/core/formatters.mjs +356 -0
  279. package/hooks/core/mcp-ready.mjs +109 -0
  280. package/hooks/core/platform-detect.mjs +49 -0
  281. package/hooks/core/routing.mjs +1050 -0
  282. package/hooks/core/stdin.mjs +90 -0
  283. package/hooks/core/tool-naming.mjs +57 -0
  284. package/hooks/cursor/afteragentresponse.mjs +74 -0
  285. package/hooks/cursor/hooks.json +31 -0
  286. package/hooks/cursor/posttooluse.mjs +72 -0
  287. package/hooks/cursor/pretooluse.mjs +26 -0
  288. package/hooks/cursor/sessionstart.mjs +97 -0
  289. package/hooks/cursor/stop.mjs +48 -0
  290. package/hooks/ensure-deps.mjs +254 -0
  291. package/hooks/formatters/claude-code.mjs +113 -0
  292. package/hooks/formatters/cursor.mjs +37 -0
  293. package/hooks/formatters/gemini-cli.mjs +55 -0
  294. package/hooks/formatters/vscode-copilot.mjs +55 -0
  295. package/hooks/gemini-cli/aftermodel.mjs +70 -0
  296. package/hooks/gemini-cli/aftertool.mjs +61 -0
  297. package/hooks/gemini-cli/beforeagent.mjs +99 -0
  298. package/hooks/gemini-cli/beforetool.mjs +27 -0
  299. package/hooks/gemini-cli/precompress.mjs +55 -0
  300. package/hooks/gemini-cli/sessionstart.mjs +137 -0
  301. package/hooks/heal-partial-install.mjs +712 -0
  302. package/hooks/hooks.json +143 -0
  303. package/hooks/jetbrains-copilot/posttooluse.mjs +61 -0
  304. package/hooks/jetbrains-copilot/precompact.mjs +55 -0
  305. package/hooks/jetbrains-copilot/pretooluse.mjs +27 -0
  306. package/hooks/jetbrains-copilot/sessionstart.mjs +124 -0
  307. package/hooks/kimi/platform.mjs +1 -0
  308. package/hooks/kimi/posttooluse.mjs +72 -0
  309. package/hooks/kimi/precompact.mjs +80 -0
  310. package/hooks/kimi/pretooluse.mjs +42 -0
  311. package/hooks/kimi/sessionend.mjs +61 -0
  312. package/hooks/kimi/sessionstart.mjs +113 -0
  313. package/hooks/kimi/stop.mjs +132 -0
  314. package/hooks/kimi/userpromptsubmit.mjs +90 -0
  315. package/hooks/kiro/agentspawn.mjs +97 -0
  316. package/hooks/kiro/posttooluse.mjs +51 -0
  317. package/hooks/kiro/pretooluse.mjs +64 -0
  318. package/hooks/kiro/userpromptsubmit.mjs +88 -0
  319. package/hooks/normalize-hooks.mjs +323 -0
  320. package/hooks/platform-bridge.mjs +340 -0
  321. package/hooks/posttooluse.mjs +225 -0
  322. package/hooks/precompact.mjs +100 -0
  323. package/hooks/pretooluse.mjs +227 -0
  324. package/hooks/qwen-code/platform.mjs +1 -0
  325. package/hooks/qwen-code/stop.mjs +168 -0
  326. package/hooks/routing-block.mjs +105 -0
  327. package/hooks/run-hook.mjs +95 -0
  328. package/hooks/security.bundle.mjs +2 -0
  329. package/hooks/session-attribution.bundle.mjs +1 -0
  330. package/hooks/session-db.bundle.mjs +145 -0
  331. package/hooks/session-directive.mjs +520 -0
  332. package/hooks/session-extract.bundle.mjs +3 -0
  333. package/hooks/session-helpers.mjs +428 -0
  334. package/hooks/session-loaders.mjs +448 -0
  335. package/hooks/session-snapshot.bundle.mjs +32 -0
  336. package/hooks/sessionstart.mjs +464 -0
  337. package/hooks/stop.mjs +82 -0
  338. package/hooks/suppress-stderr.mjs +25 -0
  339. package/hooks/userpromptsubmit.mjs +108 -0
  340. package/hooks/vscode-copilot/posttooluse.mjs +61 -0
  341. package/hooks/vscode-copilot/precompact.mjs +55 -0
  342. package/hooks/vscode-copilot/pretooluse.mjs +27 -0
  343. package/hooks/vscode-copilot/sessionstart.mjs +129 -0
  344. package/openclaw.plugin.json +38 -0
  345. package/package.json +132 -0
  346. package/scripts/heal-better-sqlite3.mjs +430 -0
  347. package/scripts/heal-installed-plugins.mjs +635 -0
  348. package/scripts/plugin-cache-integrity.mjs +248 -0
  349. package/scripts/postinstall.mjs +397 -0
  350. package/server.bundle.mjs +1421 -0
  351. package/server.js +5 -0
  352. package/skills/.ignore +7 -0
  353. package/skills/context-mode/SKILL.md +300 -0
  354. package/skills/context-mode/references/anti-patterns.md +283 -0
  355. package/skills/context-mode/references/patterns-javascript.md +298 -0
  356. package/skills/context-mode/references/patterns-python.md +304 -0
  357. package/skills/context-mode/references/patterns-shell.md +277 -0
  358. package/skills/ctx-doctor/SKILL.md +22 -0
  359. package/skills/ctx-index/SKILL.md +46 -0
  360. package/skills/ctx-insight/SKILL.md +24 -0
  361. package/skills/ctx-purge/SKILL.md +49 -0
  362. package/skills/ctx-search/SKILL.md +35 -0
  363. package/skills/ctx-stats/SKILL.md +26 -0
  364. package/skills/ctx-upgrade/SKILL.md +31 -0
  365. package/start.mjs +616 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * adapters/opencode/v2 — self-contained OpenCode v2 helper machinery.
3
+ *
4
+ * Holds only what has a clean seam from the plugin orchestration in
5
+ * plugin.ts (which owns the shared v1 handlers, the v2 registration/
6
+ * bridging functions, setupV2, and the hybrid activation guard):
7
+ * - the host-client log types (shared by the v1 and v2 logging paths)
8
+ * - the VERIFIED v2 setup-context surface types (opencode2 beta-19135
9
+ * live probe + docs build/plugins)
10
+ * - the Zod → JSON-Schema converter feeding ToolInfo.input
11
+ * - defensive field readers for the UNCONFIRMED v2 hook payload shapes
12
+ *
13
+ * Imports NOTHING from plugin.ts — no cycles. Exports kept minimal.
14
+ */
15
+ export type PluginClientAppLogBodyExtra = {
16
+ sessionId?: string;
17
+ source?: string;
18
+ };
19
+ export type PluginClientAppLogBody = {
20
+ service: string;
21
+ level: "info" | "warn" | "error" | "debug";
22
+ message: string;
23
+ extra?: PluginClientAppLogBodyExtra;
24
+ };
25
+ export type PluginClientAppLogOptions = {
26
+ body: PluginClientAppLogBody;
27
+ };
28
+ export type PluginClientApp = {
29
+ log: (options: PluginClientAppLogOptions) => Promise<void>;
30
+ };
31
+ export type PluginClient = {
32
+ app: PluginClientApp;
33
+ };
34
+ /**
35
+ * VERIFIED against opencode2 beta-19135 (live probe) + the v2 plugin docs
36
+ * (opencode.ai/v2/docs/build/plugins):
37
+ * ctx.tool { reload, transform, hook }
38
+ * ctx.session { hook, create, get, prompt, interrupt, rename, context, … }
39
+ * ctx.event { subscribe }
40
+ * ctx.app { name, version, channel } — NO app.log on v2
41
+ * Fields marked UNCONFIRMED (hook payload extras, event names) are accessed
42
+ * defensively — never assume a field exists.
43
+ */
44
+ /** v2 ToolEditor — handed to the ctx.tool.transform callback. */
45
+ export type V2ToolEditor = {
46
+ list?: () => unknown[];
47
+ get?: (id: string) => unknown;
48
+ namespace?: (options: unknown) => unknown;
49
+ add?: (tool: unknown) => unknown;
50
+ update?: (id: string, fn: (tool: unknown) => unknown) => unknown;
51
+ remove?: (id: string) => unknown;
52
+ };
53
+ /** v2 ToolInfo — what we register via editor.add() (docs: build/plugins). */
54
+ export type V2ToolInfo = {
55
+ name: string;
56
+ description?: string;
57
+ /** JSON-Schema object schema for the tool input. */
58
+ input: Record<string, unknown>;
59
+ options?: {
60
+ namespace?: string;
61
+ codemode?: boolean;
62
+ };
63
+ execute: (input: unknown, tool: unknown) => Promise<unknown>;
64
+ };
65
+ export type V2SetupContext = {
66
+ directory?: string;
67
+ project?: {
68
+ directory?: string;
69
+ };
70
+ client?: PluginClient;
71
+ app?: {
72
+ name?: string;
73
+ version?: string;
74
+ channel?: string;
75
+ };
76
+ tool?: {
77
+ reload?: (...args: unknown[]) => unknown;
78
+ transform?: (cb: (editor: V2ToolEditor) => unknown) => unknown;
79
+ hook?: (name: string, cb: (event: unknown) => unknown) => unknown;
80
+ };
81
+ session?: {
82
+ hook?: (name: string, cb: (event: unknown) => unknown) => unknown;
83
+ };
84
+ event?: {
85
+ /** AsyncIterable of { type, ... } events; exact event shapes UNCONFIRMED. */
86
+ subscribe?: (options?: {
87
+ signal?: AbortSignal;
88
+ }) => unknown;
89
+ };
90
+ };
91
+ /**
92
+ * Convert a Zod (v3-classic) schema into a JSON-Schema object — the shared
93
+ * single conversion point for the v2 ToolInfo `input` field. The MCP layer
94
+ * passes its Zod schemas to the SDK (which converts internally), so there is
95
+ * no repo util to reuse; this helper covers exactly the constructs the
96
+ * ctx_* tools use (object/optional/default/enum/string/number/boolean/
97
+ * array/preprocess/record/union/literal/any) and degrades to a permissive
98
+ * `{}` (accept anything) for anything it does not understand — a weird
99
+ * schema must never break tool registration.
100
+ */
101
+ export declare function zodSchemaToJsonSchema(schema: unknown, depth?: number): Record<string, unknown>;
102
+ export declare function v2ToolNameOf(event: Record<string, any>): string;
103
+ export declare function v2SessionIdOf(event: Record<string, any>): string;
104
+ /**
105
+ * Extract displayable text from an UNCONFIRMED v2 tool-result shape
106
+ * ({content: "..."} | {content: [{text}]} | {output} | string | other).
107
+ */
108
+ export declare function extractV2ToolResultText(result: unknown): string;
109
+ /**
110
+ * Extract displayable text from an UNCONFIRMED v2 tool-error shape
111
+ * (Error | string | {message} | object | undefined). Feeds the shared
112
+ * post-tool capture on `execute.after` error status so failed tool calls
113
+ * still produce error_tool events (v1 parity — extract.ts isToolError).
114
+ */
115
+ export declare function extractV2ToolErrorText(error: unknown): string;
116
+ /** Read displayable text out of a v2 SystemPart (string or {text}). */
117
+ export declare function v2SystemPartText(part: unknown): string;
@@ -0,0 +1,224 @@
1
+ /**
2
+ * adapters/opencode/v2 — self-contained OpenCode v2 helper machinery.
3
+ *
4
+ * Holds only what has a clean seam from the plugin orchestration in
5
+ * plugin.ts (which owns the shared v1 handlers, the v2 registration/
6
+ * bridging functions, setupV2, and the hybrid activation guard):
7
+ * - the host-client log types (shared by the v1 and v2 logging paths)
8
+ * - the VERIFIED v2 setup-context surface types (opencode2 beta-19135
9
+ * live probe + docs build/plugins)
10
+ * - the Zod → JSON-Schema converter feeding ToolInfo.input
11
+ * - defensive field readers for the UNCONFIRMED v2 hook payload shapes
12
+ *
13
+ * Imports NOTHING from plugin.ts — no cycles. Exports kept minimal.
14
+ */
15
+ // ── Zod → JSON-Schema (ToolInfo.input) ────────────────────
16
+ /**
17
+ * Whether a Zod schema position is OMITTABLE for JSON-Schema `required`
18
+ * purposes. Unwraps wrapper constructs recursively:
19
+ * ZodOptional → true (field may be absent)
20
+ * ZodDefault → true (the default satisfies the field — omittable)
21
+ * ZodEffects (z.preprocess/refine) → unwrap to the inner schema
22
+ * ZodCatch → unwrap to the inner schema
23
+ * ZodNullable → false (null allowed, but the field is still required —
24
+ * matches zod-to-json-schema semantics)
25
+ */
26
+ function zodSchemaIsOmittable(schema, depth = 0) {
27
+ if (depth > 12 || schema === null || typeof schema !== "object")
28
+ return false;
29
+ const def = schema._def;
30
+ if (!def)
31
+ return false;
32
+ switch (def.typeName) {
33
+ case "ZodOptional":
34
+ return true;
35
+ case "ZodDefault":
36
+ return true;
37
+ case "ZodCatch":
38
+ return zodSchemaIsOmittable(def.innerType, depth + 1);
39
+ case "ZodEffects":
40
+ return zodSchemaIsOmittable(def.schema, depth + 1);
41
+ case "ZodNullable":
42
+ return false;
43
+ default:
44
+ return false;
45
+ }
46
+ }
47
+ /**
48
+ * Convert a Zod (v3-classic) schema into a JSON-Schema object — the shared
49
+ * single conversion point for the v2 ToolInfo `input` field. The MCP layer
50
+ * passes its Zod schemas to the SDK (which converts internally), so there is
51
+ * no repo util to reuse; this helper covers exactly the constructs the
52
+ * ctx_* tools use (object/optional/default/enum/string/number/boolean/
53
+ * array/preprocess/record/union/literal/any) and degrades to a permissive
54
+ * `{}` (accept anything) for anything it does not understand — a weird
55
+ * schema must never break tool registration.
56
+ */
57
+ export function zodSchemaToJsonSchema(schema, depth = 0) {
58
+ if (depth > 12 || schema === null || typeof schema !== "object")
59
+ return {};
60
+ try {
61
+ const def = schema._def ?? {};
62
+ const described = (out) => {
63
+ if (typeof def.description === "string" && def.description)
64
+ out.description = def.description;
65
+ return out;
66
+ };
67
+ switch (def.typeName) {
68
+ case "ZodString": {
69
+ const out = described({ type: "string" });
70
+ for (const check of Array.isArray(def.checks) ? def.checks : []) {
71
+ if (check?.kind === "min" && typeof check.value === "number")
72
+ out.minLength = check.value;
73
+ if (check?.kind === "max" && typeof check.value === "number")
74
+ out.maxLength = check.value;
75
+ }
76
+ return out;
77
+ }
78
+ case "ZodNumber":
79
+ return described({ type: "number" });
80
+ case "ZodBoolean":
81
+ return described({ type: "boolean" });
82
+ case "ZodEnum":
83
+ return described({ type: "string", enum: Array.isArray(def.values) ? def.values : [] });
84
+ case "ZodLiteral":
85
+ return described({ enum: [def.value] });
86
+ case "ZodArray":
87
+ return described({ type: "array", items: zodSchemaToJsonSchema(def.type, depth + 1) });
88
+ case "ZodRecord":
89
+ return described({ type: "object", additionalProperties: zodSchemaToJsonSchema(def.valueType, depth + 1) });
90
+ case "ZodUnion":
91
+ return described({ anyOf: (Array.isArray(def.options) ? def.options : []).map((o) => zodSchemaToJsonSchema(o, depth + 1)) });
92
+ case "ZodOptional":
93
+ case "ZodNullable":
94
+ case "ZodCatch":
95
+ return zodSchemaToJsonSchema(def.innerType, depth + 1);
96
+ case "ZodDefault": {
97
+ const out = zodSchemaToJsonSchema(def.innerType, depth + 1);
98
+ try {
99
+ out.default = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
100
+ }
101
+ catch {
102
+ // Non-computable default — omit it; the schema stays permissive.
103
+ }
104
+ return out;
105
+ }
106
+ case "ZodEffects":
107
+ // z.preprocess / refine / transform — the INNER schema is the
108
+ // contract; the coercion runs in the execute path (same as v1).
109
+ return zodSchemaToJsonSchema(def.schema, depth + 1);
110
+ case "ZodObject": {
111
+ const shape = typeof def.shape === "function"
112
+ ? def.shape()
113
+ : def.shape ?? {};
114
+ const properties = {};
115
+ const required = [];
116
+ for (const [key, value] of Object.entries(shape)) {
117
+ properties[key] = zodSchemaToJsonSchema(value, depth + 1);
118
+ // Requiredness sees through ZodOptional/ZodDefault/ZodEffects
119
+ // (z.preprocess) wrappers — a defaulted or coerced-optional param
120
+ // must stay omittable, otherwise HOST-side JSON-Schema validation
121
+ // can reject the call before our Zod parse (with its coercions
122
+ // and defaults) ever runs.
123
+ if (!zodSchemaIsOmittable(value))
124
+ required.push(key);
125
+ }
126
+ return described({ type: "object", properties, required });
127
+ }
128
+ case "ZodAny":
129
+ case "ZodUnknown":
130
+ return described({});
131
+ default:
132
+ // Unknown construct — permissive.
133
+ return described({});
134
+ }
135
+ }
136
+ catch {
137
+ return {};
138
+ }
139
+ }
140
+ // ── Defensive readers for UNCONFIRMED v2 hook payloads ────
141
+ export function v2ToolNameOf(event) {
142
+ if (typeof event.tool === "string")
143
+ return event.tool;
144
+ if (event.tool && typeof event.tool === "object") {
145
+ const t = event.tool;
146
+ if (typeof t.name === "string")
147
+ return t.name;
148
+ if (typeof t.id === "string")
149
+ return t.id;
150
+ }
151
+ return "";
152
+ }
153
+ export function v2SessionIdOf(event) {
154
+ const candidate = event.sessionID ??
155
+ event.session?.id ??
156
+ event.tool?.sessionID ??
157
+ event.input?.sessionID ??
158
+ event.metadata?.sessionID;
159
+ return typeof candidate === "string" && candidate ? candidate : "";
160
+ }
161
+ /**
162
+ * Extract displayable text from an UNCONFIRMED v2 tool-result shape
163
+ * ({content: "..."} | {content: [{text}]} | {output} | string | other).
164
+ */
165
+ export function extractV2ToolResultText(result) {
166
+ if (typeof result === "string")
167
+ return result;
168
+ if (result === null || typeof result !== "object")
169
+ return "";
170
+ const r = result;
171
+ if (typeof r.content === "string")
172
+ return r.content;
173
+ if (Array.isArray(r.content)) {
174
+ return r.content
175
+ .map((part) => (part && typeof part === "object" && typeof part.text === "string" ? part.text : ""))
176
+ .filter(Boolean)
177
+ .join("\n");
178
+ }
179
+ if (typeof r.output === "string")
180
+ return r.output;
181
+ try {
182
+ return JSON.stringify(r);
183
+ }
184
+ catch {
185
+ return String(result);
186
+ }
187
+ }
188
+ /**
189
+ * Extract displayable text from an UNCONFIRMED v2 tool-error shape
190
+ * (Error | string | {message} | object | undefined). Feeds the shared
191
+ * post-tool capture on `execute.after` error status so failed tool calls
192
+ * still produce error_tool events (v1 parity — extract.ts isToolError).
193
+ */
194
+ export function extractV2ToolErrorText(error) {
195
+ if (typeof error === "string")
196
+ return error;
197
+ if (error instanceof Error) {
198
+ const code = error.code;
199
+ return code ? `${error.message} (code=${code})` : error.message;
200
+ }
201
+ if (error !== null && typeof error === "object") {
202
+ const e = error;
203
+ if (typeof e.message === "string" && e.message)
204
+ return e.message;
205
+ try {
206
+ return JSON.stringify(e);
207
+ }
208
+ catch {
209
+ // fall through to String
210
+ }
211
+ }
212
+ return error !== undefined && error !== null ? String(error) : "tool execute failed";
213
+ }
214
+ /** Read displayable text out of a v2 SystemPart (string or {text}). */
215
+ export function v2SystemPartText(part) {
216
+ if (typeof part === "string")
217
+ return part;
218
+ if (part !== null && typeof part === "object") {
219
+ const text = part.text;
220
+ if (typeof text === "string")
221
+ return text;
222
+ }
223
+ return "";
224
+ }
@@ -0,0 +1 @@
1
+ export declare function zod3ShapeToV4(shape: Record<string, unknown>, depth?: number): Record<string, unknown>;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Zod 3 → Zod 4 shape conversion for in-process plugin hosts that bundle Zod v4.
3
+ *
4
+ * KiloCode (since its inception) and recent OpenCode releases (≥ ~1.14.x)
5
+ * bundle Zod v4 internally. When they receive plugin tool definitions whose
6
+ * `args` contain Zod v3 schemas (with `_def` but no `_zod.def`), they crash
7
+ * with `TypeError: undefined is not an object (evaluating 'n._zod.def')`.
8
+ *
9
+ * This module converts Zod 3 schema shapes into Zod 4 equivalents so both
10
+ * hosts can process them natively.
11
+ */
12
+ import z from 'zod/v4';
13
+ export function zod3ShapeToV4(shape, depth = 0) {
14
+ const result = {};
15
+ for (const [key, value] of Object.entries(shape)) {
16
+ result[key] = zod3ToV4(value, depth);
17
+ }
18
+ return result;
19
+ }
20
+ function zod3ToV4(v, depth = 0) {
21
+ if (depth > 10)
22
+ return z.unknown();
23
+ if (v == null || typeof v !== "object")
24
+ return z.unknown();
25
+ const obj = v;
26
+ if (!obj._def || typeof obj._def !== "object")
27
+ return z.unknown();
28
+ const def = obj._def;
29
+ let result;
30
+ switch (def.typeName) {
31
+ case "ZodString":
32
+ result = def.coerce === true ? z.coerce.string() : z.string();
33
+ break;
34
+ case "ZodNumber":
35
+ result = def.coerce === true ? z.coerce.number() : z.number();
36
+ break;
37
+ case "ZodBoolean":
38
+ result = def.coerce === true ? z.coerce.boolean() : z.boolean();
39
+ break;
40
+ case "ZodAny":
41
+ result = z.any();
42
+ break;
43
+ case "ZodUnknown":
44
+ result = z.unknown();
45
+ break;
46
+ case "ZodNever":
47
+ result = z.never();
48
+ break;
49
+ case "ZodNull":
50
+ result = z.null();
51
+ break;
52
+ case "ZodUndefined":
53
+ result = z.undefined();
54
+ break;
55
+ case "ZodLiteral":
56
+ result = z.literal(def.value);
57
+ break;
58
+ case "ZodArray":
59
+ result = z.array(zod3ToV4(def.type ?? def.elementType, depth + 1));
60
+ break;
61
+ case "ZodEnum": {
62
+ const values = def.values;
63
+ result = Array.isArray(values) && values.length > 0
64
+ ? z.enum(values)
65
+ : z.never();
66
+ break;
67
+ }
68
+ case "ZodObject": {
69
+ const raw = def.shape;
70
+ const inner = typeof raw === "function" ? raw() : raw;
71
+ result = z.object(inner ? zod3ShapeToV4(inner, depth + 1) : {});
72
+ break;
73
+ }
74
+ case "ZodOptional":
75
+ result = z.optional(zod3ToV4(def.innerType ?? def.type, depth + 1));
76
+ break;
77
+ case "ZodNullable":
78
+ result = z.nullable(zod3ToV4(def.innerType ?? def.type, depth + 1));
79
+ break;
80
+ case "ZodDefault": {
81
+ const val = typeof def.defaultValue === "function"
82
+ ? def.defaultValue()
83
+ : def.defaultValue;
84
+ result = zod3ToV4(def.innerType ?? def.type, depth + 1).default(val);
85
+ break;
86
+ }
87
+ case "ZodRecord":
88
+ result = z.record(z.string(), zod3ToV4(def.valueType, depth + 1));
89
+ break;
90
+ case "ZodUnion": {
91
+ const opts = def.options;
92
+ if (!opts || opts.length === 0)
93
+ return z.never();
94
+ if (opts.length === 1)
95
+ return zod3ToV4(opts[0], depth + 1);
96
+ result = z.union(opts.map(o => zod3ToV4(o, depth + 1)));
97
+ break;
98
+ }
99
+ case "ZodEffects": {
100
+ // Zod v3 has two patterns for coercion:
101
+ //
102
+ // 1. Native coercion (z.coerce.number()): typeName is ZodNumber
103
+ // with _def.coerce=true. Handled in the ZodNumber case above.
104
+ //
105
+ // 2. Custom preprocess (z.preprocess(fn, schema)): typeName is
106
+ // ZodEffects with effect.type="preprocess". The transform is
107
+ // plain JS and works identically in Zod v4's z.preprocess().
108
+ //
109
+ // We never map ZodEffects→native coerce here because native
110
+ // coerce is already a ZodType (not ZodEffects), and custom
111
+ // transforms can't be safely replaced (e.g., z.coerce.boolean()
112
+ // in v4 converts "false"→true via Boolean(), which is wrong).
113
+ const effect = def.effect;
114
+ if (effect?.type === "preprocess" && typeof effect?.transform === "function") {
115
+ const innerSchema = zod3ToV4(def.schema, depth + 1);
116
+ result = z.preprocess(effect.transform, innerSchema);
117
+ }
118
+ else {
119
+ // Refinement / transform effects — host schema only.
120
+ result = zod3ToV4(def.schema, depth + 1);
121
+ }
122
+ break;
123
+ }
124
+ default:
125
+ // Never leak raw Zod 3 schemas back to a v4 host.
126
+ result = z.unknown();
127
+ break;
128
+ }
129
+ return def.description && typeof result.describe === "function"
130
+ ? result.describe(String(def.description))
131
+ : result;
132
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Pi coding agent extension for context-mode.
3
+ *
4
+ * Follows the OpenClaw adapter pattern: imports shared session modules,
5
+ * registers Pi-specific hooks. NO copy-paste of session logic.
6
+ * NO external npm dependencies beyond what Pi runtime provides.
7
+ *
8
+ * Entry point: `export default function(pi: ExtensionAPI) { ... }`
9
+ *
10
+ * Lifecycle: session_start, tool_call, tool_result, before_agent_start,
11
+ * session_before_compact, session_compact, session_shutdown.
12
+ */
13
+ /**
14
+ * Strip heredoc + single-quoted + double-quoted content from a shell command
15
+ * so the routing regex only sees command tokens, not user-provided strings.
16
+ *
17
+ * Mirrors hooks/core/routing.mjs:196–209. Inlined here because the Pi
18
+ * extension is bundled as a standalone build artifact (.pi/extensions/...)
19
+ * and cannot import hooks/core/* at runtime — they live in a sibling tree
20
+ * and may not be present in every Pi installation.
21
+ *
22
+ * Exported for unit tests.
23
+ */
24
+ export declare function stripQuotedContent(cmd: string): string;
25
+ /**
26
+ * Returns true iff `segment` is a curl/wget invocation that is SAFE to allow
27
+ * through the Pi routing block — i.e. it cannot flood the model's context
28
+ * window because the response body is written to disk (or appended to a file)
29
+ * and no verbose/trace flag is dumping headers to stderr.
30
+ *
31
+ * Mirrors hooks/core/routing.mjs:672–701. Segments that are NOT curl/wget
32
+ * return `true` (nothing to evaluate). The caller is expected to split chained
33
+ * commands on `&&`, `||`, `;` and call this per segment.
34
+ *
35
+ * Issue #625 — without this, the only escape hatch when the MCP bridge dies
36
+ * is `gh` CLI or a full Pi restart. Neither is acceptable as baseline UX.
37
+ *
38
+ * Exported for unit tests.
39
+ */
40
+ export declare function isSafeCurlWget(segment: string): boolean;
41
+ /**
42
+ * Settles when the MCP bridge bootstrap has finished — resolves on
43
+ * success AND on failure (the bootstrap is best-effort; failures are
44
+ * logged to stderr but never propagated). Exposed for tests so they
45
+ * can `await` the wiring deterministically without relying on internal
46
+ * timing or `setImmediate` polling.
47
+ *
48
+ * Starts as an already-settled promise because the bridge is now bootstrapped
49
+ * lazily from `before_agent_start`, not during extension discovery.
50
+ */
51
+ export declare let _mcpBridgeReady: Promise<void>;
52
+ /**
53
+ * Issue #545 — Pi workspace resolver.
54
+ *
55
+ * Pi's runtime sets PI_CONFIG_DIR to ~/.pi (its CONFIG dir, not the user's
56
+ * project). The extension previously used this as the project anchor, which
57
+ * meant every Pi session re-rooted under ~/.pi — collapsing all of a user's
58
+ * projects into a single phantom workspace. This helper picks the user's
59
+ * actual project directory while NEVER returning a path equal to or under
60
+ * ~/.pi/.
61
+ *
62
+ * Cascade:
63
+ * 1. PI_WORKSPACE_DIR — set by Pi's bridge (extension-set, freshest)
64
+ * 2. PI_PROJECT_DIR — legacy/user override
65
+ * 3. PWD — shell-set, survives process.chdir
66
+ * 4. cwd — last resort
67
+ *
68
+ * Each candidate is rejected if it equals ~/.pi or lives under ~/.pi/. If
69
+ * every candidate is poisoned, falls back to homedir() as a safe non-config
70
+ * anchor — caller may still render a "no project context" notice but the
71
+ * function stays total.
72
+ */
73
+ export declare function resolvePiWorkspaceDir(opts: {
74
+ env: Record<string, string | undefined>;
75
+ pwd: string | undefined;
76
+ cwd: string;
77
+ /** Optional override for tests; defaults to `os.homedir()`. */
78
+ home?: string;
79
+ }): string;
80
+ /** Pi extension default export. Called once by Pi runtime with the extension API. */
81
+ export default function piExtension(pi: any): void;