Personal Telegram developer console for GitHub
feat: add compact workspace commit approval codec
davoodmehraban89 committed
Oct 3, 2026 at 13:29 UTC
efab80caec378f2b5ad54a8d4e1c54a1277920b0
1 file changed
+36
-11
src/core/approval.js
+36
-11
@@ -1,16 +1,25 @@
1
const encoder = new TextEncoder();
2
const SIGNING_DOMAIN = 'nexa-approval-v1';
3
+const INTENT_ID_PATTERN = /^[A-Za-z0-9_-]{8}$/;
4
5
const DEFAULT_CODECS = new Map([
6
['github.workflow.run.rerun_failed', {
7
code: 'r',
8
pluginId: 'github',
8
- risk: 'WRITE'
9
+ risk: 'WRITE',
10
+ target: 'run'
11
}],
12
['github.workflow.run.cancel', {
13
code: 'c',
14
pluginId: 'github',
13
- risk: 'WRITE'
15
+ risk: 'WRITE',
16
+ target: 'run'
17
+ }],
18
+ ['github.workspace.commit_branch', {
19
+ code: 'e',
20
+ pluginId: 'github',
21
+ risk: 'WRITE',
22
+ target: 'intent'
23
}]
24
]);
25
@@ -161,19 +170,29 @@ export class ApprovalService {
170
#encodeBody(payload) {
171
const codec = compactCodecFor(payload.actionId);
172
const repoId = payload.input?.repoId;
164
- const runId = payload.input?.runId;
173
if (
174
codec &&
175
codec.pluginId === payload.pluginId &&
176
codec.risk === payload.risk &&
169
- Number.isSafeInteger(Number(repoId)) &&
170
- Number.isSafeInteger(Number(runId))
177
+ Number.isSafeInteger(Number(repoId))
178
) {
179
+ let target;
180
+ if (codec.target === 'run') {
181
+ const runId = payload.input?.runId;
182
+ if (!Number.isSafeInteger(Number(runId))) return `j.${textToBase64Url(JSON.stringify(payload))}`;
183
+ target = toBase36Int(runId);
184
+ } else if (codec.target === 'intent') {
185
+ const intentId = String(payload.input?.intentId || '');
186
+ if (!INTENT_ID_PATTERN.test(intentId)) throw new Error('Invalid approval intent ID');
187
+ target = intentId;
188
+ } else {
189
+ return `j.${textToBase64Url(JSON.stringify(payload))}`;
190
+ }
191
return [
192
'1',
193
codec.code,
194
toBase36Int(repoId),
176
- toBase36Int(runId),
195
+ target,
196
toBase36Int(payload.expiresAt),
197
payload.nonce
198
].join('.');
@@ -196,20 +215,26 @@ export class ApprovalService {
215
216
const parts = body.split('.');
217
if (parts.length !== 6 || parts[0] !== '1') throw new Error('Invalid approval payload');
199
- const [, code, repoPart, runPart, expiryPart, nonce] = parts;
218
+ const [, code, repoPart, targetPart, expiryPart, nonce] = parts;
219
const codec = compactCodecByCode(code);
220
if (!codec) throw new Error('Invalid approval action');
221
const expiresAt = fromBase36Int(expiryPart);
222
+ const input = { repoId: fromBase36Int(repoPart) };
223
+ if (codec.target === 'run') {
224
+ input.runId = fromBase36Int(targetPart);
225
+ } else if (codec.target === 'intent') {
226
+ if (!INTENT_ID_PATTERN.test(targetPart)) throw new Error('Invalid approval intent ID');
227
+ input.intentId = targetPart;
228
+ } else {
229
+ throw new Error('Invalid approval target');
230
+ }
231
return {
232
v: 1,
233
pluginId: codec.pluginId,
234
actionId: codec.actionId,
235
risk: codec.risk,
236
ownerId,
209
- input: {
210
- repoId: fromBase36Int(repoPart),
211
- runId: fromBase36Int(runPart)
212
- },
237
+ input,
238
issuedAt: expiresAt - this.ttlMs,
239
expiresAt,
240
nonce