o: fix bypass command to handle array of pending requests

This commit is contained in:
Levi Neely 2026-10-09 12:54:39 +02:00
parent 780e558743
commit 995db45444
1 changed files with 15 additions and 10 deletions

View File

@ -286,19 +286,24 @@ cmd_bypass() {
local bypass_path="session/$CTX_SESSION/bypass"
local pending
pending=$(ollie-9p read "$bypass_path" 2>/dev/null || true)
if [[ -z "$pending" ]]; then
if [[ -z "$pending" || "$pending" == "[]" || "$pending" == "null" ]]; then
echo "no pending bypass request"
return 0
fi
local id cmd cwd agent
id=$(echo "$pending" | jq -r '.id' 2>/dev/null)
cmd=$(echo "$pending" | jq -r '.cmd' 2>/dev/null)
cwd=$(echo "$pending" | jq -r '.cwd' 2>/dev/null)
agent=$(echo "$pending" | jq -r '.env.OLLIE_UNAME // "unknown"' 2>/dev/null)
echo "id: $id"
echo "agent: $agent"
echo "cwd: $cwd"
echo "cmd: $cmd"
# Handle both single object and array of objects
local count
count=$(echo "$pending" | jq 'if type == "array" then length else 1 end' 2>/dev/null)
if [[ "$count" -eq 0 ]]; then
echo "no pending bypass request"
return 0
fi
echo "$count pending bypass request(s):"
echo
# Normalize to array and iterate
echo "$pending" | jq -r '
(if type == "array" then . else [.] end) | .[] |
"id: \(.id)\nagent: \(.env.OLLIE_UNAME // "unknown")\ncwd: \(.cwd)\ncmd: \(.cmd | split("\n")[0])\n"
' 2>/dev/null
}
cmd_approve() {