3c7069bdcb
authz_mixin, browser_control_broker, delivery, delivery_ledger, display_config, drain_control, hosted_room_links/peer/policy_checkpoint, hosted_rooms, platform_registry, relay/__init__, relay/ws_transport, run.py and slash_commands.py (comments), session_context, session_state, streaming_tts_consumer, turn_lease and small modules. - HostedRoomPolicyCheckpoint._apply_event -> per-kind handler table - WebSocketRelayTransport._handle_frame -> frame-handler table - GatewayAuthorizationMixin: unified adapter setting/flag/extra readers - dead symbols removed (verified zero references): RoomLinkProbe/select_room_link, relay_bot_username, is_restart_loop_tripped, debug_rows, DeadTargetRegistry.all_dead, BrowserControlBroker.detach_owner/_prune_tickets, StreamingTTSConsumer.started/_enqueue_done/ _iter_stream_chunks/_next_stream_chunk, RecoverableHandleCache.status_for, _auth_env, _copy_default_catalog, _parse_timestamp_prefix, _present_* helpers, _send_result_error_kind, _truthy_env, SessionFieldView/TurnLeaseTokenView dunder shims, and their orphaned tests. - lost WHY/invariant text from the earlier compaction restored compactly (541 hunks audited)
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""Resolve gateway ``terminal.cwd`` placeholder values to ``TERMINAL_CWD``.
|
|
|
|
When ``terminal.cwd`` is unset or a placeholder (``.``, ``auto``, ``cwd``),
|
|
the gateway must not blindly map host ``Path.home()`` into container backends.
|
|
Docker with workspace mounting still needs an explicit host path signal
|
|
(``MESSAGING_CWD`` or an absolute config path) for ``terminal_tool`` to map
|
|
``/host/project`` → ``/workspace``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
CWD_PLACEHOLDERS = frozenset({".", "auto", "cwd"})
|
|
|
|
|
|
def resolve_placeholder_terminal_cwd(
|
|
*,
|
|
configured_cwd: str,
|
|
terminal_backend: str,
|
|
messaging_cwd: str | None,
|
|
docker_mount_cwd_to_workspace: bool,
|
|
home_fallback: str,
|
|
) -> str | None:
|
|
"""Return the ``TERMINAL_CWD`` value to set, or ``None`` to leave it unset.
|
|
|
|
Cases:
|
|
- **local** + placeholder → ``MESSAGING_CWD`` or ``home_fallback``
|
|
- **docker** + placeholder + mount on + host ``MESSAGING_CWD`` → host path
|
|
(for ``terminal_tool`` ``/workspace`` mapping)
|
|
- **docker** + placeholder + mount off → ``None`` (sandbox default)
|
|
- other non-local backends + placeholder → ``None``
|
|
"""
|
|
if configured_cwd and configured_cwd not in CWD_PLACEHOLDERS:
|
|
return configured_cwd
|
|
|
|
backend = (terminal_backend or "local").strip().lower()
|
|
messaging = (messaging_cwd or "").strip()
|
|
if backend == "local":
|
|
return messaging or home_fallback
|
|
if backend == "docker" and docker_mount_cwd_to_workspace and messaging and messaging not in CWD_PLACEHOLDERS:
|
|
return messaging
|
|
return None
|