nolo-cli 0.104.0-alpha.1 → 0.104.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/{_executeModel-4W7C3ACS.js → _executeModel-JXG5TLPE.js} +75 -68
- package/action-GVA5ARSJ.js +20 -0
- package/{addContentAction-O7R66HEX.js → addContentAction-J3DLDV64.js} +12 -11
- package/{addDialogAgentAction-74OA7KYP.js → addDialogAgentAction-PHIXJCF2.js} +18 -19
- package/{agentDeleteCommand-2YAHAZFJ.js → agentDeleteCommand-2AWJGHXG.js} +117 -42
- package/{agentEmailCommands-O2KH4G7U.js → agentEmailCommands-VV5OSILE.js} +98 -88
- package/agentListCommands-OQMRBDWP.js +742 -0
- package/{agentMachineCommands-5I5CCUBM.js → agentMachineCommands-3VLLR6RL.js} +48 -43
- package/{agentProviderCommands-GNPTL5XR.js → agentProviderCommands-XPJYZSCE.js} +97 -2
- package/{agentPullCommand-O5MPVJ5E.js → agentPullCommand-B4T2DJ5H.js} +1 -1
- package/agentRecordCommands-GPIARVOW.js +138 -0
- package/agentRunCommand-LRJTZ7IM.js +167 -0
- package/{agentRunControl-AVJR4JW4.js → agentRunControl-3HWA2LLQ.js} +2 -2
- package/{agentRuntimeLocal-VXZSDIGT.js → agentRuntimeLocal-PV6AZOEU.js} +48 -39
- package/{agentSlice-6LBOYNKN.js → agentSlice-6R3JKS6I.js} +14 -13
- package/{appDeleteCommands-32MHLR4L.js → appDeleteCommands-WEX73P5R.js} +46 -41
- package/{appDeployCommands-WCQOUSOB.js → appDeployCommands-7BAXWA4M.js} +46 -41
- package/{appDeployStatusCommands-6QKB7DYN.js → appDeployStatusCommands-EJ6A2U4X.js} +46 -41
- package/{appGetCommands-SFAPP5PB.js → appGetCommands-SB355OEX.js} +46 -41
- package/{appListCommands-EKUBDRUO.js → appListCommands-TSZDPIKJ.js} +46 -41
- package/{authCommand-F4EFRRX6.js → authCommand-5PB3YRVV.js} +118 -24
- package/{authCommands-RGOGCPP6.js → authCommands-5RTUDYZW.js} +7 -5
- package/{builtinSkillRegistry-FUAVTRVZ.js → builtinSkillRegistry-SBBWTANC.js} +10 -8
- package/{chromeCommands-FZYAU75D.js → chromeCommands-AU5ZJXBG.js} +289 -37
- package/{chromeOpsCommands-62P2Q2YB.js → chromeOpsCommands-ZYTCMNHG.js} +156 -22
- package/{chunk-6OZ36FXI.js → chunk-27ONFIEY.js} +22 -4
- package/{chunk-JEDZAO7L.js → chunk-2SYTUTLI.js} +257 -37
- package/{chunk-HVURBGF3.js → chunk-2U3NHADM.js} +6 -6
- package/{chunk-53HEEOTT.js → chunk-2WJ57RJA.js} +83 -16
- package/{chunk-OIVSQH2O.js → chunk-3BXNTXYI.js} +299 -5
- package/{chunk-V4MJDUSR.js → chunk-3F424ASC.js} +2 -2
- package/{chunk-HJUYAD4A.js → chunk-3Q7NEHAR.js} +5 -5
- package/chunk-44CU7CKA.js +13545 -0
- package/{chunk-EYAQT56M.js → chunk-4DPP773Q.js} +2 -2
- package/chunk-4LCOCOR5.js +50 -0
- package/{chunk-JPGCXHNM.js → chunk-4LKMZ3RR.js} +1 -1
- package/{chunk-2GRGFCF6.js → chunk-4VJAC32I.js} +2 -1
- package/{chunk-6D6VBVEW.js → chunk-4W24JM32.js} +80 -14
- package/{chunk-H62HCIUP.js → chunk-4WMMIL66.js} +35 -22
- package/{chunk-MC4XLIJ7.js → chunk-523DITKR.js} +1 -1
- package/{chunk-ZCYXJSTU.js → chunk-54VPQTOA.js} +66 -94
- package/{chunk-E4MARS3Q.js → chunk-5GVBDNTO.js} +1 -1
- package/chunk-5MMAK75Q.js +15 -0
- package/{chunk-7S4YWN7P.js → chunk-5UUIGN6I.js} +4 -4
- package/{chunk-42V6BK2E.js → chunk-62IL3KQV.js} +4 -34
- package/{chunk-GQBOR3G6.js → chunk-7KVZ5LDQ.js} +2 -2
- package/chunk-A4SQRTZ6.js +15 -0
- package/{chunk-L5UXH3B2.js → chunk-AFH5QC6R.js} +58 -9
- package/{chunk-AEOE4Z6Q.js → chunk-AFSY3ZMB.js} +39 -15
- package/chunk-AGIM7IMJ.js +147 -0
- package/{chunk-5UTFL4QJ.js → chunk-AOTBKDRK.js} +7 -0
- package/{chunk-NA35QHCF.js → chunk-AWVP7PPG.js} +1 -1
- package/{chunk-EEGDMATE.js → chunk-B7APRSPS.js} +86 -81
- package/{chunk-W324THOB.js → chunk-BB7LVBTS.js} +20 -11
- package/{chunk-6YTOJY35.js → chunk-BZ7NPA6G.js} +35 -2
- package/{chunk-5H7KJX7J.js → chunk-CFHWVEUJ.js} +5 -5
- package/chunk-CHOZJMJS.js +78 -0
- package/{chunk-ETI2NYVF.js → chunk-CNA27EMD.js} +4 -4
- package/{chunk-ACTMNVHM.js → chunk-CYSYR67N.js} +1 -1
- package/{chunk-WV42OMV7.js → chunk-D2GQE6AF.js} +8 -8
- package/{chunk-GBRG75BQ.js → chunk-D2MDMY2M.js} +1 -0
- package/{chunk-Q554LLSI.js → chunk-DMXLXZKL.js} +1 -1
- package/chunk-DZ7R5V3Y.js +164 -0
- package/{chunk-3VNWWVKB.js → chunk-E3YWHWCR.js} +50 -18
- package/{chunk-KQ4ONNQD.js → chunk-EKPKW6RM.js} +155 -8
- package/{chunk-2J5Y72GY.js → chunk-EP7BWZ4B.js} +1 -1
- package/{chunk-ABQYVJBJ.js → chunk-EV235ILT.js} +5 -5
- package/{chunk-TRV2MIDW.js → chunk-EXAJ6DCR.js} +1 -0
- package/{chunk-3ZW5ZJMM.js → chunk-FGSJ3YMD.js} +23 -28
- package/{chunk-2F7RJC6L.js → chunk-FOXQ7BAB.js} +1 -1
- package/{chunk-SH43IESU.js → chunk-GGC55Q32.js} +199 -29
- package/chunk-GMZLP5DV.js +82 -0
- package/{chunk-DHDMC6FO.js → chunk-GSKPJIHY.js} +14 -9
- package/{chunk-FDTR4QJ6.js → chunk-H6A6X4EK.js} +32 -1
- package/{chunk-DVINR3PL.js → chunk-HDLLCBRF.js} +1 -1
- package/{chunk-QOKAKDPE.js → chunk-HIM3FCLF.js} +0 -1
- package/{chunk-ONXOABJR.js → chunk-HNGRBWYF.js} +3 -0
- package/{chunk-VLTIYV3X.js → chunk-HP57OUJO.js} +4 -4
- package/{chunk-NXUYQBDZ.js → chunk-HYXABXCZ.js} +29 -78
- package/{chunk-DNCEALKX.js → chunk-IEJ5YDA4.js} +22 -29
- package/{chunk-O6OSWFZQ.js → chunk-IHPDK6UD.js} +6 -0
- package/{chunk-BP4XNZRM.js → chunk-JIXGJTBU.js} +4 -4
- package/{chunk-GPCZ7UXG.js → chunk-K6U4NKFJ.js} +1 -1
- package/{chunk-Z77CRGTW.js → chunk-KA5O5KQL.js} +1 -1
- package/{chunk-4OEFYTWL.js → chunk-L5WOICCV.js} +67 -48
- package/{chunk-LS2ZANRJ.js → chunk-LOCNXNOU.js} +1 -1
- package/chunk-LWLNLZC5.js +265 -0
- package/{chunk-H66KLASO.js → chunk-LWXE6IFU.js} +567 -519
- package/{chunk-PUOC4YRO.js → chunk-M7VLQGQP.js} +11 -0
- package/chunk-NKWIS6G2.js +442 -0
- package/{chunk-BFU6C242.js → chunk-NMFV26UG.js} +1 -1
- package/{chunk-DJWMIXDZ.js → chunk-NSAFG343.js} +10 -10
- package/{chunk-UKZDAFYT.js → chunk-NSBID7PR.js} +6 -10
- package/{chunk-4J4QNKTW.js → chunk-NTR4SD3P.js} +845 -240
- package/{chunk-FZGV4FGK.js → chunk-NUHHBEJC.js} +378 -187
- package/chunk-NWENLDMM.js +42 -0
- package/chunk-O7SVKKLY.js +875 -0
- package/chunk-OCZKATRC.js +129 -0
- package/{chunk-VMFTFOWF.js → chunk-OKGVNZTL.js} +35 -8
- package/{chunk-KQHGZWSV.js → chunk-OXME3PEE.js} +1 -1
- package/{chunk-JRQFUXY7.js → chunk-P5GCTVGV.js} +99 -22
- package/{chunk-PQFHGD77.js → chunk-QKTESDWK.js} +161 -14
- package/{chunk-U3JZVWIB.js → chunk-QMXJ5KDJ.js} +68 -46
- package/{chunk-GEPUP7OO.js → chunk-QYUBY3OZ.js} +3 -3
- package/{chunk-3BMYXEUW.js → chunk-R5AJODNI.js} +1 -1
- package/{chunk-J4MOO56S.js → chunk-RILRSUGC.js} +10 -2
- package/{chunk-OEVAY4J6.js → chunk-RWX7AY7J.js} +18 -20
- package/{chunk-YY7I6GQ3.js → chunk-S2NSK7AZ.js} +11 -9
- package/{chunk-IIVGDG4I.js → chunk-SJKULPGX.js} +13 -7
- package/{chunk-BYMV6QZG.js → chunk-TNIX77YM.js} +4 -0
- package/chunk-TY3TIUJK.js +89 -0
- package/{chunk-I3TQJXQ7.js → chunk-U3C3IA32.js} +9 -2
- package/{chunk-UZGQNTVW.js → chunk-UA324D4O.js} +8 -6
- package/{chunk-YYLHWIW6.js → chunk-UKZX3NHN.js} +1 -1
- package/chunk-UWXDA7L5.js +8005 -0
- package/{chunk-3DII57IT.js → chunk-VCAQFMVN.js} +1 -1
- package/chunk-VIWDGTDA.js +8 -0
- package/chunk-VJVNU77E.js +83 -0
- package/{chunk-A6FMKU7M.js → chunk-VVJ2ENLY.js} +47 -67
- package/{chunk-UKWGR5SS.js → chunk-VY6VFGKR.js} +194 -1144
- package/{chunk-QDSINZM3.js → chunk-WJ3B6FX6.js} +1 -14
- package/{chunk-Q67DOFOO.js → chunk-Y3PMXGLH.js} +2 -0
- package/chunk-YK5MHOWM.js +915 -0
- package/chunk-YV25TM3R.js +780 -0
- package/{chunk-TOP2VXOR.js → chunk-YVU4XVJD.js} +5 -5
- package/{chunk-7SOWRCQQ.js → chunk-Z5NGE5DH.js} +29 -9
- package/{chunk-6VFARHZW.js → chunk-ZBHR642M.js} +994 -1079
- package/chunk-ZRAU6T47.js +56 -0
- package/{chunk-B6P4QKEN.js → chunk-ZSUDOTPL.js} +19 -17
- package/commandRegistry-QU62WJQX.js +833 -0
- package/{contentThunks-LXOZUD2Y.js → contentThunks-VGV3JJVB.js} +37 -35
- package/{cooldownCommands-REAWYVTY.js → cooldownCommands-ZLEPIB4A.js} +2 -2
- package/{createAgentAutomationAction-M5NDEIC6.js → createAgentAutomationAction-ZNVLI4WV.js} +39 -37
- package/createDialogAction-TTUA46DT.js +69 -0
- package/{createPageAction-WY5ZKP2M.js → createPageAction-KUFSC5XW.js} +46 -43
- package/{chunk-ITBLTYQB.js → cursorProvider-YGGNMVWX.js} +2496 -9897
- package/{dbSlice-XVWBAGYN.js → dbSlice-MYEETO73.js} +11 -10
- package/{deleteFile-YG6QMJLU.js → deleteFile-KESP65GC.js} +7 -6
- package/{dialogCommands-5J56DFWN.js → dialogCommands-DRDPEOTL.js} +49 -45
- package/{dialogSlice-HSGREZGA.js → dialogSlice-V2SVSTIV.js} +41 -34
- package/{dist-VODFSGNG.js → dist-NJC2W7I4.js} +61 -54
- package/{docCreateCommands-KYI2DC2U.js → docCreateCommands-M26CFDDQ.js} +48 -43
- package/{docDeleteCommands-67REUSRY.js → docDeleteCommands-LRZHCKVX.js} +49 -44
- package/{docReadCommands-HOSVSBDJ.js → docReadCommands-6QJSISHK.js} +47 -42
- package/{docStore-IIS36NGG.js → docStore-4RWAFNDM.js} +16 -12
- package/{docUpdateCommands-EMGCSMXY.js → docUpdateCommands-W4KU4U5T.js} +48 -43
- package/{fetchMessages-EIU7UFFK.js → fetchMessages-3PXAHKCR.js} +5 -5
- package/{getPricing-LUSEABA6.js → getPricing-NMMFT3YI.js} +4 -4
- package/{handleSendMessageAction-FEHCWMN2.js → handleSendMessageAction-VEWLGB5Z.js} +107 -41
- package/index.js +87 -884
- package/{lib-FRRS27KN.js → lib-PU2G2MSO.js} +523 -191
- package/{localDialogRead-BTFJ4V2I.js → localDialogRead-UYCKO7YZ.js} +2 -2
- package/{localRuntimeAuthority-6IR6BBXE.js → localRuntimeAuthority-TU6OBC76.js} +9 -6
- package/{localRuntimeDb-SYQGUF4U.js → localRuntimeDb-VKWVOPPI.js} +1 -1
- package/{machineCommands-G5J754EH.js → machineCommands-AEHHCJEW.js} +92 -82
- package/machineWsRunDispatch-MY2KHS36.js +154 -0
- package/{memberThunks-QGFLFVCI.js → memberThunks-EE6TI3TV.js} +20 -18
- package/{models-T3SG6MJ5.js → models-ZPU5EDF4.js} +2 -2
- package/oauthTokenStore-ITEB663N.js +23 -0
- package/package.json +1 -1
- package/pdf-U6KSUEZZ.js +26435 -0
- package/processSpawn-SOAV3FEV.js +11 -0
- package/profileConfig-ZGOFORWV.js +43 -0
- package/{providerPresetApply-FG6NZ57W.js → providerPresetApply-TEBH7FDX.js} +7 -7
- package/{providerRegistry-757OWH3O.js → providerRegistry-CBJLNCET.js} +11 -7
- package/{read-COE3ZYR6.js → read-PJIT2YEJ.js} +7 -6
- package/{readDocTool-5USN4A6V.js → readDocTool-DRSXHGNL.js} +5 -3
- package/{readlineWorkspace-TGCYJFEB.js → readlineWorkspace-7Q6MITLV.js} +2685 -2050
- package/{removeDialogAgentAction-IX3MN2ZO.js → removeDialogAgentAction-IN4WUKJJ.js} +21 -25
- package/{runAgentClientLoop-UY76PPZM.js → runAgentClientLoop-H2JALUVD.js} +76 -70
- package/{runtimeDoctorCommands-X6WDBEQX.js → runtimeDoctorCommands-PIVSBZRZ.js} +4 -4
- package/runtimeModeArgs-2Y7BALTO.js +31 -0
- package/{setDialogExtraReferencesAction-X4HCPNZL.js → setDialogExtraReferencesAction-VDRF7LPK.js} +15 -13
- package/{setPrimaryDialogAgentAction-4GMIQLOD.js → setPrimaryDialogAgentAction-RO6LIWJ4.js} +22 -26
- package/{chunk-AFUORTY4.js → settingThunks-3OPOLOIA.js} +226 -940
- package/{skillDiscovery-CYUCJMAG.js → skillDiscovery-ZBU76COE.js} +3 -3
- package/{slateUtils-RIZES3PV.js → slateUtils-NGV2NMKM.js} +1 -1
- package/{spaceCommands-NKJVJCQQ.js → spaceCommands-UBLL5EF2.js} +51 -46
- package/{streamAgentChatTurn-3YVIO4KE.js → streamAgentChatTurn-FFJWW3FD.js} +214 -108
- package/{switchDialogAgentAction-N52LRPA3.js → switchDialogAgentAction-MVF2JNE7.js} +18 -19
- package/{tableCommands-O6NWHFKV.js → tableCommands-6U4BMLRR.js} +10 -10
- package/{toolApiClient-QVJ6HDNN.js → toolApiClient-EJT6TMFG.js} +3 -3
- package/tools-AZRYLYNK.js +116 -0
- package/{tuiSummaryLlmCaller-WFRWERGK.js → tuiSummaryLlmCaller-7S5HJ3MT.js} +25 -22
- package/{updateCommands-2M74UL7P.js → updateCommands-4EHDLF5J.js} +3 -3
- package/{updateDialogTitleAction-GF5T3VMK.js → updateDialogTitleAction-5WXTRUJM.js} +82 -44
- package/action-YVYQEAAV.js +0 -31
- package/agentListCommands-GUDMBDHZ.js +0 -410
- package/agentRecordCommands-RSS44XHC.js +0 -128
- package/agentRunCommand-P7VHL4ZR.js +0 -156
- package/browser-image-compression-MFDTD7K6.js +0 -1763
- package/chatQueueReduxAdapter-WFROMKD3.js +0 -186
- package/chunk-CQ3WA2NE.js +0 -299
- package/chunk-FQUHIG5X.js +0 -20782
- package/chunk-M76ECQRD.js +0 -13658
- package/chunk-MEYIRKDN.js +0 -8967
- package/chunk-Q5FJJ6XI.js +0 -103
- package/chunk-S7Z2HMCN.js +0 -25
- package/chunk-Y5GCAMGP.js +0 -9
- package/chunk-YPREESF4.js +0 -225
- package/createDialogAction-TDFOINOY.js +0 -65
- package/machineWsRunDispatch-VXYBYYKM.js +0 -144
- package/settingSlice-ZQZVUPKK.js +0 -204
- package/syncMapping-N6RGXGBW.js +0 -437
- package/tools-Q6IBBG33.js +0 -110
- package/{chunk-X7HHHIOZ.js → chunk-Y6ROFCZO.js} +0 -0
- 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
|
+
};
|