diff --git a/.agents/skills/lib.sh b/.agents/skills/lib.sh index 775147e..7217137 100644 --- a/.agents/skills/lib.sh +++ b/.agents/skills/lib.sh @@ -37,15 +37,25 @@ AGENT_SESSIONS_YAML="${AGENT_SESSIONS_YAML:-$WORKSPACE_ROOT/.mam/agent-sessions. # (Issue #71). The herdr shim gets this same definition: _init_herdr_isolation # writes it in with `declare -f`. A long name needs its SHA-1 suffix; with no # shasum, sha1sum, openssl or python3 to make it, this fails (stderr, nonzero) -# rather than return a name herdr never registered. +# rather than return a name herdr never registered. A name that is not ASCII +# is lowercased and replaced by python3 (tr/sed differ from str.lower() there), +# and fails the same way without it. _sanitize_herdr_agent_name() { local n="$1" if [ -z "$n" ]; then printf 'agent\n' return 0 fi - local s - s=$(echo "$n" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9_-]/-/g') + local s="" + if [ -z "$(printf '%s' "$n" | LC_ALL=C tr -d '\000-\177')" ]; then + s=$(printf '%s' "$n" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9_-]/-/g') + elif command -v python3 >/dev/null 2>&1; then + s=$(python3 -c 'import re,sys; sys.stdout.write(re.sub(r"[^a-z0-9_-]", "-", sys.argv[1].lower()))' "$n") || s="" + fi + if [ -z "$s" ]; then + echo "ERROR: cannot make the herdr name of '$n': it is not ASCII and there is no python3 to convert it" >&2 + return 1 + fi if [[ ! "$s" =~ ^[a-z] ]]; then s="x-$s"; fi if [ "${#s}" -gt 32 ]; then local h=""