diff --git a/data/scripts/o b/data/scripts/o index 373bd03..b2cfc70 100755 --- a/data/scripts/o +++ b/data/scripts/o @@ -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 - 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 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 - # 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