refactor(cli): handle max turns from stream end

This commit is contained in:
Adam Weidman
2026-03-20 11:19:34 -04:00
committed by Adam Weidman
parent f34b146a05
commit 6d8cee7620
+14 -13
View File
@@ -445,18 +445,6 @@ export async function runNonInteractive({
const errorCode = event._meta?.['code'];
if (errorCode === 'MAX_TURNS_EXCEEDED') {
if (streamFormatter) {
streamFormatter.emitEvent({
type: JsonStreamEventType.ERROR,
timestamp: new Date().toISOString(),
severity: 'error',
message: event.message,
});
}
break;
}
if (errorCode === 'AGENT_EXECUTION_BLOCKED') {
if (config.getOutputFormat() === OutputFormat.TEXT) {
process.stderr.write(`[WARNING] ${event.message}\n`);
@@ -483,7 +471,20 @@ export async function runNonInteractive({
if (event.reason === 'aborted') {
handleCancellationError(config);
} else if (event.reason === 'max_turns') {
handleMaxTurnsExceededError(config);
const isSessionLimit =
typeof event.data?.['maxTurns'] === 'number' &&
typeof event.data?.['turnCount'] === 'number';
if (isSessionLimit) {
handleMaxTurnsExceededError(config);
}
if (streamFormatter) {
streamFormatter.emitEvent({
type: JsonStreamEventType.ERROR,
timestamp: new Date().toISOString(),
severity: 'error',
message: 'Maximum session turns exceeded',
});
}
}
const stopMessage =