Commit Graph
47 Commits
Author SHA1 Message Date
Timothy Jaeryang Baek aa60f5bc2a refac 2026-11-07 19:47:21 +09:00
Timothy Jaeryang Baek 15c1116ee6 refac 2026-11-06 22:11:00 +09:00
Timothy Jaeryang Baek cc8becd226 refac 2026-11-06 21:59:24 +09:00
Timothy Jaeryang Baek 0f96ad5db4 refac 2026-11-04 14:57:22 +09:00
Timothy Jaeryang Baek 13afaba925 refac 2026-11-01 23:44:20 +09:00
Timothy Jaeryang Baek f3836da92c refac 2026-11-01 23:24:10 +09:00
Timothy Jaeryang Baek bda6209717 refac 2026-11-01 23:10:42 +09:00
Timothy Jaeryang Baek a8def225a9 refac 2026-11-01 22:30:47 +09:00
Timothy Jaeryang Baek 238784880a refac 2026-11-01 22:15:46 +09:00
Timothy Jaeryang Baek 7d81297299 refac 2026-11-01 22:12:36 +09:00
Timothy Jaeryang Baek a8ea18e391 refac 2026-10-31 05:58:40 +09:00
Timothy Jaeryang Baek 3994f0939b refac 2026-10-25 12:39:40 +09:00
Timothy Jaeryang Baek f369c2e51b refac 2026-10-24 04:59:06 +09:00
Timothy Jaeryang Baekandmazzz1y dd69911d84 refac
Co-Authored-By: mazzz1y <17034108+mazzz1y@users.noreply.github.com>
2026-10-24 04:10:31 +09:00
Timothy Jaeryang Baek 6852d4d663 refac 2026-10-19 04:00:34 +09:00
Timothy Jaeryang Baek f3d321fa4d refac 2026-10-19 03:49:20 +09:00
Timothy Jaeryang Baek 757b451cf3 refac 2026-10-19 03:42:59 +09:00
Timothy Jaeryang Baek d09d027e06 refac 2026-10-19 03:40:42 +09:00
Timothy Jaeryang Baek 01c1c4e283 refac 2026-10-19 03:40:01 +09:00
Timothy Jaeryang Baek a0ef1c0af8 refac 2026-10-19 03:38:17 +09:00
Timothy Jaeryang Baek f92cc22c04 refac 2026-10-19 03:33:37 +09:00
Timothy Jaeryang Baek 4240b4e934 refac 2026-10-19 03:32:20 +09:00
Alan Chow 613c0431d0 Fix _is_writable_sync Windows compatibility (NotImplementedError) (#179)
- Catch NotImplementedError as the primary fallback since os.access(..., effective_ids=True) is not implemented on Windows
- Also catch AttributeError, OSError, and TypeError as supplementary guards
- Prevents crashes when checking file writability on Windows platforms, primarily fixing directory listing operations (/files/list, stat, listdir)

Fixes #174
2026-10-10 19:18:15 +04:00
Timothy Jaeryang Baek e436b6a2b6 refac 2026-09-13 22:36:09 -04:00
Timothy Jaeryang Baek 011022abb1 refac 2026-09-08 20:32:02 -04:00
Timothy Jaeryang Baek f0edc9ecc5 refac 2026-09-06 15:19:53 -04:00
Timothy Jaeryang Baek 690c5681c9 refac 2026-08-08 19:35:47 -06:00
Timothy Jaeryang Baek 4db47e8cee feat: resolve relative paths against session cwd in all file endpoints
All LLM-exposed file endpoints (list_files, read_file, write_file,
display_file, replace_file_content, grep_search, glob_search) now
read the X-Session-Id header and resolve relative paths against the
session's working directory instead of always using fs.home.

- Added optional cwd parameter to UserFS.resolve_path()
- Relative paths join against cwd if provided, else fs.home
- Absolute paths are unaffected
- execute endpoint also resolves relative cwd param against session cwd
2026-03-29 21:22:28 -05:00
Timothy Jaeryang Baek 952c3f1314 fix: set group-write permission on files after chown in multi-user mode
_chown() transferred file ownership to the provisioned user but didn't
set group-write permission, leaving files at 644. The server process
(a group member) could create new files but couldn't overwrite them on
subsequent saves, returning PermissionError. Now sets chmod g+w after
chown, matching the 2770 treatment already applied to directories.

Fixes #93
2026-03-24 16:53:28 -05:00
Timothy Jaeryang Baek a5e44c44a7 refactor: extract document parsers into utils/documents.py
Moved all document text extraction logic from read_file() into a
dedicated utils/documents.py module with an EXTRACTORS registry.
The read_file endpoint now iterates the registry in a 15-line loop
instead of inlining ~330 lines of per-format parsing.

Adding a new format requires only a single extract_* function and
a one-line registry entry. No behaviour changes.
2026-03-20 17:23:59 -05:00
Timothy Jaeryang Baek 40e1225d53 fix: /ports returns 500 in multi-user mode on restricted runtimes (#80)
list_ports triggered full user provisioning (useradd) just to filter
ports by UID. On runtimes that reject useradd (e.g. Azure Container
Apps), this crashed with an unhandled CalledProcessError.

Now catches provisioning failures and returns an empty port list —
an unprovisioned user has no listening ports to show.
2026-03-19 17:51:24 -05:00
Timothy Jaeryang Baek 5a79b898b5 fix: multi-user mode works when running as root (#60)
ensure_os_user() no longer unconditionally requires sudo; when the
process is already root (e.g. user: '0:0' in Docker Compose), user
provisioning commands run directly. check_environment() now only
requires sudo when not running as root.
2026-03-15 18:14:55 -05:00
Timothy Jaeryang Baek 4ab451d27b fix: write_file permission denied in multi-user subdirectories (#70)
Directories created by run_command (as the provisioned user via sudo -u)
get default 755 permissions, leaving the server process without group-write.
Both makedirs (creating subdirs) and aiofiles.open (creating files) fail
with EPERM.

UserFS._ensure_parents now:
- Creates directories as the provisioned user (sudo -u mkdir -p) to bypass
  755 restrictions on existing parent directories
- Sets 2770 (setgid + group rwx) on all intermediate directories up to the
  user's home, matching the home directory's permissions
- Falls through to plain makedirs in single-user mode (no behavior change)

Closes #70
2026-03-15 16:40:46 -05:00
Timothy Jaeryang Baek 674cf047fc feat: configurable log flush strategy (#65)
Add OPEN_TERMINAL_LOG_FLUSH_INTERVAL and OPEN_TERMINAL_LOG_FLUSH_BUFFER
env vars to control how frequently process output is flushed to disk.
Default 0 preserves existing per-chunk flush behaviour.

Setting FLUSH_INTERVAL=1 reduces fsyncs from ~250/sec to ~1/sec for
high-output commands, preventing I/O storms that can make ARM/eMMC
systems unresponsive.

- Centralize flush control in BoundedLogWriter
- Remove per-chunk flush() from PtyRunner, PipeRunner, WinPtyRunner
- Add explicit final flush before writing process end marker
- Bump version to 0.11.18
2026-03-15 16:24:23 -05:00
Timothy Jaeryang Baek abbface95a fix: remove misleading user from system info in multi-user mode, catch /home/usr hallucination
- get_system_info() no longer includes 'as user user' when MULTI_USER is
  active, removing the hint that caused smaller LLMs to hardcode /home/user
- resolve_path() now rewrites /home/usr → actual user home, matching the
  existing /home/user rewrite

Closes #57
2026-03-13 17:21:05 -05:00
Timothy Jaeryang Baek 68b9380c94 fix: recursive chown on user recreation (UID mismatch) (#62) 2026-03-13 14:57:33 -05:00
Timothy Jaeryang Baekandwjss f4277c3210 fix: bounded process log rotation and timestamp-sortable IDs (#52, #54)
Co-Authored-By: wjss <a123edcrfv@live.cn>
2026-03-11 16:37:09 -05:00
Timothy Jaeryang Baek fd5c5deef9 fix: bounded process log rotation and timestamp-sortable IDs (#52, #54)
- Add log rotation: when a process log exceeds MAX_PROCESS_LOG_SIZE (default
  50 MB), the oldest half is discarded and writing continues so the most
  recent output is always available. Prevents unbounded memory growth that
  caused ~26 GB OOM kills.

- Add tail-optimized log reads: _read_log with tail parameter now reads from
  the end of the file instead of loading the entire file into memory.

- Add OPEN_TERMINAL_MAX_LOG_SIZE (default 50 MB) and
  OPEN_TERMINAL_LOG_RETENTION (default 7 days) configuration.

- Use timestamp-prefixed process IDs (YYYYMMDD-HHMMSS-<random>) so log files
  sort chronologically in the filesystem.

- Extract log management into utils/log.py to reduce main.py size.
2026-03-11 16:22:46 -05:00
Timothy Jaeryang Baek 34054e5052 fix: multi-user search isolation for glob_search, grep_search, listdir, walk (#46)
Added is_path_allowed() to UserFS and wired it into all directory
traversal code paths. In multi-user mode, entries belonging to other
users' home directories are now filtered out during os.walk/os.listdir,
preventing file listing leaks when searching parent directories like
/home. Single-user mode is unaffected (early return on username=None).
2026-03-11 15:16:05 -05:00
Timothy Jaeryang Baek eaf7cb7812 fix: resolve relative paths against user home in multi-user mode (#47)
- Add resolve_path() to UserFS that resolves relative paths against
  self.home instead of os.getcwd()
- Replace all os.path.abspath() calls in route handlers with
  fs.resolve_path()
- Auto-swap /home/user → provisioned user home for hardcoded paths
- Add fs dependency to grep_search and glob_search endpoints
2026-03-11 15:09:32 -05:00
Timothy Jaeryang Baek 998abd4e3e fix: chown home dir after useradd to handle stale ownership
When a home directory pre-exists from a previous container run with
different UID assignments, useradd -m doesn't fix ownership. Adding
an explicit chown ensures the dir always belongs to the correct user.
2026-03-09 18:30:15 -05:00
Timothy Jaeryang Baek 3e224e37e9 refactor: move runner, notebooks, user_isolation into utils/
Also adds per-user port visibility filtering — /ports endpoint now
filters by socket UID in multi-user mode so each user only sees
their own listening ports.
2026-03-09 18:26:07 -05:00
Timothy Jaeryang Baek 7d1584d4bf refactor: native Python I/O for all UserFS operations
Replace all subprocess-based writes (sudo tee, mkdir -p, rm -rf, mv)
with native Python I/O. The only subprocess left is 'sudo chown' for
ownership fixup after writes.

- chmod 2770 (setgid + group rwx) on home dirs so native writes work
- write/write_bytes: aiofiles.open + chown
- mkdir: os.makedirs + chown
- remove: shutil.rmtree / os.remove (no chown needed)
- move: shutil.move + chown
2026-03-09 18:21:14 -05:00
Timothy Jaeryang Baek c948b266c9 fix: cross-user path validation and terminal spawn directory
- UserFS._check_path blocks access to other users' /home/<user>/ paths
- PermissionError → 403 Forbidden (global exception handler)
- Terminal spawn uses 'sudo -i -u' with cwd=fs.home so the shell
  starts in the user's own home directory
- System paths (/etc, /usr, etc.) remain accessible to all users
2026-03-09 18:17:49 -05:00
Timothy Jaeryang Baek 0aeda7392c refactor: native Python I/O for multi-user reads
Replace subprocess-based reads (cat, find, stat, test) with native
Python file I/O. Uses chmod 750 + group membership so the server
process can read user directories directly. Writes still use sudo -u
for correct ownership.

- Dockerfile: add CAP_SETGID to Python binary via setcap
- user_isolation: chmod 750, usermod -aG, os.setgroups() refresh
- utils/fs.py: all reads now use aiofiles/os (no subprocess branching)
2026-03-09 18:05:55 -05:00
Timothy Jaeryang Baek 18b3bc941d refactor: UserFS abstraction for multi-user file operations
Replace per-endpoint sudo wrappers with a unified UserFS class in
utils/fs.py. All file endpoints now receive a UserFS instance via
FastAPI dependency injection. Single-user mode uses stdlib/aiofiles,
multi-user mode routes all I/O through sudo -u.

- New: open_terminal/utils/fs.py (UserFS class)
- Simplified: user_isolation.py (provisioning only, sudo helpers removed)
- Updated: all 16 file endpoints in main.py (no more if-branches)
- Removed: user_fs.py (moved to utils/fs.py)
2026-03-09 17:56:00 -05:00
Timothy Jaeryang Baek ef63677087 feat: port detection and reverse proxy (0.9.0)
- GET /ports discovers listening TCP ports scoped to descendant processes
- /proxy/{port}/{path} reverse-proxies HTTP to localhost:{port}
- Cross-platform: /proc/net/tcp (Linux), lsof (macOS), netstat (Windows)
- New utils/port.py module with detect_listening_ports and get_descendant_pids
- Zero new dependencies
2026-03-04 14:59:59 -06:00