(input: ResolveApprovalInput)
| 54 | |
| 55 | /** Resolve a harness permission request against policy + client approvals. */ |
| 56 | export function resolveApproval(input: ResolveApprovalInput): ApprovalOutcome { |
| 57 | const base = |
| 58 | input.command !== undefined |
| 59 | ? evaluateCommand(input.command, input.policy, input.scripts) |
| 60 | : input.capability !== undefined |
| 61 | ? (input.policy?.capabilities?.[input.capability] ?? |
| 62 | input.policy?.default ?? |
| 63 | 'ask') |
| 64 | : (input.policy?.default ?? 'ask') |
| 65 | |
| 66 | if (base === 'allow') return { decision: 'allow', needsApproval: false } |
| 67 | if (base === 'deny') return { decision: 'deny', needsApproval: false } |
| 68 | |
| 69 | // base === 'ask' — consult the client's decision. |
| 70 | const granted = input.approvals?.get(input.id) |
| 71 | if (granted === true) return { decision: 'allow', needsApproval: false } |
| 72 | if (granted === false) return { decision: 'deny', needsApproval: false } |
| 73 | return { decision: 'deny', needsApproval: true } |
| 74 | } |
| 75 | |
| 76 | /** Build the AG-UI `approval-requested` CUSTOM event for a harness action. */ |
| 77 | export function buildApprovalRequestedEvent(input: { |
no test coverage detected