Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ”§ chore(acceptance): update skill to 0.7.2 (#20381)

AmAzing-6dbe4f1e3f63
diff --git a/.agents/acceptance/PROCESS.md b/.agents/acceptance/PROCESS.md
index 2943b194311..a2a7c645e88 100644
--- a/.agents/acceptance/PROCESS.md
+++ b/.agents/acceptance/PROCESS.md
@@ -233,7 +233,11 @@ bash "$GUARD" claim "$!" # the dev server this run
`stop-owned` stops only what this run tagged or claimed, so a sibling run's browser
and a dev server the user started are never in its kill set. `bash "$GUARD" check --json` gives one verdict on the same thresholds the watcher uses (0 green, 10
-yellow, 20 red). Thresholds and groups are in `PROJECT.md` Β§5.
+yellow, 20 red, 2 unknown/error). On macOS the watcher requires three consecutive
+red samples before stopping processes; inspect `events.jsonl` to distinguish
+pending confirmation from actual stops. An unknown pressure reading is not healthy
+and must be resolved, but never triggers termination. Platform policy and groups
+are in `PROJECT.md` Β§5.
Generic capture helpers come from the installed skill, not the project layer:
diff --git a/.agents/acceptance/PROJECT.md b/.agents/acceptance/PROJECT.md
index 3645355f633..25e9e273a47 100644
--- a/.agents/acceptance/PROJECT.md
+++ b/.agents/acceptance/PROJECT.md
@@ -355,7 +355,7 @@ export ACCEPTANCE_RUN_TAG="acceptance-<subject>-<timestamp>-$$" # required
bash "$GUARD" start # before the first heavy command
bash "$GUARD" claim <pid>... # a process this run started
bash "$GUARD" claim-browser <session> # the browser behind an agent-browser session
-bash "$GUARD" check --json # one verdict; 0 green, 10 yellow, 20 red
+bash "$GUARD" check --json # 0 green, 10 yellow, 20 red, 2 unknown/error
bash "$GUARD" status --json # samples, tiers, recorded stops
bash "$GUARD" stop # teardown, always
```
@@ -364,15 +364,23 @@ bash "$GUARD" stop # teardown, always
| ------------------------- | --------------------------------------------- | ---------------------------------------------------------- |
| `ACCEPTANCE_RUN_TAG` | β€” (required) | Proves ownership; must be β‰₯ 8 chars and `[A-Za-z0-9._-]+` |
| `ACCEPTANCE_GUARD_DIR` | `${TMPDIR:-/tmp}/lobe-acceptance/guard/<tag>` | Keeps the run's samples and claims out of the working tree |
-| `ACCEPTANCE_GUARD_YELLOW` | `swap=60,free=20` | Recycle before red |
-| `ACCEPTANCE_GUARD_RED` | `swap=80,free=8` | Stop this run's claimed processes |
+| `ACCEPTANCE_GUARD_YELLOW` | `swap=60,free=20` | Linux host warning thresholds |
+| `ACCEPTANCE_GUARD_RED` | `swap=80,free=8` | Linux host stop thresholds |
Thresholds are host-level on purpose. The groups (`Google Chrome for Testing`,
`next-server|vite`, `tsgo`) also match other worktrees' servers and other runs'
browsers β€” five such processes held \~20 GB here β€” so a group or total RSS cap turns a
-merely busy machine red and stops a healthy run. Swap exhaustion is what actually
-freezes the host, so that is what the tier is made of; the groups exist so
-`stop-owned` has something it is allowed to stop.
+merely busy machine red and stops a healthy run. The groups select what
+`stop-owned` may stop; they do not determine this adapter's tier.
+
+On **macOS**, kernel pressure (`kern.memorystatus_vm_pressure_level`: 1 normal,
+2 warning, 4 critical) determines the tier. Free-page and swap percentages are
+diagnostics only: neither low unused RAM nor a high fraction of dynamically
+allocated swap proves exhaustion. Three consecutive red samples are required
+before automatic termination. Unknown pressure exits 2 and never kills processes.
+On **Linux**, the existing `MemAvailable` and swap thresholds apply; cgroup/PSI
+support is not implemented. Native Windows is unsupported. See the skill's
+[platform policy](../skills/acceptance/references/resource-guard.md#platform-policy).
## 6. Known constraints
diff --git a/.agents/acceptance/scripts/acceptance-guard.sh b/.agents/acceptance/scripts/acceptance-guard.sh
index 41fb6e0802b..891895e1e43 100755
--- a/.agents/acceptance/scripts/acceptance-guard.sh
+++ b/.agents/acceptance/scripts/acceptance-guard.sh
@@ -12,7 +12,7 @@
# acceptance-guard.sh start start this run's sampler
# acceptance-guard.sh claim <pid>... register a process this run started
# acceptance-guard.sh claim-browser [session] claim the browser behind an agent-browser session
-# acceptance-guard.sh check [--json] one sample now; exit 0 green, 10 yellow, 20 red
+# acceptance-guard.sh check [--json] exit 0 green, 10 yellow, 20 red, 2 unknown/error
# acceptance-guard.sh status [--json] this run's recorded guard state
# acceptance-guard.sh stop stop the sampler (teardown; always)
#
@@ -27,8 +27,9 @@
# The thresholds are host-level on purpose. The group patterns below also match other
# worktrees' servers and other runs' browsers β€” five such processes held ~20 GB here
# β€” so a group or total RSS cap would turn a merely busy machine red and stop a
-# healthy run. Swap exhaustion is what actually freezes the host, so that is what
-# this adapter tiers on; the groups exist so `stop-owned` has something it may stop.
+# healthy run. macOS tiers on kernel memory pressure (three consecutive red samples
+# before stop-owned); Linux uses the swap/free thresholds below. On macOS swap and
+# free percentages are diagnostic only. The groups select what stop-owned may stop.
#
# Contract: .agents/skills/acceptance/references/resource-guard.md
set -uo pipefail
diff --git a/.agents/acceptance/scripts/resource-guard.test.sh b/.agents/acceptance/scripts/resource-guard.test.sh
new file mode 100755
index 00000000000..352df3092a1
--- /dev/null
+++ b/.agents/acceptance/scripts/resource-guard.test.sh
@@ -0,0 +1,121 @@
+#!/usr/bin/env bash
+# Local regression coverage for the macOS pressure policy in the installed guard.
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "$0")/../../.." && pwd)"
+GUARD="$ROOT/.agents/skills/acceptance/scripts/resource-guard.sh"
+TMP="$(mktemp -d)"
+trap 'rm -rf "$TMP"' EXIT
+mkdir -p "$TMP/bin"
+export GUARD_TEST_DIR="$TMP"
+
+cat > "$TMP/bin/uname" <<'SH'
+#!/usr/bin/env bash
+echo "${TEST_PLATFORM:-Darwin}"
+SH
+cat > "$TMP/bin/sysctl" <<'SH'
+#!/usr/bin/env bash
+case "$2" in
+ hw.memsize) echo 25769803776 ;;
+ vm.swapusage) echo 'total = 1024.00M used = 950.00M free = 74.00M (encrypted)' ;;
+ kern.memorystatus_vm_pressure_level)
+ if [ -f "$GUARD_TEST_DIR/sequence" ]; then
+ n=$(cat "$GUARD_TEST_DIR/index")
+ n=$((n + 1))
+ echo "$n" > "$GUARD_TEST_DIR/index"
+ value=$(sed -n "${n}p" "$GUARD_TEST_DIR/sequence")
+ else
+ value="${TEST_PRESSURE:-1}"
+ fi
+ [ "$value" != missing ] || exit 1
+ echo "$value"
+ ;;
+ *) exit 1 ;;
+esac
+SH
+cat > "$TMP/bin/vm_stat" <<'SH'
+#!/usr/bin/env bash
+# Approximately 4% free, based on the captured 24 GiB host; swap is also >80%.
+echo 'Mach Virtual Memory Statistics: (page size of 16384 bytes)'
+echo 'Pages free: 63491.'
+echo 'Pages speculative: 5373.'
+SH
+cat > "$TMP/bin/ps" <<'SH'
+#!/usr/bin/env bash
+# No real processes may be selected by these watcher tests.
+exit 0
+SH
+cat > "$TMP/bin/sleep" <<'SH'
+#!/usr/bin/env bash
+if [ -f "$GUARD_TEST_DIR/sequence" ]; then
+ n=$(cat "$GUARD_TEST_DIR/index")
+ total=$(wc -l < "$GUARD_TEST_DIR/sequence")
+ if [ "$n" -ge "$total" ]; then rm -f "$GUARD_TEST_DIR/state/guard.pid"; fi
+fi
+SH
+chmod +x "$TMP/bin/"*
+export PATH="$TMP/bin:$PATH"
+
+check() {
+ local expected_exit="$1" expected_tier="$2"
+ shift 2
+ local status=0 output
+ output=$(bash "$GUARD" check --yellow swap=60,free=20 --red swap=80,free=8 --json "$@") || status=$?
+ [ "$status" -eq "$expected_exit" ] || { echo "FAIL: exit $status, expected $expected_exit: $output"; exit 1; }
+ if [ -n "$expected_tier" ]; then
+ echo "$output" | grep -q "\"platform\":\"Darwin\",\"tier\":\"$expected_tier\"" || { echo "FAIL: $output"; exit 1; }
+ fi
+ LAST_OUTPUT="$output"
+}
+
+TEST_PRESSURE=1 check 0 green
+echo "$LAST_OUTPUT" | grep -q '"pressure":{"level":1,"status":"normal"}'
+echo "$LAST_OUTPUT" | grep -q '"free":{"pct":4}'
+echo "$LAST_OUTPUT" | grep -q '"usedMb":950'
+TEST_PRESSURE=2 check 10 yellow
+TEST_PRESSURE=4 check 20 red
+TEST_PRESSURE=missing check 2 unknown
+TEST_PRESSURE=8 check 2 unknown
+
+# Explicit process budgets remain enforced. A later yellow pressure breach must
+# not override the top-level red verdict when extracting the exit code.
+TEST_PRESSURE=2 check 20 red --red total.rss=0
+
+TEST_PLATFORM=Windows_NT check 2 ''
+
+watch_case() {
+ local sequence="$1" expected_stops="$2" expected_pending="$3"
+ printf '%s\n' "$sequence" | tr ',' '\n' > "$TMP/sequence"
+ echo 0 > "$TMP/index"
+ mkdir -p "$TMP/state"
+ cat > "$TMP/state/config" <<'CONF'
+RUN_TAG=guard-test-owned
+INTERVAL=10
+ON_RED=stop-owned
+GRACE=0
+YELLOW=swap=60,free=20
+RED=swap=80,free=8
+CONF
+ : > "$TMP/state/guard.pid"
+ : > "$TMP/state/events.jsonl"
+ : > "$TMP/state/samples.jsonl"
+ bash "$GUARD" __watch --state-dir "$TMP/state"
+ local stops pending
+ stops=$(grep -c '"action":"stop-owned"' "$TMP/state/events.jsonl" || true)
+ pending=$(grep -c '"action":"pending"' "$TMP/state/events.jsonl" || true)
+ [ "$stops" -eq "$expected_stops" ] && [ "$pending" -eq "$expected_pending" ] || {
+ echo "FAIL: sequence=$sequence stops=$stops pending=$pending"
+ cat "$TMP/state/events.jsonl"
+ exit 1
+ }
+}
+
+watch_case '1,1,1' 0 0
+watch_case '4,4' 0 2
+watch_case '4,4,4' 1 2
+watch_case '4,4,1,4,4,4' 1 4
+watch_case '4,4,2,4,4' 0 4
+watch_case '4,4,missing,4,4' 0 4
+watch_case '4,4,8,4,4' 0 4
+
+echo 'resource-guard.test.sh: ok'
diff --git a/.agents/skills/acceptance/SKILL.md b/.agents/skills/acceptance/SKILL.md
index 5089a7b6e73..f1693c595c2 100644
--- a/.agents/skills/acceptance/SKILL.md
+++ b/.agents/skills/acceptance/SKILL.md
@@ -2,7 +2,7 @@
name: acceptance
license: Apache-2.0
metadata:
- version: "0.7.0"
+ version: "0.7.2"
description: >
End-to-end verification and self-evidence for a delivery in any repository,
with or without a preconfigured verify plan. Discover an existing plan when
diff --git a/.agents/skills/acceptance/references/agent-browser.md b/.agents/skills/acceptance/references/agent-browser.md
index 693cea4d902..f5d1a959405 100644
--- a/.agents/skills/acceptance/references/agent-browser.md
+++ b/.agents/skills/acceptance/references/agent-browser.md
@@ -237,8 +237,9 @@ Providers: `agentcore`, `browserbase`, `browserless`, `browseruse`, `kernel`.
- **Sessions leak when not closed** β€” daemons never exit on their own unless
`AGENT_BROWSER_IDLE_TIMEOUT_MS` is set, and `session list` can miss a daemon
whose run already died. Reap by pid, not only by session name, and keep the
- [resource guard](resource-guard.md) running so a host that starts swapping is
- stopped at the threshold instead of freezing.
+ [resource guard](resource-guard.md) running. With `stop-owned`, it stops only
+ this run's owned processes when the platform-specific stop conditions are met;
+ swap usage alone does not trigger a stop on macOS.
- **HMR invalidates everything** β€” after code changes during dev, refs break;
re-snapshot or restart.
- **`snapshot -i` doesn't find contenteditable** β€” use `snapshot -i -C` for rich
diff --git a/.agents/skills/acceptance/references/resource-guard.md b/.agents/skills/acceptance/references/resource-guard.md
index 4523c2ffe75..7ee478feed6 100644
--- a/.agents/skills/acceptance/references/resource-guard.md
+++ b/.agents/skills/acceptance/references/resource-guard.md
@@ -14,9 +14,32 @@ classifies a tier, and at **red** stops only the processes this run started.
| Dev servers and type-check workers | A dev server and a type checker per run; concurrent runs multiply them. |
| Recordings | Frame sequences held in memory until they are assembled and written. |
-**Swap exhaustion, not total RAM, is what freezes the host.** When a machine that
-was fine becomes unusable mid-run, measure `sysctl vm.swapusage` (macOS) or
-`/proc/meminfo` (Linux) before blaming the browser.
+**Low unused RAM is not necessarily memory pressure.** macOS can retain large
+reclaimable caches with little free RAM and no swapping. Use the kernel pressure
+signal rather than terminating services because of a low free-page percentage.
+
+## Platform policy
+
+- **macOS:** `kern.memorystatus_vm_pressure_level` exports `1` = normal,
+ `2` = warning, `4` = critical (not the kernel's internal enum). These map to
+ green/yellow/red. `swap` and `free` stay in samples as diagnostics; their
+ percentage thresholds do not apply on macOS. Swap allocation grows dynamically,
+ so its used percentage is not an exhaustion signal either. Explicit RSS/count
+ budgets still apply. Missing or unrecognized pressure is `unknown`, exits 2
+ on `check`, and never triggers automatic termination.
+- **Linux:** existing `MemAvailable / MemTotal` and swap-percentage thresholds
+ remain unchanged. They describe the host; this guard does not yet account for
+ cgroup limits or PSI. Do not infer container safety from a green host sample.
+- **Native Windows:** unsupported. WSL uses the Linux policy, not Windows host
+ memory monitoring.
+
+On macOS, `stop-owned` requires **three consecutive red samples** (about 20 seconds
+between the first and third at the default interval). Earlier red samples record
+`action: pending`; the third permits `action: stop-owned`. Any non-red sample,
+including unknown, resets the consecutive count. A one-shot `check` still reports
+the current tier immediately and never kills processes. Linux keeps its existing
+immediate red action. This confirmation window is an initial policy, not a
+guarantee that every workload tolerates that delay.
## Run it
@@ -36,13 +59,14 @@ bash "$GUARD" start \
bash "$GUARD" claim --state-dir "$RUN_DIR" --pid "$BROWSER_DAEMON_PID" # what this run started
-bash "$GUARD" check --json # one verdict now; exit 0 green, 10 yellow, 20 red
+bash "$GUARD" check --json # exit 0 green, 10 yellow, 20 red, 2 unknown/error
bash "$GUARD" status --state-dir "$RUN_DIR" --json # samples, red/yellow counts, recorded events
bash "$GUARD" stop --state-dir "$RUN_DIR" # at teardown, always
```
Threshold spec: comma-separated `KEY=VALUE`, any subset of
`swap=PCT`, `free=PCT`, `total.rss=MB`, `group.NAME.rss=MB`, `group.NAME.count=N`.
+`swap` and `free` thresholds apply on Linux only, per the platform policy above.
`total.rss` is the summed RSS of the declared groups, so it stays 0 without
`--group`. `--group NAME=PATTERN` is repeatable; the pattern is an ERE matched
against each process command line. Keep patterns specific to the processes this run
@@ -75,7 +99,8 @@ mid-capture.
| --- | --- |
| green | Continue. |
| yellow | Recycle before it becomes red: close idle browser sessions, drop the oldest recording frames, re-check. |
-| red | The guard stops this run's owned heavy processes. Keep the evidence already in hand, mark the remaining checks `blocked` with the reason, and publish. |
+| red | Pause new heavy work; inspect `events.jsonl` for pending confirmation or actual stops. After a stop, keep existing evidence and mark interrupted/unexecuted checks `blocked` until the environment recovers and they are exercised. |
+| unknown | Pressure could not be determined. No automatic termination; resolve the missing signal before treating the environment as healthy. |
A red tier is a real observation, not a failure to hide: a check the run never
exercised is `blocked`, never `passed`.
diff --git a/.agents/skills/acceptance/scripts/resource-guard.sh b/.agents/skills/acceptance/scripts/resource-guard.sh
index db328e19025..f7f68a0b721 100644
--- a/.agents/skills/acceptance/scripts/resource-guard.sh
+++ b/.agents/skills/acceptance/scripts/resource-guard.sh
@@ -26,6 +26,9 @@
#
# Spec: comma-separated KEY=VALUE, any subset of
# swap=PCT free=PCT total.rss=MB group.NAME.rss=MB group.NAME.count=N
+# swap/free thresholds apply on Linux only. On macOS these remain diagnostics;
+# kern.memorystatus_vm_pressure_level supplies normal/warning/critical instead.
+# A macOS watcher requires three consecutive red samples before stop-owned.
# total.rss is the summed RSS of the declared groups, so it stays 0 without --group.
# Ownership is positive, never inferred from timing: a process belongs to this run
# only when its command line contains the run tag, or it was registered with `claim`,
@@ -34,7 +37,7 @@
# would otherwise be stopped by this one. stop-owned only ever stops owned processes,
# and only in the groups named with --group: never a process-name kill.
#
-# Exit (check): 0 green, 10 yellow, 20 red, 2 unsupported platform or bad usage.
+# Exit (check): 0 green, 10 yellow, 20 red, 2 unknown pressure/unsupported/usage.
set -uo pipefail
PROG='[resource-guard]'
@@ -144,8 +147,10 @@ emit_sample() {
local groups="$1" yellow="$2" red="$3"
local swap_out free_out swap_pct swap_mb swap_total free_pct
local breaches="" tier="green" line name pattern stats count rss yv rv
+ local platform pressure_level pressure_status pressure_json="null"
local total_rss=0
+ platform="$(platform_name)"
swap_out="$(read_swap || true)"
free_out="$(read_free || true)"
swap_pct=""; swap_mb=""; swap_total=""; free_pct=""
@@ -196,7 +201,9 @@ emit_sample() {
breaches="${breaches}{\"metric\":\"total.rss\",\"value\":${total_rss},\"threshold\":${yv},\"tier\":\"yellow\"},"
fi
- if [ -n "$swap_pct" ]; then
+ # macOS swap allocation grows dynamically, and free+speculative pages exclude
+ # reclaimable memory. Neither ratio is a destructive-action pressure signal.
+ if [ "$platform" = Linux ] && [ -n "$swap_pct" ]; then
yv="$(spec_value "$yellow" swap)"; rv="$(spec_value "$red" swap)"
if ge "$swap_pct" "$rv"; then
tier="red"; breaches="${breaches}{\"metric\":\"swap\",\"value\":${swap_pct},\"threshold\":${rv},\"tier\":\"red\"},"
@@ -205,7 +212,7 @@ emit_sample() {
breaches="${breaches}{\"metric\":\"swap\",\"value\":${swap_pct},\"threshold\":${yv},\"tier\":\"yellow\"},"
fi
fi
- if [ -n "$free_pct" ]; then
+ if [ "$platform" = Linux ] && [ -n "$free_pct" ]; then
yv="$(spec_value "$yellow" free)"; rv="$(spec_value "$red" free)"
if [ -n "$rv" ] && awk -v v="$free_pct" -v t="$rv" 'BEGIN{ exit !(v+0<=t+0) }'; then
tier="red"; breaches="${breaches}{\"metric\":\"free\",\"value\":${free_pct},\"threshold\":${rv},\"tier\":\"red\"},"
@@ -214,15 +221,39 @@ emit_sample() {
breaches="${breaches}{\"metric\":\"free\",\"value\":${free_pct},\"threshold\":${yv},\"tier\":\"yellow\"},"
fi
fi
+ if [ "$platform" = Darwin ]; then
+ # The sysctl exports dispatch flags (1/2/4), NOT the internal 0/1/2/3 enum.
+ pressure_level="$(sysctl -n kern.memorystatus_vm_pressure_level 2>/dev/null)" || pressure_level=""
+ case "$pressure_level" in
+ 1) pressure_status=normal ;;
+ 2)
+ pressure_status=warning
+ [ "$tier" = red ] || tier=yellow
+ breaches="${breaches}{\"metric\":\"pressure\",\"value\":2,\"tier\":\"yellow\"},"
+ ;;
+ 4)
+ pressure_status=critical
+ tier=red
+ breaches="${breaches}{\"metric\":\"pressure\",\"value\":4,\"tier\":\"red\"},"
+ ;;
+ *)
+ pressure_status=unknown
+ pressure_level=null
+ tier=unknown
+ breaches="${breaches}{\"metric\":\"pressure\",\"value\":null,\"tier\":\"unknown\"},"
+ ;;
+ esac
+ pressure_json="{\"level\":${pressure_level},\"status\":\"${pressure_status}\"}"
+ fi
breaches="${breaches%,}"
- printf '{"ts":%s,"platform":"%s","tier":"%s","swap":%s,"free":%s,"totalRssMb":%s,"groups":{%s},"breaches":[%s]}\n' \
- "$(date +%s)" "$(platform_name)" "$tier" "$swap_json" "$free_json" "$total_rss" "$groups_json" "$breaches"
+ printf '{"ts":%s,"platform":"%s","tier":"%s","pressure":%s,"swap":%s,"free":%s,"totalRssMb":%s,"groups":{%s},"breaches":[%s]}\n' \
+ "$(date +%s)" "$platform" "$tier" "$pressure_json" "$swap_json" "$free_json" "$total_rss" "$groups_json" "$breaches"
}
count_lines() { [ -f "$1" ] || { echo 0; return; }; local n; n="$(wc -l < "$1" | tr -d ' ')"; echo "${n:-0}"; }
count_match() { [ -f "$2" ] || { echo 0; return; }; local n; n="$(grep -c -e "$1" "$2" 2>/dev/null)"; echo "${n:-0}"; }
-tier_of() { printf '%s\n' "$1" | sed -n 's/.*"tier":"\([a-z]*\)".*/\1/p'; }
+tier_of() { printf '%s\n' "$1" | sed -n 's/^[^{]*{[^}]*"platform":"[^"]*","tier":"\([a-z]*\)".*/\1/p'; }
# --- modes -------------------------------------------------------------------
@@ -249,7 +280,8 @@ do_check() {
case "$tier" in
green) exit 0 ;;
yellow) exit 10 ;;
- *) exit 20 ;;
+ red) exit 20 ;;
+ *) exit 2 ;;
esac
}
@@ -341,16 +373,18 @@ stop_owned() { # $1 group name, $2 pattern, $3 newline-separated owned set
}
watch_loop() {
- local plat sample tier
+ local plat sample tier red_streak=0 required_red=1
plat="$(platform_name)"
case "$plat" in Darwin|Linux) ;; *) fail "Unsupported platform: $plat" ;; esac
+ [ "$plat" != Darwin ] || required_red=3
load_config
while [ -f "$STATE_DIR/guard.pid" ]; do
sample="$(emit_sample "$GROUP_SPECS" "$YELLOW" "$RED")"
printf '%s\n' "$sample" >> "$STATE_DIR/samples.jsonl"
tier="$(tier_of "$sample")"
- if [ "$tier" = red ] && [ "$ON_RED" = stop-owned ]; then
- printf '{"ts":%s,"event":"tier","tier":"red","action":"stop-owned"}\n' "$(date +%s)" >> "$STATE_DIR/events.jsonl"
+ if [ "$tier" = red ]; then red_streak=$((red_streak + 1)); else red_streak=0; fi
+ if [ "$tier" = red ] && [ "$ON_RED" = stop-owned ] && [ "$red_streak" -ge "$required_red" ]; then
+ printf '{"ts":%s,"event":"tier","tier":"red","action":"stop-owned","consecutiveRed":%s}\n' "$(date +%s)" "$red_streak" >> "$STATE_DIR/events.jsonl"
local line name pattern owned
owned="$(owned_set)"
while IFS= read -r line; do
@@ -358,6 +392,8 @@ watch_loop() {
name="${line%%=*}"; pattern="${line#*=}"
stop_owned "$name" "$pattern" "$owned"
done <<< "$GROUP_SPECS"
+ elif [ "$tier" = red ] && [ "$ON_RED" = stop-owned ]; then
+ printf '{"ts":%s,"event":"tier","tier":"red","action":"pending","consecutiveRed":%s}\n' "$(date +%s)" "$red_streak" >> "$STATE_DIR/events.jsonl"
elif [ "$tier" != green ]; then
printf '{"ts":%s,"event":"tier","tier":"%s","action":"none"}\n' "$(date +%s)" "$tier" >> "$STATE_DIR/events.jsonl"
fi
@@ -407,19 +443,20 @@ do_stop() {
do_status() {
[ -n "$STATE_DIR" ] || fail "status needs --state-dir"
- local last events y r total running
+ local last events y r u total running
last="$(tail -n 1 "$STATE_DIR/samples.jsonl" 2>/dev/null)"
total="$(count_lines "$STATE_DIR/samples.jsonl")"
events="$(count_lines "$STATE_DIR/events.jsonl")"
y="$(count_match '"tier":"yellow"' "$STATE_DIR/samples.jsonl")"
r="$(count_match '"tier":"red"' "$STATE_DIR/samples.jsonl")"
+ u="$(count_match '"tier":"unknown"' "$STATE_DIR/samples.jsonl")"
running=no; [ -f "$STATE_DIR/guard.pid" ] && running=yes
if [ "$JSON" = 1 ]; then
- printf '{"running":%s,"samples":%s,"yellow":%s,"red":%s,"events":%s,"last":%s}\n' \
- "$([ "$running" = yes ] && echo true || echo false)" "$total" "$y" "$r" "$events" "${last:-null}"
+ printf '{"running":%s,"samples":%s,"yellow":%s,"red":%s,"unknown":%s,"events":%s,"last":%s}\n' \
+ "$([ "$running" = yes ] && echo true || echo false)" "$total" "$y" "$r" "$u" "$events" "${last:-null}"
else
- printf '%s running=%s samples=%s yellow=%s red=%s events=%s\n' \
- "$PROG" "$running" "$total" "$y" "$r" "$events"
+ printf '%s running=%s samples=%s yellow=%s red=%s unknown=%s events=%s\n' \
+ "$PROG" "$running" "$total" "$y" "$r" "$u" "$events"
[ -n "$last" ] && printf '%s\n' "$last"
fi
}