agent-ssh 0.4.1

Arrange agent terminal layouts and reconnect through provider attachment plans
Documentation
# Agent attachment and terminal layout ownership

The terminal consumer and managed Pulse producer are released. Pulse Agents also implements the managed Marshal adapter. The shared tmux correction replaces the earlier `libtmux` selection with the independent `tmux-session` package. Consumer migration and publication require the verification gates described below.

## Decision

Keep agent lifecycle, native conversation identity, coordination, and terminal presentation separate. Restore resolves attachment intent. It does not create replacement agents.

| Object | Authority | Stored reference |
| --- | --- | --- |
| Native conversation and history | Native harness | Destination, harness, native state scope, conversation ID |
| Managed agent | Pulse Agents control plane | Authority, API origin, managed agent ID |
| Execution resource | Execution provider or harness backend | Provider-owned recovery handle |
| Launch operation | Marshal launch service or Pulse operation service | Owner-qualified operation ID |
| Coordination participant | Marshal | Marshal participant ID |
| Terminal pane and layout | Terminal client | Client-local view and placement |

A lost Marshal presence row does not prove process exit. A stopped execution does not imply a lost conversation. Closing a pane never means stopping its agent.

## Source evidence

The original attachment review used these source revisions:

- [Pulse Agents main 018787f](https://github.com/ignition-is-go/pulse-agents/tree/018787fbbaac72507dcd83629f46ffe6d63ba18b).
- [Marshal main 31a746b](https://github.com/ignition-is-go/marshal/tree/31a746b520bc5c7e7eba7f17882421a577749a90).
- [Marshal launch PR head 67c2d75](https://github.com/ignition-is-go/marshal/tree/67c2d7534e80674bff11460329c68ecb22ff0e1f).

Pulse's `AGENTS.md`, `GOAL.md`, product specification, and taxonomy govern its managed product. The `terminal-anywhere` document is a draft. At the reviewed base, the CLI has private `Destination` and `HandoffPlan` types. It does not export the draft's native session references. Its remote Codex path refuses non-Unix workstations.

Marshal main has no launch crate. Its reviewed PR introduces daemon-owned launch records and worker-owning `LaunchBackend` implementations. Its `StartLaunch` request describes fresh work, not an existing native conversation. Its `Launched.attach` field is a human-readable shell string. A terminal client must not split that string into argv or invoke `StartLaunch` as a reconnect fallback.

## Dependency topology

```text
Pulse Agents ----+
Marshal --------+---- tmux-session ---- tmux
agent-ssh ------+

Pulse managed CLI producer ---- versioned resolution JSON ---- terminal client
             |                                                 |
             +---- agent-attachment-protocol leaf crate --------+
                                                               |
                                                        layout library

Marshal launch service ---- marshal-launch-pulse ---- Pulse managed API
```

All three applications consume the same independently versioned `tmux-session` package. It is maintained and released from [ignition-is-go/tmux-session](https://github.com/ignition-is-go/tmux-session). All three applications use its crates.io package. Marshal and Pulse depend on the library package, never on the agent-ssh binary or layout library. Native Windows builds exclude the Unix dependency and invoke the installed Unix consumer over SSH.

The library owns bounded tmux client execution, literal arguments, client and pane environment changes, observations, options, key bindings, guarded ownership operations, and attachment command construction. It has no dependency on another tmux library and introduces no helper protocol. Applications retain their names, credential policy, terminal profiles, harness selection, and transport.

Pulse separately implements Marshal's managed launch contract through a versioned process protocol. Pulse keeps provisioning, authentication, configured presets, workspaces, and durable agent identity. Marshal keeps live coordination and task delivery. The adapter does not expose arbitrary commands or inherit the native backend's Rust implementation types.

The rejected `libtmux` migration was behaviorally tested but failed the dependency selection gate. Its published API lacked pre-spawn environment removal required by Marshal. Carrying a fork would make upstream compatibility and publication our responsibility. A command-builder alternative left the shared execution and ownership mechanisms duplicated. These findings reopen the original low-level library design rather than justify per-consumer workarounds.

We own `tmux-session` compatibility, diagnostics, process cleanup, and releases. Its initial supported floor is tmux 3.4. The API is limited to the operations used by these consumers. Control mode, a session registry, a full tmux object model, and harness lifecycle policy are outside its scope.

Before cross-repository adoption, verify the crate against real private tmux servers and publish the reviewed package. Tests cover cold and existing-server credential removal, literal arguments and working directories, byte decoding, ownership mismatch and name reuse, deadlines, output limits, cancellation cleanup, diagnostic redaction, and inherited terminal attachment. Consumer tests additionally cover Pulse's pane discovery and terminal profiles, Marshal recovery and SSH helpers, and agent-ssh's Windows-to-Unix boundary. A missing capability reopens this decision before a workaround or fork is added.

The JSON contract permits independent releases and avoids importing private service dependencies into the terminal tool. The experimental `agent-attachment-protocol` leaf crate contains the existing references, resolution states, attachment plans, and validation. Both terminal and Pulse CLI consumers use crates.io version 0.1.0. The terminal repository also uses a versioned path dependency for local development. Pulse does not depend on the terminal binary or layout library. The `agent-ssh` library keeps layout planning and re-exports the protocol under its existing `attachment` path. The JSON schema and validation behavior are unchanged.

The source repository is private. Published protocol packages and CLI installs use crates.io. Pulse's other private service dependencies retain their own build-token policy.

The terminal client's trusted resolver process is an adapter boundary. It must observe, not launch. The client verifies the returned target against the saved target. It discards failed or malformed replies rather than converting them into a fresh start.

Pulse's first producer uses its existing managed action catalog. A ready plan invokes the installed Pulse Agents CLI's explicit `attach` command. Authentication and tokenized terminal endpoints remain inside that command. Plan export never requests a terminal URL or changes runtime lifecycle.

No second session registry, transcript projection, credential store, universal harness protocol, or worker supervisor is added.

## Intent and observations

A version 2 terminal layout stores ordered pane intent and a per-tab pane count. A provider-backed pane stores an exact reference and a trusted resolver invocation. Every restore obtains a new observation. It does not write observations or executable plans back into the layout.

The initial resolution protocol supports local process handoff only. A command can invoke an existing provider's SSH attachment implementation. That does not establish native SSH support on every platform. Browser and tunnel plans remain unsupported until a caller proves their requirements.

`configured_command` preserves explicitly configured legacy local or SSH invocations. It is not an agent-health observation. Such a command can resume work because the operator configured it to do so. The terminal tool cannot prove that arbitrary local programs are read-only or credential-free.

## Recovery policy

| Observation | Restore behavior |
| --- | --- |
| Attachable | Compile the provider's attachment invocation |
| Saved conversation requiring resume | Report `resume_required`; no automatic resume |
| Unreachable destination | Retain intent and report `unreachable` |
| Ownership conflict | Report conflict; do not take over |
| Uncertain launch or attachment | Report `uncertain`; owner reconciles it |
| Deleted agent | Retain reference and report `deleted` |
| Unsupported platform or capability | Report `unsupported` |
| Otherwise unavailable | Report the provider's reason without executable actions |

Default restore opens no terminals if any resolved pane is non-ready. Explicit partial restore opens ready panes and reports skips. Partial grids compress remaining entries. This behavior does not alter saved placement intent.

A ready observation is not a lease. The provider's attach command rechecks availability. A race may make attachment fail, but that failure cannot trigger creation or task replay.

## Scope of shared code

The attachment JSON contract and shared tmux implementation solve different problems. The contract communicates provider-owned attachment observations. `tmux-session` owns the repeated execution and terminal mechanisms. The earlier contract-only plan left those mechanisms in each consumer.

The shared crate is independent of the layout and attachment protocol packages. It provides no managed session authority. The provider remains behind its versioned attachment contract. Sharing tmux mechanics does not transfer lifecycle authority to terminal restore.

## Naming and distribution

Use **terminal layout** for tabs and panes. Pulse reserves **workspace** for filesystem context. The repository is `ignition-is-go/agent-ssh`. Use the `agent-ssh` command. The shared protocol is published as an experimental 0.1 crate; it carries no stable API promise.

A future presentation-only binary may use a grid-oriented name. A future general session manager belongs with Pulse's native-session workflow. Naming and public release follow the acceptance gates in [the acceptance record](acceptance.md).

## Version 3 captured layouts (0.3.8)

The default all-or-nothing and compressed partial-grid rules above describe version 1/2 provider layouts. Captured version 3 layouts preserve their exact tree: unavailable or already-running targets become labelled shell placeholders while available targets recover. Save reports gaps without failing after a successful write. Direct remote Marshal Codex launchers have verified native recovery references, including exact conversation UUID and cwd; cold recovery invokes the deployed managed-launch helper, and observed live interfaces are never duplicated. See the README for lifecycle limits.