@memnexus-ai/mx-agent-cli 0.1.297 → 0.1.298

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/agent-config/hooks/gh-pr-edit-guard.sh +21 -9
  2. package/dist/agent-config/settings.json +7 -1
  3. package/dist/commands/check.d.ts +20 -0
  4. package/dist/commands/check.d.ts.map +1 -0
  5. package/dist/commands/check.js +30 -0
  6. package/dist/commands/check.js.map +1 -0
  7. package/dist/commands/gh.d.ts +38 -0
  8. package/dist/commands/gh.d.ts.map +1 -0
  9. package/dist/commands/gh.js +162 -0
  10. package/dist/commands/gh.js.map +1 -0
  11. package/dist/commands/git-credential.d.ts +22 -0
  12. package/dist/commands/git-credential.d.ts.map +1 -0
  13. package/dist/commands/git-credential.js +53 -0
  14. package/dist/commands/git-credential.js.map +1 -0
  15. package/dist/commands/new.d.ts +24 -0
  16. package/dist/commands/new.d.ts.map +1 -1
  17. package/dist/commands/new.js +56 -5
  18. package/dist/commands/new.js.map +1 -1
  19. package/dist/commands/pr-set-body.d.ts +120 -35
  20. package/dist/commands/pr-set-body.d.ts.map +1 -1
  21. package/dist/commands/pr-set-body.js +343 -108
  22. package/dist/commands/pr-set-body.js.map +1 -1
  23. package/dist/commands/pr-sync.d.ts +2 -1
  24. package/dist/commands/pr-sync.d.ts.map +1 -1
  25. package/dist/commands/pr-sync.js +129 -32
  26. package/dist/commands/pr-sync.js.map +1 -1
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +82 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/lib/check-run.d.ts +131 -0
  32. package/dist/lib/check-run.d.ts.map +1 -0
  33. package/dist/lib/check-run.js +291 -0
  34. package/dist/lib/check-run.js.map +1 -0
  35. package/dist/lib/coordination-token.d.ts +33 -1
  36. package/dist/lib/coordination-token.d.ts.map +1 -1
  37. package/dist/lib/coordination-token.js +138 -9
  38. package/dist/lib/coordination-token.js.map +1 -1
  39. package/dist/lib/gh-remote.d.ts +20 -0
  40. package/dist/lib/gh-remote.d.ts.map +1 -1
  41. package/dist/lib/gh-remote.js +26 -0
  42. package/dist/lib/gh-remote.js.map +1 -1
  43. package/dist/lib/gh-token-run.d.ts +551 -0
  44. package/dist/lib/gh-token-run.d.ts.map +1 -0
  45. package/dist/lib/gh-token-run.js +1246 -0
  46. package/dist/lib/gh-token-run.js.map +1 -0
  47. package/dist/lib/git-credential.d.ts +120 -0
  48. package/dist/lib/git-credential.d.ts.map +1 -0
  49. package/dist/lib/git-credential.js +204 -0
  50. package/dist/lib/git-credential.js.map +1 -0
  51. package/dist/lib/github-app-token.d.ts +288 -0
  52. package/dist/lib/github-app-token.d.ts.map +1 -0
  53. package/dist/lib/github-app-token.js +519 -0
  54. package/dist/lib/github-app-token.js.map +1 -0
  55. package/dist/lib/memory.d.ts.map +1 -1
  56. package/dist/lib/memory.js +35 -2
  57. package/dist/lib/memory.js.map +1 -1
  58. package/dist/lib/repo-guard-state-dirs.d.ts +39 -0
  59. package/dist/lib/repo-guard-state-dirs.d.ts.map +1 -0
  60. package/dist/lib/repo-guard-state-dirs.js +170 -0
  61. package/dist/lib/repo-guard-state-dirs.js.map +1 -0
  62. package/package.json +1 -1
@@ -0,0 +1,519 @@
1
+ /**
2
+ * github-app-token -- mint an mx-bott installation token in-process (#440, v51).
3
+ *
4
+ * WHAT THIS DOES. Reads mx-bott's private key from the dev Key Vault, signs a
5
+ * GitHub App JWT (RS256) with node:crypto, looks up the installation on this
6
+ * repository, and exchanges the JWT for an installation token scoped to ONE
7
+ * repository and a fixed permission set. The token is returned to the caller
8
+ * as a value in process memory and goes nowhere else.
9
+ *
10
+ * FIXED, NO OVERRIDES IN THIS MODULE. The vault, the secret name, the API base,
11
+ * the app id and the repository are constants below. This module reads no flag,
12
+ * environment variable, config value or parameter that names a different
13
+ * vault, secret, host or repository (v51 plan revision 1, Must Fix 1; the same
14
+ * rule `vault.ts` states for its probe). The permission sets are a closed map
15
+ * keyed by purpose, so a caller can pick one of four named sets and cannot
16
+ * widen any of them.
17
+ *
18
+ * WHAT THAT DOES NOT COVER. Environment variables read by Node and by `az`
19
+ * still affect transport and the vault read, and this module does not clear
20
+ * them: NODE_TLS_REJECT_UNAUTHORIZED and NODE_EXTRA_CA_CERTS change TLS trust,
21
+ * NODE_OPTIONS can load code into this process, HTTPS_PROXY and similar can
22
+ * route `az`'s traffic, and AZURE_CONFIG_DIR and AZURE_CORE_* change which `az`
23
+ * login and settings are used. Anyone who can set those for this process can
24
+ * already read the key from the vault with the same `az` login.
25
+ *
26
+ * RESIDUAL RISK, NOT REMOVED. The PEM, the JWT and the token are JavaScript
27
+ * strings. Node cannot zero a string, so each stays in the heap until garbage
28
+ * collection reuses the memory. A core dump, a heap snapshot or swapped-out
29
+ * pages from this process can hold them. The exposure is one short-lived CLI
30
+ * invocation per check post. The product owner accepted the key's org-wide
31
+ * reach on 2026-10-17 (#440 comment 6268940374).
32
+ *
33
+ * THE ONE CHILD PROCESS. `az keyvault secret show ... --query value -o tsv`,
34
+ * argv in vaultReadArgv(), run with execFileSync: no shell, stdin ignored,
35
+ * stdout piped into this process, stderr ignored, a timeout and a maxBuffer,
36
+ * the environment not overridden, never `--debug` or `--verbose`. This is the
37
+ * shape of `defaultFetchSecret` in coordination-token.ts.
38
+ *
39
+ * WHY `show` IS ALLOWED HERE AND NOT IN vault.ts. The 2026-08-22 security
40
+ * ruling in vault.ts forbids `show` in the probe module because that module
41
+ * must never hold a value. This module must hold the key to sign the JWT, so
42
+ * the ruling does not cover it. The security-reviewer rules on holding the PEM
43
+ * in memory here as a v51 merge condition. The PEM is passed straight from
44
+ * fetchPrivateKey() into buildAppJwt() inside mintInstallationToken() and is
45
+ * not stored in any variable that outlives that call.
46
+ *
47
+ * NO ECHO. No error, log line or return value includes the key, the JWT, the
48
+ * token, or any HTTP response body (a 4xx body can echo request material).
49
+ * Errors name the step and, for HTTP, the status code only. Nothing is printed
50
+ * and nothing is written to a file.
51
+ *
52
+ * TRANSPORT. Node's global fetch, in this process. Never `gh`, `curl`, a child
53
+ * process, or a GH_TOKEN / GITHUB_TOKEN environment variable.
54
+ *
55
+ * REVOKE (#440 v59, #707 item 3). revokeInstallationToken() sends one
56
+ * `DELETE /installation/token` with the token as its bearer, through the same
57
+ * githubRequest() transport as the mint: the fixed GITHUB_API_BASE, the same
58
+ * headers, `redirect: 'error'`, Node's global fetch. Its own bound is
59
+ * REVOKE_TIMEOUT_MS. It is the first request in which this process sends an
60
+ * installation token, rather than the app JWT, over the network.
61
+ *
62
+ * BODY BOUND (#440 v61, #707). Every JSON body this module and check-run.ts
63
+ * read goes through readJsonBounded(): BODY_TIMEOUT_MS from the start of the
64
+ * read, then the body is cancelled through the reader that holds it and the
65
+ * caller's own error is thrown. The requests themselves are unchanged.
66
+ *
67
+ * FAIL CLOSED. Every failure throws a GitHubAppTokenError with a named code.
68
+ * There is no fallback key source and no degraded mode.
69
+ */
70
+ import { execFileSync } from 'node:child_process';
71
+ import { createPrivateKey, createSign } from 'node:crypto';
72
+ import { KEYVAULT_NAME } from './coordination-token.js';
73
+ /** The vault holding mx-bott's key. Imported, never configurable. */
74
+ export const APP_KEY_VAULT = KEYVAULT_NAME;
75
+ /** The secret name the product owner places the key under (#440 comment 6268949499). */
76
+ export const APP_KEY_SECRET_NAME = 'mx-bott-private-key';
77
+ /** GitHub REST base. Fixed: a token request must never go to another host. */
78
+ export const GITHUB_API_BASE = 'https://api.github.com';
79
+ /** mx-bott's app id, the JWT `iss` claim (#440 comment 6241758031). */
80
+ export const APP_ID = 2258107;
81
+ /** The one repository tokens are minted for. */
82
+ export const REPO_OWNER = 'memnexus-ai';
83
+ export const REPO_NAME = 'mx-agent-framework';
84
+ /** Bounds on the `az` read, so a hung or chatty `az` cannot stall or fill memory. */
85
+ export const VAULT_READ_TIMEOUT_MS = 30_000;
86
+ /** An RSA-4096 PEM is about 3.3 KB; 64 KB leaves room and still bounds the read. */
87
+ export const VAULT_READ_MAX_BUFFER = 64 * 1024;
88
+ /**
89
+ * Per-request bound on the GitHub calls (AbortSignal.timeout). It ends a wait
90
+ * for the headers. It does not reliably end a body read: v61 Step 1 measured
91
+ * it failing to once garbage collection ran, so BODY_TIMEOUT_MS bounds bodies.
92
+ */
93
+ export const HTTP_TIMEOUT_MS = 15_000;
94
+ /**
95
+ * Bound on reading one JSON response body (#440 v61, #707; plan comment
96
+ * 6284328596, revision 1 comment 6284349941). The timer starts when the body
97
+ * read starts, after the headers, so a request whose body is read is bounded
98
+ * at HTTP_TIMEOUT_MS + BODY_TIMEOUT_MS, 30 s. These bodies are small JSON
99
+ * documents; the bound is per read, not a total (#564 is the opposite risk).
100
+ */
101
+ export const BODY_TIMEOUT_MS = 15_000;
102
+ /**
103
+ * Cap on one JSON response body, 1 MiB (#440 v61 revision 3, #707 comment
104
+ * 6297162580). The token, installation, comment and check-run bodies read
105
+ * here are small JSON documents, far under the cap. Without
106
+ * a cap the read kept running after the bound fired: the red-team measured a
107
+ * 1.1 GB body delaying the revoke to 20.4 s and a larger one crashing V8
108
+ * before any revoke (relayed by the lead in that comment). Over the cap the
109
+ * reader is cancelled and the read gives the not-received outcome, the same
110
+ * as a stall.
111
+ */
112
+ export const MAX_BODY_BYTES = 1024 * 1024;
113
+ /**
114
+ * Bound on the token revoke (v59 plan revision 1, S2). Every `mx-agent gh` call
115
+ * waits for the revoke, so a short bound limits the delay a slow network adds.
116
+ * A revoke that times out leaves the token's 1-hour lifetime, as before v59.
117
+ */
118
+ export const REVOKE_TIMEOUT_MS = 5_000;
119
+ /**
120
+ * JWT window. GitHub refuses an `exp` more than 10 minutes in the future and
121
+ * recommends backdating `iat` 60 s for clock drift. exp - iat is 600 s exactly.
122
+ */
123
+ export const JWT_IAT_BACKDATE_S = 60;
124
+ export const JWT_EXP_AHEAD_S = 540;
125
+ /** The GitHub REST API version header value this module was written against. */
126
+ export const GITHUB_API_VERSION = '2022-11-28';
127
+ /**
128
+ * The four permission sets a token can be minted with. Closed map: no caller
129
+ * supplies permissions.
130
+ *
131
+ * - `check-write` posts a check run. The v51 plan's set, unchanged.
132
+ * - `verdict-read` reads the security-review verdict comment for
133
+ * `check post --name security-review`. This repository is private, so a
134
+ * token holding only `checks: write` and `metadata: read` cannot read a pull
135
+ * request comment. GitHub's `pull_requests` permission covers "pull requests
136
+ * and related comments" (REST description, components.schemas.app-permissions).
137
+ * Kept as a separate token so the check-posting token stays exactly the
138
+ * plan's set. Deviation from the plan, stated in the v51 PR body.
139
+ * - `push` lets `git push` authenticate as mx-bott through the git credential
140
+ * helper in lib/git-credential.ts (#440, v54). It holds no `workflows`
141
+ * permission, so GitHub refuses a push that changes `.github/workflows/`.
142
+ * That refusal is intended. Fetch and clone through the helper receive this
143
+ * same write-scoped token.
144
+ * - `gh` is the token `mx-agent gh` puts in one gh child's environment
145
+ * (lib/gh-token-run.ts, #440 v56). It holds no `contents: write`: the
146
+ * product owner merges and approves as himself (#440 comment 6273920817).
147
+ * `checks` and `issues` work only once the installation grants them.
148
+ * `contents: 'read'` was added in v68 by product owner decision (#757
149
+ * comment 6396745069, memory cd571fc0): gh's `pr create`, `pr checks`,
150
+ * plain `pr view` and branch lookups request fields that need it
151
+ * (measurement result, #757 comment 6397047004).
152
+ */
153
+ export const TOKEN_PERMISSIONS = {
154
+ 'check-write': { checks: 'write', metadata: 'read' },
155
+ 'verdict-read': { pull_requests: 'read', metadata: 'read' },
156
+ push: { contents: 'write', metadata: 'read' },
157
+ gh: { pull_requests: 'write', issues: 'write', checks: 'read', actions: 'read', metadata: 'read', contents: 'read' },
158
+ };
159
+ /** Every failure in this module. `message` never holds a key, JWT, token or response body. */
160
+ export class GitHubAppTokenError extends Error {
161
+ code;
162
+ constructor(code, message) {
163
+ super(`${code}: ${message}`);
164
+ this.name = 'GitHubAppTokenError';
165
+ this.code = code;
166
+ }
167
+ }
168
+ /** The ONE argv this module runs. One reviewable expression, asserted by test K4. */
169
+ export function vaultReadArgv() {
170
+ return [
171
+ 'keyvault',
172
+ 'secret',
173
+ 'show',
174
+ '--vault-name',
175
+ APP_KEY_VAULT,
176
+ '--name',
177
+ APP_KEY_SECRET_NAME,
178
+ '--query',
179
+ 'value',
180
+ '-o',
181
+ 'tsv',
182
+ ];
183
+ }
184
+ /** The options for that one call. No `env` key: `az` reads the environment unchanged. */
185
+ export function vaultReadOptions() {
186
+ return {
187
+ encoding: 'utf-8',
188
+ stdio: ['ignore', 'pipe', 'ignore'],
189
+ timeout: VAULT_READ_TIMEOUT_MS,
190
+ maxBuffer: VAULT_READ_MAX_BUFFER,
191
+ };
192
+ }
193
+ /**
194
+ * Azure CLI exit status for a missing resource on a `show` command. stderr is
195
+ * ignored (it is never read into this process), so the exit status is the only
196
+ * signal that separates "no such secret" from "cannot read the vault".
197
+ * ASSUMPTION, unverified against the live vault in v51: `az keyvault secret
198
+ * show` exits 3 for SecretNotFound, per the Azure CLI exit-code convention
199
+ * (0 success, 1 error, 2 parser error, 3 missing resource). Any other non-zero
200
+ * status, a timeout, or `az` absent reads as vault-unreadable. Both fail closed.
201
+ */
202
+ const AZ_EXIT_RESOURCE_NOT_FOUND = 3;
203
+ /** PEM shape: a BEGIN line, a body, an END line ending in KEY-----. */
204
+ const PEM_RE = /^-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----\r?\n[\s\S]+\r?\n-----END [A-Z0-9 ]*PRIVATE KEY-----$/;
205
+ /**
206
+ * Read mx-bott's private key from Key Vault. Returns the PEM. Throws a named
207
+ * error on every failure; no error quotes the value or its length.
208
+ */
209
+ export function fetchPrivateKey() {
210
+ let out;
211
+ try {
212
+ out = execFileSync('az', vaultReadArgv(), vaultReadOptions());
213
+ }
214
+ catch (err) {
215
+ const status = err?.status;
216
+ if (status === AZ_EXIT_RESOURCE_NOT_FOUND) {
217
+ throw new GitHubAppTokenError('vault-secret-missing', `secret ${APP_KEY_SECRET_NAME} was not found in vault ${APP_KEY_VAULT}. ` +
218
+ 'The product owner places it; see docs/agent-github-identity-setup.md.');
219
+ }
220
+ throw new GitHubAppTokenError('vault-unreadable', `could not read secret ${APP_KEY_SECRET_NAME} from vault ${APP_KEY_VAULT} ` +
221
+ '(az missing, not logged in, no access, timed out, or the network failed).');
222
+ }
223
+ const pem = typeof out === 'string' ? out.trim() : '';
224
+ if (pem === '') {
225
+ throw new GitHubAppTokenError('key-empty', `secret ${APP_KEY_SECRET_NAME} is empty.`);
226
+ }
227
+ if (!PEM_RE.test(pem)) {
228
+ throw new GitHubAppTokenError('key-not-pem', `secret ${APP_KEY_SECRET_NAME} is not a PEM private key with real newlines.`);
229
+ }
230
+ return pem;
231
+ }
232
+ function base64url(input) {
233
+ return Buffer.from(input).toString('base64url');
234
+ }
235
+ /**
236
+ * Sign the GitHub App JWT. RS256, iat backdated JWT_IAT_BACKDATE_S, exp
237
+ * JWT_EXP_AHEAD_S ahead, iss = APP_ID. `nowMs` exists for tests of the window.
238
+ */
239
+ export function buildAppJwt(pem, nowMs = Date.now()) {
240
+ const now = Math.floor(nowMs / 1000);
241
+ const header = { alg: 'RS256', typ: 'JWT' };
242
+ const payload = { iat: now - JWT_IAT_BACKDATE_S, exp: now + JWT_EXP_AHEAD_S, iss: String(APP_ID) };
243
+ const signingInput = `${base64url(JSON.stringify(header))}.${base64url(JSON.stringify(payload))}`;
244
+ let signature;
245
+ try {
246
+ const key = createPrivateKey({ key: pem, format: 'pem' });
247
+ signature = createSign('RSA-SHA256').update(signingInput).sign(key);
248
+ }
249
+ catch {
250
+ // The crypto error text is dropped on purpose: it is not needed and it is
251
+ // the one place key material could be described.
252
+ throw new GitHubAppTokenError('key-unusable', `secret ${APP_KEY_SECRET_NAME} could not be used to sign the app JWT.`);
253
+ }
254
+ return `${signingInput}.${base64url(signature)}`;
255
+ }
256
+ function githubHeaders(authorization) {
257
+ return {
258
+ Accept: 'application/vnd.github+json',
259
+ Authorization: authorization,
260
+ 'X-GitHub-Api-Version': GITHUB_API_VERSION,
261
+ 'User-Agent': 'mx-agent-cli',
262
+ };
263
+ }
264
+ /** One in-process request. A transport failure is a named error with no cause text. */
265
+ async function githubRequest(step, path, init, timeoutMs = HTTP_TIMEOUT_MS) {
266
+ try {
267
+ return await fetch(`${GITHUB_API_BASE}${path}`, {
268
+ method: init.method,
269
+ headers: {
270
+ ...githubHeaders(init.authorization),
271
+ ...(init.body === undefined ? {} : { 'Content-Type': 'application/json' }),
272
+ },
273
+ body: init.body === undefined ? undefined : JSON.stringify(init.body),
274
+ // A redirect would resend the Authorization header to a host this module
275
+ // did not choose. Refuse it instead of following it.
276
+ redirect: 'error',
277
+ signal: AbortSignal.timeout(timeoutMs),
278
+ });
279
+ }
280
+ catch {
281
+ throw new GitHubAppTokenError('network', `${step}: request to ${GITHUB_API_BASE} failed or timed out.`);
282
+ }
283
+ }
284
+ /** Release an unread body without reading it into this process. */
285
+ export function discardBody(res) {
286
+ try {
287
+ void res.body?.cancel().catch(() => undefined);
288
+ }
289
+ catch {
290
+ // nothing to release
291
+ }
292
+ }
293
+ /** A stream failure while the body was being received, as opposed to a parse failure. */
294
+ class BodyNotReceived extends Error {
295
+ }
296
+ /**
297
+ * Read one JSON body, bounded by `timeoutMs` from the moment this is called,
298
+ * which is after the headers (#440 v61). Settles exactly once (the settled
299
+ * guard of boundedRevoke):
300
+ *
301
+ * - the read finishes first: resolves with the parsed value and cancels the
302
+ * timer. Nothing is cancelled on this path (memory eaeab1ec: an abort after
303
+ * a successful read invalidated a body elsewhere);
304
+ * - the stream fails first: rejects with `errors.notReceived()` and cancels
305
+ * the timer. On Node 20.x in CI the request's own AbortSignal.timeout
306
+ * errors the stream at 15 s from the request start, just before this timer
307
+ * fires, so a stall can end this way; it is the same outcome as the bound;
308
+ * - the whole body arrives and is not JSON: rejects with `errors.invalid()`
309
+ * and cancels the timer;
310
+ * - the timer fires first: cancels THIS body through the reader this function
311
+ * holds, then rejects with `errors.notReceived()`. The abandoned read keeps
312
+ * its rejection handler, so a late failure after the bound is swallowed, not
313
+ * an unhandled rejection.
314
+ *
315
+ * WHY A READER CANCEL (v61 Step 1, Node 22.16.0, measured in the PR body).
316
+ * - Aborting the request's signal, whether AbortSignal.timeout or an
317
+ * AbortController this module holds, did not end the read once garbage
318
+ * collection ran after the headers, on requests made with
319
+ * `redirect: 'error'`, as every request here is. The red-team measured that
320
+ * the hang needs both: 8 of 8 hung with `redirect: 'error'` and garbage
321
+ * collection, 0 of 3 without `redirect: 'error'` (relayed in #707 comment
322
+ * 6297162580). The read then waited for undici's own body timeout, measured
323
+ * at 318 s with no signal. That matches the 301 s stall of security review
324
+ * I1 on PR #719 (comment 6284092193).
325
+ * - res.body.cancel() while res.json() reads rejects with "ReadableStream is
326
+ * locked" and ends nothing.
327
+ * - reader.cancel() on a reader this function owns ended the read within
328
+ * 40 ms of the timer, with or without garbage collection, and the server saw
329
+ * the socket close. So the body is read here, chunk by chunk, not with
330
+ * res.json().
331
+ *
332
+ * SIZE CAP. More than MAX_BODY_BYTES cancels the reader and gives
333
+ * `errors.notReceived()`. Once the read has settled by any route, the
334
+ * abandoned read stops at its next chunk and skips concat, decode and parse,
335
+ * so a body that keeps arriving after the bound costs no main-thread work.
336
+ *
337
+ * Neither error quotes the body or the underlying error.
338
+ */
339
+ export function readJsonBounded(res, timeoutMs, setTimer, errors) {
340
+ return new Promise((resolve, reject) => {
341
+ let settled = false;
342
+ let reader;
343
+ let cancelTimer = () => undefined;
344
+ const settle = (fn) => {
345
+ if (settled)
346
+ return;
347
+ settled = true;
348
+ cancelTimer();
349
+ fn();
350
+ };
351
+ cancelTimer = setTimer(timeoutMs, () => {
352
+ if (settled)
353
+ return;
354
+ settled = true;
355
+ try {
356
+ // This reader holds the lock, so its cancel is the one that releases
357
+ // the stream and the connection.
358
+ void reader?.cancel().catch(() => undefined);
359
+ }
360
+ catch {
361
+ // nothing more to release
362
+ }
363
+ reject(errors.notReceived());
364
+ });
365
+ const read = (async () => {
366
+ if (res.body === null)
367
+ throw new Error('no body');
368
+ const own = res.body.getReader();
369
+ reader = own;
370
+ let chunks = [];
371
+ let total = 0;
372
+ try {
373
+ for (;;) {
374
+ const { done, value } = await own.read();
375
+ if (done)
376
+ break;
377
+ // Settled already (the bound fired): keep nothing, parse nothing.
378
+ if (settled) {
379
+ chunks = [];
380
+ throw new BodyNotReceived();
381
+ }
382
+ total += value.byteLength;
383
+ if (total > MAX_BODY_BYTES) {
384
+ chunks = [];
385
+ try {
386
+ void own.cancel().catch(() => undefined);
387
+ }
388
+ catch {
389
+ // nothing more to release
390
+ }
391
+ throw new BodyNotReceived();
392
+ }
393
+ chunks.push(value);
394
+ }
395
+ }
396
+ catch {
397
+ throw new BodyNotReceived();
398
+ }
399
+ // The bound may have fired while the last read was pending.
400
+ if (settled)
401
+ throw new BodyNotReceived();
402
+ // TextDecoder strips a UTF-8 BOM, as res.json() does.
403
+ return JSON.parse(new TextDecoder('utf-8').decode(Buffer.concat(chunks)));
404
+ })();
405
+ // Both handlers are attached at once, so the losing read never rejects unhandled.
406
+ read.then((value) => settle(() => resolve(value)), (err) => settle(() => reject(err instanceof BodyNotReceived ? errors.notReceived() : errors.invalid())));
407
+ });
408
+ }
409
+ /** The mint's body read: bounded, `network` when the body does not arrive, `code` when it is not JSON. */
410
+ function readJson(res, code, step) {
411
+ return readJsonBounded(res, BODY_TIMEOUT_MS, realSetTimer, {
412
+ notReceived: () => new GitHubAppTokenError('network', `${step}: response body was not received.`),
413
+ invalid: () => new GitHubAppTokenError(code, `${step}: response was not JSON.`),
414
+ });
415
+ }
416
+ /**
417
+ * Mint an installation token for REPO_OWNER/REPO_NAME with the named
418
+ * permission set. Returns the token value in memory; the caller puts it in one
419
+ * Authorization header and lets it go out of scope.
420
+ */
421
+ export async function mintInstallationToken(purpose) {
422
+ const permissions = TOKEN_PERMISSIONS[purpose];
423
+ if (permissions === undefined) {
424
+ throw new GitHubAppTokenError('token-request-failed', 'unknown token purpose.');
425
+ }
426
+ // The PEM goes straight from the vault read into the signer and is not kept.
427
+ const jwt = buildAppJwt(fetchPrivateKey());
428
+ const installRes = await githubRequest('installation lookup', `/repos/${REPO_OWNER}/${REPO_NAME}/installation`, { method: 'GET', authorization: `Bearer ${jwt}` });
429
+ if (!installRes.ok)
430
+ discardBody(installRes);
431
+ if (installRes.status === 404) {
432
+ throw new GitHubAppTokenError('installation-not-found', `app ${APP_ID} is not installed on ${REPO_OWNER}/${REPO_NAME} (HTTP 404).`);
433
+ }
434
+ if (!installRes.ok) {
435
+ throw new GitHubAppTokenError('installation-lookup-failed', `installation lookup returned HTTP ${installRes.status}.`);
436
+ }
437
+ const install = (await readJson(installRes, 'installation-lookup-failed', 'installation lookup'));
438
+ const installationId = install?.id;
439
+ if (typeof installationId !== 'number' || !Number.isInteger(installationId) || installationId <= 0) {
440
+ throw new GitHubAppTokenError('installation-lookup-failed', 'installation lookup returned no integer id.');
441
+ }
442
+ const tokenRes = await githubRequest('token request', `/app/installations/${installationId}/access_tokens`, {
443
+ method: 'POST',
444
+ authorization: `Bearer ${jwt}`,
445
+ body: { repositories: [REPO_NAME], permissions: { ...permissions } },
446
+ });
447
+ if (tokenRes.status !== 201)
448
+ discardBody(tokenRes);
449
+ if (tokenRes.status === 403 || tokenRes.status === 422) {
450
+ throw new GitHubAppTokenError('permission-not-accepted', `token request returned HTTP ${tokenRes.status}: the installation does not grant ` +
451
+ `${Object.entries(permissions).map(([k, v]) => `${k}:${v}`).join(', ')} on ${REPO_NAME}. ` +
452
+ 'The product owner accepts the permission on the mx-bott installation.');
453
+ }
454
+ if (tokenRes.status !== 201) {
455
+ throw new GitHubAppTokenError('token-request-failed', `token request returned HTTP ${tokenRes.status}.`);
456
+ }
457
+ // A 201 whose body does not arrive, or exceeds MAX_BODY_BYTES, or arrives
458
+ // in full but is not JSON or holds no token, means GitHub issued a token
459
+ // this process cannot revoke: it stays live for up to 1 hour (doc, v61).
460
+ // Bytes already received, possibly holding the token, stay in this
461
+ // process's heap until garbage collection reuses the memory.
462
+ const body = (await readJson(tokenRes, 'token-response-invalid', 'token request'));
463
+ const token = body?.token;
464
+ if (typeof token !== 'string' || token === '') {
465
+ throw new GitHubAppTokenError('token-response-invalid', 'token response held no token.');
466
+ }
467
+ return token;
468
+ }
469
+ /**
470
+ * Revoke an installation token (#440 v59, #707 item 3). Sends exactly one
471
+ * `DELETE ${GITHUB_API_BASE}/installation/token` with the token as its bearer
472
+ * and no body, bounded by REVOKE_TIMEOUT_MS. GitHub answers 204 when it
473
+ * revokes the token. Every other status is a failure, 200, 401 and 404
474
+ * included: 401 or 404 means the token was already unusable, and the caller
475
+ * reports that the same way (v59 plan revision 1, S5).
476
+ *
477
+ * Throws GitHubAppTokenError `revoke-failed` naming the status code only, or
478
+ * `network` with no cause text. The body is never read. Never logs.
479
+ */
480
+ export async function revokeInstallationToken(token) {
481
+ const res = await githubRequest('token revoke', '/installation/token', { method: 'DELETE', authorization: `Bearer ${token}` }, REVOKE_TIMEOUT_MS);
482
+ discardBody(res);
483
+ if (res.status !== 204) {
484
+ throw new GitHubAppTokenError('revoke-failed', `token revoke returned HTTP ${res.status}.`);
485
+ }
486
+ }
487
+ /** The real timer: setTimeout, cancelled with clearTimeout. */
488
+ export const realSetTimer = (ms, fn) => {
489
+ const t = setTimeout(fn, ms);
490
+ return () => clearTimeout(t);
491
+ };
492
+ /**
493
+ * Attempt `revoke(token)`, bounded by REVOKE_TIMEOUT_MS on this side as well
494
+ * as in the request (moved from gh-token-run.ts in v60, plan revision 1 S1,
495
+ * #707 comment 6283638859). Never rejects. Resolves `revoked` when the revoke
496
+ * resolves first, and `failed` when it rejects, throws, or the bound fires
497
+ * first. The settled guard makes the first of those the only result. The
498
+ * outcome holds no error text and no token.
499
+ */
500
+ export function boundedRevoke(revoke, token, setTimer) {
501
+ return new Promise((resolve) => {
502
+ let settled = false;
503
+ const done = (ok) => {
504
+ if (settled)
505
+ return;
506
+ settled = true;
507
+ cancel();
508
+ resolve(ok ? 'revoked' : 'failed');
509
+ };
510
+ const cancel = setTimer(REVOKE_TIMEOUT_MS, () => done(false));
511
+ try {
512
+ revoke(token).then(() => done(true), () => done(false));
513
+ }
514
+ catch {
515
+ done(false);
516
+ }
517
+ });
518
+ }
519
+ //# sourceMappingURL=github-app-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-app-token.js","sourceRoot":"","sources":["../../src/lib/github-app-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAE3C,wFAAwF;AACxF,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAEzD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AAExD,uEAAuE;AACvE,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;AAE9B,gDAAgD;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,oBAAoB,CAAC;AAE9C,qFAAqF;AACrF,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAC5C,oFAAoF;AACpF,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AAEtC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA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G;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAY5E;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,qBAAqB,CAAC;IAC9B,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAyBrF;AAyBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE;IAC3C,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,eAAe,CA0ClB;AA4BD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkBlD;AAsFD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAoBjE"}
@@ -1073,6 +1073,31 @@ export function classifyNamedMemoryRead(res) {
1073
1073
  : `mx exited ${res.status}${detail ? ` (${detail})` : ''}`,
1074
1074
  };
1075
1075
  }
1076
+ /**
1077
+ * Names in this repository that the `mx` key-prefix rule in redactSecrets would
1078
+ * otherwise rewrite, so a link to `memnexus-ai/mx-agent-framework` survived as
1079
+ * `mx_[REDACTED]` (#689). The real MemNexus key shape is minted outside this
1080
+ * repository and documented nowhere in it, so the rule is not narrowed; only
1081
+ * these closed words are exempt.
1082
+ */
1083
+ const OWN_REPO_NAMES = new Set([
1084
+ 'mx-agent',
1085
+ 'mx-agent-framework',
1086
+ 'mx-agent-system',
1087
+ 'mx-agent-cli',
1088
+ ]);
1089
+ /**
1090
+ * True when a key-prefix match is one of OWN_REPO_NAMES as a whole token: the
1091
+ * entire run of `[A-Za-z0-9_-]` around it equals the word. The match already
1092
+ * runs to the end of the run (its tail quantifier is greedy), so only the
1093
+ * character before it needs checking. `mx-agent-<tail>` and `x-mx-agent` are
1094
+ * not exempt.
1095
+ */
1096
+ function isOwnRepoName(match, offset, whole) {
1097
+ if (!OWN_REPO_NAMES.has(match))
1098
+ return false;
1099
+ return offset === 0 || !/[A-Za-z0-9_-]/.test(whole[offset - 1]);
1100
+ }
1076
1101
  /**
1077
1102
  * Redact credential-shaped substrings from text that is about to be surfaced.
1078
1103
  *
@@ -1087,11 +1112,19 @@ export function classifyNamedMemoryRead(res) {
1087
1112
  */
1088
1113
  export function redactSecrets(text) {
1089
1114
  return text
1115
+ // PEM private-key blocks, including one truncated before its END line (#440).
1116
+ .replace(/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY-----|$)/g, '[REDACTED PRIVATE KEY]')
1117
+ // Bare JWTs: base64url header and payload both start with `eyJ` (`{"`) (#440).
1118
+ .replace(/\beyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g, '[REDACTED JWT]')
1119
+ // GitHub fine-grained personal access tokens (#440).
1120
+ .replace(/\bgithub_pat_[A-Za-z0-9_]{8,}/g, 'github_pat_[REDACTED]')
1090
1121
  .replace(/Bearer\s+\S+/gi, 'Bearer [REDACTED]')
1091
1122
  // URL userinfo: scheme://user:password@host
1092
1123
  .replace(/\/\/[^/@\s]+:[^/@\s]+@/g, '//[REDACTED]@')
1093
- // Common API-key prefixes: mx_/mx-, sk_/sk-, ghp_, xoxb-/xoxp-/xoxa-
1094
- .replace(/\b(mx|sk|ghp|xox[bap])[-_][A-Za-z0-9_-]{8,}/g, '$1_[REDACTED]')
1124
+ // Common API-key prefixes: mx_/mx-, sk_/sk-, GitHub ghp_/gho_/ghu_/ghs_/ghr_
1125
+ // (ghs_ is an app installation token, #440), xoxb-/xoxp-/xoxa-
1126
+ // The broad mx rule stays; only this repository's own names are kept (#689).
1127
+ .replace(/\b(mx|sk|gh[pousr]|xox[bap])[-_][A-Za-z0-9_-]{8,}/g, (match, prefix, offset, whole) => isOwnRepoName(match, offset, whole) ? match : `${prefix}_[REDACTED]`)
1095
1128
  // Labelled secrets, bare and JSON/YAML-quoted — see LABELLED_SECRET_RE.
1096
1129
  .replace(LABELLED_SECRET_RE, '$1[REDACTED]');
1097
1130
  }