@orion-agents/orion-code 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +4 -4
  3. package/README.zh-CN.md +4 -4
  4. package/dist/commands/context-commands.js +16 -28
  5. package/dist/commands/context-tool-command-handlers.d.ts +2 -3
  6. package/dist/commands/context-tool-command-handlers.js +2 -20
  7. package/dist/commands/registry.js +24 -61
  8. package/dist/commands/retired-commands.d.ts +2 -0
  9. package/dist/commands/retired-commands.js +24 -0
  10. package/dist/commands/session-command-handlers.d.ts +3 -2
  11. package/dist/commands/session-command-handlers.js +41 -42
  12. package/dist/commands/session-commands.js +21 -0
  13. package/dist/commands/system-commands.js +2 -27
  14. package/dist/commands/tool-commands.js +0 -10
  15. package/dist/commands/types.d.ts +6 -4
  16. package/dist/commands/workflow-commands.js +0 -24
  17. package/dist/core/tool-artifacts.js +17 -4
  18. package/dist/framework/query.js +151 -17
  19. package/dist/framework/tool-state.d.ts +4 -0
  20. package/dist/harness/context-harness.d.ts +7 -3
  21. package/dist/harness/context-harness.js +222 -48
  22. package/dist/harness/contract.js +3 -1
  23. package/dist/harness/drift-guard.js +67 -17
  24. package/dist/harness/goal-verification.d.ts +11 -0
  25. package/dist/harness/goal-verification.js +62 -0
  26. package/dist/harness/ledger.js +16 -3
  27. package/dist/harness/state.js +3 -0
  28. package/dist/harness/stop-controller.js +1 -1
  29. package/dist/harness/task-checklist.d.ts +11 -1
  30. package/dist/harness/task-checklist.js +48 -4
  31. package/dist/harness/types.d.ts +10 -0
  32. package/dist/harness/verification.d.ts +11 -1
  33. package/dist/harness/verification.js +47 -2
  34. package/dist/runtime/agent-loop.js +4 -1
  35. package/dist/runtime/agent-runtime-controller.d.ts +4 -2
  36. package/dist/runtime/agent-runtime-controller.js +115 -30
  37. package/dist/runtime/batch-read-service.js +21 -4
  38. package/dist/runtime/goal-runtime-coordinator.js +1 -0
  39. package/dist/runtime/orion-session-runner.js +3 -5
  40. package/dist/runtime/product-bootstrap.js +24 -11
  41. package/dist/runtime/product-orion-runtime.js +24 -2
  42. package/dist/runtime/task-context-recovery.js +21 -5
  43. package/dist/runtime/task-context-service.d.ts +3 -1
  44. package/dist/runtime/task-context-service.js +3 -0
  45. package/dist/runtime/ui-events.d.ts +4 -1
  46. package/dist/runtime/ui-view-model.js +7 -3
  47. package/dist/runtime/workspace-verification.d.ts +2 -2
  48. package/dist/runtime/workspace-verification.js +24 -9
  49. package/dist/services/chat-completion-sse.d.ts +9 -0
  50. package/dist/services/chat-completion-sse.js +50 -0
  51. package/dist/services/compact/summary-generator.d.ts +1 -1
  52. package/dist/services/compact/summary-generator.js +12 -0
  53. package/dist/services/llm.d.ts +1 -1
  54. package/dist/services/llm.js +165 -292
  55. package/dist/services/provider-diagnostics.d.ts +1 -1
  56. package/dist/services/provider-diagnostics.js +7 -2
  57. package/dist/services/provider-resilience/error-classifier.d.ts +3 -0
  58. package/dist/services/provider-resilience/error-classifier.js +14 -0
  59. package/dist/skills/builtin/security-check/SKILL.md +2 -2
  60. package/dist/skills/builtin/test-gen/SKILL.md +2 -2
  61. package/dist/terminal-ui/launch.js +1 -1
  62. package/dist/tools/core/common.d.ts +0 -11
  63. package/dist/tools/core/common.js +0 -18
  64. package/dist/tools/core/edit-file.js +57 -86
  65. package/dist/tools/core/exec-command.js +61 -80
  66. package/dist/tools/core/grep.js +84 -24
  67. package/dist/tools/core/read-file.js +3 -2
  68. package/dist/tools/todo.d.ts +2 -2
  69. package/dist/tools/todo.js +13 -10
  70. package/dist/tui-ui/launch.js +4 -1
  71. package/dist/tui-ui/layout.d.ts +2 -2
  72. package/dist/tui-ui/layout.js +59 -47
  73. package/dist/tui-ui/pickers.d.ts +3 -1
  74. package/dist/tui-ui/pickers.js +17 -11
  75. package/dist/tui-ui/runner.d.ts +1 -1
  76. package/dist/tui-ui/runner.js +61 -68
  77. package/dist/tui-ui/state.d.ts +4 -0
  78. package/dist/tui-ui/state.js +33 -2
  79. package/dist/utils/utf8.d.ts +6 -0
  80. package/dist/utils/utf8.js +14 -0
  81. package/docs/cli-guide.md +27 -3
  82. package/npm-shrinkwrap.json +2 -2
  83. package/package.json +1 -1
@@ -21,7 +21,7 @@ const TODO_PROMPT = `Use this tool to create and manage a structured task list f
21
21
 
22
22
  ## When to Use This Tool
23
23
 
24
- If the task context requires a checklist, create it before changing the workspace. Name the exact target paths in the implementation steps and include a separate verification step.
24
+ If the task context requires a checklist, create it before changing the workspace. Name the exact target paths in the implementation steps and include verification.
25
25
 
26
26
  1. Complex multi-step tasks - When a task requires 3 or more distinct steps
27
27
  2. Non-trivial tasks - Tasks that require careful planning or multiple operations
@@ -56,8 +56,9 @@ For verification steps, also include verification with the required check kinds
56
56
 
57
57
  - Keep at most ONE task in_progress at a time
58
58
  - Mark tasks complete IMMEDIATELY after finishing
59
- - Keep the descriptions of existing steps stable. Add new steps as needed.
59
+ - Keep descriptions stable. To clarify an unfinished step, replace its bare filename with the exact workspace-relative path.
60
60
  - Only mark a step completed after running its work and checks while it is in progress.
61
+ - An implementation step with verification requires both a file change and a passing check.
61
62
  - Run each verification command directly with exec_command and use its cwd argument for the project directory. If a check fails, retry that check successfully before completing the step.`;
62
63
  exports.MAX_TODOS = 8;
63
64
  exports.MAX_TODO_TEXT = 120;
@@ -166,16 +167,18 @@ ${TODO_PROMPT}`,
166
167
  error: 'A blocker requires one active todo and a reason of up to 400 characters.',
167
168
  };
168
169
  }
169
- const error = typeof blocker === 'string' ? save(normalized, blocker.trim()) : save(normalized);
170
- if (error)
171
- return { success: false, output: '', error };
172
- const completed = normalized.filter(todo => todo.status === 'completed').length;
173
- const current = normalized.find(todo => todo.status === 'in_progress');
170
+ const saved = typeof blocker === 'string' ? save(normalized, blocker.trim()) : save(normalized);
171
+ if (typeof saved === 'string')
172
+ return { success: false, output: '', error: saved };
173
+ const applied = saved?.todos ?? normalized;
174
+ const completed = applied.filter(todo => todo.status === 'completed').length;
175
+ const current = applied.find(todo => todo.status === 'in_progress');
176
+ const output = [formatTodosForDisplay(applied), ...(saved?.warnings ?? [])].join('\n');
174
177
  return {
175
178
  success: true,
176
- output: formatTodosForDisplay(normalized),
177
- summary: `${completed}/${normalized.length} complete${current ? ` · ${current.activeForm}` : ''}`,
178
- metadata: { taskTodos: normalized },
179
+ output,
180
+ summary: `${completed}/${applied.length} complete${current ? ` · ${current.activeForm}` : ''}`,
181
+ metadata: { taskTodos: applied },
179
182
  };
180
183
  },
181
184
  isReadOnly: () => false,
@@ -324,7 +324,10 @@ async function launchTuiUI(runtime, options = {}) {
324
324
  if (result.type === 'exit_requested') {
325
325
  void stop();
326
326
  }
327
- if (result.type === 'followup_queue_full' || result.type === 'followup_queue_rejected') {
327
+ if (result.type === 'followup_queue_full' ||
328
+ result.type === 'followup_queue_rejected' ||
329
+ result.type === 'command_rejected_busy' ||
330
+ result.type === 'command_ignored') {
328
331
  return false;
329
332
  }
330
333
  };
@@ -42,8 +42,8 @@ export interface TuiLayoutBudget {
42
42
  }
43
43
  /**
44
44
  * Measure the cursor-owned live block. Idle TUI state stays compact like an
45
- * ordinary shell prompt; streaming transcript and overlays grow the block only
46
- * as needed, up to the surface's viewport-derived limit.
45
+ * ordinary shell prompt. Composer pickers draw into this same block, so opening
46
+ * one does not allocate terminal rows or advance native scrollback.
47
47
  */
48
48
  export declare function measureTuiLiveFrameHeight(state: TuiUiState, width: number, maxHeight: number, options?: TuiTranscriptLayoutOptions): number;
49
49
  export declare function renderTuiUiFrame(state: TuiUiState, options: TuiLayoutOptions): TuiFrame;
@@ -20,6 +20,7 @@ const MIN_WIDTH = 24;
20
20
  const MIN_HEIGHT = 8;
21
21
  const PROMPT_BORDER_ROWS = 2;
22
22
  const MAX_TIMELINE_ROWS = 6;
23
+ const MAX_COMPOSER_PICKER_ROWS = 6;
23
24
  const STATUS_ROWS = 1;
24
25
  const ACTIVITY_SPINNER = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧'];
25
26
  /**
@@ -55,15 +56,16 @@ function activeSubtaskTimelineEntries(state) {
55
56
  }
56
57
  /**
57
58
  * Measure the cursor-owned live block. Idle TUI state stays compact like an
58
- * ordinary shell prompt; streaming transcript and overlays grow the block only
59
- * as needed, up to the surface's viewport-derived limit.
59
+ * ordinary shell prompt. Composer pickers draw into this same block, so opening
60
+ * one does not allocate terminal rows or advance native scrollback.
60
61
  */
61
62
  function measureTuiLiveFrameHeight(state, width, maxHeight, options = {}) {
62
63
  const safeWidth = Math.max(MIN_WIDTH, Math.floor(width));
63
64
  const transcriptWidth = resolveTranscriptWidth(safeWidth, options.transcriptWidth);
64
65
  const safeMaxHeight = Math.max(MIN_HEIGHT, Math.floor(maxHeight));
65
- if (state.overlay)
66
+ if (state.overlay && state.overlay.type !== 'commands' && state.overlay.type !== 'files') {
66
67
  return safeMaxHeight;
68
+ }
67
69
  const budget = computeBudget(safeMaxHeight, state);
68
70
  const fixedRows = safeMaxHeight - budget.transcriptRows;
69
71
  const transcriptRows = state.transcript
@@ -88,8 +90,7 @@ function renderTuiUiFrame(state, options) {
88
90
  renderTimeline(frame, state, timelineTop, budget.timelineRows, options.theme);
89
91
  renderStatus(frame, state, statusRow, options);
90
92
  renderPrompt(frame, state, promptTop, width, budget.promptLineCount, options.theme);
91
- // Overlay covers the region above status (transcript + timeline).
92
- renderOverlay(frame, state, activityRow);
93
+ renderOverlay(frame, state.overlay, activityRow, timelineTop, options.theme ?? style_1.DEFAULT_THEME);
93
94
  if (budget.activityRows)
94
95
  renderActivity(frame, state, activityRow, options);
95
96
  return frame;
@@ -118,7 +119,7 @@ function renderTuiLiveFrame(state, options) {
118
119
  renderTimeline(frame, state, timelineTop, budget.timelineRows, options.theme);
119
120
  renderStatus(frame, state, statusRow, options);
120
121
  renderPrompt(frame, state, promptTop, width, budget.promptLineCount, options.theme);
121
- renderOverlay(frame, state, activityRow);
122
+ renderOverlay(frame, state.overlay, activityRow, timelineTop, options.theme ?? style_1.DEFAULT_THEME);
122
123
  if (budget.activityRows)
123
124
  renderActivity(frame, state, activityRow, options);
124
125
  return frame;
@@ -332,14 +333,17 @@ function promptLineViewport(value, cursor, width) {
332
333
  cursorCells,
333
334
  };
334
335
  }
335
- function renderOverlay(frame, state, maxRows) {
336
- if (!state.overlay || maxRows <= 0)
336
+ function renderOverlay(frame, overlay, maxRows, transcriptRows, theme) {
337
+ if (!overlay || maxRows <= 0)
338
+ return;
339
+ if (overlay.type === 'commands' || overlay.type === 'files') {
340
+ renderComposerPicker(frame, overlay, transcriptRows, theme);
337
341
  return;
338
- if (state.overlay.type === 'sessions') {
339
- const overlay = state.overlay;
342
+ }
343
+ if (overlay.type === 'sessions') {
340
344
  const request = overlay.request;
341
345
  const visibleCount = Math.max(0, Math.min(maxRows - 1, request.maxVisibleItems ?? maxRows - 1, request.sessions.length));
342
- const start = sessionPickerStartIndex(state.overlay.selectedIndex, visibleCount, request.sessions.length);
346
+ const start = sessionPickerStartIndex(overlay.selectedIndex, visibleCount, request.sessions.length);
343
347
  const visibleSessions = request.sessions.slice(start, start + visibleCount);
344
348
  const rows = [
345
349
  `Sessions: ${request.title} (${overlay.selectedIndex + 1}/${request.sessions.length})`,
@@ -362,12 +366,11 @@ function renderOverlay(frame, state, maxRows) {
362
366
  }
363
367
  return;
364
368
  }
365
- if (state.overlay.type === 'model') {
366
- const overlay = state.overlay;
369
+ if (overlay.type === 'model') {
367
370
  const request = overlay.request;
368
371
  const pickerState = (0, ui_view_model_1.createModelPickerState)({ ...request, visibleStart: 0 });
369
372
  const visibleCount = Math.max(0, Math.min(maxRows - 1, request.maxVisibleItems ?? maxRows - 1, request.models.length));
370
- const start = sessionPickerStartIndex(state.overlay.selectedIndex, visibleCount, request.models.length);
373
+ const start = sessionPickerStartIndex(overlay.selectedIndex, visibleCount, request.models.length);
371
374
  const visibleModels = request.models.slice(start, start + visibleCount);
372
375
  const rows = [
373
376
  `Models: ${request.title ?? 'Switch Model'} (${overlay.selectedIndex + 1}/${request.models.length})`,
@@ -391,8 +394,7 @@ function renderOverlay(frame, state, maxRows) {
391
394
  }
392
395
  return;
393
396
  }
394
- if (state.overlay.type === 'edit') {
395
- const overlay = state.overlay;
397
+ if (overlay.type === 'edit') {
396
398
  const req = overlay.request;
397
399
  const visibleCount = Math.max(0, Math.min(maxRows - 1, 10, req.candidates.length));
398
400
  const start = pickerStartIndex(overlay.selectedIndex, visibleCount, req.candidates.length);
@@ -420,36 +422,7 @@ function renderOverlay(frame, state, maxRows) {
420
422
  }
421
423
  return;
422
424
  }
423
- if (state.overlay.type === 'commands' || state.overlay.type === 'files') {
424
- const overlay = state.overlay;
425
- const visibleCount = Math.max(0, Math.min(maxRows - 2, 10, overlay.items.length || 1));
426
- const start = pickerStartIndex(overlay.selectedIndex, visibleCount, overlay.items.length);
427
- const visibleItems = overlay.items.slice(start, start + visibleCount);
428
- const title = overlay.type === 'commands'
429
- ? `Commands${overlay.query ? ` "${overlay.query}"` : ''}`
430
- : `Files${overlay.query ? ` "${overlay.query}"` : ''}`;
431
- const rows = [
432
- `${title} (${overlay.items.length} match${overlay.items.length === 1 ? '' : 'es'})`,
433
- ...(overlay.items.length === 0
434
- ? [' No matching items']
435
- : visibleItems.map((item, offset) => {
436
- const index = start + offset;
437
- const marker = index === overlay.selectedIndex ? '›' : ' ';
438
- const description = item.description ? ` ${item.description}` : '';
439
- return `${marker} ${item.label}${description}`;
440
- })),
441
- ].map(row => truncateCells(row, frame.width));
442
- rows.slice(0, maxRows).forEach((line, index) => {
443
- (0, frame_1.writeFrameText)(frame, index, 0, line);
444
- });
445
- // Clear any remaining transcript rows below overlay content
446
- for (let i = rows.length; i < maxRows; i++) {
447
- (0, frame_1.writeFrameText)(frame, i, 0, '');
448
- }
449
- return;
450
- }
451
- if (state.overlay.type === 'permission') {
452
- const overlay = state.overlay;
425
+ if (overlay.type === 'permission') {
453
426
  const picker = (0, ui_view_model_1.createPermissionDecisionPickerState)(overlay.request);
454
427
  const rows = [
455
428
  `Tool Permission: ${overlay.request.name}`,
@@ -468,7 +441,7 @@ function renderOverlay(frame, state, maxRows) {
468
441
  }
469
442
  return;
470
443
  }
471
- if (state.overlay.type === 'shortcuts') {
444
+ if (overlay.type === 'shortcuts') {
472
445
  const rows = [
473
446
  'Orion Pixel · Shortcuts',
474
447
  '/ commands @ files ? help Ctrl+O tools',
@@ -482,6 +455,45 @@ function renderOverlay(frame, state, maxRows) {
482
455
  });
483
456
  }
484
457
  }
458
+ function renderComposerPicker(frame, overlay, endRow, theme) {
459
+ const availableRows = Math.min(endRow, MAX_COMPOSER_PICKER_ROWS);
460
+ if (availableRows <= 0)
461
+ return;
462
+ const rows = [];
463
+ if (overlay.type === 'files' && availableRows > 1) {
464
+ const query = singleLine(overlay.query);
465
+ rows.push({ text: query ? `Files "${query}"` : 'Files' });
466
+ }
467
+ const count = Math.min(availableRows - rows.length, overlay.items.length);
468
+ const start = pickerStartIndex(overlay.selectedIndex, count, overlay.items.length);
469
+ const items = overlay.items.slice(start, start + count);
470
+ const labelWidth = Math.min(18, frame.width - 4);
471
+ for (const [index, item] of items.entries()) {
472
+ const selected = start + index === overlay.selectedIndex;
473
+ const marker = selected ? '›' : ' ';
474
+ const label = singleLine(item.label);
475
+ const description = item.description ? singleLine(item.description) : '';
476
+ const text = overlay.type === 'commands' &&
477
+ frame.width >= 40 &&
478
+ description &&
479
+ (0, string_width_1.default)(label) <= labelWidth
480
+ ? `${marker} ${label}${' '.repeat(labelWidth - (0, string_width_1.default)(label) + 2)}${description}`
481
+ : `${marker} ${label}`;
482
+ rows.push({ text, selected });
483
+ }
484
+ if (!items.length) {
485
+ rows.push({
486
+ text: overlay.type === 'commands' ? ' No matching commands' : ' No matching files',
487
+ });
488
+ }
489
+ rows.forEach(({ text, selected }, index) => {
490
+ const row = endRow - rows.length + index;
491
+ const style = selected ? theme.pickerSelected : undefined;
492
+ // Overwrite the entire row, including continuation cells from wide characters.
493
+ (0, frame_1.writeFrameText)(frame, row, 0, ' '.repeat(frame.width), style);
494
+ (0, frame_1.writeFrameText)(frame, row, 0, ellipsizeCells(text, frame.width), style);
495
+ });
496
+ }
485
497
  function sessionPickerStartIndex(selectedIndex, visibleCount, total) {
486
498
  return pickerStartIndex(selectedIndex, visibleCount, total);
487
499
  }
@@ -7,7 +7,9 @@ export interface TuiFileQuery {
7
7
  base: string;
8
8
  query: string;
9
9
  }
10
- export declare function visibleCommandItems(input: string): TuiPickerItem[];
10
+ /** Only the first slash token belongs to the root command picker. */
11
+ export declare function getCommandToken(input: string): string | undefined;
12
+ export declare function visibleCommandItems(query: string): TuiPickerItem[];
11
13
  export declare function getFileQuery(input: string): TuiFileQuery | null;
12
14
  export declare function visibleFileItems(cwd: string, input: string): TuiPickerItem[];
13
15
  //# sourceMappingURL=pickers.d.ts.map
@@ -1,22 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCommandToken = getCommandToken;
3
4
  exports.visibleCommandItems = visibleCommandItems;
4
5
  exports.getFileQuery = getFileQuery;
5
6
  exports.visibleFileItems = visibleFileItems;
6
7
  const commands_1 = require("../commands");
7
8
  const ui_view_model_1 = require("../runtime/ui-view-model");
8
9
  const file_glob_1 = require("../services/file-glob");
9
- function visibleCommandItems(input) {
10
- const commandToken = input.match(/^\/([^\s]*)/u)?.[1] ?? '';
11
- return (0, ui_view_model_1.createCommandPickerState)({
12
- input: `/${commandToken}`,
13
- commands: (0, commands_1.getVisibleCommands)('tui'),
14
- maxVisibleItems: 10,
15
- categoryLabel: commands_1.getCommandCategoryLabel,
16
- }).visibleItems.map(item => ({
17
- value: item.value,
18
- label: item.label,
19
- description: item.description,
10
+ /** Only the first slash token belongs to the root command picker. */
11
+ function getCommandToken(input) {
12
+ return /^\/[A-Za-z0-9-]*(?=\s|$)/u.exec(input)?.[0];
13
+ }
14
+ function visibleCommandItems(query) {
15
+ const prefix = query.toLowerCase();
16
+ const exact = (0, commands_1.findCommand)(prefix);
17
+ const commands = (0, commands_1.getVisibleCommands)('tui').filter(command => [command.name, ...(command.aliases ?? [])].some(name => name.toLowerCase().startsWith(prefix)));
18
+ if (exact && commands.includes(exact)) {
19
+ commands.splice(commands.indexOf(exact), 1);
20
+ commands.unshift(exact);
21
+ }
22
+ return commands.map(command => ({
23
+ value: command.name,
24
+ label: `/${command.name}`,
25
+ description: command.description,
20
26
  }));
21
27
  }
22
28
  function getFileQuery(input) {
@@ -65,6 +65,7 @@ export declare class TuiRunner {
65
65
  private historySearchQuery;
66
66
  private historySearchIndex;
67
67
  private historySearchMatch;
68
+ private dismissedCommandToken?;
68
69
  private animationFrame;
69
70
  private animationTimer;
70
71
  private surfaceFailed;
@@ -157,7 +158,6 @@ export declare class TuiRunner {
157
158
  private updatePrompt;
158
159
  private syncPromptOverlay;
159
160
  private completeCommand;
160
- private hasRecognizedCommandArguments;
161
161
  private completeFile;
162
162
  private answerPermission;
163
163
  /** Restore any temporary Inspector terminal ownership before shutdown. */
@@ -568,19 +568,16 @@ class TuiRunner {
568
568
  this.completeCommand(overlay.items[overlay.selectedIndex], false);
569
569
  return;
570
570
  case 'enter':
571
- if (/^\/(?:tool-output|redraw)(?:\s|$)/u.test(this.state.prompt.value.trim())) {
572
- this.dispatch({ type: 'closeOverlay' });
573
- this.submitPrompt();
574
- return;
575
- }
576
- if (this.hasRecognizedCommandArguments()) {
577
- this.dispatch({ type: 'closeOverlay' });
578
- this.submitPrompt();
579
- return;
571
+ if (value.trim() !== '/' || overlay.selectedIndex !== 0) {
572
+ const selected = overlay.items[overlay.selectedIndex];
573
+ if (selected)
574
+ this.completeCommand(selected, true);
575
+ else
576
+ this.submitPrompt();
580
577
  }
581
- this.completeCommand(overlay.items[overlay.selectedIndex], true);
582
578
  return;
583
579
  case 'escape':
580
+ this.dismissedCommandToken = (0, pickers_1.getCommandToken)(value);
584
581
  this.dispatch({ type: 'closeOverlay' });
585
582
  return;
586
583
  }
@@ -700,10 +697,10 @@ class TuiRunner {
700
697
  this.updatePrompt(deleteAfterCursor(value, cursor));
701
698
  return;
702
699
  case 'left':
703
- this.dispatch({ type: 'setPrompt', value, cursor: previousBoundary(value, cursor) });
700
+ this.updatePrompt({ value, cursor: previousBoundary(value, cursor) });
704
701
  return;
705
702
  case 'right':
706
- this.dispatch({ type: 'setPrompt', value, cursor: nextBoundary(value, cursor) });
703
+ this.updatePrompt({ value, cursor: nextBoundary(value, cursor) });
707
704
  return;
708
705
  case 'home':
709
706
  this.moveCursorLineHome();
@@ -712,7 +709,7 @@ class TuiRunner {
712
709
  this.moveCursorLineEnd();
713
710
  return;
714
711
  case 'ctrl+u':
715
- this.dispatch({ type: 'setPrompt', value: '', cursor: 0 });
712
+ this.updatePrompt({ value: '', cursor: 0 });
716
713
  this.dispatch({ type: 'closeOverlay' });
717
714
  return;
718
715
  case 'ctrl+w':
@@ -727,16 +724,15 @@ class TuiRunner {
727
724
  this.options.onInterrupt?.();
728
725
  return;
729
726
  case 'tab':
727
+ if ((0, pickers_1.getCommandToken)(value)) {
728
+ this.syncPromptOverlay(value, cursor, true);
729
+ return;
730
+ }
730
731
  if (this.state.processing && value.trim()) {
731
732
  this.queuePrompt();
732
733
  return;
733
734
  }
734
- if (value.startsWith('/')) {
735
- this.syncPromptOverlay(value);
736
- }
737
- else if ((0, pickers_1.getFileQuery)(value)) {
738
- this.syncPromptOverlay(value);
739
- }
735
+ this.syncPromptOverlay(value, cursor);
740
736
  return;
741
737
  case 'up':
742
738
  this.moveCursorUpOrHistory();
@@ -752,14 +748,14 @@ class TuiRunner {
752
748
  }
753
749
  queuePrompt() {
754
750
  const input = this.state.prompt.value.trim();
755
- if (!input)
751
+ if (!input || (0, pickers_1.getCommandToken)(input))
756
752
  return;
757
753
  try {
758
754
  const queued = this.options.onQueueSubmit?.(input);
759
755
  if (queued === false)
760
756
  return;
761
757
  this.history = (0, history_1.pushHistoryEntry)(this.history, input);
762
- this.dispatch({ type: 'setPrompt', value: '', cursor: 0 });
758
+ this.updatePrompt({ value: '', cursor: 0 });
763
759
  this.dispatch({ type: 'closeOverlay' });
764
760
  if (queued instanceof Promise)
765
761
  void queued.catch(() => this.reportSubmitFailure());
@@ -788,7 +784,7 @@ class TuiRunner {
788
784
  const match = matches[this.historySearchIndex % matches.length];
789
785
  this.historySearchIndex += 1;
790
786
  this.historySearchMatch = match;
791
- this.dispatch({ type: 'setPrompt', value: match, cursor: match.length });
787
+ this.updatePrompt({ value: match, cursor: match.length });
792
788
  this.dispatch({
793
789
  type: 'setStatus',
794
790
  message: `History ${((this.historySearchIndex - 1) % matches.length) + 1}/${matches.length}`,
@@ -808,7 +804,7 @@ class TuiRunner {
808
804
  await (0, promises_1.writeFile)(filePath, original, { encoding: 'utf8', mode: 0o600 });
809
805
  await this.options.onOpenExternalEditor(filePath);
810
806
  const next = await (0, promises_1.readFile)(filePath, 'utf8');
811
- this.dispatch({ type: 'setPrompt', value: next, cursor: next.length });
807
+ this.updatePrompt({ value: next, cursor: next.length });
812
808
  }
813
809
  finally {
814
810
  await (0, promises_1.rm)(directory, { recursive: true, force: true });
@@ -852,7 +848,7 @@ class TuiRunner {
852
848
  const { value, cursor } = this.state.prompt;
853
849
  const { line, col } = lineColOfCursor(value, cursor);
854
850
  if (line > 0) {
855
- this.dispatch({ type: 'setPrompt', value, cursor: cursorOfLineCol(value, line - 1, col) });
851
+ this.updatePrompt({ value, cursor: cursorOfLineCol(value, line - 1, col) });
856
852
  }
857
853
  else {
858
854
  this.historyBack();
@@ -869,7 +865,7 @@ class TuiRunner {
869
865
  const lines = value.split('\n');
870
866
  const { line, col } = lineColOfCursor(value, cursor);
871
867
  if (line < lines.length - 1) {
872
- this.dispatch({ type: 'setPrompt', value, cursor: cursorOfLineCol(value, line + 1, col) });
868
+ this.updatePrompt({ value, cursor: cursorOfLineCol(value, line + 1, col) });
873
869
  }
874
870
  else {
875
871
  this.historyForward();
@@ -877,21 +873,16 @@ class TuiRunner {
877
873
  }
878
874
  /** Home: move to the start of the current visual line (not whole buffer). */
879
875
  moveCursorLineHome() {
880
- if (this.state.overlay)
881
- return;
882
876
  const { value, cursor } = this.state.prompt;
883
877
  const { line } = lineColOfCursor(value, cursor);
884
- this.dispatch({ type: 'setPrompt', value, cursor: cursorOfLineCol(value, line, 0) });
878
+ this.updatePrompt({ value, cursor: cursorOfLineCol(value, line, 0) });
885
879
  }
886
880
  /** End: move to the end of the current visual line (not whole buffer). */
887
881
  moveCursorLineEnd() {
888
- if (this.state.overlay)
889
- return;
890
882
  const { value, cursor } = this.state.prompt;
891
883
  const { line } = lineColOfCursor(value, cursor);
892
884
  const lines = value.split('\n');
893
- this.dispatch({
894
- type: 'setPrompt',
885
+ this.updatePrompt({
895
886
  value,
896
887
  cursor: cursorOfLineCol(value, line, lines[line].length),
897
888
  });
@@ -900,11 +891,16 @@ class TuiRunner {
900
891
  const { value: input, cursor } = this.state.prompt;
901
892
  if (!input.trim() && !options.allowEmpty)
902
893
  return;
903
- this.dispatch({ type: 'setPrompt', value: '', cursor: 0 });
894
+ if (input.trim() === '/') {
895
+ this.syncPromptOverlay(input, cursor, true);
896
+ return;
897
+ }
898
+ this.updatePrompt({ value: '', cursor: 0 });
904
899
  try {
905
900
  const submission = this.handleLocalCommand(input) || this.options.onSubmit?.(input);
906
901
  if (submission === false) {
907
- this.dispatch({ type: 'setPrompt', value: input, cursor });
902
+ this.dismissedCommandToken = (0, pickers_1.getCommandToken)(input);
903
+ this.updatePrompt({ value: input, cursor });
908
904
  return;
909
905
  }
910
906
  this.history = (0, history_1.pushHistoryEntry)(this.history, input);
@@ -921,10 +917,6 @@ class TuiRunner {
921
917
  }
922
918
  handleLocalCommand(input) {
923
919
  const command = input.trim();
924
- if (command === '/redraw') {
925
- this.forceOwnedRedraw();
926
- return true;
927
- }
928
920
  if (command === '/queue') {
929
921
  const items = this.state.followupQueue.items;
930
922
  this.dispatch({
@@ -956,7 +948,7 @@ class TuiRunner {
956
948
  });
957
949
  return true;
958
950
  }
959
- if (command.startsWith('/tool-output')) {
951
+ if (/^\/tool-output(?:\s|$)/u.test(command)) {
960
952
  this.dispatch({
961
953
  type: 'setStatus',
962
954
  message: 'Usage: /tool-output adaptive|collapsed|full',
@@ -977,21 +969,30 @@ class TuiRunner {
977
969
  }
978
970
  updatePrompt(next) {
979
971
  this.dispatch({ type: 'setPrompt', value: next.value, cursor: next.cursor });
980
- this.syncPromptOverlay(next.value);
972
+ this.syncPromptOverlay(next.value, next.cursor);
981
973
  }
982
- syncPromptOverlay(value) {
983
- if (this.state.overlay?.type === 'shortcuts' && value.trim()) {
984
- this.dispatch({ type: 'closeOverlay' });
974
+ syncPromptOverlay(value, cursor, reopen = false) {
975
+ const token = (0, pickers_1.getCommandToken)(value);
976
+ if (reopen || token !== this.dismissedCommandToken)
977
+ this.dismissedCommandToken = undefined;
978
+ const overlay = this.state.overlay;
979
+ if (overlay?.type === 'shortcuts') {
980
+ if (value.trim())
981
+ this.dispatch({ type: 'closeOverlay' });
982
+ }
983
+ else if (overlay && overlay.type !== 'commands' && overlay.type !== 'files') {
984
+ return;
985
985
  }
986
- if (value.startsWith('/')) {
986
+ if (token && cursor > 0 && cursor <= token.length && token !== this.dismissedCommandToken) {
987
+ const query = token.slice(1);
987
988
  this.dispatch({
988
989
  type: 'showCommandPalette',
989
- query: value.slice(1),
990
- items: visibleTuiCommandItems(value),
990
+ query,
991
+ items: (0, pickers_1.visibleCommandItems)(query),
991
992
  });
992
993
  return;
993
994
  }
994
- const fileQuery = (0, pickers_1.getFileQuery)(value);
995
+ const fileQuery = cursor === value.length ? (0, pickers_1.getFileQuery)(value) : null;
995
996
  if (fileQuery) {
996
997
  this.dispatch({
997
998
  type: 'showFilePicker',
@@ -1006,27 +1007,22 @@ class TuiRunner {
1006
1007
  }
1007
1008
  }
1008
1009
  completeCommand(item, submitImmediately) {
1009
- if (!item)
1010
+ const { value } = this.state.prompt;
1011
+ const token = (0, pickers_1.getCommandToken)(value);
1012
+ if (!item || !token)
1010
1013
  return;
1011
- const command = (0, commands_1.getCommands)().find(candidate => candidate.name === item.value);
1012
- const needsArgs = item.value === 'tool-output' ||
1013
- Boolean(command?.argumentHint || command?.params?.some(param => param.required));
1014
- const value = `/${item.value}${needsArgs ? ' ' : ''}`;
1015
- const promptAlreadyMatchesCommand = this.state.prompt.value.trim() === `/${item.value}`;
1016
- const nextValue = promptAlreadyMatchesCommand ? `/${item.value}` : value;
1014
+ const command = (0, commands_1.findCommand)(item.value);
1015
+ const tail = value.slice(token.length);
1016
+ const separator = !submitImmediately && !tail && command?.argumentHint ? ' ' : '';
1017
+ this.dismissedCommandToken = item.label;
1017
1018
  this.dispatch({ type: 'closeOverlay' });
1018
- this.dispatch({ type: 'setPrompt', value: nextValue, cursor: nextValue.length });
1019
- if (submitImmediately && (!needsArgs || promptAlreadyMatchesCommand)) {
1019
+ this.dispatch({
1020
+ type: 'setPrompt',
1021
+ value: item.label + separator + tail,
1022
+ cursor: item.label.length + separator.length,
1023
+ });
1024
+ if (submitImmediately)
1020
1025
  this.submitPrompt();
1021
- }
1022
- }
1023
- hasRecognizedCommandArguments() {
1024
- const prompt = this.state.prompt.value.trim();
1025
- const match = prompt.match(/^\/([^\s]+)\s+\S/u);
1026
- if (!match)
1027
- return false;
1028
- const name = match[1].toLowerCase();
1029
- return (0, commands_1.findCommand)(name) !== undefined;
1030
1026
  }
1031
1027
  completeFile(item) {
1032
1028
  if (!item)
@@ -1421,9 +1417,6 @@ function insertAtCursor(value, cursor, text) {
1421
1417
  cursor: safeCursor + text.length,
1422
1418
  };
1423
1419
  }
1424
- function visibleTuiCommandItems(input) {
1425
- return (0, pickers_1.visibleCommandItems)(input);
1426
- }
1427
1420
  function safeFileName(value) {
1428
1421
  return value.replace(/[^a-zA-Z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '') || 'tool';
1429
1422
  }
@@ -123,6 +123,10 @@ export type TuiUiAction = {
123
123
  } | {
124
124
  type: 'replaceTranscript';
125
125
  entries: TranscriptEntry[];
126
+ } | {
127
+ type: 'startSession';
128
+ sessionId: string;
129
+ model?: string;
126
130
  } | {
127
131
  type: 'clearTranscript';
128
132
  } | {