Skip to content

Add amika send and amika sessions commands - #320

Open
jdc123 wants to merge 2 commits into
mainfrom
agent-send-cli
Open

Add amika send and amika sessions commands#320
jdc123 wants to merge 2 commits into
mainfrom
agent-send-cli

Conversation

@jdc123

@jdc123 jdc123 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What

Adds the CLI half of the agent-sessions feature: a one-shot amika send and a sessions browser, driving the new remote agent-sessions API.

  • amika send [message] — send a message to a coding agent. With neither --session-id nor --sandbox, a sandbox is created behind the scenes and a new chat starts; the returned session_id continues it next time. Agent from --agent (claude|codex), else the org default, else claude. Message from a positional arg or stdin. Synchronous — prints the reply. Flags: --agent, --session-id, --sandbox, --new-session, --repo. In text mode session_id/created-sandbox notes go to stderr so stdout stays the pure response; --output json emits the AgentSessionSendResponse verbatim.
  • amika sessions list / amika sessions show <id> — browse the durable chats those sends create (backed by GET /agent-sessions).
  • API client: SendAgentSession, ListAgentSessions, GetAgentSession + mirror types. SendAgentSession uses the same 10-minute timeout as the existing synchronous agent-send.

Server dependency

Requires the agent-sessions endpoint in amika-mono (gofixpoint/amika-mono#866). The client structs are hand-maintained mirrors of that API's OpenAPI schema, matching how the rest of apiclient works.

Testing

  • httptest coverage of the three client methods: request method/path/body, full response parsing, nullable sandbox_id/agent, []-not-null list, and id path-escaping.
  • Command tests: send/sessions registration + flags, message-required, and --output validation.
  • make fmtcheck vet lint and go test ./internal/apiclient/... ./cmd/amika/... pass; the CLI builds (make build-cli).

Streaming (update)

amika send now streams the reply in real time via the new
POST /agent-sessions/stream SSE endpoint (amika-mono#915), instead of
blocking on the whole message.

  • API client: SendAgentSessionStream(req, handlers) POSTs with
    Accept: text/event-stream, forwards status (sandbox lifecycle) and
    delta (agent text) frames to callbacks as they arrive, and returns the
    terminal done frame — the same AgentSessionSendResponse the buffered
    SendAgentSession returns. A mid-stream error frame, or a stream that
    ends without done, becomes an error; auth/validation failures arrive as a
    JSON error before the stream opens and are surfaced like the buffered path.
  • amika send --stream: streams by default when stdout is a terminal;
    buffers when stdout is piped (so a captured pipe stays the single final
    response, not the concatenated deltas) and always for --output json (which
    must stay one valid object). --stream / --stream=false forces either
    mode. Sandbox progress + session_id go to stderr; only agent text goes to
    stdout, matching the buffered path. Buffered SendAgentSession is unchanged.

The --session-id returned by either mode continues the chat as before.

Testing (streaming)

  • httptest SSE coverage of SendAgentSessionStream: in-order status/delta
    dispatch + done parsing (and Accept/method/path), an error frame → error,
    a stream with no done → error, and a pre-stream 4xx → error.
  • send command test now also asserts the --stream flag is registered.

Note: the streaming code was added in an environment without a Go toolchain,
so it was hand-verified (tab-clean, imports checked) rather than compiled
locally — CI (make fmtcheck vet lint + go test) is the gate.

Add a top-level `send` command that drives the remote agent-sessions API:
it sends a message to a coding agent, creating a sandbox behind the scenes
when the chat has none, or continuing an existing chat (`--session-id`) or
routing into a specific sandbox (`--sandbox`). The agent is picked by
`--agent`, else the org default, else `claude`. The message comes from a
positional arg or stdin; the call is synchronous and prints the reply
(with `session_id`/created-sandbox notes on stderr so stdout stays the pure
response, or a single JSON object under `--output json`).

Add a `sessions` group (`list`, `show <id>`) to browse the durable chats
those sends create, backed by the new `GET /agent-sessions` endpoints.

Extend the API client with `SendAgentSession`, `ListAgentSessions`, and
`GetAgentSession` (plus their request/response mirror types). `SendAgentSession`
uses the 10-minute timeout the synchronous agent-send path already uses.

Tested: httptest coverage of the three client methods (request shape,
response parsing, nullable fields, id path-escaping) and command-level tests
for registration, flags, message-required, and `--output` validation.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

The agent-sessions endpoint now offers a streaming transport
(`POST /agent-sessions/stream`), so `amika send` no longer has to block
on the whole reply before showing anything.

- `apiclient.SendAgentSessionStream` POSTs to the stream endpoint with
  `Accept: text/event-stream`, forwards `status` and `delta` frames to
  handler callbacks as they arrive, and returns the terminal `done`
  frame — the same `AgentSessionSendResponse` the buffered call returns.
  A mid-stream `error` frame (or a stream that ends without `done`)
  becomes an error; auth/validation failures arrive as a JSON error
  before the stream opens and are surfaced like the buffered path.
- `amika send` streams by default when stdout is a terminal and buffers
  when piped (so a captured pipe stays the single final response) or
  when `--output json` is set (which must stay one valid object).
  `--stream` / `--stream=false` overrides the default. Sandbox
  lifecycle progress and the session id go to stderr; only the agent's
  text goes to stdout, matching the buffered path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant