fix(coding-agent): reserve stdout in print and json mode closes #2482
This commit is contained in:
@@ -21,6 +21,7 @@ import type { LoadExtensionsResult } from "./core/extensions/index.js";
|
||||
import { migrateKeybindingsConfigFile } from "./core/keybindings.js";
|
||||
import { ModelRegistry } from "./core/model-registry.js";
|
||||
import { resolveCliModel, resolveModelScope, type ScopedModel } from "./core/model-resolver.js";
|
||||
import { restoreStdout, takeOverStdout } from "./core/output-guard.js";
|
||||
import { DefaultPackageManager } from "./core/package-manager.js";
|
||||
import { DefaultResourceLoader } from "./core/resource-loader.js";
|
||||
import { type CreateAgentSessionOptions, createAgentSession } from "./core/sdk.js";
|
||||
@@ -635,11 +636,15 @@ export async function main(args: string[]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run migrations (pass cwd for project-local migrations)
|
||||
const { migratedAuthProviders: migratedProviders, deprecationWarnings } = runMigrations(process.cwd());
|
||||
|
||||
// First pass: parse args to get --extension paths
|
||||
const firstPass = parseArgs(args);
|
||||
const shouldTakeOverStdout = firstPass.mode !== undefined || firstPass.print || !process.stdin.isTTY;
|
||||
if (shouldTakeOverStdout) {
|
||||
takeOverStdout();
|
||||
}
|
||||
|
||||
// Run migrations (pass cwd for project-local migrations)
|
||||
const { migratedAuthProviders: migratedProviders, deprecationWarnings } = runMigrations(process.cwd());
|
||||
|
||||
// Early load extensions to discover their CLI flags
|
||||
const cwd = process.cwd();
|
||||
@@ -884,9 +889,7 @@ export async function main(args: string[]) {
|
||||
initialImages,
|
||||
});
|
||||
stopThemeWatcher();
|
||||
if (process.stdout.writableLength > 0) {
|
||||
await new Promise<void>((resolve) => process.stdout.once("drain", resolve));
|
||||
}
|
||||
process.exit(0);
|
||||
restoreStdout();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user