mirror of
https://github.com/andrewyng/openworker.git
synced 2026-09-03 04:49:26 +00:00
Minimal engine footprint: a checkpoint at each iteration top (between tool turns and before a new turn), the usage signal captured per round-trip (context_tokens; chars/4 estimate when never reported), and _outbound_messages consulting the boundary. The summarizer runs off-loop through the normal provider router, so the Settings model pin is just an id. Failure policy per spec: retry once in both modes; attended sessions get the Retry / Trim-oldest-10% prompt (via the ask_user plumbing, gated by an is_attended callback the WS surface wires); unattended runs auto-trim and continue — never parked on internal bookkeeping. Raw context-overflow 400s from the main model route into the same policy, progress-guarded so a still-overflowing model terminates in the error path. CompactionState persists on the session record (new sqlite column, same defensive parse as grants), so reloads keep the compacted view. A persisted compacted notice + a new COMPACTED event mark the spot for the GUI divider (rendered in commit 3).
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""Event model — the contract between the turn engine and any surface (TUI/GUI/IDE).
|
|
|
|
No token streaming in v1, so granularity is per-message/per-tool. Streaming later adds
|
|
`assistant_delta` / `tool_output_delta` without changing the rest.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from enum import Enum
|
|
from typing import Any
|
|
|
|
|
|
class EventType(str, Enum):
|
|
TURN_START = "turn_start"
|
|
ASSISTANT_DELTA = "assistant_delta"
|
|
REASONING_DELTA = "reasoning_delta" # model thinking text (display-only, never replayed)
|
|
ASSISTANT_MESSAGE = "assistant_message"
|
|
TOOL_PROPOSED = "tool_proposed"
|
|
PERMISSION_REQUIRED = "permission_required"
|
|
DIRECTORY_REQUESTED = "directory_requested" # agent asks the user to grant a folder
|
|
QUESTION_REQUESTED = (
|
|
"question_requested" # agent asks the user a free-text/multiple-choice question
|
|
)
|
|
PLAN_PROPOSED = (
|
|
"plan_proposed" # agent presents a plan for approval (plan mode exit)
|
|
)
|
|
TOOL_STARTED = "tool_started"
|
|
TOOL_FINISHED = "tool_finished"
|
|
ITERATION_END = "iteration_end"
|
|
TURN_END = "turn_end"
|
|
ERROR = "error"
|
|
INTERRUPTED = "interrupted"
|
|
COMPACTED = "compacted" # outbound history was compacted (summary or trim)
|
|
|
|
|
|
@dataclass
|
|
class Event:
|
|
type: EventType
|
|
data: dict[str, Any] = field(default_factory=dict)
|