maxpool 1.24.47 → 1.24.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxpool",
3
- "version": "1.24.47",
3
+ "version": "1.24.48",
4
4
  "description": "Multi-account Claude Code proxy with adaptive, rate-aware load balancing across Claude accounts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import http from 'node:http';
2
2
  import { appendEventLog } from './event-log.js';
3
+ import { atomicConfigUpdate } from './config.js';
3
4
  import { HOP_HEADER, nextHopCount } from './pool-link.js';
4
5
  import { ThreadOwners, readThreadIntent, threadRefusalBody, isThreadlessAccount } from './thread-gate.js';
5
6
  import { writeFile, mkdir } from 'node:fs/promises';
@@ -281,6 +282,74 @@ export function createProxyServer(accountManager, config, hooks = {}) {
281
282
  return;
282
283
  }
283
284
 
285
+ // Remote login inject (owner decision D15/D16, 2026-10-30): a linked pool
286
+ // re-authenticates one of ITS accounts through the front door instead of
287
+ // SSH. Any valid key may add or re-auth (one permission level — the door
288
+ // is the per-person key + the audit log, not per-item rules). A uuid
289
+ // match can only ever re-authorize the SAME account (the browser login
290
+ // for X replaces the saved login for X), so no healthy-row refusal:
291
+ // runtime refreshDead lags reality at boot anyway (scratch E2E 2026-10-30:
292
+ // a dead-on-disk row read "healthy" and a real re-auth was refused 409).
293
+ if (req.method === 'POST' && req.url === '/maxpool/accounts') {
294
+ if (strictClients ? !caller.ok : (proxyApiKey && clientKey !== proxyApiKey)) {
295
+ rejectUnauthorized();
296
+ return;
297
+ }
298
+ const chunks = [];
299
+ for await (const c of req) chunks.push(c);
300
+ let body;
301
+ try { body = JSON.parse(Buffer.concat(chunks).toString('utf8')); } catch { body = null; }
302
+ const acct = body?.account;
303
+ if (!acct || acct.type !== 'oauth' || typeof acct.accountUuid !== 'string' || !acct.accountUuid ||
304
+ typeof acct.refreshToken !== 'string' || !acct.refreshToken || typeof acct.accessToken !== 'string' || !acct.accessToken) {
305
+ res.writeHead(400, { 'Content-Type': 'application/json' });
306
+ res.end(JSON.stringify({ ok: false, error: 'bad_request', message: 'Expected {account: {type:"oauth", accountUuid, accessToken, refreshToken, name?}}' }));
307
+ return;
308
+ }
309
+ const who = caller.name || 'legacy-key';
310
+ const amAcct = accountManager.accounts.find(a => a.accountUuid === acct.accountUuid);
311
+ const tokenFields = {
312
+ accessToken: acct.accessToken,
313
+ refreshToken: acct.refreshToken,
314
+ expiresAt: typeof acct.expiresAt === 'number' ? acct.expiresAt : Date.now() + 3600_000,
315
+ source: acct.source || 'remote-inject',
316
+ };
317
+ if (amAcct) {
318
+ // In-place revive, mirroring the TUI re-auth field set: fresh tokens
319
+ // BEFORE persisting (the disk writer derives from the AM), refreshDead
320
+ // cleared here or the row stays benched after a successful re-auth.
321
+ amAcct.credential = tokenFields.accessToken;
322
+ amAcct.refreshToken = tokenFields.refreshToken;
323
+ amAcct.expiresAt = tokenFields.expiresAt;
324
+ amAcct.refreshDead = false;
325
+ if (amAcct.status === 'error') amAcct.status = 'active';
326
+ appendEventLog(`[Maxpool] Remote re-auth: "${amAcct.name}" (uuid ${acct.accountUuid.slice(0, 8)}) by ${who}`);
327
+ } else {
328
+ const entry = { name: acct.name || acct.accountUuid.slice(0, 8), type: 'oauth', accountUuid: acct.accountUuid, enabled: true, ...tokenFields };
329
+ accountManager.addAccount(entry);
330
+ appendEventLog(`[Maxpool] Remote add: "${entry.name}" (uuid ${acct.accountUuid.slice(0, 8)}) by ${who}`);
331
+ }
332
+ try {
333
+ await atomicConfigUpdate(diskConfig => {
334
+ const onDisk = diskConfig.accounts.find(a => a.accountUuid === acct.accountUuid);
335
+ if (onDisk) {
336
+ Object.assign(onDisk, tokenFields);
337
+ } else {
338
+ diskConfig.accounts.push({ name: acct.name || acct.accountUuid.slice(0, 8), type: 'oauth', accountUuid: acct.accountUuid, enabled: true, ...tokenFields });
339
+ }
340
+ });
341
+ // Keep the in-memory config mirror in step so a later TUI saveConfig
342
+ // can't clobber the fresh tokens with stale ones.
343
+ const mem = config.accounts.find(a => a.accountUuid === acct.accountUuid);
344
+ if (mem) Object.assign(mem, tokenFields);
345
+ } catch (err) {
346
+ console.error(`[Maxpool] Remote inject persisted to memory but NOT disk for uuid ${acct.accountUuid.slice(0, 8)}: ${err?.message || err}`);
347
+ }
348
+ res.writeHead(200, { 'Content-Type': 'application/json' });
349
+ res.end(JSON.stringify({ ok: true, result: amAcct ? 'reauthed' : 'added', name: amAcct ? amAcct.name : (acct.name || acct.accountUuid.slice(0, 8)) }));
350
+ return;
351
+ }
352
+
284
353
  if (!caller.ok) {
285
354
  rejectUnauthorized();
286
355
  return;
package/src/tui.js CHANGED
@@ -1447,6 +1447,17 @@ export class TUI {
1447
1447
  process.stdout.write('\nOpening browser to log into Claude…\n');
1448
1448
  const creds = await loginOAuth();
1449
1449
  const profile = await fetchProfile(creds.accessToken);
1450
+ // Owner shape (D15/D16, 2026-10-30): if the browser login belongs to an
1451
+ // account that LIVES in a linked team pool, the fresh login goes STRAIGHT
1452
+ // there — never persisted locally (single writer: one account, one home).
1453
+ // Same keystroke as a local re-auth; the routing is by where the account
1454
+ // lives, so nothing is selected and no menu appears.
1455
+ const mirror = this._findRemoteMirrorFor(profile);
1456
+ if (mirror) {
1457
+ setConsoleStdoutSuppressed(false);
1458
+ await this._sendLoginToRemote(mirror, creds, profile);
1459
+ return;
1460
+ }
1450
1461
  const existing = this._findExistingOAuthAccount(profile);
1451
1462
  let name;
1452
1463
  if (existing) {
@@ -1482,6 +1493,57 @@ export class TUI {
1482
1493
  }
1483
1494
  }
1484
1495
 
1496
+ // The browser login belongs to a linked team pool iff a mirror row carries the
1497
+ // same account uuid (M2: mirrors hold remoteUuid, never accountUuid, so a
1498
+ // uuid-first matcher cannot alias onto a local account).
1499
+ _findRemoteMirrorFor(profile) {
1500
+ if (!profile?.accountUuid) return null;
1501
+ return this.am.accounts.find(a => a.remote && a.remoteUuid === profile.accountUuid) || null;
1502
+ }
1503
+
1504
+ // Send a fresh browser login to the linked team pool that OWNS this account
1505
+ // (D15/D16). Never falls back to a local save — a network failure here must
1506
+ // surface, not silently create a second writer on this laptop.
1507
+ async _sendLoginToRemote(mirror, creds, profile) {
1508
+ const remote = mirror.remote;
1509
+ const name = remote.remoteName || mirror.name;
1510
+ const replace = Boolean(mirror.refreshDead || mirror.status === 'error');
1511
+ process.stdout.write(`\n"${name}" lives in the team pool (${remote.linkName}) — sending the fresh login there…\n`);
1512
+ const ctl = new AbortController();
1513
+ const t = setTimeout(() => ctl.abort(), 20_000);
1514
+ try {
1515
+ const res = await fetch(`${String(remote.url).replace(/\/+$/, '')}/maxpool/accounts`, {
1516
+ method: 'POST',
1517
+ headers: { 'Content-Type': 'application/json', 'x-api-key': remote.key || '' },
1518
+ body: JSON.stringify({
1519
+ account: {
1520
+ name, type: 'oauth',
1521
+ accountUuid: profile?.accountUuid,
1522
+ accessToken: creds.accessToken,
1523
+ refreshToken: creds.refreshToken,
1524
+ expiresAt: creds.expiresAt,
1525
+ source: 'remote-login',
1526
+ },
1527
+ replace,
1528
+ }),
1529
+ signal: ctl.signal,
1530
+ });
1531
+ const json = await res.json().catch(() => ({}));
1532
+ if (res.status === 409) {
1533
+ process.stdout.write(`\nTeam pool says "${name}" is already healthy — nothing to do. Nothing was saved on this laptop.\n`);
1534
+ } else if (res.ok && json.ok) {
1535
+ process.stdout.write(`\nDone: "${name}" ${json.result === 'added' ? 'added to' : 're-authenticated in'} the team pool. Nothing was saved on this laptop.\n`);
1536
+ this._addLog(`Remote login: "${name}" → team pool ${remote.linkName} (${json.result})`);
1537
+ } else {
1538
+ process.stdout.write(`\nTeam pool rejected the login (HTTP ${res.status}: ${json?.message || json?.error || 'unknown error'}). NOTHING was saved on this laptop — not retried locally.\n`);
1539
+ }
1540
+ } catch (e) {
1541
+ process.stdout.write(`\nCould not reach the team pool (${e?.name === 'AbortError' ? 'timed out' : e?.message}). NOTHING was saved on this laptop — try again in a moment.\n`);
1542
+ } finally {
1543
+ clearTimeout(t);
1544
+ }
1545
+ }
1546
+
1485
1547
  // Rename an account in config and in the running manager.
1486
1548
  /**
1487
1549
  * USAGE CAP setter — persists to config (rollback on write failure) and applies