feat(ai, frontend): Session Summary Enhancement & Code Quality (Issue #79)#84
Merged
Conversation
…tion branching (Issue #79) This commit implements three interconnected specifications: - P1-A006: LLM Stats Collection + Session Summary for Normal Mode - ai-block-fields-extension: Token usage, cost estimate, model version fields - tree-conversation-branching: Fork/switch/delete conversation branches Backend changes: - Add LLMCallStats struct with token usage and timing metrics - Refactor LLMService.Chat/ChatStream to return stats - Implement BaseParrot with stats accumulation for all Parrot agents - Add TokenUsage, CostEstimate fields to Block proto/message - Add parent_block_id, branch_path for tree branching support - Add ForkBlock, ListBlockBranches, SwitchBranch, DeleteBranch RPCs - Implement postgres migration for new Block fields - Add comprehensive tests for stats, ForkBlock, and cost calculation Frontend changes: - Add TokenUsageBadge and BlockCostBadge components for displaying stats - Add BranchIndicator and BranchSelector for conversation branching - Implement useBranchTree hook for branch operations - Update SessionSummaryPanel to display token usage and timing - Add frontend integration tests with Vitest - Update i18n keys for new features Documentation: - Add AI_CHAT_INTERFACE.md with complete UI architecture diagrams - Update ARCHITECTURE.md with Unified Block Model references All 51 Loki Mode tasks completed. make check-all passes. Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Restructure from patch collection to纲领性 document - Add "第一性原理" section defining project essence - Consolidate architecture decisions with clear mappings - Streamline workflow and coding standards - Remove troubleshooting details (defer to DEBUG_LESSONS.md) - Reduce from 150 to 112 lines while increasing clarity Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Features: - Add SessionBar component displaying aggregated session stats (cost, tokens, duration) - Add BlockEditDialog for editing user inputs and creating branches - Add type guards isStreamingStatus(), isErrorStatus() for BlockStatus checks - Add isCompletedStatus() helper function Code quality fixes (P0/P1/P2/P3): - Fix JSX syntax errors: rename test files from .test.ts to .test.tsx - Fix BlockStatus comparison bug (String() was always false) - Reduce 'any' type usage in useBlockQueries.ts - Extract magic number MILLI_CENTS_TO_USD constant - Remove unused imports and variables i18n: - Add translations for session bar, edit dialog, and status labels Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Condense decision tree from verbose Chinese to concise English - Simplify idea-researcher trigger flow - Add language directive to CCRunner system prompt Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Backend changes: - Add replaceUserInputs parameter to ForkBlock API for message editing - Add reason validation and return InvalidArgument for empty reason - Store fork metadata (forked_from, fork_reason, fork_type) for debugging - Remove duplicate log entry from ForkBlock (keep service layer only) - Add unit tests: TestForkBlock_WithReplaceUserInputs, TestForkBlock_EmptyReason Frontend changes: - Simplify BlockEditDialog UI: remove "original message" display area - Merge multiple user inputs (with newlines) for editing - Fix handleEdit to pass complete MessageBlock for input merging - Remove onSend call after ForkBlock (was creating duplicate block) - Add new i18n keys: message, edit_placeholder Bug fix: - Fix mouse cursor flickering on /auth/signup page caused by overly broad [tabIndex] CSS selector targeting Radix UI components Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… audit fixes (Issue #79) This commit completes the P0-P3 phase tasks and addresses all code audit findings: **P2 Tasks:** - Add BlockSummary restoration from persisted Block.sessionStats after page refresh - Implement friendly branch path numbering (0/1/2 → A.2.3) with Base26 conversion - Integrate SessionBar into ChatHeader for PC, mobile-only standalone display **P3 Tasks:** - Update AI_CHAT_INTERFACE.md to v0.93.1 with new UI patterns **Code Audit Fixes:** - P1-#1: Add safeBigIntToNumber with MAX_SAFE_INTEGER boundary check - P2-#1: Add MAX_ITERATIONS limit to toBase26 to prevent potential infinite loops - P2-#2: Optimize calculateSessionStats to process only last 100 blocks - P3-#1: Replace hardcoded Chinese text with i18n t() calls - P3-#2: Add detailed comment for MILLI_CENTS_TO_USD constant **New Components:** - HeaderSessionStats: Mode-differentiated session stats (Normal/Geek/Evolution) **Bug Fixes:** - Fix ForkBlock protobuf serialization using create(UserInputSchema, ...) - Fix ToolCalls duplication with occurrence-based deduplication - Fix import ordering per Biome lint rules Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The sync.RWMutex field was declared but never used since the underlying LRUCache handles its own locking internally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove unused BlockListCacheData interface (re-added for internal use) - Fix protobuf mock creation using proper types - Change \`as any\` to \`as unknown as Type\` for observer mocks - Use EmptySchema for delete/append operations - Use ListBlocksResponseSchema for list operations - Import EmptySchema from @bufbuild/protobuf/wkt Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
b6dc93f to
8a7ebe5
Compare
- Update @testing-library/jest-dom from 6.6.0 to 6.9.1 - Update @testing-library/react from 16.2.0 to 16.3.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
完成 Issue #79 的会话摘要功能增强,包括 UI 组件、统计数据收集、分支管理和代码质量改进。
变更内容
AI 后端
前端 UI
代码质量
关联 Issue
Resolves #79
测试计划
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com