From 859bb4910f42ca4d86bb657c30d1e80e5bbcf38e Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Fri, 9 Oct 2026 13:01:36 +0200 Subject: [PATCH] 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) --- data/scripts/o | 57 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) 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