Code highlights ala Paul Gauthier's repomap technique from Aider Chat (#785)

* finish pop stack merge

* package changes
This commit is contained in:
restlessronin 2024-02-03 09:09:25 +05:30 • committed by GitHub
parent 76fe78a1a3
commit b3ba9074cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 269 additions and 1 deletions

2
.gitignore vendored
View file

@ -152,4 +152,4 @@ continue_server.build
continue_server.dist
Icon
Icon?
Icon?

View file

@ -0,0 +1,60 @@
import { BaseContextProvider } from "..";
import {
ContextItem,
ContextProviderDescription,
ContextProviderExtras,
} from "../..";
const highlighterPromise = import("llm-code-highlighter/dist/index.continue");
class CodeHighlightsContextProvider extends BaseContextProvider {
static description: ContextProviderDescription = {
title: "highlights",
displayTitle: "Highlights",
description: "Code highlights from open files",
type: "normal",
};
async getContextItems(
query: string,
extras: ContextProviderExtras
): Promise<ContextItem[]> {
const ide = extras.ide;
const openFiles = await ide.getOpenFiles();
const allFiles: { name: string; absPath: string; content: string }[] =
await Promise.all(
openFiles.map(async (filepath: string) => {
return {
name: (filepath.split("/").pop() || "").split("\\").pop() || "",
absPath: filepath,
content: `${await ide.readFile(filepath)}`,
};
})
);
const topPercentile = 0.5;
const highlighter = await highlighterPromise;
const repoMap = await highlighter.getRepoHighlights(
topPercentile,
[],
allFiles
.filter((file) => file.content.length > 0)
.map((file) => {
return {
relPath: file.name,
code: file.content,
};
})
);
return [
{
content: repoMap,
name: "Code Highlights",
description: "Code highlights from open files",
},
];
}
async load(): Promise<void> {}
}
export default CodeHighlightsContextProvider;

View file

@ -1,6 +1,7 @@
import { BaseContextProvider } from "..";
import { ContextProviderName } from "../..";
import CodebaseContextProvider from "./CodebaseContextProvider";
import CodeHighlightsContextProvider from "./CodeHighlightsContextProvider";
import DiffContextProvider from "./DiffContextProvider";
import DocsContextProvider from "./DocsContextProvider";
import FileTreeContextProvider from "./FileTreeContextProvider";
@ -28,6 +29,7 @@ const Providers: (typeof BaseContextProvider)[] = [
ProblemsContextProvider,
FolderContextProvider,
DocsContextProvider,
CodeHighlightsContextProvider,
];
export function contextProviderClassFromName(

109
core/package-lock.json generated
View file

@ -16,6 +16,7 @@
"fastest-levenshtein": "^1.0.16",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"llm-code-highlighter": "^0.0.1",
"node-html-markdown": "^1.3.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",
@ -2002,6 +2003,11 @@
"onnxruntime-node": "1.14.0"
}
},
"node_modules/@yomguithereal/helpers": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@yomguithereal/helpers/-/helpers-1.1.1.tgz",
"integrity": "sha512-UYvAq/XCA7xoh1juWDYsq3W0WywOB+pz8cgVnE1b45ZfdMhBvHDrgmSFG3jXeZSr2tMTYLGHFHON+ekG05Jebg=="
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -3234,6 +3240,14 @@
"node": ">=6"
}
},
"node_modules/events": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
"engines": {
"node": ">=0.8.x"
}
},
"node_modules/execa": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz",
@ -3564,6 +3578,71 @@
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"devOptional": true
},
"node_modules/graphology": {
"version": "0.25.4",
"resolved": "https://registry.npmjs.org/graphology/-/graphology-0.25.4.tgz",
"integrity": "sha512-33g0Ol9nkWdD6ulw687viS8YJQBxqG5LWII6FI6nul0pq6iM2t5EKquOTFDbyTblRB3O9I+7KX4xI8u5ffekAQ==",
"dependencies": {
"events": "^3.3.0",
"obliterator": "^2.0.2"
},
"peerDependencies": {
"graphology-types": ">=0.24.0"
}
},
"node_modules/graphology-indices": {
"version": "0.17.0",
"resolved": "https://registry.npmjs.org/graphology-indices/-/graphology-indices-0.17.0.tgz",
"integrity": "sha512-A7RXuKQvdqSWOpn7ZVQo4S33O0vCfPBnUSf7FwE0zNCasqwZVUaCXePuWo5HBpWw68KJcwObZDHpFk6HKH6MYQ==",
"dependencies": {
"graphology-utils": "^2.4.2",
"mnemonist": "^0.39.0"
},
"peerDependencies": {
"graphology-types": ">=0.20.0"
}
},
"node_modules/graphology-metrics": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/graphology-metrics/-/graphology-metrics-2.2.0.tgz",
"integrity": "sha512-eZZFRLGGyyI+iD+XwQvc+lLM3EKCoqUvVjvF/14Htgy4grB2m95OytToYq3saWuHfuf22VVnj9GBHv/pTzKuTw==",
"dependencies": {
"graphology-shortest-path": "^2.0.0",
"graphology-utils": "^2.4.4",
"mnemonist": "^0.39.0"
},
"peerDependencies": {
"graphology-types": ">=0.20.0"
}
},
"node_modules/graphology-shortest-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/graphology-shortest-path/-/graphology-shortest-path-2.0.2.tgz",
"integrity": "sha512-hlGvh4Yb1Vmd2J7wT8Q8+t4RQ6Tx+9wRYm0/fZB9PZJ4uW3nml5kJ7yXZ2+JYWT+7wLLmY5mg3o9bLSAWmv/jQ==",
"dependencies": {
"@yomguithereal/helpers": "^1.1.1",
"graphology-indices": "^0.17.0",
"graphology-utils": "^2.4.3",
"mnemonist": "^0.39.0"
},
"peerDependencies": {
"graphology-types": ">=0.20.0"
}
},
"node_modules/graphology-types": {
"version": "0.24.7",
"resolved": "https://registry.npmjs.org/graphology-types/-/graphology-types-0.24.7.tgz",
"integrity": "sha512-tdcqOOpwArNjEr0gNQKCXwaNCWnQJrog14nJNQPeemcLnXQUUGrsCWpWkVKt46zLjcS6/KGoayeJfHHyPDlvwA==",
"peer": true
},
"node_modules/graphology-utils": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/graphology-utils/-/graphology-utils-2.5.2.tgz",
"integrity": "sha512-ckHg8MXrXJkOARk56ZaSCM1g1Wihe2d6iTmz1enGOz4W/l831MBCKSayeFQfowgF8wd+PQ4rlch/56Vs/VZLDQ==",
"peerDependencies": {
"graphology-types": ">=0.23.0"
}
},
"node_modules/guid-typescript": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/guid-typescript/-/guid-typescript-1.0.9.tgz",
@ -4647,6 +4726,18 @@
"integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==",
"dev": true
},
"node_modules/llm-code-highlighter": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/llm-code-highlighter/-/llm-code-highlighter-0.0.1.tgz",
"integrity": "sha512-26PExkQxeh5EiBNroldpV82pZDrjC6C5v4PLcm5ZpGIKExrHs9Hqw36B+1Fg+dxXGZMnwlCZ+6EbC2FEVocmcw==",
"dependencies": {
"graphology": "^0.25.4",
"graphology-metrics": "^2.2.0",
"lodash": "^4.17.21",
"tree-sitter-wasms": "^0.1.6",
"web-tree-sitter": "^0.20.8"
}
},
"node_modules/locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@ -4659,6 +4750,11 @@
"node": ">=8"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/lodash.assignwith": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/lodash.assignwith/-/lodash.assignwith-4.2.0.tgz",
@ -4999,6 +5095,14 @@
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
},
"node_modules/mnemonist": {
"version": "0.39.7",
"resolved": "https://registry.npmjs.org/mnemonist/-/mnemonist-0.39.7.tgz",
"integrity": "sha512-ix3FwHWZgdXUt0dHM8bCrI4r1KMeYx8bCunPCYmvKXq4tn6gbNsqrsb4q0kDbDqbpIOvEaW5Sn+dmDwGydfrwA==",
"dependencies": {
"obliterator": "^2.0.1"
}
},
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@ -5263,6 +5367,11 @@
"url": "https://github.com/fb55/nth-check?sponsor=1"
}
},
"node_modules/obliterator": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz",
"integrity": "sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ=="
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",

View file

@ -25,6 +25,7 @@
"fastest-levenshtein": "^1.0.16",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"llm-code-highlighter": "^0.0.1",
"node-html-markdown": "^1.3.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",

View file

@ -950,6 +950,11 @@
optionalDependencies:
onnxruntime-node "1.14.0"
"@yomguithereal/helpers@^1.1.1":
version "1.1.1"
resolved "https://registry.npmjs.org/@yomguithereal/helpers/-/helpers-1.1.1.tgz"
integrity sha512-UYvAq/XCA7xoh1juWDYsq3W0WywOB+pz8cgVnE1b45ZfdMhBvHDrgmSFG3jXeZSr2tMTYLGHFHON+ekG05Jebg==
abbrev@1:
version "1.1.1"
resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz"
@ -1741,6 +1746,11 @@ event-target-shim@^5.0.0:
resolved "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz"
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
events@^3.3.0:
version "3.3.0"
resolved "https://registry.npmjs.org/events/-/events-3.3.0.tgz"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
execa@^5.0.0:
version "5.1.1"
resolved "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz"
@ -1951,6 +1961,51 @@ graceful-fs@^4.2.6, graceful-fs@^4.2.9:
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==
graphology-indices@^0.17.0:
version "0.17.0"
resolved "https://registry.npmjs.org/graphology-indices/-/graphology-indices-0.17.0.tgz"
integrity sha512-A7RXuKQvdqSWOpn7ZVQo4S33O0vCfPBnUSf7FwE0zNCasqwZVUaCXePuWo5HBpWw68KJcwObZDHpFk6HKH6MYQ==
dependencies:
graphology-utils "^2.4.2"
mnemonist "^0.39.0"
graphology-metrics@^2.2.0:
version "2.2.0"
resolved "https://registry.npmjs.org/graphology-metrics/-/graphology-metrics-2.2.0.tgz"
integrity sha512-eZZFRLGGyyI+iD+XwQvc+lLM3EKCoqUvVjvF/14Htgy4grB2m95OytToYq3saWuHfuf22VVnj9GBHv/pTzKuTw==
dependencies:
graphology-shortest-path "^2.0.0"
graphology-utils "^2.4.4"
mnemonist "^0.39.0"
graphology-shortest-path@^2.0.0:
version "2.0.2"
resolved "https://registry.npmjs.org/graphology-shortest-path/-/graphology-shortest-path-2.0.2.tgz"
integrity sha512-hlGvh4Yb1Vmd2J7wT8Q8+t4RQ6Tx+9wRYm0/fZB9PZJ4uW3nml5kJ7yXZ2+JYWT+7wLLmY5mg3o9bLSAWmv/jQ==
dependencies:
"@yomguithereal/helpers" "^1.1.1"
graphology-indices "^0.17.0"
graphology-utils "^2.4.3"
mnemonist "^0.39.0"
graphology-types@>=0.20.0, graphology-types@>=0.23.0, graphology-types@>=0.24.0:
version "0.24.7"
resolved "https://registry.npmjs.org/graphology-types/-/graphology-types-0.24.7.tgz"
integrity sha512-tdcqOOpwArNjEr0gNQKCXwaNCWnQJrog14nJNQPeemcLnXQUUGrsCWpWkVKt46zLjcS6/KGoayeJfHHyPDlvwA==
graphology-utils@^2.4.2, graphology-utils@^2.4.3, graphology-utils@^2.4.4:
version "2.5.2"
resolved "https://registry.npmjs.org/graphology-utils/-/graphology-utils-2.5.2.tgz"
integrity sha512-ckHg8MXrXJkOARk56ZaSCM1g1Wihe2d6iTmz1enGOz4W/l831MBCKSayeFQfowgF8wd+PQ4rlch/56Vs/VZLDQ==
graphology@^0.25.4:
version "0.25.4"
resolved "https://registry.npmjs.org/graphology/-/graphology-0.25.4.tgz"
integrity sha512-33g0Ol9nkWdD6ulw687viS8YJQBxqG5LWII6FI6nul0pq6iM2t5EKquOTFDbyTblRB3O9I+7KX4xI8u5ffekAQ==
dependencies:
events "^3.3.0"
obliterator "^2.0.2"
guid-typescript@^1.0.9:
version "1.0.9"
resolved "https://registry.npmjs.org/guid-typescript/-/guid-typescript-1.0.9.tgz"
@ -2620,6 +2675,17 @@ lines-and-columns@^1.1.6:
resolved "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
llm-code-highlighter@^0.0.1:
version "0.0.1"
resolved "https://registry.npmjs.org/llm-code-highlighter/-/llm-code-highlighter-0.0.1.tgz"
integrity sha512-26PExkQxeh5EiBNroldpV82pZDrjC6C5v4PLcm5ZpGIKExrHs9Hqw36B+1Fg+dxXGZMnwlCZ+6EbC2FEVocmcw==
dependencies:
graphology "^0.25.4"
graphology-metrics "^2.2.0"
lodash "^4.17.21"
tree-sitter-wasms "^0.1.6"
web-tree-sitter "^0.20.8"
locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz"
@ -2642,6 +2708,11 @@ lodash.memoize@4.x:
resolved "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz"
integrity sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==
lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
long@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz"
@ -2827,6 +2898,13 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
mnemonist@^0.39.0:
version "0.39.7"
resolved "https://registry.npmjs.org/mnemonist/-/mnemonist-0.39.7.tgz"
integrity sha512-ix3FwHWZgdXUt0dHM8bCrI4r1KMeYx8bCunPCYmvKXq4tn6gbNsqrsb4q0kDbDqbpIOvEaW5Sn+dmDwGydfrwA==
dependencies:
obliterator "^2.0.1"
ms@^2.0.0, ms@2.1.2:
version "2.1.2"
resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz"
@ -2958,6 +3036,11 @@ nth-check@^2.0.1:
dependencies:
boolbase "^1.0.0"
obliterator@^2.0.1, obliterator@^2.0.2:
version "2.0.4"
resolved "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz"
integrity sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==
once@^1.3.0, once@^1.3.1, once@^1.4.0:
version "1.4.0"
resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz"

View file

@ -183,6 +183,19 @@ if (args[2] === "--target") {
);
console.log("[info] Copied tree-sitter wasms");
// tree-sitter tag query files
ncp(
path.join(
__dirname,
"../../../core/node_modules/llm-code-highlighter/dist/tag-qry"
),
path.join(__dirname, "../out/tag-qry"),
(error) => {
if (error)
console.warn("Error copying code-highlighter tag-qry files", error);
}
);
function ghAction() {
return target !== undefined;
}