opencode-copilot-delegate 0.12.2 → 0.13.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,232 +0,0 @@
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