@ywldan/kiro 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -397,9 +397,12 @@ Compaction shows a notice and is written to the session, so a resumed conversati
397
397
  | `multi_edit(path, edits[])` | Several exact replacements in one file, validated together and written once | always (except `--yolo`) |
398
398
  | `apply_patch(patch)` | Applies a unified diff to one or more files after validating every hunk | always (except `--yolo`) |
399
399
  | `run_command(command, timeout_seconds?)` | Runs a shell command in the working directory | always (except `--yolo`) |
400
+ | `ask_user(question, options, header?, multi_select?, allow_other?)` | Asks the user to pick from 1 to 4 short options and waits for the answer. `Other` accepts typed text | never |
400
401
 
401
402
  `grep` and `glob` keep large repositories manageable, and `read_file` pages through long files. Use `multi_edit` for several changes in one file and `apply_patch` for coordinated changes across files; `apply_patch` validates the whole patch before writing and rejects deletions and renames.
402
403
 
404
+ `ask_user` shows a centered prompt when the model needs a decision that belongs to you, such as a design direction or a choice between conflicting requirements. Use `↑/↓` to move, `Enter` to choose, `Space` to toggle when several answers are allowed, and `Esc` to dismiss. Dismissing returns a refusal to the model and the turn continues. Headless runs have no terminal, so the tool returns an error and the model is told to ask in plain text instead.
405
+
403
406
  Approvals show a diff, or the exact command, and offer:
404
407
 
405
408
  - `[y]` allow once
@@ -48,10 +48,11 @@ export async function buildSystemPrompt(cwd) {
48
48
  '- Tool output may be truncated. Use read_file offsets, narrower grep patterns/globs, or smaller result limits if you need more detail.',
49
49
  '- If a tool returns an error, read it carefully and adjust; edit_file/multi_edit errors include a hint about the closest line or whitespace mismatch.',
50
50
  '- The user must approve write_file, edit_file, multi_edit, apply_patch, and run_command. If they deny a call, respect the decision and explain alternatives instead of retrying the same action.',
51
+ '- Use ask_user when a choice belongs to the user: design direction, mutually exclusive options, or a requirement only they can settle. Ask once with short labels and wait; do not print numbered questions as text. Do not use it to ask permission for a tool call.',
51
52
  '- Do not invent file contents or command output. Keep final answers concise: say what changed and include relevant verification results.',
52
53
  '- A turn is limited to 25 tool-call rounds. Keep work focused and finish when the task is done.',
53
54
  '',
54
- 'You have these tools: read_file, write_file, edit_file, multi_edit, apply_patch, list_dir, glob, grep, run_command.',
55
+ 'You have these tools: read_file, write_file, edit_file, multi_edit, apply_patch, list_dir, glob, grep, run_command, ask_user.',
55
56
  ].join('\n');
56
57
  const [agents, inventory] = await Promise.all([readAgentsSection(cwd), loadSkills(cwd)]);
57
58
  const sections = [base, agents, formatSkillIndex(inventory.skills)].filter(Boolean);
@@ -0,0 +1,136 @@
1
+ import { booleanArg, stringArg } from './paths.js';
2
+ import { denied, ok, toolError } from './types.js';
3
+ const MAX_OPTIONS = 4;
4
+ const MAX_OPTION_LABEL_CHARS = 40;
5
+ const MAX_OPTION_DESCRIPTION_CHARS = 120;
6
+ const MAX_QUESTION_CHARS = 400;
7
+ const MAX_HEADER_CHARS = 12;
8
+ function optionList(input) {
9
+ const raw = input.options;
10
+ if (!Array.isArray(raw))
11
+ throw new Error('Argument "options" must be an array.');
12
+ if (raw.length < 1 || raw.length > MAX_OPTIONS) {
13
+ throw new Error(`Argument "options" must contain 1 to ${MAX_OPTIONS} entries.`);
14
+ }
15
+ const seen = new Set();
16
+ return raw.map((entry, index) => {
17
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
18
+ throw new Error(`Option ${index + 1} must be an object with a "label" and optional "description".`);
19
+ }
20
+ const item = entry;
21
+ const label = typeof item.label === 'string' ? item.label.trim() : '';
22
+ if (!label)
23
+ throw new Error(`Option ${index + 1} needs a non-empty "label".`);
24
+ if (label.length > MAX_OPTION_LABEL_CHARS) {
25
+ throw new Error(`Option ${index + 1} label is longer than ${MAX_OPTION_LABEL_CHARS} characters; shorten it.`);
26
+ }
27
+ if (seen.has(label.toLowerCase())) {
28
+ throw new Error(`Option ${index + 1} repeats the label "${label}". Use distinct labels.`);
29
+ }
30
+ seen.add(label.toLowerCase());
31
+ if (item.description === undefined || item.description === null)
32
+ return { label };
33
+ if (typeof item.description !== 'string') {
34
+ throw new Error(`Option ${index + 1} "description" must be a string.`);
35
+ }
36
+ const description = item.description.trim();
37
+ if (!description)
38
+ return { label };
39
+ if (description.length > MAX_OPTION_DESCRIPTION_CHARS) {
40
+ throw new Error(`Option ${index + 1} description is longer than ${MAX_OPTION_DESCRIPTION_CHARS} characters; shorten it.`);
41
+ }
42
+ return { label, description };
43
+ });
44
+ }
45
+ function answerText(request, selected, other) {
46
+ const lines = [`The user answered: ${request.question}`];
47
+ if (selected.length > 0)
48
+ lines.push(`Selected: ${selected.join('; ')}`);
49
+ if (other)
50
+ lines.push(`Other: ${other}`);
51
+ return lines.join('\n');
52
+ }
53
+ const askUserTool = {
54
+ definition: {
55
+ type: 'function',
56
+ function: {
57
+ name: 'ask_user',
58
+ description: 'Ask the user a question with a short list of choices when the decision is genuinely theirs and guessing would waste work. ' +
59
+ 'This blocks until they answer and returns the selection. Use it instead of printing numbered questions as text. ' +
60
+ 'Do not use it to request permission for a tool call; approvals already cover that.',
61
+ parameters: {
62
+ type: 'object',
63
+ properties: {
64
+ question: {
65
+ type: 'string',
66
+ description: `What to ask, one or two sentences (max ${MAX_QUESTION_CHARS} characters).`,
67
+ },
68
+ header: {
69
+ type: 'string',
70
+ description: `Short title for the prompt, at most ${MAX_HEADER_CHARS} characters, e.g. "Design".`,
71
+ },
72
+ options: {
73
+ type: 'array',
74
+ minItems: 1,
75
+ maxItems: MAX_OPTIONS,
76
+ description: `One to ${MAX_OPTIONS} distinct choices.`,
77
+ items: {
78
+ type: 'object',
79
+ properties: {
80
+ label: { type: 'string', description: `Choice text (max ${MAX_OPTION_LABEL_CHARS} characters).` },
81
+ description: {
82
+ type: 'string',
83
+ description: `Optional one-line detail (max ${MAX_OPTION_DESCRIPTION_CHARS} characters).`,
84
+ },
85
+ },
86
+ required: ['label'],
87
+ additionalProperties: false,
88
+ },
89
+ },
90
+ multi_select: {
91
+ type: 'boolean',
92
+ description: 'Allow more than one choice. Default false.',
93
+ },
94
+ allow_other: {
95
+ type: 'boolean',
96
+ description: 'Offer a free-form answer next to the listed choices. Default true.',
97
+ },
98
+ },
99
+ required: ['question', 'options'],
100
+ additionalProperties: false,
101
+ },
102
+ },
103
+ },
104
+ async run(input, ctx) {
105
+ const question = stringArg(input, 'question').trim();
106
+ if (question.length > MAX_QUESTION_CHARS) {
107
+ return toolError(`The question is longer than ${MAX_QUESTION_CHARS} characters. Shorten it and put details in the option descriptions.`);
108
+ }
109
+ const header = (stringArg(input, 'header', true) ?? '').trim().slice(0, MAX_HEADER_CHARS) || undefined;
110
+ const options = optionList(input);
111
+ const multiSelect = booleanArg(input, 'multi_select', false);
112
+ const allowOther = booleanArg(input, 'allow_other', true);
113
+ const request = { question, header, options, multiSelect, allowOther };
114
+ if (!ctx.askUser) {
115
+ return toolError('ask_user needs an interactive terminal, and this run has none. ' +
116
+ 'Ask the question in plain text and stop, so the user can answer in their next message.');
117
+ }
118
+ if (ctx.signal.aborted)
119
+ return denied('Cancelled before the user answered.');
120
+ const answer = await ctx.askUser(request);
121
+ if (answer.cancelled) {
122
+ return denied('The user dismissed the question without answering. Do not ask it again; continue with a sensible ' +
123
+ 'default, or ask in plain text if the answer is still required.');
124
+ }
125
+ const selected = request.options
126
+ .map((option) => option.label)
127
+ .filter((label) => answer.selected.includes(label));
128
+ const other = answer.other?.trim();
129
+ if (selected.length === 0 && !other) {
130
+ return denied('The user submitted no answer.');
131
+ }
132
+ return ok(answerText(request, selected, other), `ask_user: ${[...selected, ...(other ? [`Other: ${other}`] : [])].join(', ')}`);
133
+ },
134
+ };
135
+ export const askTools = [askUserTool];
136
+ //# sourceMappingURL=ask.js.map
@@ -1,4 +1,5 @@
1
1
  import { redactSecrets } from '../secrets.js';
2
+ import { askTools } from './ask.js';
2
3
  import { fsTools } from './fs.js';
3
4
  import { patchTools } from './patch.js';
4
5
  import { searchTools } from './search.js';
@@ -6,7 +7,14 @@ import { runCommandTool } from './shell.js';
6
7
  import { skillTools } from './skill.js';
7
8
  import { toolError } from './types.js';
8
9
  export const MAX_TOOL_RESULT_CHARS = 60_000;
9
- export const tools = [...fsTools, ...searchTools, ...patchTools, runCommandTool, ...skillTools];
10
+ export const tools = [
11
+ ...fsTools,
12
+ ...searchTools,
13
+ ...patchTools,
14
+ runCommandTool,
15
+ ...askTools,
16
+ ...skillTools,
17
+ ];
10
18
  export const toolDefinitions = tools.map((tool) => tool.definition);
11
19
  const byName = new Map(tools.map((tool) => [tool.definition.function.name, tool]));
12
20
  export function isReadOnlyTool(name) {
package/dist/ui/App.js CHANGED
@@ -14,6 +14,7 @@ import { runAddFlow, runEditFlow, runRemoveFlow, } from '../model/wizard.js';
14
14
  import { createProvider } from '../providers/index.js';
15
15
  import { dropIncompleteToolCalls, formatSessionTime, isSessionId, listAllSessions, listSessions, loadSession, newSessionId, projectSessionsDir, saveSession, titleFromMessages, } from '../sessions.js';
16
16
  import { ApprovalPrompt } from './ApprovalPrompt.js';
17
+ import { AskUserPrompt } from './AskUserPrompt.js';
17
18
  import { ApprovalPolicy } from './approval-policy.js';
18
19
  import { builtinCommandNames, buildSkillCommands, SLASH_COMMANDS, slashHelpLines, } from './commands.js';
19
20
  import { defaultExportPath, renderTranscriptMarkdown } from './export.js';
@@ -36,6 +37,8 @@ import { undoLastCheckpoint } from '../tools/checkpoint.js';
36
37
  import { MAX_EXPANDED_TOOL_CHARS, MAX_REASONING_CHARS, } from './types.js';
37
38
  /** Idle Ctrl+C must be pressed again within this window to exit. */
38
39
  const QUIT_CONFIRM_MS = 2_000;
40
+ /** Tallest inline question block: title, three question lines, four options, other, footer, borders. */
41
+ const ASK_INLINE_ROWS = 12;
39
42
  function useTerminalSize() {
40
43
  const { stdout } = useStdout();
41
44
  const read = useCallback(() => ({
@@ -87,6 +90,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
87
90
  const [activeTool, setActiveTool] = useState(null);
88
91
  const [cancelling, setCancelling] = useState(false);
89
92
  const [pendingApproval, setPendingApproval] = useState(null);
93
+ const [pendingQuestion, setPendingQuestion] = useState(null);
90
94
  const [pickerOpen, setPickerOpen] = useState(false);
91
95
  const [sessionPicker, setSessionPicker] = useState(null);
92
96
  const [quitArmed, setQuitArmed] = useState(false);
@@ -146,6 +150,8 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
146
150
  const [autoAllowed, setAutoAllowed] = useState([]);
147
151
  const pendingApprovalRef = useRef(null);
148
152
  const pendingResolverRef = useRef(null);
153
+ const pendingQuestionRef = useRef(null);
154
+ const questionResolverRef = useRef(null);
149
155
  const textBufferRef = useRef('');
150
156
  const queuedRef = useRef([]);
151
157
  const [queuedCount, setQueuedCount] = useState(0);
@@ -485,6 +491,29 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
485
491
  setPendingApproval(request);
486
492
  });
487
493
  }, [approvalPolicy]);
494
+ const resolveQuestion = useCallback((answer) => {
495
+ const resolver = questionResolverRef.current;
496
+ pendingQuestionRef.current = null;
497
+ questionResolverRef.current = null;
498
+ setPendingQuestion(null);
499
+ resolver?.(answer);
500
+ }, []);
501
+ const askUser = useCallback((request) => {
502
+ const signal = abortRef.current?.signal;
503
+ if (signal?.aborted)
504
+ return Promise.resolve({ selected: [], cancelled: true });
505
+ return new Promise((resolve) => {
506
+ // Cancelling the turn must release the tool, even if Ctrl+C skipped the prompt.
507
+ const onAbort = () => resolveQuestion({ selected: [], cancelled: true });
508
+ signal?.addEventListener('abort', onAbort, { once: true });
509
+ pendingQuestionRef.current = request;
510
+ questionResolverRef.current = (answer) => {
511
+ signal?.removeEventListener('abort', onAbort);
512
+ resolve(answer);
513
+ };
514
+ setPendingQuestion(request);
515
+ });
516
+ }, [resolveQuestion]);
488
517
  const resetAutoAllowed = useCallback(() => {
489
518
  approvalPolicy.clear();
490
519
  setAutoAllowed([]);
@@ -566,6 +595,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
566
595
  cwd,
567
596
  signal: controller.signal,
568
597
  approve,
598
+ askUser,
569
599
  };
570
600
  for await (const event of runAgentTurn({
571
601
  provider,
@@ -708,6 +738,8 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
708
738
  setCancelling(false);
709
739
  if (pendingApprovalRef.current)
710
740
  resolveApproval('deny');
741
+ if (pendingQuestionRef.current)
742
+ resolveQuestion({ selected: [], cancelled: true });
711
743
  recomputeContext();
712
744
  void persistSession();
713
745
  void refreshSkillCommands();
@@ -724,6 +756,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
724
756
  }, [
725
757
  addNotice,
726
758
  approve,
759
+ askUser,
727
760
  autoCompact,
728
761
  cwd,
729
762
  finalizeAssistant,
@@ -735,6 +768,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
735
768
  queueText,
736
769
  recomputeContext,
737
770
  resolveApproval,
771
+ resolveQuestion,
738
772
  ]);
739
773
  const runProfileTest = useCallback(async (requested) => {
740
774
  if (busyRef.current || transitioningRef.current || wizardActiveRef.current) {
@@ -1409,8 +1443,12 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
1409
1443
  }, [stdout, mouseOn]);
1410
1444
  useInput((input, key) => {
1411
1445
  if (key.ctrl && input === 'o') {
1412
- if (wizardActiveRef.current || wizardPromptRef.current || pendingApprovalRef.current)
1446
+ if (wizardActiveRef.current ||
1447
+ wizardPromptRef.current ||
1448
+ pendingApprovalRef.current ||
1449
+ pendingQuestionRef.current) {
1413
1450
  return;
1451
+ }
1414
1452
  if (pickerOpen || sessionPicker !== null)
1415
1453
  return;
1416
1454
  expandLastToolOutput();
@@ -1433,11 +1471,12 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
1433
1471
  cancelWizard();
1434
1472
  return;
1435
1473
  }
1436
- if (pendingApprovalRef.current) {
1474
+ if (pendingApprovalRef.current || pendingQuestionRef.current) {
1437
1475
  disarmQuit();
1438
1476
  cancelRequestedRef.current = true;
1439
1477
  setCancelling(true);
1440
1478
  resolveApproval('deny');
1479
+ resolveQuestion({ selected: [], cancelled: true });
1441
1480
  abortRef.current?.abort();
1442
1481
  return;
1443
1482
  }
@@ -1458,45 +1497,59 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
1458
1497
  }
1459
1498
  armQuit();
1460
1499
  });
1461
- const activity = pendingApproval
1462
- ? 'approval'
1463
- : cancelling
1464
- ? 'cancelling'
1465
- : busy
1466
- ? activeTool
1467
- ? 'running'
1468
- : replying
1469
- ? 'replying'
1470
- : 'thinking'
1471
- : null;
1500
+ const activity = pendingQuestion
1501
+ ? 'question'
1502
+ : pendingApproval
1503
+ ? 'approval'
1504
+ : cancelling
1505
+ ? 'cancelling'
1506
+ : busy
1507
+ ? activeTool
1508
+ ? 'running'
1509
+ : replying
1510
+ ? 'replying'
1511
+ : 'thinking'
1512
+ : null;
1472
1513
  const activeProfile = runtimeConfig.profiles[profileName];
1473
1514
  const contextWindow = contextWindowFor(activeProfile);
1515
+ const questionPopup = pendingQuestion !== null && !pendingApproval ? pickerPopupRect(columns, rows) : null;
1516
+ const questionInline = pendingQuestion !== null && !pendingApproval && questionPopup === null;
1474
1517
  const pickerPopup = (pickerOpen || sessionPicker !== null) && !pendingApproval
1475
1518
  ? pickerPopupRect(columns, rows)
1476
1519
  : null;
1477
1520
  const pickerInline = pickerOpen && !pendingApproval && pickerPopup === null;
1478
1521
  const sessionInline = sessionPicker !== null && !pendingApproval && pickerPopup === null && !pickerOpen;
1479
- const extraInputRows = pendingApproval || pickerInline || sessionInline ? 0 : Math.max(0, inputRows - 1);
1522
+ const extraInputRows = pendingApproval || questionInline || pickerInline || sessionInline
1523
+ ? 0
1524
+ : Math.max(0, inputRows - 1);
1480
1525
  const viewportHeight = Math.max(3, rows -
1481
1526
  5 -
1482
1527
  extraInputRows -
1483
1528
  (pendingApproval ? 12 : 0) -
1529
+ (questionInline ? ASK_INLINE_ROWS : 0) -
1484
1530
  (pickerInline ? PICKER_INLINE_ROWS : 0) -
1485
1531
  (sessionInline ? SESSION_INLINE_ROWS : 0));
1486
1532
  const showUsageCard = usageCardEnabled && shouldShowUsageCard(columns, viewportHeight);
1487
1533
  const chatWidth = showUsageCard ? Math.max(40, width - USAGE_CARD_WIDTH - USAGE_CARD_GAP) : width;
1488
- return (_jsxs(Box, { flexDirection: "column", width: columns, paddingX: 1, children: [_jsxs(Box, { flexDirection: "row", alignItems: "flex-end", width: width, children: [_jsx(MessageList, { items: items, width: chatWidth, height: viewportHeight, resetSignal: resetSignal, expandedToolId: expandedToolId, palette: palette, interactive: !pendingApproval && !pickerOpen && sessionPicker === null && !wizardActive && wizardPrompt === null }), showUsageCard ? (_jsx(Box, { marginLeft: USAGE_CARD_GAP, flexShrink: 0, children: _jsx(UsageCard, { usage: sessionUsage, contextTokens: contextTokens, contextWindow: contextWindow, contextEstimated: usageRef.current === null, lastReply: lastReply, busy: busy }) })) : null] }), pendingApproval ? (_jsx(ApprovalPrompt, { request: pendingApproval, width: width, onDecision: resolveApproval })) : pickerInline ? (_jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: width, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) })) : sessionInline && sessionPicker ? (_jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: width, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) })) : (_jsx(Input, { disabled: pickerOpen || sessionPicker !== null, width: width, mask: wizardPrompt?.mask, allowEmpty: wizardPrompt?.allowEmpty, fileMenu: !wizardActive && !wizardPrompt, loadFiles: loadFileIndex, maxRows: Math.max(1, Math.min(6, rows - 9)), history: wizardPrompt || wizardActive ? undefined : promptHistory, slashCommands: [...SLASH_COMMANDS, ...skillCommands], onPaletteChange: setPalette, onHeightChange: setInputRows, placeholder: pickerOpen
1534
+ return (_jsxs(Box, { flexDirection: "column", width: columns, paddingX: 1, children: [_jsxs(Box, { flexDirection: "row", alignItems: "flex-end", width: width, children: [_jsx(MessageList, { items: items, width: chatWidth, height: viewportHeight, resetSignal: resetSignal, expandedToolId: expandedToolId, palette: palette, interactive: !pendingApproval &&
1535
+ pendingQuestion === null &&
1536
+ !pickerOpen &&
1537
+ sessionPicker === null &&
1538
+ !wizardActive &&
1539
+ wizardPrompt === null }), showUsageCard ? (_jsx(Box, { marginLeft: USAGE_CARD_GAP, flexShrink: 0, children: _jsx(UsageCard, { usage: sessionUsage, contextTokens: contextTokens, contextWindow: contextWindow, contextEstimated: usageRef.current === null, lastReply: lastReply, busy: busy }) })) : null] }), pendingApproval ? (_jsx(ApprovalPrompt, { request: pendingApproval, width: width, onDecision: resolveApproval })) : questionInline && pendingQuestion ? (_jsx(AskUserPrompt, { request: pendingQuestion, width: width, onAnswer: resolveQuestion, onCancel: () => resolveQuestion({ selected: [], cancelled: true }) })) : pickerInline ? (_jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: width, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) })) : sessionInline && sessionPicker ? (_jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: width, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) })) : (_jsx(Input, { disabled: pickerOpen || sessionPicker !== null || pendingQuestion !== null, width: width, mask: wizardPrompt?.mask, allowEmpty: wizardPrompt?.allowEmpty, fileMenu: !wizardActive && !wizardPrompt, loadFiles: loadFileIndex, maxRows: Math.max(1, Math.min(6, rows - 9)), history: wizardPrompt || wizardActive ? undefined : promptHistory, slashCommands: [...SLASH_COMMANDS, ...skillCommands], onPaletteChange: setPalette, onHeightChange: setInputRows, placeholder: pickerOpen
1489
1540
  ? 'Model picker open · Esc to close'
1490
1541
  : sessionPicker
1491
1542
  ? 'Session picker open · Esc to close'
1492
- : wizardPrompt
1493
- ? wizardPrompt.defaultValue && !wizardPrompt.mask
1494
- ? `${wizardPrompt.label} [${wizardPrompt.defaultValue}]`
1495
- : wizardPrompt.label
1496
- : busy
1497
- ? 'Kiro is working… type ahead, or Ctrl+C to cancel'
1498
- : wizardActive
1499
- ? 'Working… Esc to cancel'
1500
- : 'Ask Kiro to build or change something…', slashMenu: !wizardActive && !wizardPrompt, onSubmit: handleSubmit, onCancel: wizardActive ? cancelWizard : undefined }, wizardPrompt?.id ?? 0)), _jsx(StatusBar, { width: width, profile: profileName, model: activeProfile?.model ?? 'unknown', cwd: cwd, activity: activity, toolName: activeTool ?? undefined, busySince: busySince ?? undefined, queued: queuedCount > 0 ? queuedCount : undefined, yolo: yolo, autoAllowed: autoAllowed, quitHint: quitArmed, contextTokens: showUsageCard ? undefined : contextTokens, contextWindow: showUsageCard ? undefined : contextWindow }), pickerOpen && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: pickerPopup.width, height: pickerPopup.height, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) }) })) : sessionPicker && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: pickerPopup.width, height: pickerPopup.height, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) }) })) : null] }));
1543
+ : pendingQuestion
1544
+ ? 'Answer the question above · Esc to cancel'
1545
+ : wizardPrompt
1546
+ ? wizardPrompt.defaultValue && !wizardPrompt.mask
1547
+ ? `${wizardPrompt.label} [${wizardPrompt.defaultValue}]`
1548
+ : wizardPrompt.label
1549
+ : busy
1550
+ ? 'Kiro is working… type ahead, or Ctrl+C to cancel'
1551
+ : wizardActive
1552
+ ? 'Working… Esc to cancel'
1553
+ : 'Ask Kiro to build or change something…', slashMenu: !wizardActive && !wizardPrompt, onSubmit: handleSubmit, onCancel: wizardActive ? cancelWizard : undefined }, wizardPrompt?.id ?? 0)), _jsx(StatusBar, { width: width, profile: profileName, model: activeProfile?.model ?? 'unknown', cwd: cwd, activity: activity, toolName: activeTool ?? undefined, busySince: busySince ?? undefined, queued: queuedCount > 0 ? queuedCount : undefined, yolo: yolo, autoAllowed: autoAllowed, quitHint: quitArmed, contextTokens: showUsageCard ? undefined : contextTokens, contextWindow: showUsageCard ? undefined : contextWindow }), pendingQuestion && questionPopup ? (_jsx(Box, { position: "absolute", marginTop: questionPopup.top, marginLeft: questionPopup.left, children: _jsx(AskUserPrompt, { request: pendingQuestion, width: questionPopup.width, height: questionPopup.height, onAnswer: resolveQuestion, onCancel: () => resolveQuestion({ selected: [], cancelled: true }) }) })) : pickerOpen && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: pickerPopup.width, height: pickerPopup.height, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) }) })) : sessionPicker && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: pickerPopup.width, height: pickerPopup.height, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) }) })) : null] }));
1501
1554
  }
1502
1555
  //# sourceMappingURL=App.js.map
@@ -0,0 +1,130 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Box, Text, useInput } from 'ink';
4
+ import { sanitizeText, truncateToWidth, wrapPlain } from './text.js';
5
+ /** Keys are highlighted so the hint reads at a glance; the rest stays dim. */
6
+ const KEY_COLOR = '#ff9e64';
7
+ const MAX_QUESTION_LINES = 3;
8
+ function Key({ children }) {
9
+ return _jsx(Text, { color: KEY_COLOR, children: children });
10
+ }
11
+ function Said({ children }) {
12
+ return _jsx(Text, { dimColor: true, children: children });
13
+ }
14
+ /**
15
+ * Blocking question with a short choice list. Enter picks (or submits the
16
+ * checked set), Space toggles in multi-select mode, and typing jumps to the
17
+ * free-form "Other" row when the request allows it.
18
+ */
19
+ export function AskUserPrompt({ request, width, height, onAnswer, onCancel, }) {
20
+ const [index, setIndex] = useState(0);
21
+ const [checked, setChecked] = useState(new Set());
22
+ const [editing, setEditing] = useState(false);
23
+ const [draft, setDraft] = useState('');
24
+ const rows = request.options.length + (request.allowOther ? 1 : 0);
25
+ const selected = Math.min(index, Math.max(0, rows - 1));
26
+ const otherIndex = request.allowOther ? request.options.length : -1;
27
+ const popup = height !== undefined;
28
+ const base = popup ? 'white' : undefined;
29
+ const submit = (labels, other) => {
30
+ if (labels.length === 0 && !other?.trim())
31
+ return;
32
+ onAnswer({ selected: labels, other: other?.trim() || undefined, cancelled: false });
33
+ };
34
+ useInput((input, key) => {
35
+ if (editing) {
36
+ if (key.escape) {
37
+ setEditing(false);
38
+ setDraft('');
39
+ return;
40
+ }
41
+ if (key.return) {
42
+ submit([...checked], draft);
43
+ return;
44
+ }
45
+ if (key.backspace || key.delete) {
46
+ setDraft(draft.slice(0, -1));
47
+ return;
48
+ }
49
+ if (key.ctrl || key.meta || key.tab || key.upArrow || key.downArrow || key.pageUp || key.pageDown) {
50
+ return;
51
+ }
52
+ const typed = input.replace(/[\u0000-\u001f\u007f]/g, '');
53
+ if (typed)
54
+ setDraft(draft + typed);
55
+ return;
56
+ }
57
+ if (key.escape) {
58
+ onCancel();
59
+ return;
60
+ }
61
+ if (key.upArrow || key.downArrow) {
62
+ if (rows === 0)
63
+ return;
64
+ const delta = key.upArrow ? -1 : 1;
65
+ setIndex(Math.min(rows - 1, Math.max(0, selected + delta)));
66
+ return;
67
+ }
68
+ if (key.home) {
69
+ setIndex(0);
70
+ return;
71
+ }
72
+ if (key.end) {
73
+ setIndex(Math.max(0, rows - 1));
74
+ return;
75
+ }
76
+ if (input === ' ' && request.multiSelect && selected !== otherIndex) {
77
+ const label = request.options[selected]?.label;
78
+ if (!label)
79
+ return;
80
+ const next = new Set(checked);
81
+ if (next.has(label))
82
+ next.delete(label);
83
+ else
84
+ next.add(label);
85
+ setChecked(next);
86
+ return;
87
+ }
88
+ if (!key.return) {
89
+ if (!request.allowOther || key.ctrl || key.meta || key.tab)
90
+ return;
91
+ const typed = input.replace(/[\u0000-\u001f\u007f]/g, '');
92
+ if (!typed)
93
+ return;
94
+ setIndex(otherIndex);
95
+ setEditing(true);
96
+ setDraft(typed);
97
+ return;
98
+ }
99
+ if (selected === otherIndex) {
100
+ setEditing(true);
101
+ return;
102
+ }
103
+ const option = request.options[selected];
104
+ if (!option)
105
+ return;
106
+ if (!request.multiSelect) {
107
+ submit([option.label]);
108
+ return;
109
+ }
110
+ const labels = new Set(checked);
111
+ if (labels.size === 0)
112
+ labels.add(option.label);
113
+ submit([...labels]);
114
+ });
115
+ const innerWidth = Math.max(10, width - 4);
116
+ const questionLines = wrapPlain(sanitizeText(request.question), innerWidth);
117
+ const clipped = questionLines.slice(0, MAX_QUESTION_LINES);
118
+ if (questionLines.length > MAX_QUESTION_LINES) {
119
+ const last = clipped.length - 1;
120
+ clipped[last] = `${truncateToWidth(clipped[last] ?? '', innerWidth - 2)} …`;
121
+ }
122
+ const title = `? ${request.header ?? 'Question'}`;
123
+ return (_jsxs(Box, { flexDirection: "column", width: width, height: height, borderStyle: "round", borderColor: "magenta", paddingX: 1, flexShrink: 0, backgroundColor: popup ? 'black' : undefined, overflow: height === undefined ? undefined : 'hidden', children: [_jsx(Text, { bold: true, color: "magenta", wrap: "truncate-end", children: title }), clipped.map((line, lineIndex) => (_jsx(Text, { color: base, wrap: "truncate-end", children: line || ' ' }, `q${lineIndex}`))), request.options.map((option, optionIndex) => {
124
+ const focused = optionIndex === selected;
125
+ const mark = request.multiSelect ? (checked.has(option.label) ? '[x]' : '[ ]') : ' ';
126
+ return (_jsxs(Text, { color: focused ? 'magenta' : base, bold: focused, wrap: "truncate-end", children: [`${focused ? '>' : ' '} ${mark} ${optionIndex + 1}. ${option.label}`, option.description ? _jsx(Said, { children: ` ${option.description}` }) : null] }, `o${optionIndex}`));
127
+ }), request.allowOther ? (_jsxs(Text, { color: selected === otherIndex ? 'magenta' : base, bold: selected === otherIndex, children: [`${selected === otherIndex ? '>' : ' '}${request.multiSelect ? ' ' : ' '}` +
128
+ `${request.options.length + 1}. Other: `, editing ? (_jsx(Text, { color: base, children: `${draft || ''}▌` })) : (_jsx(Said, { children: "type an answer" }))] })) : null, height === undefined ? null : _jsx(Box, { flexGrow: 1 }), editing ? (_jsxs(Text, { color: base, wrap: "truncate-end", children: [_jsx(Key, { children: "Enter" }), _jsx(Said, { children: " submit \u00B7 type your answer \u00B7 " }), _jsx(Key, { children: "Esc" }), _jsx(Said, { children: " back" })] })) : (_jsxs(Text, { color: base, wrap: "truncate-end", children: [_jsx(Key, { children: "\u2191/\u2193" }), _jsx(Said, { children: " move \u00B7 " }), request.multiSelect ? (_jsxs(_Fragment, { children: [_jsx(Key, { children: "Space" }), _jsx(Said, { children: " toggle \u00B7 " }), _jsx(Key, { children: "Enter" }), _jsx(Said, { children: " submit \u00B7 " })] })) : (_jsxs(_Fragment, { children: [_jsx(Key, { children: "Enter" }), _jsx(Said, { children: " choose \u00B7 " })] })), _jsx(Key, { children: "Esc" }), _jsx(Said, { children: " cancel" })] }))] }));
129
+ }
130
+ //# sourceMappingURL=AskUserPrompt.js.map
@@ -27,15 +27,17 @@ export function StatusBar({ width, profile, model, cwd, activity, toolName, busy
27
27
  ? 'Ctrl+C again to quit'
28
28
  : activity === 'approval'
29
29
  ? 'approval needed'
30
- : activity === 'cancelling'
31
- ? 'cancelling…'
32
- : activity === 'running'
33
- ? `running ${toolName ?? 'tool'}…`
34
- : activity === 'replying'
35
- ? 'replying…'
36
- : activity === 'thinking'
37
- ? 'thinking…'
38
- : 'ready';
30
+ : activity === 'question'
31
+ ? 'answer needed'
32
+ : activity === 'cancelling'
33
+ ? 'cancelling…'
34
+ : activity === 'running'
35
+ ? `running ${toolName ?? 'tool'}…`
36
+ : activity === 'replying'
37
+ ? 'replying…'
38
+ : activity === 'thinking'
39
+ ? 'thinking…'
40
+ : 'ready';
39
41
  const stateColor = quitHint
40
42
  ? 'red'
41
43
  : activity === 'cancelling'
package/dist/ui/text.js CHANGED
@@ -473,6 +473,8 @@ export function summarizeToolArgs(name, rawArguments) {
473
473
  const command = typeof args.command === 'string' ? args.command : '';
474
474
  return `$ ${sanitizeInput(command)}`;
475
475
  }
476
+ case 'ask_user':
477
+ return typeof args.question === 'string' ? args.question : '?';
476
478
  default:
477
479
  return truncateToWidth(sanitizeInput(rawArguments), 80);
478
480
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ywldan/kiro",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "A small terminal coding agent with your own OpenAI-compatible endpoint",
5
5
  "keywords": [
6
6
  "ai",