fix(lib): resolve workspace CWD mismatch in herdr new-session shim and enforce target workspace slug priority

This commit is contained in:
2026-08-13 08:37:51 +09:00
parent da92624273
commit 20e2e9bd2d
+25 -22
View File
@@ -265,13 +265,20 @@ print('\t'.join(env_flags) + '\n' + ' '.join(binary_tokens))
fi
# Check if there is an existing workspace inside this session (to reuse and split view)
existing_ws=$(_real_herdr workspace list 2>/dev/null | python3 -c "
import sys, json
existing_ws=$(_real_herdr workspace list 2>/dev/null | TARGET_CWD="${ws:-.}" python3 -c "
import sys, json, os
target_ws = os.environ.get('TARGET_CWD', '')
try:
target_abs = os.path.realpath(target_ws) if target_ws else ''
d = json.loads(sys.stdin.read())
wss = d.get('result', {}).get('workspaces', [])
if wss:
print(wss[0].get('workspace_id', ''))
matched_id = ''
for w in wss:
w_cwd = os.path.realpath(w.get('cwd', '')) if w.get('cwd') else ''
if target_abs and w_cwd == target_abs:
matched_id = w.get('workspace_id', '')
break
print(matched_id)
except Exception:
pass
")
@@ -745,24 +752,20 @@ for s in d.get('herdr_sessions', []):
if s.get('name') == name:
print(s.get('herdr_session') or s.get('herdr_server') or s.get('herdr_workspace') or 'default')
sys.exit(0)
fallback = os.environ.get('HERDR_SESSION_NAME', '')
if not fallback or fallback == 'default':
legacy = os.environ.get('HERDR_SERVER_NAME', '')
if legacy and legacy != 'default':
fallback = legacy
if not fallback or fallback == 'default':
if ws:
# derive_workspace_slug Equivalent in python
abs_ws = os.path.abspath(ws)
parent = os.path.basename(os.path.dirname(abs_ws)) or 'workspace'
work = os.path.basename(abs_ws) or 'root'
if parent in ('/', '.'): parent = 'workspace'
if work in ('/', '.'): work = 'root'
slug = f'{parent}-{work}'.lower().replace('_', '-')
import re
slug = re.sub(r'[^a-zA-Z0-9-]', '', slug).lstrip('-')
fallback = f'mam-{slug}' if slug else 'mam-ws'
else:
fallback = ''
if ws:
abs_ws = os.path.abspath(ws)
parent = os.path.basename(os.path.dirname(abs_ws)) or 'workspace'
work = os.path.basename(abs_ws) or 'root'
if parent in ('/', '.'): parent = 'workspace'
if work in ('/', '.'): work = 'root'
slug = f'{parent}-{work}'.lower().replace('_', '-')
import re
slug = re.sub(r'[^a-zA-Z0-9-]', '', slug).lstrip('-')
fallback = f'mam-{slug}' if slug else 'mam-ws'
else:
fallback = os.environ.get('HERDR_SESSION_NAME', '') or os.environ.get('HERDR_SERVER_NAME', '')
if not fallback or fallback == 'default':
fallback = 'default'
print('WARN: resolve_herdr_session called without workspace parameter for unregistered session; falling back to default', file=sys.stderr)
print(fallback or 'default')