@henryqw/pi-ask-question 0.1.8 → 0.1.9

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.
package/README.md CHANGED
@@ -41,7 +41,6 @@ pi remove npm:@henryqw/pi-ask-question
41
41
  ## Development
42
42
 
43
43
  ```bash
44
- npm test --workspace @henryqw/pi-ask-question
45
44
  npm run typecheck --workspace @henryqw/pi-ask-question
46
45
  npm run pack:check --workspace @henryqw/pi-ask-question
47
46
  ```
@@ -3,6 +3,7 @@ import {
3
3
  Editor,
4
4
  type EditorTheme,
5
5
  Key,
6
+ type KeyId,
6
7
  matchesKey,
7
8
  Text,
8
9
  visibleWidth,
@@ -21,7 +22,6 @@ const CUSTOM_OPTION_LABEL = "Something else.";
21
22
  // Models are told to omit "(Recommended)" from labels but don't always comply; normalize instead of duplicating.
22
23
  const RECOMMENDED_SUFFIX = /\s*\(recommended\)\s*$/i;
23
24
  const withRecommended = (label: string): string => `${label.replace(RECOMMENDED_SUFFIX, "")} (Recommended)`;
24
- const NUMBER_KEYS = ["1", "2", "3", "4"] as const;
25
25
 
26
26
  interface QuestionDetails {
27
27
  question: string;
@@ -75,8 +75,7 @@ export default function askQuestionExtension(pi: ExtensionAPI): void {
75
75
  };
76
76
  }
77
77
  let validationError: string | undefined;
78
- if (suppliedOptions.length < 1 || suppliedOptions.length > 3) validationError = "1 to 3 options required";
79
- else if (!question) validationError = "Question must not be blank";
78
+ if (!question) validationError = "Question must not be blank";
80
79
  else if (suppliedOptions.some((option) => !option.label)) validationError = "Option labels must not be blank";
81
80
  else if (new Set(options.map((option) => option.toLowerCase())).size !== options.length) validationError = "Option labels must be unique";
82
81
  else if (options.some((option) => option.toLowerCase() === CUSTOM_OPTION_LABEL.toLowerCase())) validationError = `Option label "${CUSTOM_OPTION_LABEL}" is reserved`;
@@ -139,7 +138,7 @@ export default function askQuestionExtension(pi: ExtensionAPI): void {
139
138
  return;
140
139
  }
141
140
 
142
- const numberIndex = NUMBER_KEYS.findIndex((key, index) => index < allOptions.length && matchesKey(data, key));
141
+ const numberIndex = allOptions.findIndex((_, index) => matchesKey(data, `${index + 1}` as KeyId));
143
142
  if (numberIndex >= 0) {
144
143
  optionIndex = numberIndex;
145
144
  selectOption();
@@ -157,11 +156,10 @@ export default function askQuestionExtension(pi: ExtensionAPI): void {
157
156
  if (cachedLines) return cachedLines;
158
157
  const lines: string[] = [];
159
158
  const renderWidth = Math.max(1, width);
160
- const addWrapped = (text: string): void => { lines.push(...wrapTextWithAnsi(text, renderWidth)); };
161
159
  const addWrappedWithPrefix = (prefix: string, text: string): void => {
162
160
  const prefixWidth = visibleWidth(prefix);
163
161
  if (prefixWidth >= renderWidth) {
164
- addWrapped(prefix + text);
162
+ lines.push(...wrapTextWithAnsi(prefix + text, renderWidth));
165
163
  return;
166
164
  }
167
165
  const wrapped = wrapTextWithAnsi(text, renderWidth - prefixWidth);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-ask-question",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Ask Pi users one interactive question with choices or a custom answer.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -19,7 +19,6 @@
19
19
  "LICENSE"
20
20
  ],
21
21
  "scripts": {
22
- "test": "node --test test/*.test.ts",
23
22
  "test:manual": "pi --no-extensions -e ./extensions/ask-question.ts --tools ask_question --no-session \"We need storage for a small team app. Before making changes, ask me to choose storage.\"",
24
23
  "typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2022 --module NodeNext --moduleResolution NodeNext --skipLibCheck extensions/ask-question.ts",
25
24
  "pack:check": "npm pack --dry-run"