nolo-cli 0.159.0-alpha.3 → 0.160.0-alpha.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.
Files changed (123) hide show
  1. package/{_executeModel-SHA5BWRT.js → _executeModel-3HHZYHHB.js} +38 -37
  2. package/accountResolver-55EDKEIK.js +1 -1
  3. package/action-GPPJC5TI.js +1 -1
  4. package/{addContentAction-BI6RDRTQ.js → addContentAction-XJQEJ4XW.js} +6 -6
  5. package/{addDialogAgentAction-4RJYUSIK.js → addDialogAgentAction-5WZX5CAY.js} +5 -5
  6. package/{agentDeleteCommand-VU3BA264.js → agentDeleteCommand-ON2KVSJ5.js} +55 -55
  7. package/{agentEmailCommands-WUANEGTM.js → agentEmailCommands-2QPD5VP3.js} +55 -55
  8. package/{agentListCommands-3YNO6UP4.js → agentListCommands-L33M3I6V.js} +30 -30
  9. package/{agentMachineCommands-ONGZXXQW.js → agentMachineCommands-V44DPSED.js} +25 -23
  10. package/{agentPullCommand-FA43RBRU.js → agentPullCommand-GXXEDOSA.js} +4 -4
  11. package/{agentRecordCommands-DXXA2RET.js → agentRecordCommands-CKILCNQZ.js} +49 -49
  12. package/{agentRunCommand-WY77TJ72.js → agentRunCommand-6IN7NK7H.js} +52 -52
  13. package/{agentRunControl-PPYWJRIJ.js → agentRunControl-XBSNHHZE.js} +4 -4
  14. package/{agentRuntimeLocal-NHC5DQPJ.js → agentRuntimeLocal-XCKO5FVP.js} +13 -11
  15. package/{agentSlice-MIOEV36T.js → agentSlice-YT3VCCEW.js} +6 -6
  16. package/{appDeleteCommands-VQYCXZRF.js → appDeleteCommands-2PJFNLAJ.js} +22 -20
  17. package/{appDeployCommands-OKSJDVEY.js → appDeployCommands-AZCMCMK6.js} +22 -20
  18. package/{appDeployStatusCommands-UFGNZS6G.js → appDeployStatusCommands-HSIKPVJN.js} +22 -20
  19. package/{appGetCommands-3HNO5WLF.js → appGetCommands-IUZCPAP7.js} +22 -20
  20. package/{appListCommands-H33BIZHJ.js → appListCommands-JLFVS44M.js} +22 -20
  21. package/{authCommand-MSINEFHH.js → authCommand-3Z52KJID.js} +14 -14
  22. package/{authCommands-AMNIAKEG.js → authCommands-QOCKVPX3.js} +5 -5
  23. package/{builtinSkillRegistry-H3AY27TR.js → builtinSkillRegistry-LJV7FHNI.js} +4 -4
  24. package/{chunk-MJKKEGF5.js → chunk-2XDQAWBM.js} +12 -12
  25. package/{chunk-GCLZBOB6.js → chunk-2ZYCNT2O.js} +29 -29
  26. package/{chunk-XBLZ5IFE.js → chunk-3GTVM7NJ.js} +17 -17
  27. package/{chunk-US6MKPE7.js → chunk-3L5MSPWX.js} +1 -1
  28. package/{chunk-QYAYO5JA.js → chunk-4L4K6YR7.js} +1 -1
  29. package/{chunk-P5QACQDK.js → chunk-62TBKWTV.js} +1 -1
  30. package/{chunk-YLMMECCH.js → chunk-6XIE5ZGI.js} +1 -1
  31. package/{chunk-J2ATF74A.js → chunk-BAWAKW7X.js} +1 -1
  32. package/{chunk-ZVQHBIWV.js → chunk-CDLP56BS.js} +7 -7
  33. package/{chunk-ZIGIN5IX.js → chunk-DD2EOI6S.js} +1 -1
  34. package/{chunk-OON4OBWI.js → chunk-DLV3H464.js} +7 -7
  35. package/{chunk-DWBY333O.js → chunk-DT7EWFTY.js} +5 -5
  36. package/{chunk-IRTOYSA2.js → chunk-ESMZW5PE.js} +1 -1
  37. package/{chunk-E46SJRWA.js → chunk-EVPKKBSI.js} +13 -13
  38. package/{chunk-ZJG7YU3I.js → chunk-F3SOW2EU.js} +46 -1
  39. package/{chunk-FZYTJOAQ.js → chunk-F5WASHQA.js} +27 -29
  40. package/{chunk-BFI6JGF6.js → chunk-FB5WLEOD.js} +11 -11
  41. package/{chunk-FBSDWUOJ.js → chunk-FCUKCVKN.js} +4 -4
  42. package/{chunk-FY4SDK2E.js → chunk-FDLDMJTM.js} +1 -1
  43. package/{chunk-PKC7D6SX.js → chunk-FFHV45HO.js} +3 -3
  44. package/{chunk-TMYAT2MD.js → chunk-FZYKQFBQ.js} +3 -3
  45. package/{chunk-CSCSMGQI.js → chunk-HW7EBEC5.js} +15 -191
  46. package/{chunk-5MPS5OOY.js → chunk-I7S63QUU.js} +1 -1
  47. package/{chunk-CON6SI7N.js → chunk-IF7V3CBU.js} +1 -1
  48. package/{chunk-GSKVOMBU.js → chunk-JDKSYQQN.js} +4 -4
  49. package/{chunk-RJBHRIEL.js → chunk-JSB2OPQT.js} +107 -45
  50. package/{chunk-M2P3OGXZ.js → chunk-JWEXJ573.js} +2 -2
  51. package/{chunk-NT3LMOSE.js → chunk-K25WQPP3.js} +213 -50
  52. package/{chunk-SPKLALBU.js → chunk-MAYW6V3E.js} +1 -1
  53. package/{chunk-NDZOXXIM.js → chunk-NHEWV5FD.js} +1 -1
  54. package/{chunk-NUE735UT.js → chunk-O2IWR23M.js} +1 -1
  55. package/{chunk-NNE5NIW2.js → chunk-OLVOR45M.js} +2 -2
  56. package/{chunk-CVSKYIXX.js → chunk-QXZH5UDF.js} +2 -2
  57. package/{chunk-QO436IJ5.js → chunk-QZIOZDM6.js} +9 -9
  58. package/{chunk-V4AK4IVZ.js → chunk-R2KWTENX.js} +3 -3
  59. package/{chunk-C3WXTFRP.js → chunk-RIHQGFFA.js} +1 -1
  60. package/{chunk-DC3SZCRR.js → chunk-SH3XD4E2.js} +2 -2
  61. package/{chunk-42W7LKBM.js → chunk-SNAWGDXT.js} +263 -4
  62. package/chunk-TT644UJD.js +188 -0
  63. package/{chunk-QOYJE6NX.js → chunk-U34KT53V.js} +28 -10
  64. package/{chunk-DFWLD7WU.js → chunk-ULQAD7ZY.js} +18 -6
  65. package/{chunk-ZAB4R7LU.js → chunk-UY73HNIN.js} +40 -42
  66. package/{chunk-RE5I35J7.js → chunk-VXS4YYJ2.js} +6 -6
  67. package/{chunk-JZX2XLKC.js → chunk-YCRROBDY.js} +1 -1
  68. package/{chunk-6MH6PWVJ.js → chunk-YR47Y7CN.js} +6 -6
  69. package/{chunk-C47WM5SD.js → chunk-ZAV4YVEA.js} +1 -1
  70. package/{chunk-2NROMJBM.js → chunk-ZSLIYVIQ.js} +7 -7
  71. package/{commandRegistry-DAM7RV6E.js → commandRegistry-A4OR4B4L.js} +83 -83
  72. package/{contentThunks-WLKR5KQ6.js → contentThunks-QBL5NK2W.js} +14 -15
  73. package/{createAgentAutomationAction-AI2HZHLE.js → createAgentAutomationAction-5UWBLR2N.js} +14 -15
  74. package/{createDialogAction-AU4IWDR3.js → createDialogAction-NJ2LE7KC.js} +18 -19
  75. package/{createPageAction-CAXS6ZUJ.js → createPageAction-7T3RINS2.js} +16 -17
  76. package/{dbSlice-DC2J53RC.js → dbSlice-6PVPY44C.js} +5 -5
  77. package/{deleteFile-KYWEMNFX.js → deleteFile-YM6NDPAR.js} +3 -3
  78. package/{dialogCommands-2QMR63AY.js → dialogCommands-KMECTGCW.js} +27 -25
  79. package/{dialogSlice-QEP5EUON.js → dialogSlice-GQMTD4HR.js} +13 -14
  80. package/{docCreateCommands-EG3KFJGO.js → docCreateCommands-4IT5PUAL.js} +24 -22
  81. package/{docDeleteCommands-MAM2BLCP.js → docDeleteCommands-QS66YNZV.js} +25 -23
  82. package/{docReadCommands-XVX2VLVM.js → docReadCommands-3SAI46YC.js} +24 -22
  83. package/{docStore-WTXUKAQB.js → docStore-PM5PYKPZ.js} +6 -6
  84. package/{docUpdateCommands-JURMHPS5.js → docUpdateCommands-OGYG5BRC.js} +24 -22
  85. package/{handleSendMessageAction-7MAFLFOD.js → handleSendMessageAction-EQ3U6K5N.js} +31 -28
  86. package/index.js +7 -7
  87. package/{localRuntimeAdapter-DSO3Y5ZS.js → localRuntimeAdapter-MO64KEOS.js} +46 -46
  88. package/{localRuntimeAuthority-JDAD7CB6.js → localRuntimeAuthority-BPN5OAQG.js} +2 -2
  89. package/{localRuntimeDb-CVC62PM5.js → localRuntimeDb-QIVAXMUL.js} +1 -1
  90. package/{machineCommands-DWILXGTZ.js → machineCommands-7MBJJY4K.js} +51 -51
  91. package/{machineWsRunDispatch-NJJZ34JJ.js → machineWsRunDispatch-T4LFRJL3.js} +47 -47
  92. package/{memberThunks-2DWKLE6W.js → memberThunks-AZINUM4S.js} +8 -8
  93. package/package.json +1 -1
  94. package/{read-L7QEJETH.js → read-7JPIWRBQ.js} +3 -3
  95. package/{readDocTool-QELXV2GW.js → readDocTool-AAQTB2Y3.js} +1 -1
  96. package/{readlineWorkspace-STK57SSQ.js → readlineWorkspace-QHPB5LUC.js} +81 -118
  97. package/{removeDialogAgentAction-376XSUP2.js → removeDialogAgentAction-RMVRILLK.js} +6 -6
  98. package/{runAgentClientLoop-6OD2CTYG.js → runAgentClientLoop-EXIQDX7G.js} +36 -35
  99. package/{runtimeDoctorCommands-HEN5IPIH.js → runtimeDoctorCommands-MMCP4B4U.js} +11 -11
  100. package/{setDialogExtraReferencesAction-QBDSH63D.js → setDialogExtraReferencesAction-L3V7JTMG.js} +6 -6
  101. package/{setPrimaryDialogAgentAction-537QFGW3.js → setPrimaryDialogAgentAction-X52JQGTJ.js} +6 -6
  102. package/{settingThunks-4Z43ZSAT.js → settingThunks-N6XFWPOU.js} +5 -5
  103. package/{spaceCommands-WPCHZKEY.js → spaceCommands-WQMUCGV7.js} +24 -22
  104. package/{streamAgentChatTurn-BOATI5H3.js → streamAgentChatTurn-DI2334G3.js} +132 -72
  105. package/{switchDialogAgentAction-CSO6AKRL.js → switchDialogAgentAction-ZJ5CGU7J.js} +5 -5
  106. package/{tools-FPKQX2J6.js → tools-23VQGJOX.js} +27 -28
  107. package/{tuiSummaryLlmCaller-PEYFTAVL.js → tuiSummaryLlmCaller-FESHBDTT.js} +4 -4
  108. package/{updateCommands-LXZLG44Y.js → updateCommands-KALLBWJE.js} +3 -3
  109. package/{updateDialogTitleAction-WAH5KADA.js → updateDialogTitleAction-AGAYHWS7.js} +14 -15
  110. package/chunk-UKZX3NHN.js +0 -48
  111. package/{agentGrantCommands-HOJ3JBBQ.js → agentGrantCommands-5DPHYEKP.js} +3 -3
  112. package/{agentProviderCommands-CUBOAVPB.js → agentProviderCommands-CXBHNONN.js} +3 -3
  113. package/{chromeOpsCommands-3Z34RKSE.js → chromeOpsCommands-GZVVK7HU.js} +4 -4
  114. package/{chunk-2SGAI64X.js → chunk-43OFVLWJ.js} +4 -4
  115. package/{chunk-XETG4RIX.js → chunk-AETZ7AD6.js} +4 -4
  116. package/{chunk-YNCJYU4X.js → chunk-G3VYRPTV.js} +4 -4
  117. package/{chunk-2IXDJNZI.js → chunk-GAGGEA7D.js} +3 -3
  118. package/{chunk-O4KVUI4W.js → chunk-KABQ74UQ.js} +3 -3
  119. package/{chunk-TCQPBZUL.js → chunk-QA2C5NKI.js} +3 -3
  120. package/{chunk-4RJJDA57.js → chunk-WR37DI7R.js} +3 -3
  121. package/{memoryCommands-CUNBFRVS.js → memoryCommands-ZS3VQJAL.js} +3 -3
  122. package/{offlineMarxistsAgentCommand-2QTHJCHV.js → offlineMarxistsAgentCommand-3GLX4QQY.js} +3 -3
  123. package/{tableCommands-LBH3QPPO.js → tableCommands-IVC5S7Y3.js} +11 -11
@@ -2,13 +2,13 @@ import {
2
2
  isAgentRunTerminalStatus,
3
3
  normalizeRunTitle
4
4
  } from "./chunk-PJNFNEJE.js";
5
- import {
6
- resolvePlatformAuthToken
7
- } from "./chunk-PIG2IUVZ.js";
8
5
  import {
9
6
  isCompiledBinary,
10
7
  resolveCliEntrypointPath
11
8
  } from "./chunk-A7GB5UGH.js";
9
+ import {
10
+ resolvePlatformAuthToken
11
+ } from "./chunk-PIG2IUVZ.js";
12
12
 
13
13
  // packages/cli/client/originShellApprovalTransport.ts
14
14
  import { realpathSync } from "node:fs";
@@ -324,6 +324,233 @@ import { dirname, isAbsolute as isAbsolute2, join, resolve } from "node:path";
324
324
  import * as nodeFs from "node:fs";
325
325
  import { execFileSync as nodeExecFileSync, spawn as nodeSpawn } from "node:child_process";
326
326
 
327
+ // packages/cli/client/hostMemory.ts
328
+ import { readFileSync, existsSync } from "node:fs";
329
+ import { freemem as osFreemem, totalmem as osTotalmem } from "node:os";
330
+ var PROC_MEMINFO_PATH = "/proc/meminfo";
331
+ var PROC_MOUNTS_PATH = "/proc/mounts";
332
+ var DEFAULT_CGROUP2_MOUNT = "/sys/fs/cgroup";
333
+ var SANDBOX_MARKER_PATHS = ["/.dockerenv", "/run/.containerenv"];
334
+ var PROC_SELF_CGROUP_PATH = "/proc/self/cgroup";
335
+ var SANDBOX_CGROUP_PATTERN = /(docker|kubepods|instabox|containerd)/;
336
+ var MEMORY_AVAILABLE_RATIO_THRESHOLD = 0.15;
337
+ var SWAP_USED_RATIO_THRESHOLD = 0.7;
338
+ var HOST_MEMORY_PRESSURE_HINT = "\u26A0 \u5185\u5B58\u504F\u7D27\uFF0C\u5EFA\u8BAE\u91CD\u6D3B\u653E\u6C99\u76D2/\u8FDC\u7AEF\u6216\u51CF\u5C11\u5E76\u53D1";
339
+ var BYTES_PER_MB = 1024 * 1024;
340
+ function toMbFromBytes(bytes) {
341
+ return Math.round(bytes / BYTES_PER_MB);
342
+ }
343
+ function kbToMb(kb) {
344
+ return Math.round(kb / 1024);
345
+ }
346
+ function tryReadText(deps, path) {
347
+ try {
348
+ const reader = deps.readFile ?? ((p) => readFileSync(p, "utf8"));
349
+ const text = reader(path);
350
+ return typeof text === "string" ? text : null;
351
+ } catch {
352
+ return null;
353
+ }
354
+ }
355
+ function tryExists(deps, path) {
356
+ try {
357
+ const checker = deps.exists ?? ((p) => existsSync(p));
358
+ return checker(path) === true;
359
+ } catch {
360
+ return false;
361
+ }
362
+ }
363
+ function readKbValue(text, key) {
364
+ const match = new RegExp(`^${key}:\\s*(\\d+)`, "m").exec(text);
365
+ if (!match) return null;
366
+ const value = Number.parseInt(match[1], 10);
367
+ return Number.isFinite(value) ? value : null;
368
+ }
369
+ function parseProcMeminfo(text) {
370
+ if (typeof text !== "string" || text.length === 0) return null;
371
+ const totalKb = readKbValue(text, "MemTotal");
372
+ const availableKb = readKbValue(text, "MemAvailable");
373
+ if (totalKb === null || availableKb === null) return null;
374
+ if (!(totalKb > 0)) return null;
375
+ const swapTotalKb = readKbValue(text, "SwapTotal") ?? 0;
376
+ const swapFreeKb = readKbValue(text, "SwapFree") ?? 0;
377
+ return {
378
+ source: "proc-meminfo",
379
+ totalMb: kbToMb(totalKb),
380
+ availableMb: kbToMb(Math.max(0, availableKb)),
381
+ swapTotalMb: kbToMb(Math.max(0, swapTotalKb)),
382
+ swapUsedMb: kbToMb(Math.max(0, swapTotalKb - swapFreeKb)),
383
+ hostAvailableMb: null
384
+ };
385
+ }
386
+ function detectSandbox(deps = {}) {
387
+ const platform = deps.platform ?? process.platform;
388
+ if (platform !== "linux") return false;
389
+ for (const marker of SANDBOX_MARKER_PATHS) {
390
+ if (tryExists(deps, marker)) return true;
391
+ }
392
+ const selfCgroup = tryReadText(deps, PROC_SELF_CGROUP_PATH);
393
+ return selfCgroup !== null && SANDBOX_CGROUP_PATTERN.test(selfCgroup);
394
+ }
395
+ function readOsView(deps) {
396
+ const os = deps.os ?? { totalmem: osTotalmem, freemem: osFreemem };
397
+ try {
398
+ const totalMb = toMbFromBytes(os.totalmem());
399
+ const availableMb = toMbFromBytes(os.freemem());
400
+ if (!(totalMb > 0) || !Number.isFinite(availableMb)) return null;
401
+ return {
402
+ source: "os",
403
+ totalMb,
404
+ availableMb: Math.max(0, availableMb),
405
+ // os 没有可移植的 swap 口径:按契约显示 n/a,而不是编一个数字。
406
+ swapTotalMb: null,
407
+ swapUsedMb: null,
408
+ hostAvailableMb: null
409
+ };
410
+ } catch {
411
+ return null;
412
+ }
413
+ }
414
+ function readHostView(deps) {
415
+ const platform = deps.platform ?? process.platform;
416
+ if (platform === "linux") {
417
+ const text = tryReadText(deps, PROC_MEMINFO_PATH);
418
+ if (text !== null) {
419
+ const parsed = parseProcMeminfo(text);
420
+ if (parsed) return parsed;
421
+ }
422
+ }
423
+ return readOsView(deps);
424
+ }
425
+ function parseCgroup2RelativePath(text) {
426
+ for (const line of text.split("\n")) {
427
+ const trimmed = line.trim();
428
+ if (!trimmed) continue;
429
+ const parts = trimmed.split(":");
430
+ if (parts.length < 3 || parts[0] !== "0" || parts[1] !== "") continue;
431
+ const path = parts.slice(2).join(":").trim();
432
+ if (!path) continue;
433
+ return path.startsWith("/") ? path : `/${path}`;
434
+ }
435
+ return null;
436
+ }
437
+ function parseCgroup2MountPoint(mountsText) {
438
+ for (const line of mountsText.split("\n")) {
439
+ const fields = line.trim().split(/\s+/);
440
+ if (fields.length < 3) continue;
441
+ if (fields[2] !== "cgroup2") continue;
442
+ const mountPoint = fields[1].replace(/\\040/g, " ");
443
+ if (mountPoint.startsWith("/")) return mountPoint;
444
+ }
445
+ return null;
446
+ }
447
+ function cgroupAncestorDirs(mountPoint, relativePath) {
448
+ const base = mountPoint.length > 1 && mountPoint.endsWith("/") ? mountPoint.slice(0, -1) : mountPoint;
449
+ const dirs = [];
450
+ if (relativePath && relativePath !== "/") {
451
+ const rel = relativePath.startsWith("/") ? relativePath : `/${relativePath}`;
452
+ const segments = rel.split("/").filter(Boolean);
453
+ for (let depth = segments.length; depth >= 1; depth -= 1) {
454
+ dirs.push(`${base}/${segments.slice(0, depth).join("/")}`);
455
+ }
456
+ }
457
+ dirs.push(base);
458
+ return dirs;
459
+ }
460
+ function readCgroupMaxMb(deps, dir) {
461
+ const maxText = tryReadText(deps, `${dir}/memory.max`);
462
+ if (maxText === null) return null;
463
+ const maxRaw = maxText.trim();
464
+ if (maxRaw === "" || maxRaw === "max") return null;
465
+ const maxBytes = Number.parseInt(maxRaw, 10);
466
+ if (!Number.isFinite(maxBytes) || maxBytes <= 0) return null;
467
+ const totalMb = toMbFromBytes(maxBytes);
468
+ return totalMb > 0 ? totalMb : null;
469
+ }
470
+ function buildCgroupSnapshot(deps, dir, totalMb, hostView) {
471
+ const currentText = tryReadText(deps, `${dir}/memory.current`);
472
+ let usedMb = null;
473
+ if (currentText !== null) {
474
+ const currentBytes = Number.parseInt(currentText.trim(), 10);
475
+ if (Number.isFinite(currentBytes)) {
476
+ usedMb = Math.min(totalMb, Math.max(0, toMbFromBytes(currentBytes)));
477
+ }
478
+ }
479
+ return {
480
+ source: "cgroup",
481
+ totalMb,
482
+ availableMb: usedMb === null ? null : Math.max(0, totalMb - usedMb),
483
+ // swap 不是 cgroup 配额的一部分,只能借宿主视角(Linux 上就是 /proc/meminfo)。
484
+ swapTotalMb: hostView?.swapTotalMb ?? null,
485
+ swapUsedMb: hostView?.swapUsedMb ?? null,
486
+ hostAvailableMb: hostView?.availableMb ?? null
487
+ };
488
+ }
489
+ function readCgroupLimitView(deps, hostView) {
490
+ const selfCgroupText = tryReadText(deps, PROC_SELF_CGROUP_PATH) ?? "";
491
+ const relativePath = parseCgroup2RelativePath(selfCgroupText);
492
+ const mountsText = tryReadText(deps, PROC_MOUNTS_PATH) ?? "";
493
+ const mountPoint = parseCgroup2MountPoint(mountsText) ?? DEFAULT_CGROUP2_MOUNT;
494
+ let limitingDir = null;
495
+ let limitingMb = Number.POSITIVE_INFINITY;
496
+ for (const dir of cgroupAncestorDirs(mountPoint, relativePath)) {
497
+ const totalMb = readCgroupMaxMb(deps, dir);
498
+ if (totalMb === null) continue;
499
+ if (totalMb < limitingMb) {
500
+ limitingMb = totalMb;
501
+ limitingDir = dir;
502
+ }
503
+ }
504
+ if (limitingDir === null) return null;
505
+ return buildCgroupSnapshot(deps, limitingDir, limitingMb, hostView);
506
+ }
507
+ function readHostMemory(deps = {}) {
508
+ const platform = deps.platform ?? process.platform;
509
+ if (platform !== "linux") {
510
+ return readHostView(deps);
511
+ }
512
+ const hostView = readHostView(deps);
513
+ const cgroupView = readCgroupLimitView(deps, hostView);
514
+ if (!cgroupView) return hostView;
515
+ return {
516
+ ...cgroupView,
517
+ scope: detectSandbox(deps) ? "sandbox" : "cgroup-limit"
518
+ };
519
+ }
520
+ function isHostMemoryTight(mem) {
521
+ if (!(mem.totalMb > 0)) return false;
522
+ if (mem.availableMb !== null && mem.availableMb / mem.totalMb < MEMORY_AVAILABLE_RATIO_THRESHOLD) {
523
+ return true;
524
+ }
525
+ if (mem.swapTotalMb !== null && mem.swapUsedMb !== null && mem.swapTotalMb > 0 && mem.swapUsedMb / mem.swapTotalMb > SWAP_USED_RATIO_THRESHOLD) {
526
+ return true;
527
+ }
528
+ return false;
529
+ }
530
+ function formatHostMemoryMb(mb) {
531
+ const value = Math.max(0, Math.round(Number.isFinite(mb) ? mb : 0));
532
+ if (value >= 1024) return `${(value / 1024).toFixed(1)}G`;
533
+ return `${value}M`;
534
+ }
535
+ function formatSwapPart(mem) {
536
+ if (mem.swapTotalMb === null || mem.swapUsedMb === null) return "swap n/a";
537
+ return `swap ${formatHostMemoryMb(mem.swapUsedMb)}/${formatHostMemoryMb(mem.swapTotalMb)}`;
538
+ }
539
+ function formatHostMemoryLine(mem) {
540
+ const usedMb = mem.availableMb === null ? null : Math.max(0, mem.totalMb - mem.availableMb);
541
+ let line;
542
+ if (mem.source === "cgroup") {
543
+ const hostAvailable = mem.hostAvailableMb === null ? "n/a" : formatHostMemoryMb(mem.hostAvailableMb);
544
+ const prefix = (mem.scope ?? "sandbox") === "cgroup-limit" ? "[\u9650\u989D] \u672C\u8FDB\u7A0B\u5185\u5B58" : "[sandbox] \u5BB9\u5668\u5185\u5B58";
545
+ const usage = usedMb === null ? "\u5360\u7528\u672A\u77E5" : formatHostMemoryMb(usedMb);
546
+ line = `${prefix} ${usage}/${formatHostMemoryMb(mem.totalMb)} \xB7 \u5BBF\u4E3B\u53EF\u7528 ${hostAvailable}`;
547
+ } else {
548
+ const available = mem.availableMb === null ? "n/a" : formatHostMemoryMb(mem.availableMb);
549
+ line = `\u672C\u5730\u5185\u5B58 ${formatHostMemoryMb(usedMb ?? 0)}/${formatHostMemoryMb(mem.totalMb)}\uFF08\u53EF\u7528 ${available}\uFF09\xB7 ${formatSwapPart(mem)}`;
550
+ }
551
+ return isHostMemoryTight(mem) ? `${line} \xB7 ${HOST_MEMORY_PRESSURE_HINT}` : line;
552
+ }
553
+
327
554
  // packages/cli/client/localRuntimeHelpers.ts
328
555
  var REMOTE_DIALOG_SYNC_TIMEOUT_MS = 1e4;
329
556
  var remoteDialogSyncTimeoutMsForTest;
@@ -1183,6 +1410,29 @@ function buildAgentRunChildCommand(options, deps = {}) {
1183
1410
  }
1184
1411
  return { execPath, childArgs: [entrypoint, ...commandParts, ...strippedArgs] };
1185
1412
  }
1413
+ function safeReadHostMemory(reader) {
1414
+ try {
1415
+ return reader();
1416
+ } catch {
1417
+ return null;
1418
+ }
1419
+ }
1420
+ function emitHostMemoryNotice(mem, output) {
1421
+ if (!mem || !output) return void 0;
1422
+ let notice;
1423
+ try {
1424
+ notice = formatHostMemoryLine(mem);
1425
+ } catch {
1426
+ return void 0;
1427
+ }
1428
+ try {
1429
+ output.write(`${notice}
1430
+ `);
1431
+ } catch {
1432
+ return notice;
1433
+ }
1434
+ return notice;
1435
+ }
1186
1436
  async function spawnLocalBackgroundRun(input, deps = {}) {
1187
1437
  const env = deps.env ?? process.env;
1188
1438
  const homedir = deps.homedir ?? nodeHomedir;
@@ -1266,6 +1516,7 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
1266
1516
  NOLO_AGENT_RUN_CHILD: "1",
1267
1517
  NOLO_AGENT_RUN_ID: runId
1268
1518
  };
1519
+ const hostMemory = safeReadHostMemory(deps.readHostMemory ?? readHostMemory);
1269
1520
  const logFd = fs.openSync(logPath, "a");
1270
1521
  const proc = spawn(execPath, childArgs, {
1271
1522
  cwd: input.cwd,
@@ -1283,6 +1534,7 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
1283
1534
  proc.channel?.unref?.();
1284
1535
  }
1285
1536
  proc.unref();
1537
+ const hostMemoryNotice = emitHostMemoryNotice(hostMemory, input.output);
1286
1538
  if (typeof proc.pid === "number") {
1287
1539
  const processStartedAt = (deps.getProcessStartTime ?? defaultGetProcessStartTime)(proc.pid);
1288
1540
  withRunRecordLock(runId, deps, () => {
@@ -1292,7 +1544,14 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
1292
1544
  writeRunRecord(latest, deps);
1293
1545
  });
1294
1546
  }
1295
- return { runId, pid: proc.pid, logPath, queuePath, batchId };
1547
+ return {
1548
+ runId,
1549
+ pid: proc.pid,
1550
+ logPath,
1551
+ queuePath,
1552
+ batchId,
1553
+ ...hostMemoryNotice ? { hostMemoryNotice } : {}
1554
+ };
1296
1555
  }
1297
1556
  function ackRunRecord(runId, deps = {}) {
1298
1557
  withRunRecordLock(runId, deps, () => {
@@ -0,0 +1,188 @@
1
+ import {
2
+ shouldUseServerProxy
3
+ } from "./chunk-F3SOW2EU.js";
4
+ import {
5
+ ANTIGRAVITY_CLOUD_CODE_BASE_URL,
6
+ isAntigravityCloudCodeBaseUrl,
7
+ isAntigravityOAuthAgent
8
+ } from "./chunk-SQX235S2.js";
9
+ import {
10
+ isOpenAiResponsesModel,
11
+ resolvePlatformChatCompletionsEndpoint,
12
+ resolvePlatformResponsesEndpoint
13
+ } from "./chunk-V7PCFWX3.js";
14
+ import {
15
+ findModelConfig
16
+ } from "./chunk-6EQD4AQL.js";
17
+ import {
18
+ asOptionalTrimmedString
19
+ } from "./chunk-G3SUCT4W.js";
20
+ import {
21
+ asTrimmedLowercaseString
22
+ } from "./chunk-QSJ3HFEF.js";
23
+
24
+ // packages/agent-runtime/agentCallPlan.ts
25
+ var CODEX_RESPONSES_URL = "https://chatgpt.com/backend-api/codex/responses";
26
+ var CURSOR_AGENT_URL = "https://api2.cursor.sh/agent.v1.AgentService/Run";
27
+ var DEVIN_CONNECT_URL = "https://server.codeium.com/exa.api_server_pb.ApiServerService/GetChatMessage";
28
+ function resolveClientWire(plan) {
29
+ if (plan.upstreamWire === "gemini-cca") return "chat.completions";
30
+ if (plan.upstreamWire === "anthropic-messages") return "chat.completions";
31
+ if (plan.upstreamWire === "cursor-connect") return "chat.completions";
32
+ if (plan.upstreamWire === "devin-connect") return "chat.completions";
33
+ if (plan.upstreamWire === "custom-gemini") return "chat.completions";
34
+ if (plan.upstreamWire === "custom-openai-responses") return "chat.completions";
35
+ if (plan.upstreamWire === "custom-anthropic-messages") return "chat.completions";
36
+ if (plan.upstreamWire === "responses" && plan.authMethod.kind === "oauth" && plan.authMethod.ref === "chatgpt") {
37
+ return "chat.completions";
38
+ }
39
+ return plan.upstreamWire;
40
+ }
41
+ var XAI_CHAT_COMPLETIONS_URL = "https://api.x.ai/v1/chat/completions";
42
+ var ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages";
43
+ var CODEX_REQUIRED_HEADERS = [
44
+ "chatgpt-account-id",
45
+ "OpenAI-Beta",
46
+ "originator",
47
+ "version"
48
+ ];
49
+ var ANTIGRAVITY_REQUIRED_HEADERS = [
50
+ "User-Agent"
51
+ // antigravity-specific UA (matches getAntigravityUserAgent)
52
+ ];
53
+ function agentShouldUseServerProxy(agentConfig) {
54
+ return shouldUseServerProxy(agentConfig);
55
+ }
56
+ function resolveCustomUpstreamWire(endpoint, nativeProtocol) {
57
+ const responsesEndpoint = endpoint.includes("/responses");
58
+ if (nativeProtocol === "openai-responses" && responsesEndpoint) return "responses";
59
+ if (nativeProtocol === "gemini") return "custom-gemini";
60
+ if (nativeProtocol === "openai-responses") return "custom-openai-responses";
61
+ if (nativeProtocol === "anthropic-messages") return "custom-anthropic-messages";
62
+ return responsesEndpoint ? "responses" : "chat.completions";
63
+ }
64
+ function hasOwnCustomProviderKey(agentConfig) {
65
+ const endpoint = asOptionalTrimmedString(agentConfig.customProviderUrl);
66
+ if (!endpoint) return false;
67
+ if (isAntigravityCloudCodeBaseUrl(endpoint)) return false;
68
+ return Boolean(asOptionalTrimmedString(agentConfig.apiKey));
69
+ }
70
+ function resolveAgentCallPlan(agentConfig, _env) {
71
+ const apiKeyRef = asTrimmedLowercaseString(agentConfig.apiKeyRef);
72
+ const provider = asTrimmedLowercaseString(
73
+ agentConfig.provider ?? agentConfig.apiSource
74
+ );
75
+ const ownCustomKeyWins = hasOwnCustomProviderKey(agentConfig);
76
+ const oauthApiKeyRef = ownCustomKeyWins ? "" : apiKeyRef;
77
+ if (!ownCustomKeyWins && isAntigravityOAuthAgent(agentConfig)) {
78
+ return {
79
+ authMethod: { kind: "oauth", ref: "antigravity" },
80
+ transport: "server-proxy",
81
+ upstreamWire: "gemini-cca",
82
+ endpoint: ANTIGRAVITY_CLOUD_CODE_BASE_URL,
83
+ requiredHeaders: [...ANTIGRAVITY_REQUIRED_HEADERS],
84
+ vendor: provider || "google-antigravity"
85
+ };
86
+ }
87
+ if (oauthApiKeyRef === "chatgpt") {
88
+ return {
89
+ authMethod: { kind: "oauth", ref: "chatgpt" },
90
+ transport: "server-proxy",
91
+ upstreamWire: "responses",
92
+ endpoint: CODEX_RESPONSES_URL,
93
+ requiredHeaders: [...CODEX_REQUIRED_HEADERS],
94
+ vendor: provider || "openai"
95
+ };
96
+ }
97
+ if (oauthApiKeyRef === "claude") {
98
+ return {
99
+ authMethod: { kind: "oauth", ref: "claude" },
100
+ transport: "server-proxy",
101
+ upstreamWire: "anthropic-messages",
102
+ endpoint: ANTHROPIC_MESSAGES_URL,
103
+ requiredHeaders: ["anthropic-version", "anthropic-beta"],
104
+ vendor: provider || "anthropic"
105
+ };
106
+ }
107
+ if (oauthApiKeyRef === "xai") {
108
+ return {
109
+ authMethod: { kind: "oauth", ref: "xai" },
110
+ transport: "server-proxy",
111
+ upstreamWire: "chat.completions",
112
+ endpoint: XAI_CHAT_COMPLETIONS_URL,
113
+ requiredHeaders: [],
114
+ vendor: provider || "xai"
115
+ };
116
+ }
117
+ if (oauthApiKeyRef === "cursor") {
118
+ return {
119
+ authMethod: { kind: "oauth", ref: "cursor" },
120
+ transport: "server-proxy",
121
+ upstreamWire: "cursor-connect",
122
+ endpoint: CURSOR_AGENT_URL,
123
+ requiredHeaders: [
124
+ "x-cursor-client-version",
125
+ "x-cursor-client-type",
126
+ "x-ghost-mode"
127
+ ],
128
+ vendor: provider || "cursor"
129
+ };
130
+ }
131
+ if (oauthApiKeyRef === "devin" || !ownCustomKeyWins && provider === "devin") {
132
+ return {
133
+ authMethod: { kind: "oauth", ref: "devin" },
134
+ transport: "server-proxy",
135
+ upstreamWire: "devin-connect",
136
+ endpoint: DEVIN_CONNECT_URL,
137
+ requiredHeaders: ["connect-protocol-version"],
138
+ vendor: provider || "devin"
139
+ };
140
+ }
141
+ if (agentConfig.cliProvider || agentConfig.apiSource === "cli" || provider === "cli") {
142
+ return {
143
+ authMethod: { kind: "cli", provider: agentConfig.cliProvider || provider || "codex" },
144
+ transport: "direct",
145
+ upstreamWire: "cli",
146
+ endpoint: "",
147
+ requiredHeaders: [],
148
+ vendor: provider || "cli"
149
+ };
150
+ }
151
+ if (agentConfig.customProviderUrl || agentConfig.apiSource === "custom") {
152
+ const transport2 = agentShouldUseServerProxy(agentConfig) ? "server-proxy" : "direct";
153
+ const endpoint2 = asOptionalTrimmedString(agentConfig.customProviderUrl) ?? "";
154
+ const upstreamWire2 = resolveCustomUpstreamWire(
155
+ endpoint2,
156
+ findModelConfig(provider, agentConfig.model ?? "")?.nativeProtocol
157
+ );
158
+ return {
159
+ authMethod: { kind: "custom-key" },
160
+ transport: transport2,
161
+ upstreamWire: upstreamWire2,
162
+ endpoint: endpoint2,
163
+ requiredHeaders: [],
164
+ vendor: provider || "custom"
165
+ };
166
+ }
167
+ const transport = agentShouldUseServerProxy(agentConfig) ? "server-proxy" : "direct";
168
+ const useResponses = isOpenAiResponsesModel({
169
+ provider,
170
+ model: agentConfig.model,
171
+ endpointKey: agentConfig.endpointKey
172
+ });
173
+ const upstreamWire = useResponses ? "responses" : "chat.completions";
174
+ const endpoint = upstreamWire === "responses" ? resolvePlatformResponsesEndpoint(provider, agentConfig.model) ?? "" : resolvePlatformChatCompletionsEndpoint(provider, agentConfig.model) ?? "";
175
+ return {
176
+ authMethod: { kind: "platform-key" },
177
+ transport,
178
+ upstreamWire,
179
+ endpoint,
180
+ requiredHeaders: [],
181
+ vendor: provider || "openai"
182
+ };
183
+ }
184
+
185
+ export {
186
+ resolveClientWire,
187
+ resolveAgentCallPlan
188
+ };
@@ -1,3 +1,9 @@
1
+ import {
2
+ resolveAgentCallPlan
3
+ } from "./chunk-TT644UJD.js";
4
+ import {
5
+ SUBSCRIPTION_OAUTH_PROVIDERS
6
+ } from "./chunk-EWO77ZGF.js";
1
7
  import {
2
8
  findModelConfig,
3
9
  getProviderByModelName
@@ -90,16 +96,18 @@ var lookupKnownModelVision = (provider, model) => {
90
96
  if (provider && provider !== "custom") {
91
97
  const direct = findModelConfig(provider, candidate);
92
98
  if (direct && typeof direct.hasVision === "boolean") return direct.hasVision;
93
- }
94
- const detected = getProviderByModelName(candidate);
95
- if (detected) {
96
- const found = findModelConfig(detected, candidate)?.hasVision;
97
- if (found !== void 0) return found;
99
+ } else {
100
+ const detected = getProviderByModelName(candidate);
101
+ if (detected) {
102
+ const found = findModelConfig(detected, candidate)?.hasVision;
103
+ if (found !== void 0) return found;
104
+ }
98
105
  }
99
106
  if (candidate.includes("/")) {
100
107
  const slash = candidate.indexOf("/");
101
108
  const modelProvider = candidate.slice(0, slash).toLowerCase();
102
109
  const modelName = candidate.slice(slash + 1);
110
+ if (provider && provider !== "custom" && provider !== modelProvider) continue;
103
111
  const nested = findModelConfig(modelProvider, modelName);
104
112
  if (nested && typeof nested.hasVision === "boolean") return nested.hasVision;
105
113
  }
@@ -108,12 +116,22 @@ var lookupKnownModelVision = (provider, model) => {
108
116
  };
109
117
  var resolveAgentImageInputSupport = (agent) => {
110
118
  if (!agent) return true;
111
- const provider = asTrimmedLowercaseString(agent.provider) || null;
119
+ const provider = asTrimmedLowercaseString(agent.provider) || asTrimmedLowercaseString(agent.apiSource) || null;
112
120
  const model = asOptionalTrimmedString(agent.model) ?? "";
113
- const catalogHasVision = lookupKnownModelVision(
114
- provider,
115
- model
116
- );
121
+ const { authMethod } = resolveAgentCallPlan({
122
+ key: "",
123
+ provider: agent.provider ?? void 0,
124
+ apiSource: agent.apiSource ?? void 0,
125
+ cliProvider: agent.cliProvider ?? void 0,
126
+ model,
127
+ apiKeyRef: agent.apiKeyRef ?? void 0,
128
+ customProviderUrl: agent.customProviderUrl ?? void 0,
129
+ apiKey: agent.apiKey ?? void 0,
130
+ useServerProxy: agent.useServerProxy ?? void 0
131
+ });
132
+ const catalogHasVision = authMethod.kind === "oauth" ? SUBSCRIPTION_OAUTH_PROVIDERS.find((entry) => entry.apiKeyRef === authMethod.ref)?.modelOptions.find(
133
+ (entry) => [model, stripEffortSuffix(model), stripPreviewSuffix(model)].includes(entry.id)
134
+ )?.hasVision : lookupKnownModelVision(provider, model);
117
135
  if (catalogHasVision !== void 0) {
118
136
  return catalogHasVision;
119
137
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveAgentImageInputSupport
3
- } from "./chunk-QOYJE6NX.js";
3
+ } from "./chunk-U34KT53V.js";
4
4
  import {
5
5
  asOptionalFiniteNumber
6
6
  } from "./chunk-WWC7I6TA.js";
@@ -33,9 +33,13 @@ function hasImageInRuntimeMessages(messages) {
33
33
  var IMAGE_OMITTED_PLACEHOLDER = "[Image content omitted: model does not support image input]";
34
34
  function stripImagePartsFromContent(content) {
35
35
  if (!Array.isArray(content)) return content;
36
- const filtered = content.filter((part) => part?.type !== "image_url");
37
- if (filtered.length === 0) return IMAGE_OMITTED_PLACEHOLDER;
38
- return filtered;
36
+ const hasImage = content.some((part) => part && typeof part === "object" && part.type === "image_url");
37
+ if (!hasImage) return content;
38
+ const hasNonImage = content.some((part) => part && typeof part === "object" && part.type !== "image_url");
39
+ if (!hasNonImage) return IMAGE_OMITTED_PLACEHOLDER;
40
+ return content.map(
41
+ (part) => part && typeof part === "object" && part.type === "image_url" ? { type: "text", text: IMAGE_OMITTED_PLACEHOLDER } : part
42
+ );
39
43
  }
40
44
  function stripImagePartsFromMessages(messages) {
41
45
  return messages.map((msg) => ({
@@ -45,8 +49,15 @@ function stripImagePartsFromMessages(messages) {
45
49
  }
46
50
  async function stripImagePartsForTextOnlyAgent(messages, agentConfig) {
47
51
  const supportsVision = resolveAgentImageInputSupport(agentConfig);
48
- const hasImages = hasImageInRuntimeMessages(messages);
49
- return { messages: !supportsVision && hasImages ? stripImagePartsFromMessages(messages) : messages };
52
+ const runtimeMessages = messages;
53
+ const hasImages = hasImageInRuntimeMessages(runtimeMessages);
54
+ const shouldStrip = !supportsVision && hasImages;
55
+ const omittedImageCount = shouldStrip ? extractImageUrlsFromMessages(runtimeMessages).length : 0;
56
+ return {
57
+ messages: shouldStrip ? stripImagePartsFromMessages(messages) : messages,
58
+ downgraded: shouldStrip,
59
+ omittedImageCount
60
+ };
50
61
  }
51
62
 
52
63
  // packages/agent-runtime/agentRecordConfig.ts
@@ -414,6 +425,7 @@ function assertDesktopAgentRuntimeTurnBodyHasNoRawSecrets(body) {
414
425
  }
415
426
 
416
427
  export {
428
+ extractImageUrlsFromMessages,
417
429
  hasImageInRuntimeMessages,
418
430
  stripImagePartsFromMessages,
419
431
  stripImagePartsForTextOnlyAgent,