Skip to content

feat(runtime): stream binary responses to stdout or files #121

Description

@samzong

Problem

Generated commands can receive binary responses, but pkg/runtime/client.go::doRawFullOnce always buffers the full body in memory. The output path then treats the result like ordinary formatter input; users must know to select raw output, and large downloads remain fully buffered.

This makes generated commands unsuitable for large artifacts and can corrupt terminal output when a binary response is handled through a text-oriented default formatter.

Proposal

Provide an explicit binary-response execution path based on the declared response media type or schema format.

  • Stream successful response bytes directly to an explicitly selected file or stdout.
  • Keep non-2xx bodies in the normal bounded error path.
  • Avoid writing binary bytes to an interactive terminal without explicit user intent.
  • Define overwrite behavior and never silently replace an existing file.
  • Close partial files safely on cancellation or read failure.

Binary request bodies already work through --file; this issue is limited to response handling and avoiding full-response buffering.

Alternatives considered

-o raw preserves bytes but still buffers the complete response and does not provide safe file ownership or terminal behavior.

Acceptance criteria

  • A large test response is copied without retaining the complete body in memory.
  • stdout and file destinations preserve byte-for-byte content.
  • Cancellation closes the response and leaves no successful-looking partial artifact.
  • Existing JSON/table/yaml/raw behavior remains unchanged for non-binary responses.
  • Catalog and generated Skill metadata explain the required output mode.

Affected surface

Runtime HTTP/auth/body/output behavior; command catalog; generated Skill docs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions