apex-code 0.0.1-alpha.1 → 0.0.1-alpha.11

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 (798) hide show
  1. package/CHANGELOG.md +482 -0
  2. package/README.md +75 -680
  3. package/dist/cli/args.d.ts +21 -1
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +119 -15
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/auth-command.d.ts.map +1 -1
  8. package/dist/cli/auth-command.js +3 -3
  9. package/dist/cli/auth-command.js.map +1 -1
  10. package/dist/cli/concurrent-session.d.ts +3 -0
  11. package/dist/cli/concurrent-session.d.ts.map +1 -0
  12. package/dist/cli/concurrent-session.js +13 -0
  13. package/dist/cli/concurrent-session.js.map +1 -0
  14. package/dist/cli/cost-command.d.ts +19 -0
  15. package/dist/cli/cost-command.d.ts.map +1 -0
  16. package/dist/cli/cost-command.js +107 -0
  17. package/dist/cli/cost-command.js.map +1 -0
  18. package/dist/cli/file-processor.d.ts.map +1 -1
  19. package/dist/cli/file-processor.js +2 -1
  20. package/dist/cli/file-processor.js.map +1 -1
  21. package/dist/cli/startup-ui.d.ts +1 -1
  22. package/dist/cli/startup-ui.d.ts.map +1 -1
  23. package/dist/cli/startup-ui.js +1 -2
  24. package/dist/cli/startup-ui.js.map +1 -1
  25. package/dist/cli.d.ts.map +1 -1
  26. package/dist/cli.js +99 -16
  27. package/dist/cli.js.map +1 -1
  28. package/dist/config.d.ts +5 -4
  29. package/dist/config.d.ts.map +1 -1
  30. package/dist/config.js +58 -24
  31. package/dist/config.js.map +1 -1
  32. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  33. package/dist/core/agent-session-runtime.js +2 -0
  34. package/dist/core/agent-session-runtime.js.map +1 -1
  35. package/dist/core/agent-session-services.d.ts +28 -0
  36. package/dist/core/agent-session-services.d.ts.map +1 -1
  37. package/dist/core/agent-session-services.js +140 -4
  38. package/dist/core/agent-session-services.js.map +1 -1
  39. package/dist/core/agent-session.d.ts +147 -9
  40. package/dist/core/agent-session.d.ts.map +1 -1
  41. package/dist/core/agent-session.js +440 -123
  42. package/dist/core/agent-session.js.map +1 -1
  43. package/dist/core/auth-storage.d.ts +4 -1
  44. package/dist/core/auth-storage.d.ts.map +1 -1
  45. package/dist/core/auth-storage.js +17 -14
  46. package/dist/core/auth-storage.js.map +1 -1
  47. package/dist/core/bash-executor.d.ts.map +1 -1
  48. package/dist/core/bash-executor.js +18 -10
  49. package/dist/core/bash-executor.js.map +1 -1
  50. package/dist/core/checkpoints/git-checkpoints.d.ts +33 -0
  51. package/dist/core/checkpoints/git-checkpoints.d.ts.map +1 -0
  52. package/dist/core/checkpoints/git-checkpoints.js +230 -0
  53. package/dist/core/checkpoints/git-checkpoints.js.map +1 -0
  54. package/dist/core/checkpoints/session-checkpoints.d.ts +23 -0
  55. package/dist/core/checkpoints/session-checkpoints.d.ts.map +1 -0
  56. package/dist/core/checkpoints/session-checkpoints.js +29 -0
  57. package/dist/core/checkpoints/session-checkpoints.js.map +1 -0
  58. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  59. package/dist/core/compaction/branch-summarization.js +3 -0
  60. package/dist/core/compaction/branch-summarization.js.map +1 -1
  61. package/dist/core/compaction/compaction.d.ts +4 -3
  62. package/dist/core/compaction/compaction.d.ts.map +1 -1
  63. package/dist/core/compaction/compaction.js +41 -32
  64. package/dist/core/compaction/compaction.js.map +1 -1
  65. package/dist/core/context/deferred-schemas.d.ts +92 -0
  66. package/dist/core/context/deferred-schemas.d.ts.map +1 -0
  67. package/dist/core/context/deferred-schemas.js +74 -0
  68. package/dist/core/context/deferred-schemas.js.map +1 -0
  69. package/dist/core/context/eviction.d.ts +47 -0
  70. package/dist/core/context/eviction.d.ts.map +1 -0
  71. package/dist/core/context/eviction.js +83 -0
  72. package/dist/core/context/eviction.js.map +1 -0
  73. package/dist/core/context/pipeline.d.ts +90 -0
  74. package/dist/core/context/pipeline.d.ts.map +1 -0
  75. package/dist/core/context/pipeline.js +109 -0
  76. package/dist/core/context/pipeline.js.map +1 -0
  77. package/dist/core/credential-failover.d.ts +30 -0
  78. package/dist/core/credential-failover.d.ts.map +1 -0
  79. package/dist/core/credential-failover.js +46 -0
  80. package/dist/core/credential-failover.js.map +1 -0
  81. package/dist/core/credential-pool.d.ts +60 -0
  82. package/dist/core/credential-pool.d.ts.map +1 -0
  83. package/dist/core/credential-pool.js +84 -0
  84. package/dist/core/credential-pool.js.map +1 -0
  85. package/dist/core/defaults.d.ts +1 -0
  86. package/dist/core/defaults.d.ts.map +1 -1
  87. package/dist/core/defaults.js +9 -0
  88. package/dist/core/defaults.js.map +1 -1
  89. package/dist/core/delegation/agents.d.ts +15 -0
  90. package/dist/core/delegation/agents.d.ts.map +1 -0
  91. package/dist/core/delegation/agents.js +55 -0
  92. package/dist/core/delegation/agents.js.map +1 -0
  93. package/dist/core/delegation/ceiling.d.ts +29 -0
  94. package/dist/core/delegation/ceiling.d.ts.map +1 -0
  95. package/dist/core/delegation/ceiling.js +34 -0
  96. package/dist/core/delegation/ceiling.js.map +1 -0
  97. package/dist/core/delegation/runtime.d.ts +94 -0
  98. package/dist/core/delegation/runtime.d.ts.map +1 -0
  99. package/dist/core/delegation/runtime.js +117 -0
  100. package/dist/core/delegation/runtime.js.map +1 -0
  101. package/dist/core/durable-state/daemon.d.ts +37 -0
  102. package/dist/core/durable-state/daemon.d.ts.map +1 -0
  103. package/dist/core/durable-state/daemon.js +62 -0
  104. package/dist/core/durable-state/daemon.js.map +1 -0
  105. package/dist/core/durable-state/provenance.d.ts +7 -0
  106. package/dist/core/durable-state/provenance.d.ts.map +1 -0
  107. package/dist/core/durable-state/provenance.js +24 -0
  108. package/dist/core/durable-state/provenance.js.map +1 -0
  109. package/dist/core/durable-state/sqlite.d.ts +84 -0
  110. package/dist/core/durable-state/sqlite.d.ts.map +1 -0
  111. package/dist/core/durable-state/sqlite.js +355 -0
  112. package/dist/core/durable-state/sqlite.js.map +1 -0
  113. package/dist/core/environment.d.ts +12 -0
  114. package/dist/core/environment.d.ts.map +1 -0
  115. package/dist/core/environment.js +69 -0
  116. package/dist/core/environment.js.map +1 -0
  117. package/dist/core/evidence-policy.d.ts +17 -0
  118. package/dist/core/evidence-policy.d.ts.map +1 -0
  119. package/dist/core/evidence-policy.js +25 -0
  120. package/dist/core/evidence-policy.js.map +1 -0
  121. package/dist/core/evidence.d.ts +16 -0
  122. package/dist/core/evidence.d.ts.map +1 -0
  123. package/dist/core/evidence.js +51 -0
  124. package/dist/core/evidence.js.map +1 -0
  125. package/dist/core/exec.d.ts.map +1 -1
  126. package/dist/core/exec.js +5 -2
  127. package/dist/core/exec.js.map +1 -1
  128. package/dist/core/experimental.d.ts +4 -0
  129. package/dist/core/experimental.d.ts.map +1 -1
  130. package/dist/core/experimental.js +6 -1
  131. package/dist/core/experimental.js.map +1 -1
  132. package/dist/core/extensions/index.d.ts +2 -2
  133. package/dist/core/extensions/index.d.ts.map +1 -1
  134. package/dist/core/extensions/index.js +1 -1
  135. package/dist/core/extensions/index.js.map +1 -1
  136. package/dist/core/extensions/loader.d.ts.map +1 -1
  137. package/dist/core/extensions/loader.js +122 -49
  138. package/dist/core/extensions/loader.js.map +1 -1
  139. package/dist/core/extensions/types.d.ts +44 -9
  140. package/dist/core/extensions/types.d.ts.map +1 -1
  141. package/dist/core/extensions/types.js +3 -0
  142. package/dist/core/extensions/types.js.map +1 -1
  143. package/dist/core/footer-data-provider.d.ts +1 -1
  144. package/dist/core/footer-data-provider.d.ts.map +1 -1
  145. package/dist/core/footer-data-provider.js +1 -1
  146. package/dist/core/footer-data-provider.js.map +1 -1
  147. package/dist/core/http-dispatcher.d.ts +1 -2
  148. package/dist/core/http-dispatcher.d.ts.map +1 -1
  149. package/dist/core/http-dispatcher.js +2 -17
  150. package/dist/core/http-dispatcher.js.map +1 -1
  151. package/dist/core/http-idle-timeout.d.ts +12 -0
  152. package/dist/core/http-idle-timeout.d.ts.map +1 -0
  153. package/dist/core/http-idle-timeout.js +27 -0
  154. package/dist/core/http-idle-timeout.js.map +1 -0
  155. package/dist/core/index.d.ts +1 -0
  156. package/dist/core/index.d.ts.map +1 -1
  157. package/dist/core/index.js +1 -0
  158. package/dist/core/index.js.map +1 -1
  159. package/dist/core/keybindings.d.ts +38 -13
  160. package/dist/core/keybindings.d.ts.map +1 -1
  161. package/dist/core/keybindings.js +26 -5
  162. package/dist/core/keybindings.js.map +1 -1
  163. package/dist/core/lsp/client.d.ts +78 -0
  164. package/dist/core/lsp/client.d.ts.map +1 -0
  165. package/dist/core/lsp/client.js +494 -0
  166. package/dist/core/lsp/client.js.map +1 -0
  167. package/dist/core/lsp/diagnostics.d.ts +47 -0
  168. package/dist/core/lsp/diagnostics.d.ts.map +1 -0
  169. package/dist/core/lsp/diagnostics.js +224 -0
  170. package/dist/core/lsp/diagnostics.js.map +1 -0
  171. package/dist/core/lsp/pool.d.ts +48 -0
  172. package/dist/core/lsp/pool.d.ts.map +1 -0
  173. package/dist/core/lsp/pool.js +150 -0
  174. package/dist/core/lsp/pool.js.map +1 -0
  175. package/dist/core/lsp/registry.d.ts +49 -0
  176. package/dist/core/lsp/registry.d.ts.map +1 -0
  177. package/dist/core/lsp/registry.js +215 -0
  178. package/dist/core/lsp/registry.js.map +1 -0
  179. package/dist/core/lsp/status.d.ts +23 -0
  180. package/dist/core/lsp/status.d.ts.map +1 -0
  181. package/dist/core/lsp/status.js +35 -0
  182. package/dist/core/lsp/status.js.map +1 -0
  183. package/dist/core/lsp/sync.d.ts +13 -0
  184. package/dist/core/lsp/sync.d.ts.map +1 -0
  185. package/dist/core/lsp/sync.js +71 -0
  186. package/dist/core/lsp/sync.js.map +1 -0
  187. package/dist/core/mcp/config.d.ts +16 -0
  188. package/dist/core/mcp/config.d.ts.map +1 -0
  189. package/dist/core/mcp/config.js +152 -0
  190. package/dist/core/mcp/config.js.map +1 -0
  191. package/dist/core/mcp/connector.d.ts +10 -0
  192. package/dist/core/mcp/connector.d.ts.map +1 -0
  193. package/dist/core/mcp/connector.js +70 -0
  194. package/dist/core/mcp/connector.js.map +1 -0
  195. package/dist/core/mcp/contract.d.ts +19 -0
  196. package/dist/core/mcp/contract.d.ts.map +1 -0
  197. package/dist/core/mcp/contract.js +89 -0
  198. package/dist/core/mcp/contract.js.map +1 -0
  199. package/dist/core/mcp/mcp-tool.d.ts +32 -0
  200. package/dist/core/mcp/mcp-tool.d.ts.map +1 -0
  201. package/dist/core/mcp/mcp-tool.js +165 -0
  202. package/dist/core/mcp/mcp-tool.js.map +1 -0
  203. package/dist/core/mcp/metadata-cache.d.ts +29 -0
  204. package/dist/core/mcp/metadata-cache.d.ts.map +1 -0
  205. package/dist/core/mcp/metadata-cache.js +99 -0
  206. package/dist/core/mcp/metadata-cache.js.map +1 -0
  207. package/dist/core/mcp/runtime.d.ts +18 -0
  208. package/dist/core/mcp/runtime.d.ts.map +1 -0
  209. package/dist/core/mcp/runtime.js +35 -0
  210. package/dist/core/mcp/runtime.js.map +1 -0
  211. package/dist/core/mcp/schema.d.ts +22 -0
  212. package/dist/core/mcp/schema.d.ts.map +1 -0
  213. package/dist/core/mcp/schema.js +20 -0
  214. package/dist/core/mcp/schema.js.map +1 -0
  215. package/dist/core/mcp/server-manager.d.ts +43 -0
  216. package/dist/core/mcp/server-manager.d.ts.map +1 -0
  217. package/dist/core/mcp/server-manager.js +142 -0
  218. package/dist/core/mcp/server-manager.js.map +1 -0
  219. package/dist/core/mcp/types.d.ts +98 -0
  220. package/dist/core/mcp/types.d.ts.map +1 -0
  221. package/dist/core/mcp/types.js +8 -0
  222. package/dist/core/mcp/types.js.map +1 -0
  223. package/dist/core/model-config.d.ts +18 -0
  224. package/dist/core/model-config.d.ts.map +1 -1
  225. package/dist/core/model-config.js +25 -6
  226. package/dist/core/model-config.js.map +1 -1
  227. package/dist/core/model-resolver.d.ts +21 -0
  228. package/dist/core/model-resolver.d.ts.map +1 -1
  229. package/dist/core/model-resolver.js +73 -8
  230. package/dist/core/model-resolver.js.map +1 -1
  231. package/dist/core/model-runtime.d.ts +73 -0
  232. package/dist/core/model-runtime.d.ts.map +1 -1
  233. package/dist/core/model-runtime.js +225 -8
  234. package/dist/core/model-runtime.js.map +1 -1
  235. package/dist/core/models-store.d.ts.map +1 -1
  236. package/dist/core/models-store.js +2 -1
  237. package/dist/core/models-store.js.map +1 -1
  238. package/dist/core/observability/aggregate.d.ts +21 -0
  239. package/dist/core/observability/aggregate.d.ts.map +1 -0
  240. package/dist/core/observability/aggregate.js +36 -0
  241. package/dist/core/observability/aggregate.js.map +1 -0
  242. package/dist/core/observability/otlp.d.ts +66 -0
  243. package/dist/core/observability/otlp.d.ts.map +1 -0
  244. package/dist/core/observability/otlp.js +95 -0
  245. package/dist/core/observability/otlp.js.map +1 -0
  246. package/dist/core/package-manager.d.ts.map +1 -1
  247. package/dist/core/package-manager.js +40 -16
  248. package/dist/core/package-manager.js.map +1 -1
  249. package/dist/core/permissions/gate.d.ts +42 -0
  250. package/dist/core/permissions/gate.d.ts.map +1 -0
  251. package/dist/core/permissions/gate.js +72 -0
  252. package/dist/core/permissions/gate.js.map +1 -0
  253. package/dist/core/permissions/modes.d.ts +18 -0
  254. package/dist/core/permissions/modes.d.ts.map +1 -0
  255. package/dist/core/permissions/modes.js +57 -0
  256. package/dist/core/permissions/modes.js.map +1 -0
  257. package/dist/core/permissions/responder.d.ts +30 -0
  258. package/dist/core/permissions/responder.d.ts.map +1 -0
  259. package/dist/core/permissions/responder.js +32 -0
  260. package/dist/core/permissions/responder.js.map +1 -0
  261. package/dist/core/permissions/rules.d.ts +34 -0
  262. package/dist/core/permissions/rules.d.ts.map +1 -0
  263. package/dist/core/permissions/rules.js +74 -0
  264. package/dist/core/permissions/rules.js.map +1 -0
  265. package/dist/core/permissions/startup.d.ts +45 -0
  266. package/dist/core/permissions/startup.d.ts.map +1 -0
  267. package/dist/core/permissions/startup.js +63 -0
  268. package/dist/core/permissions/startup.js.map +1 -0
  269. package/dist/core/permissions/store.d.ts +114 -0
  270. package/dist/core/permissions/store.d.ts.map +1 -0
  271. package/dist/core/permissions/store.js +229 -0
  272. package/dist/core/permissions/store.js.map +1 -0
  273. package/dist/core/pi-manifest.d.ts.map +1 -1
  274. package/dist/core/pi-manifest.js +2 -1
  275. package/dist/core/pi-manifest.js.map +1 -1
  276. package/dist/core/project-trust.d.ts.map +1 -1
  277. package/dist/core/project-trust.js +1 -1
  278. package/dist/core/project-trust.js.map +1 -1
  279. package/dist/core/provider-attribution.d.ts.map +1 -1
  280. package/dist/core/provider-attribution.js +6 -7
  281. package/dist/core/provider-attribution.js.map +1 -1
  282. package/dist/core/remote-catalog-provider.d.ts +2 -2
  283. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  284. package/dist/core/remote-catalog-provider.js +22 -17
  285. package/dist/core/remote-catalog-provider.js.map +1 -1
  286. package/dist/core/resource-loader.d.ts.map +1 -1
  287. package/dist/core/resource-loader.js +3 -2
  288. package/dist/core/resource-loader.js.map +1 -1
  289. package/dist/core/sandbox/bwrap-arguments.d.ts +52 -0
  290. package/dist/core/sandbox/bwrap-arguments.d.ts.map +1 -0
  291. package/dist/core/sandbox/bwrap-arguments.js +86 -0
  292. package/dist/core/sandbox/bwrap-arguments.js.map +1 -0
  293. package/dist/core/sandbox/child-entry.d.ts +2 -0
  294. package/dist/core/sandbox/child-entry.d.ts.map +1 -0
  295. package/dist/core/sandbox/child-entry.js +22 -0
  296. package/dist/core/sandbox/child-entry.js.map +1 -0
  297. package/dist/core/sandbox/cli-launch.d.ts +88 -0
  298. package/dist/core/sandbox/cli-launch.d.ts.map +1 -0
  299. package/dist/core/sandbox/cli-launch.js +272 -0
  300. package/dist/core/sandbox/cli-launch.js.map +1 -0
  301. package/dist/core/sandbox/cli-supervisor.d.ts +30 -0
  302. package/dist/core/sandbox/cli-supervisor.d.ts.map +1 -0
  303. package/dist/core/sandbox/cli-supervisor.js +123 -0
  304. package/dist/core/sandbox/cli-supervisor.js.map +1 -0
  305. package/dist/core/sandbox/default-hosts.d.ts +28 -0
  306. package/dist/core/sandbox/default-hosts.d.ts.map +1 -0
  307. package/dist/core/sandbox/default-hosts.js +69 -0
  308. package/dist/core/sandbox/default-hosts.js.map +1 -0
  309. package/dist/core/sandbox/full-access.d.ts +28 -0
  310. package/dist/core/sandbox/full-access.d.ts.map +1 -0
  311. package/dist/core/sandbox/full-access.js +63 -0
  312. package/dist/core/sandbox/full-access.js.map +1 -0
  313. package/dist/core/sandbox/git-identity.d.ts +57 -0
  314. package/dist/core/sandbox/git-identity.d.ts.map +1 -0
  315. package/dist/core/sandbox/git-identity.js +78 -0
  316. package/dist/core/sandbox/git-identity.js.map +1 -0
  317. package/dist/core/sandbox/host-approval.d.ts +42 -0
  318. package/dist/core/sandbox/host-approval.d.ts.map +1 -0
  319. package/dist/core/sandbox/host-approval.js +99 -0
  320. package/dist/core/sandbox/host-approval.js.map +1 -0
  321. package/dist/core/sandbox/linux-backend.d.ts +46 -0
  322. package/dist/core/sandbox/linux-backend.d.ts.map +1 -0
  323. package/dist/core/sandbox/linux-backend.js +304 -0
  324. package/dist/core/sandbox/linux-backend.js.map +1 -0
  325. package/dist/core/sandbox/macos-backend.d.ts +28 -0
  326. package/dist/core/sandbox/macos-backend.d.ts.map +1 -0
  327. package/dist/core/sandbox/macos-backend.js +313 -0
  328. package/dist/core/sandbox/macos-backend.js.map +1 -0
  329. package/dist/core/sandbox/network-proxy.d.ts +38 -0
  330. package/dist/core/sandbox/network-proxy.d.ts.map +1 -0
  331. package/dist/core/sandbox/network-proxy.js +153 -0
  332. package/dist/core/sandbox/network-proxy.js.map +1 -0
  333. package/dist/core/sandbox/network-refusal.d.ts +24 -0
  334. package/dist/core/sandbox/network-refusal.d.ts.map +1 -0
  335. package/dist/core/sandbox/network-refusal.js +72 -0
  336. package/dist/core/sandbox/network-refusal.js.map +1 -0
  337. package/dist/core/sandbox/policy.d.ts +40 -0
  338. package/dist/core/sandbox/policy.d.ts.map +1 -0
  339. package/dist/core/sandbox/policy.js +55 -0
  340. package/dist/core/sandbox/policy.js.map +1 -0
  341. package/dist/core/sandbox/profiles.d.ts +25 -0
  342. package/dist/core/sandbox/profiles.d.ts.map +1 -0
  343. package/dist/core/sandbox/profiles.js +23 -0
  344. package/dist/core/sandbox/profiles.js.map +1 -0
  345. package/dist/core/sandbox/rpc/command-client.d.ts +28 -0
  346. package/dist/core/sandbox/rpc/command-client.d.ts.map +1 -0
  347. package/dist/core/sandbox/rpc/command-client.js +86 -0
  348. package/dist/core/sandbox/rpc/command-client.js.map +1 -0
  349. package/dist/core/sandbox/rpc/command-proxy.d.ts +48 -0
  350. package/dist/core/sandbox/rpc/command-proxy.d.ts.map +1 -0
  351. package/dist/core/sandbox/rpc/command-proxy.js +120 -0
  352. package/dist/core/sandbox/rpc/command-proxy.js.map +1 -0
  353. package/dist/core/sandbox/rpc/credential-client.d.ts +20 -0
  354. package/dist/core/sandbox/rpc/credential-client.d.ts.map +1 -0
  355. package/dist/core/sandbox/rpc/credential-client.js +170 -0
  356. package/dist/core/sandbox/rpc/credential-client.js.map +1 -0
  357. package/dist/core/sandbox/rpc/credential-proxy.d.ts +44 -0
  358. package/dist/core/sandbox/rpc/credential-proxy.d.ts.map +1 -0
  359. package/dist/core/sandbox/rpc/credential-proxy.js +287 -0
  360. package/dist/core/sandbox/rpc/credential-proxy.js.map +1 -0
  361. package/dist/core/sandbox/rpc/framing.d.ts +35 -0
  362. package/dist/core/sandbox/rpc/framing.d.ts.map +1 -0
  363. package/dist/core/sandbox/rpc/framing.js +114 -0
  364. package/dist/core/sandbox/rpc/framing.js.map +1 -0
  365. package/dist/core/sandbox/rpc/git-credential-helper.d.ts +40 -0
  366. package/dist/core/sandbox/rpc/git-credential-helper.d.ts.map +1 -0
  367. package/dist/core/sandbox/rpc/git-credential-helper.js +152 -0
  368. package/dist/core/sandbox/rpc/git-credential-helper.js.map +1 -0
  369. package/dist/core/sandbox/rpc/git-credential-proxy.d.ts +48 -0
  370. package/dist/core/sandbox/rpc/git-credential-proxy.d.ts.map +1 -0
  371. package/dist/core/sandbox/rpc/git-credential-proxy.js +142 -0
  372. package/dist/core/sandbox/rpc/git-credential-proxy.js.map +1 -0
  373. package/dist/core/sandbox/supervisor-temp.d.ts +18 -0
  374. package/dist/core/sandbox/supervisor-temp.d.ts.map +1 -0
  375. package/dist/core/sandbox/supervisor-temp.js +21 -0
  376. package/dist/core/sandbox/supervisor-temp.js.map +1 -0
  377. package/dist/core/sandbox/supervisor.d.ts +51 -0
  378. package/dist/core/sandbox/supervisor.d.ts.map +1 -0
  379. package/dist/core/sandbox/supervisor.js +18 -0
  380. package/dist/core/sandbox/supervisor.js.map +1 -0
  381. package/dist/core/sandbox/terminal-handoff.d.ts +45 -0
  382. package/dist/core/sandbox/terminal-handoff.d.ts.map +1 -0
  383. package/dist/core/sandbox/terminal-handoff.js +176 -0
  384. package/dist/core/sandbox/terminal-handoff.js.map +1 -0
  385. package/dist/core/sandbox/terminal-size.d.ts +40 -0
  386. package/dist/core/sandbox/terminal-size.d.ts.map +1 -0
  387. package/dist/core/sandbox/terminal-size.js +105 -0
  388. package/dist/core/sandbox/terminal-size.js.map +1 -0
  389. package/dist/core/sandbox/violations.d.ts +23 -0
  390. package/dist/core/sandbox/violations.d.ts.map +1 -0
  391. package/dist/core/sandbox/violations.js +30 -0
  392. package/dist/core/sandbox/violations.js.map +1 -0
  393. package/dist/core/sdk.d.ts +32 -41
  394. package/dist/core/sdk.d.ts.map +1 -1
  395. package/dist/core/sdk.js +174 -6
  396. package/dist/core/sdk.js.map +1 -1
  397. package/dist/core/session-export.d.ts +4 -0
  398. package/dist/core/session-export.d.ts.map +1 -0
  399. package/dist/core/session-export.js +32 -0
  400. package/dist/core/session-export.js.map +1 -0
  401. package/dist/core/session-lease.d.ts +31 -0
  402. package/dist/core/session-lease.d.ts.map +1 -0
  403. package/dist/core/session-lease.js +138 -0
  404. package/dist/core/session-lease.js.map +1 -0
  405. package/dist/core/session-manager.d.ts +58 -2
  406. package/dist/core/session-manager.d.ts.map +1 -1
  407. package/dist/core/session-manager.js +92 -7
  408. package/dist/core/session-manager.js.map +1 -1
  409. package/dist/core/session-share.d.ts +31 -0
  410. package/dist/core/session-share.d.ts.map +1 -0
  411. package/dist/core/session-share.js +45 -0
  412. package/dist/core/session-share.js.map +1 -0
  413. package/dist/core/settings-diagnostics.d.ts +9 -0
  414. package/dist/core/settings-diagnostics.d.ts.map +1 -0
  415. package/dist/core/settings-diagnostics.js +21 -0
  416. package/dist/core/settings-diagnostics.js.map +1 -0
  417. package/dist/core/settings-manager.d.ts +99 -9
  418. package/dist/core/settings-manager.d.ts.map +1 -1
  419. package/dist/core/settings-manager.js +141 -36
  420. package/dist/core/settings-manager.js.map +1 -1
  421. package/dist/core/skills.d.ts +19 -7
  422. package/dist/core/skills.d.ts.map +1 -1
  423. package/dist/core/skills.js +128 -52
  424. package/dist/core/skills.js.map +1 -1
  425. package/dist/core/slash-commands.d.ts.map +1 -1
  426. package/dist/core/slash-commands.js +6 -2
  427. package/dist/core/slash-commands.js.map +1 -1
  428. package/dist/core/system-prompt.d.ts +2 -2
  429. package/dist/core/system-prompt.d.ts.map +1 -1
  430. package/dist/core/system-prompt.js +59 -68
  431. package/dist/core/system-prompt.js.map +1 -1
  432. package/dist/core/timings.d.ts +1 -1
  433. package/dist/core/timings.d.ts.map +1 -1
  434. package/dist/core/timings.js +3 -2
  435. package/dist/core/timings.js.map +1 -1
  436. package/dist/core/tools/ask-user.d.ts +25 -0
  437. package/dist/core/tools/ask-user.d.ts.map +1 -0
  438. package/dist/core/tools/ask-user.js +49 -0
  439. package/dist/core/tools/ask-user.js.map +1 -0
  440. package/dist/core/tools/bash-command-segments.d.ts +22 -0
  441. package/dist/core/tools/bash-command-segments.d.ts.map +1 -0
  442. package/dist/core/tools/bash-command-segments.js +128 -0
  443. package/dist/core/tools/bash-command-segments.js.map +1 -0
  444. package/dist/core/tools/bash.d.ts +40 -4
  445. package/dist/core/tools/bash.d.ts.map +1 -1
  446. package/dist/core/tools/bash.js +183 -32
  447. package/dist/core/tools/bash.js.map +1 -1
  448. package/dist/core/tools/contract-snapshot.d.ts +58 -0
  449. package/dist/core/tools/contract-snapshot.d.ts.map +1 -0
  450. package/dist/core/tools/contract-snapshot.js +51 -0
  451. package/dist/core/tools/contract-snapshot.js.map +1 -0
  452. package/dist/core/tools/contract.d.ts +185 -0
  453. package/dist/core/tools/contract.d.ts.map +1 -0
  454. package/dist/core/tools/contract.js +50 -0
  455. package/dist/core/tools/contract.js.map +1 -0
  456. package/dist/core/tools/delegate.d.ts +38 -0
  457. package/dist/core/tools/delegate.d.ts.map +1 -0
  458. package/dist/core/tools/delegate.js +90 -0
  459. package/dist/core/tools/delegate.js.map +1 -0
  460. package/dist/core/tools/diagnostics.d.ts +39 -0
  461. package/dist/core/tools/diagnostics.d.ts.map +1 -0
  462. package/dist/core/tools/diagnostics.js +62 -0
  463. package/dist/core/tools/diagnostics.js.map +1 -0
  464. package/dist/core/tools/edit-diff.d.ts +0 -5
  465. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  466. package/dist/core/tools/edit-diff.js +2 -5
  467. package/dist/core/tools/edit-diff.js.map +1 -1
  468. package/dist/core/tools/edit.d.ts +12 -2
  469. package/dist/core/tools/edit.d.ts.map +1 -1
  470. package/dist/core/tools/edit.js +61 -10
  471. package/dist/core/tools/edit.js.map +1 -1
  472. package/dist/core/tools/find.d.ts +2 -2
  473. package/dist/core/tools/find.d.ts.map +1 -1
  474. package/dist/core/tools/find.js +13 -1
  475. package/dist/core/tools/find.js.map +1 -1
  476. package/dist/core/tools/grep.d.ts +4 -2
  477. package/dist/core/tools/grep.d.ts.map +1 -1
  478. package/dist/core/tools/grep.js +47 -10
  479. package/dist/core/tools/grep.js.map +1 -1
  480. package/dist/core/tools/index.d.ts +60 -6
  481. package/dist/core/tools/index.d.ts.map +1 -1
  482. package/dist/core/tools/index.js +148 -2
  483. package/dist/core/tools/index.js.map +1 -1
  484. package/dist/core/tools/ls.d.ts +4 -2
  485. package/dist/core/tools/ls.d.ts.map +1 -1
  486. package/dist/core/tools/ls.js +17 -1
  487. package/dist/core/tools/ls.js.map +1 -1
  488. package/dist/core/tools/lsp.d.ts +62 -0
  489. package/dist/core/tools/lsp.d.ts.map +1 -0
  490. package/dist/core/tools/lsp.js +216 -0
  491. package/dist/core/tools/lsp.js.map +1 -0
  492. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  493. package/dist/core/tools/output-accumulator.js +1 -1
  494. package/dist/core/tools/output-accumulator.js.map +1 -1
  495. package/dist/core/tools/path-permission.d.ts +18 -0
  496. package/dist/core/tools/path-permission.d.ts.map +1 -0
  497. package/dist/core/tools/path-permission.js +28 -0
  498. package/dist/core/tools/path-permission.js.map +1 -0
  499. package/dist/core/tools/plan-present.d.ts +27 -0
  500. package/dist/core/tools/plan-present.d.ts.map +1 -0
  501. package/dist/core/tools/plan-present.js +55 -0
  502. package/dist/core/tools/plan-present.js.map +1 -0
  503. package/dist/core/tools/powershell.d.ts +16 -0
  504. package/dist/core/tools/powershell.d.ts.map +1 -0
  505. package/dist/core/tools/powershell.js +39 -0
  506. package/dist/core/tools/powershell.js.map +1 -0
  507. package/dist/core/tools/read.d.ts +2 -2
  508. package/dist/core/tools/read.d.ts.map +1 -1
  509. package/dist/core/tools/read.js +14 -0
  510. package/dist/core/tools/read.js.map +1 -1
  511. package/dist/core/tools/skill-search.d.ts +32 -0
  512. package/dist/core/tools/skill-search.d.ts.map +1 -0
  513. package/dist/core/tools/skill-search.js +56 -0
  514. package/dist/core/tools/skill-search.js.map +1 -0
  515. package/dist/core/tools/test.d.ts +34 -0
  516. package/dist/core/tools/test.d.ts.map +1 -0
  517. package/dist/core/tools/test.js +75 -0
  518. package/dist/core/tools/test.js.map +1 -0
  519. package/dist/core/tools/todo-write.d.ts +31 -0
  520. package/dist/core/tools/todo-write.d.ts.map +1 -0
  521. package/dist/core/tools/todo-write.js +51 -0
  522. package/dist/core/tools/todo-write.js.map +1 -0
  523. package/dist/core/tools/tool-definition-wrapper.d.ts +13 -2
  524. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  525. package/dist/core/tools/tool-definition-wrapper.js +11 -1
  526. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  527. package/dist/core/tools/tool-schema.d.ts +22 -0
  528. package/dist/core/tools/tool-schema.d.ts.map +1 -0
  529. package/dist/core/tools/tool-schema.js +45 -0
  530. package/dist/core/tools/tool-schema.js.map +1 -0
  531. package/dist/core/tools/web-fetch.d.ts +26 -0
  532. package/dist/core/tools/web-fetch.d.ts.map +1 -0
  533. package/dist/core/tools/web-fetch.js +62 -0
  534. package/dist/core/tools/web-fetch.js.map +1 -0
  535. package/dist/core/tools/web-search-exa.d.ts +33 -0
  536. package/dist/core/tools/web-search-exa.d.ts.map +1 -0
  537. package/dist/core/tools/web-search-exa.js +128 -0
  538. package/dist/core/tools/web-search-exa.js.map +1 -0
  539. package/dist/core/tools/web-search.d.ts +26 -0
  540. package/dist/core/tools/web-search.d.ts.map +1 -0
  541. package/dist/core/tools/web-search.js +53 -0
  542. package/dist/core/tools/web-search.js.map +1 -0
  543. package/dist/core/tools/write.d.ts +16 -2
  544. package/dist/core/tools/write.d.ts.map +1 -1
  545. package/dist/core/tools/write.js +48 -2
  546. package/dist/core/tools/write.js.map +1 -1
  547. package/dist/core/trust-manager.d.ts.map +1 -1
  548. package/dist/core/trust-manager.js +2 -1
  549. package/dist/core/trust-manager.js.map +1 -1
  550. package/dist/core/usage-performance-store.d.ts +56 -0
  551. package/dist/core/usage-performance-store.d.ts.map +1 -0
  552. package/dist/core/usage-performance-store.js +85 -0
  553. package/dist/core/usage-performance-store.js.map +1 -0
  554. package/dist/core/web-search-provider.d.ts +64 -0
  555. package/dist/core/web-search-provider.d.ts.map +1 -0
  556. package/dist/core/web-search-provider.js +149 -0
  557. package/dist/core/web-search-provider.js.map +1 -0
  558. package/dist/extensions/llama/index.d.ts.map +1 -1
  559. package/dist/extensions/llama/index.js +2 -0
  560. package/dist/extensions/llama/index.js.map +1 -1
  561. package/dist/extensions/llama/provider.d.ts.map +1 -1
  562. package/dist/extensions/llama/provider.js +6 -2
  563. package/dist/extensions/llama/provider.js.map +1 -1
  564. package/dist/index.d.ts +9 -6
  565. package/dist/index.d.ts.map +1 -1
  566. package/dist/index.js +7 -4
  567. package/dist/index.js.map +1 -1
  568. package/dist/main.d.ts +5 -0
  569. package/dist/main.d.ts.map +1 -1
  570. package/dist/main.js +87 -22
  571. package/dist/main.js.map +1 -1
  572. package/dist/migrations.d.ts.map +1 -1
  573. package/dist/migrations.js +6 -5
  574. package/dist/migrations.js.map +1 -1
  575. package/dist/modes/interactive/components/assistant-message.d.ts +29 -0
  576. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  577. package/dist/modes/interactive/components/assistant-message.js +182 -23
  578. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  579. package/dist/modes/interactive/components/bash-execution.d.ts +7 -0
  580. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  581. package/dist/modes/interactive/components/bash-execution.js +20 -0
  582. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  583. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  584. package/dist/modes/interactive/components/config-selector.js +9 -6
  585. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  586. package/dist/modes/interactive/components/custom-editor.d.ts +72 -1
  587. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  588. package/dist/modes/interactive/components/custom-editor.js +338 -1
  589. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  590. package/dist/modes/interactive/components/dynamic-border.d.ts +7 -1
  591. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  592. package/dist/modes/interactive/components/dynamic-border.js +11 -2
  593. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  594. package/dist/modes/interactive/components/extension-selector.d.ts +4 -0
  595. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  596. package/dist/modes/interactive/components/extension-selector.js +24 -6
  597. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  598. package/dist/modes/interactive/components/first-time-setup.d.ts +1 -4
  599. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  600. package/dist/modes/interactive/components/first-time-setup.js +17 -41
  601. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  602. package/dist/modes/interactive/components/first-use-hints.d.ts +8 -0
  603. package/dist/modes/interactive/components/first-use-hints.d.ts.map +1 -0
  604. package/dist/modes/interactive/components/first-use-hints.js +22 -0
  605. package/dist/modes/interactive/components/first-use-hints.js.map +1 -0
  606. package/dist/modes/interactive/components/footer.d.ts +31 -1
  607. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  608. package/dist/modes/interactive/components/footer.js +205 -24
  609. package/dist/modes/interactive/components/footer.js.map +1 -1
  610. package/dist/modes/interactive/components/index.d.ts +2 -0
  611. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  612. package/dist/modes/interactive/components/index.js +2 -0
  613. package/dist/modes/interactive/components/index.js.map +1 -1
  614. package/dist/modes/interactive/components/model-selector.d.ts +31 -9
  615. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  616. package/dist/modes/interactive/components/model-selector.js +236 -96
  617. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  618. package/dist/modes/interactive/components/settings-selector.d.ts +25 -5
  619. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  620. package/dist/modes/interactive/components/settings-selector.js +226 -58
  621. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  622. package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
  623. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
  624. package/dist/modes/interactive/components/settings-submenu.js +165 -0
  625. package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
  626. package/dist/modes/interactive/components/splash-header.d.ts +66 -0
  627. package/dist/modes/interactive/components/splash-header.d.ts.map +1 -0
  628. package/dist/modes/interactive/components/splash-header.js +180 -0
  629. package/dist/modes/interactive/components/splash-header.js.map +1 -0
  630. package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
  631. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  632. package/dist/modes/interactive/components/thinking-selector.js +74 -17
  633. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  634. package/dist/modes/interactive/components/tool-execution.d.ts +28 -1
  635. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  636. package/dist/modes/interactive/components/tool-execution.js +144 -35
  637. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  638. package/dist/modes/interactive/components/tool-panel.d.ts +30 -0
  639. package/dist/modes/interactive/components/tool-panel.d.ts.map +1 -0
  640. package/dist/modes/interactive/components/tool-panel.js +130 -0
  641. package/dist/modes/interactive/components/tool-panel.js.map +1 -0
  642. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  643. package/dist/modes/interactive/external-editor.js +60 -10
  644. package/dist/modes/interactive/external-editor.js.map +1 -1
  645. package/dist/modes/interactive/interactive-mode.d.ts +90 -5
  646. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  647. package/dist/modes/interactive/interactive-mode.js +729 -206
  648. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  649. package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
  650. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
  651. package/dist/modes/interactive/model-catalog-refresh.js +34 -0
  652. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
  653. package/dist/modes/interactive/theme/apex.json +93 -0
  654. package/dist/modes/interactive/theme/dark.json +2 -0
  655. package/dist/modes/interactive/theme/light.json +3 -1
  656. package/dist/modes/interactive/theme/theme-controller.d.ts +10 -2
  657. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  658. package/dist/modes/interactive/theme/theme-controller.js +25 -11
  659. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  660. package/dist/modes/interactive/theme/theme-schema.json +11 -3
  661. package/dist/modes/interactive/theme/theme.d.ts +14 -3
  662. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  663. package/dist/modes/interactive/theme/theme.js +65 -10
  664. package/dist/modes/interactive/theme/theme.js.map +1 -1
  665. package/dist/modes/json-event.d.ts +18 -12
  666. package/dist/modes/json-event.d.ts.map +1 -1
  667. package/dist/modes/json-event.js +22 -5
  668. package/dist/modes/json-event.js.map +1 -1
  669. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  670. package/dist/modes/rpc/rpc-mode.js +2 -1
  671. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  672. package/dist/package-manager-cli.d.ts +1 -0
  673. package/dist/package-manager-cli.d.ts.map +1 -1
  674. package/dist/package-manager-cli.js +210 -19
  675. package/dist/package-manager-cli.js.map +1 -1
  676. package/dist/rpc-entry.d.ts.map +1 -1
  677. package/dist/rpc-entry.js +2 -1
  678. package/dist/rpc-entry.js.map +1 -1
  679. package/dist/testing/replay/metrics.d.ts +24 -0
  680. package/dist/testing/replay/metrics.d.ts.map +1 -0
  681. package/dist/testing/replay/metrics.js +35 -0
  682. package/dist/testing/replay/metrics.js.map +1 -0
  683. package/dist/testing/replay/recorded-provider.d.ts +10 -0
  684. package/dist/testing/replay/recorded-provider.d.ts.map +1 -0
  685. package/dist/testing/replay/recorded-provider.js +108 -0
  686. package/dist/testing/replay/recorded-provider.js.map +1 -0
  687. package/dist/testing/replay/runner.d.ts +56 -0
  688. package/dist/testing/replay/runner.d.ts.map +1 -0
  689. package/dist/testing/replay/runner.js +406 -0
  690. package/dist/testing/replay/runner.js.map +1 -0
  691. package/dist/themes/apex-logo.d.ts +41 -0
  692. package/dist/themes/apex-logo.d.ts.map +1 -0
  693. package/dist/themes/apex-logo.js +35 -0
  694. package/dist/themes/apex-logo.js.map +1 -0
  695. package/dist/utils/apex-code-user-agent.d.ts +2 -0
  696. package/dist/utils/apex-code-user-agent.d.ts.map +1 -0
  697. package/dist/utils/apex-code-user-agent.js +5 -0
  698. package/dist/utils/apex-code-user-agent.js.map +1 -0
  699. package/dist/utils/changelog.d.ts +7 -2
  700. package/dist/utils/changelog.d.ts.map +1 -1
  701. package/dist/utils/changelog.js +82 -13
  702. package/dist/utils/changelog.js.map +1 -1
  703. package/dist/utils/clipboard-image.d.ts.map +1 -1
  704. package/dist/utils/clipboard-image.js +1 -1
  705. package/dist/utils/clipboard-image.js.map +1 -1
  706. package/dist/utils/frontmatter.d.ts.map +1 -1
  707. package/dist/utils/frontmatter.js +2 -1
  708. package/dist/utils/frontmatter.js.map +1 -1
  709. package/dist/utils/management-http.d.ts +5 -3
  710. package/dist/utils/management-http.d.ts.map +1 -1
  711. package/dist/utils/management-http.js +14 -10
  712. package/dist/utils/management-http.js.map +1 -1
  713. package/dist/utils/shell.d.ts +3 -0
  714. package/dist/utils/shell.d.ts.map +1 -1
  715. package/dist/utils/shell.js +17 -5
  716. package/dist/utils/shell.js.map +1 -1
  717. package/dist/utils/syntax-highlight.d.ts +1 -0
  718. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  719. package/dist/utils/syntax-highlight.js +60 -1
  720. package/dist/utils/syntax-highlight.js.map +1 -1
  721. package/dist/utils/text.d.ts +8 -0
  722. package/dist/utils/text.d.ts.map +1 -0
  723. package/dist/utils/text.js +9 -0
  724. package/dist/utils/text.js.map +1 -0
  725. package/dist/utils/tools-manager.d.ts +70 -2
  726. package/dist/utils/tools-manager.d.ts.map +1 -1
  727. package/dist/utils/tools-manager.js +280 -124
  728. package/dist/utils/tools-manager.js.map +1 -1
  729. package/dist/utils/version-check.d.ts +7 -5
  730. package/dist/utils/version-check.d.ts.map +1 -1
  731. package/dist/utils/version-check.js +27 -14
  732. package/dist/utils/version-check.js.map +1 -1
  733. package/dist/utils/windows-self-update.d.ts.map +1 -1
  734. package/dist/utils/windows-self-update.js +1 -1
  735. package/dist/utils/windows-self-update.js.map +1 -1
  736. package/docs/compaction.md +41 -24
  737. package/docs/containerization.md +24 -21
  738. package/docs/custom-provider.md +15 -12
  739. package/docs/development.md +11 -11
  740. package/docs/environment-variables.md +37 -77
  741. package/docs/extensions.md +68 -54
  742. package/docs/index.md +12 -24
  743. package/docs/json.md +18 -11
  744. package/docs/keybindings.md +18 -12
  745. package/docs/llama-cpp.md +9 -7
  746. package/docs/models.md +17 -11
  747. package/docs/packages.md +47 -43
  748. package/docs/prompt-templates.md +3 -3
  749. package/docs/providers.md +10 -10
  750. package/docs/quickstart.md +49 -32
  751. package/docs/rpc.md +35 -18
  752. package/docs/sdk.md +20 -6
  753. package/docs/security.md +18 -18
  754. package/docs/session-format.md +9 -9
  755. package/docs/sessions.md +13 -13
  756. package/docs/settings.md +83 -16
  757. package/docs/shell-aliases.md +1 -1
  758. package/docs/skills.md +66 -15
  759. package/docs/terminal-setup.md +44 -19
  760. package/docs/termux.md +4 -4
  761. package/docs/themes.md +32 -11
  762. package/docs/tmux.md +4 -4
  763. package/docs/tui.md +5 -5
  764. package/docs/usage.md +61 -53
  765. package/docs/windows.md +24 -2
  766. package/examples/extensions/border-status-editor.ts +1 -1
  767. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  768. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  769. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  770. package/examples/extensions/git-checkpoint.ts +24 -36
  771. package/examples/extensions/gondolin/package-lock.json +2 -2
  772. package/examples/extensions/gondolin/package.json +1 -1
  773. package/examples/extensions/notify.ts +3 -1
  774. package/examples/extensions/sandbox/package-lock.json +2 -2
  775. package/examples/extensions/sandbox/package.json +1 -1
  776. package/examples/extensions/subagent/README.md +3 -1
  777. package/examples/extensions/subagent/agents.ts +40 -9
  778. package/examples/extensions/subagent/index.ts +27 -4
  779. package/examples/extensions/titlebar-spinner.ts +1 -1
  780. package/examples/extensions/with-deps/package-lock.json +2 -2
  781. package/examples/extensions/with-deps/package.json +1 -1
  782. package/examples/rpc-extension-ui.ts +1 -1
  783. package/examples/sdk/06-extensions.ts +1 -1
  784. package/examples/sdk/README.md +1 -1
  785. package/npm-shrinkwrap.json +435 -452
  786. package/package.json +17 -18
  787. package/dist/core/telemetry.d.ts +0 -3
  788. package/dist/core/telemetry.d.ts.map +0 -1
  789. package/dist/core/telemetry.js +0 -9
  790. package/dist/core/telemetry.js.map +0 -1
  791. package/dist/server/create-harness.d.ts +0 -26
  792. package/dist/server/create-harness.d.ts.map +0 -1
  793. package/dist/server/create-harness.js +0 -104
  794. package/dist/server/create-harness.js.map +0 -1
  795. package/dist/utils/pi-user-agent.d.ts +0 -2
  796. package/dist/utils/pi-user-agent.d.ts.map +0 -1
  797. package/dist/utils/pi-user-agent.js +0 -5
  798. package/dist/utils/pi-user-agent.js.map +0 -1
@@ -12,31 +12,42 @@
12
12
  *
13
13
  * Modes use this class and add their own I/O layer on top.
14
14
  */
15
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
15
+ import { readFileSync } from "node:fs";
16
16
  import { basename, dirname } from "node:path";
17
17
  import { contentText } from "@earendil-works/pi-ai";
18
- import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple, } from "@earendil-works/pi-ai/compat";
18
+ import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, } from "@earendil-works/pi-ai/compat";
19
19
  import { getThemeByName, theme } from "../modes/interactive/theme/theme.js";
20
20
  import { stripFrontmatter } from "../utils/frontmatter.js";
21
- import { resolvePath } from "../utils/paths.js";
22
21
  import { sleep } from "../utils/sleep.js";
23
22
  import { normalizeToolResultImages } from "../utils/tool-result-images.js";
24
23
  import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
25
24
  import { executeBashWithOperations } from "./bash-executor.js";
25
+ import { createSessionCheckpoints } from "./checkpoints/session-checkpoints.js";
26
26
  import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
27
- import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
27
+ import { evictionBudget, installContextPipeline, isDefaultStreamFunction } from "./context/pipeline.js";
28
+ import { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from "./defaults.js";
29
+ import { SessionEvidenceSink } from "./evidence.js";
28
30
  import { exportSessionToHtml } from "./export-html/index.js";
29
31
  import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
30
32
  import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
31
33
  import { emitSessionShutdownEvent } from "./extensions/runner.js";
32
34
  import { ModelRegistry } from "./model-registry.js";
35
+ import { evaluateToolCall } from "./permissions/gate.js";
36
+ import { createInteractiveResponder } from "./permissions/responder.js";
37
+ import { resolveEffectiveModeWithOrigin } from "./permissions/startup.js";
33
38
  import { expandPromptTemplate } from "./prompt-templates.js";
34
- import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
39
+ import { exportSessionToJsonl } from "./session-export.js";
40
+ import { getLatestCompactionEntry, TODO_CUSTOM_ENTRY_TYPE } from "./session-manager.js";
41
+ import { slugifySkillCommandName } from "./skills.js";
35
42
  import { createSyntheticSourceInfo } from "./source-info.js";
36
43
  import { buildSystemPrompt } from "./system-prompt.js";
37
44
  import { createLocalBashOperations } from "./tools/bash.js";
45
+ import { buildToolContractSnapshot, isUnclassifiedTool, } from "./tools/contract-snapshot.js";
38
46
  import { createAllToolDefinitions } from "./tools/index.js";
47
+ import { createSkillSearchToolDefinition } from "./tools/skill-search.js";
48
+ import { createTodoWriteToolDefinition } from "./tools/todo-write.js";
39
49
  import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
50
+ import { createToolSchemaToolDefinition } from "./tools/tool-schema.js";
40
51
  import { addUsageToTotals, createUsageTotals } from "./usage-totals.js";
41
52
  /**
42
53
  * Parse a skill block from message text.
@@ -71,8 +82,6 @@ function estimateMessagesTokens(messages) {
71
82
  // ============================================================================
72
83
  // Constants
73
84
  // ============================================================================
74
- /** Standard thinking levels */
75
- const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
76
85
  // ============================================================================
77
86
  // AgentSession Class
78
87
  // ============================================================================
@@ -97,6 +106,7 @@ export class AgentSession {
97
106
  _compactionAbortController = undefined;
98
107
  _autoCompactionAbortController = undefined;
99
108
  _overflowRecoveryAttempted = false;
109
+ _midRunCompactionNeeded = false;
100
110
  // Branch summarization state
101
111
  _branchSummaryAbortController = undefined;
102
112
  // Retry state
@@ -118,6 +128,21 @@ export class AgentSession {
118
128
  _excludedToolNames;
119
129
  _baseToolsOverride;
120
130
  _sessionStartEvent;
131
+ _permissionGate;
132
+ _evidenceSink;
133
+ _diagnosticsOperations;
134
+ _lspOperations;
135
+ _mcpRuntime;
136
+ /** Configured MCP subsystem, or undefined when no server is configured. */
137
+ get mcpRuntime() {
138
+ return this._mcpRuntime;
139
+ }
140
+ _checkpoints;
141
+ /** Worktree checkpoints for this session. Inert unless `checkpoints.enabled` is set. */
142
+ get checkpoints() {
143
+ return this._checkpoints;
144
+ }
145
+ _webSearchOperations;
121
146
  _extensionUIContext;
122
147
  _extensionMode = "print";
123
148
  _extensionCommandContextActions;
@@ -131,6 +156,7 @@ export class AgentSession {
131
156
  _toolDefinitions = new Map();
132
157
  _toolPromptSnippets = new Map();
133
158
  _toolPromptGuidelines = new Map();
159
+ _loadedDeferredSchemas = new Set();
134
160
  // Base system prompt (without extension appends) - used to apply fresh appends each turn
135
161
  _baseSystemPrompt = "";
136
162
  _baseSystemPromptOptions;
@@ -150,11 +176,24 @@ export class AgentSession {
150
176
  this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
151
177
  this._baseToolsOverride = config.baseToolsOverride;
152
178
  this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
179
+ this._permissionGate = config.permissionGate;
180
+ this._evidenceSink = config.evidenceSink ?? new SessionEvidenceSink(this.sessionManager);
181
+ this._diagnosticsOperations = config.diagnosticsOperations;
182
+ this._lspOperations = config.lspOperations;
183
+ this._mcpRuntime = config.mcpRuntime;
184
+ this._webSearchOperations = config.webSearchOperations;
185
+ this._checkpoints = createSessionCheckpoints({
186
+ workspace: this._cwd,
187
+ sessionId: this.sessionManager.getSessionId(),
188
+ settings: config.checkpointSettings,
189
+ });
153
190
  // Always subscribe to agent events for internal handling
154
191
  // (session persistence, extensions, auto-compaction, retry logic)
155
192
  this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
156
193
  this._installAgentToolHooks();
157
194
  this._installAgentNextTurnRefresh();
195
+ this._installMidRunCompactionHook();
196
+ this._installContextPipeline();
158
197
  this._buildRuntime({
159
198
  activeToolNames: this._initialActiveToolNames,
160
199
  includeAllExtensionTools: true,
@@ -193,7 +232,7 @@ export class AgentSession {
193
232
  throw new Error(formatNoApiKeyFoundMessage(model.provider));
194
233
  }
195
234
  async _getSummarizationRequestAuth(model) {
196
- if (this.agent.streamFunction === streamSimple) {
235
+ if (isDefaultStreamFunction(this.agent.streamFunction)) {
197
236
  return this._getRequiredRequestAuth(model);
198
237
  }
199
238
  try {
@@ -223,25 +262,63 @@ export class AgentSession {
223
262
  _installAgentToolHooks() {
224
263
  this.agent.beforeToolCall = async ({ toolCall, args }) => {
225
264
  const runner = this._extensionRunner;
226
- if (!runner.hasHandlers("tool_call")) {
227
- return undefined;
228
- }
229
- try {
230
- return await runner.emitToolCall({
231
- type: "tool_call",
232
- toolName: toolCall.name,
233
- toolCallId: toolCall.id,
234
- input: args,
235
- });
236
- }
237
- catch (err) {
238
- if (err instanceof Error) {
239
- throw err;
265
+ if (runner.hasHandlers("tool_call")) {
266
+ let extensionResult;
267
+ try {
268
+ extensionResult = await runner.emitToolCall({
269
+ type: "tool_call",
270
+ toolName: toolCall.name,
271
+ toolCallId: toolCall.id,
272
+ input: args,
273
+ });
274
+ }
275
+ catch (err) {
276
+ if (err instanceof Error) {
277
+ throw err;
278
+ }
279
+ throw new Error(`Extension failed, blocking execution: ${String(err)}`);
240
280
  }
241
- throw new Error(`Extension failed, blocking execution: ${String(err)}`);
281
+ // A blocking extension remains authoritative. A non-blocking result
282
+ // (including a mutation-only `{}`) must still pass the permission gate,
283
+ // which evaluates the extension's final input below.
284
+ if (extensionResult?.block === true)
285
+ return extensionResult;
286
+ }
287
+ // Permission gate (roadmap Phase 2a, ADR 0004). Off by default — see
288
+ // AgentSessionConfig.permissionGate. When present, every registered tool
289
+ // call passes through it (contracts.md invariant 2): this is the seam,
290
+ // not a per-tool opt-in.
291
+ if (this._permissionGate) {
292
+ const decision = await evaluateToolCall(toolCall.name, args, {
293
+ ...this._permissionGate,
294
+ getContract: (name) => this.getToolDefinition(name)?.contract,
295
+ getResponder: () => this._extensionMode === "tui" && this._extensionUIContext
296
+ ? createInteractiveResponder(this._extensionUIContext)
297
+ : undefined,
298
+ });
299
+ if (decision.block)
300
+ return { block: true, reason: decision.reason };
242
301
  }
302
+ return undefined;
243
303
  };
244
304
  this.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {
305
+ const definition = this.getToolDefinition(toolCall.name);
306
+ if (this._evidenceSink && definition?.contract) {
307
+ try {
308
+ const records = definition.contract.evidence.capture(args, result);
309
+ if (!records.every((record) => definition.contract?.evidence.emits.has(record.kind))) {
310
+ throw new Error("Evidence capture emitted a kind not declared by its tool contract");
311
+ }
312
+ if (records.length > 0)
313
+ this._evidenceSink.record({ toolName: toolCall.name, records });
314
+ }
315
+ catch (error) {
316
+ this._evidenceSink.recordDiagnostic?.({
317
+ toolName: toolCall.name,
318
+ reason: error instanceof Error ? error.message : String(error),
319
+ });
320
+ }
321
+ }
245
322
  const runner = this._extensionRunner;
246
323
  const hookResult = runner.hasHandlers("tool_result")
247
324
  ? await runner.emitToolResult({
@@ -291,6 +368,75 @@ export class AgentSession {
291
368
  };
292
369
  };
293
370
  }
371
+ /** Stop an over-threshold tool loop before it sends another provider request. */
372
+ _installMidRunCompactionHook() {
373
+ const previousShouldStopAfterTurn = this.agent.shouldStopAfterTurn;
374
+ this.agent.shouldStopAfterTurn = async (turn, signal) => {
375
+ if (await previousShouldStopAfterTurn?.(turn, signal)) {
376
+ return true;
377
+ }
378
+ return this._shouldStopForMidRunCompaction(turn);
379
+ };
380
+ }
381
+ _shouldStopForMidRunCompaction(turn) {
382
+ if (!turn.hasMoreToolCalls || turn.toolResults.length === 0) {
383
+ return false;
384
+ }
385
+ const settings = this.settingsManager.getCompactionSettings();
386
+ if (!settings.enabled) {
387
+ return false;
388
+ }
389
+ const contextWindow = this.model?.contextWindow ?? 0;
390
+ if (contextWindow <= 0) {
391
+ return false;
392
+ }
393
+ const contextTokens = estimateContextTokens(turn.context.messages).tokens;
394
+ if (!shouldCompact(contextTokens, contextWindow, settings)) {
395
+ return false;
396
+ }
397
+ this._midRunCompactionNeeded = true;
398
+ return true;
399
+ }
400
+ /**
401
+ * Installs the context pipeline settled in `docs/architecture/contracts.md` § 2:
402
+ * deferred-schema resolution → tool-result eviction → compaction. Compaction
403
+ * already runs reactively from `_checkCompaction`, after a response comes back
404
+ * over-threshold or overflowed; this method only adds the two stages that run
405
+ * *ahead of* every LLM request, so that reactive check is reached less often
406
+ * because the request it is reacting to is smaller. It does not call into
407
+ * compaction and does not need to.
408
+ *
409
+ * The wiring itself — where each stage attaches, and why they land in different
410
+ * seams (`transformContext` for eviction, `streamFunction` for schema
411
+ * projection) — lives in `./context/pipeline.ts`'s `installContextPipeline`,
412
+ * shared with the offline replay harness so there is one implementation, not
413
+ * two. This method only supplies this session's two dependencies: a contract
414
+ * lookup backed by `getToolDefinition`, and a budget thunk (never cached — see
415
+ * `_evictionBudget`, which reads live `this.model` / `this.settingsManager` on
416
+ * every call, so a model switch or settings edit mid-session takes effect on
417
+ * the very next request).
418
+ */
419
+ _installContextPipeline() {
420
+ installContextPipeline(this.agent, {
421
+ contractLookup: (name) => this.getToolDefinition(name)?.contract,
422
+ loadedSchemaNames: this._loadedDeferredSchemas,
423
+ evictionBudget: () => this._evictionBudget(),
424
+ });
425
+ }
426
+ /**
427
+ * Token budget for `evictToolResults`'s outbound pass, derived from the same
428
+ * quantities compaction already uses for its own threshold
429
+ * (`getCompactionSettings()`; see `shouldCompact` in
430
+ * `core/compaction/compaction.ts`). The formula itself is `./context/
431
+ * pipeline.ts`'s `evictionBudget` — see that function's comment for the "why
432
+ * half of headroom" reasoning; this method only supplies production's real
433
+ * `contextWindow` / `reserveTokens` inputs.
434
+ */
435
+ _evictionBudget() {
436
+ const contextWindow = this.model?.contextWindow ?? 0;
437
+ const { reserveTokens } = this.settingsManager.getCompactionSettings();
438
+ return evictionBudget(contextWindow, reserveTokens);
439
+ }
294
440
  // =========================================================================
295
441
  // Event Subscription
296
442
  // =========================================================================
@@ -307,6 +453,11 @@ export class AgentSession {
307
453
  followUp: [...this._followUpMessages],
308
454
  });
309
455
  }
456
+ async _emitSessionCompactFailed(event) {
457
+ if (this._extensionRunner.hasHandlers("session_compact_failed")) {
458
+ await this._extensionRunner.emit({ type: "session_compact_failed", ...event });
459
+ }
460
+ }
310
461
  _getIdleWaitPromise() {
311
462
  if (!this._idleWaitPromise) {
312
463
  this._idleWaitPromise = new Promise((resolve) => {
@@ -446,6 +597,18 @@ export class AgentSession {
446
597
  await this._extensionRunner.emit({ type: "agent_end", messages: event.messages });
447
598
  }
448
599
  else if (event.type === "turn_start") {
600
+ // Snapshot before the model gets to act, keyed to the entry `/tree` and `/fork`
601
+ // already navigate to, so the two agree about what an entry means.
602
+ //
603
+ // Awaited, despite the turn latency. Detached, the snapshot races the turn it is
604
+ // supposed to precede: a tool call can edit the worktree while `add -A` is still
605
+ // walking it, and the ref then holds mid-turn state that no `/fork` should ever
606
+ // restore. "The state before the model acted" is the whole guarantee, so paying
607
+ // for it here is the point. The engine's own timeout bounds the wait and a failed
608
+ // capture is never fatal.
609
+ const leafEntryId = this.sessionManager.getLeafEntry()?.id;
610
+ if (leafEntryId)
611
+ await this._checkpoints.capture(leafEntryId);
449
612
  const extensionEvent = {
450
613
  type: "turn_start",
451
614
  turnIndex: this._turnIndex,
@@ -567,6 +730,9 @@ export class AgentSession {
567
730
  this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload().");
568
731
  this._disconnectFromAgent();
569
732
  this._eventListeners = [];
733
+ // Every connected MCP server is a child process this session started. Without
734
+ // this, one leaks per server per session, because nothing else owns them.
735
+ this._mcpRuntime?.close().catch(() => undefined);
570
736
  cleanupSessionResources(this.sessionId);
571
737
  }
572
738
  // =========================================================================
@@ -610,13 +776,24 @@ export class AgentSession {
610
776
  /**
611
777
  * Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
612
778
  */
779
+ /**
780
+ * The ADR 0010 projection over this session's registry: the one read every surface
781
+ * that *describes* the tool set consumes. Never an authorization input.
782
+ */
783
+ getToolContractSnapshot() {
784
+ return buildToolContractSnapshot(Array.from(this._toolDefinitions.values()).map(({ definition }) => definition));
785
+ }
613
786
  getAllTools() {
614
- return Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({
787
+ const schemaToolActive = this.getActiveToolNames().includes("tool_schema");
788
+ return Array.from(this._toolDefinitions.values())
789
+ .filter(({ definition }) => definition.name !== "tool_schema" || schemaToolActive)
790
+ .map(({ definition, sourceInfo }) => ({
615
791
  name: definition.name,
616
792
  description: definition.description,
617
793
  parameters: definition.parameters,
618
794
  promptGuidelines: definition.promptGuidelines,
619
795
  sourceInfo,
796
+ unclassified: isUnclassifiedTool(definition),
620
797
  }));
621
798
  }
622
799
  getToolDefinition(name) {
@@ -756,6 +933,10 @@ export class AgentSession {
756
933
  }
757
934
  }
758
935
  async _handlePostAgentRun() {
936
+ if (this._midRunCompactionNeeded) {
937
+ this._midRunCompactionNeeded = false;
938
+ return await this._runAutoCompaction("threshold", true);
939
+ }
759
940
  const msg = this._lastAssistantMessage;
760
941
  this._lastAssistantMessage = undefined;
761
942
  if (!msg) {
@@ -954,9 +1135,16 @@ export class AgentSession {
954
1135
  if (!text.startsWith("/skill:"))
955
1136
  return text;
956
1137
  const spaceIndex = text.indexOf(" ");
957
- const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
1138
+ const commandToken = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
958
1139
  const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1).trim();
959
- const skill = this.resourceLoader.getSkills().skills.find((s) => s.name === skillName);
1140
+ // Matched against the slugged command token (SKILL.5), not the raw frontmatter
1141
+ // name -- identity for an already command-safe name, so an exactly-typed raw
1142
+ // name still matches too. A skill whose name contains a space or other
1143
+ // slash-command-breaking character (docs/skills.md's lenient loading allows
1144
+ // this) is only reachable through its slugged token.
1145
+ const skill = this.resourceLoader
1146
+ .getSkills()
1147
+ .skills.find((s) => slugifySkillCommandName(s.name) === commandToken);
960
1148
  if (!skill)
961
1149
  return text; // Unknown skill, pass through
962
1150
  try {
@@ -1078,7 +1266,7 @@ export class AgentSession {
1078
1266
  if (options?.deliverAs === "nextTurn") {
1079
1267
  this._pendingNextTurnMessages.push(appMessage);
1080
1268
  }
1081
- else if (this.isStreaming) {
1269
+ else if (this.isStreaming && options?.triggerTurn !== false) {
1082
1270
  if (options?.deliverAs === "followUp") {
1083
1271
  this.agent.followUp(appMessage);
1084
1272
  }
@@ -1102,6 +1290,7 @@ export class AgentSession {
1102
1290
  *
1103
1291
  * @param content User message content (string or content array)
1104
1292
  * @param options.deliverAs Delivery mode when streaming: "steer" or "followUp"
1293
+ * @param options.expandPromptTemplates Whether to dispatch extension commands and expand skill commands and prompt templates. Default: false.
1105
1294
  */
1106
1295
  async sendUserMessage(content, options) {
1107
1296
  // Normalize content to text string + optional images
@@ -1125,9 +1314,8 @@ export class AgentSession {
1125
1314
  if (images.length === 0)
1126
1315
  images = undefined;
1127
1316
  }
1128
- // Use prompt() with expandPromptTemplates: false to skip command handling and template expansion
1129
1317
  await this.prompt(text, {
1130
- expandPromptTemplates: false,
1318
+ expandPromptTemplates: options?.expandPromptTemplates ?? false,
1131
1319
  streamingBehavior: options?.deliverAs,
1132
1320
  images,
1133
1321
  source: "extension",
@@ -1189,21 +1377,53 @@ export class AgentSession {
1189
1377
  source,
1190
1378
  });
1191
1379
  }
1380
+ /** True when this session runs behind a permission gate at all. */
1381
+ get hasPermissionGate() {
1382
+ return this._permissionGate !== undefined;
1383
+ }
1384
+ /**
1385
+ * The mode in force right now, and which source won. `getMode` in the gate
1386
+ * config re-reads the store on every decision, so a mode written here applies
1387
+ * to the next tool call with no restart.
1388
+ */
1389
+ async getPermissionMode() {
1390
+ if (!this._permissionGate)
1391
+ return undefined;
1392
+ const snapshot = await this._permissionGate.store.snapshot();
1393
+ return resolveEffectiveModeWithOrigin(this._permissionGate.flagMode, snapshot.modesBySource);
1394
+ }
1395
+ /**
1396
+ * Persist a permission mode to user scope (`~/.apex-code/agent/permissions.json`).
1397
+ * Returns the resolution that is actually in force afterwards, which is *not*
1398
+ * necessarily `mode`: `flag`, `local`, and `project` all outrank `user`, so the
1399
+ * caller has to be able to tell the user their choice was recorded but shadowed.
1400
+ */
1401
+ async setPermissionMode(mode) {
1402
+ if (!this._permissionGate)
1403
+ return undefined;
1404
+ await this._permissionGate.store.apply({ type: "setMode", destination: "user", mode });
1405
+ return this.getPermissionMode();
1406
+ }
1192
1407
  /**
1193
1408
  * Set model directly.
1194
- * Validates that auth is configured, saves to session and settings.
1409
+ * Validates that auth is configured and saves to the session transcript.
1410
+ * Persists to global defaults only when options.persist is true.
1195
1411
  * @throws Error if no auth is configured for the model
1196
1412
  */
1197
- async setModel(model) {
1413
+ async setModel(model, options = {}) {
1198
1414
  if (!(await this._modelRuntime.checkAuth(model.provider))) {
1199
1415
  throw new Error(`No API key for ${model.provider}/${model.id}`);
1200
1416
  }
1201
1417
  const previousModel = this.model;
1202
- const thinkingLevel = this._getThinkingLevelForModelSwitch();
1418
+ const thinkingLevel = this._getThinkingLevelForModelSwitch(model);
1203
1419
  this.agent.state.model = model;
1204
1420
  this.sessionManager.appendModelChange(model.provider, model.id);
1205
- this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
1206
- // Re-clamp thinking level for new model's capabilities
1421
+ if (options.persist) {
1422
+ this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
1423
+ }
1424
+ // Apply thinking level for the new model.
1425
+ // Per-model thinking level overrides take priority over the global default.
1426
+ // Model persistence does not implicitly rewrite the global thinking default.
1207
1427
  this.setThinkingLevel(thinkingLevel);
1208
1428
  await this._emitModelSelect(model, previousModel, "set");
1209
1429
  }
@@ -1213,13 +1433,13 @@ export class AgentSession {
1213
1433
  * @param direction - "forward" (default) or "backward"
1214
1434
  * @returns The new model info, or undefined if only one model available
1215
1435
  */
1216
- async cycleModel(direction = "forward") {
1436
+ async cycleModel(direction = "forward", options = {}) {
1217
1437
  if (this._scopedModels.length > 0) {
1218
- return this._cycleScopedModel(direction);
1438
+ return this._cycleScopedModel(direction, options);
1219
1439
  }
1220
- return this._cycleAvailableModel(direction);
1440
+ return this._cycleAvailableModel(direction, options);
1221
1441
  }
1222
- async _cycleScopedModel(direction) {
1442
+ async _cycleScopedModel(direction, options) {
1223
1443
  const availableIds = new Set(this._modelRuntime.getAvailableSnapshot().map((model) => `${model.provider}\0${model.id}`));
1224
1444
  const scopedModels = this._scopedModels.filter((scoped) => availableIds.has(`${scoped.model.provider}\0${scoped.model.id}`));
1225
1445
  if (scopedModels.length <= 1)
@@ -1231,20 +1451,23 @@ export class AgentSession {
1231
1451
  const len = scopedModels.length;
1232
1452
  const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
1233
1453
  const next = scopedModels[nextIndex];
1234
- const thinkingLevel = this._getThinkingLevelForModelSwitch(next.thinkingLevel);
1454
+ const thinkingLevel = this._getThinkingLevelForModelSwitch(next.model, next.thinkingLevel);
1235
1455
  // Apply model
1236
1456
  this.agent.state.model = next.model;
1237
1457
  this.sessionManager.appendModelChange(next.model.provider, next.model.id);
1238
- this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
1239
- // Apply thinking level.
1240
- // - Explicit scoped model thinking level overrides current session level
1241
- // - Undefined scoped model thinking level inherits the current session preference
1458
+ if (options.persist) {
1459
+ this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
1460
+ }
1461
+ // Apply thinking level for the new model.
1462
+ // - Explicit scoped model thinking level overrides defaults
1463
+ // - Per-model thinking level overrides take priority over the global default
1242
1464
  // setThinkingLevel clamps to model capabilities.
1465
+ // Model persistence does not implicitly rewrite the global thinking default.
1243
1466
  this.setThinkingLevel(thinkingLevel);
1244
1467
  await this._emitModelSelect(next.model, currentModel, "cycle");
1245
1468
  return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true };
1246
1469
  }
1247
- async _cycleAvailableModel(direction) {
1470
+ async _cycleAvailableModel(direction, options) {
1248
1471
  const availableModels = this._modelRuntime.getAvailableSnapshot();
1249
1472
  if (availableModels.length <= 1)
1250
1473
  return undefined;
@@ -1255,11 +1478,14 @@ export class AgentSession {
1255
1478
  const len = availableModels.length;
1256
1479
  const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
1257
1480
  const nextModel = availableModels[nextIndex];
1258
- const thinkingLevel = this._getThinkingLevelForModelSwitch();
1481
+ const thinkingLevel = this._getThinkingLevelForModelSwitch(nextModel);
1259
1482
  this.agent.state.model = nextModel;
1260
1483
  this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
1261
- this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
1262
- // Re-clamp thinking level for new model's capabilities
1484
+ if (options.persist) {
1485
+ this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
1486
+ }
1487
+ // Apply thinking level for the new model.
1488
+ // Model persistence does not implicitly rewrite the global thinking default.
1263
1489
  this.setThinkingLevel(thinkingLevel);
1264
1490
  await this._emitModelSelect(nextModel, currentModel, "cycle");
1265
1491
  return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: false };
@@ -1270,20 +1496,21 @@ export class AgentSession {
1270
1496
  /**
1271
1497
  * Set thinking level.
1272
1498
  * Clamps to model capabilities based on available thinking levels.
1273
- * Saves to session and settings only if the level actually changes.
1499
+ * Saves the clamped level to the session transcript only if the level actually changes.
1500
+ * Persists the requested level to global defaults only when options.persist is true.
1274
1501
  */
1275
- setThinkingLevel(level) {
1502
+ setThinkingLevel(level, options = {}) {
1276
1503
  const availableLevels = this.getAvailableThinkingLevels();
1277
1504
  const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
1278
1505
  // Only persist if actually changing
1279
1506
  const previousLevel = this.agent.state.thinkingLevel;
1280
1507
  const isChanging = effectiveLevel !== previousLevel;
1281
1508
  this.agent.state.thinkingLevel = effectiveLevel;
1509
+ if (options.persist) {
1510
+ this.settingsManager.setDefaultThinkingLevel(level);
1511
+ }
1282
1512
  if (isChanging) {
1283
1513
  this.sessionManager.appendThinkingLevelChange(effectiveLevel);
1284
- if (this.supportsThinking() || effectiveLevel !== "off") {
1285
- this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
1286
- }
1287
1514
  this._emit({ type: "thinking_level_changed", level: effectiveLevel });
1288
1515
  void this._extensionRunner.emit({
1289
1516
  type: "thinking_level_select",
@@ -1296,14 +1523,14 @@ export class AgentSession {
1296
1523
  * Cycle to next thinking level.
1297
1524
  * @returns New level, or undefined if model doesn't support thinking
1298
1525
  */
1299
- cycleThinkingLevel() {
1526
+ cycleThinkingLevel(options = {}) {
1300
1527
  if (!this.supportsThinking())
1301
1528
  return undefined;
1302
1529
  const levels = this.getAvailableThinkingLevels();
1303
1530
  const currentIndex = levels.indexOf(this.thinkingLevel);
1304
1531
  const nextIndex = (currentIndex + 1) % levels.length;
1305
1532
  const nextLevel = levels[nextIndex];
1306
- this.setThinkingLevel(nextLevel);
1533
+ this.setThinkingLevel(nextLevel, options);
1307
1534
  return nextLevel;
1308
1535
  }
1309
1536
  /**
@@ -1312,7 +1539,7 @@ export class AgentSession {
1312
1539
  */
1313
1540
  getAvailableThinkingLevels() {
1314
1541
  if (!this.model)
1315
- return THINKING_LEVELS;
1542
+ return [...THINKING_LEVEL_OPTIONS];
1316
1543
  return getSupportedThinkingLevels(this.model);
1317
1544
  }
1318
1545
  /**
@@ -1321,14 +1548,18 @@ export class AgentSession {
1321
1548
  supportsThinking() {
1322
1549
  return !!this.model?.reasoning;
1323
1550
  }
1324
- _getThinkingLevelForModelSwitch(explicitLevel) {
1551
+ _getThinkingLevelForModelSwitch(targetModel, explicitLevel) {
1325
1552
  if (explicitLevel !== undefined) {
1326
1553
  return explicitLevel;
1327
1554
  }
1328
- if (!this.supportsThinking()) {
1329
- return this.settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;
1555
+ // Per-model default takes priority when switching to a model that has one
1556
+ if (targetModel) {
1557
+ const perModel = this.settingsManager.getModelThinkingLevel(targetModel.provider, targetModel.id);
1558
+ if (perModel !== undefined) {
1559
+ return perModel;
1560
+ }
1330
1561
  }
1331
- return this.thinkingLevel;
1562
+ return this.settingsManager.getDefaultThinkingLevel() ?? this.thinkingLevel ?? DEFAULT_THINKING_LEVEL;
1332
1563
  }
1333
1564
  _clampThinkingLevel(level, _availableLevels) {
1334
1565
  return this.model ? clampThinkingLevel(this.model, level) : "off";
@@ -1359,15 +1590,30 @@ export class AgentSession {
1359
1590
  // =========================================================================
1360
1591
  // Compaction
1361
1592
  // =========================================================================
1593
+ /** Generate Pi's built-in compaction summary for manual and automatic compaction. */
1594
+ async _runDefaultCompaction(preparation, requestModel, apiKey, headers, customInstructions, signal, env, reason) {
1595
+ return compact(preparation, requestModel, apiKey, headers, customInstructions, signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }), undefined);
1596
+ }
1362
1597
  /**
1363
1598
  * Manually compact the session context.
1364
- * Aborts current agent operation first.
1599
+ *
1600
+ * This is the manual entry point used by `/compact`, RPC, and extensions. It is
1601
+ * separate from automatic threshold/overflow compaction, which enters through
1602
+ * `_checkCompaction()` and `_runAutoCompaction()`. After preparation and the
1603
+ * `session_before_compact` hook, both paths call the lower-level `compact()`
1604
+ * function imported from `./compaction/index.ts`, unless the hook cancels or
1605
+ * supplies a custom result.
1606
+ *
1607
+ * Aborts the current agent operation first. Manual compaction never retries or
1608
+ * continues the interrupted agent turn.
1609
+ *
1365
1610
  * @param customInstructions Optional instructions for the compaction summary
1366
1611
  */
1367
1612
  async compact(customInstructions) {
1368
1613
  await this.abort();
1369
1614
  this._compactionAbortController = new AbortController();
1370
1615
  this._emit({ type: "compaction_start", reason: "manual" });
1616
+ let fromExtension = false;
1371
1617
  try {
1372
1618
  if (!this.model) {
1373
1619
  throw new Error(formatNoModelSelectedMessage());
@@ -1385,7 +1631,6 @@ export class AgentSession {
1385
1631
  throw new Error("Nothing to compact (session too small)");
1386
1632
  }
1387
1633
  let extensionCompaction;
1388
- let fromExtension = false;
1389
1634
  if (this._extensionRunner.hasHandlers("session_before_compact")) {
1390
1635
  const result = (await this._extensionRunner.emit({
1391
1636
  type: "session_before_compact",
@@ -1418,8 +1663,8 @@ export class AgentSession {
1418
1663
  details = extensionCompaction.details;
1419
1664
  }
1420
1665
  else {
1421
- // Generate compaction result
1422
- const result = await compact(preparation, requestModel, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason: "manual" }));
1666
+ // Shared default summary generator, also used by automatic compaction.
1667
+ const result = await this._runDefaultCompaction(preparation, requestModel, apiKey, headers, customInstructions, this._compactionAbortController.signal, env, "manual");
1423
1668
  summary = result.summary;
1424
1669
  firstKeptEntryId = result.firstKeptEntryId;
1425
1670
  tokensBefore = result.tokensBefore;
@@ -1467,6 +1712,7 @@ export class AgentSession {
1467
1712
  catch (error) {
1468
1713
  const message = error instanceof Error ? error.message : String(error);
1469
1714
  const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
1715
+ const errorMessage = aborted ? undefined : `Compaction failed: ${message}`;
1470
1716
  this._compactionAbortController = undefined;
1471
1717
  this._emit({
1472
1718
  type: "compaction_end",
@@ -1474,7 +1720,14 @@ export class AgentSession {
1474
1720
  result: undefined,
1475
1721
  aborted,
1476
1722
  willRetry: false,
1477
- errorMessage: aborted ? undefined : `Compaction failed: ${message}`,
1723
+ errorMessage,
1724
+ });
1725
+ await this._emitSessionCompactFailed({
1726
+ reason: "manual",
1727
+ errorMessage,
1728
+ aborted,
1729
+ willRetry: false,
1730
+ fromExtension,
1478
1731
  });
1479
1732
  throw error;
1480
1733
  }
@@ -1496,16 +1749,25 @@ export class AgentSession {
1496
1749
  this._branchSummaryAbortController?.abort();
1497
1750
  }
1498
1751
  /**
1499
- * Check if compaction is needed and run it.
1500
- * Called after agent_end and before prompt submission.
1752
+ * Dispatch automatic compaction after `agent_end` or before prompt submission.
1753
+ * Manual compaction does not call this method; it enters through `compact()`.
1501
1754
  *
1502
- * Two cases:
1503
- * 1. Recoverable failure: LLM returned context overflow or stopped below its desired output limit;
1504
- * remove the assistant message, compact, and auto-retry once
1505
- * 2. Threshold: Context over threshold, compact, NO auto-retry (user continues manually)
1755
+ * Automatic cases:
1756
+ * 1. Overflow with retry: a context-overflow error or recoverable length stop;
1757
+ * remove the failed assistant message, compact, and retry the turn once.
1758
+ * 2. Overflow without retry: a successful response exceeded the configured
1759
+ * context window; compact but preserve the completed response.
1760
+ * 3. Threshold without retry: valid or estimated context usage crossed the
1761
+ * configured threshold; compact without retrying the completed response.
1762
+ *
1763
+ * Each case calls `_runAutoCompaction()`. After preparation and the
1764
+ * `session_before_compact` hook, that method calls the lower-level `compact()`
1765
+ * function imported from `./compaction/index.ts`, unless the hook cancels or
1766
+ * supplies a custom result.
1506
1767
  *
1507
1768
  * @param assistantMessage The assistant message to check
1508
1769
  * @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
1770
+ * @returns Whether the post-run loop should call `agent.continue()` for overflow recovery or queued messages
1509
1771
  */
1510
1772
  async _checkCompaction(assistantMessage, skipAbortedCheck = true) {
1511
1773
  const settings = this.settingsManager.getCompactionSettings();
@@ -1528,38 +1790,49 @@ export class AgentSession {
1528
1790
  if (assistantIsFromBeforeCompaction) {
1529
1791
  return false;
1530
1792
  }
1531
- // Case 1: Recoverable failure. Explicit/silent context overflow still uses context metadata.
1793
+ // Automatic cases 1 and 2: context overflow.
1532
1794
  // A length stop is recoverable when output ended below the model's original desired limit,
1533
1795
  // independent of the configured context size or any context-clamped provider request limit.
1534
- // A successful response over the configured window should compact but must not retry: the
1535
- // assistant answer already completed and agent.continue() cannot continue from an assistant.
1796
+ const contextOverflow = sameModel && isContextOverflow(assistantMessage, contextWindow);
1536
1797
  const recoverableLength = sameModel && isRecoverableLength(assistantMessage, this.model?.maxTokens ?? 0);
1537
- if (sameModel && (isContextOverflow(assistantMessage, contextWindow) || recoverableLength)) {
1798
+ if (contextOverflow || recoverableLength) {
1538
1799
  const willRetry = assistantMessage.stopReason !== "stop";
1800
+ // Case 2: the response completed successfully. Compact, but do not retry because
1801
+ // agent.continue() cannot continue from a completed assistant response.
1539
1802
  if (!willRetry) {
1540
1803
  return await this._runAutoCompaction("overflow", false);
1541
1804
  }
1542
1805
  if (this._overflowRecoveryAttempted) {
1806
+ const errorMessage = contextOverflow
1807
+ ? "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model."
1808
+ : "Truncated response recovery failed after one compact-and-retry attempt.";
1543
1809
  this._emit({
1544
1810
  type: "compaction_end",
1545
1811
  reason: "overflow",
1546
1812
  result: undefined,
1547
1813
  aborted: false,
1548
1814
  willRetry: false,
1549
- errorMessage: "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.",
1815
+ errorMessage,
1816
+ });
1817
+ await this._emitSessionCompactFailed({
1818
+ reason: "overflow",
1819
+ errorMessage,
1820
+ aborted: false,
1821
+ willRetry: false,
1822
+ fromExtension: false,
1550
1823
  });
1551
1824
  return false;
1552
1825
  }
1826
+ // Case 1: remove the failed or truncated message from agent state, compact, and
1827
+ // retry once. The message remains in session history but is excluded from retry context.
1553
1828
  this._overflowRecoveryAttempted = true;
1554
- // Remove the failed or truncated message from agent state. It remains in session history,
1555
- // but must not be included in the compact-and-retry context.
1556
1829
  const messages = this.agent.state.messages;
1557
1830
  if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
1558
1831
  this.agent.state.messages = messages.slice(0, -1);
1559
1832
  }
1560
1833
  return await this._runAutoCompaction("overflow", willRetry);
1561
1834
  }
1562
- // Case 2: Threshold - context is getting large
1835
+ // Case 3: threshold compaction without retry.
1563
1836
  // For error messages or all-zero usage messages, estimate from the last valid response.
1564
1837
  // This ensures sessions that hit persistent API errors (e.g. 529) or malformed zero-usage
1565
1838
  // responses can still compact and do not reset context accounting.
@@ -1568,16 +1841,18 @@ export class AgentSession {
1568
1841
  if (assistantMessage.stopReason === "error" || directContextTokens === 0) {
1569
1842
  const messages = this.agent.state.messages;
1570
1843
  const estimate = estimateContextTokens(messages);
1571
- if (estimate.lastUsageIndex === null)
1572
- return false; // No usage data at all
1573
- // Verify the usage source is post-compaction. Kept pre-compaction messages
1574
- // have stale usage reflecting the old (larger) context and would falsely
1575
- // trigger compaction right after one just finished.
1576
- const usageMsg = messages[estimate.lastUsageIndex];
1577
- if (compactionEntry &&
1578
- usageMsg.role === "assistant" &&
1579
- usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
1580
- return false;
1844
+ // Without provider usage, estimate.tokens is the pure message-size estimate.
1845
+ // Only usage-backed estimates need the stale pre-compaction check.
1846
+ if (estimate.lastUsageIndex !== null) {
1847
+ // Verify the usage source is post-compaction. Kept pre-compaction messages
1848
+ // have stale usage reflecting the old (larger) context and would falsely
1849
+ // trigger compaction right after one just finished.
1850
+ const usageMsg = messages[estimate.lastUsageIndex];
1851
+ if (compactionEntry &&
1852
+ usageMsg.role === "assistant" &&
1853
+ usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
1854
+ return false;
1855
+ }
1581
1856
  }
1582
1857
  contextTokens = estimate.tokens;
1583
1858
  }
@@ -1590,11 +1865,19 @@ export class AgentSession {
1590
1865
  return false;
1591
1866
  }
1592
1867
  /**
1593
- * Internal: Run auto-compaction with events.
1868
+ * Execute threshold or overflow compaction. Manual compaction uses
1869
+ * `AgentSession.compact()` instead. Both paths call the lower-level `compact()`
1870
+ * function imported from `./compaction/index.ts` after preparation and extension
1871
+ * interception.
1872
+ *
1873
+ * @param reason Automatic trigger selected by `_checkCompaction()`
1874
+ * @param willRetry Whether to continue the interrupted turn after overflow compaction
1875
+ * @returns Whether the post-run loop should call `agent.continue()`
1594
1876
  */
1595
1877
  async _runAutoCompaction(reason, willRetry) {
1596
1878
  const settings = this.settingsManager.getCompactionSettings();
1597
1879
  let started = false;
1880
+ let fromExtension = false;
1598
1881
  try {
1599
1882
  if (!this.model) {
1600
1883
  return false;
@@ -1609,7 +1892,6 @@ export class AgentSession {
1609
1892
  this._autoCompactionAbortController = new AbortController();
1610
1893
  started = true;
1611
1894
  let extensionCompaction;
1612
- let fromExtension = false;
1613
1895
  if (this._extensionRunner.hasHandlers("session_before_compact")) {
1614
1896
  const extensionResult = (await this._extensionRunner.emit({
1615
1897
  type: "session_before_compact",
@@ -1628,6 +1910,12 @@ export class AgentSession {
1628
1910
  aborted: true,
1629
1911
  willRetry: false,
1630
1912
  });
1913
+ await this._emitSessionCompactFailed({
1914
+ reason,
1915
+ aborted: true,
1916
+ willRetry: false,
1917
+ fromExtension: false,
1918
+ });
1631
1919
  return false;
1632
1920
  }
1633
1921
  if (extensionResult?.compaction) {
@@ -1649,8 +1937,8 @@ export class AgentSession {
1649
1937
  details = extensionCompaction.details;
1650
1938
  }
1651
1939
  else {
1652
- // Generate compaction result
1653
- const compactResult = await compact(preparation, requestModel, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }));
1940
+ // Shared default summary generator, also used by manual compaction.
1941
+ const compactResult = await this._runDefaultCompaction(preparation, requestModel, apiKey, headers, undefined, this._autoCompactionAbortController.signal, env, reason);
1654
1942
  summary = compactResult.summary;
1655
1943
  firstKeptEntryId = compactResult.firstKeptEntryId;
1656
1944
  tokensBefore = compactResult.tokensBefore;
@@ -1665,6 +1953,12 @@ export class AgentSession {
1665
1953
  aborted: true,
1666
1954
  willRetry: false,
1667
1955
  });
1956
+ await this._emitSessionCompactFailed({
1957
+ reason,
1958
+ aborted: true,
1959
+ willRetry: false,
1960
+ fromExtension,
1961
+ });
1668
1962
  return false;
1669
1963
  }
1670
1964
  this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
@@ -1711,15 +2005,23 @@ export class AgentSession {
1711
2005
  catch (error) {
1712
2006
  const errorMessage = error instanceof Error ? error.message : "compaction failed";
1713
2007
  if (started) {
2008
+ const formattedErrorMessage = reason === "overflow"
2009
+ ? `Context overflow recovery failed: ${errorMessage}`
2010
+ : `Auto-compaction failed: ${errorMessage}`;
1714
2011
  this._emit({
1715
2012
  type: "compaction_end",
1716
2013
  reason,
1717
2014
  result: undefined,
1718
2015
  aborted: false,
1719
2016
  willRetry: false,
1720
- errorMessage: reason === "overflow"
1721
- ? `Context overflow recovery failed: ${errorMessage}`
1722
- : `Auto-compaction failed: ${errorMessage}`,
2017
+ errorMessage: formattedErrorMessage,
2018
+ });
2019
+ await this._emitSessionCompactFailed({
2020
+ reason,
2021
+ errorMessage: formattedErrorMessage,
2022
+ aborted: false,
2023
+ willRetry: false,
2024
+ fromExtension,
1723
2025
  });
1724
2026
  }
1725
2027
  return false;
@@ -1835,7 +2137,7 @@ export class AgentSession {
1835
2137
  sourceInfo: template.sourceInfo,
1836
2138
  }));
1837
2139
  const skills = this._resourceLoader.getSkills().skills.map((skill) => ({
1838
- name: `skill:${skill.name}`,
2140
+ name: `skill:${slugifySkillCommandName(skill.name)}`,
1839
2141
  description: skill.description,
1840
2142
  source: "skill",
1841
2143
  sourceInfo: skill.sourceInfo,
@@ -2012,6 +2314,14 @@ export class AgentSession {
2012
2314
  }
2013
2315
  }
2014
2316
  }
2317
+ const hasDeferredActiveTool = nextActiveToolNames.some((name) => {
2318
+ const contract = definitionRegistry.get(name)?.definition
2319
+ ?.contract;
2320
+ return contract?.context.deferSchema === true;
2321
+ });
2322
+ if (hasDeferredActiveTool && this._toolRegistry.has("tool_schema")) {
2323
+ nextActiveToolNames.push("tool_schema");
2324
+ }
2015
2325
  this.setActiveToolsByName([...new Set(nextActiveToolNames)]);
2016
2326
  }
2017
2327
  _buildRuntime(options) {
@@ -2026,7 +2336,34 @@ export class AgentSession {
2026
2336
  : createAllToolDefinitions(this._cwd, {
2027
2337
  read: { autoResizeImages },
2028
2338
  bash: { commandPrefix: shellCommandPrefix, shellPath },
2339
+ edit: { diagnosticsOperations: this._diagnosticsOperations },
2340
+ write: { diagnosticsOperations: this._diagnosticsOperations },
2341
+ ...(this._lspOperations ? { lsp: { operations: this._lspOperations } } : {}),
2342
+ ...(this._mcpRuntime ? { mcp: this._mcpRuntime } : {}),
2343
+ ...(this._webSearchOperations ? { web_search: { operations: this._webSearchOperations } } : {}),
2029
2344
  });
2345
+ baseToolDefinitions.tool_schema = createToolSchemaToolDefinition({
2346
+ getTool: (name) => {
2347
+ if (!this.getActiveToolNames().includes(name))
2348
+ return undefined;
2349
+ const definition = this._toolDefinitions.get(name)?.definition;
2350
+ return definition ? { name: definition.name, parameters: definition.parameters } : undefined;
2351
+ },
2352
+ markLoaded: (name) => {
2353
+ this._loadedDeferredSchemas.add(name);
2354
+ },
2355
+ });
2356
+ baseToolDefinitions.todo_write = createTodoWriteToolDefinition({
2357
+ write: (todos) => {
2358
+ this.sessionManager.appendCustomEntry(TODO_CUSTOM_ENTRY_TYPE, todos);
2359
+ },
2360
+ });
2361
+ // Reads the resource loader live on every call (not a snapshot taken here), so
2362
+ // a project-trust change or a settings reload that alters the loaded skill set
2363
+ // is reflected on the next search without rebuilding the tool registry.
2364
+ baseToolDefinitions.skill_search = createSkillSearchToolDefinition({
2365
+ getSkills: () => this.resourceLoader.getSkills().skills,
2366
+ });
2030
2367
  this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
2031
2368
  const extensionsResult = this._resourceLoader.getExtensions();
2032
2369
  if (options.flagValues) {
@@ -2042,7 +2379,9 @@ export class AgentSession {
2042
2379
  this._applyExtensionBindings(this._extensionRunner);
2043
2380
  const defaultActiveToolNames = this._baseToolsOverride
2044
2381
  ? Object.keys(this._baseToolsOverride)
2045
- : ["read", "bash", "edit", "write"];
2382
+ : this._lspOperations
2383
+ ? ["read", "bash", "edit", "write", "lsp"]
2384
+ : ["read", "bash", "edit", "write"];
2046
2385
  const baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;
2047
2386
  this._refreshToolRegistry({
2048
2387
  activeToolNames: baseActiveToolNames,
@@ -2583,11 +2922,11 @@ export class AgentSession {
2583
2922
  /**
2584
2923
  * Export session to HTML.
2585
2924
  * @param outputPath Optional output path (defaults to session directory)
2925
+ * @param options Optional export presentation settings
2586
2926
  * @returns Path to exported file
2587
2927
  */
2588
- async exportToHtml(outputPath) {
2589
- const configuredThemeName = this.settingsManager.getTheme();
2590
- const themeName = configuredThemeName && getThemeByName(configuredThemeName) ? configuredThemeName : undefined;
2928
+ async exportToHtml(outputPath, options = {}) {
2929
+ const themeName = [options.themeName, this.settingsManager.getTheme()].find((candidate) => candidate !== undefined && getThemeByName(candidate) !== undefined);
2591
2930
  // Create tool renderer if we have an extension runner (for custom tool HTML rendering)
2592
2931
  const toolRenderer = createToolHtmlRenderer({
2593
2932
  getToolDefinition: (name) => this.getToolDefinition(name),
@@ -2607,29 +2946,7 @@ export class AgentSession {
2607
2946
  * @returns The resolved output file path.
2608
2947
  */
2609
2948
  exportToJsonl(outputPath) {
2610
- const filePath = resolvePath(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`, process.cwd());
2611
- const dir = dirname(filePath);
2612
- if (!existsSync(dir)) {
2613
- mkdirSync(dir, { recursive: true });
2614
- }
2615
- const header = {
2616
- type: "session",
2617
- version: CURRENT_SESSION_VERSION,
2618
- id: this.sessionManager.getSessionId(),
2619
- timestamp: new Date().toISOString(),
2620
- cwd: this.sessionManager.getCwd(),
2621
- };
2622
- const branchEntries = this.sessionManager.getBranch();
2623
- const lines = [JSON.stringify(header)];
2624
- // Re-chain parentIds to form a linear sequence
2625
- let prevId = null;
2626
- for (const entry of branchEntries) {
2627
- const linear = { ...entry, parentId: prevId };
2628
- lines.push(JSON.stringify(linear));
2629
- prevId = entry.id;
2630
- }
2631
- writeFileSync(filePath, `${lines.join("\n")}\n`);
2632
- return filePath;
2949
+ return exportSessionToJsonl(this.sessionManager, outputPath);
2633
2950
  }
2634
2951
  // =========================================================================
2635
2952
  // Utilities