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
21 changes: 20 additions & 1 deletion packages/opencode/src/hook/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,16 @@ export function detectUnsupportedFields(
for (const m of matchers) {
for (const h of m.hooks ?? []) {
if (h.shell !== undefined) unsupported.push({ field: "shell", value: h.shell, eventName })
// issue #286 — schema-accepted but executor-dropped fields. Surfaced
// here instead of silently swallowed: allowedEnvVars/statusMessage have
// zero consumers anywhere; per-command `once` is never read (only the
// entry-level _sessionEntry?.once is consumed). `timeout` is NOT
// flagged — every handler type applies it (incl. prompt).
if (h.allowedEnvVars !== undefined)
unsupported.push({ field: "allowedEnvVars", value: h.allowedEnvVars, eventName })
if (h.statusMessage !== undefined)
unsupported.push({ field: "statusMessage", value: h.statusMessage, eventName })
if (h.once !== undefined) unsupported.push({ field: "once", value: h.once, eventName })
// `if` is implemented (condition-filter); async/asyncRewake implemented.
// All 5 known types now have handlers; type-level unsupported set is empty by design.
}
Expand Down Expand Up @@ -1537,10 +1547,19 @@ const promptHandler: HookHandler = {
schema: HookJSONOutputZodSchema,
} satisfies Parameters<typeof generateObject>[0]

// issue #286 — the header doc promises `timeout` for every hook type,
// but promptHandler was the only executor never applying it. Honor it
// with the same idiom as command/mcp/http; on expiry the TimeoutException
// is captured by Effect.exit below and degrades to the non-blocking warn.
const timeoutMs = entry.timeout ? entry.timeout * 1000 : DEFAULT_TIMEOUT_MS

const llmExit = yield* Effect.tryPromise({
try: () => generateObject(params).then((r) => r.object),
catch: (e) => e,
}).pipe(Effect.exit)
}).pipe(
Effect.timeout(timeoutMs),
Effect.exit,
)

if (llmExit._tag === "Failure") {
log.warn("prompt hook failed (non-blocking)", { error: String(llmExit.cause) })
Expand Down
12 changes: 12 additions & 0 deletions packages/opencode/test/hook/warn-unsupported.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ describe("detectUnsupportedFields", () => {
expect(detectUnsupportedFields(undefined)).toEqual([])
expect(detectUnsupportedFields({})).toEqual([])
})

// GOAL-FP/issue #286: HookCommand fields accepted by the schema but dropped
// by every executor must be surfaced, not silently swallowed. `timeout` for
// type "prompt" is implemented (excluded here); allowedEnvVars/statusMessage
// have zero consumers anywhere, and per-command `once` is never read (only
// the entry-level _sessionEntry?.once is consumed).
test("allowedEnvVars / statusMessage / per-command once are flagged (dropped by executors)", () => {
const unsupported = detectUnsupportedFields(
hooks({ allowedEnvVars: ["FOO"], statusMessage: "hi", once: true }),
)
expect(unsupported.map((u) => u.field).sort()).toEqual(["allowedEnvVars", "once", "statusMessage"])
})
})
Loading