@mnemom/mnemom 0.17.35 → 0.17.36

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 (94) hide show
  1. package/dist/commands/agent-run.d.ts +4 -0
  2. package/dist/commands/agent-run.js +9 -1
  3. package/dist/commands/agent-share-render.js +1 -1
  4. package/dist/commands/scan.d.ts +13 -3
  5. package/dist/commands/scan.js +48 -10
  6. package/dist/index.js +3 -2
  7. package/dist/lib/config.d.ts +7 -0
  8. package/dist/lib/config.js +21 -0
  9. package/dist/lib/scan/pr-source.js +2 -0
  10. package/dist/lib/scan/repo-picker.d.ts +32 -0
  11. package/dist/lib/scan/repo-picker.js +80 -0
  12. package/node_modules/@mnemom/aip-verifier/LICENSE +190 -0
  13. package/node_modules/@mnemom/aip-verifier/dist/claim-lint-CVITIRcU.d.cts +478 -0
  14. package/node_modules/@mnemom/aip-verifier/dist/claim-lint-CVITIRcU.d.ts +478 -0
  15. package/node_modules/@mnemom/aip-verifier/dist/index.cjs +971 -0
  16. package/node_modules/@mnemom/aip-verifier/dist/index.cjs.map +1 -0
  17. package/node_modules/@mnemom/aip-verifier/dist/index.d.cts +330 -0
  18. package/node_modules/@mnemom/aip-verifier/dist/index.d.ts +330 -0
  19. package/node_modules/@mnemom/aip-verifier/dist/index.js +933 -0
  20. package/node_modules/@mnemom/aip-verifier/dist/index.js.map +1 -0
  21. package/node_modules/@mnemom/aip-verifier/dist/render-lines.cjs +879 -0
  22. package/node_modules/@mnemom/aip-verifier/dist/render-lines.cjs.map +1 -0
  23. package/node_modules/@mnemom/aip-verifier/dist/render-lines.d.cts +96 -0
  24. package/node_modules/@mnemom/aip-verifier/dist/render-lines.d.ts +96 -0
  25. package/node_modules/@mnemom/aip-verifier/dist/render-lines.js +875 -0
  26. package/node_modules/@mnemom/aip-verifier/dist/render-lines.js.map +1 -0
  27. package/node_modules/@mnemom/aip-verifier/package.json +86 -0
  28. package/node_modules/@noble/ed25519/LICENSE +21 -0
  29. package/node_modules/@noble/ed25519/README.md +371 -0
  30. package/node_modules/@noble/ed25519/index.d.ts +391 -0
  31. package/node_modules/@noble/ed25519/index.js +933 -0
  32. package/node_modules/@noble/ed25519/index.ts +1134 -0
  33. package/node_modules/@noble/ed25519/package.json +54 -0
  34. package/node_modules/@noble/hashes/LICENSE +21 -0
  35. package/node_modules/@noble/hashes/README.md +478 -0
  36. package/node_modules/@noble/hashes/_blake.d.ts +20 -0
  37. package/node_modules/@noble/hashes/_blake.js +59 -0
  38. package/node_modules/@noble/hashes/_md.d.ts +95 -0
  39. package/node_modules/@noble/hashes/_md.js +209 -0
  40. package/node_modules/@noble/hashes/_u64.d.ts +36 -0
  41. package/node_modules/@noble/hashes/_u64.js +77 -0
  42. package/node_modules/@noble/hashes/argon2.d.ts +148 -0
  43. package/node_modules/@noble/hashes/argon2.js +577 -0
  44. package/node_modules/@noble/hashes/blake1.d.ts +162 -0
  45. package/node_modules/@noble/hashes/blake1.js +630 -0
  46. package/node_modules/@noble/hashes/blake2.d.ts +203 -0
  47. package/node_modules/@noble/hashes/blake2.js +573 -0
  48. package/node_modules/@noble/hashes/blake3.d.ts +68 -0
  49. package/node_modules/@noble/hashes/blake3.js +310 -0
  50. package/node_modules/@noble/hashes/eskdf.d.ts +91 -0
  51. package/node_modules/@noble/hashes/eskdf.js +225 -0
  52. package/node_modules/@noble/hashes/hkdf.d.ts +70 -0
  53. package/node_modules/@noble/hashes/hkdf.js +152 -0
  54. package/node_modules/@noble/hashes/hmac.d.ts +50 -0
  55. package/node_modules/@noble/hashes/hmac.js +93 -0
  56. package/node_modules/@noble/hashes/index.d.ts +1 -0
  57. package/node_modules/@noble/hashes/index.js +34 -0
  58. package/node_modules/@noble/hashes/legacy.d.ts +107 -0
  59. package/node_modules/@noble/hashes/legacy.js +348 -0
  60. package/node_modules/@noble/hashes/package.json +91 -0
  61. package/node_modules/@noble/hashes/pbkdf2.d.ts +66 -0
  62. package/node_modules/@noble/hashes/pbkdf2.js +176 -0
  63. package/node_modules/@noble/hashes/scrypt.d.ts +98 -0
  64. package/node_modules/@noble/hashes/scrypt.js +304 -0
  65. package/node_modules/@noble/hashes/sha2.d.ts +176 -0
  66. package/node_modules/@noble/hashes/sha2.js +446 -0
  67. package/node_modules/@noble/hashes/sha3-addons.d.ts +533 -0
  68. package/node_modules/@noble/hashes/sha3-addons.js +973 -0
  69. package/node_modules/@noble/hashes/sha3.d.ts +208 -0
  70. package/node_modules/@noble/hashes/sha3.js +475 -0
  71. package/node_modules/@noble/hashes/src/_blake.ts +67 -0
  72. package/node_modules/@noble/hashes/src/_md.ts +227 -0
  73. package/node_modules/@noble/hashes/src/_u64.ts +111 -0
  74. package/node_modules/@noble/hashes/src/argon2.ts +693 -0
  75. package/node_modules/@noble/hashes/src/blake1.ts +677 -0
  76. package/node_modules/@noble/hashes/src/blake2.ts +648 -0
  77. package/node_modules/@noble/hashes/src/blake3.ts +344 -0
  78. package/node_modules/@noble/hashes/src/eskdf.ts +265 -0
  79. package/node_modules/@noble/hashes/src/hkdf.ts +161 -0
  80. package/node_modules/@noble/hashes/src/hmac.ts +130 -0
  81. package/node_modules/@noble/hashes/src/index.ts +33 -0
  82. package/node_modules/@noble/hashes/src/legacy.ts +361 -0
  83. package/node_modules/@noble/hashes/src/pbkdf2.ts +219 -0
  84. package/node_modules/@noble/hashes/src/scrypt.ts +375 -0
  85. package/node_modules/@noble/hashes/src/sha2.ts +486 -0
  86. package/node_modules/@noble/hashes/src/sha3-addons.ts +1157 -0
  87. package/node_modules/@noble/hashes/src/sha3.ts +525 -0
  88. package/node_modules/@noble/hashes/src/utils.ts +978 -0
  89. package/node_modules/@noble/hashes/src/webcrypto.ts +283 -0
  90. package/node_modules/@noble/hashes/utils.d.ts +560 -0
  91. package/node_modules/@noble/hashes/utils.js +687 -0
  92. package/node_modules/@noble/hashes/webcrypto.d.ts +121 -0
  93. package/node_modules/@noble/hashes/webcrypto.js +228 -0
  94. package/package.json +5 -2
@@ -24,6 +24,8 @@ export interface RunDeps {
24
24
  env: NodeJS.ProcessEnv;
25
25
  fetch: FetchFn;
26
26
  apiUrl: string;
27
+ /** The gateway the model proxy forwards to. */
28
+ gatewayUrl: string;
27
29
  /** stdout: one outcome line per job. */
28
30
  emit(line: string): void;
29
31
  /** stderr. */
@@ -36,6 +38,8 @@ export interface RunDeps {
36
38
  }
37
39
  /** The refusal of a runner with no ANTHROPIC_API_KEY (34.30.1); a config error, exit 2. */
38
40
  export declare const RUNNER_MODEL_KEY_MISSING = "runner_model_key_missing";
41
+ /** The refusal of a non-production API paired with the production gateway; a config error, exit 2. */
42
+ export declare const RUNNER_GATEWAY_RING_MISMATCH = "runner_gateway_ring_mismatch";
39
43
  /** Resolves the process exit code; never throws for a usage, config or Mnemom error. */
40
44
  export declare function agentRunCommand(flags: RunFlags, deps: RunDeps): Promise<number>;
41
45
  export declare const GITHUB_API: string;
@@ -20,7 +20,7 @@ import { randomUUID } from "node:crypto";
20
20
  import { mkdtemp, readFile, rm } from "node:fs/promises";
21
21
  import { homedir, tmpdir } from "node:os";
22
22
  import { join } from "node:path";
23
- import { getApiUrl, getGatewayUrl } from "../lib/config.js";
23
+ import { gatewayRingMismatch, getApiUrl, getGatewayUrl } from "../lib/config.js";
24
24
  import { runnerApi } from "../lib/runner/executor-client.js";
25
25
  import { resolveClaudeBin } from "../lib/claude-bin.js";
26
26
  import { executorIdFromState } from "../lib/runner/executor-state.js";
@@ -35,6 +35,8 @@ import { resolveGithubToken } from "./agent-fuel.js";
35
35
  import { executorStatePath } from "../vendor/durable-contract/index.js";
36
36
  /** The refusal of a runner with no ANTHROPIC_API_KEY (34.30.1); a config error, exit 2. */
37
37
  export const RUNNER_MODEL_KEY_MISSING = "runner_model_key_missing";
38
+ /** The refusal of a non-production API paired with the production gateway; a config error, exit 2. */
39
+ export const RUNNER_GATEWAY_RING_MISMATCH = "runner_gateway_ring_mismatch";
38
40
  /** Resolves the process exit code; never throws for a usage, config or Mnemom error. */
39
41
  export async function agentRunCommand(flags, deps) {
40
42
  const resolved = resolveRunPlan(flags, deps.env);
@@ -45,6 +47,11 @@ export async function agentRunCommand(flags, deps) {
45
47
  const plan = resolved.plan;
46
48
  for (const w of plan.warnings)
47
49
  deps.err(w);
50
+ if (gatewayRingMismatch(deps.apiUrl, deps.gatewayUrl)) {
51
+ deps.err(`mnemom agent run: refused (${RUNNER_GATEWAY_RING_MISMATCH}): the API is ${deps.apiUrl} but the gateway is the production one, ${deps.gatewayUrl}; nothing was claimed`);
52
+ deps.err(" fix: set MNEMOM_GATEWAY_URL to the same cell's gateway as MNEMOM_API_URL");
53
+ return USAGE_EXIT_CODE;
54
+ }
48
55
  const modelKey = deps.env.ANTHROPIC_API_KEY?.trim();
49
56
  if (!modelKey) {
50
57
  deps.err(`mnemom agent run: refused (${RUNNER_MODEL_KEY_MISSING}): this runner has no ANTHROPIC_API_KEY for its phases' model calls; nothing was claimed`);
@@ -247,6 +254,7 @@ export function runAgentRun(flags) {
247
254
  env: process.env,
248
255
  fetch,
249
256
  apiUrl: getApiUrl(),
257
+ gatewayUrl: getGatewayUrl(),
250
258
  emit: (line) => process.stdout.write(`${line}\n`),
251
259
  err: (line) => process.stderr.write(`${line}\n`),
252
260
  stop: stop.signal,
@@ -20,7 +20,7 @@ async function loadVerifier(load) {
20
20
  catch (error) {
21
21
  const e = error;
22
22
  if (e.code === "ERR_MODULE_NOT_FOUND" || e.code === "MODULE_NOT_FOUND") {
23
- throw new Error("the aip verifier (@mnemom/aip-verifier) is not installed: run `npm install https://github.com/mnemom/aip/releases/download/aip-verifier-v0.6.0/mnemom-aip-verifier-0.6.0.tgz`", { cause: error });
23
+ throw new Error("the aip verifier (@mnemom/aip-verifier) is not installed: it ships bundled inside @mnemom/mnemom, so reinstall with `npm install -g @mnemom/mnemom`", { cause: error });
24
24
  }
25
25
  throw new Error(`the aip verifier (@mnemom/aip-verifier) failed to load: ${e.message ?? error}`, { cause: error });
26
26
  }
@@ -11,6 +11,7 @@ import { type AnthropicUsageDeps } from "../lib/scan/spend/anthropic-usage.js";
11
11
  import { type RecordDeps, type RecordOutcome } from "../lib/scan/record.js";
12
12
  import { type CostSpend } from "../lib/scan/cost-per-pr.js";
13
13
  import { type ReportEmailDeps } from "../lib/scan/report-email.js";
14
+ import { type RepoListDeps } from "../lib/scan/repo-picker.js";
14
15
  import { type ReportRecipients } from "../lib/scan/share.js";
15
16
  export interface ScanCommandOptions {
16
17
  repos: string[];
@@ -42,12 +43,20 @@ export interface ScanCommandOptions {
42
43
  recordDeps?: RecordDeps;
43
44
  /** Test seam: the report-email POST. */
44
45
  emailDeps?: ReportEmailDeps;
46
+ /** Test seam: the org this login was authorized for (none of the stored tokens carry one today). */
47
+ authorizedOrg?: () => string | undefined;
48
+ /** Test seam: the `mnemom org use` default. */
49
+ activeOrg?: () => {
50
+ org_id: string;
51
+ } | undefined;
45
52
  /** Test seam: the signed-in user's orgs, used to infer --org when it is omitted. */
46
53
  listOrgs?: () => Promise<Array<{
47
54
  org_id: string;
48
55
  name?: string;
49
56
  is_personal?: boolean;
50
57
  }>>;
58
+ /** Test seam: the fetch behind the repo picker's list read. */
59
+ repoListDeps?: RepoListDeps;
51
60
  /** Test seams. */
52
61
  isTty?: boolean;
53
62
  env?: NodeJS.ProcessEnv;
@@ -93,9 +102,10 @@ export declare function resolveMeasuredUsage(o: ScanCommandOptions, period: {
93
102
  } | null>;
94
103
  /**
95
104
  * --org is optional only because it can be inferred: the report is emailed on every scan, so the scan
96
- * needs an org. Inference uses the signed-in user's own memberships (GET /v1/orgs, personal org
97
- * excluded): exactly one org is used; none, several, or a failed read stops the scan loudly BEFORE any
98
- * scan work, naming the fix. It never guesses between orgs and never skips the email.
105
+ * needs an org. Order: --org; the org the login was authorized for; the `mnemom org use` default; the
106
+ * signed-in user's single non-personal membership (GET /v1/orgs); a terminal picker over several; else it
107
+ * stops loudly BEFORE any scan work, naming each org beside its id. It never guesses between orgs and
108
+ * never skips the email.
99
109
  */
100
110
  export declare function resolveScanOrg(o: ScanCommandOptions): Promise<string>;
101
111
  export declare const INVALID_ORG_MSG = "--org must be an org id like org-1a2b3c4d.";
@@ -12,10 +12,12 @@ import { isSpendTiersEnabled, NOT_ENABLED_MSG, parseMonthlySpendUsd, selectSpend
12
12
  import { ADMIN_KEY_ENV, AnthropicUsageError, fetchMeasuredUsage, isAdminKeyShape, usageFailureText, } from "../lib/scan/spend/anthropic-usage.js";
13
13
  import { getAuthInfo } from "../lib/auth.js";
14
14
  import { listMyOrgs } from "../lib/api.js";
15
+ import { getActiveOrg } from "../lib/cli-config.js";
15
16
  import { fetchRecordTotals, isOrgId, } from "../lib/scan/record.js";
16
17
  import { modelledSpend } from "../lib/scan/cost-per-pr.js";
17
18
  import { RECORD_NO_ORG_NOTE, renderRecordSection } from "../lib/scan/report.js";
18
19
  import { buildEmailBody, buildEmailReport, DRY_RUN_MSG, UNAVAILABLE_MSG, failureMessage, ReportEmailError, sendReportEmail, } from "../lib/scan/report-email.js";
20
+ import { pickRepos, REPO_PICKER_NO_TERMINAL_HINT, } from "../lib/scan/repo-picker.js";
19
21
  import { buildSharePayload, parseShareLevel, promptShareLevel, } from "../lib/scan/share.js";
20
22
  /** Parses repeated/comma-separated `--repo owner/name`. Returns null on any invalid slug. */
21
23
  export function parseRepoFlags(raw) {
@@ -126,9 +128,10 @@ export async function resolveMeasuredUsage(o, period) {
126
128
  }
127
129
  /**
128
130
  * --org is optional only because it can be inferred: the report is emailed on every scan, so the scan
129
- * needs an org. Inference uses the signed-in user's own memberships (GET /v1/orgs, personal org
130
- * excluded): exactly one org is used; none, several, or a failed read stops the scan loudly BEFORE any
131
- * scan work, naming the fix. It never guesses between orgs and never skips the email.
131
+ * needs an org. Order: --org; the org the login was authorized for; the `mnemom org use` default; the
132
+ * signed-in user's single non-personal membership (GET /v1/orgs); a terminal picker over several; else it
133
+ * stops loudly BEFORE any scan work, naming each org beside its id. It never guesses between orgs and
134
+ * never skips the email.
132
135
  */
133
136
  export async function resolveScanOrg(o) {
134
137
  if (o.org !== undefined) {
@@ -136,6 +139,18 @@ export async function resolveScanOrg(o) {
136
139
  throw new Error(INVALID_ORG_MSG);
137
140
  return o.org;
138
141
  }
142
+ // 2. The org this login was authorized for, when the token or session carries one.
143
+ const authorized = o.authorizedOrg?.();
144
+ if (authorized !== undefined) {
145
+ if (!isOrgId(authorized))
146
+ throw new Error(INVALID_ORG_MSG);
147
+ return authorized;
148
+ }
149
+ // 3. The default set with `mnemom org use <slug>` (a malformed stored id is ignored, not trusted).
150
+ const active = (o.activeOrg ?? getActiveOrg)()?.org_id;
151
+ if (active !== undefined && isOrgId(active))
152
+ return active;
153
+ // 4-6. Memberships: a single one, else a terminal picker, else fail closed.
139
154
  let orgs;
140
155
  try {
141
156
  orgs = (await (o.listOrgs ?? listMyOrgs)()).filter((x) => !x.is_personal);
@@ -147,8 +162,20 @@ export async function resolveScanOrg(o) {
147
162
  return orgs[0].org_id;
148
163
  if (orgs.length === 0)
149
164
  throw new Error("You belong to no organization, so the report has nowhere to be emailed from. Pass --org <org_id>.");
150
- throw new Error(`You belong to ${orgs.length} organizations; pass --org <org_id> (${orgs.map((x) => x.org_id).join(", ")}).`);
165
+ // Several orgs: ids alone mean nothing, so show each name beside its id. A terminal picks one; anything
166
+ // else fails closed (never a guess) with the same labels in the message.
167
+ const labels = orgs.map(orgLabel);
168
+ if (o.isTty ?? process.stdin.isTTY) {
169
+ const chosen = await askSelect("Which organization should the report be emailed for?", labels);
170
+ const hit = orgs.find((x, i) => labels[i] === chosen);
171
+ if (hit && isOrgId(hit.org_id))
172
+ return hit.org_id;
173
+ throw new Error("No organization selected. Pass --org <org_id>.");
174
+ }
175
+ throw new Error(`You belong to ${orgs.length} organizations; pass --org <org_id> (${labels.join(", ")}).`);
151
176
  }
177
+ /** "Name (org-id)", or just the id when the org has no usable name. */
178
+ const orgLabel = (x) => typeof x.name === "string" && x.name.trim() !== "" ? `${x.name.trim()} (${x.org_id})` : x.org_id;
152
179
  export const INVALID_ORG_MSG = "--org must be an org id like org-1a2b3c4d.";
153
180
  /**
154
181
  * The Record read for the preview: null when the flag gate is off (no read, no output, as before).
@@ -168,23 +195,34 @@ export async function scanCommand(o) {
168
195
  if (o.share !== undefined && parseShareLevel(o.share) === null) {
169
196
  throw new Error("--share must be one of: summary, full, none");
170
197
  }
171
- if (o.repos.length === 0)
172
- throw new Error("--repo owner/name is required (repeatable)");
198
+ const noRepoFlag = o.repos.length === 0;
199
+ // No --repo: on a terminal pick from the repos this GitHub login can read; otherwise the error stays, with a hint.
200
+ if (noRepoFlag && !(o.isTty ?? process.stdin.isTTY))
201
+ throw new Error(`--repo owner/name is required (repeatable). ${REPO_PICKER_NO_TERMINAL_HINT}`);
173
202
  // The report is emailed on every scan, so resolve the org before any scan work; failure is loud.
174
203
  const emailOrg = await resolveScanOrg(o);
175
204
  if (o.ctoEmail !== undefined && !isEmail(o.ctoEmail))
176
205
  throw new Error("--cto-email must be a valid email address");
206
+ const getCredential = async () => {
207
+ const c = o.credential ?? (await resolveCredential().catch(() => null));
208
+ if (!c)
209
+ throw new Error(failureText("credential"));
210
+ return c;
211
+ };
212
+ // Asked before the spend prompts so the repo comes first; the credential is reused for the scan.
213
+ const pickedCredential = noRepoFlag ? await getCredential() : null;
214
+ const repos = pickedCredential
215
+ ? await pickRepos(pickedCredential, { isTty: true, deps: o.repoListDeps })
216
+ : o.repos;
177
217
  const selfReported = await resolveSelfReportedSpend(o);
178
218
  const now = o.now ?? Date.now;
179
219
  const end = new Date(now()).toISOString().slice(0, 10);
180
220
  const period = o.period ?? { start: end, end };
181
221
  const measured = await resolveMeasuredUsage(o, period);
182
- const credential = o.credential ?? (await resolveCredential().catch(() => null));
183
- if (!credential)
184
- throw new Error(failureText("credential"));
222
+ const credential = pickedCredential ?? (await getCredential());
185
223
  // Before the local scan: a refused credential fails closed without spending the GitHub reads.
186
224
  const record = await resolveRecordOutcome(o);
187
- const outcome = await runLocalScan({ credential, now, ...o.deps }, { repos: o.repos, period });
225
+ const outcome = await runLocalScan({ credential, now, ...o.deps }, { repos, period });
188
226
  if (outcome.status === "withheld")
189
227
  throw new Error(`Scan withheld: ${failureText(outcome.reason)}`);
190
228
  const { result } = outcome;
package/dist/index.js CHANGED
@@ -2384,7 +2384,7 @@ program
2384
2384
  program
2385
2385
  .command("scan")
2386
2386
  .description("Read-only local scan of GitHub PR metadata; the report is emailed to you every time (counts only, no repo names) and Mnemom keeps nothing at share level none")
2387
- .option("--repo <owner/name...>", "Repo to scan (repeatable or comma-separated)")
2387
+ .option("--repo <owner/name...>", "Repo to scan (repeatable or comma-separated; omit on a terminal to pick from your repos)")
2388
2388
  .option("--start <YYYY-MM-DD>", "Period start (default: today)")
2389
2389
  .option("--end <YYYY-MM-DD>", "Period end (default: today)")
2390
2390
  .option("--share <level>", "summary | full | none (default: full when asked; none when not interactive)")
@@ -2395,7 +2395,8 @@ program
2395
2395
  .option("--org <org_id>", "Your org id; the report is emailed to you for this org (default: your only organization, else the scan stops and asks). Also selects the Record totals preview (needs MNEMOM_ORG_SCAN_MODE=true)")
2396
2396
  .action(async (options) => {
2397
2397
  try {
2398
- const repos = parseRepoFlags(options.repo);
2398
+ // Omitted --repo is allowed here: scanCommand picks from your repos on a terminal, else stops with a hint.
2399
+ const repos = options.repo === undefined ? [] : parseRepoFlags(options.repo);
2399
2400
  if (!repos)
2400
2401
  throw new Error("--repo owner/name is required (repeatable)");
2401
2402
  const today = new Date().toISOString().slice(0, 10);
@@ -42,6 +42,13 @@ export declare function setRing(ring: CellRing | undefined): void;
42
42
  export declare function getRing(): CellRing | undefined;
43
43
  /** Override the active API base for this process (clears on undefined/empty). */
44
44
  export declare function setApiUrlOverride(url: string | undefined): void;
45
+ /**
46
+ * True when the API is not production but the gateway is the production one. A lease key minted
47
+ * by a non-production cell's API means nothing to the production gateway, which answers every
48
+ * model call 401 and still receives the key (door2-path run 41783208169), so `agent run` refuses
49
+ * this pairing. A base that does not parse decides nothing. Pure.
50
+ */
51
+ export declare function gatewayRingMismatch(apiUrl: string, gatewayUrl: string): boolean;
45
52
  export declare function getApiUrl(): string;
46
53
  export declare function getGatewayUrl(): string;
47
54
  export declare function getWebsiteUrl(): string;
@@ -113,6 +113,27 @@ function ringUrls() {
113
113
  const ring = getRing();
114
114
  return ring ? RING_URLS[ring] : undefined;
115
115
  }
116
+ function originOf(url) {
117
+ try {
118
+ return new URL(url).origin.toLowerCase();
119
+ }
120
+ catch {
121
+ return null;
122
+ }
123
+ }
124
+ /**
125
+ * True when the API is not production but the gateway is the production one. A lease key minted
126
+ * by a non-production cell's API means nothing to the production gateway, which answers every
127
+ * model call 401 and still receives the key (door2-path run 41783208169), so `agent run` refuses
128
+ * this pairing. A base that does not parse decides nothing. Pure.
129
+ */
130
+ export function gatewayRingMismatch(apiUrl, gatewayUrl) {
131
+ const api = originOf(apiUrl);
132
+ const gateway = originOf(gatewayUrl);
133
+ if (api === null || gateway === null)
134
+ return false;
135
+ return api !== originOf(API_URLS.production) && gateway === originOf(GATEWAY_URLS.production);
136
+ }
116
137
  export function getApiUrl() {
117
138
  return (apiUrlOverride ?? envBase("MNEMOM_API_URL") ?? ringUrls()?.api ?? API_URLS[getEnvironment()]);
118
139
  }
@@ -31,6 +31,8 @@ const ALLOWED_PATHS = [
31
31
  new RegExp(`^/repos/${SLUG}/pulls\\?state=closed&sort=updated&direction=desc&per_page=\\d{1,3}&page=\\d{1,4}$`),
32
32
  new RegExp(`^/repos/${SLUG}/pulls/\\d{1,9}$`),
33
33
  new RegExp(`^/repos/${SLUG}/commits/[0-9a-f]{40}/check-runs\\?per_page=100$`),
34
+ // The repo picker's one list read (MNE-9643): the repos this login can read, newest push first.
35
+ /^\/user\/repos\?sort=pushed&direction=desc&per_page=\d{1,3}$/,
34
36
  ];
35
37
  export function isAllowedScanPath(path) {
36
38
  return ALLOWED_PATHS.some((re) => re.test(path));
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Repo picker for `mnemom scan` when --repo is omitted on a terminal (MNE-9643). Read-only: one GET of
3
+ * the repos the signed-in GitHub account can read, through the same credential seam the scan uses.
4
+ * Only `full_name` is kept; descriptions, owners' logins beyond the slug, URLs and the token never leave
5
+ * this module. Failures throw fixed text (never a GitHub body, header or URL). Prompt style and fail-closed
6
+ * handling follow promptShareLevel in ./share.ts: no terminal, no answer, or a bad answer selects nothing.
7
+ */
8
+ import { askMultiSelect } from "../prompt.js";
9
+ import { type GitHubCredential } from "./credential.js";
10
+ /** Most repos listed: the most recently pushed, so the list stays pickable. `--repo` names any other. */
11
+ export declare const REPO_PICKER_LIMIT = 30;
12
+ /** The only path the picker may read. */
13
+ export declare const REPO_LIST_PATH = "/user/repos?sort=pushed&direction=desc&per_page=30";
14
+ export declare const REPO_PICKER_NO_TERMINAL_HINT = "Pass --repo owner/name (repeatable), or run in a terminal to pick from your repos.";
15
+ export declare const REPO_LIST_FAILED_MSG = "Could not list your GitHub repos. Pass --repo owner/name, or check `gh auth status`.";
16
+ export declare const NO_REPOS_MSG = "No GitHub repos are readable by this account. Pass --repo owner/name.";
17
+ export declare const NO_REPO_SELECTED_MSG = "No repo selected. Pass --repo owner/name, or choose at least one number from the list.";
18
+ export interface RepoListDeps {
19
+ fetchImpl?: typeof fetch;
20
+ timeoutMs?: number;
21
+ }
22
+ /** GET-only read of the repos the credential can see. Returns valid slugs only, newest push first. */
23
+ export declare function listReadableRepos(credential: GitHubCredential, deps?: RepoListDeps): Promise<string[]>;
24
+ /**
25
+ * Lists the readable repos and asks which to scan (comma-separated numbers, as the other multi-select
26
+ * prompts do). Throws fixed text when there is no terminal, nothing is listed, or nothing valid is chosen.
27
+ */
28
+ export declare function pickRepos(credential: GitHubCredential, o: {
29
+ isTty: boolean;
30
+ deps?: RepoListDeps;
31
+ ask?: typeof askMultiSelect;
32
+ }): Promise<string[]>;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Repo picker for `mnemom scan` when --repo is omitted on a terminal (MNE-9643). Read-only: one GET of
3
+ * the repos the signed-in GitHub account can read, through the same credential seam the scan uses.
4
+ * Only `full_name` is kept; descriptions, owners' logins beyond the slug, URLs and the token never leave
5
+ * this module. Failures throw fixed text (never a GitHub body, header or URL). Prompt style and fail-closed
6
+ * handling follow promptShareLevel in ./share.ts: no terminal, no answer, or a bad answer selects nothing.
7
+ */
8
+ import { askMultiSelect } from "../prompt.js";
9
+ import { GITHUB_API, isAllowedScanPath } from "./pr-source.js";
10
+ import { assertReadOnlyCredential, isValidRepoSlug } from "./credential.js";
11
+ /** Most repos listed: the most recently pushed, so the list stays pickable. `--repo` names any other. */
12
+ export const REPO_PICKER_LIMIT = 30;
13
+ /** The only path the picker may read. */
14
+ export const REPO_LIST_PATH = `/user/repos?sort=pushed&direction=desc&per_page=${REPO_PICKER_LIMIT}`;
15
+ export const REPO_PICKER_NO_TERMINAL_HINT = "Pass --repo owner/name (repeatable), or run in a terminal to pick from your repos.";
16
+ export const REPO_LIST_FAILED_MSG = "Could not list your GitHub repos. Pass --repo owner/name, or check `gh auth status`.";
17
+ export const NO_REPOS_MSG = "No GitHub repos are readable by this account. Pass --repo owner/name.";
18
+ export const NO_REPO_SELECTED_MSG = "No repo selected. Pass --repo owner/name, or choose at least one number from the list.";
19
+ /** GET-only read of the repos the credential can see. Returns valid slugs only, newest push first. */
20
+ export async function listReadableRepos(credential, deps = {}) {
21
+ if (!isAllowedScanPath(REPO_LIST_PATH))
22
+ throw new Error(REPO_LIST_FAILED_MSG);
23
+ // Same order as runLocalScan: a credential GitHub granted more than read is refused before any read.
24
+ await assertReadOnlyCredential(credential).catch(() => {
25
+ throw new Error(REPO_LIST_FAILED_MSG);
26
+ });
27
+ const doFetch = deps.fetchImpl ?? fetch;
28
+ let res;
29
+ try {
30
+ // User-level read: there is no single repo to scope to (the gh-login credential ignores the argument).
31
+ const bearer = await credential.tokenFor("");
32
+ res = await doFetch(`${GITHUB_API}${REPO_LIST_PATH}`, {
33
+ method: "GET",
34
+ headers: {
35
+ accept: "application/vnd.github+json",
36
+ "x-github-api-version": "2022-11-28",
37
+ "user-agent": "mnemom-cli-scan/1",
38
+ authorization: `Bearer ${bearer}`,
39
+ },
40
+ redirect: "error",
41
+ signal: AbortSignal.timeout(deps.timeoutMs ?? 10_000),
42
+ });
43
+ }
44
+ catch {
45
+ throw new Error(REPO_LIST_FAILED_MSG);
46
+ }
47
+ if (!res.ok) {
48
+ await res.body?.cancel().catch(() => { });
49
+ throw new Error(REPO_LIST_FAILED_MSG);
50
+ }
51
+ let json;
52
+ try {
53
+ json = await res.json();
54
+ }
55
+ catch {
56
+ throw new Error(REPO_LIST_FAILED_MSG);
57
+ }
58
+ if (!Array.isArray(json))
59
+ throw new Error(REPO_LIST_FAILED_MSG);
60
+ const slugs = json
61
+ .map((r) => (r && typeof r === "object" ? r.full_name : undefined))
62
+ .filter(isValidRepoSlug);
63
+ return [...new Set(slugs)].slice(0, REPO_PICKER_LIMIT);
64
+ }
65
+ /**
66
+ * Lists the readable repos and asks which to scan (comma-separated numbers, as the other multi-select
67
+ * prompts do). Throws fixed text when there is no terminal, nothing is listed, or nothing valid is chosen.
68
+ */
69
+ export async function pickRepos(credential, o) {
70
+ if (!o.isTty)
71
+ throw new Error(`--repo owner/name is required (repeatable). ${REPO_PICKER_NO_TERMINAL_HINT}`);
72
+ const repos = await listReadableRepos(credential, o.deps);
73
+ if (repos.length === 0)
74
+ throw new Error(NO_REPOS_MSG);
75
+ const chosen = await (o.ask ?? askMultiSelect)("Which repos should be scanned (read-only)?", repos);
76
+ const picked = chosen.filter((c) => repos.includes(c));
77
+ if (picked.length === 0)
78
+ throw new Error(NO_REPO_SELECTED_MSG);
79
+ return picked;
80
+ }
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Mnemon
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.