CheckpointRewindController constructor

CheckpointRewindController({
  1. required Agent agent,
  2. required CheckpointSessionSink sink,
  3. void onRewindApplied(
    1. int messageCount
    )?,
  4. CheckpointAutoCloseCallback? onAutoClose,
})

Creates a controller and attaches it to agent: subscribes to the event stream and wraps Agent.prepareNextTurn (preserving any existing hook, the same composition pattern attachApproval uses).

onRewindApplied fires after each applied rewind with the new in-memory message count, so the host can realign its persistence cursor (the pruned detour and the report are already persisted by then).

onAutoClose fires after each auto-close, with the reason and the closed checkpoint — the audit record is already persisted. The host hooks its budget guard here (gh-1425 AC4: a user turn that ends a detour leaves the FULL detour history live; the host caps it against its compaction budget before the next request).

Implementation

CheckpointRewindController({
  required Agent agent,
  required CheckpointSessionSink sink,
  void Function(int messageCount)? onRewindApplied,
  CheckpointAutoCloseCallback? onAutoClose,
}) : _agent = agent,
     _sink = sink,
     _onRewindApplied = onRewindApplied,
     _onAutoClose = onAutoClose {
  _unsubscribe = _agent.subscribe(_onAgentEvent);
  _wrapPrepareNextTurn();
}