feat(cli,registry): introduce --herdr-workspace option and decouple socket fallback chains
This commit is contained in:
+59
-6
@@ -1007,10 +1007,10 @@ print(resolved)
|
||||
"
|
||||
}
|
||||
|
||||
# Despite the name (kept for caller compatibility — resume/stop/update_yaml_resumed
|
||||
# all do `HERDR_SESSION_NAME="$(resolve_herdr_workspace "$SESSION_NAME")"`), this
|
||||
# returns the isolated herdr *session* name to use for this MAM session row, not
|
||||
# a workspace id. Real isolation is `--session <name>` (see `_MAM_SESSION` in the
|
||||
# resolve_herdr_session <session_name> [workspace]
|
||||
#
|
||||
# returns the isolated herdr *session* name (socket/daemon) to use for this MAM session row,
|
||||
# not a workspace label. 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.
|
||||
|
||||
@@ -1024,7 +1024,8 @@ ws = os.environ.get('TARGET_WS', '').strip()
|
||||
d = json.loads(os.environ.get('MAM_STATE_JSON', '{}'))
|
||||
for s in d.get('herdr_sessions', []):
|
||||
if s.get('name') == name:
|
||||
val = s.get('herdr_session') or s.get('herdr_server') or s.get('herdr_workspace')
|
||||
# herdr_workspace 는 워크스페이스 *라벨* 이지 소켓 이름이 아니다.
|
||||
val = s.get('herdr_session') or s.get('herdr_server')
|
||||
if val and val != 'default':
|
||||
print(val)
|
||||
sys.exit(0)
|
||||
@@ -1048,8 +1049,60 @@ print(fallback or 'default')
|
||||
"
|
||||
}
|
||||
|
||||
# resolve_herdr_workspace <session_name> [workspace]
|
||||
#
|
||||
# 이 MAM 세션 행의 워크스페이스 *라벨* 을 돌려준다. herdr 소켓/데몬 이름이
|
||||
# 아니다 — 그쪽은 resolve_herdr_session() 이다. 라벨이 소켓 인자로 흘러가면
|
||||
# reconcile.sh 가 엉뚱한 소켓에 kill-session 을 날린다.
|
||||
#
|
||||
# 우선순위 (C-1: 등록된 행의 사실이 호출자 인자를 이긴다):
|
||||
# ① row['herdr_workspace'] — 명시 기록
|
||||
# ② row['pane']['cwd'] 의 슬러그 — 등록된 세션의 실제 작업 디렉터리
|
||||
# ③ 인자 workspace 의 슬러그 — 미등록 세션 전용 폴백
|
||||
# ④ 빈 문자열
|
||||
# 주의 1: herdr_session / herdr_server 로는 절대 폴백하지 않는다 (D4).
|
||||
# 주의 2: create_session.sh 는 이 함수를 쓰지 않는다 — 재생성 시 낡은 행의
|
||||
# pane.cwd 를 물려받기 때문 (D5).
|
||||
resolve_herdr_workspace() {
|
||||
resolve_herdr_session "$@"
|
||||
local session_name="$1"
|
||||
local workspace="${2:-}"
|
||||
MAM_STATE_JSON="$(load_state_json)" SESSION_NAME="$session_name" TARGET_WS="$workspace" python3 -c "
|
||||
import sys, os, json, re
|
||||
name = os.environ['SESSION_NAME']
|
||||
ws = os.environ.get('TARGET_WS', '').strip()
|
||||
d = json.loads(os.environ.get('MAM_STATE_JSON', '{}'))
|
||||
|
||||
def slug(path):
|
||||
if not path:
|
||||
return ''
|
||||
a = os.path.abspath(path)
|
||||
parent = os.path.basename(os.path.dirname(a)) or 'workspace'
|
||||
work = os.path.basename(a) or 'root'
|
||||
if parent in ('/', '.'): parent = 'workspace'
|
||||
if work in ('/', '.'): work = 'root'
|
||||
s = f'{parent}-{work}'.lower().replace('_', '-')
|
||||
return re.sub(r'[^a-zA-Z0-9-]', '', s).lstrip('-')
|
||||
|
||||
row = next((s for s in d.get('herdr_sessions', []) if s.get('name') == name), None)
|
||||
|
||||
# ① 명시 기록
|
||||
if row and row.get('herdr_workspace'):
|
||||
print(row['herdr_workspace']); sys.exit(0)
|
||||
|
||||
# ② 등록된 행의 실제 cwd — 호출자 인자보다 우선 (C-1)
|
||||
if row:
|
||||
derived = slug((row.get('pane') or {}).get('cwd', ''))
|
||||
if derived:
|
||||
print(derived); sys.exit(0)
|
||||
|
||||
# ③ 미등록(또는 cwd 부재) 세션 폴백
|
||||
if ws:
|
||||
derived = slug(ws)
|
||||
if derived:
|
||||
print(derived); sys.exit(0)
|
||||
|
||||
print('')
|
||||
"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user