@shareai-lab/kode 1.0.79 → 1.0.81
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/package.json +1 -1
- package/src/utils/debugLogger.ts +12 -7
- package/src/utils/log.ts +6 -5
package/package.json
CHANGED
package/src/utils/debugLogger.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, appendFileSync } from 'fs'
|
|
2
2
|
import { join } from 'path'
|
|
3
|
+
import { homedir } from 'os'
|
|
3
4
|
import { randomUUID } from 'crypto'
|
|
4
5
|
import chalk from 'chalk'
|
|
5
|
-
import envPaths from 'env-paths'
|
|
6
6
|
import { PRODUCT_COMMAND } from '../constants/product'
|
|
7
7
|
import { SESSION_ID } from './log'
|
|
8
8
|
import type { Message } from '../types/conversation'
|
|
@@ -60,14 +60,14 @@ const USER_FRIENDLY_LEVELS = new Set([
|
|
|
60
60
|
const STARTUP_TIMESTAMP = new Date().toISOString().replace(/[:.]/g, '-')
|
|
61
61
|
const REQUEST_START_TIME = Date.now()
|
|
62
62
|
|
|
63
|
-
// 路径配置
|
|
64
|
-
const
|
|
63
|
+
// 路径配置 - 统一使用 ~/.kode 目录
|
|
64
|
+
const KODE_DIR = join(homedir(), '.kode')
|
|
65
65
|
function getProjectDir(cwd: string): string {
|
|
66
66
|
return cwd.replace(/[^a-zA-Z0-9]/g, '-')
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
const DEBUG_PATHS = {
|
|
70
|
-
base: () => join(
|
|
70
|
+
base: () => join(KODE_DIR, getProjectDir(process.cwd()), 'debug'),
|
|
71
71
|
detailed: () => join(DEBUG_PATHS.base(), `${STARTUP_TIMESTAMP}-detailed.log`),
|
|
72
72
|
flow: () => join(DEBUG_PATHS.base(), `${STARTUP_TIMESTAMP}-flow.log`),
|
|
73
73
|
api: () => join(DEBUG_PATHS.base(), `${STARTUP_TIMESTAMP}-api.log`),
|
|
@@ -467,11 +467,16 @@ export function logAPIError(context: {
|
|
|
467
467
|
response?: any
|
|
468
468
|
provider?: string
|
|
469
469
|
}) {
|
|
470
|
-
const errorDir = join(
|
|
470
|
+
const errorDir = join(KODE_DIR, 'logs', 'error', 'api')
|
|
471
471
|
|
|
472
472
|
// 确保目录存在
|
|
473
473
|
if (!existsSync(errorDir)) {
|
|
474
|
-
|
|
474
|
+
try {
|
|
475
|
+
mkdirSync(errorDir, { recursive: true })
|
|
476
|
+
} catch (err) {
|
|
477
|
+
console.error('Failed to create error log directory:', err)
|
|
478
|
+
return // Exit early if we can't create the directory
|
|
479
|
+
}
|
|
475
480
|
}
|
|
476
481
|
|
|
477
482
|
// 生成文件名
|
|
@@ -557,7 +562,7 @@ export function logAPIError(context: {
|
|
|
557
562
|
}
|
|
558
563
|
|
|
559
564
|
console.log()
|
|
560
|
-
console.log(chalk.dim(` 📁 Full log:
|
|
565
|
+
console.log(chalk.dim(` 📁 Full log: ${filepath}`))
|
|
561
566
|
console.log(chalk.red('━'.repeat(60)))
|
|
562
567
|
console.log()
|
|
563
568
|
}
|
package/src/utils/log.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from 'fs'
|
|
2
2
|
import { dirname, join } from 'path'
|
|
3
|
+
import { homedir } from 'os'
|
|
3
4
|
import { writeFileSync, readFileSync } from 'fs'
|
|
4
5
|
import { captureException } from '../services/sentry'
|
|
5
6
|
import { randomUUID } from 'crypto'
|
|
6
|
-
import envPaths from 'env-paths'
|
|
7
7
|
import { promises as fsPromises } from 'fs'
|
|
8
8
|
import type { LogOption, SerializedMessage } from '../types/logs'
|
|
9
9
|
import { MACRO } from '../constants/macros'
|
|
@@ -16,17 +16,18 @@ const MAX_IN_MEMORY_ERRORS = 100 // Limit to prevent memory issues
|
|
|
16
16
|
|
|
17
17
|
export const SESSION_ID = randomUUID()
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// 统一使用 ~/.kode 目录
|
|
20
|
+
const KODE_DIR = join(homedir(), '.kode')
|
|
20
21
|
|
|
21
22
|
function getProjectDir(cwd: string): string {
|
|
22
23
|
return cwd.replace(/[^a-zA-Z0-9]/g, '-')
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export const CACHE_PATHS = {
|
|
26
|
-
errors: () => join(
|
|
27
|
-
messages: () => join(
|
|
27
|
+
errors: () => join(KODE_DIR, getProjectDir(process.cwd()), 'errors'),
|
|
28
|
+
messages: () => join(KODE_DIR, getProjectDir(process.cwd()), 'messages'),
|
|
28
29
|
mcpLogs: (serverName: string) =>
|
|
29
|
-
join(
|
|
30
|
+
join(KODE_DIR, getProjectDir(process.cwd()), `mcp-logs-${serverName}`),
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export function dateToFilename(date: Date): string {
|