feat: session summary enhancement and code quality improvements#87
Merged
Conversation
Add React and related dependencies to optimizeDeps.include to prevent runtime issues where React hooks may be unavailable due to module loading order problems. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…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>
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>
… 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>
- 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>
- 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
Rebase caused duplicate TrackToolCall call. Remove one instance. Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix cold-start latency issue in ScheduleParrot by sending thinking event before first LLM call (reduces perceived latency from 4s to immediate feedback) - Add episodic_memory table to LATEST.sql for new installations - Unify all Parrot agents to send thinking event before LLM call Related to #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add 6 missing tables to LATEST.sql for new installations: - user_preferences: AI personalization preferences - conversation_context: AI session persistence and recovery - agent_metrics: A/B testing metrics - tool_metrics: Tool call performance metrics - chat_app_credential: Multi-platform chat app integrations - ai_block: Unified Block Model (core table!) This ensures new installations have all required tables from the start, preventing "relation does not exist" warnings. Related to #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add prevention mechanism for future migration sync issues: - store/migration/postgres/CLAUDE.md: Complete migration development guide - scripts/check-migration-sync.sh: Automated sync verification script - Link to migration guide in root CLAUDE.md Key principles: 1. Any DB change must update BOTH migrate/*.up.sql AND LATEST.sql 2. Run check-migration-sync.sh before committing migrations Related to #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove 5 outdated migration files from root of postgres dir: - 20260203_chat_apps_credential.* (superseded by 20260203070000_*) - 20260203_conversation_channel_type.* (superseded by 20260203130000_*) - V0.53.4__add_chat_app_app_secret.sql (superseded by 20260203080000_*) These files: - Use old naming format (YYYYMMDD_ and V*.*__) - Are not read by the migration system (migrator.go only reads migrate/) - Have newer counterparts in migrate/ directory Directory structure now cleaner: - CLAUDE.md (migration guide) - migrate/ (incremental migrations) - schema/ (LATEST.sql) Related to #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update freshness timestamp to 2026-02-07 (v0.93.1) - Document four-layer routing system (Cache → Rule → History → LLM) - Add AI model strategy overview table - Update intent classification to use SiliconFlow + Qwen2.5-7B-Instruct - Document fast path optimization (time + query keywords) - Remove deprecated ChatRouterConfig from API documentation - Add structured JSON Schema output for LLM classifier Ref: - ai/router/service.go: four-layer routing implementation - server/router/api/v1/ai_service.go: SiliconFlow + Qwen integration - ai/router/rule_matcher.go: fast path optimization Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add asynchronous LLM connection warmup to reduce first-request latency. The warmup sends a minimal ping request (max_tokens=1, temperature=0) to pre-establish TCP/TLS connections before the first real user request. Changes: - Add Warmup(ctx) method to llmService with direct API call - Uses max_tokens=1 (minimum cost, ~85% cheaper than default) - Uses temperature=0 (fastest deterministic response) - 5s timeout, failures don't affect service startup - Call Warmup asynchronously in NewAPIV1Service after LLM init - Add provider() helper for logging Expected impact: - First request latency: ~5400ms → ~4900ms (save ~500ms) - Warmup cost: ~¥0.0000006 per startup (vs ¥0.000005 before) Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add guidance for using TODO LIST to track multiple tasks, preventing "memory loss" or losing direction during multi-task sessions. When to use TODO LIST: - Multiple optimization points found during analysis - User requests to tackle issues one by one - Tasks take >1 hour or have multiple steps Workflow: 1. Create tasks with TaskCreate after analysis 2. Track status with TaskList 3. Update to in_progress before starting 4. Mark completed when done Example practice from this session: - Analyzed logs → found 5 issues - Created 4 TODOs for remaining work - Completed #1 (connection warmup), tracked others Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use LEFT JOIN + COUNT GROUP BY to fetch block counts in a single query, eliminating the N+1 query problem where each conversation triggered a separate ListAIBlocks call. Changes: - store.AIConversation: add BlockCount field - postgres.ListAIConversations: use LEFT JOIN ai_block with COUNT - Remove per-conversation ListAIBlocks calls from handler Before: N conversations → N+1 database queries After: N conversations → 1 database query Performance impact: - 10 conversations: 11 queries → 1 query (91% reduction) - 100 conversations: 101 queries → 1 query (99% reduction) Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tool-based agents (MemoParrot/ScheduleParrot/AmazingParrot) don't have direct LLM calls, so token stats are always zero. Instead of logging misleading zeros, log meaningful tool metrics: Changes: - When PromptTokens=0 and CompletionTokens=0: - Log "tool-based agent stats" with tool_calls count - Log "tool-based agent completed" with tools used - Preserve original logging for agents with real token stats Before: Agent: got normal stats... prompt_tokens=0 completion_tokens=0 Agent: applied normal stats... prompt_tokens=0 completion_tokens=0 After: Agent: tool-based agent stats tool_calls=1 duration_ms=5423 Agent: tool-based agent completed tool_calls=1 tools=schedule_query Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Align comment formatting in Warmup function for consistency. Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use ListMessages API instead of ListBlocks for pagination support - Reduces duplicate DB queries when switching conversations - React Query now caches response for both hooks Before: useBlocksWithFallback → ListBlocks + syncMessages → ListMessages After: Both hooks use ListMessages → cached response Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Major improvements: - Add "SOTA Agent 工程实践" section with: - Thinking Protocol for complex decisions - Tool usage strategy matrix - Metacognition: self-healing protocol when stuck - SOTA reasoning patterns (CoT, ReAct, Self-Refinement) - Restructure for progressive disclosure - Add freshness header (v0.93.1) - Simplify tables for better scannability - Emoji icons for visual hierarchy Key additions: - When to use Task tools vs direct operations - Explicit thinking criteria (architecture changes, unfamiliar APIs) - Self-healing flow: re-read → visualize → clarify → confidence → document Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
BlockManager already logs "Created block for chat" with round_number. Removed redundant log in handler.go to avoid duplication. Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The lockfile had duplicated mapping keys causing CI to fail. Regenerated with pnpm install. Refs #87 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add duration_ms to track request processing time - Shorten service name (remove memos.api.v1. prefix) - Use underscore case for status (ok, client_error, server_error) - Use empty message for cleaner structured log output Before: INFO OK method=/memos.api.v1.AuthService/GetCurrentUser After: INFO type=API method=AuthService/GetCurrentUser status=ok duration_ms=12 Refs #79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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 会话摘要增强功能,并进行代码质量优化。
变更内容
后端 (Go)
前端 (React/TypeScript)
文档
数据库
关键指标
关联 Issue
Resolves #79
检查清单
make check-all通过Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com