moshi-opencode-hooks 1.0.8 → 1.0.10
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 +37 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Plugin } from "@opencode-ai/plugin"
|
|
|
4
4
|
|
|
5
5
|
const TOKEN_PATH = `${homedir()}/.config/moshi/token`
|
|
6
6
|
const API_URL = "https://api.getmoshi.app/api/v1/agent-events"
|
|
7
|
-
const INTERESTING_TOOLS = new Set(["bash", "edit", "write", "read", "glob", "grep", "task"])
|
|
7
|
+
const INTERESTING_TOOLS = new Set(["bash", "edit", "write", "read", "glob", "grep", "task", "question", "apply_patch"])
|
|
8
8
|
|
|
9
9
|
interface HookState {
|
|
10
10
|
model?: string
|
|
@@ -170,19 +170,51 @@ export const MoshiHooks: Plugin = async ({ client, directory }) => {
|
|
|
170
170
|
|
|
171
171
|
setupEventSubscription()
|
|
172
172
|
|
|
173
|
+
const isSubagentSession = async (sessionID: string): Promise<boolean> => {
|
|
174
|
+
try {
|
|
175
|
+
const res = await (client.session.get as any)({ sessionID })
|
|
176
|
+
return !!(res.data?.parentID)
|
|
177
|
+
} catch {
|
|
178
|
+
return false
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
173
182
|
return {
|
|
174
|
-
"tool.execute.before": async (input,
|
|
183
|
+
"tool.execute.before": async (input, output) => {
|
|
175
184
|
const token = await loadToken()
|
|
176
185
|
if (!token) return
|
|
177
186
|
|
|
178
187
|
const { tool, sessionID } = input
|
|
179
188
|
if (!tool || !INTERESTING_TOOLS.has(tool.toLowerCase())) return
|
|
189
|
+
if (await isSubagentSession(sessionID)) return
|
|
180
190
|
|
|
181
191
|
await writeState(sessionID, { lastToolName: tool })
|
|
182
192
|
|
|
183
193
|
const state = await readState(sessionID)
|
|
184
194
|
const projectName = directory ? basename(directory) : undefined
|
|
185
195
|
|
|
196
|
+
if (tool === "question") {
|
|
197
|
+
const questions: any[] = output.args?.questions ?? []
|
|
198
|
+
const lines = questions.map((q) => {
|
|
199
|
+
const opts = q.options?.map((o: any) => ` - ${o.label}`).join("\n") ?? ""
|
|
200
|
+
return `${q.header}: ${q.question}\n${opts}`
|
|
201
|
+
})
|
|
202
|
+
const evt: AgentEvent = {
|
|
203
|
+
source: "opencode",
|
|
204
|
+
eventType: "notification",
|
|
205
|
+
sessionId: sessionID,
|
|
206
|
+
category: "approval_required",
|
|
207
|
+
title: "Question",
|
|
208
|
+
message: lines.join("\n---\n").slice(0, 512),
|
|
209
|
+
eventId: crypto.randomUUID(),
|
|
210
|
+
projectName,
|
|
211
|
+
modelName: state.model,
|
|
212
|
+
toolName: tool,
|
|
213
|
+
}
|
|
214
|
+
await sendAgentEvent(client, token, evt)
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
|
|
186
218
|
const evt: AgentEvent = {
|
|
187
219
|
source: "opencode",
|
|
188
220
|
eventType: "pre_tool",
|
|
@@ -204,6 +236,9 @@ export const MoshiHooks: Plugin = async ({ client, directory }) => {
|
|
|
204
236
|
|
|
205
237
|
const { tool, sessionID } = input
|
|
206
238
|
if (!tool || !INTERESTING_TOOLS.has(tool.toLowerCase())) return
|
|
239
|
+
if (await isSubagentSession(sessionID)) return
|
|
240
|
+
|
|
241
|
+
if (tool === "question") return
|
|
207
242
|
|
|
208
243
|
const state = await readState(sessionID)
|
|
209
244
|
const projectName = directory ? basename(directory) : undefined
|