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
4 changes: 2 additions & 2 deletions bin/fm-helm-refresh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# - state/.stow-guard.json holds an offer for exactly that session id (the
# id in state/.lock-session), made within FM_HELM_REFRESH_OFFER_TTL seconds
# (default 7200) by bin/fm-stow-guard.sh's prompt hook when the captain
# typed /stow, so a /stow the stow guard asked for, or an agent or the
# fleet started, never restarts the helm;
# typed /stow (not /stow quick), so a quick save, a /stow the stow guard
# asked for, or one an agent or the fleet started, never restarts the helm;
# - this process runs in a tmux or Herdr pane bin/fm-primary-pane-lib.sh
# can prove;
# - state/.afk and state/.afk-contract are absent;
Expand Down
10 changes: 9 additions & 1 deletion bin/fm-stow-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
# state file, when a submitted prompt is /stow itself: after trimming
# whitespace, exactly /stow or /stow followed by whitespace and arguments
# (Claude Code 2.1.328 puts a typed /stow in the payload's prompt as typed;
# docs/verification/supervision.md "Helm refresh by /clear"). It also needs a
# docs/verification/supervision.md "Helm refresh by /clear"), except when its
# first argument word is quick, in any case: a quick save never claims reset-safe, so a
# /stow quick records no offer. It also needs a
# Claude session id, this session holding state/.lock under that same id in
# state/.lock-session, and a tmux or Herdr pane bin/fm-primary-pane-lib.sh
# can name. Anything that reaches the session as fleet input (a from-firstmate
Expand Down Expand Up @@ -155,6 +157,12 @@ if [ "$mode" = prompt ]; then
/stow|/stow[[:space:]]*) ;;
*) exit 0 ;;
esac
# A quick save never claims reset-safe, so its offer could only expire.
stow_args=${prompt#/stow}
stow_args=${stow_args#"${stow_args%%[![:space:]]*}"}
case "$stow_args" in
[Qq][Uu][Ii][Cc][Kk]|[Qq][Uu][Ii][Cc][Kk][[:space:]]*) exit 0 ;;
esac
# shellcheck source=bin/fm-session-lock-lib.sh
. "$SCRIPT_DIR/fm-session-lock-lib.sh" >/dev/null 2>&1 || exit 0
fm_session_lock_owned_by_self "$STATE" >/dev/null 2>&1 || exit 0
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@ The script header owns the transcript read, the state file, and the block messag

With `restart=1`, a `/stow` the captain types himself in the primary's tmux or Herdr pane offers a fresh restart in place of compaction, through the same script's UserPromptSubmit hook.
A `/stow` that the guard's own ask, an agent, or the stow cascade starts makes no offer, so it saves and keeps the session.
A typed `/stow quick` makes no offer either, because a quick save never claims reset-safe.
A quick save never asks the fresh-start question, even when the captain types `/stow quick`.
When the typed `/stow`'s receipt says the session is reset-safe, the primary asks the captain whether to start fresh now or keep the session.
Only "Start fresh now" runs `bin/fm-helm-refresh.sh request`, and once its turn ends the session is cleared with Claude Code's `/clear` and started again by one doorbell.
Expand Down
1 change: 1 addition & 0 deletions docs/fork-decisions/2026-11-22-typed-stow-restarts-helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Decision: a `/stow` the captain types in the Claude helm runs the pass as normal
The `/stow` the stow guard asks for saves everything and keeps the session, and a receipt that is not reset-safe asks nothing.
This supersedes the offer half of [the helm fresh restart record](2026-11-22-helm-fresh-restart-after-stow.md), whose restart ran only "for a session the guard asked"; the `/clear` refresh mechanics it records are unchanged.
The stow guard gains a UserPromptSubmit mode that records `offer:{sid, at}` in `state/.stow-guard.json` when the lock-holding primary's prompt is `/stow` itself, and its Stop ask no longer offers or records a restart, so the typed `/stow` is the one offer source and `bin/fm-helm-refresh.sh request` stays its one reader.
A typed `/stow quick` records nothing either, because a quick save never claims reset-safe (amended 2026-11-22).
A `/stow` that an agent, a secondmate home or the stow cascade sends records nothing, and every other refusal in `request` is unchanged.
The guard's own ask state (`fired`, `last_stow`, `asked`) is left alone, because a Stop hook cannot tell which turn it ends and that state is what stops a compaction without a stow.
So a typed `/stow` whose own turn ends over the token line still gets the guard's ask and a second pass, as before, and its offer survives it.
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ The shared no-mistakes gate lifecycle boundary is summarized in [architecture.md
| `fm-role-lib.sh` | The home role and self-repository publication consent |
| `fm-role.sh` | Report and check this home's firstmate role |
| `fm-sessionstart-agy.sh` | Antigravity CLI (agy) session-open hook transport to `fm-sessionstart-run.sh` |
| `fm-stow-guard.sh` | Opt-in Claude Stop hook that asks a primary session to `/stow` before context compaction, and with `prompt`, the UserPromptSubmit hook that records a fresh-restart offer for a `/stow` the captain types |
| `fm-stow-guard.sh` | Opt-in Claude Stop hook that asks a primary session to `/stow` before context compaction, and with `prompt`, the UserPromptSubmit hook that records a fresh-restart offer for a `/stow` the captain types, except `/stow quick` |
| `fm-supervision-handoff.sh` | Private Claude host hand-back owner, enabled by `config/supervision-handoff-ack` |
| `fm-test-linux.sh` | Opt-in: run the shell tests changed on this branch inside a Linux container with GNU userland |
| `fm-test-tap-verify.sh` | Prove a TAP-planned suite actually finished |
Expand Down
15 changes: 14 additions & 1 deletion tests/fm-stow-guard.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,25 @@ test_typed_stow_records_the_offer() {
|| fail "the Stop dropped the typed /stow's offer: $(cat "$CASE_STATE/.stow-guard.json")"

prepare_prompt_case typed-stow-args
invoke_prompt "$PRIMARY" "$(prompt_payload $' /stow quick\n')" \
invoke_prompt "$PRIMARY" "$(prompt_payload $' /stow quickly\n')" \
TMUX_PANE= HERDR_ENV=1 HERDR_PANE_ID=w1:p1
jq -e --arg sid "$PROMPT_SID" '.offer == {sid:$sid, at:5000}' "$CASE_STATE/.stow-guard.json" >/dev/null \
|| fail "a typed /stow with arguments in a Herdr pane recorded no offer: $(cat "$CASE_STATE/.stow-guard.json" 2>/dev/null)"
pass "a /stow the lock session types records only the restart offer, and the guard's next ask carries it through"
}

test_typed_stow_quick_records_no_offer() {
local prompt n=0
local -a prompts=('/stow quick' $' /stow\tquick \n' '/stow quick extra words' $'/stow\nquick' '/stow QUICK')
for prompt in "${prompts[@]}"; do
n=$((n + 1))
prepare_prompt_case "typed-stow-quick-$n"
invoke_prompt "$PRIMARY" "$(prompt_payload "$prompt")"
assert_no_offer "typed quick prompt $n"
done
pass "a typed /stow quick records no restart offer"
}

test_fleet_sent_stow_records_no_offer() {
local prompt label mark=$'\xE2\x81\xA3' n=0
local -a prompts=(
Expand Down Expand Up @@ -684,6 +696,7 @@ fm_test_run \
test_context_crossing_blocks_once_until_rearm \
test_guard_ask_never_offers_a_restart \
test_typed_stow_records_the_offer \
test_typed_stow_quick_records_no_offer \
test_fleet_sent_stow_records_no_offer \
test_typed_stow_outside_the_primary_session_records_no_offer \
test_continuation_stop_blocks_once_per_crossing \
Expand Down
Loading