very-happy-cli 0.2.159 → 0.2.161
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/dist/{AcpBackend-VsfkZiVF.mjs → AcpBackend-6U6pQgx1.mjs} +4 -2
- package/dist/{AcpBackend-DUYFlyfN.cjs → AcpBackend-Ba98QDif.cjs} +78 -76
- package/dist/{AcpSessionManager-Bdv8LWXh.cjs → AcpSessionManager-BAY1Pggx.cjs} +9 -9
- package/dist/{AcpSessionManager-rYtVb0kN.mjs → AcpSessionManager-CoMWFVw3.mjs} +1 -1
- package/dist/BasePermissionHandler-2R0uH2CI.cjs +157 -0
- package/dist/BasePermissionHandler-BvvhBTja.mjs +155 -0
- package/dist/BaseReasoningProcessor-DyhO1uoU.mjs +198 -0
- package/dist/BaseReasoningProcessor-fsVNmCEF.cjs +200 -0
- package/dist/RemoteModeDisplay-D-HewyXg.mjs +150 -0
- package/dist/RemoteModeDisplay-NC1gPHtj.cjs +153 -0
- package/dist/agentAttachments-Dbw8iMCZ.cjs +20 -0
- package/dist/agentAttachments-M_B5qEF2.mjs +18 -0
- package/dist/agentGuidance-B5NATuFa.cjs +28 -0
- package/dist/agentGuidance-CQuNlNx8.mjs +20 -0
- package/dist/{agentHome-CvsJyeQB.mjs → agentHome-Ck1i1TQB.mjs} +8 -22
- package/dist/{agentHome-CHh4lmjM.cjs → agentHome-DvNnGphb.cjs} +14 -28
- package/dist/api-B2vLMS-z.cjs +3346 -0
- package/dist/api-SffjRQ1b.mjs +3339 -0
- package/dist/{types-Dh-s4Lqs.mjs → apiMachine-BpW9t8MO.mjs} +9116 -16205
- package/dist/{types-BbvK1Tr_.cjs → apiMachine-gFA54X7y.cjs} +9104 -16247
- package/dist/assistantTools-BfA0R3_m.cjs +380 -0
- package/dist/assistantTools-CgiTbnWb.mjs +376 -0
- package/dist/attachmentContent-CSGxr71v.mjs +82 -0
- package/dist/attachmentContent-DMMZzevR.cjs +88 -0
- package/dist/attachmentLimits-CzVrqgLR.cjs +354 -0
- package/dist/attachmentLimits-yba1uHFO.mjs +348 -0
- package/dist/auth-Bt4ceBBy.cjs +227 -0
- package/dist/auth-CYHjQ8oQ.mjs +225 -0
- package/dist/auth-DdyVZSo6.mjs +218 -0
- package/dist/auth-x4CEoysH.cjs +220 -0
- package/dist/authRelay-BdYkC1Po.cjs +156 -0
- package/dist/authRelay-DSAvg1uv.mjs +143 -0
- package/dist/{auto-DKmEls8Z.cjs → auto-BDXDUnjB.cjs} +70 -79
- package/dist/{auto-nb8GhRRy.mjs → auto-CXLlRi3a.mjs} +27 -36
- package/dist/backgroundTaskActivity-8PdPxrvy.mjs +149 -0
- package/dist/backgroundTaskActivity-CBvUdj39.cjs +157 -0
- package/dist/bootstrap-BNQq05jR.mjs +112 -0
- package/dist/bootstrap-CkgIq8N3.cjs +116 -0
- package/dist/browser-9pyhQr1R.mjs +20 -0
- package/dist/browser-BDOlKWYe.cjs +22 -0
- package/dist/claudeCliPath-BqkaH2oR.mjs +8 -0
- package/dist/claudeCliPath-U4HHmV4r.cjs +10 -0
- package/dist/claudeLocal-BDuGFnjJ.cjs +343 -0
- package/dist/claudeLocal-CQa8qnwq.mjs +339 -0
- package/dist/claudeLocalLauncher-Bd5I2-j6.cjs +154 -0
- package/dist/claudeLocalLauncher-CDqQI9ak.mjs +152 -0
- package/dist/cliUpdate-DsKXPFYp.cjs +120 -0
- package/dist/cliUpdate-Y34VGe9Y.mjs +112 -0
- package/dist/client-Brn-UwVk.mjs +100 -0
- package/dist/client-CXb1VJui.mjs +112 -0
- package/dist/client-C_axwRry.cjs +104 -0
- package/dist/client-DOBWJL3u.cjs +119 -0
- package/dist/codex/happyMcpStdioBridge.cjs +33 -14
- package/dist/codex/happyMcpStdioBridge.mjs +26 -7
- package/dist/codexAppServerClient-ZzhUTWPo.cjs +1090 -0
- package/dist/codexAppServerClient-oeQKD6Qf.mjs +1088 -0
- package/dist/codexCommand-C7H0NpBe.cjs +2088 -0
- package/dist/codexCommand-CJ82bl3l.mjs +2086 -0
- package/dist/codexThreadFork-BCaEMBiM.mjs +338 -0
- package/dist/codexThreadFork-BZqF-9bX.cjs +350 -0
- package/dist/{config-ClLtM6F3.mjs → config-BglnktIo.mjs} +7 -40
- package/dist/{config-DLx-vW3I.cjs → config-CYpL1Ahd.cjs} +26 -59
- package/dist/configuration-DoWFJUPm.mjs +170 -0
- package/dist/configuration-v9f8LM9T.cjs +181 -0
- package/dist/connect-hgcNjyAB.mjs +682 -0
- package/dist/connect-yEvjdRvx.cjs +684 -0
- package/dist/constants-BC4St0xd.mjs +11 -0
- package/dist/constants-VJ0N6WuG.cjs +17 -0
- package/dist/contentLogMetadata-BlWI0egu.mjs +51 -0
- package/dist/contentLogMetadata-ZSFk_NjQ.cjs +54 -0
- package/dist/context-B45vMtSZ.cjs +69 -0
- package/dist/context-C9GHPLEm.mjs +65 -0
- package/dist/controlClient-DjoKTtgK.mjs +260 -0
- package/dist/controlClient-fEHE85bH.cjs +279 -0
- package/dist/createSessionMetadata-BRLB9CNO.cjs +58 -0
- package/dist/createSessionMetadata-mIeehclp.mjs +54 -0
- package/dist/defaultPermissionMode-BnxJPVHT.mjs +4 -0
- package/dist/defaultPermissionMode-CxmTXUQR.cjs +7 -0
- package/dist/detectCLI-CSGMlV51.mjs +58 -0
- package/dist/detectCLI-DR9ZaN6B.cjs +61 -0
- package/dist/deterministicJson-DKDP_mM-.cjs +507 -0
- package/dist/deterministicJson-p835AdAU.mjs +502 -0
- package/dist/doctor-BPkYWSuq.mjs +75 -0
- package/dist/doctor-BeUuQXFs.mjs +391 -0
- package/dist/doctor-hVNnSZJn.cjs +395 -0
- package/dist/doctor-u46qYYKX.cjs +79 -0
- package/dist/doctorReadiness-BCZGcN0a.cjs +151 -0
- package/dist/doctorReadiness-C208SMN9.mjs +142 -0
- package/dist/editPaths-BVfS_FFL.mjs +68 -0
- package/dist/editPaths-Bqp4OFPw.cjs +73 -0
- package/dist/ensureDaemonRunning-CO7d1gOC.mjs +61 -0
- package/dist/ensureDaemonRunning-Dg9aZfjs.cjs +64 -0
- package/dist/handleResumeCommand-BiTPK0qd.mjs +240 -0
- package/dist/handleResumeCommand-DnVmy7a3.cjs +245 -0
- package/dist/ids-B6ZC0HGt.cjs +13 -0
- package/dist/ids-DU6sLx4C.mjs +10 -0
- package/dist/index-B6UGRQ7h.mjs +102 -0
- package/dist/{index-2mCaeKyf.mjs → index-CAFwetLk.mjs} +68 -38
- package/dist/index-Cqx-Raq6.mjs +68 -0
- package/dist/index-D3kI0hDR.cjs +107 -0
- package/dist/index-DA7yINuk.cjs +994 -0
- package/dist/{index-BEOMECtE.cjs → index-LIn6nCcq.cjs} +121 -91
- package/dist/index-Pf2cV9cn.cjs +182 -0
- package/dist/index-SPGPenK5.mjs +158 -0
- package/dist/index-gNTWtSKN.cjs +71 -0
- package/dist/index-qdS1friN.mjs +949 -0
- package/dist/index.cjs +5 -46
- package/dist/index.mjs +5 -46
- package/dist/{install-BPhJppvd.mjs → install-BO_W7VhL.mjs} +37 -37
- package/dist/install-Bu85vlHD.cjs +88 -0
- package/dist/install-ClUUl3yp.mjs +86 -0
- package/dist/{install-BOHrUaFM.cjs → install-Cs5qAPrB.cjs} +38 -38
- package/dist/{installPiTools-DuZ6jZvX.cjs → installPiTools-BKnXjrVu.cjs} +2 -3
- package/dist/{installPiTools-Cj7yU9Fc.mjs → installPiTools-B_CdM5_2.mjs} +1 -2
- package/dist/{installTerminalHooks-Cou3WUf3.cjs → installTerminalHooks-BQZbvxsZ.cjs} +5 -40
- package/dist/{installTerminalHooks-WeznjkuC.mjs → installTerminalHooks-By7gBMEF.mjs} +3 -38
- package/dist/lib.cjs +28 -19
- package/dist/lib.d.cts +12 -2
- package/dist/lib.d.mts +12 -2
- package/dist/lib.mjs +23 -14
- package/dist/lidState-C2dI0FAN.mjs +297 -0
- package/dist/lidState-KHHu1015.cjs +305 -0
- package/dist/limits-C-a7gr04.cjs +43 -0
- package/dist/limits-DIo7rEBR.mjs +36 -0
- package/dist/localHappyAgentAuth-BXiHPXdC.cjs +86 -0
- package/dist/localHappyAgentAuth-DCsetiyG.mjs +82 -0
- package/dist/logger-Bc8-u1w0.cjs +275 -0
- package/dist/logger-fXoNzNuB.mjs +271 -0
- package/dist/loginShellEnv-BkuYtExZ.cjs +182 -0
- package/dist/loginShellEnv-Dw8M7tkI.mjs +167 -0
- package/dist/machineMetadata-BHjehxJY.mjs +38 -0
- package/dist/machineMetadata-BibDMFVx.cjs +41 -0
- package/dist/main-BktM4A1K.mjs +939 -0
- package/dist/main-CLaX-t-b.cjs +941 -0
- package/dist/manager-BQ4flvQZ.mjs +101 -0
- package/dist/manager-Cly8xVIR.cjs +105 -0
- package/dist/{mcp-Dy3f_K0h.mjs → mcp-CeUd9KDr.mjs} +27 -33
- package/dist/{mcp-CPYbtsYG.cjs → mcp-GBfE70nk.cjs} +42 -48
- package/dist/messageBuffer-BWlGgR3A.mjs +71 -0
- package/dist/messageBuffer-fJMH6uY8.cjs +73 -0
- package/dist/mirrorProtocol-BNLtoWjO.mjs +170 -0
- package/dist/mirrorProtocol-BUtmg1ws.cjs +186 -0
- package/dist/oneShotPrompts-CL0dip9C.cjs +16 -0
- package/dist/oneShotPrompts-DT4p6RNd.mjs +12 -0
- package/dist/package-Cl5BEP5x.cjs +173 -0
- package/dist/package-uOg9SCKi.mjs +171 -0
- package/dist/path-B7zW-WwE.cjs +18 -0
- package/dist/path-D2wdaNSk.mjs +15 -0
- package/dist/peerTools-CIeiy9wn.cjs +283 -0
- package/dist/peerTools-Dz3_7Bkk.mjs +272 -0
- package/dist/permissionMode-CH4FoZfU.mjs +80 -0
- package/dist/permissionMode-CrV-XuMs.cjs +87 -0
- package/dist/persistence-CBNMzSa8.cjs +414 -0
- package/dist/persistence-oET5n61f.mjs +372 -0
- package/dist/piExtension.mjs +2 -1
- package/dist/piRunnerArgs-Bf7RUF__.cjs +66 -0
- package/dist/piRunnerArgs-Dk1ncwHF.mjs +59 -0
- package/dist/{piRuntime-NtF0YqjH.cjs → piRuntime-B_6TE9Eb.cjs} +4 -4
- package/dist/{piRuntime-kLZNpAAl.mjs → piRuntime-BwRdhK_N.mjs} +2 -2
- package/dist/{piTerminal-B0fEOV_2.mjs → piTerminal-Bap3R8Re.mjs} +32 -35
- package/dist/{piTerminal-9J0GAKzb.cjs → piTerminal-CagmEoez.cjs} +32 -35
- package/dist/previewPath-B0rBdhy1.cjs +83 -0
- package/dist/previewPath-CXN4Vag0.mjs +81 -0
- package/dist/projectPath-BTBIMB57.mjs +10 -0
- package/dist/projectPath-ChLhdOyt.cjs +13 -0
- package/dist/registerCommonHandlers-BjSV2Skz.cjs +538 -0
- package/dist/registerCommonHandlers-CrgvJsOy.mjs +536 -0
- package/dist/registerKillSessionHandler-6TC2S3lf.cjs +366 -0
- package/dist/registerKillSessionHandler-Cbc8Rgtd.mjs +363 -0
- package/dist/remoteSessionClient-BNx78NLb.cjs +634 -0
- package/dist/remoteSessionClient-CO7qOjR0.mjs +612 -0
- package/dist/resources-BdFBQi8r.mjs +117 -0
- package/dist/resources-JDPugcDq.cjs +120 -0
- package/dist/run-2l5vSt2h.mjs +5743 -0
- package/dist/run-D5xAEWSB.cjs +5766 -0
- package/dist/runClaude-BX6ixjtW.cjs +894 -0
- package/dist/runClaude-BgN6xo05.mjs +892 -0
- package/dist/runClaudeDeps-Bp20MScE.cjs +4168 -0
- package/dist/runClaudeDeps-COBBhD9o.mjs +4129 -0
- package/dist/{runGemini-F-mqx3_K.cjs → runGemini-CSMPkt0p.cjs} +202 -175
- package/dist/{runGemini-DV6Ouadt.mjs → runGemini-Cc2jq-uh.mjs} +58 -31
- package/dist/{runOpenClaw-D7MlPS5n.mjs → runOpenClaw-CIlCwdW2.mjs} +31 -32
- package/dist/{runOpenClaw-Qqo9j63M.cjs → runOpenClaw-YBwua4Rf.cjs} +64 -65
- package/dist/sandbox-C4gXLP1p.cjs +187 -0
- package/dist/sandbox-CNkwOtHI.mjs +180 -0
- package/dist/selfCheck-CU8xSDsl.cjs +87 -0
- package/dist/selfCheck-hJ6PCh7v.mjs +84 -0
- package/dist/{send-CLhYXNgy.mjs → send-CGHcKZ-w.mjs} +12 -5
- package/dist/{send-4qJTCAYW.cjs → send-DY9Nr-x4.cjs} +16 -9
- package/dist/server-II51Mimf.cjs +407 -0
- package/dist/server-m2b5pamZ.mjs +404 -0
- package/dist/sessionLock-7ePAYDOg.cjs +205 -0
- package/dist/sessionLock-Cw6FmbMv.mjs +197 -0
- package/dist/sessionModeFile-BVCV5f7E.cjs +36 -0
- package/dist/sessionModeFile-CDmDyRkD.mjs +32 -0
- package/dist/sessionOps-C_f1wKOr.mjs +760 -0
- package/dist/sessionOps-DJdExmBy.cjs +783 -0
- package/dist/sessionScanner-CaAHLyNV.mjs +206 -0
- package/dist/sessionScanner-D1goKdd3.cjs +209 -0
- package/dist/{sessions-Bh1pyddi.cjs → sessions-DGs6ALNo.cjs} +37 -28
- package/dist/{sessions-CzIH2rGp.mjs → sessions-DnvmWUel.mjs} +17 -8
- package/dist/setupOfflineReconnection-CVViqZft.mjs +72 -0
- package/dist/setupOfflineReconnection-R7XuR_sj.cjs +74 -0
- package/dist/smallFastModel-BLNgMrwR.mjs +18 -0
- package/dist/smallFastModel-D_uxGMo3.cjs +21 -0
- package/dist/{spawn-CmFOSVdW.cjs → spawn-CXTH7qg1.cjs} +61 -65
- package/dist/{spawn-CPIWlPOM.mjs → spawn-DNYSvFtC.mjs} +35 -40
- package/dist/spawnAgents-BGQiEF-w.cjs +52 -0
- package/dist/spawnAgents-DZzZ9jMI.mjs +45 -0
- package/dist/spawnHappyCLI-BhYj84rv.cjs +66 -0
- package/dist/spawnHappyCLI-cqWQbwsb.mjs +64 -0
- package/dist/specialCommands-BSqhYg5X.mjs +52 -0
- package/dist/specialCommands-DSsTeRej.cjs +54 -0
- package/dist/startFileWatcher-CKKx-8ZO.cjs +71 -0
- package/dist/startFileWatcher-CdegMbJj.mjs +69 -0
- package/dist/startupPlan-BLMbfQIH.cjs +12 -0
- package/dist/startupPlan-DFMyNgAs.mjs +10 -0
- package/dist/streamRelay-BiKw59Cc.cjs +233 -0
- package/dist/streamRelay-FPVbHpbM.mjs +231 -0
- package/dist/sync-CVk4QERO.cjs +71 -0
- package/dist/sync-CxD-w_40.mjs +69 -0
- package/dist/systemPrompt-BygJcmbi.cjs +97 -0
- package/dist/systemPrompt-DmtypUc7.mjs +94 -0
- package/dist/{teams-CEahj4cm.mjs → teams-BOC6nIPL.mjs} +9 -40
- package/dist/{teams-CB1R9-Z9.cjs → teams-BsvpOBfn.cjs} +14 -45
- package/dist/template-BaHAmH2K.cjs +129 -0
- package/dist/template-CiOPa2rd.mjs +121 -0
- package/dist/{terminalTitleSuggest-DKgX3osW.mjs → terminalTitleSuggest-CeKsX_V6.mjs} +1 -9
- package/dist/{terminalTitleSuggest-Dji8I0Jy.cjs → terminalTitleSuggest-DhvRFX3H.cjs} +0 -10
- package/dist/terminals-B_bfC9c2.cjs +250 -0
- package/dist/terminals-Dlg0x3nY.mjs +235 -0
- package/dist/time-BZNdNiIV.mjs +38 -0
- package/dist/time-CNRE4ChD.cjs +42 -0
- package/dist/titleGenerator-CFRhU-xq.cjs +172 -0
- package/dist/titleGenerator-ox6ptCsp.mjs +166 -0
- package/dist/tmuxSocket-B8Yx20sT.mjs +19 -0
- package/dist/tmuxSocket-D-Xt6Vn-.cjs +24 -0
- package/dist/{todo-DqyRI4wP.cjs → todo-B-KB7oAB.cjs} +15 -12
- package/dist/{todo-Cknp5D4U.mjs → todo-C5KBVbUw.mjs} +11 -8
- package/dist/tools-BZabNIid.mjs +177 -0
- package/dist/tools-BmQQUATY.mjs +60 -0
- package/dist/tools-CsSovyNp.cjs +180 -0
- package/dist/tools-lMDra4Pv.cjs +63 -0
- package/dist/trimIdent-4gvk9Wk6.cjs +22 -0
- package/dist/trimIdent-BAjmv_TG.mjs +20 -0
- package/dist/types-CRS-srZK.cjs +66 -0
- package/dist/types-CkqAACXx.mjs +64 -0
- package/dist/uninstall-B1WLtC1d.mjs +47 -0
- package/dist/uninstall-fvA5aWpU.cjs +49 -0
- package/package.json +7 -7
- package/scripts/session_hook_forwarder.cjs +9 -2
- package/dist/agentGuidance-BRDN1NoZ.cjs +0 -2217
- package/dist/agentGuidance-KgvYuF3R.mjs +0 -2145
- package/dist/index-BF6WfgV5.mjs +0 -19624
- package/dist/index-C-JazrMB.mjs +0 -52
- package/dist/index-blDSadUR.cjs +0 -58
- package/dist/index-rH3DrQ5B.cjs +0 -19688
- package/dist/limits-BH5CV5vR.cjs +0 -2683
- package/dist/limits-CjRj8IX5.mjs +0 -2558
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chalk = require('chalk');
|
|
4
|
+
var node_util = require('node:util');
|
|
5
|
+
var configuration = require('./configuration-v9f8LM9T.cjs');
|
|
6
|
+
var node_fs = require('node:fs');
|
|
7
|
+
var path = require('node:path');
|
|
8
|
+
|
|
9
|
+
function sensitiveKey(key) {
|
|
10
|
+
const normalized = key.toLowerCase().replace(/[_\-\s]/g, "");
|
|
11
|
+
return /(token|secret|password|authorization|cookie|credential|apikey|privatekey|encryptionkey|accesskey|claimsecret)/.test(normalized);
|
|
12
|
+
}
|
|
13
|
+
function redactLogString(value) {
|
|
14
|
+
return value.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1[REDACTED]").replace(/([?&](?:token|secret|password|api[_-]?key)=)[^&#\s]+/gi, "$1[REDACTED]").replace(/((?:token|secret|password|api[_-]?key)\s*[=:]\s*)[^\s,;]+/gi, "$1[REDACTED]");
|
|
15
|
+
}
|
|
16
|
+
function redactLogValue(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
17
|
+
if (typeof value === "string") return redactLogString(value);
|
|
18
|
+
if (value === null || typeof value !== "object") return value;
|
|
19
|
+
if (depth >= 6) return "[TRUNCATED]";
|
|
20
|
+
if (seen.has(value)) return "[CIRCULAR]";
|
|
21
|
+
seen.add(value);
|
|
22
|
+
if (value instanceof Error) {
|
|
23
|
+
const error = value;
|
|
24
|
+
return {
|
|
25
|
+
name: error.name,
|
|
26
|
+
message: redactLogString(error.message),
|
|
27
|
+
...typeof error.code === "string" || typeof error.code === "number" ? { code: error.code } : {},
|
|
28
|
+
...typeof (error.status ?? error.response?.status) === "number" ? { status: error.status ?? error.response?.status } : {}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(value)) return value.map((item) => redactLogValue(item, depth + 1, seen));
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const [key, child] of Object.entries(value)) {
|
|
34
|
+
if (sensitiveKey(key)) {
|
|
35
|
+
result[key] = "[REDACTED]";
|
|
36
|
+
} else if (key === "environmentVariables" && child && typeof child === "object") {
|
|
37
|
+
result[key] = { names: Object.keys(child).sort() };
|
|
38
|
+
} else {
|
|
39
|
+
result[key] = redactLogValue(child, depth + 1, seen);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function createTimestampForFilename(date = /* @__PURE__ */ new Date()) {
|
|
46
|
+
return date.toLocaleString("sv-SE", {
|
|
47
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
48
|
+
year: "numeric",
|
|
49
|
+
month: "2-digit",
|
|
50
|
+
day: "2-digit",
|
|
51
|
+
hour: "2-digit",
|
|
52
|
+
minute: "2-digit",
|
|
53
|
+
second: "2-digit"
|
|
54
|
+
}).replace(/[: ]/g, "-").replace(/,/g, "") + "-pid-" + process.pid;
|
|
55
|
+
}
|
|
56
|
+
function createTimestampForLogEntry(date = /* @__PURE__ */ new Date()) {
|
|
57
|
+
return date.toLocaleTimeString("en-US", {
|
|
58
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
59
|
+
hour12: false,
|
|
60
|
+
hour: "2-digit",
|
|
61
|
+
minute: "2-digit",
|
|
62
|
+
second: "2-digit",
|
|
63
|
+
fractionalSecondDigits: 3
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function getSessionLogPath() {
|
|
67
|
+
const timestamp = createTimestampForFilename();
|
|
68
|
+
const filename = configuration.configuration.isDaemonProcess ? `${timestamp}-daemon.log` : `${timestamp}.log`;
|
|
69
|
+
return path.join(configuration.configuration.logsDir, filename);
|
|
70
|
+
}
|
|
71
|
+
function safeRemoteLogUrl(raw) {
|
|
72
|
+
if (!raw) return void 0;
|
|
73
|
+
try {
|
|
74
|
+
const url = new URL(raw);
|
|
75
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
76
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) return void 0;
|
|
77
|
+
if (url.username || url.password || url.search || url.hash || url.pathname !== "/" && url.pathname !== "") return void 0;
|
|
78
|
+
return url.origin;
|
|
79
|
+
} catch {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class Logger {
|
|
84
|
+
constructor(logFilePath = getSessionLogPath()) {
|
|
85
|
+
this.logFilePath = logFilePath;
|
|
86
|
+
const remoteUrl = safeRemoteLogUrl(process.env.HAPPY_SERVER_URL);
|
|
87
|
+
const remoteToken = process.env.DANGEROUSLY_LOG_TO_SERVER_FOR_AI_AUTO_DEBUGGING_TOKEN;
|
|
88
|
+
if (process.env.DANGEROUSLY_LOG_TO_SERVER_FOR_AI_AUTO_DEBUGGING && remoteUrl && remoteToken && Buffer.byteLength(remoteToken) >= 32) {
|
|
89
|
+
this.dangerouslyUnencryptedServerLoggingUrl = remoteUrl;
|
|
90
|
+
this.dangerouslyUnencryptedServerLoggingToken = remoteToken;
|
|
91
|
+
console.log(chalk.yellow("[REMOTE LOGGING] Sending logs to server for AI debugging"));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
dangerouslyUnencryptedServerLoggingUrl;
|
|
95
|
+
dangerouslyUnencryptedServerLoggingToken;
|
|
96
|
+
// Use local timezone for simplicity of locating the logs,
|
|
97
|
+
// in practice you will not need absolute timestamps
|
|
98
|
+
localTimezoneTimestamp() {
|
|
99
|
+
return createTimestampForLogEntry();
|
|
100
|
+
}
|
|
101
|
+
debug(message, ...args) {
|
|
102
|
+
this.logToFile(`[${this.localTimezoneTimestamp()}]`, message, ...args);
|
|
103
|
+
}
|
|
104
|
+
debugLargeJson(message, object, maxStringLength = 100, maxArrayLength = 10) {
|
|
105
|
+
if (!process.env.DEBUG) {
|
|
106
|
+
this.debug(`In production, skipping message inspection`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const truncateStrings = (obj) => {
|
|
110
|
+
if (typeof obj === "string") {
|
|
111
|
+
return obj.length > maxStringLength ? obj.substring(0, maxStringLength) + "... [truncated for logs]" : obj;
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(obj)) {
|
|
114
|
+
const truncatedArray = obj.map((item) => truncateStrings(item)).slice(0, maxArrayLength);
|
|
115
|
+
if (obj.length > maxArrayLength) {
|
|
116
|
+
truncatedArray.push(`... [truncated array for logs up to ${maxArrayLength} items]`);
|
|
117
|
+
}
|
|
118
|
+
return truncatedArray;
|
|
119
|
+
}
|
|
120
|
+
if (obj && typeof obj === "object") {
|
|
121
|
+
const result = {};
|
|
122
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
123
|
+
if (key === "usage") {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
result[key] = truncateStrings(value);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
return obj;
|
|
131
|
+
};
|
|
132
|
+
const truncatedObject = truncateStrings(redactLogValue(object));
|
|
133
|
+
const json = JSON.stringify(truncatedObject, null, 2);
|
|
134
|
+
this.logToFile(`[${this.localTimezoneTimestamp()}]`, redactLogString(message), "\n", json);
|
|
135
|
+
}
|
|
136
|
+
info(message, ...args) {
|
|
137
|
+
this.logToConsole("info", "", message, ...args);
|
|
138
|
+
this.debug(message, args);
|
|
139
|
+
}
|
|
140
|
+
infoDeveloper(message, ...args) {
|
|
141
|
+
this.debug(message, ...args);
|
|
142
|
+
if (process.env.DEBUG) {
|
|
143
|
+
this.logToConsole("info", "[DEV]", message, ...args);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
warn(message, ...args) {
|
|
147
|
+
this.logToConsole("warn", "", message, ...args);
|
|
148
|
+
this.debug(`[WARN] ${message}`, ...args);
|
|
149
|
+
}
|
|
150
|
+
getLogPath() {
|
|
151
|
+
return this.logFilePath;
|
|
152
|
+
}
|
|
153
|
+
logToConsole(level, prefix, message, ...args) {
|
|
154
|
+
message = redactLogString(message);
|
|
155
|
+
args = args.map((arg) => redactLogValue(arg));
|
|
156
|
+
switch (level) {
|
|
157
|
+
case "debug": {
|
|
158
|
+
console.log(chalk.gray(prefix), message, ...args);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
case "error": {
|
|
162
|
+
console.error(chalk.red(prefix), message, ...args);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
case "info": {
|
|
166
|
+
console.log(chalk.blue(prefix), message, ...args);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case "warn": {
|
|
170
|
+
console.log(chalk.yellow(prefix), message, ...args);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
default: {
|
|
174
|
+
this.debug("Unknown log level:", level);
|
|
175
|
+
console.log(chalk.blue(prefix), message, ...args);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async sendToRemoteServer(level, message, ...args) {
|
|
181
|
+
if (!this.dangerouslyUnencryptedServerLoggingUrl) return;
|
|
182
|
+
try {
|
|
183
|
+
await fetch(this.dangerouslyUnencryptedServerLoggingUrl + "/logs-combined-from-cli-and-mobile-for-simple-ai-debugging", {
|
|
184
|
+
method: "POST",
|
|
185
|
+
headers: {
|
|
186
|
+
"Content-Type": "application/json",
|
|
187
|
+
"Authorization": `Bearer ${this.dangerouslyUnencryptedServerLoggingToken}`
|
|
188
|
+
},
|
|
189
|
+
body: JSON.stringify({
|
|
190
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
191
|
+
level,
|
|
192
|
+
message: `${redactLogString(message)} ${args.map((raw) => {
|
|
193
|
+
const safe = redactLogValue(raw);
|
|
194
|
+
return typeof safe === "object" ? JSON.stringify(safe, null, 2) : String(safe);
|
|
195
|
+
}).join(" ")}`,
|
|
196
|
+
source: "cli",
|
|
197
|
+
platform: process.platform
|
|
198
|
+
})
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
logToFile(prefix, message, ...args) {
|
|
204
|
+
const safeMessage = redactLogString(message);
|
|
205
|
+
const safeArgs = args.map((arg) => redactLogValue(arg));
|
|
206
|
+
const logLine = `${prefix} ${safeMessage} ${safeArgs.map(
|
|
207
|
+
(arg) => typeof arg === "string" ? arg : node_util.inspect(arg, { depth: 5, breakLength: 120 })
|
|
208
|
+
).join(" ")}
|
|
209
|
+
`;
|
|
210
|
+
if (this.dangerouslyUnencryptedServerLoggingUrl) {
|
|
211
|
+
let level = "info";
|
|
212
|
+
if (prefix.includes(this.localTimezoneTimestamp())) {
|
|
213
|
+
level = "debug";
|
|
214
|
+
}
|
|
215
|
+
this.sendToRemoteServer(level, safeMessage, ...safeArgs).catch(() => {
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
configuration.appendPrivateFileSync(this.logFilePath, logLine);
|
|
220
|
+
} catch (appendError) {
|
|
221
|
+
if (process.env.DEBUG) {
|
|
222
|
+
console.error("[DEV MODE ONLY THROWING] Failed to append to log file:", appendError);
|
|
223
|
+
throw appendError;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
let logger = new Logger();
|
|
229
|
+
async function listDaemonLogFiles(limit = 50) {
|
|
230
|
+
try {
|
|
231
|
+
const logsDir = configuration.configuration.logsDir;
|
|
232
|
+
if (!node_fs.existsSync(logsDir)) {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
const logs = node_fs.readdirSync(logsDir).filter((file) => file.endsWith("-daemon.log")).map((file) => {
|
|
236
|
+
const fullPath = path.join(logsDir, file);
|
|
237
|
+
const stats = node_fs.statSync(fullPath);
|
|
238
|
+
return { file, path: fullPath, modified: stats.mtime };
|
|
239
|
+
}).sort((a, b) => b.modified.getTime() - a.modified.getTime());
|
|
240
|
+
try {
|
|
241
|
+
const { readDaemonState } = await Promise.resolve().then(function () { return require('./persistence-CBNMzSa8.cjs'); });
|
|
242
|
+
const state = await readDaemonState();
|
|
243
|
+
if (!state) {
|
|
244
|
+
return logs;
|
|
245
|
+
}
|
|
246
|
+
if (state.daemonLogPath && node_fs.existsSync(state.daemonLogPath)) {
|
|
247
|
+
const stats = node_fs.statSync(state.daemonLogPath);
|
|
248
|
+
const persisted = {
|
|
249
|
+
file: path.basename(state.daemonLogPath),
|
|
250
|
+
path: state.daemonLogPath,
|
|
251
|
+
modified: stats.mtime
|
|
252
|
+
};
|
|
253
|
+
const idx = logs.findIndex((l) => l.path === persisted.path);
|
|
254
|
+
if (idx >= 0) {
|
|
255
|
+
const [found] = logs.splice(idx, 1);
|
|
256
|
+
logs.unshift(found);
|
|
257
|
+
} else {
|
|
258
|
+
logs.unshift(persisted);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} catch {
|
|
262
|
+
}
|
|
263
|
+
return logs.slice(0, Math.max(0, limit));
|
|
264
|
+
} catch {
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async function getLatestDaemonLog() {
|
|
269
|
+
const [latest] = await listDaemonLogFiles(1);
|
|
270
|
+
return latest || null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
exports.getLatestDaemonLog = getLatestDaemonLog;
|
|
274
|
+
exports.logger = logger;
|
|
275
|
+
exports.redactLogValue = redactLogValue;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { inspect } from 'node:util';
|
|
3
|
+
import { d as appendPrivateFileSync, c as configuration } from './configuration-DoWFJUPm.mjs';
|
|
4
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
5
|
+
import { join, basename } from 'node:path';
|
|
6
|
+
|
|
7
|
+
function sensitiveKey(key) {
|
|
8
|
+
const normalized = key.toLowerCase().replace(/[_\-\s]/g, "");
|
|
9
|
+
return /(token|secret|password|authorization|cookie|credential|apikey|privatekey|encryptionkey|accesskey|claimsecret)/.test(normalized);
|
|
10
|
+
}
|
|
11
|
+
function redactLogString(value) {
|
|
12
|
+
return value.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1[REDACTED]").replace(/([?&](?:token|secret|password|api[_-]?key)=)[^&#\s]+/gi, "$1[REDACTED]").replace(/((?:token|secret|password|api[_-]?key)\s*[=:]\s*)[^\s,;]+/gi, "$1[REDACTED]");
|
|
13
|
+
}
|
|
14
|
+
function redactLogValue(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
15
|
+
if (typeof value === "string") return redactLogString(value);
|
|
16
|
+
if (value === null || typeof value !== "object") return value;
|
|
17
|
+
if (depth >= 6) return "[TRUNCATED]";
|
|
18
|
+
if (seen.has(value)) return "[CIRCULAR]";
|
|
19
|
+
seen.add(value);
|
|
20
|
+
if (value instanceof Error) {
|
|
21
|
+
const error = value;
|
|
22
|
+
return {
|
|
23
|
+
name: error.name,
|
|
24
|
+
message: redactLogString(error.message),
|
|
25
|
+
...typeof error.code === "string" || typeof error.code === "number" ? { code: error.code } : {},
|
|
26
|
+
...typeof (error.status ?? error.response?.status) === "number" ? { status: error.status ?? error.response?.status } : {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(value)) return value.map((item) => redactLogValue(item, depth + 1, seen));
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [key, child] of Object.entries(value)) {
|
|
32
|
+
if (sensitiveKey(key)) {
|
|
33
|
+
result[key] = "[REDACTED]";
|
|
34
|
+
} else if (key === "environmentVariables" && child && typeof child === "object") {
|
|
35
|
+
result[key] = { names: Object.keys(child).sort() };
|
|
36
|
+
} else {
|
|
37
|
+
result[key] = redactLogValue(child, depth + 1, seen);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createTimestampForFilename(date = /* @__PURE__ */ new Date()) {
|
|
44
|
+
return date.toLocaleString("sv-SE", {
|
|
45
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
46
|
+
year: "numeric",
|
|
47
|
+
month: "2-digit",
|
|
48
|
+
day: "2-digit",
|
|
49
|
+
hour: "2-digit",
|
|
50
|
+
minute: "2-digit",
|
|
51
|
+
second: "2-digit"
|
|
52
|
+
}).replace(/[: ]/g, "-").replace(/,/g, "") + "-pid-" + process.pid;
|
|
53
|
+
}
|
|
54
|
+
function createTimestampForLogEntry(date = /* @__PURE__ */ new Date()) {
|
|
55
|
+
return date.toLocaleTimeString("en-US", {
|
|
56
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
57
|
+
hour12: false,
|
|
58
|
+
hour: "2-digit",
|
|
59
|
+
minute: "2-digit",
|
|
60
|
+
second: "2-digit",
|
|
61
|
+
fractionalSecondDigits: 3
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function getSessionLogPath() {
|
|
65
|
+
const timestamp = createTimestampForFilename();
|
|
66
|
+
const filename = configuration.isDaemonProcess ? `${timestamp}-daemon.log` : `${timestamp}.log`;
|
|
67
|
+
return join(configuration.logsDir, filename);
|
|
68
|
+
}
|
|
69
|
+
function safeRemoteLogUrl(raw) {
|
|
70
|
+
if (!raw) return void 0;
|
|
71
|
+
try {
|
|
72
|
+
const url = new URL(raw);
|
|
73
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
74
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) return void 0;
|
|
75
|
+
if (url.username || url.password || url.search || url.hash || url.pathname !== "/" && url.pathname !== "") return void 0;
|
|
76
|
+
return url.origin;
|
|
77
|
+
} catch {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class Logger {
|
|
82
|
+
constructor(logFilePath = getSessionLogPath()) {
|
|
83
|
+
this.logFilePath = logFilePath;
|
|
84
|
+
const remoteUrl = safeRemoteLogUrl(process.env.HAPPY_SERVER_URL);
|
|
85
|
+
const remoteToken = process.env.DANGEROUSLY_LOG_TO_SERVER_FOR_AI_AUTO_DEBUGGING_TOKEN;
|
|
86
|
+
if (process.env.DANGEROUSLY_LOG_TO_SERVER_FOR_AI_AUTO_DEBUGGING && remoteUrl && remoteToken && Buffer.byteLength(remoteToken) >= 32) {
|
|
87
|
+
this.dangerouslyUnencryptedServerLoggingUrl = remoteUrl;
|
|
88
|
+
this.dangerouslyUnencryptedServerLoggingToken = remoteToken;
|
|
89
|
+
console.log(chalk.yellow("[REMOTE LOGGING] Sending logs to server for AI debugging"));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
dangerouslyUnencryptedServerLoggingUrl;
|
|
93
|
+
dangerouslyUnencryptedServerLoggingToken;
|
|
94
|
+
// Use local timezone for simplicity of locating the logs,
|
|
95
|
+
// in practice you will not need absolute timestamps
|
|
96
|
+
localTimezoneTimestamp() {
|
|
97
|
+
return createTimestampForLogEntry();
|
|
98
|
+
}
|
|
99
|
+
debug(message, ...args) {
|
|
100
|
+
this.logToFile(`[${this.localTimezoneTimestamp()}]`, message, ...args);
|
|
101
|
+
}
|
|
102
|
+
debugLargeJson(message, object, maxStringLength = 100, maxArrayLength = 10) {
|
|
103
|
+
if (!process.env.DEBUG) {
|
|
104
|
+
this.debug(`In production, skipping message inspection`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const truncateStrings = (obj) => {
|
|
108
|
+
if (typeof obj === "string") {
|
|
109
|
+
return obj.length > maxStringLength ? obj.substring(0, maxStringLength) + "... [truncated for logs]" : obj;
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(obj)) {
|
|
112
|
+
const truncatedArray = obj.map((item) => truncateStrings(item)).slice(0, maxArrayLength);
|
|
113
|
+
if (obj.length > maxArrayLength) {
|
|
114
|
+
truncatedArray.push(`... [truncated array for logs up to ${maxArrayLength} items]`);
|
|
115
|
+
}
|
|
116
|
+
return truncatedArray;
|
|
117
|
+
}
|
|
118
|
+
if (obj && typeof obj === "object") {
|
|
119
|
+
const result = {};
|
|
120
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
121
|
+
if (key === "usage") {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
result[key] = truncateStrings(value);
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
return obj;
|
|
129
|
+
};
|
|
130
|
+
const truncatedObject = truncateStrings(redactLogValue(object));
|
|
131
|
+
const json = JSON.stringify(truncatedObject, null, 2);
|
|
132
|
+
this.logToFile(`[${this.localTimezoneTimestamp()}]`, redactLogString(message), "\n", json);
|
|
133
|
+
}
|
|
134
|
+
info(message, ...args) {
|
|
135
|
+
this.logToConsole("info", "", message, ...args);
|
|
136
|
+
this.debug(message, args);
|
|
137
|
+
}
|
|
138
|
+
infoDeveloper(message, ...args) {
|
|
139
|
+
this.debug(message, ...args);
|
|
140
|
+
if (process.env.DEBUG) {
|
|
141
|
+
this.logToConsole("info", "[DEV]", message, ...args);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
warn(message, ...args) {
|
|
145
|
+
this.logToConsole("warn", "", message, ...args);
|
|
146
|
+
this.debug(`[WARN] ${message}`, ...args);
|
|
147
|
+
}
|
|
148
|
+
getLogPath() {
|
|
149
|
+
return this.logFilePath;
|
|
150
|
+
}
|
|
151
|
+
logToConsole(level, prefix, message, ...args) {
|
|
152
|
+
message = redactLogString(message);
|
|
153
|
+
args = args.map((arg) => redactLogValue(arg));
|
|
154
|
+
switch (level) {
|
|
155
|
+
case "debug": {
|
|
156
|
+
console.log(chalk.gray(prefix), message, ...args);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "error": {
|
|
160
|
+
console.error(chalk.red(prefix), message, ...args);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "info": {
|
|
164
|
+
console.log(chalk.blue(prefix), message, ...args);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case "warn": {
|
|
168
|
+
console.log(chalk.yellow(prefix), message, ...args);
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
default: {
|
|
172
|
+
this.debug("Unknown log level:", level);
|
|
173
|
+
console.log(chalk.blue(prefix), message, ...args);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async sendToRemoteServer(level, message, ...args) {
|
|
179
|
+
if (!this.dangerouslyUnencryptedServerLoggingUrl) return;
|
|
180
|
+
try {
|
|
181
|
+
await fetch(this.dangerouslyUnencryptedServerLoggingUrl + "/logs-combined-from-cli-and-mobile-for-simple-ai-debugging", {
|
|
182
|
+
method: "POST",
|
|
183
|
+
headers: {
|
|
184
|
+
"Content-Type": "application/json",
|
|
185
|
+
"Authorization": `Bearer ${this.dangerouslyUnencryptedServerLoggingToken}`
|
|
186
|
+
},
|
|
187
|
+
body: JSON.stringify({
|
|
188
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
189
|
+
level,
|
|
190
|
+
message: `${redactLogString(message)} ${args.map((raw) => {
|
|
191
|
+
const safe = redactLogValue(raw);
|
|
192
|
+
return typeof safe === "object" ? JSON.stringify(safe, null, 2) : String(safe);
|
|
193
|
+
}).join(" ")}`,
|
|
194
|
+
source: "cli",
|
|
195
|
+
platform: process.platform
|
|
196
|
+
})
|
|
197
|
+
});
|
|
198
|
+
} catch (error) {
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
logToFile(prefix, message, ...args) {
|
|
202
|
+
const safeMessage = redactLogString(message);
|
|
203
|
+
const safeArgs = args.map((arg) => redactLogValue(arg));
|
|
204
|
+
const logLine = `${prefix} ${safeMessage} ${safeArgs.map(
|
|
205
|
+
(arg) => typeof arg === "string" ? arg : inspect(arg, { depth: 5, breakLength: 120 })
|
|
206
|
+
).join(" ")}
|
|
207
|
+
`;
|
|
208
|
+
if (this.dangerouslyUnencryptedServerLoggingUrl) {
|
|
209
|
+
let level = "info";
|
|
210
|
+
if (prefix.includes(this.localTimezoneTimestamp())) {
|
|
211
|
+
level = "debug";
|
|
212
|
+
}
|
|
213
|
+
this.sendToRemoteServer(level, safeMessage, ...safeArgs).catch(() => {
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
appendPrivateFileSync(this.logFilePath, logLine);
|
|
218
|
+
} catch (appendError) {
|
|
219
|
+
if (process.env.DEBUG) {
|
|
220
|
+
console.error("[DEV MODE ONLY THROWING] Failed to append to log file:", appendError);
|
|
221
|
+
throw appendError;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
let logger = new Logger();
|
|
227
|
+
async function listDaemonLogFiles(limit = 50) {
|
|
228
|
+
try {
|
|
229
|
+
const logsDir = configuration.logsDir;
|
|
230
|
+
if (!existsSync(logsDir)) {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
const logs = readdirSync(logsDir).filter((file) => file.endsWith("-daemon.log")).map((file) => {
|
|
234
|
+
const fullPath = join(logsDir, file);
|
|
235
|
+
const stats = statSync(fullPath);
|
|
236
|
+
return { file, path: fullPath, modified: stats.mtime };
|
|
237
|
+
}).sort((a, b) => b.modified.getTime() - a.modified.getTime());
|
|
238
|
+
try {
|
|
239
|
+
const { readDaemonState } = await import('./persistence-oET5n61f.mjs');
|
|
240
|
+
const state = await readDaemonState();
|
|
241
|
+
if (!state) {
|
|
242
|
+
return logs;
|
|
243
|
+
}
|
|
244
|
+
if (state.daemonLogPath && existsSync(state.daemonLogPath)) {
|
|
245
|
+
const stats = statSync(state.daemonLogPath);
|
|
246
|
+
const persisted = {
|
|
247
|
+
file: basename(state.daemonLogPath),
|
|
248
|
+
path: state.daemonLogPath,
|
|
249
|
+
modified: stats.mtime
|
|
250
|
+
};
|
|
251
|
+
const idx = logs.findIndex((l) => l.path === persisted.path);
|
|
252
|
+
if (idx >= 0) {
|
|
253
|
+
const [found] = logs.splice(idx, 1);
|
|
254
|
+
logs.unshift(found);
|
|
255
|
+
} else {
|
|
256
|
+
logs.unshift(persisted);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
return logs.slice(0, Math.max(0, limit));
|
|
262
|
+
} catch {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function getLatestDaemonLog() {
|
|
267
|
+
const [latest] = await listDaemonLogFiles(1);
|
|
268
|
+
return latest || null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export { getLatestDaemonLog as g, logger as l, redactLogValue as r };
|