Skip to content

Repository files navigation

AutoPilot AI

AutoPilot AI is a VS Code extension that adds a sidebar chat assistant for coding tasks. It can answer general questions, explain selected code, refactor snippets, generate documentation, and apply generated code into the active editor.

Features

  • Sidebar chat view inside VS Code (AutoPilot AI activity bar item)
  • OpenAI-backed chat with API-key sign-in flow
  • Context-aware prompting:
    • none: no editor context for general questions
    • selection: selected code context when relevant
    • file: current file context for file-wide questions
  • Hybrid request routing:
    • Heuristic classifier
    • Optional mini-model router for ambiguous requests
  • Task-aware response depth:
    • quick, normal, deep
  • Selection-based editor actions:
    • Explain selection
    • Refactor selection
    • Document selection
  • "Apply Code" button on generated code blocks to insert/replace in editor

Developer Documentation

For a deeper explanation of the codebase, architecture, request flow, project-aware retrieval, and edit-planning workflow, see docs/DEVELOPER_GUIDE.md.

Requirements

  • VS Code ^1.100.0
  • Node.js 20+
  • An OpenAI Project API key (for example sk-proj-...)

Getting Started

  1. Clone and install dependencies:
npm install
  1. Compile:
npm run compile
  1. Run extension in development:
  • Press F5 in VS Code to launch the Extension Development Host.
  1. In the extension UI, click Sign In and provide:
  • Email address (stored with MongoDB chat history records)
  • OpenAI Project API key (stored in VS Code global state)

Commands

The extension contributes these commands:

  • autopilot-searchbar.search — Open AutoPilot AI
  • autopilot-searchbar.logout — Logout
  • autopilot-searchbar.explainSelection — Explain with AutoPilot AI
  • autopilot-searchbar.refactorCode — Refactor Code with AutoPilot AI
  • autopilot-searchbar.documentSelection — Document It with AutoPilot AI
  • autopilot-searchbar.applyCode — Apply Code from AutoPilot AI

Selection commands are also available in the editor context menu when text is selected.

Extension Settings

This extension contributes the following settings:

  • autopilot.apiKey (string): API key field (primary sign-in uses secure global state flow).
  • autopilot.enableAiRouter (boolean, default true): Enables mini-model request classification when heuristics are uncertain.
  • autopilot.routerModel (string, default gpt-4o-mini): Model used for the lightweight request router.
  • autopilot.chatHistoryApiUrl (string, default empty): Base URL of the chat history API. Leave empty to disable persistence.
  • autopilot.chatHistoryApiKey (string, default empty): Bearer token sent to the chat history API.

Chat history is stored via the backend API in the api/ folder. Firebase Spark can host static files only; the REST API must run on a host that supports server code, such as Blaze Functions, Cloudflare Workers, Render, or Vercel.

How Context Routing Works

For normal chat messages, the extension plans each request before sending it to the main model:

  1. Detect intent/context need (none / selection / file)
  2. Detect response depth (quick / normal / deep)
  3. Build minimal prompt payload
  4. Send to OpenAI

This reduces unnecessary token usage and improves latency versus always attaching full-file context.

Development Scripts

  • npm run compile — Build extension
  • npm run watch — Build in watch mode
  • npm run package — Production bundle
  • npm run lint — Lint source
  • npm run check-types — Type-check only
  • npm run test — Run extension tests

Packaging and Publishing

1. Prepare package.json

Ensure at least the following are set:

  • name
  • displayName
  • publisher
  • version
  • engines.vscode

2. Create a VSIX package

npx vsce package

This generates a file like:

  • autopilot-ai-<version>.vsix

3. Publish to Visual Studio Marketplace

  1. Create/manage publisher: https://marketplace.visualstudio.com/manage
  2. Create Azure DevOps PAT with Marketplace publish permissions
  3. Publish:
npx vsce publish -p <YOUR_PAT>

Troubleshooting

  • If authentication fails, verify you are using a valid OpenAI Project API key.
  • If responses are empty due to token limits, ask a narrower question or reduce file/selection size.
  • If network errors occur, check proxy/firewall settings in your environment.

Security Notes

  • API key is read from VS Code global state in this extension.
  • Email is read from VS Code global state and included in chat history API records when persistence is configured.
  • MongoDB credentials belong on the API server (api/.env), never in the extension package.
  • Review your organization policy before using personal or shared keys.

License

See LICENSE (add one before marketplace publish if missing).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages