@denizokcu/haze 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/README.md +9 -5
  3. package/dist/buildInfo.json +3 -3
  4. package/dist/cli/chat/busyIndicator.d.ts +11 -0
  5. package/dist/cli/chat/busyIndicator.js +34 -0
  6. package/dist/cli/chat/chatMetrics.d.ts +0 -1
  7. package/dist/cli/chat/chatMetrics.js +1 -7
  8. package/dist/cli/chat/followUpQueue.d.ts +11 -0
  9. package/dist/cli/chat/followUpQueue.js +38 -0
  10. package/dist/cli/chat/messages.d.ts +0 -22
  11. package/dist/cli/chat/messages.js +40 -85
  12. package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
  13. package/dist/cli/chat/sessionLifecycle.js +6 -1
  14. package/dist/cli/chat/sessionRecorder.d.ts +2 -0
  15. package/dist/cli/chat/sessionRecorder.js +6 -0
  16. package/dist/cli/chat/startupSequence.d.ts +29 -0
  17. package/dist/cli/chat/startupSequence.js +59 -0
  18. package/dist/cli/chat/transcriptPartition.d.ts +23 -0
  19. package/dist/cli/chat/transcriptPartition.js +78 -0
  20. package/dist/cli/chat/wizard/fieldTransitions.d.ts +38 -0
  21. package/dist/cli/chat/wizard/fieldTransitions.js +43 -0
  22. package/dist/cli/chat/wizard/lspHandlers.d.ts +4 -0
  23. package/dist/cli/chat/wizard/lspHandlers.js +85 -0
  24. package/dist/cli/chat/wizard/mcpHandlers.d.ts +8 -0
  25. package/dist/cli/chat/wizard/mcpHandlers.js +82 -0
  26. package/dist/cli/chat/wizard/providerHandlers.d.ts +12 -0
  27. package/dist/cli/chat/wizard/providerHandlers.js +420 -0
  28. package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +4 -0
  29. package/dist/cli/chat/wizard/sessionThemeHandlers.js +48 -0
  30. package/dist/cli/chat/wizard/skillsHandlers.d.ts +4 -0
  31. package/dist/cli/chat/wizard/skillsHandlers.js +125 -0
  32. package/dist/cli/chat/wizard/types.d.ts +63 -0
  33. package/dist/cli/chat/wizard/types.js +24 -0
  34. package/dist/cli/chat/wizard/uiState.d.ts +56 -0
  35. package/dist/cli/chat/wizard/uiState.js +15 -0
  36. package/dist/cli/chat/wizardDispatch.d.ts +11 -113
  37. package/dist/cli/chat/wizardDispatch.js +41 -815
  38. package/dist/cli/commands/chat.js +45 -108
  39. package/dist/cli/commands/formatters.d.ts +0 -3
  40. package/dist/cli/commands/formatters.js +0 -29
  41. package/dist/cli/commands/runCommand.d.ts +2 -0
  42. package/dist/cli/commands/runCommand.js +67 -4
  43. package/dist/cli/commands/streaming/assistantSegments.d.ts +19 -0
  44. package/dist/cli/commands/streaming/assistantSegments.js +48 -0
  45. package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -2
  46. package/dist/cli/commands/streaming/attemptOutcome.js +17 -7
  47. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +69 -8
  48. package/dist/cli/commands/streaming/goalCheckpoint.js +36 -1
  49. package/dist/cli/commands/streaming/goalSupervisor.d.ts +17 -2
  50. package/dist/cli/commands/streaming/goalSupervisor.js +62 -12
  51. package/dist/cli/commands/streaming/prepareStep.d.ts +35 -0
  52. package/dist/cli/commands/streaming/prepareStep.js +100 -0
  53. package/dist/cli/commands/streaming/recoverySlices.d.ts +15 -0
  54. package/dist/cli/commands/streaming/recoverySlices.js +29 -0
  55. package/dist/cli/commands/streaming/stallRecovery.d.ts +0 -1
  56. package/dist/cli/commands/streaming/stallRecovery.js +0 -4
  57. package/dist/cli/commands/streaming/streamLoop.js +9 -230
  58. package/dist/cli/commands/streaming/toolGroupRenderer.js +2 -1
  59. package/dist/cli/commands/streaming/toolPartHandlers.d.ts +19 -0
  60. package/dist/cli/commands/streaming/toolPartHandlers.js +95 -0
  61. package/dist/cli/commands/streaming.d.ts +4 -1
  62. package/dist/cli/commands/streaming.js +6 -21
  63. package/dist/cli/index.js +3 -1
  64. package/dist/config/providerPresets.d.ts +7 -0
  65. package/dist/config/providerPresets.js +195 -391
  66. package/dist/core/agent/completionController.d.ts +14 -7
  67. package/dist/core/agent/completionController.js +12 -6
  68. package/dist/core/agent/events.d.ts +12 -0
  69. package/dist/core/agent/goalPolicy.d.ts +4 -3
  70. package/dist/core/agent/goalPolicy.js +9 -4
  71. package/dist/core/agent/workState.d.ts +25 -15
  72. package/dist/core/agent/workState.js +71 -43
  73. package/dist/core/session/sessionSlimming.js +8 -0
  74. package/dist/core/session/sessionStore.d.ts +61 -1
  75. package/dist/core/session/sessionStore.js +115 -6
  76. package/dist/llm/hazeTools.d.ts +64 -208
  77. package/dist/llm/tools/taskTool.d.ts +64 -208
  78. package/dist/llm/tools/taskTool.js +22 -10
  79. package/dist/ui/components/TextInput.js +6 -67
  80. package/dist/ui/components/useInputSuggestions.d.ts +27 -0
  81. package/dist/ui/components/useInputSuggestions.js +98 -0
  82. package/dist/ui/theme.d.ts +8 -8
  83. package/dist/ui/theme.js +11 -12
  84. package/dist/ui/themes/registry.d.ts +5 -0
  85. package/dist/ui/themes/registry.js +436 -0
  86. package/dist/utils/format.d.ts +10 -0
  87. package/dist/utils/format.js +45 -0
  88. package/package.json +1 -1
  89. package/dist/ui/themes/af-magic.d.ts +0 -7
  90. package/dist/ui/themes/af-magic.js +0 -25
  91. package/dist/ui/themes/agnoster.d.ts +0 -10
  92. package/dist/ui/themes/agnoster.js +0 -40
  93. package/dist/ui/themes/bira.d.ts +0 -10
  94. package/dist/ui/themes/bira.js +0 -28
  95. package/dist/ui/themes/bureau.d.ts +0 -10
  96. package/dist/ui/themes/bureau.js +0 -28
  97. package/dist/ui/themes/clean.d.ts +0 -9
  98. package/dist/ui/themes/clean.js +0 -27
  99. package/dist/ui/themes/cloud.d.ts +0 -6
  100. package/dist/ui/themes/cloud.js +0 -24
  101. package/dist/ui/themes/dst.d.ts +0 -10
  102. package/dist/ui/themes/dst.js +0 -28
  103. package/dist/ui/themes/fishy.d.ts +0 -7
  104. package/dist/ui/themes/fishy.js +0 -25
  105. package/dist/ui/themes/index.d.ts +0 -8
  106. package/dist/ui/themes/index.js +0 -36
  107. package/dist/ui/themes/light.d.ts +0 -3
  108. package/dist/ui/themes/light.js +0 -21
  109. package/dist/ui/themes/purple.d.ts +0 -7
  110. package/dist/ui/themes/purple.js +0 -26
  111. package/dist/ui/themes/robbyrussell.d.ts +0 -8
  112. package/dist/ui/themes/robbyrussell.js +0 -26
  113. package/dist/ui/themes/solarized-dark.d.ts +0 -16
  114. package/dist/ui/themes/solarized-dark.js +0 -44
  115. package/dist/ui/themes/solarized-light.d.ts +0 -12
  116. package/dist/ui/themes/solarized-light.js +0 -40
  117. package/dist/ui/themes/steeef.d.ts +0 -11
  118. package/dist/ui/themes/steeef.js +0 -29
@@ -38,24 +38,15 @@ export declare const writeTasksTool: ({
38
38
  output: NoInfer<{
39
39
  ok: boolean;
40
40
  error: string;
41
- taskCount?: undefined;
42
- summary?: undefined;
43
- counts?: undefined;
44
41
  } | {
45
- ok: boolean;
46
- taskCount: number;
47
42
  summary: string;
48
- error?: undefined;
49
- counts?: undefined;
50
- } | {
51
- ok: boolean;
52
- taskCount: number;
53
- counts: {
43
+ counts?: {
54
44
  pending: number;
55
45
  in_progress: number;
56
46
  completed: number;
57
- };
58
- summary: string;
47
+ } | undefined;
48
+ ok: boolean;
49
+ taskCount: number;
59
50
  error?: undefined;
60
51
  }>;
61
52
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
@@ -63,24 +54,15 @@ export declare const writeTasksTool: ({
63
54
  outputSchema?: import("ai").FlexibleSchema<{
64
55
  ok: boolean;
65
56
  error: string;
66
- taskCount?: undefined;
67
- summary?: undefined;
68
- counts?: undefined;
69
57
  } | {
70
- ok: boolean;
71
- taskCount: number;
72
58
  summary: string;
73
- error?: undefined;
74
- counts?: undefined;
75
- } | {
76
- ok: boolean;
77
- taskCount: number;
78
- counts: {
59
+ counts?: {
79
60
  pending: number;
80
61
  in_progress: number;
81
62
  completed: number;
82
- };
83
- summary: string;
63
+ } | undefined;
64
+ ok: boolean;
65
+ taskCount: number;
84
66
  error?: undefined;
85
67
  }> | undefined;
86
68
  execute: import("ai").ToolExecuteFunction<{
@@ -91,24 +73,15 @@ export declare const writeTasksTool: ({
91
73
  }, {
92
74
  ok: boolean;
93
75
  error: string;
94
- taskCount?: undefined;
95
- summary?: undefined;
96
- counts?: undefined;
97
76
  } | {
98
- ok: boolean;
99
- taskCount: number;
100
77
  summary: string;
101
- error?: undefined;
102
- counts?: undefined;
103
- } | {
104
- ok: boolean;
105
- taskCount: number;
106
- counts: {
78
+ counts?: {
107
79
  pending: number;
108
80
  in_progress: number;
109
81
  completed: number;
110
- };
111
- summary: string;
82
+ } | undefined;
83
+ ok: boolean;
84
+ taskCount: number;
112
85
  error?: undefined;
113
86
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
114
87
  } & {
@@ -140,24 +113,15 @@ export declare const writeTasksTool: ({
140
113
  }, {
141
114
  ok: boolean;
142
115
  error: string;
143
- taskCount?: undefined;
144
- summary?: undefined;
145
- counts?: undefined;
146
116
  } | {
147
- ok: boolean;
148
- taskCount: number;
149
117
  summary: string;
150
- error?: undefined;
151
- counts?: undefined;
152
- } | {
153
- ok: boolean;
154
- taskCount: number;
155
- counts: {
118
+ counts?: {
156
119
  pending: number;
157
120
  in_progress: number;
158
121
  completed: number;
159
- };
160
- summary: string;
122
+ } | undefined;
123
+ ok: boolean;
124
+ taskCount: number;
161
125
  error?: undefined;
162
126
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
163
127
  }) | ({
@@ -200,24 +164,15 @@ export declare const writeTasksTool: ({
200
164
  output: NoInfer<{
201
165
  ok: boolean;
202
166
  error: string;
203
- taskCount?: undefined;
204
- summary?: undefined;
205
- counts?: undefined;
206
167
  } | {
207
- ok: boolean;
208
- taskCount: number;
209
168
  summary: string;
210
- error?: undefined;
211
- counts?: undefined;
212
- } | {
213
- ok: boolean;
214
- taskCount: number;
215
- counts: {
169
+ counts?: {
216
170
  pending: number;
217
171
  in_progress: number;
218
172
  completed: number;
219
- };
220
- summary: string;
173
+ } | undefined;
174
+ ok: boolean;
175
+ taskCount: number;
221
176
  error?: undefined;
222
177
  }>;
223
178
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
@@ -225,24 +180,15 @@ export declare const writeTasksTool: ({
225
180
  outputSchema?: import("ai").FlexibleSchema<{
226
181
  ok: boolean;
227
182
  error: string;
228
- taskCount?: undefined;
229
- summary?: undefined;
230
- counts?: undefined;
231
183
  } | {
232
- ok: boolean;
233
- taskCount: number;
234
184
  summary: string;
235
- error?: undefined;
236
- counts?: undefined;
237
- } | {
238
- ok: boolean;
239
- taskCount: number;
240
- counts: {
185
+ counts?: {
241
186
  pending: number;
242
187
  in_progress: number;
243
188
  completed: number;
244
- };
245
- summary: string;
189
+ } | undefined;
190
+ ok: boolean;
191
+ taskCount: number;
246
192
  error?: undefined;
247
193
  }> | undefined;
248
194
  execute: import("ai").ToolExecuteFunction<{
@@ -253,24 +199,15 @@ export declare const writeTasksTool: ({
253
199
  }, {
254
200
  ok: boolean;
255
201
  error: string;
256
- taskCount?: undefined;
257
- summary?: undefined;
258
- counts?: undefined;
259
202
  } | {
260
- ok: boolean;
261
- taskCount: number;
262
203
  summary: string;
263
- error?: undefined;
264
- counts?: undefined;
265
- } | {
266
- ok: boolean;
267
- taskCount: number;
268
- counts: {
204
+ counts?: {
269
205
  pending: number;
270
206
  in_progress: number;
271
207
  completed: number;
272
- };
273
- summary: string;
208
+ } | undefined;
209
+ ok: boolean;
210
+ taskCount: number;
274
211
  error?: undefined;
275
212
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
276
213
  } & {
@@ -302,24 +239,15 @@ export declare const writeTasksTool: ({
302
239
  }, {
303
240
  ok: boolean;
304
241
  error: string;
305
- taskCount?: undefined;
306
- summary?: undefined;
307
- counts?: undefined;
308
242
  } | {
309
- ok: boolean;
310
- taskCount: number;
311
243
  summary: string;
312
- error?: undefined;
313
- counts?: undefined;
314
- } | {
315
- ok: boolean;
316
- taskCount: number;
317
- counts: {
244
+ counts?: {
318
245
  pending: number;
319
246
  in_progress: number;
320
247
  completed: number;
321
- };
322
- summary: string;
248
+ } | undefined;
249
+ ok: boolean;
250
+ taskCount: number;
323
251
  error?: undefined;
324
252
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
325
253
  }) | ({
@@ -362,24 +290,15 @@ export declare const writeTasksTool: ({
362
290
  output: NoInfer<{
363
291
  ok: boolean;
364
292
  error: string;
365
- taskCount?: undefined;
366
- summary?: undefined;
367
- counts?: undefined;
368
293
  } | {
369
- ok: boolean;
370
- taskCount: number;
371
294
  summary: string;
372
- error?: undefined;
373
- counts?: undefined;
374
- } | {
375
- ok: boolean;
376
- taskCount: number;
377
- counts: {
295
+ counts?: {
378
296
  pending: number;
379
297
  in_progress: number;
380
298
  completed: number;
381
- };
382
- summary: string;
299
+ } | undefined;
300
+ ok: boolean;
301
+ taskCount: number;
383
302
  error?: undefined;
384
303
  }>;
385
304
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
@@ -387,24 +306,15 @@ export declare const writeTasksTool: ({
387
306
  outputSchema?: import("ai").FlexibleSchema<{
388
307
  ok: boolean;
389
308
  error: string;
390
- taskCount?: undefined;
391
- summary?: undefined;
392
- counts?: undefined;
393
309
  } | {
394
- ok: boolean;
395
- taskCount: number;
396
310
  summary: string;
397
- error?: undefined;
398
- counts?: undefined;
399
- } | {
400
- ok: boolean;
401
- taskCount: number;
402
- counts: {
311
+ counts?: {
403
312
  pending: number;
404
313
  in_progress: number;
405
314
  completed: number;
406
- };
407
- summary: string;
315
+ } | undefined;
316
+ ok: boolean;
317
+ taskCount: number;
408
318
  error?: undefined;
409
319
  }> | undefined;
410
320
  execute: import("ai").ToolExecuteFunction<{
@@ -415,24 +325,15 @@ export declare const writeTasksTool: ({
415
325
  }, {
416
326
  ok: boolean;
417
327
  error: string;
418
- taskCount?: undefined;
419
- summary?: undefined;
420
- counts?: undefined;
421
328
  } | {
422
- ok: boolean;
423
- taskCount: number;
424
329
  summary: string;
425
- error?: undefined;
426
- counts?: undefined;
427
- } | {
428
- ok: boolean;
429
- taskCount: number;
430
- counts: {
330
+ counts?: {
431
331
  pending: number;
432
332
  in_progress: number;
433
333
  completed: number;
434
- };
435
- summary: string;
334
+ } | undefined;
335
+ ok: boolean;
336
+ taskCount: number;
436
337
  error?: undefined;
437
338
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
438
339
  } & {
@@ -454,24 +355,15 @@ export declare const writeTasksTool: ({
454
355
  }, {
455
356
  ok: boolean;
456
357
  error: string;
457
- taskCount?: undefined;
458
- summary?: undefined;
459
- counts?: undefined;
460
358
  } | {
461
- ok: boolean;
462
- taskCount: number;
463
359
  summary: string;
464
- error?: undefined;
465
- counts?: undefined;
466
- } | {
467
- ok: boolean;
468
- taskCount: number;
469
- counts: {
360
+ counts?: {
470
361
  pending: number;
471
362
  in_progress: number;
472
363
  completed: number;
473
- };
474
- summary: string;
364
+ } | undefined;
365
+ ok: boolean;
366
+ taskCount: number;
475
367
  error?: undefined;
476
368
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
477
369
  }) | ({
@@ -514,24 +406,15 @@ export declare const writeTasksTool: ({
514
406
  output: NoInfer<{
515
407
  ok: boolean;
516
408
  error: string;
517
- taskCount?: undefined;
518
- summary?: undefined;
519
- counts?: undefined;
520
409
  } | {
521
- ok: boolean;
522
- taskCount: number;
523
410
  summary: string;
524
- error?: undefined;
525
- counts?: undefined;
526
- } | {
527
- ok: boolean;
528
- taskCount: number;
529
- counts: {
411
+ counts?: {
530
412
  pending: number;
531
413
  in_progress: number;
532
414
  completed: number;
533
- };
534
- summary: string;
415
+ } | undefined;
416
+ ok: boolean;
417
+ taskCount: number;
535
418
  error?: undefined;
536
419
  }>;
537
420
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
@@ -539,24 +422,15 @@ export declare const writeTasksTool: ({
539
422
  outputSchema?: import("ai").FlexibleSchema<{
540
423
  ok: boolean;
541
424
  error: string;
542
- taskCount?: undefined;
543
- summary?: undefined;
544
- counts?: undefined;
545
425
  } | {
546
- ok: boolean;
547
- taskCount: number;
548
426
  summary: string;
549
- error?: undefined;
550
- counts?: undefined;
551
- } | {
552
- ok: boolean;
553
- taskCount: number;
554
- counts: {
427
+ counts?: {
555
428
  pending: number;
556
429
  in_progress: number;
557
430
  completed: number;
558
- };
559
- summary: string;
431
+ } | undefined;
432
+ ok: boolean;
433
+ taskCount: number;
560
434
  error?: undefined;
561
435
  }> | undefined;
562
436
  execute: import("ai").ToolExecuteFunction<{
@@ -567,24 +441,15 @@ export declare const writeTasksTool: ({
567
441
  }, {
568
442
  ok: boolean;
569
443
  error: string;
570
- taskCount?: undefined;
571
- summary?: undefined;
572
- counts?: undefined;
573
444
  } | {
574
- ok: boolean;
575
- taskCount: number;
576
445
  summary: string;
577
- error?: undefined;
578
- counts?: undefined;
579
- } | {
580
- ok: boolean;
581
- taskCount: number;
582
- counts: {
446
+ counts?: {
583
447
  pending: number;
584
448
  in_progress: number;
585
449
  completed: number;
586
- };
587
- summary: string;
450
+ } | undefined;
451
+ ok: boolean;
452
+ taskCount: number;
588
453
  error?: undefined;
589
454
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
590
455
  } & {
@@ -606,24 +471,15 @@ export declare const writeTasksTool: ({
606
471
  }, {
607
472
  ok: boolean;
608
473
  error: string;
609
- taskCount?: undefined;
610
- summary?: undefined;
611
- counts?: undefined;
612
474
  } | {
613
- ok: boolean;
614
- taskCount: number;
615
475
  summary: string;
616
- error?: undefined;
617
- counts?: undefined;
618
- } | {
619
- ok: boolean;
620
- taskCount: number;
621
- counts: {
476
+ counts?: {
622
477
  pending: number;
623
478
  in_progress: number;
624
479
  completed: number;
625
- };
626
- summary: string;
480
+ } | undefined;
481
+ ok: boolean;
482
+ taskCount: number;
627
483
  error?: undefined;
628
484
  }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
629
485
  });
@@ -1,11 +1,21 @@
1
1
  import { tool } from 'ai';
2
2
  import { z } from 'zod';
3
3
  import { generateTaskId, saveTasks } from '../../core/tasks/taskStorage.js';
4
+ /**
5
+ * Size policy: task titles are never Zod-capped. A schema `.max()` turns an
6
+ * over-long string into a hard `AI_TypeValidationError` that rejects the whole
7
+ * call, so `execute` truncates titles instead.
8
+ */
9
+ const TITLE_CHARS = 200;
10
+ function truncate(value, max) {
11
+ const trimmed = value.trim();
12
+ return trimmed.length <= max ? trimmed : trimmed.slice(0, max);
13
+ }
4
14
  export const writeTasksTool = tool({
5
- description: 'Replace the task list for substantial work. Update at meaningful phase changes, blockers, and completion; pass the complete list.',
15
+ description: 'Replace the task list for substantial work. Update tasks at meaningful phase changes, blockers, and completion; pass the complete list.',
6
16
  inputSchema: z.object({
7
17
  tasks: z.array(z.object({
8
- title: z.string().max(200).describe('Short task description'),
18
+ title: z.string().min(1).describe('Short task description'),
9
19
  status: z.enum(['pending', 'in_progress', 'completed']).optional().describe('Task status (defaults to pending)'),
10
20
  })).describe('Complete task list. Replaces any existing tasks. Pass an empty array to clear.'),
11
21
  }),
@@ -14,28 +24,30 @@ export const writeTasksTool = tool({
14
24
  return { ok: false, error: 'Tasks must be an array. Pass an empty array to clear the list.' };
15
25
  }
16
26
  for (let i = 0; i < inputTasks.length; i++) {
17
- const title = inputTasks[i]?.title?.trim();
18
- if (!title)
27
+ if (!inputTasks[i]?.title?.trim())
19
28
  return { ok: false, error: `Task ${i + 1}: title cannot be empty.` };
20
- if (title.length > 200)
21
- return { ok: false, error: `Task ${i + 1}: title is too long (max 200 characters).` };
22
29
  }
23
30
  const now = new Date().toISOString();
24
31
  const tasks = inputTasks.map((input) => ({
25
32
  id: generateTaskId(),
26
- title: input.title.trim(),
33
+ title: truncate(input.title, TITLE_CHARS),
27
34
  status: input.status ?? 'pending',
28
35
  createdAt: now,
29
36
  updatedAt: now,
30
37
  }));
31
38
  await saveTasks(tasks);
32
- if (tasks.length === 0)
33
- return { ok: true, taskCount: 0, summary: 'Task list cleared.' };
34
39
  const counts = {
35
40
  pending: tasks.filter(t => t.status === 'pending').length,
36
41
  in_progress: tasks.filter(t => t.status === 'in_progress').length,
37
42
  completed: tasks.filter(t => t.status === 'completed').length,
38
43
  };
39
- return { ok: true, taskCount: tasks.length, counts, summary: `Tasks: ${counts.pending} pending, ${counts.in_progress} in progress, ${counts.completed} completed.` };
44
+ return {
45
+ ok: true,
46
+ taskCount: tasks.length,
47
+ ...(tasks.length > 0 ? { counts } : {}),
48
+ summary: tasks.length === 0
49
+ ? 'Task list cleared.'
50
+ : `Tasks: ${counts.pending} pending, ${counts.in_progress} in progress, ${counts.completed} completed.`,
51
+ };
40
52
  },
41
53
  });
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react';
3
3
  import { Box, Text, useInput } from 'ink';
4
4
  import { theme } from '../theme.js';
5
5
  import { compactPasteBlocksForDisplay, cursorPosition, displayCursorForValueCursor, lineCount, normalizeLineEndings, updatePasteBlocksForReplacement, valueCursorForDisplayCursor, wrapDisplayValue, } from '../inputBuffer.js';
6
- import { detectMentionAtCursor } from '../../cli/chat/fileMentionSuggestions.js';
6
+ import { useInputSuggestions } from './useInputSuggestions.js';
7
7
  const COMPACT_PASTE_MIN_LINES = 4;
8
8
  const CTRL_ENTER_ESCAPE_INPUTS = new Set(['\u001B[13;5u', '\u001B[13;5~']);
9
9
  export function shouldInsertNewline(input, key) {
@@ -15,10 +15,6 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
15
15
  const [value, setValue] = useState('');
16
16
  const [cursor, setCursor] = useState(0);
17
17
  const [pasteBlocks, setPasteBlocks] = useState([]);
18
- const [selectedSuggestionIndex, setSelectedSuggestionIndex] = useState(0);
19
- const [mentionContext, setMentionContext] = useState();
20
- const [mentionSuggestions, setMentionSuggestions] = useState([]);
21
- const [mentionSelectedIndex, setMentionSelectedIndex] = useState(0);
22
18
  const history = useRef(historyItems);
23
19
  const historyIndex = useRef(null);
24
20
  const draft = useRef('');
@@ -32,19 +28,19 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
32
28
  setValue('');
33
29
  setCursor(0);
34
30
  setPasteBlocks([]);
35
- setSelectedSuggestionIndex(0);
36
31
  historyIndex.current = null;
37
32
  draft.current = '';
38
33
  nextPasteId.current = 1;
39
34
  }
40
35
  }, [disabled]);
36
+ const suggestionLayers = useInputSuggestions({ value, cursor, suggestions, suggestionMode, mask, getMentionSuggestions });
37
+ const { detectedMention, inMentionMode, filteredSuggestions, mentionList, activeMentionIndex, activeSuggestionIndex, activeSuggestion } = suggestionLayers;
41
38
  function setInput(next, nextCursor = next.length, nextPasteBlocks = []) {
42
39
  preferredColumn.current = null;
43
40
  setValue(next);
44
41
  setCursor(Math.max(0, Math.min(nextCursor, next.length)));
45
42
  setPasteBlocks(nextPasteBlocks);
46
- setSelectedSuggestionIndex(0);
47
- setMentionSelectedIndex(0);
43
+ suggestionLayers.resetSelection();
48
44
  }
49
45
  function replaceInput(start, end, inserted) {
50
46
  const normalizedInserted = normalizeLineEndings(inserted);
@@ -61,45 +57,6 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
61
57
  historyIndex.current = index;
62
58
  setInput(history.current[index] ?? '');
63
59
  }
64
- const suggestionQuery = !mask && (suggestionMode === 'always' || value.startsWith('/'))
65
- ? (suggestionMode === 'always' ? value : value.slice(1)).toLowerCase()
66
- : undefined;
67
- const filteredSuggestions = suggestionQuery == null ? [] : suggestions
68
- .filter(suggestion => {
69
- const suggestionValue = suggestionMode === 'always' ? suggestion.value : suggestion.value.slice(1);
70
- return suggestionValue.toLowerCase().includes(suggestionQuery) || suggestion.description?.toLowerCase().includes(suggestionQuery);
71
- })
72
- .slice(0, 20);
73
- // `@token` mention detection — only in chat mode (slash) so wizard pickers
74
- // never grab `@`-prefixed tokens. Detection is sync; suggestion fetch is
75
- // async with cancellation so fast typing does not race stale results.
76
- const detectedMention = !mask && suggestionMode === 'slash' && !value.startsWith('/') && getMentionSuggestions
77
- ? detectMentionAtCursor(value, cursor)
78
- : undefined;
79
- useEffect(() => {
80
- setMentionContext(detectedMention);
81
- }, [detectedMention?.token, detectedMention?.start, detectedMention?.end]);
82
- useEffect(() => {
83
- if (!mentionContext || !getMentionSuggestions) {
84
- if (mentionSuggestions.length > 0)
85
- setMentionSuggestions([]);
86
- return;
87
- }
88
- let cancelled = false;
89
- Promise.resolve(getMentionSuggestions(mentionContext.token))
90
- .then(results => { if (!cancelled) {
91
- setMentionSuggestions(results);
92
- setMentionSelectedIndex(0);
93
- } })
94
- .catch(() => { if (!cancelled)
95
- setMentionSuggestions([]); });
96
- return () => { cancelled = true; };
97
- }, [mentionContext?.token, mentionContext?.start, mentionContext?.end]);
98
- const inMentionMode = !!detectedMention;
99
- const mentionList = inMentionMode ? mentionSuggestions : [];
100
- const activeMentionIndex = Math.min(mentionSelectedIndex, Math.max(0, mentionList.length - 1));
101
- const activeSuggestionIndex = Math.min(selectedSuggestionIndex, Math.max(0, filteredSuggestions.length - 1));
102
- const activeSuggestion = inMentionMode ? mentionList[activeMentionIndex] : filteredSuggestions[activeSuggestionIndex];
103
60
  const displayValue = mask ? '•'.repeat(value.length) : compactPasteBlocksForDisplay(value, pasteBlocks);
104
61
  const displayCursor = mask ? cursor : displayCursorForValueCursor(pasteBlocks, cursor);
105
62
  const inputWidth = Math.max(1, width - 2);
@@ -196,19 +153,10 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
196
153
  return;
197
154
  }
198
155
  if (key.upArrow) {
199
- if (inMentionMode && mentionList.length > 0) {
200
- if (activeMentionIndex > 0)
201
- setMentionSelectedIndex(current => Math.max(0, current - 1));
202
- return;
203
- }
204
- if (filteredSuggestions.length > 0 && activeSuggestionIndex > 0) {
205
- setSelectedSuggestionIndex(current => Math.max(0, current - 1));
156
+ if (suggestionLayers.moveSelection(-1))
206
157
  return;
207
- }
208
158
  if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(-1))
209
159
  return;
210
- if (inMentionMode)
211
- return; // no history navigation while completing
212
160
  preferredColumn.current = null;
213
161
  if (history.current.length === 0)
214
162
  return;
@@ -222,19 +170,10 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
222
170
  return;
223
171
  }
224
172
  if (key.downArrow) {
225
- if (inMentionMode && mentionList.length > 0) {
226
- if (activeMentionIndex < mentionList.length - 1)
227
- setMentionSelectedIndex(current => Math.min(mentionList.length - 1, current + 1));
228
- return;
229
- }
230
- if (filteredSuggestions.length > 0 && activeSuggestionIndex < filteredSuggestions.length - 1) {
231
- setSelectedSuggestionIndex(current => Math.min(filteredSuggestions.length - 1, current + 1));
173
+ if (suggestionLayers.moveSelection(1))
232
174
  return;
233
- }
234
175
  if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(1))
235
176
  return;
236
- if (inMentionMode)
237
- return;
238
177
  preferredColumn.current = null;
239
178
  if (historyIndex.current === null)
240
179
  return;
@@ -0,0 +1,27 @@
1
+ import { type MentionContext } from '../../cli/chat/fileMentionSuggestions.js';
2
+ import type { MentionSuggestionsProvider, TextInputSuggestion } from './TextInput.js';
3
+ /**
4
+ * The suggestion engine behind TextInput, extracted as a standalone hook:
5
+ * two composable layers — slash-command filtering (sync, prefix/substring
6
+ * match over the caller's suggestion list) and `@token` mention completion
7
+ * (async fetch with cancellation so fast typing never races stale results) —
8
+ * plus the shared selection state the keyboard handler moves through.
9
+ */
10
+ export declare function useInputSuggestions({ value, cursor, suggestions, suggestionMode, mask, getMentionSuggestions }: {
11
+ value: string;
12
+ cursor: number;
13
+ suggestions: TextInputSuggestion[];
14
+ suggestionMode: 'slash' | 'always';
15
+ mask?: boolean;
16
+ getMentionSuggestions?: MentionSuggestionsProvider;
17
+ }): {
18
+ detectedMention: MentionContext | undefined;
19
+ inMentionMode: boolean;
20
+ filteredSuggestions: TextInputSuggestion[];
21
+ mentionList: TextInputSuggestion[];
22
+ activeMentionIndex: number;
23
+ activeSuggestionIndex: number;
24
+ activeSuggestion: TextInputSuggestion;
25
+ resetSelection: () => void;
26
+ moveSelection: (direction: -1 | 1) => boolean;
27
+ };