Operate your computer in plain language over MCP shell tools, powered by tinystruct.
SmartTerminal is an AI terminal agent built on the tinystruct Java framework (1.7.40), modeled after SmartDBA. Ask your computer to perform everyday tasks in natural language — "show me the top 5 processes by memory", "find all .log files larger than 10MB", or "check git status and recent commits" — and SmartTerminal translates your request into OS-appropriate shell commands, executes them through Model Context Protocol (MCP) terminal tools, and streams the results as ANSI-formatted Markdown directly in your terminal.
- Features
- How It Works
- Safety Model
- Prerequisites
- Quick Start
- Usage
- Configuration
- Tools Exposed Over MCP
- Project Layout
- Testing
- License
- Streaming Interactive CLI: Renders model responses live chunk-by-chunk as ANSI-colored Markdown (headings, lists, syntax-highlighted code blocks, and tables) while suppressing internal JSON tool-call blocks.
- Cross-Platform Shell Execution over MCP: Automatically adapts to PowerShell (
powershell.exewith UTF-8 output) on Windows and/bin/bash(or/bin/sh) on Linux/macOS, with configurable shell overrides and per-command timeouts (default30s, max300s). - Stateful Session Directory: Tracks working directory changes across turns via
terminal/cdandterminal/cwd. - Flexible LLM Support: Defaults to Google Gemini (
gemini-3.5-flash-lite) and supports any OpenAI-compatible API endpoint viaagent.api_url. - Dual-Mode CLI & HTTP + SSE: Run interactively in your terminal, execute single-shot CLI queries, or expose the
chataction over HTTP with live token updates streamed via Server-Sent Events (SSE). - Conversation Memory & Custom Skills: Persists turn history in
.agent_history.jsonand supports an optional Markdown skill file (agent.skill_file) to inject domain-specific guidance into the system prompt. - Defense-in-Depth Safety: Combines deterministic read-only command classification, high-risk warnings, interactive
[y/N]approval, optional TypeSafe JEV semantic review, and workspace-confined file operations.
flowchart LR
User["User (CLI / HTTP + SSE)"] --> Agent["SmartTerminal Agent\n(LLM Streaming + Markdown Renderer)"]
Agent --> Gate{"Safety Gate\n(Read-Only Classifier +\nOptional TypeSafe JEV)"}
Gate -- "Read-only" --> MCP["SmartTerminalServer\n(MCP Server)"]
Gate -- "Mutating / High-risk" --> Prompt["Interactive [y/N] Approval"]
Prompt -- "Approved" --> MCP
MCP --> Tool["TerminalTool\n(PowerShell / Bash)"]
Tool --> OS["Operating System"]
Model output is always treated as untrusted input. SmartTerminal enforces multiple independent safeguards:
| Layer | Protection |
|---|---|
| Deterministic Read-Only Floor | terminal/execute runs without prompting only when the command is provably read-only (TerminalTool.isReadOnlyCommand). Any command chaining (;, &&, ||, &), redirection (>, <), subshells ($(...), backticks), script blocks ({ ... }), multi-line scripts, or mutating commands automatically require [y/N] approval. |
| High-Risk Warnings | Destructive patterns (such as rm -rf, Remove-Item -Recurse -Force, del /s, shutdown, format, sudo, curl | sh) display a bold red [HIGH RISK COMMAND] warning before asking for confirmation. |
| TypeSafe JEV Semantic Review | When TYPESAFE_API_KEY is configured, the TypeSafe JEV model performs an additional semantic review of read-only commands before execution. You can also require confirmation for every command by adding terminal/execute to typesafe.routing.confirm-actions. |
| No Approver, No Side Effects | Outside an interactive terminal (such as one-shot --message mode or the HTTP chat action), there is no human to approve prompts, so state-changing shell commands and file writes are refused. |
| Confined Workspace File Actions | The agent's read and write actions are restricted to agent.workspace (default: current working directory), blocking application.properties, .agent_history.json, .. path traversal, and symlinks that escape the workspace root. |
- Java 17 or higher
- Maven 3.6+ (or use the bundled
./mvnw/mvnw.cmdwrapper) - A Google Gemini API key (or an OpenAI-compatible API key and endpoint)
git clone https://github.com/tinystruct/tinystruct-smart-terminal.git
cd tinystruct-smart-terminal
./mvnw package # builds, runs tests, and copies dependencies into lib/(On Windows PowerShell, use .\mvnw.cmd package.)
Windows (PowerShell):
$env:GEMINI_API_KEY = "your-api-key"
.\bin\dispatcher.cmd chatLinux / macOS:
export GEMINI_API_KEY="your-api-key"
bin/dispatcher chatWhat OS and shell am I running, and what is in the current directory?Show me the top 5 processes using the most memoryFind all .log files larger than 10MB in this folderCreate a folder called demo and put a hello.txt file inside it(prompts for[y/N]approval)
bin/dispatcher chat # Linux / macOS
bin\dispatcher.cmd chat # WindowsBuilt-in session commands:
clear— resets conversation history (.agent_history.json).exitorquit— exits the session.
bin/dispatcher chat --message "List files in the current directory"Prints the formatted response and exits immediately. Because one-shot mode cannot prompt for interactive approval, only read-only commands are permitted.
Serve SmartTerminal over HTTP using tinystruct's built-in HTTP server:
bin/dispatcher start --import org.tinystruct.system.HttpServer --import org.tinystruct.app.SmartTerminalCall the chat action over HTTP (?q=chat&message=...); live token deltas are pushed over Server-Sent Events (SSE), and the final response returns raw Markdown. As with one-shot mode, state-changing commands are refused without an interactive approver.
Deploy only the MCP terminal server so external MCP clients can connect to it:
bin/dispatcher start --import org.tinystruct.system.HttpServer --import org.tinystruct.app.SmartTerminalServerAll settings live in src/main/resources/application.properties. Values written as $_NAME are resolved automatically from the environment variable NAME.
# LLM
agent.api_key=$_GEMINI_API_KEY
agent.model=gemini-3.5-flash-lite
# agent.api_url=... # OpenAI-compatible endpoint; defaults to Gemini
# agent.workspace=. # root directory for read/write file actions
# agent.skill_file=path/to/SKILL.md # optional Markdown file appended to system prompt
# Terminal execution
terminal.shell= # optional override (e.g. pwsh, /bin/zsh)
terminal.timeout.seconds=30 # default command timeout in seconds (max 300)
# Internal MCP server (change token in production)
mcp.server.url=http://localhost:8080/
mcp.auth.token=123456
# Approval rules (TypeSafe / JEV)
typesafe.routing.confirm-actions= # add terminal/execute to confirm EVERY command
typesafe.api-key=$_TYPESAFE_API_KEY # optional semantic review for read-only commands| Property | Default | Description |
|---|---|---|
agent.api_key |
$_GEMINI_API_KEY |
API key for Gemini or your OpenAI-compatible provider. |
agent.model |
gemini-3.5-flash-lite |
Model identifier sent to the LLM API. |
agent.api_url |
(empty — Gemini) | Custom OpenAI-compatible chat completions URL. |
agent.workspace |
. |
Root directory confining read and write file actions. |
agent.skill_file |
(empty) | Path to a Markdown file injected into the system prompt. |
terminal.shell |
(OS default) | Shell executable override (pwsh, /bin/zsh, cmd.exe, etc.). |
terminal.timeout.seconds |
30 |
Default per-command timeout in seconds (capped at 300). |
mcp.server.url |
http://localhost:8080/ |
URL of the embedded or remote MCP server. |
mcp.auth.token |
123456 |
Bearer token for MCP authentication (change in production). |
typesafe.api-key |
$_TYPESAFE_API_KEY |
Optional TypeSafe JEV API key for semantic command review. |
typesafe.routing.confirm-actions |
(empty) | Comma-separated actions that always require confirmation (e.g. terminal/execute). |
| Tool | Parameters | Purpose |
|---|---|---|
terminal/info |
(none) | Returns OS, architecture, hostname, user, default shell, and current working directory. |
terminal/cwd |
(none) | Returns the current session working directory. |
terminal/cd |
path (required) |
Changes the session working directory. |
terminal/execute |
command (required), cwd, timeout |
Executes a shell command with optional working directory override and timeout (default 30s, max 300s). |
tinystruct-smart-terminal/
├── src/main/java/org/tinystruct/app/
│ ├── SmartTerminal.java # Interactive CLI, HTTP/SSE agent, LLM streaming, Markdown renderer, approval gate
│ ├── SmartTerminalServer.java # MCP server registering the terminal tools
│ └── tools/
│ └── TerminalTool.java # MCP shell tools, cross-platform runner, read-only & high-risk classifiers
├── src/main/resources/
│ └── application.properties # Agent, terminal, MCP, and TypeSafe configuration
├── src/test/java/org/tinystruct/app/
│ ├── CompletionTest.java # Completion tests
│ ├── StreamRendererTest.java # Streaming Markdown & tool-call suppression tests
│ └── tools/
│ └── TerminalToolSafetyTest.java # Read-only & high-risk classifier tests
└── static/
└── banner.png # Project banner
Run the JUnit 5 test suite with Maven:
./mvnw test # Linux / macOS
.\mvnw.cmd test # WindowsLicensed under the Apache License 2.0. See LICENSE for details.
