- R1 (P1): without rules the input region runs from the last prompt line to the end of the pane; only a last line matching the adapter's footer pattern (codex: ` <model> · ~/<cwd> · …`) is dropped, so a draft on a second line keeps the nudge withheld. - R2: while the synchronous submit runs, a relay thread finds the job it registers (same session, created since the submit) and prints its stalled:/stall_watch: notices; before, they appeared only after the job. - R3: the broker-unavailable disk wait that runs into the deadline is the wall clock: wall_clock_timeout (caller rc stays 3). - R4: a state_change_seq change seen right before the judgement restarts the idle window (decision 9: S seconds of continuous idle). Regression tests are the reviewer's reproductions, each with its passing twin; the wrapper-level #30 tests now use this environment's broker instead of the #18 harness's public default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
3.4 KiB
Python
79 lines
3.4 KiB
Python
# input_region.py — Rule-based input region extraction and normalization (T2 & T3)
|
|
|
|
import re
|
|
from lib_py.agents.registry import get_adapter
|
|
|
|
def extract_input_region(pane_text: str, agent_name: str) -> str:
|
|
"""
|
|
Extracts the input area text of a pane, using only the agent adapter's facts
|
|
(issue #30, measured on herdr 0.9.1 captures in tests/fixtures/panes):
|
|
|
|
1. an `input_block_prefix` -> the last contiguous block of lines starting
|
|
with it, prefix removed, cut at the first `input_stop_pattern` line;
|
|
2. two or more `input_rule_pattern` rules -> the lines between the last two;
|
|
3. an `input_prompt` -> from the last line starting with the prompt to
|
|
the end of the pane, minus a last non-blank line matching
|
|
`input_stop_pattern` (the status footer). Every other line below the
|
|
prompt line is input: a multi-line draft is never cut to its first line.
|
|
|
|
Then `input_frame_chars`, the prompt and the placeholder are stripped. There
|
|
is no whole-pane fallback: a pane with none of these shapes has no input
|
|
region and yields a non-empty "unknown" result rather than a guess.
|
|
Raises ValueError for agents without input area facts (like hermes' peers).
|
|
"""
|
|
adapter = get_adapter(agent_name)
|
|
if not adapter or not adapter.input_prompt:
|
|
raise ValueError(f"Agent {agent_name!r} has no input area facts")
|
|
|
|
lines = pane_text.splitlines()
|
|
prompt = adapter.input_prompt
|
|
region_lines = None
|
|
|
|
if adapter.input_block_prefix:
|
|
prefix = adapter.input_block_prefix
|
|
block = []
|
|
for line in reversed(lines):
|
|
if line.lstrip().startswith(prefix):
|
|
block.insert(0, line.lstrip()[len(prefix):])
|
|
elif block:
|
|
break
|
|
stop_re = re.compile(adapter.input_stop_pattern) if adapter.input_stop_pattern else None
|
|
for i, line in enumerate(block):
|
|
if stop_re and stop_re.search(line):
|
|
block = block[:i]
|
|
break
|
|
# No block on screen is not an empty box: fall through to the other shapes.
|
|
region_lines = block or None
|
|
|
|
if region_lines is None and adapter.input_rule_pattern:
|
|
rule_re = re.compile(adapter.input_rule_pattern)
|
|
rule_indices = [i for i, line in enumerate(lines) if rule_re.search(line)]
|
|
if len(rule_indices) >= 2:
|
|
region_lines = lines[rule_indices[-2] + 1:rule_indices[-1]]
|
|
|
|
if region_lines is None:
|
|
starts = [i for i, line in enumerate(lines) if line.lstrip().startswith(prompt)]
|
|
if starts:
|
|
region_lines = [line for line in lines[starts[-1]:]]
|
|
while region_lines and not region_lines[-1].strip():
|
|
region_lines.pop()
|
|
if (len(region_lines) > 1 and adapter.input_stop_pattern
|
|
and re.search(adapter.input_stop_pattern, region_lines[-1])):
|
|
region_lines.pop()
|
|
else:
|
|
# No input line at all: report the whole tail as "not empty" (unknown).
|
|
region_lines = [pane_text or '?']
|
|
|
|
frame = adapter.input_frame_chars
|
|
if frame:
|
|
region_lines = [line.strip().strip(frame) for line in region_lines]
|
|
|
|
region_text = "\n".join(region_lines)
|
|
region_text = re.sub(r'^\s*' + re.escape(prompt) + r'\s*', '', region_text, flags=re.MULTILINE)
|
|
|
|
placeholder = adapter.input_placeholder
|
|
if placeholder:
|
|
region_text = region_text.replace(placeholder, '')
|
|
|
|
return region_text.strip()
|