feat(scope): implement workspace-scoped session isolation (A-1) and native Herdr session naming (A-5)

This commit is contained in:
2026-08-05 09:31:57 +09:00
parent 793a221587
commit 51dcf56c80
7 changed files with 89 additions and 57 deletions
+12 -14
View File
@@ -48,7 +48,7 @@ LOCAL_BIN="${LOCAL_BIN:-$HOME/.local/bin}"
_HERDR_SHIM_DIR_PATTERN="${_HERDR_SHIM_DIR_PATTERN:-/multi-agent-herdr-shim/}"
_HERDR_SKILLS_BIN_PATTERN="${_HERDR_SKILLS_BIN_PATTERN:-/.agents/skills/.bin}"
HERDR_SERVER_NAME="${HERDR_SERVER_NAME:-default}"
HERDR_SESSION_NAME="${HERDR_SESSION_NAME:-default}"
_resolve_real_herdr_path() {
_REAL_HERDR_PATH="herdr"
@@ -90,23 +90,17 @@ _resolve_real_herdr() {
}
REAL_HERDR=$(_resolve_real_herdr)
# Support parsing -L <server> before the subcommand
# Support parsing -L <session> before the subcommand
while [ "${1:-}" = "-L" ]; do
if [ $# -lt 2 ]; then
echo "herdr shim: -L requires an argument" >&2
exit 1
fi
export HERDR_SERVER_NAME="$2"
export HERDR_SESSION_NAME="$2"
shift 2
done
# Herdr's real isolation boundary is `--session <name>` (a whole separate
# server + socket, like tmux `-L`) — NOT `workspace create --label`, which is
# just a named subdivision inside ONE server and provides no actual isolation
# (agent/pane commands are server-global regardless of workspace). When
# HERDR_SERVER_NAME names a non-default session, make sure its headless server
# is actually running, then scope every real herdr call to it via `--session`.
_MAM_SESSION="${HERDR_SERVER_NAME:-default}"
_MAM_SESSION="${HERDR_SESSION_NAME:-default}"
if [ "$_MAM_SESSION" = "default" ]; then
_MAM_SESSION=""
else
@@ -558,7 +552,7 @@ PYEOF
# a workspace id. Real isolation is `--session <name>` (see `_MAM_SESSION` in the
# generated wrapper) — a workspace label match provides no actual isolation
# since agent/pane commands are server-global regardless of workspace.
resolve_herdr_workspace() {
resolve_herdr_session() {
local session_name="$1"
MAM_STATE_JSON="$(load_state_json)" SESSION_NAME="$session_name" python3 -c "
import sys, os, json
@@ -566,16 +560,20 @@ name = os.environ['SESSION_NAME']
d = json.loads(os.environ.get('MAM_STATE_JSON', '{}'))
for s in d.get('herdr_sessions', []):
if s.get('name') == name:
print(s.get('herdr_workspace') or s.get('herdr_server') or 'default')
print(s.get('herdr_session') or 'default')
sys.exit(0)
fallback = os.environ.get('HERDR_SERVER_NAME', '')
fallback = os.environ.get('HERDR_SESSION_NAME', '')
if not fallback or fallback == 'default':
pwd = os.path.abspath(os.getcwd())
fallback = os.path.basename(pwd)
fallback = 'mam-' + os.path.basename(pwd).lower().replace('_', '-')
print(fallback or 'default')
"
}
resolve_herdr_workspace() {
resolve_herdr_session "$@"
}
# ---------------------------------------------------------------------------
# derive_session_name <workspace> <agent>
#