Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 49 additions & 58 deletions bin/fm-composer-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -875,15 +875,12 @@ fm_composer_classify_content() { # <bordered> <content> [idle_re] [idle_case] [
# exact positive proof they require (`empty`), so unrecognized future verdicts
# fail safe by default.

# _fm_composer_pi_separator_row: a solid separator of at least 8 `─` glyphs,
# or a titled rule with that prefix and a closing `──` suffix. Claude
# under Herdr uses the titled form above its bare `❯` row and a solid rule
# below it. The width floor uses literal glyphs in every locale. Both rules
# must be seen before the row becomes a proven composer. A working Pi labels
# its top rule with a spinner; the verdict admits that rule only under native
# `working` status.
# _fm_composer_pi_separator_row: a solid pi separator - nothing but `─`, at
# least 8 columns wide. The width floor is a literal substring test so it is
# byte-exact in every locale. A working Pi labels its top rule with a spinner;
# the verdict admits that rule only under native `working` status.
_fm_composer_pi_separator_row() { # <trimmed-row>
local row=$1 spinner prefix suffix title
local row=$1 spinner
FM_COMPOSER_PI_ROW_LABELLED=0
[ -n "$row" ] || return 1
case "$row" in
Expand All @@ -895,18 +892,10 @@ _fm_composer_pi_separator_row() { # <trimmed-row>
FM_COMPOSER_PI_ROW_LABELLED=1
;;
esac
if [ -z "${row//─/}" ]; then
case "$row" in *────────*) return 0 ;; esac
return 1
fi
prefix=${row%% *}
suffix=${row##* }
title=${row#"$prefix "}
title=${title%" $suffix"}
[ -z "${prefix//─/}" ] && [ -z "${suffix//─/}" ] \
&& [ -n "$title" ] && [ "$title" != "$row" ] || return 1
case "$prefix" in *────────*) ;; *) return 1 ;; esac
case "$suffix" in *──*) return 0 ;; esac
[ -z "${row//─/}" ] || return 1
case "$row" in
*────────*) return 0 ;;
esac
return 1
}

Expand Down Expand Up @@ -948,8 +937,7 @@ EOF
#
# This is deliberately NOT a relaxation of _fm_composer_pi_separator_row, and
# the two must not be merged: that predicate also feeds the pi identity
# conjunction, so it stays strictly dashes-only. This one has the single
# consumer _fm_composer_bare_rule_sandwich.
# conjunction, so it stays strictly dashes-only.
#
# The row must OPEN with the same 8-column dash run the strict separator
# requires. Width is proven by comparing canonical space strings, never by
Expand Down Expand Up @@ -1023,7 +1011,7 @@ _fm_composer_scan_screen() { # <plain-screen> <cursor-or-empty> [extract-wrap]
FM_COMPOSER_SCAN_PI_GLYPH=
FM_COMPOSER_SCAN_LEFTBAR_GLYPH_ROW=-1
FM_COMPOSER_SCAN_LEFTBAR_GLYPH=
local leftbar_start=-1 pi_open=-1 pi_open_labelled=0 pi_lines=0 pi_max
local leftbar_start=-1 pi_open=-1 pi_open_rule='' pi_open_labelled=0 pi_lines=0 pi_max
local probe row_glyph row_glyph_row
local box_glyph_row=-1 box_glyph='' pi_glyph_row=-1 pi_glyph=''
local pi_status_rows='' status_row footer_run=0 footer_row=-1 footer_close=-1
Expand Down Expand Up @@ -1068,10 +1056,18 @@ _fm_composer_scan_screen() { # <plain-screen> <cursor-or-empty> [extract-wrap]
row_glyph_row=$row
fi
fi
# Pi separator rows: a solid `─` rule at least 8 columns wide. A separator
# closes the preceding candidate and immediately opens the next, so an
# earlier transcript rule can never outrank the live bottom composer pair.
# Each solid separator closes the preceding candidate and opens the next.
# Every newer rule retires earlier pair proof before validation, including
# a titled candidate that later fails width, title, or glyph proof, so an
# earlier transcript pair cannot stand in for the live composer.
if _fm_composer_pi_separator_row "$trimmed"; then
FM_COMPOSER_SCAN_PI_PAIR_FOUND=0
FM_COMPOSER_SCAN_PI_PAIR_VALID=0
FM_COMPOSER_SCAN_PI_OPEN=-1
FM_COMPOSER_SCAN_PI_CLOSE=-1
FM_COMPOSER_SCAN_PI_OPEN_LABELLED=0
FM_COMPOSER_SCAN_PI_GLYPH_ROW=-1
FM_COMPOSER_SCAN_PI_GLYPH=
FM_COMPOSER_SCAN_PI_LAST_SEPARATOR=$row
footer_run=1
footer_row=-1
Expand All @@ -1085,16 +1081,21 @@ _fm_composer_scan_screen() { # <plain-screen> <cursor-or-empty> [extract-wrap]
FM_COMPOSER_SCAN_PI_COMPACT_OPEN=$top
FM_COMPOSER_SCAN_PI_COMPACT_CLOSE=$row
fi
if [ "$pi_open" -ge 0 ]; then
if [ "$pi_open" -ge 0 ] \
&& { [ -z "$pi_open_rule" ] \
|| { [ "$pi_glyph_row" -ge 0 ] \
&& _fm_composer_titled_rule_row "$pi_open_rule" "${trimmed//─/ }"; }; }; then
FM_COMPOSER_SCAN_PI_PAIR_FOUND=1
FM_COMPOSER_SCAN_PI_OPEN=$pi_open
FM_COMPOSER_SCAN_PI_CLOSE=$row
FM_COMPOSER_SCAN_PI_OPEN_LABELLED=$pi_open_labelled
# Titled envelopes support bare-glyph selection and footer demotion,
# but only a strict separator pair may prove Pi identity.
# A pair must ENCLOSE at least one row to hold an input row at all:
# two adjacent rules are a divider, not a composer, and a zero-height
# region trivially satisfies every content check, which read `empty`
# and authorized injection into a region with nowhere to type.
if [ "$pi_lines" -ge 1 ] && [ "$pi_lines" -le "$pi_max" ]; then
if [ -z "$pi_open_rule" ] && [ "$pi_lines" -ge 1 ] && [ "$pi_lines" -le "$pi_max" ]; then
FM_COMPOSER_SCAN_PI_PAIR_VALID=1
else
FM_COMPOSER_SCAN_PI_PAIR_VALID=0
Expand All @@ -1103,11 +1104,29 @@ _fm_composer_scan_screen() { # <plain-screen> <cursor-or-empty> [extract-wrap]
FM_COMPOSER_SCAN_PI_GLYPH=$pi_glyph
fi
pi_open=$row
pi_open_rule=''
pi_open_labelled=$FM_COMPOSER_PI_ROW_LABELLED
pi_lines=0
pi_glyph_row=-1
pi_glyph=''
else
case "$trimmed" in
────────*)
FM_COMPOSER_SCAN_PI_PAIR_FOUND=0
FM_COMPOSER_SCAN_PI_PAIR_VALID=0
FM_COMPOSER_SCAN_PI_OPEN=-1
FM_COMPOSER_SCAN_PI_CLOSE=-1
FM_COMPOSER_SCAN_PI_OPEN_LABELLED=0
FM_COMPOSER_SCAN_PI_GLYPH_ROW=-1
FM_COMPOSER_SCAN_PI_GLYPH=
pi_open=$row
pi_open_rule=$trimmed
pi_open_labelled=0
pi_lines=0
pi_glyph_row=-1
pi_glyph=''
;;
esac
if [ "$pi_open" -ge 0 ]; then
pi_lines=$((pi_lines + 1))
if [ "$pi_glyph_row" -lt 0 ] && [ "$row_glyph_row" -ge 0 ]; then
Expand Down Expand Up @@ -1995,28 +2014,6 @@ EOF
return 0
}

# _fm_composer_bare_rule_sandwich: 0 when bare agent-glyph <row> sits in its
# own titled composer: a titled rule directly above it and the screen's only
# unmatched separator directly below it, which is that composer's closing rule.
#
# The cursorless staleness rule reads an unmatched separator BELOW a candidate
# as proof the candidate is scrollback. A titled top rule never opens the
# separator pair, so the composer's own closing rule becomes that unmatched
# separator and a genuinely idle composer read `unknown`. Adjacency on BOTH
# edges keeps the staleness rule intact everywhere else: a glyph stranded in
# scrollback has transcript rows, not its own rules, around it.
_fm_composer_bare_rule_sandwich() { # <plain-screen> <row>
local plain=$1 row=$2 above below
[ "$row" -ge 1 ] || return 1
[ "$FM_COMPOSER_SCAN_PI_LAST_SEPARATOR" -eq "$((row + 1))" ] || return 1
below=$(_fm_composer_screen_row "$((row + 1))" "$plain")
fm_composer_normalize_trim_var below
_fm_composer_pi_separator_row "$below" || return 1
above=$(_fm_composer_screen_row "$((row - 1))" "$plain")
fm_composer_normalize_trim_var above
_fm_composer_titled_rule_row "$above" "${below//─/ }"
}

# _fm_composer_select_cursorless <plain> [pi-compact]: <pi-compact> is 1 only
# when THIS call's caps carry pi-compact=1; it defaults to 0.
_fm_composer_select_cursorless() {
Expand Down Expand Up @@ -2082,14 +2079,8 @@ _fm_composer_select_cursorless() {
fi
if [ "$FM_COMPOSER_SCAN_PI_PAIR_FOUND" = 0 ] \
&& [ "$FM_COMPOSER_SCAN_PI_LAST_SEPARATOR" -gt "$generic" ]; then
# Spare only a bare glyph inside its own titled composer rules; see
# _fm_composer_bare_rule_sandwich for why that shape is not scrollback.
if ! { [ "$FM_COMPOSER_SELECTED_KIND" = bare ] \
&& [ "$generic" = "$FM_COMPOSER_SCAN_BARE_ROW" ] \
&& _fm_composer_bare_rule_sandwich "$plain" "$FM_COMPOSER_SCAN_BARE_ROW"; }; then
FM_COMPOSER_SELECTED_KIND=
return 1
fi
FM_COMPOSER_SELECTED_KIND=
return 1
fi
# Pi's footer status row is furniture only under the pi pair it hangs from;
# below any other selected shape it is a dead-shell row like any other.
Expand Down
3 changes: 2 additions & 1 deletion docs/herdr-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@ It hands the visible pane's ANSI viewport plus Herdr's capability facts to the f
- Bare agent-glyph rows, including muse's `⟩`, which the adapter's retired local pattern silently omitted.
- opencode's left bar.
- The Pi separator region this adapter pioneered, admitted only when native `agent get` identity is exactly Pi and state is idle, done, or working.
- Claude's rule-framed composer under Herdr: a titled opening rule (`──── Title ──`) and a plain closing rule around a bare `❯` row.
- Claude's rule-framed composer under Herdr: an opening rule beginning with at least eight `─` glyphs and carrying an ASCII-printable session title, matched in width by a plain closing rule around a bare `❯` row and any wrapped input.
Non-ASCII session titles remain `unknown`, so delivery waits.
- Cortex Code's titled rounded top rule, admitted only when native `agent get` identity is exactly `cortex`, which the adapter reads lazily and only when the classifier answers `need-identity` for a titled rounded box holding an agent prompt glyph; the same box on any other pane stays ambiguous, and Cortex is [verified](verification/cortex.md) on Herdr for crewmates and scouts only.

### Pi composer states
Expand Down
2 changes: 1 addition & 1 deletion docs/verification/runtime-backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false claude -n <name> herdr: unknown
claude -n <name> tmux: empty (typed text: pending)
```

The classifier now accepts a bare agent-glyph row sandwiched between a width-proven titled top rule and its solid closing rule (`_fm_composer_titled_rule_row` and `_fm_composer_bare_rule_sandwich` in `bin/fm-composer-lib.sh`, issues #5601 and #5558).
Current named-composer support and title limits are documented in [Composer and injection safety](../herdr-backend.md#composer-and-injection-safety).
After the fix the named Herdr pane read `empty`, and the daemon's real injection path wrote the operational record, typed the doorbell, sent Enter, and confirmed the submit on that pane.
`test_matrix_claude_named_session_titled_rule` in `tests/fm-composer-lib.test.sh` pins idle, ghost-suggestion, typed, and extraction cases on every capability profile, the unnamed ghost case, and the Pi blank-row non-regression.
The composer-matrix guard's `claude-named` arm requires the cursorless read of a real named Claude pane to be exactly `empty`:
Expand Down
79 changes: 78 additions & 1 deletion tests/fm-composer-lib.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,16 @@ test_matrix_claude_arrow_statusline_footer() {
test_matrix_herdr_titled_claude_composer() {
# Synthetic replay of the screen shape reported in upstream issue #6127.
# The titled opening rule and plain closing rule enclose Claude's bare input.
local head foot screen typed content claude_working out
local head foot screen typed content claude_working pi_idle out
head=$'────────────────────────── Firstmate ──\n❯'
foot=$'\n───────────────────────────────────────\n Opus 5 (1M context) │ firstmate │ main │ fleet idle'
claude_working=$(printf 'claude\tworking')
screen="$head$foot"
pi_idle=$(printf 'pi\tidle')
assert_screen "non-ASCII Herdr title defers" unknown "$CAPS_STYLED" \
"${screen/Firstmate/Fïrstmate}" '' "$claude_working"
assert_screen "Herdr title cannot prove a blank Pi composer" unknown "$CAPS_STYLED" \
"${screen/❯/}" '' "$pi_idle"
assert_screen "idle Claude under a titled Herdr rule" empty "$CAPS_STYLED" "$screen" '' "$claude_working"
typed="${head} Firstmate instruction waiting${foot}"
assert_screen "pending Claude doorbell under a titled Herdr rule" pending "$CAPS_STYLED" "$typed" '' "$claude_working"
Expand All @@ -287,6 +292,76 @@ test_matrix_herdr_titled_claude_composer() {
pass "matrix: titled Herdr rules preserve Claude's empty and pending composer verdicts"
}

test_matrix_herdr_titled_claude_wrapping_and_footer() {
local head close footer idle typed wrapped screen caps want content identity locale
head=$'────────────────────────── Firstmate ──\n❯'
close=$'\n───────────────────────────────────────'
footer=$'\n → repo git:(main) | Opus 5\n ⏵⏵ bypass permissions on'
identity=$(printf 'claude\tidle')
idle="$head$close"
typed="$head message$close"
wrapped="$head message"$'\ncontinuation row'"$close"
for caps in "$CAPS_STYLED" "$CAPS_STYLED_NOID" "$CAPS_PLAIN"; do
want=pending
[ "$caps" != "$CAPS_PLAIN" ] || want=unknown
assert_screen "wrapped titled Claude draft" "$want" "$caps" "$wrapped" '' "$identity"
assert_screen "idle titled Claude under arrow footer" empty "$caps" "$idle$footer" '' "$identity"
assert_screen "typed titled Claude under arrow footer" "$want" "$caps" "$typed$footer" '' "$identity"
assert_screen "wrapped titled Claude under arrow footer" "$want" "$caps" "$wrapped$footer" '' "$identity"
for locale in "${LC_ALL:-${LANG:-C}}" C; do
content=$(LC_ALL="$locale" fm_composer_extract_selected_content "$caps" "$idle$footer") \
|| fail "idle titled Claude content must extract under $locale"
[ -z "$content" ] || fail "idle titled Claude extracted footer under $locale: '$content'"
for screen in "$wrapped" "$wrapped$footer"; do
content=$(LC_ALL="$locale" fm_composer_extract_selected_content "$caps" "$screen") \
|| fail "wrapped titled Claude content must extract under $locale"
[ "$content" = 'message continuation row' ] \
|| fail "wrapped titled Claude must retain its whole draft under $locale: '$content'"
done
done
done
assert_screen "wrapped titled Claude with cursor on continuation" pending "$CAPS_TMUX" "$wrapped" 2 "$identity"
assert_screen "titled glyph envelope cannot prove Pi identity" unknown "$CAPS_STYLED" "$idle" '' $'pi\tidle'
for screen in "${wrapped/Firstmate/Fïrstmate}" "${wrapped/Firstmate/Firstmates}"; do
assert_screen "unproven title cannot rescue wrapped draft" unknown "$CAPS_STYLED" "$screen" '' "$identity"
done
pass "matrix: ASCII titled Claude envelopes preserve wrapped drafts and demote arrow footers"
}

test_matrix_rejected_titled_composer_retires_prior_pair() {
local title close prior rejected screen caps identity locale content
title='────────────────────────── Firstmate ──'
close='───────────────────────────────────────'
for prior in $'────────\nold output\n────────\n' \
$'────────\n❯ old draft\n────────\n'; do
for rejected in "${title/Firstmate/Fïrstmate}"$'\n❯\n'"$close" \
"${title/Firstmate/Firstmates}"$'\n❯\n'"$close" \
"$title"$'\n\n'"$close" \
"${title/Firstmate/Fïrstmate}"; do
screen="$prior$rejected"
for caps in "$CAPS_STYLED" "$CAPS_STYLED_NOID" "$CAPS_PLAIN"; do
for identity in '' $'claude\tidle' $'pi\tidle'; do
assert_screen "rejected titled composer supersedes transcript pair" unknown \
"$caps" "$screen" '' "$identity"
done
for locale in "${LC_ALL:-${LANG:-C}}" C; do
if content=$(LC_ALL="$locale" fm_composer_extract_selected_content "$caps" "$screen"); then
fail "rejected titled composer must not extract prior input under $locale: '$content'"
fi
done
done
done
screen="$prior$title"$'\n❯ message\ncontinuation row\n'"$close"
assert_screen "valid titled composer supersedes transcript pair" pending \
"$CAPS_STYLED" "$screen" '' $'claude\tidle'
content=$(fm_composer_extract_selected_content "$CAPS_STYLED" "$screen") \
|| fail "valid replacement titled composer must extract its draft"
[ "$content" = 'message continuation row' ] \
|| fail "valid replacement titled composer extracted stale content: '$content'"
done
pass "matrix: rejected titled composers cannot inherit transcript pair proof"
}

test_composer_footer_demotion_needs_a_proven_pair() {
# The demotion is bounded in three directions, and each bound is a case
# where a lower glyph row IS the live composer.
Expand Down Expand Up @@ -1845,6 +1920,8 @@ test_matrix_claude_bare_nbsp_row
test_matrix_claude_named_session_titled_rule
test_matrix_claude_arrow_statusline_footer
test_matrix_herdr_titled_claude_composer
test_matrix_herdr_titled_claude_wrapping_and_footer
test_matrix_rejected_titled_composer_retires_prior_pair
test_composer_footer_demotion_needs_a_proven_pair
test_composer_footer_zone_is_shape_independent
test_composer_footer_zone_refuses_rather_than_allows
Expand Down
Loading