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

Function processHookJSONOutput

src/utils/hooks.ts:490–738  ·  view source on GitHub ↗
({
  json,
  command,
  hookName,
  toolUseID,
  hookEvent,
  expectedHookEvent,
  stdout,
  stderr,
  exitCode,
  durationMs,
}: {
  json: SyncHookJSONOutput
  command: string
  hookName: string
  toolUseID: string
  hookEvent: HookEvent
  expectedHookEvent?: HookEvent
  stdout?: string
  stderr?: string
  exitCode?: number
  durationMs?: number
})

Source from the content-addressed store, hash-verified

488}
489
490function processHookJSONOutput({
491 json,
492 command,
493 hookName,
494 toolUseID,
495 hookEvent,
496 expectedHookEvent,
497 stdout,
498 stderr,
499 exitCode,
500 durationMs,
501}: {
502 json: SyncHookJSONOutput
503 command: string
504 hookName: string
505 toolUseID: string
506 hookEvent: HookEvent
507 expectedHookEvent?: HookEvent
508 stdout?: string
509 stderr?: string
510 exitCode?: number
511 durationMs?: number
512}): Partial<HookResult> {
513 const result: Partial<HookResult> = {}
514
515 // At this point we know it's a sync response
516 const syncJson = json
517
518 // Handle common elements
519 if (syncJson.continue === false) {
520 result.preventContinuation = true
521 if (syncJson.stopReason) {
522 result.stopReason = syncJson.stopReason
523 }
524 }
525
526 if (json.decision) {
527 switch (json.decision) {
528 case 'approve':
529 result.permissionBehavior = 'allow'
530 break
531 case 'block':
532 result.permissionBehavior = 'deny'
533 result.blockingError = {
534 blockingError: json.reason || 'Blocked by hook',
535 command,
536 }
537 break
538 default:
539 // Handle unknown decision types as errors
540 throw new Error(
541 `Unknown hook decision type: ${json.decision}. Valid types are: approve, block`,
542 )
543 }
544 }
545
546 // Handle systemMessage field
547 if (json.systemMessage) {

Callers 2

executeHooksFunction · 0.85
executeHookCallbackFunction · 0.85

Calls 2

jsonStringifyFunction · 0.85
createAttachmentMessageFunction · 0.70

Tested by

no test coverage detected