Share
## https://sploitus.com/exploit?id=682A33CB-562C-54B2-A504-79E1605365A9
# Agent Skill POC - LLM-driven Interactive CLI Agent

An LLM-driven interactive CLI Agent with sandbox execution, human-in-the-loop permissions, and skill integration.

## Features

### Core Architecture

1. **Subprocess Sandbox (Stream Hijacking)**
   - Uses Node.js `child_process.spawn` for subprocess management
   - stdio: `["pipe", "pipe", "pipe"]` to hijack all streams
   - `shell: false` for secure structured argument passing
   - Non-blocking stdout/stderr reading with output truncation (1MB limit)

2. **Human-in-the-Loop Permission Gateway**
   - Command classification strategy:
     - **READ_ONLY**: `ls`, `cat`, `grep`, `find`, `head`, `tail`, `pwd`, `echo`, `python3`, `node` (auto-approved)
     - **DANGEROUS**: `rm`, `mv`, `cp`, `git`, `npm`, `yarn`, `pip`, `wget`, `curl`, `ssh`, `chmod` (requires confirmation)
     - **FORBIDDEN**: `mkfs`, `dd`, `fdisk`, `reboot`, `shutdown`, `curl | bash` patterns (completely blocked)
   - High-risk command approval with impact display

3. **Session State Management (CWD)**
   - Maintains `current_working_directory` variable
   - Parses `cd` command to dynamically update CWD
   - Each subprocess explicitly injected with CWD

4. **Interactive Command Support**
   - Uses `node-pty` for interactive programs (Python REPL, vim, etc.)
   - Stream forwarding: user input โ†’ PTY โ†’ subprocess โ†’ PTY โ†’ main process โ†’ output

5. **LLM Agent Integration**
   - OpenAI-compatible API support
   - Tool Calling architecture with tools:
     - `run_command`: Execute shell commands (via permission gateway)
     - `run_python`: Execute Python code (temp file + sandbox execution)
     - `call_skill`: Invoke installed skills
     - `list_skills`: List available skills
     - `load_skill`: Install skills from GitHub (Anthropic format)
     - `use_template`: Use templates from skills

6. **Anthropic Skills Compatibility**
   - Full support for [Anthropic's official Skills format](https://github.com/anthropics/skills)
   - Install skills directly from GitHub repositories
   - Template support for skill output formatting
   - Unified registry for both Anthropic and OpenClaw format skills

## Installation

```bash
npm install
npm run build
```

Or install globally:

```bash
npm link
```

## Usage

### Interactive Chat Mode

```bash
# Start interactive chat
npm run chat
# or
node bin/agent-skill-poc.js chat

# With verbose output
node bin/agent-skill-poc.js chat -v

# With custom working directory
node bin/agent-skill-poc.js chat -C /path/to/project
```

### CLI Commands

```bash
# List available skills
agent-skill-poc list
agent-skill-poc list --verbose
agent-skill-poc ls -v

# Run a skill
agent-skill-poc run 
agent-skill-poc run  --dry-run

# Show skill info
agent-skill-poc info 

# Show configuration
agent-skill-poc config
```

### Chat Commands (in interactive mode)

- `/help` - Show available commands
- `/clear` - Clear conversation history
- `/cwd` - Show current working directory
- `/cd ` - Change working directory
- `/skill list` - List all installed skills
- `/skill list --anthropic` - List only Anthropic format skills
- `/skill install ` - Install a skill from GitHub (e.g., `anthropics/skills/algorithmic-art`)
- `/skill search ` - Search installed skills
- `/exit` - Exit the program

## Configuration

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `OPENAI_API_KEY` | Your OpenAI API key | Required |
| `OPENAI_BASE_URL` | Custom API endpoint | `https://api.openai.com/v1` |
| `OPENAI_MODEL` | Model to use | `gpt-4` |
| `AGENT_SKILL_PATHS` | Additional skill directories (colon-separated) | - |

### Example

```bash
export OPENAI_API_KEY=your-api-key
export OPENAI_BASE_URL=https://api.your-provider.com/v1  # optional
export OPENAI_MODEL=gpt-4  # optional
```

## Project Structure

```
src/
โ”œโ”€โ”€ cli.ts                    # Interactive CLI entry point
โ”œโ”€โ”€ index.ts                  # Main CLI (backward compatible commands)
โ”œโ”€โ”€ types.ts                  # Re-exported types
โ”œโ”€โ”€ agent/
โ”‚   โ”œโ”€โ”€ core.ts               # Agent core, handles LLM interaction
โ”‚   โ”œโ”€โ”€ prompt.ts             # System prompt definition
โ”‚   โ””โ”€โ”€ tools.ts              # Tool definitions and handlers
โ”œโ”€โ”€ sandbox/
โ”‚   โ”œโ”€โ”€ core.ts               # Sandbox core interface
โ”‚   โ”œโ”€โ”€ executor.ts           # Command executor (stream hijacking)
โ”‚   โ”œโ”€โ”€ permission.ts         # Permission gateway
โ”‚   โ”œโ”€โ”€ session.ts            # Session state (CWD)
โ”‚   โ””โ”€โ”€ interactive.ts        # Interactive command support (PTY)
โ”œโ”€โ”€ llm/
โ”‚   โ”œโ”€โ”€ provider.ts           # LLM abstract interface
โ”‚   โ””โ”€โ”€ openai.ts             # OpenAI-compatible implementation
โ”œโ”€โ”€ skill/
โ”‚   โ”œโ”€โ”€ types.ts              # Skill type definitions (Anthropic & OpenClaw)
โ”‚   โ”œโ”€โ”€ discovery.ts          # Skill discovery
โ”‚   โ”œโ”€โ”€ executor.ts           # Skill execution
โ”‚   โ”œโ”€โ”€ anthropic-loader.ts   # Anthropic format loader (GitHub support)
โ”‚   โ””โ”€โ”€ registry.ts           # Unified skill registry
โ””โ”€โ”€ utils/
    โ”œโ”€โ”€ logger.ts             # Logging utility
    โ””โ”€โ”€ config.ts             # Configuration management
```

## Skill Format

Skills are defined in `SKILL.md` files with YAML frontmatter:

```markdown
---
name: my-skill
description: A brief description of the skill
homepage: https://example.com
metadata:
  openclaw:
    emoji: ๐Ÿ”ง
    requires:
      bins: [node, python]
      env: [API_KEY]
---

# Skill Title

Documentation and usage examples...

## Commands

\`\`\`bash
node {baseDir}/scripts/my-script.js
\`\`\`
```

### Frontmatter Fields

- `name` (required): The skill name
- `description` (required): A brief description
- `homepage` (optional): URL to more information
- `metadata` (optional): JSON object with additional metadata
  - `openclaw.emoji`: Emoji displayed in listings
  - `openclaw.requires.bins`: Required binaries
  - `openclaw.requires.env`: Required environment variables

### Placeholders

- `{baseDir}`: Replaced with the skill's directory path

## Anthropic Skills Format

The project now supports the [official Anthropic Skills format](https://github.com/anthropics/skills).

### Skill Structure

```
skill-name/
โ”œโ”€โ”€ SKILL.md          # Main file (YAML frontmatter + Markdown)
โ”œโ”€โ”€ templates/        # Optional template files
โ”‚   โ””โ”€โ”€ viewer.html
โ””โ”€โ”€ LICENSE.txt       # Optional license
```

### SKILL.md Format

```markdown
---
name: algorithmic-art
description: Creating algorithmic art using p5.js
license: Complete terms in LICENSE.txt
---

# Algorithmic Art

Create beautiful algorithmic art with p5.js...

## Examples

- Generate geometric patterns
- Create animated visuals

## Guidelines

- Use p5.js for canvas operations
- Keep animations performant
```

### Installing Anthropic Skills

```bash
# In interactive mode
> /skill install anthropics/skills/algorithmic-art

# Or with full URL
> /skill install https://github.com/anthropics/skills/tree/main/skills/brand-guidelines
```

### Using Templates

Skills can include templates that can be rendered with custom variables:

```typescript
// Via LLM agent
await useTemplate('algorithmic-art', 'viewer.html', { title: 'My Art' });
```

### Storage Locations

- **OpenClaw Skills**: `~/.openclaw/workspace/skills/`
- **Anthropic Skills**: `~/.agent-skills/anthropic/repos/`

## Interactive Example

```
$ agent-chat
๐Ÿค– Agent CLI v1.0.0
ๅทฅไฝœ็›ฎๅฝ•: /home/user/projects/my-app
ๆจกๅž‹: gpt-4

่พ“ๅ…ฅๆ‚จ็š„้—ฎ้ข˜ๆˆ–ๅ‘ฝไปค๏ผŒๆŒ‰ Ctrl+C ้€€ๅ‡บ
่พ“ๅ…ฅ /help ๆŸฅ็œ‹ๅฏ็”จๅ‘ฝไปค

> ๅธฎๆˆ‘ๅˆ—ๅ‡บๅฝ“ๅ‰็›ฎๅฝ•็š„ๆ–‡ไปถ
๐Ÿ“ ๆ‰ง่กŒ: ls -la
...

> ่ฟ่กŒ Python ่ฎก็ฎ— 2+2
๐Ÿ ๆ‰ง่กŒ Python ไปฃ็ ...
็ป“ๆžœ: 4

> rm -rf /
โš ๏ธ  ้ซ˜ๅฑๅ‘ฝไปค้œ€่ฆ็กฎ่ฎค
ๅ‘ฝไปค: rm -rf /
ๅฝฑๅ“: ๅˆ ้™คๆ น็›ฎๅฝ•ไธ‹ๆ‰€ๆœ‰ๆ–‡ไปถ
[y/n] ๆ˜ฏๅฆๆ‰ง่กŒ? n
ๅทฒๅ–ๆถˆ

> ๅฏๅŠจ Python REPL
๐Ÿ ่ฟ›ๅ…ฅไบคไบ’ๅผ Python...
>>> print("hello")
hello
>>> exit()
```

## Commands Summary

| Command | Alias | Description |
|---------|-------|-------------|
| `list` | `ls` | List all available skills |
| `run ` | - | Execute a skill |
| `info ` | - | Show skill documentation |
| `config` | - | Show current configuration |
| `chat` | - | Start interactive LLM agent session |

### Run Options

| Option | Description |
|--------|-------------|
| `-c, --command ` | Run a specific command |
| `-d, --dry-run` | Show what would be executed |
| `--help-skill` | Show skill documentation |

### Chat Options

| Option | Description |
|--------|-------------|
| `-v, --verbose` | Show detailed tool execution info |
| `-C, --cwd ` | Set working directory |

## Development

```bash
# Build
npm run build

# Run in development
npm run dev -- list
npm run dev:chat

# Run directly
npx ts-node src/index.ts list
npx ts-node src/cli.ts
```

## Dependencies

- `openai` - OpenAI SDK
- `node-pty` - PTY support (interactive commands)
- `inquirer` - Interactive CLI
- `chalk` - Colored output
- `uuid` - Temporary file naming
- `commander` - CLI framework
- `gray-matter` - Markdown frontmatter parsing
- `fs-extra` - Enhanced file system operations

## License

MIT