backend
backend
¶
InteractiveCliBackend — Backend ABC implementation over tmux sessions.
Executes a sheet by launching the instrument's CLI as a live interactive TUI
in an isolated tmux session and driving it to completion with
:class:InteractiveSessionDriver. The musician calls execute() exactly
like any other backend — interactive mode is invisible above the Backend ABC.
Completion marker = "the agent claims done", mapped to success=True;
validations remain the authoritative arbiter of sheet success (they run on
the workspace after every successful execution, unchanged).
Error classification honours the GH#189 lesson with extra force: the interactive transcript is agent-work-contaminated and there is NO stderr channel. Only the final rendered screen is scanned, only on non-completed outcomes, only with the profile's own vendor patterns — a missed rate limit retries normally; a false positive would burn the instrument fallback chain.
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
Functions:¶
completion_marker_path
¶
Per-attempt completion marker path (lab P0: never workspace-global).
Scoped by job/sheet/attempt so concurrent sheets sharing a workspace can never satisfy each other's done condition, and a stale marker from a prior attempt never instantly completes a new one.
Source code in src/marianne/execution/instruments/interactive/backend.py
session_name
¶
Deterministic tmux session name for one sheet attempt.
Determinism is load-bearing: pre-launch same-name cleanup, per-job
teardown (mzt-{job}-*), and the daemon-startup orphan sweep all rely
on reconstructing these names.