Metadata-Version: 2.2
Name: agentssh
Version: 1.0.0
Summary: AgentSSH — Production-Ready AI Agent SSH Client developed by Its2Pawan
Author-email: Its2Pawan <pawan@example.com>
License: MIT
Project-URL: Homepage, https://github.com/Its2Pawan/agentssh
Project-URL: Repository, https://github.com/Its2Pawan/agentssh
Project-URL: Documentation, https://github.com/Its2Pawan/agentssh#readme
Keywords: ssh,ai-agents,sftp,cli,monitoring,claude-code,cursor,antigravity,codex,devops
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Topic :: System :: Systems Administration
Classifier: Topic :: System :: Networking
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: paramiko>=3.4.0
Requires-Dist: asyncssh>=2.14.0
Requires-Dist: typer>=0.12.0
Requires-Dist: rich>=13.7.0
Requires-Dist: pydantic>=2.6.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: cryptography>=42.0.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
Dynamic: license-file

# 🚀 AgentSSH — AI Agent SSH Client

<div align="center">

```
╭──────────────────────────────────────────────────────────╮
│                                                          │
│                 ⚡  AgentSSH  ⚡                          │
│            AI Agent SSH & SFTP Client                    │
│                                                          │
│              Developed by Its2Pawan                      │
│                                                          │
╰──────────────────────────────────────────────────────────╯
```

**Production-ready, terminal-first SSH client specifically designed for AI Coding Agents and DevOps Engineers.**

[![PyPI Version](https://img.shields.io/badge/pypi-v1.0.0-blue.svg?logo=pypi&logoColor=white)](https://pypi.org/project/agentssh/)
[![Python](https://img.shields.io/badge/Python-3.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue.svg?logo=python&logoColor=white)](https://python.org)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Tests](https://img.shields.io/badge/Tests-34%20Passed-brightgreen.svg?logo=pytest&logoColor=white)](tests/)
[![Security](https://img.shields.io/badge/Security-Strict%20HostKey-red.svg?logo=shield&logoColor=white)](docs/architecture.md)
[![MCP](https://img.shields.io/badge/MCP-Protocol%20Ready-purple.svg?logo=anthropic&logoColor=white)](docs/mcp_server.md)

</div>

---

## 🎯 1. Why AgentSSH?

Traditional SSH clients (like standard OpenSSH) were built for human interactive typing. When terminal-based AI agents (**Claude Code**, **Google Antigravity**, **Cursor**, **Codex**) run standard SSH commands, they often get stuck:
- ❌ **Unattended Password / Host Key Prompts**: Stalls agent loops indefinitely.
- ❌ **Mixed Output Streams**: Interleaved stderr and stdout breaks automated JSON parsers.
- ❌ **Lost Exit Codes**: Command failures go undetected.
- ❌ **Heavy Dependencies**: Requires installing monitoring agents on remote servers.

### 🌟 The AgentSSH Solution:
- 🟢 **Machine-Readable JSON (`--json`)**: Every command emits deterministic, schema-validated JSON to `stdout`.
- 🟢 **Pure Stream Separation**: Output payloads flow to `stdout`; diagnostics and warnings flow strictly to `stderr`.
- 🟢 **Fail-Fast Non-Interactive Mode**: Never hangs on prompts (`AGENTSSH_NON_INTERACTIVE=1`).
- 🟢 **Zero Remote Agent Telemetry**: Monitor CPU, RAM, Disks, Uptime, Processes, and Docker using built-in Linux tools.
- 🟢 **Hardened Security**: Strict SSH host-key verification by default, permissions protection (`0700`/`0600`), and SQLite audit logs.
- 🟢 **Native MCP Integration**: Launch as a Model Context Protocol server (`agentssh --mcp`).

---

## 🏗️ 2. Architecture Overview

```mermaid
flowchart TD
    subgraph AI["🤖 AI Coding Agents & Users"]
        A1["Claude Code"]
        A2["Google Antigravity"]
        A3["Cursor IDE"]
        A4["OpenAI Codex"]
        A5["DevOps Engineer"]
    end

    subgraph CLI["⚡ AgentSSH CLI Engine (Typer + Rich)"]
        B1["CLI Controller\n`agentssh <cmd>`"]
        B2["JSON Mode Formatter\n`--json -> stdout`"]
        B3["Audit Logger\n`SQLite history.db`"]
    end

    subgraph Core["🔐 Security & Transport Layer"]
        C1["Paramiko SSH Engine\n`Keepalive + Reconnect`"]
        C2["HostKey Policy\n`Strict / Accept-New`"]
        C3["Credential Manager\n`Env Vars + Keypairs`"]
        C4["SFTP Client\n`Upload / Download / Resume`"]
        C5["Metrics Collector\n`CPU / RAM / Disk / Docker`"]
    end

    subgraph Remote["🐧 Remote Linux Server"]
        D1["Remote Shell / PTY"]
        D2["Linux System (/proc, df, ps)"]
        D3["Docker Daemon"]
        D4["Remote Filesystem"]
    end

    AI --> CLI
    CLI --> Core
    Core -->|Encrypted SSH2| Remote
```

---

## 📦 3. Installation

### From PyPI
```bash
pip install agentssh
```

### From Source (Development)
```bash
git clone https://github.com/Its2Pawan/agentssh.git
cd agentssh
pip install -e ".[dev]"
```

---

## 🚀 4. How to Use (Step-by-Step)

### Step 1: 🏥 Health Check (`doctor`)
Verify your environment, permissions, and dependencies in one second:
```bash
agentssh doctor
```

---

### Step 2: ➕ Add an SSH Connection Profile (`add`)
Save remote server connection parameters once under an easy alias:

```bash
# Production server with SSH private key
agentssh add production \
  --host 192.168.1.100 \
  --user root \
  --port 22 \
  --key ~/.ssh/id_ed25519 \
  --alias prod

# Staging server with password in an environment variable
agentssh add staging \
  --host 10.0.0.50 \
  --user deploy \
  --password-env STAGING_PASSWORD \
  --policy accept-new
```

To list all configured profiles:
```bash
agentssh list
# Or in JSON:
agentssh list --json
```

---

### Step 3: ⚡ Execute Remote Commands (`exec`)

Execute commands without an interactive shell, capturing stdout, stderr, and exit codes:

```bash
# Human-readable output
agentssh exec production "uptime"

# Machine-readable JSON output for AI Agents
agentssh exec production "docker ps" --json
```

**JSON Output Example**:
```json
{
  "success": true,
  "action": "exec",
  "exit_code": 0,
  "data": {
    "command": "docker ps",
    "exit_code": 0,
    "stdout": "CONTAINER ID   IMAGE          STATUS\n8f3c7e492a10   nginx:alpine   Up 3 hours\n",
    "stderr": "",
    "duration_ms": 22.4,
    "timed_out": false,
    "profile": "production"
  },
  "error": null,
  "timestamp": "2026-11-22T09:50:00.000000+00:00"
}
```

---

### Step 4: 📊 Server Monitoring (`stats`, `processes`, `docker`)
Instantly monitor servers **without installing any daemon or software** on the remote server:

```bash
# Full server stats (CPU, RAM, Disks, Uptime, Load)
agentssh stats production --json

# Top running processes sorted by CPU or Memory
agentssh processes production --limit 10 --sort cpu

# Inspect Docker containers
agentssh docker ps production --all --json
```

---

### Step 5: 📁 SFTP Remote File Manager (`upload`, `download`, `ls`, `rm`)

```bash
# Upload a file
agentssh upload production ./app.py /root/app.py

# Upload a whole directory recursively
agentssh upload production ./dist /var/www/html --recursive

# Download remote logs with transfer speed & progress
agentssh download production /var/log/syslog ./syslog

# List remote files in table or JSON
agentssh ls production /var/www/html --json

# Remote directory and file operations
agentssh mkdir production /root/my-project
agentssh rm production /root/old-file.txt
agentssh rename production /root/old.txt /root/new.txt
```

---

### Step 6: 💻 Interactive Terminal Shell (`shell`)
For human operators requiring full interactive access:
```bash
agentssh shell production
```
- Full PTY allocation (`xterm-256color`)
- Real-time window resizing (`SIGWINCH`)
- Keyboard forwarding & Ctrl+C trapping
- Clean terminal restoration on exit

---

### Step 7: 🔑 SSH Keypair Generator (`keys`)
Generate modern, hardened SSH keys with strict `0600` permissions and install them remotely:

```bash
# Generate Ed25519 keypair
agentssh keys generate ~/.agentssh/keys/id_ed25519 --type ed25519

# Copy public key to remote authorized_keys
agentssh keys copy-id production
```

---

### Step 8: 📜 Execution History & Audit Log (`history`)
Every executed command is audited in SQLite (`~/.agentssh/history.db`):
```bash
agentssh history --limit 20
```

---

## 🤖 5. AI Agent Quick Integration

### 🔹 Claude Code
Add to `.claude/config.json`:
```json
{
  "system_prompt": "When managing remote servers, use `agentssh` in JSON mode: `agentssh <subcommand> <profile> --json`. Inspect `data.stdout` and `exit_code`."
}
```

### 🔹 Google Antigravity
In `.gemini/rules/agentssh.md`:
```markdown
## Remote Operations
- Always invoke AgentSSH with `--json`.
- Non-zero exit codes signify remote errors.
- For remote inspection without installing software, use `agentssh stats <target> --json`.
```

### 🔹 Cursor Agent
In `.cursorrules`:
```markdown
When managing remote servers:
1. Use `agentssh` CLI commands with `--json`.
2. Inspect `agentssh stats <target> --json` before running heavy builds.
```

### 🔹 Model Context Protocol (MCP) Server
Launch native MCP stdio server:
```bash
agentssh --mcp
```

---

## 📋 6. Full Command Cheat Sheet

| Icon | Command | Description | Example |
|:---:|:---|:---|:---|
| ➕ | `add` | Add an SSH profile | `agentssh add prod --host 10.0.0.1 --user root` |
| ➖ | `remove` | Remove an SSH profile | `agentssh remove prod` |
| ✏️ | `edit` | Update existing profile | `agentssh edit prod --port 2222` |
| 📋 | `list` | List saved profiles | `agentssh list [--json]` |
| 🔌 | `connect` | Test connection & latency | `agentssh connect prod --check [--json]` |
| ⚡ | `exec` | Execute remote command | `agentssh exec prod "uptime" [--json]` |
| 💻 | `shell` | Open interactive terminal | `agentssh shell prod` |
| ⬆️ | `upload` | SFTP upload (file/folder) | `agentssh upload prod ./src /var/www -r` |
| ⬇️ | `download` | SFTP download (file/folder) | `agentssh download prod /var/log ./logs -r` |
| 📂 | `ls` | List remote directory | `agentssh ls prod /root [--json]` |
| 📁 | `mkdir` | Create remote directory | `agentssh mkdir prod /root/data -p` |
| 🗑️ | `rm` | Delete remote file/folder | `agentssh rm prod /root/old -r` |
| 🔄 | `rename` | Rename remote file | `agentssh rename prod /root/a /root/b` |
| 📊 | `stats` | System stats (CPU/RAM/Disk) | `agentssh stats prod [--json]` |
| 📈 | `processes` | List remote processes | `agentssh processes prod --limit 20` |
| 🐳 | `docker ps` | List Docker containers | `agentssh docker ps prod --all [--json]` |
| ⏱️ | `history` | Command audit log | `agentssh history --limit 50 [--json]` |
| 🔑 | `keys` | Manage SSH keys | `agentssh keys generate` |
| 🏥 | `doctor` | Health & permissions check | `agentssh doctor` |
| 📖 | `guide` | Agent integration guide | `agentssh guide [agent]` |
| ℹ️ | `version` | Version & brand info | `agentssh version [--json]` |

---

## 🛡️ 7. Security Hardening

- 🔒 **Strict Host-Key Verification**: Enabled by default to block Man-in-the-Middle attacks.
- 🔒 **File Permissions Protection**: Config directory enforced to `0700`, files and keys to `0600`.
- 🔒 **Zero Plaintext Password Storage**: Passwords resolved exclusively from environment variables or secure prompts.
- 🔒 **Local Audit Trail**: Persistent SQLite log tracking execution history.

---

## 🧪 8. Automated Tests

```bash
pytest -v
```
**34 / 34 Tests Passing (100% Success Rate)**

---

## 👨‍💻 9. Brand & License

Developed with precision by **Its2Pawan**.  
Licensed under the [MIT License](LICENSE).
