fix: add thread safety for concurrent state modifications
- Add stateLock to synchronize all getState/setState read-modify-write
operations across UI thread and AgentLoop background threads
- Synchronize onInput, onPaste, addMessage, appendToStreamingMessage,
finishStreamingMessage, completeLastToolCall, setThinking, runAgent
- Extract addMessageInternal() to avoid double-locking
- Harden extractToolSummary with explicit indexOf checks
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>