Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 19 additions & 4 deletions .agents/skills/stow/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: stow
description: >-
Sweep the session for uncaptured durable knowledge and unfiled or wrong open work records, and curate startup memory.
Use when the captain invokes /stow (e.g. "/stow", "stow what you've learned"), before a session reset or context compaction, or periodically to keep operational memory current.
Use when the captain invokes /stow (e.g. "/stow", "stow what you've learned"), before a session reset or context compaction, or periodically to keep operational memory current; `/stow quick` is the short save the stow guard asks for at its token line.
user-invocable: true
metadata:
internal: true
Expand All @@ -16,6 +16,20 @@ Sweep this session for durable knowledge and open-work record state that exist o
Memory entries are tiered and decay between passes, and stale material retires to a cold archive instead of being deleted.
This skill writes only through the existing Firstmate ownership and write boundaries.

## Quick save (`/stow quick`)

The mode is chosen by the first argument word: `quick`, in any case, selects the quick save, and anything else, including no argument, is the full pass every other section describes.
A `/stow` the captain types with no argument is always the full pass.
The stow guard asks for the quick save at its token line, because the full pass does not fit between that line and compaction; its daily age ask still asks for the full pass ([Stow guard](../../../docs/configuration.md#stow-guard-configstow-guard)).

The quick save runs only [Knowledge sweep and routing](#knowledge-sweep-and-routing) and [Open-record persistence](#open-record-persistence): file unfiled findings, correct stale row notes, and record each captain answer held only in conversation through `bin/fm-captain-hold.sh answer`.
It skips the whole required startup-memory pass, so it reads no memory file in full and runs no decay, migration, consolidation, budget eviction, or offload; it also skips the cascade and the restart question.
Within the sweep, it leaves existing memory entries alone: archiving, offloading, consolidating, and retiring superseded copies of a ruling in memory all wait for the next full pass, while it still records answers and corrects open records.
A finding that would replace or contradict an existing memory entry, such as a changed captain ruling, gets no new memory entry either: record a captain answer on its origin row, leave any other such finding on its task row or in the receipt, and leave the memory write to the full pass.
It adds any other new startup-memory entry, a pending-capture fallback included, only when `bin/fm-startup-memory-budget.sh report` shows the new entry fits within the effective budget; otherwise leave the finding on its task row, or in the receipt when it has none, for the next full pass.
Its receipt is a few lines: what it filed or corrected, and anything it left for the full pass.
It never says the session is reset-safe, so it never asks the captain to start fresh, even after a `/stow quick` he typed.

## Memory tiers and entry markers

Markers are compact trailing HTML comments, deliberately cheap because marker bytes are counted content:
Expand Down Expand Up @@ -81,7 +95,7 @@ While the flag is present:

## Required startup-memory pass

Every `/stow` invocation performs this complete pass, even when the session contains no new finding:
Every full `/stow` pass performs this complete pass, even when the session contains no new finding; only the [quick save](#quick-save-stow-quick) skips it:

1. Run `bin/fm-startup-memory-budget.sh report` before considering a write.
Record its effective budget and each file's estimated-token total.
Expand Down Expand Up @@ -229,7 +243,7 @@ A local skill exists only in this home, so offloading an entry out of `data/capt
Match each finding against the home's declared memory tiers first and capture a tier-owned finding to that tier, falling back to the local files only for classes no declared tier owns.
When the owning tier is unreachable from this session, write the finding to the startup-loaded local memory file its class would otherwise use, or keep it where it already lives, carrying the pending-capture marker for that tier; it is still an exception for the receipt, never a reason to treat the local copy as sufficient.
3. **Write within the existing boundaries.**
- Captain preferences and fleet-local operational facts belong in the destination selected by AGENTS.md after the required whole-file curation pass.
- Captain preferences and fleet-local operational facts belong in the destination selected by AGENTS.md after the required whole-file curation pass, which a quick save replaces with its budget check.
Create `data/learnings.md` only for a genuinely new local learning with no stronger owner.
- In a primary home, curate shared captain preferences only under the existing primary-authoritative shared-preference contract.
In a secondmate home, route a newly discovered shared preference to the main firstmate through marked status or a document pointer instead of editing the inherited file.
Expand Down Expand Up @@ -272,6 +286,7 @@ The first pass after adoption performs a one-time revalidation sweep of editable

## Completion receipt

This is the full pass's receipt; the [quick save](#quick-save-stow-quick) writes its own short one.
Report the outcome in plain captain-facing language with all of these facts:

- effective startup-memory budget and total estimated tokens before and after;
Expand All @@ -295,7 +310,7 @@ Apart from that re-run for his answer, ask nothing and leave `request` unrun aft

## Automatic cascade to secondmates

In a primary home, every `/stow` cascades to every registered secondmate after this home's own required pass and knowledge sweep are complete.
In a primary home, every full `/stow` pass cascades to every registered secondmate after this home's own required pass and knowledge sweep are complete.
In a secondmate home, `/stow` curates that home only and never cascades further.
The cascade changes nothing until `/stow` is invoked: it adds no notification, no digest section, and no background work.

Expand Down
29 changes: 19 additions & 10 deletions bin/fm-stow-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
#
# The context ask fires once when the newest usage in the transcript tail is at
# or above the token line, then again only after a later read falls below
# two-thirds of that line. The age ask fires when the newest seen /stow is
# older than the hour line, and then not again for an hour. It is skipped when
# two-thirds of that line. It asks for the stow skill's quick save
# (`/stow quick`), because a full pass does not fit between the line and
# compaction. The age ask fires when the newest seen full /stow is older than
# the hour line, and then not again for an hour; it asks for the full pass.
# When both are due on one stop, the context ask wins, and its ask time holds
# the age ask off for the next hour. The age ask is skipped when
# a /stow timestamp cannot be read, including when python3 is missing, so a
# just-completed /stow is not asked for again from a stale clock. The stored
# state is what makes each ask once per crossing, so a continuation stop
Expand All @@ -27,13 +31,15 @@
#
# Context size is the same sum warm-cache compaction uses: input + cache_read
# + cache_creation on the newest usage object in the last 2MB of the transcript.
# A /stow is a Skill tool call whose skill is stow, in that same tail. The
# newest one is remembered in state/.stow-guard.json, so a later tail that no
# longer contains it does not rewind the clock.
# A full /stow is a Skill tool call whose skill is stow, in that same tail,
# unless the first word of its args is quick (any case). A quick save does not
# move the clock, so the full pass still comes due after quick saves. The
# newest full one is remembered in state/.stow-guard.json as last_stow, so a
# later tail that no longer contains it does not rewind the clock.
#
# The ask never offers a fresh restart and never writes an offer, so the
# /stow it asks for saves and keeps the session. It carries an existing offer
# through unchanged.
# Neither ask offers a fresh restart or writes an offer, so the /stow it asks
# for saves and keeps the session. It carries an existing offer through
# unchanged.
#
# With restart=1, `fm-stow-guard.sh prompt` is the one writer of that offer:
# it records offer:{sid, at} for the session, and changes nothing else in the
Expand Down Expand Up @@ -240,6 +246,8 @@ if [ -n "$transcript" ] && [ -r "$transcript" ]; then
fromjson? | .timestamp as $ts | select($ts != null)
| .message.content[]?
| select(.type == "tool_use" and .name == "Skill" and .input.skill == "stow")
| select((.input.args // "" | tostring | ascii_downcase
| [splits("[[:space:]]+")] | map(select(. != "")) | .[0] // "") != "quick")
| $ts
' | python3 -c 'import datetime, sys
best = 0
Expand Down Expand Up @@ -279,15 +287,16 @@ reason=
has_fired=$(jq -r --arg sid "$sid" 'if .[$sid] == true then "1" else "0" end' <<<"$fired") || exit 0
if [ "$tokens" -ge "$threshold" ] && [ "$has_fired" -eq 0 ]; then
reason="fm-stow-guard: context is ${tokens} tokens, near auto-compaction."
reason="$reason Run the stow skill now with the argument quick (/stow quick) for a quick save, then continue the turn you were in."
fired=$(jq -c --arg sid "$sid" '.[$sid] = true' <<<"$fired") || exit 0
elif [ "$saves_readable" -eq 1 ] && [ -z "$last_stow" ]; then
last_stow=$now
elif [ "$saves_readable" -eq 1 ] && [ $((now - last_stow)) -ge "$max_age" ] && [ $((now - asked)) -ge 3600 ]; then

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The age ask can still ask for a full pass while the session is above the token line. This PR set out to stop exactly that, and the case is wider than the 'both due at one stop' limit the PR accepts. Example: the context ask fires at hour 23 since the last full pass, and the quick save no longer moves last_stow. At hour 24 the age branch fires (the context branch is skipped because fired[sid] is already true) and asks for a full pass, even though tokens are still at or above the threshold. Fix: skip or defer the age ask while tokens >= threshold (or while fired[sid] is true), so it waits until the context has dropped below the line.

Failure scenario: tokens=240000, last full stow 23h ago. Stop A has 250K tokens, so the context ask asks for /stow quick, which runs and leaves last_stow unchanged. The helm keeps working for 61 more minutes at 260-290K. Stop B finds now-last_stow >= 24h and now-asked >= 3600, so it blocks with 'Run the /stow skill now (full pass, no argument)'. The full pass then starts about 10-50K tokens before compaction, and compaction hits mid-pass. That is the failure cited in the decision record.

reason="fm-stow-guard: the last /stow is older than ${hours}h."
reason="fm-stow-guard: the last full /stow is older than ${hours}h."
reason="$reason Run the /stow skill now (full pass, no argument), then continue the turn you were in."
fi
if [ -n "$reason" ]; then
asked=$now
reason="$reason Run the /stow skill now (full pass), then continue the turn you were in."
fi

tmp=$(mktemp "$STATE/.stow-guard.json.XXXXXX") || exit 0
Expand Down
12 changes: 9 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1469,9 +1469,14 @@ The skill text owns the marker spelling, the tick order, and the reinforcement r
Without the file the session is unchanged.

With the file present, the Claude Stop hook `bin/fm-stow-guard.sh` blocks one turn end and tells that session to run the existing `/stow` skill.
It asks when the newest context reading in the transcript tail is at least `tokens` (default 300000), once per crossing, and again only after a later reading falls below two-thirds of that line.
It also asks when the newest `/stow` it has seen is at least `hours` old (default 24), and then not again for an hour.
It makes two asks.
The context ask comes when the newest context reading in the transcript tail is at least `tokens` (default 300000), once per crossing, and again only after a later reading falls below two-thirds of that line.
It asks for `/stow quick`, the skill's quick save: it files and corrects the open work records and findings the session holds, and skips the startup-memory curation, the cascade, and the restart question, so it fits in the room left before compaction.
The age ask comes when the newest full `/stow` it has seen is at least `hours` old (default 24), and then not again for an hour.
It asks for the full pass, and a quick save does not reset its clock, so the full pass still comes due once a day.
When both are due at one turn end, the context ask wins and the age ask waits an hour.
That age ask is skipped when a `/stow` timestamp cannot be read.
The [stow skill](../.agents/skills/stow/SKILL.md#quick-save-stow-quick) owns what the quick save does.
The stored state is what makes each ask once per crossing, so a continuation stop is handled like any other stop.
A hook error does not block the turn, and the hook never compacts the session itself.
It runs for a plain Claude primary checkout of this home.
Expand All @@ -1484,7 +1489,8 @@ Remove the file to turn the ask off.
The script header owns the transcript read, the state file, and the block message.

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 everything and keeps the session.
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 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.
The process, its session lock, its parked supervision, its Remote Control session, and its session name stay the same, while the context drops back to the fresh-start set.
Expand Down
12 changes: 12 additions & 0 deletions docs/fork-decisions/2026-11-22-stow-guard-quick-save.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
2026-11-22: Arjun answered "Yes" in the helm to the recommendation that the stow guard ask for a quick save at its token line and keep the full pass for its daily age ask.
The guard asks at `tokens=240000` against a compaction near 300K, and a full pass (budget report, all three memory files, date checks, curation, the cascade) used up that gap: compaction hit in the middle of the pass, the helm re-read its 69KB startup digest to finish, and the pass captured only a few lines because open work was already on durable records.
Decision: the context ask asks for `/stow quick`, which runs only the knowledge sweep and open-record persistence, adds a memory entry only when the budget report shows room, skips the startup-memory pass, the cascade and the restart question, and never says reset-safe.
The age ask (`hours=`, default 24) still asks for the full pass, and a quick save does not move its clock (`last_stow` in `state/.stow-guard.json`), so the full pass still comes due once a day after quick saves.
The guard tells them apart by the stow Skill call's args: a first word of `quick` is a quick save, anything else is the full pass.
The once-per-crossing state, the offer handling and `restart=1` are unchanged, and a guard ask still never offers a restart; the fresh restart still follows only a `/stow` the captain types and his "Start fresh now" pick, so this amends the "saves everything" wording of [the typed-stow restart record](2026-11-22-typed-stow-restarts-helm.md) and nothing else in it.
No upstream proposal yet: the stow guard is upstream's, but its token line and this fleet's long-running helm are what made the full pass too big for the gap.

| What | Files or functions | Upstream code touched | Status | Last checked sync |
| --- | --- | --- | --- | --- |
| The stow guard's context ask asks for `/stow quick`, its age ask for the full pass, and a quick save does not move the full pass's clock | `bin/fm-stow-guard.sh` (header, transcript read, block messages), `tests/fm-stow-guard.test.sh`, `docs/configuration.md` ("Stow guard") | `bin/fm-stow-guard.sh`, `tests/fm-stow-guard.test.sh`, `docs/configuration.md` | carried | 427056c4 |
| The stow skill gains a quick save mode selected by the `quick` argument | `.agents/skills/stow/SKILL.md` (description, "Quick save", startup-memory pass, sweep step 3, receipt, cascade) | `.agents/skills/stow/SKILL.md` | carried | 427056c4 |
Loading
Loading