@integrity-labs/agt-cli 0.27.7-test.5 → 0.27.7-test.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env bash
2
+ # Augmented Team — impersonation statusline (ENG-5801).
3
+ #
4
+ # Renders a `🤖 <display-name>` badge in Claude Code's statusline when the
5
+ # operator is inside the project directory where they ran
6
+ # `agt impersonate connect`. Other Claude Code sessions on the machine —
7
+ # including ones in different projects, or this same project after `exit` —
8
+ # render plain `dir git:(branch) ✗` with no badge.
9
+ #
10
+ # Read-only. No `agt` shell-out; just stat + a small Python JSON parse, so
11
+ # refresh cost is negligible.
12
+
13
+ set -u
14
+
15
+ manifest="$HOME/.augmented-impersonate/active/manifest.json"
16
+
17
+ if [ -f "$manifest" ]; then
18
+ # Extract project_cwd, code_name, expires_at from the manifest. Python is
19
+ # preinstalled on macOS and matches Node's JSON precisely (jq isn't
20
+ # guaranteed to be on PATH).
21
+ read -r project_cwd code_name expires_at < <(
22
+ python3 - "$manifest" <<'PY' 2>/dev/null
23
+ import json, sys
24
+ try:
25
+ with open(sys.argv[1]) as f:
26
+ m = json.load(f)
27
+ print(m.get("project_cwd", ""), m.get("code_name", ""), m.get("expires_at", ""))
28
+ except Exception:
29
+ pass
30
+ PY
31
+ )
32
+
33
+ # Only render the badge when this Claude Code session is INSIDE the
34
+ # project where impersonate connect ran. The marker is intentionally
35
+ # global ("one impersonation at a time" by design) so we must scope here.
36
+ if [ -n "${project_cwd:-}" ] && [ "$project_cwd" = "$PWD" ]; then
37
+ # Prefer the H1 display name from the rendered persona CLAUDE.md so the
38
+ # badge reads `🤖 Koda` not `🤖 koda`. Falls back to code_name when the
39
+ # persona file is missing or has no H1.
40
+ display_name="$code_name"
41
+ persona_md="$HOME/.augmented-impersonate/$code_name/CLAUDE.md"
42
+ if [ -f "$persona_md" ]; then
43
+ h1=$(awk '/^# / { sub(/^# +/, ""); print; exit }' "$persona_md" 2>/dev/null)
44
+ [ -n "$h1" ] && display_name="$h1"
45
+ fi
46
+
47
+ # expires_at is unix-seconds (matches the manifest's number type). Red
48
+ # EXPIRED badge cues the operator to run `agt impersonate exit`.
49
+ expired=0
50
+ if [ -n "${expires_at:-}" ]; then
51
+ now_epoch=$(date -u +%s)
52
+ # Strip any trailing decimals defensively in case a future manifest
53
+ # writes a float.
54
+ exp_int=${expires_at%%.*}
55
+ if [ -n "$exp_int" ] && [ "$exp_int" -lt "$now_epoch" ] 2>/dev/null; then
56
+ expired=1
57
+ fi
58
+ fi
59
+
60
+ if [ "$expired" = "1" ]; then
61
+ printf "\033[1;41m 🤖 %s EXPIRED \033[0m " "$display_name"
62
+ else
63
+ printf "\033[1;45m 🤖 %s \033[0m " "$display_name"
64
+ fi
65
+
66
+ # Also rename the terminal tab to the agent name so operators with
67
+ # multiple impersonation windows can tell them apart at a glance.
68
+ # OSC 1 sets the tab title in iTerm2, Terminal.app, Kitty, Alacritty,
69
+ # and most modern terminals. Emitting it every refresh is cheap (same
70
+ # value = no-op for the terminal). On `agt impersonate exit` the
71
+ # operator's user statusline takes over and stops emitting this — the
72
+ # tab title stays stale until the next process changes it; `exit`
73
+ # emits a one-shot reset to put that right.
74
+ printf "\033]1;🤖 %s\007" "$display_name"
75
+ fi
76
+ fi
77
+
78
+ # --- baseline dir + git segment ---
79
+ current_dir=$(basename "$PWD")
80
+ if git rev-parse --git-dir >/dev/null 2>&1; then
81
+ branch=$(git branch --show-current 2>/dev/null)
82
+ printf "\033[36m%s\033[0m \033[1;34mgit:(\033[31m%s\033[1;34m)\033[0m" "$current_dir" "$branch"
83
+ if ! git diff --quiet 2>/dev/null || ! git diff --cached --quiet 2>/dev/null; then
84
+ printf " \033[33m✗\033[0m"
85
+ fi
86
+ else
87
+ printf "\033[36m%s\033[0m" "$current_dir"
88
+ fi