Skip to content

feat(bin): add opt-in local Claude usage threshold warner - #3

Merged
max-metaplanet merged 6 commits into
mainfrom
fm/usage-warner
Sep 23, 2026
Merged

max-metaplanet merged 6 commits into
mainfrom
fm/usage-warner

Conversation

@max-metaplanet

@max-metaplanet max-metaplanet commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Intent

yes start the warner

Build the local Claude usage-limit warner for macOS exactly as its approved design specifies: a threshold warner only, NOT a usage viewer. quota-axi already reads Claude quota locally with --json, --full, --tui and --no-credential-refresh, and a second reader that drifts from it is the defect class being removed. The one prerequisite, a one-time Keychain approval for quota-axi, landed on 2026-09-22 and a live read now returns real windows.

The approved design, in full, is at ~/.treehouse/firstmate-7bab20/2/firstmate/data/usage-warner-design.md: one read with two callers, on demand and periodic, reusing existing scheduling with no daemon; warnings through Notification Center via the same path the wedge alarm resolves to, edge-triggered with a de-dupe record; lives in firstmate bin/ with a doc; opt-in and silent when unconfigured, so an unconfigured user sees no behaviour change, no new failure mode, and no new hard dependency at dispatch. The upstream claude-swap licence is MIT and allows vendoring with notice; this change does not vendor, and the PR records that the licence was checked and what it allows.

What Changed

  • Adds bin/fm-usage-warner.sh, a macOS-only warner for Claude usage limits. It does not display usage. check runs the existing quota-axi read with --no-credential-refresh and compares each window against the <window-id>:<percent> thresholds in a local config/usage-warner file. When a window crosses its threshold it sends one Notification Center alert through osascript, the same OS path the wedge alarm uses. Several crossings from one read go out as a single alert. A de-dupe record in state/.usage-warner keeps it quiet until the window drops back below its threshold, and a read failure that persists is reported once until it changes. The read is capped at 10s, or at FM_CHECK_TIMEOUT minus 3s when that is lower.
  • The feature is opt-in. Without a valid config file, check prints nothing and arm refuses. arm also refuses on anything other than macOS. arm writes state/usage-warner.check.sh and registers it with bin/fm-check-register.sh, so the existing watcher polls it on its normal schedule. There is no new daemon and no separate schedule. disarm removes the check script, its registration and the de-dupe record.
  • Adds docs/usage-warner.md, a config-schema section in docs/configuration.md, an example file at docs/examples/usage-warner, a README link and a documentation-audience entry. Also adds tests/fm-usage-warner.test.sh.

No code is copied in from claude-swap. Its licence was checked: it is MIT, which would allow copying code in as long as the licence notice is kept.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The warner does nothing unless configured and is isolated behind its own config gate. The last fix round now takes FM_CHECK_TIMEOUT the same way fm-mail-check.sh and fm-tool-update-check.sh do: same default and same fallback for bad values, with 3 seconds reserved for startup and kill grace. The read is capped at 10s, and when no time is left it is skipped and recorded as not measured. It never exits nonzero, so a user who has not configured it cannot hit a failure. I traced it with FM_CHECK_TIMEOUT set to 30, 6, 4, 3 and 2: the read always ends inside the watcher's limit.

Testing

The baseline suite (tests/fm-usage-warner.test.sh) passed. I then drove the warner live against the real quota-axi read in isolated temp homes, first on demand and then through the real fm-watch.sh periodic sweep. An unconfigured home stayed silent with exit 0 and wrote nothing, even with quota-axi missing from PATH and a bogus FM_CHECK_TIMEOUT, and arm refused. A configured five_hour:20 threshold, against a live reading of 22%, produced exactly one line and one notification call. Repeated checks stayed quiet. The warning fired again only after the record was cleared by a read below threshold, which I simulated by raising the threshold, since the live window could not be made to drop. Every quota-axi call carried --no-credential-refresh, and none carried --allow-keychain-prompt. Under the real watcher, the armed shim was dispatched and its warning surfaced as the wake reason. With FM_CHECK_TIMEOUT=5 and a hanging quota-axi, the warner reported its own 2s read timeout before the watcher could kill it, and recorded it. With FM_CHECK_TIMEOUT=2, it returned at once and recorded the read as not measured, exiting 0. Disarm removed the shim, trust file and record. The real osascript notification call succeeded, but I could not screenshot the banner: screencapture failed with 'could not create image from display' because the process lacks Screen Recording permission. The second watcher sweep woke on the watcher's own 'rearm-resurface' reason, so it only confirms that no second notification was posted; the de-dupe itself is shown by the on-demand repeats. All temp homes were removed, and the worktree is clean.

  • Live validation: ✅ go - 8 of 9 scenarios driven live against the product
Scenario Result Live Evidence
An unconfigured user runs check (even with quota-axi absent and a bogus FM_CHECK_TIMEOUT) and sees no output, exit 0, no state written; arm refuses ✅ pass live on-demand-transcript.txt S1
A user with five_hour:20 runs check on demand while the real five_hour window reads 22% and gets one warning line plus one notification and a de-dupe record ✅ pass live on-demand-transcript.txt S2
Repeated checks while the window stays above its threshold stay silent (edge-triggered de-dupe) ✅ pass live on-demand-transcript.txt S3
After a read below threshold clears the record, the next crossing warns again (the drop was simulated by raising the threshold to 99, since the live window cannot be forced down) ✅ pass live on-demand-transcript.txt S4
Every quota-axi call is read-only: --no-credential-refresh always, --allow-keychain-prompt never ✅ pass live on-demand-transcript.txt S5 (argv log of 5 real calls)
arm registers a trusted check, and the real fm-watch.sh periodic sweep dispatches it and surfaces the warning as its wake reason ✅ pass live watcher-transcript.txt S6
Adversarial: with FM_CHECK_TIMEOUT=5 and a hanging quota-axi, the warner reports its own bounded timeout inside the watcher budget, and with FM_CHECK_TIMEOUT=2 it records not-measured and exits 0 imme… ✅ pass live watcher-transcript.txt S7/S7b
disarm removes the shim, trust file and record, and the next watcher sweep posts no warning ✅ pass live watcher-transcript.txt S8
A crossing shows a visible 'Firstmate: Claude usage' banner in macOS Notification Center ⏸️ untested no The banner could not be captured on screen: screencapture failed with 'could not create image from display' because this agent process lacks the macOS Screen Recording permission. Grant it to the term…
Evidence: On-demand live transcript (real quota-axi read, opt-in gate, edge-trigger, read-only argv)

Source: On-demand live transcript (real quota-axi read, opt-in gate, edge-trigger, read-only argv)

== live quota-axi windows (real read) ==
[{"id":"five_hour","percentUsed":22},{"id":"seven_day","percentUsed":3},{"id":"model:fable","percentUsed":0},{"id":"extra_usage","percentUsed":0}]

== S1 unconfigured home: check silent, arm refuses, nothing written ==
$ fm-usage-warner.sh check
[exit=0]
[exit=0 with quota-axi absent from PATH and bogus FM_CHECK_TIMEOUT]
$ fm-usage-warner.sh arm
fm-usage-warner: no threshold configured at /private/tmp/fm-uw-live.XexVYC/home/config/usage-warner
[exit=1]
state dir: (empty means nothing written)

== S2 configure five_hour:20 (live reads above), seven_day:90, model:fable:50 ==
$ fm-usage-warner.sh check
usage-warner: five_hour at 22% (>=20%)
[exit=0]
notifications so far:        1
NOTIFY argv-last=five_hour at 22% (>=20%)
--- de-dupe record ---
fm-usage-warner-v1
reported=usage-warner: five_hour at 22% (>=20%)
notified-begin
five_hour
notified-end

== S3 repeat on-demand check while still above: stays quiet ==
$ fm-usage-warner.sh check
[exit=0]
$ fm-usage-warner.sh check
[exit=0]
notifications so far:        1

== S4 window reads below threshold (threshold raised to 99) then crosses again (back to 20) ==
$ fm-usage-warner.sh check
[exit=0]
--- record after drop ---
fm-usage-warner-v1
reported=
notified-begin
notified-end
$ fm-usage-warner.sh check
usage-warner: five_hour at 22% (>=20%)
[exit=0]
notifications so far:        2
NOTIFY argv-last=five_hour at 22% (>=20%)
NOTIFY argv-last=five_hour at 22% (>=20%)

== S5 every quota-axi invocation argv (read-only proof) ==
--provider claude --json --full --no-credential-refresh
--provider claude --json --full --no-credential-refresh
--provider claude --json --full --no-credential-refresh
--provider claude --json --full --no-credential-refresh
--provider claude --json --full --no-credential-refresh
no --allow-keychain-prompt in any call
calls missing --no-credential-refresh: 0
Evidence: Real watcher transcript (arm, periodic dispatch, timeout guard, disarm)

Source: Real watcher transcript (arm, periodic dispatch, timeout guard, disarm)

== S6 arm in a configured home ==
armed: state/usage-warner.check.sh
[exit=0]
-rw-------@ 1 max  wheel   84 Sep 23 15:56 usage-warner.check-trust
-rwx------@ 1 max  wheel  334 Sep 23 15:56 usage-warner.check.sh

== S6 real watcher sweep #1 dispatches the armed check (live quota read) ==
[watcher ran 2s] stdout:
  | check: /private/tmp/fm-uw-watch.STl1wG/home/state/usage-warner.check.sh: usage-warner: five_hour at 22% (>=20%)
notifications: NOTIFY five_hour at 22% (>=20%)

== S6 real watcher sweep #2: already crossed, check silent (edge-triggered) ==
[watcher ran 1s] stdout:
  | check: rearm-resurface
notifications count:        1

== S7 adversarial: FM_CHECK_TIMEOUT=5 and a hanging quota-axi under the real watcher ==
armed: state/usage-warner.check.sh
[watcher ran 4s] stdout:
  | check: /private/tmp/fm-uw-watch.STl1wG/home2/state/usage-warner.check.sh: usage-warner: quota-axi read did not finish within the 2s budget
--- record ---
fm-usage-warner-v1
reported=usage-warner: quota-axi read did not finish within the 2s budget
notified-begin
notified-end

== S7b FM_CHECK_TIMEOUT=2 (no room) with hanging read, on demand ==
usage-warner: quota-axi read not measured: FM_CHECK_TIMEOUT of 2s leaves no room for a read
[exit=0 after 0s]
fm-usage-warner-v1
reported=usage-warner: quota-axi read not measured: FM_CHECK_TIMEOUT of 2s leaves no room for a read
notified-begin
notified-end

== S8 disarm ==
disarmed: state/usage-warner.check.sh
[exit=0]
no usage-warner shim, trust, or record left in state/

== S8 real watcher sweep after disarm: no usage-warner dispatch ==
[watcher ran 1s] stdout:
  | check: rearm-resurface
notifications count:        0
Evidence: Real Notification Center post transcript

Source: Real Notification Center post transcript

usage-warner: five_hour at 22% (>=20%)
Evidence: On-demand driver script

Source: On-demand driver script

#!/usr/bin/env bash
# Live drive of bin/fm-usage-warner.sh against the REAL quota-axi read in a throwaway FM_HOME.
set -u
ROOT=~/.no-mistakes/worktrees/61c6dd39b831/01M37WQ78FK5ZNWFRM18FZ8GBR
W="$ROOT/bin/fm-usage-warner.sh"
T=$(mktemp -d /tmp/fm-uw-live.XXXXXX); T=$(cd "$T" && pwd -P)
REALQ=$(command -v quota-axi)
mkdir -p "$T/bin" "$T/home"
# argv-logging passthrough to the real quota-axi, and an osascript recorder
cat > "$T/bin/quota-axi" <<SH
#!/usr/bin/env bash
printf '%s\n' "\$*" >> "$T/quota-argv.log"
exec "$REALQ" "\$@"
SH
cat > "$T/bin/osascript" <<SH
#!/usr/bin/env bash
printf 'NOTIFY argv-last=%s\n' "\${@: -1}" >> "$T/notify.log"
SH
chmod +x "$T/bin/"*
H="$T/home"
run() { echo "\$ fm-usage-warner.sh $*"; PATH="$T/bin:$PATH" FM_HOME="$H" "$W" "$@"; echo "[exit=$?]"; }
echo "== live quota-axi windows (real read) =="
"$REALQ" --provider claude --json --full --no-credential-refresh | jq -c '[.. | objects | select(has("windows")) | .windows[] | {id,percentUsed}]'
echo; echo "== S1 unconfigured home: check silent, arm refuses, nothing written =="
run check; FM_CHECK_TIMEOUT=bogus PATH=/usr/bin:/bin FM_HOME="$H" "$W" check; echo "[exit=$? with quota-axi absent from PATH and bogus FM_CHECK_TIMEOUT]"
run arm
echo "state dir: $(ls -A "$H" 2>/dev/null | tr '\n' ' ')(empty means nothing written)"
echo; echo "== S2 configure five_hour:20 (live reads above), seven_day:90, model:fable:50 =="
mkdir -p "$H/config"; printf 'five_hour:20\nseven_day:90\nmodel:fable:50\n' > "$H/config/usage-warner"
run check
echo "notifications so far: $(wc -l < "$T/notify.log" 2>/dev/null || echo 0)"; cat "$T/notify.log" 2>/dev/null
echo "--- de-dupe record ---"; cat "$H/state/.usage-warner"
echo; echo "== S3 repeat on-demand check while still above: stays quiet =="
run check; run check
echo "notifications so far: $(wc -l < "$T/notify.log")"
echo; echo "== S4 window reads below threshold (threshold raised to 99) then crosses again (back to 20) =="
printf 'five_hour:99\nseven_day:90\n' > "$H/config/usage-warner"; run check
echo "--- record after drop ---"; cat "$H/state/.usage-warner"
printf 'five_hour:20\nseven_day:90\n' > "$H/config/usage-warner"; run check
echo "notifications so far: $(wc -l < "$T/notify.log")"; cat "$T/notify.log"
echo; echo "== S5 every quota-axi invocation argv (read-only proof) =="
cat "$T/quota-argv.log"
grep -q -- '--allow-keychain-prompt' "$T/quota-argv.log" && echo "FAIL: credential refresh requested" || echo "no --allow-keychain-prompt in any call"
grep -vc -- '--no-credential-refresh' "$T/quota-argv.log" | sed 's/^/calls missing --no-credential-refresh: /'
rm -rf "$T"
Evidence: Watcher driver script

Source: Watcher driver script

#!/usr/bin/env bash
# Live drive: arm the warner in a throwaway FM_HOME, then run the REAL bin/fm-watch.sh
# so its periodic check sweep dispatches the armed shim (real quota-axi read).
set -u
ROOT=~/.no-mistakes/worktrees/61c6dd39b831/01M37WQ78FK5ZNWFRM18FZ8GBR
W="$ROOT/bin/fm-usage-warner.sh"; WATCH="$ROOT/bin/fm-watch.sh"
T=$(mktemp -d /tmp/fm-uw-watch.XXXXXX); T=$(cd "$T" && pwd -P)
REALQ=$(command -v quota-axi)
mkdir -p "$T/bin"
printf '#!/usr/bin/env bash\nexit 0\n' > "$T/bin/tmux"
cat > "$T/bin/osascript" <<SH
#!/usr/bin/env bash
printf 'NOTIFY %s\n' "\${@: -1}" >> "$T/notify.log"
SH
cat > "$T/bin/quota-axi" <<SH
#!/usr/bin/env bash
if [ -n "\${HANG_QUOTA:-}" ]; then sleep 60; fi
exec "$REALQ" "\$@"
SH
chmod +x "$T/bin/"*
mk_home() { local h=$1; mkdir -p "$h/state" "$h/data" "$h/config" "$h/projects"; printf '# lab home\n' > "$h/AGENTS.md"; printf 'lab\n' > "$h/.fm-secondmate-home"; printf '## In flight\n\n## Queued\n\n## Done\n' > "$h/data/backlog.md"; }
watch_once() {  # <home> [extra env...]
  local h=$1; shift
  local start=$(date +%s)
  env "$@" PATH="$T/bin:$PATH" FM_ROOT_OVERRIDE="$ROOT" FM_HOME="$h" FM_POLL=1 FM_SIGNAL_GRACE=0 \
    FM_CHECK_INTERVAL=0 FM_HEARTBEAT=9999999 "$WATCH" > "$T/w.out" 2> "$T/w.err" &
  local pid=$! i=0
  while kill -0 $pid 2>/dev/null && [ $i -lt 400 ]; do sleep 0.1; i=$((i+1)); done
  kill $pid 2>/dev/null; wait $pid 2>/dev/null
  echo "[watcher ran $(( $(date +%s) - start ))s] stdout:"; sed 's/^/  | /' "$T/w.out"
  grep -i 'usage-warner\|reject\|unauth' "$T/w.err" | head -5 | sed 's/^/  err| /'
}
H="$T/home"; mk_home "$H"
printf 'five_hour:20\nseven_day:90\n' > "$H/config/usage-warner"
echo "== S6 arm in a configured home =="
PATH="$T/bin:$PATH" FM_HOME="$H" "$W" arm; echo "[exit=$?]"
ls -l "$H/state" | grep usage-warner
echo; echo "== S6 real watcher sweep #1 dispatches the armed check (live quota read) =="
watch_once "$H"
echo "notifications: $(cat "$T/notify.log" 2>/dev/null)"
echo; echo "== S6 real watcher sweep #2: already crossed, check silent (edge-triggered) =="
rm -f "$H/state/.last-check"; watch_once "$H" FM_WATCH_MAX_SECS=8
echo "notifications count: $(wc -l < "$T/notify.log")"
echo; echo "== S7 adversarial: FM_CHECK_TIMEOUT=5 and a hanging quota-axi under the real watcher =="
H2="$T/home2"; mk_home "$H2"; printf 'five_hour:20\n' > "$H2/config/usage-warner"
PATH="$T/bin:$PATH" FM_HOME="$H2" "$W" arm
watch_once "$H2" HANG_QUOTA=1 FM_CHECK_TIMEOUT=5
echo "--- record ---"; cat "$H2/state/.usage-warner"
echo; echo "== S7b FM_CHECK_TIMEOUT=2 (no room) with hanging read, on demand =="
s=$(date +%s); HANG_QUOTA=1 FM_CHECK_TIMEOUT=2 PATH="$T/bin:$PATH" FM_HOME="$H2" "$W" check; echo "[exit=$? after $(( $(date +%s)-s ))s]"
cat "$H2/state/.usage-warner"
echo; echo "== S8 disarm =="
PATH="$T/bin:$PATH" FM_HOME="$H" "$W" disarm; echo "[exit=$?]"
ls -A "$H/state" | grep -i usage-warner || echo "no usage-warner shim, trust, or record left in state/"
echo; echo "== S8 real watcher sweep after disarm: no usage-warner dispatch =="
rm -f "$H/state/.last-check"; : > "$T/notify.log"; watch_once "$H" FM_WATCH_MAX_SECS=8
echo "notifications count: $(wc -l < "$T/notify.log")"
pkill -f "$T/" 2>/dev/null; rm -rf "$T"
Evidence: Watcher dispatch of the armed check
check: .../home/state/usage-warner.check.sh: usage-warner: five_hour at 22% (>=20%)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 5 issues found → auto-fixed (2) ✅
  • ⚠️ docs/configuration.md:669 - The new 'Local Claude usage warner' section was inserted in the middle of the watched-tools section. The watched-tools lines that followed it ('A changed or returning condition is reported again.', 'Adding, removing, or changing a watched tool is an edit to this file and needs no code change or re-arming.', 'This file is not inherited by secondmate homes...', and the FM_TOOL_UPDATE_* paragraph) now sit under the usage-warner heading. Readers will take them as statements about config/usage-warner, and the watched-tools section loses its closing rules. Fix: move the new section so it starts after the FM_TOOL_UPDATE budget paragraph (just before '## Mail plane (.env)').
  • ⚠️ bin/fm-usage-warner.sh:310 - The de-dupe record is keyed only by window id, not by the directive. If one window has more than one threshold (for example five_hour:80 and five_hour:95, which the schema allows), the higher one never fires. At 85% the id is recorded as notified. When the window later reads 96%, id_in_list &#34;$RECORD_NOTIFIED&#34; five_hour is true, so the 95% crossing is dropped silently until the window falls below 80%. Fix: key notified_new and the record entries by id&lt;TAB&gt;threshold, or reject duplicate ids in config_thresholds.
  • ⚠️ bin/fm-usage-warner.sh:132 - FM_USAGE_WARNER_TIMEOUT_SECS accepts up to 60s, but the watcher kills a check after FM_CHECK_TIMEOUT (default 30). A killed run prints nothing and records nothing (docs/configuration.md:675). With a value such as 45 and a slow quota-axi, every poll is killed silently: no timeout report and no de-dupe update, repeated forever. The sibling checks (fm-mail-check.sh, fm-tool-update-check.sh) cut their budget to fit FM_CHECK_TIMEOUT. Fix: clamp TIMEOUT_SECS below ${FM_CHECK_TIMEOUT:-30}, leaving room for the record write and notification, the same way the siblings do.
  • ℹ️ bin/fm-usage-warner.sh:323 - usage_warner_notify runs osascript with no time limit, and record_write only runs after it. The wedge alarm it claims parity with wraps the same call in wedge_alarm_run_bounded. If osascript stalls (for example on a first-run notification-permission prompt) until the watcher kills the check, the crossing is never recorded, so every later poll re-attempts the notification, and the watcher discards the printed line each time. Fix: write the record before notifying, and wrap osascript in fm_run_timed.
  • ⚠️ bin/fm-usage-warner.sh:125 - Simplification: the user-tunable FM_USAGE_WARNER_TIMEOUT_SECS environment variable, with its own validation, its exit-2 refusal, and a documented configuration entry, is not required by the intent, which only needs the read to be bounded. It also causes the watcher-timeout mismatch reported above. The validation also runs before action dispatch, so a bad value makes even an unconfigured check, disarm, or --help exit 2. Recommend removing it in favour of a fixed internal bound that fits FM_CHECK_TIMEOUT.

🔧 Fix applied.
1 warning still open:

  • ⚠️ bin/fm-usage-warner.sh:124 - The fix round's fixed READ_TIMEOUT_SECS=10 only stays under the watcher's default FM_CHECK_TIMEOUT of 30. FM_CHECK_TIMEOUT is a documented user setting (docs/configuration.md:1150, bin/fm-watch.sh:233), and the sibling checks (fm-mail-check.sh:96, fm-tool-update-check.sh:163) cut their budgets to fit it. Failure case: a user sets FM_CHECK_TIMEOUT=8 and quota-axi hangs. The watcher kills the check at 8s, before the 10s bound fires. Nothing is printed and nothing is recorded, and that silent kill repeats on every poll. Your instruction for the fix said the bound should sit 'safely below FM_CHECK_TIMEOUT so the watcher never kills the check first'. Today that only holds for the default. The smallest remedy is to clamp the fixed bound to min(10, FM_CHECK_TIMEOUT minus a margin), reading FM_CHECK_TIMEOUT only on the configured read path so unconfigured runs still ignore the environment. Asking first because that brings back an environment read, which your 'one fixed internal bound' wording may have meant to exclude. Leaving it as is and documenting that FM_CHECK_TIMEOUT must stay above about 12 is the other option.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 8 of 9 scenarios driven live against the product
Scenario Result Live Evidence
An unconfigured user runs check (even with quota-axi absent and a bogus FM_CHECK_TIMEOUT) and sees no output, exit 0, no state written; arm refuses ✅ pass live on-demand-transcript.txt S1
A user with five_hour:20 runs check on demand while the real five_hour window reads 22% and gets one warning line plus one notification and a de-dupe record ✅ pass live on-demand-transcript.txt S2
Repeated checks while the window stays above its threshold stay silent (edge-triggered de-dupe) ✅ pass live on-demand-transcript.txt S3
After a read below threshold clears the record, the next crossing warns again (the drop was simulated by raising the threshold to 99, since the live window cannot be forced down) ✅ pass live on-demand-transcript.txt S4
Every quota-axi call is read-only: --no-credential-refresh always, --allow-keychain-prompt never ✅ pass live on-demand-transcript.txt S5 (argv log of 5 real calls)
arm registers a trusted check, and the real fm-watch.sh periodic sweep dispatches it and surfaces the warning as its wake reason ✅ pass live watcher-transcript.txt S6
Adversarial: with FM_CHECK_TIMEOUT=5 and a hanging quota-axi, the warner reports its own bounded timeout inside the watcher budget, and with FM_CHECK_TIMEOUT=2 it records not-measured and exits 0 imme… ✅ pass live watcher-transcript.txt S7/S7b
disarm removes the shim, trust file and record, and the next watcher sweep posts no warning ✅ pass live watcher-transcript.txt S8
A crossing shows a visible 'Firstmate: Claude usage' banner in macOS Notification Center ⏸️ untested no The banner could not be captured on screen: screencapture failed with 'could not create image from display' because this agent process lacks the macOS Screen Recording permission. Grant it to the term…
  • bash tests/fm-usage-warner.test.sh (baseline targeted suite, 19 cases)
  • ~/.no-mistakes/evidence/01M37WQ78FK5ZNWFRM18FZ8GBR/drive-on-demand.sh: on-demand fm-usage-warner.sh check|arm against the real quota-axi (five_hour read 22%) in a throwaway FM_HOME, with a quota-axi wrapper that logs argv, then passes the call to the real binary, plus an osascript recorder
  • ~/.no-mistakes/evidence/01M37WQ78FK5ZNWFRM18FZ8GBR/drive-watcher.sh: fm-usage-warner.sh arm, then the real bin/fm-watch.sh (FM_CHECK_INTERVAL=0, fake tmux) dispatching the armed shim; a hanging-quota-axi run with FM_CHECK_TIMEOUT=5 under the watcher; FM_CHECK_TIMEOUT=2 on demand; disarm, then another watcher sweep
  • FM_HOME=&lt;tmp&gt; bin/fm-usage-warner.sh check with the real osascript (a real Notification Center post), followed by a screencapture -x attempt
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A threshold warner, not a viewer: fm-usage-warner.sh runs quota-axi's
existing read-only --json snapshot (never a credential refresh) and
posts a macOS Notification Center banner, edge-triggered with a
de-dupe record, only when a configured window crosses a configured
percentage. Silent and inert when unconfigured; arm refuses without a
threshold or off macOS. Reuses the watcher's existing check-shim
cadence rather than a new schedule or daemon.
…this PR, and that is now fixed. Shard 7 (fm-contributions.test.sh) failed for a reason outside this PR, so I left it alone. - **Shard 5:** `action_arm` refuses to run on anything but macOS before it checks for thresholds. The arm tests ran on a Linux runner without a Darwin stub. So `test_arm_refuses_without_a_configured_threshold` got "only available on macOS" when it expected "no threshold configured", and the three arm tests after it would have failed the same way. Fix: the test now makes one `uname` stub that prints Darwin (`DARWIN_BIN`) and puts it first on PATH for every `arm` call. The Linux-refusal test keeps its own stub that prints Linux. `bin/fm-usage-warner.sh` is unchanged. Checked: all 19 cases pass on macOS, all 19 pass with a fake `uname` printing Linux on PATH to stand in for the CI runner, and `shellcheck -x` is clean. - **Shard 7:** the failing assertion is `test_reservation_defers_later_url_when_fifteen_seconds_do_not_remain` ("a later PR began without the fifteen-second observation reservation"). It depends on the wall clock and a 20-second budget. This PR changes only usage-warner files (`bin/fm-usage-warner.sh`, its test, and docs) and does not touch `fm-contributions`. This looks like a timing flake on the runner, not something this change caused. The only file changed is `tests/fm-usage-warner.test.sh`, and it is not committed
… `tests/fm-usage-warner.test.sh`. `bin/fm-usage-warner.sh` is unchanged. The failing case was `test_arm_writes_and_binds_the_check_and_disarm_removes_it`, which reported "arm must succeed: could not write .../state/usage-warner.check.sh". The last fix round put a `uname` stub that prints Darwin in front of every `arm` call. But the stat helpers in `bin/fm-pr-lib.sh` (`fm_pr_file_device`, `fm_pr_file_mode`) also check `uname`, so the stub sent them to BSD `/usr/bin/stat -f` on the Linux runner. That call fails, so `shim_write` could never succeed. The symlink-refusal case only passed on Linux by accident, because this stat failure produces the same "could not write" message. Fix: - The Darwin stub is now used only by `test_arm_refuses_without_a_configured_threshold`. That check returns before any stat call, so the case still means something on Linux. - The three cases that go through the real shim write (arm/disarm, symlink refusal, armed shim runs a real check) no longer use the stub. They run only when the host is really Darwin. On other platforms the test prints one `ok - ... macOS-only; skipping on <os>` line, the same way `fm-stat-shadowing.test.sh` handles its Darwin-only cases. `arm` itself refuses to run anywhere but macOS, so those cases have nothing real to test on Linux. Checked: - On macOS, all cases pass. - With a `uname` stub that prints Linux first on PATH (standing in for the CI runner), every case passes or skips as expected and the exit code is 0. - `shellcheck -x` is clean. The change is not committed
@max-metaplanet
max-metaplanet merged commit 7ec98fa into main Sep 23, 2026
35 of 37 checks passed
max-metaplanet added a commit that referenced this pull request Oct 6, 2026
Carried from fork commit 80595ae (#3).

Conflict resolution in docs/configuration.md: upstream has since restructured
the watched-tool-updates section into labelled sub-headings with bullet lists.
As authored, this commit inserted the usage-warner heading partway through that
section's prose, so the warner section absorbed four lines and a settings
paragraph that describe watched tool updates rather than the warner - the
`FM_TOOL_UPDATE_*` bounds, the watched-tool edit note, and the secondmate
inheritance note about watched tools.
Upstream's restructure now owns all of that correctly under its own headings, so
the warner is placed as a self-contained section after it and carries only the
warner's own schema and arming contract, with its own one-line statement that
the file is not inherited by secondmate homes.
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.

1 participant