Skip to content

Commit a2af40e

Browse files
authored
Merge pull request #2887 from continuedev/nate/small-fixes
second new prompt file
2 parents 98b2699 + 3a5329e commit a2af40e

File tree

9 files changed

+84
-31
lines changed

9 files changed

+84
-31
lines changed

core/config/load.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ async function serializedToIntermediateConfig(
215215
promptFiles.push(...readAllGlobalPromptFiles());
216216

217217
for (const file of promptFiles) {
218-
slashCommands.push(slashCommandFromPromptFile(file.path, file.content));
218+
const slashCommand = slashCommandFromPromptFile(file.path, file.content);
219+
if (slashCommand) {
220+
slashCommands.push(slashCommand);
221+
}
219222
}
220223
}
221224

core/config/promptFile.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import path from "path";
33
import Handlebars from "handlebars";
44
import * as YAML from "yaml";
55

6-
import { BaseContextProvider } from "../context";
76
import { walkDir } from "../indexing/walkDir";
87
import { stripImages } from "../llm/images";
98
import { renderTemplatedString } from "../promptFiles/v1/renderTemplatedString";
109
import { getBasename } from "../util/index";
1110

12-
import type { ChatHistory, ChatHistoryItem, ChatMessage, ContextItem, ContinueSDK, IContextProvider, IDE, SlashCommand } from "..";
11+
import type {
12+
ChatMessage,
13+
ContextItem,
14+
ContinueSDK,
15+
IContextProvider,
16+
IDE,
17+
SlashCommand,
18+
} from "..";
1319

1420
export const DEFAULT_PROMPTS_FOLDER = ".prompts";
1521

@@ -93,12 +99,16 @@ export async function createNewPromptFile(
9399
export function slashCommandFromPromptFile(
94100
path: string,
95101
content: string,
96-
): SlashCommand {
97-
const { name, description, systemMessage, prompt } = parsePromptFile(
102+
): SlashCommand | null {
103+
const { name, description, systemMessage, prompt, version } = parsePromptFile(
98104
path,
99105
content,
100106
);
101107

108+
if (version !== 1) {
109+
return null;
110+
}
111+
102112
return {
103113
name,
104114
description,
@@ -134,14 +144,15 @@ function parsePromptFile(path: string, content: string) {
134144
const preamble = YAML.parse(preambleRaw) ?? {};
135145
const name = preamble.name ?? getBasename(path).split(".prompt")[0];
136146
const description = preamble.description ?? name;
147+
const version = preamble.version ?? 2;
137148

138149
let systemMessage: string | undefined = undefined;
139150
if (prompt.includes("<system>")) {
140151
systemMessage = prompt.split("<system>")[1].split("</system>")[0].trim();
141152
prompt = prompt.split("</system>")[1].trim();
142153
}
143154

144-
return { name, description, systemMessage, prompt };
155+
return { name, description, systemMessage, prompt, version };
145156
}
146157

147158
function extractUserInput(input: string, commandName: string): string {
@@ -151,7 +162,11 @@ function extractUserInput(input: string, commandName: string): string {
151162
return input;
152163
}
153164

154-
async function renderPrompt(prompt: string, context: ContinueSDK, userInput: string) {
165+
async function renderPrompt(
166+
prompt: string,
167+
context: ContinueSDK,
168+
userInput: string,
169+
) {
155170
const helpers = getContextProviderHelpers(context);
156171

157172
// A few context providers that don't need to be in config.json to work in .prompt files

core/indexing/docs/DocsService.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,16 @@ export default class DocsService {
362362
isPreIndexedDoc: !!preIndexedDocs[startUrl],
363363
});
364364

365-
const docs: LanceDbDocsRow[] = await table
366-
.search(vector)
367-
.limit(nRetrieve)
368-
.where(`starturl = '${startUrl}'`)
369-
.execute();
365+
let docs: LanceDbDocsRow[] = [];
366+
try {
367+
docs = await table
368+
.search(vector)
369+
.limit(nRetrieve)
370+
.where(`starturl = '${startUrl}'`)
371+
.execute();
372+
} catch (e: any) {
373+
console.error("Error retrieving chunks from LanceDB", e);
374+
}
370375

371376
const hasIndexedDoc = await this.hasIndexedDoc(startUrl);
372377

@@ -553,9 +558,8 @@ export default class DocsService {
553558
private async getLanceTableNameFromEmbeddingsProvider(
554559
isPreIndexedDoc: boolean,
555560
) {
556-
const embeddingsProvider = await this.getEmbeddingsProvider(
557-
isPreIndexedDoc,
558-
);
561+
const embeddingsProvider =
562+
await this.getEmbeddingsProvider(isPreIndexedDoc);
559563

560564
const tableName = this.sanitizeLanceTableName(
561565
`${DocsService.lanceTableName}${embeddingsProvider.id}`,

core/indexing/docs/preIndexedDocs.ts

+5
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ const preIndexedDocs: Record<
325325
rootUrl: "https://awscli.amazonaws.com/v2/documentation/api/latest/",
326326
faviconUrl: "https://docs.aws.amazon.com/favicon.ico",
327327
},
328+
"https://llama-stack.readthedocs.io/": {
329+
title: "Llama Stack",
330+
startUrl: "https://llama-stack.readthedocs.io/",
331+
rootUrl: "https://llama-stack.readthedocs.io/",
332+
},
328333
};
329334

330335
export default preIndexedDocs;

core/promptFiles/v2/createNewPromptFile.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ export async function createNewPromptFileV2(
6666
counter++;
6767
} while (await ide.fileExists(promptFilePath));
6868

69+
const globalContext = new GlobalContext();
6970
const PROMPT_FILE =
70-
new GlobalContext().get("hasAlreadyCreatedAPromptFile") === true
71+
globalContext.get("hasAlreadyCreatedAPromptFile") === true
7172
? DEFAULT_PROMPT_FILE
7273
: FIRST_TIME_DEFAULT_PROMPT_FILE;
7374

75+
globalContext.update("hasAlreadyCreatedAPromptFile", true);
76+
7477
await ide.writeFile(promptFilePath, PROMPT_FILE);
7578
await ide.openFile(promptFilePath);
7679
}

extensions/vscode/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/vscode/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "continue",
33
"icon": "media/icon.png",
44
"author": "Continue Dev, Inc",
5-
"version": "0.9.227",
5+
"version": "0.9.228",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/continuedev/continue"

extensions/vscode/src/lang-server/promptFileCompletions.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ class YamlKeysCompletionItemProvider implements vscode.CompletionItemProvider {
141141
const lineText = document.lineAt(position).text;
142142
const textBeforeCursor = lineText.substring(0, position.character);
143143

144+
// 0. If no delimiter in the file, return no completions
145+
const fullContent = document.getText();
146+
if (!fullContent.includes("---")) {
147+
return undefined;
148+
}
149+
144150
// 1. Check if the cursor is in YAML section (before --- delimiter)
145151
const beforeDelimiter = isCursorBeforeDelimiter(document, position);
146152

@@ -160,7 +166,7 @@ class YamlKeysCompletionItemProvider implements vscode.CompletionItemProvider {
160166
vscode.CompletionItemKind.Property,
161167
);
162168
item.documentation = new vscode.MarkdownString(key.description);
163-
item.insertText = key + ": ";
169+
item.insertText = key.key + ": ";
164170
return item;
165171
});
166172

gui/src/pages/edit.tsx

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
22
import { Editor, JSONContent } from "@tiptap/core";
33
import { InputModifiers } from "core";
4+
import { stripImages } from "core/llm/images";
45
import { getBasename } from "core/util";
56
import { usePostHog } from "posthog-js/react";
67
import { useContext, useEffect, useState } from "react";
@@ -71,7 +72,17 @@ const EditHistoryDiv = styled.div`
7172
}
7273
`;
7374

74-
const EDIT_ALLOWS_CONTEXT_PROVIDERS = ["file", "code"];
75+
const EDIT_DISALLOWED_CONTEXT_PROVIDERS = [
76+
"codebase",
77+
"tree",
78+
"open",
79+
"web",
80+
"diff",
81+
"folder",
82+
"search",
83+
"debugger",
84+
"repo-map",
85+
];
7586

7687
function Edit() {
7788
const posthog = usePostHog();
@@ -174,7 +185,7 @@ function Edit() {
174185
border={`1px solid #aa0`}
175186
availableContextProviders={availableContextProviders.filter(
176187
(provider) =>
177-
EDIT_ALLOWS_CONTEXT_PROVIDERS.includes(provider.title),
188+
!EDIT_DISALLOWED_CONTEXT_PROVIDERS.includes(provider.title),
178189
)}
179190
historyKey="edit"
180191
availableSlashCommands={[]}
@@ -184,15 +195,21 @@ function Edit() {
184195
modifiers: InputModifiers,
185196
editor: Editor,
186197
): Promise<void> {
187-
const [_, __, prompt] = await resolveEditorContent(
188-
editorState,
189-
{
190-
noContext: true,
191-
useCodebase: false,
192-
},
193-
ideMessenger,
194-
[],
195-
);
198+
const [contextItems, __, userInstructions] =
199+
await resolveEditorContent(
200+
editorState,
201+
{
202+
noContext: true,
203+
useCodebase: false,
204+
},
205+
ideMessenger,
206+
[],
207+
);
208+
209+
const prompt = [
210+
...contextItems.map((item) => item.content),
211+
stripImages(userInstructions),
212+
].join("\n\n");
196213
ideMessenger.request("edit/sendPrompt", {
197214
prompt,
198215
range: editModeState.highlightedCode,

0 commit comments

Comments
 (0)