chore: optimize metrics framework and codebase readability#140
chore: optimize metrics framework and codebase readability#140
Conversation
Extract 6 custom hooks from App.tsx (1737 → 686 lines): - useInstanceManager: instance CRUD, SSH hosts, discovery - useSshConnection: SSH connect/reconnect, passphrase dialog, health self-healing - useInstancePersistence: persistence scope, instance token, config version - useChannelCache: channel nodes, Discord guild channels, loading/refresh - useAppLifecycle: app update, analytics, preload, legacy migration, error handlers - useWorkspaceTabs: tab management, instance selection, install-ready handler Also fixes TS type narrowing for resolveInstanceTransport return type.
trace_command and record_timing now use microseconds instead of milliseconds. This fixes 0ms readings for fast local commands. PerfSample.elapsed_ms renamed to elapsed_us. CI report updated to show µs units with proper limits.
- JS initial load: add ≤200KB gate - Command P50: add ≤50ms gate (measured in µs) - Command max: add ≤200ms informational limit - Code Readability: expand from 2 to 18 tracked files with per-file targets - Files >500 lines: gate at ≤28 (must not increase) - SSH remote perf: replace 'expected in Docker' with descriptive label - metrics.md: update baselines and targets to match current codebase
📊 Test Coverage Report
Coverage measured by |
📦 PR Build Artifacts
|
📏 Metrics Gate ReportStatus: ✅ All gates passed Commit Size ❌
Bundle Size ✅
Perf Metrics E2E ✅
Command Perf (local) ✅
Local command timings
Command Perf (remote SSH) ✅
Remote command timings (via Docker SSH)
Home Page Render Probes (mock IPC 50ms, cache-first render) ✅
Code Readability
|
📸 UI ScreenshotsCommit: Light Mode — Core Pages
Dark Mode
Responsive + Dialogs
|
…bar footer Extract three more modules from App.tsx (686 → 500 lines): - useNavItems.tsx: navigation item definitions with icons - AppDialogs.tsx: passphrase and SSH edit dialogs - SidebarFooter.tsx: profile sync status, SSH transfer speed, pending changes bar
The previous threshold of 100µs was set before the ms→µs migration, causing false positives on CI. Local commands like get_app_preferences can take 100ms+ due to CI scheduling jitter.
Measured → New Limit (was): - Command P50: 32µs → ≤1,000µs (was 50,000µs) - Command P95: 36µs → ≤5,000µs (was 100,000µs) - Command Max: 40µs → ≤50,000µs (was 200,000µs) - JS initial load: 166KB → ≤180KB (was 200KB) - JS bundle gzip: 288KB → ≤350KB (was 512KB) - RSS: 3.1MB → ≤20MB (was 80MB) - Home probes: 10ms → ≤200ms (was 500ms) - Models probe: 107ms → ≤300ms (was 500ms) - Settled: 10ms → ≤1,000ms (was 5,000ms)
…es mock 1. Readability: auto-scans all .ts/.tsx/.rs files >300 lines, auto-calculates targets (60% of current, floor 500), with manual overrides for key files. Covers entire codebase instead of 18 hand-picked files. 2. Home Probes: annotated as mock IPC (50ms latency) so the 10ms values are understood as render-only timing, not E2E with real API calls.
…→ 959) - profile-utils.ts: ProfileForm type, credential helpers (emptyForm, normalizeOauthProvider, inferCredentialSource, etc.) - AutocompleteField.tsx: standalone autocomplete input component
… (963 → 901) Moves duplicate install detection and post-install onboarding guidance event emission into a dedicated hook with self-contained refs.
Also skip get_status_extra, get_status_light, list_agents_overview during the first 2 IPC rounds, so prewarm doesn't populate any cache.
Each run now clears localStorage before goto to prevent persisted cache from previous runs. Increased cold-start skip from 2 to 4 to handle all prewarm paths.
Skip=4 caused the poll loop to keep getting null from cache, preventing settled from firing. Skip=1 blocks just the prewarm call; the poll loop's 2nd call returns real data.
…863 → 5709) Moves skip_json5_ws_and_comments, scan_json5_string_end, scan_json5_value_end, extract_json5_top_level_value into src/json5_extract.rs. These are pure string parsers with no doctor-specific dependencies.
Moves 22 SSH-related type definitions to src/lib/ssh-types.ts. Re-exported from types.ts for backward compatibility — no import path changes needed in consuming files.
Extract 47 type definitions into 3 domain files: - ssh-types.ts (22 types, 160 lines) - rescue-types.ts (15 types, 142 lines) - install-types.ts (12 types, 82 lines) - cron-types.ts (10 types, 62 lines) All re-exported from types.ts for backward compatibility.
… → 5635) Moves DoctorTempGatewaySessionRecord/Store structs and 5 CRUD functions into src-tauri/src/doctor_temp_store.rs (80 lines). Registered in lib.rs, all call sites updated.
…rget) Moves 9 doctor/diagnosis type definitions to src/lib/doctor-types.ts. types.ts now passes readability gate (491 ≤ 500).
Keith-CY
left a comment
There was a problem hiding this comment.
P1 - src/App.tsx:107-121
The refactor broke the SSH transfer-speed preference wiring. useInstancePersistence still loads showSshTransferSpeedUi from app preferences, but App now passes a no-op setter (setShowSshTransferSpeedUi: () => {}) and never connects that preference to the state returned by useSshConnection.
That leaves showSshTransferSpeedUi stuck at false inside src/hooks/useSshConnection.ts:56 and :297-320, so the polling effect never starts and the sidebar transfer-speed panel never appears even when the toggle is enabled in Settings (src/pages/Settings.tsx:432-442). This regresses the pre-refactor behavior where the same preference load updated the live sidebar state.
Please thread the real setter through, or move the preference read into useSshConnection, before merging.
Move showSshTransferSpeedUi preference loading from useInstancePersistence into useSshConnection where the state lives. The refactor had broken the wiring by passing a no-op setter, leaving the transfer-speed sidebar permanently hidden. Now useSshConnection loads + subscribes to the preference directly, so Settings toggle correctly drives the sidebar panel.
dev01lay2
left a comment
There was a problem hiding this comment.
Fixed in 712c424 — moved showSshTransferSpeedUi preference loading from useInstancePersistence into useSshConnection where the state lives. The no-op setter is removed; useSshConnection now loads + subscribes to the preference cache key directly.
Keith-CY
left a comment
There was a problem hiding this comment.
Re-reviewed the current head 712c424. The previous SSH transfer-speed preference regression is fixed: the preference load/subscription now lives in useSshConnection, the no-op setter is gone from App, and I do not see remaining blockers in the follow-up patch.

























What
Comprehensive metrics framework optimization and codebase readability improvements, based on PR #139 metrics report.
Metrics Framework
_COLD_START_SKIP.ts/.tsx/.rsfiles >300 lines tracked with auto-calculated targetsCode Refactoring (20+ new modules)
New files created:
useAppUpdate,useHomeGuidance,useSshConnection,useInstancePersistence,useChannelCache,useAppLifecycle,useWorkspaceTabsAutocompleteField, nav-itemsapi-read-cache,profile-utils,start-page-utils,cron-utilsssh-types,rescue-types,install-types,cron-types,doctor-typesjson5_extract,doctor_temp_storeFinal Metrics (all gates ✅)
Remaining (informational⚠️ )
25 files still over readability targets (16 Rust, 9 frontend) — deeply coupled, deferred to follow-up PRs.