( stdout: string, )
| 151 | } |
| 152 | |
| 153 | function structuredOutput( |
| 154 | stdout: string, |
| 155 | ): { action?: 'block'; reason?: string; message?: string; structuredOutput: true } | undefined { |
| 156 | const text = stdout.trim(); |
| 157 | if (text.length === 0) return undefined; |
| 158 | |
| 159 | try { |
| 160 | const parsed = JSON.parse(text) as unknown; |
| 161 | const output = HookJsonOutputSchema.safeParse(parsed); |
| 162 | if (!output.success) return undefined; |
| 163 | |
| 164 | const { message, hookSpecificOutput } = output.data; |
| 165 | const result = { |
| 166 | message: message ?? hookSpecificOutput?.message, |
| 167 | structuredOutput: true as const, |
| 168 | }; |
| 169 | if (hookSpecificOutput?.permissionDecision !== 'deny') { |
| 170 | return result; |
| 171 | } |
| 172 | return { |
| 173 | action: 'block', |
| 174 | message: result.message, |
| 175 | reason: hookSpecificOutput.permissionDecisionReason, |
| 176 | structuredOutput: true, |
| 177 | }; |
| 178 | } catch { |
| 179 | return undefined; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | function allowResult(input: { |
| 184 | readonly message?: string; |
no outgoing calls
no test coverage detected