Personal Telegram developer console for GitHub

feat: audit approval lifecycle without logging tokens

davoodmehraban89 committed Oct 3, 2026 at 06:17 UTC d83a3dc39650a43ec31ec0eb34e8ded4d4493db3
1 file changed +33 -4
src/bot.js
+33 -4
@@ -121,11 +121,32 @@ export class NexaDevBot {
121 throw new Error('Approval owner is required');
122 }
123 const token = data.slice('approve:'.length);
124 - const payload = await this.approvals.consume(token, {
125 - ownerId: String(ownerId),
126 - pluginId: 'github',
127 - risk: 'WRITE'
124 + let payload;
125 + try {
126 + payload = await this.approvals.consume(token, {
127 + ownerId: String(ownerId),
128 + pluginId: 'github',
129 + risk: 'WRITE'
130 + });
131 + } catch (error) {
132 + this.audit.log({
133 + event: 'approval_rejected',
134 + pluginId: 'github',
135 + risk: 'WRITE',
136 + outcome: 'rejected',
137 + error: error?.message || 'Approval rejected'
138 + });
139 + throw error;
140 + }
141 +
142 + this.audit.log({
143 + event: 'approval_verified',
144 + pluginId: payload.pluginId,
145 + actionId: payload.actionId,
146 + risk: payload.risk,
147 + outcome: 'verified'
148 });
149 +
150 const sourceCallback = approvalSourceCallback(payload);
151 const routed = await this.router.dispatchCallback(sourceCallback, {
152 isOwner: true,
@@ -172,6 +193,14 @@ export class NexaDevBot {
193 ownerId: String(ownerId),
194 input: approval.input
195 });
196 + this.audit.log({
197 + event: 'approval_issued',
198 + pluginId: routed.pluginId,
199 + actionId: routed.actionId,
200 + risk: routed.risk,
201 + outcome: 'pending'
202 + });
203 +
204 const view = approvalView({
205 label: approval.label || routed.actionId,
206 token,