This is a tool meant for exploring the codebase of Github Copilot (the client side, not the model itself).
It's work in progress. See the Journal for details on what's been done so far and my observations.
There's a blog post that explains the high level findings, and provides necessary code pointers.
You can access a version of the tool here.
This explores version 1.57.7193 of the VSCode extension of Copilot.
The webpage shows 3 panels:
Module Names: I've also named modules -- some of them manually, while most of them were automatically named using codex in a few-shot manner. Some names are not unique, and I've not dealt with that. IDs of every module are unique though.
Module Categories: I've similarly also categorized modules automatically (again using codex and a bit of manual labeling). The categories are not perfect, but they serve as a very good guideline for segregating modules.
Manual annotations: Some of the modules were quite interesting, so I manually annotated them (added comments and renamed variables) to make them easier to understand. These are now directly viewable in the middle panel. Links below.
If you want to start browsing, below are some interesting starting points.
Navigation tips:
M_prompt_extractor.getPrompt()
, then you know to look for prompt-extractor
module in the right panel.Some interesting modules I've found so far (these notes were written before I wrote the blog post, so some comments might be outdated):
Prompting:
This is the most interesting part of the codebase to me. This is what brings all the smarts to Copilot apart from the model itself. The reason copilot can get function names right often is because of this stuff.
The following modules have been manually annotated and constitute most of all the magic:
For many languages, copilot calls the tree-sitter parser via WASM. There are some wrappers around that in 464.
Note that there are some duplicate modules, idk why but I'm guessing webpack does something. So many modules starting with 3055... will have copies with other ids.
Completion: There appear to be two main workflows for completion:
Inline-Completions (the stuff you most commonly use, where copilot autocompletes as you type).
3197 appears to be the main module for this. This is imported by the main module and it registers an inline-completion-provider. The class v
there is actually the InlineCompletionItemProvider.
9334 appears to be the module that contains the core logic for inline completion. It defines getGhostText
.. Depends on lots of other copilot modules. Only two hops away from the main module. The core functionality appears to the following:
Panel Completion (the stuff shown if you press ctrl+enter)
2388 seems to contain the main logic for this.
2990 is the main copilot-panel module. This is imported by the main module. You can see this contains the "Accept Solution" and "Replace code with this solution" buttons.
Telemetry:
Network:
Misc:
Config/Experiments:
If you want to play with the code (different transformations, different visualizations, etc.), you can run the tool locally and modify the code.
npm install
node index.js
-- this processes the copilot extension code and produces modules by doing some automatic reverse engineering.Steps 2 and 3 are optional. They're only needed if you modify the extension code or the transformation code. The repo already contains the processed modules.
pip install manifest-ml
.codeviz/.openai-api-key
storing your OpenAI API key. You can keep this empty if you're not going to predict names and categories, or going to use the select-snippet -> right-click -> Describe this snippet
feature (which doesn't work that well anyway).python3 codeviz/app.py
to start the app.localhost:5000
in your browser.The tool supports 3 types of annotations: (a) module names (b) module categories (c) module code.
You can change the first two annotations (rename/recategorize modules) by the UI. These annotations persist in your localstorage. If you want to export them, you can use browser console to do so. I know this isn't ideal, but hey this is a hacky repo. I doubt anyone will reannotate stuff seriously.
For module code -- if you find a particular module interesting and want to add your comments, you can do that and save the annotated module under codeviz/data/manually_annotated_modules/<module_id>.js
. Finally, run codeviz/compress_annotated_codes.js
which takes all the annotated modules and puts them in a single file that's loaded in the browser...so that your annotations show up in the UI.
lmao
But seriously, this is all on a best-effort basis, I might've misunderstood a few things and so the conclusions might be slightly off. If you find something, do raise an issue or a PR.