Skip to content

About

An AI terminal agent built on the tinystruct framework. Ask your computer to perform tasks in natural language ("show me the top 5 processes by memory", "find all .log files larger than 10MB", "check git status and recent commits"); the agent translates your request into OS-appropriate shell commands and streams the results in your terminal.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

SmartTerminal — Natural Language OS Agent

Operate your computer in plain language over MCP shell tools, powered by tinystruct.

Java tinystruct MCP License

English | 简体中文 | 日本語 | 한국어 | Español | Français | Deutsch

SmartTerminal Banner


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.


Table of Contents


Features

  • 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.exe with UTF-8 output) on Windows and /bin/bash (or /bin/sh) on Linux/macOS, with configurable shell overrides and per-command timeouts (default 30s, max 300s).
  • Stateful Session Directory: Tracks working directory changes across turns via terminal/cd and terminal/cwd.
  • Flexible LLM Support: Defaults to Google Gemini (gemini-3.5-flash-lite) and supports any OpenAI-compatible API endpoint via agent.api_url.
  • Dual-Mode CLI & HTTP + SSE: Run interactively in your terminal, execute single-shot CLI queries, or expose the chat action over HTTP with live token updates streamed via Server-Sent Events (SSE).
  • Conversation Memory & Custom Skills: Persists turn history in .agent_history.json and 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.

How It Works

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"]
Loading

Safety Model

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.

Prerequisites

  • Java 17 or higher
  • Maven 3.6+ (or use the bundled ./mvnw / mvnw.cmd wrapper)
  • A Google Gemini API key (or an OpenAI-compatible API key and endpoint)

Quick Start

1. Clone and Build

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.)

2. Set Your API Key and Launch

Windows (PowerShell):

$env:GEMINI_API_KEY = "your-api-key"
.\bin\dispatcher.cmd chat

Linux / macOS:

export GEMINI_API_KEY="your-api-key"
bin/dispatcher chat

3. Try a Few Prompts

  • What OS and shell am I running, and what is in the current directory?
  • Show me the top 5 processes using the most memory
  • Find all .log files larger than 10MB in this folder
  • Create a folder called demo and put a hello.txt file inside it (prompts for [y/N] approval)

Usage

Interactive CLI Session

bin/dispatcher chat        # Linux / macOS
bin\dispatcher.cmd chat    # Windows

Built-in session commands:

  • clear — resets conversation history (.agent_history.json).
  • exit or quit — exits the session.

Single-Message (One-Shot) Mode

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.

HTTP + SSE Mode

Serve SmartTerminal over HTTP using tinystruct's built-in HTTP server:

bin/dispatcher start --import org.tinystruct.system.HttpServer --import org.tinystruct.app.SmartTerminal

Call 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.

Standalone MCP Server Mode

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.SmartTerminalServer

Configuration

All 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).

Tools Exposed Over MCP

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).

Project Layout

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

Testing

Run the JUnit 5 test suite with Maven:

./mvnw test       # Linux / macOS
.\mvnw.cmd test   # Windows

License

Licensed under the Apache License 2.0. See LICENSE for details.

About

An AI terminal agent built on the tinystruct framework. Ask your computer to perform tasks in natural language ("show me the top 5 processes by memory", "find all .log files larger than 10MB", "check git status and recent commits"); the agent translates your request into OS-appropriate shell commands and streams the results in your terminal.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages