import { Event } from "@codingame/monaco-vscode-api/vscode/vs/base/common/event"; import { Disposable, IDisposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle"; import { URI } from "@codingame/monaco-vscode-api/vscode/vs/base/common/uri"; import { FileType, IFileChange, IFileDeleteOptions, IFileOverwriteOptions, IFileSystemProvider, IFileSystemProviderWithFileRealpathCapability, IFileWriteOptions, IStat, IWatchOptions } from "@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files"; import { type CreateResourceWatchParams, type ResourceCopyParams, type ResourceCopyResult, type ResourceDeleteParams, type ResourceDeleteResult, type ResourceListResult, type ResourceMkdirParams, type ResourceMkdirResult, type ResourceMoveParams, type ResourceMoveResult, type ResourceReadResult, type ResourceRequestParams, type ResourceRequestResult, type ResourceResolveParams, type ResourceResolveResult, type ResourceWriteParams, type ResourceWriteResult } from "@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/state/protocol/commands"; import { type ActionEnvelope } from "./state/sessionActions.js"; /** * Interface for performing resource operations on a remote endpoint. * * Both {@link IAgentConnection} (client→server) and client-exposed * filesystems (server→client) satisfy this contract. */ export interface IRemoteFilesystemConnection { resourceList(uri: URI): Promise; resourceRead(uri: URI): Promise; resourceWrite(params: ResourceWriteParams): Promise; resourceDelete(params: ResourceDeleteParams): Promise; resourceMove(params: ResourceMoveParams): Promise; /** Copy a resource on the remote endpoint. */ resourceCopy(params: ResourceCopyParams): Promise; /** * Negotiate access to a resource the receiver mediates. Optional because * not every connection in the codebase carries one — only the agent-host * server-to-client direction needs to send `resourceRequest` today. */ resourceRequest?(params: ResourceRequestParams): Promise; /** Resolve (stat + realpath) a resource on the remote endpoint. */ resourceResolve(params: ResourceResolveParams): Promise; /** Create a directory on the remote endpoint (mkdir -p semantics). */ resourceMkdir(params: ResourceMkdirParams): Promise; /** * Start a file-system watcher on the remote endpoint and return a * handle whose `onDidChange` event fires for every change the remote * reports under the watched root. Disposing the handle unsubscribes * the watch (subject to the receiver's grace window). * * Optional: implementations that do not have access to the AHP * subscription machinery (e.g. raw IPC channels in * {@link createAgentHostClientResourceConnection}) omit it; the FS * provider degrades to a no-op `watch()` in that case. */ watchResource?(params: CreateResourceWatchParams): Promise; } /** * Handle for a remote file-system watcher returned by * {@link IRemoteFilesystemConnection.watchResource}. Mirrors the shape * of `IFileSystemWatcher` from `../../files/common/files.js` so the FS * provider can plug events straight into its own `onDidChangeFile` * emitter. */ export interface IRemoteWatchHandle extends IDisposable { readonly onDidChange: Event; } /** * Shared implementation of {@link IAgentConnection.watchResource} — * bundles `createResourceWatch` + `subscribe` + a per-channel listener * on the action stream into an {@link IRemoteWatchHandle}. Used by * every transport that exposes those four primitives so we don't need * to duplicate the wire bookkeeping in each `IAgentConnection` * implementation. */ export declare function createRemoteWatchHandle(primitives: { createResourceWatch(params: CreateResourceWatchParams): Promise<{ channel: string; }>; subscribe(channel: URI): Promise; unsubscribe(channel: URI): void; onDidAction: Event; }, params: CreateResourceWatchParams): Promise; /** * Build a {@link AGENT_HOST_SCHEME} URI for a given connection authority * and remote path. Assumes the remote path is a `file://` resource. */ export declare function agentHostUri(authority: string, path: string): URI; /** * Extract the remote filesystem path from a {@link AGENT_HOST_SCHEME} URI. */ export declare function agentHostRemotePath(uri: URI): string; /** * {@link IFileSystemProvider} that proxies filesystem operations * through a {@link IRemoteFilesystemConnection}. * * URIs encode the original scheme and authority in the path so any remote * resource can be represented. Subclasses provide the URI decode function * and scheme-specific helpers. * * Individual connections are identified by the URI's authority component. */ export declare abstract class AHPFileSystemProvider extends Disposable implements IFileSystemProvider, IFileSystemProviderWithFileRealpathCapability { private readonly _connectionGraceMs; readonly capabilities: number; private readonly _onDidChangeCapabilities; readonly onDidChangeCapabilities: Event; private readonly _onDidChangeFile; readonly onDidChangeFile: Event; private readonly _onDidWatchError; readonly onDidWatchError: Event; /** * Per-authority registration slot. We keep the slot alive for a brief * grace period after the last registration is disposed, so an * operation issued during a reconnection window can wait for the * replacement registration instead of failing immediately. */ private readonly _authorities; /** * Fires the authority whose active connection has changed: added, * replaced, fallen back to an older registration, entered the grace * window (no active connection), or evicted. Long-lived consumers * (e.g. {@link watch}) subscribe here so they continue to receive * notifications across full entry eviction + later re-creation — * something a per-entry emitter cannot offer. */ private readonly _onDidChangeConnection; /** * Grace period during which {@link _getConnection} will await a new * registration after the previous one is disposed. Covers the window * where a transport is briefly torn down and re-registered (e.g. an * agent-host client reconnect that races a plugin sync). 5s matches * the typical reconnect timeout. Consumers should still implement * logical retries for longer reconnection latencies, but this is a * low level, best-effort mechanism. * * Tests can override this via the constructor parameter. */ private static readonly _DEFAULT_CONNECTION_GRACE_MS; constructor(_connectionGraceMs?: number); /** * Register a mapping from a URI authority to a connection. * Returns a disposable that unregisters the mapping. Multiple * concurrent registrations for the same authority are supported; * the most recent registration wins, and disposing it falls back to * the previous one (if any). After the *last* registration is * disposed the entry is held open for {@link _connectionGraceMs} so * that a reconnect can replace it without orphaning in-flight * operations. */ registerAuthority(authority: string, connection: IRemoteFilesystemConnection): IDisposable; private _expireAuthority; dispose(): void; /** Decode a provider URI back to the original URI for the remote endpoint. */ protected abstract _decodeUri(resource: URI): URI; /** Encode a remote URI back into a provider URI with the given authority. */ protected abstract _encodeUri(resource: URI, authority: string): URI; watch(resource: URI, opts: IWatchOptions): IDisposable; stat(resource: URI): Promise; realpath(resource: URI): Promise; readdir(resource: URI): Promise<[ string, FileType ][]>; readFile(resource: URI): Promise; writeFile(resource: URI, content: Uint8Array, _opts: IFileWriteOptions): Promise; mkdir(resource: URI): Promise; delete(resource: URI, opts: IFileDeleteOptions): Promise; rename(from: URI, to: URI, opts: IFileOverwriteOptions): Promise; copy(from: URI, to: URI, opts: IFileOverwriteOptions): Promise; /** * Negotiate access to {@link resource} with the receiver, asking for the * granted modes in {@link opts}. Used after a `NoPermissions` failure to * prompt the receiver to grant access; the caller can then retry. * * Resolves on success. Rejects if the receiver denies, the connection * is missing, or the connection doesn't implement `resourceRequest`. */ requestResourceAccess(resource: URI, opts: { readonly read?: boolean; readonly write?: boolean; }): Promise; private _getConnection; /** * Translate a thrown error from a {@link IRemoteFilesystemConnection} * into a {@link FileSystemProviderError}. Preserves `PermissionDenied` * (-32009) as `NoPermissions` so callers can distinguish a * permission failure from `NotFound` and decide whether to negotiate * via {@link requestResourceAccess}. */ private _mapError; /** * Resolve a decoded resource over {@link connection}. Shared by * {@link stat} and {@link realpath}. */ private _resolve; private _listDirectory; } /** * Filesystem provider for accessing agent host files from the * client side. Registered under the `vscode-agent-host` scheme. * * ``` * vscode-agent-host://[connectionAuthority]/[originalScheme]/[originalAuthority]/[originalPath] * ``` */ export declare class AgentHostFileSystemProvider extends AHPFileSystemProvider { protected _decodeUri(resource: URI): URI; protected _encodeUri(resource: URI, authority: string): URI; }