Skip to content

Add AgentResourceResolver for RemoteHub virtual URI support in chat editing #260458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 8, 2025

This PR enables VS Code coding-agent chat editing sessions to edit files that are not in the local workspace by resolving remote targets to RemoteHub virtual (vscode-vfs://) URIs. This keeps the chat editing pipeline unchanged while leveraging RemoteHub's writable virtual filesystem.

Problem

Currently, chat editing sessions can only work with local workspace files (file:// URIs) or existing virtual files (vscode-vfs:// URIs). When agents want to edit remote repository files (e.g., from GitHub), there's no mechanism to resolve remote descriptors to writable virtual URIs.

Solution

Introduces a minimal IAgentResourceResolver service that:

  1. Pass-through behavior: file:// and vscode-vfs:// URIs are returned unchanged
  2. Remote resolution: AgentTargetDescriptor objects are resolved via RemoteHub's remoteHub.createAgentVirtualUri command
  3. Safe fallback: When RemoteHub is unavailable, the resolver gracefully returns the original resource

Implementation

New agentResourceResolver.ts:

export interface AgentTargetDescriptor {
  providerId: 'github' | 'azurerepos';
  owner: string;
  repo: string; 
  ref?: string;
  path?: string;
}

export class AgentResourceResolver implements IAgentResourceResolver {
  async resolve(candidate: URI | AgentTargetDescriptor): Promise<URI> {
    // Pass-through for known URI schemes
    if (URI.isUri(candidate)) {
      if (candidate.scheme === 'file' || candidate.scheme === 'vscode-vfs') {
        return candidate;
      }
      return candidate; // Other schemes pass through
    }

    // Try RemoteHub for descriptors
    try {
      const uri = await this.commandService.executeCommand<URI>(
        'remoteHub.createAgentVirtualUri', candidate
      );
      return uri ?? (candidate as any);
    } catch {
      return candidate as any; // Fallback if RemoteHub unavailable
    }
  }
}

Integration in ChatEditingSession._acceptEdits:

private async _acceptEdits(resource: URI, textEdits: TextEdit[], ...): Promise<void> {
  // Resolve remote targets to virtual URIs (no-op if not applicable)
  try {
    resource = await this._agentResolver.resolve(resource as any);
  } catch {
    // ignore; proceed with original resource
  }
  
  const entry = await this._getOrCreateModifiedFileEntry(resource, ...);
  await entry.acceptAgentEdits(resource, textEdits, ...);
}

Benefits

  • Cross-repository editing: Agents can now edit files in remote repositories
  • Zero breaking changes: Existing local file editing behavior is unchanged
  • Pipeline compatibility: The chat editing accept/reject/diff pipeline works seamlessly
  • Safe implementation: Graceful degradation when RemoteHub is not installed

Example Usage

// Local files work as before
const localFile = URI.file('/workspace/src/main.ts');
await resolver.resolve(localFile); // → same URI

// Remote descriptors get resolved to vscode-vfs://
const remoteDescriptor = {
  providerId: 'github',
  owner: 'microsoft', 
  repo: 'vscode',
  path: 'src/vs/workbench/browser/workbench.ts'
};
await resolver.resolve(remoteDescriptor); // → vscode-vfs://... URI

The resolver is registered as a singleton and injected via DI into ChatEditingSession, making it available throughout the chat editing pipeline with no changes required to calling code.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Resolve coding-agent remote targets to RemoteHub virtual URIs in chat editing Add AgentResourceResolver for RemoteHub virtual URI support in chat editing Aug 8, 2025
@Copilot Copilot AI requested a review from osortega August 8, 2025 03:02
Copilot finished work on behalf of osortega August 8, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants