Skip to content

Add agent session orchestration API#9

Open
thehumanworks wants to merge 3 commits into
mainfrom
orchestration-api
Open

Add agent session orchestration API#9
thehumanworks wants to merge 3 commits into
mainfrom
orchestration-api

Conversation

@thehumanworks

Copy link
Copy Markdown
Owner

Summary

  • add a dedicated Electron IPC/preload agentSession PTY orchestration API with a main-process session manager
  • cover the new manager and preload bridge with focused tests
  • document the new agentSession API with usage examples

Testing

  • bun test src/main/agent-session-manager.test.ts src/preload/index.test.ts src/main/shell-resolver.test.ts src/main/preferences.test.ts
  • bun install
  • bun x tsc --noEmit --pretty false --skipLibCheck

Copilot AI review requested due to automatic review settings April 21, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 thread README.md
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([])
})
Comment thread src/main/index.ts
}
})

ipcMain.handle('agentSession:create', (_event, request: AgentSessionCreateRequest) => {
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