nolo-cli 0.95.0-alpha.6 → 0.95.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-AUQRMRWL.js → _executeModel-4NTXSCYT.js} +67 -63
- package/{action-YVYQEAAV.js → action-GI44T4DR.js} +10 -10
- package/{addContentAction-O7R66HEX.js → addContentAction-B2DRF7P6.js} +9 -9
- package/{addDialogAgentAction-74OA7KYP.js → addDialogAgentAction-T3I7IXPK.js} +15 -17
- package/{agentDeleteCommand-4BAHJRU3.js → agentDeleteCommand-QYCCUQ35.js} +47 -43
- package/{agentEmailCommands-QISOY7Y6.js → agentEmailCommands-GJ7KXHA6.js} +89 -82
- package/{agentListCommands-U46ODMQU.js → agentListCommands-JDU7V3M5.js} +77 -82
- package/{agentMachineCommands-EHV2KM2C.js → agentMachineCommands-PXJG3EDI.js} +42 -38
- package/{agentProviderCommands-GNPTL5XR.js → agentProviderCommands-YK2BIIXZ.js} +1 -1
- package/{agentPullCommand-O5MPVJ5E.js → agentPullCommand-HF4A42D4.js} +1 -1
- package/agentRecordCommands-3ONMYU6P.js +135 -0
- package/{agentRunCommand-K4CLMA6B.js → agentRunCommand-L6NJGDBA.js} +88 -80
- package/{agentRunControl-XLGD3UZ5.js → agentRunControl-5T64LM2M.js} +2 -2
- package/{agentRuntimeLocal-O4HPUJA4.js → agentRuntimeLocal-SYLNOKCT.js} +44 -36
- package/{agentSlice-ZYT2OUR3.js → agentSlice-X63VSE6R.js} +11 -11
- package/{appDeleteCommands-R5BBTKQK.js → appDeleteCommands-IP22BHZE.js} +42 -38
- package/{appDeployCommands-ZJIXOJWD.js → appDeployCommands-5ZTQL6UL.js} +42 -38
- package/{appDeployStatusCommands-B3R2ZTBF.js → appDeployStatusCommands-G6EMAT75.js} +42 -38
- package/{appGetCommands-2AQSOV2A.js → appGetCommands-UXBDAYEM.js} +42 -38
- package/{appListCommands-HCIJGZFY.js → appListCommands-J274GTVP.js} +42 -38
- package/{authCommand-F4EFRRX6.js → authCommand-W6I6GD3F.js} +115 -23
- package/{authCommands-RGOGCPP6.js → authCommands-GBIFZWD3.js} +5 -5
- package/{builtinSkillRegistry-FUAVTRVZ.js → builtinSkillRegistry-ZMF6YGNO.js} +6 -5
- package/{chatQueueReduxAdapter-Q5V4YJVI.js → chatQueueReduxAdapter-KN774OKJ.js} +30 -29
- package/{chromeCommands-FZYAU75D.js → chromeCommands-K27J4OVZ.js} +124 -28
- package/{chromeOpsCommands-62P2Q2YB.js → chromeOpsCommands-IXRLN57H.js} +4 -3
- package/{chunk-6OZ36FXI.js → chunk-27ONFIEY.js} +22 -4
- package/{chunk-XOVEWFLK.js → chunk-2JCOP36I.js} +100 -100
- package/{chunk-JEDZAO7L.js → chunk-2SYTUTLI.js} +257 -37
- package/{chunk-OIVSQH2O.js → chunk-3BXNTXYI.js} +299 -5
- package/{chunk-EYAQT56M.js → chunk-4DPP773Q.js} +2 -2
- package/chunk-4LCOCOR5.js +50 -0
- package/{chunk-2GRGFCF6.js → chunk-4VJAC32I.js} +2 -1
- package/{chunk-MC4XLIJ7.js → chunk-523DITKR.js} +1 -1
- package/{chunk-IAO6JBYW.js → chunk-5B7XS6UO.js} +164 -14
- package/{chunk-E4MARS3Q.js → chunk-5GVBDNTO.js} +1 -1
- package/chunk-5J3PYNUP.js +255 -0
- package/chunk-5MMAK75Q.js +15 -0
- package/{chunk-JPGCXHNM.js → chunk-5OA5HMTL.js} +1 -1
- package/{chunk-AFDS2CVM.js → chunk-5T2W2ZZN.js} +15 -20
- package/{chunk-42V6BK2E.js → chunk-62IL3KQV.js} +4 -34
- package/{chunk-YQTQQX2H.js → chunk-67HHBCFJ.js} +1 -1
- package/{chunk-SNPMM7H3.js → chunk-67T7O467.js} +13 -13
- package/{chunk-6YTOJY35.js → chunk-6D2JFXLY.js} +35 -0
- package/{chunk-4MY4GLIW.js → chunk-6IHBIRPK.js} +969 -1090
- package/{chunk-3BMYXEUW.js → chunk-6O4IK4V2.js} +1 -1
- package/{chunk-DHDMC6FO.js → chunk-6TPOEJMQ.js} +9 -4
- package/{chunk-LLT642J4.js → chunk-6UPZ63YT.js} +24 -5
- package/{chunk-WADCY6G6.js → chunk-6ZWMH6TJ.js} +111 -41
- package/{chunk-ABQYVJBJ.js → chunk-7CHC4W22.js} +1 -1
- package/{chunk-GQBOR3G6.js → chunk-7KVZ5LDQ.js} +2 -2
- package/{chunk-MMPXJXHT.js → chunk-7VJHIB2S.js} +573 -476
- package/{chunk-OA6Q2A4I.js → chunk-A7RSPKU6.js} +98 -22
- package/{chunk-KQ4ONNQD.js → chunk-ALFH24P3.js} +56 -7
- package/{chunk-Q554LLSI.js → chunk-AUDNYVRC.js} +1 -1
- package/{chunk-GPCZ7UXG.js → chunk-AZRHIN5B.js} +1 -1
- package/{chunk-JRQFUXY7.js → chunk-B2XUQXQX.js} +96 -19
- package/chunk-BMQ2MJUK.js +153 -0
- package/{chunk-3IIEFNGY.js → chunk-C53ZG23R.js} +2 -2
- package/chunk-CHOZJMJS.js +78 -0
- package/{chunk-A6G32FNX.js → chunk-CJXHT3S7.js} +13 -13
- package/{chunk-HJUYAD4A.js → chunk-CPUFH46E.js} +8 -8
- package/{chunk-JOHSKZQX.js → chunk-CQMQXVFQ.js} +859 -141
- package/{chunk-LS2ZANRJ.js → chunk-CTUQJVQM.js} +1 -1
- package/{chunk-BP4XNZRM.js → chunk-CU3QB4HW.js} +3 -3
- package/{chunk-ACTMNVHM.js → chunk-CYSYR67N.js} +1 -1
- package/{chunk-ZXKVPF4K.js → chunk-DA54MHPJ.js} +236 -36
- package/{chunk-VLTIYV3X.js → chunk-DCLMZ5TX.js} +4 -4
- package/{chunk-UKZDAFYT.js → chunk-DSSTTEKI.js} +6 -10
- package/{chunk-HVURBGF3.js → chunk-ESRMFY7G.js} +2 -2
- package/{chunk-TRV2MIDW.js → chunk-EXAJ6DCR.js} +1 -0
- package/chunk-GMZLP5DV.js +82 -0
- package/{chunk-FDTR4QJ6.js → chunk-H6A6X4EK.js} +32 -1
- package/{chunk-DVINR3PL.js → chunk-HDLLCBRF.js} +1 -1
- package/{chunk-ONXOABJR.js → chunk-HNGRBWYF.js} +3 -0
- package/{chunk-ZLR5JN3E.js → chunk-HWRQVJGX.js} +7 -7
- package/{chunk-H62HCIUP.js → chunk-HYZIYH2H.js} +11 -10
- package/{chunk-NTW5GWDM.js → chunk-I3QNET24.js} +32 -17
- package/{chunk-WV42OMV7.js → chunk-IAESIMK7.js} +4 -4
- package/{chunk-QIAVMDHY.js → chunk-IUVCUGQR.js} +4 -4
- package/{chunk-EGSKXKR5.js → chunk-IX27RP45.js} +1 -1
- package/{chunk-IIVGDG4I.js → chunk-LNPYTNMG.js} +8 -4
- package/{chunk-BLJWCTRL.js → chunk-LVITW736.js} +1 -1
- package/{chunk-76WEAXJB.js → chunk-M3LRSBOX.js} +18 -15
- package/{chunk-XRWZB6CF.js → chunk-M73PVOVS.js} +23 -76
- package/{chunk-7S4YWN7P.js → chunk-MX574M24.js} +1 -1
- package/{chunk-FZGV4FGK.js → chunk-NUHHBEJC.js} +378 -187
- package/{chunk-53HEEOTT.js → chunk-O26PCYLS.js} +80 -13
- package/{chunk-3DII57IT.js → chunk-O2OWEFII.js} +1 -1
- package/chunk-OCZKATRC.js +129 -0
- package/chunk-P6GMCCAT.js +870 -0
- package/{chunk-CPH3W5A7.js → chunk-Q4GP72HX.js} +94 -3
- package/{chunk-Z77CRGTW.js → chunk-R4SQ3LGW.js} +1 -1
- package/chunk-RE3CDVRX.js +7600 -0
- package/{chunk-DEUUPHOO.js → chunk-RKGKDQGJ.js} +74 -17
- package/{chunk-V4MJDUSR.js → chunk-RSEEDUMS.js} +2 -2
- package/{chunk-BZWBEHGD.js → chunk-S3VFZW75.js} +66 -38
- package/{chunk-UZGQNTVW.js → chunk-S5XGT6GB.js} +5 -3
- package/{chunk-AFUORTY4.js → chunk-SONWNI3L.js} +21 -21
- package/{chunk-BYMV6QZG.js → chunk-TNIX77YM.js} +4 -0
- package/{chunk-OF7AQZUG.js → chunk-TU5NE4U3.js} +9 -84
- package/chunk-UNYJU5L6.js +780 -0
- package/{chunk-J4MOO56S.js → chunk-UQNS32WZ.js} +10 -2
- package/chunk-V2SAIXHE.js +13349 -0
- package/chunk-VIWDGTDA.js +8 -0
- package/chunk-VJVNU77E.js +83 -0
- package/{chunk-6D6VBVEW.js → chunk-VPFEPRME.js} +9 -9
- package/{chunk-JAXOVNM4.js → chunk-WILHZY7K.js} +45 -45
- package/{chunk-UKWGR5SS.js → chunk-WIWM4FE3.js} +187 -398
- package/{chunk-BGSLKVCP.js → chunk-XTDH3PGV.js} +6 -7
- package/{chunk-O6OSWFZQ.js → chunk-XUWRURDF.js} +6 -0
- package/{chunk-Q67DOFOO.js → chunk-Y3PMXGLH.js} +2 -0
- package/{chunk-SH43IESU.js → chunk-YUNJN43V.js} +44 -9
- package/{chunk-TOP2VXOR.js → chunk-Z4CSIXYP.js} +2 -2
- package/{chunk-2F7RJC6L.js → chunk-ZOVKKMF6.js} +1 -1
- package/chunk-ZRAU6T47.js +56 -0
- package/commandRegistry-NPS6IYBO.js +833 -0
- package/{contentThunks-PT23JWJX.js → contentThunks-EB4JFL4K.js} +32 -30
- package/{cooldownCommands-REAWYVTY.js → cooldownCommands-ZLEPIB4A.js} +2 -2
- package/{createAgentAutomationAction-N27SYTLU.js → createAgentAutomationAction-NZS7N4AW.js} +32 -30
- package/{createDialogAction-XZPLHD5G.js → createDialogAction-4Q4J7P4T.js} +36 -33
- package/{createPageAction-KHVJQ3CS.js → createPageAction-FPKRGV7D.js} +38 -36
- package/{chunk-3SJQXXGY.js → cursorProvider-YGGNMVWX.js} +2560 -9879
- package/{dbSlice-XVWBAGYN.js → dbSlice-DQ32LYTJ.js} +8 -8
- package/{deleteFile-YG6QMJLU.js → deleteFile-NX6QHCWZ.js} +3 -3
- package/{dialogCommands-ZUWW5UT6.js → dialogCommands-XXZH5K6U.js} +45 -41
- package/{dialogSlice-3YH242HS.js → dialogSlice-DXEZ3PA3.js} +36 -29
- package/{dist-VODFSGNG.js → dist-NJC2W7I4.js} +61 -54
- package/{docCreateCommands-Q6FADDSJ.js → docCreateCommands-FLNUDWG6.js} +44 -40
- package/{docDeleteCommands-ZKIH54PZ.js → docDeleteCommands-74OURFAB.js} +44 -40
- package/{docReadCommands-7BZT2QTW.js → docReadCommands-QENWDQVH.js} +43 -39
- package/{docStore-YSZRNUUD.js → docStore-2JTPJVFK.js} +11 -10
- package/{docUpdateCommands-WJXWTRL7.js → docUpdateCommands-J4HWJ5JO.js} +44 -40
- package/{fetchMessages-EIU7UFFK.js → fetchMessages-67MEFPZR.js} +2 -2
- package/{getPricing-LUSEABA6.js → getPricing-NMMFT3YI.js} +3 -3
- package/{handleSendMessageAction-KJO2QDBM.js → handleSendMessageAction-FGPHI364.js} +91 -83
- package/index.js +87 -884
- package/{localDialogRead-BTFJ4V2I.js → localDialogRead-EBRS242U.js} +2 -2
- package/{localRuntimeAuthority-6IR6BBXE.js → localRuntimeAuthority-5W6IJRAD.js} +6 -6
- package/{localRuntimeDb-SYQGUF4U.js → localRuntimeDb-3LRMNLCM.js} +1 -1
- package/{machineCommands-QC4TD7GJ.js → machineCommands-26AZP4AS.js} +84 -77
- package/{machineWsRunDispatch-XUOIAXO7.js → machineWsRunDispatch-GQ5XJ2DL.js} +81 -74
- package/{memberThunks-QGFLFVCI.js → memberThunks-5ZXPR63F.js} +9 -9
- 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-DD6NGWW6.js} +7 -7
- package/{providerRegistry-757OWH3O.js → providerRegistry-XDRLMYGJ.js} +7 -7
- package/{read-COE3ZYR6.js → read-EPTJRAEF.js} +5 -5
- package/{readDocTool-5USN4A6V.js → readDocTool-W4NDXNEX.js} +5 -3
- package/{readlineWorkspace-74TXXSLO.js → readlineWorkspace-B7NBQCX6.js} +2448 -2022
- package/{removeDialogAgentAction-IX3MN2ZO.js → removeDialogAgentAction-BVAWQKXE.js} +17 -19
- package/{runAgentClientLoop-37BXJD62.js → runAgentClientLoop-RVB5K6R2.js} +61 -58
- package/{runtimeDoctorCommands-X6WDBEQX.js → runtimeDoctorCommands-3USD722U.js} +3 -3
- package/runtimeModeArgs-2Y7BALTO.js +31 -0
- package/{setDialogExtraReferencesAction-X4HCPNZL.js → setDialogExtraReferencesAction-LYY45IAD.js} +12 -11
- package/{setPrimaryDialogAgentAction-4GMIQLOD.js → setPrimaryDialogAgentAction-73IL7DLU.js} +18 -20
- package/{settingSlice-ZQZVUPKK.js → settingSlice-Q6EKL7EQ.js} +9 -9
- package/{skillDiscovery-CYUCJMAG.js → skillDiscovery-ZBU76COE.js} +3 -3
- package/{spaceCommands-P3ONT6LL.js → spaceCommands-BYDGOMW7.js} +44 -40
- package/{streamAgentChatTurn-FGXQXALU.js → streamAgentChatTurn-HV3FSRHN.js} +183 -91
- package/{switchDialogAgentAction-N52LRPA3.js → switchDialogAgentAction-UUXDSQ6X.js} +15 -17
- package/{tableCommands-O6NWHFKV.js → tableCommands-G7RV3RU3.js} +4 -4
- package/{toolApiClient-QVJ6HDNN.js → toolApiClient-INIQCPGY.js} +3 -3
- package/{tools-R5UF2KZO.js → tools-AZR26MXC.js} +54 -51
- package/{tuiSummaryLlmCaller-T2SHYMDZ.js → tuiSummaryLlmCaller-74NRRLVW.js} +18 -16
- package/{updateCommands-2M74UL7P.js → updateCommands-4EHDLF5J.js} +3 -3
- package/{updateDialogTitleAction-RTADGV7A.js → updateDialogTitleAction-HEWCCXZZ.js} +81 -43
- package/agentRecordCommands-SIPURU2S.js +0 -128
- package/chunk-FOWEGIMF.js +0 -18881
- package/chunk-M76ECQRD.js +0 -13658
- package/chunk-Q5FJJ6XI.js +0 -103
- package/chunk-S7Z2HMCN.js +0 -25
- package/{chunk-VMFTFOWF.js → chunk-3AH7LNUB.js} +7 -7
- 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 };
|
|
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
|
+
};
|