Elffuss BraidHub

kikocis/continue public

Merge pull request #6523 from Jazzcort/fix-docs-mention

Fix: improved Documentation Indexing and Submenu Updates
Changeset402bc38c172a41880dc0d70d00109adcab05f5fda6f2943be8b6c09bac880cc6
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-09 17:10 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-09 17:10 -07:00
Parents81ce8cce6ac5, c081a032c656

Browse the files at this changeset

2 files changed

modified core/context/providers/DocsContextProvider.ts +13 −6
@@ -145,6 +145,11 @@
145145 async loadSubmenuItems(
146146 args: LoadSubmenuItemsArgs,
147147 ): Promise<ContextSubmenuItem[]> {
148+ const { config } = args;
149+ // This set is used to filter out the docs that is not in docs config but exist in sqlite metadata
150+ const configDocsSet = new Set(
151+ config.docs?.map((doc) => doc.startUrl) || [],
152+ );
148153 // Get docs service
149154 const docsService = DocsService.getSingleton();
150155 if (!docsService) {
@@ -159,12 +164,14 @@
159164 // Get all indexed docs from the database
160165 const docs = (await docsService.listMetadata()) ?? [];
161166 for (const { startUrl, title, favicon } of docs) {
162- submenuItems.push({
163- title,
164- id: startUrl,
165- description: new URL(startUrl).hostname,
166- icon: favicon,
167- });
167+ if (configDocsSet.has(startUrl)) {
168+ submenuItems.push({
169+ title,
170+ id: startUrl,
171+ description: new URL(startUrl).hostname,
172+ icon: favicon,
173+ });
174+ }
168175 }
169176
170177 // Sort alphabetically
modified core/indexing/docs/DocsService.ts +87 −11
@@ -107,6 +107,17 @@
107107 );
108108 };
109109
110+const siteIndexingConfigsAreEqualExceptTitleAndFavicon = (
111+ config1: SiteIndexingConfig,
112+ config2: SiteIndexingConfig,
113+) => {
114+ return (
115+ config1.startUrl === config2.startUrl &&
116+ config1.maxDepth === config2.maxDepth &&
117+ config1.useLocalCrawling === config2.useLocalCrawling
118+ );
119+};
120+
110121 /*
111122 General process:
112123 - On config update:
@@ -395,6 +406,21 @@
395406 siteIndexingConfig: SiteIndexingConfig,
396407 ): Promise<boolean> {
397408 try {
409+ // Set a initial status when retrieving cache
410+ this.handleStatusUpdate({
411+ type: "docs",
412+ id: startUrl,
413+ embeddingsProviderId: embeddingId,
414+ isReindexing: false,
415+ title: siteIndexingConfig.title,
416+ debugInfo: "Loaded from cache",
417+ icon: siteIndexingConfig.faviconUrl,
418+ url: startUrl,
419+ progress: 0,
420+ description: "Try to retrieve cache",
421+ status: "indexing",
422+ });
423+
398424 const cacheHit = await this.tryFetchFromCache(startUrl, embeddingId);
399425
400426 if (cacheHit) {
@@ -429,7 +455,8 @@
429455 siteIndexingConfig: SiteIndexingConfig,
430456 forceReindex: boolean = false,
431457 ): Promise<void> {
432- const { startUrl, useLocalCrawling, maxDepth } = siteIndexingConfig;
458+ const { startUrl, useLocalCrawling, maxDepth, faviconUrl } =
459+ siteIndexingConfig;
433460
434461 // First, if indexing is already in process, don't attempt
435462 // This queue is necessary because indexAndAdd is invoked circularly by config edits
@@ -685,7 +712,9 @@
685712 await this.deleteIndexes(startUrl);
686713 }
687714
688- const favicon = await fetchFavicon(new URL(siteIndexingConfig.startUrl));
715+ const favicon =
716+ faviconUrl ||
717+ (await fetchFavicon(new URL(siteIndexingConfig.startUrl)));
689718
690719 if (this.shouldCancel(startUrl, startedWithEmbedder)) {
691720 return;
@@ -718,10 +747,6 @@
718747 void this.ide.showToast("info", `Successfully indexed ${startUrl}`);
719748 }
720749
721- this.messenger?.send("refreshSubmenuItems", {
722- providers: ["docs"],
723- });
724-
725750 removeFromFailedGlobalContext(siteIndexingConfig);
726751 } catch (e) {
727752 console.error(
@@ -766,14 +791,22 @@
766791 const siteEmbeddings = JSON.parse(data) as SiteIndexingResults;
767792
768793 // Try to get a favicon for the site
769- const favicon = await fetchFavicon(new URL(startUrl));
794+ const favicon =
795+ this.statuses.get(startUrl)?.icon ||
796+ (await fetchFavicon(new URL(startUrl)));
797+
798+ // Always try to make the title match what users set in the config
799+ const title =
800+ this.statuses.get(startUrl)?.title ||
801+ siteEmbeddings.title ||
802+ new URL(startUrl).hostname;
770803
771804 // Add the cached embeddings to our database
772805 await this.add({
773806 favicon,
774807 siteIndexingConfig: {
775808 startUrl,
776- title: siteEmbeddings.title || new URL(startUrl).hostname,
809+ title,
777810 },
778811 chunks: siteEmbeddings.chunks,
779812 embeddings: siteEmbeddings.chunks.map((c) => c.embedding),
@@ -910,6 +943,10 @@
910943 );
911944
912945 if (cacheHit) {
946+ // If cache hit, refresh the submenu items for docs
947+ this.messenger?.send("refreshSubmenuItems", {
948+ providers: ["docs"],
949+ });
913950 // If cache hit, retry the search once
914951 return await this.retrieveChunks(startUrl, vector, nRetrieve, true);
915952 }
@@ -987,8 +1024,7 @@
9871024 const currentStartUrls = currentlyIndexedDocs.map((doc) => doc.startUrl);
9881025
9891026 // Anything found in old config, new config, AND sqlite that doesn't match should be reindexed
990- // TODO if only favicon and title change, only update, don't embed
991- // Otherwise anything found in new config that isn't in sqlite should be added/indexed
1027+ // Anything found in new config that isn't in sqlite should be added/indexed
9921028 const addedDocs: SiteIndexingConfig[] = [];
9931029 const changedDocs: SiteIndexingConfig[] = [];
9941030 for (const doc of newConfigDocs) {
@@ -999,12 +1035,26 @@
9991035 (d) => d.startUrl === doc.startUrl,
10001036 );
10011037
1038+ // TODO: Changes to the docs config made while Continue isn't running won't be caught
10021039 if (oldConfigDoc && !siteIndexingConfigsAreEqual(oldConfigDoc, doc)) {
1003- changedDocs.push(doc);
1040+ // When only the title or faviconUrl changed, Update the sqlite metadate instead of reindexing
1041+ if (
1042+ siteIndexingConfigsAreEqualExceptTitleAndFavicon(
1043+ oldConfigDoc,
1044+ doc,
1045+ )
1046+ ) {
1047+ await this.updateMetadataInSqlite(doc);
1048+ } else {
1049+ changedDocs.push(doc);
1050+ }
10041051 } else {
10051052 if (forceReindex) {
10061053 changedDocs.push(doc);
10071054 } else {
1055+ // This is a temperary fix to catch the changes to the docs config that were made when Continue isn't running
1056+ // We only update title and faviconUrl here
1057+ await this.updateMetadataInSqlite(doc);
10081058 // if get's here, not changed, no update needed, mark as complete
10091059 this.handleStatusUpdate({
10101060 type: "docs",
@@ -1036,6 +1086,10 @@
10361086 console.error("Error syncing docs index on config update", e);
10371087 } finally {
10381088 this.isSyncing = false;
1089+ // Refresh the submenu items for docs
1090+ this.messenger?.send("refreshSubmenuItems", {
1091+ providers: ["docs"],
1092+ });
10391093 }
10401094 }
10411095
@@ -1182,6 +1236,27 @@
11821236 );
11831237 }
11841238
1239+ private async updateMetadataInSqlite(siteIndexingConfig: SiteIndexingConfig) {
1240+ const { startUrl, title, faviconUrl } = siteIndexingConfig;
1241+ const favicon = faviconUrl || (await fetchFavicon(new URL(startUrl)));
1242+ if (!this.config.selectedModelByRole.embed) {
1243+ console.warn(
1244+ `Attempting to add metadata for ${startUrl} without embeddings provider specified`,
1245+ );
1246+ return;
1247+ }
1248+
1249+ const db = await this.getOrCreateSqliteDb();
1250+
1251+ await db.run(
1252+ `UPDATE ${DocsService.sqlitebTableName} SET title = ?, favicon = ? WHERE startUrl = ? AND embeddingsProviderId = ?`,
1253+ title,
1254+ favicon,
1255+ startUrl,
1256+ this.config.selectedModelByRole.embed.embeddingId,
1257+ );
1258+ }
1259+
11851260 private addToConfig(siteIndexingConfig: SiteIndexingConfig) {
11861261 // Handles the case where a user has manually added the doc to config.json
11871262 // so it already exists in the file
@@ -1286,5 +1361,6 @@
12861361 this.messenger?.send("refreshSubmenuItems", {
12871362 providers: ["docs"],
12881363 });
1364+ this.statuses.delete(startUrl);
12891365 }
12901366 }