diff --git a/bin/fm-composer-lib.sh b/bin/fm-composer-lib.sh index f51e819750a..db8d17af48a 100644 --- a/bin/fm-composer-lib.sh +++ b/bin/fm-composer-lib.sh @@ -875,15 +875,12 @@ fm_composer_classify_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() { # - local row=$1 spinner prefix suffix title + local row=$1 spinner FM_COMPOSER_PI_ROW_LABELLED=0 [ -n "$row" ] || return 1 case "$row" in @@ -895,18 +892,10 @@ _fm_composer_pi_separator_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 } @@ -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 @@ -1023,7 +1011,7 @@ _fm_composer_scan_screen() { # [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 @@ -1068,10 +1056,18 @@ _fm_composer_scan_screen() { # [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 @@ -1085,16 +1081,21 @@ _fm_composer_scan_screen() { # [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 @@ -1103,11 +1104,29 @@ _fm_composer_scan_screen() { # [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 @@ -1995,28 +2014,6 @@ EOF return 0 } -# _fm_composer_bare_rule_sandwich: 0 when bare agent-glyph 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() { # - 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 [pi-compact]: is 1 only # when THIS call's caps carry pi-compact=1; it defaults to 0. _fm_composer_select_cursorless() { @@ -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. diff --git a/docs/herdr-backend.md b/docs/herdr-backend.md index 4ddc0ae6966..832e75a8946 100644 --- a/docs/herdr-backend.md +++ b/docs/herdr-backend.md @@ -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 diff --git a/docs/verification/runtime-backends.md b/docs/verification/runtime-backends.md index 51ff07200a1..73d33494e98 100644 --- a/docs/verification/runtime-backends.md +++ b/docs/verification/runtime-backends.md @@ -1098,7 +1098,7 @@ CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false claude -n herdr: unknown claude -n 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`: diff --git a/tests/fm-composer-lib.test.sh b/tests/fm-composer-lib.test.sh index 2f144c7e676..3bd602b0ba1 100755 --- a/tests/fm-composer-lib.test.sh +++ b/tests/fm-composer-lib.test.sh @@ -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" @@ -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. @@ -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