How msh-protocol/msh works
msh is a safety-focused command-execution runtime for AI agents, with CLI, HTTP, MCP, and SDK entry points. The principal workflow accepts a command, executes it through a session-aware runtime, and returns structured, sanitized output; supported capabilities include prompt handling, secret redaction, truncation, file-change tracking, rollback, and run verification. A separate fleet hub registers worker daemons, relays commands and streams, and provides a telemetry dashboard. Some subsystem wiring is based on README capabilities and the file tree because those implementations were not sampled.
Main entry points: executor.go Command executor · fleet/server.go Fleet hub · main.go CLI commands · server/server.go HTTP server
Components 25
Agent interfaces
- CLI commands
cmd/msh/main.go - Python client
packages/python/msh/client.py - TypeScript client
packages/typescript/src/index.ts - MCP server
pkg/mcp/server.go - HTTP server
pkg/server/server.go
Execution runtime
- Session manager
pkg/execution/manager.go - Command executor
pkg/execution/executor.go - Execution engines
pkg/execution/engine.go - Prompt handling
pkg/execution/prompt_responder.go - Output protection
pkg/sanitize/sanitize.go - Error extraction
pkg/sanitize/error_extractor.go - Change tracking
pkg/fs/watcher.go - Execution hooks
pkg/hooks/hooks.go
Run history and recovery
- Execution history
pkg/db/db.go - Undo command
cmd/msh/undo.go - Diff rollback
pkg/fs/rollback.go - Run verification
pkg/execution/verify.go
Fleet control plane
- Fleet command
cmd/msh/fleet.go - Fleet hub
pkg/fleet/server.go - Worker daemon
pkg/fleet/node.go - Background processes
pkg/daemon/manager.go - Fleet dashboard
fleet-ui/src/App.tsx
Other components
- Agent or user
- Worker machines
- Command workspace
Connections 30
- Agent or user → CLI commands: runs commands
- Agent or user → Python client: calls client
- Agent or user → TypeScript client: calls client
- Agent or user → MCP server: invokes tool
- Python client → CLI commands: runs CLI
- Python client → HTTP server: posts commands
- TypeScript client → HTTP server: posts commands
- CLI commands → Command executor: executes
- MCP server → Session manager: gets session
- MCP server → Command executor: executes
- HTTP server → Session manager: gets session
- HTTP server → Command executor: executes
- Session manager → Command executor: provides session
- Command executor → Execution engines: runs command
- Execution engines → Command workspace: executes in
- Command executor → Prompt handling: handles prompts
- Command executor → Output protection: sanitizes output
- Command executor → Error extraction: extracts causes
- Command executor → Change tracking: tracks changes
- Command executor → Execution hooks: runs hooks
- CLI commands → Execution history: saves execution
- Fleet hub → Execution history: stores history
- Undo command → Diff rollback: reverts changes
- Run verification → Execution history: reads run record
- Fleet command → Fleet hub: starts hub
- Fleet dashboard → Fleet hub: calls APIs
- Fleet hub → Worker daemon: registers and relays
- Worker daemon → Fleet hub: streams results
- Worker machines → Worker daemon: connects
- Fleet hub → Background processes: manages daemons