fix(lib): enhance target agent resolution and import fallback in herdr shim
This commit is contained in:
+52
-12
@@ -246,22 +246,58 @@ case "$cmd" in
|
|||||||
agent)
|
agent)
|
||||||
sub="${1:-}"
|
sub="${1:-}"
|
||||||
shift || true
|
shift || true
|
||||||
|
_resolve_herdr_target() {
|
||||||
|
local raw="$1"
|
||||||
|
local sat
|
||||||
|
sat=$(_sanitize_herdr_agent_name "$raw")
|
||||||
|
if _real_herdr agent get "$sat" >/dev/null 2>&1; then
|
||||||
|
echo "$sat"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if _real_herdr agent get "$raw" >/dev/null 2>&1; then
|
||||||
|
echo "$raw"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
local from_list
|
||||||
|
from_list=$(_real_herdr agent list 2>/dev/null | TARGET_NAME="$raw" python3 -c '
|
||||||
|
import sys, json, os
|
||||||
|
tn = os.environ.get("TARGET_NAME", "")
|
||||||
|
try:
|
||||||
|
d = json.loads(sys.stdin.read())
|
||||||
|
for a in d.get("result", {}).get("agents", []):
|
||||||
|
name = a.get("name", "")
|
||||||
|
agent = a.get("agent", "")
|
||||||
|
pane_id = a.get("pane_id", "")
|
||||||
|
if name == tn or (not name and agent and agent in tn):
|
||||||
|
print(pane_id or agent)
|
||||||
|
sys.exit(0)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
sys.exit(1)
|
||||||
|
' 2>/dev/null || echo "")
|
||||||
|
if [ -n "$from_list" ]; then
|
||||||
|
echo "$from_list"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "$raw"
|
||||||
|
}
|
||||||
|
|
||||||
if [ "$sub" = "prompt" ] && [ $# -ge 2 ]; then
|
if [ "$sub" = "prompt" ] && [ $# -ge 2 ]; then
|
||||||
t="$1"
|
t="$1"
|
||||||
txt="$2"
|
txt="$2"
|
||||||
shift 2
|
shift 2
|
||||||
at=$(_sanitize_herdr_agent_name "$t")
|
tgt=$(_resolve_herdr_target "$t")
|
||||||
_real_herdr agent prompt "$at" "$txt" "$@" 2>/dev/null || _real_herdr agent prompt "$t" "$txt" "$@"
|
_real_herdr agent prompt "$tgt" "$txt" "$@"
|
||||||
elif [ "$sub" = "get" ] && [ $# -ge 1 ]; then
|
elif [ "$sub" = "get" ] && [ $# -ge 1 ]; then
|
||||||
t="$1"
|
t="$1"
|
||||||
shift
|
shift
|
||||||
at=$(_sanitize_herdr_agent_name "$t")
|
tgt=$(_resolve_herdr_target "$t")
|
||||||
_real_herdr agent get "$at" "$@" 2>/dev/null || _real_herdr agent get "$t" "$@"
|
_real_herdr agent get "$tgt" "$@"
|
||||||
elif [ "$sub" = "read" ] && [ $# -ge 1 ]; then
|
elif [ "$sub" = "read" ] && [ $# -ge 1 ]; then
|
||||||
t="$1"
|
t="$1"
|
||||||
shift
|
shift
|
||||||
at=$(_sanitize_herdr_agent_name "$t")
|
tgt=$(_resolve_herdr_target "$t")
|
||||||
_real_herdr agent read "$at" "$@" 2>/dev/null || _real_herdr agent read "$t" "$@"
|
_real_herdr agent read "$tgt" "$@"
|
||||||
else
|
else
|
||||||
_real_herdr agent "$sub" "$@"
|
_real_herdr agent "$sub" "$@"
|
||||||
fi
|
fi
|
||||||
@@ -284,22 +320,26 @@ case "$cmd" in
|
|||||||
if _real_herdr agent get "$(_sanitize_herdr_agent_name "$sess")" >/dev/null 2>&1 || _real_herdr agent get "$sess" >/dev/null 2>&1; then
|
if _real_herdr agent get "$(_sanitize_herdr_agent_name "$sess")" >/dev/null 2>&1 || _real_herdr agent get "$sess" >/dev/null 2>&1; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if _real_herdr agent list 2>/dev/null | TARGET_NAME="$sess" python3 -c "
|
if _real_herdr agent list 2>/dev/null | TARGET_NAME="$sess" python3 -c '
|
||||||
import sys, json, os
|
import sys, json, os
|
||||||
|
try:
|
||||||
|
sys.path.insert(0, os.path.abspath(".agents/skills"))
|
||||||
from lib_py.agents.sanitize import sanitize_herdr_agent_name
|
from lib_py.agents.sanitize import sanitize_herdr_agent_name
|
||||||
tn = os.environ.get('TARGET_NAME', '')
|
except Exception:
|
||||||
|
sanitize_herdr_agent_name = lambda s: s.lower()[:32] if s else "agent"
|
||||||
|
tn = os.environ.get("TARGET_NAME", "")
|
||||||
stn = sanitize_herdr_agent_name(tn)
|
stn = sanitize_herdr_agent_name(tn)
|
||||||
try:
|
try:
|
||||||
d = json.loads(sys.stdin.read())
|
d = json.loads(sys.stdin.read())
|
||||||
agents = d.get('result', {}).get('agents', [])
|
agents = d.get("result", {}).get("agents", [])
|
||||||
for a in agents:
|
for a in agents:
|
||||||
an = a.get('name', '')
|
an = a.get("name", "")
|
||||||
if an == tn or an == stn:
|
if (an and (an == tn or an == stn)) or (not an and a.get("agent") and a.get("agent") in tn):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
"; then
|
'; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user