feat(tasks): auto-compact a resumed session before the round's prompt
Task settings gain an auto-compact threshold (percent, 0 = off) and an optional compact command. When a retry, follow-up or merge round resumes a session whose context window is at least that full, the engine sends the compact command, waits for that turn to land, and only then sends the round's own message; a fresh session is never compacted. Occupancy comes from the live connection's usage, falling back to the parsed transcript only when it belongs to the session actually connected. The command resolves per agent — the setting, then a compaction verb the session advertises, then a built-in default — and every outcome is recorded on the task timeline with the before/after occupancy. The compaction turn is fenced off from the round it precedes by (connection, event seq) on every exit of the wait: the internal bus is a broadcast, so the engine's own receiver can dequeue that completion long after the launch has bound the connection to the run, and would settle the round and disconnect the agent mid-work. The wait also polls liveness, because apply_event clears turn_in_flight on TurnComplete but not on a terminal error or a disconnect, so a lagged terminal event would park the launch forever holding the task lock.
X
xintaofei committed
19af22a5a0da558e7ee2945f974cc0a54e59339e
Parent: f240d74