feat(ws-support): cp websocket runtime support with browser chat#475
Open
sskmlm wants to merge 27 commits into
Open
feat(ws-support): cp websocket runtime support with browser chat#475sskmlm wants to merge 27 commits into
sskmlm wants to merge 27 commits into
Conversation
9f5fe3b to
f440ebd
Compare
load_plugin_callbacks() returns dict with 'builtin' and 'user' keys but not always 'external'. Use .get() with default to avoid KeyError.
Root cause analysis for missing tool call streaming: - ContextVar bridge (current_emitter_session_id) never wired - Pre-existing gap from original puppy-desk branch - Events tagged session_id=None, dropped by session-filtered subscriber - b1_streaming_used stays False, GUGI gets no tool lifecycle frames Also documents: stale sender session_id, session switch sync, executor shutdown cosmetic error. Execution plan: P0 ContextVar fix, P1 sender sync, future extraction targets.
P0 — Tool call streaming was broken because the emitter ContextVar (current_emitter_session_id) was never set. Events emitted by register_callbacks had session_id=None, which session-filtered subscribers dropped. Now set/reset around the agent run window. P1 — WebSocketSender.session_id was stale after session generation and session switching. Added setter property and synced at all 3 assignment sites (new session, switch-to-new, switch-to-existing). Pre-existing gap — original feature/puppy-desk also never set the ContextVar. Not a Phase 3 regression. Test results: 4095 passed, 29 skipped (3 pre-existing failures excluded)
Aligns chat_handler.py import order and removes extra blank lines in test files so ws/ layer is byte-identical across both repos.
Improve the desk chat template with wireframe-inspired message and tool-call rendering, including safer markdown/tool-card handling and collapsed tool call payloads. Strengthen resumed-session recovery, session CWD handling, permission auto-approval behavior, SQL query loading, and command runner cleanup coverage. Validation: node --check /tmp/chat_inline_pr_handoff_check.js; ruff check targeted files; pytest -q --no-cov targeted tests (11 passed).
1fdcecc to
e65d6c3
Compare
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.
Summary
───────
• add websocket streaming support for Code Puppy via a local API/server runtime
• enable chatting with Code Puppy from the browser while Code Puppy runs locally as the server
• add modular websocket/session handling, persistence, and recovery flows for streamed chat execution
• preserve legacy CLI session resume behavior while separating browser/server concerns into the API runtime
What changed
────────────
Local API/server runtime
• add the API app/bootstrap under code_puppy.api, including main entrypoint, app wiring, routers, and protocol/config endpoints
• add DB/session infrastructure for chat history, backfill, message utilities, SQL loading, and session context management
• add backend logging setup and model error normalization support
• add permission/session binding enforcement for API operations
WebSocket streaming
• add modular websocket handling under code_puppy.api.ws
• add runtime/session managers, chat turn lifecycle helpers, response frame adaptation, background saves, and stream draining
• add one-shot resume recovery with sqlite reload for failed resumed sessions
• improve tool lifecycle and event adapter handling during streamed/browser-based execution
Browser chat support
• refresh chat.html for browser-based chat flows and session recovery UX
• support browser ask_user_question responses
• harden config/schema and XSS-related template behavior
Reliability fixes
• dedupe duplicate Codex input item IDs before API requests
• add BaseAgent session/model compatibility helpers
• fix emitter/session-id wiring and avoid cwd history corruption
• keep legacy CLI session resume unchanged while browser/server support is added alongside it
Why
───
This branch adds websocket streaming support for Code Puppy so it can run locally as a server and be used from a browser chat UI. It also closes several session recovery, browser interaction, and streamed execution gaps that showed up while building that flow.