Index
interactive
¶
Interactive instrument execution — tmux-driven live agent sessions.
Instead of single-pass headless execution (claude -p), interactive mode
launches the agent CLI as a live TUI inside an isolated tmux server, submits
the sheet prompt, and a driver state machine pushes the agent to completion.
See docs/specs/2026-06-10-interactive-mode-design.md.
Classes¶
InteractiveCliBackend
¶
Bases: WorkspaceMcpConfigMixin, Backend
Backend that drives a CLI instrument through a live tmux session.
One instance per concurrent interactive sheet (pooled in a free-list
separate from headless instances). All per-attempt state is local to
execute(); the attempt identity set by the adapter is consumed and
cleared each execution, so free-list reuse is inherently clean.
Initialize from an InstrumentProfile with interactive config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
InstrumentProfile
|
Instrument profile; must be kind=cli with a
|
required |
working_directory
|
Path | None
|
Working directory (the sheet workspace). |
None
|
tmux
|
TmuxControl | None
|
TmuxControl override for tests; defaults to the shared
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the profile cannot run interactively. |
Source code in src/marianne/execution/instruments/interactive/backend.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
Attributes¶
Methods:¶
set_output_callback
¶
Set (or clear with None) the live output sink (GH #381).
Receives ("stdout", chunk) for each new slice of the pipe-pane
transcript, once per driver poll. Runs on the event loop; keep it
cheap. Without a transcript (capture failed) nothing is delivered.
Source code in src/marianne/execution/instruments/interactive/backend.py
set_mcp_config
¶
Connect this attempt to the pool via a flag or workspace config file.
set_attempt_identity
¶
Record the attempt identity for session/marker naming.
Called by the baton adapter after acquire, before execute(). Consumed by the next execute() and cleared — never carries across free-list reuse.
Source code in src/marianne/execution/instruments/interactive/backend.py
configure_interactive
¶
configure_interactive(*, max_nudges=None, nudge_message=None, nudge_policy=None, nudge_instrument=None, nudge_timeout_seconds=None, backend_factory=None)
Apply per-sheet interactive knobs from instrument_config.
Source code in src/marianne/execution/instruments/interactive/backend.py
apply_overrides
¶
Apply per-sheet parameter overrides (model).
Source code in src/marianne/execution/instruments/interactive/backend.py
clear_overrides
¶
Restore defaults after execution (called on pool release).
Source code in src/marianne/execution/instruments/interactive/backend.py
set_preamble
¶
Set preamble to prepend to the next prompt.
Direct-use contract: the dispatch path carries the per-attempt
preamble request-locally (SheetRequestState) — see
Backend.set_preamble.
Source code in src/marianne/execution/instruments/interactive/backend.py
set_prompt_extensions
¶
Set prompt extensions to append to the next prompt.
Direct-use contract — see Backend.set_prompt_extensions.
Source code in src/marianne/execution/instruments/interactive/backend.py
effort_refusal
¶
Why this instrument cannot run a sheet at level (None = it can).
Judged as an interactive launch: a mapping whose interactive is
false refuses every level here.
Source code in src/marianne/execution/instruments/interactive/backend.py
tools_refusal
¶
Why this instrument cannot run a sheet with tools (None = it can).
Judged as an interactive launch (a mapping with interactive: false
refuses every list here).
Source code in src/marianne/execution/instruments/interactive/backend.py
execute
async
¶
Execute a prompt by driving a live interactive session.
Returns an ExecutionResult mapped from the driver outcome; never raises for session-level failures (the musician's exception path is reserved for genuine bugs).
Source code in src/marianne/execution/instruments/interactive/backend.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | |
health_check
async
¶
tmux present at a supported version AND the instrument on PATH.
Source code in src/marianne/execution/instruments/interactive/backend.py
ContinuationContext
dataclass
¶
ContinuationPolicy
¶
DriverResult
dataclass
¶
Outcome of one interactive session attempt.
Attributes¶
final_screen
instance-attribute
¶
Last captured rendered screen (plain text). May be empty when the session died before any capture succeeded.
detail
class-attribute
instance-attribute
¶
Human-readable diagnostic for non-completed outcomes.
supervisor_report
class-attribute
instance-attribute
¶
Parsed instrument-supervisor forensic report for this attempt (GH #487).
Present only when the pane ran under supervise: true AND the
supervisor managed to write its report before the pane teardown — an
absent report is itself evidence (external kill; the supervisor never
observed a forwarded signal). Never parsed from the agent's output:
the report is the backend-controlled supervisor's own record.
InteractiveSessionDriver
¶
Drives one agent CLI session to completion inside tmux.
Stateless across attempts: everything attempt-specific is passed to
:meth:run and lives in its locals.
Source code in src/marianne/execution/instruments/interactive/driver.py
Methods:¶
run
async
¶
run(*, session, command, cwd, prompt, marker_path, timeout_seconds, policy, max_nudges, transcript_path=None, supervisor_report_path=None, on_pane_pid=None, env=None, on_output=None)
Run one full attempt: launch, gate, submit, drive, harvest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
str
|
tmux session name (already sanitized, deterministic). |
required |
command
|
list[str]
|
agent argv (executable + args), exec'd directly. |
required |
cwd
|
Path
|
working directory for the agent (the sheet workspace). |
required |
prompt
|
str
|
full prompt text, already carrying the completion
protocol suffix that names |
required |
marker_path
|
Path
|
per-attempt completion marker the agent creates. |
required |
timeout_seconds
|
float
|
overall attempt deadline. |
required |
policy
|
ContinuationPolicy
|
continuation policy consulted on idle. |
required |
max_nudges
|
int
|
consecutive-idle nudge budget (resets when the agent transitions back to verified-busy). |
required |
transcript_path
|
Path | None
|
raw pipe-pane log destination (debug artifact), or None to skip transcript capture. |
None
|
supervisor_report_path
|
Path | None
|
where the instrument supervisor writes its JSON forensic report (GH #487). Read after the attempt ends; an absent/unreadable/malformed report simply means no forensics — it never fails the attempt. |
None
|
on_pane_pid
|
Callable[[int], None] | None
|
callback fired with the pane PID once known — the backend routes this to the baton's process-group registration. |
None
|
on_output
|
Callable[[str, bytes], None] | None
|
live output sink |
None
|
Never raises TmuxError — tmux failures map to session_lost /
startup_failed outcomes. CancelledError propagates (after
cleanup) so musician-task cancellation works unchanged.
Source code in src/marianne/execution/instruments/interactive/driver.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
NudgeDecision
dataclass
¶
An input to send, or a reason the idle session cannot continue.
Abstain: message=None, unrecoverable=False means "nothing to send
right now" — the driver re-polls without spending nudge budget; the
attempt deadline still bounds the loop.
StaticNudgePolicy
¶
ModelNudgePolicy
¶
ModelNudgePolicy(backend_factory, instrument_name, timeout_seconds=30.0, fallback_message=DEFAULT_NUDGE_MESSAGE)
Ask a one-off headless instrument what to type into an idle session.
The caller supplies the factory so service calls do not consume a sheet dispatch slot. Failure leaves the existing static continuation intact.
Source code in src/marianne/execution/instruments/interactive/model_nudge.py
Methods:¶
next_nudge
async
¶
Produce bounded input; propagate cancellation after backend cleanup.
Source code in src/marianne/execution/instruments/interactive/model_nudge.py
TmuxControl
¶
Async control surface over an isolated tmux server.
One instance per socket name; safe to share across sessions (tmux
serializes commands server-side). All methods raise :class:TmuxError
on failure or per-command timeout.
Source code in src/marianne/execution/instruments/interactive/tmux.py
Attributes¶
Methods:¶
version
async
¶
Parse the tmux version, or None when unparseable.
Returns (major, minor); suffixes like 3.4a parse as (3, 4).
Source code in src/marianne/execution/instruments/interactive/tmux.py
new_session
async
¶
Create a detached session running command as the pane process.
The command is passed as an explicit argv tail — tmux execs it
directly (no shell), so the pane process is the agent itself in its
own process group (spike-verified; integration tests pin this).
When supplied, env replaces the server environment via env -i.
The wrapper execs the target, preserving the pane PID/process group.
None retains tmux inheritance for callers without an environment policy.
Source code in src/marianne/execution/instruments/interactive/tmux.py
has_session
async
¶
Whether the session exists on this server.
kill_session
async
¶
Kill the session. Idempotent — a missing session is not an error.
list_sessions
async
¶
List session names on this server, optionally prefix-filtered.
Returns an empty list when the server is not running.
Source code in src/marianne/execution/instruments/interactive/tmux.py
capture_screen
async
¶
Capture the session's rendered screen as plain text.
capture-pane -p without -e renders to plain text — no ANSI
escape sequences (spike-verified), so the result is directly
pattern-matchable.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pane_exit
async
¶
How the pane's process ended, or None while it is still running.
Reads tmux's pane_dead / pane_dead_status / pane_dead_signal
(tmux 3.0+). A vanished session or a tmux failure also reads as None —
the caller already knows the session is unusable and only wants the
cause when tmux still holds the dead pane.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pane_pid
async
¶
The pane process PID, or None when unavailable.
Source code in src/marianne/execution/instruments/interactive/tmux.py
send_keys
async
¶
Send key names (tmux key syntax, e.g. 'Enter', 'Escape').
paste_text
async
¶
Deliver text to the session via a named buffer paste.
Uses load-buffer from a private temp file + bracketed paste
(paste-buffer -p), which delivers arbitrary multiline UTF-8
without key-escaping issues or ARG_MAX limits. The buffer name is
per-session so concurrent sheets never clobber each other; -d
deletes the buffer after pasting. Does NOT submit — callers send
Enter separately.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pipe_pane_to_file
async
¶
Stream the pane's raw output to log_path.
The raw stream is a debug artifact (cursor-addressing soup from
TUIs) — it is never machine-parsed. State detection uses
:meth:capture_screen exclusively.
The file is truncated first (GH #398): transcript names are keyed by job/sheet/attempt, and a later run that reuses that identity must not inherit — and misattribute — a previous run's session content.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pipe_pane_off
async
¶
Stop streaming the pane's output (idempotent).
kill_server
async
¶
Kill the entire tmux server. TESTS ONLY.
Never call from production paths — it destroys every concurrent interactive session on the socket.
Source code in src/marianne/execution/instruments/interactive/tmux.py
TmuxError
¶
Bases: RuntimeError
A tmux control command failed or timed out.
The driver treats any TmuxError during DRIVE as session-lost; during
LAUNCH it is a startup failure. stderr carries tmux's own message
for diagnostics.