Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-06-22 - Overview Stats 토글 버튼 키보드 접근성 개선
**Learning:** `overview-stats` 컴포넌트의 설명 텍스트를 펼치거나 접는 `<button>` 요소에 키보드 포커스 스타일이 누락되어 있어, 키보드 내비게이션 사용자에게 현재 포커스 위치를 명확히 보여주지 못했습니다. `hover` 스타일은 있었으나 `focus-visible` 처리가 없어 접근성 결함이 있었습니다.
**Action:** Tailwind CSS의 `focus-visible` 관련 유틸리티 클래스(`focus-visible:outline-none`, `focus-visible:ring-2`, `focus-visible:ring-ring`, `rounded-sm`)를 추가하여 탭(Tab) 키 이동 시 포커스 링이 보이도록 수정했습니다. 앞으로 대화형 컴포넌트를 설계할 때는 항상 키보드 접근성(focus states)을 염두에 두고 작업해야 합니다.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## [Unreleased]

### 🎨 변경 사항 (UX / 접근성)

- 웹 대시보드의 각종 로그아웃 버튼(`org-sidebar.tsx`, `org-header.tsx`, `no-organization-state.tsx`)에 스크린 리더용 `aria-label="Log out of your account"` (또는 `Sign out of your account`) 속성을 추가하여 접근성을 개선했습니다.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SessionFilesTab,
} from '@/components/dashboard/session-files'
import { useSessionDetail } from '@/hooks/use-dashboard-sessions'
import { messagesToTimeline, formatSlashCommandText } from '@/lib/timeline-events'
import { messagesToTimeline, buildTimelineGroups, formatSlashCommandText } from '@/lib/timeline-events'
import { extractSessionFiles } from '@/lib/session-files'
import {
formatTokens,
Expand Down Expand Up @@ -46,6 +46,7 @@ export default function OrgSessionDetailPage({
() => (data ? messagesToTimeline(data.messages) : []),
[data],
)
const groups = useMemo(() => buildTimelineGroups(events), [events])
const files = useMemo(() => extractSessionFiles(events), [events])
const [selectedIdx, setSelectedIdx] = useState<number | null>(0)
const safeIdx =
Expand Down Expand Up @@ -221,6 +222,7 @@ export default function OrgSessionDetailPage({
<div className="px-4 pt-3 pb-2">
<SessionActivityRibbon
events={events}
groups={groups}
selectedIdx={safeIdx}
onSelect={setSelectedIdx}
sessionStartedAt={data.startedAt}
Expand All @@ -232,6 +234,7 @@ export default function OrgSessionDetailPage({
<div className="border-r border-border min-h-0 overflow-hidden">
<EventList
events={events}
groups={groups}
selectedIdx={safeIdx ?? -1}
onSelect={setSelectedIdx}
sessionStartedAt={data.startedAt}
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/components/dashboard/event-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { List, type RowComponentProps } from "react-window";
import { User, Bot, Wrench, ChevronRight } from "lucide-react";
import {
formatSlashCommandText,
buildTimelineGroups,
type TimelineEvent,
type TimelineGroup,
} from "@/lib/timeline-events";
import { cn } from "@/lib/utils";

type EventListProps = {
events: TimelineEvent[];
groups: TimelineGroup[];
selectedIdx: number;
onSelect: (idx: number) => void;
sessionStartedAt: string;
Expand Down Expand Up @@ -50,11 +51,10 @@ function formatElapsed(timestamp: string, sessionStartedAt: string): string {
}

function buildFlatRows(
events: TimelineEvent[],
groups: TimelineGroup[],
expandedGroups: Set<number>,
selectedIdx: number,
): FlatRow[] {
const groups = buildTimelineGroups(events);
const rows: FlatRow[] = [];
for (const group of groups) {
if (group.kind === "single") {
Expand Down Expand Up @@ -261,15 +261,16 @@ function Row({

export function EventList({
events,
groups,
selectedIdx,
onSelect,
sessionStartedAt,
expandedGroups,
onToggleGroup,
}: EventListProps) {
const rows = useMemo(
() => buildFlatRows(events, expandedGroups, selectedIdx),
[events, expandedGroups, selectedIdx],
() => buildFlatRows(groups, expandedGroups, selectedIdx),
[groups, expandedGroups, selectedIdx],
);

if (events.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function NoOrganizationState({
<button
onClick={() => signOut({ callbackUrl: '/login' })}
className="text-sm text-destructive hover:underline"
aria-label="Log out of your account"
>
Log out
</button>
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/dashboard/overview-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function OverviewStats({
id="overview-stats-explanation-toggle"
aria-expanded={expanded}
aria-controls="overview-stats-explanation"
className="mt-4 flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors"
className="mt-4 flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring transition-colors rounded-sm"
>
<span
aria-hidden="true"
Expand Down
27 changes: 16 additions & 11 deletions packages/web/src/components/dashboard/reports/weekly-flow-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Legend,
type TooltipProps,
} from 'recharts'
import { useMemo } from 'react'
import { parseISO } from 'date-fns'
import { formatTokens } from '@/lib/format'
import type { DailySeriesPoint } from '@/types/reports'
Expand Down Expand Up @@ -57,18 +58,22 @@ function sumTokens(p: DailySeriesPoint): number {
}

export function WeeklyFlowChart({ thisWeek, prevWeek }: WeeklyFlowChartProps) {
// 요일 기준으로 병합 (월~일 7개 슬롯)
const dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
const data: ChartRow[] = dayNames.map((day) => ({ day, thisWeekTokens: 0, prevWeekTokens: 0 }))
const data = useMemo(() => {
// 요일 기준으로 병합 (월~일 7개 슬롯)
const dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
const result: ChartRow[] = dayNames.map((day) => ({ day, thisWeekTokens: 0, prevWeekTokens: 0 }))

for (const p of thisWeek) {
const idx = dayIndex(p.date)
if (idx >= 0) data[idx].thisWeekTokens += sumTokens(p)
}
for (const p of prevWeek) {
const idx = dayIndex(p.date)
if (idx >= 0) data[idx].prevWeekTokens += sumTokens(p)
}
for (const p of thisWeek) {
const idx = dayIndex(p.date)
if (idx >= 0) result[idx].thisWeekTokens += sumTokens(p)
}
for (const p of prevWeek) {
const idx = dayIndex(p.date)
if (idx >= 0) result[idx].prevWeekTokens += sumTokens(p)
}

return result
}, [thisWeek, prevWeek])

return (
<ResponsiveContainer width="100%" height={260}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use client'

import { useMemo, useState, useRef } from 'react'
import { useState, useRef } from 'react'
import {
formatSlashCommandText,
buildTimelineGroups,
type TimelineEvent,
type TimelineGroup,
} from '@/lib/timeline-events'
import { formatTokens, formatCost, formatRelativeTime } from '@/lib/format'
import { segmentVisuals } from './session-ribbon-visuals'

type Props = {
events: TimelineEvent[]
groups: TimelineGroup[]
selectedIdx: number | null
onSelect: (idx: number) => void
sessionStartedAt: string
Expand Down Expand Up @@ -147,6 +148,7 @@ function MergedTooltipBody({

export function SessionActivityRibbon({
events,
groups,
selectedIdx,
onSelect,
sessionStartedAt,
Expand All @@ -156,8 +158,6 @@ export function SessionActivityRibbon({
const [hover, setHover] = useState<HoverState | null>(null)
const containerRef = useRef<HTMLDivElement>(null)

const groups = useMemo(() => buildTimelineGroups(events), [events])

if (events.length === 0) return null

const trackMouse = (e: React.MouseEvent) => {
Expand Down
26 changes: 16 additions & 10 deletions packages/web/src/components/dashboard/session-timeline-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ interface ToolCallPoint {
toolName: string
}

interface ParsedToolCallPoint {
timestampMs: number
toolName: string
}

interface ChartDataItem {
relativeTime: string
input: number
Expand All @@ -35,20 +40,18 @@ interface ChartDataItem {

function getToolSummaryForIndex(
index: number,
usageTimeline: SessionTimelineUsage[],
toolCalls: ToolCallPoint[]
parsedUsage: number[],
toolCalls: ParsedToolCallPoint[]
): string {
if (toolCalls.length === 0) return ''

const currentTimestamp = new Date(usageTimeline[index]!.timestamp).getTime()
const prevTimestamp =
index > 0 ? new Date(usageTimeline[index - 1]!.timestamp).getTime() : 0
const currentTimestamp = parsedUsage[index]!
const prevTimestamp = index > 0 ? parsedUsage[index - 1]! : 0

// 현재 usageTimeline timestamp 이전이면서, 이전 usageTimeline timestamp 이후의 tool events 찾기
// 첫 번째 bar(index=0)는 prevTimestamp가 0이므로 해당 bar 이전의 모든 이벤트를 포함
const relevantTools = toolCalls.filter((e) => {
const toolTimestamp = new Date(e.timestamp).getTime()
return toolTimestamp <= currentTimestamp && toolTimestamp > prevTimestamp
return e.timestampMs <= currentTimestamp && e.timestampMs > prevTimestamp
})
Comment on lines 51 to 55

if (relevantTools.length === 0) return ''
Expand Down Expand Up @@ -132,17 +135,20 @@ export function SessionTimelineChart({
)
}

const toolCalls: ToolCallPoint[] = messages
// Pre-parse timestamps to avoid O(N*M) Date parsing inside loops
const toolCalls: ParsedToolCallPoint[] = messages
.filter((m) => m.role === 'TOOL')
.map((m) => ({ timestamp: m.timestamp, toolName: m.toolName ?? 'unknown' }))
.map((m) => ({ timestampMs: new Date(m.timestamp).getTime(), toolName: m.toolName ?? 'unknown' }))

const parsedUsage = usageTimeline.map(u => new Date(u.timestamp).getTime())
Comment on lines +139 to +143

const chartData: ChartDataItem[] = usageTimeline.map((u, idx) => ({
relativeTime: formatRelativeTime(u.timestamp, sessionStartedAt),
input: u.inputTokens,
output: u.outputTokens,
cost: u.estimatedCostUsd,
model: u.model,
toolSummary: getToolSummaryForIndex(idx, usageTimeline, toolCalls),
toolSummary: getToolSummaryForIndex(idx, parsedUsage, toolCalls),
}))

return (
Expand Down
21 changes: 12 additions & 9 deletions packages/web/src/components/dashboard/token-usage-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client'

import { useMemo } from 'react'
import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, TooltipProps } from 'recharts'
import { formatTokens, formatCost } from '@/lib/format'
import type { UsageSeries } from '@argos/shared'
Expand Down Expand Up @@ -43,15 +44,17 @@ function CustomTooltip({ active, payload, label }: TooltipProps<number, string>)
}

export function TokenUsageChart({ data }: TokenUsageChartProps) {
const chartData = data.map(d => {
const date = new Date(d.date)
return {
date: format(date, 'MMM d'),
fullDate: format(date, 'MMM d, yyyy'),
input: d.inputTokens,
output: d.outputTokens,
}
})
const chartData = useMemo(() => {
return data.map(d => {
const date = new Date(d.date)
return {
date: format(date, 'MMM d'),
fullDate: format(date, 'MMM d, yyyy'),
input: d.inputTokens,
output: d.outputTokens,
}
})
}, [data])

return (
<ResponsiveContainer width="100%" height={300}>
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/components/layout/org-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function OrgHeader({ orgName }: { orgName?: string }) {
<Button
variant="outline"
onClick={() => signOut({ callbackUrl: '/login' })}
aria-label="Sign out of your account"
>
Sign out
</Button>
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/components/layout/org-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function OrgSidebar() {
<button
onClick={handleLogout}
className="w-full px-3 py-2 text-sm font-medium text-destructive hover:bg-destructive/10 rounded-md transition-colors"
aria-label="Log out of your account"
>
Log Out
</button>
Expand All @@ -150,6 +151,7 @@ export function OrgSidebar() {
<button
onClick={handleLogout}
className="px-3 py-1 text-sm text-destructive hover:bg-destructive/10 rounded-md transition-colors"
aria-label="Log out of your account"
>
Logout
</button>
Expand Down
23 changes: 14 additions & 9 deletions packages/web/src/lib/server/weekly-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,22 @@ export async function getWeeklyReport(
}

// Insights — delegation
const totalAgentCalls = thisWeekRollups.reduce(
(sum, r) => sum + Object.values(r.agentCounts).reduce((a, b) => a + b, 0),
0,
)
const totalSkillCalls = thisWeekRollups.reduce(
(sum, r) => sum + Object.values(r.skillCounts).reduce((a, b) => a + b, 0),
0,
)
// ⚡ Bolt Optimization:
// 병목 지점: 기존 코드는 `thisWeekRollups`를 3번 순회하고, 매 순회마다 Object.values()로 중간 배열을 생성하여 메모리 할당 비용이 발생했습니다.
// 최적화 방법: 단일 for...of 루프와 Object.keys() 순회를 결합하여 N+1 순회를 1회 순회로 통합하고 중간 배열 할당을 제거했습니다.
// 기대 효과: `thisWeekRollups`의 크기가 클 경우, 불필요한 배열 생성 오버헤드와 O(N) 순회를 1/3로 줄여 리포트 생성 성능이 향상됩니다.
let totalAgentCalls = 0
let totalSkillCalls = 0
const distinctSkillsThisWeek = new Set<string>()

for (const r of thisWeekRollups) {
for (const k of Object.keys(r.skillCounts)) distinctSkillsThisWeek.add(k)
for (const k of Object.keys(r.agentCounts)) {
totalAgentCalls += r.agentCounts[k]
}
for (const k of Object.keys(r.skillCounts)) {
totalSkillCalls += r.skillCounts[k]
distinctSkillsThisWeek.add(k)
}
}

const insights: WeeklyInsights = {
Expand Down