pybao-cli 1.3.3
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/LICENSE +201 -0
- package/README.md +440 -0
- package/README.zh-CN.md +338 -0
- package/cli-acp.js +82 -0
- package/cli.js +105 -0
- package/dist/REPL-WPV32MTF.js +42 -0
- package/dist/REPL-WPV32MTF.js.map +7 -0
- package/dist/acp-75HO2LBV.js +1357 -0
- package/dist/acp-75HO2LBV.js.map +7 -0
- package/dist/agentsValidate-6Z57ARKC.js +373 -0
- package/dist/agentsValidate-6Z57ARKC.js.map +7 -0
- package/dist/ask-NXXXCGY4.js +125 -0
- package/dist/ask-NXXXCGY4.js.map +7 -0
- package/dist/autoUpdater-PJMGNPUG.js +17 -0
- package/dist/autoUpdater-PJMGNPUG.js.map +7 -0
- package/dist/chunk-27GYWUY2.js +72 -0
- package/dist/chunk-27GYWUY2.js.map +7 -0
- package/dist/chunk-3DFBSQIT.js +23 -0
- package/dist/chunk-3DFBSQIT.js.map +7 -0
- package/dist/chunk-3KNGJX7Q.js +794 -0
- package/dist/chunk-3KNGJX7Q.js.map +7 -0
- package/dist/chunk-3PDD7M4T.js +164 -0
- package/dist/chunk-3PDD7M4T.js.map +7 -0
- package/dist/chunk-3ZNSAB7B.js +515 -0
- package/dist/chunk-3ZNSAB7B.js.map +7 -0
- package/dist/chunk-4SNFQYCY.js +511 -0
- package/dist/chunk-4SNFQYCY.js.map +7 -0
- package/dist/chunk-4XPNRLJG.js +1609 -0
- package/dist/chunk-4XPNRLJG.js.map +7 -0
- package/dist/chunk-5P7HBXTD.js +12 -0
- package/dist/chunk-5P7HBXTD.js.map +7 -0
- package/dist/chunk-6RZIUY5K.js +191 -0
- package/dist/chunk-6RZIUY5K.js.map +7 -0
- package/dist/chunk-6WELHKDA.js +240 -0
- package/dist/chunk-6WELHKDA.js.map +7 -0
- package/dist/chunk-7AAE6EO2.js +145 -0
- package/dist/chunk-7AAE6EO2.js.map +7 -0
- package/dist/chunk-A3BVXXA3.js +47 -0
- package/dist/chunk-A3BVXXA3.js.map +7 -0
- package/dist/chunk-A6PUMROK.js +152 -0
- package/dist/chunk-A6PUMROK.js.map +7 -0
- package/dist/chunk-BH3Y62E3.js +11 -0
- package/dist/chunk-BH3Y62E3.js.map +7 -0
- package/dist/chunk-BJSWTHRM.js +16 -0
- package/dist/chunk-BJSWTHRM.js.map +7 -0
- package/dist/chunk-BQA2EOUU.js +124 -0
- package/dist/chunk-BQA2EOUU.js.map +7 -0
- package/dist/chunk-CZZKRPE2.js +19 -0
- package/dist/chunk-CZZKRPE2.js.map +7 -0
- package/dist/chunk-ERMQRV55.js +24 -0
- package/dist/chunk-ERMQRV55.js.map +7 -0
- package/dist/chunk-HB2P6645.js +34 -0
- package/dist/chunk-HB2P6645.js.map +7 -0
- package/dist/chunk-HIRIJ2LQ.js +1256 -0
- package/dist/chunk-HIRIJ2LQ.js.map +7 -0
- package/dist/chunk-ICTEVBLN.js +735 -0
- package/dist/chunk-ICTEVBLN.js.map +7 -0
- package/dist/chunk-JKGOGSFT.js +128 -0
- package/dist/chunk-JKGOGSFT.js.map +7 -0
- package/dist/chunk-JZDE77EH.js +836 -0
- package/dist/chunk-JZDE77EH.js.map +7 -0
- package/dist/chunk-M624LT6O.js +17 -0
- package/dist/chunk-M624LT6O.js.map +7 -0
- package/dist/chunk-OMELVAJD.js +96 -0
- package/dist/chunk-OMELVAJD.js.map +7 -0
- package/dist/chunk-OUXHGDLH.js +95 -0
- package/dist/chunk-OUXHGDLH.js.map +7 -0
- package/dist/chunk-PCXUZ6AT.js +249 -0
- package/dist/chunk-PCXUZ6AT.js.map +7 -0
- package/dist/chunk-Q24ZGKIE.js +1097 -0
- package/dist/chunk-Q24ZGKIE.js.map +7 -0
- package/dist/chunk-QBHEERCF.js +30254 -0
- package/dist/chunk-QBHEERCF.js.map +7 -0
- package/dist/chunk-QIHB5PYM.js +472 -0
- package/dist/chunk-QIHB5PYM.js.map +7 -0
- package/dist/chunk-RQVLBMP7.js +24 -0
- package/dist/chunk-RQVLBMP7.js.map +7 -0
- package/dist/chunk-SWYJOV5E.js +490 -0
- package/dist/chunk-SWYJOV5E.js.map +7 -0
- package/dist/chunk-T6GVXTNQ.js +21 -0
- package/dist/chunk-T6GVXTNQ.js.map +7 -0
- package/dist/chunk-T7GPUZVK.js +766 -0
- package/dist/chunk-T7GPUZVK.js.map +7 -0
- package/dist/chunk-TXFCNQDE.js +2934 -0
- package/dist/chunk-TXFCNQDE.js.map +7 -0
- package/dist/chunk-UNNVICVU.js +95 -0
- package/dist/chunk-UNNVICVU.js.map +7 -0
- package/dist/chunk-UUNVJZWA.js +515 -0
- package/dist/chunk-UUNVJZWA.js.map +7 -0
- package/dist/chunk-VRGR4ZTQ.js +49 -0
- package/dist/chunk-VRGR4ZTQ.js.map +7 -0
- package/dist/chunk-VTVTEE5N.js +2613 -0
- package/dist/chunk-VTVTEE5N.js.map +7 -0
- package/dist/chunk-WPTPPOYN.js +936 -0
- package/dist/chunk-WPTPPOYN.js.map +7 -0
- package/dist/chunk-XXFY63TM.js +196 -0
- package/dist/chunk-XXFY63TM.js.map +7 -0
- package/dist/chunk-Z3HMXDXP.js +654 -0
- package/dist/chunk-Z3HMXDXP.js.map +7 -0
- package/dist/chunk-ZJGXEWKF.js +138 -0
- package/dist/chunk-ZJGXEWKF.js.map +7 -0
- package/dist/cli-RFYBXM7F.js +3917 -0
- package/dist/cli-RFYBXM7F.js.map +7 -0
- package/dist/commands-YOXMODDO.js +46 -0
- package/dist/commands-YOXMODDO.js.map +7 -0
- package/dist/config-5OPX3H2K.js +81 -0
- package/dist/config-5OPX3H2K.js.map +7 -0
- package/dist/context-THRRBPFP.js +30 -0
- package/dist/context-THRRBPFP.js.map +7 -0
- package/dist/costTracker-ELNBZ2DN.js +19 -0
- package/dist/costTracker-ELNBZ2DN.js.map +7 -0
- package/dist/customCommands-4XOZH44N.js +25 -0
- package/dist/customCommands-4XOZH44N.js.map +7 -0
- package/dist/env-EL4KBHMB.js +22 -0
- package/dist/env-EL4KBHMB.js.map +7 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +7 -0
- package/dist/kodeAgentSessionId-PROTVRBR.js +13 -0
- package/dist/kodeAgentSessionId-PROTVRBR.js.map +7 -0
- package/dist/kodeAgentSessionLoad-UMPV7MC3.js +18 -0
- package/dist/kodeAgentSessionLoad-UMPV7MC3.js.map +7 -0
- package/dist/kodeAgentSessionResume-YJS4FVQM.js +16 -0
- package/dist/kodeAgentSessionResume-YJS4FVQM.js.map +7 -0
- package/dist/kodeAgentStreamJson-3T26CHCP.js +13 -0
- package/dist/kodeAgentStreamJson-3T26CHCP.js.map +7 -0
- package/dist/kodeAgentStreamJsonSession-BZS2VDCY.js +131 -0
- package/dist/kodeAgentStreamJsonSession-BZS2VDCY.js.map +7 -0
- package/dist/kodeAgentStructuredStdio-TNB6U6SP.js +10 -0
- package/dist/kodeAgentStructuredStdio-TNB6U6SP.js.map +7 -0
- package/dist/kodeHooks-VUAWIY2D.js +36 -0
- package/dist/kodeHooks-VUAWIY2D.js.map +7 -0
- package/dist/llm-A3BCM4Q2.js +3118 -0
- package/dist/llm-A3BCM4Q2.js.map +7 -0
- package/dist/llmLazy-ZJSRLZVD.js +15 -0
- package/dist/llmLazy-ZJSRLZVD.js.map +7 -0
- package/dist/loader-HZQBWO74.js +28 -0
- package/dist/loader-HZQBWO74.js.map +7 -0
- package/dist/mcp-XKOJ55B2.js +49 -0
- package/dist/mcp-XKOJ55B2.js.map +7 -0
- package/dist/mentionProcessor-ANYU5MLF.js +211 -0
- package/dist/mentionProcessor-ANYU5MLF.js.map +7 -0
- package/dist/messages-75DL5XBP.js +63 -0
- package/dist/messages-75DL5XBP.js.map +7 -0
- package/dist/model-OPJGJZRC.js +30 -0
- package/dist/model-OPJGJZRC.js.map +7 -0
- package/dist/openai-DT54BAFP.js +29 -0
- package/dist/openai-DT54BAFP.js.map +7 -0
- package/dist/outputStyles-TPFVI52O.js +28 -0
- package/dist/outputStyles-TPFVI52O.js.map +7 -0
- package/dist/package.json +4 -0
- package/dist/pluginRuntime-W74PYSZ4.js +218 -0
- package/dist/pluginRuntime-W74PYSZ4.js.map +7 -0
- package/dist/pluginValidation-FALYRVI2.js +17 -0
- package/dist/pluginValidation-FALYRVI2.js.map +7 -0
- package/dist/prompts-J4TPRMJ3.js +48 -0
- package/dist/prompts-J4TPRMJ3.js.map +7 -0
- package/dist/query-K3QKBVDN.js +50 -0
- package/dist/query-K3QKBVDN.js.map +7 -0
- package/dist/responsesStreaming-HMB74TRD.js +10 -0
- package/dist/responsesStreaming-HMB74TRD.js.map +7 -0
- package/dist/ripgrep-XJGSUBG7.js +17 -0
- package/dist/ripgrep-XJGSUBG7.js.map +7 -0
- package/dist/skillMarketplace-AUGKNCPW.js +37 -0
- package/dist/skillMarketplace-AUGKNCPW.js.map +7 -0
- package/dist/state-DQYRXKTG.js +16 -0
- package/dist/state-DQYRXKTG.js.map +7 -0
- package/dist/theme-MS5HDUBJ.js +14 -0
- package/dist/theme-MS5HDUBJ.js.map +7 -0
- package/dist/toolPermissionContext-GYD5LYFK.js +17 -0
- package/dist/toolPermissionContext-GYD5LYFK.js.map +7 -0
- package/dist/toolPermissionSettings-4MPZVYDR.js +18 -0
- package/dist/toolPermissionSettings-4MPZVYDR.js.map +7 -0
- package/dist/tools-QW6SIJLJ.js +47 -0
- package/dist/tools-QW6SIJLJ.js.map +7 -0
- package/dist/userInput-F2PGBRFU.js +311 -0
- package/dist/userInput-F2PGBRFU.js.map +7 -0
- package/dist/uuid-GYYCQ6QK.js +9 -0
- package/dist/uuid-GYYCQ6QK.js.map +7 -0
- package/dist/yoga.wasm +0 -0
- package/package.json +136 -0
- package/scripts/binary-utils.cjs +62 -0
- package/scripts/cli-acp-wrapper.cjs +82 -0
- package/scripts/cli-wrapper.cjs +105 -0
- package/scripts/postinstall.js +144 -0
- package/yoga.wasm +0 -0
|
@@ -0,0 +1,794 @@
|
|
|
1
|
+
import { createRequire as __pybCreateRequire } from "node:module";
|
|
2
|
+
const require = __pybCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
SESSION_ID
|
|
5
|
+
} from "./chunk-TXFCNQDE.js";
|
|
6
|
+
|
|
7
|
+
// src/utils/log/debugLogger.ts
|
|
8
|
+
import { existsSync, mkdirSync, appendFileSync } from "fs";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
import { homedir } from "os";
|
|
11
|
+
import { format } from "node:util";
|
|
12
|
+
import chalk from "chalk";
|
|
13
|
+
var isDebugMode = () => process.argv.includes("--debug-verbose") || process.argv.includes("--mcp-debug") || process.argv.some(
|
|
14
|
+
(arg) => arg === "--debug" || arg === "-d" || arg.startsWith("--debug=")
|
|
15
|
+
);
|
|
16
|
+
var isVerboseMode = () => process.argv.includes("--verbose");
|
|
17
|
+
var isDebugVerboseMode = () => process.argv.includes("--debug-verbose");
|
|
18
|
+
var TERMINAL_LOG_LEVELS = /* @__PURE__ */ new Set([
|
|
19
|
+
"ERROR" /* ERROR */,
|
|
20
|
+
"WARN" /* WARN */,
|
|
21
|
+
"INFO" /* INFO */,
|
|
22
|
+
"REMINDER" /* REMINDER */
|
|
23
|
+
]);
|
|
24
|
+
var DEBUG_VERBOSE_TERMINAL_LOG_LEVELS = /* @__PURE__ */ new Set([
|
|
25
|
+
"ERROR" /* ERROR */,
|
|
26
|
+
"WARN" /* WARN */,
|
|
27
|
+
"FLOW" /* FLOW */,
|
|
28
|
+
"API" /* API */,
|
|
29
|
+
"STATE" /* STATE */,
|
|
30
|
+
"INFO" /* INFO */,
|
|
31
|
+
"REMINDER" /* REMINDER */
|
|
32
|
+
]);
|
|
33
|
+
var STARTUP_TIMESTAMP = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
34
|
+
var REQUEST_START_TIME = Date.now();
|
|
35
|
+
var KODE_DIR = join(homedir(), ".kode");
|
|
36
|
+
function getProjectDir(cwd) {
|
|
37
|
+
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
38
|
+
}
|
|
39
|
+
var DEBUG_PATHS = {
|
|
40
|
+
base: () => join(KODE_DIR, getProjectDir(process.cwd()), "debug"),
|
|
41
|
+
detailed: () => join(DEBUG_PATHS.base(), `${STARTUP_TIMESTAMP}-detailed.log`),
|
|
42
|
+
flow: () => join(DEBUG_PATHS.base(), `${STARTUP_TIMESTAMP}-flow.log`),
|
|
43
|
+
api: () => join(DEBUG_PATHS.base(), `${STARTUP_TIMESTAMP}-api.log`),
|
|
44
|
+
state: () => join(DEBUG_PATHS.base(), `${STARTUP_TIMESTAMP}-state.log`)
|
|
45
|
+
};
|
|
46
|
+
function ensureDebugDir() {
|
|
47
|
+
const debugDir = DEBUG_PATHS.base();
|
|
48
|
+
if (!existsSync(debugDir)) {
|
|
49
|
+
mkdirSync(debugDir, { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
var currentRequest = null;
|
|
53
|
+
function terminalLog(...args) {
|
|
54
|
+
process.stderr.write(`${format(...args)}
|
|
55
|
+
`);
|
|
56
|
+
}
|
|
57
|
+
function writeToFile(filePath, entry) {
|
|
58
|
+
if (!isDebugMode()) return;
|
|
59
|
+
try {
|
|
60
|
+
ensureDebugDir();
|
|
61
|
+
const logLine = JSON.stringify(
|
|
62
|
+
{
|
|
63
|
+
...entry,
|
|
64
|
+
sessionId: SESSION_ID,
|
|
65
|
+
pid: process.pid,
|
|
66
|
+
uptime: Date.now() - REQUEST_START_TIME
|
|
67
|
+
},
|
|
68
|
+
null,
|
|
69
|
+
2
|
|
70
|
+
) + ",\n";
|
|
71
|
+
appendFileSync(filePath, logLine);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
var recentLogs = /* @__PURE__ */ new Map();
|
|
76
|
+
var LOG_DEDUPE_WINDOW_MS = 5e3;
|
|
77
|
+
function getDedupeKey(level, phase, data) {
|
|
78
|
+
if (phase.startsWith("CONFIG_")) {
|
|
79
|
+
const file = data?.file || "";
|
|
80
|
+
return `${level}:${phase}:${file}`;
|
|
81
|
+
}
|
|
82
|
+
return `${level}:${phase}`;
|
|
83
|
+
}
|
|
84
|
+
function shouldLogWithDedupe(level, phase, data) {
|
|
85
|
+
const key = getDedupeKey(level, phase, data);
|
|
86
|
+
const now = Date.now();
|
|
87
|
+
const lastLogTime = recentLogs.get(key);
|
|
88
|
+
if (!lastLogTime || now - lastLogTime > LOG_DEDUPE_WINDOW_MS) {
|
|
89
|
+
recentLogs.set(key, now);
|
|
90
|
+
for (const [oldKey, oldTime] of recentLogs.entries()) {
|
|
91
|
+
if (now - oldTime > LOG_DEDUPE_WINDOW_MS) {
|
|
92
|
+
recentLogs.delete(oldKey);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
function formatMessages(messages) {
|
|
100
|
+
if (Array.isArray(messages)) {
|
|
101
|
+
const recentMessages = messages.slice(-5);
|
|
102
|
+
return recentMessages.map((msg, index) => {
|
|
103
|
+
const role = msg.role || "unknown";
|
|
104
|
+
let content = "";
|
|
105
|
+
if (typeof msg.content === "string") {
|
|
106
|
+
content = msg.content.length > 300 ? msg.content.substring(0, 300) + "..." : msg.content;
|
|
107
|
+
} else if (typeof msg.content === "object") {
|
|
108
|
+
content = "[complex_content]";
|
|
109
|
+
} else {
|
|
110
|
+
content = String(msg.content || "");
|
|
111
|
+
}
|
|
112
|
+
const totalIndex = messages.length - recentMessages.length + index;
|
|
113
|
+
return `[${totalIndex}] ${chalk.dim(role)}: ${content}`;
|
|
114
|
+
}).join("\n ");
|
|
115
|
+
}
|
|
116
|
+
if (typeof messages === "string") {
|
|
117
|
+
try {
|
|
118
|
+
const parsed = JSON.parse(messages);
|
|
119
|
+
if (Array.isArray(parsed)) {
|
|
120
|
+
return formatMessages(parsed);
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (typeof messages === "string" && messages.length > 200) {
|
|
126
|
+
return messages.substring(0, 200) + "...";
|
|
127
|
+
}
|
|
128
|
+
return typeof messages === "string" ? messages : JSON.stringify(messages);
|
|
129
|
+
}
|
|
130
|
+
function shouldShowInTerminal(level) {
|
|
131
|
+
if (!isDebugMode()) return false;
|
|
132
|
+
if (isDebugVerboseMode()) {
|
|
133
|
+
return DEBUG_VERBOSE_TERMINAL_LOG_LEVELS.has(level);
|
|
134
|
+
}
|
|
135
|
+
return TERMINAL_LOG_LEVELS.has(level);
|
|
136
|
+
}
|
|
137
|
+
function logToTerminal(entry) {
|
|
138
|
+
if (!shouldShowInTerminal(entry.level)) return;
|
|
139
|
+
const { level, phase, data, requestId, elapsed } = entry;
|
|
140
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
|
|
141
|
+
let prefix = "";
|
|
142
|
+
let color = chalk.gray;
|
|
143
|
+
switch (level) {
|
|
144
|
+
case "FLOW" /* FLOW */:
|
|
145
|
+
prefix = "\u{1F504}";
|
|
146
|
+
color = chalk.cyan;
|
|
147
|
+
break;
|
|
148
|
+
case "API" /* API */:
|
|
149
|
+
prefix = "\u{1F310}";
|
|
150
|
+
color = chalk.yellow;
|
|
151
|
+
break;
|
|
152
|
+
case "STATE" /* STATE */:
|
|
153
|
+
prefix = "\u{1F4CA}";
|
|
154
|
+
color = chalk.blue;
|
|
155
|
+
break;
|
|
156
|
+
case "ERROR" /* ERROR */:
|
|
157
|
+
prefix = "\u274C";
|
|
158
|
+
color = chalk.red;
|
|
159
|
+
break;
|
|
160
|
+
case "WARN" /* WARN */:
|
|
161
|
+
prefix = "\u26A0\uFE0F";
|
|
162
|
+
color = chalk.yellow;
|
|
163
|
+
break;
|
|
164
|
+
case "INFO" /* INFO */:
|
|
165
|
+
prefix = "\u2139\uFE0F";
|
|
166
|
+
color = chalk.green;
|
|
167
|
+
break;
|
|
168
|
+
case "TRACE" /* TRACE */:
|
|
169
|
+
prefix = "\u{1F4C8}";
|
|
170
|
+
color = chalk.magenta;
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
prefix = "\u{1F50D}";
|
|
174
|
+
color = chalk.gray;
|
|
175
|
+
}
|
|
176
|
+
const reqId = requestId ? chalk.dim(`[${requestId}]`) : "";
|
|
177
|
+
const elapsedStr = elapsed !== void 0 ? chalk.dim(`+${elapsed}ms`) : "";
|
|
178
|
+
let dataStr = "";
|
|
179
|
+
if (typeof data === "object" && data !== null) {
|
|
180
|
+
if (data.messages) {
|
|
181
|
+
const formattedMessages = formatMessages(data.messages);
|
|
182
|
+
dataStr = JSON.stringify(
|
|
183
|
+
{
|
|
184
|
+
...data,
|
|
185
|
+
messages: `
|
|
186
|
+
${formattedMessages}`
|
|
187
|
+
},
|
|
188
|
+
null,
|
|
189
|
+
2
|
|
190
|
+
);
|
|
191
|
+
} else {
|
|
192
|
+
dataStr = JSON.stringify(data, null, 2);
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
dataStr = typeof data === "string" ? data : JSON.stringify(data);
|
|
196
|
+
}
|
|
197
|
+
terminalLog(
|
|
198
|
+
`${color(`[${timestamp}]`)} ${prefix} ${color(phase)} ${reqId} ${dataStr} ${elapsedStr}`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
function debugLog(level, phase, data, requestId) {
|
|
202
|
+
if (!isDebugMode()) return;
|
|
203
|
+
if (!shouldLogWithDedupe(level, phase, data)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const entry = {
|
|
207
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
208
|
+
level,
|
|
209
|
+
phase,
|
|
210
|
+
data,
|
|
211
|
+
requestId: requestId || currentRequest?.id,
|
|
212
|
+
elapsed: currentRequest ? Date.now() - currentRequest.startTime : void 0
|
|
213
|
+
};
|
|
214
|
+
writeToFile(DEBUG_PATHS.detailed(), entry);
|
|
215
|
+
switch (level) {
|
|
216
|
+
case "FLOW" /* FLOW */:
|
|
217
|
+
writeToFile(DEBUG_PATHS.flow(), entry);
|
|
218
|
+
break;
|
|
219
|
+
case "API" /* API */:
|
|
220
|
+
writeToFile(DEBUG_PATHS.api(), entry);
|
|
221
|
+
break;
|
|
222
|
+
case "STATE" /* STATE */:
|
|
223
|
+
writeToFile(DEBUG_PATHS.state(), entry);
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
logToTerminal(entry);
|
|
227
|
+
}
|
|
228
|
+
var debug = {
|
|
229
|
+
flow: (phase, data, requestId) => debugLog("FLOW" /* FLOW */, phase, data, requestId),
|
|
230
|
+
api: (phase, data, requestId) => debugLog("API" /* API */, phase, data, requestId),
|
|
231
|
+
state: (phase, data, requestId) => debugLog("STATE" /* STATE */, phase, data, requestId),
|
|
232
|
+
info: (phase, data, requestId) => debugLog("INFO" /* INFO */, phase, data, requestId),
|
|
233
|
+
warn: (phase, data, requestId) => debugLog("WARN" /* WARN */, phase, data, requestId),
|
|
234
|
+
error: (phase, data, requestId) => debugLog("ERROR" /* ERROR */, phase, data, requestId),
|
|
235
|
+
trace: (phase, data, requestId) => debugLog("TRACE" /* TRACE */, phase, data, requestId),
|
|
236
|
+
ui: (phase, data, requestId) => debugLog("STATE" /* STATE */, `UI_${phase}`, data, requestId)
|
|
237
|
+
};
|
|
238
|
+
function getCurrentRequest() {
|
|
239
|
+
return currentRequest;
|
|
240
|
+
}
|
|
241
|
+
function markPhase(phase, data) {
|
|
242
|
+
if (!currentRequest) return;
|
|
243
|
+
currentRequest.markPhase(phase);
|
|
244
|
+
debug.flow(`PHASE_${phase.toUpperCase()}`, {
|
|
245
|
+
requestId: currentRequest.id,
|
|
246
|
+
elapsed: currentRequest.getPhaseTime(phase),
|
|
247
|
+
data
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function logAPIError(context) {
|
|
251
|
+
const errorDir = join(KODE_DIR, "logs", "error", "api");
|
|
252
|
+
if (!existsSync(errorDir)) {
|
|
253
|
+
try {
|
|
254
|
+
mkdirSync(errorDir, { recursive: true });
|
|
255
|
+
} catch (err) {
|
|
256
|
+
terminalLog("Failed to create error log directory:", err);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
261
|
+
const sanitizedModel = context.model.replace(/[^a-zA-Z0-9-_]/g, "_");
|
|
262
|
+
const filename = `${sanitizedModel}_${timestamp}.log`;
|
|
263
|
+
const filepath = join(errorDir, filename);
|
|
264
|
+
const fullLogContent = {
|
|
265
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
266
|
+
sessionId: SESSION_ID,
|
|
267
|
+
requestId: getCurrentRequest()?.id,
|
|
268
|
+
model: context.model,
|
|
269
|
+
provider: context.provider,
|
|
270
|
+
endpoint: context.endpoint,
|
|
271
|
+
status: context.status,
|
|
272
|
+
error: context.error,
|
|
273
|
+
request: context.request,
|
|
274
|
+
response: context.response,
|
|
275
|
+
environment: {
|
|
276
|
+
nodeVersion: process.version,
|
|
277
|
+
platform: process.platform,
|
|
278
|
+
cwd: process.cwd()
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
try {
|
|
282
|
+
appendFileSync(filepath, JSON.stringify(fullLogContent, null, 2) + "\n");
|
|
283
|
+
appendFileSync(filepath, "=".repeat(80) + "\n\n");
|
|
284
|
+
} catch (err) {
|
|
285
|
+
terminalLog("Failed to write API error log:", err);
|
|
286
|
+
}
|
|
287
|
+
if (isDebugMode()) {
|
|
288
|
+
debug.error("API_ERROR", {
|
|
289
|
+
model: context.model,
|
|
290
|
+
status: context.status,
|
|
291
|
+
error: typeof context.error === "string" ? context.error : context.error?.message || "Unknown error",
|
|
292
|
+
endpoint: context.endpoint,
|
|
293
|
+
logFile: filename
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
if (isVerboseMode() || isDebugVerboseMode()) {
|
|
297
|
+
terminalLog();
|
|
298
|
+
terminalLog(chalk.red("\u2501".repeat(60)));
|
|
299
|
+
terminalLog(chalk.red.bold("\u26A0\uFE0F API Error"));
|
|
300
|
+
terminalLog(chalk.red("\u2501".repeat(60)));
|
|
301
|
+
terminalLog(chalk.white(" Model: ") + chalk.yellow(context.model));
|
|
302
|
+
terminalLog(chalk.white(" Status: ") + chalk.red(context.status));
|
|
303
|
+
let errorMessage = "Unknown error";
|
|
304
|
+
if (typeof context.error === "string") {
|
|
305
|
+
errorMessage = context.error;
|
|
306
|
+
} else if (context.error?.message) {
|
|
307
|
+
errorMessage = context.error.message;
|
|
308
|
+
} else if (context.error?.error?.message) {
|
|
309
|
+
errorMessage = context.error.error.message;
|
|
310
|
+
}
|
|
311
|
+
terminalLog(chalk.white(" Error: ") + chalk.red(errorMessage));
|
|
312
|
+
if (context.response) {
|
|
313
|
+
terminalLog();
|
|
314
|
+
terminalLog(chalk.gray(" Response:"));
|
|
315
|
+
const responseStr = typeof context.response === "string" ? context.response : JSON.stringify(context.response, null, 2);
|
|
316
|
+
responseStr.split("\n").forEach((line) => {
|
|
317
|
+
terminalLog(chalk.gray(" " + line));
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
terminalLog();
|
|
321
|
+
terminalLog(chalk.dim(` \u{1F4C1} Full log: ${filepath}`));
|
|
322
|
+
terminalLog(chalk.red("\u2501".repeat(60)));
|
|
323
|
+
terminalLog();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function logLLMInteraction(context) {
|
|
327
|
+
if (!isDebugMode()) return;
|
|
328
|
+
const duration = context.timing.end - context.timing.start;
|
|
329
|
+
terminalLog("\n" + chalk.blue("\u{1F9E0} LLM CALL DEBUG"));
|
|
330
|
+
terminalLog(chalk.gray("\u2501".repeat(60)));
|
|
331
|
+
terminalLog(chalk.yellow("\u{1F4CA} Context Overview:"));
|
|
332
|
+
terminalLog(` Messages Count: ${context.messages.length}`);
|
|
333
|
+
terminalLog(` System Prompt Length: ${context.systemPrompt.length} chars`);
|
|
334
|
+
terminalLog(` Duration: ${duration.toFixed(0)}ms`);
|
|
335
|
+
if (context.usage) {
|
|
336
|
+
terminalLog(
|
|
337
|
+
` Token Usage: ${context.usage.inputTokens} \u2192 ${context.usage.outputTokens}`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
const apiLabel = context.apiFormat ? ` (${context.apiFormat.toUpperCase()})` : "";
|
|
341
|
+
terminalLog(chalk.cyan(`
|
|
342
|
+
\u{1F4AC} Real API Messages${apiLabel} (last 10):`));
|
|
343
|
+
const recentMessages = context.messages.slice(-10);
|
|
344
|
+
recentMessages.forEach((msg, index) => {
|
|
345
|
+
const globalIndex = context.messages.length - recentMessages.length + index;
|
|
346
|
+
const roleColor = msg.role === "user" ? "green" : msg.role === "assistant" ? "blue" : msg.role === "system" ? "yellow" : "gray";
|
|
347
|
+
let content = "";
|
|
348
|
+
let isReminder = false;
|
|
349
|
+
if (typeof msg.content === "string") {
|
|
350
|
+
if (msg.content.includes("<system-reminder>")) {
|
|
351
|
+
isReminder = true;
|
|
352
|
+
const reminderContent = msg.content.replace(/<\/?system-reminder>/g, "").trim();
|
|
353
|
+
content = `\u{1F514} ${reminderContent.length > 800 ? reminderContent.substring(0, 800) + "..." : reminderContent}`;
|
|
354
|
+
} else {
|
|
355
|
+
const maxLength = msg.role === "user" ? 1e3 : msg.role === "system" ? 1200 : 800;
|
|
356
|
+
content = msg.content.length > maxLength ? msg.content.substring(0, maxLength) + "..." : msg.content;
|
|
357
|
+
}
|
|
358
|
+
} else if (Array.isArray(msg.content)) {
|
|
359
|
+
const textBlocks = msg.content.filter(
|
|
360
|
+
(block) => block.type === "text"
|
|
361
|
+
);
|
|
362
|
+
const toolBlocks = msg.content.filter(
|
|
363
|
+
(block) => block.type === "tool_use"
|
|
364
|
+
);
|
|
365
|
+
if (textBlocks.length > 0) {
|
|
366
|
+
const text = textBlocks[0].text || "";
|
|
367
|
+
const maxLength = msg.role === "assistant" ? 1e3 : 800;
|
|
368
|
+
content = text.length > maxLength ? text.substring(0, maxLength) + "..." : text;
|
|
369
|
+
}
|
|
370
|
+
if (toolBlocks.length > 0) {
|
|
371
|
+
content += ` [+ ${toolBlocks.length} tool calls]`;
|
|
372
|
+
}
|
|
373
|
+
if (textBlocks.length === 0 && toolBlocks.length === 0) {
|
|
374
|
+
content = `[${msg.content.length} blocks: ${msg.content.map((b) => b.type || "unknown").join(", ")}]`;
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
content = "[complex_content]";
|
|
378
|
+
}
|
|
379
|
+
if (isReminder) {
|
|
380
|
+
terminalLog(
|
|
381
|
+
` [${globalIndex}] ${chalk.magenta("\u{1F514} REMINDER")}: ${chalk.dim(content)}`
|
|
382
|
+
);
|
|
383
|
+
} else {
|
|
384
|
+
const roleIcon = msg.role === "user" ? "\u{1F464}" : msg.role === "assistant" ? "\u{1F916}" : msg.role === "system" ? "\u2699\uFE0F" : "\u{1F4C4}";
|
|
385
|
+
terminalLog(
|
|
386
|
+
` [${globalIndex}] ${chalk[roleColor](roleIcon + " " + msg.role.toUpperCase())}: ${content}`
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
390
|
+
const toolCalls2 = msg.content.filter(
|
|
391
|
+
(block) => block.type === "tool_use"
|
|
392
|
+
);
|
|
393
|
+
if (toolCalls2.length > 0) {
|
|
394
|
+
terminalLog(
|
|
395
|
+
chalk.cyan(
|
|
396
|
+
` \u{1F527} \u2192 Tool calls (${toolCalls2.length}): ${toolCalls2.map((t) => t.name).join(", ")}`
|
|
397
|
+
)
|
|
398
|
+
);
|
|
399
|
+
toolCalls2.forEach((tool, idx) => {
|
|
400
|
+
const inputStr = JSON.stringify(tool.input || {});
|
|
401
|
+
const maxLength = 200;
|
|
402
|
+
const displayInput = inputStr.length > maxLength ? inputStr.substring(0, maxLength) + "..." : inputStr;
|
|
403
|
+
terminalLog(
|
|
404
|
+
chalk.dim(` [${idx}] ${tool.name}: ${displayInput}`)
|
|
405
|
+
);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
410
|
+
terminalLog(
|
|
411
|
+
chalk.cyan(
|
|
412
|
+
` \u{1F527} \u2192 Tool calls (${msg.tool_calls.length}): ${msg.tool_calls.map((t) => t.function.name).join(", ")}`
|
|
413
|
+
)
|
|
414
|
+
);
|
|
415
|
+
msg.tool_calls.forEach((tool, idx) => {
|
|
416
|
+
const inputStr = tool.function.arguments || "{}";
|
|
417
|
+
const maxLength = 200;
|
|
418
|
+
const displayInput = inputStr.length > maxLength ? inputStr.substring(0, maxLength) + "..." : inputStr;
|
|
419
|
+
terminalLog(
|
|
420
|
+
chalk.dim(` [${idx}] ${tool.function.name}: ${displayInput}`)
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
terminalLog(chalk.magenta("\n\u{1F916} LLM Response:"));
|
|
426
|
+
let responseContent = "";
|
|
427
|
+
let toolCalls = [];
|
|
428
|
+
if (Array.isArray(context.response.content)) {
|
|
429
|
+
const textBlocks = context.response.content.filter(
|
|
430
|
+
(block) => block.type === "text"
|
|
431
|
+
);
|
|
432
|
+
responseContent = textBlocks.length > 0 ? textBlocks[0].text || "" : "";
|
|
433
|
+
toolCalls = context.response.content.filter(
|
|
434
|
+
(block) => block.type === "tool_use"
|
|
435
|
+
);
|
|
436
|
+
} else if (typeof context.response.content === "string") {
|
|
437
|
+
responseContent = context.response.content;
|
|
438
|
+
toolCalls = context.response.tool_calls || context.response.toolCalls || [];
|
|
439
|
+
} else if (context.response.message?.content) {
|
|
440
|
+
if (Array.isArray(context.response.message.content)) {
|
|
441
|
+
const textBlocks = context.response.message.content.filter(
|
|
442
|
+
(block) => block.type === "text"
|
|
443
|
+
);
|
|
444
|
+
responseContent = textBlocks.length > 0 ? textBlocks[0].text || "" : "";
|
|
445
|
+
toolCalls = context.response.message.content.filter(
|
|
446
|
+
(block) => block.type === "tool_use"
|
|
447
|
+
);
|
|
448
|
+
} else if (typeof context.response.message.content === "string") {
|
|
449
|
+
responseContent = context.response.message.content;
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
responseContent = JSON.stringify(
|
|
453
|
+
context.response.content || context.response || ""
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
const maxResponseLength = 1e3;
|
|
457
|
+
const displayContent = responseContent.length > maxResponseLength ? responseContent.substring(0, maxResponseLength) + "..." : responseContent;
|
|
458
|
+
terminalLog(` Content: ${displayContent}`);
|
|
459
|
+
if (toolCalls.length > 0) {
|
|
460
|
+
const toolNames = toolCalls.map(
|
|
461
|
+
(t) => t.name || t.function?.name || "unknown"
|
|
462
|
+
);
|
|
463
|
+
terminalLog(
|
|
464
|
+
chalk.cyan(
|
|
465
|
+
` \u{1F527} Tool Calls (${toolCalls.length}): ${toolNames.join(", ")}`
|
|
466
|
+
)
|
|
467
|
+
);
|
|
468
|
+
toolCalls.forEach((tool, index) => {
|
|
469
|
+
const toolName = tool.name || tool.function?.name || "unknown";
|
|
470
|
+
const toolInput = tool.input || tool.function?.arguments || "{}";
|
|
471
|
+
const inputStr = typeof toolInput === "string" ? toolInput : JSON.stringify(toolInput);
|
|
472
|
+
const maxToolInputLength = 300;
|
|
473
|
+
const displayInput = inputStr.length > maxToolInputLength ? inputStr.substring(0, maxToolInputLength) + "..." : inputStr;
|
|
474
|
+
terminalLog(chalk.dim(` [${index}] ${toolName}: ${displayInput}`));
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
terminalLog(
|
|
478
|
+
` Stop Reason: ${context.response.stop_reason || context.response.finish_reason || "unknown"}`
|
|
479
|
+
);
|
|
480
|
+
terminalLog(chalk.gray("\u2501".repeat(60)));
|
|
481
|
+
}
|
|
482
|
+
function logSystemPromptConstruction(construction) {
|
|
483
|
+
if (!isDebugMode()) return;
|
|
484
|
+
terminalLog("\n" + chalk.yellow("\u{1F4DD} SYSTEM PROMPT CONSTRUCTION"));
|
|
485
|
+
terminalLog(` Base Prompt: ${construction.basePrompt.length} chars`);
|
|
486
|
+
if (construction.kodeContext) {
|
|
487
|
+
terminalLog(` + Kode Context: ${construction.kodeContext.length} chars`);
|
|
488
|
+
}
|
|
489
|
+
if (construction.reminders.length > 0) {
|
|
490
|
+
terminalLog(
|
|
491
|
+
` + Dynamic Reminders: ${construction.reminders.length} items`
|
|
492
|
+
);
|
|
493
|
+
construction.reminders.forEach((reminder, index) => {
|
|
494
|
+
terminalLog(chalk.dim(` [${index}] ${reminder.substring(0, 80)}...`));
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
terminalLog(` = Final Length: ${construction.finalPrompt.length} chars`);
|
|
498
|
+
}
|
|
499
|
+
function logUserFriendly(type, data, requestId) {
|
|
500
|
+
if (!isDebugMode()) return;
|
|
501
|
+
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
502
|
+
let message = "";
|
|
503
|
+
let color = chalk.gray;
|
|
504
|
+
let icon = "\u2022";
|
|
505
|
+
switch (type) {
|
|
506
|
+
case "SESSION_START":
|
|
507
|
+
icon = "\u{1F680}";
|
|
508
|
+
color = chalk.green;
|
|
509
|
+
message = `Session started with ${data.model || "default model"}`;
|
|
510
|
+
break;
|
|
511
|
+
case "QUERY_START":
|
|
512
|
+
icon = "\u{1F4AD}";
|
|
513
|
+
color = chalk.blue;
|
|
514
|
+
message = `Processing query: "${data.query?.substring(0, 50)}${data.query?.length > 50 ? "..." : ""}"`;
|
|
515
|
+
break;
|
|
516
|
+
case "QUERY_PROGRESS":
|
|
517
|
+
icon = "\u23F3";
|
|
518
|
+
color = chalk.yellow;
|
|
519
|
+
message = `${data.phase} (${data.elapsed}ms)`;
|
|
520
|
+
break;
|
|
521
|
+
case "QUERY_COMPLETE":
|
|
522
|
+
icon = "\u2705";
|
|
523
|
+
color = chalk.green;
|
|
524
|
+
message = `Query completed in ${data.duration}ms - Cost: $${data.cost} - ${data.tokens} tokens`;
|
|
525
|
+
break;
|
|
526
|
+
case "TOOL_EXECUTION":
|
|
527
|
+
icon = "\u{1F527}";
|
|
528
|
+
color = chalk.cyan;
|
|
529
|
+
message = `${data.toolName}: ${data.action} ${data.target ? "\u2192 " + data.target : ""}`;
|
|
530
|
+
break;
|
|
531
|
+
case "ERROR_OCCURRED":
|
|
532
|
+
icon = "\u274C";
|
|
533
|
+
color = chalk.red;
|
|
534
|
+
message = `${data.error} ${data.context ? "(" + data.context + ")" : ""}`;
|
|
535
|
+
break;
|
|
536
|
+
case "PERFORMANCE_SUMMARY":
|
|
537
|
+
icon = "\u{1F4CA}";
|
|
538
|
+
color = chalk.magenta;
|
|
539
|
+
message = `Session: ${data.queries} queries, $${data.totalCost}, ${data.avgResponseTime}ms avg`;
|
|
540
|
+
break;
|
|
541
|
+
default:
|
|
542
|
+
message = JSON.stringify(data);
|
|
543
|
+
}
|
|
544
|
+
const reqId = requestId ? chalk.dim(`[${requestId.slice(0, 8)}]`) : "";
|
|
545
|
+
terminalLog(`${color(`[${timestamp}]`)} ${icon} ${color(message)} ${reqId}`);
|
|
546
|
+
}
|
|
547
|
+
function initDebugLogger() {
|
|
548
|
+
if (!isDebugMode()) return;
|
|
549
|
+
debug.info("DEBUG_LOGGER_INIT", {
|
|
550
|
+
startupTimestamp: STARTUP_TIMESTAMP,
|
|
551
|
+
sessionId: SESSION_ID,
|
|
552
|
+
debugPaths: {
|
|
553
|
+
detailed: DEBUG_PATHS.detailed(),
|
|
554
|
+
flow: DEBUG_PATHS.flow(),
|
|
555
|
+
api: DEBUG_PATHS.api(),
|
|
556
|
+
state: DEBUG_PATHS.state()
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
const terminalLevels = isDebugVerboseMode() ? Array.from(DEBUG_VERBOSE_TERMINAL_LOG_LEVELS).join(", ") : Array.from(TERMINAL_LOG_LEVELS).join(", ");
|
|
560
|
+
terminalLog(
|
|
561
|
+
chalk.dim(`[DEBUG] Terminal output filtered to: ${terminalLevels}`)
|
|
562
|
+
);
|
|
563
|
+
terminalLog(
|
|
564
|
+
chalk.dim(`[DEBUG] Complete logs saved to: ${DEBUG_PATHS.base()}`)
|
|
565
|
+
);
|
|
566
|
+
if (!isDebugVerboseMode()) {
|
|
567
|
+
terminalLog(
|
|
568
|
+
chalk.dim(
|
|
569
|
+
`[DEBUG] Use --debug-verbose for detailed system logs (FLOW, API, STATE)`
|
|
570
|
+
)
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function diagnoseError(error, context) {
|
|
575
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
576
|
+
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
577
|
+
if (errorMessage.includes("aborted") || errorMessage.includes("AbortController")) {
|
|
578
|
+
return {
|
|
579
|
+
errorType: "REQUEST_ABORTED",
|
|
580
|
+
category: "SYSTEM",
|
|
581
|
+
severity: "MEDIUM",
|
|
582
|
+
description: "Request was aborted, often due to user cancellation or timeout",
|
|
583
|
+
suggestions: [
|
|
584
|
+
"\u68C0\u67E5\u662F\u5426\u6309\u4E0B\u4E86 ESC \u952E\u53D6\u6D88\u8BF7\u6C42",
|
|
585
|
+
"\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u662F\u5426\u7A33\u5B9A",
|
|
586
|
+
"\u9A8C\u8BC1 AbortController \u72B6\u6001: isActive \u548C signal.aborted \u5E94\u8BE5\u4E00\u81F4",
|
|
587
|
+
"\u67E5\u770B\u662F\u5426\u6709\u91CD\u590D\u7684\u8BF7\u6C42\u5BFC\u81F4\u51B2\u7A81"
|
|
588
|
+
],
|
|
589
|
+
debugSteps: [
|
|
590
|
+
"\u4F7F\u7528 --debug-verbose \u6A21\u5F0F\u67E5\u770B\u8BE6\u7EC6\u7684\u8BF7\u6C42\u6D41\u7A0B",
|
|
591
|
+
"\u68C0\u67E5 debug \u65E5\u5FD7\u4E2D\u7684 BINARY_FEEDBACK_* \u4E8B\u4EF6",
|
|
592
|
+
"\u9A8C\u8BC1 REQUEST_START \u548C REQUEST_END \u65E5\u5FD7\u914D\u5BF9",
|
|
593
|
+
"\u67E5\u770B QUERY_ABORTED \u4E8B\u4EF6\u7684\u89E6\u53D1\u539F\u56E0"
|
|
594
|
+
]
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
if (errorMessage.includes("api-key") || errorMessage.includes("authentication") || errorMessage.includes("401")) {
|
|
598
|
+
return {
|
|
599
|
+
errorType: "API_AUTHENTICATION",
|
|
600
|
+
category: "API",
|
|
601
|
+
severity: "HIGH",
|
|
602
|
+
description: "API authentication failed - invalid or missing API key",
|
|
603
|
+
suggestions: [
|
|
604
|
+
"\u8FD0\u884C /login \u91CD\u65B0\u8BBE\u7F6E API \u5BC6\u94A5",
|
|
605
|
+
"\u68C0\u67E5 ~/.kode/ \u914D\u7F6E\u6587\u4EF6\u4E2D\u7684 API \u5BC6\u94A5",
|
|
606
|
+
"\u9A8C\u8BC1 API \u5BC6\u94A5\u662F\u5426\u5DF2\u8FC7\u671F\u6216\u88AB\u64A4\u9500",
|
|
607
|
+
"\u786E\u8BA4\u4F7F\u7528\u7684 provider \u8BBE\u7F6E\u6B63\u786E (anthropic/opendev/bigdream)"
|
|
608
|
+
],
|
|
609
|
+
debugSteps: [
|
|
610
|
+
"\u68C0\u67E5 CONFIG_LOAD \u65E5\u5FD7\u4E2D\u7684 provider \u548C API \u5BC6\u94A5\u72B6\u6001",
|
|
611
|
+
"\u8FD0\u884C kode doctor \u68C0\u67E5\u7CFB\u7EDF\u5065\u5EB7\u72B6\u6001",
|
|
612
|
+
"\u67E5\u770B API_ERROR \u65E5\u5FD7\u4E86\u89E3\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F",
|
|
613
|
+
"\u4F7F\u7528 kode config \u547D\u4EE4\u67E5\u770B\u5F53\u524D\u914D\u7F6E"
|
|
614
|
+
]
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
if (errorMessage.includes("ECONNREFUSED") || errorMessage.includes("ENOTFOUND") || errorMessage.includes("timeout")) {
|
|
618
|
+
return {
|
|
619
|
+
errorType: "NETWORK_CONNECTION",
|
|
620
|
+
category: "NETWORK",
|
|
621
|
+
severity: "HIGH",
|
|
622
|
+
description: "Network connection failed - unable to reach API endpoint",
|
|
623
|
+
suggestions: [
|
|
624
|
+
"\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u662F\u5426\u6B63\u5E38",
|
|
625
|
+
"\u786E\u8BA4\u9632\u706B\u5899\u6CA1\u6709\u963B\u6B62\u76F8\u5173\u7AEF\u53E3",
|
|
626
|
+
"\u68C0\u67E5 proxy \u8BBE\u7F6E\u662F\u5426\u6B63\u786E",
|
|
627
|
+
"\u5C1D\u8BD5\u5207\u6362\u5230\u4E0D\u540C\u7684\u7F51\u7EDC\u73AF\u5883",
|
|
628
|
+
"\u9A8C\u8BC1 baseURL \u914D\u7F6E\u662F\u5426\u6B63\u786E"
|
|
629
|
+
],
|
|
630
|
+
debugSteps: [
|
|
631
|
+
"\u68C0\u67E5 API_REQUEST_START \u548C\u76F8\u5173\u7F51\u7EDC\u65E5\u5FD7",
|
|
632
|
+
"\u67E5\u770B LLM_REQUEST_ERROR \u4E2D\u7684\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F",
|
|
633
|
+
"\u4F7F\u7528 ping \u6216 curl \u6D4B\u8BD5 API \u7AEF\u70B9\u8FDE\u901A\u6027",
|
|
634
|
+
"\u68C0\u67E5\u4F01\u4E1A\u7F51\u7EDC\u662F\u5426\u9700\u8981\u4EE3\u7406\u8BBE\u7F6E"
|
|
635
|
+
]
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (errorMessage.includes("permission") || errorMessage.includes("EACCES") || errorMessage.includes("denied")) {
|
|
639
|
+
return {
|
|
640
|
+
errorType: "PERMISSION_DENIED",
|
|
641
|
+
category: "PERMISSION",
|
|
642
|
+
severity: "MEDIUM",
|
|
643
|
+
description: "Permission denied - insufficient access rights",
|
|
644
|
+
suggestions: [
|
|
645
|
+
"\u68C0\u67E5\u6587\u4EF6\u548C\u76EE\u5F55\u7684\u8BFB\u5199\u6743\u9650",
|
|
646
|
+
"\u786E\u8BA4\u5F53\u524D\u7528\u6237\u6709\u8DB3\u591F\u7684\u7CFB\u7EDF\u6743\u9650",
|
|
647
|
+
"\u67E5\u770B\u662F\u5426\u9700\u8981\u7BA1\u7406\u5458\u6743\u9650\u8FD0\u884C",
|
|
648
|
+
"\u68C0\u67E5\u5DE5\u5177\u6743\u9650\u8BBE\u7F6E\u662F\u5426\u6B63\u786E\u914D\u7F6E"
|
|
649
|
+
],
|
|
650
|
+
debugSteps: [
|
|
651
|
+
"\u67E5\u770B PERMISSION_* \u65E5\u5FD7\u4E86\u89E3\u6743\u9650\u68C0\u67E5\u8FC7\u7A0B",
|
|
652
|
+
"\u68C0\u67E5\u6587\u4EF6\u7CFB\u7EDF\u6743\u9650: ls -la",
|
|
653
|
+
"\u9A8C\u8BC1\u5DE5\u5177\u5BA1\u6279\u72B6\u6001",
|
|
654
|
+
"\u67E5\u770B TOOL_* \u76F8\u5173\u7684\u8C03\u8BD5\u65E5\u5FD7"
|
|
655
|
+
]
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
if (errorMessage.includes("substring is not a function") || errorMessage.includes("content")) {
|
|
659
|
+
return {
|
|
660
|
+
errorType: "RESPONSE_FORMAT",
|
|
661
|
+
category: "API",
|
|
662
|
+
severity: "MEDIUM",
|
|
663
|
+
description: "LLM response format mismatch between different providers",
|
|
664
|
+
suggestions: [
|
|
665
|
+
"\u68C0\u67E5\u5F53\u524D\u4F7F\u7528\u7684 provider \u662F\u5426\u4E0E\u671F\u671B\u4E00\u81F4",
|
|
666
|
+
"\u9A8C\u8BC1\u54CD\u5E94\u683C\u5F0F\u5904\u7406\u903B\u8F91",
|
|
667
|
+
"\u786E\u8BA4\u4E0D\u540C provider \u7684\u54CD\u5E94\u683C\u5F0F\u5DEE\u5F02",
|
|
668
|
+
"\u68C0\u67E5\u662F\u5426\u9700\u8981\u66F4\u65B0\u54CD\u5E94\u89E3\u6790\u4EE3\u7801"
|
|
669
|
+
],
|
|
670
|
+
debugSteps: [
|
|
671
|
+
"\u67E5\u770B LLM_CALL_DEBUG \u4E2D\u7684\u54CD\u5E94\u683C\u5F0F",
|
|
672
|
+
"\u68C0\u67E5 provider \u914D\u7F6E\u548C\u5B9E\u9645\u4F7F\u7528\u7684 API",
|
|
673
|
+
"\u5BF9\u6BD4 Anthropic \u548C OpenAI \u54CD\u5E94\u683C\u5F0F\u5DEE\u5F02",
|
|
674
|
+
"\u9A8C\u8BC1 logLLMInteraction \u51FD\u6570\u7684\u683C\u5F0F\u5904\u7406"
|
|
675
|
+
]
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
if (errorMessage.includes("too long") || errorMessage.includes("context") || errorMessage.includes("token")) {
|
|
679
|
+
return {
|
|
680
|
+
errorType: "CONTEXT_OVERFLOW",
|
|
681
|
+
category: "SYSTEM",
|
|
682
|
+
severity: "MEDIUM",
|
|
683
|
+
description: "Context window exceeded - conversation too long",
|
|
684
|
+
suggestions: [
|
|
685
|
+
"\u8FD0\u884C /compact \u624B\u52A8\u538B\u7F29\u5BF9\u8BDD\u5386\u53F2",
|
|
686
|
+
"\u68C0\u67E5\u81EA\u52A8\u538B\u7F29\u8BBE\u7F6E\u662F\u5426\u6B63\u786E\u914D\u7F6E",
|
|
687
|
+
"\u51CF\u5C11\u5355\u6B21\u8F93\u5165\u7684\u5185\u5BB9\u957F\u5EA6",
|
|
688
|
+
"\u6E05\u7406\u4E0D\u5FC5\u8981\u7684\u4E0A\u4E0B\u6587\u4FE1\u606F"
|
|
689
|
+
],
|
|
690
|
+
debugSteps: [
|
|
691
|
+
"\u67E5\u770B AUTO_COMPACT_* \u65E5\u5FD7\u68C0\u67E5\u538B\u7F29\u89E6\u53D1",
|
|
692
|
+
"\u68C0\u67E5 token \u4F7F\u7528\u91CF\u548C\u9608\u503C",
|
|
693
|
+
"\u67E5\u770B CONTEXT_COMPRESSION \u76F8\u5173\u65E5\u5FD7",
|
|
694
|
+
"\u9A8C\u8BC1\u6A21\u578B\u7684\u6700\u5927 token \u9650\u5236"
|
|
695
|
+
]
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
if (errorMessage.includes("config") || errorMessage.includes("undefined") && context?.configRelated) {
|
|
699
|
+
return {
|
|
700
|
+
errorType: "CONFIGURATION",
|
|
701
|
+
category: "CONFIG",
|
|
702
|
+
severity: "MEDIUM",
|
|
703
|
+
description: "Configuration error - missing or invalid settings",
|
|
704
|
+
suggestions: [
|
|
705
|
+
"\u8FD0\u884C kode config \u68C0\u67E5\u914D\u7F6E\u8BBE\u7F6E",
|
|
706
|
+
"\u5220\u9664\u635F\u574F\u7684\u914D\u7F6E\u6587\u4EF6\u91CD\u65B0\u521D\u59CB\u5316",
|
|
707
|
+
"\u68C0\u67E5 JSON \u914D\u7F6E\u6587\u4EF6\u8BED\u6CD5\u662F\u5426\u6B63\u786E",
|
|
708
|
+
"\u9A8C\u8BC1\u73AF\u5883\u53D8\u91CF\u8BBE\u7F6E"
|
|
709
|
+
],
|
|
710
|
+
debugSteps: [
|
|
711
|
+
"\u67E5\u770B CONFIG_LOAD \u548C CONFIG_SAVE \u65E5\u5FD7",
|
|
712
|
+
"\u68C0\u67E5\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\u548C\u6743\u9650",
|
|
713
|
+
"\u9A8C\u8BC1 JSON \u683C\u5F0F: cat ~/.kode/config.json | jq",
|
|
714
|
+
"\u67E5\u770B\u914D\u7F6E\u7F13\u5B58\u76F8\u5173\u7684\u8C03\u8BD5\u4FE1\u606F"
|
|
715
|
+
]
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
return {
|
|
719
|
+
errorType: "UNKNOWN",
|
|
720
|
+
category: "SYSTEM",
|
|
721
|
+
severity: "MEDIUM",
|
|
722
|
+
description: `Unexpected error: ${errorMessage}`,
|
|
723
|
+
suggestions: [
|
|
724
|
+
"\u91CD\u65B0\u542F\u52A8\u5E94\u7528\u7A0B\u5E8F",
|
|
725
|
+
"\u68C0\u67E5\u7CFB\u7EDF\u8D44\u6E90\u662F\u5426\u5145\u8DB3",
|
|
726
|
+
"\u67E5\u770B\u5B8C\u6574\u7684\u9519\u8BEF\u65E5\u5FD7\u83B7\u53D6\u66F4\u591A\u4FE1\u606F",
|
|
727
|
+
"\u5982\u679C\u95EE\u9898\u6301\u7EED\uFF0C\u8BF7\u62A5\u544A\u6B64\u9519\u8BEF"
|
|
728
|
+
],
|
|
729
|
+
debugSteps: [
|
|
730
|
+
"\u4F7F\u7528 --debug-verbose \u83B7\u53D6\u8BE6\u7EC6\u65E5\u5FD7",
|
|
731
|
+
"\u68C0\u67E5 error.log \u4E2D\u7684\u5B8C\u6574\u9519\u8BEF\u4FE1\u606F",
|
|
732
|
+
"\u67E5\u770B\u7CFB\u7EDF\u8D44\u6E90\u4F7F\u7528\u60C5\u51B5",
|
|
733
|
+
"\u6536\u96C6\u91CD\u73B0\u6B65\u9AA4\u548C\u73AF\u5883\u4FE1\u606F"
|
|
734
|
+
],
|
|
735
|
+
relatedLogs: errorStack ? [errorStack] : void 0
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function logErrorWithDiagnosis(error, context, requestId) {
|
|
739
|
+
if (!isDebugMode()) return;
|
|
740
|
+
const diagnosis = diagnoseError(error, context);
|
|
741
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
742
|
+
debug.error(
|
|
743
|
+
"ERROR_OCCURRED",
|
|
744
|
+
{
|
|
745
|
+
error: errorMessage,
|
|
746
|
+
errorType: diagnosis.errorType,
|
|
747
|
+
category: diagnosis.category,
|
|
748
|
+
severity: diagnosis.severity,
|
|
749
|
+
context
|
|
750
|
+
},
|
|
751
|
+
requestId
|
|
752
|
+
);
|
|
753
|
+
terminalLog("\n" + chalk.red("\u{1F6A8} ERROR DIAGNOSIS"));
|
|
754
|
+
terminalLog(chalk.gray("\u2501".repeat(60)));
|
|
755
|
+
terminalLog(chalk.red(`\u274C ${diagnosis.errorType}`));
|
|
756
|
+
terminalLog(
|
|
757
|
+
chalk.dim(
|
|
758
|
+
`Category: ${diagnosis.category} | Severity: ${diagnosis.severity}`
|
|
759
|
+
)
|
|
760
|
+
);
|
|
761
|
+
terminalLog(`
|
|
762
|
+
${diagnosis.description}`);
|
|
763
|
+
terminalLog(chalk.yellow("\n\u{1F4A1} Recovery Suggestions:"));
|
|
764
|
+
diagnosis.suggestions.forEach((suggestion, index) => {
|
|
765
|
+
terminalLog(` ${index + 1}. ${suggestion}`);
|
|
766
|
+
});
|
|
767
|
+
terminalLog(chalk.cyan("\n\u{1F50D} Debug Steps:"));
|
|
768
|
+
diagnosis.debugSteps.forEach((step, index) => {
|
|
769
|
+
terminalLog(` ${index + 1}. ${step}`);
|
|
770
|
+
});
|
|
771
|
+
if (diagnosis.relatedLogs && diagnosis.relatedLogs.length > 0) {
|
|
772
|
+
terminalLog(chalk.magenta("\n\u{1F4CB} Related Information:"));
|
|
773
|
+
diagnosis.relatedLogs.forEach((log, index) => {
|
|
774
|
+
const truncatedLog = log.length > 200 ? log.substring(0, 200) + "..." : log;
|
|
775
|
+
terminalLog(chalk.dim(` ${truncatedLog}`));
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
const debugPath = DEBUG_PATHS.base();
|
|
779
|
+
terminalLog(chalk.gray(`
|
|
780
|
+
\u{1F4C1} Complete logs: ${debugPath}`));
|
|
781
|
+
terminalLog(chalk.gray("\u2501".repeat(60)));
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
export {
|
|
785
|
+
debug,
|
|
786
|
+
getCurrentRequest,
|
|
787
|
+
markPhase,
|
|
788
|
+
logAPIError,
|
|
789
|
+
logLLMInteraction,
|
|
790
|
+
logSystemPromptConstruction,
|
|
791
|
+
logUserFriendly,
|
|
792
|
+
initDebugLogger,
|
|
793
|
+
logErrorWithDiagnosis
|
|
794
|
+
};
|