@openeryc/pi-coding-agent 0.75.26 → 0.75.27

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 (313) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cli/config-selector.d.ts +1 -13
  3. package/dist/cli/config-selector.d.ts.map +1 -1
  4. package/dist/cli/config-selector.js +4 -29
  5. package/dist/cli/config-selector.js.map +1 -1
  6. package/dist/cli/list-models.d.ts.map +1 -1
  7. package/dist/cli/list-models.js +1 -1
  8. package/dist/cli/list-models.js.map +1 -1
  9. package/dist/core/agent-session.d.ts +0 -2
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +12 -20
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  14. package/dist/core/export-html/tool-renderer.js.map +1 -1
  15. package/dist/core/extensions/loader.d.ts.map +1 -1
  16. package/dist/core/extensions/loader.js +1 -1
  17. package/dist/core/extensions/loader.js.map +1 -1
  18. package/dist/core/extensions/runner.d.ts +1 -1
  19. package/dist/core/extensions/runner.d.ts.map +1 -1
  20. package/dist/core/extensions/runner.js +1 -1
  21. package/dist/core/extensions/runner.js.map +1 -1
  22. package/dist/core/extensions/types.d.ts +1 -1
  23. package/dist/core/extensions/types.d.ts.map +1 -1
  24. package/dist/core/extensions/types.js.map +1 -1
  25. package/dist/core/keybindings.d.ts +7 -135
  26. package/dist/core/keybindings.d.ts.map +1 -1
  27. package/dist/core/keybindings.js +1 -1
  28. package/dist/core/keybindings.js.map +1 -1
  29. package/dist/core/mcp/client.d.ts +30 -11
  30. package/dist/core/mcp/client.d.ts.map +1 -1
  31. package/dist/core/mcp/client.js +55 -110
  32. package/dist/core/mcp/client.js.map +1 -1
  33. package/dist/core/mcp/index.d.ts +1 -3
  34. package/dist/core/mcp/index.d.ts.map +1 -1
  35. package/dist/core/mcp/index.js.map +1 -1
  36. package/dist/core/mcp/manager.d.ts +3 -9
  37. package/dist/core/mcp/manager.d.ts.map +1 -1
  38. package/dist/core/mcp/manager.js +71 -105
  39. package/dist/core/mcp/manager.js.map +1 -1
  40. package/dist/core/tools/bash.d.ts.map +1 -1
  41. package/dist/core/tools/bash.js +1 -1
  42. package/dist/core/tools/bash.js.map +1 -1
  43. package/dist/core/tools/edit.d.ts +1 -1
  44. package/dist/core/tools/edit.d.ts.map +1 -1
  45. package/dist/core/tools/edit.js +1 -1
  46. package/dist/core/tools/edit.js.map +1 -1
  47. package/dist/core/tools/find.d.ts.map +1 -1
  48. package/dist/core/tools/find.js +1 -1
  49. package/dist/core/tools/find.js.map +1 -1
  50. package/dist/core/tools/grep.d.ts.map +1 -1
  51. package/dist/core/tools/grep.js +1 -1
  52. package/dist/core/tools/grep.js.map +1 -1
  53. package/dist/core/tools/index.d.ts +3 -1
  54. package/dist/core/tools/index.d.ts.map +1 -1
  55. package/dist/core/tools/index.js +27 -1
  56. package/dist/core/tools/index.js.map +1 -1
  57. package/dist/core/tools/ls.d.ts.map +1 -1
  58. package/dist/core/tools/ls.js +1 -1
  59. package/dist/core/tools/ls.js.map +1 -1
  60. package/dist/core/tools/read.d.ts.map +1 -1
  61. package/dist/core/tools/read.js +1 -1
  62. package/dist/core/tools/read.js.map +1 -1
  63. package/dist/core/tools/render-utils.d.ts.map +1 -1
  64. package/dist/core/tools/render-utils.js +1 -1
  65. package/dist/core/tools/render-utils.js.map +1 -1
  66. package/dist/core/tools/web-fetch.d.ts +15 -0
  67. package/dist/core/tools/web-fetch.d.ts.map +1 -0
  68. package/dist/core/tools/web-fetch.js +52 -0
  69. package/dist/core/tools/web-fetch.js.map +1 -0
  70. package/dist/core/tools/web-search.d.ts +18 -0
  71. package/dist/core/tools/web-search.d.ts.map +1 -0
  72. package/dist/core/tools/web-search.js +83 -0
  73. package/dist/core/tools/web-search.js.map +1 -0
  74. package/dist/core/tools/write.d.ts.map +1 -1
  75. package/dist/core/tools/write.js +1 -1
  76. package/dist/core/tools/write.js.map +1 -1
  77. package/dist/core/tui-stubs.d.ts +95 -0
  78. package/dist/core/tui-stubs.d.ts.map +1 -0
  79. package/dist/core/tui-stubs.js +90 -0
  80. package/dist/core/tui-stubs.js.map +1 -0
  81. package/dist/index.d.ts +5 -3
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +7 -5
  84. package/dist/index.js.map +1 -1
  85. package/dist/main.d.ts.map +1 -1
  86. package/dist/main.js +14 -106
  87. package/dist/main.js.map +1 -1
  88. package/dist/modes/index.d.ts +0 -4
  89. package/dist/modes/index.d.ts.map +1 -1
  90. package/dist/modes/index.js +0 -4
  91. package/dist/modes/index.js.map +1 -1
  92. package/dist/modes/interactive/components/diff.d.ts +1 -8
  93. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  94. package/dist/modes/interactive/components/diff.js +2 -131
  95. package/dist/modes/interactive/components/diff.js.map +1 -1
  96. package/dist/modes/interactive/components/keybinding-hints.d.ts +2 -12
  97. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  98. package/dist/modes/interactive/components/keybinding-hints.js +4 -33
  99. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  100. package/dist/modes/interactive/components/visual-truncate.d.ts +1 -19
  101. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  102. package/dist/modes/interactive/components/visual-truncate.js +4 -31
  103. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  104. package/dist/modes/interactive/theme/theme.d.ts +27 -89
  105. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  106. package/dist/modes/interactive/theme/theme.js +44 -992
  107. package/dist/modes/interactive/theme/theme.js.map +1 -1
  108. package/dist/package-manager-cli.d.ts.map +1 -1
  109. package/dist/package-manager-cli.js +1 -1
  110. package/dist/package-manager-cli.js.map +1 -1
  111. package/npm-shrinkwrap.json +240 -246
  112. package/package.json +6 -7
  113. package/dist/cli/session-picker.d.ts +0 -9
  114. package/dist/cli/session-picker.d.ts.map +0 -1
  115. package/dist/cli/session-picker.js +0 -35
  116. package/dist/cli/session-picker.js.map +0 -1
  117. package/dist/core/mcp/types.d.ts +0 -86
  118. package/dist/core/mcp/types.d.ts.map +0 -1
  119. package/dist/core/mcp/types.js +0 -8
  120. package/dist/core/mcp/types.js.map +0 -1
  121. package/dist/modes/interactive/assets/clankolas.png +0 -0
  122. package/dist/modes/interactive/components/armin.d.ts +0 -34
  123. package/dist/modes/interactive/components/armin.d.ts.map +0 -1
  124. package/dist/modes/interactive/components/armin.js +0 -333
  125. package/dist/modes/interactive/components/armin.js.map +0 -1
  126. package/dist/modes/interactive/components/assistant-message.d.ts +0 -20
  127. package/dist/modes/interactive/components/assistant-message.d.ts.map +0 -1
  128. package/dist/modes/interactive/components/assistant-message.js +0 -121
  129. package/dist/modes/interactive/components/assistant-message.js.map +0 -1
  130. package/dist/modes/interactive/components/bash-execution.d.ts +0 -34
  131. package/dist/modes/interactive/components/bash-execution.d.ts.map +0 -1
  132. package/dist/modes/interactive/components/bash-execution.js +0 -175
  133. package/dist/modes/interactive/components/bash-execution.js.map +0 -1
  134. package/dist/modes/interactive/components/bordered-loader.d.ts +0 -16
  135. package/dist/modes/interactive/components/bordered-loader.d.ts.map +0 -1
  136. package/dist/modes/interactive/components/bordered-loader.js +0 -54
  137. package/dist/modes/interactive/components/bordered-loader.js.map +0 -1
  138. package/dist/modes/interactive/components/branch-summary-message.d.ts +0 -16
  139. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +0 -1
  140. package/dist/modes/interactive/components/branch-summary-message.js +0 -44
  141. package/dist/modes/interactive/components/branch-summary-message.js.map +0 -1
  142. package/dist/modes/interactive/components/compaction-summary-message.d.ts +0 -16
  143. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +0 -1
  144. package/dist/modes/interactive/components/compaction-summary-message.js +0 -45
  145. package/dist/modes/interactive/components/compaction-summary-message.js.map +0 -1
  146. package/dist/modes/interactive/components/config-selector.d.ts +0 -71
  147. package/dist/modes/interactive/components/config-selector.d.ts.map +0 -1
  148. package/dist/modes/interactive/components/config-selector.js +0 -506
  149. package/dist/modes/interactive/components/config-selector.js.map +0 -1
  150. package/dist/modes/interactive/components/countdown-timer.d.ts +0 -14
  151. package/dist/modes/interactive/components/countdown-timer.d.ts.map +0 -1
  152. package/dist/modes/interactive/components/countdown-timer.js +0 -33
  153. package/dist/modes/interactive/components/countdown-timer.js.map +0 -1
  154. package/dist/modes/interactive/components/custom-editor.d.ts +0 -21
  155. package/dist/modes/interactive/components/custom-editor.d.ts.map +0 -1
  156. package/dist/modes/interactive/components/custom-editor.js +0 -70
  157. package/dist/modes/interactive/components/custom-editor.js.map +0 -1
  158. package/dist/modes/interactive/components/custom-message.d.ts +0 -20
  159. package/dist/modes/interactive/components/custom-message.d.ts.map +0 -1
  160. package/dist/modes/interactive/components/custom-message.js +0 -79
  161. package/dist/modes/interactive/components/custom-message.js.map +0 -1
  162. package/dist/modes/interactive/components/daxnuts.d.ts +0 -23
  163. package/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
  164. package/dist/modes/interactive/components/daxnuts.js +0 -140
  165. package/dist/modes/interactive/components/daxnuts.js.map +0 -1
  166. package/dist/modes/interactive/components/dynamic-border.d.ts +0 -15
  167. package/dist/modes/interactive/components/dynamic-border.d.ts.map +0 -1
  168. package/dist/modes/interactive/components/dynamic-border.js +0 -21
  169. package/dist/modes/interactive/components/dynamic-border.js.map +0 -1
  170. package/dist/modes/interactive/components/earendil-announcement.d.ts +0 -5
  171. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +0 -1
  172. package/dist/modes/interactive/components/earendil-announcement.js +0 -40
  173. package/dist/modes/interactive/components/earendil-announcement.js.map +0 -1
  174. package/dist/modes/interactive/components/extension-editor.d.ts +0 -20
  175. package/dist/modes/interactive/components/extension-editor.d.ts.map +0 -1
  176. package/dist/modes/interactive/components/extension-editor.js +0 -119
  177. package/dist/modes/interactive/components/extension-editor.js.map +0 -1
  178. package/dist/modes/interactive/components/extension-input.d.ts +0 -23
  179. package/dist/modes/interactive/components/extension-input.d.ts.map +0 -1
  180. package/dist/modes/interactive/components/extension-input.js +0 -61
  181. package/dist/modes/interactive/components/extension-input.js.map +0 -1
  182. package/dist/modes/interactive/components/extension-selector.d.ts +0 -26
  183. package/dist/modes/interactive/components/extension-selector.d.ts.map +0 -1
  184. package/dist/modes/interactive/components/extension-selector.js +0 -83
  185. package/dist/modes/interactive/components/extension-selector.js.map +0 -1
  186. package/dist/modes/interactive/components/footer.d.ts +0 -27
  187. package/dist/modes/interactive/components/footer.d.ts.map +0 -1
  188. package/dist/modes/interactive/components/footer.js +0 -201
  189. package/dist/modes/interactive/components/footer.js.map +0 -1
  190. package/dist/modes/interactive/components/index.d.ts +0 -32
  191. package/dist/modes/interactive/components/index.d.ts.map +0 -1
  192. package/dist/modes/interactive/components/index.js +0 -33
  193. package/dist/modes/interactive/components/index.js.map +0 -1
  194. package/dist/modes/interactive/components/login-dialog.d.ts +0 -46
  195. package/dist/modes/interactive/components/login-dialog.d.ts.map +0 -1
  196. package/dist/modes/interactive/components/login-dialog.js +0 -160
  197. package/dist/modes/interactive/components/login-dialog.js.map +0 -1
  198. package/dist/modes/interactive/components/model-selector.d.ts +0 -47
  199. package/dist/modes/interactive/components/model-selector.d.ts.map +0 -1
  200. package/dist/modes/interactive/components/model-selector.js +0 -278
  201. package/dist/modes/interactive/components/model-selector.js.map +0 -1
  202. package/dist/modes/interactive/components/oauth-selector.d.ts +0 -31
  203. package/dist/modes/interactive/components/oauth-selector.d.ts.map +0 -1
  204. package/dist/modes/interactive/components/oauth-selector.js +0 -165
  205. package/dist/modes/interactive/components/oauth-selector.js.map +0 -1
  206. package/dist/modes/interactive/components/scoped-models-selector.d.ts +0 -42
  207. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +0 -1
  208. package/dist/modes/interactive/components/scoped-models-selector.js +0 -290
  209. package/dist/modes/interactive/components/scoped-models-selector.js.map +0 -1
  210. package/dist/modes/interactive/components/session-selector-search.d.ts +0 -23
  211. package/dist/modes/interactive/components/session-selector-search.d.ts.map +0 -1
  212. package/dist/modes/interactive/components/session-selector-search.js +0 -155
  213. package/dist/modes/interactive/components/session-selector-search.js.map +0 -1
  214. package/dist/modes/interactive/components/session-selector.d.ts +0 -96
  215. package/dist/modes/interactive/components/session-selector.d.ts.map +0 -1
  216. package/dist/modes/interactive/components/session-selector.js +0 -861
  217. package/dist/modes/interactive/components/session-selector.js.map +0 -1
  218. package/dist/modes/interactive/components/settings-selector.d.ts +0 -69
  219. package/dist/modes/interactive/components/settings-selector.d.ts.map +0 -1
  220. package/dist/modes/interactive/components/settings-selector.js +0 -390
  221. package/dist/modes/interactive/components/settings-selector.js.map +0 -1
  222. package/dist/modes/interactive/components/show-images-selector.d.ts +0 -10
  223. package/dist/modes/interactive/components/show-images-selector.d.ts.map +0 -1
  224. package/dist/modes/interactive/components/show-images-selector.js +0 -39
  225. package/dist/modes/interactive/components/show-images-selector.js.map +0 -1
  226. package/dist/modes/interactive/components/skill-invocation-message.d.ts +0 -17
  227. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +0 -1
  228. package/dist/modes/interactive/components/skill-invocation-message.js +0 -47
  229. package/dist/modes/interactive/components/skill-invocation-message.js.map +0 -1
  230. package/dist/modes/interactive/components/theme-selector.d.ts +0 -11
  231. package/dist/modes/interactive/components/theme-selector.d.ts.map +0 -1
  232. package/dist/modes/interactive/components/theme-selector.js +0 -50
  233. package/dist/modes/interactive/components/theme-selector.js.map +0 -1
  234. package/dist/modes/interactive/components/thinking-selector.d.ts +0 -11
  235. package/dist/modes/interactive/components/thinking-selector.d.ts.map +0 -1
  236. package/dist/modes/interactive/components/thinking-selector.js +0 -51
  237. package/dist/modes/interactive/components/thinking-selector.js.map +0 -1
  238. package/dist/modes/interactive/components/tool-execution.d.ts +0 -63
  239. package/dist/modes/interactive/components/tool-execution.d.ts.map +0 -1
  240. package/dist/modes/interactive/components/tool-execution.js +0 -295
  241. package/dist/modes/interactive/components/tool-execution.js.map +0 -1
  242. package/dist/modes/interactive/components/tree-selector.d.ts +0 -89
  243. package/dist/modes/interactive/components/tree-selector.d.ts.map +0 -1
  244. package/dist/modes/interactive/components/tree-selector.js +0 -1093
  245. package/dist/modes/interactive/components/tree-selector.js.map +0 -1
  246. package/dist/modes/interactive/components/user-message-selector.d.ts +0 -30
  247. package/dist/modes/interactive/components/user-message-selector.d.ts.map +0 -1
  248. package/dist/modes/interactive/components/user-message-selector.js +0 -114
  249. package/dist/modes/interactive/components/user-message-selector.js.map +0 -1
  250. package/dist/modes/interactive/components/user-message.d.ts +0 -10
  251. package/dist/modes/interactive/components/user-message.d.ts.map +0 -1
  252. package/dist/modes/interactive/components/user-message.js +0 -29
  253. package/dist/modes/interactive/components/user-message.js.map +0 -1
  254. package/dist/modes/interactive/interactive-mode.d.ts +0 -375
  255. package/dist/modes/interactive/interactive-mode.d.ts.map +0 -1
  256. package/dist/modes/interactive/interactive-mode.js +0 -4799
  257. package/dist/modes/interactive/interactive-mode.js.map +0 -1
  258. package/dist/modes/interactive/theme/dark.json +0 -86
  259. package/dist/modes/interactive/theme/light.json +0 -85
  260. package/dist/modes/interactive/theme/theme-schema.json +0 -335
  261. package/examples/extensions/border-status-editor.ts +0 -150
  262. package/examples/extensions/built-in-tool-renderer.ts +0 -249
  263. package/examples/extensions/custom-footer.ts +0 -64
  264. package/examples/extensions/custom-header.ts +0 -73
  265. package/examples/extensions/custom-provider-anthropic/index.ts +0 -604
  266. package/examples/extensions/custom-provider-anthropic/package-lock.json +0 -24
  267. package/examples/extensions/custom-provider-anthropic/package.json +0 -19
  268. package/examples/extensions/custom-provider-gitlab-duo/index.ts +0 -349
  269. package/examples/extensions/custom-provider-gitlab-duo/package.json +0 -16
  270. package/examples/extensions/custom-provider-gitlab-duo/test.ts +0 -82
  271. package/examples/extensions/doom-overlay/README.md +0 -46
  272. package/examples/extensions/doom-overlay/doom/build/doom.js +0 -21
  273. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  274. package/examples/extensions/doom-overlay/doom/build.sh +0 -152
  275. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +0 -72
  276. package/examples/extensions/doom-overlay/doom-component.ts +0 -132
  277. package/examples/extensions/doom-overlay/doom-engine.ts +0 -173
  278. package/examples/extensions/doom-overlay/doom-keys.ts +0 -104
  279. package/examples/extensions/doom-overlay/index.ts +0 -74
  280. package/examples/extensions/doom-overlay/wad-finder.ts +0 -51
  281. package/examples/extensions/github-issue-autocomplete.ts +0 -185
  282. package/examples/extensions/handoff.ts +0 -191
  283. package/examples/extensions/interactive-shell.ts +0 -196
  284. package/examples/extensions/message-renderer.ts +0 -59
  285. package/examples/extensions/minimal-mode.ts +0 -426
  286. package/examples/extensions/modal-editor.ts +0 -85
  287. package/examples/extensions/overlay-qa-tests.ts +0 -1379
  288. package/examples/extensions/overlay-test.ts +0 -153
  289. package/examples/extensions/plan-mode/index.ts +0 -340
  290. package/examples/extensions/preset.ts +0 -430
  291. package/examples/extensions/qna.ts +0 -122
  292. package/examples/extensions/question.ts +0 -264
  293. package/examples/extensions/questionnaire.ts +0 -427
  294. package/examples/extensions/rainbow-editor.ts +0 -88
  295. package/examples/extensions/sandbox/index.ts +0 -321
  296. package/examples/extensions/sandbox/package-lock.json +0 -92
  297. package/examples/extensions/sandbox/package.json +0 -19
  298. package/examples/extensions/snake.ts +0 -343
  299. package/examples/extensions/space-invaders.ts +0 -560
  300. package/examples/extensions/ssh.ts +0 -220
  301. package/examples/extensions/status-line.ts +0 -32
  302. package/examples/extensions/structured-output.ts +0 -65
  303. package/examples/extensions/subagent/index.ts +0 -1009
  304. package/examples/extensions/summarize.ts +0 -206
  305. package/examples/extensions/tic-tac-toe.ts +0 -1008
  306. package/examples/extensions/todo.ts +0 -297
  307. package/examples/extensions/tools.ts +0 -141
  308. package/examples/extensions/truncated-tool.ts +0 -195
  309. package/examples/extensions/with-deps/index.ts +0 -32
  310. package/examples/extensions/with-deps/package-lock.json +0 -31
  311. package/examples/extensions/with-deps/package.json +0 -22
  312. package/examples/extensions/working-indicator.ts +0 -123
  313. package/examples/rpc-extension-ui.ts +0 -632
@@ -1,264 +0,0 @@
1
- /**
2
- * Question Tool - Single question with options
3
- * Full custom UI: options list + inline editor for "Type something..."
4
- * Escape in editor returns to options, Escape in options cancels
5
- */
6
-
7
- import type { ExtensionAPI } from "@openeryc/pi-coding-agent";
8
- import { Editor, type EditorTheme, Key, matchesKey, Text, truncateToWidth } from "@openeryc/pi-tui";
9
- import { Type } from "typebox";
10
-
11
- interface OptionWithDesc {
12
- label: string;
13
- description?: string;
14
- }
15
-
16
- type DisplayOption = OptionWithDesc & { isOther?: boolean };
17
-
18
- interface QuestionDetails {
19
- question: string;
20
- options: string[];
21
- answer: string | null;
22
- wasCustom?: boolean;
23
- }
24
-
25
- // Options with labels and optional descriptions
26
- const OptionSchema = Type.Object({
27
- label: Type.String({ description: "Display label for the option" }),
28
- description: Type.Optional(Type.String({ description: "Optional description shown below label" })),
29
- });
30
-
31
- const QuestionParams = Type.Object({
32
- question: Type.String({ description: "The question to ask the user" }),
33
- options: Type.Array(OptionSchema, { description: "Options for the user to choose from" }),
34
- });
35
-
36
- export default function question(pi: ExtensionAPI) {
37
- pi.registerTool({
38
- name: "question",
39
- label: "Question",
40
- description: "Ask the user a question and let them pick from options. Use when you need user input to proceed.",
41
- parameters: QuestionParams,
42
-
43
- async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
44
- if (!ctx.hasUI) {
45
- return {
46
- content: [{ type: "text", text: "Error: UI not available (running in non-interactive mode)" }],
47
- details: {
48
- question: params.question,
49
- options: params.options.map((o) => o.label),
50
- answer: null,
51
- } as QuestionDetails,
52
- };
53
- }
54
-
55
- if (params.options.length === 0) {
56
- return {
57
- content: [{ type: "text", text: "Error: No options provided" }],
58
- details: { question: params.question, options: [], answer: null } as QuestionDetails,
59
- };
60
- }
61
-
62
- const allOptions: DisplayOption[] = [...params.options, { label: "Type something.", isOther: true }];
63
-
64
- const result = await ctx.ui.custom<{ answer: string; wasCustom: boolean; index?: number } | null>(
65
- (tui, theme, _kb, done) => {
66
- let optionIndex = 0;
67
- let editMode = false;
68
- let cachedLines: string[] | undefined;
69
-
70
- const editorTheme: EditorTheme = {
71
- borderColor: (s) => theme.fg("accent", s),
72
- selectList: {
73
- selectedPrefix: (t) => theme.fg("accent", t),
74
- selectedText: (t) => theme.fg("accent", t),
75
- description: (t) => theme.fg("muted", t),
76
- scrollInfo: (t) => theme.fg("dim", t),
77
- noMatch: (t) => theme.fg("warning", t),
78
- },
79
- };
80
- const editor = new Editor(tui, editorTheme);
81
-
82
- editor.onSubmit = (value) => {
83
- const trimmed = value.trim();
84
- if (trimmed) {
85
- done({ answer: trimmed, wasCustom: true });
86
- } else {
87
- editMode = false;
88
- editor.setText("");
89
- refresh();
90
- }
91
- };
92
-
93
- function refresh() {
94
- cachedLines = undefined;
95
- tui.requestRender();
96
- }
97
-
98
- function handleInput(data: string) {
99
- if (editMode) {
100
- if (matchesKey(data, Key.escape)) {
101
- editMode = false;
102
- editor.setText("");
103
- refresh();
104
- return;
105
- }
106
- editor.handleInput(data);
107
- refresh();
108
- return;
109
- }
110
-
111
- if (matchesKey(data, Key.up)) {
112
- optionIndex = Math.max(0, optionIndex - 1);
113
- refresh();
114
- return;
115
- }
116
- if (matchesKey(data, Key.down)) {
117
- optionIndex = Math.min(allOptions.length - 1, optionIndex + 1);
118
- refresh();
119
- return;
120
- }
121
-
122
- if (matchesKey(data, Key.enter)) {
123
- const selected = allOptions[optionIndex];
124
- if (selected.isOther) {
125
- editMode = true;
126
- refresh();
127
- } else {
128
- done({ answer: selected.label, wasCustom: false, index: optionIndex + 1 });
129
- }
130
- return;
131
- }
132
-
133
- if (matchesKey(data, Key.escape)) {
134
- done(null);
135
- }
136
- }
137
-
138
- function render(width: number): string[] {
139
- if (cachedLines) return cachedLines;
140
-
141
- const lines: string[] = [];
142
- const add = (s: string) => lines.push(truncateToWidth(s, width));
143
-
144
- add(theme.fg("accent", "─".repeat(width)));
145
- add(theme.fg("text", ` ${params.question}`));
146
- lines.push("");
147
-
148
- for (let i = 0; i < allOptions.length; i++) {
149
- const opt = allOptions[i];
150
- const selected = i === optionIndex;
151
- const isOther = opt.isOther === true;
152
- const prefix = selected ? theme.fg("accent", "> ") : " ";
153
-
154
- if (isOther && editMode) {
155
- add(prefix + theme.fg("accent", `${i + 1}. ${opt.label} ✎`));
156
- } else if (selected) {
157
- add(prefix + theme.fg("accent", `${i + 1}. ${opt.label}`));
158
- } else {
159
- add(` ${theme.fg("text", `${i + 1}. ${opt.label}`)}`);
160
- }
161
-
162
- // Show description if present
163
- if (opt.description) {
164
- add(` ${theme.fg("muted", opt.description)}`);
165
- }
166
- }
167
-
168
- if (editMode) {
169
- lines.push("");
170
- add(theme.fg("muted", " Your answer:"));
171
- for (const line of editor.render(width - 2)) {
172
- add(` ${line}`);
173
- }
174
- }
175
-
176
- lines.push("");
177
- if (editMode) {
178
- add(theme.fg("dim", " Enter to submit • Esc to go back"));
179
- } else {
180
- add(theme.fg("dim", " ↑↓ navigate • Enter to select • Esc to cancel"));
181
- }
182
- add(theme.fg("accent", "─".repeat(width)));
183
-
184
- cachedLines = lines;
185
- return lines;
186
- }
187
-
188
- return {
189
- render,
190
- invalidate: () => {
191
- cachedLines = undefined;
192
- },
193
- handleInput,
194
- };
195
- },
196
- );
197
-
198
- // Build simple options list for details
199
- const simpleOptions = params.options.map((o) => o.label);
200
-
201
- if (!result) {
202
- return {
203
- content: [{ type: "text", text: "User cancelled the selection" }],
204
- details: { question: params.question, options: simpleOptions, answer: null } as QuestionDetails,
205
- };
206
- }
207
-
208
- if (result.wasCustom) {
209
- return {
210
- content: [{ type: "text", text: `User wrote: ${result.answer}` }],
211
- details: {
212
- question: params.question,
213
- options: simpleOptions,
214
- answer: result.answer,
215
- wasCustom: true,
216
- } as QuestionDetails,
217
- };
218
- }
219
- return {
220
- content: [{ type: "text", text: `User selected: ${result.index}. ${result.answer}` }],
221
- details: {
222
- question: params.question,
223
- options: simpleOptions,
224
- answer: result.answer,
225
- wasCustom: false,
226
- } as QuestionDetails,
227
- };
228
- },
229
-
230
- renderCall(args, theme, _context) {
231
- let text = theme.fg("toolTitle", theme.bold("question ")) + theme.fg("muted", args.question);
232
- const opts = Array.isArray(args.options) ? args.options : [];
233
- if (opts.length) {
234
- const labels = opts.map((o: OptionWithDesc) => o.label);
235
- const numbered = [...labels, "Type something."].map((o, i) => `${i + 1}. ${o}`);
236
- text += `\n${theme.fg("dim", ` Options: ${numbered.join(", ")}`)}`;
237
- }
238
- return new Text(text, 0, 0);
239
- },
240
-
241
- renderResult(result, _options, theme, _context) {
242
- const details = result.details as QuestionDetails | undefined;
243
- if (!details) {
244
- const text = result.content[0];
245
- return new Text(text?.type === "text" ? text.text : "", 0, 0);
246
- }
247
-
248
- if (details.answer === null) {
249
- return new Text(theme.fg("warning", "Cancelled"), 0, 0);
250
- }
251
-
252
- if (details.wasCustom) {
253
- return new Text(
254
- theme.fg("success", "✓ ") + theme.fg("muted", "(wrote) ") + theme.fg("accent", details.answer),
255
- 0,
256
- 0,
257
- );
258
- }
259
- const idx = details.options.indexOf(details.answer) + 1;
260
- const display = idx > 0 ? `${idx}. ${details.answer}` : details.answer;
261
- return new Text(theme.fg("success", "✓ ") + theme.fg("accent", display), 0, 0);
262
- },
263
- });
264
- }
@@ -1,427 +0,0 @@
1
- /**
2
- * Questionnaire Tool - Unified tool for asking single or multiple questions
3
- *
4
- * Single question: simple options list
5
- * Multiple questions: tab bar navigation between questions
6
- */
7
-
8
- import type { ExtensionAPI } from "@openeryc/pi-coding-agent";
9
- import { Editor, type EditorTheme, Key, matchesKey, Text, truncateToWidth } from "@openeryc/pi-tui";
10
- import { Type } from "typebox";
11
-
12
- // Types
13
- interface QuestionOption {
14
- value: string;
15
- label: string;
16
- description?: string;
17
- }
18
-
19
- type RenderOption = QuestionOption & { isOther?: boolean };
20
-
21
- interface Question {
22
- id: string;
23
- label: string;
24
- prompt: string;
25
- options: QuestionOption[];
26
- allowOther: boolean;
27
- }
28
-
29
- interface Answer {
30
- id: string;
31
- value: string;
32
- label: string;
33
- wasCustom: boolean;
34
- index?: number;
35
- }
36
-
37
- interface QuestionnaireResult {
38
- questions: Question[];
39
- answers: Answer[];
40
- cancelled: boolean;
41
- }
42
-
43
- // Schema
44
- const QuestionOptionSchema = Type.Object({
45
- value: Type.String({ description: "The value returned when selected" }),
46
- label: Type.String({ description: "Display label for the option" }),
47
- description: Type.Optional(Type.String({ description: "Optional description shown below label" })),
48
- });
49
-
50
- const QuestionSchema = Type.Object({
51
- id: Type.String({ description: "Unique identifier for this question" }),
52
- label: Type.Optional(
53
- Type.String({
54
- description: "Short contextual label for tab bar, e.g. 'Scope', 'Priority' (defaults to Q1, Q2)",
55
- }),
56
- ),
57
- prompt: Type.String({ description: "The full question text to display" }),
58
- options: Type.Array(QuestionOptionSchema, { description: "Available options to choose from" }),
59
- allowOther: Type.Optional(Type.Boolean({ description: "Allow 'Type something' option (default: true)" })),
60
- });
61
-
62
- const QuestionnaireParams = Type.Object({
63
- questions: Type.Array(QuestionSchema, { description: "Questions to ask the user" }),
64
- });
65
-
66
- function errorResult(
67
- message: string,
68
- questions: Question[] = [],
69
- ): { content: { type: "text"; text: string }[]; details: QuestionnaireResult } {
70
- return {
71
- content: [{ type: "text", text: message }],
72
- details: { questions, answers: [], cancelled: true },
73
- };
74
- }
75
-
76
- export default function questionnaire(pi: ExtensionAPI) {
77
- pi.registerTool({
78
- name: "questionnaire",
79
- label: "Questionnaire",
80
- description:
81
- "Ask the user one or more questions. Use for clarifying requirements, getting preferences, or confirming decisions. For single questions, shows a simple option list. For multiple questions, shows a tab-based interface.",
82
- parameters: QuestionnaireParams,
83
-
84
- async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
85
- if (!ctx.hasUI) {
86
- return errorResult("Error: UI not available (running in non-interactive mode)");
87
- }
88
- if (params.questions.length === 0) {
89
- return errorResult("Error: No questions provided");
90
- }
91
-
92
- // Normalize questions with defaults
93
- const questions: Question[] = params.questions.map((q, i) => ({
94
- ...q,
95
- label: q.label || `Q${i + 1}`,
96
- allowOther: q.allowOther !== false,
97
- }));
98
-
99
- const isMulti = questions.length > 1;
100
- const totalTabs = questions.length + 1; // questions + Submit
101
-
102
- const result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {
103
- // State
104
- let currentTab = 0;
105
- let optionIndex = 0;
106
- let inputMode = false;
107
- let inputQuestionId: string | null = null;
108
- let cachedLines: string[] | undefined;
109
- const answers = new Map<string, Answer>();
110
-
111
- // Editor for "Type something" option
112
- const editorTheme: EditorTheme = {
113
- borderColor: (s) => theme.fg("accent", s),
114
- selectList: {
115
- selectedPrefix: (t) => theme.fg("accent", t),
116
- selectedText: (t) => theme.fg("accent", t),
117
- description: (t) => theme.fg("muted", t),
118
- scrollInfo: (t) => theme.fg("dim", t),
119
- noMatch: (t) => theme.fg("warning", t),
120
- },
121
- };
122
- const editor = new Editor(tui, editorTheme);
123
-
124
- // Helpers
125
- function refresh() {
126
- cachedLines = undefined;
127
- tui.requestRender();
128
- }
129
-
130
- function submit(cancelled: boolean) {
131
- done({ questions, answers: Array.from(answers.values()), cancelled });
132
- }
133
-
134
- function currentQuestion(): Question | undefined {
135
- return questions[currentTab];
136
- }
137
-
138
- function currentOptions(): RenderOption[] {
139
- const q = currentQuestion();
140
- if (!q) return [];
141
- const opts: RenderOption[] = [...q.options];
142
- if (q.allowOther) {
143
- opts.push({ value: "__other__", label: "Type something.", isOther: true });
144
- }
145
- return opts;
146
- }
147
-
148
- function allAnswered(): boolean {
149
- return questions.every((q) => answers.has(q.id));
150
- }
151
-
152
- function advanceAfterAnswer() {
153
- if (!isMulti) {
154
- submit(false);
155
- return;
156
- }
157
- if (currentTab < questions.length - 1) {
158
- currentTab++;
159
- } else {
160
- currentTab = questions.length; // Submit tab
161
- }
162
- optionIndex = 0;
163
- refresh();
164
- }
165
-
166
- function saveAnswer(questionId: string, value: string, label: string, wasCustom: boolean, index?: number) {
167
- answers.set(questionId, { id: questionId, value, label, wasCustom, index });
168
- }
169
-
170
- // Editor submit callback
171
- editor.onSubmit = (value) => {
172
- if (!inputQuestionId) return;
173
- const trimmed = value.trim() || "(no response)";
174
- saveAnswer(inputQuestionId, trimmed, trimmed, true);
175
- inputMode = false;
176
- inputQuestionId = null;
177
- editor.setText("");
178
- advanceAfterAnswer();
179
- };
180
-
181
- function handleInput(data: string) {
182
- // Input mode: route to editor
183
- if (inputMode) {
184
- if (matchesKey(data, Key.escape)) {
185
- inputMode = false;
186
- inputQuestionId = null;
187
- editor.setText("");
188
- refresh();
189
- return;
190
- }
191
- editor.handleInput(data);
192
- refresh();
193
- return;
194
- }
195
-
196
- const q = currentQuestion();
197
- const opts = currentOptions();
198
-
199
- // Tab navigation (multi-question only)
200
- if (isMulti) {
201
- if (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {
202
- currentTab = (currentTab + 1) % totalTabs;
203
- optionIndex = 0;
204
- refresh();
205
- return;
206
- }
207
- if (matchesKey(data, Key.shift("tab")) || matchesKey(data, Key.left)) {
208
- currentTab = (currentTab - 1 + totalTabs) % totalTabs;
209
- optionIndex = 0;
210
- refresh();
211
- return;
212
- }
213
- }
214
-
215
- // Submit tab
216
- if (currentTab === questions.length) {
217
- if (matchesKey(data, Key.enter) && allAnswered()) {
218
- submit(false);
219
- } else if (matchesKey(data, Key.escape)) {
220
- submit(true);
221
- }
222
- return;
223
- }
224
-
225
- // Option navigation
226
- if (matchesKey(data, Key.up)) {
227
- optionIndex = Math.max(0, optionIndex - 1);
228
- refresh();
229
- return;
230
- }
231
- if (matchesKey(data, Key.down)) {
232
- optionIndex = Math.min(opts.length - 1, optionIndex + 1);
233
- refresh();
234
- return;
235
- }
236
-
237
- // Select option
238
- if (matchesKey(data, Key.enter) && q) {
239
- const opt = opts[optionIndex];
240
- if (opt.isOther) {
241
- inputMode = true;
242
- inputQuestionId = q.id;
243
- editor.setText("");
244
- refresh();
245
- return;
246
- }
247
- saveAnswer(q.id, opt.value, opt.label, false, optionIndex + 1);
248
- advanceAfterAnswer();
249
- return;
250
- }
251
-
252
- // Cancel
253
- if (matchesKey(data, Key.escape)) {
254
- submit(true);
255
- }
256
- }
257
-
258
- function render(width: number): string[] {
259
- if (cachedLines) return cachedLines;
260
-
261
- const lines: string[] = [];
262
- const q = currentQuestion();
263
- const opts = currentOptions();
264
-
265
- // Helper to add truncated line
266
- const add = (s: string) => lines.push(truncateToWidth(s, width));
267
-
268
- add(theme.fg("accent", "─".repeat(width)));
269
-
270
- // Tab bar (multi-question only)
271
- if (isMulti) {
272
- const tabs: string[] = ["← "];
273
- for (let i = 0; i < questions.length; i++) {
274
- const isActive = i === currentTab;
275
- const isAnswered = answers.has(questions[i].id);
276
- const lbl = questions[i].label;
277
- const box = isAnswered ? "■" : "□";
278
- const color = isAnswered ? "success" : "muted";
279
- const text = ` ${box} ${lbl} `;
280
- const styled = isActive ? theme.bg("selectedBg", theme.fg("text", text)) : theme.fg(color, text);
281
- tabs.push(`${styled} `);
282
- }
283
- const canSubmit = allAnswered();
284
- const isSubmitTab = currentTab === questions.length;
285
- const submitText = " ✓ Submit ";
286
- const submitStyled = isSubmitTab
287
- ? theme.bg("selectedBg", theme.fg("text", submitText))
288
- : theme.fg(canSubmit ? "success" : "dim", submitText);
289
- tabs.push(`${submitStyled} →`);
290
- add(` ${tabs.join("")}`);
291
- lines.push("");
292
- }
293
-
294
- // Helper to render options list
295
- function renderOptions() {
296
- for (let i = 0; i < opts.length; i++) {
297
- const opt = opts[i];
298
- const selected = i === optionIndex;
299
- const isOther = opt.isOther === true;
300
- const prefix = selected ? theme.fg("accent", "> ") : " ";
301
- const color = selected ? "accent" : "text";
302
- // Mark "Type something" differently when in input mode
303
- if (isOther && inputMode) {
304
- add(prefix + theme.fg("accent", `${i + 1}. ${opt.label} ✎`));
305
- } else {
306
- add(prefix + theme.fg(color, `${i + 1}. ${opt.label}`));
307
- }
308
- if (opt.description) {
309
- add(` ${theme.fg("muted", opt.description)}`);
310
- }
311
- }
312
- }
313
-
314
- // Content
315
- if (inputMode && q) {
316
- add(theme.fg("text", ` ${q.prompt}`));
317
- lines.push("");
318
- // Show options for reference
319
- renderOptions();
320
- lines.push("");
321
- add(theme.fg("muted", " Your answer:"));
322
- for (const line of editor.render(width - 2)) {
323
- add(` ${line}`);
324
- }
325
- lines.push("");
326
- add(theme.fg("dim", " Enter to submit • Esc to cancel"));
327
- } else if (currentTab === questions.length) {
328
- add(theme.fg("accent", theme.bold(" Ready to submit")));
329
- lines.push("");
330
- for (const question of questions) {
331
- const answer = answers.get(question.id);
332
- if (answer) {
333
- const prefix = answer.wasCustom ? "(wrote) " : "";
334
- add(`${theme.fg("muted", ` ${question.label}: `)}${theme.fg("text", prefix + answer.label)}`);
335
- }
336
- }
337
- lines.push("");
338
- if (allAnswered()) {
339
- add(theme.fg("success", " Press Enter to submit"));
340
- } else {
341
- const missing = questions
342
- .filter((q) => !answers.has(q.id))
343
- .map((q) => q.label)
344
- .join(", ");
345
- add(theme.fg("warning", ` Unanswered: ${missing}`));
346
- }
347
- } else if (q) {
348
- add(theme.fg("text", ` ${q.prompt}`));
349
- lines.push("");
350
- renderOptions();
351
- }
352
-
353
- lines.push("");
354
- if (!inputMode) {
355
- const help = isMulti
356
- ? " Tab/←→ navigate • ↑↓ select • Enter confirm • Esc cancel"
357
- : " ↑↓ navigate • Enter select • Esc cancel";
358
- add(theme.fg("dim", help));
359
- }
360
- add(theme.fg("accent", "─".repeat(width)));
361
-
362
- cachedLines = lines;
363
- return lines;
364
- }
365
-
366
- return {
367
- render,
368
- invalidate: () => {
369
- cachedLines = undefined;
370
- },
371
- handleInput,
372
- };
373
- });
374
-
375
- if (result.cancelled) {
376
- return {
377
- content: [{ type: "text", text: "User cancelled the questionnaire" }],
378
- details: result,
379
- };
380
- }
381
-
382
- const answerLines = result.answers.map((a) => {
383
- const qLabel = questions.find((q) => q.id === a.id)?.label || a.id;
384
- if (a.wasCustom) {
385
- return `${qLabel}: user wrote: ${a.label}`;
386
- }
387
- return `${qLabel}: user selected: ${a.index}. ${a.label}`;
388
- });
389
-
390
- return {
391
- content: [{ type: "text", text: answerLines.join("\n") }],
392
- details: result,
393
- };
394
- },
395
-
396
- renderCall(args, theme, _context) {
397
- const qs = (args.questions as Question[]) || [];
398
- const count = qs.length;
399
- const labels = qs.map((q) => q.label || q.id).join(", ");
400
- let text = theme.fg("toolTitle", theme.bold("questionnaire "));
401
- text += theme.fg("muted", `${count} question${count !== 1 ? "s" : ""}`);
402
- if (labels) {
403
- text += theme.fg("dim", ` (${truncateToWidth(labels, 40)})`);
404
- }
405
- return new Text(text, 0, 0);
406
- },
407
-
408
- renderResult(result, _options, theme, _context) {
409
- const details = result.details as QuestionnaireResult | undefined;
410
- if (!details) {
411
- const text = result.content[0];
412
- return new Text(text?.type === "text" ? text.text : "", 0, 0);
413
- }
414
- if (details.cancelled) {
415
- return new Text(theme.fg("warning", "Cancelled"), 0, 0);
416
- }
417
- const lines = details.answers.map((a) => {
418
- if (a.wasCustom) {
419
- return `${theme.fg("success", "✓ ")}${theme.fg("accent", a.id)}: ${theme.fg("muted", "(wrote) ")}${a.label}`;
420
- }
421
- const display = a.index ? `${a.index}. ${a.label}` : a.label;
422
- return `${theme.fg("success", "✓ ")}${theme.fg("accent", a.id)}: ${display}`;
423
- });
424
- return new Text(lines.join("\n"), 0, 0);
425
- },
426
- });
427
- }