Skip to content

feat(email): two-way email notifier (out-of-band, opt-in) - #127

Closed
2jfhas2bn2jfds wants to merge 1 commit into
kunchenguid:mainfrom
2jfhas2bn2jfds:fm/fm-email-notifier
Closed

2jfhas2bn2jfds wants to merge 1 commit into
kunchenguid:mainfrom
2jfhas2bn2jfds:fm/fm-email-notifier

Conversation

@2jfhas2bn2jfds

Copy link
Copy Markdown

Two-way email notifier for firstmate (out-of-band notifier, opt-in)

Implements the pluggable out-of-band notifier from #106: firstmate emails the captain when something captain-relevant comes up, and the captain can reply by email to steer it. Modeled closely on X mode (section 14) so it is purely additive and opt-in.

Opt-in and additive (zero behavior change when off)

Gated on .env: FM_EMAIL_NOTIFY=1 plus AGENTMAIL_API_KEY, FM_NOTIFY_EMAIL (recipient), and AGENTMAIL_INBOX. With the switch absent/falsey every script is a hard no-op and bootstrap writes/prints nothing. No edits to the watcher backbone (fm-watch.sh, fm-watch-arm.sh, fm-wake-lib.sh, the afk daemon); it rides the existing state/*.check.sh mechanism and the shared captain-relevant classifier (fm-classify-lib.sh).

Outbound (bin/fm-email-notify.sh)

Scans state/*.status with the same classifier the watcher uses and emails the captain on needs-decision/blocked/failed/done/PR ready/checks green/merged via AgentMail POST /inboxes/<inbox>/messages/send. Plain outcome language (no internal jargon, mirrors section 9), deduped per task in state/.email-seen-<task> (marker advances only after a successful send, so failures retry). Silent: never adds a wake.

Inbound / two-way (bin/fm-email-poll.sh)

Polls GET /inboxes/<inbox>/messages, baselines on first run (never replays pre-existing mail), and surfaces each new reply from the captain as an email-reply <id> check: wake with the full reply text stashed to state/email-inbox/<id>.json as the payload, so a reply can steer firstmate. Config/auth errors surface one rate-limited email-mode-error line.

Secrets and untrusted input

Key and recipient come only from gitignored .env; the captain's address is never hardcoded in tracked files. Bearer key goes to a 0600 header file, never on argv, never echoed. Inbound email text is only ever parsed by jq from a file (never inlined into a shell), and message ids are sanitized before becoming filenames.

Bootstrap, cadence, docs, tests

Bootstrap drops an idempotent state/email-watch.check.sh shim (silent notify then poll, one shim so outbound always runs each cadence) and config/email-mode.env (60s cadence), removed on opt-out. FM_EMAIL_DRY_RUN previews notifications to state/email-outbox/ with no key or network. Documented in AGENTS.md section 15 and README; config/email-mode.env added to .gitignore.

tests/fm-email-mode.test.sh: 19 hermetic tests with the AgentMail HTTP call faked (no real network or keys) covering inert-by-default, classify/compose, dedupe, live send, baseline, inbound parse, sender filtering, id sanitization, error reporting, and bootstrap activation/opt-out.

Validation

shellcheck bin/*.sh tests/*.sh clean; the new suite and the rest of the suite pass (two unrelated tests fail only under the local macOS bash 3.2 due to a pre-existing fm-brief.sh heredoc issue; they pass on CI's Ubuntu bash 5).

Delivered via direct-PR from a fork because the no-mistakes gate is currently not creating runs. Captain merges.

Add an AgentMail-backed email notifier modeled on X mode (issue #106):
purely additive, opt-in via .env (FM_EMAIL_NOTIFY + AGENTMAIL_API_KEY +
FM_NOTIFY_EMAIL + AGENTMAIL_INBOX), zero behavior change when off.

- bin/fm-email-notify.sh: outbound. Scans state/*.status with the shared
  captain-relevant classifier and emails the captain on needs-decision/
  blocked/failed/done events, in plain outcome language, deduped per task.
- bin/fm-email-poll.sh: inbound. Polls the AgentMail inbox, baselines on
  first run, and surfaces each new captain reply as an email-reply check:
  wake with the reply text as payload, so the captain can steer by email.
- bin/fm-email-lib.sh: shared config/secret handling (bearer to a 0600
  header file, never on argv; jq @uri path encoding).
- bootstrap drops an idempotent state/email-watch.check.sh shim (silent
  notify then poll) and config/email-mode.env (60s cadence); removed on
  opt-out. No watcher-backbone edits.
- Untrusted email text is never inlined into a shell; message ids are
  sanitized before becoming filenames.
- tests/fm-email-mode.test.sh: 19 hermetic tests (HTTP faked, no key).
- Docs: AGENTS.md section 15, README feature, gitignore.
@2jfhas2bn2jfds
2jfhas2bn2jfds deleted the fm/fm-email-notifier branch June 28, 2026 22:39
@jorgenseeyou

Copy link
Copy Markdown

Reviewed at ccdf369179742a4dcdab38150cfa85035240c694, against merge-base be6e88647c5631bfd36f5b7338213f9b8fb74cac. The prune is sound and most of it is clearly right: the courier entry really is outdated by the code, the two sign-in entries really did duplicate each other, and the sweep counts really were stale.

Two entries look like they should stay, because the conditions they warn about are still true. Both are documentation-only; nothing here asks for a code change in this PR.

1. The OTEL_ABSENCE warning is dropped while the control is still red.

The shortened failure overview at H:1295–1323 no longer names it; it stood at B:1508 and B:1533. The control was run twice on this head with Node v22.23.1 and failed both times at the completing task intent is accepted (platform/controls/otel_absence_control.mjs:202).

This is not a stale stage count. The control starts the real platform server on HOST=127.0.0.1, PORT=0, reads the port from the listen line, disables .env loading, and drives /v1/task-intents over HTTP. The stage register runs that same file at platform/controls/run_merged_regression.mjs:272.

H:78–79 still cites the control as evidence for the tracing-absence property, without saying it does not currently pass. Keeping a short named line about the standing failure, with the measured assertion, would prevent the next reader from classifying an existing red as a new regression. No sweep numbers needed.

2. The deleted island list also carried a live mock warning.

H:563–573 reinstates the Instrument, SpellHint and TextSizeDial warnings but loses the one about JobsChoices, which stood at B:644–646. JobsChoices, WhatsApp and chToggle no longer appear anywhere in the file.

The behaviour is unchanged between base and head. frontend/components/screens/JobsChoices.tsx:18 creates local whatsappOn with useState(true); the handler at :51–55 calls only setWhatsappOn(next) and toast(...), with no setSetting, no door and no transport. The other handler in the same component does call setSetting("sy-autonomy", ...) at :29, and the tooltip at :45 still says the channel is not connected. So the toast reads "notifications on" while no notification capability is enabled.

Re-adding one short line beside the other island warnings, stating that the WhatsApp choice is local simulation with no persistence or delivery, would keep that boundary visible. grep -rl '"use client"' frontend/ regenerates the file list but not this warning.

Two smaller notes, neither blocking:

  • The wording check refuses three role attributions at H:979, H:1147 and H:1219. They predate this PR, but it edits those same lines to remove the dates, so they could be switched to owner decision cheaply while they are open.
  • H:1294 describes a path that has never existed in this repository as "environment absence wearing a defect's clothes", while H:1303–1305 correctly says the two toolchain stages are still FAIL when their registered hold signature does not arrive. Worth keeping cause and runner verdict separate.

@Ali-Flt

Ali-Flt commented Oct 15, 2026

Copy link
Copy Markdown

CLAUDE here. Thanks; on the notes:

  1. Not changed. Every limits loader in the station reads data.get(...) straight after json.loads (steady.load_limits does the same), so a file whose top level is not an object fails the same way for all of them. It has never happened, and fixing this one loader alone would make them differ.
  2. Intended. An unusable idle_limits.json stops the line at its start, as an unusable steady_limits.json does, so a station never runs with a window whose picture it did not configure. The package copies the file into a station that lacks it, so only a hand-edit or a wrong --idle-limits reaches this.
  3. Right, and intended: open now runs the same release a phase runs, so a manual value a previous program left set is reset too. The phases already write those same values on this camera every run. Added to the PR text.
  4. Agreed, no change.

fritznoff pushed a commit to fritznoff/starship that referenced this pull request Nov 2, 2026
… status bar (kunchenguid#127)

* feat(bin): supply real Codex context and account quota to the companion row

The Codex and Astra companion showed no context and no quota at all, which
read as exhausted headroom when in fact nothing was ever being supplied.

Context now comes from the exact session the companion follows: the pane
resolves to its Codex process, that process is asked which rollout file it
holds open, and only that file is read. One open descriptor per thread makes
this a binding rather than a newest-file guess, so a sibling Codex session can
never be borrowed. The figure uses the context window that session itself
reported, so no capacity is assumed and compaction needs no special handling.

Provider quota comes from quota-axi, read strictly read-only, as the account's
binding window with that window named - the same percentage means something
different against five hours than against a week.

The rollout's own rate_limits block is deliberately NOT used as a quota source
unless its stamped identity provably belongs to the running model. A live
gpt-6-astra primary was measured reporting limit_id=codex_bengalfox
(GPT-5.3-Codex-Spark) at 0% used while the account's binding weekly window sat
at 54% used; reporting that 0% would claim full headroom that does not exist.

Every reading is positively known or unavailable: missing, malformed, expired,
stale, and unattributable figures stay dim placeholders and are never turned
into zero, while a genuine zero still renders. Caches are bounded and the
provider read never runs on a per-refresh path, so a one-second companion does
no subprocess work on most ticks and never triggers a credential refresh.

Co-Authored-By: Claude Opus 5 <[email protected]>

* no-mistakes(review): drop rollout quota source, defer provider read, bound context tail

* feat(bin): reclaim the status companion's empty rows on Herdr

On a large tab Herdr's proportional split floor left the one-row status strip
sitting in a six-row pane: a border, the row, three empty rows, a border. Pane
sizing cannot fix that - the floor is a tenth of the tab - so the row now also
goes onto the primary pane's own border title, where it costs no rows, and the
companion pane is hidden by zooming the primary.

Measured in a disposable fm-lab session on herdr 0.7.4, through a new bounded
lab viewer, because Herdr draws borders in its client rather than its server so
`pane read` cannot see them:

- A pane with no split has NO border, and neither a reported title nor a pane
  name renders on it. So the companion pane has to keep existing for a border
  to exist at all: the reclaim is hiding it, never closing it. The earlier
  record that it could be closed outright was measured with the split still
  present and is superseded in docs/status-bar.md.
- With the split present the primary's top border carries every canonical
  field, and keeps refreshing while the primary is unfocused.
- Zoomed, the companion's rows return to the conversation and the border row
  survives. End to end at 182x64: all six rows reclaimed, real fleet counts on
  the border, the launcher's own metadata record untouched.
- Herdr truncates the border title itself, visibly, at 60 and at 40 columns, so
  width is left to Herdr.

Three properties are load-bearing. The border row is published under its own
metadata source, never the launcher's, because Herdr replaces a source's whole
record per call and publishing under the launcher's source would wipe the
primary's supervision state labels on the first refresh. The row is clipped to
Herdr's silent 80-codepoint store by dropping whole fields with a visible
marker, on the separator rather than by offset so a multibyte glyph is never
split, and the role marker leads the row so a clip can never reach it. And the
row carries a ttl of two and a half intervals, so a renderer that dies lets the
border expire instead of freezing a stale fleet count.

Zoom is applied once, by the launcher, and only when nothing but the primary
and its new companion share the tab. The renderer only ever RELEASES it, when a
third pane appears, then stands down - so a co-tenant's live work is never
hidden and a deliberate unzoom is not fought once a second.

The companion keeps drawing its in-pane row throughout, so an unzoomed primary,
a Herdr below the presentation protocol, a refused zoom and a failing metadata
call all degrade to the surface that shipped before this change.

Context and quota stay `--`; supplying them is separate work and no number is
invented here.

Co-Authored-By: Claude Opus 5 <[email protected]>

* no-mistakes(review): gate chrome mode on proven Herdr capability and owned zoom

* feat(bin): report live work and task records as different fleet numbers

The status row counted every state/<id>.meta as a running ship and folded each
status log's last line into paused and attention. Both readings turn records
into apparent workers: a meta outlives its worker, and AGENTS.md section 8
defines a status line as a wake event rather than current state. On the
captain's own fleet that rendered twelve ships while two workers were alive.

bin/fm-fleet-status-lib.sh now folds bin/fm-crew-state.sh, the canonical
current-state reader, instead of deriving state here. It selects no run and
re-implements no attribution. A canonical read costs about a second per task, so
the fold runs out of band under a single refresh claim and every frame renders
the cache; a frame never calls the reader.

The row gains working, validating, paused, attention and records as separate
fields. Records is always exact and makes no claim about workers. The four live
fields are one reading: a missing, incomplete, aged-out, malformed, or
different-fleet reading renders placeholders for all four, never zero, because
an idle fleet is a real state the captain has to be able to believe.

Cache and freshness mechanics move to bin/fm-status-cache-lib.sh so this supply
and the Codex metrics supply agree on what a still-current reading is.

The Codex path deliberately stops publishing the primary-handoff context sample.
That file drives the handoff supervisor's context axis, and feeding it from a
display change would arm a live-primary rotation path nobody asked for.

Co-Authored-By: Claude Opus 5 <[email protected]>

* feat(bin): make Astra's extended context window selectable at launch

This Codex installation grants gpt-6-astra a 872000-token ceiling against a
272000 catalog default, but only if the launch asks for it. The ask existed only
as a private profile on one machine, so an ordinary launch never used it.

config/astra-context now selects the window at launch, as a sibling of
config/astra-effort: absent changes nothing, `max` resolves to the installed
catalog's own max_context_window for the model, and an explicit integer is
honoured only up to that ceiling. A request above it refuses rather than being
clamped or passed through, and an unreadable catalog refuses rather than
supplying a remembered number. The provider's API maximum for a model and the
window this subscription CLI will open are different quantities, and only the
second one is ever used here.

config/astra-compact-at sets the compaction point. It is never derived: how much
of a window to spend before summarising is an operational choice, and nothing in
the catalog prescribes one.

Co-Authored-By: Claude Opus 5 <[email protected]>

* feat(bin): let the isolated lab viewer return the raw byte stream

Colour and erase behaviour live in the byte stream, not in the rendered
characters, so a question about a pane's background could not be answered from
the viewer's text output. view --format raw-bytes returns the capture the engine
already produced, under exactly the same bounds: one attached client that only
ever draws, for the same bounded seconds, in a validated non-default lab.

Also claims the lab viewer and the chrome end-to-end proof in the fork surface.

Co-Authored-By: Claude Opus 5 <[email protected]>

* docs: state the fleet-field contract and the Astra context window

docs/status-bar.md gains the fleet-field section: what each field claims, why
the four live fields share one fate rather than falling back to zero, and why
the Codex companion displays context without feeding the primary-handoff
rotation axis. Its verification record gains the 2026-09-12 measurement against
the captain's own fleet, and a note that older captures show the previous field
shape rather than being rewritten.

docs/configuration.md owns config/astra-context and config/astra-compact-at,
including why a window above the installed catalog's ceiling refuses instead of
being clamped, and why the compaction point is never derived.

docs/herdr-backend.md records what the lab measured about pane rendering: the
Herdr client re-emits fully specified cell runs rather than passing escape
sequences through, and background-colour erase is honoured where the cells are
stored. A solid block of colour in a pane is therefore a statement about the
producer in that pane, not about Herdr.

Co-Authored-By: Claude Opus 5 <[email protected]>

* no-mistakes(review): fix fleet signature, fold truncation, refresh claim, quota bound and docs

* no-mistakes(document): docs: cover lab view --format, new status libs, status caches

* no-mistakes: apply CI fixes

---------

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants