MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseElicitationHookOutput

Function parseElicitationHookOutput

source code/utils/hooks.ts:4390–4470  ·  view source on GitHub ↗

* Parse elicitation-specific fields from a HookOutsideReplResult. * Mirrors the relevant branches of processHookJSONOutput for Elicitation * and ElicitationResult hook events.

(
  result: HookOutsideReplResult,
  expectedEventName: 'Elicitation' | 'ElicitationResult',
)

Source from the content-addressed store, hash-verified

4388 * and ElicitationResult hook events.
4389 */
4390function parseElicitationHookOutput(
4391 result: HookOutsideReplResult,
4392 expectedEventName: 'Elicitation' | 'ElicitationResult',
4393): {
4394 response?: ElicitationResponse
4395 blockingError?: HookBlockingError
4396} {
4397 // Exit code 2 = blocking (same as executeHooks path)
4398 if (result.blocked && !result.succeeded) {
4399 return {
4400 blockingError: {
4401 blockingError: result.output || `Elicitation blocked by hook`,
4402 command: result.command,
4403 },
4404 }
4405 }
4406
4407 if (!result.output.trim()) {
4408 return {}
4409 }
4410
4411 // Try to parse JSON output for structured elicitation response
4412 const trimmed = result.output.trim()
4413 if (!trimmed.startsWith('{')) {
4414 return {}
4415 }
4416
4417 try {
4418 const parsed = hookJSONOutputSchema().parse(JSON.parse(trimmed))
4419 if (isAsyncHookJSONOutput(parsed)) {
4420 return {}
4421 }
4422 if (!isSyncHookJSONOutput(parsed)) {
4423 return {}
4424 }
4425
4426 // Check for top-level decision: 'block' (exit code 0 + JSON block)
4427 if (parsed.decision === 'block' || result.blocked) {
4428 return {
4429 blockingError: {
4430 blockingError: parsed.reason || 'Elicitation blocked by hook',
4431 command: result.command,
4432 },
4433 }
4434 }
4435
4436 const specific = parsed.hookSpecificOutput
4437 if (!specific || specific.hookEventName !== expectedEventName) {
4438 return {}
4439 }
4440
4441 if (!specific.action) {
4442 return {}
4443 }
4444
4445 const response: ElicitationResponse = {
4446 action: specific.action,
4447 content: specific.content as ElicitationResponse['content'] | undefined,

Callers 2

executeElicitationHooksFunction · 0.85

Calls 2

isAsyncHookJSONOutputFunction · 0.85
isSyncHookJSONOutputFunction · 0.85

Tested by

no test coverage detected