@prestyj/core 5.24.0 → 5.25.1

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.
@@ -222,7 +222,7 @@ async function refreshKimiToken(refreshToken) {
222
222
 
223
223
  // src/auth-storage.ts
224
224
  import fs4 from "fs/promises";
225
- import { readFileSync as readFileSync2 } from "fs";
225
+ import { readFileSync as readFileSync3 } from "fs";
226
226
  import crypto5 from "crypto";
227
227
 
228
228
  // src/oauth/anthropic.ts
@@ -248,6 +248,7 @@ async function generatePKCE() {
248
248
 
249
249
  // src/claude-code-version.ts
250
250
  import fs2 from "fs/promises";
251
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
251
252
  import path3 from "path";
252
253
 
253
254
  // src/logger.ts
@@ -375,19 +376,41 @@ function closeLogger(opts) {
375
376
 
376
377
  // src/claude-code-version.ts
377
378
  var NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
378
- var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
379
+ var CACHE_FRESH_MS = 60 * 60 * 1e3;
380
+ var CACHE_HARD_MS = 24 * 60 * 60 * 1e3;
379
381
  var FETCH_TIMEOUT_MS = 3e3;
380
- var FALLBACK_VERSION = "2.1.88";
382
+ var FALLBACK_VERSION = "2.1.280";
381
383
  var memoryCache = null;
382
384
  var inflight = null;
385
+ var backgroundRefresh = null;
386
+ var versionFloor = null;
383
387
  function cachePath() {
384
388
  return path3.join(getAppPaths().agentDir, "claude-code-version.json");
385
389
  }
390
+ function compareClaudeCodeVersions(a, b) {
391
+ const parse = (v) => v.split(".").map((part) => Number.parseInt(part, 10)).map((n) => Number.isFinite(n) ? n : 0);
392
+ const left = parse(a);
393
+ const right = parse(b);
394
+ for (let i = 0; i < Math.max(left.length, right.length); i += 1) {
395
+ const diff = (left[i] ?? 0) - (right[i] ?? 0);
396
+ if (diff !== 0) return diff;
397
+ }
398
+ return 0;
399
+ }
400
+ function applyFloor(version) {
401
+ if (!versionFloor) return version;
402
+ return compareClaudeCodeVersions(versionFloor, version) > 0 ? versionFloor : version;
403
+ }
386
404
  async function readDiskCache() {
387
405
  try {
388
406
  const raw = await fs2.readFile(cachePath(), "utf-8");
389
407
  const parsed = JSON.parse(raw);
390
408
  if (typeof parsed.version === "string" && typeof parsed.fetchedAt === "number") {
409
+ if (typeof parsed.minVersion === "string") {
410
+ if (!versionFloor || compareClaudeCodeVersions(parsed.minVersion, versionFloor) > 0) {
411
+ versionFloor = parsed.minVersion;
412
+ }
413
+ }
391
414
  return parsed;
392
415
  }
393
416
  return null;
@@ -398,7 +421,11 @@ async function readDiskCache() {
398
421
  async function writeDiskCache(data) {
399
422
  try {
400
423
  await fs2.mkdir(getAppPaths().agentDir, { recursive: true, mode: 448 });
401
- await fs2.writeFile(cachePath(), JSON.stringify(data), { mode: 384 });
424
+ await fs2.writeFile(
425
+ cachePath(),
426
+ JSON.stringify({ ...data, ...versionFloor ? { minVersion: versionFloor } : {} }),
427
+ { mode: 384 }
428
+ );
402
429
  } catch (err) {
403
430
  log(
404
431
  "WARN",
@@ -424,6 +451,19 @@ async function fetchLatest() {
424
451
  clearTimeout(timer);
425
452
  }
426
453
  }
454
+ function refreshInBackground() {
455
+ if (backgroundRefresh) return;
456
+ backgroundRefresh = (async () => {
457
+ const fetched = await fetchLatest();
458
+ if (fetched) {
459
+ await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
460
+ memoryCache = { version: applyFloor(fetched), expiresAt: Date.now() + CACHE_FRESH_MS };
461
+ }
462
+ })().catch(() => {
463
+ }).finally(() => {
464
+ backgroundRefresh = null;
465
+ });
466
+ }
427
467
  async function getClaudeCodeVersion() {
428
468
  if (memoryCache && Date.now() < memoryCache.expiresAt) {
429
469
  return memoryCache.version;
@@ -431,18 +471,26 @@ async function getClaudeCodeVersion() {
431
471
  if (inflight) return inflight;
432
472
  inflight = (async () => {
433
473
  const disk = await readDiskCache();
434
- const diskFresh = disk && Date.now() - disk.fetchedAt < CACHE_TTL_MS;
435
- if (disk && diskFresh) {
436
- memoryCache = { version: disk.version, expiresAt: Date.now() + CACHE_TTL_MS };
437
- return disk.version;
474
+ const age = disk ? Date.now() - disk.fetchedAt : Infinity;
475
+ if (disk && age < CACHE_FRESH_MS) {
476
+ const version = applyFloor(disk.version);
477
+ memoryCache = { version, expiresAt: Date.now() + CACHE_FRESH_MS };
478
+ return version;
479
+ }
480
+ if (disk && age < CACHE_HARD_MS) {
481
+ const version = applyFloor(disk.version);
482
+ memoryCache = { version, expiresAt: Date.now() + 5 * 60 * 1e3 };
483
+ refreshInBackground();
484
+ return version;
438
485
  }
439
486
  const fetched = await fetchLatest();
440
487
  if (fetched) {
441
488
  await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
442
- memoryCache = { version: fetched, expiresAt: Date.now() + CACHE_TTL_MS };
443
- return fetched;
489
+ const version = applyFloor(fetched);
490
+ memoryCache = { version, expiresAt: Date.now() + CACHE_FRESH_MS };
491
+ return version;
444
492
  }
445
- const resolved = disk?.version ?? FALLBACK_VERSION;
493
+ const resolved = applyFloor(disk?.version ?? FALLBACK_VERSION);
446
494
  memoryCache = { version: resolved, expiresAt: Date.now() + 5 * 60 * 1e3 };
447
495
  log(
448
496
  "WARN",
@@ -457,6 +505,44 @@ async function getClaudeCodeVersion() {
457
505
  inflight = null;
458
506
  }
459
507
  }
508
+ var REQUIRED_VERSION_PATTERN = /version\s+(\d+(?:\.\d+)+)\s+or\s+newer\s+is\s+required/i;
509
+ function recordRequiredClaudeCodeVersion(message) {
510
+ const required = REQUIRED_VERSION_PATTERN.exec(message ?? "")?.[1];
511
+ if (!required) return null;
512
+ if (versionFloor && compareClaudeCodeVersions(required, versionFloor) <= 0) return versionFloor;
513
+ versionFloor = required;
514
+ memoryCache = null;
515
+ log(
516
+ "WARN",
517
+ "claude-code-version",
518
+ `Provider requires Claude Code >= ${required}; pinning User-Agent floor`
519
+ );
520
+ try {
521
+ const dir = getAppPaths().agentDir;
522
+ mkdirSync2(dir, { recursive: true, mode: 448 });
523
+ let existing = {};
524
+ try {
525
+ existing = JSON.parse(readFileSync2(cachePath(), "utf-8"));
526
+ } catch {
527
+ }
528
+ writeFileSync2(
529
+ cachePath(),
530
+ JSON.stringify({
531
+ version: existing.version ?? required,
532
+ fetchedAt: existing.fetchedAt ?? 0,
533
+ minVersion: required
534
+ }),
535
+ { mode: 384 }
536
+ );
537
+ } catch (err) {
538
+ log(
539
+ "WARN",
540
+ "claude-code-version",
541
+ `Failed to persist required version: ${err instanceof Error ? err.message : String(err)}`
542
+ );
543
+ }
544
+ return required;
545
+ }
460
546
  async function getClaudeCliUserAgent() {
461
547
  const version = await getClaudeCodeVersion();
462
548
  return `claude-cli/${version} (external, cli)`;
@@ -1444,7 +1530,7 @@ function activeBaseUrlEntry(data, provider) {
1444
1530
  }
1445
1531
  function readStoredBaseUrlSync(authFile, provider) {
1446
1532
  try {
1447
- const data = JSON.parse(readFileSync2(authFile, "utf-8"));
1533
+ const data = JSON.parse(readFileSync3(authFile, "utf-8"));
1448
1534
  return activeBaseUrlEntry(data, provider)?.baseUrl;
1449
1535
  } catch {
1450
1536
  return void 0;
@@ -1935,11 +2021,37 @@ var MODELS = [
1935
2021
  // costTier: "high",
1936
2022
  // maxThinkingLevel: "max",
1937
2023
  // },
2024
+ {
2025
+ // Released 2026-09-22 — "For long-running agentic coding and knowledge
2026
+ // work". Fable-class capability at $4/$20 MTok (cheaper than the Opus 5 it
2027
+ // replaces, $5/$25). Adaptive thinking with the full effort ladder
2028
+ // (low→max, xhigh included), but thinking can no longer be disabled: a
2029
+ // `thinking: {type: "disabled"}` or budget_tokens request 400s. @prestyj/ai
2030
+ // omits the field entirely when thinking is off, so that path is safe.
2031
+ // Forced tool use (`tool_choice` any/tool) also 400s — see
2032
+ // `toAnthropicToolChoice`, which downgrades it to `auto` for this model.
2033
+ // Anthropic declares the server-side default effort as `medium` (Opus 5
2034
+ // ran `high`), and 5.5 thinks more per turn at a given level, so a fresh
2035
+ // session starts at `medium` rather than the ladder ceiling.
2036
+ id: "claude-opus-5-5",
2037
+ name: "Claude Opus 5.5",
2038
+ provider: "anthropic",
2039
+ contextWindow: 1e6,
2040
+ maxOutputTokens: 128e3,
2041
+ supportsThinking: true,
2042
+ defaultThinkingLevel: "medium",
2043
+ supportsImages: true,
2044
+ supportsVideo: false,
2045
+ costTier: "high",
2046
+ maxThinkingLevel: "max"
2047
+ },
1938
2048
  {
1939
2049
  // Released 2026-07-24 — "For complex agentic coding and enterprise work".
1940
2050
  // Near-Fable capability at half the price ($5/$25 vs $10/$50). Adaptive
1941
2051
  // thinking with the full effort ladder (low→max, xhigh included); dateless
1942
- // ID is the canonical pinned snapshot (post-4.6 naming scheme).
2052
+ // ID is the canonical pinned snapshot (post-4.6 naming scheme). Kept as a
2053
+ // legacy option now that Opus 5.5 leads the line: it's the last Opus that
2054
+ // accepts disabled thinking and forced tool use.
1943
2055
  id: "claude-opus-5",
1944
2056
  name: "Claude Opus 5",
1945
2057
  provider: "anthropic",
@@ -2088,16 +2200,21 @@ var MODELS = [
2088
2200
  maxThinkingLevel: "max"
2089
2201
  },
2090
2202
  // ── xAI (Grok) ─────────────────────────────────────────
2091
- // Grok 4.6 (released 2026-08-12) is xAI's flagship for coding, agentic tasks,
2092
- // and knowledge work, with a focus on long-running agents — 500K context,
2093
- // text+image input, and a `reasoning_effort` ladder that adds a new `xhigh`
2094
- // top rung (low/medium/high default/xhigh; reasoning still can't be fully
2203
+ // Grok 4.7 (released 2026-09-21) — xAI's flagship for coding, agentic tasks,
2204
+ // and knowledge work: a new, larger base model with a longer RL run weighted
2205
+ // toward hours-long tasks, plus stronger self-verification and long-context
2206
+ // management. 500K context, text+image input, and a `reasoning_effort`
2207
+ // ladder of low/medium/high default/xhigh (reasoning still can't be fully
2095
2208
  // disabled). $2/$6 per MTok under 200K prompt tokens ($4/$12 at or above),
2096
- // and it's the default model of the Grok Build coding agent. xAI advertises "no text output limit"; we keep the same
2097
- // 131K practical cap as 4.5 for budget predictability and input headroom.
2209
+ // and it's the default model of the Grok Build coding agent. xAI advertises
2210
+ // "no fixed text output limit"; we keep the 131K practical cap for budget
2211
+ // predictability and input headroom. (A faster "Grok 4.7 Fast" variant
2212
+ // exists but is Cursor/Grok Build-only — not on the public API — so it isn't
2213
+ // registered.) Only the newest Grok ships — 4.6/4.5 are superseded and
2214
+ // retired; saved sessions on them fall back to this default.
2098
2215
  {
2099
- id: "grok-4.6",
2100
- name: "Grok 4.6",
2216
+ id: "grok-4.7",
2217
+ name: "Grok 4.7",
2101
2218
  provider: "xai",
2102
2219
  contextWindow: 5e5,
2103
2220
  maxOutputTokens: 131072,
@@ -2107,24 +2224,6 @@ var MODELS = [
2107
2224
  costTier: "medium",
2108
2225
  maxThinkingLevel: "xhigh"
2109
2226
  },
2110
- // Grok 4.5 (released 2026-07-08) — superseded by 4.6 but retained as an explicit option. 500K context, text+image input,
2111
- // configurable `reasoning_effort` (low/medium/high, server default high;
2112
- // reasoning can't be fully disabled). Served over the OpenAI-compatible API
2113
- // at https://api.x.ai/v1 (API key from console.x.ai). xAI hasn't published an
2114
- // official max-output cap for 4.5; 131K matches the Grok Responses ceiling
2115
- // third-party integrations use.
2116
- {
2117
- id: "grok-4.5",
2118
- name: "Grok 4.5",
2119
- provider: "xai",
2120
- contextWindow: 5e5,
2121
- maxOutputTokens: 131072,
2122
- supportsThinking: true,
2123
- supportsImages: true,
2124
- supportsVideo: false,
2125
- costTier: "medium",
2126
- maxThinkingLevel: "high"
2127
- },
2128
2227
  // ── Gemini ─────────────────────────────────────────
2129
2228
  {
2130
2229
  id: "gemini-3.1-flash-lite",
@@ -2313,11 +2412,15 @@ var MODELS = [
2313
2412
  maxThinkingLevel: "high"
2314
2413
  },
2315
2414
  // ── Xiaomi (MiMo) ──────────────────────────────────────
2316
- // V2.6 series (2026-09) supersedes V2.5 one-for-one: pro → pro, the omni
2317
- // `mimo-v2.5` → flash, ultraspeed → ultraspeed. The whole series is now
2318
- // full-modality, so unlike V2.5-Pro the flagship no longer needs a separate
2319
- // omni sibling for attachments. V2.5 entries are retired here — a session
2320
- // that still has one saved falls back to the provider default on next start.
2415
+ // V2.6 series (released 2026-09-22, open-weight: Pro 1.02T/42B-A, Flash
2416
+ // 309B/15B-A, plus a 9B Qwen distill not served over the API) supersedes V2.5
2417
+ // one-for-one: pro → pro, the omni `mimo-v2.5` → flash, ultraspeed →
2418
+ // ultraspeed. Every V2.6 text model is natively full-modality, so unlike
2419
+ // V2.5-Pro the flagship no longer needs a separate omni sibling for
2420
+ // attachments — image/video ride the same OpenAI-compatible base64 transport
2421
+ // the old omni model used. API prices are unchanged from V2.5. The V2.5 ids
2422
+ // deprecate on the platform 2026-10-21 and are retired here — a session that
2423
+ // still has one saved falls back to the provider default on next start.
2321
2424
  //
2322
2425
  // Capabilities below are measured against the Token Plan host, not taken
2323
2426
  // from marketing copy: image and video both come back with `image_tokens` /
@@ -2327,6 +2430,8 @@ var MODELS = [
2327
2430
  // binary 1M below (2^20) and not the decimal 1e6 V2.5 was listed with — the
2328
2431
  // few-token gap is the chat envelope the server adds on top of the content.
2329
2432
  {
2433
+ // Coding/agentic flagship — highest open-weight score on Artificial
2434
+ // Analysis at launch (46, tied with Grok 4.7).
2330
2435
  id: "mimo-v2.6-pro",
2331
2436
  name: "MiMo-V2.6-Pro",
2332
2437
  provider: "xiaomi",
@@ -2340,9 +2445,10 @@ var MODELS = [
2340
2445
  maxThinkingLevel: "high",
2341
2446
  authStorageKeys: ["xiaomi", XIAOMI_CREDITS_KEY]
2342
2447
  },
2343
- // Flash: the cheap, high-frequency sibling at the same modality surface and
2344
- // window as Pro. It is the provider's `low` tier, so scout sub-agents and
2345
- // compaction summaries route here instead of paying Pro rates.
2448
+ // Flash: the cheap, high-frequency sibling (~10% of Pro's price class) at the
2449
+ // same modality surface and window as Pro. It is the provider's `low` tier,
2450
+ // so scout sub-agents and compaction summaries route here instead of paying
2451
+ // Pro rates.
2346
2452
  {
2347
2453
  id: "mimo-v2.6-flash",
2348
2454
  name: "MiMo-V2.6-Flash",
@@ -2363,9 +2469,9 @@ var MODELS = [
2363
2469
  // authStorageKeys doc). The Token Plan host rejects it with "Not supported
2364
2470
  // model" — the known-model/wrong-host reply — where an invented id gets
2365
2471
  // "Unsupported model", which is how this id was confirmed without a
2366
- // Credits key. Attachment support is inferred from the series announcement
2367
- // ("full modality across the series") rather than measured: images are
2368
- // enabled, video stays off until it can be verified on the platform host.
2472
+ // Credits key. Attachments can't be probed directly for the same reason, so
2473
+ // this entry tracks the rest of the V2.6 series ("full modality across the
2474
+ // series") and mirrors Pro's verified image+video surface.
2369
2475
  {
2370
2476
  id: "mimo-v2.6-pro-ultraspeed",
2371
2477
  name: "MiMo-V2.6-Pro-UltraSpeed",
@@ -2374,7 +2480,8 @@ var MODELS = [
2374
2480
  maxOutputTokens: 131072,
2375
2481
  supportsThinking: true,
2376
2482
  supportsImages: true,
2377
- supportsVideo: false,
2483
+ supportsVideo: true,
2484
+ maxVideoBytes: 36 * 1024 * 1024,
2378
2485
  costTier: "high",
2379
2486
  maxThinkingLevel: "high",
2380
2487
  authStorageKeys: [XIAOMI_CREDITS_KEY]
@@ -2524,7 +2631,7 @@ function getDefaultModel(provider) {
2524
2631
  return MODELS.find((m) => m.id === "Qwen/Qwen3-Coder-480B-A35B-Instruct");
2525
2632
  if (provider === "openrouter") return MODELS.find((m) => m.id === "qwen/qwen3.6-plus");
2526
2633
  if (provider === "sakana") return MODELS.find((m) => m.id === "fugu");
2527
- if (provider === "xai") return MODELS.find((m) => m.id === "grok-4.6");
2634
+ if (provider === "xai") return MODELS.find((m) => m.id === "grok-4.7");
2528
2635
  if (provider === "local") {
2529
2636
  return getModelsForProvider("local")[0] ?? PLACEHOLDER_LOCAL_MODEL;
2530
2637
  }
@@ -2592,7 +2699,9 @@ export {
2592
2699
  log,
2593
2700
  registerLogCleanup,
2594
2701
  closeLogger,
2702
+ compareClaudeCodeVersions,
2595
2703
  getClaudeCodeVersion,
2704
+ recordRequiredClaudeCodeVersion,
2596
2705
  getClaudeCliUserAgent,
2597
2706
  loginAnthropic,
2598
2707
  refreshAnthropicToken,
@@ -2636,4 +2745,4 @@ export {
2636
2745
  getSummaryModel,
2637
2746
  getFastModel
2638
2747
  };
2639
- //# sourceMappingURL=chunk-SQLBQOQH.js.map
2748
+ //# sourceMappingURL=chunk-THUBQC6I.js.map