1. 修复统计消息上报时的日期格式;2.修复对.cluade目录会话jsonl格式上的理解错误

This commit is contained in:
zbc 2026-05-28 21:42:10 +08:00
parent a96006ae15
commit 53359f91fc
2 changed files with 16 additions and 33 deletions

View File

@ -24,7 +24,7 @@ export function getClaudeConfigHomeDir(): string {
* /Users/linkai/code/csc -Users-linkai-code-csc
*/
export function normalizeProjectPath(dir: string): string {
return dir.replace(/:/, '-').replace(/[/\\]/g, '-')
return dir.replace(/:/g, '-').replace(/[/\\]/g, '-')
}
/**
@ -135,17 +135,14 @@ export async function loadSessionMessages(
}
/**
* ID
* message.uuid message.id
* ID (message.uuid)
*/
export function findMessage(
messages: Record<string, unknown>[],
messageID: string,
): Record<string, unknown> | undefined {
return messages.find(
m =>
m.uuid === messageID ||
(m.message as Record<string, unknown>)?.id === messageID,
m => m.uuid === messageID,
)
}
@ -479,10 +476,7 @@ export async function getLatestSessionInfo(
(msg.session_id as string) ||
(msg.uuid as string) ||
''
const messageId =
(msg.uuid as string) ||
((msg.message as Record<string, unknown>)?.id as string) ||
''
const messageId = (msg.uuid as string) || ''
if (sessionId && messageId) {
latestMsg = { sessionId, messageId, ts }
}

View File

@ -119,7 +119,6 @@ async function processTask(
const repoInfo = await getCachedRepoInfo(task.directory)
// 统计本轮 session 的 conversation 数和 token 使用量
let conversationCount = 0
let upstreamTokens = 0
let downstreamTokens = 0
let startTime = 0
@ -138,7 +137,6 @@ async function processTask(
)
if (conversationUploaded) {
conversationCount = 1
// 提取 messages 中的 token 使用量
for (const msg of messages) {
const usage = (msg.message as Record<string, unknown>)?.usage as
@ -181,13 +179,7 @@ async function processTask(
await uploadStatistics(
{
sessionID: task.sessionID,
directory: task.directory,
sessionCount: 1,
conversationCount,
upstreamTokens,
downstreamTokens,
startTime,
endTime,
directory: task.directory
},
authData,
state,
@ -284,9 +276,15 @@ async function uploadReport(
? 'conversation'
: endpoint === '/raw-store/task-summary'
? 'summary'
: 'commit'
: endpoint === '/raw-store/commit'
? 'commit'
: endpoint === '/raw-store/statistics'
? 'statistics'
: 'unknown'
if (mode === RAW_DUMP_MODE.LOCAL || mode === RAW_DUMP_MODE.BOTH) {
if (type === 'unknown') {
log.warn('unknown endpoint, skipping local dump', { endpoint })
} else if (mode === RAW_DUMP_MODE.LOCAL || mode === RAW_DUMP_MODE.BOTH) {
await writeLocalDump(type, body as Record<string, unknown>)
const b = body as Record<string, unknown>
log.info(`local dump: ${type} saved`, {
@ -575,10 +573,7 @@ export async function uploadConversation(
}
}
const requestID =
((assistant.message as Record<string, unknown>)?.id as string) ||
String(assistant.uuid) ||
payload.messageID
const requestID = String(assistant.uuid) || payload.messageID
log.debug('found assistant message', {
requestID,
model: (assistant.message as Record<string, unknown>)?.model,
@ -825,25 +820,19 @@ export async function uploadCommits(
const STATS_DEDUP_WINDOW_MS = 60 * 60 * 1000 // 同一 session 1 小时内只上报一次 statistics
/**
* YYYY/MM/DD
* YYYY-MM-DD
*/
function formatDateKey(date: Date): string {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}/${month}/${day}`
return `${year}-${month}-${day}`
}
export async function uploadStatistics(
payload: {
sessionID: string
directory: string
sessionCount: number
conversationCount: number
upstreamTokens: number
downstreamTokens: number
startTime: number
endTime: number
},
authData: Awaited<ReturnType<typeof auth>>,
state: Awaited<ReturnType<typeof readState>>,