Skip to content

feat(cmd): add JSON result envelope on stdout for up/build/exec - #199

Merged
skevetter merged 2 commits into
mainfrom
d40a-e90f-devsy-022-json-envelope
May 4, 2026
Merged

feat(cmd): add JSON result envelope on stdout for up/build/exec#199
skevetter merged 2 commits into
mainfrom
d40a-e90f-devsy-022-json-envelope

Conversation

@skevetter

@skevetterskevetter commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds structured JSON result output to up, build, and exec commands matching the official devcontainer CLI envelope format ({"outcome":"success","containerId":"...","remoteUser":"...","remoteWorkspaceFolder":"..."}).

  • up and build emit the envelope to stdout on success (error envelope on failure)
  • exec emits to stderr since stdout is reserved for the executed command's output
  • Includes unit tests for envelope marshaling with edge cases

Summary by CodeRabbit

Release Notes

  • New Features

    • CLI commands now output structured JSON responses, including container ID, remote user, and workspace information on success and detailed error messages on failure, enabling better programmatic integration and automation.
  • Tests

    • Added comprehensive test coverage for JSON output formatting and validation.

Emit a structured JSON envelope matching the official devcontainer CLI
format after successful command execution. The `up` and `build` commands
write to stdout; `exec` writes to stderr since stdout belongs to the
executed command's output.
@netlify

netlifyBot commented May 4, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

NameLink
🔨 Latest commit9e9103c
🔍 Latest deploy loghttps://app.netlify.com/projects/devsydev/deploys/69f850a26aa2a7000925386f

@coderabbitai

coderabbitaiBot commented May 4, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad01a959-cac8-49ab-8737-97abb559061a

📥 Commits

Reviewing files that changed from the base of the PR and between d396b6b and 9e9103c.

📒 Files selected for processing (5)
  • cmd/build.go
  • cmd/exec.go
  • cmd/up.go
  • pkg/devcontainer/config/envelope.go
  • pkg/devcontainer/config/envelope_test.go

📝 Walkthrough

Walkthrough

The PR introduces standardized JSON output envelopes for structured success and error responses across multiple CLI commands. A new envelope.go file defines the envelope types and JSON writer helpers, which are then integrated into the build, exec, and up command handlers to emit structured results to their respective output streams.

Changes

JSON Output Envelope System

Layer / File(s)Summary
Data Shape
pkg/devcontainer/config/envelope.go
New ResultEnvelope struct with Outcome, ContainerID, RemoteUser, and RemoteWorkspaceFolder fields; new ErrorEnvelope struct with Outcome and Message fields.
Core Implementation
pkg/devcontainer/config/envelope.go
WriteResultJSON marshals a success envelope and writes it with trailing newline; WriteErrorJSON marshals an error envelope and writes it with trailing newline. Both return any JSON marshal or I/O errors.
Command Integration
cmd/build.go, cmd/exec.go, cmd/up.go
Each command now captures execution results and errors, then calls the appropriate envelope writer to emit JSON to os.Stdout (build, up) or os.Stderr (exec) before returning. Success paths extract containerID, remoteUser, and workdir from execution context.
Tests & Verification
pkg/devcontainer/config/envelope_test.go
Table-driven tests validate WriteResultJSON and WriteErrorJSON output structure, JSON parseability, field values, newline termination, and single-line formatting.

Sequence Diagram

sequenceDiagram
participant User
participant Command as Build/Exec/Up Command
participant Executor as Execution Handler
participant Envelope as JSON Envelope Writer
participant Output as os.Stdout/stderr
User->>Command: Execute command with args
Command->>Executor: Execute (BuildAgent, execInContainer, etc.)
alt Execution succeeds
Executor-->>Command: result, nil
Command->>Command: Extract containerID, user, workdir
Command->>Envelope: WriteResultJSON(output, containerID, user, workdir)
Envelope->>Envelope: Marshal ResultEnvelope{Outcome: "success", ...}
Envelope->>Output: Write JSON + newline
Envelope-->>Command: nil
Command-->>User: success
else Execution fails
Executor-->>Command: nil, error
Command->>Envelope: WriteErrorJSON(output, error.Error())
Envelope->>Envelope: Marshal ErrorEnvelope{Outcome: "error", Message: msg}
Envelope->>Output: Write JSON + newline
Envelope-->>Command: error
Command-->>User: error
end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Move WriteResultJSON in up command to after configureWorkspace and
openIDE succeed, preventing contradictory success output on non-zero
exit. Add error envelopes for configureWorkspace and openIDE failures.
@skevetter
skevetter marked this pull request as ready for review May 4, 2026 09:03
@skevetter
skevetter merged commit 75cec78 into mainMay 4, 2026
54 checks passed
@skevetter
skevetter deleted the d40a-e90f-devsy-022-json-envelope branch May 4, 2026 09:03
This was referenced May 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@skevetter