mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 08:15:53 +00:00
chore: 移除 insights.ts 中未引用的导出
- 删除 deduplicateSessionBranches(全仓零调用,含 JSDoc) - 删除 buildExportData(全仓零调用,原 S3 上传路径实际用 HTML 而非 JSON) - InsightsExport 仅移除 export 关键字(保留类型本体,仍作为内部返回类型) Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
@@ -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<string, { log: LogOption; meta: SessionMeta }>()
|
|
||||||
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 {
|
function formatTranscriptForFacets(log: LogOption): string {
|
||||||
const lines: string[] = []
|
const lines: string[] = []
|
||||||
const meta = logToSessionMeta(log)
|
const meta = logToSessionMeta(log)
|
||||||
@@ -2658,7 +2630,7 @@ function generateHtmlReport(
|
|||||||
/**
|
/**
|
||||||
* Structured export format for claudescope consumption
|
* Structured export format for claudescope consumption
|
||||||
*/
|
*/
|
||||||
export type InsightsExport = {
|
type InsightsExport = {
|
||||||
metadata: {
|
metadata: {
|
||||||
username: string
|
username: string
|
||||||
generated_at: 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<string, SessionFacets>,
|
|
||||||
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<string, number>,
|
|
||||||
outcomes: {} as Record<string, number>,
|
|
||||||
satisfaction: {} as Record<string, number>,
|
|
||||||
friction: {} as Record<string, number>,
|
|
||||||
}
|
|
||||||
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
|
// Lite Session Scanning
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user