Skip to content

feat: session-scoped client integration channel (publish + events)#30

Merged
jesse23 merged 10 commits into
mainfrom
docs/channel-pubsub-spec
Jun 9, 2026
Merged

feat: session-scoped client integration channel (publish + events)#30
jesse23 merged 10 commits into
mainfrom
docs/channel-pubsub-spec

Conversation

@jesse23

@jesse23 jesse23 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds POST /s/:id/publish — accepts one-shot or streaming newline-delimited JSON; broadcasts each line to subscribers as a discrete WS frame as it arrives; 204 after publisher closes; 409 if PTY not running
  • Adds ws /ws/:id/events — WebSocket subscribe endpoint; receives one JSON object per frame; WS close 4002 if PTY not running
  • Renames PTY WebSocket from /ws/:id/ws/:id/pty for consistency (server and client ship together, not a breaking change)
  • Channel lifecycle is tied to the PTY — subscribers are closed alongside PTY clients on shell exit, session delete, or server stop
  • session.subscribers is a separate Set<WebSocket> from session.clients (PTY); the two are fully independent

Spec / ADR

Test plan

  • 223 tests passing, 100% coverage on all tracked files
  • POST /s/:id/publish — 404 unknown session, 400 wrong content-type, 409 no PTY
  • /ws/:id/events — 4001 unknown session, 4002 no PTY, receives published events, multi-line delivers one frame per line, invalid JSON lines skipped, closed with 4001 on shell exit

🤖 Generated with Claude Code

jesse23 and others added 9 commits June 8, 2026 20:29
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ange

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- POST /s/:id/publish — streams JSON lines to subscribers; 409 if PTY not running
- ws /ws/:id/events — WebSocket subscribe; 4002 if PTY not running
- ws /ws/:id/pty — PTY renamed from /ws/:id for consistency
- session.subscribers set independent from session.clients (PTY)
- channel lifecycle tied to PTY: closes with shell exit / server stop
- 100% coverage on tracked files (223 tests)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a session-scoped “client integration channel” alongside the existing PTY WebSocket, enabling external publishers (CLI/tools) to stream newline-delimited JSON events into a session while browser subscribers receive one JSON frame per event.

Changes:

  • Added POST /s/:id/publish to stream/submit JSON lines and broadcast valid lines to session event subscribers.
  • Added ws /ws/:id/events subscribe endpoint and introduced session.subscribers to manage subscriber lifecycle tied to the PTY.
  • Renamed PTY WebSocket endpoint from /ws/:id to /ws/:id/pty and updated client/tests/docs accordingly.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/server/websocket.ts Adds /events WebSocket routing, subscriber tracking, and subscriber cleanup on shutdown/exit.
src/server/websocket.test.ts Updates PTY WS route and adds tests for the new events subscription behavior.
src/server/session.ts Extends Session with subscribers: Set<WS> and initializes it.
src/server/routes.ts Implements POST /s/:id/publish streaming JSON-line ingestion and broadcasting.
src/server/routes.test.ts Adds route-level tests for /s/:id/publish error cases.
src/client/index.ts Updates browser client to connect to /ws/:id/pty.
src/cli/http.test.ts Adds CLI tests around executor selection and spawn error handling.
docs/specs/webtty.md Documents the client integration feature in the feature table.
docs/specs/client-integration.md Adds the client integration spec document.
docs/adrs/025.server.channel.md Adds the ADR describing the integration channel API and lifecycle.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/server/routes.ts
Comment thread docs/specs/webtty.md Outdated
Comment thread docs/specs/client-integration.md Outdated
Comment thread docs/adrs/025.server.channel.md Outdated
Comment thread src/server/routes.ts
…ix ADR subscribe error code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jesse23 jesse23 merged commit 0b333bb into main Jun 9, 2026
3 checks passed
@jesse23 jesse23 deleted the docs/channel-pubsub-spec branch June 9, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants