@bastani/atomic 0.8.10 → 0.8.12-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (514) hide show
  1. package/CHANGELOG.md +29 -2
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/CHANGELOG.md +3 -0
  5. package/dist/builtin/subagents/package.json +1 -1
  6. package/dist/builtin/subagents/src/agents/agent-serializer.ts +3 -2
  7. package/dist/builtin/subagents/src/agents/agents.ts +1 -1
  8. package/dist/builtin/subagents/src/extension/index.ts +597 -471
  9. package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +16 -8
  10. package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +9 -13
  11. package/dist/builtin/subagents/src/runs/foreground/execution.ts +7 -3
  12. package/dist/builtin/subagents/src/shared/formatters.ts +8 -3
  13. package/dist/builtin/subagents/src/slash/slash-commands.ts +625 -468
  14. package/dist/builtin/subagents/src/tui/render.ts +342 -158
  15. package/dist/builtin/web-access/package.json +1 -1
  16. package/dist/builtin/workflows/package.json +1 -1
  17. package/dist/builtin/workflows/src/runs/foreground/executor.ts +15 -4
  18. package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +75 -33
  19. package/dist/builtin/workflows/src/shared/store-types.ts +3 -4
  20. package/dist/builtin/workflows/src/shared/store.ts +2 -3
  21. package/dist/builtin/workflows/src/tui/graph-view.ts +12 -1
  22. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +1 -2
  23. package/dist/builtin/workflows/src/tui/status-helpers.ts +1 -1
  24. package/dist/bun/cli.d.ts.map +1 -1
  25. package/dist/bun/cli.js.map +1 -1
  26. package/dist/cli/args.d.ts +1 -1
  27. package/dist/cli/args.d.ts.map +1 -1
  28. package/dist/cli/args.js.map +1 -1
  29. package/dist/cli/config-selector.d.ts +2 -2
  30. package/dist/cli/config-selector.d.ts.map +1 -1
  31. package/dist/cli/config-selector.js.map +1 -1
  32. package/dist/cli/file-processor.d.ts.map +1 -1
  33. package/dist/cli/file-processor.js.map +1 -1
  34. package/dist/cli/initial-message.d.ts +1 -1
  35. package/dist/cli/initial-message.d.ts.map +1 -1
  36. package/dist/cli/initial-message.js.map +1 -1
  37. package/dist/cli/list-models.d.ts +1 -1
  38. package/dist/cli/list-models.d.ts.map +1 -1
  39. package/dist/cli/list-models.js.map +1 -1
  40. package/dist/cli/session-picker.d.ts +1 -1
  41. package/dist/cli/session-picker.d.ts.map +1 -1
  42. package/dist/cli/session-picker.js.map +1 -1
  43. package/dist/cli.d.ts.map +1 -1
  44. package/dist/cli.js +2 -6
  45. package/dist/cli.js.map +1 -1
  46. package/dist/config.d.ts.map +1 -1
  47. package/dist/config.js +45 -22
  48. package/dist/config.js.map +1 -1
  49. package/dist/core/agent-session-runtime.d.ts +9 -9
  50. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  51. package/dist/core/agent-session-runtime.js +2 -3
  52. package/dist/core/agent-session-runtime.js.map +1 -1
  53. package/dist/core/agent-session-services.d.ts +7 -7
  54. package/dist/core/agent-session-services.d.ts.map +1 -1
  55. package/dist/core/agent-session-services.js.map +1 -1
  56. package/dist/core/agent-session.d.ts +10 -10
  57. package/dist/core/agent-session.d.ts.map +1 -1
  58. package/dist/core/agent-session.js.map +1 -1
  59. package/dist/core/atomic-guide-command.d.ts.map +1 -1
  60. package/dist/core/atomic-guide-command.js.map +1 -1
  61. package/dist/core/auth-guidance.d.ts.map +1 -1
  62. package/dist/core/auth-guidance.js.map +1 -1
  63. package/dist/core/auth-storage.d.ts +1 -1
  64. package/dist/core/auth-storage.d.ts.map +1 -1
  65. package/dist/core/auth-storage.js +1 -1
  66. package/dist/core/auth-storage.js.map +1 -1
  67. package/dist/core/bash-executor.d.ts +1 -1
  68. package/dist/core/bash-executor.d.ts.map +1 -1
  69. package/dist/core/bash-executor.js.map +1 -1
  70. package/dist/core/builtin-packages.d.ts.map +1 -1
  71. package/dist/core/builtin-packages.js.map +1 -1
  72. package/dist/core/compaction/branch-summarization.d.ts +3 -3
  73. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  74. package/dist/core/compaction/branch-summarization.js.map +1 -1
  75. package/dist/core/compaction/compaction.d.ts +2 -2
  76. package/dist/core/compaction/compaction.d.ts.map +1 -1
  77. package/dist/core/compaction/compaction.js.map +1 -1
  78. package/dist/core/compaction/index.d.ts +3 -3
  79. package/dist/core/compaction/index.d.ts.map +1 -1
  80. package/dist/core/compaction/index.js.map +1 -1
  81. package/dist/core/exec.d.ts.map +1 -1
  82. package/dist/core/exec.js.map +1 -1
  83. package/dist/core/export-html/index.d.ts +1 -1
  84. package/dist/core/export-html/index.d.ts.map +1 -1
  85. package/dist/core/export-html/index.js.map +1 -1
  86. package/dist/core/export-html/tool-renderer.d.ts +2 -2
  87. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  88. package/dist/core/export-html/tool-renderer.js.map +1 -1
  89. package/dist/core/extensions/index.d.ts +8 -8
  90. package/dist/core/extensions/index.d.ts.map +1 -1
  91. package/dist/core/extensions/index.js.map +1 -1
  92. package/dist/core/extensions/loader.d.ts +3 -3
  93. package/dist/core/extensions/loader.d.ts.map +1 -1
  94. package/dist/core/extensions/loader.js.map +1 -1
  95. package/dist/core/extensions/runner.d.ts +6 -6
  96. package/dist/core/extensions/runner.d.ts.map +1 -1
  97. package/dist/core/extensions/runner.js.map +1 -1
  98. package/dist/core/extensions/types.d.ts +20 -20
  99. package/dist/core/extensions/types.d.ts.map +1 -1
  100. package/dist/core/extensions/types.js.map +1 -1
  101. package/dist/core/extensions/wrapper.d.ts +2 -2
  102. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  103. package/dist/core/extensions/wrapper.js.map +1 -1
  104. package/dist/core/footer-data-provider.d.ts.map +1 -1
  105. package/dist/core/footer-data-provider.js.map +1 -1
  106. package/dist/core/http-dispatcher.d.ts +32 -0
  107. package/dist/core/http-dispatcher.d.ts.map +1 -0
  108. package/dist/core/http-dispatcher.js +43 -0
  109. package/dist/core/http-dispatcher.js.map +1 -0
  110. package/dist/core/index.d.ts +8 -8
  111. package/dist/core/index.d.ts.map +1 -1
  112. package/dist/core/index.js.map +1 -1
  113. package/dist/core/keybindings.d.ts.map +1 -1
  114. package/dist/core/keybindings.js.map +1 -1
  115. package/dist/core/model-registry.d.ts +4 -4
  116. package/dist/core/model-registry.d.ts.map +1 -1
  117. package/dist/core/model-registry.js +2 -2
  118. package/dist/core/model-registry.js.map +1 -1
  119. package/dist/core/model-resolver.d.ts +1 -1
  120. package/dist/core/model-resolver.d.ts.map +1 -1
  121. package/dist/core/model-resolver.js.map +1 -1
  122. package/dist/core/package-manager.d.ts +1 -1
  123. package/dist/core/package-manager.d.ts.map +1 -1
  124. package/dist/core/package-manager.js +10 -11
  125. package/dist/core/package-manager.js.map +1 -1
  126. package/dist/core/prompt-templates.d.ts +1 -1
  127. package/dist/core/prompt-templates.d.ts.map +1 -1
  128. package/dist/core/prompt-templates.js.map +1 -1
  129. package/dist/core/resolve-config-value.d.ts.map +1 -1
  130. package/dist/core/resolve-config-value.js.map +1 -1
  131. package/dist/core/resource-loader.d.ts +9 -9
  132. package/dist/core/resource-loader.d.ts.map +1 -1
  133. package/dist/core/resource-loader.js.map +1 -1
  134. package/dist/core/sdk.d.ts +13 -13
  135. package/dist/core/sdk.d.ts.map +1 -1
  136. package/dist/core/sdk.js.map +1 -1
  137. package/dist/core/session-manager.d.ts +1 -1
  138. package/dist/core/session-manager.d.ts.map +1 -1
  139. package/dist/core/session-manager.js.map +1 -1
  140. package/dist/core/settings-manager.d.ts +3 -0
  141. package/dist/core/settings-manager.d.ts.map +1 -1
  142. package/dist/core/settings-manager.js +21 -0
  143. package/dist/core/settings-manager.js.map +1 -1
  144. package/dist/core/skills.d.ts +2 -2
  145. package/dist/core/skills.d.ts.map +1 -1
  146. package/dist/core/skills.js.map +1 -1
  147. package/dist/core/slash-commands.d.ts +1 -1
  148. package/dist/core/slash-commands.d.ts.map +1 -1
  149. package/dist/core/slash-commands.js.map +1 -1
  150. package/dist/core/source-info.d.ts +1 -1
  151. package/dist/core/source-info.d.ts.map +1 -1
  152. package/dist/core/source-info.js.map +1 -1
  153. package/dist/core/system-prompt.d.ts +1 -1
  154. package/dist/core/system-prompt.d.ts.map +1 -1
  155. package/dist/core/system-prompt.js +7 -8
  156. package/dist/core/system-prompt.js.map +1 -1
  157. package/dist/core/telemetry.d.ts +1 -1
  158. package/dist/core/telemetry.d.ts.map +1 -1
  159. package/dist/core/telemetry.js.map +1 -1
  160. package/dist/core/timings.d.ts.map +1 -1
  161. package/dist/core/timings.js.map +1 -1
  162. package/dist/core/tools/ask-user-question/ask-user-question.d.ts +4 -4
  163. package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
  164. package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
  165. package/dist/core/tools/ask-user-question/index.d.ts +1 -1
  166. package/dist/core/tools/ask-user-question/index.d.ts.map +1 -1
  167. package/dist/core/tools/ask-user-question/index.js.map +1 -1
  168. package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts +5 -5
  169. package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts.map +1 -1
  170. package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -1
  171. package/dist/core/tools/ask-user-question/state/key-router.d.ts +2 -2
  172. package/dist/core/tools/ask-user-question/state/key-router.d.ts.map +1 -1
  173. package/dist/core/tools/ask-user-question/state/key-router.js.map +1 -1
  174. package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts +3 -3
  175. package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -1
  176. package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
  177. package/dist/core/tools/ask-user-question/state/row-intent.d.ts +2 -2
  178. package/dist/core/tools/ask-user-question/state/row-intent.d.ts.map +1 -1
  179. package/dist/core/tools/ask-user-question/state/row-intent.js.map +1 -1
  180. package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts +6 -6
  181. package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts.map +1 -1
  182. package/dist/core/tools/ask-user-question/state/selectors/contract.js.map +1 -1
  183. package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts +2 -2
  184. package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts.map +1 -1
  185. package/dist/core/tools/ask-user-question/state/selectors/derivations.js.map +1 -1
  186. package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts +1 -1
  187. package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts.map +1 -1
  188. package/dist/core/tools/ask-user-question/state/selectors/focus.js.map +1 -1
  189. package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts +8 -8
  190. package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -1
  191. package/dist/core/tools/ask-user-question/state/selectors/projections.js.map +1 -1
  192. package/dist/core/tools/ask-user-question/state/state-reducer.d.ts +4 -4
  193. package/dist/core/tools/ask-user-question/state/state-reducer.d.ts.map +1 -1
  194. package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -1
  195. package/dist/core/tools/ask-user-question/state/state.d.ts +2 -2
  196. package/dist/core/tools/ask-user-question/state/state.d.ts.map +1 -1
  197. package/dist/core/tools/ask-user-question/state/state.js.map +1 -1
  198. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +1 -1
  199. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -1
  200. package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -1
  201. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +1 -1
  202. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -1
  203. package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -1
  204. package/dist/core/tools/ask-user-question/tool/types.d.ts.map +1 -1
  205. package/dist/core/tools/ask-user-question/tool/types.js.map +1 -1
  206. package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts +1 -1
  207. package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts.map +1 -1
  208. package/dist/core/tools/ask-user-question/tool/validate-questionnaire.js.map +1 -1
  209. package/dist/core/tools/ask-user-question/view/body-residual-spacer.d.ts.map +1 -1
  210. package/dist/core/tools/ask-user-question/view/body-residual-spacer.js.map +1 -1
  211. package/dist/core/tools/ask-user-question/view/component-binding.d.ts +4 -4
  212. package/dist/core/tools/ask-user-question/view/component-binding.d.ts.map +1 -1
  213. package/dist/core/tools/ask-user-question/view/component-binding.js.map +1 -1
  214. package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts +2 -2
  215. package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts.map +1 -1
  216. package/dist/core/tools/ask-user-question/view/components/chat-row-view.js.map +1 -1
  217. package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts +4 -4
  218. package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
  219. package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
  220. package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts +2 -2
  221. package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts.map +1 -1
  222. package/dist/core/tools/ask-user-question/view/components/option-list-view.js.map +1 -1
  223. package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts +2 -2
  224. package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts.map +1 -1
  225. package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.js.map +1 -1
  226. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +3 -3
  227. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -1
  228. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
  229. package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts +2 -2
  230. package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts.map +1 -1
  231. package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.js.map +1 -1
  232. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts +8 -8
  233. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts.map +1 -1
  234. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js.map +1 -1
  235. package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts +3 -3
  236. package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts.map +1 -1
  237. package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -1
  238. package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts +3 -3
  239. package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts.map +1 -1
  240. package/dist/core/tools/ask-user-question/view/components/tab-bar.js.map +1 -1
  241. package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts +8 -8
  242. package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts.map +1 -1
  243. package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -1
  244. package/dist/core/tools/ask-user-question/view/props-adapter.d.ts +5 -5
  245. package/dist/core/tools/ask-user-question/view/props-adapter.d.ts.map +1 -1
  246. package/dist/core/tools/ask-user-question/view/props-adapter.js.map +1 -1
  247. package/dist/core/tools/ask-user-question/view/tab-components.d.ts +4 -4
  248. package/dist/core/tools/ask-user-question/view/tab-components.d.ts.map +1 -1
  249. package/dist/core/tools/ask-user-question/view/tab-components.js.map +1 -1
  250. package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts +9 -9
  251. package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts.map +1 -1
  252. package/dist/core/tools/ask-user-question/view/tab-content-strategy.js +2 -2
  253. package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -1
  254. package/dist/core/tools/bash.d.ts +2 -2
  255. package/dist/core/tools/bash.d.ts.map +1 -1
  256. package/dist/core/tools/bash.js +9 -1
  257. package/dist/core/tools/bash.js.map +1 -1
  258. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  259. package/dist/core/tools/edit-diff.js.map +1 -1
  260. package/dist/core/tools/edit.d.ts +2 -2
  261. package/dist/core/tools/edit.d.ts.map +1 -1
  262. package/dist/core/tools/edit.js.map +1 -1
  263. package/dist/core/tools/find.d.ts +2 -2
  264. package/dist/core/tools/find.d.ts.map +1 -1
  265. package/dist/core/tools/find.js.map +1 -1
  266. package/dist/core/tools/grep.d.ts +2 -2
  267. package/dist/core/tools/grep.d.ts.map +1 -1
  268. package/dist/core/tools/grep.js.map +1 -1
  269. package/dist/core/tools/index.d.ts +19 -19
  270. package/dist/core/tools/index.d.ts.map +1 -1
  271. package/dist/core/tools/index.js.map +1 -1
  272. package/dist/core/tools/ls.d.ts +2 -2
  273. package/dist/core/tools/ls.d.ts.map +1 -1
  274. package/dist/core/tools/ls.js.map +1 -1
  275. package/dist/core/tools/output-accumulator.d.ts +1 -1
  276. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  277. package/dist/core/tools/output-accumulator.js.map +1 -1
  278. package/dist/core/tools/read.d.ts +2 -2
  279. package/dist/core/tools/read.d.ts.map +1 -1
  280. package/dist/core/tools/read.js.map +1 -1
  281. package/dist/core/tools/render-utils.d.ts +1 -1
  282. package/dist/core/tools/render-utils.d.ts.map +1 -1
  283. package/dist/core/tools/render-utils.js.map +1 -1
  284. package/dist/core/tools/todos.d.ts +1 -1
  285. package/dist/core/tools/todos.d.ts.map +1 -1
  286. package/dist/core/tools/todos.js.map +1 -1
  287. package/dist/core/tools/tool-definition-wrapper.d.ts +1 -1
  288. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  289. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  290. package/dist/core/tools/write.d.ts +1 -1
  291. package/dist/core/tools/write.d.ts.map +1 -1
  292. package/dist/core/tools/write.js.map +1 -1
  293. package/dist/index.d.ts +30 -29
  294. package/dist/index.d.ts.map +1 -1
  295. package/dist/index.js +1 -0
  296. package/dist/index.js.map +1 -1
  297. package/dist/main.d.ts +1 -1
  298. package/dist/main.d.ts.map +1 -1
  299. package/dist/main.js +2 -0
  300. package/dist/main.js.map +1 -1
  301. package/dist/migrations.d.ts.map +1 -1
  302. package/dist/migrations.js.map +1 -1
  303. package/dist/modes/index.d.ts +5 -5
  304. package/dist/modes/index.d.ts.map +1 -1
  305. package/dist/modes/index.js.map +1 -1
  306. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  307. package/dist/modes/interactive/components/armin.js.map +1 -1
  308. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  309. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  310. package/dist/modes/interactive/components/atomic-banner.d.ts +1 -1
  311. package/dist/modes/interactive/components/atomic-banner.d.ts.map +1 -1
  312. package/dist/modes/interactive/components/atomic-banner.js.map +1 -1
  313. package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
  314. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  315. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  316. package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
  317. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  318. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  319. package/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
  320. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  321. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  322. package/dist/modes/interactive/components/chat-message-renderer.d.ts +3 -3
  323. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  324. package/dist/modes/interactive/components/chat-message-renderer.js +1 -1
  325. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  326. package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
  327. package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
  328. package/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
  329. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  330. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  331. package/dist/modes/interactive/components/config-selector.d.ts +2 -2
  332. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  333. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  334. package/dist/modes/interactive/components/countdown-timer.d.ts +2 -2
  335. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  336. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  337. package/dist/modes/interactive/components/custom-editor.d.ts +1 -1
  338. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  339. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  340. package/dist/modes/interactive/components/custom-message.d.ts +2 -2
  341. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  342. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  343. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  344. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  345. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  346. package/dist/modes/interactive/components/diff.js.map +1 -1
  347. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  348. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  349. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  350. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  351. package/dist/modes/interactive/components/extension-editor.d.ts +1 -1
  352. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  353. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  354. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  355. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  356. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  357. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  358. package/dist/modes/interactive/components/footer.d.ts +3 -3
  359. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  360. package/dist/modes/interactive/components/footer.js +1 -1
  361. package/dist/modes/interactive/components/footer.js.map +1 -1
  362. package/dist/modes/interactive/components/index.d.ts +34 -34
  363. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  364. package/dist/modes/interactive/components/index.js.map +1 -1
  365. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  366. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  367. package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
  368. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  369. package/dist/modes/interactive/components/login-dialog.js +1 -1
  370. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  371. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  372. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  373. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  374. package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
  375. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  376. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  377. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  378. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  379. package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
  380. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  381. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  382. package/dist/modes/interactive/components/session-selector.d.ts +3 -3
  383. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  384. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  385. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  386. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  387. package/dist/modes/interactive/components/settings-selector.js +13 -0
  388. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  389. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  390. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  391. package/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
  392. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  393. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  394. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  395. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  396. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  397. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  398. package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
  399. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  400. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  401. package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
  402. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  403. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  404. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  405. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  406. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  407. package/dist/modes/interactive/components/user-message.js.map +1 -1
  408. package/dist/modes/interactive/components/working-status.d.ts.map +1 -1
  409. package/dist/modes/interactive/components/working-status.js.map +1 -1
  410. package/dist/modes/interactive/interactive-mode.d.ts +2 -2
  411. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  412. package/dist/modes/interactive/interactive-mode.js +7 -1
  413. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  414. package/dist/modes/interactive/theme/theme.d.ts +1 -1
  415. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  416. package/dist/modes/interactive/theme/theme.js.map +1 -1
  417. package/dist/modes/print-mode.d.ts +1 -1
  418. package/dist/modes/print-mode.d.ts.map +1 -1
  419. package/dist/modes/print-mode.js.map +1 -1
  420. package/dist/modes/rpc/rpc-client.d.ts +5 -5
  421. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  422. package/dist/modes/rpc/rpc-client.js +1 -1
  423. package/dist/modes/rpc/rpc-client.js.map +1 -1
  424. package/dist/modes/rpc/rpc-mode.d.ts +2 -2
  425. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  426. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  427. package/dist/modes/rpc/rpc-types.d.ts +4 -4
  428. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  429. package/dist/modes/rpc/rpc-types.js.map +1 -1
  430. package/dist/package-manager-cli.d.ts.map +1 -1
  431. package/dist/package-manager-cli.js +22 -6
  432. package/dist/package-manager-cli.js.map +1 -1
  433. package/dist/utils/changelog.d.ts +1 -1
  434. package/dist/utils/changelog.d.ts.map +1 -1
  435. package/dist/utils/changelog.js.map +1 -1
  436. package/dist/utils/child-process.d.ts +5 -2
  437. package/dist/utils/child-process.d.ts.map +1 -1
  438. package/dist/utils/child-process.js +9 -7
  439. package/dist/utils/child-process.js.map +1 -1
  440. package/dist/utils/clipboard-image.d.ts.map +1 -1
  441. package/dist/utils/clipboard-image.js.map +1 -1
  442. package/dist/utils/clipboard.d.ts.map +1 -1
  443. package/dist/utils/clipboard.js.map +1 -1
  444. package/dist/utils/exif-orientation.d.ts +1 -1
  445. package/dist/utils/exif-orientation.d.ts.map +1 -1
  446. package/dist/utils/exif-orientation.js.map +1 -1
  447. package/dist/utils/image-convert.d.ts.map +1 -1
  448. package/dist/utils/image-convert.js.map +1 -1
  449. package/dist/utils/image-resize.d.ts.map +1 -1
  450. package/dist/utils/image-resize.js.map +1 -1
  451. package/dist/utils/shell.d.ts.map +1 -1
  452. package/dist/utils/shell.js.map +1 -1
  453. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  454. package/dist/utils/syntax-highlight.js.map +1 -1
  455. package/dist/utils/tools-manager.d.ts.map +1 -1
  456. package/dist/utils/tools-manager.js.map +1 -1
  457. package/dist/utils/version-check.d.ts.map +1 -1
  458. package/dist/utils/version-check.js.map +1 -1
  459. package/dist/utils/windows-self-update.d.ts +3 -0
  460. package/dist/utils/windows-self-update.d.ts.map +1 -0
  461. package/dist/utils/windows-self-update.js +78 -0
  462. package/dist/utils/windows-self-update.js.map +1 -0
  463. package/docs/compaction.md +5 -5
  464. package/docs/custom-provider.md +2 -2
  465. package/docs/development.md +22 -16
  466. package/docs/docs.json +6 -2
  467. package/docs/extensions.md +25 -25
  468. package/docs/index.md +11 -14
  469. package/docs/keybindings.md +5 -5
  470. package/docs/models.md +6 -6
  471. package/docs/packages.md +55 -48
  472. package/docs/prompt-templates.md +5 -5
  473. package/docs/providers.md +10 -10
  474. package/docs/quickstart.md +32 -30
  475. package/docs/rpc.md +9 -9
  476. package/docs/sdk.md +1 -1
  477. package/docs/session-format.md +3 -3
  478. package/docs/sessions.md +11 -11
  479. package/docs/settings.md +18 -15
  480. package/docs/shell-aliases.md +2 -2
  481. package/docs/skills.md +11 -11
  482. package/docs/terminal-setup.md +8 -8
  483. package/docs/termux.md +6 -6
  484. package/docs/themes.md +10 -10
  485. package/docs/tui.md +5 -4
  486. package/docs/usage.md +50 -50
  487. package/docs/windows.md +2 -2
  488. package/docs/workflows.md +695 -0
  489. package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
  490. package/examples/extensions/doom-overlay/doom-component.ts +2 -2
  491. package/examples/extensions/doom-overlay/index.ts +3 -3
  492. package/examples/extensions/overlay-qa-tests.ts +116 -33
  493. package/examples/extensions/overlay-test.ts +9 -3
  494. package/examples/extensions/plan-mode/index.ts +1 -1
  495. package/examples/extensions/subagent/index.ts +1159 -903
  496. package/package.json +6 -4
  497. package/dist/builtin/workflows/skills/workflow/SKILL.md +0 -322
  498. package/dist/builtin/workflows/skills/workflow/references/context-engineering/advanced-evaluation.md +0 -404
  499. package/dist/builtin/workflows/skills/workflow/references/context-engineering/bdi-mental-states.md +0 -313
  500. package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-compression.md +0 -274
  501. package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-degradation.md +0 -208
  502. package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-fundamentals.md +0 -203
  503. package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-optimization.md +0 -197
  504. package/dist/builtin/workflows/skills/workflow/references/context-engineering/evaluation.md +0 -253
  505. package/dist/builtin/workflows/skills/workflow/references/context-engineering/filesystem-context.md +0 -289
  506. package/dist/builtin/workflows/skills/workflow/references/context-engineering/hosted-agents.md +0 -262
  507. package/dist/builtin/workflows/skills/workflow/references/context-engineering/memory-systems.md +0 -221
  508. package/dist/builtin/workflows/skills/workflow/references/context-engineering/multi-agent-patterns.md +0 -259
  509. package/dist/builtin/workflows/skills/workflow/references/context-engineering/project-development.md +0 -293
  510. package/dist/builtin/workflows/skills/workflow/references/context-engineering/tool-design.md +0 -273
  511. package/dist/builtin/workflows/skills/workflow/references/context-engineering.md +0 -23
  512. package/dist/builtin/workflows/skills/workflow/references/design-checklist.md +0 -83
  513. package/dist/builtin/workflows/skills/workflow/references/running-workflows.md +0 -159
  514. package/dist/builtin/workflows/skills/workflow/references/sdk-authoring.md +0 -260
@@ -1,7 +1,7 @@
1
- import type { ToolDefinition } from "../../extensions/types.js";
2
- import { buildQuestionnaireResponse, buildToolResult } from "./tool/response-envelope.js";
3
- import { type QuestionData, QuestionParamsSchema } from "./tool/types.js";
4
- import type { WrappingSelectItem } from "./view/components/wrapping-select.js";
1
+ import type { ToolDefinition } from "../../extensions/types.ts";
2
+ import { buildQuestionnaireResponse, buildToolResult } from "./tool/response-envelope.ts";
3
+ import { type QuestionData, QuestionParamsSchema } from "./tool/types.ts";
4
+ import type { WrappingSelectItem } from "./view/components/wrapping-select.ts";
5
5
  export declare function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[];
6
6
  export declare const DEFAULT_PROMPT_SNIPPET = "Ask the user up to 4 structured questions (2-4 options each) when requirements are ambiguous";
7
7
  export declare const DEFAULT_PROMPT_GUIDELINES: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"ask-user-question.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIhE,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAIN,KAAK,YAAY,EAGjB,oBAAoB,EACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAI/E,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,YAAY,GAAG,kBAAkB,EAAE,CAWlF;AAED,eAAO,MAAM,sBAAsB,iGAA0I,CAAC;AAC9K,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAK7C,CAAC;AAEF,wBAAgB,mCAAmC,IAAI,cAAc,CAAC,OAAO,oBAAoB,EAAE,OAAO,CAAC,CAyD1G;AAED,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { ToolDefinition } from \"../../extensions/types.js\";\nimport { loadConfig, validateGuidanceFields } from \"./config.js\";\nimport { QuestionnaireSession } from \"./state/questionnaire-session.js\";\nimport { ROW_INTENT_META, sentinelsToAppend } from \"./state/row-intent.js\";\nimport { buildQuestionnaireResponse, buildToolResult } from \"./tool/response-envelope.js\";\nimport {\n\tMAX_OPTIONS,\n\tMAX_QUESTIONS,\n\tMIN_OPTIONS,\n\ttype QuestionData,\n\ttype QuestionnaireResult,\n\ttype QuestionParams,\n\tQuestionParamsSchema,\n} from \"./tool/types.js\";\nimport { validateQuestionnaire } from \"./tool/validate-questionnaire.js\";\nimport type { WrappingSelectItem } from \"./view/components/wrapping-select.js\";\n\nconst ERROR_NO_UI = \"Error: UI not available (running in non-interactive mode)\";\n\nexport function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {\n\tconst items: WrappingSelectItem[] = question.options.map((o) => ({\n\t\tkind: \"option\",\n\t\tlabel: o.label,\n\t\tdescription: o.description,\n\t}));\n\tconst hasAnyPreview = question.options.some((o) => typeof o.preview === \"string\" && o.preview.length > 0);\n\tfor (const kind of sentinelsToAppend(question, hasAnyPreview)) {\n\t\titems.push({ kind, label: ROW_INTENT_META[kind].label });\n\t}\n\treturn items;\n}\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n\t`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n\t`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer (\"Type something.\" row is appended automatically to single-select questions) or pick \"Chat about this\" to abandon the questionnaire.`,\n\t`Set multiSelect: true when multiple answers are valid; this suppresses the \"Type something.\" row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the \"Type something.\" row (no room in the side-by-side layout); \"Chat about this\" remains the escape hatch. If you recommend a specific option, make it the first option and append \"(Recommended)\" to its label.`,\n\t\"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.\",\n];\n\nexport function createAskUserQuestionToolDefinition(): ToolDefinition<typeof QuestionParamsSchema, unknown> {\n\tconst guidance = validateGuidanceFields(loadConfig().guidance);\n\treturn {\n\t\tname: \"ask_user_question\",\n\t\tlabel: \"Ask User Question\",\n\t\tdescription: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users will always be able to type a custom answer (\"Type something.\" row is appended automatically to every single-select question) or pick \"Chat about this\" to abandon the questionnaire and continue in free-form conversation. Do NOT author \"Other\" / \"Type something.\" / \"Chat about this\" labels yourself — duplicates are rejected at runtime.\n- Use multiSelect: true to allow multiple answers to be selected for a question. The \"Type something.\" row is suppressed on multi-select questions, and is ALSO suppressed on single-select questions where any option carries a \\`preview\\` (the side-by-side layout has no room for inline custom text — \"Chat about this\" remains as the free-form escape hatch).\n- If you recommend a specific option, make that the first option in the list and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional \\`preview\\` field on options when presenting concrete artifacts that users need to visually compare:\n- ASCII mockups of UI layouts or components\n- Code snippets showing different implementations\n- Diagram variations\n- Configuration examples\n\nPreview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,\n\t\tpromptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n\t\tpromptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParamsSchema,\n\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst typed = params as unknown as QuestionParams;\n\t\t\tif (!ctx.hasUI) return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: \"no_ui\" });\n\n\t\t\tconst validation = validateQuestionnaire(typed);\n\t\t\tif (!validation.ok) {\n\t\t\t\treturn buildToolResult(validation.message, {\n\t\t\t\t\tanswers: [],\n\t\t\t\t\tcancelled: true,\n\t\t\t\t\terror: validation.error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));\n\n\t\t\tconst result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {\n\t\t\t\tconst session = new QuestionnaireSession({\n\t\t\t\t\ttui,\n\t\t\t\t\ttheme,\n\t\t\t\t\tparams: typed,\n\t\t\t\t\titemsByTab,\n\t\t\t\t\tdone,\n\t\t\t\t});\n\t\t\t\treturn session.component;\n\t\t\t});\n\n\t\t\treturn buildQuestionnaireResponse(result, typed);\n\t\t},\n\t};\n}\n\nexport { buildQuestionnaireResponse, buildToolResult };\n"]}
1
+ {"version":3,"file":"ask-user-question.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIhE,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAIN,KAAK,YAAY,EAGjB,oBAAoB,EACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAI/E,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,YAAY,GAAG,kBAAkB,EAAE,CAWlF;AAED,eAAO,MAAM,sBAAsB,iGAA0I,CAAC;AAC9K,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAK7C,CAAC;AAEF,wBAAgB,mCAAmC,IAAI,cAAc,CAAC,OAAO,oBAAoB,EAAE,OAAO,CAAC,CAyD1G;AAED,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { ToolDefinition } from \"../../extensions/types.ts\";\nimport { loadConfig, validateGuidanceFields } from \"./config.ts\";\nimport { QuestionnaireSession } from \"./state/questionnaire-session.ts\";\nimport { ROW_INTENT_META, sentinelsToAppend } from \"./state/row-intent.ts\";\nimport { buildQuestionnaireResponse, buildToolResult } from \"./tool/response-envelope.ts\";\nimport {\n\tMAX_OPTIONS,\n\tMAX_QUESTIONS,\n\tMIN_OPTIONS,\n\ttype QuestionData,\n\ttype QuestionnaireResult,\n\ttype QuestionParams,\n\tQuestionParamsSchema,\n} from \"./tool/types.ts\";\nimport { validateQuestionnaire } from \"./tool/validate-questionnaire.ts\";\nimport type { WrappingSelectItem } from \"./view/components/wrapping-select.ts\";\n\nconst ERROR_NO_UI = \"Error: UI not available (running in non-interactive mode)\";\n\nexport function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {\n\tconst items: WrappingSelectItem[] = question.options.map((o) => ({\n\t\tkind: \"option\",\n\t\tlabel: o.label,\n\t\tdescription: o.description,\n\t}));\n\tconst hasAnyPreview = question.options.some((o) => typeof o.preview === \"string\" && o.preview.length > 0);\n\tfor (const kind of sentinelsToAppend(question, hasAnyPreview)) {\n\t\titems.push({ kind, label: ROW_INTENT_META[kind].label });\n\t}\n\treturn items;\n}\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n\t`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n\t`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer (\"Type something.\" row is appended automatically to single-select questions) or pick \"Chat about this\" to abandon the questionnaire.`,\n\t`Set multiSelect: true when multiple answers are valid; this suppresses the \"Type something.\" row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the \"Type something.\" row (no room in the side-by-side layout); \"Chat about this\" remains the escape hatch. If you recommend a specific option, make it the first option and append \"(Recommended)\" to its label.`,\n\t\"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.\",\n];\n\nexport function createAskUserQuestionToolDefinition(): ToolDefinition<typeof QuestionParamsSchema, unknown> {\n\tconst guidance = validateGuidanceFields(loadConfig().guidance);\n\treturn {\n\t\tname: \"ask_user_question\",\n\t\tlabel: \"Ask User Question\",\n\t\tdescription: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users will always be able to type a custom answer (\"Type something.\" row is appended automatically to every single-select question) or pick \"Chat about this\" to abandon the questionnaire and continue in free-form conversation. Do NOT author \"Other\" / \"Type something.\" / \"Chat about this\" labels yourself — duplicates are rejected at runtime.\n- Use multiSelect: true to allow multiple answers to be selected for a question. The \"Type something.\" row is suppressed on multi-select questions, and is ALSO suppressed on single-select questions where any option carries a \\`preview\\` (the side-by-side layout has no room for inline custom text — \"Chat about this\" remains as the free-form escape hatch).\n- If you recommend a specific option, make that the first option in the list and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional \\`preview\\` field on options when presenting concrete artifacts that users need to visually compare:\n- ASCII mockups of UI layouts or components\n- Code snippets showing different implementations\n- Diagram variations\n- Configuration examples\n\nPreview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,\n\t\tpromptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n\t\tpromptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParamsSchema,\n\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst typed = params as unknown as QuestionParams;\n\t\t\tif (!ctx.hasUI) return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: \"no_ui\" });\n\n\t\t\tconst validation = validateQuestionnaire(typed);\n\t\t\tif (!validation.ok) {\n\t\t\t\treturn buildToolResult(validation.message, {\n\t\t\t\t\tanswers: [],\n\t\t\t\t\tcancelled: true,\n\t\t\t\t\terror: validation.error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));\n\n\t\t\tconst result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {\n\t\t\t\tconst session = new QuestionnaireSession({\n\t\t\t\t\ttui,\n\t\t\t\t\ttheme,\n\t\t\t\t\tparams: typed,\n\t\t\t\t\titemsByTab,\n\t\t\t\t\tdone,\n\t\t\t\t});\n\t\t\t\treturn session.component;\n\t\t\t});\n\n\t\t\treturn buildQuestionnaireResponse(result, typed);\n\t\t},\n\t};\n}\n\nexport { buildQuestionnaireResponse, buildToolResult };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ask-user-question.js","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EACN,WAAW,EACX,aAAa,EACb,WAAW,EAIX,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,MAAM,WAAW,GAAG,2DAA2D,CAAC;AAEhF,MAAM,UAAU,qBAAqB,CAAC,QAAsB;IAC3D,MAAM,KAAK,GAAyB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChE,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,WAAW,EAAE,CAAC,CAAC,WAAW;KAC1B,CAAC,CAAC,CAAC;IACJ,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,CAA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,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;gBACpB,OAAO,eAAe,CAAC,UAAU,CAAC,OAAO,EAAE;oBAC1C,OAAO,EAAE,EAAE;oBACX,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,UAAU,CAAC,KAAK;iBACvB,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,UAAU,GAA2B,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;YAEhG,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAsB,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;gBACjF,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC;oBACxC,GAAG;oBACH,KAAK;oBACL,MAAM,EAAE,KAAK;oBACb,UAAU;oBACV,IAAI;iBACJ,CAAC,CAAC;gBACH,OAAO,OAAO,CAAC,SAAS,CAAC;YAC1B,CAAC,CAAC,CAAC;YAEH,OAAO,0BAA0B,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,CAAC;KACD,CAAC;AACH,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { ToolDefinition } from \"../../extensions/types.js\";\nimport { loadConfig, validateGuidanceFields } from \"./config.js\";\nimport { QuestionnaireSession } from \"./state/questionnaire-session.js\";\nimport { ROW_INTENT_META, sentinelsToAppend } from \"./state/row-intent.js\";\nimport { buildQuestionnaireResponse, buildToolResult } from \"./tool/response-envelope.js\";\nimport {\n\tMAX_OPTIONS,\n\tMAX_QUESTIONS,\n\tMIN_OPTIONS,\n\ttype QuestionData,\n\ttype QuestionnaireResult,\n\ttype QuestionParams,\n\tQuestionParamsSchema,\n} from \"./tool/types.js\";\nimport { validateQuestionnaire } from \"./tool/validate-questionnaire.js\";\nimport type { WrappingSelectItem } from \"./view/components/wrapping-select.js\";\n\nconst ERROR_NO_UI = \"Error: UI not available (running in non-interactive mode)\";\n\nexport function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {\n\tconst items: WrappingSelectItem[] = question.options.map((o) => ({\n\t\tkind: \"option\",\n\t\tlabel: o.label,\n\t\tdescription: o.description,\n\t}));\n\tconst hasAnyPreview = question.options.some((o) => typeof o.preview === \"string\" && o.preview.length > 0);\n\tfor (const kind of sentinelsToAppend(question, hasAnyPreview)) {\n\t\titems.push({ kind, label: ROW_INTENT_META[kind].label });\n\t}\n\treturn items;\n}\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n\t`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n\t`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer (\"Type something.\" row is appended automatically to single-select questions) or pick \"Chat about this\" to abandon the questionnaire.`,\n\t`Set multiSelect: true when multiple answers are valid; this suppresses the \"Type something.\" row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the \"Type something.\" row (no room in the side-by-side layout); \"Chat about this\" remains the escape hatch. If you recommend a specific option, make it the first option and append \"(Recommended)\" to its label.`,\n\t\"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.\",\n];\n\nexport function createAskUserQuestionToolDefinition(): ToolDefinition<typeof QuestionParamsSchema, unknown> {\n\tconst guidance = validateGuidanceFields(loadConfig().guidance);\n\treturn {\n\t\tname: \"ask_user_question\",\n\t\tlabel: \"Ask User Question\",\n\t\tdescription: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users will always be able to type a custom answer (\"Type something.\" row is appended automatically to every single-select question) or pick \"Chat about this\" to abandon the questionnaire and continue in free-form conversation. Do NOT author \"Other\" / \"Type something.\" / \"Chat about this\" labels yourself — duplicates are rejected at runtime.\n- Use multiSelect: true to allow multiple answers to be selected for a question. The \"Type something.\" row is suppressed on multi-select questions, and is ALSO suppressed on single-select questions where any option carries a \\`preview\\` (the side-by-side layout has no room for inline custom text — \"Chat about this\" remains as the free-form escape hatch).\n- If you recommend a specific option, make that the first option in the list and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional \\`preview\\` field on options when presenting concrete artifacts that users need to visually compare:\n- ASCII mockups of UI layouts or components\n- Code snippets showing different implementations\n- Diagram variations\n- Configuration examples\n\nPreview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,\n\t\tpromptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n\t\tpromptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParamsSchema,\n\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst typed = params as unknown as QuestionParams;\n\t\t\tif (!ctx.hasUI) return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: \"no_ui\" });\n\n\t\t\tconst validation = validateQuestionnaire(typed);\n\t\t\tif (!validation.ok) {\n\t\t\t\treturn buildToolResult(validation.message, {\n\t\t\t\t\tanswers: [],\n\t\t\t\t\tcancelled: true,\n\t\t\t\t\terror: validation.error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));\n\n\t\t\tconst result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {\n\t\t\t\tconst session = new QuestionnaireSession({\n\t\t\t\t\ttui,\n\t\t\t\t\ttheme,\n\t\t\t\t\tparams: typed,\n\t\t\t\t\titemsByTab,\n\t\t\t\t\tdone,\n\t\t\t\t});\n\t\t\t\treturn session.component;\n\t\t\t});\n\n\t\t\treturn buildQuestionnaireResponse(result, typed);\n\t\t},\n\t};\n}\n\nexport { buildQuestionnaireResponse, buildToolResult };\n"]}
1
+ {"version":3,"file":"ask-user-question.js","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EACN,WAAW,EACX,aAAa,EACb,WAAW,EAIX,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,MAAM,WAAW,GAAG,2DAA2D,CAAC;AAEhF,MAAM,UAAU,qBAAqB,CAAC,QAAsB;IAC3D,MAAM,KAAK,GAAyB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChE,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,WAAW,EAAE,CAAC,CAAC,WAAW;KAC1B,CAAC,CAAC,CAAC;IACJ,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,OAA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GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;YAChD,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;gBACpB,OAAO,eAAe,CAAC,UAAU,CAAC,OAAO,EAAE;oBAC1C,OAAO,EAAE,EAAE;oBACX,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,UAAU,CAAC,KAAK;iBACvB,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,UAAU,GAA2B,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;YAEhG,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAsB,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;gBACjF,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC;oBACxC,GAAG;oBACH,KAAK;oBACL,MAAM,EAAE,KAAK;oBACb,UAAU;oBACV,IAAI;iBACJ,CAAC,CAAC;gBACH,OAAO,OAAO,CAAC,SAAS,CAAC;YAC1B,CAAC,CAAC,CAAC;YAEH,OAAO,0BAA0B,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,CAAC;KACD,CAAC;AACH,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { ToolDefinition } from \"../../extensions/types.ts\";\nimport { loadConfig, validateGuidanceFields } from \"./config.ts\";\nimport { QuestionnaireSession } from \"./state/questionnaire-session.ts\";\nimport { ROW_INTENT_META, sentinelsToAppend } from \"./state/row-intent.ts\";\nimport { buildQuestionnaireResponse, buildToolResult } from \"./tool/response-envelope.ts\";\nimport {\n\tMAX_OPTIONS,\n\tMAX_QUESTIONS,\n\tMIN_OPTIONS,\n\ttype QuestionData,\n\ttype QuestionnaireResult,\n\ttype QuestionParams,\n\tQuestionParamsSchema,\n} from \"./tool/types.ts\";\nimport { validateQuestionnaire } from \"./tool/validate-questionnaire.ts\";\nimport type { WrappingSelectItem } from \"./view/components/wrapping-select.ts\";\n\nconst ERROR_NO_UI = \"Error: UI not available (running in non-interactive mode)\";\n\nexport function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {\n\tconst items: WrappingSelectItem[] = question.options.map((o) => ({\n\t\tkind: \"option\",\n\t\tlabel: o.label,\n\t\tdescription: o.description,\n\t}));\n\tconst hasAnyPreview = question.options.some((o) => typeof o.preview === \"string\" && o.preview.length > 0);\n\tfor (const kind of sentinelsToAppend(question, hasAnyPreview)) {\n\t\titems.push({ kind, label: ROW_INTENT_META[kind].label });\n\t}\n\treturn items;\n}\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n\t`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n\t`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer (\"Type something.\" row is appended automatically to single-select questions) or pick \"Chat about this\" to abandon the questionnaire.`,\n\t`Set multiSelect: true when multiple answers are valid; this suppresses the \"Type something.\" row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the \"Type something.\" row (no room in the side-by-side layout); \"Chat about this\" remains the escape hatch. If you recommend a specific option, make it the first option and append \"(Recommended)\" to its label.`,\n\t\"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.\",\n];\n\nexport function createAskUserQuestionToolDefinition(): ToolDefinition<typeof QuestionParamsSchema, unknown> {\n\tconst guidance = validateGuidanceFields(loadConfig().guidance);\n\treturn {\n\t\tname: \"ask_user_question\",\n\t\tlabel: \"Ask User Question\",\n\t\tdescription: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users will always be able to type a custom answer (\"Type something.\" row is appended automatically to every single-select question) or pick \"Chat about this\" to abandon the questionnaire and continue in free-form conversation. Do NOT author \"Other\" / \"Type something.\" / \"Chat about this\" labels yourself — duplicates are rejected at runtime.\n- Use multiSelect: true to allow multiple answers to be selected for a question. The \"Type something.\" row is suppressed on multi-select questions, and is ALSO suppressed on single-select questions where any option carries a \\`preview\\` (the side-by-side layout has no room for inline custom text — \"Chat about this\" remains as the free-form escape hatch).\n- If you recommend a specific option, make that the first option in the list and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional \\`preview\\` field on options when presenting concrete artifacts that users need to visually compare:\n- ASCII mockups of UI layouts or components\n- Code snippets showing different implementations\n- Diagram variations\n- Configuration examples\n\nPreview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,\n\t\tpromptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n\t\tpromptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParamsSchema,\n\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst typed = params as unknown as QuestionParams;\n\t\t\tif (!ctx.hasUI) return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: \"no_ui\" });\n\n\t\t\tconst validation = validateQuestionnaire(typed);\n\t\t\tif (!validation.ok) {\n\t\t\t\treturn buildToolResult(validation.message, {\n\t\t\t\t\tanswers: [],\n\t\t\t\t\tcancelled: true,\n\t\t\t\t\terror: validation.error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));\n\n\t\t\tconst result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {\n\t\t\t\tconst session = new QuestionnaireSession({\n\t\t\t\t\ttui,\n\t\t\t\t\ttheme,\n\t\t\t\t\tparams: typed,\n\t\t\t\t\titemsByTab,\n\t\t\t\t\tdone,\n\t\t\t\t});\n\t\t\t\treturn session.component;\n\t\t\t});\n\n\t\t\treturn buildQuestionnaireResponse(result, typed);\n\t\t},\n\t};\n}\n\nexport { buildQuestionnaireResponse, buildToolResult };\n"]}
@@ -15,5 +15,5 @@
15
15
  * - ../index.ts (registers via createAllToolDefinitions)
16
16
  * - ./ask-user-question.ts (tool definition + execute pipeline)
17
17
  */
18
- export { createAskUserQuestionToolDefinition } from "./ask-user-question.js";
18
+ export { createAskUserQuestionToolDefinition } from "./ask-user-question.ts";
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * `ask_user_question` base tool — registered alongside read/bash/edit/write.\n *\n * Upstream: https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-ask-user-question\n * Upstream copyright: (c) 2026 juicesharp — MIT (see ./LICENSE.upstream).\n *\n * Differences from upstream:\n * - i18n is removed entirely. The upstream `state/i18n-bridge.ts`,\n * `locales/*.json`, and the optional `@juicesharp/rpiv-i18n` peer\n * dependency are gone. All UI copy is plain English string literals\n * or local module-level constants.\n * - Exposed as a base tool definition (no extension registration).\n *\n * cross-ref:\n * - ../index.ts (registers via createAllToolDefinitions)\n * - ./ask-user-question.ts (tool definition + execute pipeline)\n */\nexport { createAskUserQuestionToolDefinition } from \"./ask-user-question.js\";\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * `ask_user_question` base tool — registered alongside read/bash/edit/write.\n *\n * Upstream: https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-ask-user-question\n * Upstream copyright: (c) 2026 juicesharp — MIT (see ./LICENSE.upstream).\n *\n * Differences from upstream:\n * - i18n is removed entirely. The upstream `state/i18n-bridge.ts`,\n * `locales/*.json`, and the optional `@juicesharp/rpiv-i18n` peer\n * dependency are gone. All UI copy is plain English string literals\n * or local module-level constants.\n * - Exposed as a base tool definition (no extension registration).\n *\n * cross-ref:\n * - ../index.ts (registers via createAllToolDefinitions)\n * - ./ask-user-question.ts (tool definition + execute pipeline)\n */\nexport { createAskUserQuestionToolDefinition } from \"./ask-user-question.ts\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * `ask_user_question` base tool — registered alongside read/bash/edit/write.\n *\n * Upstream: https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-ask-user-question\n * Upstream copyright: (c) 2026 juicesharp — MIT (see ./LICENSE.upstream).\n *\n * Differences from upstream:\n * - i18n is removed entirely. The upstream `state/i18n-bridge.ts`,\n * `locales/*.json`, and the optional `@juicesharp/rpiv-i18n` peer\n * dependency are gone. All UI copy is plain English string literals\n * or local module-level constants.\n * - Exposed as a base tool definition (no extension registration).\n *\n * cross-ref:\n * - ../index.ts (registers via createAllToolDefinitions)\n * - ./ask-user-question.ts (tool definition + execute pipeline)\n */\nexport { createAskUserQuestionToolDefinition } from \"./ask-user-question.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * `ask_user_question` base tool — registered alongside read/bash/edit/write.\n *\n * Upstream: https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-ask-user-question\n * Upstream copyright: (c) 2026 juicesharp — MIT (see ./LICENSE.upstream).\n *\n * Differences from upstream:\n * - i18n is removed entirely. The upstream `state/i18n-bridge.ts`,\n * `locales/*.json`, and the optional `@juicesharp/rpiv-i18n` peer\n * dependency are gone. All UI copy is plain English string literals\n * or local module-level constants.\n * - Exposed as a base tool definition (no extension registration).\n *\n * cross-ref:\n * - ../index.ts (registers via createAllToolDefinitions)\n * - ./ask-user-question.ts (tool definition + execute pipeline)\n */\nexport { createAskUserQuestionToolDefinition } from \"./ask-user-question.ts\";\n"]}
@@ -1,9 +1,9 @@
1
- import { type Theme } from "../../../../modes/interactive/theme/theme.js";
1
+ import { type Theme } from "../../../../modes/interactive/theme/theme.ts";
2
2
  import { Input } from "@earendil-works/pi-tui";
3
- import type { QuestionData } from "../tool/types.js";
4
- import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
5
- import { QuestionnairePropsAdapter } from "../view/props-adapter.js";
6
- import type { QuestionnaireState } from "./state.js";
3
+ import type { QuestionData } from "../tool/types.ts";
4
+ import type { WrappingSelectItem } from "../view/components/wrapping-select.ts";
5
+ import { QuestionnairePropsAdapter } from "../view/props-adapter.ts";
6
+ import type { QuestionnaireState } from "./state.ts";
7
7
  export interface QuestionnaireBuildConfig {
8
8
  tui: {
9
9
  terminal: {
@@ -1 +1 @@
1
- {"version":3,"file":"build-questionnaire.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/build-questionnaire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgBrD,OAAO,KAAK,EAAE,kBAAkB,EAAuB,MAAM,uCAAuC,CAAC;AAErG,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAerE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,wBAAwB;IACxC,GAAG,EAAE;QAAE,QAAQ,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,aAAa,IAAI,IAAI,CAAA;KAAE,CAAC;IAC9D,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,SAAS,YAAY,EAAE,CAAC;IACnC,UAAU,EAAE,aAAa,CAAC,SAAS,kBAAkB,EAAE,CAAC,CAAC;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,kBAAkB,CAAC;IACjC,aAAa,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,yBAAyB,CAAC;IACnC,UAAU,EAAE,KAAK,CAAC;IAClB,WAAW,EAAE,KAAK,CAAC;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IACpC,UAAU,EAAE,MAAM,IAAI,CAAC;CACvB;AAwBD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,CAEvF","sourcesContent":["import { getMarkdownTheme, type Theme } from \"../../../../modes/interactive/theme/theme.js\";\nimport { Input } from \"@earendil-works/pi-tui\";\nimport type { QuestionData } from \"../tool/types.js\";\nimport {\n\ttype BoundGlobalBinding,\n\ttype BoundPerTabBinding,\n\tglobalBinding,\n\tperTabBinding,\n} from \"../view/component-binding.js\";\nimport { ChatRowView } from \"../view/components/chat-row-view.js\";\nimport { MultiSelectView } from \"../view/components/multi-select-view.js\";\nimport { OptionListView } from \"../view/components/option-list-view.js\";\nimport { PreviewBlockRenderer } from \"../view/components/preview/preview-block-renderer.js\";\nimport { crossTabLeftWidthWithDonation } from \"../view/components/preview/preview-layout-decider.js\";\nimport type { PreviewPaneProps } from \"../view/components/preview/preview-pane.js\";\nimport { PreviewPane } from \"../view/components/preview/preview-pane.js\";\nimport { SubmitPicker } from \"../view/components/submit-picker.js\";\nimport { TabBar } from \"../view/components/tab-bar.js\";\nimport type { WrappingSelectItem, WrappingSelectTheme } from \"../view/components/wrapping-select.js\";\nimport { DialogView } from \"../view/dialog-builder.js\";\nimport { QuestionnairePropsAdapter } from \"../view/props-adapter.js\";\nimport type { StatefulView } from \"../view/stateful-view.js\";\nimport type { TabBodyHeights, TabComponents } from \"../view/tab-components.js\";\nimport { ROW_INTENT_META } from \"./row-intent.js\";\nimport type { PerTabSelector } from \"./selectors/contract.js\";\nimport { selectActivePreviewPaneIndex } from \"./selectors/derivations.js\";\nimport {\n\tselectChatRowProps,\n\tselectDialogProps,\n\tselectMultiSelectProps,\n\tselectOptionListProps,\n\tselectPreviewPaneProps,\n\tselectSubmitPickerProps,\n\tselectTabBarProps,\n} from \"./selectors/projections.js\";\nimport type { QuestionnaireState } from \"./state.js\";\n\nexport interface QuestionnaireBuildConfig {\n\ttui: { terminal: { columns: number }; requestRender(): void };\n\ttheme: Theme;\n\tquestions: readonly QuestionData[];\n\titemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tisMulti: boolean;\n\tinitialState: QuestionnaireState;\n\tgetCurrentTab: () => number;\n}\n\nexport interface QuestionnaireBuilt {\n\tadapter: QuestionnairePropsAdapter;\n\tnotesInput: Input;\n\tinlineInput: Input;\n\trender: (width: number) => string[];\n\tinvalidate: () => void;\n}\n\ninterface HeightComputers {\n\tglobal: (width: number) => number;\n\tcurrent: (width: number) => number;\n}\n\nfunction previewBodyHeights(pane: PreviewPane): (width: number) => TabBodyHeights {\n\treturn (width) => ({\n\t\tcurrent: pane.naturalHeight(width),\n\t\tmax: pane.maxNaturalHeight(width),\n\t});\n}\n\nfunction multiSelectBodyHeights(view: MultiSelectView): (width: number) => TabBodyHeights {\n\treturn (width) => {\n\t\tconst h = view.naturalHeight(width);\n\t\treturn { current: h, max: h };\n\t};\n}\n\nconst isActiveTab: PerTabSelector<boolean> = (s, ctx) =>\n\tctx.i === selectActivePreviewPaneIndex(s.currentTab, ctx.totalQuestions);\n\n/**\n * Pure factory: assembles every TUI component, the props adapter, and a\n * lifecycle handle. Session-state dependencies arrive via `getCurrentTab` and\n * the `inputBuffer` cell. Initial paint is delegated to\n * `adapter.apply(initialState)` (called by the session at construction-end);\n * no selector is invoked here.\n */\nexport function buildQuestionnaire(config: QuestionnaireBuildConfig): QuestionnaireBuilt {\n\treturn new QuestionnaireBuilder(config).build();\n}\n\n/**\n * Programming-by-intention assembly: each private method names one\n * construction step from `build()`. Read top-down; the class is build-only and\n * discarded once the handle is returned.\n */\nclass QuestionnaireBuilder {\n\tprivate readonly tui: QuestionnaireBuildConfig[\"tui\"];\n\tprivate readonly theme: Theme;\n\tprivate readonly questions: readonly QuestionData[];\n\tprivate readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tprivate readonly isMulti: boolean;\n\tprivate readonly initialState: QuestionnaireState;\n\tprivate readonly getCurrentTab: () => number;\n\n\tprivate readonly selectTheme: WrappingSelectTheme;\n\tprivate readonly markdownTheme = getMarkdownTheme();\n\tprivate readonly chatRow: ChatRowView;\n\tprivate readonly notesInput = new Input();\n\tprivate readonly inlineInput = new Input();\n\tprivate readonly getTerminalWidth = () => this.tui.terminal.columns;\n\n\tconstructor(config: QuestionnaireBuildConfig) {\n\t\tthis.tui = config.tui;\n\t\tthis.theme = config.theme;\n\t\tthis.questions = config.questions;\n\t\tthis.itemsByTab = config.itemsByTab;\n\t\tthis.isMulti = config.isMulti;\n\t\tthis.initialState = config.initialState;\n\t\tthis.getCurrentTab = config.getCurrentTab;\n\n\t\tthis.selectTheme = this.makeSelectTheme();\n\t\tthis.chatRow = new ChatRowView({\n\t\t\titem: { kind: \"chat\", label: ROW_INTENT_META.chat.label },\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t}\n\n\tbuild(): QuestionnaireBuilt {\n\t\tconst tabs = this.buildTabComponents();\n\t\tthis.injectGlobalLeftWidth(tabs);\n\t\tconst submitPicker = this.buildSubmitPicker();\n\t\tconst tabBar = this.buildTabBar();\n\t\tconst heights = this.buildHeightComputers(tabs);\n\t\tconst dialog = this.buildDialog(tabs, submitPicker, tabBar, heights);\n\t\tconst globalBindings = this.buildGlobalBindings(dialog, submitPicker, tabBar);\n\t\tconst perTabBindings = this.buildPerTabBindings();\n\t\tconst adapter = this.buildAdapter(tabs, globalBindings, perTabBindings);\n\t\treturn this.handle(adapter, dialog);\n\t}\n\n\tprivate makeSelectTheme(): WrappingSelectTheme {\n\t\tconst t = this.theme;\n\t\treturn {\n\t\t\tselectedText: (s) => t.fg(\"accent\", t.bold(s)),\n\t\t\tdescription: (s) => t.fg(\"muted\", s),\n\t\t\tscrollInfo: (s) => t.fg(\"dim\", s),\n\t\t};\n\t}\n\n\tprivate buildTabComponents(): ReadonlyArray<TabComponents> {\n\t\treturn this.questions.map((q, i) => this.buildTabFor(q, i));\n\t}\n\n\tprivate buildTabFor(question: QuestionData, index: number): TabComponents {\n\t\tconst optionList = new OptionListView({\n\t\t\titems: this.itemsByTab[index] ?? [],\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t\tconst previewBlock = new PreviewBlockRenderer({\n\t\t\tquestion,\n\t\t\ttheme: this.theme,\n\t\t\tmarkdownTheme: this.markdownTheme,\n\t\t});\n\t\tconst preview = new PreviewPane({\n\t\t\tquestion,\n\t\t\tgetTerminalWidth: this.getTerminalWidth,\n\t\t\toptionListView: optionList,\n\t\t\tpreviewBlock,\n\t\t});\n\t\tconst multiSelect = question.multiSelect ? new MultiSelectView(this.theme, question) : undefined;\n\t\tconst bodyHeights = this.buildBodyHeights(question, preview, multiSelect);\n\t\treturn { optionList, preview, multiSelect, bodyHeights };\n\t}\n\n\tprivate buildBodyHeights(\n\t\tquestion: QuestionData,\n\t\tpreview: PreviewPane,\n\t\tmultiSelect: MultiSelectView | undefined,\n\t): (width: number) => TabBodyHeights {\n\t\treturn question.multiSelect ? multiSelectBodyHeights(multiSelect!) : previewBodyHeights(preview);\n\t}\n\n\t/**\n\t * Compute cross-tab max adaptive left width and inject into each PreviewPane.\n\t * Mirrors buildHeightComputers pattern — iterates all tabs, takes max.\n\t * Called after buildTabComponents, before buildDialog (so setGlobalLeftWidth\n\t * is set before any rendering occurs).\n\t */\n\tprivate injectGlobalLeftWidth(tabs: ReadonlyArray<TabComponents>): void {\n\t\tconst questions = this.questions;\n\t\tconst itemsByTab = this.itemsByTab;\n\t\tconst tabsDescriptor = questions.map((q) => ({ multiSelect: q.multiSelect }));\n\t\tconst globalLeftWidth = (paneWidth: number): number =>\n\t\t\tcrossTabLeftWidthWithDonation(tabsDescriptor, itemsByTab, questions, paneWidth);\n\t\tfor (const tab of tabs) {\n\t\t\ttab.preview.setGlobalLeftWidth(globalLeftWidth);\n\t\t}\n\t}\n\n\tprivate buildSubmitPicker(): SubmitPicker | undefined {\n\t\treturn this.isMulti ? new SubmitPicker(this.theme) : undefined;\n\t}\n\n\tprivate buildTabBar(): TabBar | undefined {\n\t\treturn this.isMulti ? new TabBar(this.theme) : undefined;\n\t}\n\n\tprivate buildHeightComputers(tabs: ReadonlyArray<TabComponents>): HeightComputers {\n\t\tconst global = (width: number): number => {\n\t\t\tlet max = 0;\n\t\t\tfor (const tab of tabs) {\n\t\t\t\tconst h = tab.bodyHeights(width).max;\n\t\t\t\tif (h > max) max = h;\n\t\t\t}\n\t\t\treturn Math.max(1, max);\n\t\t};\n\t\tconst current = (width: number): number => {\n\t\t\tconst idx = Math.min(this.getCurrentTab(), tabs.length - 1);\n\t\t\treturn Math.max(0, tabs[idx]?.bodyHeights(width).current ?? 0);\n\t\t};\n\t\treturn { global, current };\n\t}\n\n\tprivate pickInitialActivePreview(tabs: ReadonlyArray<TabComponents>): StatefulView<PreviewPaneProps> {\n\t\tconst idx = selectActivePreviewPaneIndex(this.initialState.currentTab, this.questions.length);\n\t\treturn tabs[idx]?.preview ?? tabs[0]!.preview;\n\t}\n\n\tprivate buildDialog(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t\theights: HeightComputers,\n\t): DialogView {\n\t\treturn new DialogView(\n\t\t\t{\n\t\t\t\ttheme: this.theme,\n\t\t\t\tquestions: this.questions,\n\t\t\t\ttabBar,\n\t\t\t\tnotesInput: this.notesInput,\n\t\t\t\tchatRow: this.chatRow,\n\t\t\t\tisMulti: this.isMulti,\n\t\t\t\ttabsByIndex: tabs,\n\t\t\t\tsubmitPicker,\n\t\t\t\tgetBodyHeight: heights.global,\n\t\t\t\tgetCurrentBodyHeight: heights.current,\n\t\t\t},\n\t\t\t{ state: this.initialState, activePreviewPane: this.pickInitialActivePreview(tabs) },\n\t\t);\n\t}\n\n\tprivate buildGlobalBindings(\n\t\tdialog: DialogView,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t): ReadonlyArray<BoundGlobalBinding> {\n\t\treturn [\n\t\t\tglobalBinding({ component: dialog, select: selectDialogProps }),\n\t\t\tglobalBinding({ component: this.chatRow, select: selectChatRowProps }),\n\t\t\t...(submitPicker ? [globalBinding({ component: submitPicker, select: selectSubmitPickerProps })] : []),\n\t\t\t...(tabBar ? [globalBinding({ component: tabBar, select: selectTabBarProps })] : []),\n\t\t];\n\t}\n\n\tprivate buildPerTabBindings(): ReadonlyArray<BoundPerTabBinding> {\n\t\treturn [\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.optionList,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectOptionListProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.preview,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectPreviewPaneProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.multiSelect,\n\t\t\t\tselect: selectMultiSelectProps,\n\t\t\t}),\n\t\t];\n\t}\n\n\tprivate buildAdapter(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tglobalBindings: ReadonlyArray<BoundGlobalBinding>,\n\t\tperTabBindings: ReadonlyArray<BoundPerTabBinding>,\n\t): QuestionnairePropsAdapter {\n\t\treturn new QuestionnairePropsAdapter({\n\t\t\ttui: this.tui,\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t\ttabsByIndex: tabs,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\tglobalBindings,\n\t\t\tperTabBindings,\n\t\t\textraInvalidatables: [this.notesInput],\n\t\t});\n\t}\n\n\tprivate handle(adapter: QuestionnairePropsAdapter, dialog: DialogView): QuestionnaireBuilt {\n\t\treturn {\n\t\t\tadapter,\n\t\t\tnotesInput: this.notesInput,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\trender: (w) => dialog.render(w),\n\t\t\tinvalidate: () => adapter.invalidate(),\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"build-questionnaire.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/build-questionnaire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgBrD,OAAO,KAAK,EAAE,kBAAkB,EAAuB,MAAM,uCAAuC,CAAC;AAErG,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAerE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,wBAAwB;IACxC,GAAG,EAAE;QAAE,QAAQ,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,aAAa,IAAI,IAAI,CAAA;KAAE,CAAC;IAC9D,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,SAAS,YAAY,EAAE,CAAC;IACnC,UAAU,EAAE,aAAa,CAAC,SAAS,kBAAkB,EAAE,CAAC,CAAC;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,kBAAkB,CAAC;IACjC,aAAa,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,yBAAyB,CAAC;IACnC,UAAU,EAAE,KAAK,CAAC;IAClB,WAAW,EAAE,KAAK,CAAC;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IACpC,UAAU,EAAE,MAAM,IAAI,CAAC;CACvB;AAwBD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,CAEvF","sourcesContent":["import { getMarkdownTheme, type Theme } from \"../../../../modes/interactive/theme/theme.ts\";\nimport { Input } from \"@earendil-works/pi-tui\";\nimport type { QuestionData } from \"../tool/types.ts\";\nimport {\n\ttype BoundGlobalBinding,\n\ttype BoundPerTabBinding,\n\tglobalBinding,\n\tperTabBinding,\n} from \"../view/component-binding.ts\";\nimport { ChatRowView } from \"../view/components/chat-row-view.ts\";\nimport { MultiSelectView } from \"../view/components/multi-select-view.ts\";\nimport { OptionListView } from \"../view/components/option-list-view.ts\";\nimport { PreviewBlockRenderer } from \"../view/components/preview/preview-block-renderer.ts\";\nimport { crossTabLeftWidthWithDonation } from \"../view/components/preview/preview-layout-decider.ts\";\nimport type { PreviewPaneProps } from \"../view/components/preview/preview-pane.ts\";\nimport { PreviewPane } from \"../view/components/preview/preview-pane.ts\";\nimport { SubmitPicker } from \"../view/components/submit-picker.ts\";\nimport { TabBar } from \"../view/components/tab-bar.ts\";\nimport type { WrappingSelectItem, WrappingSelectTheme } from \"../view/components/wrapping-select.ts\";\nimport { DialogView } from \"../view/dialog-builder.ts\";\nimport { QuestionnairePropsAdapter } from \"../view/props-adapter.ts\";\nimport type { StatefulView } from \"../view/stateful-view.ts\";\nimport type { TabBodyHeights, TabComponents } from \"../view/tab-components.ts\";\nimport { ROW_INTENT_META } from \"./row-intent.ts\";\nimport type { PerTabSelector } from \"./selectors/contract.ts\";\nimport { selectActivePreviewPaneIndex } from \"./selectors/derivations.ts\";\nimport {\n\tselectChatRowProps,\n\tselectDialogProps,\n\tselectMultiSelectProps,\n\tselectOptionListProps,\n\tselectPreviewPaneProps,\n\tselectSubmitPickerProps,\n\tselectTabBarProps,\n} from \"./selectors/projections.ts\";\nimport type { QuestionnaireState } from \"./state.ts\";\n\nexport interface QuestionnaireBuildConfig {\n\ttui: { terminal: { columns: number }; requestRender(): void };\n\ttheme: Theme;\n\tquestions: readonly QuestionData[];\n\titemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tisMulti: boolean;\n\tinitialState: QuestionnaireState;\n\tgetCurrentTab: () => number;\n}\n\nexport interface QuestionnaireBuilt {\n\tadapter: QuestionnairePropsAdapter;\n\tnotesInput: Input;\n\tinlineInput: Input;\n\trender: (width: number) => string[];\n\tinvalidate: () => void;\n}\n\ninterface HeightComputers {\n\tglobal: (width: number) => number;\n\tcurrent: (width: number) => number;\n}\n\nfunction previewBodyHeights(pane: PreviewPane): (width: number) => TabBodyHeights {\n\treturn (width) => ({\n\t\tcurrent: pane.naturalHeight(width),\n\t\tmax: pane.maxNaturalHeight(width),\n\t});\n}\n\nfunction multiSelectBodyHeights(view: MultiSelectView): (width: number) => TabBodyHeights {\n\treturn (width) => {\n\t\tconst h = view.naturalHeight(width);\n\t\treturn { current: h, max: h };\n\t};\n}\n\nconst isActiveTab: PerTabSelector<boolean> = (s, ctx) =>\n\tctx.i === selectActivePreviewPaneIndex(s.currentTab, ctx.totalQuestions);\n\n/**\n * Pure factory: assembles every TUI component, the props adapter, and a\n * lifecycle handle. Session-state dependencies arrive via `getCurrentTab` and\n * the `inputBuffer` cell. Initial paint is delegated to\n * `adapter.apply(initialState)` (called by the session at construction-end);\n * no selector is invoked here.\n */\nexport function buildQuestionnaire(config: QuestionnaireBuildConfig): QuestionnaireBuilt {\n\treturn new QuestionnaireBuilder(config).build();\n}\n\n/**\n * Programming-by-intention assembly: each private method names one\n * construction step from `build()`. Read top-down; the class is build-only and\n * discarded once the handle is returned.\n */\nclass QuestionnaireBuilder {\n\tprivate readonly tui: QuestionnaireBuildConfig[\"tui\"];\n\tprivate readonly theme: Theme;\n\tprivate readonly questions: readonly QuestionData[];\n\tprivate readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tprivate readonly isMulti: boolean;\n\tprivate readonly initialState: QuestionnaireState;\n\tprivate readonly getCurrentTab: () => number;\n\n\tprivate readonly selectTheme: WrappingSelectTheme;\n\tprivate readonly markdownTheme = getMarkdownTheme();\n\tprivate readonly chatRow: ChatRowView;\n\tprivate readonly notesInput = new Input();\n\tprivate readonly inlineInput = new Input();\n\tprivate readonly getTerminalWidth = () => this.tui.terminal.columns;\n\n\tconstructor(config: QuestionnaireBuildConfig) {\n\t\tthis.tui = config.tui;\n\t\tthis.theme = config.theme;\n\t\tthis.questions = config.questions;\n\t\tthis.itemsByTab = config.itemsByTab;\n\t\tthis.isMulti = config.isMulti;\n\t\tthis.initialState = config.initialState;\n\t\tthis.getCurrentTab = config.getCurrentTab;\n\n\t\tthis.selectTheme = this.makeSelectTheme();\n\t\tthis.chatRow = new ChatRowView({\n\t\t\titem: { kind: \"chat\", label: ROW_INTENT_META.chat.label },\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t}\n\n\tbuild(): QuestionnaireBuilt {\n\t\tconst tabs = this.buildTabComponents();\n\t\tthis.injectGlobalLeftWidth(tabs);\n\t\tconst submitPicker = this.buildSubmitPicker();\n\t\tconst tabBar = this.buildTabBar();\n\t\tconst heights = this.buildHeightComputers(tabs);\n\t\tconst dialog = this.buildDialog(tabs, submitPicker, tabBar, heights);\n\t\tconst globalBindings = this.buildGlobalBindings(dialog, submitPicker, tabBar);\n\t\tconst perTabBindings = this.buildPerTabBindings();\n\t\tconst adapter = this.buildAdapter(tabs, globalBindings, perTabBindings);\n\t\treturn this.handle(adapter, dialog);\n\t}\n\n\tprivate makeSelectTheme(): WrappingSelectTheme {\n\t\tconst t = this.theme;\n\t\treturn {\n\t\t\tselectedText: (s) => t.fg(\"accent\", t.bold(s)),\n\t\t\tdescription: (s) => t.fg(\"muted\", s),\n\t\t\tscrollInfo: (s) => t.fg(\"dim\", s),\n\t\t};\n\t}\n\n\tprivate buildTabComponents(): ReadonlyArray<TabComponents> {\n\t\treturn this.questions.map((q, i) => this.buildTabFor(q, i));\n\t}\n\n\tprivate buildTabFor(question: QuestionData, index: number): TabComponents {\n\t\tconst optionList = new OptionListView({\n\t\t\titems: this.itemsByTab[index] ?? [],\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t\tconst previewBlock = new PreviewBlockRenderer({\n\t\t\tquestion,\n\t\t\ttheme: this.theme,\n\t\t\tmarkdownTheme: this.markdownTheme,\n\t\t});\n\t\tconst preview = new PreviewPane({\n\t\t\tquestion,\n\t\t\tgetTerminalWidth: this.getTerminalWidth,\n\t\t\toptionListView: optionList,\n\t\t\tpreviewBlock,\n\t\t});\n\t\tconst multiSelect = question.multiSelect ? new MultiSelectView(this.theme, question) : undefined;\n\t\tconst bodyHeights = this.buildBodyHeights(question, preview, multiSelect);\n\t\treturn { optionList, preview, multiSelect, bodyHeights };\n\t}\n\n\tprivate buildBodyHeights(\n\t\tquestion: QuestionData,\n\t\tpreview: PreviewPane,\n\t\tmultiSelect: MultiSelectView | undefined,\n\t): (width: number) => TabBodyHeights {\n\t\treturn question.multiSelect ? multiSelectBodyHeights(multiSelect!) : previewBodyHeights(preview);\n\t}\n\n\t/**\n\t * Compute cross-tab max adaptive left width and inject into each PreviewPane.\n\t * Mirrors buildHeightComputers pattern — iterates all tabs, takes max.\n\t * Called after buildTabComponents, before buildDialog (so setGlobalLeftWidth\n\t * is set before any rendering occurs).\n\t */\n\tprivate injectGlobalLeftWidth(tabs: ReadonlyArray<TabComponents>): void {\n\t\tconst questions = this.questions;\n\t\tconst itemsByTab = this.itemsByTab;\n\t\tconst tabsDescriptor = questions.map((q) => ({ multiSelect: q.multiSelect }));\n\t\tconst globalLeftWidth = (paneWidth: number): number =>\n\t\t\tcrossTabLeftWidthWithDonation(tabsDescriptor, itemsByTab, questions, paneWidth);\n\t\tfor (const tab of tabs) {\n\t\t\ttab.preview.setGlobalLeftWidth(globalLeftWidth);\n\t\t}\n\t}\n\n\tprivate buildSubmitPicker(): SubmitPicker | undefined {\n\t\treturn this.isMulti ? new SubmitPicker(this.theme) : undefined;\n\t}\n\n\tprivate buildTabBar(): TabBar | undefined {\n\t\treturn this.isMulti ? new TabBar(this.theme) : undefined;\n\t}\n\n\tprivate buildHeightComputers(tabs: ReadonlyArray<TabComponents>): HeightComputers {\n\t\tconst global = (width: number): number => {\n\t\t\tlet max = 0;\n\t\t\tfor (const tab of tabs) {\n\t\t\t\tconst h = tab.bodyHeights(width).max;\n\t\t\t\tif (h > max) max = h;\n\t\t\t}\n\t\t\treturn Math.max(1, max);\n\t\t};\n\t\tconst current = (width: number): number => {\n\t\t\tconst idx = Math.min(this.getCurrentTab(), tabs.length - 1);\n\t\t\treturn Math.max(0, tabs[idx]?.bodyHeights(width).current ?? 0);\n\t\t};\n\t\treturn { global, current };\n\t}\n\n\tprivate pickInitialActivePreview(tabs: ReadonlyArray<TabComponents>): StatefulView<PreviewPaneProps> {\n\t\tconst idx = selectActivePreviewPaneIndex(this.initialState.currentTab, this.questions.length);\n\t\treturn tabs[idx]?.preview ?? tabs[0]!.preview;\n\t}\n\n\tprivate buildDialog(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t\theights: HeightComputers,\n\t): DialogView {\n\t\treturn new DialogView(\n\t\t\t{\n\t\t\t\ttheme: this.theme,\n\t\t\t\tquestions: this.questions,\n\t\t\t\ttabBar,\n\t\t\t\tnotesInput: this.notesInput,\n\t\t\t\tchatRow: this.chatRow,\n\t\t\t\tisMulti: this.isMulti,\n\t\t\t\ttabsByIndex: tabs,\n\t\t\t\tsubmitPicker,\n\t\t\t\tgetBodyHeight: heights.global,\n\t\t\t\tgetCurrentBodyHeight: heights.current,\n\t\t\t},\n\t\t\t{ state: this.initialState, activePreviewPane: this.pickInitialActivePreview(tabs) },\n\t\t);\n\t}\n\n\tprivate buildGlobalBindings(\n\t\tdialog: DialogView,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t): ReadonlyArray<BoundGlobalBinding> {\n\t\treturn [\n\t\t\tglobalBinding({ component: dialog, select: selectDialogProps }),\n\t\t\tglobalBinding({ component: this.chatRow, select: selectChatRowProps }),\n\t\t\t...(submitPicker ? [globalBinding({ component: submitPicker, select: selectSubmitPickerProps })] : []),\n\t\t\t...(tabBar ? [globalBinding({ component: tabBar, select: selectTabBarProps })] : []),\n\t\t];\n\t}\n\n\tprivate buildPerTabBindings(): ReadonlyArray<BoundPerTabBinding> {\n\t\treturn [\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.optionList,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectOptionListProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.preview,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectPreviewPaneProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.multiSelect,\n\t\t\t\tselect: selectMultiSelectProps,\n\t\t\t}),\n\t\t];\n\t}\n\n\tprivate buildAdapter(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tglobalBindings: ReadonlyArray<BoundGlobalBinding>,\n\t\tperTabBindings: ReadonlyArray<BoundPerTabBinding>,\n\t): QuestionnairePropsAdapter {\n\t\treturn new QuestionnairePropsAdapter({\n\t\t\ttui: this.tui,\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t\ttabsByIndex: tabs,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\tglobalBindings,\n\t\t\tperTabBindings,\n\t\t\textraInvalidatables: [this.notesInput],\n\t\t});\n\t}\n\n\tprivate handle(adapter: QuestionnairePropsAdapter, dialog: DialogView): QuestionnaireBuilt {\n\t\treturn {\n\t\t\tadapter,\n\t\t\tnotesInput: this.notesInput,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\trender: (w) => dialog.render(w),\n\t\t\tinvalidate: () => adapter.invalidate(),\n\t\t};\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"build-questionnaire.js","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/build-questionnaire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAc,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EAGN,aAAa,EACb,aAAa,GACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,sDAAsD,CAAC;AAErG,OAAO,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AACzE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../../../../modes/interactive/theme/theme.js\";\nimport { Input } from \"@earendil-works/pi-tui\";\nimport type { QuestionData } from \"../tool/types.js\";\nimport {\n\ttype BoundGlobalBinding,\n\ttype BoundPerTabBinding,\n\tglobalBinding,\n\tperTabBinding,\n} from \"../view/component-binding.js\";\nimport { ChatRowView } from \"../view/components/chat-row-view.js\";\nimport { MultiSelectView } from \"../view/components/multi-select-view.js\";\nimport { OptionListView } from \"../view/components/option-list-view.js\";\nimport { PreviewBlockRenderer } from \"../view/components/preview/preview-block-renderer.js\";\nimport { crossTabLeftWidthWithDonation } from \"../view/components/preview/preview-layout-decider.js\";\nimport type { PreviewPaneProps } from \"../view/components/preview/preview-pane.js\";\nimport { PreviewPane } from \"../view/components/preview/preview-pane.js\";\nimport { SubmitPicker } from \"../view/components/submit-picker.js\";\nimport { TabBar } from \"../view/components/tab-bar.js\";\nimport type { WrappingSelectItem, WrappingSelectTheme } from \"../view/components/wrapping-select.js\";\nimport { DialogView } from \"../view/dialog-builder.js\";\nimport { QuestionnairePropsAdapter } from \"../view/props-adapter.js\";\nimport type { StatefulView } from \"../view/stateful-view.js\";\nimport type { TabBodyHeights, TabComponents } from \"../view/tab-components.js\";\nimport { ROW_INTENT_META } from \"./row-intent.js\";\nimport type { PerTabSelector } from \"./selectors/contract.js\";\nimport { selectActivePreviewPaneIndex } from \"./selectors/derivations.js\";\nimport {\n\tselectChatRowProps,\n\tselectDialogProps,\n\tselectMultiSelectProps,\n\tselectOptionListProps,\n\tselectPreviewPaneProps,\n\tselectSubmitPickerProps,\n\tselectTabBarProps,\n} from \"./selectors/projections.js\";\nimport type { QuestionnaireState } from \"./state.js\";\n\nexport interface QuestionnaireBuildConfig {\n\ttui: { terminal: { columns: number }; requestRender(): void };\n\ttheme: Theme;\n\tquestions: readonly QuestionData[];\n\titemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tisMulti: boolean;\n\tinitialState: QuestionnaireState;\n\tgetCurrentTab: () => number;\n}\n\nexport interface QuestionnaireBuilt {\n\tadapter: QuestionnairePropsAdapter;\n\tnotesInput: Input;\n\tinlineInput: Input;\n\trender: (width: number) => string[];\n\tinvalidate: () => void;\n}\n\ninterface HeightComputers {\n\tglobal: (width: number) => number;\n\tcurrent: (width: number) => number;\n}\n\nfunction previewBodyHeights(pane: PreviewPane): (width: number) => TabBodyHeights {\n\treturn (width) => ({\n\t\tcurrent: pane.naturalHeight(width),\n\t\tmax: pane.maxNaturalHeight(width),\n\t});\n}\n\nfunction multiSelectBodyHeights(view: MultiSelectView): (width: number) => TabBodyHeights {\n\treturn (width) => {\n\t\tconst h = view.naturalHeight(width);\n\t\treturn { current: h, max: h };\n\t};\n}\n\nconst isActiveTab: PerTabSelector<boolean> = (s, ctx) =>\n\tctx.i === selectActivePreviewPaneIndex(s.currentTab, ctx.totalQuestions);\n\n/**\n * Pure factory: assembles every TUI component, the props adapter, and a\n * lifecycle handle. Session-state dependencies arrive via `getCurrentTab` and\n * the `inputBuffer` cell. Initial paint is delegated to\n * `adapter.apply(initialState)` (called by the session at construction-end);\n * no selector is invoked here.\n */\nexport function buildQuestionnaire(config: QuestionnaireBuildConfig): QuestionnaireBuilt {\n\treturn new QuestionnaireBuilder(config).build();\n}\n\n/**\n * Programming-by-intention assembly: each private method names one\n * construction step from `build()`. Read top-down; the class is build-only and\n * discarded once the handle is returned.\n */\nclass QuestionnaireBuilder {\n\tprivate readonly tui: QuestionnaireBuildConfig[\"tui\"];\n\tprivate readonly theme: Theme;\n\tprivate readonly questions: readonly QuestionData[];\n\tprivate readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tprivate readonly isMulti: boolean;\n\tprivate readonly initialState: QuestionnaireState;\n\tprivate readonly getCurrentTab: () => number;\n\n\tprivate readonly selectTheme: WrappingSelectTheme;\n\tprivate readonly markdownTheme = getMarkdownTheme();\n\tprivate readonly chatRow: ChatRowView;\n\tprivate readonly notesInput = new Input();\n\tprivate readonly inlineInput = new Input();\n\tprivate readonly getTerminalWidth = () => this.tui.terminal.columns;\n\n\tconstructor(config: QuestionnaireBuildConfig) {\n\t\tthis.tui = config.tui;\n\t\tthis.theme = config.theme;\n\t\tthis.questions = config.questions;\n\t\tthis.itemsByTab = config.itemsByTab;\n\t\tthis.isMulti = config.isMulti;\n\t\tthis.initialState = config.initialState;\n\t\tthis.getCurrentTab = config.getCurrentTab;\n\n\t\tthis.selectTheme = this.makeSelectTheme();\n\t\tthis.chatRow = new ChatRowView({\n\t\t\titem: { kind: \"chat\", label: ROW_INTENT_META.chat.label },\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t}\n\n\tbuild(): QuestionnaireBuilt {\n\t\tconst tabs = this.buildTabComponents();\n\t\tthis.injectGlobalLeftWidth(tabs);\n\t\tconst submitPicker = this.buildSubmitPicker();\n\t\tconst tabBar = this.buildTabBar();\n\t\tconst heights = this.buildHeightComputers(tabs);\n\t\tconst dialog = this.buildDialog(tabs, submitPicker, tabBar, heights);\n\t\tconst globalBindings = this.buildGlobalBindings(dialog, submitPicker, tabBar);\n\t\tconst perTabBindings = this.buildPerTabBindings();\n\t\tconst adapter = this.buildAdapter(tabs, globalBindings, perTabBindings);\n\t\treturn this.handle(adapter, dialog);\n\t}\n\n\tprivate makeSelectTheme(): WrappingSelectTheme {\n\t\tconst t = this.theme;\n\t\treturn {\n\t\t\tselectedText: (s) => t.fg(\"accent\", t.bold(s)),\n\t\t\tdescription: (s) => t.fg(\"muted\", s),\n\t\t\tscrollInfo: (s) => t.fg(\"dim\", s),\n\t\t};\n\t}\n\n\tprivate buildTabComponents(): ReadonlyArray<TabComponents> {\n\t\treturn this.questions.map((q, i) => this.buildTabFor(q, i));\n\t}\n\n\tprivate buildTabFor(question: QuestionData, index: number): TabComponents {\n\t\tconst optionList = new OptionListView({\n\t\t\titems: this.itemsByTab[index] ?? [],\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t\tconst previewBlock = new PreviewBlockRenderer({\n\t\t\tquestion,\n\t\t\ttheme: this.theme,\n\t\t\tmarkdownTheme: this.markdownTheme,\n\t\t});\n\t\tconst preview = new PreviewPane({\n\t\t\tquestion,\n\t\t\tgetTerminalWidth: this.getTerminalWidth,\n\t\t\toptionListView: optionList,\n\t\t\tpreviewBlock,\n\t\t});\n\t\tconst multiSelect = question.multiSelect ? new MultiSelectView(this.theme, question) : undefined;\n\t\tconst bodyHeights = this.buildBodyHeights(question, preview, multiSelect);\n\t\treturn { optionList, preview, multiSelect, bodyHeights };\n\t}\n\n\tprivate buildBodyHeights(\n\t\tquestion: QuestionData,\n\t\tpreview: PreviewPane,\n\t\tmultiSelect: MultiSelectView | undefined,\n\t): (width: number) => TabBodyHeights {\n\t\treturn question.multiSelect ? multiSelectBodyHeights(multiSelect!) : previewBodyHeights(preview);\n\t}\n\n\t/**\n\t * Compute cross-tab max adaptive left width and inject into each PreviewPane.\n\t * Mirrors buildHeightComputers pattern — iterates all tabs, takes max.\n\t * Called after buildTabComponents, before buildDialog (so setGlobalLeftWidth\n\t * is set before any rendering occurs).\n\t */\n\tprivate injectGlobalLeftWidth(tabs: ReadonlyArray<TabComponents>): void {\n\t\tconst questions = this.questions;\n\t\tconst itemsByTab = this.itemsByTab;\n\t\tconst tabsDescriptor = questions.map((q) => ({ multiSelect: q.multiSelect }));\n\t\tconst globalLeftWidth = (paneWidth: number): number =>\n\t\t\tcrossTabLeftWidthWithDonation(tabsDescriptor, itemsByTab, questions, paneWidth);\n\t\tfor (const tab of tabs) {\n\t\t\ttab.preview.setGlobalLeftWidth(globalLeftWidth);\n\t\t}\n\t}\n\n\tprivate buildSubmitPicker(): SubmitPicker | undefined {\n\t\treturn this.isMulti ? new SubmitPicker(this.theme) : undefined;\n\t}\n\n\tprivate buildTabBar(): TabBar | undefined {\n\t\treturn this.isMulti ? new TabBar(this.theme) : undefined;\n\t}\n\n\tprivate buildHeightComputers(tabs: ReadonlyArray<TabComponents>): HeightComputers {\n\t\tconst global = (width: number): number => {\n\t\t\tlet max = 0;\n\t\t\tfor (const tab of tabs) {\n\t\t\t\tconst h = tab.bodyHeights(width).max;\n\t\t\t\tif (h > max) max = h;\n\t\t\t}\n\t\t\treturn Math.max(1, max);\n\t\t};\n\t\tconst current = (width: number): number => {\n\t\t\tconst idx = Math.min(this.getCurrentTab(), tabs.length - 1);\n\t\t\treturn Math.max(0, tabs[idx]?.bodyHeights(width).current ?? 0);\n\t\t};\n\t\treturn { global, current };\n\t}\n\n\tprivate pickInitialActivePreview(tabs: ReadonlyArray<TabComponents>): StatefulView<PreviewPaneProps> {\n\t\tconst idx = selectActivePreviewPaneIndex(this.initialState.currentTab, this.questions.length);\n\t\treturn tabs[idx]?.preview ?? tabs[0]!.preview;\n\t}\n\n\tprivate buildDialog(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t\theights: HeightComputers,\n\t): DialogView {\n\t\treturn new DialogView(\n\t\t\t{\n\t\t\t\ttheme: this.theme,\n\t\t\t\tquestions: this.questions,\n\t\t\t\ttabBar,\n\t\t\t\tnotesInput: this.notesInput,\n\t\t\t\tchatRow: this.chatRow,\n\t\t\t\tisMulti: this.isMulti,\n\t\t\t\ttabsByIndex: tabs,\n\t\t\t\tsubmitPicker,\n\t\t\t\tgetBodyHeight: heights.global,\n\t\t\t\tgetCurrentBodyHeight: heights.current,\n\t\t\t},\n\t\t\t{ state: this.initialState, activePreviewPane: this.pickInitialActivePreview(tabs) },\n\t\t);\n\t}\n\n\tprivate buildGlobalBindings(\n\t\tdialog: DialogView,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t): ReadonlyArray<BoundGlobalBinding> {\n\t\treturn [\n\t\t\tglobalBinding({ component: dialog, select: selectDialogProps }),\n\t\t\tglobalBinding({ component: this.chatRow, select: selectChatRowProps }),\n\t\t\t...(submitPicker ? [globalBinding({ component: submitPicker, select: selectSubmitPickerProps })] : []),\n\t\t\t...(tabBar ? [globalBinding({ component: tabBar, select: selectTabBarProps })] : []),\n\t\t];\n\t}\n\n\tprivate buildPerTabBindings(): ReadonlyArray<BoundPerTabBinding> {\n\t\treturn [\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.optionList,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectOptionListProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.preview,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectPreviewPaneProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.multiSelect,\n\t\t\t\tselect: selectMultiSelectProps,\n\t\t\t}),\n\t\t];\n\t}\n\n\tprivate buildAdapter(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tglobalBindings: ReadonlyArray<BoundGlobalBinding>,\n\t\tperTabBindings: ReadonlyArray<BoundPerTabBinding>,\n\t): QuestionnairePropsAdapter {\n\t\treturn new QuestionnairePropsAdapter({\n\t\t\ttui: this.tui,\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t\ttabsByIndex: tabs,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\tglobalBindings,\n\t\t\tperTabBindings,\n\t\t\textraInvalidatables: [this.notesInput],\n\t\t});\n\t}\n\n\tprivate handle(adapter: QuestionnairePropsAdapter, dialog: DialogView): QuestionnaireBuilt {\n\t\treturn {\n\t\t\tadapter,\n\t\t\tnotesInput: this.notesInput,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\trender: (w) => dialog.render(w),\n\t\t\tinvalidate: () => adapter.invalidate(),\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"build-questionnaire.js","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/build-questionnaire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAc,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAA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,CAAC;SACtC,CAAC,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,OAAkC,EAAE,MAAkB;QACpE,OAAO;YACN,OAAO;YACP,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YAC/B,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE;SACtC,CAAC;IACH,CAAC;CACD","sourcesContent":["import { getMarkdownTheme, type Theme } from \"../../../../modes/interactive/theme/theme.ts\";\nimport { Input } from \"@earendil-works/pi-tui\";\nimport type { QuestionData } from \"../tool/types.ts\";\nimport {\n\ttype BoundGlobalBinding,\n\ttype BoundPerTabBinding,\n\tglobalBinding,\n\tperTabBinding,\n} from \"../view/component-binding.ts\";\nimport { ChatRowView } from \"../view/components/chat-row-view.ts\";\nimport { MultiSelectView } from \"../view/components/multi-select-view.ts\";\nimport { OptionListView } from \"../view/components/option-list-view.ts\";\nimport { PreviewBlockRenderer } from \"../view/components/preview/preview-block-renderer.ts\";\nimport { crossTabLeftWidthWithDonation } from \"../view/components/preview/preview-layout-decider.ts\";\nimport type { PreviewPaneProps } from \"../view/components/preview/preview-pane.ts\";\nimport { PreviewPane } from \"../view/components/preview/preview-pane.ts\";\nimport { SubmitPicker } from \"../view/components/submit-picker.ts\";\nimport { TabBar } from \"../view/components/tab-bar.ts\";\nimport type { WrappingSelectItem, WrappingSelectTheme } from \"../view/components/wrapping-select.ts\";\nimport { DialogView } from \"../view/dialog-builder.ts\";\nimport { QuestionnairePropsAdapter } from \"../view/props-adapter.ts\";\nimport type { StatefulView } from \"../view/stateful-view.ts\";\nimport type { TabBodyHeights, TabComponents } from \"../view/tab-components.ts\";\nimport { ROW_INTENT_META } from \"./row-intent.ts\";\nimport type { PerTabSelector } from \"./selectors/contract.ts\";\nimport { selectActivePreviewPaneIndex } from \"./selectors/derivations.ts\";\nimport {\n\tselectChatRowProps,\n\tselectDialogProps,\n\tselectMultiSelectProps,\n\tselectOptionListProps,\n\tselectPreviewPaneProps,\n\tselectSubmitPickerProps,\n\tselectTabBarProps,\n} from \"./selectors/projections.ts\";\nimport type { QuestionnaireState } from \"./state.ts\";\n\nexport interface QuestionnaireBuildConfig {\n\ttui: { terminal: { columns: number }; requestRender(): void };\n\ttheme: Theme;\n\tquestions: readonly QuestionData[];\n\titemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tisMulti: boolean;\n\tinitialState: QuestionnaireState;\n\tgetCurrentTab: () => number;\n}\n\nexport interface QuestionnaireBuilt {\n\tadapter: QuestionnairePropsAdapter;\n\tnotesInput: Input;\n\tinlineInput: Input;\n\trender: (width: number) => string[];\n\tinvalidate: () => void;\n}\n\ninterface HeightComputers {\n\tglobal: (width: number) => number;\n\tcurrent: (width: number) => number;\n}\n\nfunction previewBodyHeights(pane: PreviewPane): (width: number) => TabBodyHeights {\n\treturn (width) => ({\n\t\tcurrent: pane.naturalHeight(width),\n\t\tmax: pane.maxNaturalHeight(width),\n\t});\n}\n\nfunction multiSelectBodyHeights(view: MultiSelectView): (width: number) => TabBodyHeights {\n\treturn (width) => {\n\t\tconst h = view.naturalHeight(width);\n\t\treturn { current: h, max: h };\n\t};\n}\n\nconst isActiveTab: PerTabSelector<boolean> = (s, ctx) =>\n\tctx.i === selectActivePreviewPaneIndex(s.currentTab, ctx.totalQuestions);\n\n/**\n * Pure factory: assembles every TUI component, the props adapter, and a\n * lifecycle handle. Session-state dependencies arrive via `getCurrentTab` and\n * the `inputBuffer` cell. Initial paint is delegated to\n * `adapter.apply(initialState)` (called by the session at construction-end);\n * no selector is invoked here.\n */\nexport function buildQuestionnaire(config: QuestionnaireBuildConfig): QuestionnaireBuilt {\n\treturn new QuestionnaireBuilder(config).build();\n}\n\n/**\n * Programming-by-intention assembly: each private method names one\n * construction step from `build()`. Read top-down; the class is build-only and\n * discarded once the handle is returned.\n */\nclass QuestionnaireBuilder {\n\tprivate readonly tui: QuestionnaireBuildConfig[\"tui\"];\n\tprivate readonly theme: Theme;\n\tprivate readonly questions: readonly QuestionData[];\n\tprivate readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tprivate readonly isMulti: boolean;\n\tprivate readonly initialState: QuestionnaireState;\n\tprivate readonly getCurrentTab: () => number;\n\n\tprivate readonly selectTheme: WrappingSelectTheme;\n\tprivate readonly markdownTheme = getMarkdownTheme();\n\tprivate readonly chatRow: ChatRowView;\n\tprivate readonly notesInput = new Input();\n\tprivate readonly inlineInput = new Input();\n\tprivate readonly getTerminalWidth = () => this.tui.terminal.columns;\n\n\tconstructor(config: QuestionnaireBuildConfig) {\n\t\tthis.tui = config.tui;\n\t\tthis.theme = config.theme;\n\t\tthis.questions = config.questions;\n\t\tthis.itemsByTab = config.itemsByTab;\n\t\tthis.isMulti = config.isMulti;\n\t\tthis.initialState = config.initialState;\n\t\tthis.getCurrentTab = config.getCurrentTab;\n\n\t\tthis.selectTheme = this.makeSelectTheme();\n\t\tthis.chatRow = new ChatRowView({\n\t\t\titem: { kind: \"chat\", label: ROW_INTENT_META.chat.label },\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t}\n\n\tbuild(): QuestionnaireBuilt {\n\t\tconst tabs = this.buildTabComponents();\n\t\tthis.injectGlobalLeftWidth(tabs);\n\t\tconst submitPicker = this.buildSubmitPicker();\n\t\tconst tabBar = this.buildTabBar();\n\t\tconst heights = this.buildHeightComputers(tabs);\n\t\tconst dialog = this.buildDialog(tabs, submitPicker, tabBar, heights);\n\t\tconst globalBindings = this.buildGlobalBindings(dialog, submitPicker, tabBar);\n\t\tconst perTabBindings = this.buildPerTabBindings();\n\t\tconst adapter = this.buildAdapter(tabs, globalBindings, perTabBindings);\n\t\treturn this.handle(adapter, dialog);\n\t}\n\n\tprivate makeSelectTheme(): WrappingSelectTheme {\n\t\tconst t = this.theme;\n\t\treturn {\n\t\t\tselectedText: (s) => t.fg(\"accent\", t.bold(s)),\n\t\t\tdescription: (s) => t.fg(\"muted\", s),\n\t\t\tscrollInfo: (s) => t.fg(\"dim\", s),\n\t\t};\n\t}\n\n\tprivate buildTabComponents(): ReadonlyArray<TabComponents> {\n\t\treturn this.questions.map((q, i) => this.buildTabFor(q, i));\n\t}\n\n\tprivate buildTabFor(question: QuestionData, index: number): TabComponents {\n\t\tconst optionList = new OptionListView({\n\t\t\titems: this.itemsByTab[index] ?? [],\n\t\t\ttheme: this.selectTheme,\n\t\t});\n\t\tconst previewBlock = new PreviewBlockRenderer({\n\t\t\tquestion,\n\t\t\ttheme: this.theme,\n\t\t\tmarkdownTheme: this.markdownTheme,\n\t\t});\n\t\tconst preview = new PreviewPane({\n\t\t\tquestion,\n\t\t\tgetTerminalWidth: this.getTerminalWidth,\n\t\t\toptionListView: optionList,\n\t\t\tpreviewBlock,\n\t\t});\n\t\tconst multiSelect = question.multiSelect ? new MultiSelectView(this.theme, question) : undefined;\n\t\tconst bodyHeights = this.buildBodyHeights(question, preview, multiSelect);\n\t\treturn { optionList, preview, multiSelect, bodyHeights };\n\t}\n\n\tprivate buildBodyHeights(\n\t\tquestion: QuestionData,\n\t\tpreview: PreviewPane,\n\t\tmultiSelect: MultiSelectView | undefined,\n\t): (width: number) => TabBodyHeights {\n\t\treturn question.multiSelect ? multiSelectBodyHeights(multiSelect!) : previewBodyHeights(preview);\n\t}\n\n\t/**\n\t * Compute cross-tab max adaptive left width and inject into each PreviewPane.\n\t * Mirrors buildHeightComputers pattern — iterates all tabs, takes max.\n\t * Called after buildTabComponents, before buildDialog (so setGlobalLeftWidth\n\t * is set before any rendering occurs).\n\t */\n\tprivate injectGlobalLeftWidth(tabs: ReadonlyArray<TabComponents>): void {\n\t\tconst questions = this.questions;\n\t\tconst itemsByTab = this.itemsByTab;\n\t\tconst tabsDescriptor = questions.map((q) => ({ multiSelect: q.multiSelect }));\n\t\tconst globalLeftWidth = (paneWidth: number): number =>\n\t\t\tcrossTabLeftWidthWithDonation(tabsDescriptor, itemsByTab, questions, paneWidth);\n\t\tfor (const tab of tabs) {\n\t\t\ttab.preview.setGlobalLeftWidth(globalLeftWidth);\n\t\t}\n\t}\n\n\tprivate buildSubmitPicker(): SubmitPicker | undefined {\n\t\treturn this.isMulti ? new SubmitPicker(this.theme) : undefined;\n\t}\n\n\tprivate buildTabBar(): TabBar | undefined {\n\t\treturn this.isMulti ? new TabBar(this.theme) : undefined;\n\t}\n\n\tprivate buildHeightComputers(tabs: ReadonlyArray<TabComponents>): HeightComputers {\n\t\tconst global = (width: number): number => {\n\t\t\tlet max = 0;\n\t\t\tfor (const tab of tabs) {\n\t\t\t\tconst h = tab.bodyHeights(width).max;\n\t\t\t\tif (h > max) max = h;\n\t\t\t}\n\t\t\treturn Math.max(1, max);\n\t\t};\n\t\tconst current = (width: number): number => {\n\t\t\tconst idx = Math.min(this.getCurrentTab(), tabs.length - 1);\n\t\t\treturn Math.max(0, tabs[idx]?.bodyHeights(width).current ?? 0);\n\t\t};\n\t\treturn { global, current };\n\t}\n\n\tprivate pickInitialActivePreview(tabs: ReadonlyArray<TabComponents>): StatefulView<PreviewPaneProps> {\n\t\tconst idx = selectActivePreviewPaneIndex(this.initialState.currentTab, this.questions.length);\n\t\treturn tabs[idx]?.preview ?? tabs[0]!.preview;\n\t}\n\n\tprivate buildDialog(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t\theights: HeightComputers,\n\t): DialogView {\n\t\treturn new DialogView(\n\t\t\t{\n\t\t\t\ttheme: this.theme,\n\t\t\t\tquestions: this.questions,\n\t\t\t\ttabBar,\n\t\t\t\tnotesInput: this.notesInput,\n\t\t\t\tchatRow: this.chatRow,\n\t\t\t\tisMulti: this.isMulti,\n\t\t\t\ttabsByIndex: tabs,\n\t\t\t\tsubmitPicker,\n\t\t\t\tgetBodyHeight: heights.global,\n\t\t\t\tgetCurrentBodyHeight: heights.current,\n\t\t\t},\n\t\t\t{ state: this.initialState, activePreviewPane: this.pickInitialActivePreview(tabs) },\n\t\t);\n\t}\n\n\tprivate buildGlobalBindings(\n\t\tdialog: DialogView,\n\t\tsubmitPicker: SubmitPicker | undefined,\n\t\ttabBar: TabBar | undefined,\n\t): ReadonlyArray<BoundGlobalBinding> {\n\t\treturn [\n\t\t\tglobalBinding({ component: dialog, select: selectDialogProps }),\n\t\t\tglobalBinding({ component: this.chatRow, select: selectChatRowProps }),\n\t\t\t...(submitPicker ? [globalBinding({ component: submitPicker, select: selectSubmitPickerProps })] : []),\n\t\t\t...(tabBar ? [globalBinding({ component: tabBar, select: selectTabBarProps })] : []),\n\t\t];\n\t}\n\n\tprivate buildPerTabBindings(): ReadonlyArray<BoundPerTabBinding> {\n\t\treturn [\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.optionList,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectOptionListProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.preview,\n\t\t\t\tpredicate: isActiveTab,\n\t\t\t\tselect: selectPreviewPaneProps,\n\t\t\t}),\n\t\t\tperTabBinding({\n\t\t\t\tresolve: (tab) => tab.multiSelect,\n\t\t\t\tselect: selectMultiSelectProps,\n\t\t\t}),\n\t\t];\n\t}\n\n\tprivate buildAdapter(\n\t\ttabs: ReadonlyArray<TabComponents>,\n\t\tglobalBindings: ReadonlyArray<BoundGlobalBinding>,\n\t\tperTabBindings: ReadonlyArray<BoundPerTabBinding>,\n\t): QuestionnairePropsAdapter {\n\t\treturn new QuestionnairePropsAdapter({\n\t\t\ttui: this.tui,\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t\ttabsByIndex: tabs,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\tglobalBindings,\n\t\t\tperTabBindings,\n\t\t\textraInvalidatables: [this.notesInput],\n\t\t});\n\t}\n\n\tprivate handle(adapter: QuestionnairePropsAdapter, dialog: DialogView): QuestionnaireBuilt {\n\t\treturn {\n\t\t\tadapter,\n\t\t\tnotesInput: this.notesInput,\n\t\t\tinlineInput: this.inlineInput,\n\t\t\trender: (w) => dialog.render(w),\n\t\t\tinvalidate: () => adapter.invalidate(),\n\t\t};\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { QuestionAnswer } from "../tool/types.js";
2
- import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
1
+ import type { QuestionAnswer } from "../tool/types.ts";
2
+ import type { QuestionnaireRuntime, QuestionnaireState } from "./state.ts";
3
3
  export type QuestionnaireAction = {
4
4
  kind: "nav";
5
5
  nextIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"key-router.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/key-router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAU3E,MAAM,MAAM,mBAAmB,GAC5B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE;AACxB;;;GAGG;GACD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEtB,MAAM,WAAW,wBAAwB;IACxC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAM7F;AAkGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,oBAAoB,GAAG,mBAAmB,CAwHpH","sourcesContent":["import { Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport type { QuestionAnswer } from \"../tool/types.js\";\nimport { ROW_INTENT_META } from \"./row-intent.js\";\nimport type { QuestionnaireRuntime, QuestionnaireState } from \"./state.js\";\n\nconst KEYBIND_UP = \"tui.select.up\";\nconst KEYBIND_DOWN = \"tui.select.down\";\nconst KEYBIND_CONFIRM = \"tui.select.confirm\";\nconst KEYBIND_CANCEL = \"tui.select.cancel\";\n\nconst NOTES_ACTIVATE_KEY = \"n\";\nconst SPACE_KEY = \" \";\n\nexport type QuestionnaireAction =\n\t| { kind: \"nav\"; nextIndex: number }\n\t| { kind: \"tab_switch\"; nextTab: number }\n\t| { kind: \"confirm\"; answer: QuestionAnswer; autoAdvanceTab?: number }\n\t| { kind: \"toggle\"; index: number }\n\t| { kind: \"multi_confirm\"; selected: string[]; autoAdvanceTab?: number }\n\t| { kind: \"cancel\" }\n\t| { kind: \"notes_enter\" }\n\t| { kind: \"notes_exit\" }\n\t| { kind: \"submit\" }\n\t| { kind: \"submit_nav\"; nextIndex: 0 | 1 }\n\t| { kind: \"focus_chat\" }\n\t/**\n\t * Carries the target index so UP/DOWN form a continuous cycle through\n\t * `[chat, option0, …, optionLast]`.\n\t */\n\t| { kind: \"focus_options\"; optionIndex: number }\n\t| { kind: \"notes_forward\"; data: string }\n\t| { kind: \"ignore\" };\n\nexport interface QuestionnaireKeybindings {\n\tmatches(data: string, name: string): boolean;\n}\n\nexport function wrapTab(index: number, total: number): number {\n\tif (total <= 0) return 0;\n\treturn ((index % total) + total) % total;\n}\n\nexport function allAnswered(state: QuestionnaireState, runtime: QuestionnaireRuntime): boolean {\n\tif (runtime.questions.length === 0) return false;\n\tfor (let i = 0; i < runtime.questions.length; i++) {\n\t\tif (!state.answers.has(i)) return false;\n\t}\n\treturn true;\n}\n\nfunction totalTabs(runtime: QuestionnaireRuntime): number {\n\treturn runtime.isMulti ? runtime.questions.length + 1 : 1;\n}\n\nfunction computeAutoAdvanceTab(state: QuestionnaireState, runtime: QuestionnaireRuntime): number | undefined {\n\tif (!runtime.isMulti) return undefined;\n\tif (state.currentTab < runtime.questions.length - 1) return state.currentTab + 1;\n\treturn runtime.questions.length;\n}\n\nfunction buildSingleSelectAnswer(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionAnswer | null {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return null;\n\n\t// Chat sentinel takes priority over inputMode: when chatFocused=true, the host overrides\n\t// currentItem() to return the chat sentinel even if inputMode is still true (e.g. user\n\t// navigated from \"Type something.\" and DOWN focused the chat row).\n\tconst item = runtime.currentItem;\n\tif (item?.kind === \"chat\") {\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"chat\",\n\t\t\tanswer: item.label,\n\t\t};\n\t}\n\n\tif (state.inputMode) {\n\t\tconst label = runtime.inputBuffer;\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"custom\",\n\t\t\tanswer: label.length > 0 ? label : null,\n\t\t};\n\t}\n\tif (!item) return null;\n\tif (item.kind === \"other\") {\n\t\treturn null;\n\t}\n\tif (item.kind === \"next\") {\n\t\treturn null;\n\t}\n\treturn {\n\t\tquestionIndex: state.currentTab,\n\t\tquestion: q.question,\n\t\tkind: \"option\",\n\t\tanswer: item.label,\n\t};\n}\n\nfunction buildMultiSelected(state: QuestionnaireState, runtime: QuestionnaireRuntime): string[] {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return [];\n\tconst out: string[] = [];\n\tfor (let i = 0; i < q.options.length; i++) {\n\t\tif (state.multiSelectChecked.has(i)) {\n\t\t\tconst label = q.options[i]?.label;\n\t\t\tif (typeof label === \"string\") out.push(label);\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction tabSwitchAction(\n\tdata: string,\n\tstate: QuestionnaireState,\n\truntime: QuestionnaireRuntime,\n): QuestionnaireAction | null {\n\tif (!runtime.isMulti) return null;\n\tconst total = totalTabs(runtime);\n\tif (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab + 1, total) };\n\t}\n\tif (matchesKey(data, Key.shift(\"tab\")) || matchesKey(data, Key.left)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab - 1, total) };\n\t}\n\treturn null;\n}\n\n// DOWN at the last item emits focus_chat so the cycle [chat, option0, …, optionLast] wraps.\nfunction nextNavOnDown(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === runtime.items.length - 1) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex + 1, Math.max(1, runtime.items.length)) };\n}\n\n// UP at the top item emits focus_chat (symmetric with nextNavOnDown).\nfunction prevNavOnUp(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === 0) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex - 1, Math.max(1, runtime.items.length)) };\n}\n\nexport function routeKey(data: string, state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tconst kb = runtime.keybindings;\n\n\tif (state.notesVisible) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"notes_exit\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) return { kind: \"notes_exit\" };\n\t\treturn { kind: \"notes_forward\", data };\n\t}\n\n\tif (state.chatFocused) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\t// Continuous cycle: UP from chat → bottom of options (last navigable row), DOWN from\n\t\t// chat → top of options (option 0). Symmetric with UP-at-top → focus_chat and\n\t\t// DOWN-at-bottom → focus_chat below; together they form one wrapping cycle through\n\t\t// `[chat, option0, …, optionLast]`.\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\tconst last = Math.max(0, runtime.items.length - 1);\n\t\t\treturn { kind: \"focus_options\", optionIndex: last };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn { kind: \"focus_options\", optionIndex: 0 };\n\t\t}\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (state.inputMode) {\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\treturn prevNavOnUp(state, runtime);\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn nextNavOnDown(state, runtime);\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (runtime.isMulti && state.currentTab === runtime.questions.length) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\tif (kb.matches(data, KEYBIND_UP) || kb.matches(data, KEYBIND_DOWN)) {\n\t\t\tconst delta = kb.matches(data, KEYBIND_DOWN) ? 1 : -1;\n\t\t\tconst next = wrapTab(state.submitChoiceIndex + delta, 2);\n\t\t\treturn { kind: \"submit_nav\", nextIndex: (next === 1 ? 1 : 0) as 0 | 1 };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// D1 (revised): Submit always submits; Cancel always cancels. The warning header\n\t\t\t// is informational only — `allAnswered(state)` no longer gates submission. Partial\n\t\t\t// answers flow through `orderedAnswers()` in the host.\n\t\t\treturn state.submitChoiceIndex === 1 ? { kind: \"cancel\" } : { kind: \"submit\" };\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tconst tab = tabSwitchAction(data, state, runtime);\n\tif (tab) return tab;\n\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return { kind: \"ignore\" };\n\n\tif (data === NOTES_ACTIVATE_KEY && !q.multiSelect && state.focusedOptionHasPreview) {\n\t\treturn { kind: \"notes_enter\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_UP)) {\n\t\treturn prevNavOnUp(state, runtime);\n\t}\n\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\treturn nextNavOnDown(state, runtime);\n\t}\n\n\tif (q.multiSelect) {\n\t\tconst focusedKind = runtime.currentItem?.kind;\n\t\tconst focusedMeta = focusedKind ? ROW_INTENT_META[focusedKind] : undefined;\n\t\t// Space toggles the focused row's checkbox. Suppressed on rows whose META declares\n\t\t// `blocksMultiToggle` (the Next sentinel) — Next is not a real option and has no\n\t\t// checked/unchecked state.\n\t\tif (data === SPACE_KEY) {\n\t\t\tif (focusedMeta?.blocksMultiToggle) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"toggle\", index: state.optionIndex };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// Enter on a regular row toggles (matching Space) — committing the question is now\n\t\t\t// gated behind explicit focus on a row whose META declares `autoSubmitsInMulti`\n\t\t\t// (the Next sentinel), so Enter on options is a no-cost way to flip checkboxes\n\t\t\t// without leaving the keyboard home row.\n\t\t\tif (!focusedMeta?.autoSubmitsInMulti) return { kind: \"toggle\", index: state.optionIndex };\n\t\t\t// Enter on Next: carry autoAdvanceTab so the host can advance to the next tab in\n\t\t\t// multi-question mode, OR submit the dialog in single-question mode\n\t\t\t// (autoAdvanceTab === undefined when !isMulti). Without this, a single multi-select\n\t\t\t// question would have no way to commit at all.\n\t\t\treturn {\n\t\t\t\tkind: \"multi_confirm\",\n\t\t\t\tselected: buildMultiSelected(state, runtime),\n\t\t\t\tautoAdvanceTab: computeAutoAdvanceTab(state, runtime),\n\t\t\t};\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\tif (!answer) return { kind: \"ignore\" };\n\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t}\n\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\treturn { kind: \"ignore\" };\n}\n"]}
1
+ {"version":3,"file":"key-router.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/key-router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAU3E,MAAM,MAAM,mBAAmB,GAC5B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE;AACxB;;;GAGG;GACD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEtB,MAAM,WAAW,wBAAwB;IACxC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAM7F;AAkGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,oBAAoB,GAAG,mBAAmB,CAwHpH","sourcesContent":["import { Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport type { QuestionAnswer } from \"../tool/types.ts\";\nimport { ROW_INTENT_META } from \"./row-intent.ts\";\nimport type { QuestionnaireRuntime, QuestionnaireState } from \"./state.ts\";\n\nconst KEYBIND_UP = \"tui.select.up\";\nconst KEYBIND_DOWN = \"tui.select.down\";\nconst KEYBIND_CONFIRM = \"tui.select.confirm\";\nconst KEYBIND_CANCEL = \"tui.select.cancel\";\n\nconst NOTES_ACTIVATE_KEY = \"n\";\nconst SPACE_KEY = \" \";\n\nexport type QuestionnaireAction =\n\t| { kind: \"nav\"; nextIndex: number }\n\t| { kind: \"tab_switch\"; nextTab: number }\n\t| { kind: \"confirm\"; answer: QuestionAnswer; autoAdvanceTab?: number }\n\t| { kind: \"toggle\"; index: number }\n\t| { kind: \"multi_confirm\"; selected: string[]; autoAdvanceTab?: number }\n\t| { kind: \"cancel\" }\n\t| { kind: \"notes_enter\" }\n\t| { kind: \"notes_exit\" }\n\t| { kind: \"submit\" }\n\t| { kind: \"submit_nav\"; nextIndex: 0 | 1 }\n\t| { kind: \"focus_chat\" }\n\t/**\n\t * Carries the target index so UP/DOWN form a continuous cycle through\n\t * `[chat, option0, …, optionLast]`.\n\t */\n\t| { kind: \"focus_options\"; optionIndex: number }\n\t| { kind: \"notes_forward\"; data: string }\n\t| { kind: \"ignore\" };\n\nexport interface QuestionnaireKeybindings {\n\tmatches(data: string, name: string): boolean;\n}\n\nexport function wrapTab(index: number, total: number): number {\n\tif (total <= 0) return 0;\n\treturn ((index % total) + total) % total;\n}\n\nexport function allAnswered(state: QuestionnaireState, runtime: QuestionnaireRuntime): boolean {\n\tif (runtime.questions.length === 0) return false;\n\tfor (let i = 0; i < runtime.questions.length; i++) {\n\t\tif (!state.answers.has(i)) return false;\n\t}\n\treturn true;\n}\n\nfunction totalTabs(runtime: QuestionnaireRuntime): number {\n\treturn runtime.isMulti ? runtime.questions.length + 1 : 1;\n}\n\nfunction computeAutoAdvanceTab(state: QuestionnaireState, runtime: QuestionnaireRuntime): number | undefined {\n\tif (!runtime.isMulti) return undefined;\n\tif (state.currentTab < runtime.questions.length - 1) return state.currentTab + 1;\n\treturn runtime.questions.length;\n}\n\nfunction buildSingleSelectAnswer(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionAnswer | null {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return null;\n\n\t// Chat sentinel takes priority over inputMode: when chatFocused=true, the host overrides\n\t// currentItem() to return the chat sentinel even if inputMode is still true (e.g. user\n\t// navigated from \"Type something.\" and DOWN focused the chat row).\n\tconst item = runtime.currentItem;\n\tif (item?.kind === \"chat\") {\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"chat\",\n\t\t\tanswer: item.label,\n\t\t};\n\t}\n\n\tif (state.inputMode) {\n\t\tconst label = runtime.inputBuffer;\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"custom\",\n\t\t\tanswer: label.length > 0 ? label : null,\n\t\t};\n\t}\n\tif (!item) return null;\n\tif (item.kind === \"other\") {\n\t\treturn null;\n\t}\n\tif (item.kind === \"next\") {\n\t\treturn null;\n\t}\n\treturn {\n\t\tquestionIndex: state.currentTab,\n\t\tquestion: q.question,\n\t\tkind: \"option\",\n\t\tanswer: item.label,\n\t};\n}\n\nfunction buildMultiSelected(state: QuestionnaireState, runtime: QuestionnaireRuntime): string[] {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return [];\n\tconst out: string[] = [];\n\tfor (let i = 0; i < q.options.length; i++) {\n\t\tif (state.multiSelectChecked.has(i)) {\n\t\t\tconst label = q.options[i]?.label;\n\t\t\tif (typeof label === \"string\") out.push(label);\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction tabSwitchAction(\n\tdata: string,\n\tstate: QuestionnaireState,\n\truntime: QuestionnaireRuntime,\n): QuestionnaireAction | null {\n\tif (!runtime.isMulti) return null;\n\tconst total = totalTabs(runtime);\n\tif (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab + 1, total) };\n\t}\n\tif (matchesKey(data, Key.shift(\"tab\")) || matchesKey(data, Key.left)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab - 1, total) };\n\t}\n\treturn null;\n}\n\n// DOWN at the last item emits focus_chat so the cycle [chat, option0, …, optionLast] wraps.\nfunction nextNavOnDown(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === runtime.items.length - 1) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex + 1, Math.max(1, runtime.items.length)) };\n}\n\n// UP at the top item emits focus_chat (symmetric with nextNavOnDown).\nfunction prevNavOnUp(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === 0) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex - 1, Math.max(1, runtime.items.length)) };\n}\n\nexport function routeKey(data: string, state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tconst kb = runtime.keybindings;\n\n\tif (state.notesVisible) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"notes_exit\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) return { kind: \"notes_exit\" };\n\t\treturn { kind: \"notes_forward\", data };\n\t}\n\n\tif (state.chatFocused) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\t// Continuous cycle: UP from chat → bottom of options (last navigable row), DOWN from\n\t\t// chat → top of options (option 0). Symmetric with UP-at-top → focus_chat and\n\t\t// DOWN-at-bottom → focus_chat below; together they form one wrapping cycle through\n\t\t// `[chat, option0, …, optionLast]`.\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\tconst last = Math.max(0, runtime.items.length - 1);\n\t\t\treturn { kind: \"focus_options\", optionIndex: last };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn { kind: \"focus_options\", optionIndex: 0 };\n\t\t}\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (state.inputMode) {\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\treturn prevNavOnUp(state, runtime);\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn nextNavOnDown(state, runtime);\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (runtime.isMulti && state.currentTab === runtime.questions.length) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\tif (kb.matches(data, KEYBIND_UP) || kb.matches(data, KEYBIND_DOWN)) {\n\t\t\tconst delta = kb.matches(data, KEYBIND_DOWN) ? 1 : -1;\n\t\t\tconst next = wrapTab(state.submitChoiceIndex + delta, 2);\n\t\t\treturn { kind: \"submit_nav\", nextIndex: (next === 1 ? 1 : 0) as 0 | 1 };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// D1 (revised): Submit always submits; Cancel always cancels. The warning header\n\t\t\t// is informational only — `allAnswered(state)` no longer gates submission. Partial\n\t\t\t// answers flow through `orderedAnswers()` in the host.\n\t\t\treturn state.submitChoiceIndex === 1 ? { kind: \"cancel\" } : { kind: \"submit\" };\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tconst tab = tabSwitchAction(data, state, runtime);\n\tif (tab) return tab;\n\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return { kind: \"ignore\" };\n\n\tif (data === NOTES_ACTIVATE_KEY && !q.multiSelect && state.focusedOptionHasPreview) {\n\t\treturn { kind: \"notes_enter\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_UP)) {\n\t\treturn prevNavOnUp(state, runtime);\n\t}\n\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\treturn nextNavOnDown(state, runtime);\n\t}\n\n\tif (q.multiSelect) {\n\t\tconst focusedKind = runtime.currentItem?.kind;\n\t\tconst focusedMeta = focusedKind ? ROW_INTENT_META[focusedKind] : undefined;\n\t\t// Space toggles the focused row's checkbox. Suppressed on rows whose META declares\n\t\t// `blocksMultiToggle` (the Next sentinel) — Next is not a real option and has no\n\t\t// checked/unchecked state.\n\t\tif (data === SPACE_KEY) {\n\t\t\tif (focusedMeta?.blocksMultiToggle) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"toggle\", index: state.optionIndex };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// Enter on a regular row toggles (matching Space) — committing the question is now\n\t\t\t// gated behind explicit focus on a row whose META declares `autoSubmitsInMulti`\n\t\t\t// (the Next sentinel), so Enter on options is a no-cost way to flip checkboxes\n\t\t\t// without leaving the keyboard home row.\n\t\t\tif (!focusedMeta?.autoSubmitsInMulti) return { kind: \"toggle\", index: state.optionIndex };\n\t\t\t// Enter on Next: carry autoAdvanceTab so the host can advance to the next tab in\n\t\t\t// multi-question mode, OR submit the dialog in single-question mode\n\t\t\t// (autoAdvanceTab === undefined when !isMulti). Without this, a single multi-select\n\t\t\t// question would have no way to commit at all.\n\t\t\treturn {\n\t\t\t\tkind: \"multi_confirm\",\n\t\t\t\tselected: buildMultiSelected(state, runtime),\n\t\t\t\tautoAdvanceTab: computeAutoAdvanceTab(state, runtime),\n\t\t\t};\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\tif (!answer) return { kind: \"ignore\" };\n\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t}\n\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\treturn { kind: \"ignore\" };\n}\n"]}
@@ -1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YAC/E,yCAAyC;YACzC,IAAI,CAAC,WAAW,EAAE,kBAAkB;gBAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;YAC1F,iFAAiF;YACjF,oEAAoE;YACpE,oFAAoF;YACpF,+CAA+C;YAC/C,OAAO;gBACN,IAAI,EAAE,eAAe;gBACrB,QAAQ,EAAE,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC;gBAC5C,cAAc,EAAE,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC;aACrD,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAChE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACvC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;IAC3F,CAAC;IACD,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAChE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import { Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport type { QuestionAnswer } from \"../tool/types.js\";\nimport { ROW_INTENT_META } from \"./row-intent.js\";\nimport type { QuestionnaireRuntime, QuestionnaireState } from \"./state.js\";\n\nconst KEYBIND_UP = \"tui.select.up\";\nconst KEYBIND_DOWN = \"tui.select.down\";\nconst KEYBIND_CONFIRM = \"tui.select.confirm\";\nconst KEYBIND_CANCEL = \"tui.select.cancel\";\n\nconst NOTES_ACTIVATE_KEY = \"n\";\nconst SPACE_KEY = \" \";\n\nexport type QuestionnaireAction =\n\t| { kind: \"nav\"; nextIndex: number }\n\t| { kind: \"tab_switch\"; nextTab: number }\n\t| { kind: \"confirm\"; answer: QuestionAnswer; autoAdvanceTab?: number }\n\t| { kind: \"toggle\"; index: number }\n\t| { kind: \"multi_confirm\"; selected: string[]; autoAdvanceTab?: number }\n\t| { kind: \"cancel\" }\n\t| { kind: \"notes_enter\" }\n\t| { kind: \"notes_exit\" }\n\t| { kind: \"submit\" }\n\t| { kind: \"submit_nav\"; nextIndex: 0 | 1 }\n\t| { kind: \"focus_chat\" }\n\t/**\n\t * Carries the target index so UP/DOWN form a continuous cycle through\n\t * `[chat, option0, …, optionLast]`.\n\t */\n\t| { kind: \"focus_options\"; optionIndex: number }\n\t| { kind: \"notes_forward\"; data: string }\n\t| { kind: \"ignore\" };\n\nexport interface QuestionnaireKeybindings {\n\tmatches(data: string, name: string): boolean;\n}\n\nexport function wrapTab(index: number, total: number): number {\n\tif (total <= 0) return 0;\n\treturn ((index % total) + total) % total;\n}\n\nexport function allAnswered(state: QuestionnaireState, runtime: QuestionnaireRuntime): boolean {\n\tif (runtime.questions.length === 0) return false;\n\tfor (let i = 0; i < runtime.questions.length; i++) {\n\t\tif (!state.answers.has(i)) return false;\n\t}\n\treturn true;\n}\n\nfunction totalTabs(runtime: QuestionnaireRuntime): number {\n\treturn runtime.isMulti ? runtime.questions.length + 1 : 1;\n}\n\nfunction computeAutoAdvanceTab(state: QuestionnaireState, runtime: QuestionnaireRuntime): number | undefined {\n\tif (!runtime.isMulti) return undefined;\n\tif (state.currentTab < runtime.questions.length - 1) return state.currentTab + 1;\n\treturn runtime.questions.length;\n}\n\nfunction buildSingleSelectAnswer(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionAnswer | null {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return null;\n\n\t// Chat sentinel takes priority over inputMode: when chatFocused=true, the host overrides\n\t// currentItem() to return the chat sentinel even if inputMode is still true (e.g. user\n\t// navigated from \"Type something.\" and DOWN focused the chat row).\n\tconst item = runtime.currentItem;\n\tif (item?.kind === \"chat\") {\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"chat\",\n\t\t\tanswer: item.label,\n\t\t};\n\t}\n\n\tif (state.inputMode) {\n\t\tconst label = runtime.inputBuffer;\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"custom\",\n\t\t\tanswer: label.length > 0 ? label : null,\n\t\t};\n\t}\n\tif (!item) return null;\n\tif (item.kind === \"other\") {\n\t\treturn null;\n\t}\n\tif (item.kind === \"next\") {\n\t\treturn null;\n\t}\n\treturn {\n\t\tquestionIndex: state.currentTab,\n\t\tquestion: q.question,\n\t\tkind: \"option\",\n\t\tanswer: item.label,\n\t};\n}\n\nfunction buildMultiSelected(state: QuestionnaireState, runtime: QuestionnaireRuntime): string[] {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return [];\n\tconst out: string[] = [];\n\tfor (let i = 0; i < q.options.length; i++) {\n\t\tif (state.multiSelectChecked.has(i)) {\n\t\t\tconst label = q.options[i]?.label;\n\t\t\tif (typeof label === \"string\") out.push(label);\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction tabSwitchAction(\n\tdata: string,\n\tstate: QuestionnaireState,\n\truntime: QuestionnaireRuntime,\n): QuestionnaireAction | null {\n\tif (!runtime.isMulti) return null;\n\tconst total = totalTabs(runtime);\n\tif (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab + 1, total) };\n\t}\n\tif (matchesKey(data, Key.shift(\"tab\")) || matchesKey(data, Key.left)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab - 1, total) };\n\t}\n\treturn null;\n}\n\n// DOWN at the last item emits focus_chat so the cycle [chat, option0, …, optionLast] wraps.\nfunction nextNavOnDown(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === runtime.items.length - 1) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex + 1, Math.max(1, runtime.items.length)) };\n}\n\n// UP at the top item emits focus_chat (symmetric with nextNavOnDown).\nfunction prevNavOnUp(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === 0) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex - 1, Math.max(1, runtime.items.length)) };\n}\n\nexport function routeKey(data: string, state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tconst kb = runtime.keybindings;\n\n\tif (state.notesVisible) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"notes_exit\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) return { kind: \"notes_exit\" };\n\t\treturn { kind: \"notes_forward\", data };\n\t}\n\n\tif (state.chatFocused) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\t// Continuous cycle: UP from chat → bottom of options (last navigable row), DOWN from\n\t\t// chat → top of options (option 0). Symmetric with UP-at-top → focus_chat and\n\t\t// DOWN-at-bottom → focus_chat below; together they form one wrapping cycle through\n\t\t// `[chat, option0, …, optionLast]`.\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\tconst last = Math.max(0, runtime.items.length - 1);\n\t\t\treturn { kind: \"focus_options\", optionIndex: last };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn { kind: \"focus_options\", optionIndex: 0 };\n\t\t}\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (state.inputMode) {\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\treturn prevNavOnUp(state, runtime);\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn nextNavOnDown(state, runtime);\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (runtime.isMulti && state.currentTab === runtime.questions.length) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\tif (kb.matches(data, KEYBIND_UP) || kb.matches(data, KEYBIND_DOWN)) {\n\t\t\tconst delta = kb.matches(data, KEYBIND_DOWN) ? 1 : -1;\n\t\t\tconst next = wrapTab(state.submitChoiceIndex + delta, 2);\n\t\t\treturn { kind: \"submit_nav\", nextIndex: (next === 1 ? 1 : 0) as 0 | 1 };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// D1 (revised): Submit always submits; Cancel always cancels. The warning header\n\t\t\t// is informational only — `allAnswered(state)` no longer gates submission. Partial\n\t\t\t// answers flow through `orderedAnswers()` in the host.\n\t\t\treturn state.submitChoiceIndex === 1 ? { kind: \"cancel\" } : { kind: \"submit\" };\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tconst tab = tabSwitchAction(data, state, runtime);\n\tif (tab) return tab;\n\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return { kind: \"ignore\" };\n\n\tif (data === NOTES_ACTIVATE_KEY && !q.multiSelect && state.focusedOptionHasPreview) {\n\t\treturn { kind: \"notes_enter\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_UP)) {\n\t\treturn prevNavOnUp(state, runtime);\n\t}\n\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\treturn nextNavOnDown(state, runtime);\n\t}\n\n\tif (q.multiSelect) {\n\t\tconst focusedKind = runtime.currentItem?.kind;\n\t\tconst focusedMeta = focusedKind ? ROW_INTENT_META[focusedKind] : undefined;\n\t\t// Space toggles the focused row's checkbox. Suppressed on rows whose META declares\n\t\t// `blocksMultiToggle` (the Next sentinel) — Next is not a real option and has no\n\t\t// checked/unchecked state.\n\t\tif (data === SPACE_KEY) {\n\t\t\tif (focusedMeta?.blocksMultiToggle) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"toggle\", index: state.optionIndex };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// Enter on a regular row toggles (matching Space) — committing the question is now\n\t\t\t// gated behind explicit focus on a row whose META declares `autoSubmitsInMulti`\n\t\t\t// (the Next sentinel), so Enter on options is a no-cost way to flip checkboxes\n\t\t\t// without leaving the keyboard home row.\n\t\t\tif (!focusedMeta?.autoSubmitsInMulti) return { kind: \"toggle\", index: state.optionIndex };\n\t\t\t// Enter on Next: carry autoAdvanceTab so the host can advance to the next tab in\n\t\t\t// multi-question mode, OR submit the dialog in single-question mode\n\t\t\t// (autoAdvanceTab === undefined when !isMulti). Without this, a single multi-select\n\t\t\t// question would have no way to commit at all.\n\t\t\treturn {\n\t\t\t\tkind: \"multi_confirm\",\n\t\t\t\tselected: buildMultiSelected(state, runtime),\n\t\t\t\tautoAdvanceTab: computeAutoAdvanceTab(state, runtime),\n\t\t\t};\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\tif (!answer) return { kind: \"ignore\" };\n\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t}\n\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\treturn { kind: \"ignore\" };\n}\n"]}
1
+ {"version":3,"file":"key-router.js","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/key-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,UAAU,GAAG,eAAe,CAAC;AACnC,MAAM,YAAY,GAAG,iBAAiB,CAAC;AACvC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAC7C,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAE3C,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,SAAS,GAAG,GAAG,CAAC;AA0BtB,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,KAAa;IACnD,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACzB,OAAO,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB,EAAE,OAA6B;IACnF,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACjD,KAAK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AAI,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;IAC3F,CAAC;IACD,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAChE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import { Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport type { QuestionAnswer } from \"../tool/types.ts\";\nimport { ROW_INTENT_META } from \"./row-intent.ts\";\nimport type { QuestionnaireRuntime, QuestionnaireState } from \"./state.ts\";\n\nconst KEYBIND_UP = \"tui.select.up\";\nconst KEYBIND_DOWN = \"tui.select.down\";\nconst KEYBIND_CONFIRM = \"tui.select.confirm\";\nconst KEYBIND_CANCEL = \"tui.select.cancel\";\n\nconst NOTES_ACTIVATE_KEY = \"n\";\nconst SPACE_KEY = \" \";\n\nexport type QuestionnaireAction =\n\t| { kind: \"nav\"; nextIndex: number }\n\t| { kind: \"tab_switch\"; nextTab: number }\n\t| { kind: \"confirm\"; answer: QuestionAnswer; autoAdvanceTab?: number }\n\t| { kind: \"toggle\"; index: number }\n\t| { kind: \"multi_confirm\"; selected: string[]; autoAdvanceTab?: number }\n\t| { kind: \"cancel\" }\n\t| { kind: \"notes_enter\" }\n\t| { kind: \"notes_exit\" }\n\t| { kind: \"submit\" }\n\t| { kind: \"submit_nav\"; nextIndex: 0 | 1 }\n\t| { kind: \"focus_chat\" }\n\t/**\n\t * Carries the target index so UP/DOWN form a continuous cycle through\n\t * `[chat, option0, …, optionLast]`.\n\t */\n\t| { kind: \"focus_options\"; optionIndex: number }\n\t| { kind: \"notes_forward\"; data: string }\n\t| { kind: \"ignore\" };\n\nexport interface QuestionnaireKeybindings {\n\tmatches(data: string, name: string): boolean;\n}\n\nexport function wrapTab(index: number, total: number): number {\n\tif (total <= 0) return 0;\n\treturn ((index % total) + total) % total;\n}\n\nexport function allAnswered(state: QuestionnaireState, runtime: QuestionnaireRuntime): boolean {\n\tif (runtime.questions.length === 0) return false;\n\tfor (let i = 0; i < runtime.questions.length; i++) {\n\t\tif (!state.answers.has(i)) return false;\n\t}\n\treturn true;\n}\n\nfunction totalTabs(runtime: QuestionnaireRuntime): number {\n\treturn runtime.isMulti ? runtime.questions.length + 1 : 1;\n}\n\nfunction computeAutoAdvanceTab(state: QuestionnaireState, runtime: QuestionnaireRuntime): number | undefined {\n\tif (!runtime.isMulti) return undefined;\n\tif (state.currentTab < runtime.questions.length - 1) return state.currentTab + 1;\n\treturn runtime.questions.length;\n}\n\nfunction buildSingleSelectAnswer(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionAnswer | null {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return null;\n\n\t// Chat sentinel takes priority over inputMode: when chatFocused=true, the host overrides\n\t// currentItem() to return the chat sentinel even if inputMode is still true (e.g. user\n\t// navigated from \"Type something.\" and DOWN focused the chat row).\n\tconst item = runtime.currentItem;\n\tif (item?.kind === \"chat\") {\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"chat\",\n\t\t\tanswer: item.label,\n\t\t};\n\t}\n\n\tif (state.inputMode) {\n\t\tconst label = runtime.inputBuffer;\n\t\treturn {\n\t\t\tquestionIndex: state.currentTab,\n\t\t\tquestion: q.question,\n\t\t\tkind: \"custom\",\n\t\t\tanswer: label.length > 0 ? label : null,\n\t\t};\n\t}\n\tif (!item) return null;\n\tif (item.kind === \"other\") {\n\t\treturn null;\n\t}\n\tif (item.kind === \"next\") {\n\t\treturn null;\n\t}\n\treturn {\n\t\tquestionIndex: state.currentTab,\n\t\tquestion: q.question,\n\t\tkind: \"option\",\n\t\tanswer: item.label,\n\t};\n}\n\nfunction buildMultiSelected(state: QuestionnaireState, runtime: QuestionnaireRuntime): string[] {\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return [];\n\tconst out: string[] = [];\n\tfor (let i = 0; i < q.options.length; i++) {\n\t\tif (state.multiSelectChecked.has(i)) {\n\t\t\tconst label = q.options[i]?.label;\n\t\t\tif (typeof label === \"string\") out.push(label);\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction tabSwitchAction(\n\tdata: string,\n\tstate: QuestionnaireState,\n\truntime: QuestionnaireRuntime,\n): QuestionnaireAction | null {\n\tif (!runtime.isMulti) return null;\n\tconst total = totalTabs(runtime);\n\tif (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab + 1, total) };\n\t}\n\tif (matchesKey(data, Key.shift(\"tab\")) || matchesKey(data, Key.left)) {\n\t\treturn { kind: \"tab_switch\", nextTab: wrapTab(state.currentTab - 1, total) };\n\t}\n\treturn null;\n}\n\n// DOWN at the last item emits focus_chat so the cycle [chat, option0, …, optionLast] wraps.\nfunction nextNavOnDown(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === runtime.items.length - 1) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex + 1, Math.max(1, runtime.items.length)) };\n}\n\n// UP at the top item emits focus_chat (symmetric with nextNavOnDown).\nfunction prevNavOnUp(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tif (runtime.items.length > 0 && state.optionIndex === 0) {\n\t\treturn { kind: \"focus_chat\" };\n\t}\n\treturn { kind: \"nav\", nextIndex: wrapTab(state.optionIndex - 1, Math.max(1, runtime.items.length)) };\n}\n\nexport function routeKey(data: string, state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {\n\tconst kb = runtime.keybindings;\n\n\tif (state.notesVisible) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"notes_exit\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) return { kind: \"notes_exit\" };\n\t\treturn { kind: \"notes_forward\", data };\n\t}\n\n\tif (state.chatFocused) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\t// Continuous cycle: UP from chat → bottom of options (last navigable row), DOWN from\n\t\t// chat → top of options (option 0). Symmetric with UP-at-top → focus_chat and\n\t\t// DOWN-at-bottom → focus_chat below; together they form one wrapping cycle through\n\t\t// `[chat, option0, …, optionLast]`.\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\tconst last = Math.max(0, runtime.items.length - 1);\n\t\t\treturn { kind: \"focus_options\", optionIndex: last };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn { kind: \"focus_options\", optionIndex: 0 };\n\t\t}\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (state.inputMode) {\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\t\tif (!answer) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tif (kb.matches(data, KEYBIND_UP)) {\n\t\t\treturn prevNavOnUp(state, runtime);\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\t\treturn nextNavOnDown(state, runtime);\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (runtime.isMulti && state.currentTab === runtime.questions.length) {\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\tconst tab = tabSwitchAction(data, state, runtime);\n\t\tif (tab) return tab;\n\t\tif (kb.matches(data, KEYBIND_UP) || kb.matches(data, KEYBIND_DOWN)) {\n\t\t\tconst delta = kb.matches(data, KEYBIND_DOWN) ? 1 : -1;\n\t\t\tconst next = wrapTab(state.submitChoiceIndex + delta, 2);\n\t\t\treturn { kind: \"submit_nav\", nextIndex: (next === 1 ? 1 : 0) as 0 | 1 };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// D1 (revised): Submit always submits; Cancel always cancels. The warning header\n\t\t\t// is informational only — `allAnswered(state)` no longer gates submission. Partial\n\t\t\t// answers flow through `orderedAnswers()` in the host.\n\t\t\treturn state.submitChoiceIndex === 1 ? { kind: \"cancel\" } : { kind: \"submit\" };\n\t\t}\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tconst tab = tabSwitchAction(data, state, runtime);\n\tif (tab) return tab;\n\n\tconst q = runtime.questions[state.currentTab];\n\tif (!q) return { kind: \"ignore\" };\n\n\tif (data === NOTES_ACTIVATE_KEY && !q.multiSelect && state.focusedOptionHasPreview) {\n\t\treturn { kind: \"notes_enter\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_UP)) {\n\t\treturn prevNavOnUp(state, runtime);\n\t}\n\tif (kb.matches(data, KEYBIND_DOWN)) {\n\t\treturn nextNavOnDown(state, runtime);\n\t}\n\n\tif (q.multiSelect) {\n\t\tconst focusedKind = runtime.currentItem?.kind;\n\t\tconst focusedMeta = focusedKind ? ROW_INTENT_META[focusedKind] : undefined;\n\t\t// Space toggles the focused row's checkbox. Suppressed on rows whose META declares\n\t\t// `blocksMultiToggle` (the Next sentinel) — Next is not a real option and has no\n\t\t// checked/unchecked state.\n\t\tif (data === SPACE_KEY) {\n\t\t\tif (focusedMeta?.blocksMultiToggle) return { kind: \"ignore\" };\n\t\t\treturn { kind: \"toggle\", index: state.optionIndex };\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\t\t// Enter on a regular row toggles (matching Space) — committing the question is now\n\t\t\t// gated behind explicit focus on a row whose META declares `autoSubmitsInMulti`\n\t\t\t// (the Next sentinel), so Enter on options is a no-cost way to flip checkboxes\n\t\t\t// without leaving the keyboard home row.\n\t\t\tif (!focusedMeta?.autoSubmitsInMulti) return { kind: \"toggle\", index: state.optionIndex };\n\t\t\t// Enter on Next: carry autoAdvanceTab so the host can advance to the next tab in\n\t\t\t// multi-question mode, OR submit the dialog in single-question mode\n\t\t\t// (autoAdvanceTab === undefined when !isMulti). Without this, a single multi-select\n\t\t\t// question would have no way to commit at all.\n\t\t\treturn {\n\t\t\t\tkind: \"multi_confirm\",\n\t\t\t\tselected: buildMultiSelected(state, runtime),\n\t\t\t\tautoAdvanceTab: computeAutoAdvanceTab(state, runtime),\n\t\t\t};\n\t\t}\n\t\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\t\treturn { kind: \"ignore\" };\n\t}\n\n\tif (kb.matches(data, KEYBIND_CONFIRM)) {\n\t\tconst answer = buildSingleSelectAnswer(state, runtime);\n\t\tif (!answer) return { kind: \"ignore\" };\n\t\treturn { kind: \"confirm\", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };\n\t}\n\tif (kb.matches(data, KEYBIND_CANCEL)) return { kind: \"cancel\" };\n\treturn { kind: \"ignore\" };\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { Theme } from "../../../../modes/interactive/theme/theme.js";
2
- import type { QuestionnaireResult, QuestionParams } from "../tool/types.js";
3
- import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
1
+ import type { Theme } from "../../../../modes/interactive/theme/theme.ts";
2
+ import type { QuestionnaireResult, QuestionParams } from "../tool/types.ts";
3
+ import type { WrappingSelectItem } from "../view/components/wrapping-select.ts";
4
4
  export interface QuestionnaireSessionConfig {
5
5
  tui: {
6
6
  terminal: {
@@ -1 +1 @@
1
- {"version":3,"file":"questionnaire-session.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/questionnaire-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAE1E,OAAO,KAAK,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAahF,MAAM,WAAW,0BAA0B;IAC1C,GAAG,EAAE;QAAE,QAAQ,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,aAAa,IAAI,IAAI,CAAA;KAAE,CAAC;IAC9D,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,cAAc,CAAC;IACvB,UAAU,EAAE,kBAAkB,EAAE,EAAE,CAAC;IACnC,IAAI,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,6BAA6B;IAC7C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,UAAU,IAAI,IAAI,CAAC;IACnB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAkBD;;;;;GAKG;AACH,qBAAa,oBAAoB;IAChC,OAAO,CAAC,KAAK,CAAsC;IAEnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IAEpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA4B;IAExD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoC;IACxD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqC;IAE1D,QAAQ,CAAC,SAAS,EAAE,6BAA6B,CAAC;IAElD,YAAY,MAAM,EAAE,0BAA0B,EA8B7C;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAO3B;IAED,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,SAAS;IAwBjB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,OAAO;IAWf,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,WAAW;CAMnB","sourcesContent":["import type { Theme } from \"../../../../modes/interactive/theme/theme.js\";\nimport { getKeybindings, type Input } from \"@earendil-works/pi-tui\";\nimport type { QuestionData, QuestionnaireResult, QuestionParams } from \"../tool/types.js\";\nimport type { WrappingSelectItem } from \"../view/components/wrapping-select.js\";\nimport type { QuestionnairePropsAdapter } from \"../view/props-adapter.js\";\nimport { buildQuestionnaire } from \"./build-questionnaire.js\";\nimport { ROW_INTENT_META } from \"./row-intent.js\";\nimport { type QuestionnaireAction, routeKey } from \"./key-router.js\";\nimport { computeFocusedOptionHasPreview } from \"./selectors/derivations.js\";\nimport type { QuestionnaireRuntime, QuestionnaireState } from \"./state.js\";\nimport { type ApplyContext, type Effect, reduce } from \"./state-reducer.js\";\n\n// Module-level constant; reused for cursor-end mutations after setValue rehydration.\n// Ctrl-E → tui.editor.cursorLineEnd (public path; pi-tui keybindings.js:25-28).\nconst CURSOR_END = \"\\x05\";\n\nexport interface QuestionnaireSessionConfig {\n\ttui: { terminal: { columns: number }; requestRender(): void };\n\ttheme: Theme;\n\tparams: QuestionParams;\n\titemsByTab: WrappingSelectItem[][];\n\tdone: (result: QuestionnaireResult) => void;\n}\n\nexport interface QuestionnaireSessionComponent {\n\trender(width: number): string[];\n\tinvalidate(): void;\n\thandleInput(data: string): void;\n}\n\nfunction initialState(): QuestionnaireState {\n\treturn {\n\t\tcurrentTab: 0,\n\t\toptionIndex: 0,\n\t\tinputMode: false,\n\t\tnotesVisible: false,\n\t\tchatFocused: false,\n\t\tanswers: new Map(),\n\t\tmultiSelectChecked: new Set(),\n\t\tnotesByTab: new Map(),\n\t\tfocusedOptionHasPreview: false,\n\t\tsubmitChoiceIndex: 0,\n\t\tnotesDraft: \"\",\n\t};\n}\n\n/**\n * Slim runtime: owns the canonical state cell, the input-buffer cell, the\n * two-pass `notesVisible` dispatch loop, and the effect runner. State\n * transitions go through the pure `reduce` reducer; UI fan-out goes through\n * the `QuestionnairePropsAdapter` produced by `buildQuestionnaire`.\n */\nexport class QuestionnaireSession {\n\tprivate state: QuestionnaireState = initialState();\n\n\tprivate readonly questions: readonly QuestionData[];\n\tprivate readonly isMulti: boolean;\n\tprivate readonly itemsByTab: WrappingSelectItem[][];\n\n\tprivate readonly notesInput: Input;\n\tprivate readonly inlineInput: Input;\n\tprivate readonly viewAdapter: QuestionnairePropsAdapter;\n\n\tprivate readonly tui: QuestionnaireSessionConfig[\"tui\"];\n\tprivate readonly done: QuestionnaireSessionConfig[\"done\"];\n\n\treadonly component: QuestionnaireSessionComponent;\n\n\tconstructor(config: QuestionnaireSessionConfig) {\n\t\tthis.tui = config.tui;\n\t\tthis.done = config.done;\n\t\tthis.questions = config.params.questions;\n\t\tthis.isMulti = this.questions.length > 1;\n\t\tthis.itemsByTab = config.itemsByTab;\n\t\t// Seed from the focused option at start; the reducer keeps it in sync via withFocusedOptionHasPreview.\n\t\tthis.state = { ...this.state, focusedOptionHasPreview: computeFocusedOptionHasPreview(this.questions, 0, 0) };\n\n\t\tconst built = buildQuestionnaire({\n\t\t\ttui: this.tui,\n\t\t\ttheme: config.theme,\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t\tisMulti: this.isMulti,\n\t\t\tinitialState: this.state,\n\t\t\tgetCurrentTab: () => this.state.currentTab,\n\t\t});\n\n\t\tthis.notesInput = built.notesInput;\n\t\tthis.inlineInput = built.inlineInput;\n\t\tthis.viewAdapter = built.adapter;\n\n\t\tthis.component = {\n\t\t\trender: built.render,\n\t\t\tinvalidate: built.invalidate,\n\t\t\thandleInput: (data) => this.dispatch(data),\n\t\t};\n\n\t\tthis.viewAdapter.apply(this.state);\n\t}\n\n\tdispatch(data: string): void {\n\t\tconst action = routeKey(data, this.state, this.runtime());\n\t\tif (action.kind === \"ignore\") {\n\t\t\tthis.handleIgnoreInline(data);\n\t\t\treturn;\n\t\t}\n\t\tthis.commit(action);\n\t}\n\n\tprivate commit(action: QuestionnaireAction): void {\n\t\tconst result = reduce(this.state, action, this.applyContext());\n\t\tthis.state = result.state;\n\t\tfor (const effect of result.effects) this.runEffect(effect);\n\t\tthis.state = this.mirrorNotesDraft(this.state);\n\t\tthis.viewAdapter.apply(this.state);\n\t}\n\n\tprivate mirrorNotesDraft(s: QuestionnaireState): QuestionnaireState {\n\t\tconst draft = this.notesInput.getValue();\n\t\treturn s.notesDraft === draft ? s : { ...s, notesDraft: draft };\n\t}\n\n\tprivate runEffect(effect: Effect): void {\n\t\tswitch (effect.kind) {\n\t\t\tcase \"set_input_buffer\":\n\t\t\t\tthis.inlineInput.setValue(effect.value);\n\t\t\t\tthis.inlineInput.handleInput(CURSOR_END);\n\t\t\t\treturn;\n\t\t\tcase \"clear_input_buffer\":\n\t\t\t\tthis.inlineInput.setValue(\"\");\n\t\t\t\treturn;\n\t\t\tcase \"set_notes_value\":\n\t\t\t\tthis.notesInput.setValue(effect.value);\n\t\t\t\treturn;\n\t\t\tcase \"set_notes_focused\":\n\t\t\t\tthis.notesInput.focused = effect.focused;\n\t\t\t\treturn;\n\t\t\tcase \"forward_notes_keystroke\":\n\t\t\t\tthis.notesInput.handleInput(effect.data);\n\t\t\t\treturn;\n\t\t\tcase \"done\":\n\t\t\t\tthis.done(effect.result);\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\t/**\n\t * Per-keystroke `ignore` fast path: delegates to the headless `inlineInput`\n\t * Input so bracketed-paste accumulator (`input.js:33-63`) and Kitty CSI-u\n\t * decode (`input.js:155-163`) take effect. Cursor is NOT force-reset here —\n\t * doing so would corrupt split-chunk pastes (a `\\x05` byte mid-paste lands\n\t * verbatim in `pasteBuffer` and survives `handlePaste`'s narrow strip).\n\t * Cursor advances naturally via `insertCharacter` on typing/paste; cursor-\n\t * movement keys (Left/Right/Home/End/word-jumps) are now functional, with\n\t * the always-end visual cursor marker drawn independently by\n\t * `WrappingSelect.renderInlineInputRow`. `viewAdapter.apply` is called\n\t * directly without a reducer round-trip — preserves the D3 fast-path\n\t * latency profile from Phase 11.\n\t */\n\tprivate handleIgnoreInline(data: string): void {\n\t\tif (!this.state.inputMode) return;\n\t\tthis.inlineInput.handleInput(data);\n\t\tthis.viewAdapter.apply(this.state);\n\t}\n\n\tprivate runtime(): QuestionnaireRuntime {\n\t\treturn {\n\t\t\tkeybindings: getKeybindings(),\n\t\t\tinputBuffer: this.inlineInput.getValue(),\n\t\t\tquestions: this.questions,\n\t\t\tisMulti: this.isMulti,\n\t\t\tcurrentItem: this.currentItem(),\n\t\t\titems: this.itemsByTab[this.state.currentTab] ?? [],\n\t\t};\n\t}\n\n\tprivate applyContext(): ApplyContext {\n\t\treturn {\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t};\n\t}\n\n\tprivate currentItem(): WrappingSelectItem | undefined {\n\t\tif (this.state.chatFocused) return { kind: \"chat\", label: ROW_INTENT_META.chat.label };\n\t\tconst arr = this.itemsByTab[this.state.currentTab] ?? [];\n\t\tif (this.state.optionIndex < arr.length) return arr[this.state.optionIndex];\n\t\treturn { kind: \"chat\", label: ROW_INTENT_META.chat.label };\n\t}\n}\n"]}
1
+ {"version":3,"file":"questionnaire-session.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/state/questionnaire-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAE1E,OAAO,KAAK,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAA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;;;;OAYG;IACH,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,OAAO;IAWf,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,WAAW;CAMnB","sourcesContent":["import type { Theme } from \"../../../../modes/interactive/theme/theme.ts\";\nimport { getKeybindings, type Input } from \"@earendil-works/pi-tui\";\nimport type { QuestionData, QuestionnaireResult, QuestionParams } from \"../tool/types.ts\";\nimport type { WrappingSelectItem } from \"../view/components/wrapping-select.ts\";\nimport type { QuestionnairePropsAdapter } from \"../view/props-adapter.ts\";\nimport { buildQuestionnaire } from \"./build-questionnaire.ts\";\nimport { ROW_INTENT_META } from \"./row-intent.ts\";\nimport { type QuestionnaireAction, routeKey } from \"./key-router.ts\";\nimport { computeFocusedOptionHasPreview } from \"./selectors/derivations.ts\";\nimport type { QuestionnaireRuntime, QuestionnaireState } from \"./state.ts\";\nimport { type ApplyContext, type Effect, reduce } from \"./state-reducer.ts\";\n\n// Module-level constant; reused for cursor-end mutations after setValue rehydration.\n// Ctrl-E → tui.editor.cursorLineEnd (public path; pi-tui keybindings.js:25-28).\nconst CURSOR_END = \"\\x05\";\n\nexport interface QuestionnaireSessionConfig {\n\ttui: { terminal: { columns: number }; requestRender(): void };\n\ttheme: Theme;\n\tparams: QuestionParams;\n\titemsByTab: WrappingSelectItem[][];\n\tdone: (result: QuestionnaireResult) => void;\n}\n\nexport interface QuestionnaireSessionComponent {\n\trender(width: number): string[];\n\tinvalidate(): void;\n\thandleInput(data: string): void;\n}\n\nfunction initialState(): QuestionnaireState {\n\treturn {\n\t\tcurrentTab: 0,\n\t\toptionIndex: 0,\n\t\tinputMode: false,\n\t\tnotesVisible: false,\n\t\tchatFocused: false,\n\t\tanswers: new Map(),\n\t\tmultiSelectChecked: new Set(),\n\t\tnotesByTab: new Map(),\n\t\tfocusedOptionHasPreview: false,\n\t\tsubmitChoiceIndex: 0,\n\t\tnotesDraft: \"\",\n\t};\n}\n\n/**\n * Slim runtime: owns the canonical state cell, the input-buffer cell, the\n * two-pass `notesVisible` dispatch loop, and the effect runner. State\n * transitions go through the pure `reduce` reducer; UI fan-out goes through\n * the `QuestionnairePropsAdapter` produced by `buildQuestionnaire`.\n */\nexport class QuestionnaireSession {\n\tprivate state: QuestionnaireState = initialState();\n\n\tprivate readonly questions: readonly QuestionData[];\n\tprivate readonly isMulti: boolean;\n\tprivate readonly itemsByTab: WrappingSelectItem[][];\n\n\tprivate readonly notesInput: Input;\n\tprivate readonly inlineInput: Input;\n\tprivate readonly viewAdapter: QuestionnairePropsAdapter;\n\n\tprivate readonly tui: QuestionnaireSessionConfig[\"tui\"];\n\tprivate readonly done: QuestionnaireSessionConfig[\"done\"];\n\n\treadonly component: QuestionnaireSessionComponent;\n\n\tconstructor(config: QuestionnaireSessionConfig) {\n\t\tthis.tui = config.tui;\n\t\tthis.done = config.done;\n\t\tthis.questions = config.params.questions;\n\t\tthis.isMulti = this.questions.length > 1;\n\t\tthis.itemsByTab = config.itemsByTab;\n\t\t// Seed from the focused option at start; the reducer keeps it in sync via withFocusedOptionHasPreview.\n\t\tthis.state = { ...this.state, focusedOptionHasPreview: computeFocusedOptionHasPreview(this.questions, 0, 0) };\n\n\t\tconst built = buildQuestionnaire({\n\t\t\ttui: this.tui,\n\t\t\ttheme: config.theme,\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t\tisMulti: this.isMulti,\n\t\t\tinitialState: this.state,\n\t\t\tgetCurrentTab: () => this.state.currentTab,\n\t\t});\n\n\t\tthis.notesInput = built.notesInput;\n\t\tthis.inlineInput = built.inlineInput;\n\t\tthis.viewAdapter = built.adapter;\n\n\t\tthis.component = {\n\t\t\trender: built.render,\n\t\t\tinvalidate: built.invalidate,\n\t\t\thandleInput: (data) => this.dispatch(data),\n\t\t};\n\n\t\tthis.viewAdapter.apply(this.state);\n\t}\n\n\tdispatch(data: string): void {\n\t\tconst action = routeKey(data, this.state, this.runtime());\n\t\tif (action.kind === \"ignore\") {\n\t\t\tthis.handleIgnoreInline(data);\n\t\t\treturn;\n\t\t}\n\t\tthis.commit(action);\n\t}\n\n\tprivate commit(action: QuestionnaireAction): void {\n\t\tconst result = reduce(this.state, action, this.applyContext());\n\t\tthis.state = result.state;\n\t\tfor (const effect of result.effects) this.runEffect(effect);\n\t\tthis.state = this.mirrorNotesDraft(this.state);\n\t\tthis.viewAdapter.apply(this.state);\n\t}\n\n\tprivate mirrorNotesDraft(s: QuestionnaireState): QuestionnaireState {\n\t\tconst draft = this.notesInput.getValue();\n\t\treturn s.notesDraft === draft ? s : { ...s, notesDraft: draft };\n\t}\n\n\tprivate runEffect(effect: Effect): void {\n\t\tswitch (effect.kind) {\n\t\t\tcase \"set_input_buffer\":\n\t\t\t\tthis.inlineInput.setValue(effect.value);\n\t\t\t\tthis.inlineInput.handleInput(CURSOR_END);\n\t\t\t\treturn;\n\t\t\tcase \"clear_input_buffer\":\n\t\t\t\tthis.inlineInput.setValue(\"\");\n\t\t\t\treturn;\n\t\t\tcase \"set_notes_value\":\n\t\t\t\tthis.notesInput.setValue(effect.value);\n\t\t\t\treturn;\n\t\t\tcase \"set_notes_focused\":\n\t\t\t\tthis.notesInput.focused = effect.focused;\n\t\t\t\treturn;\n\t\t\tcase \"forward_notes_keystroke\":\n\t\t\t\tthis.notesInput.handleInput(effect.data);\n\t\t\t\treturn;\n\t\t\tcase \"done\":\n\t\t\t\tthis.done(effect.result);\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\t/**\n\t * Per-keystroke `ignore` fast path: delegates to the headless `inlineInput`\n\t * Input so bracketed-paste accumulator (`input.js:33-63`) and Kitty CSI-u\n\t * decode (`input.js:155-163`) take effect. Cursor is NOT force-reset here —\n\t * doing so would corrupt split-chunk pastes (a `\\x05` byte mid-paste lands\n\t * verbatim in `pasteBuffer` and survives `handlePaste`'s narrow strip).\n\t * Cursor advances naturally via `insertCharacter` on typing/paste; cursor-\n\t * movement keys (Left/Right/Home/End/word-jumps) are now functional, with\n\t * the always-end visual cursor marker drawn independently by\n\t * `WrappingSelect.renderInlineInputRow`. `viewAdapter.apply` is called\n\t * directly without a reducer round-trip — preserves the D3 fast-path\n\t * latency profile from Phase 11.\n\t */\n\tprivate handleIgnoreInline(data: string): void {\n\t\tif (!this.state.inputMode) return;\n\t\tthis.inlineInput.handleInput(data);\n\t\tthis.viewAdapter.apply(this.state);\n\t}\n\n\tprivate runtime(): QuestionnaireRuntime {\n\t\treturn {\n\t\t\tkeybindings: getKeybindings(),\n\t\t\tinputBuffer: this.inlineInput.getValue(),\n\t\t\tquestions: this.questions,\n\t\t\tisMulti: this.isMulti,\n\t\t\tcurrentItem: this.currentItem(),\n\t\t\titems: this.itemsByTab[this.state.currentTab] ?? [],\n\t\t};\n\t}\n\n\tprivate applyContext(): ApplyContext {\n\t\treturn {\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t};\n\t}\n\n\tprivate currentItem(): WrappingSelectItem | undefined {\n\t\tif (this.state.chatFocused) return { kind: \"chat\", label: ROW_INTENT_META.chat.label };\n\t\tconst arr = this.itemsByTab[this.state.currentTab] ?? [];\n\t\tif (this.state.optionIndex < arr.length) return arr[this.state.optionIndex];\n\t\treturn { kind: \"chat\", label: ROW_INTENT_META.chat.label };\n\t}\n}\n"]}