This file provides guidance to AI agents when working with code in this repository.
- Build:
make build- Compiles the gosh binary tobuild/gosh - Test:
make test- Runs unit tests withgo test -v ./... - Test with race detection:
make test-race- Runs tests with race detection enabled - Lint:
make lint- Runs golangci-lint with auto-fix enabled - Integration tests:
make test-integration- Builds and runs integration tests viatest_integration.sh - Clean:
make clean- Removes build artifacts - Full build:
make all- Runs test, lint, and build in sequence
Always run make after making code changes to ensure code quality and stability.
gosh is a Go-based SSH session manager that executes commands across multiple hosts in parallel. The main application is in cmd/main.go with core functionality in the pkg/ directory and supporting tests in pkg/main_test.go.
Command Execution Flow:
main()- Parses CLI flags using spf13/pflag libraryExecuteCommand()- Orchestrates parallel SSH execution using goroutines and sync.WaitGroupRunSSH()- Handles individual SSH connections usingsshcommand with timeout and batch modeFormatHost()- Creates colored output prefixes for host identification
Interactive Mode:
InteractiveMode()- Provides a REPL-like interface for running commands- Built-in commands:
help,exit/quit - All other input is treated as SSH commands to execute on all hosts
Output Management:
- Uses ANSI color codes for host differentiation (16 predefined colors)
- Supports
--no-colorflag to disable colored output - Each host's output is prefixed with colored/formatted hostname
- Uses system
sshcommand with connection timeout of 5 seconds - Enables batch mode (
BatchMode=yes) for non-interactive operation - Supports custom usernames via
-u/--userflag - All SSH connections run in parallel using goroutines
- Unit tests in
pkg/main_test.gofor utility functions (MaxLen,FormatHost) - Integration tests in
test_integration.shrequire.envfile withTEST_HOSTSconfiguration - Integration tests validate real SSH connections and command execution
- Test keys for local SSH server testing are auto-generated via
//go:generate(rungo generate ./pkgto create them) - Generated test keys are stored in
pkg/test_keys/and excluded from git via.gitignore
Integration tests require a .env file (copy from .env.example) with:
TEST_HOSTS- Space-separated list of hostnames/IPs for testingTEST_SSH_USER- Optional SSH username for testsTEST_SSH_TIMEOUT- SSH timeout in seconds (default: 5)
- GitHub Actions workflow tests on Go 1.24.x and 1.25.x
- Cross-platform builds for Linux, macOS, and Windows (amd64)
- Comprehensive golangci-lint configuration with 40+ enabled linters