# agent-ssh
Arrange agent terminal layouts and reconnect through provider attachment plans. `agent-ssh` is the command. The repository is `ignition-is-go/agent-ssh`.
See [the experimental attachment contract](docs/attachment-contract.md) for version 2 terminal layouts, provider resolution, and machine-readable restore plans.
## Legacy layouts and recovery
```powershell
# Save selected SSH hosts without opening terminals.
agent-ssh --group production --save-workspace production.json --panes-per-tab 4
# Restore saved attach/resume commands in four-pane grids.
agent-ssh --restore production.json --window agents
agent-ssh --restore production.json --panes-per-tab 4 --dry-run
# Regroup 16 EXISTING single-pane tabs, beginning at tab zero.
agent-ssh --regroup 16 --window agents
```
`--regroup` moves existing panes without starting or stopping their processes. Run it only against the specified number of single-pane tabs; it is not idempotent. `--first-tab` selects a zero-based starting tab. Terminal chooses split direction when moving existing panes; restoring a workspace explicitly builds balanced grids. Existing tabs outside the selected range remain in place.
`--restore` opens new terminal interfaces. Remote attach commands should reconnect to an existing `tmux` session; local Codex commands should use an explicit thread ID. Repeating restore can create duplicate interfaces, especially for local agents. A saved workspace retains commands and layout, not process memory or in-flight command state. Restoring does not stop an already-open interface or take over a conversation lock.
Workspace JSON uses version 1, an ordered pane list, and a per-tab pane count:
```json
{
"version": 1,
"panes_per_tab": 4,
"panes": [
{
"title": "remote agent",
"command": ["ssh.exe", "-t", "pulse-admin", "/root/.local/share/agent-sessions/open-agent.sh"]
},
{
"title": "local agent",
"cwd": "C:\\Work Projects",
"command": ["codex.cmd", "resume", "EXPLICIT-THREAD-ID"]
}
]
}
```
Each pane may specify a Windows Terminal `profile`. Commands are argument arrays, not shell strings. Use only trusted workspace files: restoring executes their commands. Semicolons and line breaks in pane fields are rejected because Windows Terminal interprets semicolons as action separators. Saving to an existing filename is refused. `--save-workspace` saves selected SSH destinations, not automatic discovery of active agent IDs; provide explicit resume/attach commands for agent recovery.
See [Marshal integration](docs/marshal-integration.md) for the boundary with the work-in-progress `LaunchBackend` API.
`agent-ssh` opens SSH aliases from `~/.ssh/config` as balanced pane grids or tabs in Windows Terminal. Groups and colors are declared with comments:
```ssh-config
# @group production #E57000
Host app-one
HostName app-one.example.com
Host app-two
HostName app-two.example.com
User deploy
```
## Install
```powershell
cargo install agent-ssh --locked
agent-ssh --sync
```
To install from a source checkout, run `cargo install --path . --force`.
Restart Windows Terminal after the initial sync.
## Usage
```text
agent-ssh --group production
agent-ssh --group production --new-window
agent-ssh --group development --tabs
agent-ssh --group production --command uptime
agent-ssh --list
agent-ssh --sync
agent-ssh --group production --dry-run
```
Inside a grid, Windows Terminal's `Alt+Shift+B` toggles broadcast input, `Alt+Shift+Z` zooms the focused pane, and `Alt+Arrow` moves focus.
## Releases
Push a semantic-version tag matching `Cargo.toml` to create a GitHub Release:
```powershell
git tag v0.2.1
git push origin v0.2.1
```
The release workflow verifies the version, runs the full quality suite, builds the Windows executable, and publishes a ZIP plus a SHA-256 checksum.
Publish the shared dependency before the terminal crate:
```powershell
cargo publish -p agent-attachment-protocol
cargo publish -p agent-ssh
```
## Inspect provider-backed layouts
Version 2 layouts retain references and resolve their attachment plans on every restore. Use the provider on the same host as the terminal consumer. A remote producer's local executable path is not a local Windows executable.
```powershell
agent-ssh --restore my-layout.json --window agents --plan
agent-ssh --restore my-layout.json --window agents
agent-ssh --restore my-layout.json --window agents --allow-partial
```
Default restore blocks if a provider cannot attach every referenced agent. Partial restore is explicit. Neither mode starts replacement agents or replays prompts. See the [ownership decision](docs/architecture.md) and [acceptance record](docs/acceptance.md).
To convert a version 1 recovery file, use the migration tool. It compares both files through the actual CLI before writing and refuses to overwrite an existing destination.
```powershell
python scripts/migrate_layout.py old-layout.json terminal-layout.json --binary agent-ssh
```
The Pulse Agents `attachment-plan` and `attach` commands are companion source changes. Until that provider version is installed, provider-backed layouts cannot use those commands. Existing configured SSH and local recovery commands remain supported.