opencode-discord 1.8.1 → 1.8.2
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/index.ts +61 -4
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ const CLIENT_ID = process.env.DISCORD_CLIENT_ID ?? "1486144419940929676"
|
|
|
5
5
|
const RECONNECT_DELAY = 5_000
|
|
6
6
|
const MAX_RECONNECT_ATTEMPTS = 5
|
|
7
7
|
|
|
8
|
-
type Activity = "idle" | "thinking" | "editing" | "running" | "reading"
|
|
8
|
+
type Activity = "idle" | "thinking" | "editing" | "running" | "reading" | "approving" | "commanding"
|
|
9
9
|
type LogLevel = "debug" | "info" | "error" | "warn"
|
|
10
10
|
|
|
11
11
|
function basename(filePath?: string): string | undefined {
|
|
@@ -24,6 +24,8 @@ export const DiscordStatus: Plugin = async ({ client: sdk, directory }) => {
|
|
|
24
24
|
let lastEditedFile: string | undefined
|
|
25
25
|
let activity: Activity = "idle"
|
|
26
26
|
let sessionCount = 0
|
|
27
|
+
let filesChanged = 0
|
|
28
|
+
let lastCommand: string | undefined
|
|
27
29
|
let reconnectAttempts = 0
|
|
28
30
|
let reconnectTimer: ReturnType<typeof setTimeout> | undefined
|
|
29
31
|
let pendingPresence = false
|
|
@@ -70,13 +72,21 @@ export const DiscordStatus: Plugin = async ({ client: sdk, directory }) => {
|
|
|
70
72
|
case "reading":
|
|
71
73
|
details = lastEditedFile ? `Reading ${lastEditedFile}` : "Reading files"
|
|
72
74
|
break
|
|
75
|
+
case "approving":
|
|
76
|
+
details = "Waiting for approval..."
|
|
77
|
+
break
|
|
78
|
+
case "commanding":
|
|
79
|
+
details = lastCommand ? `Running /${lastCommand}` : "Running command"
|
|
80
|
+
break
|
|
73
81
|
default:
|
|
74
82
|
details = "Session active"
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
state =
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
state = filesChanged > 0
|
|
86
|
+
? `${currentProject} · ${filesChanged} file${filesChanged !== 1 ? "s" : ""} changed`
|
|
87
|
+
: currentProject
|
|
88
|
+
smallImageKey = activity === "thinking" ? "thinking" : activity === "approving" ? "idle" : "active"
|
|
89
|
+
smallImageText = activity === "thinking" ? "Generating" : activity === "approving" ? "Needs approval" : "Active"
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
rpc.user?.setActivity({
|
|
@@ -154,8 +164,24 @@ export const DiscordStatus: Plugin = async ({ client: sdk, directory }) => {
|
|
|
154
164
|
sessionCount += 1
|
|
155
165
|
startTimestamp = new Date()
|
|
156
166
|
lastEditedFile = undefined
|
|
167
|
+
lastCommand = undefined
|
|
168
|
+
filesChanged = 0
|
|
157
169
|
activity = "thinking"
|
|
158
170
|
break
|
|
171
|
+
case "session.updated":
|
|
172
|
+
sessionActive = true
|
|
173
|
+
if (activity === "idle") activity = "thinking"
|
|
174
|
+
break
|
|
175
|
+
case "session.status": {
|
|
176
|
+
const status = (event as { properties?: { status?: string } }).properties?.status
|
|
177
|
+
if (status === "busy" || status === "retry") {
|
|
178
|
+
sessionActive = true
|
|
179
|
+
activity = "thinking"
|
|
180
|
+
} else if (status === "idle") {
|
|
181
|
+
activity = "idle"
|
|
182
|
+
}
|
|
183
|
+
break
|
|
184
|
+
}
|
|
159
185
|
case "session.idle":
|
|
160
186
|
activity = "idle"
|
|
161
187
|
break
|
|
@@ -166,6 +192,8 @@ export const DiscordStatus: Plugin = async ({ client: sdk, directory }) => {
|
|
|
166
192
|
case "session.deleted":
|
|
167
193
|
sessionActive = false
|
|
168
194
|
lastEditedFile = undefined
|
|
195
|
+
lastCommand = undefined
|
|
196
|
+
filesChanged = 0
|
|
169
197
|
activity = "idle"
|
|
170
198
|
if (connected) {
|
|
171
199
|
rpc.user?.clearActivity().catch(() => {})
|
|
@@ -180,6 +208,35 @@ export const DiscordStatus: Plugin = async ({ client: sdk, directory }) => {
|
|
|
180
208
|
lastEditedFile = basename(editedFile) ?? lastEditedFile
|
|
181
209
|
break
|
|
182
210
|
}
|
|
211
|
+
case "session.diff": {
|
|
212
|
+
const diffs = (event as { properties?: { diff?: unknown[] } }).properties?.diff
|
|
213
|
+
if (diffs) filesChanged = diffs.length
|
|
214
|
+
break
|
|
215
|
+
}
|
|
216
|
+
case "message.part.updated": {
|
|
217
|
+
if (sessionActive && activity !== "editing" && activity !== "running") {
|
|
218
|
+
activity = "thinking"
|
|
219
|
+
}
|
|
220
|
+
break
|
|
221
|
+
}
|
|
222
|
+
case "pty.created":
|
|
223
|
+
activity = "running"
|
|
224
|
+
break
|
|
225
|
+
case "pty.exited":
|
|
226
|
+
activity = sessionActive ? "thinking" : "idle"
|
|
227
|
+
break
|
|
228
|
+
case "permission.updated":
|
|
229
|
+
activity = "approving"
|
|
230
|
+
break
|
|
231
|
+
case "permission.replied":
|
|
232
|
+
activity = sessionActive ? "thinking" : "idle"
|
|
233
|
+
break
|
|
234
|
+
case "command.executed": {
|
|
235
|
+
const cmdName = (event as { properties?: { name?: string } }).properties?.name
|
|
236
|
+
lastCommand = cmdName
|
|
237
|
+
activity = "commanding"
|
|
238
|
+
break
|
|
239
|
+
}
|
|
183
240
|
}
|
|
184
241
|
|
|
185
242
|
updatePresence()
|