opencode-queue 0.3.0 → 0.4.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/README.md +12 -3
- package/index.ts +56 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Queue OpenCode input until the current agent run is actually idle.
|
|
4
4
|
|
|
5
|
-
This plugin adds a `/queue
|
|
5
|
+
This plugin adds a real `/queue` slash command that keeps the current run focused instead of injecting your next message into the still-running loop.
|
|
6
6
|
|
|
7
7
|
## What it does
|
|
8
8
|
|
|
@@ -11,6 +11,7 @@ This plugin adds a `/queue ...` prefix that keeps the current run focused instea
|
|
|
11
11
|
- Hides queued placeholders from both the UI transcript and the running agent
|
|
12
12
|
- Replays queued input in order once the session becomes idle
|
|
13
13
|
- Replays queued commands as a visible `/command` message before executing them
|
|
14
|
+
- Registers `/queue` as a real OpenCode slash command
|
|
14
15
|
- Shows the current queue with `/queue list`
|
|
15
16
|
- Clears the current queue with `/queue clear`
|
|
16
17
|
|
|
@@ -40,14 +41,22 @@ While the agent is busy:
|
|
|
40
41
|
/queue clear
|
|
41
42
|
```
|
|
42
43
|
|
|
44
|
+
When the session is idle:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
/queue hello
|
|
48
|
+
/queue /review
|
|
49
|
+
/queue
|
|
50
|
+
```
|
|
51
|
+
|
|
43
52
|
Queued items stay hidden while the current run is still working, then replay automatically when the session becomes idle.
|
|
44
53
|
|
|
45
54
|
## Notes
|
|
46
55
|
|
|
47
56
|
- This is a `/queue` plugin, not a keyboard shortcut plugin. OpenCode plugins cannot currently register custom TUI keybindings.
|
|
48
57
|
- Idle `/queue some text` is treated like a normal prompt with the `/queue` prefix removed.
|
|
49
|
-
- Idle `/queue /command`
|
|
50
|
-
- `/queue list`
|
|
58
|
+
- Idle `/queue /command` immediately runs the nested command.
|
|
59
|
+
- `/queue` and `/queue list` show the in-memory queue for the current session.
|
|
51
60
|
- `/queue clear` drops all currently queued items for the current session.
|
|
52
61
|
|
|
53
62
|
## License
|
package/index.ts
CHANGED
|
@@ -10,10 +10,11 @@ import type {
|
|
|
10
10
|
|
|
11
11
|
const QUEUE = /^\/queue(?:\s+([\s\S]*))?$/
|
|
12
12
|
const COMMAND = /^\/(\S+)(?:\s+([\s\S]*))?$/
|
|
13
|
+
const HANDLED = "__QUEUE_HANDLED__"
|
|
13
14
|
|
|
14
15
|
type InputPart = TextPartInput | FilePartInput | AgentPartInput | SubtaskPartInput
|
|
15
16
|
type Info = { agent: string; model: { providerID: string; modelID: string } }
|
|
16
|
-
type Item = { info: Info; text: string; parts?: InputPart[]; command?: string; arguments?: string }
|
|
17
|
+
type Item = { info: Info; text: string; parts?: InputPart[]; command?: string; arguments?: string; files?: FilePartInput[] }
|
|
17
18
|
|
|
18
19
|
const label = (body: string, files: number) => {
|
|
19
20
|
const text = body.trim() || `${files} attachment${files === 1 ? "" : "s"}`
|
|
@@ -83,7 +84,7 @@ export const QueuePlugin: Plugin = async ({ client }) => {
|
|
|
83
84
|
agent: item.info.agent,
|
|
84
85
|
model: item.info.model,
|
|
85
86
|
noReply: true,
|
|
86
|
-
parts: [{ type: "text", text: item.text }],
|
|
87
|
+
parts: [{ type: "text", text: item.text }, ...(item.files ?? [])],
|
|
87
88
|
},
|
|
88
89
|
})
|
|
89
90
|
|
|
@@ -94,7 +95,8 @@ export const QueuePlugin: Plugin = async ({ client }) => {
|
|
|
94
95
|
model: `${item.info.model.providerID}/${item.info.model.modelID}`,
|
|
95
96
|
command: item.command,
|
|
96
97
|
arguments: item.arguments,
|
|
97
|
-
|
|
98
|
+
parts: item.files,
|
|
99
|
+
} as any,
|
|
98
100
|
})
|
|
99
101
|
}
|
|
100
102
|
|
|
@@ -124,6 +126,13 @@ export const QueuePlugin: Plugin = async ({ client }) => {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
return {
|
|
129
|
+
config: async (cfg) => {
|
|
130
|
+
cfg.command ??= {}
|
|
131
|
+
cfg.command.queue = {
|
|
132
|
+
template: "",
|
|
133
|
+
description: "Queue input until the session is idle",
|
|
134
|
+
}
|
|
135
|
+
},
|
|
127
136
|
event: async ({ event }) => {
|
|
128
137
|
if (event.type !== "session.status") return
|
|
129
138
|
|
|
@@ -136,6 +145,47 @@ export const QueuePlugin: Plugin = async ({ client }) => {
|
|
|
136
145
|
busy.delete(sid)
|
|
137
146
|
await flush(sid)
|
|
138
147
|
},
|
|
148
|
+
"command.execute.before": async (input, output) => {
|
|
149
|
+
if (input.command !== "queue") return
|
|
150
|
+
|
|
151
|
+
const body = input.arguments ?? ""
|
|
152
|
+
const text = body.trim()
|
|
153
|
+
const files = output.parts.filter((part): part is FilePart => part.type === "file").map((part) => ({ ...part }))
|
|
154
|
+
|
|
155
|
+
if ((!text || text === "list" || text === "clear") && !files.length) {
|
|
156
|
+
await toast(text === "clear" ? clear(input.sessionID) : summary(input.sessionID), "info", 5000)
|
|
157
|
+
throw new Error(HANDLED)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!busy.has(input.sessionID)) {
|
|
161
|
+
const cmd = parseCommand(body)
|
|
162
|
+
if (!cmd) {
|
|
163
|
+
output.parts.length = 0
|
|
164
|
+
output.parts.push({ type: "text", text: body } as any, ...files)
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
await client.session.prompt({
|
|
169
|
+
path: { id: input.sessionID },
|
|
170
|
+
body: {
|
|
171
|
+
noReply: true,
|
|
172
|
+
parts: [{ type: "text", text }, ...files],
|
|
173
|
+
} as any,
|
|
174
|
+
})
|
|
175
|
+
await client.session.command({
|
|
176
|
+
path: { id: input.sessionID },
|
|
177
|
+
body: {
|
|
178
|
+
command: cmd.command,
|
|
179
|
+
arguments: cmd.arguments,
|
|
180
|
+
parts: files,
|
|
181
|
+
} as any,
|
|
182
|
+
})
|
|
183
|
+
throw new Error(HANDLED)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
output.parts.length = 0
|
|
187
|
+
output.parts.push({ type: "text", text: `/queue ${body}` } as any, ...files)
|
|
188
|
+
},
|
|
139
189
|
"chat.message": async ({ sessionID }, output) => {
|
|
140
190
|
const text = output.parts.find((part): part is TextPart => part.type === "text" && !part.synthetic)
|
|
141
191
|
if (!text) return
|
|
@@ -175,7 +225,9 @@ export const QueuePlugin: Plugin = async ({ client }) => {
|
|
|
175
225
|
|
|
176
226
|
const info = { agent: output.message.agent, model: { ...output.message.model } }
|
|
177
227
|
const command = parseCommand(body)
|
|
178
|
-
const item = command
|
|
228
|
+
const item = command
|
|
229
|
+
? { info, text: trimmed, files, ...command }
|
|
230
|
+
: { info, text: label(body, files.length), parts }
|
|
179
231
|
|
|
180
232
|
enqueue(sessionID, item)
|
|
181
233
|
hide(output.message.id, text)
|
package/package.json
CHANGED