o: filter bypass/approve/deny by agent when agent context is set
o session/agent bypass - shows only that agent's requests o session/agent approve - approves first request from that agent o session/agent deny - denies first request from that agent o session bypass - shows all requests (unchanged)
This commit is contained in:
parent
2c8b301a59
commit
859bb4910f
|
|
@ -290,18 +290,35 @@ cmd_bypass() {
|
|||
echo "no pending bypass request"
|
||||
return 0
|
||||
fi
|
||||
# Handle both single object and array of objects
|
||||
|
||||
# Normalize to array
|
||||
local arr
|
||||
arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null)
|
||||
|
||||
# Filter by agent if agent context is set
|
||||
if [[ -n "$CTX_AGENT" ]]; then
|
||||
arr=$(echo "$arr" | jq --arg agent "$CTX_AGENT" '[.[] | select(.env.OLLIE_UNAME == $agent)]' 2>/dev/null)
|
||||
fi
|
||||
|
||||
local count
|
||||
count=$(echo "$pending" | jq 'if type == "array" then length else 1 end' 2>/dev/null)
|
||||
count=$(echo "$arr" | jq 'length' 2>/dev/null)
|
||||
if [[ "$count" -eq 0 ]]; then
|
||||
if [[ -n "$CTX_AGENT" ]]; then
|
||||
echo "no pending bypass request for agent $CTX_AGENT"
|
||||
else
|
||||
echo "no pending bypass request"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -n "$CTX_AGENT" ]]; then
|
||||
echo "$count pending bypass request(s) for agent $CTX_AGENT:"
|
||||
else
|
||||
echo "$count pending bypass request(s):"
|
||||
fi
|
||||
echo
|
||||
# Normalize to array and iterate
|
||||
echo "$pending" | jq -r '
|
||||
(if type == "array" then . else [.] end) | .[] |
|
||||
echo "$arr" | jq -r '
|
||||
.[] |
|
||||
"id: \(.id)\nagent: \(.env.OLLIE_UNAME // "unknown")\ncwd: \(.cwd)\ncmd: \(.cmd | split("\n")[0])\n"
|
||||
' 2>/dev/null
|
||||
}
|
||||
|
|
@ -325,6 +342,11 @@ cmd_approve() {
|
|||
local arr
|
||||
arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null)
|
||||
|
||||
# Filter by agent if agent context is set
|
||||
if [[ -n "$CTX_AGENT" ]]; then
|
||||
arr=$(echo "$arr" | jq --arg agent "$CTX_AGENT" '[.[] | select(.env.OLLIE_UNAME == $agent)]' 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Find the request to approve
|
||||
local req
|
||||
if [[ -n "$req_id" ]]; then
|
||||
|
|
@ -335,6 +357,14 @@ cmd_approve() {
|
|||
fi
|
||||
else
|
||||
req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null)
|
||||
if [[ -z "$req" || "$req" == "null" ]]; then
|
||||
if [[ -n "$CTX_AGENT" ]]; then
|
||||
echo "no pending bypass request for agent $CTX_AGENT"
|
||||
else
|
||||
echo "no pending bypass request"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
local id cmd cwd
|
||||
|
|
@ -380,6 +410,11 @@ cmd_deny() {
|
|||
local arr
|
||||
arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null)
|
||||
|
||||
# Filter by agent if agent context is set
|
||||
if [[ -n "$CTX_AGENT" ]]; then
|
||||
arr=$(echo "$arr" | jq --arg agent "$CTX_AGENT" '[.[] | select(.env.OLLIE_UNAME == $agent)]' 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Find the request to deny
|
||||
local req
|
||||
if [[ -n "$req_id" ]]; then
|
||||
|
|
@ -390,6 +425,14 @@ cmd_deny() {
|
|||
fi
|
||||
else
|
||||
req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null)
|
||||
if [[ -z "$req" || "$req" == "null" ]]; then
|
||||
if [[ -n "$CTX_AGENT" ]]; then
|
||||
echo "no pending bypass request for agent $CTX_AGENT"
|
||||
else
|
||||
echo "no pending bypass request"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
local id cmd cwd
|
||||
|
|
|
|||
Loading…
Reference in New Issue