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"
|
echo "no pending bypass request"
|
||||||
return 0
|
return 0
|
||||||
fi
|
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
|
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 [[ "$count" -eq 0 ]]; then
|
||||||
echo "no pending bypass request"
|
if [[ -n "$CTX_AGENT" ]]; then
|
||||||
|
echo "no pending bypass request for agent $CTX_AGENT"
|
||||||
|
else
|
||||||
|
echo "no pending bypass request"
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
echo "$count pending bypass request(s):"
|
|
||||||
|
if [[ -n "$CTX_AGENT" ]]; then
|
||||||
|
echo "$count pending bypass request(s) for agent $CTX_AGENT:"
|
||||||
|
else
|
||||||
|
echo "$count pending bypass request(s):"
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
# Normalize to array and iterate
|
echo "$arr" | jq -r '
|
||||||
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"
|
"id: \(.id)\nagent: \(.env.OLLIE_UNAME // "unknown")\ncwd: \(.cwd)\ncmd: \(.cmd | split("\n")[0])\n"
|
||||||
' 2>/dev/null
|
' 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
@ -325,6 +342,11 @@ cmd_approve() {
|
||||||
local arr
|
local arr
|
||||||
arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null)
|
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
|
# Find the request to approve
|
||||||
local req
|
local req
|
||||||
if [[ -n "$req_id" ]]; then
|
if [[ -n "$req_id" ]]; then
|
||||||
|
|
@ -335,6 +357,14 @@ cmd_approve() {
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null)
|
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
|
fi
|
||||||
|
|
||||||
local id cmd cwd
|
local id cmd cwd
|
||||||
|
|
@ -380,6 +410,11 @@ cmd_deny() {
|
||||||
local arr
|
local arr
|
||||||
arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null)
|
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
|
# Find the request to deny
|
||||||
local req
|
local req
|
||||||
if [[ -n "$req_id" ]]; then
|
if [[ -n "$req_id" ]]; then
|
||||||
|
|
@ -390,6 +425,14 @@ cmd_deny() {
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null)
|
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
|
fi
|
||||||
|
|
||||||
local id cmd cwd
|
local id cmd cwd
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue