devlyn-cli 4.1.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/AGENTS.md +10 -94
  2. package/CLAUDE.md +7 -160
  3. package/LICENSE +21 -0
  4. package/README.md +68 -111
  5. package/bin/devlyn.js +265 -259
  6. package/bin/instruction-templates.json +43 -2
  7. package/bin/instructions.js +29 -8
  8. package/bin/skill-history.json +140 -0
  9. package/bin/skill-ownership.js +67 -0
  10. package/config/skills/_shared/adapters/claude.md +8 -85
  11. package/config/skills/_shared/adapters/codex.md +14 -34
  12. package/config/skills/_shared/adapters/omp.md +1 -11
  13. package/config/skills/_shared/codex-monitored.sh +4 -54
  14. package/config/skills/_shared/engine-doctor.sh +18 -58
  15. package/config/skills/_shared/engine-preflight.md +15 -47
  16. package/config/skills/_shared/expected-contract.py +242 -0
  17. package/config/skills/_shared/expected.schema.json +10 -95
  18. package/config/skills/_shared/invocation-receipt.py +26 -757
  19. package/config/skills/_shared/platform-support.py +37 -28
  20. package/config/skills/_shared/role-config.py +100 -421
  21. package/config/skills/_shared/runtime-principles.md +17 -93
  22. package/config/skills/_shared/task-complete.py +490 -285
  23. package/config/skills/_shared/task-completion.md +235 -0
  24. package/config/skills/devlyn-engines/SKILL.md +9 -11
  25. package/config/skills/devlyn-ideate/SKILL.md +57 -107
  26. package/config/skills/devlyn-ideate/references/elicitation.md +18 -99
  27. package/config/skills/devlyn-ideate/references/loop.md +110 -0
  28. package/config/skills/devlyn-ideate/references/package-format.md +128 -0
  29. package/config/skills/devlyn-ideate/scripts/acceptance.py +795 -0
  30. package/config/skills/devlyn-ideate/scripts/queue.py +1780 -0
  31. package/node_modules/@inquirer/ansi/LICENSE +22 -0
  32. package/node_modules/@inquirer/ansi/README.md +121 -0
  33. package/node_modules/@inquirer/ansi/dist/index.d.ts +14 -0
  34. package/node_modules/@inquirer/ansi/dist/index.js +21 -0
  35. package/node_modules/@inquirer/ansi/package.json +79 -0
  36. package/node_modules/@inquirer/checkbox/LICENSE +22 -0
  37. package/node_modules/@inquirer/checkbox/README.md +265 -0
  38. package/node_modules/@inquirer/checkbox/dist/index.d.ts +67 -0
  39. package/node_modules/@inquirer/checkbox/dist/index.js +210 -0
  40. package/node_modules/@inquirer/checkbox/package.json +93 -0
  41. package/node_modules/@inquirer/core/LICENSE +22 -0
  42. package/node_modules/@inquirer/core/README.md +424 -0
  43. package/node_modules/@inquirer/core/dist/index.d.ts +13 -0
  44. package/node_modules/@inquirer/core/dist/index.js +12 -0
  45. package/node_modules/@inquirer/core/dist/lib/Separator.d.ts +10 -0
  46. package/node_modules/@inquirer/core/dist/lib/Separator.js +21 -0
  47. package/node_modules/@inquirer/core/dist/lib/__probe/p1.d.ts +9 -0
  48. package/node_modules/@inquirer/core/dist/lib/__probe/p1.js +4 -0
  49. package/node_modules/@inquirer/core/dist/lib/__probe/p2.d.ts +9 -0
  50. package/node_modules/@inquirer/core/dist/lib/__probe/p2.js +3 -0
  51. package/node_modules/@inquirer/core/dist/lib/__probe/p3.d.ts +9 -0
  52. package/node_modules/@inquirer/core/dist/lib/__probe/p3.js +5 -0
  53. package/node_modules/@inquirer/core/dist/lib/create-prompt.d.ts +11 -0
  54. package/node_modules/@inquirer/core/dist/lib/create-prompt.js +185 -0
  55. package/node_modules/@inquirer/core/dist/lib/errors.d.ts +20 -0
  56. package/node_modules/@inquirer/core/dist/lib/errors.js +21 -0
  57. package/node_modules/@inquirer/core/dist/lib/hook-engine.d.ts +17 -0
  58. package/node_modules/@inquirer/core/dist/lib/hook-engine.js +109 -0
  59. package/node_modules/@inquirer/core/dist/lib/key.d.ts +15 -0
  60. package/node_modules/@inquirer/core/dist/lib/key.js +34 -0
  61. package/node_modules/@inquirer/core/dist/lib/make-theme.d.ts +3 -0
  62. package/node_modules/@inquirer/core/dist/lib/make-theme.js +33 -0
  63. package/node_modules/@inquirer/core/dist/lib/pagination/use-pagination.d.ts +15 -0
  64. package/node_modules/@inquirer/core/dist/lib/pagination/use-pagination.js +121 -0
  65. package/node_modules/@inquirer/core/dist/lib/screen-manager.d.ts +14 -0
  66. package/node_modules/@inquirer/core/dist/lib/screen-manager.js +84 -0
  67. package/node_modules/@inquirer/core/dist/lib/theme.d.ts +166 -0
  68. package/node_modules/@inquirer/core/dist/lib/theme.js +29 -0
  69. package/node_modules/@inquirer/core/dist/lib/use-effect.d.ts +2 -0
  70. package/node_modules/@inquirer/core/dist/lib/use-effect.js +11 -0
  71. package/node_modules/@inquirer/core/dist/lib/use-keypress.d.ts +3 -0
  72. package/node_modules/@inquirer/core/dist/lib/use-keypress.js +20 -0
  73. package/node_modules/@inquirer/core/dist/lib/use-memo.d.ts +1 -0
  74. package/node_modules/@inquirer/core/dist/lib/use-memo.js +14 -0
  75. package/node_modules/@inquirer/core/dist/lib/use-prefix.d.ts +5 -0
  76. package/node_modules/@inquirer/core/dist/lib/use-prefix.js +35 -0
  77. package/node_modules/@inquirer/core/dist/lib/use-ref.d.ts +6 -0
  78. package/node_modules/@inquirer/core/dist/lib/use-ref.js +4 -0
  79. package/node_modules/@inquirer/core/dist/lib/use-state.d.ts +7 -0
  80. package/node_modules/@inquirer/core/dist/lib/use-state.js +28 -0
  81. package/node_modules/@inquirer/core/dist/lib/utils.d.ts +13 -0
  82. package/node_modules/@inquirer/core/dist/lib/utils.js +25 -0
  83. package/node_modules/@inquirer/core/package.json +98 -0
  84. package/node_modules/@inquirer/figures/LICENSE +22 -0
  85. package/node_modules/@inquirer/figures/dist/index.d.ts +275 -0
  86. package/node_modules/@inquirer/figures/dist/index.js +315 -0
  87. package/node_modules/@inquirer/figures/package.json +81 -0
  88. package/node_modules/@inquirer/select/LICENSE +22 -0
  89. package/node_modules/@inquirer/select/README.md +258 -0
  90. package/node_modules/@inquirer/select/dist/index.d.ts +42 -0
  91. package/node_modules/@inquirer/select/dist/index.js +191 -0
  92. package/node_modules/@inquirer/select/package.json +93 -0
  93. package/node_modules/@inquirer/type/LICENSE +22 -0
  94. package/node_modules/@inquirer/type/dist/index.d.ts +2 -0
  95. package/node_modules/@inquirer/type/dist/index.js +2 -0
  96. package/node_modules/@inquirer/type/dist/inquirer.d.ts +35 -0
  97. package/node_modules/@inquirer/type/dist/inquirer.js +1 -0
  98. package/node_modules/@inquirer/type/dist/utils.d.ts +45 -0
  99. package/node_modules/@inquirer/type/dist/utils.js +16 -0
  100. package/node_modules/@inquirer/type/package.json +88 -0
  101. package/node_modules/cli-width/LICENSE +13 -0
  102. package/node_modules/cli-width/README.md +71 -0
  103. package/node_modules/cli-width/index.d.ts +13 -0
  104. package/node_modules/cli-width/index.js +49 -0
  105. package/node_modules/cli-width/package.json +40 -0
  106. package/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
  107. package/node_modules/fast-string-truncated-width/dist/index.js +111 -0
  108. package/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
  109. package/node_modules/fast-string-truncated-width/dist/types.js +2 -0
  110. package/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
  111. package/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
  112. package/node_modules/fast-string-truncated-width/license +21 -0
  113. package/node_modules/fast-string-truncated-width/package.json +35 -0
  114. package/node_modules/fast-string-truncated-width/readme.md +59 -0
  115. package/node_modules/fast-string-width/dist/index.d.ts +4 -0
  116. package/node_modules/fast-string-width/dist/index.js +14 -0
  117. package/node_modules/fast-string-width/license +21 -0
  118. package/node_modules/fast-string-width/package.json +34 -0
  119. package/node_modules/fast-string-width/readme.md +42 -0
  120. package/node_modules/fast-wrap-ansi/LICENSE +23 -0
  121. package/node_modules/fast-wrap-ansi/README.md +26 -0
  122. package/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
  123. package/node_modules/fast-wrap-ansi/lib/main.js +218 -0
  124. package/node_modules/fast-wrap-ansi/package.json +51 -0
  125. package/node_modules/mute-stream/LICENSE +15 -0
  126. package/node_modules/mute-stream/README.md +68 -0
  127. package/node_modules/mute-stream/lib/index.js +142 -0
  128. package/node_modules/mute-stream/package.json +54 -0
  129. package/node_modules/signal-exit/LICENSE.txt +16 -0
  130. package/node_modules/signal-exit/README.md +74 -0
  131. package/node_modules/signal-exit/dist/cjs/browser.d.ts +12 -0
  132. package/node_modules/signal-exit/dist/cjs/browser.d.ts.map +1 -0
  133. package/node_modules/signal-exit/dist/cjs/browser.js +10 -0
  134. package/node_modules/signal-exit/dist/cjs/browser.js.map +1 -0
  135. package/node_modules/signal-exit/dist/cjs/index.d.ts +48 -0
  136. package/node_modules/signal-exit/dist/cjs/index.d.ts.map +1 -0
  137. package/node_modules/signal-exit/dist/cjs/index.js +279 -0
  138. package/node_modules/signal-exit/dist/cjs/index.js.map +1 -0
  139. package/node_modules/signal-exit/dist/cjs/package.json +3 -0
  140. package/node_modules/signal-exit/dist/cjs/signals.d.ts +29 -0
  141. package/node_modules/signal-exit/dist/cjs/signals.d.ts.map +1 -0
  142. package/node_modules/signal-exit/dist/cjs/signals.js +42 -0
  143. package/node_modules/signal-exit/dist/cjs/signals.js.map +1 -0
  144. package/node_modules/signal-exit/dist/mjs/browser.d.ts +12 -0
  145. package/node_modules/signal-exit/dist/mjs/browser.d.ts.map +1 -0
  146. package/node_modules/signal-exit/dist/mjs/browser.js +4 -0
  147. package/node_modules/signal-exit/dist/mjs/browser.js.map +1 -0
  148. package/node_modules/signal-exit/dist/mjs/index.d.ts +48 -0
  149. package/node_modules/signal-exit/dist/mjs/index.d.ts.map +1 -0
  150. package/node_modules/signal-exit/dist/mjs/index.js +275 -0
  151. package/node_modules/signal-exit/dist/mjs/index.js.map +1 -0
  152. package/node_modules/signal-exit/dist/mjs/package.json +3 -0
  153. package/node_modules/signal-exit/dist/mjs/signals.d.ts +29 -0
  154. package/node_modules/signal-exit/dist/mjs/signals.d.ts.map +1 -0
  155. package/node_modules/signal-exit/dist/mjs/signals.js +39 -0
  156. package/node_modules/signal-exit/dist/mjs/signals.js.map +1 -0
  157. package/node_modules/signal-exit/package.json +106 -0
  158. package/package.json +17 -4
  159. package/config/commit-conventions.md +0 -28
  160. package/config/skills/_shared/adapters/README.md +0 -74
  161. package/config/skills/_shared/adapters/grok.md +0 -100
  162. package/config/skills/_shared/archive_run.py +0 -969
  163. package/config/skills/_shared/codex-config.md +0 -81
  164. package/config/skills/_shared/collect-codex-findings.py +0 -505
  165. package/config/skills/_shared/finish-gate.py +0 -521
  166. package/config/skills/_shared/grok-anchor-guard.py +0 -78
  167. package/config/skills/_shared/judge-output-parser.py +0 -200
  168. package/config/skills/_shared/judge-role-evidence.py +0 -320
  169. package/config/skills/_shared/phase-prompt-render.py +0 -183
  170. package/config/skills/_shared/process-evidence.py +0 -926
  171. package/config/skills/_shared/resolve-bootstrap.py +0 -1410
  172. package/config/skills/_shared/resolve-stop-hook.py +0 -359
  173. package/config/skills/_shared/run-bounded.py +0 -58
  174. package/config/skills/_shared/spec-verify-check.py +0 -5083
  175. package/config/skills/_shared/state-phase-write.py +0 -5989
  176. package/config/skills/_shared/terminal-claim-check.py +0 -777
  177. package/config/skills/_shared/verify-merge-findings.py +0 -3528
  178. package/config/skills/devlyn-design-ui/SKILL.md +0 -650
  179. package/config/skills/devlyn-ideate/references/from-spec-mode.md +0 -61
  180. package/config/skills/devlyn-ideate/references/project-mode.md +0 -80
  181. package/config/skills/devlyn-ideate/references/spec-template.md +0 -121
  182. package/config/skills/devlyn-ideate/references/templates/decision.md +0 -48
  183. package/config/skills/devlyn-ideate/references/templates/roadmap.md +0 -50
  184. package/config/skills/devlyn-ideate/references/templates/vision.md +0 -44
  185. package/config/skills/devlyn-queue/SKILL.md +0 -66
  186. package/config/skills/devlyn-queue/scripts/append.py +0 -94
  187. package/config/skills/devlyn-resolve/SKILL.md +0 -379
  188. package/config/skills/devlyn-resolve/references/free-form-mode.md +0 -71
  189. package/config/skills/devlyn-resolve/references/outer-loop.md +0 -23
  190. package/config/skills/devlyn-resolve/references/phases/build-gate.md +0 -75
  191. package/config/skills/devlyn-resolve/references/phases/cleanup.md +0 -33
  192. package/config/skills/devlyn-resolve/references/phases/implement.md +0 -44
  193. package/config/skills/devlyn-resolve/references/phases/plan.md +0 -39
  194. package/config/skills/devlyn-resolve/references/phases/probe-derive.md +0 -261
  195. package/config/skills/devlyn-resolve/references/phases/surface-close.md +0 -34
  196. package/config/skills/devlyn-resolve/references/phases/verify.md +0 -310
  197. package/config/skills/devlyn-resolve/references/state-schema.md +0 -152
  198. package/config/skills/devlyn-resolve/references/task-completion.md +0 -160
  199. package/config/templates/prompt-templates.md +0 -71
  200. package/config/templates/template-feature.spec.md +0 -255
  201. package/config/templates/template-product-spec.md +0 -680
@@ -0,0 +1,424 @@
1
+ # `@inquirer/core`
2
+
3
+ The `@inquirer/core` package is the library enabling the creation of Inquirer prompts.
4
+
5
+ It aims to implements a lightweight API similar to React hooks - but without JSX.
6
+
7
+ # Installation
8
+
9
+ <table>
10
+ <tr>
11
+ <th>yarn</th>
12
+ <th>pnpm</th>
13
+ </tr>
14
+ <tr>
15
+ <td>
16
+
17
+ ```sh
18
+ yarn add @inquirer/core
19
+ ```
20
+
21
+ </td>
22
+ <td>
23
+
24
+ ```sh
25
+ pnpm add @inquirer/core
26
+ ```
27
+
28
+ </td>
29
+ </tr>
30
+ <tr>
31
+ <th>bun</th>
32
+ <th>deno</th>
33
+ </tr>
34
+ <tr>
35
+ <td>
36
+
37
+ ```sh
38
+ bun add @inquirer/core
39
+ ```
40
+
41
+ </td>
42
+ <td>
43
+
44
+ ```sh
45
+ deno add npm:@inquirer/core
46
+ ```
47
+
48
+ </td>
49
+ </tr>
50
+ <tr>
51
+ <th colSpan="2">npm</th>
52
+ </tr>
53
+ <tr>
54
+ <td colSpan="2">
55
+
56
+ ```sh
57
+ npm install @inquirer/core
58
+ ```
59
+
60
+ </td>
61
+ </tr>
62
+ </table>
63
+
64
+ # Usage
65
+
66
+ ## Basic concept
67
+
68
+ Visual terminal apps are at their core strings rendered onto the terminal.
69
+
70
+ The most basic prompt is a function returning a string that'll be rendered in the terminal. This function will run every time the prompt state change, and the new returned string will replace the previously rendered one. The prompt cursor appears after the string.
71
+
72
+ Wrapping the rendering function with `createPrompt()` will setup the rendering layer, inject the state management utilities, and wait until the `done` callback is called.
73
+
74
+ ```ts
75
+ import { createPrompt } from '@inquirer/core';
76
+
77
+ const input = createPrompt((config, done) => {
78
+ // Implement logic
79
+
80
+ return '? My question';
81
+ });
82
+
83
+ // And it is then called as
84
+ const answer = await input({/* config */});
85
+ ```
86
+
87
+ ## Hooks
88
+
89
+ State management and user interactions are handled through hooks. Hooks are common [within the React ecosystem](https://react.dev/reference/react/hooks), and Inquirer reimplement the common ones.
90
+
91
+ ### State hook
92
+
93
+ State lets a component “remember” information like user input. For example, an input prompt can use state to store the input value, while a list prompt can use state to track the cursor index.
94
+
95
+ `useState` declares a state variable that you can update directly.
96
+
97
+ The setter also accepts an updater function to compute the next state from the current one (mirroring React):
98
+
99
+ ```ts
100
+ const [index, setIndex] = useState(0);
101
+
102
+ setIndex((current) => current + 1);
103
+ ```
104
+
105
+ ```ts
106
+ import { createPrompt, useState } from '@inquirer/core';
107
+
108
+ const input = createPrompt((config, done) => {
109
+ const [index, setIndex] = useState(0);
110
+
111
+ // ...
112
+ ```
113
+
114
+ ### Keypress hook
115
+
116
+ Almost all prompts need to react to user actions. In a terminal, this is done through typing.
117
+
118
+ `useKeypress` allows you to react to keypress events, and access the prompt line.
119
+
120
+ ```ts
121
+ const input = createPrompt((config, done) => {
122
+ useKeypress((key) => {
123
+ if (key.name === 'enter') {
124
+ done(answer);
125
+ }
126
+ });
127
+
128
+ // ...
129
+ ```
130
+
131
+ Behind the scenes, Inquirer prompts are wrappers around [readlines](https://nodejs.org/api/readline.html). Aside the keypress event object, the hook also pass the active readline instance to the event handler.
132
+
133
+ ```ts
134
+ const input = createPrompt((config, done) => {
135
+ useKeypress((key, readline) => {
136
+ setValue(readline.line);
137
+ });
138
+
139
+ // ...
140
+ ```
141
+
142
+ ### Ref hook
143
+
144
+ Refs let a prompt hold some information that isn’t used for rendering, like a class instance or a timeout ID. Unlike with state, updating a ref does not re-render your prompt. Refs are an “escape hatch” from the rendering paradigm.
145
+
146
+ `useRef` declares a ref. You can hold any value in it, but most often it’s used to hold a timeout ID.
147
+
148
+ ```ts
149
+ const input = createPrompt((config, done) => {
150
+ const timeout = useRef(null);
151
+
152
+ // ...
153
+ ```
154
+
155
+ ### Effect Hook
156
+
157
+ Effects let a prompt connect to and synchronize with external systems. This includes dealing with network or animations.
158
+
159
+ `useEffect` connects a component to an external system.
160
+
161
+ ```ts
162
+ const chat = createPrompt((config, done) => {
163
+ useEffect(() => {
164
+ const connection = createConnection(roomId);
165
+ connection.connect();
166
+ return () => connection.disconnect();
167
+ }, [roomId]);
168
+
169
+ // ...
170
+ ```
171
+
172
+ ### Performance hook
173
+
174
+ A common way to optimize re-rendering performance is to skip unnecessary work. For example, you can tell Inquirer to reuse a cached calculation or to skip a re-render if the data has not changed since the previous render.
175
+
176
+ `useMemo` lets you cache the result of an expensive calculation.
177
+
178
+ ```ts
179
+ const todoSelect = createPrompt((config, done) => {
180
+ const visibleTodos = useMemo(() => filterTodos(todos, tab), [todos, tab]);
181
+
182
+ // ...
183
+ ```
184
+
185
+ ### Rendering hooks
186
+
187
+ #### Prefix / loading
188
+
189
+ All default prompts, and most custom ones, uses a prefix at the beginning of the prompt line. This helps visually delineate different questions, and provides a convenient area to render a loading spinner.
190
+
191
+ `usePrefix` is a built-in hook to do this.
192
+
193
+ ```ts
194
+ const input = createPrompt((config, done) => {
195
+ const prefix = usePrefix({ status });
196
+
197
+ return `${prefix} My question`;
198
+ });
199
+ ```
200
+
201
+ #### Pagination
202
+
203
+ When looping through a long list of options (like in the `select` prompt), paginating the results appearing on the screen at once can be necessary. The `usePagination` hook is the utility used within the `select` and `checkbox` prompts to cycle through the list of options.
204
+
205
+ Pagination works by taking in the list of options and returning a subset of the rendered items that fit within the page. The hook takes in a few options. It needs a list of options (`items`), and a `pageSize` which is the number of lines to be rendered. The `active` index is the index of the currently selected/selectable item. The `loop` option is a boolean that indicates if the list should loop around when reaching the end: this is the default behavior. The pagination hook renders items only as necessary, so it takes a function that can render an item at an index, including an `active` state, called `renderItem`.
206
+
207
+ ```js
208
+ export default createPrompt((config, done) => {
209
+ const [active, setActive] = useState(0);
210
+
211
+ const allChoices = config.choices.map((choice) => choice.name);
212
+
213
+ const page = usePagination({
214
+ items: allChoices,
215
+ active: active,
216
+ renderItem: ({ item, index, isActive }) => `${isActive ? ">" : " "}${index}. ${item.toString()}`
217
+ pageSize: config.pageSize,
218
+ loop: config.loop,
219
+ });
220
+
221
+ return `... ${page}`;
222
+ });
223
+ ```
224
+
225
+ ## `createPrompt()` API
226
+
227
+ As we saw earlier, the rendering function should return a string, and eventually call `done` to close the prompt and return the answer.
228
+
229
+ ```ts
230
+ const input = createPrompt((config, done) => {
231
+ const [value, setValue] = useState();
232
+
233
+ useKeypress((key, readline) => {
234
+ if (key.name === 'enter') {
235
+ done(answer);
236
+ } else {
237
+ setValue(readline.line);
238
+ }
239
+ });
240
+
241
+ return `? ${config.message} ${value}`;
242
+ });
243
+ ```
244
+
245
+ The rendering function can also return a tuple of 2 string (`[string, string]`.) The first string represents the prompt. The second one is content to render under the prompt, like an error message. The text input cursor will appear after the first string.
246
+
247
+ ```ts
248
+ const number = createPrompt((config, done) => {
249
+ // Add some logic here
250
+
251
+ return [`? My question ${input}`, `! The input must be a number`];
252
+ });
253
+ ```
254
+
255
+ ### Typescript
256
+
257
+ If using typescript, `createPrompt` takes 2 generic arguments.
258
+
259
+ ```ts
260
+ // createPrompt<Value, Config>
261
+ const input = createPrompt<string, { message: string }>(// ...
262
+ ```
263
+
264
+ The first one is the type of the resolved value
265
+
266
+ ```ts
267
+ const answer: string = await input();
268
+ ```
269
+
270
+ The second one is the type of the prompt config; in other words the interface the created prompt will provide to users.
271
+
272
+ ```ts
273
+ const answer = await input({
274
+ message: 'My question',
275
+ });
276
+ ```
277
+
278
+ ## Key utilities
279
+
280
+ Listening for keypress events inside an inquirer prompt is a very common pattern. To ease this, we export a few utility functions taking in the keypress event object and return a boolean:
281
+
282
+ - `isEnterKey()`
283
+ - `isBackspaceKey()`
284
+ - `isSpaceKey()`
285
+ - `isUpKey()` - Note: this utility will handle vim and emacs keybindings (up, `k`, and `ctrl+p`)
286
+ - `isDownKey()` - Note: this utility will handle vim and emacs keybindings (down, `j`, and `ctrl+n`)
287
+ - `isNumberKey()` one of 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
288
+
289
+ Set `INQUIRER_KEYBINDINGS=vim`, `INQUIRER_KEYBINDINGS=emacs`, or `INQUIRER_KEYBINDINGS=vim,emacs` to enable alternative navigation keybindings globally. Prompt-level `theme.keybindings` values override the environment variable.
290
+
291
+ ## Theming
292
+
293
+ Theming utilities will allow you to expose customization of the prompt style. Inquirer also has a few standard theme values shared across all the official prompts.
294
+
295
+ To allow standard customization:
296
+
297
+ ```ts
298
+ import { createPrompt, usePrefix, makeTheme, type Theme } from '@inquirer/core';
299
+ import type { PartialDeep } from '@inquirer/type';
300
+
301
+ type PromptConfig = {
302
+ theme?: PartialDeep<Theme>;
303
+ };
304
+
305
+ export default createPrompt<string, PromptConfig>((config, done) => {
306
+ const theme = makeTheme(config.theme);
307
+
308
+ const prefix = usePrefix({ status, theme });
309
+
310
+ return `${prefix} ${theme.style.highlight('hello')}`;
311
+ });
312
+ ```
313
+
314
+ To setup a custom theme:
315
+
316
+ ```ts
317
+ import { createPrompt, makeTheme, type Theme } from '@inquirer/core';
318
+ import type { PartialDeep } from '@inquirer/type';
319
+
320
+ type PromptTheme = {};
321
+
322
+ const promptTheme: PromptTheme = {
323
+ icon: '!',
324
+ };
325
+
326
+ type PromptConfig = {
327
+ theme?: PartialDeep<Theme<PromptTheme>>;
328
+ };
329
+
330
+ export default createPrompt<string, PromptConfig>((config, done) => {
331
+ const theme = makeTheme(promptTheme, config.theme);
332
+
333
+ const prefix = usePrefix({ status, theme });
334
+
335
+ return `${prefix} ${theme.icon}`;
336
+ });
337
+ ```
338
+
339
+ The [default theme keys cover](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/core/src/lib/theme.ts):
340
+
341
+ ```ts
342
+ type DefaultTheme = {
343
+ prefix: string | { idle: string; done: string };
344
+ spinner: {
345
+ interval: number;
346
+ frames: string[];
347
+ };
348
+ keybindings: readonly ('emacs' | 'vim')[];
349
+ style: {
350
+ answer: (text: string) => string;
351
+ message: (text: string, status: 'idle' | 'done' | 'loading') => string;
352
+ error: (text: string) => string;
353
+ defaultAnswer: (text: string) => string;
354
+ help: (text: string) => string;
355
+ highlight: (text: string) => string;
356
+ key: (text: string) => string;
357
+ };
358
+ };
359
+ ```
360
+
361
+ # Examples
362
+
363
+ You can refer to any `@inquirer/prompts` prompts for real examples:
364
+
365
+ - [Confirm Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/confirm/src/index.ts)
366
+ - [Input Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/input/src/index.ts)
367
+ - [Password Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/password/src/index.ts)
368
+ - [Editor Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/editor/src/index.ts)
369
+ - [Select Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/select/src/index.ts)
370
+ - [Checkbox Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/checkbox/src/index.ts)
371
+ - [Rawlist Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/rawlist/src/index.ts)
372
+ - [Expand Prompt](https://github.com/SBoudrias/Inquirer.js/blob/main/packages/expand/src/index.ts)
373
+
374
+ ```ts
375
+ import { styleText } from 'node:util';
376
+ import {
377
+ createPrompt,
378
+ useState,
379
+ useKeypress,
380
+ isEnterKey,
381
+ usePrefix,
382
+ type Status,
383
+ } from '@inquirer/core';
384
+
385
+ const confirm = createPrompt<boolean, { message: string; default?: boolean }>(
386
+ (config, done) => {
387
+ const [status, setStatus] = useState<Status>('idle');
388
+ const [value, setValue] = useState('');
389
+ const prefix = usePrefix({});
390
+
391
+ useKeypress((key, rl) => {
392
+ if (isEnterKey(key)) {
393
+ const answer = value ? /^y(es)?/i.test(value) : config.default !== false;
394
+ setValue(answer ? 'yes' : 'no');
395
+ setStatus('done');
396
+ done(answer);
397
+ } else {
398
+ setValue(rl.line);
399
+ }
400
+ });
401
+
402
+ let formattedValue = value;
403
+ let defaultValue = '';
404
+ if (status === 'done') {
405
+ formattedValue = styleText('cyan', value);
406
+ } else {
407
+ defaultValue = styleText('dim', config.default === false ? ' (y/N)' : ' (Y/n)');
408
+ }
409
+
410
+ const message = styleText('bold', config.message);
411
+ return `${prefix} ${message}${defaultValue} ${formattedValue}`;
412
+ },
413
+ );
414
+
415
+ /**
416
+ * Which then can be used like this:
417
+ */
418
+ const answer = await confirm({ message: 'Do you want to continue?' });
419
+ ```
420
+
421
+ # License
422
+
423
+ Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
424
+ Licensed under the MIT license.
@@ -0,0 +1,13 @@
1
+ export { isUpKey, isDownKey, isSpaceKey, isBackspaceKey, isTabKey, isNumberKey, isEnterKey, isShiftKey, type KeypressEvent, type Keybinding, } from './lib/key.ts';
2
+ export * from './lib/errors.ts';
3
+ export { usePrefix } from './lib/use-prefix.ts';
4
+ export { useState } from './lib/use-state.ts';
5
+ export { useEffect } from './lib/use-effect.ts';
6
+ export { useMemo } from './lib/use-memo.ts';
7
+ export { useRef } from './lib/use-ref.ts';
8
+ export { useKeypress } from './lib/use-keypress.ts';
9
+ export { makeTheme } from './lib/make-theme.ts';
10
+ export type { Theme, Status } from './lib/theme.ts';
11
+ export { usePagination } from './lib/pagination/use-pagination.ts';
12
+ export { createPrompt } from './lib/create-prompt.ts';
13
+ export { Separator } from './lib/Separator.ts';
@@ -0,0 +1,12 @@
1
+ export { isUpKey, isDownKey, isSpaceKey, isBackspaceKey, isTabKey, isNumberKey, isEnterKey, isShiftKey, } from "./lib/key.js";
2
+ export * from "./lib/errors.js";
3
+ export { usePrefix } from "./lib/use-prefix.js";
4
+ export { useState } from "./lib/use-state.js";
5
+ export { useEffect } from "./lib/use-effect.js";
6
+ export { useMemo } from "./lib/use-memo.js";
7
+ export { useRef } from "./lib/use-ref.js";
8
+ export { useKeypress } from "./lib/use-keypress.js";
9
+ export { makeTheme } from "./lib/make-theme.js";
10
+ export { usePagination } from "./lib/pagination/use-pagination.js";
11
+ export { createPrompt } from "./lib/create-prompt.js";
12
+ export { Separator } from "./lib/Separator.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Separator object
3
+ * Used to space/separate choices group
4
+ */
5
+ export declare class Separator {
6
+ readonly separator: string;
7
+ readonly type: string;
8
+ constructor(separator?: string);
9
+ static isSeparator(choice: unknown): choice is Separator;
10
+ }
@@ -0,0 +1,21 @@
1
+ import { styleText } from 'node:util';
2
+ import figures from '@inquirer/figures';
3
+ /**
4
+ * Separator object
5
+ * Used to space/separate choices group
6
+ */
7
+ export class Separator {
8
+ separator = styleText('dim', Array.from({ length: 15 }).join(figures.line));
9
+ type = 'separator';
10
+ constructor(separator) {
11
+ if (separator) {
12
+ this.separator = separator;
13
+ }
14
+ }
15
+ static isSeparator(choice) {
16
+ return Boolean(choice &&
17
+ typeof choice === 'object' &&
18
+ 'type' in choice &&
19
+ choice.type === 'separator');
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ type A = {
2
+ a: string;
3
+ };
4
+ type B = {
5
+ a: string;
6
+ b: number;
7
+ };
8
+ export declare function f(x: A): B;
9
+ export {};
@@ -0,0 +1,4 @@
1
+ export function f(x) {
2
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
3
+ return x;
4
+ }
@@ -0,0 +1,9 @@
1
+ type A = {
2
+ a: string;
3
+ };
4
+ type B = {
5
+ a: string;
6
+ b: number;
7
+ };
8
+ export declare function f(x: A): B;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ export function f(x) {
2
+ return x; // oxlint-disable-line typescript/no-unsafe-type-assertion
3
+ }
@@ -0,0 +1,9 @@
1
+ type A = {
2
+ a: string;
3
+ };
4
+ type B = {
5
+ a: string;
6
+ b: number;
7
+ };
8
+ export declare function f(x: A): B;
9
+ export {};
@@ -0,0 +1,5 @@
1
+ /* oxlint-disable typescript/no-unsafe-type-assertion */
2
+ export function f(x) {
3
+ return x;
4
+ }
5
+ /* oxlint-enable typescript/no-unsafe-type-assertion */
@@ -0,0 +1,11 @@
1
+ import { type Prompt } from '@inquirer/type';
2
+ type ViewFunction<Value, Config> = (config: Config, done: (value: Value) => void) => string | [string, string | undefined];
3
+ /**
4
+ * Expand the top-level keys of a type for better IDE display, without
5
+ * recursing into nested fields (so generic values stay compatible).
6
+ */
7
+ type ShallowPrettify<T> = {
8
+ [K in keyof T]: T[K];
9
+ } & {};
10
+ export declare function createPrompt<Value, Config>(view: ViewFunction<Value, Config>): Prompt<Value, ShallowPrettify<Config> & Config>;
11
+ export {};