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.
- package/CHANGELOG.md +22 -0
- package/dist/index.js +21 -16
- package/dist/runtime/plugin-singleton.d.ts +51 -20
- package/dist/tui/components/confirm-card.d.ts +0 -2
- package/dist/tui/components/modal-list.d.ts +1 -4
- package/dist/tui/index.js +106 -433
- package/package.json +6 -6
- package/src/tui/__tests__/confirm-card.test.tsx +68 -52
- package/src/tui/__tests__/index.test.ts +84 -53
- package/src/tui/__tests__/modal-list.test.tsx +52 -70
- package/src/tui/components/confirm-card.tsx +33 -57
- package/src/tui/components/modal-list.tsx +43 -200
- package/src/tui/index.tsx +22 -18
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
|
|
3
|
-
import type { TuiPluginApi } from '@opencode-ai/plugin/tui'
|
|
4
3
|
import {
|
|
5
4
|
type BoxRenderable,
|
|
6
|
-
type KeyEvent,
|
|
7
5
|
TextAttributes,
|
|
8
6
|
type TextRenderable,
|
|
9
7
|
} from '@opentui/core'
|
|
@@ -16,10 +14,6 @@ const LOADING_HEADER = 'Loading delegations…'
|
|
|
16
14
|
const EMPTY_STATE_TITLE = 'No Copilot delegations are running.'
|
|
17
15
|
const EMPTY_STATE_HINT =
|
|
18
16
|
'Start one with the copilot_delegate tool, then reopen /copilot-status.'
|
|
19
|
-
const ERROR_STATE_TITLE = 'The Copilot delegate TUI plugin is not responding.'
|
|
20
|
-
const ERROR_STATE_HINT =
|
|
21
|
-
'Try reloading the plugin (or run /copilot-status again).'
|
|
22
|
-
|
|
23
17
|
export type ModalListClock = {
|
|
24
18
|
now(): number
|
|
25
19
|
setInterval(fn: () => void, delayMs: number): unknown
|
|
@@ -27,18 +21,14 @@ export type ModalListClock = {
|
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
type ModalListProps = {
|
|
30
|
-
Dialog: TuiPluginApi['ui']['Dialog']
|
|
31
24
|
rpc: Pick<RpcClient, 'tasksList'>
|
|
32
25
|
onClose: () => void
|
|
33
|
-
|
|
26
|
+
onLoadError?: (error: unknown) => void
|
|
34
27
|
initialTaskId?: string
|
|
35
28
|
clock?: ModalListClock
|
|
36
29
|
}
|
|
37
30
|
|
|
38
|
-
type ViewState =
|
|
39
|
-
| { kind: 'loading' }
|
|
40
|
-
| { kind: 'ready'; tasks: ModalListTask[] }
|
|
41
|
-
| { kind: 'error'; message: string }
|
|
31
|
+
type ViewState = { kind: 'loading' } | { kind: 'ready'; tasks: ModalListTask[] }
|
|
42
32
|
|
|
43
33
|
const defaultClock: ModalListClock = {
|
|
44
34
|
now: () => Date.now(),
|
|
@@ -48,14 +38,6 @@ const defaultClock: ModalListClock = {
|
|
|
48
38
|
},
|
|
49
39
|
}
|
|
50
40
|
|
|
51
|
-
function errorMessage(error: unknown): string {
|
|
52
|
-
if (error instanceof Error && error.message.trim().length > 0) {
|
|
53
|
-
return error.message.trim()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return 'Unknown RPC error.'
|
|
57
|
-
}
|
|
58
|
-
|
|
59
41
|
function updateText(
|
|
60
42
|
node: TextRenderable | undefined,
|
|
61
43
|
content: string,
|
|
@@ -80,22 +62,12 @@ function updateBoxVisibility(
|
|
|
80
62
|
node.visible = visible
|
|
81
63
|
}
|
|
82
64
|
|
|
83
|
-
function matchesKey(key: KeyEvent, expected: string): boolean {
|
|
84
|
-
return (
|
|
85
|
-
key.name === expected || key.sequence === expected || key.raw === expected
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
65
|
type ModalRefs = {
|
|
90
66
|
headerText?: TextRenderable
|
|
91
67
|
footerText?: TextRenderable
|
|
92
68
|
emptyBox?: BoxRenderable
|
|
93
69
|
emptyLineOne?: TextRenderable
|
|
94
70
|
emptyLineTwo?: TextRenderable
|
|
95
|
-
errorBox?: BoxRenderable
|
|
96
|
-
errorLineOne?: TextRenderable
|
|
97
|
-
errorLineTwo?: TextRenderable
|
|
98
|
-
errorLineThree?: TextRenderable
|
|
99
71
|
rowsBox?: BoxRenderable
|
|
100
72
|
rowTexts: Array<TextRenderable | undefined>
|
|
101
73
|
}
|
|
@@ -104,25 +76,12 @@ function renderLoadingState(refs: ModalRefs) {
|
|
|
104
76
|
updateText(refs.headerText, LOADING_HEADER)
|
|
105
77
|
updateText(refs.footerText, 'Esc close')
|
|
106
78
|
updateBoxVisibility(refs.emptyBox, false)
|
|
107
|
-
updateBoxVisibility(refs.errorBox, false)
|
|
108
|
-
updateBoxVisibility(refs.rowsBox, false)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function renderErrorState(refs: ModalRefs, message: string) {
|
|
112
|
-
updateText(refs.headerText, 'Status unavailable.')
|
|
113
|
-
updateText(refs.footerText, 'Esc close')
|
|
114
|
-
updateBoxVisibility(refs.emptyBox, false)
|
|
115
|
-
updateBoxVisibility(refs.errorBox, true)
|
|
116
79
|
updateBoxVisibility(refs.rowsBox, false)
|
|
117
|
-
updateText(refs.errorLineOne, ERROR_STATE_TITLE)
|
|
118
|
-
updateText(refs.errorLineTwo, message)
|
|
119
|
-
updateText(refs.errorLineThree, ERROR_STATE_HINT)
|
|
120
80
|
}
|
|
121
81
|
|
|
122
82
|
function renderEmptyView(refs: ModalRefs) {
|
|
123
83
|
updateText(refs.headerText, '0 running · 0 recent')
|
|
124
84
|
updateText(refs.footerText, 'Esc close')
|
|
125
|
-
updateBoxVisibility(refs.errorBox, false)
|
|
126
85
|
updateBoxVisibility(refs.emptyBox, true)
|
|
127
86
|
updateBoxVisibility(refs.rowsBox, false)
|
|
128
87
|
updateText(refs.emptyLineOne, EMPTY_STATE_TITLE)
|
|
@@ -132,12 +91,10 @@ function renderEmptyView(refs: ModalRefs) {
|
|
|
132
91
|
function renderTaskRows(
|
|
133
92
|
refs: ModalRefs,
|
|
134
93
|
tasks: ModalListTask[],
|
|
135
|
-
focusedIndex: number,
|
|
136
94
|
nowMs: number,
|
|
137
95
|
) {
|
|
138
96
|
updateText(refs.headerText, `${tasks.length} running · 0 recent`)
|
|
139
|
-
updateText(refs.footerText, '
|
|
140
|
-
updateBoxVisibility(refs.errorBox, false)
|
|
97
|
+
updateText(refs.footerText, 'Esc close')
|
|
141
98
|
updateBoxVisibility(refs.emptyBox, false)
|
|
142
99
|
updateBoxVisibility(refs.rowsBox, true)
|
|
143
100
|
|
|
@@ -150,42 +107,15 @@ function renderTaskRows(
|
|
|
150
107
|
|
|
151
108
|
rowText.visible = task !== undefined
|
|
152
109
|
rowText.content = task ? formatRowText(task, nowMs) : ''
|
|
153
|
-
rowText.attributes =
|
|
154
|
-
task && index === focusedIndex
|
|
155
|
-
? TextAttributes.INVERSE
|
|
156
|
-
: TextAttributes.NONE
|
|
110
|
+
rowText.attributes = TextAttributes.NONE
|
|
157
111
|
}
|
|
158
112
|
}
|
|
159
113
|
|
|
160
|
-
function isReadyState(
|
|
161
|
-
state: ViewState,
|
|
162
|
-
): state is Extract<ViewState, { kind: 'ready' }> {
|
|
163
|
-
return state.kind === 'ready'
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function previousIndex(current: number, total: number): number {
|
|
167
|
-
return current === 0 ? total - 1 : current - 1
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function nextIndex(current: number, total: number): number {
|
|
171
|
-
return current === total - 1 ? 0 : current + 1
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function isUpKey(key: KeyEvent): boolean {
|
|
175
|
-
return matchesKey(key, 'up') || matchesKey(key, 'k')
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function isDownKey(key: KeyEvent): boolean {
|
|
179
|
-
return matchesKey(key, 'down') || matchesKey(key, 'j')
|
|
180
|
-
}
|
|
181
|
-
|
|
182
114
|
export function ModalList(props: ModalListProps) {
|
|
183
|
-
const Dialog = props.Dialog
|
|
184
115
|
const renderer = useRenderer()
|
|
185
116
|
const clock = props.clock ?? defaultClock
|
|
186
117
|
const now = { value: clock.now() }
|
|
187
118
|
const state: { value: ViewState } = { value: { kind: 'loading' } }
|
|
188
|
-
const focusedIndex = { value: 0 }
|
|
189
119
|
let disposed = false
|
|
190
120
|
|
|
191
121
|
let headerText: TextRenderable | undefined
|
|
@@ -193,10 +123,6 @@ export function ModalList(props: ModalListProps) {
|
|
|
193
123
|
let emptyBox: BoxRenderable | undefined
|
|
194
124
|
let emptyLineOne: TextRenderable | undefined
|
|
195
125
|
let emptyLineTwo: TextRenderable | undefined
|
|
196
|
-
let errorBox: BoxRenderable | undefined
|
|
197
|
-
let errorLineOne: TextRenderable | undefined
|
|
198
|
-
let errorLineTwo: TextRenderable | undefined
|
|
199
|
-
let errorLineThree: TextRenderable | undefined
|
|
200
126
|
let rowsBox: BoxRenderable | undefined
|
|
201
127
|
const rowTexts: Array<TextRenderable | undefined> = []
|
|
202
128
|
|
|
@@ -206,10 +132,6 @@ export function ModalList(props: ModalListProps) {
|
|
|
206
132
|
emptyBox,
|
|
207
133
|
emptyLineOne,
|
|
208
134
|
emptyLineTwo,
|
|
209
|
-
errorBox,
|
|
210
|
-
errorLineOne,
|
|
211
|
-
errorLineTwo,
|
|
212
|
-
errorLineThree,
|
|
213
135
|
rowsBox,
|
|
214
136
|
rowTexts,
|
|
215
137
|
})
|
|
@@ -228,12 +150,6 @@ export function ModalList(props: ModalListProps) {
|
|
|
228
150
|
return
|
|
229
151
|
}
|
|
230
152
|
|
|
231
|
-
if (currentState.kind === 'error') {
|
|
232
|
-
renderErrorState(currentRefs, currentState.message)
|
|
233
|
-
renderer.requestRender()
|
|
234
|
-
return
|
|
235
|
-
}
|
|
236
|
-
|
|
237
153
|
const tasks = currentState.tasks
|
|
238
154
|
|
|
239
155
|
if (tasks.length === 0) {
|
|
@@ -242,45 +158,20 @@ export function ModalList(props: ModalListProps) {
|
|
|
242
158
|
return
|
|
243
159
|
}
|
|
244
160
|
|
|
245
|
-
renderTaskRows(currentRefs, tasks,
|
|
161
|
+
renderTaskRows(currentRefs, tasks, now.value)
|
|
246
162
|
|
|
247
163
|
renderer.requestRender()
|
|
248
164
|
}
|
|
249
165
|
|
|
250
166
|
const loadTasks = async () => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const initialIndex = props.initialTaskId
|
|
259
|
-
? response.tasks.findIndex(
|
|
260
|
-
(task) => task.taskId === props.initialTaskId,
|
|
261
|
-
)
|
|
262
|
-
: -1
|
|
263
|
-
|
|
264
|
-
if (initialIndex >= 0) {
|
|
265
|
-
focusedIndex.value = initialIndex
|
|
266
|
-
} else if (response.tasks.length === 0) {
|
|
267
|
-
focusedIndex.value = 0
|
|
268
|
-
} else {
|
|
269
|
-
focusedIndex.value = Math.min(
|
|
270
|
-
focusedIndex.value,
|
|
271
|
-
response.tasks.length - 1,
|
|
272
|
-
)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
state.value = { kind: 'ready', tasks: response.tasks }
|
|
276
|
-
} catch (error) {
|
|
277
|
-
if (disposed) {
|
|
278
|
-
return
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
state.value = { kind: 'error', message: errorMessage(error) }
|
|
167
|
+
const response = await props.rpc.tasksList()
|
|
168
|
+
|
|
169
|
+
if (disposed) {
|
|
170
|
+
return
|
|
282
171
|
}
|
|
283
172
|
|
|
173
|
+
state.value = { kind: 'ready', tasks: response.tasks }
|
|
174
|
+
|
|
284
175
|
renderView()
|
|
285
176
|
}
|
|
286
177
|
|
|
@@ -292,97 +183,49 @@ export function ModalList(props: ModalListProps) {
|
|
|
292
183
|
}
|
|
293
184
|
}, 1_000)
|
|
294
185
|
|
|
295
|
-
void loadTasks()
|
|
296
|
-
|
|
297
|
-
const handleKeyPress = (key: KeyEvent) => {
|
|
298
|
-
if (matchesKey(key, 'escape')) {
|
|
299
|
-
key.preventDefault()
|
|
300
|
-
props.onClose()
|
|
301
|
-
return
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (!isReadyState(state.value) || state.value.tasks.length === 0) {
|
|
305
|
-
return
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (isUpKey(key)) {
|
|
309
|
-
key.preventDefault()
|
|
310
|
-
focusedIndex.value = previousIndex(
|
|
311
|
-
focusedIndex.value,
|
|
312
|
-
state.value.tasks.length,
|
|
313
|
-
)
|
|
314
|
-
renderView()
|
|
315
|
-
return
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (isDownKey(key)) {
|
|
319
|
-
key.preventDefault()
|
|
320
|
-
focusedIndex.value = nextIndex(
|
|
321
|
-
focusedIndex.value,
|
|
322
|
-
state.value.tasks.length,
|
|
323
|
-
)
|
|
324
|
-
renderView()
|
|
186
|
+
void loadTasks().catch((error) => {
|
|
187
|
+
if (disposed) {
|
|
325
188
|
return
|
|
326
189
|
}
|
|
327
190
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
props.onCancelTask?.(state.value.tasks[focusedIndex.value])
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
renderer.keyInput.on('keypress', handleKeyPress)
|
|
191
|
+
props.onLoadError?.(error)
|
|
192
|
+
})
|
|
335
193
|
|
|
336
194
|
onCleanup(() => {
|
|
337
195
|
disposed = true
|
|
338
|
-
renderer.keyInput.off('keypress', handleKeyPress)
|
|
339
196
|
clock.clearInterval(intervalHandle)
|
|
340
197
|
})
|
|
341
198
|
|
|
342
199
|
return (
|
|
343
|
-
<
|
|
344
|
-
<
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
<text ref={emptyLineTwo} />
|
|
356
|
-
</box>
|
|
357
|
-
|
|
358
|
-
<box
|
|
359
|
-
ref={errorBox}
|
|
360
|
-
flexDirection="column"
|
|
361
|
-
flexGrow={1}
|
|
362
|
-
justifyContent="center"
|
|
363
|
-
visible={false}
|
|
364
|
-
>
|
|
365
|
-
<text ref={errorLineOne} />
|
|
366
|
-
<text ref={errorLineTwo} />
|
|
367
|
-
<text ref={errorLineThree} />
|
|
368
|
-
</box>
|
|
369
|
-
|
|
370
|
-
<box ref={rowsBox} flexDirection="column" flexGrow={1} visible={false}>
|
|
371
|
-
<text ref={(node) => (rowTexts[0] = node)} />
|
|
372
|
-
<text ref={(node) => (rowTexts[1] = node)} />
|
|
373
|
-
<text ref={(node) => (rowTexts[2] = node)} />
|
|
374
|
-
<text ref={(node) => (rowTexts[3] = node)} />
|
|
375
|
-
<text ref={(node) => (rowTexts[4] = node)} />
|
|
376
|
-
<text ref={(node) => (rowTexts[5] = node)} />
|
|
377
|
-
<text ref={(node) => (rowTexts[6] = node)} />
|
|
378
|
-
<text ref={(node) => (rowTexts[7] = node)} />
|
|
379
|
-
<text ref={(node) => (rowTexts[8] = node)} />
|
|
380
|
-
<text ref={(node) => (rowTexts[9] = node)} />
|
|
381
|
-
</box>
|
|
382
|
-
|
|
383
|
-
<text ref={footerText}>Esc close</text>
|
|
200
|
+
<box flexDirection="column" gap={1} padding={1} width="100%">
|
|
201
|
+
<text ref={headerText}>Loading delegations…</text>
|
|
202
|
+
|
|
203
|
+
<box
|
|
204
|
+
ref={emptyBox}
|
|
205
|
+
flexDirection="column"
|
|
206
|
+
flexGrow={1}
|
|
207
|
+
justifyContent="center"
|
|
208
|
+
visible={false}
|
|
209
|
+
>
|
|
210
|
+
<text ref={emptyLineOne} />
|
|
211
|
+
<text ref={emptyLineTwo} />
|
|
384
212
|
</box>
|
|
385
|
-
|
|
213
|
+
|
|
214
|
+
<box ref={rowsBox} flexDirection="column" flexGrow={1} visible={false}>
|
|
215
|
+
<text ref={(node) => (rowTexts[0] = node)} />
|
|
216
|
+
<text ref={(node) => (rowTexts[1] = node)} />
|
|
217
|
+
<text ref={(node) => (rowTexts[2] = node)} />
|
|
218
|
+
<text ref={(node) => (rowTexts[3] = node)} />
|
|
219
|
+
<text ref={(node) => (rowTexts[4] = node)} />
|
|
220
|
+
<text ref={(node) => (rowTexts[5] = node)} />
|
|
221
|
+
<text ref={(node) => (rowTexts[6] = node)} />
|
|
222
|
+
<text ref={(node) => (rowTexts[7] = node)} />
|
|
223
|
+
<text ref={(node) => (rowTexts[8] = node)} />
|
|
224
|
+
<text ref={(node) => (rowTexts[9] = node)} />
|
|
225
|
+
</box>
|
|
226
|
+
|
|
227
|
+
<text ref={footerText}>Esc close</text>
|
|
228
|
+
</box>
|
|
386
229
|
)
|
|
387
230
|
}
|
|
388
231
|
|
package/src/tui/index.tsx
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
|
|
3
3
|
import type { TuiPlugin, TuiPluginModule } from '@opencode-ai/plugin/tui'
|
|
4
|
-
import { ConfirmCard } from './components/confirm-card'
|
|
5
4
|
import { ModalList } from './components/modal-list'
|
|
6
|
-
import type { ModalListTask } from './components/row'
|
|
7
5
|
import { createRpcClient } from './rpc-client'
|
|
8
6
|
|
|
7
|
+
function errorMessage(error: unknown): string {
|
|
8
|
+
if (error instanceof Error && error.message.trim().length > 0) {
|
|
9
|
+
return error.message.trim()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return 'Unknown RPC error.'
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
const tui: TuiPlugin = async (api) => {
|
|
10
16
|
const rpc = createRpcClient()
|
|
11
17
|
const closeDialog = () => {
|
|
12
18
|
api.ui.dialog.clear()
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
const
|
|
21
|
+
const showUnavailableAlert = (error: unknown) => {
|
|
22
|
+
api.ui.dialog.setSize('medium')
|
|
16
23
|
api.ui.dialog.replace(() => {
|
|
17
24
|
return (
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
initialTaskId={initialTaskId}
|
|
23
|
-
rpc={rpc}
|
|
25
|
+
<api.ui.DialogAlert
|
|
26
|
+
title="Status unavailable."
|
|
27
|
+
message={errorMessage(error)}
|
|
28
|
+
onConfirm={closeDialog}
|
|
24
29
|
/>
|
|
25
30
|
)
|
|
26
|
-
}
|
|
31
|
+
})
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
const
|
|
34
|
+
const openList = (initialTaskId?: string) => {
|
|
35
|
+
api.ui.dialog.setSize('large')
|
|
30
36
|
api.ui.dialog.replace(() => {
|
|
31
37
|
return (
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
<ModalList
|
|
39
|
+
onClose={closeDialog}
|
|
40
|
+
onLoadError={showUnavailableAlert}
|
|
41
|
+
initialTaskId={initialTaskId}
|
|
35
42
|
rpc={rpc}
|
|
36
|
-
onConfirm={() => openList(task.taskId)}
|
|
37
|
-
onCancel={() => openList(task.taskId)}
|
|
38
|
-
onDismissAfterError={() => openList(task.taskId)}
|
|
39
43
|
/>
|
|
40
44
|
)
|
|
41
|
-
}
|
|
45
|
+
})
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
const unregister = api.command.register(() => [
|