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

Function parseHookOutput

source code/utils/hooks.ts:401–453  ·  view source on GitHub ↗
(stdout: string)

Source from the content-addressed store, hash-verified

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

Callers 2

executeHooksFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Calls 3

logForDebuggingFunction · 0.85
validateHookJsonFunction · 0.85
jsonStringifyFunction · 0.85

Tested by

no test coverage detected