Skip to content
Merged
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
11 changes: 10 additions & 1 deletion packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ const layer = Layer.effect(
(part) => part.type !== "file" || !inputFiles.has(fileURLToPath(part.url)),
)
const isSubtask = (agent.mode === "subagent" && cmd.subtask !== false) || cmd.subtask === true
const parts = isSubtask
let parts = isSubtask
? [
{
type: "subtask" as const,
Expand All @@ -1477,6 +1477,15 @@ const layer = Layer.effect(
{ command: input.command, sessionID: input.sessionID, arguments: input.arguments },
{ parts },
)
const decidedCommand = yield* events.waterfall(SessionEvent.Command.PreExecute, [
(_e, next) =>
Effect.gen(function* () {
const downstream = yield* next()
const downstreamParts = (downstream as { parts?: typeof parts } | undefined)?.parts
return { parts: downstreamParts ?? parts }
}),
])
parts = (decidedCommand as { parts: typeof parts }).parts

const result = yield* prompt({
sessionID: input.sessionID,
Expand Down
23 changes: 23 additions & 0 deletions packages/schema/src/session-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,29 @@ export namespace Permission {
export type Requested = typeof Requested.Type
}

export namespace Command {
const CommandBase = {
...Base,
command: Schema.String,
}

/**
* Live waterfall fired before a slash command runs. Listeners return
* `{ parts }` to rewrite the prompt payload, or throw to veto. This is
* the V2 replacement for the legacy V1 `command.execute.before` hook
* and gives plugins proper deny/transform semantics with `next()`.
*/
export const PreExecute = Event.define({
type: "session.next.command.pre_execute",
schema: {
...CommandBase,
arguments: Schema.String,
parts: Schema.Array(Schema.Unknown),
},
})
export type PreExecute = typeof PreExecute.Type
}

export const Retried = Event.define({
type: "session.next.retried",
...options,
Expand Down
Loading