@pencil-agent/nano-pencil 2.0.0-beta.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/README.md +267 -267
  2. package/dist/build-meta.json +3 -3
  3. package/dist/core/export-html/AGENT.md +11 -11
  4. package/dist/core/export-html/template.css +971 -971
  5. package/dist/core/export-html/template.html +54 -54
  6. package/dist/core/extensions-host/index.d.ts +1 -1
  7. package/dist/core/extensions-host/loader.js +1 -1
  8. package/dist/core/extensions-host/runner.d.ts +1 -0
  9. package/dist/core/extensions-host/runner.js +2 -2
  10. package/dist/core/extensions-host/types.d.ts +17 -22
  11. package/dist/core/lib/ai/src/types.d.ts +12 -2
  12. package/dist/core/persona/persona-manager.js +5 -2
  13. package/dist/core/runtime/agent-session.js +3 -3
  14. package/dist/core/runtime/extension-core-bindings.d.ts +1 -0
  15. package/dist/core/runtime/extension-core-bindings.js +2 -2
  16. package/dist/extensions/builtin/AGENT.md +115 -115
  17. package/dist/extensions/builtin/browser/AGENT.md +17 -17
  18. package/dist/extensions/builtin/browser/agent-workspace/agent_helpers.py +12 -12
  19. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/amazon/product-search.md +198 -198
  20. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/archive-org/scraping.md +341 -341
  21. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/arxiv/scraping.md +311 -311
  22. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/arxiv-bulk/scraping.md +333 -333
  23. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/atlas/overview.md +70 -70
  24. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/booking-com/scraping.md +578 -578
  25. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/capterra/scraping.md +440 -440
  26. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/centilebrain/generate-estimates.md +110 -110
  27. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coingecko/scraping.md +325 -325
  28. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coinmarketcap/scraping.md +463 -463
  29. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coursera/scraping.md +360 -360
  30. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/craigslist/scraping.md +390 -390
  31. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/crossref/scraping.md +568 -568
  32. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/dev-to/scraping.md +323 -323
  33. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/duckduckgo/scraping.md +349 -349
  34. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/ebay/scraping.md +435 -435
  35. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/etsy/scraping.md +506 -506
  36. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/eventbrite/scraping.md +363 -363
  37. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/expedia/automation.md +168 -168
  38. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/facebook/groups.md +236 -236
  39. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/facebook/pages.md +295 -295
  40. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/framer/editor.md +108 -108
  41. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/fred/scraping.md +493 -493
  42. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/g2/scraping.md +580 -580
  43. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/genius/scraping.md +511 -511
  44. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/github/repo-actions.md +65 -65
  45. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/github/scraping.md +184 -184
  46. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/glassdoor/scraping.md +543 -543
  47. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/gmail/compose.md +122 -122
  48. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/goodreads/scraping.md +461 -461
  49. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/gutenberg/scraping.md +383 -383
  50. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/hackernews/scraping.md +243 -243
  51. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/howlongtobeat/scraping.md +473 -473
  52. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/imdb/scraping.md +271 -271
  53. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/itch-io/scraping.md +436 -436
  54. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/job-boards/indeed-glassdoor.md +1021 -1021
  55. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/letterboxd/scraping.md +349 -349
  56. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/linkedin/invitation-manager.md +109 -109
  57. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/loom/folder-enumeration.md +170 -170
  58. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/macrotrends/scraping.md +537 -537
  59. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/medium/article-hydration.md +120 -120
  60. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/medium/scraping.md +414 -414
  61. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/metacritic/scraping.md +477 -477
  62. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/musicbrainz/scraping.md +478 -478
  63. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/nasa/scraping.md +339 -339
  64. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/news-aggregation/multi-source.md +205 -205
  65. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/open-library/scraping.md +472 -472
  66. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/openalex/scraping.md +470 -470
  67. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/openstreetmap/scraping.md +490 -490
  68. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/package-registries/npm-pypi.md +478 -478
  69. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/polymarket/scraping.md +234 -234
  70. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/producthunt/scraping.md +307 -307
  71. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/pubmed/scraping.md +421 -421
  72. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/quora/scraping.md +364 -364
  73. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/rawg/scraping.md +352 -352
  74. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/reddit/scraping.md +124 -124
  75. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/rest-countries/scraping.md +233 -233
  76. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/sec-edgar/scraping.md +361 -361
  77. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/README.md +36 -36
  78. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/embedded-apps.md +72 -72
  79. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/knowledge-base.md +109 -109
  80. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/polaris-inputs.md +137 -137
  81. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/soundcloud/scraping.md +362 -362
  82. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/spotify/scraping.md +339 -339
  83. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/stackoverflow/scraping.md +435 -435
  84. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/steam/scraping.md +575 -575
  85. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/substack/scraping.md +338 -338
  86. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/thetechgeeks/pricing.md +52 -52
  87. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/tiktok/upload.md +107 -107
  88. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/tradingview/scraping.md +309 -309
  89. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/trello/boards-and-lists.md +88 -88
  90. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/trustpilot/scraping.md +375 -375
  91. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/walmart/scraping.md +444 -444
  92. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/wayback-machine/scraping.md +306 -306
  93. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/weather/scraping.md +398 -398
  94. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/wellfound/scraping.md +596 -596
  95. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/world-bank/scraping.md +356 -356
  96. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/xiaohongshu/scraping.md +84 -84
  97. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/youtube/scraping.md +418 -418
  98. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/zillow/scraping.md +433 -433
  99. package/dist/extensions/builtin/browser/browser.md +73 -73
  100. package/dist/extensions/builtin/browser/install.md +142 -142
  101. package/dist/extensions/builtin/browser/interaction-skills/connection.md +48 -48
  102. package/dist/extensions/builtin/browser/interaction-skills/cookies.md +3 -3
  103. package/dist/extensions/builtin/browser/interaction-skills/cross-origin-iframes.md +3 -3
  104. package/dist/extensions/builtin/browser/interaction-skills/dialogs.md +64 -64
  105. package/dist/extensions/builtin/browser/interaction-skills/downloads.md +3 -3
  106. package/dist/extensions/builtin/browser/interaction-skills/drag-and-drop.md +3 -3
  107. package/dist/extensions/builtin/browser/interaction-skills/dropdowns.md +3 -3
  108. package/dist/extensions/builtin/browser/interaction-skills/iframes.md +3 -3
  109. package/dist/extensions/builtin/browser/interaction-skills/network-requests.md +3 -3
  110. package/dist/extensions/builtin/browser/interaction-skills/print-as-pdf.md +3 -3
  111. package/dist/extensions/builtin/browser/interaction-skills/profile-sync.md +90 -90
  112. package/dist/extensions/builtin/browser/interaction-skills/screenshots.md +17 -17
  113. package/dist/extensions/builtin/browser/interaction-skills/scrolling.md +3 -3
  114. package/dist/extensions/builtin/browser/interaction-skills/shadow-dom.md +3 -3
  115. package/dist/extensions/builtin/browser/interaction-skills/tabs.md +69 -69
  116. package/dist/extensions/builtin/browser/interaction-skills/uploads.md +1 -1
  117. package/dist/extensions/builtin/browser/interaction-skills/viewport.md +3 -3
  118. package/dist/extensions/builtin/browser/src/browser_harness/AGENT.md +15 -15
  119. package/dist/extensions/builtin/browser/src/browser_harness/__init__.py +8 -8
  120. package/dist/extensions/builtin/browser/src/browser_harness/_ipc.py +90 -90
  121. package/dist/extensions/builtin/browser/src/browser_harness/admin.py +722 -722
  122. package/dist/extensions/builtin/browser/src/browser_harness/daemon.py +328 -328
  123. package/dist/extensions/builtin/browser/src/browser_harness/helpers.py +396 -396
  124. package/dist/extensions/builtin/browser/src/browser_harness/run.py +103 -103
  125. package/dist/extensions/builtin/discipline/skills/brainstorming/SKILL.md +33 -33
  126. package/dist/extensions/builtin/discipline/skills/executing-plans/SKILL.md +25 -25
  127. package/dist/extensions/builtin/discipline/skills/finishing-development-branch/SKILL.md +25 -25
  128. package/dist/extensions/builtin/discipline/skills/receiving-code-review/SKILL.md +22 -22
  129. package/dist/extensions/builtin/discipline/skills/requesting-code-review/SKILL.md +31 -31
  130. package/dist/extensions/builtin/discipline/skills/systematic-debugging/SKILL.md +28 -28
  131. package/dist/extensions/builtin/discipline/skills/test-driven-development/SKILL.md +32 -32
  132. package/dist/extensions/builtin/discipline/skills/using-git-worktrees/SKILL.md +25 -25
  133. package/dist/extensions/builtin/discipline/skills/verification-before-completion/SKILL.md +27 -27
  134. package/dist/extensions/builtin/discipline/skills/writing-plans/SKILL.md +26 -26
  135. package/dist/extensions/builtin/goal/README.md +67 -67
  136. package/dist/extensions/builtin/goal/goal-controller.d.ts +39 -10
  137. package/dist/extensions/builtin/goal/goal-controller.js +1 -1
  138. package/dist/extensions/builtin/goal/goal-format.js +1 -1
  139. package/dist/extensions/builtin/goal/goal-prompts.d.ts +2 -0
  140. package/dist/extensions/builtin/goal/goal-prompts.js +5 -4
  141. package/dist/extensions/builtin/goal/goal-store.js +1 -1
  142. package/dist/extensions/builtin/goal/index.d.ts +1 -1
  143. package/dist/extensions/builtin/goal/index.js +10 -7
  144. package/dist/extensions/builtin/grub/README.md +112 -112
  145. package/dist/extensions/builtin/link-world/agent-workspace/README.md +16 -16
  146. package/dist/extensions/builtin/link-world/index.js +6 -6
  147. package/dist/extensions/builtin/link-world/internet-search/internet-search.md +65 -65
  148. package/dist/extensions/builtin/link-world/link-world-agent.md +82 -82
  149. package/dist/extensions/builtin/link-world/linkworld.md +313 -313
  150. package/dist/extensions/builtin/link-world/{network-routing.md → network-routing/network-routing.md} +67 -67
  151. package/dist/extensions/builtin/loop/README.md +92 -92
  152. package/dist/extensions/builtin/mcp/figma-design.md +68 -68
  153. package/dist/extensions/builtin/mcp/mcp-management.md +85 -85
  154. package/dist/extensions/builtin/plan/index.js +1 -1
  155. package/dist/extensions/builtin/recap/AGENT.md +15 -15
  156. package/dist/extensions/builtin/sal/README.md +72 -72
  157. package/dist/extensions/builtin/security-audit/README.md +289 -289
  158. package/dist/extensions/builtin/task/task-store.d.ts +4 -0
  159. package/dist/extensions/builtin/task/task-store.js +1 -1
  160. package/dist/extensions/builtin/team/AGENT.md +112 -112
  161. package/dist/extensions/builtin/team/TESTING.md +299 -299
  162. package/dist/extensions/builtin/token-save/README.md +56 -56
  163. package/dist/extensions/optional/AGENT.md +10 -10
  164. package/dist/index.d.ts +5 -30
  165. package/dist/index.js +1 -1
  166. package/dist/models.d.ts +7 -0
  167. package/dist/models.js +1 -0
  168. package/dist/modes/interactive/components/footer.js +1 -1
  169. package/dist/modes/interactive/components/task-status-panel.d.ts +36 -0
  170. package/dist/modes/interactive/components/task-status-panel.js +1 -0
  171. package/dist/modes/interactive/controllers/stream-render-controller.d.ts +7 -0
  172. package/dist/modes/interactive/controllers/stream-render-controller.js +2 -2
  173. package/dist/modes/interactive/interactive-mode.js +40 -40
  174. package/dist/modes/interactive/state/interactive-state.d.ts +2 -0
  175. package/dist/modes/interactive/state/interactive-state.js +1 -1
  176. package/dist/modes/interactive/theme/dark.json +85 -85
  177. package/dist/modes/interactive/theme/light.json +84 -84
  178. package/dist/modes/interactive/theme/theme-schema.json +335 -335
  179. package/dist/modes/interactive/theme/warm.json +81 -81
  180. package/dist/node_modules/@pencil-agent/ai/dist/cli.js +0 -0
  181. package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +1 -1
  182. package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.js +2 -2
  183. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.js +5 -5
  184. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.js +1 -1
  185. package/dist/node_modules/@pencil-agent/ai/dist/stream.js +1 -1
  186. package/dist/packages/protocol/src/commands.d.ts +33 -0
  187. package/dist/packages/protocol/src/flags.d.ts +20 -0
  188. package/dist/packages/protocol/src/hooks.d.ts +17 -0
  189. package/dist/packages/protocol/src/hooks.js +0 -0
  190. package/dist/packages/{extension-sdk → protocol}/src/index.d.ts +7 -4
  191. package/dist/packages/protocol/src/index.js +1 -0
  192. package/dist/packages/{extension-sdk → protocol}/src/lifecycle.d.ts +15 -27
  193. package/dist/packages/protocol/src/lifecycle.js +0 -0
  194. package/dist/packages/{extension-sdk → protocol}/src/tools.d.ts +1 -1
  195. package/dist/packages/protocol/src/tools.js +0 -0
  196. package/dist/public-config.d.ts +12 -0
  197. package/dist/public-config.js +1 -0
  198. package/dist/runtime.d.ts +9 -0
  199. package/dist/runtime.js +1 -0
  200. package/dist/session-compaction.d.ts +7 -0
  201. package/dist/session-compaction.js +1 -0
  202. package/dist/session.d.ts +7 -0
  203. package/dist/session.js +1 -0
  204. package/dist/skills.d.ts +7 -0
  205. package/dist/skills.js +1 -0
  206. package/dist/tools.d.ts +7 -0
  207. package/dist/tools.js +1 -0
  208. package/docs/ACP/345/215/217/350/256/256/351/233/206/346/210/220/345/274/200/345/217/221/346/226/207/346/241/243.md +851 -0
  209. package/docs/SDK-TESTING.md +364 -0
  210. package/docs/codex-goal-command-impl.md +1055 -1055
  211. package/docs/codex-goal-vs-grub.md +500 -500
  212. package/docs/custom-provider.md +27 -27
  213. package/docs/extensions.md +27 -27
  214. package/docs/keybindings.md +27 -27
  215. package/docs/loop /351/207/215/346/236/204/345/256/214/346/210/220/346/200/273/347/273/223.md" +250 -250
  216. package/docs/loop /351/207/215/346/236/204/345/256/214/346/210/220/346/212/245/345/221/212.md" +122 -122
  217. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210.md" +1222 -1222
  218. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210/345/256/236/347/216/260/346/212/245/345/221/212.md" +158 -158
  219. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210/345/257/271/346/257/224/345/210/206/346/236/220.md" +128 -128
  220. package/docs/loop /351/207/215/346/236/204/350/256/241/345/210/222.md" +320 -320
  221. package/docs/loop-usage-examples.md +214 -214
  222. package/docs/mem-core/346/212/200/346/234/257/346/226/207/346/241/243.md +593 -0
  223. package/docs/models.md +27 -27
  224. package/docs/packages.md +27 -27
  225. package/docs/pi-design-philosophy.md +457 -457
  226. package/docs/planmode.md +1987 -1987
  227. package/docs/prompt-templates.md +27 -27
  228. package/docs/providers.md +27 -27
  229. package/docs/sdk.md +27 -27
  230. package/docs/skills.md +27 -27
  231. package/docs/startup-performance-optimization.md +301 -0
  232. package/docs/themes.md +27 -27
  233. package/docs/tui.md +27 -27
  234. package/docs//350/256/244/347/237/245/345/234/260/345/233/276.md +47 -0
  235. package/package.json +190 -162
  236. package/dist/packages/extension-sdk/src/index.js +0 -1
  237. package/docs/cc-agent-design.md +0 -1297
  238. package/docs/cc-tui-design.md +0 -1333
  239. package/docs//345/257/271/346/240/207Claude-Code.md +0 -1775
  240. /package/dist/packages/{extension-sdk/src/lifecycle.js → protocol/src/commands.js} +0 -0
  241. /package/dist/packages/{extension-sdk/src/tools.js → protocol/src/flags.js} +0 -0
@@ -1,37 +1,37 @@
1
- var Le=Object.defineProperty;var s=(P,e)=>Le(P,"name",{value:e,configurable:!0});import*as $ from"node:fs";import*as J from"node:os";import*as q from"node:path";import{CombinedAutocompleteProvider as De,CachedContainer as Be,Container as R,Markdown as me,matchesKey as Ue,ProcessTerminal as Oe,Spacer as u,Text as m,TruncatedText as he,TUI as qe,visibleWidth as pe}from"@pencil-agent/tui";import{spawn as We,spawnSync as de}from"child_process";import{APP_NAME as Y,getDebugLogPath as Fe,getShareViewerUrl as Ne,VERSION as He}from"../../config.js";import{parseSkillBlock as Ke}from"../../core/runtime/agent-session.js";import{FooterDataProvider as _e}from"./footer-data-provider.js";import{KeybindingsManager as je}from"../../core/platform/keybindings.js";import{createCompactionSummaryMessage as Qe}from"../../core/messages.js";import{listMCPServers as fe,setMCPServerEnabled as Ge}from"../../core/mcp/mcp-config.js";import{getExtensionBackedBuiltinCommandNames as Ve,formatSlashCommandDescription as Z,getLocalizedCommands as ze,inferSlashCommandCategory as le}from"../../core/slash-commands.js";import{t as H}from"../../core/platform/i18n/index.js";import{getActivePersonaId as ee,getPersonaDescription as Xe,getPersonaDir as te,getPersonaMcpConfigPath as Ce,getPersonaMemoryDir as we,getPersonaSoulDir as ye,listPersonas as Se,setActivePersonaId as Me,toAbsolutePath as A}from"../../core/persona/persona-manager.js";import{NANOPENCIL_WHATS_NEW as Je}from"../../nanopencil-defaults.js";import{getChangelogPath as Ye,parseChangelog as Ze}from"../../utils/changelog.js";import{copyToClipboard as et}from"../utils/clipboard.js";import{ensureTool as be,getToolPath as Te,prewarmTool as Ee}from"../../core/platform/utils/tools-manager.js";import{printTimings as tt,time as K}from"../../core/platform/timings.js";import{ArminComponent as st}from"./components/armin.js";import{ImagePipelineController as it}from"./controllers/image-pipeline-controller.js";import{SelfUpdateController as nt}from"./controllers/self-update-controller.js";import{InteractiveState as ot}from"./state/interactive-state.js";import{PersistentSurfaceRegistry as at}from"./controllers/extension-ui/persistent-surface-registry.js";import{PromptHost as rt}from"./controllers/extension-ui/prompt-host.js";import{CustomOverlayHost as ht}from"./controllers/extension-ui/custom-overlay-host.js";import{EditorComponentAdapter as dt}from"./controllers/extension-ui/editor-component-adapter.js";import{ModelOverlayController as lt}from"./controllers/model-overlay-controller.js";import{AuthProviderConfigController as ct}from"./controllers/auth-provider-config-controller.js";import{TreeOverlayController as ut}from"./controllers/tree-overlay-controller.js";import{SettingsOverlayController as gt}from"./controllers/settings-overlay-controller.js";import{SlashDispatcherController as mt}from"./controllers/slash-dispatcher-controller.js";import{InputSubmitController as pt}from"./controllers/input-submit-controller.js";import{InterruptController as ft}from"./controllers/interrupt-controller.js";import{StreamRenderController as Ct}from"./controllers/stream-render-controller.js";import{AssistantMessageComponent as xe}from"./components/assistant-message.js";import{BashExecutionComponent as ce}from"./components/bash-execution.js";import{BorderedLoader as Pe}from"./components/bordered-loader.js";import{BuddyPetComponent as wt}from"./components/buddy/pet-sprites.js";import{EditorBuddyLayout as yt}from"./components/editor-buddy-layout.js";import{BranchSummaryMessageComponent as St}from"./components/branch-summary-message.js";import{PencilLoader as Mt}from"./components/pencil-loader.js";import{NotificationQueue as bt}from"./components/notification-queue.js";import{PersonaSelectorComponent as Tt}from"./components/persona-selector.js";import{CompactionSummaryMessageComponent as Et}from"./components/compaction-summary-message.js";import{CustomEditor as xt}from"./components/custom-editor.js";import{CustomMessageComponent as Pt}from"./components/custom-message.js";import{DaxnutsComponent as kt}from"./components/daxnuts.js";import{DynamicBorder as se}from"./components/dynamic-border.js";import{FooterComponent as $t,renderContextProgressBar as At}from"./components/footer.js";import{appKey as D,appKeyHint as Rt,editorKey as vt,keyHint as It,rawKeyHint as W}from"./components/keybinding-hints.js";import{formatSoulStats as Lt}from"./components/soul-stats.js";import{SkillInvocationMessageComponent as Dt}from"./components/skill-invocation-message.js";import{ToolExecutionComponent as ke}from"./components/tool-execution.js";import{UserMessageComponent as $e}from"./components/user-message.js";import{RawText as Bt}from"./components/raw-text.js";import{getAvailableThemesWithPaths as Ut,getEditorTheme as Ot,getMarkdownTheme as qt,getThemeByName as Wt,initTheme as Ft,onThemeChange as Nt,setRegisteredThemes as ue,setTheme as Ae,setThemeInstance as Ht,theme as r}from"./theme/theme.js";import{getAgentLoopArgumentCompletions as Kt,getLanguageArgumentCompletions as _t,getLoginArgumentCompletions as jt,getMcpArgumentCompletions as Qt,getModelArgumentCompletions as Gt,getPersonaArgumentCompletions as Vt,getThinkingArgumentCompletions as zt}from"./slash-command-arguments.js";import{formatAgentLoopStatusLines as Xt}from"./agent-loop-status.js";function Jt(P){return typeof P=="object"&&P!==null&&"setExpanded"in P&&typeof P.setExpanded=="function"}s(Jt,"isExpandable");const Yt=q.join(J.homedir(),".nanopencil","agent","nanopencil-debug.log");function ie(P){$.appendFileSync(Yt,`[${new Date().toISOString()}] [imode] ${P}
2
- `)}s(ie,"_dbg");class ii{static{s(this,"InteractiveMode")}options;session;ui;chatContainer;pendingMessagesContainer;statusContainer;defaultEditor;editor;autocompleteProvider;fdPath;startupToolsPrewarmed=!1;editorContainer;footer;buddyPet=null;buddyPetSpecies=null;buddyPetResetTimer;footerDataProvider;keybindings;version;isInitialized=!1;onInputCallback;catWorkingMessages=["Purring\u2026","Meowing\u2026","Napping\u2026","Stretching\u2026","Zooming\u2026","Sneaking\u2026","Pouncing\u2026","Scratching\u2026","Yawning\u2026","Blinking\u2026","Kneading\u2026","Crouching\u2026","Spinning\u2026","Twitching\u2026","Hiding\u2026"];catMessageIndex=Math.floor(Math.random()*15);catMessageLastSwitch=0;state=new ot;skillCommands=new Map;unsubscribe;isBashMode=!1;bashComponent=void 0;pendingBashComponents=[];shutdownRequested=!1;statusTimers=new Set;notificationQueue;extensionTerminalInputUnsubscribers=new Set;widgetContainerAbove;widgetContainerBelow;buddySlot;editorBuddyLayout;headerContainer;builtInHeader=void 0;attachmentsContainer=void 0;imagePipeline;selfUpdate;authProviderConfig;modelOverlay;treeOverlay;settingsOverlay;slashDispatcher;inputSubmit;interrupt;streamRender;surfaces;promptHost;customOverlay;editorAdapter;get agent(){return this.session.agent}get sessionManager(){return this.session.sessionManager}get settingsManager(){return this.session.settingsManager}constructor(e,n={}){this.options=n,this.session=e,this.version=He,this.ui=new qe(new Oe,this.settingsManager.getShowHardwareCursor()),this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink()),this.headerContainer=new R,this.chatContainer=new Be,this.pendingMessagesContainer=new R,this.statusContainer=new R,this.widgetContainerAbove=new R,this.widgetContainerBelow=new R,this.notificationQueue=new bt(this.ui,r),this.keybindings=je.create();const i=this.settingsManager.getEditorPaddingX(),o=this.settingsManager.getAutocompleteMaxVisible();this.defaultEditor=new xt(this.ui,Ot(),this.keybindings,{paddingX:i,autocompleteMaxVisible:o}),this.editor=this.defaultEditor,this.editorContainer=new R,this.attachmentsContainer=new R,this.buddySlot=new R,this.editorBuddyLayout=new yt(()=>this.editor,this.buddySlot),this.editorContainer.addChild(this.attachmentsContainer),this.editorContainer.addChild(this.editorBuddyLayout),this.imagePipeline=new it({getCwd:s(()=>this.session.cwd,"getCwd"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),showStatus:s(t=>this.showStatus(t),"showStatus"),getThemeName:s(()=>this.settingsManager.getTheme(),"getThemeName"),isEditorCursorAtTop:s(()=>this.editor.isCursorOnFirstVisualLine?.()??!this.editor.getText().includes(`
3
- `),"isEditorCursorAtTop"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getAttachmentsContainer:s(()=>this.attachmentsContainer,"getAttachmentsContainer"),getEditorBuddyLayout:s(()=>this.editorBuddyLayout,"getEditorBuddyLayout")}),this.selfUpdate=new nt({getChatContainer:s(()=>this.chatContainer,"getChatContainer"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),getAutoUpdate:s(()=>this.settingsManager.getAutoUpdate(),"getAutoUpdate"),getSkippedVersion:s(()=>this.settingsManager.getSkippedVersion(),"getSkippedVersion"),setSkippedVersion:s(t=>this.settingsManager.setSkippedVersion(t),"setSkippedVersion"),setAutoUpdate:s(t=>this.settingsManager.setAutoUpdate(t),"setAutoUpdate"),showSelector:s((t,a)=>this.promptHost.selector(t,a),"showSelector")}),this.surfaces=new at({requestRender:s(()=>this.ui.requestRender(),"requestRender"),getUi:s(()=>this.ui,"getUi"),getWidgetContainerAbove:s(()=>this.widgetContainerAbove,"getWidgetContainerAbove"),getWidgetContainerBelow:s(()=>this.widgetContainerBelow,"getWidgetContainerBelow"),getHeaderContainer:s(()=>this.headerContainer,"getHeaderContainer"),getBuiltInHeader:s(()=>this.builtInHeader,"getBuiltInHeader"),getFooter:s(()=>this.footer,"getFooter"),getFooterDataProvider:s(()=>this.footerDataProvider,"getFooterDataProvider")}),this.promptHost=new rt({getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getUi:s(()=>this.ui,"getUi"),getEditor:s(()=>this.editor,"getEditor"),getEditorBuddyLayout:s(()=>this.editorBuddyLayout,"getEditorBuddyLayout"),getKeybindings:s(()=>this.keybindings,"getKeybindings"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")}),this.customOverlay=new ht({getEditor:s(()=>this.editor,"getEditor"),getUi:s(()=>this.ui,"getUi"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getKeybindings:s(()=>this.keybindings,"getKeybindings"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")}),this.editorAdapter=new dt({getEditor:s(()=>this.editor,"getEditor"),setEditor:s(t=>{this.editor=t},"setEditor"),getDefaultEditor:s(()=>this.defaultEditor,"getDefaultEditor"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getUi:s(()=>this.ui,"getUi"),getKeybindings:s(()=>this.keybindings,"getKeybindings"),getAutocompleteProvider:s(()=>this.autocompleteProvider,"getAutocompleteProvider"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")}),this.footerDataProvider=new _e(e.cwd),this.footer=new $t(e,this.footerDataProvider,this.settingsManager.getShowTokenStats()),this.footer.setAutoCompactEnabled(e.autoCompactionEnabled),this.authProviderConfig=new ct({modelRegistry:this.session.modelRegistry,surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),promptInput:s((t,a,h)=>this.promptHost.input(t,a,h),"promptInput"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),getUi:s(()=>this.ui,"getUi"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getEditor:s(()=>this.editor,"getEditor"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")},modelBridge:{getCurrentModel:s(()=>this.session.model,"getCurrentModel"),setCurrentModel:s(async t=>{await this.session.setModel(t),this.footer.invalidate(),this.updateEditorBorderColor()},"setCurrentModel"),showModelSelector:s((t,a)=>this.modelOverlay.showModelSelector(t,a),"showModelSelector"),applySelectedModel:s(t=>this.modelOverlay.applySelectedModel(t),"applySelectedModel"),updateAvailableProviderCount:s(()=>this.modelOverlay.updateAvailableProviderCount(),"updateAvailableProviderCount")}}),this.modelOverlay=new lt({modelSession:{getModel:s(()=>this.session.model,"getModel"),setModel:s(t=>this.session.setModel(t),"setModel"),cycleModel:s(t=>this.session.cycleModel(t),"cycleModel"),getThinkingLevel:s(()=>this.session.thinkingLevel,"getThinkingLevel"),setThinkingLevel:s(t=>this.session.setThinkingLevel(t),"setThinkingLevel"),cycleThinkingLevel:s(()=>this.session.cycleThinkingLevel(),"cycleThinkingLevel"),getAvailableThinkingLevels:s(()=>this.session.getAvailableThinkingLevels(),"getAvailableThinkingLevels"),getScopedModels:s(()=>this.session.scopedModels,"getScopedModels"),setScopedModels:s(t=>this.session.setScopedModels(t),"setScopedModels")},modelCatalog:{refresh:s(()=>this.session.modelRegistry.refresh(),"refresh"),getAvailable:s(()=>this.session.modelRegistry.getAvailable(),"getAvailable"),getAll:s(()=>this.session.modelRegistry.getAll(),"getAll"),find:s((t,a)=>this.session.modelRegistry.find(t,a),"find"),appendOpenRouterModel:s((t,a)=>this.session.modelRegistry.appendOpenRouterModel(t,a),"appendOpenRouterModel"),getCredentialType:s(t=>this.session.modelRegistry.authStorage.get(t)?.type,"getCredentialType"),getRegistry:s(()=>this.session.modelRegistry,"getRegistry")},modelSettings:{getEnabledModels:s(()=>this.settingsManager.getEnabledModels(),"getEnabledModels"),setEnabledModels:s(t=>this.settingsManager.setEnabledModels(t),"setEnabledModels"),setDefaultModelAndProvider:s((t,a)=>this.settingsManager.setDefaultModelAndProvider(t,a),"setDefaultModelAndProvider")},providerConfig:{ensureProviderConfiguredForSelection:s(t=>this.authProviderConfig.ensureProviderConfiguredForSelection(t),"ensureProviderConfiguredForSelection"),handleProviderSelectionFromSelector:s((t,a)=>this.authProviderConfig.handleProviderSelectionFromSelector(t,a),"handleProviderSelectionFromSelector"),promptForProviderApiKey:s((t,a)=>this.authProviderConfig.promptForProviderApiKey(t,a),"promptForProviderApiKey")},surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),promptInput:s((t,a,h)=>this.promptHost.input(t,a,h),"promptInput"),getUi:s(()=>this.ui,"getUi")},footer:{invalidate:s(()=>this.footer.invalidate(),"invalidate"),setAvailableProviderCount:s(t=>this.footerDataProvider.setAvailableProviderCount(t),"setAvailableProviderCount"),updateEditorBorderColor:s(()=>this.updateEditorBorderColor(),"updateEditorBorderColor")},playDaxnuts:s(()=>this.handleDaxnuts(),"playDaxnuts")}),this.treeOverlay=new ut({session:this.session,getSessionManager:s(()=>this.sessionManager,"getSessionManager"),surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),getUi:s(()=>this.ui,"getUi"),getChatContainer:s(()=>this.chatContainer,"getChatContainer"),getStatusContainer:s(()=>this.statusContainer,"getStatusContainer"),clearChat:s(()=>{this.clearStatusTimers(),this.chatContainer.clear()},"clearChat"),clearTransientSessionUi:s(()=>{this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear(),this.pendingMessagesContainer.clear(),this.state.compactionQueuedMessages=[],this.state.streamingComponent=void 0,this.state.streamingMessage=void 0,this.state.pendingTools.clear(),this.imagePipeline.clearAttachments()},"clearTransientSessionUi"),addSessionNavigationBanner:s(t=>this.addSessionNavigationBanner(t),"addSessionNavigationBanner"),renderInitialMessages:s(()=>this.renderInitialMessages(),"renderInitialMessages"),getEditorText:s(()=>this.editor.getText(),"getEditorText"),setEditorText:s(t=>this.editor.setText(t),"setEditorText"),getEscapeHandler:s(()=>this.defaultEditor.onEscape,"getEscapeHandler"),setEscapeHandler:s(t=>{this.defaultEditor.onEscape=t},"setEscapeHandler")},promptHost:{selector:s((t,a)=>this.promptHost.selector(t,a),"selector"),editor:s((t,a)=>this.promptHost.editor(t,a),"editor")},keybindings:this.keybindings,shutdown:s(()=>this.shutdown(),"shutdown")}),this.settingsOverlay=new gt({session:this.session,settingsManager:this.settingsManager,surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),invalidateUi:s(()=>this.ui.invalidate(),"invalidateUi"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),setShowHardwareCursor:s(t=>this.ui.setShowHardwareCursor(t),"setShowHardwareCursor"),setClearOnShrink:s(t=>this.ui.setClearOnShrink(t),"setClearOnShrink")},footer:{setAutoCompactEnabled:s(t=>this.footer.setAutoCompactEnabled(t),"setAutoCompactEnabled"),setShowTokenStats:s(t=>this.footer.setShowTokenStats(t),"setShowTokenStats"),invalidate:s(()=>this.footer.invalidate(),"invalidate")},editor:{setPaddingX:s(t=>{this.defaultEditor.setPaddingX(t),this.editor!==this.defaultEditor&&this.editor.setPaddingX!==void 0&&this.editor.setPaddingX(t)},"setPaddingX"),setAutocompleteMaxVisible:s(t=>{this.defaultEditor.setAutocompleteMaxVisible(t),this.editor!==this.defaultEditor&&this.editor.setAutocompleteMaxVisible!==void 0&&this.editor.setAutocompleteMaxVisible(t)},"setAutocompleteMaxVisible"),updateBorderColor:s(()=>this.updateEditorBorderColor(),"updateBorderColor")},render:{setToolImagesEnabled:s(t=>{for(const a of this.chatContainer.children)a instanceof ke&&a.setShowImages(t)},"setToolImagesEnabled"),setAssistantThinkingHidden:s(t=>{for(const a of this.chatContainer.children)a instanceof xe&&a.setHideThinkingBlock(t);this.clearStatusTimers(),this.chatContainer.clear()},"setAssistantThinkingHidden"),rebuildChatFromMessages:s(()=>this.rebuildChatFromMessages(),"rebuildChatFromMessages")},getHideThinkingBlock:s(()=>this.state.hideThinkingBlock,"getHideThinkingBlock"),setHideThinkingBlock:s(t=>{this.state.hideThinkingBlock=t},"setHideThinkingBlock"),rebuildAutocomplete:s(()=>this.setupAutocomplete(this.fdPath),"rebuildAutocomplete"),syncBuddyPet:s(()=>this.syncBuddyPet(),"syncBuddyPet")}),this.slashDispatcher=new mt({clearEditor:s(()=>this.editor.setText(""),"clearEditor"),settings:{showSettingsSelector:s(()=>this.settingsOverlay.showSettingsSelector(),"showSettingsSelector")},model:{showScopedModelsSelector:s(()=>this.modelOverlay.showModelsSelector(),"showScopedModelsSelector"),handleModelCommand:s(t=>this.modelOverlay.handleModelCommand(t),"handleModelCommand"),handleThinkingCommand:s(t=>this.modelOverlay.handleThinkingCommand(t),"handleThinkingCommand")},auth:{handleApiKeyCommand:s(()=>this.authProviderConfig.handleApiKeyCommand(),"handleApiKeyCommand"),handleLoginCommand:s(t=>this.authProviderConfig.handleLoginCommand(t),"handleLoginCommand"),showLogoutSelector:s(()=>this.authProviderConfig.showOAuthSelector("logout"),"showLogoutSelector")},tree:{showForkSelector:s(()=>this.treeOverlay.showForkSelector(),"showForkSelector"),showTreeSelector:s(()=>this.treeOverlay.showTreeSelector(),"showTreeSelector"),showSessionSelector:s(()=>this.treeOverlay.showSessionSelector(),"showSessionSelector")},selfUpdate:{handleUpdateCommand:s(()=>this.selfUpdate.handleUpdateCommand(),"handleUpdateCommand"),handleReinstallCommand:s(()=>this.selfUpdate.handleReinstallCommand(),"handleReinstallCommand")},commands:{isExtensionCommand:s(t=>this.isExtensionCommand(t),"isExtensionCommand"),handleAgentLoopCommand:s(t=>this.handleAgentLoopCommand(t),"handleAgentLoopCommand"),handleMcpCommand:s(t=>this.handleMcpCommand(t),"handleMcpCommand"),handleExportCommand:s(t=>this.handleExportCommand(t),"handleExportCommand"),handleShareCommand:s(()=>this.handleShareCommand(),"handleShareCommand"),handleCopyCommand:s(()=>this.handleCopyCommand(),"handleCopyCommand"),handleStatusCommand:s(()=>this.handleStatusCommand(),"handleStatusCommand"),handleUsageCommand:s(()=>this.handleUsageCommand(),"handleUsageCommand"),handleNameCommand:s(t=>this.handleNameCommand(t),"handleNameCommand"),handleSessionCommand:s(()=>this.handleSessionCommand(),"handleSessionCommand"),handleChangelogCommand:s(()=>this.handleChangelogCommand(),"handleChangelogCommand"),handleHotkeysCommand:s(()=>this.handleHotkeysCommand(),"handleHotkeysCommand"),handleShowResourcesCommand:s(()=>this.handleShowResourcesCommand(),"handleShowResourcesCommand"),handleClearCommand:s(()=>this.handleClearCommand(),"handleClearCommand"),handleCompactCommand:s(t=>this.handleCompactCommand(t),"handleCompactCommand"),handleReloadCommand:s(()=>this.handleReloadCommand(),"handleReloadCommand"),handleLanguageCommand:s(t=>this.handleLanguageCommand(t),"handleLanguageCommand"),handleSoulCommand:s(()=>this.handleSoulCommand(),"handleSoulCommand"),handlePersonaCommand:s(t=>this.handlePersonaCommand(t),"handlePersonaCommand"),handleMemoryCommand:s(()=>this.handleMemoryCommand(),"handleMemoryCommand"),handleArminSaysHi:s(()=>this.handleArminSaysHi(),"handleArminSaysHi"),handleBrowserOptInCommand:s(()=>this.handleBrowserOptInCommand(),"handleBrowserOptInCommand"),shutdown:s(()=>this.shutdown(),"shutdown")}}),this.inputSubmit=new pt({editor:{setText:s(t=>this.editor.setText(t),"setText"),addToHistory:s(t=>this.editor.addToHistory?.(t),"addToHistory"),handleExternalInput:s(t=>this.onInputCallback?(this.onInputCallback(t),this.editor.addToHistory?.(t),!0):!1,"handleExternalInput"),setBashMode:s(t=>{this.isBashMode=t},"setBashMode"),updateBorderColor:s(()=>this.updateEditorBorderColor(),"updateBorderColor")},slash:{execute:s(t=>this.slashDispatcher.execute(t),"execute")},image:{awaitPendingPaste:s(()=>this.imagePipeline.awaitPendingPaste(),"awaitPendingPaste"),extractImagesFromText:s(t=>this.imagePipeline.extractImagesFromText(t),"extractImagesFromText"),takePendingAttachments:s(()=>this.imagePipeline.takePendingAttachments(),"takePendingAttachments"),processAttachmentFiles:s(t=>this.imagePipeline.processAttachmentFiles(t),"processAttachmentFiles"),cleanupClipboardImages:s(()=>this.imagePipeline.cleanupClipboardImages(),"cleanupClipboardImages")},session:{isBashRunning:s(()=>this.session.isBashRunning,"isBashRunning"),isCompacting:s(()=>this.session.isCompacting,"isCompacting"),isStreaming:s(()=>this.session.isStreaming,"isStreaming"),getModel:s(()=>this.session.model,"getModel"),getCwd:s(()=>this.session.cwd,"getCwd"),promptAfterRender:s((t,a)=>this.promptAfterRender(t,a),"promptAfterRender"),queueCompactionMessage:s((t,a)=>this.queueCompactionMessage(t,a),"queueCompactionMessage")},commands:{isExtensionCommand:s(t=>this.isExtensionCommand(t),"isExtensionCommand"),handlePersonaCommand:s(t=>this.handlePersonaCommand(t),"handlePersonaCommand"),handleBashCommand:s((t,a)=>this.handleBashCommand(t,a),"handleBashCommand")},render:{showStatus:s(t=>this.showStatus(t),"showStatus"),showWarning:s(t=>this.showWarning(t),"showWarning"),showError:s(t=>this.showError(t),"showError"),notify:s((t,a)=>this.notify(t,a),"notify"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),flushPendingBashComponents:s(()=>this.flushPendingBashComponents(),"flushPendingBashComponents"),updatePendingMessagesDisplay:s(()=>this.updatePendingMessagesDisplay(),"updatePendingMessagesDisplay"),addOptimisticUserMessage:s((t,a)=>{this.state.optimisticUserMessages.push({text:t}),this.addMessageToChat({role:"user",content:a,timestamp:Date.now()})},"addOptimisticUserMessage"),rollbackFirstOptimisticUserMessageIfMatches:s(t=>{this.state.optimisticUserMessages.length>0&&this.state.optimisticUserMessages[0]?.text===t&&this.state.optimisticUserMessages.shift()},"rollbackFirstOptimisticUserMessageIfMatches")}}),this.interrupt=new ft({queue:{isLoadingAnimationActive:s(()=>!!this.state.loadingAnimation,"isLoadingAnimationActive"),restoreQueuedMessagesWithAbort:s(()=>{this.restoreQueuedMessagesToEditor({abort:!0})},"restoreQueuedMessagesWithAbort")},runtime:{isStreaming:s(()=>this.session.isStreaming,"isStreaming"),isBashRunning:s(()=>this.session.isBashRunning,"isBashRunning"),abortAgent:s(()=>this.agent.abort(),"abortAgent"),abortBash:s(()=>this.session.abortBash(),"abortBash")},bash:{isBashMode:s(()=>this.isBashMode,"isBashMode"),exitBashMode:s(()=>{this.editor.setText(""),this.isBashMode=!1,this.updateEditorBorderColor()},"exitBashMode")},editor:{getText:s(()=>this.editor.getText(),"getText"),clearEditor:s(()=>this.clearEditor(),"clearEditor")},tree:{getDoubleEscapeAction:s(()=>this.settingsManager.getDoubleEscapeAction(),"getDoubleEscapeAction"),showTreeSelector:s(()=>this.treeOverlay.showTreeSelector(),"showTreeSelector"),showForkSelector:s(()=>this.treeOverlay.showForkSelector(),"showForkSelector")},lifecycle:{requestShutdown:s(()=>{this.shutdown()},"requestShutdown"),suspend:s(()=>this.suspend(),"suspend")}}),this.streamRender=new Ct({state:{get:s(()=>this.state,"get")},layout:{getUi:s(()=>this.ui,"getUi"),getChatContainer:s(()=>this.chatContainer,"getChatContainer"),getStatusContainer:s(()=>this.statusContainer,"getStatusContainer"),addMessageToChat:s(t=>this.addMessageToChat(t),"addMessageToChat"),updatePendingMessagesDisplay:s(()=>this.updatePendingMessagesDisplay(),"updatePendingMessagesDisplay"),rebuildChatFromMessages:s(()=>this.rebuildChatFromMessages(),"rebuildChatFromMessages"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),invalidateFooter:s(()=>this.footer.invalidate(),"invalidateFooter")},loaders:{getSessionId:s(()=>this.sessionManager.getSessionId(),"getSessionId"),getDefaultWorkingMessage:s(()=>this.getNextCatMessage(),"getDefaultWorkingMessage"),getInterruptKeyHint:s(()=>D(this.keybindings,"interrupt"),"getInterruptKeyHint"),setBuddyPetState:s((t,a,h)=>this.setBuddyPetState(t,a,h),"setBuddyPetState"),startAgentRunTimer:s(()=>this.startAgentRunTimer(),"startAgentRunTimer"),stopAgentRunTimer:s(()=>this.stopAgentRunTimer(),"stopAgentRunTimer"),updateWorkingMessage:s(t=>this.updateWorkingMessage(t),"updateWorkingMessage"),formatElapsedSeconds:s(t=>this.formatElapsedSeconds(t),"formatElapsedSeconds"),isInPlanMode:s(()=>this.footerDataProvider.getExtensionStatuses().has("plan"),"isInPlanMode")},toolTrace:{shouldRenderToolTrace:s(t=>this.shouldRenderToolTrace(t),"shouldRenderToolTrace"),getRegisteredToolDefinition:s(t=>this.getRegisteredToolDefinition(t),"getRegisteredToolDefinition"),getShowImages:s(()=>this.settingsManager.getShowImages(),"getShowImages")},runtime:{getRetryAttempt:s(()=>this.session.retryAttempt,"getRetryAttempt"),abortCompaction:s(()=>this.session.abortCompaction(),"abortCompaction"),abortRetry:s(()=>this.session.abortRetry(),"abortRetry"),flushCompactionQueue:s(t=>{this.flushCompactionQueue(t)},"flushCompactionQueue"),checkShutdownRequested:s(()=>this.checkShutdownRequested(),"checkShutdownRequested"),clearAttachments:s(()=>this.imagePipeline.clearAttachments(),"clearAttachments")},escape:{getHandler:s(()=>this.defaultEditor.onEscape,"getHandler"),setHandler:s(t=>{this.defaultEditor.onEscape=t},"setHandler")},surface:{ensureInitialized:s(async()=>{this.isInitialized||await this.init()},"ensureInitialized"),restoreEditorFocusIfPossible:s(()=>this.promptHost.restoreEditorFocusIfPossible(),"restoreEditorFocusIfPossible"),getUserMessageText:s(t=>this.getUserMessageText(t),"getUserMessageText"),getMarkdownThemeWithSettings:s(()=>this.getMarkdownThemeWithSettings(),"getMarkdownThemeWithSettings"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError")}}),this.syncBuddyPet(),this.state.hideThinkingBlock=this.settingsManager.getHideThinkingBlock(),ue(this.session.resourceLoader.getThemes().themes),Ft(this.settingsManager.getTheme(),!0),this.session.setSlashCommandExecutor(t=>this.slashDispatcher.execute(t,{clearEditor:!1}))}setupAutocomplete(e){const i=ze(H).map(l=>({name:l.name,description:Z(l.description,l.category,H)})),o=i.find(l=>l.name==="model");o&&(o.getArgumentCompletions=(l,T)=>{const v=this.session.scopedModels.length>0?this.session.scopedModels.map(k=>k.model):this.session.modelRegistry.getAvailable();return Gt(l,T,v)});const t=i.find(l=>l.name==="thinking");t&&(t.getArgumentCompletions=(l,T)=>zt(l,T,this.session.getAvailableThinkingLevels()));const a=i.find(l=>l.name==="agent-loop");a&&(a.getArgumentCompletions=Kt);const h=i.find(l=>l.name==="mcp");h&&(h.getArgumentCompletions=(l,T)=>Qt(l,T,fe()));const c=i.find(l=>l.name==="language");c&&(c.getArgumentCompletions=_t);const d=i.find(l=>l.name==="persona");d&&(d.getArgumentCompletions=(l,T)=>Vt(l,T,Se(),ee()));const g=i.find(l=>l.name==="login");g&&(g.getArgumentCompletions=(l,T)=>jt(l,T,this.authProviderConfig.getLoginSelectorProviders("login")));const C=this.session.promptTemplates.map(l=>({name:l.name,description:Z(l.description,le(l.name,"prompt"),H)})),b=new Set(i.map(l=>l.name)),w=Ve(),E=new Set([...b].filter(l=>!w.has(l))),S=this.session.extensionRunner?.getRegisteredCommands(E)??[],f=new Map(S.map(l=>[l.name,l]));for(const l of i){if(!w.has(l.name))continue;const T=f.get(l.name);T?.getArgumentCompletions&&(l.getArgumentCompletions=T.getArgumentCompletions)}const p=S.filter(l=>!b.has(l.name)).map(l=>({name:l.name,description:Z(l.description??"(extension command)",le(l.name,"extension"),H),getArgumentCompletions:l.getArgumentCompletions}));this.skillCommands.clear();const y=[];if(this.settingsManager.getEnableSkillCommands())for(const l of this.session.resourceLoader.getSkills().skills){const T=`skill:${l.name}`;this.skillCommands.set(T,l.filePath),y.push({name:T,description:Z(l.description,le(l.name,"skill"),H)})}this.autocompleteProvider=new De([...i,...C,...p,...y],this.session.cwd,e),this.defaultEditor.setAutocompleteProvider(this.autocompleteProvider),this.editor!==this.defaultEditor&&this.editor.setAutocompleteProvider?.(this.autocompleteProvider);const M=new Set([...i,...C,...p,...y].map(l=>l.name));this.defaultEditor.enableSlashHighlight(()=>M,r)}prewarmStartupTools(){this.startupToolsPrewarmed||(this.startupToolsPrewarmed=!0,K("interactive.tools.prewarm.start"),Ee("fd"),Ee("rg"),Promise.all([be("fd",!0),be("rg",!0)]).then(([e])=>{const n=e??Te("fd")??void 0;!n||n===this.fdPath||(this.fdPath=n,this.setupAutocomplete(this.fdPath))}).finally(()=>{K("interactive.tools.prewarm.end")}))}async init(){if(!this.isInitialized){if(K("interactive.init.start"),this.imagePipeline.cleanupStaleClipboardFiles(),this.fdPath=Te("fd")??void 0,this.ui.addChild(this.headerContainer),this.options.verbose||!this.settingsManager.getQuietStartup()){const e=r.bold(r.fg("accent",Y))+r.fg("dim",` v${this.version}`),n=Y==="nanopencil"?`${r.fg("dim",Je)}
4
- `:"",i=this.keybindings,o=s((a,h)=>Rt(i,a,h),"hint"),t=[o("interrupt","to interrupt"),o("clear","to clear"),W(`${D(i,"clear")} twice`,"to exit"),o("exit","to exit (empty)"),o("suspend","to suspend"),It("deleteToLineEnd","to delete to end"),o("cycleThinkingLevel","to cycle thinking level"),W(`${D(i,"cycleModelForward")}/${D(i,"cycleModelBackward")}`,"to cycle models"),o("selectModel","to select model"),o("selectProviderThenModel","to select provider then model"),o("expandTools","to expand tools"),o("toggleThinking","to expand thinking"),o("externalEditor","for external editor"),W("/","for commands"),W("!","to run bash"),W("!!","to run bash (no context)"),o("followUp","to queue follow-up"),o("dequeue","to edit all queued messages"),o("pasteImage","to paste image"),W("drop files","to attach")].join(`
1
+ var Le=Object.defineProperty;var s=(P,e)=>Le(P,"name",{value:e,configurable:!0});import*as k from"node:fs";import*as X from"node:os";import*as U from"node:path";import{CombinedAutocompleteProvider as De,CachedContainer as Be,Container as v,Markdown as me,matchesKey as Ue,ProcessTerminal as Oe,Spacer as u,Text as m,TruncatedText as ae,TUI as qe,visibleWidth as pe}from"@pencil-agent/tui";import{spawn as We,spawnSync as re}from"child_process";import{APP_NAME as J,getDebugLogPath as Fe,getShareViewerUrl as Ne,VERSION as He}from"../../config.js";import{parseSkillBlock as Ke}from"../../core/runtime/agent-session.js";import{FooterDataProvider as _e}from"./footer-data-provider.js";import{KeybindingsManager as je}from"../../core/platform/keybindings.js";import{createCompactionSummaryMessage as Qe}from"../../core/messages.js";import{listMCPServers as fe,setMCPServerEnabled as Ge}from"../../core/mcp/mcp-config.js";import{getExtensionBackedBuiltinCommandNames as Ve,formatSlashCommandDescription as Y,getLocalizedCommands as ze,inferSlashCommandCategory as he}from"../../core/slash-commands.js";import{t as F}from"../../core/platform/i18n/index.js";import{getActivePersonaId as de,getPersonaDescription as Xe,getPersonaDir as le,getPersonaMcpConfigPath as Ce,getPersonaMemoryDir as we,getPersonaSoulDir as ye,listPersonas as Se,setActivePersonaId as be,toAbsolutePath as I}from"../../core/persona/persona-manager.js";import{NANOPENCIL_WHATS_NEW as Je}from"../../nanopencil-defaults.js";import{getChangelogPath as Ye,parseChangelog as Ze}from"../../utils/changelog.js";import{copyToClipboard as et}from"../utils/clipboard.js";import{ensureTool as Me,getToolPath as Te,prewarmTool as Ee}from"../../core/platform/utils/tools-manager.js";import{printTimings as tt,time as N}from"../../core/platform/timings.js";import{ArminComponent as st}from"./components/armin.js";import{ImagePipelineController as it}from"./controllers/image-pipeline-controller.js";import{SelfUpdateController as nt}from"./controllers/self-update-controller.js";import{InteractiveState as ot}from"./state/interactive-state.js";import{PersistentSurfaceRegistry as at}from"./controllers/extension-ui/persistent-surface-registry.js";import{PromptHost as rt}from"./controllers/extension-ui/prompt-host.js";import{CustomOverlayHost as ht}from"./controllers/extension-ui/custom-overlay-host.js";import{EditorComponentAdapter as dt}from"./controllers/extension-ui/editor-component-adapter.js";import{ModelOverlayController as lt}from"./controllers/model-overlay-controller.js";import{AuthProviderConfigController as ct}from"./controllers/auth-provider-config-controller.js";import{TreeOverlayController as ut}from"./controllers/tree-overlay-controller.js";import{SettingsOverlayController as gt}from"./controllers/settings-overlay-controller.js";import{SlashDispatcherController as mt}from"./controllers/slash-dispatcher-controller.js";import{InputSubmitController as pt}from"./controllers/input-submit-controller.js";import{InterruptController as ft}from"./controllers/interrupt-controller.js";import{StreamRenderController as Ct}from"./controllers/stream-render-controller.js";import{AssistantMessageComponent as xe}from"./components/assistant-message.js";import{BashExecutionComponent as ce}from"./components/bash-execution.js";import{BorderedLoader as Pe}from"./components/bordered-loader.js";import{BuddyPetComponent as wt}from"./components/buddy/pet-sprites.js";import{EditorBuddyLayout as yt}from"./components/editor-buddy-layout.js";import{BranchSummaryMessageComponent as St}from"./components/branch-summary-message.js";import{PencilLoader as bt}from"./components/pencil-loader.js";import{NotificationQueue as Mt}from"./components/notification-queue.js";import{PersonaSelectorComponent as Tt}from"./components/persona-selector.js";import{CompactionSummaryMessageComponent as Et}from"./components/compaction-summary-message.js";import{CustomEditor as xt}from"./components/custom-editor.js";import{CustomMessageComponent as Pt}from"./components/custom-message.js";import{DaxnutsComponent as kt}from"./components/daxnuts.js";import{DynamicBorder as Z}from"./components/dynamic-border.js";import{FooterComponent as $t,renderContextProgressBar as At}from"./components/footer.js";import{appKey as L,appKeyHint as Rt,editorKey as vt,keyHint as It,rawKeyHint as O}from"./components/keybinding-hints.js";import{formatSoulStats as Lt}from"./components/soul-stats.js";import{SkillInvocationMessageComponent as Dt}from"./components/skill-invocation-message.js";import{ToolExecutionComponent as ke}from"./components/tool-execution.js";import{UserMessageComponent as $e}from"./components/user-message.js";import{RawText as Bt}from"./components/raw-text.js";import{getAvailableThemesWithPaths as Ut,getEditorTheme as Ot,getMarkdownTheme as qt,getThemeByName as Wt,initTheme as Ft,onThemeChange as Nt,setRegisteredThemes as ue,setTheme as Ae,setThemeInstance as Ht,theme as r}from"./theme/theme.js";import{getAgentLoopArgumentCompletions as Kt,getLanguageArgumentCompletions as _t,getLoginArgumentCompletions as jt,getMcpArgumentCompletions as Qt,getModelArgumentCompletions as Gt,getPersonaArgumentCompletions as Vt,getThinkingArgumentCompletions as zt}from"./slash-command-arguments.js";import{formatAgentLoopStatusLines as Xt}from"./agent-loop-status.js";function Jt(P){return typeof P=="object"&&P!==null&&"setExpanded"in P&&typeof P.setExpanded=="function"}s(Jt,"isExpandable");const Yt=U.join(X.homedir(),".nanopencil","agent","nanopencil-debug.log");function ee(P){k.appendFileSync(Yt,`[${new Date().toISOString()}] [imode] ${P}
2
+ `)}s(ee,"_dbg");class ii{static{s(this,"InteractiveMode")}options;session;ui;chatContainer;pendingMessagesContainer;statusContainer;defaultEditor;editor;autocompleteProvider;fdPath;startupToolsPrewarmed=!1;editorContainer;footer;buddyPet=null;buddyPetSpecies=null;buddyPetResetTimer;footerDataProvider;keybindings;version;isInitialized=!1;onInputCallback;catWorkingMessages=["Purring\u2026","Meowing\u2026","Napping\u2026","Stretching\u2026","Zooming\u2026","Sneaking\u2026","Pouncing\u2026","Scratching\u2026","Yawning\u2026","Blinking\u2026","Kneading\u2026","Crouching\u2026","Spinning\u2026","Twitching\u2026","Hiding\u2026"];catMessageIndex=Math.floor(Math.random()*15);catMessageLastSwitch=0;state=new ot;skillCommands=new Map;unsubscribe;isBashMode=!1;bashComponent=void 0;pendingBashComponents=[];shutdownRequested=!1;statusTimers=new Set;notificationQueue;extensionTerminalInputUnsubscribers=new Set;widgetContainerAbove;widgetContainerBelow;buddySlot;editorBuddyLayout;headerContainer;builtInHeader=void 0;attachmentsContainer=void 0;imagePipeline;selfUpdate;authProviderConfig;modelOverlay;treeOverlay;settingsOverlay;slashDispatcher;inputSubmit;interrupt;streamRender;surfaces;promptHost;customOverlay;editorAdapter;get agent(){return this.session.agent}get sessionManager(){return this.session.sessionManager}get settingsManager(){return this.session.settingsManager}constructor(e,n={}){this.options=n,this.session=e,this.version=He,this.ui=new qe(new Oe,this.settingsManager.getShowHardwareCursor()),this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink()),this.headerContainer=new v,this.chatContainer=new Be,this.pendingMessagesContainer=new v,this.statusContainer=new v,this.widgetContainerAbove=new v,this.widgetContainerBelow=new v,this.notificationQueue=new Mt(this.ui,r),this.keybindings=je.create();const i=this.settingsManager.getEditorPaddingX(),o=this.settingsManager.getAutocompleteMaxVisible();this.defaultEditor=new xt(this.ui,Ot(),this.keybindings,{paddingX:i,autocompleteMaxVisible:o}),this.editor=this.defaultEditor,this.editorContainer=new v,this.attachmentsContainer=new v,this.buddySlot=new v,this.editorBuddyLayout=new yt(()=>this.editor,this.buddySlot),this.editorContainer.addChild(this.attachmentsContainer),this.editorContainer.addChild(this.editorBuddyLayout),this.imagePipeline=new it({getCwd:s(()=>this.session.cwd,"getCwd"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),showStatus:s(t=>this.showStatus(t),"showStatus"),getThemeName:s(()=>this.settingsManager.getTheme(),"getThemeName"),isEditorCursorAtTop:s(()=>this.editor.isCursorOnFirstVisualLine?.()??!this.editor.getText().includes(`
3
+ `),"isEditorCursorAtTop"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getAttachmentsContainer:s(()=>this.attachmentsContainer,"getAttachmentsContainer"),getEditorBuddyLayout:s(()=>this.editorBuddyLayout,"getEditorBuddyLayout")}),this.selfUpdate=new nt({getChatContainer:s(()=>this.chatContainer,"getChatContainer"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),getAutoUpdate:s(()=>this.settingsManager.getAutoUpdate(),"getAutoUpdate"),getSkippedVersion:s(()=>this.settingsManager.getSkippedVersion(),"getSkippedVersion"),setSkippedVersion:s(t=>this.settingsManager.setSkippedVersion(t),"setSkippedVersion"),setAutoUpdate:s(t=>this.settingsManager.setAutoUpdate(t),"setAutoUpdate"),showSelector:s((t,a)=>this.promptHost.selector(t,a),"showSelector")}),this.surfaces=new at({requestRender:s(()=>this.ui.requestRender(),"requestRender"),getUi:s(()=>this.ui,"getUi"),getWidgetContainerAbove:s(()=>this.widgetContainerAbove,"getWidgetContainerAbove"),getWidgetContainerBelow:s(()=>this.widgetContainerBelow,"getWidgetContainerBelow"),getHeaderContainer:s(()=>this.headerContainer,"getHeaderContainer"),getBuiltInHeader:s(()=>this.builtInHeader,"getBuiltInHeader"),getFooter:s(()=>this.footer,"getFooter"),getFooterDataProvider:s(()=>this.footerDataProvider,"getFooterDataProvider")}),this.promptHost=new rt({getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getUi:s(()=>this.ui,"getUi"),getEditor:s(()=>this.editor,"getEditor"),getEditorBuddyLayout:s(()=>this.editorBuddyLayout,"getEditorBuddyLayout"),getKeybindings:s(()=>this.keybindings,"getKeybindings"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")}),this.customOverlay=new ht({getEditor:s(()=>this.editor,"getEditor"),getUi:s(()=>this.ui,"getUi"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getKeybindings:s(()=>this.keybindings,"getKeybindings"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")}),this.editorAdapter=new dt({getEditor:s(()=>this.editor,"getEditor"),setEditor:s(t=>{this.editor=t},"setEditor"),getDefaultEditor:s(()=>this.defaultEditor,"getDefaultEditor"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getUi:s(()=>this.ui,"getUi"),getKeybindings:s(()=>this.keybindings,"getKeybindings"),getAutocompleteProvider:s(()=>this.autocompleteProvider,"getAutocompleteProvider"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")}),this.footerDataProvider=new _e(e.cwd),this.footer=new $t(e,this.footerDataProvider,this.settingsManager.getShowTokenStats()),this.footer.setAutoCompactEnabled(e.autoCompactionEnabled),this.authProviderConfig=new ct({modelRegistry:this.session.modelRegistry,surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),promptInput:s((t,a,h)=>this.promptHost.input(t,a,h),"promptInput"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),getUi:s(()=>this.ui,"getUi"),getEditorContainer:s(()=>this.editorContainer,"getEditorContainer"),getEditor:s(()=>this.editor,"getEditor"),remountEditorShell:s(()=>this.remountEditorShell(),"remountEditorShell")},modelBridge:{getCurrentModel:s(()=>this.session.model,"getCurrentModel"),setCurrentModel:s(async t=>{await this.session.setModel(t),this.footer.invalidate(),this.updateEditorBorderColor()},"setCurrentModel"),showModelSelector:s((t,a)=>this.modelOverlay.showModelSelector(t,a),"showModelSelector"),applySelectedModel:s(t=>this.modelOverlay.applySelectedModel(t),"applySelectedModel"),updateAvailableProviderCount:s(()=>this.modelOverlay.updateAvailableProviderCount(),"updateAvailableProviderCount")}}),this.modelOverlay=new lt({modelSession:{getModel:s(()=>this.session.model,"getModel"),setModel:s(t=>this.session.setModel(t),"setModel"),cycleModel:s(t=>this.session.cycleModel(t),"cycleModel"),getThinkingLevel:s(()=>this.session.thinkingLevel,"getThinkingLevel"),setThinkingLevel:s(t=>this.session.setThinkingLevel(t),"setThinkingLevel"),cycleThinkingLevel:s(()=>this.session.cycleThinkingLevel(),"cycleThinkingLevel"),getAvailableThinkingLevels:s(()=>this.session.getAvailableThinkingLevels(),"getAvailableThinkingLevels"),getScopedModels:s(()=>this.session.scopedModels,"getScopedModels"),setScopedModels:s(t=>this.session.setScopedModels(t),"setScopedModels")},modelCatalog:{refresh:s(()=>this.session.modelRegistry.refresh(),"refresh"),getAvailable:s(()=>this.session.modelRegistry.getAvailable(),"getAvailable"),getAll:s(()=>this.session.modelRegistry.getAll(),"getAll"),find:s((t,a)=>this.session.modelRegistry.find(t,a),"find"),appendOpenRouterModel:s((t,a)=>this.session.modelRegistry.appendOpenRouterModel(t,a),"appendOpenRouterModel"),getCredentialType:s(t=>this.session.modelRegistry.authStorage.get(t)?.type,"getCredentialType"),getRegistry:s(()=>this.session.modelRegistry,"getRegistry")},modelSettings:{getEnabledModels:s(()=>this.settingsManager.getEnabledModels(),"getEnabledModels"),setEnabledModels:s(t=>this.settingsManager.setEnabledModels(t),"setEnabledModels"),setDefaultModelAndProvider:s((t,a)=>this.settingsManager.setDefaultModelAndProvider(t,a),"setDefaultModelAndProvider")},providerConfig:{ensureProviderConfiguredForSelection:s(t=>this.authProviderConfig.ensureProviderConfiguredForSelection(t),"ensureProviderConfiguredForSelection"),handleProviderSelectionFromSelector:s((t,a)=>this.authProviderConfig.handleProviderSelectionFromSelector(t,a),"handleProviderSelectionFromSelector"),promptForProviderApiKey:s((t,a)=>this.authProviderConfig.promptForProviderApiKey(t,a),"promptForProviderApiKey")},surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),promptInput:s((t,a,h)=>this.promptHost.input(t,a,h),"promptInput"),getUi:s(()=>this.ui,"getUi")},footer:{invalidate:s(()=>this.footer.invalidate(),"invalidate"),setAvailableProviderCount:s(t=>this.footerDataProvider.setAvailableProviderCount(t),"setAvailableProviderCount"),updateEditorBorderColor:s(()=>this.updateEditorBorderColor(),"updateEditorBorderColor")},playDaxnuts:s(()=>this.handleDaxnuts(),"playDaxnuts")}),this.treeOverlay=new ut({session:this.session,getSessionManager:s(()=>this.sessionManager,"getSessionManager"),surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),getUi:s(()=>this.ui,"getUi"),getChatContainer:s(()=>this.chatContainer,"getChatContainer"),getStatusContainer:s(()=>this.statusContainer,"getStatusContainer"),clearChat:s(()=>{this.clearStatusTimers(),this.chatContainer.clear()},"clearChat"),clearTransientSessionUi:s(()=>{this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear(),this.pendingMessagesContainer.clear(),this.state.compactionQueuedMessages=[],this.state.streamingComponent=void 0,this.state.streamingMessage=void 0,this.state.pendingTools.clear(),this.imagePipeline.clearAttachments()},"clearTransientSessionUi"),addSessionNavigationBanner:s(t=>this.addSessionNavigationBanner(t),"addSessionNavigationBanner"),renderInitialMessages:s(()=>this.renderInitialMessages(),"renderInitialMessages"),getEditorText:s(()=>this.editor.getText(),"getEditorText"),setEditorText:s(t=>this.editor.setText(t),"setEditorText"),getEscapeHandler:s(()=>this.defaultEditor.onEscape,"getEscapeHandler"),setEscapeHandler:s(t=>{this.defaultEditor.onEscape=t},"setEscapeHandler")},promptHost:{selector:s((t,a)=>this.promptHost.selector(t,a),"selector"),editor:s((t,a)=>this.promptHost.editor(t,a),"editor")},keybindings:this.keybindings,shutdown:s(()=>this.shutdown(),"shutdown")}),this.settingsOverlay=new gt({session:this.session,settingsManager:this.settingsManager,surface:{showSelector:s(t=>this.showSelector(t),"showSelector"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError"),invalidateUi:s(()=>this.ui.invalidate(),"invalidateUi"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),setShowHardwareCursor:s(t=>this.ui.setShowHardwareCursor(t),"setShowHardwareCursor"),setClearOnShrink:s(t=>this.ui.setClearOnShrink(t),"setClearOnShrink")},footer:{setAutoCompactEnabled:s(t=>this.footer.setAutoCompactEnabled(t),"setAutoCompactEnabled"),setShowTokenStats:s(t=>this.footer.setShowTokenStats(t),"setShowTokenStats"),invalidate:s(()=>this.footer.invalidate(),"invalidate")},editor:{setPaddingX:s(t=>{this.defaultEditor.setPaddingX(t),this.editor!==this.defaultEditor&&this.editor.setPaddingX!==void 0&&this.editor.setPaddingX(t)},"setPaddingX"),setAutocompleteMaxVisible:s(t=>{this.defaultEditor.setAutocompleteMaxVisible(t),this.editor!==this.defaultEditor&&this.editor.setAutocompleteMaxVisible!==void 0&&this.editor.setAutocompleteMaxVisible(t)},"setAutocompleteMaxVisible"),updateBorderColor:s(()=>this.updateEditorBorderColor(),"updateBorderColor")},render:{setToolImagesEnabled:s(t=>{for(const a of this.chatContainer.children)a instanceof ke&&a.setShowImages(t)},"setToolImagesEnabled"),setAssistantThinkingHidden:s(t=>{for(const a of this.chatContainer.children)a instanceof xe&&a.setHideThinkingBlock(t);this.clearStatusTimers(),this.chatContainer.clear()},"setAssistantThinkingHidden"),rebuildChatFromMessages:s(()=>this.rebuildChatFromMessages(),"rebuildChatFromMessages")},getHideThinkingBlock:s(()=>this.state.hideThinkingBlock,"getHideThinkingBlock"),setHideThinkingBlock:s(t=>{this.state.hideThinkingBlock=t},"setHideThinkingBlock"),rebuildAutocomplete:s(()=>this.setupAutocomplete(this.fdPath),"rebuildAutocomplete"),syncBuddyPet:s(()=>this.syncBuddyPet(),"syncBuddyPet")}),this.slashDispatcher=new mt({clearEditor:s(()=>this.editor.setText(""),"clearEditor"),settings:{showSettingsSelector:s(()=>this.settingsOverlay.showSettingsSelector(),"showSettingsSelector")},model:{showScopedModelsSelector:s(()=>this.modelOverlay.showModelsSelector(),"showScopedModelsSelector"),handleModelCommand:s(t=>this.modelOverlay.handleModelCommand(t),"handleModelCommand"),handleThinkingCommand:s(t=>this.modelOverlay.handleThinkingCommand(t),"handleThinkingCommand")},auth:{handleApiKeyCommand:s(()=>this.authProviderConfig.handleApiKeyCommand(),"handleApiKeyCommand"),handleLoginCommand:s(t=>this.authProviderConfig.handleLoginCommand(t),"handleLoginCommand"),showLogoutSelector:s(()=>this.authProviderConfig.showOAuthSelector("logout"),"showLogoutSelector")},tree:{showForkSelector:s(()=>this.treeOverlay.showForkSelector(),"showForkSelector"),showTreeSelector:s(()=>this.treeOverlay.showTreeSelector(),"showTreeSelector"),showSessionSelector:s(()=>this.treeOverlay.showSessionSelector(),"showSessionSelector")},selfUpdate:{handleUpdateCommand:s(()=>this.selfUpdate.handleUpdateCommand(),"handleUpdateCommand"),handleReinstallCommand:s(()=>this.selfUpdate.handleReinstallCommand(),"handleReinstallCommand")},commands:{isExtensionCommand:s(t=>this.isExtensionCommand(t),"isExtensionCommand"),handleAgentLoopCommand:s(t=>this.handleAgentLoopCommand(t),"handleAgentLoopCommand"),handleMcpCommand:s(t=>this.handleMcpCommand(t),"handleMcpCommand"),handleExportCommand:s(t=>this.handleExportCommand(t),"handleExportCommand"),handleShareCommand:s(()=>this.handleShareCommand(),"handleShareCommand"),handleCopyCommand:s(()=>this.handleCopyCommand(),"handleCopyCommand"),handleStatusCommand:s(()=>this.handleStatusCommand(),"handleStatusCommand"),handleUsageCommand:s(()=>this.handleUsageCommand(),"handleUsageCommand"),handleNameCommand:s(t=>this.handleNameCommand(t),"handleNameCommand"),handleSessionCommand:s(()=>this.handleSessionCommand(),"handleSessionCommand"),handleChangelogCommand:s(()=>this.handleChangelogCommand(),"handleChangelogCommand"),handleHotkeysCommand:s(()=>this.handleHotkeysCommand(),"handleHotkeysCommand"),handleShowResourcesCommand:s(()=>this.handleShowResourcesCommand(),"handleShowResourcesCommand"),handleClearCommand:s(()=>this.handleClearCommand(),"handleClearCommand"),handleCompactCommand:s(t=>this.handleCompactCommand(t),"handleCompactCommand"),handleReloadCommand:s(()=>this.handleReloadCommand(),"handleReloadCommand"),handleLanguageCommand:s(t=>this.handleLanguageCommand(t),"handleLanguageCommand"),handleSoulCommand:s(()=>this.handleSoulCommand(),"handleSoulCommand"),handlePersonaCommand:s(t=>this.handlePersonaCommand(t),"handlePersonaCommand"),handleMemoryCommand:s(()=>this.handleMemoryCommand(),"handleMemoryCommand"),handleArminSaysHi:s(()=>this.handleArminSaysHi(),"handleArminSaysHi"),handleBrowserOptInCommand:s(()=>this.handleBrowserOptInCommand(),"handleBrowserOptInCommand"),shutdown:s(()=>this.shutdown(),"shutdown")}}),this.inputSubmit=new pt({editor:{setText:s(t=>this.editor.setText(t),"setText"),addToHistory:s(t=>this.editor.addToHistory?.(t),"addToHistory"),handleExternalInput:s(t=>this.onInputCallback?(this.onInputCallback(t),this.editor.addToHistory?.(t),!0):!1,"handleExternalInput"),setBashMode:s(t=>{this.isBashMode=t},"setBashMode"),updateBorderColor:s(()=>this.updateEditorBorderColor(),"updateBorderColor")},slash:{execute:s(t=>this.slashDispatcher.execute(t),"execute")},image:{awaitPendingPaste:s(()=>this.imagePipeline.awaitPendingPaste(),"awaitPendingPaste"),extractImagesFromText:s(t=>this.imagePipeline.extractImagesFromText(t),"extractImagesFromText"),takePendingAttachments:s(()=>this.imagePipeline.takePendingAttachments(),"takePendingAttachments"),processAttachmentFiles:s(t=>this.imagePipeline.processAttachmentFiles(t),"processAttachmentFiles"),cleanupClipboardImages:s(()=>this.imagePipeline.cleanupClipboardImages(),"cleanupClipboardImages")},session:{isBashRunning:s(()=>this.session.isBashRunning,"isBashRunning"),isCompacting:s(()=>this.session.isCompacting,"isCompacting"),isStreaming:s(()=>this.session.isStreaming,"isStreaming"),getModel:s(()=>this.session.model,"getModel"),getCwd:s(()=>this.session.cwd,"getCwd"),promptAfterRender:s((t,a)=>this.promptAfterRender(t,a),"promptAfterRender"),queueCompactionMessage:s((t,a)=>this.queueCompactionMessage(t,a),"queueCompactionMessage")},commands:{isExtensionCommand:s(t=>this.isExtensionCommand(t),"isExtensionCommand"),handlePersonaCommand:s(t=>this.handlePersonaCommand(t),"handlePersonaCommand"),handleBashCommand:s((t,a)=>this.handleBashCommand(t,a),"handleBashCommand")},render:{showStatus:s(t=>this.showStatus(t),"showStatus"),showWarning:s(t=>this.showWarning(t),"showWarning"),showError:s(t=>this.showError(t),"showError"),notify:s((t,a)=>this.notify(t,a),"notify"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),flushPendingBashComponents:s(()=>this.flushPendingBashComponents(),"flushPendingBashComponents"),updatePendingMessagesDisplay:s(()=>this.updatePendingMessagesDisplay(),"updatePendingMessagesDisplay"),addOptimisticUserMessage:s((t,a)=>{this.state.optimisticUserMessages.push({text:t}),this.addMessageToChat({role:"user",content:a,timestamp:Date.now()})},"addOptimisticUserMessage"),rollbackFirstOptimisticUserMessageIfMatches:s(t=>{this.state.optimisticUserMessages.length>0&&this.state.optimisticUserMessages[0]?.text===t&&this.state.optimisticUserMessages.shift()},"rollbackFirstOptimisticUserMessageIfMatches")}}),this.interrupt=new ft({queue:{isLoadingAnimationActive:s(()=>!!this.state.loadingAnimation,"isLoadingAnimationActive"),restoreQueuedMessagesWithAbort:s(()=>{this.restoreQueuedMessagesToEditor({abort:!0})},"restoreQueuedMessagesWithAbort")},runtime:{isStreaming:s(()=>this.session.isStreaming,"isStreaming"),isBashRunning:s(()=>this.session.isBashRunning,"isBashRunning"),abortAgent:s(()=>this.agent.abort(),"abortAgent"),abortBash:s(()=>this.session.abortBash(),"abortBash")},bash:{isBashMode:s(()=>this.isBashMode,"isBashMode"),exitBashMode:s(()=>{this.editor.setText(""),this.isBashMode=!1,this.updateEditorBorderColor()},"exitBashMode")},editor:{getText:s(()=>this.editor.getText(),"getText"),clearEditor:s(()=>this.clearEditor(),"clearEditor")},tree:{getDoubleEscapeAction:s(()=>this.settingsManager.getDoubleEscapeAction(),"getDoubleEscapeAction"),showTreeSelector:s(()=>this.treeOverlay.showTreeSelector(),"showTreeSelector"),showForkSelector:s(()=>this.treeOverlay.showForkSelector(),"showForkSelector")},lifecycle:{requestShutdown:s(()=>{this.shutdown()},"requestShutdown"),suspend:s(()=>this.suspend(),"suspend")}}),this.streamRender=new Ct({state:{get:s(()=>this.state,"get")},layout:{getUi:s(()=>this.ui,"getUi"),getChatContainer:s(()=>this.chatContainer,"getChatContainer"),getStatusContainer:s(()=>this.statusContainer,"getStatusContainer"),addMessageToChat:s(t=>this.addMessageToChat(t),"addMessageToChat"),updatePendingMessagesDisplay:s(()=>this.updatePendingMessagesDisplay(),"updatePendingMessagesDisplay"),rebuildChatFromMessages:s(()=>this.rebuildChatFromMessages(),"rebuildChatFromMessages"),requestRender:s(()=>this.ui.requestRender(),"requestRender"),invalidateFooter:s(()=>this.footer.invalidate(),"invalidateFooter")},loaders:{getSessionId:s(()=>this.sessionManager.getSessionId(),"getSessionId"),getDefaultWorkingMessage:s(()=>this.getNextCatMessage(),"getDefaultWorkingMessage"),getInterruptKeyHint:s(()=>L(this.keybindings,"interrupt"),"getInterruptKeyHint"),setBuddyPetState:s((t,a,h)=>this.setBuddyPetState(t,a,h),"setBuddyPetState"),startAgentRunTimer:s(()=>this.startAgentRunTimer(),"startAgentRunTimer"),stopAgentRunTimer:s(()=>this.stopAgentRunTimer(),"stopAgentRunTimer"),updateWorkingMessage:s(t=>this.updateWorkingMessage(t),"updateWorkingMessage"),formatElapsedSeconds:s(t=>this.formatElapsedSeconds(t),"formatElapsedSeconds"),isInPlanMode:s(()=>this.footerDataProvider.getExtensionStatuses().has("plan"),"isInPlanMode")},toolTrace:{shouldRenderToolTrace:s(t=>this.shouldRenderToolTrace(t),"shouldRenderToolTrace"),getRegisteredToolDefinition:s(t=>this.getRegisteredToolDefinition(t),"getRegisteredToolDefinition"),getShowImages:s(()=>this.settingsManager.getShowImages(),"getShowImages")},runtime:{getRetryAttempt:s(()=>this.session.retryAttempt,"getRetryAttempt"),abortCompaction:s(()=>this.session.abortCompaction(),"abortCompaction"),abortRetry:s(()=>this.session.abortRetry(),"abortRetry"),flushCompactionQueue:s(t=>{this.flushCompactionQueue(t)},"flushCompactionQueue"),checkShutdownRequested:s(()=>this.checkShutdownRequested(),"checkShutdownRequested"),clearAttachments:s(()=>this.imagePipeline.clearAttachments(),"clearAttachments"),getAgentDir:s(()=>this.session.agentDir,"getAgentDir")},escape:{getHandler:s(()=>this.defaultEditor.onEscape,"getHandler"),setHandler:s(t=>{this.defaultEditor.onEscape=t},"setHandler")},surface:{ensureInitialized:s(async()=>{this.isInitialized||await this.init()},"ensureInitialized"),restoreEditorFocusIfPossible:s(()=>this.promptHost.restoreEditorFocusIfPossible(),"restoreEditorFocusIfPossible"),getUserMessageText:s(t=>this.getUserMessageText(t),"getUserMessageText"),getMarkdownThemeWithSettings:s(()=>this.getMarkdownThemeWithSettings(),"getMarkdownThemeWithSettings"),showStatus:s(t=>this.showStatus(t),"showStatus"),showError:s(t=>this.showError(t),"showError")}}),this.syncBuddyPet(),this.state.hideThinkingBlock=this.settingsManager.getHideThinkingBlock(),ue(this.session.resourceLoader.getThemes().themes),Ft(this.settingsManager.getTheme(),!0),this.session.setSlashCommandExecutor(t=>this.slashDispatcher.execute(t,{clearEditor:!1}))}setupAutocomplete(e){const i=ze(F).map(l=>({name:l.name,description:Y(l.description,l.category,F)})),o=i.find(l=>l.name==="model");o&&(o.getArgumentCompletions=(l,T)=>{const $=this.session.scopedModels.length>0?this.session.scopedModels.map(A=>A.model):this.session.modelRegistry.getAvailable();return Gt(l,T,$)});const t=i.find(l=>l.name==="thinking");t&&(t.getArgumentCompletions=(l,T)=>zt(l,T,this.session.getAvailableThinkingLevels()));const a=i.find(l=>l.name==="agent-loop");a&&(a.getArgumentCompletions=Kt);const h=i.find(l=>l.name==="mcp");h&&(h.getArgumentCompletions=(l,T)=>Qt(l,T,fe()));const c=i.find(l=>l.name==="language");c&&(c.getArgumentCompletions=_t);const d=i.find(l=>l.name==="persona");d&&(d.getArgumentCompletions=(l,T)=>Vt(l,T,Se(),de()));const g=i.find(l=>l.name==="login");g&&(g.getArgumentCompletions=(l,T)=>jt(l,T,this.authProviderConfig.getLoginSelectorProviders("login")));const C=this.session.promptTemplates.map(l=>({name:l.name,description:Y(l.description,he(l.name,"prompt"),F)})),M=new Set(i.map(l=>l.name)),w=Ve(),E=new Set([...M].filter(l=>!w.has(l))),S=this.session.extensionRunner?.getRegisteredCommands(E)??[],f=new Map(S.map(l=>[l.name,l]));for(const l of i){if(!w.has(l.name))continue;const T=f.get(l.name);T?.getArgumentCompletions&&(l.getArgumentCompletions=T.getArgumentCompletions)}const p=S.filter(l=>!M.has(l.name)).map(l=>({name:l.name,description:Y(l.description??"(extension command)",he(l.name,"extension"),F),getArgumentCompletions:l.getArgumentCompletions}));this.skillCommands.clear();const y=[];if(this.settingsManager.getEnableSkillCommands())for(const l of this.session.resourceLoader.getSkills().skills){const T=`skill:${l.name}`;this.skillCommands.set(T,l.filePath),y.push({name:T,description:Y(l.description,he(l.name,"skill"),F)})}this.autocompleteProvider=new De([...i,...C,...p,...y],this.session.cwd,e),this.defaultEditor.setAutocompleteProvider(this.autocompleteProvider),this.editor!==this.defaultEditor&&this.editor.setAutocompleteProvider?.(this.autocompleteProvider);const b=new Set([...i,...C,...p,...y].map(l=>l.name));this.defaultEditor.enableSlashHighlight(()=>b,r)}prewarmStartupTools(){this.startupToolsPrewarmed||(this.startupToolsPrewarmed=!0,N("interactive.tools.prewarm.start"),Ee("fd"),Ee("rg"),Promise.all([Me("fd",!0),Me("rg",!0)]).then(([e])=>{const n=e??Te("fd")??void 0;!n||n===this.fdPath||(this.fdPath=n,this.setupAutocomplete(this.fdPath))}).finally(()=>{N("interactive.tools.prewarm.end")}))}async init(){if(!this.isInitialized){if(N("interactive.init.start"),this.imagePipeline.cleanupStaleClipboardFiles(),this.fdPath=Te("fd")??void 0,this.ui.addChild(this.headerContainer),this.options.verbose||!this.settingsManager.getQuietStartup()){const e=r.bold(r.fg("accent",J))+r.fg("dim",` v${this.version}`),n=J==="nanopencil"?`${r.fg("dim",Je)}
4
+ `:"",i=this.keybindings,o=s((a,h)=>Rt(i,a,h),"hint"),t=[o("interrupt","to interrupt"),o("clear","to clear"),O(`${L(i,"clear")} twice`,"to exit"),o("exit","to exit (empty)"),o("suspend","to suspend"),It("deleteToLineEnd","to delete to end"),o("cycleThinkingLevel","to cycle thinking level"),O(`${L(i,"cycleModelForward")}/${L(i,"cycleModelBackward")}`,"to cycle models"),o("selectModel","to select model"),o("selectProviderThenModel","to select provider then model"),o("expandTools","to expand tools"),o("toggleThinking","to expand thinking"),o("externalEditor","for external editor"),O("/","for commands"),O("!","to run bash"),O("!!","to run bash (no context)"),o("followUp","to queue follow-up"),o("dequeue","to edit all queued messages"),o("pasteImage","to paste image"),O("drop files","to attach")].join(`
5
5
  `);this.builtInHeader=new m(`${e}
6
- ${n}${t}`,1,0),this.headerContainer.addChild(new u(1)),this.headerContainer.addChild(this.builtInHeader),this.headerContainer.addChild(new u(1))}else this.builtInHeader=new m("",0,0),this.headerContainer.addChild(this.builtInHeader);this.ui.addChild(this.notificationQueue),this.ui.addChild(this.chatContainer),this.ui.addChild(this.pendingMessagesContainer),this.ui.addChild(this.statusContainer),this.surfaces.renderWidgets(),this.ui.addChild(this.widgetContainerAbove),this.ui.addChild(this.editorContainer),this.ui.addChild(this.widgetContainerBelow),this.ui.addChild(this.footer),this.ui.setFocus(this.editor),this.setupKeyHandlers(),this.setupEditorSubmitHandler(),await this.applyPersonaFromSessionIfAny(),await this.initExtensions(),this.renderInitialMessages(),this.ui.start(),K("interactive.ui.start"),this.isInitialized=!0,this.prewarmStartupTools(),this.updateTerminalTitle(),this.subscribeToAgent(),this.chatContainer.clear(),this.renderInitialMessages(),await this.session.extensionRunner?.emit({type:"session_ready"}),Nt(()=>{this.ui.invalidate(),this.updateEditorBorderColor(),this.ui.requestRender()}),this.footerDataProvider.onBranchChange(()=>{this.ui.requestRender()}),await this.modelOverlay.updateAvailableProviderCount(),K("interactive.firstInput.ready"),tt(),this.session.warmupMcpTools()}}updateTerminalTitle(){const e=q.basename(this.session.cwd),n=this.sessionManager.getSessionName();n?this.ui.terminal.setTitle(`\u270E - ${n} - ${e}`):this.ui.terminal.setTitle(`\u270E - ${e}`)}async run(){await this.init();const e=s(()=>{this.shutdown()},"signalShutdown");process.once("SIGHUP",e),process.once("SIGTERM",e),await this.selfUpdate.checkAutoUpdateOnStartup(),this.settingsManager.getAutoUpdate()!=="always"&&this.selfUpdate.checkForNewVersion().then(d=>{d&&this.selfUpdate.showNewVersionNotification(d)});const{migratedProviders:i,modelFallbackMessage:o,initialMessage:t,initialImages:a,initialMessages:h}=this.options;i&&i.length>0&&this.showWarning(`Migrated credentials to auth.json: ${i.join(", ")}`);const c=this.session.modelRegistry.getError();if(c&&this.showError(`models.json error: ${c}`),o&&this.showWarning(o),t)try{await this.session.prompt(t,{images:a})}catch(d){const g=d instanceof Error?d.message:"Unknown error occurred";this.showError(g)}if(h)for(const d of h)try{await this.session.prompt(d)}catch(g){const C=g instanceof Error?g.message:"Unknown error occurred";this.showError(C)}for(;;){const d=await this.getUserInput();ie(`main loop: got input "${d.slice(0,80)}"`);try{await this.session.prompt(d),ie("main loop: prompt returned normally")}catch(g){ie(`main loop: prompt threw: ${g}`);const C=g instanceof Error?g.message:"Unknown error occurred";this.showError(C)}}}getMarkdownThemeWithSettings(){return{...qt(),codeBlockIndent:this.settingsManager.getCodeBlockIndent()}}formatDisplayPath(e){const n=J.homedir();let i=e;return i.startsWith(n)&&(i=`~${i.slice(n.length)}`),i}getShortPath(e,n){const i=e.match(/node_modules\/(@?[^/]+(?:\/[^/]+)?)\/(.*)/);if(i&&n.startsWith("npm:"))return i[2];const o=e.match(/git\/[^/]+\/[^/]+\/(.*)/);return o&&n.startsWith("git:")?o[1]:this.formatDisplayPath(e)}getDisplaySourceInfo(e,n){return e==="local"?n==="user"?{label:"user",color:"muted"}:n==="project"?{label:"project",color:"muted"}:n==="temporary"?{label:"path",scopeLabel:"temp",color:"muted"}:{label:"path",color:"muted"}:e==="cli"?{label:"path",scopeLabel:n==="temporary"?"temp":void 0,color:"muted"}:{label:e,scopeLabel:n==="user"?"user":n==="project"?"project":n==="temporary"?"temp":void 0,color:"accent"}}getScopeGroup(e,n){return e==="cli"||n==="temporary"?"path":n==="user"?"user":n==="project"?"project":"path"}isPackageSource(e){return e.startsWith("npm:")||e.startsWith("git:")}buildScopeGroups(e,n){const i={user:{scope:"user",paths:[],packages:new Map},project:{scope:"project",paths:[],packages:new Map},path:{scope:"path",paths:[],packages:new Map}};for(const o of e){const t=this.findMetadata(o,n),a=t?.source??"local",h=t?.scope??"project",c=this.getScopeGroup(a,h),d=i[c];if(this.isPackageSource(a)){const g=d.packages.get(a)??[];g.push(o),d.packages.set(a,g)}else d.paths.push(o)}return[i.project,i.user,i.path].filter(o=>o.paths.length>0||o.packages.size>0)}formatScopeGroups(e,n){const i=[];for(const o of e){i.push(` ${r.fg("accent",o.scope)}`);const t=[...o.paths].sort((h,c)=>h.localeCompare(c));for(const h of t)i.push(r.fg("dim",` ${n.formatPath(h)}`));const a=Array.from(o.packages.entries()).sort(([h],[c])=>h.localeCompare(c));for(const[h,c]of a){i.push(` ${r.fg("mdLink",h)}`);const d=[...c].sort((g,C)=>g.localeCompare(C));for(const g of d)i.push(r.fg("dim",` ${n.formatPackagePath(g,h)}`))}}return i.join(`
6
+ ${n}${t}`,1,0),this.headerContainer.addChild(new u(1)),this.headerContainer.addChild(this.builtInHeader),this.headerContainer.addChild(new u(1))}else this.builtInHeader=new m("",0,0),this.headerContainer.addChild(this.builtInHeader);this.ui.addChild(this.notificationQueue),this.ui.addChild(this.chatContainer),this.ui.addChild(this.pendingMessagesContainer),this.ui.addChild(this.statusContainer),this.surfaces.renderWidgets(),this.ui.addChild(this.widgetContainerAbove),this.ui.addChild(this.editorContainer),this.ui.addChild(this.widgetContainerBelow),this.ui.addChild(this.footer),this.ui.setFocus(this.editor),this.setupKeyHandlers(),this.setupEditorSubmitHandler(),await this.applyPersonaFromSessionIfAny(),await this.initExtensions(),this.renderInitialMessages(),this.ui.start(),N("interactive.ui.start"),this.isInitialized=!0,this.prewarmStartupTools(),this.updateTerminalTitle(),this.subscribeToAgent(),this.chatContainer.clear(),this.renderInitialMessages(),await this.session.extensionRunner?.emit({type:"session_ready"}),Nt(()=>{this.ui.invalidate(),this.updateEditorBorderColor(),this.ui.requestRender()}),this.footerDataProvider.onBranchChange(()=>{this.ui.requestRender()}),await this.modelOverlay.updateAvailableProviderCount(),N("interactive.firstInput.ready"),tt(),this.session.warmupMcpTools()}}updateTerminalTitle(){const e=U.basename(this.session.cwd),n=this.sessionManager.getSessionName();n?this.ui.terminal.setTitle(`\u270E - ${n} - ${e}`):this.ui.terminal.setTitle(`\u270E - ${e}`)}async run(){await this.init();const e=s(()=>{this.shutdown()},"signalShutdown");process.once("SIGHUP",e),process.once("SIGTERM",e),await this.selfUpdate.checkAutoUpdateOnStartup(),this.settingsManager.getAutoUpdate()!=="always"&&this.selfUpdate.checkForNewVersion().then(d=>{d&&this.selfUpdate.showNewVersionNotification(d)});const{migratedProviders:i,modelFallbackMessage:o,initialMessage:t,initialImages:a,initialMessages:h}=this.options;i&&i.length>0&&this.showWarning(`Migrated credentials to auth.json: ${i.join(", ")}`);const c=this.session.modelRegistry.getError();if(c&&this.showError(`models.json error: ${c}`),o&&this.showWarning(o),t)try{await this.session.prompt(t,{images:a})}catch(d){const g=d instanceof Error?d.message:"Unknown error occurred";this.showError(g)}if(h)for(const d of h)try{await this.session.prompt(d)}catch(g){const C=g instanceof Error?g.message:"Unknown error occurred";this.showError(C)}for(;;){const d=await this.getUserInput();ee(`main loop: got input "${d.slice(0,80)}"`);try{await this.session.prompt(d),ee("main loop: prompt returned normally")}catch(g){ee(`main loop: prompt threw: ${g}`);const C=g instanceof Error?g.message:"Unknown error occurred";this.showError(C)}}}getMarkdownThemeWithSettings(){return{...qt(),codeBlockIndent:this.settingsManager.getCodeBlockIndent()}}formatDisplayPath(e){const n=X.homedir();let i=e;return i.startsWith(n)&&(i=`~${i.slice(n.length)}`),i}getShortPath(e,n){const i=e.match(/node_modules\/(@?[^/]+(?:\/[^/]+)?)\/(.*)/);if(i&&n.startsWith("npm:"))return i[2];const o=e.match(/git\/[^/]+\/[^/]+\/(.*)/);return o&&n.startsWith("git:")?o[1]:this.formatDisplayPath(e)}getDisplaySourceInfo(e,n){return e==="local"?n==="user"?{label:"user",color:"muted"}:n==="project"?{label:"project",color:"muted"}:n==="temporary"?{label:"path",scopeLabel:"temp",color:"muted"}:{label:"path",color:"muted"}:e==="cli"?{label:"path",scopeLabel:n==="temporary"?"temp":void 0,color:"muted"}:{label:e,scopeLabel:n==="user"?"user":n==="project"?"project":n==="temporary"?"temp":void 0,color:"accent"}}getScopeGroup(e,n){return e==="cli"||n==="temporary"?"path":n==="user"?"user":n==="project"?"project":"path"}isPackageSource(e){return e.startsWith("npm:")||e.startsWith("git:")}buildScopeGroups(e,n){const i={user:{scope:"user",paths:[],packages:new Map},project:{scope:"project",paths:[],packages:new Map},path:{scope:"path",paths:[],packages:new Map}};for(const o of e){const t=this.findMetadata(o,n),a=t?.source??"local",h=t?.scope??"project",c=this.getScopeGroup(a,h),d=i[c];if(this.isPackageSource(a)){const g=d.packages.get(a)??[];g.push(o),d.packages.set(a,g)}else d.paths.push(o)}return[i.project,i.user,i.path].filter(o=>o.paths.length>0||o.packages.size>0)}formatScopeGroups(e,n){const i=[];for(const o of e){i.push(` ${r.fg("accent",o.scope)}`);const t=[...o.paths].sort((h,c)=>h.localeCompare(c));for(const h of t)i.push(r.fg("dim",` ${n.formatPath(h)}`));const a=Array.from(o.packages.entries()).sort(([h],[c])=>h.localeCompare(c));for(const[h,c]of a){i.push(` ${r.fg("mdLink",h)}`);const d=[...c].sort((g,C)=>g.localeCompare(C));for(const g of d)i.push(r.fg("dim",` ${n.formatPackagePath(g,h)}`))}}return i.join(`
7
7
  `)}findMetadata(e,n){const i=n.get(e);if(i)return i;let o=e;for(;o.includes("/");){o=o.substring(0,o.lastIndexOf("/"));const t=n.get(o);if(t)return t}}formatPathWithSource(e,n){const i=this.findMetadata(e,n);if(i){const o=this.getShortPath(e,i.source),{label:t,scopeLabel:a}=this.getDisplaySourceInfo(i.source,i.scope);return`${a?`${t} (${a})`:t} ${o}`}return this.formatDisplayPath(e)}formatDiagnostics(e,n){const i=[],o=new Map,t=[];for(const a of e)if(a.type==="collision"&&a.collision){const h=o.get(a.collision.name)??[];h.push(a),o.set(a.collision.name,h)}else t.push(a);for(const[a,h]of o){const c=h[0]?.collision;if(c){i.push(r.fg("warning",` "${a}" collision:`)),i.push(r.fg("dim",` ${r.fg("success","\u2713")} ${this.formatPathWithSource(c.winnerPath,n)}`));for(const d of h)d.collision&&i.push(r.fg("dim",` ${r.fg("warning","\u2717")} ${this.formatPathWithSource(d.collision.loserPath,n)} (skipped)`))}}for(const a of t)if(a.path){const h=this.formatPathWithSource(a.path,n);i.push(r.fg(a.type==="error"?"error":"warning",` ${h}`)),i.push(r.fg(a.type==="error"?"error":"warning",` ${a.message}`))}else i.push(r.fg(a.type==="error"?"error":"warning",` ${a.message}`));return i.join(`
8
8
  `)}showLoadedResources(e){const n=e?.force||this.options.verbose||!this.settingsManager.getQuietStartup(),i=n||e?.showDiagnosticsWhenQuiet===!0;if(!n&&!i)return;const o=this.session.resourceLoader.getPathMetadata(),t=s((d,g="mdHeading")=>r.fg(g,`[${d}]`),"sectionHeader"),a=this.session.resourceLoader.getSkills(),h=this.session.resourceLoader.getPrompts(),c=this.session.resourceLoader.getThemes();if(n){const d=this.session.resourceLoader.getAgentsFiles().agentsFiles;if(d.length>0){this.chatContainer.addChild(new u(1));const S=d.map(f=>r.fg("dim",` ${this.formatDisplayPath(f.path)}`)).join(`
9
9
  `);this.chatContainer.addChild(new m(`${t("Context")}
10
- ${S}`,0,0)),this.chatContainer.addChild(new u(1))}const g=a.skills;if(g.length>0){const S=g.map(y=>y.filePath),f=this.buildScopeGroups(S,o),p=this.formatScopeGroups(f,{formatPath:s(y=>this.formatDisplayPath(y),"formatPath"),formatPackagePath:s((y,M)=>this.getShortPath(y,M),"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Skills")}
11
- ${p}`,0,0)),this.chatContainer.addChild(new u(1))}const C=this.session.promptTemplates;if(C.length>0){const S=C.map(M=>M.filePath),f=this.buildScopeGroups(S,o),p=new Map(C.map(M=>[M.filePath,M])),y=this.formatScopeGroups(f,{formatPath:s(M=>{const l=p.get(M);return l?`/${l.name}`:this.formatDisplayPath(M)},"formatPath"),formatPackagePath:s(M=>{const l=p.get(M);return l?`/${l.name}`:this.formatDisplayPath(M)},"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Prompts")}
12
- ${y}`,0,0)),this.chatContainer.addChild(new u(1))}const b=e?.extensionPaths??[];if(b.length>0){const S=this.buildScopeGroups(b,o),f=this.formatScopeGroups(S,{formatPath:s(p=>this.formatDisplayPath(p),"formatPath"),formatPackagePath:s((p,y)=>this.getShortPath(p,y),"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Extensions","mdHeading")}
13
- ${f}`,0,0)),this.chatContainer.addChild(new u(1))}const E=c.themes.filter(S=>S.sourcePath);if(E.length>0){const S=E.map(y=>y.sourcePath),f=this.buildScopeGroups(S,o),p=this.formatScopeGroups(f,{formatPath:s(y=>this.formatDisplayPath(y),"formatPath"),formatPackagePath:s((y,M)=>this.getShortPath(y,M),"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Themes")}
10
+ ${S}`,0,0)),this.chatContainer.addChild(new u(1))}const g=a.skills;if(g.length>0){const S=g.map(y=>y.filePath),f=this.buildScopeGroups(S,o),p=this.formatScopeGroups(f,{formatPath:s(y=>this.formatDisplayPath(y),"formatPath"),formatPackagePath:s((y,b)=>this.getShortPath(y,b),"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Skills")}
11
+ ${p}`,0,0)),this.chatContainer.addChild(new u(1))}const C=this.session.promptTemplates;if(C.length>0){const S=C.map(b=>b.filePath),f=this.buildScopeGroups(S,o),p=new Map(C.map(b=>[b.filePath,b])),y=this.formatScopeGroups(f,{formatPath:s(b=>{const l=p.get(b);return l?`/${l.name}`:this.formatDisplayPath(b)},"formatPath"),formatPackagePath:s(b=>{const l=p.get(b);return l?`/${l.name}`:this.formatDisplayPath(b)},"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Prompts")}
12
+ ${y}`,0,0)),this.chatContainer.addChild(new u(1))}const M=e?.extensionPaths??[];if(M.length>0){const S=this.buildScopeGroups(M,o),f=this.formatScopeGroups(S,{formatPath:s(p=>this.formatDisplayPath(p),"formatPath"),formatPackagePath:s((p,y)=>this.getShortPath(p,y),"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Extensions","mdHeading")}
13
+ ${f}`,0,0)),this.chatContainer.addChild(new u(1))}const E=c.themes.filter(S=>S.sourcePath);if(E.length>0){const S=E.map(y=>y.sourcePath),f=this.buildScopeGroups(S,o),p=this.formatScopeGroups(f,{formatPath:s(y=>this.formatDisplayPath(y),"formatPath"),formatPackagePath:s((y,b)=>this.getShortPath(y,b),"formatPackagePath")});this.chatContainer.addChild(new m(`${t("Themes")}
14
14
  ${p}`,0,0)),this.chatContainer.addChild(new u(1))}}if(i){const d=a.diagnostics;if(d.length>0){const f=this.formatDiagnostics(d,o);this.chatContainer.addChild(new m(`${r.fg("warning","[Skill conflicts]")}
15
15
  ${f}`,0,0)),this.chatContainer.addChild(new u(1))}const g=h.diagnostics;if(g.length>0){const f=this.formatDiagnostics(g,o);this.chatContainer.addChild(new m(`${r.fg("warning","[Prompt conflicts]")}
16
- ${f}`,0,0)),this.chatContainer.addChild(new u(1))}const C=[],b=this.session.resourceLoader.getExtensions().errors;if(b.length>0)for(const f of b)C.push({type:"error",message:f.error,path:f.path});const w=this.session.extensionRunner?.getCommandDiagnostics()??[];C.push(...w);const E=this.session.extensionRunner?.getShortcutDiagnostics()??[];if(C.push(...E),C.length>0){const f=this.formatDiagnostics(C,o);this.chatContainer.addChild(new m(`${r.fg("warning","[Extension issues]")}
16
+ ${f}`,0,0)),this.chatContainer.addChild(new u(1))}const C=[],M=this.session.resourceLoader.getExtensions().errors;if(M.length>0)for(const f of M)C.push({type:"error",message:f.error,path:f.path});const w=this.session.extensionRunner?.getCommandDiagnostics()??[];C.push(...w);const E=this.session.extensionRunner?.getShortcutDiagnostics()??[];if(C.push(...E),C.length>0){const f=this.formatDiagnostics(C,o);this.chatContainer.addChild(new m(`${r.fg("warning","[Extension issues]")}
17
17
  ${f}`,0,0)),this.chatContainer.addChild(new u(1))}const S=c.diagnostics;if(S.length>0){const f=this.formatDiagnostics(S,o);this.chatContainer.addChild(new m(`${r.fg("warning","[Theme conflicts]")}
18
- ${f}`,0,0)),this.chatContainer.addChild(new u(1))}}}async initExtensions(){const e=this.createExtensionUIContext();await this.session.bindExtensions({uiContext:e,commandContextActions:{waitForIdle:s(()=>this.session.agent.waitForIdle(),"waitForIdle"),newSession:s(async i=>(this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear(),await this.session.newSession(i)?(this.clearStatusTimers(),this.chatContainer.clear(),this.pendingMessagesContainer.clear(),this.state.compactionQueuedMessages=[],this.state.streamingComponent=void 0,this.state.streamingMessage=void 0,this.state.pendingTools.clear(),this.imagePipeline.clearAttachments(),this.renderInitialMessages(),{cancelled:!1}):{cancelled:!0}),"newSession"),fork:s(async i=>{const o=await this.session.fork(i);return o.cancelled?{cancelled:!0}:(this.clearStatusTimers(),this.chatContainer.clear(),this.imagePipeline.clearAttachments(),this.addSessionNavigationBanner("Forked session"),this.renderInitialMessages(),this.editor.setText(o.selectedText),this.showStatus("Forked to new session"),{cancelled:!1})},"fork"),navigateTree:s(async(i,o)=>{const t=await this.session.navigateTree(i,{summarize:o?.summarize,customInstructions:o?.customInstructions,replaceInstructions:o?.replaceInstructions,label:o?.label});return t.cancelled?{cancelled:!0}:(this.clearStatusTimers(),this.chatContainer.clear(),this.imagePipeline.clearAttachments(),this.addSessionNavigationBanner("Navigated session tree"),this.renderInitialMessages(),t.editorText&&!this.editor.getText().trim()&&this.editor.setText(t.editorText),this.showStatus("Navigated to selected point"),{cancelled:!1})},"navigateTree"),switchSession:s(async i=>(await this.treeOverlay.resumeSession(i),{cancelled:!1}),"switchSession"),reload:s(async()=>{await this.handleReloadCommand()},"reload")},shutdownHandler:s(()=>{this.shutdownRequested=!0,this.session.isStreaming||this.shutdown()},"shutdownHandler"),onError:s(i=>{this.showExtensionError(i.extensionPath,i.error,i.stack)},"onError")}),ue(this.session.resourceLoader.getThemes().themes),this.setupAutocomplete(this.fdPath);const n=this.session.extensionRunner;if(!n){this.showLoadedResources({extensionPaths:[],force:!1});return}this.setupExtensionShortcuts(n),this.showLoadedResources({extensionPaths:n.getExtensionPaths(),force:!1})}getRegisteredToolDefinition(e){return(this.session.extensionRunner?.getAllRegisteredTools()??[]).find(o=>o.definition.name===e)?.definition}setupExtensionShortcuts(e){const n=e.getShortcuts(this.keybindings.getEffectiveConfig());n.size!==0&&(this.defaultEditor.onExtensionShortcut=i=>{for(const[o,t]of n)if(Ue(i,o))return Promise.resolve(t.handler(e.createContext())).catch(a=>{this.showError(`Shortcut handler error: ${a instanceof Error?a.message:String(a)}`)}),!0;return!1})}formatElapsedSeconds(e){return`${(Math.max(0,e)/1e3).toFixed(1)}s`}getNextCatMessage(){const e=Date.now();return e-this.catMessageLastSwitch>=1e3&&(this.catMessageIndex++,this.catMessageLastSwitch=e),this.catWorkingMessages[this.catMessageIndex%this.catWorkingMessages.length]}buildWorkingMessage(){const e=this.state.workingMessageOverride||this.getNextCatMessage(),n=`${D(this.keybindings,"interrupt")} to interrupt`,i=this.state.agentRunStartMs!==void 0?this.formatElapsedSeconds(Date.now()-this.state.agentRunStartMs):void 0,o=i?`(${i}, ${n})`:`(${n})`;return{base:e,suffix:o}}updateWorkingMessage(e){if(!this.state.loadingAnimation)return;const{base:n,suffix:i}=this.buildWorkingMessage();this.state.loadingAnimation.setMessage(n,{...e,suffix:i})}stopAgentRunTimer(){this.state.agentRunTimer&&(clearInterval(this.state.agentRunTimer),this.state.agentRunTimer=void 0)}stopWelcomeBannerTimer(){this.state.welcomeBannerTimer&&(clearInterval(this.state.welcomeBannerTimer),this.state.welcomeBannerTimer=void 0)}startAgentRunTimer(){this.stopAgentRunTimer(),this.state.agentRunStartMs=Date.now(),this.state.agentRunTimer=setInterval(()=>{if(!this.state.loadingAnimation||this.state.agentRunStartMs===void 0){this.stopAgentRunTimer();return}this.updateWorkingMessage({resetStallTimer:!1})},100)}resetExtensionUI(){this.promptHost.dismiss(),this.ui.hideOverlay(),this.clearExtensionTerminalInputListeners(),this.surfaces.setFooter(void 0),this.surfaces.setHeader(void 0),this.surfaces.clearWidgets(),this.footerDataProvider.clearExtensionStatuses(),this.footer.invalidate(),this.editorAdapter.setComponent(void 0),this.defaultEditor.onExtensionShortcut=void 0,this.updateTerminalTitle(),this.state.loadingAnimation&&(this.state.workingMessageOverride=void 0,this.updateWorkingMessage())}clearBuddyPetResetTimer(){this.buddyPetResetTimer&&(clearTimeout(this.buddyPetResetTimer),this.buddyPetResetTimer=void 0)}syncBuddyPet(){const e=this.settingsManager.getBuddyEnabled(),n=this.settingsManager.getBuddySpecies();if(!e){this.clearBuddyPetResetTimer(),this.buddyPet?.dispose(),this.buddyPet=null,this.buddyPetSpecies=null,this.buddySlot.clear(),this.surfaces.renderWidgets();return}(!this.buddyPet||this.buddyPetSpecies!==n)&&(this.clearBuddyPetResetTimer(),this.buddyPet?.dispose(),this.buddyPet=new wt(this.ui,n),this.buddyPetSpecies=n,this.buddyPet.setState("idle"),this.buddyPet.setSpeechBubble("")),this.buddySlot.clear(),this.buddySlot.addChild(this.buddyPet),this.surfaces.renderWidgets()}remountEditorShell(){this.editorContainer.clear(),this.imagePipeline.hasAttachments()&&this.attachmentsContainer&&this.editorContainer.addChild(this.attachmentsContainer),this.editorContainer.addChild(this.editorBuddyLayout)}setBuddyPetState(e,n="",i){this.buddyPet&&(this.clearBuddyPetResetTimer(),this.buddyPet.setState(e),this.buddyPet.setSpeechBubble(n),i?.resetTo&&(this.buddyPetResetTimer=setTimeout(()=>{this.buddyPet&&(this.buddyPet.setState(i.resetTo??"idle"),this.buddyPet.setSpeechBubble(""),this.buddyPetResetTimer=void 0,this.ui.requestRender())},i.afterMs??1500)),this.ui.requestRender())}addExtensionTerminalInputListener(e){const n=this.ui.addInputListener(e);return this.extensionTerminalInputUnsubscribers.add(n),()=>{n(),this.extensionTerminalInputUnsubscribers.delete(n)}}clearExtensionTerminalInputListeners(){for(const e of this.extensionTerminalInputUnsubscribers)e();this.extensionTerminalInputUnsubscribers.clear()}createExtensionUIContext(){return{select:s((e,n,i)=>this.promptHost.selector(e,n,i),"select"),confirm:s((e,n,i)=>this.promptHost.confirm(e,n,i),"confirm"),input:s((e,n,i)=>this.promptHost.input(e,n,i),"input"),notify:s((e,n)=>this.showExtensionNotify(e,n),"notify"),onTerminalInput:s(e=>this.addExtensionTerminalInputListener(e),"onTerminalInput"),setStatus:s((e,n)=>this.surfaces.setStatus(e,n),"setStatus"),setWorkingMessage:s(e=>{this.state.workingMessageOverride=e||void 0,this.state.loadingAnimation?this.updateWorkingMessage():this.state.pendingWorkingMessage=e},"setWorkingMessage"),setWidget:s((e,n,i)=>this.surfaces.setWidget(e,n,i),"setWidget"),setFooter:s(e=>this.surfaces.setFooter(e),"setFooter"),setHeader:s(e=>this.surfaces.setHeader(e),"setHeader"),setTitle:s(e=>this.ui.terminal.setTitle(e),"setTitle"),custom:s((e,n)=>this.customOverlay.show(e,n),"custom"),pasteToEditor:s(e=>this.editor.handleInput(`\x1B[200~${e}\x1B[201~`),"pasteToEditor"),setEditorText:s(e=>this.editor.setText(e),"setEditorText"),getEditorText:s(()=>this.editor.getText(),"getEditorText"),editor:s((e,n)=>this.promptHost.editor(e,n),"editor"),openExternalEditor:s(e=>this.openExistingFileInExternalEditor(e),"openExternalEditor"),setEditorComponent:s(e=>this.editorAdapter.setComponent(e),"setEditorComponent"),get theme(){return r},getAllThemes:s(()=>Ut(),"getAllThemes"),getTheme:s(e=>Wt(e),"getTheme"),setTheme:s(e=>{if(typeof e!="string")return Ht(e),this.ui.requestRender(),{success:!0};const n=Ae(e,!0);return n.success&&(this.settingsManager.getTheme()!==e&&this.settingsManager.setTheme(e),this.ui.requestRender()),n},"setTheme"),getToolsExpanded:s(()=>this.state.toolOutputExpanded,"getToolsExpanded"),setToolsExpanded:s(e=>this.setToolsExpanded(e),"setToolsExpanded")}}showExtensionNotify(e,n){n==="error"?this.showError(e):n==="warning"?this.showWarning(e):this.showStatus(e)}shouldRenderToolTrace(e){return e.startsWith("nanomem_")?this.settingsManager.getShowMemoryTrace():this.settingsManager.getShowWorkingTrace()}showExtensionError(e,n,i){const o=`Extension "${e}" error: ${n}`,t=new m(r.fg("error",o),1,0);if(this.chatContainer.addChild(t),i){const a=i.split(`
18
+ ${f}`,0,0)),this.chatContainer.addChild(new u(1))}}}async initExtensions(){const e=this.createExtensionUIContext();await this.session.bindExtensions({uiContext:e,commandContextActions:{waitForIdle:s(()=>this.session.agent.waitForIdle(),"waitForIdle"),newSession:s(async i=>(this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear(),await this.session.newSession(i)?(this.clearStatusTimers(),this.chatContainer.clear(),this.pendingMessagesContainer.clear(),this.state.compactionQueuedMessages=[],this.state.streamingComponent=void 0,this.state.streamingMessage=void 0,this.state.pendingTools.clear(),this.imagePipeline.clearAttachments(),this.renderInitialMessages(),{cancelled:!1}):{cancelled:!0}),"newSession"),fork:s(async i=>{const o=await this.session.fork(i);return o.cancelled?{cancelled:!0}:(this.clearStatusTimers(),this.chatContainer.clear(),this.imagePipeline.clearAttachments(),this.addSessionNavigationBanner("Forked session"),this.renderInitialMessages(),this.editor.setText(o.selectedText),this.showStatus("Forked to new session"),{cancelled:!1})},"fork"),navigateTree:s(async(i,o)=>{const t=await this.session.navigateTree(i,{summarize:o?.summarize,customInstructions:o?.customInstructions,replaceInstructions:o?.replaceInstructions,label:o?.label});return t.cancelled?{cancelled:!0}:(this.clearStatusTimers(),this.chatContainer.clear(),this.imagePipeline.clearAttachments(),this.addSessionNavigationBanner("Navigated session tree"),this.renderInitialMessages(),t.editorText&&!this.editor.getText().trim()&&this.editor.setText(t.editorText),this.showStatus("Navigated to selected point"),{cancelled:!1})},"navigateTree"),switchSession:s(async i=>(await this.treeOverlay.resumeSession(i),{cancelled:!1}),"switchSession"),reload:s(async()=>{await this.handleReloadCommand()},"reload")},shutdownHandler:s(()=>{this.shutdownRequested=!0,this.session.isStreaming||this.shutdown()},"shutdownHandler"),onError:s(i=>{this.showExtensionError(i.extensionPath,i.error,i.stack)},"onError")}),ue(this.session.resourceLoader.getThemes().themes),this.setupAutocomplete(this.fdPath);const n=this.session.extensionRunner;if(!n){this.showLoadedResources({extensionPaths:[],force:!1});return}this.setupExtensionShortcuts(n),this.showLoadedResources({extensionPaths:n.getExtensionPaths(),force:!1})}getRegisteredToolDefinition(e){return(this.session.extensionRunner?.getAllRegisteredTools()??[]).find(o=>o.definition.name===e)?.definition}setupExtensionShortcuts(e){const n=e.getShortcuts(this.keybindings.getEffectiveConfig());n.size!==0&&(this.defaultEditor.onExtensionShortcut=i=>{for(const[o,t]of n)if(Ue(i,o))return Promise.resolve(t.handler(e.createContext())).catch(a=>{this.showError(`Shortcut handler error: ${a instanceof Error?a.message:String(a)}`)}),!0;return!1})}formatElapsedSeconds(e){return`${(Math.max(0,e)/1e3).toFixed(1)}s`}getNextCatMessage(){const e=Date.now();return e-this.catMessageLastSwitch>=3e3&&(this.catMessageIndex++,this.catMessageLastSwitch=e),this.catWorkingMessages[this.catMessageIndex%this.catWorkingMessages.length]}buildWorkingMessage(){const e=this.state.workingMessageOverride||this.getNextCatMessage(),n=`${L(this.keybindings,"interrupt")} to interrupt`,i=this.state.agentRunStartMs!==void 0?this.formatElapsedSeconds(Date.now()-this.state.agentRunStartMs):void 0,o=i?`(${i}, ${n})`:`(${n})`;return{base:e,suffix:o}}updateWorkingMessage(e){if(!this.state.loadingAnimation)return;const{base:n,suffix:i}=this.buildWorkingMessage();this.state.loadingAnimation.setMessage(n,{...e,suffix:i})}stopAgentRunTimer(){this.state.agentRunTimer&&(clearInterval(this.state.agentRunTimer),this.state.agentRunTimer=void 0)}stopWelcomeBannerTimer(){this.state.welcomeBannerTimer&&(clearInterval(this.state.welcomeBannerTimer),this.state.welcomeBannerTimer=void 0)}startAgentRunTimer(){this.stopAgentRunTimer(),this.state.agentRunStartMs=Date.now(),this.state.agentRunTimer=setInterval(()=>{if(!this.state.loadingAnimation||this.state.agentRunStartMs===void 0){this.stopAgentRunTimer();return}this.updateWorkingMessage({resetStallTimer:!1})},100)}resetExtensionUI(){this.promptHost.dismiss(),this.ui.hideOverlay(),this.clearExtensionTerminalInputListeners(),this.surfaces.setFooter(void 0),this.surfaces.setHeader(void 0),this.surfaces.clearWidgets(),this.footerDataProvider.clearExtensionStatuses(),this.footer.invalidate(),this.editorAdapter.setComponent(void 0),this.defaultEditor.onExtensionShortcut=void 0,this.updateTerminalTitle(),this.state.loadingAnimation&&(this.state.workingMessageOverride=void 0,this.updateWorkingMessage())}clearBuddyPetResetTimer(){this.buddyPetResetTimer&&(clearTimeout(this.buddyPetResetTimer),this.buddyPetResetTimer=void 0)}syncBuddyPet(){const e=this.settingsManager.getBuddyEnabled(),n=this.settingsManager.getBuddySpecies();if(!e){this.clearBuddyPetResetTimer(),this.buddyPet?.dispose(),this.buddyPet=null,this.buddyPetSpecies=null,this.buddySlot.clear(),this.surfaces.renderWidgets();return}(!this.buddyPet||this.buddyPetSpecies!==n)&&(this.clearBuddyPetResetTimer(),this.buddyPet?.dispose(),this.buddyPet=new wt(this.ui,n),this.buddyPetSpecies=n,this.buddyPet.setState("idle"),this.buddyPet.setSpeechBubble("")),this.buddySlot.clear(),this.buddySlot.addChild(this.buddyPet),this.surfaces.renderWidgets()}remountEditorShell(){this.editorContainer.clear(),this.imagePipeline.hasAttachments()&&this.attachmentsContainer&&this.editorContainer.addChild(this.attachmentsContainer),this.editorContainer.addChild(this.editorBuddyLayout)}setBuddyPetState(e,n="",i){this.buddyPet&&(this.clearBuddyPetResetTimer(),this.buddyPet.setState(e),this.buddyPet.setSpeechBubble(n),i?.resetTo&&(this.buddyPetResetTimer=setTimeout(()=>{this.buddyPet&&(this.buddyPet.setState(i.resetTo??"idle"),this.buddyPet.setSpeechBubble(""),this.buddyPetResetTimer=void 0,this.ui.requestRender())},i.afterMs??1500)),this.ui.requestRender())}addExtensionTerminalInputListener(e){const n=this.ui.addInputListener(e);return this.extensionTerminalInputUnsubscribers.add(n),()=>{n(),this.extensionTerminalInputUnsubscribers.delete(n)}}clearExtensionTerminalInputListeners(){for(const e of this.extensionTerminalInputUnsubscribers)e();this.extensionTerminalInputUnsubscribers.clear()}createExtensionUIContext(){return{select:s((e,n,i)=>this.promptHost.selector(e,n,i),"select"),confirm:s((e,n,i)=>this.promptHost.confirm(e,n,i),"confirm"),input:s((e,n,i)=>this.promptHost.input(e,n,i),"input"),notify:s((e,n)=>this.showExtensionNotify(e,n),"notify"),onTerminalInput:s(e=>this.addExtensionTerminalInputListener(e),"onTerminalInput"),setStatus:s((e,n)=>this.surfaces.setStatus(e,n),"setStatus"),setWorkingMessage:s(e=>{this.state.workingMessageOverride=e||void 0,this.state.loadingAnimation?this.updateWorkingMessage():this.state.pendingWorkingMessage=e},"setWorkingMessage"),setWidget:s((e,n,i)=>this.surfaces.setWidget(e,n,i),"setWidget"),setFooter:s(e=>this.surfaces.setFooter(e),"setFooter"),setHeader:s(e=>this.surfaces.setHeader(e),"setHeader"),setTitle:s(e=>this.ui.terminal.setTitle(e),"setTitle"),custom:s((e,n)=>this.customOverlay.show(e,n),"custom"),pasteToEditor:s(e=>this.editor.handleInput(`\x1B[200~${e}\x1B[201~`),"pasteToEditor"),setEditorText:s(e=>this.editor.setText(e),"setEditorText"),getEditorText:s(()=>this.editor.getText(),"getEditorText"),editor:s((e,n)=>this.promptHost.editor(e,n),"editor"),openExternalEditor:s(e=>this.openExistingFileInExternalEditor(e),"openExternalEditor"),setEditorComponent:s(e=>this.editorAdapter.setComponent(e),"setEditorComponent"),get theme(){return r},getAllThemes:s(()=>Ut(),"getAllThemes"),getTheme:s(e=>Wt(e),"getTheme"),setTheme:s(e=>{if(typeof e!="string")return Ht(e),this.ui.requestRender(),{success:!0};const n=Ae(e,!0);return n.success&&(this.settingsManager.getTheme()!==e&&this.settingsManager.setTheme(e),this.ui.requestRender()),n},"setTheme"),getToolsExpanded:s(()=>this.state.toolOutputExpanded,"getToolsExpanded"),setToolsExpanded:s(e=>this.setToolsExpanded(e),"setToolsExpanded")}}showExtensionNotify(e,n){n==="error"?this.showError(e):n==="warning"?this.showWarning(e):this.showStatus(e)}shouldRenderToolTrace(e){return e.startsWith("nanomem_")?this.settingsManager.getShowMemoryTrace():this.settingsManager.getShowWorkingTrace()}showExtensionError(e,n,i){const o=`Extension "${e}" error: ${n}`,t=new m(r.fg("error",o),1,0);if(this.chatContainer.addChild(t),i){const a=i.split(`
19
19
  `).slice(1).map(h=>r.fg("dim",` ${h.trim()}`)).join(`
20
- `);a&&this.chatContainer.addChild(new m(a,1,0))}this.ui.requestRender()}setupKeyHandlers(){this.defaultEditor.onEscape=()=>this.interrupt.dispatchEscape(),this.defaultEditor.onAction("clear",()=>this.interrupt.handleCtrlC()),this.defaultEditor.onAction("showResources",()=>this.handleShowResourcesCommand()),this.defaultEditor.onCtrlD=()=>this.interrupt.handleCtrlD(),this.defaultEditor.onAction("suspend",()=>this.interrupt.handleCtrlZ()),this.defaultEditor.onAction("cycleThinkingLevel",()=>this.modelOverlay.cycleThinkingLevel()),this.defaultEditor.onAction("cycleModelForward",()=>this.modelOverlay.cycleModel("forward")),this.defaultEditor.onAction("cycleModelBackward",()=>this.modelOverlay.cycleModel("backward")),this.ui.onDebug=()=>this.handleRenderDebugCommand(),this.defaultEditor.onAction("selectModel",()=>this.modelOverlay.showProviderThenModelSelector()),this.defaultEditor.onAction("selectProviderThenModel",()=>this.modelOverlay.showProviderThenModelSelector()),this.defaultEditor.onAction("expandTools",()=>this.toggleToolOutputExpansion()),this.defaultEditor.onAction("toggleThinking",()=>this.toggleThinkingBlockVisibility()),this.defaultEditor.onAction("externalEditor",()=>this.openExternalEditor()),this.defaultEditor.onAction("followUp",()=>this.handleFollowUp()),this.defaultEditor.onAction("dequeue",()=>this.handleDequeue()),this.defaultEditor.onAction("newSession",()=>this.handleClearCommand()),this.defaultEditor.onAction("tree",()=>this.treeOverlay.showTreeSelector()),this.defaultEditor.onAction("fork",()=>this.treeOverlay.showForkSelector()),this.defaultEditor.onAction("resume",()=>this.treeOverlay.showSessionSelector()),this.defaultEditor.onChange=e=>{const n=this.isBashMode;this.isBashMode=e.trimStart().startsWith("!"),n!==this.isBashMode&&this.updateEditorBorderColor()},this.defaultEditor.onPasteImage=()=>{this.imagePipeline.handleClipboardImagePaste()},this.defaultEditor.onAttachmentKey=e=>this.imagePipeline.handleAttachmentKeyNavigation(e)}setupEditorSubmitHandler(){this.defaultEditor.onSubmit=async e=>{await this.inputSubmit.handleSubmit(e)}}subscribeToAgent(){this.unsubscribe=this.session.subscribe(async e=>{await this.handleEvent(e)})}addSessionNavigationBanner(e){const n=this.sessionManager.getSessionName(),i=this.sessionManager.getSessionId(),o=n?` "${n}"`:"",t=r.fg("dim",`\u21AA ${e} \u2192 session${o} (${i})`);this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(t,1,1)),this.chatContainer.addChild(new u(1))}async handleEvent(e){if(ie(`handleEvent: ${e.type}`),e.type==="sdk:mcp_ready"){e.toolCount>0&&this.showStatus(`MCP: ${e.toolCount} tool(s) ready`);return}await this.streamRender.handle(e)}getUserMessageText(e){return e.role!=="user"?"":(typeof e.content=="string"?[{type:"text",text:e.content}]:e.content.filter(i=>i.type==="text")).map(i=>i.text).join("")}showStatus(e){const n=this.chatContainer.children,i=n.length>0?n[n.length-1]:void 0,o=n.length>1?n[n.length-2]:void 0;if(i&&o&&i===this.state.lastStatusText&&o===this.state.lastStatusSpacer){this.state.lastStatusText.setText(r.fg("dim",e)),this.scheduleStatusDismiss(this.state.lastStatusSpacer,this.state.lastStatusText),this.ui.requestRender();return}const t=new u(1),a=new m(r.fg("dim",e),1,0);this.chatContainer.addChild(t),this.chatContainer.addChild(a),this.state.lastStatusSpacer=t,this.state.lastStatusText=a,this.scheduleStatusDismiss(t,a),this.ui.requestRender()}addMessageToChat(e,n){switch(e.role){case"bashExecution":{const i=new ce(e.command,this.ui,e.excludeFromContext);e.output&&i.appendOutput(e.output),i.setComplete(e.exitCode,e.cancelled,e.truncated?{truncated:!0}:void 0,e.fullOutputPath),this.chatContainer.addChild(i);break}case"custom":{if(e.display){const i=typeof e.details=="object"&&e.details!==null?e.details:void 0;if(i?.replace&&i.streamKey){const a=this.state.customStreamComponents.get(i.streamKey);if(a){a.updateMessage(e),this.ui.requestRender();break}}const o=this.session.extensionRunner?.getMessageRenderer(e.customType),t=new Pt(e,o,this.getMarkdownThemeWithSettings());t.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(t),i?.streamKey&&this.state.customStreamComponents.set(i.streamKey,t)}break}case"compactionSummary":{this.chatContainer.addChild(new u(1));const i=new Et(e,this.getMarkdownThemeWithSettings());i.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(i);break}case"branchSummary":{this.chatContainer.addChild(new u(1));const i=new St(e,this.getMarkdownThemeWithSettings());i.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(i);break}case"user":{const i=this.getUserMessageText(e);if(i){const o=Ke(i);if(o){this.chatContainer.addChild(new u(1));const t=new Dt(o,this.getMarkdownThemeWithSettings());if(t.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(t),o.userMessage){const a=new $e(o.userMessage,this.getMarkdownThemeWithSettings());this.chatContainer.addChild(a)}}else{const t=new $e(i,this.getMarkdownThemeWithSettings());this.chatContainer.addChild(t)}n?.populateHistory&&this.editor.addToHistory?.(i)}break}case"assistant":{const i=new xe(e,this.state.hideThinkingBlock,this.getMarkdownThemeWithSettings());this.chatContainer.addChild(i);break}case"toolResult":break;default:{const i=e}}}renderSessionContext(e,n={}){this.state.pendingTools.clear(),this.state.customStreamComponents.clear(),n.updateFooter&&(this.footer.invalidate(),this.updateEditorBorderColor());for(const i of e.messages)if(i.role==="assistant"){this.addMessageToChat(i);for(const o of i.content)if(o.type==="toolCall"){const t=new ke(o.name,o.arguments,{showImages:this.settingsManager.getShowImages()},this.getRegisteredToolDefinition(o.name),this.ui);if(t.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(t),i.stopReason==="aborted"||i.stopReason==="error"){let a;if(i.stopReason==="aborted"){const h=this.session.retryAttempt;a=h>0?`Aborted after ${h} retry attempt${h>1?"s":""}`:"Operation aborted"}else a=i.errorMessage||"Error";t.updateResult({content:[{type:"text",text:a}],isError:!0})}else this.state.pendingTools.set(o.id,t)}}else if(i.role==="toolResult"){const o=this.state.pendingTools.get(i.toolCallId);o&&(o.updateResult(i),this.state.pendingTools.delete(i.toolCallId))}else this.addMessageToChat(i,n);this.state.pendingTools.clear(),this.ui.requestRender()}renderInitialMessages(){this.stopWelcomeBannerTimer();const e=this.sessionManager.buildSessionContext();if(this.renderSessionContext(e,{updateFooter:!0,populateHistory:!0}),e.messages.length===0){if(this.chatContainer.addChild(new u(1)),Y==="nanopencil"){const o=this.session.cwd,t=this.session.model,a=t?.name??(t?.provider?`${t.provider}`:"DashScope \xB7 Ollama"),h=s(l=>{const T=l%8===5,v=l%4<2?"*":".",k=l%4>=2?"*":".",I=[` ${v} ,MMM8&&&. ${k}`," MMMM88&&&&& ."," MMMM88&&&&&&&"," * MMM88&&&&&&&&"," MMM88&&&&&&&&"," 'MMM88&&&&&&'",` 'MMM8&&&' ${k} _`," |\\___/| \\\\"," ) ( |\\_/| || '",T?` =\\ /= )- - '._.-""""-. //`:` =\\ /= )a a '._.-""""-. //`," )===( =\\T_= / ~ ~ \\//",' / \\ `"`\\ ~ / ~ /'," | | |~ \\ | ~/"," / \\ \\ ~/- \\ ~\\"," \\ / || | // /`"," _/\\_/\\_ _/_/\\_/\\_/\\_((_|\\((_//\\_/\\_/\\_"," | | | |( ( | | | | | | | | | |"," | | | | ) ) | | | | | | | | | |"," | | | |(_( | | | | | | | | | |"," | | | | | | | | | | | | | | |"," | | | | | | | | | | | | | | |"],B=Math.max(...I.map(L=>L.length));return I.map(L=>L.padEnd(B))},"buildAsciiLines"),c=s(l=>h(l).map(T=>r.fg("accent",T.slice(0,Math.max(1,this.ui.terminal.columns||80)))).join(`
21
- `),"renderAscii"),d=r.bold(r.fg("accent",`nano-pencil v${this.version}`)),g=r.fg("dim",a),C=r.fg("dim",o),b=r.fg("dim"," /model to switch model"),w=this.getAppKeyDisplay("showResources"),E=this.settingsManager.getQuietStartup()?r.fg("dim",` ${w} to show context/skills/extensions`):"",S=r.fg("borderMuted","\u2500".repeat(Math.max(40,this.ui.terminal.columns||80))),f=r.fg("accent",'\u276F Try "refactor <filepath>" or type below'),p=[c(0),"",` ${d}`,` ${g}`,` ${C}`,"",b,...E?["",E]:[],"",S,f].join(`
22
- `),y=new m(p,0,0);this.chatContainer.addChild(y);let M=0;this.state.welcomeBannerTimer=setInterval(()=>{M+=1,y.setText([c(M),"",` ${d}`,` ${g}`,` ${C}`,"",b,...E?["",E]:[],"",S,f].join(`
23
- `)),this.ui.requestRender(),M>=16&&this.stopWelcomeBannerTimer()},220)}else{const t=[" \u270E"," +---------------+",` | ${Y.padEnd(14).slice(0,14)} |`," +---------------+"].join(`
20
+ `);a&&this.chatContainer.addChild(new m(a,1,0))}this.ui.requestRender()}setupKeyHandlers(){this.defaultEditor.onEscape=()=>this.interrupt.dispatchEscape(),this.defaultEditor.onAction("clear",()=>this.interrupt.handleCtrlC()),this.defaultEditor.onAction("showResources",()=>this.handleShowResourcesCommand()),this.defaultEditor.onCtrlD=()=>this.interrupt.handleCtrlD(),this.defaultEditor.onAction("suspend",()=>this.interrupt.handleCtrlZ()),this.defaultEditor.onAction("cycleThinkingLevel",()=>this.modelOverlay.cycleThinkingLevel()),this.defaultEditor.onAction("cycleModelForward",()=>this.modelOverlay.cycleModel("forward")),this.defaultEditor.onAction("cycleModelBackward",()=>this.modelOverlay.cycleModel("backward")),this.ui.onDebug=()=>this.handleRenderDebugCommand(),this.defaultEditor.onAction("selectModel",()=>this.modelOverlay.showProviderThenModelSelector()),this.defaultEditor.onAction("selectProviderThenModel",()=>this.modelOverlay.showProviderThenModelSelector()),this.defaultEditor.onAction("expandTools",()=>this.toggleToolOutputExpansion()),this.defaultEditor.onAction("toggleThinking",()=>this.toggleThinkingBlockVisibility()),this.defaultEditor.onAction("externalEditor",()=>this.openExternalEditor()),this.defaultEditor.onAction("followUp",()=>this.handleFollowUp()),this.defaultEditor.onAction("dequeue",()=>this.handleDequeue()),this.defaultEditor.onAction("newSession",()=>this.handleClearCommand()),this.defaultEditor.onAction("tree",()=>this.treeOverlay.showTreeSelector()),this.defaultEditor.onAction("fork",()=>this.treeOverlay.showForkSelector()),this.defaultEditor.onAction("resume",()=>this.treeOverlay.showSessionSelector()),this.defaultEditor.onChange=e=>{const n=this.isBashMode;this.isBashMode=e.trimStart().startsWith("!"),n!==this.isBashMode&&this.updateEditorBorderColor()},this.defaultEditor.onPasteImage=()=>{this.imagePipeline.handleClipboardImagePaste()},this.defaultEditor.onAttachmentKey=e=>this.imagePipeline.handleAttachmentKeyNavigation(e)}setupEditorSubmitHandler(){this.defaultEditor.onSubmit=async e=>{await this.inputSubmit.handleSubmit(e)}}subscribeToAgent(){this.unsubscribe=this.session.subscribe(async e=>{await this.handleEvent(e)})}addSessionNavigationBanner(e){const n=this.sessionManager.getSessionName(),i=this.sessionManager.getSessionId(),o=n?` "${n}"`:"",t=r.fg("dim",`\u21AA ${e} \u2192 session${o} (${i})`);this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(t,1,1)),this.chatContainer.addChild(new u(1))}async handleEvent(e){if(ee(`handleEvent: ${e.type}`),e.type==="sdk:mcp_ready"){e.toolCount>0&&this.showStatus(`MCP: ${e.toolCount} tool(s) ready`);return}await this.streamRender.handle(e)}getUserMessageText(e){return e.role!=="user"?"":(typeof e.content=="string"?[{type:"text",text:e.content}]:e.content.filter(i=>i.type==="text")).map(i=>i.text).join("")}showStatus(e){const n=this.chatContainer.children,i=n.length>0?n[n.length-1]:void 0,o=n.length>1?n[n.length-2]:void 0;if(i&&o&&i===this.state.lastStatusText&&o===this.state.lastStatusSpacer){this.state.lastStatusText.setText(r.fg("dim",e)),this.scheduleStatusDismiss(this.state.lastStatusSpacer,this.state.lastStatusText),this.ui.requestRender();return}const t=new u(1),a=new m(r.fg("dim",e),1,0);this.chatContainer.addChild(t),this.chatContainer.addChild(a),this.state.lastStatusSpacer=t,this.state.lastStatusText=a,this.scheduleStatusDismiss(t,a),this.ui.requestRender()}addMessageToChat(e,n){switch(e.role){case"bashExecution":{const i=new ce(e.command,this.ui,e.excludeFromContext);e.output&&i.appendOutput(e.output),i.setComplete(e.exitCode,e.cancelled,e.truncated?{truncated:!0}:void 0,e.fullOutputPath),this.chatContainer.addChild(i);break}case"custom":{if(e.display){const i=typeof e.details=="object"&&e.details!==null?e.details:void 0;if(i?.replace&&i.streamKey){const a=this.state.customStreamComponents.get(i.streamKey);if(a){a.updateMessage(e),this.ui.requestRender();break}}const o=this.session.extensionRunner?.getMessageRenderer(e.customType),t=new Pt(e,o,this.getMarkdownThemeWithSettings());t.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(t),i?.streamKey&&this.state.customStreamComponents.set(i.streamKey,t)}break}case"compactionSummary":{this.chatContainer.addChild(new u(1));const i=new Et(e,this.getMarkdownThemeWithSettings());i.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(i);break}case"branchSummary":{this.chatContainer.addChild(new u(1));const i=new St(e,this.getMarkdownThemeWithSettings());i.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(i);break}case"user":{const i=this.getUserMessageText(e);if(i){const o=Ke(i);if(o){this.chatContainer.addChild(new u(1));const t=new Dt(o,this.getMarkdownThemeWithSettings());if(t.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(t),o.userMessage){const a=new $e(o.userMessage,this.getMarkdownThemeWithSettings());this.chatContainer.addChild(a)}}else{const t=new $e(i,this.getMarkdownThemeWithSettings());this.chatContainer.addChild(t)}n?.populateHistory&&this.editor.addToHistory?.(i)}break}case"assistant":{const i=new xe(e,this.state.hideThinkingBlock,this.getMarkdownThemeWithSettings());this.chatContainer.addChild(i);break}case"toolResult":break;default:{const i=e}}}renderSessionContext(e,n={}){this.state.pendingTools.clear(),this.state.customStreamComponents.clear(),n.updateFooter&&(this.footer.invalidate(),this.updateEditorBorderColor());for(const i of e.messages)if(i.role==="assistant"){this.addMessageToChat(i);for(const o of i.content)if(o.type==="toolCall"){const t=new ke(o.name,o.arguments,{showImages:this.settingsManager.getShowImages()},this.getRegisteredToolDefinition(o.name),this.ui);if(t.setExpanded(this.state.toolOutputExpanded),this.chatContainer.addChild(t),i.stopReason==="aborted"||i.stopReason==="error"){let a;if(i.stopReason==="aborted"){const h=this.session.retryAttempt;a=h>0?`Aborted after ${h} retry attempt${h>1?"s":""}`:"Operation aborted"}else a=i.errorMessage||"Error";t.updateResult({content:[{type:"text",text:a}],isError:!0})}else this.state.pendingTools.set(o.id,t)}}else if(i.role==="toolResult"){const o=this.state.pendingTools.get(i.toolCallId);o&&(o.updateResult(i),this.state.pendingTools.delete(i.toolCallId))}else this.addMessageToChat(i,n);this.state.pendingTools.clear(),this.ui.requestRender()}renderInitialMessages(){this.stopWelcomeBannerTimer();const e=this.sessionManager.buildSessionContext();if(this.renderSessionContext(e,{updateFooter:!0,populateHistory:!0}),e.messages.length===0){if(this.chatContainer.addChild(new u(1)),J==="nanopencil"){const o=this.session.cwd,t=this.session.model,a=t?.name??(t?.provider?`${t.provider}`:"DashScope \xB7 Ollama"),h=s(l=>{const $=[" __..--''``\\--....___ _..,_",""," //// _.-' .-/\"; ` ``<._ ``-+'~=. ////",""," ///_.-' _..--.' \\ `(^) ) //",""," // ((..-' // (< - ;_..__ ; `' //",""," ////////////// `-._,_)'//////``--...____..-' /////"," //////////////////////////////////////////////////","",l%8===5?"///CATU I///////////////////////////////////////////":"///CATUI////////////////////////////////////////////","","---------------------------------------------------"],A=Math.max(...$.map(R=>R.length));return $.map(R=>R.padEnd(A))},"buildAsciiLines"),c=s(l=>h(l).map(T=>r.fg("accent",T.slice(0,Math.max(1,this.ui.terminal.columns||80)))).join(`
21
+ `),"renderAscii"),d=r.bold(r.fg("accent",`nano-pencil v${this.version}`)),g=r.fg("dim",a),C=r.fg("dim",o),M=r.fg("dim"," /model to switch model"),w=this.getAppKeyDisplay("showResources"),E=this.settingsManager.getQuietStartup()?r.fg("dim",` ${w} to show context/skills/extensions`):"",S=r.fg("borderMuted","\u2500".repeat(Math.max(40,this.ui.terminal.columns||80))),f=r.fg("accent",'\u276F Try "refactor <filepath>" or type below'),p=[c(0),"",` ${d}`,` ${g}`,` ${C}`,"",M,...E?["",E]:[],"",S,f].join(`
22
+ `),y=new m(p,0,0);this.chatContainer.addChild(y);let b=0;this.state.welcomeBannerTimer=setInterval(()=>{b+=1,y.setText([c(b),"",` ${d}`,` ${g}`,` ${C}`,"",M,...E?["",E]:[],"",S,f].join(`
23
+ `)),this.ui.requestRender(),b>=16&&this.stopWelcomeBannerTimer()},220)}else{const t=[" \u270E"," +---------------+",` | ${J.padEnd(14).slice(0,14)} |`," +---------------+"].join(`
24
24
  `),a=` ${r.fg("dim","AI coding agent. Type below to start.")}`;this.chatContainer.addChild(new m(`${r.fg("accent",t)}
25
25
  ${a}`,0,0))}this.chatContainer.addChild(new u(1))}const i=this.sessionManager.getEntries().filter(o=>o.type==="compaction").length;if(i>0){const o=i===1?"1 time":`${i} times`;this.showStatus(`Session compacted ${o}`)}this.ui.requestRender(!0)}async getUserInput(){return new Promise(e=>{this.onInputCallback=n=>{this.onInputCallback=void 0,e(n)}})}rebuildChatFromMessages(){this.clearStatusTimers(),this.chatContainer.clear();const e=this.sessionManager.buildSessionContext();this.renderSessionContext(e);for(const n of this.state.optimisticUserMessages)this.addMessageToChat({role:"user",content:[{type:"text",text:n.text}],timestamp:Date.now()});this.ui.requestRender(!0)}isShuttingDown=!1;async shutdown(){if(this.isShuttingDown)return;this.isShuttingDown=!0;const e=this.session.extensionRunner;e?.hasHandlers("session_shutdown")&&await Promise.race([e.emit({type:"session_shutdown"}),new Promise(t=>setTimeout(t,5e3))]),this.imagePipeline.cleanupClipboardImages(),await new Promise(o=>process.nextTick(o)),await this.ui.terminal.drainInput(1e3),this.stop();const n=this.sessionManager.getSessionId(),i=this.session.cwd;console.log(`
26
26
  Resume this session with: nanopencil --session ${n} --cwd "${i}"`),process.exit(0)}async checkShutdownRequested(){this.shutdownRequested&&await this.shutdown()}suspend(){process.once("SIGCONT",()=>{this.ui.start(),this.ui.requestRender(!0)}),this.ui.stop(),process.kill(0,"SIGTSTP")}async handleFollowUp(){const e=(this.editor.getExpandedText?.()??this.editor.getText()).trim();if(e){if(this.session.isCompacting){this.isExtensionCommand(e)?(this.editor.addToHistory?.(e),this.editor.setText(""),await this.promptAfterRender(e)):this.queueCompactionMessage(e,"followUp");return}this.session.isStreaming?(this.editor.addToHistory?.(e),this.editor.setText(""),await this.promptAfterRender(e,{streamingBehavior:"followUp"}),this.updatePendingMessagesDisplay(),this.ui.requestRender()):this.editor.onSubmit&&this.editor.onSubmit(e)}}handleDequeue(){const e=this.restoreQueuedMessagesToEditor();e===0?this.showStatus("No queued messages to restore"):this.showStatus(`Restored ${e} queued message${e>1?"s":""} to editor`)}async promptAfterRender(e,n){const i=this.ui;typeof i.awaitRender=="function"?await i.awaitRender():await new Promise(o=>process.nextTick(o)),await this.session.prompt(e,n)}updateEditorBorderColor(){if(this.isBashMode)this.editor.borderColor=r.getBashModeBorderColor();else{const e=this.session.thinkingLevel||"off";this.editor.borderColor=r.getThinkingBorderColor(e)}this.ui.requestRender()}handleAgentLoopCommand(e){const n=e.slice(11).trim().toLowerCase(),i=["standard","weak-model-compatible"],o=n==="high-intelligence"?"standard":n==="low-intelligence"||n==="structured-adaptive"?"weak-model-compatible":n;if(!n){this.showStatus(`Agent loop: ${this.session.agentLoopFramework} (available: ${i.join(", ")})`);return}if(!i.includes(o)){this.showError(`Unknown agent loop framework: ${n}
27
- Available: ${i.join(", ")}`);return}this.session.setAgentLoopFramework(o),this.footer.invalidate(),this.showStatus(`Agent loop framework: ${this.session.agentLoopFramework}`)}toggleToolOutputExpansion(){this.setToolsExpanded(!this.state.toolOutputExpanded)}setToolsExpanded(e){this.state.toolOutputExpanded=e;for(const n of this.chatContainer.children)Jt(n)&&n.setExpanded(e);this.ui.requestRender()}toggleThinkingBlockVisibility(){this.state.hideThinkingBlock=!this.state.hideThinkingBlock,this.settingsManager.setHideThinkingBlock(this.state.hideThinkingBlock),this.chatContainer.clear(),this.rebuildChatFromMessages(),this.state.streamingComponent&&this.state.streamingMessage&&(this.state.streamingComponent.setHideThinkingBlock(this.state.hideThinkingBlock),this.state.streamingComponent.updateContent(this.state.streamingMessage),this.chatContainer.addChild(this.state.streamingComponent)),this.showStatus(`Thinking blocks: ${this.state.hideThinkingBlock?"hidden":"visible"}`)}openExternalEditor(){const e=process.env.VISUAL||process.env.EDITOR;if(!e){this.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable.");return}const n=this.editor.getExpandedText?.()??this.editor.getText(),i=q.join(J.tmpdir(),`nanopencil-editor-${Date.now()}.nanopencil.md`);try{$.writeFileSync(i,n,"utf-8"),this.ui.stop();const[o,...t]=e.split(" ");if(de(o,[...t,i],{stdio:"inherit"}).status===0){const h=$.readFileSync(i,"utf-8").replace(/\n$/,"");this.editor.setText(h)}}finally{try{$.unlinkSync(i)}catch{}this.ui.start(),this.ui.requestRender(!0)}}async openExistingFileInExternalEditor(e){const n=process.env.VISUAL||process.env.EDITOR;if(!n)return this.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable."),!1;try{this.ui.stop();const[i,...o]=n.split(" ");return de(i,[...o,e],{stdio:"inherit"}).status===0}finally{this.ui.start(),this.ui.requestRender(!0)}}clearEditor(){this.editor.setText(""),this.ui.requestRender()}showError(e){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("error",`Error: ${e}`),1,0)),this.setBuddyPetState("error","Oops...",{resetTo:"idle",afterMs:2200}),this.ui.requestRender()}showWarning(e){const n=new u(1),i=new m(r.fg("warning",`Warning: ${e}`),1,0);this.chatContainer.addChild(n),this.chatContainer.addChild(i),this.scheduleStatusDismiss(n,i),this.setBuddyPetState("error","Careful.",{resetTo:"idle",afterMs:1800}),this.ui.requestRender()}scheduleStatusDismiss(e,n){const i=setTimeout(()=>{this.statusTimers.delete(i),this.chatContainer.removeChild(e),this.chatContainer.removeChild(n),this.state.lastStatusText===n&&(this.state.lastStatusText=void 0,this.state.lastStatusSpacer=void 0),this.ui.requestRender()},5e3);this.statusTimers.add(i)}clearStatusTimers(){for(const e of this.statusTimers)clearTimeout(e);this.statusTimers.clear(),this.notificationQueue.clearAll()}notify(e,n){this.notificationQueue.notify(e,n)}getAllQueuedMessages(){return{steering:[...this.session.getSteeringMessages(),...this.state.compactionQueuedMessages.filter(e=>e.mode==="steer").map(e=>e.text)],followUp:[...this.session.getFollowUpMessages(),...this.state.compactionQueuedMessages.filter(e=>e.mode==="followUp").map(e=>e.text)]}}clearAllQueues(){const{steering:e,followUp:n}=this.session.clearQueue(),i=this.state.compactionQueuedMessages.filter(t=>t.mode==="steer").map(t=>t.text),o=this.state.compactionQueuedMessages.filter(t=>t.mode==="followUp").map(t=>t.text);return this.state.compactionQueuedMessages=[],{steering:[...e,...i],followUp:[...n,...o]}}updatePendingMessagesDisplay(){this.pendingMessagesContainer.clear();const{steering:e,followUp:n}=this.getAllQueuedMessages();if(e.length>0||n.length>0){this.pendingMessagesContainer.addChild(new u(1));for(const t of e){const a=r.fg("dim",`Steering: ${t}`);this.pendingMessagesContainer.addChild(new he(a,1,0))}for(const t of n){const a=r.fg("dim",`Follow-up: ${t}`);this.pendingMessagesContainer.addChild(new he(a,1,0))}const i=this.getAppKeyDisplay("dequeue"),o=r.fg("dim",`\u21B3 ${i} to edit all queued messages`);this.pendingMessagesContainer.addChild(new he(o,1,0))}}restoreQueuedMessagesToEditor(e){const{steering:n,followUp:i}=this.clearAllQueues(),o=[...n,...i];if(o.length===0)return this.updatePendingMessagesDisplay(),e?.abort&&this.agent.abort(),0;const t=o.join(`
27
+ Available: ${i.join(", ")}`);return}this.session.setAgentLoopFramework(o),this.footer.invalidate(),this.showStatus(`Agent loop framework: ${this.session.agentLoopFramework}`)}toggleToolOutputExpansion(){this.setToolsExpanded(!this.state.toolOutputExpanded)}setToolsExpanded(e){this.state.toolOutputExpanded=e;for(const n of this.chatContainer.children)Jt(n)&&n.setExpanded(e);this.ui.requestRender()}toggleThinkingBlockVisibility(){this.state.hideThinkingBlock=!this.state.hideThinkingBlock,this.settingsManager.setHideThinkingBlock(this.state.hideThinkingBlock),this.chatContainer.clear(),this.rebuildChatFromMessages(),this.state.streamingComponent&&this.state.streamingMessage&&(this.state.streamingComponent.setHideThinkingBlock(this.state.hideThinkingBlock),this.state.streamingComponent.updateContent(this.state.streamingMessage),this.chatContainer.addChild(this.state.streamingComponent)),this.showStatus(`Thinking blocks: ${this.state.hideThinkingBlock?"hidden":"visible"}`)}openExternalEditor(){const e=process.env.VISUAL||process.env.EDITOR;if(!e){this.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable.");return}const n=this.editor.getExpandedText?.()??this.editor.getText(),i=U.join(X.tmpdir(),`nanopencil-editor-${Date.now()}.nanopencil.md`);try{k.writeFileSync(i,n,"utf-8"),this.ui.stop();const[o,...t]=e.split(" ");if(re(o,[...t,i],{stdio:"inherit"}).status===0){const h=k.readFileSync(i,"utf-8").replace(/\n$/,"");this.editor.setText(h)}}finally{try{k.unlinkSync(i)}catch{}this.ui.start(),this.ui.requestRender(!0)}}async openExistingFileInExternalEditor(e){const n=process.env.VISUAL||process.env.EDITOR;if(!n)return this.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable."),!1;try{this.ui.stop();const[i,...o]=n.split(" ");return re(i,[...o,e],{stdio:"inherit"}).status===0}finally{this.ui.start(),this.ui.requestRender(!0)}}clearEditor(){this.editor.setText(""),this.ui.requestRender()}showError(e){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("error",`Error: ${e}`),1,0)),this.setBuddyPetState("error","Oops...",{resetTo:"idle",afterMs:2200}),this.ui.requestRender()}showWarning(e){const n=new u(1),i=new m(r.fg("warning",`Warning: ${e}`),1,0);this.chatContainer.addChild(n),this.chatContainer.addChild(i),this.scheduleStatusDismiss(n,i),this.setBuddyPetState("error","Careful.",{resetTo:"idle",afterMs:1800}),this.ui.requestRender()}scheduleStatusDismiss(e,n){const i=setTimeout(()=>{this.statusTimers.delete(i),this.chatContainer.removeChild(e),this.chatContainer.removeChild(n),this.state.lastStatusText===n&&(this.state.lastStatusText=void 0,this.state.lastStatusSpacer=void 0),this.ui.requestRender()},5e3);this.statusTimers.add(i)}clearStatusTimers(){for(const e of this.statusTimers)clearTimeout(e);this.statusTimers.clear(),this.notificationQueue.clearAll()}notify(e,n){this.notificationQueue.notify(e,n)}getAllQueuedMessages(){return{steering:[...this.session.getSteeringMessages(),...this.state.compactionQueuedMessages.filter(e=>e.mode==="steer").map(e=>e.text)],followUp:[...this.session.getFollowUpMessages(),...this.state.compactionQueuedMessages.filter(e=>e.mode==="followUp").map(e=>e.text)]}}clearAllQueues(){const{steering:e,followUp:n}=this.session.clearQueue(),i=this.state.compactionQueuedMessages.filter(t=>t.mode==="steer").map(t=>t.text),o=this.state.compactionQueuedMessages.filter(t=>t.mode==="followUp").map(t=>t.text);return this.state.compactionQueuedMessages=[],{steering:[...e,...i],followUp:[...n,...o]}}updatePendingMessagesDisplay(){this.pendingMessagesContainer.clear();const{steering:e,followUp:n}=this.getAllQueuedMessages();if(e.length>0||n.length>0){this.pendingMessagesContainer.addChild(new u(1));for(const t of e){const a=r.fg("dim",`Steering: ${t}`);this.pendingMessagesContainer.addChild(new ae(a,1,0))}for(const t of n){const a=r.fg("dim",`Follow-up: ${t}`);this.pendingMessagesContainer.addChild(new ae(a,1,0))}const i=this.getAppKeyDisplay("dequeue"),o=r.fg("dim",`\u21B3 ${i} to edit all queued messages`);this.pendingMessagesContainer.addChild(new ae(o,1,0))}}restoreQueuedMessagesToEditor(e){const{steering:n,followUp:i}=this.clearAllQueues(),o=[...n,...i];if(o.length===0)return this.updatePendingMessagesDisplay(),e?.abort&&this.agent.abort(),0;const t=o.join(`
28
28
 
29
29
  `),a=e?.currentText??this.editor.getText(),h=[t,a].filter(c=>c.trim()).join(`
30
30
 
31
31
  `);return this.editor.setText(h),this.updatePendingMessagesDisplay(),e?.abort&&this.agent.abort(),o.length}queueCompactionMessage(e,n){this.state.compactionQueuedMessages.push({text:e,mode:n}),this.editor.addToHistory?.(e),this.editor.setText(""),this.updatePendingMessagesDisplay(),this.showStatus("Queued message for after compaction")}isExtensionCommand(e){if(!e.startsWith("/"))return!1;const n=this.session.extensionRunner;if(!n)return!1;const i=e.indexOf(" "),o=i===-1?e.slice(1):e.slice(1,i);return!!n.getCommand(o)}async flushCompactionQueue(e){if(this.state.compactionQueuedMessages.length===0)return;const n=[...this.state.compactionQueuedMessages];this.state.compactionQueuedMessages=[],this.updatePendingMessagesDisplay();const i=s(o=>{this.session.clearQueue(),this.state.compactionQueuedMessages=n,this.updatePendingMessagesDisplay(),this.showError(`Failed to send queued message${n.length>1?"s":""}: ${o instanceof Error?o.message:String(o)}`)},"restoreQueue");try{if(e?.willRetry){for(const d of n)this.isExtensionCommand(d.text)?await this.promptAfterRender(d.text):d.mode==="followUp"?await this.session.followUp(d.text):await this.session.steer(d.text);this.updatePendingMessagesDisplay();return}const o=n.findIndex(d=>!this.isExtensionCommand(d.text));if(o===-1){for(const d of n)await this.promptAfterRender(d.text);return}const t=n.slice(0,o),a=n[o],h=n.slice(o+1);for(const d of t)await this.promptAfterRender(d.text);const c=this.promptAfterRender(a.text).catch(d=>{i(d)});for(const d of h)this.isExtensionCommand(d.text)?await this.promptAfterRender(d.text):d.mode==="followUp"?await this.session.followUp(d.text):await this.session.steer(d.text);this.updatePendingMessagesDisplay()}catch(o){i(o)}}flushPendingBashComponents(){for(const e of this.pendingBashComponents)this.pendingMessagesContainer.removeChild(e),this.chatContainer.addChild(e);this.pendingBashComponents=[]}showSelector(e){const n=s(()=>{this.remountEditorShell(),this.ui.setFocus(this.editor)},"done"),{component:i,focus:o}=e(n);this.editorContainer.clear(),this.editorContainer.addChild(i),this.ui.setFocus(o),this.ui.requestRender()}async handleReloadCommand(){if(this.session.isStreaming){this.showWarning("Wait for the current response to finish before reloading.");return}if(this.session.isCompacting){this.showWarning("Wait for compaction to finish before reloading.");return}this.resetExtensionUI();const e=new Pe(this.ui,r,"Reloading extensions, skills, prompts, themes...",{cancellable:!1}),n=this.editor;this.editorContainer.clear(),this.editorContainer.addChild(e),this.ui.setFocus(e),this.ui.requestRender();const i=s(o=>{e.dispose(),this.remountEditorShell(),this.ui.setFocus(this.editor),this.ui.requestRender()},"dismissLoader");try{await this.session.reload(),ue(this.session.resourceLoader.getThemes().themes),this.state.hideThinkingBlock=this.settingsManager.getHideThinkingBlock();const o=this.settingsManager.getTheme(),t=o?Ae(o,!0):{success:!0};t.success||this.showError(`Failed to load theme "${o}": ${t.error}
32
- Fell back to dark theme.`);const a=this.settingsManager.getEditorPaddingX(),h=this.settingsManager.getAutocompleteMaxVisible();this.defaultEditor.setPaddingX(a),this.defaultEditor.setAutocompleteMaxVisible(h),this.editor!==this.defaultEditor&&(this.editor.setPaddingX?.(a),this.editor.setAutocompleteMaxVisible?.(h)),this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor()),this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink()),this.setupAutocomplete(this.fdPath);const c=this.session.extensionRunner;c&&this.setupExtensionShortcuts(c),this.rebuildChatFromMessages(),i(this.editor),this.showLoadedResources({extensionPaths:c?.getExtensionPaths()??[],force:!1,showDiagnosticsWhenQuiet:!0});const d=this.session.modelRegistry.getError();d&&this.showError(`models.json error: ${d}`),this.showStatus("Reloaded extensions, skills, prompts, themes")}catch(o){i(n),this.showError(`Reload failed: ${o instanceof Error?o.message:String(o)}`)}}async handleExportCommand(e){const n=e.split(/\s+/),i=n.length>1?n[1]:void 0;try{const o=await this.session.exportToHtml(i);this.showStatus(`Session exported to: ${o}`)}catch(o){this.showError(`Failed to export session: ${o instanceof Error?o.message:"Unknown error"}`)}}async handleShareCommand(){try{if(de("gh",["auth","status"],{encoding:"utf-8"}).status!==0){this.showError("GitHub CLI is not logged in. Run 'gh auth login' first.");return}}catch{this.showError("GitHub CLI (gh) is not installed. Install it from https://cli.github.com/");return}const e=q.join(J.tmpdir(),"session.html");try{await this.session.exportToHtml(e)}catch(t){this.showError(`Failed to export session: ${t instanceof Error?t.message:"Unknown error"}`);return}const n=new Pe(this.ui,r,"Creating gist...");this.editorContainer.clear(),this.editorContainer.addChild(n),this.ui.setFocus(n),this.ui.requestRender();const i=s(()=>{n.dispose(),this.remountEditorShell(),this.ui.setFocus(this.editor);try{$.unlinkSync(e)}catch{}},"restoreEditor");let o=null;n.onAbort=()=>{o?.kill(),i(),this.showStatus("Share cancelled")};try{const t=await new Promise(d=>{o=We("gh",["gist","create","--public=false",e]);let g="",C="";o.stdout?.on("data",b=>{g+=b.toString()}),o.stderr?.on("data",b=>{C+=b.toString()}),o.on("close",b=>d({stdout:g,stderr:C,code:b}))});if(n.signal.aborted)return;if(i(),t.code!==0){const d=t.stderr?.trim()||"Unknown error";this.showError(`Failed to create gist: ${d}`);return}const a=t.stdout?.trim(),h=a?.split("/").pop();if(!h){this.showError("Failed to parse gist ID from gh output");return}const c=Ne(h);this.showStatus(`Share URL: ${c}
33
- Gist: ${a}`)}catch(t){n.signal.aborted||(i(),this.showError(`Failed to create gist: ${t instanceof Error?t.message:"Unknown error"}`))}}handleCopyCommand(){const e=this.session.getLastAssistantText();if(!e){this.showError("No agent messages to copy yet.");return}try{et(e),this.showStatus("Copied last agent message to clipboard")}catch(n){this.showError(n instanceof Error?n.message:String(n))}}async handleStatusCommand(){const e=this.session.state,n=this.sessionManager,i=s((x,N)=>{const ge=N-2,ve=pe(x),Ie=Math.max(0,ge-ve);return x+" ".repeat(Ie)},"padLine"),o=[],t=Math.min(this.ui.terminal.columns||80,73),a=` >_ NanoPencil (v${this.version}) `,h=Math.max(0,t-a.length-1);o.push(r.fg("border",`\u256D${"\u2500".repeat(Math.max(1,t-2))}\u256E`)),o.push(r.fg("border","\u2502")+r.bold(a)+" ".repeat(h)+r.fg("border","\u2502")),o.push(r.fg("border","\u2502")+" ".repeat(Math.max(1,t-2))+r.fg("border","\u2502"));const c=e.model?.id||"no-model",d=e.thinkingLevel||"off",g=e.model?.reasoning?`reasoning ${d}`:"",C=` Model: ${c}${g?` (${g})`:""}`;o.push(r.fg("border","\u2502")+i(C,t)+r.fg("border","\u2502"));const b=` Agent loop: ${this.session.agentLoopFramework}`;o.push(r.fg("border","\u2502")+i(b,t)+r.fg("border","\u2502"));for(const x of Xt(e.lastResult))o.push(r.fg("border","\u2502")+i(` ${x}`,t)+r.fg("border","\u2502"));let w=this.session.cwd;const E=process.env.HOME||process.env.USERPROFILE;E&&w.startsWith(E)&&(w=`~${w.slice(E.length)}`);const S=this.footerDataProvider.getGitBranch(),f=` Directory: ${w}${S?` (${S})`:""}`;o.push(r.fg("border","\u2502")+i(f,t)+r.fg("border","\u2502"));const p=q.join(this.session.cwd,"AGENTS.md"),M=` AGENTS.md: ${$.existsSync(p)?"AGENTS.md":"not found"}`;o.push(r.fg("border","\u2502")+i(M,t)+r.fg("border","\u2502"));const l=n.getSessionId(),v=` Session: ${n.getSessionName()||l.slice(0,8)}...`;o.push(r.fg("border","\u2502")+i(v,t)+r.fg("border","\u2502"));const k=this.session.modelRegistry.authStorage,I=k.list();let B="Not logged in";I.length>0&&(B=I.map(N=>k.get(N)?.type==="oauth"?`${N} (OAuth)`:`${N} (API key)`).join(", "));const L=` Account: ${B}`;o.push(r.fg("border","\u2502")+i(L,t)+r.fg("border","\u2502")),o.push(r.fg("border","\u2502")+" ".repeat(Math.max(1,t-2))+r.fg("border","\u2502"));let _=0,j=0,Q=0,G=0;for(const x of n.getBranch())x.type==="message"&&x.message.role==="assistant"&&(_+=x.message.usage.input,j+=x.message.usage.output,Q+=x.message.usage.cost.total,G++);const U=s(x=>x.toLocaleString(),"fmt"),ne=s(x=>`$${x.toFixed(4)}`,"fmtCost");o.push(r.fg("border","\u2502")+r.bold(r.fg("accent"," \u2550\u2550\u2550 Session Usage \u2550\u2550\u2550"))+" ".repeat(Math.max(1,t-23))+r.fg("border","\u2502")),o.push(r.fg("border","\u2502")+" ".repeat(Math.max(1,t-2))+r.fg("border","\u2502"));const F=` Requests: ${G}`;o.push(r.fg("border","\u2502")+i(F,t)+r.fg("border","\u2502"));const V=` Input tokens: ${U(_)}`;o.push(r.fg("border","\u2502")+i(V,t)+r.fg("border","\u2502"));const z=` Output tokens: ${U(j)}`;o.push(r.fg("border","\u2502")+i(z,t)+r.fg("border","\u2502"));const oe=` Cost: ${ne(Q)}`;o.push(r.fg("border","\u2502")+i(oe,t)+r.fg("border","\u2502"));const O=this.session.getContextUsage(),ae=O?.contextWindow??e.model?.contextWindow??0,X=O?.percent??0,re=O?.tokens??0,Re=` Context: ${At(X)} ${X.toFixed(1)}% (${U(re)}/${U(ae)})`;o.push(r.fg("border","\u2502")+i(Re,t)+r.fg("border","\u2502")),o.push(r.fg("border",`\u2570${"\u2500".repeat(Math.max(1,t-2))}\u256F`)),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new Bt(o.join(`
34
- `))),this.ui.requestRender()}async handleUsageCommand(){const e=new Map;let n=0,i=0,o=0,t=0,a=0,h=0,c=0;for(const f of this.sessionManager.getBranch())if(f.type==="message"&&f.message.role==="assistant"){const p=f.message,y=p.model||"unknown",M=p.usage.totalTokens||p.usage.input+p.usage.output+p.usage.cacheRead+p.usage.cacheWrite;e.has(y)||e.set(y,{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:0,requestCount:0});const l=e.get(y);l.input+=p.usage.input,l.output+=p.usage.output,l.cacheRead+=p.usage.cacheRead,l.cacheWrite+=p.usage.cacheWrite,l.totalTokens+=M,l.cost+=p.usage.cost.total,l.requestCount++,n+=p.usage.input,i+=p.usage.output,o+=p.usage.cacheRead,t+=p.usage.cacheWrite,h+=M,a+=p.usage.cost.total,c++}const d=this.session.getContextUsage(),g=d?.contextWindow??0,C=s(f=>f.toLocaleString(),"fmt"),b=s(f=>`$${f.toFixed(4)}`,"fmtCost"),w=[];if(w.push(r.bold(r.fg("accent","\u2550\u2550\u2550 Token Usage \u2550\u2550\u2550"))),w.push(""),e.size>0)for(const[f,p]of e)w.push(r.fg("accent",`\u250C\u2500 ${f} \u2500`)),w.push(""),w.push(`\u2502 Requests: ${p.requestCount}`),w.push(`\u2502 Input: ${C(p.input)} tokens`),w.push(`\u2502 Output: ${C(p.output)} tokens`),w.push(`\u2502 Cache: ${C(p.cacheRead+p.cacheWrite)} tokens`),w.push(`\u2502 Total: ${C(p.totalTokens)} tokens`),w.push(`\u2502 Cost: ${b(p.cost)}`),w.push(r.fg("accent",`\u2514${"\u2500".repeat(Math.min(50,f.length+4))}`)),w.push("");w.push(r.bold(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Total \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),w.push(` Requests: ${c}`),w.push(` Input: ${C(n)} tokens`),w.push(` Output: ${C(i)} tokens`),w.push(` Cache: ${C(o+t)} tokens`),w.push(` Total: ${C(h)} tokens`),w.push(` Cost: ${b(a)}`),w.push("");const E=d?.percent!=null?`${d.percent.toFixed(1)}%`:"?";w.push(` Context: ${E} / ${C(g)} tokens`);const S=this.session.state;S.model&&w.push(` Current: ${S.model.id}`),w.push(""),w.push(r.fg("dim"," Tip: Use /settings \u2192 Terminal \u2192 Show token stats to toggle footer display"));for(const f of w)this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(f,1,0))}handleNameCommand(e){const n=e.replace(/^\/name\s*/,"").trim();if(!n){const i=this.sessionManager.getSessionName();i?(this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("dim",`Session name: ${i}`),1,0))):this.showWarning("Usage: /name <name>"),this.ui.requestRender();return}this.sessionManager.appendSessionInfo(n),this.updateTerminalTitle(),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("dim",`Session name set: ${n}`),1,0)),this.ui.requestRender()}handleSessionCommand(){const e=this.session.getSessionStats(),n=this.sessionManager.getSessionName();let i=`${r.bold("Session Info")}
32
+ Fell back to dark theme.`);const a=this.settingsManager.getEditorPaddingX(),h=this.settingsManager.getAutocompleteMaxVisible();this.defaultEditor.setPaddingX(a),this.defaultEditor.setAutocompleteMaxVisible(h),this.editor!==this.defaultEditor&&(this.editor.setPaddingX?.(a),this.editor.setAutocompleteMaxVisible?.(h)),this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor()),this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink()),this.setupAutocomplete(this.fdPath);const c=this.session.extensionRunner;c&&this.setupExtensionShortcuts(c),this.rebuildChatFromMessages(),i(this.editor),this.showLoadedResources({extensionPaths:c?.getExtensionPaths()??[],force:!1,showDiagnosticsWhenQuiet:!0});const d=this.session.modelRegistry.getError();d&&this.showError(`models.json error: ${d}`),this.showStatus("Reloaded extensions, skills, prompts, themes")}catch(o){i(n),this.showError(`Reload failed: ${o instanceof Error?o.message:String(o)}`)}}async handleExportCommand(e){const n=e.split(/\s+/),i=n.length>1?n[1]:void 0;try{const o=await this.session.exportToHtml(i);this.showStatus(`Session exported to: ${o}`)}catch(o){this.showError(`Failed to export session: ${o instanceof Error?o.message:"Unknown error"}`)}}async handleShareCommand(){try{if(re("gh",["auth","status"],{encoding:"utf-8"}).status!==0){this.showError("GitHub CLI is not logged in. Run 'gh auth login' first.");return}}catch{this.showError("GitHub CLI (gh) is not installed. Install it from https://cli.github.com/");return}const e=U.join(X.tmpdir(),"session.html");try{await this.session.exportToHtml(e)}catch(t){this.showError(`Failed to export session: ${t instanceof Error?t.message:"Unknown error"}`);return}const n=new Pe(this.ui,r,"Creating gist...");this.editorContainer.clear(),this.editorContainer.addChild(n),this.ui.setFocus(n),this.ui.requestRender();const i=s(()=>{n.dispose(),this.remountEditorShell(),this.ui.setFocus(this.editor);try{k.unlinkSync(e)}catch{}},"restoreEditor");let o=null;n.onAbort=()=>{o?.kill(),i(),this.showStatus("Share cancelled")};try{const t=await new Promise(d=>{o=We("gh",["gist","create","--public=false",e]);let g="",C="";o.stdout?.on("data",M=>{g+=M.toString()}),o.stderr?.on("data",M=>{C+=M.toString()}),o.on("close",M=>d({stdout:g,stderr:C,code:M}))});if(n.signal.aborted)return;if(i(),t.code!==0){const d=t.stderr?.trim()||"Unknown error";this.showError(`Failed to create gist: ${d}`);return}const a=t.stdout?.trim(),h=a?.split("/").pop();if(!h){this.showError("Failed to parse gist ID from gh output");return}const c=Ne(h);this.showStatus(`Share URL: ${c}
33
+ Gist: ${a}`)}catch(t){n.signal.aborted||(i(),this.showError(`Failed to create gist: ${t instanceof Error?t.message:"Unknown error"}`))}}handleCopyCommand(){const e=this.session.getLastAssistantText();if(!e){this.showError("No agent messages to copy yet.");return}try{et(e),this.showStatus("Copied last agent message to clipboard")}catch(n){this.showError(n instanceof Error?n.message:String(n))}}async handleStatusCommand(){const e=this.session.state,n=this.sessionManager,i=s((x,W)=>{const ge=W-2,ve=pe(x),Ie=Math.max(0,ge-ve);return x+" ".repeat(Ie)},"padLine"),o=[],t=Math.min(this.ui.terminal.columns||80,73),a=` >_ NanoPencil (v${this.version}) `,h=Math.max(0,t-a.length-1);o.push(r.fg("border",`\u256D${"\u2500".repeat(Math.max(1,t-2))}\u256E`)),o.push(r.fg("border","\u2502")+r.bold(a)+" ".repeat(h)+r.fg("border","\u2502")),o.push(r.fg("border","\u2502")+" ".repeat(Math.max(1,t-2))+r.fg("border","\u2502"));const c=e.model?.id||"no-model",d=e.thinkingLevel||"off",g=e.model?.reasoning?`reasoning ${d}`:"",C=` Model: ${c}${g?` (${g})`:""}`;o.push(r.fg("border","\u2502")+i(C,t)+r.fg("border","\u2502"));const M=` Agent loop: ${this.session.agentLoopFramework}`;o.push(r.fg("border","\u2502")+i(M,t)+r.fg("border","\u2502"));for(const x of Xt(e.lastResult))o.push(r.fg("border","\u2502")+i(` ${x}`,t)+r.fg("border","\u2502"));let w=this.session.cwd;const E=process.env.HOME||process.env.USERPROFILE;E&&w.startsWith(E)&&(w=`~${w.slice(E.length)}`);const S=this.footerDataProvider.getGitBranch(),f=` Directory: ${w}${S?` (${S})`:""}`;o.push(r.fg("border","\u2502")+i(f,t)+r.fg("border","\u2502"));const p=U.join(this.session.cwd,"AGENTS.md"),b=` AGENTS.md: ${k.existsSync(p)?"AGENTS.md":"not found"}`;o.push(r.fg("border","\u2502")+i(b,t)+r.fg("border","\u2502"));const l=n.getSessionId(),$=` Session: ${n.getSessionName()||l.slice(0,8)}...`;o.push(r.fg("border","\u2502")+i($,t)+r.fg("border","\u2502"));const A=this.session.modelRegistry.authStorage,R=A.list();let H="Not logged in";R.length>0&&(H=R.map(W=>A.get(W)?.type==="oauth"?`${W} (OAuth)`:`${W} (API key)`).join(", "));const te=` Account: ${H}`;o.push(r.fg("border","\u2502")+i(te,t)+r.fg("border","\u2502")),o.push(r.fg("border","\u2502")+" ".repeat(Math.max(1,t-2))+r.fg("border","\u2502"));let K=0,_=0,j=0,Q=0;for(const x of n.getBranch())x.type==="message"&&x.message.role==="assistant"&&(K+=x.message.usage.input,_+=x.message.usage.output,j+=x.message.usage.cost.total,Q++);const D=s(x=>x.toLocaleString(),"fmt"),se=s(x=>`$${x.toFixed(4)}`,"fmtCost");o.push(r.fg("border","\u2502")+r.bold(r.fg("accent"," \u2550\u2550\u2550 Session Usage \u2550\u2550\u2550"))+" ".repeat(Math.max(1,t-23))+r.fg("border","\u2502")),o.push(r.fg("border","\u2502")+" ".repeat(Math.max(1,t-2))+r.fg("border","\u2502"));const q=` Requests: ${Q}`;o.push(r.fg("border","\u2502")+i(q,t)+r.fg("border","\u2502"));const G=` Input tokens: ${D(K)}`;o.push(r.fg("border","\u2502")+i(G,t)+r.fg("border","\u2502"));const V=` Output tokens: ${D(_)}`;o.push(r.fg("border","\u2502")+i(V,t)+r.fg("border","\u2502"));const ie=` Cost: ${se(j)}`;o.push(r.fg("border","\u2502")+i(ie,t)+r.fg("border","\u2502"));const B=this.session.getContextUsage(),ne=B?.contextWindow??e.model?.contextWindow??0,z=B?.percent??0,oe=B?.tokens??0,Re=` Context: ${At(z)} ${z.toFixed(1)}% (${D(oe)}/${D(ne)})`;o.push(r.fg("border","\u2502")+i(Re,t)+r.fg("border","\u2502")),o.push(r.fg("border",`\u2570${"\u2500".repeat(Math.max(1,t-2))}\u256F`)),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new Bt(o.join(`
34
+ `))),this.ui.requestRender()}async handleUsageCommand(){const e=new Map;let n=0,i=0,o=0,t=0,a=0,h=0,c=0;for(const f of this.sessionManager.getBranch())if(f.type==="message"&&f.message.role==="assistant"){const p=f.message,y=p.model||"unknown",b=p.usage.totalTokens||p.usage.input+p.usage.output+p.usage.cacheRead+p.usage.cacheWrite;e.has(y)||e.set(y,{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:0,requestCount:0});const l=e.get(y);l.input+=p.usage.input,l.output+=p.usage.output,l.cacheRead+=p.usage.cacheRead,l.cacheWrite+=p.usage.cacheWrite,l.totalTokens+=b,l.cost+=p.usage.cost.total,l.requestCount++,n+=p.usage.input,i+=p.usage.output,o+=p.usage.cacheRead,t+=p.usage.cacheWrite,h+=b,a+=p.usage.cost.total,c++}const d=this.session.getContextUsage(),g=d?.contextWindow??0,C=s(f=>f.toLocaleString(),"fmt"),M=s(f=>`$${f.toFixed(4)}`,"fmtCost"),w=[];if(w.push(r.bold(r.fg("accent","\u2550\u2550\u2550 Token Usage \u2550\u2550\u2550"))),w.push(""),e.size>0)for(const[f,p]of e)w.push(r.fg("accent",`\u250C\u2500 ${f} \u2500`)),w.push(""),w.push(`\u2502 Requests: ${p.requestCount}`),w.push(`\u2502 Input: ${C(p.input)} tokens`),w.push(`\u2502 Output: ${C(p.output)} tokens`),w.push(`\u2502 Cache: ${C(p.cacheRead+p.cacheWrite)} tokens`),w.push(`\u2502 Total: ${C(p.totalTokens)} tokens`),w.push(`\u2502 Cost: ${M(p.cost)}`),w.push(r.fg("accent",`\u2514${"\u2500".repeat(Math.min(50,f.length+4))}`)),w.push("");w.push(r.bold(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Total \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),w.push(` Requests: ${c}`),w.push(` Input: ${C(n)} tokens`),w.push(` Output: ${C(i)} tokens`),w.push(` Cache: ${C(o+t)} tokens`),w.push(` Total: ${C(h)} tokens`),w.push(` Cost: ${M(a)}`),w.push("");const E=d?.percent!=null?`${d.percent.toFixed(1)}%`:"?";w.push(` Context: ${E} / ${C(g)} tokens`);const S=this.session.state;S.model&&w.push(` Current: ${S.model.id}`),w.push(""),w.push(r.fg("dim"," Tip: Use /settings \u2192 Terminal \u2192 Show token stats to toggle footer display"));for(const f of w)this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(f,1,0))}handleNameCommand(e){const n=e.replace(/^\/name\s*/,"").trim();if(!n){const i=this.sessionManager.getSessionName();i?(this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("dim",`Session name: ${i}`),1,0))):this.showWarning("Usage: /name <name>"),this.ui.requestRender();return}this.sessionManager.appendSessionInfo(n),this.updateTerminalTitle(),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("dim",`Session name set: ${n}`),1,0)),this.ui.requestRender()}handleSessionCommand(){const e=this.session.getSessionStats(),n=this.sessionManager.getSessionName();let i=`${r.bold("Session Info")}
35
35
 
36
36
  `;n&&(i+=`${r.fg("dim","Name:")} ${n}
37
37
  `),i+=`${r.fg("dim","File:")} ${e.sessionFile??"In-memory"}
@@ -54,7 +54,7 @@ Gist: ${a}`)}catch(t){n.signal.aborted||(i(),this.showError(`Failed to create gi
54
54
  ${r.bold("Cost")}
55
55
  `,i+=`${r.fg("dim","Total:")} ${e.cost.toFixed(4)}`),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(i,1,0)),this.ui.requestRender()}handleChangelogCommand(){const e=Ye(),n=Ze(e),i=n.length>0?n.reverse().map(o=>o.content).join(`
56
56
 
57
- `):"No changelog entries found.";this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new se),this.chatContainer.addChild(new m(r.bold(r.fg("accent","What's New")),1,0)),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new me(i,1,1,this.getMarkdownThemeWithSettings())),this.chatContainer.addChild(new se),this.ui.requestRender()}capitalizeKey(e){return e.split("/").map(n=>n.split("+").map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join("+")).join("/")}getAppKeyDisplay(e){return this.capitalizeKey(D(this.keybindings,e))}getEditorKeyDisplay(e){return this.capitalizeKey(vt(e))}handleHotkeysCommand(){const e=this.getEditorKeyDisplay("cursorWordLeft"),n=this.getEditorKeyDisplay("cursorWordRight"),i=this.getEditorKeyDisplay("cursorLineStart"),o=this.getEditorKeyDisplay("cursorLineEnd"),t=this.getEditorKeyDisplay("jumpForward"),a=this.getEditorKeyDisplay("jumpBackward"),h=this.getEditorKeyDisplay("pageUp"),c=this.getEditorKeyDisplay("pageDown"),d=this.getEditorKeyDisplay("submit"),g=this.getEditorKeyDisplay("newLine"),C=this.getEditorKeyDisplay("deleteWordBackward"),b=this.getEditorKeyDisplay("deleteWordForward"),w=this.getEditorKeyDisplay("deleteToLineStart"),E=this.getEditorKeyDisplay("deleteToLineEnd"),S=this.getEditorKeyDisplay("yank"),f=this.getEditorKeyDisplay("yankPop"),p=this.getEditorKeyDisplay("undo"),y=this.getEditorKeyDisplay("tab"),M=this.getAppKeyDisplay("interrupt"),l=this.getAppKeyDisplay("showResources"),T=this.getAppKeyDisplay("clear"),v=this.getAppKeyDisplay("exit"),k=this.getAppKeyDisplay("suspend"),I=this.getAppKeyDisplay("cycleThinkingLevel"),B=this.getAppKeyDisplay("cycleModelForward"),L=this.getAppKeyDisplay("selectModel"),_=this.getAppKeyDisplay("selectProviderThenModel"),j=this.getAppKeyDisplay("expandTools"),Q=this.getAppKeyDisplay("toggleThinking"),G=this.getAppKeyDisplay("externalEditor"),U=this.getAppKeyDisplay("followUp"),ne=this.getAppKeyDisplay("dequeue");let F=`
57
+ `):"No changelog entries found.";this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new Z),this.chatContainer.addChild(new m(r.bold(r.fg("accent","What's New")),1,0)),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new me(i,1,1,this.getMarkdownThemeWithSettings())),this.chatContainer.addChild(new Z),this.ui.requestRender()}capitalizeKey(e){return e.split("/").map(n=>n.split("+").map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join("+")).join("/")}getAppKeyDisplay(e){return this.capitalizeKey(L(this.keybindings,e))}getEditorKeyDisplay(e){return this.capitalizeKey(vt(e))}handleHotkeysCommand(){const e=this.getEditorKeyDisplay("cursorWordLeft"),n=this.getEditorKeyDisplay("cursorWordRight"),i=this.getEditorKeyDisplay("cursorLineStart"),o=this.getEditorKeyDisplay("cursorLineEnd"),t=this.getEditorKeyDisplay("jumpForward"),a=this.getEditorKeyDisplay("jumpBackward"),h=this.getEditorKeyDisplay("pageUp"),c=this.getEditorKeyDisplay("pageDown"),d=this.getEditorKeyDisplay("submit"),g=this.getEditorKeyDisplay("newLine"),C=this.getEditorKeyDisplay("deleteWordBackward"),M=this.getEditorKeyDisplay("deleteWordForward"),w=this.getEditorKeyDisplay("deleteToLineStart"),E=this.getEditorKeyDisplay("deleteToLineEnd"),S=this.getEditorKeyDisplay("yank"),f=this.getEditorKeyDisplay("yankPop"),p=this.getEditorKeyDisplay("undo"),y=this.getEditorKeyDisplay("tab"),b=this.getAppKeyDisplay("interrupt"),l=this.getAppKeyDisplay("showResources"),T=this.getAppKeyDisplay("clear"),$=this.getAppKeyDisplay("exit"),A=this.getAppKeyDisplay("suspend"),R=this.getAppKeyDisplay("cycleThinkingLevel"),H=this.getAppKeyDisplay("cycleModelForward"),te=this.getAppKeyDisplay("selectModel"),K=this.getAppKeyDisplay("selectProviderThenModel"),_=this.getAppKeyDisplay("expandTools"),j=this.getAppKeyDisplay("toggleThinking"),Q=this.getAppKeyDisplay("externalEditor"),D=this.getAppKeyDisplay("followUp"),se=this.getAppKeyDisplay("dequeue");let q=`
58
58
  **Navigation**
59
59
  | Key | Action |
60
60
  |-----|--------|
@@ -72,7 +72,7 @@ ${r.bold("Cost")}
72
72
  | \`${d}\` | Send message |
73
73
  | \`${g}\` | New line${process.platform==="win32"?" (Ctrl+Enter on Windows Terminal)":""} |
74
74
  | \`${C}\` | Delete word backwards |
75
- | \`${b}\` | Delete word forwards |
75
+ | \`${M}\` | Delete word forwards |
76
76
  | \`${w}\` | Delete to start of line |
77
77
  | \`${E}\` | Delete to end of line |
78
78
  | \`${S}\` | Paste the most-recently-deleted text |
@@ -83,35 +83,35 @@ ${r.bold("Cost")}
83
83
  | Key | Action |
84
84
  |-----|--------|
85
85
  | \`${y}\` | Path completion / accept autocomplete |
86
- | \`${M}\` | Cancel autocomplete / abort streaming |
86
+ | \`${b}\` | Cancel autocomplete / abort streaming |
87
87
  | \`${l}\` | Show context/skills/extensions |
88
88
  | \`${T}\` | Clear editor (first) / exit (second) |
89
- | \`${v}\` | Exit (when editor is empty) |
90
- | \`${k}\` | Suspend to background |
91
- | \`${I}\` | Cycle thinking level |
92
- | \`${B}\` | Cycle models |
93
- | \`${L}\` | Open model selector |
94
- | \`${_}\` | Select provider then model |
95
- | \`${j}\` | Toggle tool output expansion |
96
- | \`${Q}\` | Toggle thinking block visibility |
97
- | \`${G}\` | Edit message in external editor |
98
- | \`${U}\` | Queue follow-up message |
99
- | \`${ne}\` | Restore queued messages |
89
+ | \`${$}\` | Exit (when editor is empty) |
90
+ | \`${A}\` | Suspend to background |
91
+ | \`${R}\` | Cycle thinking level |
92
+ | \`${H}\` | Cycle models |
93
+ | \`${te}\` | Open model selector |
94
+ | \`${K}\` | Select provider then model |
95
+ | \`${_}\` | Toggle tool output expansion |
96
+ | \`${j}\` | Toggle thinking block visibility |
97
+ | \`${Q}\` | Edit message in external editor |
98
+ | \`${D}\` | Queue follow-up message |
99
+ | \`${se}\` | Restore queued messages |
100
100
  | \`Ctrl+V\` | Paste image from clipboard |
101
101
  | \`/\` | Slash commands |
102
102
  | \`!\` | Run bash command |
103
103
  | \`!!\` | Run bash command (excluded from context) |
104
- `;const V=this.session.extensionRunner;if(V){const z=V.getShortcuts(this.keybindings.getEffectiveConfig());if(z.size>0){F+=`
104
+ `;const G=this.session.extensionRunner;if(G){const V=G.getShortcuts(this.keybindings.getEffectiveConfig());if(V.size>0){q+=`
105
105
  **Extensions**
106
106
  | Key | Action |
107
107
  |-----|--------|
108
- `;for(const[oe,O]of z){const ae=O.description??O.extensionPath,X=oe.replace(/\b\w/g,re=>re.toUpperCase());F+=`| \`${X}\` | ${ae} |
109
- `}}}this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new se),this.chatContainer.addChild(new m(r.bold(r.fg("accent","Keyboard Shortcuts")),1,0)),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new me(F.trim(),1,1,this.getMarkdownThemeWithSettings())),this.chatContainer.addChild(new se),this.ui.requestRender()}async handleClearCommand(){this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear(),await this.session.newSession(),this.clearStatusTimers(),this.chatContainer.clear(),this.pendingMessagesContainer.clear(),this.state.compactionQueuedMessages=[],this.state.streamingComponent=void 0,this.state.streamingMessage=void 0,this.state.pendingTools.clear(),this.imagePipeline.clearAttachments(),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(`${r.fg("accent","\u2713 New session started")}`,1,1)),this.ui.requestRender()}handleRenderDebugCommand(){const e=this.ui.terminal.columns,n=this.ui.terminal.rows,i=this.ui.render(e),o=Fe(),t=[`Debug output at ${new Date().toISOString()}`,`Terminal: ${e}x${n}`,`Total lines: ${i.length}`,"","=== All rendered lines with visible widths ===",...i.map((a,h)=>{const c=pe(a),d=JSON.stringify(a);return`[${h}] (w=${c}) ${d}`}),"","=== Agent messages (JSONL) ===",...this.session.messages.map(a=>JSON.stringify(a)),""].join(`
110
- `);$.mkdirSync(q.dirname(o),{recursive:!0}),$.writeFileSync(o,t),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(`${r.fg("accent","\u2713 Debug log written")}
111
- ${r.fg("muted",o)}`,1,1)),this.ui.requestRender()}handleArminSaysHi(){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new st(this.ui)),this.ui.requestRender()}handleShowResourcesCommand(){const e=this.session.extensionRunner;this.showLoadedResources({extensionPaths:e?.getExtensionPaths()??[],force:!0,showDiagnosticsWhenQuiet:!0}),this.ui.requestRender()}handleDaxnuts(){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new kt(this.ui)),this.ui.requestRender()}async handleBashCommand(e,n=!1){const i=this.session.extensionRunner,o=i?await i.emitUserBash({type:"user_bash",command:e,excludeFromContext:n,cwd:this.session.cwd}):void 0;if(o?.result){const a=o.result;this.bashComponent=new ce(e,this.ui,n),this.session.isStreaming?(this.pendingMessagesContainer.addChild(this.bashComponent),this.pendingBashComponents.push(this.bashComponent)):this.chatContainer.addChild(this.bashComponent),a.output&&this.bashComponent.appendOutput(a.output),this.bashComponent.setComplete(a.exitCode,a.cancelled,a.truncated?{truncated:!0,content:a.output}:void 0,a.fullOutputPath),this.session.recordBashResult(e,a,{excludeFromContext:n}),this.bashComponent=void 0,this.ui.requestRender();return}const t=this.session.isStreaming;this.bashComponent=new ce(e,this.ui,n),t?(this.pendingMessagesContainer.addChild(this.bashComponent),this.pendingBashComponents.push(this.bashComponent)):this.chatContainer.addChild(this.bashComponent),this.ui.requestRender();try{const a=await this.session.executeBash(e,h=>{this.bashComponent&&(this.bashComponent.appendOutput(h),this.ui.requestRender())},{excludeFromContext:n,operations:o?.operations});this.bashComponent&&this.bashComponent.setComplete(a.exitCode,a.cancelled,a.truncated?{truncated:!0,content:a.output}:void 0,a.fullOutputPath)}catch(a){this.bashComponent&&this.bashComponent.setComplete(void 0,!1),this.showError(`Bash command failed: ${a instanceof Error?a.message:"Unknown error"}`)}this.bashComponent=void 0,this.ui.requestRender()}async handleCompactCommand(e){if(this.sessionManager.getEntries().filter(o=>o.type==="message").length<2){this.showWarning("Nothing to compact (no messages yet)");return}await this.executeCompaction(e,!1)}async executeCompaction(e,n=!1){this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear();const i=this.defaultEditor.onEscape;this.defaultEditor.onEscape=()=>{this.session.abortCompaction()},this.chatContainer.addChild(new u(1));const o=`(${D(this.keybindings,"interrupt")} to cancel)`,t=n?`Auto-compacting context... ${o}`:`Compacting context... ${o}`,a=new Mt(this.ui,r,t);this.statusContainer.addChild(a),this.ui.requestRender();let h;try{h=await this.session.compact(e),this.rebuildChatFromMessages();const c=Qe(h.summary,h.tokensBefore,new Date().toISOString());this.addMessageToChat(c),this.footer.invalidate()}catch(c){const d=c instanceof Error?c.message:String(c);d==="Compaction cancelled"||c instanceof Error&&c.name==="AbortError"?this.showError("Compaction cancelled"):this.showError(`Compaction failed: ${d}`)}finally{a.stop(),this.statusContainer.clear(),this.defaultEditor.onEscape=i}return this.flushCompactionQueue({willRetry:!1}),h}stop(){this.stopWelcomeBannerTimer(),this.clearBuddyPetResetTimer(),this.buddyPet?.dispose(),this.buddyPet=null,this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.clearExtensionTerminalInputListeners(),this.footer.dispose(),this.footerDataProvider.dispose(),this.unsubscribe&&this.unsubscribe(),this.isInitialized&&(this.ui.stop(),this.isInitialized=!1)}async applyPersonaFromSessionIfAny(){const n=this.session.sessionManager.getEntries().filter(t=>t.type==="custom"&&t.customType==="persona");let i;if(n.length>0){const t=n[n.length-1],a=t?.data?.personaId??t?.data?.id;typeof a=="string"&&a.trim()&&(i=a)}if(i=i??ee(),!i)return;if(ee()===i&&n.length===0){process.env.NANO_PERSONA_DIR??=A(te(i));return}n.length>0&&Me(i),process.env.NANOMEM_MEMORY_DIR=A(we(i)),process.env.SOUL_DIR=A(ye(i)),process.env.MCP_CONFIG_PATH=A(Ce(i)),process.env.NANO_PERSONA_DIR=A(te(i)),n.length>0&&!this.session.isStreaming&&!this.session.isCompacting&&await this.session.reload()}handleSoulCommand(){const e=this.session._soulManager;if(!e){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("warning","\u26A0\uFE0F Soul Not Enabled"),1,0)),this.chatContainer.addChild(new m(r.fg("dim","Soul (AI personality system) is not enabled. Please use NanoPencil 1.3.0 or later."),1,0)),this.ui.requestRender();return}const n=Lt(e,{compact:!1});this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(n,1,0)),this.ui.requestRender()}async handlePersonaCommand(e){const n=e.trim().split(/\s+/),i=(n[1]??"list").toLowerCase(),o=n[2];if(i==="list"||i==="use"&&!o){const a=Se(),h=ee();this.showSelector(c=>{const d=new Tt(this.ui,a,h,Xe,g=>{c(),this.switchPersona(g)},()=>{c(),this.ui.requestRender()});return{component:d,focus:d}});return}if(i!=="use"){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("dim",`Usage:
108
+ `;for(const[ie,B]of V){const ne=B.description??B.extensionPath,z=ie.replace(/\b\w/g,oe=>oe.toUpperCase());q+=`| \`${z}\` | ${ne} |
109
+ `}}}this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new Z),this.chatContainer.addChild(new m(r.bold(r.fg("accent","Keyboard Shortcuts")),1,0)),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new me(q.trim(),1,1,this.getMarkdownThemeWithSettings())),this.chatContainer.addChild(new Z),this.ui.requestRender()}async handleClearCommand(){this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear(),await this.session.newSession(),this.clearStatusTimers(),this.chatContainer.clear(),this.pendingMessagesContainer.clear(),this.state.compactionQueuedMessages=[],this.state.streamingComponent=void 0,this.state.streamingMessage=void 0,this.state.pendingTools.clear(),this.imagePipeline.clearAttachments(),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(`${r.fg("accent","\u2713 New session started")}`,1,1)),this.ui.requestRender()}handleRenderDebugCommand(){const e=this.ui.terminal.columns,n=this.ui.terminal.rows,i=this.ui.render(e),o=Fe(),t=[`Debug output at ${new Date().toISOString()}`,`Terminal: ${e}x${n}`,`Total lines: ${i.length}`,"","=== All rendered lines with visible widths ===",...i.map((a,h)=>{const c=pe(a),d=JSON.stringify(a);return`[${h}] (w=${c}) ${d}`}),"","=== Agent messages (JSONL) ===",...this.session.messages.map(a=>JSON.stringify(a)),""].join(`
110
+ `);k.mkdirSync(U.dirname(o),{recursive:!0}),k.writeFileSync(o,t),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(`${r.fg("accent","\u2713 Debug log written")}
111
+ ${r.fg("muted",o)}`,1,1)),this.ui.requestRender()}handleArminSaysHi(){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new st(this.ui)),this.ui.requestRender()}handleShowResourcesCommand(){const e=this.session.extensionRunner;this.showLoadedResources({extensionPaths:e?.getExtensionPaths()??[],force:!0,showDiagnosticsWhenQuiet:!0}),this.ui.requestRender()}handleDaxnuts(){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new kt(this.ui)),this.ui.requestRender()}async handleBashCommand(e,n=!1){const i=this.session.extensionRunner,o=i?await i.emitUserBash({type:"user_bash",command:e,excludeFromContext:n,cwd:this.session.cwd}):void 0;if(o?.result){const a=o.result;this.bashComponent=new ce(e,this.ui,n),this.session.isStreaming?(this.pendingMessagesContainer.addChild(this.bashComponent),this.pendingBashComponents.push(this.bashComponent)):this.chatContainer.addChild(this.bashComponent),a.output&&this.bashComponent.appendOutput(a.output),this.bashComponent.setComplete(a.exitCode,a.cancelled,a.truncated?{truncated:!0,content:a.output}:void 0,a.fullOutputPath),this.session.recordBashResult(e,a,{excludeFromContext:n}),this.bashComponent=void 0,this.ui.requestRender();return}const t=this.session.isStreaming;this.bashComponent=new ce(e,this.ui,n),t?(this.pendingMessagesContainer.addChild(this.bashComponent),this.pendingBashComponents.push(this.bashComponent)):this.chatContainer.addChild(this.bashComponent),this.ui.requestRender();try{const a=await this.session.executeBash(e,h=>{this.bashComponent&&(this.bashComponent.appendOutput(h),this.ui.requestRender())},{excludeFromContext:n,operations:o?.operations});this.bashComponent&&this.bashComponent.setComplete(a.exitCode,a.cancelled,a.truncated?{truncated:!0,content:a.output}:void 0,a.fullOutputPath)}catch(a){this.bashComponent&&this.bashComponent.setComplete(void 0,!1),this.showError(`Bash command failed: ${a instanceof Error?a.message:"Unknown error"}`)}this.bashComponent=void 0,this.ui.requestRender()}async handleCompactCommand(e){if(this.sessionManager.getEntries().filter(o=>o.type==="message").length<2){this.showWarning("Nothing to compact (no messages yet)");return}await this.executeCompaction(e,!1)}async executeCompaction(e,n=!1){this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.statusContainer.clear();const i=this.defaultEditor.onEscape;this.defaultEditor.onEscape=()=>{this.session.abortCompaction()},this.chatContainer.addChild(new u(1));const o=`(${L(this.keybindings,"interrupt")} to cancel)`,t=n?`Auto-compacting context... ${o}`:`Compacting context... ${o}`,a=new bt(this.ui,r,t);this.statusContainer.addChild(a),this.ui.requestRender();let h;try{h=await this.session.compact(e),this.rebuildChatFromMessages();const c=Qe(h.summary,h.tokensBefore,new Date().toISOString());this.addMessageToChat(c),this.footer.invalidate()}catch(c){const d=c instanceof Error?c.message:String(c);d==="Compaction cancelled"||c instanceof Error&&c.name==="AbortError"?this.showError("Compaction cancelled"):this.showError(`Compaction failed: ${d}`)}finally{a.stop(),this.statusContainer.clear(),this.defaultEditor.onEscape=i}return this.flushCompactionQueue({willRetry:!1}),h}stop(){this.stopWelcomeBannerTimer(),this.clearBuddyPetResetTimer(),this.buddyPet?.dispose(),this.buddyPet=null,this.state.loadingAnimation&&(this.state.loadingAnimation.stop(),this.state.loadingAnimation=void 0),this.clearExtensionTerminalInputListeners(),this.footer.dispose(),this.footerDataProvider.dispose(),this.unsubscribe&&this.unsubscribe(),this.isInitialized&&(this.ui.stop(),this.isInitialized=!1)}async applyPersonaFromSessionIfAny(){const n=this.session.sessionManager.getEntries().filter(o=>o.type==="custom"&&o.customType==="persona");let i;if(n.length>0){const o=n[n.length-1],t=o?.data?.personaId??o?.data?.id;typeof t=="string"&&t.trim()&&(i=t)}i=i??de(),i&&(process.env.NANOMEM_MEMORY_DIR=I(we(i)),process.env.SOUL_DIR=I(ye(i)),process.env.MCP_CONFIG_PATH=I(Ce(i)),process.env.NANO_PERSONA_DIR=I(le(i)),n.length>0&&be(i),!this.session.isStreaming&&!this.session.isCompacting&&await this.session.reload())}handleSoulCommand(){const e=this.session._soulManager;if(!e){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("warning","\u26A0\uFE0F Soul Not Enabled"),1,0)),this.chatContainer.addChild(new m(r.fg("dim","Soul (AI personality system) is not enabled. Please use NanoPencil 1.3.0 or later."),1,0)),this.ui.requestRender();return}const n=Lt(e,{compact:!1});this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(n,1,0)),this.ui.requestRender()}async handlePersonaCommand(e){const n=e.trim().split(/\s+/),i=(n[1]??"list").toLowerCase(),o=n[2];if(i==="list"||i==="use"&&!o){const a=Se(),h=de();this.showSelector(c=>{const d=new Tt(this.ui,a,h,Xe,g=>{c(),this.switchPersona(g)},()=>{c(),this.ui.requestRender()});return{component:d,focus:d}});return}if(i!=="use"){this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(r.fg("dim",`Usage:
112
112
  - /persona (open selector)
113
- - /persona use <personaId>`),1,0)),this.ui.requestRender();return}const t=o?o.trim():"";if(!t){this.showError("Missing personaId. Use: /persona use <personaId>");return}await this.switchPersona(t)}async switchPersona(e){const n=te(e);if(!$.existsSync(n)){this.showError(`Persona not found: ${e}
114
- Expected: ${n}`);return}const i=this.session.sessionManager.getBranch();let o;for(let a=i.length-1;a>=0;a--){const h=i[a];if(h?.type==="message"&&h?.message?.role==="user"){o=h.id;break}}if(!o){this.showError("No user message found in the current session branch.");return}(await this.session.fork(o)).cancelled||(this.session.sessionManager.appendCustomEntry("persona",{personaId:e}),Me(e),process.env.NANOMEM_MEMORY_DIR=A(we(e)),process.env.SOUL_DIR=A(ye(e)),process.env.MCP_CONFIG_PATH=A(Ce(e)),process.env.NANO_PERSONA_DIR=A(te(e)),process.env.NANOPENCIL_JUST_SWITCHED_PERSONA="true",await this.handleReloadCommand(),this.showStatus(`Persona switched to: ${e}`))}handleMemoryCommand(){const e=[];e.push(r.fg("accent","\u{1F4DA} Project Memory - NanoMem")),e.push(""),e.push(r.fg("dim",`Storage: ${this.session.agentDir}/memory/`)),e.push(r.fg("dim"," - knowledge.json (project knowledge)")),e.push(r.fg("dim"," - lessons.json (lessons learned)")),e.push(r.fg("dim"," - preferences.json (user preferences)")),e.push(r.fg("dim"," - patterns.json (behavior patterns)")),e.push(r.fg("dim"," - facets.json (patterns/struggles)")),e.push(""),e.push(r.fg("dim","\u{1F4A1} Tip: NanoMem automatically extracts and remembers project knowledge from conversations")),e.push(r.fg("dim"," - Remembers API endpoints, configuration options")),e.push(r.fg("dim"," - Learns error patterns and solutions")),e.push(r.fg("dim"," - Recognizes user preferences and coding style")),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(e.join(`
113
+ - /persona use <personaId>`),1,0)),this.ui.requestRender();return}const t=o?o.trim():"";if(!t){this.showError("Missing personaId. Use: /persona use <personaId>");return}await this.switchPersona(t)}async switchPersona(e){const n=le(e);if(!k.existsSync(n)){this.showError(`Persona not found: ${e}
114
+ Expected: ${n}`);return}const i=this.session.sessionManager.getBranch();let o;for(let t=i.length-1;t>=0;t--){const a=i[t];if(a?.type==="message"&&a?.message?.role==="user"){o=a.id;break}}o&&(await this.session.fork(o)).cancelled||(this.session.sessionManager.appendCustomEntry("persona",{personaId:e}),be(e),process.env.NANOMEM_MEMORY_DIR=I(we(e)),process.env.SOUL_DIR=I(ye(e)),process.env.MCP_CONFIG_PATH=I(Ce(e)),process.env.NANO_PERSONA_DIR=I(le(e)),process.env.NANOPENCIL_JUST_SWITCHED_PERSONA="true",await this.handleReloadCommand(),this.showStatus(`Persona switched to: ${e}`))}handleMemoryCommand(){const e=[];e.push(r.fg("accent","\u{1F4DA} Project Memory - NanoMem")),e.push(""),e.push(r.fg("dim",`Storage: ${this.session.agentDir}/memory/`)),e.push(r.fg("dim"," - knowledge.json (project knowledge)")),e.push(r.fg("dim"," - lessons.json (lessons learned)")),e.push(r.fg("dim"," - preferences.json (user preferences)")),e.push(r.fg("dim"," - patterns.json (behavior patterns)")),e.push(r.fg("dim"," - facets.json (patterns/struggles)")),e.push(""),e.push(r.fg("dim","\u{1F4A1} Tip: NanoMem automatically extracts and remembers project knowledge from conversations")),e.push(r.fg("dim"," - Remembers API endpoints, configuration options")),e.push(r.fg("dim"," - Learns error patterns and solutions")),e.push(r.fg("dim"," - Recognizes user preferences and coding style")),this.chatContainer.addChild(new u(1)),this.chatContainer.addChild(new m(e.join(`
115
115
  `),1,0)),this.ui.requestRender()}handleBrowserOptInCommand(){this.showStatus(["Browser automation is opt-in.","","Enable it by starting NanoPencil with:"," --extension extensions/builtin/browser","","Or add that path to your extensions config, then run /browser status."].join(`
116
116
  `))}async handleMcpCommand(e){const n=e.trim().split(/\s+/),i=(n[1]||"list").toLowerCase(),o=n[2];if(i==="list"){const t=fe();if(this.chatContainer.addChild(new u(1)),t.length===0)this.chatContainer.addChild(new m(r.fg("dim","No MCP servers configured."),1,0));else{const a=[r.bold("MCP Servers"),"",...t.map(h=>{const c=h.enabled===!1?"disabled":"enabled";return`- ${h.id} (${h.name}) [${c}]`}),"",r.fg("dim","Use: /mcp enable <id> or /mcp disable <id>")];this.chatContainer.addChild(new m(a.join(`
117
117
  `),1,0))}this.ui.requestRender();return}if(i==="status"||i==="tools"){const t=this.session.getAllTools().filter(a=>a.name.startsWith("mcp_"));if(this.chatContainer.addChild(new u(1)),t.length===0)this.chatContainer.addChild(new m([r.bold("MCP Runtime Status"),"","No MCP tools are currently registered in this session.",r.fg("dim","Tip: run /reload and check startup logs for MCP errors.")].join(`
@@ -17,6 +17,7 @@ import type { Component, Spacer, Text } from "@pencil-agent/tui";
17
17
  import type { AssistantMessageComponent } from "../components/assistant-message.js";
18
18
  import type { CustomMessageComponent } from "../components/custom-message.js";
19
19
  import type { PlanProgressPanelComponent } from "../components/plan-progress-panel.js";
20
+ import type { TaskStatusPanelComponent } from "../components/task-status-panel.js";
20
21
  import type { ToolExecutionComponent } from "../components/tool-execution.js";
21
22
  export type CompactionQueuedMessage = {
22
23
  text: string;
@@ -63,6 +64,7 @@ export declare class InteractiveState {
63
64
  subAgentPanelComponent: Component | undefined;
64
65
  planProgress: PlanProgressState | undefined;
65
66
  planProgressPanel: PlanProgressPanelComponent | undefined;
67
+ taskStatusPanel: TaskStatusPanelComponent | undefined;
66
68
  toolOutputExpanded: boolean;
67
69
  hideThinkingBlock: boolean;
68
70
  compactionQueuedMessages: CompactionQueuedMessage[];
@@ -1 +1 @@
1
- var a=Object.defineProperty;var n=(e,s)=>a(e,"name",{value:s,configurable:!0});class t{static{n(this,"InteractiveState")}loadingAnimation=void 0;pendingWorkingMessage=void 0;workingMessageOverride=void 0;agentRunStartMs=void 0;agentRunTimer=void 0;welcomeBannerTimer=void 0;lastStatusSpacer=void 0;lastStatusText=void 0;streamingComponent=void 0;streamingMessage=void 0;customStreamComponents=new Map;pendingTools=new Map;subAgentStates=new Map;subAgentPanelComponent=void 0;planProgress=void 0;planProgressPanel=void 0;toolOutputExpanded=!1;hideThinkingBlock=!1;compactionQueuedMessages=[];optimisticUserMessages=[]}export{t as InteractiveState};
1
+ var s=Object.defineProperty;var n=(e,a)=>s(e,"name",{value:a,configurable:!0});class d{static{n(this,"InteractiveState")}loadingAnimation=void 0;pendingWorkingMessage=void 0;workingMessageOverride=void 0;agentRunStartMs=void 0;agentRunTimer=void 0;welcomeBannerTimer=void 0;lastStatusSpacer=void 0;lastStatusText=void 0;streamingComponent=void 0;streamingMessage=void 0;customStreamComponents=new Map;pendingTools=new Map;subAgentStates=new Map;subAgentPanelComponent=void 0;planProgress=void 0;planProgressPanel=void 0;taskStatusPanel=void 0;toolOutputExpanded=!1;hideThinkingBlock=!1;compactionQueuedMessages=[];optimisticUserMessages=[]}export{d as InteractiveState};