opencode-copilot-delegate 0.9.0 → 0.10.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.
- package/CHANGELOG.md +12 -0
- package/README.md +14 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14141 -215
- package/dist/runtime/cancel-helper.d.ts +10 -0
- package/dist/runtime/envelope.d.ts +1 -1
- package/dist/runtime/notify.d.ts +2 -1
- package/dist/runtime/rpc-contract.d.ts +39 -0
- package/dist/runtime/rpc-server.d.ts +32 -0
- package/dist/tui/__tests__/confirm-card.test.d.ts +2 -0
- package/dist/tui/__tests__/index.test.d.ts +1 -0
- package/dist/tui/__tests__/modal-list.test.d.ts +1 -0
- package/dist/tui/__tests__/rpc-client.test.d.ts +1 -0
- package/dist/tui/components/confirm-card.d.ts +12 -0
- package/dist/tui/components/modal-list.d.ts +16 -0
- package/dist/tui/components/row.d.ts +6 -0
- package/dist/tui/index.d.ts +7 -0
- package/dist/tui/index.js +14107 -0
- package/dist/tui/rpc-client.d.ts +43 -0
- package/package.json +32 -9
- package/src/tui/.gitkeep +1 -0
- package/src/tui/__tests__/confirm-card.test.tsx +516 -0
- package/src/tui/__tests__/index.test.ts +438 -0
- package/src/tui/__tests__/modal-list.test.tsx +518 -0
- package/src/tui/__tests__/rpc-client.test.ts +507 -0
- package/src/tui/components/confirm-card.tsx +252 -0
- package/src/tui/components/modal-list.tsx +232 -0
- package/src/tui/components/row.tsx +41 -0
- package/src/tui/index.tsx +67 -0
- package/src/tui/rpc-client.ts +379 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type KeyEvent,
|
|
5
|
+
TextAttributes,
|
|
6
|
+
type TextRenderable,
|
|
7
|
+
} from '@opentui/core'
|
|
8
|
+
import { useRenderer } from '@opentui/solid'
|
|
9
|
+
import { onCleanup } from 'solid-js'
|
|
10
|
+
import type { RpcClient } from '../rpc-client'
|
|
11
|
+
import type { ModalListTask } from './row'
|
|
12
|
+
|
|
13
|
+
type ConfirmCardProps = {
|
|
14
|
+
task: ModalListTask
|
|
15
|
+
rpc: Pick<RpcClient, 'tasksCancel'>
|
|
16
|
+
onConfirm: () => void
|
|
17
|
+
onCancel: () => void
|
|
18
|
+
onDismissAfterError: () => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ConfirmState =
|
|
22
|
+
| {
|
|
23
|
+
kind: 'confirm'
|
|
24
|
+
focusedAction: 'confirm' | 'cancel'
|
|
25
|
+
busy: boolean
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
kind: 'error'
|
|
29
|
+
message: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function errorMessage(error: unknown): string {
|
|
33
|
+
if (error instanceof Error && error.message.trim().length > 0) {
|
|
34
|
+
return error.message.trim()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return 'Unknown RPC error.'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function matchesKey(key: KeyEvent, expected: string): boolean {
|
|
41
|
+
return (
|
|
42
|
+
key.name === expected || key.sequence === expected || key.raw === expected
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isActivateKey(key: KeyEvent): boolean {
|
|
47
|
+
return (
|
|
48
|
+
matchesKey(key, 'return') ||
|
|
49
|
+
matchesKey(key, 'enter') ||
|
|
50
|
+
matchesKey(key, 'space') ||
|
|
51
|
+
key.sequence === ' ' ||
|
|
52
|
+
key.raw === ' '
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isLeftKey(key: KeyEvent): boolean {
|
|
57
|
+
return matchesKey(key, 'left')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isRightKey(key: KeyEvent): boolean {
|
|
61
|
+
return matchesKey(key, 'right')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function updateText(
|
|
65
|
+
node: TextRenderable | undefined,
|
|
66
|
+
content: string,
|
|
67
|
+
attributes = TextAttributes.NONE,
|
|
68
|
+
) {
|
|
69
|
+
if (!node) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
node.content = content
|
|
74
|
+
node.attributes = attributes
|
|
75
|
+
node.visible = content.length > 0
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function ConfirmCard(props: ConfirmCardProps) {
|
|
79
|
+
const renderer = useRenderer()
|
|
80
|
+
const title = `Cancel Copilot delegation ${props.task.taskId}?`
|
|
81
|
+
const state: { value: ConfirmState } = {
|
|
82
|
+
value: {
|
|
83
|
+
kind: 'confirm',
|
|
84
|
+
focusedAction: 'confirm',
|
|
85
|
+
busy: false,
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let confirmText: TextRenderable | undefined
|
|
90
|
+
let cancelText: TextRenderable | undefined
|
|
91
|
+
let errorText: TextRenderable | undefined
|
|
92
|
+
let dismissText: TextRenderable | undefined
|
|
93
|
+
|
|
94
|
+
const renderView = () => {
|
|
95
|
+
const currentState = state.value
|
|
96
|
+
|
|
97
|
+
if (currentState.kind === 'error') {
|
|
98
|
+
updateText(confirmText, '')
|
|
99
|
+
updateText(cancelText, '')
|
|
100
|
+
updateText(errorText, `Cancel failed: ${currentState.message}`)
|
|
101
|
+
updateText(dismissText, 'Dismiss', TextAttributes.INVERSE)
|
|
102
|
+
renderer.requestRender()
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
updateText(
|
|
107
|
+
confirmText,
|
|
108
|
+
'Cancel Task',
|
|
109
|
+
currentState.focusedAction === 'confirm'
|
|
110
|
+
? TextAttributes.INVERSE
|
|
111
|
+
: TextAttributes.NONE,
|
|
112
|
+
)
|
|
113
|
+
updateText(
|
|
114
|
+
cancelText,
|
|
115
|
+
'Keep Running',
|
|
116
|
+
currentState.focusedAction === 'cancel'
|
|
117
|
+
? TextAttributes.INVERSE
|
|
118
|
+
: TextAttributes.NONE,
|
|
119
|
+
)
|
|
120
|
+
updateText(errorText, '')
|
|
121
|
+
updateText(dismissText, '')
|
|
122
|
+
renderer.requestRender()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const confirmCancel = async () => {
|
|
126
|
+
if (state.value.kind !== 'confirm' || state.value.busy) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
state.value = { ...state.value, busy: true }
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const response = await props.rpc.tasksCancel(props.task.taskId)
|
|
134
|
+
|
|
135
|
+
if (response.cancelled) {
|
|
136
|
+
props.onConfirm()
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (response.error === 'no such task') {
|
|
141
|
+
props.onConfirm()
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
state.value = {
|
|
146
|
+
kind: 'error',
|
|
147
|
+
message: response.error ?? 'Unknown RPC error.',
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
state.value = { kind: 'error', message: errorMessage(error) }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
renderView()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const activateFocusedAction = () => {
|
|
157
|
+
if (state.value.kind === 'error') {
|
|
158
|
+
props.onDismissAfterError()
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (state.value.focusedAction === 'confirm') {
|
|
163
|
+
void confirmCancel()
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
props.onCancel()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const focusConfirm = () => {
|
|
171
|
+
if (state.value.kind !== 'confirm' || state.value.busy) {
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
state.value = { ...state.value, focusedAction: 'confirm' }
|
|
176
|
+
renderView()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const focusCancel = () => {
|
|
180
|
+
if (state.value.kind !== 'confirm' || state.value.busy) {
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
state.value = { ...state.value, focusedAction: 'cancel' }
|
|
185
|
+
renderView()
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const handleKeyPress = (key: KeyEvent) => {
|
|
189
|
+
if (state.value.kind === 'confirm' && !state.value.busy) {
|
|
190
|
+
if (isLeftKey(key)) {
|
|
191
|
+
key.preventDefault()
|
|
192
|
+
focusConfirm()
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (isRightKey(key)) {
|
|
197
|
+
key.preventDefault()
|
|
198
|
+
focusCancel()
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (isActivateKey(key)) {
|
|
204
|
+
key.preventDefault()
|
|
205
|
+
activateFocusedAction()
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
renderer.keyInput.on('keypress', handleKeyPress)
|
|
210
|
+
|
|
211
|
+
onCleanup(() => {
|
|
212
|
+
renderer.keyInput.off('keypress', handleKeyPress)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
return (
|
|
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>
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export default ConfirmCard
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type BoxRenderable,
|
|
5
|
+
TextAttributes,
|
|
6
|
+
type TextRenderable,
|
|
7
|
+
} from '@opentui/core'
|
|
8
|
+
import { useRenderer } from '@opentui/solid'
|
|
9
|
+
import { onCleanup } from 'solid-js'
|
|
10
|
+
import type { RpcClient } from '../rpc-client'
|
|
11
|
+
import { formatRowText, type ModalListTask } from './row'
|
|
12
|
+
|
|
13
|
+
const LOADING_HEADER = 'Loading delegations…'
|
|
14
|
+
const EMPTY_STATE_TITLE = 'No Copilot delegations are running.'
|
|
15
|
+
const EMPTY_STATE_HINT =
|
|
16
|
+
'Start one with the copilot_delegate tool, then reopen /copilot-status.'
|
|
17
|
+
export type ModalListClock = {
|
|
18
|
+
now(): number
|
|
19
|
+
setInterval(fn: () => void, delayMs: number): unknown
|
|
20
|
+
clearInterval(handle: unknown): void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type ModalListProps = {
|
|
24
|
+
rpc: Pick<RpcClient, 'tasksList'>
|
|
25
|
+
onClose: () => void
|
|
26
|
+
onLoadError?: (error: unknown) => void
|
|
27
|
+
initialTaskId?: string
|
|
28
|
+
clock?: ModalListClock
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type ViewState = { kind: 'loading' } | { kind: 'ready'; tasks: ModalListTask[] }
|
|
32
|
+
|
|
33
|
+
const defaultClock: ModalListClock = {
|
|
34
|
+
now: () => Date.now(),
|
|
35
|
+
setInterval: (fn, delayMs) => globalThis.setInterval(fn, delayMs),
|
|
36
|
+
clearInterval: (handle) => {
|
|
37
|
+
globalThis.clearInterval(handle as ReturnType<typeof setInterval>)
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function updateText(
|
|
42
|
+
node: TextRenderable | undefined,
|
|
43
|
+
content: string,
|
|
44
|
+
attributes = TextAttributes.NONE,
|
|
45
|
+
) {
|
|
46
|
+
if (!node) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
node.content = content
|
|
51
|
+
node.attributes = attributes
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function updateBoxVisibility(
|
|
55
|
+
node: BoxRenderable | undefined,
|
|
56
|
+
visible: boolean,
|
|
57
|
+
) {
|
|
58
|
+
if (!node) {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
node.visible = visible
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type ModalRefs = {
|
|
66
|
+
headerText?: TextRenderable
|
|
67
|
+
footerText?: TextRenderable
|
|
68
|
+
emptyBox?: BoxRenderable
|
|
69
|
+
emptyLineOne?: TextRenderable
|
|
70
|
+
emptyLineTwo?: TextRenderable
|
|
71
|
+
rowsBox?: BoxRenderable
|
|
72
|
+
rowTexts: Array<TextRenderable | undefined>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function renderLoadingState(refs: ModalRefs) {
|
|
76
|
+
updateText(refs.headerText, LOADING_HEADER)
|
|
77
|
+
updateText(refs.footerText, 'Esc close')
|
|
78
|
+
updateBoxVisibility(refs.emptyBox, false)
|
|
79
|
+
updateBoxVisibility(refs.rowsBox, false)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function renderEmptyView(refs: ModalRefs) {
|
|
83
|
+
updateText(refs.headerText, '0 running · 0 recent')
|
|
84
|
+
updateText(refs.footerText, 'Esc close')
|
|
85
|
+
updateBoxVisibility(refs.emptyBox, true)
|
|
86
|
+
updateBoxVisibility(refs.rowsBox, false)
|
|
87
|
+
updateText(refs.emptyLineOne, EMPTY_STATE_TITLE)
|
|
88
|
+
updateText(refs.emptyLineTwo, EMPTY_STATE_HINT)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function renderTaskRows(
|
|
92
|
+
refs: ModalRefs,
|
|
93
|
+
tasks: ModalListTask[],
|
|
94
|
+
nowMs: number,
|
|
95
|
+
) {
|
|
96
|
+
updateText(refs.headerText, `${tasks.length} running · 0 recent`)
|
|
97
|
+
updateText(refs.footerText, 'Esc close')
|
|
98
|
+
updateBoxVisibility(refs.emptyBox, false)
|
|
99
|
+
updateBoxVisibility(refs.rowsBox, true)
|
|
100
|
+
|
|
101
|
+
for (const [index, rowText] of refs.rowTexts.entries()) {
|
|
102
|
+
const task = tasks[index]
|
|
103
|
+
|
|
104
|
+
if (!rowText) {
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
rowText.visible = task !== undefined
|
|
109
|
+
rowText.content = task ? formatRowText(task, nowMs) : ''
|
|
110
|
+
rowText.attributes = TextAttributes.NONE
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function ModalList(props: ModalListProps) {
|
|
115
|
+
const renderer = useRenderer()
|
|
116
|
+
const clock = props.clock ?? defaultClock
|
|
117
|
+
const now = { value: clock.now() }
|
|
118
|
+
const state: { value: ViewState } = { value: { kind: 'loading' } }
|
|
119
|
+
let disposed = false
|
|
120
|
+
|
|
121
|
+
let headerText: TextRenderable | undefined
|
|
122
|
+
let footerText: TextRenderable | undefined
|
|
123
|
+
let emptyBox: BoxRenderable | undefined
|
|
124
|
+
let emptyLineOne: TextRenderable | undefined
|
|
125
|
+
let emptyLineTwo: TextRenderable | undefined
|
|
126
|
+
let rowsBox: BoxRenderable | undefined
|
|
127
|
+
const rowTexts: Array<TextRenderable | undefined> = []
|
|
128
|
+
|
|
129
|
+
const refs = (): ModalRefs => ({
|
|
130
|
+
headerText,
|
|
131
|
+
footerText,
|
|
132
|
+
emptyBox,
|
|
133
|
+
emptyLineOne,
|
|
134
|
+
emptyLineTwo,
|
|
135
|
+
rowsBox,
|
|
136
|
+
rowTexts,
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const renderView = () => {
|
|
140
|
+
if (disposed) {
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const currentState = state.value
|
|
145
|
+
const currentRefs = refs()
|
|
146
|
+
|
|
147
|
+
if (currentState.kind === 'loading') {
|
|
148
|
+
renderLoadingState(currentRefs)
|
|
149
|
+
renderer.requestRender()
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const tasks = currentState.tasks
|
|
154
|
+
|
|
155
|
+
if (tasks.length === 0) {
|
|
156
|
+
renderEmptyView(currentRefs)
|
|
157
|
+
renderer.requestRender()
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
renderTaskRows(currentRefs, tasks, now.value)
|
|
162
|
+
|
|
163
|
+
renderer.requestRender()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const loadTasks = async () => {
|
|
167
|
+
const response = await props.rpc.tasksList()
|
|
168
|
+
|
|
169
|
+
if (disposed) {
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
state.value = { kind: 'ready', tasks: response.tasks }
|
|
174
|
+
|
|
175
|
+
renderView()
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const intervalHandle = clock.setInterval(() => {
|
|
179
|
+
now.value = clock.now()
|
|
180
|
+
|
|
181
|
+
if (state.value.kind === 'ready' && state.value.tasks.length > 0) {
|
|
182
|
+
renderView()
|
|
183
|
+
}
|
|
184
|
+
}, 1_000)
|
|
185
|
+
|
|
186
|
+
void loadTasks().catch((error) => {
|
|
187
|
+
if (disposed) {
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
props.onLoadError?.(error)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
onCleanup(() => {
|
|
195
|
+
disposed = true
|
|
196
|
+
clock.clearInterval(intervalHandle)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
return (
|
|
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} />
|
|
212
|
+
</box>
|
|
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>
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export default ModalList
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TasksListResponse } from '../../runtime/rpc-contract'
|
|
2
|
+
|
|
3
|
+
export type ModalListTask = TasksListResponse['tasks'][number]
|
|
4
|
+
|
|
5
|
+
export function displayValue(value: string): string {
|
|
6
|
+
const trimmed = value.trim()
|
|
7
|
+
|
|
8
|
+
return trimmed.length > 0 ? trimmed : 'default'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function formatElapsed(elapsedMs: number): string {
|
|
12
|
+
const totalSeconds = Math.max(0, Math.floor(elapsedMs / 1_000))
|
|
13
|
+
|
|
14
|
+
if (totalSeconds >= 3_600) {
|
|
15
|
+
const hours = Math.floor(totalSeconds / 3_600)
|
|
16
|
+
const minutes = Math.floor((totalSeconds % 3_600) / 60)
|
|
17
|
+
return `${hours}h ${minutes}m`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (totalSeconds >= 60) {
|
|
21
|
+
const minutes = Math.floor(totalSeconds / 60)
|
|
22
|
+
const seconds = totalSeconds % 60
|
|
23
|
+
return `${minutes}m ${seconds}s`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return `${totalSeconds}s`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function formatStatus(status: ModalListTask['status']): string {
|
|
30
|
+
return status === 'running' ? `● ${status}` : status
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function formatToolCalls(toolCallCount: number): string {
|
|
34
|
+
return `${toolCallCount} ${toolCallCount === 1 ? 'call' : 'calls'}`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function formatRowText(task: ModalListTask, nowMs: number): string {
|
|
38
|
+
const elapsed = Math.max(0, nowMs - task.startedAt)
|
|
39
|
+
|
|
40
|
+
return `${formatStatus(task.status)} ${task.taskId} ${displayValue(task.agent)} ${displayValue(task.model)} ${formatElapsed(elapsed)} ${formatToolCalls(task.toolCallCount)}`
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
|
|
3
|
+
import type { TuiPlugin, TuiPluginModule } from '@opencode-ai/plugin/tui'
|
|
4
|
+
import { ModalList } from './components/modal-list'
|
|
5
|
+
import { createRpcClient } from './rpc-client'
|
|
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
|
+
|
|
15
|
+
const tui: TuiPlugin = async (api) => {
|
|
16
|
+
const rpc = createRpcClient()
|
|
17
|
+
const closeDialog = () => {
|
|
18
|
+
api.ui.dialog.clear()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const showUnavailableAlert = (error: unknown) => {
|
|
22
|
+
api.ui.dialog.setSize('medium')
|
|
23
|
+
api.ui.dialog.replace(() => {
|
|
24
|
+
return (
|
|
25
|
+
<api.ui.DialogAlert
|
|
26
|
+
title="Status unavailable."
|
|
27
|
+
message={errorMessage(error)}
|
|
28
|
+
onConfirm={closeDialog}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const openList = (initialTaskId?: string) => {
|
|
35
|
+
api.ui.dialog.setSize('large')
|
|
36
|
+
api.ui.dialog.replace(() => {
|
|
37
|
+
return (
|
|
38
|
+
<ModalList
|
|
39
|
+
onClose={closeDialog}
|
|
40
|
+
onLoadError={showUnavailableAlert}
|
|
41
|
+
initialTaskId={initialTaskId}
|
|
42
|
+
rpc={rpc}
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const unregister = api.command.register(() => [
|
|
49
|
+
{
|
|
50
|
+
title: 'Copilot Status',
|
|
51
|
+
value: '/copilot-status',
|
|
52
|
+
slash: { name: 'copilot-status' },
|
|
53
|
+
onSelect: () => {
|
|
54
|
+
openList()
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
])
|
|
58
|
+
|
|
59
|
+
api.lifecycle.onDispose(() => {
|
|
60
|
+
rpc.dispose()
|
|
61
|
+
unregister()
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const id = 'opencode-copilot-delegate'
|
|
66
|
+
|
|
67
|
+
export default { id, tui } satisfies TuiPluginModule
|