Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libs/code/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Regenerate this file with `make commands-catalog` after changing command names,
aliases, descriptions, visibility, or hidden-command metadata.


## Public (30)
## Public (31)

| Command | Aliases | Description |
| --- | --- | --- |
Expand All @@ -34,6 +34,7 @@ aliases, descriptions, visibility, or hidden-command metadata.
| `/remember` | | Save useful context to memory or skills |
| `/restart` | | Restart the agent server |
| `/rubric` | `/criteria` | Set explicit acceptance criteria for rubric grading |
| `/scrollbar` | | Show or hide the chat scrollbar |
| `/skill-creator` | | Create or refine agent skills |
| `/theme` | | Change color theme |
| `/threads` | | Browse and resume past threads |
Expand Down
12 changes: 12 additions & 0 deletions libs/code/deepagents_code/_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@
to hide replica tracing details from the splash while leaving tracing active.
"""

SHOW_SCROLLBAR = "DEEPAGENTS_CODE_SHOW_SCROLLBAR"
"""Show the vertical scrollbar in the chat area when enabled.

Off by default; use the `/scrollbar` slash command or `[ui].show_scrollbar` in
config.toml to toggle. Parsed by `classify_env_bool` (an unrecognized or empty
value falls through to the config value rather than forcing the default).

When set, this env var takes precedence over the persisted `[ui].show_scrollbar`
config value on launch, so a `/scrollbar` toggle will not appear to "stick"
across restarts while the env var remains set.
"""

THEME = "DEEPAGENTS_CODE_THEME"
"""Force the CLI to launch with this theme name when set."""

Expand Down
191 changes: 183 additions & 8 deletions libs/code/deepagents_code/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@
format_token_count,
)

# Only is_ascii_mode is needed before first paint (on_mount scrollbar config).
# All other config imports — settings, create_model, detect_provider, etc. — are
# deferred to local imports at their call sites since they are only accessed
# after user interaction begins.
# All config imports — settings, create_model, detect_provider, is_ascii_mode,
# etc. — are deferred to local imports at their call sites since they are only
# accessed after user interaction begins.
from deepagents_code._version import CHANGELOG_URL, DOCS_URL
from deepagents_code.config import is_ascii_mode
from deepagents_code.formatting import format_message_timestamp
from deepagents_code.iterm_cursor_guide import restore_iterm_cursor_guide
from deepagents_code.notifications import (
Expand Down Expand Up @@ -603,6 +601,55 @@ def _load_message_timestamps_visible() -> bool:
return False


def _load_show_scrollbar() -> bool:
"""Load the chat scrollbar visibility preference.

Reads `DEEPAGENTS_CODE_SHOW_SCROLLBAR` env var, falling back to
`[ui].show_scrollbar` from `~/.deepagents/config.toml`, and finally `False`.

Returns:
The resolved preference.
"""
from deepagents_code._env_vars import SHOW_SCROLLBAR, classify_env_bool

raw = os.environ.get(SHOW_SCROLLBAR)
if raw is not None and raw.strip():
env = classify_env_bool(raw)
if env is not None:
return env

import tomllib

from deepagents_code.model_config import DEFAULT_CONFIG_PATH

if not DEFAULT_CONFIG_PATH.exists():
return False
try:
with DEFAULT_CONFIG_PATH.open("rb") as f:
data = tomllib.load(f)
except (tomllib.TOMLDecodeError, PermissionError, OSError) as exc:
logger.warning("Could not read config for scrollbar preference: %s", exc)
return False

ui = data.get("ui", {})
if not isinstance(ui, dict):
logger.warning(
"[ui] should be a table; got %s while loading scrollbar preference",
type(ui).__name__,
)
return False

value = ui.get("show_scrollbar")
if isinstance(value, bool):
return value
if value is not None:
logger.warning(
"[ui].show_scrollbar should be a boolean; got %s",
type(value).__name__,
)
return False


def _replace_malformed_ui(
data: dict[str, object],
) -> tuple[dict[str, object], str | None]:
Expand Down Expand Up @@ -946,6 +993,65 @@ def _save_message_timestamps_visible_result(visible: bool) -> _ConfigWriteResult
return _ConfigWriteResult(True, repair_message)


def _save_show_scrollbar_result(visible: bool) -> _ConfigWriteResult:
"""Persist the chat scrollbar visibility preference.

Writes `[ui].show_scrollbar` atomically (temp file +
`Path.replace`). Mirrors `_save_message_timestamps_visible_result`.

Returns:
Write status and a message suitable for a toast when the user needs to
know about a repair or failure.
"""
import contextlib
import tempfile
import tomllib

try:
import tomli_w

from deepagents_code.model_config import DEFAULT_CONFIG_PATH

DEFAULT_CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
with _CONFIG_WRITE_LOCK:
if DEFAULT_CONFIG_PATH.exists():
with DEFAULT_CONFIG_PATH.open("rb") as f:
data = tomllib.load(f)
else:
data = {}

ui, repair_message = _replace_malformed_ui(data)
ui["show_scrollbar"] = visible

fd, tmp_path = tempfile.mkstemp(
dir=DEFAULT_CONFIG_PATH.parent,
suffix=".tmp",
)
try:
with os.fdopen(fd, "wb") as f:
tomli_w.dump(data, f)
Path(tmp_path).replace(DEFAULT_CONFIG_PATH)
except BaseException:
with contextlib.suppress(OSError):
Path(tmp_path).unlink()
raise
except (
OSError,
tomllib.TOMLDecodeError,
ImportError,
TypeError,
ValueError,
) as exc:
logger.exception("Could not save scrollbar preference")
return _ConfigWriteResult(
False,
f"Scrollbar toggled for this session but could not be saved "
f"({type(exc).__name__}).",
"error",
)
return _ConfigWriteResult(True, repair_message)


def _extract_model_params_flag(raw_arg: str) -> tuple[str, dict[str, Any] | None]:
"""Extract `--model-params` and its JSON value from a `/model` arg string.

Expand Down Expand Up @@ -2143,6 +2249,13 @@ def __init__(
Restored from `[ui].show_message_timestamps` and re-persisted on toggle.
"""

self._show_scrollbar = _load_show_scrollbar()
"""Whether the vertical scrollbar is shown in the chat area.

Restored from `DEEPAGENTS_CODE_SHOW_SCROLLBAR` env var or
`[ui].show_scrollbar` and re-persisted on toggle. Off by default.
"""

# Widget refs (populated in compose/on_mount)
self._status_bar: StatusBar | None = None
"""Status bar widget; populated in `on_mount`."""
Expand Down Expand Up @@ -2622,8 +2735,7 @@ async def on_mount(self) -> None:

chat = self.query_one("#chat", VerticalScroll)
chat.anchor()
if is_ascii_mode():
chat.styles.scrollbar_size_vertical = 0
self._apply_scrollbar_visibility(chat)

self._status_bar = self.query_one("#status-bar", StatusBar)
self._chat_input = self.query_one("#input-area", ChatInput)
Expand Down Expand Up @@ -8749,7 +8861,8 @@ async def _handle_command(self, command: str) -> None:
"/mcp, /model [--model-params JSON] [--default], "
"/notifications, /reload, /restart, /rubric, "
"/skill:<name>, /remember, "
"/skill-creator, /theme, /timestamps, /tokens, /threads, /trace, "
"/skill-creator, /theme, /scrollbar, /timestamps, /tokens, "
"/threads, /trace, "
"/update, /auto-update, /install, /changelog, /docs, "
"/feedback, /help\n\n"
"Interactive Features:\n"
Expand Down Expand Up @@ -8876,6 +8989,15 @@ async def _handle_command(self, command: str) -> None:
await self._handle_auto_update_toggle()
elif cmd == "/install" or cmd.startswith("/install "):
await self._handle_install_command(command)
elif cmd == "/scrollbar":
await self._toggle_scrollbar()
label = "shown" if self._show_scrollbar else "hidden"
self.notify(
f"Chat scrollbar {label}.",
severity="information",
timeout=5,
markup=False,
)
elif cmd == "/timestamps":
await self._toggle_message_timestamp_footers()
label = "shown" if self._message_timestamps_visible else "hidden"
Expand Down Expand Up @@ -10245,6 +10367,59 @@ async def _persist_message_timestamps_visible(self) -> None:
"Failed to persist message timestamp preference",
exc_info=True,
)
self.notify(
"Timestamps toggled for this session but could not be saved.",
severity="error",
timeout=6,
markup=False,
)

def _apply_scrollbar_visibility(self, chat: VerticalScroll | None = None) -> None:
"""Apply the current scrollbar visibility to the chat container.

Hides the scrollbar when the user preference is off or ASCII mode is
active (ASCII terminals can't render the scrollbar glyphs).
"""
from deepagents_code.config import is_ascii_mode

if chat is None:
try:
chat = self.query_one("#chat", VerticalScroll)
except NoMatches:
return

if self._show_scrollbar and not is_ascii_mode():
chat.styles.scrollbar_size_vertical = 1
else:
chat.styles.scrollbar_size_vertical = 0

async def _toggle_scrollbar(self) -> None:
"""Toggle chat scrollbar visibility and persist the preference."""
self._show_scrollbar = not self._show_scrollbar
self._apply_scrollbar_visibility()
try:
status = await asyncio.to_thread(
_save_show_scrollbar_result,
self._show_scrollbar,
)
if status.message is not None:
self.notify(
status.message,
severity=status.severity,
timeout=6,
markup=False,
)
except Exception:
logger.warning(
"Failed to persist scrollbar preference",
exc_info=True,
)
self.notify(
"Scrollbar toggled for this session but could not be saved.",
severity="error",
timeout=6,
markup=False,
)

async def _mount_message(
self,
Expand Down
7 changes: 5 additions & 2 deletions libs/code/deepagents_code/app.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ Screen {
display: block;
}

/* Chat area - main scrollable messages area */
/* Chat area - main scrollable messages area.
No horizontal padding so message blocks span the same full width as the
input box below (whose border is flush to both edges). The scrollbar is
toggled at runtime via the /scrollbar command (off by default). */
#chat {
height: 1fr;
padding: 1 2 0 2;
padding: 1 0 0 0;
background: $background;
}

Expand Down
6 changes: 6 additions & 0 deletions libs/code/deepagents_code/command_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ def to_entry(self) -> CommandEntry:
bypass_tier=BypassTier.IMMEDIATE_UI,
hidden_keywords="dark light color appearance",
),
SlashCommand(
name="/scrollbar",
description="Show or hide the chat scrollbar",
bypass_tier=BypassTier.SIDE_EFFECT_FREE,
hidden_keywords="scroll scroller bar vertical",
),
SlashCommand(
name="/timestamps",
description="Show or hide message timestamps",
Expand Down
9 changes: 9 additions & 0 deletions libs/code/deepagents_code/config_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,15 @@ def _credential_options() -> tuple[ConfigOption, ...]:
kind=OptionKind.BOOL,
env_var=_env_vars.KITTY_KEYBOARD,
),
ConfigOption(
key="display.show_scrollbar",
group="Display",
summary="Show the vertical scrollbar in the chat area (off by default).",
kind=OptionKind.BOOL,
default=False,
env_var=_env_vars.SHOW_SCROLLBAR,
toml_keys=("ui", "show_scrollbar"),
),
ConfigOption(
key="display.hide_cwd",
group="Display",
Expand Down
2 changes: 1 addition & 1 deletion libs/code/deepagents_code/widgets/chat_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ class ChatInput(Vertical):
min-height: 3;
max-height: 25;
padding: 0;
background: $surface;
background: $background;
border: solid $primary;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/code/deepagents_code/widgets/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class StatusBar(Horizontal):
StatusBar {
height: 1;
dock: bottom;
background: $surface;
background: $background;
}

StatusBar .status-mode {
Expand Down
Loading
Loading