Add agent session orchestration API#9
Open
thehumanworks wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a dedicated Electron IPC + preload bridge API (window.baton.agentSession) backed by a new main-process AgentSessionManager to orchestrate long-lived local PTY sessions, with tests and usage documentation.
Changes:
- Introduces
AgentSessionManager(main process) to create/list/get/write/resize/close agent PTY sessions and stream data/exit events. - Exposes the agent session orchestration API through the Electron preload bridge and augments shared protocol types.
- Adds Bun tests for the manager and preload bridge, plus README usage documentation.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Suppresses TypeScript deprecation warnings up to a specified version. |
| src/shared/terminal-types.ts | Adds shared request/response/event types for the new agent session protocol. |
| src/renderer/src/env.d.ts | Extends the renderer-facing window.baton typings to include agentSession. |
| src/preload/index.ts | Implements the preload IPC bridge for agentSession APIs and events. |
| src/preload/index.test.ts | Tests the preload bridge’s IPC wiring for agent session APIs/events. |
| src/main/index.ts | Wires IPC handlers and instantiates AgentSessionManager, forwarding data/exit events to the renderer. |
| src/main/agent-session-manager.ts | New session manager implementing PTY lifecycle, metadata tracking, and recent output buffering. |
| src/main/agent-session-manager.test.ts | Tests manager creation/output buffering/write/resize/close/list behaviors. |
| README.md | Documents window.baton.agentSession with an end-to-end usage example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+148
to
+154
| try { | ||
| if (session.summary.status === 'running') { | ||
| session.pty.kill() | ||
| } | ||
| } finally { | ||
| session.summary.status = 'closed' | ||
| session.summary.closedAt = session.summary.closedAt ?? this.now() |
| } finally { | ||
| session.summary.status = 'closed' | ||
| session.summary.closedAt = session.summary.closedAt ?? this.now() | ||
| this.sessions.delete(sessionId) |
Comment on lines
+177
to
+178
| - `onExit()` fires when the backing process exits as `{ sessionId, exitCode, signal }`. | ||
| - `get()` returns the latest known summary for one session, while `list()` returns all tracked sessions, including exited or closed state when available. |
Comment on lines
+55
to
+89
| export type AgentSessionStatus = 'running' | 'exited' | 'closed' | ||
|
|
||
| export interface AgentSessionCreateRequest { | ||
| cols: number | ||
| rows: number | ||
| cwd?: string | ||
| shellId?: string | ||
| } | ||
|
|
||
| export interface AgentSessionCreateResponse { | ||
| sessionId: string | ||
| shell: string | ||
| shellId: string | ||
| pid?: number | ||
| cwd: string | ||
| status: AgentSessionStatus | ||
| createdAt: number | ||
| startedAt: number | ||
| recentOutput: string | ||
| } | ||
|
|
||
| export interface AgentSessionSummary { | ||
| sessionId: string | ||
| shell: string | ||
| shellId: string | ||
| pid?: number | ||
| cwd: string | ||
| status: AgentSessionStatus | ||
| createdAt: number | ||
| startedAt: number | ||
| closedAt?: number | ||
| exitCode?: number | null | ||
| signal?: number | null | ||
| recentOutput: string | ||
| } |
| manager.closeAll() | ||
| expect(second.killed).toBe(1) | ||
| expect(manager.list()).toEqual([]) | ||
| }) |
| } | ||
| }) | ||
|
|
||
| ipcMain.handle('agentSession:create', (_event, request: AgentSessionCreateRequest) => { |
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
Testing