Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`**):
Expand Down
19 changes: 18 additions & 1 deletion packages/cli/src/nonInteractiveCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/output/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand Down Expand Up @@ -110,6 +117,7 @@ export interface ResultEvent extends BaseJsonStreamEvent {
export type JsonStreamEvent =
| InitEvent
| MessageEvent
| ThinkingEvent
| ToolUseEvent
| ToolResultEvent
| ErrorEvent
Expand Down