mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-24 21:10:43 -07:00
fix(patch): cherry-pick 828afe1 to release/v0.20.0-preview.1-pr-14159 to patch version v0.20.0-preview.1 and create version 0.20.0-preview.2 (#14733)
Co-authored-by: Allen Hutchison <adh@google.com>
This commit is contained in:
@@ -50,7 +50,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
),
|
||||
),
|
||||
patchStdio: vi.fn(() => () => {}),
|
||||
createInkStdio: vi.fn(() => ({
|
||||
createWorkingStdio: vi.fn(() => ({
|
||||
stdout: {
|
||||
write: vi.fn((...args) =>
|
||||
process.stdout.write(
|
||||
|
||||
@@ -47,7 +47,7 @@ import {
|
||||
recordSlowRender,
|
||||
coreEvents,
|
||||
CoreEvent,
|
||||
createInkStdio,
|
||||
createWorkingStdio,
|
||||
patchStdio,
|
||||
writeToStdout,
|
||||
writeToStderr,
|
||||
@@ -203,7 +203,7 @@ export async function startInteractiveUI(
|
||||
consolePatcher.patch();
|
||||
registerCleanup(consolePatcher.cleanup);
|
||||
|
||||
const { stdout: inkStdout, stderr: inkStderr } = createInkStdio();
|
||||
const { stdout: inkStdout, stderr: inkStderr } = createWorkingStdio();
|
||||
|
||||
// Create wrapper component to use hooks inside render
|
||||
const AppWrapper = () => {
|
||||
|
||||
@@ -24,7 +24,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
...actual,
|
||||
writeToStdout: vi.fn(),
|
||||
patchStdio: vi.fn(() => () => {}),
|
||||
createInkStdio: vi.fn(() => ({
|
||||
createWorkingStdio: vi.fn(() => ({
|
||||
stdout: {
|
||||
write: vi.fn(),
|
||||
columns: 80,
|
||||
|
||||
@@ -68,6 +68,10 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
getMetrics: vi.fn(),
|
||||
},
|
||||
coreEvents: mockCoreEvents,
|
||||
createWorkingStdio: vi.fn(() => ({
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
debugLogger,
|
||||
coreEvents,
|
||||
CoreEvent,
|
||||
createWorkingStdio,
|
||||
} from '@google/gemini-cli-core';
|
||||
|
||||
import type { Content, Part } from '@google/genai';
|
||||
@@ -70,7 +71,8 @@ export async function runNonInteractive({
|
||||
coreEvents.emitConsoleLog(msg.type, msg.content);
|
||||
},
|
||||
});
|
||||
const textOutput = new TextOutput();
|
||||
const { stdout: workingStdout } = createWorkingStdio();
|
||||
const textOutput = new TextOutput(workingStdout);
|
||||
|
||||
const handleUserFeedback = (payload: UserFeedbackPayload) => {
|
||||
const prefix = payload.severity.toUpperCase();
|
||||
|
||||
@@ -65,7 +65,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
),
|
||||
),
|
||||
patchStdio: vi.fn(() => () => {}),
|
||||
createInkStdio: vi.fn(() => ({
|
||||
createWorkingStdio: vi.fn(() => ({
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
})),
|
||||
|
||||
@@ -13,6 +13,11 @@ import stripAnsi from 'strip-ansi';
|
||||
|
||||
export class TextOutput {
|
||||
private atStartOfLine = true;
|
||||
private outputStream: NodeJS.WriteStream;
|
||||
|
||||
constructor(outputStream: NodeJS.WriteStream = process.stdout) {
|
||||
this.outputStream = outputStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a string to stdout.
|
||||
@@ -22,7 +27,7 @@ export class TextOutput {
|
||||
if (str.length === 0) {
|
||||
return;
|
||||
}
|
||||
process.stdout.write(str);
|
||||
this.outputStream.write(str);
|
||||
const strippedStr = stripAnsi(str);
|
||||
if (strippedStr.length > 0) {
|
||||
this.atStartOfLine = strippedStr.endsWith('\n');
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
debugLogger,
|
||||
ReadManyFilesTool,
|
||||
getEffectiveModel,
|
||||
createWorkingStdio,
|
||||
startupProfiler,
|
||||
} from '@google/gemini-cli-core';
|
||||
import * as acp from './acp.js';
|
||||
@@ -51,15 +52,10 @@ export async function runZedIntegration(
|
||||
settings: LoadedSettings,
|
||||
argv: CliArgs,
|
||||
) {
|
||||
const stdout = Writable.toWeb(process.stdout) as WritableStream;
|
||||
const { stdout: workingStdout } = createWorkingStdio();
|
||||
const stdout = Writable.toWeb(workingStdout) as WritableStream;
|
||||
const stdin = Readable.toWeb(process.stdin) as ReadableStream<Uint8Array>;
|
||||
|
||||
// Stdout is used to send messages to the client, so console.log/console.info
|
||||
// messages to stderr so that they don't interfere with ACP.
|
||||
console.log = console.error;
|
||||
console.info = console.error;
|
||||
console.debug = console.error;
|
||||
|
||||
new acp.AgentSideConnection(
|
||||
(client: acp.Client) => new GeminiAgent(config, settings, argv, client),
|
||||
stdout,
|
||||
|
||||
@@ -48,7 +48,7 @@ vi.mock('../utils/browser.js', () => ({
|
||||
vi.mock('../utils/stdio.js', () => ({
|
||||
writeToStdout: vi.fn(),
|
||||
writeToStderr: vi.fn(),
|
||||
createInkStdio: vi.fn(() => ({
|
||||
createWorkingStdio: vi.fn(() => ({
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
})),
|
||||
|
||||
@@ -33,7 +33,7 @@ import { FORCE_ENCRYPTED_FILE_ENV_VAR } from '../mcp/token-storage/index.js';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
import {
|
||||
writeToStdout,
|
||||
createInkStdio,
|
||||
createWorkingStdio,
|
||||
writeToStderr,
|
||||
} from '../utils/stdio.js';
|
||||
import {
|
||||
@@ -334,7 +334,7 @@ async function authWithUserCode(client: OAuth2Client): Promise<boolean> {
|
||||
const code = await new Promise<string>((resolve, _) => {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: createInkStdio().stdout,
|
||||
output: createWorkingStdio().stdout,
|
||||
terminal: true,
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { patchStdio, createInkStdio } from './stdio.js';
|
||||
import { patchStdio, createWorkingStdio } from './stdio.js';
|
||||
import { coreEvents } from './events.js';
|
||||
|
||||
vi.mock('./events.js', () => ({
|
||||
@@ -53,14 +53,14 @@ describe('stdio utils', () => {
|
||||
expect(process.stderr.write).toBe(originalStderrWrite);
|
||||
});
|
||||
|
||||
it('createInkStdio writes to real stdout/stderr bypassing patch', () => {
|
||||
it('createWorkingStdio writes to real stdout/stderr bypassing patch', () => {
|
||||
const cleanup = patchStdio();
|
||||
const { stdout: inkStdout, stderr: inkStderr } = createInkStdio();
|
||||
const { stdout, stderr } = createWorkingStdio();
|
||||
|
||||
inkStdout.write('ink stdout');
|
||||
stdout.write('working stdout');
|
||||
expect(coreEvents.emitOutput).not.toHaveBeenCalled();
|
||||
|
||||
inkStderr.write('ink stderr');
|
||||
stderr.write('working stderr');
|
||||
expect(coreEvents.emitOutput).not.toHaveBeenCalled();
|
||||
|
||||
cleanup();
|
||||
|
||||
@@ -80,9 +80,9 @@ export function patchStdio(): () => void {
|
||||
/**
|
||||
* Creates proxies for process.stdout and process.stderr that use the real write methods
|
||||
* (writeToStdout and writeToStderr) bypassing any monkey patching.
|
||||
* This is used by Ink to render to the real output.
|
||||
* This is used to write to the real output even when stdio is patched.
|
||||
*/
|
||||
export function createInkStdio() {
|
||||
export function createWorkingStdio() {
|
||||
const inkStdout = new Proxy(process.stdout, {
|
||||
get(target, prop, receiver) {
|
||||
if (prop === 'write') {
|
||||
|
||||
Reference in New Issue
Block a user