Commit Graph
31 Commits
Author SHA1 Message Date
Timothy Jaeryang Baek 7862652733 refac 2026-11-05 18:00:38 +09:00
Timothy Jaeryang Baek 2059b65ee0 refac 2026-11-05 12:41:59 +09:00
Timothy Jaeryang Baek 200b7ee445 refac 2026-11-02 08:27:16 +09:00
Timothy Jaeryang Baek b1fdd9ea1d refac 2026-11-02 02:20:33 +09:00
Timothy Jaeryang Baek 6f0b75076b refac 2026-10-24 05:14:56 +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 4240b4e934 refac 2026-10-19 03:32:20 +09:00
Timothy Jaeryang Baek 68f0fa1cf5 refac 2026-06-22 17:02:02 +02:00
Timothy Jaeryang Baek 811d4abc18 refac 2026-06-22 16:56:50 +02:00
Timothy Jaeryang Baek fbaf2e8e69 feat: per-session working directory tracking via X-Session-Id header
Replace the process-global os.chdir() with an in-memory dictionary
keyed by session ID (passed via X-Session-Id header). Multiple
concurrent chat sessions now maintain independent working directories.

- GET/POST /files/cwd read X-Session-Id to resolve per-session cwd
- POST /execute falls back to session cwd when no cwd param provided
- POST /api/terminals spawns PTY in the session's cwd
- 7-day sliding TTL for session entries
- Fully backward compatible: no header = fs.home default
2026-03-29 20:59:47 -05:00
Timothy Jaeryang Baek d5c9fc48e7 feat: add GET /system endpoint for LLM system prompt injection
- GET /system returns a structured system prompt grounding the LLM in
  the environment (OS, hostname, user, shell, Python version) with
  directives for tool usage
- Gated by OPEN_TERMINAL_ENABLE_SYSTEM_PROMPT env var (default: true)
- Advertised via features.system in GET /api/config for consumer discovery
- OPEN_TERMINAL_SYSTEM_PROMPT env var for full prompt override
- Endpoint excluded from OpenAPI schema, auth-protected
2026-03-22 22:11:08 -05:00
Timothy Jaeryang Baek 7738e7032a fix: enforce env/_FILE mutual exclusivity for empty values
The _FILE mutual-exclusivity guard silently passed when the plain env
var was set to an empty string, because empty strings are falsy.

Python: changed `if value and file_path` to
`if value is not None and file_path is not None`, and the fallback
return from `value or default` to
`value if value is not None else default`.

entrypoint.sh: changed ${!var:-} to ${!var+set} to test whether the
variable is defined at all, not just non-empty.

entrypoint-slim.sh: changed -n tests to ${var+set} via eval, matching
the bash entrypoint semantics.
2026-03-19 17:53:56 -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 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 9006401538 feat: conditional /info endpoint via OPEN_TERMINAL_INFO env var 2026-03-10 17:13:36 -05:00
Timothy Jaeryang Baek 7a629e1feb feat: multi-user mode via OPEN_TERMINAL_MULTI_USER
When enabled, reads the X-User-Id header (set by the OWUI proxy),
provisions a per-user Linux account on first access (useradd -m),
and runs all commands, file operations, and terminal sessions as
that user via sudo -u. chmod 700 on home directories provides
kernel-enforced isolation between users.

New environment variables:
- OPEN_TERMINAL_MULTI_USER (default: false)
- OPEN_TERMINAL_USER_PREFIX (default: empty)
- OPEN_TERMINAL_UVICORN_LOOP (default: auto)

Closes #38
2026-03-09 17:26:27 -05:00
Timothy Jaeryang Baek 500525fde5 feat: make uvicorn event loop configurable via OPEN_TERMINAL_UVICORN_LOOP
Defaults to 'auto' (uvicorn's default). Users hitting segfaults on
Python 3.12 can set OPEN_TERMINAL_UVICORN_LOOP=asyncio to bypass uvloop.

Refs #37
2026-03-09 16:37:09 -05:00
Timothy Jaeryang Baek 79ba67cf00 feat: add notebook execution endpoints (/notebooks)
Multi-session Jupyter notebook execution via REST endpoints.
Each session gets its own kernel via nbclient.
Supports per-cell execution with rich outputs (images, HTML, LaTeX).

- POST /notebooks — create session (starts kernel)
- POST /notebooks/{id}/execute — execute cell
- GET /notebooks/{id} — session status
- DELETE /notebooks/{id} — stop kernel

nbclient and ipykernel are now core dependencies.
OPEN_TERMINAL_ENABLE_NOTEBOOKS env var to enable/disable.

Bump version 0.9.3 → 0.10.0
2026-03-05 15:51:41 -06:00
Timothy Jaeryang Baek b37842f693 feat: custom execute description env var (0.9.2) 2026-03-05 15:23:06 -06:00
Timothy Jaeryang Baek bab6a5a079 feat: add configurable execute_timeout for default command wait
When OPEN_TERMINAL_EXECUTE_TIMEOUT is set (env var or execute_timeout
in config.toml), the execute and get_process_status endpoints will use
it as the default wait time when the caller omits the wait parameter.

This helps smaller LLM models get command output inline without needing
to call get_process_status separately.

Closes #17
2026-03-04 13:41:06 -06:00
Timothy Jaeryang Baek 87b0dcfba5 feat: configurable TERM env var for terminal color support
Terminal sessions now set the TERM environment variable (default
xterm-256color) so programs emit ANSI color codes. Configurable via
OPEN_TERMINAL_TERM environment variable or 'term' in config.toml.
2026-03-02 19:17:16 -06:00
Timothy Jaeryang Baek 4d896916bd feat: configurable terminal feature with server-side discovery
- Add OPEN_TERMINAL_ENABLE_TERMINAL env var / enable_terminal config
  option to enable/disable the interactive terminal (default: true)
- Add GET /api/config endpoint for client-side feature discovery
- When disabled, all /api/terminals routes and WebSocket endpoint
  are not mounted
- Bump version to 0.8.1
2026-03-02 16:29:41 -06:00
Timothy Jaeryang Baek 840f538d79 fix: PTY device exhaustion and session limit (0.7.2)
- Close leaked PTY file descriptors when subprocess creation fails
- Return 503 with descriptive message when PTY devices are exhausted
- Add MAX_TERMINAL_SESSIONS (default 16, env OPEN_TERMINAL_MAX_SESSIONS)
- Prune dead sessions before checking the session limit
- Bump version to 0.7.2
2026-03-02 15:43:10 -06:00
Timothy Jaeryang Baek f94fa3cec6 feat: add TOML configuration file support
Load settings from /etc/open-terminal/config.toml (system) and
$XDG_CONFIG_HOME/open-terminal/config.toml (user). Supports host, port,
api_key, cors_allowed_origins, log_dir, and binary_mime_prefixes.

CLI flags and environment variables still take precedence. A --config
flag allows pointing to a custom config file.

Closes #11
2026-03-02 12:52:33 -06:00
Timothy Jaeryang Baek acb32b0101 feat: use XDG Base Directories for log storage
Change the default LOG_DIR from ~/.open-terminal/logs to
$XDG_STATE_HOME/open-terminal/logs (defaults to
~/.local/state/open-terminal/logs when XDG_STATE_HOME is unset).

The OPEN_TERMINAL_LOG_DIR env var override is unchanged.

Closes #12
2026-03-02 12:26:12 -06:00
Timothy Jaeryang Baek 26090678d4 feat: add Docker secrets support for OPEN_TERMINAL_API_KEY_FILE
Allow loading the API key from a file via OPEN_TERMINAL_API_KEY_FILE,
following the convention used by the official PostgreSQL Docker image.

- Add _resolve_file_env() helper in env.py
- Add file_env shell function in entrypoint.sh
- Add _FILE fallback in cli.py run command
- Update README with Docker Compose example
- Bump version to 0.4.3

Closes #14
2026-03-02 12:17:54 -06:00
Timothy Jaeryang Baek 19543ee983 refac 2026-02-25 19:56:20 -06:00
Timothy Jaeryang Baek 6c08563b56 refactor: read_file returns raw binary for supported types, rejects others
- Text files: return JSON with content string (unchanged)
- Supported binary types (image/* by default): return raw binary
  with proper Content-Type header
- Unsupported binary types: 415 error
- New env var OPEN_TERMINAL_BINARY_MIME_PREFIXES (comma-separated,
  default: 'image') controls which binary types are allowed
2026-02-24 18:49:47 -06:00
Timothy Jaeryang Baek dd5649b696 v0.2.1: file-backed process output with offset-based polling
- Persist all process stdout/stderr to JSONL log files for audit
- Add offset-based polling (next_offset) for stateless incremental reads
- Add tail parameter to bound response size for AI agents
- Remove in-memory output buffer and drain-on-read pattern
- Organize logs under ~/.open-terminal/logs/processes/
- Add aiofiles dependency for async file I/O
- Remove OPEN_TERMINAL_MAX_OUTPUT_LINES (no longer needed)
2026-02-14 19:35:20 -06:00
Timothy Jaeryang Baek af21be471c refac 2026-02-14 17:05:15 -06:00
Timothy Jaeryang Baek 3103f34ee7 refac 2026-02-12 13:45:59 -06:00