Skip to content

Commit 68f0fa1

Browse files
committed
refac
1 parent 811d4ab commit 68f0fa1

3 files changed

Lines changed: 39 additions & 7 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ cors_allowed_origins = "*"
133133
log_dir = "/var/log/open-terminal"
134134
binary_mime_prefixes = "image,audio"
135135
execute_timeout = 5 # seconds to wait for command output (unset by default)
136+
file_browser_root = "home"
136137
```
137138

138139
> [!TIP]
@@ -144,6 +145,21 @@ You can also point to a specific config file:
144145
open-terminal run --config /path/to/my-config.toml
145146
```
146147

148+
### File Browser Root
149+
150+
Open Terminal reports file-browser root metadata from `GET /files/cwd` so clients can hide parent navigation above a friendly starting point.
151+
152+
Set `OPEN_TERMINAL_FILE_BROWSER_ROOT` to:
153+
154+
| Value | Behavior |
155+
|---|---|
156+
| `home` | Default. Report the current user's home directory as `Home` |
157+
| `/workspace` | Report an explicit path as the visual root |
158+
| `{{home}}/project` | Report a path under the current user's home |
159+
| `filesystem` | Opt out and report no visual root metadata |
160+
161+
This is a UI hint for clients. It does not restrict terminal commands or file APIs.
162+
147163
## Using with Open WebUI
148164

149165
Open Terminal integrates with [Open WebUI](https://github.com/open-webui/open-webui), giving your AI assistants the ability to run commands, manage files, and interact with a terminal right from the AI interface. Make sure to add it under **Open Terminal** in the integrations settings, not as a tool server. Adding it as an Open Terminal connection gives you a built-in file navigation sidebar where you can browse directories, upload, download, and edit files. There are two ways to connect:

open_terminal/env.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _resolve_file_env(var: str, default: str = "") -> str:
164164
FILE_BROWSER_ROOT = os.environ.get(
165165
"OPEN_TERMINAL_FILE_BROWSER_ROOT",
166166
config.get("file_browser_root", "home"),
167-
).strip().lower()
167+
).strip()
168168

169169
# How long (in seconds) to keep per-session cwd entries in memory.
170170
# Sliding window — refreshed on every access.
@@ -174,4 +174,3 @@ def _resolve_file_env(var: str, default: str = "") -> str:
174174
config.get("session_cwd_ttl", 604_800), # 7 days
175175
)
176176
)
177-

open_terminal/main.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ def get_filesystem(request: Request) -> UserFS:
146146
return UserFS(username=username, home=home)
147147

148148

149+
def get_file_browser_root(fs: UserFS) -> dict[str, str] | None:
150+
configured = FILE_BROWSER_ROOT.strip()
151+
mode = configured.lower()
152+
if mode in ("", "home"):
153+
return {"path": fs.home, "label": "Home"}
154+
if mode == "filesystem":
155+
return None
156+
157+
path = configured.replace("{{home}}", fs.home)
158+
if path == "~":
159+
path = fs.home
160+
elif path.startswith("~/"):
161+
path = os.path.join(fs.home, path[2:])
162+
163+
root_path = fs.resolve_path(path)
164+
label = "Home" if root_path == fs.home else os.path.basename(root_path) or root_path
165+
return {"path": root_path, "label": label}
166+
167+
149168
app = FastAPI(
150169
title="Open Terminal",
151170
description="A remote terminal API.",
@@ -445,11 +464,9 @@ async def get_cwd(
445464
"cwd": _get_session_cwd(session_id, fs),
446465
"home": fs.home,
447466
}
448-
if FILE_BROWSER_ROOT != "filesystem":
449-
response["root"] = {
450-
"path": fs.home,
451-
"label": "Home",
452-
}
467+
root = get_file_browser_root(fs)
468+
if root:
469+
response["root"] = root
453470
return response
454471

455472

0 commit comments

Comments
 (0)