import { VSBuffer } from "../../../../../../base/common/buffer.js"; import { Event } from "../../../../../../base/common/event.js"; import { Disposable } from "../../../../../../base/common/lifecycle.js"; import { IObservable, IReader } from "../../../../../../base/common/observable.js"; import { URI } from "../../../../../../base/common/uri.js"; import { ITextModel } from "../../../../../../editor/common/model.js"; import { type ISessionFileDiff, type ToolCallState } from "../../../../../../platform/agentHost/common/state/sessionState.js"; import { IFileService } from "../../../../../../platform/files/common/files.service.js"; import { ILogService } from "../../../../../../platform/log/common/log.service.js"; import { IWorkingCopyService } from "../../../../../services/workingCopy/common/workingCopyService.service.js"; import { IChatProgress, IChatWorkspaceEdit } from "../../../common/chatService/chatService.js"; import { ChatEditingSessionState, IChatEditingSession, IEditSessionDiffStats, IEditSessionEntryDiff, IModifiedFileEntry, IStreamingEdits } from "../../../common/editing/chatEditingService.js"; import { IChatRequestDisablement, IChatResponseModel } from "../../../common/model/chatModel.js"; import { AgentHostEditReview } from "@codingame/monaco-vscode-chat-service-override/vscode/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostEditReview"; import { AgentHostCheckpointReview } from "./agentHostCheckpointReview.js"; /** * A thin {@link IChatEditingSession} for agent host sessions. The agent host * has its own diff / changeset machinery and renders file edits via the * dedicated {@link IChatExternalEdit} progress part — so this session only * needs to support the chat-level "restore to checkpoint" UX. * * Concretely it implements: * - {@link restoreSnapshot} (writes before/after content to disk) * - {@link requestDisablement} (so disabled-request UI works after restore) * - {@link getSnapshotUri} / {@link getSnapshotContents} (so checkpoint diff * viewers can resolve historical content) * * Everything else is a no-op / empty observable / `undefined`. In particular: * - `entries` is empty unless an {@link AgentHostEditReview} is attached * (`chat.editor.workingSet.enabled`); then they are the files of the * session's Working Set, which the editor's keep/undo UI shows * - no streaming-edits APIs: the agent host writes files itself * * Undo/redo granularity is per-request: every request occupies one checkpoint * regardless of how many tool calls it ran. The `stopId` parameters on * {@link restoreSnapshot}, {@link getSnapshotUri}, and {@link getSnapshotContents} * are accepted for interface compatibility but ignored. * * Hydrated by the session handler as turns and tool calls arrive, with * optional turn changesets resolved when checkpoint content is needed. */ export declare class AgentHostSnapshotController extends Disposable implements IChatEditingSession { readonly chatSessionResource: URI; private readonly _connectionAuthority; private readonly _turnEdits; private readonly _logService; private readonly _fileService; private readonly _workingCopyService; readonly checkpointReview: AgentHostCheckpointReview; private readonly _review; private readonly _reviewBinding; /** True when the edits of this chat can be kept or undone. */ readonly supportsKeepUndo: IObservable; /** A reviewing session participates in the editor's keep/undo overlay, like local chat. */ readonly isGlobalEditingSession: IObservable; readonly state: IObservable; readonly entries: IObservable; readonly additionalReviewFiles: import("../../../../../../base/common/observable.js").IObservableWithChange; readonly requestDisablement: IObservable; readonly canUndo: IObservable; readonly canRedo: IObservable; private readonly _onDidDispose; readonly onDidDispose: Event; private readonly _checkpoints; private readonly _currentCheckpointIndex; private readonly _undoRedoSequencer; constructor(chatSessionResource: URI, _connectionAuthority: string, _turnEdits: { readonly getChanges: (requestId: string) => IObservable | undefined; readonly resolve: (requestId: string) => Promise; } | undefined, _logService: ILogService, _fileService: IFileService, _workingCopyService: IWorkingCopyService); /** Owns editor review while enabled, releasing it immediately when the preference changes. */ attachReview(enabled: IObservable, createReview: () => AgentHostEditReview): void; get review(): AgentHostEditReview | undefined; /** * Ensures a checkpoint exists for the given request. Called at the start * of every turn (and during history hydration) so {@link requestDisablement} * and {@link restoreSnapshot} can reference every request, even ones that * produce no file edits. * * Splices away stale checkpoints past the current index (undo branch * semantics) when a new request arrives after a checkpoint restore. */ ensureRequestCheckpoint(requestId: string): void; /** * Folds a completed tool call's file edits into the checkpoint for the * given request. Idempotent on `toolCallId`. */ addToolCallEdits(requestId: string, tc: ToolCallState): void; private _addCheckpointEdits; private _findCheckpointIndex; restoreSnapshot(requestId: string, _stopId: string | undefined): Promise; /** * Steps a single checkpoint backwards, undoing the edits of the current * checkpoint. The "Undo" UI invokes this once per click. */ undoInteraction(): Promise; /** * Steps a single checkpoint forwards, redoing the edits of the next * checkpoint. * * Implementing this is essential: the "Redo" action repeatedly calls this * while {@link canRedo} is `true`, so a no-op implementation would spin * forever and hang the window. */ redoInteraction(): Promise; /** * Moves the on-disk file state and the checkpoint cursor to `targetIdx`, * writing each crossed checkpoint's before/after content. Must run inside * the {@link _undoRedoSequencer} to avoid racing writes. */ private _navigateToCheckpointIndex; getSnapshotUri(requestId: string, uri: URI, _stopId: string | undefined): URI | undefined; getSnapshotContents(requestId: string, uri: URI, _stopId: string | undefined): Promise; getSnapshotModel(_requestId: string, _undoStop: string | undefined, _snapshotUri: URI): Promise; hasEditsInRequest(requestId: string, reader?: IReader): boolean; show(previousChanges?: boolean): Promise; getEntry(uri: URI): IModifiedFileEntry | undefined; resolveEntry(uri: URI): Promise; readEntry(uri: URI, reader: IReader): IModifiedFileEntry | undefined; accept(...uris: URI[]): Promise; reject(...uris: URI[]): Promise; getEntryDiffBetweenStops(_uri: URI, _requestId: string | undefined, _stopId: string | undefined): IObservable | undefined; getEntryDiffBetweenRequests(_uri: URI, _startRequestId: string, _stopRequestId: string): IObservable; getDiffsForFilesInSession(): IObservable; getDiffsForFilesInRequest(_requestId: string): IObservable; getDiffForSession(): IObservable; triggerExplanationGeneration(): Promise; clearExplanations(): void; hasExplanations(): boolean; startStreamingEdits(_resource: URI, _responseModel: IChatResponseModel, _inUndoStop: string | undefined): IStreamingEdits; applyWorkspaceEdit(_edit: IChatWorkspaceEdit, _responseModel: IChatResponseModel, _undoStopId: string): void; startExternalEdits(_responseModel: IChatResponseModel, _operationId: number, _resources: URI[], _undoStopId: string, _contentFor?: URI[]): Promise; stopExternalEdits(_responseModel: IChatResponseModel, _operationId: number, _contentFor?: URI[]): Promise; stop(_clearState?: boolean): Promise; dispose(): void; /** Loads authoritative turn snapshots for providers that do not report edits on tool calls. */ private _resolveCheckpointEdits; private _writeCheckpointContent; private _readCheckpointFile; private _writeCheckpointFile; private _deleteCheckpointFile; private _checkpointFileExists; private _moveCheckpointFile; }