From 55a1711e86283a0306b38b552f3702cb1fd0e421 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Sat, 20 Jun 2026 10:21:52 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=20insights.ts=20?= =?UTF-8?q?=E4=B8=AD=E6=9C=AA=E5=BC=95=E7=94=A8=E7=9A=84=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 deduplicateSessionBranches(全仓零调用,含 JSDoc) - 删除 buildExportData(全仓零调用,原 S3 上传路径实际用 HTML 而非 JSON) - InsightsExport 仅移除 export 关键字(保留类型本体,仍作为内部返回类型) Co-Authored-By: glm-5.2 --- src/commands/insights.ts | 94 +--------------------------------------- 1 file changed, 1 insertion(+), 93 deletions(-) diff --git a/src/commands/insights.ts b/src/commands/insights.ts index 27c7c8c9d..dcf78d496 100644 --- a/src/commands/insights.ts +++ b/src/commands/insights.ts @@ -800,34 +800,6 @@ function logToSessionMeta(log: LogOption): SessionMeta { } } -/** - * Deduplicate conversation branches within the same session. - * - * When a session file has multiple leaf messages (from retries or branching), - * loadAllLogsFromSessionFile produces one LogOption per leaf. Each branch - * shares the same root message, so its duration overlaps with sibling - * branches. This keeps only the branch with the most user messages - * (tie-break by longest duration) per session_id. - */ -export function deduplicateSessionBranches( - entries: Array<{ log: LogOption; meta: SessionMeta }>, -): Array<{ log: LogOption; meta: SessionMeta }> { - const bestBySession = new Map() - for (const entry of entries) { - const id = entry.meta.session_id - const existing = bestBySession.get(id) - if ( - !existing || - entry.meta.user_message_count > existing.meta.user_message_count || - (entry.meta.user_message_count === existing.meta.user_message_count && - entry.meta.duration_minutes > existing.meta.duration_minutes) - ) { - bestBySession.set(id, entry) - } - } - return [...bestBySession.values()] -} - function formatTranscriptForFacets(log: LogOption): string { const lines: string[] = [] const meta = logToSessionMeta(log) @@ -2658,7 +2630,7 @@ function generateHtmlReport( /** * Structured export format for claudescope consumption */ -export type InsightsExport = { +type InsightsExport = { metadata: { username: string generated_at: string @@ -2678,70 +2650,6 @@ export type InsightsExport = { } } -/** - * Build export data from already-computed values. - * Used by background upload to S3. - */ -export function buildExportData( - data: AggregatedData, - insights: InsightResults, - facets: Map, - remoteStats?: { hosts: RemoteHostInfo[]; totalCopied: number }, -): InsightsExport { - const version = typeof MACRO !== 'undefined' ? MACRO.VERSION : 'unknown' - - const remote_hosts_collected = remoteStats?.hosts - .filter(h => h.sessionCount > 0) - .map(h => h.name) - - const facets_summary = { - total: facets.size, - goal_categories: {} as Record, - outcomes: {} as Record, - satisfaction: {} as Record, - friction: {} as Record, - } - for (const f of facets.values()) { - for (const [cat, count] of safeEntries(f.goal_categories)) { - if (count > 0) { - facets_summary.goal_categories[cat] = - (facets_summary.goal_categories[cat] || 0) + count - } - } - facets_summary.outcomes[f.outcome] = - (facets_summary.outcomes[f.outcome] || 0) + 1 - for (const [level, count] of safeEntries(f.user_satisfaction_counts)) { - if (count > 0) { - facets_summary.satisfaction[level] = - (facets_summary.satisfaction[level] || 0) + count - } - } - for (const [type, count] of safeEntries(f.friction_counts)) { - if (count > 0) { - facets_summary.friction[type] = - (facets_summary.friction[type] || 0) + count - } - } - } - - return { - metadata: { - username: process.env.SAFEUSER || process.env.USER || 'unknown', - generated_at: new Date().toISOString(), - claude_code_version: version, - date_range: data.date_range, - session_count: data.total_sessions, - ...(remote_hosts_collected && - remote_hosts_collected.length > 0 && { - remote_hosts_collected, - }), - }, - aggregated_data: data, - insights, - facets_summary, - } -} - // ============================================================================ // Lite Session Scanning // ============================================================================