The Analysis tab (info.js `loadAI` + `pollAIStatus` + `renderAIProgress` + `renderAIAnalysis` + the trading pipeline section + competitor scoring + key-people polling) has grown into a tangled web of:
- Two overlapping state machines (Phase 1 `intelligence` poll vs Phase 2 `trading` poll), each with its own polling function, stop-handle, and re-render path
- innerHTML swaps at the container level that have repeatedly clobbered the Deep Analysis header / button (see the fix that introduced `#ai-content-host`)
- Pieces of vim-nav state (`tradingPanelIdx`) reset at the top of `loadAI` for a single ergonomics fix
- Trading button wiring split across `renderTradingButton` (HTML), `wireTradingButton` (handler), and the in-flight running state baked into the same render path
Symptoms over time:
- Run Deep Analysis button vanishing when Phase 1 auto-kicks off on a fresh security (fixed by introducing an `#ai-content-host` div, but the fix is a workaround for the root architectural issue)
- Polling intervals leaking when the user tab-switches mid-flight (handled via `currentTab` checks scattered through every poll callback)
- Re-render races between Phase 1 completion and Phase 2 kick-off
Suggested refactor:
- One state object: `{ phase1, phase2, costInfo }` with explicit transitions
- Pure render functions taking that state → HTML, no mid-poll innerHTML mutations
- Single poller that knows about both Phase 1 and Phase 2 and routes by which is in flight
- Move the Deep Analysis header into a stable shell that the polled content slots into
Not a regression — just a "the next time someone touches this tab, redesign instead of patching" reminder.
The Analysis tab (info.js `loadAI` + `pollAIStatus` + `renderAIProgress` + `renderAIAnalysis` + the trading pipeline section + competitor scoring + key-people polling) has grown into a tangled web of:
Symptoms over time:
Suggested refactor:
Not a regression — just a "the next time someone touches this tab, redesign instead of patching" reminder.