( tool: ToolType, messageId: string, source: PermissionApprovalSource | 'config', waitMs: number | undefined, )
| 105 | |
| 106 | // Emits a distinct analytics event name per approval source for funnel analysis |
| 107 | function logApprovalEvent( |
| 108 | tool: ToolType, |
| 109 | messageId: string, |
| 110 | source: PermissionApprovalSource | 'config', |
| 111 | waitMs: number | undefined, |
| 112 | ): void { |
| 113 | if (source === 'config') { |
| 114 | // Auto-approved by allowlist in settings -- no user wait time |
| 115 | logEvent( |
| 116 | 'tengu_tool_use_granted_in_config', |
| 117 | baseMetadata(messageId, tool.name, undefined), |
| 118 | ) |
| 119 | return |
| 120 | } |
| 121 | if ( |
| 122 | (feature('BASH_CLASSIFIER') || feature('TRANSCRIPT_CLASSIFIER')) && |
| 123 | source.type === 'classifier' |
| 124 | ) { |
| 125 | logEvent( |
| 126 | 'tengu_tool_use_granted_by_classifier', |
| 127 | baseMetadata(messageId, tool.name, waitMs), |
| 128 | ) |
| 129 | return |
| 130 | } |
| 131 | switch (source.type) { |
| 132 | case 'user': |
| 133 | logEvent( |
| 134 | source.permanent |
| 135 | ? 'tengu_tool_use_granted_in_prompt_permanent' |
| 136 | : 'tengu_tool_use_granted_in_prompt_temporary', |
| 137 | baseMetadata(messageId, tool.name, waitMs), |
| 138 | ) |
| 139 | break |
| 140 | case 'hook': |
| 141 | logEvent('tengu_tool_use_granted_by_permission_hook', { |
| 142 | ...baseMetadata(messageId, tool.name, waitMs), |
| 143 | permanent: source.permanent ?? false, |
| 144 | }) |
| 145 | break |
| 146 | default: |
| 147 | break |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // Rejections share a single event name, differentiated by metadata fields |
| 152 | function logRejectionEvent( |
no test coverage detected