mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-25 12:34:38 -07:00
feat(a2a): Introduce restore command for a2a server (#13015)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
This commit is contained in:
@@ -27,6 +27,8 @@ import {
|
||||
type Config,
|
||||
type UserTierId,
|
||||
type AnsiOutput,
|
||||
EDIT_TOOL_NAMES,
|
||||
processRestorableToolCalls,
|
||||
} from '@google/gemini-cli-core';
|
||||
import type { RequestContext } from '@a2a-js/sdk/server';
|
||||
import { type ExecutionEventBus } from '@a2a-js/sdk/server';
|
||||
@@ -40,7 +42,8 @@ import type {
|
||||
} from '@a2a-js/sdk';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { logger } from '../utils/logger.js';
|
||||
import * as fs from 'node:fs';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
import { CoderAgentEvent } from '../types.js';
|
||||
import type {
|
||||
CoderAgentMessage,
|
||||
@@ -511,7 +514,7 @@ export class Task {
|
||||
new_string: string,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const currentContent = fs.readFileSync(file_path, 'utf8');
|
||||
const currentContent = await fs.readFile(file_path, 'utf8');
|
||||
return this._applyReplacement(
|
||||
currentContent,
|
||||
old_string,
|
||||
@@ -554,6 +557,44 @@ export class Task {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set checkpoint file before any file modification tool executes
|
||||
const restorableToolCalls = requests.filter((request) =>
|
||||
EDIT_TOOL_NAMES.has(request.name),
|
||||
);
|
||||
|
||||
if (restorableToolCalls.length > 0) {
|
||||
const gitService = await this.config.getGitService();
|
||||
if (gitService) {
|
||||
const { checkpointsToWrite, toolCallToCheckpointMap, errors } =
|
||||
await processRestorableToolCalls(
|
||||
restorableToolCalls,
|
||||
gitService,
|
||||
this.geminiClient,
|
||||
);
|
||||
|
||||
if (errors.length > 0) {
|
||||
errors.forEach((error) => logger.error(error));
|
||||
}
|
||||
|
||||
if (checkpointsToWrite.size > 0) {
|
||||
const checkpointDir =
|
||||
this.config.storage.getProjectTempCheckpointsDir();
|
||||
await fs.mkdir(checkpointDir, { recursive: true });
|
||||
for (const [fileName, content] of checkpointsToWrite) {
|
||||
const filePath = path.join(checkpointDir, fileName);
|
||||
await fs.writeFile(filePath, content);
|
||||
}
|
||||
}
|
||||
|
||||
for (const request of requests) {
|
||||
const checkpoint = toolCallToCheckpointMap.get(request.callId);
|
||||
if (checkpoint) {
|
||||
request.checkpoint = checkpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const updatedRequests = await Promise.all(
|
||||
requests.map(async (request) => {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user