@gajae-code/coding-agent 0.1.1

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 (1775) hide show
  1. package/CHANGELOG.md +8662 -0
  2. package/README.md +37 -0
  3. package/dist/types/async/index.d.ts +2 -0
  4. package/dist/types/async/job-manager.d.ts +101 -0
  5. package/dist/types/async/support.d.ts +2 -0
  6. package/dist/types/autoresearch/dashboard.d.ts +4 -0
  7. package/dist/types/autoresearch/git.d.ts +36 -0
  8. package/dist/types/autoresearch/helpers.d.ts +24 -0
  9. package/dist/types/autoresearch/index.d.ts +2 -0
  10. package/dist/types/autoresearch/state.d.ts +17 -0
  11. package/dist/types/autoresearch/storage.d.ts +142 -0
  12. package/dist/types/autoresearch/tools/init-experiment.d.ts +31 -0
  13. package/dist/types/autoresearch/tools/log-experiment.d.ts +23 -0
  14. package/dist/types/autoresearch/tools/run-experiment.d.ts +8 -0
  15. package/dist/types/autoresearch/tools/update-notes.d.ts +12 -0
  16. package/dist/types/autoresearch/types.d.ts +154 -0
  17. package/dist/types/capability/context-file.d.ts +17 -0
  18. package/dist/types/capability/extension-module.d.ts +15 -0
  19. package/dist/types/capability/extension.d.ts +28 -0
  20. package/dist/types/capability/fs.d.ts +20 -0
  21. package/dist/types/capability/hook.d.ts +19 -0
  22. package/dist/types/capability/index.d.ts +80 -0
  23. package/dist/types/capability/instruction.d.ts +17 -0
  24. package/dist/types/capability/mcp.d.ts +45 -0
  25. package/dist/types/capability/prompt.d.ts +15 -0
  26. package/dist/types/capability/rule.d.ts +61 -0
  27. package/dist/types/capability/settings.d.ts +15 -0
  28. package/dist/types/capability/skill.d.ts +36 -0
  29. package/dist/types/capability/slash-command.d.ts +17 -0
  30. package/dist/types/capability/ssh.d.ts +23 -0
  31. package/dist/types/capability/system-prompt.d.ts +15 -0
  32. package/dist/types/capability/tool.d.ts +19 -0
  33. package/dist/types/capability/types.d.ts +154 -0
  34. package/dist/types/cli/agents-cli.d.ts +12 -0
  35. package/dist/types/cli/args.d.ts +53 -0
  36. package/dist/types/cli/auth-broker-cli.d.ts +25 -0
  37. package/dist/types/cli/auth-gateway-cli.d.ts +18 -0
  38. package/dist/types/cli/classify-install-target.d.ts +18 -0
  39. package/dist/types/cli/commands/init-xdg.d.ts +1 -0
  40. package/dist/types/cli/config-cli.d.ts +22 -0
  41. package/dist/types/cli/file-processor.d.ts +11 -0
  42. package/dist/types/cli/grep-cli.d.ts +17 -0
  43. package/dist/types/cli/initial-message.d.ts +17 -0
  44. package/dist/types/cli/list-models.d.ts +30 -0
  45. package/dist/types/cli/plugin-cli.d.ts +32 -0
  46. package/dist/types/cli/read-cli.d.ts +4 -0
  47. package/dist/types/cli/session-picker.d.ts +3 -0
  48. package/dist/types/cli/setup-cli.d.ts +31 -0
  49. package/dist/types/cli/shell-cli.d.ts +8 -0
  50. package/dist/types/cli/ssh-cli.d.ts +21 -0
  51. package/dist/types/cli/stats-cli.d.ts +17 -0
  52. package/dist/types/cli/update-cli.d.ts +38 -0
  53. package/dist/types/cli/web-search-cli.d.ts +20 -0
  54. package/dist/types/cli/worktree-cli.d.ts +26 -0
  55. package/dist/types/cli.d.ts +3 -0
  56. package/dist/types/commands/acp.d.ts +12 -0
  57. package/dist/types/commands/agents.d.ts +34 -0
  58. package/dist/types/commands/auth-broker.d.ts +54 -0
  59. package/dist/types/commands/auth-gateway.d.ts +32 -0
  60. package/dist/types/commands/codex-native-hook.d.ts +6 -0
  61. package/dist/types/commands/commit.d.ts +27 -0
  62. package/dist/types/commands/config.d.ts +30 -0
  63. package/dist/types/commands/deep-interview.d.ts +7 -0
  64. package/dist/types/commands/gjc-runtime-bridge.d.ts +6 -0
  65. package/dist/types/commands/grep.d.ts +42 -0
  66. package/dist/types/commands/launch.d.ts +121 -0
  67. package/dist/types/commands/plugin.d.ts +52 -0
  68. package/dist/types/commands/question.d.ts +7 -0
  69. package/dist/types/commands/ralplan.d.ts +7 -0
  70. package/dist/types/commands/read.d.ts +15 -0
  71. package/dist/types/commands/setup.d.ts +48 -0
  72. package/dist/types/commands/shell.d.ts +21 -0
  73. package/dist/types/commands/ssh.d.ts +48 -0
  74. package/dist/types/commands/state.d.ts +7 -0
  75. package/dist/types/commands/stats.d.ts +25 -0
  76. package/dist/types/commands/team.d.ts +24 -0
  77. package/dist/types/commands/ultragoal.d.ts +7 -0
  78. package/dist/types/commands/update.d.ts +20 -0
  79. package/dist/types/commands/web-search.d.ts +33 -0
  80. package/dist/types/commands/worktree.d.ts +34 -0
  81. package/dist/types/commit/agentic/agent.d.ts +31 -0
  82. package/dist/types/commit/agentic/fallback.d.ts +5 -0
  83. package/dist/types/commit/agentic/index.d.ts +2 -0
  84. package/dist/types/commit/agentic/state.d.ts +58 -0
  85. package/dist/types/commit/agentic/tools/analyze-file.d.ts +19 -0
  86. package/dist/types/commit/agentic/tools/git-file-diff.d.ts +10 -0
  87. package/dist/types/commit/agentic/tools/git-hunk.d.ts +9 -0
  88. package/dist/types/commit/agentic/tools/git-overview.d.ts +9 -0
  89. package/dist/types/commit/agentic/tools/index.d.ts +16 -0
  90. package/dist/types/commit/agentic/tools/propose-changelog.d.ts +28 -0
  91. package/dist/types/commit/agentic/tools/propose-commit.d.ts +36 -0
  92. package/dist/types/commit/agentic/tools/recent-commits.d.ts +7 -0
  93. package/dist/types/commit/agentic/tools/schemas.d.ts +27 -0
  94. package/dist/types/commit/agentic/tools/split-commit.d.ts +53 -0
  95. package/dist/types/commit/agentic/topo-sort.d.ts +4 -0
  96. package/dist/types/commit/agentic/trivial.d.ts +7 -0
  97. package/dist/types/commit/agentic/validation.d.ts +20 -0
  98. package/dist/types/commit/analysis/conventional.d.ts +22 -0
  99. package/dist/types/commit/analysis/index.d.ts +4 -0
  100. package/dist/types/commit/analysis/scope.d.ts +6 -0
  101. package/dist/types/commit/analysis/summary.d.ts +19 -0
  102. package/dist/types/commit/analysis/validation.d.ts +8 -0
  103. package/dist/types/commit/changelog/detect.d.ts +2 -0
  104. package/dist/types/commit/changelog/generate.d.ts +30 -0
  105. package/dist/types/commit/changelog/index.d.ts +30 -0
  106. package/dist/types/commit/changelog/parse.d.ts +2 -0
  107. package/dist/types/commit/cli.d.ts +3 -0
  108. package/dist/types/commit/git/diff.d.ts +5 -0
  109. package/dist/types/commit/index.d.ts +4 -0
  110. package/dist/types/commit/map-reduce/index.d.ts +28 -0
  111. package/dist/types/commit/map-reduce/map-phase.d.ts +17 -0
  112. package/dist/types/commit/map-reduce/reduce-phase.d.ts +13 -0
  113. package/dist/types/commit/map-reduce/utils.d.ts +2 -0
  114. package/dist/types/commit/message.d.ts +2 -0
  115. package/dist/types/commit/model-selection.d.ts +15 -0
  116. package/dist/types/commit/pipeline.d.ts +5 -0
  117. package/dist/types/commit/shared-llm.d.ts +54 -0
  118. package/dist/types/commit/types.d.ts +78 -0
  119. package/dist/types/commit/utils/exclusions.d.ts +4 -0
  120. package/dist/types/commit/utils.d.ts +20 -0
  121. package/dist/types/config/config-file.d.ts +58 -0
  122. package/dist/types/config/file-lock.d.ts +6 -0
  123. package/dist/types/config/keybindings.d.ts +334 -0
  124. package/dist/types/config/model-equivalence.d.ts +24 -0
  125. package/dist/types/config/model-registry.d.ts +390 -0
  126. package/dist/types/config/model-resolver.d.ts +230 -0
  127. package/dist/types/config/models-config-schema.d.ts +504 -0
  128. package/dist/types/config/prompt-templates.d.ts +32 -0
  129. package/dist/types/config/resolve-config-value.d.ts +17 -0
  130. package/dist/types/config/settings-schema.d.ts +3337 -0
  131. package/dist/types/config/settings.d.ts +132 -0
  132. package/dist/types/config/skill-settings-defaults.d.ts +14 -0
  133. package/dist/types/config.d.ts +66 -0
  134. package/dist/types/cursor.d.ts +24 -0
  135. package/dist/types/dap/client.d.ts +38 -0
  136. package/dist/types/dap/config.d.ts +6 -0
  137. package/dist/types/dap/index.d.ts +4 -0
  138. package/dist/types/dap/session.d.ts +108 -0
  139. package/dist/types/dap/types.d.ts +524 -0
  140. package/dist/types/debug/index.d.ts +15 -0
  141. package/dist/types/debug/log-formatting.d.ts +4 -0
  142. package/dist/types/debug/log-viewer.d.ts +68 -0
  143. package/dist/types/debug/profiler.d.ts +24 -0
  144. package/dist/types/debug/raw-sse-buffer.d.ts +44 -0
  145. package/dist/types/debug/raw-sse.d.ts +16 -0
  146. package/dist/types/debug/report-bundle.d.ts +55 -0
  147. package/dist/types/debug/system-info.d.ts +26 -0
  148. package/dist/types/defaults/gjc-defaults.d.ts +44 -0
  149. package/dist/types/discovery/agents-md.d.ts +1 -0
  150. package/dist/types/discovery/agents.d.ts +12 -0
  151. package/dist/types/discovery/builtin.d.ts +1 -0
  152. package/dist/types/discovery/claude-plugins.d.ts +1 -0
  153. package/dist/types/discovery/claude.d.ts +1 -0
  154. package/dist/types/discovery/cline.d.ts +1 -0
  155. package/dist/types/discovery/codex.d.ts +1 -0
  156. package/dist/types/discovery/cursor.d.ts +16 -0
  157. package/dist/types/discovery/gemini.d.ts +1 -0
  158. package/dist/types/discovery/github.d.ts +1 -0
  159. package/dist/types/discovery/helpers.d.ts +268 -0
  160. package/dist/types/discovery/index.d.ts +48 -0
  161. package/dist/types/discovery/mcp-json.d.ts +1 -0
  162. package/dist/types/discovery/opencode.d.ts +1 -0
  163. package/dist/types/discovery/plugin-dir-roots.d.ts +15 -0
  164. package/dist/types/discovery/ssh.d.ts +1 -0
  165. package/dist/types/discovery/substitute-plugin-root.d.ts +5 -0
  166. package/dist/types/discovery/vscode.d.ts +1 -0
  167. package/dist/types/discovery/windsurf.d.ts +13 -0
  168. package/dist/types/edit/apply-patch/index.d.ts +35 -0
  169. package/dist/types/edit/apply-patch/parser.d.ts +34 -0
  170. package/dist/types/edit/diff.d.ts +59 -0
  171. package/dist/types/edit/file-read-cache.d.ts +25 -0
  172. package/dist/types/edit/index.d.ts +58 -0
  173. package/dist/types/edit/modes/apply-patch.d.ts +24 -0
  174. package/dist/types/edit/modes/patch.d.ts +99 -0
  175. package/dist/types/edit/modes/replace.d.ts +142 -0
  176. package/dist/types/edit/normalize.d.ts +43 -0
  177. package/dist/types/edit/notebook.d.ts +23 -0
  178. package/dist/types/edit/read-file.d.ts +2 -0
  179. package/dist/types/edit/renderer.d.ts +110 -0
  180. package/dist/types/edit/streaming.d.ts +66 -0
  181. package/dist/types/eval/backend.d.ts +40 -0
  182. package/dist/types/eval/index.d.ts +4 -0
  183. package/dist/types/eval/js/context-manager.d.ts +24 -0
  184. package/dist/types/eval/js/executor.d.ts +28 -0
  185. package/dist/types/eval/js/index.d.ts +10 -0
  186. package/dist/types/eval/js/shared/helpers.d.ts +38 -0
  187. package/dist/types/eval/js/shared/indirect-eval.d.ts +14 -0
  188. package/dist/types/eval/js/shared/prelude.d.ts +1 -0
  189. package/dist/types/eval/js/shared/rewrite-imports.d.ts +6 -0
  190. package/dist/types/eval/js/shared/runtime.d.ts +47 -0
  191. package/dist/types/eval/js/shared/types.d.ts +24 -0
  192. package/dist/types/eval/js/tool-bridge.d.ts +18 -0
  193. package/dist/types/eval/js/worker-core.d.ts +5 -0
  194. package/dist/types/eval/js/worker-entry.d.ts +1 -0
  195. package/dist/types/eval/js/worker-protocol.d.ts +77 -0
  196. package/dist/types/eval/py/display.d.ts +25 -0
  197. package/dist/types/eval/py/executor.d.ts +83 -0
  198. package/dist/types/eval/py/index.d.ts +10 -0
  199. package/dist/types/eval/py/kernel.d.ts +61 -0
  200. package/dist/types/eval/py/prelude.d.ts +1 -0
  201. package/dist/types/eval/py/runtime.d.ts +21 -0
  202. package/dist/types/eval/py/tool-bridge.d.ts +20 -0
  203. package/dist/types/eval/types.d.ts +52 -0
  204. package/dist/types/exa/factory.d.ts +13 -0
  205. package/dist/types/exa/index.d.ts +20 -0
  206. package/dist/types/exa/mcp-client.d.ts +45 -0
  207. package/dist/types/exa/render.d.ts +19 -0
  208. package/dist/types/exa/researcher.d.ts +9 -0
  209. package/dist/types/exa/search.d.ts +9 -0
  210. package/dist/types/exa/types.d.ts +155 -0
  211. package/dist/types/exa/websets.d.ts +9 -0
  212. package/dist/types/exec/bash-executor.d.ts +41 -0
  213. package/dist/types/exec/exec.d.ts +25 -0
  214. package/dist/types/exec/idle-timeout-watchdog.d.ts +18 -0
  215. package/dist/types/exec/non-interactive-env.d.ts +1 -0
  216. package/dist/types/export/custom-share.d.ts +20 -0
  217. package/dist/types/export/html/index.d.ts +10 -0
  218. package/dist/types/export/html/template.generated.d.ts +1 -0
  219. package/dist/types/export/html/template.macro.d.ts +5 -0
  220. package/dist/types/export/ttsr.d.ts +44 -0
  221. package/dist/types/extensibility/custom-commands/bundled/ci-green/index.d.ts +9 -0
  222. package/dist/types/extensibility/custom-commands/bundled/review/index.d.ts +10 -0
  223. package/dist/types/extensibility/custom-commands/index.d.ts +2 -0
  224. package/dist/types/extensibility/custom-commands/loader.d.ts +29 -0
  225. package/dist/types/extensibility/custom-commands/types.d.ts +106 -0
  226. package/dist/types/extensibility/custom-tools/index.d.ts +6 -0
  227. package/dist/types/extensibility/custom-tools/loader.d.ts +69 -0
  228. package/dist/types/extensibility/custom-tools/types.d.ts +226 -0
  229. package/dist/types/extensibility/custom-tools/wrapper.d.ts +23 -0
  230. package/dist/types/extensibility/extensions/compact-handler.d.ts +26 -0
  231. package/dist/types/extensibility/extensions/get-commands-handler.d.ts +29 -0
  232. package/dist/types/extensibility/extensions/index.d.ts +8 -0
  233. package/dist/types/extensibility/extensions/loader.d.ts +43 -0
  234. package/dist/types/extensibility/extensions/runner.d.ts +134 -0
  235. package/dist/types/extensibility/extensions/types.d.ts +864 -0
  236. package/dist/types/extensibility/extensions/wrapper.d.ts +54 -0
  237. package/dist/types/extensibility/hooks/index.d.ts +5 -0
  238. package/dist/types/extensibility/hooks/loader.d.ts +89 -0
  239. package/dist/types/extensibility/hooks/runner.d.ts +126 -0
  240. package/dist/types/extensibility/hooks/tool-wrapper.d.ts +25 -0
  241. package/dist/types/extensibility/hooks/types.d.ts +431 -0
  242. package/dist/types/extensibility/plugins/doctor.d.ts +3 -0
  243. package/dist/types/extensibility/plugins/git-url.d.ts +34 -0
  244. package/dist/types/extensibility/plugins/index.d.ts +7 -0
  245. package/dist/types/extensibility/plugins/installer.d.ts +5 -0
  246. package/dist/types/extensibility/plugins/legacy-pi-compat.d.ts +2 -0
  247. package/dist/types/extensibility/plugins/loader.d.ts +31 -0
  248. package/dist/types/extensibility/plugins/manager.d.ts +65 -0
  249. package/dist/types/extensibility/plugins/marketplace/cache.d.ts +41 -0
  250. package/dist/types/extensibility/plugins/marketplace/fetcher.d.ts +48 -0
  251. package/dist/types/extensibility/plugins/marketplace/index.d.ts +6 -0
  252. package/dist/types/extensibility/plugins/marketplace/manager.d.ts +57 -0
  253. package/dist/types/extensibility/plugins/marketplace/registry.d.ts +34 -0
  254. package/dist/types/extensibility/plugins/marketplace/source-resolver.d.ts +28 -0
  255. package/dist/types/extensibility/plugins/marketplace/types.d.ts +130 -0
  256. package/dist/types/extensibility/plugins/parser.d.ts +52 -0
  257. package/dist/types/extensibility/plugins/types.d.ts +149 -0
  258. package/dist/types/extensibility/shared-events.d.ts +279 -0
  259. package/dist/types/extensibility/skills.d.ts +74 -0
  260. package/dist/types/extensibility/slash-commands.d.ts +48 -0
  261. package/dist/types/extensibility/tool-proxy.d.ts +4 -0
  262. package/dist/types/extensibility/typebox.d.ts +155 -0
  263. package/dist/types/extensibility/utils.d.ts +12 -0
  264. package/dist/types/gjc-runtime/goal-mode-request.d.ts +46 -0
  265. package/dist/types/gjc-runtime/launch-tmux.d.ts +45 -0
  266. package/dist/types/gjc-runtime/launch-worktree.d.ts +46 -0
  267. package/dist/types/gjc-runtime/team-runtime.d.ts +204 -0
  268. package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +85 -0
  269. package/dist/types/goals/index.d.ts +3 -0
  270. package/dist/types/goals/runtime.d.ts +68 -0
  271. package/dist/types/goals/state.d.ts +35 -0
  272. package/dist/types/goals/tools/goal-tool.d.ts +128 -0
  273. package/dist/types/hashline/anchors.d.ts +20 -0
  274. package/dist/types/hashline/apply.d.ts +14 -0
  275. package/dist/types/hashline/constants.d.ts +19 -0
  276. package/dist/types/hashline/diff-preview.d.ts +2 -0
  277. package/dist/types/hashline/diff.d.ts +17 -0
  278. package/dist/types/hashline/execute.d.ts +4 -0
  279. package/dist/types/hashline/hash.d.ts +123 -0
  280. package/dist/types/hashline/index.d.ts +13 -0
  281. package/dist/types/hashline/input.d.ts +11 -0
  282. package/dist/types/hashline/parser.d.ts +7 -0
  283. package/dist/types/hashline/prefixes.d.ts +7 -0
  284. package/dist/types/hashline/recovery.d.ts +27 -0
  285. package/dist/types/hashline/stream.d.ts +2 -0
  286. package/dist/types/hashline/types.d.ts +77 -0
  287. package/dist/types/hindsight/backend.d.ts +13 -0
  288. package/dist/types/hindsight/bank.d.ts +54 -0
  289. package/dist/types/hindsight/client.d.ts +224 -0
  290. package/dist/types/hindsight/config.d.ts +51 -0
  291. package/dist/types/hindsight/content.d.ts +70 -0
  292. package/dist/types/hindsight/index.d.ts +8 -0
  293. package/dist/types/hindsight/mental-models.d.ts +125 -0
  294. package/dist/types/hindsight/state.d.ts +99 -0
  295. package/dist/types/hindsight/transcript.d.ts +28 -0
  296. package/dist/types/hooks/codex-native-hooks-config.d.ts +29 -0
  297. package/dist/types/hooks/native-skill-hook.d.ts +16 -0
  298. package/dist/types/hooks/skill-keywords.d.ts +17 -0
  299. package/dist/types/hooks/skill-state.d.ts +80 -0
  300. package/dist/types/index.d.ts +33 -0
  301. package/dist/types/internal-urls/agent-protocol.d.ts +12 -0
  302. package/dist/types/internal-urls/artifact-protocol.d.ts +6 -0
  303. package/dist/types/internal-urls/docs-index.generated.d.ts +2 -0
  304. package/dist/types/internal-urls/gjc-protocol.d.ts +12 -0
  305. package/dist/types/internal-urls/index.d.ts +20 -0
  306. package/dist/types/internal-urls/issue-pr-protocol.d.ts +17 -0
  307. package/dist/types/internal-urls/json-query.d.ts +30 -0
  308. package/dist/types/internal-urls/local-protocol.d.ts +39 -0
  309. package/dist/types/internal-urls/mcp-protocol.d.ts +12 -0
  310. package/dist/types/internal-urls/memory-protocol.d.ts +23 -0
  311. package/dist/types/internal-urls/parse.d.ts +19 -0
  312. package/dist/types/internal-urls/registry-helpers.d.ts +10 -0
  313. package/dist/types/internal-urls/router.d.ts +14 -0
  314. package/dist/types/internal-urls/rule-protocol.d.ts +6 -0
  315. package/dist/types/internal-urls/skill-protocol.d.ts +13 -0
  316. package/dist/types/internal-urls/types.d.ts +105 -0
  317. package/dist/types/lsp/client.d.ts +65 -0
  318. package/dist/types/lsp/clients/biome-client.d.ts +16 -0
  319. package/dist/types/lsp/clients/index.d.ts +19 -0
  320. package/dist/types/lsp/clients/lsp-linter-client.d.ts +16 -0
  321. package/dist/types/lsp/clients/swiftlint-client.d.ts +20 -0
  322. package/dist/types/lsp/config.d.ts +65 -0
  323. package/dist/types/lsp/edits.d.ts +23 -0
  324. package/dist/types/lsp/index.d.ts +130 -0
  325. package/dist/types/lsp/lspmux.d.ts +58 -0
  326. package/dist/types/lsp/render.d.ts +32 -0
  327. package/dist/types/lsp/startup-events.d.ts +11 -0
  328. package/dist/types/lsp/types.d.ts +302 -0
  329. package/dist/types/lsp/utils.d.ts +108 -0
  330. package/dist/types/main.d.ts +50 -0
  331. package/dist/types/memories/index.d.ts +28 -0
  332. package/dist/types/memories/storage.d.ts +110 -0
  333. package/dist/types/memory-backend/index.d.ts +4 -0
  334. package/dist/types/memory-backend/local-backend.d.ts +9 -0
  335. package/dist/types/memory-backend/off-backend.d.ts +7 -0
  336. package/dist/types/memory-backend/resolve.d.ts +15 -0
  337. package/dist/types/memory-backend/types.d.ts +61 -0
  338. package/dist/types/modes/acp/acp-agent.d.ts +61 -0
  339. package/dist/types/modes/acp/acp-client-bridge.d.ts +9 -0
  340. package/dist/types/modes/acp/acp-event-mapper.d.ts +32 -0
  341. package/dist/types/modes/acp/acp-mode.d.ts +5 -0
  342. package/dist/types/modes/acp/index.d.ts +2 -0
  343. package/dist/types/modes/acp/terminal-auth.d.ts +6 -0
  344. package/dist/types/modes/components/agent-dashboard.d.ts +21 -0
  345. package/dist/types/modes/components/assistant-message.d.ts +16 -0
  346. package/dist/types/modes/components/bash-execution.d.ts +29 -0
  347. package/dist/types/modes/components/bordered-loader.d.ts +11 -0
  348. package/dist/types/modes/components/branch-summary-message.d.ts +13 -0
  349. package/dist/types/modes/components/btw-panel.d.ts +16 -0
  350. package/dist/types/modes/components/compaction-summary-message.d.ts +13 -0
  351. package/dist/types/modes/components/countdown-timer.d.ts +14 -0
  352. package/dist/types/modes/components/custom-editor.d.ts +47 -0
  353. package/dist/types/modes/components/custom-message.d.ts +15 -0
  354. package/dist/types/modes/components/diff.d.ts +11 -0
  355. package/dist/types/modes/components/dynamic-border.d.ts +14 -0
  356. package/dist/types/modes/components/eval-execution.d.ts +23 -0
  357. package/dist/types/modes/components/execution-shared.d.ts +46 -0
  358. package/dist/types/modes/components/extensions/extension-dashboard.d.ts +26 -0
  359. package/dist/types/modes/components/extensions/extension-list.d.ts +39 -0
  360. package/dist/types/modes/components/extensions/index.d.ts +8 -0
  361. package/dist/types/modes/components/extensions/inspector-panel.d.ts +8 -0
  362. package/dist/types/modes/components/extensions/state-manager.d.ts +50 -0
  363. package/dist/types/modes/components/extensions/types.d.ts +151 -0
  364. package/dist/types/modes/components/footer.d.ts +30 -0
  365. package/dist/types/modes/components/history-search.d.ts +7 -0
  366. package/dist/types/modes/components/hook-editor.d.ts +18 -0
  367. package/dist/types/modes/components/hook-input.d.ts +15 -0
  368. package/dist/types/modes/components/hook-message.d.ts +15 -0
  369. package/dist/types/modes/components/hook-selector.d.ts +23 -0
  370. package/dist/types/modes/components/index.d.ts +35 -0
  371. package/dist/types/modes/components/keybinding-hints.d.ts +40 -0
  372. package/dist/types/modes/components/login-dialog.d.ts +32 -0
  373. package/dist/types/modes/components/message-frame.d.ts +42 -0
  374. package/dist/types/modes/components/model-selector.d.ts +26 -0
  375. package/dist/types/modes/components/oauth-selector.d.ts +14 -0
  376. package/dist/types/modes/components/plugin-selector.d.ts +26 -0
  377. package/dist/types/modes/components/plugin-settings.d.ts +66 -0
  378. package/dist/types/modes/components/provider-onboarding-selector.d.ts +7 -0
  379. package/dist/types/modes/components/queue-mode-selector.d.ts +9 -0
  380. package/dist/types/modes/components/read-tool-group.d.ts +30 -0
  381. package/dist/types/modes/components/runtime-mcp-add-wizard.d.ts +25 -0
  382. package/dist/types/modes/components/session-observer-overlay.d.ts +11 -0
  383. package/dist/types/modes/components/session-selector.d.ts +30 -0
  384. package/dist/types/modes/components/settings-defs.d.ts +50 -0
  385. package/dist/types/modes/components/settings-selector.d.ts +54 -0
  386. package/dist/types/modes/components/show-images-selector.d.ts +9 -0
  387. package/dist/types/modes/components/skill-hud/render.d.ts +2 -0
  388. package/dist/types/modes/components/skill-message.d.ts +9 -0
  389. package/dist/types/modes/components/status-line/context-thresholds.d.ts +4 -0
  390. package/dist/types/modes/components/status-line/git-utils.d.ts +22 -0
  391. package/dist/types/modes/components/status-line/index.d.ts +4 -0
  392. package/dist/types/modes/components/status-line/presets.d.ts +3 -0
  393. package/dist/types/modes/components/status-line/segments.d.ts +5 -0
  394. package/dist/types/modes/components/status-line/separators.d.ts +3 -0
  395. package/dist/types/modes/components/status-line/token-rate.d.ts +10 -0
  396. package/dist/types/modes/components/status-line/types.d.ts +80 -0
  397. package/dist/types/modes/components/status-line.d.ts +80 -0
  398. package/dist/types/modes/components/theme-selector.d.ts +10 -0
  399. package/dist/types/modes/components/thinking-selector.d.ts +10 -0
  400. package/dist/types/modes/components/todo-reminder.d.ts +13 -0
  401. package/dist/types/modes/components/tool-execution.d.ts +53 -0
  402. package/dist/types/modes/components/tree-selector.d.ts +31 -0
  403. package/dist/types/modes/components/ttsr-notification.d.ts +13 -0
  404. package/dist/types/modes/components/user-message-selector.d.ts +28 -0
  405. package/dist/types/modes/components/user-message.d.ts +7 -0
  406. package/dist/types/modes/components/visual-truncate.d.ts +19 -0
  407. package/dist/types/modes/components/welcome.d.ts +34 -0
  408. package/dist/types/modes/controllers/btw-controller.d.ts +10 -0
  409. package/dist/types/modes/controllers/command-controller-shared.d.ts +47 -0
  410. package/dist/types/modes/controllers/command-controller.d.ts +36 -0
  411. package/dist/types/modes/controllers/event-controller.d.ts +12 -0
  412. package/dist/types/modes/controllers/extension-ui-controller.d.ts +80 -0
  413. package/dist/types/modes/controllers/input-controller.d.ts +35 -0
  414. package/dist/types/modes/controllers/runtime-mcp-command-controller.d.ts +10 -0
  415. package/dist/types/modes/controllers/selector-controller.d.ts +46 -0
  416. package/dist/types/modes/controllers/ssh-command-controller.d.ts +10 -0
  417. package/dist/types/modes/controllers/todo-command-controller.d.ts +7 -0
  418. package/dist/types/modes/emoji-autocomplete.d.ts +16 -0
  419. package/dist/types/modes/index.d.ts +9 -0
  420. package/dist/types/modes/interactive-mode.d.ts +271 -0
  421. package/dist/types/modes/loop-limit.d.ts +22 -0
  422. package/dist/types/modes/oauth-manual-input.d.ts +8 -0
  423. package/dist/types/modes/print-mode.d.ts +27 -0
  424. package/dist/types/modes/prompt-action-autocomplete.d.ts +46 -0
  425. package/dist/types/modes/rpc/host-tools.d.ts +16 -0
  426. package/dist/types/modes/rpc/host-uris.d.ts +38 -0
  427. package/dist/types/modes/rpc/rpc-client.d.ts +249 -0
  428. package/dist/types/modes/rpc/rpc-mode.d.ts +17 -0
  429. package/dist/types/modes/rpc/rpc-types.d.ts +586 -0
  430. package/dist/types/modes/runtime-init.d.ts +21 -0
  431. package/dist/types/modes/session-observer-registry.d.ts +26 -0
  432. package/dist/types/modes/shared.d.ts +15 -0
  433. package/dist/types/modes/theme/defaults/index.d.ts +9559 -0
  434. package/dist/types/modes/theme/mermaid-cache.d.ts +9 -0
  435. package/dist/types/modes/theme/shimmer.d.ts +38 -0
  436. package/dist/types/modes/theme/theme.d.ts +273 -0
  437. package/dist/types/modes/types.d.ts +278 -0
  438. package/dist/types/modes/utils/context-usage.d.ts +47 -0
  439. package/dist/types/modes/utils/hotkeys-markdown.d.ts +5 -0
  440. package/dist/types/modes/utils/keybinding-matchers.d.ts +10 -0
  441. package/dist/types/modes/utils/tools-markdown.d.ts +5 -0
  442. package/dist/types/modes/utils/ui-helpers.d.ts +53 -0
  443. package/dist/types/plan-mode/approved-plan.d.ts +49 -0
  444. package/dist/types/plan-mode/state.d.ts +6 -0
  445. package/dist/types/registry/agent-registry.d.ts +62 -0
  446. package/dist/types/runtime-mcp/client.d.ts +74 -0
  447. package/dist/types/runtime-mcp/config-writer.d.ts +53 -0
  448. package/dist/types/runtime-mcp/config.d.ts +75 -0
  449. package/dist/types/runtime-mcp/discoverable-tool-metadata.d.ts +7 -0
  450. package/dist/types/runtime-mcp/index.d.ts +18 -0
  451. package/dist/types/runtime-mcp/json-rpc.d.ts +22 -0
  452. package/dist/types/runtime-mcp/loader.d.ts +43 -0
  453. package/dist/types/runtime-mcp/manager.d.ts +193 -0
  454. package/dist/types/runtime-mcp/oauth-discovery.d.ts +40 -0
  455. package/dist/types/runtime-mcp/oauth-flow.d.ts +59 -0
  456. package/dist/types/runtime-mcp/render.d.ts +25 -0
  457. package/dist/types/runtime-mcp/smithery-auth.d.ts +16 -0
  458. package/dist/types/runtime-mcp/smithery-connect.d.ts +38 -0
  459. package/dist/types/runtime-mcp/smithery-registry.d.ts +51 -0
  460. package/dist/types/runtime-mcp/tool-bridge.d.ts +86 -0
  461. package/dist/types/runtime-mcp/tool-cache.d.ts +8 -0
  462. package/dist/types/runtime-mcp/transports/http.d.ts +36 -0
  463. package/dist/types/runtime-mcp/transports/index.d.ts +5 -0
  464. package/dist/types/runtime-mcp/transports/stdio.d.ts +32 -0
  465. package/dist/types/runtime-mcp/types.d.ts +333 -0
  466. package/dist/types/sdk.d.ts +216 -0
  467. package/dist/types/secrets/index.d.ts +9 -0
  468. package/dist/types/secrets/obfuscator.d.ts +23 -0
  469. package/dist/types/secrets/regex.d.ts +2 -0
  470. package/dist/types/session/agent-session.d.ts +930 -0
  471. package/dist/types/session/agent-storage.d.ts +100 -0
  472. package/dist/types/session/artifacts.d.ts +61 -0
  473. package/dist/types/session/auth-broker-config.d.ts +13 -0
  474. package/dist/types/session/auth-storage.d.ts +6 -0
  475. package/dist/types/session/blob-store.d.ts +63 -0
  476. package/dist/types/session/client-bridge.d.ts +88 -0
  477. package/dist/types/session/history-storage.d.ts +16 -0
  478. package/dist/types/session/messages.d.ts +162 -0
  479. package/dist/types/session/session-dump-format.d.ts +22 -0
  480. package/dist/types/session/session-manager.d.ts +549 -0
  481. package/dist/types/session/session-storage.d.ts +82 -0
  482. package/dist/types/session/streaming-output.d.ts +185 -0
  483. package/dist/types/session/tool-choice-queue.d.ts +78 -0
  484. package/dist/types/session/yield-queue.d.ts +24 -0
  485. package/dist/types/setup/model-onboarding-guidance.d.ts +8 -0
  486. package/dist/types/setup/provider-onboarding.d.ts +28 -0
  487. package/dist/types/skill-state/active-state.d.ts +50 -0
  488. package/dist/types/slash-commands/acp-builtins.d.ts +18 -0
  489. package/dist/types/slash-commands/builtin-registry.d.ts +23 -0
  490. package/dist/types/slash-commands/helpers/context-report.d.ts +7 -0
  491. package/dist/types/slash-commands/helpers/format.d.ts +10 -0
  492. package/dist/types/slash-commands/helpers/mcp.d.ts +3 -0
  493. package/dist/types/slash-commands/helpers/parse.d.ts +33 -0
  494. package/dist/types/slash-commands/helpers/ssh.d.ts +3 -0
  495. package/dist/types/slash-commands/helpers/todo.d.ts +3 -0
  496. package/dist/types/slash-commands/helpers/usage-report.d.ts +7 -0
  497. package/dist/types/slash-commands/types.d.ts +118 -0
  498. package/dist/types/ssh/config-writer.d.ts +49 -0
  499. package/dist/types/ssh/connection-manager.d.ts +33 -0
  500. package/dist/types/ssh/ssh-executor.d.ts +37 -0
  501. package/dist/types/ssh/sshfs-mount.d.ts +6 -0
  502. package/dist/types/ssh/utils.d.ts +2 -0
  503. package/dist/types/stt/downloader.d.ts +9 -0
  504. package/dist/types/stt/index.d.ts +3 -0
  505. package/dist/types/stt/recorder.d.ts +13 -0
  506. package/dist/types/stt/setup.d.ts +18 -0
  507. package/dist/types/stt/stt-controller.d.ts +16 -0
  508. package/dist/types/stt/transcriber.d.ts +16 -0
  509. package/dist/types/system-prompt.d.ts +93 -0
  510. package/dist/types/task/agents.d.ts +28 -0
  511. package/dist/types/task/commands.d.ts +35 -0
  512. package/dist/types/task/discovery.d.ts +19 -0
  513. package/dist/types/task/executor.d.ts +106 -0
  514. package/dist/types/task/gjc-command.d.ts +7 -0
  515. package/dist/types/task/index.d.ts +38 -0
  516. package/dist/types/task/name-generator.d.ts +16 -0
  517. package/dist/types/task/output-manager.d.ts +36 -0
  518. package/dist/types/task/parallel.d.ts +34 -0
  519. package/dist/types/task/render.d.ts +22 -0
  520. package/dist/types/task/simple-mode.d.ts +8 -0
  521. package/dist/types/task/subprocess-tool-registry.d.ts +72 -0
  522. package/dist/types/task/types.d.ts +295 -0
  523. package/dist/types/task/worktree.d.ts +94 -0
  524. package/dist/types/thinking.d.ts +30 -0
  525. package/dist/types/tool-discovery/tool-index.d.ts +112 -0
  526. package/dist/types/tools/archive-reader.d.ts +40 -0
  527. package/dist/types/tools/ask.d.ts +109 -0
  528. package/dist/types/tools/ast-edit.d.ts +77 -0
  529. package/dist/types/tools/ast-grep.d.ts +69 -0
  530. package/dist/types/tools/auto-generated-guard.d.ts +17 -0
  531. package/dist/types/tools/bash-command-fixup.d.ts +11 -0
  532. package/dist/types/tools/bash-interactive.d.ts +16 -0
  533. package/dist/types/tools/bash-interceptor.d.ts +24 -0
  534. package/dist/types/tools/bash-pty-selection.d.ts +7 -0
  535. package/dist/types/tools/bash-skill-urls.d.ts +31 -0
  536. package/dist/types/tools/bash.d.ts +130 -0
  537. package/dist/types/tools/browser/attach.d.ts +34 -0
  538. package/dist/types/tools/browser/launch.d.ts +62 -0
  539. package/dist/types/tools/browser/readable.d.ts +17 -0
  540. package/dist/types/tools/browser/registry.d.ts +42 -0
  541. package/dist/types/tools/browser/render.d.ts +50 -0
  542. package/dist/types/tools/browser/tab-protocol.d.ts +144 -0
  543. package/dist/types/tools/browser/tab-supervisor.d.ts +63 -0
  544. package/dist/types/tools/browser/tab-worker-entry.d.ts +1 -0
  545. package/dist/types/tools/browser/tab-worker.d.ts +19 -0
  546. package/dist/types/tools/browser.d.ts +114 -0
  547. package/dist/types/tools/calculator.d.ts +76 -0
  548. package/dist/types/tools/checkpoint.d.ts +63 -0
  549. package/dist/types/tools/conflict-detect.d.ts +205 -0
  550. package/dist/types/tools/context.d.ts +19 -0
  551. package/dist/types/tools/debug.d.ts +209 -0
  552. package/dist/types/tools/eval.d.ts +108 -0
  553. package/dist/types/tools/fetch.d.ts +61 -0
  554. package/dist/types/tools/file-recorder.d.ts +13 -0
  555. package/dist/types/tools/find.d.ts +95 -0
  556. package/dist/types/tools/fs-cache-invalidation.d.ts +15 -0
  557. package/dist/types/tools/gh-format.d.ts +6 -0
  558. package/dist/types/tools/gh-renderer.d.ts +25 -0
  559. package/dist/types/tools/gh.d.ts +356 -0
  560. package/dist/types/tools/github-cache.d.ts +103 -0
  561. package/dist/types/tools/grouped-file-output.d.ts +36 -0
  562. package/dist/types/tools/hindsight-recall.d.ts +23 -0
  563. package/dist/types/tools/hindsight-reflect.d.ts +25 -0
  564. package/dist/types/tools/hindsight-retain.d.ts +29 -0
  565. package/dist/types/tools/image-gen.d.ts +78 -0
  566. package/dist/types/tools/index.d.ts +242 -0
  567. package/dist/types/tools/inspect-image-renderer.d.ts +26 -0
  568. package/dist/types/tools/inspect-image.d.ts +31 -0
  569. package/dist/types/tools/irc.d.ts +79 -0
  570. package/dist/types/tools/job.d.ts +65 -0
  571. package/dist/types/tools/json-tree.d.ts +23 -0
  572. package/dist/types/tools/jtd-to-json-schema.d.ts +29 -0
  573. package/dist/types/tools/jtd-to-typescript.d.ts +26 -0
  574. package/dist/types/tools/jtd-utils.d.ts +42 -0
  575. package/dist/types/tools/list-limit.d.ts +12 -0
  576. package/dist/types/tools/match-line-format.d.ts +11 -0
  577. package/dist/types/tools/output-meta.d.ts +204 -0
  578. package/dist/types/tools/path-utils.d.ts +146 -0
  579. package/dist/types/tools/plan-mode-guard.d.ts +18 -0
  580. package/dist/types/tools/read.d.ts +85 -0
  581. package/dist/types/tools/recipe/index.d.ts +45 -0
  582. package/dist/types/tools/recipe/render.d.ts +36 -0
  583. package/dist/types/tools/recipe/runner.d.ts +60 -0
  584. package/dist/types/tools/recipe/runners/cargo.d.ts +16 -0
  585. package/dist/types/tools/recipe/runners/index.d.ts +2 -0
  586. package/dist/types/tools/recipe/runners/just.d.ts +2 -0
  587. package/dist/types/tools/recipe/runners/make.d.ts +2 -0
  588. package/dist/types/tools/recipe/runners/pkg.d.ts +2 -0
  589. package/dist/types/tools/recipe/runners/task.d.ts +2 -0
  590. package/dist/types/tools/render-mermaid.d.ts +37 -0
  591. package/dist/types/tools/render-utils.d.ts +158 -0
  592. package/dist/types/tools/renderers.d.ts +26 -0
  593. package/dist/types/tools/resolve.d.ts +90 -0
  594. package/dist/types/tools/review.d.ts +63 -0
  595. package/dist/types/tools/search-tool-bm25.d.ts +65 -0
  596. package/dist/types/tools/search.d.ts +93 -0
  597. package/dist/types/tools/sqlite-reader.d.ts +93 -0
  598. package/dist/types/tools/ssh.d.ts +67 -0
  599. package/dist/types/tools/subagent.d.ts +58 -0
  600. package/dist/types/tools/todo-write.d.ts +120 -0
  601. package/dist/types/tools/tool-errors.d.ts +33 -0
  602. package/dist/types/tools/tool-result.d.ts +30 -0
  603. package/dist/types/tools/tool-timeouts.d.ts +51 -0
  604. package/dist/types/tools/vim.d.ts +58 -0
  605. package/dist/types/tools/write.d.ts +59 -0
  606. package/dist/types/tools/yield.d.ts +25 -0
  607. package/dist/types/tui/code-cell.d.ts +32 -0
  608. package/dist/types/tui/file-list.d.ts +22 -0
  609. package/dist/types/tui/hyperlink.d.ts +42 -0
  610. package/dist/types/tui/index.d.ts +11 -0
  611. package/dist/types/tui/output-block.d.ts +28 -0
  612. package/dist/types/tui/status-line.d.ts +18 -0
  613. package/dist/types/tui/tree-list.d.ts +19 -0
  614. package/dist/types/tui/types.d.ts +13 -0
  615. package/dist/types/tui/utils.d.ts +36 -0
  616. package/dist/types/utils/changelog.d.ts +20 -0
  617. package/dist/types/utils/clipboard.d.ts +22 -0
  618. package/dist/types/utils/command-args.d.ts +9 -0
  619. package/dist/types/utils/commit-message-generator.d.ts +7 -0
  620. package/dist/types/utils/edit-mode.d.ts +13 -0
  621. package/dist/types/utils/event-bus.d.ts +6 -0
  622. package/dist/types/utils/external-editor.d.ts +17 -0
  623. package/dist/types/utils/file-display-mode.d.ts +27 -0
  624. package/dist/types/utils/file-mentions.d.ts +11 -0
  625. package/dist/types/utils/git.d.ts +361 -0
  626. package/dist/types/utils/image-loading.d.ts +26 -0
  627. package/dist/types/utils/image-resize.d.ts +39 -0
  628. package/dist/types/utils/lang-from-path.d.ts +8 -0
  629. package/dist/types/utils/markit.d.ts +7 -0
  630. package/dist/types/utils/open.d.ts +2 -0
  631. package/dist/types/utils/session-color.d.ts +10 -0
  632. package/dist/types/utils/shell-snapshot.d.ts +5 -0
  633. package/dist/types/utils/sixel.d.ts +21 -0
  634. package/dist/types/utils/title-generator.d.ts +31 -0
  635. package/dist/types/utils/tool-choice.d.ts +7 -0
  636. package/dist/types/utils/tools-manager.d.ts +9 -0
  637. package/dist/types/vim/buffer.d.ts +41 -0
  638. package/dist/types/vim/commands.d.ts +6 -0
  639. package/dist/types/vim/engine.d.ts +47 -0
  640. package/dist/types/vim/parser.d.ts +3 -0
  641. package/dist/types/vim/render.d.ts +25 -0
  642. package/dist/types/vim/types.d.ts +182 -0
  643. package/dist/types/web/kagi.d.ts +23 -0
  644. package/dist/types/web/parallel.d.ts +58 -0
  645. package/dist/types/web/scrapers/artifacthub.d.ts +6 -0
  646. package/dist/types/web/scrapers/arxiv.d.ts +5 -0
  647. package/dist/types/web/scrapers/aur.d.ts +5 -0
  648. package/dist/types/web/scrapers/biorxiv.d.ts +5 -0
  649. package/dist/types/web/scrapers/bluesky.d.ts +5 -0
  650. package/dist/types/web/scrapers/brew.d.ts +5 -0
  651. package/dist/types/web/scrapers/cheatsh.d.ts +8 -0
  652. package/dist/types/web/scrapers/chocolatey.d.ts +5 -0
  653. package/dist/types/web/scrapers/choosealicense.d.ts +2 -0
  654. package/dist/types/web/scrapers/cisa-kev.d.ts +5 -0
  655. package/dist/types/web/scrapers/clojars.d.ts +5 -0
  656. package/dist/types/web/scrapers/coingecko.d.ts +5 -0
  657. package/dist/types/web/scrapers/crates-io.d.ts +5 -0
  658. package/dist/types/web/scrapers/crossref.d.ts +2 -0
  659. package/dist/types/web/scrapers/devto.d.ts +5 -0
  660. package/dist/types/web/scrapers/discogs.d.ts +8 -0
  661. package/dist/types/web/scrapers/discourse.d.ts +5 -0
  662. package/dist/types/web/scrapers/dockerhub.d.ts +5 -0
  663. package/dist/types/web/scrapers/docs-rs.d.ts +2 -0
  664. package/dist/types/web/scrapers/fdroid.d.ts +5 -0
  665. package/dist/types/web/scrapers/firefox-addons.d.ts +2 -0
  666. package/dist/types/web/scrapers/flathub.d.ts +2 -0
  667. package/dist/types/web/scrapers/github-gist.d.ts +5 -0
  668. package/dist/types/web/scrapers/github.d.ts +12 -0
  669. package/dist/types/web/scrapers/gitlab.d.ts +5 -0
  670. package/dist/types/web/scrapers/go-pkg.d.ts +5 -0
  671. package/dist/types/web/scrapers/hackage.d.ts +5 -0
  672. package/dist/types/web/scrapers/hackernews.d.ts +2 -0
  673. package/dist/types/web/scrapers/hex.d.ts +5 -0
  674. package/dist/types/web/scrapers/huggingface.d.ts +2 -0
  675. package/dist/types/web/scrapers/iacr.d.ts +5 -0
  676. package/dist/types/web/scrapers/index.d.ts +84 -0
  677. package/dist/types/web/scrapers/jetbrains-marketplace.d.ts +2 -0
  678. package/dist/types/web/scrapers/lemmy.d.ts +2 -0
  679. package/dist/types/web/scrapers/lobsters.d.ts +5 -0
  680. package/dist/types/web/scrapers/mastodon.d.ts +5 -0
  681. package/dist/types/web/scrapers/maven.d.ts +6 -0
  682. package/dist/types/web/scrapers/mdn.d.ts +2 -0
  683. package/dist/types/web/scrapers/metacpan.d.ts +5 -0
  684. package/dist/types/web/scrapers/musicbrainz.d.ts +5 -0
  685. package/dist/types/web/scrapers/npm.d.ts +5 -0
  686. package/dist/types/web/scrapers/nuget.d.ts +5 -0
  687. package/dist/types/web/scrapers/nvd.d.ts +5 -0
  688. package/dist/types/web/scrapers/ollama.d.ts +2 -0
  689. package/dist/types/web/scrapers/open-vsx.d.ts +5 -0
  690. package/dist/types/web/scrapers/opencorporates.d.ts +5 -0
  691. package/dist/types/web/scrapers/openlibrary.d.ts +5 -0
  692. package/dist/types/web/scrapers/orcid.d.ts +5 -0
  693. package/dist/types/web/scrapers/osv.d.ts +5 -0
  694. package/dist/types/web/scrapers/packagist.d.ts +5 -0
  695. package/dist/types/web/scrapers/pub-dev.d.ts +5 -0
  696. package/dist/types/web/scrapers/pubmed.d.ts +5 -0
  697. package/dist/types/web/scrapers/pypi.d.ts +5 -0
  698. package/dist/types/web/scrapers/rawg.d.ts +2 -0
  699. package/dist/types/web/scrapers/readthedocs.d.ts +2 -0
  700. package/dist/types/web/scrapers/reddit.d.ts +5 -0
  701. package/dist/types/web/scrapers/repology.d.ts +5 -0
  702. package/dist/types/web/scrapers/rfc.d.ts +5 -0
  703. package/dist/types/web/scrapers/rubygems.d.ts +5 -0
  704. package/dist/types/web/scrapers/searchcode.d.ts +2 -0
  705. package/dist/types/web/scrapers/sec-edgar.d.ts +5 -0
  706. package/dist/types/web/scrapers/semantic-scholar.d.ts +2 -0
  707. package/dist/types/web/scrapers/snapcraft.d.ts +2 -0
  708. package/dist/types/web/scrapers/sourcegraph.d.ts +2 -0
  709. package/dist/types/web/scrapers/spdx.d.ts +5 -0
  710. package/dist/types/web/scrapers/spotify.d.ts +8 -0
  711. package/dist/types/web/scrapers/stackoverflow.d.ts +6 -0
  712. package/dist/types/web/scrapers/terraform.d.ts +5 -0
  713. package/dist/types/web/scrapers/tldr.d.ts +7 -0
  714. package/dist/types/web/scrapers/twitter.d.ts +5 -0
  715. package/dist/types/web/scrapers/types.d.ts +78 -0
  716. package/dist/types/web/scrapers/utils.d.ts +26 -0
  717. package/dist/types/web/scrapers/vimeo.d.ts +5 -0
  718. package/dist/types/web/scrapers/vscode-marketplace.d.ts +5 -0
  719. package/dist/types/web/scrapers/w3c.d.ts +2 -0
  720. package/dist/types/web/scrapers/wikidata.d.ts +5 -0
  721. package/dist/types/web/scrapers/wikipedia.d.ts +5 -0
  722. package/dist/types/web/scrapers/youtube.d.ts +5 -0
  723. package/dist/types/web/search/index.d.ts +84 -0
  724. package/dist/types/web/search/provider.d.ts +21 -0
  725. package/dist/types/web/search/providers/anthropic.d.ts +32 -0
  726. package/dist/types/web/search/providers/base.d.ts +67 -0
  727. package/dist/types/web/search/providers/brave.d.ts +27 -0
  728. package/dist/types/web/search/providers/codex.d.ts +35 -0
  729. package/dist/types/web/search/providers/exa.d.ts +52 -0
  730. package/dist/types/web/search/providers/gemini.d.ts +57 -0
  731. package/dist/types/web/search/providers/jina.d.ts +26 -0
  732. package/dist/types/web/search/providers/kagi.d.ts +24 -0
  733. package/dist/types/web/search/providers/kimi.d.ts +27 -0
  734. package/dist/types/web/search/providers/parallel.d.ts +15 -0
  735. package/dist/types/web/search/providers/perplexity.d.ts +38 -0
  736. package/dist/types/web/search/providers/searxng.d.ts +44 -0
  737. package/dist/types/web/search/providers/synthetic.d.ts +21 -0
  738. package/dist/types/web/search/providers/tavily.d.ts +29 -0
  739. package/dist/types/web/search/providers/utils.d.ts +52 -0
  740. package/dist/types/web/search/providers/zai.d.ts +28 -0
  741. package/dist/types/web/search/render.d.ts +35 -0
  742. package/dist/types/web/search/types.d.ts +344 -0
  743. package/dist/types/web/search/utils.d.ts +4 -0
  744. package/dist/types/workspace-tree.d.ts +42 -0
  745. package/examples/README.md +21 -0
  746. package/examples/custom-tools/README.md +104 -0
  747. package/examples/custom-tools/hello/index.ts +20 -0
  748. package/examples/extensions/README.md +141 -0
  749. package/examples/extensions/api-demo.ts +79 -0
  750. package/examples/extensions/chalk-logger.ts +25 -0
  751. package/examples/extensions/hello.ts +31 -0
  752. package/examples/extensions/pirate.ts +43 -0
  753. package/examples/extensions/plan-mode.ts +549 -0
  754. package/examples/extensions/reload-runtime.ts +38 -0
  755. package/examples/extensions/tools.ts +144 -0
  756. package/examples/extensions/with-deps/index.ts +36 -0
  757. package/examples/extensions/with-deps/package-lock.json +31 -0
  758. package/examples/extensions/with-deps/package.json +16 -0
  759. package/examples/hooks/README.md +56 -0
  760. package/examples/hooks/auto-commit-on-exit.ts +48 -0
  761. package/examples/hooks/confirm-destructive.ts +58 -0
  762. package/examples/hooks/custom-compaction.ts +115 -0
  763. package/examples/hooks/dirty-repo-guard.ts +51 -0
  764. package/examples/hooks/file-trigger.ts +40 -0
  765. package/examples/hooks/git-checkpoint.ts +52 -0
  766. package/examples/hooks/handoff.ts +149 -0
  767. package/examples/hooks/permission-gate.ts +33 -0
  768. package/examples/hooks/protected-paths.ts +29 -0
  769. package/examples/hooks/qna.ts +118 -0
  770. package/examples/hooks/status-line.ts +39 -0
  771. package/examples/sdk/01-minimal.ts +21 -0
  772. package/examples/sdk/02-custom-model.ts +49 -0
  773. package/examples/sdk/03-custom-prompt.ts +46 -0
  774. package/examples/sdk/04-skills.ts +43 -0
  775. package/examples/sdk/06-extensions.ts +82 -0
  776. package/examples/sdk/06-hooks.ts +61 -0
  777. package/examples/sdk/07-context-files.ts +35 -0
  778. package/examples/sdk/08-prompt-templates.ts +41 -0
  779. package/examples/sdk/08-slash-commands.ts +46 -0
  780. package/examples/sdk/09-api-keys-and-oauth.ts +54 -0
  781. package/examples/sdk/11-sessions.ts +47 -0
  782. package/examples/sdk/README.md +172 -0
  783. package/package.json +533 -0
  784. package/scripts/build-binary.ts +77 -0
  785. package/scripts/format-prompts.ts +68 -0
  786. package/scripts/generate-docs-index.ts +71 -0
  787. package/scripts/generate-template.ts +33 -0
  788. package/src/async/index.ts +2 -0
  789. package/src/async/job-manager.ts +586 -0
  790. package/src/async/support.ts +6 -0
  791. package/src/autoresearch/command-resume.md +14 -0
  792. package/src/autoresearch/dashboard.ts +446 -0
  793. package/src/autoresearch/git.ts +319 -0
  794. package/src/autoresearch/helpers.ts +218 -0
  795. package/src/autoresearch/index.ts +536 -0
  796. package/src/autoresearch/prompt-setup.md +43 -0
  797. package/src/autoresearch/prompt.md +103 -0
  798. package/src/autoresearch/resume-message.md +10 -0
  799. package/src/autoresearch/state.ts +273 -0
  800. package/src/autoresearch/storage.ts +699 -0
  801. package/src/autoresearch/tools/init-experiment.ts +272 -0
  802. package/src/autoresearch/tools/log-experiment.ts +524 -0
  803. package/src/autoresearch/tools/run-experiment.ts +475 -0
  804. package/src/autoresearch/tools/update-notes.ts +109 -0
  805. package/src/autoresearch/types.ts +168 -0
  806. package/src/bun-imports.d.ts +28 -0
  807. package/src/capability/context-file.ts +44 -0
  808. package/src/capability/extension-module.ts +34 -0
  809. package/src/capability/extension.ts +47 -0
  810. package/src/capability/fs.ts +107 -0
  811. package/src/capability/hook.ts +40 -0
  812. package/src/capability/index.ts +436 -0
  813. package/src/capability/instruction.ts +37 -0
  814. package/src/capability/mcp.ts +74 -0
  815. package/src/capability/prompt.ts +35 -0
  816. package/src/capability/rule.ts +244 -0
  817. package/src/capability/settings.ts +34 -0
  818. package/src/capability/skill.ts +56 -0
  819. package/src/capability/slash-command.ts +40 -0
  820. package/src/capability/ssh.ts +41 -0
  821. package/src/capability/system-prompt.ts +34 -0
  822. package/src/capability/tool.ts +38 -0
  823. package/src/capability/types.ts +168 -0
  824. package/src/cli/agents-cli.ts +138 -0
  825. package/src/cli/args.ts +269 -0
  826. package/src/cli/auth-broker-cli.ts +746 -0
  827. package/src/cli/auth-gateway-cli.ts +411 -0
  828. package/src/cli/classify-install-target.ts +50 -0
  829. package/src/cli/commands/init-xdg.ts +27 -0
  830. package/src/cli/config-cli.ts +418 -0
  831. package/src/cli/file-processor.ts +123 -0
  832. package/src/cli/grep-cli.ts +160 -0
  833. package/src/cli/initial-message.ts +58 -0
  834. package/src/cli/list-models.ts +194 -0
  835. package/src/cli/plugin-cli.ts +942 -0
  836. package/src/cli/read-cli.ts +57 -0
  837. package/src/cli/session-picker.ts +52 -0
  838. package/src/cli/setup-cli.ts +433 -0
  839. package/src/cli/shell-cli.ts +176 -0
  840. package/src/cli/ssh-cli.ts +179 -0
  841. package/src/cli/stats-cli.ts +238 -0
  842. package/src/cli/update-cli.ts +408 -0
  843. package/src/cli/web-search-cli.ts +133 -0
  844. package/src/cli/worktree-cli.ts +291 -0
  845. package/src/cli.ts +99 -0
  846. package/src/commands/acp.ts +24 -0
  847. package/src/commands/agents.ts +57 -0
  848. package/src/commands/auth-broker.ts +96 -0
  849. package/src/commands/auth-gateway.ts +63 -0
  850. package/src/commands/codex-native-hook.ts +11 -0
  851. package/src/commands/commit.ts +46 -0
  852. package/src/commands/config.ts +51 -0
  853. package/src/commands/deep-interview.ts +12 -0
  854. package/src/commands/gjc-runtime-bridge.ts +81 -0
  855. package/src/commands/grep.ts +48 -0
  856. package/src/commands/launch.ts +161 -0
  857. package/src/commands/plugin.ts +78 -0
  858. package/src/commands/question.ts +12 -0
  859. package/src/commands/ralplan.ts +12 -0
  860. package/src/commands/read.ts +35 -0
  861. package/src/commands/setup.ts +52 -0
  862. package/src/commands/shell.ts +29 -0
  863. package/src/commands/ssh.ts +60 -0
  864. package/src/commands/state.ts +12 -0
  865. package/src/commands/stats.ts +29 -0
  866. package/src/commands/team.ts +130 -0
  867. package/src/commands/ultragoal.ts +32 -0
  868. package/src/commands/update.ts +21 -0
  869. package/src/commands/web-search.ts +42 -0
  870. package/src/commands/worktree.ts +56 -0
  871. package/src/commit/agentic/agent.ts +316 -0
  872. package/src/commit/agentic/fallback.ts +96 -0
  873. package/src/commit/agentic/index.ts +355 -0
  874. package/src/commit/agentic/prompts/analyze-file.md +22 -0
  875. package/src/commit/agentic/prompts/session-user.md +25 -0
  876. package/src/commit/agentic/prompts/split-confirm.md +1 -0
  877. package/src/commit/agentic/prompts/system.md +38 -0
  878. package/src/commit/agentic/state.ts +60 -0
  879. package/src/commit/agentic/tools/analyze-file.ts +127 -0
  880. package/src/commit/agentic/tools/git-file-diff.ts +191 -0
  881. package/src/commit/agentic/tools/git-hunk.ts +50 -0
  882. package/src/commit/agentic/tools/git-overview.ts +81 -0
  883. package/src/commit/agentic/tools/index.ts +54 -0
  884. package/src/commit/agentic/tools/propose-changelog.ts +144 -0
  885. package/src/commit/agentic/tools/propose-commit.ts +109 -0
  886. package/src/commit/agentic/tools/recent-commits.ts +81 -0
  887. package/src/commit/agentic/tools/schemas.ts +23 -0
  888. package/src/commit/agentic/tools/split-commit.ts +238 -0
  889. package/src/commit/agentic/topo-sort.ts +44 -0
  890. package/src/commit/agentic/trivial.ts +51 -0
  891. package/src/commit/agentic/validation.ts +183 -0
  892. package/src/commit/analysis/conventional.ts +64 -0
  893. package/src/commit/analysis/index.ts +4 -0
  894. package/src/commit/analysis/scope.ts +242 -0
  895. package/src/commit/analysis/summary.ts +105 -0
  896. package/src/commit/analysis/validation.ts +66 -0
  897. package/src/commit/changelog/detect.ts +40 -0
  898. package/src/commit/changelog/generate.ts +97 -0
  899. package/src/commit/changelog/index.ts +234 -0
  900. package/src/commit/changelog/parse.ts +44 -0
  901. package/src/commit/cli.ts +85 -0
  902. package/src/commit/git/diff.ts +148 -0
  903. package/src/commit/index.ts +5 -0
  904. package/src/commit/map-reduce/index.ts +69 -0
  905. package/src/commit/map-reduce/map-phase.ts +193 -0
  906. package/src/commit/map-reduce/reduce-phase.ts +49 -0
  907. package/src/commit/map-reduce/utils.ts +9 -0
  908. package/src/commit/message.ts +11 -0
  909. package/src/commit/model-selection.ts +66 -0
  910. package/src/commit/pipeline.ts +243 -0
  911. package/src/commit/prompts/analysis-system.md +148 -0
  912. package/src/commit/prompts/analysis-user.md +38 -0
  913. package/src/commit/prompts/changelog-system.md +50 -0
  914. package/src/commit/prompts/changelog-user.md +18 -0
  915. package/src/commit/prompts/file-observer-system.md +24 -0
  916. package/src/commit/prompts/file-observer-user.md +8 -0
  917. package/src/commit/prompts/reduce-system.md +50 -0
  918. package/src/commit/prompts/reduce-user.md +17 -0
  919. package/src/commit/prompts/summary-retry.md +3 -0
  920. package/src/commit/prompts/summary-system.md +38 -0
  921. package/src/commit/prompts/summary-user.md +13 -0
  922. package/src/commit/prompts/types-description.md +2 -0
  923. package/src/commit/shared-llm.ts +77 -0
  924. package/src/commit/types.ts +118 -0
  925. package/src/commit/utils/exclusions.ts +42 -0
  926. package/src/commit/utils.ts +58 -0
  927. package/src/config/config-file.ts +232 -0
  928. package/src/config/file-lock.ts +121 -0
  929. package/src/config/keybindings.ts +493 -0
  930. package/src/config/mcp-schema.json +230 -0
  931. package/src/config/model-equivalence.ts +811 -0
  932. package/src/config/model-registry.ts +2384 -0
  933. package/src/config/model-resolver.ts +1398 -0
  934. package/src/config/models-config-schema.ts +175 -0
  935. package/src/config/prompt-templates.ts +310 -0
  936. package/src/config/resolve-config-value.ts +94 -0
  937. package/src/config/settings-schema.ts +2939 -0
  938. package/src/config/settings.ts +919 -0
  939. package/src/config/skill-settings-defaults.ts +27 -0
  940. package/src/config.ts +212 -0
  941. package/src/cursor.ts +350 -0
  942. package/src/dap/client.ts +675 -0
  943. package/src/dap/config.ts +150 -0
  944. package/src/dap/defaults.json +211 -0
  945. package/src/dap/index.ts +4 -0
  946. package/src/dap/session.ts +1306 -0
  947. package/src/dap/types.ts +600 -0
  948. package/src/debug/index.ts +459 -0
  949. package/src/debug/log-formatting.ts +58 -0
  950. package/src/debug/log-viewer.ts +908 -0
  951. package/src/debug/profiler.ts +162 -0
  952. package/src/debug/raw-sse-buffer.ts +270 -0
  953. package/src/debug/raw-sse.ts +213 -0
  954. package/src/debug/report-bundle.ts +365 -0
  955. package/src/debug/system-info.ts +111 -0
  956. package/src/defaults/gjc/skills/deep-interview/SKILL.md +795 -0
  957. package/src/defaults/gjc/skills/ralplan/SKILL.md +142 -0
  958. package/src/defaults/gjc/skills/team/SKILL.md +373 -0
  959. package/src/defaults/gjc/skills/ultragoal/SKILL.md +176 -0
  960. package/src/defaults/gjc-defaults.ts +151 -0
  961. package/src/discovery/agents-md.ts +67 -0
  962. package/src/discovery/agents.ts +230 -0
  963. package/src/discovery/builtin.ts +932 -0
  964. package/src/discovery/claude-plugins.ts +387 -0
  965. package/src/discovery/claude.ts +313 -0
  966. package/src/discovery/cline.ts +83 -0
  967. package/src/discovery/codex.ts +330 -0
  968. package/src/discovery/cursor.ts +220 -0
  969. package/src/discovery/gemini.ts +383 -0
  970. package/src/discovery/github.ts +118 -0
  971. package/src/discovery/helpers.ts +964 -0
  972. package/src/discovery/index.ts +76 -0
  973. package/src/discovery/mcp-json.ts +171 -0
  974. package/src/discovery/opencode.ts +398 -0
  975. package/src/discovery/plugin-dir-roots.ts +28 -0
  976. package/src/discovery/ssh.ts +153 -0
  977. package/src/discovery/substitute-plugin-root.ts +29 -0
  978. package/src/discovery/vscode.ts +105 -0
  979. package/src/discovery/windsurf.ts +147 -0
  980. package/src/edit/apply-patch/index.ts +87 -0
  981. package/src/edit/apply-patch/parser.ts +174 -0
  982. package/src/edit/diff.ts +810 -0
  983. package/src/edit/file-read-cache.ts +95 -0
  984. package/src/edit/index.ts +528 -0
  985. package/src/edit/modes/apply-patch.lark +19 -0
  986. package/src/edit/modes/apply-patch.ts +53 -0
  987. package/src/edit/modes/patch.ts +1835 -0
  988. package/src/edit/modes/replace.ts +1103 -0
  989. package/src/edit/normalize.ts +375 -0
  990. package/src/edit/notebook.ts +222 -0
  991. package/src/edit/read-file.ts +25 -0
  992. package/src/edit/renderer.ts +683 -0
  993. package/src/edit/streaming.ts +561 -0
  994. package/src/eval/backend.ts +43 -0
  995. package/src/eval/index.ts +4 -0
  996. package/src/eval/js/context-manager.ts +414 -0
  997. package/src/eval/js/executor.ts +134 -0
  998. package/src/eval/js/index.ts +46 -0
  999. package/src/eval/js/shared/helpers.ts +237 -0
  1000. package/src/eval/js/shared/indirect-eval.ts +30 -0
  1001. package/src/eval/js/shared/prelude.ts +2 -0
  1002. package/src/eval/js/shared/prelude.txt +70 -0
  1003. package/src/eval/js/shared/rewrite-imports.ts +416 -0
  1004. package/src/eval/js/shared/runtime.ts +301 -0
  1005. package/src/eval/js/shared/types.ts +18 -0
  1006. package/src/eval/js/tool-bridge.ts +144 -0
  1007. package/src/eval/js/worker-core.ts +146 -0
  1008. package/src/eval/js/worker-entry.ts +24 -0
  1009. package/src/eval/js/worker-protocol.ts +41 -0
  1010. package/src/eval/py/display.ts +71 -0
  1011. package/src/eval/py/executor.ts +602 -0
  1012. package/src/eval/py/index.ts +58 -0
  1013. package/src/eval/py/kernel.ts +668 -0
  1014. package/src/eval/py/prelude.py +462 -0
  1015. package/src/eval/py/prelude.ts +3 -0
  1016. package/src/eval/py/runner.py +910 -0
  1017. package/src/eval/py/runtime.ts +210 -0
  1018. package/src/eval/py/tool-bridge.ts +137 -0
  1019. package/src/eval/types.ts +48 -0
  1020. package/src/exa/factory.ts +60 -0
  1021. package/src/exa/index.ts +27 -0
  1022. package/src/exa/mcp-client.ts +364 -0
  1023. package/src/exa/render.ts +244 -0
  1024. package/src/exa/researcher.ts +36 -0
  1025. package/src/exa/search.ts +47 -0
  1026. package/src/exa/types.ts +166 -0
  1027. package/src/exa/websets.ts +248 -0
  1028. package/src/exec/bash-executor.ts +309 -0
  1029. package/src/exec/exec.ts +53 -0
  1030. package/src/exec/idle-timeout-watchdog.ts +126 -0
  1031. package/src/exec/non-interactive-env.ts +48 -0
  1032. package/src/export/custom-share.ts +65 -0
  1033. package/src/export/html/index.ts +164 -0
  1034. package/src/export/html/template.css +1060 -0
  1035. package/src/export/html/template.generated.ts +2 -0
  1036. package/src/export/html/template.html +47 -0
  1037. package/src/export/html/template.js +2268 -0
  1038. package/src/export/html/template.macro.ts +25 -0
  1039. package/src/export/html/vendor/highlight.min.js +1213 -0
  1040. package/src/export/html/vendor/marked.min.js +6 -0
  1041. package/src/export/ttsr.ts +434 -0
  1042. package/src/extensibility/custom-commands/bundled/ci-green/index.ts +25 -0
  1043. package/src/extensibility/custom-commands/bundled/review/index.ts +456 -0
  1044. package/src/extensibility/custom-commands/index.ts +2 -0
  1045. package/src/extensibility/custom-commands/loader.ts +238 -0
  1046. package/src/extensibility/custom-commands/types.ts +113 -0
  1047. package/src/extensibility/custom-tools/index.ts +7 -0
  1048. package/src/extensibility/custom-tools/loader.ts +245 -0
  1049. package/src/extensibility/custom-tools/types.ts +254 -0
  1050. package/src/extensibility/custom-tools/wrapper.ts +47 -0
  1051. package/src/extensibility/extensions/compact-handler.ts +40 -0
  1052. package/src/extensibility/extensions/get-commands-handler.ts +80 -0
  1053. package/src/extensibility/extensions/index.ts +15 -0
  1054. package/src/extensibility/extensions/loader.ts +545 -0
  1055. package/src/extensibility/extensions/runner.ts +900 -0
  1056. package/src/extensibility/extensions/types.ts +1259 -0
  1057. package/src/extensibility/extensions/wrapper.ts +189 -0
  1058. package/src/extensibility/hooks/index.ts +5 -0
  1059. package/src/extensibility/hooks/loader.ts +257 -0
  1060. package/src/extensibility/hooks/runner.ts +425 -0
  1061. package/src/extensibility/hooks/tool-wrapper.ts +107 -0
  1062. package/src/extensibility/hooks/types.ts +599 -0
  1063. package/src/extensibility/plugins/doctor.ts +66 -0
  1064. package/src/extensibility/plugins/git-url.ts +281 -0
  1065. package/src/extensibility/plugins/index.ts +9 -0
  1066. package/src/extensibility/plugins/installer.ts +192 -0
  1067. package/src/extensibility/plugins/legacy-pi-compat.ts +336 -0
  1068. package/src/extensibility/plugins/loader.ts +288 -0
  1069. package/src/extensibility/plugins/manager.ts +731 -0
  1070. package/src/extensibility/plugins/marketplace/cache.ts +136 -0
  1071. package/src/extensibility/plugins/marketplace/fetcher.ts +317 -0
  1072. package/src/extensibility/plugins/marketplace/index.ts +6 -0
  1073. package/src/extensibility/plugins/marketplace/manager.ts +770 -0
  1074. package/src/extensibility/plugins/marketplace/registry.ts +196 -0
  1075. package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
  1076. package/src/extensibility/plugins/marketplace/types.ts +191 -0
  1077. package/src/extensibility/plugins/parser.ts +105 -0
  1078. package/src/extensibility/plugins/types.ts +194 -0
  1079. package/src/extensibility/shared-events.ts +343 -0
  1080. package/src/extensibility/skills.ts +391 -0
  1081. package/src/extensibility/slash-commands.ts +227 -0
  1082. package/src/extensibility/tool-proxy.ts +25 -0
  1083. package/src/extensibility/typebox.ts +418 -0
  1084. package/src/extensibility/utils.ts +44 -0
  1085. package/src/gjc-runtime/goal-mode-request.ts +212 -0
  1086. package/src/gjc-runtime/launch-tmux.ts +162 -0
  1087. package/src/gjc-runtime/launch-worktree.ts +291 -0
  1088. package/src/gjc-runtime/team-runtime.ts +2025 -0
  1089. package/src/gjc-runtime/ultragoal-runtime.ts +564 -0
  1090. package/src/goals/index.ts +3 -0
  1091. package/src/goals/runtime.ts +524 -0
  1092. package/src/goals/state.ts +37 -0
  1093. package/src/goals/tools/goal-tool.ts +371 -0
  1094. package/src/hashline/anchors.ts +113 -0
  1095. package/src/hashline/apply.ts +737 -0
  1096. package/src/hashline/bigrams.json +649 -0
  1097. package/src/hashline/constants.ts +25 -0
  1098. package/src/hashline/diff-preview.ts +43 -0
  1099. package/src/hashline/diff.ts +56 -0
  1100. package/src/hashline/execute.ts +267 -0
  1101. package/src/hashline/grammar.lark +21 -0
  1102. package/src/hashline/hash.ts +173 -0
  1103. package/src/hashline/index.ts +13 -0
  1104. package/src/hashline/input.ts +130 -0
  1105. package/src/hashline/parser.ts +246 -0
  1106. package/src/hashline/prefixes.ts +101 -0
  1107. package/src/hashline/recovery.ts +113 -0
  1108. package/src/hashline/stream.ts +123 -0
  1109. package/src/hashline/types.ts +68 -0
  1110. package/src/hindsight/backend.ts +205 -0
  1111. package/src/hindsight/bank.ts +131 -0
  1112. package/src/hindsight/client.ts +598 -0
  1113. package/src/hindsight/config.ts +175 -0
  1114. package/src/hindsight/content.ts +210 -0
  1115. package/src/hindsight/index.ts +8 -0
  1116. package/src/hindsight/mental-models.ts +382 -0
  1117. package/src/hindsight/seeds.json +32 -0
  1118. package/src/hindsight/state.ts +469 -0
  1119. package/src/hindsight/transcript.ts +71 -0
  1120. package/src/hooks/codex-native-hooks-config.ts +143 -0
  1121. package/src/hooks/native-skill-hook.ts +279 -0
  1122. package/src/hooks/skill-keywords.ts +86 -0
  1123. package/src/hooks/skill-state.ts +416 -0
  1124. package/src/index.ts +56 -0
  1125. package/src/internal-urls/agent-protocol.ts +129 -0
  1126. package/src/internal-urls/artifact-protocol.ts +80 -0
  1127. package/src/internal-urls/docs-index.generated.ts +81 -0
  1128. package/src/internal-urls/gjc-protocol.ts +83 -0
  1129. package/src/internal-urls/index.ts +21 -0
  1130. package/src/internal-urls/issue-pr-protocol.ts +577 -0
  1131. package/src/internal-urls/json-query.ts +126 -0
  1132. package/src/internal-urls/local-protocol.ts +249 -0
  1133. package/src/internal-urls/mcp-protocol.ts +151 -0
  1134. package/src/internal-urls/memory-protocol.ts +164 -0
  1135. package/src/internal-urls/parse.ts +72 -0
  1136. package/src/internal-urls/registry-helpers.ts +25 -0
  1137. package/src/internal-urls/router.ts +78 -0
  1138. package/src/internal-urls/rule-protocol.ts +38 -0
  1139. package/src/internal-urls/skill-protocol.ts +103 -0
  1140. package/src/internal-urls/types.ts +110 -0
  1141. package/src/lsp/client.ts +951 -0
  1142. package/src/lsp/clients/biome-client.ts +202 -0
  1143. package/src/lsp/clients/index.ts +50 -0
  1144. package/src/lsp/clients/lsp-linter-client.ts +93 -0
  1145. package/src/lsp/clients/swiftlint-client.ts +120 -0
  1146. package/src/lsp/config.ts +492 -0
  1147. package/src/lsp/defaults.json +493 -0
  1148. package/src/lsp/edits.ts +166 -0
  1149. package/src/lsp/index.ts +2282 -0
  1150. package/src/lsp/lspmux.ts +233 -0
  1151. package/src/lsp/render.ts +692 -0
  1152. package/src/lsp/startup-events.ts +13 -0
  1153. package/src/lsp/types.ts +443 -0
  1154. package/src/lsp/utils.ts +678 -0
  1155. package/src/main.ts +961 -0
  1156. package/src/memories/index.ts +1135 -0
  1157. package/src/memories/storage.ts +577 -0
  1158. package/src/memory-backend/index.ts +4 -0
  1159. package/src/memory-backend/local-backend.ts +30 -0
  1160. package/src/memory-backend/off-backend.ts +16 -0
  1161. package/src/memory-backend/resolve.ts +24 -0
  1162. package/src/memory-backend/types.ts +79 -0
  1163. package/src/modes/acp/acp-agent.ts +2170 -0
  1164. package/src/modes/acp/acp-client-bridge.ts +154 -0
  1165. package/src/modes/acp/acp-event-mapper.ts +879 -0
  1166. package/src/modes/acp/acp-mode.ts +23 -0
  1167. package/src/modes/acp/index.ts +2 -0
  1168. package/src/modes/acp/terminal-auth.ts +37 -0
  1169. package/src/modes/components/agent-dashboard.ts +1120 -0
  1170. package/src/modes/components/assistant-message.ts +231 -0
  1171. package/src/modes/components/bash-execution.ts +228 -0
  1172. package/src/modes/components/bordered-loader.ts +41 -0
  1173. package/src/modes/components/branch-summary-message.ts +45 -0
  1174. package/src/modes/components/btw-panel.ts +104 -0
  1175. package/src/modes/components/compaction-summary-message.ts +51 -0
  1176. package/src/modes/components/countdown-timer.ts +75 -0
  1177. package/src/modes/components/custom-editor.ts +237 -0
  1178. package/src/modes/components/custom-message.ts +65 -0
  1179. package/src/modes/components/diff.ts +266 -0
  1180. package/src/modes/components/dynamic-border.ts +25 -0
  1181. package/src/modes/components/eval-execution.ts +164 -0
  1182. package/src/modes/components/execution-shared.ts +102 -0
  1183. package/src/modes/components/extensions/extension-dashboard.ts +350 -0
  1184. package/src/modes/components/extensions/extension-list.ts +492 -0
  1185. package/src/modes/components/extensions/index.ts +9 -0
  1186. package/src/modes/components/extensions/inspector-panel.ts +317 -0
  1187. package/src/modes/components/extensions/state-manager.ts +628 -0
  1188. package/src/modes/components/extensions/types.ts +191 -0
  1189. package/src/modes/components/footer.ts +270 -0
  1190. package/src/modes/components/history-search.ts +158 -0
  1191. package/src/modes/components/hook-editor.ts +151 -0
  1192. package/src/modes/components/hook-input.ts +79 -0
  1193. package/src/modes/components/hook-message.ts +68 -0
  1194. package/src/modes/components/hook-selector.ts +190 -0
  1195. package/src/modes/components/index.ts +36 -0
  1196. package/src/modes/components/keybinding-hints.ts +65 -0
  1197. package/src/modes/components/login-dialog.ts +164 -0
  1198. package/src/modes/components/message-frame.ts +88 -0
  1199. package/src/modes/components/model-selector.ts +794 -0
  1200. package/src/modes/components/oauth-selector.ts +248 -0
  1201. package/src/modes/components/plugin-selector.ts +95 -0
  1202. package/src/modes/components/plugin-settings.ts +488 -0
  1203. package/src/modes/components/provider-onboarding-selector.ts +88 -0
  1204. package/src/modes/components/queue-mode-selector.ts +56 -0
  1205. package/src/modes/components/read-tool-group.ts +267 -0
  1206. package/src/modes/components/runtime-mcp-add-wizard.ts +1341 -0
  1207. package/src/modes/components/session-observer-overlay.ts +839 -0
  1208. package/src/modes/components/session-selector.ts +343 -0
  1209. package/src/modes/components/settings-defs.ts +175 -0
  1210. package/src/modes/components/settings-selector.ts +635 -0
  1211. package/src/modes/components/show-images-selector.ts +45 -0
  1212. package/src/modes/components/skill-hud/render.ts +47 -0
  1213. package/src/modes/components/skill-message.ts +90 -0
  1214. package/src/modes/components/status-line/context-thresholds.ts +68 -0
  1215. package/src/modes/components/status-line/git-utils.ts +42 -0
  1216. package/src/modes/components/status-line/index.ts +4 -0
  1217. package/src/modes/components/status-line/presets.ts +105 -0
  1218. package/src/modes/components/status-line/segments.ts +560 -0
  1219. package/src/modes/components/status-line/separators.ts +55 -0
  1220. package/src/modes/components/status-line/token-rate.ts +66 -0
  1221. package/src/modes/components/status-line/types.ts +93 -0
  1222. package/src/modes/components/status-line.ts +839 -0
  1223. package/src/modes/components/theme-selector.ts +63 -0
  1224. package/src/modes/components/thinking-selector.ts +52 -0
  1225. package/src/modes/components/todo-reminder.ts +40 -0
  1226. package/src/modes/components/tool-execution.ts +830 -0
  1227. package/src/modes/components/tree-selector.ts +930 -0
  1228. package/src/modes/components/ttsr-notification.ts +80 -0
  1229. package/src/modes/components/user-message-selector.ts +141 -0
  1230. package/src/modes/components/user-message.ts +51 -0
  1231. package/src/modes/components/visual-truncate.ts +63 -0
  1232. package/src/modes/components/welcome.ts +389 -0
  1233. package/src/modes/controllers/btw-controller.ts +105 -0
  1234. package/src/modes/controllers/command-controller-shared.ts +108 -0
  1235. package/src/modes/controllers/command-controller.ts +1630 -0
  1236. package/src/modes/controllers/event-controller.ts +786 -0
  1237. package/src/modes/controllers/extension-ui-controller.ts +927 -0
  1238. package/src/modes/controllers/input-controller.ts +858 -0
  1239. package/src/modes/controllers/runtime-mcp-command-controller.ts +1934 -0
  1240. package/src/modes/controllers/selector-controller.ts +1039 -0
  1241. package/src/modes/controllers/ssh-command-controller.ts +384 -0
  1242. package/src/modes/controllers/todo-command-controller.ts +485 -0
  1243. package/src/modes/data/emojis.json +1 -0
  1244. package/src/modes/emoji-autocomplete.ts +285 -0
  1245. package/src/modes/index.ts +34 -0
  1246. package/src/modes/interactive-mode.ts +2756 -0
  1247. package/src/modes/loop-limit.ts +140 -0
  1248. package/src/modes/oauth-manual-input.ts +42 -0
  1249. package/src/modes/print-mode.ts +121 -0
  1250. package/src/modes/prompt-action-autocomplete.ts +345 -0
  1251. package/src/modes/rpc/host-tools.ts +186 -0
  1252. package/src/modes/rpc/host-uris.ts +235 -0
  1253. package/src/modes/rpc/rpc-client.ts +810 -0
  1254. package/src/modes/rpc/rpc-mode.ts +851 -0
  1255. package/src/modes/rpc/rpc-types.ts +378 -0
  1256. package/src/modes/runtime-init.ts +116 -0
  1257. package/src/modes/session-observer-registry.ts +146 -0
  1258. package/src/modes/shared.ts +55 -0
  1259. package/src/modes/theme/dark.json +95 -0
  1260. package/src/modes/theme/defaults/alabaster.json +93 -0
  1261. package/src/modes/theme/defaults/amethyst.json +96 -0
  1262. package/src/modes/theme/defaults/anthracite.json +93 -0
  1263. package/src/modes/theme/defaults/basalt.json +91 -0
  1264. package/src/modes/theme/defaults/birch.json +95 -0
  1265. package/src/modes/theme/defaults/dark-abyss.json +91 -0
  1266. package/src/modes/theme/defaults/dark-arctic.json +104 -0
  1267. package/src/modes/theme/defaults/dark-aurora.json +95 -0
  1268. package/src/modes/theme/defaults/dark-catppuccin.json +107 -0
  1269. package/src/modes/theme/defaults/dark-cavern.json +91 -0
  1270. package/src/modes/theme/defaults/dark-copper.json +95 -0
  1271. package/src/modes/theme/defaults/dark-cosmos.json +90 -0
  1272. package/src/modes/theme/defaults/dark-cyberpunk.json +102 -0
  1273. package/src/modes/theme/defaults/dark-dracula.json +98 -0
  1274. package/src/modes/theme/defaults/dark-eclipse.json +91 -0
  1275. package/src/modes/theme/defaults/dark-ember.json +95 -0
  1276. package/src/modes/theme/defaults/dark-equinox.json +90 -0
  1277. package/src/modes/theme/defaults/dark-forest.json +96 -0
  1278. package/src/modes/theme/defaults/dark-github.json +105 -0
  1279. package/src/modes/theme/defaults/dark-gruvbox.json +112 -0
  1280. package/src/modes/theme/defaults/dark-lavender.json +95 -0
  1281. package/src/modes/theme/defaults/dark-lunar.json +89 -0
  1282. package/src/modes/theme/defaults/dark-midnight.json +95 -0
  1283. package/src/modes/theme/defaults/dark-monochrome.json +94 -0
  1284. package/src/modes/theme/defaults/dark-monokai.json +98 -0
  1285. package/src/modes/theme/defaults/dark-nebula.json +90 -0
  1286. package/src/modes/theme/defaults/dark-nord.json +97 -0
  1287. package/src/modes/theme/defaults/dark-ocean.json +101 -0
  1288. package/src/modes/theme/defaults/dark-one.json +100 -0
  1289. package/src/modes/theme/defaults/dark-poimandres.json +142 -0
  1290. package/src/modes/theme/defaults/dark-rainforest.json +91 -0
  1291. package/src/modes/theme/defaults/dark-reef.json +91 -0
  1292. package/src/modes/theme/defaults/dark-retro.json +92 -0
  1293. package/src/modes/theme/defaults/dark-rose-pine.json +96 -0
  1294. package/src/modes/theme/defaults/dark-sakura.json +95 -0
  1295. package/src/modes/theme/defaults/dark-slate.json +95 -0
  1296. package/src/modes/theme/defaults/dark-solarized.json +97 -0
  1297. package/src/modes/theme/defaults/dark-solstice.json +90 -0
  1298. package/src/modes/theme/defaults/dark-starfall.json +91 -0
  1299. package/src/modes/theme/defaults/dark-sunset.json +99 -0
  1300. package/src/modes/theme/defaults/dark-swamp.json +90 -0
  1301. package/src/modes/theme/defaults/dark-synthwave.json +103 -0
  1302. package/src/modes/theme/defaults/dark-taiga.json +91 -0
  1303. package/src/modes/theme/defaults/dark-terminal.json +95 -0
  1304. package/src/modes/theme/defaults/dark-tokyo-night.json +101 -0
  1305. package/src/modes/theme/defaults/dark-tundra.json +91 -0
  1306. package/src/modes/theme/defaults/dark-twilight.json +91 -0
  1307. package/src/modes/theme/defaults/dark-volcanic.json +91 -0
  1308. package/src/modes/theme/defaults/graphite.json +92 -0
  1309. package/src/modes/theme/defaults/index.ts +201 -0
  1310. package/src/modes/theme/defaults/light-arctic.json +107 -0
  1311. package/src/modes/theme/defaults/light-aurora-day.json +91 -0
  1312. package/src/modes/theme/defaults/light-canyon.json +91 -0
  1313. package/src/modes/theme/defaults/light-catppuccin.json +106 -0
  1314. package/src/modes/theme/defaults/light-cirrus.json +90 -0
  1315. package/src/modes/theme/defaults/light-coral.json +95 -0
  1316. package/src/modes/theme/defaults/light-cyberpunk.json +96 -0
  1317. package/src/modes/theme/defaults/light-dawn.json +90 -0
  1318. package/src/modes/theme/defaults/light-dunes.json +91 -0
  1319. package/src/modes/theme/defaults/light-eucalyptus.json +95 -0
  1320. package/src/modes/theme/defaults/light-forest.json +100 -0
  1321. package/src/modes/theme/defaults/light-frost.json +95 -0
  1322. package/src/modes/theme/defaults/light-github.json +115 -0
  1323. package/src/modes/theme/defaults/light-glacier.json +91 -0
  1324. package/src/modes/theme/defaults/light-gruvbox.json +108 -0
  1325. package/src/modes/theme/defaults/light-haze.json +90 -0
  1326. package/src/modes/theme/defaults/light-honeycomb.json +95 -0
  1327. package/src/modes/theme/defaults/light-lagoon.json +91 -0
  1328. package/src/modes/theme/defaults/light-lavender.json +95 -0
  1329. package/src/modes/theme/defaults/light-meadow.json +91 -0
  1330. package/src/modes/theme/defaults/light-mint.json +95 -0
  1331. package/src/modes/theme/defaults/light-monochrome.json +101 -0
  1332. package/src/modes/theme/defaults/light-ocean.json +99 -0
  1333. package/src/modes/theme/defaults/light-one.json +99 -0
  1334. package/src/modes/theme/defaults/light-opal.json +91 -0
  1335. package/src/modes/theme/defaults/light-orchard.json +91 -0
  1336. package/src/modes/theme/defaults/light-paper.json +95 -0
  1337. package/src/modes/theme/defaults/light-poimandres.json +142 -0
  1338. package/src/modes/theme/defaults/light-prism.json +90 -0
  1339. package/src/modes/theme/defaults/light-retro.json +98 -0
  1340. package/src/modes/theme/defaults/light-sand.json +95 -0
  1341. package/src/modes/theme/defaults/light-savanna.json +91 -0
  1342. package/src/modes/theme/defaults/light-solarized.json +102 -0
  1343. package/src/modes/theme/defaults/light-soleil.json +90 -0
  1344. package/src/modes/theme/defaults/light-sunset.json +99 -0
  1345. package/src/modes/theme/defaults/light-synthwave.json +98 -0
  1346. package/src/modes/theme/defaults/light-tokyo-night.json +111 -0
  1347. package/src/modes/theme/defaults/light-wetland.json +91 -0
  1348. package/src/modes/theme/defaults/light-zenith.json +89 -0
  1349. package/src/modes/theme/defaults/limestone.json +94 -0
  1350. package/src/modes/theme/defaults/mahogany.json +97 -0
  1351. package/src/modes/theme/defaults/marble.json +93 -0
  1352. package/src/modes/theme/defaults/obsidian.json +91 -0
  1353. package/src/modes/theme/defaults/onyx.json +91 -0
  1354. package/src/modes/theme/defaults/pearl.json +93 -0
  1355. package/src/modes/theme/defaults/porcelain.json +91 -0
  1356. package/src/modes/theme/defaults/quartz.json +96 -0
  1357. package/src/modes/theme/defaults/red-claw.json +123 -0
  1358. package/src/modes/theme/defaults/sandstone.json +95 -0
  1359. package/src/modes/theme/defaults/titanium.json +90 -0
  1360. package/src/modes/theme/light.json +93 -0
  1361. package/src/modes/theme/mermaid-cache.ts +29 -0
  1362. package/src/modes/theme/shimmer.ts +219 -0
  1363. package/src/modes/theme/theme-schema.json +429 -0
  1364. package/src/modes/theme/theme.ts +2413 -0
  1365. package/src/modes/types.ts +313 -0
  1366. package/src/modes/utils/context-usage.ts +335 -0
  1367. package/src/modes/utils/hotkeys-markdown.ts +59 -0
  1368. package/src/modes/utils/keybinding-matchers.ts +30 -0
  1369. package/src/modes/utils/tools-markdown.ts +27 -0
  1370. package/src/modes/utils/ui-helpers.ts +741 -0
  1371. package/src/plan-mode/approved-plan.ts +163 -0
  1372. package/src/plan-mode/state.ts +6 -0
  1373. package/src/priority.json +37 -0
  1374. package/src/prompts/agents/architect.md +79 -0
  1375. package/src/prompts/agents/critic.md +55 -0
  1376. package/src/prompts/agents/executor.md +45 -0
  1377. package/src/prompts/agents/explore.md +58 -0
  1378. package/src/prompts/agents/frontmatter.md +12 -0
  1379. package/src/prompts/agents/init.md +34 -0
  1380. package/src/prompts/agents/plan.md +49 -0
  1381. package/src/prompts/agents/planner.md +49 -0
  1382. package/src/prompts/agents/reviewer.md +141 -0
  1383. package/src/prompts/agents/task.md +16 -0
  1384. package/src/prompts/ci-green-request.md +36 -0
  1385. package/src/prompts/commands/orchestrate.md +49 -0
  1386. package/src/prompts/goals/goal-budget-limit.md +16 -0
  1387. package/src/prompts/goals/goal-continuation.md +28 -0
  1388. package/src/prompts/goals/goal-mode-active.md +23 -0
  1389. package/src/prompts/memories/consolidation.md +30 -0
  1390. package/src/prompts/memories/read-path.md +11 -0
  1391. package/src/prompts/memories/stage_one_input.md +6 -0
  1392. package/src/prompts/memories/stage_one_system.md +21 -0
  1393. package/src/prompts/review-request.md +70 -0
  1394. package/src/prompts/system/agent-creation-architect.md +75 -0
  1395. package/src/prompts/system/agent-creation-user.md +6 -0
  1396. package/src/prompts/system/auto-continue.md +1 -0
  1397. package/src/prompts/system/btw-user.md +8 -0
  1398. package/src/prompts/system/commit-message-system.md +2 -0
  1399. package/src/prompts/system/custom-system-prompt.md +64 -0
  1400. package/src/prompts/system/eager-todo.md +13 -0
  1401. package/src/prompts/system/irc-incoming.md +8 -0
  1402. package/src/prompts/system/plan-mode-active.md +116 -0
  1403. package/src/prompts/system/plan-mode-approved.md +28 -0
  1404. package/src/prompts/system/plan-mode-compact-instructions.md +16 -0
  1405. package/src/prompts/system/plan-mode-reference.md +14 -0
  1406. package/src/prompts/system/plan-mode-subagent.md +34 -0
  1407. package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
  1408. package/src/prompts/system/project-prompt.md +46 -0
  1409. package/src/prompts/system/subagent-system-prompt.md +54 -0
  1410. package/src/prompts/system/subagent-user-prompt.md +3 -0
  1411. package/src/prompts/system/subagent-yield-reminder.md +12 -0
  1412. package/src/prompts/system/system-prompt.md +267 -0
  1413. package/src/prompts/system/title-system.md +2 -0
  1414. package/src/prompts/system/ttsr-interrupt.md +7 -0
  1415. package/src/prompts/system/ttsr-tool-reminder.md +5 -0
  1416. package/src/prompts/system/web-search.md +25 -0
  1417. package/src/prompts/tools/apply-patch.md +65 -0
  1418. package/src/prompts/tools/ask.md +29 -0
  1419. package/src/prompts/tools/ast-edit.md +39 -0
  1420. package/src/prompts/tools/ast-grep.md +42 -0
  1421. package/src/prompts/tools/async-result.md +8 -0
  1422. package/src/prompts/tools/bash.md +39 -0
  1423. package/src/prompts/tools/browser.md +70 -0
  1424. package/src/prompts/tools/calculator.md +10 -0
  1425. package/src/prompts/tools/checkpoint.md +16 -0
  1426. package/src/prompts/tools/create-goal.md +3 -0
  1427. package/src/prompts/tools/debug.md +33 -0
  1428. package/src/prompts/tools/eval.md +75 -0
  1429. package/src/prompts/tools/find.md +34 -0
  1430. package/src/prompts/tools/get-goal.md +3 -0
  1431. package/src/prompts/tools/github.md +20 -0
  1432. package/src/prompts/tools/goal.md +18 -0
  1433. package/src/prompts/tools/hashline.md +130 -0
  1434. package/src/prompts/tools/image-gen.md +7 -0
  1435. package/src/prompts/tools/inspect-image-system.md +20 -0
  1436. package/src/prompts/tools/inspect-image.md +32 -0
  1437. package/src/prompts/tools/irc.md +49 -0
  1438. package/src/prompts/tools/job.md +19 -0
  1439. package/src/prompts/tools/lsp.md +42 -0
  1440. package/src/prompts/tools/patch.md +70 -0
  1441. package/src/prompts/tools/read.md +82 -0
  1442. package/src/prompts/tools/recall.md +5 -0
  1443. package/src/prompts/tools/recipe.md +16 -0
  1444. package/src/prompts/tools/reflect.md +5 -0
  1445. package/src/prompts/tools/render-mermaid.md +9 -0
  1446. package/src/prompts/tools/replace.md +36 -0
  1447. package/src/prompts/tools/resolve.md +9 -0
  1448. package/src/prompts/tools/retain.md +6 -0
  1449. package/src/prompts/tools/rewind.md +13 -0
  1450. package/src/prompts/tools/search-tool-bm25.md +33 -0
  1451. package/src/prompts/tools/search.md +25 -0
  1452. package/src/prompts/tools/ssh.md +35 -0
  1453. package/src/prompts/tools/subagent.md +21 -0
  1454. package/src/prompts/tools/task-summary.md +28 -0
  1455. package/src/prompts/tools/task.md +79 -0
  1456. package/src/prompts/tools/todo-write.md +50 -0
  1457. package/src/prompts/tools/update-goal.md +3 -0
  1458. package/src/prompts/tools/vim.md +98 -0
  1459. package/src/prompts/tools/web-search.md +10 -0
  1460. package/src/prompts/tools/write.md +14 -0
  1461. package/src/registry/agent-registry.ts +140 -0
  1462. package/src/runtime-mcp/client.ts +482 -0
  1463. package/src/runtime-mcp/config-writer.ts +225 -0
  1464. package/src/runtime-mcp/config.ts +365 -0
  1465. package/src/runtime-mcp/discoverable-tool-metadata.ts +25 -0
  1466. package/src/runtime-mcp/index.ts +29 -0
  1467. package/src/runtime-mcp/json-rpc.ts +84 -0
  1468. package/src/runtime-mcp/loader.ts +124 -0
  1469. package/src/runtime-mcp/manager.ts +1172 -0
  1470. package/src/runtime-mcp/oauth-discovery.ts +349 -0
  1471. package/src/runtime-mcp/oauth-flow.ts +407 -0
  1472. package/src/runtime-mcp/render.ts +123 -0
  1473. package/src/runtime-mcp/smithery-auth.ts +104 -0
  1474. package/src/runtime-mcp/smithery-connect.ts +145 -0
  1475. package/src/runtime-mcp/smithery-registry.ts +477 -0
  1476. package/src/runtime-mcp/tool-bridge.ts +416 -0
  1477. package/src/runtime-mcp/tool-cache.ts +117 -0
  1478. package/src/runtime-mcp/transports/http.ts +477 -0
  1479. package/src/runtime-mcp/transports/index.ts +6 -0
  1480. package/src/runtime-mcp/transports/stdio.ts +325 -0
  1481. package/src/runtime-mcp/types.ts +423 -0
  1482. package/src/sdk.ts +2064 -0
  1483. package/src/secrets/index.ts +116 -0
  1484. package/src/secrets/obfuscator.ts +277 -0
  1485. package/src/secrets/regex.ts +21 -0
  1486. package/src/session/agent-session.ts +8794 -0
  1487. package/src/session/agent-storage.ts +466 -0
  1488. package/src/session/artifacts.ts +135 -0
  1489. package/src/session/auth-broker-config.ts +102 -0
  1490. package/src/session/auth-storage.ts +23 -0
  1491. package/src/session/blob-store.ts +168 -0
  1492. package/src/session/client-bridge.ts +85 -0
  1493. package/src/session/history-storage.ts +311 -0
  1494. package/src/session/messages.ts +403 -0
  1495. package/src/session/session-dump-format.ts +209 -0
  1496. package/src/session/session-manager.ts +3333 -0
  1497. package/src/session/session-storage.ts +389 -0
  1498. package/src/session/streaming-output.ts +1093 -0
  1499. package/src/session/tool-choice-queue.ts +213 -0
  1500. package/src/session/yield-queue.ts +155 -0
  1501. package/src/setup/model-onboarding-guidance.ts +36 -0
  1502. package/src/setup/provider-onboarding.ts +195 -0
  1503. package/src/skill-state/active-state.ts +272 -0
  1504. package/src/slash-commands/acp-builtins.ts +46 -0
  1505. package/src/slash-commands/builtin-registry.ts +955 -0
  1506. package/src/slash-commands/helpers/context-report.ts +39 -0
  1507. package/src/slash-commands/helpers/format.ts +46 -0
  1508. package/src/slash-commands/helpers/mcp.ts +532 -0
  1509. package/src/slash-commands/helpers/parse.ts +85 -0
  1510. package/src/slash-commands/helpers/ssh.ts +195 -0
  1511. package/src/slash-commands/helpers/todo.ts +279 -0
  1512. package/src/slash-commands/helpers/usage-report.ts +91 -0
  1513. package/src/slash-commands/types.ts +125 -0
  1514. package/src/ssh/config-writer.ts +183 -0
  1515. package/src/ssh/connection-manager.ts +482 -0
  1516. package/src/ssh/ssh-executor.ts +133 -0
  1517. package/src/ssh/sshfs-mount.ts +140 -0
  1518. package/src/ssh/utils.ts +8 -0
  1519. package/src/stt/downloader.ts +71 -0
  1520. package/src/stt/index.ts +3 -0
  1521. package/src/stt/recorder.ts +351 -0
  1522. package/src/stt/setup.ts +52 -0
  1523. package/src/stt/stt-controller.ts +160 -0
  1524. package/src/stt/transcribe.py +70 -0
  1525. package/src/stt/transcriber.ts +91 -0
  1526. package/src/system-prompt.ts +581 -0
  1527. package/src/task/agents.ts +162 -0
  1528. package/src/task/commands.ts +135 -0
  1529. package/src/task/discovery.ts +130 -0
  1530. package/src/task/executor.ts +1564 -0
  1531. package/src/task/gjc-command.ts +26 -0
  1532. package/src/task/index.ts +1366 -0
  1533. package/src/task/name-generator.ts +1577 -0
  1534. package/src/task/output-manager.ts +107 -0
  1535. package/src/task/parallel.ts +116 -0
  1536. package/src/task/render.ts +1136 -0
  1537. package/src/task/simple-mode.ts +27 -0
  1538. package/src/task/subprocess-tool-registry.ts +88 -0
  1539. package/src/task/types.ts +315 -0
  1540. package/src/task/worktree.ts +506 -0
  1541. package/src/thinking.ts +87 -0
  1542. package/src/tool-discovery/tool-index.ts +400 -0
  1543. package/src/tools/archive-reader.ts +321 -0
  1544. package/src/tools/ask.ts +790 -0
  1545. package/src/tools/ast-edit.ts +542 -0
  1546. package/src/tools/ast-grep.ts +423 -0
  1547. package/src/tools/auto-generated-guard.ts +305 -0
  1548. package/src/tools/bash-command-fixup.ts +37 -0
  1549. package/src/tools/bash-interactive.ts +388 -0
  1550. package/src/tools/bash-interceptor.ts +67 -0
  1551. package/src/tools/bash-pty-selection.ts +14 -0
  1552. package/src/tools/bash-skill-urls.ts +248 -0
  1553. package/src/tools/bash.ts +1061 -0
  1554. package/src/tools/browser/attach.ts +175 -0
  1555. package/src/tools/browser/launch.ts +651 -0
  1556. package/src/tools/browser/readable.ts +95 -0
  1557. package/src/tools/browser/registry.ts +194 -0
  1558. package/src/tools/browser/render.ts +212 -0
  1559. package/src/tools/browser/tab-protocol.ts +105 -0
  1560. package/src/tools/browser/tab-supervisor.ts +577 -0
  1561. package/src/tools/browser/tab-worker-entry.ts +21 -0
  1562. package/src/tools/browser/tab-worker.ts +1054 -0
  1563. package/src/tools/browser.ts +301 -0
  1564. package/src/tools/calculator.ts +540 -0
  1565. package/src/tools/checkpoint.ts +134 -0
  1566. package/src/tools/conflict-detect.ts +672 -0
  1567. package/src/tools/context.ts +39 -0
  1568. package/src/tools/debug.ts +1014 -0
  1569. package/src/tools/eval.ts +1101 -0
  1570. package/src/tools/fetch.ts +1482 -0
  1571. package/src/tools/file-recorder.ts +35 -0
  1572. package/src/tools/find.ts +540 -0
  1573. package/src/tools/fs-cache-invalidation.ts +28 -0
  1574. package/src/tools/gh-format.ts +12 -0
  1575. package/src/tools/gh-renderer.ts +428 -0
  1576. package/src/tools/gh.ts +3499 -0
  1577. package/src/tools/github-cache.ts +548 -0
  1578. package/src/tools/grouped-file-output.ts +96 -0
  1579. package/src/tools/hindsight-recall.ts +68 -0
  1580. package/src/tools/hindsight-reflect.ts +57 -0
  1581. package/src/tools/hindsight-retain.ts +56 -0
  1582. package/src/tools/image-gen.ts +1248 -0
  1583. package/src/tools/index.ts +519 -0
  1584. package/src/tools/inspect-image-renderer.ts +103 -0
  1585. package/src/tools/inspect-image.ts +165 -0
  1586. package/src/tools/irc.ts +239 -0
  1587. package/src/tools/job.ts +520 -0
  1588. package/src/tools/json-tree.ts +243 -0
  1589. package/src/tools/jtd-to-json-schema.ts +219 -0
  1590. package/src/tools/jtd-to-typescript.ts +136 -0
  1591. package/src/tools/jtd-utils.ts +102 -0
  1592. package/src/tools/list-limit.ts +40 -0
  1593. package/src/tools/match-line-format.ts +22 -0
  1594. package/src/tools/output-meta.ts +754 -0
  1595. package/src/tools/path-utils.ts +739 -0
  1596. package/src/tools/plan-mode-guard.ts +68 -0
  1597. package/src/tools/puppeteer/00_stealth_tampering.txt +63 -0
  1598. package/src/tools/puppeteer/01_stealth_activity.txt +20 -0
  1599. package/src/tools/puppeteer/02_stealth_hairline.txt +11 -0
  1600. package/src/tools/puppeteer/03_stealth_botd.txt +384 -0
  1601. package/src/tools/puppeteer/04_stealth_iframe.txt +81 -0
  1602. package/src/tools/puppeteer/05_stealth_webgl.txt +75 -0
  1603. package/src/tools/puppeteer/06_stealth_screen.txt +72 -0
  1604. package/src/tools/puppeteer/07_stealth_fonts.txt +97 -0
  1605. package/src/tools/puppeteer/08_stealth_audio.txt +51 -0
  1606. package/src/tools/puppeteer/09_stealth_locale.txt +46 -0
  1607. package/src/tools/puppeteer/10_stealth_plugins.txt +206 -0
  1608. package/src/tools/puppeteer/11_stealth_hardware.txt +8 -0
  1609. package/src/tools/puppeteer/12_stealth_codecs.txt +40 -0
  1610. package/src/tools/puppeteer/13_stealth_worker.txt +74 -0
  1611. package/src/tools/read.ts +2332 -0
  1612. package/src/tools/recipe/index.ts +80 -0
  1613. package/src/tools/recipe/render.ts +19 -0
  1614. package/src/tools/recipe/runner.ts +219 -0
  1615. package/src/tools/recipe/runners/cargo.ts +131 -0
  1616. package/src/tools/recipe/runners/index.ts +8 -0
  1617. package/src/tools/recipe/runners/just.ts +73 -0
  1618. package/src/tools/recipe/runners/make.ts +101 -0
  1619. package/src/tools/recipe/runners/pkg.ts +167 -0
  1620. package/src/tools/recipe/runners/task.ts +72 -0
  1621. package/src/tools/render-mermaid.ts +68 -0
  1622. package/src/tools/render-utils.ts +774 -0
  1623. package/src/tools/renderers.ts +75 -0
  1624. package/src/tools/resolve.ts +258 -0
  1625. package/src/tools/review.ts +252 -0
  1626. package/src/tools/search-tool-bm25.ts +360 -0
  1627. package/src/tools/search.ts +786 -0
  1628. package/src/tools/sqlite-reader.ts +736 -0
  1629. package/src/tools/ssh.ts +310 -0
  1630. package/src/tools/subagent.ts +312 -0
  1631. package/src/tools/todo-write.ts +695 -0
  1632. package/src/tools/tool-errors.ts +62 -0
  1633. package/src/tools/tool-result.ts +86 -0
  1634. package/src/tools/tool-timeouts.ts +30 -0
  1635. package/src/tools/vim.ts +949 -0
  1636. package/src/tools/write.ts +953 -0
  1637. package/src/tools/yield.ts +268 -0
  1638. package/src/tui/code-cell.ts +201 -0
  1639. package/src/tui/file-list.ts +55 -0
  1640. package/src/tui/hyperlink.ts +126 -0
  1641. package/src/tui/index.ts +12 -0
  1642. package/src/tui/output-block.ts +150 -0
  1643. package/src/tui/status-line.ts +39 -0
  1644. package/src/tui/tree-list.ts +84 -0
  1645. package/src/tui/types.ts +15 -0
  1646. package/src/tui/utils.ts +103 -0
  1647. package/src/utils/changelog.ts +98 -0
  1648. package/src/utils/clipboard.ts +156 -0
  1649. package/src/utils/command-args.ts +76 -0
  1650. package/src/utils/commit-message-generator.ts +142 -0
  1651. package/src/utils/edit-mode.ts +42 -0
  1652. package/src/utils/event-bus.ts +33 -0
  1653. package/src/utils/external-editor.ts +65 -0
  1654. package/src/utils/file-display-mode.ts +45 -0
  1655. package/src/utils/file-mentions.ts +376 -0
  1656. package/src/utils/git.ts +1536 -0
  1657. package/src/utils/image-loading.ts +102 -0
  1658. package/src/utils/image-resize.ts +309 -0
  1659. package/src/utils/lang-from-path.ts +239 -0
  1660. package/src/utils/markit.ts +89 -0
  1661. package/src/utils/open.ts +20 -0
  1662. package/src/utils/session-color.ts +43 -0
  1663. package/src/utils/shell-snapshot.ts +187 -0
  1664. package/src/utils/sixel.ts +69 -0
  1665. package/src/utils/title-generator.ts +223 -0
  1666. package/src/utils/tool-choice.ts +33 -0
  1667. package/src/utils/tools-manager.ts +363 -0
  1668. package/src/vim/buffer.ts +309 -0
  1669. package/src/vim/commands.ts +382 -0
  1670. package/src/vim/engine.ts +2409 -0
  1671. package/src/vim/parser.ts +134 -0
  1672. package/src/vim/render.ts +252 -0
  1673. package/src/vim/types.ts +197 -0
  1674. package/src/web/kagi.ts +183 -0
  1675. package/src/web/parallel.ts +349 -0
  1676. package/src/web/scrapers/artifacthub.ts +207 -0
  1677. package/src/web/scrapers/arxiv.ts +83 -0
  1678. package/src/web/scrapers/aur.ts +162 -0
  1679. package/src/web/scrapers/biorxiv.ts +133 -0
  1680. package/src/web/scrapers/bluesky.ts +262 -0
  1681. package/src/web/scrapers/brew.ts +172 -0
  1682. package/src/web/scrapers/cheatsh.ts +68 -0
  1683. package/src/web/scrapers/chocolatey.ts +196 -0
  1684. package/src/web/scrapers/choosealicense.ts +95 -0
  1685. package/src/web/scrapers/cisa-kev.ts +87 -0
  1686. package/src/web/scrapers/clojars.ts +154 -0
  1687. package/src/web/scrapers/coingecko.ts +177 -0
  1688. package/src/web/scrapers/crates-io.ts +97 -0
  1689. package/src/web/scrapers/crossref.ts +136 -0
  1690. package/src/web/scrapers/devto.ts +147 -0
  1691. package/src/web/scrapers/discogs.ts +306 -0
  1692. package/src/web/scrapers/discourse.ts +197 -0
  1693. package/src/web/scrapers/dockerhub.ts +138 -0
  1694. package/src/web/scrapers/docs-rs.ts +653 -0
  1695. package/src/web/scrapers/fdroid.ts +134 -0
  1696. package/src/web/scrapers/firefox-addons.ts +191 -0
  1697. package/src/web/scrapers/flathub.ts +223 -0
  1698. package/src/web/scrapers/github-gist.ts +58 -0
  1699. package/src/web/scrapers/github.ts +452 -0
  1700. package/src/web/scrapers/gitlab.ts +401 -0
  1701. package/src/web/scrapers/go-pkg.ts +266 -0
  1702. package/src/web/scrapers/hackage.ts +140 -0
  1703. package/src/web/scrapers/hackernews.ts +189 -0
  1704. package/src/web/scrapers/hex.ts +105 -0
  1705. package/src/web/scrapers/huggingface.ts +321 -0
  1706. package/src/web/scrapers/iacr.ts +89 -0
  1707. package/src/web/scrapers/index.ts +252 -0
  1708. package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
  1709. package/src/web/scrapers/lemmy.ts +203 -0
  1710. package/src/web/scrapers/lobsters.ts +175 -0
  1711. package/src/web/scrapers/mastodon.ts +292 -0
  1712. package/src/web/scrapers/maven.ts +138 -0
  1713. package/src/web/scrapers/mdn.ts +173 -0
  1714. package/src/web/scrapers/metacpan.ts +222 -0
  1715. package/src/web/scrapers/musicbrainz.ts +250 -0
  1716. package/src/web/scrapers/npm.ts +98 -0
  1717. package/src/web/scrapers/nuget.ts +183 -0
  1718. package/src/web/scrapers/nvd.ts +222 -0
  1719. package/src/web/scrapers/ollama.ts +239 -0
  1720. package/src/web/scrapers/open-vsx.ts +106 -0
  1721. package/src/web/scrapers/opencorporates.ts +292 -0
  1722. package/src/web/scrapers/openlibrary.ts +336 -0
  1723. package/src/web/scrapers/orcid.ts +286 -0
  1724. package/src/web/scrapers/osv.ts +176 -0
  1725. package/src/web/scrapers/packagist.ts +160 -0
  1726. package/src/web/scrapers/pub-dev.ts +143 -0
  1727. package/src/web/scrapers/pubmed.ts +211 -0
  1728. package/src/web/scrapers/pypi.ts +112 -0
  1729. package/src/web/scrapers/rawg.ts +110 -0
  1730. package/src/web/scrapers/readthedocs.ts +120 -0
  1731. package/src/web/scrapers/reddit.ts +95 -0
  1732. package/src/web/scrapers/repology.ts +251 -0
  1733. package/src/web/scrapers/rfc.ts +201 -0
  1734. package/src/web/scrapers/rubygems.ts +103 -0
  1735. package/src/web/scrapers/searchcode.ts +189 -0
  1736. package/src/web/scrapers/sec-edgar.ts +261 -0
  1737. package/src/web/scrapers/semantic-scholar.ts +171 -0
  1738. package/src/web/scrapers/snapcraft.ts +187 -0
  1739. package/src/web/scrapers/sourcegraph.ts +336 -0
  1740. package/src/web/scrapers/spdx.ts +108 -0
  1741. package/src/web/scrapers/spotify.ts +198 -0
  1742. package/src/web/scrapers/stackoverflow.ts +120 -0
  1743. package/src/web/scrapers/terraform.ts +277 -0
  1744. package/src/web/scrapers/tldr.ts +47 -0
  1745. package/src/web/scrapers/twitter.ts +93 -0
  1746. package/src/web/scrapers/types.ts +318 -0
  1747. package/src/web/scrapers/utils.ts +109 -0
  1748. package/src/web/scrapers/vimeo.ts +133 -0
  1749. package/src/web/scrapers/vscode-marketplace.ts +187 -0
  1750. package/src/web/scrapers/w3c.ts +156 -0
  1751. package/src/web/scrapers/wikidata.ts +344 -0
  1752. package/src/web/scrapers/wikipedia.ts +84 -0
  1753. package/src/web/scrapers/youtube.ts +319 -0
  1754. package/src/web/search/index.ts +288 -0
  1755. package/src/web/search/provider.ts +173 -0
  1756. package/src/web/search/providers/anthropic.ts +302 -0
  1757. package/src/web/search/providers/base.ts +71 -0
  1758. package/src/web/search/providers/brave.ts +149 -0
  1759. package/src/web/search/providers/codex.ts +556 -0
  1760. package/src/web/search/providers/exa.ts +193 -0
  1761. package/src/web/search/providers/gemini.ts +455 -0
  1762. package/src/web/search/providers/jina.ts +101 -0
  1763. package/src/web/search/providers/kagi.ts +75 -0
  1764. package/src/web/search/providers/kimi.ts +171 -0
  1765. package/src/web/search/providers/parallel.ts +210 -0
  1766. package/src/web/search/providers/perplexity.ts +575 -0
  1767. package/src/web/search/providers/searxng.ts +309 -0
  1768. package/src/web/search/providers/synthetic.ts +108 -0
  1769. package/src/web/search/providers/tavily.ts +173 -0
  1770. package/src/web/search/providers/utils.ts +128 -0
  1771. package/src/web/search/providers/zai.ts +320 -0
  1772. package/src/web/search/render.ts +299 -0
  1773. package/src/web/search/types.ts +436 -0
  1774. package/src/web/search/utils.ts +17 -0
  1775. package/src/workspace-tree.ts +286 -0
@@ -0,0 +1,2409 @@
1
+ import type { FileDiagnosticsResult } from "../lsp";
2
+ import { snapshotEqual, type VimBuffer } from "./buffer";
3
+ import { parseExCommand } from "./commands";
4
+ import { replayTokens } from "./parser";
5
+ import type {
6
+ Position,
7
+ VimBufferSnapshot,
8
+ VimInputMode,
9
+ VimKeyToken,
10
+ VimLineRange,
11
+ VimLoadedFile,
12
+ VimPendingInput,
13
+ VimRegister,
14
+ VimSearchState,
15
+ VimSelection,
16
+ VimUndoEntry,
17
+ } from "./types";
18
+ import { clonePosition, maxPosition, minPosition, toPublicMode, VimInputError as VimError } from "./types";
19
+
20
+ export interface VimSaveResult {
21
+ loaded: VimLoadedFile;
22
+ diagnostics?: FileDiagnosticsResult;
23
+ }
24
+
25
+ export interface VimEngineCallbacks {
26
+ beforeMutate: (buffer: VimBuffer) => Promise<void>;
27
+ loadBuffer: (path: string) => Promise<VimLoadedFile>;
28
+ saveBuffer: (buffer: VimBuffer, options?: { force?: boolean }) => Promise<VimSaveResult>;
29
+ }
30
+
31
+ interface PendingChange {
32
+ before: VimBufferSnapshot;
33
+ tokens: string[];
34
+ moveCursorLeftOnEscape: boolean;
35
+ inserted: boolean;
36
+ }
37
+
38
+ interface MotionResult {
39
+ nextIndex: number;
40
+ target: Position;
41
+ inclusive?: boolean;
42
+ linewise?: boolean;
43
+ range?: { start: number; end: number; linewise?: boolean };
44
+ }
45
+
46
+ const WORD_CHAR = /[A-Za-z0-9_]/;
47
+ const DEFAULT_VIEWPORT_HEIGHT = 10;
48
+ const BRACKET_PAIRS = new Map<string, string>([
49
+ ["(", ")"],
50
+ ["[", "]"],
51
+ ["{", "}"],
52
+ ["<", ">"],
53
+ ]);
54
+ const CLOSING_BRACKETS = new Map<string, string>(
55
+ Array.from(BRACKET_PAIRS.entries()).map(([open, close]) => [close, open]),
56
+ );
57
+ const NOOP_Z_COMMANDS = new Set(["a", "A", "c", "C", "m", "M", "o", "O", "r", "R", "v", "x", "X"]);
58
+
59
+ function escapeRegex(value: string): string {
60
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
61
+ }
62
+
63
+ function isWhitespace(char: string): boolean {
64
+ return /\s/.test(char);
65
+ }
66
+
67
+ function isWordChar(char: string): boolean {
68
+ return WORD_CHAR.test(char);
69
+ }
70
+
71
+ function wordCategory(char: string, bigWord: boolean): "space" | "word" | "punct" {
72
+ if (char.length === 0 || isWhitespace(char)) {
73
+ return "space";
74
+ }
75
+ if (bigWord) {
76
+ return "word";
77
+ }
78
+ return isWordChar(char) ? "word" : "punct";
79
+ }
80
+
81
+ function decodeReplacement(replacement: string): string {
82
+ return replacement.replace(/\\\//g, "/").replace(/\\\\/g, "\\");
83
+ }
84
+
85
+ function literalTextToReplayTokens(text: string): string[] {
86
+ const tokens: string[] = [];
87
+ for (const char of text) {
88
+ if (char === "\n") {
89
+ tokens.push("CR");
90
+ continue;
91
+ }
92
+ if (char === "\t") {
93
+ tokens.push("Tab");
94
+ continue;
95
+ }
96
+ tokens.push(char);
97
+ }
98
+ return tokens;
99
+ }
100
+
101
+ // Convert a vim-style search pattern to a JavaScript RegExp.
102
+ // In vim's default ("magic") mode, (, ), {, }, |, + are literal unless backslash-escaped.
103
+ // In JS regex these are metacharacters. Swap the escaping so bare chars are literal
104
+ // and \( etc. become regex groups.
105
+ function vimPatternToJsRegex(pattern: string): string {
106
+ return pattern.replace(/\\([(){}|+])|([(){}|+])/g, (_match, escaped, bare) => {
107
+ if (escaped) return escaped; // \( -> ( (regex group)
108
+ return `\\${bare}`; // ( -> \( (literal paren)
109
+ });
110
+ }
111
+
112
+ function createSearchRegex(pattern: string, flags = "g"): RegExp {
113
+ try {
114
+ return new RegExp(vimPatternToJsRegex(pattern), flags);
115
+ } catch {
116
+ return new RegExp(escapeRegex(pattern), flags);
117
+ }
118
+ }
119
+
120
+ function detectIndentUnit(lines: string[]): string {
121
+ for (const line of lines) {
122
+ if (line.startsWith("\t")) {
123
+ return "\t";
124
+ }
125
+ if (line.startsWith(" ")) {
126
+ return " ";
127
+ }
128
+ }
129
+ return "\t";
130
+ }
131
+
132
+ function normalizeRange(start: number, end: number): { start: number; end: number } {
133
+ return {
134
+ start: Math.min(start, end),
135
+ end: Math.max(start, end),
136
+ };
137
+ }
138
+
139
+ function selectionFromAnchor(buffer: VimBuffer, anchor: Position, linewise: boolean): VimSelection {
140
+ if (linewise) {
141
+ const startLine = Math.min(anchor.line, buffer.cursor.line);
142
+ const endLine = Math.max(anchor.line, buffer.cursor.line);
143
+ return {
144
+ kind: "line",
145
+ start: { line: startLine + 1, col: 1 },
146
+ end: { line: endLine + 1, col: buffer.getLine(endLine).length + 1 },
147
+ };
148
+ }
149
+ const start = minPosition(anchor, buffer.cursor);
150
+ const end = maxPosition(anchor, buffer.cursor);
151
+ return {
152
+ kind: "char",
153
+ start: { line: start.line + 1, col: start.col + 1 },
154
+ end: { line: end.line + 1, col: end.col + 1 },
155
+ };
156
+ }
157
+
158
+ function expandVisualOffsets(
159
+ buffer: VimBuffer,
160
+ anchor: Position,
161
+ linewise: boolean,
162
+ ): { start: number; end: number; linewise: boolean } {
163
+ if (linewise) {
164
+ const startLine = Math.min(anchor.line, buffer.cursor.line);
165
+ const endLine = Math.max(anchor.line, buffer.cursor.line);
166
+ const startOffset = buffer.positionToOffset({ line: startLine, col: 0 });
167
+ const endOffset =
168
+ endLine >= buffer.lastLineIndex()
169
+ ? buffer.getText().length
170
+ : buffer.positionToOffset({ line: endLine + 1, col: 0 });
171
+ return { start: startOffset, end: endOffset, linewise: true };
172
+ }
173
+ const anchorOffset = buffer.positionToOffset(anchor);
174
+ const cursorOffset = buffer.positionToOffset(buffer.cursor);
175
+ const { start, end } = normalizeRange(anchorOffset, cursorOffset);
176
+ return { start, end: end + 1, linewise: false };
177
+ }
178
+
179
+ function nextWordStart(text: string, offset: number, bigWord: boolean): number {
180
+ let index = Math.min(Math.max(offset, 0), text.length);
181
+ if (index >= text.length) {
182
+ return text.length;
183
+ }
184
+
185
+ const currentCategory = wordCategory(text[index] ?? "", bigWord);
186
+ if (currentCategory === "space") {
187
+ while (index < text.length && wordCategory(text[index] ?? "", bigWord) === "space") {
188
+ index += 1;
189
+ }
190
+ return index;
191
+ }
192
+
193
+ while (index < text.length && wordCategory(text[index] ?? "", bigWord) === currentCategory) {
194
+ index += 1;
195
+ }
196
+ while (index < text.length && wordCategory(text[index] ?? "", bigWord) === "space") {
197
+ index += 1;
198
+ }
199
+ return index;
200
+ }
201
+
202
+ function previousWordStart(text: string, offset: number, bigWord: boolean): number {
203
+ let index = Math.min(Math.max(offset - 1, 0), text.length);
204
+ while (index > 0 && wordCategory(text[index] ?? "", bigWord) === "space") {
205
+ index -= 1;
206
+ }
207
+ const category = wordCategory(text[index] ?? "", bigWord);
208
+ while (index > 0 && wordCategory(text[index - 1] ?? "", bigWord) === category) {
209
+ index -= 1;
210
+ }
211
+ return index;
212
+ }
213
+
214
+ function endOfWord(text: string, offset: number, bigWord: boolean): number {
215
+ let index = Math.min(Math.max(offset, 0), text.length);
216
+ while (index < text.length && wordCategory(text[index] ?? "", bigWord) === "space") {
217
+ index += 1;
218
+ }
219
+ const category = wordCategory(text[index] ?? "", bigWord);
220
+ while (index < text.length && wordCategory(text[index] ?? "", bigWord) === category) {
221
+ index += 1;
222
+ }
223
+ return Math.max(0, index - 1);
224
+ }
225
+
226
+ function endOfPreviousWord(text: string, offset: number, bigWord: boolean): number {
227
+ if (text.length === 0) {
228
+ return 0;
229
+ }
230
+
231
+ let index = Math.min(Math.max(offset - 1, 0), text.length - 1);
232
+ while (index >= 0 && wordCategory(text[index] ?? "", bigWord) === "space") {
233
+ index -= 1;
234
+ }
235
+ if (index < 0) {
236
+ return 0;
237
+ }
238
+
239
+ const currentCategory = wordCategory(text[index] ?? "", bigWord);
240
+ while (index >= 0 && wordCategory(text[index] ?? "", bigWord) === currentCategory) {
241
+ index -= 1;
242
+ }
243
+ while (index >= 0 && wordCategory(text[index] ?? "", bigWord) === "space") {
244
+ index -= 1;
245
+ }
246
+
247
+ return Math.max(0, index);
248
+ }
249
+
250
+ function toggleCase(text: string): string {
251
+ let toggled = "";
252
+ for (const char of text) {
253
+ if (char >= "a" && char <= "z") {
254
+ toggled += char.toUpperCase();
255
+ continue;
256
+ }
257
+ if (char >= "A" && char <= "Z") {
258
+ toggled += char.toLowerCase();
259
+ continue;
260
+ }
261
+ toggled += char;
262
+ }
263
+ return toggled;
264
+ }
265
+
266
+ function lastNonBlankColumn(line: string): number {
267
+ for (let index = line.length - 1; index >= 0; index -= 1) {
268
+ if (!isWhitespace(line[index] ?? "")) {
269
+ return index;
270
+ }
271
+ }
272
+ return 0;
273
+ }
274
+
275
+ function findParagraphStart(lines: string[], line: number): number {
276
+ let index = Math.max(0, line - 1);
277
+ while (index > 0 && lines[index]!.trim().length > 0) {
278
+ index -= 1;
279
+ }
280
+ while (index > 0 && lines[index - 1]!.trim().length === 0) {
281
+ index -= 1;
282
+ }
283
+ return index;
284
+ }
285
+
286
+ function findParagraphEnd(lines: string[], line: number): number {
287
+ let index = Math.min(lines.length - 1, line + 1);
288
+ while (index < lines.length - 1 && lines[index]!.trim().length > 0) {
289
+ index += 1;
290
+ }
291
+ while (index < lines.length - 1 && lines[index + 1]!.trim().length === 0) {
292
+ index += 1;
293
+ }
294
+ return index;
295
+ }
296
+
297
+ function cloneUndoStack(stack: VimUndoEntry[]): VimUndoEntry[] {
298
+ return stack.map(entry => ({
299
+ before: {
300
+ ...entry.before,
301
+ lines: [...entry.before.lines],
302
+ cursor: clonePosition(entry.before.cursor),
303
+ baseFingerprint: entry.before.baseFingerprint ? { ...entry.before.baseFingerprint } : null,
304
+ },
305
+ after: {
306
+ ...entry.after,
307
+ lines: [...entry.after.lines],
308
+ cursor: clonePosition(entry.after.cursor),
309
+ baseFingerprint: entry.after.baseFingerprint ? { ...entry.after.baseFingerprint } : null,
310
+ },
311
+ }));
312
+ }
313
+
314
+ export class VimEngine {
315
+ buffer: VimBuffer;
316
+ inputMode: VimInputMode = "normal";
317
+ selectionAnchor: Position | null = null;
318
+ register: VimRegister = { kind: "char", text: "" };
319
+ lastSearch: VimSearchState | null = null;
320
+ lastCharFind: { char: string; mode: "f" | "F" | "t" | "T" } | null = null;
321
+ lastVisual: { anchor: Position; cursor: Position; mode: VimInputMode } | null = null;
322
+ lastCommand?: string;
323
+ statusMessage?: string;
324
+ diagnostics?: FileDiagnosticsResult;
325
+ viewportStart = 1;
326
+ closed = false;
327
+
328
+ #callbacks: VimEngineCallbacks;
329
+ #undoStack: VimUndoEntry[] = [];
330
+ #redoStack: VimUndoEntry[] = [];
331
+ #pendingInput = "";
332
+ #lastChangeTokens: string[] | null = null;
333
+ #pendingChange: PendingChange | null = null;
334
+ #stepCallback?: () => Promise<void>;
335
+
336
+ constructor(buffer: VimBuffer, callbacks: VimEngineCallbacks) {
337
+ this.buffer = buffer;
338
+ this.#callbacks = callbacks;
339
+ }
340
+
341
+ clone(callbacks?: Partial<VimEngineCallbacks>): VimEngine {
342
+ const next = new VimEngine(this.buffer.clone(), {
343
+ beforeMutate: callbacks?.beforeMutate ?? this.#callbacks.beforeMutate,
344
+ loadBuffer: callbacks?.loadBuffer ?? this.#callbacks.loadBuffer,
345
+ saveBuffer: callbacks?.saveBuffer ?? this.#callbacks.saveBuffer,
346
+ });
347
+ next.inputMode = this.inputMode;
348
+ next.selectionAnchor = this.selectionAnchor ? clonePosition(this.selectionAnchor) : null;
349
+ next.register = { ...this.register };
350
+ next.lastSearch = this.lastSearch ? { ...this.lastSearch } : null;
351
+ next.lastCharFind = this.lastCharFind ? { ...this.lastCharFind } : null;
352
+ next.lastVisual = this.lastVisual
353
+ ? {
354
+ anchor: clonePosition(this.lastVisual.anchor),
355
+ cursor: clonePosition(this.lastVisual.cursor),
356
+ mode: this.lastVisual.mode,
357
+ }
358
+ : null;
359
+ next.lastCommand = this.lastCommand;
360
+ next.statusMessage = this.statusMessage;
361
+ next.diagnostics = this.diagnostics;
362
+ next.viewportStart = this.viewportStart;
363
+ next.closed = this.closed;
364
+ next.#pendingInput = this.#pendingInput;
365
+ next.#lastChangeTokens = this.#lastChangeTokens ? [...this.#lastChangeTokens] : null;
366
+ next.#pendingChange = this.#pendingChange
367
+ ? {
368
+ before: {
369
+ ...this.#pendingChange.before,
370
+ lines: [...this.#pendingChange.before.lines],
371
+ cursor: clonePosition(this.#pendingChange.before.cursor),
372
+ baseFingerprint: this.#pendingChange.before.baseFingerprint
373
+ ? { ...this.#pendingChange.before.baseFingerprint }
374
+ : null,
375
+ },
376
+ tokens: [...this.#pendingChange.tokens],
377
+ moveCursorLeftOnEscape: this.#pendingChange.moveCursorLeftOnEscape,
378
+ inserted: this.#pendingChange.inserted,
379
+ }
380
+ : null;
381
+ next.#undoStack = cloneUndoStack(this.#undoStack);
382
+ next.#redoStack = cloneUndoStack(this.#redoStack);
383
+ return next;
384
+ }
385
+
386
+ getPublicMode() {
387
+ return toPublicMode(this.inputMode);
388
+ }
389
+
390
+ getSelection(): VimSelection | undefined {
391
+ if (this.selectionAnchor === null) {
392
+ return undefined;
393
+ }
394
+ return selectionFromAnchor(this.buffer, this.selectionAnchor, this.inputMode === "visual-line");
395
+ }
396
+
397
+ getPendingInput(): VimPendingInput | undefined {
398
+ switch (this.inputMode) {
399
+ case "insert":
400
+ return { kind: "insert", text: "" };
401
+ case "command":
402
+ case "search-forward":
403
+ case "search-backward":
404
+ return { kind: this.inputMode, text: this.#pendingInput };
405
+ default:
406
+ return undefined;
407
+ }
408
+ }
409
+
410
+ rollbackPendingInsert(): void {
411
+ if (this.#pendingChange) {
412
+ this.buffer.restore(this.#pendingChange.before);
413
+ this.#pendingChange = null;
414
+ }
415
+ this.inputMode = "normal";
416
+ this.selectionAnchor = null;
417
+ this.#pendingInput = "";
418
+ }
419
+
420
+ setCursor(line: number, col: number): void {
421
+ this.buffer.setCursor({ line, col });
422
+ }
423
+
424
+ async executeTokens(
425
+ tokens: readonly VimKeyToken[],
426
+ lastCommand?: string,
427
+ onStep?: () => Promise<void>,
428
+ ): Promise<void> {
429
+ const previousStepCallback = this.#stepCallback;
430
+ this.#stepCallback = onStep ?? previousStepCallback;
431
+ this.lastCommand = lastCommand;
432
+ this.statusMessage = undefined;
433
+ this.diagnostics = undefined;
434
+
435
+ try {
436
+ for (let index = 0; index < tokens.length; ) {
437
+ switch (this.inputMode) {
438
+ case "insert":
439
+ index = await this.#executeInsert(tokens, index);
440
+ break;
441
+ case "command":
442
+ case "search-forward":
443
+ case "search-backward":
444
+ index = await this.#executePrompt(tokens, index);
445
+ break;
446
+ case "visual":
447
+ case "visual-line":
448
+ index = await this.#executeVisual(tokens, index);
449
+ break;
450
+ default:
451
+ index = await this.#executeNormal(tokens, index);
452
+ break;
453
+ }
454
+ if (this.closed) {
455
+ break;
456
+ }
457
+ this.#ensureCursorVisible();
458
+ await this.#stepCallback?.();
459
+ }
460
+ } finally {
461
+ this.#stepCallback = previousStepCallback;
462
+ }
463
+ }
464
+
465
+ async close(force: boolean): Promise<void> {
466
+ if (this.buffer.modified && !force) {
467
+ throw new VimError("Unsaved changes; use force to discard");
468
+ }
469
+ this.closed = true;
470
+ this.statusMessage = `Closed ${this.buffer.displayPath}`;
471
+ }
472
+
473
+ #ensureCursorVisible(): void {
474
+ const line = this.buffer.cursor.line + 1;
475
+ if (line < this.viewportStart) {
476
+ this.viewportStart = line;
477
+ return;
478
+ }
479
+ const viewportEnd = this.viewportStart + DEFAULT_VIEWPORT_HEIGHT - 1;
480
+ if (line > viewportEnd) {
481
+ this.viewportStart = Math.max(1, line - DEFAULT_VIEWPORT_HEIGHT + 1);
482
+ }
483
+ }
484
+
485
+ centerViewportOnCursor(size = DEFAULT_VIEWPORT_HEIGHT): void {
486
+ const lineCount = Math.max(this.buffer.lineCount(), 1);
487
+ const clampedSize = Math.max(1, Math.min(size, lineCount));
488
+ const maxStart = Math.max(1, lineCount - clampedSize + 1);
489
+ this.viewportStart = Math.max(1, Math.min(this.buffer.cursor.line + 1 - Math.floor(clampedSize / 2), maxStart));
490
+ }
491
+
492
+ #clearSelection(): void {
493
+ if (this.selectionAnchor && (this.inputMode === "visual" || this.inputMode === "visual-line")) {
494
+ this.lastVisual = {
495
+ anchor: clonePosition(this.selectionAnchor),
496
+ cursor: clonePosition(this.buffer.cursor),
497
+ mode: this.inputMode,
498
+ };
499
+ }
500
+ this.selectionAnchor = null;
501
+ if (this.inputMode === "visual" || this.inputMode === "visual-line") {
502
+ this.inputMode = "normal";
503
+ }
504
+ }
505
+
506
+ async #ensureEditable(): Promise<void> {
507
+ await this.#callbacks.beforeMutate(this.buffer);
508
+ this.diagnostics = undefined;
509
+ this.statusMessage = undefined;
510
+ }
511
+
512
+ #pushUndo(entry: VimUndoEntry, changeTokens?: readonly string[]): void {
513
+ if (snapshotEqual(entry.before, entry.after)) {
514
+ return;
515
+ }
516
+ this.#undoStack.push(entry);
517
+ this.#redoStack = [];
518
+ if (changeTokens && changeTokens.length > 0) {
519
+ this.#lastChangeTokens = [...changeTokens];
520
+ }
521
+ }
522
+
523
+ #beginPendingChange(prefixTokens: readonly string[], moveCursorLeftOnEscape: boolean): void {
524
+ this.#pendingChange = {
525
+ before: this.buffer.createSnapshot(),
526
+ tokens: [...prefixTokens],
527
+ moveCursorLeftOnEscape,
528
+ inserted: false,
529
+ };
530
+ }
531
+
532
+ #markPendingInserted(): void {
533
+ if (this.#pendingChange) {
534
+ this.#pendingChange.inserted = true;
535
+ }
536
+ }
537
+
538
+ #commitPendingChange(): void {
539
+ if (!this.#pendingChange) {
540
+ return;
541
+ }
542
+ const entry: VimUndoEntry = {
543
+ before: this.#pendingChange.before,
544
+ after: this.buffer.createSnapshot(),
545
+ };
546
+ this.#pushUndo(entry, this.#pendingChange.tokens);
547
+ this.#pendingChange = null;
548
+ }
549
+
550
+ async #applyAtomicChange(tokens: readonly string[], mutator: () => void): Promise<void> {
551
+ await this.#ensureEditable();
552
+ const before = this.buffer.createSnapshot();
553
+ mutator();
554
+ this.buffer.modified = true;
555
+ this.#pushUndo({ before, after: this.buffer.createSnapshot() }, tokens);
556
+ }
557
+
558
+ async #startInsertChange(
559
+ tokens: readonly string[],
560
+ mutator?: () => void,
561
+ moveCursorLeftOnEscape = true,
562
+ ): Promise<void> {
563
+ await this.#ensureEditable();
564
+ this.#beginPendingChange(tokens, moveCursorLeftOnEscape);
565
+ mutator?.();
566
+ this.buffer.modified = true;
567
+ this.inputMode = "insert";
568
+ }
569
+
570
+ async #executePrompt(tokens: readonly VimKeyToken[], index: number): Promise<number> {
571
+ const token = tokens[index]!;
572
+ if (token.value === "Esc") {
573
+ this.#pendingInput = "";
574
+ this.inputMode = "normal";
575
+ return index + 1;
576
+ }
577
+ if (token.value === "BS") {
578
+ this.#pendingInput = this.#pendingInput.slice(0, -1);
579
+ return index + 1;
580
+ }
581
+ if (token.value !== "CR") {
582
+ this.#pendingInput += token.value === "Tab" ? "\t" : token.value;
583
+ return index + 1;
584
+ }
585
+
586
+ const input = this.#pendingInput;
587
+ this.#pendingInput = "";
588
+ const mode = this.inputMode;
589
+ this.inputMode = "normal";
590
+ if (mode === "command") {
591
+ await this.#executeEx(input);
592
+ } else {
593
+ await this.#runSearch(input, mode === "search-forward" ? 1 : -1, true);
594
+ }
595
+ return index + 1;
596
+ }
597
+
598
+ #exitInsertMode(): void {
599
+ if (this.#pendingChange) {
600
+ this.#pendingChange.tokens.push("Esc");
601
+ if (this.#pendingChange.moveCursorLeftOnEscape && this.#pendingChange.inserted && this.buffer.cursor.col > 0) {
602
+ this.buffer.setCursor({ line: this.buffer.cursor.line, col: this.buffer.cursor.col - 1 });
603
+ }
604
+ }
605
+ this.inputMode = "normal";
606
+ this.#commitPendingChange();
607
+ }
608
+
609
+ async applyLiteralInsert(text: string, exitInsertMode: boolean): Promise<void> {
610
+ if (this.inputMode !== "insert" || !this.#pendingChange) {
611
+ throw new VimError("Insert payload requires INSERT mode.");
612
+ }
613
+
614
+ if (text.length > 0) {
615
+ const offset = this.buffer.currentOffset();
616
+ this.buffer.replaceOffsets(offset, offset, text, offset + text.length);
617
+ this.buffer.modified = true;
618
+ if (text.includes("\n")) {
619
+ this.buffer.trailingNewline = this.buffer.trailingNewline || text.endsWith("\n");
620
+ }
621
+ this.#pendingChange.tokens.push(...literalTextToReplayTokens(text));
622
+ this.#markPendingInserted();
623
+ }
624
+
625
+ if (exitInsertMode) {
626
+ this.#exitInsertMode();
627
+ }
628
+ }
629
+
630
+ async #executeInsert(tokens: readonly VimKeyToken[], index: number): Promise<number> {
631
+ const token = tokens[index]!;
632
+ if (token.value === "Esc") {
633
+ this.#exitInsertMode();
634
+ return index + 1;
635
+ }
636
+ if (token.value === "CR") {
637
+ const offset = this.buffer.currentOffset();
638
+ this.buffer.replaceOffsets(offset, offset, "\n", offset + 1);
639
+ this.buffer.modified = true;
640
+ this.buffer.trailingNewline = true;
641
+ this.#pendingChange?.tokens.push(token.value);
642
+ this.#markPendingInserted();
643
+ return index + 1;
644
+ }
645
+ if (token.value === "BS") {
646
+ const offset = this.buffer.currentOffset();
647
+ if (offset > 0) {
648
+ this.buffer.deleteOffsets(offset - 1, offset);
649
+ this.buffer.modified = true;
650
+ this.#pendingChange?.tokens.push(token.value);
651
+ this.#markPendingInserted();
652
+ }
653
+ return index + 1;
654
+ }
655
+ if (token.value === "Tab") {
656
+ const offset = this.buffer.currentOffset();
657
+ this.buffer.replaceOffsets(offset, offset, "\t", offset + 1);
658
+ this.buffer.modified = true;
659
+ this.#pendingChange?.tokens.push(token.value);
660
+ this.#markPendingInserted();
661
+ return index + 1;
662
+ }
663
+ if (token.value === "C-w") {
664
+ const offset = this.buffer.currentOffset();
665
+ const text = this.buffer.getText();
666
+ let start = previousWordStart(text, offset, false);
667
+ if (start === offset && start > 0) {
668
+ start -= 1;
669
+ }
670
+ this.buffer.deleteOffsets(start, offset);
671
+ this.buffer.modified = true;
672
+ this.#pendingChange?.tokens.push(token.value);
673
+ this.#markPendingInserted();
674
+ return index + 1;
675
+ }
676
+ if (token.value === "C-u") {
677
+ const offset = this.buffer.currentOffset();
678
+ const lineStart = this.buffer.positionToOffset({ line: this.buffer.cursor.line, col: 0 });
679
+ if (offset > lineStart) {
680
+ this.buffer.deleteOffsets(lineStart, offset);
681
+ this.buffer.modified = true;
682
+ this.#pendingChange?.tokens.push(token.value);
683
+ this.#markPendingInserted();
684
+ }
685
+ return index + 1;
686
+ }
687
+ if (token.value === "C-o") {
688
+ // Execute one normal-mode command, then return to insert
689
+ const nextToken = tokens[index + 1];
690
+ if (!nextToken) {
691
+ return index + 1;
692
+ }
693
+ const savedMode = this.inputMode;
694
+ this.inputMode = "normal";
695
+ const nextIdx = await this.#executeNormal(tokens, index + 1);
696
+ this.inputMode = savedMode;
697
+ return nextIdx;
698
+ }
699
+
700
+ const insertText = token.value;
701
+ const offset = this.buffer.currentOffset();
702
+ this.buffer.replaceOffsets(offset, offset, insertText, offset + insertText.length);
703
+ this.buffer.modified = true;
704
+ this.#pendingChange?.tokens.push(token.value);
705
+ this.#markPendingInserted();
706
+ return index + 1;
707
+ }
708
+
709
+ async #executeVisual(tokens: readonly VimKeyToken[], index: number): Promise<number> {
710
+ const token = tokens[index]!;
711
+ if (token.value === "Esc") {
712
+ this.#clearSelection();
713
+ return index + 1;
714
+ }
715
+ if (token.value === "v") {
716
+ if (this.inputMode === "visual") {
717
+ this.#clearSelection();
718
+ }
719
+ return index + 1;
720
+ }
721
+ if (token.value === "V") {
722
+ this.inputMode = this.inputMode === "visual-line" ? "visual" : "visual-line";
723
+ return index + 1;
724
+ }
725
+ if (token.value === "o") {
726
+ if (this.selectionAnchor) {
727
+ const tmp = clonePosition(this.buffer.cursor);
728
+ this.buffer.setCursor(this.selectionAnchor);
729
+ this.selectionAnchor = tmp;
730
+ }
731
+ return index + 1;
732
+ }
733
+ if (token.value === "J") {
734
+ const visual = expandVisualOffsets(
735
+ this.buffer,
736
+ this.selectionAnchor ?? this.buffer.cursor,
737
+ this.inputMode === "visual-line",
738
+ );
739
+ const startLine = this.buffer.offsetToPosition(visual.start).line;
740
+ const endLine = this.buffer.offsetToPosition(Math.max(visual.start, visual.end - 1)).line;
741
+ await this.#applyAtomicChange(["J"], () => {
742
+ this.buffer.joinLines(startLine, endLine - startLine);
743
+ });
744
+ this.#clearSelection();
745
+ return index + 1;
746
+ }
747
+ if (token.value === "u" || token.value === "U") {
748
+ const visual = expandVisualOffsets(
749
+ this.buffer,
750
+ this.selectionAnchor ?? this.buffer.cursor,
751
+ this.inputMode === "visual-line",
752
+ );
753
+ await this.#applyAtomicChange([token.value], () => {
754
+ const original = this.buffer.getText().slice(visual.start, visual.end);
755
+ const transformed = token.value === "U" ? original.toUpperCase() : original.toLowerCase();
756
+ this.buffer.replaceOffsets(visual.start, visual.end, transformed, visual.start);
757
+ });
758
+ this.#clearSelection();
759
+ return index + 1;
760
+ }
761
+ if (token.value === "p" || token.value === "P") {
762
+ const visual = expandVisualOffsets(
763
+ this.buffer,
764
+ this.selectionAnchor ?? this.buffer.cursor,
765
+ this.inputMode === "visual-line",
766
+ );
767
+ await this.#applyAtomicChange([token.value], () => {
768
+ const removed = this.buffer.getText().slice(visual.start, visual.end);
769
+ const pasteText = this.register.text;
770
+ this.buffer.replaceOffsets(visual.start, visual.end, pasteText, visual.start + pasteText.length);
771
+ this.register = { kind: visual.linewise ? "line" : "char", text: removed };
772
+ });
773
+ this.#clearSelection();
774
+ return index + 1;
775
+ }
776
+ if (token.value === "g") {
777
+ const next = tokens[index + 1];
778
+ if (!next) {
779
+ throw new VimError("g requires a second key", token);
780
+ }
781
+ if (next.value === "J") {
782
+ const visual = expandVisualOffsets(
783
+ this.buffer,
784
+ this.selectionAnchor ?? this.buffer.cursor,
785
+ this.inputMode === "visual-line",
786
+ );
787
+ const startLine = this.buffer.offsetToPosition(visual.start).line;
788
+ const endLine = this.buffer.offsetToPosition(Math.max(visual.start, visual.end - 1)).line;
789
+ await this.#applyAtomicChange(["g", "J"], () => {
790
+ const start = this.buffer.clampLine(startLine);
791
+ const end = this.buffer.clampLine(endLine);
792
+ if (start < end) {
793
+ const joined = this.buffer.lines.slice(start, end + 1).join("");
794
+ this.buffer.lines.splice(start, end - start + 1, joined);
795
+ this.buffer.setCursor({ line: start, col: Math.max(0, joined.length - 1) });
796
+ }
797
+ });
798
+ this.#clearSelection();
799
+ return index + 2;
800
+ }
801
+ if (next.value === "u" || next.value === "U" || next.value === "~") {
802
+ const visual = expandVisualOffsets(
803
+ this.buffer,
804
+ this.selectionAnchor ?? this.buffer.cursor,
805
+ this.inputMode === "visual-line",
806
+ );
807
+ await this.#applyAtomicChange(["g", next.value], () => {
808
+ const original = this.buffer.getText().slice(visual.start, visual.end);
809
+ const transformed =
810
+ next.value === "u"
811
+ ? original.toLowerCase()
812
+ : next.value === "U"
813
+ ? original.toUpperCase()
814
+ : toggleCase(original);
815
+ this.buffer.replaceOffsets(visual.start, visual.end, transformed, visual.start);
816
+ });
817
+ this.#clearSelection();
818
+ return index + 2;
819
+ }
820
+ throw new VimError(`Unsupported g command: g${next.display}`, next);
821
+ }
822
+
823
+ const { count, hasCount, nextIndex } = this.#readCount(tokens, index);
824
+ const opToken = tokens[nextIndex];
825
+ if (!opToken) {
826
+ return nextIndex;
827
+ }
828
+
829
+ switch (opToken.value) {
830
+ case "d":
831
+ case "x":
832
+ case "X":
833
+ case "D":
834
+ case "y":
835
+ case "c":
836
+ case "s":
837
+ case "S":
838
+ case "C":
839
+ case ">":
840
+ case "<":
841
+ case "~": {
842
+ const visual = expandVisualOffsets(
843
+ this.buffer,
844
+ this.selectionAnchor ?? this.buffer.cursor,
845
+ this.inputMode === "visual-line",
846
+ );
847
+ const consumeExtraIndent =
848
+ (opToken.value === ">" || opToken.value === "<") && tokens[nextIndex + 1]?.value === opToken.value;
849
+ const operatorValue =
850
+ opToken.value === "x" || opToken.value === "X" || opToken.value === "D"
851
+ ? "d"
852
+ : opToken.value === "s" || opToken.value === "S" || opToken.value === "C"
853
+ ? "c"
854
+ : opToken.value;
855
+ const visualTokens = consumeExtraIndent ? [opToken.value, opToken.value] : [opToken.value];
856
+ await this.#applyVisualOperator(operatorValue, visual, count, visualTokens);
857
+ return nextIndex + visualTokens.length;
858
+ }
859
+ case "r": {
860
+ const replacement = tokens[nextIndex + 1];
861
+ if (!replacement || replacement.value.length !== 1) {
862
+ throw new VimError("Visual replace requires a literal character", opToken);
863
+ }
864
+ const visual = expandVisualOffsets(
865
+ this.buffer,
866
+ this.selectionAnchor ?? this.buffer.cursor,
867
+ this.inputMode === "visual-line",
868
+ );
869
+ await this.#applyAtomicChange(["r", replacement.value], () => {
870
+ const original = this.buffer.getText().slice(visual.start, visual.end);
871
+ let replaced = "";
872
+ for (const char of original) {
873
+ replaced += char === "\n" ? "\n" : replacement.value;
874
+ }
875
+ this.buffer.replaceOffsets(visual.start, visual.end, replaced, visual.start);
876
+ });
877
+ this.#clearSelection();
878
+ return nextIndex + 2;
879
+ }
880
+ default:
881
+ break;
882
+ }
883
+
884
+ const motion = this.#resolveMotion(tokens, nextIndex, count, hasCount);
885
+ this.buffer.setCursor(motion.target);
886
+ return motion.nextIndex;
887
+ }
888
+
889
+ async #applyVisualOperator(
890
+ operator: string,
891
+ visual: { start: number; end: number; linewise: boolean },
892
+ count: number,
893
+ tokens: readonly string[],
894
+ ): Promise<void> {
895
+ switch (operator) {
896
+ case "y": {
897
+ this.register = {
898
+ kind: visual.linewise ? "line" : "char",
899
+ text: this.buffer.getText().slice(visual.start, visual.end),
900
+ };
901
+ this.#clearSelection();
902
+ this.statusMessage = `Yanked ${count} selection${count === 1 ? "" : "s"}`;
903
+ return;
904
+ }
905
+ case "d": {
906
+ await this.#applyAtomicChange(tokens, () => {
907
+ this.#yankAndDeleteRange(visual);
908
+ });
909
+ this.#clearSelection();
910
+ return;
911
+ }
912
+ case "c": {
913
+ await this.#startInsertChange(tokens, () => {
914
+ this.#yankAndDeleteRange(visual);
915
+ });
916
+ this.#clearSelection();
917
+ return;
918
+ }
919
+ case ">":
920
+ case "<": {
921
+ const startLine = this.buffer.offsetToPosition(visual.start).line;
922
+ const endLine = this.buffer.offsetToPosition(Math.max(visual.start, visual.end - 1)).line;
923
+ await this.#applyAtomicChange(tokens, () => {
924
+ this.buffer.indentLines(
925
+ startLine,
926
+ endLine,
927
+ detectIndentUnit(this.buffer.lines),
928
+ operator === ">" ? 1 : -1,
929
+ );
930
+ });
931
+ this.#clearSelection();
932
+ return;
933
+ }
934
+ case "~": {
935
+ await this.#applyAtomicChange(tokens, () => {
936
+ const original = this.buffer.getText().slice(visual.start, visual.end);
937
+ this.buffer.replaceOffsets(visual.start, visual.end, toggleCase(original), visual.start);
938
+ });
939
+ this.#clearSelection();
940
+ return;
941
+ }
942
+ default:
943
+ throw new VimError(`Unsupported visual operator: ${operator}`);
944
+ }
945
+ }
946
+
947
+ async #executeNormal(tokens: readonly VimKeyToken[], index: number): Promise<number> {
948
+ const { count, hasCount, nextIndex } = this.#readCount(tokens, index);
949
+ const token = tokens[nextIndex];
950
+ if (!token) {
951
+ return nextIndex;
952
+ }
953
+
954
+ switch (token.value) {
955
+ case "h":
956
+ this.buffer.setCursor({ line: this.buffer.cursor.line, col: this.buffer.cursor.col - count });
957
+ return nextIndex + 1;
958
+ case "j":
959
+ this.buffer.setCursor({ line: this.buffer.cursor.line + count, col: this.buffer.cursor.col });
960
+ return nextIndex + 1;
961
+ case "k":
962
+ this.buffer.setCursor({ line: this.buffer.cursor.line - count, col: this.buffer.cursor.col });
963
+ return nextIndex + 1;
964
+ case "l":
965
+ case " ":
966
+ this.buffer.setCursor({ line: this.buffer.cursor.line, col: this.buffer.cursor.col + count });
967
+ return nextIndex + 1;
968
+ case "w":
969
+ case "W":
970
+ case "b":
971
+ case "B":
972
+ case "e":
973
+ case "E":
974
+ case "0":
975
+ case "$":
976
+ case "^":
977
+ case "|":
978
+ case ";":
979
+ case ",":
980
+ case "G":
981
+ case "f":
982
+ case "F":
983
+ case "t":
984
+ case "T":
985
+ case "{":
986
+ case "}":
987
+ case "%":
988
+ case "H":
989
+ case "M":
990
+ case "+":
991
+ case "-":
992
+ case "_":
993
+ case "L": {
994
+ const motion = this.#resolveMotion(tokens, nextIndex, count, hasCount);
995
+ this.buffer.setCursor(motion.target);
996
+ return motion.nextIndex;
997
+ }
998
+ case "*":
999
+ case "#": {
1000
+ const text = this.buffer.getText();
1001
+ const offset = this.buffer.currentOffset();
1002
+ const cat = wordCategory(text[offset] ?? "", false);
1003
+ if (cat === "space") {
1004
+ throw new VimError("No word under cursor", token);
1005
+ }
1006
+ let start = offset;
1007
+ while (start > 0 && wordCategory(text[start - 1] ?? "", false) === cat) start -= 1;
1008
+ let end = offset;
1009
+ while (end < text.length && wordCategory(text[end] ?? "", false) === cat) end += 1;
1010
+ const word = text.slice(start, end);
1011
+ const pattern = `\\b${escapeRegex(word)}\\b`;
1012
+ const direction = token.value === "*" ? 1 : -1;
1013
+ for (let step = 0; step < count; step += 1) {
1014
+ await this.#runSearch(pattern, direction, true);
1015
+ }
1016
+ return nextIndex + 1;
1017
+ }
1018
+ case "n":
1019
+ await this.#repeatSearch(this.lastSearch?.direction ?? 1, count);
1020
+ return nextIndex + 1;
1021
+ case "N":
1022
+ await this.#repeatSearch(((this.lastSearch?.direction ?? 1) * -1) as 1 | -1, count);
1023
+ return nextIndex + 1;
1024
+ case "/":
1025
+ this.inputMode = "search-forward";
1026
+ this.#pendingInput = "";
1027
+ return nextIndex + 1;
1028
+ case "?":
1029
+ this.inputMode = "search-backward";
1030
+ this.#pendingInput = "";
1031
+ return nextIndex + 1;
1032
+ case ":":
1033
+ this.inputMode = "command";
1034
+ this.#pendingInput = "";
1035
+ return nextIndex + 1;
1036
+ case "v":
1037
+ this.inputMode = "visual";
1038
+ this.selectionAnchor = clonePosition(this.buffer.cursor);
1039
+ return nextIndex + 1;
1040
+ case "V":
1041
+ this.inputMode = "visual-line";
1042
+ this.selectionAnchor = clonePosition(this.buffer.cursor);
1043
+ return nextIndex + 1;
1044
+ case "i":
1045
+ // When count > 1 (e.g. `2i`), interpret as `2Gi` — go to line N then insert.
1046
+ // Models confuse `Ni` with `NGi`; bare `i` with a high count is almost never intended.
1047
+ if (hasCount) {
1048
+ this.buffer.setCursor({ line: Math.min(count, this.buffer.lineCount()) - 1, col: 0 });
1049
+ }
1050
+ await this.#startInsertChange(["i"]);
1051
+ return nextIndex + 1;
1052
+ case "a":
1053
+ this.buffer.setCursor({ line: this.buffer.cursor.line, col: this.buffer.cursor.col + 1 });
1054
+ await this.#startInsertChange(["a"]);
1055
+ return nextIndex + 1;
1056
+ case "I":
1057
+ this.buffer.setCursor({
1058
+ line: this.buffer.cursor.line,
1059
+ col: this.buffer.firstNonBlank(this.buffer.cursor.line),
1060
+ });
1061
+ await this.#startInsertChange(["I"]);
1062
+ return nextIndex + 1;
1063
+ case "A":
1064
+ this.buffer.setCursor({
1065
+ line: this.buffer.cursor.line,
1066
+ col: this.buffer.getLine(this.buffer.cursor.line).length,
1067
+ });
1068
+ await this.#startInsertChange(["A"]);
1069
+ return nextIndex + 1;
1070
+ case "o":
1071
+ // When count > 1 (e.g. `13o`), interpret as `13Go` — go to line N then open below.
1072
+ // Models confuse `No` with `NGo`; bare `o` with a high count is almost never intended.
1073
+ if (hasCount) {
1074
+ this.buffer.setCursor({ line: Math.min(count, this.buffer.lineCount()) - 1, col: 0 });
1075
+ }
1076
+ await this.#startInsertChange(["o"], () => {
1077
+ const line = this.buffer.cursor.line + 1;
1078
+ this.buffer.insertLines(line, [""]);
1079
+ });
1080
+ return nextIndex + 1;
1081
+ case "O":
1082
+ if (hasCount) {
1083
+ this.buffer.setCursor({ line: Math.min(count, this.buffer.lineCount()) - 1, col: 0 });
1084
+ }
1085
+ await this.#startInsertChange(["O"], () => {
1086
+ const line = this.buffer.cursor.line;
1087
+ this.buffer.insertLines(line, [""]);
1088
+ });
1089
+ return nextIndex + 1;
1090
+ case "s":
1091
+ await this.#startInsertChange(["s"], () => {
1092
+ this.#deleteCharsForward(count);
1093
+ });
1094
+ return nextIndex + 1;
1095
+ case "S":
1096
+ await this.#changeWholeLines(count, ["S"]);
1097
+ return nextIndex + 1;
1098
+ case "x":
1099
+ await this.#applyAtomicChange(["x"], () => {
1100
+ this.#deleteCharsForward(count);
1101
+ });
1102
+ return nextIndex + 1;
1103
+ case "X":
1104
+ await this.#applyAtomicChange(["X"], () => {
1105
+ const end = this.buffer.currentOffset();
1106
+ const start = Math.max(0, end - count);
1107
+ this.register = { kind: "char", text: this.buffer.deleteOffsets(start, end) };
1108
+ });
1109
+ return nextIndex + 1;
1110
+ case "r": {
1111
+ const replacement = tokens[nextIndex + 1];
1112
+ if (!replacement || replacement.value.length !== 1) {
1113
+ throw new VimError("r requires a replacement character", token);
1114
+ }
1115
+ await this.#applyAtomicChange(["r", replacement.value], () => {
1116
+ const start = this.buffer.currentOffset();
1117
+ this.buffer.replaceOffsets(
1118
+ start,
1119
+ Math.min(this.buffer.getText().length, start + count),
1120
+ replacement.value.repeat(count),
1121
+ start,
1122
+ );
1123
+ });
1124
+ return nextIndex + 2;
1125
+ }
1126
+ case "~":
1127
+ await this.#applyAtomicChange(["~"], () => {
1128
+ const start = this.buffer.currentOffset();
1129
+ const end = Math.min(this.buffer.getText().length, start + count);
1130
+ const text = this.buffer.getText().slice(start, end);
1131
+ this.buffer.replaceOffsets(start, end, toggleCase(text), end);
1132
+ });
1133
+ return nextIndex + 1;
1134
+ case "J":
1135
+ await this.#applyAtomicChange(["J"], () => {
1136
+ this.buffer.joinLines(this.buffer.cursor.line, count);
1137
+ });
1138
+ return nextIndex + 1;
1139
+ case "p":
1140
+ case "P":
1141
+ await this.#applyAtomicChange([token.value], () => {
1142
+ this.#paste(token.value === "p", count);
1143
+ });
1144
+ return nextIndex + 1;
1145
+ case "u":
1146
+ await this.#undo(count);
1147
+ return nextIndex + 1;
1148
+ case "C-r":
1149
+ await this.#redo(count);
1150
+ return nextIndex + 1;
1151
+ case ".":
1152
+ await this.#repeatLastChange(count, token);
1153
+ return nextIndex + 1;
1154
+ case "d":
1155
+ case "c":
1156
+ case "y":
1157
+ case ">":
1158
+ case "<":
1159
+ return this.#executeOperator(tokens, nextIndex, count, hasCount, token.value);
1160
+ case "D":
1161
+ await this.#applyAtomicChange(["D"], () => {
1162
+ const start = this.buffer.currentOffset();
1163
+ const line = this.buffer.getLine(this.buffer.cursor.line);
1164
+ const end = start + (line.length - this.buffer.cursor.col);
1165
+ this.register = { kind: "char", text: this.buffer.deleteOffsets(start, end) };
1166
+ });
1167
+ return nextIndex + 1;
1168
+ case "C":
1169
+ await this.#startInsertChange(["C"], () => {
1170
+ const start = this.buffer.currentOffset();
1171
+ const line = this.buffer.getLine(this.buffer.cursor.line);
1172
+ const end = start + (line.length - this.buffer.cursor.col);
1173
+ this.register = { kind: "char", text: this.buffer.deleteOffsets(start, end) };
1174
+ });
1175
+ return nextIndex + 1;
1176
+ case "z": {
1177
+ const zTarget = tokens[nextIndex + 1];
1178
+ if (!zTarget) {
1179
+ throw new VimError("z requires a second key", token);
1180
+ }
1181
+ if (zTarget.value === "z") {
1182
+ this.centerViewportOnCursor();
1183
+ } else if (zTarget.value === "t" || zTarget.value === "CR") {
1184
+ this.viewportStart = this.buffer.cursor.line + 1;
1185
+ this.buffer.setCursor({
1186
+ line: this.buffer.cursor.line,
1187
+ col: this.buffer.firstNonBlank(this.buffer.cursor.line),
1188
+ });
1189
+ } else if (zTarget.value === "b" || zTarget.value === "-") {
1190
+ this.viewportStart = Math.max(1, this.buffer.cursor.line + 1 - (DEFAULT_VIEWPORT_HEIGHT - 1));
1191
+ this.buffer.setCursor({
1192
+ line: this.buffer.cursor.line,
1193
+ col: this.buffer.firstNonBlank(this.buffer.cursor.line),
1194
+ });
1195
+ } else if (zTarget.value === ".") {
1196
+ this.centerViewportOnCursor();
1197
+ this.buffer.setCursor({
1198
+ line: this.buffer.cursor.line,
1199
+ col: this.buffer.firstNonBlank(this.buffer.cursor.line),
1200
+ });
1201
+ } else if (NOOP_Z_COMMANDS.has(zTarget.value)) {
1202
+ this.statusMessage = `Ignored z${zTarget.display} (folds unsupported)`;
1203
+ } else {
1204
+ throw new VimError(`Unsupported z command: z${zTarget.display}`, zTarget);
1205
+ }
1206
+ return nextIndex + 2;
1207
+ }
1208
+ case "C-f":
1209
+ this.buffer.setCursor({
1210
+ line: this.buffer.cursor.line + Math.max(1, (DEFAULT_VIEWPORT_HEIGHT - 2) * count),
1211
+ col: this.buffer.cursor.col,
1212
+ });
1213
+ return nextIndex + 1;
1214
+ case "C-b":
1215
+ this.buffer.setCursor({
1216
+ line: this.buffer.cursor.line - Math.max(1, (DEFAULT_VIEWPORT_HEIGHT - 2) * count),
1217
+ col: this.buffer.cursor.col,
1218
+ });
1219
+ return nextIndex + 1;
1220
+ case "C-d":
1221
+ this.buffer.setCursor({
1222
+ line: this.buffer.cursor.line + Math.max(1, Math.floor(DEFAULT_VIEWPORT_HEIGHT / 2) * count),
1223
+ col: this.buffer.cursor.col,
1224
+ });
1225
+ return nextIndex + 1;
1226
+ case "C-u":
1227
+ this.buffer.setCursor({
1228
+ line: this.buffer.cursor.line - Math.max(1, Math.floor(DEFAULT_VIEWPORT_HEIGHT / 2) * count),
1229
+ col: this.buffer.cursor.col,
1230
+ });
1231
+ return nextIndex + 1;
1232
+ case "Esc":
1233
+ return nextIndex + 1;
1234
+ case "Y": {
1235
+ const start = this.buffer.cursor.line;
1236
+ const end = this.buffer.clampLine(start + count - 1);
1237
+ this.register = { kind: "line", text: this.buffer.lines.slice(start, end + 1).join("\n") };
1238
+ this.statusMessage = `Yanked ${end - start + 1} line${end === start ? "" : "s"}`;
1239
+ return nextIndex + 1;
1240
+ }
1241
+ case "R":
1242
+ await this.#startInsertChange(["R"], undefined, false);
1243
+ return nextIndex + 1;
1244
+ case "g": {
1245
+ const gNext = tokens[nextIndex + 1];
1246
+ if (!gNext) {
1247
+ throw new VimError("g requires a second key", token);
1248
+ }
1249
+ if (gNext.value === "g") {
1250
+ this.buffer.setCursor({ line: hasCount ? Math.max(0, count - 1) : 0, col: 0 });
1251
+ return nextIndex + 2;
1252
+ }
1253
+ if (gNext.value === "v") {
1254
+ if (this.lastVisual) {
1255
+ this.selectionAnchor = clonePosition(this.lastVisual.anchor);
1256
+ this.buffer.setCursor(this.lastVisual.cursor);
1257
+ this.inputMode = this.lastVisual.mode;
1258
+ }
1259
+ return nextIndex + 2;
1260
+ }
1261
+ if (gNext.value === "*" || gNext.value === "#") {
1262
+ const text = this.buffer.getText();
1263
+ const offset = this.buffer.currentOffset();
1264
+ const cat = wordCategory(text[offset] ?? "", false);
1265
+ if (cat === "space") {
1266
+ throw new VimError("No word under cursor", gNext);
1267
+ }
1268
+ let start = offset;
1269
+ while (start > 0 && wordCategory(text[start - 1] ?? "", false) === cat) start -= 1;
1270
+ let end = offset;
1271
+ while (end < text.length && wordCategory(text[end] ?? "", false) === cat) end += 1;
1272
+ const word = text.slice(start, end);
1273
+ const direction = gNext.value === "*" ? 1 : -1;
1274
+ for (let step = 0; step < count; step += 1) {
1275
+ await this.#runSearch(escapeRegex(word), direction, true);
1276
+ }
1277
+ return nextIndex + 2;
1278
+ }
1279
+ if (gNext.value === "U" || gNext.value === "u") {
1280
+ const caseOp = gNext.value;
1281
+ const {
1282
+ count: motionCount,
1283
+ hasCount: hasMotionCount,
1284
+ nextIndex: motionStart,
1285
+ } = this.#readCount(tokens, nextIndex + 2);
1286
+ const motionToken = tokens[motionStart];
1287
+ if (!motionToken) {
1288
+ throw new VimError(`g${caseOp} requires a motion`, gNext);
1289
+ }
1290
+ if ((motionToken.value === "U" && caseOp === "U") || (motionToken.value === "u" && caseOp === "u")) {
1291
+ const effectiveCount = hasMotionCount ? count * motionCount : count;
1292
+ await this.#applyAtomicChange(["g", caseOp, motionToken.value], () => {
1293
+ const start = this.buffer.cursor.line;
1294
+ const end = this.buffer.clampLine(start + effectiveCount - 1);
1295
+ for (let line = start; line <= end; line++) {
1296
+ const content = this.buffer.getLine(line);
1297
+ this.buffer.replaceLine(line, caseOp === "U" ? content.toUpperCase() : content.toLowerCase());
1298
+ }
1299
+ });
1300
+ return motionStart + 1;
1301
+ }
1302
+ const effectiveCount = hasMotionCount ? count * motionCount : count;
1303
+ const motion = this.#resolveMotion(tokens, motionStart, effectiveCount, hasCount || hasMotionCount);
1304
+ const range = this.#resolveMotionRange(motion);
1305
+ await this.#applyAtomicChange(
1306
+ tokens.slice(nextIndex, motion.nextIndex).map(tokenEntry => tokenEntry.value),
1307
+ () => {
1308
+ const text = this.buffer.getText();
1309
+ const slice = text.slice(range.start, range.end);
1310
+ const transformed = caseOp === "U" ? slice.toUpperCase() : slice.toLowerCase();
1311
+ this.buffer.replaceOffsets(range.start, range.end, transformed, range.start);
1312
+ },
1313
+ );
1314
+ return motion.nextIndex;
1315
+ }
1316
+ if (gNext.value === "~") {
1317
+ const {
1318
+ count: motionCount,
1319
+ hasCount: hasMotionCount,
1320
+ nextIndex: motionStart,
1321
+ } = this.#readCount(tokens, nextIndex + 2);
1322
+ const motionToken = tokens[motionStart];
1323
+ if (!motionToken) {
1324
+ throw new VimError("g~ requires a motion", gNext);
1325
+ }
1326
+ if (motionToken.value === "~") {
1327
+ const effectiveCount = hasMotionCount ? count * motionCount : count;
1328
+ await this.#applyAtomicChange(["g", "~", motionToken.value], () => {
1329
+ const start = this.buffer.cursor.line;
1330
+ const end = this.buffer.clampLine(start + effectiveCount - 1);
1331
+ for (let line = start; line <= end; line += 1) {
1332
+ this.buffer.replaceLine(line, toggleCase(this.buffer.getLine(line)));
1333
+ }
1334
+ });
1335
+ return motionStart + 1;
1336
+ }
1337
+ const effectiveCount = hasMotionCount ? count * motionCount : count;
1338
+ const motion = this.#resolveMotion(tokens, motionStart, effectiveCount, hasCount || hasMotionCount);
1339
+ const range = this.#resolveMotionRange(motion);
1340
+ await this.#applyAtomicChange(
1341
+ tokens.slice(nextIndex, motion.nextIndex).map(tokenEntry => tokenEntry.value),
1342
+ () => {
1343
+ const text = this.buffer.getText();
1344
+ const slice = text.slice(range.start, range.end);
1345
+ this.buffer.replaceOffsets(range.start, range.end, toggleCase(slice), range.start);
1346
+ },
1347
+ );
1348
+ return motion.nextIndex;
1349
+ }
1350
+ if (gNext.value === "J") {
1351
+ await this.#applyAtomicChange(["g", "J"], () => {
1352
+ const start = this.buffer.clampLine(this.buffer.cursor.line);
1353
+ const end = this.buffer.clampLine(start + Math.max(count, 1));
1354
+ if (start < end) {
1355
+ const joined = this.buffer.lines.slice(start, end + 1).join("");
1356
+ this.buffer.lines.splice(start, end - start + 1, joined);
1357
+ this.buffer.setCursor({ line: start, col: Math.max(0, joined.length - 1) });
1358
+ }
1359
+ });
1360
+ return nextIndex + 2;
1361
+ }
1362
+ throw new VimError(`Unsupported g command: g${gNext.display}`, gNext);
1363
+ }
1364
+ case "Z": {
1365
+ const zNext = tokens[nextIndex + 1];
1366
+ if (!zNext) {
1367
+ throw new VimError("Z requires a second key", token);
1368
+ }
1369
+ if (zNext.value === "Z") {
1370
+ await this.#executeEx("wq");
1371
+ return nextIndex + 2;
1372
+ }
1373
+ if (zNext.value === "Q") {
1374
+ await this.#executeEx("q!");
1375
+ return nextIndex + 2;
1376
+ }
1377
+ throw new VimError(`Unsupported Z command: Z${zNext.display}`, zNext);
1378
+ }
1379
+ default:
1380
+ throw new VimError(`Unsupported command: ${token.display}`, token);
1381
+ }
1382
+ }
1383
+
1384
+ async #repeatLastChange(count: number, token: VimKeyToken): Promise<void> {
1385
+ if (!this.#lastChangeTokens || this.#lastChangeTokens.length === 0) {
1386
+ throw new VimError("No previous change to repeat", token);
1387
+ }
1388
+ for (let index = 0; index < count; index += 1) {
1389
+ await this.executeTokens(replayTokens(this.#lastChangeTokens), ".");
1390
+ }
1391
+ }
1392
+
1393
+ async #undo(count: number): Promise<void> {
1394
+ await this.#ensureEditable();
1395
+ let applied = 0;
1396
+ for (let index = 0; index < count; index += 1) {
1397
+ const entry = this.#undoStack.pop();
1398
+ if (!entry) {
1399
+ break;
1400
+ }
1401
+ this.#redoStack.push(entry);
1402
+ this.buffer.restore(entry.before);
1403
+ applied += 1;
1404
+ }
1405
+ this.inputMode = "normal";
1406
+ this.selectionAnchor = null;
1407
+ this.#pendingChange = null;
1408
+ this.statusMessage = `Undid ${applied} change${applied === 1 ? "" : "s"}`;
1409
+ }
1410
+
1411
+ async #redo(count: number): Promise<void> {
1412
+ await this.#ensureEditable();
1413
+ let applied = 0;
1414
+ for (let index = 0; index < count; index += 1) {
1415
+ const entry = this.#redoStack.pop();
1416
+ if (!entry) {
1417
+ break;
1418
+ }
1419
+ this.#undoStack.push(entry);
1420
+ this.buffer.restore(entry.after);
1421
+ applied += 1;
1422
+ }
1423
+ this.inputMode = "normal";
1424
+ this.selectionAnchor = null;
1425
+ this.#pendingChange = null;
1426
+ this.statusMessage = `Redid ${applied} change${applied === 1 ? "" : "s"}`;
1427
+ }
1428
+
1429
+ async #executeOperator(
1430
+ tokens: readonly VimKeyToken[],
1431
+ operatorIndex: number,
1432
+ operatorCount: number,
1433
+ hasOperatorCount: boolean,
1434
+ operator: string,
1435
+ ): Promise<number> {
1436
+ const { count: motionCount, hasCount: hasMotionCount, nextIndex } = this.#readCount(tokens, operatorIndex + 1);
1437
+ const token = tokens[nextIndex];
1438
+ if (!token) {
1439
+ throw new VimError(`Operator ${operator} requires a motion`, tokens[operatorIndex]);
1440
+ }
1441
+ const hasAnyCount = hasOperatorCount || hasMotionCount;
1442
+ const effectiveCount = hasMotionCount ? operatorCount * motionCount : operatorCount;
1443
+
1444
+ if (token.value === operator) {
1445
+ if (operator === "d") {
1446
+ await this.#applyAtomicChange([operator, operator], () => {
1447
+ const start = this.buffer.cursor.line;
1448
+ const removed = this.buffer.deleteLines(start, start + Math.max(1, effectiveCount) - 1);
1449
+ this.register = { kind: "line", text: removed.join("\n") };
1450
+ });
1451
+ return nextIndex + 1;
1452
+ }
1453
+ if (operator === "y") {
1454
+ const start = this.buffer.cursor.line;
1455
+ const end = this.buffer.clampLine(start + Math.max(1, effectiveCount) - 1);
1456
+ this.register = { kind: "line", text: this.buffer.lines.slice(start, end + 1).join("\n") };
1457
+ this.statusMessage = `Yanked ${end - start + 1} line${end === start ? "" : "s"}`;
1458
+ return nextIndex + 1;
1459
+ }
1460
+ if (operator === "c") {
1461
+ await this.#changeWholeLines(Math.max(1, effectiveCount), [operator, operator]);
1462
+ return nextIndex + 1;
1463
+ }
1464
+ if (operator === ">" || operator === "<") {
1465
+ await this.#applyAtomicChange([operator, operator], () => {
1466
+ this.buffer.indentLines(
1467
+ this.buffer.cursor.line,
1468
+ this.buffer.cursor.line + Math.max(1, effectiveCount) - 1,
1469
+ detectIndentUnit(this.buffer.lines),
1470
+ operator === ">" ? 1 : -1,
1471
+ );
1472
+ });
1473
+ return nextIndex + 1;
1474
+ }
1475
+ }
1476
+
1477
+ if (token.value === "i" || token.value === "a") {
1478
+ const object = tokens[nextIndex + 1];
1479
+ if (!object) {
1480
+ throw new VimError(`Missing text object after ${operator}${token.value}`, token);
1481
+ }
1482
+ const textObject = this.#resolveTextObject(token.value === "i", object.value, object);
1483
+ await this.#applyOperatorToMotion(
1484
+ operator,
1485
+ { nextIndex: nextIndex + 2, target: this.buffer.cursor, range: textObject },
1486
+ [operator, token.value, object.value],
1487
+ );
1488
+ return nextIndex + 2;
1489
+ }
1490
+
1491
+ // In vim, `cw` and `cW` act like `ce` and `cE` (don't include trailing whitespace)
1492
+ const motionToken = tokens[nextIndex];
1493
+ let motion: MotionResult;
1494
+ if (operator === "c" && motionToken && (motionToken.value === "w" || motionToken.value === "W")) {
1495
+ const eMotionValue = motionToken.value === "w" ? "e" : "E";
1496
+ const syntheticTokens: readonly VimKeyToken[] = [
1497
+ ...tokens.slice(0, nextIndex),
1498
+ { ...motionToken, value: eMotionValue },
1499
+ ...tokens.slice(nextIndex + 1),
1500
+ ];
1501
+ motion = this.#resolveMotion(syntheticTokens, nextIndex, effectiveCount, hasAnyCount);
1502
+ } else {
1503
+ motion = this.#resolveMotion(tokens, nextIndex, effectiveCount, hasAnyCount);
1504
+ }
1505
+ await this.#applyOperatorToMotion(
1506
+ operator,
1507
+ motion,
1508
+ tokens.slice(operatorIndex, motion.nextIndex).map(tokenEntry => tokenEntry.value),
1509
+ );
1510
+ return motion.nextIndex;
1511
+ }
1512
+
1513
+ async #applyOperatorToMotion(operator: string, motion: MotionResult, tokens: readonly string[]): Promise<void> {
1514
+ if (operator === "y") {
1515
+ const range = this.#resolveMotionRange(motion);
1516
+ this.register = {
1517
+ kind: range.linewise ? "line" : "char",
1518
+ text: this.buffer.getText().slice(range.start, range.end),
1519
+ };
1520
+ this.statusMessage = `Yanked ${range.linewise ? "line" : "selection"}`;
1521
+ return;
1522
+ }
1523
+
1524
+ if (operator === ">" || operator === "<") {
1525
+ const range = this.#resolveMotionRange(motion);
1526
+ const startLine = this.buffer.offsetToPosition(range.start).line;
1527
+ const endLine = this.buffer.offsetToPosition(Math.max(range.start, range.end - 1)).line;
1528
+ await this.#applyAtomicChange(tokens, () => {
1529
+ this.buffer.indentLines(startLine, endLine, detectIndentUnit(this.buffer.lines), operator === ">" ? 1 : -1);
1530
+ });
1531
+ return;
1532
+ }
1533
+
1534
+ if (operator === "d") {
1535
+ const range = this.#resolveMotionRange(motion);
1536
+ await this.#applyAtomicChange(tokens, () => {
1537
+ this.#yankAndDeleteRange(range);
1538
+ });
1539
+ return;
1540
+ }
1541
+
1542
+ if (operator === "c") {
1543
+ const range = this.#resolveMotionRange(motion);
1544
+ await this.#startInsertChange(tokens, () => {
1545
+ this.#yankAndDeleteRange(range);
1546
+ });
1547
+ return;
1548
+ }
1549
+ }
1550
+
1551
+ #yankAndDeleteRange(range: { start: number; end: number; linewise: boolean }): void {
1552
+ this.register = {
1553
+ kind: range.linewise ? "line" : "char",
1554
+ text: this.buffer.getText().slice(range.start, range.end),
1555
+ };
1556
+ this.buffer.deleteOffsets(range.start, range.end);
1557
+ }
1558
+
1559
+ #deleteCharsForward(count: number): void {
1560
+ const start = this.buffer.currentOffset();
1561
+ this.register = {
1562
+ kind: "char",
1563
+ text: this.buffer.deleteOffsets(start, Math.min(this.buffer.getText().length, start + count)),
1564
+ };
1565
+ }
1566
+
1567
+ async #changeWholeLines(count: number, tokens: readonly string[]): Promise<void> {
1568
+ await this.#startInsertChange(tokens, () => {
1569
+ const start = this.buffer.cursor.line;
1570
+ const end = this.buffer.clampLine(start + count - 1);
1571
+ const removed = this.buffer.lines.slice(start, end + 1);
1572
+ this.register = { kind: "line", text: removed.join("\n") };
1573
+ this.buffer.lines.splice(start, end - start + 1, "");
1574
+ if (this.buffer.lines.length === 0) {
1575
+ this.buffer.lines = [""];
1576
+ }
1577
+ this.buffer.setCursor({ line: Math.min(start, this.buffer.lastLineIndex()), col: 0 });
1578
+ });
1579
+ }
1580
+
1581
+ #resolveMotionRange(motion: MotionResult): { start: number; end: number; linewise: boolean } {
1582
+ if (motion.range) {
1583
+ return {
1584
+ start: motion.range.start,
1585
+ end: motion.range.end,
1586
+ linewise: motion.range.linewise ?? false,
1587
+ };
1588
+ }
1589
+
1590
+ if (motion.linewise) {
1591
+ const startLine = Math.min(this.buffer.cursor.line, motion.target.line);
1592
+ const endLine = Math.max(this.buffer.cursor.line, motion.target.line);
1593
+ const start = this.buffer.positionToOffset({ line: startLine, col: 0 });
1594
+ const end =
1595
+ endLine >= this.buffer.lastLineIndex()
1596
+ ? this.buffer.getText().length
1597
+ : this.buffer.positionToOffset({ line: endLine + 1, col: 0 });
1598
+ return { start, end, linewise: true };
1599
+ }
1600
+
1601
+ const from = this.buffer.positionToOffset(this.buffer.cursor);
1602
+ const to = this.buffer.positionToOffset(motion.target);
1603
+ const normalized = normalizeRange(from, to);
1604
+ return {
1605
+ start: normalized.start,
1606
+ end: normalized.end + (motion.inclusive === false ? 0 : 1),
1607
+ linewise: false,
1608
+ };
1609
+ }
1610
+
1611
+ #resolveMotion(tokens: readonly VimKeyToken[], index: number, count: number, hasCount = true): MotionResult {
1612
+ const token = tokens[index];
1613
+ if (!token) {
1614
+ throw new VimError("Missing motion");
1615
+ }
1616
+
1617
+ const text = this.buffer.getText();
1618
+ switch (token.value) {
1619
+ case "h":
1620
+ return {
1621
+ nextIndex: index + 1,
1622
+ target: { line: this.buffer.cursor.line, col: this.buffer.cursor.col - count },
1623
+ };
1624
+ case "j":
1625
+ return {
1626
+ nextIndex: index + 1,
1627
+ target: { line: this.buffer.cursor.line + count, col: this.buffer.cursor.col },
1628
+ linewise: true,
1629
+ };
1630
+ case "k":
1631
+ return {
1632
+ nextIndex: index + 1,
1633
+ target: { line: this.buffer.cursor.line - count, col: this.buffer.cursor.col },
1634
+ linewise: true,
1635
+ };
1636
+ case "l":
1637
+ case " ":
1638
+ return {
1639
+ nextIndex: index + 1,
1640
+ target: { line: this.buffer.cursor.line, col: this.buffer.cursor.col + count },
1641
+ };
1642
+ case "w":
1643
+ case "W": {
1644
+ let offset = this.buffer.currentOffset();
1645
+ for (let step = 0; step < count; step += 1) {
1646
+ offset = nextWordStart(text, step === 0 ? offset + 1 : offset, token.value === "W");
1647
+ }
1648
+ return { nextIndex: index + 1, target: this.buffer.offsetToPosition(offset), inclusive: false };
1649
+ }
1650
+ case "b":
1651
+ case "B": {
1652
+ let offset = this.buffer.currentOffset();
1653
+ for (let step = 0; step < count; step += 1) {
1654
+ offset = previousWordStart(text, offset, token.value === "B");
1655
+ }
1656
+ return { nextIndex: index + 1, target: this.buffer.offsetToPosition(offset) };
1657
+ }
1658
+ case "e":
1659
+ case "E": {
1660
+ let offset = this.buffer.currentOffset();
1661
+ for (let step = 0; step < count; step += 1) {
1662
+ offset = endOfWord(text, step === 0 ? offset : offset + 1, token.value === "E");
1663
+ }
1664
+ return { nextIndex: index + 1, target: this.buffer.offsetToPosition(offset) };
1665
+ }
1666
+ case "0":
1667
+ return { nextIndex: index + 1, target: { line: this.buffer.cursor.line, col: 0 } };
1668
+ case "^":
1669
+ return {
1670
+ nextIndex: index + 1,
1671
+ target: { line: this.buffer.cursor.line, col: this.buffer.firstNonBlank(this.buffer.cursor.line) },
1672
+ };
1673
+ case "|":
1674
+ return {
1675
+ nextIndex: index + 1,
1676
+ target: { line: this.buffer.cursor.line, col: Math.max(0, count - 1) },
1677
+ };
1678
+ case "$":
1679
+ return {
1680
+ nextIndex: index + 1,
1681
+ target: {
1682
+ line: this.buffer.cursor.line,
1683
+ col: Math.max(0, this.buffer.getLine(this.buffer.cursor.line).length - 1),
1684
+ },
1685
+ };
1686
+ case "+": {
1687
+ const targetLine = this.buffer.clampLine(this.buffer.cursor.line + count);
1688
+ return {
1689
+ nextIndex: index + 1,
1690
+ target: { line: targetLine, col: this.buffer.firstNonBlank(targetLine) },
1691
+ linewise: true,
1692
+ };
1693
+ }
1694
+ case "-": {
1695
+ const targetLine = this.buffer.clampLine(this.buffer.cursor.line - count);
1696
+ return {
1697
+ nextIndex: index + 1,
1698
+ target: { line: targetLine, col: this.buffer.firstNonBlank(targetLine) },
1699
+ linewise: true,
1700
+ };
1701
+ }
1702
+ case "_": {
1703
+ const targetLine = this.buffer.clampLine(this.buffer.cursor.line + (count - 1));
1704
+ return {
1705
+ nextIndex: index + 1,
1706
+ target: { line: targetLine, col: this.buffer.firstNonBlank(targetLine) },
1707
+ linewise: true,
1708
+ };
1709
+ }
1710
+ case "g": {
1711
+ const next = tokens[index + 1];
1712
+ if (!next) {
1713
+ throw new VimError("Unsupported g motion", token);
1714
+ }
1715
+ if (next.value === "g") {
1716
+ return {
1717
+ nextIndex: index + 2,
1718
+ target: { line: hasCount ? Math.max(0, count - 1) : 0, col: 0 },
1719
+ linewise: true,
1720
+ };
1721
+ }
1722
+ if (next.value === "e" || next.value === "E") {
1723
+ let offset = this.buffer.currentOffset();
1724
+ for (let step = 0; step < count; step += 1) {
1725
+ offset = endOfPreviousWord(text, offset, next.value === "E");
1726
+ }
1727
+ return { nextIndex: index + 2, target: this.buffer.offsetToPosition(offset) };
1728
+ }
1729
+ if (next.value === "_") {
1730
+ const targetLine = this.buffer.clampLine(this.buffer.cursor.line + (count - 1));
1731
+ return {
1732
+ nextIndex: index + 2,
1733
+ target: { line: targetLine, col: lastNonBlankColumn(this.buffer.getLine(targetLine)) },
1734
+ };
1735
+ }
1736
+ throw new VimError("Unsupported g motion", token);
1737
+ }
1738
+ case "G":
1739
+ return {
1740
+ nextIndex: index + 1,
1741
+ target: { line: hasCount ? count - 1 : this.buffer.lastLineIndex(), col: 0 },
1742
+ linewise: true,
1743
+ };
1744
+ case "f":
1745
+ case "F":
1746
+ case "t":
1747
+ case "T": {
1748
+ const searchToken = tokens[index + 1];
1749
+ if (!searchToken || searchToken.value.length !== 1) {
1750
+ throw new VimError(`${token.value} requires a literal character`, token);
1751
+ }
1752
+ this.lastCharFind = { char: searchToken.value, mode: token.value as "f" | "F" | "t" | "T" };
1753
+ const line = this.buffer.getLine(this.buffer.cursor.line);
1754
+ const cursorCol = this.buffer.cursor.col;
1755
+ let matchIndex = -1;
1756
+ if (token.value === "f" || token.value === "t") {
1757
+ let start = cursorCol + 1;
1758
+ for (let step = 0; step < count; step += 1) {
1759
+ matchIndex = line.indexOf(searchToken.value, start);
1760
+ if (matchIndex === -1) break;
1761
+ start = matchIndex + 1;
1762
+ }
1763
+ if (matchIndex === -1) {
1764
+ throw new VimError(`Character not found: ${searchToken.value}`, searchToken);
1765
+ }
1766
+ if (token.value === "t") {
1767
+ matchIndex -= 1;
1768
+ }
1769
+ } else {
1770
+ let start = Math.max(0, cursorCol - 1);
1771
+ for (let step = 0; step < count; step += 1) {
1772
+ matchIndex = line.lastIndexOf(searchToken.value, start);
1773
+ if (matchIndex === -1) break;
1774
+ start = matchIndex - 1;
1775
+ }
1776
+ if (matchIndex === -1) {
1777
+ throw new VimError(`Character not found: ${searchToken.value}`, searchToken);
1778
+ }
1779
+ if (token.value === "T") {
1780
+ matchIndex += 1;
1781
+ }
1782
+ }
1783
+ return {
1784
+ nextIndex: index + 2,
1785
+ target: { line: this.buffer.cursor.line, col: Math.max(0, matchIndex) },
1786
+ };
1787
+ }
1788
+ case "{":
1789
+ return {
1790
+ nextIndex: index + 1,
1791
+ target: { line: findParagraphStart(this.buffer.lines, this.buffer.cursor.line), col: 0 },
1792
+ linewise: true,
1793
+ };
1794
+ case "}":
1795
+ return {
1796
+ nextIndex: index + 1,
1797
+ target: { line: findParagraphEnd(this.buffer.lines, this.buffer.cursor.line), col: 0 },
1798
+ linewise: true,
1799
+ };
1800
+ case "%": {
1801
+ const match = this.#findMatchingBracket();
1802
+ return { nextIndex: index + 1, target: match };
1803
+ }
1804
+ case "H":
1805
+ return {
1806
+ nextIndex: index + 1,
1807
+ target: { line: Math.max(0, this.viewportStart - 1), col: 0 },
1808
+ linewise: true,
1809
+ };
1810
+ case "M":
1811
+ return {
1812
+ nextIndex: index + 1,
1813
+ target: { line: Math.max(0, this.viewportStart - 1 + 20), col: 0 },
1814
+ linewise: true,
1815
+ };
1816
+ case "L":
1817
+ return {
1818
+ nextIndex: index + 1,
1819
+ target: { line: Math.max(0, this.viewportStart - 1 + 39), col: 0 },
1820
+ linewise: true,
1821
+ };
1822
+ case ";":
1823
+ case ",": {
1824
+ if (!this.lastCharFind) {
1825
+ throw new VimError(
1826
+ "No previous character search. If you meant an ex-command range like `:4,5d`, add the `:` prefix and `<CR>` suffix.",
1827
+ token,
1828
+ );
1829
+ }
1830
+ let mode = this.lastCharFind.mode;
1831
+ if (token.value === ",") {
1832
+ const reverseMap: Record<string, "f" | "F" | "t" | "T"> = { f: "F", F: "f", t: "T", T: "t" };
1833
+ mode = reverseMap[mode]!;
1834
+ }
1835
+ const line = this.buffer.getLine(this.buffer.cursor.line);
1836
+ const cursorCol = this.buffer.cursor.col;
1837
+ let matchIndex = -1;
1838
+ if (mode === "f" || mode === "t") {
1839
+ let start = cursorCol + 1;
1840
+ for (let step = 0; step < count; step += 1) {
1841
+ matchIndex = line.indexOf(this.lastCharFind.char, start);
1842
+ if (matchIndex === -1) break;
1843
+ start = matchIndex + 1;
1844
+ }
1845
+ if (matchIndex !== -1 && mode === "t") matchIndex -= 1;
1846
+ } else {
1847
+ let start = Math.max(0, cursorCol - 1);
1848
+ for (let step = 0; step < count; step += 1) {
1849
+ matchIndex = line.lastIndexOf(this.lastCharFind.char, start);
1850
+ if (matchIndex === -1) break;
1851
+ start = matchIndex - 1;
1852
+ }
1853
+ if (matchIndex !== -1 && mode === "T") matchIndex += 1;
1854
+ }
1855
+ if (matchIndex === -1) {
1856
+ throw new VimError(`Character not found: ${this.lastCharFind.char}`, token);
1857
+ }
1858
+ return {
1859
+ nextIndex: index + 1,
1860
+ target: { line: this.buffer.cursor.line, col: Math.max(0, matchIndex) },
1861
+ };
1862
+ }
1863
+ default:
1864
+ throw new VimError(`Unsupported motion: ${token.display}`, token);
1865
+ }
1866
+ }
1867
+
1868
+ #resolveTextObject(
1869
+ inner: boolean,
1870
+ objectToken: string,
1871
+ sourceToken: VimKeyToken,
1872
+ ): { start: number; end: number; linewise?: boolean } {
1873
+ if (objectToken === "w" || objectToken === "W") {
1874
+ return this.#resolveWordTextObject(inner, objectToken === "W");
1875
+ }
1876
+ if (objectToken === '"' || objectToken === "'" || objectToken === "`") {
1877
+ return this.#resolveQuoteTextObject(inner, objectToken, sourceToken);
1878
+ }
1879
+
1880
+ if (objectToken === "p") {
1881
+ return this.#resolveParagraphTextObject(inner);
1882
+ }
1883
+
1884
+ const normalized =
1885
+ objectToken === ")"
1886
+ ? "("
1887
+ : objectToken === "}"
1888
+ ? "{"
1889
+ : objectToken === "]"
1890
+ ? "["
1891
+ : objectToken === ">"
1892
+ ? "<"
1893
+ : objectToken;
1894
+ if (!BRACKET_PAIRS.has(normalized)) {
1895
+ throw new VimError(`Unsupported text object: ${objectToken}`, sourceToken);
1896
+ }
1897
+ return this.#resolveBracketTextObject(inner, normalized, sourceToken);
1898
+ }
1899
+
1900
+ #resolveWordTextObject(inner: boolean, bigWord: boolean): { start: number; end: number } {
1901
+ const text = this.buffer.getText();
1902
+ const cursor = this.buffer.currentOffset();
1903
+ let start = cursor;
1904
+ if (wordCategory(text[start] ?? "", bigWord) === "space") {
1905
+ start = nextWordStart(text, start, bigWord);
1906
+ }
1907
+ const category = wordCategory(text[start] ?? "", bigWord);
1908
+ while (start > 0 && wordCategory(text[start - 1] ?? "", bigWord) === category) {
1909
+ start -= 1;
1910
+ }
1911
+ let end = start;
1912
+ while (end < text.length && wordCategory(text[end] ?? "", bigWord) === category) {
1913
+ end += 1;
1914
+ }
1915
+ if (!inner) {
1916
+ while (end < text.length && wordCategory(text[end] ?? "", bigWord) === "space") {
1917
+ end += 1;
1918
+ }
1919
+ while (start > 0 && wordCategory(text[start - 1] ?? "", bigWord) === "space") {
1920
+ start -= 1;
1921
+ }
1922
+ }
1923
+ return { start, end };
1924
+ }
1925
+
1926
+ #resolveParagraphTextObject(inner: boolean): { start: number; end: number; linewise: boolean } {
1927
+ const lines = this.buffer.lines;
1928
+ const cursorLine = this.buffer.cursor.line;
1929
+ let start = cursorLine;
1930
+ let end = cursorLine;
1931
+ // Find paragraph boundaries (delimited by blank lines)
1932
+ if (lines[cursorLine]?.trim().length === 0) {
1933
+ // On a blank line: select contiguous blank lines
1934
+ while (start > 0 && lines[start - 1]!.trim().length === 0) start -= 1;
1935
+ while (end < lines.length - 1 && lines[end + 1]!.trim().length === 0) end += 1;
1936
+ if (!inner) {
1937
+ // Include following non-blank paragraph
1938
+ while (end < lines.length - 1 && lines[end + 1]!.trim().length > 0) end += 1;
1939
+ }
1940
+ } else {
1941
+ // On a non-blank line: select contiguous non-blank lines
1942
+ while (start > 0 && lines[start - 1]!.trim().length > 0) start -= 1;
1943
+ while (end < lines.length - 1 && lines[end + 1]!.trim().length > 0) end += 1;
1944
+ if (!inner) {
1945
+ // Include trailing blank lines
1946
+ while (end < lines.length - 1 && lines[end + 1]!.trim().length === 0) end += 1;
1947
+ }
1948
+ }
1949
+ const startOffset = this.buffer.positionToOffset({ line: start, col: 0 });
1950
+ const endOffset =
1951
+ end >= this.buffer.lastLineIndex()
1952
+ ? this.buffer.getText().length
1953
+ : this.buffer.positionToOffset({ line: end + 1, col: 0 });
1954
+ return { start: startOffset, end: endOffset, linewise: true };
1955
+ }
1956
+
1957
+ #resolveQuoteTextObject(inner: boolean, quote: string, sourceToken: VimKeyToken): { start: number; end: number } {
1958
+ const line = this.buffer.getLine(this.buffer.cursor.line);
1959
+ const col = this.buffer.cursor.col;
1960
+ const before = line.lastIndexOf(quote, col);
1961
+ const after = line.indexOf(quote, col + (line[col] === quote ? 1 : 0));
1962
+ if (before === -1 || after === -1 || before === after) {
1963
+ throw new VimError(`Quote text object not found for ${quote}`, sourceToken);
1964
+ }
1965
+ const startCol = inner ? before + 1 : before;
1966
+ const endCol = inner ? after : after + 1;
1967
+ return {
1968
+ start: this.buffer.positionToOffset({ line: this.buffer.cursor.line, col: startCol }),
1969
+ end: this.buffer.positionToOffset({ line: this.buffer.cursor.line, col: endCol }),
1970
+ };
1971
+ }
1972
+
1973
+ #resolveBracketTextObject(inner: boolean, open: string, sourceToken: VimKeyToken): { start: number; end: number } {
1974
+ const close = BRACKET_PAIRS.get(open)!;
1975
+ const text = this.buffer.getText();
1976
+ const cursor = this.buffer.currentOffset();
1977
+ let start = -1;
1978
+ let depth = 0;
1979
+ for (let index = cursor; index >= 0; index -= 1) {
1980
+ const char = text[index] ?? "";
1981
+ if (char === close) {
1982
+ depth += 1;
1983
+ } else if (char === open) {
1984
+ if (depth === 0) {
1985
+ start = index;
1986
+ break;
1987
+ }
1988
+ depth -= 1;
1989
+ }
1990
+ }
1991
+ if (start === -1) {
1992
+ throw new VimError(`Text object ${open}${close} not found`, sourceToken);
1993
+ }
1994
+ let end = -1;
1995
+ depth = 0;
1996
+ for (let index = start; index < text.length; index += 1) {
1997
+ const char = text[index] ?? "";
1998
+ if (char === open) {
1999
+ depth += 1;
2000
+ } else if (char === close) {
2001
+ depth -= 1;
2002
+ if (depth === 0) {
2003
+ end = index;
2004
+ break;
2005
+ }
2006
+ }
2007
+ }
2008
+ if (end === -1) {
2009
+ throw new VimError(`Text object ${open}${close} not found`, sourceToken);
2010
+ }
2011
+ return {
2012
+ start: inner ? start + 1 : start,
2013
+ end: inner ? end : end + 1,
2014
+ };
2015
+ }
2016
+
2017
+ #findMatchingBracket(): Position {
2018
+ const text = this.buffer.getText();
2019
+ const cursor = this.buffer.currentOffset();
2020
+ let offset = cursor;
2021
+ let char = text[offset] ?? "";
2022
+ if (!BRACKET_PAIRS.has(char) && !CLOSING_BRACKETS.has(char)) {
2023
+ offset += 1;
2024
+ char = text[offset] ?? "";
2025
+ }
2026
+ if (BRACKET_PAIRS.has(char)) {
2027
+ const close = BRACKET_PAIRS.get(char)!;
2028
+ let depth = 0;
2029
+ for (let index = offset; index < text.length; index += 1) {
2030
+ const current = text[index] ?? "";
2031
+ if (current === char) depth += 1;
2032
+ if (current === close) {
2033
+ depth -= 1;
2034
+ if (depth === 0) {
2035
+ return this.buffer.offsetToPosition(index);
2036
+ }
2037
+ }
2038
+ }
2039
+ }
2040
+ if (CLOSING_BRACKETS.has(char)) {
2041
+ const open = CLOSING_BRACKETS.get(char)!;
2042
+ let depth = 0;
2043
+ for (let index = offset; index >= 0; index -= 1) {
2044
+ const current = text[index] ?? "";
2045
+ if (current === char) depth += 1;
2046
+ if (current === open) {
2047
+ depth -= 1;
2048
+ if (depth === 0) {
2049
+ return this.buffer.offsetToPosition(index);
2050
+ }
2051
+ }
2052
+ }
2053
+ }
2054
+ throw new VimError("Matching bracket not found");
2055
+ }
2056
+
2057
+ async #runSearch(pattern: string, direction: 1 | -1, updateState: boolean): Promise<void> {
2058
+ const text = this.buffer.getText();
2059
+ const regex = createSearchRegex(pattern, "g");
2060
+ const cursor = this.buffer.currentOffset();
2061
+ let matchOffset = -1;
2062
+
2063
+ if (direction > 0) {
2064
+ regex.lastIndex = Math.min(text.length, cursor + 1);
2065
+ const match = regex.exec(text);
2066
+ if (match && match.index >= 0) {
2067
+ matchOffset = match.index;
2068
+ } else {
2069
+ regex.lastIndex = 0;
2070
+ const wrapMatch = regex.exec(text);
2071
+ if (wrapMatch && wrapMatch.index >= 0) {
2072
+ matchOffset = wrapMatch.index;
2073
+ }
2074
+ }
2075
+ } else {
2076
+ const matches = Array.from(text.matchAll(regex));
2077
+ for (let index = matches.length - 1; index >= 0; index -= 1) {
2078
+ const match = matches[index];
2079
+ if ((match.index ?? -1) < cursor) {
2080
+ matchOffset = match.index ?? -1;
2081
+ break;
2082
+ }
2083
+ }
2084
+ if (matchOffset === -1 && matches.length > 0) {
2085
+ matchOffset = matches[matches.length - 1]?.index ?? -1;
2086
+ }
2087
+ }
2088
+
2089
+ if (matchOffset === -1) {
2090
+ throw new VimError(`Pattern not found: ${pattern}`);
2091
+ }
2092
+
2093
+ this.buffer.setCursor(this.buffer.offsetToPosition(matchOffset));
2094
+ this.statusMessage = `${direction > 0 ? "/" : "?"}${pattern}`;
2095
+ if (updateState) {
2096
+ this.lastSearch = { pattern, direction };
2097
+ }
2098
+ }
2099
+
2100
+ async #repeatSearch(direction: 1 | -1, count: number): Promise<void> {
2101
+ if (!this.lastSearch) {
2102
+ throw new VimError("No previous search");
2103
+ }
2104
+ for (let index = 0; index < count; index += 1) {
2105
+ await this.#runSearch(this.lastSearch.pattern, direction, false);
2106
+ }
2107
+ this.lastSearch = { pattern: this.lastSearch.pattern, direction };
2108
+ }
2109
+
2110
+ #resolveExRange(
2111
+ range: VimLineRange | "all" | undefined,
2112
+ defaultStart: number,
2113
+ defaultEnd = defaultStart,
2114
+ ): VimLineRange {
2115
+ const totalLines = Math.max(1, this.buffer.lineCount());
2116
+ if (range === "all") {
2117
+ return { start: 1, end: totalLines };
2118
+ }
2119
+ const next = range ?? { start: defaultStart, end: defaultEnd };
2120
+ const start = Math.max(1, Math.min(next.start, totalLines));
2121
+ const end = Math.max(start, Math.min(next.end, totalLines));
2122
+ return { start, end };
2123
+ }
2124
+
2125
+ async #executeEx(input: string): Promise<void> {
2126
+ const command = parseExCommand(input, {
2127
+ currentLine: this.buffer.cursor.line + 1,
2128
+ lastLine: this.buffer.lineCount(),
2129
+ });
2130
+ switch (command.kind) {
2131
+ case "goto-line":
2132
+ this.buffer.setCursor({ line: Math.max(0, command.line - 1), col: 0 });
2133
+ this.statusMessage = `Line ${command.line}`;
2134
+ return;
2135
+ case "write": {
2136
+ const result = await this.#callbacks.saveBuffer(this.buffer, { force: command.force });
2137
+ this.buffer.markSaved(result.loaded);
2138
+ this.diagnostics = result.diagnostics;
2139
+ this.statusMessage = result.diagnostics
2140
+ ? `Wrote ${this.buffer.displayPath} (${result.diagnostics.summary})`
2141
+ : `Wrote ${this.buffer.displayPath}`;
2142
+ this.#undoStack = [];
2143
+ this.#redoStack = [];
2144
+ return;
2145
+ }
2146
+ case "update":
2147
+ if (!this.buffer.modified) {
2148
+ this.statusMessage = `${this.buffer.displayPath} unchanged`;
2149
+ return;
2150
+ }
2151
+ await this.#executeEx(command.force ? "w!" : "w");
2152
+ return;
2153
+ case "write-quit":
2154
+ await this.#executeEx(command.force ? "w!" : "w");
2155
+ this.closed = true;
2156
+ this.statusMessage = `Wrote and closed ${this.buffer.displayPath}`;
2157
+ return;
2158
+ case "quit":
2159
+ if (this.buffer.modified && !command.force) {
2160
+ throw new VimError("Unsaved changes; use :q! to discard");
2161
+ }
2162
+ this.closed = true;
2163
+ this.statusMessage = `Closed ${this.buffer.displayPath}`;
2164
+ return;
2165
+ case "edit": {
2166
+ if (this.buffer.modified && !command.force) {
2167
+ throw new VimError("Unsaved changes; use :e! to reload or force open");
2168
+ }
2169
+ const next = await this.#callbacks.loadBuffer(command.path ?? this.buffer.displayPath);
2170
+ this.buffer.replaceLoadedFile(next);
2171
+ this.inputMode = "normal";
2172
+ this.selectionAnchor = null;
2173
+ this.#pendingInput = "";
2174
+ this.#pendingChange = null;
2175
+ this.#undoStack = [];
2176
+ this.#redoStack = [];
2177
+ this.statusMessage = command.path
2178
+ ? `Opened ${this.buffer.displayPath}`
2179
+ : `Reloaded ${this.buffer.displayPath}`;
2180
+ return;
2181
+ }
2182
+ case "substitute": {
2183
+ const range = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2184
+ const startLine = range.start;
2185
+ const endLine = range.end;
2186
+ const regexFlags = command.flags.includes("i") ? "gi" : "g";
2187
+ const regex = createSearchRegex(command.pattern, regexFlags);
2188
+ let replacements = 0;
2189
+ await this.#applyAtomicChange([":substitute"], () => {
2190
+ for (let lineIndex = startLine - 1; lineIndex <= endLine - 1; lineIndex += 1) {
2191
+ const line = this.buffer.getLine(lineIndex);
2192
+ let lineReplacements = 0;
2193
+ const nextLine = line.replace(regex, match => {
2194
+ if (!command.flags.includes("g") && lineReplacements > 0) {
2195
+ return match;
2196
+ }
2197
+ lineReplacements += 1;
2198
+ replacements += 1;
2199
+ return decodeReplacement(command.replacement).replace(/&/g, match);
2200
+ });
2201
+ this.buffer.replaceLine(lineIndex, nextLine);
2202
+ regex.lastIndex = 0;
2203
+ }
2204
+ });
2205
+ if (replacements === 0) {
2206
+ throw new VimError(`Pattern not found: ${command.pattern}`);
2207
+ }
2208
+ this.statusMessage = `${replacements} substitution${replacements === 1 ? "" : "s"}`;
2209
+ return;
2210
+ }
2211
+ case "delete": {
2212
+ const range = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2213
+ await this.#applyAtomicChange([":delete"], () => {
2214
+ const removed = this.buffer.deleteLines(range.start - 1, range.end - 1);
2215
+ this.register = { kind: "line", text: removed.join("\n") };
2216
+ });
2217
+ this.statusMessage = `Deleted ${range.end - range.start + 1} line${range.end === range.start ? "" : "s"}`;
2218
+ return;
2219
+ }
2220
+ case "yank": {
2221
+ const range = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2222
+ this.register = {
2223
+ kind: "line",
2224
+ text: this.buffer.lines.slice(range.start - 1, range.end).join("\n"),
2225
+ };
2226
+ this.statusMessage = `Yanked ${range.end - range.start + 1} line${range.end === range.start ? "" : "s"}`;
2227
+ return;
2228
+ }
2229
+ case "put": {
2230
+ if (!this.register.text) {
2231
+ this.statusMessage = "Register empty";
2232
+ return;
2233
+ }
2234
+ const anchorRange = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2235
+ const anchorLine = command.before ? anchorRange.start : anchorRange.end;
2236
+ const lines = this.register.text.split("\n");
2237
+ await this.#applyAtomicChange([":put"], () => {
2238
+ const insertAt = command.before
2239
+ ? Math.max(0, anchorLine - 1)
2240
+ : Math.min(anchorLine, this.buffer.lineCount());
2241
+ this.buffer.insertLines(insertAt, lines);
2242
+ });
2243
+ this.statusMessage = `Put ${lines.length} line${lines.length === 1 ? "" : "s"}`;
2244
+ return;
2245
+ }
2246
+ case "copy": {
2247
+ const totalLines = this.buffer.lineCount();
2248
+ const range = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2249
+ const dest = Math.max(0, Math.min(command.destination, totalLines));
2250
+ await this.#applyAtomicChange([":copy"], () => {
2251
+ const lines = this.buffer.lines.slice(range.start - 1, range.end);
2252
+ this.buffer.insertLines(dest, lines);
2253
+ });
2254
+ this.statusMessage = `Copied ${range.end - range.start + 1} line${range.end === range.start ? "" : "s"}`;
2255
+ return;
2256
+ }
2257
+ case "move": {
2258
+ const totalLines = this.buffer.lineCount();
2259
+ const range = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2260
+ const dest = Math.max(0, Math.min(command.destination, totalLines));
2261
+ await this.#applyAtomicChange([":move"], () => {
2262
+ const lines = this.buffer.lines.splice(range.start - 1, range.end - range.start + 1);
2263
+ const adjustedDest = dest > range.end - 1 ? dest - lines.length : dest;
2264
+ this.buffer.lines.splice(adjustedDest, 0, ...lines);
2265
+ if (this.buffer.lines.length === 0) this.buffer.lines = [""];
2266
+ this.buffer.setCursor({ line: adjustedDest, col: 0 });
2267
+ });
2268
+ this.statusMessage = `Moved ${range.end - range.start + 1} line${range.end === range.start ? "" : "s"}`;
2269
+ return;
2270
+ }
2271
+ case "sort": {
2272
+ const range = this.#resolveExRange(command.range ?? "all", 1, this.buffer.lineCount());
2273
+ const startLine = range.start;
2274
+ const endLine = range.end;
2275
+ const reverse = command.flags.includes("!");
2276
+ const ignoreCase = command.flags.includes("i");
2277
+ await this.#applyAtomicChange([":sort"], () => {
2278
+ const slice = this.buffer.lines.slice(startLine - 1, endLine);
2279
+ slice.sort((a, b) => {
2280
+ const left = ignoreCase ? a.toLowerCase() : a;
2281
+ const right = ignoreCase ? b.toLowerCase() : b;
2282
+ return left < right ? -1 : left > right ? 1 : 0;
2283
+ });
2284
+ if (reverse) slice.reverse();
2285
+ for (let i = 0; i < slice.length; i++) {
2286
+ this.buffer.lines[startLine - 1 + i] = slice[i]!;
2287
+ }
2288
+ });
2289
+ this.statusMessage = `Sorted ${endLine - startLine + 1} line${endLine === startLine ? "" : "s"}`;
2290
+ return;
2291
+ }
2292
+ case "join": {
2293
+ const currentLine = this.buffer.cursor.line + 1;
2294
+ const baseRange = this.#resolveExRange(
2295
+ command.range,
2296
+ currentLine,
2297
+ command.range ? undefined : Math.min(this.buffer.lineCount(), currentLine + 1),
2298
+ );
2299
+ const startLine = baseRange.start;
2300
+ const endLine =
2301
+ baseRange.start === baseRange.end ? Math.min(this.buffer.lineCount(), baseRange.end + 1) : baseRange.end;
2302
+ const lineCount = endLine - startLine + 1;
2303
+ if (lineCount < 2) {
2304
+ this.statusMessage = "Nothing to join";
2305
+ return;
2306
+ }
2307
+ await this.#applyAtomicChange([":join"], () => {
2308
+ const startIndex = startLine - 1;
2309
+ if (command.trimWhitespace) {
2310
+ this.buffer.joinLines(startIndex, lineCount - 1);
2311
+ return;
2312
+ }
2313
+ const joined = this.buffer.lines.slice(startIndex, endLine).join("");
2314
+ this.buffer.lines.splice(startIndex, lineCount, joined);
2315
+ this.buffer.setCursor({ line: startIndex, col: Math.max(0, joined.length - 1) });
2316
+ });
2317
+ this.statusMessage = `Joined ${lineCount} lines`;
2318
+ return;
2319
+ }
2320
+ case "append": {
2321
+ const anchorRange = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2322
+ const anchorLine = anchorRange.end;
2323
+ const lines = command.text.length > 0 ? command.text.split("\n") : [""];
2324
+ await this.#applyAtomicChange([":append"], () => {
2325
+ const insertAt = Math.min(anchorLine, this.buffer.lineCount());
2326
+ this.buffer.insertLines(insertAt, lines);
2327
+ });
2328
+ this.statusMessage = `Appended ${lines.length} line${lines.length === 1 ? "" : "s"}`;
2329
+ return;
2330
+ }
2331
+ case "insert-before": {
2332
+ const anchorRange = this.#resolveExRange(command.range, this.buffer.cursor.line + 1);
2333
+ const anchorLine = anchorRange.start;
2334
+ const lines = command.text.length > 0 ? command.text.split("\n") : [""];
2335
+ await this.#applyAtomicChange([":insert"], () => {
2336
+ const insertAt = Math.max(0, anchorLine - 1);
2337
+ this.buffer.insertLines(insertAt, lines);
2338
+ });
2339
+ this.statusMessage = `Inserted ${lines.length} line${lines.length === 1 ? "" : "s"}`;
2340
+ return;
2341
+ }
2342
+ case "global": {
2343
+ const regex = createSearchRegex(command.pattern);
2344
+ const range = this.#resolveExRange(command.range ?? "all", 1, this.buffer.lineCount());
2345
+ await this.#applyAtomicChange([":global"], () => {
2346
+ const linesToProcess: number[] = [];
2347
+ for (let i = range.start - 1; i <= range.end - 1; i += 1) {
2348
+ const matches = regex.test(this.buffer.getLine(i));
2349
+ regex.lastIndex = 0;
2350
+ if (command.invert ? !matches : matches) {
2351
+ linesToProcess.push(i);
2352
+ }
2353
+ }
2354
+ if (command.command === "d" || command.command === "delete") {
2355
+ // Delete matching lines in reverse to preserve indices
2356
+ for (let i = linesToProcess.length - 1; i >= 0; i--) {
2357
+ this.buffer.lines.splice(linesToProcess[i]!, 1);
2358
+ }
2359
+ if (this.buffer.lines.length === 0) this.buffer.lines = [""];
2360
+ this.buffer.clampCursor();
2361
+ this.buffer.trailingNewline = true;
2362
+ } else {
2363
+ throw new VimError(`Unsupported :global sub-command: ${command.command}`);
2364
+ }
2365
+ });
2366
+ this.statusMessage = `Global: processed ${command.pattern}`;
2367
+ return;
2368
+ }
2369
+ }
2370
+ }
2371
+
2372
+ #paste(after: boolean, count: number): void {
2373
+ if (!this.register.text) {
2374
+ return;
2375
+ }
2376
+ if (this.register.kind === "line") {
2377
+ const lines = this.register.text.split("\n");
2378
+ const insertAt = after ? this.buffer.cursor.line + 1 : this.buffer.cursor.line;
2379
+ for (let iteration = 0; iteration < count; iteration += 1) {
2380
+ this.buffer.insertLines(insertAt + iteration * lines.length, lines);
2381
+ }
2382
+ return;
2383
+ }
2384
+ const text = this.register.text.repeat(count);
2385
+ const offset = this.buffer.currentOffset() + (after ? 1 : 0);
2386
+ this.buffer.replaceOffsets(offset, offset, text, offset + text.length);
2387
+ }
2388
+
2389
+ #readCount(tokens: readonly VimKeyToken[], index: number): { count: number; hasCount: boolean; nextIndex: number } {
2390
+ let cursor = index;
2391
+ let digits = "";
2392
+ while (cursor < tokens.length) {
2393
+ const value = tokens[cursor]?.value ?? "";
2394
+ if (!/^\d$/.test(value)) {
2395
+ break;
2396
+ }
2397
+ if (digits.length === 0 && value === "0") {
2398
+ break;
2399
+ }
2400
+ digits += value;
2401
+ cursor += 1;
2402
+ }
2403
+ return {
2404
+ count: digits.length > 0 ? Number.parseInt(digits, 10) : 1,
2405
+ hasCount: digits.length > 0,
2406
+ nextIndex: cursor,
2407
+ };
2408
+ }
2409
+ }