apex-code 0.5.0 → 0.5.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 (512) hide show
  1. package/CHANGELOG.md +263 -5
  2. package/README.md +624 -0
  3. package/dist/bun/cli.d.ts +3 -1
  4. package/dist/bun/cli.d.ts.map +1 -1
  5. package/dist/bun/cli.js +3 -9
  6. package/dist/bun/cli.js.map +1 -1
  7. package/dist/bun/runtime-setup.d.ts +2 -0
  8. package/dist/bun/runtime-setup.d.ts.map +1 -0
  9. package/dist/bun/runtime-setup.js +9 -0
  10. package/dist/bun/runtime-setup.js.map +1 -0
  11. package/dist/bun/sandbox-env-setup.d.ts +2 -0
  12. package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
  13. package/dist/bun/sandbox-env-setup.js +4 -0
  14. package/dist/bun/sandbox-env-setup.js.map +1 -0
  15. package/dist/cli/args.d.ts.map +1 -1
  16. package/dist/cli/args.js +16 -5
  17. package/dist/cli/args.js.map +1 -1
  18. package/dist/cli/config-selector.d.ts.map +1 -1
  19. package/dist/cli/config-selector.js +2 -1
  20. package/dist/cli/config-selector.js.map +1 -1
  21. package/dist/cli/file-processor.d.ts +1 -1
  22. package/dist/cli/file-processor.d.ts.map +1 -1
  23. package/dist/cli/file-processor.js.map +1 -1
  24. package/dist/cli/session-picker.d.ts +1 -1
  25. package/dist/cli/session-picker.d.ts.map +1 -1
  26. package/dist/cli/session-picker.js.map +1 -1
  27. package/dist/cli/setup.d.ts +2 -0
  28. package/dist/cli/setup.d.ts.map +1 -0
  29. package/dist/cli/setup.js +13 -0
  30. package/dist/cli/setup.js.map +1 -0
  31. package/dist/config.d.ts +1 -0
  32. package/dist/config.d.ts.map +1 -1
  33. package/dist/config.js +1 -0
  34. package/dist/config.js.map +1 -1
  35. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  36. package/dist/core/agent-session-runtime.js +16 -8
  37. package/dist/core/agent-session-runtime.js.map +1 -1
  38. package/dist/core/agent-session.d.ts +85 -15
  39. package/dist/core/agent-session.d.ts.map +1 -1
  40. package/dist/core/agent-session.js +685 -266
  41. package/dist/core/agent-session.js.map +1 -1
  42. package/dist/core/auth-storage.d.ts +4 -0
  43. package/dist/core/auth-storage.d.ts.map +1 -1
  44. package/dist/core/auth-storage.js +55 -0
  45. package/dist/core/auth-storage.js.map +1 -1
  46. package/dist/core/bug-report.d.ts +176 -0
  47. package/dist/core/bug-report.d.ts.map +1 -0
  48. package/dist/core/bug-report.js +291 -0
  49. package/dist/core/bug-report.js.map +1 -0
  50. package/dist/core/cache-stats.d.ts.map +1 -1
  51. package/dist/core/cache-stats.js +12 -1
  52. package/dist/core/cache-stats.js.map +1 -1
  53. package/dist/core/cache-warmer.d.ts +103 -0
  54. package/dist/core/cache-warmer.d.ts.map +1 -0
  55. package/dist/core/cache-warmer.js +356 -0
  56. package/dist/core/cache-warmer.js.map +1 -0
  57. package/dist/core/compaction/branch-summarization.d.ts +1 -1
  58. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  59. package/dist/core/compaction/branch-summarization.js +4 -3
  60. package/dist/core/compaction/branch-summarization.js.map +1 -1
  61. package/dist/core/compaction/compaction.d.ts +5 -3
  62. package/dist/core/compaction/compaction.d.ts.map +1 -1
  63. package/dist/core/compaction/compaction.js +163 -66
  64. package/dist/core/compaction/compaction.js.map +1 -1
  65. package/dist/core/context/pipeline.d.ts +8 -8
  66. package/dist/core/context/pipeline.d.ts.map +1 -1
  67. package/dist/core/context/pipeline.js +21 -12
  68. package/dist/core/context/pipeline.js.map +1 -1
  69. package/dist/core/crash-log.d.ts +27 -0
  70. package/dist/core/crash-log.d.ts.map +1 -0
  71. package/dist/core/crash-log.js +139 -0
  72. package/dist/core/crash-log.js.map +1 -0
  73. package/dist/core/export-html/template.js +6 -1
  74. package/dist/core/extensions/index.d.ts +1 -1
  75. package/dist/core/extensions/index.d.ts.map +1 -1
  76. package/dist/core/extensions/index.js.map +1 -1
  77. package/dist/core/extensions/jiti-loader.d.ts +2 -0
  78. package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
  79. package/dist/core/extensions/jiti-loader.js +4 -0
  80. package/dist/core/extensions/jiti-loader.js.map +1 -0
  81. package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
  82. package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
  83. package/dist/core/extensions/jiti-static-loader.js +4 -0
  84. package/dist/core/extensions/jiti-static-loader.js.map +1 -0
  85. package/dist/core/extensions/loader.d.ts.map +1 -1
  86. package/dist/core/extensions/loader.js +40 -59
  87. package/dist/core/extensions/loader.js.map +1 -1
  88. package/dist/core/extensions/runner.d.ts +24 -8
  89. package/dist/core/extensions/runner.d.ts.map +1 -1
  90. package/dist/core/extensions/runner.js +195 -72
  91. package/dist/core/extensions/runner.js.map +1 -1
  92. package/dist/core/extensions/types.d.ts +142 -55
  93. package/dist/core/extensions/types.d.ts.map +1 -1
  94. package/dist/core/extensions/types.js.map +1 -1
  95. package/dist/core/extensions/virtual-modules.d.ts +3 -0
  96. package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
  97. package/dist/core/extensions/virtual-modules.js +41 -0
  98. package/dist/core/extensions/virtual-modules.js.map +1 -0
  99. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  100. package/dist/core/extensions/wrapper.js +1 -20
  101. package/dist/core/extensions/wrapper.js.map +1 -1
  102. package/dist/core/http-dispatcher.d.ts.map +1 -1
  103. package/dist/core/http-dispatcher.js +2 -0
  104. package/dist/core/http-dispatcher.js.map +1 -1
  105. package/dist/core/index.d.ts +2 -1
  106. package/dist/core/index.d.ts.map +1 -1
  107. package/dist/core/index.js.map +1 -1
  108. package/dist/core/keybindings.d.ts +6 -1
  109. package/dist/core/keybindings.d.ts.map +1 -1
  110. package/dist/core/keybindings.js +5 -1
  111. package/dist/core/keybindings.js.map +1 -1
  112. package/dist/core/messages.d.ts +1 -1
  113. package/dist/core/messages.d.ts.map +1 -1
  114. package/dist/core/messages.js +1 -0
  115. package/dist/core/messages.js.map +1 -1
  116. package/dist/core/model-config.d.ts +168 -20
  117. package/dist/core/model-config.d.ts.map +1 -1
  118. package/dist/core/model-config.js +44 -18
  119. package/dist/core/model-config.js.map +1 -1
  120. package/dist/core/model-registry.d.ts +5 -1
  121. package/dist/core/model-registry.d.ts.map +1 -1
  122. package/dist/core/model-registry.js +8 -0
  123. package/dist/core/model-registry.js.map +1 -1
  124. package/dist/core/model-resolver.d.ts.map +1 -1
  125. package/dist/core/model-resolver.js +4 -3
  126. package/dist/core/model-resolver.js.map +1 -1
  127. package/dist/core/model-runtime.d.ts +1 -0
  128. package/dist/core/model-runtime.d.ts.map +1 -1
  129. package/dist/core/model-runtime.js +12 -6
  130. package/dist/core/model-runtime.js.map +1 -1
  131. package/dist/core/permissions/store.d.ts.map +1 -1
  132. package/dist/core/permissions/store.js +11 -8
  133. package/dist/core/permissions/store.js.map +1 -1
  134. package/dist/core/prompt-templates.d.ts +6 -1
  135. package/dist/core/prompt-templates.d.ts.map +1 -1
  136. package/dist/core/prompt-templates.js +61 -35
  137. package/dist/core/prompt-templates.js.map +1 -1
  138. package/dist/core/provider-composer.d.ts +4 -2
  139. package/dist/core/provider-composer.d.ts.map +1 -1
  140. package/dist/core/provider-composer.js +29 -2
  141. package/dist/core/provider-composer.js.map +1 -1
  142. package/dist/core/radius.d.ts +3 -0
  143. package/dist/core/radius.d.ts.map +1 -1
  144. package/dist/core/radius.js +6 -0
  145. package/dist/core/radius.js.map +1 -1
  146. package/dist/core/resource-loader.d.ts.map +1 -1
  147. package/dist/core/resource-loader.js +6 -2
  148. package/dist/core/resource-loader.js.map +1 -1
  149. package/dist/core/sdk.d.ts.map +1 -1
  150. package/dist/core/sdk.js +63 -42
  151. package/dist/core/sdk.js.map +1 -1
  152. package/dist/core/session-export.d.ts +6 -2
  153. package/dist/core/session-export.d.ts.map +1 -1
  154. package/dist/core/session-export.js +14 -13
  155. package/dist/core/session-export.js.map +1 -1
  156. package/dist/core/session-manager.d.ts +66 -15
  157. package/dist/core/session-manager.d.ts.map +1 -1
  158. package/dist/core/session-manager.js +295 -115
  159. package/dist/core/session-manager.js.map +1 -1
  160. package/dist/core/settings-manager.d.ts +27 -4
  161. package/dist/core/settings-manager.d.ts.map +1 -1
  162. package/dist/core/settings-manager.js +55 -7
  163. package/dist/core/settings-manager.js.map +1 -1
  164. package/dist/core/skills.d.ts +1 -1
  165. package/dist/core/skills.d.ts.map +1 -1
  166. package/dist/core/skills.js +5 -4
  167. package/dist/core/skills.js.map +1 -1
  168. package/dist/core/slash-commands.d.ts.map +1 -1
  169. package/dist/core/slash-commands.js +1 -0
  170. package/dist/core/slash-commands.js.map +1 -1
  171. package/dist/core/system-prompt.d.ts +49 -6
  172. package/dist/core/system-prompt.d.ts.map +1 -1
  173. package/dist/core/system-prompt.js +140 -79
  174. package/dist/core/system-prompt.js.map +1 -1
  175. package/dist/core/tools/bash.d.ts +7 -8
  176. package/dist/core/tools/bash.d.ts.map +1 -1
  177. package/dist/core/tools/bash.js +20 -115
  178. package/dist/core/tools/bash.js.map +1 -1
  179. package/dist/core/tools/edit.d.ts +1 -12
  180. package/dist/core/tools/edit.d.ts.map +1 -1
  181. package/dist/core/tools/edit.js +6 -204
  182. package/dist/core/tools/edit.js.map +1 -1
  183. package/dist/core/tools/find.d.ts.map +1 -1
  184. package/dist/core/tools/find.js +4 -55
  185. package/dist/core/tools/find.js.map +1 -1
  186. package/dist/core/tools/grep.d.ts.map +1 -1
  187. package/dist/core/tools/grep.js +4 -60
  188. package/dist/core/tools/grep.js.map +1 -1
  189. package/dist/core/tools/ls.d.ts.map +1 -1
  190. package/dist/core/tools/ls.js +4 -49
  191. package/dist/core/tools/ls.js.map +1 -1
  192. package/dist/core/tools/read.d.ts +4 -1
  193. package/dist/core/tools/read.d.ts.map +1 -1
  194. package/dist/core/tools/read.js +10 -125
  195. package/dist/core/tools/read.js.map +1 -1
  196. package/dist/core/tools/renderers/bash.d.ts +18 -0
  197. package/dist/core/tools/renderers/bash.d.ts.map +1 -0
  198. package/dist/core/tools/renderers/bash.js +126 -0
  199. package/dist/core/tools/renderers/bash.js.map +1 -0
  200. package/dist/core/tools/renderers/edit.d.ts +23 -0
  201. package/dist/core/tools/renderers/edit.d.ts.map +1 -0
  202. package/dist/core/tools/renderers/edit.js +207 -0
  203. package/dist/core/tools/renderers/edit.js.map +1 -0
  204. package/dist/core/tools/renderers/find.d.ts +10 -0
  205. package/dist/core/tools/renderers/find.d.ts.map +1 -0
  206. package/dist/core/tools/renderers/find.js +64 -0
  207. package/dist/core/tools/renderers/find.js.map +1 -0
  208. package/dist/core/tools/renderers/grep.d.ts +10 -0
  209. package/dist/core/tools/renderers/grep.d.ts.map +1 -0
  210. package/dist/core/tools/renderers/grep.js +69 -0
  211. package/dist/core/tools/renderers/grep.js.map +1 -0
  212. package/dist/core/tools/renderers/index.d.ts +34 -0
  213. package/dist/core/tools/renderers/index.d.ts.map +1 -0
  214. package/dist/core/tools/renderers/index.js +47 -0
  215. package/dist/core/tools/renderers/index.js.map +1 -0
  216. package/dist/core/tools/renderers/ls.d.ts +10 -0
  217. package/dist/core/tools/renderers/ls.d.ts.map +1 -0
  218. package/dist/core/tools/renderers/ls.js +58 -0
  219. package/dist/core/tools/renderers/ls.js.map +1 -0
  220. package/dist/core/tools/renderers/read.d.ts +11 -0
  221. package/dist/core/tools/renderers/read.d.ts.map +1 -0
  222. package/dist/core/tools/renderers/read.js +132 -0
  223. package/dist/core/tools/renderers/read.js.map +1 -0
  224. package/dist/core/tools/renderers/write.d.ts +10 -0
  225. package/dist/core/tools/renderers/write.d.ts.map +1 -0
  226. package/dist/core/tools/renderers/write.js +152 -0
  227. package/dist/core/tools/renderers/write.js.map +1 -0
  228. package/dist/core/tools/write.d.ts.map +1 -1
  229. package/dist/core/tools/write.js +6 -146
  230. package/dist/core/tools/write.js.map +1 -1
  231. package/dist/core/usage-totals.d.ts +1 -1
  232. package/dist/core/usage-totals.d.ts.map +1 -1
  233. package/dist/core/usage-totals.js +5 -1
  234. package/dist/core/usage-totals.js.map +1 -1
  235. package/dist/extensions/llama/client.d.ts +2 -0
  236. package/dist/extensions/llama/client.d.ts.map +1 -1
  237. package/dist/extensions/llama/client.js +7 -3
  238. package/dist/extensions/llama/client.js.map +1 -1
  239. package/dist/extensions/llama/provider.d.ts.map +1 -1
  240. package/dist/extensions/llama/provider.js +20 -5
  241. package/dist/extensions/llama/provider.js.map +1 -1
  242. package/dist/index.d.ts +5 -4
  243. package/dist/index.d.ts.map +1 -1
  244. package/dist/index.js +1 -1
  245. package/dist/index.js.map +1 -1
  246. package/dist/main.d.ts.map +1 -1
  247. package/dist/main.js +21 -13
  248. package/dist/main.js.map +1 -1
  249. package/dist/modes/interactive/bug-report.d.ts +16 -0
  250. package/dist/modes/interactive/bug-report.d.ts.map +1 -0
  251. package/dist/modes/interactive/bug-report.js +167 -0
  252. package/dist/modes/interactive/bug-report.js.map +1 -0
  253. package/dist/modes/interactive/chat-viewport.d.ts +20 -0
  254. package/dist/modes/interactive/chat-viewport.d.ts.map +1 -0
  255. package/dist/modes/interactive/chat-viewport.js +28 -0
  256. package/dist/modes/interactive/chat-viewport.js.map +1 -0
  257. package/dist/modes/interactive/components/assistant-message.d.ts +7 -0
  258. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  259. package/dist/modes/interactive/components/assistant-message.js +63 -17
  260. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  261. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  262. package/dist/modes/interactive/components/branch-summary-message.js +12 -5
  263. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  264. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  265. package/dist/modes/interactive/components/compaction-summary-message.js +12 -5
  266. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  267. package/dist/modes/interactive/components/custom-editor.d.ts +12 -0
  268. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  269. package/dist/modes/interactive/components/custom-editor.js +38 -0
  270. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  271. package/dist/modes/interactive/components/error-summary.d.ts +11 -0
  272. package/dist/modes/interactive/components/error-summary.d.ts.map +1 -0
  273. package/dist/modes/interactive/components/error-summary.js +31 -0
  274. package/dist/modes/interactive/components/error-summary.js.map +1 -0
  275. package/dist/modes/interactive/components/extension-editor.d.ts +4 -1
  276. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  277. package/dist/modes/interactive/components/extension-editor.js +6 -1
  278. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  279. package/dist/modes/interactive/components/extension-input.d.ts +2 -0
  280. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  281. package/dist/modes/interactive/components/extension-input.js +6 -0
  282. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  283. package/dist/modes/interactive/components/extension-selector.d.ts +2 -0
  284. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  285. package/dist/modes/interactive/components/extension-selector.js +4 -0
  286. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  287. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  288. package/dist/modes/interactive/components/footer.js +4 -1
  289. package/dist/modes/interactive/components/footer.js.map +1 -1
  290. package/dist/modes/interactive/components/index.d.ts +1 -1
  291. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  292. package/dist/modes/interactive/components/index.js.map +1 -1
  293. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  294. package/dist/modes/interactive/components/model-selector.js +3 -3
  295. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  296. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  297. package/dist/modes/interactive/components/scoped-models-selector.js +13 -15
  298. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  299. package/dist/modes/interactive/components/session-selector.d.ts +5 -5
  300. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  301. package/dist/modes/interactive/components/session-selector.js +74 -48
  302. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  303. package/dist/modes/interactive/components/settings-selector.d.ts +5 -1
  304. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  305. package/dist/modes/interactive/components/settings-selector.js +35 -10
  306. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  307. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  308. package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
  309. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  310. package/dist/modes/interactive/components/status-indicator.d.ts +3 -1
  311. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  312. package/dist/modes/interactive/components/status-indicator.js +10 -3
  313. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  314. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  315. package/dist/modes/interactive/components/thinking-selector.js +6 -6
  316. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  317. package/dist/modes/interactive/components/tool-execution.d.ts +27 -5
  318. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  319. package/dist/modes/interactive/components/tool-execution.js +64 -42
  320. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  321. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  322. package/dist/modes/interactive/components/tree-selector.js +9 -0
  323. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  324. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  325. package/dist/modes/interactive/components/trust-selector.js +2 -2
  326. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  327. package/dist/modes/interactive/interactive-mode.d.ts +43 -29
  328. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  329. package/dist/modes/interactive/interactive-mode.js +431 -166
  330. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  331. package/dist/modes/interactive/theme/dark.json +2 -1
  332. package/dist/modes/interactive/theme/light.json +2 -1
  333. package/dist/modes/interactive/theme/theme-controller.d.ts +1 -0
  334. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  335. package/dist/modes/interactive/theme/theme-controller.js +5 -0
  336. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  337. package/dist/modes/interactive/theme/theme-json.d.ts +84 -0
  338. package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -0
  339. package/dist/modes/interactive/theme/theme-json.js +130 -0
  340. package/dist/modes/interactive/theme/theme-json.js.map +1 -0
  341. package/dist/modes/interactive/theme/theme-schema.json +6 -2
  342. package/dist/modes/interactive/theme/theme.d.ts +14 -5
  343. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  344. package/dist/modes/interactive/theme/theme.js +18 -119
  345. package/dist/modes/interactive/theme/theme.js.map +1 -1
  346. package/dist/modes/interactive/tui-renderer.d.ts +21 -0
  347. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -0
  348. package/dist/modes/interactive/tui-renderer.js +66 -0
  349. package/dist/modes/interactive/tui-renderer.js.map +1 -0
  350. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  351. package/dist/modes/rpc/rpc-mode.js +2 -2
  352. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  353. package/dist/package-manager-cli.d.ts.map +1 -1
  354. package/dist/package-manager-cli.js +31 -72
  355. package/dist/package-manager-cli.js.map +1 -1
  356. package/dist/testing/replay/recorded-provider.d.ts +2 -2
  357. package/dist/testing/replay/recorded-provider.d.ts.map +1 -1
  358. package/dist/testing/replay/recorded-provider.js +2 -5
  359. package/dist/testing/replay/recorded-provider.js.map +1 -1
  360. package/dist/testing/replay/runner.d.ts.map +1 -1
  361. package/dist/testing/replay/runner.js +0 -1
  362. package/dist/testing/replay/runner.js.map +1 -1
  363. package/dist/utils/clipboard-command.d.ts +7 -0
  364. package/dist/utils/clipboard-command.d.ts.map +1 -0
  365. package/dist/utils/clipboard-command.js +45 -0
  366. package/dist/utils/clipboard-command.js.map +1 -0
  367. package/dist/utils/clipboard-image.d.ts.map +1 -1
  368. package/dist/utils/clipboard-image.js +53 -81
  369. package/dist/utils/clipboard-image.js.map +1 -1
  370. package/dist/utils/clipboard.d.ts.map +1 -1
  371. package/dist/utils/clipboard.js +111 -121
  372. package/dist/utils/clipboard.js.map +1 -1
  373. package/dist/utils/exif-orientation.d.ts.map +1 -1
  374. package/dist/utils/exif-orientation.js +2 -3
  375. package/dist/utils/exif-orientation.js.map +1 -1
  376. package/dist/utils/mime.d.ts.map +1 -1
  377. package/dist/utils/mime.js +1 -1
  378. package/dist/utils/mime.js.map +1 -1
  379. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  380. package/dist/utils/syntax-highlight.js +21 -21
  381. package/dist/utils/syntax-highlight.js.map +1 -1
  382. package/dist/utils/tool-result-images.d.ts +3 -1
  383. package/dist/utils/tool-result-images.d.ts.map +1 -1
  384. package/dist/utils/tool-result-images.js +4 -1
  385. package/dist/utils/tool-result-images.js.map +1 -1
  386. package/dist/utils/tools-manager.d.ts.map +1 -1
  387. package/dist/utils/tools-manager.js +11 -2
  388. package/dist/utils/tools-manager.js.map +1 -1
  389. package/dist/utils/wsl.d.ts +3 -0
  390. package/dist/utils/wsl.d.ts.map +1 -0
  391. package/dist/utils/wsl.js +15 -0
  392. package/dist/utils/wsl.js.map +1 -0
  393. package/dist/utils/zip.d.ts +7 -0
  394. package/dist/utils/zip.d.ts.map +1 -0
  395. package/dist/utils/zip.js +60 -0
  396. package/dist/utils/zip.js.map +1 -0
  397. package/docs/cli-integration.md +107 -0
  398. package/docs/cli.md +269 -0
  399. package/docs/compaction.md +73 -24
  400. package/docs/configuration.md +45 -0
  401. package/docs/containerization.md +22 -21
  402. package/docs/custom-provider.md +21 -12
  403. package/docs/development.md +19 -0
  404. package/docs/docs.json +139 -95
  405. package/docs/extensions.md +243 -371
  406. package/docs/how-pi-works.md +49 -0
  407. package/docs/images/interactive-mode.png +0 -0
  408. package/docs/index.md +3 -3
  409. package/docs/json.md +7 -3
  410. package/docs/keybindings.md +57 -54
  411. package/docs/llama-cpp.md +2 -2
  412. package/docs/message-types.md +261 -0
  413. package/docs/models.md +103 -49
  414. package/docs/packages.md +49 -47
  415. package/docs/prompt-templates.md +29 -56
  416. package/docs/providers.md +91 -139
  417. package/docs/quickstart.md +42 -14
  418. package/docs/rpc-commands.md +854 -0
  419. package/docs/rpc-extension-ui.md +200 -0
  420. package/docs/rpc.md +121 -223
  421. package/docs/sdk.md +99 -124
  422. package/docs/security.md +7 -7
  423. package/docs/session-format.md +85 -82
  424. package/docs/sessions.md +41 -57
  425. package/docs/settings.md +94 -87
  426. package/docs/shell-aliases.md +68 -3
  427. package/docs/skills.md +62 -49
  428. package/docs/slash-commands.md +60 -0
  429. package/docs/terminal-setup.md +86 -55
  430. package/docs/termux.md +65 -75
  431. package/docs/themes.md +64 -86
  432. package/docs/tmux.md +29 -7
  433. package/docs/tui.md +67 -122
  434. package/docs/usage.md +31 -42
  435. package/docs/windows.md +41 -13
  436. package/examples/README.md +16 -2
  437. package/examples/extensions/README.md +0 -1
  438. package/examples/extensions/custom-provider-anthropic/index.ts +18 -12
  439. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  440. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  441. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  442. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  443. package/examples/extensions/dynamic-resources/dynamic.json +2 -0
  444. package/examples/extensions/gondolin/package-lock.json +2 -2
  445. package/examples/extensions/gondolin/package.json +1 -1
  446. package/examples/extensions/prompt-customizer.ts +19 -67
  447. package/examples/extensions/sandbox/package-lock.json +2 -2
  448. package/examples/extensions/sandbox/package.json +1 -1
  449. package/examples/extensions/with-deps/package-lock.json +2 -2
  450. package/examples/extensions/with-deps/package.json +1 -1
  451. package/examples/plugins/pi-example-plugin/README.md +38 -0
  452. package/examples/plugins/pi-example-plugin/package.json +10 -0
  453. package/examples/plugins/pi-example-plugin/src/contract.ts +13 -0
  454. package/examples/plugins/pi-example-plugin/src/session.ts +24 -0
  455. package/examples/plugins/pi-example-plugin/src/tui.ts +31 -0
  456. package/examples/rpc-client.ts +35 -0
  457. package/examples/rpc-extension-ui.ts +25 -5
  458. package/examples/sdk/README.md +1 -1
  459. package/npm-shrinkwrap.json +861 -513
  460. package/package.json +27 -18
  461. package/dist/bun/register-bedrock.d.ts +0 -2
  462. package/dist/bun/register-bedrock.d.ts.map +0 -1
  463. package/dist/bun/register-bedrock.js +0 -4
  464. package/dist/bun/register-bedrock.js.map +0 -1
  465. package/dist/cli/experimental/auth.d.ts +0 -16
  466. package/dist/cli/experimental/auth.d.ts.map +0 -1
  467. package/dist/cli/experimental/auth.js +0 -13
  468. package/dist/cli/experimental/auth.js.map +0 -1
  469. package/dist/cli/experimental/cli.d.ts +0 -6
  470. package/dist/cli/experimental/cli.d.ts.map +0 -1
  471. package/dist/cli/experimental/cli.js +0 -5
  472. package/dist/cli/experimental/cli.js.map +0 -1
  473. package/dist/cli/experimental/command-options.d.ts +0 -17
  474. package/dist/cli/experimental/command-options.d.ts.map +0 -1
  475. package/dist/cli/experimental/command-options.js +0 -35
  476. package/dist/cli/experimental/command-options.js.map +0 -1
  477. package/dist/cli/experimental/command.d.ts +0 -63
  478. package/dist/cli/experimental/command.d.ts.map +0 -1
  479. package/dist/cli/experimental/command.js +0 -130
  480. package/dist/cli/experimental/command.js.map +0 -1
  481. package/dist/cli/experimental/commands/client.d.ts +0 -13
  482. package/dist/cli/experimental/commands/client.d.ts.map +0 -1
  483. package/dist/cli/experimental/commands/client.js +0 -25
  484. package/dist/cli/experimental/commands/client.js.map +0 -1
  485. package/dist/cli/experimental/commands/pi.d.ts +0 -15
  486. package/dist/cli/experimental/commands/pi.d.ts.map +0 -1
  487. package/dist/cli/experimental/commands/pi.js +0 -28
  488. package/dist/cli/experimental/commands/pi.js.map +0 -1
  489. package/dist/cli/experimental/commands/server.d.ts +0 -13
  490. package/dist/cli/experimental/commands/server.d.ts.map +0 -1
  491. package/dist/cli/experimental/commands/server.js +0 -25
  492. package/dist/cli/experimental/commands/server.js.map +0 -1
  493. package/dist/cli/experimental/transport-address.d.ts +0 -10
  494. package/dist/cli/experimental/transport-address.d.ts.map +0 -1
  495. package/dist/cli/experimental/transport-address.js +0 -38
  496. package/dist/cli/experimental/transport-address.js.map +0 -1
  497. package/dist/client/index.d.ts +0 -3
  498. package/dist/client/index.d.ts.map +0 -1
  499. package/dist/client/index.js +0 -3
  500. package/dist/client/index.js.map +0 -1
  501. package/dist/client/remote-session.d.ts +0 -53
  502. package/dist/client/remote-session.d.ts.map +0 -1
  503. package/dist/client/remote-session.js +0 -340
  504. package/dist/client/remote-session.js.map +0 -1
  505. package/dist/client/transcript.d.ts +0 -12
  506. package/dist/client/transcript.d.ts.map +0 -1
  507. package/dist/client/transcript.js +0 -98
  508. package/dist/client/transcript.js.map +0 -1
  509. package/dist/utils/clipboard-native.d.ts +0 -11
  510. package/dist/utils/clipboard-native.d.ts.map +0 -1
  511. package/dist/utils/clipboard-native.js +0 -20
  512. package/dist/utils/clipboard-native.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.js","sourceRoot":"","sources":["../../src/utils/zip.ts"],"names":[],"mappings":"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","sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { crc32, deflateRawSync } from \"node:zlib\";\n\ninterface ZipEntry {\n\tname: string;\n\tdata: string | Uint8Array;\n}\n\nfunction dosDateTime(date: Date): { time: number; day: number } {\n\treturn {\n\t\ttime: (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1),\n\t\tday: ((Math.max(1980, date.getFullYear()) - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate(),\n\t};\n}\n\n/** Create the small, classic ZIP archives used by bug reports. */\nfunction createZipArchive(entries: readonly ZipEntry[]): Buffer {\n\tconst files: Buffer[] = [];\n\tconst directory: Buffer[] = [];\n\tconst { time, day } = dosDateTime(new Date());\n\tlet offset = 0;\n\n\tfor (const entry of entries) {\n\t\tconst name = Buffer.from(entry.name);\n\t\tconst data = typeof entry.data === \"string\" ? Buffer.from(entry.data) : Buffer.from(entry.data);\n\t\tconst compressed = deflateRawSync(data);\n\t\tconst checksum = crc32(data);\n\n\t\tconst local = Buffer.alloc(30);\n\t\tlocal.writeUInt32LE(0x04034b50, 0);\n\t\tlocal.writeUInt16LE(20, 4);\n\t\tlocal.writeUInt16LE(0x0800, 6);\n\t\tlocal.writeUInt16LE(8, 8);\n\t\tlocal.writeUInt16LE(time, 10);\n\t\tlocal.writeUInt16LE(day, 12);\n\t\tlocal.writeUInt32LE(checksum, 14);\n\t\tlocal.writeUInt32LE(compressed.length, 18);\n\t\tlocal.writeUInt32LE(data.length, 22);\n\t\tlocal.writeUInt16LE(name.length, 26);\n\n\t\tconst central = Buffer.alloc(46);\n\t\tcentral.writeUInt32LE(0x02014b50, 0);\n\t\tcentral.writeUInt16LE(20, 4);\n\t\tcentral.writeUInt16LE(20, 6);\n\t\tcentral.writeUInt16LE(0x0800, 8);\n\t\tcentral.writeUInt16LE(8, 10);\n\t\tcentral.writeUInt16LE(time, 12);\n\t\tcentral.writeUInt16LE(day, 14);\n\t\tcentral.writeUInt32LE(checksum, 16);\n\t\tcentral.writeUInt32LE(compressed.length, 20);\n\t\tcentral.writeUInt32LE(data.length, 24);\n\t\tcentral.writeUInt16LE(name.length, 28);\n\t\tcentral.writeUInt32LE(offset, 42);\n\n\t\tfiles.push(local, name, compressed);\n\t\tdirectory.push(central, name);\n\t\toffset += local.length + name.length + compressed.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(directory);\n\tconst end = Buffer.alloc(22);\n\tend.writeUInt32LE(0x06054b50, 0);\n\tend.writeUInt16LE(entries.length, 8);\n\tend.writeUInt16LE(entries.length, 10);\n\tend.writeUInt32LE(centralDirectory.length, 12);\n\tend.writeUInt32LE(offset, 16);\n\treturn Buffer.concat([...files, centralDirectory, end]);\n}\n\nexport function writeZipArchive(filePath: string, entries: readonly ZipEntry[]): Promise<void> {\n\treturn writeFile(filePath, createZipArchive(entries));\n}\n"]}
@@ -0,0 +1,107 @@
1
+ # CLI Integration
2
+
3
+ By default, running `apex-code` opens the interactive terminal interface. When input or output is piped or redirected, Apex Code uses print mode instead. You can also select print, JSON, RPC, or ACP mode explicitly for scripts and applications.
4
+
5
+ All five modes use the same agent, sessions, resources, and tools. The mode determines how input enters Apex Code, how output is exposed, and whether the process remains available for more commands.
6
+
7
+ The SDK is not a CLI mode. It embeds the agent directly in a Node.js or Bun process. See the [SDK](sdk.md) when direct TypeScript access is preferable to a process boundary.
8
+
9
+ ## Choose a mode
10
+
11
+ | Mode | Interface | Lifetime | Use it when |
12
+ |---|---|---|---|
13
+ | Interactive | Terminal UI | Until the user exits | A person is working with Apex Code directly |
14
+ | Print | Final text on stdout | One invocation | A script needs the final assistant response |
15
+ | JSON | JSONL events on stdout | One invocation | A process needs structured progress from a run |
16
+ | RPC | JSONL commands, responses, and events | Long-lived | A process needs bidirectional control |
17
+ | ACP | ACP v1 JSON-RPC on stdio | Long-lived | An ACP host needs to manage sessions and tool permissions |
18
+
19
+ CLI options still select the working directory, model, tools, resources, and session persistence independently of the mode. See [Command Line](cli.md) for the complete startup options.
20
+
21
+ ## Print to stdout
22
+
23
+ Print mode runs the supplied prompts, writes the final assistant text to stdout, and exits:
24
+
25
+ ```bash
26
+ apex-code --print "Summarize the changes in this repository"
27
+ ```
28
+
29
+ Use print mode when only the final text is needed, including command substitution, pipelines, and one-shot jobs. Intermediate events are not exposed.
30
+
31
+ Print mode writes errors to stderr. A final assistant response with an `error` or `aborted` stop reason produces a nonzero exit status.
32
+
33
+ When no mode is selected explicitly, non-TTY stdin or stdout also selects print mode. This allows piped input and output without adding `--print`.
34
+
35
+ ## Stream JSON events
36
+
37
+ JSON mode writes a session header followed by agent and session events as newline-delimited JSON:
38
+
39
+ ```bash
40
+ apex-code --mode json "Review this repository" > events.jsonl
41
+ ```
42
+
43
+ This is structured event output, not a single JSON result or a constraint on the format of the model’s response.
44
+
45
+ All prompts are supplied when the process starts. The process streams events for that run and then exits; it does not accept later commands.
46
+
47
+ A failed or aborted assistant response appears in the event stream but does not by itself produce a nonzero exit status. Inspect the events when success or failure matters. Apex Code still exits nonzero if the invocation throws an error.
48
+
49
+ Streaming `message_update` records contain deltas rather than a growing message snapshot. Assemble live output from the delta events, then replace it with the authoritative message from `message_end`.
50
+
51
+ `agent_end` can be followed by automatic recovery or queued work. `agent_settled` marks the end of automatic work for the current run.
52
+
53
+ Stdout is reserved for JSONL. Diagnostics and application logging are written to stderr. See [JSON Event Stream](json.md) for framing, event shapes, and reconstruction rules.
54
+
55
+ ## Control Apex Code with RPC
56
+
57
+ RPC mode keeps Apex Code running while another process sends commands and receives responses and events:
58
+
59
+ ```bash
60
+ apex-code --mode rpc --no-session
61
+ ```
62
+
63
+ Commands are JSON objects written to stdin. Responses and events are JSON objects written to stdout. Every record occupies one line.
64
+
65
+ Add an `id` to commands that need correlation. The matching response repeats that ID. Events generally have no command ID because they describe session activity rather than one request.
66
+
67
+ A successful `prompt` response means the prompt was accepted, queued, or handled. It does not mean the run completed. Continue consuming events through `agent_settled` when completion matters.
68
+
69
+ RPC commands can change models, inspect state, manage sessions, run shell commands, and answer extension UI requests.
70
+
71
+ Extension dialogs form a request-response subprotocol. Other extension UI updates are notifications that a client may display or ignore. TUI-only extension capabilities are unavailable or degraded outside interactive mode.
72
+
73
+ For Node.js or TypeScript integrations, prefer `RpcClient` from `@earendil-works/pi-coding-agent`. It starts an Apex Code RPC child process, correlates requests, exposes typed command methods, and delivers session events to listeners.
74
+
75
+ The [RPC client example](../examples/rpc-client.ts) sends one prompt, streams text and tool activity, waits for `agent_settled`, and shuts down the child process. It is included in the repository’s TypeScript checks.
76
+
77
+ `RpcClient.promptAndWait()` installs its event listener before sending the prompt, avoiding a race with fast completions. For separate operations, subscribe before calling `prompt()` and call `waitForIdle()` only while a run is active.
78
+
79
+ The client requires a path to a runnable Apex Code CLI. The repository example points at `dist/cli.js`, so the package must be built before that example runs from a checkout.
80
+
81
+ If you are building a client without `RpcClient`, start with [RPC Protocol](rpc.md), then use [RPC Commands](rpc-commands.md) and [JSON Event Stream](json.md) as the wire references.
82
+
83
+ ## Fork and rebrand Apex Code
84
+
85
+ A source fork can change the CLI name and configuration directory through `package.json`:
86
+
87
+ ```json
88
+ {
89
+ "piConfig": {
90
+ "name": "my-agent",
91
+ "configDir": ".my-agent"
92
+ }
93
+ }
94
+ ```
95
+
96
+ Change the top-level `bin` field to set the executable name. These settings affect the CLI banner, configuration paths, and derived environment variable names.
97
+
98
+ ## Examples and references
99
+
100
+ - [RPC client](../examples/rpc-client.ts): typed Node.js integration
101
+ - [RPC extension UI](../examples/rpc-extension-ui.ts): custom terminal client with extension dialogs
102
+ - [Command Line](cli.md): startup options and mode selection
103
+ - [JSON Event Stream](json.md): JSON event reference
104
+ - [RPC Protocol](rpc.md): RPC lifecycle, framing, errors, and shutdown
105
+ - [RPC Commands](rpc-commands.md): command and response reference
106
+ - [RPC Extension UI](rpc-extension-ui.md): extension interaction subprotocol
107
+ - [SDK examples](../examples/sdk/): in-process TypeScript integrations
package/docs/cli.md ADDED
@@ -0,0 +1,269 @@
1
+ <a id="cli-and-modes-reference"></a>
2
+
3
+ # Command Line
4
+
5
+ This page documents Apex Code's built-in command-line commands and options. Run `apex-code --help` or append `--help` to a command for the exact interface in your installed version. The top-level help also includes options registered by loaded extensions.
6
+
7
+ ```sh
8
+ apex-code [options] [--] [@files...] [messages...]
9
+ apex-code install <source> [options]
10
+ apex-code remove <source> [options]
11
+ apex-code uninstall <source> [options]
12
+ apex-code update [target] [options]
13
+ apex-code list
14
+ apex-code config [options]
15
+ apex-code auth <check|print-api-key|print-bearer-token> [options]
16
+ ```
17
+
18
+ <a id="modes"></a>
19
+
20
+ ## Invocation and output
21
+
22
+ ```sh
23
+ apex-code
24
+ apex-code --print "Summarize this repository"
25
+ git diff | apex-code --print "Review this change"
26
+ apex-code --mode json "Inspect this repository" > events.jsonl
27
+ ```
28
+
29
+ With terminal stdin and stdout, Apex Code opens the terminal UI unless `--print`, `--mode json`, or `--mode rpc` selects another interface. When either stream is redirected and neither JSON nor RPC mode is selected, Apex Code uses print mode. See [CLI Integration](cli-integration.md) for choosing between interactive, print, JSON, RPC, and SDK integration.
30
+
31
+ | Input | Behavior |
32
+ |---|---|
33
+ | `message` | Provide an initial prompt |
34
+ | `@path` | Include a text file or image in the first prompt |
35
+ | Piped stdin | Prepend its contents to the first prompt |
36
+ | `--` | Stop option parsing so a prompt can begin with `-` |
37
+
38
+ Apex Code resolves `@path` from the current working directory. The working directory also controls project configuration, resource discovery, and session grouping.
39
+
40
+ `--print` controls whether Apex Code runs once and exits. `--mode` selects the output interface. `--mode text` does not force one-shot execution when stdin and stdout are terminals; use `--print` for that behavior.
41
+
42
+ | Option | Behavior |
43
+ |---|---|
44
+ | `-p`, `--print` | Run the supplied prompts, write the final assistant text to stdout, then exit |
45
+ | `--mode text` | Select text output; still open the terminal UI when stdin and stdout are terminals |
46
+ | `--mode json` | Run the supplied prompts, write JSONL events to stdout, then exit |
47
+ | `--mode rpc` | Read JSONL commands from stdin and write responses and events to stdout until shutdown |
48
+ | `--mode acp` | Run the ACP v1 agent protocol over newline-delimited JSON-RPC on stdin and stdout |
49
+ | `--export <input> [output]` | Export a session file to HTML and exit; derive the destination when `output` is omitted |
50
+
51
+ RPC mode rejects `@file` arguments. JSON and RPC modes reserve stdout for protocol records. See [JSON Event Stream](json.md) and [RPC Protocol](rpc.md).
52
+
53
+ <a id="model-options"></a>
54
+
55
+ ## Models
56
+
57
+ ```sh
58
+ apex-code --model sonnet:high
59
+ ```
60
+
61
+ See [Choose a Model](models.md) for model selection and [Provider Authentication](providers.md) for credentials.
62
+
63
+ - `--provider <name>`<br>
64
+ Restricts `--model` lookup to one provider.
65
+ - `--model <pattern>`<br>
66
+ Selects by exact ID or fuzzy ID/name match. It accepts `provider/id` and an optional `:<thinking>` suffix.
67
+ - `--api-key <key>`<br>
68
+ Uses a non-persistent API-key override. It requires a model selected through `--model` or `--models`.
69
+ - `--thinking <level>`<br>
70
+ Sets `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`. It overrides a `--model` suffix and is clamped to the model's capabilities.
71
+ - `--models <patterns>`<br>
72
+ Sets a comma-separated scope for startup and cycling. It accepts exact IDs, fuzzy matches, case-insensitive globs, and optional `:<thinking>` suffixes.
73
+ - `--list-models [search]`<br>
74
+ Lists available models, optionally filtered by a fuzzy search, then exits.
75
+
76
+ <a id="session-options"></a>
77
+
78
+ ## Sessions
79
+
80
+ ```sh
81
+ apex-code --continue
82
+ ```
83
+
84
+ See [Sessions and Context](sessions.md) for resuming, forking, naming, and storing sessions.
85
+
86
+ - `-c`, `--continue`<br>
87
+ Continues the most recent session for the current project.
88
+ - `-r`, `--resume`<br>
89
+ Opens the session selector.
90
+ - `--session <path|id>`<br>
91
+ Opens by file path, exact ID, or partial ID. Apex Code searches the current project first and offers to fork a cross-project match.
92
+ - `--session-id <id>`<br>
93
+ Opens the exact project session ID or creates it if absent. IDs accept letters, numbers, `.`, `_`, and `-`.
94
+ - `--fork <path|id>`<br>
95
+ Forks an existing session into a new session for the current project.
96
+ - `--session-dir <dir>`<br>
97
+ Overrides storage and lookup. It takes precedence over `PI_CODING_AGENT_SESSION_DIR` and the `sessionDir` setting.
98
+ - `--no-session`<br>
99
+ Uses an in-memory session that is not persisted.
100
+ - `-n`, `--name <name>`<br>
101
+ Sets the session display name.
102
+
103
+ Constraints:
104
+
105
+ - Session IDs must start and end with a letter or number.
106
+ - `--fork` cannot be combined with `--session`, `--continue`, `--resume`, or `--no-session`.
107
+ - `--session-id` cannot be combined with `--session`, `--continue`, or `--resume`. Combine it with `--fork` to choose the new ID.
108
+
109
+ <a id="tool-options"></a>
110
+
111
+ ## Tools
112
+
113
+ ```sh
114
+ apex-code --tools read,grep,find,ls --print "Review this project"
115
+ ```
116
+
117
+ See [Settings](settings.md#tools) for configuring the default tool selection.
118
+
119
+ - `-t`, `--tools <list>`<br>
120
+ Replaces the default selection with a comma-separated allowlist of built-in, extension, or custom tools.
121
+ - `-xt`, `--exclude-tools <list>`<br>
122
+ Disables comma-separated tool names after all other selection options.
123
+ - `-nbt`, `--no-builtin-tools`<br>
124
+ Disables default built-in tools while retaining extension and custom tools.
125
+ - `-nt`, `--no-tools`<br>
126
+ Starts with all built-in, extension, and custom tools disabled.
127
+
128
+ Default enabled tools are `read`, `bash`, `edit`, and `write`, unless `defaultTools` changes them.
129
+
130
+ | Built-in | Purpose |
131
+ |---|---|
132
+ | `read` | Read text files and supported images |
133
+ | `bash` | Run shell commands |
134
+ | `powershell` | Run PowerShell commands on Windows |
135
+ | `edit` | Apply exact text replacements to an existing file |
136
+ | `write` | Create or overwrite a file |
137
+ | `grep` | Search file contents |
138
+ | `find` | Find paths using glob patterns |
139
+ | `ls` | List directory contents |
140
+
141
+ <a id="resource-options"></a>
142
+
143
+ ## Resources
144
+
145
+ ```sh
146
+ apex-code --extension ./review.ts
147
+ ```
148
+
149
+ See [Configuration](configuration.md) for conventional directories and project trust, [Settings](settings.md#resources) for configured paths, and [Apex Code Packages](packages.md) for package sources.
150
+
151
+ - `-e`, `--extension <path>`<br>
152
+ Loads an extension file or directory and is repeatable.
153
+ - `-ne`, `--no-extensions`<br>
154
+ Disables discovered and configured extensions. Explicit `-e` paths still load.
155
+ - `--skill <path>`<br>
156
+ Loads a skill file or directory and is repeatable.
157
+ - `-ns`, `--no-skills`<br>
158
+ Disables discovered and configured skills. Explicit `--skill` paths still load.
159
+ - `--prompt-template <path>`<br>
160
+ Loads a prompt-template file or directory and is repeatable.
161
+ - `-np`, `--no-prompt-templates`<br>
162
+ Disables discovered and configured templates. Explicit `--prompt-template` paths still load.
163
+ - `--theme <path>`<br>
164
+ Loads a theme file or directory and is repeatable.
165
+ - `--use-theme <name[/name]>`<br>
166
+ Selects the initial interactive theme for this run.
167
+ - `--no-themes`<br>
168
+ Disables discovered and configured themes. Explicit `--theme` paths still load.
169
+ - `-nc`, `--no-context-files`<br>
170
+ Disables `AGENTS.md` and `CLAUDE.md` discovery.
171
+
172
+ Resource paths apply only to the current process. Relative paths resolve from the current working directory.
173
+
174
+ <a id="prompt-and-display-options"></a>
175
+
176
+ ## Prompts and process
177
+
178
+ ```sh
179
+ apex-code --append-system-prompt ./instructions.md
180
+ ```
181
+
182
+ See [Configuration](configuration.md) for saved configuration, [Security](security.md#understand-project-trust) for project trust, and [Environment Variables](environment-variables.md) for process controls.
183
+
184
+ - `--system-prompt <text|path>`<br>
185
+ Replaces the default system prompt with text or the contents of an existing file.
186
+ - `--append-system-prompt <text|path>`<br>
187
+ Appends text or an existing file to the system prompt and is repeatable.
188
+ - `--tui-mode <mode>`<br>
189
+ Uses `regular` or `fullscreen` terminal mode.
190
+ - `--verbose`<br>
191
+ Shows verbose interactive startup information, overriding `quietStartup`.
192
+ - `-a`, `--approve`<br>
193
+ Trusts project-local configuration and resources for this process.
194
+ - `-na`, `--no-approve`<br>
195
+ Ignores trust-gated project-local configuration and resources for this process.
196
+ - `--offline`<br>
197
+ Disables automatic network activity, including model catalog refreshes. Equivalent to `PI_OFFLINE=1`.
198
+ - `-h`, `--help`<br>
199
+ Shows help, including flags registered by loaded extensions, then exits.
200
+ - `-v`, `--version`<br>
201
+ Shows the Apex Code version, then exits.
202
+
203
+ Extensions may register additional long-form options. Unknown short options are rejected.
204
+
205
+ ## Package commands
206
+
207
+ ```sh
208
+ apex-code install npm:@scope/package
209
+ ```
210
+
211
+ See [Apex Code Packages](packages.md) for source formats, filtering, installation, and project scope.
212
+
213
+ ### Common tasks
214
+
215
+ | Task | Command |
216
+ |---|---|
217
+ | Install a package | `apex-code install <source>` |
218
+ | List configured packages | `apex-code list` |
219
+ | Remove a package and its settings entry | `apex-code remove <source>` |
220
+ | Configure which package resources load | `apex-code config` |
221
+
222
+ Add `--local` or `-l` to `install`, `remove`, `uninstall`, or `config` to use project settings instead of global settings.
223
+
224
+ ### Update Apex Code or packages
225
+
226
+ Running `apex-code update` without a target updates Apex Code itself.
227
+
228
+ | Task | Command |
229
+ |---|---|
230
+ | Update Apex Code | `apex-code update` |
231
+ | Update all installed packages | `apex-code update --extensions` |
232
+ | Update one installed package | `apex-code update <source>` |
233
+ | Refresh model catalogs | `apex-code update --models` |
234
+ | Update Apex Code and all installed packages | `apex-code update --all` |
235
+
236
+ Add `--force` to reinstall Apex Code when the selected update includes Apex Code.
237
+
238
+ ### Aliases and command options
239
+
240
+ - `apex-code uninstall <source>` is an alias for `apex-code remove <source>`.
241
+ - `apex-code update --self`, `apex-code update self`, and `apex-code update pi` are aliases for `apex-code update`.
242
+ - `apex-code update --extension <source>` is an alias for `apex-code update <source>`.
243
+ - `-a`, `--approve` trusts project-local files for one command. `-na`, `--no-approve` ignores trust-gated project-local files.
244
+ - Append `-h` or `--help` to a command for its exact usage and option constraints.
245
+
246
+ ## Credential commands
247
+
248
+ ```sh
249
+ apex-code auth check --provider openai --json
250
+ ```
251
+
252
+ Authentication commands require `--provider <provider>` or `--model <model>`. See [Provider Authentication](providers.md) for supported methods.
253
+
254
+ | Command | Description |
255
+ |---|---|
256
+ | `apex-code auth check` | Print `ready`, `not_ready`, or `invalid`; exit with status `0`, `1`, or `2`, respectively |
257
+ | `apex-code auth print-api-key` | Print the resolved API key |
258
+ | `apex-code auth print-bearer-token` | Print a resolved OAuth bearer token |
259
+
260
+ | Option | Applies to | Description |
261
+ |---|---|---|
262
+ | `--provider <provider>` | All | Resolve credentials for a provider |
263
+ | `--model <model>` | All | Resolve credentials from a model; may be combined with `--provider` |
264
+ | `--json` | `auth check` | Write the structured result as JSON |
265
+ | `--credentials` | `auth check` | Emit the resolved credential when ready |
266
+ | `--no-refresh` | `auth check` | Do not refresh expired OAuth credentials; refresh is the default |
267
+ | `--min-expiry <duration>` | `print-bearer-token` | Require remaining token lifetime using `ms`, `s`, `m`, or `h`, such as `30m` |
268
+
269
+ Credential-printing commands write secrets to stdout.
@@ -1,4 +1,4 @@
1
- # Compaction & Branch Summarization
1
+ # Compaction Reference
2
2
 
3
3
  LLMs have limited context windows. When conversations grow too long, Apex Code uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
4
4
 
@@ -20,7 +20,7 @@ Apex Code has two summarization mechanisms:
20
20
  | Compaction | Context exceeds threshold, or `/compact` | Summarize old messages to free up context |
21
21
  | Branch summarization | `/tree` navigation | Preserve context when switching branches |
22
22
 
23
- Both use the same structured summary format and track file operations cumulatively. Compaction and branch-summary requests use fresh routing session IDs and, where supported by the provider, disable prompt-cache writes because these one-off prompts are unlikely to be reused.
23
+ Both use closely related structured formats and track file operations cumulatively. Summarization requests disable prompt-cache writes because these one-off prompts are unlikely to be reused.
24
24
 
25
25
  ## Compaction
26
26
 
@@ -36,17 +36,19 @@ By default, `reserveTokens` is 16384 tokens (configurable in `~/.apex-code/agent
36
36
 
37
37
  Apex Code checks this threshold after every completed tool batch that would otherwise start another provider request. If a long tool run crosses the threshold, it compacts at that safe boundary and resumes the unfinished run.
38
38
 
39
- During a multi-turn agent run, Pi checks this threshold after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, Pi compacts inside the same agent run and resumes with the summary and retained messages. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. Pi also checks the threshold before a new user prompt and after a low-level agent run ends.
39
+ During a multi-turn agent run, Apex Code checks the finalized session projection after tools finish and before it starts the next assistant response. If the threshold is crossed, it compacts during `prepareNextTurn` and polls steering before `turn_start`. It skips this check when the tool batch ends the run and no queued message needs a response. Apex Code also checks before a new user prompt and performs overflow recovery after the low-level run ends.
40
+
41
+ A provider context-overflow error or an early final `stopReason: "length"` can select one compact-and-retry recovery attempt. Length responses with tool calls retain their synthetic failed tool results and follow the ordinary tool/queue scheduler rather than forcing the run to end.
40
42
 
41
43
  You can also trigger manually with `/compact [instructions]`, where optional instructions focus the summary.
42
44
 
43
45
  ### How It Works
44
46
 
45
- 1. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.apex-code/agent/settings.json` or `<project-dir>/.apex-code/settings.json`) is reached
46
- 2. **Extract messages**: Collect messages from the previous kept boundary (or session start) up to the cut point
47
- 3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present
48
- 4. **Append entry**: Save `CompactionEntry` with summary and `firstKeptEntryId`
49
- 5. **Rebuilds context**: Session rebuilds the context for the next request, using summary + messages from `firstKeptEntryId` onwards
47
+ 1. **Find the cut point**: Walk backward through the finalized session projection and accumulate token estimates until you reach `keepRecentTokens`. The default is 20k tokens. Configure it in `~/.apex-code/agent/settings.json` or `<project-dir>/.apex-code/settings.json`.
48
+ 2. **Extract messages**: Collect projected messages from the previous kept boundary, or from the session start, up to the cut point.
49
+ 3. **Generate the summary**: Ask the model for a structured summary and include the previous summary when one exists.
50
+ 4. **Append the entry**: Save a `CompactionEntry` with the summary and `firstKeptEntryId`.
51
+ 5. **Rebuild the context**: Include the summary and projected messages from `firstKeptEntryId` onward.
50
52
 
51
53
  ```
52
54
  Before compaction:
@@ -80,16 +82,33 @@ What the LLM sees:
80
82
  prompt from cmp messages from firstKeptEntryId
81
83
  ```
82
84
 
83
- On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. Apex Code also recalculates `tokensBefore` from the rebuilt session context before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced.
85
+ On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`). If that entry is missing from the path, compaction starts after the previous compaction. A retain-none compaction records its own ID as `firstKeptEntryId`, so the next pass starts after that entry. These rules preserve messages that survived an earlier compaction.
86
+
87
+ Apex Code recalculates `tokensBefore` from the rebuilt, context-edited session projection before it writes the new `CompactionEntry`. Omitted raw entries remain stored, but they do not affect cut selection, summaries, checkpoints, or token estimates.
88
+
89
+ ### Overflow and length recovery ordering
90
+
91
+ Recovery preserves the event order. The completed attempt remains visible to `turn_end` and `agent_end`. The session then repairs persisted model context before it retries:
92
+
93
+ ```text
94
+ persist final assistant response
95
+ → extension/public turn_end
96
+ → extension/public agent_end
97
+ → append context_edit omissions for the selected attempt
98
+ → for overflow/length: run session_before_compact and append compaction on success
99
+ → start the retry as a fresh run
100
+ ```
101
+
102
+ If recovery compaction fails or is cancelled, Apex Code keeps the omission edits, appends no compaction, and schedules no internal retry. Steering and follow-up queues keep their normal behavior. `agent_before_settle` sees the repaired projection. Raw transcript history, exports, billing totals, and history-search extensions can still inspect the omitted attempt.
84
103
 
85
- ### Split Turns
104
+ ### Split user-message spans
86
105
 
87
- A "turn" starts with a user message and includes all assistant responses and tool calls until the next user message. Normally, compaction cuts at turn boundaries.
106
+ A user-message span starts with a user message and includes all turns until the next user message. Normally, compaction cuts at user-message boundaries.
88
107
 
89
- When a single turn exceeds `keepRecentTokens`, the cut point lands mid-turn at an assistant message. This is a "split turn":
108
+ When one user-message span exceeds `keepRecentTokens`, the cut point lands within that span at an assistant message. This is a split user-message span:
90
109
 
91
110
  ```
92
- Split turn (one huge turn exceeds budget):
111
+ Split user-message span (one span exceeds budget):
93
112
 
94
113
  entry: 0 1 2 3 4 5 6 7 8
95
114
  ┌─────┬─────┬─────┬──────┬─────┬──────┬──────┬─────┬──────┐
@@ -102,13 +121,13 @@ Split turn (one huge turn exceeds budget):
102
121
  └── kept (7-8)
103
122
 
104
123
  isSplitTurn = true
105
- messagesToSummarize = [] (no complete turns before)
124
+ messagesToSummarize = [] (no earlier user-message spans)
106
125
  turnPrefixMessages = [usr, ass, tool, ass, tool, tool]
107
126
  ```
108
127
 
109
128
  For split turns, Apex Code generates two summaries and merges them:
110
129
  1. **History summary**: Previous context (if any)
111
- 2. **Turn prefix summary**: The early part of the split turn
130
+ 2. **User-message-span prefix summary**: The early part of the split user-message span
112
131
 
113
132
  ### Cut Point Rules
114
133
 
@@ -120,6 +139,8 @@ Valid cut points are:
120
139
 
121
140
  Never cut at tool results (they must stay with their tool call).
122
141
 
142
+ Preparation advances the kept boundary into a context-invisible suffix only when that suffix contains an omitted assistant attempt and no unomitted context-producing entries. Recovery `context_edit` omissions satisfy this rule; intrinsically context-invisible metadata may coexist with them. Metadata alone and newly appended custom messages do not move the cut. A replacement edit affecting the candidate input or summarized prefix also blocks advancement because the omitted assistant answered the pre-edit input; replacements of suffix entries that are ultimately omitted remain safe. This allows an over-budget recovered input to be summarized while retaining the edits that keep the abandoned attempt omitted, without making bookkeeping change whether new model input is preserved verbatim.
143
+
123
144
  ### CompactionEntry Structure
124
145
 
125
146
  Defined in [`session-manager.ts`](https://github.com/Fchery87/apex-code/blob/main/packages/coding-agent/src/core/session-manager.ts):
@@ -128,8 +149,8 @@ Defined in [`session-manager.ts`](https://github.com/Fchery87/apex-code/blob/mai
128
149
  interface CompactionEntry<T = unknown> {
129
150
  type: "compaction";
130
151
  id: string;
131
- parentId: string;
132
- timestamp: number;
152
+ parentId: string | null;
153
+ timestamp: string;
133
154
  summary: string;
134
155
  firstKeptEntryId: string;
135
156
  tokensBefore: number;
@@ -186,7 +207,7 @@ Both compaction and branch summarization track files cumulatively. When generati
186
207
  - Tool calls in the messages being summarized
187
208
  - Previous compaction or branch summary `details` (if any)
188
209
 
189
- This means file tracking accumulates across multiple compactions or nested branch summaries, preserving the full history of read and modified files.
210
+ File tracking therefore accumulates across default compactions and nested default branch summaries. Pi does not automatically carry file lists from extension-generated summaries whose `fromHook` field is `true`; extensions manage their own `details` format.
190
211
 
191
212
  ### BranchSummaryEntry Structure
192
213
 
@@ -196,8 +217,8 @@ Defined in [`session-manager.ts`](https://github.com/Fchery87/apex-code/blob/mai
196
217
  interface BranchSummaryEntry<T = unknown> {
197
218
  type: "branch_summary";
198
219
  id: string;
199
- parentId: string;
200
- timestamp: number;
220
+ parentId: string | null;
221
+ timestamp: string;
201
222
  summary: string;
202
223
  fromId: string; // Entry we navigated from
203
224
  usage?: Usage; // LLM usage that generated the summary
@@ -218,7 +239,9 @@ See [`collectEntriesForBranchSummary()`](https://github.com/Fchery87/apex-code/b
218
239
 
219
240
  ## Summary Format
220
241
 
221
- Both compaction and branch summarization use the same structured format:
242
+ Both formats include Goal, Constraints & Preferences, Progress, Key Decisions, and Next Steps. Compaction summaries also include Critical Context. Branch summaries stop after Next Steps. Pi appends file lists to either format when relevant.
243
+
244
+ Compaction summaries use this format:
222
245
 
223
246
  ```markdown
224
247
  ## Goal
@@ -285,12 +308,12 @@ pi.on("session_before_compact", async (event, ctx) => {
285
308
  const { preparation, branchEntries, customInstructions, reason, willRetry, signal } = event;
286
309
 
287
310
  // preparation.messagesToSummarize - messages to summarize
288
- // preparation.turnPrefixMessages - split turn prefix (if isSplitTurn)
311
+ // preparation.turnPrefixMessages - user-message-span prefix (if isSplitTurn)
289
312
  // preparation.previousSummary - previous compaction summary
290
313
  // preparation.fileOps - extracted file operations
291
314
  // preparation.tokensBefore - context tokens before compaction
292
315
  // preparation.firstKeptEntryId - where kept messages start
293
- // preparation.settings - compaction settings
316
+ // preparation.settings - effective settings after applying model overrides
294
317
 
295
318
  // branchEntries - all entries on current branch (for custom state)
296
319
  // reason - "manual" (/compact), "threshold", or "overflow"
@@ -359,7 +382,7 @@ pi.on("session_compact_failed", async (event, ctx) => {
359
382
  const { reason, errorMessage, aborted, willRetry, fromExtension } = event;
360
383
  // reason - "manual" (/compact), "threshold", or "overflow"
361
384
  // errorMessage - present for non-abort failures
362
- // aborted - true for cancelled/aborted compactions
385
+ // aborted - true for canceled/aborted compactions
363
386
  // willRetry - whether the aborted turn would have retried after compaction
364
387
  // fromExtension - whether extension-provided compaction content was being used
365
388
  });
@@ -418,3 +441,29 @@ Configure compaction in `~/.apex-code/agent/settings.json` or `<project-dir>/.ap
418
441
  | `keepRecentTokens` | `20000` | Recent tokens to keep (not summarized) |
419
442
 
420
443
  Disable auto-compaction with `"enabled": false`. You can still compact manually with `/compact`.
444
+
445
+ ### Per-model overrides
446
+
447
+ Use `compaction.modelOverrides` to tune token budgets for different models:
448
+
449
+ ```json
450
+ {
451
+ "compaction": {
452
+ "reserveTokens": 16384,
453
+ "keepRecentTokens": 20000,
454
+ "modelOverrides": {
455
+ "some-provider/big-model": {
456
+ "reserveTokens": 400000
457
+ }
458
+ }
459
+ }
460
+ }
461
+ ```
462
+
463
+ For a model with a 1M context window, this override triggers compaction above 600K tokens and keeps the ordinary 20000 recent tokens. Other models retain the ordinary 16384-token reserve. `reserveTokens` also influences summarization output limits, capped by the model's maximum output tokens; it is not solely a trigger threshold.
464
+
465
+ Keys are exact, case-sensitive `provider/modelId` values, including any slashes within the model ID. Each `reserveTokens` and `keepRecentTokens` value falls back independently from the model override to the ordinary setting to the built-in default. Values must be non-negative safe integers. Invalid values in the matching model override produce an error when read; only omitted fields fall back to the ordinary setting. Model override entries must be objects. Invalid ordinary token settings produce an error when read, even if the active model has a valid override. Only omitted ordinary values use built-in defaults. `enabled` remains global, not model-specific.
466
+
467
+ These resolved values are used for manual compaction, all automatic threshold checks, overflow recovery, and extension-visible `preparation.settings`. Model switches affect subsequent checks and compactions without changing ordinary settings. Compaction already in progress uses the model and settings captured for that operation. Branch summarization settings are unaffected.
468
+
469
+ Overrides work in both global and project settings. The files merge recursively before lookup, so a global model-specific value beats a project-wide fallback; a project must override that model entry to change it. See [Settings](settings.md#per-model-compaction-overrides) for details.
@@ -0,0 +1,45 @@
1
+ # Configuration
2
+
3
+ Apex Code supports user-level and project configuration. User-level configuration lives in the agent directory, which defaults to `~/.apex-code/agent`. Project configuration lives in `.apex-code` under the working directory and loads after [project trust](security.md#understand-project-trust) is granted. The only exception is `sessionDir`, which Apex Code reads before resolving trust so it can locate sessions.
4
+
5
+ In interactive mode, use `/settings` to change common preferences. For other options, ask Apex Code to update the configuration or edit the relevant files directly. Run `/reload` after manually changing settings, keybindings, instructions, or resources.
6
+
7
+ ## Agent directory
8
+
9
+ The agent directory is shown as `<agent-dir>` below. Set its location with the `APEX_CODE_CODING_AGENT_DIR` environment variable or the SDK's [`agentDir`](sdk.md) option.
10
+
11
+ | Path | Responsibility |
12
+ |---|---|
13
+ | `<agent-dir>/settings.json` | User-level [settings](settings.md), including preferences, defaults, resource paths, and Apex Code package declarations. |
14
+ | `<agent-dir>/keybindings.json` | Custom terminal UI and application [keybindings](keybindings.md). |
15
+ | `<agent-dir>/models.json` | [Compatible endpoints, models, and model overrides](models.md#configure-a-compatible-endpoint). |
16
+ | `<agent-dir>/auth.json` | Saved API keys and OAuth credentials. |
17
+ | `<agent-dir>/AGENTS.override.md`, `AGENTS.md`, `AGENTS.MD`, `CLAUDE.md`, or `CLAUDE.MD` | User instructions applied across working directories. |
18
+ | `<agent-dir>/SYSTEM.md` | Replaces Apex Code’s default system prompt. |
19
+ | `<agent-dir>/APPEND_SYSTEM.md` | Adds instructions to Apex Code’s system prompt. |
20
+ | `<agent-dir>/extensions/` | User [extensions](extensions.md). |
21
+ | `<agent-dir>/skills/` | User [skills](skills.md) and supporting files. |
22
+ | `<agent-dir>/prompts/` | User [prompt templates](prompt-templates.md) exposed as slash commands. |
23
+ | `<agent-dir>/themes/` | User [theme](themes.md) files. |
24
+
25
+ ## Project `.apex-code` directory
26
+
27
+ | Path | Responsibility |
28
+ |---|---|
29
+ | `.apex-code/settings.json` | Project-level [settings](settings.md), resource paths, and Apex Code package declarations. |
30
+ | `.apex-code/SYSTEM.md` | Replaces the system prompt for the project. |
31
+ | `.apex-code/APPEND_SYSTEM.md` | Adds project-specific instructions to the system prompt. |
32
+ | `.apex-code/extensions/` | Project extensions. |
33
+ | `.apex-code/skills/` | Project skills and supporting files. |
34
+ | `.apex-code/prompts/` | Project prompt templates exposed as slash commands. |
35
+ | `.apex-code/themes/` | Project theme files. |
36
+
37
+ For `SYSTEM.md` and `APPEND_SYSTEM.md`, the trusted project file takes precedence over the corresponding agent-directory file. Files with the same name are not combined.
38
+
39
+ ## Context files
40
+
41
+ Context files are separate from project `.apex-code` configuration. Apex Code loads them from the agent directory, the working directory, and its parent directories. A context file applies whenever Apex Code runs in its directory or anywhere below it.
42
+
43
+ An `AGENTS.override.md` replaces `AGENTS.md` or `CLAUDE.md` only in the same directory. It does not suppress context files from the agent directory or other directories.
44
+
45
+ Context-file discovery does not require project trust.