opencode-copilot-delegate 0.10.0 → 0.11.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.
@@ -1,5 +1,4 @@
1
1
  import { describe, expect, it } from 'bun:test'
2
- import type { TuiDialogProps } from '@opencode-ai/plugin/tui'
3
2
  import { type JSX, testRender } from '@opentui/solid'
4
3
 
5
4
  type TaskStatus = 'running' | 'cancelling' | 'complete' | 'failed' | 'cancelled'
@@ -25,12 +24,11 @@ type ModalListClock = {
25
24
  }
26
25
 
27
26
  type ModalListProps = {
28
- Dialog: (props: TuiDialogProps) => JSX.Element
29
27
  rpc: {
30
28
  tasksList(): Promise<TasksListResponse>
31
29
  }
32
30
  onClose: () => void
33
- onCancelTask?: (task: TaskRow) => void
31
+ onLoadError?: (error: unknown) => void
34
32
  clock?: ModalListClock
35
33
  }
36
34
 
@@ -159,20 +157,6 @@ function createDeferred<T>(): Deferred<T> {
159
157
  }
160
158
  }
161
159
 
162
- function createDialogStub() {
163
- let onClose: (() => void) | undefined
164
-
165
- const Dialog = (props: TuiDialogProps) => {
166
- onClose = props.onClose
167
- return <box flexDirection="column">{props.children}</box>
168
- }
169
-
170
- return {
171
- Dialog,
172
- getOnClose: () => onClose,
173
- }
174
- }
175
-
176
160
  function makeTask(taskId: string, overrides: Partial<TaskRow> = {}): TaskRow {
177
161
  return {
178
162
  taskId,
@@ -243,13 +227,11 @@ describe('modal list', () => {
243
227
  it('renders a loading state before tasksList resolves', async () => {
244
228
  const ModalList = await loadModalList()
245
229
  const deferred = createDeferred<TasksListResponse>()
246
- const dialog = createDialogStub()
247
230
  let calls = 0
248
231
 
249
232
  const { renderOnce, captureCharFrame } = await testRender(
250
233
  () => (
251
234
  <ModalList
252
- Dialog={dialog.Dialog}
253
235
  rpc={{
254
236
  tasksList: () => {
255
237
  calls += 1
@@ -272,12 +254,10 @@ describe('modal list', () => {
272
254
 
273
255
  it('renders an empty state after tasksList returns no tasks', async () => {
274
256
  const ModalList = await loadModalList()
275
- const dialog = createDialogStub()
276
257
 
277
258
  const { renderOnce, captureCharFrame, renderer } = await testRender(
278
259
  () => (
279
260
  <ModalList
280
- Dialog={dialog.Dialog}
281
261
  rpc={{ tasksList: async () => ({ tasks: [] }) }}
282
262
  onClose={() => {}}
283
263
  />
@@ -301,20 +281,25 @@ describe('modal list', () => {
301
281
  expect(frame).toContain('Esc close')
302
282
  })
303
283
 
304
- it('renders an error state with the rpc rejection message', async () => {
284
+ it('reports load errors instead of rendering an inline error state', async () => {
305
285
  const ModalList = await loadModalList()
306
- const dialog = createDialogStub()
286
+ const loadErrors: unknown[] = []
287
+ let closeCalls = 0
307
288
 
308
289
  const { renderOnce, captureCharFrame, renderer } = await testRender(
309
290
  () => (
310
291
  <ModalList
311
- Dialog={dialog.Dialog}
312
292
  rpc={{
313
293
  tasksList: async () => {
314
294
  throw new Error('rpc exploded on localhost')
315
295
  },
316
296
  }}
317
- onClose={() => {}}
297
+ onClose={() => {
298
+ closeCalls += 1
299
+ }}
300
+ onLoadError={(error: unknown) => {
301
+ loadErrors.push(error)
302
+ }}
318
303
  />
319
304
  ),
320
305
  { width: 120, height: 20, useThread: false },
@@ -326,18 +311,48 @@ describe('modal list', () => {
326
311
  renderOnce,
327
312
  idle: () => renderer.idle(),
328
313
  captureCharFrame,
329
- includes: 'Status unavailable.',
314
+ includes: 'Loading delegations…',
330
315
  })
331
- expect(frame).toContain('Status unavailable.')
332
- expect(frame).toContain('rpc exploded on localhost')
316
+ expect(frame).toContain('Loading delegations…')
333
317
  expect(frame).toContain('Esc close')
318
+ expect(closeCalls).toBe(0)
319
+ expect(loadErrors).toHaveLength(1)
320
+ expect(loadErrors[0]).toBeInstanceOf(Error)
321
+ expect((loadErrors[0] as Error).message).toBe('rpc exploded on localhost')
334
322
  })
335
323
 
336
- it('renders running rows with focused styling, defaults, and key navigation', async () => {
324
+ it('reports load errors without closing first when an alert handler is present', async () => {
325
+ const ModalList = await loadModalList()
326
+ const callOrder: string[] = []
327
+
328
+ const { renderOnce, renderer } = await testRender(
329
+ () => (
330
+ <ModalList
331
+ rpc={{
332
+ tasksList: async () => {
333
+ throw new Error('rpc exploded on localhost')
334
+ },
335
+ }}
336
+ onClose={() => {
337
+ callOrder.push('close')
338
+ }}
339
+ onLoadError={() => {
340
+ callOrder.push('error')
341
+ }}
342
+ />
343
+ ),
344
+ { width: 120, height: 20, useThread: false },
345
+ )
346
+
347
+ await renderOnce()
348
+ await settle(renderOnce, () => renderer.idle())
349
+
350
+ expect(callOrder).toEqual(['error'])
351
+ })
352
+
353
+ it('renders running rows as a read-only status list', async () => {
337
354
  const ModalList = await loadModalList()
338
- const dialog = createDialogStub()
339
355
  const clock = new TestClock(2_000)
340
- const cancelled: TaskRow[] = []
341
356
  const tasks = [
342
357
  makeTask('cpl_alpha', {
343
358
  startedAt: 0,
@@ -357,14 +372,12 @@ describe('modal list', () => {
357
372
  }),
358
373
  ]
359
374
 
360
- const { renderOnce, captureCharFrame, captureSpans, mockInput, renderer } =
375
+ const { renderOnce, captureCharFrame, captureSpans, renderer } =
361
376
  await testRender(
362
377
  () => (
363
378
  <ModalList
364
- Dialog={dialog.Dialog}
365
379
  rpc={{ tasksList: async () => ({ tasks }) }}
366
380
  onClose={() => {}}
367
- onCancelTask={(task) => cancelled.push(task)}
368
381
  clock={clock.adapter()}
369
382
  />
370
383
  ),
@@ -380,7 +393,9 @@ describe('modal list', () => {
380
393
  includes: '3 running · 0 recent',
381
394
  })
382
395
  expect(frame).toContain('3 running · 0 recent')
383
- expect(frame).toContain('↑↓ navigate · c cancel · Esc close')
396
+ expect(frame).toContain('Esc close')
397
+ expect(frame).not.toContain('navigate')
398
+ expect(frame).not.toContain('c cancel')
384
399
  expect(frame).toContain('cpl_alpha')
385
400
  expect(frame).toContain('cpl_beta')
386
401
  expect(frame).toContain('cpl_gamma')
@@ -391,47 +406,18 @@ describe('modal list', () => {
391
406
  expect(frame).toContain('5 calls')
392
407
  expect(frame).toContain('0s')
393
408
 
394
- let spans = captureSpans()
409
+ const spans = captureSpans()
395
410
  const firstLine = findLineAttributesContaining(spans, 'cpl_alpha')
396
411
  expect(firstLine).toBeDefined()
397
- expect(lineHasInverse(firstLine)).toBe(true)
398
-
399
- mockInput.pressKey('j')
400
- await settle(renderOnce, () => renderer.idle())
401
- expect(captureCharFrame()).toContain('cpl_beta')
402
- spans = captureSpans()
403
- const secondLine = findLineAttributesContaining(spans, 'cpl_beta')
404
- expect(secondLine).toBeDefined()
405
- expect(lineHasInverse(secondLine)).toBe(true)
406
-
407
- mockInput.pressArrow('up')
408
- await settle(renderOnce, () => renderer.idle())
409
- spans = captureSpans()
410
- const wrappedLine = findLineAttributesContaining(spans, 'cpl_alpha')
411
- expect(wrappedLine).toBeDefined()
412
- expect(lineHasInverse(wrappedLine)).toBe(true)
413
-
414
- mockInput.pressKey('k')
415
- await settle(renderOnce, () => renderer.idle())
416
- spans = captureSpans()
417
- const lastLine = findLineAttributesContaining(spans, 'cpl_gamma')
418
- expect(lastLine).toBeDefined()
419
- expect(lineHasInverse(lastLine)).toBe(true)
420
-
421
- mockInput.pressKey('c')
422
- await settle(renderOnce, () => renderer.idle())
423
-
424
- expect(cancelled).toEqual([tasks[2]])
412
+ expect(lineHasInverse(firstLine)).toBe(false)
425
413
  })
426
414
 
427
415
  it('keeps cancelling tasks visible until runtime removes them', async () => {
428
416
  const ModalList = await loadModalList()
429
- const dialog = createDialogStub()
430
417
 
431
418
  const { renderOnce, captureCharFrame, renderer } = await testRender(
432
419
  () => (
433
420
  <ModalList
434
- Dialog={dialog.Dialog}
435
421
  rpc={{
436
422
  tasksList: async () => ({
437
423
  tasks: [makeTask('cpl_cancelling', { status: 'cancelling' })],
@@ -459,13 +445,11 @@ describe('modal list', () => {
459
445
 
460
446
  it('updates elapsed time from an injected clock without waiting on wall time', async () => {
461
447
  const ModalList = await loadModalList()
462
- const dialog = createDialogStub()
463
448
  const clock = new TestClock(0)
464
449
 
465
450
  const { renderOnce, captureCharFrame, renderer } = await testRender(
466
451
  () => (
467
452
  <ModalList
468
- Dialog={dialog.Dialog}
469
453
  rpc={{
470
454
  tasksList: async () => ({
471
455
  tasks: [
@@ -499,13 +483,11 @@ describe('modal list', () => {
499
483
 
500
484
  it('clears its refresh interval on teardown', async () => {
501
485
  const ModalList = await loadModalList()
502
- const dialog = createDialogStub()
503
486
  const clock = new TestClock(0)
504
487
 
505
488
  const { renderer, renderOnce } = await testRender(
506
489
  () => (
507
490
  <ModalList
508
- Dialog={dialog.Dialog}
509
491
  rpc={{
510
492
  tasksList: async () => ({
511
493
  tasks: [makeTask('cpl_cleanup')],
@@ -1,6 +1,5 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
 
3
- import type { TuiPluginApi } from '@opencode-ai/plugin/tui'
4
3
  import {
5
4
  type KeyEvent,
6
5
  TextAttributes,
@@ -12,7 +11,6 @@ import type { RpcClient } from '../rpc-client'
12
11
  import type { ModalListTask } from './row'
13
12
 
14
13
  type ConfirmCardProps = {
15
- Dialog: TuiPluginApi['ui']['Dialog']
16
14
  task: ModalListTask
17
15
  rpc: Pick<RpcClient, 'tasksCancel'>
18
16
  onConfirm: () => void
@@ -78,7 +76,6 @@ function updateText(
78
76
  }
79
77
 
80
78
  export function ConfirmCard(props: ConfirmCardProps) {
81
- const Dialog = props.Dialog
82
79
  const renderer = useRenderer()
83
80
  const title = `Cancel Copilot delegation ${props.task.taskId}?`
84
81
  const state: { value: ConfirmState } = {
@@ -125,19 +122,6 @@ export function ConfirmCard(props: ConfirmCardProps) {
125
122
  renderer.requestRender()
126
123
  }
127
124
 
128
- const closeToList = () => {
129
- if (state.value.kind === 'error') {
130
- props.onDismissAfterError()
131
- return
132
- }
133
-
134
- if (state.value.busy) {
135
- return
136
- }
137
-
138
- props.onCancel()
139
- }
140
-
141
125
  const confirmCancel = async () => {
142
126
  if (state.value.kind !== 'confirm' || state.value.busy) {
143
127
  return
@@ -202,12 +186,6 @@ export function ConfirmCard(props: ConfirmCardProps) {
202
186
  }
203
187
 
204
188
  const handleKeyPress = (key: KeyEvent) => {
205
- if (matchesKey(key, 'escape')) {
206
- key.preventDefault()
207
- closeToList()
208
- return
209
- }
210
-
211
189
  if (state.value.kind === 'confirm' && !state.value.busy) {
212
190
  if (isLeftKey(key)) {
213
191
  key.preventDefault()
@@ -235,41 +213,39 @@ export function ConfirmCard(props: ConfirmCardProps) {
235
213
  })
236
214
 
237
215
  return (
238
- <Dialog onClose={closeToList} size="medium">
239
- <box flexDirection="column" gap={1} padding={1}>
240
- <text>{title}</text>
241
- {/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI text nodes handle terminal mouse events directly. */}
242
- <text
243
- ref={confirmText}
244
- attributes={TextAttributes.INVERSE}
245
- onMouseUp={() => {
246
- focusConfirm()
247
- void confirmCancel()
248
- }}
249
- >
250
- Cancel Task
251
- </text>
252
- {/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI text nodes handle terminal mouse events directly. */}
253
- <text
254
- ref={cancelText}
255
- onMouseUp={() => {
256
- focusCancel()
257
- closeToList()
258
- }}
259
- >
260
- Keep Running
261
- </text>
262
- <text ref={errorText} visible={false} />
263
- {/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI text nodes handle terminal mouse events directly. */}
264
- <text
265
- ref={dismissText}
266
- visible={false}
267
- onMouseUp={() => {
268
- props.onDismissAfterError()
269
- }}
270
- />
271
- </box>
272
- </Dialog>
216
+ <box flexDirection="column" gap={1} padding={1} width="100%">
217
+ <text>{title}</text>
218
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI text nodes handle terminal mouse events directly. */}
219
+ <text
220
+ ref={confirmText}
221
+ attributes={TextAttributes.INVERSE}
222
+ onMouseUp={() => {
223
+ focusConfirm()
224
+ void confirmCancel()
225
+ }}
226
+ >
227
+ Cancel Task
228
+ </text>
229
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI text nodes handle terminal mouse events directly. */}
230
+ <text
231
+ ref={cancelText}
232
+ onMouseUp={() => {
233
+ focusCancel()
234
+ props.onCancel()
235
+ }}
236
+ >
237
+ Keep Running
238
+ </text>
239
+ <text ref={errorText} visible={false} />
240
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI text nodes handle terminal mouse events directly. */}
241
+ <text
242
+ ref={dismissText}
243
+ visible={false}
244
+ onMouseUp={() => {
245
+ props.onDismissAfterError()
246
+ }}
247
+ />
248
+ </box>
273
249
  )
274
250
  }
275
251