fix(lib.sh): the herdr name of a non-ASCII or option-like name equals Python's (Issue #71)
tr/sed lowercase differently from str.lower() outside ASCII, so a name
like "İstanbul-creator-claude" was started as x--stanbul-... while the
row's attach_command named i-stanbul-.... A non-ASCII name is now
lowercased and replaced by python3 (fail closed without it), and the
name is read with printf, not echo ("-n" no longer vanishes).
Refs #71
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e4c7c8fe9b
commit
5cd72d2df3
1 file changed
+13
-3
+13
-3
@@ -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=""
|
||||
|
||||
Reference in new issue
Block a user