Skip to content

feat(shell): add /sh shell command execution and persistent shell mode#47

Open
yuanguangshan wants to merge 1 commit intofastclaw-ai:mainfrom
yuanguangshan:feat/shell-mode
Open

feat(shell): add /sh shell command execution and persistent shell mode#47
yuanguangshan wants to merge 1 commit intofastclaw-ai:mainfrom
yuanguangshan:feat/shell-mode

Conversation

@yuanguangshan
Copy link
Copy Markdown

Add WeChat-accessible shell command interface via /sh and /$ commands.

Features

/sh — Single command execution

  • Execute read-only shell commands directly from WeChat
  • Usage: /sh ls -la, /sh cat README.md
  • /$ <cmd> is an alias

/sh — Persistent shell mode

  • Enter interactive shell mode with persistent working directory
  • Type commands without prefix (like a real terminal)
  • Exit with /q
  • Prompt displays current path: /path/to/dir:#
  • Auto-runs ls after each cd

Security — defense in depth

  • Command whitelist: only safe read-only commands allowed (ls, pwd, cd, cat, head, tail, grep, find, wc, du, df, file, stat, date, echo, basename, dirname, realpath, readlink, which, tree, nl, sort, uniq, cut, awk, sed, tr, xargs)
  • Operator blacklist: blocks |, >, &&, ||, ;, `````, $(
  • Symlink escape protection: resolves symlinks before cd
  • Sandbox support: optional baseDir restriction per session
  • File size guard: cat files > 50KB are rejected with tips

UX polish

  • Shortcut aliases: llls -lh, ..cd .., ...cd ../..
  • Auto-enhance ls with -C (column layout) flag
  • ANSI escape code stripping for clean WeChat display
  • Output truncation at 4000 chars (WeChat message limit)
  • Markdown code block wrapping for monospace rendering

Files changed

  • messaging/handler.go: shell mode state, routing, handleShell, enterShellMode, handleShellWithState, cleanANSI, helpers
  • docs/shell-mode-guide.md: full user guide with examples

Add WeChat-accessible shell command interface via /sh and /$ commands.

## Features

### /sh <cmd> — Single command execution
- Execute read-only shell commands directly from WeChat
- Usage: `/sh ls -la`, `/sh cat README.md`
- `/$ <cmd>` is an alias

### /sh — Persistent shell mode
- Enter interactive shell mode with persistent working directory
- Type commands without prefix (like a real terminal)
- Exit with `/q`
- Prompt displays current path: `/path/to/dir:#`
- Auto-runs `ls` after each `cd`

### Security — defense in depth
- **Command whitelist**: only safe read-only commands allowed
  (ls, pwd, cd, cat, head, tail, grep, find, wc, du, df, file, stat,
   date, echo, basename, dirname, realpath, readlink, which, tree,
   nl, sort, uniq, cut, awk, sed, tr, xargs)
- **Operator blacklist**: blocks `|`, `>`, `&&`, `||`, `;`, `````, `$(`
- **Symlink escape protection**: resolves symlinks before cd
- **Sandbox support**: optional baseDir restriction per session
- **File size guard**: cat files > 50KB are rejected with tips

### UX polish
- Shortcut aliases: `ll` → `ls -lh`, `..` → `cd ..`, `...` → `cd ../..`
- Auto-enhance `ls` with `-C` (column layout) flag
- ANSI escape code stripping for clean WeChat display
- Output truncation at 4000 chars (WeChat message limit)
- Markdown code block wrapping for monospace rendering

## Files changed
- `messaging/handler.go`: shell mode state, routing, handleShell,
  enterShellMode, handleShellWithState, cleanANSI, helpers
- `docs/shell-mode-guide.md`: full user guide with examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant