@bahulam/code 0.1.6 → 0.1.8

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.
Files changed (204) hide show
  1. package/LICENSE +1 -1
  2. package/NOTICE +6 -6
  3. package/README.md +11 -18
  4. package/package.json +11 -11
  5. package/src/agents/loader.mjs +1 -1
  6. package/src/agents/workflow_loader.mjs +2 -2
  7. package/src/auth/{tarang-auth.mjs → bahulam-auth.mjs} +4 -3
  8. package/src/commands/agent.mjs +3 -3
  9. package/src/commands/device.mjs +2 -2
  10. package/src/commands/pair.mjs +2 -2
  11. package/src/commands/remote.mjs +3 -3
  12. package/src/commands/workflow.mjs +5 -5
  13. package/src/config/env.mjs +9 -2
  14. package/src/config/memory-loader.mjs +1 -1
  15. package/src/config/model-catalog-default.json +4 -3
  16. package/src/config/model-catalog.mjs +2 -0
  17. package/src/config/settings.mjs +2 -2
  18. package/src/context/prose-chunker.mjs +162 -5
  19. package/src/core/agent-loop.mjs +17 -0
  20. package/src/core/attachments.mjs +66 -4
  21. package/src/core/backend-url.mjs +11 -12
  22. package/src/core/bundled-runtime.mjs +1 -1
  23. package/src/core/callback-client.mjs +1 -1
  24. package/src/core/headless.mjs +18 -4
  25. package/src/core/jsonl-writer.mjs +18 -18
  26. package/src/core/lint-resolver.mjs +472 -0
  27. package/src/core/local-agent.mjs +40 -8
  28. package/src/core/local-store.mjs +5 -1
  29. package/src/core/mode-selector.mjs +1 -1
  30. package/src/core/output-filter.mjs +22 -26
  31. package/src/core/pricing.mjs +10 -3
  32. package/src/core/project-artifacts.mjs +3 -3
  33. package/src/core/project-context-loader.mjs +9 -9
  34. package/src/core/settings-sync.mjs +1 -1
  35. package/src/core/stagnation.mjs +61 -1
  36. package/src/core/stream-client.mjs +13 -8
  37. package/src/core/system-prompt.mjs +2 -2
  38. package/src/core/tool-executor.mjs +178 -84
  39. package/src/daemon/http-dashboard.mjs +400 -0
  40. package/src/daemon/session-core.mjs +1 -0
  41. package/src/local-service/agent-relay.mjs +868 -0
  42. package/src/local-service/approval-bridge.mjs +222 -0
  43. package/src/local-service/browser.mjs +24 -0
  44. package/src/local-service/command.mjs +155 -0
  45. package/src/local-service/file-access.mjs +393 -0
  46. package/src/local-service/machine.mjs +86 -0
  47. package/src/local-service/paths.mjs +29 -0
  48. package/src/local-service/preview-converters.mjs +260 -0
  49. package/src/local-service/server.mjs +2644 -0
  50. package/src/local-service/session-store.mjs +221 -0
  51. package/src/mcp/client.mjs +4 -4
  52. package/src/onboarding/preflight.mjs +2 -2
  53. package/src/terminal/agents.mjs +2 -2
  54. package/src/terminal/analytics.mjs +2 -6
  55. package/src/terminal/ansi.mjs +11 -3
  56. package/src/terminal/main.mjs +43 -17
  57. package/src/terminal/model-catalog-display.mjs +111 -0
  58. package/src/terminal/repl-format.mjs +4 -1
  59. package/src/terminal/repl-model-form.mjs +81 -14
  60. package/src/terminal/repl-render.mjs +37 -7
  61. package/src/terminal/repl-resume.mjs +2 -2
  62. package/src/terminal/repl-state.mjs +12 -0
  63. package/src/terminal/repl.mjs +248 -70
  64. package/src/terminal/tool-display.mjs +32 -0
  65. package/src/terminal/watch-state.mjs +118 -0
  66. package/src/tools/agent.mjs +2 -2
  67. package/src/tools/analyze-image.mjs +158 -0
  68. package/src/tools/bash.mjs +11 -9
  69. package/src/tools/generate-image.mjs +411 -0
  70. package/src/tools/lint.mjs +24 -43
  71. package/src/tools/project-overview.mjs +12 -12
  72. package/src/tools/registry.mjs +4 -0
  73. package/src/ui/formatter.mjs +2 -2
  74. package/src/ui/icons.mjs +2 -0
  75. package/src/ui/input-dock.mjs +7 -7
  76. package/src/ui/palette.mjs +1 -1
  77. package/src/ui/slash-commands.mjs +4 -6
  78. package/src/ui/spinner.mjs +1 -1
  79. package/src/ui/term.mjs +2 -6
  80. package/src/ui/tool-card.mjs +81 -6
  81. package/pulse/app/activity/page.tsx +0 -190
  82. package/pulse/app/api/activity/route.ts +0 -138
  83. package/pulse/app/api/benchmark/route.ts +0 -113
  84. package/pulse/app/api/benchmarks/route.ts +0 -195
  85. package/pulse/app/api/costs/route.ts +0 -88
  86. package/pulse/app/api/export/route.ts +0 -77
  87. package/pulse/app/api/history/route.ts +0 -11
  88. package/pulse/app/api/import/route.ts +0 -31
  89. package/pulse/app/api/memory/route.ts +0 -50
  90. package/pulse/app/api/plans/route.ts +0 -9
  91. package/pulse/app/api/projects/[slug]/route.ts +0 -96
  92. package/pulse/app/api/projects/route.ts +0 -121
  93. package/pulse/app/api/sessions/[id]/replay/route.ts +0 -20
  94. package/pulse/app/api/sessions/[id]/route.ts +0 -31
  95. package/pulse/app/api/sessions/route.ts +0 -112
  96. package/pulse/app/api/settings/route.ts +0 -14
  97. package/pulse/app/api/stats/route.ts +0 -143
  98. package/pulse/app/api/todos/route.ts +0 -9
  99. package/pulse/app/api/tools/route.ts +0 -160
  100. package/pulse/app/benchmarks/page.tsx +0 -224
  101. package/pulse/app/costs/page.tsx +0 -179
  102. package/pulse/app/export/page.tsx +0 -465
  103. package/pulse/app/favicon.ico +0 -0
  104. package/pulse/app/globals.css +0 -263
  105. package/pulse/app/help/page.tsx +0 -143
  106. package/pulse/app/history/page.tsx +0 -157
  107. package/pulse/app/layout.tsx +0 -46
  108. package/pulse/app/memory/page.tsx +0 -365
  109. package/pulse/app/overview-client.tsx +0 -393
  110. package/pulse/app/page.tsx +0 -14
  111. package/pulse/app/plans/page.tsx +0 -308
  112. package/pulse/app/projects/[slug]/page.tsx +0 -390
  113. package/pulse/app/projects/page.tsx +0 -110
  114. package/pulse/app/sessions/[id]/page.tsx +0 -243
  115. package/pulse/app/sessions/page.tsx +0 -39
  116. package/pulse/app/settings/page.tsx +0 -188
  117. package/pulse/app/todos/page.tsx +0 -211
  118. package/pulse/app/tools/page.tsx +0 -249
  119. package/pulse/cli.js +0 -164
  120. package/pulse/components/activity/day-of-week-chart.tsx +0 -35
  121. package/pulse/components/activity/streak-card.tsx +0 -36
  122. package/pulse/components/costs/cache-efficiency-panel.tsx +0 -76
  123. package/pulse/components/costs/cost-by-project-chart.tsx +0 -48
  124. package/pulse/components/costs/cost-over-time-chart.tsx +0 -95
  125. package/pulse/components/costs/model-token-table.tsx +0 -60
  126. package/pulse/components/global-search.tsx +0 -193
  127. package/pulse/components/keyboard-nav-provider.tsx +0 -23
  128. package/pulse/components/layout/bottom-nav.tsx +0 -53
  129. package/pulse/components/layout/client-layout.tsx +0 -31
  130. package/pulse/components/layout/sidebar-context.tsx +0 -50
  131. package/pulse/components/layout/sidebar.tsx +0 -183
  132. package/pulse/components/layout/top-bar.tsx +0 -121
  133. package/pulse/components/overview/activity-heatmap.tsx +0 -107
  134. package/pulse/components/overview/conversation-table.tsx +0 -148
  135. package/pulse/components/overview/model-breakdown-donut.tsx +0 -95
  136. package/pulse/components/overview/peak-hours-chart.tsx +0 -87
  137. package/pulse/components/overview/project-activity-donut.tsx +0 -96
  138. package/pulse/components/overview/stat-card.tsx +0 -102
  139. package/pulse/components/overview/usage-over-time-chart.tsx +0 -166
  140. package/pulse/components/projects/project-card.tsx +0 -175
  141. package/pulse/components/sessions/replay/assistant-markdown.tsx +0 -94
  142. package/pulse/components/sessions/replay/compaction-card.tsx +0 -25
  143. package/pulse/components/sessions/replay/session-sidebar.tsx +0 -231
  144. package/pulse/components/sessions/replay/token-accumulation-chart.tsx +0 -98
  145. package/pulse/components/sessions/replay/tool-call-badge.tsx +0 -127
  146. package/pulse/components/sessions/replay/turn-cards.tsx +0 -220
  147. package/pulse/components/sessions/replay/user-tool-result.tsx +0 -158
  148. package/pulse/components/sessions/session-badges.tsx +0 -49
  149. package/pulse/components/sessions/session-table.tsx +0 -299
  150. package/pulse/components/theme-provider.tsx +0 -44
  151. package/pulse/components/tools/feature-adoption-table.tsx +0 -58
  152. package/pulse/components/tools/mcp-server-panel.tsx +0 -45
  153. package/pulse/components/tools/tool-ranking-chart.tsx +0 -57
  154. package/pulse/components/tools/version-history-table.tsx +0 -32
  155. package/pulse/components/ui/alert.tsx +0 -66
  156. package/pulse/components/ui/badge.tsx +0 -48
  157. package/pulse/components/ui/breadcrumb.tsx +0 -109
  158. package/pulse/components/ui/button.tsx +0 -64
  159. package/pulse/components/ui/calendar.tsx +0 -220
  160. package/pulse/components/ui/card.tsx +0 -92
  161. package/pulse/components/ui/command.tsx +0 -158
  162. package/pulse/components/ui/dialog.tsx +0 -158
  163. package/pulse/components/ui/input.tsx +0 -21
  164. package/pulse/components/ui/popover.tsx +0 -89
  165. package/pulse/components/ui/progress.tsx +0 -31
  166. package/pulse/components/ui/select.tsx +0 -190
  167. package/pulse/components/ui/separator.tsx +0 -28
  168. package/pulse/components/ui/sheet.tsx +0 -143
  169. package/pulse/components/ui/skeleton.tsx +0 -13
  170. package/pulse/components/ui/table.tsx +0 -116
  171. package/pulse/components/ui/tabs.tsx +0 -91
  172. package/pulse/components/ui/tooltip.tsx +0 -57
  173. package/pulse/components/use-global-keyboard-nav.ts +0 -79
  174. package/pulse/components.json +0 -23
  175. package/pulse/eslint.config.mjs +0 -18
  176. package/pulse/lib/bahulam-paths.ts +0 -23
  177. package/pulse/lib/claude-reader.ts +0 -592
  178. package/pulse/lib/decode.ts +0 -129
  179. package/pulse/lib/pricing.ts +0 -102
  180. package/pulse/lib/replay-parser.ts +0 -165
  181. package/pulse/lib/tool-categories.ts +0 -140
  182. package/pulse/lib/utils.ts +0 -6
  183. package/pulse/next-env.d.ts +0 -6
  184. package/pulse/next.config.ts +0 -16
  185. package/pulse/package.json +0 -45
  186. package/pulse/postcss.config.mjs +0 -7
  187. package/pulse/public/activity.png +0 -0
  188. package/pulse/public/cc-lens.png +0 -0
  189. package/pulse/public/command-k.png +0 -0
  190. package/pulse/public/costs.png +0 -0
  191. package/pulse/public/dashboard-dark.png +0 -0
  192. package/pulse/public/dashboard-white.png +0 -0
  193. package/pulse/public/export.png +0 -0
  194. package/pulse/public/file.svg +0 -1
  195. package/pulse/public/globe.svg +0 -1
  196. package/pulse/public/next.svg +0 -1
  197. package/pulse/public/projects.png +0 -0
  198. package/pulse/public/session-chat.png +0 -0
  199. package/pulse/public/todos.png +0 -0
  200. package/pulse/public/tools.png +0 -0
  201. package/pulse/public/vercel.svg +0 -1
  202. package/pulse/public/window.svg +0 -1
  203. package/pulse/tsconfig.json +0 -34
  204. package/pulse/types/claude.ts +0 -294
@@ -1,20 +0,0 @@
1
- import { NextResponse } from 'next/server'
2
- import { findSessionJSONL } from '@/lib/claude-reader'
3
- import { parseSessionReplay } from '@/lib/replay-parser'
4
-
5
- export const dynamic = 'force-dynamic'
6
-
7
- export async function GET(
8
- _req: Request,
9
- { params }: { params: Promise<{ id: string }> }
10
- ) {
11
- const { id } = await params
12
- const jsonlPath = await findSessionJSONL(id)
13
-
14
- if (!jsonlPath) {
15
- return NextResponse.json({ error: 'Session JSONL not found' }, { status: 404 })
16
- }
17
-
18
- const replay = await parseSessionReplay(jsonlPath, id)
19
- return NextResponse.json(replay)
20
- }
@@ -1,31 +0,0 @@
1
- import { NextResponse } from 'next/server'
2
- import { readSessionMeta, readFacet, getSessions } from '@/lib/claude-reader'
3
- import { estimateCostFromUsage } from '@/lib/pricing'
4
-
5
- export const dynamic = 'force-dynamic'
6
-
7
- export async function GET(
8
- _req: Request,
9
- { params }: { params: Promise<{ id: string }> }
10
- ) {
11
- const { id } = await params
12
- const [meta, facet] = await Promise.all([readSessionMeta(id), readFacet(id)])
13
-
14
- // readSessionMeta only finds session-meta/*.json files (legacy path).
15
- // Fall back to JSONL-derived sessions for machines without that directory.
16
- const resolved = meta ?? (await getSessions()).find(s => s.session_id === id) ?? null
17
-
18
- if (!resolved) {
19
- return NextResponse.json({ error: 'Session not found' }, { status: 404 })
20
- }
21
-
22
- const estimated_cost = estimateCostFromUsage('claude-opus-4-6', {
23
- input_tokens: resolved.input_tokens ?? 0,
24
- output_tokens: resolved.output_tokens ?? 0,
25
- cache_creation_input_tokens: resolved.cache_creation_input_tokens ?? 0,
26
- cache_read_input_tokens: resolved.cache_read_input_tokens ?? 0,
27
- })
28
-
29
- return NextResponse.json({ session: { ...resolved, facet, estimated_cost } })
30
- }
31
-
@@ -1,112 +0,0 @@
1
- import path from 'path'
2
- import { NextResponse } from 'next/server'
3
- import {
4
- getSessions,
5
- readAllSessionMeta,
6
- readAllFacets,
7
- listProjectSlugs,
8
- listProjectJSONLFiles,
9
- readJSONLLines,
10
- } from '@/lib/claude-reader'
11
- import { estimateCostFromUsage } from '@/lib/pricing'
12
- import type { SessionWithFacet } from '@/types/claude'
13
-
14
- export const dynamic = 'force-dynamic'
15
-
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- type AnyLine = Record<string, any>
18
-
19
- async function enrichSessions(sessions: { session_id: string }[]) {
20
- // Build a map of sessionId -> { slug, version, gitBranch, has_compaction, has_thinking }
21
- const enrichment: Record<string, {
22
- slug?: string
23
- version?: string
24
- git_branch?: string
25
- has_compaction?: boolean
26
- has_thinking?: boolean
27
- }> = {}
28
-
29
- const slugs = await listProjectSlugs()
30
- await Promise.all(
31
- slugs.map(async (slug) => {
32
- const files = await listProjectJSONLFiles(slug)
33
- await Promise.all(
34
- files.map(async (f) => {
35
- const sessionId = path.basename(f, '.jsonl')
36
- const data: {
37
- slug?: string; version?: string; gitBranch?: string
38
- has_compaction?: boolean; has_thinking?: boolean
39
- } = {}
40
-
41
- await readJSONLLines(f, (line: AnyLine) => {
42
- if (!data.slug && line.slug) data.slug = line.slug
43
- if (!data.version && line.version) data.version = line.version
44
- if (!data.gitBranch && line.gitBranch && line.gitBranch !== 'HEAD') {
45
- data.gitBranch = line.gitBranch
46
- }
47
- if (line.type === 'system' && line.subtype === 'compact_boundary') {
48
- data.has_compaction = true
49
- }
50
- if (line.type === 'assistant' && Array.isArray(line.message?.content)) {
51
- if (line.message.content.some((c: AnyLine) => c.type === 'thinking')) {
52
- data.has_thinking = true
53
- }
54
- }
55
- })
56
-
57
- enrichment[sessionId] = {
58
- slug: data.slug,
59
- version: data.version,
60
- git_branch: data.gitBranch,
61
- has_compaction: data.has_compaction,
62
- has_thinking: data.has_thinking,
63
- }
64
- })
65
- )
66
- })
67
- )
68
- return enrichment
69
- }
70
-
71
- export async function GET() {
72
- const [sessions, metaSessions, facets] = await Promise.all([
73
- getSessions(),
74
- readAllSessionMeta(),
75
- readAllFacets(),
76
- ])
77
- const metaMap = new Map(metaSessions.map((s) => [s.session_id, s]))
78
- const merged = sessions.map((s) => {
79
- const meta = metaMap.get(s.session_id)
80
- if (meta) return { ...meta, ...s } as typeof s
81
- return s
82
- })
83
- const enrichment = await enrichSessions(merged)
84
-
85
- const facetMap = new Map(facets.map(f => [f.session_id, f]))
86
-
87
- const result: SessionWithFacet[] = merged.map(s => {
88
- const facet = facetMap.get(s.session_id)
89
- const enrich = enrichment[s.session_id] ?? {}
90
-
91
- // Estimate cost from session tokens (rough: treat all as opus)
92
- const estimated_cost = estimateCostFromUsage('claude-opus-4-6', {
93
- input_tokens: s.input_tokens ?? 0,
94
- output_tokens: s.output_tokens ?? 0,
95
- cache_creation_input_tokens: s.cache_creation_input_tokens ?? 0,
96
- cache_read_input_tokens: s.cache_read_input_tokens ?? 0,
97
- })
98
-
99
- return {
100
- ...s,
101
- facet,
102
- estimated_cost,
103
- slug: enrich.slug,
104
- version: enrich.version,
105
- git_branch: enrich.git_branch,
106
- has_compaction: enrich.has_compaction ?? false,
107
- has_thinking: enrich.has_thinking ?? false,
108
- }
109
- })
110
-
111
- return NextResponse.json({ sessions: result, total: result.length })
112
- }
@@ -1,14 +0,0 @@
1
- import { NextResponse } from 'next/server'
2
- import { readSettings, getClaudeStorageBytes, readSkills, readInstalledPlugins } from '@/lib/claude-reader'
3
-
4
- export const dynamic = 'force-dynamic'
5
-
6
- export async function GET() {
7
- const [settings, storageBytes, skills, plugins] = await Promise.all([
8
- readSettings(),
9
- getClaudeStorageBytes(),
10
- readSkills(),
11
- readInstalledPlugins(),
12
- ])
13
- return NextResponse.json({ settings, storageBytes, skills, plugins })
14
- }
@@ -1,143 +0,0 @@
1
- import { NextResponse } from 'next/server'
2
- import { readStatsCache, getSessions, getClaudeStorageBytes } from '@/lib/claude-reader'
3
- import { estimateTotalCostFromModel, getPricing } from '@/lib/pricing'
4
- import type { DailyActivity, SessionMeta } from '@/types/claude'
5
-
6
- export const dynamic = 'force-dynamic'
7
-
8
- /** Compute daily activity from session JSONL — fresher than stats-cache */
9
- function computeDailyActivityFromSessions(sessions: SessionMeta[]): DailyActivity[] {
10
- const byDate = new Map<string, { messages: number; sessions: number; tools: number }>()
11
- for (const s of sessions) {
12
- const date = s.start_time.slice(0, 10)
13
- if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) continue
14
- const existing = byDate.get(date) ?? { messages: 0, sessions: 0, tools: 0 }
15
- existing.messages += (s.user_message_count ?? 0) + (s.assistant_message_count ?? 0)
16
- existing.sessions += 1
17
- existing.tools += Object.values(s.tool_counts ?? {}).reduce((a, b) => a + b, 0)
18
- byDate.set(date, existing)
19
- }
20
- return Array.from(byDate.entries())
21
- .map(([date, { messages, sessions: count, tools }]) => ({
22
- date,
23
- messageCount: messages,
24
- sessionCount: count,
25
- toolCallCount: tools,
26
- }))
27
- .sort((a, b) => a.date.localeCompare(b.date))
28
- }
29
-
30
- /** Merge stats dailyActivity with session-derived data; session data overrides for same dates */
31
- function mergeDailyActivity(
32
- fromStats: DailyActivity[],
33
- fromSessions: DailyActivity[]
34
- ): DailyActivity[] {
35
- const map = new Map<string, DailyActivity>()
36
- for (const d of fromStats) map.set(d.date, d)
37
- for (const d of fromSessions) map.set(d.date, d)
38
- return Array.from(map.values()).sort((a, b) => a.date.localeCompare(b.date))
39
- }
40
-
41
- export async function GET() {
42
- const [stats, sessions, storageBytes] = await Promise.all([
43
- readStatsCache(),
44
- getSessions(),
45
- getClaudeStorageBytes(),
46
- ])
47
-
48
- const dailyFromSessions = computeDailyActivityFromSessions(sessions)
49
- const dailyActivity = stats
50
- ? mergeDailyActivity(stats.dailyActivity ?? [], dailyFromSessions)
51
- : dailyFromSessions
52
-
53
- const modelUsage = stats?.modelUsage ?? {}
54
-
55
- // Compute estimated total cost from modelUsage
56
- let totalCost = 0
57
- let totalCacheSavings = 0
58
- for (const [model, usage] of Object.entries(modelUsage)) {
59
- const cost = estimateTotalCostFromModel(model, usage)
60
- totalCost += cost
61
- const p = getPricing(model)
62
- totalCacheSavings += (usage.cacheReadInputTokens ?? 0) * (p.input - p.cacheRead)
63
- }
64
-
65
- // Compute total tokens
66
- let totalInputTokens = 0
67
- let totalOutputTokens = 0
68
- let totalCacheReadTokens = 0
69
- let totalCacheWriteTokens = 0
70
- for (const usage of Object.values(modelUsage)) {
71
- totalInputTokens += usage.inputTokens ?? 0
72
- totalOutputTokens += usage.outputTokens ?? 0
73
- totalCacheReadTokens += usage.cacheReadInputTokens ?? 0
74
- totalCacheWriteTokens += usage.cacheCreationInputTokens ?? 0
75
- }
76
- const totalTokens = totalInputTokens + totalOutputTokens + totalCacheReadTokens + totalCacheWriteTokens
77
-
78
- // Aggregate tool calls total
79
- let totalToolCalls = 0
80
- for (const s of sessions) {
81
- for (const count of Object.values(s.tool_counts ?? {})) {
82
- totalToolCalls += count
83
- }
84
- }
85
-
86
- // Active days (days with at least 1 session)
87
- const activeDays = dailyActivity.filter(d => d.sessionCount > 0).length
88
-
89
- // Average session length
90
- const avgSessionMinutes =
91
- sessions.length > 0
92
- ? sessions.reduce((sum, s) => sum + (s.duration_minutes ?? 0), 0) / sessions.length
93
- : 0
94
-
95
- // Sessions this month & week
96
- const now = new Date()
97
- const monthStart = new Date(now.getFullYear(), now.getMonth(), 1)
98
- const weekStart = new Date(now)
99
- weekStart.setDate(now.getDate() - 7)
100
-
101
- const sessionsThisMonth = sessions.filter(
102
- s => new Date(s.start_time) >= monthStart
103
- ).length
104
- const sessionsThisWeek = sessions.filter(
105
- s => new Date(s.start_time) >= weekStart
106
- ).length
107
-
108
- const statsOut = stats
109
- ? { ...stats, dailyActivity }
110
- : {
111
- version: 0,
112
- lastComputedDate: '',
113
- dailyActivity,
114
- tokensByDate: [],
115
- modelUsage: {},
116
- totalSessions: sessions.length,
117
- totalMessages: sessions.reduce((s, m) => s + (m.user_message_count ?? 0) + (m.assistant_message_count ?? 0), 0),
118
- longestSession: { sessionId: '', duration: 0, messageCount: 0, timestamp: '' },
119
- firstSessionDate: sessions[sessions.length - 1]?.start_time ?? '',
120
- hourCounts: {},
121
- totalSpeculationTimeSavedMs: 0,
122
- }
123
-
124
- return NextResponse.json({
125
- stats: statsOut,
126
- computed: {
127
- totalCost,
128
- totalCacheSavings,
129
- totalTokens,
130
- totalInputTokens,
131
- totalOutputTokens,
132
- totalCacheReadTokens,
133
- totalCacheWriteTokens,
134
- totalToolCalls,
135
- activeDays,
136
- avgSessionMinutes,
137
- sessionsThisMonth,
138
- sessionsThisWeek,
139
- storageBytes,
140
- sessionCount: sessions.length,
141
- },
142
- })
143
- }
@@ -1,9 +0,0 @@
1
- import { NextResponse } from 'next/server'
2
- import { readTodos } from '@/lib/claude-reader'
3
-
4
- export const dynamic = 'force-dynamic'
5
-
6
- export async function GET() {
7
- const todos = await readTodos()
8
- return NextResponse.json({ todos })
9
- }
@@ -1,160 +0,0 @@
1
- import path from 'path'
2
- import { NextResponse } from 'next/server'
3
- import { getSessions, listProjectSlugs, listProjectJSONLFiles, readJSONLLines } from '@/lib/claude-reader'
4
- import { categorizeTool, isMcpTool, parseMcpTool } from '@/lib/tool-categories'
5
- import type { ToolsAnalytics, ToolSummary, McpServerSummary, VersionRecord } from '@/types/claude'
6
-
7
- export const dynamic = 'force-dynamic'
8
-
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- type AnyLine = Record<string, any>
11
-
12
- export async function GET() {
13
- const sessions = await getSessions()
14
- const totalSessions = sessions.length
15
-
16
- // ── Aggregate tool counts across all sessions ──────────────────────────────
17
- const toolTotals = new Map<string, number>()
18
- const toolSessionCount = new Map<string, Set<string>>()
19
- const mcpServerCalls = new Map<string, Map<string, number>>()
20
- const mcpServerSessions = new Map<string, Set<string>>()
21
- const errorCategories: Record<string, number> = {}
22
- let totalErrors = 0
23
-
24
- for (const s of sessions) {
25
- const sid = s.session_id
26
- for (const [tool, count] of Object.entries(s.tool_counts ?? {})) {
27
- toolTotals.set(tool, (toolTotals.get(tool) ?? 0) + count)
28
- if (!toolSessionCount.has(tool)) toolSessionCount.set(tool, new Set())
29
- toolSessionCount.get(tool)!.add(sid)
30
-
31
- if (isMcpTool(tool)) {
32
- const parsed = parseMcpTool(tool)
33
- if (parsed) {
34
- if (!mcpServerCalls.has(parsed.server)) mcpServerCalls.set(parsed.server, new Map())
35
- if (!mcpServerSessions.has(parsed.server)) mcpServerSessions.set(parsed.server, new Set())
36
- const srv = mcpServerCalls.get(parsed.server)!
37
- srv.set(parsed.tool, (srv.get(parsed.tool) ?? 0) + count)
38
- mcpServerSessions.get(parsed.server)!.add(sid)
39
- }
40
- }
41
- }
42
-
43
- // Error categories
44
- for (const [cat, count] of Object.entries(s.tool_error_categories ?? {})) {
45
- errorCategories[cat] = (errorCategories[cat] ?? 0) + count
46
- totalErrors += count
47
- }
48
- }
49
-
50
- // ── Build ToolSummary list ─────────────────────────────────────────────────
51
- const tools: ToolSummary[] = [...toolTotals.entries()]
52
- .map(([name, total_calls]) => ({
53
- name,
54
- category: categorizeTool(name),
55
- total_calls,
56
- session_count: toolSessionCount.get(name)?.size ?? 0,
57
- error_count: 0,
58
- }))
59
- .sort((a, b) => b.total_calls - a.total_calls)
60
-
61
- const totalToolCalls = tools.reduce((s, t) => s + t.total_calls, 0)
62
-
63
- // ── MCP server summaries ───────────────────────────────────────────────────
64
- const mcp_servers: McpServerSummary[] = [...mcpServerCalls.entries()]
65
- .map(([server_name, toolMap]) => {
66
- const toolArr = [...toolMap.entries()]
67
- .map(([name, calls]) => ({ name, calls }))
68
- .sort((a, b) => b.calls - a.calls)
69
- const total_calls = toolArr.reduce((s, t) => s + t.calls, 0)
70
- return {
71
- server_name,
72
- tools: toolArr,
73
- total_calls,
74
- session_count: mcpServerSessions.get(server_name)?.size ?? 0,
75
- }
76
- })
77
- .sort((a, b) => b.total_calls - a.total_calls)
78
-
79
- // ── Feature adoption ──────────────────────────────────────────────────────
80
- const featureSessions = {
81
- task_agents: sessions.filter(s => s.uses_task_agent || (s.tool_counts?.Task ?? 0) > 0).length,
82
- mcp: sessions.filter(s => s.uses_mcp || Object.keys(s.tool_counts ?? {}).some(isMcpTool)).length,
83
- web_search: sessions.filter(s => s.uses_web_search || (s.tool_counts?.WebSearch ?? 0) > 0).length,
84
- web_fetch: sessions.filter(s => s.uses_web_fetch || (s.tool_counts?.WebFetch ?? 0) > 0).length,
85
- plan_mode: sessions.filter(s => (s.tool_counts?.EnterPlanMode ?? 0) > 0).length,
86
- git_commits: sessions.filter(s => (s.git_commits ?? 0) > 0).length,
87
- }
88
-
89
- const feature_adoption: Record<string, { sessions: number; pct: number }> = {}
90
- for (const [key, count] of Object.entries(featureSessions)) {
91
- feature_adoption[key] = { sessions: count, pct: totalSessions > 0 ? count / totalSessions : 0 }
92
- }
93
-
94
- // ── Version + branch info from JSONL ─────────────────────────────────────
95
- const versionData = new Map<string, { sessions: Set<string>; dates: string[] }>()
96
- const branchTurns = new Map<string, number>()
97
-
98
- const slugs = await listProjectSlugs()
99
- await Promise.all(
100
- slugs.map(async (slug) => {
101
- const files = await listProjectJSONLFiles(slug)
102
- await Promise.all(
103
- files.map(async (f) => {
104
- const sessionId = path.basename(f, '.jsonl')
105
- let fileVersion: string | undefined
106
- let fileDate: string | undefined
107
-
108
- await readJSONLLines(f, (line: AnyLine) => {
109
- if (!fileVersion && line.version) {
110
- fileVersion = line.version
111
- fileDate = line.timestamp
112
- }
113
- if (line.gitBranch && line.gitBranch !== 'HEAD') {
114
- branchTurns.set(line.gitBranch, (branchTurns.get(line.gitBranch) ?? 0) + 1)
115
- }
116
- })
117
-
118
- if (fileVersion) {
119
- if (!versionData.has(fileVersion)) {
120
- versionData.set(fileVersion, { sessions: new Set(), dates: [] })
121
- }
122
- const vd = versionData.get(fileVersion)!
123
- vd.sessions.add(sessionId)
124
- if (fileDate) vd.dates.push(fileDate)
125
- }
126
- })
127
- )
128
- })
129
- )
130
-
131
- const versions: VersionRecord[] = [...versionData.entries()]
132
- .map(([version, data]) => {
133
- const sortedDates = data.dates.sort()
134
- return {
135
- version,
136
- session_count: data.sessions.size,
137
- first_seen: sortedDates[0] ?? '',
138
- last_seen: sortedDates[sortedDates.length - 1] ?? '',
139
- }
140
- })
141
- .sort((a, b) => b.last_seen.localeCompare(a.last_seen))
142
-
143
- const branches = [...branchTurns.entries()]
144
- .map(([branch, turns]) => ({ branch, turns }))
145
- .sort((a, b) => b.turns - a.turns)
146
- .slice(0, 15)
147
-
148
- const result: ToolsAnalytics = {
149
- tools,
150
- mcp_servers,
151
- feature_adoption,
152
- versions,
153
- branches,
154
- error_categories: errorCategories,
155
- total_tool_calls: totalToolCalls,
156
- total_errors: totalErrors,
157
- }
158
-
159
- return NextResponse.json(result)
160
- }