Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ export function Prompt(props: PromptProps) {
return sync.data.command.some((x) => x.name === command)
})
) {
let [command, ...args] = inputText.split(" ")
sdk.client.session.command({
const [command, ...args] = inputText.split(" ")
const result = await sdk.client.session.command({
sessionID,
command: command.slice(1),
arguments: args.join(" "),
Expand All @@ -567,6 +567,8 @@ export function Prompt(props: PromptProps) {
...x,
})),
})
input.clear()
if (result.response.status === 204) return
} else {
sdk.client.session
.prompt({
Expand Down
4 changes: 4 additions & 0 deletions packages/opencode/src/server/routes/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ export const SessionRoutes = lazy(() =>
},
},
},
204: {
description: "Command execution was prevented by a plugin",
},
...errors(400, 404),
},
}),
Expand All @@ -796,6 +799,7 @@ export const SessionRoutes = lazy(() =>
const sessionID = c.req.valid("param").sessionID
const body = c.req.valid("json")
const msg = await SessionPrompt.command({ ...body, sessionID })
if (!msg) return c.body(null, 204)
return c.json(msg)
},
)
Expand Down
10 changes: 9 additions & 1 deletion packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1702,16 +1702,24 @@ NOTE: At any point in time through this workflow you should feel free to ask the
: await lastModel(input.sessionID)
: taskModel

let defaultPrevented = false
await Plugin.trigger(
"command.execute.before",
{
command: input.command,
sessionID: input.sessionID,
arguments: input.arguments,
},
{ parts },
{
parts: parts as any,
preventDefault() {
defaultPrevented = true
},
},
)

if (defaultPrevented) return undefined

const result = (await prompt({
sessionID: input.sessionID,
messageID: input.messageID,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface Hooks {
"permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
"command.execute.before"?: (
input: { command: string; sessionID: string; arguments: string },
output: { parts: Part[] },
output: { parts: Part[]; preventDefault(): void },
) => Promise<void>
"tool.execute.before"?: (
input: { tool: string; sessionID: string; callID: string },
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3504,6 +3504,10 @@ export type SessionCommandResponses = {
info: AssistantMessage
parts: Array<Part>
}
/**
* Command execution was prevented by a plugin
*/
204: void
}

export type SessionCommandResponse = SessionCommandResponses[keyof SessionCommandResponses]
Expand Down