opencode-copilot-delegate 0.12.1 → 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.
Files changed (35) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/README.md +16 -16
  3. package/dist/index.js +20666 -14568
  4. package/dist/lib/normalize-tool-arg-schemas.d.ts +1 -1
  5. package/dist/lib/process-global.d.ts +18 -0
  6. package/dist/lib/tool.d.ts +25 -0
  7. package/dist/runtime/plugin-singleton.d.ts +60 -36
  8. package/dist/runtime/rpc-paths.d.ts +6 -0
  9. package/dist/runtime/rpc-port-sweep.d.ts +38 -0
  10. package/dist/runtime/rpc-server.d.ts +10 -0
  11. package/dist/tools/cancel.d.ts +3 -9
  12. package/dist/tools/delegate.d.ts +8 -19
  13. package/dist/tools/output.d.ts +5 -13
  14. package/dist/tools/resume.d.ts +13 -15
  15. package/dist/tui/index.js +2818 -10922
  16. package/dist/tui/status-dialogs.d.ts +17 -0
  17. package/dist/tui/status-format.d.ts +10 -0
  18. package/package.json +17 -13
  19. package/src/tui/index.tsx +11 -42
  20. package/src/tui/rpc-client.ts +5 -13
  21. package/src/tui/status-dialogs.tsx +243 -0
  22. package/src/tui/{components/row.tsx → status-format.ts} +10 -6
  23. package/dist/tui/__tests__/confirm-card.test.d.ts +0 -2
  24. package/dist/tui/__tests__/index.test.d.ts +0 -1
  25. package/dist/tui/__tests__/modal-list.test.d.ts +0 -1
  26. package/dist/tui/__tests__/rpc-client.test.d.ts +0 -1
  27. package/dist/tui/components/confirm-card.d.ts +0 -12
  28. package/dist/tui/components/modal-list.d.ts +0 -16
  29. package/dist/tui/components/row.d.ts +0 -6
  30. package/src/tui/__tests__/confirm-card.test.tsx +0 -516
  31. package/src/tui/__tests__/index.test.ts +0 -561
  32. package/src/tui/__tests__/modal-list.test.tsx +0 -518
  33. package/src/tui/__tests__/rpc-client.test.ts +0 -507
  34. package/src/tui/components/confirm-card.tsx +0 -252
  35. package/src/tui/components/modal-list.tsx +0 -232
@@ -1,252 +0,0 @@
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
@@ -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