agent-ssh 0.3.4

Arrange agent terminal layouts and reconnect through provider attachment plans
Documentation
# Terminal attachment contract


This is an experimental JSON boundary between a trusted attachment provider and the terminal client. The experimental `agent-attachment-protocol` crate owns references, observations, attachment plans, and validation. The `agent-ssh` library owns layout planning and re-exports the protocol as `agent_ssh::attachment`. Neither crate owns agent processes, transcripts, launch records, discovery, credentials, or replacement policy.

## Inspect a restore


```powershell
agent-ssh --restore agents.json --window agents --plan
agent-ssh --restore agents.json --window agents --dry-run
```

Both commands resolve each provider entry again. Neither opens Windows Terminal. `--plan` returns JSON with pane observations, skipped count, a blocked flag, and terminal arguments. It exits successfully when inspection succeeds, even if the plan is blocked. A blocked plan has no terminal arguments.

Ordinary restore opens no terminals if any entry is non-ready. `--allow-partial` explicitly opens only ready entries. It compresses the ready entries into grids without altering the saved layout. Non-ready handling never invokes a fallback launch, resume, prompt, or ownership takeover. An executable attachment plan or configured command still performs the behavior specified by its trusted provider or author.

## Save layout intent


Version 2 stores an ordered pane list, a per-tab count, and explicit attachment intent. A resolved pane names its expected target and a trusted read-only resolver process. The process reads no stdin and emits one resolution object on stdout.

```json
{
  "version": 2,
  "panes_per_tab": 4,
  "panes": [
    {
      "title": "Build agent",
      "attachment": {
        "kind": "resolved",
        "target": {
          "kind": "managed",
          "authority": "pulse-agents",
          "origin": "https://agents.example",
          "agent_id": "agent-1"
        },
        "resolver": {
          "program": "pulse-agents.exe",
          "args": ["--url", "https://agents.example", "attachment-plan", "agent-1"]
        }
      }
    }
  ]
}
```

This example requires a provider implementing `attachment-plan`. The resolver command itself is trusted local configuration. The client does not sandbox it or prove that arbitrary configured code is read-only.

A `configured_command` attachment instead has `command` as an argv array. This preserves existing local and SSH recovery helpers. It makes no discovery, process-health, ownership, or version-compatibility claim. These commands execute only during an actual restore. An explicitly configured `codex resume THREAD_ID` remains permitted. Keep credentials out of command arguments and layout files.

`--save-layout` saves selected SSH destinations as version 2 configured commands. `--save-workspace` retains its version 1 output for existing callers. Both versions restore through the same compiler. Saving refuses to overwrite an existing file. `TerminalLayout::from_legacy` converts a validated version 1 object into version 2 without changing its launch arguments.

## Provider resolution


A ready resolution contains its exact target and one local attachment invocation.

```json
{
  "version": 1,
  "target": {
    "kind": "managed",
    "authority": "pulse-agents",
    "origin": "https://agents.example",
    "agent_id": "agent-1"
  },
  "observation": {
    "state": "attachable",
    "plan": {
      "kind": "local_process",
      "program": "pulse-agents.exe",
      "args": ["--url", "https://agents.example", "attach", "agent-1"]
    }
  }
}
```

Only `attachable` contains a plan. The other states are `resume_required`, `unreachable`, `ownership_conflict`, `uncertain`, `deleted`, `unsupported`, and `unavailable`. Each contains a reason and no plan. The consumer rejects extra fields, unknown variants, unsupported versions, mismatched targets, invalid managed origins, and Terminal action separators or control characters in executable arguments.

Managed origins permit HTTP or HTTPS and a base path. They reject user information, passwords, query strings, and fragments. Plans have no environment map or credential fields. Providers must keep bearer material and tokenized endpoints inside their own authenticated attachment implementation. Arbitrary argv cannot be automatically classified as secret-free.

The prototype native reference preserves `destination`, `harness`, `state_scope`, and `conversation_id`. Destination distinguishes local execution from an SSH target. This schema does not add a native resolver or imply that every harness and platform supports remote attachment. Browser and tunnel plans are not supported in this initial version.

## Resolver limits and failure behavior


A resolver has ten seconds and at most 1 MiB of stdout. Its stderr is discarded and never included in the plan. Invalid output, process failure, timeout, and target mismatch become `uncertain`, with no executable plan. Human-readable diagnostics discard control characters and are limited to 4096 characters.

The timeout kills and reaps the direct provider child. It does not contain arbitrary descendants. Trusted providers must not leave background workers or inherit stdout into long-lived processes. Provider-specific launch or stop logic belongs outside this contract.

## Verify the consumer


```text
cargo test --all-features --locked
cargo clippy --all-targets --all-features --locked -- -D warnings
```

The integration suite invokes the actual CLI with read-only fixture producers on Windows. It verifies every non-ready state, fresh resolution, mismatched responses, partial plans, legacy migration, overwrite refusal, process timeout, and output limits. These fixtures do not establish production managed-agent attachment, native discovery, active-turn survival, pending approval recovery, or Codex client/server compatibility.