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

Function parseHookOutput

src/utils/hooks.ts:400–452  ·  view source on GitHub ↗
(stdout: string)

Source from the content-addressed store, hash-verified

398}
399
400function parseHookOutput(stdout: string): {
401 json?: HookJSONOutput
402 plainText?: string
403 validationError?: string
404} {
405 const trimmed = stdout.trim()
406 if (!trimmed.startsWith('{')) {
407 logForDebugging('Hook output does not start with {, treating as plain text')
408 return { plainText: stdout }
409 }
410
411 try {
412 const result = validateHookJson(trimmed)
413 if ('json' in result) {
414 return result
415 }
416 // For command hooks, include the schema hint in the error message
417 const errorMessage = `${result.validationError}\n\nExpected schema:\n${jsonStringify(
418 {
419 continue: 'boolean (optional)',
420 suppressOutput: 'boolean (optional)',
421 stopReason: 'string (optional)',
422 decision: '"approve" | "block" (optional)',
423 reason: 'string (optional)',
424 systemMessage: 'string (optional)',
425 permissionDecision: '"allow" | "deny" | "ask" (optional)',
426 hookSpecificOutput: {
427 'for PreToolUse': {
428 hookEventName: '"PreToolUse"',
429 permissionDecision: '"allow" | "deny" | "ask" (optional)',
430 permissionDecisionReason: 'string (optional)',
431 updatedInput: 'object (optional) - Modified tool input to use',
432 },
433 'for UserPromptSubmit': {
434 hookEventName: '"UserPromptSubmit"',
435 additionalContext: 'string (required)',
436 },
437 'for PostToolUse': {
438 hookEventName: '"PostToolUse"',
439 additionalContext: 'string (optional)',
440 },
441 },
442 },
443 null,
444 2,
445 )}`
446 logForDebugging(errorMessage)
447 return { plainText: stdout, validationError: errorMessage }
448 } catch (e) {
449 logForDebugging(`Failed to parse hook output as JSON: ${e}`)
450 return { plainText: stdout }
451 }
452}
453
454function parseHttpHookOutput(body: string): {
455 json?: HookJSONOutput

Callers 2

executeHooksFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Calls 3

validateHookJsonFunction · 0.85
jsonStringifyFunction · 0.85
logForDebuggingFunction · 0.70

Tested by

no test coverage detected