nolo-cli 0.102.0-alpha.1 → 0.102.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 (206) hide show
  1. package/README.md +1 -1
  2. package/{_executeModel-LUNEV235.js → _executeModel-WLFACVFR.js} +74 -67
  3. package/action-PNPQLJHG.js +20 -0
  4. package/{addContentAction-O7R66HEX.js → addContentAction-RBOUD7SJ.js} +12 -11
  5. package/{addDialogAgentAction-74OA7KYP.js → addDialogAgentAction-IODCR6TB.js} +18 -19
  6. package/{agentDeleteCommand-2YAHAZFJ.js → agentDeleteCommand-XHHDYJ3U.js} +117 -42
  7. package/{agentEmailCommands-G6A7IRPQ.js → agentEmailCommands-GJ2TE3CV.js} +97 -87
  8. package/agentListCommands-B3YHJQNM.js +742 -0
  9. package/{agentMachineCommands-W2SMNSQ3.js → agentMachineCommands-KQLRJF5O.js} +48 -43
  10. package/{agentProviderCommands-GNPTL5XR.js → agentProviderCommands-XPJYZSCE.js} +97 -2
  11. package/{agentPullCommand-O5MPVJ5E.js → agentPullCommand-B4T2DJ5H.js} +1 -1
  12. package/agentRecordCommands-LXDIXYQM.js +138 -0
  13. package/agentRunCommand-P2KLVSYL.js +167 -0
  14. package/{agentRunControl-AVJR4JW4.js → agentRunControl-3HWA2LLQ.js} +2 -2
  15. package/{agentRuntimeLocal-VXZSDIGT.js → agentRuntimeLocal-SXYAKX3A.js} +48 -39
  16. package/{agentSlice-5YJHUO47.js → agentSlice-WBSSBKBB.js} +14 -13
  17. package/{appDeleteCommands-32MHLR4L.js → appDeleteCommands-4EX37I4K.js} +46 -41
  18. package/{appDeployCommands-WCQOUSOB.js → appDeployCommands-SDBR3J75.js} +46 -41
  19. package/{appDeployStatusCommands-6QKB7DYN.js → appDeployStatusCommands-764PQNYN.js} +46 -41
  20. package/{appGetCommands-SFAPP5PB.js → appGetCommands-BBCN3XJC.js} +46 -41
  21. package/{appListCommands-EKUBDRUO.js → appListCommands-OGTABCS3.js} +46 -41
  22. package/{authCommand-F4EFRRX6.js → authCommand-NHDLY3IB.js} +118 -24
  23. package/{authCommands-RGOGCPP6.js → authCommands-UDBJVSZU.js} +7 -5
  24. package/{builtinSkillRegistry-FUAVTRVZ.js → builtinSkillRegistry-MAR5LPAC.js} +10 -8
  25. package/{chromeCommands-FZYAU75D.js → chromeCommands-K27J4OVZ.js} +124 -28
  26. package/{chromeOpsCommands-62P2Q2YB.js → chromeOpsCommands-IXRLN57H.js} +4 -3
  27. package/{chunk-6OZ36FXI.js → chunk-27ONFIEY.js} +22 -4
  28. package/{chunk-JEDZAO7L.js → chunk-2SYTUTLI.js} +257 -37
  29. package/{chunk-53HEEOTT.js → chunk-2WJ57RJA.js} +83 -16
  30. package/{chunk-OIVSQH2O.js → chunk-3BXNTXYI.js} +299 -5
  31. package/{chunk-ABQYVJBJ.js → chunk-46Y5D2BZ.js} +5 -5
  32. package/{chunk-EYAQT56M.js → chunk-4DPP773Q.js} +2 -2
  33. package/{chunk-H62HCIUP.js → chunk-4FFUDT6D.js} +24 -21
  34. package/chunk-4LCOCOR5.js +50 -0
  35. package/{chunk-2GRGFCF6.js → chunk-4VJAC32I.js} +2 -1
  36. package/{chunk-IIVGDG4I.js → chunk-4YSOUKUR.js} +13 -7
  37. package/{chunk-MC4XLIJ7.js → chunk-523DITKR.js} +1 -1
  38. package/{chunk-E4MARS3Q.js → chunk-5GVBDNTO.js} +1 -1
  39. package/chunk-5J3PYNUP.js +255 -0
  40. package/{chunk-DRGSDQBL.js → chunk-5LTAPGPV.js} +10 -10
  41. package/chunk-5MMAK75Q.js +15 -0
  42. package/{chunk-JPGCXHNM.js → chunk-5OA5HMTL.js} +1 -1
  43. package/{chunk-42V6BK2E.js → chunk-62IL3KQV.js} +4 -34
  44. package/{chunk-3BMYXEUW.js → chunk-6O4IK4V2.js} +1 -1
  45. package/{chunk-AEOE4Z6Q.js → chunk-7EPXUZOX.js} +39 -15
  46. package/{chunk-GQBOR3G6.js → chunk-7KVZ5LDQ.js} +2 -2
  47. package/{chunk-DNCEALKX.js → chunk-7MMSLEPA.js} +22 -29
  48. package/{chunk-L5UXH3B2.js → chunk-7TKWCTSY.js} +22 -6
  49. package/chunk-A4SQRTZ6.js +15 -0
  50. package/{chunk-7S4YWN7P.js → chunk-ADBZWMFB.js} +4 -4
  51. package/chunk-AGIM7IMJ.js +147 -0
  52. package/{chunk-SSDAAEC2.js → chunk-AOJB5QYD.js} +873 -227
  53. package/{chunk-5UTFL4QJ.js → chunk-AOTBKDRK.js} +7 -0
  54. package/{chunk-Q554LLSI.js → chunk-AUDNYVRC.js} +1 -1
  55. package/chunk-BMQ2MJUK.js +153 -0
  56. package/{chunk-6YTOJY35.js → chunk-BZ7NPA6G.js} +35 -2
  57. package/{chunk-4S5QUMJP.js → chunk-CHNCM7EF.js} +11 -9
  58. package/chunk-CHOZJMJS.js +78 -0
  59. package/chunk-CJN5OERD.js +13545 -0
  60. package/{chunk-ACTMNVHM.js → chunk-CYSYR67N.js} +1 -1
  61. package/{chunk-GBRG75BQ.js → chunk-D2MDMY2M.js} +1 -0
  62. package/{chunk-RFCKMYDK.js → chunk-DNHENQ3T.js} +23 -28
  63. package/chunk-DZ7R5V3Y.js +164 -0
  64. package/{chunk-3VNWWVKB.js → chunk-E3YWHWCR.js} +50 -18
  65. package/{chunk-V4MJDUSR.js → chunk-E73ON47R.js} +2 -2
  66. package/{chunk-ETI2NYVF.js → chunk-EHER73LN.js} +4 -4
  67. package/{chunk-KQ4ONNQD.js → chunk-EKPKW6RM.js} +155 -8
  68. package/{chunk-TRV2MIDW.js → chunk-EXAJ6DCR.js} +1 -0
  69. package/{chunk-HJUYAD4A.js → chunk-FJ5BGMNM.js} +5 -5
  70. package/{chunk-2F7RJC6L.js → chunk-FOXQ7BAB.js} +1 -1
  71. package/{chunk-6VFARHZW.js → chunk-G53AA7RW.js} +934 -1091
  72. package/{chunk-J4MOO56S.js → chunk-GARACBQB.js} +10 -2
  73. package/chunk-GMZLP5DV.js +82 -0
  74. package/{chunk-5FBTLSFG.js → chunk-GUYEMTRK.js} +551 -516
  75. package/{chunk-FDTR4QJ6.js → chunk-H6A6X4EK.js} +32 -1
  76. package/{chunk-DVINR3PL.js → chunk-HDLLCBRF.js} +1 -1
  77. package/{chunk-QOKAKDPE.js → chunk-HIM3FCLF.js} +0 -1
  78. package/{chunk-ONXOABJR.js → chunk-HNGRBWYF.js} +3 -0
  79. package/{chunk-VLTIYV3X.js → chunk-HP57OUJO.js} +4 -4
  80. package/{chunk-6IG4XSS6.js → chunk-HRYFI64G.js} +88 -17
  81. package/{chunk-GPCZ7UXG.js → chunk-K6U4NKFJ.js} +1 -1
  82. package/{chunk-6Q33GUCC.js → chunk-KLUBZL6X.js} +1 -1
  83. package/{chunk-4OEFYTWL.js → chunk-LKERWYPX.js} +67 -48
  84. package/{chunk-LS2ZANRJ.js → chunk-LOCNXNOU.js} +1 -1
  85. package/{chunk-PUOC4YRO.js → chunk-M7VLQGQP.js} +11 -0
  86. package/{chunk-NA35QHCF.js → chunk-N4QIAW6W.js} +1 -1
  87. package/{chunk-BFU6C242.js → chunk-NMFV26UG.js} +1 -1
  88. package/{chunk-OEVAY4J6.js → chunk-NTDEBTK5.js} +18 -20
  89. package/{chunk-FZGV4FGK.js → chunk-NUHHBEJC.js} +378 -187
  90. package/chunk-NWENLDMM.js +42 -0
  91. package/chunk-OCZKATRC.js +129 -0
  92. package/{chunk-G2O6V3HJ.js → chunk-ODTDLPBV.js} +20 -11
  93. package/chunk-OW4APERY.js +870 -0
  94. package/{chunk-KQHGZWSV.js → chunk-OXME3PEE.js} +1 -1
  95. package/{chunk-Q2XN3EOZ.js → chunk-OYPMWCIQ.js} +67 -45
  96. package/{chunk-TOP2VXOR.js → chunk-PCF3QU5Q.js} +5 -5
  97. package/chunk-PH275YDS.js +7881 -0
  98. package/{chunk-WV42OMV7.js → chunk-PTDYOADJ.js} +8 -8
  99. package/{chunk-GEPUP7OO.js → chunk-SEA64CDY.js} +3 -3
  100. package/{chunk-5H7KJX7J.js → chunk-SEB5HAUU.js} +5 -5
  101. package/{chunk-6D6VBVEW.js → chunk-SNMQMOD2.js} +80 -14
  102. package/{chunk-BYMV6QZG.js → chunk-TNIX77YM.js} +4 -0
  103. package/{chunk-Z77CRGTW.js → chunk-TVCAR26G.js} +1 -1
  104. package/chunk-TY3TIUJK.js +89 -0
  105. package/{chunk-I3TQJXQ7.js → chunk-U3C3IA32.js} +9 -2
  106. package/{chunk-ORYWEJO4.js → chunk-U6IGAJT4.js} +47 -67
  107. package/{chunk-RG6JBBX5.js → chunk-U7XXEI5R.js} +166 -13
  108. package/{chunk-UZGQNTVW.js → chunk-UA324D4O.js} +8 -6
  109. package/chunk-UJXNKP5V.js +760 -0
  110. package/{chunk-UKZDAFYT.js → chunk-UM4PH574.js} +6 -10
  111. package/{chunk-ZCYXJSTU.js → chunk-V5OWQOJZ.js} +19 -88
  112. package/{chunk-3DII57IT.js → chunk-VCAQFMVN.js} +1 -1
  113. package/{chunk-JRQFUXY7.js → chunk-VEYL5MO5.js} +99 -22
  114. package/chunk-VIWDGTDA.js +8 -0
  115. package/chunk-VJVNU77E.js +83 -0
  116. package/{chunk-UKWGR5SS.js → chunk-VY6VFGKR.js} +194 -1144
  117. package/{chunk-BP4XNZRM.js → chunk-W72ISAKC.js} +4 -4
  118. package/{chunk-DHDMC6FO.js → chunk-WCGC6S77.js} +14 -9
  119. package/{chunk-QDSINZM3.js → chunk-WJ3B6FX6.js} +1 -14
  120. package/{chunk-HVURBGF3.js → chunk-XFUBXRVI.js} +6 -6
  121. package/{chunk-45C5ER5U.js → chunk-XIRXOUBV.js} +19 -17
  122. package/{chunk-O6OSWFZQ.js → chunk-XUWRURDF.js} +6 -0
  123. package/{chunk-Q67DOFOO.js → chunk-Y3PMXGLH.js} +2 -0
  124. package/{chunk-SH43IESU.js → chunk-YUNJN43V.js} +44 -9
  125. package/chunk-YV25TM3R.js +780 -0
  126. package/{chunk-X6DN5HBD.js → chunk-YXZYNMYK.js} +29 -9
  127. package/{chunk-BTI7PJDX.js → chunk-Z56IK6UT.js} +29 -78
  128. package/chunk-ZRAU6T47.js +56 -0
  129. package/commandRegistry-TDXN5OP7.js +833 -0
  130. package/{contentThunks-GJV22WVZ.js → contentThunks-F2BNWOZV.js} +36 -34
  131. package/{cooldownCommands-REAWYVTY.js → cooldownCommands-ZLEPIB4A.js} +2 -2
  132. package/{createAgentAutomationAction-6V25TZEO.js → createAgentAutomationAction-5N2NRNR7.js} +38 -36
  133. package/createDialogAction-DSEG4L5Y.js +69 -0
  134. package/{createPageAction-IR4BGJSI.js → createPageAction-K32FYQPE.js} +45 -42
  135. package/{chunk-YFE4A4O7.js → cursorProvider-YGGNMVWX.js} +2496 -9897
  136. package/{dbSlice-XVWBAGYN.js → dbSlice-Q25STFGJ.js} +11 -10
  137. package/{deleteFile-YG6QMJLU.js → deleteFile-AJ2EZMHT.js} +7 -6
  138. package/{dialogCommands-5J56DFWN.js → dialogCommands-ODG2OKLO.js} +49 -45
  139. package/{dialogSlice-UNX2FAPZ.js → dialogSlice-4GBOUTGL.js} +40 -33
  140. package/{dist-VODFSGNG.js → dist-NJC2W7I4.js} +61 -54
  141. package/{docCreateCommands-KYI2DC2U.js → docCreateCommands-Q6FQUHUF.js} +48 -43
  142. package/{docDeleteCommands-67REUSRY.js → docDeleteCommands-N224CFZL.js} +49 -44
  143. package/{docReadCommands-HOSVSBDJ.js → docReadCommands-CJWAEAB4.js} +47 -42
  144. package/{docStore-JWVG5NDO.js → docStore-ZTYSP3YE.js} +16 -12
  145. package/{docUpdateCommands-EMGCSMXY.js → docUpdateCommands-OPG6ZY4H.js} +48 -43
  146. package/{fetchMessages-EIU7UFFK.js → fetchMessages-I5ICDDHM.js} +5 -5
  147. package/{getPricing-LUSEABA6.js → getPricing-NMMFT3YI.js} +4 -4
  148. package/{handleSendMessageAction-B75UOJKF.js → handleSendMessageAction-XFZH2TQS.js} +110 -86
  149. package/index.js +87 -884
  150. package/{lib-FRRS27KN.js → lib-PU2G2MSO.js} +523 -191
  151. package/{localDialogRead-BTFJ4V2I.js → localDialogRead-ZHZ3KXDM.js} +2 -2
  152. package/{localRuntimeAuthority-6IR6BBXE.js → localRuntimeAuthority-TU6OBC76.js} +9 -6
  153. package/{localRuntimeDb-SYQGUF4U.js → localRuntimeDb-VKWVOPPI.js} +1 -1
  154. package/{machineCommands-GFPTOY6L.js → machineCommands-KMU3D5I5.js} +91 -81
  155. package/machineWsRunDispatch-6GJ5YOSW.js +154 -0
  156. package/{memberThunks-QGFLFVCI.js → memberThunks-R75S3RWP.js} +20 -18
  157. package/{models-T3SG6MJ5.js → models-ZPU5EDF4.js} +2 -2
  158. package/oauthTokenStore-ITEB663N.js +23 -0
  159. package/package.json +1 -1
  160. package/pdf-U6KSUEZZ.js +26435 -0
  161. package/processSpawn-SOAV3FEV.js +11 -0
  162. package/profileConfig-ZGOFORWV.js +43 -0
  163. package/{providerPresetApply-FG6NZ57W.js → providerPresetApply-TEBH7FDX.js} +7 -7
  164. package/{providerRegistry-757OWH3O.js → providerRegistry-CBJLNCET.js} +11 -7
  165. package/{read-COE3ZYR6.js → read-SRQMNO26.js} +7 -6
  166. package/{readDocTool-5USN4A6V.js → readDocTool-RC3JUNJ2.js} +5 -3
  167. package/{readlineWorkspace-UFSWHFKD.js → readlineWorkspace-EXCG3IFX.js} +2704 -2060
  168. package/{removeDialogAgentAction-IX3MN2ZO.js → removeDialogAgentAction-46XQV5Q7.js} +21 -25
  169. package/{runAgentClientLoop-25LJ4XGV.js → runAgentClientLoop-URRDZ5WG.js} +75 -69
  170. package/{runtimeDoctorCommands-X6WDBEQX.js → runtimeDoctorCommands-PIVSBZRZ.js} +4 -4
  171. package/runtimeModeArgs-2Y7BALTO.js +31 -0
  172. package/{setDialogExtraReferencesAction-X4HCPNZL.js → setDialogExtraReferencesAction-J4V5ADQF.js} +15 -13
  173. package/{setPrimaryDialogAgentAction-4GMIQLOD.js → setPrimaryDialogAgentAction-UHHV2QZW.js} +22 -26
  174. package/{chunk-AFUORTY4.js → settingThunks-PPZZZOWN.js} +226 -940
  175. package/{skillDiscovery-CYUCJMAG.js → skillDiscovery-ZBU76COE.js} +3 -3
  176. package/{slateUtils-RIZES3PV.js → slateUtils-NGV2NMKM.js} +1 -1
  177. package/{spaceCommands-NKJVJCQQ.js → spaceCommands-7CLUNI2I.js} +51 -46
  178. package/{streamAgentChatTurn-A46QFV4O.js → streamAgentChatTurn-YPUYKXDX.js} +206 -105
  179. package/{switchDialogAgentAction-N52LRPA3.js → switchDialogAgentAction-A2TMVGAE.js} +18 -19
  180. package/{tableCommands-O6NWHFKV.js → tableCommands-6U4BMLRR.js} +10 -10
  181. package/{toolApiClient-QVJ6HDNN.js → toolApiClient-EJT6TMFG.js} +3 -3
  182. package/tools-M5ENXZRJ.js +116 -0
  183. package/{tuiSummaryLlmCaller-WFRWERGK.js → tuiSummaryLlmCaller-Q65IBDGO.js} +24 -21
  184. package/{updateCommands-2M74UL7P.js → updateCommands-4EHDLF5J.js} +3 -3
  185. package/{updateDialogTitleAction-QJPZGF52.js → updateDialogTitleAction-7PNUE23W.js} +82 -44
  186. package/action-YVYQEAAV.js +0 -31
  187. package/agentListCommands-KMS675GZ.js +0 -406
  188. package/agentRecordCommands-D7BRMFNI.js +0 -128
  189. package/agentRunCommand-VL6MMEUB.js +0 -155
  190. package/browser-image-compression-MFDTD7K6.js +0 -1763
  191. package/chatQueueReduxAdapter-PQMRR2PK.js +0 -186
  192. package/chunk-M76ECQRD.js +0 -13658
  193. package/chunk-MEYIRKDN.js +0 -8967
  194. package/chunk-Q5FJJ6XI.js +0 -103
  195. package/chunk-QVKRR2SS.js +0 -20782
  196. package/chunk-S7Z2HMCN.js +0 -25
  197. package/chunk-Y5GCAMGP.js +0 -9
  198. package/chunk-YPREESF4.js +0 -225
  199. package/createDialogAction-SX36BGSX.js +0 -65
  200. package/machineWsRunDispatch-46PSZ3DJ.js +0 -144
  201. package/settingSlice-ZQZVUPKK.js +0 -204
  202. package/syncMapping-N6RGXGBW.js +0 -437
  203. package/tools-TTDGRNY6.js +0 -110
  204. package/{chunk-VMFTFOWF.js → chunk-3AH7LNUB.js} +7 -7
  205. package/{chunk-X7HHHIOZ.js → chunk-Y6ROFCZO.js} +0 -0
  206. package/{db-WK5MDZVN.js → db-VQSAOWAO.js} +1 -1
@@ -0,0 +1,780 @@
1
+ // packages/cli/diagnostics/normalizeError.ts
2
+ var MAX_CAUSE_DEPTH = 4;
3
+ var MAX_AGGREGATE_ERRORS = 8;
4
+ var MAX_MESSAGE_LENGTH = 400;
5
+ var MAX_OUTPUT_LENGTH = 2e3;
6
+ var SECRET_PATTERNS = [
7
+ /\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/gi,
8
+ /\b(?:token|secret|password|passwd|apikey|api[_-]?key|authorization|auth)\s*[:=]\s*["']?[^\s"']{6,}/gi,
9
+ /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\b/g,
10
+ // JWT
11
+ /\b[A-Fa-f0-9]{32,}\b/g,
12
+ // 长 hex(session key / hash token)
13
+ /\b(?:sk|pk|ak|xox[baprs]|ghp|gho|ghu|ghs|ghr|glpat|nolo)[-_][A-Za-z0-9_-]{8,}\b/g
14
+ // 常见 key 前缀
15
+ ];
16
+ var PATH_PREFIXES = [];
17
+ function initPathPrefixes() {
18
+ try {
19
+ const home = process.env.HOME ?? process.env.USERPROFILE;
20
+ const noloHome = process.env.NOLO_HOME;
21
+ if (noloHome && noloHome.length > 4) {
22
+ PATH_PREFIXES.push(new RegExp(escapeRe(noloHome), "g"));
23
+ }
24
+ if (home && home.length > 4) {
25
+ PATH_PREFIXES.push(new RegExp(escapeRe(home), "g"));
26
+ }
27
+ } catch {
28
+ }
29
+ }
30
+ function escapeRe(s) {
31
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
32
+ }
33
+ initPathPrefixes();
34
+ function sanitizeText(input) {
35
+ let s;
36
+ try {
37
+ s = typeof input === "string" ? input : String(input);
38
+ } catch {
39
+ return "[unstringifiable]";
40
+ }
41
+ for (const re of SECRET_PATTERNS) {
42
+ re.lastIndex = 0;
43
+ s = s.replace(re, (m) => {
44
+ const sepIdx = m.search(/[:=\s]/);
45
+ const head = sepIdx >= 0 && sepIdx < 12 ? m.slice(0, sepIdx + 1) : "";
46
+ return `${head}[redacted]`;
47
+ });
48
+ }
49
+ for (const re of PATH_PREFIXES) {
50
+ re.lastIndex = 0;
51
+ s = s.replace(re, "~");
52
+ }
53
+ s = s.replace(/[\r\n]+/g, "\u23CE").replace(/[\u0000-\u001f\u007f-\u009f]/g, "");
54
+ if (s.length > MAX_MESSAGE_LENGTH) {
55
+ s = `${s.slice(0, MAX_MESSAGE_LENGTH)}\u2026(+${s.length - MAX_MESSAGE_LENGTH}ch)`;
56
+ }
57
+ return s;
58
+ }
59
+ function safeGet(obj, key) {
60
+ try {
61
+ if (obj === null || obj === void 0) return void 0;
62
+ return obj[key];
63
+ } catch {
64
+ return `[throwing-getter:${key}]`;
65
+ }
66
+ }
67
+ function safeString(v, maxLen = MAX_MESSAGE_LENGTH) {
68
+ if (v === void 0 || v === null) return void 0;
69
+ try {
70
+ const s = typeof v === "string" ? v : String(v);
71
+ return s.length > maxLen ? `${s.slice(0, maxLen)}\u2026` : s;
72
+ } catch {
73
+ return "[unstringifiable]";
74
+ }
75
+ }
76
+ function normalizeError(err) {
77
+ try {
78
+ if (err === null) return "null";
79
+ if (err === void 0) return "undefined";
80
+ const seen = /* @__PURE__ */ new Set();
81
+ const parts = [];
82
+ let current2 = err;
83
+ let depth = 0;
84
+ while (current2 !== void 0 && current2 !== null && depth < MAX_CAUSE_DEPTH) {
85
+ if (typeof current2 === "object") {
86
+ if (seen.has(current2)) {
87
+ parts.push("[circular-cause]");
88
+ break;
89
+ }
90
+ seen.add(current2);
91
+ }
92
+ const { text, cause } = describeOne(current2, seen);
93
+ parts.push(text);
94
+ if (cause === void 0) break;
95
+ current2 = cause;
96
+ depth += 1;
97
+ }
98
+ if (depth >= MAX_CAUSE_DEPTH && current2 !== void 0 && current2 !== null) {
99
+ parts.push(`[cause-chain-truncated@depth=${MAX_CAUSE_DEPTH}]`);
100
+ }
101
+ let out = parts.join(" <-caused by<- ");
102
+ if (out.length > MAX_OUTPUT_LENGTH) {
103
+ out = `${out.slice(0, MAX_OUTPUT_LENGTH)}\u2026[truncated]`;
104
+ }
105
+ return out || "[empty-error]";
106
+ } catch (inner) {
107
+ try {
108
+ return `[normalizeError-failed: ${String(inner)}]`;
109
+ } catch {
110
+ return "[normalizeError-failed]";
111
+ }
112
+ }
113
+ }
114
+ function describeOne(v, seen) {
115
+ if (v === null) return { text: "null", cause: void 0 };
116
+ if (v === void 0) return { text: "undefined", cause: void 0 };
117
+ const t = typeof v;
118
+ if (t === "string") return { text: sanitizeText(v), cause: void 0 };
119
+ if (t === "number" || t === "boolean" || t === "bigint" || t === "symbol") {
120
+ return { text: safeString(v) ?? String(t), cause: void 0 };
121
+ }
122
+ if (t === "function") {
123
+ return { text: `[function ${safeString(safeGet(v, "name"), 60) ?? "anonymous"}]`, cause: void 0 };
124
+ }
125
+ const name = safeString(safeGet(v, "name"), 80) ?? safeString(safeGet(v, "constructor") && safeGet(safeGet(v, "constructor"), "name"), 80);
126
+ const message = safeString(safeGet(v, "message"));
127
+ const code = safeString(safeGet(v, "code"), 60);
128
+ const status = safeGet(v, "status") ?? safeGet(v, "statusCode");
129
+ const cause = safeGet(v, "cause");
130
+ let head;
131
+ if (name && message) head = `${name}: ${message}`;
132
+ else if (message) head = message;
133
+ else if (name) head = name;
134
+ else head = safeString(v, 160) ?? "[object-error]";
135
+ head = sanitizeText(head);
136
+ const extras = [];
137
+ if (code) extras.push(`code=${sanitizeText(code)}`);
138
+ if (typeof status === "number") extras.push(`status=${status}`);
139
+ if (isAggregateErrorLike(v)) {
140
+ const agg = describeAggregate(v, seen);
141
+ if (agg) extras.push(agg);
142
+ }
143
+ const suffix = extras.length > 0 ? ` (${extras.join(", ")})` : "";
144
+ return { text: `${head}${suffix}`, cause };
145
+ }
146
+ function isAggregateErrorLike(v) {
147
+ try {
148
+ if (v instanceof AggregateError) return true;
149
+ } catch {
150
+ }
151
+ const name = safeGet(v, "name");
152
+ const errors = safeGet(v, "errors");
153
+ return name === "AggregateError" && Array.isArray(errors);
154
+ }
155
+ function describeAggregate(v, seen) {
156
+ const errors = safeGet(v, "errors");
157
+ if (!Array.isArray(errors)) return void 0;
158
+ const total = errors.length;
159
+ const first = [];
160
+ for (let i = 0; i < Math.min(total, MAX_AGGREGATE_ERRORS); i += 1) {
161
+ const e = errors[i];
162
+ if (e !== null && typeof e === "object" && seen.has(e)) {
163
+ first.push("[circular]");
164
+ continue;
165
+ }
166
+ first.push(describeOne(e, seen).text);
167
+ }
168
+ const more = total > MAX_AGGREGATE_ERRORS ? `, +${total - MAX_AGGREGATE_ERRORS} more` : "";
169
+ return `${total} aggregated [${first.join(" | ")}${more}]`;
170
+ }
171
+
172
+ // packages/cli/diagnostics/consoleBridge.ts
173
+ var PATCHED_METHODS = [
174
+ "log",
175
+ "info",
176
+ "debug",
177
+ "trace",
178
+ "warn",
179
+ "error",
180
+ "dir",
181
+ "table",
182
+ "group",
183
+ "groupEnd",
184
+ "groupCollapsed",
185
+ "assert",
186
+ "count",
187
+ "countReset",
188
+ "time",
189
+ "timeEnd",
190
+ "timeLog",
191
+ "timeStamp"
192
+ ];
193
+ var LEVEL_BY_METHOD = {
194
+ log: "info",
195
+ info: "info",
196
+ debug: "debug",
197
+ trace: "trace",
198
+ warn: "warn",
199
+ error: "error",
200
+ dir: "info",
201
+ table: "info",
202
+ group: "info",
203
+ groupEnd: "info",
204
+ groupCollapsed: "info",
205
+ assert: "warn",
206
+ count: "debug",
207
+ countReset: "debug",
208
+ time: "debug",
209
+ timeEnd: "debug",
210
+ timeLog: "debug",
211
+ timeStamp: "debug"
212
+ };
213
+ var DIAG_MAX_ARG_CHARS = 400;
214
+ function formatArg(a) {
215
+ if (typeof a === "string") return a;
216
+ if (a instanceof Error) {
217
+ try {
218
+ return `${a.name}: ${a.message}`;
219
+ } catch {
220
+ return "[error]";
221
+ }
222
+ }
223
+ try {
224
+ const j = JSON.stringify(a);
225
+ if (j === void 0) return String(a);
226
+ return j.length > DIAG_MAX_ARG_CHARS ? `${j.slice(0, DIAG_MAX_ARG_CHARS)}\u2026` : j;
227
+ } catch {
228
+ try {
229
+ return String(a);
230
+ } catch {
231
+ return "[unprintable]";
232
+ }
233
+ }
234
+ }
235
+ function installConsoleBridge(opts) {
236
+ const originals = /* @__PURE__ */ new Map();
237
+ const originalFns = /* @__PURE__ */ new Map();
238
+ let installed = true;
239
+ let inBridge = false;
240
+ let reentrantDropped = 0;
241
+ const emit = (level, args) => {
242
+ if (inBridge) {
243
+ reentrantDropped += 1;
244
+ return;
245
+ }
246
+ inBridge = true;
247
+ try {
248
+ const raw = args.map(formatArg).join(" ");
249
+ const event = {
250
+ ts: opts.now?.() ?? Date.now(),
251
+ level,
252
+ component: opts.component ?? "console",
253
+ message: raw
254
+ };
255
+ opts.sink.write(event, `[${event.level}] [${event.component}] ${sanitizeText(raw)}`);
256
+ } catch {
257
+ } finally {
258
+ inBridge = false;
259
+ }
260
+ };
261
+ for (const name of PATCHED_METHODS) {
262
+ try {
263
+ const desc = Object.getOwnPropertyDescriptor(console, name) ?? {
264
+ value: console[name],
265
+ writable: true,
266
+ configurable: true,
267
+ enumerable: true
268
+ };
269
+ originals.set(name, desc);
270
+ const origFn = desc.value;
271
+ if (typeof origFn === "function") {
272
+ originalFns.set(name, origFn.bind(console));
273
+ }
274
+ const level = LEVEL_BY_METHOD[name] ?? "info";
275
+ const patched = function patchedConsole(...args) {
276
+ if (name === "assert") {
277
+ const [assertion, ...rest] = args;
278
+ if (assertion) return void 0;
279
+ emit("warn", ["Assertion failed:", ...rest]);
280
+ return void 0;
281
+ }
282
+ if (opts.passthrough && LOG_LEVEL_ORDER_VALUE[level] < LOG_LEVEL_ORDER_VALUE.warn) {
283
+ const orig = originalFns.get(name);
284
+ if (orig) {
285
+ try {
286
+ orig(...args);
287
+ } catch {
288
+ }
289
+ }
290
+ }
291
+ emit(level, args);
292
+ return void 0;
293
+ };
294
+ Object.defineProperty(console, name, {
295
+ value: patched,
296
+ writable: true,
297
+ configurable: true,
298
+ enumerable: desc.enumerable ?? true
299
+ });
300
+ } catch {
301
+ }
302
+ }
303
+ return {
304
+ get installed() {
305
+ return installed;
306
+ },
307
+ /** 测试/诊断自观测:被重入守卫丢弃的调用数 */
308
+ get reentrantDropped() {
309
+ return reentrantDropped;
310
+ },
311
+ uninstall() {
312
+ if (!installed) return;
313
+ installed = false;
314
+ for (const name of PATCHED_METHODS) {
315
+ const orig = originals.get(name);
316
+ if (!orig) continue;
317
+ try {
318
+ Object.defineProperty(console, name, orig);
319
+ } catch {
320
+ try {
321
+ console[name] = orig.value;
322
+ } catch {
323
+ }
324
+ }
325
+ }
326
+ }
327
+ };
328
+ }
329
+ var LOG_LEVEL_ORDER_VALUE = {
330
+ trace: 10,
331
+ debug: 20,
332
+ info: 30,
333
+ warn: 40,
334
+ error: 50,
335
+ fatal: 60
336
+ };
337
+
338
+ // packages/cli/diagnostics/sinks/ringBuffer.ts
339
+ var RING_BUFFER_CAPACITY = 2e3;
340
+ var RingBufferSink = class {
341
+ capacity;
342
+ buf;
343
+ head = 0;
344
+ // 下一次写入位置
345
+ count = 0;
346
+ constructor(capacity = RING_BUFFER_CAPACITY) {
347
+ this.capacity = Math.max(1, capacity);
348
+ this.buf = new Array(this.capacity);
349
+ }
350
+ write(event, _line) {
351
+ try {
352
+ this.buf[this.head] = event;
353
+ this.head = (this.head + 1) % this.capacity;
354
+ if (this.count < this.capacity) this.count += 1;
355
+ } catch {
356
+ }
357
+ }
358
+ /** 按时间序 dump(最旧 → 最新) */
359
+ drain() {
360
+ if (this.count === 0) return [];
361
+ const out = new Array(this.count);
362
+ const start = this.count < this.capacity ? 0 : this.head;
363
+ for (let i = 0; i < this.count; i += 1) {
364
+ out[i] = this.buf[(start + i) % this.capacity];
365
+ }
366
+ return out;
367
+ }
368
+ get size() {
369
+ return this.count;
370
+ }
371
+ };
372
+ var GLOBAL_KEY = "__nolo_diag_ring__";
373
+ function getProcessRingBuffer() {
374
+ try {
375
+ return globalThis[GLOBAL_KEY];
376
+ } catch {
377
+ return void 0;
378
+ }
379
+ }
380
+ function installProcessRingBuffer(sink) {
381
+ try {
382
+ globalThis[GLOBAL_KEY] = sink;
383
+ } catch {
384
+ }
385
+ return sink;
386
+ }
387
+
388
+ // packages/cli/diagnostics/sinks/rotatingFile.ts
389
+ import { openSync, mkdirSync, statSync, renameSync, writeSync, closeSync, constants } from "node:fs";
390
+ import { dirname, join } from "node:path";
391
+ var MAX_FILE_BYTES = 10 * 1024 * 1024;
392
+ var MAX_BACKUPS = 5;
393
+ var RotatingFileSink = class {
394
+ filePath;
395
+ maxBytes;
396
+ maxBackups;
397
+ fd = null;
398
+ written = 0;
399
+ disabled = false;
400
+ constructor(opts) {
401
+ this.filePath = opts?.filePath ?? resolveDefaultLogPath(opts?.env ?? process.env);
402
+ this.maxBytes = opts?.maxBytes ?? MAX_FILE_BYTES;
403
+ this.maxBackups = opts?.maxBackups ?? MAX_BACKUPS;
404
+ }
405
+ write(_event, line) {
406
+ if (this.disabled) return;
407
+ try {
408
+ this.ensureOpen();
409
+ if (this.fd === null) return;
410
+ const payload = `${line}
411
+ `;
412
+ writeSync(this.fd, payload);
413
+ this.written += Buffer.byteLength(payload);
414
+ if (this.written >= this.maxBytes) this.rotate();
415
+ } catch {
416
+ this.disabled = true;
417
+ try {
418
+ if (this.fd !== null) closeSync(this.fd);
419
+ } catch {
420
+ }
421
+ this.fd = null;
422
+ }
423
+ }
424
+ flush() {
425
+ try {
426
+ if (this.fd !== null) {
427
+ }
428
+ } catch {
429
+ }
430
+ }
431
+ close() {
432
+ try {
433
+ if (this.fd !== null) closeSync(this.fd);
434
+ } catch {
435
+ }
436
+ this.fd = null;
437
+ }
438
+ ensureOpen() {
439
+ if (this.fd !== null) return;
440
+ mkdirSync(dirname(this.filePath), { recursive: true, mode: 448 });
441
+ this.fd = openSync(this.filePath, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND, 384);
442
+ try {
443
+ const st = statSync(this.filePath);
444
+ this.written = st.size;
445
+ } catch {
446
+ this.written = 0;
447
+ }
448
+ }
449
+ rotate() {
450
+ try {
451
+ if (this.fd !== null) {
452
+ closeSync(this.fd);
453
+ this.fd = null;
454
+ }
455
+ for (let i = this.maxBackups - 1; i >= 1; i -= 1) {
456
+ try {
457
+ renameSync(`${this.filePath}.${i}`, `${this.filePath}.${i + 1}`);
458
+ } catch {
459
+ }
460
+ }
461
+ try {
462
+ renameSync(this.filePath, `${this.filePath}.1`);
463
+ } catch {
464
+ }
465
+ this.written = 0;
466
+ this.ensureOpen();
467
+ } catch {
468
+ this.disabled = true;
469
+ }
470
+ }
471
+ };
472
+ function resolveDefaultLogPath(env) {
473
+ const noloHome = env.NOLO_HOME;
474
+ if (noloHome) return join(noloHome, "logs", "tui-diag.log");
475
+ const home = env.HOME ?? env.USERPROFILE ?? ".";
476
+ return join(home, ".nolo", "logs", "tui-diag.log");
477
+ }
478
+
479
+ // packages/cli/diagnostics/sinks/stderr.ts
480
+ var StderrSink = class {
481
+ writer;
482
+ constructor(writer) {
483
+ if (writer) {
484
+ this.writer = writer;
485
+ } else {
486
+ const bound = process.stderr.write.bind(process.stderr);
487
+ this.writer = (t) => {
488
+ try {
489
+ bound(t);
490
+ } catch {
491
+ }
492
+ };
493
+ }
494
+ }
495
+ write(_event, line) {
496
+ try {
497
+ this.writer(`${line}
498
+ `);
499
+ } catch {
500
+ }
501
+ }
502
+ };
503
+
504
+ // packages/cli/diagnostics/types.ts
505
+ var LOG_LEVEL_ORDER = {
506
+ trace: 10,
507
+ debug: 20,
508
+ info: 30,
509
+ warn: 40,
510
+ error: 50,
511
+ fatal: 60
512
+ };
513
+
514
+ // packages/cli/diagnostics/index.ts
515
+ function detectMode(args, env) {
516
+ const cmd = args[0];
517
+ const isTuiCommand = cmd === "chat" || cmd === "tui";
518
+ const tuiModeFlag = args[1] === "--local" || args[1] === "--server" || args[1] === "--auto";
519
+ const wantsTui = args.length === 0 && !!process.stdin.isTTY || isTuiCommand && args.length === 1 || isTuiCommand && args.length === 2 && tuiModeFlag;
520
+ if (wantsTui) return "tui";
521
+ if (env.CI === "true" || env.CI === "1" || env.NOLO_CI === "1" || env.NOLO_CI === "true") {
522
+ return "ci";
523
+ }
524
+ return "agent";
525
+ }
526
+ var noopSink = { write() {
527
+ } };
528
+ var FanoutSink = class {
529
+ constructor(sinks) {
530
+ this.sinks = sinks;
531
+ }
532
+ write(event, line) {
533
+ for (const s of this.sinks) {
534
+ try {
535
+ s.write(event, line);
536
+ } catch {
537
+ }
538
+ }
539
+ }
540
+ flush() {
541
+ for (const s of this.sinks) {
542
+ try {
543
+ s.flush?.();
544
+ } catch {
545
+ }
546
+ }
547
+ }
548
+ close() {
549
+ for (const s of this.sinks) {
550
+ try {
551
+ s.close?.();
552
+ } catch {
553
+ }
554
+ }
555
+ }
556
+ };
557
+ var LevelGatedSink = class {
558
+ constructor(inner, min, maxExclusive) {
559
+ this.inner = inner;
560
+ this.min = min;
561
+ this.maxExclusive = maxExclusive;
562
+ }
563
+ write(event, line) {
564
+ const v = LOG_LEVEL_ORDER[event.level] ?? 0;
565
+ if (v < LOG_LEVEL_ORDER[this.min]) return;
566
+ if (this.maxExclusive && v >= LOG_LEVEL_ORDER[this.maxExclusive]) return;
567
+ this.inner.write(event, line);
568
+ }
569
+ flush() {
570
+ this.inner.flush?.();
571
+ }
572
+ close() {
573
+ this.inner.close?.();
574
+ }
575
+ };
576
+ function formatHumanLine(e) {
577
+ const ts = new Date(e.ts).toISOString();
578
+ const errPart = e.error ? ` err=${e.error}` : "";
579
+ const fp = e.fingerprint ? ` fp=${e.fingerprint}` : "";
580
+ const fieldsPart = e.fields && Object.keys(e.fields).length > 0 ? ` ${sanitizeText(JSON.stringify(e.fields))}` : "";
581
+ return `${ts} [${e.level}] [${e.component}] ${sanitizeText(e.message)}${errPart}${fp}${fieldsPart}`;
582
+ }
583
+ function formatJsonLine(e) {
584
+ try {
585
+ return sanitizeText(JSON.stringify({ ...e, message: sanitizeText(e.message) }));
586
+ } catch {
587
+ return `{"level":"${e.level}","component":"${e.component}","message":"${sanitizeText(e.message)}"}`;
588
+ }
589
+ }
590
+ var FormattingSink = class {
591
+ constructor(inner, format) {
592
+ this.inner = inner;
593
+ this.format = format;
594
+ }
595
+ write(event) {
596
+ let line;
597
+ try {
598
+ line = this.format(event);
599
+ } catch {
600
+ line = `[${event.level}] [${event.component}] ${sanitizeText(event.message)}`;
601
+ }
602
+ this.inner.write(event, line);
603
+ }
604
+ flush() {
605
+ this.inner.flush?.();
606
+ }
607
+ close() {
608
+ this.inner.close?.();
609
+ }
610
+ };
611
+ function extractError(args) {
612
+ const last = args[args.length - 1];
613
+ if (last instanceof Error) {
614
+ return { error: normalizeError(last), rest: args.slice(0, -1) };
615
+ }
616
+ if (args.some((a) => a instanceof Error)) {
617
+ const rest = args.map((a) => a instanceof Error ? normalizeError(a) : a);
618
+ return { rest };
619
+ }
620
+ return { rest: args };
621
+ }
622
+ function formatMsgArg(a) {
623
+ if (typeof a === "string") return a;
624
+ if (a instanceof Error) return normalizeError(a);
625
+ try {
626
+ const j = JSON.stringify(a);
627
+ if (j === void 0) return String(a);
628
+ return j;
629
+ } catch {
630
+ try {
631
+ return String(a);
632
+ } catch {
633
+ return "[unprintable]";
634
+ }
635
+ }
636
+ }
637
+ var DiagLogger = class _DiagLogger {
638
+ constructor(sink, component, fields = {}) {
639
+ this.sink = sink;
640
+ this.component = component;
641
+ this.fields = fields;
642
+ }
643
+ emit(level, msg, args) {
644
+ try {
645
+ const { error, rest } = extractError(args);
646
+ const extra = rest.map(formatMsgArg).join(" ");
647
+ const message = extra ? `${msg} ${extra}` : msg;
648
+ const fields = Object.keys(this.fields).length > 0 ? { ...this.fields } : void 0;
649
+ const event = {
650
+ ts: Date.now(),
651
+ level,
652
+ component: this.component,
653
+ message,
654
+ ...error ? { error } : {},
655
+ ...fields ? { fields } : {}
656
+ };
657
+ this.sink.write(event, "");
658
+ } catch {
659
+ }
660
+ }
661
+ trace(m, ...a) {
662
+ this.emit("trace", m, a);
663
+ }
664
+ debug(m, ...a) {
665
+ this.emit("debug", m, a);
666
+ }
667
+ info(m, ...a) {
668
+ this.emit("info", m, a);
669
+ }
670
+ warn(m, ...a) {
671
+ this.emit("warn", m, a);
672
+ }
673
+ error(m, ...a) {
674
+ this.emit("error", m, a);
675
+ }
676
+ fatal(m, ...a) {
677
+ this.emit("fatal", m, a);
678
+ }
679
+ child(bindings) {
680
+ return new _DiagLogger(
681
+ this.sink,
682
+ bindings.component ?? this.component,
683
+ { ...this.fields, ...bindings.fields ?? {} }
684
+ );
685
+ }
686
+ };
687
+ var current = null;
688
+ function initializeDiagnostics(mode, env = process.env) {
689
+ if (current) return current;
690
+ let ring = null;
691
+ const sharedSinks = [];
692
+ try {
693
+ ring = installProcessRingBuffer(new RingBufferSink());
694
+ sharedSinks.push(new FormattingSink(ring, formatHumanLine));
695
+ } catch {
696
+ }
697
+ try {
698
+ sharedSinks.push(new FormattingSink(new RotatingFileSink({ env }), formatHumanLine));
699
+ } catch {
700
+ }
701
+ const diagSinks = [...sharedSinks];
702
+ const consoleSinks = [...sharedSinks];
703
+ if (mode !== "tui") {
704
+ try {
705
+ const stderrWriter = process.stderr.write.bind(process.stderr);
706
+ const useJson = env.NOLO_LOG_FORMAT === "json";
707
+ const fmt = useJson ? formatJsonLine : formatHumanLine;
708
+ const stderrRaw = new StderrSink((t) => {
709
+ try {
710
+ stderrWriter(t);
711
+ } catch {
712
+ }
713
+ });
714
+ diagSinks.push(new FormattingSink(stderrRaw, fmt));
715
+ consoleSinks.push(new LevelGatedSink(new FormattingSink(stderrRaw, fmt), "warn"));
716
+ } catch {
717
+ }
718
+ }
719
+ const diagSink = new FanoutSink(diagSinks.length > 0 ? diagSinks : [noopSink]);
720
+ const consoleSink = new FanoutSink(consoleSinks.length > 0 ? consoleSinks : [noopSink]);
721
+ let bridge;
722
+ try {
723
+ bridge = installConsoleBridge({
724
+ sink: consoleSink,
725
+ component: "console",
726
+ // 非 TUI:< warn 调原始 console 方法直通 stdout,保 CLI 输出契约
727
+ // (大 JSON 不截断、%s 占位符生效);诊断侧仍记 ring/file。
728
+ passthrough: mode !== "tui"
729
+ });
730
+ } catch {
731
+ bridge = { uninstall() {
732
+ }, installed: false, reentrantDropped: 0 };
733
+ }
734
+ const logger = new DiagLogger(diagSink, "cli");
735
+ current = {
736
+ logger,
737
+ ringBuffer: ring ?? new RingBufferSink(),
738
+ bridge,
739
+ mode,
740
+ shutdown() {
741
+ try {
742
+ bridge.uninstall();
743
+ } catch {
744
+ }
745
+ try {
746
+ diagSink.close();
747
+ } catch {
748
+ }
749
+ try {
750
+ consoleSink.close();
751
+ } catch {
752
+ }
753
+ current = null;
754
+ }
755
+ };
756
+ return current;
757
+ }
758
+ function getLogger(component) {
759
+ if (current) return current.logger.child({ component });
760
+ const bound = process.stderr.write.bind(process.stderr);
761
+ const fallbackSink = {
762
+ write(e, line) {
763
+ try {
764
+ bound(line || `[${e.level}] [${e.component}] ${sanitizeText(e.message)}`);
765
+ bound("\n");
766
+ } catch {
767
+ }
768
+ }
769
+ };
770
+ return new DiagLogger(fallbackSink, component);
771
+ }
772
+
773
+ export {
774
+ normalizeError,
775
+ getProcessRingBuffer,
776
+ resolveDefaultLogPath,
777
+ detectMode,
778
+ initializeDiagnostics,
779
+ getLogger
780
+ };