diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index 767630e7737..258c6667d41 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -1558,7 +1558,10 @@ for that specific session. - **Values:** - `text`: (Default) The standard human-readable output. - `json`: A machine-readable JSON output. - - `stream-json`: A streaming JSON output that emits real-time events. + - `stream-json`: A streaming JSON output that emits real-time JSONL events. + Event types include: `init`, `message`, `thinking`, `tool_use`, + `tool_result`, `error`, and `result`. The `thinking` event exposes model + reasoning from thinking-capable models (for example, Gemini 2.5 Pro). - **Note:** For structured output and scripting, use the `--output-format json` or `--output-format stream-json` flag. - **`--sandbox`** (**`-s`**): diff --git a/packages/cli/src/nonInteractiveCli.ts b/packages/cli/src/nonInteractiveCli.ts index c25e452ee07..7712c555810 100644 --- a/packages/cli/src/nonInteractiveCli.ts +++ b/packages/cli/src/nonInteractiveCli.ts @@ -314,7 +314,24 @@ export async function runNonInteractive({ handleCancellationError(config); } - if (event.type === GeminiEventType.Content) { + if (event.type === GeminiEventType.Thought) { + if (streamFormatter) { + const isRaw = + config.getRawOutput() || config.getAcceptRawOutputRisk(); + const subject = isRaw + ? event.value.subject || undefined + : stripAnsi(event.value.subject) || undefined; + const description = isRaw + ? event.value.description + : stripAnsi(event.value.description); + streamFormatter.emitEvent({ + type: JsonStreamEventType.THINKING, + timestamp: new Date().toISOString(), + description, + subject, + }); + } + } else if (event.type === GeminiEventType.Content) { const isRaw = config.getRawOutput() || config.getAcceptRawOutputRisk(); const output = isRaw ? event.value : stripAnsi(event.value); diff --git a/packages/core/src/output/types.ts b/packages/core/src/output/types.ts index c67c8afe995..423e5ce1e50 100644 --- a/packages/core/src/output/types.ts +++ b/packages/core/src/output/types.ts @@ -29,6 +29,7 @@ export interface JsonOutput { export enum JsonStreamEventType { INIT = 'init', MESSAGE = 'message', + THINKING = 'thinking', TOOL_USE = 'tool_use', TOOL_RESULT = 'tool_result', ERROR = 'error', @@ -53,6 +54,12 @@ export interface MessageEvent extends BaseJsonStreamEvent { delta?: boolean; } +export interface ThinkingEvent extends BaseJsonStreamEvent { + type: JsonStreamEventType.THINKING; + description: string; + subject?: string; +} + export interface ToolUseEvent extends BaseJsonStreamEvent { type: JsonStreamEventType.TOOL_USE; tool_name: string; @@ -110,6 +117,7 @@ export interface ResultEvent extends BaseJsonStreamEvent { export type JsonStreamEvent = | InitEvent | MessageEvent + | ThinkingEvent | ToolUseEvent | ToolResultEvent | ErrorEvent