feat(omp-rpc): introduced typed event listeners and todo phase management to RPC client

- Added typed event listeners and granular event handling for all RPC notification types.
- Added set_todos RPC command and todoPhases session state field for todo phase management.
- Added RpcClient initialization parameters (thinking, tools, no_session, rpc_defaults) for startup configuration.
- Added install_headless_ui() method and todo management methods (get_todos, set_todos, clear_todos).
- Added TodoItem and TodoPhase dataclasses with parser functions for structured todo representation.
- Added RPC mode behavior: disables session title generation by default and resets workflow settings to built-in defaults.
This commit is contained in:
can1357
2026-04-08 04:52:46 +02:00
parent 67e12b39fe
commit d7261bcbeb
11 changed files with 740 additions and 17 deletions
+57 -2
View File
@@ -22,6 +22,8 @@ omp --mode rpc [regular CLI options]
Behavior notes:
- `@file` CLI arguments are rejected in RPC mode.
- RPC mode disables automatic session title generation by default to avoid an extra model call.
- RPC mode resets workflow-altering `todo.*`, `task.*`, and `async.*` settings to their built-in defaults instead of inheriting user overrides.
- The process reads stdin as JSONL (`readJsonl(Bun.stdin.stream())`).
- When stdin closes, the process exits with code `0`.
- Responses/events are written as one JSON object per line.
@@ -73,6 +75,7 @@ Important edge behavior from runtime:
### State
- `{ id?, type: "get_state" }`
- `{ id?, type: "set_todos", phases: TodoPhase[] }`
### Model
@@ -145,10 +148,54 @@ Data payloads are command-specific and defined in `rpc-types.ts`.
"sessionName": "...",
"autoCompactionEnabled": true,
"messageCount": 0,
"queuedMessageCount": 0
"queuedMessageCount": 0,
"todoPhases": [
{
"id": "phase-1",
"name": "Todos",
"tasks": [
{
"id": "task-1",
"content": "Map the tool surface",
"status": "in_progress"
}
]
}
]
}
```
### `set_todos` payload
Replaces the in-memory todo state for the current session and returns the normalized phase list:
```json
{
"id": "req_2",
"type": "set_todos",
"phases": [
{
"id": "phase-1",
"name": "Evaluation",
"tasks": [
{
"id": "task-1",
"content": "Map the read tool surface",
"status": "in_progress"
},
{
"id": "task-2",
"content": "Exercise edit operations",
"status": "pending"
}
]
}
]
}
```
This is useful for hosts that want to pre-seed a plan before the first prompt.
## Event Stream Schema
RPC mode forwards `AgentSessionEvent` objects from `AgentSession.subscribe(...)`.
@@ -163,6 +210,7 @@ Common event types:
- `auto_retry_start`, `auto_retry_end`
- `ttsr_triggered`
- `todo_reminder`
- `todo_auto_clear`
Extension runner errors are emitted separately as:
@@ -226,6 +274,13 @@ Extensions in RPC mode use request/response UI frames.
- `select`, `confirm`, `input`, `editor`
- `notify`, `setStatus`, `setWidget`, `setTitle`, `set_editor_text`
Runtime note:
- Automatic session title generation is disabled in RPC mode, and `setTitle` UI
requests are also suppressed by default because most hosts do not have a
meaningful terminal-title surface. Set `PI_RPC_EMIT_TITLE=1` to opt back in to
the UI event only.
Example:
```json
@@ -322,4 +377,4 @@ Current helper characteristics:
- Dispatches only recognized `AgentEvent` types to listeners
- Does **not** expose helper methods for every protocol command (for example, `set_interrupt_mode` and `set_session_name` are in protocol types but not wrapped as dedicated methods)
Use raw protocol frames if you need complete surface coverage.
Use raw protocol frames if you need complete surface coverage.