@within-7/minto 0.1.1 → 0.1.3

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.
@@ -0,0 +1,140 @@
1
+ import { Box, Text, useInput } from "ink";
2
+ import * as React from "react";
3
+ import { useState, useCallback } from "react";
4
+ import { QuestionView } from "./QuestionView.js";
5
+ import { useNotifyAfterTimeout } from "../../hooks/useNotifyAfterTimeout.js";
6
+ import { PRODUCT_NAME } from "../../constants/product.js";
7
+ import TextInput from "ink-text-input";
8
+ function AskUserQuestionDialog({
9
+ context,
10
+ onDone
11
+ }) {
12
+ const { questions, resolve, reject } = context;
13
+ const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
14
+ const [selectedOptions, setSelectedOptions] = useState(
15
+ questions.map(() => 0)
16
+ );
17
+ const [isCustomInputMode, setIsCustomInputMode] = useState(false);
18
+ const [customInput, setCustomInput] = useState("");
19
+ useNotifyAfterTimeout(`${PRODUCT_NAME} needs your input to continue`);
20
+ const currentQuestion = questions[currentQuestionIndex];
21
+ useInput(
22
+ (input, key) => {
23
+ if (key.escape || key.ctrl && input === "c") {
24
+ onDone();
25
+ reject();
26
+ return;
27
+ }
28
+ if (isCustomInputMode) {
29
+ return;
30
+ }
31
+ if (key.leftArrow && currentQuestionIndex > 0) {
32
+ setCurrentQuestionIndex((prev) => prev - 1);
33
+ return;
34
+ }
35
+ if (key.rightArrow && currentQuestionIndex < questions.length - 1) {
36
+ setCurrentQuestionIndex((prev) => prev + 1);
37
+ return;
38
+ }
39
+ if (key.return) {
40
+ handleConfirm();
41
+ return;
42
+ }
43
+ if (input === "o" && currentQuestion.options) {
44
+ setIsCustomInputMode(true);
45
+ setCustomInput("");
46
+ return;
47
+ }
48
+ },
49
+ { isActive: true }
50
+ );
51
+ const handleOptionChange = useCallback(
52
+ (optionIndex) => {
53
+ const newSelectedOptions = [...selectedOptions];
54
+ newSelectedOptions[currentQuestionIndex] = optionIndex;
55
+ setSelectedOptions(newSelectedOptions);
56
+ if (optionIndex === -1) {
57
+ setIsCustomInputMode(true);
58
+ setCustomInput("");
59
+ }
60
+ },
61
+ [selectedOptions, currentQuestionIndex]
62
+ );
63
+ const handleConfirm = useCallback(() => {
64
+ if (isCustomInputMode) {
65
+ if (!customInput.trim()) {
66
+ return;
67
+ }
68
+ setIsCustomInputMode(false);
69
+ if (currentQuestionIndex === questions.length - 1) {
70
+ submitAnswers(customInput);
71
+ } else {
72
+ setCurrentQuestionIndex((prev) => prev + 1);
73
+ }
74
+ return;
75
+ }
76
+ if (currentQuestionIndex === questions.length - 1) {
77
+ submitAnswers();
78
+ } else {
79
+ setCurrentQuestionIndex((prev) => prev + 1);
80
+ }
81
+ }, [isCustomInputMode, customInput, currentQuestionIndex, questions.length]);
82
+ const submitAnswers = useCallback(
83
+ (customInputOverride) => {
84
+ const answers = questions.map((question, index) => {
85
+ const selectedOptionIndex = selectedOptions[index];
86
+ if (index === currentQuestionIndex && (customInputOverride || isCustomInputMode)) {
87
+ return {
88
+ questionIndex: index,
89
+ customInput: customInputOverride || customInput
90
+ };
91
+ }
92
+ if (selectedOptionIndex === -1) {
93
+ return {
94
+ questionIndex: index,
95
+ customInput
96
+ };
97
+ }
98
+ return {
99
+ questionIndex: index,
100
+ selectedOptions: [selectedOptionIndex]
101
+ };
102
+ });
103
+ onDone();
104
+ resolve(answers);
105
+ },
106
+ [
107
+ questions,
108
+ selectedOptions,
109
+ currentQuestionIndex,
110
+ isCustomInputMode,
111
+ customInput,
112
+ onDone,
113
+ resolve
114
+ ]
115
+ );
116
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingY: 1 }, isCustomInputMode ? /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingX: 2 }, /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Enter your custom response:")), /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, "> "), /* @__PURE__ */ React.createElement(
117
+ TextInput,
118
+ {
119
+ value: customInput,
120
+ onChange: setCustomInput,
121
+ onSubmit: handleConfirm
122
+ }
123
+ )), /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "[Enter to confirm] [Esc to cancel]"))) : (
124
+ /* Normal question view */
125
+ /* @__PURE__ */ React.createElement(
126
+ QuestionView,
127
+ {
128
+ question: currentQuestion,
129
+ questionIndex: currentQuestionIndex,
130
+ totalQuestions: questions.length,
131
+ selectedOptionIndex: selectedOptions[currentQuestionIndex],
132
+ onOptionChange: handleOptionChange
133
+ }
134
+ )
135
+ ));
136
+ }
137
+ export {
138
+ AskUserQuestionDialog
139
+ };
140
+ //# sourceMappingURL=AskUserQuestionDialog.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/AskUserQuestionDialog/AskUserQuestionDialog.tsx"],
4
+ "sourcesContent": ["import { Box, Text, useInput } from 'ink'\nimport * as React from 'react'\nimport { useState, useCallback } from 'react'\nimport { type AskUserQuestionContext, type UserAnswer } from '@minto-types/askUserQuestion'\nimport { QuestionView } from './QuestionView'\nimport { useNotifyAfterTimeout } from '@hooks/useNotifyAfterTimeout'\nimport { PRODUCT_NAME } from '@constants/product'\nimport TextInput from 'ink-text-input'\n\ninterface AskUserQuestionDialogProps {\n context: AskUserQuestionContext\n onDone: () => void\n}\n\nexport function AskUserQuestionDialog({\n context,\n onDone,\n}: AskUserQuestionDialogProps): React.ReactElement {\n const { questions, resolve, reject } = context\n\n // Current question index (for multi-question scenarios)\n const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0)\n\n // Selected option indices for each question\n const [selectedOptions, setSelectedOptions] = useState<number[]>(\n questions.map(() => 0),\n )\n\n // Custom input mode for \"Other\" option\n const [isCustomInputMode, setIsCustomInputMode] = useState(false)\n const [customInput, setCustomInput] = useState('')\n\n // Notification after timeout\n useNotifyAfterTimeout(`${PRODUCT_NAME} needs your input to continue`)\n\n const currentQuestion = questions[currentQuestionIndex]!\n\n // Handle keyboard input\n useInput(\n (input, key) => {\n // Cancel with Escape or Ctrl+C\n if (key.escape || (key.ctrl && input === 'c')) {\n onDone()\n reject()\n return\n }\n\n // Don't handle other keys in custom input mode\n if (isCustomInputMode) {\n return\n }\n\n // Navigate between questions with left/right arrows\n if (key.leftArrow && currentQuestionIndex > 0) {\n setCurrentQuestionIndex(prev => prev - 1)\n return\n }\n\n if (key.rightArrow && currentQuestionIndex < questions.length - 1) {\n setCurrentQuestionIndex(prev => prev + 1)\n return\n }\n\n // Confirm with Enter\n if (key.return) {\n handleConfirm()\n return\n }\n\n // Press 'o' to enter custom input mode\n if (input === 'o' && currentQuestion.options) {\n setIsCustomInputMode(true)\n setCustomInput('')\n return\n }\n },\n { isActive: true },\n )\n\n // Handle option change\n const handleOptionChange = useCallback(\n (optionIndex: number) => {\n const newSelectedOptions = [...selectedOptions]\n newSelectedOptions[currentQuestionIndex] = optionIndex\n setSelectedOptions(newSelectedOptions)\n\n // If \"Other\" is selected (-1), enter custom input mode\n if (optionIndex === -1) {\n setIsCustomInputMode(true)\n setCustomInput('')\n }\n },\n [selectedOptions, currentQuestionIndex],\n )\n\n // Handle confirmation\n const handleConfirm = useCallback(() => {\n // If in custom input mode, save the custom input\n if (isCustomInputMode) {\n if (!customInput.trim()) {\n // Don't allow empty custom input\n return\n }\n\n // Save custom input and exit custom input mode\n setIsCustomInputMode(false)\n\n // If this is the last question, submit all answers\n if (currentQuestionIndex === questions.length - 1) {\n submitAnswers(customInput)\n } else {\n // Move to next question\n setCurrentQuestionIndex(prev => prev + 1)\n }\n return\n }\n\n // If this is the last question, submit all answers\n if (currentQuestionIndex === questions.length - 1) {\n submitAnswers()\n } else {\n // Move to next question\n setCurrentQuestionIndex(prev => prev + 1)\n }\n }, [isCustomInputMode, customInput, currentQuestionIndex, questions.length])\n\n // Submit all answers\n const submitAnswers = useCallback(\n (customInputOverride?: string) => {\n const answers: UserAnswer[] = questions.map((question, index) => {\n const selectedOptionIndex = selectedOptions[index]!\n\n // If it's the current question and we have custom input\n if (\n index === currentQuestionIndex &&\n (customInputOverride || isCustomInputMode)\n ) {\n return {\n questionIndex: index,\n customInput: customInputOverride || customInput,\n }\n }\n\n // If \"Other\" was selected (-1), use custom input\n if (selectedOptionIndex === -1) {\n return {\n questionIndex: index,\n customInput: customInput,\n }\n }\n\n // Regular option selection\n return {\n questionIndex: index,\n selectedOptions: [selectedOptionIndex],\n }\n })\n\n onDone()\n resolve(answers)\n },\n [\n questions,\n selectedOptions,\n currentQuestionIndex,\n isCustomInputMode,\n customInput,\n onDone,\n resolve,\n ],\n )\n\n return (\n <Box flexDirection=\"column\" paddingY={1}>\n {/* Custom input mode */}\n {isCustomInputMode ? (\n <Box flexDirection=\"column\" paddingX={2}>\n <Box marginBottom={1}>\n <Text bold>Enter your custom response:</Text>\n </Box>\n <Box marginBottom={1}>\n <Text color=\"cyan\">&gt; </Text>\n <TextInput\n value={customInput}\n onChange={setCustomInput}\n onSubmit={handleConfirm}\n />\n </Box>\n <Box>\n <Text dimColor>[Enter to confirm] [Esc to cancel]</Text>\n </Box>\n </Box>\n ) : (\n /* Normal question view */\n <QuestionView\n question={currentQuestion}\n questionIndex={currentQuestionIndex}\n totalQuestions={questions.length}\n selectedOptionIndex={selectedOptions[currentQuestionIndex]!}\n onOptionChange={handleOptionChange}\n />\n )}\n </Box>\n )\n}\n"],
5
+ "mappings": "AAAA,SAAS,KAAK,MAAM,gBAAgB;AACpC,YAAY,WAAW;AACvB,SAAS,UAAU,mBAAmB;AAEtC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,OAAO,eAAe;AAOf,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AACF,GAAmD;AACjD,QAAM,EAAE,WAAW,SAAS,OAAO,IAAI;AAGvC,QAAM,CAAC,sBAAsB,uBAAuB,IAAI,SAAS,CAAC;AAGl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AAK,UAAQ,QAAC,oCAAkC,CACnD,CACF;AAAA;AAAA,IAGA;AAAA,MAAC;AAAA;AAAA,QACC,UAAU;AAAA,QACV,eAAe;AAAA,QACf,gBAAgB,UAAU;AAAA,QAC1B,qBAAqB,gBAAgB,oBAAoB;AAAA,QACzD,gBAAgB;AAAA;AAAA,IAClB;AAAA,GAEJ;AAEJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,45 @@
1
+ import { Box, Text } from "ink";
2
+ import * as React from "react";
3
+ import { Select } from "../CustomSelect/select.js";
4
+ import { getTheme } from "../../utils/theme.js";
5
+ function QuestionView({
6
+ question,
7
+ questionIndex,
8
+ totalQuestions,
9
+ selectedOptionIndex,
10
+ onOptionChange
11
+ }) {
12
+ const theme = getTheme();
13
+ const options = React.useMemo(() => {
14
+ if (!question.options || question.options.length === 0) {
15
+ return [];
16
+ }
17
+ const selectOptions = question.options.map((opt, index) => ({
18
+ label: opt.label,
19
+ value: String(index)
20
+ }));
21
+ selectOptions.push({
22
+ label: "Other (custom input)",
23
+ value: "other"
24
+ });
25
+ return selectOptions;
26
+ }, [question.options]);
27
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingX: 2, paddingY: 1 }, /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { color: theme.primary, bold: true }, "\u{1F914} AI needs your input"), totalQuestions > 1 && /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, " ", "(Question ", questionIndex + 1, " of ", totalQuestions, ")")), question.header && /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { color: theme.minto }, "[", question.header, "]")), /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true }, question.question)), question.options && question.options.length > 0 && /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(
28
+ Select,
29
+ {
30
+ options,
31
+ defaultValue: String(selectedOptionIndex),
32
+ onChange: (value) => {
33
+ if (value === "other") {
34
+ onOptionChange(-1);
35
+ } else {
36
+ onOptionChange(Number(value));
37
+ }
38
+ }
39
+ }
40
+ )), question.options && question.options.length > 0 && selectedOptionIndex >= 0 && selectedOptionIndex < question.options.length && /* @__PURE__ */ React.createElement(Box, { marginLeft: 2, marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText, dimColor: true }, question.options[selectedOptionIndex]?.description || "")), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, borderStyle: "single", borderColor: theme.secondaryBorder, paddingX: 1 }, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "[\u2191/\u2193 Navigate] [Enter Confirm]", totalQuestions > 1 && " [\u2190/\u2192 Switch Questions]", " [Esc Cancel]")));
41
+ }
42
+ export {
43
+ QuestionView
44
+ };
45
+ //# sourceMappingURL=QuestionView.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/AskUserQuestionDialog/QuestionView.tsx"],
4
+ "sourcesContent": ["import { Box, Text } from 'ink'\nimport * as React from 'react'\nimport { Select } from '@components/CustomSelect/select'\nimport { type UserQuestion, type QuestionOption } from '@minto-types/askUserQuestion'\nimport { Option } from '@inkjs/ui'\nimport { getTheme } from '@utils/theme'\n\ninterface QuestionViewProps {\n question: UserQuestion\n questionIndex: number\n totalQuestions: number\n selectedOptionIndex: number\n onOptionChange: (optionIndex: number) => void\n}\n\nexport function QuestionView({\n question,\n questionIndex,\n totalQuestions,\n selectedOptionIndex,\n onOptionChange,\n}: QuestionViewProps): React.ReactElement {\n const theme = getTheme()\n\n // Build options for the Select component\n const options: Option[] = React.useMemo(() => {\n if (!question.options || question.options.length === 0) {\n return []\n }\n\n const selectOptions = question.options.map((opt, index) => ({\n label: opt.label,\n value: String(index),\n }))\n\n // Always add \"Other (custom input)\" option\n selectOptions.push({\n label: 'Other (custom input)',\n value: 'other',\n })\n\n return selectOptions\n }, [question.options])\n\n return (\n <Box flexDirection=\"column\" paddingX={2} paddingY={1}>\n {/* Header with question counter */}\n <Box marginBottom={1}>\n <Text color={theme.primary} bold>\n \uD83E\uDD14 AI needs your input\n </Text>\n {totalQuestions > 1 && (\n <Text color={theme.secondaryText}>\n {' '}\n (Question {questionIndex + 1} of {totalQuestions})\n </Text>\n )}\n </Box>\n\n {/* Question header tag */}\n {question.header && (\n <Box marginBottom={1}>\n <Text color={theme.minto}>[{question.header}]</Text>\n </Box>\n )}\n\n {/* Question text */}\n <Box marginBottom={1}>\n <Text bold>{question.question}</Text>\n </Box>\n\n {/* Options list */}\n {question.options && question.options.length > 0 && (\n <Box marginBottom={1}>\n <Select\n options={options}\n defaultValue={String(selectedOptionIndex)}\n onChange={value => {\n if (value === 'other') {\n onOptionChange(-1) // -1 indicates \"Other\"\n } else {\n onOptionChange(Number(value))\n }\n }}\n />\n </Box>\n )}\n\n {/* Show option descriptions */}\n {question.options &&\n question.options.length > 0 &&\n selectedOptionIndex >= 0 &&\n selectedOptionIndex < question.options.length && (\n <Box marginLeft={2} marginBottom={1}>\n <Text color={theme.secondaryText} dimColor>\n {question.options[selectedOptionIndex]?.description || ''}\n </Text>\n </Box>\n )}\n\n {/* Help text */}\n <Box marginTop={1} borderStyle=\"single\" borderColor={theme.secondaryBorder} paddingX={1}>\n <Text color={theme.secondaryText}>\n [\u2191/\u2193 Navigate] [Enter Confirm]\n {totalQuestions > 1 && ' [\u2190/\u2192 Switch Questions]'} [Esc Cancel]\n </Text>\n </Box>\n </Box>\n )\n}\n"],
5
+ "mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,YAAY,WAAW;AACvB,SAAS,cAAc;AAGvB,SAAS,gBAAgB;AAUlB,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA0C;AACxC,QAAM,QAAQ,SAAS;AAGvB,QAAM,UAAoB,MAAM,QAAQ,MAAM;AAC5C,QAAI,CAAC,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ACzD,CACF,GAIJ,oCAAC,OAAI,WAAW,GAAG,aAAY,UAAS,aAAa,MAAM,iBAAiB,UAAU,KACpF,oCAAC,QAAK,OAAO,MAAM,iBAAe,4CAE/B,iBAAiB,KAAK,qCAA0B,eACnD,CACF,CACF;AAEJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AskUserQuestionDialog } from "./AskUserQuestionDialog.js";
2
+ import { QuestionView } from "./QuestionView.js";
3
+ export {
4
+ AskUserQuestionDialog,
5
+ QuestionView
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/AskUserQuestionDialog/index.ts"],
4
+ "sourcesContent": ["export { AskUserQuestionDialog } from './AskUserQuestionDialog'\nexport { QuestionView } from './QuestionView'\n"],
5
+ "mappings": "AAAA,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;",
6
+ "names": []
7
+ }
@@ -28,14 +28,14 @@ function TodoPanel({
28
28
  }
29
29
  const visibleTodos = todos;
30
30
  const currentTask = currentTaskActiveForm || todos.find((t) => t.status === "in_progress")?.activeForm || "Executing tasks";
31
- return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginY: 1 }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Box, { width: 2, flexShrink: 0 }, /* @__PURE__ */ React.createElement(Text, null, SYMBOLS.THINKING_FRAMES[frameIndex])), /* @__PURE__ */ React.createElement(Text, null, currentTask), /* @__PURE__ */ React.createElement(Text, null, "\u2026 "), /* @__PURE__ */ React.createElement(Text, { color: theme.dim }, "(esc to interrupt \xB7 ctrl+t to hide todos \xB7 ", elapsedTime, "s \xB7 \u2193", " ", formatNumber(tokenCount), " tokens)")), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, visibleTodos.map((todo, idx) => /* @__PURE__ */ React.createElement(
31
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginY: 1 }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Box, { width: 2, flexShrink: 0 }, /* @__PURE__ */ React.createElement(Text, null, SYMBOLS.THINKING_FRAMES[frameIndex])), /* @__PURE__ */ React.createElement(Text, null, currentTask), /* @__PURE__ */ React.createElement(Text, null, "\u2026 "), /* @__PURE__ */ React.createElement(Text, { color: theme.dim }, "(esc to interrupt \xB7 ctrl+t to hide todos \xB7 ", elapsedTime, "s \xB7 \u2193", " ", formatNumber(tokenCount), " tokens)")), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, visibleTodos.map((todo, idx) => /* @__PURE__ */ React.createElement(React.Fragment, { key: `todo-${idx}-${todo.content.slice(0, 20)}` }, /* @__PURE__ */ React.createElement(
32
32
  TodoItemClaudeStyle,
33
33
  {
34
34
  todo,
35
35
  theme,
36
36
  isFirst: idx === 0
37
37
  }
38
- ))));
38
+ )))));
39
39
  }
40
40
  function TodoItemClaudeStyle({
41
41
  todo,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/components/TodoPanel.tsx"],
4
- "sourcesContent": ["import React, { useState, useEffect } from 'react'\nimport { Box, Text } from 'ink'\nimport { TodoItem } from './TodoItem'\nimport { getTheme } from '@utils/theme'\nimport { SYMBOLS, getTodoStatusSymbol } from '@constants/symbols'\nimport { formatNumber } from '@utils/format'\nimport type { TodoItem as TodoItemType } from '@utils/todoStorage'\n\ninterface TodoPanelProps {\n /** TODO \u5217\u8868 */\n todos: TodoItemType[]\n /** \u662F\u5426\u663E\u793A\u9762\u677F\uFF08\u7531 Ctrl+T \u63A7\u5236\uFF09 */\n isVisible: boolean\n /** \u5F53\u524D\u4E3B\u4EFB\u52A1\u7684 activeForm\uFF08\u8FDB\u884C\u4E2D\u7684\u4EFB\u52A1\u63CF\u8FF0\uFF09 */\n currentTaskActiveForm?: string\n /** \u8FD0\u884C\u65F6\u95F4\uFF08\u79D2\uFF09 */\n elapsedTime?: number\n /** Token \u8BA1\u6570 */\n tokenCount?: number\n /** \u662F\u5426\u6B63\u5728\u52A0\u8F7D\uFF08\u63A7\u5236\u52A8\u753B\uFF09 */\n isLoading?: boolean\n}\n\n/**\n * TODO \u9762\u677F\u7EC4\u4EF6 - Claude Code CLI \u98CE\u683C\n *\n * \u89C6\u89C9\u683C\u5F0F\uFF1A\n * ```\n * \u273D \u4F18\u5316\u5E76\u884C\u4EFB\u52A1\u8FDB\u5EA6\u5C55\u793A\u2026 (esc to interrupt \u00B7 ctrl+t to hide todos \u00B7 252s \u00B7 \u2193 5.8k tokens)\n * \u23BF \u2612 \u5DF2\u5B8C\u6210\u4EFB\u52A1 (\u7070\u8272 + \u5220\u9664\u7EBF)\n * \u2610 \u5F85\u5B8C\u6210\u4EFB\u52A1\n * ```\n */\nexport function TodoPanel({\n todos,\n isVisible,\n currentTaskActiveForm,\n elapsedTime = 0,\n tokenCount = 0,\n isLoading = true,\n}: TodoPanelProps) {\n const theme = getTheme()\n\n // Claude Code \u98CE\u683C\uFF1A\u52A8\u6001\u52A8\u753B\u7B26\u53F7 (6\u5E27\u5FAA\u73AF)\n const [frameIndex, setFrameIndex] = useState(0)\n useEffect(() => {\n // \u53EA\u5728 isLoading \u4E3A true \u65F6\u8FD0\u884C\u52A8\u753B\n if (!isLoading) {\n return\n }\n\n const timer = setInterval(() => {\n setFrameIndex(i => (i + 1) % SYMBOLS.THINKING_FRAMES.length)\n }, 150)\n return () => clearInterval(timer)\n }, [isLoading])\n\n // Claude Code \u98CE\u683C\uFF1A\u6240\u6709\u4EFB\u52A1\u5B8C\u6210\u540E\u9690\u85CF\u9762\u677F\n const hasIncompleteTasks = todos.some(t => t.status !== 'completed')\n\n // \u5982\u679C\u4E0D\u53EF\u89C1\u3001\u6CA1\u6709 TODO\u3001\u6216\u6240\u6709\u4EFB\u52A1\u90FD\u5DF2\u5B8C\u6210\uFF0C\u4E0D\u6E32\u67D3\n if (!isVisible || todos.length === 0 || !hasIncompleteTasks) {\n return null\n }\n\n // Claude Code \u98CE\u683C\uFF1A\u663E\u793A\u6240\u6709 TODO\uFF08\u5305\u62EC\u5DF2\u5B8C\u6210\u7684\uFF09\n const visibleTodos = todos\n\n // \u83B7\u53D6\u5F53\u524D\u8FDB\u884C\u4E2D\u7684\u4EFB\u52A1\u63CF\u8FF0\n const currentTask =\n currentTaskActiveForm ||\n todos.find(t => t.status === 'in_progress')?.activeForm ||\n 'Executing tasks'\n\n return (\n <Box flexDirection=\"column\" marginY={1}>\n {/* \u7B2C\u4E00\u884C\uFF1A\u52A8\u753B + \u5F53\u524D\u4EFB\u52A1 + \u7EDF\u8BA1\u4FE1\u606F */}\n <Box flexDirection=\"row\">\n {/* \u52A8\u753B\u7B26\u53F7 - \u4F7F\u7528\u56FA\u5B9A\u5BBD\u5EA6\u907F\u514D\u6296\u52A8 */}\n <Box width={2} flexShrink={0}>\n <Text>{SYMBOLS.THINKING_FRAMES[frameIndex]}</Text>\n </Box>\n\n {/* \u5F53\u524D\u4EFB\u52A1\u63CF\u8FF0 */}\n <Text>{currentTask}</Text>\n\n {/* \u7701\u7565\u7B26\u53F7 */}\n <Text>\u2026 </Text>\n\n {/* \u7EDF\u8BA1\u4FE1\u606F\u548C\u63D0\u793A */}\n <Text color={theme.dim}>\n (esc to interrupt \u00B7 ctrl+t to hide todos \u00B7 {elapsedTime}s \u00B7 \u2193{' '}\n {formatNumber(tokenCount)} tokens)\n </Text>\n </Box>\n\n {/* TODO \u5217\u8868 */}\n <Box flexDirection=\"column\">\n {visibleTodos.map((todo, idx) => (\n <TodoItemClaudeStyle\n todo={todo}\n theme={theme}\n isFirst={idx === 0}\n />\n ))}\n </Box>\n </Box>\n )\n}\n\n/**\n * Claude Code \u98CE\u683C\u7684 TODO \u9879\n *\n * \u683C\u5F0F\uFF1A\n * ```\n * \u23BF \u2612 \u5DF2\u5B8C\u6210\u4EFB\u52A1 (\u7070\u8272 + \u5220\u9664\u7EBF)\n * \u2610 \u5F85\u5B8C\u6210\u4EFB\u52A1\n * ```\n */\ninterface TodoItemClaudeStyleProps {\n todo: TodoItemType\n theme: ReturnType<typeof getTheme>\n isFirst: boolean\n}\n\nfunction TodoItemClaudeStyle({\n todo,\n theme,\n isFirst,\n}: TodoItemClaudeStyleProps) {\n const isCompleted = todo.status === 'completed'\n\n // \u7B26\u53F7\uFF1A\u2610 \u672A\u5B8C\u6210 / \u2612 \u5DF2\u5B8C\u6210\n const symbol = getTodoStatusSymbol(todo.status)\n\n // \u989C\u8272\uFF1A\u5DF2\u5B8C\u6210\u7528\u7070\u8272\uFF0C\u5176\u4ED6\u6B63\u5E38\n const color = isCompleted ? theme.dim : undefined\n\n // \u7F29\u8FDB\uFF1A\u7B2C\u4E00\u4E2A\u7528 \" \u23BF \"\uFF0C\u5176\u4ED6\u7528 \" \" (5\u4E2A\u7A7A\u683C\u5BF9\u9F50)\n const indent = isFirst ? ' \u23BF ' : ' '\n\n return (\n <Box flexDirection=\"row\">\n {/* \u7F29\u8FDB */}\n <Text color={theme.dim}>{indent}</Text>\n\n {/* \u72B6\u6001\u7B26\u53F7 */}\n <Text color={color}>{symbol} </Text>\n\n {/* \u4EFB\u52A1\u63CF\u8FF0 */}\n <Text color={color} strikethrough={isCompleted}>\n {todo.content}\n </Text>\n </Box>\n )\n}\n"],
5
- "mappings": "AAAA,OAAO,SAAS,UAAU,iBAAiB;AAC3C,SAAS,KAAK,YAAY;AAE1B,SAAS,gBAAgB;AACzB,SAAS,SAAS,2BAA2B;AAC7C,SAAS,oBAAoB;AA4BtB,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb,YAAY;AACd,GAAmB;AACjB,QAAM,QAAQ,SAAS;AAGvB,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,CAAC;AAC9C,YAAU,MAAM;AAEd,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEA,UAAM,QAAQ,YAAY,MAAM;AAC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4
+ "sourcesContent": ["import React, { useState, useEffect } from 'react'\nimport { Box, Text } from 'ink'\nimport { TodoItem } from './TodoItem'\nimport { getTheme } from '@utils/theme'\nimport { SYMBOLS, getTodoStatusSymbol } from '@constants/symbols'\nimport { formatNumber } from '@utils/format'\nimport type { TodoItem as TodoItemType } from '@utils/todoStorage'\n\ninterface TodoPanelProps {\n /** TODO \u5217\u8868 */\n todos: TodoItemType[]\n /** \u662F\u5426\u663E\u793A\u9762\u677F\uFF08\u7531 Ctrl+T \u63A7\u5236\uFF09 */\n isVisible: boolean\n /** \u5F53\u524D\u4E3B\u4EFB\u52A1\u7684 activeForm\uFF08\u8FDB\u884C\u4E2D\u7684\u4EFB\u52A1\u63CF\u8FF0\uFF09 */\n currentTaskActiveForm?: string\n /** \u8FD0\u884C\u65F6\u95F4\uFF08\u79D2\uFF09 */\n elapsedTime?: number\n /** Token \u8BA1\u6570 */\n tokenCount?: number\n /** \u662F\u5426\u6B63\u5728\u52A0\u8F7D\uFF08\u63A7\u5236\u52A8\u753B\uFF09 */\n isLoading?: boolean\n}\n\n/**\n * TODO \u9762\u677F\u7EC4\u4EF6 - Claude Code CLI \u98CE\u683C\n *\n * \u89C6\u89C9\u683C\u5F0F\uFF1A\n * ```\n * \u273D \u4F18\u5316\u5E76\u884C\u4EFB\u52A1\u8FDB\u5EA6\u5C55\u793A\u2026 (esc to interrupt \u00B7 ctrl+t to hide todos \u00B7 252s \u00B7 \u2193 5.8k tokens)\n * \u23BF \u2612 \u5DF2\u5B8C\u6210\u4EFB\u52A1 (\u7070\u8272 + \u5220\u9664\u7EBF)\n * \u2610 \u5F85\u5B8C\u6210\u4EFB\u52A1\n * ```\n */\nexport function TodoPanel({\n todos,\n isVisible,\n currentTaskActiveForm,\n elapsedTime = 0,\n tokenCount = 0,\n isLoading = true,\n}: TodoPanelProps) {\n const theme = getTheme()\n\n // Claude Code \u98CE\u683C\uFF1A\u52A8\u6001\u52A8\u753B\u7B26\u53F7 (6\u5E27\u5FAA\u73AF)\n const [frameIndex, setFrameIndex] = useState(0)\n useEffect(() => {\n // \u53EA\u5728 isLoading \u4E3A true \u65F6\u8FD0\u884C\u52A8\u753B\n if (!isLoading) {\n return\n }\n\n const timer = setInterval(() => {\n setFrameIndex(i => (i + 1) % SYMBOLS.THINKING_FRAMES.length)\n }, 150)\n return () => clearInterval(timer)\n }, [isLoading])\n\n // Claude Code \u98CE\u683C\uFF1A\u6240\u6709\u4EFB\u52A1\u5B8C\u6210\u540E\u9690\u85CF\u9762\u677F\n const hasIncompleteTasks = todos.some(t => t.status !== 'completed')\n\n // \u5982\u679C\u4E0D\u53EF\u89C1\u3001\u6CA1\u6709 TODO\u3001\u6216\u6240\u6709\u4EFB\u52A1\u90FD\u5DF2\u5B8C\u6210\uFF0C\u4E0D\u6E32\u67D3\n if (!isVisible || todos.length === 0 || !hasIncompleteTasks) {\n return null\n }\n\n // Claude Code \u98CE\u683C\uFF1A\u663E\u793A\u6240\u6709 TODO\uFF08\u5305\u62EC\u5DF2\u5B8C\u6210\u7684\uFF09\n const visibleTodos = todos\n\n // \u83B7\u53D6\u5F53\u524D\u8FDB\u884C\u4E2D\u7684\u4EFB\u52A1\u63CF\u8FF0\n const currentTask =\n currentTaskActiveForm ||\n todos.find(t => t.status === 'in_progress')?.activeForm ||\n 'Executing tasks'\n\n return (\n <Box flexDirection=\"column\" marginY={1}>\n {/* \u7B2C\u4E00\u884C\uFF1A\u52A8\u753B + \u5F53\u524D\u4EFB\u52A1 + \u7EDF\u8BA1\u4FE1\u606F */}\n <Box flexDirection=\"row\">\n {/* \u52A8\u753B\u7B26\u53F7 - \u4F7F\u7528\u56FA\u5B9A\u5BBD\u5EA6\u907F\u514D\u6296\u52A8 */}\n <Box width={2} flexShrink={0}>\n <Text>{SYMBOLS.THINKING_FRAMES[frameIndex]}</Text>\n </Box>\n\n {/* \u5F53\u524D\u4EFB\u52A1\u63CF\u8FF0 */}\n <Text>{currentTask}</Text>\n\n {/* \u7701\u7565\u7B26\u53F7 */}\n <Text>\u2026 </Text>\n\n {/* \u7EDF\u8BA1\u4FE1\u606F\u548C\u63D0\u793A */}\n <Text color={theme.dim}>\n (esc to interrupt \u00B7 ctrl+t to hide todos \u00B7 {elapsedTime}s \u00B7 \u2193{' '}\n {formatNumber(tokenCount)} tokens)\n </Text>\n </Box>\n\n {/* TODO \u5217\u8868 */}\n <Box flexDirection=\"column\">\n {visibleTodos.map((todo, idx) => (\n <React.Fragment key={`todo-${idx}-${todo.content.slice(0, 20)}`}>\n <TodoItemClaudeStyle\n todo={todo}\n theme={theme}\n isFirst={idx === 0}\n />\n </React.Fragment>\n ))}\n </Box>\n </Box>\n )\n}\n\n/**\n * Claude Code \u98CE\u683C\u7684 TODO \u9879\n *\n * \u683C\u5F0F\uFF1A\n * ```\n * \u23BF \u2612 \u5DF2\u5B8C\u6210\u4EFB\u52A1 (\u7070\u8272 + \u5220\u9664\u7EBF)\n * \u2610 \u5F85\u5B8C\u6210\u4EFB\u52A1\n * ```\n */\ninterface TodoItemClaudeStyleProps {\n todo: TodoItemType\n theme: ReturnType<typeof getTheme>\n isFirst: boolean\n}\n\nfunction TodoItemClaudeStyle({\n todo,\n theme,\n isFirst,\n}: TodoItemClaudeStyleProps) {\n const isCompleted = todo.status === 'completed'\n\n // \u7B26\u53F7\uFF1A\u2610 \u672A\u5B8C\u6210 / \u2612 \u5DF2\u5B8C\u6210\n const symbol = getTodoStatusSymbol(todo.status)\n\n // \u989C\u8272\uFF1A\u5DF2\u5B8C\u6210\u7528\u7070\u8272\uFF0C\u5176\u4ED6\u6B63\u5E38\n const color = isCompleted ? theme.dim : undefined\n\n // \u7F29\u8FDB\uFF1A\u7B2C\u4E00\u4E2A\u7528 \" \u23BF \"\uFF0C\u5176\u4ED6\u7528 \" \" (5\u4E2A\u7A7A\u683C\u5BF9\u9F50)\n const indent = isFirst ? ' \u23BF ' : ' '\n\n return (\n <Box flexDirection=\"row\">\n {/* \u7F29\u8FDB */}\n <Text color={theme.dim}>{indent}</Text>\n\n {/* \u72B6\u6001\u7B26\u53F7 */}\n <Text color={color}>{symbol} </Text>\n\n {/* \u4EFB\u52A1\u63CF\u8FF0 */}\n <Text color={color} strikethrough={isCompleted}>\n {todo.content}\n </Text>\n </Box>\n )\n}\n"],
5
+ "mappings": "AAAA,OAAO,SAAS,UAAU,iBAAiB;AAC3C,SAAS,KAAK,YAAY;AAE1B,SAAS,gBAAgB;AACzB,SAAS,SAAS,2BAA2B;AAC7C,SAAS,oBAAoB;AA4BtB,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb,YAAY;AACd,GAAmB;AACjB,QAAM,QAAQ,SAAS;AAGvB,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,CAAC;AAC9C,YAAU,MAAM;AAEd,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEA,UAAM,QAAQ,YAAY,MAAM;AAC9B,oBAAc,QAAM,IAAI,KAAK,QAAQ,gBAAgB,MAAM;AAAA,IAC7D,GAAG,GAAG;AACN,WAAO,MAAM,cAAc,KAAK;AAAA,EAClC,GAAG,CAAC,SAAS,CAAC;AAGd,QAAM,qBAAqB,MAAM,KAAK,OAAK,EAAE,WAAW,WAAW;AAGnE,MAAI,CAAC,aAAa,MAAM,WAAW,KAAK,CAAC,oBAAoB;AAC3D,WAAO;AAAA,EACT;AAGA,QAAM,eAAe;AAGrB,QAAM,cACJ,yBACA,MAAM,KAAK,OAAK,EAAE,WAAW,aAAa,GAAG,cAC7C;AAEF,SACE,oCAAC,OAAI,eAAc,UAAS,SAAS,KAEnC,oCAAC,OAAI,eAAc,SAEjB,oCAAC,OAAI,OAAO,GAAG,YAAY,KACzB,oCAAC,YAAM,QAAQ,gBAAgB,UAAU,CAAE,CAC7C,GAGA,oCAAC,YAAM,WAAY,GAGnB,oCAAC,YAAK,SAAE,GAGR,oCAAC,QAAK,OAAO,MAAM,OAAK,qDACsB,aAAY,iBAAM,KAC7D,aAAa,UAAU,GAAE,UAC5B,CACF,GAGA,oCAAC,OAAI,eAAc,YAChB,aAAa,IAAI,CAAC,MAAM,QACvB,oCAAC,MAAM,UAAN,EAAe,KAAK,QAAQ,GAAG,IAAI,KAAK,QAAQ,MAAM,GAAG,EAAE,CAAC,MAC3D;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,SAAS,QAAQ;AAAA;AAAA,EACnB,CACF,CACD,CACH,CACF;AAEJ;AAiBA,SAAS,oBAAoB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAA6B;AAC3B,QAAM,cAAc,KAAK,WAAW;AAGpC,QAAM,SAAS,oBAAoB,KAAK,MAAM;AAG9C,QAAM,QAAQ,cAAc,MAAM,MAAM;AAGxC,QAAM,SAAS,UAAU,eAAU;AAEnC,SACE,oCAAC,OAAI,eAAc,SAEjB,oCAAC,QAAK,OAAO,MAAM,OAAM,MAAO,GAGhC,oCAAC,QAAK,SAAe,QAAO,GAAC,GAG7B,oCAAC,QAAK,OAAc,eAAe,eAChC,KAAK,OACR,CACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,24 @@
1
+ import { useCallback } from "react";
2
+ function useAskUser(setAskUserQuestionContext) {
3
+ return useCallback(
4
+ (questions) => {
5
+ return new Promise((resolve, reject) => {
6
+ setAskUserQuestionContext({
7
+ questions,
8
+ resolve: (answers) => {
9
+ resolve(answers);
10
+ },
11
+ reject: () => {
12
+ reject(new Error("User cancelled the question dialog"));
13
+ }
14
+ });
15
+ });
16
+ },
17
+ [setAskUserQuestionContext]
18
+ );
19
+ }
20
+ var useAskUser_default = useAskUser;
21
+ export {
22
+ useAskUser_default as default
23
+ };
24
+ //# sourceMappingURL=useAskUser.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/useAskUser.ts"],
4
+ "sourcesContent": ["import * as React from 'react'\nimport { useCallback } from 'react'\nimport type {\n UserQuestion,\n UserAnswer,\n AskUserQuestionContext,\n} from '@minto-types/askUserQuestion'\n\ntype SetState<T> = React.Dispatch<React.SetStateAction<T>>\n\n/**\n * Function type for asking the user questions\n */\nexport type AskUserFn = (questions: UserQuestion[]) => Promise<UserAnswer[]>\n\n/**\n * Hook to provide the askUser function for triggering user question dialogs\n *\n * Similar to useCanUseTool, this creates a Promise-based interaction\n * where the dialog is shown and the promise resolves when the user responds.\n *\n * @param setAskUserQuestionContext - State setter to trigger the dialog\n * @returns Function to ask user questions\n */\nfunction useAskUser(\n setAskUserQuestionContext: SetState<AskUserQuestionContext | null>,\n): AskUserFn {\n return useCallback<AskUserFn>(\n (questions: UserQuestion[]) => {\n return new Promise<UserAnswer[]>((resolve, reject) => {\n // Set the context to trigger the dialog render\n setAskUserQuestionContext({\n questions,\n resolve: (answers: UserAnswer[]) => {\n // User provided answers\n resolve(answers)\n },\n reject: () => {\n // User cancelled\n reject(new Error('User cancelled the question dialog'))\n },\n })\n })\n },\n [setAskUserQuestionContext],\n )\n}\n\nexport default useAskUser\n"],
5
+ "mappings": "AACA,SAAS,mBAAmB;AAuB5B,SAAS,WACP,2BACW;AACX,SAAO;AAAA,IACL,CAAC,cAA8B;AAC7B,aAAO,IAAI,QAAsB,CAAC,SAAS,WAAW;AAEpD,kCAA0B;AAAA,UACxB;AAAA,UACA,SAAS,CAAC,YAA0B;AAElC,oBAAQ,OAAO;AAAA,UACjB;AAAA,UACA,QAAQ,MAAM;AAEZ,mBAAO,IAAI,MAAM,oCAAoC,CAAC;AAAA,UACxD;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,IACA,CAAC,yBAAyB;AAAA,EAC5B;AACF;AAEA,IAAO,qBAAQ;",
6
+ "names": []
7
+ }
package/dist/query.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/query.ts"],
4
- "sourcesContent": ["import {\n Message as APIAssistantMessage,\n MessageParam,\n ToolUseBlock,\n} from '@anthropic-ai/sdk/resources/index.mjs'\nimport type { UUID } from './types/common'\nimport type { Tool, ToolUseContext } from './Tool'\nimport {\n messagePairValidForBinaryFeedback,\n shouldUseBinaryFeedback,\n} from '@components/binary-feedback/utils'\nimport { CanUseToolFn } from './hooks/useCanUseTool'\nimport {\n formatSystemPromptWithContext,\n queryLLM,\n queryModel,\n} from '@services/claude'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { all } from '@utils/generators'\nimport { logError } from '@utils/log'\nimport {\n debug,\n markPhase,\n getCurrentRequest,\n logUserFriendly,\n} from './utils/debugLogger'\nimport { getModelManager } from '@utils/model'\nimport {\n createAssistantMessage,\n createProgressMessage,\n createToolResultStopMessage,\n createUserMessage,\n FullToolUseResult,\n INTERRUPT_MESSAGE,\n INTERRUPT_MESSAGE_FOR_TOOL_USE,\n NormalizedMessage,\n normalizeMessagesForAPI,\n} from '@utils/messages'\nimport { createToolExecutionController } from '@utils/toolExecutionController'\nimport { BashTool } from '@tools/BashTool/BashTool'\nimport { getCwd } from './utils/state'\nimport { checkAutoCompact } from './utils/autoCompactCore'\nimport { getHookManager } from '@utils/hookManager'\n\n// Extended ToolUseContext for query functions\ninterface ExtendedToolUseContext extends ToolUseContext {\n abortController: AbortController\n options: {\n commands: any[]\n forkNumber: number\n messageLogName: string\n tools: Tool[]\n verbose: boolean\n safeMode: boolean\n maxThinkingTokens: number\n isKodingRequest?: boolean\n model?: string | import('./utils/config').ModelPointerType\n }\n readFileTimestamps: { [filename: string]: number }\n setToolJSX: (jsx: any) => void\n requestId?: string\n}\n\nexport type Response = { costUSD: number; response: string }\nexport type UserMessage = {\n message: MessageParam\n type: 'user'\n uuid: UUID\n toolUseResult?: FullToolUseResult\n options?: {\n isKodingRequest?: boolean\n kodingContext?: string\n isCustomCommand?: boolean\n commandName?: string\n commandArgs?: string\n }\n}\n\nexport type AssistantMessage = {\n costUSD: number\n durationMs: number\n message: APIAssistantMessage\n type: 'assistant'\n uuid: UUID\n isApiErrorMessage?: boolean\n responseId?: string // For GPT-5 Responses API state management\n}\n\nexport type BinaryFeedbackResult =\n | { message: AssistantMessage | null; shouldSkipPermissionCheck: false }\n | { message: AssistantMessage; shouldSkipPermissionCheck: true }\n\nexport type ProgressMessage = {\n content: AssistantMessage\n normalizedMessages: NormalizedMessage[]\n siblingToolUseIDs: Set<string>\n tools: Tool[]\n toolUseID: string\n type: 'progress'\n uuid: UUID\n}\n\n// Each array item is either a single message or a message-and-response pair\nexport type Message = UserMessage | AssistantMessage | ProgressMessage\n\nconst MAX_TOOL_USE_CONCURRENCY = 10\n\n// Returns a message if we got one, or `null` if the user cancelled\nasync function queryWithBinaryFeedback(\n toolUseContext: ExtendedToolUseContext,\n getAssistantResponse: () => Promise<AssistantMessage>,\n getBinaryFeedbackResponse?: (\n m1: AssistantMessage,\n m2: AssistantMessage,\n ) => Promise<BinaryFeedbackResult>,\n): Promise<BinaryFeedbackResult> {\n if (\n process.env.USER_TYPE !== 'ant' ||\n !getBinaryFeedbackResponse ||\n !(await shouldUseBinaryFeedback())\n ) {\n const assistantMessage = await getAssistantResponse()\n if (toolUseContext.abortController.signal.aborted) {\n return { message: null, shouldSkipPermissionCheck: false }\n }\n return { message: assistantMessage, shouldSkipPermissionCheck: false }\n }\n const [m1, m2] = await Promise.all([\n getAssistantResponse(),\n getAssistantResponse(),\n ])\n if (toolUseContext.abortController.signal.aborted) {\n return { message: null, shouldSkipPermissionCheck: false }\n }\n if (m2.isApiErrorMessage) {\n // If m2 is an error, we might as well return m1, even if it's also an error --\n // the UI will display it as an error as it would in the non-feedback path.\n return { message: m1, shouldSkipPermissionCheck: false }\n }\n if (m1.isApiErrorMessage) {\n return { message: m2, shouldSkipPermissionCheck: false }\n }\n if (!messagePairValidForBinaryFeedback(m1, m2)) {\n return { message: m1, shouldSkipPermissionCheck: false }\n }\n return await getBinaryFeedbackResponse(m1, m2)\n}\n\n/**\n * The rules of thinking are lengthy and fortuitous. They require plenty of thinking\n * of most long duration and deep meditation for a wizard to wrap one's noggin around.\n *\n * The rules follow:\n * 1. A message that contains a thinking or redacted_thinking block must be part of a query whose max_thinking_length > 0\n * 2. A thinking block may not be the last message in a block\n * 3. Thinking blocks must be preserved for the duration of an assistant trajectory (a single turn, or if that turn includes a tool_use block then also its subsequent tool_result and the following assistant message)\n *\n * Heed these rules well, young wizard. For they are the rules of thinking, and\n * the rules of thinking are the rules of the universe. If ye does not heed these\n * rules, ye will be punished with an entire day of debugging and hair pulling.\n */\nexport async function* query(\n messages: Message[],\n systemPrompt: string[],\n context: { [k: string]: string },\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n getBinaryFeedbackResponse?: (\n m1: AssistantMessage,\n m2: AssistantMessage,\n ) => Promise<BinaryFeedbackResult>,\n): AsyncGenerator<Message, void> {\n const currentRequest = getCurrentRequest()\n\n markPhase('QUERY_INIT')\n\n // Auto-compact check\n const { messages: processedMessages, wasCompacted } = await checkAutoCompact(\n messages,\n toolUseContext,\n )\n if (wasCompacted) {\n messages = processedMessages\n }\n\n markPhase('SYSTEM_PROMPT_BUILD')\n \n const { systemPrompt: fullSystemPrompt, reminders } =\n formatSystemPromptWithContext(systemPrompt, context, toolUseContext.agentId)\n\n // Emit session startup event\n emitReminderEvent('session:startup', {\n agentId: toolUseContext.agentId,\n messages: messages.length,\n timestamp: Date.now(),\n })\n\n // Inject reminders into the latest user message\n if (reminders && messages.length > 0) {\n // Find the last user message\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i]\n if (msg?.type === 'user') {\n const lastUserMessage = msg as UserMessage\n messages[i] = {\n ...lastUserMessage,\n message: {\n ...lastUserMessage.message,\n content:\n typeof lastUserMessage.message.content === 'string'\n ? reminders + lastUserMessage.message.content\n : [\n ...(Array.isArray(lastUserMessage.message.content)\n ? lastUserMessage.message.content\n : []),\n { type: 'text', text: reminders },\n ],\n },\n }\n break\n }\n }\n }\n\n markPhase('LLM_PREPARATION')\n\n function getAssistantResponse() {\n return queryLLM(\n normalizeMessagesForAPI(messages),\n fullSystemPrompt,\n toolUseContext.options.maxThinkingTokens,\n toolUseContext.options.tools,\n toolUseContext.abortController.signal,\n {\n safeMode: toolUseContext.options.safeMode ?? false,\n model: toolUseContext.options.model || 'main',\n prependCLISysprompt: true,\n toolUseContext: toolUseContext,\n },\n )\n }\n\n const result = await queryWithBinaryFeedback(\n toolUseContext,\n getAssistantResponse,\n getBinaryFeedbackResponse,\n )\n\n // If request was cancelled, return immediately with interrupt message \n if (toolUseContext.abortController.signal.aborted) {\n yield createAssistantMessage(INTERRUPT_MESSAGE)\n return\n }\n\n if (result.message === null) {\n yield createAssistantMessage(INTERRUPT_MESSAGE)\n return\n }\n\n const assistantMessage = result.message\n const shouldSkipPermissionCheck = result.shouldSkipPermissionCheck\n\n yield assistantMessage\n\n // @see https://docs.anthropic.com/en/docs/build-with-claude/tool-use\n // Note: stop_reason === 'tool_use' is unreliable -- it's not always set correctly\n const toolUseMessages = assistantMessage.message.content.filter(\n _ => _.type === 'tool_use',\n )\n\n // If there's no more tool use, we're done\n if (!toolUseMessages.length) {\n return\n }\n\n const toolResults: UserMessage[] = []\n \n // Simple concurrency check like original system\n const canRunConcurrently = toolUseMessages.every(msg =>\n toolUseContext.options.tools.find(t => t.name === msg.name)?.isReadOnly(),\n )\n\n if (canRunConcurrently) {\n for await (const message of runToolsConcurrently(\n toolUseMessages,\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n )) {\n yield message\n // progress messages are not sent to the server, so don't need to be accumulated for the next turn\n if (message.type === 'user') {\n toolResults.push(message)\n }\n }\n } else {\n for await (const message of runToolsSerially(\n toolUseMessages,\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n )) {\n yield message\n // progress messages are not sent to the server, so don't need to be accumulated for the next turn\n if (message.type === 'user') {\n toolResults.push(message)\n }\n }\n }\n\n if (toolUseContext.abortController.signal.aborted) {\n yield createAssistantMessage(INTERRUPT_MESSAGE_FOR_TOOL_USE)\n return\n }\n\n // Sort toolResults to match the order of toolUseMessages\n const orderedToolResults = toolResults.sort((a, b) => {\n const aIndex = toolUseMessages.findIndex(\n tu => tu.id === (a.message.content[0] as ToolUseBlock).id,\n )\n const bIndex = toolUseMessages.findIndex(\n tu => tu.id === (b.message.content[0] as ToolUseBlock).id,\n )\n return aIndex - bIndex\n })\n\n // Recursive query\n\n try {\n yield* await query(\n [...messages, assistantMessage, ...orderedToolResults],\n systemPrompt,\n context,\n canUseTool,\n toolUseContext,\n getBinaryFeedbackResponse,\n )\n } catch (error) {\n // Re-throw the error to maintain the original behavior\n throw error\n }\n}\n\nasync function* runToolsConcurrently(\n toolUseMessages: ToolUseBlock[],\n assistantMessage: AssistantMessage,\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<Message, void> {\n yield* all(\n toolUseMessages.map(toolUse =>\n runToolUse(\n toolUse,\n new Set(toolUseMessages.map(_ => _.id)),\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n ),\n ),\n MAX_TOOL_USE_CONCURRENCY,\n )\n}\n\nasync function* runToolsSerially(\n toolUseMessages: ToolUseBlock[],\n assistantMessage: AssistantMessage,\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<Message, void> {\n for (const toolUse of toolUseMessages) {\n yield* runToolUse(\n toolUse,\n new Set(toolUseMessages.map(_ => _.id)),\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n )\n }\n}\n\nexport async function* runToolUse(\n toolUse: ToolUseBlock,\n siblingToolUseIDs: Set<string>,\n assistantMessage: AssistantMessage,\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<Message, void> {\n const currentRequest = getCurrentRequest()\n\n // \uD83D\uDD0D Debug: \u5DE5\u5177\u8C03\u7528\u5F00\u59CB\n debug.flow('TOOL_USE_START', {\n toolName: toolUse.name,\n toolUseID: toolUse.id,\n inputSize: JSON.stringify(toolUse.input).length,\n siblingToolCount: siblingToolUseIDs.size,\n shouldSkipPermissionCheck: !!shouldSkipPermissionCheck,\n requestId: currentRequest?.id,\n })\n\n logUserFriendly(\n 'TOOL_EXECUTION',\n {\n toolName: toolUse.name,\n action: 'Starting',\n target: toolUse.input ? Object.keys(toolUse.input).join(', ') : '',\n },\n currentRequest?.id,\n )\n\n\n \n\n const toolName = toolUse.name\n const tool = toolUseContext.options.tools.find(t => t.name === toolName)\n\n // Check if the tool exists\n if (!tool) {\n debug.error('TOOL_NOT_FOUND', {\n requestedTool: toolName,\n availableTools: toolUseContext.options.tools.map(t => t.name),\n toolUseID: toolUse.id,\n requestId: currentRequest?.id,\n })\n\n \n\n yield createUserMessage([\n {\n type: 'tool_result',\n content: `Error: No such tool available: ${toolName}`,\n is_error: true,\n tool_use_id: toolUse.id,\n },\n ])\n return\n }\n\n const toolInput = toolUse.input as { [key: string]: string }\n\n debug.flow('TOOL_VALIDATION_START', {\n toolName: tool.name,\n toolUseID: toolUse.id,\n inputKeys: Object.keys(toolInput),\n requestId: currentRequest?.id,\n })\n\n try {\n // \uD83D\uDD27 Check for cancellation before starting tool execution\n if (toolUseContext.abortController.signal.aborted) {\n debug.flow('TOOL_USE_CANCELLED_BEFORE_START', {\n toolName: tool.name,\n toolUseID: toolUse.id,\n abortReason: 'AbortController signal',\n requestId: currentRequest?.id,\n })\n\n \n\n const message = createUserMessage([\n createToolResultStopMessage(toolUse.id),\n ])\n yield message\n return\n }\n\n // Track if any progress messages were yielded\n let hasProgressMessages = false\n \n for await (const message of checkPermissionsAndCallTool(\n tool,\n toolUse.id,\n siblingToolUseIDs,\n toolInput,\n toolUseContext,\n canUseTool,\n assistantMessage,\n shouldSkipPermissionCheck,\n )) {\n // \uD83D\uDD27 Check for cancellation during tool execution\n if (toolUseContext.abortController.signal.aborted) {\n debug.flow('TOOL_USE_CANCELLED_DURING_EXECUTION', {\n toolName: tool.name,\n toolUseID: toolUse.id,\n hasProgressMessages,\n abortReason: 'AbortController signal during execution',\n requestId: currentRequest?.id,\n })\n\n // If we yielded progress messages but got cancelled, yield a cancellation result\n if (hasProgressMessages && message.type === 'progress') {\n yield message // yield the last progress message first\n }\n \n // Always yield a tool result message for cancellation to clear UI state\n const cancelMessage = createUserMessage([\n createToolResultStopMessage(toolUse.id),\n ])\n yield cancelMessage\n return\n }\n\n if (message.type === 'progress') {\n hasProgressMessages = true\n }\n \n yield message\n }\n } catch (e) {\n logError(e)\n \n // \uD83D\uDD27 Even on error, ensure we yield a tool result to clear UI state\n const errorMessage = createUserMessage([\n {\n type: 'tool_result',\n content: `Tool execution failed: ${e instanceof Error ? e.message : String(e)}`,\n is_error: true,\n tool_use_id: toolUse.id,\n },\n ])\n yield errorMessage\n }\n}\n\n// TODO: Generalize this to all tools\nexport function normalizeToolInput(\n tool: Tool,\n input: { [key: string]: boolean | string | number },\n): { [key: string]: boolean | string | number } {\n switch (tool) {\n case BashTool: {\n const { command, timeout } = BashTool.inputSchema.parse(input) // already validated upstream, won't throw\n return {\n command: command.replace(`cd ${getCwd()} && `, ''),\n ...(timeout ? { timeout } : {}),\n }\n }\n default:\n return input\n }\n}\n\nasync function* checkPermissionsAndCallTool(\n tool: Tool,\n toolUseID: string,\n siblingToolUseIDs: Set<string>,\n input: { [key: string]: boolean | string | number },\n context: ToolUseContext,\n canUseTool: CanUseToolFn,\n assistantMessage: AssistantMessage,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<UserMessage | ProgressMessage, void> {\n // Validate input types with zod\n // (surprisingly, the model is not great at generating valid input)\n const isValidInput = tool.inputSchema.safeParse(input)\n if (!isValidInput.success) {\n // Create a more helpful error message for common cases\n let errorMessage = `InputValidationError: ${isValidInput.error.message}`\n \n // Special handling for the \"View\" tool (FileReadTool) being called with empty parameters\n if (tool.name === 'View' && Object.keys(input).length === 0) {\n errorMessage = `Error: The View tool requires a 'file_path' parameter to specify which file to read. Please provide the absolute path to the file you want to view. For example: {\"file_path\": \"/path/to/file.txt\"}`\n }\n \n \n yield createUserMessage([\n {\n type: 'tool_result',\n content: errorMessage,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n\n const normalizedInput = normalizeToolInput(tool, input)\n\n // Validate input values. Each tool has its own validation logic\n const isValidCall = await tool.validateInput?.(\n normalizedInput as never,\n context,\n )\n if (isValidCall?.result === false) {\n yield createUserMessage([\n {\n type: 'tool_result',\n content: isValidCall!.message,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n\n // Check whether we have permission to use the tool,\n // and ask the user for permission if we don't\n const permissionResult = shouldSkipPermissionCheck\n ? ({ result: true } as const)\n : await canUseTool(tool, normalizedInput, context, assistantMessage)\n if (permissionResult.result === false) {\n yield createUserMessage([\n {\n type: 'tool_result',\n content: permissionResult.message,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n\n // PreToolUse hooks\n const hookManager = getHookManager()\n if (hookManager) {\n try {\n const decision = await hookManager.executePreToolUse(\n tool.name,\n normalizedInput as Record<string, unknown>,\n )\n\n if (!decision.shouldContinue) {\n if (decision.shouldAskUser) {\n // Ask user for approval via permission system\n const approved = await canUseTool(tool, normalizedInput, context, assistantMessage)\n if (approved.result === false) {\n yield createUserMessage([\n {\n type: 'tool_result',\n content: decision.reason || 'Hook requested approval but user denied',\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n } else {\n // Hook blocked the tool\n yield createUserMessage([\n {\n type: 'tool_result',\n content: decision.reason || 'Tool execution blocked by hook',\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n }\n } catch (error) {\n debug.error('PreToolUse hook failed', { error })\n // Continue on error (fail-safe)\n }\n }\n\n // Call the tool\n let toolOutput: FullToolUseResult | null = null\n try {\n const generator = tool.call(normalizedInput as never, context)\n for await (const result of generator) {\n switch (result.type) {\n case 'result':\n toolOutput = {\n data: result.data,\n resultForAssistant: result.resultForAssistant || String(result.data),\n }\n\n yield createUserMessage(\n [\n {\n type: 'tool_result',\n content: result.resultForAssistant || String(result.data),\n tool_use_id: toolUseID,\n },\n ],\n toolOutput,\n )\n\n // PostToolUse hooks (fire-and-forget)\n if (hookManager && toolOutput) {\n hookManager.executePostToolUse(\n tool.name,\n normalizedInput as Record<string, unknown>,\n toolOutput as any,\n ).catch(err => {\n debug.error('PostToolUse hook failed', { error: err })\n })\n }\n\n return\n case 'progress':\n \n yield createProgressMessage(\n toolUseID,\n siblingToolUseIDs,\n result.content,\n result.normalizedMessages || [],\n result.tools || [],\n )\n break\n }\n }\n } catch (error) {\n const content = formatError(error)\n logError(error)\n \n yield createUserMessage([\n {\n type: 'tool_result',\n content,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n }\n}\n\nfunction formatError(error: unknown): string {\n if (!(error instanceof Error)) {\n return String(error)\n }\n const parts = [error.message]\n if ('stderr' in error && typeof error.stderr === 'string') {\n parts.push(error.stderr)\n }\n if ('stdout' in error && typeof error.stdout === 'string') {\n parts.push(error.stdout)\n }\n const fullMessage = parts.filter(Boolean).join('\\n')\n if (fullMessage.length <= 10000) {\n return fullMessage\n }\n const halfLength = 5000\n const start = fullMessage.slice(0, halfLength)\n const end = fullMessage.slice(-halfLength)\n return `${start}\\n\\n... [${fullMessage.length - 10000} characters truncated] ...\\n\\n${end}`\n}\n"],
5
- "mappings": "AAOA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,yBAAyB;AAClC,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,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SAAS,OAAO,MAAM,WAAW,UAAU;AACzD,UAAM,KAAK,MAAM,MAAM;AAAA,EACzB;AACA,QAAM,cAAc,MAAM,OAAO,OAAO,EAAE,KAAK,IAAI;AACnD,MAAI,YAAY,UAAU,KAAO;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,aAAa;AACnB,QAAM,QAAQ,YAAY,MAAM,GAAG,UAAU;AAC7C,QAAM,MAAM,YAAY,MAAM,CAAC,UAAU;AACzC,SAAO,GAAG,KAAK;AAAA;AAAA,OAAY,YAAY,SAAS,GAAK;AAAA;AAAA,EAAiC,GAAG;AAC3F;",
4
+ "sourcesContent": ["import {\n Message as APIAssistantMessage,\n MessageParam,\n ToolUseBlock,\n} from '@anthropic-ai/sdk/resources/index.mjs'\nimport type { UUID } from './types/common'\nimport type { Tool, ToolUseContext, AskUserFn } from './Tool'\nimport {\n messagePairValidForBinaryFeedback,\n shouldUseBinaryFeedback,\n} from '@components/binary-feedback/utils'\nimport { CanUseToolFn } from './hooks/useCanUseTool'\nimport {\n formatSystemPromptWithContext,\n queryLLM,\n queryModel,\n} from '@services/claude'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { all } from '@utils/generators'\nimport { logError } from '@utils/log'\nimport {\n debug,\n markPhase,\n getCurrentRequest,\n logUserFriendly,\n} from './utils/debugLogger'\nimport { getModelManager } from '@utils/model'\nimport {\n createAssistantMessage,\n createProgressMessage,\n createToolResultStopMessage,\n createUserMessage,\n FullToolUseResult,\n INTERRUPT_MESSAGE,\n INTERRUPT_MESSAGE_FOR_TOOL_USE,\n NormalizedMessage,\n normalizeMessagesForAPI,\n} from '@utils/messages'\nimport { createToolExecutionController } from '@utils/toolExecutionController'\nimport { BashTool } from '@tools/BashTool/BashTool'\nimport { getCwd } from './utils/state'\nimport { checkAutoCompact } from './utils/autoCompactCore'\nimport { getHookManager } from '@utils/hookManager'\n\n// Extended ToolUseContext for query functions\ninterface ExtendedToolUseContext extends ToolUseContext {\n abortController: AbortController\n options: {\n commands: any[]\n forkNumber: number\n messageLogName: string\n tools: Tool[]\n verbose: boolean\n safeMode: boolean\n maxThinkingTokens: number\n isKodingRequest?: boolean\n model?: string | import('./utils/config').ModelPointerType\n }\n readFileTimestamps: { [filename: string]: number }\n setToolJSX: (jsx: any) => void\n askUser?: AskUserFn\n requestId?: string\n}\n\nexport type Response = { costUSD: number; response: string }\nexport type UserMessage = {\n message: MessageParam\n type: 'user'\n uuid: UUID\n toolUseResult?: FullToolUseResult\n options?: {\n isKodingRequest?: boolean\n kodingContext?: string\n isCustomCommand?: boolean\n commandName?: string\n commandArgs?: string\n }\n}\n\nexport type AssistantMessage = {\n costUSD: number\n durationMs: number\n message: APIAssistantMessage\n type: 'assistant'\n uuid: UUID\n isApiErrorMessage?: boolean\n responseId?: string // For GPT-5 Responses API state management\n}\n\nexport type BinaryFeedbackResult =\n | { message: AssistantMessage | null; shouldSkipPermissionCheck: false }\n | { message: AssistantMessage; shouldSkipPermissionCheck: true }\n\nexport type ProgressMessage = {\n content: AssistantMessage\n normalizedMessages: NormalizedMessage[]\n siblingToolUseIDs: Set<string>\n tools: Tool[]\n toolUseID: string\n type: 'progress'\n uuid: UUID\n}\n\n// Each array item is either a single message or a message-and-response pair\nexport type Message = UserMessage | AssistantMessage | ProgressMessage\n\nconst MAX_TOOL_USE_CONCURRENCY = 10\n\n// Returns a message if we got one, or `null` if the user cancelled\nasync function queryWithBinaryFeedback(\n toolUseContext: ExtendedToolUseContext,\n getAssistantResponse: () => Promise<AssistantMessage>,\n getBinaryFeedbackResponse?: (\n m1: AssistantMessage,\n m2: AssistantMessage,\n ) => Promise<BinaryFeedbackResult>,\n): Promise<BinaryFeedbackResult> {\n if (\n process.env.USER_TYPE !== 'ant' ||\n !getBinaryFeedbackResponse ||\n !(await shouldUseBinaryFeedback())\n ) {\n const assistantMessage = await getAssistantResponse()\n if (toolUseContext.abortController.signal.aborted) {\n return { message: null, shouldSkipPermissionCheck: false }\n }\n return { message: assistantMessage, shouldSkipPermissionCheck: false }\n }\n const [m1, m2] = await Promise.all([\n getAssistantResponse(),\n getAssistantResponse(),\n ])\n if (toolUseContext.abortController.signal.aborted) {\n return { message: null, shouldSkipPermissionCheck: false }\n }\n if (m2.isApiErrorMessage) {\n // If m2 is an error, we might as well return m1, even if it's also an error --\n // the UI will display it as an error as it would in the non-feedback path.\n return { message: m1, shouldSkipPermissionCheck: false }\n }\n if (m1.isApiErrorMessage) {\n return { message: m2, shouldSkipPermissionCheck: false }\n }\n if (!messagePairValidForBinaryFeedback(m1, m2)) {\n return { message: m1, shouldSkipPermissionCheck: false }\n }\n return await getBinaryFeedbackResponse(m1, m2)\n}\n\n/**\n * The rules of thinking are lengthy and fortuitous. They require plenty of thinking\n * of most long duration and deep meditation for a wizard to wrap one's noggin around.\n *\n * The rules follow:\n * 1. A message that contains a thinking or redacted_thinking block must be part of a query whose max_thinking_length > 0\n * 2. A thinking block may not be the last message in a block\n * 3. Thinking blocks must be preserved for the duration of an assistant trajectory (a single turn, or if that turn includes a tool_use block then also its subsequent tool_result and the following assistant message)\n *\n * Heed these rules well, young wizard. For they are the rules of thinking, and\n * the rules of thinking are the rules of the universe. If ye does not heed these\n * rules, ye will be punished with an entire day of debugging and hair pulling.\n */\nexport async function* query(\n messages: Message[],\n systemPrompt: string[],\n context: { [k: string]: string },\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n getBinaryFeedbackResponse?: (\n m1: AssistantMessage,\n m2: AssistantMessage,\n ) => Promise<BinaryFeedbackResult>,\n): AsyncGenerator<Message, void> {\n const currentRequest = getCurrentRequest()\n\n markPhase('QUERY_INIT')\n\n // Auto-compact check\n const { messages: processedMessages, wasCompacted } = await checkAutoCompact(\n messages,\n toolUseContext,\n )\n if (wasCompacted) {\n messages = processedMessages\n }\n\n markPhase('SYSTEM_PROMPT_BUILD')\n \n const { systemPrompt: fullSystemPrompt, reminders } =\n formatSystemPromptWithContext(systemPrompt, context, toolUseContext.agentId)\n\n // Emit session startup event\n emitReminderEvent('session:startup', {\n agentId: toolUseContext.agentId,\n messages: messages.length,\n timestamp: Date.now(),\n })\n\n // Inject reminders into the latest user message\n if (reminders && messages.length > 0) {\n // Find the last user message\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i]\n if (msg?.type === 'user') {\n const lastUserMessage = msg as UserMessage\n messages[i] = {\n ...lastUserMessage,\n message: {\n ...lastUserMessage.message,\n content:\n typeof lastUserMessage.message.content === 'string'\n ? reminders + lastUserMessage.message.content\n : [\n ...(Array.isArray(lastUserMessage.message.content)\n ? lastUserMessage.message.content\n : []),\n { type: 'text', text: reminders },\n ],\n },\n }\n break\n }\n }\n }\n\n markPhase('LLM_PREPARATION')\n\n function getAssistantResponse() {\n return queryLLM(\n normalizeMessagesForAPI(messages),\n fullSystemPrompt,\n toolUseContext.options.maxThinkingTokens,\n toolUseContext.options.tools,\n toolUseContext.abortController.signal,\n {\n safeMode: toolUseContext.options.safeMode ?? false,\n model: toolUseContext.options.model || 'main',\n prependCLISysprompt: true,\n toolUseContext: toolUseContext,\n },\n )\n }\n\n const result = await queryWithBinaryFeedback(\n toolUseContext,\n getAssistantResponse,\n getBinaryFeedbackResponse,\n )\n\n // If request was cancelled, return immediately with interrupt message \n if (toolUseContext.abortController.signal.aborted) {\n yield createAssistantMessage(INTERRUPT_MESSAGE)\n return\n }\n\n if (result.message === null) {\n yield createAssistantMessage(INTERRUPT_MESSAGE)\n return\n }\n\n const assistantMessage = result.message\n const shouldSkipPermissionCheck = result.shouldSkipPermissionCheck\n\n yield assistantMessage\n\n // @see https://docs.anthropic.com/en/docs/build-with-claude/tool-use\n // Note: stop_reason === 'tool_use' is unreliable -- it's not always set correctly\n const toolUseMessages = assistantMessage.message.content.filter(\n _ => _.type === 'tool_use',\n )\n\n // If there's no more tool use, we're done\n if (!toolUseMessages.length) {\n return\n }\n\n const toolResults: UserMessage[] = []\n \n // Simple concurrency check like original system\n const canRunConcurrently = toolUseMessages.every(msg =>\n toolUseContext.options.tools.find(t => t.name === msg.name)?.isReadOnly(),\n )\n\n if (canRunConcurrently) {\n for await (const message of runToolsConcurrently(\n toolUseMessages,\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n )) {\n yield message\n // progress messages are not sent to the server, so don't need to be accumulated for the next turn\n if (message.type === 'user') {\n toolResults.push(message)\n }\n }\n } else {\n for await (const message of runToolsSerially(\n toolUseMessages,\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n )) {\n yield message\n // progress messages are not sent to the server, so don't need to be accumulated for the next turn\n if (message.type === 'user') {\n toolResults.push(message)\n }\n }\n }\n\n if (toolUseContext.abortController.signal.aborted) {\n yield createAssistantMessage(INTERRUPT_MESSAGE_FOR_TOOL_USE)\n return\n }\n\n // Sort toolResults to match the order of toolUseMessages\n const orderedToolResults = toolResults.sort((a, b) => {\n const aIndex = toolUseMessages.findIndex(\n tu => tu.id === (a.message.content[0] as ToolUseBlock).id,\n )\n const bIndex = toolUseMessages.findIndex(\n tu => tu.id === (b.message.content[0] as ToolUseBlock).id,\n )\n return aIndex - bIndex\n })\n\n // Recursive query\n\n try {\n yield* await query(\n [...messages, assistantMessage, ...orderedToolResults],\n systemPrompt,\n context,\n canUseTool,\n toolUseContext,\n getBinaryFeedbackResponse,\n )\n } catch (error) {\n // Re-throw the error to maintain the original behavior\n throw error\n }\n}\n\nasync function* runToolsConcurrently(\n toolUseMessages: ToolUseBlock[],\n assistantMessage: AssistantMessage,\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<Message, void> {\n yield* all(\n toolUseMessages.map(toolUse =>\n runToolUse(\n toolUse,\n new Set(toolUseMessages.map(_ => _.id)),\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n ),\n ),\n MAX_TOOL_USE_CONCURRENCY,\n )\n}\n\nasync function* runToolsSerially(\n toolUseMessages: ToolUseBlock[],\n assistantMessage: AssistantMessage,\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<Message, void> {\n for (const toolUse of toolUseMessages) {\n yield* runToolUse(\n toolUse,\n new Set(toolUseMessages.map(_ => _.id)),\n assistantMessage,\n canUseTool,\n toolUseContext,\n shouldSkipPermissionCheck,\n )\n }\n}\n\nexport async function* runToolUse(\n toolUse: ToolUseBlock,\n siblingToolUseIDs: Set<string>,\n assistantMessage: AssistantMessage,\n canUseTool: CanUseToolFn,\n toolUseContext: ExtendedToolUseContext,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<Message, void> {\n const currentRequest = getCurrentRequest()\n\n // \uD83D\uDD0D Debug: \u5DE5\u5177\u8C03\u7528\u5F00\u59CB\n debug.flow('TOOL_USE_START', {\n toolName: toolUse.name,\n toolUseID: toolUse.id,\n inputSize: JSON.stringify(toolUse.input).length,\n siblingToolCount: siblingToolUseIDs.size,\n shouldSkipPermissionCheck: !!shouldSkipPermissionCheck,\n requestId: currentRequest?.id,\n })\n\n logUserFriendly(\n 'TOOL_EXECUTION',\n {\n toolName: toolUse.name,\n action: 'Starting',\n target: toolUse.input ? Object.keys(toolUse.input).join(', ') : '',\n },\n currentRequest?.id,\n )\n\n\n \n\n const toolName = toolUse.name\n const tool = toolUseContext.options.tools.find(t => t.name === toolName)\n\n // Check if the tool exists\n if (!tool) {\n debug.error('TOOL_NOT_FOUND', {\n requestedTool: toolName,\n availableTools: toolUseContext.options.tools.map(t => t.name),\n toolUseID: toolUse.id,\n requestId: currentRequest?.id,\n })\n\n \n\n yield createUserMessage([\n {\n type: 'tool_result',\n content: `Error: No such tool available: ${toolName}`,\n is_error: true,\n tool_use_id: toolUse.id,\n },\n ])\n return\n }\n\n const toolInput = toolUse.input as { [key: string]: string }\n\n debug.flow('TOOL_VALIDATION_START', {\n toolName: tool.name,\n toolUseID: toolUse.id,\n inputKeys: Object.keys(toolInput),\n requestId: currentRequest?.id,\n })\n\n try {\n // \uD83D\uDD27 Check for cancellation before starting tool execution\n if (toolUseContext.abortController.signal.aborted) {\n debug.flow('TOOL_USE_CANCELLED_BEFORE_START', {\n toolName: tool.name,\n toolUseID: toolUse.id,\n abortReason: 'AbortController signal',\n requestId: currentRequest?.id,\n })\n\n \n\n const message = createUserMessage([\n createToolResultStopMessage(toolUse.id),\n ])\n yield message\n return\n }\n\n // Track if any progress messages were yielded\n let hasProgressMessages = false\n \n for await (const message of checkPermissionsAndCallTool(\n tool,\n toolUse.id,\n siblingToolUseIDs,\n toolInput,\n toolUseContext,\n canUseTool,\n assistantMessage,\n shouldSkipPermissionCheck,\n )) {\n // \uD83D\uDD27 Check for cancellation during tool execution\n if (toolUseContext.abortController.signal.aborted) {\n debug.flow('TOOL_USE_CANCELLED_DURING_EXECUTION', {\n toolName: tool.name,\n toolUseID: toolUse.id,\n hasProgressMessages,\n abortReason: 'AbortController signal during execution',\n requestId: currentRequest?.id,\n })\n\n // If we yielded progress messages but got cancelled, yield a cancellation result\n if (hasProgressMessages && message.type === 'progress') {\n yield message // yield the last progress message first\n }\n \n // Always yield a tool result message for cancellation to clear UI state\n const cancelMessage = createUserMessage([\n createToolResultStopMessage(toolUse.id),\n ])\n yield cancelMessage\n return\n }\n\n if (message.type === 'progress') {\n hasProgressMessages = true\n }\n \n yield message\n }\n } catch (e) {\n logError(e)\n \n // \uD83D\uDD27 Even on error, ensure we yield a tool result to clear UI state\n const errorMessage = createUserMessage([\n {\n type: 'tool_result',\n content: `Tool execution failed: ${e instanceof Error ? e.message : String(e)}`,\n is_error: true,\n tool_use_id: toolUse.id,\n },\n ])\n yield errorMessage\n }\n}\n\n// TODO: Generalize this to all tools\nexport function normalizeToolInput(\n tool: Tool,\n input: { [key: string]: boolean | string | number },\n): { [key: string]: boolean | string | number } {\n switch (tool) {\n case BashTool: {\n const { command, timeout } = BashTool.inputSchema.parse(input) // already validated upstream, won't throw\n return {\n command: command.replace(`cd ${getCwd()} && `, ''),\n ...(timeout ? { timeout } : {}),\n }\n }\n default:\n return input\n }\n}\n\nasync function* checkPermissionsAndCallTool(\n tool: Tool,\n toolUseID: string,\n siblingToolUseIDs: Set<string>,\n input: { [key: string]: boolean | string | number },\n context: ToolUseContext,\n canUseTool: CanUseToolFn,\n assistantMessage: AssistantMessage,\n shouldSkipPermissionCheck?: boolean,\n): AsyncGenerator<UserMessage | ProgressMessage, void> {\n // Validate input types with zod\n // (surprisingly, the model is not great at generating valid input)\n const isValidInput = tool.inputSchema.safeParse(input)\n if (!isValidInput.success) {\n // Create a more helpful error message for common cases\n let errorMessage = `InputValidationError: ${isValidInput.error.message}`\n \n // Special handling for the \"View\" tool (FileReadTool) being called with empty parameters\n if (tool.name === 'View' && Object.keys(input).length === 0) {\n errorMessage = `Error: The View tool requires a 'file_path' parameter to specify which file to read. Please provide the absolute path to the file you want to view. For example: {\"file_path\": \"/path/to/file.txt\"}`\n }\n \n \n yield createUserMessage([\n {\n type: 'tool_result',\n content: errorMessage,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n\n const normalizedInput = normalizeToolInput(tool, input)\n\n // Validate input values. Each tool has its own validation logic\n const isValidCall = await tool.validateInput?.(\n normalizedInput as never,\n context,\n )\n if (isValidCall?.result === false) {\n yield createUserMessage([\n {\n type: 'tool_result',\n content: isValidCall!.message,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n\n // Check whether we have permission to use the tool,\n // and ask the user for permission if we don't\n const permissionResult = shouldSkipPermissionCheck\n ? ({ result: true } as const)\n : await canUseTool(tool, normalizedInput, context, assistantMessage)\n if (permissionResult.result === false) {\n yield createUserMessage([\n {\n type: 'tool_result',\n content: permissionResult.message,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n\n // PreToolUse hooks\n const hookManager = getHookManager()\n if (hookManager) {\n try {\n const decision = await hookManager.executePreToolUse(\n tool.name,\n normalizedInput as Record<string, unknown>,\n )\n\n if (!decision.shouldContinue) {\n if (decision.shouldAskUser) {\n // Ask user for approval via permission system\n const approved = await canUseTool(tool, normalizedInput, context, assistantMessage)\n if (approved.result === false) {\n yield createUserMessage([\n {\n type: 'tool_result',\n content: decision.reason || 'Hook requested approval but user denied',\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n } else {\n // Hook blocked the tool\n yield createUserMessage([\n {\n type: 'tool_result',\n content: decision.reason || 'Tool execution blocked by hook',\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n return\n }\n }\n } catch (error) {\n debug.error('PreToolUse hook failed', { error })\n // Continue on error (fail-safe)\n }\n }\n\n // Call the tool\n let toolOutput: FullToolUseResult | null = null\n try {\n const generator = tool.call(normalizedInput as never, context)\n for await (const result of generator) {\n switch (result.type) {\n case 'result':\n toolOutput = {\n data: result.data,\n resultForAssistant: result.resultForAssistant || String(result.data),\n }\n\n yield createUserMessage(\n [\n {\n type: 'tool_result',\n content: result.resultForAssistant || String(result.data),\n tool_use_id: toolUseID,\n },\n ],\n toolOutput,\n )\n\n // PostToolUse hooks (fire-and-forget)\n if (hookManager && toolOutput) {\n hookManager.executePostToolUse(\n tool.name,\n normalizedInput as Record<string, unknown>,\n toolOutput as any,\n ).catch(err => {\n debug.error('PostToolUse hook failed', { error: err })\n })\n }\n\n return\n case 'progress':\n \n yield createProgressMessage(\n toolUseID,\n siblingToolUseIDs,\n result.content,\n result.normalizedMessages || [],\n result.tools || [],\n )\n break\n }\n }\n } catch (error) {\n const content = formatError(error)\n logError(error)\n \n yield createUserMessage([\n {\n type: 'tool_result',\n content,\n is_error: true,\n tool_use_id: toolUseID,\n },\n ])\n }\n}\n\nfunction formatError(error: unknown): string {\n if (!(error instanceof Error)) {\n return String(error)\n }\n const parts = [error.message]\n if ('stderr' in error && typeof error.stderr === 'string') {\n parts.push(error.stderr)\n }\n if ('stdout' in error && typeof error.stdout === 'string') {\n parts.push(error.stdout)\n }\n const fullMessage = parts.filter(Boolean).join('\\n')\n if (fullMessage.length <= 10000) {\n return fullMessage\n }\n const halfLength = 5000\n const start = fullMessage.slice(0, halfLength)\n const end = fullMessage.slice(-halfLength)\n return `${start}\\n\\n... [${fullMessage.length - 10000} characters truncated] ...\\n\\n${end}`\n}\n"],
5
+ "mappings": "AAOA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,yBAAyB;AAClC,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAgE/B,MAAM,2BAA2B;AAGjC,eAAe,wBACb,gBACA,sBACA,2BAI+B;AAC/B,MACE,QAAQ,IAAI,cAAc,SAC1B,CAAC,6BACD,CAAE,MAAM,wBAAwB,GAChC;AACA,UAAM,mBAAmB,MAAM,qBAAqB;AACpD,QAAI,eAAe,gBAAgB,OAAO,SAAS;AACjD,aAAO,EAAE,SAAS,MAAM,2BAA2B,MAAM;AAAA,IAC3D;AACA,WAAO,EAAE,SAAS,kBAAkB,2BAA2B,MAAM;AAAA,EACvE;AACA,QAAM,CAAC,IAAI,EAAE,IAAI,MAAM,QAAQ,IAAI;AAAA,IACjC,qBAAqB;AAAA,IACrB,qBAAqB;AAAA,EACvB,CAAC;AACD,MAAI,eAAe,gBAAgB,OAAO,SAAS;AACjD,WAAO,EAAE,SAAS,MAAM,2BAA2B,MAAM;AAAA,EAC3D;AACA,MAAI,GAAG,mBAAmB;AAGxB,WAAO,EAAE,SAAS,IAAI,2BAA2B,MAAM;AAAA,EACzD;AACA,MAAI,GAAG,mBAAmB;AACxB,WAAO,EAAE,SAAS,IAAI,2BAA2B,MAAM;AAAA,EACzD;AACA,MAAI,C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,MACJ;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,UAAM,UAAU,YAAY,KAAK;AACjC,aAAS,KAAK;AAEd,UAAM,kBAAkB;AAAA,MACtB;AAAA,QACE,MAAM;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,aAAa;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEA,SAAS,YAAY,OAAwB;AAC3C,MAAI,EAAE,iBAAiB,QAAQ;AAC7B,WAAO,OAAO,KAAK;AAAA,EACrB;AACA,QAAM,QAAQ,CAAC,MAAM,OAAO;AAC5B,MAAI,YAAY,SAAS,OAAO,MAAM,WAAW,UAAU;AACzD,UAAM,KAAK,MAAM,MAAM;AAAA,EACzB;AACA,MAAI,YAAY,SAAS,OAAO,MAAM,WAAW,UAAU;AACzD,UAAM,KAAK,MAAM,MAAM;AAAA,EACzB;AACA,QAAM,cAAc,MAAM,OAAO,OAAO,EAAE,KAAK,IAAI;AACnD,MAAI,YAAY,UAAU,KAAO;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,aAAa;AACnB,QAAM,QAAQ,YAAY,MAAM,GAAG,UAAU;AAC7C,QAAM,MAAM,YAAY,MAAM,CAAC,UAAU;AACzC,SAAO,GAAG,KAAK;AAAA;AAAA,OAAY,YAAY,SAAS,GAAK;AAAA;AAAA,EAAiC,GAAG;AAC3F;",
6
6
  "names": []
7
7
  }
@@ -63,6 +63,8 @@ import { randomUUID } from "crypto";
63
63
  import { getMessagesPath } from "../utils/log.js";
64
64
  import { BackgroundShellManager } from "../utils/BackgroundShellManager.js";
65
65
  import { BackgroundTasksPanel } from "../components/BackgroundTasksPanel.js";
66
+ import { AskUserQuestionDialog } from "../components/AskUserQuestionDialog.js";
67
+ import useAskUser from "../hooks/useAskUser.js";
66
68
  function REPL({
67
69
  commands,
68
70
  safeMode,
@@ -107,6 +109,7 @@ function REPL({
107
109
  getGlobalConfig().hasAcknowledgedCostThreshold
108
110
  );
109
111
  const [binaryFeedbackContext, setBinaryFeedbackContext] = useState(null);
112
+ const [askUserQuestionContext, setAskUserQuestionContext] = useState(null);
110
113
  const updateAvailableVersion = initialUpdateVersion ?? null;
111
114
  const updateCommands = initialUpdateCommands ?? null;
112
115
  const [isTodoPanelVisible, setIsTodoPanelVisible] = useState(true);
@@ -162,6 +165,7 @@ function REPL({
162
165
  }
163
166
  }, [messages, showCostDialog, haveShownCostDialog]);
164
167
  const canUseTool = useCanUseTool(setToolUseConfirm);
168
+ const askUser = useAskUser(setAskUserQuestionContext);
165
169
  async function onInit() {
166
170
  reverify();
167
171
  if (!initialPrompt) {
@@ -228,7 +232,8 @@ function REPL({
228
232
  messageId: getLastAssistantMessageId([...messages, ...newMessages]),
229
233
  readFileTimestamps: readFileTimestamps.current,
230
234
  abortController: newAbortController,
231
- setToolJSX
235
+ setToolJSX,
236
+ askUser
232
237
  },
233
238
  getBinaryFeedbackResponse
234
239
  )) {
@@ -298,7 +303,8 @@ function REPL({
298
303
  messageId: getLastAssistantMessageId([...messages, lastMessage]),
299
304
  readFileTimestamps: readFileTimestamps.current,
300
305
  abortController: controllerToUse,
301
- setToolJSX
306
+ setToolJSX,
307
+ askUser
302
308
  },
303
309
  getBinaryFeedbackResponse
304
310
  )) {
@@ -527,7 +533,7 @@ function REPL({
527
533
  unresolvedToolUseIDs
528
534
  }
529
535
  ),
530
- !toolJSX && toolUseConfirm && !isMessageSelectorVisible && !binaryFeedbackContext && /* @__PURE__ */ React.createElement(
536
+ !toolJSX && toolUseConfirm && !isMessageSelectorVisible && !binaryFeedbackContext && !askUserQuestionContext && /* @__PURE__ */ React.createElement(
531
537
  PermissionRequest,
532
538
  {
533
539
  toolUseConfirm,
@@ -535,7 +541,14 @@ function REPL({
535
541
  verbose
536
542
  }
537
543
  ),
538
- !toolJSX && !toolUseConfirm && !isMessageSelectorVisible && !binaryFeedbackContext && showingCostDialog && /* @__PURE__ */ React.createElement(
544
+ !toolJSX && !toolUseConfirm && !isMessageSelectorVisible && !binaryFeedbackContext && askUserQuestionContext && /* @__PURE__ */ React.createElement(
545
+ AskUserQuestionDialog,
546
+ {
547
+ context: askUserQuestionContext,
548
+ onDone: () => setAskUserQuestionContext(null)
549
+ }
550
+ ),
551
+ !toolJSX && !toolUseConfirm && !isMessageSelectorVisible && !binaryFeedbackContext && !askUserQuestionContext && showingCostDialog && /* @__PURE__ */ React.createElement(
539
552
  CostThresholdDialog,
540
553
  {
541
554
  onDone: () => {
@@ -549,7 +562,7 @@ function REPL({
549
562
  }
550
563
  }
551
564
  ),
552
- !toolUseConfirm && !toolJSX?.shouldHidePromptInput && shouldShowPromptInput && !isMessageSelectorVisible && !binaryFeedbackContext && !showingCostDialog && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
565
+ !toolUseConfirm && !toolJSX?.shouldHidePromptInput && shouldShowPromptInput && !isMessageSelectorVisible && !binaryFeedbackContext && !askUserQuestionContext && !showingCostDialog && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
553
566
  TodoPanel,
554
567
  {
555
568
  todos: getTodos(),