Skip to content

Commit f4785f4

Browse files
committed
sim-cli: --output json prints the API data verbatim; the single-key unwrap stays a table-only convenience
1 parent 6e5c4b9 commit f4785f4

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

packages/sim-cli/src/commands/protocol/workflow-run-wait.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ function optionalString(value: unknown): string | null {
101101
* record — what a self-hosted deployment behind an unwrapping proxy hands back —
102102
* still polls, rather than refusing to find a status that is right there.
103103
*/
104+
/** The run itself: v2 answers `{ data: run }` and the renderer prints exactly what it is handed. */
105+
function runData(raw: unknown): unknown {
106+
return isRecord(raw) && isRecord(raw.data) ? raw.data : raw
107+
}
108+
104109
function readRun(raw: unknown): RunSnapshot {
105110
const run = isRecord(raw) && isRecord(raw.data) ? raw.data : raw
106111
if (!isRecord(run) || typeof run.status !== 'string') {
@@ -254,7 +259,7 @@ export function attachWorkflowRunWait(runs: Command): void {
254259

255260
if (outcome) {
256261
progress.finish()
257-
renderResult('getWorkflowRun', profile.output, raw, runSpec())
262+
renderResult('getWorkflowRun', profile.output, runData(raw), runSpec())
258263
const message = explain(outcome, runId, options.workflow, snapshot)
259264
if (message) console.error(chalk.red(message))
260265
setSoftExitCode(WAIT_EXIT_CODES[outcome])
@@ -264,7 +269,7 @@ export function attachWorkflowRunWait(runs: Command): void {
264269
const remainingMs = deadline - Date.now()
265270
if (remainingMs <= 0) {
266271
progress.finish()
267-
renderResult('getWorkflowRun', profile.output, raw, runSpec())
272+
renderResult('getWorkflowRun', profile.output, runData(raw), runSpec())
268273
console.error(
269274
chalk.red(
270275
`Timed out after ${timeoutSeconds}s waiting for run ${runId} (status: ${snapshot.status}${

packages/sim-cli/src/runtime/build.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,30 @@ describe('single-resource rendering', () => {
10441044
expect(printed.join('\n')).toMatch(/Deepwiki/)
10451045
})
10461046

1047+
it('prints the API data verbatim for machine output, envelope included', async () => {
1048+
// `--output json` is what scripts and the agent reference card (generated from the
1049+
// OpenAPI response shapes) consume: the single-key unwrap above is a table-only
1050+
// convenience, so JSON keeps `mcpServer` exactly as the API returned it.
1051+
const printed = await lines(
1052+
[
1053+
'mcp-servers',
1054+
'create',
1055+
'--name',
1056+
'Deepwiki',
1057+
'--transport',
1058+
'streamable-http',
1059+
'--url',
1060+
'https://mcp.deepwiki.com/mcp',
1061+
],
1062+
{ mcpServer: { id: 'mcp-1', name: 'Deepwiki', enabled: true } },
1063+
'json'
1064+
)
1065+
1066+
expect(JSON.parse(printed.join('\n'))).toEqual({
1067+
mcpServer: { id: 'mcp-1', name: 'Deepwiki', enabled: true },
1068+
})
1069+
})
1070+
10471071
it('renders nested fields instead of dropping them', async () => {
10481072
// `workflows export` printed `version` and `exportedAt` and nothing else:
10491073
// the record builder kept only scalars, so `workflow` and `state` — the

packages/sim-cli/src/runtime/result.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ export function renderResult(
458458
return
459459
}
460460

461-
const data = unwrapResource(raw)
461+
// The single-key unwrap exists for the human table: `{ mcpServer: {...} }` rendered as-is
462+
// printed nothing. Machine formats print the API's data verbatim, so `--output json`
463+
// matches the OpenAPI shape the docs and the agent reference card are generated from.
464+
const data = format === 'json' || format === 'yaml' ? raw : unwrapResource(raw)
462465
if (spec.itemsPath) {
463466
const items = at(data, spec.itemsPath)
464467
if (!Array.isArray(items)) {

0 commit comments

Comments
 (0)