cli/cloud: prefer markdown over JSON in default content negotiation#22963
Conversation
|
are we sure that this is what we want? is this consistent with other tools? or are we doing something new here? |
|
ah I think I glossed completely over this important bit:
seems fine then, though I can imagine this being a bit surprising if we start adding markdown to more places. if this is primarily for registry, etc. then I think this is great. |
@pgavlin My thinking is that if an operation is declaring both markdown and json outputs, the markdown is going to be the preferred output for humans and agents. Right now it is only used by the registry APIs. If we want more control over this behavior in the future we can look into including an ordering in the spec or a setting that users could set in the CLI. |
3e5bf22 to
7819419
Compare
When `pulumi cloud api` runs without `--format`, prefer `text/markdown` if the operation's OpenAPI spec declares it; otherwise fall back to the op's primary response content type (still JSON for most endpoints). Endpoints that author both formats use markdown as a human/agent friendly rendering of the same data, so dumping JSON by default is rarely what the caller wants. `--format=json`, `--format=markdown`, and JSON-only endpoints are unchanged.
7819419 to
09de97f
Compare
|
yeah it's not clear to me whether or not MD is always preferable to JSON for agents--that's the one place I'm not sure here. I think for the registry it makes sense, but for other structured data I'm not confident. |
|
@fallimic @pgavlin It would be good to fix this soon, maybe by restricting the effect to just docs commands for now. Our help output (e.g. #22904) and other references to these features mention |
|
This PR has been shipped in release v3.243.0. |
## (2026-05-22) ### Features - [cli] Make the `pulumi project new -y` command write a minimal project file with no template [pulumi#22847](pulumi#22847) - [cli] Suggest `pulumi neo` in `pulumi preview` and `pulumi up` diagnostics output [pulumi#23326](pulumi#23326) - [sdk] Add `List` to the Go `plugin.Provider` interface, wired to the streaming `ResourceProvider.List` RPC [pulumi#23287](pulumi#23287) - [sdkgen] Reserve the package names 'pulumi' and 'input' for internal use [pulumi#23321](pulumi#23321) - [cli/cloud] Prefer text/markdown over JSON in `pulumi api` when an endpoint produces both [pulumi#22963](pulumi#22963) - [cli/do] Add resource support to `pulumi do` [pulumi#23215](pulumi#23215) - [cli/neo] Pressing Esc in `pulumi neo` now clears the input box when it has text; with an empty box, Esc still cancels the agent's current turn [pulumi#23299](pulumi#23299) - [cli/new] Alias `pulumi new` to `pulumi project new` [pulumi#23265](pulumi#23265) ### Bug Fixes - [cli] Require `--yes` to confirm `pulumi deployment cancel`, `pulumi stack schedule remove`, `pulumi org webhook remove`, and `pulumi stack webhook remove` when running non-interactively [pulumi#23264](pulumi#23264) - [pcl] Don't silently ignore `...` in function arguments [pulumi#23309](pulumi#23309) - [sdkgen/nodejs] Cache package references per-deployment in generated SDKs to fix concurrent inline programs [pulumi#23068](pulumi#23068) - [backend/service] Error out when setting up journaler fails [pulumi#22671](pulumi#22671) ### Miscellaneous - [cli/package] Update the `pulumi package add --agent` documentation hint to use `<type-token>` as the placeholder for the `/docs/...` URL [pulumi#23294](pulumi#23294) - [cli/plugin] Rename plugin ls to list and rm to remove [pulumi#23291](pulumi#23291)
Summary
When
pulumi cloud api <op>runs without an explicit--format, prefertext/markdownif the operation's OpenAPI spec declares it; otherwise fall back to the op's primary response content type (still JSON for most endpoints).Endpoints that author both
application/jsonandtext/markdowntypically write the markdown as a human / agent friendly rendering of the same data, so defaulting to JSON dumps a schema-shaped payload on the caller when the markdown is what they actually want.Closes #22958
Test plan
pkg/engine/lifecycletest- For all engine/protocol changes — N/A, CLI-only changepkg/testing/pulumi-test-language- For language protocol changes — N/Apkg/backend/display- For changes to the output renderers — N/Apkg/cmd/pulumi/cloud/api_test.gonow hasTestNegotiateAccept_DefaultPrefersMarkdown(op declares both → returnstext/markdown) andTestNegotiateAccept_DefaultFallsBackToJSON(markdown not declared → still JSON). Existing--format=json/--format=markdown/ invalid-format / unsupported-format tests are unchanged.Validation
make lint— cleanmake test_fast— passes forpkg/cmd/pulumi/cloud/...(fullmake test_fastnot run locally)make tidy_fix— cleanmake format— clean (rangofumpt -won the two touched files; no rewrites)make check_proto— clean (if proto changes) — N/A, no proto changesChangelog
changelog/pending/20260511--cli-cloud--prefer-markdown-when-endpoint-produces-both.yamlRisk
Low blast radius.
--formatflag values and their meanings are unchanged. The only user-visible difference is the defaultAcceptheader sent on behalf of endpoints that declare both content types.Acceptvalue (application/vnd.pulumi+N) advertising CLI capability is still sent unchanged. The Pulumi Cloud service must already handleAccept: text/markdowncorrectly for these endpoints (it's why they declare it in the spec); if it does not, those endpoints would already break under--format=markdowntoday.🤖 Generated with Claude Code