@gruu6y/page-clean-login 0.2.5 → 0.2.7

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.
package/README.en.md CHANGED
@@ -293,6 +293,19 @@ Run `bun bin/clean-login.mjs help` for the full command list. A remote service (
293
293
 
294
294
  Pull requests are welcome. The test suite is the contract: `bun test` runs all of it, and a change without a test is a change nobody will dare trust later. Touching `lib/`, `ui/`, `page/` or `index.mjs` does **not** require a version bump of your own -- the merger assigns the version at the merge point; `node scripts/check-version-bump.mjs` still refuses a downgrade or a number already released. Read [AGENTS.md](AGENTS.md) and [docs/releasing.md](docs/releasing.md) before you start.
295
295
 
296
+ ### Submitting issues and dual-line triage
297
+
298
+ When opening a bug report or feature request, the **预计改动范围 / 风险区域** (`route_scope`) dropdown in the issue form determines which maintainer line handles the issue (see [docs/auto-maintainer.md](docs/auto-maintainer.md) for full rules):
299
+
300
+ - **`agent:cindy` (Cindy line)**: handles clearly scoped, low-risk tasks. An issue is routed here only when `route_scope` selects one of:
301
+ - `纯文档 / README / Issue 模板修改` (docs / README / issue templates only)
302
+ - `纯文案或不涉及逻辑的简单样式修改` (copy or non-logic styling only)
303
+ - `纯测试补充` (tests only)
304
+ - `单个非核心文件小 Bug(已附完整复现步骤与验收条件)` (single non-core-file bug with both **reproduction steps** and **acceptance criteria** filled in)
305
+ - For Feature Requests, **是否需要对应 CLI 支持** must also be `不需要(仅涉及页面展示或内部逻辑)` (no CLI support needed).
306
+ - **`agent:agy` (agy line)**: handles general, complex, cross-platform, core-logic, or CLI-related tasks. Keeping the default `核心功能 / 复杂改动 / 跨平台 / 不确定`, omitting required fields, selecting `需要` or `不确定` for CLI support on a feature request, opening a blank issue, or reporting via the card's **Report a problem** button (`from-plugin`) all route to `agent:agy`.
307
+ - **Not sure which to pick?** Keep the default `核心功能 / 复杂改动 / 跨平台 / 不确定`. Maintainers can manually adjust `agent:cindy` / `agent:agy` labels at any time, and Cindy will also hand the issue back to `agent:agy` if it finds the change is out of scope.
308
+
296
309
  <a id="license"></a>
297
310
 
298
311
  ## License
package/README.md CHANGED
@@ -298,6 +298,19 @@ bun bin/clean-login.mjs score cancel # 停掉信任度评分
298
298
 
299
299
  欢迎 pull request。测试套件就是契约:`bun test` 跑全部,一个没有测试的改动就是以后没人敢信的改动。改 `lib/`、`ui/`、`page/` 或 `index.mjs` **不需要自己升版本号**——版本由合并方在合并点分配;`node scripts/check-version-bump.mjs` 仍会拒绝降级或等于已发布的版本号。动手前先读 [AGENTS.md](AGENTS.md) 与 [docs/releasing.md](docs/releasing.md)。
300
300
 
301
+ ### 提交 Issue 与双线自动分流
302
+
303
+ 提交问题或功能建议时,Issue 表单中的 **预计改动范围 / 风险区域**(`route_scope` 字段)用于自动分流处理执行器(完整规则见 [docs/auto-maintainer.md](docs/auto-maintainer.md)):
304
+
305
+ - **`agent:cindy`(Cindy 自动线)**:处理范围明确的低风险 / 简单任务。仅当 `route_scope` 选择以下之一时才会路由到此线:
306
+ - `纯文档 / README / Issue 模板修改`
307
+ - `纯文案或不涉及逻辑的简单样式修改`
308
+ - `纯测试补充`
309
+ - `单个非核心文件小 Bug(已附完整复现步骤与验收条件)`(须同时填写非空的 **复现步骤** 与 **验收条件**)
310
+ - 若为功能建议(Feature Request),还要求 **是否需要对应 CLI 支持** 选择 `不需要(仅涉及页面展示或内部逻辑)`。
311
+ - **`agent:agy`(agy 代理线)**:处理常规、复杂、跨平台或涉及核心逻辑 / CLI 的任务。当 `route_scope` 保留默认的 `核心功能 / 复杂改动 / 跨平台 / 不确定`,或缺少上述必要字段、功能建议需要或不确定是否同步 CLI、空白 Issue 以及卡片 **报告问题**(`from-plugin`)提交的 Issue 时,均由 `agent:agy` 接管。
312
+ - **拿不准怎么选?** 直接保留默认的 `核心功能 / 复杂改动 / 不确定` 即可。维护者也可随时手工增删 `agent:cindy` / `agent:agy` 标签改判;若 Cindy 评估后发现超出范围,也会自动退回给 `agent:agy` 接管。
313
+
301
314
  <a id="license"></a>
302
315
 
303
316
  ## 许可
@@ -382,6 +382,7 @@ export async function rotateIdentity(
382
382
  await sweep();
383
383
  throw error;
384
384
  }
385
+ await rm(join(dir, "check-profile"), { recursive: true, force: true }).catch(() => {});
385
386
  await rename(pendingFile, join(dir, IDENTITY_FILE));
386
387
  return { identity, clearedProfile: true };
387
388
  }
@@ -292,6 +292,7 @@ export async function importAccounts(env = process.env, deps = {}) {
292
292
  key: item.key,
293
293
  accountId: item.accountId,
294
294
  uid: item.uid,
295
+ email: item.email ?? null,
295
296
  // Honest: importing is not a sign-in and the auth file does not record
296
297
  // when the account last signed in.
297
298
  signedInAt: null,
@@ -365,19 +365,50 @@ export async function writeAccountExit({
365
365
 
366
366
  // A finished sign-in: the account's own entry follows the exit it just used.
367
367
  // `proxy` is the full stored record (credentials included) when the page named
368
- // a stored exit; a direct sign-in has none and leaves magpie untouched.
369
- export async function syncSignInProxy({ env = process.env, provider, accountId, proxy } = {}) {
368
+ // a stored exit. A direct sign-in (`proxy == null`) leaves a clean account
369
+ // untouched so magpie keeps inheriting; if magpie already holds an entry for
370
+ // this account from an earlier exit, re-signing in as direct switches it to
371
+ // `"direct"` so traffic does not remain pinned to the stale proxy.
372
+ export async function syncSignInProxy({
373
+ env = process.env,
374
+ provider,
375
+ accountId,
376
+ proxy,
377
+ file = providersFile(env),
378
+ } = {}) {
370
379
  const url = proxyUrlFor(proxy);
371
- if (!url || !accountProxyKey(accountId) || !provider) {
380
+ const key = accountProxyKey(accountId);
381
+ if (!key || RESERVED_KEYS.has(key) || !provider) {
382
+ return { ok: true, changed: [], skipped: [], reason: "no_proxy" };
383
+ }
384
+ if (!url) {
385
+ if (proxy === null || proxy === undefined) {
386
+ const loaded = await readProvidersDoc(file);
387
+ const entry = loaded.ok ? findProvider(loaded.doc, provider) : null;
388
+ const map = accountProxyMap(entry);
389
+ if (entry && Object.hasOwn(map, key) && map[key] !== "direct") {
390
+ const res = await writeAccountExit({ env, provider, accountId, mode: "direct", file });
391
+ return {
392
+ ok: res.ok,
393
+ changed: res.changed ? [{ provider, accountId, key: res.key, url: "direct" }] : [],
394
+ skipped: [],
395
+ reason: res.changed ? "cleared_to_direct" : (res.reason ?? "no_proxy"),
396
+ };
397
+ }
398
+ }
372
399
  return { ok: true, changed: [], skipped: [], reason: "no_proxy" };
373
400
  }
374
- return writeAccountProxies({ env, entries: [{ provider, accountId, url }] });
401
+ return writeAccountProxies({ env, entries: [{ provider, accountId, url }], file });
375
402
  }
376
403
 
377
- // Startup backfill: every ledger that remembers which exit it signed in
378
- // through gets that exit into magpie, but only where magpie has no entry yet.
379
- // This is what repairs accounts signed in before this feature existed, without
380
- // touching anything the user configured by hand.
404
+ function accountActiveProxyId(meta) {
405
+ const picked = meta?.exit && typeof meta.exit === "object" ? meta.exit : meta?.lastLogin;
406
+ return typeof picked?.proxyId === "string" && picked.proxyId ? picked.proxyId : null;
407
+ }
408
+
409
+ // Startup backfill: every ledger that remembers which exit it is bound to
410
+ // (`exit`, falling back to `lastLogin`) gets that exit into magpie, but only
411
+ // where magpie has no entry yet.
381
412
  export async function backfillAccountProxies({
382
413
  env = process.env,
383
414
  store,
@@ -398,7 +429,7 @@ export async function backfillAccountProxies({
398
429
  const seen = new Set();
399
430
  for (const account of Array.isArray(accounts) ? accounts : []) {
400
431
  const meta = account?.meta;
401
- const proxyId = meta?.lastLogin?.proxyId;
432
+ const proxyId = accountActiveProxyId(meta);
402
433
  const accountId = meta?.accountId;
403
434
  const provider = meta?.provider ?? account?.provider;
404
435
  if (!proxyId || !accountProxyKey(accountId) || !provider) continue;
@@ -415,7 +446,7 @@ export async function backfillAccountProxies({
415
446
  report.skipped.push({ provider, accountId, reason: "proxy_missing" });
416
447
  continue;
417
448
  }
418
- const key = `${provider}${accountProxyKey(accountId)}`;
449
+ const key = `${provider}\u0000${accountProxyKey(accountId)}`;
419
450
  if (seen.has(key)) continue;
420
451
  seen.add(key);
421
452
  wanted.push({ provider, accountId, url });
@@ -430,6 +461,99 @@ export async function backfillAccountProxies({
430
461
  return { ...written, ledgers: report.ledgers, skipped: [...report.skipped, ...written.skipped] };
431
462
  }
432
463
 
464
+ // Re-sync every account whose active exit points to `proxyId` after that
465
+ // proxy's connection or credentials are updated.
466
+ export async function syncProxyUpdate({
467
+ env = process.env,
468
+ store,
469
+ proxyId,
470
+ listAccounts = listAccountDirsWithMeta,
471
+ file = providersFile(env),
472
+ } = {}) {
473
+ if (typeof proxyId !== "string" || !proxyId) {
474
+ return { ok: false, file, changed: [], skipped: [], reason: "invalid_proxy" };
475
+ }
476
+ let record = null;
477
+ try {
478
+ record = await store?.get?.(proxyId);
479
+ } catch {
480
+ record = null;
481
+ }
482
+ const url = proxyUrlFor(record);
483
+ let accounts;
484
+ try {
485
+ accounts = await listAccounts(env);
486
+ } catch (error) {
487
+ return {
488
+ ok: false,
489
+ file,
490
+ changed: [],
491
+ skipped: [],
492
+ reason: "accounts_unreadable",
493
+ error: String(error?.message ?? error),
494
+ };
495
+ }
496
+ const entries = [];
497
+ const seen = new Set();
498
+ for (const account of Array.isArray(accounts) ? accounts : []) {
499
+ const meta = account?.meta;
500
+ if (accountActiveProxyId(meta) !== proxyId) continue;
501
+ const accountId = meta?.accountId;
502
+ const provider = meta?.provider ?? account?.provider;
503
+ const accountKey = accountProxyKey(accountId);
504
+ if (!provider || !accountKey || RESERVED_KEYS.has(accountKey)) continue;
505
+ const dedupeKey = `${provider}\u0000${accountKey}`;
506
+ if (seen.has(dedupeKey)) continue;
507
+ seen.add(dedupeKey);
508
+ entries.push({ provider, accountId, url });
509
+ }
510
+ if (!entries.length) {
511
+ return { ok: true, file, changed: [], skipped: [], reason: "nothing_to_sync" };
512
+ }
513
+ if (!url) {
514
+ return {
515
+ ok: false,
516
+ file,
517
+ changed: [],
518
+ skipped: entries.map(({ provider, accountId }) => ({
519
+ provider,
520
+ accountId,
521
+ reason: "proxy_missing",
522
+ })),
523
+ reason: "proxy_missing",
524
+ };
525
+ }
526
+ return writeAccountProxies({ env, entries, onlyMissing: false, file });
527
+ }
528
+
529
+ // Removes an account's per-account proxy override from magpie's providers.json
530
+ // when the account is deleted.
531
+ export async function clearAccountProxy({
532
+ env = process.env,
533
+ provider,
534
+ accountId,
535
+ file = providersFile(env),
536
+ } = {}) {
537
+ const key = accountProxyKey(accountId);
538
+ if (!provider || !key || RESERVED_KEYS.has(key)) {
539
+ return { ok: true, changed: false, reason: "account_name_unknown" };
540
+ }
541
+ const loaded = await readProvidersDoc(file);
542
+ if (!loaded.ok) {
543
+ return loaded.reason === "providers_missing"
544
+ ? { ok: true, changed: false, reason: "providers_missing" }
545
+ : { ok: false, changed: false, reason: loaded.reason };
546
+ }
547
+ const entry = findProvider(loaded.doc, provider);
548
+ if (!entry) return { ok: true, changed: false, reason: "provider_missing" };
549
+ const map = accountProxyMap(entry);
550
+ if (!Object.hasOwn(map, key)) {
551
+ return { ok: true, changed: false, reason: "unchanged" };
552
+ }
553
+ const res = await writeAccountExit({ env, provider, accountId, mode: "inherit", file });
554
+ return { ok: res.ok, changed: Boolean(res.changed), reason: res.reason };
555
+ }
556
+
433
557
  // The flow's default: build the sync from the environment alone, so a sign-in
434
558
  // driven without the HTTP service still lands in magpie. The proxy store is
435
559
  // only read here, never written.
@@ -450,6 +574,10 @@ export function createAccountProxySync({ env = process.env, store, dataDir = plu
450
574
  }
451
575
  return syncSignInProxy({ env, provider, accountId, proxy: record });
452
576
  },
577
+ syncProxyUpdate: async ({ proxyId }) =>
578
+ syncProxyUpdate({ env, store: await ensureStore(), proxyId }),
579
+ clearAccountProxy: async ({ provider, accountId }) =>
580
+ clearAccountProxy({ env, provider, accountId }),
453
581
  backfill: async () =>
454
582
  backfillAccountProxies({ env, store: await ensureStore() }),
455
583
  };
package/lib/agent-cli.mjs CHANGED
@@ -74,7 +74,7 @@ function addOption(options, key, value) {
74
74
  // an optional-value flag stays bare only when another flag or the end of the
75
75
  // line follows (a token it does take is validated by the command), and a
76
76
  // required value flag errors instead of quietly storing `true`.
77
- const BOOLEAN_FLAGS = new Set(["help", "raw", "single"]);
77
+ const BOOLEAN_FLAGS = new Set(["help", "raw", "single", "clear-password"]);
78
78
  const OPTIONAL_VALUE_FLAGS = new Set(["wait"]);
79
79
  const VALUE_FLAGS = new Set([
80
80
  "url",
@@ -101,6 +101,8 @@ const VALUE_FLAGS = new Set([
101
101
  "name",
102
102
  "host",
103
103
  "exit-port",
104
+ "file",
105
+ "prefix",
104
106
  ]);
105
107
 
106
108
  export function parseArgs(argv) {
@@ -284,7 +286,8 @@ export function usage() {
284
286
  " providers Merged provider cards, compact.",
285
287
  " proxies Stored proxies, compact (no credentials).",
286
288
  " proxies add <name> <type> <host> <port> Store an exit (type http|https|socks5).",
287
- " proxies update <id> [--name N] [--type T] [--host H] [--exit-port P] [--user U] [--pass P]",
289
+ " proxies import [--file PATH | <text>] [--type T] [--prefix P] Bulk import exits.",
290
+ " proxies update <id> [--name N] [--type T] [--host H] [--exit-port P] [--user U] [--pass P] [--clear-password]",
288
291
  " Change an exit; a connection change clears its per-provider latency and score.",
289
292
  " proxies delete <proxyId> Remove a stored exit.",
290
293
  " proxies targets The endpoints a proxy probe can be aimed at.",
@@ -310,7 +313,7 @@ export function usage() {
310
313
  " native status [--wait ms] The current native sign-in flow.",
311
314
  " native paste <text> Paste a callback URL or code into it.",
312
315
  " native cancel Cancel the native sign-in.",
313
- " proxy test <proxyId> Probe a stored proxy and persist the result.",
316
+ " proxy test <proxyId> [--provider ID] Probe a stored proxy and persist the result.",
314
317
  " proxy score <proxyId> Start the Claude trust-score check.",
315
318
  " score status [--wait ms] The trust-score job.",
316
319
  " score cancel Stop the trust-score job.",
@@ -335,6 +338,9 @@ export function usage() {
335
338
  " --mode M Exit mode for accounts exit: inherit, direct or custom.",
336
339
  " --note TEXT Note for assets add/update, or the report note.",
337
340
  " --user / --pass Optional credentials for proxies add and update.",
341
+ " --clear-password Clear a stored proxy password on proxies update.",
342
+ " --file PATH Read bulk proxy lines from a UTF-8 file for proxies import.",
343
+ " --prefix TEXT Name prefix for imported proxies on proxies import.",
338
344
  " --exit-port N Exit port for proxies update (--port is the service port).",
339
345
  " --single Replace the single stored account for this provider.",
340
346
  "",
@@ -409,6 +415,28 @@ export async function runCli(argv, {
409
415
  noSurplus(positional, 3);
410
416
  return emit(await del(`/api/proxies/${encodeURIComponent(required(positional[2] ?? options.id, "<proxyId>"))}`), options, write);
411
417
  }
418
+ if (action === "import") {
419
+ noSurplus(positional, 3);
420
+ let text = "";
421
+ if (options.file !== undefined) {
422
+ const filePath = required(options.file, "--file");
423
+ try {
424
+ const { readFile } = await import("node:fs/promises");
425
+ text = await readFile(filePath, "utf8");
426
+ } catch (error) {
427
+ throw new CliError(
428
+ `Could not read proxy file ${filePath}: ${String(error?.message || error)}`,
429
+ { code: "file_unreadable" },
430
+ );
431
+ }
432
+ } else {
433
+ text = required(positional[2] ?? options.text, "<text> or --file");
434
+ }
435
+ const body = { text };
436
+ if (options.type) body.defaultType = String(options.type);
437
+ if (options.prefix !== undefined) body.prefix = String(options.prefix);
438
+ return emit(await post("/api/proxies/bulk", body), options, write);
439
+ }
412
440
  if (action === "update") {
413
441
  // Only fields the caller spelled out are sent, so a later read cannot
414
442
  // mistake an omitted flag for a request to clear it. The exit's port
@@ -424,9 +452,10 @@ export async function runCli(argv, {
424
452
  if (Object.prototype.hasOwnProperty.call(options, "exit-port")) body.port = String(options["exit-port"]);
425
453
  if (Object.prototype.hasOwnProperty.call(options, "user")) body.username = String(options.user);
426
454
  if (Object.prototype.hasOwnProperty.call(options, "pass")) body.password = String(options.pass);
455
+ if (options["clear-password"] === true) body.clearPassword = true;
427
456
  if (!Object.keys(body).length) {
428
457
  throw new CliError(
429
- "Nothing to update; pass --name, --type, --host, --exit-port, --user or --pass.",
458
+ "Nothing to update; pass --name, --type, --host, --exit-port, --user, --pass or --clear-password.",
430
459
  { code: "bad_command" },
431
460
  );
432
461
  }
@@ -632,7 +661,8 @@ export async function runCli(argv, {
632
661
  const id = required(positional[2] ?? options.id, "<proxyId>");
633
662
  const path = `/api/proxies/${encodeURIComponent(id)}`;
634
663
  if (action === "test") {
635
- const payload = await post(`${path}/test`, {});
664
+ const body = options.provider ? { provider: String(options.provider) } : {};
665
+ const payload = await post(`${path}/test`, body);
636
666
  emit(payload, options, write);
637
667
  // The probe answered but reported a dead exit: that is a failure the
638
668
  // caller must see in the exit code, not just in the JSON body.
@@ -53,6 +53,7 @@ export const AGENT_COMMANDS = Object.freeze([
53
53
  Object.freeze({ command: "status", http: "GET /api/health", args: "", summary: "Liveness and the account-prune summary." }),
54
54
  Object.freeze({ command: "providers", http: "GET /api/agent", args: "", summary: "The merged provider cards, compact." }),
55
55
  Object.freeze({ command: "proxies", http: "GET /api/agent", args: "", summary: "Stored proxies, compact, without credentials." }),
56
+ Object.freeze({ command: "proxies import", http: "POST /api/proxies/bulk", args: "[--file <path> | <text>] [--type T] [--prefix P]", summary: "Bulk import proxies from text lines." }),
56
57
  Object.freeze({ command: "accounts", http: "GET /api/agent", args: "", summary: "Known accounts and whether each is signed in." }),
57
58
  Object.freeze({ command: "signin start", http: "POST /api/signin", args: "--provider <id> [--proxy <id>] [--method <label>] [--input k=v]... [--single] [--wait ms]", summary: "Start a sign-in, optionally waiting until it settles." }),
58
59
  Object.freeze({ command: "signin status", http: "GET /api/signin?wait=ms", args: "[--wait ms]", summary: "The current sign-in flow." }),
@@ -62,7 +63,7 @@ export const AGENT_COMMANDS = Object.freeze([
62
63
  Object.freeze({ command: "native status", http: "GET /api/native-signin?wait=ms", args: "[--wait ms]", summary: "The current native sign-in flow." }),
63
64
  Object.freeze({ command: "native paste", http: "POST /api/native-signin/paste", args: "<text>", summary: "Paste a callback URL or code into the native flow." }),
64
65
  Object.freeze({ command: "native cancel", http: "POST /api/native-signin/cancel", args: "", summary: "Cancel the native sign-in." }),
65
- Object.freeze({ command: "proxy test", http: "POST /api/proxies/:id/test", args: "<proxyId>", summary: "Probe a stored proxy and persist the result." }),
66
+ Object.freeze({ command: "proxy test", http: "POST /api/proxies/:id/test", args: "<proxyId> [--provider <id>]", summary: "Probe a stored proxy and persist the result." }),
66
67
  Object.freeze({ command: "proxy score", http: "POST /api/proxies/:id/score", args: "<proxyId> [--wait ms]", summary: "Start the Claude trust-score check." }),
67
68
  Object.freeze({ command: "score status", http: "GET /api/proxy-score?wait=ms", args: "[--wait ms]", summary: "The trust-score job." }),
68
69
  Object.freeze({ command: "env", http: "GET /api/environment/job?wait=ms", args: "[--wait ms]", summary: "The login browser and its download job." }),