@causyne/agent 1.20.122 → 1.20.127

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 (641) hide show
  1. package/bin/causyne.js +38 -15
  2. package/docs/SECURITY_REVIEW.md +42 -6
  3. package/package.json +7 -7
  4. package/src/acp/agentCatalog.js +74 -50
  5. package/src/acp/agentCatalog.ts +82 -49
  6. package/src/acp/client.js +309 -86
  7. package/src/acp/client.ts +291 -84
  8. package/src/acp/protocol.js +147 -3
  9. package/src/acp/protocol.ts +181 -4
  10. package/src/acp/server.js +418 -45
  11. package/src/acp/server.ts +404 -47
  12. package/src/agent/abortableDelay.js +2 -2
  13. package/src/agent/abortableDelay.ts +2 -2
  14. package/src/agent/errorClassifier.js +51 -7
  15. package/src/agent/errorClassifier.ts +52 -6
  16. package/src/agent/providerFailure.js +1 -1
  17. package/src/agent/providerFailure.ts +7 -1
  18. package/src/agent/toolArgValidator.js +38 -4
  19. package/src/agent/toolArgValidator.ts +39 -4
  20. package/src/agent/toolTurnIntegrity.js +28 -7
  21. package/src/agent/toolTurnIntegrity.ts +25 -6
  22. package/src/agent/workspaceBoundary.js +30 -4
  23. package/src/agent/workspaceBoundary.ts +32 -4
  24. package/src/agentLoop.js +673 -236
  25. package/src/agentLoop.ts +705 -233
  26. package/src/approvalPolicy.js +61 -10
  27. package/src/approvalPolicy.ts +69 -11
  28. package/src/auditLog.js +641 -48
  29. package/src/auditLog.ts +661 -0
  30. package/src/autoUpdate.js +32 -5
  31. package/src/autoUpdate.ts +27 -5
  32. package/src/backgroundTasks.js +328 -0
  33. package/src/backgroundTasks.ts +339 -0
  34. package/src/benchmarks/codingEval.js +558 -0
  35. package/src/benchmarks/codingEval.ts +628 -0
  36. package/src/benchmarks/planCache.js +115 -134
  37. package/src/benchmarks/planCache.ts +163 -0
  38. package/src/browser/browserRuntime.js +52 -0
  39. package/src/browser/browserRuntime.ts +55 -0
  40. package/src/browser/causyneBrowser.js +914 -13
  41. package/src/browser/causyneBrowser.ts +1075 -35
  42. package/src/browser/searchProviders.js +94 -6
  43. package/src/browser/searchProviders.ts +89 -6
  44. package/src/browser/urlPolicy.js +22 -2
  45. package/src/browser/urlPolicy.ts +19 -2
  46. package/src/browser/workspacePathSafety.js +6 -4
  47. package/src/browser/workspacePathSafety.ts +7 -4
  48. package/src/capabilities.js +18 -17
  49. package/src/capabilities.ts +38 -0
  50. package/src/checkpoints.js +1241 -1127
  51. package/src/checkpoints.ts +1377 -0
  52. package/src/cliMode.js +718 -754
  53. package/src/cliMode.ts +792 -0
  54. package/src/codebase/repoMap.js +656 -0
  55. package/src/codebase/repoMap.ts +664 -0
  56. package/src/commands.js +3806 -2513
  57. package/src/commands.ts +4162 -0
  58. package/src/compiledSkills.js +8052 -8054
  59. package/src/compiledSkills.ts +8078 -0
  60. package/src/config.js +118 -1
  61. package/src/config.ts +124 -1
  62. package/src/configVault.js +29 -2
  63. package/src/configVault.ts +26 -2
  64. package/src/contextManager.js +473 -557
  65. package/src/contextManager.ts +599 -0
  66. package/src/continuum/adapters/antigravity.js +8 -3
  67. package/src/continuum/adapters/antigravity.ts +8 -3
  68. package/src/continuum/sanitizer.js +23 -1
  69. package/src/continuum/sanitizer.ts +23 -1
  70. package/src/continuum/ui/continuumPicker.js +0 -2
  71. package/src/continuum/ui/continuumPicker.ts +0 -2
  72. package/src/continuum/ui/continuumPickerView.js +0 -2
  73. package/src/continuum/ui/continuumPickerView.ts +4 -20
  74. package/src/core/contextCompactor.js +142 -14
  75. package/src/core/contextCompactor.ts +150 -15
  76. package/src/core/goalLoop.js +257 -0
  77. package/src/core/goalLoop.ts +310 -0
  78. package/src/creative/liveBridge.js +3 -2
  79. package/src/creative/liveBridge.ts +4 -2
  80. package/src/creative/studioScripts.js +1 -1
  81. package/src/creative/studioScripts.ts +1 -1
  82. package/src/decideTools.js +7 -2
  83. package/src/decideTools.ts +7 -2
  84. package/src/decisionPolicy.js +10 -2
  85. package/src/decisionPolicy.ts +10 -2
  86. package/src/designPalettes.js +72 -84
  87. package/src/designPalettes.ts +111 -0
  88. package/src/devMode.js +2 -2
  89. package/src/devMode.ts +6 -0
  90. package/src/diffReview.js +370 -0
  91. package/src/diffReview.ts +407 -0
  92. package/src/dynamicCatalogue.js +311 -11
  93. package/src/dynamicCatalogue.ts +331 -11
  94. package/src/embodimentSession.js +143 -154
  95. package/src/embodimentSession.ts +173 -0
  96. package/src/engines/installer.js +60 -29
  97. package/src/engines/installer.ts +73 -22
  98. package/src/enterprisePolicy.js +660 -0
  99. package/src/enterprisePolicy.ts +728 -0
  100. package/src/entrypoint.js +646 -268
  101. package/src/entrypoint.ts +740 -0
  102. package/src/game/causyneCoreBridge.js +686 -0
  103. package/src/game/causyneCoreBridge.ts +702 -0
  104. package/src/game/gameLauncher.js +287 -0
  105. package/src/game/gameLauncher.ts +352 -0
  106. package/src/game/gameProvisioner.js +425 -0
  107. package/src/game/gameProvisioner.ts +488 -0
  108. package/src/gitSnapshot.js +417 -312
  109. package/src/gitSnapshot.ts +500 -0
  110. package/src/headlessCli.js +343 -25
  111. package/src/headlessCli.ts +343 -20
  112. package/src/hooks.js +247 -26
  113. package/src/hooks.ts +236 -26
  114. package/src/ignoreRules.js +297 -0
  115. package/src/ignoreRules.ts +308 -0
  116. package/src/implementationPlan.js +7 -6
  117. package/src/implementationPlan.ts +8 -6
  118. package/src/infra/atomicWriter.js +127 -18
  119. package/src/infra/atomicWriter.ts +141 -20
  120. package/src/launchIntent.js +85 -4
  121. package/src/launchIntent.ts +88 -4
  122. package/src/licensing/entitlements.js +553 -237
  123. package/src/licensing/entitlements.ts +590 -0
  124. package/src/licensing/policy.js +17 -1
  125. package/src/licensing/policy.ts +31 -0
  126. package/src/lsp/lspCatalog.js +398 -0
  127. package/src/lsp/lspCatalog.ts +452 -0
  128. package/src/lsp/lspClient.js +770 -0
  129. package/src/lsp/lspClient.ts +862 -0
  130. package/src/lsp/lspProtocol.js +121 -0
  131. package/src/lsp/lspProtocol.ts +140 -0
  132. package/src/mcp/mcpClient.js +69 -8
  133. package/src/mcp/mcpClient.ts +66 -9
  134. package/src/mcp/mcpRegistry.js +255 -15
  135. package/src/mcp/mcpRegistry.ts +241 -14
  136. package/src/mcp/mcpSecurity.js +6 -7
  137. package/src/mcp/mcpSecurity.ts +7 -6
  138. package/src/memory/contextBudget.js +2 -0
  139. package/src/memory/contextBudget.ts +1 -0
  140. package/src/memory/episodicStore.js +2 -5
  141. package/src/memory/episodicStore.ts +2 -5
  142. package/src/memory.js +80 -32
  143. package/src/memory.ts +111 -0
  144. package/src/memoryManager.js +151 -143
  145. package/src/memoryManager.ts +182 -0
  146. package/src/modelCatalogue.js +172 -195
  147. package/src/modelCatalogue.ts +201 -0
  148. package/src/modelIds.js +8 -27
  149. package/src/modelIds.ts +33 -0
  150. package/src/modelVariants.js +645 -0
  151. package/src/modelVariants.ts +717 -0
  152. package/src/observer/evidence.js +5 -1
  153. package/src/observer/evidence.ts +5 -1
  154. package/src/osKeychain.js +17 -9
  155. package/src/osKeychain.ts +14 -9
  156. package/src/outputRecovery.js +3 -2
  157. package/src/outputRecovery.ts +4 -2
  158. package/src/outputStore.js +210 -156
  159. package/src/outputStore.ts +321 -0
  160. package/src/permissionPresets.js +327 -0
  161. package/src/permissionPresets.ts +361 -0
  162. package/src/planCache.js +3 -6
  163. package/src/planCache.ts +3 -6
  164. package/src/plugins/pluginManager.js +689 -461
  165. package/src/plugins/pluginManager.ts +807 -0
  166. package/src/plugins/pluginRunner.js +82 -37
  167. package/src/plugins/pluginRunner.ts +98 -0
  168. package/src/plugins/pluginSkills.js +47 -9
  169. package/src/plugins/pluginSkills.ts +46 -8
  170. package/src/pluginsFactory/discovery.js +0 -1
  171. package/src/pluginsFactory/discovery.ts +0 -1
  172. package/src/pluginsFactory/templates.js +17 -4
  173. package/src/pluginsFactory/templates.ts +17 -4
  174. package/src/prWorkflow.js +337 -0
  175. package/src/prWorkflow.ts +376 -0
  176. package/src/procSignal.js +1 -2
  177. package/src/procSignal.ts +1 -3
  178. package/src/projectInstructions.js +319 -0
  179. package/src/projectInstructions.ts +361 -0
  180. package/src/providers/acp.js +234 -49
  181. package/src/providers/acp.ts +240 -50
  182. package/src/providers/anthropic.js +152 -47
  183. package/src/providers/anthropic.ts +152 -45
  184. package/src/providers/antigravity.js +620 -356
  185. package/src/providers/antigravity.ts +621 -357
  186. package/src/providers/base.js +9 -2
  187. package/src/providers/base.ts +10 -2
  188. package/src/providers/byokHttp.js +134 -18
  189. package/src/providers/byokHttp.ts +181 -19
  190. package/src/providers/byokStream.js +183 -44
  191. package/src/providers/byokStream.ts +179 -62
  192. package/src/providers/dashscope-byok.js +50 -8
  193. package/src/providers/dashscope-byok.ts +59 -13
  194. package/src/providers/deepseek.js +12 -3
  195. package/src/providers/deepseek.ts +12 -3
  196. package/src/providers/factory.js +41 -0
  197. package/src/providers/factory.ts +42 -0
  198. package/src/providers/gemini.js +74 -22
  199. package/src/providers/gemini.ts +78 -26
  200. package/src/providers/moonshot.js +60 -8
  201. package/src/providers/moonshot.ts +64 -14
  202. package/src/providers/muse.js +6 -0
  203. package/src/providers/muse.ts +8 -0
  204. package/src/providers/ollama.js +299 -21
  205. package/src/providers/ollama.ts +331 -29
  206. package/src/providers/openai-compatible.js +81 -12
  207. package/src/providers/openai-compatible.ts +89 -18
  208. package/src/providers/openai.js +87 -6
  209. package/src/providers/openai.ts +74 -6
  210. package/src/providers/openrouter.js +248 -66
  211. package/src/providers/openrouter.ts +243 -70
  212. package/src/providers/qwen-byok.js +50 -8
  213. package/src/providers/qwen-byok.ts +59 -13
  214. package/src/providers/wireNormalizer.js +66 -0
  215. package/src/providers/wireNormalizer.ts +64 -0
  216. package/src/providers/xai.js +31 -8
  217. package/src/providers/xai.ts +38 -14
  218. package/src/provisioning/capabilityConsent.js +29 -11
  219. package/src/provisioning/capabilityConsent.ts +42 -0
  220. package/src/provisioning/capabilityProvisioner.js +309 -197
  221. package/src/provisioning/capabilityProvisioner.ts +413 -0
  222. package/src/provisioning/capabilityTools.js +31 -17
  223. package/src/provisioning/capabilityTools.ts +43 -0
  224. package/src/provisioning/npmInstall.js +33 -5
  225. package/src/provisioning/npmInstall.ts +33 -5
  226. package/src/reporting.js +330 -326
  227. package/src/reporting.ts +484 -0
  228. package/src/sandbox.js +71 -0
  229. package/src/sandbox.ts +81 -0
  230. package/src/scheduler/scheduler.js +372 -0
  231. package/src/scheduler/scheduler.ts +433 -0
  232. package/src/sessionJournal.js +24 -3
  233. package/src/sessionJournal.ts +18 -3
  234. package/src/sessionSearchIndex.js +267 -0
  235. package/src/sessionSearchIndex.ts +311 -0
  236. package/src/sessionStore.js +1 -2
  237. package/src/sessionStore.ts +2 -0
  238. package/src/skillsManager.js +2 -3
  239. package/src/skillsManager.ts +2 -3
  240. package/src/slopDetector.js +202 -265
  241. package/src/slopDetector.ts +279 -0
  242. package/src/smartToolsUse.js +10 -4
  243. package/src/smartToolsUse.ts +10 -4
  244. package/src/stallGuard.js +10 -3
  245. package/src/stallGuard.ts +9 -3
  246. package/src/taskBuffer.js +91 -40
  247. package/src/taskBuffer.ts +94 -0
  248. package/src/tokenTracker.js +78 -11
  249. package/src/tokenTracker.ts +69 -11
  250. package/src/toolPacks.js +11 -0
  251. package/src/toolPacks.ts +11 -0
  252. package/src/tools/applyPatch.js +610 -0
  253. package/src/tools/applyPatch.ts +661 -0
  254. package/src/tools/archive.js +135 -21
  255. package/src/tools/archive.ts +136 -21
  256. package/src/tools/astryxOracle.js +77 -72
  257. package/src/tools/astryxOracle.ts +95 -0
  258. package/src/tools/axSnapshot.js +127 -147
  259. package/src/tools/axSnapshot.ts +174 -0
  260. package/src/tools/backgroundTask.js +86 -0
  261. package/src/tools/backgroundTask.ts +121 -0
  262. package/src/tools/blenderAutomator.js +434 -390
  263. package/src/tools/blenderAutomator.ts +623 -0
  264. package/src/tools/checkSystemSpecs.js +54 -61
  265. package/src/tools/checkSystemSpecs.ts +73 -0
  266. package/src/tools/clipboard.js +42 -31
  267. package/src/tools/clipboard.ts +61 -0
  268. package/src/tools/codeSearchAst.js +359 -91
  269. package/src/tools/codeSearchAst.ts +399 -0
  270. package/src/tools/codeSearcher.js +179 -37
  271. package/src/tools/codeSearcher.ts +188 -33
  272. package/src/tools/codeTools.js +208 -245
  273. package/src/tools/codeTools.ts +271 -0
  274. package/src/tools/codebaseSearch.js +5 -0
  275. package/src/tools/codebaseSearch.ts +5 -0
  276. package/src/tools/desktopAct.js +185 -197
  277. package/src/tools/desktopAct.ts +257 -0
  278. package/src/tools/dynamicLoader.js +4 -40
  279. package/src/tools/dynamicLoader.ts +13 -0
  280. package/src/tools/executeProceduralMedia.js +117 -86
  281. package/src/tools/executeProceduralMedia.ts +135 -0
  282. package/src/tools/fileTracker.js +74 -0
  283. package/src/tools/fileTracker.ts +94 -0
  284. package/src/tools/fsDelete.js +57 -47
  285. package/src/tools/fsDelete.ts +80 -0
  286. package/src/tools/fsEdit.js +192 -74
  287. package/src/tools/fsEdit.ts +201 -72
  288. package/src/tools/fsMove.js +79 -52
  289. package/src/tools/fsMove.ts +108 -0
  290. package/src/tools/fsRead.js +54 -15
  291. package/src/tools/fsRead.ts +55 -15
  292. package/src/tools/fsSearch.js +5 -0
  293. package/src/tools/fsSearch.ts +5 -0
  294. package/src/tools/fsWrite.js +14 -6
  295. package/src/tools/fsWrite.ts +14 -6
  296. package/src/tools/gameAiBehaviorTree.js +74 -91
  297. package/src/tools/gameAiBehaviorTree.ts +219 -0
  298. package/src/tools/gameAnimationRig.js +128 -147
  299. package/src/tools/gameAnimationRig.ts +215 -0
  300. package/src/tools/gameAssetFetcher.js +403 -441
  301. package/src/tools/gameAssetFetcher.ts +477 -0
  302. package/src/tools/gameAssetHarvester.js +171 -200
  303. package/src/tools/gameAssetHarvester.ts +261 -0
  304. package/src/tools/gameAudioSynth.js +223 -259
  305. package/src/tools/gameAudioSynth.ts +255 -0
  306. package/src/tools/gameBuilder.js +100 -91
  307. package/src/tools/gameBuilder.ts +913 -0
  308. package/src/tools/gameCanvasAudit.js +138 -96
  309. package/src/tools/gameCanvasAudit.ts +157 -0
  310. package/src/tools/gameCinematicSequencer.js +93 -111
  311. package/src/tools/gameCinematicSequencer.ts +165 -0
  312. package/src/tools/gameDataForge.js +115 -118
  313. package/src/tools/gameDataForge.ts +151 -0
  314. package/src/tools/gameDialogueTreeGen.js +125 -156
  315. package/src/tools/gameDialogueTreeGen.ts +159 -0
  316. package/src/tools/gameEconomyBalancer.js +150 -153
  317. package/src/tools/gameEconomyBalancer.ts +186 -0
  318. package/src/tools/gameEntitySpawner.js +91 -108
  319. package/src/tools/gameEntitySpawner.ts +209 -0
  320. package/src/tools/gameLoreForge.js +125 -147
  321. package/src/tools/gameLoreForge.ts +162 -0
  322. package/src/tools/gameQuestArcBuilder.js +105 -144
  323. package/src/tools/gameQuestArcBuilder.ts +147 -0
  324. package/src/tools/gameSceneBuilder.js +143 -149
  325. package/src/tools/gameSceneBuilder.ts +196 -0
  326. package/src/tools/gameShaderForge.js +83 -101
  327. package/src/tools/gameShaderForge.ts +181 -0
  328. package/src/tools/gameTilemapGenerator.js +99 -129
  329. package/src/tools/gameTilemapGenerator.ts +158 -0
  330. package/src/tools/gameUiHudBuilder.js +109 -129
  331. package/src/tools/gameUiHudBuilder.ts +300 -0
  332. package/src/tools/gameVfxEmitterGen.js +86 -89
  333. package/src/tools/gameVfxEmitterGen.ts +133 -0
  334. package/src/tools/gameWebRuntimeInspector.js +153 -86
  335. package/src/tools/gameWebRuntimeInspector.ts +167 -0
  336. package/src/tools/generateMediaViaApi.js +57 -15
  337. package/src/tools/generateMediaViaApi.ts +56 -15
  338. package/src/tools/gitExec.js +133 -86
  339. package/src/tools/gitExec.ts +146 -0
  340. package/src/tools/gitWorktree.js +115 -0
  341. package/src/tools/gitWorktree.ts +150 -0
  342. package/src/tools/godotAutomator.js +417 -394
  343. package/src/tools/godotAutomator.ts +530 -0
  344. package/src/tools/lspCodeIntel.js +217 -0
  345. package/src/tools/lspCodeIntel.ts +260 -0
  346. package/src/tools/manageLocalAiDependencies.js +242 -206
  347. package/src/tools/manageLocalAiDependencies.ts +288 -0
  348. package/src/tools/multiEdit.js +16 -76
  349. package/src/tools/multiEdit.ts +20 -77
  350. package/src/tools/nativeEngine.js +2 -2
  351. package/src/tools/nativeEngine.ts +2 -2
  352. package/src/tools/openSourceToolProvisioner.js +2 -2
  353. package/src/tools/openSourceToolProvisioner.ts +2 -2
  354. package/src/tools/osSandbox.js +152 -15
  355. package/src/tools/osSandbox.ts +148 -15
  356. package/src/tools/palmierAutomator.js +147 -95
  357. package/src/tools/palmierAutomator.ts +171 -0
  358. package/src/tools/payloadSanitizer.js +0 -1
  359. package/src/tools/payloadSanitizer.ts +0 -1
  360. package/src/tools/pdfReader.js +197 -104
  361. package/src/tools/pdfReader.ts +216 -0
  362. package/src/tools/persistentShell.js +267 -144
  363. package/src/tools/persistentShell.ts +314 -0
  364. package/src/tools/pluginManager.js +84 -72
  365. package/src/tools/pluginManager.ts +109 -0
  366. package/src/tools/presentDeliverable.js +103 -0
  367. package/src/tools/presentDeliverable.ts +127 -0
  368. package/src/tools/printer.js +278 -296
  369. package/src/tools/printer.ts +326 -0
  370. package/src/tools/procTerm.js +96 -83
  371. package/src/tools/procTerm.ts +127 -0
  372. package/src/tools/processList.js +45 -48
  373. package/src/tools/processList.ts +73 -0
  374. package/src/tools/ptcRuntime.js +444 -0
  375. package/src/tools/ptcRuntime.ts +490 -0
  376. package/src/tools/ptyTerminal.js +1096 -0
  377. package/src/tools/ptyTerminal.ts +1231 -0
  378. package/src/tools/registry.js +308 -287
  379. package/src/tools/registry.ts +495 -0
  380. package/src/tools/repoMap.js +46 -0
  381. package/src/tools/repoMap.ts +66 -0
  382. package/src/tools/subagentOrchestrator.js +404 -348
  383. package/src/tools/subagentOrchestrator.ts +457 -0
  384. package/src/tools/sysRun.js +83 -26
  385. package/src/tools/sysRun.ts +80 -26
  386. package/src/tools/toolForge.js +84 -67
  387. package/src/tools/toolForge.ts +102 -0
  388. package/src/tools/toolOutputStore.js +26 -4
  389. package/src/tools/toolOutputStore.ts +22 -4
  390. package/src/tools/toolPathSafety.js +262 -0
  391. package/src/tools/toolPathSafety.ts +308 -0
  392. package/src/tools/toolScanner.js +28 -0
  393. package/src/tools/toolScanner.ts +29 -0
  394. package/src/tools/toolSelfRepair.js +21 -6
  395. package/src/tools/toolSelfRepair.ts +26 -6
  396. package/src/tools/walkerSafety.ts +1 -0
  397. package/src/tools/webFetch.js +163 -13
  398. package/src/tools/webFetch.ts +150 -13
  399. package/src/tools/webSearch.js +123 -36
  400. package/src/tools/webSearch.ts +124 -33
  401. package/src/toolsList.js +5 -0
  402. package/src/toolsList.ts +5 -0
  403. package/src/tui/ask.js +159 -168
  404. package/src/tui/ask.ts +259 -0
  405. package/src/tui/banner.js +5 -1
  406. package/src/tui/banner.ts +6 -1
  407. package/src/tui/block.js +0 -1
  408. package/src/tui/block.ts +0 -1
  409. package/src/tui/chatRenderer.js +1194 -1443
  410. package/src/tui/chatRenderer.ts +1335 -0
  411. package/src/tui/clipboardImage.js +36 -12
  412. package/src/tui/clipboardImage.ts +39 -13
  413. package/src/tui/clipboardSync.js +34 -9
  414. package/src/tui/clipboardSync.ts +38 -9
  415. package/src/tui/codeProgress.js +0 -1
  416. package/src/tui/codeProgress.ts +0 -1
  417. package/src/tui/completion.js +396 -371
  418. package/src/tui/completion.ts +575 -0
  419. package/src/tui/composerControls.js +212 -34
  420. package/src/tui/composerControls.ts +235 -34
  421. package/src/tui/consoleGuard.js +27 -7
  422. package/src/tui/consoleGuard.ts +29 -7
  423. package/src/tui/dialogs.js +867 -733
  424. package/src/tui/dialogs.ts +971 -0
  425. package/src/tui/diff.js +205 -195
  426. package/src/tui/diff.ts +336 -0
  427. package/src/tui/history.js +143 -108
  428. package/src/tui/history.ts +167 -0
  429. package/src/tui/home.js +166 -161
  430. package/src/tui/home.ts +252 -0
  431. package/src/tui/invocation.js +59 -67
  432. package/src/tui/invocation.ts +116 -0
  433. package/src/tui/keys.js +437 -420
  434. package/src/tui/keys.ts +597 -0
  435. package/src/tui/lineEditor.js +477 -432
  436. package/src/tui/lineEditor.ts +542 -0
  437. package/src/tui/messageActionPlacement.js +0 -1
  438. package/src/tui/messageActionPlacement.ts +0 -1
  439. package/src/tui/messageInteraction.js +0 -2
  440. package/src/tui/messageInteraction.ts +0 -2
  441. package/src/tui/modelPicker.js +22 -15
  442. package/src/tui/modelPicker.ts +25 -18
  443. package/src/tui/observerPicker.js +0 -2
  444. package/src/tui/observerPicker.ts +0 -2
  445. package/src/tui/overlay.js +2 -6
  446. package/src/tui/overlay.ts +2 -6
  447. package/src/tui/prompt.js +1818 -2151
  448. package/src/tui/prompt.ts +1872 -0
  449. package/src/tui/runningLight.js +0 -1
  450. package/src/tui/runningLight.ts +0 -1
  451. package/src/tui/selectList.js +369 -349
  452. package/src/tui/selectList.ts +433 -0
  453. package/src/tui/sessionPicker.js +0 -1
  454. package/src/tui/sessionPicker.ts +0 -1
  455. package/src/tui/sessionPickerView.js +0 -2
  456. package/src/tui/sessionPickerView.ts +4 -21
  457. package/src/tui/sessionSidebar.js +3 -1
  458. package/src/tui/sessionSidebar.ts +4 -1
  459. package/src/tui/setup.js +39 -14
  460. package/src/tui/setup.ts +45 -14
  461. package/src/tui/skillAuthoring.js +0 -2
  462. package/src/tui/skillAuthoring.ts +0 -3
  463. package/src/tui/stageSurface.js +829 -909
  464. package/src/tui/stageSurface.ts +1003 -0
  465. package/src/tui/statusLine.js +7 -4
  466. package/src/tui/statusLine.ts +9 -3
  467. package/src/tui/terminalInputFramer.js +82 -69
  468. package/src/tui/terminalInputFramer.ts +116 -0
  469. package/src/tui/text.js +25 -10
  470. package/src/tui/text.ts +24 -10
  471. package/src/tui/textLayout.js +0 -1
  472. package/src/tui/textLayout.ts +0 -1
  473. package/src/tui/theme.js +245 -250
  474. package/src/tui/theme.ts +441 -0
  475. package/src/tui/thinkingBox.js +0 -1
  476. package/src/tui/thinkingBox.ts +0 -1
  477. package/src/tui/transcript.js +239 -216
  478. package/src/tui/transcript.ts +324 -0
  479. package/src/tui/turnRail.js +53 -54
  480. package/src/tui/turnRail.ts +51 -49
  481. package/src/tui/usageCard.js +0 -2
  482. package/src/tui/usageCard.ts +0 -2
  483. package/src/tui/workspaceSwitch.js +4 -2
  484. package/src/tui/workspaceSwitch.ts +5 -2
  485. package/src/types/contracts.ts +4 -1
  486. package/src/utils/browserOpen.js +107 -0
  487. package/src/utils/browserOpen.ts +129 -0
  488. package/src/utils/cli_ui.js +0 -0
  489. package/src/utils/cli_ui.ts +158 -0
  490. package/src/utils/winSpawn.js +248 -0
  491. package/src/utils/winSpawn.ts +275 -0
  492. package/src/verification/boundedExplorer.js +138 -107
  493. package/src/verification/boundedExplorer.ts +154 -0
  494. package/src/verification/byokSmokeProbe.js +193 -0
  495. package/src/verification/byokSmokeProbe.ts +234 -0
  496. package/src/verification/cliProbe.js +144 -110
  497. package/src/verification/cliProbe.ts +170 -0
  498. package/src/verification/featureMap.js +105 -75
  499. package/src/verification/featureMap.ts +124 -0
  500. package/src/verification/interactivePty.js +195 -100
  501. package/src/verification/interactivePty.ts +333 -0
  502. package/src/verification/propertyProbe.js +109 -101
  503. package/src/verification/propertyProbe.ts +159 -0
  504. package/src/verification/ptyProbe.js +168 -73
  505. package/src/verification/ptyProbe.ts +254 -0
  506. package/src/verification/skillCatalog.js +25 -25
  507. package/src/verification/skillCatalog.ts +66 -0
  508. package/src/verification/statechart.js +140 -127
  509. package/src/verification/statechart.ts +196 -0
  510. package/src/verification/uiRuntime.js +80 -49
  511. package/src/verification/uiRuntime.ts +88 -0
  512. package/src/version.js +37 -32
  513. package/src/version.ts +45 -0
  514. package/src/web/client/browserPanel.js +702 -0
  515. package/src/web/client/browserPanel.ts +663 -0
  516. package/src/web/client/chatStream.js +309 -0
  517. package/src/web/client/chatStream.ts +289 -0
  518. package/src/web/client/cliPanel.js +165 -0
  519. package/src/web/client/cliPanel.ts +171 -0
  520. package/src/web/client/composer.js +204 -0
  521. package/src/web/client/composer.ts +209 -0
  522. package/src/web/client/diffPanel.js +176 -0
  523. package/src/web/client/diffPanel.ts +203 -0
  524. package/src/web/client/dom.js +220 -0
  525. package/src/web/client/dom.ts +221 -0
  526. package/src/web/client/filesAndCanvas.js +231 -0
  527. package/src/web/client/filesAndCanvas.ts +238 -0
  528. package/src/web/client/gameLauncherUi.js +78 -0
  529. package/src/web/client/gameLauncherUi.ts +78 -0
  530. package/src/web/client/main.js +301 -0
  531. package/src/web/client/main.ts +368 -0
  532. package/src/web/client/markdown.js +364 -0
  533. package/src/web/client/markdown.ts +373 -0
  534. package/src/web/client/modelPicker.js +455 -0
  535. package/src/web/client/modelPicker.ts +451 -0
  536. package/src/web/client/permissionPresetsUi.js +307 -0
  537. package/src/web/client/permissionPresetsUi.ts +333 -0
  538. package/src/web/client/sessions.js +353 -0
  539. package/src/web/client/sessions.ts +372 -0
  540. package/src/web/client/settingsModal.js +191 -0
  541. package/src/web/client/settingsModal.ts +176 -0
  542. package/src/web/client/state.js +250 -0
  543. package/src/web/client/state.ts +233 -0
  544. package/src/web/client/streamSmoother.js +127 -0
  545. package/src/web/client/streamSmoother.ts +119 -0
  546. package/src/web/client/studioLayout.js +54 -0
  547. package/src/web/client/studioLayout.ts +60 -0
  548. package/src/web/client/studioShell.js +327 -0
  549. package/src/web/client/studioShell.ts +340 -0
  550. package/src/web/client/studioStart.js +77 -0
  551. package/src/web/client/studioStart.ts +89 -0
  552. package/src/web/client/terminalPanel.js +357 -0
  553. package/src/web/client/terminalPanel.ts +345 -0
  554. package/src/web/client/turnView.js +934 -0
  555. package/src/web/client/turnView.ts +981 -0
  556. package/src/web/client/types.js +1 -0
  557. package/src/web/client/types.ts +319 -0
  558. package/src/web/client/validators.js +106 -0
  559. package/src/web/client/validators.ts +96 -0
  560. package/src/web/guiLauncher.js +89 -0
  561. package/src/web/guiLauncher.ts +119 -0
  562. package/src/web/server/activeRuns.js +152 -0
  563. package/src/web/server/activeRuns.ts +171 -0
  564. package/src/web/server/routesBrowser.js +355 -0
  565. package/src/web/server/routesBrowser.ts +386 -0
  566. package/src/web/server/routesChat.js +304 -0
  567. package/src/web/server/routesChat.ts +347 -0
  568. package/src/web/server/routesCore.js +472 -0
  569. package/src/web/server/routesCore.ts +522 -0
  570. package/src/web/server/routesTerminal.js +162 -0
  571. package/src/web/server/routesTerminal.ts +182 -0
  572. package/src/web/server/routesWorkspace.js +510 -0
  573. package/src/web/server/routesWorkspace.ts +546 -0
  574. package/src/web/server/security.js +98 -0
  575. package/src/web/server/security.ts +108 -0
  576. package/src/web/server/sessionTranscript.js +586 -0
  577. package/src/web/server/sessionTranscript.ts +566 -0
  578. package/src/web/server/staticAssets.js +80 -0
  579. package/src/web/server/staticAssets.ts +91 -0
  580. package/src/web/server/types.js +1 -0
  581. package/src/web/server/types.ts +135 -0
  582. package/src/web/server/workspaceFiles.js +368 -0
  583. package/src/web/server/workspaceFiles.ts +363 -0
  584. package/src/web/skybridgeBrowserBridge.js +256 -0
  585. package/src/web/skybridgeBrowserBridge.ts +285 -0
  586. package/src/web/skybridgeBrowserMcp.js +730 -0
  587. package/src/web/skybridgeBrowserMcp.ts +813 -0
  588. package/src/web/skybridgeServer.js +249 -0
  589. package/src/web/skybridgeServer.ts +305 -0
  590. package/src/web/skybridgeUi.js +38 -0
  591. package/src/web/skybridgeUi.ts +47 -0
  592. package/src/web/styles/agent.css +380 -0
  593. package/src/web/styles/composer.css +193 -0
  594. package/src/web/styles/overlays.css +436 -0
  595. package/src/web/styles/shell.css +387 -0
  596. package/src/web/styles/studio.css +723 -0
  597. package/src/web/styles/thread.css +221 -0
  598. package/src/web/styles/tokens.css +94 -0
  599. package/src/web/ui/brandMark.js +73 -0
  600. package/src/web/ui/brandMark.ts +82 -0
  601. package/src/web/ui/modalsTemplate.js +139 -0
  602. package/src/web/ui/modalsTemplate.ts +139 -0
  603. package/src/web/ui/sidebarTemplate.js +63 -0
  604. package/src/web/ui/sidebarTemplate.ts +64 -0
  605. package/src/web/ui/studioTemplate.js +258 -0
  606. package/src/web/ui/studioTemplate.ts +258 -0
  607. package/src/web/ui/workspaceTemplate.js +72 -0
  608. package/src/web/ui/workspaceTemplate.ts +73 -0
  609. package/src/worktreeManager.js +526 -0
  610. package/src/worktreeManager.ts +567 -0
  611. package/src/zeroCostFailover.js +168 -0
  612. package/src/zeroCostFailover.ts +198 -0
  613. package/src/zeroCostRouting.js +391 -0
  614. package/src/zeroCostRouting.ts +437 -0
  615. package/src/agentLoop.d.ts +0 -65
  616. package/src/auditLog.d.ts +0 -3
  617. package/src/checkpoints.d.ts +0 -4
  618. package/src/compiledSkills.d.ts +0 -5
  619. package/src/contextManager.d.ts +0 -14
  620. package/src/designPalettes.d.ts +0 -2
  621. package/src/devMode.d.ts +0 -1
  622. package/src/embodimentSession.d.ts +0 -2
  623. package/src/licensing/entitlements.d.ts +0 -14
  624. package/src/memory.d.ts +0 -13
  625. package/src/memoryManager.d.ts +0 -1
  626. package/src/modelCatalogue.d.ts +0 -6
  627. package/src/modelIds.d.ts +0 -2
  628. package/src/outputStore.d.ts +0 -4
  629. package/src/plugins/pluginManager.d.ts +0 -7
  630. package/src/providers/antigravity.d.ts +0 -19
  631. package/src/provisioning/capabilityProvisioner.d.ts +0 -12
  632. package/src/slopDetector.d.ts +0 -3
  633. package/src/taskBuffer.d.ts +0 -1
  634. package/src/tools/desktopAct.d.ts +0 -10
  635. package/src/tools/registry.d.ts +0 -5
  636. package/src/tui/chatRenderer.d.ts +0 -27
  637. package/src/tui/diff.d.ts +0 -3
  638. package/src/utils/cli_ui.d.ts +0 -19
  639. package/src/utils/paths.d.ts +0 -3
  640. package/src/verification/skillCatalog.d.ts +0 -1
  641. package/src/version.d.ts +0 -1
@@ -1,21 +1,7 @@
1
- // The concrete dialogs.
2
- //
3
- // Every one of these is the SelectList or a scrolling text pane inside a Layer.
4
- // That is the payoff of building the primitives properly: opencode needs twenty
5
- // `dialog-*.tsx` files because each one re-declares its own layout; here a
6
- // picker is a title, a list of items and a callback.
7
- //
8
- // The one that is not a picker is ApprovalLayer, and it is the reason this file
9
- // exists at all. Causyne's approval used inquirer, which means the question is
10
- // asked in the scrollback, below whatever the agent last printed, with the diff
11
- // already scrolled away above it. As a modal the risk badge, the tool, the
12
- // arguments and the full scrollable diff sit in one frame that the user cannot
13
- // lose — and neither reference does this: openclaw approves in a plain prompt,
14
- // opencode's permission dialog does not scroll its diff by keyboard.
15
- //
1
+ // Concrete TUI modal dialogs built over SelectList and scrolling Layer panes.
2
+ // ApprovalLayer keeps the risk badge, tool, arguments, and scrollable diff in
3
+ // one focused modal frame instead of losing them in terminal scrollback.
16
4
  // Pure Node over ./selectList.js, ./overlay.js, ./theme.js, ./text.js.
17
- // No dependency, no shell.
18
-
19
5
  import { Layer, dialogHint } from './overlay.js';
20
6
  import { SelectList } from './selectList.js';
21
7
  import { LineEditor } from './lineEditor.js';
@@ -24,11 +10,17 @@ import { truncate, wrap, visibleWidth, safeDisplay, shortenHome } from './text.j
24
10
  import { approvalDiff } from './diff.js';
25
11
  import { isChar, isMouseMotion } from './keys.js';
26
12
  import { readClipboardSync } from './clipboardSync.js';
27
-
28
- const cleanDialogText = (value) => (
29
- value == null ? '' : safeDisplay(String(value)).replace(/\s+/g, ' ').trim()
30
- );
31
-
13
+ const MAX_DIALOG_PASTE_CHARS = 65536;
14
+ const cleanDialogText = (value) => (value == null ? '' : safeDisplay(String(value)).replace(/\s+/g, ' ').trim());
15
+ function safeJsonPreview(value) {
16
+ try {
17
+ const serialized = JSON.stringify(value);
18
+ return serialized === undefined ? String(value) : serialized;
19
+ }
20
+ catch {
21
+ return String(value);
22
+ }
23
+ }
32
24
  /**
33
25
  * A picker. `items` are SelectList items; `onPick(item)` fires on enter.
34
26
  *
@@ -36,169 +28,207 @@ const cleanDialogText = (value) => (
36
28
  * picker wants, so the user can see each theme applied before committing.
37
29
  */
38
30
  export class SelectLayer extends Layer {
39
- constructor(options = {}) {
40
- const opts = options && typeof options === 'object' ? options : {};
41
- super({ width: opts.width || 68, height: opts.height || 18, ...opts });
42
- this.list = new SelectList(opts.items || [], {
43
- placeholder: opts.placeholder,
44
- emptyText: opts.emptyText,
45
- showFilter: opts.showFilter
46
- });
47
- this.onPick = opts.onPick || null;
48
- this.settled = false;
49
- this.footer = opts.footer || dialogHint();
50
- }
51
-
52
- /** Dismissal must resolve pending picker flows, just like text inputs. */
53
- answer() {
54
- if (this.settled) return;
55
- this.settled = true;
56
- if (this.onPick) this.onPick(null);
57
- }
58
-
59
- preferredHeight() {
60
- // filter row + rule + one row per item (+ its category header) + frame.
61
- const categories = new Set(this.list.filtered.map((entry) => entry.item.category).filter(Boolean));
62
- return 2 + this.list.filtered.length + categories.size + 2;
63
- }
64
-
65
- body(width, height) {
66
- const { rows } = this.list.render(width, height);
67
- this.cursor = { x: this.list.cursorColumn(), y: 0 };
68
- return rows;
69
- }
70
-
71
- key(event) {
72
- // Scroll by the budget the RENDERER used, not by one derived from the
73
- // layer's configured height. The panel gives the body
74
- // `min(preferredHeight, maxHeight) - 2` rows and the list then spends two
75
- // more on the filter and its rule and one on the position counter — so this
76
- // used to move the selection by 17 rows through a list that was drawing 15.
77
- // The list publishes what it actually budgeted on its last render; before
78
- // the first render there is nothing to disagree with, so the estimate stands.
79
- const visibleRows = this.list.lastItemRows || Math.max(1, this.height - 5);
80
- const action = this.list.handleKey(event, visibleRows);
81
-
82
- if (action === 'select') {
83
- const item = this.list.current;
84
- this.settled = true;
85
- const result = this.onPick ? this.onPick(item) : null;
86
- if (result === 'keep' || result === 'handled') {
31
+ list;
32
+ onPick;
33
+ settled;
34
+ constructor(options = {}) {
35
+ const opts = options && typeof options === 'object' ? options : {};
36
+ super({ width: opts.width || 68, height: opts.height || 18, ...opts });
37
+ this.list = new SelectList((opts.items || []), {
38
+ placeholder: opts.placeholder,
39
+ emptyText: opts.emptyText,
40
+ showFilter: opts.showFilter
41
+ });
42
+ this.onPick = opts.onPick || null;
87
43
  this.settled = false;
88
- return 'handled';
89
- }
90
- return 'close';
44
+ this.footer = opts.footer || dialogHint();
45
+ }
46
+ /** Dismissal must resolve pending picker flows, just like text inputs. */
47
+ answer() {
48
+ if (this.settled)
49
+ return;
50
+ this.settled = true;
51
+ if (this.onPick)
52
+ this.onPick(null);
53
+ }
54
+ preferredHeight() {
55
+ // filter row + rule + one row per item (+ its category header) + frame.
56
+ const categories = new Set(this.list.filtered.map((entry) => entry.item.category).filter(Boolean));
57
+ return 2 + this.list.filtered.length + categories.size + 2;
58
+ }
59
+ body(width = 64, height = 16) {
60
+ const { rows } = this.list.render(width, height);
61
+ this.cursor = { x: this.list.cursorColumn(), y: 0 };
62
+ return rows;
63
+ }
64
+ key(event) {
65
+ // Scroll by the budget the RENDERER used, not by one derived from the
66
+ // layer's configured height. The panel gives the body
67
+ // `min(preferredHeight, maxHeight) - 2` rows and the list then spends two
68
+ // more on the filter and its rule and one on the position counter — so this
69
+ // used to move the selection by 17 rows through a list that was drawing 15.
70
+ // The list publishes what it actually budgeted on its last render; before
71
+ // the first render there is nothing to disagree with, so the estimate stands.
72
+ const visibleRows = this.list.lastItemRows || Math.max(1, this.height - 5);
73
+ const action = this.list.handleKey(event, visibleRows);
74
+ if (action === 'select') {
75
+ const item = this.list.current;
76
+ this.settled = true;
77
+ const result = this.onPick ? this.onPick(item) : null;
78
+ if (result === 'keep' || result === 'handled') {
79
+ this.settled = false;
80
+ return 'handled';
81
+ }
82
+ return 'close';
83
+ }
84
+ if (action === 'cancel')
85
+ return 'close';
86
+ return action ? 'handled' : null;
91
87
  }
92
- if (action === 'cancel') return 'close';
93
- return action ? 'handled' : null;
94
- }
95
88
  }
96
-
97
-
98
89
  export class InputLayer extends Layer {
99
- constructor(options = {}) {
100
- const opts = options && typeof options === 'object' ? options : {};
101
- super({ width: opts.width || 68, height: opts.height || 10, ...opts });
102
- this.editor = new LineEditor(String(opts.value == null ? '' : opts.value));
103
- this.lines = Array.isArray(opts.lines) ? opts.lines : [];
104
- this.mask = opts.mask === true;
105
- this.placeholder = opts.placeholder || '';
106
- this.onSubmit = opts.onSubmit || null;
107
- this.onCancel = opts.onCancel || null;
108
- this.footer = opts.footer || `enter accept ${GLYPHS.dot} esc cancel`;
109
- this.settled = false;
110
- }
111
-
112
- // Blurb rows + a blank + the input row, inside the frame.
113
- preferredHeight() { return this.lines.length + (this.lines.length ? 1 : 0) + 1 + 2; }
114
-
115
- /** Dismissal is a cancel, so the caller's promise can never hang. */
116
- answer() {
117
- if (this.settled) return;
118
- this.settled = true;
119
- if (this.onCancel) this.onCancel();
120
- }
121
-
122
- body(width) {
123
- const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
124
- const rows = this.lines.map((line) => truncate(cleanDialogText(line), safeWidth, GLYPHS.ellipsis));
125
- if (rows.length) rows.push('');
126
-
127
- const raw = this.editor.getText();
128
- const shown = this.mask ? GLYPHS.bullet.repeat(Array.from(raw).length) : cleanDialogText(raw);
129
- const cleanPlaceholder = cleanDialogText(this.placeholder);
130
- const text = shown.length === 0 && cleanPlaceholder ? dim(cleanPlaceholder) : shown;
131
-
132
- const prefix = paint('accent', `${GLYPHS.arrow} `);
133
- rows.push(truncate(prefix + text, safeWidth, GLYPHS.ellipsis));
134
-
135
- // Park the caret after what is displayed — which for a masked field is the
136
- // dot count, not the character count, or the caret drifts off the value —
137
- // and never past the rightmost body column.
138
- const before = this.mask
139
- ? Array.from(raw.slice(0, this.editor.col)).length
140
- : visibleWidth(cleanDialogText(raw.slice(0, this.editor.col)));
141
- const maxCol = Math.max(0, safeWidth - 1);
142
- this.cursor = { x: Math.min(maxCol, 2 + before), y: rows.length - 1 };
143
- return rows;
144
- }
145
-
146
- key(event) {
147
- if (!event) return null;
148
-
149
- switch (event.name) {
150
- case 'escape':
151
- return 'close';
152
- case 'enter':
153
- case 'return': {
154
- if (this.settled) return 'close';
90
+ editor;
91
+ lines;
92
+ mask;
93
+ placeholder;
94
+ onSubmit;
95
+ onCancel;
96
+ settled;
97
+ constructor(options = {}) {
98
+ const opts = options && typeof options === 'object' ? options : {};
99
+ super({ width: opts.width || 68, height: opts.height || 10, ...opts });
100
+ this.mask = opts.mask === true;
101
+ this.editor = new LineEditor(String(opts.value == null ? '' : opts.value), { disableClipboard: this.mask });
102
+ this.lines = Array.isArray(opts.lines) ? [...opts.lines] : [];
103
+ this.placeholder = opts.placeholder || '';
104
+ this.onSubmit = opts.onSubmit || null;
105
+ this.onCancel = opts.onCancel || null;
106
+ this.footer = opts.footer || `enter accept ${GLYPHS.dot} esc cancel`;
107
+ this.settled = false;
108
+ }
109
+ // Blurb rows + a blank + the input row, inside the frame.
110
+ preferredHeight() { return this.lines.length + (this.lines.length ? 1 : 0) + 1 + 2; }
111
+ /** Dismissal is a cancel, so the caller's promise can never hang. */
112
+ answer() {
113
+ if (this.settled)
114
+ return;
155
115
  this.settled = true;
156
- const value = this.editor.getText();
157
- if (this.onSubmit) this.onSubmit(value);
158
- return 'close';
159
- }
160
- case 'backspace':
161
- if (event.alt) this.editor.killWordLeft(); else this.editor.backspace();
162
- return 'handled';
163
- case 'delete': this.editor.deleteForward(); return 'handled';
164
- case 'left': this.editor.moveLeft(); return 'handled';
165
- case 'right': this.editor.moveRight(); return 'handled';
166
- case 'home': this.editor.moveHome(); return 'handled';
167
- case 'end': this.editor.moveEnd(); return 'handled';
168
- case 'char': this.editor.insert(event.text); return 'handled';
169
- case 'paste': {
170
- const clean = String(event.text || '').replace(/[\r\n]+/g, '').trim();
171
- if (clean) this.editor.insert(clean);
172
- return 'handled';
173
- }
174
- default: break;
175
- }
176
-
177
- if (event.ctrl) {
178
- switch (event.name) {
179
- case 'a': this.editor.moveHome(); return 'handled';
180
- case 'e': this.editor.moveEnd(); return 'handled';
181
- case 'k': this.editor.killToEnd(); return 'handled';
182
- case 'u': this.editor.killToStart(); return 'handled';
183
- case 'w': this.editor.killWordLeft(); return 'handled';
184
- case 'v': {
185
- const text = readClipboardSync();
186
- if (text) {
187
- const clean = String(text).replace(/[\r\n]+/g, '').trim();
188
- if (clean) this.editor.insert(clean);
189
- }
190
- return 'handled';
116
+ if (this.onCancel)
117
+ this.onCancel();
118
+ }
119
+ body(width = 64) {
120
+ const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
121
+ const rows = this.lines.map((line) => truncate(cleanDialogText(line), safeWidth, GLYPHS.ellipsis));
122
+ if (rows.length)
123
+ rows.push('');
124
+ const raw = this.editor.getText();
125
+ const shown = this.mask ? GLYPHS.bullet.repeat(Array.from(raw).length) : cleanDialogText(raw);
126
+ const cleanPlaceholder = cleanDialogText(this.placeholder);
127
+ const text = shown.length === 0 && cleanPlaceholder ? dim(cleanPlaceholder) : shown;
128
+ const prefix = paint('accent', `${GLYPHS.arrow} `);
129
+ rows.push(truncate(prefix + text, safeWidth, GLYPHS.ellipsis));
130
+ // Park the caret after what is displayed — which for a masked field is the
131
+ // dot count, not the character count, or the caret drifts off the value —
132
+ // using code-point slicing (never UTF-16 `.slice()`) so emoji never shift
133
+ // the caret off the visible glyph boundary.
134
+ const beforeCodePoints = Array.from(raw).slice(0, this.editor.col);
135
+ const before = this.mask
136
+ ? beforeCodePoints.length
137
+ : visibleWidth(cleanDialogText(beforeCodePoints.join('')));
138
+ const maxCol = Math.max(0, safeWidth - 1);
139
+ this.cursor = { x: Math.min(maxCol, 2 + before), y: rows.length - 1 };
140
+ return rows;
141
+ }
142
+ key(event) {
143
+ if (!event)
144
+ return null;
145
+ switch (event.name) {
146
+ case 'escape':
147
+ return 'close';
148
+ case 'enter':
149
+ case 'return': {
150
+ if (this.settled)
151
+ return 'close';
152
+ this.settled = true;
153
+ const value = this.editor.getText();
154
+ if (this.onSubmit)
155
+ this.onSubmit(value);
156
+ return 'close';
157
+ }
158
+ case 'backspace':
159
+ if (event.alt)
160
+ this.editor.killWordLeft();
161
+ else
162
+ this.editor.backspace();
163
+ return 'handled';
164
+ case 'delete':
165
+ this.editor.deleteForward();
166
+ return 'handled';
167
+ case 'left':
168
+ this.editor.moveLeft();
169
+ return 'handled';
170
+ case 'right':
171
+ this.editor.moveRight();
172
+ return 'handled';
173
+ case 'home':
174
+ this.editor.moveHome();
175
+ return 'handled';
176
+ case 'end':
177
+ this.editor.moveEnd();
178
+ return 'handled';
179
+ case 'char':
180
+ this.editor.insert(event.text);
181
+ return 'handled';
182
+ case 'paste': {
183
+ // eslint-disable-next-line no-control-regex
184
+ const clean = String(event.text || '').replace(/[\x00-\x1f\x7f]+/g, '').trim().slice(0, MAX_DIALOG_PASTE_CHARS);
185
+ if (clean)
186
+ this.editor.insert(clean);
187
+ return 'handled';
188
+ }
189
+ default: break;
190
+ }
191
+ if (event.ctrl) {
192
+ switch (event.name) {
193
+ case 'a':
194
+ this.editor.moveHome();
195
+ return 'handled';
196
+ case 'e':
197
+ this.editor.moveEnd();
198
+ return 'handled';
199
+ case 'k':
200
+ this.editor.killToEnd();
201
+ return 'handled';
202
+ case 'u':
203
+ this.editor.killToStart();
204
+ return 'handled';
205
+ case 'w':
206
+ this.editor.killWordLeft();
207
+ return 'handled';
208
+ case 'v': {
209
+ let text = '';
210
+ try {
211
+ text = readClipboardSync() || '';
212
+ }
213
+ catch {
214
+ text = '';
215
+ }
216
+ if (text) {
217
+ // eslint-disable-next-line no-control-regex
218
+ const clean = String(text).replace(/[\x00-\x1f\x7f]+/g, '').trim().slice(0, MAX_DIALOG_PASTE_CHARS);
219
+ if (clean)
220
+ this.editor.insert(clean);
221
+ }
222
+ return 'handled';
223
+ }
224
+ default: break;
225
+ }
191
226
  }
192
- default: break;
193
- }
194
- }
195
-
196
- // Stay modal for anything unrecognised: a stray key must not reach the
197
- // input line behind a question that is still open.
198
- return 'handled';
199
- }
227
+ // Stay modal for anything unrecognised: a stray key must not reach the
228
+ // input line behind a question that is still open.
229
+ return 'handled';
230
+ }
200
231
  }
201
-
202
232
  /**
203
233
  * The home menu: the action list that sits above the input line.
204
234
  *
@@ -223,74 +253,75 @@ export class InputLayer extends Layer {
223
253
  * invariant is unchanged for them.
224
254
  */
225
255
  export class HomeLayer extends Layer {
226
- constructor(options = {}) {
227
- super({ width: options.width || 66, height: options.height || 14, ...options });
228
- this.items = Array.isArray(options.items) ? options.items : [];
229
- this.index = 0;
230
- this.onPick = options.onPick || null;
231
- this.title = options.title || 'what would you like to do?';
232
- this.footer = options.footer || `↑↓ pick ${GLYPHS.dot} enter run ${GLYPHS.dot} esc menu off ${GLYPHS.dot} or just start typing`;
233
- }
234
-
235
- // No filter row and no rule — one row per item, plus the frame.
236
- preferredHeight() { return this.items.length + 2; }
237
-
238
- get current() { return this.items[this.index] || null; }
239
-
240
- body(width) {
241
- // The hint column is right-padded from the widest label so the two columns
242
- // line up, but it is computed from the ACTUAL labels rather than a constant:
243
- // a hardcoded inset is what makes a menu look off by one at some widths.
244
- const cleanItems = this.items.map((item) => ({
245
- label: cleanDialogText(item?.label || ''),
246
- hint: cleanDialogText(item?.hint || '')
247
- }));
248
- const labelWidth = cleanItems.reduce((max, item) => Math.max(max, visibleWidth(item.label)), 0);
249
- return cleanItems.map((item, i) => {
250
- const selected = i === this.index;
251
- const marker = selected ? paint('accent', GLYPHS.arrow) : ' ';
252
- const label = selected ? bold(paint('accent', item.label)) : item.label;
253
- const pad = ' '.repeat(Math.max(0, labelWidth - visibleWidth(item.label)));
254
- const hint = item.hint ? dim(item.hint) : '';
255
- // truncate() is ANSI-aware, so styling the label first is safe. The row is
256
- // clamped to the panel, never to the terminal — the panel is narrower.
257
- return truncate(` ${marker} ${label}${pad} ${hint}`, width);
258
- });
259
- }
260
-
261
- key(event) {
262
- if (!event) return null;
263
-
264
- switch (event.name) {
265
- case 'up':
266
- if (this.items.length === 0) return 'handled';
267
- this.index = (this.index - 1 + this.items.length) % this.items.length;
268
- return 'handled';
269
- case 'down':
270
- if (this.items.length === 0) return 'handled';
271
- this.index = (this.index + 1) % this.items.length;
272
- return 'handled';
273
- case 'enter':
274
- case 'return': {
275
- const item = this.current;
276
- if (!item) return 'close';
277
- const result = this.onPick ? this.onPick(item) : null;
278
- return result === 'keep' ? 'handled' : 'close';
279
- }
280
- case 'escape': return 'close';
281
- default: break;
282
- }
283
-
284
- // A printable character is the user starting a sentence. Put the menu away
285
- // and let the character land in the input line in the same keystroke.
286
- if (event.name === 'char' || event.name === 'paste') return 'dismiss';
287
-
288
- // Anything else — ctrl chords, tab, backspace on an empty line — belongs to
289
- // the prompt, and the menu has no opinion about it.
290
- return 'passthrough';
291
- }
256
+ items;
257
+ index;
258
+ onPick;
259
+ constructor(options = {}) {
260
+ const opts = options && typeof options === 'object' ? options : {};
261
+ super({ width: opts.width || 66, height: opts.height || 14, ...opts });
262
+ this.items = Array.isArray(opts.items) ? [...opts.items] : [];
263
+ this.index = 0;
264
+ this.onPick = opts.onPick || null;
265
+ this.title = opts.title || 'what would you like to do?';
266
+ this.footer = opts.footer || `↑↓ pick ${GLYPHS.dot} enter run ${GLYPHS.dot} esc menu off ${GLYPHS.dot} or just start typing`;
267
+ }
268
+ // No filter row and no rule — one row per item, plus the frame.
269
+ preferredHeight() { return this.items.length + 2; }
270
+ get current() { return this.items[this.index] || null; }
271
+ body(width = 64) {
272
+ // The hint column is right-padded from the widest label so the two columns
273
+ // line up, but it is computed from the ACTUAL labels rather than a constant:
274
+ // a hardcoded inset is what makes a menu look off by one at some widths.
275
+ const cleanItems = this.items.map((item) => ({
276
+ label: cleanDialogText(item?.label || ''),
277
+ hint: cleanDialogText(item?.hint || '')
278
+ }));
279
+ const labelWidth = cleanItems.reduce((max, item) => Math.max(max, visibleWidth(item.label)), 0);
280
+ return cleanItems.map((item, i) => {
281
+ const selected = i === this.index;
282
+ const marker = selected ? paint('accent', GLYPHS.arrow) : ' ';
283
+ const label = selected ? bold(paint('accent', item.label)) : item.label;
284
+ const pad = ' '.repeat(Math.max(0, labelWidth - visibleWidth(item.label)));
285
+ const hint = item.hint ? dim(item.hint) : '';
286
+ // truncate() is ANSI-aware, so styling the label first is safe. The row is
287
+ // clamped to the panel, never to the terminal — the panel is narrower.
288
+ return truncate(` ${marker} ${label}${pad} ${hint}`, width);
289
+ });
290
+ }
291
+ key(event) {
292
+ if (!event)
293
+ return null;
294
+ switch (event.name) {
295
+ case 'up':
296
+ if (this.items.length === 0)
297
+ return 'handled';
298
+ this.index = (this.index - 1 + this.items.length) % this.items.length;
299
+ return 'handled';
300
+ case 'down':
301
+ if (this.items.length === 0)
302
+ return 'handled';
303
+ this.index = (this.index + 1) % this.items.length;
304
+ return 'handled';
305
+ case 'enter':
306
+ case 'return': {
307
+ const item = this.current;
308
+ if (!item)
309
+ return 'close';
310
+ const result = this.onPick ? this.onPick(item) : null;
311
+ return result === 'keep' ? 'handled' : 'close';
312
+ }
313
+ case 'escape': return 'close';
314
+ default: break;
315
+ }
316
+ // A printable character is the user starting a sentence. Put the menu away
317
+ // and let the character land in the input line in the same keystroke.
318
+ if (event.name === 'char' || event.name === 'paste')
319
+ return 'dismiss';
320
+ // Anything else — ctrl chords, tab, backspace on an empty line — belongs to
321
+ // the prompt, and the menu has no opinion about it.
322
+ return 'passthrough';
323
+ }
292
324
  }
293
-
294
325
  /**
295
326
  * A scrolling text pane — help, usage, an expanded tool output, an error.
296
327
  *
@@ -298,57 +329,71 @@ export class HomeLayer extends Layer {
298
329
  * whole thing" never again means dumping 900 lines into the transcript.
299
330
  */
300
331
  export class TextLayer extends Layer {
301
- constructor(options = {}) {
302
- super({ width: options.width || 76, height: options.height || 20, ...options });
303
- this.lines = Array.isArray(options.lines) ? options.lines : String(options.text || '').split('\n');
304
- this.scroll = 0;
305
- this.footer = options.footer || `↑↓ scroll ${GLYPHS.dot} esc close`;
306
- }
307
-
308
- preferredHeight() { return this.lines.length + 2; }
309
-
310
- body(width, height) {
311
- const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
312
- const safeHeight = Number.isFinite(height) && height > 0 ? Math.floor(height) : 1;
313
- this.viewHeight = safeHeight;
314
- const maximum = Math.max(0, this.lines.length - safeHeight);
315
- this.scroll = Math.max(0, Math.min(this.scroll, maximum));
316
-
317
- const window = this.lines.slice(this.scroll, this.scroll + safeHeight)
318
- .map((line) => truncate(line == null ? '' : safeDisplay(String(line)), safeWidth, GLYPHS.ellipsis));
319
-
320
- if (this.lines.length > safeHeight) {
321
- const position = `${this.scroll + 1}-${Math.min(this.lines.length, this.scroll + safeHeight)}/${this.lines.length}`;
322
- while (window.length < safeHeight) window.push('');
323
- window[safeHeight - 1] = dim(position.padStart(safeWidth));
324
- }
325
- this.cursor = null;
326
- return window;
327
- }
328
-
329
- key(event) {
330
- if (!event) return null;
331
- const page = Math.max(1, (this.viewHeight || this.height) - 1);
332
- switch (event.name) {
333
- case 'escape':
334
- case 'q': return 'close';
335
- case 'wheel':
336
- if (event.wheel?.direction === 'up') this.scroll = Math.max(0, this.scroll - 1);
337
- else if (event.wheel?.direction === 'down') this.scroll++;
338
- return 'handled';
339
- case 'up': this.scroll = Math.max(0, this.scroll - 1); return 'handled';
340
- case 'down': this.scroll++; return 'handled';
341
- case 'pageup': this.scroll = Math.max(0, this.scroll - page); return 'handled';
342
- case 'pagedown': this.scroll += page; return 'handled';
343
- case 'home': this.scroll = 0; return 'handled';
344
- case 'end': this.scroll = this.lines.length; return 'handled';
345
- case 'enter':
346
- case 'return': return 'close';
347
- default: return 'handled';
348
- }
349
- }
332
+ lines;
333
+ scroll;
334
+ viewHeight;
335
+ constructor(options = {}) {
336
+ const opts = options && typeof options === 'object' ? options : {};
337
+ super({ width: opts.width || 76, height: opts.height || 20, ...opts });
338
+ this.lines = Array.isArray(opts.lines) ? [...opts.lines] : String(opts.text || '').split('\n');
339
+ this.scroll = 0;
340
+ this.footer = opts.footer || `↑↓ scroll ${GLYPHS.dot} esc close`;
341
+ }
342
+ preferredHeight() { return this.lines.length + 2; }
343
+ body(width = 72, height = 18) {
344
+ const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
345
+ const safeHeight = Number.isFinite(height) && height > 0 ? Math.floor(height) : 1;
346
+ this.viewHeight = safeHeight;
347
+ const maximum = Math.max(0, this.lines.length - safeHeight);
348
+ this.scroll = Math.max(0, Math.min(this.scroll, maximum));
349
+ const windowLines = this.lines.slice(this.scroll, this.scroll + safeHeight)
350
+ .map((line) => truncate(line == null ? '' : safeDisplay(String(line)), safeWidth, GLYPHS.ellipsis));
351
+ if (this.lines.length > safeHeight) {
352
+ const position = `${this.scroll + 1}-${Math.min(this.lines.length, this.scroll + safeHeight)}/${this.lines.length}`;
353
+ while (windowLines.length < safeHeight)
354
+ windowLines.push('');
355
+ windowLines[safeHeight - 1] = dim(position.padStart(safeWidth));
356
+ }
357
+ this.cursor = null;
358
+ return windowLines;
359
+ }
360
+ key(event) {
361
+ if (!event)
362
+ return null;
363
+ const page = Math.max(1, (this.viewHeight || this.height) - 1);
364
+ switch (event.name) {
365
+ case 'escape':
366
+ case 'q': return 'close';
367
+ case 'wheel':
368
+ if (event.wheel?.direction === 'up')
369
+ this.scroll = Math.max(0, this.scroll - 1);
370
+ else if (event.wheel?.direction === 'down')
371
+ this.scroll++;
372
+ return 'handled';
373
+ case 'up':
374
+ this.scroll = Math.max(0, this.scroll - 1);
375
+ return 'handled';
376
+ case 'down':
377
+ this.scroll++;
378
+ return 'handled';
379
+ case 'pageup':
380
+ this.scroll = Math.max(0, this.scroll - page);
381
+ return 'handled';
382
+ case 'pagedown':
383
+ this.scroll += page;
384
+ return 'handled';
385
+ case 'home':
386
+ this.scroll = 0;
387
+ return 'handled';
388
+ case 'end':
389
+ this.scroll = this.lines.length;
390
+ return 'handled';
391
+ case 'enter':
392
+ case 'return': return 'close';
393
+ default: return 'handled';
394
+ }
395
+ }
350
396
  }
351
-
352
397
  /**
353
398
  * The approval modal.
354
399
  *
@@ -361,411 +406,501 @@ export class TextLayer extends Layer {
361
406
  * denies, while an intentional move to either Allow option works consistently.
362
407
  */
363
408
  export class ApprovalLayer extends Layer {
364
- constructor(options = {}) {
365
- super({ width: options.width || 84, height: options.height || 22, ...options });
366
- this.request = options.request || {};
367
- this.detail = options.detail || '';
368
- this.verb = options.verb || '';
369
- this.onAnswer = options.onAnswer || null;
370
- this.scroll = 0;
371
-
372
- // The risk TIER is kept for colour and for the audit trail; it is never
373
- // shown as a word. Printing 'DANGEROUS' at someone who asked to install a
374
- // package does not make them careful, it makes them numb — and a gate people
375
- // are numb to is not a gate. opencode shows a warning triangle and the tool,
376
- // and that is the whole signal: being asked at all IS the warning.
377
- const risk = String(this.request.risk || 'unknown').toUpperCase();
378
- this.risk = risk;
379
- this.role = risk === 'EXTREME' ? 'danger' : risk === 'DANGEROUS' ? 'warn' : 'accent';
380
- this.title = 'permission required';
381
-
382
- // Selectable options, modelled on opencode's permission prompt: a row of
383
- // chips moved with ←/→ and committed with enter. Typing y/n still answers
384
- // directly, so the fast path stays one keystroke rather than two.
385
- // grant_capability stores consent for the named capability group itself.
386
- // A standing grant for the *manager tool* would also authorize unrelated
387
- // package and MCP operations, and adds a redundant second confirmation.
388
- this.capabilityGrant = this.request.tool === 'manage_local_dependencies'
389
- && this.request.args?.action === 'grant_capability';
390
- this.options = [
391
- { id: 'once', label: 'Allow once', answer: true },
392
- // Standing approval for the rest of the PROCESS — never written to disk.
393
- // Seven developers in ten would rather grant this than be asked again,
394
- // and a gate people hammer through is worse than one they chose to lift.
395
- // It is not the default and it is confirmed a second time before it takes
396
- // effect; see makeApprovalHandler in cliMode.js.
397
- ...(!this.capabilityGrant ? [{ id: 'always', label: 'Allow always', answer: true }] : []),
398
- { id: 'reject', label: 'Reject', answer: false }
399
- ];
400
-
401
- // THE DEFAULT IS DENY, AND THAT IS DELIBERATE.
402
- //
403
- // opencode starts on its approving option, which suits a coding session
404
- // where the worst case is an unwanted file edit. Causyne's approval gate
405
- // also stands in front of `sysRun` and `desktop_act` — arbitrary shell and
406
- // full control of the user's mouse and keyboard. Enter is the key people
407
- // press without reading, so it must not be the one that says yes.
408
- //
409
- // Approving is still a single keystroke (`y`); it is just not the REFLEX
410
- // keystroke. Set the highlight to Approve here and one careless enter
411
- // authorises anything the agent asks for.
412
- this.selected = this.options.findIndex(option => option.id === 'reject');
413
-
414
- this.footer = `←→ choose ${GLYPHS.dot} enter confirm ${GLYPHS.dot} ${this.capabilityGrant ? 'y/n' : 'y/a/n'} direct ${GLYPHS.dot} ↑↓ scroll ${GLYPHS.dot} esc reject`;
415
-
416
- this.diff = approvalDiff(this.request.tool, this.request.args, { width: this.width - 6, maxLines: 400 });
417
- }
418
-
419
- preferredHeight() {
420
- const detailRows = this.detail ? 1 : 0;
421
- // A diff costs a blank, a stat row and a rule on top of its own rows.
422
- const diffRows = this.diff ? this.diff.rows.length + 3 : Object.keys(this.request.args || {}).length + 1;
423
- // +2 for the blank line and the option row that always sit at the bottom.
424
- return 1 + detailRows + diffRows + 2 + 2;
425
- }
426
-
427
- /** The chip row: the selected option is filled, the rest are dimmed. */
428
- optionRow() {
429
- let col = 0;
430
- this.optionBounds = [];
431
- const parts = this.options.map((option, index) => {
432
- const rendered = index === this.selected
433
- ? badge(option.id === 'reject' ? 'danger' : 'success', option.label)
434
- : dim(` ${option.label} `);
435
- const width = visibleWidth(rendered);
436
- this.optionBounds.push({ index, option, startCol: col, endCol: col + width - 1 });
437
- col += width + 1;
438
- return rendered;
439
- });
440
- return parts.join(' ');
441
- }
442
-
443
- body(width, fullHeight) {
444
- // Two rows are reserved at the bottom for the blank line and the option
445
- // chips, so the diff never grows into the controls and push them off-panel.
446
- const height = Math.max(1, fullHeight - 2);
447
- const rows = [];
448
- const cleanVerb = this.verb ? cleanDialogText(this.verb) : '';
449
- rows.push(`${paint(this.role, GLYPHS.warnMark)} ${bold(safeDisplay(this.request.tool || ''))}${cleanVerb ? dim(` ${cleanVerb}`) : ''}`);
450
-
451
- if (this.detail) {
452
- for (const line of wrap(paint('ink', cleanDialogText(this.detail)), width).slice(0, 2)) rows.push(line);
453
- }
454
-
455
- if (this.diff) {
456
- const stat = [
457
- this.diff.added ? paint('success', `+${this.diff.added}`) : '',
458
- this.diff.removed ? paint('danger', `-${this.diff.removed}`) : ''
459
- ].filter(Boolean).join(' ');
460
- const note = this.diff.note ? dim(` ${GLYPHS.dot} ${cleanDialogText(this.diff.note)}`) : '';
461
- // The detail row above already names the file; printing the path again
462
- // here just spends a row saying the same thing twice.
463
- const where = this.detail ? '' : `${dim(cleanDialogText(this.diff.path))} `;
464
- rows.push('');
465
- rows.push(`${where}${stat}${note}`);
466
- rows.push(paint('rule', GLYPHS.hLine.repeat(width)));
467
-
468
- // Only spend a row on the scroll indicator when there is actually
469
- // something out of view. Reserving it unconditionally cost one diff row
470
- // on every dialog that fit perfectly.
471
- const available = Math.max(1, height - rows.length);
472
- const needsIndicator = this.diff.rows.length > available;
473
- const room = needsIndicator ? Math.max(1, available - 1) : available;
474
- this.viewHeight = room;
475
- const maximum = Math.max(0, this.diff.rows.length - room);
476
- this.scroll = Math.max(0, Math.min(this.scroll, maximum));
477
-
478
- for (const line of this.diff.rows.slice(this.scroll, this.scroll + room)) {
479
- rows.push(truncate(line, width, GLYPHS.ellipsis));
480
- }
481
- if (this.diff.rows.length > room) {
482
- rows.push(dim(`${this.scroll + 1}-${Math.min(this.diff.rows.length, this.scroll + room)}/${this.diff.rows.length}`.padStart(width)));
483
- }
484
- } else if (this.request.args) {
485
- rows.push('');
486
- // No diff means this is not a file mutation; show the arguments instead,
487
- // because "approve sysRun" with the command hidden is not consent either.
488
- for (const [key, value] of Object.entries(this.request.args).slice(0, 8)) {
489
- const shown = typeof value === 'string' ? shortenHome(value) : JSON.stringify(value);
490
- for (const line of wrap(`${paint('muted', key)} ${paint('ink', safeDisplay(String(shown)))}`, width).slice(0, 4)) {
491
- rows.push(line);
492
- if (rows.length >= height) break;
409
+ request;
410
+ detail;
411
+ verb;
412
+ onAnswer;
413
+ scroll;
414
+ risk;
415
+ role;
416
+ capabilityGrant;
417
+ options;
418
+ selected;
419
+ diff;
420
+ optionBounds;
421
+ panelGeometry;
422
+ viewHeight;
423
+ answered;
424
+ constructor(options = {}) {
425
+ const opts = options && typeof options === 'object' ? options : {};
426
+ super({ width: opts.width || 84, height: opts.height || 22, ...opts });
427
+ this.request = opts.request || {};
428
+ this.detail = opts.detail || '';
429
+ this.verb = opts.verb || '';
430
+ this.onAnswer = opts.onAnswer || null;
431
+ this.scroll = 0;
432
+ // The risk TIER is kept for colour and for the audit trail; it is never
433
+ // shown as a word. Printing 'DANGEROUS' at someone who asked to install a
434
+ // package does not make them careful, it makes them numb — and a gate people
435
+ // are numb to is not a gate. opencode shows a warning triangle and the tool,
436
+ // and that is the whole signal: being asked at all IS the warning.
437
+ const risk = String(this.request.risk || 'unknown').toUpperCase();
438
+ this.risk = risk;
439
+ this.role = risk === 'EXTREME' ? 'danger' : risk === 'DANGEROUS' ? 'warn' : 'accent';
440
+ this.title = 'permission required';
441
+ // Selectable options, modelled on opencode's permission prompt: a row of
442
+ // chips moved with ←/→ and committed with enter. Typing y/n still answers
443
+ // directly, so the fast path stays one keystroke rather than two.
444
+ // grant_capability stores consent for the named capability group itself.
445
+ // A standing grant for the *manager tool* would also authorize unrelated
446
+ // package and MCP operations, and adds a redundant second confirmation.
447
+ this.capabilityGrant = this.request.tool === 'manage_local_dependencies'
448
+ && this.request.args?.action === 'grant_capability';
449
+ this.options = [
450
+ { id: 'once', label: 'Allow once', answer: true },
451
+ // Standing approval for the rest of the PROCESS — never written to disk.
452
+ // Seven developers in ten would rather grant this than be asked again,
453
+ // and a gate people hammer through is worse than one they chose to lift.
454
+ // It is not the default and it is confirmed a second time before it takes
455
+ // effect; see makeApprovalHandler in cliMode.js.
456
+ ...(!this.capabilityGrant ? [{ id: 'always', label: 'Allow always', answer: true }] : []),
457
+ { id: 'reject', label: 'Reject', answer: false }
458
+ ];
459
+ // THE DEFAULT IS DENY, AND THAT IS DELIBERATE.
460
+ //
461
+ // opencode starts on its approving option, which suits a coding session
462
+ // where the worst case is an unwanted file edit. Causyne's approval gate
463
+ // also stands in front of `sysRun` and `desktop_act` — arbitrary shell and
464
+ // full control of the user's mouse and keyboard. Enter is the key people
465
+ // press without reading, so it must not be the one that says yes.
466
+ //
467
+ // Approving is still a single keystroke (`y`); it is just not the REFLEX
468
+ // keystroke. Set the highlight to Approve here and one careless enter
469
+ // authorises anything the agent asks for.
470
+ this.selected = this.options.findIndex(option => option.id === 'reject');
471
+ this.footer = `←→ choose ${GLYPHS.dot} enter confirm ${GLYPHS.dot} ${this.capabilityGrant ? 'y/n' : 'y/a/n'} direct ${GLYPHS.dot} ↑↓ scroll ${GLYPHS.dot} esc reject`;
472
+ this.diff = approvalDiff(this.request.tool, this.request.args, { width: this.width - 6, maxLines: 400 });
473
+ }
474
+ preferredHeight() {
475
+ const detailRows = this.detail ? 1 : 0;
476
+ // A diff costs a blank, a stat row and a rule on top of its own rows.
477
+ const diffRows = this.diff ? this.diff.rows.length + 3 : Object.keys(this.request.args || {}).length + 1;
478
+ // +2 for the blank line and the option row that always sit at the bottom.
479
+ return 1 + detailRows + diffRows + 2 + 2;
480
+ }
481
+ /** The chip row: the selected option is filled, the rest are dimmed. */
482
+ optionRow() {
483
+ let col = 0;
484
+ this.optionBounds = [];
485
+ const parts = this.options.map((option, index) => {
486
+ const rendered = index === this.selected
487
+ ? badge(option.id === 'reject' ? 'danger' : 'success', option.label)
488
+ : dim(` ${option.label} `);
489
+ const width = visibleWidth(rendered);
490
+ this.optionBounds.push({ index, option, startCol: col, endCol: col + width - 1 });
491
+ col += width + 1;
492
+ return rendered;
493
+ });
494
+ return parts.join(' ');
495
+ }
496
+ body(width = 80, fullHeight = 20) {
497
+ // Two rows are reserved at the bottom for the blank line and the option
498
+ // chips, so the diff never grows into the controls and push them off-panel.
499
+ const height = Math.max(1, fullHeight - 2);
500
+ const rows = [];
501
+ const cleanVerb = this.verb ? cleanDialogText(this.verb) : '';
502
+ rows.push(`${paint(this.role, GLYPHS.warnMark)} ${bold(safeDisplay(this.request.tool || ''))}${cleanVerb ? dim(` ${cleanVerb}`) : ''}`);
503
+ if (this.detail) {
504
+ for (const line of wrap(paint('ink', cleanDialogText(this.detail)), width).slice(0, 2))
505
+ rows.push(line);
506
+ }
507
+ if (this.diff) {
508
+ const stat = [
509
+ this.diff.added ? paint('success', `+${this.diff.added}`) : '',
510
+ this.diff.removed ? paint('danger', `-${this.diff.removed}`) : ''
511
+ ].filter(Boolean).join(' ');
512
+ const note = this.diff.note ? dim(` ${GLYPHS.dot} ${cleanDialogText(this.diff.note)}`) : '';
513
+ // The detail row above already names the file; printing the path again
514
+ // here just spends a row saying the same thing twice.
515
+ const where = this.detail ? '' : `${dim(cleanDialogText(this.diff.path))} `;
516
+ rows.push('');
517
+ rows.push(`${where}${stat}${note}`);
518
+ rows.push(paint('rule', GLYPHS.hLine.repeat(width)));
519
+ // Only spend a row on the scroll indicator when there is actually
520
+ // something out of view. Reserving it unconditionally cost one diff row
521
+ // on every dialog that fit perfectly.
522
+ const available = Math.max(1, height - rows.length);
523
+ const needsIndicator = this.diff.rows.length > available;
524
+ const room = needsIndicator ? Math.max(1, available - 1) : available;
525
+ this.viewHeight = room;
526
+ const maximum = Math.max(0, this.diff.rows.length - room);
527
+ this.scroll = Math.max(0, Math.min(this.scroll, maximum));
528
+ for (const line of this.diff.rows.slice(this.scroll, this.scroll + room)) {
529
+ rows.push(truncate(line, width, GLYPHS.ellipsis));
530
+ }
531
+ if (this.diff.rows.length > room) {
532
+ rows.push(dim(`${this.scroll + 1}-${Math.min(this.diff.rows.length, this.scroll + room)}/${this.diff.rows.length}`.padStart(width)));
533
+ }
493
534
  }
494
- if (rows.length >= height) break;
495
- }
496
- }
497
-
498
- while (rows.length < height) rows.push('');
499
- rows.push('');
500
- rows.push(this.optionRow());
501
-
502
- this.cursor = null;
503
- return rows.slice(0, fullHeight);
504
- }
505
-
506
- key(event) {
507
- if (!event) return null;
508
- const page = Math.max(1, (this.viewHeight || 8) - 1);
509
-
510
- // isChar(), NOT event.name. A printable key decodes to {name:'char',
511
- // text:'y'} — only MODIFIED letters carry the letter as a name. Testing
512
- // event.name === 'y' here matched ctrl+y and never matched y, so this
513
- // dialog could not be approved at all; escape worked, which made it look
514
- // responsive. See src/tui/keys.js isChar().
515
- if (isChar(event, 'y')) { this.answer(true, 'once'); return 'close'; }
516
- if (!this.capabilityGrant && isChar(event, 'a')) { this.answer(true, 'always'); return 'close'; }
517
- if (isChar(event, 'n')) { this.answer(false, 'reject'); return 'close'; }
518
- if (event.name === 'escape') { this.answer(false, 'reject'); return 'close'; }
519
-
520
- // ←/→ move the highlight, enter commits it — opencode's permission model,
521
- // which is the one people already have muscle memory for. `h`/`l` come
522
- // along for the same reason opencode binds them: a vim user reaches for
523
- // them without thinking, and they cost nothing here.
524
- const move = (delta) => {
525
- this.selected = (this.selected + delta + this.options.length) % this.options.length;
526
- return 'handled';
527
- };
528
- if (event.name === 'left' || isChar(event, 'h')) return move(-1);
529
- if (event.name === 'right' || isChar(event, 'l')) return move(1);
530
- if (event.name === 'enter' || event.name === 'return') {
531
- const choice = this.options[this.selected];
532
- this.answer(Boolean(choice && choice.answer), choice ? choice.id : 'reject');
533
- return 'close';
534
- }
535
-
536
- if (event.name === 'mouse' && event.mouse && event.mouse.pressed && event.mouse.button === 0 && !isMouseMotion(event.sequence)) {
537
- if (!Array.isArray(this.optionBounds) || this.optionBounds.length === 0) {
538
- this.optionRow();
539
- }
540
- const geom = this.panelGeometry;
541
- const hasZeroRow = Number.isFinite(event.mouse.y);
542
- const rawRow = hasZeroRow
543
- ? Math.floor(event.mouse.y)
544
- : (Number.isFinite(event.mouse.row) ? Math.floor(event.mouse.row) : NaN);
545
- if (geom && Number.isFinite(rawRow) && Number.isFinite(geom.optionScreenRow)) {
546
- // drawLayer() computes 0-based screen rows; legacy synthetic callers send 1-based row.
547
- const zeroBasedRow = hasZeroRow ? rawRow : rawRow - 1;
548
- if (Math.abs(zeroBasedRow - geom.optionScreenRow) > 1) return 'handled';
549
- }
550
- const hasZeroCol = Number.isFinite(event.mouse.x);
551
- const rawCol = hasZeroCol
552
- ? Math.floor(event.mouse.x)
553
- : (Number.isFinite(event.mouse.col) ? Math.floor(event.mouse.col) : -1);
554
- const bodyCol = geom
555
- ? rawCol - (hasZeroCol ? 0 : 1) - (geom.inset || 0) - 2
556
- : rawCol;
557
- const hit = (this.optionBounds || []).find(b => bodyCol >= b.startCol && bodyCol <= b.endCol);
558
- if (hit) {
559
- this.selected = hit.index;
560
- this.answer(Boolean(hit.option.answer), hit.option.id);
561
- return 'close';
562
- }
563
- return 'handled';
564
- }
565
-
566
- if (event.name === 'wheel') {
567
- if (event.wheel?.direction === 'up') this.scroll = Math.max(0, this.scroll - 1);
568
- else if (event.wheel?.direction === 'down') this.scroll++;
569
- return 'handled';
570
- }
571
-
572
- switch (event.name) {
573
- case 'up': this.scroll = Math.max(0, this.scroll - 1); return 'handled';
574
- case 'down': this.scroll++; return 'handled';
575
- case 'pageup': this.scroll = Math.max(0, this.scroll - page); return 'handled';
576
- case 'pagedown': this.scroll += page; return 'handled';
577
- case 'home': this.scroll = 0; return 'handled';
578
- case 'end': this.scroll = this.diff ? this.diff.rows.length : 0; return 'handled';
579
- default: return 'handled';
580
- }
581
- }
582
-
583
- /**
584
- * Deliver the decision exactly once.
585
- *
586
- * `scope` says WHICH option produced it — 'once', 'always' or 'reject'.
587
- * closeLayer() calls this with no arguments when a dialog is torn down from
588
- * outside, and the defaults make that a rejection, which is the safe reading
589
- * of a question nobody answered.
590
- */
591
- answer(approved = false, scope = 'reject') {
592
- if (this.answered) return;
593
- this.answered = true;
594
- if (this.onAnswer) this.onAnswer(approved, scope);
595
- }
535
+ else if (this.request.args) {
536
+ rows.push('');
537
+ // No diff means this is not a file mutation; show the arguments instead,
538
+ // because "approve sysRun" with the command hidden is not consent either.
539
+ for (const [key, value] of Object.entries(this.request.args).slice(0, 8)) {
540
+ const shown = typeof value === 'string' ? shortenHome(value) : safeJsonPreview(value);
541
+ for (const line of wrap(`${paint('muted', key)} ${paint('ink', safeDisplay(String(shown)))}`, width).slice(0, 4)) {
542
+ rows.push(line);
543
+ if (rows.length >= height)
544
+ break;
545
+ }
546
+ if (rows.length >= height)
547
+ break;
548
+ }
549
+ }
550
+ while (rows.length < height)
551
+ rows.push('');
552
+ rows.push('');
553
+ rows.push(this.optionRow());
554
+ this.cursor = null;
555
+ return rows.slice(0, fullHeight);
556
+ }
557
+ key(event) {
558
+ if (!event)
559
+ return null;
560
+ const page = Math.max(1, (this.viewHeight || 8) - 1);
561
+ // isChar(), NOT event.name. A printable key decodes to {name:'char',
562
+ // text:'y'} — only MODIFIED letters carry the letter as a name. Testing
563
+ // event.name === 'y' here matched ctrl+y and never matched y, so this
564
+ // dialog could not be approved at all; escape worked, which made it look
565
+ // responsive. See src/tui/keys.js isChar().
566
+ if (isChar(event, 'y')) {
567
+ this.answer(true, 'once');
568
+ return 'close';
569
+ }
570
+ if (!this.capabilityGrant && isChar(event, 'a')) {
571
+ this.answer(true, 'always');
572
+ return 'close';
573
+ }
574
+ if (isChar(event, 'n')) {
575
+ this.answer(false, 'reject');
576
+ return 'close';
577
+ }
578
+ if (event.name === 'escape') {
579
+ this.answer(false, 'reject');
580
+ return 'close';
581
+ }
582
+ // ←/→ move the highlight, enter commits it — opencode's permission model,
583
+ // which is the one people already have muscle memory for. `h`/`l` come
584
+ // along for the same reason opencode binds them: a vim user reaches for
585
+ // them without thinking, and they cost nothing here.
586
+ const move = (delta) => {
587
+ this.selected = (this.selected + delta + this.options.length) % this.options.length;
588
+ return 'handled';
589
+ };
590
+ if (event.name === 'left' || isChar(event, 'h'))
591
+ return move(-1);
592
+ if (event.name === 'right' || isChar(event, 'l'))
593
+ return move(1);
594
+ if (event.name === 'enter' || event.name === 'return') {
595
+ const choice = this.options[this.selected];
596
+ this.answer(Boolean(choice && choice.answer), choice ? choice.id : 'reject');
597
+ return 'close';
598
+ }
599
+ if (event.name === 'mouse' && event.mouse && event.mouse.pressed && event.mouse.button === 0 && !isMouseMotion(event.sequence)) {
600
+ if (!Array.isArray(this.optionBounds) || this.optionBounds.length === 0) {
601
+ this.optionRow();
602
+ }
603
+ const geom = this.panelGeometry;
604
+ const hasZeroRow = Number.isFinite(event.mouse.y);
605
+ const rawRow = hasZeroRow
606
+ ? Math.floor(event.mouse.y)
607
+ : (Number.isFinite(event.mouse.row) ? Math.floor(event.mouse.row) : Number.NaN);
608
+ if (geom && Number.isFinite(rawRow) && typeof geom.optionScreenRow === 'number' && Number.isFinite(geom.optionScreenRow)) {
609
+ // drawLayer() computes 0-based screen rows; legacy synthetic callers send 1-based row.
610
+ const zeroBasedRow = hasZeroRow ? rawRow : rawRow - 1;
611
+ if (Math.abs(zeroBasedRow - geom.optionScreenRow) > 1)
612
+ return 'handled';
613
+ }
614
+ const hasZeroCol = Number.isFinite(event.mouse.x);
615
+ const rawCol = hasZeroCol
616
+ ? Math.floor(event.mouse.x)
617
+ : (Number.isFinite(event.mouse.col) ? Math.floor(event.mouse.col) : -1);
618
+ const bodyCol = geom
619
+ ? rawCol - (hasZeroCol ? 0 : 1) - (geom.inset || 0) - 2
620
+ : rawCol;
621
+ const hit = (this.optionBounds || []).find(b => bodyCol >= b.startCol && bodyCol <= b.endCol);
622
+ if (hit) {
623
+ this.selected = hit.index;
624
+ this.answer(Boolean(hit.option.answer), hit.option.id);
625
+ return 'close';
626
+ }
627
+ return 'handled';
628
+ }
629
+ if (event.name === 'wheel') {
630
+ if (event.wheel?.direction === 'up')
631
+ this.scroll = Math.max(0, this.scroll - 1);
632
+ else if (event.wheel?.direction === 'down')
633
+ this.scroll++;
634
+ return 'handled';
635
+ }
636
+ switch (event.name) {
637
+ case 'up':
638
+ this.scroll = Math.max(0, this.scroll - 1);
639
+ return 'handled';
640
+ case 'down':
641
+ this.scroll++;
642
+ return 'handled';
643
+ case 'pageup':
644
+ this.scroll = Math.max(0, this.scroll - page);
645
+ return 'handled';
646
+ case 'pagedown':
647
+ this.scroll += page;
648
+ return 'handled';
649
+ case 'home':
650
+ this.scroll = 0;
651
+ return 'handled';
652
+ case 'end':
653
+ this.scroll = this.diff ? this.diff.rows.length : 0;
654
+ return 'handled';
655
+ default: return 'handled';
656
+ }
657
+ }
658
+ /**
659
+ * Deliver the decision exactly once.
660
+ *
661
+ * `scope` says WHICH option produced it — 'once', 'always' or 'reject'.
662
+ * closeLayer() calls this with no arguments when a dialog is torn down from
663
+ * outside, and the defaults make that a rejection, which is the safe reading
664
+ * of a question nobody answered.
665
+ */
666
+ answer(approved = false, scope = 'reject') {
667
+ if (this.answered)
668
+ return;
669
+ this.answered = true;
670
+ if (this.onAnswer)
671
+ this.onAnswer(approved, scope);
672
+ }
596
673
  }
597
-
598
674
  /** A structured product or architecture choice, separate from permissions. */
599
675
  export class DecisionLayer extends Layer {
600
- constructor(options = {}) {
601
- super({ width: options.width || 82, height: options.height || 24, ...options });
602
- this.request = options.request || {};
603
- this.onAnswer = options.onAnswer || null;
604
- this.options = Array.isArray(this.request.options) ? this.request.options.slice(0, 4) : [];
605
- this.selected = 0;
606
- this.customIndex = this.options.length;
607
- this.customMode = false;
608
- this.editor = new LineEditor();
609
- this.answered = false;
610
- this.title = safeDisplay(this.request.header || 'decision required');
611
- this.footer = `↑↓ choose ${GLYPHS.dot} enter select ${GLYPHS.dot} esc cancel`;
612
- }
613
-
614
- preferredHeight() {
615
- const questionRows = wrap(safeDisplay(this.request.question || ''), Math.max(20, this.width - 6)).length;
616
- const reasonRows = wrap(safeDisplay(this.request.reason || ''), Math.max(20, this.width - 6)).length;
617
- return Math.min(this.height, questionRows + reasonRows + (this.options.length * 2) + 7);
618
- }
619
-
620
- body(width, height) {
621
- const rows = [];
622
- rows.push(...wrap(bold(safeDisplay(this.request.question || 'Choose a direction')), width).slice(0, 4));
623
- if (this.request.reason) rows.push(...wrap(dim(safeDisplay(this.request.reason)), width).slice(0, 3));
624
- rows.push('');
625
-
626
- for (const [index, option] of this.options.entries()) {
627
- const selected = index === this.selected;
628
- const marker = selected ? paint('accent', GLYPHS.arrow) : paint('muted', GLYPHS.dot);
629
- rows.push(`${marker} ${selected ? bold(safeDisplay(option.label || '')) : safeDisplay(option.label || '')}`);
630
- if (option.description) rows.push(` ${dim(truncate(safeDisplay(option.description), Math.max(1, width - 2), GLYPHS.ellipsis))}`);
631
- }
632
-
633
- const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
634
- const safeHeight = Number.isFinite(height) && height > 0 ? Math.floor(height) : rows.length + 2;
635
- const customSelected = this.selected === this.customIndex;
636
- rows.push(`${customSelected ? paint('accent', GLYPHS.arrow) : paint('muted', GLYPHS.dot)} ${customSelected ? bold('Type your own answer') : 'Type your own answer'}`);
637
- if (this.customMode) {
638
- const raw = this.editor.getText();
639
- const value = cleanDialogText(raw);
640
- rows.push(truncate(`${paint('accent', `${GLYPHS.arrow} `)}${value || dim('Describe the direction you want')}`, safeWidth, GLYPHS.ellipsis));
641
- const rendered = rows.length > safeHeight ? rows.slice(rows.length - safeHeight) : rows;
642
- const before = visibleWidth(cleanDialogText(raw.slice(0, this.editor.col)));
643
- this.cursor = {
644
- x: Math.min(Math.max(0, safeWidth - 1), 2 + before),
645
- y: Math.max(0, rendered.length - 1)
646
- };
647
- this.footer = `enter submit ${GLYPHS.dot} esc choices`;
648
- return rendered;
649
- } else {
650
- this.cursor = null;
651
- this.footer = `↑↓ choose ${GLYPHS.dot} enter select ${GLYPHS.dot} esc cancel`;
652
- }
653
- return rows.slice(0, safeHeight);
654
- }
655
-
656
- key(event) {
657
- if (!event) return null;
658
- if (this.customMode) {
659
- if (event.name === 'escape') { this.customMode = false; return 'handled'; }
660
- if (event.name === 'enter' || event.name === 'return') {
661
- const label = this.editor.getText().replace(/\s+/g, ' ').trim();
662
- if (!label) return 'handled';
663
- this.answer({ requestId: this.request.id, optionId: null, label, custom: true });
664
- return 'close';
665
- }
666
- if (event.name === 'backspace') { this.editor.backspace(); return 'handled'; }
667
- if (event.name === 'delete') { this.editor.deleteForward(); return 'handled'; }
668
- if (event.name === 'left') { this.editor.moveLeft(); return 'handled'; }
669
- if (event.name === 'right') { this.editor.moveRight(); return 'handled'; }
670
- if (event.name === 'home') { this.editor.moveHome(); return 'handled'; }
671
- if (event.name === 'end') { this.editor.moveEnd(); return 'handled'; }
672
- if (event.name === 'paste') { this.editor.insert(event.text); return 'handled'; }
673
- if (event.name === 'char') { this.editor.insert(event.text); return 'handled'; }
674
- return 'handled';
675
- }
676
-
677
- if (event.name === 'escape') { this.answer(null); return 'close'; }
678
- const count = this.options.length + 1;
679
- if (event.name === 'up') { this.selected = (this.selected - 1 + count) % count; return 'handled'; }
680
- if (event.name === 'down') { this.selected = (this.selected + 1) % count; return 'handled'; }
681
- if (event.name === 'enter' || event.name === 'return') {
682
- if (this.selected === this.customIndex) { this.customMode = true; return 'handled'; }
683
- const option = this.options[this.selected];
684
- if (!option) return 'handled';
685
- this.answer({ requestId: this.request.id, optionId: option.id, label: option.label, custom: false });
686
- return 'close';
687
- }
688
- return 'handled';
689
- }
690
-
691
- answer(value = null) {
692
- if (this.answered) return;
693
- this.answered = true;
694
- if (this.onAnswer) this.onAnswer(value);
695
- }
676
+ request;
677
+ onAnswer;
678
+ options;
679
+ selected;
680
+ customIndex;
681
+ customMode;
682
+ editor;
683
+ answered;
684
+ constructor(options = {}) {
685
+ const opts = options && typeof options === 'object' ? options : {};
686
+ super({ width: opts.width || 82, height: opts.height || 24, ...opts });
687
+ this.request = opts.request || {};
688
+ this.onAnswer = opts.onAnswer || null;
689
+ this.options = Array.isArray(this.request.options) ? this.request.options.slice(0, 4) : [];
690
+ this.selected = 0;
691
+ this.customIndex = this.options.length;
692
+ this.customMode = false;
693
+ this.editor = new LineEditor();
694
+ this.answered = false;
695
+ this.title = safeDisplay(this.request.header || 'decision required');
696
+ this.footer = `↑↓ choose ${GLYPHS.dot} enter select ${GLYPHS.dot} esc cancel`;
697
+ }
698
+ preferredHeight() {
699
+ const questionRows = wrap(safeDisplay(this.request.question || ''), Math.max(20, this.width - 6)).length;
700
+ const reasonRows = wrap(safeDisplay(this.request.reason || ''), Math.max(20, this.width - 6)).length;
701
+ return Math.min(this.height, questionRows + reasonRows + (this.options.length * 2) + 7);
702
+ }
703
+ body(width = 78, height = 22) {
704
+ const rows = [];
705
+ rows.push(...wrap(bold(safeDisplay(this.request.question || 'Choose a direction')), width).slice(0, 4));
706
+ if (this.request.reason)
707
+ rows.push(...wrap(dim(safeDisplay(this.request.reason)), width).slice(0, 3));
708
+ rows.push('');
709
+ for (const [index, option] of this.options.entries()) {
710
+ const selected = index === this.selected;
711
+ const marker = selected ? paint('accent', GLYPHS.arrow) : paint('muted', GLYPHS.dot);
712
+ rows.push(`${marker} ${selected ? bold(safeDisplay(option.label || '')) : safeDisplay(option.label || '')}`);
713
+ if (option.description)
714
+ rows.push(` ${dim(truncate(safeDisplay(option.description), Math.max(1, width - 2), GLYPHS.ellipsis))}`);
715
+ }
716
+ const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
717
+ const safeHeight = Number.isFinite(height) && height > 0 ? Math.floor(height) : rows.length + 2;
718
+ const customSelected = this.selected === this.customIndex;
719
+ rows.push(`${customSelected ? paint('accent', GLYPHS.arrow) : paint('muted', GLYPHS.dot)} ${customSelected ? bold('Type your own answer') : 'Type your own answer'}`);
720
+ if (this.customMode) {
721
+ const raw = this.editor.getText();
722
+ const value = cleanDialogText(raw);
723
+ rows.push(truncate(`${paint('accent', `${GLYPHS.arrow} `)}${value || dim('Describe the direction you want')}`, safeWidth, GLYPHS.ellipsis));
724
+ const rendered = rows.length > safeHeight ? rows.slice(rows.length - safeHeight) : rows;
725
+ const before = visibleWidth(cleanDialogText(raw.slice(0, this.editor.col)));
726
+ this.cursor = {
727
+ x: Math.min(Math.max(0, safeWidth - 1), 2 + before),
728
+ y: Math.max(0, rendered.length - 1)
729
+ };
730
+ this.footer = `enter submit ${GLYPHS.dot} esc choices`;
731
+ return rendered;
732
+ }
733
+ else {
734
+ this.cursor = null;
735
+ this.footer = `↑↓ choose ${GLYPHS.dot} enter select ${GLYPHS.dot} esc cancel`;
736
+ }
737
+ return rows.slice(0, safeHeight);
738
+ }
739
+ key(event) {
740
+ if (!event)
741
+ return null;
742
+ if (this.customMode) {
743
+ if (event.name === 'escape') {
744
+ this.customMode = false;
745
+ return 'handled';
746
+ }
747
+ if (event.name === 'enter' || event.name === 'return') {
748
+ const label = this.editor.getText().replace(/\s+/g, ' ').trim();
749
+ if (!label)
750
+ return 'handled';
751
+ this.answer({ requestId: this.request.id, optionId: null, label, custom: true });
752
+ return 'close';
753
+ }
754
+ if (event.name === 'backspace') {
755
+ this.editor.backspace();
756
+ return 'handled';
757
+ }
758
+ if (event.name === 'delete') {
759
+ this.editor.deleteForward();
760
+ return 'handled';
761
+ }
762
+ if (event.name === 'left') {
763
+ this.editor.moveLeft();
764
+ return 'handled';
765
+ }
766
+ if (event.name === 'right') {
767
+ this.editor.moveRight();
768
+ return 'handled';
769
+ }
770
+ if (event.name === 'home') {
771
+ this.editor.moveHome();
772
+ return 'handled';
773
+ }
774
+ if (event.name === 'end') {
775
+ this.editor.moveEnd();
776
+ return 'handled';
777
+ }
778
+ if (event.name === 'paste') {
779
+ const clean = safeDisplay(String(event.text || '')).replace(/[\r\n]+/g, ' ').slice(0, MAX_DIALOG_PASTE_CHARS);
780
+ if (clean)
781
+ this.editor.insert(clean);
782
+ return 'handled';
783
+ }
784
+ if (event.name === 'char') {
785
+ this.editor.insert(event.text);
786
+ return 'handled';
787
+ }
788
+ return 'handled';
789
+ }
790
+ if (event.name === 'escape') {
791
+ this.answer(null);
792
+ return 'close';
793
+ }
794
+ const count = this.options.length + 1;
795
+ if (event.name === 'up') {
796
+ this.selected = (this.selected - 1 + count) % count;
797
+ return 'handled';
798
+ }
799
+ if (event.name === 'down') {
800
+ this.selected = (this.selected + 1) % count;
801
+ return 'handled';
802
+ }
803
+ if (event.name === 'enter' || event.name === 'return') {
804
+ if (this.selected === this.customIndex) {
805
+ this.customMode = true;
806
+ return 'handled';
807
+ }
808
+ const option = this.options[this.selected];
809
+ if (!option)
810
+ return 'handled';
811
+ this.answer({ requestId: this.request.id, optionId: option.id, label: option.label, custom: false });
812
+ return 'close';
813
+ }
814
+ return 'handled';
815
+ }
816
+ answer(value = null) {
817
+ if (this.answered)
818
+ return;
819
+ this.answered = true;
820
+ if (this.onAnswer)
821
+ this.onAnswer(value);
822
+ }
696
823
  }
697
-
698
824
  /** A yes/no confirm, for destructive commands that are not tool approvals. */
699
825
  export class ConfirmLayer extends Layer {
700
- constructor(options = {}) {
701
- super({ width: options.width || 60, height: options.height || 8, ...options });
702
- this.message = options.message || 'Are you sure?';
703
- this.onAnswer = options.onAnswer || null;
704
- this.defaultAnswer = options.defaultAnswer === true;
705
- this.footer = this.defaultAnswer
706
- ? `enter confirm ${GLYPHS.dot} y yes ${GLYPHS.dot} n no ${GLYPHS.dot} esc cancel`
707
- : `enter cancel ${GLYPHS.dot} y yes ${GLYPHS.dot} n no ${GLYPHS.dot} esc cancel`;
708
- this.settled = false;
709
- }
710
-
711
- /**
712
- * Dismissal is an ANSWER, and the safe answer is no.
713
- *
714
- * ChatPrompt.closeLayer() calls this on any layer that defines it. Without it
715
- * a confirm torn down from outside — an interrupt, a resize teardown, the
716
- * host stopping — left its promise pending forever and hung the caller
717
- * mid-approval. The `settled` guard is what makes the y/n path and this path
718
- * safe to both fire.
719
- */
720
- answer(value = false) {
721
- if (this.settled) return;
722
- this.settled = true;
723
- if (this.onAnswer) this.onAnswer(Boolean(value));
724
- }
725
-
726
- preferredHeight() { return 6; }
727
-
728
- body(width) {
729
- this.cursor = null;
730
- return ['', ...wrap(paint('ink', safeDisplay(this.message)), width)];
731
- }
732
-
733
- key(event) {
734
- if (!event) return null;
735
- // `y` is always an explicit approval. Enter follows the default selected by
736
- // the caller: false for ordinary destructive confirmations, true only for
737
- // the second step after the user has already selected Allow always.
738
- if (isChar(event, 'y')) { this.answer(true); return 'close'; }
739
- if (isChar(event, 'n') || event.name === 'escape') { this.answer(false); return 'close'; }
740
- if (event.name === 'enter' || event.name === 'return') {
741
- this.answer(this.defaultAnswer);
742
- return 'close';
743
- }
744
- return 'handled';
745
- }
826
+ message;
827
+ onAnswer;
828
+ defaultAnswer;
829
+ settled;
830
+ constructor(options = {}) {
831
+ const opts = options && typeof options === 'object' ? options : {};
832
+ super({ width: opts.width || 60, height: opts.height || 8, ...opts });
833
+ this.message = opts.message || 'Are you sure?';
834
+ this.onAnswer = opts.onAnswer || null;
835
+ this.defaultAnswer = opts.defaultAnswer === true;
836
+ this.footer = this.defaultAnswer
837
+ ? `enter confirm ${GLYPHS.dot} y yes ${GLYPHS.dot} n no ${GLYPHS.dot} esc cancel`
838
+ : `enter cancel ${GLYPHS.dot} y yes ${GLYPHS.dot} n no ${GLYPHS.dot} esc cancel`;
839
+ this.settled = false;
840
+ }
841
+ /**
842
+ * Dismissal is an ANSWER, and the safe answer is no.
843
+ *
844
+ * ChatPrompt.closeLayer() calls this on any layer that defines it. Without it
845
+ * a confirm torn down from outside — an interrupt, a resize teardown, the
846
+ * host stopping — left its promise pending forever and hung the caller
847
+ * mid-approval. The `settled` guard is what makes the y/n path and this path
848
+ * safe to both fire.
849
+ */
850
+ answer(value = false) {
851
+ if (this.settled)
852
+ return;
853
+ this.settled = true;
854
+ if (this.onAnswer)
855
+ this.onAnswer(Boolean(value));
856
+ }
857
+ preferredHeight() { return 6; }
858
+ body(width = 56) {
859
+ this.cursor = null;
860
+ return ['', ...wrap(paint('ink', safeDisplay(this.message)), width)];
861
+ }
862
+ key(event) {
863
+ if (!event)
864
+ return null;
865
+ // `y` is always an explicit approval. Enter follows the default selected by
866
+ // the caller: false for ordinary destructive confirmations, true only for
867
+ // the second step after the user has already selected Allow always.
868
+ if (isChar(event, 'y')) {
869
+ this.answer(true);
870
+ return 'close';
871
+ }
872
+ if (isChar(event, 'n') || event.name === 'escape') {
873
+ this.answer(false);
874
+ return 'close';
875
+ }
876
+ if (event.name === 'enter' || event.name === 'return') {
877
+ this.answer(this.defaultAnswer);
878
+ return 'close';
879
+ }
880
+ return 'handled';
881
+ }
746
882
  }
747
-
748
883
  /** The command palette — every command in the app, fuzzy-searchable. */
749
884
  export function commandPalette(commands, onRun) {
750
- const safeCommands = Array.isArray(commands) ? commands.filter(Boolean) : [];
751
- return new SelectLayer({
752
- title: 'commands',
753
- placeholder: 'search commands',
754
- emptyText: 'no command matches',
755
- width: 72,
756
- height: 20,
757
- items: safeCommands.map((command) => ({
758
- label: cleanDialogText(command.name || ''),
759
- description: cleanDialogText(command.description || ''),
760
- category: cleanDialogText(command.category || ''),
761
- hint: cleanDialogText(command.hint || ''),
762
- searchText: cleanDialogText(command.description || ''),
763
- value: command
764
- })),
765
- onPick: (item) => { if (item && onRun) onRun(item.value); }
766
- });
885
+ const safeCommands = Array.isArray(commands) ? commands.filter(Boolean) : [];
886
+ return new SelectLayer({
887
+ title: 'commands',
888
+ placeholder: 'search commands',
889
+ emptyText: 'no command matches',
890
+ width: 72,
891
+ height: 20,
892
+ items: safeCommands.map((command) => ({
893
+ label: cleanDialogText(command.name || ''),
894
+ description: cleanDialogText(command.description || ''),
895
+ category: cleanDialogText(command.category || ''),
896
+ hint: cleanDialogText(command.hint || ''),
897
+ searchText: cleanDialogText(command.description || ''),
898
+ value: command
899
+ })),
900
+ onPick: (item) => { if (item && onRun)
901
+ onRun(item.value); }
902
+ });
767
903
  }
768
-
769
904
  /**
770
905
  * The skill browser: 100 skills, fuzzy-searchable, grouped by domain.
771
906
  *
@@ -777,55 +912,54 @@ export function commandPalette(commands, onRun) {
777
912
  * the pane rather than to the terminal, so overflow is structurally impossible.
778
913
  */
779
914
  export function skillPicker(skills, onOpen) {
780
- const safeSkills = Array.isArray(skills) ? skills.filter(Boolean) : [];
781
- return new SelectLayer({
782
- title: `skills (${safeSkills.length})`,
783
- placeholder: 'search skills',
784
- emptyText: 'no skill matches',
785
- width: 76,
786
- height: 22,
787
- items: safeSkills.map((skill) => ({
788
- label: `${cleanDialogText(skill.domain || '')}/${cleanDialogText(skill.id || '')}`,
789
- description: cleanDialogText(skill.description || ''),
790
- category: cleanDialogText(skill.domain || ''),
791
- searchText: cleanDialogText(`${skill.name || ''} ${skill.description || ''}`),
792
- value: skill
793
- })),
794
- onPick: (item) => { if (item && onOpen) onOpen(item.value); }
795
- });
915
+ const safeSkills = Array.isArray(skills) ? skills.filter(Boolean) : [];
916
+ return new SelectLayer({
917
+ title: `skills (${safeSkills.length})`,
918
+ placeholder: 'search skills',
919
+ emptyText: 'no skill matches',
920
+ width: 76,
921
+ height: 22,
922
+ items: safeSkills.map((skill) => ({
923
+ label: `${cleanDialogText(skill.domain || '')}/${cleanDialogText(skill.id || '')}`,
924
+ description: cleanDialogText(skill.description || ''),
925
+ category: cleanDialogText(skill.domain || ''),
926
+ searchText: cleanDialogText(`${skill.name || ''} ${skill.description || ''}`),
927
+ value: skill
928
+ })),
929
+ onPick: (item) => { if (item && onOpen)
930
+ onOpen(item.value); }
931
+ });
796
932
  }
797
-
798
933
  /** Help: the keys, grouped, in a scrolling pane. */
799
934
  export function helpLayer(sections) {
800
- const safeSections = Array.isArray(sections) ? sections.filter(Boolean) : [];
801
- const lines = [];
802
- for (const section of safeSections) {
803
- lines.push(bold(paint('ink', cleanDialogText(section.title || ''))));
804
- const rows = Array.isArray(section.rows) ? section.rows : [];
805
- for (const pair of rows) {
806
- if (!Array.isArray(pair)) continue;
807
- const keys = cleanDialogText(pair[0] || '');
808
- const what = cleanDialogText(pair[1] || '');
809
- lines.push(` ${paint('accent', keys.padEnd(18))}${dim(what)}`);
810
- }
811
- lines.push('');
812
- }
813
- return new TextLayer({ title: 'keys', lines, width: 62, height: Math.min(24, lines.length + 3) });
935
+ const safeSections = Array.isArray(sections) ? sections.filter(Boolean) : [];
936
+ const lines = [];
937
+ for (const section of safeSections) {
938
+ lines.push(bold(paint('ink', cleanDialogText(section.title || ''))));
939
+ const rows = Array.isArray(section.rows) ? section.rows : [];
940
+ for (const pair of rows) {
941
+ if (!Array.isArray(pair))
942
+ continue;
943
+ const keys = cleanDialogText(pair[0] || '');
944
+ const what = cleanDialogText(pair[1] || '');
945
+ lines.push(` ${paint('accent', keys.padEnd(18))}${dim(what)}`);
946
+ }
947
+ lines.push('');
948
+ }
949
+ return new TextLayer({ title: 'keys', lines, width: 62, height: Math.min(24, lines.length + 3) });
814
950
  }
815
-
816
951
  /** A status pane: session facts that would otherwise need a scrollback hunt. */
817
952
  export function statusLayer(rows) {
818
- const safeRows = (Array.isArray(rows) ? rows : []).filter(row => Array.isArray(row));
819
- const labels = safeRows.map(row => cleanDialogText(row[0] == null ? '' : String(row[0])));
820
- const width = labels.reduce((max, label) => Math.max(max, label.length), 0);
821
- const lines = safeRows.map((row, index) => {
822
- const label = labels[index];
823
- const value = cleanDialogText(row[1] == null ? '' : String(row[1]));
824
- return label === ''
825
- ? ''
826
- : `${paint('muted', label.padEnd(width + 2))}${paint('ink', value)}`;
827
- });
828
- return new TextLayer({ title: 'session', lines, width: 74, height: Math.min(24, lines.length + 3) });
953
+ const safeRows = (Array.isArray(rows) ? rows : []).filter((row) => Array.isArray(row));
954
+ const labels = safeRows.map(row => cleanDialogText(row[0] == null ? '' : String(row[0])));
955
+ const width = labels.reduce((max, label) => Math.max(max, label.length), 0);
956
+ const lines = safeRows.map((row, index) => {
957
+ const label = labels[index] ?? '';
958
+ const value = cleanDialogText(row[1] == null ? '' : String(row[1]));
959
+ return label === ''
960
+ ? ''
961
+ : `${paint('muted', label.padEnd(width + 2))}${paint('ink', value)}`;
962
+ });
963
+ return new TextLayer({ title: 'session', lines, width: 74, height: Math.min(24, lines.length + 3) });
829
964
  }
830
-
831
965
  export { visibleWidth };