MCPcopy Create free account
hub / github.com/Noumena-Network/code / parseElicitationHookOutput

Function parseElicitationHookOutput

src/utils/hooks.ts:4392–4472  ·  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

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