aboutsummaryrefslogtreecommitdiff
path: root/hooks/session-start-disarm.sh
blob: 520d8c0035750d8f5fd89a2009b5f8b2e8b1720f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
#
# SessionStart: disarm any wrap sentinel left over from a previous session.
#
# wrap-it-up drops /tmp/ai-wrap-teardown-<project> (or -shutdown-) to ask the
# Stop hook to kill the tmux session once the wrap certifies clean. The Stop
# hook deliberately PRESERVES that sentinel when certification fails, so a wrap
# blocked by a dirty tree can retry on a later stop in the same session without
# the user re-running the workflow.
#
# Nothing bounded that retry to the session. A sentinel armed by a wrap that
# never certified survived indefinitely and fired in whatever session next
# happened to reach a clean tree:
#
#   work, 2026-07-27. The 11:37 wrap requested teardown, failed certification
#   on a dirty tree, and left the sentinel armed. A fresh session started at
#   13:20, committed twice during startup, went clean — and the next stop
#   consumed the two-hour-old sentinel and killed the terminal mid-work.
#   archsetup's had been armed for two days on a live attached session.
#
# A new session means the wrap that armed the sentinel is gone, so its pending
# teardown is meaningless: clear it. Within-session retry is untouched, because
# this only runs at session start. If the user still wants teardown, wrap-it-up
# re-arms it.
#
# Scoped to the current project's sentinels only — a concurrent session in
# another project keeps its own.
#
# Silent and exit 0 always. A SessionStart hook must never block a session from
# starting, and there is nothing here a user needs told.

set -u

payload="$(cat 2>/dev/null || true)"

cwd="$(printf '%s' "$payload" | jq -r '.cwd // empty' 2>/dev/null)"
[ -z "$cwd" ] && cwd="$PWD"
proj="$(basename "$cwd")"

rm -f "/tmp/ai-wrap-teardown-${proj}" "/tmp/ai-wrap-shutdown-${proj}"

exit 0