@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
package/server.js ADDED
@@ -0,0 +1,5 @@
1
+ // opencode v2 plugin loader entry: the v2 resolver expects a root-level
2
+ // `server` module (or a "./server" package export) — see
3
+ // docs/opencode-v2-compatibility.md. Re-export the plugin (default export
4
+ // carries both v1 `server` and v2 `setup` entries).
5
+ export { default } from "./build/adapters/opencode/plugin.js";
package/skills/.ignore ADDED
@@ -0,0 +1,7 @@
1
+ # Files in this directory that are NOT skills.
2
+ # Pi's skill loader (@mariozechner/pi-coding-agent) reads `.ignore`, `.gitignore`,
3
+ # and `.fdignore` while scanning skill directories with includeRootFiles=true,
4
+ # and skips matching entries. Keeping this list in-package guarantees Pi will not
5
+ # attempt to parse non-skill markdown as a skill — even if a stale copy of the
6
+ # file ever slips into a published tarball (see issue #496 / v1.0.120 regression).
7
+ UPSTREAM-CREDITS.md
@@ -0,0 +1,300 @@
1
+ ---
2
+ name: context-mode
3
+ description: |
4
+ Use context-mode tools (ctx_execute, ctx_execute_file) instead of Bash/cat when processing
5
+ large outputs. Triggers: "analyze logs", "summarize output", "process data",
6
+ "parse JSON", "filter results", "extract errors", "check build output",
7
+ "analyze dependencies", "process API response", "large file analysis",
8
+ "page snapshot", "browser snapshot", "DOM structure", "inspect page",
9
+ "accessibility tree", "Playwright snapshot",
10
+ "run tests", "test output", "coverage report", "git log", "recent commits",
11
+ "diff between branches", "list containers", "pod status", "disk usage",
12
+ "fetch docs", "API reference", "index documentation",
13
+ "call API", "check response", "query results",
14
+ "find TODOs", "count lines", "codebase statistics", "security audit",
15
+ "outdated packages", "dependency tree", "cloud resources", "CI/CD output".
16
+ Also triggers on ANY MCP tool output that may exceed 20 lines.
17
+ Subagent routing is handled automatically via PreToolUse hook.
18
+ ---
19
+
20
+ # Context Mode: Default for All Large Output
21
+
22
+ ## MANDATORY RULE
23
+
24
+ <context_mode_logic>
25
+ <mandatory_rule>
26
+ Default to context-mode for ALL commands. Only use Bash for guaranteed-small-output operations.
27
+ </mandatory_rule>
28
+ </context_mode_logic>
29
+
30
+ Bash whitelist (safe to run directly):
31
+ - **File mutations**: `mkdir`, `mv`, `cp`, `rm`, `touch`, `chmod`
32
+ - **Git writes**: `git add`, `git commit`, `git push`, `git checkout`, `git branch`, `git merge`
33
+ - **Navigation**: `cd`, `pwd`, `which`
34
+ - **Process control**: `kill`, `pkill`
35
+ - **Package management**: `npm install`, `npm publish`, `pip install`
36
+ - **Simple output**: `echo`, `printf`
37
+
38
+ **Everything else → `ctx_execute` or `ctx_execute_file`.** Any command that reads, queries, fetches, lists, logs, tests, builds, diffs, inspects, or calls an external service. This includes ALL CLIs (gh, aws, kubectl, docker, terraform, wrangler, fly, heroku, gcloud, etc.) — there are thousands and we cannot list them all.
39
+
40
+ **When uncertain, use context-mode.** Every KB of unnecessary context reduces the quality and speed of the entire session.
41
+
42
+ ## Decision Tree
43
+
44
+ ```
45
+ About to run a command / read a file / call an API?
46
+
47
+ ├── Command is on the Bash whitelist (file mutations, git writes, navigation, echo)?
48
+ │ └── Use Bash
49
+
50
+ ├── Output MIGHT be large or you're UNSURE?
51
+ │ └── Use context-mode ctx_execute or ctx_execute_file
52
+
53
+ ├── Fetching web documentation or HTML page?
54
+ │ └── Use ctx_fetch_and_index → ctx_search
55
+
56
+ ├── Using Playwright (navigate, snapshot, console, network)?
57
+ │ └── ALWAYS use filename parameter to save to file, then:
58
+ │ browser_snapshot(filename) → ctx_index(path) or ctx_execute_file(path)
59
+ │ browser_console_messages(filename) → ctx_execute_file(path)
60
+ │ browser_network_requests(filename) → ctx_execute_file(path)
61
+ │ ⚠ browser_navigate returns a snapshot automatically — ignore it,
62
+ │ use browser_snapshot(filename) for any inspection.
63
+ │ ⚠ Playwright MCP uses a SINGLE browser instance — NOT parallel-safe.
64
+ │ For parallel browser ops, use agent-browser via execute instead.
65
+
66
+ ├── Using agent-browser (parallel-safe browser automation)?
67
+ │ └── Run via execute (shell) — each call gets its own subprocess:
68
+ │ execute("agent-browser open example.com && agent-browser snapshot -i -c")
69
+ │ ✓ Supports sessions for isolated browser instances
70
+ │ ✓ Safe for parallel subagent execution
71
+ │ ✓ Lightweight accessibility tree with ref-based interaction
72
+
73
+ ├── Processing output from another MCP tool (Context7, GitHub API, etc.)?
74
+ │ ├── Output already in context from a previous tool call?
75
+ │ │ └── Use it directly. Do NOT re-index with ctx_index(content: ...).
76
+ │ ├── Need to search the output multiple times?
77
+ │ │ └── Save to file via ctx_execute, then ctx_index(path) → ctx_search
78
+ │ └── One-shot extraction?
79
+ │ └── Save to file via ctx_execute, then ctx_execute_file(path)
80
+
81
+ └── Reading a file to analyze/summarize (not edit)?
82
+ └── Use ctx_execute_file (file loads into FILE_CONTENT, not context)
83
+ ```
84
+
85
+ ## When to Use Each Tool
86
+
87
+ | Situation | Tool | Example |
88
+ |-----------|------|---------|
89
+ | Hit an API endpoint | `ctx_execute` | `fetch('http://localhost:3000/api/orders')` |
90
+ | Run CLI that returns data | `ctx_execute` | `gh pr list`, `aws s3 ls`, `kubectl get pods` |
91
+ | Run tests | `ctx_execute` | `npm test`, `pytest`, `go test ./...` |
92
+ | Git operations | `ctx_execute` | `git log --oneline -50`, `git diff HEAD~5` |
93
+ | Docker/K8s inspection | `ctx_execute` | `docker stats --no-stream`, `kubectl describe pod` |
94
+ | Read a log file | `ctx_execute_file` | Parse access.log, error.log, build output |
95
+ | Read a data file | `ctx_execute_file` | Analyze CSV, JSON, YAML, XML |
96
+ | Read source code to analyze | `ctx_execute_file` | Count functions, find patterns, extract metrics |
97
+ | Fetch web docs | `ctx_fetch_and_index` | Index React/Next.js/Zod docs, then search |
98
+ | Playwright snapshot | `browser_snapshot(filename)` → `ctx_index(path)` → `ctx_search` | Save to file, index server-side, query |
99
+ | Playwright snapshot (one-shot) | `browser_snapshot(filename)` → `ctx_execute_file(path)` | Save to file, extract in sandbox |
100
+ | Playwright console/network | `browser_*(filename)` → `ctx_execute_file(path)` | Save to file, analyze in sandbox |
101
+ | MCP output (already in context) | Use directly | Don't re-index — it's already loaded |
102
+ | MCP output (need multi-query) | `ctx_execute` to save → `ctx_index(path)` → `ctx_search` | Save to file first, index server-side |
103
+ | Wipe indexed KB content | `ctx_purge(confirm: true)` | Permanently deletes all indexed content |
104
+
105
+ ## Automatic Triggers
106
+
107
+ Use context-mode for ANY of these, without being asked:
108
+
109
+ - **API debugging**: "hit this endpoint", "call the API", "check the response", "find the bug in the response"
110
+ - **Log analysis**: "check the logs", "what errors", "read access.log", "debug the 500s"
111
+ - **Test runs**: "run the tests", "check if tests pass", "test suite output"
112
+ - **Git history**: "show recent commits", "git log", "what changed", "diff between branches"
113
+ - **Data inspection**: "look at the CSV", "parse the JSON", "analyze the config"
114
+ - **Infrastructure**: "list containers", "check pods", "S3 buckets", "show running services"
115
+ - **Dependency audit**: "check dependencies", "outdated packages", "security audit"
116
+ - **Build output**: "build the project", "check for warnings", "compile errors"
117
+ - **Code metrics**: "count lines", "find TODOs", "function count", "analyze codebase"
118
+ - **Web docs lookup**: "look up the docs", "check the API reference", "find examples"
119
+
120
+ ## Language Selection
121
+
122
+ | Situation | Language | Why |
123
+ |-----------|----------|-----|
124
+ | HTTP/API calls, JSON | `javascript` | Native fetch, JSON.parse, async/await |
125
+ | Data analysis, CSV, stats | `python` | csv, statistics, collections, re |
126
+ | Shell commands with pipes | `shell` | grep, awk, jq, native tools |
127
+ | File pattern matching | `shell` | find, wc, sort, uniq |
128
+
129
+ ## Search Query Strategy
130
+
131
+ - BM25 uses **OR semantics** — results matching more terms rank higher automatically
132
+ - Use 2-4 specific technical terms per query
133
+ - **Always use `source` parameter** when multiple docs are indexed to avoid cross-source contamination
134
+ - Partial match works: `source: "Node"` matches `"Node.js v22 CHANGELOG"`
135
+ - **Always use `queries` array** — batch ALL search questions in ONE call:
136
+ - `ctx_search(queries: ["transform pipe", "refine superRefine", "coerce codec"], source: "Zod")`
137
+ - NEVER make multiple separate ctx_search() calls — put all queries in one array
138
+
139
+ ## External Documentation
140
+
141
+ - **Always use `ctx_fetch_and_index`** for external docs — NEVER `cat` or `ctx_execute` with local paths for packages you don't own
142
+ - For GitHub-hosted projects, use the raw URL: `https://raw.githubusercontent.com/org/repo/main/CHANGELOG.md`
143
+ - After indexing, use the `source` parameter in search to scope results to that specific document
144
+
145
+ ## Critical Rules
146
+
147
+ 1. **Always console.log/print your findings.** stdout is all that enters context. No output = wasted call.
148
+ 2. **Write analysis code, not just data dumps.** Don't `console.log(JSON.stringify(data))` — analyze first, print findings.
149
+ 3. **Be specific in output.** Print bug details with IDs, line numbers, exact values — not just counts.
150
+ 4. **For files you need to EDIT**: Use the normal Read tool. context-mode is for analysis, not editing.
151
+ 5. **For Bash whitelist commands only**: Use Bash for file mutations, git writes, navigation, process control, package install, and echo. Everything else goes through context-mode.
152
+ 6. **Never use `ctx_index(content: large_data)`.** Use `ctx_index(path: ...)` to read files server-side. The `content` parameter sends data through context as a tool parameter — use it only for small inline text.
153
+ 7. **Always use `filename` parameter** on Playwright tools (`browser_snapshot`, `browser_console_messages`, `browser_network_requests`). Without it, the full output enters context.
154
+ 8. **Don't re-index data already in context.** If an MCP tool returned data in a previous response, it's already loaded — use it directly or save to file first.
155
+
156
+ ## Sandboxed Data Workflow
157
+
158
+ <sandboxed_data_workflow>
159
+ <critical_rule>
160
+ When using tools that support saving to a file: ALWAYS use the 'filename' parameter.
161
+ NEVER return large raw datasets directly to context.
162
+ </critical_rule>
163
+ <workflow>
164
+ LargeDataTool(filename: "path") → mcp__context-mode__ctx_index(path: "path") → ctx_search()
165
+ </workflow>
166
+ </sandboxed_data_workflow>
167
+
168
+ This is the universal pattern for context preservation regardless of
169
+ the source tool (Playwright, GitHub API, AWS CLI, etc.).
170
+
171
+ ## Examples
172
+
173
+ ### Debug an API endpoint
174
+ ```javascript
175
+ const resp = await fetch('http://localhost:3000/api/orders');
176
+ const { orders } = await resp.json();
177
+
178
+ const bugs = [];
179
+ const negQty = orders.filter(o => o.quantity < 0);
180
+ if (negQty.length) bugs.push(`Negative qty: ${negQty.map(o => o.id).join(', ')}`);
181
+
182
+ const nullFields = orders.filter(o => !o.product || !o.customer);
183
+ if (nullFields.length) bugs.push(`Null fields: ${nullFields.map(o => o.id).join(', ')}`);
184
+
185
+ console.log(`${orders.length} orders, ${bugs.length} bugs found:`);
186
+ bugs.forEach(b => console.log(`- ${b}`));
187
+ ```
188
+
189
+ ### Analyze test output
190
+ ```shell
191
+ npm test 2>&1
192
+ echo "EXIT=$?"
193
+ ```
194
+
195
+ ### Check GitHub PRs
196
+ ```shell
197
+ gh pr list --json number,title,state,reviewDecision --jq '.[] | "\(.number) [\(.state)] \(.title) — \(.reviewDecision // "no review")"'
198
+ ```
199
+
200
+ ### Read and analyze a large file
201
+ ```python
202
+ # FILE_CONTENT is pre-loaded by ctx_execute_file
203
+ import json
204
+ data = json.loads(FILE_CONTENT)
205
+ print(f"Records: {len(data)}")
206
+ # ... analyze and print findings
207
+ ```
208
+
209
+ ## Browser & Playwright Integration
210
+
211
+ **When a task involves Playwright snapshots, screenshots, or page inspection, ALWAYS route through file → sandbox.**
212
+
213
+ Playwright `browser_snapshot` returns 10K–135K tokens of accessibility tree data. Calling it without `filename` dumps all of that into context. Passing the output to `ctx_index(content: ...)` sends it into context a SECOND time as a parameter. Both are wrong.
214
+
215
+ **The key insight**: `browser_snapshot` has a `filename` parameter that saves to file instead of returning to context. `ctx_index` has a `path` parameter that reads files server-side. `ctx_execute_file` processes files in a sandbox. **None of these touch context.**
216
+
217
+ ### Workflow A: Snapshot → File → Index → Search (multiple queries)
218
+
219
+ ```
220
+ Step 1: browser_snapshot(filename: "/tmp/playwright-snapshot.md")
221
+ → saves to file, returns ~50B confirmation (NOT 135K tokens)
222
+
223
+ Step 2: ctx_index(path: "/tmp/playwright-snapshot.md", source: "Playwright snapshot")
224
+ → reads file SERVER-SIDE, indexes into FTS5, returns ~80B confirmation
225
+
226
+ Step 3: ctx_search(queries: ["login form email password"], source: "Playwright")
227
+ → returns only matching chunks (~300B)
228
+ ```
229
+
230
+ **Total context: ~430B** instead of 270K tokens. Real 99% savings.
231
+
232
+ ### Workflow B: Snapshot → File → Execute File (one-shot extraction)
233
+
234
+ ```
235
+ Step 1: browser_snapshot(filename: "/tmp/playwright-snapshot.md")
236
+ → saves to file, returns ~50B confirmation
237
+
238
+ Step 2: ctx_execute_file(path: "/tmp/playwright-snapshot.md", language: "javascript", code: "
239
+ const links = [...FILE_CONTENT.matchAll(/- link \"([^\"]+)\"/g)].map(m => m[1]);
240
+ const buttons = [...FILE_CONTENT.matchAll(/- button \"([^\"]+)\"/g)].map(m => m[1]);
241
+ const inputs = [...FILE_CONTENT.matchAll(/- textbox|- checkbox|- radio/g)];
242
+ console.log('Links:', links.length, '| Buttons:', buttons.length, '| Inputs:', inputs.length);
243
+ console.log('Navigation:', links.slice(0, 10).join(', '));
244
+ ")
245
+ → processes in sandbox, returns ~200B summary
246
+ ```
247
+
248
+ **Total context: ~250B** instead of 135K tokens.
249
+
250
+ ### Workflow C: Console & Network (save to file if large)
251
+
252
+ ```
253
+ browser_console_messages(level: "error", filename: "/tmp/console.md")
254
+ → ctx_execute_file(path: "/tmp/console.md", ...) or ctx_index(path: "/tmp/console.md", ...)
255
+
256
+ browser_network_requests(includeStatic: false, filename: "/tmp/network.md")
257
+ → ctx_execute_file(path: "/tmp/network.md", ...) or ctx_index(path: "/tmp/network.md", ...)
258
+ ```
259
+
260
+ ### CRITICAL: Why `filename` + `path` is mandatory
261
+
262
+ | Approach | Context cost | Correct? |
263
+ |----------|-------------|----------|
264
+ | `browser_snapshot()` → raw into context | **135K tokens** | NO |
265
+ | `browser_snapshot()` → `ctx_index(content: raw)` | **270K tokens** (doubled!) | NO |
266
+ | `browser_snapshot(filename)` → `ctx_index(path)` → `ctx_search` | **~430B** | YES |
267
+ | `browser_snapshot(filename)` → `ctx_execute_file(path)` | **~250B** | YES |
268
+
269
+ ### Key Rule
270
+
271
+ > **ALWAYS use `filename` parameter when calling `browser_snapshot`, `browser_console_messages`, or `browser_network_requests`.**
272
+ > Then process via `ctx_index(path: ...)` or `ctx_execute_file(path: ...)` — never `ctx_index(content: ...)`.
273
+ >
274
+ > Data flow: **Playwright → file → server-side read → context**. Never: **Playwright → context → ctx_index(content) → context again**.
275
+
276
+ ## Subagent Usage
277
+
278
+ Subagents automatically receive context-mode tool routing via a PreToolUse hook. You do NOT need to manually add tool names to subagent prompts — the hook injects them. Just write natural task descriptions.
279
+
280
+ ## Anti-Patterns
281
+
282
+ - Using `curl http://api/endpoint` via Bash → 50KB floods context. Use `ctx_execute` with fetch instead.
283
+ - Using `cat large-file.json` via Bash → entire file in context. Use `ctx_execute_file` instead.
284
+ - Using `gh pr list` via Bash → raw JSON in context. Use `ctx_execute` with `--jq` filter instead.
285
+ - Piping Bash output through `| head -20` → you lose the rest. Use `ctx_execute` to analyze ALL data and print summary.
286
+ - Narrowing `ctx_execute` output upstream of capture → `ctx_execute` captures, `ctx_search` filters; merging the layers drops data that the index never sees. See `references/anti-patterns.md` §8.
287
+ - Running `npm test` via Bash → full test output in context. Use `ctx_execute` to capture and summarize.
288
+ - Calling `browser_snapshot()` WITHOUT `filename` parameter → 135K tokens flood context. **Always** use `browser_snapshot(filename: "/tmp/snap.md")`.
289
+ - Calling `browser_console_messages()` or `browser_network_requests()` WITHOUT `filename` → entire output floods context. **Always** use the `filename` parameter.
290
+ - Passing ANY large data to `ctx_index(content: ...)` → data enters context as a parameter. **Always** use `ctx_index(path: ...)` to read server-side. The `content` parameter should only be used for small inline text you're composing yourself.
291
+ - Calling an MCP tool (Context7 `query-docs`, GitHub API, etc.) then passing the response to `ctx_index(content: response)` → **doubles** context usage. The response is already in context — use it directly or save to file first.
292
+ - Ignoring `browser_navigate` auto-snapshot → navigation response includes a full page snapshot. Don't rely on it for inspection — call `browser_snapshot(filename)` separately.
293
+ - Expecting `ctx_stats` to reset or wipe anything → `ctx_stats` is read-only (shows stats only). Use `ctx_purge(confirm: true)` to permanently delete all indexed content.
294
+
295
+ ## Reference Files
296
+
297
+ - [JavaScript/TypeScript Patterns](./references/patterns-javascript.md)
298
+ - [Python Patterns](./references/patterns-python.md)
299
+ - [Shell Patterns](./references/patterns-shell.md)
300
+ - [Anti-Patterns & Common Mistakes](./references/anti-patterns.md)
@@ -0,0 +1,283 @@
1
+ # Anti-Patterns: Common Mistakes with execute / execute_file
2
+
3
+ Avoid these pitfalls when using context-mode tools.
4
+
5
+ ---
6
+
7
+ ## 1. Using execute for Small Outputs (< 20 Lines)
8
+
9
+ **Problem:** `execute` adds overhead (LLM summarization call). For small outputs, Bash is faster and cheaper.
10
+
11
+ ```
12
+ BAD — wasteful use of execute:
13
+ Tool: execute
14
+ code: "echo $(node --version)"
15
+ language: shell
16
+
17
+ GOOD — just use Bash:
18
+ Tool: Bash
19
+ command: node --version
20
+ ```
21
+
22
+ **Rule:** If the output fits comfortably in your context window (under ~20 lines), use Bash directly. Reserve `execute` for outputs that would bloat context or need intelligent summarization.
23
+
24
+ More examples of "just use Bash":
25
+ - `git status` — usually 5-10 lines
26
+ - `ls -la` — directory listing
27
+ - `cat .env.example` — small config file
28
+ - `pwd`, `whoami`, `which node`
29
+ - `wc -l src/index.ts` — single line output
30
+
31
+ ---
32
+
33
+ ## 2. Forgetting to Print Output
34
+
35
+ **Problem:** `execute` captures stdout. If your code doesn't print anything, the summary will be empty or meaningless.
36
+
37
+ ```javascript
38
+ // BAD — no output:
39
+ const fs = require('fs');
40
+ const data = JSON.parse(fs.readFileSync('package.json', 'utf8'));
41
+ const deps = Object.keys(data.dependencies);
42
+ // Nothing printed! The LLM sees empty stdout.
43
+
44
+ // GOOD — explicit output:
45
+ const fs = require('fs');
46
+ const data = JSON.parse(fs.readFileSync('package.json', 'utf8'));
47
+ const deps = Object.keys(data.dependencies);
48
+ console.log(`Dependencies (${deps.length}):`);
49
+ deps.forEach(d => console.log(` ${d}: ${data.dependencies[d]}`));
50
+ ```
51
+
52
+ ```python
53
+ # BAD — computes but never prints:
54
+ with open('data.json') as f:
55
+ data = json.load(f)
56
+ result = [x for x in data if x['status'] == 'error']
57
+ # result is lost — never printed
58
+
59
+ # GOOD — always print results:
60
+ with open('data.json') as f:
61
+ data = json.load(f)
62
+ result = [x for x in data if x['status'] == 'error']
63
+ print(f"Found {len(result)} errors:")
64
+ for r in result:
65
+ print(f" {r['id']}: {r['message']}")
66
+ ```
67
+
68
+ **Rule:** Every `execute` script must end with print/console.log of the results you want summarized.
69
+
70
+ ---
71
+
72
+ ## 3. Using Bash When JS/Python Would Be Cleaner
73
+
74
+ **Problem:** Complex data processing in Bash quickly becomes unreadable and error-prone.
75
+
76
+ ```shell
77
+ # BAD — parsing JSON in Bash is fragile:
78
+ cat data.json | python3 -c "
79
+ import sys, json
80
+ data = json.load(sys.stdin)
81
+ for item in data:
82
+ if item['status'] == 'error':
83
+ print(item['id'], item['message'])
84
+ "
85
+ # If you're already using Python inline, just use language: python
86
+ ```
87
+
88
+ ```javascript
89
+ // GOOD — use the right language for the job:
90
+ // language: javascript
91
+ const data = require('./data.json');
92
+ data.filter(x => x.status === 'error')
93
+ .forEach(x => console.log(`${x.id}: ${x.message}`));
94
+ ```
95
+
96
+ **Rule:** If your Bash script contains inline Python/Node or complex `jq`/`awk` chains, switch to `language: python` or `language: javascript` instead.
97
+
98
+ Signs you should switch from shell:
99
+ - Using `python3 -c` or `node -e` inside the shell script
100
+ - More than 3 pipes chained together
101
+ - Using `jq` for complex JSON transformations
102
+ - Nested loops in Bash
103
+ - String manipulation beyond simple `cut`/`sed`
104
+
105
+ ---
106
+
107
+ ## 4. Loading Entire Files into Context Then Processing
108
+
109
+ **Problem:** Reading a 10,000-line file with `Read` tool, then asking about it, wastes your entire context window. Use `execute` to process the file and return only the summary.
110
+
111
+ ```
112
+ BAD workflow:
113
+ 1. Read tool: read 'server.log' (10,000 lines loaded into context)
114
+ 2. "Find all errors in this log"
115
+ → 10,000 lines consumed context for a question that needs ~20 lines of output
116
+
117
+ GOOD workflow:
118
+ 1. execute with language: python
119
+ code: |
120
+ with open('server.log') as f:
121
+ errors = [l for l in f if 'ERROR' in l]
122
+ print(f"Total errors: {len(errors)}")
123
+ for e in errors[-20:]:
124
+ print(e.strip())
125
+ summary_prompt: "Categorize errors and report frequency"
126
+ → Only the summary enters context
127
+ ```
128
+
129
+ ```
130
+ BAD workflow:
131
+ 1. Read tool: read 'package-lock.json' (20,000 lines)
132
+ 2. "What version of lodash is installed?"
133
+
134
+ GOOD workflow:
135
+ 1. execute with language: javascript
136
+ code: |
137
+ const lock = require('./package-lock.json');
138
+ const find = (deps, name) => {
139
+ if (deps[name]) return deps[name].version;
140
+ for (const [, dep] of Object.entries(deps)) {
141
+ if (dep.dependencies) {
142
+ const v = find(dep.dependencies, name);
143
+ if (v) return v;
144
+ }
145
+ }
146
+ };
147
+ console.log(`lodash: ${find(lock.dependencies, 'lodash') || 'not found'}`);
148
+ summary_prompt: "Report the installed version of lodash"
149
+ ```
150
+
151
+ **Rule:** If a file is over 200 lines and you only need specific data from it, use `execute` to extract what you need rather than reading the whole file into context.
152
+
153
+ ---
154
+
155
+ ## 5. Not Using JSON.stringify for Structured Output
156
+
157
+ **Problem:** Printing objects without serialization gives `[object Object]` in JavaScript.
158
+
159
+ ```javascript
160
+ // BAD — prints [object Object]:
161
+ const pkg = require('./package.json');
162
+ console.log(pkg.dependencies);
163
+ // Output: [object Object]
164
+
165
+ // GOOD — serialize properly:
166
+ const pkg = require('./package.json');
167
+ console.log(JSON.stringify(pkg.dependencies, null, 2));
168
+ // Output: { "react": "^18.2.0", "next": "^14.0.0", ... }
169
+ ```
170
+
171
+ ```javascript
172
+ // BAD — loses structure in arrays:
173
+ const items = [{name: 'a', value: 1}, {name: 'b', value: 2}];
174
+ console.log(items);
175
+ // May print unhelpfully
176
+
177
+ // GOOD — format as table:
178
+ const items = [{name: 'a', value: 1}, {name: 'b', value: 2}];
179
+ console.log('Name | Value');
180
+ console.log('------|------');
181
+ items.forEach(i => console.log(`${i.name.padEnd(5)} | ${i.value}`));
182
+ // Or use JSON.stringify:
183
+ console.log(JSON.stringify(items, null, 2));
184
+ ```
185
+
186
+ **Rule:** Always use `JSON.stringify(data, null, 2)` for objects/arrays in JavaScript, or format as a readable table. In Python, use `json.dumps(data, indent=2)` or `pprint.pprint(data)`.
187
+
188
+ ---
189
+
190
+ ## 6. Timeout Too Short for Network Operations
191
+
192
+ **Problem:** Default timeout may be too short for API calls, builds, or test suites.
193
+
194
+ ```
195
+ BAD — will timeout on API calls:
196
+ Tool: execute
197
+ code: |
198
+ const resp = await fetch('https://api.slow-service.com/data');
199
+ console.log(await resp.json());
200
+ language: javascript
201
+ timeout_ms: 5000 ← API may take 10+ seconds
202
+
203
+ GOOD — generous timeout for network:
204
+ Tool: execute
205
+ code: |
206
+ const resp = await fetch('https://api.slow-service.com/data');
207
+ console.log(JSON.stringify(await resp.json(), null, 2));
208
+ language: javascript
209
+ timeout_ms: 30000 ← 30 seconds for network calls
210
+ ```
211
+
212
+ **Recommended timeouts:**
213
+ | Operation | timeout_ms |
214
+ |-----------|-----------|
215
+ | File reading/parsing | 5000 - 10000 |
216
+ | Local computation | 10000 |
217
+ | Single API request | 15000 - 30000 |
218
+ | Paginated API calls | 30000 - 60000 |
219
+ | npm install / build | 120000 |
220
+ | Full test suite | 120000 - 300000 |
221
+
222
+ **Rule:** Always consider what your script does and set `timeout_ms` accordingly. Network calls and builds need significantly more time than file operations.
223
+
224
+ ---
225
+
226
+ ## 7. Not Using summary_prompt Effectively
227
+
228
+ **Problem:** Without a good `summary_prompt`, the LLM summarization may focus on irrelevant details.
229
+
230
+ ```
231
+ BAD — vague or missing summary_prompt:
232
+ summary_prompt: "Summarize this"
233
+ → May focus on the wrong aspects
234
+
235
+ GOOD — specific and actionable:
236
+ summary_prompt: "Report the count of failing tests, list each failure with its file path and error message, and identify any patterns in the failures"
237
+ ```
238
+
239
+ **Tips for effective summary_prompt:**
240
+ - Be specific about what data points you need
241
+ - Ask for counts and metrics, not just descriptions
242
+ - Request actionable insights ("suggest fixes", "identify patterns")
243
+ - Mention the format you want ("list as bullet points", "group by category")
244
+
245
+ ---
246
+
247
+ ## 8. `ctx_execute` Captures, `ctx_search` Filters — Don't Merge the Layers
248
+
249
+ `ctx_execute` and `ctx_search` are two layers, not one. `ctx_execute` exists to **capture** full output into the index. `ctx_search` exists to **filter** what was captured. When you narrow the output *inside* `ctx_execute` — at the shell layer, in script logic, anywhere upstream of capture — the dropped lines never reach the index. `ctx_search` cannot recover what was never written. You've spent the capture budget and lost the data you'd want to query later, for no context-window benefit: large stdout is already auto-indexed, not returned inline.
250
+
251
+ The mental model:
252
+
253
+ ```
254
+ ┌──────────────────────┐ ┌──────────────────────┐
255
+ │ ctx_execute │ ───▶ │ ctx_search │
256
+ │ (capture layer) │ │ (filter layer) │
257
+ │ │ │ │
258
+ │ produces full │ │ queries the │
259
+ │ output into index │ │ captured index │
260
+ └──────────────────────┘ └──────────────────────┘
261
+ ▲ ▲
262
+ │ │
263
+ Job: capture Job: narrow
264
+ Do NOT narrow here. Do all narrowing here.
265
+ ```
266
+
267
+ **Rule:** Treat `ctx_execute`'s output as write-once to the index. Run the command in full and let it index. Do every narrowing step downstream, via `ctx_search`. If you find yourself trimming inside `ctx_execute`, you are doing the filter layer's job in the capture layer — stop and move the narrowing to a `ctx_search` call.
268
+
269
+ **Why the layer separation matters:** the index is what survives across calls and across sessions. Anything you discard before the index is gone permanently from this session's queryable surface. Anything you keep is queryable, repeatedly, with different questions, at zero re-execution cost.
270
+
271
+ ---
272
+
273
+ ## Summary Checklist
274
+
275
+ Before using `execute`, verify:
276
+
277
+ - [ ] Output will be > 20 lines (otherwise use Bash)
278
+ - [ ] Script prints all results to stdout
279
+ - [ ] Objects are serialized with JSON.stringify / json.dumps
280
+ - [ ] Timeout matches the operation type
281
+ - [ ] Language matches the task (JS for JSON/API, Python for data, Shell for pipes)
282
+ - [ ] summary_prompt is specific and actionable
283
+ - [ ] Not loading a file into context that could be processed inside execute