fix(gc): fast-fail respawn cap on permanent sessions (#54) (#56)
Fixes #54. A `strategy=permanent` session whose leaf exits within
`strategy.fast-fail-window` seconds (default 60) of its previous
`pty gc` respawn counts as a fast fail. After `strategy.fast-fail-limit`
consecutive fast fails (default 3), gc writes `strategy.status=flapping`
on the session, emits a `session_flapping` event, and stops respawning
it. Subsequent ticks print `Skipped (flapping): <name>` and take no
action. Closes the crash-loop-with-live-cwd gap that #47/#50's
cwd-gone + idle reap didn't catch.
Bookkeeping tags stamped on every respawn:
- strategy.last-respawn-at (ISO ts)
- strategy.consecutive-fast-fails (running counter)
- strategy.command-hash (16-char sha256 prefix of the respawn cmd)
The classifier compares the current command fingerprint against the
stored hash; a divergence auto-resets the counter and clears
`strategy.status=flapping`. Manual reset: `pty tag <name> --rm
strategy.status`.
Per-session overrides `strategy.fast-fail-window=<sec>` and
`strategy.fast-fail-limit=<int>` beat CLI globals
`--fast-fail-window=<sec>` / `--fast-fail-limit=<int>` (which mirror
the `--idle-days` shape).
GcResult gains `flapped` and `flappingSkipped` buckets — additive,
existing consumers unaffected. cmdGc surfaces both.
10 new tests in tests/gc-flapping.test.ts cover: dry-run preview,
at-limit persistence + session_flapping event, silent skip on
subsequent ticks, slow-fail counter reset, command-hash auto-reset,
per-session + CLI-global window/limit overrides, first-respawn
(no prior last-respawn-at) case.